New structure for the ckeditor dependencies see #5875

The new structure allows the use of other editors such as TinyMce, that
plays well with elfinder. The dependencies were moved inside
ChamiloLMS/Component/Editor classes. Now the editor is used as a
service. The problem with ckeditor is that, it does not works properly
in smartphones/tablets event with the latest version 4.3.
1.10.x
Julio Montoya 13 years ago
parent 06e081dbc5
commit 9bf39ae027
  1. 31
      main/inc/lib/formvalidator/Element/html_editor.php
  2. 18
      main/inc/lib/formvalidator/FormValidator.class.php
  3. 6
      main/inc/lib/template.lib.php
  4. 49
      main/inc/services.php
  5. 0
      main/template/default/javascript/editor/ckeditor/elfinder.tpl
  6. 41
      main/template/default/javascript/editor/tinymce/elfinder.tpl
  7. 1
      main/template/extendme/javascript/elfinder.tpl
  8. 54
      src/ChamiloLMS/Component/Editor/CkEditor.php
  9. 62
      src/ChamiloLMS/Component/Editor/CkEditor/CkEditor.php
  10. 31
      src/ChamiloLMS/Component/Editor/CkEditor/Toolbar/Basic.php
  11. 8
      src/ChamiloLMS/Component/Editor/CkEditor/Toolbar/Documents.php
  12. 9
      src/ChamiloLMS/Component/Editor/CkEditor/Toolbar/IntroductionTool.php
  13. 9
      src/ChamiloLMS/Component/Editor/CkEditor/Toolbar/LearningPathDocuments.php
  14. 9
      src/ChamiloLMS/Component/Editor/CkEditor/Toolbar/Message.php
  15. 8
      src/ChamiloLMS/Component/Editor/CkEditor/Toolbar/TestFreeAnswer.php
  16. 9
      src/ChamiloLMS/Component/Editor/CkEditor/Toolbar/TestFreeAnswerStrict.php
  17. 7
      src/ChamiloLMS/Component/Editor/CkEditor/Toolbar/TestProposedAnswer.php
  18. 7
      src/ChamiloLMS/Component/Editor/CkEditor/Toolbar/TestQuestionDescription.php
  19. 8
      src/ChamiloLMS/Component/Editor/CkEditor/Toolbar/UniqueAnswerImage.php
  20. 5
      src/ChamiloLMS/Component/Editor/Connector.php
  21. 72
      src/ChamiloLMS/Component/Editor/Editor.php
  22. 81
      src/ChamiloLMS/Component/Editor/TinyMce/TinyMce.php
  23. 54
      src/ChamiloLMS/Component/Editor/TinyMceEditor.php
  24. 69
      src/ChamiloLMS/Component/Editor/Toolbar.php
  25. 6
      src/ChamiloLMS/Controller/EditorController.php

@ -8,8 +8,10 @@ require_once 'HTML/QuickForm/textarea.php';
*/
class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea
{
/** @var \ChamiloLMS\Component\Editor\Editor */
public $editor;
/**
* Class constructor
* @param string HTML editor name/id
@ -25,31 +27,17 @@ class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea
}
HTML_QuickForm_element :: HTML_QuickForm_element($name, $label, $attributes);
$this->_persistantFreeze = true;
$this->_type = 'html_editor';
global $app, $fck_attribute;
$this->editor = new ChamiloLMS\Component\Editor\Editor($name, $app['translator']);
$this->editor->toolbarSet = $fck_attribute['ToolbarSet'];
//We get the optionals config parameters in $fck_attribute array
$this->editor->config = !empty($fck_attribute['Config']) ? $fck_attribute['Config'] : array();
$width = !empty($fck_attribute['Width']) ? $fck_attribute['Width'] : '990';
$this->editor->setConfigAttribute('width', $width);
$height = !empty($fck_attribute['Height']) ? $fck_attribute['Height'] : '400';
$this->editor->setConfigAttribute('height', $height);
if (isset($fck_attribute['FullPage'])) {
$fullPage = is_bool($config['FullPage']) ? $config['FullPage'] : ($config['FullPage'] === 'true');
$this->editor->setConfigAttribute('fullPage', $fullPage);
}
// This is an alternative (a better) way to pass configuration data to the editor.
if (is_array($config)) {
foreach ($config as $key => $value) {
$this->editor->setConfigAttribute($key, $value);
}
}
/** @var ChamiloLMS\Component\Editor\Editor $editor */
$editor = $app['html_editor'];
$this->editor = $editor;
$this->editor->setName($name);
$this->editor->processConfig($fck_attribute);
$this->editor->processConfig($config);
}
/**
@ -89,6 +77,7 @@ class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea
public function buildEditor()
{
$this->editor->value = $this->getValue();
$this->editor->setName($this->getName());
$result = $this->editor->createHtml();
return $result;
}

@ -278,25 +278,13 @@ EOT;
{
$this->addElement('html_editor', $name, $label, 'rows="15" cols="80"', $config);
$this->applyFilter($name, 'trim');
if (is_array($config)) {
if (isset($config['FullPage'])) {
$full_page = is_bool($config['FullPage']) ? $config['FullPage'] : ($config['FullPage'] === 'true');
} else {
$config['FullPage'] = $full_page;
}
} else {
$config = array('FullPage' => (bool) $full_page);
}
if ($required) {
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
}
if ($full_page) {
$element = $this->getElement($name);
$element->fullPage = true;
}
/** @var HTML_QuickForm_html_editor $element */
$element = $this->getElement($name);
$element->editor->processConfig($config);
}
/**

@ -490,14 +490,14 @@ class Template
$jsFolder.'jquery.js',
$jsFolder.'chosen/chosen.jquery.min.js',
$jsFolder.'jquery-ui/js/jquery-ui.custom.js',
//$jsFolder.'jquery-ui/jquery.ui.touch-punch.js',
$jsFolder.'thickbox.js',
$jsFolder.'ckeditor/ckeditor.js',
//$jsFolder.'tinymce/tinymce.min.js',
$jsFolder.'bootstrap/js/bootstrap.js',
);
}
$this->app['html_editor']->getJavascriptToInclude($js_files);
if (api_is_global_chat_enabled()) {
//Do not include the global chat in LP
if ($this->show_learnpath == false && $this->show_footer == true && $this->app['template.hide_global_chat'] == false) {

@ -14,6 +14,11 @@ use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
use MediaAlchemyst\Alchemyst;
use MediaAlchemyst\MediaAlchemystServiceProvider;
use MediaVorus\MediaVorusServiceProvider;
use FFMpeg\FFMpegServiceProvider;
use PHPExiftool\PHPExiftoolServiceProvider;
// Flint
$app->register(new Flint\Provider\ConfigServiceProvider());
@ -27,6 +32,40 @@ $app->register(new Flint\Provider\RoutingServiceProvider(), array(
),
));
if (isset($app['configuration']['services']['media-alchemyst'])) {
$app->register(new MediaAlchemystServiceProvider());
$app->register(new PHPExiftoolServiceProvider());
$app->register(new FFMpegServiceProvider());
$app->register(new MediaVorusServiceProvider(), array(
'media-alchemyst.configuration' => array(
'ffmpeg.threads' => 4,
'ffmpeg.ffmpeg.timeout' => 3600,
'ffmpeg.ffprobe.timeout' => 60,
'ffmpeg.ffmpeg.binaries' => '/path/to/custom/ffmpeg',
'ffmpeg.ffprobe.binaries' => '/path/to/custom/ffprobe',
'imagine.driver' => 'imagick',
'gs.timeout' => 60,
'gs.binaries' => '/path/to/custom/gs',
'mp4box.timeout' => 60,
'mp4box.binaries' => '/path/to/custom/MP4Box',
'swftools.timeout' => 60,
'swftools.pdf2swf.binaries' => '/path/to/custom/pdf2swf',
'swftools.swfrender.binaries' => '/path/to/custom/swfrender',
'swftools.swfextract.binaries' => '/path/to/custom/swfextract',
'unoconv.binaries' => $app['configuration']['services']['media-alchemyst']['unoconv_path'],
'unoconv.timeout' => 60,
//'exiftool.reader' => '/path/to/custom/exiftool.reader',
//'exiftool.writer' => '/path/to/custom/exiftool.writer'
),
//'media-alchemyst.logger' => $logger, // A PSR Logger
));
}
use Knp\Provider\ConsoleServiceProvider;
$app->register(new ConsoleServiceProvider(), array(
@ -387,10 +426,7 @@ $app['twig'] = $app->share(
$twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
$twig->addFilter('return_message', new Twig_Filter_Function('Display::return_message_and_translate'));
$twig->addFilter('display_page_header', new Twig_Filter_Function('Display::page_header_and_translate'));
$twig->addFilter(
'display_page_subheader',
new Twig_Filter_Function('Display::page_subheader_and_translate')
);
$twig->addFilter('display_page_subheader', new Twig_Filter_Function('Display::page_subheader_and_translate'));
$twig->addFilter('icon', new Twig_Filter_Function('Template::get_icon_path'));
$twig->addFilter('format_date', new Twig_Filter_Function('Template::format_date'));
@ -784,3 +820,8 @@ $app['upgrade.controller'] = $app->share(
}
);
$app['html_editor'] = $app->share(function($app) {
return new ChamiloLMS\Component\Editor\CkEditor\CkEditor($app['translator'], $app['url_generator']);
//return new ChamiloLMS\Component\Editor\TinyMce\TinyMce($app['translator'], $app['url_generator']);
});

@ -0,0 +1,41 @@
{% extends app.template_style ~ "/layout/no_layout.tpl" %}
{% block body %}
<!-- elFinder CSS (REQUIRED) -->
<link rel="stylesheet" type="text/css" media="screen" href="{{ _p.web_lib }}elfinder/css/elfinder.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="{{ _p.web_lib }}elfinder/css/theme.css">
<!-- elFinder JS (REQUIRED) -->
<script type="text/javascript" src="{{ _p.web_lib }}elfinder/js/elfinder.min.js"></script>
<!-- elFinder translation (OPTIONAL) -->
<script type="text/javascript" src="{{ _p.web_lib }}elfinder/js/i18n/elfinder.ru.js"></script>
<script type="text/javascript">
var FileBrowserDialogue = {
init: function() {
// Here goes your code for setting your custom things onLoad.
},
mySubmit: function (URL) {
// pass selected file path to TinyMCE
top.tinymce.activeEditor.windowManager.getParams().setUrl(URL);
// close popup window
top.tinymce.activeEditor.windowManager.close();
}
}
$().ready(function() {
var elf = $('#elfinder').elfinder({
// set your elFinder options here
url : '{{ url('editor_connector') }}', // connector URL (REQUIRED)
getFileCallback: function(file) { // editor callback
// actually file.url - doesnt work for me, but file does. (elfinder 2.0-rc1)
FileBrowserDialogue.mySubmit(file); // pass selected file path to TinyMCE
}
}).elfinder('instance');
});
</script>
<div id="elfinder"></div>
{% endblock %}

@ -1 +0,0 @@
{% extends app.template_style ~ "/../default/javascript/elfinder.tpl" %}

@ -1,54 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\CkEditor;
class CkEditor extends Editor
{
/**
* @param string $name
* @param \Symfony\Component\Translation\Translator $translator
*/
public function __construct($name, \Symfony\Component\Translation\Translator $translator)
{
$this->name = $name;
$this->toolbarSet = 'Basic';
$this->value = '';
$this->config = array();
$this->setConfigAttribute('width', '100%');
$this->setConfigAttribute('height', '200');
$this->setConfigAttribute('fullPage', false);
$this->translator = $translator;
}
/**
* Return the HTML code required to run editor.
*
* @return string
*/
public function createHtml()
{
$Html = '<textarea id="'.$this->name.'" name="'.$this->name.'" class="ckeditor" >'.$this->value.'</textarea>';
$Html .= $this->editorReplace();
return $Html;
}
/**
* @return string
*/
public function editorReplace()
{
$toolbar = new Toolbar\Basic($this->toolbarSet);
$toolbar->setLanguage($this->translator->getLocale());
$config = $toolbar->getConfig();
$javascript = $this->toJavascript($config);
$html = "<script>
CKEDITOR.replace('".$this->name."',
$javascript
);
</script>";
return $html;
}
}

@ -0,0 +1,62 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\CkEditor;
use ChamiloLMS\Component\Editor\Editor;
use ChamiloLMS\Component\Editor\Toolbar;
/**
* Class CkEditor
* @package ChamiloLMS\Component\Editor\CkEditor
*/
class CkEditor extends Editor
{
/**
* @return string
*/
public function getTemplate()
{
return 'javascript/editor/ckeditor/elfinder.tpl';
}
/**
* @param array $files
*/
public function getJavascriptToInclude(& $files)
{
$jsFolder = api_get_path(WEB_LIBRARY_PATH).'javascript/';
$files[] = $jsFolder.'ckeditor/ckeditor.js';
}
/**
* Return the HTML code required to run editor.
*
* @return string
*/
public function createHtml()
{
$html = '<textarea id="'.$this->getName().'" name="'.$this->getName().'" class="ckeditor" >'.$this->value.'</textarea>';
$html .= $this->editorReplace();
return $html;
}
/**
* @return string
*/
public function editorReplace()
{
$toolbar = new Toolbar($this->toolbarSet, $this->config, 'CkEditor');
$toolbar->setLanguage($this->translator->getLocale());
$config = $toolbar->getConfig();
$javascript = $this->toJavascript($config);
$html = "<script>
CKEDITOR.replace('".$this->getName()."',
$javascript
);
</script>";
return $html;
}
}

@ -1,22 +1,15 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Toolbar;
namespace ChamiloLMS\Component\Editor\CkEditor\Toolbar;
class Basic
{
public $config;
public function __construct($toolbar = null)
{
if (!empty($toolbar)) {
if (class_exists(__NAMESPACE__."\\".$toolbar)) {
$class = __NAMESPACE__."\\".$toolbar;
$customToolbar = new $class;
$this->config = $customToolbar->getConfig();
}
}
}
use ChamiloLMS\Component\Editor\Toolbar;
/**
* Class Basic
* @package ChamiloLMS\Component\Editor\CkEditor\Toolbar
*/
class Basic extends Toolbar
{
public function getConfig()
{
@ -98,16 +91,8 @@ class Basic
$this->config = $config;
}
//$config['width'] = '100';
//$config['height'] = '200';
return $this->config;
}
public function setLanguage($language)
{
$this->config['language'] = $language;
}
}

@ -1,7 +1,11 @@
<?php
namespace ChamiloLMS\Component\Editor\Toolbar;
namespace ChamiloLMS\Component\Editor\CkEditor\Toolbar;
/**
* Class Documents
* @package ChamiloLMS\Component\Editor\CkEditor\Toolbar
*/
class Documents extends Basic
{
@ -31,5 +35,3 @@ class Documents extends Basic
return $config;
}
}

@ -1,10 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Toolbar;
namespace ChamiloLMS\Component\Editor\CkEditor\Toolbar;
/**
* Class IntroductionTool
* @package ChamiloLMS\Component\Editor\CkEditor\Toolbar
*/
class IntroductionTool extends Basic
{
public function getConfig()
{
$config['toolbarGroups'] = array(
@ -31,5 +34,3 @@ class IntroductionTool extends Basic
return $config;
}
}

@ -1,10 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Toolbar;
namespace ChamiloLMS\Component\Editor\CkEditor\Toolbar;
/**
* Class LearningPathDocuments
* @package ChamiloLMS\Component\Editor\CkEditor\Toolbar
*/
class LearningPathDocuments extends Basic
{
public function getConfig()
{
$config['toolbarGroups'] = array(
@ -30,5 +33,3 @@ class LearningPathDocuments extends Basic
return $config;
}
}

@ -1,10 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Toolbar;
namespace ChamiloLMS\Component\Editor\CkEditor\Toolbar;
/**
* Class Message
* @package ChamiloLMS\Component\Editor\CkEditor\Toolbar
*/
class Message extends Basic
{
public function getConfig()
{
$config['toolbarGroups'] = array(
@ -26,5 +29,3 @@ class Message extends Basic
return $config;
}
}

@ -1,7 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Toolbar;
namespace ChamiloLMS\Component\Editor\CkEditor\Toolbar;
/**
* Class TestFreeAnswer
* @package ChamiloLMS\Component\Editor\CkEditor\Toolbar
*/
class TestFreeAnswer extends Basic
{
public function getConfig()
@ -40,5 +44,3 @@ class TestFreeAnswer extends Basic
return $config;
}
}

@ -1,10 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Toolbar;
namespace ChamiloLMS\Component\Editor\CkEditor\Toolbar;
/**
* Class TestFreeAnswerStrict
* @package ChamiloLMS\Component\Editor\CkEditor\Toolbar
*/
class TestFreeAnswerStrict extends Basic
{
public function getConfig()
{
$config['toolbarGroups'] = array(
@ -45,5 +48,3 @@ class TestFreeAnswerStrict extends Basic
return $config;
}
}

@ -1,7 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Toolbar;
namespace ChamiloLMS\Component\Editor\CkEditor\Toolbar;
/**
* Class TestProposedAnswer
* @package ChamiloLMS\Component\Editor\CkEditor\Toolbar
*/
class TestProposedAnswer
{
@ -27,4 +31,3 @@ class TestProposedAnswer
return $config;
}
}

@ -1,10 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Toolbar;
namespace ChamiloLMS\Component\Editor\CkEditor\Toolbar;
/**
* Class TestQuestionDescription
* @package ChamiloLMS\Component\Editor\CkEditor\Toolbar
*/
class TestQuestionDescription
{
public function getConfig()
{
$config['toolbarGroups'] = array(

@ -1,7 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Toolbar;
namespace ChamiloLMS\Component\Editor\CkEditor\Toolbar;
/**
* Class UniqueAnswerImage
* @package ChamiloLMS\Component\Editor\CkEditor\Toolbar
*/
class UniqueAnswerImage extends Basic
{
public function getConfig()
@ -26,5 +30,3 @@ class UniqueAnswerImage extends Basic
return $config;
}
}

@ -3,7 +3,7 @@
namespace ChamiloLMS\Component\Editor;
/**
* Class Connector
* Class elfinder Connector - editor + Chamilo repository
* @package ChamiloLMS\Component\Editor
*/
class Connector
@ -25,7 +25,8 @@ class Connector
* @param string $volume
* @return bool|null
**/
public function access($attr, $path, $data, $volume) {
public function access($attr, $path, $data, $volume)
{
//error_log($path); error_log($attr);
return strpos(basename($path), '.') === 0 // if file/folder begins with '.' (dot)
? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true

@ -2,6 +2,10 @@
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor;
/**
* Class Editor
* @package ChamiloLMS\Component\Editor
*/
class Editor
{
/**
@ -34,13 +38,15 @@ class Editor
/** @var \Symfony\Component\Translation\Translator */
public $translator;
/** @var \Symfony\Component\Routing\Generator\UrlGenerator */
public $urlGenerator;
/**
* @param string $name
* @param \Symfony\Component\Translation\Translator $translator
* @param \Symfony\Component\Routing\Generator\UrlGenerator $urlGenerator
*/
public function __construct($name, \Symfony\Component\Translation\Translator $translator)
public function __construct(\Symfony\Component\Translation\Translator $translator, $urlGenerator)
{
$this->name = $name;
$this->toolbarSet = 'Basic';
$this->value = '';
$this->config = array();
@ -48,6 +54,23 @@ class Editor
$this->setConfigAttribute('height', '200');
$this->setConfigAttribute('fullPage', false);
$this->translator = $translator;
$this->urlGenerator = $urlGenerator;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
@ -57,10 +80,9 @@ class Editor
*/
public function createHtml()
{
$Html = '<textarea id="'.$this->name.'" name="'.$this->name.'" class="ckeditor" >'.$this->value.'</textarea>';
$Html .= $this->editorReplace();
return $Html;
$html = '<textarea id="'.$this->getName().'" name="'.$this->getName().'">'.$this->value.'</textarea>';
//$html .= $this->editorReplace();
return $html;
}
/**
@ -68,7 +90,7 @@ class Editor
*/
public function editorReplace()
{
$toolbar = new Toolbar\Basic($this->toolbarSet);
$toolbar = new Toolbar($this->toolbarSet, $this->config);
$toolbar->setLanguage($this->translator->getLocale());
$config = $toolbar->getConfig();
$javascript = $this->toJavascript($config);
@ -81,7 +103,6 @@ class Editor
return $html;
}
/**
* 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.
@ -90,7 +111,7 @@ class Editor
* Note: This function is similar to json_encode(), in addition it produces HTML-safe strings, i.e. with <, > and & escaped.
* @link http://drupal.org/
*/
private function toJavascript($var)
protected function toJavascript($var)
{
switch (gettype($var)) {
case 'boolean':
@ -167,4 +188,35 @@ class Editor
{
return isset($this->config[$key]) ? $this->config[$key] : null;
}
/**
* @param array $config
*/
public function processConfig($config)
{
if (is_array($config)) {
foreach ($config as $key => $value) {
switch($key) {
case 'ToolbarSet':
$this->toolbarSet = $value;
break;
case 'Config':
$this->processConfig($value);
break;
case 'Width':
$this->setConfigAttribute('width', $value);
break;
case 'Height':
$this->setConfigAttribute('height', $value);
break;
case 'FullPage':
$this->setConfigAttribute('fullPage', $value);
break;
default:
$this->setConfigAttribute($key, $value);
break;
}
}
}
}
}

@ -0,0 +1,81 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\TinyMce;
use ChamiloLMS\Component\Editor;
/**
* Class TinyMce
* @package ChamiloLMS\Component\Editor\TinyMce
*/
class TinyMce extends Editor\Editor
{
/**
* @param array $files
*/
public function getJavascriptToInclude(& $files)
{
$jsFolder = api_get_path(WEB_LIBRARY_PATH).'javascript/';
$files[] = $jsFolder.'tinymce/tinymce.min.js';
}
/**
* @return string
*/
public function getTemplate()
{
return 'javascript/editor/tinymce/elfinder.tpl';
}
/**
* Return the HTML code required to run editor.
*
* @return string
*/
public function createHtml()
{
$html = '<textarea id="'.$this->name.'" name="'.$this->name.'" class="ckeditor" >'.$this->value.'</textarea>';
$html .= $this->editorReplace();
return $html;
}
/**
* @return string
*/
public function editorReplace()
{
$toolbar = new Toolbar($this->toolbarSet, $this->config, 'TinyMce');
$toolbar->setLanguage($this->translator->getLocale());
$config = $toolbar->getConfig();
$config['selector'] = "#".$this->name;
$javascript = $this->toJavascript($config);
$javascript = str_replace('"elFinderBrowser"', "elFinderBrowser", $javascript);
$html = "<script>
function elFinderBrowser (field_name, url, type, win) {
tinymce.activeEditor.windowManager.open({
file: '".$this->urlGenerator->generate('filemanager')."',
title: 'elFinder 2.0',
width: 900,
height: 450,
resizable: 'yes'
}, {
setUrl: function (url) {
win.document.getElementById(field_name).value = url;
}
});
return false;
}
$(document).ready(function() {
tinymce.init(
$javascript
);
});
</script>";
return $html;
}
}

@ -1,54 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\CkEditor;
class TinyMceEditor extends Editor
{
/**
* @param string $name
* @param \Symfony\Component\Translation\Translator $translator
*/
public function __construct($name, \Symfony\Component\Translation\Translator $translator)
{
$this->name = $name;
$this->toolbarSet = 'Basic';
$this->value = '';
$this->config = array();
$this->setConfigAttribute('width', '100%');
$this->setConfigAttribute('height', '200');
$this->setConfigAttribute('fullPage', false);
$this->translator = $translator;
}
/**
* Return the HTML code required to run editor.
*
* @return string
*/
public function createHtml()
{
$Html = '<textarea id="'.$this->name.'" name="'.$this->name.'" class="ckeditor" >'.$this->value.'</textarea>';
$Html .= $this->editorReplace();
return $Html;
}
/**
* @return string
*/
public function editorReplace()
{
$toolbar = new Toolbar\Basic($this->toolbarSet);
$toolbar->setLanguage($this->translator->getLocale());
$config = $toolbar->getConfig();
$javascript = $this->toJavascript($config);
$html = "<script>
CKEDITOR.replace('".$this->name."',
$javascript
);
</script>";
return $html;
}
}

@ -0,0 +1,69 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor;
/**
* Class Toolbar
* @package ChamiloLMS\Component\Editor
*/
class Toolbar
{
public $config;
/**
* @param string $toolbar
* @param array $config
* @param string $prefix
*/
public function __construct($toolbar = null, $config = array(), $prefix = null)
{
if (!empty($toolbar)) {
$class = __NAMESPACE__."\\".$prefix."\\Toolbar\\".$toolbar;
if (class_exists($class)) {
$toolbarObj = new $class;
$this->setConfig($toolbarObj->getConfig());
}
}
if (!empty($config)) {
$this->updateConfig($config);
}
}
/**
* @param array $config
*/
public function setConfig(array $config)
{
$this->config = $config;
}
/**
* @param array $config
*/
public function updateConfig(array $config)
{
if (empty($this->config)) {
$this->setConfig($config);
} else {
$this->config = array_merge($this->config, $config);
}
}
/**
* @return array
*/
public function getConfig()
{
return $this->config;
}
/**
* @param $language
*/
public function setLanguage($language)
{
$this->config['language'] = $language;
}
}

@ -21,15 +21,15 @@ class EditorController
*/
public function filemanagerAction(Application $app)
{
$response = $app['template']->render_template('javascript/elfinder.tpl');
$response = $app['template']->render_template($app['html_editor']->getTemplate());
return new Response($response, 200, array());
}
/**
* @param Application $app
*
*/
public function connectorAction(Application $app)
public function connectorAction()
{
$chamiloConnector = new Connector();
$opts = $chamiloConnector->getOperations();

Loading…
Cancel
Save