예제 #1
0
 /**
  * อ่านข้อมูล Schema จากตาราง
  *
  * @param string $table
  */
 private function init($table)
 {
     if (empty($this->tables[$table])) {
         $sql = "SHOW FULL COLUMNS FROM {$table}";
         $columns = $this->db->cacheOn()->customQuery($sql, true);
         if (empty($columns)) {
             throw new Exception($this->db->getError());
         } else {
             $datas = array();
             foreach ($columns as $column) {
                 $datas[$column['Field']] = $column;
             }
             $this->tables[$table] = $datas;
         }
     }
 }
예제 #2
0
 /**
  * ฟังก์ชั่นสร้างคำสั่ง SQL เป้นข้อความ
  *
  * @return string
  */
 public function text()
 {
     if (empty($this->sqls)) {
         return '';
     } else {
         $sql = $this->db->makeQuery($this->sqls);
         $values = $this->getValues();
         if (!empty($values)) {
             foreach ($values as $key => $value) {
                 $sql = str_replace($key, is_string($value) ? "'{$value}'" : $value, $sql);
             }
         }
         return $sql;
     }
 }
예제 #3
0
 /**
  * ouput เป็น HTML.
  *
  * @param string|null $template HTML Template ถ้าไม่กำหนด (null) จะใช้ index.html
  * @return string
  */
 public function renderHTML($template = null)
 {
     // เนื้อหา
     parent::setContents(array('/{LOGIN}/' => method_exists('Index\\Login\\Controller', 'init') ? \Index\Login\Controller::init(Login::isMember()) : '', '/{WIDGET_([A-Z]+)(([_\\s]+)([^}]+))?}/e' => '\\Gcms\\View::getWidgets(array(1=>"$1",3=>"$3",4=>"$4"))', '/{BREADCRUMBS}/' => implode('', $this->breadcrumbs), '/{FONTSIZE}/' => '<a class="font_size small" title="{LNG_change font small}">A<sup>-</sup></a><a class="font_size normal" title="{LNG_change font normal}">A</a><a class="font_size large" title="{LNG_change font large}">A<sup>+</sup></a>', '/{VERSION}/' => self::$cfg->version, '/{ELAPSED}/' => round(microtime(true) - REQUEST_TIME, 4), '/{QURIES}/' => \Kotchasan\Database\Driver::queryCount()));
     return parent::renderHTML($template);
 }
예제 #4
0
 /**
  * GLoader
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // ตรวจสอบ Referer
     if ($request->initSession() && $request->isReferer()) {
         // ตัวแปรป้องกันการเรียกหน้าเพจโดยตรง
         define('MAIN_INIT', __FILE__);
         // ตรวจสอบการ login
         Login::create();
         // กำหนด skin ให้กับ template
         Template::init(self::$cfg->skin);
         // counter และ useronline
         \Index\Counter\Model::init();
         // View
         Gcms::$view = new \Index\Loader\View();
         // โมดูลที่ติดตั้ง
         $dir = ROOT_PATH . 'modules/';
         // โหลดโมดูลทั้งหมด
         foreach (\Index\Module\Model::getInstalledModule() as $owner) {
             if (is_file($dir . $owner . '/controllers/init.php')) {
                 include $dir . $owner . '/controllers/init.php';
                 $class = ucfirst($owner) . '\\Init\\Controller';
                 if (method_exists($class, 'init')) {
                     createClass($class)->init();
                 }
             }
         }
         // โหลด Init ของ 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 . '/Controllers/Init.php')) {
                             include $dir . $text . '/Controllers/Init.php';
                             $class = 'Widgets\\' . ucfirst($text) . '\\Controllers\\Init';
                             if (method_exists($class, 'init')) {
                                 createClass($class)->init();
                             }
                         }
                     }
                 }
             }
             closedir($f);
         }
         // หน้า home มาจากเมนูรายการแรก
         $home = Gcms::$menu->homeMenu();
         if ($home) {
             $home->canonical = WEB_URL . 'index.php';
             // breadcrumb หน้า home
             Gcms::$view->addBreadcrumb($home->canonical, $home->menu_text, $home->menu_tooltip, 'icon-home');
         }
         // ตรวจสอบโมดูลที่เรียก
         $posts = $request->getParsedBody();
         $modules = \Index\Module\Controller::get($posts);
         if (!empty($modules)) {
             // โหลดโมดูลที่เรียก
             $page = createClass($modules->className)->{$modules->method}($request->withQueryParams($posts), $modules->module);
         }
         if (empty($page)) {
             // ไม่พบหน้าที่เรียก (index)
             $page = createClass('Index\\PageNotFound\\Controller')->init($request, 'index');
         }
         // output เป็น HTML
         $ret = array('db_elapsed' => round(microtime(true) - REQUEST_TIME, 4), 'db_quries' => \Kotchasan\Database\Driver::queryCount());
         foreach ($page as $key => $value) {
             $ret[$key] = $value;
         }
         if (empty($ret['menu'])) {
             $ret['menu'] = $ret['module'];
         }
         $ret['detail'] = Gcms::$view->renderHTML($page->detail);
         echo json_encode($ret);
     }
 }