Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_entryproperties
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31269/plugins/serendipity_event_entryproperties
Modified Files:
Tag: branch-smarty
serendipity_event_entryproperties.php
Log Message:
Allow to cache entire entries.
Needs some further work to maybe remove plugin references from _functions completely.
Possibly add a hook to rebuild entries on certain events (like when a new textile/bbcode etc. plugin is added)
Index: serendipity_event_entryproperties.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_entryproperties/Attic/serendipity_event_entryproperties.php,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -d -r1.1.2.4 -r1.1.2.5
--- serendipity_event_entryproperties.php 22 Sep 2004 09:02:20 -0000 1.1.2.4
+++ serendipity_event_entryproperties.php 22 Sep 2004 10:58:58 -0000 1.1.2.5
@@ -9,6 +9,16 @@
@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_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');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_BUILDING', 'Erzeuge cache für Artikel #%d, <em>%s</em>...');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHED', 'Artikel gecached.');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DONE', 'Alle Artikel gecached.');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_ABORTED', 'Caching der Artikel ABGEBROCHEN.');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_TOTAL', ' (insgesamt %d Artikel vorhanden)...');
break;
case 'en':
@@ -21,6 +31,16 @@
@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_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');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_BUILDING', 'Building cache for entry #%d, <em>%s</em>...');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHED', 'Entry cached.');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DONE', 'Entry caching completed.');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_ABORTED', 'Entry caching ABORTED.');
+ @define('PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_TOTAL', ' (totalling %d entries)...');
break;
}
@@ -35,14 +55,31 @@
$propbag->add('name', PLUGIN_EVENT_ENTRYPROPERTIES_TITLE);
$propbag->add('description', PLUGIN_EVENT_ENTRYPROPERTIES_DESC);
$propbag->add('event_hooks', array(
- 'frontend_fetchentries' => true,
- 'frontend_fetchentry' => true,
- 'backend_publish' => true,
- 'backend_save' => true,
- 'backend_display' => true,
- 'frontend_entryproperties' => true
+ 'frontend_fetchentries' => true,
+ 'frontend_fetchentry' => true,
+ 'backend_publish' => true,
+ 'backend_save' => true,
+ 'backend_display' => true,
+ 'frontend_entryproperties' => true,
+ 'backend_sidebar_entries_event_display_buildcache' => true,
+ 'backend_sidebar_entries' => true
));
- $this->supported_properties = array('is_sticky', 'access');
+
+ $propbag->add('configuration', array('cache'));
+ $this->supported_properties = array('is_sticky', 'access', 'cache_body', 'cache_extended');
+ }
+
+ function introspect_config_item($name, &$propbag)
+ {
+ switch($name) {
+ case 'cache':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_ENTRYPROPERTIES_CACHE);
+ $propbag->add('description', PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DESC);
+ $propbag->add('default', 'true');
+ break;
+ }
+ return true;
}
function generate_content(&$title) {
@@ -53,6 +90,7 @@
global $serendipity;
$hooks = &$bag->get('event_hooks');
+ $is_cache = serendipity_db_bool($this->get_config('cache', 'true'));
if (isset($hooks[$event])) {
switch($event) {
case 'backend_display':
@@ -94,12 +132,74 @@
return true;
break;
+ case 'backend_sidebar_entries':
+?>
+ • <a href="?serendipity[adminModule]=event_display&serendipity[adminAction]=buildcache"><?php echo PLUGIN_EVENT_ENTRYPROPERTY_BUILDCACHE; ?></a><br />
+<?php
+ return true;
+ break;
+
+ case 'backend_sidebar_entries_event_display_buildcache':
+ if ($is_cache) {
+ $per_fetch = 25;
+ $page = (isset($serendipity['GET']['page']) ? $serendipity['GET']['page'] : 1);
+ $from = ($page-1)*$per_fetch;
+ $to = ($page)*$per_fetch;
+
+ printf(PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_FETCHNO, $from, $to);
+ $entries = serendipity_fetchEntries(
+ null,
+ true,
+ $per_fetch,
+ false,
+ false,
+ 'timestamp DESC',
+ '',
+ true
+ );
+
+ $total = serendipity_getTotalEntries();
+ printf(PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_TOTAL . '<br />', $total);
+
+ 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']) . "')");
+ echo PLUGIN_EVENT_ENTRYPROPERTIES_CACHED . '<br /><br />';
+ }
+
+ echo '<br />';
+
+ if ($to < $total) {
+?>
+ <script type="text/javascript">
+ if (confirm("<?php echo htmlspecialchars(PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_FETCHNEXT); ?>")) {
+ location.href = "?serendipity[adminModule]=event_display&serendipity[adminAction]=buildcache&serendipity[page]=<?php echo ($page+1); ?>";
+ } else {
+ alert("<?php echo htmlspecialchars(PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_ABORTED); ?>");
+ }
+ </script>
+<?php
+ } else {
+ echo '<div class="serendipity_msg_notice">' . PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DONE . '</div>';
+ }
+ }
+ return true;
+ break;
+
case 'backend_publish':
case 'backend_save':
if (!isset($serendipity['POST']['properties']) || !is_array($serendipity['POST']['properties']) || !isset($eventData['id'])) {
return true;
}
+ if ($is_cache) {
+ $serendipity['POST']['properties']['cache_body'] = $eventData['body'];
+ $serendipity['POST']['properties']['cache_extended'] = $eventData['extended'];
+ }
+
// Get existing data
$property = serendipity_fetchEntryProperties($eventData['id']);
@@ -149,11 +249,18 @@
}
}
- $cond = 'ep_sticky.value IS NULL AS orderkey,';
- if (empty($eventData['orderkey'])) {
- $eventData['orderkey'] = $cond;
+ $conds = array();
+ $conds[] = 'ep_sticky.value IS NULL AS orderkey,';
+ if ($iscache && (!isset($addData['noCache']) || !$addData['noCache'])) {
+ $conds[] = 'ep_cache_extended,';
+ $conds[] = 'ep_cache_body,';
+ }
+
+ $cond = implode("\n", $conds);
+ if (empty($eventData['addkey'])) {
+ $eventData['addkey'] = $cond;
} else {
- $eventData['orderkey'] .= $cond;
+ $eventData['addkey'] .= $cond;
}
$cond = 'orderkey ASC';
@@ -164,6 +271,12 @@
}
$joins = array();
+ if ($is_cache && (!isset($addData['noCache']) || !$addData['noCache'])) {
+ $joins[] = "LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_cache_extended
+ ON (e.id = ep_cache_extended.entryid AND ep_cache_extended.property = 'ep_cache_extended')";
+ $joins[] = "LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_cache_body
+ ON (e.id = ep_cache_body.entryid AND ep_cache_body.property = 'ep_cache_body')";
+ }
$joins[] = "LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_access
ON (e.id = ep_access.entryid AND ep_access.property = 'ep_access')";
$joins[] = "LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_sticky
|