tuxmartin

CakePHP TinymceHelper

May 15th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.25 KB | None | 0 0
  1. <?php
  2. //     /cakephp/app/View/Helper/TinymceHelper.php
  3.  
  4. App::uses('AppHelper', 'View/Helper');
  5.  
  6. class TinymceHelper extends AppHelper {
  7.    
  8.     public $helpers = array('Js', 'Html', 'Form');
  9.  
  10.     public $_script = false;
  11.  
  12.     function _build($fieldName, $tinyoptions = array()){
  13.         if(!$this->_script){
  14.             $this->_script = true;
  15.             $this->Html->script('tiny_mce/tinymce.min', array('inline' => false));
  16.             $this->Html->script('tiny_mce/jquery.tinymce.min', array('inline' => false));
  17.         }
  18.  
  19.        
  20.         $tinyoptions['elements'] = $this->domId($fieldName);
  21.  
  22.         $value_arr = array();
  23.         $replace_keys = array();
  24.         foreach($tinyoptions as $key => &$value){
  25.             if(strpos($value, 'function(') === 0){
  26.                 $value_arr[] = $value;
  27.                 $value = '%' . $key . '%';
  28.                 $replace_keys[] = '"' . $value . '"';
  29.             }
  30.         }
  31.  
  32.  
  33.         $this->Html->scriptStart(array('inline' => false));
  34.        
  35.        
  36.         echo 'tinymce.init({
  37.    selector: "textarea",
  38.    theme: "modern",
  39.    mode: "textareas",
  40.    plugins: [
  41.        "advlist autolink lists link image charmap print preview hr anchor pagebreak",
  42.        "searchreplace wordcount visualblocks visualchars code fullscreen",
  43.        "insertdatetime media nonbreaking save table contextmenu directionality",
  44.        "emoticons template paste"
  45.    ],
  46.    toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
  47.    toolbar2: "print preview media | forecolor backcolor emoticons",
  48.    templates: [
  49.        {title: \'Test template 1\', content: \'Test 1\'},
  50.        {title: \'Test template 2\', content: \'Test 2\'}
  51.    ]
  52. });';
  53.         $this->Html->scriptEnd();
  54.     }
  55.  
  56.     function textarea($fieldName, $options = array(), $tinyoptions = array()){
  57.         return $this->Form->textarea($fieldName, $options) . $this->_build($fieldName, $tinyoptions);
  58.     }
  59.  
  60.     function input($fieldName, $options = array(), $tinyoptions = array()){
  61.         $options['type'] = 'textarea';
  62.         return $this->Form->input($fieldName, $options) . $this->_build($fieldName, $tinyoptions);
  63.     }
  64.    
  65. }
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment