PageRenderTime 46ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/xoops/xoopseditor/elrte/trunk/formelrte.php

https://github.com/krisxoofoo/XooFoo
PHP | 186 lines | 93 code | 15 blank | 78 comment | 8 complexity | 604e15b3ea49a2ce1307ad6679da573c MD5 | raw file
  1. <?php
  2. /**
  3. * Adapted elRTE wysiwyg editor
  4. *
  5. * @copyright The XOOPS project http://www.xoops.org/
  6. * @license http://www.fsf.org/copyleft/gpl.html GNU public license
  7. * @package core
  8. * @subpackage xoopseditor
  9. * @since 2.4.5
  10. * @author Taiwen Jiang <phppp@users.sourceforge.net>
  11. * @author kris <http://www.xoofoo.org>
  12. */
  13. xoops_load('XoopsEditor');
  14. /**
  15. * Constructor
  16. *
  17. * @param string $caption Caption
  18. * @param string $name "name" attribute
  19. * @param string $value Initial text
  20. * @param string $width iframe width
  21. * @param string $height iframe height
  22. * @param array $options Toolbar Options
  23. */
  24. class XoopsFormElrte extends XoopsEditor
  25. {
  26. var $language = _LANGCODE;
  27. var $width;
  28. var $height;
  29. var $editor;
  30. // PHP 5 Constructor
  31. function __construct($configs)
  32. {
  33. $current_path = __FILE__;
  34. if ( DIRECTORY_SEPARATOR != "/" ) {
  35. $current_path = str_replace( strpos( $current_path, "\\\\", 2 ) ? "\\\\" : DIRECTORY_SEPARATOR, "/", $current_path);
  36. }
  37. $this->rootPath = "/class/xoopseditor/elrte";
  38. parent::__construct($configs);
  39. //$this->XoopsFormTextArea($configs['caption'], $configs['name'], $configs['value']);
  40. $this->width = $configs['width'];
  41. $this->height = $configs['height'];
  42. }
  43. // PHP 4 Constructor
  44. function XoopsFormElrte($configs)
  45. {
  46. $this->__construct($configs);
  47. }
  48. function getName()
  49. {
  50. return $this->name;
  51. }
  52. function setName($value)
  53. {
  54. $this->name = $value;
  55. }
  56. /**
  57. * get textarea width
  58. *
  59. * @return string
  60. */
  61. function getWidth()
  62. {
  63. return $this->width;
  64. }
  65. /**
  66. * get textarea height
  67. *
  68. * @return string
  69. */
  70. function getHeight()
  71. {
  72. return $this->height;
  73. }
  74. /**
  75. * get language
  76. *
  77. * @return string
  78. */
  79. function getLanguage()
  80. {
  81. return str_replace('_','-',strtolower($this->language));
  82. }
  83. /**
  84. * set language
  85. *
  86. * @return null
  87. */
  88. function setLanguage($lang='en')
  89. {
  90. $this->language = $lang;
  91. }
  92. /**
  93. * Get initial content
  94. *
  95. * @param bool $encode To sanitizer the text? Default value should be "true"; however we have to set "false" for backward compat
  96. * @return string
  97. */
  98. function getValue() {
  99. return strtr(htmlspecialchars_decode($this->_value) , array("\n" => '<br />', "\r\n" =>'<br />'));
  100. }
  101. /**
  102. * Renders the Javascript function needed for client-side for validation
  103. *
  104. * @return string
  105. */
  106. function renderValidationJS()
  107. {
  108. if ($this->isRequired() && $eltname = $this->getName()) {
  109. $eltcaption = $this->getCaption();
  110. $eltmsg = empty($eltcaption) ? sprintf( _FORM_ENTER, $eltname ) : sprintf( _FORM_ENTER, $eltcaption );
  111. $eltmsg = str_replace('"', '\"', stripslashes( $eltmsg ) );
  112. $ret = "\n";
  113. $ret.= "if ( myform.{$eltname}.value == '' || myform.{$eltname}.value == '<br />' )";
  114. $ret.= "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }";
  115. return $ret;
  116. }
  117. return '';
  118. }
  119. /**
  120. * prepare HTML for output
  121. *
  122. * @return sting HTML
  123. */
  124. function render()
  125. {
  126. static $isJsLoaded = false;
  127. $ret = "\n";
  128. if(!$isJsLoaded)
  129. {
  130. $GLOBALS['xoTheme']->addStylesheet( XOOPS_URL . '/class/xoopseditor/elrte/elrte/js/ui-themes/smoothness/jquery-ui-1.8.5.custom.css' );
  131. $GLOBALS['xoTheme']->addStylesheet( XOOPS_URL . '/class/xoopseditor/elrte/elrte/css/elrte.full.css' );
  132. //$GLOBALS['xoTheme']->addStylesheet( XOOPS_URL . '/class/xoopseditor/elrte/elfinder/js/ui-themes/base/ui.all.css' );
  133. //$GLOBALS['xoTheme']->addStylesheet( XOOPS_URL . '/class/xoopseditor/elrte/elfinder/css/elfinder.css' );
  134. $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
  135. $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
  136. $GLOBALS['xoTheme']->addScript( XOOPS_URL . '/class/xoopseditor/elrte/elrte/js/elrte.min.js' );
  137. // load language file
  138. $GLOBALS['xoTheme']->addScript( XOOPS_URL . '/class/xoopseditor/elrte/elrte/js/i18n/elrte.'.$this->getLanguage().'.js' );
  139. //$GLOBALS['xoTheme']->addScript( XOOPS_URL . '/class/xoopseditor/elrte/elfinder/js/elfinder.min.js' );
  140. //$GLOBALS['xoTheme']->addScript( XOOPS_URL . '/class/xoopseditor/elrte/elfinder/js/i18n/elfinder.'.$this->getLanguage().'.js' );
  141. $isJsLoaded = true;
  142. }
  143. $ret.= "<script type='text/javascript' charset='utf-8'>\n";
  144. $ret.= "jQuery().ready(function() {\n";
  145. //$ret.= " jQuery('selector').elrte({\n";
  146. //$ret.= " // ... elrte options\n";
  147. //$ret.= " fmOpen : function(callback) {\n";
  148. //$ret.= " jQuery('<div id=\"myelfinder\" />').elfinder({\n";
  149. //$ret.= " url : '".XOOPS_URL."/class/xoopseditor/elrte/elfinder/connectors/php/connector.php',\n";
  150. //$ret.= " lang : '".$this->getLanguage()."',\n"; // set your language
  151. //$ret.= " dialog : { width : 900, modal : true, title : 'Files' },\n"; // open in dialog window
  152. //$ret.= " closeOnEditorCallback : true,\n"; // close after file select
  153. //$ret.= " editorCallback : callback \n"; // pass callback to file manager
  154. //$ret.= " })\n";
  155. //$ret.= " }\n";
  156. //$ret.= "})\n";
  157. $ret.= " var opts = {\n";
  158. $ret.= " lang : '".$this->getLanguage()."',\n"; // set your language
  159. $ret.= " styleWidthCss : false,\n";
  160. $ret.= " height : 450,\n";
  161. $ret.= " toolbar : 'maxi'\n";
  162. $ret.= " };\n";
  163. // create editor
  164. $ret.= " jQuery('#".$this->getName()."').elrte(opts);\n";
  165. $ret.= " });\n";
  166. $ret.= "</script>\n";
  167. $ret.= "<div class='".$this->getName()."' name='".$this->getName()."' id='".$this->getName()."' ".$this->getExtra()."style='width:".$this->getWidth().";height:".$this->getHeight().";'>" . $this->getValue() . "</div>";
  168. return $ret ;
  169. }
  170. }
  171. ?>