Source for file tinymce.php

Documentation is available at tinymce.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Plugin
  4.  * @subpackage  Editors.tinymce
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * TinyMCE Editor Plugin
  14.  *
  15.  * @package     Joomla.Plugin
  16.  * @subpackage  Editors.tinymce
  17.  * @since       1.5
  18.  */
  19. class PlgEditorTinymce extends JPlugin
  20. {
  21.     /**
  22.      * Base path for editor files
  23.      */
  24.     protected $_basePath = 'media/editors/tinymce';
  25.  
  26.     /**
  27.      * Load the language file on instantiation.
  28.      *
  29.      * @var    boolean 
  30.      * @since  3.1
  31.      */
  32.     protected $autoloadLanguage = true;
  33.  
  34.     /**
  35.      * Loads the application object
  36.      *
  37.      * @var    JApplicationCms 
  38.      * @since  3.2
  39.      */
  40.     protected $app = null;
  41.  
  42.     /**
  43.      * Initialises the Editor.
  44.      *
  45.      * @return  string  JavaScript Initialization string
  46.      *
  47.      * @since 1.5
  48.      */
  49.     public function onInit()
  50.     {
  51.         $language JFactory::getLanguage();
  52.  
  53.         $mode = (int) $this->params->get('mode'1);
  54.         $theme    'modern';
  55.         $skin    $this->params->get('skin''0');
  56.  
  57.         switch ($skin)
  58.         {
  59.             case '0':
  60.             default:
  61.                 $skin 'skin : "lightgray",';
  62.         }
  63.  
  64.         $entity_encoding    $this->params->get('entity_encoding''raw');
  65.  
  66.         $langMode            $this->params->get('lang_mode'0);
  67.         $langPrefix            $this->params->get('lang_code''en');
  68.  
  69.         if ($langMode)
  70.         {
  71.             if (file_exists(JPATH_ROOT "/media/editors/tinymce/langs/" $language->getTag(".js"))
  72.             {
  73.                 $langPrefix $language->getTag();
  74.             }
  75.             elseif (file_exists(JPATH_ROOT "/media/editors/tinymce/langs/" substr($language->getTag()0strpos($language->getTag()'-')) ".js"))
  76.             {
  77.                 $langPrefix substr($language->getTag()0strpos($language->getTag()'-'));
  78.             }
  79.             else
  80.             {
  81.                 $langPrefix "en";
  82.             }
  83.         }
  84.  
  85.         $text_direction 'ltr';
  86.  
  87.         if ($language->isRTL())
  88.         {
  89.             $text_direction 'rtl';
  90.         }
  91.  
  92.         $use_content_css    $this->params->get('content_css'1);
  93.         $content_css_custom    $this->params->get('content_css_custom''');
  94.  
  95.         /*
  96.          * Lets get the default template for the site application
  97.          */
  98.         $db        JFactory::getDbo();
  99.         $query    $db->getQuery(true)
  100.             ->select('template')
  101.             ->from('#__template_styles')
  102.             ->where('client_id=0 AND home=' $db->quote('1'));
  103.  
  104.         $db->setQuery($query);
  105.         $template $db->loadResult();
  106.  
  107.         $content_css '';
  108.  
  109.         $templates_path JPATH_SITE '/templates';
  110.  
  111.         // Loading of css file for 'styles' dropdown
  112.         if $content_css_custom )
  113.         {
  114.             // If URL, just pass it to $content_css
  115.             if (strpos($content_css_custom'http'!== false)
  116.             {
  117.                 $content_css 'content_css : "' $content_css_custom '",';
  118.             }
  119.  
  120.             // If it is not a URL, assume it is a file name in the current template folder
  121.             else
  122.             {
  123.                 $content_css 'content_css : "' JUri::root('templates/' $template '/css/' $content_css_custom '",';
  124.  
  125.                 // Issue warning notice if the file is not found (but pass name to $content_css anyway to avoid TinyMCE error
  126.                 if (!file_exists($templates_path '/' $template '/css/' $content_css_custom))
  127.                 {
  128.                     $msg sprintf(JText::_('PLG_TINY_ERR_CUSTOMCSSFILENOTPRESENT')$content_css_custom);
  129.                     JLog::add($msgJLog::WARNING'jerror');
  130.                 }
  131.             }
  132.         }
  133.         else
  134.         {
  135.             // Process when use_content_css is Yes and no custom file given
  136.             if ($use_content_css)
  137.             {
  138.                 // First check templates folder for default template
  139.                 // if no editor.css file in templates folder, check system template folder
  140.                 if (!file_exists($templates_path '/' $template '/css/editor.css'))
  141.                 {
  142.                     // If no editor.css file in system folder, show alert
  143.                     if (!file_exists($templates_path '/system/css/editor.css'))
  144.                     {
  145.                         JLog::add(JText::_('PLG_TINY_ERR_EDITORCSSFILENOTPRESENT')JLog::WARNING'jerror');
  146.                     }
  147.                     else
  148.                     {
  149.                         $content_css 'content_css : "' JUri::root('templates/system/css/editor.css",';
  150.                     }
  151.                 }
  152.                 else
  153.                 {
  154.                     $content_css 'content_css : "' JUri::root('templates/' $template '/css/editor.css",';
  155.                 }
  156.             }
  157.         }
  158.  
  159.         $relative_urls        $this->params->get('relative_urls''1');
  160.  
  161.         if ($relative_urls)
  162.         {
  163.             // Relative
  164.             $relative_urls "true";
  165.         }
  166.         else
  167.         {
  168.             // Absolute
  169.             $relative_urls "false";
  170.         }
  171.  
  172.         $newlines            $this->params->get('newlines'0);
  173.  
  174.         if ($newlines)
  175.         {
  176.             // Break
  177.             $forcenewline "force_br_newlines : true, force_p_newlines : false, forced_root_block : '',";
  178.         }
  179.         else
  180.         {
  181.             // Paragraph
  182.             $forcenewline "force_br_newlines : false, force_p_newlines : true, forced_root_block : 'p',";
  183.         }
  184.  
  185.         $invalid_elements    $this->params->get('invalid_elements''script,applet,iframe');
  186.         $extended_elements    $this->params->get('extended_elements''');
  187.  
  188.         // Advanced Options
  189.         $html_height        $this->params->get('html_height''550');
  190.         $html_width            $this->params->get('html_width''750');
  191.  
  192.         // The param is true false, so we turn true to both rather than showing vertical resize only
  193.         $resizing $this->params->get('resizing''1');
  194.  
  195.         if ($resizing || $resizing == 'true')
  196.         {
  197.             $resizing 'resize: "both",';
  198.         }
  199.         else
  200.         {
  201.             $resizing 'resize: false,';
  202.         }
  203.  
  204.         $toolbar1_add array();
  205.         $toolbar2_add array();
  206.         $toolbar3_add array();
  207.         $toolbar4_add array();
  208.         $elements array();
  209.         $plugins array('autolink''lists''image''charmap''print''preview''anchor''pagebreak''code''save''textcolor''importcss');
  210.         $toolbar1_add['bold';
  211.         $toolbar1_add['italic';
  212.         $toolbar1_add['underline';
  213.         $toolbar1_add['strikethrough';
  214.  
  215.         // Alignment buttons
  216.         $alignment $this->params->get('alignment'1);
  217.  
  218.         if ($alignment)
  219.         {
  220.             $toolbar1_add['|';
  221.             $toolbar1_add['alignleft';
  222.             $toolbar1_add['aligncenter';
  223.             $toolbar1_add['alignright';
  224.             $toolbar1_add['alignjustify';
  225.         }
  226.  
  227.         $toolbar1_add['|';
  228.         $toolbar1_add['styleselect';
  229.         $toolbar1_add['|';
  230.         $toolbar1_add['formatselect';
  231.  
  232.         // Fonts
  233.         $fonts $this->params->get('fonts'1);
  234.  
  235.         if ($fonts)
  236.         {
  237.             $toolbar1_add[]    'fontselect';
  238.             $toolbar1_add['fontsizeselect';
  239.         }
  240.  
  241.         // Search & replace
  242.         $searchreplace $this->params->get('searchreplace'1);
  243.  
  244.         if ($searchreplace)
  245.         {
  246.             $plugins[]    'searchreplace';
  247.             $toolbar2_add['searchreplace';
  248.         }
  249.  
  250.         $toolbar2_add['|';
  251.         $toolbar2_add['bullist';
  252.         $toolbar2_add['numlist';
  253.         $toolbar2_add['|';
  254.         $toolbar2_add[]    'outdent';
  255.         $toolbar2_add[]    'indent';
  256.         $toolbar2_add['|';
  257.         $toolbar2_add['undo';
  258.         $toolbar2_add['redo';
  259.         $toolbar2_add['|';
  260.  
  261.         // Insert date and/or time plugin
  262.         $insertdate    $this->params->get('insertdate'1);
  263.  
  264.         if ($insertdate)
  265.         {
  266.             $plugins[]    'insertdatetime';
  267.             $toolbar4_add['inserttime';
  268.         }
  269.  
  270.         // Link plugin
  271.         $link $this->params->get('link'1);
  272.  
  273.         if ($link)
  274.         {
  275.             $plugins[]    'link';
  276.             $toolbar2_add['link';
  277.             $toolbar2_add['unlink';
  278.         }
  279.  
  280.         $toolbar2_add['anchor';
  281.         $toolbar2_add['image';
  282.         $toolbar2_add['|';
  283.         $toolbar2_add['code';
  284.  
  285.         // Colours
  286.         $colours $this->params->get('colours'1);
  287.  
  288.         if ($colours)
  289.         {
  290.             $toolbar2_add['|';
  291.             $toolbar2_add[]    'forecolor,backcolor';
  292.         }
  293.  
  294.         // Fullscreen
  295.         $fullscreen    $this->params->get('fullscreen'1);
  296.  
  297.         if ($fullscreen)
  298.         {
  299.             $plugins[]    'fullscreen';
  300.             $toolbar2_add['|';
  301.             $toolbar2_add[]    'fullscreen';
  302.         }
  303.  
  304.         // Table
  305.         $table $this->params->get('table'1);
  306.  
  307.         if ($table)
  308.         {
  309.             $plugins[]    'table';
  310.             $toolbar3_add[]    'table';
  311.             $toolbar3_add['|';
  312.         }
  313.  
  314.         $toolbar3_add['subscript';
  315.         $toolbar3_add['superscript';
  316.         $toolbar3_add['|';
  317.         $toolbar3_add['charmap';
  318.  
  319.         // Emotions
  320.         $smilies $this->params->get('smilies'1);
  321.  
  322.         if ($smilies)
  323.         {
  324.             $plugins[]    'emoticons';
  325.             $toolbar3_add[]    'emoticons';
  326.         }
  327.  
  328.         // Media plugin
  329.         $media $this->params->get('media'1);
  330.  
  331.         if ($media)
  332.         {
  333.             $plugins['media';
  334.             $toolbar3_add['media';
  335.         }
  336.  
  337.         // Horizontal line
  338.         $hr $this->params->get('hr'1);
  339.  
  340.         if ($hr)
  341.         {
  342.             $plugins[]    'hr';
  343.             $elements['hr[id|title|alt|class|width|size|noshade]';
  344.             $toolbar3_add['hr';
  345.         }
  346.         else
  347.         {
  348.             $elements['hr[id|class|title|alt]';
  349.         }
  350.  
  351.         // RTL/LTR buttons
  352.         $directionality    $this->params->get('directionality'1);
  353.  
  354.         if ($directionality)
  355.         {
  356.             $plugins['directionality';
  357.             $toolbar3_add[]    'ltr rtl';
  358.         }
  359.  
  360.         if ($extended_elements != "")
  361.         {
  362.             $elements    explode(','$extended_elements);
  363.         }
  364.  
  365.         $toolbar4_add['cut';
  366.         $toolbar4_add['copy';
  367.  
  368.         // Paste
  369.         $paste $this->params->get('paste'1);
  370.  
  371.         if ($paste)
  372.         {
  373.             $plugins[]    'paste';
  374.             $toolbar4_add['paste';
  375.         }
  376.  
  377.         $toolbar4_add['|';
  378.  
  379.         // Visualchars
  380.         $visualchars $this->params->get('visualchars'1);
  381.  
  382.         if ($visualchars)
  383.         {
  384.             $plugins[]    'visualchars';
  385.             $toolbar4_add['visualchars';
  386.         }
  387.  
  388.         // Visualblocks
  389.         $visualblocks $this->params->get('visualblocks'1);
  390.  
  391.         if ($visualblocks)
  392.         {
  393.             $plugins[]    'visualblocks';
  394.             $toolbar4_add['visualblocks';
  395.         }
  396.  
  397.         // Non-breaking
  398.         $nonbreaking $this->params->get('nonbreaking'1);
  399.  
  400.         if ($nonbreaking)
  401.         {
  402.             $plugins[]    'nonbreaking';
  403.  
  404.             $toolbar4_add['nonbreaking';
  405.         }
  406.  
  407.         // Blockquote
  408.         $blockquote    $this->params->get('blockquote'1);
  409.  
  410.         if ($blockquote)
  411.         {
  412.             $toolbar4_add['blockquote';
  413.         }
  414.  
  415.         // Template
  416.         $template $this->params->get('template'1);
  417.  
  418.         if ($template)
  419.         {
  420.             $plugins[]    'template';
  421.             $toolbar4_add['template';
  422.  
  423.             // Note this check for the template_list.js file will be removed in Joomla 4.0
  424.             if (is_file(JPATH_ROOT "/media/editors/tinymce/templates/template_list.js"))
  425.             {
  426.                 // If using the legacy file we need to include and input the files the new way
  427.                 $str file_get_contents(JPATH_ROOT "/media/editors/tinymce/templates/template_list.js");
  428.  
  429.                 // Find from one [ to the last ]
  430.                 preg_match_all('/\[.*\]/'$str$matches);
  431.  
  432.                 $templates "templates: [";
  433.  
  434.                 // Set variables
  435.                 foreach ($matches['0'as $match)
  436.                 {
  437.                     preg_match_all('/\".*\"/'$match$values);
  438.                     $result trim($values["0"]["0"]'"');
  439.                     $final_result explode(','$result);
  440.                     $templates .= "{title: '" trim($final_result['0']' " '"', description: '" trim($final_result['2']' " '"', url: '" JUri::root(trim($final_result['1']' " '"'},";
  441.                 }
  442.  
  443.                 $templates .= "],";
  444.             }
  445.             else
  446.             {
  447.                 $templates "templates: [
  448.                     {title: 'Layout', description: 'HTMLLayout', url:'" JUri::root("media/editors/tinymce/templates/layout1.html'},
  449.                     {title: 'Simple snippet', description: 'Simple HTML snippet', url:'" JUri::root("media/editors/tinymce/templates/snippet1.html'}
  450.                 ],";
  451.             }
  452.         }
  453.         else
  454.         {
  455.             $templates '';
  456.         }
  457.  
  458.         // Print
  459.         $print $this->params->get('print'1);
  460.  
  461.         if ($print)
  462.         {
  463.             $plugins['print';
  464.             $toolbar4_add['|';
  465.             $toolbar4_add['print';
  466.             $toolbar4_add['preview';
  467.         }
  468.  
  469.         // Spellchecker
  470.         $spell $this->params->get('spell'0);
  471.  
  472.         if ($spell)
  473.         {
  474.             $plugins['spellchecker';
  475.             $toolbar4_add['|';
  476.             $toolbar4_add['spellchecker';
  477.         }
  478.  
  479.         // Wordcount
  480.         $wordcount    $this->params->get('wordcount'1);
  481.  
  482.         if ($wordcount)
  483.         {
  484.             $plugins['wordcount';
  485.         }
  486.  
  487.         // Advlist
  488.         $advlist    $this->params->get('advlist'1);
  489.  
  490.         if ($advlist)
  491.         {
  492.             $plugins[]    'advlist';
  493.         }
  494.  
  495.         // Autosave
  496.         $autosave $this->params->get('autosave'1);
  497.  
  498.         if ($autosave)
  499.         {
  500.             $plugins[]    'autosave';
  501.         }
  502.  
  503.         // Context menu
  504.         $contextmenu $this->params->get('contextmenu'1);
  505.  
  506.         if ($contextmenu)
  507.         {
  508.             $plugins[]    'contextmenu';
  509.         }
  510.  
  511.         $custom_plugin $this->params->get('custom_plugin''');
  512.  
  513.         if ($custom_plugin != "")
  514.         {
  515.             $plugins[$custom_plugin;
  516.         }
  517.  
  518.         $custom_button $this->params->get('custom_button''');
  519.  
  520.         if ($custom_button != "")
  521.         {
  522.             $toolbar4_add[$custom_button;
  523.         }
  524.  
  525.         // Prepare config variables
  526.         $plugins implode(','$plugins);
  527.         $elements implode(','$elements);
  528.  
  529.         // Prepare config variables
  530.         $toolbar1 implode(' '$toolbar1_add);
  531.         $toolbar2 implode(' '$toolbar2_add);
  532.         $toolbar3 implode(' '$toolbar3_add);
  533.         $toolbar4 implode(' '$toolbar4_add);
  534.  
  535.         // See if mobileVersion is activated
  536.         $mobileVersion $this->params->get('mobile'1);
  537.  
  538.         $load "\t<script type=\"text/javascript\" src=\"" .
  539.                 JUri::root($this->_basePath .
  540.                 "/tinymce.min.js\"></script>\n";
  541.  
  542.         /**
  543.          * Shrink the buttons if not on a mobile or if mobile view is off.
  544.          * If mobile view is on force into simple mode and enlarge the buttons
  545.         **/
  546.         if (!$this->app->client->mobile)
  547.         {
  548.             $smallButtons 'toolbar_items_size: "small",';
  549.         }
  550.         elseif ($mobileVersion == false)
  551.         {
  552.             $smallButtons '';
  553.         }
  554.         else
  555.         {
  556.             $smallButtons '';
  557.             $mode 0;
  558.         }
  559.  
  560.         switch ($mode)
  561.         {
  562.             case 0/* Simple mode*/
  563.                 $return $load .
  564.                 "\t<script type=\"text/javascript\">
  565.                     tinymce.init({
  566.                         // General
  567.                         directionality: \"$text_direction\",
  568.                         selector: \"textarea.mce_editable\",
  569.                         language : \"$langPrefix\",
  570.                         mode : \"specific_textareas\",
  571.                         $skin
  572.                         theme : \"$theme\",
  573.                         schema: \"html5\",
  574.                         menubar: false,
  575.                         toolbar1: \"bold italics underline strikethrough | undo redo | bullist numlist\",
  576.                         // Cleanup/Output
  577.                         inline_styles : true,
  578.                         gecko_spellcheck : true,
  579.                         entity_encoding : \"$entity_encoding\",
  580.                         $forcenewline
  581.                         $smallButtons
  582.                         // URL
  583.                         relative_urls : $relative_urls,
  584.                         remove_script_host : false,
  585.                         // Layout
  586.                         $content_css
  587.                         document_base_url : \"JUri::root("\"
  588.                     });
  589.                 </script>";
  590.             break;
  591.  
  592.             case 1:
  593.             default/* Advanced mode*/
  594.                 $toolbar1 "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | formatselect | bullist numlist";
  595.                 $toolbar2 "outdent indent | undo redo | link unlink anchor image code | hr table | subscript superscript | charmap";
  596.                 $return $load .
  597.                 "\t<script type=\"text/javascript\">
  598.                 tinyMCE.init({
  599.                     // General
  600.                     directionality: \"$text_direction\",
  601.                     language : \"$langPrefix\",
  602.                     mode : \"specific_textareas\",
  603.                     $skin
  604.                     theme : \"$theme\",
  605.                     schema: \"html5\",
  606.                     selector: \"textarea.mce_editable\",
  607.                     // Cleanup/Output
  608.                     inline_styles : true,
  609.                     gecko_spellcheck : true,
  610.                     entity_encoding : \"$entity_encoding\",
  611.                     extended_valid_elements : \"$elements\",
  612.                     $forcenewline
  613.                     $smallButtons
  614.                     invalid_elements : \"$invalid_elements\",
  615.                     // Plugins
  616.                     plugins : \"table link image code charmap autolink lists importcss\",
  617.                     // Toolbar
  618.                     toolbar1: \"$toolbar1\",
  619.                     toolbar2: \"$toolbar2\",
  620.                     removed_menuitems: \"newdocument\",
  621.                     // URL
  622.                     relative_urls : $relative_urls,
  623.                     remove_script_host : false,
  624.                     document_base_url : \"JUri::root("\",
  625.                     // Layout
  626.                     $content_css
  627.                     importcss_append: true,
  628.                     // Advanced Options
  629.                     $resizing
  630.                     height : \"$html_height\",
  631.                     width : \"$html_width\",
  632.  
  633.                 });
  634.                 </script>";
  635.             break;
  636.  
  637.             case 2/* Extended mode*/
  638.                 $return $load .
  639.                 "\t<script type=\"text/javascript\">
  640.                 tinyMCE.init({
  641.                     // General
  642.                     directionality: \"$text_direction\",
  643.                     language : \"$langPrefix\",
  644.                     mode : \"specific_textareas\",
  645.                     $skin
  646.                     theme : \"$theme\",
  647.                     schema: \"html5\",
  648.                     selector: \"textarea.mce_editable\",
  649.                     // Cleanup/Output
  650.                     inline_styles : true,
  651.                     gecko_spellcheck : true,
  652.                     entity_encoding : \"$entity_encoding\",
  653.                     extended_valid_elements : \"$elements\",
  654.                     $forcenewline
  655.                     $smallButtons
  656.                     invalid_elements : \"$invalid_elements\",
  657.                     // Plugins
  658.                     plugins : \"$plugins\",
  659.                     // Toolbar
  660.                     toolbar1: \"$toolbar1\",
  661.                     toolbar2: \"$toolbar2\",
  662.                     toolbar3: \"$toolbar3\",
  663.                     toolbar4: \"$toolbar4\",
  664.                     removed_menuitems: \"newdocument\",
  665.                     // URL
  666.                     relative_urls : $relative_urls,
  667.                     remove_script_host : false,
  668.                     document_base_url : \"JUri::root("\",
  669.                     //Templates
  670.                     " $templates "
  671.                     // Layout
  672.                     $content_css
  673.                     importcss_append: true,
  674.                     // Advanced Options
  675.                     $resizing
  676.                     height : \"$html_height\",
  677.                     width : \"$html_width\",
  678.  
  679.                 });
  680.                 </script>";
  681.             break;
  682.         }
  683.  
  684.         return $return;
  685.     }
  686.  
  687.     /**
  688.      * TinyMCE WYSIWYG Editor - get the editor content
  689.      *
  690.      * @param   string  $editor  The name of the editor
  691.      *
  692.      * @return  string 
  693.      */
  694.     public function onGetContent($editor)
  695.     {
  696.         return 'tinyMCE.get(\'' $editor '\').getContent();';
  697.     }
  698.  
  699.     /**
  700.      * TinyMCE WYSIWYG Editor - set the editor content
  701.      *
  702.      * @param   string  $editor  The name of the editor
  703.      * @param   string  $html    The html to place in the editor
  704.      *
  705.      * @return  string 
  706.      */
  707.     public function onSetContent($editor$html)
  708.     {
  709.         return 'tinyMCE.get(\'' $editor '\').setContent(' $html ');';
  710.     }
  711.  
  712.     /**
  713.      * TinyMCE WYSIWYG Editor - copy editor content to form field
  714.      *
  715.      * @param   string  $editor  The name of the editor
  716.      *
  717.      * @return  string 
  718.      */
  719.     public function onSave($editor)
  720.     {
  721.         return 'if (tinyMCE.get("' $editor '").isHidden()) {tinyMCE.get("' $editor '").show()}; tinyMCE.get("' $editor '").save();';
  722.     }
  723.  
  724.     /**
  725.      * Inserts html code into the editor
  726.      *
  727.      * @param   string  $name  The name of the editor
  728.      *
  729.      * @return  boolean 
  730.      */
  731.     public function onGetInsertMethod($name)
  732.     {
  733.         $doc JFactory::getDocument();
  734.  
  735.         $js "
  736.             function isBrowserIE()
  737.             {
  738.                 return navigator.appName==\"Microsoft Internet Explorer\";
  739.             }
  740.  
  741.             function jInsertEditorText( text, editor )
  742.             {
  743.                 if (isBrowserIE())
  744.                 {
  745.                     if (window.parent.tinyMCE)
  746.                     {
  747.                         window.parent.tinyMCE.selectedInstance.selection.moveToBookmark(window.parent.global_ie_bookmark);
  748.                     }
  749.                 }
  750.                 tinyMCE.execCommand('mceInsertContent', false, text);
  751.             }
  752.  
  753.             var global_ie_bookmark = false;
  754.  
  755.             function IeCursorFix()
  756.             {
  757.                 if (isBrowserIE())
  758.                 {
  759.                     tinyMCE.execCommand('mceInsertContent', false, '');
  760.                     global_ie_bookmark = tinyMCE.activeEditor.selection.getBookmark(false);
  761.                 }
  762.                 return true;
  763.             }";
  764.  
  765.         $doc->addScriptDeclaration($js);
  766.  
  767.         return true;
  768.     }
  769.  
  770.     /**
  771.      * Display the editor area.
  772.      *
  773.      * @param   string   $name     The name of the editor area.
  774.      * @param   string   $content  The content of the field.
  775.      * @param   string   $width    The width of the editor area.
  776.      * @param   string   $height   The height of the editor area.
  777.      * @param   int      $col      The number of columns for the editor area.
  778.      * @param   int      $row      The number of rows for the editor area.
  779.      * @param   boolean  $buttons  True and the editor buttons will be displayed.
  780.      * @param   string   $id       An optional ID for the textarea. If not supplied the name is used.
  781.      * @param   string   $asset    The object asset
  782.      * @param   object   $author   The author.
  783.      *
  784.      * @return  string 
  785.      */
  786.     public function onDisplay($name$content$width$height$col$row$buttons true$id null$asset null$author null)
  787.     {
  788.         if (empty($id))
  789.         {
  790.             $id $name;
  791.         }
  792.  
  793.         // Only add "px" to width and height if they are not given as a percentage
  794.         if (is_numeric($width))
  795.         {
  796.             $width .= 'px';
  797.         }
  798.  
  799.         if (is_numeric($height))
  800.         {
  801.             $height .= 'px';
  802.         }
  803.  
  804.         // Data object for the layout
  805.         $textarea new stdClass;
  806.         $textarea->name    $name;
  807.         $textarea->id      $id;
  808.         $textarea->cols    $col;
  809.         $textarea->rows    $row;
  810.         $textarea->width   $width;
  811.         $textarea->height  $height;
  812.         $textarea->content $content;
  813.  
  814.         $editor JLayoutHelper::render('joomla.tinymce.textarea'$textarea);
  815.         $editor .= $this->_displayButtons($id$buttons$asset$author);
  816.         $editor .= $this->_toogleButton($id);
  817.  
  818.         return $editor;
  819.     }
  820.  
  821.     /**
  822.      * Displays the editor buttons.
  823.      *
  824.      * @param   string  $name     The editor name
  825.      * @param   mixed   $buttons  [array with button objects | boolean true to display buttons]
  826.      * @param   string  $asset    The object asset
  827.      * @param   object  $author   The author.
  828.      *
  829.      * @return  string HTML
  830.      */
  831.     private function _displayButtons($name$buttons$asset$author)
  832.     {
  833.         $return '';
  834.  
  835.         $args array(
  836.             'name'  => $name,
  837.             'event' => 'onGetInsertMethod'
  838.         );
  839.  
  840.         $results = (array) $this->update($args);
  841.  
  842.         if ($results)
  843.         {
  844.             foreach ($results as $result)
  845.             {
  846.                 if (is_string($result&& trim($result))
  847.                 {
  848.                     $return .= $result;
  849.                 }
  850.             }
  851.         }
  852.  
  853.         if (is_array($buttons|| (is_bool($buttons&& $buttons))
  854.         {
  855.             $buttons $this->_subject->getButtons($name$buttons$asset$author);
  856.  
  857.             $return .= JLayoutHelper::render('joomla.tinymce.buttons'$buttons);
  858.         }
  859.  
  860.         return $return;
  861.     }
  862.  
  863.     /**
  864.      * Get the toggle editor button
  865.      *
  866.      * @param   string  $name  Editor name
  867.      *
  868.      * @return  string 
  869.      */
  870.     private function _toogleButton($name)
  871.     {
  872.         return JLayoutHelper::render('joomla.tinymce.togglebutton'$name);
  873.     }
  874. }

Documentation generated on Tue, 19 Nov 2013 15:15:47 +0100 by phpDocumentor 1.4.3