protected function getOptions() { $options = array(); $items = JCKHelper::getEditorToolbars(); // Build the field options. if (!empty($items)) { foreach ($items as $item) { $options[] = JHtml::_('select.option', $item, $item); } } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
function &getSelectedToolbarList() { $rows = array(); jckimport('helper'); $toolbars = JCKHelper::getEditorToolbars(); $cid = JRequest::getVar('cid', array(0), '', 'array'); JArrayHelper::toInteger($cid, array(0)); $db = JFactory::getDBO(); $query = 'SELECT title FROM #__jckplugins' . ' WHERE id = ' . $cid[0]; $db->setQuery($query); $pluginname = $db->loadResult(); if (!!$pluginname && !is_string($pluginname)) { JError::raiseError(500, $db->getErrorMsg()); } jckimport('helper'); $toolbarnames = JCKHelper::getEditorToolbars(); if (!empty($toolbarnames)) { require_once CKEDITOR_LIBRARY . DS . 'toolbar.php'; $CKfolder = CKEDITOR_LIBRARY . DS . 'toolbar'; foreach ($toolbarnames as $toolbarname) { $tmpfilename = $CKfolder . DS . $toolbarname . '.php'; require $tmpfilename; $classname = 'JCK' . ucfirst($toolbarname); $toolbar = new $classname(); $pluginTitle = str_replace(' ', '', $pluginname); //$pluginTitle = ucfirst($pluginTitle); leave it to plugin XML to captialize title if (!isset($toolbar->{$pluginTitle})) { continue; } $row = new stdclass(); $row->text = $toolbarname; $row->value = $toolbarname; $rows[] = $row; } } return $rows; }
function &getToolbarList() { $rows = array(); jckimport('helper'); $toolbars =& JCKHelper::getEditorToolbars(); if (!empty($toolbars)) { foreach ($toolbars as $toolbar) { $row = new stdclass(); $row->text = $toolbar; $row->value = $toolbar; $rows[] = $row; } } return $rows; }
/** * A JParameter object holding the parameters for the plugin * * @var A JParameter object * @access public * @since 1.5 */ function onSave($plugin, $pluginToolbarnames) { if (!$this->canDo->get('core.edit')) { $this->app->redirect(JRoute::_('index.php?option=com_jckman&view=list', false), JText::_('COM_JCKMAN_PLUGIN_PERM_NO_SAVE'), 'error'); return false; } require_once CKEDITOR_LIBRARY . DS . 'toolbar.php'; $CKfolder = CKEDITOR_LIBRARY . DS . 'toolbar'; jckimport('helper'); $toolbarnames = JCKHelper::getEditorToolbars(); if (!empty($toolbarnames)) { foreach ($toolbarnames as $toolbarname) { $tmpfilename = $CKfolder . DS . $toolbarname . '.php'; require $tmpfilename; $classname = 'JCK' . ucfirst($toolbarname); $toolbar = new $classname(); if (!$plugin->title) { //publish or unpblish plugin $this->onPublish(array($plugin->id), $plugin->published); return; } $pluginTitle = str_replace(' ', '', $plugin->title); $pluginTitle = $pluginTitle; //fix toolbar values or they will get wiped out foreach (get_object_vars($toolbar) as $k => $v) { if (is_null($v)) { $toolbar->{$k} = ''; } if ($k[0] == '_') { $toolbar->{$k} = NULL; } } $toolbar->{$pluginTitle} = NULL; if (!empty($pluginToolbarnames) && in_array($toolbarname, $pluginToolbarnames)) { $toolbar->{$pluginTitle} = ''; } $toolbarConfig = new JRegistry('toolbar'); $toolbarConfig->loadObject($toolbar); // Get the config registry in PHP class format and write it to file if (!JFile::write($tmpfilename, $toolbarConfig->toString('PHP', array('class' => $classname . ' extends JCKToolbar')))) { JCKHelper::error(JText::sprintf('COM_JCK_PLUGIN_LIST_FAILED_TO_MODIFY_TOOLBAR', $pname, $classname)); } } //layout stuff $cids = array(0); $db = JFactory::getDBO(); if (!empty($pluginToolbarnames)) { $values = array(); foreach ($pluginToolbarnames as $plugintoolbarname) { $query = 'SELECT id' . ' FROM #__jcktoolbars' . ' WHERE name = "' . $plugintoolbarname . '"'; $db->setQuery($query); $toolbarid = $db->loadResult(); if ($toolbarid) { $rowDetail = JCKHelper::getNextLayoutRow($toolbarid); $values[] = '(' . $toolbarid . ',' . $plugin->id . ',' . $rowDetail->rowid . ',' . $rowDetail->rowordering . ',1)'; $cids[] = $toolbarid; } } } //First remove plugin from every layout that has not been selected $query = 'DELETE FROM #__jcktoolbarplugins' . ' WHERE pluginid =' . $plugin->id . ' AND toolbarid NOT IN (' . implode(',', $cids) . ')'; $db->setQuery($query); if (!$db->query()) { JCKHelper::error($db->getErrorMsg()); } //Now add plugin to selected layouts if (!empty($values)) { $query = 'INSERT INTO #__jcktoolbarplugins(toolbarid,pluginid,row,ordering,state) VALUES ' . implode(',', $values) . ' ON DUPLICATE KEY UPDATE toolbarid = VALUES(toolbarid),pluginid = VALUES(pluginid)'; $db->setQuery($query); if (!$db->query()) { JCKHelper::error($db->getErrorMsg()); } } } //publish or unpblish plugin $this->onPublish(array($plugin->id), $plugin->published); }
/** * Custom uninstall method * * @access public * @param int $cid The id of the plugin to uninstall * @param int $clientId The id of the client (unused) * @return boolean True on success * @since 1.5 */ function uninstall($id) { // Initialize variables $row = null; $retval = true; $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. // ^ Changes to plugin parameters. Use JCK Plugins Table class. $row =& JTable::getInstance('plugin', 'JCKTable'); $row->load((int) $id); // Is the plugin we are trying to uninstall a core one? // Because that is not a good idea... if ($row->iscore) { JError::raiseWarning(100, 'Plugin Uninstall: ' . JText::sprintf('WARNCOREPLUGIN', $row->title) . "<br />" . JText::_('WARNCOREPLUGIN2')); return false; } // Get the plugin folder so we can properly build the plugin path if (trim($row->name) == '') { JError::raiseWarning(100, 'Plugin Uninstall: ' . JText::_('Plugin field empty, cannot remove files')); return false; } //Now delete dependencies $query = 'DELETE FROM #__jcktoolbarplugins' . ' WHERE pluginid =' . $row->id; $db->setQuery($query); if (!$db->query()) { JError::raiseWarning(100, $db->getErrorMsg()); } // Set the plugin root path $this->parent->setPath('extension_root', JCK_PLUGINS . DS . $row->name); $manifestFile = $this->parent->getPath('extension_root') . DS . $row->name . '.xml'; if (file_exists($manifestFile)) { // If we cannot load the xml file return null if (!($xml =& JFactory::getXML($manifestFile))) { JError::raiseWarning(100, 'Plugin Uninstall: ' . JText::_('Could not load manifest file')); return false; } $pname = (string) $xml->attributes()->plugin; if ((string) $xml->scriptfile) { $manifestScript = (string) $xml->scriptfile; $manifestScriptFile = $this->parent->getPath('extension_root') . DS . $manifestScript; if (is_file($manifestScriptFile)) { // load the file include_once $manifestScriptFile; } // Set the class name $classname = 'plgJCK' . $pname . 'InstallerScript'; if (class_exists($classname)) { // create a new instance $this->parent->manifestClass = new $classname($this); // and set this so we can copy it later $this->set('manifest_script', $manifestScript); // Note: if we don't find the class, don't bother to copy the file } // run preflight if possible ob_start(); ob_implicit_flush(false); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'preflight')) { if ($this->parent->manifestClass->preflight('uninstall', $this) === false) { // Install failed, rollback changes $this->parent->abort(JText::_('Installer abort for custom plugin install script')); return false; } } ob_end_clean(); ob_start(); ob_implicit_flush(false); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'uninstall')) { $this->parent->manifestClass->uninstall($this); } $msg = ob_get_contents(); // append messages ob_end_clean(); } /** * * Remove plugin from toolbars file AW * */ $CKfolder = CKEDITOR_LIBRARY . DS . 'toolbar'; $toolbarnames =& JCKHelper::getEditorToolbars(); foreach ($toolbarnames as $toolbarname) { $tmpfilename = $CKfolder . DS . $toolbarname . '.php'; require_once $tmpfilename; $classname = 'JCK' . ucfirst($toolbarname); $toolbar = new $classname(); $pluginTitle = str_replace(' ', '', $row->title); $pluginTitle = ucfirst($pluginTitle); if (!isset($toolbar->{$pluginTitle})) { continue; } //fix toolbar values or they will get wiped out foreach (get_object_vars($toolbar) as $k => $v) { if (is_null($v)) { $toolbar->{$k} = ''; } if ($k[0] == '_') { $toolbar->{$k} = NULL; } } $toolbar->{$pluginTitle} = NULL; $toolbarConfig = new JRegistry('toolbar'); $toolbarConfig->loadObject($toolbar); // Get the config registry in PHP class format and write it to configuation.php if (!JFile::write($tmpfilename, $toolbarConfig->toString('PHP', array('class' => $classname . ' extends JCKToolbar')))) { JError::raiseWarning(100, 'Failed to remove ' . $row->name . 'plugin from ' . $classname . ' toolbar'); } } /** * * Remove plugin from config file AW * */ $config =& JCKHelper::getEditorPluginConfig(); $config->setValue($row->name, NULL); // remove value from output $cfgFile = CKEDITOR_LIBRARY . DS . 'plugins' . DS . 'toolbarplugins.php'; // Get the config registry in PHP class format and write it to configuation.php if (!JFile::write($cfgFile, $config->toString('PHP', array('class' => 'JCKToolbarPlugins extends JCKPlugins')))) { JError::raiseWarning(100, 'Failed to remove ' . $pname . ' jckeditor plugin from config file'); } /* * 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'. */ $root =& $xml; if ($root->getName() != 'extension' && $root->getName() != 'install') { JError::raiseWarning(100, 'Plugin Uninstall: ' . JText::_('Invalid manifest file')); return false; } // Remove the plugin files $this->parent->removeFiles($root->files, -1); JFile::delete($manifestFile); // Remove all media and languages as well $this->parent->removeFiles($root->languages, 0); /** * --------------------------------------------------------------------------------------------- * Custom Uninstallation Script Section * --------------------------------------------------------------------------------------------- */ // Now lets load the uninstall file if there is one and execute the uninstall function if it exists. $uninstallfileElement =& $root->uninstallfile; if (is_a($uninstallfileElement, 'JXMLElement')) { // Element exists, does the file exist? if (is_file($this->parent->getPath('extension_root') . DS . $uninstallfileElement->data())) { ob_start(); ob_implicit_flush(false); require_once $this->parent->getPath('extension_root') . DS . $uninstallfileElement->data(); if (function_exists('com_uninstall')) { if (com_uninstall() === false) { JError::raiseWarning(100, JText::_('Plugin') . ' ' . JText::_('Uninstall') . ': ' . JText::_('Custom Uninstall script unsuccessful')); $retval = false; } } $msg = ob_get_contents(); ob_end_clean(); if ($msg != '') { $this->parent->set('extension.message', $msg); } } } } else { JError::raiseWarning(100, 'Plugin Uninstall: Manifest File invalid or not found. Plugin entry removed from database.'); $row->delete($row->id); unset($row); $retval = false; } // Now we will no longer need the plugin object, so lets delete it $row->delete($row->id); unset($row); // If the folder is empty, let's delete it $files = JFolder::files($this->parent->getPath('extension_root')); if (!count($files)) { JFolder::delete($this->parent->getPath('extension_root')); } //Now delete copy of plugin stored in the component $copyPath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'plugins' . DS . $pname; JFolder::delete($copyPath); return $retval; }
/** * Custom uninstall method * * @access public * @param int $cid The id of the plugin to uninstall * @param int $clientId The id of the client (unused) * @return boolean True on success * @since 1.5 */ function uninstall($id) { // Initialize variables $row = null; $retval = true; $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. // ^ Changes to plugin parameters. Use JCK Plugins Table class. $row =& JTable::getInstance('plugin', 'JCKTable'); $row->load((int) $id); // Is the plugin we are trying to uninstall a core one? // Because that is not a good idea... if ($row->iscore) { JCKHelper::error('Plugin Uninstall: ' . JText::sprintf('WARNCOREPLUGIN', $row->title) . "<br />" . JText::_('WARNCOREPLUGIN2')); return false; } // Get the plugin folder so we can properly build the plugin path if (trim($row->name) == '') { JCKHelper::error(JText::_('COM_JCKMAN_ADAPTER_PLUGIN_FIELD_EMPTY')); return false; } //Now delete dependencies $sql = $db->getQuery(true); $sql->delete('#__jcktoolbarplugins')->where('pluginid =' . $row->id); if (!$db->setQuery($sql)->query()) { JCKHelper::error($db->getErrorMsg()); } // Set the plugin root path $this->parent->setPath('extension_root', JCK_PLUGINS . DS . $row->name); $manifestFile = $this->parent->getPath('extension_root') . DS . $row->name . '.xml'; if (file_exists($manifestFile)) { // If we cannot load the xml file return null if (!($xml = JFactory::getXML($manifestFile))) { JCKHelper::error(JText::_('COM_JCKMAN_ADAPTER_UNINSTALL_COULD_NOT_LOAD_MANIFEST')); return false; } $pname = (string) $xml->attributes()->plugin; if ((string) $xml->scriptfile) { $manifestScript = (string) $xml->scriptfile; $manifestScriptFile = $this->parent->getPath('extension_root') . DS . $manifestScript; if (is_file($manifestScriptFile)) { // load the file include_once $manifestScriptFile; } // Set the class name $classname = 'plgJCK' . $pname . 'InstallerScript'; if (class_exists($classname)) { // create a new instance $this->parent->manifestClass = new $classname($this); // and set this so we can copy it later $this->set('manifest_script', $manifestScript); // Note: if we don't find the class, don't bother to copy the file } // run preflight if possible ob_start(); ob_implicit_flush(false); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'preflight')) { if ($this->parent->manifestClass->preflight('uninstall', $this) === false) { // Install failed, rollback changes $this->parent->abort(JText::_('COM_JCKMAN_ADAPTER_CUSTOM_ABORT')); return false; } } ob_end_clean(); ob_start(); ob_implicit_flush(false); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'uninstall')) { $this->parent->manifestClass->uninstall($this); } $msg = ob_get_contents(); // append messages ob_end_clean(); } /** * * Remove plugin from toolbars file AW * */ $CKfolder = CKEDITOR_LIBRARY . DS . 'toolbar'; $toolbarnames =& JCKHelper::getEditorToolbars(); foreach ($toolbarnames as $toolbarname) { $tmpfilename = $CKfolder . DS . $toolbarname . '.php'; require_once $tmpfilename; $classname = 'JCK' . ucfirst($toolbarname); $toolbar = new $classname(); $pluginTitle = str_replace(' ', '', $row->title); $pluginTitle = ucfirst($pluginTitle); if (!isset($toolbar->{$pluginTitle})) { continue; } //fix toolbar values or they will get wiped out foreach (get_object_vars($toolbar) as $k => $v) { if (is_null($v)) { $toolbar->{$k} = ''; } if ($k[0] == '_') { $toolbar->{$k} = NULL; } } $toolbar->{$pluginTitle} = NULL; $toolbarConfig = new JRegistry('toolbar'); $toolbarConfig->loadObject($toolbar); // Get the config registry in PHP class format and write it to configuation.php if (!JFile::write($tmpfilename, $toolbarConfig->toString('PHP', array('class' => $classname . ' extends JCKToolbar')))) { JCKHelper::error(JText::sprintf('COM_JCKMAN_ADAPTER_FAILED_TO_REMOVE_PLUGIN_TOOLBAR', $row->name, $classname)); } } /** * * Remove plugin from config file AW * */ $config =& JCKHelper::getEditorPluginConfig(); $config->set($row->name, NULL); // remove value from output $cfgFile = CKEDITOR_LIBRARY . DS . 'plugins' . DS . 'toolbarplugins.php'; // Get the config registry in PHP class format and write it to configuation.php if (!JFile::write($cfgFile, $config->toString('PHP', array('class' => 'JCKToolbarPlugins extends JCKPlugins')))) { JCKHelper::error(JText::sprintf('COM_JCKMAN_ADAPTER_FAILED_TO_REMOVE_PLUGIN_FROM_CONFIG', $pname)); } $root =& $xml; if ($root->getName() != 'extension' && $root->getName() != 'install') { JCKHelper::error(JText::_('COM_JCKMAN_ADAPTER_UNINSTALL_INVALID_MANIFEST')); return false; } // Remove the plugin files $this->parent->removeFiles($root->files, -1); JFile::delete($manifestFile); // Remove all media and languages as well $this->parent->removeFiles($root->languages, 0); } else { JCKHelper::error(Jtext::_('COM_JCKMAN_ADAPTER_UNINSTALL_INVALID_MANIFEST_OR_NOT_FOUND')); $row->delete($row->id); unset($row); $retval = false; } if ($row) { // Now we will no longer need the plugin object, so lets delete it $row->delete($row->id); unset($row); } // If the folder is empty, let's delete it $files = JFolder::files($this->parent->getPath('extension_root')); if (!count($files)) { JFolder::delete($this->parent->getPath('extension_root')); } //Now delete copy of plugin stored in the component $copyPath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'plugins' . DS . $pname; JFolder::delete($copyPath); return $retval; }