⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 component.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 2 页
字号:
		 * Custom Uninstallation Script Section		 * ---------------------------------------------------------------------------------------------		 */		// Now lets load the uninstall file if there is one and execute the uninstall function if it exists.		$uninstallfileElement =& $this->manifest->getElementByPath('uninstallfile');		if (is_a($uninstallfileElement, 'JSimpleXMLElement')) {			// Element exists, does the file exist?			if (is_file($this->parent->getPath('extension_administrator').DS.$uninstallfileElement->data())) {				ob_start();				ob_implicit_flush(false);				require_once ($this->parent->getPath('extension_administrator').DS.$uninstallfileElement->data());				if (function_exists('com_uninstall')) {					if (com_uninstall() === false) {						JError::raiseWarning(100, JText::_('Component').' '.JText::_('Uninstall').': '.JText::_('Custom Uninstall script unsuccessful'));						$retval = false;					}				}				$msg = ob_get_contents();				ob_end_clean();				if ($msg != '') {					$this->parent->set('extension.message', $msg);				}			}		}		/**		 * ---------------------------------------------------------------------------------------------		 * Database Processing Section		 * ---------------------------------------------------------------------------------------------		 */		/*		 * Let's run the uninstall queries for the component		 *	If backward compatibility is required - run queries in xml file		 *	If Joomla 1.5 compatible, with discreet sql files - execute appropriate		 *	file for utf-8 support or non-utf support		 */		$result = $this->parent->parseQueries($this->manifest->getElementByPath('uninstall/queries'));		if ($result === false) {			// Install failed, rollback changes			JError::raiseWarning(100, JText::_('Component').' '.JText::_('Uninstall').': '.JText::_('SQL Error')." ".$db->stderr(true));			$retval = false;		} elseif ($result === 0) {			// no backward compatibility queries found - try for Joomla 1.5 type queries			// second argument is the utf compatible version attribute			$utfresult = $this->parent->parseSQLFiles($this->manifest->getElementByPath('uninstall/sql'));			if ($utfresult === false) {				// Install failed, rollback changes				JError::raiseWarning(100, JText::_('Component').' '.JText::_('Uninstall').': '.JText::_('SQLERRORORFILE')." ".$db->stderr(true));				$retval = false;			}		}		$this->_removeAdminMenus($row);		/**		 * ---------------------------------------------------------------------------------------------		 * Filesystem Processing Section		 * ---------------------------------------------------------------------------------------------		 */		// Let's remove language files and media in the JROOT/images/ folder that are		// associated with the component we are uninstalling		$this->parent->removeFiles($this->manifest->getElementByPath('media'));		$this->parent->removeFiles($this->manifest->getElementByPath('languages'));		$this->parent->removeFiles($this->manifest->getElementByPath('administration/languages'), 1);		// Now we need to delete the installation directories.  This is the final step in uninstalling the component.		if (trim($row->option)) {			// Delete the component site directory			if (is_dir($this->parent->getPath('extension_site'))) {				if (!JFolder::delete($this->parent->getPath('extension_site'))) {					JError::raiseWarning(100, JText::_('Component').' '.JText::_('Uninstall').': '.JText::_('Unable to remove the component site directory'));					$retval = false;				}			}			// Delete the component admin directory			if (is_dir($this->parent->getPath('extension_administrator'))) {				if (!JFolder::delete($this->parent->getPath('extension_administrator'))) {					JError::raiseWarning(100, JText::_('Component').' '.JText::_('Uninstall').': '.JText::_('Unable to remove the component admin directory'));					$retval = false;				}			}			return $retval;		} else {			// No component option defined... cannot delete what we don't know about			JError::raiseWarning(100, 'Component Uninstall: Option field empty, cannot remove files');			return false;		}	}	/**	 * Method to build menu database entries for a component	 *	 * @access	private	 * @return	boolean	True if successful	 * @since	1.5	 */	function _buildAdminMenus()	{		// Get database connector object		$db =& $this->parent->getDBO();		// Initialize variables		$option = strtolower("com_".str_replace(" ", "", $this->get('name')));		// If a component exists with this option in the table than we don't need to add menus		// Grab the params for later		$query = 'SELECT id, params, enabled' .				' FROM #__components' .				' WHERE `option` = '.$db->Quote($option) .				' ORDER BY `parent` ASC';		$db->setQuery($query);		$componentrow = $db->loadAssoc(); // will return null on error		$exists = 0;		$oldparams = '';		// Check if menu items exist		if ($componentrow) {			// set the value of exists to be the value of the old id			$exists = $componentrow['id'];			// and set the old params			$oldparams = $componentrow['params'];			// and old enabled			$oldenabled = $componentrow['enabled'];			// Don't do anything if overwrite has not been enabled			if ( ! $this->parent->getOverwrite() ) {				return true;			}			// Remove existing menu items if overwrite has been enabled			if ( $option ) {				$sql = 'DELETE FROM #__components WHERE `option` = '.$db->Quote($option);				$db->setQuery($sql);				if (!$db->query()) {					JError::raiseWarning(100, JText::_('Component').' '.JText::_('Install').': '.$db->stderr(true));				}			}		}		// Ok, now its time to handle the menus.  Start with the component root menu, then handle submenus.		$menuElement = & $this->adminElement->getElementByPath('menu');		if (is_a($menuElement, 'JSimpleXMLElement')) {			$db_name = $menuElement->data();			$db_link = "option=".$option;			$db_menuid = 0;			$db_parent = 0;			$db_admin_menu_link = "option=".$option;			$db_admin_menu_alt = $menuElement->data();			$db_option = $option;			$db_ordering = 0;			$db_admin_menu_img = ($menuElement->attributes('img')) ? $menuElement->attributes('img') : 'js/ThemeOffice/component.png';			$db_iscore = 0;			// use the old params if a previous entry exists			$db_params = $exists ? $oldparams : $this->parent->getParams();			// use the old enabled field if a previous entry exists			$db_enabled = $exists ? $oldenabled : 1;			// This works because exists will be zero (autoincr)			// or the old component id			$query = 'INSERT INTO #__components' .				' VALUES( '.$exists .', '.$db->Quote($db_name).', '.$db->Quote($db_link).', '.(int) $db_menuid.',' .				' '.(int) $db_parent.', '.$db->Quote($db_admin_menu_link).', '.$db->Quote($db_admin_menu_alt).',' .				' '.$db->Quote($db_option).', '.(int) $db_ordering.', '.$db->Quote($db_admin_menu_img).',' .				' '.(int) $db_iscore.', '.$db->Quote($db_params).', '.(int) $db_enabled.' )';			$db->setQuery($query);			if (!$db->query()) {				// Install failed, rollback changes				$this->parent->abort(JText::_('Component').' '.JText::_('Install').': '.$db->stderr(true));				return false;			}			// save ourselves a call if we don't need it			$menuid = $exists ? $exists : $db->insertid(); // if there was an existing value, reuse			/*			 * Since we have created a menu item, we add it to the installation step stack			 * so that if we have to rollback the changes we can undo it.			 */			$this->parent->pushStep(array ('type' => 'menu', 'id' => $menuid));		} else {			/*			 * No menu element was specified so lets first see if we have an admin menu entry for this component			 * if we do.. then we obviously don't want to create one -- we'll just attach sub menus to that one.			 */			$query = 'SELECT id' .					' FROM #__components' .					' WHERE `option` = '.$db->Quote($option) .					' AND parent = 0';			$db->setQuery($query);			$menuid = $db->loadResult();			if (!$menuid) {				// No menu entry, lets just enter a component entry to the table.				$db_name = $this->get('name');				$db_link = "";				$db_menuid = 0;				$db_parent = 0;				$db_admin_menu_link = "";				$db_admin_menu_alt = $this->get('name');				$db_option = $option;				$db_ordering = 0;				$db_admin_menu_img = "";				$db_iscore = 0;				$db_params = $this->parent->getParams();				$db_enabled = 1;				$query = 'INSERT INTO #__components' .					' VALUES( "", '.$db->Quote($db_name).', '.$db->Quote($db_link).', '.(int) $db_menuid.',' .					' '.(int) $db_parent.', '.$db->Quote($db_admin_menu_link).', '.$db->Quote($db_admin_menu_alt).',' .					' '.$db->Quote($db_option).', '.(int) $db_ordering.', '.$db->Quote($db_admin_menu_img).',' .					' '.(int) $db_iscore.', '.$db->Quote($db_params).', '.(int) $db_enabled.' )';				$db->setQuery($query);				if (!$db->query()) {					// Install failed, rollback changes					$this->parent->abort(JText::_('Component').' '.JText::_('Install').': '.$db->stderr(true));					return false;				}				$menuid = $db->insertid();				/*				 * Since we have created a menu item, we add it to the installation step stack				 * so that if we have to rollback the changes we can undo it.				 */				$this->parent->pushStep(array ('type' => 'menu', 'id' => $menuid));			}		}		/*		 * Process SubMenus		 */		// Initialize submenu ordering value		$ordering = 0;		$submenu = $this->adminElement->getElementByPath('submenu');		if (!is_a($submenu, 'JSimpleXMLElement') || !count($submenu->children())) {			return true;		}		foreach ($submenu->children() as $child)		{			if (is_a($child, 'JSimpleXMLElement') && $child->name() == 'menu') {				$com =& JTable::getInstance('component');				$com->name = $child->data();				$com->link = '';				$com->menuid = 0;				$com->parent = $menuid;				$com->iscore = 0;				$com->admin_menu_alt = $child->data();				$com->option = $option;				$com->ordering = $ordering ++;				// Set the sub menu link				if ($child->attributes("link")) {					$com->admin_menu_link = str_replace('&', '&', $child->attributes("link"));				} else {					$request = array();					if ($child->attributes('act')) {						$request[] = 'act='.$child->attributes('act');					}					if ($child->attributes('task')) {						$request[] = 'task='.$child->attributes('task');					}					if ($child->attributes('controller')) {						$request[] = 'controller='.$child->attributes('controller');					}					if ($child->attributes('view')) {						$request[] = 'view='.$child->attributes('view');					}					if ($child->attributes('layout')) {						$request[] = 'layout='.$child->attributes('layout');					}					if ($child->attributes('sub')) {						$request[] = 'sub='.$child->attributes('sub');					}					$qstring = (count($request)) ? '&'.implode('&',$request) : '';					$com->admin_menu_link = "option=".$option.$qstring;				}				// Set the sub menu image				if ($child->attributes("img")) {					$com->admin_menu_img = $child->attributes("img");				} else {					$com->admin_menu_img = "js/ThemeOffice/component.png";				}				// Store the submenu				if (!$com->store()) {					// Install failed, rollback changes					$this->parent->abort(JText::_('Component').' '.JText::_('Install').': '.JText::_('SQL Error')." ".$db->stderr(true));					return false;				}				/*				 * Since we have created a menu item, we add it to the installation step stack				 * so that if we have to rollback the changes we can undo it.				 */				$this->parent->pushStep(array ('type' => 'menu', 'id' => $com->id));			}		}	}	/**	 * Method to remove admin menu references to a component	 *	 * @access	private	 * @param	object	$component	Component table object	 * @return	boolean	True if successful	 * @since	1.5	 */	function _removeAdminMenus(&$row)	{		// Get database connector object		$db =& $this->parent->getDBO();		$retval = true;		// Delete the submenu items		$sql = 'DELETE ' .				' FROM #__components ' .				'WHERE parent = '.(int)$row->id;		$db->setQuery($sql);		if (!$db->query()) {			JError::raiseWarning(100, JText::_('Component').' '.JText::_('Uninstall').': '.$db->stderr(true));			$retval = false;		}		// Next, we will delete the component object		if (!$row->delete($row->id)) {			JError::raiseWarning(100, JText::_('Component').' '.JText::_('Uninstall').': '.JText::_('Unable to delete the component from the database'));			$retval = false;		}		return $retval;	}	/**	 * Custom rollback method	 * 	- Roll back the component menu item	 *	 * @access	public	 * @param	array	$arg	Installation step to rollback	 * @return	boolean	True on success	 * @since	1.5	 */	function _rollback_menu($arg)	{		// Get database connector object		$db =& $this->parent->getDBO();		// Remove the entry from the #__components table		$query = 'DELETE ' .				' FROM `#__components` ' .				' WHERE id='.(int)$arg['id'];		$db->setQuery($query);		return ($db->query() !== false);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -