| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Joomla
Revision: 10147
Author: eddieajau
Date: 19 Mar 2008 06:36:19
Changes:Trunk merge
Files:| ... | ...@@ -1,49 +1,49 @@ | |
| 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | <install type="module" version="1.5.0"> | |
| 3 | <name>Feed Display</name> | |
| 4 | <author>Joomla! Project</author> | |
| 5 | <creationDate>July 2005</creationDate> | |
| 6 | <copyright>Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.</copyright> | |
| 7 | <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license> | |
| 8 | <authorEmail>admin@joomla.org</authorEmail> | |
| 9 | <authorUrl>www.joomla.org</authorUrl> | |
| 10 | <version>1.5.0</version> | |
| 11 | <description>This module allows the displaying of a syndicated feed</description> | |
| 12 | <files> | |
| 13 | <filename module="mod_feed">mod_feed.php</filename> | |
| 14 | </files> | |
| 15 | <params> | |
| 16 | <param name="moduleclass_sfx" type="text" default="" label="Module Class Suffix" description="PARAMMODULECLASSSUFFIX" /> | |
| 17 | <param name="@spacer" type="spacer" default="" label="" description="" /> | |
| 18 | <param name="rssurl" type="text" size="50" default="" label="Feed URL" description="Enter the URL of the RSS/RDF feed" /> | |
| 19 | <param name="rssrtl" type="radio" default="0" label="RTL feed" description="Display feed in RTL direction"> | |
| 20 | <option value="1">Yes</option> | |
| 21 | <option value="0">No</option> | |
| 22 | </param> | |
| 23 | <param name="rsstitle" type="radio" default="1" label="Feed Title" description="Display news feed title"> | |
| 24 | <option value="1">Yes</option> | |
| 25 | <option value="0">No</option> | |
| 26 | </param> | |
| 27 | <param name="rssdesc" type="radio" default="1" label="Feed Description" description="Show the description text for the whole Feed"> | |
| 28 | <option value="1">Yes</option> | |
| 29 | <option value="0">No</option> | |
| 30 | </param> | |
| 31 | <param name="rssimage" type="radio" default="1" label="Feed Image" description="Show the image associated with the whole Feed"> | |
| 32 | <option value="1">Yes</option> | |
| 33 | <option value="0">No</option> | |
| 34 | </param> | |
| 35 | <param name="rssitems" type="text" default="3" label="Items" description="Enter number of RSS items to display" /> | |
| 36 | <param name="rssitemdesc" type="radio" default="1" label="Item Description" description="PARAMITEMDESC"> | |
| 37 | <option value="1">Yes</option> | |
| 38 | <option value="0">No</option> | |
| 39 | </param> | |
| 40 | <param name="word_count" type="text" size="6" default="0" label="Word Count" description="PARAMWORDCOUNT" /> | |
| 41 | </params> | |
| 42 | <params group="advanced"> | |
| 43 | <param name="cache" type="list" default="0" label="Caching" description="Select whether to cache the content of this module"> | |
| 44 | <option value="1">Use global</option> | |
| 45 | <option value="0">No caching</option> | |
| 46 | </param> | |
| 47 | <param name="cache_time" type="text" default="900" label="Cache Time" description="The time before the module is recached" /> | |
| 48 | </params> | |
| 49 | </install> | |
| 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | <install type="module" version="1.5.0"> | |
| 3 | <name>Feed Display</name> | |
| 4 | <author>Joomla! Project</author> | |
| 5 | <creationDate>July 2005</creationDate> | |
| 6 | <copyright>Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.</copyright> | |
| 7 | <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license> | |
| 8 | <authorEmail>admin@joomla.org</authorEmail> | |
| 9 | <authorUrl>www.joomla.org</authorUrl> | |
| 10 | <version>1.5.0</version> | |
| 11 | <description>This module allows the displaying of a syndicated feed</description> | |
| 12 | <files> | |
| 13 | <filename module="mod_feed">mod_feed.php</filename> | |
| 14 | </files> | |
| 15 | <params> | |
| 16 | <param name="moduleclass_sfx" type="text" default="" label="Module Class Suffix" description="PARAMMODULECLASSSUFFIX" /> | |
| 17 | <param name="@spacer" type="spacer" default="" label="" description="" /> | |
| 18 | <param name="rssurl" type="text" size="50" default="" label="Feed URL" description="Enter the URL of the RSS/RDF feed" /> | |
| 19 | <param name="rssrtl" type="radio" default="0" label="RTL feed" description="Display feed in RTL direction"> | |
| 20 | <option value="1">Yes</option> | |
| 21 | <option value="0">No</option> | |
| 22 | </param> | |
| 23 | <param name="rsstitle" type="radio" default="1" label="Feed Title" description="Display news feed title"> | |
| 24 | <option value="1">Yes</option> | |
| 25 | <option value="0">No</option> | |
| 26 | </param> | |
| 27 | <param name="rssdesc" type="radio" default="1" label="Feed Description" description="Show the description text for the whole Feed"> | |
| 28 | <option value="1">Yes</option> | |
| 29 | <option value="0">No</option> | |
| 30 | </param> | |
| 31 | <param name="rssimage" type="radio" default="1" label="Feed Image" description="Show the image associated with the whole Feed"> | |
| 32 | <option value="1">Yes</option> | |
| 33 | <option value="0">No</option> | |
| 34 | </param> | |
| 35 | <param name="rssitems" type="text" default="3" label="Items" description="Enter number of RSS items to display" /> | |
| 36 | <param name="rssitemdesc" type="radio" default="1" label="Item Description" description="PARAMITEMDESC"> | |
| 37 | <option value="1">Yes</option> | |
| 38 | <option value="0">No</option> | |
| 39 | </param> | |
| 40 | <param name="word_count" type="text" size="6" default="0" label="Word Count" description="PARAMWORDCOUNT" /> | |
| 41 | </params> | |
| 42 | <params group="advanced"> | |
| 43 | <param name="cache" type="list" default="0" label="Caching" description="Select whether to cache the content of this module"> | |
| 44 | <option value="1">Use global</option> | |
| 45 | <option value="0">No caching</option> | |
| 46 | </param> | |
| 47 | <param name="cache_time" type="text" default="15" label="Cache Time" description="The time before the module is recached" /> | |
| 48 | </params> | |
| 49 | </install> |
| ... | ...@@ -1,55 +1,60 @@ | |
| 1 | <?php | |
| 2 | /** | |
| 3 | * @version $Id$ | |
| 4 | * @package Joomla | |
| 5 | * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. | |
| 6 | * @license GNU/GPL, see LICENSE.php | |
| 7 | * Joomla! is free software. This version may have been modified pursuant | |
| 8 | * to the GNU General Public License, and as distributed it includes or | |
| 9 | * is derivative of works licensed under the GNU General Public License or | |
| 10 | * other free or open source software licenses. | |
| 11 | * See COPYRIGHT.php for copyright notices and details. | |
| 12 | */ | |
| 13 | ||
| 14 | /** ensure this file is being included by a parent file */ | |
| 15 | defined('_JEXEC') or die('Direct Access to this location is not allowed.'); | |
| 16 | ||
| 17 | class modFeedHelper | |
| 18 | { | |
| 19 | function getFeed($params) | |
| 20 | { | |
| 21 | // module params | |
| 22 | $rssurl = $params->get('rssurl', ''); | |
| 23 | ||
| 24 | // get RSS parsed object | |
| 25 | $options = array(); | |
| 26 | $options['rssUrl'] = $rssurl; | |
| 27 | $options['cache_time'] = 3600; | |
| 28 | ||
| 29 | $rssDoc =& JFactory::getXMLparser('RSS', $options); | |
| 30 | ||
| 31 | $feed = new stdclass(); | |
| 32 | ||
| 33 | if ($rssDoc != false) | |
| 34 | { | |
| 35 | // channel header and link | |
| 36 | $feed->title = $rssDoc->get_title(); | |
| 37 | $feed->link = $rssDoc->get_link(); | |
| 38 | $feed->description = $rssDoc->get_description(); | |
| 39 | ||
| 40 | // channel image if exists | |
| 41 | $feed->image->url = $rssDoc->get_image_url(); | |
| 42 | $feed->image->title = $rssDoc->get_image_title(); | |
| 43 | ||
| 44 | // items | |
| 45 | $items = $rssDoc->get_items(); | |
| 46 | ||
| 47 | // feed elements | |
| 48 | $feed->items = array_slice($items, 0, $params->get('rssitems', 5)); | |
| 49 | } else { | |
| 50 | $feed = false; | |
| 51 | } | |
| 52 | ||
| 53 | return $feed; | |
| 54 | } | |
| 1 | <?php | |
| 2 | /** | |
| 3 | * @version $Id$ | |
| 4 | * @package Joomla | |
| 5 | * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. | |
| 6 | * @license GNU/GPL, see LICENSE.php | |
| 7 | * Joomla! is free software. This version may have been modified pursuant | |
| 8 | * to the GNU General Public License, and as distributed it includes or | |
| 9 | * is derivative of works licensed under the GNU General Public License or | |
| 10 | * other free or open source software licenses. | |
| 11 | * See COPYRIGHT.php for copyright notices and details. | |
| 12 | */ | |
| 13 | ||
| 14 | /** ensure this file is being included by a parent file */ | |
| 15 | defined('_JEXEC') or die('Direct Access to this location is not allowed.'); | |
| 16 | ||
| 17 | class modFeedHelper | |
| 18 | { | |
| 19 | function getFeed($params) | |
| 20 | { | |
| 21 | // module params | |
| 22 | $rssurl = $params->get('rssurl', ''); | |
| 23 | ||
| 24 | // get RSS parsed object | |
| 25 | $options = array(); | |
| 26 | $options['rssUrl'] = $rssurl; | |
| 27 | if ($params->get('cache')) { | |
| 28 | $options['cache_time'] = $params->get('cache_time', 15) ; | |
| 29 | $options['cache_time'] *= 60; | |
| 30 | } else { | |
| 31 | $options['cache_time'] = null; | |
| 32 | } | |
| 33 | ||
| 34 | $rssDoc =& JFactory::getXMLparser('RSS', $options); | |
| 35 | ||
| 36 | $feed = new stdclass(); | |
| 37 | ||
| 38 | if ($rssDoc != false) | |
| 39 | { | |
| 40 | // channel header and link | |
| 41 | $feed->title = $rssDoc->get_title(); | |
| 42 | $feed->link = $rssDoc->get_link(); | |
| 43 | $feed->description = $rssDoc->get_description(); | |
| 44 | ||
| 45 | // channel image if exists | |
| 46 | $feed->image->url = $rssDoc->get_image_url(); | |
| 47 | $feed->image->title = $rssDoc->get_image_title(); | |
| 48 | ||
| 49 | // items | |
| 50 | $items = $rssDoc->get_items(); | |
| 51 | ||
| 52 | // feed elements | |
| 53 | $feed->items = array_slice($items, 0, $params->get('rssitems', 5)); | |
| 54 | } else { | |
| 55 | $feed = false; | |
| 56 | } | |
| 57 | ||
| 58 | return $feed; | |
| 59 | } | |
| 55 | 60 | } |
| 56 | 61 | \ No newline at end of file |
| ... | ...@@ -31,6 +31,6 @@ | |
| 31 | 31 | this.setHandler('username', |
| 32 | 32 | function (value) { |
| 33 | regex=/^[a-zA-Z](([\.\-a-zA-Z0-9@])?[a-zA-Z0-9]*)*$/; | |
| 34 | return regex.test(value); | |
| 33 | regex = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&]", "i"); | |
| 34 | return !regex.test(value); | |
| 35 | 35 | } |
| 36 | 36 | ); |
| ... | ...@@ -1,390 +1,392 @@ | |
| 1 | <?php | |
| 2 | /** | |
| 3 | * @version $Id$ | |
| 4 | * @package Joomla | |
| 5 | * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. | |
| 6 | * @license GNU/GPL, see LICENSE.php | |
| 7 | * Joomla! is free software. This version may have been modified pursuant | |
| 8 | * to the GNU General Public License, and as distributed it includes or | |
| 9 | * is derivative of works licensed under the GNU General Public License or | |
| 10 | * other free or open source software licenses. | |
| 11 | * See COPYRIGHT.php for copyright notices and details. | |
| 12 | */ | |
| 13 | ||
| 14 | // no direct access | |
| 15 | defined('_JEXEC') or die('Restricted access'); | |
| 16 | ||
| 17 | ||
| 18 | jimport('joomla.base.tree'); | |
| 19 | jimport('joomla.utilities.simplexml'); | |
| 20 | ||
| 21 | /** | |
| 22 | * mod_mainmenu Helper class | |
| 23 | * | |
| 24 | * @static | |
| 25 | * @package Joomla | |
| 26 | * @subpackage Menus | |
| 27 | * @since 1.5 | |
| 28 | */ | |
| 29 | class modMainMenuHelper | |
| 30 | { | |
| 31 | function buildXML(&$params) | |
| 32 | { | |
| 33 | $menu = new JMenuTree($params); | |
| 34 | $items = &JSite::getMenu(); | |
| 35 | ||
| 36 | // Get Menu Items | |
| 37 | $rows = $items->getItems('menutype', $params->get('menutype')); | |
| 38 | $maxdepth = $params->get('maxdepth',10); | |
| 39 | ||
| 40 | // Build Menu Tree root down (orphan proof - child might have lower id than parent) | |
| 41 | $user =& JFactory::getUser(); | |
| 42 | $ids = array(); | |
| 43 | $ids[0] = true; | |
| 44 | $last = null; | |
| 45 | $unresolved = array(); | |
| 46 | // pop the first item until the array is empty if there is any item | |
| 47 | if ( is_array($rows)) { | |
| 48 | while (count($rows) && !is_null($row = array_shift($rows))) | |
| 49 | { | |
| 50 | if (array_key_exists($row->parent, $ids)) { | |
| 51 | $menu->addNode($row); | |
| 52 | // record loaded parents | |
| 53 | $ids[$row->id] = true; | |
| 54 | } else { | |
| 55 | // no parent yet so push item to back of list | |
| 56 | // SAM: But if the key isn't in the list and we dont _add_ this is infinite, so check the unresolved queue | |
| 57 | if(!array_key_exists($row->id, $unresolved) || $unresolved[$row->id] < $maxdepth) { | |
| 58 | array_push($rows, $row); | |
| 59 | // so let us do max $maxdepth passes | |
| 60 | // TODO: Put a time check in this loop in case we get too close to the PHP timeout | |
| 61 | if(!isset($unresolved[$row->id])) $unresolved[$row->id] = 1; | |
| 62 | else $unresolved[$row->id]++; | |
| 63 | } | |
| 64 | } | |
| 65 | } | |
| 66 | } | |
| 67 | return $menu->toXML(); | |
| 68 | } | |
| 69 | ||
| 70 | function &getXML($type, &$params, $decorator) | |
| 71 | { | |
| 72 | static $xmls; | |
| 73 | ||
| 74 | if (!isset($xmls[$type])) { | |
| 75 | $cache =& JFactory::getCache('mod_mainmenu'); | |
| 76 | $string = $cache->call(array('modMainMenuHelper', 'buildXML'), $params); | |
| 77 | $xmls[$type] = $string; | |
| 78 | } | |
| 79 | ||
| 80 | // Get document | |
| 81 | $xml = JFactory::getXMLParser('Simple'); | |
| 82 | $xml->loadString($xmls[$type]); | |
| 83 | $doc = &$xml->document; | |
| 84 | ||
| 85 | $menu = &JSite::getMenu(); | |
| 86 | $active = $menu->getActive(); | |
| 87 | $start = $params->get('startLevel'); | |
| 88 | $end = $params->get('endLevel'); | |
| 89 | $sChild = $params->get('showAllChildren'); | |
| 90 | $path = array(); | |
| 91 | ||
| 92 | // Get subtree | |
| 93 | if ($start) | |
| 94 | { | |
| 95 | $found = false; | |
| 96 | $root = true; | |
| 97 | if(!isset($active)){ | |
| 98 | $doc = false; | |
| 99 | } | |
| 100 | else{ | |
| 101 | $path = $active->tree; | |
| 102 | for ($i=0,$n=count($path);$i<$n;$i++) | |
| 103 | { | |
| 104 | foreach ($doc->children() as $child) | |
| 105 | { | |
| 106 | if ($child->attributes('id') == $path[$i]) { | |
| 107 | $doc = &$child->ul[0]; | |
| 108 | $root = false; | |
| 109 | break; | |
| 110 | } | |
| 111 | } | |
| 112 | ||
| 113 | if ($i == $start-1) { | |
| 114 | $found = true; | |
| 115 | break; | |
| 116 | } | |
| 117 | } | |
| 118 | if ((!is_a($doc, 'JSimpleXMLElement')) || (!$found) || ($root)) { | |
| 119 | $doc = false; | |
| 120 | } | |
| 121 | } | |
| 122 | } | |
| 123 | ||
| 124 | if ($doc && is_callable($decorator)) { | |
| 125 | $doc->map($decorator, array('end'=>$end, 'children'=>$sChild)); | |
| 126 | } | |
| 127 | return $doc; | |
| 128 | } | |
| 129 | ||
| 130 | function render(&$params, $callback) | |
| 131 | { | |
| 132 | switch ( $params->get( 'menu_style', 'list' ) ) | |
| 133 | { | |
| 134 | case 'list_flat' : | |
| 135 | // Include the legacy library file | |
| 136 | require_once(dirname(__FILE__).DS.'legacy.php'); | |
| 137 | mosShowHFMenu($params, 1); | |
| 138 | break; | |
| 139 | ||
| 140 | case 'horiz_flat' : | |
| 141 | // Include the legacy library file | |
| 142 | require_once(dirname(__FILE__).DS.'legacy.php'); | |
| 143 | mosShowHFMenu($params, 0); | |
| 144 | break; | |
| 145 | ||
| 146 | case 'vert_indent' : | |
| 147 | // Include the legacy library file | |
| 148 | require_once(dirname(__FILE__).DS.'legacy.php'); | |
| 149 | mosShowVIMenu($params); | |
| 150 | break; | |
| 151 | ||
| 152 | default : | |
| 153 | // Include the new menu class | |
| 154 | $xml = modMainMenuHelper::getXML($params->get('menutype'), $params, $callback); | |
| 155 | if ($xml) { | |
| 156 | $class = $params->get('class_sfx'); | |
| 157 | $xml->addAttribute('class', 'menu'.$class); | |
| 158 | if ($tagId = $params->get('tag_id')) { | |
| 159 | $xml->addAttribute('id', $tagId); | |
| 160 | } | |
| 161 | ||
| 162 | echo JFilterOutput::ampReplace($xml->toString((bool)$params->get('show_whitespace'))); | |
| 163 | } | |
| 164 | break; | |
| 165 | } | |
| 166 | } | |
| 167 | } | |
| 168 | ||
| 169 | /** | |
| 170 | * Main Menu Tree Class. | |
| 171 | * | |
| 172 | * @package Joomla | |
| 173 | * @subpackage Menus | |
| 174 | * @since 1.5 | |
| 175 | */ | |
| 176 | class JMenuTree extends JTree | |
| 177 | { | |
| 178 | /** | |
| 179 | * Node/Id Hash for quickly handling node additions to the tree. | |
| 180 | */ | |
| 181 | var $_nodeHash = array(); | |
| 182 | ||
| 183 | /** | |
| 184 | * Menu parameters | |
| 185 | */ | |
| 186 | var $_params = null; | |
| 187 | ||
| 188 | /** | |
| 189 | * Menu parameters | |
| 190 | */ | |
| 191 | var $_buffer = null; | |
| 192 | ||
| 193 | function __construct(&$params) | |
| 194 | { | |
| 195 | $this->_params =& $params; | |
| 196 | $this->_root = new JMenuNode(0, 'ROOT'); | |
| 197 | $this->_nodeHash[0] =& $this->_root; | |
| 198 | $this->_current =& $this->_root; | |
| 199 | } | |
| 200 | ||
| 201 | function addNode($item) | |
| 202 | { | |
| 203 | // Get menu item data | |
| 204 | $data = $this->_getItemData($item); | |
| 205 | ||
| 206 | // Create the node and add it | |
| 207 | $node = new JMenuNode($item->id, $item->name, $item->access, $data); | |
| 208 | ||
| 209 | if (isset($item->mid)) { | |
| 210 | $nid = $item->mid; | |
| 211 | } else { | |
| 212 | $nid = $item->id; | |
| 213 | } | |
| 214 | $this->_nodeHash[$nid] =& $node; | |
| 215 | $this->_current =& $this->_nodeHash[$item->parent]; | |
| 216 | ||
| 217 | if ($this->_current) { | |
| 218 | $this->addChild($node, true); | |
| 219 | } else { | |
| 220 | // sanity check | |
| 221 | JError::raiseError( 500, 'Orphan Error. Could not find parent for Item '.$item->id ); | |
| 222 | } | |
| 223 | } | |
| 224 | ||
| 225 | function toXML() | |
| 226 | { | |
| 227 | // Initialize variables | |
| 228 | $this->_current =& $this->_root; | |
| 229 | ||
| 230 | // Recurse through children if they exist | |
| 231 | while ($this->_current->hasChildren()) | |
| 232 | { | |
| 233 | $this->_buffer .= '<ul>'; | |
| 234 | foreach ($this->_current->getChildren() as $child) | |
| 235 | { | |
| 236 | $this->_current = & $child; | |
| 237 | $this->_getLevelXML(0); | |
| 238 | } | |
| 239 | $this->_buffer .= '</ul>'; | |
| 240 | } | |
| 241 | if($this->_buffer == '') { $this->_buffer = '<ul />'; } | |
| 242 | return $this->_buffer; | |
| 243 | } | |
| 244 | ||
| 245 | function _getLevelXML($depth) | |
| 246 | { | |
| 247 | $depth++; | |
| 248 | ||
| 249 | // Start the item | |
| 250 | $this->_buffer .= '<li access="'.$this->_current->access.'" level="'.$depth.'" id="'.$this->_current->id.'">'; | |
| 251 | ||
| 252 | // Append item data | |
| 253 | $this->_buffer .= $this->_current->link; | |
| 254 | ||
| 255 | // Recurse through item's children if they exist | |
| 256 | while ($this->_current->hasChildren()) | |
| 257 | { | |
| 258 | $this->_buffer .= '<ul>'; | |
| 259 | foreach ($this->_current->getChildren() as $child) | |
| 260 | { | |
| 261 | $this->_current = & $child; | |
| 262 | $this->_getLevelXML($depth); | |
| 263 | } | |
| 264 | $this->_buffer .= '</ul>'; | |
| 265 | } | |
| 266 | ||
| 267 | // Finish the item | |
| 268 | $this->_buffer .= '</li>'; | |
| 269 | } | |
| 270 | ||
| 271 | function _getItemData($item) | |
| 272 | { | |
| 273 | $data = null; | |
| 274 | ||
| 275 | // Menu Link is a special type that is a link to another item | |
| 276 | if ($item->type == 'menulink') | |
| 277 | { | |
| 278 | $menu = &JSite::getMenu(); | |
| 279 | if ($tmp = clone($menu->getItem($item->query['Itemid']))) { | |
| 280 | $tmp->name = '<span><![CDATA['.$item->name.']]></span>'; | |
| 281 | $tmp->mid = $item->id; | |
| 282 | $tmp->parent = $item->parent; | |
| 283 | } else { | |
| 284 | return false; | |
| 285 | } | |
| 286 | } else { | |
| 287 | $tmp = clone($item); | |
| 288 | $tmp->name = '<span><![CDATA['.$item->name.']]></span>'; | |
| 289 | } | |
| 290 | ||
| 291 | $iParams = new JParameter($tmp->params); | |
| 292 | if ($iParams->get('menu_image') && $iParams->get('menu_image') != -1) { | |
| 293 | $image = '<img src="'.JURI::base(true).'/images/stories/'.$iParams->get('menu_image').'" alt="" />'; | |
| 294 | } else { | |
| 295 | $image = null; | |
| 296 | } | |
| 297 | switch ($tmp->type) | |
| 298 | { | |
| 299 | case 'separator' : | |
| 300 | return '<span class="separator">'.$image.$tmp->name.'</span>'; | |
| 301 | break; | |
| 302 | ||
| 303 | case 'url' : | |
| 304 | if ((strpos($tmp->link, 'index.php?') !== false) && (strpos($tmp->link, 'Itemid=') === false)) { | |
| 305 | $tmp->url = $tmp->link.'&Itemid='.$tmp->id; | |
| 306 | } else { | |
| 307 | $tmp->url = $tmp->link; | |
| 308 | } | |
| 309 | break; | |
| 310 | ||
| 311 | default : | |
| 312 | $router = JSite::getRouter(); | |
| 313 | $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id; | |
| 314 | break; | |
| 315 | } | |
| 316 | ||
| 317 | // Print a link if it exists | |
| 318 | if ($tmp->url != null) | |
| 319 | { | |
| 320 | // Handle SSL links | |
| 321 | $iSecure = $iParams->def('secure', 0); | |
| 322 | if ($tmp->home == 1) { | |
| 323 | $tmp->url = JURI::base(); | |
| 324 | } elseif (strcasecmp(substr($tmp->url, 0, 4), 'http') && (strpos($tmp->link, 'index.php?') !== false)) { | |
| 325 | $tmp->url = JRoute::_($tmp->url, true, $iSecure); | |
| 326 | } else { | |
| 327 | $tmp->url = str_replace('&', '&', $tmp->url); | |
| 328 | } | |
| 329 | ||
| 330 | switch ($tmp->browserNav) | |
| 331 | { | |
| 332 | default: | |
| 333 | case 0: | |
| 334 | // _top | |
| 335 | $data = '<a href="'.$tmp->url.'">'.$image.$tmp->name.'</a>'; | |
| 336 | break; | |
| 337 | case 1: | |
| 338 | // _blank | |
| 339 | $data = '<a href="'.$tmp->url.'" target="_blank">'.$image.$tmp->name.'</a>'; | |
| 340 | break; | |
| 341 | case 2: | |
| 342 | // window.open | |
| 343 | $attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,'.$this->_params->get('window_open'); | |
| 344 | ||
| 345 | // hrm...this is a bit dickey | |
| 346 | $link = str_replace('index.php', 'index2.php', $tmp->url); | |
| 347 | $data = '<a href="'.$link.'" onclick="window.open(this.href,\'targetWindow\',\''.$attribs.'\');return false;">'.$image.$tmp->name.'</a>'; | |
| 348 | break; | |
| 349 | } | |
| 350 | } else { | |
| 351 | $data = '<a>'.$image.$tmp->name.'</a>'; | |
| 352 | } | |
| 353 | ||
| 354 | return $data; | |
| 355 | } | |
| 356 | } | |
| 357 | ||
| 358 | /** | |
| 359 | * Main Menu Tree Node Class. | |
| 360 | * | |
| 361 | * @package Joomla | |
| 362 | * @subpackage Menus | |
| 363 | * @since 1.5 | |
| 364 | */ | |
| 365 | class JMenuNode extends JNode | |
| 366 | { | |
| 367 | /** | |
| 368 | * Node Title | |
| 369 | */ | |
| 370 | var $title = null; | |
| 371 | ||
| 372 | /** | |
| 373 | * Node Link | |
| 374 | */ | |
| 375 | var $link = null; | |
| 376 | ||
| 377 | /** | |
| 378 | * CSS Class for node | |
| 379 | */ | |
| 380 | var $class = null; | |
| 381 | ||
| 382 | function __construct($id, $title, $access = null, $link = null, $class = null) | |
| 383 | { | |
| 384 | $this->id = $id; | |
| 385 | $this->title = $title; | |
| 386 | $this->access = $access; | |
| 387 | $this->link = $link; | |
| 388 | $this->class = $class; | |
| 389 | } | |
| 1 | <?php | |
| 2 | /** | |
| 3 | * @version $Id$ | |
| 4 | * @package Joomla | |
| 5 | * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. | |
| 6 | * @license GNU/GPL, see LICENSE.php | |
| 7 | * Joomla! is free software. This version may have been modified pursuant | |
| 8 | * to the GNU General Public License, and as distributed it includes or | |
| 9 | * is derivative of works licensed under the GNU General Public License or | |
| 10 | * other free or open source software licenses. | |
| 11 | * See COPYRIGHT.php for copyright notices and details. | |
| 12 | */ | |
| 13 | ||
| 14 | // no direct access | |
| 15 | defined('_JEXEC') or die('Restricted access'); | |
| 16 | ||
| 17 | ||
| 18 | jimport('joomla.base.tree'); | |
| 19 | jimport('joomla.utilities.simplexml'); | |
| 20 | ||
| 21 | /** | |
| 22 | * mod_mainmenu Helper class | |
| 23 | * | |
| 24 | * @static | |
| 25 | * @package Joomla | |
| 26 | * @subpackage Menus | |
| 27 | * @since 1.5 | |
| 28 | */ | |
| 29 | class modMainMenuHelper | |
| 30 | { | |
| 31 | function buildXML(&$params) | |
| 32 | { | |
| 33 | $menu = new JMenuTree($params); | |
| 34 | $items = &JSite::getMenu(); | |
| 35 | ||
| 36 | // Get Menu Items | |
| 37 | $rows = $items->getItems('menutype', $params->get('menutype')); | |
| 38 | $maxdepth = $params->get('maxdepth',10); | |
| 39 | ||
| 40 | // Build Menu Tree root down (orphan proof - child might have lower id than parent) | |
| 41 | $user =& JFactory::getUser(); | |
| 42 | $ids = array(); | |
| 43 | $ids[0] = true; | |
| 44 | $last = null; | |
| 45 | $unresolved = array(); | |
| 46 | // pop the first item until the array is empty if there is any item | |
| 47 | if ( is_array($rows)) { | |
| 48 | while (count($rows) && !is_null($row = array_shift($rows))) | |
| 49 | { | |
| 50 | if (array_key_exists($row->parent, $ids)) { | |
| 51 | $menu->addNode($row); | |
| 52 | // record loaded parents | |
| 53 | $ids[$row->id] = true; | |
| 54 | } else { | |
| 55 | // no parent yet so push item to back of list | |
| 56 | // SAM: But if the key isn't in the list and we dont _add_ this is infinite, so check the unresolved queue | |
| 57 | if(!array_key_exists($row->id, $unresolved) || $unresolved[$row->id] < $maxdepth) { | |
| 58 | array_push($rows, $row); | |
| 59 | // so let us do max $maxdepth passes | |
| 60 | // TODO: Put a time check in this loop in case we get too close to the PHP timeout | |
| 61 | if(!isset($unresolved[$row->id])) $unresolved[$row->id] = 1; | |
| 62 | else $unresolved[$row->id]++; | |
| 63 | } | |
| 64 | } | |
| 65 | } | |
| 66 | } | |
| 67 | return $menu->toXML(); | |
| 68 | } | |
| 69 | ||
| 70 | function &getXML($type, &$params, $decorator) | |
| 71 | { | |
| 72 | static $xmls; | |
| 73 | ||
| 74 | if (!isset($xmls[$type])) { | |
| 75 | $cache =& JFactory::getCache('mod_mainmenu'); | |
| 76 | $string = $cache->call(array('modMainMenuHelper', 'buildXML'), $params); | |
| 77 | $xmls[$type] = $string; | |
| 78 | } | |
| 79 | ||
| 80 | // Get document | |
| 81 | $xml = JFactory::getXMLParser('Simple'); | |
| 82 | $xml->loadString($xmls[$type]); | |
| 83 | $doc = &$xml->document; | |
| 84 | ||
| 85 | $menu = &JSite::getMenu(); | |
| 86 | $active = $menu->getActive(); | |
| 87 | $start = $params->get('startLevel'); | |
| 88 | $end = $params->get('endLevel'); | |
| 89 | $sChild = $params->get('showAllChildren'); | |
| 90 | $path = array(); | |
| 91 | ||
| 92 | // Get subtree | |
| 93 | if ($start) | |
| 94 | { | |
| 95 | $found = false; | |
| 96 | $root = true; | |
| 97 | if(!isset($active)){ | |
| 98 | $doc = false; | |
| 99 | } | |
| 100 | else{ | |
| 101 | $path = $active->tree; | |
| 102 | for ($i=0,$n=count($path);$i<$n;$i++) | |
| 103 | { | |
| 104 | foreach ($doc->children() as $child) | |
| 105 | { | |
| 106 | if ($child->attributes('id') == $path[$i]) { | |
| 107 | $doc = &$child->ul[0]; | |
| 108 | $root = false; | |
| 109 | break; | |
| 110 | } | |
| 111 | } | |
| 112 | ||
| 113 | if ($i == $start-1) { | |
| 114 | $found = true; | |
| 115 | break; | |
| 116 | } | |
| 117 | } | |
| 118 | if ((!is_a($doc, 'JSimpleXMLElement')) || (!$found) || ($root)) { | |
| 119 | $doc = false; | |
| 120 | } | |
| 121 | } | |
| 122 | } | |
| 123 | ||
| 124 | if ($doc && is_callable($decorator)) { | |
| 125 | $doc->map($decorator, array('end'=>$end, 'children'=>$sChild)); | |
| 126 | } | |
| 127 | return $doc; | |
| 128 | } | |
| 129 | ||
| 130 | function render(&$params, $callback) | |
| 131 | { | |
| 132 | switch ( $params->get( 'menu_style', 'list' ) ) | |
| 133 | { | |
| 134 | case 'list_flat' : | |
| 135 | // Include the legacy library file | |
| 136 | require_once(dirname(__FILE__).DS.'legacy.php'); | |
| 137 | mosShowHFMenu($params, 1); | |
| 138 | break; | |
| 139 | ||
| 140 | case 'horiz_flat' : | |
| 141 | // Include the legacy library file | |
| 142 | require_once(dirname(__FILE__).DS.'legacy.php'); | |
| 143 | mosShowHFMenu($params, 0); | |
| 144 | break; | |
| 145 | ||
| 146 | case 'vert_indent' : | |
| 147 | // Include the legacy library file | |
| 148 | require_once(dirname(__FILE__).DS.'legacy.php'); | |
| 149 | mosShowVIMenu($params); | |
| 150 | break; | |
| 151 | ||
| 152 | default : | |
| 153 | // Include the new menu class | |
| 154 | $xml = modMainMenuHelper::getXML($params->get('menutype'), $params, $callback); | |
| 155 | if ($xml) { | |
| 156 | $class = $params->get('class_sfx'); | |
| 157 | $xml->addAttribute('class', 'menu'.$class); | |
| 158 | if ($tagId = $params->get('tag_id')) { | |
| 159 | $xml->addAttribute('id', $tagId); | |
| 160 | } | |
| 161 | ||
| 162 | $result = JFilterOutput::ampReplace($xml->toString((bool)$params->get('show_whitespace'))); | |
| 163 | $result = str_replace(array('<ul/>', '<ul />'), '', $result); | |
| 164 | echo $result; | |
| 165 | } | |
| 166 | break; | |
| 167 | } | |
| 168 | } | |
| 169 | } | |
| 170 | ||
| 171 | /** | |
| 172 | * Main Menu Tree Class. | |
| 173 | * | |
| 174 | * @package Joomla | |
| 175 | * @subpackage Menus | |
| 176 | * @since 1.5 | |
| 177 | */ | |
| 178 | class JMenuTree extends JTree | |
| 179 | { | |
| 180 | /** | |
| 181 | * Node/Id Hash for quickly handling node additions to the tree. | |
| 182 | */ | |
| 183 | var $_nodeHash = array(); | |
| 184 | ||
| 185 | /** | |
| 186 | * Menu parameters | |
| 187 | */ | |
| 188 | var $_params = null; | |
| 189 | ||
| 190 | /** | |
| 191 | * Menu parameters | |
| 192 | */ | |
| 193 | var $_buffer = null; | |
| 194 | ||
| 195 | function __construct(&$params) | |
| 196 | { | |
| 197 | $this->_params =& $params; | |
| 198 | $this->_root = new JMenuNode(0, 'ROOT'); | |
| 199 | $this->_nodeHash[0] =& $this->_root; | |
| 200 | $this->_current =& $this->_root; | |
| 201 | } | |
| 202 | ||
| 203 | function addNode($item) | |
| 204 | { | |
| 205 | // Get menu item data | |
| 206 | $data = $this->_getItemData($item); | |
| 207 | ||
| 208 | // Create the node and add it | |
| 209 | $node = new JMenuNode($item->id, $item->name, $item->access, $data); | |
| 210 | ||
| 211 | if (isset($item->mid)) { | |
| 212 | $nid = $item->mid; | |
| 213 | } else { | |
| 214 | $nid = $item->id; | |
| 215 | } | |
| 216 | $this->_nodeHash[$nid] =& $node; | |
| 217 | $this->_current =& $this->_nodeHash[$item->parent]; | |
| 218 | ||
| 219 | if ($this->_current) { | |
| 220 | $this->addChild($node, true); | |
| 221 | } else { | |
| 222 | // sanity check | |
| 223 | JError::raiseError( 500, 'Orphan Error. Could not find parent for Item '.$item->id ); | |
| 224 | } | |
| 225 | } | |
| 226 | ||
| 227 | function toXML() | |
| 228 | { | |
| 229 | // Initialize variables | |
| 230 | $this->_current =& $this->_root; | |
| 231 | ||
| 232 | // Recurse through children if they exist | |
| 233 | while ($this->_current->hasChildren()) | |
| 234 | { | |
| 235 | $this->_buffer .= '<ul>'; | |
| 236 | foreach ($this->_current->getChildren() as $child) | |
| 237 | { | |
| 238 | $this->_current = & $child; | |
| 239 | $this->_getLevelXML(0); | |
| 240 | } | |
| 241 | $this->_buffer .= '</ul>'; | |
| 242 | } | |
| 243 | if($this->_buffer == '') { $this->_buffer = '<ul />'; } | |
| 244 | return $this->_buffer; | |
| 245 | } | |
| 246 | ||
| 247 | function _getLevelXML($depth) | |
| 248 | { | |
| 249 | $depth++; | |
| 250 | ||
| 251 | // Start the item | |
| 252 | $this->_buffer .= '<li access="'.$this->_current->access.'" level="'.$depth.'" id="'.$this->_current->id.'">'; | |
| 253 | ||
| 254 | // Append item data | |
| 255 | $this->_buffer .= $this->_current->link; | |
| 256 | ||
| 257 | // Recurse through item's children if they exist | |
| 258 | while ($this->_current->hasChildren()) | |
| 259 | { | |
| 260 | $this->_buffer .= '<ul>'; | |
| 261 | foreach ($this->_current->getChildren() as $child) | |
| 262 | { | |
| 263 | $this->_current = & $child; | |
| 264 | $this->_getLevelXML($depth); | |
| 265 | } | |
| 266 | $this->_buffer .= '</ul>'; | |
| 267 | } | |
| 268 | ||
| 269 | // Finish the item | |
| 270 | $this->_buffer .= '</li>'; | |