get() публичный Метод

Get a gallery property
public get ( string $property ) : mixed
$property string The property to return.
Результат mixed The value.
Пример #1
0
 /**
  * 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);
 }
Пример #2
0
 /**
  * Empties a gallery of all images.
  *
  * @param Ansel_Gallery $gallery  The ansel gallery to empty.
  *
  * @throws Ansel_Exception
  */
 public function emptyGallery(Ansel_Gallery $gallery)
 {
     $gallery->clearStacks();
     $images = $gallery->listImages();
     foreach ($images as $image) {
         // Pretend we are a stack so we don't update the images count
         // for every image deletion, since we know the end result will
         // be zero.
         try {
             $gallery->removeImage($image, true);
         } catch (Horde_Exception_NotFound $e) {
             // Don't worry about missing images since we are deleting them
             // anyway.
             Horde::log($e->getMessage(), 'ERR');
         }
     }
     $gallery->set('images', 0, true);
     // Clear the OtherGalleries widget cache
     if ($GLOBALS['conf']['ansel_cache']['usecache']) {
         $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
         $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
     }
 }
Пример #3
0
 /**
  * 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>');
 }
Пример #4
0
 /**
  * Copy image and related data to specified gallery.
  *
  * @param array $images           An array of image ids.
  * @param Ansel_Gallery $gallery  The gallery to copy images to.
  *
  * @return integer The number of images copied
  * @throws Ansel_Exception
  */
 public function copyImagesTo(array $images, Ansel_Gallery $gallery)
 {
     if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
         throw new Horde_Exception_PermissionDenied(_("Access denied copying photos to this gallery."));
     }
     $imgCnt = 0;
     foreach ($images as $imageId) {
         $img = $this->getImage($imageId);
         // Note that we don't pass the tags when adding the image..see below
         $newId = $gallery->addImage(array('image_caption' => $img->caption, 'data' => $img->raw(), 'image_filename' => $img->filename, 'image_type' => $img->getType(), 'image_uploaded_date' => $img->uploaded));
         /* Copy any tags */
         $tags = $img->getTags();
         $GLOBALS['injector']->getInstance('Ansel_Tagger')->tag($newId, $tags, $gallery->get('owner'), 'image');
         // Check that new image_id doesn't have existing attributes,
         // throw exception if it does.
         $newAttributes = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImageAttributes($newId);
         if (count($newAttributes)) {
             throw new Ansel_Exception(_("Image already has existing attributes."));
         }
         $exif = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImageAttributes($imageId);
         if (is_array($exif) && count($exif) > 0) {
             foreach ($exif as $name => $value) {
                 $GLOBALS['injector']->getInstance('Ansel_Storage')->saveImageAttribute($newId, $name, $value);
             }
         }
         ++$imgCnt;
     }
     return $imgCnt;
 }
Пример #5
0
 /**
  * Outputs the html for a gallery tile.
  *
  * @param Ansel_Gallery $gallery  The Ansel_Gallery 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  Outputs the HTML for the tile.
  */
 public static function getTile(Ansel_Gallery $gallery, Ansel_Style $style = null, $mini = false, array $params = array())
 {
     global $prefs, $registry, $injector;
     // Create view
     $view = $injector->createInstance('Horde_View');
     $view->addTemplatePath(ANSEL_TEMPLATES . '/tile');
     $view->gallery = $gallery;
     $view_type = Horde_Util::getFormData('view', 'Gallery');
     $haveSearch = $view_type == 'Results' ? 1 : 0;
     if ($view_type == 'Results' || $view_type == 'List' || basename($_SERVER['PHP_SELF']) == 'index.php' && $prefs->getValue('defaultview') == 'galleries') {
         $showOwner = true;
     } else {
         $showOwner = false;
     }
     // Use the galleries style if not explicitly passed.
     if (is_null($style)) {
         $style = $gallery->getStyle();
     }
     // If the gallery has subgalleries, and no images, use one of the
     // subgalleries' stack image. hasSubGalleries already takes
     // permissions into account.
     if ($gallery->hasPermission($registry->getAuth(), Horde_Perms::READ) && !$gallery->countImages() && $gallery->hasSubGalleries()) {
         try {
             $galleries = $injector->getInstance('Ansel_Storage')->listGalleries(array('parent' => $gallery->id, 'all_levels' => false, 'perm' => Horde_Perms::READ));
             foreach ($galleries as $sgallery) {
                 if ($default_img = $sgallery->getKeyImage($style)) {
                     $view->gallery_image = Ansel::getImageUrl($default_img, $mini ? 'mini' : 'thumb', true, $style);
                 }
             }
         } catch (Ansel_Exception $e) {
         }
     } elseif ($gallery->hasPermission($registry->getAuth(), Horde_Perms::READ) && $gallery->countImages()) {
         $thumbstyle = $mini ? 'mini' : 'thumb';
         if ($gallery->hasPasswd()) {
             $view->gallery_image = Horde_Themes::img('gallery-locked.png');
         } else {
             $view->gallery_image = Ansel::getImageUrl($gallery->getKeyImage($style), $thumbstyle, true, $style);
         }
     }
     // If no image at this point, we can't get one.
     if (empty($view->gallery_image)) {
         $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'])) {
         $view->view_link = Ansel::getUrlFor('view', array('gallery' => $gallery->id, 'view' => 'Gallery', 'havesearch' => $haveSearch, 'slug' => $gallery->get('slug')));
     } else {
         $view->view_link = new Horde_Url(str_replace(array('%g', '%s'), array($gallery->id, $gallery->get('slug')), urldecode($params['gallery_view_url'])));
     }
     if ($gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT) && !$mini) {
         $view->properties_link = Horde::url('gallery.php', true)->add(array('gallery' => $gallery->id, 'actionID' => 'modify', 'havesearch' => $haveSearch, 'url' => Horde::selfUrl(true, false, true)));
     }
     if ($showOwner && !$mini && $registry->getAuth() != $gallery->get('owner')) {
         $view->owner_link = Ansel::getUrlFor('view', array('view' => 'List', 'owner' => $gallery->get('owner'), 'groupby' => 'owner'), true);
         $view->owner_string = $gallery->getIdentity()->getValue('fullname');
         if (empty($view->owner_string)) {
             $view->owner_string = $gallery->get('owner');
         }
     }
     $view->background_color = $style->background;
     $view->gallery_count = $gallery->countImages(true);
     $view->date_format = $prefs->getValue('date_format');
     return $view->render('gallery' . ($mini ? 'mini' : ''));
 }