Ejemplo n.º 1
0
 /**
  * Saves one media metadata
  *
  */
 public function save()
 {
     // Clear the cache
     Cache()->clear_cache();
     // Standard data;
     $data = array();
     // Standard fields
     $fields = $this->db->list_fields('media');
     foreach ($fields as $field) {
         if ($this->input->post($field) !== FALSE) {
             $data[$field] = htmlentities($this->input->post($field), ENT_QUOTES, 'utf-8');
         }
     }
     // Lang data
     $lang_data = array();
     $fields = $this->db->list_fields('media_lang');
     foreach (Settings::get_languages() as $language) {
         foreach ($fields as $field) {
             if ($this->input->post($field . '_' . $language['lang']) !== FALSE) {
                 $lang_data[$language['lang']][$field] = htmlentities($this->input->post($field . '_' . $language['lang']), ENT_QUOTES, 'utf-8');
             }
         }
     }
     // Event
     $event_data = array('base' => $data, 'lang' => $lang_data);
     $event_received = Event::fire('Media.save.before', $event_data);
     $event_received = array_pop($event_received);
     if (!empty($event_received['base']) && !empty($event_received['lang'])) {
         $data = $event_received['base'];
         $lang_data = $event_received['lang'];
     }
     // Database save
     $id_media = $this->media_model->save($data, $lang_data);
     // Event
     $event_data = array('base' => $data, 'lang' => $lang_data);
     Event::fire('Media.save.success', $event_data);
     // Save extend fields data
     $this->extend_field_model->save_data('media', $id_media, $_POST);
     // Save parent context data
     $this->media_model->save_context_data($_POST);
     $media = $this->media_model->get($id_media, Settings::get_lang('default'));
     // Delete picture thumbnails
     if ($media['type'] == 'picture') {
         $this->medias->delete_thumbs($media);
     }
     if ($id_media !== FALSE) {
         // Success Message
         $this->callback = array(array('fn' => 'mediaManager.loadMediaList', 'args' => $media['type']), array('fn' => 'ION.notification', 'args' => array('success', lang('ionize_message_media_data_saved'))));
     } else {
         Event::fire('Media.save.error');
         // Error Message
         $this->callback[] = array('fn' => 'ION.notification', 'args' => array('error', lang('ionize_message_media_data_not_saved')));
     }
     $this->response();
 }
Ejemplo n.º 2
0
Archivo: page.php Proyecto: trk/ionize
 /**
  * Saves a page
  *
  */
 public function save()
 {
     /* Check if the default lang URL or the default lang title are set
      * One of these need to be set to save the page
      *
      */
     if ($this->_check_before_save() === TRUE) {
         $id_page = $this->input->post('id_page');
         // Clear the cache
         Cache()->clear_cache();
         // Prepare data before save
         $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('Page.save.before', $event_data);
         $event_received = array_pop($event_received);
         if (!empty($event_received['base']) && !empty($event_received['lang'])) {
             $this->data = $event_received['base'];
             $this->lang_data = $event_received['lang'];
         }
         // Save Page
         $saved_id = $this->page_model->save($this->data, $this->lang_data);
         // Correct Pages levels
         // TODO : Move this into the model.
         if (!empty($id_page)) {
             // Correct pages levels regarding parents.
             $this->system_check_model->check_page_level(TRUE);
         }
         // Save extends fields data
         $this->extend_field_model->save_data('page', $saved_id, $_POST);
         // Save linked access groups authorizations
         // $this->base_model->join_items_keys_to('user_groups', $this->input->post('groups'), 'page', $this->id);
         // Save the Sitemap
         $this->structure->build_sitemap();
         // Prepare the Json answer
         $page = array_merge($this->lang_data[Settings::get_lang('default')], $this->page_model->get_by_id($saved_id));
         $page['menu'] = $this->menu_model->get(array('id_menu' => $page['id_menu']));
         // Remove HTML tags from returned array
         strip_html($page);
         $this->callback = array();
         // Event : On after save
         $event_data = array('base' => $this->data, 'lang' => $this->lang_data, 'post' => $this->input->post());
         Event::fire('Page.save.success', $event_data);
         // New page : Simply reloads the panel
         if (empty($id_page)) {
             // Save the Urls
             $this->page_model->save_urls($saved_id);
             // Used by JS Tree to detect if page in inserted in tree or not
             $page['inserted'] = TRUE;
             $this->callback[] = array('fn' => $page['menu']['name'] . 'Tree.insertElement', 'args' => array($page, 'page'));
             // Reload the panel
             $this->_reload_panel($saved_id);
             $this->success(lang('ionize_message_page_saved'));
         } else {
             // Save options : as callback
             $this->callback[] = array('fn' => 'ION.sendForm', 'args' => array('page/save_options', 'pageOptionsForm'));
             $this->response();
         }
     } else {
         Event::fire('Page.save.error');
         $this->error(lang('ionize_message_page_needs_url_or_title'));
     }
 }
Ejemplo n.º 3
0
 /**
  * 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'));
     }
 }