PageRenderTime 24ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/xfsection/submit.php

https://github.com/severnaya99/Sg-2010
PHP | 376 lines | 212 code | 60 blank | 104 comment | 52 complexity | 88f951c8fbf987009aec22c245207f5a MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0
  1. <?php
  2. // $Id: submit.php,v 1.4 2006/03/20 03:23:03 ohwada Exp $
  3. // 2006-03-17 K.OHWADA
  4. // dont use foreach($HTTP_POST_VARS as $k => $v)
  5. // $HTTP_POST_VARS -> $_POST
  6. // $HTTP_GET_VARS -> $_GET
  7. // 2005-11-05 K.OHWADA
  8. // BUG 7443: typo &nbsp
  9. // 2004/03/20 K.OHWADA
  10. // permit the auther to modify article
  11. // file upload
  12. // jump new article
  13. // 2004/02/26 K.OHWADA
  14. // add the mode which inhibit to submit article
  15. // 2004/01/25 K.OHWADA
  16. // bug fix:
  17. // don't take over a category id to the preview
  18. // don't set url and urlname
  19. // In preview, display URL link for article
  20. // 2003/10/11 K.OHWADA
  21. // easy to rename module and table
  22. // add conf.php
  23. // bug fix
  24. // _WFS_THANKS isn't defined
  25. // ------------------------------------------------------------------------ //
  26. // XOOPS - PHP Content Management System //
  27. // Copyright (c) 2000 XOOPS.org //
  28. // <http://www.xoops.org/> //
  29. // ------------------------------------------------------------------------ //
  30. // This program is free software; you can redistribute it and/or modify //
  31. // it under the terms of the GNU General Public License as published by //
  32. // the Free Software Foundation; either version 2 of the License, or //
  33. // (at your option) any later version. //
  34. // //
  35. // You may not change or alter any portion of this comment or credits //
  36. // of supporting developers from this source code or any supporting //
  37. // source code which is considered copyrighted (c) material of the //
  38. // original comment or credit authors. //
  39. // //
  40. // This program is distributed in the hope that it will be useful, //
  41. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  42. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  43. // GNU General Public License for more details. //
  44. // //
  45. // You should have received a copy of the GNU General Public License //
  46. // along with this program; if not, write to the Free Software //
  47. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
  48. // ------------------------------------------------------------------------ //
  49. include '../../mainfile.php';
  50. include_once 'conf.php'; // add
  51. include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/class/wfsarticle.php';
  52. include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/class/common.php';
  53. // easy to rename module and table
  54. //include_once XOOPS_ROOT_PATH . '/modules/wfsection/include/groupaccess.php';
  55. include_once XOOPS_ROOT_PATH . '/modules/'.$xoopsModule->dirname().'/include/groupaccess.php';
  56. include_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->dirname().'/class/wfsfiles.php';
  57. include_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->dirname().'/class/uploadfile.php';
  58. //include_once(XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/cache/uploadconfig.php");
  59. global $wfsConfig;
  60. // add the mode which inhibit to submit article
  61. if ($wfsSubmitInihibit)
  62. { redirect_header("index.php", 1, _NOPERM);
  63. exit();
  64. }
  65. if (empty($wfsConfig['anonpost']) && !is_object($xoopsUser)) {
  66. redirect_header("index.php", 1, _NOPERM);
  67. exit();
  68. }
  69. $op = 'form';
  70. if ( isset($_POST['preview'] )) {
  71. $op = 'preview';
  72. } elseif ( isset($_POST['post']) ) {
  73. $op = 'post';
  74. } elseif ( isset($_POST['edit']) ) {
  75. $op = 'edit';
  76. }
  77. if (isset($_GET['op'])) $op=$_GET['op'];
  78. if (isset($_POST['op'])) $op=$_POST['op'];
  79. $articleid = 0;
  80. if ( isset($_POST['articleid']) ) $articleid = intval( $_POST['articleid'] );
  81. if ( isset($_POST['id']) ) $id = intval( $_POST['id'] );
  82. if ( isset($_POST['notifypub']) ) $notifypub = intval( $_POST['notifypub'] );
  83. if ( isset($_POST['nobr']) ) $nobr = intval( $_POST['nobr'] );
  84. if ( isset($_POST['nosmiley']) ) $nosmiley = intval( $_POST['nosmiley'] );
  85. if ( isset($_POST['enaamp']) ) $enaamp = intval( $_POST['enaamp'] );
  86. if ( isset($_POST['subject']) ) $subject = $_POST['subject'];
  87. if ( isset($_POST['message']) ) $message = $_POST['message'];
  88. if ( isset($_POST['summary']) ) $summary = $_POST['summary'];
  89. if ( isset($_POST['groupid']) ) $groupid = $_POST['groupid'];
  90. if ( isset($_POST['url']) ) $url = $_POST['url'];
  91. if ( isset($_POST['urlname']) ) $urlname = $_POST['urlname'];
  92. $filename = '';
  93. $fileshowname = '';
  94. $filedescript = '';
  95. if ( isset($_POST['filename']) ) $filename = $_POST['filename'];
  96. if ( isset($_POST['fileshowname']) ) $fileshowname = $_POST['fileshowname'];
  97. if ( isset($_POST['filedescript']) ) $filedescript = $_POST['filedescript'];
  98. // permit the auther to modify article
  99. $submitform_title = _WFS_POSTNEWARTICLE;
  100. // file upload
  101. $file_submitform_flag = 0;
  102. if ($wfsPermitUpload) $file_submitform_flag = 1;
  103. switch ($op) {
  104. case "preview":
  105. $myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object
  106. // bug fix : don't take over a category id to the preview
  107. // $xt = new WfsCategory($xoopsDB->prefix("wfs_category"), $_POST['id']);
  108. // $xt = new WfsCategory($_POST['id']);
  109. $xt = new WfsCategory($id);
  110. include XOOPS_ROOT_PATH.'/header.php';
  111. $p_subject = $myts->makeTboxData4Preview($subject);
  112. if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
  113. $nohtml = isset($nohtml) ? intval($nohtml) : 0;
  114. } else {
  115. $nohtml = 1;
  116. }
  117. $html = empty($nohtml) ? 1 : 0;
  118. if ( isset($nosmiley) && intval($nosmiley) > 0 ) {
  119. $nosmiley = 1;
  120. $smiley = 0;
  121. } else {
  122. $nosmiley = 0;
  123. $smiley = 1;
  124. }
  125. // bug fix?: In preview, display URL link for article
  126. // BUG 7443: typo &nbsp
  127. $urllink = '&nbsp;';
  128. if (($url) && (!$urlname))
  129. { $urllink = "<a href='http://".$url."' target='_blank'>Url Link: ".$url."</a><br />"; }
  130. elseif ($urlname)
  131. { $urllink = "<a href='http://".$url."' target='_blank'>Url Link: ".$urlname."</a><br />"; }
  132. $p_message = $myts->makeTareaData4Preview($message, $html, $smiley, 1);
  133. $p_message = "$urllink$p_message";
  134. $subject = $myts->makeTboxData4PreviewInForm($subject);
  135. $message = $myts->makeTareaData4PreviewInForm($message);
  136. $noname = isset($noname) ? intval($noname) : 0;
  137. $notifypub = isset($notifypub) ? intval($notifypub) : 0;
  138. themecenterposts($p_subject, $p_message);
  139. include 'include/storyform.inc.php';
  140. include XOOPS_ROOT_PATH.'/footer.php';
  141. break;
  142. case "post":
  143. $nohtml_db = 1;
  144. if ( $xoopsUser ) {
  145. $uid = $xoopsUser->getVar('uid');
  146. if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
  147. $nohtml_db = empty($nohtml) ? 0 : 1;
  148. }
  149. } else {
  150. if ( $wfsConfig['anonpost'] == 1 ) {
  151. $uid = 0;
  152. } else {
  153. redirect_header("index.php",3,_NW_ANONNOTALLOWED);
  154. exit();
  155. }
  156. }
  157. $story = new WfsArticle();
  158. $story->setTitle($subject);
  159. $story->setMainText($message);
  160. $story->setSummary($summary);
  161. $story->setUid($uid);
  162. $story->setCategoryid($id);
  163. $story->setNohtml($nohtml_db);
  164. $nosmiley = isset($nosmiley) ? intval($nosmiley) : 0;
  165. $notifypub = isset($notifypub) ? intval($notifypub) : 0;
  166. $nobr = isset($nobr) ? intval($nobr) : 0; // add
  167. $enaamp = isset($enaamp) ? intval($enaamp) : 0; // add
  168. $story->setHtmlpage("");
  169. $story->setIshtml(0);
  170. $story->setWeight(100);
  171. //$story->setGroupid($groupid);
  172. $story->setGroupid($groupid);
  173. $story->setNosmiley($nosmiley);
  174. $story->setPublished(0);
  175. $story->setExpired(0);
  176. $story->setNotifyPub($notifypub);
  177. echo $story->articleid;
  178. $story->setType('user');
  179. // bug fix : don't set url and urlname
  180. $story->setUrl($url);
  181. $story->setUrlname($urlname);
  182. // file upload
  183. // $upload = new uploadfile($HTTP_POST_VARS['filename']);
  184. // $distfilename = $upload->doUploadToRandumFile(XOOPS_ROOT_PATH."/".$wfsConfig['filesbasepath']);
  185. //
  186. // if ( $distfilename ) {
  187. //
  188. // $article = new WfsArticle($story->articleid);
  189. // $file = new WfsFiles();
  190. // $file->setByUploadFile($HTTP_POST_VARS['filename']);
  191. // if (empty($HTTP_POST_VARS['downloadfilename'])) {
  192. // $file->setFileShowName($HTTP_POST_VARS['filename']);
  193. // } else {
  194. // $file->setFileShowName($HTTP_POST_VARS['$downloadfilename']);
  195. // }
  196. // $article->addFile($HTTP_POST_VARS['filename']);
  197. // }
  198. if ( $wfsConfig['autoapprove'] == 1 ) {
  199. $approve = 1;
  200. $story->setApproved($approve);
  201. $story->setPublished(time());
  202. $story->setExpired(0);
  203. }
  204. $result = $story->store();
  205. // error mesaage
  206. if (!$result)
  207. { redirect_header("index.php",10,_WFS_SUBMIT_FAIL);
  208. exit();
  209. }
  210. // file upload
  211. $newid = $story->getNewid();
  212. $code = file_upload($newid);
  213. if (($code != 0)&&($code != 6)&&($code != 7))
  214. {
  215. include XOOPS_ROOT_PATH.'/header.php';
  216. print_file_upload_error($code);
  217. echo "<br><br>";
  218. echo _WFS_BUT_SUBMIT_SUCCESS;
  219. echo "<br><br>";
  220. if ($newid != 0 ) echo "<a href='article.php?articleid=$newid'>"._WFS_SUBMITED_ARTICLE."</a><br>";
  221. echo "<a href='index.php'>"._WFS_MAININDEX."</a><br>";
  222. include XOOPS_ROOT_PATH.'/footer.php';
  223. exit();
  224. }
  225. // if ($result) {
  226. if ($wfsConfig['notifysubmit'] == 1 ) {
  227. $xoopsMailer =& getMailer();
  228. $xoopsMailer->useMail();
  229. $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
  230. $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
  231. $xoopsMailer->setFromName($xoopsConfig['sitename']);
  232. $xoopsMailer->setSubject(_NW_NOTIFYSBJCT);
  233. $body = _NW_NOTIFYMSG;
  234. $body .= "\n\n"._NW_TITLE.": ".$story->title();
  235. $body .= "\n"._POSTEDBY.": ".XoopsUser::getUnameFromId($uid);
  236. $body .= "\n"._DATE.": ".formatTimestamp(time(), 'm', $xoopsConfig['default_TZ']);
  237. // easy to rename module and table
  238. // $body .= "\n\n".XOOPS_URL.'/modules/wfsection/admin/index.php?op=edit&articleid='.$result;
  239. $body .= "\n\n".XOOPS_URL."/modules/$wfsModule/admin/index.php?op=edit&articleid=".$result;
  240. $xoopsMailer->setBody($body);
  241. $xoopsMailer->send();
  242. }
  243. // } else {
  244. // echo 'error';
  245. // }
  246. // bug fix
  247. // _WFS_THANKS isn't defined
  248. // http://jp.xoops.org/modules/newbb/viewtopic.php?topic_id=1596&forum=11&viewmode=flat&order=ASC&start=10
  249. // redirect_header("index.php",2,_WFS_THANKS);
  250. // jump new article
  251. if ( ( $wfsConfig['autoapprove'] == 1 ) && ($newid != 0) )
  252. { redirect_header("article.php?articleid=$newid",2,_WFS_THANKSFORPOST); }
  253. else
  254. { redirect_header("index.php",2,_WFS_THANKSFORPOST); }
  255. break;
  256. case "edit":
  257. include_once(XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/class/wfscategory.php");
  258. include_once(XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/class/wfsarticle.php");
  259. $story = new WfsArticle('articleid');
  260. $subject = $story->title();
  261. $message = $story->mainText();
  262. $summary = $story->summary("Edit");
  263. $url = $story->url();
  264. $urlname = $story->urlname();
  265. //$story->Uid();
  266. //$story->setCategoryid($id);
  267. //$story->setNohtml($nohtml_db);
  268. $nosmiley = isset($nosmiley) ? intval($nosmiley) : 0;
  269. $notifypub = isset($notifypub) ? intval($notifypub) : 0;
  270. $story->setHtmlpage("");
  271. $story->setIshtml(0);
  272. //$story->setGroupid($groupid);
  273. //$story->setNosmiley($nosmiley);
  274. //$story->setPublished(0);
  275. //$story->setExpired(0);
  276. //$story->setNotifyPub($notifypub);
  277. //$story->setType('user');
  278. // bug fix : don't take over a category id to the preview
  279. // $xt = new WfsCategory($xoopsDB->prefix("wfs_article "), 14);
  280. $xt = new WfsCategory(14);
  281. $noname = 0;
  282. $nohtml = 0;
  283. $nosmiley = 0;
  284. $notifypub = 0;
  285. include XOOPS_ROOT_PATH.'/header.php';
  286. indexmainheader();
  287. include 'include/storyform.inc.php';
  288. include XOOPS_ROOT_PATH.'/footer.php';
  289. break;
  290. case 'form':
  291. default:
  292. //include_once(XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/class/wfscategory.php");
  293. //include_once(XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/class/wfsarticle.php");
  294. // bug fix : don't take over a category id to the preview
  295. // $xt = new WfsCategory($xoopsDB->prefix("wfs_category"));
  296. $xt = new WfsCategory();
  297. $num = WfsArticle::countByCategory($xt->id);
  298. include XOOPS_ROOT_PATH.'/header.php';
  299. $subject = '';
  300. $message = '';
  301. $groupid = '';
  302. $summary = '';
  303. $url = '';
  304. $urlname = '';
  305. $filename = '';
  306. $downloadfilename ='';
  307. $noname = 0;
  308. $nohtml = 0;
  309. $nosmiley = 0;
  310. $notifypub = 1;
  311. indexmainheader();
  312. include 'include/storyform.inc.php';
  313. include XOOPS_ROOT_PATH.'/footer.php';
  314. break;
  315. }
  316. ?>