<?php
// function block
function get_topic_id($topic)
{
global $db;
$topic_id = 0;
// is this a direct value ?
$num_topic = intval($topic);
if ($topic == "$num_topic")
{
$topic_id = intval($topic);
}
// is it an url with topic id or post id ?
else
{
$name = explode('?', $topic);
$parms = ( isset($name[1]) ) ? $name[1] : $name[0];
parse_str($parms, $parm);
$found = false;
$topic_id = 0;
while ((list($key, $val) = each($parm)) && !$found):
$vals = explode('#', $val);
$val = $vals[0];
if (empty($val)) $val = 0;
switch($key)
{
case POST_POST_URL:
$sql = "SELECT topic_id FROM " . POSTS_TABLE . " WHERE post_id=$val";
if ( !($result = $db->sql_query($sql)) ) message_die(GENERAL_ERROR, 'Could not get post informations', '', __LINE__, __FILE__, $sql);
if ($row = $db->sql_fetchrow($result))
{
$val = $row['topic_id'];
$found = true;
}
break;
case POST_TOPIC_URL:
$found = true;
break;
}
if ($found)
{
$topic_id = intval($val);
}
endwhile;
}
return $topic_id;
}