From: <txm...@us...> - 2015-03-07 11:02:44
|
Revision: 13009 http://sourceforge.net/p/xoops/svn/13009 Author: txmodxoops Date: 2015-03-07 11:02:42 +0000 (Sat, 07 Mar 2015) Log Message: ----------- Added Breadcrumbs class & smarty plugin Added Paths: ----------- XoopsCore/branches/2.5.x/2.5.8_timgno/htdocs/class/breadcrumbs.php XoopsCore/branches/2.5.x/2.5.8_timgno/htdocs/class/smarty/ XoopsCore/branches/2.5.x/2.5.8_timgno/htdocs/class/smarty/plugins/ XoopsCore/branches/2.5.x/2.5.8_timgno/htdocs/class/smarty/plugins/function.breadcrumbs.php Added: XoopsCore/branches/2.5.x/2.5.8_timgno/htdocs/class/breadcrumbs.php =================================================================== --- XoopsCore/branches/2.5.x/2.5.8_timgno/htdocs/class/breadcrumbs.php (rev 0) +++ XoopsCore/branches/2.5.x/2.5.8_timgno/htdocs/class/breadcrumbs.php 2015-03-07 11:02:42 UTC (rev 13009) @@ -0,0 +1,81 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. +*/ + +/** + * XOOPS breadcrumbs navigation + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package class + * @since 2.5.7 + * @author Txmod Xoops (AKA Timgno) + * @version $Id: breadcrumbs.php 12991 2015-02-28 11:18:20Z timgno $ + */ + +defined('XOOPS_ROOT_PATH') or die('Restricted access'); + +class Breadcrumbs +{ + /** + * *#@+ + * + * @access private + */ + /** + * @var array + */ + private $_trail = array(); + /** + * *#@- + */ + + /** + * Constructor + * + * @param null + */ + public function __construct() { } + + /** + * Create step navigation + * + * @param string $title + * @param string $link + * @return string + */ + public function addStep($title, $link = "") + { + $this->_trail[] = array('title' => $title, 'link' => $link); + } + + /** + * Get trail navigation + * + * @return array + */ + public function getTrail() + { + return $this->_trail; + } + + /** + * Get title navigation + * + * @return array + */ + public function getTitle() + { + if(count($this->_trail) == 0) + return null; + + return $this->_trail[count($this->_trail)- 1]['title']; + } +} \ No newline at end of file Added: XoopsCore/branches/2.5.x/2.5.8_timgno/htdocs/class/smarty/plugins/function.breadcrumbs.php =================================================================== --- XoopsCore/branches/2.5.x/2.5.8_timgno/htdocs/class/smarty/plugins/function.breadcrumbs.php (rev 0) +++ XoopsCore/branches/2.5.x/2.5.8_timgno/htdocs/class/smarty/plugins/function.breadcrumbs.php 2015-03-07 11:02:42 UTC (rev 13009) @@ -0,0 +1,61 @@ +<?php +/** +* Smarty plugin +* @package Smarty +* @subpackage plugins +*/ + +/** +* Smarty {breadcrumbs} function plugin +* +* Type: function<br> +* Name: breadcrumbs<br> +* Date: March 7, 2015 +* Purpose: Prints breadcrumbs based on the parameters<br> +* Input:<br> +* - trail = index for the trail item +* - separator = how many items there are on a separator +* - truncate = total number of items +* +* Examples: +* <div class="breadcrumbs"> +* <{breadcrumbs trail=$breadcrumbs->getTrail() separator=' » '}> +* </div> +* +* @version 1.0 +* @author Txmod Xoops - <txmodxoops at gmail dot org | www.txmodxoops.org> +* @param array +* @param Smarty +* @return string +*/ + +function smarty_function_breadcrumbs($params, &$smarty) +{ + $defaultParams = array('trail' => array(), 'separator' => ' > ', 'truncate' => 20); + // Inizialize the parameters + foreach ($defaultParams as $k => $v) { + if(!isset($params[$k])) { + $params[$k] = $v; + } + } + // Load the truncate modifier + if($params['truncate'] > 0) { + require_once $smarty->_get_plugin_filepath('modifier', 'truncate'); + } + $links = array(); + $numSteps = count($params['trail']); + for($i = 0; $i < $numSteps; $i++) { + $step = $params['trail'][$i]; + // Truncate title if required + $step['title'] = smarty_modifier_truncate($step['title'], $params['truncate']); + // Build link if it's set and isn't the last step + if(strlen($step['link']) > 0 && $i < $numSteps - 1) { + $links[] = sprintf('<a href="%s" title="%s">%s</a>', htmlspecialChars($step['link']), htmlspecialChars($step['title']), htmlspecialChars($step['title'])); + } else { + // Either the link isn't set, or it's the last step + $links[] = htmlspecialChars($step['title']); + } + } + $breadcrumbs = join($params['separator'], $links); + $smarty->assign("breadcrumbs", $breadcrumbs); +} \ No newline at end of file |