PageRenderTime 64ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/system/expressionengine/controllers/cp/content_edit.php

https://bitbucket.org/tdevonshire/hoolux
PHP | 1910 lines | 1222 code | 396 blank | 292 comment | 197 complexity | 3535e089718c77de5ee97b573671773d 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 Content_edit extends CI_Controller {
  24. private $publish_base_uri;
  25. private $publish_base_url;
  26. private $edit_base_uri;
  27. private $edit_base_url;
  28. private $nest_categories = 'y';
  29. private $installed_modules = FALSE;
  30. private $allowed_channels = array();
  31. /**
  32. * Constructor
  33. */
  34. public function __construct()
  35. {
  36. parent::__construct();
  37. $this->installed_modules = $this->cp->get_installed_modules();
  38. $this->allowed_channels = $this->functions->fetch_assigned_channels();
  39. $this->publish_base_uri = 'C=content_publish';
  40. $this->publish_base_url = BASE.AMP.$this->publish_base_uri;
  41. $this->edit_base_uri = 'C=content_edit';
  42. $this->edit_base_url = BASE.AMP.$this->edit_base_uri;
  43. $this->load->library('api');
  44. $this->load->model('channel_model');
  45. }
  46. // --------------------------------------------------------------------
  47. /**
  48. * Index function
  49. *
  50. * @return void
  51. */
  52. public function index()
  53. {
  54. if ( ! $this->cp->allowed_group('can_access_content'))
  55. {
  56. show_error(lang('unauthorized_access'));
  57. }
  58. // Fetch channel ID numbers assigned to the current user
  59. if (empty($this->allowed_channels))
  60. {
  61. show_error(lang('no_channels'));
  62. }
  63. // Fetch channels
  64. // ----------------------------------------------------------------
  65. $this->api->instantiate('channel_structure');
  66. $channel_q = $this->api_channel_structure->get_channels();
  67. $channels = array();
  68. foreach($channel_q->result() as $c_row)
  69. {
  70. $channels[$c_row->channel_id] = $c_row;
  71. }
  72. // Set up Per page data
  73. // ----------------------------------------------------------------
  74. // Results per page pull-down menu
  75. if ( ! ($perpage = $this->input->get_post('perpage')))
  76. {
  77. $perpage = ($this->input->cookie('perpage') == FALSE) ? 50 : $this->input->cookie('perpage');
  78. }
  79. $this->functions->set_cookie('perpage' , $perpage, 60*60*24*182);
  80. // Table
  81. // ----------------------------------------------------------------
  82. $this->load->library('table');
  83. $columns = array(
  84. 'entry_id' => array('header' => '#', 'html' => FALSE),
  85. 'title' => array('header' => lang('title')),
  86. 'view' => array('header' => lang('view'), 'sort' => FALSE),
  87. 'comment_total' => array('header' => lang('comments')),
  88. 'screen_name' => array('header' => lang('author')),
  89. 'entry_date' => array('header' => lang('date')),
  90. 'channel_name' => array('header' => lang('channel')),
  91. 'status' => array('header' => lang('status')),
  92. '_check' => array(
  93. 'header' => form_checkbox('select_all', 'true', FALSE, 'class="toggle_all"'),
  94. 'sort' => FALSE
  95. )
  96. );
  97. if ( ! isset($this->installed_modules['comment']))
  98. {
  99. unset($columns['comment_total']);
  100. }
  101. $this->table->set_base_url($this->edit_base_uri);
  102. $this->table->set_columns($columns);
  103. $initial_state = array(
  104. 'sort' => array('entry_date' => 'desc')
  105. );
  106. $params = array(
  107. 'perpage' => $perpage,
  108. 'channels' => $channels,
  109. );
  110. $vars = $this->table->datasource('_table_datasource', $initial_state, $params);
  111. $filter_data = $vars['filter_data'];
  112. unset($vars['filter_data']);
  113. // Setup the form!
  114. // ----------------------------------------------------------------
  115. $form_fields = $this->_edit_form($filter_data, $channels);
  116. $vars = array_merge($vars, $form_fields);
  117. // Action Options!
  118. // ----------------------------------------------------------------
  119. $vars['action_options'] = array();
  120. if ( ! $this->input->post('toggle'))
  121. {
  122. $vars['action_options'] = array(
  123. 'edit' => lang('edit_selected'),
  124. 'delete' => lang('delete_selected'),
  125. '------' => '------',
  126. 'add_categories' => lang('add_categories'),
  127. 'remove_categories' => lang('remove_categories')
  128. );
  129. }
  130. // Assemble!
  131. // ----------------------------------------------------------------
  132. // Do we have a message to show?
  133. // Note: a message is displayed on this page after editing or submitting a new entry
  134. if ($this->input->get_post("U") == 'mu')
  135. {
  136. $vars['message'] = lang('multi_entries_updated');
  137. }
  138. // Declare the "filtering" form
  139. $vars['heading'] = 'edit_channel_entries';
  140. $vars['form_hidden'] = array();
  141. $vars['search_form'] = 'C=content_edit';
  142. $vars['entries_form'] = 'C=content_edit'.AMP.'M=multi_edit_form';
  143. $this->cp->set_variable('cp_page_title', lang('edit'));
  144. $this->cp->add_js_script(array(
  145. 'ui' => 'datepicker',
  146. 'file' => 'cp/content_edit'
  147. ));
  148. $this->javascript->set_global('autosave_map', $vars['autosave_array']);
  149. $this->javascript->compile();
  150. $this->load->view('content/edit', $vars);
  151. }
  152. // --------------------------------------------------------------------
  153. /**
  154. * Edit table datasource
  155. *
  156. * Must remain public so that it can be called from the
  157. * table library!
  158. *
  159. * @access public
  160. */
  161. public function _table_datasource($tbl_settings, $defaults)
  162. {
  163. // Get filter information
  164. // ----------------------------------------------------------------
  165. $keywords = (string) $this->input->post('keywords');
  166. $channel_id = (string) $this->input->get_post('channel_id');
  167. if ($channel_id == 'null')
  168. {
  169. $channel_id = NULL;
  170. }
  171. if ( ! $keywords)
  172. {
  173. $keywords = (string) $this->input->get('keywords');
  174. if ($keywords)
  175. {
  176. $keywords = base64_decode($keywords);
  177. }
  178. }
  179. if ($keywords)
  180. {
  181. $this->load->helper('search');
  182. $keywords = sanitize_search_terms($keywords);
  183. if (substr(strtolower($keywords), 0, 3) == 'ip:')
  184. {
  185. $keywords = str_replace('_','.',$keywords);
  186. }
  187. }
  188. // Because of the auto convert we prepare a specific variable with the converted ascii
  189. // characters while leaving the $keywords variable intact for display and URL purposes
  190. $this->load->helper('text');
  191. $search_keywords = ($this->config->item('auto_convert_high_ascii') == 'y') ? ascii_to_entities($keywords) : $keywords;
  192. $perpage = $this->input->get_post('perpage');
  193. $perpage = $perpage ? $perpage : $defaults['perpage'];
  194. $rownum = $tbl_settings['offset'];
  195. // We want the filter to work based on both get and post
  196. $filter_data = array(
  197. 'channel_id' => $channel_id,
  198. 'keywords' => $keywords,
  199. 'cat_id' => $this->input->get_post('cat_id'),
  200. 'status' => $this->input->get_post('status'),
  201. 'order' => $this->input->get_post('order'),
  202. 'date_range' => $this->input->get_post('date_range'),
  203. 'author_id' => $this->input->get_post('author_id'),
  204. 'exact_match' => $this->input->get_post('exact_match'),
  205. 'cat_id' => ($this->input->get_post('cat_id') != 'all') ? $this->input->get_post('cat_id') : '',
  206. 'search_in' => $this->input->get_post('search_in') ? $this->input->get_post('search_in') : 'title',
  207. 'rownum' => $rownum,
  208. 'perpage' => $perpage,
  209. 'search_keywords' => $search_keywords
  210. );
  211. $channels = $defaults['channels'];
  212. $order = $tbl_settings['sort'];
  213. $columns = $tbl_settings['columns'];
  214. // -------------------------------------------
  215. // 'edit_entries_additional_where' hook.
  216. // - Add additional where, where_in, where_not_in
  217. //
  218. $_hook_wheres = $this->extensions->call('edit_entries_additional_where', $filter_data);
  219. if ($this->extensions->end_script === TRUE) return;
  220. //
  221. // -------------------------------------------
  222. $filter_data['_hook_wheres'] = is_array($_hook_wheres) ? $_hook_wheres : array();
  223. $this->load->model('search_model');
  224. $filter_result = $this->search_model->get_filtered_entries($filter_data, $order);
  225. $rows = $filter_result['results'];
  226. $total = $filter_result['total_count'];
  227. unset($filter_result);
  228. $filter_url = $this->_create_return_filter($filter_data);
  229. // Gather up ids for a single quick query down the line
  230. $entry_ids = array();
  231. foreach ($rows as $row)
  232. {
  233. $entry_ids[] = $row['entry_id'];
  234. }
  235. // Load the site's templates
  236. // ----------------------------------------------------------------
  237. $templates = array();
  238. $tquery = $this->db->query("SELECT exp_template_groups.group_name, exp_templates.template_name, exp_templates.template_id
  239. FROM exp_template_groups, exp_templates
  240. WHERE exp_template_groups.group_id = exp_templates.group_id
  241. AND exp_templates.site_id = '".$this->db->escape_str($this->config->item('site_id'))."'");
  242. foreach ($tquery->result_array() as $row)
  243. {
  244. $templates[$row['template_id']] = $row['group_name'].'/'.$row['template_name'];
  245. }
  246. // Comment count
  247. // ----------------------------------------------------------------
  248. $show_link = TRUE;
  249. $comment_counts = array();
  250. if (count($entry_ids) AND $this->db->table_exists('comments'))
  251. {
  252. $comment_qry = $this->db->select('entry_id, COUNT(*) as count')
  253. ->where_in('entry_id', $entry_ids)
  254. ->group_by('entry_id')
  255. ->get('comments');
  256. foreach ($comment_qry->result() as $row)
  257. {
  258. $comment_counts[$row->entry_id] = $row->count;
  259. }
  260. }
  261. // Date formatting
  262. $date_fmt = ($this->session->userdata('time_format') != '') ? $this->session->userdata('time_format') : $this->config->item('time_format');
  263. $datestr = '%m/%d/%y %h:%i %a';
  264. if ($date_fmt != 'us')
  265. {
  266. $datestr = '%Y-%m-%d %H:%i';
  267. }
  268. // Autosave - Grab all autosaved entries
  269. // ----------------------------------------------------------------
  270. $this->prune_autosave();
  271. $this->db->select('entry_id, original_entry_id, channel_id, title, author_id, status, entry_date, dst_enabled, comment_total');
  272. $autosave = $this->db->get('channel_entries_autosave');
  273. $autosave_array = array();
  274. $autosave_show = FALSE;
  275. if ($autosave->num_rows())
  276. {
  277. $this->load->helper('snippets');
  278. $autosave_show = TRUE;
  279. }
  280. foreach ($autosave->result() as $entry)
  281. {
  282. if ($entry->original_entry_id)
  283. {
  284. $autosave_array[] = $entry->original_entry_id;
  285. }
  286. }
  287. // Status Highlight Colors
  288. // ----------------------------------------------------------------
  289. $status_color_q = $this->db->from('channels AS c, statuses AS s, status_groups AS sg')
  290. ->select('c.channel_id, c.channel_name, s.status, s.highlight')
  291. ->where('sg.group_id = c.status_group', NULL, FALSE)
  292. ->where('sg.group_id = s.group_id', NULL, FALSE)
  293. ->where('sg.site_id', $this->config->item('site_id'))
  294. ->where('s.highlight !=', '')
  295. ->where_in('c.channel_id', array_keys($channels))
  296. ->get();
  297. $c_array = array();
  298. foreach ($status_color_q->result_array() as $rez)
  299. {
  300. $c_array[$rez['channel_id'].'_'.$rez['status']] = str_replace('#', '', $rez['highlight']);
  301. }
  302. $colors = array();
  303. // Fetch Color Library
  304. if (file_exists(APPPATH.'config/colors.php'))
  305. {
  306. include (APPPATH.'config/colors.php');
  307. }
  308. // Generate row data
  309. // ----------------------------------------------------------------
  310. foreach ($rows as &$row)
  311. {
  312. $url = $this->publish_base_uri.AMP."M=entry_form".AMP."channel_id={$row['channel_id']}".AMP."entry_id={$row['entry_id']}".AMP.$filter_url;
  313. $row['title'] = anchor(BASE.AMP.$url, $row['title']);
  314. $row['view'] = '---';
  315. $row['channel_name'] = $channels[$row['channel_id']]->channel_title;
  316. $row['entry_date'] = $this->localize->decode_date($datestr, $row['entry_date'], TRUE);
  317. $row['_check'] = form_checkbox('toggle[]', $row['entry_id'], '', ' class="toggle" id="delete_box_'.$row['entry_id'].'"');
  318. // autosave indicator
  319. if (in_array($row['entry_id'], $autosave_array))
  320. {
  321. $row['title'] .= NBS.required();
  322. }
  323. // screen name email link
  324. if ( ! $row['screen_name'])
  325. {
  326. $row['screen_name'] = $row['username'];
  327. }
  328. $row['screen_name'] = mailto($row['email'], $row['screen_name']);
  329. // live look template
  330. $llt = $row['live_look_template'];
  331. if ($llt && isset($templates[$llt]))
  332. {
  333. $url = $this->functions->create_url($templates[$row['live_look_template']].'/'.$row['entry_id']);
  334. $row['view'] = anchor($this->cp->masked_url($url), lang('view'));
  335. }
  336. // Status
  337. $color_info = '';
  338. $color_key = $row['channel_id'].'_'.$row['status'];
  339. $status_name = ($row['status'] == 'open' OR $row['status'] == 'closed') ? lang($row['status']) : $row['status'];
  340. if (isset($c_array[$color_key]) AND $c_array[$color_key] != '')
  341. {
  342. $color = strtolower($c_array[$color_key]);
  343. $prefix = isset($colors[$color]) ? '' : '#';
  344. // There are custom colours, override the class above
  345. $color_info = 'style="color:'.$prefix.$color.';"';
  346. }
  347. $row['status'] = '<span class="status_'.$row['status'].'"'.$color_info.'>'.$status_name.'</span>';
  348. // comment_total link
  349. if (isset($this->installed_modules['comment']))
  350. {
  351. $all_or_own = 'all';
  352. if ($row['author_id'] == $this->session->userdata('member_id'))
  353. {
  354. $all_or_own = 'own';
  355. }
  356. // do not move these to the new allowed_group style - they are ANDs not ORs
  357. if ( ! $this->cp->allowed_group('can_edit_'.$all_or_own.'_comments') AND
  358. ! $this->cp->allowed_group('can_delete_'.$all_or_own.'_comments') AND
  359. ! $this->cp->allowed_group('can_moderate_comments'))
  360. {
  361. $row['comment_total'] = '<div class="lightLinks">--</div>';
  362. }
  363. else
  364. {
  365. $comment_count = isset($comment_counts[$row['entry_id']]) ? $comment_counts[$row['entry_id']] : 0;
  366. $view_url = BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=comment'.AMP.'method=index'.AMP.'entry_id='.$row['entry_id'];
  367. $row['comment_total'] = '<div class="lightLinks">('.$comment_count.')'.NBS.anchor($view_url, lang('view')).'</div>';
  368. }
  369. }
  370. $row = array_intersect_key($row, $columns);
  371. }
  372. // comes out with an added:
  373. // table_html
  374. // pagination_html
  375. return array(
  376. 'rows' => $rows,
  377. 'no_results' => lang('no_entries_matching_that_criteria'),
  378. 'pagination' => array(
  379. 'per_page' => $filter_data['perpage'],
  380. 'total_rows' => $total
  381. ),
  382. // used by index on non-ajax requests
  383. 'filter_data' => $filter_data,
  384. 'autosave_show' => $autosave_show,
  385. 'autosave_array' => $autosave_array
  386. );
  387. }
  388. // --------------------------------------------------------------------
  389. /**
  390. * Create Return Filter
  391. *
  392. * Creates a properly format variable to pass in the url indicating the filter state
  393. *
  394. * @access protected
  395. * @param array
  396. * @return string
  397. */
  398. protected function _create_return_filter($filter_data)
  399. {
  400. $filter = '';
  401. $filters = array();
  402. $filter_keys = array('channel_id', 'cat_id', 'status', 'date_range', 'keywords', 'exact_match', 'search_in');
  403. foreach($filter_keys as $k)
  404. {
  405. if ( isset($filter_data[$k]) && $filter_data[$k] != '')
  406. {
  407. $filters[$k] = $filter_data[$k];
  408. }
  409. }
  410. if ( ! isset($filters['keywords']))
  411. {
  412. unset($filters['exact_match']);
  413. unset($filters['search_in']);
  414. }
  415. if ( ! empty($filters))
  416. {
  417. $filter = AMP.'filter='.base64_encode(serialize($filters));
  418. }
  419. return $filter;
  420. }
  421. // --------------------------------------------------------------------
  422. /**
  423. * Multi edit form
  424. */
  425. public function multi_edit_form()
  426. {
  427. if ( ! $this->cp->allowed_group('can_access_content'))
  428. {
  429. show_error(lang('unauthorized_access'));
  430. }
  431. if ( ! in_array($this->input->post('action'), array('edit', 'delete', 'add_categories', 'remove_categories')))
  432. {
  433. show_error(lang('unauthorized_access'));
  434. }
  435. $this->load->library('table');
  436. if ( ! $this->input->post('toggle'))
  437. {
  438. return $this->index();
  439. }
  440. if ($this->input->post('action') == 'delete')
  441. {
  442. return $this->delete_entries_confirm();
  443. }
  444. $this->cp->add_js_script('ui', 'datepicker');
  445. // -----------------------------
  446. // Fetch the entry IDs
  447. // -----------------------------
  448. $entry_ids = $this->input->post('toggle');
  449. // Are there still any entry IDs at this point?
  450. // If not, we'll show an unauthorized message.
  451. if (count($entry_ids) == 0)
  452. {
  453. show_error(lang('unauthorized_to_edit'));
  454. }
  455. // -----------------------------
  456. // Build and run the query
  457. // -----------------------------
  458. $this->db->select('entry_id, exp_channel_titles.channel_id, author_id, title, url_title, entry_date, dst_enabled, status, allow_comments, sticky, comment_system_enabled');
  459. $this->db->from('exp_channel_titles');
  460. $this->db->join('exp_channels', 'exp_channels.channel_id = exp_channel_titles.channel_id');
  461. $this->db->where_in('exp_channel_titles.entry_id', $entry_ids);
  462. $this->db->order_by("entry_date", "desc");
  463. $query = $this->db->get();
  464. // -----------------------------
  465. // Security check...
  466. //
  467. // Before we show anything we have to make sure that the user is allowed to
  468. // access the channel the entry is in, and if the user is trying
  469. // to edit an entry authored by someone else they are allowed to
  470. // -----------------------------
  471. $disallowed_ids = array();
  472. foreach ($query->result_array() as $row)
  473. {
  474. if ( ! in_array($row['channel_id'], $this->allowed_channels))
  475. {
  476. $disallowed_ids = $row['entry_id'];
  477. }
  478. if ($row['author_id'] != $this->session->userdata('member_id'))
  479. {
  480. if ( ! $this->cp->allowed_group('can_edit_other_entries'))
  481. {
  482. $disallowed_ids = $row['entry_id'];
  483. }
  484. }
  485. if (count($disallowed_ids) > 0)
  486. {
  487. $disallowed_ids = array_unique($disallowed_ids);
  488. }
  489. }
  490. // Are there disallowed posts? If so, we have to remove them....
  491. if (count($disallowed_ids) > 0)
  492. {
  493. $new_ids = array_diff($entry_ids, $disallowed_ids);
  494. // After removing the disallowed entry IDs are there any left?
  495. if (count($new_ids) == 0)
  496. {
  497. show_error(lang('unauthorized_to_edit'));
  498. }
  499. unset($query);
  500. // Run the query one more time with the proper IDs.
  501. $this->db->select('entry_id, exp_channel_titles.channel_id, author_id, title, url_title, entry_date, dst_enabled, status, allow_comments, sticky, comment_system_enabled');
  502. $this->db->from('exp_channel_titles');
  503. $this->db->join('exp_channels', 'exp_channels.channel_id = exp_channel_titles.channel_id');
  504. $this->db->where_in('exp_channel_titles.entry_id', $new_ids);
  505. $this->db->order_by("entry_date", "desc");
  506. $query = $this->db->get();
  507. }
  508. // -----------------------------
  509. // Adding/Removing of Categories Breaks Off to Their Own Function
  510. // -----------------------------
  511. if ($this->input->post('action') == 'add_categories')
  512. {
  513. return $this->multi_categories_edit('add', $query);
  514. }
  515. elseif ($this->input->post('action') == 'remove_categories')
  516. {
  517. return $this->multi_categories_edit('remove', $query);
  518. }
  519. // Fetch the channel preferences
  520. // We need these in order to fetch the status groups and options.
  521. $channel_ids = array();
  522. foreach ($query->result_array() as $row)
  523. {
  524. $channel_ids[] = $row['channel_id'];
  525. }
  526. $this->db->select('channel_id, status_group, deft_status');
  527. $this->db->where_in('channel_id', $channel_ids);
  528. $channel_query = $this->db->get('channels');
  529. // Fetch disallowed statuses
  530. $no_status_access = array();
  531. if ($this->session->userdata['group_id'] != 1)
  532. {
  533. $this->db->select('status_id');
  534. $this->db->from('exp_status_no_access');
  535. $this->db->where('member_group', $this->session->userdata('group_id'));
  536. $result = $this->db->get();
  537. foreach ($result->result_array() as $row)
  538. {
  539. $no_status_access[] = $row['status_id'];
  540. }
  541. }
  542. $vars['form_hidden'] = array();
  543. if (isset($_POST['pageurl']))
  544. {
  545. $vars['form_hidden']['redirect'] = $this->security->xss_clean($_POST['pageurl']);
  546. }
  547. // used in date field
  548. $this->javascript->output('
  549. date_obj = new Date();
  550. date_obj_hours = date_obj.getHours();
  551. date_obj_mins = date_obj.getMinutes();
  552. if (date_obj_mins < 10) { date_obj_mins = "0" + date_obj_mins; }
  553. if (date_obj_hours > 11) {
  554. date_obj_hours = date_obj_hours - 12;
  555. date_obj_am_pm = " PM";
  556. } else {
  557. date_obj_am_pm = " AM";
  558. }
  559. date_obj_time = " \'"+date_obj_hours+":"+date_obj_mins+date_obj_am_pm+"\'";
  560. ');
  561. $vars['entries'] = $query;
  562. foreach ($query->result_array() as $row)
  563. {
  564. $entry_id = $row['entry_id'];
  565. $vars['form_hidden']["entry_id[$entry_id]"] = $entry_id;
  566. $vars['form_hidden']["channel_id[$entry_id]"] = $row['channel_id'];
  567. // Status pull-down menu
  568. $vars['entries_status'][$entry_id] = array();
  569. $vars['entries_selected'][$entry_id] = $row['status'];
  570. foreach ($channel_query->result_array() as $channel_row)
  571. {
  572. if ($channel_row['channel_id'] != $row['channel_id'])
  573. {
  574. continue;
  575. }
  576. $this->db->where('group_id', $channel_row['status_group']);
  577. $this->db->order_by('status_order');
  578. $status_query = $this->db->get('statuses');
  579. if ($status_query->num_rows() == 0)
  580. {
  581. // if there is no status group assigned, only Super Admins can create 'open' entries
  582. if ($this->session->userdata['group_id'] == 1)
  583. {
  584. $vars['entries_status'][$entry_id]['open'] = lang('open');
  585. }
  586. $vars['entries_status'][$entry_id]['closed'] = lang('closed');
  587. }
  588. else
  589. {
  590. $no_status_flag = TRUE;
  591. foreach ($status_query->result_array() as $status_row)
  592. {
  593. if (in_array($status_row['status_id'], $no_status_access))
  594. {
  595. continue;
  596. }
  597. $no_status_flag = FALSE;
  598. $status_name = ($status_row['status'] == 'open' OR $status_row['status'] == 'closed') ? lang($status_row['status']) : form_prep($status_row['status']);
  599. $vars['entries_status'][$entry_id][form_prep($status_row['status'])] = $status_name;
  600. }
  601. // Were there no statuses? If the current user is not allowed
  602. // to submit any statuses we'll set the default to closed
  603. if ($no_status_flag == TRUE)
  604. {
  605. $vars['entries_status'][$entry_id]['closed'] = lang('closed');
  606. }
  607. }
  608. }
  609. // Set up date js
  610. $this->javascript->output('
  611. $(".entry_date_'.$entry_id.'").datepicker({constrainInput: false, dateFormat: $.datepicker.W3C + date_obj_time, defaultDate: new Date('.($this->localize->set_localized_time($row['entry_date']) * 1000).')});
  612. ');
  613. // Sticky
  614. $vars['options'][$entry_id]['sticky'] = array();
  615. $vars['options'][$entry_id]['sticky']['name'] = 'sticky['.$row['entry_id'].']';
  616. $vars['options'][$entry_id]['sticky']['value'] = 'y';
  617. $vars['options'][$entry_id]['sticky']['checked'] = ($row['sticky'] == 'y') ? TRUE : FALSE;
  618. $vars['options'][$entry_id]['sticky']['style'] = 'width: auto!important;';
  619. // Allow Comments
  620. $vars['options'][$entry_id]['allow_comments'] = array();
  621. if ( ! isset($this->installed_modules['comment']) OR $row['comment_system_enabled'] == 'n')
  622. {
  623. $vars['form_hidden']["allow_comments[$entry_id]"] = $row['allow_comments'];
  624. }
  625. else
  626. {
  627. $vars['options'][$entry_id]['allow_comments']['name'] = 'allow_comments['.$row['entry_id'].']';
  628. $vars['options'][$entry_id]['allow_comments']['value'] = 'y';
  629. $vars['options'][$entry_id]['allow_comments']['checked'] = ($row['allow_comments'] == 'y') ? TRUE : FALSE;
  630. $vars['options'][$entry_id]['allow_comments']['style'] = 'width: auto!important;';
  631. }
  632. }
  633. $this->javascript->compile();
  634. $this->cp->set_variable('cp_page_title', lang('multi_entry_editor'));
  635. // A bit of a breadcrumb override is needed
  636. $this->cp->set_variable('cp_breadcrumbs', array(
  637. BASE.AMP.'C=content' => lang('content'),
  638. BASE.AMP.'C=content_edit'=> lang('edit')
  639. ));
  640. $this->load->view('content/multi_edit', $vars);
  641. }
  642. // --------------------------------------------------------------------
  643. /**
  644. * List Autosaved Entries
  645. *
  646. * @access public
  647. */
  648. public function autosaved()
  649. {
  650. $this->prune_autosave();
  651. $this->load->library('table');
  652. $data['entries'] = array();
  653. $data['cp_page_title'] = lang('autosaved_entries');
  654. $data['table_headings'] = array(
  655. lang('autosaved'),
  656. lang('original'),
  657. lang('channel'),
  658. lang('discard_autosave')
  659. );
  660. $autosave_q = $this->db->select('cea.channel_id, cea.entry_id, cea.original_entry_id, cea.title, c.channel_title')
  661. ->from('channel_entries_autosave as cea')
  662. ->order_by('cea.original_entry_id', 'ASC')
  663. ->where_in('cea.channel_id', $this->allowed_channels)
  664. ->join('channels c', 'cea.channel_id = c.channel_id')
  665. ->get();
  666. foreach($autosave_q->result() as $row)
  667. {
  668. $channel = $row->channel_id;
  669. $save_id = $row->entry_id;
  670. $orig_id = $row->original_entry_id;
  671. $data['entries'][] = array(
  672. anchor(
  673. BASE.AMP.'C=content_publish'.AMP.'M=entry_form'.AMP.'channel_id='.$channel.AMP.'entry_id='.$save_id.AMP.'use_autosave=y',
  674. $row->title
  675. ),
  676. $orig_id ? anchor(BASE.AMP.'C=content_publish'.AMP.'M=entry_form'.AMP.'channel_id='.$channel.AMP.'entry_id='.$orig_id, $row->title) : '--',
  677. $row->channel_title,
  678. anchor(BASE.AMP.'C=content_edit'.AMP.'M=autosaved_discard'.AMP.'id='.$save_id, lang('delete'))
  679. );
  680. }
  681. $this->cp->set_breadcrumb($this->edit_base_url, lang('edit'));
  682. $this->load->view('content/autosave', $data);
  683. }
  684. // --------------------------------------------------------------------
  685. /**
  686. * Delete Autosave Data
  687. *
  688. * @access public
  689. */
  690. function autosaved_discard()
  691. {
  692. $id = $this->input->get_post('id');
  693. $qry = $this->db->select('author_id, channel_id')
  694. ->order_by('original_entry_id', 'ASC')
  695. ->get_where('channel_entries_autosave', array('entry_id' => $id));
  696. if ($qry->num_rows() != 1)
  697. {
  698. show_error(lang('unauthorized_access'));
  699. }
  700. $row = $qry->row();
  701. $can_delete = TRUE;
  702. // Check permissions
  703. if ($this->session->userdata('group_id') != 1)
  704. {
  705. if ( ! in_array($row['channel_id'], $this->allowed_channels))
  706. {
  707. $can_delete = FALSE;
  708. }
  709. }
  710. if ($row->author_id == $this->session->userdata('member_id'))
  711. {
  712. if ($this->session->userdata('can_delete_self_entries') != 'y')
  713. {
  714. $can_delete = FALSE;
  715. }
  716. }
  717. else
  718. {
  719. if ($this->session->userdata('can_delete_all_entries') != 'y')
  720. {
  721. $can_delete = FALSE;
  722. }
  723. }
  724. if ( ! $can_delete)
  725. {
  726. show_error(lang('unauthorized_access'));
  727. }
  728. $this->db->where('entry_id', $id)->delete('channel_entries_autosave');
  729. $this->functions->redirect($this->edit_base_url.AMP.'M=autosaved');
  730. }
  731. // --------------------------------------------------------------------
  732. /**
  733. * Prune Autosaved Data
  734. *
  735. * @access public
  736. */
  737. function prune_autosave()
  738. {
  739. // default to pruning every 6 hours
  740. $autosave_prune = ($this->config->item('autosave_prune_hours') === FALSE) ?
  741. 6 : $this->config->item('autosave_prune_hours');
  742. // Convert to seconds
  743. $autosave_prune = $autosave_prune * 60 * 60;
  744. $cutoff_date = time();
  745. $cutoff_date -= $autosave_prune;
  746. $cutoff_date = date("YmdHis", $cutoff_date);
  747. $this->db->where('edit_date <', $cutoff_date)->delete('channel_entries_autosave');
  748. }
  749. // --------------------------------------------------------------------
  750. /**
  751. * Update multi entries
  752. */
  753. public function update_multi_entries()
  754. {
  755. if ( ! $this->cp->allowed_group('can_access_content'))
  756. {
  757. show_error(lang('unauthorized_access'));
  758. }
  759. if ( ! is_array($_POST['entry_id']))
  760. {
  761. show_error(lang('unauthorized_access'));
  762. }
  763. /* -------------------------------------------
  764. /* 'update_multi_entries_start' hook.
  765. /* - Perform additional actions before entries are updated
  766. */
  767. $edata = $this->extensions->call('update_multi_entries_start');
  768. if ($this->extensions->end_script === TRUE) return;
  769. /*
  770. /* -------------------------------------------*/
  771. $channel_ids = array();
  772. // Outside the for loop so seconds are consistent
  773. $edit_date = gmdate("YmdHis");
  774. foreach ($_POST['entry_id'] as $id)
  775. {
  776. $channel_id = $_POST['channel_id'][$id];
  777. // Remember channels we've touched so we can update stats at the end
  778. $channel_ids[] = intval($channel_id);
  779. $data = array(
  780. 'title' => strip_tags($_POST['title'][$id]),
  781. 'url_title' => $_POST['url_title'][$id],
  782. 'entry_date' => $_POST['entry_date'][$id],
  783. 'edit_date' => $edit_date,
  784. 'status' => $_POST['status'][$id],
  785. 'sticky' => (isset($_POST['sticky'][$id]) AND $_POST['sticky'][$id] == 'y') ? 'y' : 'n',
  786. 'allow_comments' => (isset($_POST['allow_comments'][$id]) AND $_POST['allow_comments'][$id] == 'y') ? 'y' : 'n'
  787. );
  788. $error = array();
  789. // No entry title? Assign error.
  790. if ($data['title'] == "")
  791. {
  792. $error[] = lang('missing_title');
  793. }
  794. // Is the title unique?
  795. if ($data['title'] != '')
  796. {
  797. // Do we have a URL title?
  798. // If not, create one from the title
  799. $word_separator = $this->config->item('word_separator');
  800. if ($data['url_title'] == '')
  801. {
  802. $data['url_title'] = url_title($data['title'], $word_separator, TRUE);
  803. }
  804. else
  805. {
  806. $data['url_title'] = url_title($data['url_title'], $word_separator);
  807. }
  808. // Is the url_title a pure number? If so we show an error.
  809. if (is_numeric($data['url_title']))
  810. {
  811. $error[] = lang('url_title_is_numeric');
  812. }
  813. // Is URL title unique?
  814. $unique = FALSE;
  815. $i = 0;
  816. while ($unique == FALSE)
  817. {
  818. $temp = ($i == 0) ? $data['url_title'] : $data['url_title'].$i;
  819. $i++;
  820. $sql = "SELECT count(*) AS count FROM exp_channel_titles WHERE url_title = '".$this->db->escape_str($temp)."' AND channel_id = '".$this->db->escape_str($channel_id)."'";
  821. if ($id != '')
  822. {
  823. $sql .= " AND entry_id != '".$this->db->escape_str($id)."'";
  824. }
  825. $query = $this->db->query($sql);
  826. if ($query->row('count') == 0)
  827. {
  828. $unique = TRUE;
  829. }
  830. // Safety
  831. if ($i >= 50)
  832. {
  833. $error[] = lang('url_title_not_unique');
  834. break;
  835. }
  836. }
  837. $data['url_title'] = $temp;
  838. }
  839. // No date? Assign error.
  840. if ($data['entry_date'] == '')
  841. {
  842. $error[] = lang('missing_date');
  843. }
  844. // Convert the date to a Unix timestamp
  845. $data['entry_date'] = $this->localize->convert_human_date_to_gmt($data['entry_date']);
  846. if ( ! is_numeric($data['entry_date']))
  847. {
  848. // Localize::convert_human_date_to_gmt() returns verbose errors
  849. if ($data['entry_date'] !== FALSE)
  850. {
  851. $error[] = $data['entry_date'];
  852. }
  853. else
  854. {
  855. $error[] = lang('invalid_date_formatting');
  856. }
  857. }
  858. // Do we have an error to display?
  859. if (count($error) > 0)
  860. {
  861. $msg = '';
  862. foreach($error as $val)
  863. {
  864. $msg .= '<div class="itemWrapper">'.$val.'</div>';
  865. }
  866. return show_error($msg);
  867. }
  868. // Day, Month, and Year Fields
  869. $data['year'] = $this->localize->decode_date('%Y', $data['entry_date'], TRUE);
  870. $data['month'] = $this->localize->decode_date('%m', $data['entry_date'], TRUE);
  871. $data['day'] = $this->localize->decode_date('%d', $data['entry_date'], TRUE);
  872. // Update the entry
  873. $this->db->query($this->db->update_string('exp_channel_titles', $data, "entry_id = '$id'"));
  874. /* -------------------------------------------
  875. /* 'update_multi_entries_loop' hook.
  876. /* - Perform additional actions after each entry is updated
  877. */
  878. $edata = $this->extensions->call('update_multi_entries_loop', $id, $data);
  879. if ($this->extensions->end_script === TRUE) return;
  880. /*
  881. /* -------------------------------------------*/
  882. }
  883. // Clear caches if needed
  884. $entry_ids = "'";
  885. foreach($_POST['entry_id'] as $id)
  886. {
  887. $entry_ids .= $this->db->escape_str($id)."', '";
  888. }
  889. $entry_ids = substr($entry_ids, 0, -3);
  890. $query = $this->db->query("SELECT COUNT(*) AS count FROM exp_relationships
  891. WHERE rel_parent_id IN ({$entry_ids})
  892. OR rel_child_id IN ({$entry_ids})");
  893. $clear_rel = ($query->row('count') > 0) ? TRUE : FALSE;
  894. if ($this->config->item('new_posts_clear_caches') == 'y')
  895. {
  896. $this->functions->clear_caching('all', '', $clear_rel);
  897. }
  898. else
  899. {
  900. $this->functions->clear_caching('sql', '', $clear_rel);
  901. }
  902. // Update each modified channel's stats. Might want to get update_channel_stats()
  903. // to accept an array so we can avoid looping here.
  904. foreach(array_unique($channel_ids) as $id)
  905. {
  906. $this->stats->update_channel_stats($id);
  907. }
  908. $this->session->set_flashdata('message_success', lang('multi_entries_updated'));
  909. if (isset($_POST['redirect']) && ($redirect = base64_decode($this->security->xss_clean($_POST['redirect']))) !== FALSE)
  910. {
  911. $this->functions->redirect($this->security->xss_clean($redirect));
  912. }
  913. else
  914. {
  915. $this->functions->redirect($this->edit_base_url);
  916. }
  917. }
  918. // --------------------------------------------------------------------
  919. /**
  920. * multi categories edit form
  921. */
  922. public function multi_categories_edit($type, $query)
  923. {
  924. if ( ! $this->cp->allowed_group('can_access_content'))
  925. {
  926. show_error(lang('unauthorized_access'));
  927. }
  928. if ($query->num_rows() == 0)
  929. {
  930. show_error(lang('unauthorized_to_edit'));
  931. }
  932. /** -----------------------------
  933. /** Fetch the cat_group
  934. /** -----------------------------*/
  935. /* Available from $query: entry_id, channel_id, author_id, title, url_title,
  936. entry_date, dst_enabled, status, allow_comments,
  937. sticky
  938. */
  939. $sql = "SELECT DISTINCT cat_group FROM exp_channels WHERE channel_id IN(";
  940. $channel_ids = array();
  941. $entry_ids = array();
  942. foreach ($query->result_array() as $row)
  943. {
  944. $channel_ids[] = $row['channel_id'];
  945. $entry_ids[] = $row['entry_id'];
  946. $sql .= $row['channel_id'].',';
  947. }
  948. $group_query = $this->db->query(substr($sql, 0, -1).')');
  949. $valid = 'n';
  950. if ($group_query->num_rows() > 0)
  951. {
  952. $valid = 'y';
  953. $last = explode('|', $group_query->row('cat_group'));
  954. foreach($group_query->result_array() as $row)
  955. {
  956. $valid_cats = array_intersect($last, explode('|', $row['cat_group']));
  957. if (count($valid_cats) == 0)
  958. {
  959. $valid = 'n';
  960. break;
  961. }
  962. }
  963. }
  964. if ($valid == 'n')
  965. {
  966. show_error(lang('no_category_group_match'));
  967. }
  968. $this->api->instantiate('channel_categories');
  969. $this->api_channel_categories->category_tree(($cat_group = implode('|', $valid_cats)));
  970. //print_r($this->api_channel_categories->categories);
  971. $vars['cats'] = array();
  972. $vars['message'] = '';
  973. if (count($this->api_channel_categories->categories) == 0)
  974. {
  975. $vars['message'] = lang('no_categories');
  976. }
  977. else
  978. {
  979. foreach ($this->api_channel_categories->categories as $val)
  980. {
  981. $vars['cats'][$val['3']][] = $val;
  982. }
  983. }
  984. $vars['edit_categories_link'] = FALSE; //start off as false, meaning user does not have privs
  985. $link_info = $this->api_channel_categories->fetch_allowed_category_groups($cat_group);
  986. $links = FALSE;
  987. if ($link_info !== FALSE)
  988. {
  989. foreach ($link_info as $val)
  990. {
  991. $links[] = array('url' => BASE.AMP.'C=admin_content'.AMP.'M=category_editor'.AMP.'group_id='.$val['group_id'],
  992. 'group_name' => $val['group_name']);
  993. }
  994. }
  995. $vars['edit_categories_link'] = $links;
  996. $this->cp->set_breadcrumb($this->edit_base_url, lang('edit'));
  997. $vars['form_hidden'] = array();
  998. $vars['form_hidden']['entry_ids'] = implode('|', $entry_ids);
  999. $vars['form_hidden']['type'] = $type;
  1000. $vars['type'] = $type;
  1001. $this->cp->set_variable('cp_page_title', lang('multi_entry_category_editor'));
  1002. $this->javascript->compile();
  1003. $this->load->view('content/multi_cat_edit', $vars);
  1004. }
  1005. // --------------------------------------------------------------------
  1006. /**
  1007. * Update Multiple Entries with Categories
  1008. */
  1009. public function multi_entry_category_update()
  1010. {
  1011. if ( ! $this->cp->allowed_group('can_access_content'))
  1012. {
  1013. show_error(lang('unauthorized_access'));
  1014. }
  1015. if ($this->input->get_post('entry_ids') === FALSE OR $this->input->get_post('type') === FALSE)
  1016. {
  1017. show_error(lang('unauthorized_to_edit'));
  1018. }
  1019. if ($this->input->get_post('category') === FALSE OR ! is_array($_POST['category']) OR count($_POST['category']) == 0)
  1020. {
  1021. return $this->output->show_user_error('submission', lang('no_categories_selected'));
  1022. }
  1023. /** ---------------------------------
  1024. /** Fetch categories
  1025. /** ---------------------------------*/
  1026. // We do this first so we can destroy the category index from
  1027. // the $_POST array since we use a separate table to store categories in
  1028. $this->api->instantiate('channel_categories');
  1029. foreach ($_POST['category'] as $cat_id)
  1030. {
  1031. $this->api_channel_categories->cat_parents[] = $cat_id;
  1032. }
  1033. if ($this->api_channel_categories->assign_cat_parent == TRUE)
  1034. {
  1035. $this->api_channel_categories->fetch_category_parents($_POST['category']);
  1036. }
  1037. $this->api_channel_categories->cat_parents = array_unique($this->api_channel_categories->cat_parents);
  1038. sort($this->api_channel_categories->cat_parents);
  1039. unset($_POST['category']);
  1040. $ids = array();
  1041. foreach (explode('|', $_POST['entry_ids']) as $entry_id)
  1042. {
  1043. $ids[] = $this->db->escape_str($entry_id);
  1044. }
  1045. unset($_POST['entry_ids']);
  1046. $entries_string = implode("','", $ids);
  1047. /** -----------------------------
  1048. /** Get Category Group IDs
  1049. /** -----------------------------*/
  1050. $query = $this->db->query("SELECT DISTINCT exp_channels.cat_group FROM exp_channels, exp_channel_titles
  1051. WHERE exp_channel_titles.channel_id = exp_channels.channel_id
  1052. AND exp_channel_titles.entry_id IN ('".$entries_string."')");
  1053. $valid = 'n';
  1054. if ($query->num_rows() > 0)
  1055. {
  1056. $valid = 'y';
  1057. $last = explode('|', $query->row('cat_group') );
  1058. foreach($query->result_array() as $row)
  1059. {
  1060. $valid_cats = array_intersect($last, explode('|', $row['cat_group']));
  1061. if (count($valid_cats) == 0)
  1062. {
  1063. $valid = 'n';
  1064. break;
  1065. }
  1066. }
  1067. }
  1068. if ($valid == 'n')
  1069. {
  1070. return $this->output->show_user_error('submission', lang('no_category_group_match'));
  1071. }
  1072. /** -----------------------------
  1073. /** Remove Valid Cats, Then Add...
  1074. /** -----------------------------*/
  1075. $valid_cat_ids = array();
  1076. $query = $this->db->query("SELECT cat_id FROM exp_categories
  1077. WHERE group_id IN ('".implode("','", $valid_cats)."')
  1078. AND cat_id IN ('".implode("','", $this->api_channel_categories->cat_parents)."')");
  1079. foreach($query->result_array() as $row)
  1080. {
  1081. $this->db->query("DELETE FROM exp_category_posts WHERE cat_id = ".$row['cat_id']." AND entry_id IN ('".$entries_string."')");
  1082. $valid_cat_ids[] = $row['cat_id'];
  1083. }
  1084. if ($this->input->get_post('type') == 'add')
  1085. {
  1086. $insert_cats = array_intersect($this->api_channel_categories->cat_parents, $valid_cat_ids);
  1087. // How brutish...
  1088. foreach($ids as $id)
  1089. {
  1090. foreach($insert_cats as $val)
  1091. {
  1092. $this->db->query($this->db->insert_string('exp_category_posts', array('entry_id' => $id, 'cat_id' => $val)));
  1093. }
  1094. }
  1095. }
  1096. /** ---------------------------------
  1097. /** Clear caches if needed
  1098. /** ---------------------------------*/
  1099. if ($this->config->item('new_posts_clear_caches') == 'y')
  1100. {
  1101. $this->functions->clear_caching('all');
  1102. }
  1103. else
  1104. {
  1105. $this->functions->clear_caching('sql');
  1106. }
  1107. $this->session->set_flashdata('message_success', lang('multi_entries_updated'));
  1108. $this->functions->redirect($this->edit_base_url);
  1109. }
  1110. // --------------------------------------------------------------------
  1111. /**
  1112. * Delete entries confirm
  1113. */
  1114. public function delete_entries_confirm()
  1115. {
  1116. if ( ! $this->cp->allowed_group('can_access_content'))
  1117. {
  1118. show_error(lang('unauthorized_access'));
  1119. }
  1120. if ( ! $this->cp->allowed_group('can_delete_self_entries') AND
  1121. ! $this->cp->allowed_group('can_delete_all_entries'))
  1122. {
  1123. show_error(lang('unauthorized_access'));
  1124. }
  1125. if ( ! $this->input->post('toggle'))
  1126. {
  1127. redirect(BASE.'content_edit');
  1128. }
  1129. $damned = array();
  1130. foreach ($_POST['toggle'] as $key => $val)
  1131. {
  1132. if ($val != '')
  1133. {
  1134. $damned[] = $val;
  1135. }
  1136. }
  1137. // Pass the damned on for judgement
  1138. $vars['damned'] = $damned;
  1139. if (count($damned) == 1)
  1140. {
  1141. $vars['message'] = lang('delete_entry_confirm');
  1142. }
  1143. else
  1144. {
  1145. $vars['message'] = lang('delete_entries_confirm');
  1146. }
  1147. $vars['title_deleted_entry'] = '';
  1148. // if it's just one entry, let's be kind and show a title
  1149. if (count($_POST['toggle']) == 1)
  1150. {
  1151. $query = $this->db->query('SELECT title FROM exp_channel_titles WHERE entry_id = "'.$this->db->escape_str($_POST['toggle'][0]).'"');
  1152. if ($query->num_rows() == 1)
  1153. {
  1154. $vars['title_deleted_entry'] = str_replace('%title', $query->row('title') , lang('entry_title_with_title'));
  1155. }
  1156. }
  1157. $this->cp->set_variable('cp_page_title', lang('delete_confirm'));
  1158. $this->javascript->compile();
  1159. $this->load->view('content/delete_confirm', $vars);
  1160. }
  1161. // --------------------------------------------------------------------
  1162. /**
  1163. * Delete entries
  1164. */
  1165. public function delete_entries()
  1166. {
  1167. if ( ! $this->cp->allowed_group('can_access_content'))
  1168. {
  1169. show_error(lang('unauthorized_access'));
  1170. }
  1171. if ( ! $this->cp->allowed_group('can_delete_self_entries') AND
  1172. ! $this->cp->allowed_group('can_delete_all_entries'))
  1173. {
  1174. show_error(lang('unauthorized_access'));
  1175. }
  1176. if ( ! $this->input->post('delete'))
  1177. {
  1178. $this->session->set_flashdata('message_failure', lang('no_valid_selections'));
  1179. $this->functions->redirect($this->edit_base_url);
  1180. }
  1181. /* -------------------------------------------
  1182. /* 'delete_entries_start' hook.
  1183. /* - Perform actions prior to entry deletion / take over deletion
  1184. */
  1185. $edata = $this->extensions->call('delete_entries_start');
  1186. if ($this->extensions->end_script === TRUE) return;
  1187. /*
  1188. /* -------------------------------------------*/
  1189. $this->api->instantiate('channel_entries');
  1190. $res = $this->api_channel_entries->delete_entry($this->input->post('delete'));
  1191. if ($res === FALSE)
  1192. {
  1193. $this->session->set_flashdata('message_failure', lang('no_valid_selections'));
  1194. $this->functions->redirect($this->edit_base_url);
  1195. }
  1196. // Return success message
  1197. $this->session->set_flashdata('message_success', lang('entries_deleted'));
  1198. $this->functions->redirect($this->edit_base_url);
  1199. }
  1200. // --------------------------------------------------------------------
  1201. /**
  1202. * JavaScript filtering code
  1203. *
  1204. * This function writes some JavaScript functions that
  1205. * are used to switch the various pull-down menus in the
  1206. * EDIT page
  1207. *
  1208. * @access protected
  1209. */
  1210. protected function _filtering_menus($cat_form_array)
  1211. {
  1212. // In order to build our filtering options we need to gather
  1213. // all the channels, categories and custom statuses
  1214. $channel_array = array();
  1215. $status_array = array();
  1216. $this->api->instantiate('channel_categories');
  1217. if (count($this->allowed_channels) > 0)
  1218. {
  1219. // Fetch channel titles
  1220. $this->api->instantiate('channel_structure');
  1221. $channel_q = $this->api_channel_structure->get_channels();
  1222. foreach ($channel_q->result_array() as $row)
  1223. {
  1224. $channel_array[$row['channel_id']] = array(str_replace('"','',$row['channel_title']), $row['cat_group'], $row['status_group'], $row['field_group']);
  1225. }
  1226. }
  1227. /** -----------------------------
  1228. /** Entry Statuses
  1229. /** -----------------------------*/
  1230. $this->db->select('group_id, status');
  1231. $this->db->where('site_id', $this->config->item('site_id'));
  1232. $this->db->order_by('status_order');
  1233. $query = $this->db->get('statuses');
  1234. foreach ($query->result_array() as $row)
  1235. {
  1236. $status_array[] = array($row['group_id'], $row['status']);
  1237. }
  1238. $default_cats[] = array('', lang('filter_by_category'));
  1239. $default_cats[] = array('all', lang('all'));
  1240. $default_cats[] = array('none', lang('none'));
  1241. $dstatuses[] = array('', lang('filter_by_status'));
  1242. $dstatuses[] = array('open', lang('open'));
  1243. $dstatuses[] = array('closed', lang('closed'));
  1244. $channel_info['0']['categories'] = $default_cats;
  1245. $channel_info['0']['statuses'] = $dstatuses;
  1246. foreach ($channel_array as $key => $val)
  1247. {
  1248. $any = 0;
  1249. $cats = $default_cats;
  1250. if (count($cat_form_array) > 0)
  1251. {
  1252. $last_group = 0;
  1253. foreach ($cat_form_array as $k => $v)
  1254. {
  1255. if (in_array($v['0'], explode('|', $val['1'])))
  1256. {
  1257. if ($last_group == 0 OR $last_group != $v['0'])
  1258. {
  1259. $cats[] = array('', '-------');
  1260. $last_group = $v['0'];
  1261. }
  1262. $cats[] = array($v['1'], $v['2']);
  1263. }
  1264. }
  1265. }
  1266. $channel_info[$key]['categories'] = $cats;
  1267. $statuses = array();
  1268. $statuses[] = array('', lang('filter_by_status'));
  1269. if (count($status_array) > 0)
  1270. {
  1271. foreach ($status_array as $k => $v)
  1272. {
  1273. if ($v['0'] == $val['2'])
  1274. {
  1275. $status_name = ($v['1'] == 'closed' OR $v['1'] == 'open') ? lang($v['1']) : $v['1'];
  1276. $statuses[] = array($v['1'], $status_name);
  1277. }
  1278. }
  1279. }
  1280. else
  1281. {
  1282. $statuses[] = array('open', lang('open'));
  1283. $statuses[] = array('closed', lang('closed'));
  1284. }
  1285. $channel_info[$key]['statuses'] = $statuses;
  1286. }
  1287. $this->javascript->set_global('edit.channelInfo', $channel_info);
  1288. }
  1289. // --------------------------------------------------------------------
  1290. /**
  1291. * Custom dates
  1292. */
  1293. public function custom_dates()
  1294. {
  1295. if ( ! $this->cp->allowed_group('can_access_content'))
  1296. {
  1297. show_error(lang('unauthorized_access'));
  1298. }
  1299. $this->output->enable_profiler(FALSE);
  1300. // load the javascript view, as its just a variable, no html template needed
  1301. $this->load->view('_shared/javascript');
  1302. }
  1303. // --------------------------------------------------------------------
  1304. /**
  1305. * Show entries with most recent comments
  1306. *
  1307. * Used by "recent entries" homepage link
  1308. *
  1309. * @return void
  1310. */
  1311. public function show_recent_entries()
  1312. {
  1313. if ( ! $this->cp->allowed_group('can_access_content'))
  1314. {
  1315. show_error(lang('unauthorized_access'));
  1316. }
  1317. $this->load->library('table');
  1318. $this->load->model('channel_entries_model');
  1319. $this->lang->loadfile('homepage');
  1320. $this->cp->set_variable('cp_page_title', lang('most_recent_entries'));
  1321. $count = $this->input->get('count');
  1322. $vars = array('entries' => array());
  1323. $query = $this->channel_entries_model->get_recent_entries($count);
  1324. if ($query && $query->num_rows() > 0)
  1325. {
  1326. $result = $query->result();
  1327. foreach($result as $row)
  1328. {
  1329. $c_link = BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=comment'.AMP.'method=index'.AMP.'entry_id='.$row->entry_id;
  1330. $link = BASE.AMP.'C=content_publish'.AMP.'M=view_entry'.AMP.'channel_id='.$row->channel_id.AMP.'entry_id='.$row->entry_id;
  1331. if (($row->author_id == $this->session->userdata('member_id')) OR $this->cp->allowed_group('can_edit_other_entries'))
  1332. {
  1333. $link = BASE.AMP.'C=content_publish'.AMP.'M=entry_form'.AMP.'channel_id='.$row->channel_id.AMP.'entry_id='.$row->entry_id;
  1334. }
  1335. $c_link = '<a href="'.$c_link.'">'.$row->comment_total.'</a>';
  1336. $link = '<a href="'.$link.'">'.$row->title.'</a>';
  1337. $vars['entries'][$link] = $c_link;
  1338. }
  1339. }
  1340. $vars['no_result'] = lang('no_entries');
  1341. $vars['left_column'] = lang('most_recent_entries');
  1342. $vars['right_column'] = lang('comments');
  1343. $this->javascript->compile();
  1344. $this->load->view('content/recent_list', $vars);
  1345. }
  1346. /**
  1347. * Edit Form Elements
  1348. *
  1349. * @access protected
  1350. */
  1351. protected function _edit_form($filter_data, $channels)
  1352. {
  1353. // Category Filtering Menus
  1354. // ----------------------------------------------------------------
  1355. // We need this for the filter, so grab it now
  1356. $this->api->instantiate('channel_categories');
  1357. $cat_form_array = $this->api_channel_categories->category_form_tree($this->nest_categories);
  1358. $total_channels = count($this->allowed_channels);
  1359. // If we have channels we'll write the JavaScript menu switching code
  1360. if ($total_channels > 0)
  1361. {
  1362. $this->_filtering_menus($cat_form_array);
  1363. }
  1364. // Channel selection pull-down menu
  1365. // ----------------------------------------------------------------
  1366. $c_row = FALSE;
  1367. $cat_group = '';
  1368. $channel_id = $this->input->get_post('channel_id');
  1369. if (count($channels) == 1)
  1370. {
  1371. $c_row = current($channels);
  1372. }
  1373. elseif (isset($channels[$filter_data['channel_id']]))
  1374. {
  1375. $c_row = $channels[$filter_data['channel_id']];
  1376. }
  1377. if ($c_row)
  1378. {
  1379. $channel_id = $c_row->channel_id;
  1380. $cat_group = $c_row->cat_group;
  1381. }
  1382. $vars['channel_selected'] = $this->input->get_post('channel_id');
  1383. $vars['channel_select_options'] = array('null' => lang('filter_by_channel'));
  1384. if (count($channels) > 1)
  1385. {
  1386. $vars['channel_select_options']['all'] = lang('all');
  1387. }
  1388. foreach ($channels as $id => $row)
  1389. {
  1390. $vars['channel_select_options'][$id] = $row->channel_title;
  1391. }
  1392. // Category pull-down menu
  1393. // ----------------------------------------------------------------
  1394. $vars['category_selected'] = $filter_data['cat_id'];
  1395. $vars['category_select_options'][''] = lang('filter_by_category');
  1396. if ($total_channels > 1)
  1397. {
  1398. $vars['category_select_options']['all'] = lang('all');
  1399. }
  1400. $vars['category_select_options']['none'] = lang('none');
  1401. if ($cat_group != '')
  1402. {
  1403. foreach($cat_form_array as $key => $val)
  1404. {
  1405. if ( ! in_array($val['0'], explode('|',$cat_group)))
  1406. {
  1407. unset($cat_form_array[$key]);
  1408. }
  1409. }
  1410. $i = 1;
  1411. $new_array = array();
  1412. foreach ($cat_form_array as $ckey => $cat)
  1413. {
  1414. if ($ckey-1 < 0 OR ! isset($cat_form_array[$ckey-1]))
  1415. {
  1416. $vars['category_select_options']['NULL_'.$i] = '-------';
  1417. }
  1418. $vars['category_select_options'][

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