tag
$matches = null;
preg_match('/]*/u', $previewHtml, $matches);
$previewHtml = $matches [0];
if ($previewHtml [strlen($previewHtml) - 1] === '/') {
$previewHtml = substr($previewHtml, 0, strlen($previewHtml) - 1);
}
// add some additional attributes to the tag and close it properly
$previewHtml .= ' itemprop="thumbnail" title="' . $titleForAttributes . '">';
// PhotoSwipe needs to know the dimensions of the image - so we read them
$imgsize = getimagesize($imgPathRel);
// now lets assemble the whole HTML code - including the overlay HTML, if not inserted into the DOM before
$imgHtml = self::getPhotoSwipeOverlay() . //
'
';
self::$lastusedDataIndex++;
return $imgHtml;
}
/**
* Callback function called for [gallery] tags which returns the HTML code for a PhotoSwipe gallery.
*
* @param string $action
* @param array $attr
* the attributes given in the tag
* @param string $content
* @param array $params
* @param string $node_object
* @return boolean|string the HTML code for a PhotoSwipe gallery
*/
static function getGalleryHtml($action, $attr, $content, $params, $node_object) {
global $lang;
if ($action == 'validate') {
// not used for now
return true;
}
// gallery dir is set as tag attribute
$dir = $attr ['default'];
// sanitize first
if (strpos($dir, '..') !== false) {
return $lang ['plugin'] ['photoswipe'] ['label_gallerydoesntexist'];
}
// check if dir exists
if (!file_exists("fp-content/" . $dir)) {
return $lang ['plugin'] ['photoswipe'] ['label_gallerydoesntexist'] . ' ' . $dir;
}
// force slash at the end
if (substr($dir, -1) != '/') {
$dir .= '/';
}
// read images from gallery directory
$imagefiles = gallery_read_images($dir);
// read image caption from captions file (if existant in the gallery directory)
$captions = gallery_read_captions($dir);
// call getImageHtml() to get the image's HTML code for each image in the gallery dir
$imgattr = $attr;
$str = '
';
foreach ($imagefiles as $f) {
// set the image's caption as title attribut of the img tag
$imgattr ['default'] = $dir . $f;
$imgattr ['title'] = array_key_exists($f, $captions) ? $captions [$f] : '';
$str .= self::getImageHtml($action, $imgattr, $content, $params, $node_object);
}
return $str . '
';
}
/**
* Returns the overlay HTML.
* This needs to be inserted into the DOM only once, so a second call will return an empty string.
*
* @return string the PhotoSwipe overlay HTML
*/
static function getPhotoSwipeOverlay() {
global $lang;
$photoswipeoverlay = self::$photoswipeUiIsInitialized ? '' : '
' . //
'' . //
'
' . //
'
' . //
'' . //
'' . //
'
' . //
'
' . //
'
' . //
'
' . //
'
' . //
'' . //
'' . //
'' . //
'' . //
'' . //
'
' . //
'
' . //
'
' . //
'' . //
'
' . //
'
' . //
'
' . //
'
' . //
'
' . //
'' . //
'
' . //
'' . //
'' . //
'
' . //
'' . //
'
' . //
'
' . //
'
' . //
'
';
self::$photoswipeUiIsInitialized = true;
return $photoswipeoverlay;
}
/**
* Header hook for loading the PhotoSwipe scripts.
* Echoes the
';
}
echo '
';
}
/**
* Initializes the BBCode tags of the plugin.
*/
public static function initializePluginTags() {
// At first: check if BBCode plugin is active
if (!function_exists('plugin_bbcode_init')) {
// if not, there's no use in adding any bbcode tags :)
return;
}
// get the global bbcode object
$bbcode = plugin_bbcode_init();
// gallery tags
$supportedGalleryTags = array(
'gallery', // default tag
'photoswipegallery' // legacy tag - maintaining compatibility with plugin versions <= 1.1
);
foreach ($supportedGalleryTags as $tag) {
// add gallery tag
$bbcode->addCode($tag, // tag name: this will go between square brackets
'callback_replace_single', // type of action: we'll use a callback function
'PhotoSwipeFunctions::getGalleryHtml', // name of the callback function
array(
'usecontent_param' => array(
'default'
)
), // supported parameters: "default" is [acronym=valore]
'inline', // type of the tag, inline or block, etc
array(
'listitem',
'block',
'inline',
'link'
), // type of elements in which you can use this tag
array()); // type of elements where this tag CAN'T go (in this case, none, so it can go everywhere)
$bbcode->setCodeFlag($tag, 'closetag', BBCODE_CLOSETAG_FORBIDDEN); // a closing tag is forbidden (no [/tag])
}
// single image tags
$supportedImageTags = array(
'img', // default tag
'photoswipeimage' // legacy tag - maintaining compatibility with plugin versions <= 1.1
);
foreach ($supportedImageTags as $tag) {
// at first: remove tag to make sure it will be overridden
$bbcode->removeCode($tag);
// add image tag
$bbcode->addCode($tag, // tag name: this will go between square brackets
'callback_replace_single', // type of action: we'll use a callback function
'PhotoSwipeFunctions::getImageHtml', // name of the callback function
array(
'usecontent_param' => array(
'default'
)
), // supported parameters: "default" is [acronym=valore]
'inline', // type of the tag, inline or block, etc
array(
'listitem',
'block',
'inline',
'link'
), // type of elements in which you can use this tag
array()); // type of elements where this tag CAN'T go (in this case, none, so it can go everywhere)
$bbcode->setCodeFlag($tag, 'closetag', BBCODE_CLOSETAG_FORBIDDEN); // a closing tag is forbidden (no [/tag])
}
}
}