Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_entryproperties
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24806/plugins/serendipity_event_entryproperties
Added Files:
serendipity_event_entryproperties.php
Log Message:
Merge from 'branch-smarty' to HEAD.
--- NEW FILE: serendipity_event_entryproperties.php ---
<?php # $Id: serendipity_event_entryproperties.php,v 1.2 2004/11/19 11:05:39 garvinhicking Exp $
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_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_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':
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_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_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;
}
class serendipity_event_entryproperties extends serendipity_event
{
var $services;
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_ENTRYPROPERTIES_TITLE);
$propbag->add('description', PLUGIN_EVENT_ENTRYPROPERTIES_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '1.0');
$propbag->add('event_hooks', array(
'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
));
$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) {
$title = PLUGIN_EVENT_ENTRYPROPERTIES_TITLE;
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
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':
$is_sticky = (isset($eventData['properties']['ep_is_sticky']) && serendipity_db_bool($eventData['properties']['ep_is_sticky']))
|| (isset($serendipity['POST']['properties']['is_sticky']) && serendipity_db_bool($serendipity['POST']['properties']['is_sticky']))
? 'checked="checked"'
: '';
$access_values = array(
PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_PRIVATE => 'private',
PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_MEMBER => 'member',
PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_PUBLIC => 'public',
);
if (isset($eventData['properties']['ep_access'])) {
$access = $eventData['properties']['ep_access'];
} elseif (isset($serendipity['POST']['properties']['access'])) {
$access = $serendipity['POST']['properties']['access'];
} else {
$access = 'public';
}
?>
<fieldset style="margin: 5px">
<legend><?php echo PLUGIN_EVENT_ENTRYPROPERTIES_TITLE; ?></legend>
<input type="checkbox" name="serendipity[properties][is_sticky]" id="properties_is_sticky" value="true" <?php echo $is_sticky; ?> />
<label title="<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_STICKYPOSTS; ?>" for="serendipity[properties][is_sticky]"> <?php echo PLUGIN_EVENT_ENTRYPROPERTIES_STICKYPOSTS; ?> </label><br />
<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS; ?>:
<?php
foreach($access_values AS $radio_title => $radio_value) {
?>
<input type="radio" name="serendipity[properties][access]" id="properties_access_<?php echo $radio_value; ?>" value="<?php echo $radio_value; ?>" <?php echo $radio_value == $access ? 'checked="checked"' : ''; ?> />
<label title="<?php echo $radio_title; ?>" for="id_properties_access_<?php echo $radio_value; ?>"> <?php echo $radio_title; ?> </label>
<?php
}
?>
<br />
</fieldset>
<?php
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']);
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) . "'";
}
serendipity_db_query($q);
}
return true;
break;
case 'frontend_entryproperties':
$q = "SELECT entryid, property, value FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid IN (" . implode(', ', array_keys($addData)) . ")";
$properties = serendipity_db_query($q);
if (!is_array($properties)) {
return true;
}
foreach($properties AS $idx => $row) {
$eventData[$addData[$row['entryid']]]['properties'][$row['property']] = $row['value'];
}
return true;
break;
case 'frontend_fetchentries':
case 'frontend_fetchentry':
$conds = array();
if ($_SESSION['serendipityAuthedUser'] === true) {
$conds[] = " (ISNULL(ep_access.property) OR ep_access.value = 'member' OR ep_access.value = 'public' OR (ep_access.value = 'private' AND e.authorid = " . (int)$serendipity['authorid'] . ")) ";
} else {
$conds[] = " (ISNULL(ep_access.property) OR ep_access.value = 'public') ";
}
if (count($conds) > 0) {
$cond = implode(' AND ', $conds);
if (empty($eventData['and'])) {
$eventData['and'] = " WHERE $cond ";
} else {
$eventData['and'] .= " AND $cond ";
}
}
$conds = array();
if (!isset($addData['noSticky']) || $addData['noSticky'] !== true) {
$conds[] = 'ep_sticky.value IS NULL AS orderkey,';
}
if ($is_cache && (!isset($addData['noCache']) || !$addData['noCache'])) {
$conds[] = 'ep_cache_extended.value AS ep_cache_extended,';
$conds[] = 'ep_cache_body.value AS ep_cache_body,';
}
if (count($conds) < 1) {
$conds[] = '1 AS orderkey,';
}
$cond = implode("\n", $conds);
if (empty($eventData['addkey'])) {
$eventData['addkey'] = $cond;
} else {
$eventData['addkey'] .= $cond;
}
$cond = 'orderkey ASC';
if (empty($eventData['orderby'])) {
$eventData['orderby'] = $cond;
} else {
$eventData['orderby'] = $cond . ', ' . $eventData['orderby'];
}
$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')";
if (!isset($addData['noSticky']) || $addData['noSticky'] !== true) {
$joins[] = "LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_sticky
ON (e.id = ep_sticky.entryid AND ep_sticky.property = 'ep_is_sticky')";
}
$cond = implode("\n", $joins);
if (empty($eventData['joins'])) {
$eventData['joins'] = $cond;
} else {
$eventData['joins'] .= $cond;
}
return true;
break;
default:
return false;
break;
}
} else {
return false;
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
|