|
From: <be...@us...> - 2013-08-06 11:46:40
|
Revision: 11881
http://sourceforge.net/p/xoops/svn/11881
Author: beckmi
Date: 2013-08-06 11:46:35 +0000 (Tue, 06 Aug 2013)
Log Message:
-----------
making function loadConfig in MyTextSanitizerExtension as static
Modified Paths:
--------------
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/module.textsanitizer.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/flash/flash.php
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/module.textsanitizer.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/module.textsanitizer.php 2013-08-05 21:28:45 UTC (rev 11880)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/module.textsanitizer.php 2013-08-06 11:46:35 UTC (rev 11881)
@@ -49,7 +49,7 @@
* @param string $path
* @return string
*/
- function loadConfig($path = null)
+ static function loadConfig($path = null)
{
$ts =& MyTextSanitizer::getInstance();
$path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
@@ -71,7 +71,7 @@
if (file_exists($path . '/config.custom.php')) {
$config_custom = include $path . '/config.custom.php';
}
- return $this->mergeConfig($config_default, $config_custom);
+ return self::mergeConfig($config_default, $config_custom);
}
/**
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/flash/flash.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/flash/flash.php 2013-08-05 21:28:45 UTC (rev 11880)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/flash/flash.php 2013-08-06 11:46:35 UTC (rev 11881)
@@ -51,7 +51,7 @@
}
static function myCallback($match) {
- return self::decode( $match[5], $match[3], $match[4] );
+ return self::decode( $match[5], $match[3], $match[4] );
}
function load(&$ts)
@@ -69,8 +69,8 @@
function decode($url, $width, $height)
{
-//TODO check on the loadConfig to enable it
-// $config = parent::loadConfig(dirname(__FILE__));
+ $config = parent::loadConfig(dirname(__FILE__));
+
if ((empty($width) || empty($height)) && !empty($config['detect_dimension'])) {
if (!$dimension = @getimagesize($url)) {
return "<a href='{$url}' rel='external' title=''>{$url}</a>";
|
|
From: <be...@us...> - 2013-08-17 00:24:08
|
Revision: 11935
http://sourceforge.net/p/xoops/svn/11935
Author: beckmi
Date: 2013-08-17 00:24:05 +0000 (Sat, 17 Aug 2013)
Log Message:
-----------
Making decode functions as static in MyTextSanitizerExtension
Modified Paths:
--------------
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/module.textsanitizer.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/flash/flash.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/mp3/mp3.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/wiki/wiki.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/youtube/youtube.php
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/module.textsanitizer.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/module.textsanitizer.php 2013-08-17 00:10:20 UTC (rev 11934)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/module.textsanitizer.php 2013-08-17 00:24:05 UTC (rev 11935)
@@ -110,7 +110,7 @@
*
* @return Null
*/
- function decode()
+ static function decode()
{
return null;
}
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/flash/flash.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/flash/flash.php 2013-08-17 00:10:20 UTC (rev 11934)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/flash/flash.php 2013-08-17 00:24:05 UTC (rev 11935)
@@ -67,7 +67,7 @@
return true;
}
- function decode($url, $width, $height)
+ static function decode($url, $width, $height)
{
$config = parent::loadConfig(dirname(__FILE__));
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/mp3/mp3.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/mp3/mp3.php 2013-08-17 00:10:20 UTC (rev 11934)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/mp3/mp3.php 2013-08-17 00:24:05 UTC (rev 11935)
@@ -62,7 +62,7 @@
return true;
}
- function decode($url)
+ static function decode($url)
{
$rp = "<embed flashvars=\"playerID=1&bg=0xf8f8f8&leftbg=0x3786b3&lefticon=0x78bee3&rightbg=0x3786b3&rightbghover=0x78bee3&righticon=0x78bee3&righticonhover=0x3786b3&text=0x666666&slider=0x3786b3&track=0xcccccc&border=0x666666&loader=0x78bee3&loop=no&soundFile={$url}\" quality='high' menu='false' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' src='" . XOOPS_URL . "/images/form/player.swf' width=290 height=24 type='application/x-shockwave-flash'></embed>";
return $rp;
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/wiki/wiki.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/wiki/wiki.php 2013-08-17 00:10:20 UTC (rev 11934)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/wiki/wiki.php 2013-08-17 00:24:05 UTC (rev 11935)
@@ -66,7 +66,7 @@
}
- function decode($text)
+ static function decode($text)
{
$config = parent::loadConfig(dirname(__FILE__));
if (empty($text) || empty($config['link'])) {
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/youtube/youtube.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/youtube/youtube.php 2013-08-17 00:10:20 UTC (rev 11934)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/textsanitizer/youtube/youtube.php 2013-08-17 00:24:05 UTC (rev 11935)
@@ -63,7 +63,7 @@
//mb------------------------------
}
- function decode($url, $width, $height)
+ static function decode($url, $width, $height)
{
if (!preg_match("/^http:\/\/(www\.)?youtube\.com\/watch\?v=(.*)/i", $url, $matches)) {
trigger_error("Not matched: {$url} {$width} {$height}", E_USER_WARNING);
|
|
From: <txm...@us...> - 2013-09-10 15:17:01
|
Revision: 12018
http://sourceforge.net/p/xoops/svn/12018
Author: txmodxoops
Date: 2013-09-10 15:16:57 +0000 (Tue, 10 Sep 2013)
Log Message:
-----------
Fixed javascript attribute tag language="Javascript"
Deleted because obsolete by the W3C Validator
Modified Paths:
--------------
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/tinymce.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php
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-10 13:16:27 UTC (rev 12017)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/tinymce.php 2013-09-10 15:16:57 UTC (rev 12018)
@@ -329,10 +329,10 @@
if ($isTinyMceJsLoaded) {
$ret .= "<!-- 'tiny_mce.js' SCRIPT IS ALREADY LOADED -->\n"; //debug
} else {
- $ret .= "<script language='javascript' type='text/javascript' src='" . XOOPS_URL . $this->rootpath . "/tiny_mce.js'></script>\n";
+ $ret .= "<script type='text/javascript' src='" . XOOPS_URL . $this->rootpath . "/tiny_mce.js'></script>\n";
$isTinyMceJsLoaded = true;
}
- $ret .= "<script language='javascript' type='text/javascript'>\n";
+ $ret .= "<script type='text/javascript'>\n";
$ret .= "tinyMCE.init({\n";
// set options - start
foreach ($this->setting as $key => $val) {
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php 2013-09-10 13:16:27 UTC (rev 12017)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php 2013-09-10 15:16:57 UTC (rev 12018)
@@ -167,7 +167,7 @@
}
// Load javascript
if (empty($js_loaded)) {
- $javascript = (($this->js) ? '<script language="JavaScript" type="text/javascript">' . $this->js . '</script>' : '') . '<script language="JavaScript" type="text/javascript" src="' . XOOPS_URL . '/include/formdhtmltextarea.js"></script>';
+ $javascript = (($this->js) ? '<script type="text/javascript">' . $this->js . '</script>' : '') . '<script type="text/javascript" src="' . XOOPS_URL . '/include/formdhtmltextarea.js"></script>';
$ret = $javascript . $ret;
$js_loaded = true;
}
@@ -213,7 +213,7 @@
$textarea_id = $this->getName();
$hiddentext = $this->_hiddenText;
- $fontStr = "<script type=\"text/javascript\" language=\"JavaScript\">" . "var _editor_dialog = ''" . "+ '<select id=\'{$textarea_id}Size\' onchange=\'xoopsSetElementAttribute(\"size\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'" . "+ '<option value=\'SIZE\'>" . _SIZE . "</option>'";
+ $fontStr = "<script type=\"text/javascript\">" . "var _editor_dialog = ''" . "+ '<select id=\'{$textarea_id}Size\' onchange=\'xoopsSetElementAttribute(\"size\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'" . "+ '<option value=\'SIZE\'>" . _SIZE . "</option>'";
foreach($GLOBALS["formtextdhtml_sizes"] as $_val => $_name) {
$fontStr .= " + '<option value=\'{$_val}\'>{$_name}</option>'";
}
|
|
From: <luc...@us...> - 2013-09-26 12:53:23
|
Revision: 12096
http://sourceforge.net/p/xoops/svn/12096
Author: luciorota
Date: 2013-09-26 12:53:19 +0000 (Thu, 26 Sep 2013)
Log Message:
-----------
+ added renderGetContentJS method to form objects (Renders the Javascript function needed to get contents)
+ added "mode" option to editor...
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/form.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcheckbox.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcolorpicker.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formeditor.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formelement.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselect.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselecteditor.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-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/sampleform.inc.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -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;
@@ -46,8 +49,8 @@
$options['cols'] = 60; // default value = 50
$options['width'] = '100%'; // default value = 100%
$options['height'] = '400px'; // default value = 400px
+ $options['mode'] = $mode; // for editors that support mode option
-
// "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
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-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/formtinymce.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -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-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/tinymce.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -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-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/xoopseditor.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -90,6 +90,7 @@
var $root_path = "";
var $nohtml = false;
var $allowed_editors = array();
+ var $modes = 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 mixed $modes Requested mode (or array of them)
*/
- function get($name = '', $options = null, $noHtml = false, $OnFailure = '')
+ function get($name = '', $options = null, $noHtml = false, $OnFailure = '', $modes = null)
{
- if (array_key_exists($name, $this->getList($noHtml)) && $editor = $this->_loadEditor($name, $options)) {
+ if (array_key_exists($name, $this->getList($noHtml, $modes)) && $editor = $this->_loadEditor($name, $options)) {
return $editor;
}
- $list = array_keys($this->getList($noHtml));
+ $list = array_keys($this->getList($noHtml, $modes));
if (empty($OnFailure) || !in_array($OnFailure, $list)) {
$OnFailure = $list[0];
}
@@ -145,9 +147,10 @@
* XoopsEditorHandler::getList()
*
* @param mixed $noHtml
+ * @param mixed $modes Requested mode (or array of them)
* @return
*/
- function getList($noHtml = false)
+ function getList($noHtml = false, $modes = 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($modes) && is_string($modes) && !empty($list[$name]['modes']) && !in_array(strtolower($modes), $list[$name]['modes']))
+ continue;
+ if (!empty($modes) && is_array($modes) && !empty($list[$name]['modes']) && (count(array_intersect($modes, $list[$name]['modes'])) == 0))
+ continue;
$_list[$name] = $list[$name]['title'];
}
return $_list;
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/form.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/form.php 2013-09-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/form.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -558,6 +558,60 @@
}
/**
+ * Renders the Javascript function needed for client-side for get content
+ *
+ * Additionally, each element class may provide its own "renderGetContentJS" method
+ * that is supposed to return custom get content code for the element.
+ *
+ * The element get content code can assume that the JS "myform" variable points to the form.
+ * Exemple:
+ * <script type='text/javascript'>
+ * var content[];
+ * content = " . renderGetContentJS(false) . "
+ * </script>
+ *
+ * A basic element get content method may contain something like this:
+ * <code>
+ * function renderGetContentJS() {
+ * $name = $this->getName();
+ * return "myform.{$name}.value;";
+ * }
+ * </code>
+ *
+ * @param boolean $withtags Include the < javascript > tags in the returned string
+ * @return string
+ */
+ function renderGetContentJS($withtags = true)
+ {
+ $js = '';
+ if ($withtags) {
+ $js .= "\n<!-- Start Form GetContent JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
+ }
+ $formname = $this->getName();
+ $js .= "function xoopsFormGetContent_{$formname}() {\n";
+ $js .= " var myform = window.document.{$formname};\n";
+ $js .= " var content = new Object();\n";
+ $elements = $this->getElements(true);
+ foreach($elements as $elt) {
+ if (method_exists($elt, 'renderGetContentJS') && ($elt->getName() != '')) {
+ $js .= " content['" . $elt->getName() . "'] = " . $elt->renderGetContentJS() . ";\n";
+ }
+ }
+ $js .= " Object.size = function(obj) {\n";
+ $js .= " var size = 0, key;\n";
+ $js .= " for (key in obj)\n";
+ $js .= " {if (obj.hasOwnProperty(key)) size++;}\n";
+ $js .= " return size;\n";
+ $js .= " };\n";
+ $js .= " return (Object.size(content) > 0) ? content : null;\n";
+ $js .= "}\n";
+ if ($withtags) {
+ $js .= "//--></script>\n<!-- End Form GetContent JavaScript //-->\n";
+ }
+ return $js;
+ }
+
+ /**
* assign to smarty form template instead of displaying directly
*
* @param object $ &$tpl reference to a {@link Smarty} object
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcheckbox.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcheckbox.php 2013-09-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcheckbox.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -242,4 +242,33 @@
}
return '';
}
+
+ /**
+ * Render custom javascript validation code
+ *
+ * @seealso XoopsForm::renderValidationJS
+ */
+ function renderGetContentJS()
+ {
+ // render custom validation code if any
+ if (! empty($this->customGetContentCode)) {
+ return implode(NWLINE, $this->customGetContentCode);
+ // generate get content code if required
+ } else {
+ $eltname = $this->getName();
+ return NWLINE . "
+ function(){
+ var checkboxesChecked = [];
+ var checkBox = myform.elements['{$eltname}'];
+ if (checkBox.length) {
+ for (var i = 0; i < checkBox.length; i++) {
+ if (checkBox[i].checked == true) {
+ checkboxesChecked.push(checkboxes[i]);
+ }
+ }
+ }
+ return (checkboxesChecked.length > 0) ? checkboxesChecked : null;
+ }";
+ }
+ }
}
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcolorpicker.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcolorpicker.php 2013-09-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcolorpicker.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -72,4 +72,18 @@
return "if ( !(new RegExp(\"^#[0-9a-fA-F]{6}\",\"i\").test(myform.{$eltname}.value)) ) { window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }";
}
+
+ /**
+ * Returns custom get content Javascript
+ *
+ * @return string Element get content Javascript
+ */
+ function renderGetContentJS()
+ {
+ $eltname = $this->getName();
+ return NWLINE . "
+ function(){
+ return ( (new RegExp(\"^#[0-9a-fA-F]{6}\",\"i\").test(myform.{$eltname}.value))) ? myform.{$eltname}.value : null;
+ }";
+ }
}
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php 2013-09-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -265,4 +265,19 @@
}
return parent::renderValidationJS();
}
+
+ /**
+ * XoopsFormDhtmlTextArea::renderGetContentJS()
+ *
+ * @return
+ */
+ function renderGetContentJS()
+ {
+ if ($this->htmlEditor && is_object($this->htmlEditor) && method_exists($this->htmlEditor, 'renderGetContentJS')) {
+ if (! isset($this->htmlEditor->isEnabled) || $this->htmlEditor->isEnabled) {
+ return $this->htmlEditor->renderGetContentJS();
+ }
+ }
+ return parent::renderGetContentJS();
+ }
}
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-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formeditor.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -57,7 +57,7 @@
/**
* renderValidationJS
- * TEMPORARY SOLUTION to 'override' original renderValidationJS method
+ * override original renderValidationJS method
* with custom XoopsEditor's renderValidationJS method
*/
function renderValidationJS()
@@ -77,6 +77,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
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formelement.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formelement.php 2013-09-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formelement.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -434,6 +434,37 @@
}
/**
+ * Render custom javascript get content code
+ *
+ * @seealso XoopsForm::renderGetContentJS
+ */
+ function renderGetContentJS()
+ {
+ // render custom get content code if any
+ if (!empty($this->customGetContentCode)) {
+ return implode(NWLINE, $this->customGetContentCode);
+ // generate get content code if required
+ } else if ($eltname = $this->getName()) {
+ // $eltname = $this->getName();
+ $eltcaption = $this->getCaption();
+ $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
+ $eltmsg = str_replace(array(':' , '?' , '%'), '', $eltmsg);
+ $eltmsg = str_replace('"', '\"', stripslashes($eltmsg));
+ $eltmsg = strip_tags($eltmsg);
+ echo $this->getFormType();
+ switch ($this->getFormType()) {
+ case 'checkbox':
+ return "myform.{$eltname}.value";
+ break;
+ default:
+ return "myform.{$eltname}.value";
+ break;
+ } // switch
+ }
+ return false;
+ }
+
+ /**
* Generates output for the element.
*
* This method is abstract and must be overwritten by the child classes.
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselect.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselect.php 2013-09-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselect.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -238,4 +238,34 @@
}
return '';
}
+
+ /**
+ * Render custom javascript get content code
+ *
+ * @seealso XoopsForm::renderGetContentJS
+ */
+ function renderGetContentJS()
+ {
+ // render custom validation code if any
+ if (! empty($this->customGetContentCode)) {
+ return implode("\n", $this->customGetContentCode);
+ // generate validation code if required
+ } else {
+ $eltname = $this->getName();
+ return "
+ function(){
+ var selectSelected = [];
+ var selectBox = myform.elements['{$eltname}'];
+ if (selectBox.length) {
+ for (i = 0; i < selectBox.options.length; i++ ) {
+ if (selectBox.options[i].selected == true && selectBox.options[i].value != '') {
+ selectSelected.push(selectBox.options[i].value);
+ }
+ }
+ }
+ return (selectSelected.length > 0) ? selectSelected : null;
+ }";
+ }
+ return '';
+ }
}
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselecteditor.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselecteditor.php 2013-09-26 12:38:11 UTC (rev 12095)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselecteditor.php 2013-09-26 12:53:19 UTC (rev 12096)
@@ -27,6 +27,7 @@
*/
class XoopsFormSelectEditor extends XoopsFormElementTray
{
+ var $modes = null;
var $allowed_editors = array();
var $form;
var $value;
@@ -40,10 +41,13 @@
* @param string $name editor name
* @param string $value Pre-selected text value
* @param bool $noHtml dohtml disabled
+ * @param array $allowed_editors
+ * @param mixed $modes Requested mode (or array of them)
*/
- function XoopsFormSelectEditor(&$form, $name = 'editor', $value = null, $nohtml = false, $allowed_editors = array())
+ function XoopsFormSelectEditor(&$form, $name = 'editor', $value = null, $nohtml = false, $allowed_editors = array(), $modes = null)
{
$this->XoopsFormElementTray(_SELECT);
+ $this->modes = $modes;
$this->allowed_editors = $allowed_editors;
$this->form = &$form;
$this->name = $name;
@@ -61,12 +65,13 @@
xoops_load('XoopsEditorHandler');
$editor_handler = XoopsEditorHandler::getInstance();
$editor_handler->allowed_editors = $this->allowed_editors;
+ $editor_handler->modes = $this->modes;
$option_select = new XoopsFormSelect("", $this->name, $this->value);
$extra = 'onchange="if(this.options[this.selectedIndex].value.length > 0 ){
window.document.forms.' . $this->form->getName() . '.submit();
}"';
$option_select->setExtra($extra);
- $option_select->addOptionArray($editor_handler->getList($this->nohtml));
+ $option_select->addOptionArray($editor_handler->getList($this->nohtml, $this->modes));
$this->addElement($option_select);
return parent::render();
}
|
|
From: <luc...@us...> - 2013-09-27 21:12:56
|
Revision: 12101
http://sourceforge.net/p/xoops/svn/12101
Author: luciorota
Date: 2013-09-27 21:12:53 +0000 (Fri, 27 Sep 2013)
Log Message:
-----------
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/form.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcheckbox.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcolorpicker.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formeditor.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formelement.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselect.php
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselecteditor.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-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/sampleform.inc.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -34,11 +34,8 @@
$editor = @ $xoopsUser->getVar('editor'); // Need set through user profile
}
// Add the editor selection box
- // 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));
+ // If dohtml is disabled, set $noHtml = true
+ $sample_form->addElement(new XoopsFormSelectEditor($sample_form, 'editor', $editor, $noHtml = false));
// options for the editor
// required configs
$options['editor'] = $editor;
@@ -49,8 +46,8 @@
$options['cols'] = 60; // default value = 50
$options['width'] = '100%'; // default value = 100%
$options['height'] = '400px'; // default value = 400px
- $options['mode'] = $mode; // for editors that support mode option
+
// "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
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-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/formtinymce.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -86,23 +86,6 @@
}
/**
- * 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-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/tinymce/tinymce.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -269,10 +269,11 @@
$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-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopseditor/xoopseditor.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -90,7 +90,6 @@
var $root_path = "";
var $nohtml = false;
var $allowed_editors = array();
- var $modes = null;
/**
* Enter description here...
*
@@ -126,16 +125,15 @@
*
* @param string $name Editor name which is actually the folder name
* @param array $options editor options: $key => $val
+ * @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 $OnFailure a pre-validated editor that will be used if the required editor is failed to create
- * @param mixed $modes Requested mode (or array of them)
*/
- function get($name = '', $options = null, $noHtml = false, $OnFailure = '', $modes = null)
+ function get($name = '', $options = null, $noHtml = false, $OnFailure = '')
{
- if (array_key_exists($name, $this->getList($noHtml, $modes)) && $editor = $this->_loadEditor($name, $options)) {
+ if (array_key_exists($name, $this->getList($noHtml)) && $editor = $this->_loadEditor($name, $options)) {
return $editor;
}
- $list = array_keys($this->getList($noHtml, $modes));
+ $list = array_keys($this->getList($noHtml));
if (empty($OnFailure) || !in_array($OnFailure, $list)) {
$OnFailure = $list[0];
}
@@ -147,10 +145,9 @@
* XoopsEditorHandler::getList()
*
* @param mixed $noHtml
- * @param mixed $modes Requested mode (or array of them)
* @return
*/
- function getList($noHtml = false, $modes = null)
+ function getList($noHtml = false)
{
/*
Do NOT use this method statically, please use
@@ -180,17 +177,7 @@
if (empty($config['order']))
continue;
$order[] = $config['order'];
- 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']
- );
+ $list[$item] = array('title' => $config['title'] , 'nohtml' => $config['nohtml']);
}
}
array_multisort($order, $list);
@@ -205,10 +192,6 @@
foreach ($editors as $name) {
if (!empty($noHtml) && empty($list[$name]['nohtml']))
continue;
- if (!empty($modes) && is_string($modes) && !empty($list[$name]['modes']) && !in_array(strtolower($modes), $list[$name]['modes']))
- continue;
- if (!empty($modes) && is_array($modes) && !empty($list[$name]['modes']) && (count(array_intersect($modes, $list[$name]['modes'])) == 0))
- continue;
$_list[$name] = $list[$name]['title'];
}
return $_list;
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/form.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/form.php 2013-09-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/form.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -558,60 +558,6 @@
}
/**
- * Renders the Javascript function needed for client-side for get content
- *
- * Additionally, each element class may provide its own "renderGetContentJS" method
- * that is supposed to return custom get content code for the element.
- *
- * The element get content code can assume that the JS "myform" variable points to the form.
- * Exemple:
- * <script type='text/javascript'>
- * var content[];
- * content = " . renderGetContentJS(false) . "
- * </script>
- *
- * A basic element get content method may contain something like this:
- * <code>
- * function renderGetContentJS() {
- * $name = $this->getName();
- * return "myform.{$name}.value;";
- * }
- * </code>
- *
- * @param boolean $withtags Include the < javascript > tags in the returned string
- * @return string
- */
- function renderGetContentJS($withtags = true)
- {
- $js = '';
- if ($withtags) {
- $js .= "\n<!-- Start Form GetContent JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
- }
- $formname = $this->getName();
- $js .= "function xoopsFormGetContent_{$formname}() {\n";
- $js .= " var myform = window.document.{$formname};\n";
- $js .= " var content = new Object();\n";
- $elements = $this->getElements(true);
- foreach($elements as $elt) {
- if (method_exists($elt, 'renderGetContentJS') && ($elt->getName() != '')) {
- $js .= " content['" . $elt->getName() . "'] = " . $elt->renderGetContentJS() . ";\n";
- }
- }
- $js .= " Object.size = function(obj) {\n";
- $js .= " var size = 0, key;\n";
- $js .= " for (key in obj)\n";
- $js .= " {if (obj.hasOwnProperty(key)) size++;}\n";
- $js .= " return size;\n";
- $js .= " };\n";
- $js .= " return (Object.size(content) > 0) ? content : null;\n";
- $js .= "}\n";
- if ($withtags) {
- $js .= "//--></script>\n<!-- End Form GetContent JavaScript //-->\n";
- }
- return $js;
- }
-
- /**
* assign to smarty form template instead of displaying directly
*
* @param object $ &$tpl reference to a {@link Smarty} object
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcheckbox.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcheckbox.php 2013-09-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcheckbox.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -242,33 +242,4 @@
}
return '';
}
-
- /**
- * Render custom javascript validation code
- *
- * @seealso XoopsForm::renderValidationJS
- */
- function renderGetContentJS()
- {
- // render custom validation code if any
- if (! empty($this->customGetContentCode)) {
- return implode(NWLINE, $this->customGetContentCode);
- // generate get content code if required
- } else {
- $eltname = $this->getName();
- return NWLINE . "
- function(){
- var checkboxesChecked = [];
- var checkBox = myform.elements['{$eltname}'];
- if (checkBox.length) {
- for (var i = 0; i < checkBox.length; i++) {
- if (checkBox[i].checked == true) {
- checkboxesChecked.push(checkboxes[i]);
- }
- }
- }
- return (checkboxesChecked.length > 0) ? checkboxesChecked : null;
- }";
- }
- }
}
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcolorpicker.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcolorpicker.php 2013-09-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formcolorpicker.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -72,18 +72,4 @@
return "if ( !(new RegExp(\"^#[0-9a-fA-F]{6}\",\"i\").test(myform.{$eltname}.value)) ) { window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }";
}
-
- /**
- * Returns custom get content Javascript
- *
- * @return string Element get content Javascript
- */
- function renderGetContentJS()
- {
- $eltname = $this->getName();
- return NWLINE . "
- function(){
- return ( (new RegExp(\"^#[0-9a-fA-F]{6}\",\"i\").test(myform.{$eltname}.value))) ? myform.{$eltname}.value : null;
- }";
- }
}
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php 2013-09-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formdhtmltextarea.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -265,19 +265,4 @@
}
return parent::renderValidationJS();
}
-
- /**
- * XoopsFormDhtmlTextArea::renderGetContentJS()
- *
- * @return
- */
- function renderGetContentJS()
- {
- if ($this->htmlEditor && is_object($this->htmlEditor) && method_exists($this->htmlEditor, 'renderGetContentJS')) {
- if (! isset($this->htmlEditor->isEnabled) || $this->htmlEditor->isEnabled) {
- return $this->htmlEditor->renderGetContentJS();
- }
- }
- return parent::renderGetContentJS();
- }
}
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-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formeditor.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -57,7 +57,7 @@
/**
* renderValidationJS
- * override original renderValidationJS method
+ * TEMPORARY SOLUTION to 'override' original renderValidationJS method
* with custom XoopsEditor's renderValidationJS method
*/
function renderValidationJS()
@@ -77,27 +77,6 @@
}
/**
- * 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
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formelement.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formelement.php 2013-09-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formelement.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -434,37 +434,6 @@
}
/**
- * Render custom javascript get content code
- *
- * @seealso XoopsForm::renderGetContentJS
- */
- function renderGetContentJS()
- {
- // render custom get content code if any
- if (!empty($this->customGetContentCode)) {
- return implode(NWLINE, $this->customGetContentCode);
- // generate get content code if required
- } else if ($eltname = $this->getName()) {
- // $eltname = $this->getName();
- $eltcaption = $this->getCaption();
- $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
- $eltmsg = str_replace(array(':' , '?' , '%'), '', $eltmsg);
- $eltmsg = str_replace('"', '\"', stripslashes($eltmsg));
- $eltmsg = strip_tags($eltmsg);
- echo $this->getFormType();
- switch ($this->getFormType()) {
- case 'checkbox':
- return "myform.{$eltname}.value";
- break;
- default:
- return "myform.{$eltname}.value";
- break;
- } // switch
- }
- return false;
- }
-
- /**
* Generates output for the element.
*
* This method is abstract and must be overwritten by the child classes.
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselect.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselect.php 2013-09-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselect.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -238,34 +238,4 @@
}
return '';
}
-
- /**
- * Render custom javascript get content code
- *
- * @seealso XoopsForm::renderGetContentJS
- */
- function renderGetContentJS()
- {
- // render custom validation code if any
- if (! empty($this->customGetContentCode)) {
- return implode("\n", $this->customGetContentCode);
- // generate validation code if required
- } else {
- $eltname = $this->getName();
- return "
- function(){
- var selectSelected = [];
- var selectBox = myform.elements['{$eltname}'];
- if (selectBox.length) {
- for (i = 0; i < selectBox.options.length; i++ ) {
- if (selectBox.options[i].selected == true && selectBox.options[i].value != '') {
- selectSelected.push(selectBox.options[i].value);
- }
- }
- }
- return (selectSelected.length > 0) ? selectSelected : null;
- }";
- }
- return '';
- }
}
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselecteditor.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselecteditor.php 2013-09-26 17:27:27 UTC (rev 12100)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselecteditor.php 2013-09-27 21:12:53 UTC (rev 12101)
@@ -27,7 +27,6 @@
*/
class XoopsFormSelectEditor extends XoopsFormElementTray
{
- var $modes = null;
var $allowed_editors = array();
var $form;
var $value;
@@ -41,13 +40,10 @@
* @param string $name editor name
* @param string $value Pre-selected text value
* @param bool $noHtml dohtml disabled
- * @param array $allowed_editors
- * @param mixed $modes Requested mode (or array of them)
*/
- function XoopsFormSelectEditor(&$form, $name = 'editor', $value = null, $nohtml = false, $allowed_editors = array(), $modes = null)
+ function XoopsFormSelectEditor(&$form, $name = 'editor', $value = null, $nohtml = false, $allowed_editors = array())
{
$this->XoopsFormElementTray(_SELECT);
- $this->modes = $modes;
$this->allowed_editors = $allowed_editors;
$this->form = &$form;
$this->name = $name;
@@ -65,13 +61,12 @@
xoops_load('XoopsEditorHandler');
$editor_handler = XoopsEditorHandler::getInstance();
$editor_handler->allowed_editors = $this->allowed_editors;
- $editor_handler->modes = $this->modes;
$option_select = new XoopsFormSelect("", $this->name, $this->value);
$extra = 'onchange="if(this.options[this.selectedIndex].value.length > 0 ){
window.document.forms.' . $this->form->getName() . '.submit();
}"';
$option_select->setExtra($extra);
- $option_select->addOptionArray($editor_handler->getList($this->nohtml, $this->modes));
+ $option_select->addOptionArray($editor_handler->getList($this->nohtml));
$this->addElement($option_select);
return parent::render();
}
|
|
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
|
|
From: <rgr...@us...> - 2014-06-11 14:48:13
|
Revision: 12577
http://sourceforge.net/p/xoops/svn/12577
Author: rgriffith
Date: 2014-06-11 14:48:03 +0000 (Wed, 11 Jun 2014)
Log Message:
-----------
Add XoopsRequest class
Modified Paths:
--------------
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsload.php
Added Paths:
-----------
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsrequest.php
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsload.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsload.php 2014-06-10 22:48:07 UTC (rev 12576)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsload.php 2014-06-11 14:48:03 UTC (rev 12577)
@@ -220,6 +220,7 @@
'xoopsformselecteditor' => XOOPS_ROOT_PATH . '/class/xoopsform/formselecteditor.php',
'xoopsformcalendar' => XOOPS_ROOT_PATH . '/class/xoopsform/formcalendar.php',
'xoopsfilterinput' => XOOPS_ROOT_PATH . '/class/xoopsfilterinput.php',
+ 'xoopsrequest' => XOOPS_ROOT_PATH . '/class/xoopsrequest.php',
);
}
Added: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsrequest.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsrequest.php (rev 0)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsrequest.php 2014-06-11 14:48:03 UTC (rev 12577)
@@ -0,0 +1,492 @@
+<?php
+/*
+ You may not change or alter any portion of this comment or credits
+ of supporting developers from this source code or any supporting source code
+ which is considered copyrighted (c) material of the original comment or credit authors.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/**
+ * Request Class
+ *
+ * This class serves to provide a common interface to access
+ * request variables. This includes $_POST, $_GET, and naturally $_REQUEST. Variables
+ * can be passed through an input filter to avoid injection or returned raw.
+ *
+ * @category Xmf\Module\Request
+ * @package Xmf
+ * @author Richard Griffith <ri...@ge...>
+ * @author trabis <lus...@gm...>
+ * @author Joomla!
+ * @copyright 2011-2013 The XOOPS Project http://sourceforge.net/projects/xoops/
+ * @license GNU GPL 2 or later (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
+ * @version Release: 1.0
+ * @link http://xoops.org
+ * @since 1.0
+ */
+class XoopsRequest
+{
+
+ /**
+ * Available masks for cleaning variables
+ */
+ const NOTRIM = 1;
+ const ALLOWRAW = 2;
+ const ALLOWHTML = 4;
+
+ /**
+ * Gets the request method
+ *
+ * @return string
+ */
+ public static function getMethod()
+ {
+ $method = strtoupper($_SERVER['REQUEST_METHOD']);
+
+ return $method;
+ }
+
+ /**
+ * Fetches and returns a given variable.
+ *
+ * The default behaviour is fetching variables depending on the
+ * current request method: GET and HEAD will result in returning
+ * an entry from $_GET, POST and PUT will result in returning an
+ * entry from $_POST.
+ *
+ * You can force the source by setting the $hash parameter:
+ *
+ * - post $_POST
+ * - get $_GET
+ * - files $_FILES
+ * - cookie $_COOKIE
+ * - env $_ENV
+ * - server $_SERVER
+ * - method via current $_SERVER['REQUEST_METHOD']
+ * - default $_REQUEST
+ *
+ * @param string $name Variable name
+ * @param mixed $default Default value if the variable does not exist
+ * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
+ * @param string $type Return type for the variable, for valid values see {@link XoopsFilterInput::clean()}.
+ * @param int $mask Filter mask for the variable
+ *
+ * @return mixed Requested variable
+ */
+ public static function getVar($name, $default = null, $hash = 'default', $type = 'none', $mask = 0)
+ {
+ // Ensure hash and type are uppercase
+ $hash = strtoupper($hash);
+ if ($hash === 'METHOD') {
+ $hash = strtoupper($_SERVER['REQUEST_METHOD']);
+ }
+ $type = strtoupper($type);
+ $sig = $hash . $type . $mask;
+
+ // Get the input hash
+ switch ($hash) {
+ case 'GET':
+ $input = &$_GET;
+ break;
+ case 'POST':
+ $input = &$_POST;
+ break;
+ case 'FILES':
+ $input = &$_FILES;
+ break;
+ case 'COOKIE':
+ $input = &$_COOKIE;
+ break;
+ case 'ENV':
+ $input = &$_ENV;
+ break;
+ case 'SERVER':
+ $input = &$_SERVER;
+ break;
+ default:
+ $input = &$_REQUEST;
+ $hash = 'REQUEST';
+ break;
+ }
+
+ if (isset($input[$name]) && $input[$name] !== null) {
+ // Get the variable from the input hash and clean it
+ $var = XoopsRequest::cleanVar($input[$name], $mask, $type);
+
+ // Handle magic quotes compatability
+ if (get_magic_quotes_gpc() && ($var != $default) && ($hash != 'FILES')) {
+ $var = XoopsRequest::stripSlashesRecursive($var);
+ }
+ } else {
+ if ($default !== null) {
+ // Clean the default value
+ $var = XoopsRequest::cleanVar($default, $mask, $type);
+ } else {
+ $var = $default;
+ }
+ }
+
+ return $var;
+ }
+
+ /**
+ * Fetches and returns a given filtered variable. The integer
+ * filter will allow only digits to be returned. This is currently
+ * only a proxy function for getVar().
+ *
+ * See getVar() for more in-depth documentation on the parameters.
+ *
+ * @param string $name Variable name
+ * @param int $default Default value if the variable does not exist
+ * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
+ *
+ * @return int Requested variable
+ */
+ public static function getInt($name, $default = 0, $hash = 'default')
+ {
+ return XoopsRequest::getVar($name, $default, $hash, 'int');
+ }
+
+ /**
+ * Fetches and returns a given filtered variable. The float
+ * filter only allows digits and periods. This is currently
+ * only a proxy function for getVar().
+ *
+ * See getVar() for more in-depth documentation on the parameters.
+ *
+ * @param string $name Variable name
+ * @param float $default Default value if the variable does not exist
+ * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
+ *
+ * @return float Requested variable
+ */
+ public static function getFloat($name, $default = 0.0, $hash = 'default')
+ {
+ return XoopsRequest::getVar($name, $default, $hash, 'float');
+ }
+
+ /**
+ * Fetches and returns a given filtered variable. The bool
+ * filter will only return true/false bool values. This is
+ * currently only a proxy function for getVar().
+ *
+ * See getVar() for more in-depth documentation on the parameters.
+ *
+ * @param string $name Variable name
+ * @param bool $default Default value if the variable does not exist
+ * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
+ *
+ * @return bool Requested variable
+ */
+ public static function getBool($name, $default = false, $hash = 'default')
+ {
+ return XoopsRequest::getVar($name, $default, $hash, 'bool');
+ }
+
+ /**
+ * Fetches and returns a given filtered variable. The word
+ * filter only allows the characters [A-Za-z_]. This is currently
+ * only a proxy function for getVar().
+ *
+ * See getVar() for more in-depth documentation on the parameters.
+ *
+ * @param string $name Variable name
+ * @param string $default Default value if the variable does not exist
+ * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
+ *
+ * @return string Requested variable
+ */
+ public static function getWord($name, $default = '', $hash = 'default')
+ {
+ return XoopsRequest::getVar($name, $default, $hash, 'word');
+ }
+
+ /**
+ * Fetches and returns a given filtered variable. The cmd
+ * filter only allows the characters [A-Za-z0-9.-_]. This is
+ * currently only a proxy function for getVar().
+ *
+ * See getVar() for more in-depth documentation on the parameters.
+ *
+ * @param string $name Variable name
+ * @param string $default Default value if the variable does not exist
+ * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
+ *
+ * @return string Requested variable
+ */
+ public static function getCmd($name, $default = '', $hash = 'default')
+ {
+ return XoopsRequest::getVar($name, $default, $hash, 'cmd');
+ }
+
+ /**
+ * Fetches and returns a given filtered variable. The string
+ * filter deletes 'bad' HTML code, if not overridden by the mask.
+ * This is currently only a proxy function for getVar().
+ *
+ * See getVar() for more in-depth documentation on the parameters.
+ *
+ * @param string $name Variable name
+ * @param string $default Default value if the variable does not exist
+ * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
+ * @param int $mask Filter mask for the variable
+ *
+ * @return string Requested variable
+ */
+ public static function getString($name, $default = '', $hash = 'default', $mask = 0)
+ {
+ // Cast to string, in case XoopsRequest::ALLOWRAW was specified for mask
+ return (string) XoopsRequest::getVar($name, $default, $hash, 'string', $mask);
+ }
+
+ /**
+ * Fetches and returns an array
+ *
+ * @param string $name Variable name
+ * @param string $default Default value if the variable does not exist
+ * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
+ *
+ * @return array
+ */
+ public static function getArray($name, $default = array(), $hash = 'default')
+ {
+ return XoopsRequest::getVar($name, $default, $hash, 'array');
+ }
+
+ /**
+ * Fetches and returns raw text
+ *
+ * @param string $name Variable name
+ * @param string $default Default value if the variable does not exist
+ * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
+ *
+ * @return string Requested variable
+ */
+ public static function getText($name, $default = '', $hash = 'default')
+ {
+ return (string) XoopsRequest::getVar($name, $default, $hash, 'string', XoopsRequest::ALLOWRAW);
+ }
+
+ /**
+ * Set a variable in one of the request variables
+ *
+ * @param string $name Name
+ * @param string $value Value
+ * @param string $hash Hash
+ * @param boolean $overwrite Boolean
+ *
+ * @return string Previous value
+ */
+ public static function setVar($name, $value = null, $hash = 'method', $overwrite = true)
+ {
+ //If overwrite is true, makes sure the variable hasn't been set yet
+ if (!$overwrite && array_key_exists($name, $_REQUEST)) {
+ return $_REQUEST[$name];
+ }
+
+ // Get the request hash value
+ $hash = strtoupper($hash);
+ if ($hash === 'METHOD') {
+ $hash = strtoupper($_SERVER['REQUEST_METHOD']);
+ }
+
+ $previous = array_key_exists($name, $_REQUEST) ? $_REQUEST[$name] : null;
+
+ switch ($hash) {
+ case 'GET':
+ $_GET[$name] = $value;
+ $_REQUEST[$name] = $value;
+ break;
+ case 'POST':
+ $_POST[$name] = $value;
+ $_REQUEST[$name] = $value;
+ break;
+ case 'COOKIE':
+ $_COOKIE[$name] = $value;
+ $_REQUEST[$name] = $value;
+ break;
+ case 'FILES':
+ $_FILES[$name] = $value;
+ break;
+ case 'ENV':
+ $_ENV['name'] = $value;
+ break;
+ case 'SERVER':
+ $_SERVER['name'] = $value;
+ break;
+ }
+
+ return $previous;
+ }
+
+ /**
+ * Fetches and returns a request array.
+ *
+ * The default behaviour is fetching variables depending on the
+ * current request method: GET and HEAD will result in returning
+ * $_GET, POST and PUT will result in returning $_POST.
+ *
+ * You can force the source by setting the $hash parameter:
+ *
+ * - post $_POST
+ * - get $_GET
+ * - files $_FILES
+ * - cookie $_COOKIE
+ * - env $_ENV
+ * - server $_SERVER
+ * - method via current $_SERVER['REQUEST_METHOD']
+ * - default $_REQUEST
+ *
+ * @param string $hash to get (POST, GET, FILES, METHOD)
+ * @param int $mask Filter mask for the variable
+ *
+ * @return mixed Request hash
+ */
+ public static function get($hash = 'default', $mask = 0)
+ {
+ $hash = strtoupper($hash);
+
+ if ($hash === 'METHOD') {
+ $hash = strtoupper($_SERVER['REQUEST_METHOD']);
+ }
+
+ switch ($hash) {
+ case 'GET':
+ $input = $_GET;
+ break;
+ case 'POST':
+ $input = $_POST;
+ break;
+ case 'FILES':
+ $input = $_FILES;
+ break;
+ case 'COOKIE':
+ $input = $_COOKIE;
+ break;
+ case 'ENV':
+ $input = &$_ENV;
+ break;
+ case 'SERVER':
+ $input = &$_SERVER;
+ break;
+ default:
+ $input = $_REQUEST;
+ break;
+ }
+
+ // Handle magic quotes compatability
+ if (get_magic_quotes_gpc() && ($hash != 'FILES')) {
+ $input = XoopsRequest::stripSlashesRecursive($input);
+ }
+
+ $result = XoopsRequest::cleanVars($input, $mask);
+
+ return $result;
+ }
+
+ /**
+ * Sets a request variable
+ *
+ * @param array $array An associative array of key-value pairs
+ * @param string $hash The request variable to set (POST, GET, FILES, METHOD)
+ * @param boolean $overwrite If true and an existing key is found, the value is overwritten, otherwise it is ingored
+ *
+ * @return void
+ */
+ public static function set($array, $hash = 'default', $overwrite = true)
+ {
+ foreach ($array as $key => $value) {
+ XoopsRequest::setVar($key, $value, $hash, $overwrite);
+ }
+ }
+
+ /**
+ * Clean up an input variable.
+ *
+ * @param mixed $var The input variable.
+ * @param int $mask Filter bit mask.
+ * - 1=no trim: If this flag is cleared and the input is a string,
+ * the string will have leading and trailing whitespace trimmed.
+ * - 2=allow_raw: If set, no more filtering is performed, higher bits are ignored.
+ * - 4=allow_html: HTML is allowed, but passed through a safe HTML filter first.
+ * If set, no more filtering is performed.
+ * - If no bits other than the 1 bit is set, a strict filter is applied.
+ * @param string $type The variable type. See {@link XoopsFilterInput::clean()}.
+ *
+ * @return string
+ */
+ private static function cleanVar($var, $mask = 0, $type = null)
+ {
+ // Static input filters for specific settings
+ static $noHtmlFilter = null;
+ static $safeHtmlFilter = null;
+
+ // If the no trim flag is not set, trim the variable
+ if (!($mask & 1) && is_string($var)) {
+ $var = trim($var);
+ }
+
+ // Now we handle input filtering
+ if ($mask & 2) {
+ // If the allow raw flag is set, do not modify the variable
+ } else {
+ XoopsLoad::load('xoopsfilterinput');
+ if ($mask & 4) {
+ // If the allow html flag is set, apply a safe html filter to the variable
+ if (is_null($safeHtmlFilter)) {
+ $safeHtmlFilter = XoopsFilterInput::getInstance(null, null, 1, 1);
+ }
+ $var = $safeHtmlFilter->clean($var, $type);
+ } else {
+ // Since no allow flags were set, we will apply the most strict filter to the variable
+ if (is_null($noHtmlFilter)) {
+ $noHtmlFilter = XoopsFilterInput::getInstance();
+ }
+ $var = $noHtmlFilter->clean($var, $type);
+ }
+ }
+
+ return $var;
+ }
+
+ /**
+ * Clean up an array of variables.
+ *
+ * @param mixed $var The input variable.
+ * @param int $mask Filter bit mask. See {@link XoopsRequest::cleanVar()}
+ * @param string $type The variable type. See {@link XoopsFilterInput::clean()}.
+ *
+ * @return string
+ */
+ private static function cleanVars($var, $mask = 0, $type = null)
+ {
+ if (is_string($var)) {
+ $var = XoopsRequest::cleanVar($var, $mask, $type);
+ } else {
+ foreach ($var as $key => &$value) {
+ $value = XoopsRequest::cleanVars($value, $mask, $type);
+ }
+ }
+
+ return $var;
+ }
+
+
+ /**
+ * Strips slashes recursively on an array
+ *
+ * @param array $value Array of (nested arrays of) strings
+ *
+ * @return array The input array with stripshlashes applied to it
+ */
+ private static function stripSlashesRecursive($value)
+ {
+ $value = is_array($value) ? array_map(array('XoopsRequest', 'stripSlashesRecursive'), $value)
+ : stripslashes($value);
+
+ return $value;
+ }
+}
|