PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/submitnews.php

https://github.com/CasperGemini/e107
PHP | 235 lines | 191 code | 33 blank | 11 comment | 40 complexity | 150eb32755d47508fa08074ee0fbbd91 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2013 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. */
  10. if(!empty($_POST) && !isset($_POST['e-token']))
  11. {
  12. // set e-token so it can be processed by class2
  13. $_POST['e-token'] = '';
  14. }
  15. require_once("class2.php");
  16. include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_'.e_PAGE);
  17. require_once(HEADERF);
  18. if (!isset($pref['subnews_class']))
  19. {
  20. $pref['subnews_class'] = e_UC_MEMBER;
  21. }
  22. if (!check_class($pref['subnews_class']))
  23. {
  24. $ns->tablerender(NWSLAN_12, NWSLAN_11);
  25. require_once(FOOTERF);
  26. exit;
  27. }
  28. if (isset($_POST['submitnews_submit']) && $_POST['submitnews_title'] && $_POST['submitnews_item'])
  29. {
  30. $ip = e107::getIPHandler()->getIP(FALSE);
  31. $fp = new floodprotect;
  32. if ($fp->flood("submitnews", "submitnews_datestamp") == FALSE)
  33. {
  34. header("location:".e_BASE."index.php");
  35. exit;
  36. }
  37. $submitnews_user = (USER ? USERNAME : trim($tp->toDB($_POST['submitnews_name'])));
  38. $submitnews_email = (USER ? USEREMAIL : trim(check_email($tp->toDB($_POST['submitnews_email']))));
  39. $submitnews_title = $tp->toDB($_POST['submitnews_title']);
  40. $submitnews_item = $tp->toDB($_POST['submitnews_item']);
  41. $submitnews_item = str_replace("src=&quot;e107_images", "src=&quot;".SITEURL."e107_images", $submitnews_item);
  42. $submitnews_file = "";
  43. $submitnews_error = FALSE;
  44. if (!$submitnews_user || !$submitnews_email)
  45. {
  46. $message = SUBNEWSLAN_7;
  47. $submitnews_error = TRUE;
  48. }
  49. // ==== Process File Upload ====
  50. if (FILE_UPLOADS && $_FILES['file_userfile'] && varsettrue($pref['subnews_attach']) && varsettrue($pref['upload_enabled']) && check_class($pref['upload_class']))
  51. {
  52. require_once(e_HANDLER.'upload_handler.php');
  53. $uploaded = process_uploaded_files(e_UPLOAD, FALSE, array('file_mask' => 'jpg,gif,png', 'max_file_count' => 1));
  54. if (($uploaded === FALSE) || !is_array($uploaded))
  55. { // Non-specific error
  56. $submitnews_error = TRUE;
  57. $message = SUBNEWSLAN_8;
  58. }
  59. else
  60. {
  61. $submitnews_filearray = array();
  62. foreach($uploaded as $c=>$v)
  63. {
  64. if (varset($uploaded[$c]['error'],0) != 0)
  65. {
  66. $submitnews_error = TRUE;
  67. $message = handle_upload_messages($uploaded);
  68. }
  69. else
  70. {
  71. if (isset($uploaded[$c]['name']) && isset($uploaded[$c]['type']) && isset($uploaded[$c]['size']))
  72. {
  73. $filename = $uploaded[$c]['name'];
  74. $filetype = $uploaded[$c]['type'];
  75. $filesize = $uploaded[$c]['size'];
  76. $fileext = substr(strrchr($filename, "."), 1);
  77. $today = getdate();
  78. $submitnews_file = USERID."_".$today[0]."_".$c."_".str_replace(" ", "_", substr($submitnews_title, 0, 6)).".".$fileext;
  79. if (is_numeric($pref['subnews_resize']) && ($pref['subnews_resize'] > 30) && ($pref['subnews_resize'] < 5000))
  80. {
  81. require_once(e_HANDLER.'resize_handler.php');
  82. if (!resize_image(e_UPLOAD.$filename, e_UPLOAD.$submitnews_file, $pref['subnews_resize']))
  83. {
  84. rename(e_UPLOAD.$filename, e_UPLOAD.$submitnews_file);
  85. }
  86. }
  87. elseif ($filename)
  88. {
  89. rename(e_UPLOAD.$filename, e_UPLOAD.$submitnews_file);
  90. }
  91. }
  92. }
  93. if ($filename && file_exists(e_UPLOAD.$submitnews_file))
  94. {
  95. $submitnews_filearray[] = $submitnews_file;
  96. }
  97. }
  98. }
  99. }
  100. if ($submitnews_error === FALSE)
  101. {
  102. $sql->insert("submitnews", "0, '$submitnews_user', '$submitnews_email', '$submitnews_title', '".intval($_POST['cat_id'])."', '$submitnews_item', '".time()."', '$ip', '0', '".implode(',',$submitnews_filearray)."' ");
  103. $edata_sn = array("user" => $submitnews_user, "email" => $submitnews_email, "itemtitle" => $submitnews_title, "catid" => intval($_POST['cat_id']), "item" => $submitnews_item, "image" => $submitnews_file, "ip" => $ip);
  104. $e_event->trigger("subnews", $edata_sn);
  105. $mes = e107::getMessage();
  106. $mes->addSuccess(LAN_134);
  107. echo $mes->render();
  108. // $ns->tablerender(LAN_133, "<div style='text-align:center'>".LAN_134."</div>");
  109. require_once(FOOTERF);
  110. exit;
  111. }
  112. else
  113. {
  114. message_handler("P_ALERT", $message);
  115. }
  116. }
  117. if (!defined("USER_WIDTH")) { define("USER_WIDTH","width:95%"); }
  118. $text = "
  119. <div style='text-align:center'>
  120. <form id='dataform' method='post' action='".e_SELF."' enctype='multipart/form-data' onsubmit='return frmVerify()'>
  121. <table class='table fborder'>";
  122. if (!empty($pref['news_subheader']))
  123. {
  124. $text .= "
  125. <tr>
  126. <td colspan='2' class='forumheader3'>".$tp->toHTML($pref['news_subheader'], TRUE, "TITLE")."<br /></td>
  127. </tr>";
  128. }
  129. if (!USER)
  130. {
  131. $text .= "
  132. <tr>
  133. <td style='width:20%' class='forumheader3'>".LAN_7."</td>
  134. <td style='width:80%' class='forumheader3'>
  135. <input class='tbox' type='text' name='submitnews_name' size='60' value='".$tp->toHTML($submitnews_user,FALSE,'USER_TITLE')."' maxlength='100' required />
  136. </td>
  137. </tr>
  138. <tr>
  139. <td style='width:20%' class='forumheader3'>".LAN_112."</td>
  140. <td style='width:80%' class='forumheader3'>
  141. <input class='tbox' type='text' name='submitnews_email' size='60' value='".$tp->toHTML($submitnews_email, FALSE, 'LINKTEXT')."' maxlength='100' required />
  142. </td>
  143. </tr>";
  144. }
  145. $text .= "
  146. <tr>
  147. <td style='width:20%' class='forumheader3'>".NWSLAN_6.": </td>
  148. <td style='width:80%' class='forumheader3'>";
  149. if (!$sql->db_Select("news_category"))
  150. {
  151. $text .= NWSLAN_10;
  152. }
  153. else
  154. {
  155. $text .= "
  156. <select name='cat_id' class='tbox'>";
  157. while (list($cat_id, $cat_name, $cat_icon) = $sql->db_Fetch(MYSQL_NUM))
  158. {
  159. $sel = (varset($_POST['cat_id'],'') == $cat_id) ? "selected='selected'" : "";
  160. $text .= "<option value='{$cat_id}' {$sel}>".$tp->toHTML($cat_name, FALSE, "defs")."</option>";
  161. }
  162. $text .= "</select>";
  163. }
  164. $text .= "
  165. </td>
  166. </tr>
  167. <tr>
  168. <td style='width:20%' class='forumheader3'>".LAN_62."</td>
  169. <td style='width:80%' class='forumheader3'>
  170. <input class='tbox' type='text' id='submitnews_title' name='submitnews_title' size='60' value='".$tp->toHTML(vartrue($_POST['submitnews_title']),TRUE,'USER_TITLE')."' maxlength='200' style='width:90%' required />
  171. </td>
  172. </tr>
  173. <tr>
  174. <td style='width:20%' class='forumheader3'>".LAN_135."</td>
  175. <td style='width:80%' class='forumheader3'>
  176. ".e107::getForm()->bbarea('submitnews_item', $tp->toForm(vartrue($_POST['submitnews_item'])),null, null, 'large', 'required=1')."
  177. </td>
  178. </tr>
  179. ";
  180. if ($pref['subnews_attach'] && $pref['upload_enabled'] && check_class($pref['upload_class']) && FILE_UPLOADS)
  181. {
  182. $text .= "
  183. <tr>
  184. <td style='width:20%' class='forumheader3'>".SUBNEWSLAN_5."<br /><span class='smalltext'>".SUBNEWSLAN_6."</span></td>
  185. <td style='width:80%' class='forumheader3'>
  186. <input class='tbox' type='file' name='file_userfile[]' style='width:90%' multiple='multiple' />
  187. </td>
  188. </tr>";
  189. }
  190. $text .= "
  191. <tr>
  192. <td colspan='2' style='text-align:center' class='forumheader'>
  193. <input class='btn btn-success button' type='submit' name='submitnews_submit' value='".LAN_136."' />
  194. <input type='hidden' name='e-token' value='".e_TOKEN."' />
  195. </td>
  196. </tr>
  197. </table>
  198. </form>
  199. </div>";
  200. $ns->tablerender(LAN_136, $text);
  201. require_once(FOOTERF);
  202. ?>