Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file THtmlEditor.php

Documentation is available at THtmlEditor.php

  1. <?php
  2. namespace Adianti\Widget\Form;
  3.  
  4. use Adianti\Core\AdiantiApplicationConfig;
  5. use Adianti\Widget\Form\AdiantiWidgetInterface;
  6. use Adianti\Widget\Base\TElement;
  7. use Adianti\Widget\Base\TScript;
  8. use Adianti\Widget\Form\TField;
  9.  
  10. /**
  11.  * Html Editor
  12.  *
  13.  * @version    7.4
  14.  * @package    widget
  15.  * @subpackage form
  16.  * @author     Pablo Dall'Oglio
  17.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  18.  * @license    http://www.adianti.com.br/framework-license
  19.  */
  20. class THtmlEditor extends TField implements AdiantiWidgetInterface
  21. {
  22.     protected $id;
  23.     protected $size;
  24.     protected $formName;
  25.     protected $toolbar;
  26.     protected $completion;
  27.     protected $options;
  28.     private   $height;
  29.     
  30.     /**
  31.      * Class Constructor
  32.      * @param $name Widet's name
  33.      */
  34.     public function __construct($name)
  35.     {
  36.         parent::__construct($name);
  37.         $this->id = 'THtmlEditor_'.mt_rand(10000000001999999999);
  38.         $this->toolbar = true;
  39.         $this->options = [];
  40.         
  41.         // creates a tag
  42.         $this->tag = new TElement('textarea');
  43.         $this->tag->{'widget''thtmleditor';
  44.     }
  45.     
  46.     /**
  47.      * Define max length
  48.      * @param  $length Max length
  49.      */
  50.     public function setMaxLength($length)
  51.     {
  52.         if ($length 0)
  53.         {
  54.             $this->options['maxlength'$length;
  55.         }
  56.     }
  57.  
  58.     /**
  59.      * Set extra calendar options
  60.      * @link https://summernote.org/deep-dive/
  61.      */
  62.     public function setOption($option$value)
  63.     {
  64.         $this->options[$option$value;
  65.     }
  66.     
  67.     /**
  68.      * Define the widget's size
  69.      * @param  $width   Widget's width
  70.      * @param  $height  Widget's height
  71.      */
  72.     public function setSize($width$height NULL)
  73.     {
  74.         $this->size   $width;
  75.         if ($height)
  76.         {
  77.             $this->height $height;
  78.         }
  79.     }
  80.     
  81.     /**
  82.      * Returns the size
  83.      * @return array(width, height)
  84.      */
  85.     public function getSize()
  86.     {
  87.         return array$this->size$this->height );
  88.     }
  89.     
  90.     /**
  91.      * Disable toolbar
  92.      */
  93.     public function disableToolbar()
  94.     {
  95.         $this->toolbar false;
  96.     }
  97.     
  98.     /**
  99.      * Define options for completion
  100.      * @param $options array of options for completion
  101.      */
  102.     function setCompletion($options)
  103.     {
  104.         $this->completion $options;
  105.     }
  106.     
  107.     /**
  108.      * Enable the field
  109.      * @param $form_name Form name
  110.      * @param $field Field name
  111.      */
  112.     public static function enableField($form_name$field)
  113.     {
  114.         TScript::create" thtmleditor_enable_field('{$form_name}', '{$field}'); );
  115.     }
  116.     
  117.     /**
  118.      * Disable the field
  119.      * @param $form_name Form name
  120.      * @param $field Field name
  121.      */
  122.     public static function disableField($form_name$field)
  123.     {
  124.         TScript::create" thtmleditor_disable_field('{$form_name}', '{$field}'); );
  125.     }
  126.     
  127.     /**
  128.      * Clear the field
  129.      * @param $form_name Form name
  130.      * @param $field Field name
  131.      */
  132.     public static function clearField($form_name$field)
  133.     {
  134.         TScript::create" thtmleditor_clear_field('{$form_name}', '{$field}'); );
  135.     }
  136.     
  137.     /**
  138.      * Reload completion
  139.      * 
  140.      * @param $field Field name or id
  141.      * @param $options array of options for autocomplete
  142.      */
  143.     public static function reloadCompletion($field$options)
  144.     {
  145.         $options json_encode($options);
  146.         TScript::create(" thtml_editor_reload_completion( '{$field}', $options); ");
  147.     }
  148.     
  149.     /**
  150.      * Show the widget
  151.      */
  152.     public function show()
  153.     {
  154.         $this->tag->{'id'$this->id;
  155.         $this->tag->{'class'}  'thtmleditor';       // CSS
  156.         $this->tag->{'name'}   $this->name;   // tag name
  157.         
  158.         $ini AdiantiApplicationConfig::get();
  159.         $locale !empty($ini['general']['locale']$ini['general']['locale''pt-BR';
  160.         
  161.         // add the content to the textarea
  162.         $this->tag->add(htmlspecialchars(string) $this->value));
  163.         
  164.         // show the tag
  165.         $this->tag->show();
  166.         
  167.         $options $this->options;
  168.         if (!$this->toolbar)
  169.         {
  170.             $options'airMode'true;
  171.         }
  172.         if (!empty($this->completion))
  173.         {
  174.             $options'completion'$this->completion;
  175.         }
  176.         
  177.         $options_json json_encode$options );
  178.         TScript::create(" thtmleditor_start( '{$this->tag->{'id'}}', '{$this->size}', '{$this->height}', '{$locale}', '{$options_json}' ); ");
  179.         
  180.         // check if the field is not editable
  181.         if (!parent::getEditable())
  182.         {
  183.             TScript::create" thtmleditor_disable_field('{$this->formName}', '{$this->name}'); );
  184.         }
  185.     }
  186. }