User guide

Zenphoto as a “plug-in”

NOTE: ThisĀ  is known not to work anymore with (at least) Wordpress and Joomla for yet unknown reasons and results in MySQL errors. Also see this forum thread.

You can use zenphoto features in your main web pages by including template-functions.php in your php pages. To do this successfully when the page is not in the zenphoto folders include the following PHP code in you page (this assumes zenphoto is installed in a folder named zenphoto):

define('WEBPATH', 'zenphoto');
require_once(WEBPATH . "/zp-core/template-functions.php");

You will now be able to use zenphoto functions on your page to, for instance, place an random image from your album on your index page. Code for this is:

$randomImage = getRandomImages();
$randomImageURL = getURL($randomImage);
echo "<a href='".$randomImageURL."' title='Random Picture...'>
<img src='". $randomImage->getSizedImage(getOption('image_size')) . "'
alt=\"random image\n" . $randomImage->getTitle() . '" /></a>';

NOTE: Many of the zenphoto template-functions operate on $_zp_current_album, $_zp_current_image, and $_zp_gallery. The latter are refered to as the current album and current image in the function documentation (see below.) These variables normally are setup by the process of loading the root index.php file and proceding to your theme php file. They will NOT be setup automatically for you when you use zenphoto as a plugin. You can use the functions zp_load_gallery(), zp_load_album($folder), and zp_load_image($folder, $filename) to set these variables up. $folder is the path from the album folder to the album. $filename is the name of the image within $folder.

For further details on the template functions visit the Zenphoto Functions Guide

UPDATE for zenphoto 1.1.6 and beyond:

Zenphoto 1.1.6 has implemented a plugin architecture for adding functionality. If you wish to use functions from these plugins as part of your implementation you will need to initialize the plugins with the following code. Place the code after the ‘require_once’ line that loads the template functions.

//load extensions
$_zp_plugin_scripts = array();
$_zp_flash_player = NULL;
$curdir = getcwd();
chdir(SERVERPATH . "/" . ZENFOLDER . PLUGIN_FOLDER);
$filelist = safe_glob('*'.'php');
chdir($curdir);
foreach ($filelist as $extension) {
$opt = 'zp_plugin_'.substr($extension, 0, strlen($extension)-4);
if (getOption($opt)) {
require_once(SERVERPATH . "/" . ZENFOLDER . PLUGIN_FOLDER . $extension);
}
}
(No longer required with Zenphoto 1.2.7)