Example #1
0
 /**
  * ส่งออกเป็น PDF
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     $pdf = new \Kotchasan\Pdf();
     $pdf->AddPage();
     $pdf->WriteHTML($request->post('content')->toString());
     $pdf->Output();
 }
 /**
  * แสดงผล
  */
 public function render(Request $request)
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // รายการที่ต้องการ
         $index = \Index\Pagewrite\Model::getIndex($request->get('id')->toInt(), $request->get('owner', 'index')->topic());
         if ($index) {
             // สร้างหรือแก้ไข
             // แสดงผล
             $section = Html::create('section');
             // breadcrumbs
             $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
             $ul = $breadcrumbs->add('ul');
             $ul->appendChild('<li><span class="icon-modules">{LNG_Menus} &amp; {LNG_Web pages}</span></li>');
             $ul->appendChild('<li><a href="{BACKURL?module=pages&id=0}">{LNG_Web pages}</a></li>');
             $ul->appendChild('<li><span>{LNG_' . (empty($index->id) ? 'Create' : 'Edit') . '}</span></li>');
             $section->add('header', array('innerHTML' => '<h1 class="icon-write">' . $this->title() . '</h1>'));
             if ($index) {
                 // แสดงฟอร์ม
                 $section->appendChild(createClass('Index\\Pagewrite\\View')->render($index));
                 return $section->render();
             }
         }
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
 /**
  * แสดงผล
  *
  * @return string
  */
 public function render(Request $request)
 {
     // อ่านข้อมูลสมาชิก
     $model = new Model();
     $user = $model->db()->createQuery()->from('user')->where(array('id', (int) $_SESSION['login']['id']))->first();
     $template = Template::create('member', 'member', 'profile');
     $contents = array('/<NEWREGISTER>(.*)<\\/NEWREGISTER>/isu' => $request->request('action')->toString() === 'newregister' ? '\\1' : '', '/<IDCARD>(.*)<\\/IDCARD>/isu' => empty(self::$cfg->member_idcard) ? '' : '\\1', '/{ACCEPT}/' => Mime::getEccept(self::$cfg->user_icon_typies));
     // ข้อมูลฟอร์ม
     foreach ($user as $key => $value) {
         if ($key == 'sex') {
             $datas = array();
             foreach (Language::get('SEXES') as $k => $v) {
                 $sel = $k == $value ? ' selected' : '';
                 $datas[] = '<option value="' . $k . '"' . $sel . '>' . $v . '</option>';
             }
             $contents['/{SEX}/'] = implode('', $datas);
         } elseif ($key === 'subscrib') {
             $contents['/{SUBSCRIB}/'] = $value == 1 ? 'checked' : '';
         } elseif ($key === 'icon') {
             if (is_file(ROOT_PATH . self::$cfg->usericon_folder . $value)) {
                 $icon = WEB_URL . self::$cfg->usericon_folder . $value;
             } else {
                 $icon = WEB_URL . 'skin/img/noicon.jpg';
             }
             $contents['/{ICON}/'] = $icon;
         } else {
             $contents['/{' . strtoupper($key) . '}/'] = $value;
         }
     }
     $template->add($contents);
     // after render
     Gcms::$view->setContents(array('/:type/' => empty(self::$cfg->user_icon_typies) ? 'jpg' : implode(', ', self::$cfg->user_icon_typies)), false);
     return $template->render();
 }
 /**
  * แสดงผล
  */
 public function render(Request $request)
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // โมดูลที่ต้องการติดตั้ง
         $module = $request->get('m')->filter('a-z');
         $widget = $request->get('w')->filter('a-z');
         $this->module = $module !== '' ? $module : $widget;
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         if ($module !== '') {
             $ul->appendChild('<li><span class="icon-modules">{LNG_Module}</span></li>');
             $type = 'module';
         } elseif ($widget !== '') {
             $ul->appendChild('<li><span class="icon-widgets">{LNG_Widgets}</span></li>');
             $type = 'widget';
         } else {
             // 404.html
             return \Index\Error\Controller::page404();
         }
         $ul->appendChild('<li><span>{LNG_Install}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-inbox">' . $this->title() . '</h1>'));
         // แสดงฟอร์ม
         $section->appendChild(createClass('Index\\Install\\View')->render($type, $this->module));
         return $section->render();
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
 /**
  * หน้า login
  *
  * @param Request $request
  * @return object
  */
 public function render(Request $request)
 {
     $index = (object) array('canonical' => WEB_URL . 'index.php?module=dologin', 'topic' => Language::get('Visitors please login'), 'description' => self::$cfg->web_description, 'menu' => 'dologin');
     $template = Template::create('member', 'member', 'loginfrm');
     $template->add(array('/{TOKEN}/' => $request->createToken(), '/{EMAIL}/' => Login::$text_username, '/{PASSWORD}/' => Login::$text_password, '/{REMEMBER}/' => self::$request->cookie('login_remember')->toInt() == 1 ? 'checked' : '', '/{FACEBOOK}/' => empty(self::$cfg->facebook_appId) ? 'hidden' : 'facebook', '/{TOPIC}/' => $index->topic, '/{SUBTITLE}/' => $index->description));
     $index->detail = $template->render();
     $index->keywords = $index->topic;
     if (isset(Gcms::$view)) {
         Gcms::$view->addBreadcrumb($index->canonical, Language::get('Sign In'));
     }
     return $index;
 }
Example #6
0
 /**
  * แสดงผล
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // เริ่มต้นการใช้งาน Template
     Template::init(self::$cfg->skin);
     // ถ้าไม่มีโมดูลเลือกหน้า home
     $module = $request->get('module', 'home')->toString();
     // สร้าง View
     $view = new \Kotchasan\View();
     // template default
     $view->setContents(array('/{MENU}/' => createClass('Index\\Menu\\Controller')->render($module), '/{TITLE}/' => self::$cfg->web_title, '/{CONTENT}/' => Template::load('', '', $module), '/{TIME}/' => Date::format()));
     // ส่งออกเป็น HTML
     echo $view->renderHTML();
 }
 /**
  * แสดงผลฟอร์ม ที่เรียกมาจาก GModal
  *
  * @param Request $request
  */
 public function modal(Request $request)
 {
     $action = $request->post('action')->toString();
     if ($action === 'register') {
         $page = createClass('Index\\Register\\View')->render($request, true);
     } elseif ($action === 'forgot') {
         $page = createClass('Index\\Forgot\\View')->render($request, true);
     } else {
         // 404
         $page = createClass('Index\\PageNotFound\\Controller')->init($request, 'index');
     }
     echo json_encode($page);
 }
 /**
  * ค้นหาข้อมูลทั้งหมด
  *
  * @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;
 }
 /**
  * Useronline
  *
  * @param array $query_string
  */
 public function index(Request $request)
 {
     // ตรวจสอบ Referer
     if ($request->initSession() && $request->isReferer()) {
         // ตัวแปรป้องกันการเรียกหน้าเพจโดยตรง
         define('MAIN_INIT', __FILE__);
         // เวลาปัจจุบัน
         $time = time();
         // sesssion ปัจจุบัน
         $session_id = session_id();
         // เวลาหมดอายุ
         $validtime = $time - self::$cfg->counter_gap;
         // ตาราง useronline
         $useronline = $this->getFullTableName('useronline');
         // ลบคนที่หมดเวลาและตัวเอง
         $this->db()->delete($useronline, array(array('time', '<', $validtime), array('session', $session_id)), 0, 'OR');
         // เพิ่มตัวเอง
         $save = array('time' => $time, 'session' => $session_id, 'ip' => $request->getClientIp());
         $login = Login::isMember();
         if ($login) {
             $save['member_id'] = (int) $login['id'];
             $save['displayname'] = $login['displayname'] == '' ? $login['email'] : $login['displayname'];
         }
         $this->db()->insert($useronline, $save);
         // คืนค่า user online
         $ret = array('time' => $time);
         // โหลด useronline ของ module
         $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 . '/controllers/useronline.php')) {
                             include $dir . $text . '/controllers/useronline.php';
                             $class = ucfirst($text) . '\\Useronline\\Controller';
                             if (method_exists($class, 'index')) {
                                 $ret = createClass($class)->index($ret);
                             }
                         }
                     }
                 }
             }
             closedir($f);
         }
         // คืนค่า JSON
         echo json_encode($ret);
     }
 }
 public function view(Request $request)
 {
     $topic = Language::get('Personal information') . ' ' . self::$cfg->web_title;
     $user = \Index\Member\Model::getUserById($request->get('id')->toInt());
     if ($user) {
         $template = Template::create('member', 'member', 'view');
         $template->add(array('/{ID}/' => $user->id, '/{EMAIL}/' => $user->email, '/{FNAME}/' => $user->fname, '/{LNAME}/' => $user->lname, '/{SEX}/' => $user->sex === 'f' || $user->sex === 'm' ? $user->sex : 'u', '/{DATE}/' => Date::format($user->create_date), '/{WEBSITE}/' => $user->website, '/{VISITED}/' => $user->visited, '/{LASTVISITED}/' => Date::format($user->lastvisited), '/{POST}/' => number_format($user->post), '/{REPLY}/' => number_format($user->reply), '/{STATUS}/' => isset(self::$cfg->member_status[$user->status]) ? self::$cfg->member_status[$user->status] : 'Unknow', '/{COLOR}/' => $user->status, '/{SOCIAL}/' => $user->fb == 1 ? 'icon-facebook' : '', '/{TOPIC}/' => $topic));
         // breadcrumbs
         $canonical = WEB_URL . 'index.php?module=member&amp;id=' . $user->id;
         Gcms::$view->addBreadcrumb($canonical, $topic);
         // คืนค่า
         return (object) array('detail' => $template->render(), 'keywords' => self::$cfg->web_title, 'description' => self::$cfg->web_description, 'topic' => $topic, 'canonical' => $canonical);
     } else {
         // ไม่พบสมาชิก
         return createClass('Index\\PageNotFound\\Controller')->init($request, 'index');
     }
 }
Example #11
0
 /**
  * มาจากการเรียกด้วย Ajax
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // ตรวจสอบ Referer
     if ($request->initSession() && $request->isReferer()) {
         // ตัวแปรป้องกันการเรียกหน้าเพจโดยตรง
         define('MAIN_INIT', __FILE__);
         // กำหนด skin ให้กับ template
         Template::init(self::$cfg->skin);
         // ค่าจาก POST
         $query_string = $request->getParsedBody();
         // เรียก Class ที่กำหนด
         if (!empty($query_string['class']) && preg_match('/^[a-zA-Z0-9]+$/', $query_string['method']) && method_exists($query_string['class'], $query_string['method'])) {
             $method = $query_string['method'];
             createClass($query_string['class'])->{$method}($request->withQueryParams($query_string));
         }
     }
 }
 /**
  * หน้าแก้ไขข้อมูลส่วนตัว
  *
  * @param Request $request
  * @return object
  */
 public function render(Request $request)
 {
     if ($login = Login::isMember()) {
         // tab ที่เลือก
         $tab = $request->request('tab')->toString();
         $member_tabs = array_keys(Gcms::$member_tabs);
         $tab = in_array($tab, $member_tabs) ? $tab : reset($member_tabs);
         $index = (object) array('description' => self::$cfg->web_description);
         // รายการ tabs
         $tabs = array();
         if (!empty($login['fb'])) {
             unset(Gcms::$member_tabs['password']);
         }
         foreach (Gcms::$member_tabs as $key => $values) {
             if ($values[0] != '') {
                 if ($key == $tab) {
                     $class = "tab select {$key}";
                     $index->topic = Language::get($values[0]);
                     $className = $values[1];
                 } else {
                     $class = "tab {$key}";
                 }
                 if (preg_match('/^http:\\/\\/.*/', $values[1])) {
                     $tabs[] = '<li class="' . $class . '"><a href="' . $values[1] . '">' . Language::get($values[0]) . '</a></li>';
                 } else {
                     $tabs[] = '<li class="' . $class . '"><a href="{WEBURL}index.php?module=editprofile&amp;tab=' . $key . '">' . Language::get($values[0]) . '</a></li>';
                 }
             }
         }
         if (empty($className)) {
             // FB และแก้ไขรหัสผ่าน
             return createClass('Index\\PageNotFound\\Controller')->init($request, 'index');
         } else {
             $template = Template::create('member', 'member', 'main');
             $template->add(array('/{TAB}/' => implode('', $tabs), '/{DETAIL}/' => createClass($className)->render($request)));
             $index->detail = $template->render();
             $index->keywords = $index->topic;
             // menu
             $index->menu = 'member';
             return $index;
         }
     } else {
         // ไม่ได้ login
         return createClass('Index\\PageNotFound\\Controller')->init($request, 'index');
     }
 }
 /**
  * แสดงข้อมูลสมาชิก
  *
  * @param Request $request
  * @return object
  */
 public function render(Request $request)
 {
     // ตรวจสอบข้อมูล
     $user = \Index\Member\Model::getUserByActivateCode($request->get('id')->topic());
     if ($user) {
         // activate
         \Index\Member\Model::activateUser($user);
         // ข้อมูลแสดงผล (สำเร็จ)
         $details = array('/{DETAIL}/' => Language::get('<b>Congratulations!</b> your members have already confirmed. You can use your email address and password sent with the email address used to login.'), '/{CLASS}/' => 'message');
     } else {
         // ข้อมูลแสดงผล (ไม่สำเร็จ)
         $details = array('/{DETAIL}/' => Language::get('<b>Sorry!</b> can not find it registered. Information of registration may have expired or your registration may be confirmed.'), '/{CLASS}/' => 'error');
     }
     // template
     $template = Template::create('member', 'member', 'activate');
     $template->add($details);
     // คืนค่า
     return (object) array('detail' => $template->render(), 'keywords' => self::$cfg->web_title, 'description' => self::$cfg->web_description, 'topic' => Language::get('Activate') . ' ' . self::$cfg->web_title, 'menu' => 'member');
 }
Example #14
0
 /**
  * แสดงผล
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // session cookie
     $request->initSession();
     // ตรวจสอบการ login
     Login::create();
     if (Login::isMember()) {
         echo '<a href="?action=logout">Logout</a><br>';
         var_dump($_SESSION);
     } else {
         // forgot or login
         if ($request->get('action')->toString() == 'forgot') {
             $main = new \Index\Forgot\View();
         } else {
             $main = new \Index\Login\View();
         }
         echo $main->render();
     }
 }
 public function index(Request $request)
 {
     if ($request->initSession() && $request->isReferer()) {
         $user = $this->db()->createQuery()->from('user')->where($request->get('id')->toInt())->cacheOn()->toArray()->first('icon');
         if ($user) {
             if (!empty($user['icon']) && is_file(ROOT_PATH . self::$cfg->usericon_folder . $user['icon'])) {
                 $icon = ROOT_PATH . self::$cfg->usericon_folder . $user['icon'];
             }
         }
         if (empty($icon)) {
             $icon = is_file(ROOT_PATH . 'skin/' . self::$cfg->skin . '/img/noicon.jpg') ? ROOT_PATH . 'skin/' . self::$cfg->skin . '/img/noicon.jpg' : ROOT_PATH . 'skin/img/noicon.jpg';
         }
         // ตรวจสอบรูป
         $info = getImageSize($icon);
         if (empty($info['error'])) {
             $response = new Response();
             $response->withHeaders(array('Pragma' => 'public', 'Cache-Control' => 'max-age=86400', 'Expires' => gmdate('D, d M Y H:i:s GMT', time() + 86400), 'Content-type' => $info['mime']))->withContent(file_get_contents($icon))->send();
         }
     }
 }
 /**
  * บันทึก
  */
 public function save(Request $request)
 {
     // referer, session
     if ($request->initSession() && $request->isReferer()) {
         $ret = array();
         // ค่าที่ส่งมา
         $email = $request->post('forgot_email')->url();
         if ($email === '') {
             $ret['ret_forgot_email'] = Language::get('Please fill out this form');
         } else {
             $search = $this->db()->createQuery()->from('user')->where(array(array('email', $email), array('fb', '0')))->toArray()->first('id', 'email');
             if ($search === false) {
                 $ret['ret_forgot_email'] = Language::get('not a registered user');
             }
         }
         if (empty($ret)) {
             // รหัสผ่านใหม่
             $password = Text::rndname(6);
             // ข้อมูลอีเมล์
             $replace = array('/%PASSWORD%/' => $password, '/%EMAIL%/' => $search['email']);
             // send mail
             $err = Email::send(3, 'member', $replace, $search['email']);
             if (empty($err)) {
                 // อัปเดทรหัสผ่านใหม่
                 $save = array('password' => md5($password . $search['email']));
                 $this->db()->createQuery()->update('user')->set($save)->where($search['id'])->execute();
                 // คืนค่า
                 $ret['alert'] = Language::get('Your message was sent successfully');
                 $ret['ret_forgot_email'] = '';
                 $location = $request->post('modal')->url();
                 $ret['location'] = $location === 'true' ? 'close' : $location;
             } else {
                 $ret['ret_forgot_email'] = $err;
             }
         } else {
             $ret['input'] = 'forgot_email';
         }
         // คืนค่าเป็น JSON
         echo json_encode($ret);
     }
 }
 /**
  * ส่งอีเมล์ ตาม ID
  *
  * @param Request $request
  */
 public function save(Request $request)
 {
     if ($request->initSession() && $request->isReferer() && ($login = Login::isMember())) {
         // ค่าที่ส่งมา
         $subject = $request->post('mail_subject')->topic();
         $detail = nl2br($request->post('mail_detail')->textarea());
         // ตรวจสอบ ค่าที่ส่งมา
         $ret = array();
         $antispam = new Antispam($request->post('mail_antispamid')->toString());
         if (!$antispam->valid($request->post('mail_antispam')->toString())) {
             // Antispam ไม่ถูกต้อง
             $ret['ret_mail_antispam'] = 'this';
             $ret['input'] = 'mail_antispam';
         } else {
             // ตรวจสอบผู้รับ
             $reciever = array();
             foreach (self::getUser($request->post('mail_reciever')->filter('0-9a-z')) as $item) {
                 $reciever[] = $item['email'] . (empty($item['name']) ? '' : '<' . $item['name'] . '>');
             }
             $reciever = implode(',', $reciever);
             // ตรวจสอบค่าที่ส่งมา
             if ($reciever == '') {
                 $ret['alert'] = Language::get('Unable to send e-mail, Because you can not send e-mail to yourself or can not find the email address of the recipient.');
                 $ret['location'] = WEB_URL . 'index.php';
             } elseif ($subject == '') {
                 $ret['ret_mail_subject'] = 'this';
                 $ret['input'] = 'mail_subject';
             } elseif ($detail == '') {
                 $ret['ret_mail_detail'] = 'this';
                 $ret['input'] = 'mail_detail';
             } else {
                 // ส่งอีเมล์
                 $err = Email::send($reciever, $login['email'] . (empty($login['displayname']) ? '' : '<' . $login['displayname'] . '>'), $subject, $detail);
                 if (empty($err)) {
                     // เคลียร์ Antispam
                     $antispam->delete();
                     // ส่งอีเมล์สำเร็จ
                     $ret['alert'] = Language::get('Your message was sent successfully');
                     $ret['location'] = WEB_URL . 'index.php';
                 } else {
                     // ข้อผิดพลาดการส่งอีเมล์
                     echo $err;
                 }
             }
         }
         if (!empty($ret)) {
             // คืนค่าเป็น JSON
             echo json_encode($ret);
         }
     }
 }
 /**
  * แสดงผล
  */
 public function render(Request $request)
 {
     // แอดมิน
     if (Login::isAdmin()) {
         $this->date = $request->get('date', date('Y-m-d'))->date();
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-home">{LNG_Home}</span></li>');
         $ul->appendChild('<li><span>{LNG_Report}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-stats">' . $this->title() . '</h1>'));
         // แสดงฟอร์ม
         $section->appendChild(createClass('Index\\Report\\View')->render($this->date));
         return $section->render();
     } else {
         // 404.html
         return \Index\Error\Controller::page404();
     }
 }
Example #19
0
 /**
  * หน้าหลักแอดมิน
  *
  * @param Request $request
  * @return string
  */
 public function execute(Request $request)
 {
     // โมดูลจาก URL ถ้าไม่มีใช้ default (dashboard)
     $module = $request->get('module', 'dashboard')->toString();
     if (preg_match('/^([a-z]+)([\\/\\-]([a-z]+))?$/i', $module, $match)) {
         if (empty($match[3])) {
             $owner = 'index';
             $module = $match[1];
         } else {
             $owner = $match[1];
             $module = $match[3];
         }
     } else {
         $owner = 'index';
         $module = 'dashboard';
     }
     // ตรวจสอบหน้าที่เรียก
     if (is_file(APP_PATH . 'modules/' . $owner . '/controllers/' . $module . '.php')) {
         // หน้าที่เรียก (Admin)
         include APP_PATH . 'modules/' . $owner . '/controllers/' . $module . '.php';
         $controller = ucfirst($owner) . '\\' . ucfirst($module) . '\\Controller';
     } elseif (is_file(ROOT_PATH . 'modules/' . $owner . '/controllers/admin/' . $module . '.php')) {
         // เรียกโมดูลที่ติดตั้ง
         include ROOT_PATH . 'modules/' . $owner . '/controllers/admin/' . $module . '.php';
         $controller = ucfirst($owner) . '\\Admin\\' . ucfirst($module) . '\\Controller';
     } elseif (is_file(ROOT_PATH . 'Widgets/' . ucfirst($owner) . '/Controllers/' . ucfirst($module) . '.php')) {
         // เรียก Widgets ที่ติดตั้ง
         include ROOT_PATH . 'Widgets/' . ucfirst($owner) . '/Controllers/' . ucfirst($module) . '.php';
         $controller = 'Widgets\\' . ucfirst($owner) . '\\Controllers\\' . ucfirst($module);
     } else {
         // หน้า default ของ backend
         include APP_PATH . 'modules/index/controllers/dashboard.php';
         $controller = 'Index\\Dashboard\\Controller';
     }
     $this->controller = new $controller();
     // tempalate
     $template = Template::create('', '', 'main');
     $template->add(array('/{CONTENT}/' => $this->controller->render($request)));
     return $template->render();
 }
 /**
  * GLoader
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // session cookie
     $request->initSession();
     // กำหนด skin ให้กับ template
     Template::init(self::$cfg->skin);
     // ตรวจสอบโมดูลที่เรียก
     $index = \Index\Export\Model::module($request->get('module')->toString());
     if ($index) {
         $className = ucfirst($index->owner) . '\\Export\\Controller';
         if (method_exists($className, 'init')) {
             $detail = createClass($className)->init($request, $index);
         }
         if ($detail != '') {
             $view = new \Kotchasan\View();
             $view->setContents(array('/{CONTENT}/' => $detail));
             echo $view->renderHTML(Template::load('', '', 'print'));
             exit;
         }
     }
     // ไม่พบโมดูลหรือไม่มีสิทธิ
     new \Kotchasan\Http\NotFound();
 }
 /**
  * หน้าส่งอีเมล์
  * สมาชิกส่งจดหมายถึงสมาชิก และ แอดมิน
  *
  * @param Request $request
  * @return object
  */
 public function render(Request $request)
 {
     // สมาชิก
     if ($login = Login::isMember()) {
         // ค่าที่ส่งมา
         $to = strtolower($request->get('to')->filter('0-9a-zA-Z'));
         if (preg_match('/^[0-9]+$/', $to)) {
             $reciever = \Index\Sendmail\Model::getUser($to);
             $to = '';
             foreach ($reciever as $id => $item) {
                 $to_msg = empty($item['name']) ? $item['email'] : $item['name'];
                 $to = $id;
             }
         } elseif ($to == 'admin') {
             $to_msg = self::$cfg->member_status[1];
         } else {
             $to = '';
         }
         if ($to != '') {
             // antispam
             $antispam = new Antispam();
             // ข้อมูลส่งกลับ
             $index = (object) array('topic' => Language::replace('Send a message to the :name', array(':name' => $to_msg)), 'keywords' => self::$cfg->web_title, 'description' => self::$cfg->web_description, 'module' => 'sendmail');
             $template = Template::create('member', 'member', 'sendmail');
             $template->add(array('/{TOPIC}/' => $index->topic, '/{ANTISPAM}/' => $antispam->getId(), '/{ANTISPAMVAL}/' => Login::isAdmin() ? $antispam->getValue() : '', '/{RECIEVER}/' => $to_msg, '/{SENDER}/' => $login['email'], '/{RECIEVERID}/' => $to));
             $index->detail = $template->render();
             // breadcrumbs
             $index->canonical = WEB_URL . 'index.php?module=sendmail&to=' . $to;
             Gcms::$view->addBreadcrumb($index->canonical, $index->topic);
             return $index;
         }
     }
     // ไม่สามารถส่งอีเมล์ได้
     $message = Language::get('Unable to send e-mail, Because you can not send e-mail to yourself or can not find the email address of the recipient.');
     return createClass('Index\\PageNotFound\\Controller')->init($request, 'member', $message);
 }
Example #22
0
 /**
  * แสดงผลหน้าหลักเว็บไซต์
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // ตัวแปรป้องกันการเรียกหน้าเพจโดยตรง
     define('MAIN_INIT', __FILE__);
     // session cookie
     $request->initSession();
     // ตรวจสอบการ login
     Login::create();
     // กำหนด skin ให้กับ template
     Template::init($request->get('skin', self::$cfg->skin)->toString());
     // backend
     Gcms::$view = new \Kotchasan\View();
     if ($login = Login::adminAccess()) {
         // โหลดโมดูลที่ติดตั้งแล้ว
         \Index\Index\Model::installedmodules();
         // Controller หลัก
         $main = new \Index\Main\Controller();
     } else {
         // forgot or login
         if ($request->request('action')->toString() === 'forgot') {
             $main = new \Index\Forgot\Controller();
         } else {
             $main = new \Index\Login\Controller();
         }
     }
     $languages = array();
     $uri = $request->getUri();
     foreach (array_merge(self::$cfg->languages, Language::installedLanguage()) as $i => $item) {
         $languages[$item] = '<a id=lang_' . $item . ' href="' . $uri->withParams(array('lang' => $item), true) . '" title="{LNG_Language} ' . strtoupper($item) . '" style="background-image:url(' . WEB_URL . 'language/' . $item . '.gif)" tabindex=1>&nbsp;</a>';
     }
     // เนื้อหา
     Gcms::$view->setContents(array('/{MAIN}/' => $main->execute($request), '/{VERSION}/' => self::$cfg->version, '/{LANGUAGES}/' => implode('', $languages), '/{TITLE}/' => $main->title() . ' (Admin)', '/{BACKURL(\\?([a-zA-Z0-9=&\\-_@\\.]+))?}/e' => '\\Kotchasan\\View::back'));
     if ($login) {
         $name = trim($login['fname'] . ' ' . $login['lname']);
         Gcms::$view->setContents(array('/{LOGINID}/' => $login['id'], '/{LOGINNAME}/' => empty($name) ? $login['email'] : $name, '/{STATUS}/' => $login['status'], '/{MENUS}/' => \Index\Menu\View::render()));
     }
     // ส่งออก เป็น HTML
     $response = new Response();
     $response->withContent(Gcms::$view->renderHTML())->send();
 }
 public function index(Request $request)
 {
     $request->initSession();
     // Antispam Image
     Antispam::createImage($request->get('id')->toString());
 }
 /**
  * บันทึก
  */
 public function save(Request $request)
 {
     $ret = array();
     // referer, session, member
     if ($request->initSession() && $request->isReferer() && ($login = Login::isMember())) {
         if ($login['email'] == 'demo') {
             $ret['alert'] = Language::get('Unable to complete the transaction');
         } else {
             // รับค่าจากการ POST
             $save = array();
             foreach ($request->getParsedBody() as $key => $value) {
                 $k = str_replace('register_', '', $key);
                 switch ($k) {
                     case 'phone1':
                     case 'phone2':
                     case 'provinceID':
                     case 'zipcode':
                         $save[$k] = $request->post($key)->number();
                         break;
                     case 'sex':
                         $save['sex'] = $request->post('register_sex')->topic();
                         $save['subscrib'] = $request->post('register_subscrib')->toBoolean();
                         break;
                     case 'displayname':
                     case 'fname':
                     case 'lname':
                     case 'address1':
                     case 'address2':
                     case 'province':
                     case 'country':
                         $save[$k] = $request->post($key)->topic();
                         break;
                     case 'website':
                         $save[$k] = str_replace(array('http://', 'https://', 'ftp://'), array('', '', ''), $request->post($key)->url());
                         break;
                     case 'subscrib':
                         $save[$k] = $request->post($key)->toBoolean();
                         break;
                     case 'birthday':
                         $save[$k] = $request->post($key)->date();
                         break;
                     case 'password':
                     case 'repassword':
                         ${$k} = $request->post($key)->text();
                         break;
                 }
             }
             // ชื่อตาราง user
             $user_table = $this->getFullTableName('user');
             // database connection
             $db = $this->db();
             // ตรวจสอบค่าที่ส่งมา
             $user = $db->first($user_table, $request->post('register_id')->toInt());
             if (!$user) {
                 // ไม่พบสมาชิกที่แก้ไข
                 $ret['alert'] = Language::get('not a registered user');
             } else {
                 $input = false;
                 // ชื่อเล่น
                 if (isset($save['displayname'])) {
                     if (mb_strlen($save['displayname']) < 2) {
                         $ret['ret_register_displayname'] = Language::get('Name for the show on the site at least 2 characters');
                         $input = !$input ? 'register_displayname' : $input;
                     } elseif (in_array($save['displayname'], self::$cfg->member_reserv)) {
                         $ret['ret_register_displayname'] = Language::get('Invalid name');
                         $input = !$input ? 'register_displayname' : $input;
                     } else {
                         // ตรวจสอบ displayname ซ้ำ
                         $search = $db->first($user_table, array('displayname', $save['displayname']));
                         if ($search !== false && $user->id != $search->id) {
                             $ret['ret_register_displayname'] = str_replace(':name', Language::get('Name'), Language::get('This :name is already registered'));
                             $input = !$input ? 'register_displayname' : $input;
                         } else {
                             $ret['ret_register_displayname'] = '';
                         }
                     }
                 }
                 // ชื่อ นามสกุล
                 if (!empty($save['fname']) || !empty($save['lname'])) {
                     $search = $db->first($user_table, array(array('fname', $save['fname']), array('lname', $save['lname'])));
                     if ($search !== false && $user->id != $search->id) {
                         $ret['ret_register_fname'] = str_replace(':name', Language::get('Name') . ' ' . Language::get('Surname'), Language::get('This :name is already registered'));
                         $input = !$input ? 'register_fname' : $input;
                     } else {
                         $ret['ret_register_fname'] = '';
                     }
                 }
                 // โทรศัพท์
                 if (!empty($save['phone1'])) {
                     if (!preg_match('/[0-9]{9,10}/', $save['phone1'])) {
                         $ret['ret_register_phone1'] = str_replace(':name', Language::get('phone number'), Language::get('Invalid :name'));
                         $input = !$input ? 'register_phone1' : $input;
                     } else {
                         // ตรวจสอบโทรศัพท์
                         $search = $db->first($user_table, array('phone1', $save['phone1']));
                         if ($search !== false && $user->id != $search->id) {
                             $ret['ret_register_phone1'] = str_replace(':name', Language::get('phone number'), Language::get('This :name is already registered'));
                             $input = !$input ? 'register_phone1' : $input;
                         } else {
                             $ret['ret_register_phone1'] = '';
                         }
                     }
                 }
                 // แก้ไขรหัสผ่าน
                 if ($user->fb == 0 && (!empty($password) || !empty($repassword))) {
                     if (mb_strlen($password) < 4) {
                         // รหัสผ่านต้องไม่น้อยกว่า 4 ตัวอักษร
                         $ret['ret_register_password'] = Language::get('Passwords must be at least four characters');
                         $input = !$input ? 'register_password' : $input;
                     } elseif ($repassword != $password) {
                         // ถ้าต้องการเปลี่ยนรหัสผ่าน กรุณากรอกรหัสผ่านสองช่องให้ตรงกัน
                         $ret['ret_register_repassword'] = Language::get('To change your password, enter your password to match the two inputs');
                         $input = !$input ? 'register_repassword' : $input;
                     } else {
                         // password ใหม่ถูกต้อง
                         $save['password'] = md5($password . $user->email);
                         $ret['ret_register_password'] = '';
                         $ret['ret_register_repassword'] = '';
                     }
                 }
                 // อัปโหลดไฟล์
                 foreach ($request->getUploadedFiles() as $item => $file) {
                     if ($file->hasUploadFile()) {
                         $item = str_replace('register_', '', $item);
                         if (!File::makeDirectory(ROOT_PATH . self::$cfg->usericon_folder)) {
                             // ไดเรคทอรี่ไม่สามารถสร้างได้
                             $ret['ret_register_' . $item] = sprintf(Language::get('Directory %s cannot be created or is read-only.'), self::$cfg->usericon_folder);
                             $input = !$input ? 'ret_register_' . $item : $input;
                         } else {
                             if (!empty($user->icon)) {
                                 // ลบไฟล์เดิม
                                 @unlink(ROOT_PATH . self::$cfg->usericon_folder . $user->icon);
                             }
                             try {
                                 // อัปโหลด thumbnail
                                 $save['icon'] = $user->id . '.jpg';
                                 $file->cropImage(self::$cfg->user_icon_typies, ROOT_PATH . self::$cfg->usericon_folder . $save['icon'], self::$cfg->user_icon_w, self::$cfg->user_icon_h);
                             } catch (\Exception $exc) {
                                 // ไม่สามารถอัปโหลดได้
                                 $ret['ret_register_' . $item] = Language::get($exc->getMessage());
                                 $input = !$input ? 'ret_register_' . $item : $input;
                             }
                         }
                     }
                 }
                 if (!empty($save)) {
                     if (!$input) {
                         // save
                         $db->update($user_table, $user->id, $save);
                         // เปลี่ยน password ที่ login ใหม่
                         if (!empty($save['password'])) {
                             $_SESSION['login']['password'] = $password;
                         }
                         // คืนค่า
                         $ret['alert'] = Language::get('Saved successfully');
                         $ret['location'] = 'index.php?module=editprofile&tab=' . $request->post('tab')->toString();
                     } else {
                         // error
                         $ret['input'] = $input;
                     }
                 }
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     // คืนค่าเป็น JSON
     if (!empty($ret)) {
         echo json_encode($ret);
     }
 }
 public function chklogin(Request $request)
 {
     $data = $request->post('data')->toString();
     if (!empty($data) && $request->initSession() && $request->isSafe()) {
         // สุ่มรหัสผ่านใหม่
         $login_password = Text::rndname(6);
         // ข้อมูลที่ส่งมา
         $facebook_data = array();
         foreach (explode('&', $data) as $item) {
             list($k, $v) = explode('=', $item);
             if ($k === 'gender') {
                 $facebook_data['sex'] = $v === 'male' ? 'm' : 'f';
             } elseif ($k === 'link') {
                 $facebook_data['website'] = str_replace(array('http://', 'https://', 'www.'), '', $v);
             } elseif ($k === 'first_name') {
                 $facebook_data['fname'] = $v;
                 $facebook_data['displayname'] = $v;
             } elseif ($k === 'last_name') {
                 $facebook_data['lname'] = $v;
             } elseif ($k === 'email') {
                 $facebook_data['email'] = $v;
             } elseif ($k === 'id') {
                 $fb_id = $v;
             } elseif ($k === 'birthday' && preg_match('/^([0-9]+)[\\/\\-]([0-9]+)[\\/\\-]([0-9]+)$/', $v, $match)) {
                 $facebook_data['birthday'] = "{$match['3']}-{$match['1']}-{$match['2']}";
             }
         }
         // ไม่มีอีเมล์ ใช้ id ของ Facebook
         if (empty($facebook_data['email'])) {
             $facebook_data['email'] = $fb_id;
         }
         // db
         $db = $this->db();
         // table
         $user_table = $this->getFullTableName('user');
         // ตรวจสอบสมาชิกกับ db
         $search = $db->createQuery()->from('user')->where(array('email', $facebook_data['email']), array('displayname', $facebook_data['displayname']), 'OR')->toArray()->first('id', 'email', 'visited', 'fb', 'website');
         if ($search === false) {
             // ยังไม่เคยลงทะเบียน, ลงทะเบียนใหม่
             $facebook_data['id'] = $db->getNextId($this->getTableName('user'));
             $facebook_data['fb'] = 1;
             $facebook_data['subscrib'] = 1;
             $facebook_data['visited'] = 0;
             $facebook_data['ip'] = $request->getClientIp();
             $facebook_data['password'] = md5($login_password . $facebook_data['email']);
             $facebook_data['lastvisited'] = time();
             $facebook_data['create_date'] = $facebook_data['lastvisited'];
             $facebook_data['icon'] = $facebook_data['id'] . '.jpg';
             $facebook_data['country'] = 'TH';
             $db->insert($user_table, $facebook_data);
         } elseif ($search['fb'] == 1) {
             // facebook เคยเยี่ยมชมแล้ว อัปเดทการเยี่ยมชม
             $facebook_data['visited'] = $search['visited'] + 1;
             $facebook_data['lastvisited'] = time();
             $facebook_data['ip'] = $request->getClientIp();
             $facebook_data['password'] = md5($login_password . $search['email']);
             $db->update($user_table, $search['id'], $facebook_data);
         } else {
             // ไม่สามารถ login ได้ เนื่องจากมี email อยู่ก่อนแล้ว
             $facebook_data = false;
             $ret['alert'] = str_replace(':name', Language::get('User'), Language::get('This :name is already registered'));
             $ret['isMember'] = 0;
         }
         if (is_array($facebook_data)) {
             // อัปเดท icon สมาชิก
             $data = @file_get_contents('https://graph.facebook.com/' . $fb_id . '/picture');
             if ($data) {
                 $f = @fopen(ROOT_PATH . self::$cfg->usericon_folder . $facebook_data['icon'], 'wb');
                 if ($f) {
                     fwrite($f, $data);
                     fclose($f);
                 }
             }
             // login
             $facebook_data['password'] = $login_password;
             $_SESSION['login'] = $facebook_data;
             // clear
             $request->removeToken();
             // reload
             $ret['isMember'] = 1;
             $u = $request->post('u')->toString();
             if (preg_match('/module=(do)?login/', $u) || preg_match('/(do)?login\\.html/', $u)) {
                 $ret['location'] = 'back';
             } else {
                 $ret['location'] = 'reload';
             }
         }
         // คืนค่าเป็น json
         echo json_encode($ret);
     }
 }
 /**
  * รับค่าจาก action
  */
 public function action(Request $request)
 {
     if ($request->initSession() && $request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] == 'demo' || !empty($login['fb'])) {
             echo Language::get('Unable to complete the transaction');
         } else {
             // รับค่าจากการ POST
             $action = $request->post('action')->toString();
             // id ที่ส่งมา
             if (preg_match_all('/,?([0-9]+),?/', $request->post('id')->toString(), $match)) {
                 // Model
                 $model = new \Kotchasan\Model();
                 // ตาราง user
                 $user_table = $model->getFullTableName('user');
                 if ($action === 'delete') {
                     // ลบไอคอนสมาชิก
                     $query = $model->db()->createQuery()->select('icon')->from('user')->where(array(array('id', $match[1]), array('id', '!=', 1), array('icon', '!=', '')));
                     foreach ($query->toArray()->execute() as $item) {
                         @unlink(ROOT_PATH . self::$cfg->usericon_folder . $item['icon']);
                     }
                     // ลบสมาชิก
                     $model->db()->delete($user_table, array(array('id', $match[1]), array('id', '!=', 1)), 0);
                 } elseif ($action === 'accept') {
                     // ยอมรับสมาชิกที่เลือก
                     $model->db()->update($user_table, array(array('id', $match[1]), array('fb', '0')), array('activatecode' => ''));
                 } elseif ($action === 'ban' || $action === 'unban') {
                     // ระงับ/ยกเลิก การใช้งานสมาชิก
                     $model->db()->update($user_table, array(array('id', $match[1]), array('id', '!=', 1)), array('ban' => $action == 'ban' ? 1 : 0));
                 } elseif ($action === 'activate' || $action === 'sendpassword') {
                     // ส่งอีเมล์ยืนยันสมาชิก
                     $query = $model->db()->createQuery()->select('id', 'email', 'activatecode')->from('user')->where(array(array('id', $match[1]), array('id', '!=', 1), array('fb', '0')));
                     $msgs = array();
                     foreach ($query->toArray()->execute() as $item) {
                         // รหัสผ่านใหม่
                         $password = Text::rndname(6);
                         // ข้อมูลอีเมล์
                         $replace = array('/%PASSWORD%/' => $password, '/%EMAIL%/' => $item['email']);
                         $save = array('password' => md5($password . $item['email']));
                         if ($action === 'activate' || !empty($item['activatecode'])) {
                             // activate หรือ ยังไม่ได้ activate
                             $save['activatecode'] = empty($item['activatecode']) ? Text::rndname(32) : $item['activatecode'];
                             $replace['/%ID%/'] = $save['activatecode'];
                             // send mail
                             $err = Email::send(1, 'member', $replace, $item['email']);
                         } else {
                             // send mail
                             $err = Email::send(3, 'member', $replace, $item['email']);
                         }
                         $msgs = array();
                         if (empty($err)) {
                             // อัปเดทรหัสผ่านใหม่
                             $model->db()->update($user_table, $item['id'], $save);
                         } else {
                             $msgs[] = $err;
                         }
                         if (empty($msgs)) {
                             // ส่งอีเมล์ สำเร็จ
                             echo Language::get('Your message was sent successfully');
                         } else {
                             // มีข้อผิดพลาด
                             echo implode("\n", $msgs);
                         }
                     }
                 } elseif ($request->post('module')->toString() === 'status') {
                     // เปลี่ยนสถานะสมาชิก
                     $model->db()->update($user_table, array(array('id', $match[1]), array('id', '!=', 1), array('fb', '0')), array('status' => (int) $action));
                 }
             }
         }
     }
 }
 /**
  * บันทึก
  */
 public function save(Request $request)
 {
     $ret = array();
     // referer, session, member
     if ($request->initSession() && $request->isReferer() && ($login = Login::isMember())) {
         if ($login['email'] == 'demo' || !empty($login['fb'])) {
             $ret['alert'] = Language::get('Unable to complete the transaction');
         } else {
             // รับค่าจากการ POST
             $save = array('email' => $request->post('register_email')->url(), 'displayname' => $request->post('register_displayname')->topic(), 'sex' => $request->post('register_sex')->topic(), 'website' => str_replace(array('http://', 'https://', 'ftp://'), array('', '', ''), $request->post('register_website')->url()), 'pname' => $request->post('register_pname')->topic(), 'fname' => $request->post('register_fname')->topic(), 'lname' => $request->post('register_lname')->topic(), 'company' => $request->post('register_company')->topic(), 'phone1' => $request->post('register_phone1')->number(), 'phone2' => $request->post('register_phone2')->number(), 'subscrib' => $request->post('register_subscrib')->toBoolean(), 'address1' => $request->post('register_address1')->topic(), 'address2' => $request->post('register_address2')->topic(), 'provinceID' => $request->post('register_provinceID')->number(), 'province' => $request->post('register_province')->topic(), 'zipcode' => $request->post('register_zipcode')->number(), 'country' => $request->post('register_country')->topic(), 'status' => $request->post('register_status')->toInt(), 'birthday' => $request->post('register_birthday')->date(), 'admin_access' => $request->post('register_admin_access')->toBoolean());
             // ชื่อตาราง user
             $user_table = $this->getFullTableName('user');
             // database connection
             $db = $this->db();
             // ตรวจสอบค่าที่ส่งมา
             $id = $request->post('register_id')->toInt();
             if ($id == 0) {
                 // ใหม่
                 $user = (object) array('id' => 0, 'email' => '', 'fb' => 0);
             } else {
                 // แก้ไข
                 $user = $db->first($user_table, $id);
             }
             if (!$user) {
                 // ไม่พบสมาชิกที่แก้ไข
                 $ret['alert'] = Language::get('not a registered user');
             } else {
                 $isAdmin = Login::isAdmin();
                 // ไม่ใช่แอดมิน ใช้อีเมล์เดิมจากฐานข้อมูล
                 if (!$isAdmin && $user->id > 0) {
                     $save['email'] = $user->email;
                 }
                 // ตรวจสอบค่าที่ส่งมา
                 $input = false;
                 $requirePassword = false;
                 // อีเมล์
                 if (empty($save['email'])) {
                     $ret['ret_register_email'] = 'this';
                     $input = !$input ? 'register_email' : $input;
                 } else {
                     // ตรวจสอบอีเมล์ซ้ำ
                     $search = $db->first($user_table, array('email', $save['email']));
                     if ($search !== false && $user->id != $search->id) {
                         $ret['ret_register_email'] = str_replace(':name', Language::get('Email'), Language::get('This :name is already registered'));
                         $input = !$input ? 'register_email' : $input;
                     } else {
                         $requirePassword = $user->email !== $save['email'];
                         $ret['ret_register_email'] = '';
                     }
                 }
                 // ชื่อเรียก
                 if (!empty($save['displayname'])) {
                     // ตรวจสอบ ชื่อเรียก
                     $search = $db->first($user_table, array('displayname', $save['displayname']));
                     if ($search !== false && $user->id != $search->id) {
                         $ret['ret_register_displayname'] = str_replace(':name', Language::get('Name'), Language::get('This :name is already registered'));
                         $input = !$input ? 'register_displayname' : $input;
                     } else {
                         $ret['ret_register_displayname'] = '';
                     }
                 }
                 // โทรศัพท์
                 if (!empty($save['phone1'])) {
                     if (!preg_match('/[0-9]{9,10}/', $save['phone1'])) {
                         $ret['ret_register_phone1'] = str_replace(':name', Language::get('phone number'), Language::get('Invalid :name'));
                         $input = !$input ? 'register_phone1' : $input;
                     } else {
                         // ตรวจสอบโทรศัพท์
                         $search = $db->first($user_table, array('phone1', $save['phone1']));
                         if ($search !== false && $user->id != $search->id) {
                             $ret['ret_register_phone1'] = str_replace(':name', Language::get('phone number'), Language::get('This :name is already registered'));
                             $input = !$input ? 'register_phone1' : $input;
                         } else {
                             $ret['ret_register_phone1'] = '';
                         }
                     }
                 }
                 // password
                 $password = $request->post('register_password')->topic();
                 $repassword = $request->post('register_repassword')->topic();
                 if (!empty($password) || !empty($repassword)) {
                     if (mb_strlen($password) < 4) {
                         // รหัสผ่านต้องไม่น้อยกว่า 4 ตัวอักษร
                         $ret['ret_register_password'] = '******';
                         $input = !$input ? 'register_password' : $input;
                     } elseif ($repassword != $password) {
                         // ถ้าต้องการเปลี่ยนรหัสผ่าน กรุณากรอกรหัสผ่านสองช่องให้ตรงกัน
                         $ret['ret_register_repassword'] = '******';
                         $input = !$input ? 'register_repassword' : $input;
                     } else {
                         $ret['ret_register_password'] = '';
                         $ret['ret_register_repassword'] = '';
                         $save['password'] = md5($password . $save['email']);
                         $requirePassword = false;
                     }
                 }
                 // มีการเปลี่ยน email ต้องการรหัสผ่าน
                 if (!$input && $requirePassword) {
                     $ret['ret_register_password'] = '******';
                     $input = !$input ? 'register_password' : $input;
                 }
                 // อัปโหลดไฟล์
                 foreach ($request->getUploadedFiles() as $item => $file) {
                     if ($file->hasUploadFile()) {
                         if (!File::makeDirectory(ROOT_PATH . self::$cfg->usericon_folder)) {
                             // ไดเรคทอรี่ไม่สามารถสร้างได้
                             $ret['ret_' . $item] = sprintf(Language::get('Directory %s cannot be created or is read-only.'), self::$cfg->usericon_folder);
                             $input = !$input ? $item : $input;
                         } else {
                             if (!empty($user->icon)) {
                                 // ลบไฟล์เดิม
                                 @unlink(ROOT_PATH . self::$cfg->usericon_folder . $user->icon);
                             }
                             try {
                                 // อัปโหลด thumbnail
                                 $save['icon'] = $user->id . '.jpg';
                                 $file->cropImage(self::$cfg->user_icon_typies, ROOT_PATH . self::$cfg->usericon_folder . $save['icon'], self::$cfg->user_icon_w, self::$cfg->user_icon_h);
                             } catch (\Exception $exc) {
                                 // ไม่สามารถอัปโหลดได้
                                 $ret['ret_' . $item] = Language::get($exc->getMessage());
                                 $input = !$input ? $item : $input;
                             }
                         }
                     }
                 }
                 if (!$input) {
                     // ไม่ใช่แอดมิน
                     if (!$isAdmin) {
                         unset($save['status']);
                         unset($save['point']);
                         unset($save['admin_access']);
                     }
                     // social ห้ามแก้ไข
                     if (!empty($user->fb)) {
                         unset($save['email']);
                         unset($save['password']);
                     }
                     if ($login['id'] == $id || $id == 1) {
                         unset($save['admin_access']);
                     }
                     // บันทึก
                     if ($id == 0) {
                         // ใหม่
                         $id = $db->insert($user_table, $save);
                         // ไปหน้ารายการสมาชิก
                         $ret['location'] = $request->getUri()->postBack('index.php', array('module' => 'member', 'id' => null, 'page' => null));
                     } else {
                         // แก้ไข
                         $db->update($user_table, $id, $save);
                         if ($login['id'] == $id) {
                             // ตัวเอง
                             if (isset($save['password'])) {
                                 if (isset($save['email'])) {
                                     $_SESSION['login']['email'] = $save['email'];
                                 }
                                 $_SESSION['login']['password'] = $password;
                             }
                             // reload หน้าเว็บ
                             $ret['location'] = 'reload';
                         } else {
                             // กลับไปหน้าก่อนหน้า
                             $ret['location'] = $request->getUri()->postBack('index.php', array('id' => null));
                         }
                     }
                     // คืนค่า
                     $ret['alert'] = Language::get('Saved successfully');
                 } else {
                     // error
                     $ret['input'] = $input;
                 }
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     // คืนค่าเป็น JSON
     if (!empty($ret)) {
         echo json_encode($ret);
     }
 }
Example #28
0
 /**
  * แสดงผล index.html
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // ตัวแปรป้องกันการเรียกหน้าเพจโดยตรง
     define('MAIN_INIT', __FILE__);
     // session cookie
     $request->initSession();
     // ตรวจสอบการ login
     Login::create();
     // กำหนด skin ให้กับ template
     self::$cfg->skin = $request->get('skin', self::$request->session('skin', self::$cfg->skin)->toString())->toString();
     self::$cfg->skin = is_file(ROOT_PATH . 'skin/' . self::$cfg->skin . '/style.css') ? self::$cfg->skin : 'bighead';
     $_SESSION['skin'] = self::$cfg->skin;
     Template::init(self::$cfg->skin);
     // ตรวจสอบหน้าที่จะแสดง
     if (!empty(self::$cfg->maintenance_mode) && !Login::isAdmin()) {
         Gcms::$view = new \Index\Maintenance\View();
     } elseif (!empty(self::$cfg->show_intro) && str_replace(array(BASE_PATH, '/'), '', $request->getUri()->getPath()) == '') {
         Gcms::$view = new \Index\Intro\View();
     } else {
         // counter และ useronline
         $new_day = \Index\Counter\Model::init();
         // View
         Gcms::$view = new \Gcms\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();
                 }
             }
             if ($new_day && is_file($dir . $owner . '/controllers/cron.php')) {
                 include $dir . $owner . '/controllers/cron.php';
                 $class = ucfirst($owner) . '\\Cron\\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');
         }
         // ตรวจสอบโมดูลที่เรียก
         $modules = \Index\Module\Controller::get($request->getQueryParams());
         if (!empty($modules)) {
             // โหลดโมดูลที่เรียก
             $page = createClass($modules->className)->{$modules->method}($request, $modules->module);
         }
         if (empty($page)) {
             // ไม่พบหน้าที่เรียก (index)
             $page = createClass('Index\\PageNotFound\\Controller')->init($request, 'index');
         }
         // title ของเว็บไซต์
         $web_title = strip_tags($page->topic);
         // meta tag
         $meta = array('generator' => '<meta name=generator content="GCMS AJAX CMS design by http://gcms.in.th">', 'og:title' => '<meta property="og:title" content="' . $web_title . '">', 'description' => '<meta name=description content="' . $page->description . '">', 'keywords' => '<meta name=keywords content="' . $page->keywords . '">', 'og:site_name' => '<meta property="og:site_name" content="' . $web_title . '">', 'og:type' => '<meta property="og:type" content="article">');
         // โมดูลแรกสุด ใส่ลงใน Javascript
         $module_list = array_keys(Gcms::$install_modules);
         $script = array('var FIRST_MODULE = "' . reset($module_list) . '";');
         // logo
         $image_logo = '';
         if (!empty(self::$cfg->logo) && is_file(ROOT_PATH . DATA_FOLDER . 'image/' . self::$cfg->logo)) {
             $image_src = WEB_URL . DATA_FOLDER . 'image/' . self::$cfg->logo;
             $info = getImageSize(ROOT_PATH . DATA_FOLDER . 'image/' . self::$cfg->logo);
             if ($info[0] > 0 || $info[1] > 0) {
                 $ext = explode('.', self::$cfg->logo);
                 if (strtolower(end($ext)) == 'swf') {
                     $script[] = '$G(window).Ready(function(){';
                     $script[] = 'if ($E("logo")) {';
                     $script[] = "new GMedia('logo_swf', '" . $image_src . "', {$info['0']}, {$info['1']}).write('logo');";
                     $script[] = '}';
                     $script[] = '});';
                 } else {
                     $image_logo = '<img src="' . $image_src . '" alt="{WEBTITLE}">';
                 }
             }
         }
         if (empty($page->image_src)) {
             if (is_file(ROOT_PATH . DATA_FOLDER . 'image/facebook_photo.jpg')) {
                 $page->image_src = WEB_URL . DATA_FOLDER . 'image/facebook_photo.jpg';
             }
         } elseif (!empty($image_src)) {
             $page->image_src = $image_src;
         }
         if (!empty($page->image_src)) {
             $meta['image_src'] = '<link rel=image_src href="' . $page->image_src . '">';
             $meta['og:image'] = '<meta property="og:image" content="' . $page->image_src . '">';
         }
         if (!empty(self::$cfg->facebook_appId)) {
             $meta['og:app_id'] = '<meta property="fb:app_id" content="' . self::$cfg->facebook_appId . '">';
         }
         if (isset($page->canonical)) {
             $meta['canonical'] = '<meta name=canonical content="' . $page->canonical . '">';
             $meta['og:url'] = '<meta property="og:url" content="' . $page->canonical . '">';
         }
         $meta['script'] = "<script>\n" . implode("\n", $script) . "\n</script>";
         Gcms::$view->setMetas($meta);
         // ภาษาที่ติดตั้ง
         $languages = Template::create('', '', 'language');
         foreach (self::$cfg->languages as $lng) {
             $languages->add(array('/{LNG}/' => $lng));
         }
         // เมนูหลัก
         Gcms::$view->setContents(Gcms::$menu->render(isset($page->menu) ? $page->menu : $page->module));
         // เนื้อหา
         Gcms::$view->setContents(array('/{CONTENT}/' => $page->detail, '/{TITLE}/' => $web_title, '/{LANGUAGES}/' => $languages->render(), '/{LOGO}/' => $image_logo));
     }
     // ส่งออก เป็น HTML
     $response = new Response();
     $response->withContent(Gcms::$view->renderHTML())->send();
 }
Example #29
0
 /**
  * แสดงผล
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     $action = $request->get('action', 'hello')->username();
     $this->{$action}();
 }
 /**
  * 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);
     }
 }