Return a properly formatted link depending on the global pretty url
configuration
public static getUrlFor ( string $controller, array $data, boolean $full = false, integer $append_session ) : Horde_Url | ||
$controller | string | The controller to generate a URL for. |
$data | array | The data needed to generate the URL. |
$full | boolean | Generate a full URL. |
$append_session | integer | 0 = only if needed, 1 = always, -1 = never. |
return | Horde_Url | The generated URL |
/** * Build the HTML for the other galleries widget content. * * @param Horde_View $view The view object. */ protected function _getOtherGalleries(&$view) { $owner = $this->_view->gallery->get('owner'); // Set up the tree $tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('otherAnselGalleries_' . md5($owner), 'Javascript', array('class' => 'anselWidgets')); try { $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries(array('attributes' => $owner)); } catch (Ansel_Exception $e) { Horde::log($e, 'ERR'); return; } foreach ($galleries as $gallery) { $parents = $gallery->get('parents'); if (empty($parents)) { $parent = null; } else { $parents = explode(':', $parents); $parent = array_pop($parents); } $img = (string) Ansel::getImageUrl($gallery->getKeyImage(Ansel::getStyleDefinition('ansel_default')), 'mini', true); $link = Ansel::getUrlFor('view', array('gallery' => $gallery->id, 'slug' => $gallery->get('slug'), 'view' => 'Gallery'), true); $tree->addNode(array('id' => $gallery->id, 'parent' => $parent, 'label' => $gallery->get('name'), 'expanded' => $gallery->id == $this->_view->gallery->id, 'params' => array('icon' => $img, 'url' => $link))); } Horde::startBuffer(); $tree->sort('label'); $tree->renderTree(); $view->tree = Horde::endBuffer(); $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('Ansel_Ajax_Imple_ToggleOtherGalleries', array('id' => 'othergalleries-toggle')); }
/** */ protected function _content() { $GLOBALS['page_output']->addScriptFile('block.js'); /* Get the top level galleries */ try { $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries(array('perm' => Horde_Perms::EDIT, 'attributes' => $GLOBALS['registry']->getAuth(), 'all_levels' => false, 'count' => empty($this->_params['limit']) ? 0 : $this->_params['limit'], 'sort_by' => 'last_modified', 'direction' => Ansel::SORT_DESCENDING)); } catch (Ansel_Exception $e) { return $e->getMessage(); } $header = array(_("Gallery Name"), _("Last Modified"), _("Photo Count")); $html = <<<HEADER <table class="linedRow" cellspacing="0" style="width:100%"> <thead><tr class="item nowrap"> <th class="item leftAlign">{$header['0']}</th> <th class="item leftAlign">{$header['1']}</th> <th class="item leftAlign">{$header['2']}</th> </tr></thead> <tbody> HEADER; foreach ($galleries as $gallery) { $url = Ansel::getUrlFor('view', array('view' => 'Gallery', 'slug' => $gallery->get('slug'), 'gallery' => $gallery->id), true); $html .= '<tr><td>' . $url->link(array('onmouseout' => '$("ansel_preview").hide();$("ansel_preview").update("");', 'onmouseover' => 'Ansel.previewImage(event, ' . $gallery->getKeyImage(Ansel::getStyleDefinition('ansel_default')) . ');')) . htmlspecialchars($gallery->get('name')) . '</a></td><td>' . strftime($GLOBALS['prefs']->getValue('date_format'), $gallery->get('last_modified')) . '</td><td>' . (int) $gallery->countImages(true) . '</td></tr>'; } $html .= '</tbody></table>'; return $html; }
/** */ public function uploadNotification() { global $conf, $injector, $prefs, $registry; $gallery = $injector->getInstance('Ansel_Storage')->getGallery($this->vars->g); switch ($this->vars->s) { case 'twitter': $url = Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $gallery->id), true); if (!empty($conf['urlshortener'])) { try { $url = $injector->getInstance('Horde_Service_UrlShortener')->shorten($url->setRaw(true)); } catch (Horde_Service_UrlShortener_Exception $e) { Horde::log($e, 'ERR'); header('HTTP/1.1 500'); } } $text = sprintf(_("New images uploaded to %s. %s"), $gallery->get('name'), $url); $token = unserialize($prefs->getValue('twitter')); if (empty($token['key']) && empty($token['secret'])) { $pref_link = $registry->getServiceLink('prefs', 'horde')->add('group', 'twitter')->link(); throw new Ansel_Exception(sprintf(_("You have not properly connected your Twitter account with Horde. You should check your Twitter settings in your %s."), $pref_link . _("preferences") . '</a>')); } $twitter = $injector->getInstance('Horde_Service_Twitter'); $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']); $twitter->auth->setToken($auth_token); try { return $twitter->statuses->update($text); } catch (Horde_Service_Twitter_Exception $e) { Horde::log($e, 'ERR'); header('HTTP/1.1 500'); } } }
/** * Helper function for generating the gallery actions selection widget. * * @param Horde_View $view The view object. */ protected function _getGalleryActions(&$view) { global $registry, $conf; $id = $this->_view->gallery->id; $galleryurl = Horde::url('gallery.php')->add('gallery', $id); $selfurl = Horde::selfUrl(true, false, true); $view->count = $count = $this->_view->gallery->countImages(); $date = $this->_view->gallery->getDate(); // Buid the url parameters to the zip link $view_params = array('gallery' => $this->_view->gallery->id, 'view' => 'Gallery', 'slug' => $this->_view->gallery->get('slug'), 'page' => !empty($this->_view->_params['page']) ? $this->_view->_params['page'] : 0); // Append the date information to the parameters if we need it $view_params = array_merge($view_params, $date); // Bookmark link if ($registry->hasMethod('bookmarks/getAddUrl')) { $api_params = array('url' => Ansel::getUrlFor('view', $view_params, true), 'title' => $this->_view->gallery->get('name')); try { $view->bookmark_url = new Horde_Url($registry->bookmarks->getAddUrl($api_params)); } catch (Horde_Exception $e) { } } // Download as ZIP link if (!empty($conf['gallery']['downloadzip']) && $this->_view->gallery->canDownload() && $count && $this->_view->gallery->hasFeature('zipdownload')) { $zip_params = array_merge(array('actionID' => 'downloadzip'), $date); $view->zip_url = $galleryurl->copy()->add($zip_params)->link(array('class' => 'widget')); } // Image upload, subgalleries, captions etc.. if ($this->_view->gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $view->hasEdit = true; $view->properties_url = $galleryurl->copy()->add(array('actionID' => 'modify', 'url' => $selfurl))->link(array('class' => 'widget')); if ($count) { if ($this->_view->gallery->hasFeature('image_captions')) { $params = array_merge(array('gallery' => $id), $date); $view->captions_url = Horde::url('gallery/captions.php')->add($params)->link(array('class' => 'widget')); } if ($this->_view->gallery->hasFeature('sort_images')) { $view->sort_url = Horde::url('gallery/sort.php')->add(array_merge(array('gallery' => $id), $date))->link(array('class' => 'widget')); $view->resetsort_url = Horde::url('gallery/sort.php')->add(array_merge(array('gallery' => $id, 'action' => 'Reset'), $date))->link(array('class' => 'widget')); } $view->regenerate_url = $galleryurl->copy()->add(array('actionID' => 'generateThumbs'))->link(array('class' => 'widget')); $view->regenerate_all = $galleryurl->copy()->add(array('actionID' => 'deleteCache'))->link(array('class' => 'widget')); if ($conf['faces']['driver'] && $conf['faces']['driver'] !== 'user' && $this->_view->gallery->hasFeature('faces')) { $view->faces_url = Horde::url('faces/gallery.php')->add(array_merge($date, array('gallery' => $id, 'page' => !empty($this->_view->_params['page']) ? $this->_view->_params['page'] : 0)))->link(array('class' => 'widget')); } } if ($this->_view->gallery->hasFeature('stacks')) { $view->gendefault_url = $galleryurl->copy()->add(array('actionID' => 'generateDefault', 'url' => $selfurl))->link(array('class' => 'widget')); } } if ($registry->getAuth() && $this->_view->gallery->get('owner') == $registry->getAuth()) { $url = new Horde_Url('#'); $view->perms_link = $url->link(array('class' => 'popup widget', 'onclick' => Horde::popupJs(Horde::url('perms.php'), array('params' => array('cid' => $this->_view->gallery->id), 'urlencode' => true)) . 'return false;')); } elseif (!empty($conf['report_content']['driver']) && ($conf['report_content']['allow'] == 'authenticated' && $registry->isAuthenticated() || $conf['report_content']['allow'] == 'all')) { $view->report_url = Horde::url('report.php')->add('gallery', $id)->link(array('class' => 'widget')); } if ($this->_view->gallery->hasPermission($registry->getAuth(), Horde_Perms::DELETE)) { $view->have_delete = true; $view->deleteall_url = $galleryurl->copy()->add('actionID', 'empty')->link(array('class' => 'widget')); $view->deletegallery_url = $galleryurl->copy()->add('actionID', 'delete')->link(array('class' => 'widget')); } }
public function html() { global $registry; $view = $GLOBALS['injector']->createInstance('Horde_View'); $view->addTemplatePath(ANSEL_TEMPLATES . '/widgets'); $view->owner = $this->_view->gallery->get('owner'); $view->userfeedurl = Ansel::getUrlFor('rss_user', array('owner' => $view->owner)); $view->slug = $this->_view->gallery->get('slug'); $view->galleryname = $this->_view->gallery->get('name'); $view->galleryfeedurl = Ansel::getUrlFor('rss_gallery', array('gallery' => $this->_view->gallery->id, 'slug' => $view->slug)); $view->title = _("Links"); /* Embed html */ if (empty($this->_view->_params['image_id'])) { /* Gallery view */ $params = array('count' => 10); if (!empty($slug)) { $params['gallery_slug'] = $slug; } else { $params['gallery_id'] = $this->_view->gallery->id; } } else { // This is an image view $params = array('thumbsize' => 'screen', 'images' => $this->_view->_params['image_id'], 'count' => 10); } $view->embed = Ansel::embedCode($params); return $view->render('links'); }
/** * Outputs the html for a DateGallery tile. * * @param Ansel_Gallery_Decorator_Date $dgallery The Ansel_Gallery_Date we are * displaying. * @param Ansel_Style $style A style object. * @param boolean $mini Force the use of a mini thumbail? * @param array $params An array containing additional parameters. * Currently, gallery_view_url and image_view_url * are used to override the respective urls. * %g and %i are replaced with image id and * gallery id, respectively. * * @return string The HTML for the tile. */ public function getTile(Ansel_Gallery_Decorator_Date $dgallery, Ansel_Style $style = null, $mini = false, array $params = array()) { $view = $GLOBALS['injector']->createInstance('Horde_View'); $view->addTemplatePath(ANSEL_TEMPLATES . '/tile'); // User's preferred date format $date_format = $GLOBALS['prefs']->getValue('date_format'); $date_array = $dgallery->getDate(); if (empty($date_array['month'])) { $date_array['month'] = 1; } if (empty($date_array['day'])) { $date_array['day'] = 1; } $full_date = new Horde_Date($date_array); // Need the unaltered date part array $date_array = $dgallery->getDate(); // Figure out the needed link for the next drill down level. We *must* // have at least a year since we are in a date tile. if (empty($date_array['month'])) { // unit == year $view->caption = $full_date->strftime('%Y'); $next_date = array('year' => (int) $view->caption); } elseif (empty($date_array['day'])) { // unit == month $view->caption = $full_date->strftime('%B %Y'); $next_date = array('year' => date('Y', $full_date->timestamp()), 'month' => date('n', $full_date->timestamp())); } else { // unit == day $view->caption = $full_date->strftime($date_format); $next_date = array('year' => date('Y', $full_date->timestamp()), 'month' => date('n', $full_date->timestamp()), 'day' => date('j', $full_date->timestamp())); } // Check permissions on the gallery and get appropriate tile image if ($dgallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) { if (is_null($style)) { $style = $dgallery->getStyle(); } $thumbstyle = $mini ? 'mini' : 'thumb'; $view->gallery_image = Ansel::getImageUrl($dgallery->getKeyImage(), $thumbstyle, true, $style); } else { $view->gallery_image = Horde_Themes::img('thumb-error.png'); } /* Check for being called via the api and generate correct view links */ if (!isset($params['gallery_view_url'])) { if (empty($params['style'])) { $gstyle = $dgallery->getStyle(); } else { $gstyle = $params['style']; } $params = array('gallery' => $dgallery->id, 'view' => 'Gallery', 'slug' => $dgallery->get('slug')); $view->view_link = Ansel::getUrlFor('view', array_merge($params, $next_date)); } else { $view->view_link = new Horde_Url(str_replace(array('%g', '%s'), array($dgallery->id, $dgallery->get('slug')), urldecode($params['gallery_view_url']))); $view->view_link->add($next_date); } $view->gallery_count = $dgallery->countImages(true); return $view->render('dategallery'); }
/** * Const'r * * @see Ansel_View_Base::__construct */ public function __construct(array $params = array()) { parent::__construct($params); if (!empty($params['gallery_slug'])) { $this->gallery = $this->_getGallery(null, $params['gallery_slug']); } elseif (!empty($params['gallery_id'])) { $this->gallery = $this->_getGallery($params['gallery_id']); } else { $this->gallery = $this->_getGallery(); } // Check user age if (!$this->gallery->isOldEnough()) { if (!empty($params['api'])) { throw new Ansel_Exception('Locked galleries are not viewable via the api.'); } $date = Ansel::getDateParameter(array('year' => isset($this->_params['year']) ? $this->_params['year'] : 0, 'month' => isset($this->_params['month']) ? $this->_params['month'] : 0, 'day' => isset($this->_params['day']) ? $this->_params['day'] : 0)); $galleryurl = Ansel::getUrlFor('view', array_merge(array('gallery' => $this->gallery->id, 'slug' => empty($params['slug']) ? '' : $params['slug'], 'page' => empty($params['page']) ? 0 : $params['page'], 'view' => 'Gallery'), $date), true); $params = array('gallery' => $this->gallery->id, 'url' => $galleryurl); Horde::url('disclamer.php')->add($params)->setRaw(true)->redirect(); exit; } if ($this->gallery->hasPasswd()) { if (!empty($params['api'])) { throw new Ansel_Exception(_("Locked galleries are not viewable via the api.")); } $date = Ansel::getDateParameter(array('year' => isset($this->_params['year']) ? $this->_params['year'] : 0, 'month' => isset($this->_params['month']) ? $this->_params['month'] : 0, 'day' => isset($this->_params['day']) ? $this->_params['day'] : 0)); $galleryurl = Ansel::getUrlFor('view', array_merge(array('gallery' => $this->gallery->id, 'slug' => empty($params['slug']) ? '' : $params['slug'], 'page' => empty($params['page']) ? 0 : $params['page'], 'view' => 'Gallery'), $date), true); $params = array('gallery' => $this->gallery->id, 'url' => $galleryurl); Horde::url('protect.php')->add($params)->setRaw(true)->redirect(); exit; } if (!$this->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) { throw new Horde_Exception_PermissionDenied(); } // Since this is a gallery view, the resource is the gallery. $this->resource = $this->gallery; // Do we have an explicit style set? If not, use the gallery's if (!empty($this->_params['style'])) { $style = Ansel::getStyleDefinition($this->_params['style']); } else { $style = $this->gallery->getStyle(); } if (!empty($this->_params['gallery_view'])) { $renderer = $this->_params['gallery_view']; } else { $renderer = !empty($style->gallery_view) ? $style->gallery_view : 'Gallery'; } // Load the helper $classname = 'Ansel_View_GalleryRenderer_' . basename($renderer); $this->_renderer = new $classname($this); $this->_renderer->init(); }
/** */ public function menu($menu) { global $conf, $registry; /* Browse/Search */ $menu->add(Horde::url('browse.php'), _("_Browse"), 'ansel-browse', null, null, null, $GLOBALS['prefs']->getValue('defaultview') == 'browse' && basename($_SERVER['PHP_SELF']) == 'index.php' || basename($_SERVER['PHP_SELF']) == 'browse.php' ? 'current' : '__noselection'); if ($GLOBALS['registry']->getAuth()) { $url = Ansel::getUrlFor('view', array('owner' => $GLOBALS['registry']->getAuth(), 'groupby' => 'owner', 'view' => 'List')); $menu->add($url, _("_My Galleries"), 'ansel-mygalleries', null, null, null, Horde_Util::getFormData('owner', false) == $GLOBALS['registry']->getAuth() ? 'current' : '__noselection'); } $menu->add(Ansel::getUrlFor('view', array('view' => 'List')), _("_All Galleries"), 'ansel-allgalleries', null, null, null, $GLOBALS['prefs']->getValue('defaultview') == 'galleries' && basename($_SERVER['PHP_SELF']) == 'index.php' || basename($_SERVER['PHP_SELF']) == 'group.php' && Horde_Util::getFormData('owner') !== $GLOBALS['registry']->getAuth() ? 'current' : '__noselection'); if ($conf['faces']['driver'] && $registry->isAuthenticated()) { $menu->add(Horde::url('faces/search/all.php'), _("_Faces"), 'ansel-faces'); } }
/** */ protected function _content() { /* Get the tags */ $tags = $GLOBALS['injector']->getInstance('Ansel_Tagger')->getCloud(null, $this->_params['count']); if (count($tags)) { $cloud = new Horde_Core_Ui_TagCloud(); foreach ($tags as $id => $tag) { $link = Ansel::getUrlFor('view', array('view' => 'Results', 'tag' => $tag['tag_name'])); $cloud->addElement($tag['tag_name'], $link, $tag['count']); } $html = $cloud->buildHTML(); } else { $html = ''; } return $html; }
/** */ protected function _content() { $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getRandomGallery(); if (!$gallery) { return _("There are no photo galleries available."); } $imagelist = $gallery->listImages(rand(0, $gallery->countImages() - 1), 1); if (empty($imagelist)) { return ''; } $imageId = $imagelist[0]; $viewurl = Ansel::getUrlFor('view', array('gallery' => $gallery->id, 'slug' => $gallery->get('slug'), 'image' => $imageId, 'view' => 'Image'), true); if ($gallery->isOldEnough() && !$gallery->hasPasswd()) { $img = '<img src="' . Ansel::getImageUrl($imageId, 'thumb', true, Ansel::getStyleDefinition('ansel_default')) . '" alt="[random photo]" />'; } else { $img = Horde::img('thumb-error.png'); } return $viewurl->link(array('title' => _("View Photo"))) . $img . '</a>'; }
/** * Contructor. * * Also handles any actions from the view. * * @return Ansel_View_Results */ public function __construct(array $params = array()) { global $prefs, $conf, $injector, $notification; $ansel_storage = $injector->getInstance('Ansel_Storage'); $this->_owner = Horde_Util::getFormData('owner', ''); $this->_browser = new Ansel_TagBrowser($injector->getInstance('Ansel_Tagger'), null, $this->_owner); $this->_page = Horde_Util::getFormData('page', 0); $actionID = Horde_Util::getFormData('actionID', ''); $image_id = Horde_Util::getFormData('image'); $vars = Horde_Variables::getDefaultVariables(); // Number perpage from prefs or config. $this->_perPage = min($prefs->getValue('tilesperpage'), $conf['thumbnail']['perpage']); // Common image actions. if (Ansel_ActionHandler::imageActions($actionID)) { Ansel::getUrlFor('view', array('view' => 'Results'), true)->redirect(); exit; } // Tag browsing actions. switch ($actionID) { case 'remove': $tag = Horde_Util::getFormData('tag'); if (isset($tag)) { $this->_browser->removeTag($tag); $this->_browser->save(); } break; case 'add': default: $tag = Horde_Util::getFormData('tag'); if (isset($tag)) { $this->_browser->addTag($tag); $this->_browser->save(); } break; } // Check for empty tag search and redirect if empty if ($this->_browser->tagCount() < 1) { Horde::url('browse.php', true)->redirect(); exit; } }
/** */ protected function _content() { try { $gallery = $this->_getGallery(); } catch (Ansel_Exception $e) { return $e->getMessage(); } $params = array('gallery_id' => $gallery->id, 'count' => $this->_params['perpage']); if (!empty($this->_params['use_lightbox'])) { $params['lightbox'] = true; } $html = Ansel::embedCode($params); // Be nice to people with <noscript> $viewurl = Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $gallery->id, 'slug' => $gallery->get('slug')), true); $html .= '<noscript>'; $html .= $viewurl->link(array('title' => sprintf(_("View %s"), $gallery->get('name')))); if ($iid = $gallery->getKeyImage(Ansel::getStyleDefinition('ansel_default')) && $gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) { $html .= '<img src="' . Ansel::getImageUrl($gallery->getKeyImage(Ansel::getStyleDefinition('ansel_default')), 'thumb', true) . '" alt="' . htmlspecialchars($gallery->get('name')) . '" />'; } else { $html .= Horde::img('thumb-error.png'); } return $html . '</a></noscript>'; }
/** * Helper function for generating a widget of images related to this one. * * * @return string The HTML */ public function _getRelatedImages() { $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage'); $html = ''; $args = array('typeId' => 'image', 'userId' => $this->_view->gallery->get('owner')); $results = $GLOBALS['injector']->getInstance('Ansel_Tagger')->listRelatedImages($this->_view->resource); if (count($results)) { $i = 0; foreach ($results as $result) { $img = $result['image']; try { $rGal = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($img->gallery); if ($rGal->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) { $html .= Ansel::getUrlFor('view', array('image' => $img->id, 'view' => 'Image', 'gallery' => abs($img->gallery), 'slug' => $rGal->get('slug')), true)->link(array('title' => sprintf(_("%s from %s"), $img->filename, $rGal->get('name')))) . '<img src="' . Ansel::getImageUrl($img->id, 'mini', true) . '" alt="' . htmlspecialchars($img->filename) . '" /></a>'; } } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); } $i++; } } return $html; }
/** */ protected function _content() { global $page_output, $registry, $injector, $prefs; Horde::initMap(); $page_output->addScriptFile('map.js'); $page_output->addScriptFile('blocks/geotag.js'); try { $images = $injector->getInstance('Ansel_Storage')->getRecentImagesGeodata(null, 0, min($this->_params['limit'], 100)); } catch (Ansel_Exception $e) { return $e->getMessage(); } $images = array_reverse($images); foreach ($images as $key => $image) { $id = $image['image_id']; $gallery = $injector->getInstance('Ansel_Storage')->getGallery($image['gallery_id']); // Don't show locked galleries in the block. if (!$gallery->isOldEnough() || $gallery->hasPasswd()) { continue; } $style = $gallery->getStyle(); // Generate the image view url $url = Ansel::getUrlFor('view', array('view' => 'Image', 'slug' => $gallery->get('slug'), 'gallery' => $gallery->id, 'image' => $id, 'gallery_view' => $style->gallery_view), true); $images[$key]['icon'] = strval(Ansel::getImageUrl($images[$key]['image_id'], 'mini', true)); $images[$key]['link'] = strval($url); $images[$key]['markerOnly'] = false; } // URL for updating selected layer $layerUrl = $registry->getServiceLink('ajax', 'ansel')->setRaw(true); $layerUrl->url .= 'setPrefValue'; // And the current defaultLayer, if any. $defaultLayer = $prefs->getValue('current_maplayer'); $opts = array('layerUpdateEndpoint' => strval($layerUrl), 'layerUpdatePref' => 'current_maplayer', 'defaultBaseLayer' => $defaultLayer); $json = Horde_Serialize::serialize(array_values($images), Horde_Serialize::JSON); $js = array('var opts = ' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON), 'new AnselBlockGeoTag(' . $json . ', opts);'); $page_output->addInlineScript($js, true); return '<div id="ansel_map" style="height:' . $this->_params['height'] . 'px;"></div>'; }
$gallery->setImageOrder($id, $pos); } $notification->push(_("Gallery sorted."), 'horde.success'); $style = $gallery->getStyle(); Ansel::getUrlFor('view', array_merge(array('view' => 'Gallery', 'gallery' => $galleryId, 'slug' => $gallery->get('slug')), $date), true)->redirect(); exit; case 'Reset': // Reset the sort order by date. $images = $injector->getInstance('Ansel_Storage')->listImages(array('gallery_id' => $galleryId, 'sort' => 'image_original_date')); $pos = 0; foreach ($images as $id) { $gallery->setImageOrder($id, $pos++); } $notification->push(_("Gallery sort reset."), 'horde.success'); $style = $gallery->getStyle(); Ansel::getUrlFor('view', array_merge(array('view' => 'Gallery', 'gallery' => $galleryId, 'slug' => $gallery->get('slug')), $date), true)->redirect(); exit; } $page_output->addInlineScript(array('jQuery("#sortContainer").sortable()', 'jQuery("#sortContainer").disableSelection()'), true); $title = sprintf(_("%s :: Sort"), $gallery->get('name')); $page_output->header(array('title' => _("Search Forums"))); $notification->notify(array('listeners' => 'status')); ?> <h1 class="header"><?php echo htmlspecialchars($title); ?> </h1> <div class="instructions"> <form action="<?php echo Horde::url('gallery/sort.php'); ?>
/** * JSON representation of this gallery's images. We don't use * Ansel_Gallery::toJson() on purpose since that is a general jsonification * of the gallery data. This method is specific to the view, paging, links * etc... * * @param Ansel_Gallery $gallery The gallery to represent in this view * @param array $params An array of parameters for this method: * <pre> * full - Should a full URL be generated? [false] * from - Starting image count [0] * count - The number of images to include (starting at from) [0] * image_view - The type of ImageGenerator to obtain the src url for. [screen] * view_links - Should the JSON include links to the Image and/or Gallery View? [false] * perpage - Number of images per page [from user prefs] * </pre> * * @return string A serialized JSON array. */ public static function json(Ansel_Gallery $gallery, $params = array()) { global $conf, $prefs; $default = array('full' => false, 'from' => 0, 'count' => 0, 'image_view' => 'screen', 'view_links' => false, 'perpage' => $prefs->getValue('tilesperpage', $conf['thumbnail']['perpage'])); $params = array_merge($default, $params); $json = array(); $curimage = 0; $curpage = 0; if (empty($params['images'])) { $images = $gallery->getImages($params['from'], $params['count']); } $style = $gallery->getStyle(); if ($params['image_view'] == 'thumb' && !empty($params['generator'])) { $style->thumbstyle = $params['generator']; } foreach ($images as $image) { // Calculate the page this image will appear on in the gallery view. if (++$curimage > $params['perpage']) { ++$curpage; $curimage = 0; } $data = array((string) Ansel::getImageUrl($image->id, $params['image_view'], $params['full'], $style), htmlspecialchars($image->filename), $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($image->caption, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO_LINKURL)), $image->id, $curpage); if ($params['view_links']) { $data[] = (string) Ansel::getUrlFor('view', array('gallery' => $gallery->id, 'slug' => $gallery->get('slug'), 'image' => $image->id, 'view' => 'Image', 'page' => $curpage), true); $data[] = (string) Ansel::getUrlFor('view', array('gallery' => $image->gallery, 'slug' => $gallery->get('slug'), 'view' => 'Gallery'), true); } // Source, Width, Height, Name, Caption, Image Id, Gallery Page $json[] = $data; } return Horde_Serialize::serialize($json, Horde_Serialize::JSON); }
try { $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id); } catch (Ansel_Exception $e) { $notification->push($e->getMessage(), 'horde.error'); Ansel::getUrlFor('view', array('gallery' => $gallery_id))->redirect(); exit; } if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied editing this gallery."), 'horde.error'); Ansel::getUrlFor('view', array('gallery' => $gallery_id))->redirect(); exit; } $gallery->setDate(Ansel::getDateParameter()); $page = Horde_Util::getFormData('page', 0); $perpage = min($prefs->getValue('tilesperpage'), $conf['thumbnail']['perpage']); $images = $gallery->getImages($page * $perpage, $perpage); $reloadimage = Horde::img('reload.png'); $customimage = Horde::img('layout.png'); $customurl = Horde::url('faces/custom.php')->add('page', $page); $face = $injector->getInstance('Ansel_Faces'); $autogenerate = $face->canAutogenerate(); $vars = Horde_Variables::getDefaultVariables(); $pager = new Horde_Core_Ui_Pager('page', $vars, array('num' => $gallery->countImages(), 'url' => 'faces/gallery.php', 'perpage' => $perpage)); $pager->preserve('gallery', $gallery_id); $title = sprintf(_("Searching for faces in %s"), Ansel::getUrlFor('view', array('gallery' => $gallery_id, 'view' => 'Gallery'))->link() . $gallery->get('name') . '</a>'); $page_output->addScriptFile('stripe.js', 'horde'); $page_output->addScriptFile('popup.js', 'horde'); $page_output->header(array('title' => $title)); $notification->notify(array('listeners' => 'status')); require ANSEL_TEMPLATES . '/faces/gallery.inc'; $page_output->footer();
/** * Handles saving the gallery information from the form submission, and * redirects back to previous view when complete. * * @return void */ private function _runSave() { // Check general permissions. if (!$GLOBALS['registry']->isAdmin() && ($GLOBALS['injector']->getInstance('Horde_Perms')->exists('ansel') && !$GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('ansel', $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT))) { $GLOBALS['notification']->push(_("Access denied editing galleries."), 'horde.error'); Horde::url('view.php?view=List', true)->redirect(); exit; } // Get the form values. $galleryId = Horde_Util::getFormData('gallery'); $gallery_name = Horde_Util::getFormData('gallery_name'); $gallery_desc = Horde_Util::getFormData('gallery_desc'); $gallery_slug = Horde_Util::getFormData('gallery_slug'); $gallery_age = (int) Horde_Util::getFormData('gallery_age', 0); $gallery_download = Horde_Util::getFormData('gallery_download'); $gallery_mode = Horde_Util::getFormData('view_mode', 'Normal'); $gallery_passwd = Horde_Util::getFormData('gallery_passwd'); $gallery_tags = Horde_Util::getFormData('gallery_tags'); $gallery_thumbstyle = Horde_Util::getFormData('gallery_style'); $gallery_parent = Horde_Util::getFormData('gallery_parent'); // Style $style = new Ansel_Style(array('thumbstyle' => Horde_Util::getFormData('thumbnail_style'), 'background' => Horde_Util::getFormData('background_color'), 'gallery_view' => Horde_Util::getFormData('gallery_view'), 'widgets' => array('Tags' => array('view' => 'gallery'), 'OtherGalleries' => array(), 'Geotag' => array(), 'Links' => array(), 'GalleryFaces' => array(), 'OwnerFaces' => array()))); // Double check for an empty string instead of null if (empty($gallery_parent)) { $gallery_parent = null; } if ($galleryId && ($exists = $GLOBALS['injector']->getInstance('Ansel_Storage')->galleryExists($galleryId) === true)) { // Modifying an existing gallery. $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($galleryId); if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) { $GLOBALS['notification']->push(_("Access denied saving this gallery."), 'horde.error'); } else { // Don't allow the display name to be nulled out. if ($gallery_name) { $gallery->set('name', $gallery_name); } $gallery->set('desc', $gallery_desc); $gallery->setTags(!empty($gallery_tags) ? explode(',', $gallery_tags) : array()); $gallery->set('style', $style); $gallery->set('slug', $gallery_slug); $gallery->set('age', $gallery_age); $gallery->set('download', $gallery_download); $gallery->set('view_mode', $gallery_mode); if ($GLOBALS['registry']->getAuth() && $gallery->get('owner') == $GLOBALS['registry']->getAuth()) { $gallery->set('passwd', $gallery_passwd); } // Did the parent change? $old_parent = $gallery->getParent(); if (!is_null($old_parent)) { $old_parent_id = $old_parent->id; } else { $old_parent_id = null; } if ($gallery_parent != $old_parent_id) { if (!is_null($gallery_parent)) { $new_parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_parent); } else { $new_parent = null; } try { $result = $gallery->setParent($new_parent); } catch (Ansel_Exception $e) { $GLOBALS['notification']->push($e->getMessage(), 'horde.error'); Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect(); exit; } } try { $result = $gallery->save(); $GLOBALS['notification']->push(_("The gallery was saved."), 'horde.success'); } catch (Ansel_Exception $e) { $GLOBALS['notification']->push($e->getMessage(), 'horde.error'); } } } else { // Is this a new subgallery? if ($gallery_parent) { try { $parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_parent); } catch (Ansel_Exception $e) { $GLOBALS['notification']->push($e->getMessage(), 'horde.error'); Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect(); exit; } if (!$parent->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) { $GLOBALS['notification']->push(_("You do not have permission to add sub galleries to this gallery."), 'horde.error'); Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect(); exit; } } // Require a display name. if (!$gallery_name) { $GLOBALS['notification']->push(_("You must provide a display name for your new gallery."), 'horde.warning'); $actionId = 'add'; $title = _("Adding A New Gallery"); } // Create the new gallery. $perm = !empty($parent) ? $parent->getPermission() : null; try { $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->createGallery(array('name' => $gallery_name, 'desc' => $gallery_desc, 'tags' => explode(',', $gallery_tags), 'style' => $style, 'slug' => $gallery_slug, 'age' => $gallery_age, 'download' => $gallery_download, 'view_mode' => $gallery_mode, 'passwd' => $gallery_passwd), $perm, $gallery_parent); $galleryId = $gallery->id; $msg = sprintf(_("The gallery \"%s\" was created successfully."), $gallery_name); $GLOBALS['notification']->push($msg, 'horde.success'); Horde::url('img/upload.php')->add('gallery', $galleryId)->redirect(); } catch (Ansel_Exception $e) { $galleryId = null; $error = sprintf(_("The gallery \"%s\" couldn't be created: %s"), $gallery_name, $e->getMessage()); Horde::log($error, 'ERR'); $GLOBALS['notification']->push($error, 'horde.error'); Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect(); exit; } } // Make sure that the style hash is recorded, ignoring non-styled thumbs if ($style->thumbstyle != 'Thumb') { $GLOBALS['injector']->getInstance('Ansel_Storage')->ensureHash($gallery->getStyle()->getHash('thumb')); } // Clear the OtherGalleries widget cache if ($GLOBALS['conf']['ansel_cache']['usecache']) { $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner')); } // Return to the last view. $url = Horde_Util::getFormData('url'); if (empty($url) && empty($exists)) { // Redirect to the images upload page for newly creted galleries $url = Horde::url('img/upload.php')->add('gallery', $galleryId); } elseif (empty($url)) { $url = Horde::url('index.php', true); } else { $url = new Horde_Url($url); } $url->redirect(); }
default: Ansel::getUrlFor('view', array('view' => 'List', 'groupby' => $groupby), true)->redirect(); exit; } // Set up pager. $vars = Horde_Variables::getDefaultVariables(); $group_pager = new Horde_Core_Ui_Pager('gbpage', $vars, array('num' => $num_groups, 'url' => 'group.php', 'perpage' => $groups_perpage)); $min = $gbpage * $groups_perpage; $max = $min + $groups_perpage; if ($max > $num_groups) { $max = $num_groups - $min; } $start = $min + 1; $end = min($num_groups, $min + $groups_perpage); $count = 0; $groupby_links = array(); if ($groupby !== 'owner') { $groupby_links[] = Ansel::getUrlFor('group', array('actionID' => 'groupby', 'groupby' => 'owner'))->link() . _("owner") . '</a>'; } if ($groupby !== 'none') { $groupby_links[] = Ansel::getUrlFor('group', array('actionID' => 'groupby', 'groupby' => 'none'))->link() . _("none") . '</a>'; } $page_output->header(); $notification->notify(array('listeners' => 'status')); require ANSEL_TEMPLATES . '/group/header.inc'; foreach ($groups as $group) { require ANSEL_TEMPLATES . '/group/' . $groupby . '.inc'; } require ANSEL_TEMPLATES . '/group/footer.inc'; require ANSEL_TEMPLATES . '/group/pager.inc'; $page_output->footer();
$urlparams = array('page' => $page); if (!empty($url)) { $urlparams['url'] = $url; } $form_post = Horde::url('faces/savecustom.php')->add($urlparams); try { $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id); } catch (Ansel_Exception $e) { $notification->push($image); Horde::url('list.php')->redirect(); exit; } $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery); if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied editing the photo.")); Ansel::getUrlFor('view', array('gallery' => $image->gallery))->redirect(); exit; } $x1 = 0; $y1 = 0; $x2 = $conf['screen']['width']; $y2 = $conf['screen']['width']; $name = Horde_Util::getFormData('name'); if ($face_id) { $faces = $injector->getInstance('Ansel_Faces'); try { $face = $faces->getFaceById($face_id, true); $x1 = $face['face_x1']; $y1 = $face['face_y1']; $x2 = $face['face_x2']; $y2 = $face['face_y2'];
<?php /** * Copyright 2001-2014 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.horde.org/licenses/gpl. * * @author Chuck Hagenbuch <*****@*****.**> */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('ansel'); /* Load mobile? */ if (in_array($registry->getView(), array(Horde_Registry::VIEW_MINIMAL, Horde_Registry::VIEW_SMARTMOBILE))) { include ANSEL_BASE . '/smartmobile.php'; exit; } Ansel::getUrlFor('default_view', array())->redirect();
/** * Retrieve json data for an arbitrary list of image ids, not necessarily * from the same gallery. * * @param array $images An array of image ids * @param Ansel_Style $style A gallery style to force if requesting * pretty thumbs. * @param boolean $full Generate full urls * @param string $image_view Which image view to use? screen, thumb etc.. * @param boolean $view_links Include links to the image view * * @return string The json data */ public function getImageJson(array $images, Ansel_Style $style = null, $full = false, $image_view = 'mini', $view_links = false) { $galleries = array(); if (is_null($style)) { $style = Ansel::getStyleDefinition('ansel_default'); } $json = array(); foreach ($images as $id) { $image = $this->getImage($id); $gallery_id = abs($image->gallery); if (empty($galleries[$gallery_id])) { $galleries[$gallery_id]['gallery'] = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id); } // Any authentication that needs to take place for any of the // images included here MUST have already taken place or the // image will not be incldued in the output. if (!isset($galleries[$gallery_id]['perm'])) { $galleries[$gallery_id]['perm'] = $galleries[$gallery_id]['gallery']->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ) && $galleries[$gallery_id]['gallery']->isOldEnough() && !$galleries[$gallery_id]['gallery']->hasPasswd(); } if ($galleries[$gallery_id]['perm']) { $data = array((string) Ansel::getImageUrl($image->id, $image_view, $full, $style), htmlspecialchars($image->filename), $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($image->caption, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO_LINKURL)), $image->id, 0); if ($view_links) { $data[] = (string) Ansel::getUrlFor('view', array('gallery' => $image->gallery, 'image' => $image->id, 'view' => 'Image', 'slug' => $galleries[$gallery_id]['gallery']->get('slug')), $full); $data[] = (string) Ansel::getUrlFor('view', array('gallery' => $image->gallery, 'slug' => $galleries[$gallery_id]['gallery']->get('slug'), 'view' => 'Gallery'), $full); } $json[] = $data; } } return Horde_Serialize::serialize($json, Horde_Serialize::JSON); }
public static function galleryActions($actionID) { global $registry, $notification, $page_output; if (self::download($actionID)) { return true; } $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage'); switch ($actionID) { case 'add': case 'addchild': case 'save': case 'modify': $view = new Ansel_View_GalleryProperties(array('actionID' => $actionID, 'url' => new Horde_Url(Horde_Util::getFormData('url')), 'gallery' => Horde_Util::getFormData('gallery'))); $view->run(); exit; case 'downloadzip': $galleryId = Horde_Util::getFormData('gallery'); try { $gallery = $ansel_storage->getGallery($galleryId); if (!$registry->getAuth() || !$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) { $notification->push(_("Access denied downloading photos from this gallery."), 'horde.error'); Horde::url('view.php?view=List', true)->redirect(); exit; } Ansel::downloadImagesAsZip($gallery); } catch (Ansel_Exception $e) { $notification->push($gallery->getMessage(), 'horde.error'); Horde::url('view.php?view=List', true)->redirect(); exit; } exit; case 'delete': case 'empty': // Print the confirmation screen. $galleryId = Horde_Util::getFormData('gallery'); if ($galleryId) { try { $gallery = $ansel_storage->getGallery($galleryId); $page_output->header(); $notification->notify(array('listeners' => 'status')); require ANSEL_TEMPLATES . '/gallery/delete_confirmation.inc'; $page_output->footer(); exit; } catch (Ansel_Exception $e) { $notification->push($gallery->getMessage(), 'horde.error'); } } // Return to the gallery list. Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect(); exit; case 'do_delete': case 'do_empty': $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage'); $galleryId = Horde_Util::getPost('gallery'); try { $gallery = $ansel_storage->getGallery($galleryId); } catch (Ansel_Exception $e) { $notification->push($e->getMessage(), 'horde.error'); Ansel::getUrlFor('default_view', array())->redirect(); exit; } switch ($actionID) { case 'do_delete': if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::DELETE)) { $notification->push(_("Access denied deleting this gallery."), 'horde.error'); } else { try { $ansel_storage->removeGallery($gallery); $notification->push(sprintf(_("Successfully deleted %s."), $gallery->get('name')), 'horde.success'); } catch (Ansel_Exception $e) { $notification->push(sprintf(_("There was a problem deleting %s: %s"), $gallery->get('name'), $e->getMessage()), 'horde.error'); } catch (Horde_Exception_NotFound $e) { Horde::log($e, 'err'); } } // Return to the default view. Ansel::getUrlFor('default_view', array())->redirect(); exit; case 'do_empty': if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::DELETE)) { $notification->push(_("Access denied deleting this gallery."), 'horde.error'); } else { $ansel_storage->emptyGallery($gallery); $notification->push(sprintf(_("Successfully emptied \"%s\""), $gallery->get('name')), 'horde.success'); } Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $galleryId, 'slug' => $gallery->get('slug')), true)->redirect(); exit; default: Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $galleryId, 'slug' => $gallery->get('slug')), true)->redirect(); exit; } case 'generateDefault': // Re-generate the default pretty gallery image. $galleryId = Horde_Util::getFormData('gallery'); try { $gallery = $ansel_storage->getGallery($galleryId); $gallery->clearStacks(); $notification->push(_("The gallery's default photo has successfully been reset."), 'horde.success'); Horde::url('view.php', true)->add('gallery', $galleryId)->redirect(); exit; } catch (Ansel_Exception $e) { $notification->push($e->getMessage(), 'horde.error'); Horde::url('index.php', true)->redirect(); exit; } case 'generateThumbs': // Re-generate all of this gallery's prettythumbs. $galleryId = Horde_Util::getFormData('gallery'); try { $gallery = $ansel_storage->getGallery($galleryId); } catch (Ansel_Exception $e) { $notification->push($gallery->getMessage(), 'horde.error'); Horde::url('index.php', true)->redirect(); exit; } $gallery->clearThumbs(); $notification->push(_("The gallery's thumbnails have successfully been reset."), 'horde.success'); Horde::url('view.php', true)->add('gallery', $galleryId)->redirect(); exit; case 'deleteCache': // Delete all cached image views. $galleryId = Horde_Util::getFormData('gallery'); try { $gallery = $ansel_storage->getGallery($galleryId); } catch (Ansel_Exception $e) { $notification->push($gallery->getMessage(), 'horde.error'); Horde::url('index.php', true)->redirect(); exit; } $gallery->clearViews(); $notification->push(_("The gallery's views have successfully been reset."), 'horde.success'); Horde::url('view.php', true)->add('gallery', $galleryId)->redirect(); exit; } return false; }
/** * Outputs the HTML for an image thumbnail tile. * * @param Ansel_Image $image The Ansel_Image we are displaying. * @param Ansel_Style $style A sytle definiition array. * @param boolean $mini Force the use of a mini thumbnail? * @param array $params Any other paramaters needed by this tile * * @return Outputs the HTML for the image tile. */ public static function getTile(Ansel_Image $image, Ansel_Style $style = null, $mini = false, array $params = array()) { global $conf, $registry, $injector; $page = isset($params['page']) ? $params['page'] : 0; $view_type = isset($params['view']) ? $params['view'] : 'Gallery'; $view = $injector->createInstance('Horde_View'); $view->addTemplatePath(ANSEL_TEMPLATES . '/tile'); $view->image = $image; $view->view_type = $view_type; try { $view->parent = $injector->getInstance('Ansel_Storage')->getGallery($image->gallery); } catch (Ansel_Exception $e) { // @TODO: Short circuit here and return a generic error tile. } catch (Horde_Exception_NotFound $e) { // @TODO: Ditto above. } if (is_null($style)) { $style = $view->parent->getStyle(); } $date = $view->parent->getDate(); if ($view_type == 'Results') { $haveSearch = 1; } else { $haveSearch = 0; } // Override the thumbnail to mini or use style default? $thumbstyle = $mini ? 'mini' : 'thumb'; // URL for image properties/actions $view->image_url = Horde::url('image.php')->add(array_merge(array('gallery' => $image->gallery, 'page' => $page, 'image' => $image->id, 'havesearch' => $haveSearch), $date)); // URL to view the image. This is the link for the Tile. // $view_url is the link for the thumbnail and since this might not // always point to the image view page, we set $img_view_url to link to // the image view $view->img_view_url = Ansel::getUrlFor('view', array_merge(array('gallery' => $image->gallery, 'slug' => $view->parent->get('slug'), 'page' => $page, 'view' => 'Image', 'image' => $image->id, 'havesearch' => $haveSearch), $date)); if (!empty($params['image_view_src'])) { $view->view_url = Ansel::getImageUrl($image->id, 'screen', true); } elseif (empty($params['image_view_url'])) { $view->view_url = new Horde_Url($view->img_view_url); } else { $view->view_url = new Horde_Url(str_replace(array('%i', '%g', '%s'), array($image->id, $image->gallery, $view->parent->get('slug')), urldecode($params['image_view_url']))); // If we override the view_url, assume we want to override this also $view->img_view_url = $view->view_url; } // Need the gallery URL to display the "From" link when showing // the image tile from somewhere other than the gallery view. if (!empty($view_type) || basename($_SERVER['PHP_SELF']) == 'view.php') { $view->gallery_url = Ansel::getUrlFor('view', array_merge(array('gallery' => $view->parent->id, 'slug' => $view->parent->get('slug'), 'view' => 'Gallery', 'havesearch' => $haveSearch), $date)); } $view->thumb_url = Ansel::getImageUrl($image->id, $thumbstyle, true, $style); $view->option_select = $view->parent->hasPermission($registry->getAuth(), Horde_Perms::DELETE); $view->option_edit = $view->parent->hasPermission($registry->getAuth(), Horde_Perms::EDIT); $view->imgAttributes = !empty($params['image_view_attributes']) ? $params['image_view_attributes'] : array(); $view->option_comments = ($conf['comments']['allow'] == 'all' || $conf['comments']['allow'] == 'authenticated' && $registry->getAuth()) && empty($params['hide_comments']); $view->imgOnClick = !empty($params['image_onclick']) ? str_replace('%i', $image->id, $params['image_onclick']) : ''; $view->imageCaption = $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($image->caption, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO)); if (!empty($params['image_view_title']) && !empty($image->_data[$params['image_view_title']])) { $title = $image->_data[$params['image_view_title']]; } else { $title = $image->filename; } // In-line caption editing if we have Horde_Perms::EDIT if ($view->option_edit) { try { $geometry = $image->getDimensions($thumbstyle); $injector->createInstance('Horde_Core_Factory_Imple')->create('Ansel_Ajax_Imple_EditCaption', array('dataid' => $image->id, 'id' => $image->id . 'caption', 'width' => $geometry['width'])); } catch (Ansel_Exception $e) { } } return $view->render('image'); }
require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('ansel'); $title = _("Do you really want to report this gallery?"); $gallery_id = (int) Horde_Util::getFormData('gallery'); try { $gallery = $injector->getInstance('Ansel_Storage')->getGallery($gallery_id); } catch (Ansel_Exception $e) { $notification->push($e->getMessage()); Horde::url('view.php?view=List', true)->redirect(); exit; } if (($image_id = Horde_Util::getFormData('image')) !== null) { $title = _("Do you really want to report this photo?"); $return_url = Ansel::getUrlFor('view', array('view' => 'Image', 'image' => $image_id, 'gallery' => $gallery_id), true); } else { $return_url = Ansel::getUrlFor('view', array('gallery' => $gallery_id, 'view' => 'Gallery'), true); } $vars = Horde_Variables::getDefaultVariables(); $form = new Horde_Form($vars, $title); $form->setButtons(array(array('class' => 'horde-default', 'value' => _("Report")), array('class' => 'horde-cancel', 'value' => _("Cancel")))); $enum = array('advertisement' => _("Advertisement content"), 'terms' => _("Terms and conditions infringement"), 'offensive' => _("Offensive content"), 'copyright' => _("Copyright infringement")); $form->addVariable($gallery->get('name'), 'name', 'description', false); $form->addVariable($gallery->get('desc'), 'desc', 'description', false); $form->addHidden('', 'gallery', 'text', true, true); $vars->set('gallery', $gallery_id); $form->addVariable(_("Report type"), 'type', 'radio', true, false, null, array($enum)); $form->addVariable(_("Report reason"), 'reason', 'longtext', true); $gallery_id = Horde_Util::getFormData('id'); if ($vars->get('submitbutton') == _("Cancel")) { Horde::url('', true)->redirect(); }
* did not receive this file, see http://www.horde.org/licenses/gpl. * * @author Chuck Hagenbuch <*****@*****.**> */ require_once __DIR__ . '/../lib/Application.php'; Horde_Registry::appInit('ansel'); $gallery_id = Horde_Util::getFormData('gallery'); try { $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id); } catch (Ansel_Exception $e) { $notification->push(sprintf(_("Gallery %s not found."), $gallery_id), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("You are not authorized to upload photos to this gallery."), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); } $page = Horde_Util::getFormData('page', 0); $return_url = Ansel::getUrlFor('view', array('gallery' => $gallery_id, 'slug' => $gallery->get('slug'), 'view' => 'Gallery', 'page' => $page), true); $view = new Ansel_View_Upload(array('forceNoScript' => $prefs->getValue('force_old_uploader', false), 'browse_button' => 'pickfiles', 'target' => Horde::selfUrl()->setRaw(true), 'drop_target' => 'filelist', 'upload_button' => 'uploadfiles', 'gallery' => $gallery, 'return_target' => $return_url->toString(true, true))); if (!$prefs->getValue('force_old_uploader', 'false')) { $view->run(); $nojs = ''; } else { $nojs = $view->handleLegacy(); } $page_output->header(array('title' => _("Add Photo"))); echo '<div class="header" id="galleryHeader"><span class="breadcrumbs">' . Ansel::getBreadCrumbs($gallery) . '</span></div>'; require ANSEL_TEMPLATES . '/image/plupload.inc'; $page_output->footer();
/** * Return the HTML representing this view. * * @return string The HTML. * */ public function html() { global $conf, $prefs, $registry; $vars = Horde_Variables::getDefaultVariables(); if (!empty($this->_params['page'])) { $vars->add('page', $this->_params['page']); } if (!empty($this->_params['pager_url'])) { $this->_pagerurl = $this->_params['pager_url']; $override = true; } else { $override = false; $this->_pagerurl = Ansel::getUrlFor('view', array('owner' => $this->_owner, 'special' => $this->_special, 'groupby' => $this->_view->groupby, 'view' => 'List')); } $p_params = array('num' => $this->_view->numGalleries, 'url' => $this->_pagerurl, 'perpage' => $this->_view->gPerPage); if ($override) { $p_params['url_callback'] = null; } $this->_pager = new Horde_Core_Ui_Pager('page', $vars, $p_params); $preserve = array('sort_dir' => $this->_view->sortDir); if (!empty($this->_view->sortBy)) { $preserve['sort'] = $this->_view->sortBy; } $this->_pager->preserve($preserve); if ($this->_view->numGalleries) { $min = $this->_page * $this->_view->gPerPage; $max = $min + $this->_view->gPerPage; if ($max > $this->_view->numGalleries) { $max = $this->_view->numGalleries - $min; } $this->_view->start = $min + 1; $this->_view->end = min($this->_view->numGalleries, $min + $this->_view->gPerPage); if ($this->_owner) { $this->_view->refresh_link = Ansel::getUrlFor('view', array('groupby' => $this->_view->groupby, 'owner' => $this->_owner, 'page' => $this->_page, 'view' => 'List')); } else { $this->_view->refresh_link = Ansel::getUrlFor('view', array('view' => 'List', 'groupby' => $this->_view->groupby, 'page' => $this->_page)); } // Get top-level / default gallery style. if (empty($this->_params['style'])) { $style = Ansel::getStyleDefinition($prefs->getValue('default_gallerystyle')); } else { $style = Ansel::getStyleDefinition($this->_params['style']); } // Final touches. if (empty($this->_params['api'])) { $this->_view->breadcrumbs = Ansel::getBreadcrumbs(); $this->_view->groupbyUrl = strval(Ansel::getUrlFor('group', array('actionID' => 'groupby', 'groupby' => 'owner'))); } $this->_view->pager = $this->_pager->render(); $this->_view->style = $style; $this->_view->tilesperrow = $prefs->getValue('tilesperrow'); $this->_view->cellwidth = round(100 / $this->_view->tilesperrow); $this->_view->params = $this->_params; $GLOBALS['page_output']->addScriptFile('views/common.js'); return $this->_view->render('list'); } return ' '; }
/** * Handle uploads from non-js browsers */ public function handleLegacy() { global $conf, $notification, $page_output, $browser; $vars = Horde_Variables::getDefaultVariables(); $form = new Ansel_Form_Upload($vars, _("Upload photos")); // Output the carousel JS in case we are here because the user // explicitly selected the old uploader. $js = $this->_doCarouselSetup(); if (!empty($js)) { $page_output->addInlineScript($js, true); } if ($form->validate($vars)) { $valid = true; $uploaded = 0; $form->getInfo($vars, $info); // Remember the ids of the images we uploaded so we can autogen $image_ids = array(); for ($i = 0; $i <= $conf['image']['num_uploads'] + 1; ++$i) { if (empty($info['file' . $i]['file'])) { continue; } try { $GLOBALS['browser']->wasFileUploaded('file' . $i); } catch (Horde_Browser_Exception $e) { if (!empty($info['file' . $i]['error'])) { $notification->push(sprintf(_("There was a problem uploading the photo: %s"), $info['file' . $i]['error']), 'horde.error'); } elseif (!filesize($info['file' . $i]['file'])) { $notification->push(_("The uploaded file appears to be empty. It may not exist on your computer."), 'horde.error'); } $valid = false; continue; } // Check for a compressed file. if (in_array($info['file' . $i]['type'], array('x-extension/zip', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip')) || Horde_Mime_Magic::filenameToMime($info['file' . $i]['name']) == 'application/zip') { $this->_handleZip($info['file' . $i]['name']); } else { // Read in the uploaded data. $data = file_get_contents($info['file' . $i]['file']); // Try and make sure the image is in a recognizeable // format. if (getimagesize($info['file' . $i]['file']) === false) { $notification->push(_("The file you uploaded does not appear to be a valid photo."), 'horde.error'); continue; } // Add the image to the gallery $image_data = array('image_filename' => $info['file' . $i]['name'], 'image_caption' => $vars->get('image' . $i . '_desc'), 'image_type' => $info['file' . $i]['type'], 'data' => $data, 'tags' => isset($info['image' . $i . '_tags']) ? explode(',', $info['image' . $i . '_tags']) : array()); try { $image_ids[] = $this->_gallery->addImage($image_data, (bool) $vars->get('image' . $i . '_default')); ++$uploaded; } catch (Ansel_Exception $e) { $notification->push(sprintf(_("There was a problem saving the photo: %s"), $e->getMessage()), 'horde.error'); $valid = false; } } } // Try to autogenerate some views and tell the user what happened. if ($uploaded) { $qtask = new Ansel_Queue_ProcessThumbs($image_ids); $queue = $GLOBALS['injector']->getInstance('Horde_Queue_Storage'); $queue->add($qtask); // postupload hook if needed try { Horde::callHook('postupload', array($image_ids), 'ansel'); } catch (Horde_Exception_HookNotSet $e) { } $notification->push(sprintf(ngettext("%d photo was uploaded.", "%d photos were uploaded.", $uploaded), $uploaded), 'horde.success'); } elseif ($vars->get('submitbutton') != _("Cancel")) { $notification->push(_("You did not select any photos to upload."), 'horde.error'); } if ($valid) { // Return to the gallery view. Ansel::getUrlFor('view', array('gallery' => $this->_gallery->id, 'slug' => $this->_gallery->get('slug'), 'view' => 'Gallery', 'page' => $page), true)->redirect(); exit; } } Horde::startBuffer(); include ANSEL_TEMPLATES . '/image/upload.inc'; return ($this->_forceNoScript ? '' : '<noscript>') . Horde::endBuffer() . ($this->_forceNoScript ? '' : '</noscript>'); }
<?php /** * Copyright 2001-2014 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.horde.org/licenses/gpl. * * @author Chuck Hagenbuch <*****@*****.**> * @author Michael J. Rubinsky <*****@*****.**> * @package Ansel */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('ansel'); // Redirect to the gallery list if no action has been requested. $actionID = Horde_Util::getFormData('actionID'); if (is_null($actionID)) { Horde::url('view.php?view=List', true)->redirect(); exit; } if (!Ansel_ActionHandler::galleryActions($actionID)) { Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect(); exit; }
/** * Image view specific HTML - done so we can extend View_Image for things * like the slideshow view etc... */ protected function _html() { global $conf, $registry, $prefs, $page_output; // Build initial view properties $view = $this->_getView(); $view->hide_slideshow = !empty($this->_params['hide_slideshow']); // Starting image $imageIndex = $this->_revList[$this->resource->id]; // Get the next and previous image ids if (isset($this->_imageList[$imageIndex + 1])) { $next = $this->_imageList[$imageIndex + 1]; } else { $next = $this->_imageList[0]; } if (isset($this->_imageList[$imageIndex - 1])) { $prev = $this->_imageList[$imageIndex - 1]; } else { $prev = $this->_imageList[count($this->_imageList) - 1]; } // Calculate the page number of the next/prev images $perpage = $prefs->getValue('tilesperpage'); $pagestart = $this->_page * $perpage; $pageend = min(count($this->_imageList), $pagestart + $perpage - 1); $page_next = $this->_page; if ($this->_revList[$this->resource->id] + 1 > $pageend) { ++$page_next; } $page_prev = $this->_page; if ($this->_revList[$this->resource->id] - 1 < $pagestart) { --$page_prev; } // Previous image link if (!empty($this->_params['image_view_url'])) { $view->prev_url = str_replace(array('%i', '%g', '%s'), array($prev, $this->gallery->id, $this->_slug), urldecode($this->_params['image_view_url'])); } else { $view->prev_url = Ansel::getUrlFor('view', array_merge(array('gallery' => $this->gallery->id, 'slug' => $this->_slug, 'image' => $prev, 'view' => 'Image', 'page' => $page_prev), $this->_date)); } $prevImgSrc = Ansel::getImageUrl($prev, 'screen', true, $this->_style); // Next image link if (!empty($this->_params['image_view_url'])) { $view->next_url = str_replace(array('%i', '%g', '%s'), array($prev, $this->gallery->id, $this->_slug), urldecode($this->_params['image_view_url'])); } else { $view->next_url = Ansel::getUrlFor('view', array_merge(array('gallery' => $this->gallery->id, 'slug' => $this->_slug, 'image' => $next, 'view' => 'Image', 'page' => $page_next), $this->_date)); } $nextImgSrc = Ansel::getImageUrl($next, 'screen', true, $this->_style); // Slideshow link if (!empty($this->_params['slideshow_link'])) { $this->_urls['slideshow'] = str_replace(array('%i', '%g'), array($this->resource->id, $this->gallery->id), urldecode($this->_params['slideshow_link'])); } else { $this->_urls['slideshow'] = Horde::url('view.php')->add(array_merge(array('gallery' => $this->gallery->id, 'image' => $this->resource->id, 'view' => 'Slideshow'), $this->_date)); } // These items don't work when viewing through the api if (empty($this->_params['api'])) { $this->addWidget(Ansel_Widget::factory('Tags', array('view' => 'image'))); $this->addWidget(Ansel_Widget::factory('SimilarPhotos')); $this->addWidget(Ansel_Widget::factory('Geotag', array('images' => array($this->resource->id)))); if ($conf['faces']['driver']) { $this->addWidget(Ansel_Widget::factory('ImageFaces', array('selfUrl' => $this->_urls['self']))); } $this->addWidget(Ansel_Widget::factory('Links', array())); // In line caption editing if ($this->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) { $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('Ansel_Ajax_Imple_EditCaption', array('width' => $this->_geometry['width'], 'id' => 'anselcaption', 'dataid' => $this->resource->id)); } } // Output the js if we are calling via the api if (!empty($this->_params['api'])) { foreach (array('prototype.js', 'stripe.js', 'scriptaculous/effects.js') as $val) { $tmp = new Horde_Script_File_JsDir($val, 'horde'); Horde::startBuffer(); echo $tmp->tag_full; $html = Horde::endBuffer(); } } else { $html = ''; } $js = array(); if (empty($this->_params['hide_slideshow'])) { $js[] = '$$(\'.ssPlay\').each(function(n) { n.show(); });'; } $js = array_merge($js, array('AnselImageView.nextImgSrc = "' . $nextImgSrc . '"', 'AnselImageView.prevImgSrc = "' . $prevImgSrc . '"', 'AnselImageView.urls = { "imgsrc": "' . $this->_urls['imgsrc'] . '" }', 'AnselImageView.onload()')); $page_output->addInlineScript($js); // Pass the urls now that we have them all. $view->urls = $this->_urls; // Get the exif data if needed. if ($prefs->getValue('showexif')) { $view->exif = array_chunk($this->resource->getAttributes(), 3, true); } // Comments if ($comments = $this->_getCommentData()) { if (!empty($comments['threads'])) { $this->view->commentHtml = '<br>' . $comments['threads']; } if (!empty($comments['comments'])) { $this->view->commentHtml .= '<br>' . $comments['comments']; } } return $html . $view->render('image'); }