Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_entryproperties
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20083/serendipity_event_entryproperties
Added Files:
Tag: branch-smarty
serendipity_event_entryproperties.php
Log Message:
added multi-purpose entryproperties plugin. can add unlimited number of properties to an entry (sticky posts and protected entries, i.e.).
--- NEW FILE: serendipity_event_entryproperties.php ---
<?php # $Id: serendipity_event_entryproperties.php,v 1.1.2.1 2004/09/21 20:39:32 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');
break;
case 'en':
case 'es':
default:
@define('PLUGIN_EVENT_ENTRYPROPERTIES_TITLE', 'Extended properties of entries');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_DESC', '(non-public articles, sticky posts)');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_STICKYPOSTS', 'Sticky Posts');
@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');
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('event_hooks', array(
'frontend_fetchentries' => true,
'frontend_fetchentry' => true,
'backend_publish' => true,
'backend_save' => true,
'backend_display' => true,
'frontend_entryproperties' => true
));
$this->supported_properties = array('is_sticky', 'access');
}
function generate_content(&$title) {
$title = PLUGIN_EVENT_ENTRYPROPERTIES_TITLE . ' ' . PLUGIN_EVENT_ENTRYPROPERTIES_DESC;
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
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_publish':
case 'backend_save':
if (!isset($serendipity['POST']['properties']) || !is_array($serendipity['POST']['properties']) || !isset($eventData['id'])) {
return true;
}
// 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])) {
$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) {
$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'] . ")) ";
}
$cond = implode(' AND ', $conds);
if (empty($eventData['and'])) {
$eventData['and'] = " WHERE $cond ";
} else {
$eventData['and'] .= " AND $cond ";
}
$cond = 'ep_sticky.value IS NULL AS orderkey,';
if (empty($eventData['orderkey'])) {
$eventData['orderkey'] = $cond;
} else {
$eventData['orderkey'] .= $cond;
}
$cond = 'orderkey ASC';
if (empty($eventData['orderby'])) {
$eventData['orderby'] = $cond;
} else {
$eventData['orderby'] = $cond . ', ' . $eventData['orderby'];
}
$joins = array();
$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
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 : */
?>
|