GalleryLinkItem
* @g2 GalleryItem
* @g2
* @g2 1
* @g2 1
* @g2
* @g2
*
* @package LinkItem
* @subpackage Classes
* @author Alan Harder
* @version $Revision: 15534 $
*/
class GalleryLinkItem extends GalleryItem {
/**
* The id of the linked album or text of external link.
*
* @g2
* @g2 link
* @g2 TEXT
* @g2 SMALL
* @g2
* @g2 READ
* @g2
*
* @var string $link
* @access public
*/
var $link;
/**
* Create a new instance of this GalleryEntity in the persistent store.
* Let the parent do its work, then add any initialization specific to this class.
*
* @param int $parentId the id of the parent object
* @param mixed $link the link target: either string url or int id of a GalleryAlbumItem
* @return object GalleryStatus a status code
*/
function create($parentId, $link) {
if (!isset($parentId) || empty($link)) {
return GalleryCoreApi::error(ERROR_BAD_PARAMETER);
}
if (is_numeric($link)) {
/* Link to an album */
list ($ret, $linkedAlbum) = GalleryCoreApi::loadEntitiesById($link);
if ($ret) {
return $ret;
}
if (!GalleryUtilities::isA($linkedAlbum, 'GalleryAlbumItem')) {
return GalleryCoreApi::error(ERROR_BAD_PARAMETER);
}
}
$ret = parent::create($parentId, 'linkitem' . rand(1000, 9999));
if ($ret) {
return $ret;
}
$this->setLink($link);
if (isset($linkedAlbum)) {
$this->setTitle($linkedAlbum->getTitle());
$this->setSummary($linkedAlbum->getSummary());
$this->setDescription($linkedAlbum->getDescription());
$this->setKeywords($linkedAlbum->getKeywords());
} else {
$this->setTitle(basename($link));
}
return null;
}
/**
* @see GalleryFileSystemEntity::move
*/
function move($newParentId) {
/*
* We don't really have anything in the filesystem to move.
* Pretend to be a linked entity during the move to avoid platform rename.
*/
$this->setLinkedEntity('fake');
$ret = parent::move($newParentId);
$this->setLinkedEntity(null);
if ($ret) {
return $ret;
}
return null;
}
/**
* @see GalleryEntity::itemTypeName
*/
function itemTypeName($localized = true) {
if ($localized) {
list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'linkitem');
if (!$ret) {
return array($module->translate('Link'), $module->translate('link'));
}
}
return array('Link', 'link');
}
/**
* @see GalleryEntity::onLoad
*/
function onLoad() {
$ret = parent::onLoad();
if ($ret) {
return $ret;
}
/* Redirect if trying to show this item */
list ($view, $itemId) = GalleryUtilities::getRequestVariables('view', 'itemId');
if ($view == 'core.ShowItem' && $itemId == $this->getId()) {
global $gallery;
$link = $this->getLink();
if (is_numeric($link)) {
$session =& $gallery->getSession();
$ret = $session->start();
if ($ret) {
return $ret;
}
$session->doNotUseTempId();
$urlGenerator =& $gallery->getUrlGenerator();
$link = $urlGenerator->generateUrl(array('view' => 'core.ShowItem',
'itemId' => $link),
array('forceFullUrl' => true));
}
$phpVm = $gallery->getPhpVm();
$phpVm->header('Location: ' . str_replace('&', '&', $link));
$phpVm->exit_();
}
return null;
}
/* Add functions to make this entity thumbnail-able */
function fetchPath() {
return array(null, $this->getLink());
}
function getMimeType() {
return 'gallery/linkitem';
}
function getWidth() {
return 0;
}
function getHeight() {
return 0;
}
/**
* @see GalleryEntity::getClassName
*/
function getClassName() {
return 'GalleryLinkItem';
}
function getLink() {
return $this->link;
}
function setLink($link) {
$this->link = $link;
}
}
?>