Example #1
0
 function unique_short_tag($short_tag, $current_short_tag = '')
 {
     $reserved = array('site_url', 'base_url', 'theme_url', 'title', 'created_date', 'modified_date', 'url_title', 'slug', 'dynamic_route', 'content_type', 'count', 'total_results', 'author_id', 'meta_title', 'meta_description', 'meta_keywords', '_content', '_callbacks');
     if ($this->config->item('global_tags') && is_array($this->config->item('global_tags'))) {
         $reserved = array_merge($reserved, array_keys($this->config->item('global_tags')));
     }
     // Check that the short tag is not a reserved CMS name
     if (in_array(strtolower($short_tag), $reserved)) {
         $this->form_validation->set_message('unique_short_tag', 'The %s provided is reserved by the CMS.');
         return FALSE;
     }
     $Content_fields = new Content_fields_model();
     // If in edit mode ignore its current name
     if ($current_short_tag != '') {
         $Content_fields->where('short_tag !=', $current_short_tag);
     }
     $Content_fields->where('content_type_id', $this->uri->segment(5))->where('short_tag', $short_tag)->get();
     if ($Content_fields->exists()) {
         $this->form_validation->set_message('unique_short_tag', 'The %s provided is already in use for this content type.');
         return FALSE;
     } else {
         return TRUE;
     }
 }
Example #2
0
 function pre_save_output()
 {
     if (!is_ajax()) {
         return show_404();
     }
     // Init
     $this->load->model('entries_model');
     $this->load->model('content_fields_model');
     $response = array();
     $editable_id = $this->input->post('editable_id');
     $content = $this->input->post('content');
     // Preg match the entry id and the field id from the html element's id attribute
     if (preg_match("/cc_field_(\\d+)_(\\d+)/", $editable_id, $matches)) {
         $entry_id = $matches[1];
         $field_id = $matches[2];
     } else {
         $response['status'] = 'error';
         $response['message'] = 'Unable to parse the entry id and field id.';
         echo json_encode($response);
     }
     $Entry = new Entries_model();
     $Entry->get_by_id($entry_id);
     if (!$Entry->exists()) {
         $response['status'] = 'error';
         $response['message'] = 'The entry id provided does not exist.';
         echo json_encode($response);
     }
     $Field = new Content_fields_model();
     $Field->order_by('sort', 'ASC')->include_related('content_field_types', array('model_name'))->get_by_id($field_id);
     if (!$Field->exists()) {
         $response['status'] = 'error';
         $response['message'] = 'The field id provided does not exist.';
         echo json_encode($response);
     }
     $Content_object = new stdClass();
     $Content_object->{'field_id_' . $Field->id} = $content;
     $Field_type = Field_type::factory($Field->content_field_types_model_name, $Field, $Entry, $Content_object);
     $output = $Field_type->output();
     $response['status'] = 'success';
     $response['content'] = $output;
     echo json_encode($response);
 }
Example #3
0
 function delete()
 {
     $this->load->helper('file');
     $this->load->model('content_types_model');
     $this->load->model('content_types_admin_groups_model');
     $this->load->model('entries_model');
     if ($this->input->post('selected')) {
         $selected = $this->input->post('selected');
     } else {
         $selected = (array) $this->uri->segment(5);
     }
     $Content_types = new Content_types_model();
     $Content_types->where_in('id', $selected)->get();
     if ($Content_types->exists()) {
         $message = '';
         $content_types_deleted = FALSE;
         $this->load->model('content_fields_model');
         foreach ($Content_types as $Content_type) {
             if ($Content_type->required) {
                 $message .= '<p class="error">Content type ' . $Content_type->title . ' (' . $Content_type->short_name . ') is required by the system and cannot be deleted.</p>';
             } else {
                 if ($Content_type->entries->limit(1)->get()->exists()) {
                     $message .= '<p class="error">Content type ' . $Content_type->title . ' (' . $Content_type->short_name . ') is associated to one or more entries and cannot be deleted.</p>';
                 } else {
                     // Delete content type fields and entries data coloumns
                     $Content_fields = new Content_fields_model();
                     $Content_fields->where('content_type_id', $Content_type->id)->get();
                     foreach ($Content_fields as $Content_field) {
                         $Content_fields->drop_entries_column();
                         $Content_fields->delete();
                     }
                     // Delete content type admin groups
                     $Content_types_admin_groups = new Content_types_admin_groups_model();
                     $Content_types_admin_groups->where('content_type_id', $Content_type->id)->get();
                     $Content_types_admin_groups->delete_all();
                     // Delete content type revisions
                     $Content_type->delete_revisions();
                     // Delete content type
                     $Content_type->delete();
                     $content_types_deleted = TRUE;
                 }
             }
         }
         if ($content_types_deleted) {
             // Clear cache
             $this->load->library('cache');
             $this->cache->delete_all('entries');
             $message = '<p class="success">The selected items were successfully deleted.</p>' . $message;
         }
         $this->session->set_flashdata('message', $message);
     }
     redirect(ADMIN_PATH . '/content/types');
 }