home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / unitednuke / unitednuke.exe / html / modules / News / index.php < prev    next >
PHP Script  |  2004-01-31  |  15KB  |  348 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", $_SERVER['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. //nize pridany $pagenum pro cisla stranek a $new_topic pro pripad dvouslopcovych temat
  26.     global $db, $storyhome, $topicname, $topicimage, $topictext, $datetime, $user, $cookie, $nukeurl, $prefix, $multilingual, $currentlang, $articlecomm, $sitename, $user_news, $new_topic, $pagenum, $bgcolor1, $name;
  27.     if ($multilingual == 1) {
  28.     $querylang = "AND (alanguage='$currentlang' OR alanguage='')";
  29.     } else {
  30.     $querylang = "";
  31.     }
  32.     include("header.php");
  33.     automated_news();
  34.     if (isset($cookie[3]) AND $user_news == 1) {
  35.     $storynum = $cookie[3];
  36.     } else {
  37.     $storynum = $storyhome;
  38.     }
  39.     if ($new_topic == 0) {
  40.     $qdb = "WHERE (ihome='0' OR catid='0')";
  41.     $home_msg = "";
  42.     } else {
  43.     $qdb = "WHERE topic='$new_topic'";
  44.     $sql_a = "SELECT topictext FROM ".$prefix."_topics WHERE topicid='$new_topic'";
  45.     $result_a = $db->sql_query($sql_a);
  46.     $row_a = $db->sql_fetchrow($result_a);    
  47.     $numrows_a = $db->sql_numrows($result_a);
  48.     $topic_title = $row_a['topictext'];
  49.     OpenTable();
  50.     if ($numrows_a == 0) {
  51.         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>";
  52.     } else {
  53.         echo "<center><font class=\"title\">$sitename: $topic_title</font><br><br>"
  54.         ."<form action=\"modules.php?name=Search\" method=\"post\">"
  55.         ."<input type=\"hidden\" name=\"topic\" value=\"$new_topic\">"
  56.         .""._SEARCHONTOPIC.": <input type=\"name\" name=\"query\" size=\"30\">  "
  57.         ."<input type=\"submit\" value=\""._TOPICSEARCHING."\">"
  58.         ."</form>"
  59.         ."[ <a href=\"index.php\">"._GOTOHOME."</a> | <a href=\"modules.php?name=Topics\">"._SELECTNEWTOPIC."</a> ]</center>";
  60.     }
  61.     CloseTable();
  62.     echo "<br>";
  63.     }
  64.     if ($pagenum == "") { $pagenum = 1 ; }
  65.     $offset = ($pagenum-1) * $storynum ;
  66.     $offset = intval($offset);
  67.     $storynum = intval($storynum);
  68.     $sql = "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 $offset, $storynum";
  69.     //upraveno vyse pro cisla stranek
  70.     //$sql = "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";
  71.     $result = $db->sql_query($sql);
  72.     while ($row = $db->sql_fetchrow($result)) {
  73.     $s_sid = intval($row['sid']);
  74.     $catid = intval($row['catid']);
  75.     $aid = $row['aid'];
  76.     $title = $row['title'];
  77.     $time = $row['time'];
  78.     $hometext = $row['hometext'];
  79.     $bodytext = $row['bodytext'];
  80.     $comments = $row['comments'];
  81.     $counter = $row['counter'];
  82.     $topic = $row['topic'];
  83.     $informant = $row['informant'];
  84.     $notes = $row['notes'];
  85.     $acomm = intval($row['acomm']);
  86.     $score = intval($row['score']);
  87.     $ratings = intval($row['ratings']);
  88.     if ($catid > 0) {
  89.         $sql2 = "SELECT title FROM ".$prefix."_stories_cat WHERE catid='$catid'";
  90.         $result2 = $db->sql_query($sql2);
  91.         $row2 = $db->sql_fetchrow($result2);
  92.         $cattitle = $row2['title'];
  93.     }
  94.     getTopics($s_sid);
  95.     formatTimestamp($time);
  96.     $subject = stripslashes($subject);
  97.     $hometext = stripslashes($hometext);
  98.     $notes = stripslashes($notes);
  99.     $introcount = strlen($hometext);
  100.     $fullcount = strlen($bodytext);
  101.     $totalcount = $introcount + $fullcount;
  102.     $c_count = $comments;
  103.     $r_options = "";
  104.         if (isset($cookie[4])) { $r_options .= "&mode=$cookie[4]"; }
  105.         if (isset($cookie[5])) { $r_options .= "&order=$cookie[5]"; }
  106.         if (isset($cookie[6])) { $r_options .= "&thold=$cookie[6]"; }
  107.     if (is_user($user)) {
  108.         $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>";
  109.     } else {
  110.         $the_icons = "";
  111.     }
  112.     $story_link = "<a href=\"modules.php?name=News&file=article&sid=$s_sid$r_options\">";
  113.     $morelink = "(";
  114.     if ($fullcount > 0 OR $c_count > 0 OR $articlecomm == 0 OR $acomm == 1) {
  115.         $morelink .= "$story_link<b>"._READMORE."</b></a> | ";
  116.     } else {
  117.         $morelink .= "";
  118.     }
  119.     if ($fullcount > 0) { $morelink .= "$totalcount "._BYTESMORE." | "; }
  120.     if ($articlecomm == 1 AND $acomm == 0) {
  121.         if ($c_count == 0) { $morelink .= "$story_link"._COMMENTSQ."</a>"; } elseif ($c_count == 1) { $morelink .= "$story_link$c_count "._COMMENT."</a>"; } elseif ($c_count > 1 and $c_count <= 4) { $morelink .= "$story_link$c_count "._COMMENTS4."</a>"; } elseif ($c_count > 4) { $morelink .= "$story_link$c_count "._COMMENTS5."</a>"; }
  122.     }
  123.     $morelink .= "$the_icons";
  124.     $sid = $s_sid;
  125.     if ($catid != 0) {
  126.         $sql3 = "SELECT title FROM ".$prefix."_stories_cat WHERE catid='$catid'";
  127.         $result3 = $db->sql_query($sql3);
  128.         $row3 = $db->sql_fetchrow($result3);
  129.         $title1 = $row3['title'];
  130.         $title = "<a href=\"modules.php?name=News&file=categories&op=newindex&catid=$catid\"><font class=\"storycat\">$title1</font></a>: $title";
  131.         $morelink .= " | <a href=\"modules.php?name=News&file=categories&op=newindex&catid=$catid\">$title1</a>";
  132.     }
  133.     if ($score != 0) {
  134.         $rated = substr($score / $ratings, 0, 4);
  135.     } else {
  136.         $rated = 0;
  137.     }
  138.     $morelink .= " | "._SCORE." $rated";
  139.     $morelink .= ")";
  140.     $morelink = str_replace(" |  | ", " | ", $morelink);
  141.     if (!eregi("modules.php", $_SERVER['REQUEST_URI'])) {
  142.     $mainpage = 1;
  143.     } else {
  144.     $mainpage = 0;
  145.     }
  146.     //zobrazeni aktualit start
  147.     if ($init == 1 AND !isset($new_topic) AND $mainpage == 1) { //je-li prvni clanek
  148.     // je-li aktivni modul Flashnews a existuje patricny modul a neni zobrazen blokovy styl aktualit, zobrazi Flashnews - zacatek
  149.     $sql_fn = "SELECT active, title FROM ".$prefix."_blocks WHERE blockfile='block-Flashnews.php' $querylang";
  150.     $result_fn = $db->sql_query($sql_fn);
  151.     $row_fn = $db->sql_fetchrow($result_fn);
  152.     $active_fn = $row_fn['active'];
  153.     $title_fn = $row_fn['title'];
  154.     if ($title_fn == "") { //neni-li blok uveden v DB, musime vlozit staticky titulek :-(
  155.     $title_fn = ""._FN_ACTUAL."";
  156.     }
  157.     if (is_active("Flashnews") AND $active_fn != 1) {
  158.         render_blocks("c", "block-Flashnews.php", $title_fn, "", "1", "");
  159.       }
  160.     }
  161.     $init++;
  162.        // zobrazeni Aktualit konec
  163.        $theme_init++;
  164.     themeindex($aid, $informant, $datetime, $title, $counter, $topic, $hometext, $notes, $morelink, $topicname, $topicimage, $topictext);
  165.     }
  166.     #zacatek cislovani stranek
  167.     $sql_pn = "select sid from ".$prefix."_stories $qdb $querylang";
  168.     $result_pn = $db->sql_query($sql_pn);
  169.     $numstories = $db->sql_numrows($result_pn);
  170.     $numpages = ceil($numstories / $storynum);
  171.     if ($numpages > 1 AND $pagenum <= $numpages AND $pagenum != "0" AND $pagenum > 0) {
  172.         Opentable();
  173.         echo "<center>$numstories "._STORIES." ($numpages "._PAGES.", $storynum "._PERPAGE.")<br>" ;
  174.         if ($pagenum > 1) {
  175.             $prevpage = $pagenum - 1 ;
  176.             $leftarrow = "images/left.gif" ;
  177.             if(isset($new_topic)) {
  178.                 echo "<a href=\"modules.php?name=News&new_topic=$new_topic&pagenum=$prevpage\">";
  179.                 echo "<img src=\"$leftarrow\" align=\"middle\" border=\"0\" hspace=\"10\" alt=\"\"></a>";
  180.             } elseif ($mainpage == 1){
  181.             echo "<a href=\"index.php?pagenum=$prevpage\">";
  182.                 echo "<img src=\"$leftarrow\" align=\"middle\" border=\"0\" hspace=\"10\" alt=\"\"></a>";
  183.         } else {
  184.                 echo "<a href=\"modules.php?name=News&pagenum=$prevpage\">";
  185.                 echo "<img src=\"$leftarrow\" align=\"middle\" border=\"0\" hspace=\"10\" alt=\"\"></a>";
  186.             }
  187.         }
  188.         echo "[ " ;
  189.     if ($pagenum == 1 OR $pagenum == $numpages) {
  190.     $pagenum_pom = $pagenum+1;
  191.     } else {
  192.     $pagenum_pom = $pagenum;
  193.     }
  194.  
  195.     if ($pagenum == $numpages) {
  196.     $pom_num = 2;
  197.     } else {
  198.     $pom_num = 1;
  199.     }
  200.  
  201.     for ($i=$pagenum-$pom_num; $i < $pagenum_pom+2; $i++) {
  202.  
  203.     if ($pom_num == 2) {
  204.       if ($i != $pagenum-2 AND $i != $pagenum+1 AND $i != $pagenum+2) {
  205.         if ($numpages == 2 AND $i == 2) {
  206.         echo " | ";
  207.         } elseif ($numpages != 2) {
  208.         echo " | ";
  209.         }
  210.           }
  211.     } else {
  212.  
  213.       if ($i != 1 AND $i != $numpages+1 AND $i != $pagenum-1 AND $i != $pagenum+2) {
  214.       echo " | ";
  215.       } elseif ($pagenum == 1 AND $i == 3 AND $numpages != 2) {
  216.       echo " | ";
  217.       }
  218.     }
  219.  
  220.             if ($i == $pagenum) {
  221.                 echo "<b>$i</b>";
  222.             } elseif ($i != 0 AND $i <= $numpages) {
  223.                 if(isset($new_topic) AND $i != 0 AND $i <= $numpages) {
  224.                     echo "<a href=\"modules.php?name=News&new_topic=$new_topic&pagenum=$i\">$i</a>";
  225.         } elseif ($i != 0 AND $i <= $numpages AND $mainpage == 1){
  226.             echo "<a href=\"index.php?pagenum=$i\">$i</a>";
  227.                 } elseif ($i != 0 AND $i <= $numpages) {
  228.                     echo "<a href=\"modules.php?name=News&pagenum=$i\">$i</a>";
  229.                 }
  230.             }
  231.         }
  232.     echo " ]";
  233.         if ($pagenum < $numpages) {
  234.             $nextpage = $pagenum + 1 ;
  235.             $rightarrow = "images/right.gif" ;
  236.             if(isset($new_topic)) {
  237.                 echo "<a href=\"modules.php?name=News&new_topic=$new_topic&pagenum=$nextpage\">";
  238.                 echo "<img src=\"$rightarrow\" align=\"middle\" border=\"0\" hspace=\"10\" alt=\"\"></a>";
  239.             } elseif ($mainpage == 1){
  240.             echo "<a href=\"index.php?pagenum=$nextpage\">";
  241.                 echo "<img src=\"$rightarrow\" align=\"middle\" border=\"0\" hspace=\"10\" alt=\"\"></a>";
  242.         } else {
  243.                 echo "<a href=\"modules.php?name=News&pagenum=$nextpage\">";
  244.                 echo "<img src=\"$rightarrow\" align=\"middle\" border=\"0\" hspace=\"10\" alt=\"\"></a>";
  245.             }
  246.         }
  247.     if ($mainpage == 1) {
  248.       echo "<form name=\"pagenums\" method=\"get\" action=\"index.php\">\n";
  249.     } else {
  250.       echo "<form name=\"pagenums\" method=\"get\" action=\"modules.php\">\n";
  251.       echo "  <input type=\"hidden\" name=\"name\" value=\"News\">\n";
  252.       if(isset($new_topic)) {
  253.         echo "  <input type=\"hidden\" name=\"new_topic\" value=\"$new_topic\">\n";
  254.         }
  255.     }
  256.     echo "  "._NEWPAGENUMSGOTO." <input type=\"text\" name=\"pagenum\" value=\"$pagenum\" size=\"2\" style=\"background-color: $bgcolor1\">\n";
  257.     echo "  <input type=\"submit\" value=\"OK\" style=\"font-size: 9px; font-weight: bold;\">\n";
  258.     echo "</form>\n";
  259.     echo "</center>" ;
  260.         Closetable();
  261.     } elseif ($numpages > 1 OR $pagenum = "0" OR $pagenum < 0) {
  262.     Opentable();
  263.     echo ""._NEWPAGENOTFOUND."";
  264.     Closetable();
  265.     }
  266.     #konec cislovani stranek
  267.     include("footer.php");
  268. }
  269.  
  270. function rate_article($sid, $score) {
  271.     global $prefix, $dbi, $ratecookie, $sitename, $r_options;
  272.     $score = intval($score);
  273.     $sid = intval($sid);
  274.     if ($score) {
  275.     if ($score > 5) { $score = 5; }
  276.     if ($score < 1) { $score = 1; }
  277.     if ($score != 1 AND $score != 2 AND $score != 3 AND $score != 4 AND $score != 5) {
  278.         Header("Location: index.php");
  279.         die();
  280.     }
  281.     if (isset($ratecookie)) {
  282.         $rcookie = base64_decode($ratecookie);
  283.         $r_cookie = explode(":", $rcookie);
  284.     }
  285.     for ($i=0; $i < sizeof($r_cookie); $i++) {
  286.         if ($r_cookie[$i] == $sid) {
  287.         $a = 1;
  288.         }
  289.     }
  290.     if ($a == 1) {
  291.         Header("Location: modules.php?name=News&op=rate_complete&sid=$sid&rated=1");
  292.     } else {
  293.         $result = sql_query("update ".$prefix."_stories set score=score+$score, ratings=ratings+1 where sid='$sid'", $dbi);
  294.         $info = base64_encode("$rcookie$sid:");
  295.         setcookie("ratecookie","$info",time()+3600);
  296.         Header("Location: modules.php?name=News&op=rate_complete&sid=$sid$r_options");
  297.     }
  298.     } else {
  299.     include("header.php");
  300.     title("$sitename: "._ARTICLERATING."");
  301.     OpenTable();
  302.     echo "<center>"._DIDNTRATE."<br><br>"
  303.         .""._GOBACK."</center>";
  304.     CloseTable();
  305.     include("footer.php");
  306.     }
  307. }
  308.  
  309. function rate_complete($sid, $rated=0) {
  310.     global $sitename, $user, $cookie;
  311.     $r_options = "";
  312.     if (is_user($user)) {
  313.     if (isset($cookie[4])) { $r_options .= "&mode=$cookie[4]"; }
  314.     if (isset($cookie[5])) { $r_options .= "&order=$cookie[5]"; }
  315.         if (isset($cookie[6])) { $r_options .= "&thold=$cookie[6]"; }
  316.     }
  317.     include("header.php");
  318.     title("$sitename: "._ARTICLERATING."");
  319.     OpenTable();
  320.     if ($rated == 0) {
  321.     echo "<center>"._THANKSVOTEARTICLE."<br><br>"
  322.         ."[ <a href=\"modules.php?name=News&file=article&sid=$sid$r_options\">"._BACKTOARTICLEPAGE."</a> ]</center>";
  323.     } elseif ($rated == 1) {
  324.     echo "<center>"._ALREADYVOTEDARTICLE."<br><br>"
  325.         ."[ <a href=\"modules.php?name=News&file=article&sid=$sid$r_options\">"._BACKTOARTICLEPAGE."</a> ]</center>";
  326.     }
  327.     CloseTable();
  328.     include("footer.php");
  329. }
  330.  
  331. switch ($op) {
  332.  
  333.     default:
  334.     theindex($new_topic);
  335.     break;
  336.  
  337.     case "rate_article":
  338.     rate_article($sid, $score);
  339.     break;
  340.  
  341.     case "rate_complete":
  342.     rate_complete($sid, $rated);
  343.     break;
  344.  
  345. }
  346.  
  347. ?>
  348.