Faked Plugin
Posted: Tue Jul 14, 2009 8:56 pm
Ich habe Garvins Beispiel vom "Faked Plugin" mal in einer config.inc.php eingesetzt. Ziel soll es eigentlich sein, ganz individuell eine Möglichkeit zu schaffen, die Sidebars pro entry abschalten zu können.
Beispiel http://www.xkur.de/
in der Index.tpl kommt folgender Code:
inhalt config.inc.php:
Es scheint zu funktionien. War es so gedacht und kann man einfach einen zweiten $special_key2 einbauen damit ich beide sidebars pro entry getrennt verwalten kann?
Grüße
Reinhardü
Beispiel http://www.xkur.de/
in der Index.tpl kommt folgender Code:
Code: Select all
{if $leftSidebarElements > 0} {if $entry.properties.special_switch !="false"} <td id="serendipityLeftSideBar" valign="top">{serendipity_printSidebar side="left"}</td> {/if}{/if}
Code: Select all
<?php
// CODE EXAMPLE: How to save custom field variables within the serendipity "Edit/Create Entry" backend.
// Any custom variables can later be queried inside the .tpl files through
// {if $entry.properties.special_switch == 'true'}...{/if}
// NOTE THAT THE PROPERTY IS ACCED *WITHOUT* the ep_ prefix! EP_ only comes from entryproperties.
// Helper function to get the variable content of a variable (TRUE/FALSE)
function helper_get_value($special_key, &$eventData) {
global $serendipity;
$value = (isset($eventData['properties'][$special_key]) && serendipity_db_bool($eventData['properties'][$special_key]))
|| (isset($serendipity['POST']['properties'][$special_key]) && serendipity_db_bool($serendipity['POST']['properties'][$special_key]))
? true
: false;
return $value;
}
// Helper function to store form values into the serendipity database, so that they will be retrieved later.
function helper_store($special_key, $special_val, &$eventData) {
global $serendipity;
$q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property = '" . serendipity_db_escape_string($special_key) . "'";
serendipity_db_query($q);
if (!empty($special_val)) {
$q = "INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$eventData['id'] . ", '" . serendipity_db_escape_string($special_key) . "', '" . serendipity_db_escape_string($special_val) . "')";
serendipity_db_query($q);
}
}
function serendipity_plugin_api_pre_event_hook($event, &$bag, &$eventData, &$addData) {
global $serendipity;
// Check what Event is coming in, only react to those we want.
switch($event) {
// Displaying the backend entry section
case 'backend_display':
// INFO: The whole 'entryproperties' injection is easiest to store any data you want. The entryproperties plugin
// should actually not even be required to do this, as serendipity loads all properties regardless of the installed plugin
// The name of the variable
$special_key = 'special_switch';
// Check what our special key is set to (checks both POST data as well as the actual data)
$is_special = helper_get_value($special_key, $eventData);
// This is the actual HTML output on the backend screen.
echo '<pre>' . print_r($eventData, true) . '</pre>';
echo "Do you want this entry to be special? ";
echo '<input type="radio" name="serendipity[properties][' . $special_key . ']" value="true" ' . ($is_special ? 'checked="checked"' : '') . ' id="' . $special_key . '_true">';
echo ' <label for="' . $special_key . '_true">' . YES . '</label> ';
echo '<input type="radio" name="serendipity[properties][' . $special_key . ']" value="false" ' . (!$is_special ? 'checked="checked"' : '') . ' id="' . $special_key . '_false">';
echo ' <label for="' . $special_key . '_false">' . NO . '</label> ';
break;
// To store the value of our entryproperties
case 'backend_publish':
case 'backend_save':
// Call the helper function with all custom variables here.
helper_store('special_switch', $serendipity['POST']['properties']['special_switch'], $eventData);
break;
}
}
?>
Grüße
Reinhardü