Esempio n. 1
0
/**
 * Get info about an item from Gallery2
 *
 * @param int $item_id The Gallery2 ID of the item
 * @return array $item_info The array of information about the item
 */
function g2ic_get_item_info($item_id)
{
    global $gallery;
    $urlGenerator =& $gallery->getUrlGenerator();
    list($error, $items) = GalleryCoreApi::loadEntitiesById(array($item_id));
    if (!$error) {
        foreach ($items as $item) {
            $item_info['id'] = $item_id;
            $item_info['title'] = $item->getTitle();
            $item_info['description'] = $item->getDescription();
            $item_info['summary'] = $item->getSummary();
            $item_info['fullsize_img'] = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $item->getid()), array('forceFullUrl' => true));
            list($error, $thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds(array($item->getid()));
            if (!$error) {
                foreach ($thumbnails as $thumbnail) {
                    $item_info['thumbnail_src'] = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $thumbnail->getid()), array('forceFullUrl' => true));
                    $item_info['image_url'] = $urlGenerator->generateUrl(array('view' => 'core.ShowItem', 'itemId' => $item->getid()), array('forceFullUrl' => true));
                    $item_info['thumbnail_width'] = $thumbnail->getWidth();
                    $item_info['thumbnail_height'] = $thumbnail->getHeight();
                }
            } else {
                print T_('Error loading thumbnails');
            }
        }
    } else {
        print T_('Error loading album items');
    }
    if (empty($item_info['summary'])) {
        $item_info['summary'] = $item_info['title'];
    }
    if (empty($item_info['description'])) {
        $item_info['description'] = $item_info['summary'];
    }
    return $item_info;
}
Esempio n. 2
0
 /**
  * Set the highlight properly for a single album
  */
 static function set_album_highlight(&$queue)
 {
     // Dequeue the current album and enqueue its children
     list($g2_album_id, $children) = each($queue);
     unset($queue[$g2_album_id]);
     foreach ($children as $key => $value) {
         $queue[$key] = $value;
     }
     $g3_album_id = self::map($g2_album_id);
     if (!$g3_album_id) {
         return t("Album with id: %id not imported", array("id" => $g3_album_id));
     }
     $table = g2(GalleryCoreApi::fetchThumbnailsByItemIds(array($g2_album_id)));
     if (isset($table[$g2_album_id])) {
         // Backtrack the source id to an item
         $g2_source = $table[$g2_album_id];
         while (GalleryUtilities::isA($g2_source, "GalleryDerivative")) {
             $g2_source = g2(GalleryCoreApi::loadEntitiesById($g2_source->getDerivativeSourceId()));
         }
         $item_id = self::map($g2_source->getId());
         if ($item_id) {
             $item = ORM::factory("item", $item_id);
             $g2_album = ORM::factory("item", $g3_album_id);
             $g2_album->album_cover_item_id = $item->id;
             $g2_album->thumb_dirty = 1;
             $g2_album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
             $g2_album->save();
             graphics::generate($g2_album);
         }
     }
 }
Esempio n. 3
0
 /**
  * Set the highlight properly for a single album
  */
 static function set_album_highlight(&$queue)
 {
     // Dequeue the current album and enqueue its children
     list($g2_album_id, $children) = each($queue);
     unset($queue[$g2_album_id]);
     if (!empty($children)) {
         foreach ($children as $key => $value) {
             $queue[$key] = $value;
         }
     }
     $messages = array();
     $g3_album_id = self::map($g2_album_id);
     if (!$g3_album_id) {
         return t("Album with id: %id not imported", array("id" => $g3_album_id));
     }
     $table = g2(GalleryCoreApi::fetchThumbnailsByItemIds(array($g2_album_id)));
     if (isset($table[$g2_album_id])) {
         // Backtrack the source id to an item
         $orig_g2_source = $g2_source = $table[$g2_album_id];
         while (GalleryUtilities::isA($g2_source, "GalleryDerivative")) {
             $g2_source = g2(GalleryCoreApi::loadEntitiesById($g2_source->getDerivativeSourceId()));
         }
         $item_id = self::map($g2_source->getId());
         if ($item_id) {
             $item = ORM::factory("item", $item_id);
             $g3_album = ORM::factory("item", $g3_album_id);
             $g3_album->album_cover_item_id = $item->id;
             $g3_album->thumb_dirty = 1;
             try {
                 $g3_album->view_count = (int) g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
             } catch (Exception $e) {
                 $g3_album->view_count = 0;
             }
             try {
                 $g3_album->save();
                 graphics::generate($g3_album);
             } catch (Exception $e) {
                 return (string) new G2_Import_Exception(t("Failed to generate an album highlight for album '%name'.", array("name" => $g3_album->name)), $e);
             }
             self::set_map($orig_g2_source->getId(), $g3_album->id, "thumbnail", self::g2_url(array("view" => "core.DownloadItem", "itemId" => $orig_g2_source->getId())));
         }
     }
 }