Esempio n. 1
0
    public function onSync()
    {
        if (!$this->canDo->get('jckman.sync')) {
            $this->app->redirect(JRoute::_('index.php?option=com_jckman&view=cpanel', false), JText::_('COM_JCKMAN_PLUGIN_PERM_NO_SYNC'), 'error');
            return false;
        }
        jimport('joomla.filesystem.file');
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'pluginoverrides.php';
        $dest = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'jckeditor' . DS . 'includes' . DS . 'ckeditor' . DS . 'plugins' . DS . 'editor' . DS . 'pluginoverrides.php';
        if (!JFile::copy($src, $dest)) {
            $this->app->enqueueMessage(JText::_('COM_JCKMAN_CPANEL_UNABLE_MOVE_PLUGINOVERRIDES_PLUGIN'));
        }
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'acl.php';
        $dest = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'jckeditor' . DS . 'includes' . DS . 'ckeditor' . DS . 'plugins' . DS . 'editor' . DS . 'acl.php';
        if (!JFile::copy($src, $dest)) {
            $this->app->enqueueMessage(JText::_('COM_JCKMAN_CPANEL_UNABLE_MOVE_ACL_PLUGIN'));
        }
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'components.php';
        $dest = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'jckeditor' . DS . 'includes' . DS . 'ckeditor' . DS . 'plugins' . DS . 'toolbar' . DS . 'components.php';
        if (!JFile::copy($src, $dest)) {
            $this->app->enqueueMessage(JText::_('COM_JCKMAN_CPANEL_UNABLE_MOVE_COMPONENTS_PLUGIN'));
        }
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'plugins.php';
        $dest = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'jckeditor' . DS . 'includes' . DS . 'ckeditor' . DS . 'plugins.php';
        if (!JFile::copy($src, $dest)) {
            $this->app->enqueueMessage(JText::_('COM_JCKMAN_CPANEL_UNABLE_MOVE_BASE_PLUGIN'));
        }
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'scayt.xml';
        $dest = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'plugins' . DS . 'scayt' . DS . 'scayt.xml';
        if (!JFile::copy($src, $dest)) {
            $this->app->enqueueMessage(JText::_('COM_JCKMAN_CPANEL_UNABLE_MOVE_SCAYT_PLUGIN'));
        }
        //Lets try and restore  broken or removed plugins from backup
        require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'helpers' . DS . 'restorer.php';
        $restorer = JCKRestorer::getInstance();
        $srcBase = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'plugins' . DS;
        $destBase = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'plugins' . DS;
        $folders = JFolder::folders($srcBase);
        foreach ($folders as $folder) {
            $src = $srcBase . $folder;
            if (!$restorer->install($src)) {
                $this->app->enqueueMessage(JText::sprintf('COM_JCKMAN_CPANEL_UNABLE_RESTORE_FOLDER', $folder), 'error');
            } else {
                $this->app->enqueueMessage(JText::sprintf('COM_JCKMAN_CPANEL_SUCESSFULLY_RESTORE_FOLDER', $folder));
            }
        }
        //check whether plugin is not a core plugin
        //if its not iterate through and see if there are files missing
        //then delete the plugin if there are
        $db = JFactory::getDBO();
        $query = 'SELECT p.id, p.name FROM `#__jckplugins` p WHERE p.iscore = 0';
        $results = $db->setQuery($query)->loadObjectList();
        if (!empty($results)) {
            for ($i = 0; $i < count($results); $i++) {
                if (!JFolder::exists(JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'plugins' . DS . $results[$i]->name)) {
                    $query = 'DELETE FROM #__jcktoolbarplugins
								WHERE pluginid =' . $results[$i]->id;
                    $db->setQuery($query)->query();
                    $query = 'DELETE FROM #__jckplugins
								WHERE id =' . $results[$i]->id;
                    $db->setQuery($query)->query();
                }
            }
            //end for loop
        }
        //check for plugins that have not been added to layout -- legacy check
        $query = 'SELECT id,name FROM `#__jcktoolbars`';
        $toolbars = $db->setQuery($query)->loadObjectList();
        $JCKfolder = CKEDITOR_LIBRARY . DS . 'toolbar';
        $values = array();
        if (!empty($toolbars)) {
            require_once CKEDITOR_LIBRARY . DS . 'toolbar.php';
            //update core plugins layout if needed
            foreach ($toolbars as $row) {
                // get the total number of core plugin records
                $sql = $db->getQuery(true);
                $sql->select('COUNT(*)')->from('#__jcktoolbarplugins tp')->join('INNER', '#__jckplugins p ON tp.pluginid = p.id')->where('tp.toolbarid =' . (int) $row->id)->where('p.iscore = 1');
                $totalRows = $db->setQuery($sql)->loadResult();
                if (!$totalRows) {
                    $filename = $JCKfolder . DS . $row->name . '.php';
                    require_once $filename;
                    $classname = 'JCK' . ucfirst($row->name);
                    $toolbar = new $classname();
                    $sql = $db->getQuery(true);
                    $sql->select('p.id, p.title')->from('#__jckplugins p')->join('LEFT', '#__jckplugins parent ON parent.id = p.parentid AND parent.published = 1')->where('p.title != ""')->where('p.published = 1')->where('p.iscore = 1')->where('(p.parentid IS NULL OR parent.published = 1)');
                    $allplugins = $db->setQuery($sql)->loadObjectList();
                    $values = array();
                    //fix toolbar values or they will get wiped out
                    $l = 1;
                    $n = 1;
                    $j = 1;
                    foreach (get_object_vars($toolbar) as $k => $v) {
                        if ($v) {
                            $n = $n > $v ? $n : $v;
                        }
                        if ($l < $n) {
                            $l = $n;
                            $j = 1;
                        }
                        for ($m = 0; $m < count($allplugins); $m++) {
                            if ($k == $allplugins[$m]->title) {
                                $values[] = '(' . (int) $row->id . ',' . (int) $allplugins[$m]->id . ',' . $n . ',' . $j . ',1)';
                                break;
                            }
                            if (strpos($k, 'brk_') !== false) {
                                $id = preg_match('/[0-9]+$/', $k);
                                $id = $id * -1;
                                $values[] = '(' . (int) $row->id . ',' . $id . ',' . $n . ',' . $j . ',1)';
                                $n++;
                                break;
                            }
                        }
                        $j++;
                    }
                    if (!empty($values)) {
                        $query = 'INSERT INTO #__jcktoolbarplugins(toolbarid,pluginid,row,ordering,state) VALUES ' . implode(',', $values);
                        $db->setQuery($query);
                        if (!$db->query()) {
                            JCKHelper::error($db->getErrorMsg());
                        }
                    }
                }
            }
            //update non core plugins layout
            $values = array();
            foreach ($toolbars as $row) {
                $query = 'SELECT id,title FROM `#__jckplugins` p WHERE p.title != "" AND p.iscore = 0  AND p.published = 1' . ' AND NOT EXISTS(SELECT 1 FROM  #__jcktoolbarplugins tp WHERE tp.pluginid = p.id AND tp.toolbarid = ' . $row->id . ')';
                $plugins = $db->setQuery($query)->loadObjectList();
                $tmpfilename = $JCKfolder . DS . $row->name . '.php';
                if (!file_exists($tmpfilename)) {
                    continue;
                }
                //skip
                require_once $tmpfilename;
                $classname = 'JCK' . ucfirst($row->name);
                $toolbar = new $classname();
                $rowDetail = JCKHelper::getNextLayoutRow($row->id);
                foreach (get_object_vars($toolbar) as $k => $v) {
                    foreach ($plugins as $plugin) {
                        if ($plugin->title == $k) {
                            $values[] = '(' . $row->id . ',' . $plugin->id . ',' . $rowDetail->rowid . ',' . $rowDetail->rowordering . ',1)';
                            $rowDetail->rowordering++;
                        }
                    }
                }
            }
        }
        //Now add plugins to 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());
            }
        }
        //Reload Toolbar if editor is re-installed
        jckimport('event.observable.editor');
        $obs = new JCKEditorObservable('toolbars');
        $handle = $obs->getEventHandler();
        $query = 'SELECT * FROM `#__jcktoolbars` t WHERE exists(SELECT 1 FROM  #__jcktoolbarplugins tp WHERE tp.toolbarid  = t.id)';
        $rowresults = $db->setQuery($query)->loadObjectList();
        foreach ($rowresults as $row) {
            $id = $row->id;
            $name = $row->name;
            $title = $row->title;
            switch ($name) {
                case 'publisher':
                case 'full':
                case 'basic':
                case 'blog':
                case 'image':
                case 'mobile':
                    $isNew = false;
                    break;
                default:
                    $isNew = true;
                    break;
            }
            //end switch
            $handle->onSave($id, $name, $name, $title, $isNew);
        }
        //restore state of published/unpublished plugins
        $obs = new JCKEditorObservable('list');
        $handle = $obs->getEventHandler();
        $where = array();
        $where[] = ' WHERE p.published = 1';
        $where[] = ' WHERE p.published = 0';
        $state = array(1, 0);
        $count = count($where);
        $db = JFactory::getDBO();
        for ($i = 0; $i < $count; $i++) {
            $query = 'SELECT id FROM `#__jckplugins` p' . $where[$i] . ' AND p.iscore = 1 AND type="plugin"';
            $results = $db->setQuery($query)->loadColumn();
            $handle->onPublish($results, $state[$i]);
        }
        //restore language overrides
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'overrides';
        $dest = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'language' . DS . 'overrides';
        $files = JFolder::files($src);
        foreach ($files as $file) {
            if ($file == 'index.html') {
                continue;
            }
            $source = $src . '/' . $file;
            $path = $dest . '/' . $file;
            if (JFile::exists($file)) {
                $this->app->enqueueMessage(JText::sprintf('COM_JCKMAN_CPANEL_LANGUAGE_EXISTS', $file), 'warning');
            } elseif (!JFile::copy($source, $path)) {
                $this->app->enqueueMessage(JText::sprintf('COM_JCKMAN_CPANEL_UNABLE_RESTORE_LANGUAGE', $file), 'error');
            } else {
                $this->app->enqueueMessage(JText::sprintf('COM_JCKMAN_CPANEL_SUCESSFULLY_RESTORE_LANGUAGE', $file));
            }
        }
        $this->app->enqueueMessage(JText::_('COM_JCKMAN_CPANEL_EDITOR_SYNCHRONIZED'));
    }
 /**
  * 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;
     //$manifest->document;
     /**
      * ---------------------------------------------------------------------------------------------
      * Manifest Document Setup Section
      * ---------------------------------------------------------------------------------------------
      */
     // Set the component name
     $name = '';
     if ($this->manifest->name) {
         $name = $this->manifest->name;
         $this->set('name', $name->data());
     } else {
         $this->set('name', '');
     }
     // Get the component description
     $description =& $this->manifest->description;
     if (is_a($description, 'JXMLElement')) {
         $this->parent->set('message', $description->data());
     } else {
         $this->parent->set('message', '');
     }
     $element =& $this->manifest->files;
     // Plugin name is specified
     $pname = (string) $this->manifest->attributes()->plugin;
     //Get type
     $type = $this->manifest->attributes()->group;
     if (!empty($pname)) {
         // ^ Use JCK_PLUGINS defined path
         $this->parent->setPath('extension_root', JCK_PLUGINS . DS . $pname);
     } else {
         $this->parent->abort('Extension Install: ' . JText::_('No plugin specified'));
         return false;
     }
     if ((string) $manifest->scriptfile) {
         $manifestScript = (string) $manifest->scriptfile;
         $manifestScriptFile = $this->parent->getPath('source') . 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('install', $this) === false) {
                 // Install failed, rollback changes
                 $this->parent->abort(JText::_('Installer abort for custom plugin install script'));
                 return false;
             }
         }
         ob_end_clean();
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * 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;
         }
     }
     /*
      * 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->languages, 0);
     // If there is an install file, lets copy it.
     $installScriptElement =& $this->manifest->installfile;
     if (is_a($installScriptElement, 'JXMLElement')) {
         // 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->uninstallfile;
     if (is_a($uninstallScriptElement, 'JXMLElement')) {
         // 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 . $uninstallScriptElpement->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
      * ---------------------------------------------------------------------------------------------
      */
     $type = isset($type) ? (string) $type : 'plugin';
     //Add group processimg
     // Check to see if a plugin by the same name is already installed
     // ^ Altered db query for #__JCK_PLUGINS
     $query = 'SELECT `id`' . ' FROM `#__jckplugins`' . ' WHERE name = ' . $db->Quote($pname);
     $db->setQuery($query);
     if (!$db->Query()) {
         // Install failed, roll back changes
         $this->parent->abort('Plugin Install: ' . $db->stderr(true));
         return false;
     }
     $id = $db->loadResult();
     // Was there a module already installed with the same name?
     if ($id) {
         if (!$this->parent->getOverwrite()) {
             // Install failed, roll back changes
             $this->parent->abort('Plugin Install: ' . JText::_('Plugin') . ' "' . $pname . '" ' . JText::_('already exists!'));
             return false;
         }
         $row =& JTable::getInstance('plugin', 'JCKTable');
         $row->type = $type;
         $row->load($id);
     } else {
         $icon = $this->manifest->icon;
         // ^ Changes to plugin parameters. Use JCK Plugins Table class.
         $row =& JTable::getInstance('plugin', 'JCKTable');
         $row->title = $this->get('name');
         $row->name = $pname;
         $row->type = $type;
         $row->row = 4;
         $row->published = 1;
         $row->editable = 1;
         $row->icon = $icon ? $icon->data() : '';
         $row->iscore = 0;
         $row->params = $this->parent->getParams();
         if ($this->manifest->attributes()->parent) {
             $parentName = (string) $this->manifest->attributes()->parent;
             $row->setParent($parentName);
         }
         if (!$row->store()) {
             // Install failed, roll back changes
             $this->parent->abort('Plugin Install: ' . $db->stderr(true));
             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));
     }
     /* -------------------------------------------------------------------------------------------
      * update editor plugin config file    AW 
      * -------------------------------------------------------------------------------------------
      */
     $config =& JCKHelper::getEditorPluginConfig();
     $config->setValue($pname, 1);
     $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 publish ' . $pname . ' jckeditor plugin');
     }
     /**
      *-------------------------------------------------------------------------------------------
      * Add plugin to toolbars
      *-------------------------------------------------------------------------------------------
      */
     $CKfolder = CKEDITOR_LIBRARY . DS . 'toolbar';
     //$toolbarnames =& JCKHelper::getEditorToolbars();
     $toolbarnames = JRequest::getVar('selections', array());
     if (!empty($toolbarnames) && $row->icon) {
         $values = array();
         foreach ($toolbarnames as $toolbarname) {
             $tmpfilename = $CKfolder . DS . $toolbarname . '.php';
             require $tmpfilename;
             $classname = 'JCK' . ucfirst($toolbarname);
             $toolbar = new $classname();
             $pluginTitle = str_replace(' ', '', $row->title);
             $pluginTitle = $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} = '';
             $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 add ' . $pname . 'plugin to  ' . $classname . ' toolbar');
             }
             //layout stuff
             $query = 'SELECT id' . ' FROM #__jcktoolbars' . ' WHERE name = "' . $toolbarname . '"';
             $db->setQuery($query);
             $toolbarid = $db->loadResult();
             if (!$toolbarid) {
                 continue;
             }
             $rowDetail = JCKHelper::getNextLayoutRow($toolbarid);
             $values[] = '(' . $toolbarid . ',' . $row->id . ',' . $rowDetail->rowid . ',' . $rowDetail->rowordering . ',1)';
         }
         //insert into layout table
         if (!empty($values)) {
             //Now delete dependencies
             $query = 'DELETE FROM #__jcktoolbarplugins' . ' WHERE pluginid =' . $row->id;
             $db->setQuery($query);
             if (!$db->query()) {
                 JError::raiseWarning(100, $db->getErrorMsg());
             }
             $query = 'INSERT INTO #__jcktoolbarplugins(toolbarid,pluginid,row,ordering,state) VALUES ' . implode(',', $values);
             $db->setQuery($query);
             if (!$db->query()) {
                 JError::raiseWarning(100, $db->getErrorMsg());
             }
         }
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * Custom Installation Script Section
      * ---------------------------------------------------------------------------------------------
      */
     /*
      * 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('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);
             }
         }
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * 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;
     }
     //make a copy of the plugin
     $src = $this->parent->getPath('extension_root');
     $dest = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'plugins' . DS . $pname;
     if (!JFolder::copy($src, $dest, null, true)) {
         // Install failed, roll back changes
         $this->parent->abort();
         return false;
     }
     // And now we run the postflight
     ob_start();
     ob_implicit_flush(false);
     if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'postflight')) {
         $this->parent->manifestClass->postflight('install', $this);
     }
     ob_end_clean();
     return true;
 }
Esempio n. 3
0
 /**
  * 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);
 }
Esempio n. 4
0
    public function onSync()
    {
        $mainframe = JFactory::getApplication();
        jimport('joomla.filesystem.file');
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'pluginoverrides.php';
        $dest = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'jckeditor' . DS . 'includes' . DS . 'ckeditor' . DS . 'plugins' . DS . 'editor' . DS . 'pluginoverrides.php';
        if (!JFile::copy($src, $dest)) {
            $mainframe->enqueueMessage(JText::_('Unable to move pluginoverrides JCK plugin!'));
        }
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'acl.php';
        $dest = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'jckeditor' . DS . 'includes' . DS . 'ckeditor' . DS . 'plugins' . DS . 'editor' . DS . 'acl.php';
        if (!JFile::copy($src, $dest)) {
            $mainframe->enqueueMessage(JText::_('Unable to move ACL JCK plugin!'));
        }
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'components.php';
        $dest = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'jckeditor' . DS . 'includes' . DS . 'ckeditor' . DS . 'plugins' . DS . 'toolbar' . DS . 'components.php';
        if (!JFile::copy($src, $dest)) {
            $mainframe->enqueueMessage(JText::_('Unable to move components JCK toolbar plugin!'));
        }
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'plugins.php';
        $dest = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'jckeditor' . DS . 'includes' . DS . 'ckeditor' . DS . 'plugins.php';
        if (!JFile::copy($src, $dest)) {
            $mainframe->enqueueMessage(JText::_('Unable to move base plugins file to JCK library!'));
        }
        $src = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'scayt.xml';
        $dest = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'plugins' . DS . 'scayt' . DS . 'scayt.xml';
        if (!JFile::copy($src, $dest)) {
            $mainframe->enqueueMessage(JText::_('Unable to move scayt JCK plugin!'));
        }
        //Lets try and restore  broken or removed plugins from backup
        require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'helpers' . DS . 'restorer.php';
        $restorer = JCKRestorer::getInstance();
        $srcBase = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jckman' . DS . 'editor' . DS . 'plugins' . DS;
        $destBase = JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'plugins' . DS;
        $folders = JFolder::folders($srcBase);
        foreach ($folders as $folder) {
            $src = $srcBase . $folder;
            if (!$restorer->install($src)) {
                $mainframe->enqueueMessage(JText::_('Unable to restore ' . $folder . ' JCK plugin!'), 'error');
            } else {
                $mainframe->enqueueMessage(JText::_('Sucessfully restored ' . $folder . ' JCK plugin!'));
            }
        }
        //check whether plugin is not a core plugin
        //if its not iterate through and see if there are files missing
        //then delete the plugin if there are
        $db = JFactory::getDBO();
        $query = 'SELECT p.id, p.name FROM `#__jckplugins` p WHERE p.iscore = 0';
        $db->setQuery($query);
        $results = $db->loadObjectList();
        if (!empty($results)) {
            for ($i = 0; $i < count($results); $i++) {
                if (!JFolder::exists(JPATH_PLUGINS . DS . 'editors' . DS . 'jckeditor' . DS . 'plugins' . DS . $results[$i]->name)) {
                    $query = 'DELETE FROM #__jcktoolbarplugins
								WHERE pluginid =' . $results[$i]->id;
                    $db->setQuery($query);
                    $db->query();
                    $query = 'DELETE FROM #__jckplugins
								WHERE id =' . $results[$i]->id;
                    $db->setQuery($query);
                    $db->query();
                }
            }
            //end for loop
        }
        //check for plugins that have not been added to layout -- legacy check
        $query = 'SELECT id,name FROM `#__jcktoolbars`';
        $db->setQuery($query);
        $toolbars = $db->loadObjectList();
        $JCKfolder = CKEDITOR_LIBRARY . DS . 'toolbar';
        $values = array();
        if (!empty($toolbars)) {
            require_once CKEDITOR_LIBRARY . DS . 'toolbar.php';
            //update core plugins layout if needed
            foreach ($toolbars as $row) {
                // get the total number of core plugin records
                $query = 'SELECT COUNT(*)' . ' FROM #__jcktoolbarplugins tp' . ' JOIN #__jckplugins p ON tp.pluginid = p.id' . ' WHERE tp.toolbarid =' . (int) $row->id . ' AND p.iscore = 1';
                $db->setQuery($query);
                $totalRows = $db->loadResult();
                if (!$totalRows) {
                    $filename = $JCKfolder . DS . $row->name . '.php';
                    require_once $filename;
                    $classname = 'JCK' . ucfirst($row->name);
                    $toolbar = new $classname();
                    $query = 'SELECT p.id, p.title' . ' FROM #__jckplugins p' . ' LEFT JOIN #__jckplugins parent on parent.id = p.parentid' . ' AND parent.published = 1' . ' WHERE p.title != ""' . ' AND p.published = 1' . ' AND p.iscore = 1' . ' AND(p.parentid IS NULL OR parent.published = 1)';
                    $db->setQuery($query);
                    $allplugins = $db->loadObjectList();
                    $values = array();
                    //fix toolbar values or they will get wiped out
                    $l = 1;
                    $n = 1;
                    $j = 1;
                    foreach (get_object_vars($toolbar) as $k => $v) {
                        if ($v) {
                            $n = $n > $v ? $n : $v;
                        }
                        if ($l < $n) {
                            $l = $n;
                            $j = 1;
                        }
                        for ($m = 0; $m < count($allplugins); $m++) {
                            if ($k == $allplugins[$m]->title) {
                                $values[] = '(' . (int) $row->id . ',' . (int) $allplugins[$m]->id . ',' . $n . ',' . $j . ',1)';
                                break;
                            }
                            if (strpos($k, 'brk_') !== false) {
                                $id = preg_match('/[0-9]+$/', $k);
                                $id = $id * -1;
                                $values[] = '(' . (int) $row->id . ',' . $id . ',' . $n . ',' . $j . ',1)';
                                $n++;
                                break;
                            }
                        }
                        $j++;
                    }
                    if (!empty($values)) {
                        $query = 'INSERT INTO #__jcktoolbarplugins(toolbarid,pluginid,row,ordering,state) VALUES ' . implode(',', $values);
                        $db->setQuery($query);
                        if (!$db->query()) {
                            JError::raiseWarning(500, $db->getErrorMsg());
                        }
                    }
                }
            }
            //update non core plugins layout
            $values = array();
            foreach ($toolbars as $row) {
                $query = 'SELECT id,title FROM `#__jckplugins` p WHERE p.title != "" AND p.iscore = 0  AND p.published = 1' . ' AND NOT EXISTS(SELECT 1 FROM  #__jcktoolbarplugins tp WHERE tp.pluginid = p.id AND tp.toolbarid = ' . $row->id . ')';
                $db->setQuery($query);
                $plugins = $db->loadObjectList();
                $tmpfilename = $JCKfolder . DS . $row->name . '.php';
                if (!file_exists($tmpfilename)) {
                    continue;
                }
                //skip
                require_once $tmpfilename;
                $classname = 'JCK' . ucfirst($row->name);
                $toolbar = new $classname();
                $rowDetail = JCKHelper::getNextLayoutRow($row->id);
                foreach (get_object_vars($toolbar) as $k => $v) {
                    foreach ($plugins as $plugin) {
                        if ($plugin->title == $k) {
                            $values[] = '(' . $row->id . ',' . $plugin->id . ',' . $rowDetail->rowid . ',' . $rowDetail->rowordering . ',1)';
                            $rowDetail->rowordering++;
                        }
                    }
                }
            }
        }
        //Now add plugins to 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()) {
                JError::raiseWarning(100, $db->getErrorMsg());
            }
        }
        //Reload Toolbar if editor is re-installed
        jckimport('event.observable.editor');
        $obs = new JCKEditorObservable('toolbars');
        $handle = $obs->getEventHandler();
        $query = 'SELECT * FROM `#__jcktoolbars` t WHERE exists(SELECT 1 FROM  #__jcktoolbarplugins tp WHERE tp.toolbarid  = t.id)';
        $db->setQuery($query);
        $rowresults = $db->loadObjectList();
        foreach ($rowresults as $row) {
            $id = $row->id;
            $name = $row->name;
            $title = $row->title;
            switch ($name) {
                case 'publisher':
                case 'full':
                case 'basic':
                case 'blog':
                case 'image':
                    $isNew = false;
                    break;
                default:
                    $isNew = true;
                    break;
            }
            //end switch
            $handle->onSave($id, $name, $name, $title, $isNew);
        }
        //end forloop
        //restore state of published/unpublished plugins
        $obs = new JCKEditorObservable('list');
        $handle = $obs->getEventHandler();
        $where = array();
        $where[] = ' WHERE p.published = 1';
        $where[] = ' WHERE p.published = 0';
        $state = array(1, 0);
        $count = count($where);
        for ($i = 0; $i < $count; $i++) {
            $db = JFactory::getDBO();
            $query = 'SELECT id FROM `#__jckplugins` p' . $where[$i] . ' AND p.iscore = 1 AND type="plugin"';
            $db->setQuery($query);
            $results = $db->loadResultArray();
            $handle->onPublish($results, $state[$i]);
        }
        //end for loop
        $mainframe->enqueueMessage(JText::_('Editor has been synchronized'));
    }