public function get_entry_revisions() { $CI =& get_instance(); $CI->load->model('revisions_model'); $Revisions = new Revisions_model(); $Revisions->where_related('revision_resource_types', 'key_name', 'ENTRY')->where('resource_id', $this->id)->order_by('id', 'desc')->get(); return $Revisions; }
function edit() { // Init $data = array(); $data['edit_mode'] = FALSE; $this->template->add_package(array('codemirror')); $data['breadcrumb'] = set_crumbs(array('content/snippets' => 'Snippets', current_url() => 'Snippet Edit')); $data['revision_id'] = $revision_id = $this->uri->segment(6); $this->load->model('snippets_model'); $data['Snippet'] = $Snippet = new Snippets_model(); $snippet_id = $this->uri->segment(5); // Edit mode if ($snippet_id) { $data['edit_mode'] = TRUE; $Snippet->get_by_id($snippet_id); // Check if snippet exists if (!$Snippet->exists()) { return show_404(); } // Load a revision if a revision id was provided in the URL if (!empty($revision_id)) { $this->load->model('revisions_model'); $Revision = new Revisions_model(); $Revision->get_by_id($revision_id); if ($Revision->exists()) { $revision_data = @unserialize($Revision->revision_data); $Snippet->from_array($revision_data); } else { return show_404(); } } } $this->form_validation->set_rules('title', 'Title', 'trim|required'); $this->form_validation->set_rules('short_name', 'Short Name', 'trim|required|alpha_dash|max_length[50]|is_unique[snippets.short_name.id.' . $snippet_id . ']'); $this->form_validation->set_rules('snippet', 'Snippet', ''); // Form validation if ($this->form_validation->run() == TRUE) { $Snippet->from_array($this->input->post()); if ($data['edit_mode']) { $Snippet->id = $snippet_id; } $Snippet->save(); $Snippet->add_revision(); // Clear cache $this->load->library('cache'); $this->cache->delete_all('snippets'); $this->session->set_flashdata('message', '<p class="success">Snippet Saved.</p>'); if ($this->input->post('save_exit')) { redirect(ADMIN_PATH . '/content/snippets/'); } else { redirect(ADMIN_PATH . '/content/snippets/edit/' . $Snippet->id); } } $this->template->view('admin/snippets/edit', $data); }
function save_inline_content() { if (!is_ajax()) { return show_404(); } $this->load->model('entries_model'); $this->load->model('revisions_model'); $this->load->add_package_path(APPPATH . 'modules/content/content_fields'); $response['status'] = 'success'; $data = array(); foreach ($_POST as $key => $content) { // Preg match the entry id and the field id from the html element's id attribute if (preg_match("/cc_field_(\\d+)_(\\d+|title)/", $key, $matches)) { $entry_id = $matches[1]; $field_id = $matches[2]; // Build a new data array sorted by entry $data[$entry_id]['field_id_' . $field_id] = $content; } } foreach ($data as $entry_id => $fields) { $Entry = new Entries_model(); // If user not a super admin check if user's group is allowed access if ($this->Group_session->type != SUPER_ADMIN) { $Entry->group_start()->where('restrict_admin_access', 0)->or_where_related('content_types/admin_groups', 'group_id', $this->Group_session->id)->group_end(); } $Entry->get_by_id($entry_id); // Either entry doesn't exist or user doesn't have permission to it so skip it if (!$Entry->exists()) { continue; } $Content_type = $Entry->content_types->get(); // Load content fields library $config['Entry'] = $Entry; $config['content_type_id'] = $Entry->content_type_id; $Content_fields = $this->load->library('content_fields'); $Content_fields->initialize($config); // Get content fields html $field_validation = $Content_fields->inline_validate(); // Validation and process form if ($this->form_validation->run() == TRUE && $field_validation) { if (isset($fields['field_id_title'])) { $Entry->title = $fields['field_id_title']; } $Entry->modified_date = date('Y-m-d H:i:s'); $Entry->save(); $Content_fields->from_array($fields); $Content_fields->save(); // Add Revision if versioing enabled if ($Content_type->enable_versioning) { // Delete old revsions so that not to exceed max revisions setting $Revision = new Revisions_model(); $Revision->where_related('revision_resource_types', 'key_name', 'ENTRY')->where('resource_id', $entry_id)->order_by('id', 'desc')->limit(25, $Content_type->max_revisions - 1)->get()->delete_all(); // Serialize and save post data to entry revisions table $User = $this->secure->get_user_session(); $Revision = new Revisions_model(); $Revision->resource_id = $Entry->id; $Revision->revision_resource_type_id = Revision_resource_types_model::ENTRY; $Revision->content_type_id = $Entry->content_type_id; $Revision->author_id = $User->id; $Revision->author_name = $User->first_name . ' ' . $User->last_name; $Revision->revision_date = date('Y-m-d H:i:s'); $Revision->revision_data = serialize($this->input->post()); $Revision->save(); } } } // Check if there were any validation errors if (validation_errors()) { $validation_errors = validation_errors("-", " "); $response['status'] = 'error'; $response['message'] = $validation_errors; } // Clear cache so updates will show on next page load $this->load->library('cache'); $this->cache->delete_all('entries'); // Clear navigation cache so updates will show on next page load $this->load->library('navigations/navigations_library'); $this->navigations_library->clear_cache(); echo json_encode($response); }
public function delete_revisions() { $CI =& get_instance(); $CI->load->model('revisions_model'); $Revisions = new Revisions_model(); $Revisions->where_related('revision_resource_types', 'key_name', 'CONTENT_TYPE')->where('resource_id', $this->id)->get(); $Revisions->delete_all(); }
function edit() { // Init $data = array(); $data['breadcrumb'] = set_crumbs(array('content/types' => 'Content Types', current_url() => 'Content Type Edit')); $data['revision_id'] = $revision_id = $this->uri->segment(6); $this->load->model('content_types_model'); $this->load->model('content_types_admin_groups_model'); $this->load->model('users/groups_model'); $this->load->model('category_groups_model'); // Load codemirror $this->template->add_package(array('codemirror', 'zclip')); $content_type_id = $this->uri->segment(5); $data['Content_type'] = $Content_type = $this->content_types_model->get_by_id($content_type_id); $data['theme_layouts'] = $this->template->get_theme_layouts($this->settings->theme, TRUE); $data['Admin_groups'] = $Admin_groups = $this->groups_model->where('type', ADMINISTRATOR)->order_by('name')->get(); // Get all groups except super admin for group access $Groups = new Groups_model(); $data['Groups'] = $Groups->where('type !=', SUPER_ADMIN)->order_by('name')->get(); // Get all category groups for dropdown $data['category_groups'] = option_array_value($this->category_groups_model->order_by('title')->get(), 'id', 'title', array('' => '')); // Check if layout exists if (!$data['Content_type']->exists()) { return show_404(); } // Get selected restrict to groups for repopulation $data['restrict_to'] = @unserialize($data['Content_type']->restrict_to); if (!is_array($data['restrict_to'])) { $data['restrict_to'] = (array) $data['restrict_to']; } // Load a revision if a revision id was provided in the URL if (!empty($revision_id)) { $this->load->model('revisions_model'); $Revision = new Revisions_model(); $Revision->get_by_id($revision_id); if ($Revision->exists()) { $revision_data = @unserialize($Revision->revision_data); $Content_type->from_array($revision_data); } else { return show_404(); } } // Get admin groups currently assigned to this conten type $data['current_admin_groups'] = option_array_value($Content_type->admin_groups->get(), 'id', 'group_id'); $this->form_validation->set_rules('title', 'Title', 'trim|required'); $this->form_validation->set_rules('short_name', 'Short Name', 'trim|required|alpha_dash|max_length[50]|is_unique[content_types.short_name.id.' . $content_type_id . ']'); $this->form_validation->set_rules('enable_dynamic_routing', 'Enable Dynamic Routing', 'trim'); $this->form_validation->set_rules('enable_versioning', 'Enable Versioning', 'trim|required'); $this->form_validation->set_rules('max_revisions', 'Max Revisions', 'trim|required|integer|less_than[26]'); $this->form_validation->set_rules('category_group_id', 'Category Group', 'trim'); $this->form_validation->set_rules('restrict_admin_access', 'Restrict Admin Access', 'trim|required'); $this->form_validation->set_rules('selected_admin_groups[]', 'Administrative Access', 'trim'); $this->form_validation->set_rules('access', 'Access', 'trim|required'); $this->form_validation->set_rules('restrict_to[]', 'Group Access', 'trim'); $this->form_validation->set_rules('entries_allowed', 'Number of Entries Allowed', 'trim|integer'); $this->form_validation->set_rules('layout', 'layout', ''); // Add dynamic route validation if enable dynamic routing checkbox selected if ($this->input->post('enable_dynamic_routing') == 1) { $this->form_validation->set_rules('dynamic_route', 'Dynamic Route', 'trim|required|max_length[255]|callback_unique_dynamic_route[' . $Content_type->dynamic_route . ']'); } // Form validation if ($this->form_validation->run() == TRUE) { // Detect if the category group changed. // If it has changed delete entry category relations // of the content type if ($Content_type->category_group_id != $this->input->post('category_group_id')) { $Content_type->entries->get(); foreach ($Content_type->entries as $Entry) { $Entry->categories->get(); $Entry->delete($Entry->categories->all, 'categories'); } } $Content_type->from_array($this->input->post()); $Content_type->id = $content_type_id; $Content_type->dynamic_route = $this->input->post('dynamic_route') != '' && $this->input->post('enable_dynamic_routing') ? $this->input->post('dynamic_route') : NULL; $Content_type->restrict_to = $this->input->post('access') == 2 ? serialize($this->input->post('restrict_to')) : NULL; $Content_type->category_group_id = $this->input->post('category_group_id') != '' ? $this->input->post('category_group_id') : NULL; $Content_type->layout = trim($this->input->post('layout')) != '' ? $this->input->post('layout') : NULL; $Content_type->page_head = trim($this->input->post('page_head')) != '' ? $this->input->post('page_head') : NULL; $Content_type->theme_layout = $this->input->post('theme_layout') != '' ? $this->input->post('theme_layout') : NULL; $Content_type->entries_allowed = $this->input->post('entries_allowed') != '' ? $this->input->post('entries_allowed') : NULL; $Content_type->save(); $Content_type->add_revision(); // Assign admin groups to this content type // if restrict admin access is enabled if ($this->content_types_model->restrict_admin_access && is_array($this->input->post('selected_admin_groups'))) { $selected_admin_groups = $this->input->post('selected_admin_groups'); foreach ($Admin_groups as $Admin_group) { $Content_types_admin_groups = new Content_types_admin_groups_model(); $Content_types_admin_groups->where('content_type_id', $Content_type->id)->where('group_id', $Admin_group->id)->get(); if (in_array($Admin_group->id, $selected_admin_groups)) { // Admin group was selected so Update or Insert to database $Content_types_admin_groups->content_type_id = $Content_type->id; $Content_types_admin_groups->group_id = $Admin_group->id; $Content_types_admin_groups->save(); } else { // Admin group was NOT selected so delete it $Content_types_admin_groups->delete_all(); } } } else { // Restrict admin access was disabled so remove any assigned groups from database $Content_types_admin_groups = new Content_types_admin_groups_model(); $Content_types_admin_groups->where('content_type_id', $this->content_types_model->id)->get(); $Content_types_admin_groups->delete_all(); } // Clear cache $this->load->library('cache'); $this->cache->delete_all('entries'); $this->cache->delete_all('content_types'); $this->session->set_flashdata('message', '<p class="success">Content Type Saved.</p>'); if ($this->input->post('save_exit')) { redirect(ADMIN_PATH . '/content/types/'); } else { redirect(ADMIN_PATH . '/content/types/edit/' . $this->content_types_model->id); } } $data['Fields'] = $this->content_types_model->content_fields->order_by('sort')->get(); $this->template->view('admin/types/edit', $data); }