PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/forum.admin.view.php

http://xe-forum.googlecode.com/
PHP | 418 lines | 268 code | 61 blank | 89 comment | 34 complexity | e55f05fc0c010ab6043d2280de0f3ee4 MD5 | raw file
  1. <?php
  2. /**
  3. * @class forumAdminView
  4. * @author dan (dan.dragan@arnia.ro)
  5. * @brief forum module admin view class
  6. **/
  7. class forumAdminView extends forum {
  8. /**
  9. * @brief Initialization
  10. *
  11. * forum Module is divided into general use and administrative purpose
  12. **/
  13. function init() {
  14. // checks if there are preexisting modules with the current module_srl
  15. $module_srl = Context::get('module_srl');
  16. if(!$module_srl && $this->module_srl) {
  17. $module_srl = $this->module_srl;
  18. Context::set('module_srl', $module_srl);
  19. }
  20. // module creating model object
  21. $oModuleModel = &getModel('module');
  22. // setting the information in advance, in order to save the module
  23. if($module_srl) {
  24. $module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
  25. if(!$module_info) {
  26. Context::set('module_srl','');
  27. $this->act = 'list';
  28. } else {
  29. ModuleModel::syncModuleToSite($module_info);
  30. $this->module_info = $module_info;
  31. Context::set('module_info',$module_info);
  32. }
  33. }
  34. // check if we are in the right kind of module
  35. if($module_info && $module_info->module != 'forum') return $this->stop("msg_invalid_request");
  36. // Set module categories to populate admin list
  37. $module_category = $oModuleModel->getModuleCategories();
  38. Context::set('module_category', $module_category);
  39. // Set template path for admin view pages
  40. $template_path = sprintf("%stpl/",$this->module_path);
  41. $this->setTemplatePath($template_path);
  42. // set order target
  43. foreach($this->order_target as $key) $order_target[$key] = Context::getLang($key);
  44. $order_target['list_order'] = Context::getLang('document_srl');
  45. $order_target['update_order'] = Context::getLang('last_update');
  46. Context::set('order_target', $order_target);
  47. $oSecurity = new Security();
  48. $oSecurity->encodeHTML('module_info.');
  49. $oSecurity->encodeHTML('module_category..');
  50. }
  51. /**
  52. * @brief Display forum admin content
  53. **/
  54. function dispForumAdminContent() {
  55. $output = executeQueryArray('forum.getForumList',$args);
  56. $display=Context::get('display');
  57. ModuleModel::syncModuleToSite($output->data);
  58. //if there is only one forum go directly to it's dashboard , else go to forum list
  59. if($output->total_count !=1 || $display) {
  60. $this->displayForumAdminContentList();
  61. }
  62. else {
  63. $oModuleModel = &getModel('module');
  64. $module_srl=$output->data[1]->module_srl;
  65. $module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
  66. ModuleModel::syncModuleToSite($module_info);
  67. $this->module_info = $module_info;
  68. Context::set('module_info',$module_info);
  69. Context::set('module_srl',$module_srl);
  70. Context::set('act','dispForumAdminDashboard');
  71. $this->dispForumAdminDashboard();
  72. $oSecurity = new Security();
  73. $oSecurity->encodeHTML('module_info.');
  74. }
  75. }
  76. /**
  77. * @brief Display forum admin dashboard
  78. **/
  79. function dispForumAdminDashboard() {
  80. $module_info=Context::get('module_info');
  81. $oDocumentModel = &getModel('document');
  82. $oCommentModel=&getModel('comment');
  83. $oModuleModel= &getModel('module');
  84. $obj->list_count=$oDocumentModel->getDocumentCount($module_info->module_srl);
  85. $obj->mid=$module_info->mid;
  86. $obj->module_srl=$module_info->module_srl;
  87. //seting the right format for time parameters
  88. $time = time();
  89. $end_date=date("Ymd",$time);
  90. $time-=60*60*24*7;
  91. $start_date = date("Ymd",$time);
  92. $document_list=$oDocumentModel->getDocumentList($obj);
  93. $lastweek_document_count=0;
  94. if($document_list->data)
  95. foreach($document_list->data as $document) {
  96. $member_list[]=$document->variables['nick_name'];
  97. $uploaded_count[]=$document->variables['uploaded_count'];
  98. if((substr($document->variables['last_update'],0,8) <= $end_date) && (substr($document->variables['last_update'],0,8) >= $start_date) ){
  99. $lastweek_document_count++;
  100. $lastweek_member_list[]=$document->variables['nick_name'];
  101. $lastweek_uploaded_count[]=$document->variables['uploaded_count'];
  102. }
  103. }
  104. $obj->list_count=$oCommentModel->getCommentAllCount($module_info->module_srl);
  105. $comment_list=$oCommentModel->getTotalCommentList($obj);
  106. $lastweek_comment_count=0;
  107. if($comment_list->data)
  108. {
  109. foreach ($comment_list->data as $comment)
  110. {
  111. $member_list[]=$comment->variables['nick_name'];
  112. $uploaded_count[]=$comment->variables['uploaded_count'];
  113. if((substr($comment->variables['last_update'],0,8) <= $end_date) && (substr($comment->variables['last_update'],0,8) >= $start_date))
  114. {
  115. $lastweek_comment_count++;
  116. $lastweek_member_list[]=$comment->variables['nick_name'];
  117. $lastweek_uploaded_count[]=$comment->variables['uploaded_count'];
  118. }
  119. }
  120. }
  121. if(is_array($member_list)) $member_list=array_unique($member_list);
  122. if(is_array($lastweek_member_list)) $lastweek_member_list=array_unique($lastweek_member_list);
  123. if(is_array($uploaded_count)) $uploaded_count=array_sum($uploaded_count);
  124. if(is_array($lastweek_uploaded_count)) $lastweek_uploaded_count=array_sum($lastweek_uploaded_count);
  125. if(!$uploaded_count) $uploaded_count=0;
  126. if(!$lastweek_uploaded_count) $lastweek_uploaded_count=0;
  127. $total_comments_published=$oCommentModel->getCommentAllCount($module_info->module_srl,true);
  128. $total_comments_unpublished=$oCommentModel->getCommentAllCount($module_info->module_srl,false);
  129. $comment_part_config = $oModuleModel->getModulePartConfig('comment',$module_info->module_srl);
  130. $comment_count = $comment_part_config->comment_count;
  131. $obj->list_count=5;
  132. $newest_comments=$oCommentModel->getNewestCommentList($obj);
  133. if(isset($newest_comments)){
  134. foreach($newest_comments as $comment){
  135. $comment->content=trim(cut_str($comment->content,50,"..."));
  136. $comment->document_content=$oDocumentModel->getDocument($comment->document_srl)->variables['title'];
  137. $pos = executeQuery('forum.getCommentPosition',$comment)->data;
  138. if($pos && $comment_count) {
  139. $comment->cpage= ceil($pos->count / $comment_count);
  140. }
  141. }
  142. }
  143. $module_info->list_count=5;
  144. $newest_documents= executeQuery('forum.getNewestDocumentList', $module_info);
  145. if(count($newest_documents->data)==1) $newest_docs[] = $newest_documents->data;
  146. else $newest_docs = $newest_documents->data;
  147. //setting last week variables for the dashboard template
  148. Context::set('lastweek_total_count',$lastweek_document_count);
  149. Context::set('lastweek_total_comments',$lastweek_comment_count);
  150. Context::set('lastweek_total_users',count($lastweek_member_list));
  151. Context::set('lastweek_total_attachements',$lastweek_uploaded_count);
  152. //setting total variables for the dashboard template
  153. Context::set('total_count',$document_list->total_count);
  154. Context::set('total_comments_published',$total_comments_published);
  155. Context::set('total_comments_unpublished',$total_comments_unpublished);
  156. Context::set('total_users',count($member_list));
  157. Context::set('total_attachements',$uploaded_count);
  158. //setting the documents and comments list for the dashboard template
  159. Context::set('newest_documents',$newest_docs);
  160. Context::set('newest_comments',$newest_comments);
  161. $oSecurity = new Security();
  162. $oSecurity->encodeHTML('newest_documents..', 'newest_comments..');
  163. $this->setTemplateFile('dashboard');
  164. }
  165. /**
  166. * @brief Display forum admin content list
  167. **/
  168. function displayForumAdminContentList() {
  169. // setting up default parameters
  170. $args->sort_index = "module_srl";
  171. $args->page = Context::get('page');
  172. $args->list_count = 20;
  173. $args->page_count = 10;
  174. $args->s_module_category_srl = Context::get('module_category_srl');
  175. $s_mid = Context::get('s_mid');
  176. if($s_mid) $args->s_mid = $s_mid;
  177. $s_browser_title = Context::get('s_browser_title');
  178. if($s_browser_title) $args->s_browser_title = $s_browser_title;
  179. $output = executeQueryArray('forum.getForumList', $args);
  180. ModuleModel::syncModuleToSite($output->data);
  181. $oModuleModel = &getModel('module');
  182. if(isset($output->data)){
  183. foreach ($output->data as $val) {
  184. $module_details=$oModuleModel->getModuleInfoByModuleSrl($val->module_srl);
  185. $val->title=$module_details->title;
  186. }
  187. }
  188. // setting up variables for index template
  189. Context::set('total_count', $output->total_count);
  190. Context::set('total_page', $output->total_page);
  191. Context::set('page', $output->page);
  192. Context::set('forum_list', $output->data);
  193. Context::set('page_navigation', $output->page_navigation);
  194. $this->setTemplateFile('index');
  195. }
  196. /**
  197. * @brief Display forum admin forum info
  198. **/
  199. function dispForumAdminForumInfo() {
  200. $this->dispForumAdminInsertForum();
  201. }
  202. /**
  203. * @brief display forum admin insert forum
  204. **/
  205. function dispForumAdminInsertForum() {
  206. if(!in_array($this->module_info->module, array('admin', 'forum','blog','guestbook'))) {
  207. return $this->alertMessage('msg_invalid_request');
  208. }
  209. // instancing module model
  210. $oModuleModel = &getModel('module');
  211. $skin_list = $oModuleModel->getSkins($this->module_path);
  212. Context::set('skin_list',$skin_list);
  213. $mskin_list = $oModuleModel->getSkins($this->module_path, "m.skins");
  214. Context::set('mskin_list', $mskin_list);
  215. // instancing layout model
  216. $oLayoutModel = &getModel('layout');
  217. $layout_list = $oLayoutModel->getLayoutList();
  218. Context::set('layout_list', $layout_list);
  219. $mobile_layout_list = $oLayoutModel->getLayoutList(0,"M");
  220. Context::set('mlayout_list', $mobile_layout_list);
  221. // setting up the template
  222. $this->setTemplateFile('forum_insert');
  223. }
  224. /**
  225. * @brief display forum admin additional setup
  226. **/
  227. function dispForumAdminForumAdditionSetup() {
  228. // initializing content
  229. $content = '';
  230. // getting additional setup using the trigger
  231. $output = ModuleHandler::triggerCall('forum.dispForumAdditionSetup', 'before', $content);
  232. Context::set('setup_content', $content);
  233. // setting up the template
  234. $this->setTemplateFile('addition_setup');
  235. }
  236. /**
  237. * @brief forum admin delete forum
  238. **/
  239. function dispForumAdminDeleteForum() {
  240. if(!Context::get('module_srl')) return $this->dispForumAdminContent();
  241. if(!in_array($this->module_info->module, array('admin', 'forum','blog','guestbook'))) {
  242. return $this->alertMessage('msg_invalid_request');
  243. }
  244. $module_info = Context::get('module_info');
  245. $oDocumentModel = &getModel('document');
  246. $document_count = $oDocumentModel->getDocumentCount($module_info->module_srl);
  247. $module_info->document_count = $document_count;
  248. Context::set('module_info',$module_info);
  249. // setting up the template
  250. $this->setTemplateFile('forum_delete');
  251. }
  252. /**
  253. * @brief display forum admin list setup
  254. **/
  255. function dispForumAdminListSetup() {
  256. $oforumModel = &getModel('forum');
  257. $content = '';
  258. // getting list configuration using a trigger
  259. $output = ModuleHandler::triggerCall('forum.dispForumCommentSetup', 'before', $content);
  260. $lang->comment_count=Context::getLang('comment_count');
  261. $lang->number_of_posts=Context::getLang('number_of_posts');
  262. $content=str_replace($lang->comment_count, $lang->number_of_posts, $content);
  263. Context::set('setup_content', $content);
  264. // getting default list configuration
  265. $default_list=$oforumModel->getDefaultListConfig($this->module_info->module_srl);
  266. Context::set('extra_vars', $default_list);
  267. $list_config=$oforumModel->getListConfig($this->module_info->module_srl);
  268. Context::set('list_config', $list_config);
  269. $oSecurity = new Security();
  270. $oSecurity->encodeHTML('extra_vars..');
  271. // setting up the template
  272. $this->setTemplateFile('list_setting');
  273. }
  274. /**
  275. * @brief display forum admin category info
  276. **/
  277. function dispForumAdminCategoryInfo() {
  278. $oDocumentModel = &getModel('document');
  279. $catgegory_content = $oDocumentModel->getCategoryHTML($this->module_info->module_srl);
  280. Context::set('category_content', $catgegory_content);
  281. Context::set('module_info', $this->module_info);
  282. // setting up the template
  283. $this->setTemplateFile('category_list');
  284. }
  285. /**
  286. * @brief display forum grant info
  287. **/
  288. function dispForumAdminGrantInfo() {
  289. //getting default grant configuration
  290. $oModuleAdminModel = &getAdminModel('module');
  291. $grant_content = $oModuleAdminModel->getModuleGrantHTML($this->module_info->module_srl, $this->xml_info->grant);
  292. Context::set('grant_content', $grant_content);
  293. // setting up the template
  294. $this->setTemplateFile('grant_list');
  295. }
  296. /**
  297. * @brief display forum admin extra vars
  298. **/
  299. function dispForumAdminExtraVars() {
  300. //getting extra vars html
  301. $oDocumentAdminModel = &getModel('document');
  302. $extra_vars_content = $oDocumentAdminModel->getExtraVarsHTML($this->module_info->module_srl);
  303. Context::set('extra_vars_content', $extra_vars_content);
  304. // setting up the template
  305. $this->setTemplateFile('extra_vars');
  306. }
  307. /**
  308. * @brief display forum admin skin info
  309. **/
  310. function dispForumAdminThemeInfo() {
  311. //setting all the variables
  312. $oModuleModel = &getModel('module');
  313. $skin_list = $oModuleModel->getSkins($this->module_path);
  314. Context::set('skin_list',$skin_list);
  315. $mskin_list = $oModuleModel->getSkins($this->module_path, "m.skins");
  316. Context::set('mskin_list', $mskin_list);
  317. $oLayoutModel = &getModel('layout');
  318. $layout_list = $oLayoutModel->getLayoutList();
  319. Context::set('layout_list', $layout_list);
  320. $mobile_layout_list = $oLayoutModel->getLayoutList(0,"M");
  321. Context::set('mlayout_list', $mobile_layout_list);
  322. $oSecurity = new Security();
  323. $oSecurity->encodeHTML('skin_list..', 'mskin_list..');
  324. $oSecurity->encodeHTML('layout_list..', 'mlayout_list..');
  325. // setting up the template
  326. $this->setTemplateFile('theme_info');
  327. }
  328. /**
  329. * @brief display forum admin skin info
  330. **/
  331. function dispForumAdminSkinInfo() {
  332. // getting module skin info html
  333. $oModuleAdminModel = &getAdminModel('module');
  334. $skin_content = $oModuleAdminModel->getModuleSkinHTML($this->module_info->module_srl);
  335. Context::set('skin_content', $skin_content);
  336. // setting up the template
  337. $this->setTemplateFile('skin_info');
  338. }
  339. /**
  340. * @brief display forum admin skin info
  341. **/
  342. function dispForumAdminMobileSkinInfo() {
  343. // getting module skin info html
  344. $oModuleAdminModel = &getAdminModel('module');
  345. $skin_content = $oModuleAdminModel->getModuleMobileSkinHTML($this->module_info->module_srl);
  346. Context::set('skin_content', $skin_content);
  347. $this->setTemplateFile('skin_info');
  348. }
  349. /**
  350. * @brief forum module alert message
  351. **/
  352. function alertMessage($message) {
  353. $script = sprintf('<script> xAddEventListener(window,"load", function() { alert("%s"); } );</script>', Context::getLang($message));
  354. Context::addHtmlHeader( $script );
  355. }
  356. }
  357. ?>