/** * Install method * * @access public * @return boolean True on success */ public function install() { // Get a database connector object $db = $this->parent->getDBO(); $this->setManifest(); $plugin = $this->get('plugin'); $group = $this->get('group'); $type = $this->get('type'); $folder = $this->get('folder'); $extension = $this->get('extension'); // JCE Plugin if (!empty($plugin) || !empty($extension)) { if (version_compare((string) $this->get('version'), '2.0', '<')) { $this->parent->abort(WFText::_('WF_INSTALLER_INCORRECT_VERSION')); return false; } // its an "extension" if ($extension) { $this->parent->setPath('extension_root', JPATH_COMPONENT_SITE . '/editor/extensions/' . $folder); } else { $this->parent->setPath('extension_root', JPATH_COMPONENT_SITE . '/editor/tiny_mce/plugins/' . $plugin); } } else { // Non-JCE plugin type, probably JCE MediaBox if ($type == 'plugin' && $group == 'system') { require_once JPATH_LIBRARIES . '/joomla/installer/adapters/plugin.php'; // create adapter $adapter = new JInstallerPlugin($this->parent, $db); if (method_exists($adapter, 'loadLanguage')) { $adapter->loadLanguage($this->parent->getPath('source')); } // set adapter $this->parent->setAdapter('plugin', $adapter); // isntall return $adapter->install(); } else { $this->parent->abort(WFText::_('WF_INSTALLER_EXTENSION_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_NO_PLUGIN_FILE')); return false; } } /** * --------------------------------------------------------------------------------------------- * Filesystem Processing Section * --------------------------------------------------------------------------------------------- */ // If the extension directory does not exist, lets create it $created = false; if (!file_exists($this->parent->getPath('extension_root'))) { if (!($created = JFolder::create($this->parent->getPath('extension_root')))) { $this->parent->abort(WFText::_('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_MKDIR_ERROR') . ' : "' . $this->parent->getPath('extension_root') . '"'); return false; } } // Set overwrite flag if not set by Manifest $this->parent->setOverwrite(true); /* * If we created the extension directory and will want to remove it if we * have to roll back the installation, lets add it to the installation * step stack */ if ($created) { $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_root'))); } // Copy all necessary files if (!$this->parent->parseFiles($this->get('files'), -1)) { // Install failed, roll back changes $this->parent->abort(); return false; } // install languages $this->parent->parseLanguages($this->get('languages'), 0); // install media $this->parent->parseMedia($this->get('media'), 0); // Load the language file $language = JFactory::getLanguage(); $language->load('com_jce_' . trim($plugin), JPATH_SITE); $install = (string) $this->get('install.script'); if ($install) { // Make sure it hasn't already been copied (this would be an error in the xml install file) if (!file_exists($this->parent->getPath('extension_root') . '/' . $install)) { $path['src'] = $this->parent->getPath('source') . '/' . $install; $path['dest'] = $this->parent->getPath('extension_root') . '/' . $install; if (!$this->parent->copyFiles(array($path))) { // Install failed, rollback changes $this->parent->abort(WFText::_('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_PHP_INSTALL_FILE_ERROR')); return false; } } } $uninstall = $this->get('uninstall.script'); if ($uninstall) { // Make sure it hasn't already been copied (this would be an error in the xml install file) if (!file_exists($this->parent->getPath('extension_root') . '/' . $uninstall)) { $path['src'] = $this->parent->getPath('source') . '/' . $uninstall; $path['dest'] = $this->parent->getPath('extension_root') . '/' . $uninstall; if (!$this->parent->copyFiles(array($path))) { // Install failed, rollback changes $this->parent->abort(JText('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_PHP_UNINSTALL_FILE_ERROR')); return false; } } } /** * --------------------------------------------------------------------------------------------- * 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(WFText::_('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_SETUP_COPY_ERROR')); return false; } if ($install) { if (file_exists($this->parent->getPath('extension_root') . '/' . $install)) { ob_start(); ob_implicit_flush(false); require_once $this->parent->getPath('extension_root') . '/' . $install; if (function_exists('jce_install')) { if (jce_install() === false) { $this->parent->abort(WFText::_('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_CUSTOM_INSTALL_ERROR')); return false; } } else { if (function_exists('com_install')) { if (com_install() === false) { $this->parent->abort(WFText::_('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_CUSTOM_INSTALL_ERROR')); return false; } } } $msg = ob_get_contents(); ob_end_clean(); if ($msg != '') { $this->parent->set('extension.message', $msg); } } } else { $this->parent->set('extension.message', ''); } $plugin = new StdClass(); $plugin->name = $this->get('plugin'); $plugin->icon = $this->parent->get('icon'); $plugin->row = (int) $this->get('row'); $plugin->path = $this->parent->getPath('extension_root'); $plugin->type = $type; wfimport('admin.models.plugins'); $model = new WFModelPlugins(); $model->postInstall('install', $plugin, $this); return true; }
/** * Custom install method * * @access public * @return boolean True on success * @since 1.5 * Minor alteration - see below */ function install() { // 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 plugin name $name =& $this->manifest->getElementByPath('name'); $this->set('name', $name->data()); // Get the plugin description $description =& $this->manifest->getElementByPath('description'); if (is_a($description, 'JSimpleXMLElement')) { $this->parent->set('message', $description->data()); } else { $this->parent->set('message', ''); } $element =& $this->manifest->getElementByPath('files'); // Plugin name is specified $plugin = $this->manifest->attributes('plugin'); if (!empty($plugin)) { $this->parent->setPath('extension_root', JPATH_PLUGINS . DS . 'editors' . DS . 'jce' . DS . 'tiny_mce' . DS . 'plugins' . DS . $plugin); } else { $this->parent->abort('Extension Install: ' . JText::_('No JCE Plugin file specified')); return false; } /** * --------------------------------------------------------------------------------------------- * Filesystem Processing Section * --------------------------------------------------------------------------------------------- */ // If the extension directory does not exist, lets create it $created = false; 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') . '"'); return false; } } // Set overwrite flag if not set by Manifest $this->parent->setOverwrite(true); /* * If we created the extension directory and will want to remove it if we * have to roll back the installation, lets add it to the installation * step stack */ if ($created) { $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 $this->parent->abort(); return false; } // Parse optional tags -- language files for plugins $this->parent->parseLanguages($this->manifest->getElementByPath('languages'), 0); // If there is an install file, lets copy it. $installScriptElement =& $this->manifest->getElementByPath('installfile'); if (is_a($installScriptElement, 'JSimpleXMLElement')) { // Make sure it hasn't already been copied (this would be an error in the xml install file) if (!file_exists($this->parent->getPath('extension_root') . DS . $installScriptElement->data())) { $path['src'] = $this->parent->getPath('source') . DS . $installScriptElement->data(); $path['dest'] = $this->parent->getPath('extension_root') . DS . $installScriptElement->data(); if (!$this->parent->copyFiles(array($path))) { // Install failed, rollback changes $this->parent->abort(JText::_('Component') . ' ' . JText::_('Install') . ': ' . JText::_('Could not copy PHP install file.')); return false; } } $this->set('install.script', $installScriptElement->data()); } // If there is an uninstall file, lets copy it. $uninstallScriptElement =& $this->manifest->getElementByPath('uninstallfile'); if (is_a($uninstallScriptElement, 'JSimpleXMLElement')) { // Make sure it hasn't already been copied (this would be an error in the xml install file) if (!file_exists($this->parent->getPath('extension_root') . DS . $uninstallScriptElement->data())) { $path['src'] = $this->parent->getPath('source') . DS . $uninstallScriptElement->data(); $path['dest'] = $this->parent->getPath('extension_root') . DS . $uninstallScriptElement->data(); if (!$this->parent->copyFiles(array($path))) { // Install failed, rollback changes $this->parent->abort(JText::_('Component') . ' ' . JText::_('Install') . ': ' . JText::_('Could not copy PHP uninstall file.')); return false; } } } /** * --------------------------------------------------------------------------------------------- * Database Processing Section * --------------------------------------------------------------------------------------------- */ // Check to see if a plugin by the same name is already installed $query = 'SELECT id' . ' FROM #__jce_plugins' . ' WHERE name = ' . $db->Quote($plugin); $db->setQuery($query); if (!$db->Query()) { // Install failed, roll back changes $this->parent->abort('Plugin Install: ' . $db->stderr(true)); return false; } $id = $db->loadResult(); $row =& JTable::getInstance('plugin', 'JCETable'); if ($id) { if (!$this->parent->getOverwrite()) { // Install failed, roll back changes $this->parent->abort('Plugin Install: ' . JText::_('Plugin') . ' "' . $plugin . '" ' . JText::_('already exists!')); return false; } else { $row->load($id); } } $icon = $this->manifest->getElementByPath('icon'); $layout = $this->manifest->getElementByPath('layout'); $row->title = $this->get('name'); $row->name = $this->manifest->attributes('plugin'); $row->type = 'plugin'; $row->row = 4; $row->ordering = 1; $row->published = 1; $row->editable = 1; $row->icon = $icon->data(); $row->layout = $layout->data(); $row->iscore = 0; if (!$row->store()) { // Install failed, roll back changes $this->parent->abort('Plugin Install: ' . $db->stderr(true)); return false; } // Process default extension installation (files are assumed to have been copied!) $element =& $this->manifest->getElementByPath('extensions'); if (is_a($element, 'JSimpleXMLElement') && count($element->children())) { $extensions =& $element->children(); foreach ($extensions as $extension) { if ($extension->attributes('name')) { $query = 'INSERT INTO `#__jce_extensions` ' . ' VALUES ("", ' . (int) $row->id . ', ' . $db->Quote($extension->attributes('title')) . ', ' . $db->Quote($extension->attributes('name')) . ', ' . $db->Quote($extension->attributes('folder')) . ', 1 )'; $db->setQuery($query); if (!$db->query()) { // Install failed, raise error JError::raiseWarning(100, 'Plugin Install: Unable to install default extension ' . $extension->attributes('title')); return false; } } } } // 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)); /** * --------------------------------------------------------------------------------------------- * Install plugin into Default Group * --------------------------------------------------------------------------------------------- */ // Add to Default Group if ($row->type == 'plugin') { JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jce' . DS . 'groups'); $group =& JTable::getInstance('groups', 'JCETable'); $query = 'SELECT id' . ' FROM #__jce_groups' . ' WHERE name = ' . $db->Quote('Default'); $db->setQuery($query); $gid = $db->loadResult(); $group->load($gid); // Add to plugins list $plugins = explode(',', $group->plugins); if (!in_array($row->id, explode(',', $group->plugins))) { $group->plugins .= ',' . $row->id; } // Add to last row if plugin has a layout icon if ($row->layout) { if (!in_array($row->id, preg_split('/[;,]+/', $group->rows))) { $group->rows .= ',' . $row->id; } } if (!$group->store()) { JError::raiseWarning(100, 'Plugin Install: Unable to add plugin to Default group'); } } /** * --------------------------------------------------------------------------------------------- * 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')); return false; } /* * If we have an install script, lets include it, execute the custom * install method, and append the return value from the custom install * method to the installation message. */ if ($this->get('install.script')) { if (is_file($this->parent->getPath('extension_root') . DS . $this->get('install.script'))) { ob_start(); ob_implicit_flush(false); require_once $this->parent->getPath('extension_root') . DS . $this->get('install.script'); if (function_exists('jce_install')) { if (jce_install() === false) { $this->parent->abort(JText::_('Plugin') . ' ' . JText::_('Install') . ': ' . JText::_('Custom install routine failure')); return false; } } else { if (function_exists('com_install')) { if (com_install() === false) { $this->parent->abort(JText::_('Plugin') . ' ' . JText::_('Install') . ': ' . JText::_('Custom install routine failure')); return false; } } } $msg = ob_get_contents(); ob_end_clean(); if ($msg != '') { $this->parent->set('extension.message', $msg); } } } return true; }
/** * Install method * * @access public * @return boolean True on success */ public function install() { // Get a database connector object $db = $this->parent->getDBO(); // Get the extension manifest object $manifest = $this->parent->getManifest(); // setup manifest data $this->setManifest($manifest); $this->parent->set('name', $this->get('name')); $this->parent->set('version', $this->get('version')); $this->parent->set('message', $this->get('description')); $plugin = $this->get('plugin'); $group = $this->get('group'); $type = $this->get('type'); // JCE Plugin if (!empty($plugin)) { if (version_compare($this->get('version'), '2.0.0', '<')) { $this->parent->abort(WFText::_('WF_INSTALLER_INCORRECT_VERSION')); return false; } $this->parent->setPath('extension_root', JPATH_COMPONENT_SITE . DS . 'editor' . DS . 'tiny_mce' . DS . 'plugins' . DS . $plugin); } else { // Non-JCE plugin type, probably JCE MediaBox or JCE Editor if ($type == 'plugin' && ($group == 'system' || $group == 'editors')) { require_once JPATH_LIBRARIES . DS . 'joomla' . DS . 'installer' . DS . 'adapters' . DS . 'plugin.php'; $adapter = new JInstallerPlugin($this->parent, $db); $this->parent->setAdapter('plugin', $adapter); return $adapter->install(); } else { $this->parent->abort(WFText::_('WF_INSTALLER_EXTENSION_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_NO_PLUGIN_FILE')); return false; } } /** * --------------------------------------------------------------------------------------------- * Filesystem Processing Section * --------------------------------------------------------------------------------------------- */ // If the extension directory does not exist, lets create it $created = false; if (!file_exists($this->parent->getPath('extension_root'))) { if (!($created = JFolder::create($this->parent->getPath('extension_root')))) { $this->parent->abort(WFText::_('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_MKDIR_ERROR') . ' : "' . $this->parent->getPath('extension_root') . '"'); return false; } } // Set overwrite flag if not set by Manifest $this->parent->setOverwrite(true); /* * If we created the extension directory and will want to remove it if we * have to roll back the installation, lets add it to the installation * step stack */ if ($created) { $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_root'))); } // Copy all necessary files if (!$this->parent->parseFiles($this->get('files'), -1)) { // Install failed, roll back changes $this->parent->abort(); return false; } // install languages $this->parent->parseLanguages($this->get('languages'), 0); // install media $this->parent->parseMedia($this->get('media'), 0); // Load the language file $language = JFactory::getLanguage(); $language->load('com_jce_' . trim($plugin), JPATH_SITE); $install = $this->get('install.script'); if ($install) { // Make sure it hasn't already been copied (this would be an error in the xml install file) if (!file_exists($this->parent->getPath('extension_root') . DS . $install)) { $path['src'] = $this->parent->getPath('source') . DS . $install; $path['dest'] = $this->parent->getPath('extension_root') . DS . $install; if (!$this->parent->copyFiles(array($path))) { // Install failed, rollback changes $this->parent->abort(JText('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_PHP_INSTALL_FILE_ERROR')); return false; } } } $uninstall = $this->get('uninstall.script'); if ($uninstall) { // Make sure it hasn't already been copied (this would be an error in the xml install file) if (!file_exists($this->parent->getPath('extension_root') . DS . $uninstall)) { $path['src'] = $this->parent->getPath('source') . DS . $uninstall; $path['dest'] = $this->parent->getPath('extension_root') . DS . $uninstall; if (!$this->parent->copyFiles(array($path))) { // Install failed, rollback changes $this->parent->abort(JText('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_PHP_UNINSTALL_FILE_ERROR')); return false; } } } // Install plugin install default profile layout if a row is set if (is_numeric($this->get('row')) && intval($this->get('row'))) { // Add to Default Group $profile = JTable::getInstance('profiles', 'WFTable'); $query = 'SELECT id' . ' FROM #__wf_profiles' . ' WHERE name = ' . $db->Quote('Default'); $db->setQuery($query); $id = $db->loadResult(); $profile->load($id); // Add to plugins list $plugins = explode(',', $profile->plugins); if (!in_array($this->get('plugin'), $plugins)) { $plugins[] = $this->get('plugin'); } $profile->plugins = implode(',', $plugins); if ($this->get('icon')) { if (!in_array($this->get('plugin'), preg_split('/[;,]+/', $profile->rows))) { // get rows as array $rows = explode(';', $profile->rows); // get key (row number) $key = intval($this->get('row')) - 1; // get row contents as array $row = explode(',', $rows[$key]); // add plugin name to end of row $row[] = $this->get('plugin'); // add row data back to rows array $rows[$key] = implode(',', $row); $profile->rows = implode(';', $rows); } } if (!$profile->store()) { JError::raiseWarning(100, 'WF_INSTALLER_PLUGIN_PROFILE_ERROR'); } } /** * --------------------------------------------------------------------------------------------- * 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(WFText::_('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_SETUP_COPY_ERROR')); return false; } /* * If we have an install script, lets include it, execute the custom * install method, and append the return value from the custom install * method to the installation message. */ $install = $this->get('install.script'); if ($install) { if (file_exists($this->parent->getPath('extension_root') . DS . $install)) { ob_start(); ob_implicit_flush(false); require_once $this->parent->getPath('extension_root') . DS . $install; if (function_exists('jce_install')) { if (jce_install() === false) { $this->parent->abort(WFText::_('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_CUSTOM_INSTALL_ERROR')); return false; } } else { if (function_exists('com_install')) { if (com_install() === false) { $this->parent->abort(WFText::_('WF_INSTALLER_PLUGIN_INSTALL') . ' : ' . WFText::_('WF_INSTALLER_CUSTOM_INSTALL_ERROR')); return false; } } } $msg = ob_get_contents(); ob_end_clean(); if ($msg != '') { $this->parent->set('extension.message', $msg); } } } else { $this->parent->set('extension.message', ''); } // post-install $this->addIndexfiles(); return true; }