Thread: [Phpcms-plugins-cvs] navigation4phpCMS navigation4phpcms.php,NONE,1.1 .cvsignore,NONE,1.1
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2005-01-03 18:21:40
|
Update of /cvsroot/phpcms-plugins/navigation4phpCMS In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16023 Added Files: navigation4phpcms.php .cvsignore Log Message: initial commit --- NEW FILE: .cvsignore --- navigation4phpcms.zip .project extmenuclass.php langs2link.php language.php logiclinks.php phpcms_breadcrumb.php release --- NEW FILE: navigation4phpcms.php --- <?php /** * navigation4phpCMS - Plugin for 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) 2004, Martin Jahn * @version $Id: navigation4phpcms.php,v 1.1 2005/01/03 18:21:28 mjahn Exp $ * @package navigation4phpCMS **/ /* * $Log: navigation4phpcms.php,v $ * Revision 1.1 2005/01/03 18:21:28 mjahn * initial commit * */ class navigation4phpcms { var $_quicklinks = array (); var $_Tags = array (); var $_PageContent = array (); /** * @var string name of the menu-parameter */ var $extmenu_param = 'EXTMENUCLASS'; /** * A field in the menu-file defines the values that the URI-parameter have * to have for getting the menuId. In this array you define a association * between the parametername and the menuclass where to search for the * parameter in the menu-array. * * @var array translation table for extmenuclass */ var $extmenu_translation = array ( 'query'=>'kreischa.info.home', 'menuId'=>'kreischa.info.photos'); var $I18N_MODE = 'SUFFIX'; function breadcrumbs () { // breadcrumb link with/without selectbox for last entry $bread = array (); //print_r($this->_quicklinks); $bread = explode ('.', $this->_actualClass); $breadcrumb = array_shift ($bread); $breadcrumbpath = array (); for ($i = 0; $i < count ($bread); $i++) { $breadcrumb .= '.'.$bread [$i]; if (!isset ($this->_quicklinks [$breadcrumb])) { continue; } $breadcrumbpath [] =& $this->_quicklinks [$breadcrumb]; } $output = ''; for ($i = 0; $i < count ($breadcrumbpath); $i++) { if ($i < count ($breadcrumbpath) - 1) { $output .= '<a href="'.$breadcrumbpath [$i] ['LINK'].'" title="'.$breadcrumbpath [$i] ['TITLE_'.$this->lang].'">'.htmlentities ($breadcrumbpath [$i] ['MNAME_'.$this->lang]).'</a> > '; continue; } $output .= $breadcrumbpath [$i] ['MNAME_'.$this->lang]; } array_unshift ($this->_Tags, array ('<phpcms:breadcrumb />', $output)); unset ($bread, $breadcrumb, $breadcrumbpath, $output); return null; } function extmenuclass () { if (trim (implode ($this->_PageContent->MENU)) != $this->extmenu_param) { return null; } unset ($this->_PageContent->MENU); if (!is_array ($this->extmenu_translation)) { return null; } foreach ($this->extmenu_translation as $paramname=>$class) { $this->_PageContent->MENU = array ($class); $this->_actualClass = $class; if (!isset ($_REQUEST [$paramname])) { continue; } foreach ($this->_quicklinks as $q_class=>$q_data) { // if (substr ($q_class, 0, strlen ($class)) != $class) { continue; } if (!isset ($q_data [$paramname]) || $q_data [$paramname] != $_REQUEST [$paramname]) { continue; } $this->_PageContent->MENU = array ($q_data ['CLASS']); $this->_actualClass = $q_data ['CLASS']; break; } } return null; } function headerListing () { if (isset ($this->_PageContent->NOHEADER)) { $this->_Tags [] = array ('<phpcms:headerlist />', ' '); return; } $fields = array ('CONTENT', 'CONTENT1'); $headers = array (); foreach ($fields as $field) { if (!isset ($this->_PageContent->{$field})) { continue; } if (!preg_match_all ('°(<h([0-9])[^>]*>)(([^<]*)</h\\2>)°im', join ('', (array) $this->_PageContent->{$field}), $erg)) { continue; } $headers [] = $erg; } if (count ($headers) == 0) { $this->_Tags [] = array ('<phpcms:headerlist />', ' '); return; } $out = '<div id="headers">' . "\n" . '<h3>Inhaltsverzeichnis</h3>' . "\n" . '<ul>'; $search = array (); $replace = array (); for ($i = 0; $i < count ($headers); $i++) { for ($j = 0; $j < count ($headers [$i] [4]); $j++) { $out .= '<li><a href="#h'.$i.'_'.$j.'">'.$headers [$i] [4] [$j].'</a></li>'."\n"; $replace [] = $headers [$i] [1] [$j].'<a name="h'.$i.'_'.$j.'" id="h'.$i.'_'.$j.'"></a>'.$headers [$i] [3] [$j]; $search [] = $headers [$i] [0] [$j]; } } $out .= '</ul>' . "\n" . '</div>' . "\n"; foreach ($fields as $field) { if (!isset ($this->_PageContent->{$field})) { continue; } $this->_PageContent->{$field} = str_replace ($search, $replace, $this->_PageContent->{$field}); } $this->_Tags [] = array ('<phpcms:headerlist />', $out); //print_r ($this->Tags); } function langs2links ($useI18N = true) { global $DEFAULTS; $out = ''; if ((!isset ($DEFAULTS->I18N) || strtoupper ($DEFAULTS->I18N) !== 'ON') && $useI18N) { $this->_Tags [] = array ('<phpcms:langs2links />', $out); return false; } switch ($DEFAULTS->I18N_MODE) { case 'SUFFIX': $dir = $this->_CheckPage->path.substr ($this->_CheckPage->name, 0, strrpos ($this->_CheckPage->name, '/')); $filename = substr ($this->_CheckPage->name, strrpos ($this->_CheckPage->name, '/'), 100); $pre = substr ($filename, 0, strpos ($filename, $this->lang)); $post = substr ($filename, strpos ($filename, $this->lang) + strlen ($this->lang), strlen ($filename)); $lang_files = $this->_getDirContent ($_SERVER ['DOCUMENT_ROOT'].$dir, $pre, $post); break; case 'DIR': break; default:; } /* echo '<!--'; print_r ($lang_files); echo '-->'; */ $this->_Tags [] = array ('<phpcms:langs2links />', $out); return true; } function run () { $this->_getProjectVars (); $this->_parseMenu (); $this->extmenuclass (); $this->breadcrumbs (); //$this->headerListing (); $this->langs2links (); return null; } function navigation4phpcms (&$content,&$Tags) { return $this->__construct ($content, $Tags); } function __construct (&$content, &$Tags) { global $MENU, $PHPCMS, $CHECK_PAGE; $this->_PageContent =& $content; $this->_MENU =& $MENU; $this->_Tags =& $Tags; $this->_PHPCMS =& $PHPCMS; $this->_CheckPage =& $CHECK_PAGE; $this->lang = $_GET ['lang']; $this->run (); return true; } function _getDirContent ($dir, $pre, $post) { // initialize return-value $ret = array (); // check if direrctory exists if (!file_exists ($dir) || !is_dir ($dir)) { return $ret; } // open directoy $dh = opendir ($dir); if (!$dh) { return $ret; } // walk through directory while (false !== ($entry = readdir ($dh))) { // does pattern containt a directory path if (!strstr ($pattern, '/') && !strstr ($pattern, '\\')) { if (!preg_match ('°'.$pattern.'°ims', $entry, $erg)) { continue; } $ret [$erg [1] [0]] = $erg [0] [0]; } else { // ja -> matcht der der erste Teile des Pfades? // ja -> _getDirContent (Pfad, Dateiname komplett) } } // close directory ressource-handle closedir ($dh); return $ret; } function _parseMenu () { // get value of the $home-variable $home = $this->_project ['HOME']; // create quicklinks to the menu-entries $num_menus = count ($this->_MENU->menuKlasse); // walk through all menus ... for ($i = 0; $i < $num_menus; $i++) { $classIndex = -1; $linkIndex = -1; // get the index of the class field for the actual menu for ($j = 0; $j < count ($this->_MENU->menuFieldNames [$i]); $j++) { if ($this->_MENU->menuFieldNames [$i] [$j] == 'CLASS') { // fieldname is 'CLASS' $classIndex = $j; } if ($this->_MENU->menuFieldNames [$i] [$j] == 'LINK') { // fieldname is 'LINK' $linkIndex = $j; } if ($classIndex != -1 && $linkIndex != -1) { break; } } $num_entries = count ($this->_MENU->menuFieldValues [$i]); for ($j = 0; $j < $num_entries; $j++) { for ($k = 0; $k < count ($this->_MENU->menuFieldNames [$i]); $k++) { $this->_quicklinks [$this->_MENU->menuFieldValues [$i] [$j] [$classIndex]] [$this->_MENU->menuFieldNames [$i] [$k]] =& $this->_MENU->menuFieldValues [$i] [$j] [$k]; } // check if the current page has this class if ( $this->_MENU->menuFieldValues [$i] [$j] [$linkIndex] == $this->_PHPCMS->_request_uri ['_uri_']) { $this->_actualClass = $this->_MENU->menuFieldValues [$i] [$j] [$classIndex]; } } } // if we did not found the current file in the menu-array, check for the field {MENU} if (isset ($this->_PageContent->MENU)) { $menuFieldValue = trim (join ('', $this->_PageContent->MENU)); if ($menuFieldValue != '') { $this->_actualClass = $menuFieldValue; } } unset ($this->_MENU, $menuFieldValue, $num_entries, $i, $j, $k, $classIndex, $linkIndex, $num_menues, $home); return null; } function _getProjectVars () { global $PAGE; for ($i = 0; $i < count ($PAGE->project->lines); $i++) { if (substr (trim ($PAGE->project->lines [$i]), 0, 1) == ';') { continue; } $id = substr ($PAGE->project->lines [$i], 0, strpos ($PAGE->project->lines [$i], ':=')); $value = substr (strstr ($PAGE->project->lines [$i], ':='), 3, 100); $this->_project [trim ($id)] = trim ($value); } unset ($i, $id, $value); return null; } } if (isset($DEFAULTS->EDIT)) { // do nothing in EDIT-mode return; } $navi = new navigation4phpcms ($PageContent, $Tags); ?> |