Example #1
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);
 }
 public function build_entry_data($query_results)
 {
     // Make query_results an array if not already
     if (!is_array($query_results)) {
         $query_results = array($query_results);
     }
     $total_results = count($query_results);
     $count = 0;
     foreach ($query_results as $Entry) {
         $count++;
         $content['entry_id'] = $Entry->id;
         if (is_inline_editable($Entry->content_type_id)) {
             $content['title_editable'] = '<div id="cc_field_' . $Entry->id . '_title" class="cc_admin_editable cc_text_editable" contenteditable="true">{{ noparse }}' . $Entry->title . '{{ /noparse }}</div>';
         } else {
             $content['title_editable'] = $Entry->title;
         }
         $content['title'] = $Entry->title;
         $content['created_date'] = $Entry->created_date;
         $content['modified_date'] = $Entry->modified_date;
         $content['url_title'] = $Entry->url_title;
         $content['slug'] = $Entry->slug;
         $content['dynamic_route'] = $Entry->dynamic_route;
         $content['content_type'] = $Entry->short_name;
         $content['count'] = $count;
         $content['total_results'] = $total_results;
         $content['author_id'] = $Entry->author_id;
         $content['meta_title'] = $Entry->meta_title;
         $content['meta_description'] = $Entry->meta_description;
         $content['meta_keywords'] = $Entry->meta_keywords;
         foreach ($this->content_fields as $Field) {
             // Only define tags that belong to this content type
             if ($Field->content_type_id == $Entry->content_type_id) {
                 $field_type = Field_type::factory($Field->model_name, $Field, $Entry);
                 $content[$Field->short_tag] = $field_type->output();
                 if (method_exists($field_type, 'parser_callback')) {
                     $content['_callbacks'][$Field->short_tag] = array($field_type, 'parser_callback');
                 }
             }
         }
         // Create a dynamic url tag for entries that have a content type with a dynamic route defined
         // If the content type does not have a dynamic route, it ouputs the entries id
         if ($Entry->dynamic_route != '') {
             $content['dynamic_url'] = site_url($Entry->dynamic_route . '/' . ($Entry->url_title != '' ? $Entry->url_title : $Entry->id));
         } else {
             $content['dynamic_url'] = $Entry->id;
         }
         // Use content type's layout if no content defined
         if ($this->_content == '') {
             $this->_content = $Entry->layout;
             $content['_content'] = $this->_content;
         }
         if ($count == $total_results && $this->backspace) {
             $stripped_content = preg_replace('/\\n?\\s*?\\{\\{\\s*(paginate|before_iteration|after_iteration|no_results)\\s*\\}\\}(.*?)\\{\\{\\s*\\/\\1\\s*\\}\\}/ms', '', $this->_content);
             $stripped_content = substr($stripped_content, 0, $this->backspace * -1);
             $content['_content'] = $stripped_content;
         }
         $this->entries[] = $content;
     }
 }
Example #3
0
 private function _factor_field_types()
 {
     foreach ($this->fields as $Field) {
         $this->field_types['field_id_' . $Field->id] = Field_type::factory($Field->content_field_types_model_name, $Field, $this->Entry, $this->Entry_data);
     }
 }