Faked Plugin

Hier können Probleme und alles andere in Deutscher Sprache gelöst werden.
Post Reply
reinhardl
Regular
Posts: 258
Joined: Wed Jun 20, 2007 8:54 am
Location: Germany

Faked Plugin

Post by reinhardl »

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:

Code: Select all

  {if $leftSidebarElements > 0}  {if $entry.properties.special_switch !="false"} <td id="serendipityLeftSideBar" valign="top">{serendipity_printSidebar side="left"}</td>  {/if}{/if}
inhalt config.inc.php:

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;
    }

}

?>


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ü
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Faked Plugin

Post by garvinhicking »

Hi!

Ja, eigentlich sollte man ganz einfach einen special_key2 hinzufügen können, indem man erstmal $special_key2 = 'blabla' zuweist, dann eine eigene $is_special2 variable hat, und später die <inputs> basierend darauf ausgibt. Wie die Variable heißt, ist natürlich ganz frei.

Schön dass Du dir das einmal zu Herzen genommen hast und eingebaut hast!

Ich hab bei mir standardmäßig per Windows einen eher hellblauen hintergrund, daher fällt mir auf deiner seite auf dass der Seitenhintergrund nicht wie der Content-Teil auf #FFF gesetzt ist. Ansonsten ist das eine schöne Variante vom carl-Template mit vielen Eigenheiten!

Grüße,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
reinhardl
Regular
Posts: 258
Joined: Wed Jun 20, 2007 8:54 am
Location: Germany

Re: Faked Plugin

Post by reinhardl »

kann der special key auch ein string werden?


Grüße
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Faked Plugin

Post by garvinhicking »

Hi!

special key ist ja schon ei String; du solltest aber Sonderzeichen und LEerzeichen dort vermeiden.

Grüße,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply