Browse Source

Ckeditor - Updating Toolbars + fix file drivers

Julio Montoya 10 years ago
parent
commit
b767d7cc5b

+ 2 - 2
main/inc/lib/elfinder/connectorAction.php

@@ -12,8 +12,8 @@ $connector = new Connector();
 $driverList = array(
     'PersonalDriver',
     'CourseDriver',
-    'CourseUserDriver',
-    'HomeDriver'
+    //'CourseUserDriver',
+    //'HomeDriver'
 );
 $connector->setDriverList($driverList);
 

+ 14 - 8
main/template/default/layout/head.tpl

@@ -19,17 +19,23 @@
 
 // External plugins not part of the default Ckeditor package.
 var plugins = [
-    'oembed',
-    'wordcount',
+    'asciimath',
     'asciisvg',
-    'video',
-    'toolbarswitch',
     'audio',
-    'youtube',
-    'leaflet',
-    'asciimath',
+    //'ckeditor_wiris',
+    'dialogui',
     'glossary',
-    'mapping'
+    'justify',
+    'leaflet',
+    'mapping',
+    'maximize',
+    'oembed',
+    'toolbar',
+    'toolbarswitch',
+    'video',
+    'wikilink',
+    'wordcount',
+    'youtube'
 ];
 
 plugins.forEach(function(plugin) {

+ 54 - 21
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Basic.php

@@ -13,18 +13,21 @@ class Basic extends Toolbar
 {
     /**
      * Default plugins that will be use in all toolbars
+     * In order to add a new plugin you have to load it in default/layout/head.tpl
      * @var array
      */
     public $defaultPlugins = array(
         'oembed',
         'video',
+        'audio',
         'wordcount',
         'templates',
         'justify',
         'colorbutton',
         'flash',
         'link',
-        'table'
+        'table',
+        'wikilink'
     );
 
     /**
@@ -33,33 +36,63 @@ class Basic extends Toolbar
      */
     public $plugins = array();
 
+    /**
+     * @inheritdoc
+     */
+    public function __construct(
+        $toolbar = null,
+        $config = array(),
+        $prefix = null
+    ) {
+        // Adding plugins depending of platform conditions
+        $plugins = array();
+
+        if (api_get_setting('youtube_for_students') == 'true') {
+            $plugins[] = 'youtube';
+        } else {
+            if (api_is_allowed_to_edit() || api_is_platform_admin()) {
+                $plugins[] = 'youtube';
+            }
+        }
+
+        if (api_get_setting('enabled_googlemaps') == 'true') {
+            $plugins[] = 'leaflet';
+            $plugins[] = 'mapping';
+        }
+
+        if (api_get_setting('math_asciimathML') == 'true') {
+            $plugins[] = 'asciimath';
+        }
+        $plugins[] = 'asciimath';
+
+        if (api_get_setting('enabled_asciisvg') == 'true') {
+            $plugins[] = 'asciisvg';
+        }
+
+        if (api_get_setting('enabled_wiris') == 'true') {
+            // Commercial plugin
+            //$plugins[] = 'ckeditor_wiris';
+        }
+
+        if (api_get_setting('enabled_imgmap') == 'true') {
+            // Commercial plugin
+        }
+
+        if (api_get_setting('block_copy_paste_for_students') == 'true') {
+            // Missing
+        }
+
+        $this->defaultPlugins = array_merge($this->defaultPlugins, $plugins);
+        parent::__construct($toolbar, $config, $prefix);
+    }
+
     /**
      * @return array
      */
     public function getConfig()
     {
         // Original from ckeditor
-        /*
-        $config['toolbarGroups'] = array(
-            array('name' => 'document',  'groups' =>array('mode', 'document', 'doctools')),
-            array('name' => 'clipboard',    'groups' =>array('clipboard', 'undo', )),
-            array('name' => 'editing',    'groups' =>array('clipboard', 'undo', )),
-            array('name' => 'forms',    'groups' =>array('clipboard', 'undo', )),
-            '/',
-            array('name' => 'basicstyles',    'groups' =>array('basicstyles', 'cleanup', )),
-            array('name' => 'paragraph',    'groups' =>array('list', 'indent', 'blocks', 'align' )),
-            array('name' => 'links'),
-            array('name' => 'insert'),
-            '/',
-            array('name' => 'styles'),
-            array('name' => 'colors'),
-            array('name' => 'tools'),
-            array('name' => 'others'),
-            array('name' => 'about')
-        );*/
-
         $config['toolbarGroups'] = array(
-                 //{ name: 'document',	   groups: [ 'mode', 'document', 'doctools' ] },
             array('name' => 'document',   'groups' =>array('mode', 'document', 'doctools')),
             array('name' => 'clipboard',  'groups' =>array('clipboard', 'undo', )),
             array('name' => 'editing',    'groups' =>array('clipboard', 'undo', )),

+ 14 - 7
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Documents.php

@@ -14,15 +14,9 @@ class Documents extends Basic
         'toolbarswitch',
         'audio',
         'video',
-        'youtube',
-        'leaflet',
         'widget',
         'lineutils',
-        'mathjax',
-        'asciimath',
-        'glossary',
-        'asciisvg',
-        'mapping'
+        'mathjax'
     );
 
     /**
@@ -47,6 +41,7 @@ class Documents extends Basic
             array('name' => 'others'),
             array('name' => 'mode')
         );
+
         $config['extraPlugins'] = $this->getPluginsToString();
         //$config['mathJaxLib'] = $this->urlGenerator->generate('javascript').'/math_jax/MathJax.js?config=default';
         //$config['mathJaxLib'] = api_get_path(WEB_LIBRARY_JS_PATH).'/math_jax/MathJax.js?config=default';
@@ -55,4 +50,16 @@ class Documents extends Basic
         return $config;
     }
 
+    /**
+     * @return array
+     */
+    public function getConditionalPlugins()
+    {
+        $plugins = array();
+
+        if (api_get_setting('show_glossary_in_documents') != 'none') {
+            $plugins[] = 'glossary';
+        }
+        return $plugins;
+    }
 }

+ 1 - 1
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/PortalHomePage.php

@@ -10,7 +10,7 @@ use Chamilo\CoreBundle\Component\Editor\Toolbar;
  * @todo complete config
  * @package Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar
  */
-class PortalHomePage extends Toolbar
+class PortalHomePage extends Basic
 {
 
 }

+ 1 - 1
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/PortalNews.php

@@ -10,7 +10,7 @@ use Chamilo\CoreBundle\Component\Editor\Toolbar;
  * @todo complete config
  * @package Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar
  */
-class PortalNews extends Toolbar
+class PortalNews extends Basic
 {
 
 }

+ 1 - 1
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/TestProposedAnswer.php

@@ -7,7 +7,7 @@ namespace Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar;
  * Class TestProposedAnswer
  * @package Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar
  */
-class TestProposedAnswer
+class TestProposedAnswer extends Basic
 {
     /**
      * @return mixed

+ 1 - 1
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/TestQuestionDescription.php

@@ -7,7 +7,7 @@ namespace Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar;
  * Class TestQuestionDescription
  * @package Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar
  */
-class TestQuestionDescription
+class TestQuestionDescription extends Basic
 {
     /**
      * @return mixed

+ 1 - 1
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/ToolbarStartExpanded.php

@@ -9,6 +9,6 @@ use Chamilo\CoreBundle\Component\Editor\Toolbar;
  * Class ToolbarStartExpanded
  * @package Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar
  */
-class ToolbarStartExpanded extends Toolbar
+class ToolbarStartExpanded extends Basic
 {
 }

+ 1 - 1
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/TrainingDescription.php

@@ -10,7 +10,7 @@ use Chamilo\CoreBundle\Component\Editor\Toolbar;
  * @todo complete config
  * @package Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar
  */
-class TrainingDescription extends Toolbar
+class TrainingDescription extends Basic
 {
 
 }

+ 5 - 4
src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php

@@ -97,8 +97,9 @@ class CourseDriver extends Driver
      */
     public function upload($fp, $dst, $name, $tmpname)
     {
+        $this->setConnectorFromPlugin();
+
         if ($this->allow()) {
-            $this->setConnectorFromPlugin();
 
             // upload file by elfinder.
             $result = parent::upload($fp, $dst, $name, $tmpname);
@@ -147,8 +148,9 @@ class CourseDriver extends Driver
     {
         // elfinder does not delete the file
         //parent::rm($hash);
+        $this->setConnectorFromPlugin();
+
         if ($this->allow()) {
-            $this->setConnectorFromPlugin();
 
             $path = $this->decode($hash);
             $stat = $this->stat($path);
@@ -177,11 +179,10 @@ class CourseDriver extends Driver
     public function allow()
     {
         //if ($this->connector->security->isGranted('ROLE_ADMIN')) {
-        $userId = api_get_user_id();
         return
             isset($this->connector->course) &&
             !empty($this->connector->course) &&
-            !api_is_anonymous($userId, true)
+            !api_is_anonymous()
         ;
     }
 }

+ 4 - 2
src/Chamilo/CoreBundle/Component/Editor/Driver/HomeDriver.php

@@ -36,8 +36,9 @@ class HomeDriver extends Driver
      */
     public function upload($fp, $dst, $name, $tmpname)
     {
+        $this->setConnectorFromPlugin();
+
         if ($this->allow()) {
-            $this->setConnectorFromPlugin();
 
             return parent::upload($fp, $dst, $name, $tmpname);
         }
@@ -48,8 +49,9 @@ class HomeDriver extends Driver
      */
     public function rm($hash)
     {
+        $this->setConnectorFromPlugin();
+
         if ($this->allow()) {
-            $this->setConnectorFromPlugin();
 
             return parent::rm($hash);
         }

+ 6 - 2
src/Chamilo/CoreBundle/Component/Editor/Driver/PersonalDriver.php

@@ -20,6 +20,7 @@ class PersonalDriver extends Driver
         if ($this->allow()) {
 
             $userId = api_get_user_id();
+
             if (!empty($userId)) {
 
                 // Adding user personal files
@@ -52,8 +53,9 @@ class PersonalDriver extends Driver
      */
     public function upload($fp, $dst, $name, $tmpname)
     {
+        $this->setConnectorFromPlugin();
+
         if ($this->allow()) {
-            $this->setConnectorFromPlugin();
 
             return parent::upload($fp, $dst, $name, $tmpname);
         }
@@ -64,8 +66,9 @@ class PersonalDriver extends Driver
      */
     public function rm($hash)
     {
+        $this->setConnectorFromPlugin();
+
         if ($this->allow()) {
-            $this->setConnectorFromPlugin();
 
             return parent::rm($hash);
         }
@@ -77,6 +80,7 @@ class PersonalDriver extends Driver
     public function allow()
     {
         //if ($this->connector->security->isGranted('IS_AUTHENTICATED_FULLY')) {
+
         return !api_is_anonymous();
     }
 }

+ 10 - 4
src/Chamilo/CoreBundle/Component/Editor/Editor.php

@@ -50,6 +50,9 @@ class Editor
     /** @var \Template */
     public $template;
 
+    /**
+     * Constructor
+     */
     public function __construct()
     {
         $this->toolbarSet = 'Basic';
@@ -112,9 +115,11 @@ class Editor
     /**
      * Converts a PHP variable into its Javascript equivalent.
      * The code of this method has been "borrowed" from the function drupal_to_js() within the Drupal CMS.
-     * @param mixed $var    The variable to be converted into Javascript syntax
-     * @return string        Returns a string
-     * Note: This function is similar to json_encode(), in addition it produces HTML-safe strings, i.e. with <, > and & escaped.
+     * @param mixed $var  The variable to be converted into Javascript syntax
+     *
+     * @return string    Returns a string
+     * Note: This function is similar to json_encode(),
+     * in addition it produces HTML-safe strings, i.e. with <, > and & escaped.
      * @link http://drupal.org/
      */
     protected function toJavascript($var)
@@ -159,7 +164,7 @@ class Editor
 
     /**
      * @param string $key
-     * @param mixed $value
+     * @param mixed  $value
      */
     public function setConfigAttribute($key, $value)
     {
@@ -168,6 +173,7 @@ class Editor
 
     /**
      * @param string $key
+     *
      * @return mixed
      */
     public function getConfigAttribute($key)

+ 20 - 4
src/Chamilo/CoreBundle/Component/Editor/Toolbar.php

@@ -18,7 +18,7 @@ class Toolbar
 
     /**
      * @param string $toolbar
-     * @param array $config
+     * @param array  $config
      * @param string $prefix
      */
     public function __construct(
@@ -45,7 +45,12 @@ class Toolbar
      */
     public function getPluginsToString()
     {
-        $plugins = array_filter(array_merge($this->getDefaultPlugins(), $this->getPlugins()));
+        $plugins = array_filter(
+            array_merge(
+                $this->getDefaultPlugins(),
+                $this->getPlugins(),
+                $this->getConditionalPlugins())
+        );
 
         return
             $this->getConfigAttribute('extraPlugins').
@@ -53,6 +58,16 @@ class Toolbar
     }
 
     /**
+     * Get plugins by default in all editors in the platform
+     * @return array
+     */
+    public function getDefaultPlugins()
+    {
+        return $this->defaultPlugins;
+    }
+
+    /**
+     * Get fixed plugins depending of the toolbar
      * @return array
      */
     public function getPlugins()
@@ -61,11 +76,12 @@ class Toolbar
     }
 
     /**
+     * Get dynamic/conditional plugins depending of platform/course settings.
      * @return array
      */
-    public function getDefaultPlugins()
+    public function getConditionalPlugins()
     {
-        return $this->defaultPlugins;
+        return array();
     }
 
     /**