Source code for file /joomla/installer/adapters/plugin.php
Documentation is available at plugin.php
* @version $Id: plugin.php 6138 2007-01-02 03:44:18Z eddiea $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 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 within the rest of the framework
* @package Joomla.Framework
* @param object $parent Parent object [JInstaller instance]
$this->parent =
& $parent;
* @return boolean True on success
// Get a database connector object
$db =
& $this->parent->getDBO();
// Get the extension manifest object
$manifest =
& $this->parent->getManifest();
$this->manifest =
& $manifest->document;
* ---------------------------------------------------------------------------------------------
* Manifest Document Setup Section
* ---------------------------------------------------------------------------------------------
// Set the component name
$name =
& $this->manifest->getElementByPath('name');
$this->set('name', $name->data());
// Get the component description
$description =
& $this->manifest->getElementByPath('description');
if (is_a($description, 'JSimpleXMLElement')) {
$this->parent->set('message', $this->get('name').
'<p>'.
$description->data().
'</p>');
$this->parent->set('message', $this->get('name'));
* @todo Deprecate in future version
$type =
$this->manifest->attributes('type');
// Set the installation path
$element =
& $this->manifest->getElementByPath('files');
if (is_a($element, 'JSimpleXMLElement') &&
count($element->children())) {
$files =
& $element->children();
foreach ($files as $file) {
if ($file->attributes($type)) {
$pname =
$file->attributes($type);
$group =
$this->manifest->attributes('group');
if (!empty ($pname) &&
!empty($group)) {
$this->parent->setPath('extension_root', JPATH_ROOT.
DS.
'plugins'.
DS.
$group);
$this->parent->abort('Plugin Install: '.
JText::_('No plugin file specified'));
* ---------------------------------------------------------------------------------------------
* Filesystem Processing Section
* ---------------------------------------------------------------------------------------------
// If the plugin directory does not exist, lets create it
if (!file_exists($this->parent->getPath('extension_root'))) {
if (!$created =
JFolder::create($this->parent->getPath('extension_root'))) {
$this->parent->abort('Plugin Install: '.
JText::_('Failed to create directory').
': "'.
$this->parent->getPath('extension_root').
'"');
* If we created the plugin directory and will want to remove it if we
* have to roll back the installation, lets add it to the installation
$this->parent->pushStep(array ('type' =>
'folder', 'path' =>
$this->parent->getPath('extension_root')));
// Copy all necessary files
if ($this->parent->parseFiles($element, -
1) ===
false) {
// Install failed, roll back changes
// Parse optional tags -- media and language files for plugins go in admin app
$this->parent->parseMedia($this->manifest->getElementByPath('media'), 1);
$this->parent->parseLanguages($this->manifest->getElementByPath('languages'), 1);
* ---------------------------------------------------------------------------------------------
* Database Processing Section
* ---------------------------------------------------------------------------------------------
// Check to see if a plugin by the same name is already installed
' WHERE folder = '.
$db->Quote($group) .
' AND element = '.
$db->Quote($pname);
// Install failed, roll back changes
$this->parent->abort('Plugin Install: '.
$db->stderr(true));
// Was there a module already installed with the same name?
// Install failed, roll back changes
$this->parent->abort('Plugin Install: '.
JText::_('Plugin').
' "'.
$pname.
'" '.
JText::_('already exists!'));
$row->name =
$this->get('name');
$row->params =
$this->parent->getParams();
// Editor plugins are published by default
if ($group ==
'editors') {
// Install failed, roll back changes
$this->parent->abort('Plugin Install: '.
$db->stderr(true));
// Since we have created a plugin 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' =>
'plugin', 'id' =>
$row->id));
* ---------------------------------------------------------------------------------------------
* Finalization and Cleanup Section
* ---------------------------------------------------------------------------------------------
// Lastly, we will copy the manifest file to its appropriate place.
if (!$this->parent->copyManifest(-
1)) {
// Install failed, rollback changes
$this->parent->abort('Plugin Install: '.
JText::_('Could not copy setup file'));
* Custom uninstall method
* @param int $cid The id of the plugin to uninstall
* @param int $clientId The id of the client (unused)
* @return boolean True on success
$db =
& $this->parent->getDBO();
// First order of business will be to load the module object table from the database.
// This should give us the necessary information to proceed.
// Is the plugin we are trying to uninstall a core one?
// Because that is not a good idea...
// Get the plugin folder so we can properly build the plugin path
if (trim($row->folder) ==
'') {
// Set the plugin root path
$this->parent->setPath('extension_root', JPATH_ROOT.
DS.
'plugins'.
DS.
$row->folder);
// Because plugins don't have their own folders we cannot use the standard method of finding an installation manifest
$manifestFile =
JPATH_ROOT.
DS.
'plugins'.
DS.
$row->folder.
DS.
$row->element.
'.xml';
// If we cannot load the xml file return null
if (!$xml->loadFile($manifestFile)) {
* Check for a valid XML root tag.
* @todo: Remove backwards compatability in a future version
* Should be 'install', but for backward compatability we will accept 'mosinstall'.
if ($root->name() !=
'install' &&
$root->name() !=
'mosinstall') {
// Remove the plugin files
$this->parent->removeFiles($root->getElementByPath('images'), -
1);
$this->parent->removeFiles($root->getElementByPath('files'), -
1);
// Remove all media and languages as well
$this->parent->removeFiles($root->getElementByPath('media'));
$this->parent->removeFiles($root->getElementByPath('languages'), 1);
// Now we will no longer need the plugin object, so lets delete it
// If the folder is empty, let's delete it
$files =
JFolder::files($this->parent->getPath('extension_root'));
* - Roll back the plugin item
* @param array $arg Installation step to rollback
* @return boolean True on success
// Get database connector object
$db =
& $this->parent->getDBO();
// Remove the entry from the #__plugins table
' WHERE id='.(int)
$arg['id'];
return ($db->query() !==
false);