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

/system/expressionengine/controllers/cp/admin_content.php

https://bitbucket.org/tdevonshire/hoolux
PHP | 5283 lines | 3493 code | 1083 blank | 707 comment | 503 complexity | 201607107bf2c54da47ee90b7cc3fdb1 MD5 | raw file

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

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2012, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine CP Home Page Class
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Control Panel
  19. * @category Control Panel
  20. * @author EllisLab Dev Team
  21. * @link http://ellislab.com
  22. */
  23. class Admin_content extends CI_Controller {
  24. var $reserved = array(
  25. 'random', 'date', 'title', 'url_title', 'edit_date',
  26. 'comment_total', 'username', 'screen_name',
  27. 'most_recent_comment', 'expiration_date');
  28. // Category arrays
  29. var $categories = array();
  30. var $cat_update = array();
  31. var $temp;
  32. /**
  33. * Constructor
  34. */
  35. function __construct()
  36. {
  37. parent::__construct();
  38. $this->lang->loadfile('admin');
  39. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content', lang('admin_content'));
  40. // Note- no access check here to allow the publish page access to categories
  41. }
  42. // --------------------------------------------------------------------
  43. /**
  44. * Index function
  45. *
  46. * @access public
  47. * @return void
  48. */
  49. function index()
  50. {
  51. if ( ! $this->cp->allowed_group('can_access_admin', 'can_access_content_prefs'))
  52. {
  53. show_error(lang('unauthorized_access'));
  54. }
  55. $this->cp->set_variable('cp_page_title', lang('admin'));
  56. $this->javascript->compile();
  57. $this->cp->set_variable('cp_page_title', lang('admin_content'));
  58. $this->load->vars(array('controller'=>'admin'));
  59. $this->load->view('_shared/overview');
  60. }
  61. // --------------------------------------------------------------------
  62. /**
  63. * Channel Overview
  64. *
  65. * Displays the Channel Management page
  66. *
  67. * @access public
  68. * @return void
  69. */
  70. function channel_management()
  71. {
  72. $this->_restrict_prefs_access();
  73. $this->cp->set_right_nav(array('create_new_channel' => BASE.AMP.'C=admin_content'.AMP.'M=channel_add'));
  74. $this->load->library('table');
  75. $this->lang->loadfile('admin_content');
  76. $this->load->model('channel_model');
  77. $this->cp->set_variable('cp_page_title', lang('channels'));
  78. $this->jquery->tablesorter('.mainTable', '{
  79. headers: {2: {sorter: false}, 3: {sorter: false}, 4: {sorter: false}},
  80. widgets: ["zebra"]
  81. }');
  82. $this->javascript->compile();
  83. $vars['channel_data'] = $this->channel_model->get_channels();
  84. $this->load->view('admin/channel_management', $vars);
  85. }
  86. // --------------------------------------------------------------------
  87. /**
  88. * Add Channel
  89. *
  90. * Displays the Channel Preferences form
  91. *
  92. * @access public
  93. * @return void
  94. */
  95. function channel_add()
  96. {
  97. $this->_restrict_prefs_access();
  98. $this->_channel_validation_rules();
  99. if ($this->form_validation->run() !== FALSE)
  100. {
  101. return $this->channel_update();
  102. }
  103. $this->lang->loadfile('admin_content');
  104. $this->load->helper('snippets');
  105. $this->load->model('channel_model');
  106. $this->load->model('category_model');
  107. $this->cp->add_js_script('plugin', 'ee_url_title');
  108. $this->javascript->output('
  109. $("#edit_group_prefs").hide();
  110. $("#channel_title").bind("keyup keydown", function() {
  111. $(this).ee_url_title("#channel_name");
  112. });
  113. ');
  114. $this->javascript->click("#edit_group_prefs_y", '$("#edit_group_prefs").show();', FALSE);
  115. $this->javascript->click("#edit_group_prefs_n", '$("#edit_group_prefs").hide();', FALSE);
  116. $this->cp->set_variable('cp_page_title', lang('create_new_channel'));
  117. $channels = $this->channel_model->get_channels($this->config->item('site_id'), array('channel_id', 'channel_title'));
  118. $vars['duplicate_channel_prefs_options'][''] = lang('do_not_duplicate');
  119. if ($channels != FALSE && $channels->num_rows() > 0)
  120. {
  121. foreach($channels->result() as $channel)
  122. {
  123. $vars['duplicate_channel_prefs_options'][$channel->channel_id] = $channel->channel_title;
  124. }
  125. }
  126. $vars['cat_group_options'][''] = lang('none');
  127. $groups = $this->category_model->get_categories('', $this->config->item('site_id'));
  128. if ($groups->num_rows() > 0)
  129. {
  130. foreach ($groups->result() as $group)
  131. {
  132. $vars['cat_group_options'][$group->group_id] = $group->group_name;
  133. }
  134. }
  135. $vars['status_group_options'][''] = lang('none');
  136. $this->db->select('group_id, group_name');
  137. $this->db->where('site_id', $this->config->item('site_id'));
  138. $this->db->order_by('group_name');
  139. $groups = $this->db->get('status_groups');
  140. if ($groups->num_rows() > 0)
  141. {
  142. foreach ($groups->result() as $group)
  143. {
  144. $vars['status_group_options'][$group->group_id] = $group->group_name;
  145. }
  146. }
  147. $vars['field_group_options'][''] = lang('none');
  148. $this->db->select('group_id, group_name');
  149. $this->db->where('site_id', $this->config->item('site_id'));
  150. $this->db->order_by('group_name');
  151. $groups = $this->db->get('field_groups');
  152. if ($groups->num_rows() > 0)
  153. {
  154. foreach ($groups->result() as $group)
  155. {
  156. $vars['field_group_options'][$group->group_id] = $group->group_name;
  157. }
  158. }
  159. // New themes may contain more than one group, thus naming collisions will happen
  160. // unless this is revamped.
  161. $vars['themes'] = array();
  162. $this->db->select('group_id, group_name, s.site_label');
  163. $this->db->from('template_groups tg, sites s');
  164. $this->db->where('tg.site_id = s.site_id', NULL, FALSE);
  165. if ($this->config->item('multiple_sites_enabled') !== 'y')
  166. {
  167. $this->db->where('tg.site_id', '1');
  168. }
  169. $this->db->order_by('tg.group_name');
  170. $query = $this->db->get();
  171. $vars['old_group_id'] = array();
  172. foreach ($query->result_array() as $row)
  173. {
  174. $vars['old_group_id'][$row['group_id']] = ($this->config->item('multiple_sites_enabled') == 'y') ? $row['site_label'].NBS.'-'.NBS.$row['group_name'] : $row['group_name'];
  175. }
  176. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=channel_management', lang('channels'));
  177. $this->javascript->compile();
  178. $this->load->view('admin/channel_add', $vars);
  179. }
  180. // --------------------------------------------------------------------
  181. /**
  182. * Edit Channel
  183. *
  184. * Displays the Channel Preferences form
  185. *
  186. * @access public
  187. * @return void
  188. */
  189. function channel_edit()
  190. {
  191. $this->_restrict_prefs_access();
  192. // Get modules that are installed
  193. $this->cp->get_installed_modules();
  194. $this->lang->loadfile('admin_content');
  195. $this->load->library('table');
  196. $this->load->helper('snippets');
  197. $this->load->model('channel_model');
  198. $this->load->model('template_model');
  199. $this->load->model('status_model');
  200. $this->load->model('field_model');
  201. $this->load->model('admin_model');
  202. $channel_id = $this->input->get_post('channel_id');
  203. // If we don't have the $channel_id variable, bail out.
  204. if ($channel_id == '' OR ! is_numeric($channel_id))
  205. {
  206. show_error(lang('not_authorized'));
  207. }
  208. $this->_channel_validation_rules();
  209. $this->form_validation->set_old_value('channel_id', $channel_id);
  210. if ($this->form_validation->run() !== FALSE)
  211. {
  212. $this->form_validation->set_old_value('channel_id', $channel_id);
  213. return $this->channel_update();
  214. }
  215. $query = $this->channel_model->get_channel_info($channel_id);
  216. foreach ($query->row_array() as $key => $val)
  217. {
  218. $vars[$key] = $val;
  219. }
  220. $vars['form_hidden']['channel_id'] = $channel_id;
  221. // live_look_template
  222. $query = $this->template_model->get_templates();
  223. $vars['live_look_template_options'][0] = lang('no_live_look_template');
  224. if ($query->num_rows() > 0)
  225. {
  226. foreach ($query->result() as $template)
  227. {
  228. $vars['live_look_template_options'][$template->template_id] = $template->group_name.'/'.$template->template_name;
  229. }
  230. }
  231. // Default status menu
  232. $query = $this->status_model->get_statuses($vars['status_group']);
  233. $vars['deft_status_options']['open'] = lang('open');
  234. $vars['deft_status_options']['closed'] = lang('closed');
  235. if ($query->num_rows() > 0)
  236. {
  237. foreach ($query->result() as $row)
  238. {
  239. $status_name = ($row->status == 'open' OR $row->status == 'closed') ? lang($row->status) : $row->status;
  240. $vars['deft_status_options'][$row->status] = $status_name;
  241. }
  242. }
  243. $vars['deft_category_options'][''] = lang('none');
  244. $cats = $vars['cat_group'] ? explode('|', $vars['cat_group']) : array();
  245. // Needz moar felineness!
  246. if (count($cats))
  247. {
  248. $this->db->select('CONCAT('.$this->db->dbprefix('category_groups').'.group_name, ": ", '.$this->db->dbprefix('categories').'.cat_name) as display_name', FALSE);
  249. $this->db->select('categories.cat_id, categories.cat_name, category_groups.group_name');
  250. $this->db->from('categories, '.$this->db->dbprefix('category_groups'));
  251. $this->db->where($this->db->dbprefix('category_groups').'.group_id = '.$this->db->dbprefix('categories').'.group_id', NULL, FALSE);
  252. $this->db->where_in('categories.group_id', $cats);
  253. $this->db->order_by('display_name');
  254. $query = $this->db->get();
  255. if ($query->num_rows() > 0)
  256. {
  257. foreach ($query->result() as $row)
  258. {
  259. $vars['deft_category_options'][$row->cat_id] = $row->display_name;
  260. }
  261. }
  262. }
  263. // Default field for search excerpt
  264. $this->db->select('field_id, field_label');
  265. $this->db->where('group_id', $vars['field_group']);
  266. $query = $this->db->get('channel_fields');
  267. $vars['search_excerpt_options'] = array();
  268. if ($query->num_rows() > 0)
  269. {
  270. foreach ($query->result() as $row)
  271. {
  272. $vars['search_excerpt_options'][$row->field_id] = $row->field_label;
  273. }
  274. }
  275. // HTML formatting
  276. $vars['channel_html_formatting_options'] = array(
  277. 'none' => lang('convert_to_entities'),
  278. 'safe' => lang('allow_safe_html'),
  279. 'all' => lang('allow_all_html')
  280. );
  281. if (isset($this->cp->installed_modules['comment']))
  282. {
  283. // Default comment text formatting
  284. $vars['comment_text_formatting_options'] = array(
  285. 'none' => lang('none'),
  286. 'xhtml' => lang('xhtml'),
  287. 'br' => lang('auto_br')
  288. );
  289. // Comment HTML formatting
  290. $vars['comment_html_formatting_options'] = array(
  291. 'none' => lang('convert_to_entities'),
  292. 'safe' => lang('allow_safe_html'),
  293. 'all' => lang('allow_all_html_not_recommended')
  294. );
  295. }
  296. $vars['languages'] = $this->admin_model->get_xml_encodings();
  297. $this->javascript->compile();
  298. $this->cp->set_variable('cp_page_title', lang('channel_prefs').': '.$vars['channel_title']);
  299. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=channel_management', lang('channels'));
  300. $this->load->view('admin/channel_edit', $vars);
  301. }
  302. // --------------------------------------------------------------------
  303. /**
  304. * Channel preference submission validation
  305. *
  306. * Sets the channel validation rules
  307. *
  308. * @access public
  309. * @return void
  310. */
  311. function _channel_validation_rules()
  312. {
  313. $this->load->library('form_validation');
  314. $this->form_validation->set_rules('channel_title', 'lang:channel_title', 'required');
  315. $this->form_validation->set_rules('channel_name', 'lang:channel_name', 'required|callback__valid_channel_name');
  316. $this->form_validation->set_rules('url_title_prefix', 'lang:url_title_prefix', 'strtolower|strip_tags|callback__valid_prefix');
  317. $this->form_validation->set_rules('comment_expiration', 'lang:comment_expiration', 'numeric');
  318. $this->form_validation->set_error_delimiters('<p class="notice">', '</p>');
  319. }
  320. function _valid_prefix($str)
  321. {
  322. if ($str == '')
  323. {
  324. return TRUE;
  325. }
  326. $this->form_validation->set_message('_valid_prefix', lang('invalid_url_title_prefix'));
  327. return preg_match('/^[\w\-]+$/', $str) ? TRUE : FALSE;
  328. }
  329. function _valid_channel_name($str)
  330. {
  331. // Check short name characters
  332. if (preg_match('/[^a-z0-9\-\_]/i', $str))
  333. {
  334. $this->form_validation->set_message('_valid_channel_name', lang('invalid_short_name'));
  335. return FALSE;
  336. }
  337. // Check for duplicates
  338. $this->db->where('site_id', $this->config->item('site_id'));
  339. $this->db->where('channel_name', $str);
  340. if ($this->form_validation->old_value('channel_id'))
  341. {
  342. $this->db->where('channel_id != ', $this->form_validation->old_value('channel_id'));
  343. }
  344. if ($this->db->count_all_results('channels') > 0)
  345. {
  346. $this->form_validation->set_message('_valid_channel_name', lang('taken_channel_name'));
  347. return FALSE;
  348. }
  349. return TRUE;
  350. }
  351. // --------------------------------------------------------------------
  352. /**
  353. * Channel preference submission handler
  354. *
  355. * This function receives the submitted channel preferences
  356. * and stores them in the database.
  357. *
  358. * @access public
  359. * @return void
  360. */
  361. function channel_update()
  362. {
  363. $this->_restrict_prefs_access();
  364. $this->lang->loadfile('admin_content');
  365. unset($_POST['channel_prefs_submit']); // submit button
  366. // If the $channel_id variable is present we are editing an
  367. // existing channel, otherwise we are creating a new one
  368. $edit = (isset($_POST['channel_id'])) ? TRUE : FALSE;
  369. // Load the layout Library & update the layouts
  370. $this->load->library('layout');
  371. $add_rss = (isset($_POST['add_rss'])) ? TRUE : FALSE;
  372. unset($_POST['add_rss']);
  373. $return = ($this->input->get_post('return')) ? TRUE : FALSE;
  374. unset($_POST['return']);
  375. $edit_group_prefs = TRUE;
  376. if ($this->input->get_post('edit_group_prefs') !== 'y')
  377. {
  378. unset($_POST['cat_group']);
  379. unset($_POST['status_group']);
  380. unset($_POST['field_group']);
  381. $edit_group_prefs = FALSE;
  382. }
  383. unset($_POST['edit_group_prefs']);
  384. $dupe_id = $this->input->get_post('duplicate_channel_prefs');
  385. unset($_POST['duplicate_channel_prefs']);
  386. // Check for required fields
  387. $error = array();
  388. if (isset($_POST['comment_expiration']) && $_POST['comment_expiration'] == '')
  389. {
  390. $_POST['comment_expiration'] = 0;
  391. }
  392. // Template Error Trapping
  393. if ($edit == FALSE)
  394. {
  395. $create_templates = ($this->input->get_post('create_templates') == FALSE OR $this->input->get_post('create_templates') == 'no') ? 'no' : $this->input->get_post('create_templates');
  396. $old_group_id = $this->input->get_post('old_group_id');
  397. $group_name = $this->input->post('group_name');
  398. $template_theme = $this->security->sanitize_filename($this->input->get_post('template_theme'));
  399. unset($_POST['create_templates']);
  400. unset($_POST['old_group_id']);
  401. unset($_POST['group_name']);
  402. unset($_POST['template_theme']);
  403. if ($create_templates != 'no')
  404. {
  405. $this->lang->loadfile('design');
  406. if ( ! $this->cp->allowed_group('can_admin_templates'))
  407. {
  408. show_error(lang('unauthorized_access'));
  409. }
  410. if ( ! $group_name)
  411. {
  412. show_error(lang('group_required'));
  413. }
  414. if ( ! preg_match("#^[a-zA-Z0-9_\-/]+$#i", $group_name))
  415. {
  416. show_error(lang('illegal_characters'));
  417. }
  418. $reserved[] = 'act';
  419. if ($this->config->item("forum_is_installed") == 'y' AND $this->config->item("forum_trigger") != '')
  420. {
  421. $reserved[] = $this->config->item("forum_trigger");
  422. }
  423. if (in_array($group_name, $reserved))
  424. {
  425. show_error(lang('reserved_name'));
  426. }
  427. $this->db->where('site_id', $this->config->item('site_id'));
  428. $this->db->where('group_name', $group_name);
  429. $count = $this->db->count_all_results('template_groups');
  430. if ($count > 0)
  431. {
  432. show_error(lang('template_group_taken'));
  433. }
  434. }
  435. }
  436. if ($this->input->post('apply_comment_enabled_to_existing'))
  437. {
  438. if ($this->input->post('comment_system_enabled') == 'y')
  439. {
  440. $this->channel_model->update_comments_allowed($_POST['channel_id'], 'y');
  441. }
  442. elseif ($this->input->post('comment_system_enabled') == 'n')
  443. {
  444. $this->channel_model->update_comments_allowed($_POST['channel_id'], 'n');
  445. }
  446. }
  447. unset($_POST['apply_comment_enabled_to_existing']);
  448. if (isset($_POST['apply_expiration_to_existing']))
  449. {
  450. if ($this->input->post('comment_expiration') == 0)
  451. {
  452. $this->channel_model->update_comment_expiration($_POST['channel_id'], $_POST['comment_expiration'], TRUE);
  453. }
  454. else
  455. {
  456. $this->channel_model->update_comment_expiration($_POST['channel_id'], $_POST['comment_expiration'] * 86400);
  457. }
  458. }
  459. unset($_POST['apply_expiration_to_existing']);
  460. if (isset($_POST['cat_group']) && is_array($_POST['cat_group']))
  461. {
  462. foreach($_POST['cat_group'] as $key => $value)
  463. {
  464. unset($_POST['cat_group_'.$key]);
  465. }
  466. $_POST['cat_group'] = implode('|', $_POST['cat_group']);
  467. }
  468. // Create Channel
  469. // Construct the query based on whether we are updating or inserting
  470. if ($edit == FALSE)
  471. {
  472. unset($_POST['channel_id']);
  473. unset($_POST['clear_versioning_data']);
  474. $_POST['channel_url'] = $this->functions->fetch_site_index();
  475. $_POST['channel_lang'] = $this->config->item('xml_lang');
  476. // Assign field group if there is only one
  477. if ($dupe_id != '' && ( ! isset($_POST['field_group']) OR (isset($_POST['field_group']) && ! is_numeric($_POST['field_group']))))
  478. {
  479. $this->db->select('group_id');
  480. $this->db->where('site_id', $this->config->item('site_id'));
  481. $query = $this->db->get('field_groups');
  482. if ($query->num_rows() == 1)
  483. {
  484. $_POST['field_group'] = $query->row('group_id') ;
  485. }
  486. }
  487. // Insert data
  488. $_POST['site_id'] = $this->config->item('site_id');
  489. $_POST['status_group'] = ($this->input->post('status_group') !== FALSE &&
  490. $this->input->post('status_group') != '')
  491. ? $this->input->post('status_group') : NULL;
  492. $_POST['field_group'] = ($this->input->post('field_group') !== FALSE &&
  493. $this->input->post('field_group') != '')
  494. ? $this->input->post('field_group') : NULL;
  495. // duplicating preferences?
  496. if ($dupe_id !== FALSE AND is_numeric($dupe_id))
  497. {
  498. $this->db->where('channel_id', $dupe_id);
  499. $wquery = $this->db->get('channels');
  500. if ($wquery->num_rows() == 1)
  501. {
  502. $exceptions = array('channel_id', 'site_id', 'channel_name', 'channel_title', 'total_entries',
  503. 'total_comments', 'last_entry_date', 'last_comment_date');
  504. foreach($wquery->row_array() as $key => $val)
  505. {
  506. // don't duplicate fields that are unique to each channel
  507. if ( ! in_array($key, $exceptions))
  508. {
  509. switch ($key)
  510. {
  511. // category, field, and status fields should only be duped
  512. // if both channels are assigned to the same group of each
  513. case 'cat_group':
  514. // allow to implicitly set category group to "None"
  515. if ( ! isset($_POST[$key]))
  516. {
  517. $_POST[$key] = $val;
  518. }
  519. break;
  520. case 'status_group':
  521. case 'field_group':
  522. if ( ! isset($_POST[$key]))
  523. {
  524. $_POST[$key] = $val;
  525. }
  526. elseif ($_POST[$key] == '')
  527. {
  528. $_POST[$key] = NULL;
  529. }
  530. break;
  531. case 'deft_status':
  532. case 'deft_status':
  533. if ( ! isset($_POST['status_group']) OR $_POST['status_group'] == $wquery->row('status_group') )
  534. {
  535. $_POST[$key] = $val;
  536. }
  537. break;
  538. case 'search_excerpt':
  539. if ( ! isset($_POST['field_group']) OR $_POST['field_group'] == $wquery->row('field_group') )
  540. {
  541. $_POST[$key] = $val;
  542. }
  543. break;
  544. case 'deft_category':
  545. if ( ! isset($_POST['cat_group']) OR count(array_diff(explode('|', $_POST['cat_group']), explode('|', $wquery->row('cat_group') ))) == 0)
  546. {
  547. $_POST[$key] = $val;
  548. }
  549. break;
  550. case 'blog_url':
  551. case 'comment_url':
  552. case 'search_results_url':
  553. case 'ping_return_url':
  554. case 'rss_url':
  555. if ($create_templates != 'no')
  556. {
  557. if ( ! isset($old_group_name))
  558. {
  559. $this->db->select('group_name');
  560. $this->db->where('group_id', $old_group_id);
  561. $gquery = $this->db->get('template_groups');
  562. $old_group_name = $gquery->row('group_name');
  563. }
  564. $_POST[$key] = str_replace("/{$old_group_name}/", "/{$group_name}/", $val);
  565. }
  566. else
  567. {
  568. $_POST[$key] = $val;
  569. }
  570. break;
  571. default :
  572. $_POST[$key] = $val;
  573. break;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. $_POST['default_entry_title'] = ( ! isset( $_POST['default_entry_title'])) ? '' : $_POST['default_entry_title'];
  580. $_POST['url_title_prefix'] = ( ! isset( $_POST['url_title_prefix'])) ? '' : $_POST['url_title_prefix'];
  581. $this->db->insert('channels', $_POST);
  582. $insert_id = $this->db->insert_id();
  583. $channel_id = $insert_id;
  584. // If they made the channel? Give access to that channel to the member group?
  585. if ($dupe_id !== FALSE AND is_numeric($dupe_id) && $edit_group_prefs == FALSE)
  586. {
  587. // Duplicate layouts
  588. $this->layout->duplicate_layout($dupe_id, $channel_id);
  589. }
  590. // If member group has ability to create the channel, they should be
  591. // able to access it as well
  592. if ($this->session->userdata('group_id') != 1)
  593. {
  594. $data = array(
  595. 'group_id' => $this->session->userdata('group_id'),
  596. 'channel_id' => $channel_id
  597. );
  598. $this->db->insert('channel_member_groups', $data);
  599. }
  600. $success_msg = lang('channel_created');
  601. $this->logger->log_action($success_msg.NBS.NBS.$_POST['channel_title']);
  602. }
  603. else
  604. {
  605. if (isset($_POST['clear_versioning_data']))
  606. {
  607. $this->db->delete('entry_versioning', array('channel_id' => $_POST['channel_id']));
  608. unset($_POST['clear_versioning_data']);
  609. }
  610. // Only one possible is revisions- enabled or disabled.
  611. // We treat as installed/not and delete the whole tab.
  612. $this->layout->sync_layout($_POST, $_POST['channel_id']);
  613. $sql = $this->db->update_string('exp_channels', $_POST, 'channel_id='.$this->db->escape_str($_POST['channel_id']));
  614. $this->db->query($sql);
  615. $channel_id = $this->db->escape_str($_POST['channel_id']);
  616. $success_msg = lang('channel_updated');
  617. }
  618. /** -----------------------------------------
  619. /** Create Templates
  620. /** -----------------------------------------*/
  621. if ($edit == FALSE)
  622. {
  623. if ($create_templates != 'no')
  624. {
  625. $query = $this->db->query("SELECT COUNT(*) AS count FROM exp_template_groups");
  626. $group_order = $query->row('count') +1;
  627. $this->db->insert('template_groups', array(
  628. 'group_name' => $group_name,
  629. 'group_order' => $group_order,
  630. 'is_site_default' => 'n',
  631. 'site_id' => $this->config->item('site_id')
  632. ));
  633. $group_id = $this->db->insert_id();
  634. if ($create_templates == 'duplicate')
  635. {
  636. $this->db->select('group_name');
  637. $this->db->where('group_id', $old_group_id);
  638. $query = $this->db->get('template_groups');
  639. $old_group_name = $query->row('group_name') ;
  640. $this->db->select('template_name, template_data, template_type,
  641. template_notes, cache, refresh, no_auth_bounce,
  642. allow_php, php_parse_location');
  643. $this->db->where('group_id', $old_group_id);
  644. $query = $this->db->get('templates');
  645. if ($query->num_rows() == 0)
  646. {
  647. $this->db->insert('templates', array(
  648. 'group_id' => $group_id,
  649. 'template_name' => 'index',
  650. 'edit_date' => $this->localize->now,
  651. 'site_id' => $this->config->item('site_id')
  652. ));
  653. }
  654. else
  655. {
  656. $old_channel_name = '';
  657. foreach ($query->result_array() as $row)
  658. {
  659. if ($old_channel_name == '')
  660. {
  661. if (preg_match_all("/channel=[\"'](.+?)[\"']/", $row['template_data'], $matches))
  662. {
  663. for ($i = 0; $i < count($matches['1']); $i++)
  664. {
  665. if (substr($matches['1'][$i], 0, 1) != '{')
  666. {
  667. $old_channel_name = $matches['1'][$i];
  668. break;
  669. }
  670. }
  671. }
  672. }
  673. $temp = str_replace('channel="'.$old_channel_name.'"', 'channel="'.$_POST['channel_name'].'"', $row['template_data']);
  674. $temp = str_replace("channel='".$old_channel_name."'", 'channel="'.$_POST['channel_name'].'"', $temp);
  675. $temp = preg_replace("/{stylesheet=.+?\/(.+?)}/", "{stylesheet=".$group_name."/\\1}", $temp);
  676. $temp = preg_replace("#preload_replace:master_channel_name=\".+?\"#", 'preload_replace:master_channel_name="'.$_POST['channel_name'].'"', $temp);
  677. $temp = preg_replace("#preload_replace:master_channel_name=\'.+?\'#", "preload_replace:master_channel_name='".$_POST['channel_name']."'", $temp);
  678. $temp = preg_replace('#preload_replace:my_template_group=(\042|\047)([^\\1]*?)\\1#', "preload_replace:my_template_group=\\1{$group_name}\\1", $temp);
  679. $temp = preg_replace("#".$old_group_name."/(.+?)#", $group_name."/\\1", $temp);
  680. $data = array(
  681. 'group_id' => $group_id,
  682. 'template_name' => $row['template_name'],
  683. 'template_notes' => $row['template_notes'],
  684. 'cache' => $row['cache'],
  685. 'refresh' => $row['refresh'],
  686. 'no_auth_bounce' => $row['no_auth_bounce'],
  687. 'php_parse_location' => $row['php_parse_location'],
  688. 'allow_php' => ($this->session->userdata['group_id'] == 1) ? $row['allow_php'] : 'n',
  689. 'template_type' => $row['template_type'],
  690. 'template_data' => $temp,
  691. 'edit_date' => $this->localize->now,
  692. 'last_author_id' => 0,
  693. 'site_id' => $this->config->item('site_id')
  694. );
  695. $this->db->insert('templates', $data);
  696. }
  697. }
  698. }
  699. else
  700. {
  701. $type = 'core';
  702. if ($fp = @opendir(PATH_MOD))
  703. {
  704. while (FALSE !== ($file = readdir($fp)))
  705. {
  706. if (strpos($file, '.') === FALSE)
  707. {
  708. if ($file == 'mailinglist')
  709. {
  710. $type = 'full';
  711. break;
  712. }
  713. }
  714. }
  715. closedir($fp);
  716. }
  717. require PATH_THEMES.'site_themes/'.$template_theme.'/'.$template_theme.'.php';
  718. foreach ($template_matrix as $tmpl)
  719. {
  720. $Q[] = array($tmpl['0'](), "INSERT INTO exp_templates(group_id, template_name, template_type, template_data, edit_date, site_id)
  721. VALUES ('$group_id', '".$this->db->escape_str($tmpl['0'])."', '".$this->db->escape_str($tmpl['1'])."', '{template}', '".$this->localize->now."', '".$this->db->escape_str($this->config->item('site_id'))."')");
  722. }
  723. if ($add_rss == TRUE)
  724. {
  725. require PATH_THEMES.'site_themes/rss/rss.php';
  726. $Q[] = array(rss_2(), "INSERT INTO exp_templates(group_id, template_name, template_type, template_data, edit_date, site_id)
  727. VALUES ('$group_id', 'rss_2.0', 'feed', '{template}', '".$this->db->escape_str($this->localize->now)."', '".$this->db->escape_str($this->config->item('site_id'))."')");
  728. $Q[] = array(atom(), "INSERT INTO exp_templates(group_id, template_name, template_type, template_data, edit_date, site_id)
  729. VALUES ('$group_id', 'atom', 'feed', '{template}', '".$this->db->escape_str($this->localize->now)."', '".$this->db->escape_str($this->config->item('site_id'))."')");
  730. }
  731. foreach ($Q as $val)
  732. {
  733. $temp = $val['0'];
  734. $temp = str_replace('channel="channel1"', 'channel="'.$_POST['channel_name'].'"', $temp);
  735. $temp = str_replace("channel='channel1'", 'channel="'.$_POST['channel_name'].'"', $temp);
  736. $temp = str_replace('my_channel="channel1"', 'my_channel="'.$_POST['channel_name'].'"', $temp);
  737. $temp = str_replace("my_channel='channel1'", 'my_channel="'.$_POST['channel_name'].'"', $temp);
  738. $temp = str_replace('channel="default_site"', 'channel="'.$_POST['channel_name'].'"', $temp);
  739. $temp = str_replace("channel='default_site'", 'channel="'.$_POST['channel_name'].'"', $temp);
  740. $temp = str_replace('my_channel="default_site"', 'my_channel="'.$_POST['channel_name'].'"', $temp);
  741. $temp = str_replace("my_channel='default_site'", 'my_channel="'.$_POST['channel_name'].'"', $temp);
  742. $temp = str_replace('my_template_group="site"', 'my_template_group="'.$group_name.'"', $temp);
  743. $temp = str_replace("my_template_group='site'", 'my_template_group="'.$group_name.'"', $temp);
  744. $temp = str_replace("{stylesheet=channel/channel_css}", "{stylesheet=".$group_name."/site_css}", $temp);
  745. $temp = str_replace("{stylesheet=site/site_css}", "{stylesheet=".$group_name."/site_css}", $temp);
  746. $temp = str_replace('preload_replace:master_channel_name="channel1"', 'preload_replace:master_channel_name="'.$_POST['channel_name'].'"', $temp);
  747. $temp = preg_replace("#channel/(.+?)#", $group_name."/\\1", $temp);
  748. $temp = addslashes($temp);
  749. $sql = str_replace('{template}', $temp, $val['1']);
  750. $this->db->query($sql);
  751. }
  752. }
  753. }
  754. }
  755. $cp_message = $success_msg.NBS.NBS.$_POST['channel_title'];
  756. $this->session->set_flashdata('message_success', $cp_message);
  757. if ($edit == FALSE OR $return === TRUE)
  758. {
  759. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=channel_management');
  760. }
  761. else
  762. {
  763. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=channel_edit&channel_id='.$channel_id);
  764. }
  765. }
  766. // --------------------------------------------------------------------
  767. /**
  768. * Channel Update Group Assignments
  769. *
  770. * This function processes changes to the channel's
  771. * assigned groups
  772. *
  773. * @access public
  774. * @return void
  775. */
  776. function channel_update_group_assignments()
  777. {
  778. $this->_restrict_prefs_access();
  779. $update_fields = FALSE;
  780. $channel_id = $this->input->post('channel_id');
  781. $data['field_group'] = ($this->input->post('field_group') != FALSE && $this->input->post('field_group') != '') ? $this->input->post('field_group') : NULL;
  782. $data['status_group'] = ($this->input->post('status_group') != FALSE && $this->input->post('status_group') != '') ? $this->input->post('status_group') : NULL;
  783. $this->lang->loadfile('admin_content');
  784. if (isset($_POST['cat_group']) && is_array($_POST['cat_group']))
  785. {
  786. $data['cat_group'] = ltrim(implode('|', $_POST['cat_group']), '|');
  787. }
  788. if ( ! isset($data['cat_group']) OR $data['cat_group'] == '')
  789. {
  790. $data['cat_group'] = '';
  791. }
  792. // Find the old custom fields so we can remove them
  793. // Have the field assignments changed
  794. $this->db->select('cat_group, status_group, field_group');
  795. $this->db->where('channel_id', $channel_id);
  796. $query = $this->db->get('channels');
  797. if ($query->num_rows() == 1)
  798. {
  799. $old_cat = $query->row('cat_group');
  800. $old_status = $query->row('status_group');
  801. $old_field = $query->row('field_group');
  802. }
  803. if ($old_field != $data['field_group'] && ! is_null($old_field))
  804. {
  805. $update_fields = TRUE;
  806. $this->db->select('field_id');
  807. $this->db->where('group_id', $old_field);
  808. $query = $this->db->get('channel_fields');
  809. if ($query->num_rows() > 0)
  810. {
  811. foreach($query->result() as $row)
  812. {
  813. $tabs[] = $row->field_id;
  814. }
  815. $this->load->library('layout');
  816. $this->layout->delete_layout_fields($tabs, $channel_id);
  817. unset($tabs);
  818. }
  819. }
  820. $this->db->where('channel_id', $channel_id);
  821. $this->db->update('channels', $data);
  822. // Updated saved layouts if field group changed
  823. if ($update_fields == TRUE && ! is_null($data['field_group']))
  824. {
  825. $this->db->select('field_id');
  826. $this->db->where('group_id', $data['field_group']);
  827. $query = $this->db->get('channel_fields');
  828. if ($query->num_rows() > 0)
  829. {
  830. foreach($query->result() as $row)
  831. {
  832. $tabs['publish'][$row->field_id] = array(
  833. 'visible' => 'true',
  834. 'collapse' => 'false',
  835. 'htmlbuttons' => 'true',
  836. 'width' => '100%'
  837. );
  838. }
  839. $this->load->library('layout');
  840. $this->layout->add_layout_fields($tabs, $channel_id);
  841. }
  842. }
  843. $success_msg = lang('channel_updated');
  844. $cp_message = $success_msg.NBS.NBS.$_POST['channel_title'];
  845. $this->session->set_flashdata('message_success', $cp_message);
  846. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=channel_management');
  847. }
  848. // --------------------------------------------------------------------
  849. /**
  850. * Edit Channel
  851. *
  852. * This function displays the form used to edit the various
  853. * preferences and group assignments for a given channel
  854. *
  855. * @access public
  856. * @return void
  857. */
  858. function channel_edit_group_assignments()
  859. {
  860. $this->_restrict_prefs_access();
  861. // If we don't have the $channel_id variable, bail out.
  862. $channel_id = $this->input->get_post('channel_id');
  863. if ($channel_id == '' OR ! is_numeric($channel_id))
  864. {
  865. show_error(lang('not_authorized'));
  866. }
  867. $this->lang->loadfile('admin_content');
  868. $this->load->model(array(
  869. 'channel_model', 'category_model', 'status_model', 'field_model'
  870. ));
  871. $query = $this->channel_model->get_channel_info($channel_id);
  872. foreach ($query->row_array() as $key => $val)
  873. {
  874. if ($key == 'cat_group')
  875. {
  876. $val = explode('|', $val);
  877. }
  878. $vars[$key] = $val;
  879. }
  880. $vars['form_hidden'] = array(
  881. 'channel_id' => $channel_id,
  882. 'channel_name' => $vars['channel_name'],
  883. 'channel_title' => $vars['channel_title'],
  884. 'return' => 1
  885. );
  886. // Category Select List
  887. $query = $this->category_model->get_category_groups('', FALSE, 2);
  888. $vars['cat_group_options'][''] = lang('none');
  889. if ($query->num_rows() > 0)
  890. {
  891. foreach ($query->result() as $row)
  892. {
  893. $vars['cat_group_options'][$row->group_id] = $row->group_name;
  894. }
  895. }
  896. // Status group select list
  897. $this->db->select('group_id, group_name');
  898. $this->db->where('site_id', $this->config->item('site_id'));
  899. $this->db->order_by('group_name');
  900. $query = $this->db->get('status_groups');
  901. $vars['status_group_options'][''] = lang('none');
  902. if ($query->num_rows() > 0)
  903. {
  904. foreach ($query->result() as $row)
  905. {
  906. $vars['status_group_options'][$row->group_id] = $row->group_name;
  907. }
  908. }
  909. // Field group select list
  910. $this->db->select('group_id, group_name');
  911. $this->db->where('site_id', $this->config->item('site_id'));
  912. $this->db->order_by('group_name');
  913. $query = $this->db->get('field_groups');
  914. $vars['field_group_options'][''] = lang('none');
  915. if ($query->num_rows() > 0)
  916. {
  917. foreach ($query->result() as $row)
  918. {
  919. $vars['field_group_options'][$row->group_id] = $row->group_name;
  920. }
  921. }
  922. $this->javascript->compile();
  923. $this->cp->set_variable('cp_page_title', lang('edit_group_assignments'));
  924. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=channel_management', lang('channels'));
  925. $this->load->view('admin/channel_edit_group_assignments', $vars);
  926. }
  927. // --------------------------------------------------------------------
  928. /**
  929. * Delete channel confirm
  930. *
  931. * @access public
  932. * @return void
  933. */
  934. function channel_delete_confirm()
  935. {
  936. $this->_restrict_prefs_access();
  937. $channel_id = $this->input->get_post('channel_id');
  938. if ($channel_id == '' OR ! is_numeric($channel_id))
  939. {
  940. show_error(lang('not_authorized'));
  941. }
  942. $this->lang->loadfile('admin_content');
  943. $this->load->model('channel_model');
  944. $this->cp->set_variable('cp_page_title', lang('delete_channel'));
  945. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=channel_management', lang('channels'));
  946. $vars['form_action'] = 'C=admin_content'.AMP.'M=channel_delete';
  947. $vars['form_extra'] = '';
  948. $vars['form_hidden']['channel_id'] = $channel_id;
  949. $vars['message'] = lang('delete_channel_confirmation');
  950. // Grab category_groups locations with this id
  951. $items = $this->channel_model->get_channel_info($channel_id);
  952. $vars['items'] = array();
  953. foreach($items->result() as $item)
  954. {
  955. $vars['items'][] = $item->channel_title;
  956. }
  957. $this->javascript->compile();
  958. $this->load->view('admin/preference_delete_confirm', $vars);
  959. }
  960. // --------------------------------------------------------------------
  961. /**
  962. * Delete channel
  963. *
  964. * This function deletes a given channel
  965. *
  966. * @access public
  967. * @return void
  968. */
  969. function channel_delete()
  970. {
  971. $this->_restrict_prefs_access();
  972. $channel_id = $this->input->get_post('channel_id');
  973. if ($channel_id == '' OR ! is_numeric($channel_id))
  974. {
  975. show_error(lang('not_authorized'));
  976. }
  977. $this->lang->loadfile('admin_content');
  978. $this->load->model('channel_model');
  979. $query = $this->channel_model->get_channel_info($channel_id);
  980. if ($query->num_rows() == 0)
  981. {
  982. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=channel_management');
  983. }
  984. $channel_title = $query->row('channel_title') ;
  985. $this->logger->log_action(lang('channel_deleted').NBS.NBS.$channel_title);
  986. $this->db->select('entry_id, author_id');
  987. $this->db->where('channel_id', $channel_id);
  988. $query = $this->db->get('channel_titles');
  989. $entries = array();
  990. $authors = array();
  991. if ($query->num_rows() > 0)
  992. {
  993. foreach ($query->result() as $row)
  994. {
  995. $entries[] = $row->entry_id;
  996. $authors[] = $row->author_id;
  997. }
  998. }
  999. $authors = array_unique($authors);
  1000. $this->channel_model->delete_channel($channel_id, $entries, $authors);
  1001. // Clear saved layouts
  1002. $this->load->library('layout');
  1003. $this->layout->delete_channel_layouts($channel_id);
  1004. $this->session->set_flashdata('message_success', lang('channel_deleted').NBS.$channel_title);
  1005. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=channel_management');
  1006. }
  1007. // --------------------------------------------------------------------
  1008. /**
  1009. * Category Management
  1010. *
  1011. * Creates the Category Management main page
  1012. *
  1013. * @access public
  1014. * @return void
  1015. */
  1016. function category_management()
  1017. {
  1018. if (AJAX_REQUEST)
  1019. {
  1020. if ( ! $this->cp->allowed_group('can_edit_categories'))
  1021. {
  1022. show_error(lang('unauthorized_access'));
  1023. }
  1024. }
  1025. else
  1026. {
  1027. $this->_restrict_prefs_access();
  1028. }
  1029. $this->load->library('table');
  1030. $this->load->model('category_model');
  1031. $this->lang->loadfile('admin_content');
  1032. $this->cp->set_variable('cp_page_title', lang('categories'));
  1033. $this->jquery->tablesorter('.mainTable', '{
  1034. headers: {2: {sorter: false}, 3: {sorter: false}, 4: {sorter: false}, 5: {sorter: false}},
  1035. widgets: ["zebra"]
  1036. }');
  1037. $this->javascript->compile();
  1038. // Fetch count of custom fields per group
  1039. $cfcount = array();
  1040. $this->db->select('COUNT(*) AS count, group_id');
  1041. $this->db->group_by('group_id');
  1042. $cfq = $this->db->get('category_fields');
  1043. if ($cfq->num_rows() > 0)
  1044. {
  1045. foreach ($cfq->result() as $row)
  1046. {
  1047. $cfcount[$row->group_id] = $row->count;
  1048. }
  1049. }
  1050. $cat_count = 1;
  1051. $vars['categories'] = array();
  1052. $categories = $this->category_model->get_categories('', FALSE);
  1053. foreach($categories->result() as $row)
  1054. {
  1055. $this->db->where('group_id', $row->group_id);
  1056. $category_count = $this->db->count_all_results('categories');
  1057. $vars['categories'][$cat_count]['group_id'] = $row->group_id;
  1058. $vars['categories'][$cat_count]['group_name'] = $row->group_name;
  1059. $vars['categories'][$cat_count]['category_count'] = $category_count;
  1060. $vars['categories'][$cat_count]['custom_field_count'] = ((isset($cfcount[$row->group_id])) ? $cfcount[$row->group_id] : '0');
  1061. $cat_count++;
  1062. }
  1063. $this->cp->set_right_nav(array('create_new_category_group' => BASE.AMP.'C=admin_content'.AMP.'M=edit_category_group'));
  1064. $this->load->view('admin/category_management', $vars);
  1065. }
  1066. // --------------------------------------------------------------------
  1067. /**
  1068. * Edit Category Group
  1069. *
  1070. * This function shows the form used to define a new category
  1071. * group or edit an existing one
  1072. *
  1073. * @access public
  1074. * @return mixed
  1075. */
  1076. function edit_category_group()
  1077. {
  1078. $this->_restrict_prefs_access();
  1079. $this->load->model('admin_model');
  1080. $this->load->model('category_model');
  1081. $this->lang->loadfile('admin_content');
  1082. $this->load->library('table');
  1083. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_management', lang('categories'));
  1084. // Set default values
  1085. $vars['cp_page_title'] = lang('create_new_category_group');
  1086. $vars['submit_lang_key'] = 'submit';
  1087. $vars['form_hidden'] = array(); // nothing needs to be passed into a new cat group
  1088. $vars['group_name'] = '';
  1089. $vars['field_html_formatting'] = 'all';
  1090. $vars['can_edit'] = array();
  1091. $vars['can_delete'] = array();
  1092. $vars['can_edit_selected'] = array();
  1093. $vars['can_delete_selected'] = array();
  1094. $vars['formatting_options'] = array(
  1095. 'none' => lang('convert_to_entities'),
  1096. 'safe' => lang('allow_safe_html'),
  1097. 'all' => lang('allow_all_html')
  1098. );
  1099. $can_edit_selected = array();
  1100. $can_delete_selected = array();
  1101. $vars['can_edit_categories'] = '';
  1102. $vars['can_delete_categories'] = '';
  1103. $group_id = $this->input->get_post('group_id');
  1104. // If we have the group_id variable, it's an edit request, so fetch the category data
  1105. if ($group_id != '')
  1106. {
  1107. if ( ! is_numeric($group_id))
  1108. {
  1109. show_error();
  1110. }
  1111. // some defaults to overwrite if we're editing
  1112. $vars['cp_page_title'] = lang('edit_category_group');
  1113. $vars['submit_lang_key'] = 'update';
  1114. $vars['form_hidden']['group_id'] = $group_id;
  1115. $this->db->where('group_id', $group_id);
  1116. $this->db->where('site_id', $this->config->item('site_id'));
  1117. $this->db->from('category_groups');
  1118. $this->db->order_by('group_name');
  1119. $query = $this->db->get();
  1120. // there's only 1 possible category
  1121. foreach ($query->row_array() as $key => $val)
  1122. {
  1123. $vars[$key] = $val;
  1124. }
  1125. // convert our | separated list of privileges into an array
  1126. $can_edit_selected = explode('|', rtrim($vars['can_edit_categories'], '|'));
  1127. $can_delete_selected = explode('|', rtrim($vars['can_delete_categories'], '|'));
  1128. }
  1129. // Grab member groups with potential privs
  1130. $this->db->select('group_id, group_title, can_edit_categories, can_delete_categories');
  1131. $this->db->where_not_in('group_id', array(1,2,3,4));
  1132. $this->db->where('site_id', $this->config->item('site_id'));
  1133. $query = $this->db->get('member_groups');
  1134. $vars['can_edit_checks'] = array();
  1135. $vars['can_delete_checks'] = array();
  1136. // Can Edit/Delete Categories selected
  1137. foreach ($query->result_array() as $row)
  1138. {
  1139. if ($row['can_edit_categories'] == 'y')
  1140. {
  1141. $vars['can_edit_checks'][$row['group_id']]['id'] = $row['group_id'];
  1142. $vars['can_edit_checks'][$row['group_id']]['value'] = $row['group_title'];
  1143. $vars['can_edit_checks'][$row['group_id']]['checked'] = (in_array($row['group_id'], $can_edit_selected)) ? TRUE : FALSE;
  1144. $vars['can_edit'][$row['group_id']] = $row['group_title'];
  1145. }
  1146. if ($row['can_delete_categories'] == 'y')
  1147. {
  1148. $vars['can_delete_checks'][$row['group_id']]['id'] = $row['group_id'];
  1149. $vars['can_delete_checks'][$row['group_id']]['value'] = $row['group_title'];
  1150. $vars['can_delete_checks'][$row['group_id']]['checked'] = (in_array($row['group_id'], $can_delete_selected)) ? TRUE : FALSE;
  1151. $vars['can_delete'][$row['group_id']] = $row['group_title'];
  1152. }
  1153. }
  1154. // Get the selected 'excluded' group
  1155. $vars['exclude_selected'] = (isset($vars['exclude_group'])) ? $vars['exclude_group'] : FALSE;
  1156. $this->javascript->compile();
  1157. $this->load->view('admin/edit_category_group', $vars);
  1158. }
  1159. // --------------------------------------------------------------------
  1160. /**
  1161. * Update Category Group
  1162. *
  1163. * This function receives the submission from the group
  1164. * form and stores it in the database
  1165. *
  1166. * @access public
  1167. * @return void
  1168. */
  1169. function update_category_group()
  1170. {
  1171. $this->_restrict_prefs_access();
  1172. // If the $group_id variable is present we are editing an
  1173. // existing group, otherwise we are creating a new one
  1174. $edit = ($this->input->post('group_id') != '') ? TRUE : FALSE;
  1175. if ($this->input->post('group_name') == '')
  1176. {
  1177. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_management');
  1178. }
  1179. // this should never happen, but protect ourselves!
  1180. if ( ! isset($_POST['field_html_formatting']) OR ! in_array($_POST['field_html_formatting'], array('all', 'none', 'safe')))
  1181. {
  1182. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_management');
  1183. }
  1184. $this->lang->loadfile('admin_content');
  1185. // check for bad characters in group name
  1186. if ( ! preg_match("#^[a-zA-Z0-9_\-/\s]+$#i", $_POST['group_name']))
  1187. {
  1188. show_error(lang('illegal_characters'));
  1189. }
  1190. $this->load->model('category_model');
  1191. // Is the group name taken?
  1192. if ($this->category_model->is_duplicate_category_group($this->input->post('group_name'), $this->input->post('group_id')))
  1193. {
  1194. show_error(lang('taken_category_group_name'));
  1195. }
  1196. // make data array of variables from our POST data
  1197. $data = array();
  1198. foreach ($_POST as $key => $val)
  1199. {
  1200. // we can ignore some unwanted keys before INSERTing / UPDATEing
  1201. if (strpos($key, 'can_edit_categories_') !== FALSE OR strpos($key, 'can_delete_categories_') !== FALSE OR strpos($key, 'submit') !== FALSE)
  1202. {
  1203. continue;
  1204. }
  1205. $data[$key] = $val;
  1206. }
  1207. // Set our pipe delimited privileges for edit / delete
  1208. if (isset($data['can_edit_categories']) and is_array($data['can_edit_categories']))
  1209. {
  1210. $data['can_edit_categories'] = implode('|', $data['can_edit_categories']);
  1211. }
  1212. else
  1213. {
  1214. $data['can_edit_categories'] = '';
  1215. }
  1216. if (isset($data['can_delete_categories']) and is_array($data['can_delete_categories']))
  1217. {
  1218. $data['can_delete_categories'] = implode('|', $data['can_delete_categories']);
  1219. }
  1220. else
  1221. {
  1222. $data['can_delete_categories'] = '';
  1223. }
  1224. // Construct the query based on whether we are updating or inserting
  1225. if ($edit == FALSE)
  1226. {
  1227. $this->category_model->insert_category_group($data);
  1228. $cp_message = lang('category_group_created').' '.$data['group_name'];
  1229. $this->logger->log_action(lang('category_group_created').NBS.NBS.$data['group_name']);
  1230. $this->db->select('channel_id');
  1231. $this->db->where('site_id', $this->config->item('site_id'));
  1232. $query = $this->db->get('channels');
  1233. if ($query->num_rows() > 0)
  1234. {
  1235. $cp_message .= '<br />'.lang('assign_group_to_channel');
  1236. if ($query->num_rows() == 1)
  1237. {
  1238. $link = 'C=admin_content'.AMP.'M=channel_edit_group_assignments'.AMP.'channel_id='.$query->row('channel_id') ;
  1239. }
  1240. else
  1241. {
  1242. $link = 'C=admin_content'.AMP.'M=channel_management';
  1243. }
  1244. $cp_message .= '<br /><a href="'.BASE.AMP.$link.'">'. lang('click_to_assign_group').'</a>';
  1245. }
  1246. }
  1247. else
  1248. {
  1249. $this->category_model->update_category_group($data['group_id'], $data);
  1250. $cp_message = lang('category_group_updated').NBS.$data['group_name'];
  1251. }
  1252. $this->session->set_flashdata('message_success', $cp_message);
  1253. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_management');
  1254. }
  1255. // --------------------------------------------------------------------
  1256. /**
  1257. * Delete category group confirm
  1258. *
  1259. * Warning message if you try to delete a category group
  1260. *
  1261. * @access public
  1262. * @return mixed
  1263. */
  1264. function category_group_delete_conf()
  1265. {
  1266. $this->_restrict_prefs_access();
  1267. $group_id = $this->input->get_post('group_id');
  1268. if ($group_id == '' OR ! is_numeric($group_id))
  1269. {
  1270. show_error(lang('not_authorized'));
  1271. }
  1272. $this->lang->loadfile('admin_content');
  1273. $this->load->model('category_model');
  1274. $this->cp->set_variable('cp_page_title', lang('delete_group'));
  1275. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_management', lang('categories'));
  1276. $vars['form_action'] = 'C=admin_content'.AMP.'M=category_group_delete';
  1277. $vars['form_extra'] = '';
  1278. $vars['form_hidden']['group_id'] = $group_id;
  1279. $vars['message'] = lang('delete_cat_group_confirmation');
  1280. // Grab category_groups locations with this id
  1281. $items = $this->category_model->get_category_group_name($group_id);
  1282. $vars['items'] = array();
  1283. foreach($items->result() as $item)
  1284. {
  1285. $vars['items'][] = $item->group_name;
  1286. }
  1287. $this->javascript->compile();
  1288. $this->load->view('admin/preference_delete_confirm', $vars);
  1289. }
  1290. // --------------------------------------------------------------------
  1291. /**
  1292. * Delete category group
  1293. *
  1294. * This function deletes the category group and all associated categories
  1295. *
  1296. * @access public
  1297. * @return void
  1298. */
  1299. function category_group_delete()
  1300. {
  1301. $this->_restrict_prefs_access();
  1302. $group_id = $this->input->get_post('group_id');
  1303. if ($group_id == '' OR ! is_numeric($group_id))
  1304. {
  1305. show_error(lang('not_authorized'));
  1306. }
  1307. $this->lang->loadfile('admin_content');
  1308. $this->load->model('category_model');
  1309. $category = $this->category_model->get_category_group_name($group_id);
  1310. if ($category->num_rows() == 0)
  1311. {
  1312. show_error(lang('not_authorized'));
  1313. }
  1314. $name = $category->row('group_name');
  1315. // Delete from exp_category_posts
  1316. $this->category_model->delete_category_group($group_id);
  1317. $this->logger->log_action(lang('category_group_deleted').NBS.NBS.$name);
  1318. $this->functions->clear_caching('all', '', TRUE);
  1319. $this->session->set_flashdata('message_success', lang('category_group_deleted').NBS.NBS.$name);
  1320. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_management');
  1321. }
  1322. // --------------------------------------------------------------------
  1323. /**
  1324. * Category management page
  1325. *
  1326. * This function shows the list of current categories, as
  1327. * well as the form used to submit a new category
  1328. *
  1329. * @access public
  1330. * @return void
  1331. */
  1332. function category_editor($group_id = '', $update = FALSE)
  1333. {
  1334. if (AJAX_REQUEST)
  1335. {
  1336. $vars['EE_view_disable'] = TRUE;
  1337. if ( ! $this->cp->allowed_group('can_edit_categories'))
  1338. {
  1339. show_error(lang('unauthorized_access'));
  1340. }
  1341. }
  1342. else
  1343. {
  1344. $this->_restrict_prefs_access();
  1345. }
  1346. $this->lang->loadfile('admin_content');
  1347. $this->load->model('category_model');
  1348. $this->load->library('table');
  1349. $this->load->library('api');
  1350. $this->api->instantiate('channel_categories');
  1351. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_m…

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