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