Codice PHP:
<?php
/***************************************************************************
* waptopic.php
* -------------------
* copyright : (C) 2003 Plus-Media.co.uk
* web : [url]http://www.plus-media.co.uk/[/url]
*
*
*
***************************************************************************/
require 'wapheader.php';
$topic = (empty($_GET['topic'])) ? "-1" : $_GET['topic'];
$start = (empty($_GET['s'])) ? "0" : $_GET['s'];
$forum_id = (empty($_GET['forum'])) ? "0" : $_GET['forum'];
$post = (empty($_GET['post'])) ? "-1" : $_GET['post'];
$salta = (empty($_POST['s'])) ? "0" : $_POST['s'];
$go = ($topic == -1) ? ("Spiacente,questo topic non esiste.") : ("1");
echo($header);
$i = 0;
if($go != 1)
{
echo($go);
}
$auth = auth(AUTH_ALL,$forum_id,$userdata);
if($auth['auth_read'] != 1)
{
echo "Non hai i permessi x vedere questo topic.
";
}
else {
$query = $db->sql_query("select forum_id, forum_name from " . FORUMS_TABLE . " where forum_id = \"$forum_id\"");
$forum = $db->sql_fetchrow($query);
$forum = wap_validate($forum['forum_name'],0,0);
$query = $db->sql_query("select * from " . TOPICS_TABLE . " where topic_id = \"$topic\" and forum_id = \"$forum_id\"");
$topicinfo = $db->sql_fetchrow($query);
$query = $db->sql_query("select * from " . POSTS_TABLE . " where topic_id = \"$topic\" and forum_id = \"$forum_id\" order by post_id ASC limit $start,1");
$post = $db->sql_fetchrow($query);
$query = $db->sql_query("select * from " . POSTS_TEXT_TABLE . " where post_id = \"".$post['post_id']."\"");
$posttext = $db->sql_fetchrow($query);
if(!empty($topicinfo['topic_moved_id']))
{
$query = $db->sql_query("select forum_id from " . TOPICS_TABLE . " where topic_id = \"".$topicinfo['topic_moved_id']."\"");
$forum_id = $db->sql_fetchrow($query);
echo "Mi spiace, questo topic e\' stato spostato. Clicca<anchor>qui<go href=\"" . append_sid("waptopic.php?start=$start&topic=".$topicinfo['topic_moved_id']."&forum=".$forum_id['forum_id']) . "\" /></anchor> spostato nel corretto thread.
";
}
if(empty($posttext['post_text'])) {
echo("Mi spiace,questo messaggio non esiste.
");
}
else {
$query = $db->sql_query("update " . TOPICS_TABLE . " set topic_views = topic_views+1 where topic_id = \"$topic\"");
$query = $db->sql_query("select * from " . USERS_TABLE . " where user_id = \"".$post['poster_id']."\"");
$user = $db->sql_fetchrow($query);
$posts = ($user['user_posts'] == "1") ? ("post") : ("posts");
$noposts = ($post['poster_id'] != -1) ? ( "(".$user['user_posts']." $posts)") : "";
$next = $start;
$prev = $start;
++$next;
--$prev;
$topic_replies = $topicinfo['topic_replies'];
if($start == 0)
{
if($topic_replies != 0)
{
$nav = "<anchor>Avanti>><go href=\"" . append_sid("waptopic.$phpEx?s=$next&topic=$topic&forum=$forum_id") . "\" /></anchor>";
}
}
else
{
++$topic_replies;
if($next >= $topic_replies)
{
$nav = "<anchor><<Indietro<go href=\"" . append_sid("waptopic.$phpEx?s=$prev&topic=$topic&forum=$forum_id") . "\" /></anchor>";
}
else
{
$nav = "<anchor><<Indietro<go href=\"" . append_sid("waptopic.$phpEx?s=$prev&topic=$topic&forum=$forum_id") . "\" /></anchor><anchor>Avanti>><go href=\"" . append_sid("waptopic.$phpEx?s=$next&topic=$topic&forum=$forum_id") . "\" /></anchor>";
}
--$topic_replies;
}
$nav .= "";
$post_text = $posttext['post_text'];
$post_text = wap_validate($post_text,1,1,$posttext['bbcode_uid']);
// makes the < bug disappear
$post_text = str_replace ("<table","*tttt*",$post_text);
$post_text = str_replace ("<go","*gggg*",$post_text);
$post_text = str_replace ("<tr","*trtt*",$post_text);
$post_text = str_replace ("<td","*tdtt*",$post_text);
$post_text = str_replace ("<img","*mmmm*",$post_text);
$post_text = str_replace ("<b","*bbbb*",$post_text);
$post_text = str_replace ("<i","*iiii*",$post_text);
$post_text = str_replace ("<u","*uuuu*",$post_text);
$post_text = str_replace ("<anchor","*aaaaaa*",$post_text);
$post_text = str_replace ("</","*zzzz*",$post_text);
$post_text = str_replace ("<","<",$post_text);
$post_text = str_replace ("*mmmm*","<img",$post_text);
$post_text = str_replace ("*aaaaaa*","<anchor",$post_text);
$post_text = str_replace ("*iiii*","<i",$post_text);
$post_text = str_replace ("*bbbb*","<b",$post_text);
$post_text = str_replace ("*uuuu*","<u",$post_text);
$post_text = str_replace ("*zzzz*","</",$post_text);
$post_text = str_replace ("*tttt*","<table",$post_text);
$post_text = str_replace ("*trtt*","<tr",$post_text);
$post_text = str_replace ("*gggg*","<go",$post_text);
$post_text = str_replace ("*tdtt*","<td",$post_text);
//-------------------------------------------------------------------------------------------------------------------------
//---[ BEGIN, url hacks ]--------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------
// this correctly renders url-s in posts - a little tweak is necessar to make it ok for the mod
preg_match_all ("/\/viewtopic.php\?t=([0-9]*)/",$post_text,$matches);
$match = $matches[1];
$matches = $matches[0];
foreach ($match as $key => $value)
{
$query = $db->sql_query("select topic_id, forum_id from " . TOPICS_TABLE . " where topic_id = \"$value\"");
$url_id = $db->sql_fetchrow($query);
$forum_id = $url_id['forum_id'];
$replacement = $wapdir . "/" . append_sid("waptopic.$phpEx?s=0&topic=". $value. "&forum=" . $forum_id);
$needle = $matches[$key]. "/";
$needle = str_replace ("?","\?",$needle);
$post_text = preg_replace($needle, $replacement, $post_text,1);
}
// this further more renders url-s that are not caught between bbtags, but preserves the already correct rendered ones
$post_text = str_replace ("href=\"wap","*hwap*",$post_text);
$post_text = str_replace("href=\"http://","*http*",$post_text);
$post_text = str_replace("href=\"www","*www*",$post_text);
$post_text = str_replace("src=\"http://","*srchttp*",$post_text);
$post_text = str_replace("src=\"www","*srcwww*",$post_text);
// this deals with [url]http://www.yoursite.com[/url] tags
$post_text = str_replace("<anchor>*#desc#*www","<anchor>*#descwww#*",$post_text);
$post_text = str_replace("<anchor>*#desc#*[url]http://[/url]","<anchor>*#deschttp#*",$post_text);
// main transform string
$post_text = preg_replace("/(http:\/\/[0-9a-zA-Z\.\/?=&;%]*)/","<anchor>\$1<go href=\"\$1\"/></anchor>",$post_text);
// this transforms back the already converted [url]http://www.yoursite.com[/url] tags
$post_text = str_replace("<anchor>*#deschttp#*","<anchor>[url]http://[/url]",$post_text);
$post_text = str_replace("<anchor>*#descwww#*","<anchor>www",$post_text);
$post_text = str_replace("*srcwww*","src=\"www",$post_text);
$post_text = str_replace("*srchttp*","src=\"http://",$post_text);
$post_text = str_replace("*www*","href=\"www",$post_text);
$post_text = str_replace("*http*","href=\"http://",$post_text);
$post_text = str_replace("*hwap*","href=\"wap",$post_text);
//-------------------------------------------------------------------------------------------------------------------------
//---[ END, url hacks ]----------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------
// this line solves the problem where the $ sign is mistakenly taken as start php variable
$post_text = str_replace ("$", "$", $post_text);
//Now Write out the content
echo("[b] ".$topicinfo['topic_title']."[/b]
Da ");#
if($user['username'] != "Anonymous")
{
echo("<anchor>" . $user['username'] . "<go href=\"" . append_sid("wapmisc.$phpEx?action=profile&u=" . $user['user_id'] . "") . "\" /></anchor>");
}
else
{
echo $user['username'];
}
echo (" ".$noposts." on ");
echo create_date($board_config['default_dateformat'], $post['post_time'], $board_config['board_timezone']);
echo(" Nel forum: <anchor>$forum<go href=\"" . append_sid("wapmisc.$phpEx?action=forum&forum=$forum_id") . "\" /></anchor>
");
echo($post_text);
echo "
<anchor>Rispondi<go href=\"" . append_sid("wapreply.$phpEx?topic=$topic&forum=$forum_id") . "\" /></anchor>/";
echo "<anchor>Riporta<go href=\"" . append_sid("wapreply.$phpEx?topic=$topic&forum=$forum_id&quote=1&post=" . $post['post_id']) . "\" /></anchor>
";
echo "<anchor>Ultimo Messaggio<go href=\"" . append_sid("waptopic.php?s=$topic_replies&topic=$topic&forum=$forum_id") . "\" /></anchor>
";
echo("
[b]--------------[/b]
".$user['user_sig']);
echo("
".$nav);
echo("
<u>[i]Post.. " .$start. " di " .$topic_replies. "[/i]</u>");
?>
<input name="s" emptyok="false"/>
<anchor>Salta
<go href="<?php echo append_sid("waptopic.php?s=$(s)&topic=$topic&forum=$forum_id"); ?>" method="post">
<postfield name="salta" value="$(s)"/>
</go>
</anchor>
<?php
$edit = ($post['poster_id'] == $userdata['user_id']) ? "<anchor>Edita<go href=\"" . append_sid("wapedit.$phpEx?post=" . $post['post_id']) . "\" /></anchor>" : "";
if( $topicinfo['topic_status'] == 1)
{
echo ("
[b]______________[/b]
Topic Chiuso
");
if( $userdata['user_level'] == ADMIN)
{
echo "[b]Opzioni Admin[/b]
";
echo "<anchor>Edita<go href=\"" . append_sid("wapedit.$phpEx?post=" . $post['post_id']) . "\" /></anchor>/";
}
if( $userdata['user_level'] == 2)
{
echo "[b]Opzioni Mod[/b]
";
echo "<anchor>Edita<go href=\"" . append_sid("wapedit.$phpEx?post=" . $post['post_id']) . "\" /></anchor>";
}
}
else
{
echo $login . "
\n";
if( $userdata['user_level'] == ADMIN)
{
echo "[b]Opzioni Admin[/b]
";
echo "<anchor>Edita<go href=\"" . append_sid("wapedit.$phpEx?post=" . $post['post_id']) . "\" /></anchor>/";
}
if( $userdata['user_level'] == 2)
{
echo "[b]Opzioni Mod[/b]
";
echo "<anchor>Edita<go href=\"" . append_sid("wapedit.$phpEx?post=" . $post['post_id']) . "\" /></anchor>/";
}
}
}
}
echo "
";
echo($footer);
?>