/** * Saves one article * * @param boolean if true, the transport is through XHR */ public function save() { if (!Authority::can('edit', 'admin/article')) { $this->error(lang('permission_denied')); } /* Check if the default lang URL or the default lang title are set * One of these need to be set to save the article * */ if ($this->_check_before_save() === TRUE) { // Clear the cache Cache()->clear_cache(); $rel = $this->input->post('rel'); // IDs $rel = explode(".", $rel); $this->data['id_page'] = !empty($rel[1]) ? $rel[0] : '0'; $post_id_article = $this->input->post('id_article'); // Prepare data before saving $this->_prepare_data(); // Event : On before save $event_data = array('base' => $this->data, 'lang' => $this->lang_data, 'post' => $this->input->post()); $event_received = Event::fire('Article.save.before', $event_data); $event_received = array_pop($event_received); if (!empty($event_received['base'])) { $this->data = $event_received['base']; } if (!empty($event_received['lang'])) { $this->lang_data = $event_received['lang']; } // Saves article to DB and get the saved ID $id_article = $this->article_model->save($this->data, $this->lang_data); // Link to page if (!empty($this->data['id_page'])) { $this->data['online'] = $this->input->post('online'); $this->data['main_parent'] = $this->input->post('main_parent'); $this->article_model->link_to_page($this->data['id_page'], $id_article, $this->data); } else { $this->data['id_page'] = '0'; } // Correct DB integrity : Links IDs if (!empty($post_id_article)) { $this->article_model->correct_integrity($this->data, $this->lang_data); } // Saves linked categories $this->base_model->join_items_keys_to('category', $this->input->post('categories'), 'article', $id_article); // Save extend fields data $this->extend_field_model->save_data('article', $id_article, $_POST); // Save URLs $this->article_model->save_urls($id_article); // Save the Sitemap $this->structure->build_sitemap(); // Event : On after save $event_data = array('base' => $this->data, 'lang' => $this->lang_data, 'post' => $this->input->post()); Event::fire('Article.save.success', $event_data); /* * JSON Answer * * Updates the structure tree * The data var is merged to the default lang data_lang var, * in order to send the lang values to the browser without making another SQL request */ // Get the context info $context = $this->article_model->get_context($id_article, $this->data['id_page'], Settings::get_lang('default')); $this->data = array_merge($this->data, $context); // Remove HTML tags from returned array strip_html($this->data); // Insert Case if (empty($post_id_article)) { $menu = $this->menu_model->get_from_page($this->data['id_page']); $this->data['menu'] = $menu; // Used by JS Tree to detect if article in inserted in tree or not $this->data['inserted'] = TRUE; // Context update $this->update_contexts($this->data['id_article']); // Insert article to tree if menu is found (for id_page = 0, no one is found) if (!empty($menu)) { $this->callback[] = array('fn' => $menu['name'] . 'Tree.insertElement', 'args' => array($this->data, 'article')); } // Reloads the edition panel $this->_reload_panel($this->data['id_page'], $id_article); // Answer $this->success(lang('ionize_message_article_saved')); } else { // Save options : as callback $this->callback[] = array('fn' => 'ION.sendForm', 'args' => array('article/save_options', 'articleOptionsForm')); $this->response(); } } else { Event::fire('Article.save.error'); $this->error(lang('ionize_message_article_needs_url_or_title')); } }