';
}
if ($to < $total) {
?>
' . PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DONE . '';
}
}
return true;
break;
case 'backend_cache_entries':
if (!$is_cache) {
return true;
}
$entries = serendipity_fetchEntries(
null,
true,
$serendipity['fetchLimit'],
false,
false,
'timestamp DESC',
'',
true
);
if (is_array($entries) && !empty($entries)) {
foreach($entries AS $idx => $entry) {
$this->updateCache($entry);
}
}
return true;
break;
case 'backend_cache_purge':
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE property LIKE 'ep_cache_%'");
break;
case 'backend_entry_presave':
if (is_array($serendipity['POST']['properties'])) {
$this->applyProperties($serendipity['POST']['properties']);
}
break;
case 'backend_publish':
case 'backend_save':
if (!isset($eventData['id'])) {
return true;
}
if (!empty($serendipity['POST']['change_author']) && $serendipity['POST']['change_author'] != $eventData['id']) {
// Check again if the POSTed value is an author that the current user has "access" to.
$avail_users =& $this->getValidAuthors();
$new_authorid = (int)$serendipity['POST']['change_author'];
foreach($avail_users AS $user) {
if ($new_authorid == $user['authorid']) {
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries SET authorid = " . $new_authorid . " WHERE id = " . (int)$eventData['id']);
}
}
}
if ($is_cache) {
// Previous calls to frontend_display used the "no_scramble" atteribute to not tinker with the data.
// We now need to call those plugins that have not yet operated before.
$to_addData = array('from' => 'entryproperties:' . $event);
serendipity_plugin_api::hook_event('frontend_display_cache', $eventData, $to_addData);
$serendipity['POST']['properties']['cache_body'] = $eventData['body'];
$serendipity['POST']['properties']['cache_extended'] = $eventData['extended'];
}
if (is_array($serendipity['POST']['properties']['access_groups']) && $serendipity['POST']['properties']['access'] != 'member') {
unset($serendipity['POST']['properties']['access_groups']);
}
if (is_array($serendipity['POST']['properties']['access_users']) && $serendipity['POST']['properties']['access'] != 'member') {
unset($serendipity['POST']['properties']['access_users']);
}
$this->addProperties($serendipity['POST']['properties'], $eventData);
return true;
break;
case 'frontend_configure':
if (isset($serendipity['POST']['id']) && empty($serendipity['GET']['id'])) {
$serendipity['GET']['id'] = &$serendipity['POST']['id'];
$serendipity['GET']['subpage'] = &$serendipity['POST']['subpage'];
}
break;
case 'frontend_entryproperties':
$and = $this->returnQueryCondition($is_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)) {
return true;
}
foreach($properties AS $idx => $row) {
$eventData[$addData[$row['entryid']]]['properties'][$row['property']] = $row['value'];
}
return true;
break;
case 'entry_display':
// PH: This is done after Garvins suggestion to patchup $eventData in case an entry
// is in the process of being created. This must be done for the extended properties
// to be applied in the preview.
if (isset($serendipity['GET']['id']) && isset($eventData[0]['properties']['ep_entrypassword'])) {
if ($_SESSION['entrypassword_unlocked'][$serendipity['GET']['id']] == md5($eventData[0]['properties']['ep_entrypassword']) || $eventData[0]['properties']['ep_entrypassword'] == $serendipity['POST']['entrypassword']) {
// Do not show login form again, once we have first enabled it.
$_SESSION['entrypassword_unlocked'][$serendipity['GET']['id']] = md5($eventData[0]['properties']['ep_entrypassword']);
} else {
if (is_array($eventData)) {
$eventData['clean_page'] = true;
} else {
$eventData = array('clean_page' => true);
}
$this->showPasswordForm = true;
}
}
if ($addData['preview'] && is_array($serendipity['POST']['properties']) && count($serendipity['POST']['properties']) > 0){
$parr = array();
$supported_properties = serendipity_event_entryproperties::getSupportedProperties();
foreach($supported_properties AS $prop_key) {
if (isset($serendipity['POST']['properties'][$prop_key]))
$eventData[0]['properties']['ep_' . $prop_key] = $serendipity['POST']['properties'][$prop_key];
}
}
break;
case 'entries_header':
if ($this->showPasswordForm) {
echo $this->showPasswordform();
}
break;
case 'frontend_fetchentries':
case 'frontend_fetchentry':
$joins = array();
$conds = array();
if (!$ext_joins) {
return true;
}
if ($_SESSION['serendipityAuthedUser'] === true) {
$conds[] = " (ep_access.property IS NULL OR ep_access.value = 'member' OR ep_access.value = 'public' OR (ep_access.value = 'private' AND e.authorid = " . (int)$serendipity['authorid'] . ")) ";
if ($use_groups) {
$mygroups = serendipity_checkPermission(null, null, true);
$groupcond = array();
foreach((array)$mygroups AS $mygroup) {
$groupcond[] .= "ep_access_groups.value LIKE '%;$mygroup;%'";
}
if (count($groupcond) > 0) {
$conds[] = " (ep_access_groups.property IS NULL OR (ep_access.value = 'member' AND (" . implode(' OR ', $groupcond) . ")))";
}
}
if ($use_users) {
$conds[] = " (ep_access_users.property IS NULL OR (ep_access.value = 'member' AND (ep_access_users.value LIKE '%;" . (int)$serendipity['authorid'] . ";%' OR e.authorid = " . (int)$serendipity['authorid'] . "))) ";
}
} else {
$conds[] = " (ep_access.property IS NULL OR ep_access.value = 'public')";
}
if (!isset($serendipity['GET']['viewAuthor']) && !isset($serendipity['plugin_vars']['tag']) && !isset($serendipity['GET']['category']) && !isset($serendipity['GET']['adminModule']) && $event == 'frontend_fetchentries' && $addData['source'] != 'search') {
$conds[] = " (ep_no_frontpage.property IS NULL OR ep_no_frontpage.value != 'true') ";
$joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_no_frontpage
ON (e.id = ep_no_frontpage.entryid AND ep_no_frontpage.property = 'ep_no_frontpage')";
}
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) && !isset($serendipity['skipSticky'])) {
$conds[] = 'ep_sticky.value AS orderkey,';
} else {
$conds[] = 'e.isdraft 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,';
}
$cond = implode("\n", $conds);
if (empty($eventData['addkey'])) {
$eventData['addkey'] = $cond;
} else {
$eventData['addkey'] .= $cond;
}
if ($serendipity['dbType'] == 'postgres') {
// PostgreSQL is a bit weird here. Empty columns with NULL or "" content for
// orderkey would get sorted on top when using DESC, and only after those
// the "true" content would be inserted. Thus we order ASC in postgreSQL,
// and silently wonder. Thanks to Nate Johnston for working this out!
$cond = 'orderkey ASC';
} else {
$cond = 'orderkey DESC';
}
if (empty($eventData['orderby'])) {
$eventData['orderby'] = $cond;
} else {
$eventData['orderby'] = $cond . ', ' . $eventData['orderby'];
}
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 ($use_groups) {
$joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_access_groups
ON (e.id = ep_access_groups.entryid AND ep_access_groups.property = 'ep_access_groups')";
}
if ($use_users) {
$joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_access_users
ON (e.id = ep_access_users.entryid AND ep_access_users.property = 'ep_access_users')";
}
if ((!isset($addData['noSticky']) || $addData['noSticky'] !== true) && !isset($serendipity['skipSticky'])) {
$joins[] = " LEFT 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;
case 'frontend_entries_rss':
if (is_array($eventData)) {
foreach($eventData AS $idx => $entry) {
if (is_array($entry['properties']) && isset($entry['properties']['ep_hiderss']) && $entry['properties']['ep_hiderss']) {
unset($eventData[$idx]['body']);
unset($eventData[$idx]['extended']);
unset($eventData[$idx]['exflag']);
}
}
}
return true;
break;
case 'backend_plugins_new_instance':
// This hook will always push the entryproperties plugin as last in queue.
// Happens always when a new plugin is added.
// This is important because of its caching mechanism!
// Fetch maximum sort_order value. This will be the new value of our current plugin.
$q = "SELECT MAX(sort_order) as sort_order_max FROM {$serendipity['dbPrefix']}plugins WHERE placement = '" . $addData['default_placement'] . "'";
$rs = serendipity_db_query($q, true, 'num');
// Fetch current sort_order of current plugin.
$q = "SELECT sort_order FROM {$serendipity['dbPrefix']}plugins WHERE name = '" . $this->instance . "'";
$cur = serendipity_db_query($q, true, 'num');
// Decrease sort_order of all plugins after current plugin by one.
$q = "UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = sort_order - 1 WHERE placement = '" . $addData['default_placement'] . "' AND sort_order > " . intval($cur[0]);
serendipity_db_query($q);
// Set current plugin as last plugin in queue.
$q = "UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = " . intval($rs[0]) . " WHERE name = '" . $this->instance . "'";
serendipity_db_query($q);
return true;
break;
default:
return false;
break;
}
} else {
return false;
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>