Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_entryproperties
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4177
Modified Files:
serendipity_event_entryproperties.php
Log Message:
refactor property methods to allow calling from other plugins
Index: serendipity_event_entryproperties.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_entryproperties/serendipity_event_entryproperties.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- serendipity_event_entryproperties.php 9 Dec 2004 10:41:06 -0000 1.8
+++ serendipity_event_entryproperties.php 4 Jan 2005 15:24:40 -0000 1.9
@@ -72,7 +72,6 @@
));
$propbag->add('configuration', array('cache'));
- $this->supported_properties = array('is_sticky', 'access', 'cache_body', 'cache_extended');
}
function introspect_config_item($name, &$propbag)
@@ -109,6 +108,33 @@
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 getSupportedProperties() {
+ static $supported_properties = array('is_sticky', 'access', 'cache_body', 'cache_extended');
+
+ return $supported_properties;
+ }
+
+ function addProperties(&$properties, &$eventData) {
+ global $serendipity;
+ // Get existing data
+ $property = serendipity_fetchEntryProperties($eventData['id']);
+ $supported_properties = serendipity_event_entryproperties::getSupportedProperties();
+
+ foreach($supported_properties AS $prop_key) {
+ $prop_val = (isset($properties[$prop_key]) ? $properties[$prop_key] : null);
+ $prop_key = 'ep_' . $prop_key;
+ if (!isset($property[$prop_key]) && !empty($prop_val)) {
+ $q = "INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$eventData['id'] . ", '" . serendipity_db_escape_string($prop_key) . "', '" . serendipity_db_escape_string($prop_val) . "')";
+ } elseif ($property[$propkey] != $prop_val && !empty($prop_val)) {
+ $q = "UPDATE {$serendipity['dbPrefix']}entryproperties SET value = '" . serendipity_db_escape_string($prop_val) . "' WHERE entryid = " . (int)$eventData['id'] . " AND property = '" . serendipity_db_escape_string($prop_key) . "'";
+ } else {
+ $q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property = '" . serendipity_db_escape_string($prop_key) . "'";
+ }
+
+ serendipity_db_query($q);
+ }
+ }
+
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
@@ -251,22 +277,8 @@
$serendipity['POST']['properties']['cache_extended'] = $eventData['extended'];
}
- // Get existing data
- $property = serendipity_fetchEntryProperties($eventData['id']);
-
- foreach($this->supported_properties AS $prop_key) {
- $prop_val = (isset($serendipity['POST']['properties'][$prop_key]) ? $serendipity['POST']['properties'][$prop_key] : null);
- $prop_key = 'ep_' . $prop_key;
- if (!isset($property[$prop_key]) && !empty($prop_val)) {
- $q = "INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$eventData['id'] . ", '" . serendipity_db_escape_string($prop_key) . "', '" . serendipity_db_escape_string($prop_val) . "')";
- } elseif ($property[$propkey] != $prop_val && !empty($prop_val)) {
- $q = "UPDATE {$serendipity['dbPrefix']}entryproperties SET value = '" . serendipity_db_escape_string($prop_val) . "' WHERE entryid = " . (int)$eventData['id'] . " AND property = '" . serendipity_db_escape_string($prop_key) . "'";
- } else {
- $q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property = '" . serendipity_db_escape_string($prop_key) . "'";
- }
+ $this->addProperties($serendipity['POST']['properties'], $eventData);
- serendipity_db_query($q);
- }
return true;
break;
|