tinymce在smarty下使用

在Smarty的插件加入名为function.tinyMCE.php的文件,代码如下:

  1. <?php
  2.  
  3. /*
  4.  * Smarty plugin
  5.  * -------------------------------------------------------------
  6.  * Type:     function
  7.  * Name:     tinyMCE
  8.  * Version:  0.8
  9.  * Date:     07 Mar, 2007
  10.  * Author: Rafael Dohms <rafael@rafaeldohms.com.br>
  11.  * Purpose:  inserts TinyMCE Code and inicializes editor
  12.  * Input:    mode = method of selection of fields
  13.  *           = Textarea elements target for editor
  14.  *
  15.  * -------------------------------------------------------------
  16.  */
  17. function smarty_function_tinyMCE($params, &$smarty)
  18. {
  19.  
  20. //Default values
  21. $atribs['mode'] = 'specific_textareas';
  22. $atribs['theme_advanced_toolbar_location'] = 'top';
  23. $atribs['theme_advanced_toolbar_align'] = 'left';
  24. $atribs['theme_advanced_blockformats'] = "address,pre,h1,h2,h3,h4,h5,h6";
  25. $atribs['theme_advanced_resizing'] = "true";
  26. $atribs['theme_advanced_buttons1'] = "bold,italic,underline,separator,justifyleft,justifycenter,justifyright,separator,bullist,numlist,separator,outdent,indent,separator,link,unlink,image,separator,sup,sub,separator,charmap";
  27. $atribs['theme_advanced_buttons2'] = "undo,redo,code";
  28. $atribs['theme_advanced_buttons3'] = "";
  29. $atribs['force_br_newlines'] = "true";
  30. $atribs['plugins'] = "advimage";
  31. $atribs['dialog_type'] = "modal";
  32. $atribs['language'] = "pt_br";
  33. $atribs['convert_newlines_to_brs'] = "true";
  34. //Iterar by attributes past
  35. foreach($params as $_key => $_val) {
  36. if (substr($_key,0,1) == '_'){
  37. $key = substr($_key,1);
  38. $$key = $_val;
  39. }else{
  40. $atribs[$_key] = $_val;
  41. }
  42. }
  43. //Set path of the file of the tiny
  44. $src = ($altsrc != '')? $altsrc:"jsglobal/tiny_mce/tiny_mce.js";
  45. //Check whether or not insert library
  46. if (!$GLOBALS['smarty']['tinyMCE']['JS']){
  47. $code     = '<script language="javascript" type="text/javascript" src="'.$src.'"></script>';
  48. }
  49. //Start the boot code of the editor
  50. $code   .= '<script language="javascript" type="text/javascript">';
  51. $code   .= 'tinyMCE.init({';
  52. //Iterar on attributes
  53. foreach($atribs as $atr=>$value){
  54. $code .= $atr.': "'.$value.'",';
  55. }
  56. //End
  57. $code .= 'blank: "none"'; //Evitar problem de virgula perdida
  58. $code .= '});';
  59. $code .= '</script>';
  60. //Set variable comprehensive library inserted
  61. $GLOBALS['smarty']['tinyMCE']['JS'] = true;
  62. //Return code
  63.     return $code;
  64. }
  65.  
  66. /* vim: set expandtab: */
  67.  
  68. ?>

RSS feed for comments on this post · TrackBack URL

发表评论

You must be logged in to post a comment.