home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / modules / submit_news / index.php
Encoding:
PHP Script  |  2002-09-16  |  11.0 KB  |  271 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. $pagetitle = "- "._SUBMITNEWS."";
  22.  
  23. function defaultDisplay() {
  24.     global $AllowableHTML, $prefix, $user, $cookie, $anonymous, $currentlang, $multilingual, $dbi, $module_name;
  25.     include ('header.php');
  26.     OpenTable();
  27.     echo "<center><font class=\"title\"><b>"._SUBMITNEWS."</b></font><br><br>";
  28.     echo "<font class=\"content\"><i>"._SUBMITADVICE."</i></font></center><br>";
  29.     CloseTable();
  30.     echo "<br>";
  31.     OpenTable();
  32.     if (is_user($user)) getusrinfo($user);
  33.     echo "<p><form action=\"modules.php?name=$module_name\" method=\"post\">"
  34.     ."<b>"._YOURNAME.":</b> ";
  35.     if (is_user($user)) {
  36.     cookiedecode($user);
  37.     echo "<a href=\"modules.php?name=Your_Account\">$cookie[1]</a> <font class=\"content\">[ <a href=\"modules.php?name=Your_Account&op=logout\">"._LOGOUT."</a> ]</font>";
  38.     } else {
  39.         echo "$anonymous <font class=\"content\">[ <a href=\"modules.php?name=Your_Account\">"._NEWUSER."</a> ]</font>";
  40.     }
  41.     echo "<br><br>"
  42.         ."<b>"._SUBTITLE."</b> "
  43.         ."("._BEDESCRIPTIVE.")<br>"
  44.         ."<input type=\"text\" name=\"subject\" size=\"50\" maxlength=\"80\"><br><font class=\"content\">("._BADTITLES.")</font>"
  45.         ."<br><br>"
  46.         ."<b>"._TOPIC.":</b> <select name=\"topic\">";
  47.     $toplist = sql_query("select topicid, topictext from ".$prefix."_topics order by topictext", $dbi);
  48.     echo "<option value=\"\">"._SELECTTOPIC."</option>\n";
  49.     while(list($topicid, $topics) = sql_fetch_row($toplist, $dbi)) {
  50.         if ($topicid==$topic) {
  51.         $sel = "selected ";
  52.     }
  53.         echo "<option $sel value=\"$topicid\">$topics</option>\n";
  54.     $sel = "";
  55.     }
  56.     echo "</select>";
  57.     if ($multilingual == 1) {
  58.     echo "<br><br><b>"._LANGUAGE.": </b>"
  59.         ."<select name=\"alanguage\">";
  60.     $handle=opendir('language');
  61.     while ($file = readdir($handle)) {
  62.         if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
  63.             $langFound = $matches[1];
  64.             $languageslist .= "$langFound ";
  65.         }
  66.     }
  67.     closedir($handle);
  68.     $languageslist = explode(" ", $languageslist);
  69.     sort($languageslist);
  70.     for ($i=0; $i < sizeof($languageslist); $i++) {
  71.         if($languageslist[$i]!="") {
  72.         echo "<option value=\"$languageslist[$i]\" ";
  73.         if($languageslist[$i]==$currentlang) echo "selected";
  74.         echo ">".ucfirst($languageslist[$i])."</option>\n";
  75.         }
  76.     }
  77.     echo "</select>";
  78.     } else {
  79.     echo "<input type=\"hidden\" name=\"alanguage\" value=\"$language\">";
  80.     }
  81.     echo "<br><br>"
  82.         ."<b>"._STORYTEXT.":</b> ("._HTMLISFINE.")<br>"
  83.     ."<textarea cols=\"50\" rows=\"12\" name=\"story\"></textarea><br>"
  84.         ."<br><br><b>"._EXTENDEDTEXT.":</b><br>"
  85.     ."<textarea cols=\"50\" rows=\"12\" name=\"storyext\"></textarea><br>"
  86.     ."("._AREYOUSURE.")</font><br><br>"
  87.         ."<font class=\"content\">"._ALLOWEDHTML."<br>";
  88.     while (list($key,) = each($AllowableHTML)) echo " <".$key.">";
  89.     echo "<br><br><input type=\"submit\" name=\"op\" value=\""._PREVIEW."\">  "
  90.     ."<select name=\"posttype\">\n"
  91.     ."<option value=\"exttrans\">"._EXTRANS."</option>\n"
  92.     ."<option value=\"html\" >"._HTMLFORMATED."</option>\n"
  93.     ."<option value=\"plaintext\" selected>"._PLAINTEXT."</option>\n"
  94.     ."</select>"
  95.     ."<br>("._SUBPREVIEW.")</form>";
  96.     CloseTable();
  97.     include ('footer.php');
  98. }
  99.  
  100. function PreviewStory($name, $address, $subject, $story, $storyext, $topic, $alanguage, $posttype) {
  101.     global $user, $cookie, $bgcolor1, $bgcolor2, $anonymous, $prefix, $multilingual, $AllowableHTML, $dbi, $module_name;
  102.     include ('header.php');
  103.     $subject = stripslashes($subject);
  104.     $story = stripslashes($story);
  105.     $storyext = stripslashes($storyext);
  106.     if ($posttype=="exttrans") {
  107.         $f_story = nl2br(htmlspecialchars($story));
  108.     $f_storyext = nl2br(htmlspecialchars($storyext));
  109.     } elseif ($posttype=="plaintext") {
  110.         $f_story = nl2br($story);
  111.     $f_storyext = nl2br($storyext);
  112.     } else {
  113.     $f_story = $story;
  114.     $f_storyext = $storyext;
  115.     }
  116.     $story2 = "$f_story<br><br>$f_storyext";
  117.     OpenTable();
  118.     echo "<center><font class=\"title\"><b>"._NEWSUBPREVIEW."</b></font>";
  119.     CloseTable();
  120.     echo "<br>";
  121.     OpenTable();
  122.     echo "<center><i>"._STORYLOOK."</i></center><br><br>";
  123.     echo "<table width=\"70%\" bgcolor=\"$bgcolor2\" cellpadding=\"0\" cellspacing=\"1\" border=\"0\"align=\"center\"><tr><td>"
  124.     ."<table width=\"100%\" bgcolor=\"$bgcolor1\" cellpadding=\"8\" cellspacing=\"1\" border=\"0\"><tr><td>";
  125.     if ($topic=="") {
  126.         $topicimage="AllTopics.gif";
  127.         $warning = "<center><blink><b>"._SELECTTOPIC."</b></blink></center>";
  128.     } else {
  129.         $warning = "";
  130.         $result = sql_query("select topicimage from ".$prefix."_topics where topicid='$topic'", $dbi);
  131.         list($topicimage) = sql_fetch_row($result, $dbi);
  132.     }
  133.     echo "<img src=\"images/topics/$topicimage\" border=\"0\" align=\"right\">";
  134.     themepreview($subject, $story2);
  135.     echo "$warning"
  136.     ."</td></tr></table></td></tr></table>"
  137.     ."<br><br><center><font class=\"tiny\">"._CHECKSTORY."</font></center>";
  138.     CloseTable();
  139.     echo "<br>";
  140.     OpenTable();
  141.     echo "<p><form action=\"modules.php?name=$module_name\" method=\"post\">"
  142.     ."<b>"._YOURNAME.":</b> ";
  143.     if (is_user($user)) {
  144.         cookiedecode($user);
  145.     echo "<a href=\"modules.php?name=Your_Account\">$cookie[1]</a> <font class=\"content\">[ <a href=\"modules.php?name=Your_Account&op=logout\">"._LOGOUT."</a> ]</font>";
  146.     } else {
  147.     echo "$anonymous";
  148.     }
  149.     echo "<br><br><b>"._SUBTITLE.":</b><br>"
  150.     ."<input type=\"text\" name=\"subject\" size=\"50\" maxlength=\"80\" value=\"$subject\">"
  151.     ."<br><br><b>"._TOPIC.": </b><select name=\"topic\">";
  152.     $toplist = sql_query("select topicid, topictext from ".$prefix."_topics order by topictext", $dbi);
  153.     echo "<OPTION VALUE=\"\">"._SELECTTOPIC."</option>\n";
  154.     while(list($topicid, $topics) = sql_fetch_row($toplist, $dbi)) {
  155.         if ($topicid==$topic) { $sel = "selected "; }
  156.         echo "<option $sel value=\"$topicid\">$topics</option>\n";
  157.         $sel = "";
  158.         }
  159.     echo "</select>";
  160.     if ($multilingual == 1) {
  161.     echo "<br><br><b>"._LANGUAGE.": </b>"
  162.         ."<select name=\"alanguage\">";
  163.     $handle=opendir('language');
  164.     while ($file = readdir($handle)) {
  165.         if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
  166.             $langFound = $matches[1];
  167.             $languageslist .= "$langFound ";
  168.         }
  169.     }
  170.     closedir($handle);
  171.     $languageslist = explode(" ", $languageslist);
  172.     sort($languageslist);
  173.     for ($i=0; $i < sizeof($languageslist); $i++) {
  174.         if($languageslist[$i]!="") {
  175.         echo "<option value=\"$languageslist[$i]\" ";
  176.         if($languageslist[$i]==$alanguage) echo "selected";
  177.         echo ">".ucfirst($languageslist[$i])."</option>\n";
  178.         }
  179.     }
  180.     echo "</select>";
  181.     }
  182.     echo "<br><br><b>"._STORYTEXT.":</b> ("._HTMLISFINE.")<br>"
  183.         ."<textarea cols=\"50\" rows=\"12\" name=\"story\">$story</textarea><br>"
  184.     ."<br><b>"._EXTENDEDTEXT.":</b><br>"
  185.     ."<textarea cols=\"50\" rows=\"12\" name=\"storyext\">$storyext</textarea><br>"
  186.     ."<font class=\"content\">("._AREYOUSURE.")</font><br><br>"
  187.     .""._ALLOWEDHTML."<br>";
  188.     while (list($key,) = each($AllowableHTML)) echo " <".$key.">";
  189.     echo "<br><br>"
  190.         ."<input type=\"submit\" name=\"op\" value=\""._PREVIEW."\">  "
  191.     ."<input type=\"submit\" name=\"op\" value=\""._OK."\">  "
  192.     ."<select name=\"posttype\"><option value=\"exttrans\"";
  193.     if ($posttype=="exttrans") {
  194.         echo " selected";
  195.     }
  196.     echo ">"._EXTRANS."</option>\n"
  197.     ."<OPTION value=\"html\"";;
  198.     if ($posttype=="html") {
  199.         echo " selected";
  200.     }
  201.     echo ">"._HTMLFORMATED."</option>\n"
  202.     ."<OPTION value=\"plaintext\"";
  203.     if (($posttype!="exttrans") && ($posttype!="html")) {
  204.         echo " selected";
  205.     }
  206.     echo ">"._PLAINTEXT."</option></select>"
  207.     ."</form>";
  208.     CloseTable();
  209.     include ('footer.php');
  210. }
  211.  
  212. function submitStory($name, $address, $subject, $story, $storyext, $topic, $alanguage, $posttype) {
  213.     global $user, $EditedMessage, $cookie, $anonymous, $notify, $notify_email, $notify_subject, $notify_message, $notify_from, $prefix, $dbi;
  214.     if (is_user($user)) {
  215.         cookiedecode($user);
  216.     $uid = $cookie[0];
  217.     $name = $cookie[1];
  218.     } else {
  219.         $uid = 1;
  220.     $name = "$anonymous";
  221.     }
  222.     $subject = ereg_replace("\"", "''", $subject);
  223.     $subject = FixQuotes(filter_text($subject, "nohtml"));
  224.     if($posttype=="exttrans") {
  225.         $story = FixQuotes(nl2br(htmlspecialchars(check_words($story))));
  226.     $storyext = FixQuotes(nl2br(htmlspecialchars(check_words($storyext))));
  227.     } elseif($posttype=="plaintext") {
  228.         $story = FixQuotes(nl2br(filter_text($story)));
  229.     $storyext = FixQuotes(nl2br(filter_text($storyext)));
  230.     } else {
  231.     $story = FixQuotes(filter_text($story));
  232.     $storyext = FixQuotes(filter_text($storyext));
  233.     }
  234.     $result = sql_query("insert into ".$prefix."_queue values (NULL, '$uid', '$name', '$subject', '$story', '$storyext', now(), '$topic', '$alanguage')", $dbi);
  235.     if(!$result) {
  236.         echo ""._ERROR."<br>";
  237.     exit();
  238.     }
  239.     if($notify) {
  240.     $notify_message = "$notify_message\n\n\n========================================================\n$subject\n\n\n$story\n\n$storyext\n\n$name";
  241.         mail($notify_email, $notify_subject, $notify_message, "From: $notify_from\nX-Mailer: PHP/" . phpversion());
  242.     }
  243.     include ('header.php');
  244.     OpenTable();
  245.     $result = sql_query("select * from ".$prefix."_queue", $dbi);
  246.     $waiting = sql_num_rows($result, $dbi);
  247.     echo "<center><font class=\"title\">"._SUBSENT."</font><br><br>"
  248.     ."<font class=\"content\"><b>"._THANKSSUB."</b><br><br>"
  249.     .""._SUBTEXT.""
  250.     ."<br>"._WEHAVESUB." $waiting "._WAITING."";
  251.     CloseTable();
  252.     include ('footer.php');
  253. }
  254.  
  255. switch($op) {
  256.  
  257.     case ""._PREVIEW."":
  258.     PreviewStory($name, $address, $subject, $story, $storyext, $topic, $alanguage, $posttype);
  259.     break;
  260.  
  261.     case ""._OK."":
  262.     SubmitStory($name, $address, $subject, $story, $storyext, $topic, $alanguage, $posttype);
  263.     break;
  264.  
  265.     default:
  266.     defaultDisplay();
  267.     break;
  268.  
  269. }
  270.  
  271. ?>