Code: Select all
<?php # $Id: serendipity_plugin_gallery_menalto_random_block.php,v 1.0 2005/05/02 02:00:00 andybrown Exp $
// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname(__FILE__) . '/lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
include $probelang;
}
switch ($serendipity['lang']) {
case 'en':
default:
@define('PLUGIN_GALLERYRANDOMBLOCK_NAME', 'Gallery Random Photo Block');
@define('PLUGIN_GALLERYRANDOMBLOCK_DESC', 'Adds a reference to a Gallery Random Block script (see http://gallery.menalto.com for details on this script)');
@define('PLUGIN_GALLERYRANDOMBLOCK_URL_NAME', 'URL of Gallery install');
@define('PLUGIN_GALLERYRANDOMBLOCK_URL_DESC', 'Enter the URL to a Gallery Installation');
@define('PLUGIN_GALLERYRANDOMBLOCK_URL_DEFAULT', 'http://www.susanandandy.com/gallery/');
@define('PLUGIN_GALLERYRANDOMBLOCK_NUMREPEAT_NAME', 'Number of Random Photos');
@define('PLUGIN_GALLERYRANDOMBLOCK_NUMREPEAT_DESC', 'Enter the number of random photos to show in this block.');
break;
}
class serendipity_plugin_gallery_menalto_random_block extends serendipity_plugin {
var $title = PLUGIN_GALLERYRANDOMBLOCK_NAME;
function introspect(&$propbag)
{
$this->title = $this->get_config('title', $this->title);
$propbag->add('name', PLUGIN_GALLERYRANDOMBLOCK_NAME);
$propbag->add('description', PLUGIN_GALLERYRANDOMBLOCK_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Andrew Brown');
$propbag->add('version', '1.0');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('configuration', array('title', 'path', 'repeat'));
// Register (multiple) dependencies. KEY is the name of the depending plugin. VALUE is a mode of either 'remove' or 'keep'.
// If the mode 'remove' is set, removing the plugin results in a removal of the depending plugin. 'Keep' meens to
// not touch the depending plugin.
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'title':
$propbag->add('type', 'string');
$propbag->add('name', TITLE);
$propbag->add('description', TITLE);
$propbag->add('default', '');
break;
case 'path':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_GALLERYRANDOMBLOCK_URL_NAME);
$propbag->add('description', PLUGIN_GALLERYRANDOMBLOCK_URL_DESC);
$propbag->add('default', PLUGIN_GALLERYRANDOMBLOCK_URL_DEFAULT);
break;
case 'repeat':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_GALLERYRANDOMBLOCK_NUMREPEAT_NAME);
$propbag->add('description', PLUGIN_GALLERYRANDOMBLOCK_NUMREPEAT_DESC);
$propbag->add('default', '1');
break;
default:
return false;
}
return true;
}
function generate_content(&$title) {
global $serendipity;
$title = $this->get_config('title');
$path = $this->get_config('path');
$repeat = $this->get_config('repeat');
if ($repeat != '1') {
$repeat == '1';
}
for ($i=1; $i <= $repeat; $i++) {
if (substr($path,-1) == '/') {
include($path . 'block-random.php');
}
else {
include($path . '/block-random.php');
}
if ($i < $repeat) {
echo '<HR>';
}
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>View a working version here: http://www.susanandandy.com
It uses Gallery's built-in random photo script (http://gallery.menalto.com)
If anyone knows how to write just the virtual path as the $path variable, I'd like the plugin to work that way, as currently, it can steal someone else's gallery...
Please let me know of any bugs or missing error checking.
I should also mention that I used the templatedropdown plugin as a template as it was the easiest to understand (I'm new to php...).
Enjoy!
-Andy