home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / mainfile.php < prev    next >
Encoding:
PHP Script  |  2002-09-16  |  33.2 KB  |  873 lines

  1. <?php
  2.  
  3. ob_start("ob_gzhandler");
  4.  
  5. /************************************************************************/
  6. /* PHP-NUKE: Advanced Content Management System                         */
  7. /* ============================================                         */
  8. /*                                                                      */
  9. /* Copyright (c) 2002 by Francisco Burzi                                */
  10. /* http://phpnuke.org                                                   */
  11. /*                                                                      */
  12. /* This program is free software. You can redistribute it and/or modify */
  13. /* it under the terms of the GNU General Public License as published by */
  14. /* the Free Software Foundation; either version 2 of the License.       */
  15. /************************************************************************/
  16.  
  17. if (!ini_get("register_globals")) {
  18.     $php_ver = phpversion();
  19.     $php_ver = explode(".", $php_ver);
  20.     $phpver = "$php_ver[0]$php_ver[1]";
  21.     if ($phpver >= 41) {
  22.     $PHP_SELF = $_SERVER['PHP_SELF'];
  23.     import_request_variables('GPC');
  24.     }
  25. }
  26.  
  27. foreach ($HTTP_GET_VARS as $secvalue) {
  28.     if ((eregi("<[^>]*script*\"?[^>]*>", $secvalue)) ||
  29.     (eregi("<[^>]*object*\"?[^>]*>", $secvalue)) ||
  30.     (eregi("<[^>]*iframe*\"?[^>]*>", $secvalue)) ||
  31.     (eregi("<[^>]*applet*\"?[^>]*>", $secvalue)) ||
  32.     (eregi("<[^>]*meta*\"?[^>]*>", $secvalue)) ||
  33.     (eregi("<[^>]*style*\"?[^>]*>", $secvalue)) ||
  34.     (eregi("<[^>]*form*\"?[^>]*>", $secvalue)) ||
  35.     (eregi("<[^>]*img*\"?[^>]*>", $secvalue)) ||
  36.     (eregi("\([^>]*\"?[^)]*\)", $secvalue)) ||
  37.     (eregi("\"", $secvalue))) {
  38.     die ("I don't like you...");
  39.     }
  40. }
  41.  
  42. if (eregi("mainfile.php",$PHP_SELF)) {
  43.     Header("Location: index.php");
  44.     die();
  45. }
  46.  
  47. require_once("config.php");
  48. require_once("includes/sql_layer.php");
  49. $dbi = sql_connect($dbhost, $dbuname, $dbpass, $dbname);
  50. $mainfile = 1;
  51. $result = sql_query("SELECT sitename, nukeurl, site_logo, slogan, startdate, adminmail, anonpost, Default_Theme, foot1, foot2, foot3, commentlimit, anonymous, minpass, pollcomm, articlecomm, broadcast_msg, my_headlines, top, storyhome, user_news, oldnum, ultramode, banners, backend_title, backend_language, language, locale, multilingual, useflags, notify, notify_email, notify_subject, notify_message, notify_from, footermsgtxt, email_send, attachmentdir, attachments, attachments_view, download_dir, defaultpopserver, singleaccount, singleaccountname, numaccounts, imgpath, filter_forward, moderate, admingraphic, httpref, httprefmax, CensorMode, CensorReplace, copyright, Version_Num from ".$prefix."_config", $dbi);
  52. list($sitename, $nukeurl, $site_logo, $slogan, $startdate, $adminmail, $anonpost, $Default_Theme, $foot1, $foot2, $foot3, $commentlimit, $anonymous, $minpass, $pollcomm, $articlecomm, $broadcast_msg, $my_headlines, $top, $storyhome, $user_news, $oldnum, $ultramode, $banners, $backend_title, $backend_language, $language, $locale, $multilingual, $useflags, $notify, $notify_email, $notify_subject, $notify_message, $notify_from, $footermsgtxt, $email_send, $attachmentdir, $attachments, $attachments_view, $download_dir, $defaultpopserver, $singleaccount, $singleaccountname, $numaccounts, $imgpath, $filter_forward, $moderate, $admingraphic, $httpref, $httprefmax, $CensorMode, $CensorReplace, $copyright, $Version_Num) = sql_fetch_row($result, $dbi);
  53. $domain = eregi_replace("http://", "", $nukeurl);
  54. $tipath = "images/topics/";
  55. $mtime = microtime();
  56. $mtime = explode(" ",$mtime);
  57. $mtime = $mtime[1] + $mtime[0];
  58. $starttime = $mtime;
  59.  
  60. if (isset($newlang)) {
  61.     if (file_exists("language/lang-$newlang.php")) {
  62.     setcookie("lang",$newlang,time()+31536000);
  63.     include("language/lang-$newlang.php");
  64.     $currentlang = $newlang;
  65.     } else {
  66.     setcookie("lang",$language,time()+31536000);
  67.     include("language/lang-$language.php");
  68.     $currentlang = $language;
  69.     }
  70. } elseif (isset($lang)) {
  71.     include("language/lang-$lang.php");
  72.     $currentlang = $lang;
  73. } else {
  74.     setcookie("lang",$language,time()+31536000);
  75.     include("language/lang-$language.php");
  76.     $currentlang = $language;
  77. }
  78.  
  79. function get_lang($module) {
  80.     global $currentlang, $language;
  81.     if (file_exists("modules/$module/language/lang-$currentlang.php")) {
  82.     if ($module == admin) {
  83.         include_once("admin/language/lang-$currentlang.php");
  84.     } else {
  85.         include_once("modules/$module/language/lang-$currentlang.php");
  86.     }
  87.     } else {
  88.     if ($module == admin) {
  89.         include_once("admin/language/lang-$currentlang.php");
  90.     } else {
  91.         include_once("modules/$module/language/lang-$language.php");
  92.     }
  93.     }
  94. }
  95.  
  96. function is_admin($admin) {
  97.     global $prefix, $dbi;
  98.     if(!is_array($admin)) {
  99.     $admin = base64_decode($admin);
  100.     $admin = explode(":", $admin);
  101.         $aid = "$admin[0]";
  102.     $pwd = "$admin[1]";
  103.     } else {
  104.         $aid = "$admin[0]";
  105.     $pwd = "$admin[1]";
  106.     }
  107.     if ($aid != "" AND $pwd != "") {
  108.     $result = sql_query("select pwd from ".$prefix."_authors where aid='$aid'", $dbi);
  109.     list($pass) = sql_fetch_row($result, $dbi);
  110.     if($pass == $pwd && $pass != "") {
  111.         return 1;
  112.     }
  113.     }
  114.     return 0;
  115. }
  116.  
  117. function is_user($user) {
  118.     global $prefix, $dbi, $user_prefix;
  119.     if(!is_array($user)) {
  120.     $user = base64_decode($user);
  121.     $user = explode(":", $user);
  122.         $uid = "$user[0]";
  123.     $pwd = "$user[2]";
  124.     } else {
  125.         $uid = "$user[0]";
  126.     $pwd = "$user[2]";
  127.     }
  128.     if ($uid != "" AND $pwd != "") {
  129.     $result = sql_query("select pass from ".$user_prefix."_users where uid='$uid'", $dbi);
  130.     list($pass) = sql_fetch_row($result, $dbi);
  131.     if($pass == $pwd && $pass != "") {
  132.         return 1;
  133.     }
  134.     }
  135.     return 0;
  136. }
  137.  
  138.  
  139. function title($text) {
  140.     OpenTable();
  141.     echo "<center><font class=\"title\"><b>$text</b></font></center>";
  142.     CloseTable();
  143.     echo "<br>";
  144. }
  145.  
  146. function is_active($module) {
  147.     global $prefix, $dbi;
  148.     $result = sql_query("select active from ".$prefix."_modules where title='$module'", $dbi);
  149.     list ($act) = sql_fetch_row($result, $dbi);
  150.     if (!$result OR $act == 0) {
  151.     return 0;
  152.     } else {
  153.     return 1;
  154.     }
  155. }
  156.  
  157. function render_blocks($side, $blockfile, $title, $content, $bid, $url) {
  158.     if ($url == "") {
  159.     if ($blockfile == "") {
  160.         if ($side == "c") {
  161.         themecenterbox($title, $content);
  162.         } elseif ($side == "d") {
  163.         themecenterbox($title, $content);
  164.         } else {
  165.         themesidebox($title, $content);
  166.         }
  167.     } else {
  168.         if ($side == "c") {
  169.         blockfileinc($title, $blockfile, 1);
  170.         } elseif ($side == "d") {
  171.         themecenterbox($title, $content);
  172.         } else {
  173.         blockfileinc($title, $blockfile);
  174.         }
  175.     }
  176.     } else {
  177.     if ($side == "c" OR $side == "d") {
  178.         headlines($bid,1);
  179.     } else {
  180.             headlines($bid);
  181.     }
  182.     }
  183. }
  184.  
  185. function blocks($side) {
  186.     global $storynum, $prefix, $multilingual, $currentlang, $dbi, $admin, $user;
  187.     if ($multilingual == 1) {
  188.         $querylang = "AND (blanguage='$currentlang' OR blanguage='')";
  189.     } else {
  190.         $querylang = "";
  191.     }
  192.     if (strtolower($side[0]) == "l") {
  193.     $pos = "l";
  194.     } elseif (strtolower($side[0]) == "r") {
  195.     $pos = "r";
  196.     }  elseif (strtolower($side[0]) == "c") {
  197.     $pos = "c";
  198.     } elseif  (strtolower($side[0]) == "d") {
  199.     $pos = "d";
  200.     }
  201.     $side = $pos;
  202.     $result = sql_query("select bid, bkey, title, content, url, blockfile, view from ".$prefix."_blocks where position='$pos' AND active='1' $querylang ORDER BY weight ASC", $dbi);
  203.     while(list($bid, $bkey, $title, $content, $url, $blockfile, $view) = sql_fetch_row($result, $dbi)) {
  204.     if ($bkey == admin) {
  205.         adminblock();
  206.     } elseif ($bkey == userbox) {
  207.         userblock();
  208.     } elseif ($bkey == "") {
  209.         if ($view == 0) {
  210.         render_blocks($side, $blockfile, $title, $content, $bid, $url);
  211.         } elseif ($view == 1 AND is_user($user) || is_admin($admin)) {
  212.         render_blocks($side, $blockfile, $title, $content, $bid, $url);
  213.         } elseif ($view == 2 AND is_admin($admin)) {
  214.         render_blocks($side, $blockfile, $title, $content, $bid, $url);
  215.         } elseif ($view == 3 AND !is_user($user) || is_admin($admin)) {
  216.         render_blocks($side, $blockfile, $title, $content, $bid, $url);
  217.         }
  218.     }
  219.     }
  220. }
  221.  
  222. function message_box() {
  223.     global $bgcolor1, $bgcolor2, $user, $admin, $cookie, $textcolor2, $prefix, $multilingual, $currentlang, $dbi;
  224.     if ($multilingual == 1) {
  225.     $querylang = "AND (mlanguage='$currentlang' OR mlanguage='')";
  226.     } else {
  227.     $querylang = "";
  228.     }
  229.     $result = sql_query("select mid, title, content, date, expire, view from ".$prefix."_message where active='1' $querylang", $dbi);
  230.     if (sql_num_rows($result, $dbi) == 0) {
  231.     return;
  232.     } else {
  233.     while (list($mid, $title, $content, $mdate, $expire, $view) = sql_fetch_row($result, $dbi)) {
  234.     if ($title != "" && $content != "") {
  235.         if ($expire == 0) {
  236.         $remain = _UNLIMITED;
  237.         } else {
  238.         $etime = (($mdate+$expire)-time())/3600;
  239.         $etime = (int)$etime;
  240.         if ($etime < 1) {
  241.             $remain = _EXPIRELESSHOUR;
  242.         } else {
  243.             $remain = ""._EXPIREIN." $etime "._HOURS."";
  244.         }
  245.         }
  246.         if ($view == 4 AND is_admin($admin)) {
  247.                 OpenTable();
  248.                 echo "<center><font class=\"option\" color=\"$textcolor2\"><b>$title</b></font></center><br>\n"
  249.             ."<font class=\"content\">$content</font>"
  250.             ."<br><br><center><font class=\"content\">[ "._MVIEWADMIN." - $remain - <a href=\"admin.php?op=editmsg&mid=$mid\">"._EDIT."</a> ]</font></center>";
  251.         CloseTable();
  252.         echo "<br>";
  253.         } elseif ($view == 3 AND is_user($user) || is_admin($admin)) {
  254.                 OpenTable();
  255.                 echo "<center><font class=\"option\" color=\"$textcolor2\"><b>$title</b></font></center><br>\n"
  256.             ."<font class=\"content\">$content</font>";
  257.         if (is_admin($admin)) {
  258.             echo "<br><br><center><font class=\"content\">[ "._MVIEWUSERS." - $remain - <a href=\"admin.php?op=editmsg&mid=$mid\">"._EDIT."</a> ]</font></center>";
  259.         }
  260.             CloseTable();
  261.         echo "<br>";
  262.         } elseif ($view == 2 AND !is_user($user) || is_admin($admin)) {
  263.                 OpenTable();
  264.                 echo "<center><font class=\"option\" color=\"$textcolor2\"><b>$title</b></font></center><br>\n"
  265.             ."<font class=\"content\">$content</font>";
  266.         if (is_admin($admin)) {
  267.             echo "<br><br><center><font class=\"content\">[ "._MVIEWANON." - $remain - <a href=\"admin.php?op=editmsg&mid=$mid\">"._EDIT."</a> ]</font></center>";
  268.         }
  269.         CloseTable();
  270.         echo "<br>";
  271.         } elseif ($view == 1) {
  272.                 OpenTable();
  273.                 echo "<center><font class=\"option\" color=\"$textcolor2\"><b>$title</b></font></center><br>\n"
  274.             ."<font class=\"content\">$content</font>";
  275.         if (is_admin($admin)) {
  276.             echo "<br><br><center><font class=\"content\">[ "._MVIEWALL." - $remain - <a href=\"admin.php?op=editmsg&mid=$mid\">"._EDIT."</a> ]</font></center>";
  277.         }
  278.         CloseTable();
  279.         echo "<br>";
  280.         }
  281.         if ($expire != 0) {
  282.             $past = time()-$expire;
  283.         if ($mdate < $past) {
  284.             $result = sql_query("update ".$prefix."_message set active='0' where mid='$mid'", $dbi);
  285.         }
  286.         }
  287.         }
  288.     }
  289.     }
  290. }
  291.  
  292. function online() {
  293.     global $user, $cookie, $prefix, $dbi;
  294.     cookiedecode($user);
  295.     $ip = getenv("REMOTE_ADDR");
  296.     $username = $cookie[1];
  297.     if (!isset($username)) {
  298.         $username = "$ip";
  299.         $guest = 1;
  300.     }
  301.     $past = time()-1800;
  302.     sql_query("DELETE FROM ".$prefix."_session WHERE time < $past", $dbi);
  303.     $result = sql_query("SELECT time FROM ".$prefix."_session WHERE username='$username'", $dbi);
  304.     $ctime = time();
  305.     if ($row = sql_fetch_array($result, $dbi)) {
  306.     sql_query("UPDATE ".$prefix."_session SET username='$username', time='$ctime', host_addr='$ip', guest='$guest' WHERE username='$username'", $dbi);
  307.     } else {
  308.     sql_query("INSERT INTO ".$prefix."_session (username, time, host_addr, guest) VALUES ('$username', '$ctime', '$ip', '$guest')", $dbi);
  309.     }
  310. }
  311.  
  312. function blockfileinc($title, $blockfile, $side=0) {
  313.     $blockfiletitle = $title;
  314.     $file = @file("blocks/$blockfile");
  315.     if (!$file) {
  316.     $content = _BLOCKPROBLEM;
  317.     } else {
  318.     include("blocks/$blockfile");
  319.     }
  320.     if ($content == "") {
  321.     $content = _BLOCKPROBLEM2;
  322.     }
  323.     if ($side == 1) {
  324.     themecenterbox($blockfiletitle, $content);
  325.     } elseif ($side == 2) {
  326.     themecenterbox($blockfiletitle, $content);
  327.     } else {
  328.     themesidebox($blockfiletitle, $content);
  329.     }
  330. }
  331.  
  332. function selectlanguage() {
  333.     global $useflags, $currentlang;
  334.     if ($useflags == 1) {
  335.     $title = _SELECTLANGUAGE;
  336.     $content = "<center><font class=\"content\">"._SELECTGUILANG."<br><br>";
  337.     $langdir = dir("language");
  338.     while($func=$langdir->read()) {
  339.     if(substr($func, 0, 5) == "lang-") {
  340.             $menulist .= "$func ";
  341.     }
  342.     }
  343.     closedir($langdir->handle);
  344.     $menulist = explode(" ", $menulist);
  345.     sort($menulist);
  346.     for ($i=0; $i < sizeof($menulist); $i++) {
  347.         if($menulist[$i]!="") {
  348.         $tl = ereg_replace("lang-","",$menulist[$i]);
  349.         $tl = ereg_replace(".php","",$tl);
  350.         $altlang = ucfirst($tl);
  351.         $content .= "<a href=\"index.php?newlang=$tl\"><img src=\"images/language/flag-$tl.png\" border=\"0\" alt=\"$altlang\" title=\"$altlang\" hspace=\"3\" vspace=\"3\"></a> ";
  352.     }
  353.     }
  354.     $content .= "</font></center>";
  355.     themesidebox($title, $content);
  356.     } else {
  357.     $title = _SELECTLANGUAGE;
  358.     $content = "<center><font class=\"content\">"._SELECTGUILANG."<br><br></font>";
  359.     $content .= "<form action=\"index.php\" method=\"get\"><select name=\"newlanguage\" onChange=\"top.location.href=this.options[this.selectedIndex].value\">";
  360.         $handle=opendir('language');
  361.         while ($file = readdir($handle)) {
  362.         if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
  363.                 $langFound = $matches[1];
  364.                 $languageslist .= "$langFound ";
  365.             }
  366.         }
  367.         closedir($handle);
  368.         $languageslist = explode(" ", $languageslist);
  369.         sort($languageslist);
  370.         for ($i=0; $i < sizeof($languageslist); $i++) {
  371.         if($languageslist[$i]!="") {
  372.     $content .= "<option value=\"index.php?newlang=$languageslist[$i]\" ";
  373.         if($languageslist[$i]==$currentlang) $content .= " selected";
  374.     $content .= ">".ucfirst($languageslist[$i])."</option>\n";
  375.         }
  376.     }
  377.     $content .= "</select></form></center>";
  378.     themesidebox($title, $content);
  379.     }
  380. }
  381.  
  382. function ultramode() {
  383.     global $prefix, $dbi;
  384.     $ultra = "ultramode.txt";
  385.     $file = fopen("$ultra", "w");
  386.     fwrite($file, "General purpose self-explanatory file with news headlines\n");
  387.     $rfile=sql_query("select sid, aid, title, time, comments, topic from ".$prefix."_stories order by time DESC limit 0,10", $dbi);
  388.     while(list($sid, $aid, $title, $time, $comments, $topic) = sql_fetch_row($rfile, $dbi)) {
  389.     $rfile2=sql_query("select topictext, topicimage from ".$prefix."_topics where topicid='$topic'", $dbi);
  390.     list($topictext, $topicimage) = sql_fetch_row($rfile2, $dbi);
  391.     $content = "%%\n$title\n/modules.php?name=News&file=article&sid=$sid\n$time\n$aid\n$topictext\n$comments\n$topicimage\n";
  392.     fwrite($file, $content);
  393.     }
  394.     fclose($file);
  395. }
  396.  
  397. function cookiedecode($user) {
  398.     global $cookie, $prefix, $dbi, $user_prefix;
  399.     $user = base64_decode($user);
  400.     $cookie = explode(":", $user);
  401.     $result = sql_query("select pass from ".$user_prefix."_users where uname='$cookie[1]'", $dbi);
  402.     list($pass) = sql_fetch_row($result, $dbi);
  403.     if ($cookie[2] == $pass && $pass != "") {
  404.     return $cookie;
  405.     } else {
  406.     unset($user);
  407.     unset($cookie);
  408.     }
  409. }
  410.  
  411. function getusrinfo($user) {
  412.     global $userinfo, $user_prefix, $dbi;
  413.     $user2 = base64_decode($user);
  414.     $user3 = explode(":", $user2);
  415.     $result = sql_query("select uid, name, uname, email, femail, url, user_avatar, user_icq, user_occ, user_from, user_intrest, user_sig, user_viewemail, user_theme, user_aim, user_yim, user_msnm, pass, storynum, umode, uorder, thold, noscore, bio, ublockon, ublock, theme, commentmax, newsletter, broadcast, popmeson from ".$user_prefix."_users where uname='$user3[1]' and pass='$user3[2]'", $dbi);
  416.     if (sql_num_rows($result, $dbi) == 1) {
  417.         $userinfo = sql_fetch_array($result, $dbi);
  418.     }
  419.     return $userinfo;
  420. }
  421.  
  422. function FixQuotes ($what = "") {
  423.     $what = ereg_replace("'","''",$what);
  424.     while (eregi("\\\\'", $what)) {
  425.         $what = ereg_replace("\\\\'","'",$what);
  426.     }
  427.     return $what;
  428. }
  429.  
  430. /*********************************************************/
  431. /* text filter                                           */
  432. /*********************************************************/
  433.  
  434. function check_words($Message) {
  435.     global $EditedMessage;
  436.     include("config.php");
  437.     $EditedMessage = $Message;
  438.     if ($CensorMode != 0) {
  439.  
  440.     if (is_array($CensorList)) {
  441.         $Replace = $CensorReplace;
  442.         if ($CensorMode == 1) {
  443.         for ($i = 0; $i < count($CensorList); $i++) {
  444.             $EditedMessage = eregi_replace("$CensorList[$i]([^a-zA-Z0-9])","$Replace\\1",$EditedMessage);
  445.         }
  446.         } elseif ($CensorMode == 2) {
  447.         for ($i = 0; $i < count($CensorList); $i++) {
  448.             $EditedMessage = eregi_replace("(^|[^[:alnum:]])$CensorList[$i]","\\1$Replace",$EditedMessage);
  449.         }
  450.         } elseif ($CensorMode == 3) {
  451.         for ($i = 0; $i < count($CensorList); $i++) {
  452.             $EditedMessage = eregi_replace("$CensorList[$i]","$Replace",$EditedMessage);
  453.         }
  454.         }
  455.     }
  456.     }
  457.     return ($EditedMessage);
  458. }
  459.  
  460. function delQuotes($string){
  461.     /* no recursive function to add quote to an HTML tag if needed */
  462.     /* and delete duplicate spaces between attribs. */
  463.     $tmp="";    # string buffer
  464.     $result=""; # result string
  465.     $i=0;
  466.     $attrib=-1; # Are us in an HTML attrib ?   -1: no attrib   0: name of the attrib   1: value of the atrib
  467.     $quote=0;   # Is a string quote delimited opened ? 0=no, 1=yes
  468.     $len = strlen($string);
  469.     while ($i<$len) {
  470.     switch($string[$i]) { # What car is it in the buffer ?
  471.         case "\"": #"       # a quote.
  472.         if ($quote==0) {
  473.             $quote=1;
  474.         } else {
  475.             $quote=0;
  476.             if (($attrib>0) && ($tmp != "")) { $result .= "=\"$tmp\""; }
  477.             $tmp="";
  478.             $attrib=-1;
  479.         }
  480.         break;
  481.         case "=":           # an equal - attrib delimiter
  482.         if ($quote==0) {  # Is it found in a string ?
  483.             $attrib=1;
  484.             if ($tmp!="") $result.=" $tmp";
  485.             $tmp="";
  486.         } else $tmp .= '=';
  487.         break;
  488.         case " ":           # a blank ?
  489.         if ($attrib>0) {  # add it to the string, if one opened.
  490.             $tmp .= $string[$i];
  491.         }
  492.         break;
  493.         default:            # Other
  494.         if ($attrib<0)    # If we weren't in an attrib, set attrib to 0
  495.         $attrib=0;
  496.         $tmp .= $string[$i];
  497.         break;
  498.     }
  499.     $i++;
  500.     }
  501.     if (($quote!=0) && ($tmp != "")) {
  502.     if ($attrib==1) $result .= "=";
  503.     /* If it is the value of an atrib, add the '=' */
  504.     $result .= "\"$tmp\"";  /* Add quote if needed (the reason of the function ;-) */
  505.     }
  506.     return $result;
  507. }
  508.  
  509. function check_html ($str, $strip="") {
  510.     /* The core of this code has been lifted from phpslash */
  511.     /* which is licenced under the GPL. */
  512.     include("config.php");
  513.     if ($strip == "nohtml")
  514.         $AllowableHTML=array('');
  515.     $str = stripslashes($str);
  516.     $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>",
  517.                          '<\\1>', $str);
  518.                // Delete all spaces from html tags .
  519.     $str = eregi_replace("<a[^>]*href[[:space:]]*=[[:space:]]*\"?[[:space:]]*([^\" >]*)[[:space:]]*\"?[^>]*>",
  520.                          '<a href="\\1">', $str); # "
  521.                // Delete all attribs from Anchor, except an href, double quoted.
  522.     $str = eregi_replace("<[[:space:]]* img[[:space:]]*([^>]*)[[:space:]]*>", '', $str);
  523.            // Delete all img tags
  524.     $tmp = "";
  525.     while (ereg("<(/?[[:alpha:]]*)[[:space:]]*([^>]*)>",$str,$reg)) {
  526.         $i = strpos($str,$reg[0]);
  527.         $l = strlen($reg[0]);
  528.         if ($reg[1][0] == "/") $tag = strtolower(substr($reg[1],1));
  529.         else $tag = strtolower($reg[1]);
  530.         if ($a = $AllowableHTML[$tag])
  531.             if ($reg[1][0] == "/") $tag = "</$tag>";
  532.             elseif (($a == 1) || ($reg[2] == "")) $tag = "<$tag>";
  533.             else {
  534.               # Place here the double quote fix function.
  535.               $attrb_list=delQuotes($reg[2]);
  536.               // A VER
  537.               $attrb_list = ereg_replace("&","&",$attrb_list);
  538.               $tag = "<$tag" . $attrb_list . ">";
  539.             } # Attribs in tag allowed
  540.         else $tag = "";
  541.         $tmp .= substr($str,0,$i) . $tag;
  542.         $str = substr($str,$i+$l);
  543.     }
  544.     $str = $tmp . $str;
  545.     return $str;
  546.     exit;
  547.     /* Squash PHP tags unconditionally */
  548.     $str = ereg_replace("<\?","",$str);
  549.     return $str;
  550. }
  551.  
  552. function filter_text($Message, $strip="") {
  553.     global $EditedMessage;
  554.     check_words($Message);
  555.     $EditedMessage=check_html($EditedMessage, $strip);
  556.     return ($EditedMessage);
  557. }
  558.  
  559. /*********************************************************/
  560. /* formatting stories                                    */
  561. /*********************************************************/
  562.  
  563. function formatTimestamp($time) {
  564.     global $datetime, $locale;
  565.     setlocale ("LC_TIME", "$locale");
  566.     ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
  567.     $datetime = strftime(""._DATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
  568.     $datetime = ucfirst($datetime);
  569.     return($datetime);
  570. }
  571.  
  572. function formatAidHeader($aid) {
  573.     global $prefix, $dbi;
  574.     $holder = sql_query("SELECT url, email FROM ".$prefix."_authors where aid='$aid'", $dbi);
  575.     if (!$holder) {
  576.         echo _ERROR;
  577.     exit();
  578.     }
  579.     list($url, $email) = sql_fetch_row($holder, $dbi);
  580.     if (isset($url)) {
  581.     $aid = "<a href=\"$url\">$aid</a>";
  582.     } elseif (isset($email)) {
  583.     $aid = "<a href=\"mailto:$email\">$aid</a>";
  584.     } else {
  585.     $aid = $aid;
  586.     }
  587.     echo "$aid";
  588. }
  589.  
  590. function get_author($aid) {
  591.     global $prefix, $dbi;
  592.     $holder = sql_query("SELECT url, email FROM ".$prefix."_authors where aid='$aid'", $dbi);
  593.     if (!$holder) {
  594.         echo _ERROR;
  595.     exit();
  596.     }
  597.     list($url, $email) = sql_fetch_row($holder, $dbi);
  598.     if (isset($url)) {
  599.     $aid = "<a href=\"$url\">$aid</a>";
  600.     } elseif (isset($email)) {
  601.     $aid = "<a href=\"mailto:$email\">$aid</a>";
  602.     } else {
  603.     $aid = $aid;
  604.     }
  605.     return($aid);
  606. }
  607.  
  608. function themepreview($title, $hometext, $bodytext="", $notes="") {
  609.     echo "<b>$title</b><br><br>$hometext";
  610.     if ($bodytext != "") {
  611.     echo "<br><br>$bodytext";
  612.     }
  613.     if ($notes != "") {
  614.     echo "<br><br><b>"._NOTE."</b> <i>$notes</i>";
  615.     }
  616. }
  617.  
  618. function adminblock() {
  619.     global $admin, $prefix, $dbi;
  620.     if (is_admin($admin)) {
  621.     $result = sql_query("select title, content from ".$prefix."_blocks where bkey='admin'", $dbi);
  622.     while(list($title, $content) = sql_fetch_row($result, $dbi)) {
  623.         $content = "<font class=\"content\">$content</font>";
  624.         themesidebox($title, $content);
  625.     }
  626.     $title = ""._WAITINGCONT."";
  627.     $num = sql_num_rows(sql_query("select * from ".$prefix."_queue", $dbi), $dbi);
  628.     $content = "<font class=\"content\">";
  629.     $content .= "<strong><big>·</big></strong> <a href=\"admin.php?op=submissions\">"._SUBMISSIONS."</a>: $num<br>";
  630.     $num = sql_num_rows(sql_query("select * from ".$prefix."_reviews_add", $dbi), $dbi);
  631.     $content .= "<strong><big>·</big></strong> <a href=\"admin.php?op=reviews\">"._WREVIEWS."</a>: $num<br>";
  632.     $num = sql_num_rows(sql_query("select * from ".$prefix."_links_newlink", $dbi), $dbi);
  633.     $brokenl = sql_num_rows(sql_query("select * from ".$prefix."_links_modrequest where brokenlink='1'", $dbi), $dbi);
  634.     $modreql = sql_num_rows(sql_query("select * from ".$prefix."_links_modrequest where brokenlink='0'", $dbi), $dbi);
  635.     $content .= "<strong><big>·</big></strong> <a href=\"admin.php?op=Links\">"._WLINKS."</a>: $num<br>";
  636.     $content .= "<strong><big>·</big></strong> <a href=\"admin.php?op=LinksListModRequests\">"._MODREQLINKS."</a>: $modreql<br>";
  637.     $content .= "<strong><big>·</big></strong> <a href=\"admin.php?op=LinksListBrokenLinks\">"._BROKENLINKS."</a>: $brokenl<br>";
  638.     $num = sql_num_rows(sql_query("select * from ".$prefix."_downloads_newdownload", $dbi), $dbi);
  639.     $brokend = sql_num_rows(sql_query("select * from ".$prefix."_downloads_modrequest where brokendownload='1'", $dbi), $dbi);
  640.     $modreqd = sql_num_rows(sql_query("select * from ".$prefix."_downloads_modrequest where brokendownload='0'", $dbi), $dbi);
  641.     $content .= "<strong><big>·</big></strong> <a href=\"admin.php?op=downloads\">"._UDOWNLOADS."</a>: $num<br>";
  642.     $content .= "<strong><big>·</big></strong> <a href=\"admin.php?op=DownloadsListModRequests\">"._MODREQDOWN."</a>: $modreqd<br>";
  643.     $content .= "<strong><big>·</big></strong> <a href=\"admin.php?op=DownloadsListBrokenDownloads\">"._BROKENDOWN."</a>: $brokend<br></font>";
  644.     themesidebox($title, $content);
  645.     }
  646. }
  647.  
  648. function loginbox() {
  649.     global $user;
  650.     if (!is_user($user)) {
  651.     $title = _LOGIN;
  652.     $boxstuff = "<form action=\"modules.php?name=Your_Account\" method=\"post\">";
  653.     $boxstuff .= "<center><font class=\"content\">"._NICKNAME."<br>";
  654.     $boxstuff .= "<input type=\"text\" name=\"uname\" size=\"8\" maxlength=\"25\"><br>";
  655.     $boxstuff .= ""._PASSWORD."<br>";
  656.     $boxstuff .= "<input type=\"password\" name=\"pass\" size=\"8\" maxlength=\"20\"><br>";
  657.     $boxstuff .= "<input type=\"hidden\" name=\"op\" value=\"login\">";
  658.     $boxstuff .= "<input type=\"submit\" value=\""._LOGIN."\"></font></center></form>";
  659.     $boxstuff .= "<center><font class=\"content\">"._ASREGISTERED."</font></center>";
  660.     themesidebox($title, $boxstuff);
  661.     }
  662. }
  663.  
  664. function userblock() {
  665.     global $user, $cookie, $prefix, $dbi, $user_prefix;
  666.     if((is_user($user)) AND ($cookie[8])) {
  667.     $getblock = sql_query("select ublock from ".$user_prefix."_users where uid='$cookie[0]'", $dbi);
  668.     $title = ""._MENUFOR." $cookie[1]";
  669.     list($ublock) = sql_fetch_row($getblock, $dbi);
  670.     themesidebox($title, $ublock);
  671.     }
  672. }
  673.  
  674. function getTopics($s_sid) {
  675.     global $topicname, $topicimage, $topictext, $prefix, $dbi;
  676.     $sid = $s_sid;
  677.     $result = sql_query("SELECT topic FROM ".$prefix."_stories where sid='$sid'", $dbi);
  678.     list($topic) = sql_fetch_row($result, $dbi);
  679.     $result = sql_query("SELECT topicid, topicname, topicimage, topictext FROM ".$prefix."_topics where topicid='$topic'", $dbi);
  680.     list($topicid, $topicname, $topicimage, $topictext) = sql_fetch_row($result, $dbi);
  681. }
  682.  
  683. function headlines($bid, $cenbox=0) {
  684.     global $prefix, $dbi;
  685.     $result = sql_query("select title, content, url, refresh, time from ".$prefix."_blocks where bid='$bid'", $dbi);
  686.     list($title, $content, $url, $refresh, $otime) = sql_fetch_row($result, $dbi);
  687.     $past = time()-$refresh;
  688.     if ($otime < $past) {
  689.     $btime = time();
  690.     $rdf = parse_url($url);
  691.     $fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15);
  692.     if (!$fp) {
  693.         $content = "";
  694.         $result = sql_query("update ".$prefix."_blocks set content='$content', time='$btime' where bid='$bid'", $dbi);
  695.         $cont = 0;
  696.         if ($cenbox == 0) {
  697.         themesidebox($title, $content);
  698.         } else {
  699.         themecenterbox($title, $content);
  700.         }
  701.         return;
  702.     }
  703.     if ($fp) {
  704.         fputs($fp, "GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0\r\n");
  705.         fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n");
  706.         $string    = "";
  707.         while(!feof($fp)) {
  708.             $pagetext = fgets($fp,300);
  709.             $string .= chop($pagetext);
  710.         }
  711.         fputs($fp,"Connection: close\r\n\r\n");
  712.         fclose($fp);
  713.         $items = explode("</item>",$string);
  714.         $content = "<font class=\"content\">";
  715.         for ($i=0;$i<10;$i++) {
  716.         $link = ereg_replace(".*<link>","",$items[$i]);
  717.         $link = ereg_replace("</link>.*","",$link);
  718.         $title2 = ereg_replace(".*<title>","",$items[$i]);
  719.         $title2 = ereg_replace("</title>.*","",$title2);
  720.         if ($items[$i] == "" AND $cont != 1) {
  721.             $content = "";
  722.             sql_query("update ".$prefix."_blocks set content='$content', time='$btime' where bid='$bid'", $dbi);
  723.             $cont = 0;
  724.             if ($cenbox == 0) {
  725.             themesidebox($title, $content);
  726.             } else {
  727.             themecenterbox($title, $content);
  728.             }
  729.             return;
  730.         } else {
  731.             if (strcmp($link,$title2) AND $items[$i] != "") {
  732.             $cont = 1;
  733.             $content .= "<strong><big>·</big></strong><a href=\"$link\" target=\"new\">$title2</a><br>\n";
  734.             }
  735.         }
  736.         }
  737.  
  738.     }
  739.     sql_query("update ".$prefix."_blocks set content='$content', time='$btime' where bid='$bid'", $dbi);
  740.     }
  741.     $siteurl = ereg_replace("http://","",$url);
  742.     $siteurl = explode("/",$siteurl);
  743.     if (($cont == 1) OR ($content != "")) {
  744.     $content .= "<br><a href=\"http://$siteurl[0]\" target=\"blank\"><b>"._HREADMORE."</b></a></font>";
  745.     } elseif (($cont == 0) OR ($content == "")) {
  746.     $content = "<font class=\"content\">"._RSSPROBLEM."</font>";
  747.     }
  748.     if ($cenbox == 0) {
  749.     themesidebox($title, $content);
  750.     } else {
  751.     themecenterbox($title, $content);
  752.     }
  753. }
  754.  
  755. function automated_news() {
  756.     global $prefix, $multilingual, $currentlang, $dbi;
  757.     if ($multilingual == 1) {
  758.         $querylang = "WHERE (alanguage='$currentlang' OR alanguage='')"; /* the OR is needed to display stories who are posted to ALL languages */
  759.     } else {
  760.         $querylang = "";
  761.     }
  762.     $today = getdate();
  763.     $day = $today[mday];
  764.     if ($day < 10) {
  765.     $day = "0$day";
  766.     }
  767.     $month = $today[mon];
  768.     if ($month < 10) {
  769.     $month = "0$month";
  770.     }
  771.     $year = $today[year];
  772.     $hour = $today[hours];
  773.     $min = $today[minutes];
  774.     $sec = "00";
  775.     $result = sql_query("select anid, time from ".$prefix."_autonews $querylang", $dbi);
  776.     while(list($anid, $time) = sql_fetch_row($result, $dbi)) {
  777.     ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $date);
  778.     if (($date[1] <= $year) AND ($date[2] <= $month) AND ($date[3] <= $day)) {
  779.         if (($date[4] < $hour) AND ($date[5] >= $min) OR ($date[4] <= $hour) AND ($date[5] <= $min)) {
  780.         $result2 = sql_query("select catid, aid, title, time, hometext, bodytext, topic, informant, notes, ihome, alanguage, acomm from ".$prefix."_autonews where anid='$anid'", $dbi);
  781.         while(list($catid, $aid, $title, $a_time, $hometext, $bodytext, $topic, $author, $notes, $ihome, $alanguage, $acomm) = sql_fetch_row($result2, $dbi)) {
  782.             $title = stripslashes(FixQuotes($title));
  783.             $hometext = stripslashes(FixQuotes($hometext));
  784.             $bodytext = stripslashes(FixQuotes($bodytext));
  785.             $notes = stripslashes(FixQuotes($notes));
  786.             sql_query("insert into ".$prefix."_stories values (NULL, '$catid', '$aid', '$title', '$a_time', '$hometext', '$bodytext', '0', '0', '$topic', '$author', '$notes', '$ihome', '$alanguage', '$acomm', '0', '0', '0', '0')", $dbi);
  787.             sql_query("delete from ".$prefix."_autonews where anid='$anid'", $dbi);
  788.         }
  789.         }
  790.     }
  791.     }
  792. }
  793.  
  794. function themecenterbox($title, $content) {
  795.     OpenTable();
  796.     echo "<center><font class=\"option\"><b>$title</b></font></center><br>"
  797.     ."$content";
  798.     CloseTable();
  799.     echo "<br>";
  800. }
  801.  
  802. function public_message() {
  803.     global $prefix, $user_prefix, $dbi, $user, $admin, $p_msg, $cookie, $broadcast_msg;
  804.     if ($broadcast_msg == 1) {
  805.     if (is_user($user)) {
  806.         cookiedecode($user);
  807.     $result = sql_query("select broadcast from ".$user_prefix."_users where uname='$cookie[1]'", $dbi);
  808.     list ($upref) = sql_fetch_row($result, $dbi);
  809.     if ($upref == 1) {
  810.         $t_off = "<br><p align=\"right\">[ <a href=\"modules.php?name=Your_Account&op=edithome\"><font color=\"FFFFFF\" size=\"2\">"._TURNOFFMSG."</font></a> ]</font>";
  811.         $pm_show = 1;
  812.     } else {
  813.         $pm_show = 0;
  814.     }
  815.     } else {
  816.     $t_off = "";
  817.     }
  818.     if (!is_user($user) OR (is_user($user) AND ($pm_show == 1))) {
  819.     $c_mid = base64_decode($p_msg);
  820.     $result = sql_query("select mid, content, date, who from ".$prefix."_public_messages WHERE mid > '$c_mid' order by date ASC limit 1", $dbi);
  821.     list($mid, $content, $tdate, $who) = sql_fetch_row($result, $dbi);
  822.     if ((!isset($c_mid)) OR ($c_mid = $mid)) {
  823.             $public_msg = "<br><table width=\"90%\" border=\"1\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"FFFFFF\" align=\"center\"><tr><td>\n";
  824.             $public_msg .= "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\" bgcolor=\"FF0000\"><tr><td>\n";
  825.             $public_msg .= "<font color=\"FFFFFF\" size=\"3\"><b>"._BROADCASTFROM." <a href=\"modules.php?name=Your_Account&op=userinfo&uname=$who\"><font color=\"FFFFFF\" size=\"3\">$who</font></a>: \"$content\"</b>";
  826.         $public_msg .= "$t_off";
  827.         $public_msg .= "</td></tr></table>";
  828.             $public_msg .= "</td></tr></table>";
  829.         $ref_date = $tdate+600;
  830.         $actual_date = time();
  831.         if ($actual_date >= $ref_date) {
  832.         $public_msg = "";
  833.         $numrows = sql_num_rows(sql_query("select * from ".$prefix."_public_messages", $dbi), $dbi);
  834.         if ($numrows == 1) {
  835.             $res = sql_query("delete from ".$prefix."_public_messages", $dbi);
  836.             $mid = 0;
  837.         } else {
  838.             $res = sql_query("delete from ".$prefix."_public_messages where mid='$mid'", $dbi);
  839.         }
  840.         }
  841.         if ($mid == 0 OR $mid == "") {
  842.         setcookie("p_msg");
  843.         } else {
  844.             $mid = base64_encode($mid);
  845.         setcookie("p_msg",$mid,time()+600);
  846.         }
  847.     }
  848.     }
  849.     } else {
  850.     $public_msg = "";
  851.     }
  852.     return($public_msg);
  853. }
  854.  
  855. function get_theme() {
  856.     global $user, $cookie, $Default_Theme;
  857.     if(is_user($user)) {
  858.     $user2 = base64_decode($user);
  859.     $t_cookie = explode(":", $user2);
  860.     if($t_cookie[9]=="") $t_cookie[9]=$Default_Theme;
  861.     if(isset($theme)) $t_cookie[9]=$theme;
  862.     if(!$tfile=@opendir("themes/$t_cookie[9]")) {
  863.         $ThemeSel = $Default_Theme;
  864.     } else {
  865.         $ThemeSel = $t_cookie[9];
  866.     }
  867.     } else {
  868.     $ThemeSel = $Default_Theme;
  869.     }
  870.     return($ThemeSel);
  871. }
  872.  
  873. ?>