コード例 #1
0
ファイル: entries.php プロジェクト: mamtasingh87/bytecode
 function edit()
 {
     // Init
     $data = array();
     $data['edit_mode'] = $edit_mode = FALSE;
     $data['breadcrumb'] = set_crumbs(array('content/entries' => 'Entries', current_url() => 'Entry Edit'));
     $data['content_type_id'] = $content_type_id = $this->uri->segment(5);
     $data['entry_id'] = $entry_id = $this->uri->segment(6);
     $data['revision_id'] = $revision_id = $this->uri->segment(7);
     // Get entry
     $this->load->model('users/users_model');
     $this->load->model('entries_model');
     $this->load->model('content_types_model');
     // Used for content types dropdown
     $Content_types_model = new Content_types_model();
     // If user not a super admin check if user's group is allowed access
     if ($this->Group_session->type != SUPER_ADMIN) {
         $this->content_types_model->group_start()->where('restrict_admin_access', 0)->or_where_related('admin_groups', 'group_id', $this->Group_session->id)->group_end();
         $this->entries_model->group_start()->where('restrict_admin_access', 0)->or_where_related('content_types/admin_groups', 'group_id', $this->Group_session->id)->group_end();
         // Only get Content Types user has access to for dropdown
         $Content_types_model->group_start()->where('restrict_admin_access', 0)->or_where_related('admin_groups', 'group_id', $this->Group_session->id)->group_end();
     }
     $data['Entry'] = $Entry = $this->entries_model->get_by_id($entry_id);
     $data['Content_type'] = $Content_type = $this->content_types_model->get_by_id($content_type_id);
     // Load content fields library
     $config['Entry'] = $Entry;
     $config['content_type_id'] = $content_type_id;
     $this->load->add_package_path(APPPATH . 'modules/content/content_fields');
     $Content_fields = $this->load->library('content_fields');
     $Content_fields->initialize($config);
     // Check if versioning is enabled and whether a revision is loaded
     if ($Content_type->enable_versioning && is_numeric($revision_id)) {
         $Revision = new Revisions_model();
         $Revision->get_by_id($revision_id);
         if ($Revision->exists()) {
             $revision_data = @unserialize($Revision->revision_data);
             // Update Entry and content fields from revision
             // Entries data gets queiried in the content_fields library initialize
             if (is_array($revision_data)) {
                 $Entry->from_array($revision_data);
                 $Content_fields->from_array($revision_data);
             }
         }
     }
     // Get content types for the setting's
     // content type dropdown
     $Change_content_types = $Content_types_model->where('id !=', $content_type_id)->order_by('title')->get();
     $data['change_content_types'] = array('' => '');
     foreach ($Change_content_types as $Change_content_type) {
         $entries_count = $Change_content_type->entries->count();
         // Only add the content type to the Add Entry dropdown if it has not reached the
         // limit of entries allowed. An empty entries_allowed is unlimited
         if ($Change_content_type->entries_allowed == '' || $entries_count < $Change_content_type->entries_allowed || $entries_count == 0 && $Change_content_type->entries_allowed > 0) {
             $data['change_content_types'][$Change_content_type->id] = $Change_content_type->title;
         }
     }
     // Get Admins and Super Admins for the setting's
     // author dropdown
     $Users = $this->users_model->where_in_related('groups', 'type', array(SUPER_ADMIN, ADMINISTRATOR))->order_by('first_name')->get();
     $data['authors'] = array('' => '');
     foreach ($Users as $User) {
         $data['authors'][$User->id] = $User->full_name();
     }
     // Validate that the content type exists
     if (!$Content_type->exists()) {
         return show_404();
     }
     if ($Entry->exists()) {
         // Check that url content_type_id and entry content_type_id match
         if ($Entry->content_type_id != $content_type_id && !$revision_id) {
             return show_404();
         }
         $data['edit_mode'] = $edit_mode = TRUE;
     }
     // Build categories tree if content type has a category group assigned
     if ($Content_type->category_group_id) {
         $this->load->library('categories_library');
         $config['id'] = $Content_type->category_group_id;
         $config['admin_entries_categories'] = TRUE;
         $config['populate'] = option_array_value($Entry->categories->get(), 'id', 'id');
         $data['categories_tree'] = $this->categories_library->list_categories($config);
         $Entry->categories->get();
     }
     // Form Validation Rules
     if ($edit_mode) {
         $this->form_validation->set_rules('slug', 'URL', 'trim|max_length[255]|callback_unique_slug_check[' . addslashes($Entry->slug) . ']');
     } else {
         $this->form_validation->set_rules('slug', 'URL', 'trim|max_length[255]|callback_unique_slug_check');
     }
     $this->form_validation->set_rules('meta_title', 'Meta Title', 'trim');
     $this->form_validation->set_rules('meta_description', 'Meta Description', 'trim');
     $this->form_validation->set_rules('meta_keywords', 'Meta Keywords', 'trim');
     $this->form_validation->set_rules('status', 'Status', 'trim|required');
     $this->form_validation->set_rules('title', 'Entry Title', 'trim|required|max_length[100]');
     $this->form_validation->set_rules('created_date', 'Date Created', 'trim|required');
     // Validate url title if content type has a dynamic route
     if ($Content_type->dynamic_route != '') {
         $this->form_validation->set_rules('url_title', 'URL Title', 'trim|required|alpha_dash|max_length[100]|is_unique[entries.url_title' . ($edit_mode ? '.id.' . $Entry->id : '') . ']');
     }
     // Get content fields html
     $field_validation = $Content_fields->validate();
     // Validation and process form
     if ($this->form_validation->run() == TRUE && $field_validation) {
         // Populate from post and prep for insert / update
         $Entry->from_array($this->input->post());
         $Entry->modified_date = date('Y-m-d H:i:s');
         $Entry->created_date = date('Y-m-d H:i:s', strtotime($this->input->post('created_date')));
         $Entry->slug = $this->input->post('slug') != '' ? $this->input->post('slug') : NULL;
         $Entry->url_title = $this->input->post('url_title') != '' ? $this->input->post('url_title') : NULL;
         $Entry->meta_title = $this->input->post('meta_title') != '' ? $this->input->post('meta_title') : NULL;
         $Entry->meta_description = $this->input->post('meta_description') != '' ? $this->input->post('meta_description') : NULL;
         $Entry->meta_keywords = $this->input->post('meta_keywords') != '' ? $this->input->post('meta_keywords') : NULL;
         $Entry->content_type_id = $content_type_id;
         $Entry->author_id = $this->input->post('author_id') != '' ? $this->input->post('author_id') : NULL;
         // Ensure the id wasn't overwritten by an id in the post
         if ($edit_mode) {
             $Entry->id = $entry_id;
         }
         $Entry->save();
         // Save field data to entries_data
         $Content_fields->from_array($this->input->post());
         $Content_fields->save();
         // Add Revision if versioning 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();
         }
         // Assign entry to selected categories
         if ($Content_type->category_group_id) {
             $this->load->model('categories_entries_model');
             $Categories_entries = new Categories_entries_model();
             $categories_post = is_array($this->input->post('categories')) ? $this->input->post('categories') : array();
             // Delete all of the entries categories that are not in the posted array
             $Categories_entries->where('entry_id', $Entry->id);
             if (!empty($categories_post)) {
                 $Categories_entries->where_not_in('category_id', $categories_post);
             }
             $Categories_entries->get()->delete_all();
             // Check if categories posted already exist in the relationship table
             // If not add them
             foreach ($categories_post as $category_id) {
                 $Categories_entries = new Categories_entries_model();
                 $Categories_entries->where('category_id', $category_id)->where('entry_id', $Entry->id)->get();
                 if (!$Categories_entries->exists()) {
                     $Categories_entries->category_id = $category_id;
                     $Categories_entries->entry_id = $entry_id;
                     $Categories_entries->save();
                 }
             }
         }
         // 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();
         // Set a success message
         $this->session->set_flashdata('message', '<p class="success">Changes Saved.</p>');
         // Deteremine where to redirect user
         if ($this->input->post('save_exit')) {
             redirect(ADMIN_PATH . "/content/entries");
         } else {
             redirect(ADMIN_PATH . "/content/entries/edit/" . $Entry->content_type_id . "/" . $Entry->id);
         }
     }
     $_SESSION['KCFINDER'] = array();
     $_SESSION['KCFINDER']['disabled'] = false;
     $_SESSION['isLoggedIn'] = true;
     // Field form needs to be built after running form_validation->run()
     $data['Fields'] = $Content_fields->form();
     $this->template->view('admin/entries/edit', $data);
 }
コード例 #2
0
ファイル: categories.php プロジェクト: mamtasingh87/bytecode
 function group_delete()
 {
     if ($this->input->post('selected')) {
         $selected = $this->input->post('selected');
     } else {
         $selected = (array) $this->uri->segment(5);
     }
     $Groups =& $this->load->model('category_groups_model');
     $Groups->where_in('id', $selected)->get();
     if ($Groups->exists()) {
         $this->load->model('content_types_model');
         foreach ($Groups as $Group) {
             // Clear category group relations to content types
             $Content_types = new Content_types_model();
             $Content_types->where('category_group_id', $Group->id)->update('category_group_id', NULL);
             $Group->categories->get();
             foreach ($Group->categories as $Category) {
                 // Delete category's relationship to entries
                 $Category->entries->get();
                 $Category->delete($Category->entries->all, 'entries');
                 $Category->delete();
             }
             $Group->delete();
         }
         $this->session->set_flashdata('message', '<p class="success">Category group was deleted successfully.</p>');
     }
     // Clear categories cache so updates will show on next page load
     $this->load->library('categories_library');
     $this->categories_library->clear_cache();
     redirect(ADMIN_PATH . '/content/categories/groups');
 }