home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / modules / news / index.php < prev    next >
Encoding:
PHP Script  |  2002-09-16  |  7.7 KB  |  184 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.  
  19. $index = 1;
  20. require_once("mainfile.php");
  21. $module_name = basename(dirname(__FILE__));
  22. get_lang($module_name);
  23.  
  24. function theindex($new_topic=0) {
  25.     global $dbi, $storyhome, $topicname, $topicimage, $topictext, $datetime, $user, $cookie, $nukeurl, $prefix, $multilingual, $currentlang, $articlecomm, $sitename, $user_news;
  26.     if ($multilingual == 1) {
  27.     $querylang = "AND (alanguage='$currentlang' OR alanguage='')";
  28.     } else {
  29.     $querylang = "";
  30.     }
  31.     include("header.php");
  32.     automated_news();
  33.     if (isset($cookie[3]) AND $user_news == 1) {
  34.     $storynum = $cookie[3];
  35.     } else {
  36.     $storynum = $storyhome;
  37.     }
  38.     if ($new_topic == 0) {
  39.     $qdb = "WHERE (ihome='0' OR catid='0')";
  40.     $home_msg = "";
  41.     } else {
  42.     $qdb = "WHERE topic='$new_topic'";
  43.     $res = sql_query("select topictext from ".$prefix."_topics where topicid='$new_topic'", $dbi);
  44.     list($topic_title) = sql_fetch_row($res, $dbi);
  45.     OpenTable();
  46.     if (sql_num_rows($res, $dbi) == 0) {
  47.         echo "<center><font class=\"title\">$sitename</font><br><br>"._NOINFO4TOPIC."<br><br>[ <a href=\"modules.php?name=News\">"._GOTONEWSINDEX."</a> | <a href=\"modules.php?name=Topics\">"._SELECTNEWTOPIC."</a> ]</center>";
  48.     } else {
  49.         echo "<center><font class=\"title\">$sitename: $topic_title</font><br><br>"
  50.         ."<form action=\"modules.php?name=Search\" method=\"post\">"
  51.         ."<input type=\"hidden\" name=\"topic\" value=\"$new_topic\">"
  52.         .""._SEARCHONTOPIC.": <input type=\"name\" name=\"query\" size=\"30\">  "
  53.         ."<input type=\"submit\" value=\""._SEARCH."\">"
  54.         ."</form>"
  55.         ."[ <a href=\"index.php\">"._GOTOHOME."</a> | <a href=\"modules.php?name=Topics\">"._SELECTNEWTOPIC."</a> ]</center>";
  56.     }
  57.     CloseTable();
  58.     echo "<br>";
  59.     }
  60.     $result = sql_query("SELECT sid, catid, aid, title, time, hometext, bodytext, comments, counter, topic, informant, notes, acomm, score, ratings FROM ".$prefix."_stories $qdb $querylang ORDER BY sid DESC limit $storynum", $dbi);
  61.     while (list($s_sid, $catid, $aid, $title, $time, $hometext, $bodytext, $comments, $counter, $topic, $informant, $notes, $acomm, $score, $ratings) = sql_fetch_row($result, $dbi)) {
  62.     if ($catid > 0) {
  63.         list($cattitle) = sql_fetch_row(sql_query("select title from ".$prefix."_stories_cat where catid='$catid'", $dbi), $dbi);
  64.     }
  65.     getTopics($s_sid);
  66.     formatTimestamp($time);
  67.     $subject = stripslashes($subject);
  68.     $hometext = stripslashes($hometext);
  69.     $notes = stripslashes($notes);
  70.     $introcount = strlen($hometext);
  71.     $fullcount = strlen($bodytext);
  72.     $totalcount = $introcount + $fullcount;
  73.     $c_count = $comments;
  74.     $r_options = "";
  75.         if (isset($cookie[4])) { $r_options .= "&mode=$cookie[4]"; }
  76.         if (isset($cookie[5])) { $r_options .= "&order=$cookie[5]"; }
  77.         if (isset($cookie[6])) { $r_options .= "&thold=$cookie[6]"; }
  78.     if (is_user($user)) {
  79.         $the_icons = " | <a href=\"modules.php?name=News&file=print&sid=$s_sid\"><img src=\"images/print.gif\" border=\"0\" alt=\""._PRINTER."\" title=\""._PRINTER."\" width=\"16\" height=\"11\"></a>  <a href=\"modules.php?name=News&file=friend&op=FriendSend&sid=$s_sid\"><img src=\"images/friend.gif\" border=\"0\" alt=\""._FRIEND."\" title=\""._FRIEND."\" width=\"16\" height=\"11\"></a>";
  80.     } else {
  81.         $the_icons = "";
  82.     }
  83.     $story_link = "<a href=\"modules.php?name=News&file=article&sid=$s_sid$r_options\">";
  84.     $morelink = "(";
  85.     if ($fullcount > 0 OR $c_count > 0 OR $articlecomm == 0 OR $acomm == 1) {
  86.         $morelink .= "$story_link<b>"._READMORE."</b></a> | ";
  87.     } else {
  88.         $morelink .= "";
  89.     }
  90.     if ($fullcount > 0) { $morelink .= "$totalcount "._BYTESMORE." | "; }
  91.     if ($articlecomm == 1 AND $acomm == 0) {
  92.         if ($c_count == 0) { $morelink .= "$story_link"._COMMENTSQ."</a>"; } elseif ($c_count == 1) { $morelink .= "$story_link$c_count "._COMMENT."</a>"; } elseif ($c_count > 1) { $morelink .= "$story_link$c_count "._COMMENTS."</a>"; }
  93.     }
  94.     $morelink .= "$the_icons";
  95.     $sid = $s_sid;
  96.     if ($catid != 0) {
  97.         $resultm = sql_query("select title from ".$prefix."_stories_cat where catid='$catid'", $dbi);
  98.         list($title1) = sql_fetch_row($resultm, $dbi);
  99.         $title = "<a href=\"modules.php?name=News&file=categories&op=newindex&catid=$catid\"><font class=\"storycat\">$title1</font></a>: $title";
  100.         $morelink .= " | <a href=\"modules.php?name=News&file=categories&op=newindex&catid=$catid\">$title1</a>";
  101.     }
  102.     if ($score != 0) {
  103.         $rated = substr($score / $ratings, 0, 4);
  104.     } else {
  105.         $rated = 0;
  106.     }
  107.     $morelink .= " | "._SCORE." $rated";
  108.     $morelink .= ")";
  109.     $morelink = str_replace(" |  | ", " | ", $morelink);
  110.     themeindex($aid, $informant, $datetime, $title, $counter, $topic, $hometext, $notes, $morelink, $topicname, $topicimage, $topictext);
  111.     }
  112.     include("footer.php");
  113. }
  114.  
  115. function rate_article($sid, $score) {
  116.     global $prefix, $dbi, $ratecookie, $sitename, $r_options;
  117.     if ($score) {
  118.     if (isset($ratecookie)) {
  119.         $rcookie = base64_decode($ratecookie);
  120.         $r_cookie = explode(":", $rcookie);
  121.     }
  122.     for ($i=0; $i < sizeof($r_cookie); $i++) {
  123.         if ($r_cookie[$i] == $sid) {
  124.         $a = 1;
  125.         }
  126.     }
  127.     if ($a == 1) {
  128.         Header("Location: modules.php?name=News&op=rate_complete&sid=$sid&rated=1");
  129.     } else {
  130.         $result = sql_query("update ".$prefix."_stories set score=score+$score, ratings=ratings+1 where sid='$sid'", $dbi);
  131.         $info = base64_encode("$rcookie$sid:");
  132.         setcookie("ratecookie","$info",time()+3600);
  133.         Header("Location: modules.php?name=News&op=rate_complete&sid=$sid$r_options");
  134.     }
  135.     } else {
  136.     include("header.php");
  137.     title("$sitename: "._ARTICLERATING."");
  138.     OpenTable();
  139.     echo "<center>"._DIDNTRATE."<br><br>"
  140.         .""._GOBACK."</center>";
  141.     CloseTable();
  142.     include("footer.php");
  143.     }
  144. }
  145.  
  146. function rate_complete($sid, $rated=0) {
  147.     global $sitename, $user, $cookie;
  148.     $r_options = "";
  149.     if (is_user($user)) {
  150.     if (isset($cookie[4])) { $r_options .= "&mode=$cookie[4]"; }
  151.     if (isset($cookie[5])) { $r_options .= "&order=$cookie[5]"; }
  152.         if (isset($cookie[6])) { $r_options .= "&thold=$cookie[6]"; }
  153.     }
  154.     include("header.php");
  155.     title("$sitename: "._ARTICLERATING."");
  156.     OpenTable();
  157.     if ($rated == 0) {
  158.     echo "<center>"._THANKSVOTEARTICLE."<br><br>"
  159.         ."[ <a href=\"modules.php?name=News&file=article&sid=$sid$r_options\">"._BACKTOARTICLEPAGE."</a> ]</center>";
  160.     } elseif ($rated == 1) {
  161.     echo "<center>"._ALREADYVOTEDARTICLE."<br><br>"
  162.         ."[ <a href=\"modules.php?name=News&file=article&sid=$sid$r_options\">"._BACKTOARTICLEPAGE."</a> ]</center>";
  163.     }
  164.     CloseTable();
  165.     include("footer.php");
  166. }
  167.  
  168. switch ($op) {
  169.  
  170.     default:
  171.     theindex($new_topic);
  172.     break;
  173.  
  174.     case "rate_article":
  175.     rate_article($sid, $score);
  176.     break;
  177.  
  178.     case "rate_complete":
  179.     rate_complete($sid, $rated);
  180.     break;
  181.  
  182. }
  183.  
  184. ?>