PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/smartsection/submit.php

https://github.com/severnaya99/Sg-2010
PHP | 315 lines | 211 code | 68 blank | 36 comment | 58 complexity | 67711e32163cbbfecd2bcc8829cae5b0 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. * $Id: submit.php 331 2007-12-23 16:01:11Z malanciault $
  4. * Module: SmartSection
  5. * Author: The SmartFactory <www.smartfactory.ca>
  6. * Licence: GNU
  7. */
  8. include_once("header.php");
  9. Global $smartsection_category_handler, $smartsection_item_handler, $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule;
  10. // Get the total number of categories
  11. $categoriesArray = $smartsection_category_handler->getCategoriesForSubmit();
  12. if (!$categoriesArray) {
  13. redirect_header("index.php", 1, _MD_SSECTION_NEED_CATEGORY_ITEM);
  14. exit();
  15. }
  16. // Find if the user is admin of the module
  17. $isAdmin = smartsection_userIsAdmin();
  18. $groups = ($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
  19. $gperm_handler = &xoops_gethandler('groupperm');
  20. $hModConfig = &xoops_gethandler('config');
  21. $module_id = $smartModule->getVar('mid');
  22. $itemid = (isset($_GET['itemid'])) ? $_GET['itemid'] : 0;
  23. $itemid = (isset($_POST['itemid'])) ? $_POST['itemid'] : $itemid;
  24. if ($itemid != 0) {
  25. // We are editing an article
  26. $itemObj = $smartsection_item_handler->get($itemid);
  27. if (!($isAdmin ||
  28. (is_object($xoopsUser) &&
  29. ($itemObj) &&
  30. (($xoopsUser->uid() == $itemObj->uid())
  31. )
  32. )
  33. )
  34. ) {
  35. redirect_header("index.php", 1, _NOPERM);
  36. exit();
  37. }
  38. $categoryObj = $itemObj->category();
  39. } else {
  40. // we are submitting a new article
  41. // if the user is not admin AND we don't allow user submission, exit
  42. if (!($isAdmin ||
  43. (isset($xoopsModuleConfig['allowsubmit']) && $xoopsModuleConfig['allowsubmit'] == 1 && (is_object($xoopsUser) || (isset($xoopsModuleConfig['anonpost']) && $xoopsModuleConfig['anonpost'] == 1))))
  44. ) {
  45. redirect_header("index.php", 1, _NOPERM);
  46. exit();
  47. }
  48. $itemObj = $smartsection_item_handler->create();
  49. $categoryObj = $smartsection_category_handler->create();
  50. }
  51. $uid = is_object($xoopsUser) ? $xoopsUser->uid() : 0;
  52. $op = '';
  53. if (isset($_POST['post'])) {
  54. $op = 'post';
  55. } elseif (isset($_POST['preview'])) {
  56. $op = 'preview';
  57. } else {
  58. $op = 'add';
  59. }
  60. switch ($op) {
  61. case 'preview':
  62. Global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsDB;
  63. // Putting the values about the ITEM in the ITEM object
  64. $itemObj->setVar('categoryid', $_POST['categoryid']);
  65. $itemObj->setVar('uid', $uid);
  66. $itemObj->setVar('title', stripcslashes($_POST['title']));
  67. $itemObj->setVar('summary', stripcslashes($_POST['summary']));
  68. $itemObj->setVar('body', stripcslashes($_POST['body']));
  69. $itemObj->setVar('notifypub', $_POST['notifypub']);
  70. $itemObj->setVar('dohtml', isset($_POST['dohtml']) ? intval($_POST['dohtml']) : 0);
  71. $itemObj->setVar('dosmiley', isset($_POST['dosmiley']) ? intval($_POST['dosmiley']) : 0);
  72. $itemObj->setVar('doxcode', isset($_POST['doxcode']) ? intval($_POST['doxcode']) : 0);
  73. $itemObj->setVar('doimage', isset($_POST['doimage']) ? intval($_POST['doimage']) : 0);
  74. $itemObj->setVar('dobr', isset($_POST['dobr']) ? intval($_POST['dobr']) : 0);
  75. // Uploading the image, if any
  76. // Retreive the filename to be uploaded
  77. if ( $_FILES['image_file']['name'] != "" ) {
  78. $filename = $_POST["xoops_upload_file"][0] ;
  79. if( !empty( $filename ) || $filename != "" ) {
  80. global $xoopsModuleConfig;
  81. // TODO : Implement smartsection mimetype management
  82. $max_size = $xoopsModuleConfig['maximum_filesize'];
  83. $max_imgwidth = $xoopsModuleConfig['maximum_image_width'];
  84. $max_imgheight = $xoopsModuleConfig['maximum_image_height'];
  85. $allowed_mimetypes = smartsection_getAllowedImagesTypes();
  86. include_once(XOOPS_ROOT_PATH."/class/uploader.php");
  87. if( $_FILES[$filename]['tmp_name'] == "" || ! is_readable( $_FILES[$filename]['tmp_name'] ) ) {
  88. redirect_header( 'javascript:history.go(-1)' , 2, _AM_SSECTION_FILEUPLOAD_ERROR ) ;
  89. exit ;
  90. }
  91. $uploader = new XoopsMediaUploader(smartsection_getImageDir('item'), $allowed_mimetypes, $max_size, $max_imgwidth, $max_imgheight);
  92. if( $uploader->fetchMedia( $filename ) && $uploader->upload() ) {
  93. $itemObj->setVar('image', $uploader->getSavedFileName());
  94. } else {
  95. redirect_header( 'javascript:history.go(-1)' , 2, _AM_SSECTION_FILEUPLOAD_ERROR . $uploader->getErrors() ) ;
  96. exit ;
  97. }
  98. }
  99. } else {
  100. $itemObj->setVar('image', $_POST['image']);
  101. }
  102. $notifypub = isset($_POST['notifypub']) ? $_POST['notifypub'] : '';
  103. global $xoopsUser, $myts;
  104. $xoopsOption['template_main'] = 'smartsection_submit.html';
  105. include_once(XOOPS_ROOT_PATH . "/header.php");
  106. include_once("footer.php");
  107. $name = ($xoopsUser) ? (ucwords($xoopsUser->getVar("uname"))) : 'Anonymous';
  108. $categoryObj = $smartsection_category_handler->get($_POST['categoryid']);
  109. $item = $itemObj->toArray(null, $categoryObj, false);
  110. $item['summary'] = $item['maintext'];
  111. $item['categoryPath'] = $categoryObj->getCategoryPath(true);
  112. $item['who_when'] = $itemObj->getWhoAndWhen();
  113. $item['comments'] = -1;
  114. $xoopsTpl->assign('item', $item);
  115. $xoopsTpl->assign('op', 'preview');
  116. $xoopsTpl->assign('module_home', smartsection_module_home());
  117. if ($itemid) {
  118. $xoopsTpl->assign('categoryPath', _MD_SSECTION_EDIT_ARTICLE);
  119. $xoopsTpl->assign('lang_intro_title', _MD_SSECTION_EDIT_ARTICLE);
  120. //For RISQ
  121. $xoopsTpl->assign('lang_intro_text', '');
  122. //$xoopsTpl->assign('lang_intro_text', $myts->displayTarea(smartsection_getConfig('submitintromsg')));
  123. } else {
  124. $xoopsTpl->assign('categoryPath', _MD_SSECTION_SUB_SNEWNAME);
  125. $xoopsTpl->assign('lang_intro_title', sprintf(_MD_SSECTION_SUB_SNEWNAME, ucwords($xoopsModule->name())));
  126. //For RISQ
  127. $xoopsTpl->assign('lang_intro_text', smartsection_getConfig('submitintromsg'));
  128. //$xoopsTpl->assign('lang_intro_text', $myts->displayTarea(smartsection_getConfig('submitintromsg')));
  129. }
  130. include_once SMARTSECTION_ROOT_PATH . 'include/submit.inc.php';
  131. include_once XOOPS_ROOT_PATH . '/footer.php';
  132. exit();
  133. break;
  134. case 'post':
  135. Global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsDB;
  136. // Putting the values about the ITEM in the ITEM object
  137. $itemObj->setVar('categoryid', $_POST['categoryid']);
  138. $itemObj->setVar('title', $_POST['title']);
  139. $itemObj->setVar('summary', isset($_POST['summary']) ? $_POST['summary'] : '');
  140. $itemObj->setVar('body', $_POST['body']);
  141. $itemObj->setVar('dohtml', (isset($_POST['dohtml'])) ? intval($_POST['dohtml']) : 0);
  142. $itemObj->setVar('dosmiley', (isset($_POST['dosmiley'])) ? intval($_POST['dosmiley']) : 0);
  143. $itemObj->setVar('doxcode', (isset($_POST['doxcode'])) ? intval($_POST['doxcode']) : 0);
  144. $itemObj->setVar('doimage', (isset($_POST['doimage'])) ? intval($_POST['doimage']) : 0);
  145. $itemObj->setVar('dobr', (isset($_POST['dobr'])) ? intval($_POST['dobr']) : 0);
  146. $notifypub = isset($_POST['notifypub']) ? $_POST['notifypub'] : '';
  147. $itemObj->setVar('notifypub', $notifypub);
  148. // Uploading the image, if any
  149. // Retreive the filename to be uploaded
  150. if ( $_FILES['image_file']['name'] != "" ) {
  151. $filename = $_POST["xoops_upload_file"][0] ;
  152. if( !empty( $filename ) || $filename != "" ) {
  153. global $xoopsModuleConfig;
  154. // TODO : Implement smartsection mimetype management
  155. $max_size = $xoopsModuleConfig['maximum_filesize'];
  156. $max_imgwidth = $xoopsModuleConfig['maximum_image_width'];
  157. $max_imgheight = $xoopsModuleConfig['maximum_image_height'];
  158. $allowed_mimetypes = smartsection_getAllowedImagesTypes();
  159. include_once(XOOPS_ROOT_PATH."/class/uploader.php");
  160. if( $_FILES[$filename]['tmp_name'] == "" || ! is_readable( $_FILES[$filename]['tmp_name'] ) ) {
  161. redirect_header( 'javascript:history.go(-1)' , 2, _AM_SSECTION_FILEUPLOAD_ERROR ) ;
  162. exit ;
  163. }
  164. $uploader = new XoopsMediaUploader(smartsection_getImageDir('item'), $allowed_mimetypes, $max_size, $max_imgwidth, $max_imgheight);
  165. if( $uploader->fetchMedia( $filename ) && $uploader->upload() ) {
  166. $itemObj->setVar('image', $uploader->getSavedFileName());
  167. } else {
  168. redirect_header( 'javascript:history.go(-1)' , 2, _AM_SSECTION_FILEUPLOAD_ERROR . $uploader->getErrors() ) ;
  169. exit ;
  170. }
  171. }
  172. } else {
  173. $itemObj->setVar('image', $_POST['image']);
  174. }
  175. // if we are editing an article, we don't change the uid and datesub values
  176. if (!$itemid) {
  177. $itemObj->setVar('uid', $uid);
  178. $itemObj->setVar('datesub', time());
  179. }
  180. // Setting the status of the item
  181. if ( $itemid || ($xoopsModuleConfig['autoapprove_submitted'] == 1)) {
  182. $itemObj->setVar('status', _SSECTION_STATUS_PUBLISHED);
  183. } else {
  184. $itemObj->setVar('status', _SSECTION_STATUS_SUBMITTED);
  185. }
  186. // Storing the item object in the database
  187. if ( !$itemObj->store() ) {
  188. redirect_header("javascript:history.go(-1)", 2, _MD_SSECTION_SUBMIT_ERROR);
  189. exit();
  190. }
  191. // Get the cateopry object related to that item
  192. $categoryObj =& $itemObj->category();
  193. // if autoapprove_submitted. This does not apply if we are editing an article
  194. if (!$itemid) {
  195. if ( $xoopsModuleConfig['autoapprove_submitted'] == 1) {
  196. // We do not not subscribe user to notification on publish since we publish it right away
  197. // Send notifications
  198. $itemObj->sendNotifications(array(_SSECTION_NOT_ITEM_PUBLISHED));
  199. $redirect_msg = _MD_SSECTION_ITEM_RECEIVED_AND_PUBLISHED;
  200. } else {
  201. // Subscribe the user to On Published notification, if requested
  202. if ($notifypub) {
  203. include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
  204. $notification_handler = &xoops_gethandler('notification');
  205. $notification_handler->subscribe('item', $itemObj->itemid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
  206. }
  207. // Send notifications
  208. $itemObj->sendNotifications(array(_SSECTION_NOT_ITEM_SUBMITTED));
  209. $redirect_msg = _MD_SSECTION_ITEM_RECEIVED_NEED_APPROVAL;
  210. }
  211. } else {
  212. $redirect_msg = _MD_SSECTION_ITEMMODIFIED;
  213. }
  214. redirect_header("index.php", 2, $redirect_msg);
  215. exit();
  216. break;
  217. case 'add':
  218. default:
  219. global $xoopsUser, $myts;
  220. $xoopsOption['template_main'] = 'smartsection_submit.html';
  221. include_once(XOOPS_ROOT_PATH . "/header.php");
  222. include_once("footer.php");
  223. $name = ($xoopsUser) ? (ucwords($xoopsUser->getVar("uname"))) : 'Anonymous';
  224. $notifypub = 1;
  225. $xoopsTpl->assign('module_home', smartsection_module_home());
  226. if(isset($_GET['op']) && $_GET['op'] == 'clone'){
  227. $xoopsTpl->assign('categoryPath', _MD_SSECTION_CLONE);
  228. $xoopsTpl->assign('lang_intro_title', _MD_SSECTION_CLONE);
  229. }
  230. elseif ($itemid) {
  231. $xoopsTpl->assign('categoryPath', _MD_SSECTION_EDIT_ARTICLE);
  232. $xoopsTpl->assign('lang_intro_title', _MD_SSECTION_EDIT_ARTICLE);
  233. //For RISQ
  234. $xoopsTpl->assign('lang_intro_text', '');
  235. //$xoopsTpl->assign('lang_intro_text', $myts->displayTarea(smartsection_getConfig('submitintromsg')));
  236. } else {
  237. $xoopsTpl->assign('categoryPath', _MD_SSECTION_SUB_SNEWNAME);
  238. $xoopsTpl->assign('lang_intro_title', sprintf(_MD_SSECTION_SUB_SNEWNAME, ucwords($xoopsModule->name())));
  239. //For RISQ
  240. $xoopsTpl->assign('lang_intro_text', smartsection_getConfig('submitintromsg'));
  241. //$xoopsTpl->assign('lang_intro_text', $myts->displayTarea(smartsection_getConfig('submitintromsg')));
  242. }
  243. include_once SMARTSECTION_ROOT_PATH . 'include/submit.inc.php';
  244. include_once XOOPS_ROOT_PATH . '/footer.php';
  245. break;
  246. }
  247. ?>