Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_entryproperties
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29422/plugins/serendipity_event_entryproperties
Modified Files:
serendipity_event_entryproperties.php
Log Message:
* Move Smarty object instancing to a function call, so that is not
created when not needed (like for CSS)
* make head_title / head_subtitle globally available, so that plugins
can also use it
* Code optimizations: Queries, referenced variables, plugin API
* Improved entryproperties cache
* Improved Plugin API calls to fetch titles of entries
* Improved Plugin aPI calls to set the authorid of a plugin
* Improved some plugins to not create costy introspect() calls, and move
them to the introspect_config_item() part
* Fixed trackexits plugin to not abuse the query() function too often
Index: serendipity_event_entryproperties.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_entryproperties/serendipity_event_entryproperties.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- serendipity_event_entryproperties.php 19 Nov 2004 11:05:39 -0000 1.2
+++ serendipity_event_entryproperties.php 19 Nov 2004 11:24:54 -0000 1.3
@@ -3,14 +3,14 @@
switch ($serendipity['lang']) {
case 'de':
@define('PLUGIN_EVENT_ENTRYPROPERTIES_TITLE', 'Erweiterte Eigenschaften von Artikeln');
- @define('PLUGIN_EVENT_ENTRYPROPERTIES_DESC', '(nicht-öffentliche Artikel, dauerhafte Artikel)');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_DESC', '(Cache, nicht-öffentliche Artikel, dauerhafte Artikel)');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_STICKYPOSTS', 'Dauerhafte Artikel');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS', 'Artikel können gelesen werden von');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_PRIVATE', 'mir selbst');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_MEMBER', 'Co-Autoren');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_PUBLIC', 'allen');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE', 'Artikel cachen?');
- @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DESC', 'Falls diese Option aktiviert ist, wird eine Cache-Version des Artikels gespeichert. Dieses Caching wird zwar die Performance erhöhen, aber Flexibilität anderer Plugins einschränken.');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DESC', 'Falls diese Option aktiviert ist, wird eine Cache-Version des Artikels gespeichert. Dieses Caching wird zwar die Performance erhöhen, aber Flexibilität anderer Plugins eventuell einschränken.');
@define('PLUGIN_EVENT_ENTRYPROPERTY_BUILDCACHE', 'Cachen aller Artikel');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_FETCHNEXT', 'Suche nach zu cachenden Artikeln...');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_FETCHNO', 'Bearbeite Artikel %d bis %d');
@@ -25,14 +25,14 @@
case 'es':
default:
@define('PLUGIN_EVENT_ENTRYPROPERTIES_TITLE', 'Extended properties for entries');
- @define('PLUGIN_EVENT_ENTRYPROPERTIES_DESC', '(non-public articles, sticky posts)');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_DESC', '(cache, non-public articles, sticky posts)');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_STICKYPOSTS', 'Mark this entry as a Sticky Post');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS', 'Entries can be read by');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_PRIVATE', 'Myself');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_MEMBER', 'Co-authors');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_PUBLIC', 'Everyone');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE', 'Allow to cache entries?');
- @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DESC', 'If enabled, a cached version will be generated on every saving. Caching will increase performance, but decrease flexibility for other plugins.');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DESC', 'If enabled, a cached version will be generated on every saving. Caching will increase performance, but maybe decrease flexibility for other plugins.');
@define('PLUGIN_EVENT_ENTRYPROPERTY_BUILDCACHE', 'Build cached entries');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_FETCHNEXT', 'Fetching next batch of entries...');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_FETCHNO', 'Fetching entries %d to %d');
@@ -46,7 +46,8 @@
class serendipity_event_entryproperties extends serendipity_event
{
-var $services;
+ var $services;
+ var $title = PLUGIN_EVENT_ENTRYPROPERTIES_TITLE;
function introspect(&$propbag)
{
@@ -65,7 +66,9 @@
'backend_display' => true,
'frontend_entryproperties' => true,
'backend_sidebar_entries_event_display_buildcache' => true,
- 'backend_sidebar_entries' => true
+ 'backend_sidebar_entries' => true,
+ 'backend_cache_entries' => true,
+ 'backend_cache_purge' => true
));
$propbag->add('configuration', array('cache'));
@@ -86,7 +89,24 @@
}
function generate_content(&$title) {
- $title = PLUGIN_EVENT_ENTRYPROPERTIES_TITLE;
+ $title = $this->title;
+ }
+
+ function install() {
+ serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
+ }
+
+ function uninstall() {
+ serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
+ }
+
+ function updateCache(&$entry) {
+ global $serendipity;
+
+ serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$entry['id'] . " AND property LIKE 'ep_cache_%'");
+ serendipity_plugin_api::hook_event('frontend_display', $entry);
+ serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$entry['id'] . ", 'ep_cache_body', '" . serendipity_db_escape_string($entry['body']) . "')");
+ serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$entry['id'] . ", 'ep_cache_extended', '" . serendipity_db_escape_string($entry['extended']) . "')");
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
@@ -136,9 +156,11 @@
break;
case 'backend_sidebar_entries':
+ if ($is_cache) {
?>
• <a href="?serendipity[adminModule]=event_display&serendipity[adminAction]=buildcache"><?php echo PLUGIN_EVENT_ENTRYPROPERTY_BUILDCACHE; ?></a><br />
<?php
+ }
return true;
break;
@@ -165,10 +187,7 @@
foreach($entries AS $idx => $entry) {
printf(PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_BUILDING . '<br />', $entry['id'], htmlspecialchars($entry['title']));
- serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$entry['id'] . " AND property LIKE 'ep_cache_%'");
- serendipity_plugin_api::hook_event('frontend_display', $entry);
- serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$entry['id'] . ", 'ep_cache_body', '" . serendipity_db_escape_string($entry['body']) . "')");
- serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$entry['id'] . ", 'ep_cache_extended', '" . serendipity_db_escape_string($entry['extended']) . "')");
+ $this->updateCache($entry);
echo PLUGIN_EVENT_ENTRYPROPERTIES_CACHED . '<br /><br />';
}
@@ -191,6 +210,36 @@
return true;
break;
+ case 'backend_cache_entries':
+ if (!$is_cache) {
+ return true;
+ }
+
+ $entries = serendipity_fetchEntries(
+ null,
+ true,
+ $serendipity['fetchLimit'],
+ false,
+ false,
+ 'timestamp DESC',
+ '',
+ true
+ );
+
+ foreach($entries AS $idx => $entry) {
+ $this->updateCache($entry);
+ }
+ return true;
+ break;
+
+ case 'backend_cache_purge':
+ if (!$is_cache) {
+ return true;
+ }
+
+ serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE property LIKE 'ep_cache_%'");
+ break;
+
case 'backend_publish':
case 'backend_save':
if (!isset($serendipity['POST']['properties']) || !is_array($serendipity['POST']['properties']) || !isset($eventData['id'])) {
@@ -222,7 +271,11 @@
break;
case 'frontend_entryproperties':
- $q = "SELECT entryid, property, value FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid IN (" . implode(', ', array_keys($addData)) . ")";
+ $and = '';
+ if (!$is_cache) {
+ $and = " AND property NOT LIKE 'ep_cache_%' ";
+ }
+ $q = "SELECT entryid, property, value FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid IN (" . implode(', ', array_keys($addData)) . ") $and";
$properties = serendipity_db_query($q);
if (!is_array($properties)) {
|