Overview

Namespaces

  • Kotchasan
    • Cache
    • Database
    • Http
    • Log
    • Orm
  • None
  • PHP
  • Psr
    • Cache
    • Http
      • Message
    • Log

Classes

  • ArrayIterator
  • DateInterval
  • DOMNode
  • Kotchasan
  • Kotchasan\Accordion
  • Kotchasan\ApiController
  • Kotchasan\ArrayTool
  • Kotchasan\Cache\ApcCache
  • Kotchasan\Cache\Cache
  • Kotchasan\Cache\CacheItem
  • Kotchasan\Cache\FileCache
  • Kotchasan\CKEditor
  • Kotchasan\Collection
  • Kotchasan\Config
  • Kotchasan\Controller
  • Kotchasan\Country
  • Kotchasan\Csv
  • Kotchasan\Curl
  • Kotchasan\Currency
  • Kotchasan\Database
  • Kotchasan\Database\Db
  • Kotchasan\Database\DbCache
  • Kotchasan\Database\Driver
  • Kotchasan\Database\PdoMysqlDriver
  • Kotchasan\Database\Query
  • Kotchasan\Database\QueryBuilder
  • Kotchasan\Database\Schema
  • Kotchasan\Database\Sql
  • Kotchasan\DataTable
  • Kotchasan\Date
  • Kotchasan\DOMNode
  • Kotchasan\DOMParser
  • Kotchasan\Email
  • Kotchasan\File
  • Kotchasan\Files
  • Kotchasan\Form
  • Kotchasan\Grid
  • Kotchasan\Html
  • Kotchasan\Htmldoc
  • Kotchasan\HtmlTable
  • Kotchasan\Http\AbstractMessage
  • Kotchasan\Http\AbstractRequest
  • Kotchasan\Http\Message
  • Kotchasan\Http\NotFound
  • Kotchasan\Http\Request
  • Kotchasan\Http\Response
  • Kotchasan\Http\Stream
  • Kotchasan\Http\UploadedFile
  • Kotchasan\Http\Uri
  • Kotchasan\Image
  • Kotchasan\InputItem
  • Kotchasan\Inputs
  • Kotchasan\KBase
  • Kotchasan\Language
  • Kotchasan\ListItem
  • Kotchasan\Log\AbstractLogger
  • Kotchasan\Log\Logger
  • Kotchasan\Login
  • Kotchasan\Menu
  • Kotchasan\Mime
  • Kotchasan\Model
  • Kotchasan\Number
  • Kotchasan\ObjectTool
  • Kotchasan\Orm\Field
  • Kotchasan\Orm\Recordset
  • Kotchasan\Password
  • Kotchasan\Pdf
  • Kotchasan\Province
  • Kotchasan\Router
  • Kotchasan\Session
  • Kotchasan\Singleton
  • Kotchasan\Tab
  • Kotchasan\TableRow
  • Kotchasan\Template
  • Kotchasan\Text
  • Kotchasan\Validator
  • Kotchasan\View
  • PHPMailer
  • Psr\Log\AbstractLogger
  • Psr\Log\LogLevel
  • Psr\Log\NullLogger
  • SMTP

Interfaces

  • ArrayAccess
  • Countable
  • DateTimeInterface
  • Iterator
  • IteratorAggregate
  • Psr\Cache\CacheItemInterface
  • Psr\Cache\CacheItemPoolInterface
  • Psr\Http\Message\MessageInterface
  • Psr\Http\Message\RequestInterface
  • Psr\Http\Message\ResponseInterface
  • Psr\Http\Message\ServerRequestInterface
  • Psr\Http\Message\StreamInterface
  • Psr\Http\Message\UploadedFileInterface
  • Psr\Http\Message\UriInterface
  • Psr\Log\LoggerAwareInterface
  • Psr\Log\LoggerInterface
  • SeekableIterator
  • Serializable
  • Traversable

Traits

  • Psr\Log\LoggerTrait

Exceptions

  • Exception
  • InvalidArgumentException
  • Kotchasan\ApiException
  • Kotchasan\Cache\Exception
  • Kotchasan\Database\Exception
  • Kotchasan\InputItemException
  • LogicException
  • phpmailerException
  • RuntimeException

Functions

  • createClass
  • debug
  • getClassPath
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * @filesource Kotchasan/CKEditor.php
  4:  *
  5:  * @copyright 2016 Goragod.com
  6:  * @license http://www.kotchasan.com/license/
  7:  *
  8:  * @see http://www.kotchasan.com/
  9:  */
 10: 
 11: namespace Kotchasan;
 12: 
 13: /**
 14:  * CKEditor
 15:  *
 16:  * @author Goragod Wiriya <admin@goragod.com>
 17:  *
 18:  * @since 1.0
 19:  */
 20: class CKEditor extends Html
 21: {
 22:     /**
 23:      * ฟังก์ชั่นตรวจสอบความสามารถในการอัปโหลดของ CKEDITOR.
 24:      *
 25:      * @return bool
 26:      */
 27:     public static function enabledUpload()
 28:     {
 29:         if (Login::isAdmin()) {
 30:             return true;
 31:         } elseif ($login = Login::isMember()) {
 32:             return !empty($_SESSION['CKEDITOR']) && $_SESSION['CKEDITOR'] == $login['id'];
 33:         }
 34:         return false;
 35:     }
 36: 
 37:     /**
 38:      * สร้างโค้ด HTML สำหรับแสดง CKEditor
 39:      *
 40:      * @return string
 41:      */
 42:     public function render()
 43:     {
 44:         $content = array('item' => '', 'label' => '', 'tag' => '', 'itemClass' => '');
 45:         $prop = array();
 46:         $innerHTML = '';
 47:         if (isset($this->attributes['id']) && !isset($this->attributes['name'])) {
 48:             $this->attributes['name'] = $this->attributes['id'];
 49:         }
 50:         if (isset($this->attributes['name']) && !isset($this->attributes['id'])) {
 51:             $this->attributes['id'] = $this->attributes['name'];
 52:         }
 53:         foreach ($this->attributes as $key => $value) {
 54:             if ($key === 'itemClass') {
 55:                 $content['item'] = '<div class="'.$value.'">';
 56:                 $content['itemClass'] = '</div>';
 57:             } elseif ($key === 'id') {
 58:                 $for = ' for="'.$value.'"';
 59:                 $prop[] = ' id="'.$value.'"';
 60:             } elseif ($key === 'name') {
 61:                 $prop[] = ' name="'.$value.'"';
 62:             } elseif ($key === 'value') {
 63:                 $innerHTML = $this->tag == 'textarea' ? $this->toTextarea($value) : $this->toDiv($value);
 64:             } elseif ($key !== 'label' && $key !== 'upload') {
 65:                 $attributes[$key] = $value;
 66:             }
 67:         }
 68:         if (isset($this->attributes['label'])) {
 69:             $content['label'] = '<label'.$for.'>'.$this->attributes['label'].'</label>';
 70:         }
 71:         $content['tag'] = '<div><'.$this->tag.implode('', $prop).'>'.$innerHTML.'</'.$this->tag.'></div>';
 72:         $login = Login::isMember();
 73:         if ($login) {
 74:             $_SESSION['CKEDITOR'] = $login['id'];
 75:         }
 76:         if (isset($this->attributes['id'])) {
 77:             $script = array();
 78:             foreach ($attributes as $key => $value) {
 79:                 $script[] = $key.':'.(is_int($value) ? $value : '"'.$value.'"');
 80:             }
 81:             if (isset($this->attributes['upload']) && $this->attributes['upload'] == true) {
 82:                 if (is_dir(ROOT_PATH.'ckfinder')) {
 83:                     $script[] = 'filebrowserBrowseUrl:"'.WEB_URL.'ckfinder/ckfinder.html"';
 84:                     $script[] = 'filebrowserImageBrowseUrl:"'.WEB_URL.'ckfinder/ckfinder.html?Type=Images"';
 85:                     $script[] = 'filebrowserFlashBrowseUrl:"'.WEB_URL.'ckfinder/ckfinder.html?Type=Flash"';
 86:                     $script[] = 'filebrowserUploadUrl:"'.WEB_URL.'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files"';
 87:                     $script[] = 'filebrowserImageUploadUrl:"'.WEB_URL.'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images"';
 88:                     $script[] = 'filebrowserFlashUploadUrl:"'.WEB_URL.'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash"';
 89:                 } else {
 90:                     $connector = urlencode(WEB_URL.'ckeditor/filemanager/connectors/php/connector.php');
 91:                     $script[] = 'filebrowserBrowseUrl:"'.WEB_URL.'ckeditor/filemanager/browser/default/browser.html?Connector='.$connector.'"';
 92:                     $script[] = 'filebrowserImageBrowseUrl:"'.WEB_URL.'ckeditor/filemanager/browser/default/browser.html?Type=Image&Connector='.$connector.'"';
 93:                     $script[] = 'filebrowserFlashBrowseUrl:"'.WEB_URL.'ckeditor/filemanager/browser/default/browser.html?Type=Flash&Connector='.$connector.'"';
 94:                     $script[] = 'filebrowserUploadUrl:"'.WEB_URL.'ckeditor/filemanager/connectors/php/upload.php"';
 95:                     $script[] = 'filebrowserImageUploadUrl:"'.WEB_URL.'ckeditor/filemanager/connectors/php/upload.php?Type=Image"';
 96:                     $script[] = 'filebrowserFlashUploadUrl:"'.WEB_URL.'ckeditor/filemanager/connectors/php/upload.phpType=Flash"';
 97:                 }
 98:             }
 99:             self::$form->javascript[] = 'CKEDITOR.replace("'.$this->attributes['id']."\", {\n".implode(",\n", $script)."\n});";
100:         }
101:         return implode('', $content);
102:     }
103: 
104:     /**
105:      * แปลง {} เป็น HTML entities
106:      * ใช้ส่งให้กับ div
107:      *
108:      * @param string $str ข้อความ
109:      *
110:      * @return string
111:      */
112:     public function toDiv($str)
113:     {
114:         return preg_replace(array('/{/', '/}/'), array('&#x007B;', '&#x007D;'), $str);
115:     }
116: 
117:     /**
118:      * แปลง อักขระพิเศษ และ {} เป็น HTML entities
119:      * ใช้ส่งให้กับ textarea
120:      *
121:      * @param string $str ข้อความ
122:      *
123:      * @return string
124:      */
125:     public function toTextarea($str)
126:     {
127:         return preg_replace(array('/{/', '/}/'), array('&#x007B;', '&#x007D;'), htmlspecialchars($str));
128:     }
129: }
130: 
Kotchasan API documentation generated by ApiGen