PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/class_cms.php

https://github.com/igorw-forks/icy_phoenix
PHP | 423 lines | 331 code | 29 blank | 63 comment | 48 complexity | ebd122a74ef5a304964635af00278c2e MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. if (!defined('IN_ICYPHOENIX'))
  11. {
  12. die('Hacking attempt');
  13. }
  14. /**
  15. * CMS class
  16. */
  17. class ip_cms
  18. {
  19. var $tables = array();
  20. /*
  21. * Initialize variables
  22. */
  23. function init_vars()
  24. {
  25. if (defined('IN_CMS_USERS'))
  26. {
  27. $this->tables = array(
  28. 'blocks_table' => CMS_USERS_BLOCKS_TABLE,
  29. 'block_settings_table' => CMS_USERS_BLOCK_SETTINGS_TABLE,
  30. 'block_position_table' => CMS_USERS_BLOCK_POSITION_TABLE,
  31. 'block_config_table' => CMS_USERS_CONFIG_TABLE,
  32. 'block_variable_table' => CMS_USERS_BLOCK_VARIABLE_TABLE,
  33. 'layout_table' => CMS_USERS_LAYOUT_TABLE,
  34. );
  35. }
  36. else
  37. {
  38. $this->tables = array(
  39. 'blocks_table' => CMS_BLOCKS_TABLE,
  40. 'block_settings_table' => CMS_BLOCK_SETTINGS_TABLE,
  41. 'block_position_table' => CMS_BLOCK_POSITION_TABLE,
  42. 'block_config_table' => CMS_CONFIG_TABLE,
  43. 'block_variable_table' => CMS_BLOCK_VARIABLE_TABLE,
  44. 'layout_table' => CMS_LAYOUT_TABLE,
  45. 'layout_special_table' => CMS_LAYOUT_SPECIAL_TABLE,
  46. );
  47. }
  48. return true;
  49. }
  50. /*
  51. *
  52. */
  53. function cms_assign_var_from_handle($template_var, $handle)
  54. {
  55. ob_start();
  56. $template_var->pparse($handle);
  57. $str = ob_get_contents();
  58. ob_end_clean();
  59. return $str;
  60. }
  61. /*
  62. *
  63. */
  64. function cms_blocks_view()
  65. {
  66. global $userdata, $config;
  67. $is_reg = (($config['bots_reg_auth'] && $userdata['is_bot']) || $userdata['session_logged_in']) ? true : false;
  68. if (!$is_reg)
  69. {
  70. $result = array(0, 1);
  71. }
  72. else
  73. {
  74. // User is not a guest here...
  75. switch($userdata['user_level'])
  76. {
  77. case ADMIN:
  78. // If you want admin to see also GUEST ONLY blocks you need to use these settings...
  79. //$result = array(0, 1, 2, 3, 4);
  80. $result = array(0, 2, 3, 4);
  81. break;
  82. case MOD:
  83. $result = array(0, 2, 3);
  84. break;
  85. default:
  86. $result = array(0, 2);
  87. break;
  88. }
  89. }
  90. return $result;
  91. }
  92. /*
  93. *
  94. */
  95. function cms_groups($user_id)
  96. {
  97. global $db;
  98. static $layout_groups;
  99. if(!isset($layout_groups))
  100. {
  101. $sql = "SELECT group_id FROM " . USER_GROUP_TABLE . " WHERE user_id = '" . $user_id . "' AND user_pending = 0";
  102. $result = $db->sql_query($sql);
  103. $layout_groups = array();
  104. $i = 0;
  105. while ($row = $db->sql_fetchrow($result))
  106. {
  107. $layout_groups[$i] = intval($row['group_id']);
  108. $i++;
  109. }
  110. $db->sql_freeresult($result);
  111. }
  112. return $layout_groups;
  113. }
  114. /*
  115. *
  116. */
  117. function cms_parse_blocks($layout, $is_special = false, $global_blocks = false, $type = '')
  118. {
  119. global $db, $cache, $config, $template, $userdata, $lang, $bbcode;
  120. global $cms_config_vars, $cms_config_layouts, $cms_config_global_blocks, $block_id;
  121. if(!$is_special)
  122. {
  123. $id_var_name = 'l_id';
  124. $table_name = $this->tables['layout_table'];
  125. $field_name = 'lid';
  126. $empty_block_tpl = 'cms_block_inc_wrapper.tpl';
  127. }
  128. else
  129. {
  130. $id_var_name = 'ls_id';
  131. $table_name = $this->tables['layout_special_table'];
  132. $field_name = 'lsid';
  133. $empty_block_tpl = 'cms_block_inc_wrapper.tpl';
  134. $layout = (isset($cms_config_layouts[$layout][$field_name]) ? $cms_config_layouts[$layout][$field_name] : 0);
  135. }
  136. if (!defined('CMS_BLOCKS_LANG_INCLUDED'))
  137. {
  138. $include_lang = $config['default_lang'];
  139. if(!@file_exists(IP_ROOT_PATH . 'language/lang_' . $include_lang . '/lang_blocks.' . PHP_EXT))
  140. {
  141. $include_lang = 'english';
  142. }
  143. include_once(IP_ROOT_PATH . 'language/lang_' . $include_lang . '/lang_blocks.' . PHP_EXT);
  144. define('CMS_BLOCKS_LANG_INCLUDED', true);
  145. }
  146. if(!$global_blocks && !$is_special)
  147. {
  148. $layout_pos = array();
  149. $sql_pos = "SELECT * FROM " . $this->tables['block_position_table'] . " WHERE layout = " . $layout;
  150. $block_pos_result = $db->sql_query($sql_pos, 0, 'cms_bp_', CMS_CACHE_FOLDER);
  151. while ($block_pos_row = $db->sql_fetchrow($block_pos_result))
  152. {
  153. $layout_pos[$block_pos_row['bposition']] = $block_pos_row['pkey'];
  154. }
  155. $db->sql_freeresult($block_pos_result);
  156. }
  157. $block_info = array();
  158. if($is_special || $global_blocks)
  159. {
  160. $temp_type = $type;
  161. }
  162. else
  163. {
  164. $temp_type = 's' . strval($layout);
  165. }
  166. $is_global_block = false;
  167. $is_gh_block = false;
  168. if(!$is_special && !$global_blocks)
  169. {
  170. /*
  171. $sql = "SELECT b.*, s.*
  172. FROM " . $this->tables['blocks_table'] . " AS b,
  173. " . $this->tables['block_settings_table'] . " AS s
  174. WHERE b.layout = " . $layout . "
  175. AND b.active = 1
  176. AND " . $db->sql_in_set('s.view', $this->cms_blocks_view()) . "
  177. AND b.bposition NOT IN ('gh','gf','gt','gb','gl','gr','hh','hl','hc','fc','fr','ff')
  178. AND b.block_settings_id = s.bs_id
  179. ORDER BY b.bposition ASC, b.layout ASC, b.layout_special ASC, b.weight ASC";
  180. */
  181. $sql = "SELECT *
  182. FROM " . $this->tables['blocks_table'] . "
  183. WHERE layout = " . $layout . "
  184. AND active = 1
  185. AND " . $db->sql_in_set('view', $this->cms_blocks_view()) . "
  186. AND bposition NOT IN ('gh','gf','gt','gb','gl','gr','hh','hl','hc','fc','fr','ff')
  187. ORDER BY bposition ASC, layout ASC, layout_special ASC, weight ASC";
  188. $block_im_result = $db->sql_query($sql, 0, 'cms_blocks_', CMS_CACHE_FOLDER);
  189. $block_info = array();
  190. while ($row = $db->sql_fetchrow($block_im_result))
  191. {
  192. $block_info[] = $row;
  193. }
  194. $db->sql_freeresult($block_im_result);
  195. }
  196. else
  197. {
  198. switch ($type)
  199. {
  200. case 'gheader':
  201. $temp_pos = 'gh';
  202. break;
  203. case 'gfooter':
  204. $temp_pos = 'gf';
  205. break;
  206. case 'ghtop':
  207. $temp_pos = 'gt';
  208. $empty_block_tpl = 'cms_block_inc_wrapper_buttons.tpl';
  209. $is_gh_block = true;
  210. break;
  211. case 'ghbottom':
  212. $temp_pos = 'gb';
  213. $empty_block_tpl = 'cms_block_inc_wrapper_buttons.tpl';
  214. $is_gh_block = true;
  215. break;
  216. case 'ghleft':
  217. $temp_pos = 'gl';
  218. $empty_block_tpl = 'cms_block_inc_wrapper_plain.tpl';
  219. $is_gh_block = true;
  220. break;
  221. case 'ghright':
  222. $temp_pos = 'gr';
  223. $empty_block_tpl = 'cms_block_inc_wrapper_plain.tpl';
  224. $is_gh_block = true;
  225. break;
  226. case 'header':
  227. $temp_pos = 'hh';
  228. break;
  229. case 'headerleft':
  230. $temp_pos = 'hl';
  231. $is_global_block = true;
  232. break;
  233. case 'headercenter':
  234. $temp_pos = 'hc';
  235. $is_global_block = true;
  236. break;
  237. case 'tailcenter':
  238. $temp_pos = 'fc';
  239. $is_global_block = true;
  240. break;
  241. case 'tailright':
  242. $temp_pos = 'fr';
  243. $is_global_block = true;
  244. break;
  245. case 'tail':
  246. $temp_pos = 'ff';
  247. break;
  248. default:
  249. $temp_pos = 'tt';
  250. break;
  251. }
  252. if ($is_special && !$global_blocks)
  253. {
  254. $sql_where = "AND layout_special = " . $layout;
  255. $check_array = array($layout);
  256. }
  257. elseif ($is_special && $global_blocks && ($layout != 0))
  258. {
  259. $sql_where = "AND layout_special IN(0, " . $layout . ")";
  260. $check_array = array(0, $layout);
  261. }
  262. else
  263. {
  264. $sql_where = "AND layout_special = 0";
  265. $check_array = array(0);
  266. }
  267. if (empty($cms_config_global_blocks))
  268. {
  269. $cms_config_global_blocks = $cache->obtain_cms_global_blocks_config(false);
  270. }
  271. $block_info = array();
  272. if (!empty($cms_config_global_blocks[$temp_pos]))
  273. {
  274. foreach ($cms_config_global_blocks[$temp_pos] as $row)
  275. {
  276. if (in_array($row['layout_special'], $check_array))
  277. {
  278. $block_info[] = $row;
  279. }
  280. }
  281. }
  282. /*
  283. $sql = "SELECT *
  284. FROM " . CMS_BLOCKS_TABLE . "
  285. WHERE layout = 0
  286. " . $sql_where . "
  287. AND active = 1
  288. AND " . $db->sql_in_set('view', $this->cms_blocks_view()) . "
  289. AND bposition = '" . $temp_pos . "'
  290. ORDER BY layout ASC, weight ASC";
  291. $block_im_result = $db->sql_query($sql, 0, 'cms_blocks_', CMS_CACHE_FOLDER);
  292. $block_info = array();
  293. while ($row = $db->sql_fetchrow($block_im_result))
  294. {
  295. $block_info[] = $row;
  296. }
  297. $db->sql_freeresult($block_im_result);
  298. */
  299. }
  300. $block_count = sizeof($block_info);
  301. if (($is_global_block || $is_gh_block) && ($block_count == 0))
  302. {
  303. return false;
  304. }
  305. for ($b_counter = 0; $b_counter < $block_count; $b_counter++)
  306. {
  307. $block_id = $block_info[$b_counter]['bid'];
  308. $is_group_allowed = true;
  309. if(!empty($block_info[$b_counter]['groups']))
  310. {
  311. $is_group_allowed = false;
  312. $group_content = explode(',', $block_info[$b_counter]['groups']);
  313. for ($i = 0; $i < sizeof($group_content); $i++)
  314. {
  315. if(in_array(intval($group_content[$i]), $this->cms_groups($userdata['user_id'])))
  316. {
  317. $is_group_allowed = true;
  318. }
  319. }
  320. }
  321. if($is_group_allowed)
  322. {
  323. if($is_special || $global_blocks)
  324. {
  325. $position = $type;
  326. }
  327. else
  328. {
  329. $position = $layout_pos[$block_info[$b_counter]['bposition']];
  330. }
  331. $position_prefix = $position . '_';
  332. $block_name = $block_info[$b_counter]['blockfile'];
  333. if(($block_info[$b_counter]['local'] == 1) && !empty($lang['Title_' . $block_name]))
  334. {
  335. $title_string = $lang['Title_' . $block_name];
  336. }
  337. else
  338. {
  339. $title_string = stripslashes($block_info[$b_counter]['title']);
  340. }
  341. if(!empty($block_info[$b_counter]['blockfile']))
  342. {
  343. $block_handle = $block_name . '_block_' . $block_info[$b_counter]['bid'];
  344. $template->set_filenames(array($block_handle => 'blocks/' . $block_name . '_block.tpl'));
  345. $output_block = '';
  346. include(IP_ROOT_PATH . 'blocks/' . $block_info[$b_counter]['blockfile'] . '.' . PHP_EXT);
  347. $output_block = $this->cms_assign_var_from_handle($template, $block_handle);
  348. }
  349. else
  350. {
  351. $message = stripslashes($block_info[$b_counter]['content']);
  352. if($block_info[$b_counter]['type'] == true)
  353. {
  354. @include_once(IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
  355. //$message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);
  356. $bbcode->allow_html = false;
  357. $bbcode->allow_bbcode = true;
  358. $bbcode->allow_smilies = true;
  359. $message = $bbcode->parse($message);
  360. //$message = str_replace("\n", "\n<br />\n", $message);
  361. $message = '<div class="post-text">' . $message . '</div>';
  362. }
  363. else
  364. {
  365. // You shouldn't convert NEW LINES to <br /> because you are parsing HTML, so linebreaks must be inserted as <br />
  366. // If you want linebreaks to be converted automatically, just decomment this line.
  367. //$message = str_replace("\n", "\n<br />\n", $message);
  368. }
  369. $output_block = $message;
  370. }
  371. $block_handle = 'block_' . $block_info[$b_counter]['bid'];
  372. $template->set_filenames(array($block_handle => $empty_block_tpl));
  373. $template->assign_vars(array(
  374. 'POSITION' => $position,
  375. 'OUTPUT' => $output_block,
  376. 'TITLE_CONTENT' => (($title_string == '') ? '&nbsp;' : $title_string),
  377. 'TITLE' => (($block_info[$b_counter]['titlebar'] == 1) ? true : false),
  378. 'BORDER' => (($block_info[$b_counter]['border'] == 1) ? true : false),
  379. 'BACKGROUND' => (($block_info[$b_counter]['background'] == 1) ? true : false),
  380. )
  381. );
  382. $cms_block = $this->cms_assign_var_from_handle($template, $block_handle);
  383. $template->assign_block_vars($position_prefix . 'blocks_row', array(
  384. 'CMS_BLOCK' => $cms_block,
  385. 'OUTPUT' => $output_block
  386. )
  387. );
  388. }
  389. }
  390. return true;
  391. }
  392. }
  393. ?>