[Phpcms-plugins-cvs] prev-next .project,NONE,1.1 prev-next.php,1.2,1.3
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2004-07-24 09:07:48
|
Update of /cvsroot/phpcms-plugins/prev-next In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26558 Modified Files: prev-next.php Added Files: .project Log Message: update for eclipse Index: prev-next.php =================================================================== RCS file: /cvsroot/phpcms-plugins/prev-next/prev-next.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- prev-next.php 19 May 2003 06:18:35 -0000 1.2 +++ prev-next.php 24 Jul 2004 09:07:39 -0000 1.3 @@ -1,117 +1,236 @@ -<? -/* - prev-next.php - Plugin für phpCMS +<?php +/** +* PrevNext - Plugin für phpCMS +* +* @author: Martin Jahn <ma...@ma...> +* @license: GPL +* @version: 0.2beta +* @package prevnext +* +* Das Skript erstellt auf der Basis des Menüs von phpCMS eine vor-zurück Navigation +* für die aktuelle Menüklasse. Dazu wird der aktuelle Menüpunkt und, wenn +* vorhanden, die vorhergehende und die darauf folgende Seite gesucht. +* +* Anschließend werden die Links per Tag-Ersetzung in deine phpCMS-Seite eingefügt. +* +* 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. +**/ - Das Skript erstellt auf der Basis des Menüs von phpCMS eine prev-next Navigation - für die aktuelle Menüklasse. Dazu wird der aktuelle Menüpunkt gesucht und dann wenn - vorhanden die vorhergehende und die darauf folgende Seite gesucht. +/** +* template for the links +* +* you may use all fieldnames you have defined in the menu-file with a leading % +* i.e. if you use MNAME in your menufile, you may use %MNAME in the template-declarations +* the active-parts are used, if the page exists +* the passiv-parts are used, if the page does not exist +**/ +$tpl['first']['active'] = '<a href="%LINK" title="%MNAME - %TEXT">|<</a>'; +$tpl['first']['passiv'] = '<span class="passiv">|<</span>'; +$tpl['prev']['active'] = '<a href="%LINK" title="%MNAME - %TEXT">«</a>'; +$tpl['prev']['passiv'] = '<span class="passiv">«</span>'; +$tpl['top']['active'] = '<a href="%LINK" title="%MNAME - %TEXT">^</a>'; +$tpl['top']['passiv'] = '<span class="passiv">^</span>'; +$tpl['next']['active'] = '<a href="%LINK" title="%MNAME - %TEXT">»</a>'; +$tpl['next']['passiv'] = '<span class="passiv">»</span>'; +$tpl['last']['active'] = '<a href="%LINK" title="%MNAME - %TEXT">>|</a>'; +$tpl['last']['passiv'] = '<span class="passiv">>|</span>'; - Anschließend werden die Links per Tag-Ersetzung in deine phpCMS-Seite eingefügt. - Autor: Martin Jahn (mja...@we...) +/** +* name of the tag to replace in the template-/content-file +**/ +$tag_id['first'] = '<phpcms:first />'; +$tag_id['prev'] = '<phpcms:prev />'; +$tag_id['top'] = '<phpcms:top />'; +$tag_id['next'] = '<phpcms:next />'; +$tag_id['last'] = '<phpcms:last />'; - Version: 0.1 / 02.02.2003 +/** +* recursion through the menu-levels +* +* value: number of levels for recursion +* 0: no recursion +* 1: one menu-level-recursion +* 2: two menu-level-recursion +**/ +$recursion = 0; - Homepage: http://martin.et-studium.de/ - eMail: ma...@et... - Copyright: Martin Jahn +/** +* add the new tags in before the existing tags? +**/ +$in_front = false; - 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, weitergegeben und - modifiziert werden. - Dieser Copyright-Hinweis muss jedoch in jedem Fall unverändert im Script be- - lassen werden. +/*************************************************** +** you may not change anything below this line, ** +** except if you knew, what you do ;) ** +***************************************************/ +$e = 0; +$m = 0; +$menues = 0; +$entries = 0; +$index = array(); +/** +* do nothing in phpCMS-EDIT-mode +**/ +if (isset($DEFAULTS->EDIT)) { + return; +} - 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. - Viel Spaß !!! +/** +* helper function for the template-engine +**/ +function ext_string(&$item, $key, $prefix) { + $item = $prefix.$item; +} - Martin -*/ -$dir_prev = '<<'; -$dir_next = '>>'; +/** +* iterating through the menu-array until we found the $page-name +**/ +function getMenuEntry($data = '') { + global $MENU; + if ($data == '') { + return false; + } + $menues = count ($MENU->menuFieldValues); + + for ($m = 0; $m < $menues; $m++) { + $entries = count ($MENU->menuFieldValues[$m]); + for ($e = 0; $e < $entries; $e++) { + if (in_array ($data, $MENU->menuFieldValues[$m][$e])) { + return array($m, $e, $entries); + } + } + } + return false; -$nolink = '%dir%'; -$link = '<link "%link%,_self,%name%">%dir%</link>'; -// Dateinamen der aktuellen Seite bestimmen -$page = $CHECK_PAGE->path."/".$CHECK_PAGE->name.$CHECK_PAGE->parms; +} -// Rekursiv in Unterverzeichnisse linken -// 0 -> gehe in der Menüdatei bis zum letzten Eintrag mit der URL -// 1 -> bleibe auf der ersten Menüebene, in der sich die aktuelle Seite befindet -// - zum Beispiel nützlich, wenn du im Haupt- und Untermenü die gleiche Seite zweimal drin stehen hast -// - bei 0 wird auf die Untermenüseite verlinkt -// - bei 1 wird auf die Hauptmenüseite verlinkt -$stop_at_first = 0; +/** +* Dateinamen der aktuellen Seite bestimmen +**/ +$page['LINK_PARAM'] = $CHECK_PAGE->path."/".$CHECK_PAGE->name.$CHECK_PAGE->parms; +$page['LINK'] = $CHECK_PAGE->path."/".$CHECK_PAGE->name; -// im Stealth-Mode noch den Parser vor den Link hängen -if ($GLOBALS['DEFAULTS']['STEALTH'] == 'off') { - $prelink = $GLOBALS['DEFAULTS']['SCRIPT_PATH'].'/'.$GLOBALS['DEFAULTS']['SCRIPT_NAME'].'?file='; +/** +* iterating through the menu-array until we found the $page-name +**/ +if (!($index['actual'] = getMenuEntry($page['LINK']))) { + $index['actual'] = getMenuEntry($page['LINK_PARAM']); } -// einzelne Menüklassen durchlaufen: MAIN, SUB1 .... -// Anzahl der Menüpunkte in der obersten Ebene -$x = count($GLOBALS['MENU']->menuFieldValues); -$stop = 0; +if (!$index['actual']) { + return; +} -for($xtmp=0; $xtmp<$x; $xtmp++) { +/** +* set data for first-page link +**/ +if ($index['actual'][1] > 0 && isset($MENU->menuFieldValues[$index['actual'][0]][0])) { + $index['first'] = array($index['actual'][0], 0); +} else { + $index['first'] = false; +} - // Anzahl der Menüpunkte in der zweiten Ebene - $y=count($GLOBALS['MENU']->menuFieldValues[$xtmp]); - for($ytmp=0; $ytmp<$y; $ytmp++) { +/** +* set data for previous-page link +**/ +if ($index['actual'][1] > 0 && isset($MENU->menuFieldValues[$index['actual'][0]][$index['actual'][1] - 1])) { + $index['prev'] = array($index['actual'][0], $index['actual'][1] - 1); +} else { + $index['prev'] = false; +} - // befindet sich die aktuelle Datei in dieser Ebene ? - if (in_array ($page , $GLOBALS['MENU']->menuFieldValues[$xtmp][$ytmp])) { +/** +* set data for next-page link +**/ +if ($index['actual'][1] < $index['actual'][2] - 1 && isset($MENU->menuFieldValues[$index['actual'][0]][$index['actual'][1] + 1])) { + $index['next'] = array($index['actual'][0], $index['actual'][1] + 1); +} else { + $index['next'] = false; +} - // existiert ein nachfolgender Menüpunkt ? - if (isset($GLOBALS['MENU']->menuFieldValues[$xtmp][$ytmp+1])) { - $next = $GLOBALS['MENU']->menuFieldValues[$xtmp][$ytmp+1]; - } else { - unset($next); - } - //$next = $GLOBALS['MENU']->menuFieldValues[$xtmp][$ytmp+1]; +/** +* set data for last-page link +**/ +if ($index['actual'][1] != $index['actual'][2] - 1 && isset($MENU->menuFieldValues[$index['actual'][0]][$index['actual'][1] - 1])) { + $index['last'] = array($index['actual'][0], $index['actual'][2] - 1); +} else { + $index['last'] = false; +} - // existiert ein vorhergehender Menüpunkt ? - if (isset($GLOBALS['MENU']->menuFieldValues[$xtmp][$ytmp-1])) { - $prev = $GLOBALS['MENU']->menuFieldValues[$xtmp][$ytmp-1]; - } else { - unset($prev); - } - //$prev = $GLOBALS['MENU']->menuFieldValues[$xtmp][$ytmp-1]; +/** +* get the menu-class of the current page +**/ +$search = $MENU->menuFieldNames[$index['actual'][0]]; +array_walk($search, 'ext_string', '%'); +$replace = $MENU->menuFieldValues[$index['actual'][0]][$index['actual'][1]]; +$page['LINK'] = $page; +$page['CLASS'] = str_replace($search, $replace, '%CLASS'); - if ($stop_at_first == 1) { - $stop = 1; - } - } - if ($stop==1) { - break 2; - } - } +/** +* set data for the top-page link +**/ +if (strpos ($page['CLASS'], '.') > 0) { + $page['PARENT_CLASS'] = substr ($page['CLASS'], 0, strrpos($page['CLASS'], '.')); + if (in_array($page['PARENT_CLASS'], $MENU->menuKlasse)) { + $index['top'] = getMenuEntry ($page['PARENT_CLASS']); + } else { + $index['top'] = false; + } } -// Tag für den Link auf die nachfolgende Seite -$current=count($Tags); -$Tags[$current][0]='<!-- NEXTPAGE //-->'; -if ((isset($next)) || (strlen(trim($next[3]))==0)) { - $Tags[$current][1]='nix next'; -} else { - $Tags[$current][1]= '<link "'.$prelink.$next[2].',_self,Weiter">>></a>'; +/** +* generate the necessary tags for the content +**/ +reset($index); +foreach ($index as $id=>$data) { + if (!isset($tpl[$id])) { + continue; + } + if ($data === false) { + $Tags[] = array($tag_id[$id], $tpl[$id]['passiv']); + continue; + } + $search = $MENU->menuFieldNames[$data[0]]; + array_walk($search, 'ext_string', '%'); + $replace = $MENU->menuFieldValues[$data[0]][$data[1]]; + $tag_data = array($tag_id[$id], str_replace($search, $replace, $tpl[$id]['active'])); + if ($in_front) { + array_unshift ($Tags, $tag_data); + } else { + $Tags[] = $tag_data; + } } -// Tag für die vorherige Seite */ -$current=count($Tags); -$Tags[$current][0]='<!-- PREVPAGE //-->'; // In dieses Tag wird der Link für die nächste Seite getauscht -if (isset($prev)) $Tags[$current][1]='nix prev'; -// hier kannst du das Aussehen des Links bestimmen -else $Tags[$current][1]= '<link "'.$prelink.$prev[2].',_self,Zurück"><<</a>'; -?> +/** +* clean the var-scope +**/ +unset ($data, $e, $entries, $id, $index, $in_front, $m, $menues, $page, $recursion, $replace, $search, $tag_id, $tag_data, $tpl); + +/** +* TODO: +* Rekursion in die Verzeichnisebenen möglich (sinnvoll?) +**/ +?> \ No newline at end of file --- NEW FILE: .project --- <?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>prev-next</name> <comment></comment> <projects> </projects> <buildSpec> </buildSpec> <natures> </natures> </projectDescription> |