Search
Table of ContentsDeveloper's Manual
Logging and error messages Index Using a CAPTCHA

### Reading and writing of profile settings

#### General introduction

YANA provides a global memory, that can be read and modified by all plug-ins. All variables stored this area will be accessable in all skins and templates. Please note: the global storage area in YANA is something other than the global namespace of PHP.

Values stored here are presented as a data tree and are organized as multidimensional, associative arrays. This data may be accessed via keys, analogous to Smarty - or, if you like, similar to XPath.

For example:

Assuming that the tree is as follows:
array(
"a" => 2,
"b" => array(
"c" => 3,
1 => 4
)
);
Then you can use the following keys:

    <?php
    $array = $YANA->getVar("*"); // use the key "*" to get a copy of the whole array
    $int = $YANA->getVar("a");   // output: 2
    $array = $YANA->getVar("b"); // output: array("c" => 3, 1 => 4)
    $int = $YANA->getVar("b.c"); // output: 3

    /* Unlike to XML-files, numeric ids may be used: */
    $int = $YANA->getVar("b.1"); // output: 4
    ?>

#### How do I read variables from the global memory?

The function $YANA->getVar() enables you to read values in the global storage area.

    <?php
    global $YANA;

    /* get all values */
    $array = $YANA->getVar("*");

    /* get specific values */
    $mixed = $YANA->getVar("FOO1.FOO2.FOO3");

    /* alternative notation */
    $mixed = $YANA->registry->getVar("FOO1.FOO2.FOO3");
    ?>

#### How do I write variables to the global memory?

The function $YANA->setVar() enables you to write values in the global storage area.

    <?php
    global $YANA;

    /* register variable "MY_VAR" */
    $bool = $YANA->setVar("MY_VAR", $new_value);

    $bool = $YANA->setVar("FOO1.FOO2.MY_VAR", $new_value);

    /* alternative notation */
    $mixed = $YANA->registry->setVar("FOO1.FOO2.MY_VAR", $new_value);
    ?>

#### How do I deleted variables from the global memory?

To do so use the function $YANA->unsetVar(). For example:

    <?php
    global $YANA;

    /* unset var "MY_VAR" */
    $bool = $YANA->unsetVar("MY_VAR");

    $bool = $YANA->unsetVar("FOO1.FOO2.MY_VAR");

    /* alternative notation */
    $mixed = $YANA->registry->unsetVar("FOO1.FOO2.MY_VAR");
    ?>

#### How do I change the type of a variable in global memory?

Use the function $YANA->setType() to do this. For example:

    <?php
    global $YANA;

    /* set type of "MY_VAR" to string */
    $bool = $YANA->setType("MY_VAR", "string");

    $bool = $YANA->setType("FOO1.FOO2.MY_VAR", "string");

    /* alternative notation */
    $mixed = $YANA->registry->setType("FOO1.FOO2.MY_VAR", "string");
    ?>

#### What interesting data can be found in global memory?

##### List of installed plug-ins

Output a list of all installed plug-ins:

    <?php
    global $YANA;

    $array = $YANA->getVar("INSTALLED_PLUGINS");
    print_r($array);
    ?>

Output:

        Array
            (
                [CONFIG] => 1
                [DB_ADMIN] => 1
                [DEFAULT_LIBRARY] => 1
                [GUESTBOOK] => 1
                [GUESTBOOK_ADMIN] => 1
                [USER] => 1
            )

Checking whether a particular plug-in is installed:

    <?php
    $bool = $YANA->getVar("INSTALLED_PLUGINS.MY_PLUGIN");
    if ($bool) {
        print "Plug-in 'MY_PLUGIN' found.";
    } else {
        print "Plug-in 'MY_PLUGIN' not found.";
    }

    /* alternative notation */
    $YANA->plugins->isInstalled('MY_PLUGIN');
    ?>

##### Current profile settings

The "Web site profile" is selected by using the URL-parameter "id". Each profile can have individual settings. These settings are also available via the global memory. If no profile is selected, the profile "default" will be used. In fact, as a programmer you don't need to care which one actually is selected. All you need to know is, that profile data contains settings like the background color of the page, preferred font family and other interesting data, which you can access when necessary.

    <?php
    global $YANA;

    /* read current profile settings */
    $array = $YANA->getVar("PROFILE");
    print_r($array);
    ?>

Output:

    Array
    (

    >> Web site layout

        [BGCOLOR] => #F0F0F0
        [PFONT] => Arial, Helvetica, sans-serif
        [BGIMAGE] =>
        [LOGO] =>
        [HSIZE] =>
        [HCOLOR] =>
        [HFONT] =>
        [PSIZE] =>
        [PCOLOR] =>

    >> Selected language, skin and directory for emoticons / Smilies

        [LANGUAGE] => english.config
        [SKIN] => default.config
        [SMILEYDIR] => common_files/smilies/

    >> Other options

        [USERMODE] => 1
        [AUTO] => 1
        [TIMEFORMAT] => 0

    >> Logging

        [LOGGING] => 1
        [LOG_LENGTH] => 50

    >> Settings for plug-in "rss to html factory"

        [RSS] => Array
            (
                [FILE] => plugins/rss/test.rss
                [MAX] => 5
            )

    >> Settings for plug-in 'guestbook'

        [GUESTBOOK] => Array
            (
                [NOREPLY] => noReply@meineAdresse.tld
                [FLOODING] => 0
                [ENTPERPAGE] => 5
                [NOTIFICATION] =>
                [SENDMAIL] =>
                [MAIL] => myName@domain.tld
                [FILE] =>
                [SPAMPROTECT] => 1
                [PROFILE] =>
                [USE_DB] =>
            )

    >> Settings for plug-in "search"

        [SEARCH] => Array
            (
                [TARGET] => _self
            )

    >> Settings for plug-in "user_admin" (user management)

        [USER] => Array
            (
                [ALLOW_CREATE] => 0
            )

    )

    <?php
    /* read the selected background color */
    $string = $YANA->getVar("PROFILE.BGCOLOR");
    print '<p style="background-color: '.$string.'">test</p>';
    ?>

##### Default settings

    <?php
    global $YANA;

    /* read YANA default settings */
    $array = $YANA->getVar("DEFAULT");
    print_r($a);
    ?>

Output:

        Array
            (

    >> Determines what action should be called automatically when the
       Argument "action" is empty or not set.
       Default is "sitemap" - but you may use something other, eg. "guestbook_read_read"
       to start the guestbook, or "search_start" for the search engine.
       This setting was introduced in version 2.8.0

                [HOMEPAGE] => sitemap

    >> Determines whether text messages (errors, notes, etc.) are viewed in a separate window (true)
       or in the text of the current page (false).
       This setting was introduced in version 2.8.2

                [MESSAGE] => false

    >> Default event configuration for events that are not defined

                [EVENT] => Array
                    (
                        [TYPE] => default
                        [MODE] => 0
                        [PERMISSION] => 0
                        [TEMPLATE] => index
                        [INSERT] =>
                    )

    >> Default interface configuration

                [INTERFACE] => Array
                    (
                        [TEST] => Array
                            (
                                [TYPE] => private
                                [MODE] => 0
                                [PERMISSION] => 0
                                [TEMPLATE] => NULL
                            )

                    )

    >> Default skin configuration

                [SKIN] => Array
                    (
                        [DIRECTORY] => default/
                    )

    >> Default language configuration

                [LANGUAGE] => Array
                    (
                        [DIRECTORY] => en/
                    )

    >> Default for database connections

                [DATABASE] => Array
                    (
                        [DSN] => Array
                            (
                                [USE_ODBC] =>
                                [DBMS] => mysql
                                [HOST] => localhost
                                [PORT] => 0
                                [USERNAME] => root
                                [PASSWORD] =>
                                [DATABASE] => yana
                            )

    >> Configuration of the database interface

                        [OPTIONS] => Array
                            (
                                [AUTOFREE] => 1
                                [PERSISTENT] => 1
                                [SSL] =>
                            )

    >> List of DBMS, which may be addressed via the ODBC interface

                        [REQUIRE_ODBC] => Array
                            (
                                [0] => db2
                                [1] => access
                            )

                    )

            )

##### User Information

    <?php
    global $YANA;

    /* User IP */
    print $YANA->getVar("REMOTE_ADDR")."\n";
    /* User name */
    print $YANA->getVar("SESSION_USER_ID")."\n";
    /* access restriction of users */
    print $YANA->getVar("PERMISSION")."\n";
    /* Session name */
    print $YANA->getVar("SESSION_NAME")."\n";
    /* Session id */
    print $YANA->getVar("SESSION_ID")."\n";
    ?>

    Output:
    127.0.0.1
    ADMINISTRATOR
    100
    YSID
    480f97e69eae2311d3157cc3377a2d73

Logging and error messages Index Using a CAPTCHA

Thomas Meyer, www.yanaframework.net