PageRenderTime 384ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/content.php

https://bitbucket.org/simancms/simancms
PHP | 568 lines | 537 code | 18 blank | 13 comment | 180 complexity | 60690e666980da4ecf2ae1f754276c15 MD5 | raw file
  1. <?php
  2. //------------------------------------------------------------------------------
  3. //| Content Management System SiMan CMS |
  4. //| http://www.simancms.org |
  5. //------------------------------------------------------------------------------
  6. /*
  7. Module Name: Content
  8. Module URI: http://simancms.org/modules/content/
  9. Description: Pages management. Base CMS module
  10. Version: 1.6.21
  11. Revision: 2021-10-31
  12. Author URI: http://simancms.org/
  13. */
  14. use SM\SM;
  15. if (!defined("SIMAN_DEFINED"))
  16. exit('Hacking attempt!');
  17. if (!defined("CONTENT_FUNCTIONS_DEFINED"))
  18. {
  19. function siman_load_ctgs_content($id_mainctg = -1, $extsql = '')
  20. {
  21. $addsql='';
  22. if (!empty($extsql))
  23. $addsql = ' WHERE '.$extsql;
  24. if ($id_mainctg >= 0)
  25. {
  26. if (empty($addsql))
  27. $addsql = " WHERE ";
  28. else
  29. $addsql .= " AND ";
  30. $addsql .= " id_maincategory=".intval($id_mainctg);
  31. }
  32. $sql = "SELECT * FROM ".sm_table_prefix()."categories $addsql";
  33. $sql .= " ORDER BY id_maincategory, IF(id_category=1, 0, 1), title_category";
  34. $result = execsql($sql);
  35. $i = 0;
  36. $ctg=[];
  37. while ($row = database_fetch_assoc($result))
  38. {
  39. $ctg[$i]['id'] = $row['id_category'];
  40. $ctg[$i]['title'] = $row['title_category'];
  41. $ctg[$i]['can_view'] = $row['can_view'];
  42. $ctg[$i]['main_ctg'] = $row['id_maincategory'];
  43. $ctg[$i]['sorting_category'] = $row['sorting_category'];
  44. $ctg[$i]['preview_category'] = $row['preview_category'];
  45. $ctg[$i]['groups_view'] = $row['groups_view'];
  46. $ctg[$i]['groups_modify'] = $row['groups_modify'];
  47. $ctg[$i]['level'] = 1;
  48. $ctg[$i]['filename'] = sm_fs_url('index.php?m=content&d=viewctg&ctgid='.$row['id_category']);
  49. $i++;
  50. }
  51. for ($i = 0; $i < sm_count($ctg); $i++)
  52. {
  53. $pos[$i] = 0;
  54. }
  55. for ($i = 0; $i < sm_count($ctg); $i++)
  56. {
  57. if ($ctg[$i]['main_ctg'] == 0)
  58. {
  59. $maxpos = 0;
  60. for ($j = 0; $j < sm_count($ctg); $j++)
  61. {
  62. if ($maxpos < $pos[$j])
  63. $maxpos = $pos[$j];
  64. }
  65. $pos[$i] = $maxpos + 1;
  66. }
  67. else
  68. {
  69. $rootpos = 0;
  70. $childpos = -1;
  71. for ($j = 0; $j < sm_count($ctg); $j++)
  72. {
  73. if ($ctg[$j]['id'] == $ctg[$i]['main_ctg'])
  74. {
  75. $rootpos = $pos[$j];
  76. $ctg[$i]['level'] = $ctg[$j]['level'] + 1;
  77. $ctg[$j]['is_mainctg'] = 1;
  78. }
  79. if ($ctg[$j]['main_ctg'] == $ctg[$i]['main_ctg'] && $j != $i && $childpos < $pos[$j])
  80. $childpos = $pos[$j];
  81. }
  82. $pos[$i] = ($rootpos > $childpos) ? ($rootpos + 1) : ($childpos + 1);
  83. for ($j = 0; $j < sm_count($ctg); $j++)
  84. {
  85. if ($pos[$j] >= $pos[$i] && $j != $i)
  86. $pos[$j]++;
  87. }
  88. }
  89. }
  90. $rctg=[];
  91. for ($i = 0; $i < sm_count($ctg); $i++)
  92. {
  93. $rctg[$pos[$i] - 1] = $ctg[$i];
  94. }
  95. return $rctg;
  96. }
  97. define("CONTENT_FUNCTIONS_DEFINED", 1);
  98. }
  99. $tmp_load_preview_only = 0;
  100. $tmp_dont_set_title = 0;
  101. sm_default_action('view');
  102. if (sm_action('view'))
  103. {
  104. if (!empty($m['bid'])) $m['cid'] = intval($m['bid']);
  105. $content_id = intval(sm_get_array_value($m, 'cid'));
  106. if (empty($content_id) && sm_is_main_block())
  107. {
  108. $content_id = intval(sm_getvars('cid'));
  109. if (sm_is_index_page() && empty($content_id))
  110. $content_id=1;
  111. }
  112. if (empty($content_id))
  113. {
  114. sm_title($lang['error']);
  115. $m['text'] = $lang['messages']['nothing_found'];
  116. $content_error = 1;
  117. }
  118. else
  119. {
  120. sm_template('content');
  121. sm_page_viewid('content-view-'.$content_id);
  122. $sql = "SELECT ".sm_table_prefix()."content.*, ".sm_table_prefix()."categories.* FROM ".sm_table_prefix()."content, ".sm_table_prefix()."categories WHERE ".sm_table_prefix()."content.id_category_c=".sm_table_prefix()."categories.id_category AND id_content=".intval($content_id);
  123. if (sm_is_main_block())
  124. $sql .= " AND refuse_direct_show <> 1";
  125. $sql .= " LIMIT 1";
  126. }
  127. if (intval(sm_settings('allow_alike_content')) != 1)
  128. $tmp_no_alike_content = true;
  129. }
  130. if (sm_action('viewlast') || sm_action('viewfirst'))
  131. {
  132. sm_page_viewid('content-viewlast');
  133. sm_template('content');
  134. $tmp_ctg = intval(sm_getvars('ctg'));
  135. $sql = "SELECT ".sm_table_prefix()."content.*, ".sm_table_prefix()."categories.* FROM ".sm_table_prefix()."content, ".sm_table_prefix()."categories WHERE ".sm_table_prefix()."content.id_category_c=".sm_table_prefix()."categories.id_category";
  136. if (!empty($tmp_ctg))
  137. $sql .= " AND ".sm_table_prefix()."content.id_category_c=".intval($tmp_ctg);
  138. if (sm_action('viewlast'))
  139. $sql .= " ORDER BY ".sm_table_prefix()."content.id_content DESC LIMIT 1";
  140. else
  141. $sql .= " ORDER BY ".sm_table_prefix()."content.id_content ASC LIMIT 1";
  142. $m["mode"] = 'view';
  143. if (sm_settings('allow_alike_content')!=1)
  144. $tmp_no_alike_content = true;
  145. }
  146. if (sm_action('multiview'))
  147. {
  148. sm_template('content');
  149. if (!empty($m["bid"]))
  150. $ctg_id = intval($m["bid"]);
  151. else
  152. $ctg_id = intval(sm_getvars('ctgid'));
  153. if (!empty($ctg_id))
  154. {
  155. sm_page_viewid('content-multiview-'.$ctg_id);
  156. $m['subcategories'] = siman_load_ctgs_content($ctg_id);
  157. $m['subcategories_present'] = 1;
  158. $sql = "SELECT * FROM ".sm_table_prefix()."categories WHERE id_category=".intval($ctg_id);
  159. $result = execsql($sql);
  160. while ($row = database_fetch_object($result))
  161. {
  162. $m['category']['id_ctg'] = $row->id_category;
  163. $m['category']['title_category'] = $row->title_category;
  164. $m['category']['category_can_view'] = $row->can_view;
  165. $m['category']['main_ctg'] = $row->id_maincategory;
  166. $m['category']['preview_ctg'] = $row->preview_category;
  167. }
  168. }
  169. else
  170. sm_page_viewid('content-multiview');
  171. $sql = "SELECT ".sm_table_prefix()."content.*, ".sm_table_prefix()."categories.* FROM ".sm_table_prefix()."content, ".sm_table_prefix()."categories WHERE ".sm_table_prefix()."content.id_category_c=".sm_table_prefix()."categories.id_category";
  172. $sql .= ' AND '.sm_table_prefix().'categories.can_view<='.SM::User()->Level();
  173. if (!empty($ctg_id))
  174. $sql .= ' AND '.sm_table_prefix().'content.id_category_c='.intval($ctg_id);
  175. $sql .= ' ORDER BY '.sm_table_prefix().'content.priority_content DESC"';
  176. if (sm_settings('content_multiview') == 'off')
  177. {
  178. $sql .= ' LIMIT 1';
  179. }
  180. else
  181. {
  182. if (!empty(sm_getvars('count')))
  183. {
  184. if (is_numeric(sm_getvars('count')))
  185. $sql .= ' LIMIT '.intval(sm_getvars('count'));
  186. else
  187. $sql .= ' LIMIT '.intval(sm_settings('content_per_page_multiview'));
  188. }
  189. else
  190. {
  191. $sql .= ' LIMIT '.intval(sm_settings('content_per_page_multiview'));
  192. }
  193. }
  194. $tmp_dont_set_title = 1;
  195. $tmp_load_preview_only = 1;
  196. $tmp_no_alike_content = true;
  197. $m["mode"] = 'view';
  198. }
  199. if (sm_action('rndctgview'))
  200. {
  201. sm_page_viewid('content-rndctgview');
  202. sm_template('content');
  203. if (!empty($m["bid"]))
  204. $ctg_id = intval($m["bid"]);
  205. else
  206. $ctg_id = intval(sm_getvars('ctgid'));
  207. $sql = "SELECT ".database_get_fn_name('rand')."() as rndrow,".sm_table_prefix()."content.*, ".sm_table_prefix()."categories.* FROM ".sm_table_prefix()."content, ".sm_table_prefix()."categories WHERE ".sm_table_prefix()."content.id_category_c=".sm_table_prefix()."categories.id_category";
  208. $sql .= ' AND '.sm_table_prefix().'categories.can_view<='.SM::User()->Level();
  209. if (!empty($ctg_id))
  210. $sql .= ' AND '.sm_table_prefix().'content.id_category_c='.intval($ctg_id);
  211. $sql .= ' ORDER BY rndrow LIMIT 1';
  212. $m["mode"] = 'view';
  213. $tmp_no_alike_content = true;
  214. }
  215. if (sm_action('view'))
  216. {
  217. if (!isset($content_error) || $content_error != 1)
  218. {
  219. if (!isset($tmp_no_alike_content))
  220. $tmp_no_alike_content=false;
  221. $result = execsql($sql);
  222. $i = 0;
  223. while ($row = database_fetch_assoc($result))
  224. {
  225. if ($row['type_content'] == 2)
  226. {
  227. @header('Content-type: text/plain; charset='.sm_encoding());
  228. print($row['text_content']);
  229. exit();
  230. }
  231. sm_event('onbeforecontentprocessing', $i);
  232. if (sm_is_main_block() && $i==0 && !empty($content_id))
  233. sm_meta_canonical(sm_fs_url('index.php?m=content&d=view&cid='.$content_id));
  234. if (!isset($content_id))
  235. $content_id=intval($row['id_content']);
  236. $m['content'][$i]["title"] = $row['title_content'];
  237. sm_add_title_modifier($m['content'][$i]["title"]);
  238. if ($tmp_dont_set_title != 1)
  239. sm_title($m['content'][$i]["title"]);
  240. if ($tmp_load_preview_only == 1)
  241. {
  242. $m['content'][$i]["text"] = $row['preview_content'];
  243. if (empty($m['content'][$i]["text"]))
  244. $m['content'][$i]["text"] = cut_str_by_word($row['text_content'], 300, '...');
  245. $m['content'][$i]['fullink'] = sm_fs_url('index.php?m=content&d=view&cid='.$row['id_content']);
  246. }
  247. else
  248. $m['content'][$i]["text"] = $row['text_content'];
  249. sm_add_content_modifier($m['content'][$i]["text"]);
  250. $m['content'][$i]["id_category"] = $row['id_category_c'];
  251. if ($special['categories']['getctg'] == 1)
  252. $special['categories']['id'] = $row['id_category_c'];
  253. $m['content'][$i]["title_category"] = $row['title_category'];
  254. if (sm_is_main_block() && $i == 0 && sm_settings('content_use_path') == 1 && $row['no_use_path'] != 1 && !sm_is_index_page())
  255. {
  256. $tmppath = sm_get_path_tree(sm_table_prefix()."categories", 'id_category', 'id_maincategory', $row['id_category_c']);
  257. add_path_home();
  258. for ($tmpi = 0; $tmpi < sm_count($tmppath); $tmpi++)
  259. {
  260. add_path(
  261. $tmppath[$tmpi]['title_category'],
  262. 'index.php?m=content&d=viewctg&ctgid='.$tmppath[$tmpi]['id_category']
  263. );
  264. }
  265. }
  266. if (sm_is_main_block() && $i == 0)
  267. $m['content'][$i]['attachments'] = sm_get_attachments('content', $row['id_content']);
  268. if (!$tmp_no_alike_content)
  269. if ($row['no_alike_content'] == 1)
  270. $tmp_no_alike_content = true;
  271. if ($row['can_view'] <= SM::User()->Level())
  272. $m['content'][$i]["can_view"] = 1;
  273. else
  274. {
  275. if (!empty($userinfo['groups']))
  276. {
  277. if (compare_groups($userinfo['groups'], $row['groups_view']))
  278. $m['content'][$i]["can_view"] = 1;
  279. else
  280. $m['content'][$i]["can_view"] = 0;
  281. }
  282. else
  283. $m['content'][$i]["can_view"] = 0;
  284. if ($m['content'][$i]["can_view"] == 0)
  285. {
  286. $m['content'][$i]["title"] = $lang['access_denied'];
  287. }
  288. }
  289. if ($row['type_content'] == 0)
  290. {
  291. $m['content'][$i]["text"] = nl2br($m['content'][$i]["text"]);
  292. }
  293. if (SM::User()->Level()>=intval(sm_settings('content_editor_level')) && sm_is_main_block())
  294. {
  295. $m['content'][$i]["can_edit"] = 1;
  296. $m['content'][$i]["can_delete"] = 1;
  297. }
  298. elseif (!empty($userinfo['groups']))
  299. {
  300. if (compare_groups($userinfo['groups'], $row['groups_modify']) && sm_is_main_block())
  301. {
  302. $m['content'][$i]["can_edit"] = 1;
  303. $m['content'][$i]["can_delete"] = 1;
  304. }
  305. }
  306. $m['content'][$i]["cid"] = $content_id;
  307. if (sm_settings('content_use_image') == 1)
  308. {
  309. if (file_exists('files/fullimg/content'.$content_id.'.jpg'))
  310. {
  311. if ($tmp_load_preview_only == 1)
  312. $m['content'][$i]['image'] = 'files/thumb/content'.$content_id.'.jpg';
  313. else
  314. $m['content'][$i]['image'] = 'files/fullimg/content'.$content_id.'.jpg';
  315. }
  316. elseif (file_exists('files/img/content'.$content_id.'.jpg'))
  317. {
  318. $m['content'][$i]['image'] = 'ext/showimage.php?img=content'.$content_id;
  319. if ($tmp_load_preview_only == 1)
  320. {
  321. if (!sm_empty_settings('content_image_preview_width'))
  322. $m['content'][$i]['image'] .= '&width='.sm_settings('content_image_preview_width');
  323. if (!sm_empty_settings('content_image_preview_height'))
  324. $m['content'][$i]['image'] .= '&height='.sm_settings('content_image_preview_height');
  325. }
  326. else
  327. {
  328. if (!sm_empty_settings('content_image_fulltext_width'))
  329. $m['content'][$i]['image'] .= '&width='.sm_settings('content_image_fulltext_width');
  330. if (!sm_empty_settings('content_image_fulltext_height'))
  331. $m['content'][$i]['image'] .= '&height='.sm_settings('content_image_fulltext_height');
  332. }
  333. }
  334. }
  335. if (sm_is_main_block())
  336. {
  337. if (!empty($special['meta']['keywords']) && !empty($row['keywords_content']))
  338. {
  339. $special['meta']['keywords'] = ($row['keywords_content']).', '.$special['meta']['keywords'];
  340. }
  341. elseif (!empty($row['keywords_content']))
  342. {
  343. $special['meta']['keywords'] = $row['keywords_content'];
  344. }
  345. if (!empty($row['description_content']))
  346. $special['meta']['description'] = $row['description_content'];
  347. if (isset($m['content'][$i]['can_edit']) && $m['content'][$i]['can_edit']==1)
  348. $m['content'][$i]['edit_url']='index.php?m=content&d=edit&cid='.$m['content'][$i]["cid"].'&returnto='.urlencode(sm_this_url());
  349. if (isset($m['content'][$i]['can_delete']) && $m['content'][$i]['can_delete']==1)
  350. $m['content'][$i]['delete_url']='index.php?m=content&d=delete&cid='.$m['content'][$i]["cid"].'&ctg='.$m['content'][$i]["id_category"].'&returnto='.urlencode(sm_this_url());
  351. }
  352. if (!$tmp_no_alike_content && sm_is_main_block() && $m['panel'] == 'center' && $m['content'][$i]["can_view"] != 0 && !sm_is_index_page())
  353. {
  354. $tmpsql = "SELECT * FROM ".sm_table_prefix()."content WHERE id_content<>".intval($m['content'][$i]["cid"])." AND id_category_c=".intval($m['content'][$i]['id_category'])." ORDER BY priority_content DESC LIMIT ".intval(sm_settings('alike_content_count'));
  355. $tmpresult = execsql($tmpsql);
  356. $j = 0;
  357. while ($tmprow = database_fetch_assoc($tmpresult))
  358. {
  359. $m['content'][$i]['alike_texts'][$j]['id'] = $tmprow['id_content'];
  360. $m['content'][$i]['alike_texts'][$j]['title'] = $tmprow['title_content'];
  361. $m['content'][$i]['alike_texts'][$j]['fullink'] = sm_fs_url('index.php?m=content&d=view&cid='.$tmprow['id_content']);
  362. $m['content'][$i]['alike_texts'][$j]['preview'] = $tmprow['preview_content'];
  363. if (empty($m['content'][$i]['alike_texts'][$j]['preview']))
  364. $m['content'][$i]['alike_texts'][$j]['preview'] = cut_str_by_word($tmprow['text_content'], 300, '...');
  365. sm_add_title_modifier($m['content'][$i]['alike_texts'][$j]['title']);
  366. sm_add_content_modifier($m['content'][$i]['alike_texts'][$j]['preview']);
  367. $j++;
  368. }
  369. $m['content'][$i]['alike_texts_present'] = $j;
  370. }
  371. else
  372. $m['content'][$i]['alike_texts_present'] = 0;
  373. $m['content'][$i]['data']=$row;
  374. $tmp=sm_load_metadata('content', $row['id_content']);
  375. if (!empty($tmp['main_template']) && sm_is_main_block())
  376. sm_set_main_template($tmp['main_template']);
  377. if (!empty($tmp['content_template']) && $i==0)
  378. sm_template($tmp['content_template']);
  379. if (!empty($tmp['seo_title']) && sm_is_main_block())
  380. sm_meta_title($tmp['seo_title']);
  381. sm_event('oncontentprocessed', $i);
  382. $i++;
  383. }
  384. if ($i == 0)
  385. sm_template('');
  386. elseif (sm_is_main_block())
  387. sm_event('onviewcontent', array($m['content'][0]["cid"]));
  388. }
  389. }
  390. if (sm_action('viewctg'))
  391. {
  392. sm_template('content');
  393. if (empty(sm_getvars('ctgid')) && !empty(sm_getvars('ctg')))
  394. sm_set_array_value($_getvars, 'ctgid', sm_getvars('ctg'));
  395. $ctg_id = intval(sm_getvars('ctgid'));
  396. sm_page_viewid('content-viewctg-'.$ctg_id);
  397. $sql = "SELECT * FROM ".sm_table_prefix()."categories WHERE id_category=".intval($ctg_id);
  398. $result = execsql($sql);
  399. $i=0;
  400. while ($row = database_fetch_assoc($result))
  401. {
  402. sm_event('onbeforecontentcategoriespathprocessing', $i);
  403. if (sm_is_main_block() && sm_settings('content_use_path') == 1 && $row['no_use_path'] != 1)
  404. {
  405. $tmppath = sm_get_path_tree(sm_table_prefix()."categories", 'id_category', 'id_maincategory', $row['id_maincategory']);
  406. add_path_home();
  407. for ($tmpi = 0; $tmpi < sm_count($tmppath); $tmpi++)
  408. {
  409. add_path(
  410. $tmppath[$tmpi]['title_category'],
  411. sm_fs_url('index.php?m=content&d=viewctg&ctgid='.$tmppath[$tmpi]['id_category'])
  412. );
  413. }
  414. }
  415. if ($special['categories']['getctg'] == 1)
  416. $special['categories']['id'] = $row['id_category'];
  417. sm_title($row['title_category']);
  418. $m['preview_category'] = $row['preview_category'];
  419. $m['sorting_category'] = $row['sorting_category'];
  420. if ($row['can_view'] <= SM::User()->Level())
  421. $m['category']['can_view'] = 1;
  422. else
  423. {
  424. if (!empty($userinfo['groups']))
  425. {
  426. if (compare_groups($userinfo['groups'], $row['groups_view']))
  427. $m['category']['can_view'] = 1;
  428. else
  429. $m['category']['can_view'] = 0;
  430. }
  431. else
  432. $m['category']['can_view'] = 0;
  433. if ($m['category']['can_view'] == 0)
  434. sm_title($lang['access_denied']);
  435. }
  436. $m['subcategories'] = siman_load_ctgs_content($row['id_category']);
  437. sm_add_content_modifier($m['preview_category']);
  438. $i++;
  439. }
  440. $sql = "SELECT ".sm_table_prefix()."content.* FROM ".sm_table_prefix()."content WHERE ".sm_table_prefix()."content.id_category_c=".intval($ctg_id);
  441. if ($m['sorting_category'] == 3)
  442. $sql .= " ORDER BY priority_content DESC";
  443. elseif ($m['sorting_category'] == 1)
  444. $sql .= " ORDER BY title_content DESC";
  445. elseif ($m['sorting_category'] == 2)
  446. $sql .= " ORDER BY priority_content ASC";
  447. else
  448. $sql .= " ORDER BY title_content ASC";
  449. //$sql="SELECT * FROM ".sm_table_prefix()."content WHERE id_category_c='$ctg_id'";
  450. $result = execsql($sql);
  451. $i = 0;
  452. while ($row = database_fetch_assoc($result))
  453. {
  454. sm_event('onbeforeviewctgcontentprocessing', $i);
  455. $m['category']['ctg'][$i]['title'] = $row['title_content'];
  456. $m['category']['ctg'][$i]['id'] = $row['id_content'];
  457. $m['category']['ctg'][$i]['url'] = sm_fs_url('index.php?m=content&d=view&cid='.$row['id_content']);
  458. if (sm_settings('content_use_preview') == 1)
  459. {
  460. $m['category']['ctg'][$i]['preview'] = $row['preview_content'];
  461. }
  462. if (sm_settings('content_use_image') == 1)
  463. {
  464. if (file_exists('files/thumb/content'.$m['category']['ctg'][$i]['id'].'.jpg'))
  465. {
  466. $m['category']['ctg'][$i]['image'] = 'files/thumb/content'.$m['category']['ctg'][$i]['id'].'.jpg';
  467. }
  468. elseif (file_exists('files/img/content'.$m['category']['ctg'][$i]['id'].'.jpg'))
  469. {
  470. $m['category']['ctg'][$i]['image'] = 'ext/showimage.php?img=content'.$m['category']['ctg'][$i]['id'];
  471. if (!sm_empty_settings('content_image_preview_width'))
  472. $m['category']['ctg'][$i]['image'] .= '&width='.sm_settings('content_image_preview_width');
  473. if (!sm_empty_settings('content_image_preview_height'))
  474. $m['category']['ctg'][$i]['image'] .= '&height='.sm_settings('content_image_preview_height');
  475. }
  476. }
  477. sm_add_title_modifier($m['category']['ctg'][$i]['title']);
  478. sm_add_content_modifier($m['category']['ctg'][$i]['preview']);
  479. $i++;
  480. }
  481. }
  482. if (sm_action('blockctgview'))
  483. {
  484. sm_template('content');
  485. if (isset($modules[0]['content'][0]["id_category"]))
  486. $ctg_id = intval($modules[0]['content'][0]["id_category"]);
  487. else
  488. $ctg_id = 0;
  489. if (empty($ctg_id) || $ctg_id == 1)
  490. sm_set_action('donotshow');
  491. else
  492. {
  493. $sql = "SELECT * FROM ".sm_table_prefix()."categories WHERE id_category=".intval($ctg_id);
  494. $result = execsql($sql);
  495. $i=0;
  496. while ($row = database_fetch_assoc($result))
  497. {
  498. sm_event('onbeforeblockctgviewcontentprocessing', $i);
  499. sm_title($row['title_category']);
  500. $m['sorting_category'] = $row['sorting_category'];
  501. if ($row['can_view'] <= SM::User()->Level())
  502. $m['category']['can_view'] = 1;
  503. else
  504. {
  505. if (!empty($userinfo['groups']))
  506. {
  507. if (compare_groups($userinfo['groups'], $row['groups_view']))
  508. $m['category']['can_view'] = 1;
  509. else
  510. $m['category']['can_view'] = 0;
  511. }
  512. else
  513. $m['category']['can_view'] = 0;
  514. if ($m['category']['can_view'] == 0)
  515. sm_set_action('donotshow');
  516. }
  517. $i++;
  518. }
  519. $sql = "SELECT ".sm_table_prefix()."content.* FROM ".sm_table_prefix()."content WHERE ".sm_table_prefix()."content.id_category_c=".intval($ctg_id);
  520. if ($m['sorting_category'] == 3)
  521. $sql .= " ORDER BY priority_content DESC";
  522. elseif ($m['sorting_category'] == 1)
  523. $sql .= " ORDER BY title_content DESC";
  524. elseif ($m['sorting_category'] == 2)
  525. $sql .= " ORDER BY priority_content ASC";
  526. else
  527. $sql .= " ORDER BY title_content ASC";
  528. $result = execsql($sql);
  529. $i = 0;
  530. $m['menu'] = Array();
  531. while ($row = database_fetch_assoc($result))
  532. {
  533. $m['category']['ctg'][$i]['title'] = $row['title_content'];
  534. $m['category']['ctg'][$i]['id'] = $row['id_content'];
  535. $m['category']['ctg'][$i]['url'] = sm_fs_url('index.php?m=content&d=view&cid='.$row['id_content']);
  536. sm_add_menuitem($m['menu'], $row['title_content'], $m['category']['ctg'][$i]['url']);
  537. sm_add_title_modifier($m['category']['ctg'][$i]['title']);
  538. $i++;
  539. }
  540. if ($i > 0)
  541. {
  542. sm_template('menu');
  543. sm_set_action('view');
  544. }
  545. else
  546. sm_set_action('donotshow');
  547. }
  548. }
  549. if (SM::isLoggedIn())
  550. include('modules/inc/memberspart/content.php');