home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / modules / news / article.php next >
Encoding:
PHP Script  |  2002-09-16  |  11.5 KB  |  246 lines

  1. <?php
  2.  
  3. /************************************************************************/
  4. /* PHP-NUKE: Web Portal System                                          */
  5. /* ===========================                                          */
  6. /*                                                                      */
  7. /* Copyright (c) 2002 by Francisco Burzi                                */
  8. /* http://phpnuke.org                                                   */
  9. /*                                                                      */
  10. /* This program is free software. You can redistribute it and/or modify */
  11. /* it under the terms of the GNU General Public License as published by */
  12. /* the Free Software Foundation; either version 2 of the License.       */
  13. /************************************************************************/
  14.  
  15. if (!eregi("modules.php", $PHP_SELF)) {
  16.     die ("You can't access this file directly...");
  17. }
  18. require_once("mainfile.php");
  19. $module_name = basename(dirname(__FILE__));
  20. get_lang($module_name);
  21.  
  22. if (stristr($REQUEST_URI,"mainfile")) {
  23.     Header("Location: modules.php?name=$module_name&file=article&sid=$sid");
  24. } elseif (!isset($sid) && !isset($tid)) {
  25.     Header("Location: index.php");
  26. }
  27.  
  28. if ($save AND is_user($user)) {
  29.     cookiedecode($user);
  30.     sql_query("update ".$user_prefix."_users set umode='$mode', uorder='$order', thold='$thold' where uid='$cookie[0]'", $dbi);
  31.     getusrinfo($user);
  32.     $info = base64_encode("$userinfo[uid]:$userinfo[uname]:$userinfo[pass]:$userinfo[storynum]:$userinfo[umode]:$userinfo[uorder]:$userinfo[thold]:$userinfo[noscore]");
  33.     setcookie("user","$info",time()+$cookieusrtime);
  34. }
  35.  
  36. if ($op == "Reply") {
  37.     Header("Location: modules.php?name=$module_name&file=comments&op=Reply&pid=0&sid=$sid&mode=$mode&order=$order&thold=$thold");
  38. }
  39.  
  40. $result = sql_query("select catid, aid, time, title, hometext, bodytext, topic, informant, notes, acomm, haspoll, pollID, score, ratings FROM ".$prefix."_stories where sid=$sid", $dbi);
  41. list($catid, $aid, $time, $title, $hometext, $bodytext, $topic, $informant, $notes, $acomm, $haspoll, $pollID, $score, $ratings) = sql_fetch_row($result, $dbi);
  42.  
  43. if ($aid == "") {
  44.     Header("Location: modules.php?name=$module_name");
  45. }
  46.  
  47. sql_query("UPDATE ".$prefix."_stories SET counter=counter+1 where sid=$sid", $dbi);
  48.  
  49. $artpage = 1;
  50. $pagetitle = "- $title";
  51. require("header.php");
  52. $artpage = 0;
  53.  
  54. formatTimestamp($time);
  55. $title = stripslashes($title);
  56. $hometext = stripslashes($hometext);
  57. $bodytext = stripslashes($bodytext);
  58. $notes = stripslashes($notes);
  59.  
  60. if ($notes != "") {
  61.     $notes = "<br><br><b>"._NOTE."</b> <i>$notes</i>";
  62. } else {
  63.     $notes = "";
  64. }
  65.  
  66. if($bodytext == "") {
  67.     $bodytext = "$hometext$notes";
  68. } else {
  69.     $bodytext = "$hometext<br><br>$bodytext$notes";
  70. }
  71.  
  72. if($informant == "") {
  73.     $informant = $anonymous;
  74. }
  75.  
  76. getTopics($sid);
  77.  
  78. if ($catid != 0) {
  79.     $resultx = sql_query("select title from ".$prefix."_stories_cat where catid='$catid'", $dbi);
  80.     list($title1) = sql_fetch_row($resultx, $dbi);
  81.     $title = "<a href=\"modules.php?name=$module_name&file=categories&op=newindex&catid=$catid\"><font class=\"storycat\">$title1</font></a>: $title";
  82. }
  83.  
  84. echo "<table width=\"100%\" border=\"0\"><tr><td valign=\"top\" width=\"100%\">\n";
  85. themearticle($aid, $informant, $datetime, $title, $bodytext, $topic, $topicname, $topicimage, $topictext);
  86. echo "</td><td> </td><td valign=\"top\">\n";
  87.  
  88. if ($multilingual == 1) {
  89.     $querylang = "AND (blanguage='$currentlang' OR blanguage='')";
  90. } else {
  91.     $querylang = "";
  92. }
  93.  
  94. /* Determine if the article has attached a poll */
  95. if ($haspoll == 1) {
  96.     $url = sprintf("modules.php?name=Surveys&op=results&pollID=%d", $pollID);
  97.     $boxContent = "<form action=\"modules.php?name=Surveys\" method=\"post\">";
  98.     $boxContent .= "<input type=\"hidden\" name=\"pollID\" value=\"".$pollID."\">";
  99.     $boxContent .= "<input type=\"hidden\" name=\"forwarder\" value=\"".$url."\">";
  100.     $result = sql_query("SELECT pollTitle, voters FROM ".$prefix."_poll_desc WHERE pollID=$pollID", $dbi);
  101.     list($pollTitle, $voters) = sql_fetch_row($result, $dbi);
  102.     $boxTitle = _ARTICLEPOLL;
  103.     $boxContent .= "<font class=\"content\"><b>$pollTitle</b></font><br><br>\n";
  104.     $boxContent .= "<table border=\"0\" width=\"100%\">";
  105.     for($i = 1; $i <= 12; $i++) {
  106.     $result = sql_query("SELECT pollID, optionText, optionCount, voteID FROM ".$prefix."_poll_data WHERE (pollID=$pollID) AND (voteID=$i)", $dbi);
  107.     $object = sql_fetch_object($result, $dbi);
  108.     if(is_object($object)) {
  109.         $optionText = $object->optionText;
  110.         if($optionText != "") {
  111.         $boxContent .= "<tr><td valign=\"top\"><input type=\"radio\" name=\"voteID\" value=\"".$i."\"></td><td width=\"100%\"><font class=\"content\">$optionText</font></td></tr>\n";
  112.         }
  113.     }
  114.     }
  115.     $boxContent .= "</table><br><center><font class=\"content\"><input type=\"submit\" value=\""._VOTE."\"></font><br>";
  116.     if (is_user($user)) {
  117.         cookiedecode($user);
  118.     }
  119.     for($i = 0; $i < 12; $i++) {
  120.     $result = sql_query("SELECT optionCount FROM ".$prefix."_poll_data WHERE (pollID=$pollID) AND (voteID=$i)", $dbi);
  121.     $object = sql_fetch_object($result, $dbi);
  122.     $optionCount = $object->optionCount;
  123.     $sum = (int)$sum+$optionCount;
  124.     }
  125.     $boxContent .= "<font class=\"content\">[ <a href=\"modules.php?name=Surveys&op=results&pollID=$pollID&mode=$cookie[4]&order=$cookie[5]&thold=$cookie[6]\"><b>"._RESULTS."</b></a> | <a href=\"modules.php?name=Surveys\"><b>"._POLLS."</b></a> ]<br>";
  126.  
  127.     if ($pollcomm) {
  128.     list($numcom) = sql_fetch_row(sql_query("select count(*) from ".$prefix."_pollcomments where pollID=$pollID", $dbi), $dbi);
  129.     $boxContent .= "<br>"._VOTES.": <b>$sum</b><br>"._PCOMMENTS." <b>$numcom</b>\n\n";
  130.     } else {
  131.         $boxContent .= "<br>"._VOTES." <b>$sum</b>\n\n";
  132.     }
  133.     $boxContent .= "</font></center></form>\n\n";
  134.     themesidebox($boxTitle, $boxContent);
  135. }
  136.  
  137. $result = sql_query("select title, content, active, position from ".$prefix."_blocks where blockfile='block-Login.php' $querylang", $dbi);
  138. list($title, $content, $active, $position) = sql_fetch_row($result, $dbi);
  139. if (($active == 1) AND ($position == "r") AND (!is_user($user))) {
  140.     loginbox();
  141. }
  142.  
  143. $boxtitle = ""._RELATED."";
  144. $boxstuff = "<font class=\"content\">";
  145. unset($location);
  146. $links = array();
  147. $hrefs = array();
  148. $pos = 0;
  149. while (!(($pos = strpos($bodytext,"<",$pos)) === false)) {
  150.     $pos++;
  151.     $endpos = strpos($bodytext,">",$pos);
  152.     $tag = substr($bodytext,$pos,$endpos-$pos);
  153.     $tag = trim($tag);
  154.     if (isset($location)) {
  155.         if (!strcasecmp(strtok($tag," "),"/A")) {
  156.             $link = substr($bodytext,$linkpos,$pos-1-$linkpos);
  157.             $links[] = $link;
  158.             $hrefs[] = $location;
  159.             unset($location);
  160.         }
  161.     $pos = $endpos+1;
  162.     } else {
  163.     if (!strcasecmp(strtok($tag," "),"A")) {
  164.         if (eregi("HREF[ \t\n\r\v]*=[ \t\n\r\v]*\"([^\"]*)\"",$tag,$regs));
  165.         else if (eregi("HREF[ \t\n\r\v]*=[ \t\n\r\v]*([^ \t\n\r\v]*)",$tag,$regs));
  166.         else $regs[1] = "";
  167.         if ($regs[1]) {
  168.             $location = $regs[1];
  169.         }
  170.         $pos = $endpos+1;
  171.         $linkpos = $pos;
  172.     } else {
  173.         $pos = $endpos+1;
  174.     }
  175.     }
  176. }
  177.  
  178. for ($i=0; $i<sizeof($links); $i++) {
  179.     if (strlen($links[$i]) > 20 AND !ereg(" ", $links[$i])) {
  180.     $alttext = "$links[$i]";
  181.     $links[$i] = substr($links[$i],0,20) . '...';
  182.     } else {
  183.     $alttext = "";
  184.     }
  185.     $boxstuff .= "<strong><big>·</big></strong> <a href=\"".$hrefs[$i]."\" target='blank' title='$alttext'>".$links[$i]."</a><br>\n";
  186.  
  187. $result = sql_query("select name, url from ".$prefix."_related where tid=$topic", $dbi);
  188. while(list($name, $url) = sql_fetch_row($result, $dbi)) {
  189.     $boxstuff .= "<strong><big>·</big></strong> <a href=\"$url\" target=\"new\">$name</a><br>\n";
  190. }
  191.  
  192. $boxstuff .= "<strong><big>·</big></strong> <a href=\"modules.php?name=Search&topic=$topic\">"._MOREABOUT." $topictext</a><br>\n";
  193. $boxstuff .= "<strong><big>·</big></strong> <a href=\"modules.php?name=Search&author=$aid\">"._NEWSBY." $aid</a>\n";
  194.  
  195. $boxstuff .= "</font><br><hr noshade width=\"95%\" size=\"1\"><center><font class=\"content\"><b>"._MOSTREAD." $topictext:</b><br>\n";
  196.  
  197. global $multilingual, $currentlang;
  198.     if ($multilingual == 1) {
  199.     $querylang = "AND (alanguage='$currentlang' OR alanguage='')"; /* the OR is needed to display stories who are posted to ALL languages */
  200.     } else {
  201.     $querylang = "";
  202.     }
  203. $result2 = sql_query("select sid, title from ".$prefix."_stories where topic=$topic $querylang order by counter desc limit 0,1", $dbi);
  204. list($topstory, $ttitle) = sql_fetch_row($result2, $dbi);
  205.  
  206. $boxstuff .= "<a href=\"modules.php?name=$module_name&file=article&sid=$topstory\">$ttitle</a></font></center><br>\n";
  207. themesidebox($boxtitle, $boxstuff);
  208.  
  209. if ($ratings != 0) {
  210.     $rate = substr($score / $ratings, 0, 4);
  211.     $r_image = round($rate);
  212.     $the_image = "<br><br><img src=\"images/articles/stars-$r_image.gif\" border=\"1\"></center><br>";
  213. } else {
  214.     $rate = 0;
  215.     $the_image = "</center><br>";
  216. }
  217. $ratetitle = ""._RATEARTICLE."";
  218. $ratecontent = "<center>"._AVERAGESCORE.": <b>$rate</b><br>"._VOTES.": <b>$ratings</b>$the_image";
  219. $ratecontent .= "<form action=\"modules.php?name=$module_name\" method=\"post\"><center>"._RATETHISARTICLE."</center><br>";
  220. $ratecontent .= "<input type=\"hidden\" name=\"sid\" value=\"$sid\">";
  221. $ratecontent .= "<input type=\"hidden\" name=\"op\" value=\"rate_article\">";
  222. $ratecontent .= "<input type=\"radio\" name=\"score\" value=\"1\"> <img src=\"images/articles/stars-1.gif\" border=\"0\" alt=\""._BAD."\" title=\""._BAD."\"><br>";
  223. $ratecontent .= "<input type=\"radio\" name=\"score\" value=\"2\"> <img src=\"images/articles/stars-2.gif\" border=\"0\" alt=\""._REGULAR."\" title=\""._REGULAR."\"><br>";
  224. $ratecontent .= "<input type=\"radio\" name=\"score\" value=\"3\"> <img src=\"images/articles/stars-3.gif\" border=\"0\" alt=\""._GOOD."\" title=\""._GOOD."\"><br>";
  225. $ratecontent .= "<input type=\"radio\" name=\"score\" value=\"4\"> <img src=\"images/articles/stars-4.gif\" border=\"0\" alt=\""._VERYGOOD."\" title=\""._VERYGOOD."\"><br>";
  226. $ratecontent .= "<input type=\"radio\" name=\"score\" value=\"5\"> <img src=\"images/articles/stars-5.gif\" border=\"0\" alt=\""._EXCELLENT."\" title=\""._EXCELLENT."\"><br><br>";
  227. $ratecontent .= "<center><input type=\"submit\" value=\""._CASTMYVOTE."\"></center></form><br>";
  228. themesidebox($ratetitle, $ratecontent);
  229.  
  230. $optiontitle = ""._OPTIONS."";
  231. $optionbox .= "<br><img src=\"images/print.gif\" border=\"0\" alt=\""._PRINTER."\" title=\""._PRINTER."\" width=\"16\" height=\"11\">  <a href=\"modules.php?name=$module_name&file=print&sid=$sid\">"._PRINTER."</a><br><br>";
  232. $optionbox .= "<img src=\"images/friend.gif\" border=\"0\" alt=\""._FRIEND."\" title=\""._FRIEND."\" width=\"16\" height=\"11\">  <a href=\"modules.php?name=$module_name&file=friend&op=FriendSend&sid=$sid\">"._FRIEND."</a>\n";
  233. if (is_admin($admin)) {
  234.     $optionbox .= "<center><br><b>"._ADMIN."</b><br>[ <a href=\"admin.php?op=adminStory\">"._ADD."</a> | <a href=\"admin.php?op=EditStory&sid=$sid\">"._EDIT."</a> | <a href=\"admin.php?op=RemoveStory&sid=$sid\">"._DELETE."</a> ]</center>";
  235. }
  236. themesidebox($optiontitle, $optionbox);
  237.  
  238. echo "</td></tr></table>\n";
  239. cookiedecode($user);
  240. if ((($mode != "nocomments") OR ($acomm == 0)) AND ($articlecomm == 1)) {
  241.     include("modules/News/comments.php");
  242. }
  243. include ("footer.php");
  244. ?>
  245.