Esempio n. 1
0
 /**
  * Create a new list based on the current user and $_REQUEST parameters.
  *
  * @return mixed New list ID on success, PEAR_Error on failure.
  * @access public
  */
 public function addList()
 {
     if ($this->_user) {
         if (strlen(trim($_REQUEST['title'])) == 0) {
             return new PEAR_Error('list_edit_name_required');
         }
         $list = new User_list();
         $list->title = $_REQUEST['title'];
         $list->description = $_REQUEST['desc'];
         $list->public = $_REQUEST['public'];
         $list->user_id = $this->_user->id;
         $list->insert();
         $list->find();
         // Remember that the list was used so it can be the default in future
         // dialog boxes:
         $list->rememberLastUsed();
         return $list->id;
     }
 }
Esempio n. 2
0
 /**
  * Save the record specified by GET parameters.
  *
  * @param object $user User who is saving the record.
  *
  * @return bool        True on success, false on failure.
  * @access public
  */
 public static function saveRecord($user)
 {
     // Fail if the user is not logged in:
     if (!$user) {
         return false;
     }
     $list = new User_list();
     if (isset($_GET['list']) && $_GET['list'] != '') {
         $list->id = $_GET['list'];
     } else {
         if (isset($_POST['list']) && $_POST['list'] != '') {
             $list->id = $_POST['list'];
         } else {
             $list->user_id = $user->id;
             $list->title = "My Favorites";
             if (!$list->find(true)) {
                 $list->insert();
             }
         }
     }
     // Remember that the list was used so it can be the default in future
     // dialog boxes:
     $list->rememberLastUsed();
     // Setup Search Engine Connection
     $db = ConnectionManager::connectToIndex('MetaLib');
     // Get Record Information
     $record = $db->getRecord($_GET['id']);
     if (!$record) {
         return false;
     }
     $resource = new Resource();
     $resource->record_id = $_GET['id'];
     $resource->source = 'MetaLib';
     if (!$resource->find(true)) {
         $resource->data = serialize($record);
         $resource->insert();
     } else {
         $resource->data = serialize($record);
         $resource->update();
     }
     preg_match_all('/"[^"]*"|[^ ]+/', isset($_GET['mytags']) ? $_GET['mytags'] : '', $tagArray);
     return $user->addResource($resource, $list, $tagArray[0], isset($_GET['notes']) ? $_GET['notes'] : '');
 }
Esempio n. 3
0
 /**
  * Save the records
  *
  * @return array A list of successfully saved record ids and the list id
  * @access public
  */
 public function saveRecord()
 {
     // Fail if the user is not logged in:
     if (!$this->user || !isset($_POST['ids'])) {
         return false;
     }
     $list = new User_list();
     if ($_REQUEST['list'] != '') {
         $list->id = $_REQUEST['list'];
     } else {
         $list->user_id = $this->user->id;
         $list->title = "My Favorites";
         $list->insert();
     }
     // Remember that the list was used so it can be the default in future
     // dialog boxes:
     $list->rememberLastUsed();
     foreach ($_POST['ids'] as $id) {
         $resource = new Resource();
         $resource->record_id = $id;
         $resource->source = $_REQUEST['service'];
         if (!$resource->find(true)) {
             $resource->insert();
         }
         preg_match_all('/"[^"]*"|[^ ]+/', $_REQUEST['mytags'], $tagArray);
         $result['details'][$id] = $this->user->addResource($resource, $list, $tagArray[0], false, false);
     }
     $result['list'] = $list->id;
     return $result;
 }