Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29616
Modified Files:
serendipity_functions.inc.php
Log Message:
Introducing event plugins (see mailing list)
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.200
retrieving revision 1.201
diff -u -d -r1.200 -r1.201
--- serendipity_functions.inc.php 8 Feb 2004 17:56:27 -0000 1.200
+++ serendipity_functions.inc.php 9 Feb 2004 15:20:52 -0000 1.201
@@ -7,9 +7,9 @@
include_once("${serendipity['serendipityPath']}compat.php");
include_once("${serendipity['serendipityPath']}serendipity_functions_config.inc.php");
include_once("${serendipity['serendipityPath']}bundled-libs/XML/RPC.php");
+include_once("${serendipity['serendipityPath']}serendipity_plugin_api.php");
include_once("${serendipity['serendipityPath']}serendipity_functions_images.inc.php");
-
function serendipity_logout() {
$_SESSION['serendipityAuthedUser'] = false;
session_destroy();
@@ -665,6 +665,7 @@
$add_query = '';
if (is_array($serendipity['GET'])) {
$page_get_array = $serendipity['GET'];
+ unset($page_get_array['calendarZoom']);
unset($page_get_array['page']);
unset($page_get_array['range']);
unset($page_get_array['action']);
@@ -757,7 +758,11 @@
<h4 class="serendipity_title"><a href="<?php echo $entryLink; ?>"><?php echo htmlentities($entry['title']); ?></a></h4>
<div class="serendipity_entry">
- <?php echo nl2br(serendipity_emoticate(serendipity_markup_text($entry['body'], $entry['id']))) . $html_extended; ?>
+<?php
+ $article = nl2br(serendipity_emoticate(serendipity_markup_text($entry['body'], $entry['id']))) . $html_extended;
+ serendipity_plugin_api::hook_event('frontend_display', $article);
+ echo $article;
+?>
<div class='serendipity_entryFooter'>
<?php
@@ -1277,7 +1282,11 @@
<title mode="escaped" type="text/html"><?php echo utf8_encode(htmlspecialchars($entry['title'])); ?></title>
<content type="application/xhtml+xml" xml:base="<?php echo $serendipity['baseURL']; ?>" xml:space="preserve">
<div xmlns="http://www.w3.org/1999/xhtml">
- <?php echo utf8_encode(nl2br(serendipity_emoticate(serendipity_markup_text($entry['body'] . $ext)))); ?>
+<?php
+ $article = nl2br(serendipity_emoticate(serendipity_markup_text($entry['body'] . $ext)));
+ serendipity_plugin_api::hook_event('frontend_display', $article);
+ echo utf8_encode($article);
+?>
</div>
</content>
</entry>
@@ -1307,7 +1316,11 @@
?>
<author><?php echo utf8_encode(htmlspecialchars($entry['email'])) . ' (' . utf8_encode(htmlspecialchars($entry['username'])) . ')'; ?></author>
<content:encoded>
- <?php echo utf8_encode(htmlspecialchars(nl2br(serendipity_emoticate(serendipity_markup_text($entry['body'] . $ext))))); ?>
+<?php
+ $article = nl2br(serendipity_emoticate(serendipity_markup_text($entry['body'] . $ext)));
+ serendipity_plugin_api::hook_event('frontend_display', $article);
+ echo utf8_encode(htmlspecialchars($article));
+?>
</content:encoded>
<pubDate><?php echo date('r', $entry['timestamp']); ?></pubDate>
<guid><?php echo $guid; ?></guid>
@@ -1330,7 +1343,11 @@
<title><?php echo utf8_encode(htmlspecialchars($entry['title'])); ?></title>
<link><?php echo $guid; ?></link>
<description>
- <?php echo utf8_encode(htmlspecialchars(nl2br(serendipity_emoticate(serendipity_markup_text($entry['body'] . $ext))))); ?>
+<?php
+ $article = nl2br(serendipity_emoticate(serendipity_markup_text($entry['body'] . $ext)));
+ serendipity_plugin_api::hook_event('frontend_display', $article);
+ echo utf8_encode(htmlspecialchars($article));
+?>
</description>
<dc:publisher><?php echo utf8_encode(htmlspecialchars($serendipity['blogTitle'])); ?></dc:publisher>
<dc:creator><?php echo utf8_encode(htmlspecialchars($entry['email'])) . ' (' . utf8_encode(htmlspecialchars($entry['username'])) . ')'; ?></dc:creator>
@@ -1359,102 +1376,6 @@
return('<tt>' . str_replace(' ', ' ', $arg[1]) . '</tt>');
}
-function serendipity_content_rewrite($str) {
- global $serendipity;
-
- // Do this only once!
- if (!class_exists('serendipity_plugin_api')) {
- include_once('serendipity_plugin_api.php');
- }
-
- // If this variable is not set, this function is called for the first time.
- // Now let's search for plugins needing content rewriting
- if (!isset($serendipity['content_rewrite']['active'])) {
-
- // We set this to false, so when this function is called later, it won't have to enumerate all plugins again
- $serendipity['content_rewrite']['active'] = false;
-
- // Get those nifty plugins
- $plugins = serendipity_plugin_api::enum_plugins();
-
- if (is_array($plugins)) {
-
- // store the rewrite items in our main container for later usage.
- $serendipity['content_rewrite']['data']['rewrite_from'] = array();
- $serendipity['content_rewrite']['data']['rewrite_to'] = array();
-
- // load each plugin to make some introspection
- foreach ($plugins as $plugin_data) {
- $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name']);
- $bag = new serendipity_property_bag;
- $plugin->introspect($bag);
-
- if ($bag->get('rewrite_active') === true) {
-
- // Store necessary data in our main container
- $serendipity['content_rewrite']['string'] = $plugin->get_config('rewrite_string');
-
- if ($serendipity['content_rewrite']['string'] != '') {
- $rewrite_from = $bag->get('rewrite_from');
- $serendipity['content_rewrite']['data']['rewrite_char'][$serendipity['content_rewrite']['string']] = &$plugin->get_config('rewrite_char');
-
- foreach($rewrite_from AS $nr => $key) {
- $serendipity['content_rewrite']['data']['rewrite_from'][$serendipity['content_rewrite']['string']][] = $plugin->get_config($key);
- }
-
- $rewrite_to = $bag->get('rewrite_to');
- foreach($rewrite_to AS $nr => $key) {
- $serendipity['content_rewrite']['data']['rewrite_to'][$serendipity['content_rewrite']['string']][] = $plugin->get_config($key);
- }
-
- // We now have at least one active plugin.
- $serendipity['content_rewrite']['active'] = true;
- }
- }
- }
- }
- }
-
- // Check if we have any plugin data needing rewrite
- if (is_array($serendipity['content_rewrite']['data']['rewrite_from'])) {
- foreach($serendipity['content_rewrite']['data']['rewrite_from'] AS $rewrite_string => $rewrite_values) {
- foreach($rewrite_values AS $key => $val) {
- if (trim($val) != '') {
-
- // Use the supplied rewrite string and replace the {from} and {to} values with the ones we got from the plugin
- $new =
- str_replace(
- array(
- '{from}',
- '{to}'
- ),
-
- array(
- str_replace(
- $serendipity['content_rewrite']['data']['rewrite_char'][$rewrite_string],
- '',
- $val
- ),
-
- $serendipity['content_rewrite']['data']['rewrite_to'][$rewrite_string][$key]
- ),
-
- $rewrite_string
- );
-
- // Build a regular expression (ungreedy, multiline) with our quoted value. $val here is the word needing the replacement
- $regex = '°([^\d\w])(' . preg_quote($val) . ')([^\d\w])°msU';
-
- // \1 and \3 are the prepend/append strings (usually whitespaces) and $new containing the new value
- $str = preg_replace($regex, '\1' . $new . '\3', $str);
- }
- }
- }
- }
-
- return $str;
-}
-
function serendipity_markup_text($str, $entry_id = 0) {
global $serendipity;
@@ -1498,9 +1419,6 @@
);
}
- // Do some content rewrite, if necessary
- $ret = serendipity_content_rewrite($ret);
-
return $ret;
}
@@ -1901,11 +1819,9 @@
serendipity_purgeEntry($entry['id'], $entry['timestamp']);
- # XXX this may not handle a previously-entered draft being made live
- if ($serendipity['announce_entries'] &&
- $entry['isdraft'] == 'false' &&
+ if ($entry['isdraft'] == 'false' &&
$newEntry) {
- serendipity_announceEntry();
+ serendipity_plugin_api::hook_event('backend_publish', $entry);
}
return (int)$entry['id'];
@@ -2104,34 +2020,16 @@
</td>
</tr>
-<?php
- if ($serendipity['announce_entries']) {
-?>
<tr>
<td colspan="3">
<br />
<fieldset>
<legend><b><?php echo ADVANCED_OPTIONS; ?></b></legend>
- <fieldset>
- <legend><?php echo PING_WEBLOGS; ?></legend>
-<?php
- $services = array('blogs' => 'blo.gs', 'blogrolling' => 'blogrolling.com', 'technorati' => 'technorati.com', 'weblogs' => 'weblogs.com', 'bloggde' => 'blogg.de', 'yahoo' => 'yahoo.com');
- foreach($services AS $service => $service_desc) {
- // Detect if the current checkbox needs to be saved. We use the field chk_timestamp to see,
- // if the form has already been submitted and individual changes shall be preserved
- $selected = (($serendipity['POST']['chk_timestamp'] && $serendipity['POST']['announce_entries_' . $service]) || (!isset($serendipity['POST']['chk_timestamp']) && $serendipity['announce_entries_' . $service])? 'checked="checked"' : '');
-?>
- <input style="margin: 0px; padding: 0px; vertical-align: bottom;" type="checkbox" name="serendipity[announce_entries_<?php echo $service; ?>]" id="serendipity[announce_entries_<?php echo $service; ?>]" value="true" <?php echo $selected; ?> />
- <label style="vertical-align: bottom; margin: 0px; padding: 0px;" for="serendipity[announce_entries_<?php echo $service; ?>]"> <?php echo $service_desc; ?> </label>
<?php
- }
+ serendipity_plugin_api::hook_event('backend_display', $entry);
?>
- </fieldset>
</td>
</tr>
-<?php
- }
-?>
</table>
</form>
<?php
@@ -2485,105 +2383,6 @@
}
}
-/**
-* Announces a new entry to any ping services that are registered.
-**/
-function serendipity_announceEntry() {
- global $serendipity;
-
- $services = array();
-
- if ($serendipity['POST']['announce_entries_blogs'] == 'true') {
- $services[] = array(
- 'host' => 'ping.blo.gs',
- 'path' => '/',
- 'extended' => true
- );
- }
-
- if ($serendipity['POST']['announce_entries_blogrolling'] == 'true') {
- $services[] = array(
- 'host' => 'rpc.blogrolling.com',
- 'path' => '/pinger/'
- );
- }
-
- if ($serendipity['POST']['announce_entries_technorati'] == 'true') {
- $services[] = array(
- 'host' => 'rpc.technorati.com',
- 'path' => '/rpc/ping'
- );
- }
-
- if ($serendipity['POST']['announce_entries_weblogs'] == 'true') {
- $services[] = array(
- 'host' => 'rpc.weblogs.com',
- 'path' => '/RPC2'
- );
- }
-
- if ($serendipity['POST']['announce_entries_bloggde'] == 'true') {
- $services[] = array(
- 'host' => 'xmlrpc.blogg.de',
- 'path' => '/'
- );
- }
-
- if ($serendipity['POST']['announce_entries_yahoo'] == 'true') {
- $services[] = array(
- 'host' => 'api.my.yahoo.com',
- 'path' => '/RPC2'
- );
- }
-
- foreach ($services as $service => $details) {
- printf(SENDING_PING . '...<br />', $details['host']);
-
- # XXX append $serendipity['indexFile'] to baseURL?
- $args = array(
- new XML_RPC_Value(
- $serendipity['blogTitle'],
- 'string'
- ),
- new XML_RPC_Value(
- $serendipity['baseURL'],
- 'string'
- )
- );
-
- if ($details['extended']) {
- # the checkUrl: for when the main page is not really the main page
- $args[] = new XML_RPC_Value(
- '',
- 'string'
- );
-
- # the rssUrl
- $args[] = new XML_RPC_Value(
- $serendipity['baseURL'] . 'rss.php?version=2.0',
- 'string'
- );
- }
-
- $message = new XML_RPC_Message(
- $details['extended'] ? 'weblogUpdates.extendedPing' : 'weblogUpdates.ping',
- $args
- );
-
- $client = new XML_RPC_Client(
- $details['path'],
- $details['host']
- );
-
- # 15 second timeout may not be long enough for weblogs.com
- $result = $client->send($message, 15);
-
- # TODO do something with the result? (do we care?)
- }
-
- return true;
-}
-
function serendipity_discover_rss($name, $ext, $default = '2.0') {
if ($name == 'atom') {
$ver = 'atom0.3';
|