/** * 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'); }
/** * Initialize the renderer. This *must* be called before any attempt is made * to display or otherwise interact with the renderer. * */ public function init() { global $prefs, $conf, $registry, $page_output; $this->galleryId = $this->view->gallery->id; $this->gallerySlug = $this->view->gallery->get('slug'); $this->page = $this->view->page; // Number perpage from prefs or config if ($this->view->tilesperpage) { $this->perpage = $this->view->tilesperpage; } else { $this->perpage = min($prefs->getValue('tilesperpage'), $conf['thumbnail']['perpage']); } $this->pagestart = $this->page * $this->perpage + 1; // Fetch the children $this->fetchChildren($this->view->force_grouping); // Do we have an explicit style set from the API? // If not, use the gallery's if (!empty($this->view->style)) { $this->style = Ansel::getStyleDefinition($this->view->style); } else { $this->style = $this->view->gallery->getStyle(); } // Include any widgets if (!empty($this->style->widgets) && !$this->view->api) { // Special case widgets - these are built in if (array_key_exists('Actions', $this->style->widgets)) { // Don't show action widget if no actions if ($registry->getAuth() || !empty($conf['report_content']['driver']) && ($conf['report_content']['allow'] == 'authenticated' && $registry->isAuthenticated() || $conf['report_content']['allow'] == 'all')) { $this->view->addWidget(Ansel_Widget::factory('Actions')); } unset($this->style->widgets['Actions']); } // Gallery widgets always receive an array of image ids for // the current page. $ids = $this->getChildImageIds(); foreach ($this->style->widgets as $wname => $wparams) { $wparams = array_merge($wparams, array('images' => $ids)); $this->view->addWidget(Ansel_Widget::factory($wname, $wparams)); } } if (empty($this->view->api)) { $page_output->addScriptFile('views/common.js'); $page_output->addScriptFile('views/gallery.js'); $page_output->addScriptFile('popup.js', 'horde'); $strings = array('delete_conf' => _("Are you sure you want to delete the selected photos?"), 'choose_gallery_move' => _("You must choose a gallery to move photos to."), 'choose_images' => _("You must first choose photos.")); $urls = array('image_date' => strval(Horde::url('edit_dates.php')->add(array('gallery' => $this->galleryId)))); $js = array('Ansel = window.Ansel || {};', 'Ansel.galleryview_strings = ' . Horde_Serialize::serialize($strings, Horde_Serialize::JSON), 'Ansel.galleryview_urls = ' . Horde_Serialize::serialize($urls, Horde_Serialize::JSON), 'Ansel.has_edit = ' . $this->view->gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT) ? 1 : 0, 'Ansel.has_delete = ' . $this->view->gallery->hasPermission($registry->getAuth(), Horde_Perms::DELETE) ? 1 : 0); $page_output->addInlineScript($js, true); } // Perform any initialization of the subclasses. $this->_init(); }