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 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');
 }