/**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // ภาษาที่ต้องการ
         $language = self::$request->get('language', Language::name())->toString();
         if (preg_match('/^[a-z]{2,2}$/', $language)) {
             // maintenance detail
             $template = ROOT_PATH . DATA_FOLDER . 'maintenance.' . $language . '.php';
             if (is_file($template)) {
                 $template = trim(preg_replace('/<\\?php exit([\\(\\);])?\\?>/', '', file_get_contents($template)));
             } else {
                 $template = '<p style="padding: 20px; text-align: center; font-weight: bold;">Website Temporarily Closed for Maintenance, Please try again in a few minutes.<br>ปิดปรับปรุงเว็บไซต์ชั่วคราวเพื่อบำรุงรักษา กรุณาลองใหม่ในอีกสักครู่</p>';
             }
             // แสดงผล
             $section = Html::create('section');
             // breadcrumbs
             $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
             $ul = $breadcrumbs->add('ul');
             $ul->appendChild('<li><span class="icon-settings">{LNG_Site settings}</span></li>');
             $ul->appendChild('<li><span>{LNG_Maintenance Mode}</span></li>');
             $section->add('header', array('innerHTML' => '<h1 class="icon-write">' . $this->title() . '</h1>'));
             // แสดงฟอร์ม
             $section->appendChild(createClass('Index\\Maintenance\\View')->render($language, $template));
             return $section->render();
         }
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
示例#2
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // ภาษาที่ต้องการ
         $language = self::$request->get('language', Language::name())->toString();
         if (preg_match('/^[a-z]{2,2}$/', $language)) {
             // intro detail
             $template = ROOT_PATH . DATA_FOLDER . 'intro.' . $language . '.php';
             if (is_file($template)) {
                 $template = trim(preg_replace('/<\\?php exit([\\(\\);])?\\?>/', '', file_get_contents($template)));
             } else {
                 $template = '<p style="padding: 20px; text-align: center; font-weight: bold;"><a href="index.php">Welcome<br>ยินดีต้อนรับ</a></p>';
             }
             // แสดงผล
             $section = Html::create('section');
             // breadcrumbs
             $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
             $ul = $breadcrumbs->add('ul');
             $ul->appendChild('<li><span class="icon-settings">{LNG_Site settings}</span></li>');
             $ul->appendChild('<li><span>{LNG_Intro Page}</span></li>');
             $section->add('header', array('innerHTML' => '<h1 class="icon-write">' . $this->title() . '</h1>'));
             // แสดงฟอร์ม
             $section->appendChild(createClass('Index\\Intro\\View')->render($language, $template));
             return $section->render();
         }
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
 /**
  * แสดงผล
  */
 public function render($login)
 {
     // send email form
     $form = Html::create('form', array('id' => 'write_frm', 'class' => 'setup_frm', 'action' => 'index.php/index/model/sendmail/save', 'onsubmit' => 'doFormSubmit', 'token' => true, 'ajax' => true));
     $fieldset = $form->add('fieldset', array('title' => '{LNG_Details of} {LNG_Email}'));
     // reciever
     $reciever = self::$request->get('to')->topic();
     $fieldset->add('text', array('id' => 'reciever', 'itemClass' => 'item', 'labelClass' => 'g-input icon-email-sent', 'label' => '{LNG_Reciever}', 'comment' => '{LNG_Recipient&#39;s Email Address Many can be found Each separated by, (comma).}', 'autofocus', 'value' => $reciever));
     // email_from
     $datas = array($login['email'] => $login['email']);
     if (Login::isAdmin() && empty($login['fb'])) {
         $datas[self::$cfg->noreply_email] = self::$cfg->noreply_email;
         foreach (\Index\Sendmail\Model::findAdmin(self::$request) as $item) {
             $datas[$item] = $item;
         }
     }
     $fieldset->add('select', array('id' => 'from', 'itemClass' => 'item', 'labelClass' => 'g-input icon-email', 'label' => '{LNG_Sender}', 'options' => $datas));
     // subject
     $fieldset->add('text', array('id' => 'subject', 'itemClass' => 'item', 'labelClass' => 'g-input icon-edit', 'label' => '{LNG_Subject}', 'comment' => '' . '{LNG_Please fill in} {LNG_Subject}'));
     // detail
     $fieldset->add('ckeditor', array('id' => 'detail', 'itemClass' => 'item', 'height' => 300, 'language' => Language::name(), 'toolbar' => 'Email', 'label' => '{LNG_Detail}', 'value' => Template::load('', '', 'mailtemplate')));
     $fieldset = $form->add('fieldset', array('class' => 'submit'));
     // submit
     $fieldset->add('submit', array('class' => 'button ok large', 'value' => '{LNG_Send message}'));
     return $form->render();
 }
示例#4
0
 /**
  * อ่านข้อมูลโมดูลจากชื่อโมดูล
  *
  * @param string $module
  * @param type $owner
  * @return object|false คืนค่าข้อมูล object ไม่พบ คืนค่า false
  */
 public static function getModule($module, $owner)
 {
     if (is_string($module) && is_string($owner)) {
         $model = new \Kotchasan\Model();
         $select = array('I.id', 'I.module_id', 'M.module', 'M.owner', 'D.topic', 'D.description', 'D.keywords', 'D.detail', 'I.visited');
         $where = array(array('I.index', 1), array('M.module', $module), array('M.owner', $owner), array('I.published', 1), array('I.published_date', '<=', Date::mktimeToSqlDate(time())), array('D.language', array(Language::name(), '')));
         return $model->db()->createQuery()->from('index I')->join('modules M', 'INNER', array('M.id', 'I.module_id'))->join('index_detail D', 'INNER', array(array('D.id', 'I.id'), array('D.module_id', 'M.id'), array('D.language', 'I.language')))->where($where)->cacheOn()->first($select);
     }
     return false;
 }
示例#5
0
 /**
  * ตรวจสอบโมดูลที่เรียก
  *
  * @return array
  */
 public static function getModule($module, $date)
 {
     if (defined('MAIN_INIT')) {
         $model = new static();
         return $model->db()->createQuery()->from('index I')->join('modules M', 'INNER', array('M.id', 'I.module_id'))->join('index_detail D', 'INNER', array(array('D.id', 'I.id'), array('D.module_id', 'I.module_id'), array('D.language', array(Language::name(), ''))))->where(array(array('I.index', 1), array('M.module', $module), array('I.published', 1), array('I.published_date', '<=', $date)))->cacheOn()->first('M.id module_id', 'M.module', 'M.owner', 'D.topic', 'D.description', 'M.config');
     } else {
         // เรียก method โดยตรง
         new \Kotchasan\Http\NotFound('Do not call method directly');
     }
 }
 /**
  * ส่งออกเป็น HTML
  *
  * @param string|null $template HTML Template ถ้าไม่กำหนด (null) จะใช้ index.html
  */
 public function renderHTML($template = null)
 {
     // maintenance detail
     $template = ROOT_PATH . DATA_FOLDER . 'maintenance.' . Language::name() . '.php';
     if (is_file($template)) {
         $template = trim(preg_replace('/<\\?php exit([\\(\\);])?\\?>/', '', file_get_contents($template)));
     } else {
         $template = '<p style="padding: 20px; text-align: center; font-weight: bold;">Website Temporarily Closed for Maintenance, Please try again in a few minutes.<br>ปิดปรับปรุงเว็บไซต์ชั่วคราวเพื่อบำรุงรักษา กรุณาลองใหม่ในอีกสักครู่</p>';
     }
     parent::setContents(array('/{TITLE}/' => self::$cfg->web_title, '/{CONTENT}/' => $template));
     return parent::renderHTML(file_get_contents(ROOT_PATH . 'skin/empty.html'));
 }
示例#7
0
 /**
  * ส่งออกเป็น HTML
  *
  * @param string|null $template HTML Template ถ้าไม่กำหนด (null) จะใช้ index.html
  */
 public function renderHTML($template = null)
 {
     // intro detail
     $template = ROOT_PATH . DATA_FOLDER . 'intro.' . Language::name() . '.php';
     if (is_file($template)) {
         $template = trim(preg_replace('/<\\?php exit([\\(\\);])?\\?>/', '', file_get_contents($template)));
     } else {
         $template = '<p style="padding: 20px; text-align: center; font-weight: bold;"><a href="index.php">Welcome<br>ยินดีต้อนรับ</a></p>';
     }
     parent::setContents(array('/{TITLE}/' => self::$cfg->web_title, '/{CONTENT}/' => $template));
     return parent::renderHTML(file_get_contents(ROOT_PATH . 'skin/empty.html'));
 }
 /**
  * อ่านอีเมล์ที่แก้ไข
  * id = 0 สร้างอีเมล์ใหม่
  *
  * @param int $id
  * @return object|bool คืนค่าข้อมูล object ไม่พบคืนค่า false
  */
 public static function getIndex($id)
 {
     if (is_int($id)) {
         if (empty($id)) {
             $index = (object) array('id' => 0, 'from_email' => '', 'copy_to' => '', 'subject' => '', 'language' => Language::name(), 'detail' => Template::load('', '', 'mailtemplate'), 'name' => '');
         } else {
             $model = new static();
             $index = $model->db()->first($model->getFullTableName('emailtemplate'), array('id', $id));
         }
         return $index;
     }
     return false;
 }
 /**
  * ค้นหาข้อมูลทั้งหมด
  *
  * @param Request $request
  * @param object $index
  * @return object
  */
 public static function findAll(Request $request, $index)
 {
     // model
     $model = new static();
     $db = $model->db();
     // ข้อความค้นหา
     $index->q = $request->globals(array('POST', 'GET'), 'q')->topic();
     $index->words = array();
     $where1 = array();
     $where2 = array();
     // แยกข้อความค้นหาออกเป็นคำๆ ค้นหาข้อความที่มีความยาวมากกว่า 1 ตัวอักษร
     foreach (explode(' ', $index->q) as $item) {
         if (mb_strlen($item) > 1) {
             $index->words[] = $item;
             $where1[] = array('D.topic', 'LIKE', '%' . $item . '%');
             $where1[] = array('D.detail', 'LIKE', '%' . $item . '%');
             $where2[] = array('C.detail', 'LIKE', '%' . $item . '%');
         }
     }
     $index->sqls = array();
     $select = array('I.id', 'I.alias', 'M.module', 'M.owner', 'D.topic', 'D.description', 'I.visited', 'I.index');
     $q1 = $db->createQuery()->select($select)->from('modules M')->join('index I', 'INNER', array(array('I.module_id', 'M.id'), array('I.published', 1), array('I.published_date', '<=', date('Y-m-d')), array('I.language', array(Language::name(), ''))))->join('index_detail D', 'INNER', array(array('D.id', 'I.id'), array('D.module_id', 'M.id')))->where($where1, 'OR');
     $q2 = $db->createQuery()->select($select)->from('comment C')->join('modules M', 'INNER', array('M.id', 'C.module_id'))->join('index I', 'INNER', array(array('I.module_id', 'M.id'), array('I.published', 1), array('I.published_date', '<=', date('Y-m-d')), array('I.language', array(Language::name(), ''))))->join('index_detail D', 'INNER', array(array('D.id', 'I.id'), array('D.module_id', 'M.id')))->where($where2, 'OR');
     // union all queries
     $q3 = $db->createQuery()->union(array($q1, $q2));
     // groub by id
     $index->sqls[] = $db->createQuery()->select()->from(array($q3, 'Q'))->groupBy('Q.id');
     // ค้นหาจากโมดูลอื่นๆที่ติดตั้ง
     foreach (Gcms::$install_owners as $item => $modules) {
         if ($item != 'index' && is_file(ROOT_PATH . "modules/{$item}/models/search.php")) {
             include ROOT_PATH . "modules/{$item}/models/search.php";
             //createClass(ucfirst($item).'\Search\Model')->findAll($request, $index);
         }
     }
     // union all queries
     $query = $db->createQuery()->from(array($db->createQuery()->union($index->sqls), 'Z'));
     // จำนวน
     $index->total = $query->cacheOn()->count();
     // ข้อมูลแบ่งหน้า
     if (empty($index->list_per_page)) {
         $index->list_per_page = 20;
     }
     $index->page = $request->request('page')->toInt();
     $index->totalpage = ceil($index->total / $index->list_per_page);
     $index->page = max(1, $index->page > $index->totalpage ? $index->totalpage : $index->page);
     $index->start = $index->list_per_page * ($index->page - 1);
     $index->end = $index->start + $index->list_per_page > $index->total ? $index->total : $index->start + $index->list_per_page;
     // query
     $index->items = $query->select()->order('visited')->limit($index->list_per_page, $index->start)->cacheOn()->execute();
     return $index;
 }
示例#10
0
 /**
  * list รายชื่อจังหวัดทั้งหมด  ตามภาษา (ถ้าไม่มีใช้ภาษาอังกฤษ)
  * สามารถนำไปใช้โดย Form ได้ทันที
  *
  * @return array
  */
 public static function all()
 {
     $datas = self::init();
     $language = Language::name();
     $language = in_array($language, array_keys(reset($datas))) ? $language : 'en';
     $result = array();
     foreach ($datas as $iso => $values) {
         $result[$iso] = $values[$language];
     }
     if ($language == 'en') {
         asort($result);
     }
     return $result;
 }
 /**
  * อ่านเมนูตาม id
  * 0 หมายถึง สร้างเมนูใหม่
  *
  * @return array|boolean คืนค่าแอเรย์ของข้อมูล ไม่พบคืนค่า false
  */
 public static function getMenu($id)
 {
     if (is_int($id)) {
         if (empty($id)) {
             // ใหม่
             $index = (object) array('id' => 0, 'index_id' => 0, 'parent' => self::$request->get('_parent', 'MAINMENU')->toString(), 'level' => 0, 'language' => Language::name(), 'menu_text' => '', 'menu_tooltip' => '', 'accesskey' => '', 'menu_order' => 0, 'menu_url' => '', 'menu_target' => '', 'alias' => '', 'owner' => '', 'published' => 1);
         } else {
             // อ่านข้อมูลจาก db
             $model = new static();
             $query = $model->db()->createQuery()->select('I.module_id')->from('index I')->where(array('I.id', 'U.index_id'));
             $query = $model->db()->createQuery()->select('M.owner')->from('modules M')->where(array('M.id', $query));
             $index = $model->db()->createQuery()->from('menus U')->where($id)->first('U.*', array($query, 'owner'));
         }
         return $index;
     }
     return false;
 }
 /**
  * module=maintenance
  *
  * @param string $language
  * @param string $template
  * @return string
  */
 public function render($language, $template)
 {
     // form
     $form = Html::create('form', array('id' => 'setup_frm', 'class' => 'setup_frm', 'autocomplete' => 'off', 'action' => 'index.php/index/model/maintenance/save', 'onsubmit' => 'doFormSubmit', 'ajax' => true));
     $fieldset = $form->add('fieldset', array('title' => '{LNG_The page will appear on your site is in maintenance mode}'));
     // maintenance_mode
     $fieldset->add('select', array('id' => 'maintenance_mode', 'labelClass' => 'g-input icon-config', 'itemClass' => 'item', 'label' => '{LNG_Settings}', 'options' => Language::get('BOOLEANS'), 'value' => isset(self::$cfg->maintenance_mode) ? self::$cfg->maintenance_mode : 0));
     $div = $fieldset->add('groups-table', array('label' => '{LNG_Language}'));
     // language
     $div->add('select', array('id' => 'language', 'labelClass' => 'g-input icon-language', 'itemClass' => 'width', 'options' => Language::installedLanguage(), 'value' => $language));
     $div->add('button', array('id' => 'btn_go', 'itemClass' => 'width', 'class' => 'button go', 'value' => '{LNG_Go}'));
     // detail
     $fieldset->add('ckeditor', array('id' => 'detail', 'itemClass' => 'item', 'height' => 300, 'language' => Language::name(), 'toolbar' => 'Document', 'label' => '{LNG_Detail}', 'value' => $template, 'upload' => true));
     $fieldset = $form->add('fieldset', array('class' => 'submit'));
     // submit
     $fieldset->add('submit', array('class' => 'button ok large', 'value' => '{LNG_Save}'));
     $form->script('doChangeLanguage("btn_go", "index.php?module=maintenance");');
     return $form->render();
 }
 /**
  * module=mailwrite
  *
  * @param object $index
  * @return string
  */
 public function render($index)
 {
     // form
     $form = Html::create('form', array('id' => 'setup_frm', 'class' => 'setup_frm', 'autocomplete' => 'off', 'action' => 'index.php/index/model/mailwrite/save', 'onsubmit' => 'doFormSubmit', 'ajax' => true));
     $fieldset = $form->add('fieldset', array('title' => '{LNG_Details of} {LNG_Email}'));
     // from_email
     $fieldset->add('text', array('id' => 'from_email', 'labelClass' => 'g-input icon-email', 'itemClass' => 'item', 'label' => '{LNG_Sender}', 'comment' => '{LNG_E-mail address for replies. If you do not want a response, please leave blank.}', 'maxlength' => 255, 'value' => $index->from_email));
     // copy_to
     $fieldset->add('text', array('id' => 'copy_to', 'labelClass' => 'g-input icon-cc', 'itemClass' => 'item', 'label' => '{LNG_Copy to}', 'comment' => '{LNG_More email addresses to send a copy of the email. Separate each item with comma (,)}', 'value' => $index->copy_to));
     // subject
     $fieldset->add('text', array('id' => 'subject', 'labelClass' => 'g-input icon-edit', 'itemClass' => 'item', 'label' => '{LNG_Subject}', 'title' => '{LNG_Please fill in} {LNG_Subject}', 'maxlength' => 64, 'value' => $index->subject));
     // language
     $fieldset->add('select', array('id' => 'language', 'labelClass' => 'g-input icon-language', 'itemClass' => 'item', 'label' => '{LNG_Language}', 'comment' => '{LNG_The system will e-mail the selected language. If you do not use the default language.}', 'options' => Language::installedLanguage(), 'value' => $index->language));
     // detail
     $fieldset->add('ckeditor', array('id' => 'detail', 'itemClass' => 'item', 'height' => 300, 'language' => Language::name(), 'toolbar' => 'Document', 'upload' => true, 'label' => '{LNG_Detail}', 'value' => $index->detail));
     $fieldset = $form->add('fieldset', array('class' => 'submit'));
     // submit
     $fieldset->add('submit', array('class' => 'button ok large', 'value' => '{LNG_Save}'));
     // id
     $fieldset->add('hidden', array('id' => 'id', 'value' => $index->id));
     return $form->render();
 }
示例#14
0
 /**
  * ฟังก์ชั่นส่งเมล์จากแม่แบบจดหมาย
  *
  * @param int $id ID ของจดหมายที่ต้องการส่ง
  * @param string $module ชื่อโมดูลของจดหมายที่ต้องการส่ง
  * @param array $datas ข้อมูลที่จะถูกแทนที่ลงในจดหมาย ในรูป 'ตัวแปร'=>'ข้อความ'
  * @param string $to ที่อยู่อีเมล์ผู้รับ  คั่นแต่ละรายชื่อด้วย ,
  * @return string สำเร็จคืนค่าว่าง ไม่สำเร็จ คืนค่าข้อความผิดพลาด
  */
 public static function send($id, $module, $datas, $to)
 {
     $model = new static();
     $email = $model->db()->createQuery()->from('emailtemplate')->where(array(array('module', $module), array('email_id', (int) $id), array('language', array(Language::name(), ''))))->cacheOn()->toArray()->first('from_email', 'copy_to', 'subject', 'detail');
     if ($email === false) {
         return Language::get('email template not found');
     } else {
         // ผู้ส่ง
         $from = empty($email['from_email']) ? self::$cfg->noreply_email : $email['from_email'];
         // ข้อความในอีเมล์
         $replace = ArrayTool::replace(array('/%WEBTITLE%/' => strip_tags(self::$cfg->web_title), '/%WEBURL%/' => WEB_URL, '/%ADMINEMAIL%/' => $from, '/%TIME%/' => Date::format()), $datas);
         ArrayTool::extract($replace, $keys, $values);
         $msg = preg_replace($keys, $values, $email['detail']);
         $subject = preg_replace($keys, $values, $email['subject']);
         $to = explode(',', $to);
         if (!empty($email['copy_to'])) {
             $to[] = $email['copy_to'];
         }
         // ส่งอีเมล์
         return parent::send(implode(',', $to), $from, $subject, $msg);
     }
 }
 /**
  * module=pagewrite
  *
  * @param string $id
  * @return string
  */
 public function render($index)
 {
     // form
     $form = Html::create('form', array('id' => 'setup_frm', 'class' => 'setup_frm', 'autocomplete' => 'off', 'action' => 'index.php/index/model/pagewrite/save', 'onsubmit' => 'doFormSubmit', 'ajax' => true, 'upload' => true));
     $fieldset = $form->add('fieldset', array('title' => '{LNG_Details of} ' . Language::get($index->owner === 'index' ? 'Page' : 'Module')));
     $groups = $fieldset->add('groups-table', array('label' => '{LNG_Language}', 'id' => 'language', 'comment' => '{LNG_Select the language of this item (Select the first Is present in every language)}'));
     // language
     $groups->add('select', array('id' => 'language', 'labelClass' => 'g-input icon-language', 'itemClass' => 'width', 'options' => ArrayTool::replace(array('' => '{LNG_all languages}'), Language::installedLanguage()), 'value' => $index->language));
     $groups->add('a', array('id' => 'btn_copy', 'class' => 'button icon-copy copy', 'title' => '{LNG_Copy this item to the selected language}'));
     // module
     $fieldset->add('text', array('id' => 'module', 'labelClass' => 'g-input icon-modules', 'itemClass' => 'item', 'label' => '{LNG_Module}', 'comment' => '{LNG_Name of this module. English lowercase and number only, short. (Can not use a reserve or a duplicate)}', 'maxlength' => 64, 'value' => $index->module));
     // topic
     $fieldset->add('text', array('id' => 'topic', 'labelClass' => 'g-input icon-edit', 'itemClass' => 'item', 'label' => '{LNG_Topic}', 'comment' => '{LNG_Text displayed on the Title Bar of the browser (3 - 255 characters)}', 'maxlength' => 255, 'value' => $index->topic));
     // keywords
     $fieldset->add('textarea', array('id' => 'keywords', 'labelClass' => 'g-input icon-tags', 'itemClass' => 'item', 'label' => '{LNG_Keywords}', 'comment' => '{LNG_Text keywords for SEO or Search Engine to search}', 'value' => $index->keywords));
     // description
     $fieldset->add('textarea', array('id' => 'description', 'labelClass' => 'g-input icon-file', 'itemClass' => 'item', 'label' => '{LNG_Description}', 'comment' => '{LNG_Text short summary of your story. Which can be used to show in your theme. (If not the program will fill in the contents of the first paragraph)}', 'value' => $index->description));
     // detail
     $fieldset->add('ckeditor', array('id' => 'detail', 'itemClass' => 'item', 'height' => 300, 'language' => Language::name(), 'toolbar' => 'Document', 'upload' => true, 'label' => '{LNG_Detail}', 'value' => $index->detail));
     // published_date
     $fieldset->add('date', array('id' => 'published_date', 'labelClass' => 'g-input icon-calendar', 'itemClass' => 'item', 'label' => '{LNG_Published date}', 'comment' => '{LNG_The date of publication of this information. The publisher will start automatically when you log on due date}', 'value' => $index->published_date));
     // published
     $fieldset->add('select', array('id' => 'published', 'labelClass' => 'g-input icon-published1', 'itemClass' => 'item', 'label' => '{LNG_Published}', 'comment' => '{LNG_Publish this item}', 'options' => Language::get('PUBLISHEDS'), 'value' => $index->published));
     $fieldset = $form->add('fieldset', array('class' => 'submit'));
     // submit
     $fieldset->add('submit', array('class' => 'button ok large', 'value' => '{LNG_Save}'));
     // preview button
     if ($index->owner == 'index') {
         $fieldset->add('button', array('id' => 'btn_preview', 'class' => 'button preview large', 'value' => '{LNG_Preview}'));
     }
     // owner
     $fieldset->add('hidden', array('id' => 'owner', 'value' => $index->owner));
     // id
     $fieldset->add('hidden', array('id' => 'id', 'value' => $index->id));
     $form->script('initIndexWrite();');
     return $form->render();
 }
示例#16
0
 /**
  * โหลดเมนูทั้งหมดเรียงตามลำดับเมนู (รายการแรกคือหน้า Home)
  *
  * @return array
  */
 public static function create()
 {
     if (defined('MAIN_INIT')) {
         $model = new static();
         // โหลดเมนูทั้งหมดเรียงตามลำดับเมนู (รายการแรกคือหน้า Home)
         $lng = array(Language::name(), '');
         $select = array('M.id module_id', 'M.module', 'M.owner', 'M.config', 'U.index_id', 'U.parent', 'U.level', 'U.menu_text', 'U.menu_tooltip', 'U.accesskey', 'U.menu_url', 'U.menu_target', 'U.alias', 'U.published', "(CASE U.`parent` WHEN 'MAINMENU' THEN 0 WHEN 'BOTTOMMENU' THEN 1 WHEN 'SIDEMENU' THEN 2 ELSE 3 END ) AS `pos`");
         $query = $model->db()->createQuery()->select($select)->from('menus U')->join('index I', 'LEFT', array(array('I.id', 'U.index_id'), array('I.index', '1'), array('I.language', $lng)))->join('modules M', 'LEFT', array('M.id', 'I.module_id'))->where(array(array('U.language', $lng), array('U.parent', '!=', '')))->order(array('pos', 'U.parent', 'U.menu_order'));
         // จัดลำดับเมนูตามระดับของเมนู
         $datas = array();
         $model->datas = $query->cacheOn()->execute();
         foreach ($model->datas as $i => $item) {
             if (!empty($item->config)) {
                 $config = @unserialize($item->config);
                 if (is_array($config)) {
                     foreach ($config as $key => $value) {
                         $item->{$key} = $value;
                     }
                 }
             }
             unset($item->config);
             $level = $item->level;
             if ($level == 0) {
                 $datas[$item->parent]['toplevel'][$i] = $item;
             } else {
                 $datas[$item->parent][$toplevel[$level - 1]][$i] = $item;
             }
             $toplevel[$level] = $i;
         }
         $model->menus_by_pos = (object) $datas;
         return $model;
     } else {
         // เรียก method โดยตรง
         new \Kotchasan\Http\NotFound('Do not call method directly');
     }
 }
示例#17
0
 /**
  * ฟังก์ชั่น อ่านหมวดหมู่ในรูป serialize ตามภาษาที่เลือก
  *
  * @param mixed $datas ข้อความ serialize
  * @param string $key (optional) ถ้า $datas เป็น array ต้องระบุ $key ด้วย
  * @return string คืนค่าข้อความ
  */
 public static function ser2Str($datas, $key = '')
 {
     if (is_array($datas)) {
         $datas = isset($datas[$key]) ? $datas[$key] : '';
     }
     if (!empty($datas)) {
         $datas = @unserialize($datas);
         if ($datas !== false) {
             $lng = Language::name();
             $datas = isset($datas[$lng]) ? $datas[$lng] : (isset($datas['']) ? $datas[''] : '');
         }
     }
     return $datas;
 }
示例#18
0
 /**
  * อ่านรายละเอียดของโมดูล
  * topic, details, keywords, description
  *
  * @param Object $index
  * @return Object
  */
 public static function getDetails($index)
 {
     // Model
     $model = new static();
     $search = $model->db()->createQuery()->from('index_detail D')->join('index I', 'INNER', array(array('I.index', 1), array('I.id', 'D.id'), array('I.module_id', 'D.module_id'), array('I.language', 'D.language')))->where(array(array('I.module_id', (int) $index->module_id), array('D.language', array(\Kotchasan\Language::name(), ''))))->cacheOn()->toArray()->first('D.topic', 'D.detail', 'D.keywords', 'D.description');
     if ($search) {
         foreach ($search as $key => $value) {
             $index->{$key} = $value;
         }
     }
     return $index;
 }
示例#19
0
 /**
  * Generated from @assert () [==] 'th'.
  *
  * @covers Kotchasan\Language::name
  */
 public function testName()
 {
     $this->assertEquals('th', \Kotchasan\Language::name());
 }
示例#20
0
 /**
  * สร้างไฟล์ js
  */
 public function index()
 {
     // default js
     $js = array();
     $js[] = 'var WEB_URL = "' . WEB_URL . '";';
     $js[] = 'var MODULE_URL = ' . (int) self::$cfg->module_url . ';';
     $js[] = file_get_contents(ROOT_PATH . 'js/gajax.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/loader.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/ddmenu.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/table.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/common.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/tooltip.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/media.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/gcms.js');
     $lng = Language::name();
     $data_folder = Language::languageFolder();
     if (is_file($data_folder . $lng . '.js')) {
         $js[] = file_get_contents($data_folder . $lng . '.js');
     }
     // js ของโมดูล
     $dir = ROOT_PATH . 'modules/';
     $f = @opendir($dir);
     if ($f) {
         while (false !== ($text = readdir($f))) {
             if ($text != "." && $text != "..") {
                 if (is_dir($dir . $text)) {
                     if (is_file($dir . $text . '/script.js')) {
                         $js[] = file_get_contents($dir . $text . '/script.js');
                     }
                 }
             }
         }
         closedir($f);
     }
     // js ของ Widgets
     $dir = ROOT_PATH . 'Widgets/';
     $f = @opendir($dir);
     if ($f) {
         while (false !== ($text = readdir($f))) {
             if ($text != "." && $text != "..") {
                 if (is_dir($dir . $text)) {
                     if (is_file($dir . $text . '/script.js')) {
                         $js[] = file_get_contents($dir . $text . '/script.js');
                     }
                 }
             }
         }
         closedir($f);
     }
     $languages = Language::getItems(array('MONTH_SHORT', 'MONTH_LONG', 'DATE_LONG', 'DATE_SHORT', 'YEAR_OFFSET'));
     $js[] = 'Date.monthNames = ["' . implode('", "', $languages['MONTH_SHORT']) . '"];';
     $js[] = 'Date.longMonthNames = ["' . implode('", "', $languages['MONTH_LONG']) . '"];';
     $js[] = 'Date.longDayNames = ["' . implode('", "', $languages['DATE_LONG']) . '"];';
     $js[] = 'Date.dayNames = ["' . implode('", "', $languages['DATE_SHORT']) . '"];';
     $js[] = 'Date.yearOffset = ' . (int) $languages['YEAR_OFFSET'] . ';';
     if (self::$cfg->use_ajax == 1) {
         $js[] = 'var use_ajax = 1;';
     }
     $js[] = 'var COUNTER_REFRESH_TIME = ' . (int) self::$cfg->counter_refresh_time . ';';
     if (!empty(self::$cfg->facebook_appId)) {
         $js[] = 'initFacebook("' . self::$cfg->facebook_appId . '", "' . Language::name() . '");';
     }
     // compress javascript
     $patt = array('#/\\*(?:[^*]*(?:\\*(?!/))*)*\\*/#u', '#[\\r\\t]#', '#\\n//.*\\n#', '#;//.*\\n#', '#[\\n]#', '#[\\s]{2,}#');
     $replace = array('', '', '', ";\n", '', ' ');
     // Response
     $response = new \Kotchasan\Http\Response();
     // cache 1 month
     $expire = 2592000;
     $response->withHeaders(array('Content-type' => 'application/javascript; charset=utf-8', 'Cache-Control' => 'max-age=' . $expire . ', must-revalidate, public', 'Expires' => gmdate('D, d M Y H:i:s', time() + $expire) . ' GMT', 'Last-Modified' => gmdate('D, d M Y H:i:s', time() - $expire) . ' GMT'))->withContent(preg_replace($patt, $replace, implode("\n", $js)))->send();
 }
 public function popularpage()
 {
     return $this->db()->createQuery()->select('D.topic', 'I.visited_today')->from('index I')->join('modules M', 'INNER', array(array('M.id', 'I.module_id'), array('M.owner', 'document')))->join('index_detail D', 'INNER', array(array('D.id', 'I.id'), array('D.module_id', 'I.module_id'), array('D.language', array(Language::name(), ''))))->order('I.visited_today DESC', 'I.visited DESC')->limit(12)->toArray()->execute();
 }
示例#22
0
 /**
  * ส่งออกเป็น HTML
  *
  * @param string|null $template HTML Template ถ้าไม่กำหนด (null) จะใช้ index.html
  */
 public function renderHTML($template = null)
 {
     // default for template
     if (!empty($this->metas)) {
         $this->contents['/(<head.*)(<\\/head>)/isu'] = '$1' . implode("\n", $this->metas) . "\n" . '$2';
     }
     $this->contents['/{LNG_([^}]+)}/e'] = '\\Kotchasan\\Language::get(array(1=>"$1"))';
     $this->contents['/{WEBTITLE}/'] = self::$cfg->web_title;
     $this->contents['/{WEBDESCRIPTION}/'] = self::$cfg->web_description;
     $this->contents['/{WEBURL}/'] = WEB_URL;
     $this->contents['/{SKIN}/'] = Template::$src;
     $this->contents['/{LANGUAGE}/'] = \Kotchasan\Language::name();
     $this->contents['/^[\\s\\t]+/m'] = '';
     foreach ($this->after_contents as $key => $value) {
         $this->contents[$key] = $value;
     }
     // แทนที่ลงใน Template
     if ($template === null) {
         // ถ้าไม่ได้กำหนดมาใช้ index.html
         $template = Template::load('', '', 'index');
     }
     return Template::pregReplace(array_keys($this->contents), array_values($this->contents), $template);
 }
示例#23
0
 /**
  * สร้างไฟล์ js
  */
 public function index()
 {
     // default js
     $js = array();
     $js[] = file_get_contents(ROOT_PATH . 'js/gajax.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/ddpanel.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/ddmenu.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/graphs.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/clock.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/editinplace.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/table.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/sorttable.js');
     $js[] = file_get_contents(ROOT_PATH . 'js/common.js');
     $js[] = file_get_contents(APP_PATH . 'modules/js/views/admin.js');
     $lng = Language::name();
     $data_folder = Language::languageFolder();
     if (is_file($data_folder . $lng . '.js')) {
         $js[] = file_get_contents($data_folder . $lng . '.js');
     }
     // js ของโมดูล
     $dir = ROOT_PATH . 'modules/';
     $f = @opendir($dir);
     if ($f) {
         while (false !== ($text = readdir($f))) {
             if ($text != "." && $text != "..") {
                 if (is_dir($dir . $text)) {
                     if (is_file($dir . $text . '/admin.js')) {
                         $js[] = file_get_contents($dir . $text . '/admin.js');
                     }
                 }
             }
         }
         closedir($f);
     }
     // js ของ Widgets
     $dir = ROOT_PATH . 'Widgets/';
     $f = @opendir($dir);
     if ($f) {
         while (false !== ($text = readdir($f))) {
             if ($text != "." && $text != "..") {
                 if (is_dir($dir . $text)) {
                     if (is_file($dir . $text . '/admin.js')) {
                         $js[] = file_get_contents($dir . $text . '/admin.js');
                     }
                 }
             }
         }
         closedir($f);
     }
     $languages = Language::getItems(array('MONTH_SHORT', 'MONTH_LONG', 'DATE_LONG', 'DATE_SHORT', 'YEAR_OFFSET'));
     $js[] = 'var WEB_URL = "' . WEB_URL . '";';
     $js[] = 'Date.monthNames = ["' . implode('", "', $languages['MONTH_SHORT']) . '"];';
     $js[] = 'Date.longMonthNames = ["' . implode('", "', $languages['MONTH_LONG']) . '"];';
     $js[] = 'Date.longDayNames = ["' . implode('", "', $languages['DATE_LONG']) . '"];';
     $js[] = 'Date.dayNames = ["' . implode('", "', $languages['DATE_SHORT']) . '"];';
     $js[] = 'Date.yearOffset = ' . (int) $languages['YEAR_OFFSET'] . ';';
     // compress javascript
     $patt = array('#/\\*(?:[^*]*(?:\\*(?!/))*)*\\*/#u', '#[\\r\\t]#', '#\\n//.*\\n#', '#;//.*\\n#', '#[\\n]#', '#[\\s]{2,}#');
     $replace = array('', '', '', ";\n", '', ' ');
     // Response
     $response = new \Kotchasan\Http\Response();
     // cache 1 month
     $expire = 2592000;
     $response->withHeaders(array('Content-type' => 'application/javascript; charset=utf-8', 'Cache-Control' => 'max-age=' . $expire . ', must-revalidate, public', 'Expires' => gmdate('D, d M Y H:i:s', time() + $expire) . ' GMT', 'Last-Modified' => gmdate('D, d M Y H:i:s', time() - $expire) . ' GMT'))->withContent(preg_replace($patt, $replace, implode("\n", $js)))->send();
 }