Browse Source

Integrate ckeditor with symfony2 structure

jmontoyaa 8 years ago
parent
commit
85fcd6f876

+ 4 - 2
bower.json

@@ -14,7 +14,7 @@
     "jquery-ui": "1.11.*",
     "bootstrap-daterangepicker": "1.3.*",
     "ckeditor": "*",
-    "jquery-timeago": "1.4.*",
+    "jquery-timeago": "1.5.*",
     "mediaelement": "2.*",
     "modernizr": "2.8.*",
     "jqueryui-timepicker-addon": "1.5.*",
@@ -29,7 +29,9 @@
     "jquery-file-upload": "*",
     "pwstrength-bootstrap": "*",
     "readmore-js": "2.1.0",
-    "qtip2": "*"
+    "qtip2": "*",
+    "ajaxQueue": "https://github.com/gnarf/jquery-ajaxQueue.git",
+    "moment": "*"
   },
   "resolutions": {
     "jquery": "2.1.4"

+ 1 - 1
main/inc/lib/api.lib.php

@@ -2297,7 +2297,7 @@ function api_get_setting($variable)
             $filename = api_get_path(SYS_PATH).api_get_home_path().'footer_extra_content.txt';
             if (file_exists($filename)) {
                 $value = file_get_contents($filename);
-                    return $value ;
+                return $value ;
             } else {
                 return '';
             }

+ 6 - 6
main/inc/lib/formvalidator/Element/HtmlEditor.php

@@ -2,6 +2,7 @@
 /* For licensing terms, see /license.txt */
 
 use \Chamilo\CoreBundle\Component\Editor\CkEditor\CkEditor;
+use Chamilo\CoreBundle\Framework\Container;
 
 /**
  * A html editor field to use with QuickForm
@@ -27,8 +28,8 @@ class HtmlEditor extends HTML_QuickForm_textarea
     public function __construct(
         $name = null,
         $elementLabel = null,
-        $attributes = null,
-        $config = array()
+        $attributes = [],
+        $config = []
     ) {
         if (empty($name)) {
             
@@ -39,8 +40,8 @@ class HtmlEditor extends HTML_QuickForm_textarea
         $this->_persistantFreeze = true;
         $this->_type = 'html_editor';
 
-        //$editor = Container::getHtmlEditor();
-        $editor = new CkEditor();
+        $editor = Container::getHtmlEditor();
+
         if ($editor) {
             $this->editor = $editor;
             $this->editor->setName($name);
@@ -68,7 +69,6 @@ class HtmlEditor extends HTML_QuickForm_textarea
             }
         }
 
-
         if ($this->isFrozen()) {
             return $this->getFrozenHtml();
         } else {
@@ -105,7 +105,7 @@ class HtmlEditor extends HTML_QuickForm_textarea
             $this->editor->value = $this->getValue();
             $this->editor->setName($this->getName());
 
-            if ($style == true) {
+            if ($style === true) {
                 $result = $this->editor->createHtmlStyle();
             } else {
                 $result = $this->editor->createHtml();

+ 10 - 6
main/inc/lib/formvalidator/Element/SelectLanguage.php

@@ -10,18 +10,22 @@ class SelectLanguage extends HTML_QuickForm_select
 	/**
 	 * Class constructor
 	 */
-	public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null)
-	{
+    public function __construct(
+        $elementName = null,
+        $elementLabel = null,
+        $options = null,
+        $attributes = null
+    ) {
 		parent::__construct($elementName, $elementLabel, $options, $attributes);
 		// Get all languages
 		$languages = api_get_languages();
 		$this->_options = array();
 		$this->_values = array();
-		foreach ($languages['name'] as $index => $name) {
-			if ($languages['folder'][$index] == api_get_setting('platformLanguage')) {
-				$this->addOption($name, $languages['folder'][$index], array('selected'=>'selected'));
+		foreach ($languages as $iso => $name) {
+			if ($iso == api_get_setting('language.platform_language')) {
+				$this->addOption($name, $iso, array('selected'=>'selected'));
 			} else {
-				$this->addOption($name, $languages['folder'][$index]);
+				$this->addOption($name, $iso);
 			}
 		}
 	}

+ 1 - 1
main/inc/lib/formvalidator/Rule/HTML.php

@@ -1,7 +1,7 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once api_get_path(SYS_PATH).'main/inc/lib/kses-0.2.2/kses.php';
+//require_once api_get_path(SYS_PATH).'main/inc/lib/kses-0.2.2/kses.php';
 
 /**
  * QuickForm rule to check a html

+ 0 - 18
main/inc/lib/javascript/ckeditor/config_js.php

@@ -1,18 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-require_once __DIR__.'/../../../global.inc.php';
-
-$moreButtonsInMaximizedMode = false;
-
-if (api_get_setting('more_buttons_maximized_mode') === 'true') {
-    $moreButtonsInMaximizedMode = true;
-}
-
-$template = new Template();
-$template->assign('moreButtonsInMaximizedMode', $moreButtonsInMaximizedMode);
-$template->assign('course_condition', api_get_cidreq());
-
-header('Content-type: application/x-javascript');
-$template->display('default/javascript/editor/ckeditor/config_js.tpl');
-

+ 37 - 7
src/Chamilo/CoreBundle/Component/Editor/CkEditor/CkEditor.php

@@ -6,8 +6,6 @@ namespace Chamilo\CoreBundle\Component\Editor\CkEditor;
 use Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar;
 use Chamilo\CoreBundle\Component\Editor\Editor;
 
-//use Symfony\Component\Routing\Generator\UrlGenerator;
-
 /**
  * Class CkEditor
  * @package Chamilo\CoreBundle\Component\Editor\CkEditor
@@ -73,12 +71,38 @@ class CkEditor extends Editor
         return $html;
     }
 
+    /**
+     * @param string $toolBarSet
+     *
+     * @return Toolbar\Basic
+     */
+    public function createToolBar($toolBarSet)
+    {
+        $toolbar = new Toolbar\Basic(
+            $this->urlGenerator,
+            $toolBarSet,
+            $this->config,
+            'CkEditor'
+        );
+
+        $toolbar->setLanguage($this->getLocale());
+        //$config = $toolbar->getConfig();
+
+        return $toolbar;
+    }
+
     /**
      * @return string
      */
     public function editorReplace()
     {
-        $toolbar = new Toolbar\Basic($this->toolbarSet, $this->config, 'CkEditor');
+        $toolbar = new Toolbar\Basic(
+            $this->urlGenerator,
+            $this->toolbarSet,
+            $this->config,
+            'CkEditor'
+        );
+
         $toolbar->setLanguage($this->getLocale());
         $config = $toolbar->getConfig();
 
@@ -147,7 +171,7 @@ class CkEditor extends Editor
         return [[
             'title' => get_lang('EmptyTemplate'),
             'description' => null,
-            'image' => api_get_path(WEB_APP_PATH) . 'home/default_platform_document/template_thumb/empty.gif',
+            'image' => api_get_path(WEB_IMG_PATH) . 'home/default_platform_document/template_thumb/empty.gif',
             'html' => '
                 <!DOCYTPE html>
                 <html>
@@ -188,7 +212,7 @@ class CkEditor extends Editor
         foreach ($systemTemplates as $template) {
             $image = $template->getImage();
             $image = !empty($image) ? $image : 'empty.gif';
-            $image = api_get_path(WEB_APP_PATH) . 'home/default_platform_document/template_thumb/' . $image;
+            $image = api_get_path(WEB_IMG_PATH) . 'home/default_platform_document/template_thumb/' . $image;
 
             /*$image = $this->urlGenerator->generate(
                 'get_document_template_action',
@@ -210,6 +234,13 @@ class CkEditor extends Editor
         return $templateList;
     }
 
+    /**
+     * @param int $userId
+     * @return array
+     * @throws \Doctrine\ORM\ORMException
+     * @throws \Doctrine\ORM\OptimisticLockException
+     * @throws \Doctrine\ORM\TransactionRequiredException
+     */
     private function getPersonalTemplates($userId = 0)
     {
         if (empty($userId)) {
@@ -237,8 +268,7 @@ class CkEditor extends Editor
             $templateItem = [];
             $templateItem['title'] = $template->getTitle();
             $templateItem['description'] = $template->getDescription();
-            $templateItem['image'] = api_get_path(WEB_APP_PATH)
-                . 'home/default_platform_document/template_thumb/noimage.gif';
+            $templateItem['image'] = api_get_path(WEB_IMG_PATH). 'home/default_platform_document/template_thumb/noimage.gif';
             $templateItem['html'] = file_get_contents(api_get_path(SYS_COURSE_PATH)
                 . $courseDirectory . '/document' . $templateData['path']);
 

+ 23 - 18
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Basic.php

@@ -4,6 +4,7 @@
 namespace Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar;
 
 use Chamilo\CoreBundle\Component\Editor\Toolbar;
+use Chamilo\CoreBundle\Framework\Container;
 
 /**
  * Class Basic
@@ -20,7 +21,7 @@ class Basic extends Toolbar
         'adobeair',
         'ajax',
         'audio',
-        'image2',
+        //'image2',
         'bidi',
         'colorbutton',
         'colordialog',
@@ -54,7 +55,7 @@ class Basic extends Toolbar
         'stylesheetparser',
         'tableresize',
         'templates',
-        'uicolor',
+        //'uicolor',
         'video',
         'widget',
         'wikilink',
@@ -72,6 +73,7 @@ class Basic extends Toolbar
      * @inheritdoc
      */
     public function __construct(
+        $router,
         $toolbar = null,
         $config = array(),
         $prefix = null
@@ -79,11 +81,11 @@ class Basic extends Toolbar
         // Adding plugins depending of platform conditions
         $plugins = array();
 
-        if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
+        if (api_get_setting('document.show_glossary_in_documents') == 'ismanual') {
             $plugins[] = 'glossary';
         }
 
-        if (api_get_setting('youtube_for_students') == 'true') {
+        if (api_get_setting('editor.youtube_for_students') == 'true') {
             $plugins[] = 'youtube';
         } else {
             if (api_is_allowed_to_edit() || api_is_platform_admin()) {
@@ -91,29 +93,29 @@ class Basic extends Toolbar
             }
         }
 
-        if (api_get_setting('enabled_googlemaps') == 'true') {
+        if (api_get_setting('editor.enabled_googlemaps') == 'true') {
             $plugins[] = 'leaflet';
         }
 
-        if (api_get_setting('math_asciimathML') == 'true') {
+        if (api_get_setting('editor.math_asciimathML') == 'true') {
             $plugins[] = 'asciimath';
         }
 
-        if (api_get_setting('enabled_mathjax') == 'true') {
+        if (api_get_setting('editor.enabled_mathjax') == 'true') {
             $plugins[] = 'mathjax';
             $config['mathJaxLib'] = api_get_path(WEB_PATH).'web/assets/MathJax/MathJax.js?config=AM_HTMLorMML';
         }
 
-        if (api_get_setting('enabled_asciisvg') == 'true') {
+        if (api_get_setting('editor.enabled_asciisvg') == 'true') {
             $plugins[] = 'asciisvg';
         }
 
-        if (api_get_setting('enabled_wiris') == 'true') {
+        if (api_get_setting('editor.enabled_wiris') == 'true') {
             // Commercial plugin
             $plugins[] = 'ckeditor_wiris';
         }
 
-        if (api_get_setting('enabled_imgmap') == 'true') {
+        if (api_get_setting('editor.enabled_imgmap') == 'true') {
             $plugins[] = 'mapping';
         }
 
@@ -121,16 +123,16 @@ class Basic extends Toolbar
             // Missing
         }*/
 
-        if (api_get_setting('more_buttons_maximized_mode') == 'true') {
+        if (api_get_setting('editor.more_buttons_maximized_mode') == 'true') {
             $plugins[] = 'toolbarswitch';
         }
 
-        if (api_get_setting('allow_spellcheck') == 'true') {
+        if (api_get_setting('editor.allow_spellcheck') == 'true') {
             $plugins[] = 'scayt';
         }
 
         $this->defaultPlugins = array_merge($this->defaultPlugins, $plugins);
-        parent::__construct($toolbar, $config, $prefix);
+        parent::__construct($router, $toolbar, $config, $prefix);
     }
 
     /**
@@ -140,14 +142,17 @@ class Basic extends Toolbar
     public function getConfig()
     {
         $config = array();
-        if (api_get_setting('more_buttons_maximized_mode') === 'true') {
+        if (api_get_setting('editor.more_buttons_maximized_mode') == 'true') {
             $config['toolbar_minToolbar'] = $this->getMinimizedToolbar();
-
             $config['toolbar_maxToolbar'] = $this->getMaximizedToolbar();
         }
 
-        $config['customConfig'] = api_get_path(WEB_LIBRARY_JS_PATH) . 'ckeditor/config_js.php';
-        $config['flash_flvPlayer'] = api_get_path(WEB_LIBRARY_JS_PATH) . 'ckeditor/plugins/flash/swf/player.swf';
+        /*$config['customConfig'] = api_get_path(WEB_LIBRARY_JS_PATH) . 'ckeditor/config_js.php';
+        $config['flash_flvPlayer'] = api_get_path(WEB_LIBRARY_JS_PATH) . 'ckeditor/plugins/flash/swf/player.swf';*/
+
+        $config['customConfig'] = $this->getUrlGenerator()->generate(
+            'config_editor'
+        );
 
         /*filebrowserFlashBrowseUrl
         filebrowserFlashUploadUrl
@@ -172,7 +177,7 @@ class Basic extends Toolbar
             'wordLimit' => 'unlimited'
         );*/
 
-        $config['skin'] = 'bootstrapck,' . api_get_path(WEB_LIBRARY_JS_PATH) . 'ckeditor/skins/bootstrapck/';
+        //$config['skin'] = 'bootstrapck,' . api_get_path(WEB_LIBRARY_JS_PATH) . 'ckeditor/skins/bootstrapck/';
 
         if (isset($this->config)) {
             $this->config = array_merge($config, $this->config);

+ 18 - 15
src/Chamilo/CoreBundle/Component/Editor/Connector.php

@@ -3,13 +3,15 @@
 
 namespace Chamilo\CoreBundle\Component\Editor;
 
-use Chamilo\CoreBundle\Component\Editor\Driver\Driver;
-use Chamilo\CoreBundle\Entity\Course;
+use Doctrine\ORM\EntityManager;
 use Chamilo\UserBundle\Entity\User;
-use Symfony\Component\Routing\Router;
-use Symfony\Component\Translation\Translator;
+use Chamilo\CoreBundle\Entity\Course;
 
-//use Symfony\Component\Security\Core\SecurityContext;
+use Symfony\Component\Routing\RouterInterface;
+use Symfony\Component\Translation\Translator;
+use Symfony\Component\Routing\Router;
+use Chamilo\CoreBundle\Component\Editor\Driver\Driver;
+use Symfony\Component\Security\Core\SecurityContext;
 
 /**
  * Class elFinder Connector - editor + Chamilo repository
@@ -28,6 +30,7 @@ class Connector
 
     /** @var Router */
     public $urlGenerator;
+
     /** @var SecurityContext */
     public $security;
 
@@ -39,13 +42,13 @@ class Connector
     public $driverList = array();
 
     public function __construct(
-        /*EntityManager $entityManager,
+        EntityManager $entityManager,
         array $paths,
-        Router $urlGenerator,
+        RouterInterface $urlGenerator,
         Translator $translator,
-        SecurityContext $security,*/
-        //$user,
-        //$course = null
+        SecurityContext $security,
+        $user,
+        $course = null
     ) {
         $this->paths = array(
             'root_sys' => api_get_path(SYS_PATH),
@@ -55,13 +58,13 @@ class Connector
             'path.temp' => api_get_path(SYS_ARCHIVE_PATH),
             //'sys_log_path' => $app['path.logs']
         );
-        /*$this->entityManager = $entityManager;
-        $this->paths = $paths;
+        $this->entityManager = $entityManager;
+        //$this->paths = $paths;
         $this->urlGenerator = $urlGenerator;
         $this->translator = $translator;
-        $this->security = $security;*/
-        $this->user = api_get_user_info();
-        $this->course = api_get_course_info();
+        $this->security = $security;
+        $this->user = empty($user) ? api_get_user_info() : $user;
+        $this->course = empty($course) ? api_get_course_info() : $course;
         $this->driverList = $this->getDefaultDriverList();
     }
 

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

@@ -21,8 +21,8 @@ class CourseDriver extends Driver implements DriverInterface
     public function setup()
     {
         $userId = api_get_user_id();
-        $userInfo = api_get_user_info();
         $sessionId = api_get_session_id();
+        $userInfo = $this->connector->user;
         $courseInfo = $this->connector->course;
 
         if (!empty($courseInfo)) {

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

@@ -4,8 +4,9 @@
 namespace Chamilo\CoreBundle\Component\Editor;
 
 use Chamilo\CoreBundle\Framework\Template;
-use Symfony\Component\Routing\RouterInterface;
 use Symfony\Component\Translation\Translator;
+use Symfony\Component\Routing\RouterInterface;
+use Symfony\Component\Translation\TranslatorInterface;
 
 /**
  * Class Editor
@@ -40,7 +41,7 @@ class Editor
      */
     public $config;
 
-    /** @var Translator */
+    /** @var TranslatorInterface */
     public $translator;
 
     /** @var RouterInterface */
@@ -50,18 +51,23 @@ class Editor
     public $template;
 
     /**
-     * Constructor
+     * Editor constructor.
+     * @param TranslatorInterface $translator
+     * @param RouterInterface $urlGenerator
      */
-    public function __construct()
-    {
+    public function __construct(
+        TranslatorInterface $translator,
+        RouterInterface $urlGenerator
+    ) {
         $this->toolbarSet = 'Basic';
         $this->value = '';
         $this->config = array();
         $this->setConfigAttribute('width', '100%');
         $this->setConfigAttribute('height', '200');
         $this->setConfigAttribute('fullPage', false);
-        /*$this->translator = $translator;
-        $this->urlGenerator = $urlGenerator;*/
+
+        $this->translator = $translator;
+        $this->urlGenerator = $urlGenerator;
         //$this->course = $course;
     }
 
@@ -89,7 +95,7 @@ class Editor
     public function createHtml()
     {
         $html = '<textarea id="'.$this->getName().'" name="'.$this->getName().'">'.$this->value.'</textarea>';
-        //$html .= $this->editorReplace();
+        
         return $html;
     }
 
@@ -98,10 +104,16 @@ class Editor
      */
     public function editorReplace()
     {
-        $toolbar = new Toolbar($this->toolbarSet, $this->config);
+        $toolbar = new Toolbar(
+            $this->urlGenerator,
+            $this->toolbarSet,
+            $this->config
+        );
+
         $toolbar->setLanguage($this->getLocale());
         $config = $toolbar->getConfig();
         $javascript = $this->toJavascript($config);
+
         $html = "<script>
            CKEDITOR.replace('".$this->name."',
                $javascript
@@ -155,6 +167,7 @@ class Editor
                 foreach ($var as $k => $v) {
                     $output[] = $this->toJavascript(strval($k)).': '.$this->toJavascript($v);
                 }
+
                 return '{ '.implode(', ', $output).' }';
             default:
                 return 'null';
@@ -241,6 +254,6 @@ class Editor
      */
     public function getLocale()
     {
-        return api_get_language_isocode();
+        return $this->translator->getLocale();
     }
 }

+ 4 - 6
src/Chamilo/CoreBundle/Component/Editor/Finder.php

@@ -3,6 +3,8 @@
 
 namespace Chamilo\CoreBundle\Component\Editor;
 
+use FM\ElFinderPHP\ElFinder;
+
 /**
  * Class Finder
  *
@@ -12,7 +14,7 @@ namespace Chamilo\CoreBundle\Component\Editor;
  *
  * @package Chamilo\CoreBundle\Component\Editor
  */
-class Finder extends \elFinder
+class Finder extends ElFinder
 {
 
     /**
@@ -35,11 +37,7 @@ class Finder extends \elFinder
         $this->callbackWindowURL = (isset($opts['callbackWindowURL']) ? $opts['callbackWindowURL'] : '');
 
         // setlocale and global locale regists to elFinder::locale
-        self::$locale = !empty($opts['locale']) ? $opts['locale'] : 'en_US.UTF-8';
-
-        if (false === @setlocale(LC_ALL, self::$locale)) {
-            self::$locale = setlocale(LC_ALL, '');
-        }
+        setlocale(LC_ALL, !empty($opts['locale']) ? $opts['locale'] : 'en_US.UTF-8');
 
         // bind events listeners
         if (!empty($opts['bind']) && is_array($opts['bind'])) {

+ 38 - 3
src/Chamilo/CoreBundle/Component/Editor/Toolbar.php

@@ -3,7 +3,7 @@
 
 namespace Chamilo\CoreBundle\Component\Editor;
 
-//use Symfony\Component\Routing\RouterInterface;
+use Symfony\Component\Routing\RouterInterface;
 
 /**
  * Class Toolbar
@@ -17,11 +17,13 @@ class Toolbar
     public $defaultPlugins = array();
 
     /**
+     * @param RouterInterface $urlGenerator
      * @param string $toolbar
      * @param array  $config
      * @param string $prefix
      */
     public function __construct(
+        $urlGenerator,
         $toolbar = null,
         $config = array(),
         $prefix = null
@@ -29,7 +31,7 @@ class Toolbar
         if (!empty($toolbar)) {
             $class = __NAMESPACE__."\\".$prefix."\\Toolbar\\".$toolbar;
             if (class_exists($class)) {
-                $toolbarObj = new $class();
+                $toolbarObj = new $class($urlGenerator);
                 $this->setConfig($toolbarObj->getConfig());
             }
         }
@@ -37,7 +39,15 @@ class Toolbar
         if (!empty($config)) {
             $this->updateConfig($config);
         }
-        //$this->urlGenerator = $urlGenerator;
+        $this->urlGenerator = $urlGenerator;
+    }
+
+    /**
+     * @return RouterInterface
+     */
+    public function getUrlGenerator()
+    {
+        return $this->urlGenerator;
     }
 
     /**
@@ -113,6 +123,31 @@ class Toolbar
         return $this->config;
     }
 
+    /**
+     * This config settings are specialized use when using symfony2 forms
+     * @return array
+     */
+    public function getNamedToolBarConfig()
+    {
+        $config = $this->config;
+        $namedToolBar = [];
+        $counter = 0;
+        foreach ($config['toolbar'] as $toolBarList) {
+            if ($toolBarList == '/') {
+                $namedToolBar[] = '/';
+                continue;
+            }
+            $namedToolBar[] = [
+                'name' => 'named_'.$counter,
+                'items' => $toolBarList,
+            ];
+            $counter++;
+        }
+        $config['toolbar'] = $namedToolBar;
+
+        return $config;
+    }
+
     /**
      * @param string $variable
      *

+ 3 - 3
src/Chamilo/ThemeBundle/Resources/views/Layout/header.js.twig

@@ -41,13 +41,13 @@ plugins = [
 ];
 
 plugins.forEach(function (plugin) {
-    CKEDITOR.plugins.addExternal(plugin, '{{ asset('bundles/chamilocore/components/ckeditor/plugins/') }}' + plugin + '/');
+    CKEDITOR.plugins.addExternal(plugin, '{{ asset('assets/ckeditor/plugins/') }}' + plugin + '/');
 });
 
 /* Global chat variables */
 var ajax_url = '{{ url('web.ajax') }}chat.ajax.php';
-var online_button = '{{ asset('bundles/chamilocore/img/statusonline.png') }}';
-var offline_button = '{{ asset('bundles/chamilocore/img/statusoffline.png') }}';
+var online_button = '{{ asset('assets/img/statusonline.png') }}';
+var offline_button = '{{ asset('assets/img/statusoffline.png') }}';
 var connect_lang = '{{ "ChatConnected"|trans }}';
 var disconnect_lang = '{{ "ChatDisconnected"|trans }}';