コード例 #1
0
ファイル: Storage.php プロジェクト: raz0rsdge/horde
 /**
  * Retrieves the current user's gallery list from storage.
  *
  * @param array $params  Optional parameters:
  *   <pre>
  *     (integer)perm      The permissions filter to use [Horde_Perms::SHOW]
  *     (mixed)attributes  Restrict the galleries returned to those matching
  *                        the filters. Can be an array of attribute/values
  *                        pairs or a gallery owner username.
  *     (integer)parent    The parent share to start listing at.
  *     (boolean)all_levels If set, return all levels below parent, not just
  *                        direct children [TRUE]
  *     (integer)from      The gallery to start listing at.
  *     (integer)count     The number of galleries to return.
  *     (string)sort_by    Attribute to sort by.
  *     (integer)direction The direction to sort by [Ansel::SORT_ASCENDING]
  *     (array)tags        An array of tags to limit results by.
  *   </pre>
  *
  * @return array An array of Ansel_Gallery objects
  * @throws Ansel_Exception
  */
 public function listGalleries($params = array())
 {
     $galleries = array();
     try {
         if (!empty($params['tags'])) {
             $count = !empty($params['count']) ? $params['count'] : null;
             $from = !empty($params['from']) ? $params['from'] : null;
             unset($params['count'], $params['from']);
             $shares = $this->_shares->listShares($GLOBALS['registry']->getAuth(), $params);
             if (!empty($params['attributes']) && !is_array($params['attributes'])) {
                 $user = $params['attributes'];
             } elseif (!empty($params['attributes']['owner'])) {
                 $user = $params['attributes']['owner'];
             } else {
                 $user = null;
             }
             $tagged = $GLOBALS['injector']->getInstance('Ansel_Tagger')->search($params['tags'], array('type' => 'gallery', 'user' => $user));
             foreach ($shares as $share) {
                 if (in_array($share->getId(), $tagged['galleries'])) {
                     $galleries[] = $share;
                 }
             }
             $galleries = array_slice($galleries, $from, $count);
         } else {
             $galleries = $this->_shares->listShares($GLOBALS['registry']->getAuth(), $params);
         }
         $shares = $this->buildGalleries($galleries);
     } catch (Horde_Share_Exception $e) {
         throw new Ansel_Exception($e);
     }
     return $shares;
 }
コード例 #2
0
ファイル: Manager.php プロジェクト: raz0rsdge/horde
 /**
  * List queries.
  */
 public function listQueries($user, $return_slugs = false)
 {
     try {
         $shares = $this->_shareManager->listShares($user);
     } catch (Horde_Share_Exception $e) {
         throw new Whups_Exception($e);
     }
     $queries = array();
     foreach ($shares as $share) {
         $queries[$share->getId()] = $return_slugs ? array('name' => $share->get('name'), 'slug' => $share->get('slug')) : $share->get('name');
     }
     return $queries;
 }
コード例 #3
0
ファイル: Utils.php プロジェクト: horde/horde
 /**
  * Synchronize Horde_Shares to existing IMSP address books.
  *
  * @param Horde_Share $share_obj  The Horde_Share object to use.
  * @param array $serverInfo       Information about the IMSP server and
  *                                the current user.
  *
  * @return mixed  Array describing any shares added or removed  | PEAR_Error.
  */
 public function synchShares($share_obj, array $serverInfo)
 {
     $found_shares = array();
     $return = array('added' => array(), 'removed' => array());
     $params = array();
     $imsp = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imsp')->create('Book', $serverInfo['params']);
     $abooks = $imsp->getAddressBookList();
     // Do we have a default address book? If not, create one.
     if (array_search($serverInfo['params']['username'], $abooks) === false) {
         $imsp->createAddressbook($serverInfo['params']['username']);
         // Make sure we add it to our list of books.
         $abooks[] = $serverInfo['params']['username'];
     }
     $shares = $share_obj->listShares($GLOBALS['registry']->getAuth());
     // A share for each IMSP adress book we can see.
     foreach ($abooks as $abook_uid) {
         $found = false;
         foreach ($shares as $share) {
             $params = @unserialize($share->get('params'));
             if (!empty($params['name']) && $params['name'] == $abook_uid && $params['source'] == 'imsp') {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $shareparams = array('name' => $abook_uid, 'source' => 'imsp');
             $params['uid'] = hash('md5', mt_rand());
             $params['name'] = $abook_uid . ' (IMSP)';
             $params['acl'] = $imsp->myRights($abook_uid);
             if ($abook_uid == $serverInfo['params']['username']) {
                 // This is the default address book
                 $shareparams['default'] = true;
             } else {
                 $shareparams['default'] = false;
             }
             if (self::_isOwner($abook_uid, $serverInfo['params']['username'], $params['acl'])) {
                 $params['owner'] = $GLOBALS['registry']->getAuth();
             } else {
                 // TODO: What to do for the owner when it's not current user?
                 //       We'd have to try to match the owner per IMSP
                 //       address book name to a Horde user...how to do that
                 //       without assuming usernames are equal?
             }
             self::_createShare($share_obj, $params, $shareparams);
             $return['added'][] = $params['uid'];
         } else {
             // Share already exists, just update the acl.
             $params['acl'] = $imsp->myRights($abook_uid);
         }
         $found_shares[] = $abook_uid;
     }
     // Now prune any shares that no longer exist on the IMSP server.
     $existing = $share_obj->listShares($GLOBALS['registry']->getAuth(), array('perm' => Horde_Perms::READ));
     foreach ($existing as $share) {
         $temp = unserialize($share->get('params'));
         if (is_array($temp)) {
             $sourceType = $temp['source'];
             if ($sourceType == 'imsp' && array_search($temp['name'], $found_shares) === false) {
                 $share_obj->removeShare($share);
                 $return['removed'][] = $share->getName();
             }
         }
     }
     return $return;
 }