Example #1
0
 /** 
  * Prepares data before saving
  *
  */
 protected function _prepare_data()
 {
     // Standard fields
     $fields = $this->db->list_fields('article');
     // Set the data to the posted value.
     foreach ($fields as $field) {
         if ($this->input->post($field) !== FALSE or in_array($field, $this->boolean_data)) {
             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);
             }
         }
     }
     // Page ID : Only on creation
     if ($this->input->post('id_page')) {
         $this->data['id_page'] = $this->input->post('id_page');
         // Ordering : Only done for a new article, else, don't touch
         if (!$this->input->post('id_article')) {
             $this->data['ordering'] = $this->_get_ordering($this->input->post('ordering_select'), $this->data['id_page'], $this->input->post('ordering_after'));
         }
     }
     // Author & updater
     $user = User()->get_user();
     if ($this->input->post('id_article')) {
         $this->data['updater'] = $user['username'];
     } else {
         $this->data['author'] = $user['username'];
     }
     // URLs : Feed the other languages URL with the default one if the URL is missing
     $urls = $this->_get_urls(TRUE);
     // Update the name (not used anymore in the frontend, but used in the backend)
     $this->data['name'] = $urls[Settings::get_lang('default')];
     $this->data['name'] = $this->article_model->get_unique_name($this->data['name'], $this->input->post('id_article'));
     /*
      * Lang data
      *
      */
     $fields = $this->db->list_fields('article_lang');
     foreach (Settings::get_languages() as $language) {
         foreach ($fields as $field) {
             // Do not filter
             if (in_array($field, $this->no_xss_filter)) {
                 $content = $_REQUEST[$field . '_' . $language['lang']];
                 $content = stripslashes($content);
             } else {
                 $content = $this->input->post($field . '_' . $language['lang']);
             }
             if (in_array($field, $this->htmlspecialchars)) {
                 $content = htmlspecialchars($content, ENT_QUOTES, 'utf-8');
             }
             if ($field != 'url' && $content !== FALSE) {
                 // Allowed tags filter
                 $allowed_tags = explode(',', Settings::get('article_allowed_tags'));
                 $allowed_tags = '<' . implode('>,<', $allowed_tags) . '>';
                 $content = strip_tags($content, $allowed_tags);
                 $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']);
     }
 }