/**
  * สร้างไฟล์ CSS
  */
 public function index()
 {
     // โหลด css หลัก
     $data = preg_replace('/url\\(([\'"])?fonts\\//isu', "url(\\1" . WEB_URL . 'skin/fonts/', file_get_contents(ROOT_PATH . 'skin/fonts.css'));
     $data .= file_get_contents(ROOT_PATH . 'skin/gcss.css');
     $data .= file_get_contents(ROOT_PATH . 'skin/gcms.css');
     // css ของ template
     $data2 = file_get_contents(TEMPLATE_ROOT . 'skin/' . self::$cfg->skin . '/style.css');
     $data2 = preg_replace('/url\\(([\'"])?(img|fonts)\\//isu', "url(\\1" . WEB_URL . 'skin/\\2/', $data2);
     // โหลด css ของ module
     $dir = ROOT_PATH . 'modules/';
     $f = opendir($dir);
     while (false !== ($text = readdir($f))) {
         if ($text != "." && $text != "..") {
             if (is_dir($dir . $text)) {
                 if (is_file($dir . $text . '/admin.css')) {
                     $data2 .= preg_replace('/url\\(img\\//isu', 'url(' . WEB_URL . 'modules/' . $text . '/img/', file_get_contents($dir . $text . '/admin.css'));
                 }
             }
         }
     }
     closedir($f);
     // โหลด css ของ Widgets
     $dir = ROOT_PATH . 'Widgets/';
     $f = opendir($dir);
     while (false !== ($text = readdir($f))) {
         if ($text != "." && $text != "..") {
             if (is_dir($dir . $text)) {
                 if (is_file($dir . $text . '/admin.css')) {
                     $data2 .= preg_replace('/url\\(img\\//isu', 'url(' . WEB_URL . 'Widgets/' . $text . '/img/', file_get_contents($dir . $text . '/admin.css'));
                 }
             }
         }
     }
     closedir($f);
     foreach (self::$cfg->color_status as $key => $value) {
         $data2 .= '.status' . $key . '{color:' . $value . '}';
     }
     // compress css
     $data = preg_replace(array('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '/[\\s]{0,}([:;,>\\{\\}])[\\s]{0,}/'), array('', '\\1'), $data . $data2);
     // Response
     $response = new \Kotchasan\Http\Response();
     // cache 1 month
     $expire = 2592000;
     $response->withHeaders(array('Content-type' => 'text/css; 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(array('/[\\r\\n\\t]/s', '/[\\s]{2,}/s', '/;}/'), array('', ' ', '}'), $data))->send();
 }
<?php

/*
 * BingSiteAuth.php
 *
 * @author Goragod Wiriya <*****@*****.**>
 * @link http://www.kotchasan.com/
 * @copyright 2016 Goragod.com
 * @license http://www.kotchasan.com/license/
 */
// load Kotchasan
include 'load.php';
// config
$cfg = Gcms\Config::create();
if (empty($cfg->msvalidate)) {
    new \Kotchasan\Http\NotFound();
} else {
    $response = new Kotchasan\Http\Response();
    $content = '<' . '?xml version="1.0"?' . '>';
    $content .= "\n<users>";
    $content .= "\n\t<user>" . $cfg->msvalidate . "</user>";
    $content .= "\n</users>";
    $response->withContent($content)->withHeader('Content-Type', 'application/xml; charset=UTF-8')->send();
}
 /**
  * สร้างไฟล์ CSS
  */
 public function index()
 {
     // session
     self::$request->initSession();
     // โหลด css หลัก
     $data = preg_replace('/url\\(([\'"])?fonts\\//isu', "url(\\1" . WEB_URL . 'skin/fonts/', file_get_contents(ROOT_PATH . 'skin/fonts.css'));
     $data .= file_get_contents(ROOT_PATH . 'skin/gcss.css');
     $data .= file_get_contents(ROOT_PATH . 'skin/gcms.css');
     // frontend template
     $skin = 'skin/' . (empty($_SESSION['skin']) ? self::$cfg->skin : $_SESSION['skin']);
     $data2 = file_get_contents(TEMPLATE_ROOT . $skin . '/style.css');
     $data2 = preg_replace('/url\\(([\'"])?(img|fonts)\\//isu', "url(\\1" . WEB_URL . $skin . '/\\2/', $data2);
     // css ของโมดูล
     $dir = TEMPLATE_ROOT . $skin . '/';
     $f = @opendir($dir);
     if ($f) {
         while (false !== ($text = readdir($f))) {
             if ($text != "." && $text != "..") {
                 if (is_dir($dir . $text)) {
                     if (is_file($dir . $text . '/style.css')) {
                         $data2 .= preg_replace('/url\\(img\\//isu', 'url(' . WEB_URL . $skin . '/' . $text . '/img/', file_get_contents($dir . $text . '/style.css'));
                     }
                 }
             }
         }
         closedir($f);
     }
     // โหลด css ของ Widgets
     $dir = ROOT_PATH . 'Widgets/';
     $f = opendir($dir);
     while (false !== ($text = readdir($f))) {
         if ($text != "." && $text != "..") {
             if (is_dir($dir . $text)) {
                 if (is_file($dir . $text . '/style.css')) {
                     $data2 .= preg_replace('/url\\(img\\//isu', 'url(' . WEB_URL . 'Widgets/' . $text . '/img/', file_get_contents($dir . $text . '/style.css'));
                 }
             }
         }
     }
     closedir($f);
     // status color
     foreach (self::$cfg->color_status as $key => $value) {
         $data2 .= '.status' . $key . '{color:' . $value . '}';
     }
     $bg = '';
     if (!empty(self::$cfg->bg_image) && is_file(ROOT_PATH . DATA_FOLDER . 'image/' . self::$cfg->bg_image)) {
         $bg .= 'background-image:url(' . WEB_URL . DATA_FOLDER . 'image/' . self::$cfg->bg_image . ');';
         $bg .= 'background-repeat:repeat;';
     }
     if (!empty(self::$cfg->bg_color)) {
         $bg .= 'background-color:' . self::$cfg->bg_color . ';';
     }
     if ($bg != '') {
         $data2 .= 'body{' . $bg . '}';
     }
     // compress css
     $data = preg_replace(array('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '/[\\s]{0,}([:;,>\\{\\}])[\\s]{0,}/'), array('', '\\1'), $data . $data2);
     $data = preg_replace(array('/[\\r\\n\\t]/s', '/[\\s]{2,}/s', '/;}/'), array('', ' ', '}'), $data);
     // Response
     $response = new \Kotchasan\Http\Response();
     // cache 1 month
     $expire = 2592000;
     $response->withHeaders(array('Content-type' => 'text/css; charset=utf-8', 'Cache-Control' => 'max-age=' . $expire . ', public', 'Etag' => md5($data), '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($data)->send();
 }
 /**
  * สร้างไฟล์ 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();
 }
 /**
  * สร้างไฟล์ 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();
 }