Tag in site structure

This RT is to show how with can the help of tags in the page structure, the output of the pages can be influenced.

Assumed problem:

In each of the four seasons is a special CSS files are loaded. In addition to the template, depending on the terminated season e.g., another image is being loaded.



Procedure:

In the site structure in the field “category infotext” by “HOME” (ie ID = 0) is entered a tag which controls the behavior of the RT in /frontend_render/ , e.g.

[JAHRESZEITEN] #Tag1, #Tag2, Tag3, #Tag4,...[/JAHRESZEITEN]

The wrapper [JAHRESZEITEN] separates the tags from the remaining entries in this field.
Not valid tags are simply disabled by using a leading #. (In the above example the tag Tag3 is active).

<note> Attention, with the next update please ensure that the file config/phpwcms/conf.indexpage.inc.php is previously backed up and after the update compared with the new one. (This is the special case HOME)
Incidentally, the file can be edited via FTP to change the tags 8-) :!: </note>

In the RT, the appropriate tags are also entered, such as (in active state so without adding #)

$my_tags = 'fruehling, sommer, herbst, winter';

On these tags registered here the field “category infotext” is examined. The field is investigated for this entered tags. At the first match, this matched tag is used and processed. There is only one valid tag.

Replace css file:

A new CSS file is loaded, depending on the day. In order not to change the load sequence of the CSS files, a dummy or a fallback CSS file is created in template/inc_css/* and in the correct place in the template involved.

This CSS file is exactly replaced by the RT at this point. The RT is marked with the name of the CSS file to be swapped:

$my_css  = 'master_template.css';

Attention: note Upper/lower case!

The name of the exchanged CSS file is equal to the name of the tag, e.g.

Tag = sommerCSS-Datei = specific/sommer.css (The replacement CSS files are located in the directory template/inc_css/specific/)

The result is visible here:

No active tag:


The tag “Winter” is active:


Meta-text for “description” if “Home” is active (ID=0 alias=index)


Replace content:

Of course, it is also possible to share certain content.

In the lower section of the script V1.1 are shown some examples (Custom Functions).

Bsp01.: direct replacement in the template/content direktes ersetzen im Template/Content * The php function str_replace('Suchmuster', 'wird ersetzt durch', 'zu durchsuchender Inhalt'); is used.
$content['all'] = str_replace('Suchmich Wort',Tolles Wort', $content['all']);


Bsp02.: Replace with wrapper in template/Content

In template/content we see e.g.: “Jetzt [SEASON]im Jahr ist es farbig[/SEASON].”

  • With the help of the built-in-funtion replace_cnt_template('crawler content', 'TAG', 'is replaced by'); it can quite easily be implemented.
    $content['all'] = replace_cnt_template($content['all'], SEASON, 'im Winter ist es weiß');


Bsp03.: Replacing with tag {TAG} in template/content

In template/content we see e.g.: “Jetzt ist der {SEASON} da.”

  • As noted above, here the php function str_replace(…); used.
    $content['all'] = str_replace('{SEASON}', 'Winter', $content['all']);


The safe side now needs to be examined whether there are wrapped-snippets are present in the content (This happens for example if no TAG is true ).

In addition we must have a look to the pre-setting (fallback) like e.g., {ERSETZE}. If no tag from our list matches, a default value must be registered here.

  • $content['all'] = str_replace('{ERSETZE}', 'default value', $content['all']);


Code:

rt_tag_in_site_structure V1.0 26.11.09

Docu: –
Forum: http://forum.phpwcms.org/viewtopic.php?p=121111

Autor: K.Heermann (flip-flop) http://planmatrix.de
CMS Version: >= 1.3
Version: V1.0

Tag: –

Filename: rt_tag_in_site_structure.php

Folder: template/inc_script/frontend_render/

Condition:/config/phpwcms/conf.inc.php

  • $phpwcms['allow_ext_render'] = 1;




V 1.0:

rt_tag_in_site_structure

<?php
/**
 * 26.11.09 KH (flip-flop) tags in site structure "category infotext"
 * This RT is to show how with can the help of tags in the page structure, the output of the pages can be influenced.
 *
 * Usage: sample Replacement Tag
 *
 * in the field "category infotext" in site structure (in this example we uses
 * the category HOME)
 *
 * Tag:
 * -> [JAHRESZEITEN]#Fruehling, #Sommer, #Herbst, Winter[/JAHRESZEITEN]
 *    (We trigger on "Winter", there is no # in front)
 *
 * Meta descrition if you want:
 * -> My descrition text for home
 *
 * Corresponding tags/entries in this rt:
 * -> $my_tags = 'FRUEHLING, SOMMER, HERBST, WINTER';
 *
 * encloser:
 * -> $enclose = 'JAHRESZEITEN';
 *
 * dummy/fallback css filename:
 * -> $my_css  = 'master_template.css';
 *
 **/
 
// ----------------------------------------------------------------
// OBLIGATE CHECK FOR PHPWCMS CONSTANTS
if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
// ----------------------------------------------------------------
 
 
// ist im Feld Beschreibung der Seitenebene" etwas vorhanden?
if (!empty($content["struct"][0]['acat_info']))
{
    // ===== Usereingabe =====================================
        // Vorgabe: Tags eintragen, wie im Infofeld
 
        $enclose = 'JAHRESZEITEN';                        // Umschlieszer
        $my_tags = 'fruehling, sommer, herbst, winter';    // Die Tags
        $my_css  = 'master_template.css';                 // Name der Dummy-CSS Datei bzw.
                                                        // Fallback Datei die ersetzt wird
    // ===== ENDE Usereingabe ================================
 
 
    // Tags abholen aus "HOME" ID=0
    $info = returntagcontent($content["struct"][0]['acat_info'], $enclose);
 
    // irgendeine Tagansammlung vorhanden?
    if ( !empty($info['tag']) )
    {
        $be_tags = explode(',',$info['tag']);    // BE-Tags holen
        $my_tags = strtolower($my_tags);        // normieren
        $tag = '';                                // Hier wird der Tag festgehalten
 
 
        // Vergleich ob ein Tag aus dem BE in der Vorgabe enthalten ist
        foreach ($be_tags as $key => $value)
        {
            $be_tags[$key] = strtolower(trim($value));            // normieren
 
            if (strpos($my_tags, $be_tags[$key]) != false) {     // Tag gefunden
                $tag = $be_tags[$key];
                break;                                            // foreach Abbruch da gefunden
            }
        }
 
 
        // Custom Funktionen, wie CSS austauschen oder Teile im  Template ersetzen
        // =============================================================
        if ( !empty($tag) )
        {
            // wenn Tag vorhanden, dann z.B. Dummy/Fallback-css austauschen
            // die Position in der Reihenfolge der Dateien bleibt eralten
            // -------------------------------------------------------
            $key = array_search($my_css, $block['css']);
            if ($key) $block['css'][$key] = 'specific/'.$tag.'.css';
 
 
            // Ersetzer im Template
            // -------------------------------------------------------
            if ($tag == 'winter') // wenn "winter" dann mache folgendes:
            {
                $content['all'] =
                str_replace('{RANDOM:templates/header-random/normal}',
                            '{RANDOM:templates/free_XL/header-random/weihnachten}',
                            $content['all']);
            }
        }
 
 
        // Das ganze getagge löschen, wenn "Beschreibung der Seitenebene" fuer die description gebraucht
        // ==============================================================================================
        $content["struct"][0]['acat_info'] = replace_cnt_template($content["struct"][0]['acat_info'], $enclose, '');
        $content["struct"][0]['acat_info'] = trim($content["struct"][0]['acat_info']);
 
    }
}
 
?>


V1.1: Exemplary extended by several Replacer for the content (See section “Custom Functions”).

rt_tag_in_site_structure

<?php
/**
 * 26.11.09 KH (flip-flop) tags in site structure "category infotext"
 * This RT is to show how with can the help of tags in the page structure, the output of the pages can be influenced.
 * V1.1
 *
 * Usage: sample Replacement Tag
 *
 * in the field "category infotext" in site structure (in this example we uses
 * the category HOME)
 *
 * Tag:
 * -> [JAHRESZEITEN]#Fruehling, #Sommer, #Herbst, Winter[/JAHRESZEITEN]
 *    (We trigger on "Winter", there is no # in front)
 *
 * Meta descrition if you want:
 * -> My descrition text for home
 *
 * Corresponding tags/entries in this rt:
 * -> $my_tags = 'FRUEHLING, SOMMER, HERBST, WINTER';
 *
 * encloser:
 * -> $enclose = 'JAHRESZEITEN';
 *
 * dummy/fallback css filename:
 * -> $my_css  = 'master_template.css';
 *
 **/
 
// ----------------------------------------------------------------
// OBLIGATE CHECK FOR PHPWCMS CONSTANTS
if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
// ----------------------------------------------------------------
 
 
// ist im Feld Beschreibung der Seitenebene" etwas vorhanden?
if (!empty($content["struct"][0]['acat_info']))
{
    // ===== Usereingabe =====================================
        // Vorgabe: Tags eintragen, wie im Infofeld
 
        $enclose = 'JAHRESZEITEN';                        // Umschlieszer
        $my_tags = 'fruehling, sommer, herbst, winter';    // Die Tags
        $my_css  = 'master_template.css';                 // Name der Dummy-CSS Datei bzw.
                                                        // Fallback Datei die ersetzt wird
    // ===== ENDE Usereingabe ================================
 
 
    // Tags abholen aus "HOME" ID=0
    $info = returntagcontent($content["struct"][0]['acat_info'], $enclose);
 
    // irgendeine Tagansammlung vorhanden?
    if ( !empty($info['tag']) )
    {
        $be_tags = explode(',',$info['tag']);    // BE-Tags holen
        $my_tags = strtolower($my_tags);        // normieren
        $tag = '';                                // Hier wird der Tag festgehalten
 
 
        // Vergleich ob ein Tag aus dem BE in der Vorgabe enthalten ist
        foreach ($be_tags as $key => $value)
        {
            $be_tags[$key] = strtolower(trim($value));            // normieren
 
            if (strpos($my_tags, $be_tags[$key]) != false) {     // Tag gefunden
                $tag = $be_tags[$key];
                break;                                            // foreach Abbruch da gefunden
            }
        }
 
        // ====================================================================
        // Custom Funktionen, wie CSS austauschen oder
        // Teile im  Template/Content ersetzen
        // ====================================================================
 
        // TAG ueberhaupt vorhanden und TAG in unserer Menge enthalten?
        if ( (!empty($tag)) AND (strpos($my_tags, $tag) != false) )
        {
            // wenn Tag vorhanden, dann z.B. Dummy/Fallback-css austauschen
            // die Position in der Reihenfolge der Dateien bleibt eralten
            // -------------------------------------------------------
            $key = array_search($my_css, $block['css']);
            if ($key) $block['css'][$key] = 'specific/'.$tag.'.css';
            // -------------------------------------------------------
 
            // -------------------------------------------------------
            // Bsp01.: direktes ersetzen im Template/Content
            // -------------------------------------------------------
            if ($tag == 'winter') // wenn "winter" dann mache folgendes:
            {
                $content['all'] =
                str_replace('{RANDOM:templates/header-random/normal}',
                            '{RANDOM:templates/free_XL/header-random/weihnachten}',
                            $content['all']);
            }
            // -------------------------------------------------------
            // Bsp02.: Ersetzen mit Umschlieszer (wrapper) im Template/Content
            // In der Vorlage/Content z.B.:
            // "Jetzt [SEASON]im Jahr ist es farbig[/SEASON]."
            // -------------------------------------------------------
 
            switch($tag) {
 
                // Verwendet wird die Funktion:
                // replace_cnt_template($text='', $tag='', $value='');
 
                case 'winter':
                    $content['all'] =
                    replace_cnt_template($content['all'], SEASON, 'im Winter ist es weiß');
                    break;
 
                case 'fruehling':
                    $content['all'] =
                    replace_cnt_template($content['all'], SEASON, 'im Fr&uuml;hling ist es gr&uuml;n');
                    break;
 
                case 'sommer':
                    $content['all'] =
                    replace_cnt_template($content['all'], SEASON, 'im Sommer ist es gelb');
                    break;
 
                case 'herbst':
                    $content['all'] =
                    replace_cnt_template($content['all'], SEASON, 'im Herbst ist es braun');
                    break;
 
            }
 
            // -------------------------------------------------------
            // Bsp03.: Ersetzen mit Tag {TAG} im Template/Content
            // In der Vorlage/Content z.B.:
            // "Jetzt ist der {SEASON} da."
            // -------------------------------------------------------
 
            switch($tag) {
 
                case 'winter':
                    $content['all'] = str_replace('{SEASON}', 'Winter', $content['all']);
 
                case 'fruehling':
                    $content['all'] = str_replace('{SEASON}', 'Fr&uuml;hling', $content['all']);
 
 
                case 'sommer':
                    $content['all'] = str_replace('{SEASON}', 'Sommer', $content['all']);
 
                case 'herbst':
                    $content['all'] = str_replace('{SEASON}', 'Herbst', $content['all']);
 
 
            }
            // -------------------------------------------------------
 
 
        } // ---ENDE if ( !empty($tag) ) -------------------------
 
 
 
        // All unsere [wrapper] und {Tags} in der Vorlage/Content loeschen,
        // wenn noch vorhanden   (wenn kein Tag gesetzt wurde)
        // und Fallback setzt bei {TAG}
        // --------------------------------------------------------------------
        $content['all'] = str_replace('{SEASON}', 'Regen', $content['all']);  // Fallback
        $content['all'] = preg_replace('/\[SEASON\](.*?)\[\/SEASON\]/is', '$1', $content['all']);
        // --------------------------------------------------------------------
 
 
        // Loeschen des ganze "Getagges" in der Struktuebene,
        // wenn "Beschreibung der Seitenebene" fuer die description gebraucht wird
        // ---------------------------------------------------------------------
        $content["struct"][0]['acat_info'] = replace_cnt_template($content["struct"][0]['acat_info'], $enclose, '');
        $content["struct"][0]['acat_info'] = trim($content["struct"][0]['acat_info']);
        // ---------------------------------------------------------------------
 
    }  // ---ENDE if ( !empty($info['tag']) ) -------------------------
 
}  // ---ENDE if (!empty($content["struct"][0]['acat_info'])) ----
 
 
?>


english/phpwcms_replacer_rts/frontend_render/tag-site-structure.txt · Last modified: 2018/06/03 18:09 (external edit)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0