This is an old revision of the document!


Glossar TAG erweitert

  • Der voreingestellt TAG [glossary KEY]Text[/glossary] wird ergänzt um die kürzere Variante [[key##Text]].
  • Im Script ist einstellbar, welche HTML-TAGs für die Formatierung per JS im “title” zugelassen werden.



V1.0 24.08.2011

Docu: –
Forum: –

Autor: K.Heermann (flip-flop) http://planmatrix.de

CMS Version: >= 1.3
Version: V1.0

Tag: [glossary KEY]Text[/glossary] und [[key##Text]]

Dateiname: frontend.render.php

Verzeichnis: include/inc_module/mod_glossary/*

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

  • $phpwcms['allow_ext_render'] = 1;



Installation

Verzeichnis: /include/inc_module/mod_glossary/

  • Umbenennen der vorhandenen Datei frontend.render.php nach frontend.render.php_org
  • Kopieren/Erzeugen der u.a. Datei frontend.render.php in das o.g. Verzeichnis.

frontend.render.php

<?php
/*************************************************************************************
   Copyright notice
 
   (c) 2002-2011 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
 
   This script is part of PHPWCMS. The PHPWCMS web content management system is
   free software; you can redistribute it and/or modify it under the terms of
   the GNU General Public License as published by the Free Software Foundation;
   either version 2 of the License, or (at your option) any later version.
 
   The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
   A copy is found in the textfile GPL.txt and important notices to the license
   from the author is found in LICENSE.txt distributed with these scripts.
 
   This script is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
   PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 
   This copyright notice MUST APPEAR in all copies of the script!
 
   - [x] catch glossary keyword in frontend]
     - TAG default: [glossary KEY]Text[/glossary]
     - create ABBR
 
   Update KH 24.08.2011
   - New short TAG: [[key##Text]] for creating ABBR
   - Formatting is possible for tooltip JS
     - Allowed TAGs like e.g. '<br><p><b>'
     - JavaScript: Don´t filter allowed TAGs
*************************************************************************************/
 
// Module/Plug-in Glossary frontend_render script
// use it as when it is located under "template/inc_script/frontend_render"
 
if(!isset($content['glossary'])) {
 
    // used to store glossary keywords which has been found
    $content['glossary_cache'] = array();
 
 
    // + KH Added for "allowed TAGs
    function Xclean_slweg($string_wo_slashes_weg, $allowed_tags='', $string_laenge=0, $trim=true) {
 
        // Falls die Serverfunktion magic_quotes_gpc aktiviert ist, so
        // sollen die Slashes herausgenommen werden, anderenfalls nicht
        if($trim) $string_wo_slashes_weg = trim($string_wo_slashes_weg);
 
        if( get_magic_quotes_gpc() ) $string_wo_slashes_weg = stripslashes ($string_wo_slashes_weg);
        $string_wo_slashes_weg = strip_tags($string_wo_slashes_weg, $allowed_tags );
 
        if($string_laenge) $string_wo_slashes_weg = substr($string_wo_slashes_weg, 0, $string_laenge);
 
        return $string_wo_slashes_weg;
    }
 
 
    function replace_glossary_tag($matches) {
 
        global $content;
 
        // ==== CUSTOM VAR ========================
        $js             = true;                        // JavaScript: Don´t filter allowed TAGs / Erlaubte TAGs nicht filtern
        $allowed_tags     = '<br><p><b><strong>';        // Allowed TAGs /Erlaubte TAGs
        // ========================================
 
        $inner = trim($matches[2]);
 
        // search keyword in glossary table
        $keyword = trim($matches[1]);
        if($keyword !== '') {
            $keyword = html_entity_decode($keyword, ENT_QUOTES, PHPWCMS_CHARSET);
 
            // check against cache
            if(!isset($content['glossary_cache'][$keyword])) {
 
                $like = aporeplace($keyword);
 
                $where  = 'glossary_status=1 AND glossary_highlight=1 AND (';
                $where .= "glossary_keyword LIKE '".$like."' OR ";
                $where .= "glossary_keyword LIKE '".$like.",%' OR ";
                $where .= "glossary_keyword LIKE '%, ".$like.",%' OR ";
                $where .= "glossary_keyword LIKE '%, ".$like."'";
                $where .= ')';
 
                // retrieve only single keyword that matches best
                $entry  = _dbGet('phpwcms_glossary', 'glossary_title, glossary_keyword, glossary_text, COUNT(glossary_id) AS count_all', $where, 'glossary_id', 'count_all DESC', '1');
 
                if(isset($entry[0])) {
 
                    // get keywords to store each in cache
                    $keywords    = convertStringToArray($entry[0]['glossary_keyword']);
                    $title        = empty($entry[0]['glossary_title']) ? $inner : html_specialchars($entry[0]['glossary_title']);
                    if (!$js)
                        $text        = trim(clean_slweg($entry[0]['glossary_text']));
                    else
                        $text = trim(Xclean_slweg($entry[0]['glossary_text'],'<br><p><b><strong>'));
 
                    // store glossary item in cache
                    foreach($keywords as $key) {
                        $content['glossary_cache'][$key] = array( 'title' => $title, 'text' => $text );
                    }
 
                }
            }
 
            // create ABBR
            if(isset($content['glossary_cache'][$keyword])) {
 
                $inner =    '<abbr class="glossary" title="'.$content['glossary_cache'][$keyword]['title'].
                            ' :: '.
                            $content['glossary_cache'][$keyword]['text'].
                            '">'.$inner.'</abbr>';
            }
 
        }
        return $inner;
 
    }
 
    // Search for glossary tag
    // Default TAG: [glossary KEY]Text[/glossary]
    $content['all'] = preg_replace_callback('/\[glossary (.*?)\](.*?)\[\/glossary\]/i', 'replace_glossary_tag', $content['all']);
 
    // Alternative TAG: [[key#Text]]
    $content['all'] = preg_replace_callback('/\[\[(.*?)##(.*?)\]\]/i', 'replace_glossary_tag', $content['all']);
 
 
 
 
    /*
    $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_glossary WHERE ';
    $sql .= 'glossary_status=1 AND glossary_highlight=1 AND glossary_keyword != ""';
 
    $glossary['keywords'] = _dbGet('phpwcms_glossary', );
 
    if($glossary['keywords'] !== false && is_array($glossary['keywords']) && count($glossary['keywords'])) {
 
        // OK - fine we have found all glossary words
 
        $glossary['tags'] = array();
 
        foreach($glossary['keywords'] as $value) {
            $value['glossary_tag'] = convertStringToArray(strtolower($value['glossary_tag']), ' ');
            foreach($value['glossary_tag'] as $value) {
                $glossary['tags'][$value] = $value;
            }
        }
 
        // now lets search for glossary content parts
        $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_articlecontent ac ';
        $sql .= 'LEFT JOIN '.DB_PREPEND.'phpwcms_article ar ON ac.acontent_aid = ar.article_id ';
        $sql .= 'WHERE ar.article_public=1 AND ar.article_aktiv=1 AND ';
        $sql .= 'ar.article_deleted=0 AND ar.article_begin<NOW() AND ';
        $sql .= 'ar.article_end>NOW() AND ac.acontent_visible = 1 AND ac.acontent_module = "glossary"';
 
        $glossary['cp'] = @_dbQuery($sql);
 
        if(is_array($glossary['cp']) && count($glossary['cp'])) {
 
            foreach($glossary['cp'] as $key => $value) {
 
                if(!isset($content['struct'][ $value['article_cid'] ])) {
                    unset($glossary['cp'][$key]);
                    continue;
                }
                $glossary['cp'][$key]['acontent_form'] = unserialize($value['acontent_form']);
                $glossary['cp'][$key]['acontent_form']['acontent_id']  = $value['acontent_id'];
                $glossary['cp'][$key]['acontent_form']['acontent_aid'] = $value['acontent_aid'];
                $glossary['cp'][$key]['acontent_form']['article_cid'] = $value['article_cid'];
 
                $glossary['cp'][$key] = $glossary['cp'][$key]['acontent_form'];
 
            }
 
        }
 
    //dumpVar($glossary['tags']);
    //dumpVar($glossary['cp']);
    //dumpVar($glossary['keywords']);
 
    }
 
    */
 
}
 
?>


Einstellungen

  • Wird JavaScript verwendet, also werden bestimmte HTML-TAGs im “title” erlaubt?
  • Erlaubte TAGs
        // ==== CUSTOM VAR ========================
        $js             = true;                        // JavaScript: Don´t filter allowed TAGs / Erlaubte TAGs nicht filtern
        $allowed_tags   = '<br><p><b><strong>';        // Allowed TAGs /Erlaubte TAGs
        // ========================================


Anwendung

TAG: [glossary KEY]Text[/glossary] oder [[key##Text]]

Beispiel:
Schlüssel: test02
Text: Text

Im Quelltext wird z.B. angegeben:

[[test02##Text]] oder [glossary test02]Text[/glossary]


Existiert im Glossar ein Schlüssel mit dem Wert “test02”, wird der dazugehörige Text aus dem Glossar in den “title”-TAG gesetzt.

Backend Glossar:

Z.B. in einem Wysiwyg Contentpart:

... Lorem ipsum [[test02##dolor]] sit amet consectetuer leo Nulla ...


Generierter Code:

... <p>Lorem ipsum <abbr class="glossary" title="Test02 :: &lt;p&gt;Dies ist ein &lt;strong&gt;Titeltext&lt;/strong&gt;&lt;br /&gt;
in zwei Zeilen.&lt;/p&gt;
&lt;p&gt;Ein neuer Absatzt.&lt;/p&gt;">dolor</abbr> sit amet consectetuer leo Nulla ...

Alle betreffenden Zeichen werden vom Script in Entities gewandelt und “title” in “tiptitle” umgeschrieben.

Ist nun JavaScript auf dem Client nicht eingeschaltet wird der Ursprungstext mit den HTML-Steuerzeichen ausgegeben.
Man muss sich also entscheiden, ob mit oder ohne Formatierung gearbeitet werden soll. Für die Formatierung muss JS auf dem Client eingeschaltet sein.

Dazu kommt noch, dass alle Bots natürlich den “title” mit den HTML-Steuerzeichen aufnehmen. In wie weit das ein Nachteil ist, kann ich nicht sagen.

Anmerkung: Es gibt keine wirklich zuverlässige Methode um mit PHP festzustellen ob JS auf dem Client ein- oder ausgeschaltet ist (Geht nur über Seitenweiterleitung per JS ….).


deutsch/module/glossar/glossar-tag-erweitert.1314195072.txt.gz · Last modified: 2018/06/03 18:07 (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