| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: ilink.php 21067 2011-04-03 22:21:04Z dextercowley $ 4 * @package Joomla 5 * @subpackage Menus 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant to the 9 * GNU General Public License, and as distributed it includes or is derivative 10 * of works licensed under the GNU General Public License or other free or open 11 * source software licenses. See COPYRIGHT.php for copyright notices and 12 * details. 13 */ 14 15 // Check to ensure this file is included in Joomla! 16 defined('_JEXEC') or die( 'Restricted access' ); 17 18 // Import library dependencies 19 jimport('joomla.base.tree'); 20 jimport('joomla.filesystem.folder'); 21 jimport('joomla.filesystem.file'); 22 23 /** 24 * Internal link builder 25 * 26 * @package Joomla 27 * @subpackage Menus 28 * @since 1.5 29 */ 30 class iLink extends JTree 31 { 32 var $_com = null; 33 var $_output = null; 34 var $_nodes = array(); 35 36 function __construct($component, $id=null, $menutype=null) 37 { 38 parent::__construct(); 39 40 if ($id) { 41 $this->_cid = "&cid[]=".$id; 42 } else { 43 $this->_cid = null; 44 } 45 46 if ($menutype) { 47 $this->_menutype = "&menutype=" . JFilterInput::clean($menutype, 'menutype'); 48 } else { 49 $this->_menutype = null; 50 } 51 52 $this->_com = preg_replace( '#\W#', '', $component ); 53 54 // Build the tree 55 if (!$this->_getOptions($this->_getXML(JPATH_SITE.'/components/com_'.$this->_com.'/metadata.xml', 'menu'), $this->_root)) { 56 if (!$this->_getViews()) 57 { 58 // Default behavior 59 } 60 } 61 } 62 63 /** 64 * Returns the component 65 * @return string 66 */ 67 function getComponent() 68 { 69 return $this->_com; 70 } 71 72 function getTree() 73 { 74 $depth = 0; 75 $this->reset(); 76 $class = null; 77 78 // Recurse through children if they exist 79 while ($this->_current->hasChildren()) 80 { 81 $this->_output .= '<ul>'; 82 $children = $this->_current->getChildren(); 83 for ($i=0,$n=count($children);$i<$n;$i++) 84 { 85 $this->_current = & $children[$i]; 86 $this->renderLevel($depth,($i==$n-1)?1:0); 87 } 88 $this->_output .= '</ul>'; 89 } 90 return $this->_output; 91 } 92 93 function renderLevel($depth, $isLast=0) 94 { 95 $depth++; 96 if (!isset($this->_depthHash[$depth])) { 97 $this->_depthHash[$depth] = 0; 98 } 99 $this->_depthHash[$depth]++; 100 101 if ($this->_current->hasChildren()) { 102 $classes = 'node-open'; 103 } else { 104 $classes = 'leaf'; 105 } 106 107 if ($isLast) { 108 $last = ' class="last"'; 109 } else { 110 $last = ''; 111 } 112 113 $parent = & $this->_current->getParent(); 114 // Print the item 115 $this->_output .= "<li".$last.">\n"; 116 117 // Print the url 118 $this->_output .= '<div class="' . $classes . '"><span></span>' 119 . '<a class="hasTip" '; 120 if (! $this->_current->hasChildren()) { 121 $this->_output .= 'href="index.php?option=com_menus' 122 . '&task=edit&type=component&' 123 . $this->_current->url . $this->_cid 124 . $this->_menutype . '" ' 125 ; 126 } 127 $this->_output .= 'title="' . JText::_($this->_current->title) 128 . '::' . JText::_($this->_current->msg) . '">' 129 . JText::_($this->_current->title) . '</a></div>' 130 ; 131 132 // Recurse through children if they exist 133 while ($this->_current->hasChildren()) 134 { 135 $this->_output .= "<ul>\n"; 136 $children = $this->_current->getChildren(); 137 for ($i=0,$n=count($children);$i<$n;$i++) 138 { 139 $this->_current = & $children[$i]; 140 $this->renderLevel($depth,($i==$n-1)?1:0); 141 } 142 $this->_output .= "</ul>\n"; 143 } 144 145 // Close item 146 $this->_output .= "</li>\n"; 147 } 148 149 function _getOptions($e, &$parent, $purl=null) 150 { 151 if (!$purl) { 152 $purl = 'url[option]=com_'.$this->_com; 153 154 // No metadata xml file in component root 155 if (!$e) { 156 return false; 157 } 158 } 159 160 // Does the metadata file say no options available? 161 if ($e->attributes('options') == 'none') { 162 unset($node); 163 $node = new iLinkNode($e->attributes('name'), $purl, $e->attributes('msg')); 164 $parent->addChild($node); 165 return true; 166 } 167 168 // Do we have defined options available? 169 $options = &$e->getElementByPath('options'); 170 if ($options) { 171 $children = $options->children(); 172 foreach ($children as $child) 173 { 174 if ($child->name() == 'option') { 175 $url = $purl.'&url['.$options->attributes('var').']='.$child->attributes('value'); 176 unset($node); 177 $node = new iLinkNode($child->attributes('name'), $url, $child->attributes('msg')); 178 $parent->addChild($node); 179 } elseif ($child->name() == 'default') { 180 unset($node); 181 $node = new iLinkNode($child->attributes('name'), $purl, $child->attributes('msg')); 182 $parent->addChild($node); 183 } 184 } 185 return true; 186 } else { 187 return false; 188 } 189 } 190 191 /** 192 * @access private 193 */ 194 function _getViews() 195 { 196 $return = false; 197 $path = JPATH_SITE.DS.'components'.DS.'com_'.$this->_com.DS.'views'; 198 199 if (JFolder::exists($path)) { 200 $views = JFolder::folders($path); 201 } else { 202 return $return; 203 } 204 205 if (is_array($views) && count($views)) 206 { 207 //$this->addChild(new iLinkNode('Views', null, 'Select the view'), true); 208 $return = true; 209 foreach ($views as $view) 210 { 211 if (strpos($view, '_') === false) { 212 // Load view metadata if it exists 213 $xmlpath = $path.DS.$view.DS.'metadata.xml'; 214 if (JFile::exists($xmlpath)) { 215 $data = $this->_getXML($xmlpath, 'view'); 216 } else { 217 $data = null; 218 } 219 220 $url = 'url[option]=com_'.$this->_com.'&url[view]='.$view; 221 if ($data) { 222 if ($data->attributes('hidden') != 'true') { 223 $m = $data->getElementByPath('message'); 224 $message = ($m) ? $m->data() : ''; 225 unset($node); 226 $node = new iLinkNode($data->attributes('title'), $url, $message); 227 $this->addChild($node); 228 if ($options = $data->getElementByPath('options')) { 229 $this->_getOptions($data, $node, $url); 230 } else { 231 $this->_getLayouts(dirname($xmlpath), $node); 232 } 233 } 234 } else { 235 $onclick = null; 236 unset($node); 237 $node = new iLinkNode(ucfirst($view), $url); 238 $this->addChild($node); 239 $this->_getLayouts(dirname($xmlpath), $node); 240 } 241 } 242 } 243 } 244 return $return; 245 } 246 247 /** 248 * @access private 249 */ 250 function _getLayouts($path, &$node) 251 { 252 $return = false; 253 $folder = $path.DS.'tmpl'; 254 if (is_dir( $folder )) 255 { 256 $files = JFolder::files($folder, '.php$'); 257 if (count($files)) { 258 foreach ($files as $file) 259 { 260 if (strpos($file, '_') === false) { 261 // Load view metadata if it exists 262 $layout = JFile::stripext($file); 263 $xmlpath = $path.DS.'tmpl'.DS.$layout.'.xml'; 264 if (JFile::exists($xmlpath)) { 265 $data = $this->_getXML($xmlpath, 'layout'); 266 } else { 267 $data = null; 268 } 269 270 if ($layout != 'default') { 271 $url = 'url[option]=com_'.$this->_com.'&url[view]='.basename($path).'&url[layout]='.$layout; 272 } else { 273 $url = 'url[option]=com_'.$this->_com.'&url[view]='.basename($path); 274 } 275 if ($data) { 276 if ($data->attributes('hidden') != 'true') { 277 $m = $data->getElementByPath('message'); 278 if ($m) { 279 $message = $m->data(); 280 } 281 unset($child); 282 $child = new iLinkNode($data->attributes('title'), $url, $message); 283 $node->addChild($child); 284 } 285 } else { 286 // Add default info for the layout 287 unset($child); 288 $child = new iLinkNode(ucfirst($layout).' '.JText::_('Layout'), $url); 289 $node->addChild($child); 290 } 291 } 292 } 293 } 294 } 295 return $return; 296 } 297 298 function _getXML($path, $xpath='control') 299 { 300 // Initialize variables 301 $result = null; 302 // load the xml metadata 303 if (file_exists( $path )) { 304 $xml =& JFactory::getXMLParser('Simple'); 305 if ($xml->loadFile($path)) { 306 if (isset( $xml->document )) { 307 $result = $xml->document->getElementByPath($xpath); 308 } 309 } 310 return $result; 311 } 312 return $result; 313 } 314 315 function _findNodes(&$node) 316 { 317 foreach ($node->children() as $step) 318 { 319 /* 320 * For each child we need to see if it is an include and if so we 321 * need to get those children and process them as well (break out into 322 * another method). Then we need to create the objects in the _steps 323 * array for each child of type step. For now we aren't going to handle 324 * nested includes. 325 */ 326 if ($step->name() == 'include') { 327 // Handle include 328 $this->_getIncludedSteps($step, $node); 329 } elseif ($step->name() == 'step') { 330 // Include step to array 331 $this->_nodes[] = $step; 332 } else { 333 // Do nothing 334 continue; 335 } 336 } 337 } 338 339 function _getIncludedSteps($include, &$parent) 340 { 341 $tags = array(); 342 $source = $include->attributes('source'); 343 $path = $include->attributes('path'); 344 345 preg_match_all( "/{([A-Za-z\-_]+)}/", $source, $tags); 346 if (isset( $tags[1] )) { 347 $n = count( $tags[1] ); 348 for ($i=0; $i < $n; $i++) 349 { 350 $source = str_replace($tags[0][$i], @$this->_vars[$tags[1][$i]], $source); 351 } 352 } 353 354 // load the source xml file 355 if (file_exists( JPATH_ROOT.$source )) 356 { 357 $xml = & JFactory::getXMLParser('Simple'); 358 if ($xml->loadFile(JPATH_ROOT.$source)) 359 { 360 $document = &$xml->document; 361 $steps = $document->getElementByPath($path); 362 363 foreach($steps->children() as $step) 364 { 365 if ($step->name() == 'include') { 366 // Handle include 367 } elseif ($step->name() == 'step') { 368 // Include step to array 369 $node->addChild('step', $step->attributes(), $node->level()+1); 370 } else { 371 // Do nothing 372 continue; 373 } 374 } 375 } 376 } 377 } 378 } 379 380 class iLinkNode extends JNode 381 { 382 /** 383 * Node Title 384 */ 385 var $title = null; 386 387 /** 388 * Node URL 389 */ 390 var $url = null; 391 392 /** 393 * Node message 394 */ 395 var $msg = null; 396 397 function __construct($title, $url = null, $msg = null) 398 { 399 $this->title = trim($title); 400 $this->url = $url; 401 $this->msg = trim($msg); 402 } 403 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |