예제 #1
0
 /**
  * Edit feed
  *
  * @param	integer	$feed_id
  * @param	array	$data
  * @return	boolean	true on succes, or false on fail
  */
 public function edit_feed($feed_id, $data)
 {
     if (!$this->check_token()) {
         return false;
     }
     $sm = vivvo_lite_site::get_instance();
     if ($sm->user and $sm->user->can('MANAGE_PLUGIN', 'feed_importer')) {
         if (!vivvo_hooks_manager::call('feed_edit', array(&$feed_id, &$data))) {
             return vivvo_hooks_manager::get_status();
         }
         $feed_list = new Feeds_list();
         $feed_list->search(array());
         if (!empty($data['feed'])) {
             $remove_keys = array_diff(array_keys($feed_list->list), array_keys($data['feed']));
         } else {
             $remove_keys = array_keys($feed_list->list);
         }
         if (!empty($remove_keys)) {
             $feed_list->sql_delete_list($this->_post_master, $remove_keys);
         }
         $edit_keys = $feed_list->get_list_ids();
         $feed_check = array();
         require_once VIVVO_FS_INSTALL_ROOT . 'lib/simplepie/simplepie.php';
         if (is_array($edit_keys) and !empty($edit_keys)) {
             foreach ($edit_keys as $edit_key) {
                 if (!in_array($data['feed'][$edit_key]['feed'], $feed_check)) {
                     $feed_check[] = $data['feed'][$edit_key]['feed'];
                     $feed_list->list[$edit_key]->set_feed($data['feed'][$edit_key]['feed']);
                     $feed_list->list[$edit_key]->set_category_id($data['feed'][$edit_key]['category_id']);
                     $feed_list->list[$edit_key]->set_author($data['feed'][$edit_key]['author']);
                     $simplepie = new SimplePie();
                     $simplepie->enable_cache(false);
                     $simplepie->set_feed_url($data['feed'][$edit_key]['feed']);
                     @$simplepie->init();
                     if (!$simplepie->error()) {
                         $feed_list->list[$edit_key]->set_favicon($simplepie->get_favicon());
                         $this->_post_master->set_data_object($feed_list->list[$edit_key]);
                         $this->_post_master->sql_update();
                     }
                 } else {
                     $this->_post_master->set_data_object($feed_list->list[$edit_key]);
                     $this->_post_master->sql_delete();
                 }
             }
         }
         if (is_array($data['new_feed']) and !empty($data['new_feed'])) {
             foreach ($data['new_feed'] as $add_key => $value) {
                 if (!in_array($data['new_feed'][$add_key]['feed'], $feed_check)) {
                     $feed_check[] = $data['new_feed'][$add_key]['feed'];
                     $new_feed_object = new Feeds();
                     $new_feed_object->set_feed($data['new_feed'][$add_key]['feed']);
                     $new_feed_object->set_category_id($data['new_feed'][$add_key]['category_id']);
                     $new_feed_object->set_author($data['new_feed'][$add_key]['author']);
                     $simplepie = new SimplePie();
                     $simplepie->enable_cache(false);
                     $simplepie->set_feed_url($data['new_feed'][$add_key]['feed']);
                     @$simplepie->init();
                     if (!$simplepie->error()) {
                         $new_feed_object->set_favicon($simplepie->get_favicon());
                         $this->_post_master->set_data_object($new_feed_object);
                         $this->_post_master->sql_insert();
                     }
                 }
             }
         }
         return true;
     } else {
         $this->set_error_code(10103);
         // you don't have sufficient privileges for this action
         return false;
     }
 }