Esempio n. 1
0
 /**
  * แปลง path เป็น query string ตามที่กำหนดโดย $url_rules
  *
  * @param string path เช่น /a/b/c.html
  * @param pointer $modules คืนค่า query string ที่ตัวแปรนี้
  */
 public static function parseRoutes($path, &$modules)
 {
     if (preg_match('/^\\/(.*)((\\.html?)|\\/)$/u', str_replace(BASE_PATH, '', $path), $match)) {
         $my_path = $match[1];
     } else {
         if (preg_match('/^\\/(.*)$/u', str_replace(BASE_PATH, '', $path), $match)) {
             $my_path = $match[1];
         }
     }
     if (isset($my_path)) {
         /**
          * กฏของ Router สำหรับการแยกหน้าเว็บไซต์
          */
         $config = array('/^(css|js).*?/' => array('', 'return'), '/^((sys\\-)?admin).*?/' => array('', 'user'), '/^([0-9a-z\\-]+)\\/([a-z]+)\\/([0-9]+)\\/([0-9]+)(\\/(.*))?$/' => array('', 'user', 'module', 'cat', 'id', '', 'document'), '/^([a-z]+)\\/([0-9]+)\\/([0-9]+)(\\/(.*))?$/' => array('', 'module', 'cat', 'id', '', 'document'), '/^([0-9a-z\\-]+)\\/([a-z]+)\\/([0-9]+)(\\/(.*))?$/' => array('', 'user', 'module', 'cat', '', 'document'), '/^([a-z]+)\\/([0-9]+)(\\/(.*))?$/' => array('', 'module', 'cat', '', 'document'), '/^([0-9a-z\\-]+)\\/([a-z]+)(\\/(.*))?$/' => array('', 'user', 'module', '', 'document'), '/^([a-z]+)(\\/(.*))?$/' => array('', 'module', '', 'document'));
         foreach (\Core\Gcms::get('router', 'route_rules', $config) as $patt => $items) {
             if (preg_match($patt, $my_path, $match)) {
                 foreach ($items as $i => $key) {
                     if (!empty($key) && isset($match[$i])) {
                         $modules[$key] = $match[$i];
                     }
                 }
                 break;
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * ฟังก์ชั่นอ่านค่าเวลาในรูป mktime
  *
  * @param int $mktime (optional)
  * @return int คืนค่าเวลาในรูป mktime ถ้าระบุ $mktime ฟังก์ชั่นจะคืนค่านี้ ถ้าไม่ระบุมา จะคืนค่าเวลาปัจจุบัน
  */
 protected static function _mktime($mktime = 0)
 {
     if (!isset(self::$mktime)) {
         self::$mktime = mktime(date("H") + \Core\Gcms::get('config', 'hour', 0));
     }
     return empty($mktime) ? self::$mktime : $mktime;
 }
Esempio n. 3
0
 /**
  * สร้างไฟล์ CSS
  *
  * @param mixed $params
  */
 public function render($param = null)
 {
     // header
     foreach (\Core\Gcms::get('header') as $key => $value) {
         header("{$key}: {$value}");
     }
     // result
     echo preg_replace(array('/[\\r\\n\\t]/s', '/[\\s]{2,}/s', '/;}/'), array('', ' ', '}'), $param);
 }
Esempio n. 4
0
 /**
  * @param array $params
  */
 public function __construct($params)
 {
     if (is_array($params)) {
         foreach ($params as $key => $val) {
             $this->{$key} = $val;
         }
     }
     $this->prefix = \Core\Gcms::get('database', 'prefix') . '_';
 }
Esempio n. 5
0
 /**
  * ฟังก์ชั่นสร้าง URL จากโมดูล
  *
  * @param string $module URL ชื่อโมดูล
  * @param string $document (option)
  * @param int $catid (option) id ของหมวดหมู่ (default 0)
  * @param int $id (option) id ของข้อมูล (default 0)
  * @param string $query (option) query string อื่นๆ (default ค่าว่าง)
  * @param boolean $encode (option) true=เข้ารหัสด้วย rawurlencode ด้วย (default true)
  *
  * @return string URL ที่สร้าง
  */
 public static function createUrl($module, $document = '', $catid = 0, $id = 0, $query = '', $encode = true)
 {
     /**
      * กฏของ URL ใช้สำหรับการสร้างลิงค์
      */
     $config = array(0 => 'index.php?module={module}-{document}&cat={catid}&id={id}', 1 => '{module}/{catid}/{id}/{document}.html');
     $urls = \Core\Gcms::get('url', 'urls', $config);
     $patt = array();
     $replace = array();
     if (empty($document)) {
         $patt[] = '/[\\/-]{document}/';
         $replace[] = '';
     } else {
         $patt[] = '/{document}/';
         $replace[] = $encode ? rawurlencode($document) : $document;
     }
     $patt[] = '/{module}/';
     $replace[] = $encode ? rawurlencode($module) : $module;
     if (empty($catid)) {
         $patt[] = '/((cat={catid}&)|([\\/-]{catid}))/';
         $replace[] = '';
     } else {
         $patt[] = '/{catid}/';
         $replace[] = (int) $catid;
     }
     if (empty($id)) {
         $patt[] = '/(((&|\\?)id={id})|([\\/-]{id}))/';
         $replace[] = '';
     } else {
         $patt[] = '/{id}/';
         $replace[] = (int) $id;
     }
     $link = preg_replace($patt, $replace, $urls[\Core\Gcms::get('config', 'module_url', 0)]);
     if (!empty($query)) {
         $link = preg_match('/[\\?]/u', $link) ? $link . '&' . $query : $link . '?' . $query;
     }
     $obj = new static();
     $obj->curr_parse = false;
     $obj->curr_url = WEB_URL . '/' . $link;
     return $obj->curr_url;
 }
Esempio n. 6
0
 /**
  * อ่านโมดูลที่ต้องการ
  *
  * @param string $module
  */
 public function getModule($module)
 {
     $db = \Core\Gcms::Database();
     // วันนี้
     $date = \Core\Date::mktime_to_sql_date();
     // อ่านโมดูล ตามภาษา
     $sql = "SELECT M.`module`,I.`id`,D.`topic`,D.`description`,D.`keywords`,D.`detail`,I.`visited`";
     if (is_int($module)) {
         $sql .= " FROM `" . $db->prefix . \Core\Gcms::get('database', 'index') . "` AS I";
         $sql .= " INNER JOIN `" . $db->prefix . \Core\Gcms::get('database', 'modules') . "` AS M ON M.`id`=I.`module_id`";
         $sql .= " INNER JOIN `" . $db->prefix . \Core\Gcms::get('database', 'index_detail') . "` AS D ON D.`id`=I.`id` AND D.`module_id`=I.`module_id` AND D.`language`=I.`language`";
         $sql .= " WHERE I.`id`=" . (int) $module . " AND I.`index`='1' AND I.`published`='1' AND I.`published_date`<='{$date}' LIMIT 1";
     } else {
         $sql .= " FROM `" . $db->prefix . \Core\Gcms::get('database', 'index_detail') . "` AS D ";
         $sql .= " INNER JOIN `" . $db->prefix . \Core\Gcms::get('database', 'index') . "` AS I ON I.`id`=D.`id` AND I.`index`='1' AND I.`published`='1' AND I.`published_date`<='{$date}' AND I.`language`=D.`language`";
         $sql .= " INNER JOIN `" . $db->prefix . \Core\Gcms::get('database', 'modules') . "` AS M ON M.`id`=D.`module_id` AND M.`module`='{$module}'";
         $sql .= " WHERE D.`language` IN ('" . LANGUAGE . "','') LIMIT 1";
     }
     $search = $db->customQuery($sql);
     return sizeof($search) == 1 ? $search[0] : false;
 }
Esempio n. 7
0
 /**
  * inint Controller.
  *
  * @param array $modules
  */
 public function inint($modules = null)
 {
     // cache 1 month
     $expire = 2592000;
     \Core\Gcms::header(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'));
     // โหลด 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');
     // โหลดจาก template
     $template = str_replace(ROOT_PATH, '', \Core\Gcms::get('config', 'template_root'));
     $skin = 'skin/' . \Core\Gcms::get('config', 'skin');
     $data2 = file_get_contents(ROOT_PATH . $template . $skin . '/style.css');
     $data2 = preg_replace('/url\\(([\'"])?(img|fonts)\\//isu', "url(\\1" . WEB_URL . '/' . $skin . '/\\2/', $data2);
     // compress css
     $data = preg_replace(array('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '/\\s?([:;,>\\{\\}])\\s?/s'), array('', '\\1', ' '), $data . $data2);
     // ตัด > ใน ie ต่ำกว่า 7
     if (preg_match('|MSIE ([0-9].[0-9]{1,2})|', \Core\Gcms::get($_SERVER, 'HTTP_USER_AGENT'), $matched)) {
         if ((int) $matched[1] < 7) {
             $data = str_replace('>', ' ', $data);
         }
     }
     // render
     \Core\Gcms::createClass('Css\\View')->render($data);
 }
Esempio n. 8
0
 /**
  * โหลด GCMS เพื่อประมวลผล
  */
 public function inint()
 {
     /**
      * โหลด config
      */
     $config = array();
     $config['hour'] = 0;
     $config['languages'][0] = 'th';
     $config['skin'] = '';
     $config['datas_folder'] = 'datas/';
     $config['template_root'] = APP_PATH;
     self::$CFG['config'] = new \Core\ListItem($config);
     self::$CFG['config']->loadFromFile(APP_PATH . 'settings/config.php');
     /**
      * display error
      */
     if (self::get('config', 'debug', true)) {
         // ขณะออกแบบ แสดง error และ warning ของ PHP
         ini_set('display_errors', 1);
         ini_set('display_startup_errors', 1);
         error_reporting(-1);
     } else {
         // ขณะใช้งานจริง
         error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
     }
     /**
      * โฟลเดอร์สำหรับเก็บข้อมูลต่างๆ นับจาก root ของ server
      */
     define('DATA_FOLDER', self::get('config', 'datas_folder'));
     define('DATA_PATH', APP_PATH . DATA_FOLDER);
     define('DATA_URL', WEB_URL . '/' . DATA_FOLDER);
     /**
      * ภาษาที่เลือก
      */
     $languages = self::get('config', 'languages');
     $language = self::get('GET,SESSION,COOKIE', 'lang,gcms_language,gcms_language', $languages[0]);
     $language = is_file(DATA_PATH . "language/{$language}.php") ? $language : 'th';
     define('LANGUAGE', $language);
     /**
      * skin
      */
     $skin = \Core\Gcms::get('config', 'skin');
     $template_root = \Core\Gcms::get('config', 'template_root');
     $skin = is_file($template_root . 'skin/' . $skin . '/style.css') ? $skin : 'default';
     define('SKIN', "skin/{$skin}/");
     /**
      * return current instance
      */
     return self::$instance;
 }
Esempio n. 9
0
 /**
  * แสดงผล เป็น HTML.
  */
 public function renderHTML($template)
 {
     // default for template
     self::$datas['/{WEBTITLE}/'] = \Core\Gcms::get('config', 'web_title');
     self::$datas['/{WEBDESCRIPTION}/'] = \Core\Gcms::get('config', 'web_description');
     self::$datas['/{LANGUAGE}/'] = LANGUAGE;
     self::$datas['/{WEBURL}/'] = WEB_URL;
     self::$datas['/{SKIN}/'] = SKIN;
     self::$datas['/{ELAPSED}/'] = sprintf('%.3f', microtime(true) - BEGIN_TIME);
     self::$datas['/{USAGE}/'] = memory_get_usage(false) / 1024;
     // แทนที่ลงใน template
     echo \Core\Gcms::pregReplace(array_keys(self::$datas), array_values(self::$datas), $template);
 }