📄 item.php
字号:
<?php/** * @version $Id: item.php 11646 2009-03-01 19:34:56Z ian $ * @package Joomla * @subpackage Menus * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. * @license GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant to the * GNU General Public License, and as distributed it includes or is derivative * of works licensed under the GNU General Public License or other free or open * source software licenses. See COPYRIGHT.php for copyright notices and * details. */// Check to ensure this file is included in Joomla!defined('_JEXEC') or die( 'Restricted access' );jimport( 'joomla.application.component.model' );/** * @package Joomla * @subpackage Menus */class MenusModelItem extends JModel{ /** * Menu Item ID * * @var int */ var $_id = null; /** @var object JTable object */ var $_table = null; /** @var object JTable object */ var $_url = null; /** * Overridden constructor * @access protected */ function __construct() { parent::__construct(); $url = JRequest::getVar('url', array(), '', 'array'); if (isset($url['option'])) { $this->_url = 'index.php?option='.$url['option']; unset($url['option']); if (count($url)) { foreach ($url as $k => $v) { $this->_url .= '&'.$k.'='.$v; } } } $this->setId(); } function setId() { $array = JRequest::getVar('cid', array(0), '', 'array'); $this->_id = (int) $array[0]; if (!$this->_id) { $this->_id = JRequest::getInt('id', 0); } } function &getItem() { static $item; if (isset($item)) { return $item; } $table =& $this->_getTable(); // Load the current item if it has been defined $edit = JRequest::getVar('edit',true); $cid = JRequest::getVar( 'cid', array(0), '', 'array' ); JArrayHelper::toInteger($cid, array(0)); if ($edit) { $table->load($cid[0]); } // Override the current item's type field if defined in the request if ($type = JRequest::getString('type')) { $table->type = $type; } // Override the current item's menutype field if defined in the request if ($menu_type = JRequest::getString('menutype')) { $table->menutype = $menu_type; } switch ($table->type) { case 'separator': $table->link = null; $table->componentid = 0; break; case 'url': $table->componentid = 0; break; case 'menulink': $table->componentid = 0; break; case 'component': // Override the current item's link field if defined in the request if (!is_null($this->_url)) { $table->link = $this->_url; } $url = str_replace('index.php?', '', $table->link); $url = str_replace('&', '&', $url); $table->linkparts = null; if(strpos($url, '&') !== false) { $url = str_replace('&','&',$url); } parse_str($url, $table->linkparts); $db = &$this->getDBO(); if ($component = @$table->linkparts['option']) { $query = 'SELECT `id`' . ' FROM `#__components`' . ' WHERE `link` <> \'\'' . ' AND `parent` = 0' . ' AND `option` = "'.$db->getEscaped($component).'"'; $db->setQuery( $query ); $table->componentid = $db->loadResult(); } break; } $item = $table; return $item; } function &getExpansion() { $item = &$this->getItem(); $return['option'] = JRequest::getCmd('expand'); $menutype = JRequest::getString('menutype'); if ($return['option']) { require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_menus'.DS.'classes'.DS.'ilink.php'); $handler = new iLink($return['option'], $item->id, $menutype); $return['html'] = $handler->getTree(); return $return; } else { $return['html'] = null; } return $return; } function &getUrlParams() { // Get the state parameters $item =& $this->getItem(); $params = new JParameter(''); if ($state =& $this->_getStateXML()) { if (is_a($state, 'JSimpleXMLElement')) { $sp =& $state->getElementByPath('url'); $params->setXML($sp); if (isset($item->linkparts) && is_array($item->linkparts)) { $params->loadArray($item->linkparts); } } } return $params; } function &getStateParams() { // Get the state parameters $item =& $this->getItem(); $params = new JParameter($item->params); if ($state =& $this->_getStateXML()) { if (is_a($state, 'JSimpleXMLElement')) { $sp =& $state->getElementByPath('params'); $params->setXML($sp); } } return $params; } function &getAdvancedParams() { // Get the state parameters $item =& $this->getItem(); $params = new JParameter($item->params); if ($state =& $this->_getStateXML()) { if (is_a($state, 'JSimpleXMLElement')) { $ap =& $state->getElementByPath('advanced'); $params->setXML($ap); } } return $params; } function &getComponentParams() { // Initialize variables $params = null; $item = &$this->getItem(); if ($item->type == 'component') { $comp = &$this->getComponent(); $option = preg_replace( '#\W#', '', $comp->option ); $path = JPATH_ADMINISTRATOR.DS.'components'.DS.$option.DS.'config.xml'; $params = new JParameter( $item->params ); if (file_exists( $path )) { $xml =& JFactory::getXMLParser('Simple'); if ($xml->loadFile($path)) { $document =& $xml->document; // if hide is set, don't show the component configuration while editing menu item $menu = $document->attributes('menu'); if ( isset($menu) && $menu == 'hide' ) { $params = null; return $params; } if (isset($document->params[0]->param)) { // We will collect the hidden elements in an array // loop will mess up if we do it within the loop $hide = array(); for ($i=0,$n=count($document->params[0]->param); $i<$n; $i++) { if ($document->params[0]->param[$i]->attributes('menu') == 'hide') { $hide[] = &$document->params[0]->param[$i]; } else if ($document->params[0]->param[$i]->attributes('type') == 'radio' || $document->params[0]->param[$i]->attributes('type') == 'list') { $document->params[0]->param[$i]->addAttribute('default', ''); $document->params[0]->param[$i]->addAttribute('type', 'list'); $child = &$document->params[0]->param[$i]->addChild('option', array('value' => '')); $child->setData('Use Global'); } } // Now remove any hidden elements for ($i = 0, $n = count( $hide ); $i < $n; $i++) { $document->params[0]->removeChild( $hide[$i] ); } } $params->setXML( $document->params[0] ); } } } return $params; } function &getSystemParams() { // Initialize variables $params = null; $item = &$this->getItem(); $params = new JParameter( $item->params ); if ($item->type == 'component') { $path = JPATH_BASE.DS.'components'.DS.'com_menus'.DS.'models'.DS.'metadata'.DS.'component.xml'; if (file_exists( $path )) { $xml =& JFactory::getXMLParser('Simple'); if ($xml->loadFile($path)) { $document =& $xml->document; $params->setXML($document->getElementByPath('state/params')); } } } return $params; } /** * Get the name of the current menu item * * @return string * @access public * @since 1.5 */ function getStateName() { $state =& $this->_getStateXML(); if ( ! is_a($state, 'JSimpleXMLElement')) { return null; } $name = null; $sn =& $state->getElementByPath('name'); if ($sn) { $name = $sn->data(); } return JText::_($name); } /** * Get the description of the current menu item * * @return string * @access public * @since 1.5 */ function getStateDescription() { $state =& $this->_getStateXML(); if ( ! is_a($state, 'JSimpleXMLElement')) { return null; } $description = null; $sd =& $state->getElementByPath('description'); if ($sd) { $description = $sd->data(); } return JText::_($description); } /** * Gets the componet table object related to this menu item */ function &getComponent() { $item =& $this->getItem(); $id = $item->componentid; $component = & JTable::getInstance( 'component'); $component->load( $id ); return $component; } function checkout($uid = null) { $id = JRequest::getVar('cid', array(0), '', 'array'); JArrayHelper::toInteger( $id, array(0) ); // Make sure we have a user id to checkout the article with if (is_null($uid)) { $user =& JFactory::getUser(); $uid = $user->get('id'); } // Lets get to it and checkout the thing... $item =& $this->getItem(); if(!$item->checkout($uid, $id[0])) { $this->setError($this->_db->getErrorMsg()); return false; } return true; } function checkin() { if ($this->_id) { $item =& $this->_getTable(); if(!$item->checkin($this->_id)) { $this->setError($this->_db->getErrorMsg()); return false; } return true; } return false; } function store() { // Initialize variables $db =& JFactory::getDBO(); $row =& $this->getItem();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -