|
From: <luc...@us...> - 2013-09-28 05:34:48
|
Revision: 12102
http://sourceforge.net/p/xoops/svn/12102
Author: luciorota
Date: 2013-09-28 05:34:44 +0000 (Sat, 28 Sep 2013)
Log Message:
-----------
added $mode option to XoopsFormEditor class for syntax highlighting editors (like codemirror), better $nohtml check, why use wysiwyg editors in no html textareas?
Modified Paths:
--------------
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/sampleform.inc.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/formtinymce.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/tinymce.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/xoopseditor.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formeditor.php
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/sampleform.inc.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/sampleform.inc.php 2013-09-27 21:12:53 UTC (rev 12101)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/sampleform.inc.php 2013-09-28 05:34:44 UTC (rev 12102)
@@ -34,8 +34,11 @@
$editor = @ $xoopsUser->getVar('editor'); // Need set through user profile
}
// Add the editor selection box
- // If dohtml is disabled, set $noHtml = true
- $sample_form->addElement(new XoopsFormSelectEditor($sample_form, 'editor', $editor, $noHtml = false));
+ // If dohtml is disabled, set $noHtml = true; $mode not considered if $noHtml is false
+ xoops_load('XoopsCache');
+ XoopsCache::delete('editorlist');
+ $mode = 'html'; // extension or mimetype
+ $sample_form->addElement(new XoopsFormSelectEditor($sample_form, 'editor', $editor, $noHtml = false, $mode));
// options for the editor
// required configs
$options['editor'] = $editor;
@@ -47,11 +50,10 @@
$options['width'] = '100%'; // default value = 100%
$options['height'] = '400px'; // default value = 400px
-
// "textarea": if the selected editor with name of $editor can not be created, the editor "textarea" will be used
// if no $onFailure is set, then the first available editor will be used
// If dohtml is disabled, set $noHtml to true
- $sample_form->addElement(new XoopsFormEditor(_MD_MESSAGEC, $options['name'], $options, $nohtml = false, $onfailure = 'textarea'), true);
+ $sample_form->addElement(new XoopsFormEditor(_MD_MESSAGEC, $options['name'], $options, $nohtml = false, $onfailure = 'textarea', $mode), true);
$sample_form->addElement(new XoopsFormText('SOME REQUIRED ELEMENTS', 'required_element2', 50, 255, $required_element2), true);
$sample_form->addElement(new XoopsFormButton('', 'save', _SUBMIT, 'submit'));
$sample_form->display();
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/formtinymce.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/formtinymce.php 2013-09-27 21:12:53 UTC (rev 12101)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/formtinymce.php 2013-09-28 05:34:44 UTC (rev 12102)
@@ -35,7 +35,7 @@
*
* @param array $configs Editor Options
*/
- function __construct($configs)
+ function __construct($configs, $mode)
{
$current_path = __FILE__;
if (DIRECTORY_SEPARATOR != "/") {
@@ -86,6 +86,23 @@
}
/**
+ * Renders the Javascript function needed for client-side for get content
+ *
+ * I'VE USED THIS EXAMPLE TO WRITE VALIDATION CODE
+ * http://tinymce.moxiecode.com/punbb/viewtopic.php?id=12616
+ *
+ * @return string
+ */
+ function renderGetContentJS()
+ {
+ if ($eltname = $this->getName()) {
+ $ret = "tinyMCE.get('{$eltname}').getContent()";
+ return $ret;
+ }
+ return '';
+ }
+
+ /**
* get language
*
* @return string
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/tinymce.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/tinymce.php 2013-09-27 21:12:53 UTC (rev 12101)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/tinymce.php 2013-09-28 05:34:44 UTC (rev 12102)
@@ -269,11 +269,10 @@
$this->init();
if (self::$LastOfElementsTinymce!=$this->setting["elements"]) {
$ret = "\n<!-- 'tiny_mce.js' SCRIPT NOT YET ".$this->setting["elements"]." -->\n"; //debug
-
return $ret;
- } else {
+ } else {
$this->setting["elements"]=implode(",",self::$ListOfElementsTinymce);
- }
+ }
if ( !empty($this->setting["callback"]) ) {
$callback = $this->setting["callback"];
unset($this->setting["callback"]);
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/xoopseditor.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/xoopseditor.php 2013-09-27 21:12:53 UTC (rev 12101)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/xoopseditor.php 2013-09-28 05:34:44 UTC (rev 12102)
@@ -90,6 +90,7 @@
var $root_path = "";
var $nohtml = false;
var $allowed_editors = array();
+ var $mode = null;
/**
* Enter description here...
*
@@ -125,15 +126,16 @@
*
* @param string $name Editor name which is actually the folder name
* @param array $options editor options: $key => $val
+ * @param bool $noHtml dohtml disabled
* @param string $OnFailure a pre-validated editor that will be used if the required editor is failed to create
- * @param bool $noHtml dohtml disabled
+ * @param string Requested mode (or array of them)
*/
- function get($name = '', $options = null, $noHtml = false, $OnFailure = '')
+ function get($name = '', $options = null, $noHtml = false, $OnFailure = '', $mode = null)
{
- if (array_key_exists($name, $this->getList($noHtml)) && $editor = $this->_loadEditor($name, $options)) {
+ if (array_key_exists($name, $this->getList($noHtml, $mode)) && $editor = $this->_loadEditor($name, $options, $mode)) {
return $editor;
}
- $list = array_keys($this->getList($noHtml));
+ $list = array_keys($this->getList($noHtml, $mode));
if (empty($OnFailure) || !in_array($OnFailure, $list)) {
$OnFailure = $list[0];
}
@@ -145,9 +147,10 @@
* XoopsEditorHandler::getList()
*
* @param mixed $noHtml
+ * @param string $mode Requested mode (or array of them)
* @return
*/
- function getList($noHtml = false)
+ function getList($noHtml = false, $mode = null)
{
/*
Do NOT use this method statically, please use
@@ -177,7 +180,17 @@
if (empty($config['order']))
continue;
$order[] = $config['order'];
- $list[$item] = array('title' => $config['title'] , 'nohtml' => $config['nohtml']);
+ if (!isset($config['modes'])) {
+ $config['modes'] = null;
+ }
+ if ($config['nohtml'] == false) {
+ $config['modes'] = array('htm', 'html', 'htmlmixed', 'text/html');
+ }
+ $list[$item] = array(
+ 'title' => $config['title'] ,
+ 'nohtml' => $config['nohtml'],
+ 'modes' => $config['modes']
+ );
}
}
array_multisort($order, $list);
@@ -192,6 +205,10 @@
foreach ($editors as $name) {
if (!empty($noHtml) && empty($list[$name]['nohtml']))
continue;
+ if (!empty($mode) && is_string($mode) && !empty($list[$name]['modes']) && !in_array(strtolower($mode), $list[$name]['modes']))
+ continue;
+ if (!empty($mode) && is_array($mode) && !empty($list[$name]['modes']) && (count(array_intersect($mode, $list[$name]['modes'])) == 0))
+ continue;
$_list[$name] = $list[$name]['title'];
}
return $_list;
@@ -234,7 +251,7 @@
* @param mixed $options
* @return
*/
- function _loadEditor($name, $options = null)
+ function _loadEditor($name, $options = null, $mode = null)
{
$editor = null;
if (empty($name) || !array_key_exists($name, $this->getList())) {
@@ -255,7 +272,7 @@
return $editor;
}
include_once $config['file'];
- $editor = new $config['class']($options);
+ $editor = new $config['class']($options, $mode);
return $editor;
}
}
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formeditor.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formeditor.php 2013-09-27 21:12:53 UTC (rev 12101)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formeditor.php 2013-09-28 05:34:44 UTC (rev 12102)
@@ -38,8 +38,9 @@
* @param array $configs configures: editor - editor identifier; name - textarea field name; width, height - dimensions for textarea; value - text content
* @param bool $noHtml use non-WYSIWYG eitor onfailure
* @param string $OnFailure editor to be used if current one failed
+ * @param string Requested mode, useful for syntax highlighting editors
*/
- function XoopsFormEditor($caption, $name, $configs = null, $nohtml = false, $OnFailure = '')
+ function XoopsFormEditor($caption, $name, $configs = null, $nohtml = false, $OnFailure = '', $mode = null)
{
// Backward compatibility: $name -> editor name; $configs['name'] -> textarea field name
if (! isset($configs['editor'])) {
@@ -52,12 +53,12 @@
$this->XoopsFormTextArea($caption, $name);
xoops_load('XoopsEditorHandler');
$editor_handler = XoopsEditorHandler::getInstance();
- $this->editor = $editor_handler->get($configs['editor'], $configs, $nohtml, $OnFailure);
+ $this->editor = $editor_handler->get($configs['editor'], $configs, $nohtml, $OnFailure, $mode);
}
/**
* renderValidationJS
- * TEMPORARY SOLUTION to 'override' original renderValidationJS method
+ * override original renderValidationJS method
* with custom XoopsEditor's renderValidationJS method
*/
function renderValidationJS()
@@ -77,6 +78,27 @@
}
/**
+ * renderGetContentJS
+ * 'override' original renderGetContentJS method
+ * with custom XoopsEditor's renderGetContentJS method
+ */
+ function renderGetContentJS()
+ {
+ if (is_object($this->editor)) {
+ if (method_exists($this->editor, 'renderGetContentJS')) {
+ $this->editor->setName($this->getName());
+ $this->editor->setCaption($this->getCaption());
+ $this->editor->_required = $this->isRequired();
+ $ret = $this->editor->renderGetContentJS();
+ return $ret;
+ } else {
+ parent::renderGetContentJS();
+ }
+ }
+ return false;
+ }
+
+ /**
* XoopsFormEditor::render()
*
* @return
|