* This script makes
*
* - every image a link to a popup window with upload opporunity
* - scales the view of every picture wider than $ImgPopUpMaxImgWidth (default 200 pixel)
*
*
* @author Patrick R. Michaud
* @author Sebastian Siedentopf
* @autor Laurent Meister
* @version 1.2.10
* @link http://www.pmwiki.org/wiki/Cookbook/ImgPopUp http://www.pmwiki.org/wiki/Cookbook/ImgPopUp
* @copyright by the authors 2005 – 2012
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @package imgpopup
*/
/* **************************************************************************
File: imgpopup.php
For the Admins
==============
Requirements
------------
* Last testet on PmWiki 2b55
Install
-------
1. put this script into your cookbook folder
2. include it into your config.php:
include_once("$FarmD/cookbook/imgpopup.php");
3. optionaly set the variable $ImgPopUpMaxImgWidth (in pixel) before the include. For example use
$ImgPopUpMaxImgWidth = 150;
to scale all images to 150px width
4. If you want to use a small magnifier glas before link text put an magnifier.png into /pub/cookbook/imgpopup
Customization
-------------
### Variables
* [optional] $ImgPopUpMaxImgWidth = ;
** default = 200
** sets the max. image width before scaling to 200 pixel
* [optional] $ImgPopUpSkinDirUrl = "";
** default = "cookbook/imgpopup"
** sets the directory for the magnifier image to "/pub/cookbook/imgpopup"
* [optional] $ImgPopUpProvideUploadLink =
** default = true
** sets if a upload link should be provided in the popup
* [optional] $ImgPopUpNoZoomLink =
** default = false
** sets if a Zoom Image link is shown under the image
* [optional] $ImgPopUpIgnoreUnscaledImages =
** default = false
** sets if unscaled images also open in a popup
* [optional] $ImgPopUpSameWindow =
** default = false
** sets if the image is shown in a new (popup) or in the same window
* [optional] $ImgPopUpShowZoomLinkTreshold = float
** default = 1.0
** sets an treshold for showing the zoom link. Set it to 1.1 means a image will get a zoom link if it is $ImgPopUpMaxImgWidth * 1.1 pixels wide. This prevents images with only a few pixels wider than $ImgPopUpMaxImgWidth to get displayed as zoomable
* [optional] $ImgPopUpRemoveChrome =
** default = false
** removes PmWiki chrome (header, footer, sidebar …)
### XLPage Strings
'Zoom Image' => '',
'Upload this image again' => '',
'Close window' => '',
'Go back' => '',
### Misc
If you do not like the link text under the image you can set display:none; in .imgpopuptext{}.
For the Users
=============
Just use the plain Attach:image.ext syntax.
### Markup
* (:ImgPopUpNoZoomLink:)
** images on this page don't get a zoom link ($ImgPopUpNoZoomLink = true;)
* (:ImgPopUpDisabled:)
** disables ImgPopUp for this wiki page ($ImgPopUpEnabled = false;)
For Developers
==============
Version History
---------------
* 1.2.10 - 2012-05-26 - Schlaefer
* Remove PmWiki chrome optional with flag $ImgPopUpRemoveChrome
*1.2.9
** [bugfix] solved problem regarding the reupload of pictures.
* 1.2.8
** [bugfix] deleted unnessesary
* 1.2.7 - 2005-10-02 - Schlaefer
** [bugfix] GET divider is & not ?
* 1.2.6 - 2005-09-05 - Schlaefer
** [feature] (:ImgPopUpDisabled:) disables ImgPopUp for a side
** [bugfix] "Go back" string in popup if $ImgPopUpSameWindow = 1; (contributed by noskule)
* 1.2.5 - 2005-09-03 - Schlaefer
** [feature] $ImgPopUpShowZoomLinkTreshold
** [bugfix] simple tables no longer corrupted
* 1.2.4 - 2005-09-02 - Schlaefer
** [bugfix] "Close window" link didn't respect $ImgPopUpSameWindow (reported by noskule)
* 1.2.3 - 2005-09-01 - Schlaefer
** [bugfix] caption pipe for non scaled images was shown (reported by noskule)
** [feature] new parameters $ImgPopUpIgnoreUnscaledImages, $ImgPopUpSameWindow (suggested by noskule)
* 1.2.2 - 2005-09-01 - Schlaefer
** [bugfix] respecting "|" as image capture mark (reported by noskule)
** [feature] (:ImgPopUpNoZoomLink:) and $ImgPopUpNoZoomLink introduced (suggested by noskule)
* 1.2.1 - - Schlaefer
** [feature] link with magnifier under the scaled down image
** [feature] make upload link in popup window opitonal
** [code] phpdoc commenting
* 1.2 - 2005-08-25 - Schlaefer
** [bugfix] better support for $UploadPrefixFmt = /$FullName
** [feature] click on zoomed image closes window if javascript enabled
* 1.1 - 2005-08-24 - Schlaefer
** [bugfix] not uploaded files gives no error anymore
** [bugfix] simple support for attachments from other groups
* 1.0 - 2005-08-24 - Schlaefer
** initial release
****************************************************************************/
if (!defined('PmWiki'))
exit ();
/**
* cookbook imgpopup is included
* and running on this pmwiki installation
*/
define('imgpopup', 1);
if ($action != 'imgpopup')
Markup('imgpopup', '(\\L))([^\\s$UrlExcludeChars]+$ImgExtPattern)(\"([^\"]*)\")?(\\s*\\|(?=[^|]))?)/e", "ImgPopUpFct('$0','$3')");
Markup('imgpopupparam', '";
if ($ImgPopUpNoZoomLink)
$showzoomlink = "display:none";
if (!$ImgPopUpSameWindow)
$openpopupin = "target='_blank'";
if (!file_exists($filepath))
return $wholestring;
$size = getimagesize($filepath);
$width = $size[0];
$height = $size[1];
if ($width > $ImgPopUpMaxImgWidth && $ImgPopUpEnabled) {
$wholestring = chop(str_replace("|","",$wholestring));
$out = Keep(FmtPageName("");
if ($width > $ImgPopUpShowZoomLinkTreshold * $ImgPopUpMaxImgWidth) {
$out .= Keep(FmtPageName("
",$pagename));
}
} elseif(!$ImgPopUpIgnoreUnscaledImages && $ImgPopUpEnabled) {
$wholestring = chop(str_replace("|","",$wholestring));
$out = Keep(FmtPageName("",$pagename)).$wholestring.Keep("");
} else {
$out = $wholestring;
}
return $out;
}
/**
* Generates of the pop up window.
*
* @param string $pagename
*/
function HandleImgPopUp($pagename) {
global $PageStartFmt, $PageEndFmt, $PageUrl,
$ImgPopUpProvideUploadLink,$ImgPopUpSameWindow, $ImgPopUpRemoveChrome;
$imagename = $_REQUEST['image'];
$names = imgpopuph1fct($imagename, $pagename);
if ($ImgPopUpSameWindow){
$jsgoto = "javascript:history.go(-1);";
$textgoto = "$[Go back]";
}
else {
$jsgoto = "javascript:window.close();";
$textgoto = "$[Close window]";
}
if ( $ImgPopUpRemoveChrome ) :
$text[] = "(:noheader:)(:nofooter:)(:notitle:)(:noleft:)";
endif;
$text[] = "(:div style='text-align:center;':)";
$text[] = "'''[=".$names['image']."=]''' \n ";
$text[] = Keep("")."\n";
if ($ImgPopUpProvideUploadLink)
$text[] = "[[".FmtPageName("\$PageUrl?action=upload&upname=".$names['image'], $names['page'])." | $[Upload this image again]]] \n";
$text[] = Keep("").
FmtPageName("[-$textgoto-]",$pagename);
Keep("");
$text[] = "(:divend:)";
$text = implode("\n", $text);
$PagePopUpImg = MarkupToHTML($names['page'], $text);
SDV($HandleImgPopUpFmt, array (& $PageStartFmt, & $PagePopUpImg, & $PageEndFmt));
PrintFmt($pagename, $HandleImgPopUpFmt);
}
/**
* Helps to find the image filepath depending on Attach syntax and $UploadPrefixFmt
*
* @param string $imagename the image name only "$UploadPrefixFmt/image.ext" string
* @param string $pagename
* @return array array with 'image' as the new $imagename and 'page' as the new $pagename
* @since v1.2, 2005-08-25
*/
function imgpopuph1fct($imagename, $pagename) {
global $UploadPrefixFmt;
$pgn = explode(".", $pagename);
$upl = explode("/", $imagename);
if (isset ($upl[1])) {
if ($UploadPrefixFmt == '/$Group')
$pagename = $upl[0].".Upload";
else {
$pagename = $pgn[0].".".$upl[0];
}
$imagename = $upl[1];
}
if (isset ($upl[2])) {
$pagename = $upl[0].".".$upl[1];
$imagename = $upl[2];
}
return array ('image' => $imagename, 'page' => $pagename);
}
?>