Glossar TAG enhanced

  • The default TAG [glossary KEY]Text[/glossary] is added to the shorter version [[key##Text]].
  • Certain HTML tags can be approved in the generated “title” text for an output with a JS-ToolTip.

V1.0 24.08.2011

Docu: –
Forum: –

Author: K.Heermann (flip-flop)

CMS Version: >= 1.3
Version: V1.0

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

Filename: frontend.render.php

Folder: include/inc_module/mod_glossary/*


  • $phpwcms['allow_ext_render'] = 1;


Folder: /include/inc_module/mod_glossary/

  • Rename the existing file frontend.render.php to frontend.render.php_org.
  • Copy/Create the file below named frontend.render.php in the above directory.


   Copyright notice
   (c) 2002-2011 Oliver Georgi <> // 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
   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']));
                        $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'].
                            ' :: '.
        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'] ])) {
                $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'];


  • JavaScript is used, so be certain HTML tags in the “title” allowed?
  • Allowed 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
        // ========================================


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

Key: test02
Text: Text

For example in the source code is given:

[[test02##Text]] or [glossary test02]Text[/glossary]

Exists in the glossary a key with the value “test02”, the original words from the glossary in the “title” tag is set.

Backend Glossar:

E.g. in a Wysiwyg Contentpart:

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

Generated 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 ...

All affected characters are converted by the script into entities and “title” in “tiptitle” rewritten.

If JavaScript is not enabled on the client, the original text with the HTML control character is output.
We must therefore decide whether to work with or without formatting. For formatting needs JS be turned on on the client.

In addition, all bots take the “title” with the HTML control characters. Whether it's a disadvantage, I can not say.

Note: There are no truly reliable method to determine with JS on the client whether PHP is turned on or off (Works only with side forward by JS ….).


With JavaScript JS-ToolTip

Without JavaScript

Without JavaScript and without HTML-TAGs (Switched to off in the script).

english/modules/glossar/glossar-tag-enhanced.txt · Last modified: 2018/06/03 18:09 (external edit) 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