// 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. '
'
- 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 = '
'; // 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'],'
'));
// 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 = ''.$inner.'';
}
}
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 $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']);
}
*/
}
?>
\\
==== Settings ====
* 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 = '
'; // Allowed TAGs /Erlaubte TAGs
// ========================================
\\
===== Usage =====
TAG: **%%[glossary KEY]Text[/glossary]%%** or **%%[[key##Text]]%%**
**Example:** \\
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:**
{{:deutsch:module:glossar:be_input01_1.gif|}}
E.g. in a Wysiwyg Contentpart:
... Lorem ipsum [[test02##dolor]] sit amet consectetuer leo Nulla ...
\\
==== Generated code ====
... Lorem ipsum dolor 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 ....)//.
\\
==== Output ====
With JavaScript [[deutsch/andere-erweiterungen/simpel-tooltip-abbr|JS-ToolTip]]
{{:deutsch:module:glossar:fe_output01_1.gif|}}
\\
Without JavaScript
{{:deutsch:module:glossar:fe_output02_1.gif|}}
\\
Without JavaScript and without HTML-TAGs //(Switched to off in the script)//.
{{:deutsch:module:glossar:fe_output03_1.gif|}}
\\