Thread: [Phpcms-plugins-cvs] lexiword lexiword.php,1.2,1.3
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2005-02-09 15:28:33
|
Update of /cvsroot/phpcms-plugins/lexiword In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32127 Modified Files: lexiword.php Log Message: preparation for the release of Version 1.0 in english Index: lexiword.php =================================================================== RCS file: /cvsroot/phpcms-plugins/lexiword/lexiword.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- lexiword.php 27 Jul 2004 13:14:54 -0000 1.2 +++ lexiword.php 9 Feb 2005 15:28:20 -0000 1.3 @@ -1,132 +1,118 @@ <?php /** -* LexiWord - Plugin für phpCMS -* -* @author: Martin Jahn <mj...@us...> -* @license: GPL -* @version: $Id$ -* @package lexiword -* -* Das Plugin erkennt in einer Contentdatei alle vorkommenden Begriffe aus einer Glossardatei. -* Diese Begriffe werden dann markiert und werden im Broswer mit Kurzbeschreibungen angezeigt -* werden. Die Glossardatei kann darueber hinaus auch als normale Contentdatei verwendet werden. -* Damit ist es auch moeglich die Begriffe mit Links zur Glossardatei zu versehen. -* -* Dieses Plugin/Skript veroeffentliche ich so wie es ist und gebe deshalb auch keinerlei Garantie, -* dass es richtig funktioniert. Ausserdem uebernehme ich keinerlei Haftung fuer eventuelle durch -* die Anwendung des Plugins/Skriptes entstehenden Schaeden. -* -* Falls du Verbesserungsvorschlaege oder Wuensche bezueglich des Skriptes hast melde dich bei -* Martin Jahn <ma...@ma...> -* -* Viel Spass -* -* Dieses Script ist kostenlos für private und kommerzielle Nuzung. -* Es wird unter den Bedingungen der GNU General Public License, wie von der Free -* Software Foundation herausgegeben, verteilt. Eine Kopie der GPL sollte im Zip-File -* enthalten sein. Das Script darf (im Rahmen der GPL) nach belieben genutzt, weiter- -* gegeben und modifiziert werden. Dieser Copyright-Hinweis muss jedoch in jedem Fall -* unverändert im Script belassen werden. -* -* Ich übernehme keinerlei Verantwortung für Schäden, die durch die Nutzung dieses -* Scripts entstehen. Bei Fehlern würde ich jedoch gerne informiert werden, damit -* ich diese ausbügeln kann. Auch für den Fall, dass Ihr Verbesserungen vornehmt, -* Verbesserungsvorschläge oder -wünsche habt, wäre ich dankbar für eine Benachrichtigung. -* -* -* Anleitung: -* -* 1. Das Plugin wird in einer Templatedatei statisch eingebunden -* {PLUGIN FILE="$plugindir/lexiword.php" TYPE="STATIC"} -* -* 2. Der Pfad zur Glossardatei wird relativ zum Document-Root angepasst -* -* 3. In das Array $fields alle Contentfelder eintragen, die durchsucht werden sollen -* -* 4. Eventuell noch weitere Einstellungen tunen -* -* 5. Fertig ;-) Gucken ob es funktioniert :-) -**/ + * Lexiword v1.0 + * + * LexiWord is a glossary plugin for phpCMs driven websites. It extracts the + * glossary out of a fromatted glossary-file, that also can be used as a normal + * contentfile. + * + * With the glossary it marks all found words in the specified contentfields + * with a special markup (i.e. <acronym title="..">... + * </acroym>. The format of the glossaryfile is free to define, but the default + * is: + * <dl> + * <dt>Glossary term</dt><dd>Description of the Glossary term</dd><dd>http: + * //optionional.link.to/a/site/for/this/term.htm</dd> ... next glossary entry + * ... + * </dl> + * + * <b>Installation</b> + * + * Integrate lexiword with {PLUGIN FILE="$plugindir/lexiword/lexiword.php" + * TYPE=" STATIC"} in your template. + * + * <b>Configuration</b> + * + * Open this file in your favourite text-editor and adjust the settings to your + * needs. + * + * That's all. I wish U much fun with lexiword and phpCMS + * + * <b>License</b> + * + * This program 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. + * + * This program 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. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + * + * @author Martin Jahn <mj...@us...> + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + * @copyright Copyright (c) 2005, Martin Jahn + * @version: $Id$ + * @package lexiword + * @todo Worterkennung (Luxus waere ja eine "Endungserkennung", die sieht, ob + * der Rest des Wortes eine Endung oder mehr ist *g*) + * @todo singular/plural- Erkennung... ;-) + * @todo Bindestriche gelten als Trenner zwischen zwei Worten + * @todo Quotes und Klammern + */ /* * $Log$ -* Revision 1.2 2004/07/27 13:14:54 mjahn -* fixed some little bugs +* Revision 1.3 2005/02/09 15:28:20 mjahn +* preparation for the release of Version 1.0 in english * */ /** -* 2004-07-27 -* Bugfix: -* Links werden nun richtig ersetzt -* Suchbegriffe können nun auch Leerzeichen beinhalten. -* -* 2004-04-19 -* Bugfix: -* Die Begriffe wurden bisher mit der Schreibweise ersetzt, -* wie sie in der Glossardatei steht. Ab sofort wird die Schreibweise -* so beibehalten, wie sie vorgefunden wird -**/ - - - -/** -* Pfad zur Contentdatei mit den Glossareinträgen -* -* Diese Datei muß _keine_ Contentdatei sein, kann aber so auch gleich -* als Glossar mit angezeigt werden. -* -* !!!! ACHTUNG !!!! Pfadangabe relativ zum __Document-Root__ !!! -**/ + * @var string path to the glossary-file + * + * This file must not be a contentfile, but you may use it as glossary-index. + * Take care of the path! It must be given as path from the document-root to the + * file + */ $lexifile = '/hilfe/glossar.htm'; /** -* true = nur ganze Wörter ersetzen -* false = Begriffe auch in zusammengesetzten Wörtern ersetzen -**/ + * @var boolean flag for matching words and word combinations + * + * true = only match single words + * false = match words in word combination + */ $match_only_whole_words = true; /** -* Contentfelder, die durchsucht werden sollen -**/ -$fields = array('KOLUMNE', 'CONTENT1', 'CONTENT2', 'CONTENT', 'FOOTER'); + * @var array contentfields you want to search + */ +$fields = array('CONTENT'); /** -* dieser Ausdruck wird an Stelle des gefundenen Begriffes eingesetzt -* -* folgende Platzhalter können darin verwendet werden: -* %name - der ursprüngliche Text, der ersetzt wird -* %desc - der beschreibende Text aus dem Glossar -**/ + * @var string replace found terms with the following (you may use %name for the + * replaced glossary term and %desc for the term description) + */ //$format = '<a href="#" class="info">%name<span>%desc</span></a>'; $format = '<acronym title="%desc">%name</acronym>'; /** -* dieser Ausdruck wird an Stelle des gefundenen Begriffes eingesetzt, -* wenn auch ein korrespondierender Link gefunden wird -* -* folgende Platzhalter können darin verwendet werden: -* %name - der ursprüngliche Text, der ersetzt wird -* %link - der ursprüngliche Text, der ersetzt wird -* %desc - der beschreibende Text aus dem Glossar -**/ + * @var string replace found terms with the following, if the optional link + * in the glossary file is available (you may use %name for the replaced + * glossary term, %desc for the term description and %link for the optional + * link-url) + */ //$formatlink = '<a href="%link" class="info">%name<span>%desc</span></a>'; $formatlink = '<a href="%link" title="%desc">%name</a>'; /** -* Mit dieser Variaben werden HTML-Tags ausgeschlossen, in denen nicht ersetzt werden soll. -* Sinnvoll ist dies zum Beispiel beim a-Tag, wenn dort ein Link ersetzt werden würde, oder -* der code-Tag, damit in Code-Ausdrücken keine acronym's rumflattern. -* -* Die Namen der Tags müssen mit | getrennt werden. -**/ -$ignoreTags = 'a|link|q|code|h2'; - -/* -############################################## -## Ab hier ist nichts mehr konfigurierbar ## -############################################## +* @var string all tags that content should be ignored by lexiword must be +* concatenated with the '|' (pipe-symbol) in this string +* +* Useful to prevent from replacing a term with a link inside an a-tag or to +* prevent replacing inside the code-tag */ +$ignoreTags = 'a|link|q|code|h2|h1|button|textarea'; + +///////////////////////////////////////////////////////////////////////// +//Do not change any line beyond thsi line, unless you know what you do // +///////////////////////////////////////////////////////////////////////// if (isset($DEFAULTS->EDIT)) { /** * do nothing in EDIT-mode @@ -138,35 +124,34 @@ return; } /** -* Glossardatei einlesen und ein assoziatives Array erstellen +* parse the glossary-file into an assoziative array */ if (file_exists($_SERVER['DOCUMENT_ROOT'].$lexifile)) { $lexikon = join('',file($_SERVER['DOCUMENT_ROOT'].$lexifile)); $lexikon = str_replace("\n",'',$lexikon); /** - * Extrahieren der Glossareinträge + * Extrahieren der Glossareintr�ge * * eventuell an eigene Formatierungen in der Glossardatei anpassen */ preg_match_all('$<dt>(.*?)</dt>\s*?<dd>(.*?)</dd>(\s*?<dd>.*?([http://|mailto:|ftp://]+://[^\s<>"]+).*?</dd>)*$sm',$lexikon,$entries); - echo '<!--'; - print_r($entries); - echo '-->'; + +// echo '<!--';print_r($entries);echo '-->'; /** * $entries ist ein Array * - * - Element 0 beinhaltet die kompletten Glossareinträge + * - Element 0 beinhaltet die kompletten Glossareintr�ge * - Element 1 beinhaltet die Glossarbegriffe * - Element 2 beinhaltet die Glossarbeschreibungen * - Element 3 beinhaltet das fakultative 2. Element mit dem Link * - Element 4 beinhaltet die URI des Links */ - $replace = array(); // beinhaltet die Beschreibungen + $replace = array(); // contains the descriptions $search = array(); $max = count($entries[1]); /** - * erstelle die Arrays für Suchen und Ersetzen + * erstelle die Arrays f�r Suchen und Ersetzen */ for ($i = 0; $i<$max; $i++) { $search[] = trim($entries[1][$i]); @@ -182,7 +167,7 @@ if (isset($PageContent->{$field})) { $content = join('',$PageContent->{$field}); - // Ersetze die phpcms-Variablen, so daß sie in der RegEx wegen /e nicht mit ausgewertet werden + // replace the phpCMS-variables, so that they do not interfere with the RegExp $phpcms_vars = array('$home'=>'%%home%%', '$self'=>'%%self%%', '$plugindir'=>'%%plugindir%%'); reset($phpcms_vars); @@ -194,18 +179,18 @@ for ($i=0; $i<$max; $i++) { $s = str_replace (' ', '\s', $search[$i]); $r = $replace[$i]; - /* Auslesen des Textes aus dem Contentfeld */ + // replace the tags in the contentfield if ($match_only_whole_words) { // $content = preg_replace("/((<[^>]*)|\b$s\b)/ex", '"\2"=="\1"? "\1":$r', $content); - $content = preg_replace("§((<(".$ignoreTags.")[^>]*>.*?($s).*?</\\3>)|(<[^>]*)|(\b$s\b))§iex", '("\4"!="\1") && "\6"=="\1" ? str_replace("%name", "\1", $r) : "\1"', $content); + $content = preg_replace("/((<(".$ignoreTags.")[^>]*>.*?($s).*?<\/\\3>)|(<[^>]*)|(\b$s\b))/iex", '("\4"!="\1") && "\6"=="\1" ? str_replace("%name", "\1", $r) : "\1"', $content); } else { // $content = preg_replace("/((<[^>]*)|$s)/ex", '"\2"=="\1"? "\1":$r', $content); - $content = preg_replace("§((<(".$ignoreTags.")[^>]*>.*?($s).*?</\\3>)|(<[^>]*)|($s))§iex", '("\4"!="\1") && "\6"=="\1" ? str_replace("%name", "\1", $r) : "\1"', $content); + $content = preg_replace("/((<(".$ignoreTags.")[^>]*>.*?($s).*?<\/\\3>)|(<[^>]*)|($s))/iex", '("\4"!="\1") && "\6"=="\1" ? str_replace("%name", "\1", $r) : "\1"', $content); } $content = stripslashes($content); } } - // Mache die Variablenersetzung rückgängig + // rereplace the phpCMs-variables reset($phpcms_vars); foreach ($phpcms_vars as $id=>$wert) { $content = str_replace($wert, $id, $content); @@ -220,13 +205,4 @@ **/ unset ($content, $entries, $field, $fields, $format, $formatlink, $i, $id, $item, $lexifile, $lexikon, $match_only_whole_words, $max, $phpcms_vars, $r, $replace, $s, $search, $wert); -/** -* TODO -* -* Worterkennung -* Luxus wäre ja eine "Endungserkennung", die sieht, ob der Rest des Wortes eine Endung oder mehr ist *g* -* klar singular/plural-Erkennung... ;-) -* plus: Bindestriche gelten als Trenner zwischen zwei Worten... -* Quotes und Klammern dito... -**/ ?> \ No newline at end of file |