/** * Get HTML for an image block * * @param array $params ('blocks' => string, 'show' => string, (optional)'heading' => int, * (optional)'itemId' => int, (optional)'maxSize' => int, (optional)'exactSize' => int, * (optional)'itemFrame' => frameId, (optional)'albumFrame' => frameId) * 'blocks' is a pipe (|) separated list, of one or more possible blocks which are: * randomImage|recentImage|viewedImage|randomAlbum|recentAlbum|viewedAlbum|specificItem * dailyImage|weeklyImage|monthlyImage|dailyAlbum|weeklyAlbum|monthlyAlbum * 'show' is a pipe (|) separated list of one or more possible choices which are: * title|date|views|owner|heading|fullSize or just 'none' * If you choose 'blocks' => 'specificItem', you must specify 'itemId' too. * example: GalleryEmbed::getImageBlock(array('blocks' => 'randomImage', * 'show' => 'title|date')); * itemFrame/albumFrame may require CSS to be displayed. * See Image Block Site Admin page for info on optional parameters. * @return array object GalleryStatus * string html content * string head content or null if none required */ function g2_getLightImageBlock($params,$size=null,$cssclass=null) { // Get WPG2 Option Settings $wpg2_option = get_option('wpg2_options'); // Initialize Gallery if (!defined('G2INIT')) { $ret = g2_login(); if ($ret) { echo '

' . __('Fatal G2 error', 'wpg2') . '

' . __("Here's the error from G2: ", 'wpg2') . $ret->getAsHtml(); exit; } } global $gallery; $moduleId = 'imageblock'; $blockHtml = $headHtml = null; $session =& $gallery->getSession(); $ret = $session->start(); if ($ret) { return array($ret, null, null, null); } $session->doNotUseTempId(); /* Load the module list */ list ($ret, $moduleStatus) = GalleryCoreApi::fetchPluginStatus('module'); if ($ret) { return array($ret, null, null, null); } if (isset($moduleStatus[$moduleId]) && !empty($moduleStatus[$moduleId]['active']) && $moduleStatus[$moduleId]['active']) { /* Load the G2 templating engine */ GalleryCoreApi::requireOnce('modules/core/classes/GalleryTemplate.class'); $template = new GalleryTemplate(dirname(__FILE__)); $template->setVariable('l10Domain', 'modules_' . $moduleId); if (!isset($params['maxSize'])) { $params['maxSize'] = null; } /* Generate the imageblock */ GalleryCoreApi::requireOnce( 'modules/imageblock/classes/ImageBlockHelper.class'); $ret = ImageBlockHelper::loadImageBlocks($template, $params); if ($ret) { return array($ret, null, null, null); } if ($template->hasVariable('ImageBlockData')) { $ImageBlockData =& $template->getVariableByReference('ImageBlockData'); $ImageBlockData['forceFullUrl'] = 1; $ImageBlockData['divClass'] = $cssclass; $g2_isalbum = NULL; if ($size) { foreach ($ImageBlockData['blocks'] as $blockid => $className) { if (!$ImageBlockData['blocks'][$blockid]['item']['canContainChildren']) { $g2_isalbum = NULL; $g2_link = NULL; list ($ret, $ImageBlockData['blocks'][$blockid]['lightboxid'], $isViewable) = g2_lightboxgetItemUrls($ImageBlockData['blocks'][$blockid]['id'],$size); if ($ret) { return array($ret, null, null, null); } else { if ($isViewable === FALSE) $g2_isalbum = true; } } else $g2_isalbum = true; } } $tpl = 'templates/wpg2imageblock.tpl'; /* Render and get the imageblock html */ list ($ret, $blockHtml) = $template->fetch("gallery:$tpl"); if ($ret) { return array($ret, null, null, null); } } } else { return array(GalleryCoreApi::error(ERROR_CONFIGURATION_REQUIRED), null, null, null); } return array(null, $blockHtml, $headHtml, $g2_isalbum); } /** * Get the thumbnail URL and the URL of the image version that is the closest to the requested size. * * @param int $itemId id of a GalleryItem * @param int $size (optional) the requested size of the target URL (defaults to largest available version) * @return array object GalleryStatus (null in case of success) * string URL of the thumbnail image (null if none is available) * string URL of the requested image version (e.g. the largest version) or null if none is available */ function g2_lightboxgetItemUrls($itemId, $size=null) { if (!defined('G2INIT')) { $ret = g2_login(); if ($ret) { echo '

' . __('Fatal G2 error', 'wpg2') . '

' . __("Here's the error from G2: ", 'wpg2') . $ret->getAsHtml(); exit; } } global $gallery; $urlGenerator =& $gallery->getUrlGenerator(); $thumbUrl = $targetUrl = null; list ($ret, $permissions) = GalleryCoreApi::getPermissions($itemId); if ($ret) { return array($ret, null, null); } if (!isset($permissions['core.view'])) { return array (null, null, null); // no access } list ($ret, $thumbnail) = GalleryCoreApi::fetchThumbnailsByItemIds(array($itemId)); if ($ret) { return $ret; } $targetCandidates = array(); if (!empty($thumbnail[$itemId])) { $thumb = $thumbnail[$itemId]; $thumbUrl = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $thumb->getId(), 'serialNumber' => $thumb->getSerialNumber()), array('forceFullUrl' => true)); $targetCandidates[] = $thumb; } if (isset($permissions['core.viewResizes'])) { list ($ret, $resizes) = GalleryCoreApi::fetchResizesByItemIds(array($itemId)); if ($ret) { return array($ret, null, null); } if (!empty($resizes[$itemId])) { foreach ($resizes[$itemId] as $resize) { $targetCandidates[] = $resize; } } } if (isset($permissions['core.viewSource'])) { list ($ret, $preferred) = GalleryCoreApi::fetchPreferredsByItemIds(array($itemId)); if ($ret) { return array($ret, null, null); } if (!empty($preferred[$itemId])) { $preferred = $preferred[$itemId]; $targetCandidates[] = $preferred; $isViewable = $preferred->getMimeType(); } else { list ($ret, $item) = GalleryCoreApi::loadEntitiesById($itemId); if ($ret) { return array($ret, null, null); } else { $targetCandidates[] = $item; $isViewable = $item->getMimeType(); } } } $isViewable = strpos($isViewable, 'image'); if ($isViewable !== FALSE) { if ($size == null) { /* Pick the largest version */ $size = 99999; } /* Search the closest match in size */ $targetid = $itemId; $targetdiff = 99999; foreach ($targetCandidates as $candidate) { $diff = $candidate->getHeight() - $size; if ($diff >= 0 && $diff < $targetdiff ) { $targetid = $candidate->getId(); $targetdiff = $diff; } } } return array(null, $targetid, $isViewable); }