From ad4119ca475055641514384eb4541e53948e0824 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 3 Aug 2009 15:25:43 -0600 Subject: [PATCH] Convert to new API framework. --- ansel/lib/Api.php | 1342 ++++++++++++++++++++++++++++ ansel/lib/api.php | 1335 ---------------------------- ansel/lib/version.php | 1 - ansel/rss.php | 3 +- ansel/test.php | 5 +- babel/lib/Api.php | 74 ++ babel/lib/api.php | 79 -- chora/lib/Api.php | 41 + chora/lib/api.php | 39 - chora/lib/version.php | 1 - chora/test.php | 5 +- crumb/lib/Api.php | 5 + crumb/lib/version.php | 1 - fima/lib/Api.php | 5 + fima/lib/version.php | 1 - folks/lib/Api.php | 576 ++++++++++++ folks/lib/api.php | 563 ------------ folks/lib/version.php | 1 - gollem/lib/Api.php | 651 ++++++++++++++ gollem/lib/api.php | 605 ------------- gollem/lib/version.php | 1 - gollem/test.php | 5 +- imp/acl.php | 3 +- imp/lib/Api.php | 819 +++++++++++++++++ imp/lib/api.php | 795 ----------------- imp/lib/version.php | 1 - imp/test.php | 5 +- ingo/lib/Api.php | 371 ++++++++ ingo/lib/api.php | 352 -------- ingo/lib/version.php | 1 - ingo/test.php | 5 +- jeta/lib/Api.php | 5 + jeta/lib/version.php | 1 - jeta/test.php | 5 +- kastalia/lib/Api.php | 5 + kastalia/lib/version.php | 1 - kronolith/lib/Api.php | 1544 ++++++++++++++++++++++++++++++++ kronolith/lib/api.php | 1536 -------------------------------- kronolith/lib/version.php | 1 - kronolith/test.php | 5 +- nag/lib/Api.php | 1528 ++++++++++++++++++++++++++++++++ nag/lib/api.php | 1461 ------------------------------- nag/lib/version.php | 1 - news/lib/Api.php | 161 ++++ news/lib/api.php | 155 ---- news/lib/version.php | 1 - skeleton/lib/Api.php | 5 + skeleton/lib/version.php | 1 - skoli/lib/Api.php | 5 + skoli/lib/version.php | 1 - timeobjects/lib/Api.php | 92 ++ timeobjects/lib/api.php | 77 -- turba/lib/Api.php | 2132 +++++++++++++++++++++++++++++++++++++++++++++ turba/lib/api.php | 2064 ------------------------------------------- turba/lib/version.php | 1 - turba/test.php | 5 +- 56 files changed, 9387 insertions(+), 9097 deletions(-) create mode 100644 ansel/lib/Api.php delete mode 100644 ansel/lib/api.php delete mode 100755 ansel/lib/version.php create mode 100644 babel/lib/Api.php delete mode 100644 babel/lib/api.php create mode 100644 chora/lib/Api.php delete mode 100644 chora/lib/api.php delete mode 100644 chora/lib/version.php create mode 100644 crumb/lib/Api.php delete mode 100644 crumb/lib/version.php create mode 100644 fima/lib/Api.php delete mode 100644 fima/lib/version.php create mode 100644 folks/lib/Api.php delete mode 100644 folks/lib/api.php delete mode 100644 folks/lib/version.php create mode 100644 gollem/lib/Api.php delete mode 100644 gollem/lib/api.php delete mode 100644 gollem/lib/version.php create mode 100644 imp/lib/Api.php delete mode 100644 imp/lib/api.php delete mode 100644 imp/lib/version.php create mode 100644 ingo/lib/Api.php delete mode 100644 ingo/lib/api.php delete mode 100644 ingo/lib/version.php create mode 100644 jeta/lib/Api.php delete mode 100644 jeta/lib/version.php create mode 100644 kastalia/lib/Api.php delete mode 100755 kastalia/lib/version.php create mode 100644 kronolith/lib/Api.php delete mode 100644 kronolith/lib/api.php delete mode 100644 kronolith/lib/version.php create mode 100644 nag/lib/Api.php delete mode 100644 nag/lib/api.php delete mode 100644 nag/lib/version.php create mode 100644 news/lib/Api.php delete mode 100644 news/lib/api.php delete mode 100755 news/lib/version.php create mode 100644 skeleton/lib/Api.php delete mode 100644 skeleton/lib/version.php create mode 100644 skoli/lib/Api.php delete mode 100644 skoli/lib/version.php create mode 100644 timeobjects/lib/Api.php delete mode 100644 timeobjects/lib/api.php create mode 100644 turba/lib/Api.php delete mode 100644 turba/lib/api.php delete mode 100644 turba/lib/version.php diff --git a/ansel/lib/Api.php b/ansel/lib/Api.php new file mode 100644 index 000000000..e4d600d38 --- /dev/null +++ b/ansel/lib/Api.php @@ -0,0 +1,1342 @@ + + * @author Chuck Hagenbuch + * @author Michael J. Rubinsky + * @package Ansel + */ +class Ansel_Api extends Horde_Registry_Api +{ + public $version = 'H4 (2.0-git)'; + + public $services = array( + 'perms' => array( + 'args' => array(), + 'type' => '{urn:horde}stringArray' + ), + + 'browse' => array( + 'args' => array('path' => 'string'), + 'type' => '{urn:horde}hashHash', + ), + + 'put' => array( + 'args' => array('path' => 'string', 'content' => 'string', 'content_type' => 'string'), + 'type' => '{urn:horde}stringArray', + ), + + // 'path_delete' => array( + // 'args' => array('path' => 'string'), + // 'type' => 'boolean', + // ), + + 'commentCallback' => array( + 'args' => array('image_id' => 'string'), + 'type' => 'string' + ), + + 'hasComments' => array( + 'args' => array(), + 'type' => 'boolean' + ), + + 'saveImage' => array( + 'args' => array('app' => 'string', + 'gallery_id' => 'string', + 'image' => '{urn:horde}hashHash', + 'default' => 'boolean', + 'gallery_data' => '{urn:horde}hashHash', + 'encoding' => 'string', + 'slug' => 'string', + 'compression' => 'string', + 'skiphook' => 'boolean'), + 'type' => '{urn:horde}stringArray' + ), + + 'postBatchUpload' => array( + 'args' => array('image_ids' => '{urn:horde}hash'), + 'type' => 'int' + ), + + 'createGallery' => array( + 'args' => array('app' => 'string', + 'attributes' => '{urn:horde}hashHash', + 'perm' => '{urn:horde}hashHash'), + 'type' => 'int' + ), + + 'removeImage' => array( + 'args' => array('app' => 'string', + 'gallery_id' => 'integer', + 'image_id' => 'integer'), + 'type' => 'int' + ), + + 'removeGallery' => array( + 'args' => array('app' => 'string', + 'gallery_id' => 'integer'), + 'type' => 'int' + ), + + 'getImageUrl' => array( + 'args' => array('app' => 'string', + 'image_id' => 'integer', + 'view' => 'string', + 'full' => 'boolean', + 'style' => 'string'), + 'type' => 'string' + ), + + 'getImageContent' => array( + 'args' => array('image_id' => 'integer', + 'view' => 'string', + 'style' => 'string', + 'app' => 'string'), + 'type' => 'string' + ), + + 'count' => array( + 'args' => array('app' => 'string', + 'gallery_id' => 'integer'), + 'type' => 'int' + ), + + 'getDefaultImage' => array( + 'args' => array('app' => 'string', + 'gallery_id' => 'integer', + 'style' => 'string'), + 'type' => 'string' + ), + + 'listGalleries' => array( + 'args' => array('app' => 'string', + 'perm' => 'integer', + 'parent' => 'string', + 'allLevels' => 'string', + 'from' => 'integer', + 'count' => 'integer'), + 'type' => 'string' + ), + + 'getGalleries' => array( + 'args' => array('ids' => '{urn:horde}hash', + 'app' => 'string'), + 'type' => '{urn:horde}hash' + ), + + 'selectGalleries' => array( + 'args' => array('app' => 'string', + 'perm' => 'integer', + 'parent' => 'string', + 'allLevels' => 'string', + 'from' => 'integer', + 'count' => 'integer'), + 'type' => 'string' + ), + + 'listImages' => array( + 'args' => array('app' => 'string', + 'gallery_id' => 'integer', + 'perm' => 'integer', + 'view' => 'string', + 'full' => 'boolean', + 'from' => 'integer', + 'count' => 'integer', + 'style' => 'string'), + 'type' => 'string' + ), + + 'getRecentImages' => array( + 'args' => array('app' => 'string', + 'galleries' => '{urn:horde}hash', + 'perms' => 'integer', + 'view' => 'string', + 'full' => 'boolean', + 'limit' => 'integer', + 'style' => 'string', + 'slugs' => '{urn:horde}hashHash'), + 'type' => '{urn:horde}hash' + ), + + 'countGalleries' => array( + 'args' => array('app' => 'string', + 'perm' => 'string', + 'attributes' => '{urn:horde}hash', + 'parent' => 'string', + 'allLevels' => 'boolean'), + 'type' => 'int' + ), + + 'listTagInfo' => array( + 'args' => array('tags' => '{urn:horde}stringArray'), + 'type' => '{urn:horde}hash' + ), + + 'searchTags' => array( + 'args' => array('tags' => '{urn:horde}stringArray', + 'resource_type' => 'string', + 'count' => 'int', + 'user' => 'string'), + 'type' => '{urn:horde}hash' + ), + + 'galleryExists' => array( + 'args' => array('app' => 'string', + 'gallery_name' => 'string'), + 'type' => 'boolean' + ), + + 'renderView' => array( + 'args' => array('parameters' => '{urn:horde]stringArray', + 'app' => 'string', + 'view' => 'string'), + 'type' => 'string' + ), + + 'getGalleryStyles' => array( + 'args' => array(), + 'type' => '{urn:horde}hash' + ) + ); + + /** + * Returns a list of available permissions. + * + * @return array An array describing all available permissions. + */ + public function perms() + { + $perms = array(); + $perms['tree']['ansel']['admin'] = false; + $perms['title']['ansel:admin'] = _("Administrators"); + + return $perms; + } + + /** + * Browse through Ansel's gallery tree. + * + * @param string $path The level of the tree to browse. + * @param array $properties The item properties to return. Defaults to 'name', + * 'icon', and 'browseable'. + * + * @return array The contents of $path + */ + public function browse($path = '', $properties = array()) + { + require_once dirname(__FILE__) . '/base.php'; + + // Default properties. + if (!$properties) { + $properties = array('name', 'icon', 'browseable'); + } + + if (substr($path, 0, 5) == 'ansel') { + $path = substr($path, 5); + } + $path = trim($path, '/'); + $parts = explode('/', $path); + + if (empty($path)) { + $owners = array(); + $galleries = $GLOBALS['ansel_storage']->listGalleries(PERMS_SHOW, null, null, false); + foreach ($galleries as $gallery) { + $owners[$gallery->data['share_owner']] = true; + } + + $results = array(); + foreach (array_keys($owners) as $owner) { + if (in_array('name', $properties)) { + $results['ansel/' . $owner]['name'] = $owner; + } + if (in_array('icon', $properties)) { + $results['ansel/' . $owner]['icon'] = + $registry->getImageDir('horde') . '/user.png'; + } + if (in_array('browseable', $properties)) { + $results['ansel/' . $owner]['browseable'] = true; + } + if (in_array('contenttype', $properties)) { + $results['ansel/' . $owner]['contenttype'] = + 'httpd/unix-directory'; + } + if (in_array('contentlength', $properties)) { + $results['ansel/' . $owner]['contentlength'] = 0; + } + if (in_array('modified', $properties)) { + $results['ansel/' . $owner]['modified'] = time(); + } + if (in_array('created', $properties)) { + $results['ansel/' . $owner]['created'] = 0; + } + } + return $results; + + } else { + if (count($parts) == 1) { + // This request is for all galleries owned by the requested user. + $galleries = $GLOBALS['ansel_storage']->listGalleries( + PERMS_SHOW, $parts[0], null, false); + $images = array(); + } elseif ($this->galleryExists(null, end($parts))) { + // This request if for a certain gallery, list all sub-galleries + // and images. + $gallery_id = end($parts); + $galleries = $GLOBALS['ansel_storage']->getGalleries( + array($gallery_id)); + if (!isset($galleries[$gallery_id]) || + !$galleries[$gallery_id]->hasPermission(Horde_Auth::getAuth(), + PERMS_READ)) { + return PEAR::raiseError(_("Invalid gallery specified."), 404); + } + $galleries = $GLOBALS['ansel_storage']->listGalleries( + PERMS_SHOW, null, $gallery_id, false); + + $images = $this->listImages(null, $gallery_id, PERMS_SHOW, 'mini'); + } elseif (count($parts) > 2 && + $this->galleryExists(null, $parts[count($parts) - 2]) && + !is_a($image = $GLOBALS['ansel_storage']->getImage(end($parts)), 'PEAR_Error')) { + return array('data' => $image->raw(), + 'mimetype' => $image->type, + 'mtime' => $image->uploaded); + } else { + return PEAR::raiseError(_("File not found."), 404); + } + + $results = array(); + foreach ($galleries as $galleryId => $gallery) { + $retpath = 'ansel/' . implode('/', $parts) . '/' . $galleryId; + if (in_array('name', $properties)) { + $results[$retpath]['name'] = $gallery->data['attribute_name']; + } + if (in_array('displayname', $properties)) { + $results[$retpath]['displayname'] = rawurlencode( + $gallery->data['attribute_name']); + } + if (in_array('icon', $properties)) { + $results[$retpath]['icon'] = $registry->getImageDir() + . '/ansel.png'; + } + if (in_array('browseable', $properties)) { + $results[$retpath]['browseable'] = $gallery->hasPermission( + Horde_Auth::getAuth(), PERMS_READ); + } + if (in_array('contenttype', $properties)) { + $results[$retpath]['contenttype'] = 'httpd/unix-directory'; + } + if (in_array('contentlength', $properties)) { + $results[$retpath]['contentlength'] = 0; + } + if (in_array('modified', $properties)) { + $results[$retpath]['modified'] = time(); + } + if (in_array('created', $properties)) { + $results[$retpath]['created'] = 0; + } + } + + foreach ($images as $imageId => $image) { + $retpath = 'ansel/' . implode('/', $parts) . '/' . $imageId; + if (in_array('name', $properties)) { + $results[$retpath]['name'] = $image['name']; + } + if (in_array('displayname', $properties)) { + $results[$retpath]['displayname'] = rawurlencode($image['name']); + } + if (in_array('icon', $properties)) { + $results[$retpath]['icon'] = Horde::url($image['url'], true); + } + if (in_array('browseable', $properties)) { + $results[$retpath]['browseable'] = false; + } + if (in_array('contenttype', $properties)) { + $results[$retpath]['contenttype'] = $image['type']; + } + if (in_array('contentlength', $properties)) { + $results[$retpath]['contentlength'] = 0; + } + if (in_array('modified', $properties)) { + $results[$retpath]['modified'] = $image['uploaded']; + } + if (in_array('created', $properties)) { + $results[$retpath]['created'] = $image['uploaded']; + } + } + return $results; + + } + + return PEAR::raiseError(_("File not found."), 404); + } + + /** + * Saves an image into the gallery tree. + * + * @param string $path The path where to PUT the file. + * @param string $content The file content. + * @param string $content_type The file's content type. + * + * @return array The event UIDs, or a PEAR_Error on failure. + */ + public function put($path, $content, $content_type) + { + require_once dirname(__FILE__) . '/base.php'; + + if (substr($path, 0, 5) == 'ansel') { + $path = substr($path, 9); + } + $path = trim($path, '/'); + $parts = explode('/', $path); + + if (count($parts) < 3) { + return PEAR::raiseError("Gallery does not exist"); + } + $image_name = array_pop($parts); + $gallery_id = end($parts); + if (!$GLOBALS['ansel_storage']->galleryExists($gallery_id)) { + return PEAR::raiseError("Gallery does not exist"); + } + $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); + if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT)) { + return PEAR::raiseError(_("Access denied adding photos to \"%s\".")); + } + + return $gallery->addImage(array('image_type' => $content_type, + 'image_filename' => $image_name, + 'image_caption' => '', + 'data' => $content)); + } + + /** + * Callback for Agora comments. + * + * @param integer $image_id Image id to check + * + * @return mixed Image filename on success | false on failure + */ + public function commentCallback($image_id) + { + require_once dirname(__FILE__) . '/base.php'; + + if (!$GLOBALS['conf']['comments']['allow']) { + return false; + } + + $image = $GLOBALS['ansel_storage']->getImage($image_id); + if (!$image || is_a($image, 'PEAR_Error')) { + return false; + } + + return $image->filename; + } + + /** + * Checks if applications allows comments + * + * @return boolean + */ + public function hasComments() + { + if (($GLOBALS['conf']['comments']['allow'] == 'all' || + ($GLOBALS['conf']['comments']['allow'] == 'authenticated' && + Horde_Auth::getAuth()))) { + return true; + } else { + return false; + } + } + + /** + * Returns decoded image data + * + * @param string $data The id of the image. + * @param string $encoding The encoding type for the image data. + * (none, base64, or binhex) + * @param string $compression The compression type for the image data. + * (none, gzip, or lzf) + * @param boolean $upload Process direction (true of encode/compress or false if decode/decompress) + * + * @return string The image path. + */ + protected function _getImageData($data, $encoding = 'none', $compression = 'none', $upload = true) + { + switch ($encoding) { + case 'base64': + $data = $upload ? base64_decode($data) : base64_encode($data); + break; + + case 'binhex': + $data = $upload ? pack('H*', $data) : unpack('H*', $data); + } + + switch ($compression) { + case 'gzip': + if (Horde_Util::loadExtension('zlib')) { + return $upload ? gzuncompress($data) : gzcompress($data); + } + break; + + case 'lzf': + if (Horde_Util::loadExtension('lzf')) { + return $upload ? lzf_decompress($data) : lzf_compress($data); + } + break; + + default: + return $data; + } + } + + /** + * Stores an image in a gallery and returns gallery and image data. + * + * @param integer $app Application used if null then use default. + * @param integer $gallery_id The gallery id to add the image to. + * @param array $image Image data array. This can either be the return + * from Horde_Form_Type_image:: or an array with + * the following four fields: + * 'filename', 'description', 'data', 'type' + * @param integer $default Set this image as default in the gallery? + * @param array $gallery_data Any gallery parameters to change at this time. + * @param string $encoding The encoding type for the image data. + * (none, base64, or binhex) + * @param string $slug Use gallery slug instead of id. (Pass '0' or null + * to gallery_id parameter). + * @param string $compression The compression type for the image data. + * (none, gzip, or lzf) + * + * @return mixed An array of image/gallery data || PEAR_Error + */ + public function saveImage($app = null, $gallery_id, $image, $default = false, + $gallery_data = null, $encoding = null, $slug = null, + $compression = 'none', $skiphook = false) + { + require_once dirname(__FILE__) . '/base.php'; + + $image_data = null; + + /* If no app is given use Ansel's own gallery which is initialized + * in base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + if (isset($image['filename']) && + isset($image['description']) && + isset($image['data']) && + isset($image['type'])) { + Horde::logMessage(sprintf("Receiving image %s in saveImage() with a raw filesize of %i", $image['filename'], strlen($image['data'])), __FILE__, __LINE__, PEAR_LOG_DEBUG); + $image_data = array('image_filename' => $image['filename'], + 'image_caption' => $image['description'], + 'image_type' => $image['type'], + 'data' => $this->_getImageData($image['data'], $encoding, $compression, true)); + } else { + Horde::logMessage(sprintf("Receiving image %s in saveImage() with a raw filesize of %i", $image['file'], filesize($image['file'])), __FILE__, __LINE__, PEAR_LOG_DEBUG); + } + + if (is_null($image_data) && getimagesize($image['file']) === false) { + return PEAR::raiseError(_("The file you uploaded does not appear to be a valid photo.")); + } + if (empty($slug) && empty($gallery_id)) { + return PEAR::raiseError(_("A gallery to add this photo to is required.")); + } + if (!empty($slug)) { + $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug); + if (is_a($gallery, 'PEAR_Error')) { + return $gallery; + } + } elseif ($GLOBALS['ansel_storage']->galleryExists($gallery_id)) { + $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); + if (is_a($gallery, 'PEAR_Error')) { + return $gallery; + } + } + if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT)) { + return PEAR::raiseError(sprintf(_("Access denied adding photos to \"%s\"."), $gallery->get('name'))); + } + if (!empty($gallery_data)) { + foreach ($gallery_data as $key => $value) { + $gallery->set($key, $value); + } + $gallery->save(); + } + + if (is_null($image_data)) { + $image_data = array( + 'image_filename' => $image['name'], + 'image_caption' => $image['name'], + 'image_type' => $image['name']['type'], + 'data' => file_get_contents($image['file']), + ); + } + + if (isset($image['tags']) && is_array($image['tags']) && + count($image['tags'])) { + $image_data['tags'] = $image['tags']; + } + + $image_id = $gallery->addImage($image_data, $default); + if (is_a($image_id, 'PEAR_Error')) { + return $image_id; + } + + // Call the postupload hook if needed + if (!empty($GLOBALS['conf']['hooks']['postupload']) && !$skiphook) { + Horde::callHook('_ansel_hook_postupload', array(array($image_id)), 'ansel'); + } + + return array('image_id' => (int)$image_id, + 'gallery_id' => (int)$gallery->id, + 'gallery_slug' => $gallery->get('slug'), + 'image_count' => (int)$gallery->countImages()); + } + + /** + * Notify Ansel that a group of images has just been uploaded. Used for when + * the _ansel_hook_postupload hook should be called with a group of recently + * uploaded images, as opposed to calling it once after each image is saved. + * + * @param array $image_ids An array of image ids. + */ + public function postBatchUpload($image_ids) + { + require_once dirname(__FILE__) . '/base.php'; + if (!empty($conf['hooks']['postupload'])) { + return Horde::callHook('_ansel_hook_postupload', array($image_ids), 'ansel'); + } + } + + /** + * Removes an image from a gallery. + * + * @param string $app Application scope to use, if not the default. + * @param integer $gallery_id The id of gallery. + * @param string $image_id The id of image to remove. + */ + public function removeImage($app = null, $gallery_id, $image_id) + { + require_once dirname(__FILE__) . '/base.php'; + + /* Check global Ansel permissions */ + if (!($GLOBALS['perms']->getPermissions('ansel'))) { + return PEAR::raiseError(_("Access denied deleting galleries.")); + } + + /* If no app is given use Ansel's own gallery which is initialized in + base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + $image = $GLOBALS['ansel_storage']->getImage($image_id); + if (is_a($image, 'PEAR_Error')) { + return $image; + } + $gallery = $GLOBALS['ansel_storage']->getGallery($image->gallery); + if (is_a($gallery, 'PEAR_Error') || + !$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE)) { + + return PEAR::raiseError(sprintf(_("Access denied deleting photos from \"%s\"."), $gallery->get('name'))); + } + return $gallery->removeImage($image); + } + + /** + * Add a new gallery to any arbitrary application's Ansel_Shares. + * + * @param string $app Application scope to use, if not the default. + * @param array $attributes The gallery attributes + * (@see Ansel_Storage::createGallery). + * @param array $perm An array of permission data if Ansel's defaults + * are not desired. Takes an array like: + * array('guest' => PERMS_SHOW | PERMS_READ, + * 'default' => PERMS_SHOW | PERMS_READ); + * @param integer $parent The gallery id of the parent gallery, if any. + * + * @return mixed The gallery id of the new gallery | PEAR_Error + */ + public function createGallery($app = null, $attributes = array(), $perm = null, $parent = null) + { + require_once dirname(__FILE__) . '/base.php'; + + if (!(Horde_Auth::isAdmin() || + (!$GLOBALS['perms']->exists('ansel') && Horde_Auth::getAuth()) || + $GLOBALS['perms']->hasPermission('ansel', Horde_Auth::getAuth(), PERMS_EDIT))) { + return PEAR::raiseError(_("Access denied creating new galleries.")); + } + + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + if (!empty($perm)) { + // The name is inconsequential; it is only used as a container to + // represent permissions when passed to the Ansel backend. + $permobj = new Horde_Permission(''); + $permobj->data = $perm; + } else { + $permobj = null; + } + + $gallery = $GLOBALS['ansel_storage']->createGallery($attributes, $permobj, $parent); + if (is_a($gallery, 'PEAR_Error')) { + return $gallery; + } + return $gallery->id; + } + + /** + * Removes a gallery and its images. + * + * @param string $app Application scope to use, if not the default. + * @param integer $gallery_id The id of gallery. + * + * @return mixed boolean true | PEAR_Error + */ + public function removeGallery($app = null, $gallery_id) + { + require_once dirname(__FILE__) . '/base.php'; + + /* Check global Ansel permissions */ + if (!($GLOBALS['perms']->getPermissions('ansel'))) { + return PEAR::raiseError(_("Access denied deleting galleries.")); + } + + /* If no app is given use Ansel's own gallery which is initialized in + base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); + if (is_a($gallery, 'PEAR_Error')) { + return PEAR::raiseError(sprintf(_("Access denied deleting gallery \"%s\"."), + $gallery->getMessage())); + } elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE)) { + return PEAR::raiseError(sprintf(_("Access denied deleting gallery \"%s\"."), + $gallery->get('name'))); + } else { + $imageList = $gallery->listImages(); + if ($imageList) { + foreach ($imageList as $id) { + $gallery->removeImage($id); + } + } + $result = $GLOBALS['ansel_storage']->removeGallery($gallery); + if (!is_a($result, 'PEAR_Error')) { + return true; + } else { + return PEAR::raiseError(sprintf(_("There was a problem deleting %s: %s"), + $gallery->get('name'), + $result->getMessage())); + } + } + } + + /** + * Returns the number of images in a gallery. + * + * @param integer $app Application used; if null then use default. + * @param integer $gallery_id The gallery id. + * @param string $slug The gallery slug. + * + * @return integer The number of images in the gallery. + */ + public function count($app = null, $gallery_id = null, $slug = '') + { + require_once dirname(__FILE__) . '/base.php'; + + /* If no app is given use Ansel's own gallery which is initialized in + base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + if (!empty($slug)) { + $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug); + } else { + $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); + } + + if (is_a($gallery, 'PEAR_Error')) { + return 0; + } else { + return (int)$gallery->countImages(); + } + } + + /** + * Returns the default image id of a gallery. + * + * @param string $app Application scope to use, if not the default. + * @param integer $gallery_id The gallery id. + * @param string $style The named style. + * @param string $slug The gallery slug. + * + * @return integer The default image id. + */ + public function getDefaultImage($app = null, $gallery_id = null, + $style = 'ansel_default', $slug = '') + { + require_once dirname(__FILE__) . '/base.php'; + + /* If no app is given use Ansel's own gallery which is initialized in + base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + if (!empty($slug)) { + $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug); + } else { + $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); + } + + if (is_a($gallery, 'PEAR_Error')) { + return $gallery; + } else { + return $gallery->getDefaultImage($style); + } + } + + /** + * Returns image URL. + * + * @param integer $app Application used. + * @param integer $image_id The id of the image. + * @param string $view The view ('screen', 'thumb', 'full', etc) to show. + * @param boolean $full Return a path that includes the server name? + * @param string $style Use this gallery style + * + * @return string The image path. + */ + public function getImageUrl($app = null, $image_id, $view = 'screen', + $full = false, $style = null) + { + require_once dirname(__FILE__) . '/base.php'; + + /* If no app is given use Ansel's own gallery which is initialized in + base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + return Ansel::getImageUrl($image_id, $view, $full, $style); + } + + /** + * Returns image file content. + * + * @param integer $image_id The id of the image. + * @param string $view The view ('screen', 'thumb', 'full', etc) to show. + * @param string $style Force use of this gallery style. + * @param integer $app Application used. + * @param string $encoding The encoding type for the image data. + * (none, base64, or binhex) + * @param string $compression The compression type for the image data. + * (none, gzip, or lzf) + * + * @return string The image path. + */ + public function getImageContent($image_id, $view = 'screen', $style = null, + $app = null, $encoding = null, $compression = 'none') + { + require_once dirname(__FILE__) . '/base.php'; + + /* If no app is given use Ansel's own gallery which is initialized in + base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + // Get image + $image = $GLOBALS['ansel_storage']->getImage($image_id); + if (is_a($image, 'PEAR_Error')) { + return $image; + } + + // Get gallery + $gallery = $GLOBALS['ansel_storage']->getGallery($image->gallery); + if (is_a($gallery, 'PEAR_Error')) { + return $gallery; + } + + // Check age and password + if (!$gallery->hasPasswd() || !$gallery->isOldEnough()) { + return PEAR::raiseError(_("Locked galleries are not viewable via the api.")); + } + + if ($view == 'full') { + // Check permissions for full view + if (!$gallery->canDownload()) { + return PEAR::RaiseError(sprintf(_("Access denied downloading photos from \"%s\"."), $gallery->get('name'))); + } + + $data = $GLOBALS['ansel_vfs']->read($image->getVFSPath('full'), + $image->getVFSName('full')); + } else { + // Load View + $result = $image->load($view, $style); + if (is_a($result, 'PEAR_Error')) { + return $result; + } + + // Return image content + $data = $image->_image->raw(); + } + + if (is_a($data, 'PEAR_Error')) { + return $data; + } + + return $this->_getImageData($data, $encoding, $compression, false); + } + + /** + * Returns a list of all galleries. + * + * @param string $app Application scope to use, if not the default. + * @param integer $perm The level of permissions to require for a gallery + * to be returned. + * @param integer $parent The parent gallery id to start searching from. + * This should be either a gallery id or null. + * @param boolean $allLevels Return all levels, or just the direct children of + * $parent? + * @param integer $from The gallery to start listing at. + * @param integer $count The number of galleries to return. + * @param array $attributes Restrict the returned galleries to those matching + * $attributes. An array of attribute names => values + * + * @return array An array of gallery information. + */ + public function listGalleries($app = null, $perm = PERMS_SHOW, + $parent = null, + $allLevels = true, $from = 0, $count = 0, + $attributes = null, $sort_by = null, $direction = 0) + { + require_once dirname(__FILE__) . '/base.php'; + + /* If no app is given use Ansel's own gallery which is initialized in + base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + + $galleries = $GLOBALS['ansel_storage']->listGalleries( + $perm, $attributes, $parent, $allLevels, $from, $count, $sort_by, $direction); + + if (is_a($galleries, 'PEAR_Error')) { + return $galleries; + } + + $return = array(); + foreach ($galleries as $gallery) { + $return[$gallery->id] = array_merge($gallery->data, array('crumbs' => $gallery->getGalleryCrumbData())); + } + + return $return; + } + + /** + * Returns an array of gallery information. + * + * @param array $ids An array of gallery ids. + * @param string $app Application scope to use, if not the default. + * @param array $slugs An array of gallery slugs. + * + * @return mixed An array of gallery data arrays | PEAR_Error + */ + public function getGalleries($ids = array(), $app = null, $slugs = array()) + { + require_once dirname(__FILE__) . '/base.php'; + + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + if (count($slugs)) { + $results = $GLOBALS['ansel_storage']->getGalleriesBySlugs($slugs); + } else { + $results = $GLOBALS['ansel_storage']->getGalleries($ids); + } + + if (is_a($results, 'PEAR_Error')) { + return $results; + } + + /* We can't just return the results of the getGalleries call - we need to + ensure the caller has at least PERMS_READ on the galleries. */ + $galleries = array(); + foreach ($results as $gallery) { + if ($gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { + $galleries[$gallery->id] = array_merge($gallery->data, array('crumbs' => $gallery->getGalleryCrumbData())); + } + } + + return $galleries; + } + + /** + * Returns a 'select' menu from the list of galleries created by + * listGalleries(). + * + * @param integer $app Application used if null then use default. + * @param integer $perm The permissions filter to use. + * @param string $parent The parent share to start listing at. + * @param boolean $allLevels Return all levels, or just the direct + * @param integer $from The gallery to start listing at. + * @param integer $count The number of galleries to return. + * @param boolean $default The gallery_id of the gallery that is + * selected by default in the returned option + * list. + */ + public function selectGalleries($app = null, $perm = PERMS_SHOW, + $parent = null, + $allLevels = true, $from = 0, $count = 0, + $default = null) + { + require_once dirname(__FILE__) . '/base.php'; + + /* If no app is given use Ansel's own gallery which is initialized in + base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + return Ansel::selectGalleries($default, $perm, null, $parent, $allLevels, + $from, $count); + } + + /** + * Returns a list of all images in a gallery. + * + * The return has the URL because in a lot of cases you'll want the url + * also. Using api call getImageURL results in a lot of overhead when + * e.g. generating a select list. + * + * @param string $app Application scope to use, if not the default. + * @param integer $gallery_id Gallery id to get images from. + * @param integer $perm The level of permissions to require for a + * gallery to return it. + * @param string $view Viewsize to generate URLs for. + * @param boolean $full Return a full URL + * @param integer $from Start image. + * @param integer $count End image. + * @param string $style Use this gallery style. + * @param string $slug Gallery slug + * + * @return array Two dimensional array with image names ids (key) and urls. + */ + public function listImages($app = null, $gallery_id = null, $perm = PERMS_SHOW, + $view = 'screen', $full = false, $from = 0, + $count = 0, $style = null, $slug = '') + { + require_once dirname(__FILE__) . '/base.php'; + + /* If no app is given use Ansel's own gallery which is initialized in + base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + /* Determine the default gallery when none is given. The first gallery in + the list is the default gallery. */ + if (is_null($gallery_id) && empty($slug)) { + $galleries = $GLOBALS['ansel_storage']->listGalleries($perm); + if (!count($galleries)) { + return array(); + } + $keys = array_keys($galleries); + $gallery_names = array_keys($galleries[$keys[0]]['galleries']); + $gallery_id = $gallery_names[0]; + } elseif (!empty($slug)) { + $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug); + } else { + $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); + } + if (is_a($gallery, 'PEAR_Error')) { + return $gallery; + } + + $images = $gallery->listImages(); + if (is_a($images, 'PEAR_Error')) { + return $images; + } + + $counter = 0; + $imagelist = array(); + foreach ($images as $id) { + $image = $GLOBALS['ansel_storage']->getImage($id); + if (is_a($image, 'PEAR_Error')) { + return $image; + } + $imagelist[$id]['name'] = $image->filename; + $imagelist[$id]['caption'] = $image->caption; + $imagelist[$id]['type'] = $image->type; + $imagelist[$id]['uploaded'] = $image->uploaded; + $imagelist[$id]['original_date'] = $image->originalDate; + $imagelist[$id]['url'] = Ansel::getImageUrl($id, $view, $full, $style); + if (!is_null($app) && $GLOBALS['conf']['vfs']['src'] != 'direct') { + $imagelist[$id]['url'] = Horde_Util::addParameter($imagelist[$id]['url'], + 'app', $app); + } + } + return $imagelist; + } + + /** + * Return a list of recently added images + * + * @param string $app Application used if null then use default. + * @param array $galleries An array of gallery ids to check. If left empty, + * will search all galleries with the given + * permissions for the current user. + * @param integer $perms PERMS_* constant + * @param string $view The type of image view to return. + * @param boolean $full Return a full URL if this is true. + * @param integer $limit The maximum number of images to return. + * @param string $style Force the use of this gallery style + * @param string $slugs An array of gallery slugs + * + * @return array An array of image objects. + */ + public function getRecentImages($app = null, $galleries = array(), + $perms = PERMS_SHOW, $view = 'screen', + $full = false, $limit = 10, $style = null, + $slugs = array()) + { + require_once dirname(__FILE__) . '/base.php'; + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + $images = $GLOBALS['ansel_storage']->getRecentImages($galleries, $limit, $slugs); + $imagelist = array(); + foreach ($images as $image) { + $id = $image->id; + $imagelist[$id]['id'] = $id; + $imagelist[$id]['name'] = $image->filename; + $imagelist[$id]['url'] = Ansel::getImageUrl($id, $view, $full, $style); + $imagelist[$id]['caption'] = $image->caption; + $imagelist[$id]['filename'] = $image->filename; + $imagelist[$id]['gallery'] = $image->gallery; + $imagelist[$id]['uploaded'] = $image->uploaded; + $imagelist[$id]['original_date'] = $image->originalDate; + + if (!is_null($app) && $GLOBALS['conf']['vfs']['src'] != 'direct') { + $imagelist[$id]['url'] = Horde_Util::addParameter($imagelist[$id]['url'], + 'app', $app); + } + } + return $imagelist; + + } + + /** + * Counts the number of galleries. + * + * @param string $app Application scope to use, if not the default. + * @param integer $perm The level of permissions to require for a gallery + * to return it. + * @param mixed $attributes Restrict the galleries counted to those matching + * $attributes. An array of attribute/value pairs or + * a gallery owner username. + * @param integer $parent The parent gallery id to start searching at. + * @param boolean $allLevels Return all levels, or just the direct children of + * $parent? + * + * @return integer Returns the number of matching galleries. + */ + public function countGalleries($app = null, $perm = PERMS_SHOW, $attributes = null, + $parent = null, $allLevels = true) + { + require_once dirname(__FILE__) . '/base.php'; + + /* If no app is given use Ansel's own gallery which is initialized + * in base.php */ + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + return $GLOBALS['ansel_storage']->countGalleries(Horde_Auth::getAuth(), $perm, + $attributes, $parent, + $allLevels); + } + + /** + * Retrieve the list of used tag_names, tag_ids and the total number + * of resources that are linked to that tag. + * + * @param array $tags An optional array of tag_ids. If omitted, all tags + * will be included. + * + * @return mixed An array containing tag_name, and total | PEAR_Error + */ + public function listTagInfo($tags = null) + { + require_once dirname(__FILE__) . '/base.php'; + + return Ansel_Tags::listTagInfo($tags); + } + + /** + * Searches images/galleries tagged with all requested tags. + * Returns an application-agnostic array (useful for when doing a tag search + * across multiple applications) containing the following keys: + *
+     *  'title'    - The title for this resource.
+     *  'desc'     - A terse description of this resource.
+     *  'view_url' - The URL to view this resource.
+     *  'app'      - The Horde application this resource belongs to.
+     * 
+ * + * The 'raw' results array can be returned instead by setting $raw = true. + * + * @param array $names An array of tag_names to search for. + * @param integer $max The maximum number of stories to return. + * @param integer $from The number of the story to start with. + * @param string $resource_type An array of channel_ids to limit the search to. + * @param string $user Restrict results to resources owned by $user. + * @param boolean $raw Return the raw story data? + * @param string $app Application scope to use, if not the default. + * + * @return mixed An array of results | PEAR_Error + */ + public function searchTags($names, $max = 10, $from = 0, + $resource_type = 'all', $user = null, $raw = false, + $app = null) + { + require_once dirname(__FILE__) . '/base.php'; + + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } else { + $app = 'ansel'; + } + + $results = Ansel_Tags::searchTags($names, $max, $from, $resource_type, + $user); + + /* Check for error or if we requested the raw data array */ + if (is_a($results, 'PEAR_Error') || $raw) { + return $results; + } + + $return = array(); + if (!empty($results['images'])) { + foreach ($results['images'] as $image_id) { + $image = $GLOBALS['ansel_storage']->getImage($image_id); + $desc = $image->caption; + $title = $image->filename; + $view_url = Ansel::getUrlFor('view', + array('gallery' => $image->gallery, + 'image' => $image_id, + 'view' => 'Image'), + true); + $return[] = array('title' => $image->filename, + 'desc'=> $image->caption, + 'view_url' => $view_url, + 'app' => $app); + } + + } + + if (!empty($results['galleries'])) { + foreach ($results['galleries'] as $gallery) { + $gal = $GLOBALS['ansel_storage']->getGallery($gallery); + $view_url = Horde_Util::addParameter(Horde::applicationUrl('view.php'), array('gallery' => $gallery, + 'view' => 'Gallery')); + $return[] = array('title' => $gal->get('name'), + 'desc' => $gal->get('desc'), + 'view_url' => $view_url, + 'app' => $app); + + } + } + + + return $return; + } + + /** + * Checks if the gallery exists + * + * @param string $app Application scope to use, if not the default. + * @param integer $gallery_id The gallery id + * @param string $slug The gallery slug + * + * @return boolean + */ + public function galleryExists($app, $gallery_id = null, $slug = '') + { + require_once dirname(__FILE__) . '/base.php'; + + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + + return $GLOBALS['ansel_storage']->galleryExists($gallery_id, $slug); + } + + /** + * Get a list of all configured styles. + * + * @return hash of style definitions. + */ + public function getGalleryStyles() + { + require_once dirname(__FILE__) . '/base.php'; + + return Ansel::getAvailableStyles(); + } + + /** + * Renders a gallery view + * + * @param array $params Any parameters that the view might need. + * @see Ansel_View_* classes for descriptions of + * available parameters to use here. + * @param string $app Application scope to use, if not the default. + * @param string $view The generic type of view we want. + * (Gallery, Image, List, Embedded) + * + * @return array An array containing 'html' and 'crumbs' keys. + */ + public function renderView($params = array(), $app = null, + $view = 'Gallery') + { + require_once dirname(__FILE__) . '/base.php'; + + if (!is_null($app)) { + $GLOBALS['ansel_storage'] = new Ansel_Storage($app); + } + $classname = 'Ansel_View_' . basename($view); + $params['api'] = true; + $params['view'] = $view; + $trail = array(); + $return = array(); + try { + $view = new $classname($params); + } catch (Horde_Exception $e) { + $return['html'] = $e->getMessage(); + $return['crumbs'] = array(); + return $return; + } + $return['html'] = $view->html(); + if ($params['view'] == 'Gallery' || $params['view'] == 'Image') { + $trail = $view->getGalleryCrumbData(); + } + $return['crumbs'] = $trail; + + return $return; + + } + +} diff --git a/ansel/lib/api.php b/ansel/lib/api.php deleted file mode 100644 index 214ea4838..000000000 --- a/ansel/lib/api.php +++ /dev/null @@ -1,1335 +0,0 @@ - - * @author Chuck Hagenbuch - * @author Michael J. Rubinsky - * @package Ansel - */ - -$_services['perms'] = array( - 'args' => array(), - 'type' => '{urn:horde}stringArray' -); - -$_services['browse'] = array( - 'args' => array('path' => 'string'), - 'type' => '{urn:horde}hashHash', -); - -$_services['put'] = array( - 'args' => array('path' => 'string', 'content' => 'string', 'content_type' => 'string'), - 'type' => '{urn:horde}stringArray', -); - -// $_services['path_delete'] = array( -// 'args' => array('path' => 'string'), -// 'type' => 'boolean', -// ); - -$_services['commentCallback'] = array( - 'args' => array('image_id' => 'string'), - 'type' => 'string' -); - -$_services['hasComments'] = array( - 'args' => array(), - 'type' => 'boolean' -); - -$_services['saveImage'] = array( - 'args' => array('app' => 'string', - 'gallery_id' => 'string', - 'image' => '{urn:horde}hashHash', - 'default' => 'boolean', - 'gallery_data' => '{urn:horde}hashHash', - 'encoding' => 'string', - 'slug' => 'string', - 'compression' => 'string', - 'skiphook' => 'boolean'), - 'type' => '{urn:horde}stringArray' -); - -$_services['postBatchUpload'] = array( - 'args' => array('image_ids' => '{urn:horde}hash'), - 'type' => 'int' -); - -$_services['createGallery'] = array( - 'args' => array('app' => 'string', - 'attributes' => '{urn:horde}hashHash', - 'perm' => '{urn:horde}hashHash'), - 'type' => 'int' -); - -$_services['removeImage'] = array( - 'args' => array('app' => 'string', - 'gallery_id' => 'integer', - 'image_id' => 'integer'), - 'type' => 'int' -); - -$_services['removeGallery'] = array( - 'args' => array('app' => 'string', - 'gallery_id' => 'integer'), - 'type' => 'int' -); - -$_services['getImageUrl'] = array( - 'args' => array('app' => 'string', - 'image_id' => 'integer', - 'view' => 'string', - 'full' => 'boolean', - 'style' => 'string'), - 'type' => 'string' -); - -$_services['getImageContent'] = array( - 'args' => array('image_id' => 'integer', - 'view' => 'string', - 'style' => 'string', - 'app' => 'string'), - 'type' => 'string' -); - -$_services['count'] = array( - 'args' => array('app' => 'string', - 'gallery_id' => 'integer'), - 'type' => 'int' -); - -$_services['getDefaultImage'] = array( - 'args' => array('app' => 'string', - 'gallery_id' => 'integer', - 'style' => 'string'), - 'type' => 'string' -); - -$_services['listGalleries'] = array( - 'args' => array('app' => 'string', - 'perm' => 'integer', - 'parent' => 'string', - 'allLevels' => 'string', - 'from' => 'integer', - 'count' => 'integer'), - 'type' => 'string' -); - -$_services['getGalleries'] = array( - 'args' => array('ids' => '{urn:horde}hash', - 'app' => 'string'), - 'type' => '{urn:horde}hash' -); - -$_services['selectGalleries'] = array( - 'args' => array('app' => 'string', - 'perm' => 'integer', - 'parent' => 'string', - 'allLevels' => 'string', - 'from' => 'integer', - 'count' => 'integer'), - 'type' => 'string' -); - -$_services['listImages'] = array( - 'args' => array('app' => 'string', - 'gallery_id' => 'integer', - 'perm' => 'integer', - 'view' => 'string', - 'full' => 'boolean', - 'from' => 'integer', - 'count' => 'integer', - 'style' => 'string'), - 'type' => 'string' -); - -$_services['getRecentImages'] = array( - 'args' => array('app' => 'string', - 'galleries' => '{urn:horde}hash', - 'perms' => 'integer', - 'view' => 'string', - 'full' => 'boolean', - 'limit' => 'integer', - 'style' => 'string', - 'slugs' => '{urn:horde}hashHash'), - 'type' => '{urn:horde}hash' -); - -$_services['countGalleries'] = array( - 'args' => array('app' => 'string', - 'perm' => 'string', - 'attributes' => '{urn:horde}hash', - 'parent' => 'string', - 'allLevels' => 'boolean'), - 'type' => 'int' -); - -$_services['listTagInfo'] = array( - 'args' => array('tags' => '{urn:horde}stringArray'), - 'type' => '{urn:horde}hash' -); - -$_services['searchTags'] = array( - 'args' => array('tags' => '{urn:horde}stringArray', - 'resource_type' => 'string', - 'count' => 'int', - 'user' => 'string'), - 'type' => '{urn:horde}hash' -); - -$_services['galleryExists'] = array( - 'args' => array('app' => 'string', - 'gallery_name' => 'string'), - 'type' => 'boolean' -); - -$_services['renderView'] = array( - 'args' => array('parameters' => '{urn:horde]stringArray', - 'app' => 'string', - 'view' => 'string'), - 'type' => 'string' -); - -$_services['getGalleryStyles'] = array( - 'args' => array(), - 'type' => '{urn:horde}hash'); - -/** - * Returns a list of available permissions. - * - * @return array An array describing all available permissions. - */ -function _ansel_perms() -{ - $perms = array(); - $perms['tree']['ansel']['admin'] = false; - $perms['title']['ansel:admin'] = _("Administrators"); - - return $perms; -} - -/** - * Browse through Ansel's gallery tree. - * - * @param string $path The level of the tree to browse. - * @param array $properties The item properties to return. Defaults to 'name', - * 'icon', and 'browseable'. - * - * @return array The contents of $path - */ -function _ansel_browse($path = '', $properties = array()) -{ - require_once dirname(__FILE__) . '/base.php'; - - // Default properties. - if (!$properties) { - $properties = array('name', 'icon', 'browseable'); - } - - if (substr($path, 0, 5) == 'ansel') { - $path = substr($path, 5); - } - $path = trim($path, '/'); - $parts = explode('/', $path); - - if (empty($path)) { - $owners = array(); - $galleries = $GLOBALS['ansel_storage']->listGalleries(PERMS_SHOW, null, null, false); - foreach ($galleries as $gallery) { - $owners[$gallery->data['share_owner']] = true; - } - - $results = array(); - foreach (array_keys($owners) as $owner) { - if (in_array('name', $properties)) { - $results['ansel/' . $owner]['name'] = $owner; - } - if (in_array('icon', $properties)) { - $results['ansel/' . $owner]['icon'] = - $registry->getImageDir('horde') . '/user.png'; - } - if (in_array('browseable', $properties)) { - $results['ansel/' . $owner]['browseable'] = true; - } - if (in_array('contenttype', $properties)) { - $results['ansel/' . $owner]['contenttype'] = - 'httpd/unix-directory'; - } - if (in_array('contentlength', $properties)) { - $results['ansel/' . $owner]['contentlength'] = 0; - } - if (in_array('modified', $properties)) { - $results['ansel/' . $owner]['modified'] = time(); - } - if (in_array('created', $properties)) { - $results['ansel/' . $owner]['created'] = 0; - } - } - return $results; - - } else { - if (count($parts) == 1) { - // This request is for all galleries owned by the requested user. - $galleries = $GLOBALS['ansel_storage']->listGalleries( - PERMS_SHOW, $parts[0], null, false); - $images = array(); - } elseif (_ansel_galleryExists(null, end($parts))) { - // This request if for a certain gallery, list all sub-galleries - // and images. - $gallery_id = end($parts); - $galleries = $GLOBALS['ansel_storage']->getGalleries( - array($gallery_id)); - if (!isset($galleries[$gallery_id]) || - !$galleries[$gallery_id]->hasPermission(Horde_Auth::getAuth(), - PERMS_READ)) { - return PEAR::raiseError(_("Invalid gallery specified."), 404); - } - $galleries = $GLOBALS['ansel_storage']->listGalleries( - PERMS_SHOW, null, $gallery_id, false); - - $images = _ansel_listImages(null, $gallery_id, PERMS_SHOW, 'mini'); - } elseif (count($parts) > 2 && - _ansel_galleryExists(null, $parts[count($parts) - 2]) && - !is_a($image = $GLOBALS['ansel_storage']->getImage(end($parts)), 'PEAR_Error')) { - return array('data' => $image->raw(), - 'mimetype' => $image->type, - 'mtime' => $image->uploaded); - } else { - return PEAR::raiseError(_("File not found."), 404); - } - - $results = array(); - foreach ($galleries as $galleryId => $gallery) { - $retpath = 'ansel/' . implode('/', $parts) . '/' . $galleryId; - if (in_array('name', $properties)) { - $results[$retpath]['name'] = $gallery->data['attribute_name']; - } - if (in_array('displayname', $properties)) { - $results[$retpath]['displayname'] = rawurlencode( - $gallery->data['attribute_name']); - } - if (in_array('icon', $properties)) { - $results[$retpath]['icon'] = $registry->getImageDir() - . '/ansel.png'; - } - if (in_array('browseable', $properties)) { - $results[$retpath]['browseable'] = $gallery->hasPermission( - Horde_Auth::getAuth(), PERMS_READ); - } - if (in_array('contenttype', $properties)) { - $results[$retpath]['contenttype'] = 'httpd/unix-directory'; - } - if (in_array('contentlength', $properties)) { - $results[$retpath]['contentlength'] = 0; - } - if (in_array('modified', $properties)) { - $results[$retpath]['modified'] = time(); - } - if (in_array('created', $properties)) { - $results[$retpath]['created'] = 0; - } - } - - foreach ($images as $imageId => $image) { - $retpath = 'ansel/' . implode('/', $parts) . '/' . $imageId; - if (in_array('name', $properties)) { - $results[$retpath]['name'] = $image['name']; - } - if (in_array('displayname', $properties)) { - $results[$retpath]['displayname'] = rawurlencode($image['name']); - } - if (in_array('icon', $properties)) { - $results[$retpath]['icon'] = Horde::url($image['url'], true); - } - if (in_array('browseable', $properties)) { - $results[$retpath]['browseable'] = false; - } - if (in_array('contenttype', $properties)) { - $results[$retpath]['contenttype'] = $image['type']; - } - if (in_array('contentlength', $properties)) { - $results[$retpath]['contentlength'] = 0; - } - if (in_array('modified', $properties)) { - $results[$retpath]['modified'] = $image['uploaded']; - } - if (in_array('created', $properties)) { - $results[$retpath]['created'] = $image['uploaded']; - } - } - return $results; - - } - - return PEAR::raiseError(_("File not found."), 404); -} - -/** - * Saves an image into the gallery tree. - * - * @param string $path The path where to PUT the file. - * @param string $content The file content. - * @param string $content_type The file's content type. - * - * @return array The event UIDs, or a PEAR_Error on failure. - */ -function _ansel_put($path, $content, $content_type) -{ - require_once dirname(__FILE__) . '/base.php'; - - if (substr($path, 0, 5) == 'ansel') { - $path = substr($path, 9); - } - $path = trim($path, '/'); - $parts = explode('/', $path); - - if (count($parts) < 3) { - return PEAR::raiseError("Gallery does not exist"); - } - $image_name = array_pop($parts); - $gallery_id = end($parts); - if (!$GLOBALS['ansel_storage']->galleryExists($gallery_id)) { - return PEAR::raiseError("Gallery does not exist"); - } - $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); - if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT)) { - return PEAR::raiseError(_("Access denied adding photos to \"%s\".")); - } - - return $gallery->addImage(array('image_type' => $content_type, - 'image_filename' => $image_name, - 'image_caption' => '', - 'data' => $content)); -} - -/** - * Callback for Agora comments. - * - * @param integer $image_id Image id to check - * - * @return mixed Image filename on success | false on failure - */ -function _ansel_commentCallback($image_id) -{ - require_once dirname(__FILE__) . '/base.php'; - - if (!$GLOBALS['conf']['comments']['allow']) { - return false; - } - - $image = $GLOBALS['ansel_storage']->getImage($image_id); - if (!$image || is_a($image, 'PEAR_Error')) { - return false; - } - - return $image->filename; -} - -/** - * Checks if applications allows comments - * - * @return boolean - */ -function _ansel_hasComments() -{ - if (($GLOBALS['conf']['comments']['allow'] == 'all' || - ($GLOBALS['conf']['comments']['allow'] == 'authenticated' && - Horde_Auth::getAuth()))) { - return true; - } else { - return false; - } -} - -/** - * Returns decoded image data - * - * @param string $data The id of the image. - * @param string $encoding The encoding type for the image data. - * (none, base64, or binhex) - * @param string $compression The compression type for the image data. - * (none, gzip, or lzf) - * @param boolean $upload Process direction (true of encode/compress or false if decode/decompress) - * - * @return string The image path. - */ -function _getImageData($data, $encoding = 'none', $compression = 'none', $upload = true) -{ - switch ($encoding) { - case 'base64': - $data = $upload ? base64_decode($data) : base64_encode($data); - break; - - case 'binhex': - $data = $upload ? pack('H*', $data) : unpack('H*', $data); - } - - switch ($compression) { - case 'gzip': - if (Horde_Util::loadExtension('zlib')) { - return $upload ? gzuncompress($data) : gzcompress($data); - } - break; - - case 'lzf': - if (Horde_Util::loadExtension('lzf')) { - return $upload ? lzf_decompress($data) : lzf_compress($data); - } - break; - - default: - return $data; - } -} - -/** - * Stores an image in a gallery and returns gallery and image data. - * - * @param integer $app Application used if null then use default. - * @param integer $gallery_id The gallery id to add the image to. - * @param array $image Image data array. This can either be the return - * from Horde_Form_Type_image:: or an array with - * the following four fields: - * 'filename', 'description', 'data', 'type' - * @param integer $default Set this image as default in the gallery? - * @param array $gallery_data Any gallery parameters to change at this time. - * @param string $encoding The encoding type for the image data. - * (none, base64, or binhex) - * @param string $slug Use gallery slug instead of id. (Pass '0' or null - * to gallery_id parameter). - * @param string $compression The compression type for the image data. - * (none, gzip, or lzf) - * - * @return mixed An array of image/gallery data || PEAR_Error - */ -function _ansel_saveImage($app = null, $gallery_id, $image, $default = false, - $gallery_data = null, $encoding = null, $slug = null, - $compression = 'none', $skiphook = false) -{ - require_once dirname(__FILE__) . '/base.php'; - - $image_data = null; - - /* If no app is given use Ansel's own gallery which is initialized - * in base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - if (isset($image['filename']) && - isset($image['description']) && - isset($image['data']) && - isset($image['type'])) { - Horde::logMessage(sprintf("Receiving image %s in _ansel_saveImage() with a raw filesize of %i", $image['filename'], strlen($image['data'])), __FILE__, __LINE__, PEAR_LOG_DEBUG); - $image_data = array('image_filename' => $image['filename'], - 'image_caption' => $image['description'], - 'image_type' => $image['type'], - 'data' => _getImageData($image['data'], $encoding, $compression, true)); - } else { - Horde::logMessage(sprintf("Receiving image %s in _ansel_saveImage() with a raw filesize of %i", $image['file'], filesize($image['file'])), __FILE__, __LINE__, PEAR_LOG_DEBUG); - } - - if (is_null($image_data) && getimagesize($image['file']) === false) { - return PEAR::raiseError(_("The file you uploaded does not appear to be a valid photo.")); - } - if (empty($slug) && empty($gallery_id)) { - return PEAR::raiseError(_("A gallery to add this photo to is required.")); - } - if (!empty($slug)) { - $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug); - if (is_a($gallery, 'PEAR_Error')) { - return $gallery; - } - } elseif ($GLOBALS['ansel_storage']->galleryExists($gallery_id)) { - $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); - if (is_a($gallery, 'PEAR_Error')) { - return $gallery; - } - } - if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT)) { - return PEAR::raiseError(sprintf(_("Access denied adding photos to \"%s\"."), $gallery->get('name'))); - } - if (!empty($gallery_data)) { - foreach ($gallery_data as $key => $value) { - $gallery->set($key, $value); - } - $gallery->save(); - } - - if (is_null($image_data)) { - $image_data = array( - 'image_filename' => $image['name'], - 'image_caption' => $image['name'], - 'image_type' => $image['name']['type'], - 'data' => file_get_contents($image['file']), - ); - } - - if (isset($image['tags']) && is_array($image['tags']) && - count($image['tags'])) { - $image_data['tags'] = $image['tags']; - } - - $image_id = $gallery->addImage($image_data, $default); - if (is_a($image_id, 'PEAR_Error')) { - return $image_id; - } - - // Call the postupload hook if needed - if (!empty($GLOBALS['conf']['hooks']['postupload']) && !$skiphook) { - Horde::callHook('_ansel_hook_postupload', array(array($image_id)), 'ansel'); - } - - return array('image_id' => (int)$image_id, - 'gallery_id' => (int)$gallery->id, - 'gallery_slug' => $gallery->get('slug'), - 'image_count' => (int)$gallery->countImages()); -} - -/** - * Notify Ansel that a group of images has just been uploaded. Used for when - * the _ansel_hook_postupload hook should be called with a group of recently - * uploaded images, as opposed to calling it once after each image is saved. - * - * @param array $image_ids An array of image ids. - */ -function _ansel_postBatchUpload($image_ids) -{ - require_once dirname(__FILE__) . '/base.php'; - if (!empty($conf['hooks']['postupload'])) { - return Horde::callHook('_ansel_hook_postupload', array($image_ids), 'ansel'); - } -} - -/** - * Removes an image from a gallery. - * - * @param string $app Application scope to use, if not the default. - * @param integer $gallery_id The id of gallery. - * @param string $image_id The id of image to remove. - */ -function _ansel_removeImage($app = null, $gallery_id, $image_id) -{ - require_once dirname(__FILE__) . '/base.php'; - - /* Check global Ansel permissions */ - if (!($GLOBALS['perms']->getPermissions('ansel'))) { - return PEAR::raiseError(_("Access denied deleting galleries.")); - } - - /* If no app is given use Ansel's own gallery which is initialized in - base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - $image = $GLOBALS['ansel_storage']->getImage($image_id); - if (is_a($image, 'PEAR_Error')) { - return $image; - } - $gallery = $GLOBALS['ansel_storage']->getGallery($image->gallery); - if (is_a($gallery, 'PEAR_Error') || - !$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE)) { - - return PEAR::raiseError(sprintf(_("Access denied deleting photos from \"%s\"."), $gallery->get('name'))); - } - return $gallery->removeImage($image); -} - -/** - * Add a new gallery to any arbitrary application's Ansel_Shares. - * - * @param string $app Application scope to use, if not the default. - * @param array $attributes The gallery attributes - * (@see Ansel_Storage::createGallery). - * @param array $perm An array of permission data if Ansel's defaults - * are not desired. Takes an array like: - * array('guest' => PERMS_SHOW | PERMS_READ, - * 'default' => PERMS_SHOW | PERMS_READ); - * @param integer $parent The gallery id of the parent gallery, if any. - * - * @return mixed The gallery id of the new gallery | PEAR_Error - */ -function _ansel_createGallery($app = null, $attributes = array(), $perm = null, $parent = null) -{ - require_once dirname(__FILE__) . '/base.php'; - - if (!(Horde_Auth::isAdmin() || - (!$GLOBALS['perms']->exists('ansel') && Horde_Auth::getAuth()) || - $GLOBALS['perms']->hasPermission('ansel', Horde_Auth::getAuth(), PERMS_EDIT))) { - return PEAR::raiseError(_("Access denied creating new galleries.")); - } - - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - if (!empty($perm)) { - // The name is inconsequential; it is only used as a container to - // represent permissions when passed to the Ansel backend. - $permobj = new Horde_Permission(''); - $permobj->data = $perm; - } else { - $permobj = null; - } - - $gallery = $GLOBALS['ansel_storage']->createGallery($attributes, $permobj, $parent); - if (is_a($gallery, 'PEAR_Error')) { - return $gallery; - } - return $gallery->id; -} - -/** - * Removes a gallery and its images. - * - * @param string $app Application scope to use, if not the default. - * @param integer $gallery_id The id of gallery. - * - * @return mixed boolean true | PEAR_Error - */ -function _ansel_removeGallery($app = null, $gallery_id) -{ - require_once dirname(__FILE__) . '/base.php'; - - /* Check global Ansel permissions */ - if (!($GLOBALS['perms']->getPermissions('ansel'))) { - return PEAR::raiseError(_("Access denied deleting galleries.")); - } - - /* If no app is given use Ansel's own gallery which is initialized in - base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); - if (is_a($gallery, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Access denied deleting gallery \"%s\"."), - $gallery->getMessage())); - } elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE)) { - return PEAR::raiseError(sprintf(_("Access denied deleting gallery \"%s\"."), - $gallery->get('name'))); - } else { - $imageList = $gallery->listImages(); - if ($imageList) { - foreach ($imageList as $id) { - $gallery->removeImage($id); - } - } - $result = $GLOBALS['ansel_storage']->removeGallery($gallery); - if (!is_a($result, 'PEAR_Error')) { - return true; - } else { - return PEAR::raiseError(sprintf(_("There was a problem deleting %s: %s"), - $gallery->get('name'), - $result->getMessage())); - } - } -} - -/** - * Returns the number of images in a gallery. - * - * @param integer $app Application used; if null then use default. - * @param integer $gallery_id The gallery id. - * @param string $slug The gallery slug. - * - * @return integer The number of images in the gallery. - */ -function _ansel_count($app = null, $gallery_id = null, $slug = '') -{ - require_once dirname(__FILE__) . '/base.php'; - - /* If no app is given use Ansel's own gallery which is initialized in - base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - if (!empty($slug)) { - $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug); - } else { - $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); - } - - if (is_a($gallery, 'PEAR_Error')) { - return 0; - } else { - return (int)$gallery->countImages(); - } -} - -/** - * Returns the default image id of a gallery. - * - * @param string $app Application scope to use, if not the default. - * @param integer $gallery_id The gallery id. - * @param string $style The named style. - * @param string $slug The gallery slug. - * - * @return integer The default image id. - */ -function _ansel_getDefaultImage($app = null, $gallery_id = null, - $style = 'ansel_default', $slug = '') -{ - require_once dirname(__FILE__) . '/base.php'; - - /* If no app is given use Ansel's own gallery which is initialized in - base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - if (!empty($slug)) { - $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug); - } else { - $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); - } - - if (is_a($gallery, 'PEAR_Error')) { - return $gallery; - } else { - return $gallery->getDefaultImage($style); - } -} - -/** - * Returns image URL. - * - * @param integer $app Application used. - * @param integer $image_id The id of the image. - * @param string $view The view ('screen', 'thumb', 'full', etc) to show. - * @param boolean $full Return a path that includes the server name? - * @param string $style Use this gallery style - * - * @return string The image path. - */ -function _ansel_getImageUrl($app = null, $image_id, $view = 'screen', - $full = false, $style = null) -{ - require_once dirname(__FILE__) . '/base.php'; - - /* If no app is given use Ansel's own gallery which is initialized in - base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - return Ansel::getImageUrl($image_id, $view, $full, $style); -} - -/** - * Returns image file content. - * - * @param integer $image_id The id of the image. - * @param string $view The view ('screen', 'thumb', 'full', etc) to show. - * @param string $style Force use of this gallery style. - * @param integer $app Application used. - * @param string $encoding The encoding type for the image data. - * (none, base64, or binhex) - * @param string $compression The compression type for the image data. - * (none, gzip, or lzf) - * - * @return string The image path. - */ -function _ansel_getImageContent($image_id, $view = 'screen', $style = null, - $app = null, $encoding = null, $compression = 'none') -{ - require_once dirname(__FILE__) . '/base.php'; - - /* If no app is given use Ansel's own gallery which is initialized in - base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - // Get image - $image = $GLOBALS['ansel_storage']->getImage($image_id); - if (is_a($image, 'PEAR_Error')) { - return $image; - } - - // Get gallery - $gallery = $GLOBALS['ansel_storage']->getGallery($image->gallery); - if (is_a($gallery, 'PEAR_Error')) { - return $gallery; - } - - // Check age and password - if (!$gallery->hasPasswd() || !$gallery->isOldEnough()) { - return PEAR::raiseError(_("Locked galleries are not viewable via the api.")); - } - - if ($view == 'full') { - // Check permissions for full view - if (!$gallery->canDownload()) { - return PEAR::RaiseError(sprintf(_("Access denied downloading photos from \"%s\"."), $gallery->get('name'))); - } - - $data = $GLOBALS['ansel_vfs']->read($image->getVFSPath('full'), - $image->getVFSName('full')); - } else { - // Load View - $result = $image->load($view, $style); - if (is_a($result, 'PEAR_Error')) { - return $result; - } - - // Return image content - $data = $image->_image->raw(); - } - - if (is_a($data, 'PEAR_Error')) { - return $data; - } - - return _getImageData($data, $encoding, $compression, false); -} - -/** - * Returns a list of all galleries. - * - * @param string $app Application scope to use, if not the default. - * @param integer $perm The level of permissions to require for a gallery - * to be returned. - * @param integer $parent The parent gallery id to start searching from. - * This should be either a gallery id or null. - * @param boolean $allLevels Return all levels, or just the direct children of - * $parent? - * @param integer $from The gallery to start listing at. - * @param integer $count The number of galleries to return. - * @param array $attributes Restrict the returned galleries to those matching - * $attributes. An array of attribute names => values - * - * @return array An array of gallery information. - */ -function _ansel_listGalleries($app = null, $perm = PERMS_SHOW, - $parent = null, - $allLevels = true, $from = 0, $count = 0, - $attributes = null, $sort_by = null, $direction = 0) -{ - require_once dirname(__FILE__) . '/base.php'; - - /* If no app is given use Ansel's own gallery which is initialized in - base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - - $galleries = $GLOBALS['ansel_storage']->listGalleries( - $perm, $attributes, $parent, $allLevels, $from, $count, $sort_by, $direction); - - if (is_a($galleries, 'PEAR_Error')) { - return $galleries; - } - - $return = array(); - foreach ($galleries as $gallery) { - $return[$gallery->id] = array_merge($gallery->data, array('crumbs' => $gallery->getGalleryCrumbData())); - } - - return $return; -} - -/** - * Returns an array of gallery information. - * - * @param array $ids An array of gallery ids. - * @param string $app Application scope to use, if not the default. - * @param array $slugs An array of gallery slugs. - * - * @return mixed An array of gallery data arrays | PEAR_Error - */ -function _ansel_getGalleries($ids = array(), $app = null, $slugs = array()) -{ - require_once dirname(__FILE__) . '/base.php'; - - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - if (count($slugs)) { - $results = $GLOBALS['ansel_storage']->getGalleriesBySlugs($slugs); - } else { - $results = $GLOBALS['ansel_storage']->getGalleries($ids); - } - - if (is_a($results, 'PEAR_Error')) { - return $results; - } - - /* We can't just return the results of the getGalleries call - we need to - ensure the caller has at least PERMS_READ on the galleries. */ - $galleries = array(); - foreach ($results as $gallery) { - if ($gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { - $galleries[$gallery->id] = array_merge($gallery->data, array('crumbs' => $gallery->getGalleryCrumbData())); - } - } - - return $galleries; -} - -/** - * Returns a 'select' menu from the list of galleries created by - * _ansel_listGalleries(). - * - * - * @param integer $app Application used if null then use default. - * @param integer $perm The permissions filter to use. - * @param string $parent The parent share to start listing at. - * @param boolean $allLevels Return all levels, or just the direct - * @param integer $from The gallery to start listing at. - * @param integer $count The number of galleries to return. - * @param boolean $default The gallery_id of the gallery that is - * selected by default in the returned option - * list. - */ -function _ansel_selectGalleries($app = null, $perm = PERMS_SHOW, - $parent = null, - $allLevels = true, $from = 0, $count = 0, - $default = null) -{ - require_once dirname(__FILE__) . '/base.php'; - - /* If no app is given use Ansel's own gallery which is initialized in - base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - return Ansel::selectGalleries($default, $perm, null, $parent, $allLevels, - $from, $count); -} - -/** - * Returns a list of all images in a gallery. - * - * The return has the URL because in a lot of cases you'll want the url - * also. Using api call getImageURL results in a lot of overhead when - * e.g. generating a select list. - * - * @param string $app Application scope to use, if not the default. - * @param integer $gallery_id Gallery id to get images from. - * @param integer $perm The level of permissions to require for a - * gallery to return it. - * @param string $view Viewsize to generate URLs for. - * @param boolean $full Return a full URL - * @param integer $from Start image. - * @param integer $count End image. - * @param string $style Use this gallery style. - * @param string $slug Gallery slug - * - * @return array Two dimensional array with image names ids (key) and urls. - */ -function _ansel_listImages($app = null, $gallery_id = null, $perm = PERMS_SHOW, - $view = 'screen', $full = false, $from = 0, - $count = 0, $style = null, $slug = '') -{ - require_once dirname(__FILE__) . '/base.php'; - - /* If no app is given use Ansel's own gallery which is initialized in - base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - /* Determine the default gallery when none is given. The first gallery in - the list is the default gallery. */ - if (is_null($gallery_id) && empty($slug)) { - $galleries = $GLOBALS['ansel_storage']->listGalleries($perm); - if (!count($galleries)) { - return array(); - } - $keys = array_keys($galleries); - $gallery_names = array_keys($galleries[$keys[0]]['galleries']); - $gallery_id = $gallery_names[0]; - } elseif (!empty($slug)) { - $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug); - } else { - $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id); - } - if (is_a($gallery, 'PEAR_Error')) { - return $gallery; - } - - $images = $gallery->listImages(); - if (is_a($images, 'PEAR_Error')) { - return $images; - } - - $counter = 0; - $imagelist = array(); - foreach ($images as $id) { - $image = $GLOBALS['ansel_storage']->getImage($id); - if (is_a($image, 'PEAR_Error')) { - return $image; - } - $imagelist[$id]['name'] = $image->filename; - $imagelist[$id]['caption'] = $image->caption; - $imagelist[$id]['type'] = $image->type; - $imagelist[$id]['uploaded'] = $image->uploaded; - $imagelist[$id]['original_date'] = $image->originalDate; - $imagelist[$id]['url'] = Ansel::getImageUrl($id, $view, $full, $style); - if (!is_null($app) && $GLOBALS['conf']['vfs']['src'] != 'direct') { - $imagelist[$id]['url'] = Horde_Util::addParameter($imagelist[$id]['url'], - 'app', $app); - } - } - return $imagelist; -} - -/** - * Return a list of recently added images - * - * @param string $app Application used if null then use default. - * @param array $galleries An array of gallery ids to check. If left empty, - * will search all galleries with the given - * permissions for the current user. - * @param integer $perms PERMS_* constant - * @param string $view The type of image view to return. - * @param boolean $full Return a full URL if this is true. - * @param integer $limit The maximum number of images to return. - * @param string $style Force the use of this gallery style - * @param string $slugs An array of gallery slugs - * - * @return array An array of image objects. - */ -function _ansel_getRecentImages($app = null, $galleries = array(), - $perms = PERMS_SHOW, $view = 'screen', - $full = false, $limit = 10, $style = null, - $slugs = array()) -{ - require_once dirname(__FILE__) . '/base.php'; - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - $images = $GLOBALS['ansel_storage']->getRecentImages($galleries, $limit, $slugs); - $imagelist = array(); - foreach ($images as $image) { - $id = $image->id; - $imagelist[$id]['id'] = $id; - $imagelist[$id]['name'] = $image->filename; - $imagelist[$id]['url'] = Ansel::getImageUrl($id, $view, $full, $style); - $imagelist[$id]['caption'] = $image->caption; - $imagelist[$id]['filename'] = $image->filename; - $imagelist[$id]['gallery'] = $image->gallery; - $imagelist[$id]['uploaded'] = $image->uploaded; - $imagelist[$id]['original_date'] = $image->originalDate; - - if (!is_null($app) && $GLOBALS['conf']['vfs']['src'] != 'direct') { - $imagelist[$id]['url'] = Horde_Util::addParameter($imagelist[$id]['url'], - 'app', $app); - } - } - return $imagelist; - -} - -/** - * Counts the number of galleries. - * - * @param string $app Application scope to use, if not the default. - * @param integer $perm The level of permissions to require for a gallery - * to return it. - * @param mixed $attributes Restrict the galleries counted to those matching - * $attributes. An array of attribute/value pairs or - * a gallery owner username. - * @param integer $parent The parent gallery id to start searching at. - * @param boolean $allLevels Return all levels, or just the direct children of - * $parent? - * - * @return integer Returns the number of matching galleries. - */ -function _ansel_countGalleries($app = null, $perm = PERMS_SHOW, $attributes = null, - $parent = null, $allLevels = true) -{ - require_once dirname(__FILE__) . '/base.php'; - - /* If no app is given use Ansel's own gallery which is initialized - * in base.php */ - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - return $GLOBALS['ansel_storage']->countGalleries(Horde_Auth::getAuth(), $perm, - $attributes, $parent, - $allLevels); -} - -/** - * Retrieve the list of used tag_names, tag_ids and the total number - * of resources that are linked to that tag. - * - * @param array $tags An optional array of tag_ids. If omitted, all tags - * will be included. - * - * @return mixed An array containing tag_name, and total | PEAR_Error - */ -function _ansel_listTagInfo($tags = null) -{ - require_once dirname(__FILE__) . '/base.php'; - - return Ansel_Tags::listTagInfo($tags); -} - -/** - * Searches images/galleries tagged with all requested tags. - * Returns an application-agnostic array (useful for when doing a tag search - * across multiple applications) containing the following keys: - *
- *  'title'    - The title for this resource.
- *  'desc'     - A terse description of this resource.
- *  'view_url' - The URL to view this resource.
- *  'app'      - The Horde application this resource belongs to.
- * 
- * - * The 'raw' results array can be returned instead by setting $raw = true. - * - * @param array $names An array of tag_names to search for. - * @param integer $max The maximum number of stories to return. - * @param integer $from The number of the story to start with. - * @param string $resource_type An array of channel_ids to limit the search to. - * @param string $user Restrict results to resources owned by $user. - * @param boolean $raw Return the raw story data? - * @param string $app Application scope to use, if not the default. - * - * @return mixed An array of results | PEAR_Error - */ -function _ansel_searchTags($names, $max = 10, $from = 0, - $resource_type = 'all', $user = null, $raw = false, - $app = null) -{ - require_once dirname(__FILE__) . '/base.php'; - - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } else { - $app = 'ansel'; - } - - $results = Ansel_Tags::searchTags($names, $max, $from, $resource_type, - $user); - - /* Check for error or if we requested the raw data array */ - if (is_a($results, 'PEAR_Error') || $raw) { - return $results; - } - - $return = array(); - if (!empty($results['images'])) { - foreach ($results['images'] as $image_id) { - $image = $GLOBALS['ansel_storage']->getImage($image_id); - $desc = $image->caption; - $title = $image->filename; - $view_url = Ansel::getUrlFor('view', - array('gallery' => $image->gallery, - 'image' => $image_id, - 'view' => 'Image'), - true); - $return[] = array('title' => $image->filename, - 'desc'=> $image->caption, - 'view_url' => $view_url, - 'app' => $app); - } - - } - - if (!empty($results['galleries'])) { - foreach ($results['galleries'] as $gallery) { - $gal = $GLOBALS['ansel_storage']->getGallery($gallery); - $view_url = Horde_Util::addParameter(Horde::applicationUrl('view.php'), array('gallery' => $gallery, - 'view' => 'Gallery')); - $return[] = array('title' => $gal->get('name'), - 'desc' => $gal->get('desc'), - 'view_url' => $view_url, - 'app' => $app); - - } - } - - - return $return; -} - -/** - * Checks if the gallery exists - * - * @param string $app Application scope to use, if not the default. - * @param integer $gallery_id The gallery id - * @param string $slug The gallery slug - * - * @return boolean - */ -function _ansel_galleryExists($app, $gallery_id = null, $slug = '') -{ - require_once dirname(__FILE__) . '/base.php'; - - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - - return $GLOBALS['ansel_storage']->galleryExists($gallery_id, $slug); -} - -/** - * Get a list of all configured styles. - * - * @return hash of style definitions. - */ -function _ansel_getGalleryStyles() -{ - require_once dirname(__FILE__) . '/base.php'; - - return Ansel::getAvailableStyles(); -} - -/** - * Renders a gallery view - * - * @param array $params Any parameters that the view might need. - * @see Ansel_View_* classes for descriptions of - * available parameters to use here. - * @param string $app Application scope to use, if not the default. - * @param string $view The generic type of view we want. - * (Gallery, Image, List, Embedded) - * - * @return array An array containing 'html' and 'crumbs' keys. - */ -function _ansel_renderView($params = array(), $app = null, - $view = 'Gallery') -{ - require_once dirname(__FILE__) . '/base.php'; - - if (!is_null($app)) { - $GLOBALS['ansel_storage'] = new Ansel_Storage($app); - } - $classname = 'Ansel_View_' . basename($view); - $params['api'] = true; - $params['view'] = $view; - $trail = array(); - $return = array(); - try { - $view = new $classname($params); - } catch (Horde_Exception $e) { - $return['html'] = $e->getMessage(); - $return['crumbs'] = array(); - return $return; - } - $return['html'] = $view->html(); - if ($params['view'] == 'Gallery' || $params['view'] == 'Image') { - $trail = $view->getGalleryCrumbData(); - } - $return['crumbs'] = $trail; - - return $return; - -} diff --git a/ansel/lib/version.php b/ansel/lib/version.php deleted file mode 100755 index 4b585835c..000000000 --- a/ansel/lib/version.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/ansel/rss.php b/ansel/rss.php index 5f0670dbd..d7684a36f 100644 --- a/ansel/rss.php +++ b/ansel/rss.php @@ -12,7 +12,6 @@ $ansel_session_control = 'readonly'; require_once dirname(__FILE__) . '/lib/base.php'; -require_once ANSEL_BASE . '/lib/version.php'; // Get form data $stream_type = Horde_Util::getFormData('stream_type', 'all'); @@ -266,7 +265,7 @@ if (empty($rss)) { $image_url = htmlspecialchars($params['image_url']); $image_link = htmlspecialchars($params['image_link']); $image_alt = htmlspecialchars($params['image_alt']); - $ansel = 'Ansel ' . ANSEL_VERSION . ' (http://www.horde.org/)'; + $ansel = 'Ansel ' . $registry->getVersion('ansel') . ' (http://www.horde.org/)'; if ($stream_type != 'all' && $type != 'rss2') { $getparams = array('stream_type' => $stream_type, 'type' => $type); diff --git a/ansel/test.php b/ansel/test.php index 5ac15973b..2218bc79e 100644 --- a/ansel/test.php +++ b/ansel/test.php @@ -30,8 +30,9 @@ $horde_test = new Horde_Test; /* Ansel version. */ $module = 'Ansel'; -require_once ANSEL_BASE . '/lib/version.php'; -$module_version = ANSEL_VERSION; +require_once dirname(__FILE__) . '/lib/Api.php'; +$api = new Ansel_Api(); +$module_version = $api->version; /* Ansel configuration files. */ $file_list = array( diff --git a/babel/lib/Api.php b/babel/lib/Api.php new file mode 100644 index 000000000..6e7cb5b07 --- /dev/null +++ b/babel/lib/Api.php @@ -0,0 +1,74 @@ + + * @package Babel + */ +class Babel_Api extends Horde_Registry_Api +{ + public function perms() + { + global $registry; + + static $perms = array(); + if (!empty($perms)) { + return $perms; + } + + $perms['tree']['babel']['language'] = array(); + $perms['title']['babel:language'] = _("Languages"); + $perms['type']['babel:language'] = 'none'; + + foreach(Horde_Nls::$config['languages'] as $langcode => $langdesc) { + $perms['tree']['babel']['language'][$langcode] = false; + $perms['title']['babel:language:' . $langcode] = sprintf("%s (%s)", $langdesc, $langcode); + $perms['type']['babel:language:' . $langcode] = 'boolean'; + } + + $perms['tree']['babel']['module'] = array(); + $perms['title']['babel:module'] = _("Modules"); + $perms['type']['babel:module'] = 'none'; + + foreach ($registry->applications as $app => $params) { + if ($params['status'] == 'heading' || $params['status'] == 'block') { + continue; + } + + if (isset($params['fileroot']) && !is_dir($params['fileroot'])) { + continue; + } + + if (preg_match('/_reports$/', $app) || preg_match('/_tools$/', $app)) { + continue; + } + + $perms['tree']['babel']['module'][$app] = false; + $perms['title']['babel:module:' . $app] = sprintf("%s (%s)", $params['name'], $app); + $perms['type']['babel:module:' . $app] = 'boolean'; + } + + $tabdesc['download'] = _("Download"); + $tabdesc['upload'] = _("Upload"); + $tabdesc['stats'] = _("Statistics"); + $tabdesc['view'] = _("View/Edit"); + $tabdesc['viewsource'] = _("View Source"); + $tabdesc['extract'] = _("Extract"); + $tabdesc['make'] = _("Make"); + $tabdesc['commit'] = _("Commit"); + $tabdesc['reset'] = _("Reset"); + + foreach ($tabdesc as $cat => $desc) { + $perms['tree']['babel'][$cat] = array(); + $perms['title']['babel:' . $cat] = $desc; + } + + return $perms; + } + +} diff --git a/babel/lib/api.php b/babel/lib/api.php deleted file mode 100644 index 5a5be3378..000000000 --- a/babel/lib/api.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @package Babel - */ - -$_services['perms'] = array( - 'args' => array(), - // This is actually a hash of hashes - 'type' => '{urn:horde}hash' -); - -function _babel_perms() -{ - - global $registry; - - static $perms = array(); - if (!empty($perms)) { - return $perms; - } - - $perms['tree']['babel']['language'] = array(); - $perms['title']['babel:language'] = _("Languages"); - $perms['type']['babel:language'] = 'none'; - - foreach(Horde_Nls::$config['languages'] as $langcode => $langdesc) { - $perms['tree']['babel']['language'][$langcode] = false; - $perms['title']['babel:language:' . $langcode] = sprintf("%s (%s)", $langdesc, $langcode); - $perms['type']['babel:language:' . $langcode] = 'boolean'; - } - - $perms['tree']['babel']['module'] = array(); - $perms['title']['babel:module'] = _("Modules"); - $perms['type']['babel:module'] = 'none'; - - foreach ($registry->applications as $app => $params) { - if ($params['status'] == 'heading' || $params['status'] == 'block') { - continue; - } - - if (isset($params['fileroot']) && !is_dir($params['fileroot'])) { - continue; - } - - if (preg_match('/_reports$/', $app) || preg_match('/_tools$/', $app)) { - continue; - } - - $perms['tree']['babel']['module'][$app] = false; - $perms['title']['babel:module:' . $app] = sprintf("%s (%s)", $params['name'], $app); - $perms['type']['babel:module:' . $app] = 'boolean'; - } - - $tabdesc['download'] = _("Download"); - $tabdesc['upload'] = _("Upload"); - $tabdesc['stats'] = _("Statistics"); - $tabdesc['view'] = _("View/Edit"); - $tabdesc['viewsource'] = _("View Source"); - $tabdesc['extract'] = _("Extract"); - $tabdesc['make'] = _("Make"); - $tabdesc['commit'] = _("Commit"); - $tabdesc['reset'] = _("Reset"); - - foreach ($tabdesc as $cat => $desc) { - $perms['tree']['babel'][$cat] = array(); - $perms['title']['babel:' . $cat] = $desc; - } - - return $perms; - -} diff --git a/chora/lib/Api.php b/chora/lib/Api.php new file mode 100644 index 000000000..bd458bc91 --- /dev/null +++ b/chora/lib/Api.php @@ -0,0 +1,41 @@ + $srconfig) { + $perms['tree']['chora']['sourceroots'][$sourceroot] = false; + $perms['title']['chora:sourceroots:' . $sourceroot] = $srconfig['name']; + } + + return $perms; + } + +} diff --git a/chora/lib/api.php b/chora/lib/api.php deleted file mode 100644 index e1b05d26a..000000000 --- a/chora/lib/api.php +++ /dev/null @@ -1,39 +0,0 @@ - array(), - 'type' => '{urn:horde}stringArray' -); - -function _chora_perms() -{ - static $perms = array(); - - if (!empty($perms)) { - return $perms; - } - - @define('CHORA_BASE', dirname(__FILE__) . '/..'); - require_once CHORA_BASE . '/config/sourceroots.php'; - - $perms['tree']['chora']['sourceroots'] = false; - $perms['title']['chora:sourceroots'] = _("Repositories"); - - // Run through every source repository - foreach ($sourceroots as $sourceroot => $srconfig) { - $perms['tree']['chora']['sourceroots'][$sourceroot] = false; - $perms['title']['chora:sourceroots:' . $sourceroot] = $srconfig['name']; - } - - return $perms; -} - diff --git a/chora/lib/version.php b/chora/lib/version.php deleted file mode 100644 index 4b0a8e5e1..000000000 --- a/chora/lib/version.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/chora/test.php b/chora/test.php index b3751441e..b2beca277 100644 --- a/chora/test.php +++ b/chora/test.php @@ -30,8 +30,9 @@ $horde_test = new Horde_Test; /* Chora version. */ $module = 'Chora'; -require_once CHORA_BASE . '/lib/version.php'; -$module_version = CHORA_VERSION; +require_once dirname(__FILE__) . '/lib/Api.php'; +$api = new Chora_Api(); +$module_version = $api->version; /* Chora configuration files. */ $file_list = array( diff --git a/crumb/lib/Api.php b/crumb/lib/Api.php new file mode 100644 index 000000000..54fa30010 --- /dev/null +++ b/crumb/lib/Api.php @@ -0,0 +1,5 @@ + diff --git a/fima/lib/Api.php b/fima/lib/Api.php new file mode 100644 index 000000000..6500598b5 --- /dev/null +++ b/fima/lib/Api.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/folks/lib/Api.php b/folks/lib/Api.php new file mode 100644 index 000000000..f853dbbcb --- /dev/null +++ b/folks/lib/Api.php @@ -0,0 +1,576 @@ + + * @package Folks + */ +class Folks_Api extends Horde_Registry_Api +{ + public $version = 'H4 (0.1-git)'; + + public $services = array( + 'commentCallback' => array( + 'args' => array('id' => 'string'), + 'type' => 'string' + ), + + 'removeUserData' => array( + 'args' => array('user' => 'string'), + 'type' => 'boolean' + ), + + 'hasComments' => array( + 'args' => array(), + 'type' => 'boolean' + ), + + 'getOnlineUsers' => array( + 'args' => array(), + 'type' => 'array' + ), + + 'getProfile' => array( + 'args' => array(), + 'type' => 'array' + ), + + 'getFriends' => array( + 'args' => array('user' => 'string'), + 'type' => 'array' + ), + + 'addFriend' => array( + 'args' => array('friend' => 'string'), + 'type' => 'boolean' + ), + + 'getBlacklist' => array( + 'args' => array('user' => 'string'), + 'type' => 'array' + ), + + 'addBlacklisted' => array( + 'args' => array('user' => 'string'), + 'type' => 'boolean' + ), + + 'removeBlacklisted' => array( + 'args' => array('user' => 'string'), + 'type' => 'boolean' + ), + + 'isBlacklisted' => array( + 'args' => array('user' => 'string'), + 'type' => 'boolean' + ), + + 'show' => array( + 'link' => '%application%/user.php?user=|user|' + ), + + 'listTimeObjectCategories' => array( + 'type' => '{urn:horde}stringArray' + ), + + 'listTimeObjects' => array( + 'args' => array('start' => 'int', 'end' => 'int'), + 'type' => '{urn:horde}hashHash' + ), + + 'logActivity' => array( + 'args' => array('activity_message' => 'string', + 'scope' => 'string', + 'user' => 'string'), + 'type' => 'boolean' + ), + + 'getActivity' => array( + 'args' => array('user' => 'string'), + 'type' => 'boolean' + ), + + 'setStatus' => array( + 'args' => array('status' => 'boolean'), + 'args' => array('user' => 'string'), + 'type' => 'array' + ), + + 'getStatus' => array( + 'args' => array('user' => 'string'), + 'type' => 'array' + ), + + 'authenticate' => array( + 'args' => array('userID' => 'string', + 'credentials' => '{urn:horde}hash', + 'params' => '{urn:horde}hash'), + 'checkperms' => false, + 'type' => 'boolean' + ), + + 'userExists' => array( + 'args' => array('userId' => 'string'), + 'type' => 'boolean' + ), + + 'addUser' => array( + 'args' => array('userId' => 'string') + ), + + 'getImageUrl' => array( + 'args' => array( + 'user' => 'string', + 'view' => 'string', + 'full' => 'boolean' + ), + 'type' => 'string' + ), + + 'userList' => array( + 'type' => '{urn:horde}stringArray' + ), + + 'removeUser' => array( + 'args' => array('userId' => 'string') + ) + ); + + public function __construct() + { + if (!Horde_Auth::isAdmin()) { + unset($this->services['userList'], $this->services['removeUser']); + } + } + + /** + * Returns profile image URL. + * + * @param string $user User uid + * @param string $view The view ('small', 'big') to show. + * @param boolean $full Return a path that includes the server name? + * + * @return string The image path. + */ + public function getImageUrl($user, $view = 'small', $full = false) + { + require_once dirname(__FILE__) . '/base.php'; + return Folks::getImageUrl($user, $view, $full); + } + + /** + * Callback for comment API. + * + * @param int $id Internal data identifier. + * @param string $type Type of data to retreive (title, owner...). + * @param array $params Parameter to be passed to callback function + */ + public function commentCallback($id, $type = 'title', $params = null) + { + static $info; + + if (!empty($info[$id][$type])) { + return $info[$id][$type]; + } + + require_once dirname(__FILE__) . '/base.php'; + + switch ($type) { + + case 'owner': + return $id; + + case 'link': + return Folks::getUrlFor('user', $id); + + case 'messages': + + // Update comments count + $result = $GLOBALS['folks_driver']->updateComments($id); + if ($result instanceof PEAR_Error) { + return $result; + } + + // Update activity log + $link = '' . $id . ''; + return $GLOBALS['folks_driver']->logActivity(sprintf(_("Commented user %s."), $link), 'folks:comments'); + + return true; + + default: + return $id; + } + } + + /** + * Comments are enebled + */ + public function hasComments() + { + return $GLOBALS['conf']['comments']['allow']; + } + + /** + * Get online users + */ + public function getOnlineUsers() + { + require_once dirname(__FILE__) . '/base.php'; + + return $GLOBALS['folks_driver']->getOnlineUsers(); + } + + /** + * Get user profile + * + * @param string $user User to get profile for + */ + public function getProfile($user = null) + { + require_once dirname(__FILE__) . '/base.php'; + + return $GLOBALS['folks_driver']->getProfile($user); + } + + + /** + * Get user friends + * + * @param string $user Username to get friends for + * + * @return array of users + */ + public function getFriends($user = null) + { + require_once dirname(__FILE__) . '/Friends.php'; + + $friends = Folks_Friends::singleton('sql', array('user' => $user)); + + return $friends->getFriends(); + } + + /** + * Add user to our friend list + * + * @param string $friend Friend's usersame + * + * @return true or PEAR_Error + */ + public function addFriend($user = null) + { + require_once dirname(__FILE__) . '/Friends.php'; + + $friends = Folks_Friends::singleton('sql', array('user' => $user)); + + return $friends->addFriend($user); + } + + /** + * Remove user from a fiend list + * + * @param string $friend Friend's usersame + * + * @return true or PEAR_Error + */ + public function removeFriend($user = null) + { + require_once dirname(__FILE__) . '/Friends.php'; + + $friends = Folks_Friends::singleton('sql', array('user' => $user)); + + return $friends->removeFriend($user); + } + + /** + * Get user blacklist + * + * @param string $user Username to get blacklist for + * + * @return array of users + */ + public function _getBlacklist($user = null) + { + require_once dirname(__FILE__) . '/Friends.php'; + + $friends = Folks_Friends::singleton('sql', array('user' => $user)); + + return $friends->getBlacklist(); + } + + /** + * Add user to a blacklist list + * + * @param string $user Usersame + */ + public function addBlacklisted($user = null) + { + require_once dirname(__FILE__) . '/Friends.php'; + + $friends = Folks_Friends::singleton('sql', array('user' => $user)); + + return $friends->addBlacklisted($user); + } + + /** + * Remove user from a blacklist list + * + * @param string $user Usersame + */ + public function removeBlacklisted($user = null) + { + require_once dirname(__FILE__) . '/Friends.php'; + + $friends = Folks_Friends::singleton('sql', array('user' => $user)); + + return $friends->removeBlacklisted($user); + } + + /** + * Are we blackisted by user this user? + * + * @param string $user Username to get blacklist for + * + * @return array of users + */ + public function isBlacklisted($user = null) + { + require_once dirname(__FILE__) . '/Friends.php'; + + $friends = Folks_Friends::singleton('sql', array('user' => $user)); + + return $friends->isBlacklisted(Horde_Auth::getAuth()); + } + + /** + * Users categories + */ + public function listTimeObjectCategories() + { + return array('birthday_friends' => _("Friends Birthdays")); + } + + /** + * Lists users with birthdays/goout dates as time objects. + * + * @param array $categories The time categories (from listTimeObjectCategories) to list. + * @param Horde_Date $start The start date of the period. + * @param Horde_Date $end The end date of the period. + */ + public function listTimeObjects($categories, $start, $end) + { + require_once dirname(__FILE__) . '/base.php'; + require_once FOLKS_BASE . '/lib/Friends.php'; + + $friends_driver = Folks_Friends::singleton('sql'); + $friends = $friends_driver->getFriends(); + if ($friends instanceof PEAR_Error) { + return array(); + } + + $objects = array(); + + foreach ($friends as $friend) { + $user = $GLOBALS['folks_driver']->getProfile($friend); + if ($user instanceof PEAR_Error) { + continue; + } + + $user['user_birthday'] = date('Y') . substr($user['user_birthday'], 4); + $born = strtotime($user['user_birthday']); + if ($born === false || + $born < $start->timestamp() || + $born > $end->timestamp()) { + continue; + } + + $age = Folks::calcAge($user['user_birthday']); + $desc = $age['age'] . ' (' . $age['sign'] . ')'; + + $objects[$friend] = array( + 'title' => $friend, + 'description' => $desc, + 'id' => $friend, + 'start' => date('Y-m-d\TH:i:s', $born), + 'end' => date('Y-m-d\TH:i:s', $born + 1), + 'params' => array('user' => $friend), + 'link' => Folks::getUrlFor('user', $friend, true)); + } + + return $objects; + } + + /** + * Log user's activity + * + * @param mixed $message Activity message or details + * @param string $scope Scope + * @param string $user $user + * + * @return boolean True on success or a PEAR_Error object on failure. + */ + public function logActivity($message, $scope = 'folks', $user = null) + { + if (empty($user)) { + $user = Horde_Auth::getAuth(); + } elseif ($user !== Horde_Auth::getAuth() && !Horde_Auth::isAdmin('admin:' . $scope)) { + return PEAR::raiseError(_("You cannot log activities for other users.")); + } + + require_once dirname(__FILE__) . '/base.php'; + + return $GLOBALS['folks_driver']->logActivity($message, $scope, $user); + } + + /** + * Get user's activity + * + * @param string $user Username + * @param int $limit Number of actions to return + * + * @return array Activity log + */ + public function getActivity($user, $limit = 10) + { + require_once dirname(__FILE__) . '/base.php'; + + return $GLOBALS['folks_driver']->getActivity($user, $limit); + } + + /** + * Set user status + * + * @param booelan $online True to set user online, false to push it offline + * @param string $user Username + * + * @return boolean True if succes, PEAR_Error on failure + */ + public function setStatus($online = true, $user = null) + { + require_once dirname(__FILE__) . '/base.php'; + + if ($user == null) { + $user = Horde_Auth::getAuth(); + } + + if ($online) { + return $GLOBALS['folks_driver']->resetOnlineUsers(); + } else { + $result = $GLOBALS['folks_driver']->deleteOnlineUser($user); + $GLOBALS['cache']->expire('folksOnlineUsers'); + return $result; + } + } + + /** + * Get user status + * + * @param string $user Username + * + * @return boolean True if user is online, false otherwise + */ + public function getStatus($user = null) + { + require_once dirname(__FILE__) . '/base.php'; + + if ($user == null) { + $user = Horde_Auth::getAuth(); + } + + return $GLOBALS['folks_driver']->isOnline($user); + } + + /** + * Authenticate a givern user + * + * @param string $userID Username + * @param array $credentials Array of criedentials (password requied) + * @param array $params Additional params + * + * @return boolean Whether IMP authentication was successful. + */ + public function authenticate($userID, $credentials, $params) + { + require_once dirname(__FILE__) . '/base.php'; + + return $GLOBALS['folks_driver']->comparePassword($userID, $credentials['password']); + } + + /** + * Check if a user exists + * + * @param string $userID Username + * + * @return boolean True if user exists + */ + public function userExists($userId) + { + require_once dirname(__FILE__) . '/base.php'; + + return $GLOBALS['folks_driver']->userExists($userId); + } + + /** + * Lists all users in the system. + * + * @return array The array of userIds, or a PEAR_Error object on failure. + */ + public function userList() + { + require_once dirname(__FILE__) . '/base.php'; + + $users = array(); + foreach ($GLOBALS['folks_driver']->getUsers() as $user) { + $users[] = $user['user_uid']; + } + + return $users; + } + + /** + * Adds a set of authentication credentials. + * + * @param string $userId The userId to add. + * + * @return boolean True on success or a PEAR_Error object on failure. + */ + public function addUser($userId) + { + require_once dirname(__FILE__) . '/base.php'; + + return $GLOBALS['folks_driver']->addUser($userId); + } + + /** + * Deletes a set of authentication credentials. + * + * @param string $userId The userId to delete. + * + * @return boolean True on success or a PEAR_Error object on failure. + */ + public function removeUser($userId) + { + require_once dirname(__FILE__) . '/base.php'; + + return $GLOBALS['folks_driver']->deleteUser($userId); + } + + /** + * Deletes a user and its data + * + * @param string $userId The userId to delete. + * + * @return boolean True on success or a PEAR_Error object on failure. + */ + public function removeUserData($user = null) + { + return $this->removeUser($user); + } + +} diff --git a/folks/lib/api.php b/folks/lib/api.php deleted file mode 100644 index 77d38a255..000000000 --- a/folks/lib/api.php +++ /dev/null @@ -1,563 +0,0 @@ - - * @package Folks - */ - -$_services['commentCallback'] = array( - 'args' => array('id' => 'string'), - 'type' => 'string' -); - -$_services['removeUserData'] = array( - 'args' => array('user' => 'string'), - 'type' => 'boolean' -); - -$_services['hasComments'] = array( - 'args' => array(), - 'type' => 'boolean' -); - -$_services['getOnlineUsers'] = array( - 'args' => array(), - 'type' => 'array' -); - -$_services['getProfile'] = array( - 'args' => array(), - 'type' => 'array' -); - -$_services['getFriends'] = array( - 'args' => array('user' => 'string'), - 'type' => 'array' -); - -$_services['addFriend'] = array( - 'args' => array('friend' => 'string'), - 'type' => 'boolean' -); - -$_services['getBlacklist'] = array( - 'args' => array('user' => 'string'), - 'type' => 'array' -); - -$_services['addBlacklisted'] = array( - 'args' => array('user' => 'string'), - 'type' => 'boolean' -); - -$_services['removeBlacklisted'] = array( - 'args' => array('user' => 'string'), - 'type' => 'boolean' -); - -$_services['isBlacklisted'] = array( - 'args' => array('user' => 'string'), - 'type' => 'boolean' -); - -$_services['show'] = array( - 'link' => '%application%/user.php?user=|user|' -); - -$_services['listTimeObjectCategories'] = array( - 'type' => '{urn:horde}stringArray' -); - -$_services['listTimeObjects'] = array( - 'args' => array('start' => 'int', 'end' => 'int'), - 'type' => '{urn:horde}hashHash' -); - -$_services['logActivity'] = array( - 'args' => array('activity_message' => 'string', - 'scope' => 'string', - 'user' => 'string'), - 'type' => 'boolean' -); - -$_services['getActivity'] = array( - 'args' => array('user' => 'string'), - 'type' => 'boolean' -); - -$_services['setStatus'] = array( - 'args' => array('status' => 'boolean'), - 'args' => array('user' => 'string'), - 'type' => 'array' -); - -$_services['getStatus'] = array( - 'args' => array('user' => 'string'), - 'type' => 'array' -); - -$_services['authenticate'] = array( - 'args' => array('userID' => 'string', - 'credentials' => '{urn:horde}hash', - 'params' => '{urn:horde}hash'), - 'checkperms' => false, - 'type' => 'boolean' -); - -$_services['userExists'] = array( - 'args' => array('userId' => 'string'), - 'type' => 'boolean' -); - -$_services['addUser'] = array( - 'args' => array('userId' => 'string') -); - -$_services['getImageUrl'] = array( - 'args' => array('user' => 'string', - 'view' => 'string', - 'full' => 'boolean'), - 'type' => 'string' -); - -if (Horde_Auth::isAdmin()) { - $_services['userList'] = array( - 'type' => '{urn:horde}stringArray' - ); - - $_services['removeUser'] = array( - 'args' => array('userId' => 'string') - ); -} - -/** - * Returns profile image URL. - * - * @param string $user User uid - * @param string $view The view ('small', 'big') to show. - * @param boolean $full Return a path that includes the server name? - * - * @return string The image path. - */ -function _folks_getImageUrl($user, $view = 'small', $full = false) -{ - require_once dirname(__FILE__) . '/base.php'; - - return Folks::getImageUrl($user, $view, $full); -} - -/** - * Callback for comment API. - * - * @param int $id Internal data identifier. - * @param string $type Type of data to retreive (title, owner...). - * @param array $params Parameter to be passed to callback function - */ -function _folks_commentCallback($id, $type = 'title', $params = null) -{ - static $info; - - if (!empty($info[$id][$type])) { - return $info[$id][$type]; - } - - require_once dirname(__FILE__) . '/base.php'; - - switch ($type) { - - case 'owner': - return $id; - - case 'link': - return Folks::getUrlFor('user', $id); - - case 'messages': - - // Update comments count - $result = $GLOBALS['folks_driver']->updateComments($id); - if ($result instanceof PEAR_Error) { - return $result; - } - - // Update activity log - $link = '' . $id . ''; - return $GLOBALS['folks_driver']->logActivity(sprintf(_("Commented user %s."), $link), 'folks:comments'); - - return true; - - default: - return $id; - } -} - -/** - * Comments are enebled - */ -function _folks_hasComments() -{ - return $GLOBALS['conf']['comments']['allow']; -} - -/** - * Get online users - */ -function _folks_getOnlineUsers() -{ - require_once dirname(__FILE__) . '/base.php'; - - return $GLOBALS['folks_driver']->getOnlineUsers(); -} - -/** - * Get user profile - * - * @param string $user User to get profile for - */ -function _folks_getProfile($user = null) -{ - require_once dirname(__FILE__) . '/base.php'; - - return $GLOBALS['folks_driver']->getProfile($user); -} - - -/** - * Get user friends - * - * @param string $user Username to get friends for - * - * @return array of users - */ -function _folks_getFriends($user = null) -{ - require_once dirname(__FILE__) . '/Friends.php'; - - $friends = Folks_Friends::singleton('sql', array('user' => $user)); - - return $friends->getFriends(); -} - -/** - * Add user to our friend list - * - * @param string $friend Friend's usersame - * - * @return true or PEAR_Error - */ -function _folks_addFriend($user = null) -{ - require_once dirname(__FILE__) . '/Friends.php'; - - $friends = Folks_Friends::singleton('sql', array('user' => $user)); - - return $friends->addFriend($user); -} - -/** - * Remove user from a fiend list - * - * @param string $friend Friend's usersame - * - * @return true or PEAR_Error - */ -function _folks_removeFriend($user = null) -{ - require_once dirname(__FILE__) . '/Friends.php'; - - $friends = Folks_Friends::singleton('sql', array('user' => $user)); - - return $friends->removeFriend($user); -} - -/** - * Get user blacklist - * - * @param string $user Username to get blacklist for - * - * @return array of users - */ -function _folks_getBlacklist($user = null) -{ - require_once dirname(__FILE__) . '/Friends.php'; - - $friends = Folks_Friends::singleton('sql', array('user' => $user)); - - return $friends->getBlacklist(); -} - -/** - * Add user to a blacklist list - * - * @param string $user Usersame - */ -function _folks_addBlacklisted($user = null) -{ - require_once dirname(__FILE__) . '/Friends.php'; - - $friends = Folks_Friends::singleton('sql', array('user' => $user)); - - return $friends->addBlacklisted($user); -} - -/** - * Remove user from a blacklist list - * - * @param string $user Usersame - */ -function _folks_removeBlacklisted($user = null) -{ - require_once dirname(__FILE__) . '/Friends.php'; - - $friends = Folks_Friends::singleton('sql', array('user' => $user)); - - return $friends->removeBlacklisted($user); -} - -/** - * Are we blackisted by user this user? - * - * @param string $user Username to get blacklist for - * - * @return array of users - */ -function _folks_isBlacklisted($user = null) -{ - require_once dirname(__FILE__) . '/Friends.php'; - - $friends = Folks_Friends::singleton('sql', array('user' => $user)); - - return $friends->isBlacklisted(Horde_Auth::getAuth()); -} - -/** - * Users categories - */ -function _folks_listTimeObjectCategories() -{ - return array('birthday_friends' => _("Friends Birthdays")); -} - -/** - * Lists users with birthdays/goout dates as time objects. - * - * @param array $categories The time categories (from listTimeObjectCategories) to list. - * @param Horde_Date $start The start date of the period. - * @param Horde_Date $end The end date of the period. - */ -function _folks_listTimeObjects($categories, $start, $end) -{ - require_once dirname(__FILE__) . '/base.php'; - require_once FOLKS_BASE . '/lib/Friends.php'; - - $friends_driver = Folks_Friends::singleton('sql'); - $friends = $friends_driver->getFriends(); - if ($friends instanceof PEAR_Error) { - return array(); - } - - $objects = array(); - - foreach ($friends as $friend) { - $user = $GLOBALS['folks_driver']->getProfile($friend); - if ($user instanceof PEAR_Error) { - continue; - } - - $user['user_birthday'] = date('Y') . substr($user['user_birthday'], 4); - $born = strtotime($user['user_birthday']); - if ($born === false || - $born < $start->timestamp() || - $born > $end->timestamp()) { - continue; - } - - $age = Folks::calcAge($user['user_birthday']); - $desc = $age['age'] . ' (' . $age['sign'] . ')'; - - $objects[$friend] = array( - 'title' => $friend, - 'description' => $desc, - 'id' => $friend, - 'start' => date('Y-m-d\TH:i:s', $born), - 'end' => date('Y-m-d\TH:i:s', $born + 1), - 'params' => array('user' => $friend), - 'link' => Folks::getUrlFor('user', $friend, true)); - } - - return $objects; -} - -/** - * Log user's activity - * - * @param mixed $message Activity message or details - * @param string $scope Scope - * @param string $user $user - * - * @return boolean True on success or a PEAR_Error object on failure. - */ -function _folks_logActivity($message, $scope = 'folks', $user = null) -{ - if (empty($user)) { - $user = Horde_Auth::getAuth(); - } elseif ($user !== Horde_Auth::getAuth() && !Horde_Auth::isAdmin('admin:' . $scope)) { - return PEAR::raiseError(_("You cannot log activities for other users.")); - } - - require_once dirname(__FILE__) . '/base.php'; - - return $GLOBALS['folks_driver']->logActivity($message, $scope, $user); -} - -/** - * Get user's activity - * - * @param string $user Username - * @param int $limit Number of actions to return - * - * @return array Activity log - */ -function _folks_getActivity($user, $limit = 10) -{ - require_once dirname(__FILE__) . '/base.php'; - - return $GLOBALS['folks_driver']->getActivity($user, $limit); -} - -/** - * Set user status - * - * @param booelan $online True to set user online, false to push it offline - * @param string $user Username - * - * @return boolean True if succes, PEAR_Error on failure - */ -function _folks_setStatus($online = true, $user = null) -{ - require_once dirname(__FILE__) . '/base.php'; - - if ($user == null) { - $user = Horde_Auth::getAuth(); - } - - if ($online) { - return $GLOBALS['folks_driver']->resetOnlineUsers(); - } else { - $result = $GLOBALS['folks_driver']->deleteOnlineUser($user); - $GLOBALS['cache']->expire('folksOnlineUsers'); - return $result; - } -} - -/** - * Get user status - * - * @param string $user Username - * - * @return boolean True if user is online, false otherwise - */ -function _folks_getStatus($user = null) -{ - require_once dirname(__FILE__) . '/base.php'; - - if ($user == null) { - $user = Horde_Auth::getAuth(); - } - - return $GLOBALS['folks_driver']->isOnline($user); -} - -/** - * Authenticate a givern user - * - * @param string $userID Username - * @param array $credentials Array of criedentials (password requied) - * @param array $params Additional params - * - * @return boolean Whether IMP authentication was successful. - */ -function _folks_authenticate($userID, $credentials, $params) -{ - require_once dirname(__FILE__) . '/base.php'; - - return $GLOBALS['folks_driver']->comparePassword($userID, $credentials['password']); -} - -/** - * Check if a user exists - * - * @param string $userID Username - * - * @return boolean True if user exists - */ -function _folks_userExists($userId) -{ - require_once dirname(__FILE__) . '/base.php'; - - return $GLOBALS['folks_driver']->userExists($userId); -} - -/** - * Lists all users in the system. - * - * @return array The array of userIds, or a PEAR_Error object on failure. - */ -function _folks_userList() -{ - require_once dirname(__FILE__) . '/base.php'; - - $users = array(); - foreach ($GLOBALS['folks_driver']->getUsers() as $user) { - $users[] = $user['user_uid']; - } - - return $users; -} - -/** - * Adds a set of authentication credentials. - * - * @param string $userId The userId to add. - * - * @return boolean True on success or a PEAR_Error object on failure. - */ -function _folks_addUser($userId) -{ - require_once dirname(__FILE__) . '/base.php'; - - return $GLOBALS['folks_driver']->addUser($userId); -} - -/** - * Deletes a set of authentication credentials. - * - * @param string $userId The userId to delete. - * - * @return boolean True on success or a PEAR_Error object on failure. - */ -function _folks_removeUser($userId) -{ - require_once dirname(__FILE__) . '/base.php'; - - return $GLOBALS['folks_driver']->deleteUser($userId); -} - -/** - * Deletes a user and its data - * - * @param string $userId The userId to delete. - * - * @return boolean True on success or a PEAR_Error object on failure. - */ -function _folks_removeUserData($user = null) -{ - return _folks_removeUser($user); -} diff --git a/folks/lib/version.php b/folks/lib/version.php deleted file mode 100644 index a1f769b34..000000000 --- a/folks/lib/version.php +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/gollem/lib/Api.php b/gollem/lib/Api.php new file mode 100644 index 000000000..6c2fd253a --- /dev/null +++ b/gollem/lib/Api.php @@ -0,0 +1,651 @@ + array( + 'args' => array(), + 'type' => '{urn:horde}hashHash' + ), + + 'browse' => array( + 'args' => array('path' => 'string'), + 'type' => '{urn:horde}hashHash', + ), + + 'put' => array( + 'args' => array( + 'path' => 'string', + 'content' => 'string', + 'content_type' => 'string' + ), + 'type' => 'int', + ), + + 'mkcol' => array( + 'args' => array('path' => 'string'), + 'type' => 'int', + ), + + 'move' => array( + 'args' => array( + 'path' => 'string', + 'dest' => 'string' + ), + 'type' => 'int', + ), + + 'path_delete' => array( + 'args' => array('path' => 'string'), + 'type' => 'int', + ), + + 'selectlistLink' => array( + 'args' => array( + 'link_text' => 'string', + 'link_style' => 'string', + 'formid' => 'string', + 'icon' => 'boolean', + 'selectid' => 'string' + ), + 'type' => 'string' + ), + + 'selectlistResults' => array( + 'args' => array('selectid' => 'string'), + 'type' => 'array' + ), + + 'returnFromSelectlist' => array( + 'args' => array( + 'selectid' => 'string', + 'index' => 'string' + ), + 'type' => 'string' + ), + + 'setSelectList' => array( + 'args' => array( + 'selectid' => 'string', + 'files' => 'array' + ), + 'type' => 'string' + ), + + 'getViewLink' => array( + 'args' => array( + 'dir' => 'string', + 'file' => 'string', + 'backend' => 'string' + ), + 'type' => 'string' + ) + ); + + /** + * Browses through the VFS tree. + * + * Each VFS backend is listed as a directory at the top level. No modify + * operations are allowed outside any VFS area. + * + * @param string $path The level of the tree to browse. + * @param array $properties The item properties to return. Defaults to 'name', + * 'icon', and 'browseable'. + * + * @return array The contents of $path. + */ + public function browse($path = '', $properties = array()) + { + $GLOBALS['gollem_authentication'] = 'none'; + require_once dirname(__FILE__) . '/base.php'; + require GOLLEM_BASE . '/config/backends.php'; + require GOLLEM_BASE . '/config/credentials.php'; + + $path = Gollem::stripAPIPath($path); + + // Default properties. + if (!$properties) { + $properties = array('name', 'icon', 'browseable'); + } + + $results = array(); + if ($path == '') { + // We are at the root of gollem. Return a set of folders, one for + // each backend available. + foreach ($backends as $backend => $curBackend) { + if (Gollem::checkPermissions('backend', PERMS_SHOW, $backend)) { + $results['gollem/' . $backend]['name'] = $curBackend['name']; + $results['gollem/' . $backend]['browseable'] = true; + } + } + } else { + // A file or directory has been requested. + + // Locate the backend_key in the path. + if (strchr($path, '/')) { + $backend_key = substr($path, 0, strpos($path, '/')); + } else { + $backend_key = $path; + } + + // Validate and perform permissions checks on the requested backend + if (!isset($backends[$backend_key])) { + return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); + } + //if (!Gollem::canAutoLogin($backend_key)) { + // // FIXME: Is it possible to request secondary authentication + // // credentials here for backends that require it? + // return PEAR::raiseError(_("Additional authentication required.")); + //} + if (!Gollem_Session::createSession($backend_key)) { + return PEAR::raiseError(_("Unable to create Gollem session")); + } + if (!Gollem::checkPermissions('backend', PERMS_READ)) { + return PEAR::raiseError(_("Permission denied to this backend.")); + } + + // Trim off the backend_key (and '/') to get the VFS relative path + $fullpath = substr($path, strlen($backend_key) + 1); + + // Get the VFS-standard $name,$path pair + list($name, $path) = Gollem::getVFSPath($fullpath); + + // Check to see if the request is a file or folder + if ($GLOBALS['gollem_vfs']->isFolder($path, $name)) { + // This is a folder request. Return a directory listing. + $list = Gollem::listFolder($path . '/' . $name); + if (is_a($list, 'PEAR_Error')) { + return $list; + } + + // Iterate over the directory contents + if (is_array($list) && count($list)) { + $index = 'gollem/' . $backend_key . '/' . $fullpath; + foreach ($list as $key => $val) { + $entry = Gollem::pathEncode($index . '/' . $val['name']); + $results[$entry]['name'] = $val['name']; + $results[$entry]['modified'] = $val['date']; + if ($val['type'] == '**dir') { + $results[$entry]['browseable'] = true; + } else { + $results[$entry]['browseable'] = false; + $results[$entry]['contentlength'] = $val['size']; + } + } + } + } else { + // A file has been requested. Return the contents of the file. + + // Get the file meta-data + $list = Gollem::listFolder($path); + $i = false; + foreach ($list as $key => $file) { + if ($file['name'] == $name) { + $i = $key; + break; + } + } + if ($i === false) { + // File not found + return $i; + } + + // Read the file contents + $data = $GLOBALS['gollem_vfs']->read($path, $name); + if (is_a($data, 'PEAR_Error')) { + return false; + } + + // Send the file + $results['name'] = $name; + $results['data'] = $data; + $results['contentlength'] = $list[$i]['size']; + $results['mtime'] = $list[$i]['date']; + } + } + + return $results; + } + + /** + * Accepts a file for storage into the VFS + * + * @param string $path Path to store file + * @param string $content Contents of file + * @param string $content_type MIME type of file + * + * @return mixed True on success; PEAR_Error on failure + */ + public function put($path, $content, $content_type) + { + // Gollem does not handle authentication + $GLOBALS['gollem_authentication'] = 'none'; + + // Include Gollem base libraries + require_once dirname(__FILE__) . '/base.php'; + require GOLLEM_BASE . '/config/backends.php'; + require GOLLEM_BASE . '/config/credentials.php'; + + // Clean off the irrelevant portions of the path + $path = Gollem::stripAPIPath($path); + + if ($path == '') { + // We are at the root of gollem. Any writes at this level are + // disallowed. + return PEAR::raiseError(_("Files must be written inside a VFS backend.")); + } else { + // We must be inside one of the VFS areas. Determine which one. + // Locate the backend_key in the path + if (strchr($path, '/')) { + $backend_key = substr($path, 0, strpos($path, '/')); + } else { + $backend_key = $path; + } + + // Validate and perform permissions checks on the requested backend + if (!isset($backends[$backend_key])) { + return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); + } + //if (!Gollem::canAutoLogin($backend_key)) { + // // FIXME: Is it possible to request secondary authentication + // // credentials here for backends that require it? + // return PEAR::raiseError(_("Additional authentication required.")); + //} + if (!Gollem_Session::createSession($backend_key)) { + return PEAR::raiseError(_("Unable to create Gollem session")); + } + if (!Gollem::checkPermissions('backend', PERMS_EDIT)) { + return PEAR::raiseError(_("Permission denied to this backend.")); + } + + // Trim off the backend_key (and '/') to get the VFS relative path + $fullpath = substr($path, strlen($backend_key) + 1); + + // Get the VFS-standard $name,$path pair + list($name, $path) = Gollem::getVFSPath($fullpath); + + return $GLOBALS['gollem_vfs']->writeData($path, $name, $content); + } + } + + /** + * Creates a directory ("collection" in WebDAV-speak) within the VFS + * + * @param string $path Path of directory to create + * + * @return mixed True on success; PEAR_Error on failure + */ + public function mkcol($path) + { + // Gollem does not handle authentication + $GLOBALS['gollem_authentication'] = 'none'; + + // Include Gollem base libraries + require_once dirname(__FILE__) . '/base.php'; + require GOLLEM_BASE . '/config/backends.php'; + require GOLLEM_BASE . '/config/credentials.php'; + + // Clean off the irrelevant portions of the path + $path = Gollem::stripAPIPath($path); + + if ($path == '') { + // We are at the root of gollem. Any writes at this level are + // disallowed. + return PEAR::raiseError(_('Folders must be created inside a VFS backend.')); + } else { + // We must be inside one of the VFS areas. Determine which one. + // Locate the backend_key in the path + if (!strchr($path, '/')) { + // Disallow attempts to create a share-level directory. + return PEAR::raiseError(_('Folders must be created inside a VFS backend.')); + } else { + $backend_key = substr($path, 0, strpos($path, '/')); + } + + // Validate and perform permissions checks on the requested backend + if (!isset($backends[$backend_key])) { + return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); + } + //if (!Gollem::canAutoLogin($backend_key)) { + // // FIXME: Is it possible to request secondary authentication + // // credentials here for backends that require it? + // return PEAR::raiseError(_("Additional authentication required.")); + //} + if (!Gollem_Session::createSession($backend_key)) { + return PEAR::raiseError(_("Unable to create Gollem session")); + } + if (!Gollem::checkPermissions('backend', PERMS_EDIT)) { + return PEAR::raiseError(_("Permission denied to this backend.")); + } + + // Trim off the backend_key (and '/') to get the VFS relative path + $fullpath = substr($path, strlen($backend_key) + 1); + + // Get the VFS-standard $name,$path pair + list($name, $path) = Gollem::getVFSPath($fullpath); + + return $GLOBALS['gollem_vfs']->createFolder($path, $name); + } + } + + /** + * Renames a file or directory + * + * @param string $path Path to source object to be renamed + * @param string $dest Path to new name + * + * @return mixed True on success; PEAR_Error on failure + */ + public function move($path, $dest) + { + // Gollem does not handle authentication + $GLOBALS['gollem_authentication'] = 'none'; + + // Include Gollem base libraries + require_once dirname(__FILE__) . '/base.php'; + require GOLLEM_BASE . '/config/backends.php'; + require GOLLEM_BASE . '/config/credentials.php'; + + // Clean off the irrelevant portions of the path + $path = Gollem::stripAPIPath($path); + $dest = Gollem::stripAPIPath($dest); + + if ($path == '') { + // We are at the root of gollem. Any writes at this level are + // disallowed. + return PEAR::raiseError(_('Folders must be created inside a VFS backend.')); + } else { + // We must be inside one of the VFS areas. Determine which one. + // Locate the backend_key in the path + if (!strchr($path, '/')) { + // Disallow attempts to rename a share-level directory. + return PEAR::raiseError(_('Renaming of backends is not allowed.')); + } else { + $backend_key = substr($path, 0, strpos($path, '/')); + } + + // Ensure that the destination is within the same backend + if (!strchr($dest, '/')) { + // Disallow attempts to rename a share-level directory. + return PEAR::raiseError(_('Renaming of backends is not allowed.')); + } else { + $dest_backend_key = substr($path, 0, strpos($path, '/')); + if ($dest_backend_key != $backend_key) { + return PEAR::raiseError(_('Renaming across backends is not supported.')); + } + } + + // Validate and perform permissions checks on the requested backend + if (!isset($backends[$backend_key])) { + return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); + } + //if (!Gollem::canAutoLogin($backend_key)) { + // // FIXME: Is it possible to request secondary authentication + // // credentials here for backends that require it? + // return PEAR::raiseError(_("Additional authentication required.")); + //} + if (!Gollem_Session::createSession($backend_key)) { + return PEAR::raiseError(_("Unable to create Gollem session")); + } + if (!Gollem::checkPermissions('backend', PERMS_EDIT)) { + return PEAR::raiseError(_("Permission denied to this backend.")); + } + + // Trim off the backend_key (and '/') to get the VFS relative path + $srcfullpath = substr($path, strlen($backend_key) + 1); + $dstfullpath = substr($dest, strlen($backend_key) + 1); + + // Get the VFS-standard $name,$path pair + list($srcname, $srcpath) = Gollem::getVFSPath($srcfullpath); + list($dstname, $dstpath) = Gollem::getVFSPath($dstfullpath); + + return $GLOBALS['gollem_vfs']->rename($srcpath, $srcname, $dstpath, $dstname); + } + } + + /** + * Removes a file or folder from the VFS + * + * @param string $path Path of file or folder to delete + * + * @return mixed True on success; PEAR_Error on failure + */ + public function path_delete($path) + { + // Gollem does not handle authentication + $GLOBALS['gollem_authentication'] = 'none'; + + // Include Gollem base libraries + require_once dirname(__FILE__) . '/base.php'; + require GOLLEM_BASE . '/config/backends.php'; + require GOLLEM_BASE . '/config/credentials.php'; + + // Clean off the irrelevant portions of the path + $path = Gollem::stripAPIPath($path); + + if ($path == '') { + // We are at the root of gollem. Any writes at this level are + // disallowed. + return PEAR::raiseError(_("The application folder can not be deleted.")); + } else { + // We must be inside one of the VFS areas. Determine which one. + // Locate the backend_key in the path + if (strchr($path, '/')) { + $backend_key = substr($path, 0, strpos($path, '/')); + } else { + $backend_key = $path; + } + + // Validate and perform permissions checks on the requested backend + if (!isset($backends[$backend_key])) { + return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); + } + //if (!Gollem::canAutoLogin($backend_key)) { + // // FIXME: Is it possible to request secondary authentication + // // credentials here for backends that require it? + // return PEAR::raiseError(_("Additional authentication required.")); + //} + if (!Gollem_Session::createSession($backend_key)) { + return PEAR::raiseError(_("Unable to create Gollem session")); + } + if (!Gollem::checkPermissions('backend', PERMS_EDIT)) { + return PEAR::raiseError(_("Permission denied to this backend.")); + } + + // Trim off the backend_key (and '/') to get the VFS relative path + $fullpath = substr($path, strlen($backend_key) + 1); + + // Get the VFS-standard $name,$path pair + list($name, $path) = Gollem::getVFSPath($fullpath); + + // Apparently Gollem::verifyDir() (called by deleteF* next) needs to + // see a path with a leading '/' + $path = $backends[$backend_key]['root'] . $path; + if ($GLOBALS['gollem_vfs']->isFolder($path, $name)) { + return Gollem::deleteFolder($path, $name); + } else { + return Gollem::deleteFile($path, $name); + } + } + } + + public function perms() + { + static $perms = array(); + if (!empty($perms)) { + return $perms; + } + + require_once dirname(__FILE__) . '/base.load.php'; + require GOLLEM_BASE . '/config/backends.php'; + + $perms['tree']['gollem']['backends'] = false; + $perms['title']['gollem:backends'] = _("Backends"); + + // Run through every backend. + foreach ($backends as $backend => $curBackend) { + $perms['tree']['gollem']['backends'][$backend] = false; + $perms['title']['gollem:backends:' . $backend] = $curBackend['name']; + } + + return $perms; + } + + /** + * Returns a link to the gollem file preview interface + * + * @param string $dir File absolute path + * @param string $file File basename + * @param string $backend Backend key. Defaults to Gollem::getPreferredBackend() + * + * @return string The URL string. + */ + public function getViewLink($dir, $file, $backend = '') + { + require_once dirname(__FILE__) . '/base.php'; + + if (empty($backend)) { + $backend = Gollem::getPreferredBackend(); + } + + $url = Horde_Util::addParameter( + Horde::applicationUrl('view.php'), + array('actionID' => 'view_file', + 'type' => substr($file, strrpos($file, '.') + 1), + 'file' => $file, + 'dir' => $dir, + 'driver' => $_SESSION['gollem']['backends'][$backend]['driver'])); + + return $url; + } + + /** + * Creates a link to the gollem file selection window. + * + * The file section window will return a cache ID value which should be used + * (along with the selectListResults and returnFromSelectList functions below) + * to obtain the data from a list of selected files. + * + * There MUST be a form field named 'selectlist_selectid' in the calling + * form. This field will be populated with the selection ID when the user + * completes file selection. + * + * There MUST be a form parameter named 'actionID' in the calling form. + * This form will be populated with the value 'selectlist_process' when + * the user completes file selection. The calling form will be submitted + * after the window closes (i.e. the calling form must process the + * 'selectlist_process' actionID). + * + * @param string $link_text The text to use in the link. + * @param string $link_style The style to use for the link. + * @param string $formid The formid of the calling script. + * @param boolean $icon Create the link with an icon instead of text? + * @param string $selectid Selection ID. + * + * @return string The URL string. + */ + public function selectlistLink($link_text, $link_style, $formid, + $icon = false, $selectid = '') + { + $link = Horde::link('#', $link_text, $link_style, '_blank', Horde::popupJs(Horde::applicationUrl('selectlist.php'), array('params' => array('formid' => $formid, 'cacheid' => $selectid), 'height' => 500, 'width' => 300, 'urlencode' => true)) . 'return false;'); + if ($icon) { + $link_text = Horde::img('gollem.png', $link_text); + } + return ''; + } + + /** + * Returns the list of files selected by the user for a given selection ID. + * + * @param string $selectid The selection ID. + * + * @param array An array with each file entry stored in its own array, with + * the key as the directory name and the value as the filename. + */ + public function selectlistResults($selectid) + { + if (!isset($_SESSION['gollem']['selectlist'][$selectid]['files'])) { + return null; + } else { + $list = array(); + foreach ($_SESSION['gollem']['selectlist'][$selectid]['files'] as $val) { + list($dir, $filename) = explode('|', $val); + $list[] = array($dir => $filename); + } + return $list; + } + } + + /** + * Returns the data for a given selection ID and index. + * + * @param string $selectid The selection ID. + * @param integer $index The index of the file data to return. + * + * @return string The file data. + */ + public function returnFromSelectlist($selectid, $index) + { + require_once dirname(__FILE__) . '/base.php'; + + if (!isset($_SESSION['gollem']['selectlist'][$selectid]['files'][$index])) { + return null; + } + + list($dir, $filename) = explode('|', $_SESSION['gollem']['selectlist'][$selectid]['files'][$index]); + return $GLOBALS['gollem_vfs']->read($dir, $filename); + } + + /** + * Sets the files selected for a given selection ID. + * + * @param string $selectid The selection ID to use. + * @param array $files An array with each file entry stored in its own + * array, with the key as the directory name and the + * value as the filename. + * + * @return string The selection ID. + */ + public function setSelectlist($selectid = '', $files = array()) + { + require_once dirname(__FILE__) . '/base.php'; + + if (empty($selectid)) { + $selectid = uniqid(mt_rand(), true); + } + + if (count($files) > 0) { + $list = array(); + foreach ($files as $file) { + $list[] = key($file) . '|' . current($file); + } + $_SESSION['gollem']['selectlist'][$selectid]['files'] = $list; + } + + return $selectid; + } + +} diff --git a/gollem/lib/api.php b/gollem/lib/api.php deleted file mode 100644 index 286c58b5a..000000000 --- a/gollem/lib/api.php +++ /dev/null @@ -1,605 +0,0 @@ - array('path' => 'string'), - 'type' => '{urn:horde}hashHash', -); - -$_services['put'] = array( - 'args' => array('path' => 'string', 'content' => 'string', 'content_type' => 'string'), - 'type' => 'int', -); - -$_services['mkcol'] = array( - 'args' => array('path' => 'string'), - 'type' => 'int', -); - -$_services['move'] = array( - 'args' => array('path' => 'string', 'dest' => 'string'), - 'type' => 'int', -); - -$_services['path_delete'] = array( - 'args' => array('path' => 'string'), - 'type' => 'int', -); - -$_services['perms'] = array( - 'args' => array(), - 'type' => '{urn:horde}stringArray'); - -$_services['selectlistLink'] = array( - 'args' => array('link_text' => 'string', 'link_style' => 'string', 'formid' => 'string', 'icon' => 'boolean', 'selectid' => 'string'), - 'type' => 'string'); - -$_services['selectlistResults'] = array( - 'args' => array('selectid' => 'string'), - 'type' => 'array'); - -$_services['returnFromSelectlist'] = array( - 'args' => array('selectid' => 'string', 'index' => 'string'), - 'type' => 'string'); - -$_services['setSelectList'] = array( - 'args' => array('selectid' => 'string', 'files' => 'array'), - 'type' => 'string'); - -$_services['getViewLink'] = array( - 'args' => array('dir' => 'string', 'file' => 'string', 'backend' => 'string'), - 'type' => 'string'); - -/** - * Browses through the VFS tree. - * - * Each VFS backend is listed as a directory at the top level. No modify - * operations are allowed outside any VFS area. - * - * @param string $path The level of the tree to browse. - * @param array $properties The item properties to return. Defaults to 'name', - * 'icon', and 'browseable'. - * - * @return array The contents of $path. - */ -function _gollem_browse($path = '', $properties = array()) -{ - $GLOBALS['gollem_authentication'] = 'none'; - require_once dirname(__FILE__) . '/base.php'; - require GOLLEM_BASE . '/config/backends.php'; - require GOLLEM_BASE . '/config/credentials.php'; - - $path = Gollem::stripAPIPath($path); - - // Default properties. - if (!$properties) { - $properties = array('name', 'icon', 'browseable'); - } - - $results = array(); - if ($path == '') { - // We are at the root of gollem. Return a set of folders, one for - // each backend available. - foreach ($backends as $backend => $curBackend) { - if (Gollem::checkPermissions('backend', PERMS_SHOW, $backend)) { - $results['gollem/' . $backend]['name'] = $curBackend['name']; - $results['gollem/' . $backend]['browseable'] = true; - } - } - } else { - // A file or directory has been requested. - - // Locate the backend_key in the path. - if (strchr($path, '/')) { - $backend_key = substr($path, 0, strpos($path, '/')); - } else { - $backend_key = $path; - } - - // Validate and perform permissions checks on the requested backend - if (!isset($backends[$backend_key])) { - return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); - } - //if (!Gollem::canAutoLogin($backend_key)) { - // // FIXME: Is it possible to request secondary authentication - // // credentials here for backends that require it? - // return PEAR::raiseError(_("Additional authentication required.")); - //} - if (!Gollem_Session::createSession($backend_key)) { - return PEAR::raiseError(_("Unable to create Gollem session")); - } - if (!Gollem::checkPermissions('backend', PERMS_READ)) { - return PEAR::raiseError(_("Permission denied to this backend.")); - } - - // Trim off the backend_key (and '/') to get the VFS relative path - $fullpath = substr($path, strlen($backend_key) + 1); - - // Get the VFS-standard $name,$path pair - list($name, $path) = Gollem::getVFSPath($fullpath); - - // Check to see if the request is a file or folder - if ($GLOBALS['gollem_vfs']->isFolder($path, $name)) { - // This is a folder request. Return a directory listing. - $list = Gollem::listFolder($path . '/' . $name); - if (is_a($list, 'PEAR_Error')) { - return $list; - } - - // Iterate over the directory contents - if (is_array($list) && count($list)) { - $index = 'gollem/' . $backend_key . '/' . $fullpath; - foreach ($list as $key => $val) { - $entry = Gollem::pathEncode($index . '/' . $val['name']); - $results[$entry]['name'] = $val['name']; - $results[$entry]['modified'] = $val['date']; - if ($val['type'] == '**dir') { - $results[$entry]['browseable'] = true; - } else { - $results[$entry]['browseable'] = false; - $results[$entry]['contentlength'] = $val['size']; - } - } - } - } else { - // A file has been requested. Return the contents of the file. - - // Get the file meta-data - $list = Gollem::listFolder($path); - $i = false; - foreach ($list as $key => $file) { - if ($file['name'] == $name) { - $i = $key; - break; - } - } - if ($i === false) { - // File not found - return $i; - } - - // Read the file contents - $data = $GLOBALS['gollem_vfs']->read($path, $name); - if (is_a($data, 'PEAR_Error')) { - return false; - } - - // Send the file - $results['name'] = $name; - $results['data'] = $data; - $results['contentlength'] = $list[$i]['size']; - $results['mtime'] = $list[$i]['date']; - } - } - - return $results; -} - -/** - * Accepts a file for storage into the VFS - * - * @param string $path Path to store file - * @param string $content Contents of file - * @param string $content_type MIME type of file - * - * @return mixed True on success; PEAR_Error on failure - */ -function _gollem_put($path, $content, $content_type) -{ - // Gollem does not handle authentication - $GLOBALS['gollem_authentication'] = 'none'; - - // Include Gollem base libraries - require_once dirname(__FILE__) . '/base.php'; - require GOLLEM_BASE . '/config/backends.php'; - require GOLLEM_BASE . '/config/credentials.php'; - - // Clean off the irrelevant portions of the path - $path = Gollem::stripAPIPath($path); - - if ($path == '') { - // We are at the root of gollem. Any writes at this level are - // disallowed. - return PEAR::raiseError(_("Files must be written inside a VFS backend.")); - } else { - // We must be inside one of the VFS areas. Determine which one. - // Locate the backend_key in the path - if (strchr($path, '/')) { - $backend_key = substr($path, 0, strpos($path, '/')); - } else { - $backend_key = $path; - } - - // Validate and perform permissions checks on the requested backend - if (!isset($backends[$backend_key])) { - return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); - } - //if (!Gollem::canAutoLogin($backend_key)) { - // // FIXME: Is it possible to request secondary authentication - // // credentials here for backends that require it? - // return PEAR::raiseError(_("Additional authentication required.")); - //} - if (!Gollem_Session::createSession($backend_key)) { - return PEAR::raiseError(_("Unable to create Gollem session")); - } - if (!Gollem::checkPermissions('backend', PERMS_EDIT)) { - return PEAR::raiseError(_("Permission denied to this backend.")); - } - - // Trim off the backend_key (and '/') to get the VFS relative path - $fullpath = substr($path, strlen($backend_key) + 1); - - // Get the VFS-standard $name,$path pair - list($name, $path) = Gollem::getVFSPath($fullpath); - - return $GLOBALS['gollem_vfs']->writeData($path, $name, $content); - } -} - -/** - * Creates a directory ("collection" in WebDAV-speak) within the VFS - * - * @param string $path Path of directory to create - * - * @return mixed True on success; PEAR_Error on failure - */ -function _gollem_mkcol($path) -{ - // Gollem does not handle authentication - $GLOBALS['gollem_authentication'] = 'none'; - - // Include Gollem base libraries - require_once dirname(__FILE__) . '/base.php'; - require GOLLEM_BASE . '/config/backends.php'; - require GOLLEM_BASE . '/config/credentials.php'; - - // Clean off the irrelevant portions of the path - $path = Gollem::stripAPIPath($path); - - if ($path == '') { - // We are at the root of gollem. Any writes at this level are - // disallowed. - return PEAR::raiseError(_('Folders must be created inside a VFS backend.')); - } else { - // We must be inside one of the VFS areas. Determine which one. - // Locate the backend_key in the path - if (!strchr($path, '/')) { - // Disallow attempts to create a share-level directory. - return PEAR::raiseError(_('Folders must be created inside a VFS backend.')); - } else { - $backend_key = substr($path, 0, strpos($path, '/')); - } - - // Validate and perform permissions checks on the requested backend - if (!isset($backends[$backend_key])) { - return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); - } - //if (!Gollem::canAutoLogin($backend_key)) { - // // FIXME: Is it possible to request secondary authentication - // // credentials here for backends that require it? - // return PEAR::raiseError(_("Additional authentication required.")); - //} - if (!Gollem_Session::createSession($backend_key)) { - return PEAR::raiseError(_("Unable to create Gollem session")); - } - if (!Gollem::checkPermissions('backend', PERMS_EDIT)) { - return PEAR::raiseError(_("Permission denied to this backend.")); - } - - // Trim off the backend_key (and '/') to get the VFS relative path - $fullpath = substr($path, strlen($backend_key) + 1); - - // Get the VFS-standard $name,$path pair - list($name, $path) = Gollem::getVFSPath($fullpath); - - return $GLOBALS['gollem_vfs']->createFolder($path, $name); - } -} - -/** - * Renames a file or directory - * - * @param string $path Path to source object to be renamed - * @param string $dest Path to new name - * - * @return mixed True on success; PEAR_Error on failure - */ -function _gollem_move($path, $dest) -{ - // Gollem does not handle authentication - $GLOBALS['gollem_authentication'] = 'none'; - - // Include Gollem base libraries - require_once dirname(__FILE__) . '/base.php'; - require GOLLEM_BASE . '/config/backends.php'; - require GOLLEM_BASE . '/config/credentials.php'; - - // Clean off the irrelevant portions of the path - $path = Gollem::stripAPIPath($path); - $dest = Gollem::stripAPIPath($dest); - - if ($path == '') { - // We are at the root of gollem. Any writes at this level are - // disallowed. - return PEAR::raiseError(_('Folders must be created inside a VFS backend.')); - } else { - // We must be inside one of the VFS areas. Determine which one. - // Locate the backend_key in the path - if (!strchr($path, '/')) { - // Disallow attempts to rename a share-level directory. - return PEAR::raiseError(_('Renaming of backends is not allowed.')); - } else { - $backend_key = substr($path, 0, strpos($path, '/')); - } - - // Ensure that the destination is within the same backend - if (!strchr($dest, '/')) { - // Disallow attempts to rename a share-level directory. - return PEAR::raiseError(_('Renaming of backends is not allowed.')); - } else { - $dest_backend_key = substr($path, 0, strpos($path, '/')); - if ($dest_backend_key != $backend_key) { - return PEAR::raiseError(_('Renaming across backends is not supported.')); - } - } - - // Validate and perform permissions checks on the requested backend - if (!isset($backends[$backend_key])) { - return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); - } - //if (!Gollem::canAutoLogin($backend_key)) { - // // FIXME: Is it possible to request secondary authentication - // // credentials here for backends that require it? - // return PEAR::raiseError(_("Additional authentication required.")); - //} - if (!Gollem_Session::createSession($backend_key)) { - return PEAR::raiseError(_("Unable to create Gollem session")); - } - if (!Gollem::checkPermissions('backend', PERMS_EDIT)) { - return PEAR::raiseError(_("Permission denied to this backend.")); - } - - // Trim off the backend_key (and '/') to get the VFS relative path - $srcfullpath = substr($path, strlen($backend_key) + 1); - $dstfullpath = substr($dest, strlen($backend_key) + 1); - - // Get the VFS-standard $name,$path pair - list($srcname, $srcpath) = Gollem::getVFSPath($srcfullpath); - list($dstname, $dstpath) = Gollem::getVFSPath($dstfullpath); - - return $GLOBALS['gollem_vfs']->rename($srcpath, $srcname, $dstpath, $dstname); - } -} - -/** - * Removes a file or folder from the VFS - * - * @param string $path Path of file or folder to delete - * - * @return mixed True on success; PEAR_Error on failure - */ -function _gollem_path_delete($path) -{ - // Gollem does not handle authentication - $GLOBALS['gollem_authentication'] = 'none'; - - // Include Gollem base libraries - require_once dirname(__FILE__) . '/base.php'; - require GOLLEM_BASE . '/config/backends.php'; - require GOLLEM_BASE . '/config/credentials.php'; - - // Clean off the irrelevant portions of the path - $path = Gollem::stripAPIPath($path); - - if ($path == '') { - // We are at the root of gollem. Any writes at this level are - // disallowed. - return PEAR::raiseError(_("The application folder can not be deleted.")); - } else { - // We must be inside one of the VFS areas. Determine which one. - // Locate the backend_key in the path - if (strchr($path, '/')) { - $backend_key = substr($path, 0, strpos($path, '/')); - } else { - $backend_key = $path; - } - - // Validate and perform permissions checks on the requested backend - if (!isset($backends[$backend_key])) { - return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); - } - //if (!Gollem::canAutoLogin($backend_key)) { - // // FIXME: Is it possible to request secondary authentication - // // credentials here for backends that require it? - // return PEAR::raiseError(_("Additional authentication required.")); - //} - if (!Gollem_Session::createSession($backend_key)) { - return PEAR::raiseError(_("Unable to create Gollem session")); - } - if (!Gollem::checkPermissions('backend', PERMS_EDIT)) { - return PEAR::raiseError(_("Permission denied to this backend.")); - } - - // Trim off the backend_key (and '/') to get the VFS relative path - $fullpath = substr($path, strlen($backend_key) + 1); - - // Get the VFS-standard $name,$path pair - list($name, $path) = Gollem::getVFSPath($fullpath); - - // Apparently Gollem::verifyDir() (called by deleteF* next) needs to - // see a path with a leading '/' - $path = $backends[$backend_key]['root'] . $path; - if ($GLOBALS['gollem_vfs']->isFolder($path, $name)) { - return Gollem::deleteFolder($path, $name); - } else { - return Gollem::deleteFile($path, $name); - } - } -} - -function _gollem_perms() -{ - static $perms = array(); - if (!empty($perms)) { - return $perms; - } - - require_once dirname(__FILE__) . '/base.load.php'; - require GOLLEM_BASE . '/config/backends.php'; - - $perms['tree']['gollem']['backends'] = false; - $perms['title']['gollem:backends'] = _("Backends"); - - // Run through every backend. - foreach ($backends as $backend => $curBackend) { - $perms['tree']['gollem']['backends'][$backend] = false; - $perms['title']['gollem:backends:' . $backend] = $curBackend['name']; - } - - return $perms; -} - -/** - * Returns a link to the gollem file preview interface - * - * @param string $dir File absolute path - * @param string $file File basename - * @param string $backend Backend key. Defaults to Gollem::getPreferredBackend() - * - * @return string The URL string. - */ -function _gollem_getViewLink($dir, $file, $backend = '') -{ - require_once dirname(__FILE__) . '/base.php'; - - if (empty($backend)) { - $backend = Gollem::getPreferredBackend(); - } - - $url = Horde_Util::addParameter( - Horde::applicationUrl('view.php'), - array('actionID' => 'view_file', - 'type' => substr($file, strrpos($file, '.') + 1), - 'file' => $file, - 'dir' => $dir, - 'driver' => $_SESSION['gollem']['backends'][$backend]['driver'])); - - return $url; -} - -/** - * Creates a link to the gollem file selection window. - * - * The file section window will return a cache ID value which should be used - * (along with the selectListResults and returnFromSelectList functions below) - * to obtain the data from a list of selected files. - * - * There MUST be a form field named 'selectlist_selectid' in the calling - * form. This field will be populated with the selection ID when the user - * completes file selection. - * - * There MUST be a form parameter named 'actionID' in the calling form. - * This form will be populated with the value 'selectlist_process' when - * the user completes file selection. The calling form will be submitted - * after the window closes (i.e. the calling form must process the - * 'selectlist_process' actionID). - * - * @param string $link_text The text to use in the link. - * @param string $link_style The style to use for the link. - * @param string $formid The formid of the calling script. - * @param boolean $icon Create the link with an icon instead of text? - * @param string $selectid Selection ID. - * - * @return string The URL string. - */ -function _gollem_selectlistLink($link_text, $link_style, $formid, - $icon = false, $selectid = '') -{ - $link = Horde::link('#', $link_text, $link_style, '_blank', Horde::popupJs(Horde::applicationUrl('selectlist.php'), array('params' => array('formid' => $formid, 'cacheid' => $selectid), 'height' => 500, 'width' => 300, 'urlencode' => true)) . 'return false;'); - if ($icon) { - $link_text = Horde::img('gollem.png', $link_text); - } - return ''; -} - -/** - * Returns the list of files selected by the user for a given selection ID. - * - * @param string $selectid The selection ID. - * - * @param array An array with each file entry stored in its own array, with - * the key as the directory name and the value as the filename. - */ -function _gollem_selectlistResults($selectid) -{ - if (!isset($_SESSION['gollem']['selectlist'][$selectid]['files'])) { - return null; - } else { - $list = array(); - foreach ($_SESSION['gollem']['selectlist'][$selectid]['files'] as $val) { - list($dir, $filename) = explode('|', $val); - $list[] = array($dir => $filename); - } - return $list; - } -} - -/** - * Returns the data for a given selection ID and index. - * - * @param string $selectid The selection ID. - * @param integer $index The index of the file data to return. - * - * @return string The file data. - */ -function _gollem_returnFromSelectlist($selectid, $index) -{ - require_once dirname(__FILE__) . '/base.php'; - - if (!isset($_SESSION['gollem']['selectlist'][$selectid]['files'][$index])) { - return null; - } - - list($dir, $filename) = explode('|', $_SESSION['gollem']['selectlist'][$selectid]['files'][$index]); - return $GLOBALS['gollem_vfs']->read($dir, $filename); -} - -/** - * Sets the files selected for a given selection ID. - * - * @param string $selectid The selection ID to use. - * @param array $files An array with each file entry stored in its own - * array, with the key as the directory name and the - * value as the filename. - * - * @return string The selection ID. - */ -function _gollem_setSelectlist($selectid = '', $files = array()) -{ - require_once dirname(__FILE__) . '/base.php'; - - if (empty($selectid)) { - $selectid = uniqid(mt_rand(), true); - } - - if (count($files) > 0) { - $list = array(); - foreach ($files as $file) { - $list[] = key($file) . '|' . current($file); - } - $_SESSION['gollem']['selectlist'][$selectid]['files'] = $list; - } - - return $selectid; -} diff --git a/gollem/lib/version.php b/gollem/lib/version.php deleted file mode 100644 index 79f4a6998..000000000 --- a/gollem/lib/version.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/gollem/test.php b/gollem/test.php index 5b4b8ed6a..dfb7ac67b 100644 --- a/gollem/test.php +++ b/gollem/test.php @@ -33,8 +33,9 @@ $horde_test = new Horde_Test(); /* Gollem version. */ $module = 'Gollem'; -require_once GOLLEM_BASE . '/lib/version.php'; -$module_version = GOLLEM_VERSION; +require_once dirname(__FILE__) . '/lib/Api.php'; +$api = new Gollem_Api(); +$module_version = $api->version; /* Gollem configuration files. */ $file_list = array( diff --git a/imp/acl.php b/imp/acl.php index a755ba53c..4e27e241f 100644 --- a/imp/acl.php +++ b/imp/acl.php @@ -172,10 +172,9 @@ $t->set('canedit', $canEdit); if (empty($_SESSION['imp']['admin'])) { $new_user_field = ''; } else { - require_once IMP_BASE . '/lib/api.php'; $current_users = array_keys($curr_acl); $new_user_field = '