Die Rohform eines Serendipity-Event-Plugins benötigt man immer wieder. Natürlich kann man dafür eines der kleineren Plugins wie s9ymarkup nehmen und dann rauslöschen, was man nicht braucht. Aber im Grund läuft es auf diesen Code hinaus:
<?php
if (IN_serendipity !== true) {
die ("Don't hack!");
}
@serendipity_plugin_api::load_language(dirname(__FILE__));
class serendipity_event_pluginname extends serendipity_event {
var $title = PLUGIN_EVENT_PLUGINNAME_NAME;
function introspect(&$propbag) {
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_PLUGINNAME_NAME);
$propbag->add('description', PLUGIN_EVENT_PLUGINNAME_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Your Name');
$propbag->add('version', '0.1');
$propbag->add('requirements', array(
'serendipity' => '0.8'
));
$propbag->add('event_hooks', array('frontend_display' => true));
$propbag->add('groups', array('MARKUP'));
}
function generate_content(&$title) {
$title = $this->title;
}
/*function introspect_config_item($name, &$propbag) {
}*/
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'frontend_display':
//do something
return true;
break;
default:
return false;
}
} else {
return false;
}
}
function debugMsg($msg) {
global $serendipity;
$this->debug_fp = @fopen ( $serendipity ['serendipityPath'] . 'templates_c/pluginname.log', 'a' );
if (! $this->debug_fp) {
return false;
}
if (empty ( $msg )) {
fwrite ( $this->debug_fp, "failure \
" );
} else {
fwrite ( $this->debug_fp, print_r ( $msg, true ) );
}
fclose ( $this->debug_fp );
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
onli blogging am : Einführung: Serendipity-Plugins schreiben
Vorschau anzeigen