Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_contentrewrite
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26896/serendipity_event_contentrewrite
Added Files:
serendipity_event_contentrewrite.php
Log Message:
New event plugins:
Content-Rewrite (hotwords-plugin, like the old one)
Mailer (mails entries via E-Mail)
Weblogping (performs XML-RPC weblog services pinging)
--- NEW FILE: serendipity_event_contentrewrite.php ---
<?php # $Id: serendipity_event_contentrewrite.php,v 1.1 2004/02/09 15:12:54 garvinhicking Exp $
switch ($serendipity['lang']) {
case 'de':
@define('PLUGIN_EVENT_CONTENTREWRITE_FROM', 'quelle');
@define('PLUGIN_EVENT_CONTENTREWRITE_TO', 'ziel');
@define('PLUGIN_EVENT_CONTENTREWRITE_NAME', 'Wort-Ersetzer');
@define('PLUGIN_EVENT_CONTENTREWRITE_DESCRIPTION', 'Ersetzt ein Wort mit einem neuen Inhalt, z.B. für Akronyme');
@define('PLUGIN_EVENT_CONTENTREWRITE_NEWTITLE', 'Neuer Titel');
@define('PLUGIN_EVENT_CONTENTREWRITE_NEWTDESCRIPTION', 'Der Akronym-Titel des neuen Eintrages ({quelle})');
@define('PLUGIN_EVENT_CONTENTREWRITE_OLDTITLE', 'Titel #%d');
@define('PLUGIN_EVENT_CONTENTREWRITE_OLDTDESCRIPTION', 'Das Akronym ({quelle})');
@define('PLUGIN_EVENT_CONTENTREWRITE_PTITLE', 'Plugin Titel');
@define('PLUGIN_EVENT_CONTENTREWRITE_PDESCRIPTION', 'Der Name dieses Pligins');
@define('PLUGIN_EVENT_CONTENTREWRITE_NEWDESCRIPTION', 'Neue Beschreibung');
@define('PLUGIN_EVENT_CONTENTREWRITE_NEWDDESCRIPTION', 'Die Beschreibung des neuen Eintrages ({ziel})');
@define('PLUGIN_EVENT_CONTENTREWRITE_OLDDESCRIPTION', 'Beschreibung #%s');
@define('PLUGIN_EVENT_CONTENTREWRITE_OLDDDESCRIPTION', 'Die Beschreibung des Eintrages ({ziel})');
@define('PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRING', 'Umformungsmaske');
@define('PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRINGDESC', 'Ein beliebiger Text der zur Ersetzung verwendet werden soll. Fügen Sie {quelle} und {ziel} The string used to rewrite. Place {from} and {to} anywhere you like to get a rewrite.' . "\n" . 'Example: <acronym title="{to}">{from}</acronym>');
@define('PLUGIN_EVENT_CONTENTREWRITE_REWRITECHAR', 'Rewrite char');
@define('PLUGIN_EVENT_CONTENTREWRITE_REWRITECHARDESC', 'If there is any char you append to force rewriting, enter it here. If you want to only replace \'serendipity*\' with what you entered for that word but want the \'*\' removed, enter that char here. NOTE: You can\'t use a different rewrite_char for a plugin having the same rewrite_string!');
break;
case 'en':
case 'es':
default:
@define('PLUGIN_EVENT_CONTENTREWRITE_FROM', 'from');
@define('PLUGIN_EVENT_CONTENTREWRITE_TO', 'to');
@define('PLUGIN_EVENT_CONTENTREWRITE_NAME', 'Content Rewriter');
@define('PLUGIN_EVENT_CONTENTREWRITE_DESCRIPTION', 'Replaces any word with a new string (like for Acronyms)');
@define('PLUGIN_EVENT_CONTENTREWRITE_NEWTITLE', 'New Title');
@define('PLUGIN_EVENT_CONTENTREWRITE_NEWTDESCRIPTION', 'Enter the acronym-title for a new item here ({from})');
@define('PLUGIN_EVENT_CONTENTREWRITE_OLDTITLE', 'Title #%d');
@define('PLUGIN_EVENT_CONTENTREWRITE_OLDTDESCRIPTION', 'Enter the acronym here ({from})');
@define('PLUGIN_EVENT_CONTENTREWRITE_PTITLE', 'Plugin-Title');
@define('PLUGIN_EVENT_CONTENTREWRITE_PDESCRIPTION', 'The name of this plugin');
@define('PLUGIN_EVENT_CONTENTREWRITE_NEWDESCRIPTION', 'New Description');
@define('PLUGIN_EVENT_CONTENTREWRITE_NEWDDESCRIPTION', 'Enter the description for a new item here ({to})');
@define('PLUGIN_EVENT_CONTENTREWRITE_OLDDESCRIPTION', 'Description #%s');
@define('PLUGIN_EVENT_CONTENTREWRITE_OLDDDESCRIPTION', 'Enter the description here ({to})');
@define('PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRING', 'Rewrite string');
@define('PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRINGDESC', 'The string used to rewrite. Place {from} and {to} anywhere you like to get a rewrite.' . "\n" . 'Example: <acronym title="{to}">{from}</acronym>');
@define('PLUGIN_EVENT_CONTENTREWRITE_REWRITECHAR', 'Rewrite char');
@define('PLUGIN_EVENT_CONTENTREWRITE_REWRITECHARDESC', 'If there is any char you append to force rewriting, enter it here. If you want to only replace \'serendipity*\' with what you entered for that word but want the \'*\' removed, enter that char here. NOTE: You can\'t use a different rewrite_char for a plugin having the same rewrite_string!');
break;
}
class serendipity_event_contentrewrite extends serendipity_event
{
var $rewrite_from, $rewrite_to;
function cleanup() {
// Cleanup. Remove all empty configs on SAVECONF-Submit.
serendipity_plugin_api::remove_plugin_value($this->instance, array('title', 'description'));
return true;
}
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_NAME);
$propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_DESCRIPTION);
$propbag->add('event_hooks', array(
'frontend_display' => true
));
if ($_POST['SAVECONF']) $this->cleanup();
$rows = serendipity_db_query("SELECT name, value FROM {$serendipity['dbPrefix']}config WHERE name LIKE '" . $this->instance . "/%'");
$counter = 0;
$values = array();
$values[] = 'title';
$values[] = 'rewrite_string';
$values[] = 'rewrite_char';
$this->title_values = array();
$this->descr_values = array();
$this->rewrite_from = array();
$this->rewrite_to = array();
if (is_array($rows)) {
foreach ($rows as $row) {
$plugin_value = str_replace($this->instance . '/', '', $row['name']);
preg_match('|^(.+)_([0-9]+)$|msU', $plugin_value, $reg_counter);
$found = false;
if ($reg_counter[1] == 'title') {
$this->title_values[] = $plugin_value;
$this->rewrite_from[] = $row['value'];
$found = true;
} elseif ($reg_counter[1] == 'description') {
$this->descr_values[] = $plugin_value;
$this->rewrite_to[] = $row['value'];
$found = true;
}
if ($found) {
$next_counter = $reg_counter[2] + 1;
$counter = ($next_counter > $counter ? $next_counter : $counter);
}
}
}
$counter = ($counter > 0 ? $counter + 1 : $counter);
if (count($this->title_values) == count($this->descr_values)) {
foreach($this->title_values AS $key => $val) {
$values[] = $this->title_values[$key];
$values[] = $this->descr_values[$key];
}
}
$values[] = 'title' . '_' . $counter;
$values[] = 'description' . '_' . $counter;
$propbag->add('configuration', $values);
$this->counter = $counter;
}
function introspect_config_item($name, &$propbag)
{
preg_match('|^(.+)_([0-9]+)$|msU', $name, $switch);
if (!isset($switch[2])) {
$switch[1] = $name;
$switch[2] = 'empty';
}
switch($switch[1]) {
case 'title':
if ($switch[2] != 'empty') {
$propbag->add('type', 'string');
if ($this->counter == $switch[2]) {
$propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_NEWTITLE);
$propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_NEWTDESCRIPTION);
} else {
$propbag->add('name', sprintf(PLUGIN_EVENT_CONTENTREWRITE_OLDTITLE, $switch[2]));
$propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_OLDTDESCRIPTION);
}
} else {
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_PTITLE);
$propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_PDESCRIPTION);
}
break;
case 'description':
$propbag->add('type', 'string');
if ($this->counter == $switch[2]) {
$propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_NEWDESCRIPTION);
$propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_NEWDDESCRIPTION);
} else {
$propbag->add('name', sprintf(PLUGIN_EVENT_CONTENTREWRITE_OLDDESCRIPTION, $switch[2]));
$propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_OLDDDESCRIPTION);
}
break;
case 'rewrite_string':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRING);
$propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_REWRITESTRINGDESC);
break;
case 'rewrite_char':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_EVENT_CONTENTREWRITE_REWRITECHAR);
$propbag->add('description', PLUGIN_EVENT_CONTENTREWRITE_REWRITECHARDESC);
break;
default:
return false;
}
return true;
}
function generate_content(&$title)
{
$title = $this->get_config('title');
?>
<table>
<?php
foreach($this->rewrite_from AS $key => $val) {
?>
<tr>
<th style="font-size: 8pt; font-color: white;"><?= htmlentities($val); ?></th>
<td><?= htmlentities($this->rewrite_to[$key]); ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'frontend_display':
$char = &$this->get_config('rewrite_char');
$string = &$this->get_config('rewrite_string');
foreach($this->rewrite_from AS $nr => $v_from) {
$v_to = $this->rewrite_to[$nr];
if ($v_from != '' && $v_to != '') {
// Use the supplied rewrite string and replace the {from} and {to} values with the ones we got from the plugin
$new =
str_replace(
array(
'{' . PLUGIN_EVENT_CONTENTREWRITE_FROM . '}',
'{' . PLUGIN_EVENT_CONTENTREWRITE_TO . '}'
),
array(
str_replace(
$char,
'',
$v_from
),
$v_to
),
$string
);
// Build a regular expression (ungreedy, multiline) with our quoted value. $val here is the word needing the replacement
$regex = '°([^\d\w])(' . preg_quote($v_from) . ')([^\d\w])°msU';
// \1 and \3 are the prepend/append strings (usually whitespaces) and $new containing the new value
$eventData = preg_replace($regex, '\1' . $new . '\3', $eventData);
}
}
return true;
break;
}
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
|