Update of /cvsroot/php-blog/additional_plugins/serendipity_event_authorpic
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19494/serendipity_event_authorpic
Added Files:
serendipity_event_authorpic.php
Log Message:
Added plugin for displaying an image of the author. Useful for multi-author blogs.
--- NEW FILE: serendipity_event_authorpic.php ---
<?php # $Id: serendipity_event_authorpic.php,v 1.1 2004/11/05 10:49:31 garvinhicking Exp $
switch ($serendipity['lang']) {
case 'de':
@define('PLUGIN_AUTHORPIC_NAME', 'Bild des Autoren');
@define('PLUGIN_AUTHORPIC_BLAHBLAH', 'Zeigt ein Bild des Autoren zu jedem Eintrag. Das Bild muss im Ordner "img" vom jeweiligen Templateordner liegen und so heißen, wie der Autorname. Alle Sonderzeichen (Umlaute, Leerzeichen, ...) müssen dabei durch ein "_" im Dateinamen ersetzt werden.');
@define('PLUGIN_AUTHORPIC_EXTENSION', 'Dateiendung');
@define('PLUGIN_AUTHORPIC_EXTENSION_BLAHBLAH', 'Welche Dateiendung haben die Bilder der Autoren?');
break;
case 'en':
default:
@define('PLUGIN_AUTHORPIC_NAME', 'Picture of the author');
@define('PLUGIN_AUTHORPIC_BLAHBLAH', 'Shows a picture of the author to each entry. The image file must be placed in the "img" Subfolder of your selected template and be called like the authorname. All special characters (quotes, spaces, ...) must be replaced by an "_" inside the filename.');
@define('PLUGIN_AUTHORPIC_EXTENSION', 'File extension');
@define('PLUGIN_AUTHORPIC_EXTENSION_BLAHBLAH', 'Which file extension do the images of the authors have?');
break;
}
class serendipity_event_authorpic extends serendipity_event
{
var $found_images = array();
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_AUTHORPIC_NAME);
$propbag->add('description', PLUGIN_AUTHORPIC_BLAHBLAH);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '1.0');
$propbag->add('event_hooks', array('frontend_display' => true, 'css' => true));
$propbag->add('scrambles_true_content', true);
$propbag->add('configuration', array('extension'));
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'extension':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_AUTHORPIC_EXTENSION);
$propbag->add('description', PLUGIN_AUTHORPIC_EXTENSION_BLAHBLAH);
$propbag->add('default', 'jpg');
break;
default:
return false;
}
return true;
}
function generate_content(&$title)
{
$title = PLUGIN_AUTHORPIC_NAME;
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'css':
if (stristr('.serendipity_authorpic', $addData)) {
// class exists in CSS, so a user has customized it and we don't need default
return true;
}
?>
.serendipity_authorpic {
float: right;
margin: 5px;
border: 0px;
display: block;
}
<?php
return true;
break;
case 'frontend_display':
if ($bag->get('scrambles_true_content') && is_array($addData) && isset($addData['no_scramble'])) {
return true;
}
if (isset($this->found_images[$eventData['username']])) {
// Author image was already found previously. Display it.
$eventData['body'] = $this->found_images[$eventData['username']] . $eventData['body'];
} elseif ($img = serendipity_getTemplateFile('img/' . preg_replace('@[^a-z0-9]@i', '_', $eventData['username']) . '.' . $this->get_config('extension'))) {
// Author image exists, save it in cache and display it.
$this->found_images[$eventData['username']] = '<img class="serendipity_authorpic" src="' . $img . '" alt="' . AUTHOR . '" title="' . htmlspecialchars($eventData['username']) . '" />';
$eventData['body'] = $this->found_images[$eventData['username']] . $eventData['body'];
} else {
// No image found, do not try again in next article.
$this->found_images[$eventData['username']] = '';
}
return true;
break;
default:
return false;
}
} else {
return false;
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
|