Location: PHPKode > projects > Mocovie web framework > webs/common/controls/unfinished/breadcrumb.php
<?php
/**
 *  Copyright (C) 2010  Kai Dorschner
 *
 *  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 3 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, see <http://www.gnu.org/licenses/>.
 *
 * @author Kai Dorschner <the-hide@address.com>
 * @copyright Copyright 2010, Kai Dorschner
 * @license http://www.gnu.org/licenses/gpl.html GPLv3
 * @package mocovi
 * @subpackage controls
 */

/**
 * Require Anchor Control
 */
ControlFactory::load('anchor');
/**
 * A breadcrumb is a step by step link to the destination.
 *
 * This control splits your path into pieces and links every
 * part hierarchicaly.
 *
 * You can define the name of the child elements in the DOM Document, but
 * other user options.
 *
 * @package mocovi
 * @subpackage controls
 */
class breadcrumb_control extends text_control
{
	const SEPARATOR = '/'; // XML Path separator

	protected $defaultOptions = array
		( 'text'		=> ''
		, 'textToken'	=> 'BreadCrumbYouAreHere' // Don't change, it's a token!
		);
	protected $childname = 'element';

	/**
	 * @override
	 */
	protected function program()
	{
		$text = $this->getText();
		if(!$text)
			//$text = Translator::translateToken($this->getOption('textToken'));
			$this->node->appendChild(Translator::translateToken($this->getOption('textToken')));
		$this->node->setAttribute('text', $text);
		$explode = array();
		$path = preg_replace('#^\/+|\/+$#', '', $GLOBALS['page']);
		if(!empty($path))
			$explode = explode(self::SEPARATOR, $path);
		$chain = '';
		foreach($explode as $breadcrumb)
		{
			$chain .= self::SEPARATOR.$breadcrumb;
			$element = $this->dom->createElement($this->childname);
			$anchorOptions = array
			( 'textToken'	=> $GLOBALS['filesystem']->getAlias($chain)
			, 'href'		=> $GLOBALS['linkprefix'].$chain.'.'.$GLOBALS['media']
			);
			$anchor = new anchor_control($anchorOptions);
			$element->appendChild($anchor->run($this->dom));
			$this->node->appendChild($element);
		}
	}
}
Return current item: Mocovie web framework