PageRenderTime 67ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/root/includes/acp/acp_blogs.php

https://github.com/EXreaction/User-Blog-Mod
PHP | 2191 lines | 1711 code | 374 blank | 106 comment | 231 complexity | cac6fe4eb7b7f6c14915ae2c6530ad8f MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. *
  4. * @package phpBB3 User Blog
  5. * @version $Id: acp_blogs.php 485 2008-08-15 23:33:57Z exreaction@gmail.com $
  6. * @copyright (c) 2008 EXreaction
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @package acp
  12. */
  13. class acp_blogs
  14. {
  15. var $u_action;
  16. var $new_config = array();
  17. var $state;
  18. var $search;
  19. var $max_post_id;
  20. var $batch_size = 100;
  21. var $parent_id = 0;
  22. function main($id, $mode)
  23. {
  24. global $phpbb_root_path, $phpEx, $user;
  25. $submit = (isset($_POST['submit'])) ? true : false;
  26. // Check Form Key
  27. add_form_key('acp_blogs');
  28. if ($submit && !check_form_key('acp_blogs'))
  29. {
  30. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  31. }
  32. include($phpbb_root_path . 'blog/functions.' . $phpEx);
  33. include($phpbb_root_path . 'blog/includes/functions_admin.' . $phpEx);
  34. $user->add_lang(array('mods/blog/common', 'mods/blog/acp', 'mods/blog/setup'));
  35. switch($mode)
  36. {
  37. case 'plugins' :
  38. $this->plugins($id, $mode);
  39. break;
  40. case 'search' :
  41. $this->search($id, $mode);
  42. break;
  43. case 'categories' :
  44. $this->categories($id, $mode);
  45. break;
  46. case 'ext_groups' :
  47. $this->extensions($id, $mode);
  48. break;
  49. default :
  50. $default = true;
  51. $temp = compact('default', 'id', 'mode');
  52. blog_plugins::plugin_do_ref('acp_default', $temp); // make sure to set default to false if you use your own page
  53. extract($temp);
  54. if ($default)
  55. {
  56. $this->settings($id, $mode);
  57. }
  58. }
  59. blog_plugins::plugin_do('acp_end');
  60. }
  61. function settings($id, $mode)
  62. {
  63. global $config, $db, $user, $auth, $template;
  64. global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
  65. $submit = (isset($_POST['submit'])) ? true : false;
  66. $action = request_var('action', '');
  67. $this->tpl_name = 'acp_board';
  68. $this->page_title = $user->lang['ACP_BLOGS'];
  69. blog_plugins::plugin_do('acp_main_start');
  70. $settings = array(
  71. 'legend0' => 'VERSION',
  72. 'user_blog_version' => array('lang' => 'VERSION', 'type' => 'custom', 'method' => 'blog_version', 'explain' => false),
  73. 'legend1' => 'BLOG_SETTINGS',
  74. 'user_blog_enable' => array('lang' => 'ENABLE_USER_BLOG', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true),
  75. 'user_blog_enable_plugins' => array('lang' => 'ENABLE_USER_BLOG_PLUGINS', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true),
  76. 'user_blog_subscription_enabled' => array('lang' => 'ENABLE_SUBSCRIPTIONS', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true),
  77. 'user_blog_enable_zebra' => array('lang' => 'BLOG_ENABLE_ZEBRA', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true),
  78. 'user_blog_seo' => array('lang' => 'BLOG_ENABLE_SEO', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true),
  79. 'user_blog_search' => array('lang' => 'BLOG_ENABLE_SEARCH', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true),
  80. 'user_blog_user_permissions' => array('lang' => 'BLOG_ENABLE_USER_PERMISSIONS', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true),
  81. 'user_blog_enable_ratings' => array('lang' => 'BLOG_ENABLE_RATINGS', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true),
  82. 'user_blog_enable_attachments' => array('lang' => 'BLOG_ENABLE_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true),
  83. 'user_blog_enable_feeds' => array('lang' => 'BLOG_ENABLE_FEEDS', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => false),
  84. 'legend2' => 'BLOG_POST_VIEW_SETTINGS',
  85. 'user_blog_guest_captcha' => array('lang' => 'BLOG_GUEST_CAPTCHA', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  86. 'user_blog_custom_profile_enable' => array('lang' => 'ENABLE_BLOG_CUSTOM_PROFILES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  87. 'user_blog_links_output_block' => array('lang' => 'OUTPUT_CPLINKS_BLOCK', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
  88. 'user_blog_always_show_blog_url' => array('lang' => 'BLOG_ALWAYS_SHOW_URL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
  89. 'user_blog_text_limit' => array('lang' => 'DEFAULT_TEXT_LIMIT', 'validate' => 'int', 'type' => 'text:5:5', 'explain' => true),
  90. 'user_blog_user_text_limit' => array('lang' => 'USER_TEXT_LIMIT', 'validate' => 'int', 'type' => 'text:5:5', 'explain' => true),
  91. 'user_blog_inform' => array('lang' => 'BLOG_INFORM', 'validate' => 'string', 'type' => 'text:25:100', 'explain' => true),
  92. 'user_blog_message_from' => array('lang' => 'BLOG_MESSAGE_FROM', 'validate' => 'string', 'type' => 'text:5:5', 'explain' => true),
  93. 'user_blog_min_rating' => array('lang' => 'BLOG_MIN_RATING', 'validate' => 'int', 'type' => 'text:5:5', 'explain' => true),
  94. 'user_blog_max_rating' => array('lang' => 'BLOG_MAX_RATING', 'validate' => 'int', 'type' => 'text:5:5', 'explain' => true),
  95. 'user_blog_quick_reply' => array('lang' => 'BLOG_QUICK_REPLY', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
  96. 'legend3' => 'BLOG_ATTACHMENT_SETTINGS',
  97. 'user_blog_max_attachments' => array('lang' => 'BLOG_MAX_ATTACHMENTS', 'validate' => 'int', 'type' => 'text:5:5', 'explain' => true),
  98. );
  99. blog_plugins::plugin_do_ref('acp_main_settings', $settings);
  100. $this->new_config = $config;
  101. $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config;
  102. $error = array();
  103. // We validate the complete config if whished
  104. validate_config_vars($settings, $cfg_array, $error);
  105. // Do not write values if there is an error
  106. if (sizeof($error))
  107. {
  108. $submit = false;
  109. }
  110. $template->assign_vars(array(
  111. 'L_TITLE' => $user->lang['BLOG_SETTINGS'],
  112. 'L_TITLE_EXPLAIN' => $user->lang['BLOG_SETTINGS_EXPLAIN'],
  113. 'S_ERROR' => (sizeof($error)) ? true : false,
  114. 'ERROR_MSG' => implode('<br />', $error),
  115. 'U_ACTION' => $this->u_action,
  116. ));
  117. foreach ($settings as $config_key => $vars)
  118. {
  119. if ($submit)
  120. {
  121. if (!isset($cfg_array[$config_key]) || strpos($config_key, 'legend') !== false)
  122. {
  123. continue;
  124. }
  125. $this->new_config[$config_key] = $config_value = $cfg_array[$config_key];
  126. set_config($config_key, $config_value);
  127. }
  128. else
  129. {
  130. if ((!is_array($vars) || !isset($this->new_config[$config_key])) && strpos($config_key, 'legend') === false)
  131. {
  132. continue;
  133. }
  134. if (strpos($config_key, 'legend') !== false)
  135. {
  136. $template->assign_block_vars('options', array(
  137. 'S_LEGEND' => true,
  138. 'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
  139. );
  140. continue;
  141. }
  142. $type = explode(':', $vars['type']);
  143. $l_explain = '';
  144. if ($vars['explain'] && isset($vars['lang_explain']))
  145. {
  146. $l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
  147. }
  148. else if ($vars['explain'])
  149. {
  150. $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
  151. }
  152. $template->assign_block_vars('options', array(
  153. 'KEY' => $config_key,
  154. 'TITLE' => (isset($user->lang[$vars['lang']])) ? $user->lang[$vars['lang']] : $vars['lang'],
  155. 'S_EXPLAIN' => $vars['explain'],
  156. 'TITLE_EXPLAIN' => $l_explain,
  157. 'CONTENT' => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars),
  158. )
  159. );
  160. }
  161. }
  162. if ($submit)
  163. {
  164. add_log('admin', 'LOG_BLOG_CONFIG');
  165. trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
  166. }
  167. }
  168. /**
  169. * Select default dateformat
  170. */
  171. function blog_version($value, $key)
  172. {
  173. global $user, $config, $phpbb_root_path, $phpEx;
  174. $version = $user->lang['DATABASE_VERSION'] . ': ' . $value . '<br />';
  175. $version .= $user->lang['FILE_VERSION'] . ': ' . USER_BLOG_MOD_VERSION . '<br /><br />';
  176. if (version_compare(USER_BLOG_MOD_VERSION, $value, '>'))
  177. {
  178. $version .= '<br /><br />' . sprintf($user->lang['CLICK_UPDATE'], '<a href="' . append_sid("{$phpbb_root_path}blog/database.$phpEx") . '">', '</a>') . '<br />';
  179. }
  180. return $version;
  181. }
  182. // Code taken from acp_category
  183. function categories($id, $mode)
  184. {
  185. global $db, $user, $auth, $template, $cache;
  186. global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
  187. $this->tpl_name = 'acp_blog_categories';
  188. $this->page_title = 'ACP_BLOG_CATEGORIES';
  189. $form_key = 'acp_blog';
  190. $action = request_var('action', '');
  191. $update = (isset($_POST['update'])) ? true : false;
  192. $category_id = request_var('c', 0);
  193. $this->parent_id = request_var('parent_id', 0);
  194. $category_data = $errors = array();
  195. // Clear the categories cache
  196. $cache->destroy('_blog_categories');
  197. // Major routines
  198. if ($update)
  199. {
  200. switch ($action)
  201. {
  202. case 'delete':
  203. $action_subcategories = request_var('action_subcategories', '');
  204. $subcategories_to_id = request_var('subcategories_to_id', 0);
  205. $action_blogs = request_var('action_blogs', '');
  206. $blogs_to_id = request_var('blogs_to_id', 0);
  207. $row = $this->get_category_info($category_id);
  208. $errors = $this->delete_category($category_id, $action_blogs, $action_subcategories, $blogs_to_id, $subcategories_to_id);
  209. blog_plugins::plugin_do_ref('acp_category_delete', $errors);
  210. if (sizeof($errors))
  211. {
  212. break;
  213. }
  214. add_log('admin', 'LOG_BLOG_CATEGORY_DELETE', $row['category_name']);
  215. trigger_error($user->lang['CATEGORY_DELETED'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  216. break;
  217. case 'edit':
  218. $category_data = array(
  219. 'category_id' => $category_id
  220. );
  221. // No break here
  222. case 'add':
  223. $category_data += array(
  224. 'parent_id' => request_var('category_parent_id', $this->parent_id),
  225. 'category_name' => utf8_normalize_nfc(request_var('category_name', '', true)),
  226. 'category_description' => utf8_normalize_nfc(request_var('category_description', '', true)),
  227. 'category_description_bitfield' => '',
  228. 'category_description_uid' => '',
  229. 'category_description_options' => 7,
  230. 'rules' => utf8_normalize_nfc(request_var('rules', '', true)),
  231. 'rules_bitfield' => '',
  232. 'rules_uid' => '',
  233. 'rules_options' => 7,
  234. );
  235. // Get data for category rules if specified...
  236. if ($category_data['rules'])
  237. {
  238. generate_text_for_storage($category_data['rules'], $category_data['rules_uid'], $category_data['rules_bitfield'], $category_data['rules_options'], request_var('rules_parse_bbcode', false), request_var('rules_parse_urls', false), request_var('rules_parse_smilies', false));
  239. }
  240. // Get data for category description if specified
  241. if ($category_data['category_description'])
  242. {
  243. generate_text_for_storage($category_data['category_description'], $category_data['category_description_uid'], $category_data['category_description_bitfield'], $category_data['category_description_options'], request_var('desc_parse_bbcode', false), request_var('desc_parse_urls', false), request_var('desc_parse_smilies', false));
  244. }
  245. $temp = compact('action', 'category_data');
  246. blog_plugins::plugin_do_ref('acp_category_add_edit', $temp);
  247. extract($temp);
  248. $errors = $this->update_category_data($category_data);
  249. if (!sizeof($errors))
  250. {
  251. $message = ($action == 'add') ? $user->lang['CATEGORY_CREATED'] : $user->lang['CATEGORY_UPDATED'];
  252. trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  253. }
  254. break;
  255. }
  256. }
  257. switch ($action)
  258. {
  259. case 'move_up':
  260. case 'move_down':
  261. if (!$category_id)
  262. {
  263. trigger_error($user->lang['NO_CATEGORY'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  264. }
  265. $sql = 'SELECT *
  266. FROM ' . BLOGS_CATEGORIES_TABLE . "
  267. WHERE category_id = $category_id";
  268. $result = $db->sql_query($sql);
  269. $row = $db->sql_fetchrow($result);
  270. $db->sql_freeresult($result);
  271. if (!$row)
  272. {
  273. trigger_error($user->lang['NO_CATEGORY'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  274. }
  275. $move_category_name = $this->move_category_by($row, $action, 1);
  276. break;
  277. case 'add':
  278. case 'edit':
  279. // Show form to create/modify a category
  280. if ($action == 'edit')
  281. {
  282. $this->page_title = 'EDIT_CATEGORY';
  283. $row = $this->get_category_info($category_id);
  284. if (!$update)
  285. {
  286. $category_data = $row;
  287. }
  288. else
  289. {
  290. $category_data['left_id'] = $row['left_id'];
  291. $category_data['right_id'] = $row['right_id'];
  292. }
  293. // Make sure no direct child categories are able to be selected as parents.
  294. $exclude_categories = array();
  295. foreach (get_category_branch($category_id, 'children') as $row)
  296. {
  297. $exclude_categories[] = $row['category_id'];
  298. }
  299. $parents_list = make_category_select($category_data['parent_id'], $exclude_categories);
  300. }
  301. else
  302. {
  303. $this->page_title = 'CREATE_CATEGORY';
  304. $category_id = $this->parent_id;
  305. $parents_list = make_category_select($this->parent_id);
  306. // Fill category data with default values
  307. if (!$update)
  308. {
  309. $category_data = array(
  310. 'parent_id' => $this->parent_id,
  311. 'category_name' => utf8_normalize_nfc(request_var('category_name', '', true)),
  312. 'category_description' => '',
  313. 'rules' => '',
  314. );
  315. }
  316. }
  317. $rules_data = array(
  318. 'text' => $category_data['rules'],
  319. 'allow_bbcode' => true,
  320. 'allow_smilies' => true,
  321. 'allow_urls' => true
  322. );
  323. $category_description_data = array(
  324. 'text' => $category_data['category_description'],
  325. 'allow_bbcode' => true,
  326. 'allow_smilies' => true,
  327. 'allow_urls' => true
  328. );
  329. $rules_preview = '';
  330. // Parse rules if specified
  331. if ($category_data['rules'])
  332. {
  333. if (!isset($category_data['rules_uid']))
  334. {
  335. // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
  336. $category_data['rules_uid'] = '';
  337. $category_data['rules_bitfield'] = '';
  338. $category_data['rules_options'] = 0;
  339. generate_text_for_storage($category_data['rules'], $category_data['rules_uid'], $category_data['rules_bitfield'], $category_data['rules_options'], request_var('rules_allow_bbcode', false), request_var('rules_allow_urls', false), request_var('rules_allow_smilies', false));
  340. }
  341. // Generate preview content
  342. $rules_preview = generate_text_for_display($category_data['rules'], $category_data['rules_uid'], $category_data['rules_bitfield'], $category_data['rules_options']);
  343. // decode...
  344. $rules_data = generate_text_for_edit($category_data['rules'], $category_data['rules_uid'], $category_data['rules_options']);
  345. }
  346. // Parse desciption if specified
  347. if ($category_data['category_description'])
  348. {
  349. if (!isset($category_data['category_description_uid']))
  350. {
  351. // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
  352. $category_data['category_description_uid'] = '';
  353. $category_data['category_description_bitfield'] = '';
  354. $category_data['category_description_options'] = 0;
  355. generate_text_for_storage($category_data['category_description'], $category_data['category_description_uid'], $category_data['category_description_bitfield'], $category_data['category_description_options'], request_var('desc_allow_bbcode', false), request_var('desc_allow_urls', false), request_var('desc_allow_smilies', false));
  356. }
  357. // decode...
  358. $category_description_data = generate_text_for_edit($category_data['category_description'], $category_data['category_description_uid'], $category_data['category_description_options']);
  359. }
  360. $sql = 'SELECT category_id
  361. FROM ' . BLOGS_CATEGORIES_TABLE . "
  362. WHERE category_id <> $category_id";
  363. $result = $db->sql_query($sql);
  364. if ($db->sql_fetchrow($result))
  365. {
  366. $template->assign_vars(array(
  367. 'S_MOVE_CATEGORY_OPTIONS' => make_category_select($category_data['parent_id'], $category_id))
  368. );
  369. }
  370. $db->sql_freeresult($result);
  371. $template->assign_vars(array(
  372. 'S_ADD_ACTION' => ($mode == 'add') ? true : false,
  373. 'S_EDIT_CATEGORY' => true,
  374. 'S_ERROR' => (sizeof($errors)) ? true : false,
  375. 'S_PARENT_ID' => $this->parent_id,
  376. 'S_CATEGORY_PARENT_ID' => $category_data['parent_id'],
  377. 'S_PARENT_OPTIONS' => $parents_list,
  378. 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  379. 'U_EDIT_ACTION' => $this->u_action . "&amp;parent_id={$this->parent_id}&amp;action=$action&amp;c=$category_id",
  380. 'L_TITLE' => $user->lang[$this->page_title],
  381. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
  382. 'CATEGORY_NAME' => $category_data['category_name'],
  383. 'RULES' => $category_data['rules'],
  384. 'RULES_PREVIEW' => $rules_preview,
  385. 'RULES_PLAIN' => $rules_data['text'],
  386. 'S_BBCODE_CHECKED' => ($rules_data['allow_bbcode']) ? true : false,
  387. 'S_SMILIES_CHECKED' => ($rules_data['allow_smilies']) ? true : false,
  388. 'S_URLS_CHECKED' => ($rules_data['allow_urls']) ? true : false,
  389. 'CATEGORY_DESCRIPTION' => $category_description_data['text'],
  390. 'S_DESC_BBCODE_CHECKED' => ($category_description_data['allow_bbcode']) ? true : false,
  391. 'S_DESC_SMILIES_CHECKED' => ($category_description_data['allow_smilies']) ? true : false,
  392. 'S_DESC_URLS_CHECKED' => ($category_description_data['allow_urls']) ? true : false,
  393. 'S_CATEGORY_OPTIONS' => make_category_select(($action == 'add') ? $category_data['parent_id'] : false, ($action == 'edit') ? $category_data['category_id'] : false),
  394. ));
  395. blog_plugins::plugin_do('acp_category_add_edit_initial');
  396. return;
  397. break;
  398. case 'delete':
  399. if (!$category_id)
  400. {
  401. trigger_error($user->lang['NO_CATEGORY'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  402. }
  403. $category_data = $this->get_category_info($category_id);
  404. $subcategories_id = array();
  405. $subcategories = get_category_branch($category_id, 'children');
  406. foreach ($subcategories as $row)
  407. {
  408. $subcategories_id[] = $row['category_id'];
  409. }
  410. $categories_list = make_category_select($category_data['parent_id'], $subcategories_id);
  411. $sql = 'SELECT category_id
  412. FROM ' . BLOGS_CATEGORIES_TABLE . "
  413. WHERE category_id <> $category_id";
  414. $result = $db->sql_query($sql);
  415. if ($db->sql_fetchrow($result))
  416. {
  417. $template->assign_vars(array(
  418. 'S_MOVE_CATEGORY_OPTIONS' => make_category_select($category_data['parent_id'], $subcategories_id))
  419. );
  420. }
  421. $db->sql_freeresult($result);
  422. $parent_id = ($this->parent_id == $category_id) ? 0 : $this->parent_id;
  423. $template->assign_vars(array(
  424. 'S_DELETE_CATEGORY' => true,
  425. 'U_ACTION' => $this->u_action . "&amp;parent_id={$parent_id}&amp;action=delete&amp;c=$category_id",
  426. 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  427. 'CATEGORY_NAME' => $category_data['category_name'],
  428. 'S_HAS_SUBCATEGORYS' => ($category_data['right_id'] - $category_data['left_id'] > 1) ? true : false,
  429. 'S_CATEGORIES_LIST' => $categories_list,
  430. 'S_ERROR' => (sizeof($errors)) ? true : false,
  431. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '')
  432. );
  433. return;
  434. break;
  435. }
  436. // Default management page
  437. if (!$this->parent_id)
  438. {
  439. $navigation = $user->lang['CATEGORY_INDEX'];
  440. }
  441. else
  442. {
  443. $navigation = '<a href="' . $this->u_action . '">' . $user->lang['CATEGORY_INDEX'] . '</a>';
  444. $category_nav = get_category_branch($this->parent_id, 'parents', 'descending');
  445. foreach ($category_nav as $row)
  446. {
  447. if ($row['category_id'] == $this->parent_id)
  448. {
  449. $navigation .= ' -&gt; ' . $row['category_name'];
  450. }
  451. else
  452. {
  453. $navigation .= ' -&gt; <a href="' . $this->u_action . '&amp;parent_id=' . $row['category_id'] . '">' . $row['category_name'] . '</a>';
  454. }
  455. }
  456. }
  457. // Jumpbox
  458. $category_box = make_category_select($this->parent_id);
  459. $sql = 'SELECT *
  460. FROM ' . BLOGS_CATEGORIES_TABLE . "
  461. WHERE parent_id = $this->parent_id
  462. ORDER BY left_id";
  463. $result = $db->sql_query($sql);
  464. if ($row = $db->sql_fetchrow($result))
  465. {
  466. do
  467. {
  468. $url = $this->u_action . "&amp;parent_id=$this->parent_id&amp;c={$row['category_id']}";
  469. $category_title = $row['category_name'];
  470. $template->assign_block_vars('categories', array(
  471. 'CATEGORY_NAME' => $row['category_name'],
  472. 'CATEGORY_DESCRIPTION' => generate_text_for_display($row['category_description'], $row['category_description_uid'], $row['category_description_bitfield'], $row['category_description_options']),
  473. 'U_CATEGORY' => $this->u_action . '&amp;parent_id=' . $row['category_id'],
  474. 'U_MOVE_UP' => $url . '&amp;action=move_up',
  475. 'U_MOVE_DOWN' => $url . '&amp;action=move_down',
  476. 'U_EDIT' => $url . '&amp;action=edit',
  477. 'U_DELETE' => $url . '&amp;action=delete',
  478. ));
  479. }
  480. while ($row = $db->sql_fetchrow($result));
  481. }
  482. else if ($this->parent_id)
  483. {
  484. $row = $this->get_category_info($this->parent_id);
  485. $url = $this->u_action . '&amp;parent_id=' . $this->parent_id . '&amp;c=' . $row['category_id'];
  486. $template->assign_vars(array(
  487. 'S_NO_CATEGORIES' => true,
  488. 'U_EDIT' => $url . '&amp;action=edit',
  489. 'U_DELETE' => $url . '&amp;action=delete',
  490. ));
  491. }
  492. $db->sql_freeresult($result);
  493. $template->assign_vars(array(
  494. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
  495. 'NAVIGATION' => $navigation,
  496. 'CATEGORY_BOX' => $category_box,
  497. 'U_SEL_ACTION' => $this->u_action,
  498. 'U_ACTION' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  499. ));
  500. }
  501. function plugins($id, $mode)
  502. {
  503. global $config, $db, $user, $auth, $template;
  504. global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
  505. if (blog_plugins::load_all_plugins() === false)
  506. {
  507. trigger_error('PLUGINS_DISABLED');
  508. }
  509. $submit = (isset($_POST['submit'])) ? true : false;
  510. $action = request_var('action', '');
  511. $action_to = request_var('name', '');
  512. $this->tpl_name = 'acp_blog_plugins';
  513. $this->page_title = 'ACP_BLOG_PLUGINS';
  514. $template->assign_vars(array(
  515. 'U_ACTION' => $this->u_action,
  516. ));
  517. switch ($action)
  518. {
  519. case 'activate' :
  520. blog_plugins::plugin_enable($action_to);
  521. break;
  522. case 'deactivate' :
  523. blog_plugins::plugin_disable($action_to);
  524. break;
  525. case 'install' :
  526. blog_plugins::plugin_install($action_to);
  527. break;
  528. case 'uninstall' :
  529. if (confirm_box(true))
  530. {
  531. blog_plugins::plugin_uninstall($action_to);
  532. }
  533. else
  534. {
  535. confirm_box(false, 'PLUGIN_UNINSTALL');
  536. }
  537. break;
  538. case 'update' :
  539. blog_plugins::plugin_update($action_to);
  540. break;
  541. case 'move_up' :
  542. case 'move_down' :
  543. blog_plugins::plugin_move($action_to, $action);
  544. // We need to do a redirect here because the plugins list is not shown correctly after one is moved...and I see no easy way to resync the list
  545. redirect($this->u_action);
  546. break;
  547. }
  548. $i = 0;
  549. $installed_plugins = array();
  550. foreach (blog_plugins::$available_plugins as $name => $data)
  551. {
  552. $i++;
  553. $installed = (array_key_exists($name, blog_plugins::$plugins)) ? true : false;
  554. $active = ($installed && blog_plugins::$plugins[$name]['plugin_enabled']) ? true : false;
  555. $s_actions = array();
  556. if ($installed)
  557. {
  558. if ($active)
  559. {
  560. $s_actions[] = '<a href="' . $this->u_action . "&amp;action=deactivate&amp;name=" . $name . '">' . $user->lang['PLUGIN_DEACTIVATE'] . '</a>';
  561. $s_actions[] = '<a href="' . $this->u_action . "&amp;action=uninstall&amp;name=" . $name . '">' . $user->lang['PLUGIN_UNINSTALL'] . '</a>';
  562. }
  563. else
  564. {
  565. $s_actions[] = '<a href="' . $this->u_action . "&amp;action=activate&amp;name=" . $name . '">' . $user->lang['PLUGIN_ACTIVATE'] . '</a>';
  566. $s_actions[] = '<a href="' . $this->u_action . "&amp;action=uninstall&amp;name=" . $name . '">' . $user->lang['PLUGIN_UNINSTALL'] . '</a>';
  567. }
  568. if ($i > 1)
  569. {
  570. $s_actions[] = '<a href="' . $this->u_action . "&amp;action=move_up&amp;name=" . $name . '">' . $user->lang['MOVE_UP'] . '</a>';
  571. }
  572. if ($i != sizeof(blog_plugins::$plugins))
  573. {
  574. $s_actions[] = '<a href="' . $this->u_action . "&amp;action=move_down&amp;name=" . $name . '">' . $user->lang['MOVE_DOWN'] . '</a>';
  575. }
  576. if ($data['plugin_version'] != blog_plugins::$plugins[$name]['plugin_version'])
  577. {
  578. $version = array('files' => explode('.', $data['plugin_version']), 'db' => explode('.', blog_plugins::$plugins[$name]['plugin_version']));
  579. $i = 0;
  580. $newer_files = false;
  581. foreach ($version['files'] as $v)
  582. {
  583. if ($v > $version['db'][$i])
  584. {
  585. $newer_files = true;
  586. break;
  587. }
  588. else if ($v < $version['db'][$i])
  589. {
  590. break;
  591. }
  592. $i++;
  593. }
  594. if ($newer_files)
  595. {
  596. $s_actions[] = '<a href="' . $this->u_action . "&amp;action=update&amp;name=" . $name . '">' . $user->lang['PLUGIN_UPDATE'] . '</a>';
  597. }
  598. }
  599. }
  600. else
  601. {
  602. $s_actions[] = '<a href="' . $this->u_action . "&amp;action=install&amp;name=" . $name . '">' . $user->lang['PLUGIN_INSTALL'] . '</a>';
  603. }
  604. if ($installed)
  605. {
  606. $installed_plugins[$name] = array(
  607. 'NAME' => (isset($data['plugin_title'])) ? $data['plugin_title'] : $name,
  608. 'DESCRIPTION' => (isset($data['plugin_description'])) ? $data['plugin_description'] : '',
  609. 'S_ACTIONS' => implode(' | ', $s_actions),
  610. 'COPYRIGHT' => (isset($data['plugin_copyright'])) ? $data['plugin_copyright'] : '',
  611. 'DATABASE_VERSION' => ($installed) ? blog_plugins::$plugins[$name]['plugin_version'] : false,
  612. 'FILES_VERSION' => (isset($data['plugin_version'])) ? $data['plugin_version'] : '',
  613. );
  614. }
  615. else
  616. {
  617. $template->assign_block_vars('uninstalled', array(
  618. 'NAME' => (isset($data['plugin_title'])) ? $data['plugin_title'] : $name,
  619. 'DESCRIPTION' => (isset($data['plugin_description'])) ? $data['plugin_description'] : '',
  620. 'S_ACTIONS' => implode(' | ', $s_actions),
  621. 'COPYRIGHT' => (isset($data['plugin_copyright'])) ? $data['plugin_copyright'] : '',
  622. 'DATABASE_VERSION' => ($installed) ? blog_plugins::$plugins[$name]['plugin_version'] : false,
  623. 'FILES_VERSION' => (isset($data['plugin_version'])) ? $data['plugin_version'] : '',
  624. ));
  625. }
  626. }
  627. foreach (blog_plugins::$plugins as $name => $row)
  628. {
  629. $template->assign_block_vars('installed', $installed_plugins[$name]);
  630. }
  631. }
  632. function search($id, $mode)
  633. {
  634. global $user, $phpbb_root_path, $phpEx;
  635. $user->add_lang('acp/search');
  636. // For some this may be of help...
  637. @ini_set('memory_limit', '128M');
  638. $this->search_settings($id, $mode);
  639. $this->search_index($id, $mode);
  640. }
  641. function search_settings($id, $mode)
  642. {
  643. global $db, $user, $auth, $template;
  644. global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
  645. $submit = (isset($_POST['submit'])) ? true : false;
  646. $search_types = $this->get_search_types();
  647. $settings = array(
  648. 'user_blog_search' => 'bool',
  649. );
  650. $search = null;
  651. $error = false;
  652. $search_options = '';
  653. foreach ($search_types as $type)
  654. {
  655. if ($this->init_search($type, $search, $error))
  656. {
  657. continue;
  658. }
  659. $name = ucfirst(strtolower(str_replace('_', ' ', $type)));
  660. $selected = ($config['search_type'] == $type) ? ' selected="selected"' : '';
  661. $search_options .= '<option value="' . $type . '"' . $selected . '>' . $name . '</option>';
  662. if (method_exists($search, 'acp'))
  663. {
  664. $vars = $search->acp();
  665. if (!$submit)
  666. {
  667. $template->assign_block_vars('backend', array(
  668. 'NAME' => $name,
  669. 'SETTINGS' => $vars['tpl'])
  670. );
  671. }
  672. else if (is_array($vars['config']))
  673. {
  674. $settings = array_merge($settings, $vars['config']);
  675. }
  676. }
  677. }
  678. unset($search);
  679. unset($error);
  680. $cfg_array = (isset($_REQUEST['config'])) ? request_var('config', array('' => ''), true) : array();
  681. $updated = request_var('updated', false);
  682. foreach ($settings as $config_name => $var_type)
  683. {
  684. if (!isset($cfg_array[$config_name]))
  685. {
  686. continue;
  687. }
  688. // e.g. integer:4:12 (min 4, max 12)
  689. $var_type = explode(':', $var_type);
  690. $config_value = $cfg_array[$config_name];
  691. settype($config_value, $var_type[0]);
  692. if (isset($var_type[1]))
  693. {
  694. $config_value = max($var_type[1], $config_value);
  695. }
  696. if (isset($var_type[2]))
  697. {
  698. $config_value = min($var_type[2], $config_value);
  699. }
  700. // only change config if anything was actually changed
  701. if ($submit && ($config[$config_name] != $config_value))
  702. {
  703. set_config($config_name, $config_value);
  704. $updated = true;
  705. }
  706. }
  707. if ($submit)
  708. {
  709. $extra_message = '';
  710. if (isset($cfg_array['search_type']) && in_array($cfg_array['search_type'], $search_types, true) && ($cfg_array['search_type'] != $config['search_type']))
  711. {
  712. $search = null;
  713. $error = false;
  714. if (!$this->init_search($cfg_array['search_type'], $search, $error))
  715. {
  716. if (confirm_box(true))
  717. {
  718. if (!method_exists($search, 'init') || !($error = $search->init()))
  719. {
  720. set_config('user_blog_search_type', $cfg_array['search_type']);
  721. if (!$updated)
  722. {
  723. add_log('admin', 'LOG_BLOG_CONFIG_SEARCH');
  724. }
  725. $extra_message = '<br />' . $user->lang['SWITCHED_SEARCH_BACKEND'] . '<br /><a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=search&amp;mode=index') . '">&raquo; ' . $user->lang['GO_TO_SEARCH_INDEX'] . '</a>';
  726. }
  727. else
  728. {
  729. trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
  730. }
  731. }
  732. else
  733. {
  734. confirm_box(false, $user->lang['CONFIRM_SEARCH_BACKEND'], build_hidden_fields(array(
  735. 'i' => $id,
  736. 'mode' => $mode,
  737. 'submit' => true,
  738. 'updated' => $updated,
  739. 'config' => array('user_blog_search_type' => $cfg_array['search_type']),
  740. )));
  741. }
  742. }
  743. else
  744. {
  745. trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
  746. }
  747. }
  748. add_log('admin', 'LOG_BLOG_CONFIG_SEARCH');
  749. trigger_error($user->lang['CONFIG_UPDATED'] . $extra_message . adm_back_link($this->u_action));
  750. }
  751. unset($cfg_array);
  752. $this->tpl_name = 'acp_blog_search';
  753. $this->page_title = 'ACP_SEARCH_SETTINGS';
  754. $template->assign_vars(array(
  755. 'S_SEARCH_TYPES' => $search_options,
  756. 'S_YES_SEARCH' => (bool) $config['user_blog_search'],
  757. 'S_SETTINGS' => true,
  758. 'U_ACTION' => $this->u_action)
  759. );
  760. }
  761. function search_index($id, $mode)
  762. {
  763. global $db, $user, $auth, $template;
  764. global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
  765. if (isset($_REQUEST['action']) && is_array($_REQUEST['action']))
  766. {
  767. $action = request_var('action', array('' => false));
  768. $action = key($action);
  769. }
  770. else
  771. {
  772. $action = request_var('action', '');
  773. }
  774. $this->state = explode(',', $config['search_indexing_state']);
  775. if (isset($_POST['cancel']))
  776. {
  777. $action = '';
  778. }
  779. if ($action)
  780. {
  781. $this->state[0] = request_var('search_type', '');
  782. $this->search = null;
  783. $error = false;
  784. if ($this->init_search($this->state[0], $this->search, $error))
  785. {
  786. trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
  787. }
  788. $name = ucfirst(strtolower(str_replace('_', ' ', $this->state[0])));
  789. switch ($action)
  790. {
  791. case 'delete':
  792. $this->search->delete_index();
  793. add_log('admin', 'LOG_BLOG_SEARCH_INDEX_REMOVED');
  794. trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action));
  795. break;
  796. case 'create':
  797. $section = request_var('section', 0);
  798. $part = request_var('part', 0);
  799. $limit = 250;
  800. $part_cnt = 0;
  801. if ($section == 0)
  802. {
  803. $this->search->delete_index();
  804. $section++;
  805. }
  806. else if ($section == 1)
  807. {
  808. $sql = 'SELECT * FROM ' . BLOGS_TABLE . '
  809. WHERE blog_deleted = 0
  810. AND blog_approved = 1
  811. ORDER BY blog_id DESC';
  812. $result = $db->sql_query_limit($sql, $limit, ($part * $limit));
  813. while ($row = $db->sql_fetchrow($result))
  814. {
  815. $this->search->index('add', $row['blog_id'], 0, $row['blog_text'], $row['blog_subject'], $row['user_id']);
  816. }
  817. $sql = 'SELECT count(blog_id) AS cnt FROM ' . BLOGS_TABLE . '
  818. WHERE blog_deleted = 0
  819. AND blog_approved = 1';
  820. $result = $db->sql_query($sql);
  821. $cnt = $db->sql_fetchrow($result);
  822. if ($cnt['cnt'] >= (($part + 1) * $limit))
  823. {
  824. $part++;
  825. $part_cnt = ceil($cnt['cnt'] / $limit);
  826. }
  827. else
  828. {
  829. $part = 0;
  830. $section++;
  831. }
  832. }
  833. else
  834. {
  835. $sql = 'SELECT * FROM ' . BLOGS_REPLY_TABLE . '
  836. WHERE reply_deleted = 0
  837. AND reply_approved = 1
  838. ORDER BY reply_id DESC';
  839. $result = $db->sql_query_limit($sql, $limit, ($part * $limit));
  840. while ($row = $db->sql_fetchrow($result))
  841. {
  842. $this->search->index('add', $row['blog_id'], $row['reply_id'], $row['reply_text'], $row['reply_subject'], $row['user_id']);
  843. }
  844. $sql = 'SELECT count(reply_id) AS cnt FROM ' . BLOGS_REPLY_TABLE . '
  845. WHERE reply_deleted = 0
  846. AND reply_approved = 1';
  847. $result = $db->sql_query($sql);
  848. $cnt = $db->sql_fetchrow($result);
  849. if ($cnt['cnt'] >= (($part + 1) * $limit))
  850. {
  851. $part++;
  852. $part_cnt = ceil($cnt['cnt'] / $limit);
  853. }
  854. else
  855. {
  856. $part = 0;
  857. $section++;
  858. }
  859. }
  860. if ($section > 2)
  861. {
  862. add_log('admin', 'LOG_BLOG_SEARCH_INDEX_CREATED');
  863. trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action));
  864. }
  865. else
  866. {
  867. $redirect_url = $this->u_action . "&amp;search_type={$this->state[0]}&amp;action={$action}&amp;section={$section}&amp;part={$part}";
  868. meta_refresh(1, $redirect_url);
  869. trigger_error(sprintf($user->lang['SEARCH_BREAK_CONTINUE_NOTICE'], $section, 3, $part, $part_cnt) . '<br /><br /><a href="' . $redirect_url . '">' . $user->lang['CONTINUE'] . '</a>');
  870. }
  871. break;
  872. }
  873. }
  874. $search_types = $this->get_search_types();
  875. $search = null;
  876. $error = false;
  877. $search_options = '';
  878. foreach ($search_types as $type)
  879. {
  880. if ($this->init_search($type, $search, $error) || !method_exists($search, 'index_created'))
  881. {
  882. continue;
  883. }
  884. $name = ucfirst(strtolower(str_replace('_', ' ', $type)));
  885. $data = array();
  886. if (method_exists($search, 'index_stats'))
  887. {
  888. $data = $search->index_stats();
  889. }
  890. $statistics = array();
  891. foreach ($data as $statistic => $value)
  892. {
  893. $n = sizeof($statistics);
  894. if ($n && sizeof($statistics[$n - 1]) < 3)
  895. {
  896. $statistics[$n - 1] += array('statistic_2' => $statistic, 'value_2' => $value);
  897. }
  898. else
  899. {
  900. $statistics[] = array('statistic_1' => $statistic, 'value_1' => $value);
  901. }
  902. }
  903. $template->assign_block_vars('backend', array(
  904. 'L_NAME' => $name,
  905. 'NAME' => $type,
  906. 'S_ACTIVE' => ($type == $config['search_type']) ? true : false,
  907. 'S_HIDDEN_FIELDS' => build_hidden_fields(array('search_type' => $type)),
  908. 'S_INDEXED' => (bool) $search->index_created(),
  909. 'S_STATS' => (bool) sizeof($statistics))
  910. );
  911. foreach ($statistics as $statistic)
  912. {
  913. $template->assign_block_vars('backend.data', array(
  914. 'STATISTIC_1' => $statistic['statistic_1'],
  915. 'VALUE_1' => $statistic['value_1'],
  916. 'STATISTIC_2' => (isset($statistic['statistic_2'])) ? $statistic['statistic_2'] : '',
  917. 'VALUE_2' => (isset($statistic['value_2'])) ? $statistic['value_2'] : '')
  918. );
  919. }
  920. }
  921. unset($search);
  922. unset($error);
  923. unset($statistics);
  924. unset($data);
  925. $this->tpl_name = 'acp_blog_search';
  926. $this->page_title = 'ACP_SEARCH_INDEX';
  927. $template->assign_vars(array(
  928. 'S_INDEX' => true,
  929. 'U_ACTION' => $this->u_action,
  930. 'U_PROGRESS_BAR' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=$mode&amp;action=progress_bar"),
  931. 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=$mode&amp;action=progress_bar")),
  932. ));
  933. if (isset($this->state[1]))
  934. {
  935. $template->assign_vars(array(
  936. 'S_CONTINUE_INDEXING' => $this->state[1],
  937. 'U_CONTINUE_INDEXING' => $this->u_action . '&amp;action=' . $this->state[1],
  938. 'L_CONTINUE' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_DELETING_INDEX'],
  939. 'L_CONTINUE_EXPLAIN' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING_EXPLAIN'] : $user->lang['CONTINUE_DELETING_INDEX_EXPLAIN'])
  940. );
  941. }
  942. }
  943. function get_search_types()
  944. {
  945. global $phpbb_root_path, $phpEx;
  946. $search_types = array();
  947. $dp = @opendir($phpbb_root_path . 'blog/search');
  948. if ($dp)
  949. {
  950. while (($file = readdir($dp)) !== false)
  951. {
  952. if ((preg_match('#\.' . $phpEx . '$#', $file)) && ($file != "search.$phpEx"))
  953. {
  954. $search_types[] = preg_replace('#^(.*?)\.' . $phpEx . '$#', '\1', $file);
  955. }
  956. }
  957. closedir($dp);
  958. sort($search_types);
  959. }
  960. return $search_types;
  961. }
  962. /**
  963. * Initialises a search backend object
  964. *
  965. * @return false if no error occurred else an error message
  966. */
  967. function init_search($type, &$search, &$error)
  968. {
  969. global $phpbb_root_path, $phpEx, $user;
  970. if (!preg_match('#^\w+$#', $type) || !file_exists("{$phpbb_root_path}blog/search/$type.$phpEx"))
  971. {
  972. $error = $user->lang['NO_SUCH_SEARCH_MODULE'];
  973. return $error;
  974. }
  975. include_once("{$phpbb_root_path}blog/search/$type.$phpEx");
  976. $class = 'blog_' . $type;
  977. if (!class_exists($class))
  978. {
  979. $error = $user->lang['NO_SUCH_SEARCH_MODULE'];
  980. return $error;
  981. }
  982. $error = false;
  983. $search = new $class($error);
  984. return $error;
  985. }
  986. /**
  987. * Get category details
  988. */
  989. function get_category_info($category_id)
  990. {
  991. global $db;
  992. $sql = 'SELECT *
  993. FROM ' . BLOGS_CATEGORIES_TABLE . "
  994. WHERE category_id = $category_id";
  995. $result = $db->sql_query($sql);
  996. $row = $db->sql_fetchrow($result);
  997. $db->sql_freeresult($result);
  998. if (!$row)
  999. {
  1000. trigger_error("Forum #$category_id does not exist", E_USER_ERROR);
  1001. }
  1002. return $row;
  1003. }
  1004. /**
  1005. * Update category data
  1006. */
  1007. function update_category_data(&$category_data)
  1008. {
  1009. global $db, $user;
  1010. $errors = array();
  1011. if (!$category_data['category_name'])
  1012. {
  1013. $errors[] = $user->lang['CATEGORY_NAME_EMPTY'];
  1014. }
  1015. // Unset data that are not database fields
  1016. $category_data_sql = $category_data;
  1017. // What are we going to do tonight Brain? The same thing we do everynight,
  1018. // try to take over the world ... or decide whether to continue update
  1019. // and if so, whether it's a new category/cat/link or an existing one
  1020. if (sizeof($errors))
  1021. {
  1022. return $errors;
  1023. }
  1024. if (!isset($category_data_sql['category_id']))
  1025. {
  1026. // no category_id means we're creating a new category
  1027. if ($category_data_sql['parent_id'])
  1028. {
  1029. $sql = 'SELECT left_id, right_id
  1030. FROM ' . BLOGS_CATEGORIES_TABLE . '
  1031. WHERE category_id = ' . $category_data_sql['parent_id'];
  1032. $result = $db->sql_query($sql);
  1033. $row = $db->sql_fetchrow($result);
  1034. $db->sql_freeresult($result);
  1035. if (!$row)
  1036. {
  1037. trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&amp;' . $this->parent_id), E_USER_WARNING);
  1038. }
  1039. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . '
  1040. SET left_id = left_id + 2, right_id = right_id + 2
  1041. WHERE left_id > ' . $row['right_id'];
  1042. $db->sql_query($sql);
  1043. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . '
  1044. SET right_id = right_id + 2
  1045. WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
  1046. $db->sql_query($sql);
  1047. $category_data_sql['left_id'] = $row['right_id'];
  1048. $category_data_sql['right_id'] = $row['right_id'] + 1;
  1049. }
  1050. else
  1051. {
  1052. $sql = 'SELECT MAX(right_id) AS right_id
  1053. FROM ' . BLOGS_CATEGORIES_TABLE;
  1054. $result = $db->sql_query($sql);
  1055. $row = $db->sql_fetchrow($result);
  1056. $db->sql_freeresult($result);
  1057. $category_data_sql['left_id'] = $row['right_id'] + 1;
  1058. $category_data_sql['right_id'] = $row['right_id'] + 2;
  1059. }
  1060. $sql = 'INSERT INTO ' . BLOGS_CATEGORIES_TABLE . ' ' . $db->sql_build_array('INSERT', $category_data_sql);
  1061. $db->sql_query($sql);
  1062. $category_data['category_id'] = $db->sql_nextid();
  1063. add_log('admin', 'LOG_BLOG_CATEGORY_ADD', $category_data['category_name']);
  1064. }
  1065. else
  1066. {
  1067. $row = $this->get_category_info($category_data_sql['category_id']);
  1068. if (sizeof($errors))
  1069. {
  1070. return $errors;
  1071. }
  1072. if ($row['parent_id'] != $category_data_sql['parent_id'])
  1073. {
  1074. $errors = $this->move_category($category_data_sql['category_id'], $category_data_sql['parent_id']);
  1075. }
  1076. if (sizeof($errors))
  1077. {
  1078. return $errors;
  1079. }
  1080. unset($category_data_sql['type_action']);
  1081. // Setting the category id to the category id is not really received well by some dbs. ;)
  1082. $category_id = $category_data_sql['category_id'];
  1083. unset($category_data_sql['category_id']);
  1084. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . '
  1085. SET ' . $db->sql_build_array('UPDATE', $category_data_sql) . '
  1086. WHERE category_id = ' . $category_id;
  1087. $db->sql_query($sql);
  1088. // Add it back
  1089. $category_data['category_id'] = $category_id;
  1090. add_log('admin', 'LOG_BLOG_CATEGORY_EDIT', $category_data['category_name']);
  1091. }
  1092. return $errors;
  1093. }
  1094. /**
  1095. * Move category
  1096. */
  1097. function move_category($from_id, $to_id)
  1098. {
  1099. global $db, $user;
  1100. $to_data = $moved_ids = $errors = array();
  1101. // Check if we want to move to a parent with link type
  1102. if ($to_id > 0)
  1103. {
  1104. $to_data = $this->get_category_info($to_id);
  1105. }
  1106. $moved_categories = get_category_branch($from_id, 'children', 'descending');
  1107. $from_data = $moved_categories[0];
  1108. $diff = sizeof($moved_categories) * 2;
  1109. $moved_ids = array();
  1110. for ($i = 0; $i < sizeof($moved_categories); ++$i)
  1111. {
  1112. $moved_ids[] = $moved_categories[$i]['category_id'];
  1113. }
  1114. // Resync parents
  1115. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . "
  1116. SET right_id = right_id - $diff
  1117. WHERE left_id < " . $from_data['right_id'] . "
  1118. AND right_id > " . $from_data['right_id'];
  1119. $db->sql_query($sql);
  1120. // Resync righthand side of tree
  1121. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . "
  1122. SET left_id = left_id - $diff, right_id = right_id - $diff
  1123. WHERE left_id > " . $from_data['right_id'];
  1124. $db->sql_query($sql);
  1125. if ($to_id > 0)
  1126. {
  1127. // Retrieve $to_data again, it may have been changed...
  1128. $to_data = $this->get_category_info($to_id);
  1129. // Resync new parents
  1130. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . "
  1131. SET right_id = right_id + $diff
  1132. WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
  1133. AND ' . $db->sql_in_set('category_id', $moved_ids, true);
  1134. $db->sql_query($sql);
  1135. // Resync the righthand side of the tree
  1136. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . "
  1137. SET left_id = left_id + $diff, right_id = right_id + $diff
  1138. WHERE left_id > " . $to_data['right_id'] . '
  1139. AND ' . $db->sql_in_set('category_id', $moved_ids, true);
  1140. $db->sql_query($sql);
  1141. // Resync moved branch
  1142. $to_data['right_id'] += $diff;
  1143. if ($to_data['right_id'] > $from_data['right_id'])
  1144. {
  1145. $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
  1146. }
  1147. else
  1148. {
  1149. $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
  1150. }
  1151. }
  1152. else
  1153. {
  1154. $sql = 'SELECT MAX(right_id) AS right_id
  1155. FROM ' . BLOGS_CATEGORIES_TABLE . '
  1156. WHERE ' . $db->sql_in_set('category_id', $moved_ids, true);
  1157. $result = $db->sql_query($sql);
  1158. $row = $db->sql_fetchrow($result);
  1159. $db->sql_freeresult($result);
  1160. $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
  1161. }
  1162. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . "
  1163. SET left_id = left_id $diff, right_id = right_id $diff
  1164. WHERE " . $db->sql_in_set('category_id', $moved_ids);
  1165. $db->sql_query($sql);
  1166. return $errors;
  1167. }
  1168. /**
  1169. * Move category content from one to another category
  1170. */
  1171. function move_category_content($from_id, $to_id, $sync = true)
  1172. {
  1173. global $db;
  1174. $sql = 'SELECT count(blog_id) AS total FROM ' . BLOGS_IN_CATEGORIES_TABLE . '
  1175. WHERE category_id = ' . $from_id;
  1176. $result = $db->sql_query($sql);
  1177. $row = $db->sql_fetchrow($result);
  1178. if ($row !== false)
  1179. {
  1180. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . '
  1181. SET blog_count = blog_count + ' . $row['total'] . '
  1182. WHERE category_id = \'' . $to_id . '\'';
  1183. $db->sql_query($sql);
  1184. }
  1185. $sql = 'UPDATE ' . BLOGS_IN_CATEGORIES_TABLE . "
  1186. SET category_id = '$to_id'
  1187. WHERE category_id = '$from_id'";
  1188. $db->sql_query($sql);
  1189. return array();
  1190. }
  1191. /**
  1192. * Delete category content
  1193. */
  1194. function delete_category_content($category_id)
  1195. {
  1196. global $db;
  1197. $sql = 'DELETE FROM ' . BLOGS_IN_CATEGORIES_TABLE . "
  1198. WHERE category_id = $category_id";
  1199. $db->sql_query($sql);
  1200. return array();
  1201. }
  1202. /**
  1203. * Remove complete category
  1204. */
  1205. function delete_category($category_id, $action_blogs = 'delete', $action_subcategories = 'delete', $blogs_to_id = 0, $subcategories_to_id = 0)
  1206. {
  1207. global $db, $user;
  1208. $category_data = $this->get_category_info($category_id);
  1209. $errors = array();
  1210. $log_action_posts = $log_action_categories = $posts_to_name = $subcategories_to_name = '';
  1211. $category_ids = array($category_id);
  1212. if (sizeof($errors))
  1213. {
  1214. return $errors;
  1215. }
  1216. if ($action_blogs == 'delete')
  1217. {
  1218. $errors = array_merge($errors, $this->delete_category_content($category_id));
  1219. }
  1220. else if ($action_blogs == 'move')
  1221. {
  1222. if (!$blogs_to_id)
  1223. {
  1224. $errors[] = $user->lang['NO_DESTINATION_CATEGORY'];
  1225. }
  1226. else
  1227. {
  1228. $sql = 'SELECT category_name
  1229. FROM ' . BLOGS_CATEGORIES_TABLE . '
  1230. WHERE category_id = ' . $blogs_to_id;
  1231. $result = $db->sql_query($sql);
  1232. $row = $db->sql_fetchrow($result);
  1233. $db->sql_freeresult($result);
  1234. if (!$row)
  1235. {
  1236. $errors[] = $user->lang['NO_CATEGORY'];
  1237. }
  1238. else
  1239. {
  1240. $blogs_to_name = $row['category_name'];
  1241. $errors = array_merge($errors, $this->move_category_content($category_id, $blogs_to_id));
  1242. }
  1243. }
  1244. }
  1245. if (sizeof($errors))
  1246. {
  1247. return $errors;
  1248. }
  1249. if ($action_subcategories == 'delete')
  1250. {
  1251. $rows = get_category_branch($category_id, 'children', 'descending', false);
  1252. foreach ($rows as $row)
  1253. {
  1254. $category_ids[] = $row['category_id'];
  1255. $errors = array_merge($errors, $this->delete_category_content($row['category_id']));
  1256. }
  1257. if (sizeof($errors))
  1258. {
  1259. return $errors;
  1260. }
  1261. $diff = sizeof($category_ids) * 2;
  1262. $sql = 'DELETE FROM ' . BLOGS_CATEGORIES_TABLE . '
  1263. WHERE ' . $db->sql_in_set('category_id', $category_ids);
  1264. $db->sql_query($sql);
  1265. }
  1266. else if ($action_subcategories == 'move')
  1267. {
  1268. if (!$subcategories_to_id)
  1269. {
  1270. $errors[] = $user->lang['NO_DESTINATION_FORUM'];
  1271. }
  1272. else
  1273. {
  1274. $log_action_categories = 'MOVE_CATEGORIES';
  1275. $sql = 'SELECT category_name
  1276. FROM ' . BLOGS_CATEGORIES_TABLE . '
  1277. WHERE category_id = ' . $subcategories_to_id;
  1278. $result = $db->sql_query($sql);
  1279. $row = $db->sql_fetchrow($result);
  1280. $db->sql_freeresult($result);
  1281. if (!$row)
  1282. {
  1283. $errors[] = $user->lang['NO_CATEGORY'];
  1284. }
  1285. else
  1286. {
  1287. $subcategories_to_name = $row['category_name'];
  1288. $sql = 'SELECT category_id
  1289. FROM ' . BLOGS_CATEGORIES_TABLE . "
  1290. WHERE parent_id = $category_id";
  1291. $result = $db->sql_query($sql);
  1292. while ($row = $db->sql_fetchrow($result))
  1293. {
  1294. $this->move_category($row['category_id'], $subcategories_to_id);
  1295. }
  1296. $db->sql_freeresult($result);
  1297. // Grab new category data for correct tree updating later
  1298. $category_data = $this->get_category_info($category_id);
  1299. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . "
  1300. SET parent_id = $subcategories_to_id
  1301. WHERE parent_id = $category_id";
  1302. $db->sql_query($sql);
  1303. $diff = 2;
  1304. $sql = 'DELETE FROM ' . BLOGS_CATEGORIES_TABLE . "
  1305. WHERE category_id = $category_id";
  1306. $db->sql_query($sql);
  1307. }
  1308. }
  1309. if (sizeof($errors))
  1310. {
  1311. return $errors;
  1312. }
  1313. }
  1314. else
  1315. {
  1316. $diff = 2;
  1317. $sql = 'DELETE FROM ' . BLOGS_CATEGORIES_TABLE . "
  1318. WHERE category_id = $category_id";
  1319. $db->sql_query($sql);
  1320. }
  1321. // Resync tree
  1322. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . "
  1323. SET right_id = right_id - $diff
  1324. WHERE left_id < {$category_data['right_id']} AND right_id > {$category_data['right_id']}";
  1325. $db->sql_query($sql);
  1326. $sql = 'UPDATE ' . BLOGS_CATEGORIES_TABLE . "
  1327. SET left_id = left_id - $diff, right_id = right_id - $diff
  1328. WHERE left_id > {$category_data['right_id']}";
  1329. $db->sql_query($sql);
  1330. add_log('admin', 'LOG_CATEGORY_DELETE', $category_data['category_name']);
  1331. return $errors;
  1332. }
  1333. /**
  1334. * Move category position by $steps up/down
  1335. */
  1336. function move_category_by($category_row, $action = 'move_up', $steps = 1)
  1337. {
  1338. global $db;
  1339. /**
  1340. * Fetch all the siblings between the module's current spot
  1341. * and where we want to move it to. If there are less than $steps
  1342. * siblings between the current spot and the target then the
  1343. * module will move as far as possible
  1344. */
  1345. $sql = 'SELECT category_id, category_name, left_id, right_id
  1346. FROM ' . BLOGS_CATEGORIES_TABLE . "
  1347. WHERE parent_id = {$category_row['parent_id']}
  1348. AND " . (($action == 'move_up') ? "right_id < {$category_row['right_id']} ORDER BY right_id DESC" : "left

Large files files are truncated, but you can click here to view the full file