/** * Prepare page data before saving * */ protected function _prepare_data() { // Standard fields $fields = $this->db->list_fields('page'); // Set the data to the posted value. foreach ($fields as $field) { if ($this->input->post($field) !== FALSE) { // if ( ! in_array($field, $this->no_htmlspecialchars)) // $this->data[$field] = htmlspecialchars($this->input->post($field), ENT_QUOTES, 'utf-8'); // else $this->data[$field] = $this->input->post($field); } } // level ? $parent = $this->page_model->get_by_id($this->input->post('id_parent')); if (!empty($parent)) { $this->data['level'] = $parent['level'] + 1; } else { $this->data['level'] = 0; } // Author & updater if ($this->input->post('id_page')) { $this->data['updater'] = User()->get('username'); } else { $this->data['author'] = User()->get('username'); $this->data['appears'] = $this->input->post('appears'); } // URLs : Feed the other languages URL with the default one if the URL is missing $urls = $this->_get_urls(TRUE); // Unset Ordering if no new page : Saved by page ordering in tree view if (!$this->input->post('id_page') || $this->input->post('id_page') == '') { $this->db->select_max('ordering', 'ordering'); $this->db->where('id_menu', $this->input->post('id_menu')); $query = $this->db->get('page'); if ($query->num_rows() > 0) { $row = $query->row(); $this->data['ordering'] = $row->ordering + 1; } // Create the page name : Only done for new page $this->data['name'] = $urls[Settings::get_lang('default')]; $this->data['name'] = $this->page_model->get_unique_name($this->data['name'], $this->input->post('id_page')); } else { unset($this->data['ordering']); } // Lang data $fields = $this->db->list_fields('page_lang'); foreach (Settings::get_languages() as $language) { foreach ($fields as $field) { if ($field != 'url' && $this->input->post($field . '_' . $language['lang']) !== FALSE) { $content = $this->input->post($field . '_' . $language['lang']); // Convert HTML special char only on other fields than these defined in $no_htmlspecialchars // if ( ! in_array($field, $this->no_htmlspecialchars)) // $content = htmlspecialchars($content, ENT_QUOTES, 'utf-8'); $this->lang_data[$language['lang']][$field] = $content; } else { if ($field === 'url') { $this->lang_data[$language['lang']]['url'] = $urls[$language['lang']]; } } } // Online value $this->lang_data[$language['lang']]['online'] = $this->input->post('online_' . $language['lang']); } }