enablePlugin($parent); } // Parse layouts $this->parseLayouts($parent->getParent()->getManifest()->layouts, $parent->getParent()); } /** * Enable plugin after installation * * @param InstallerAdapter $parent Parent object calling object. * * @return void * * @since 1.4.0 */ protected function enablePlugin($parent) { // Prepare plugin object $plugin = new stdClass(); $plugin->type = 'plugin'; $plugin->element = $parent->getElement(); $plugin->folder = (string) $parent->getParent()->manifest->attributes()['group']; $plugin->enabled = 1; // Update record Factory::getDbo()->updateObject('#__extensions', $plugin, array('type', 'element', 'folder')); } /** * Method to parse through a layout element of the installation manifest and take appropriate action. * * @param SimpleXMLElement $element The XML node to process. * @param Installer $installer Installer calling object. * * @return boolean True on success * * @since 1.6.2 */ public function parseLayouts(SimpleXMLElement $element, $installer) { if (!$element || !count($element->children())) { return false; } // Get destination $folder = ((string) $element->attributes()->destination) ? '/' . $element->attributes()->destination : null; $destination = Path::clean(JPATH_ROOT . '/layouts' . $folder); // Get source $folder = (string) $element->attributes()->folder; $source = ($folder && file_exists($installer->getPath('source') . '/' . $folder)) ? $installer->getPath('source') . '/' . $folder : $installer->getPath('source'); // Prepare files $copyFiles = array(); foreach ($element->children() as $file) { $path['src'] = Path::clean($source . '/' . $file); $path['dest'] = Path::clean($destination . '/' . $file); // Is this path a file or folder? $path['type'] = $file->getName() === 'folder' ? 'folder' : 'file'; if (basename($path['dest']) !== $path['dest']) { $newdir = dirname($path['dest']); if (!Folder::create($newdir)) { Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_CREATE_DIRECTORY', $newdir), Log::WARNING, 'jerror'); return false; } } $copyFiles[] = $path; } return $installer->copyFiles($copyFiles); } /** * This method is called after extension is uninstalled. * * @param InstallerAdapter $parent Parent object calling object. * * @return void * * @since 0.0.2 */ public function uninstall($parent) { // Remove layouts $this->removeLayouts($parent->getParent()->getManifest()->layouts); } /** * Method to parse through a layouts element of the installation manifest and remove the files that were installed. * * @param SimpleXMLElement $element The XML node to process. * * @return boolean True on success * * @since 1.6.2 */ protected function removeLayouts(SimpleXMLElement $element) { if (!$element || !count($element->children())) { return false; } // Get the array of file nodes to process $files = $element->children(); // Get source $folder = ((string) $element->attributes()->destination) ? '/' . $element->attributes()->destination : null; $source = Path::clean(JPATH_ROOT . '/layouts' . $folder); // Process each file in the $files array (children of $tagName). foreach ($files as $file) { $path = Path::clean($source . '/' . $file); // Actually delete the files/folders if (is_dir($path)) { $val = Folder::delete($path); } else { $val = File::delete($path); } if ($val === false) { Log::add('Failed to delete ' . $path, Log::WARNING, 'jerror'); $retval = false; } } if (!empty($folder)) { Folder::delete($source); } return $retval; } }