/** * Gets the latest released story from a given internal channel * * @param int $channel_id The channel id. * * @return int The story id. * @throws Jonah_Exception * @throws Horde_Exception_NotFound */ public function getLatestStoryId($channel_id) { $sql = 'SELECT story_id FROM jonah_stories' . ' WHERE channel_id = ? AND story_published <= ?' . ' ORDER BY story_updated DESC'; $values = array((int) $channel_id, time()); Horde::log('SQL Query by Jonah_Driver_sql::getLatestStoryId(): ' . $sql, 'DEBUG'); $result = $this->_db->getRow($sql, $values, DB_FETCHMODE_ASSOC); if ($result instanceof PEAR_Error) { Horde::log($result, 'ERR'); throw new Jonah_Exception($result); } elseif (empty($result)) { return Horde_Exception_NotFound(sprintf(_("Channel \"%s\" not found."), $channel_id)); } return $result['story_id']; }
/** * Gets the latest released story from a given internal channel * * @param int $channel_id The channel id. * * @return int The story id. * @throws Jonah_Exception * @throws Horde_Exception_NotFound */ public function getLatestStoryId($channel_id) { $sql = 'SELECT story_id FROM jonah_stories' . ' WHERE channel_id = ? AND story_published <= ?' . ' ORDER BY story_updated DESC'; Horde::log('SQL Query by Jonah_Driver_sql::getLatestStoryId(): ' . $sql, 'DEBUG'); try { $result = $this->_db->selectValue($sql, array((int) $channel_id, time())); } catch (Horde_Db_Exception $e) { Horde::log($e->getMessage(), 'ERR'); throw new Jonah_Exception($e); } if (empty($result)) { return Horde_Exception_NotFound(sprintf(_("Channel \"%s\" not found."), $channel_id)); } return $result; }
/** * 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 = '', array $properties = array()) { global $injector, $registry; // 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); $storage = $injector->getInstance('Ansel_Storage'); if (empty($path)) { $owners = array(); $galleries = $storage->listGalleries(array('all_levels' => false)); foreach ($galleries as $gallery) { $owners[$gallery->get('owner') ? $gallery->get('owner') : '-system-'] = true; } $results = array(); foreach (array_keys($owners) as $owner) { $path = 'ansel/' . $registry->convertUsername($owner, false); if (in_array('name', $properties)) { $results[$path]['name'] = $injector->getInstance('Horde_Core_Factory_Identity')->create($owner)->getName(); } if (in_array('icon', $properties)) { $results[$path]['icon'] = Horde_Themes::img('user.png'); } if (in_array('browseable', $properties)) { $results[$path]['browseable'] = true; } } return $results; } else { $dav = $injector->getInstance('Horde_Dav_Storage'); $object = end($parts); try { $object = $dav->getInternalObjectId($object, $parts[count($parts) - 2]) ?: $object; } catch (Horde_Dav_Exception $e) { } if (count($parts) == 1) { // This request is for all galleries owned by the requested // user. $galleries = $storage->listGalleries(array('attributes' => $registry->convertUsername($parts[0], true), 'all_levels' => false)); $images = array(); } elseif ($this->galleryExists(end($parts))) { // This request if for a certain gallery, list all sub-galleries // and images. $gallery_id = end($parts); $galleries = $storage->listGalleries(array('parent' => $gallery_id, 'all_levels' => false, 'perm' => Horde_Perms::SHOW)); $images = $this->listImages($gallery_id, array('perms' => Horde_Perms::SHOW, 'view' => 'mini')); } elseif (count($parts) > 2 && $this->galleryExists($parts[count($parts) - 2]) && ($image = $injector->getInstance('Ansel_Storage')->getImage($object))) { return array('data' => $image->raw(), 'mimetype' => $image->type, 'mtime' => $image->uploaded); } else { throw new Horde_Exception_NotFound(_("File not found.")); } $results = array(); foreach ($galleries as $gallery) { $retpath = 'ansel/' . implode('/', $parts) . '/' . $gallery->id; if (in_array('name', $properties)) { $results[$retpath]['name'] = sprintf(_("Photos from %s"), $gallery->get('name')); } if (in_array('displayname', $properties)) { $results[$retpath]['displayname'] = rawurlencode($gallery->get('name')); } if (in_array('icon', $properties)) { $results[$retpath]['icon'] = Horde_Themes::img('ansel.png'); } if (in_array('browseable', $properties)) { $results[$retpath]['browseable'] = $gallery->hasPermission($registry->getAuth(), Horde_Perms::READ); } } $dav = $injector->getInstance('Horde_Dav_Storage'); foreach ($images as $imageId => $image) { try { $imageId = $dav->getExternalObjectId($imageId, $parts[count($parts) - 1]) ?: $imageId; } catch (Horde_Dav_Exception $e) { } $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'] = $image['url']; } if (in_array('browseable', $properties)) { $results[$retpath]['browseable'] = false; } if (in_array('contenttype', $properties)) { $results[$retpath]['contenttype'] = $image['type']; } if (in_array('modified', $properties)) { $results[$retpath]['modified'] = $image['uploaded']; } if (in_array('created', $properties)) { $results[$retpath]['created'] = $image['uploaded']; } if (in_array('etag', $properties)) { $results[$retpath]['etag'] = '"' . md5($imageId . '|' . $image['uploaded']) . '"'; } } return $results; } throw Horde_Exception_NotFound(_("File not found."), 404); }
/** * 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 = '', array $properties = array()) { // 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); $storage = $GLOBALS['injector']->getInstance('Ansel_Storage'); if (empty($path)) { $owners = array(); $galleries = $storage->listGalleries(array('all_levels' => false)); foreach ($galleries as $gallery) { $owners[$gallery->get('owner') ? $gallery->get('owner') : '-system-'] = 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'] = Horde_Themes::img('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 = $storage->listGalleries(array('attributes' => $parts[0], 'all_levels' => false)); $images = array(); } elseif ($this->galleryExists(end($parts))) { // This request if for a certain gallery, list all sub-galleries // and images. $gallery_id = end($parts); $galleries = $storage->listGalleries(array('parent' => $gallery_id, 'all_levels' => false, 'perm' => Horde_Perms::SHOW)); $images = $this->listImages($gallery_id, array('perms' => Horde_Perms::SHOW, 'view' => 'mini')); } elseif (count($parts) > 2 && $this->galleryExists($parts[count($parts) - 2]) && ($image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(end($parts)))) { return array('data' => $image->raw(), 'mimetype' => $image->type, 'mtime' => $image->uploaded); } else { throw new Horde_Exception_NotFound(_("File not found.")); } $results = array(); foreach ($galleries as $gallery) { $retpath = 'ansel/' . implode('/', $parts) . '/' . $gallery->id; if (in_array('name', $properties)) { $results[$retpath]['name'] = sprintf(_("Photos from %s"), $gallery->get('name')); } if (in_array('displayname', $properties)) { $results[$retpath]['displayname'] = rawurlencode($gallery->get('name')); } if (in_array('icon', $properties)) { $results[$retpath]['icon'] = Horde_Themes::img('ansel.png'); } if (in_array('browseable', $properties)) { $results[$retpath]['browseable'] = $gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_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'] = $image['url']; } 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'] = 1; } if (in_array('modified', $properties)) { $results[$retpath]['modified'] = $image['uploaded']; } if (in_array('created', $properties)) { $results[$retpath]['created'] = $image['uploaded']; } if (in_array('etag', $properties)) { $results[$retpath]['etag'] = '"' . md5($imageId . '|' . $image['uploaded']) . '"'; } } return $results; } throw Horde_Exception_NotFound(_("File not found."), 404); }