예제 #1
0
 /**
  * แสดงผล
  *
  * @param object $index ข้อมูลโมดูล
  */
 public function render($index)
 {
     // template main.html, home/main.html
     $template = Template::create('', $index->module, 'main');
     // canonical
     $index->canonical = Gcms::createUrl($index->module);
     // add template
     $template->add(array('/{DETAIL}/' => Gcms::showDetail($index->detail, true, false), '/{TOPIC}/' => $index->topic, '/{MODULE}/' => $index->module));
     // detail
     $index->detail = $template->render();
     // breadcrumb ของหน้า
     Gcms::$view->addBreadcrumb($index->canonical, $index->topic, $index->description);
     return $index;
 }
예제 #2
0
 /**
  * แสดงผล
  *
  * @param object $index ข้อมูลโมดูล
  */
 public function render($index)
 {
     // รายการ
     $listitem = Grid::create('search', 'search', 'searchitem');
     foreach ($index->items as $item) {
         if ($item->index == 0 && $item->owner == 'document') {
             // document
             $uri1 = \Document\Index\Controller::url($item->module, $item->alias, $item->id);
             $uri2 = \Document\Index\Controller::url($item->module, $item->alias, $item->id, false);
         } elseif ($item->index == 0 && $item->owner == 'board') {
             // board
             $uri1 = \Board\Index\Controller::url($item->module, 0, $item->id);
             $uri2 = $uri1;
         } else {
             // other
             if (self::$cfg->module_url == 1) {
                 $uri1 = Gcms::createUrl($item->module, $item->alias);
                 $uri2 = Gcms::createUrl($item->module, $item->alias, 0, 0, '', false);
             } else {
                 $uri1 = Gcms::createUrl($item->module, '', 0, $item->id, '');
                 $uri2 = $uri1;
             }
         }
         $listitem->add(array('/{URL}/' => $uri1, '/{TOPIC}/' => $item->topic, '/{LINK}/' => $uri2, '/{DETAIL}/' => $item->description));
     }
     // template search/search.html
     $template = Template::create('search', 'search', 'search');
     // canonical
     $index->canonical = Gcms::createUrl($index->module);
     // current URL
     $uri = \Kotchasan\Http\Uri::createFromUri($index->canonical);
     if ($index->total > 0) {
         $list = Gcms::highlightSearch($listitem->render(), $index->q);
     } else {
         $list = $index->q == '' ? '' : '<div>' . Language::get('No results were found for') . ' <strong>' . $index->q . '</strong></div>';
         $list .= '<div><strong>' . Language::get('Search tips') . ' :</strong>' . Language::get('<ul><li>make sure that the spelling correct</li><li>try changing or new phrases. synonyms</li><li>try to identify a non-specific too</li><li>specific keywords to search the most concise</li></ul>') . '</div>';
     }
     // add template
     $template->add(array('/{LIST}/' => $list, '/{SPLITPAGE}/' => $uri->pagination($index->totalpage, $index->page), '/{SEARCH}/' => $index->q, '/{MODULE}/' => 'search', '/{RESULT}/' => $index->total == 0 ? '' : sprintf(Language::get('Search results <strong>%d - %d</strong> of about <strong>%d</strong> for <strong>%s</strong> (%s sec)'), $index->start + 1, $index->end, $index->total, $index->q, number_format(microtime(true) - REQUEST_TIME, 4))));
     $search = Language::get('Search');
     $index->detail = $template->render();
     $index->topic = ($index->q == '' ? '' : $index->q . ' - ') . $search;
     $index->description = $index->topic;
     $index->keywords = $index->topic;
     $index->menu = 'search';
     // breadcrumb ของหน้า
     Gcms::$view->addBreadcrumb($index->canonical, $search, $search);
     return $index;
 }
예제 #3
0
 /**
  * แสดงผล sitemap.xml
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // ตัวแปรป้องกันการเรียกหน้าเพจโดยตรง
     define('MAIN_INIT', __FILE__);
     // create Response
     $response = new Response();
     // XML
     $content = '<' . '?xml version="1.0" encoding="UTF-8"?' . '>';
     $content .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
     $content .= ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"';
     $content .= ' xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9';
     $content .= ' http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
     // วันนี้
     $cdate = date('Y-m-d');
     // view
     $view = new \Index\Sitemap\View();
     // หน้าหลัก
     $content .= $view->render(WEB_URL . 'index.php', $cdate);
     // โมดูลที่ติดตั้งแล้ว
     $modules = array();
     $owners = array();
     foreach (\Index\Sitemap\Model::getModules() as $item) {
         $modules[$item->id] = $item->module;
         $owners[$item->owner][] = $item->id;
         $content .= $view->render(Gcms::createUrl($item->module, '', 0, 0, $item->language == '' ? '' : 'lang=' . $item->language), $cdate);
     }
     // modules
     $dir = ROOT_PATH . 'modules/';
     $f = @opendir($dir);
     if ($f) {
         while (false !== ($owner = readdir($f))) {
             if ($owner != '.' && $owner != '..' && $owner != 'index') {
                 if (is_file($dir . $owner . '/controllers/sitemap.php')) {
                     include $dir . $owner . '/controllers/sitemap.php';
                     foreach (createClass(ucfirst($owner) . '\\Sitemap\\Controller')->init($owners[$owner], $modules, $cdate) as $item) {
                         $content .= $view->render($item->url, $item->date);
                     }
                 }
             }
         }
         closedir($f);
     }
     $content .= '</urlset>';
     // send Response
     $response->withContent($content)->withHeader('Content-Type', 'application/xml; charset=UTF-8')->send();
 }
예제 #4
0
 /**
  * ฟังก์ชั่น แปลงเป็นรายการเมนู
  *
  * @param array $item แอเรย์ข้อมูลเมนู
  * @param string $select (optional) เมนูที่ถูกเลือก
  * @param boolean $arrow (optional) true=แสดงลูกศรสำหรับเมนูที่มีเมนูย่อย (default false)
  * @return string คืนค่า HTML ของเมนู
  */
 public function getItem($item, $select = null, $arrow = false)
 {
     $c = array();
     if ($item->alias != '') {
         $c[] = $item->alias;
         if ($select === $item->alias) {
             $c[] = 'select';
         }
     } elseif ($item->module != '') {
         $c[] = $item->module;
         if ($select === $item->module) {
             $c[] = 'select';
         }
     }
     if (isset($item->published)) {
         if ($item->published != 1) {
             if (Login::isMember()) {
                 if ($item->published == '3') {
                     $c[] = 'hidden';
                 }
             } else {
                 if ($item->published == '2') {
                     $c[] = 'hidden';
                 }
             }
         }
     }
     $c = sizeof($c) == 0 ? '' : ' class="' . implode(' ', $c) . '"';
     if ($item->index_id > 0 || $item->menu_url != '') {
         $a = $item->menu_target == '' ? '' : ' target=' . $item->menu_target;
         $a .= $item->accesskey == '' ? '' : ' accesskey=' . $item->accesskey;
         if ($item->index_id > 0) {
             $a .= ' href="' . Gcms::createUrl($item->module) . '"';
         } elseif ($item->menu_url != '') {
             $a .= ' href="' . $item->menu_url . '"';
         } else {
             $a .= ' tabindex=0';
         }
     } else {
         $a = ' tabindex=0';
     }
     $menu_text = $item->menu_text;
     $b = $item->menu_tooltip == '' ? $menu_text : $item->menu_tooltip;
     if ($b != '') {
         $a .= ' title="' . $b . '"';
     }
     if ($arrow) {
         return '<li' . $c . '><a class=menu-arrow' . $a . '><span>' . (empty($menu_text) ? '&nbsp;' : htmlspecialchars_decode($menu_text)) . '</span></a>';
     } else {
         return '<li' . $c . '><a' . $a . '><span>' . (empty($menu_text) ? '&nbsp;' : htmlspecialchars_decode($menu_text)) . '</span></a>';
     }
 }