function query_content($args = array()) { global $hmcontent; $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET); hook_filter('before_query_content', $args); hook_action('query_content'); if (!is_array($args)) { parse_str($args, $args); } /** Lọc theo content_key */ if (isset($args['content_key'])) { /** Nếu yêu cầu content key thì lấy các id có key như query yêu cầu */ $content_key = $args['content_key']; /** Nếu content key là một mảng */ if (is_array($content_key)) { $where_key = ''; $i = 0; foreach ($content_key as $key) { if ($i == 0) { $where_key .= " `key` = '" . $key . "' "; } else { $where_key .= " OR `key` = '" . $key . "' "; } $i++; } $where_content_key = "WHERE " . $where_key; } else { $where_content_key = "WHERE `key` = '" . $content_key . "'"; } } else { /** Không yêu cầu content key, kiểm tra xem có đang ở template taxonomy không */ if (is_taxonomy() == TRUE) { $taxonomy_id = get_id(); $content_key = taxonomy_get_content_key($taxonomy_id); if ($content_key != FALSE) { $where_content_key = "WHERE `key` = '" . $content_key . "'"; } } else { $where_content_key = ''; } } $hmdb->Release(); $query_content_key = "SELECT `id` FROM `" . DB_PREFIX . "content` " . $where_content_key; /** Lọc theo taxonomy */ $where_taxonomy = ''; if (isset($args['taxonomy'])) { /** Nếu yêu cầu trong một taxonomy nhất định thì lấy các object_id có relationship như query yêu cầu */ $taxonomy_id = $args['taxonomy']; /** Nếu taxonomy là một mảng */ if (is_array($taxonomy_id)) { $implode = implode($taxonomy_id, ','); if ($implode != '') { $where_taxonomy = ' WHERE `target_id` IN (' . $implode . ') '; } } else { $where_taxonomy = 'WHERE `target_id` = ' . $taxonomy_id; } } else { /** Không yêu cầu taxonomy nhất định, kiểm tra xem có đang ở template taxonomy không */ if (is_taxonomy() == TRUE) { $taxonomy_id = get_id(); $where_taxonomy = 'WHERE `target_id` = ' . $taxonomy_id; } } if ($where_taxonomy != '') { $hmdb->Release(); $query_in_taxonomy = "SELECT `object_id` FROM `" . DB_PREFIX . "relationship` " . $where_taxonomy . " AND `relationship` = 'contax'"; } /** Lọc theo field */ if (isset($args['field_query'])) { $field_query = $args['field_query']; } else { $field_query = array(array('field' => 'status', 'compare' => '=', 'value' => 'public'), array('field' => 'public_time', 'compare' => '<=', 'value' => time())); } $all_field_query = array(); foreach ($field_query as $item) { /** check đủ điều kiện tạo field query */ if (isset($item['field']) and isset($item['compare']) and isset($item['value'])) { $field = $item['field']; $compare = $item['compare']; $value = $item['value']; $numerically = FALSE; /** build query */ if (is_numeric($value)) { $value_query = $value; } else { $value_query = "'{$value}'"; } if ($compare == 'like%') { $all_field_query[$field] = " ( `name` = '{$field}' AND `val` LIKE '%{$value}%' )"; } else { $all_field_query[$field] = " ( `name` = '{$field}' AND `val` {$compare} {$value_query} )"; } } } /** nếu size của mảng chứa các kết quả của các field query >= 2 */ $size = sizeof($all_field_query); $query_field = "SELECT `object_id` FROM `" . DB_PREFIX . "field` WHERE"; if ($size > 1) { if (isset($args['field_query_relation'])) { $field_query_relation = $args['field_query_relation']; } else { $field_query_relation = 'and'; } switch ($field_query_relation) { case 'or': $i = 0; foreach ($all_field_query as $single_field_query) { if ($i == 0) { $query_field .= " " . $single_field_query . " "; } else { $query_field .= " OR " . $single_field_query . " "; } $i++; } break; case 'and': $i = 0; foreach ($all_field_query as $single_field_query) { if ($i == 0) { $query_field .= " " . $single_field_query . " "; } else { $query_field .= " OR " . $single_field_query . " "; } $i++; } $query_field .= " GROUP BY `object_id` HAVING COUNT(*) = {$size} "; break; } /** * Đưa ra kết quả dựa trên mối quan hệ giữa các field query ( field_query_relation ) * ( thỏa mãn tất cả các field query hay chỉ cần đáp ứng được 1 trong những field query ) */ } else { $query_field = $query_field . array_shift(array_values($all_field_query)); } /** Kiểm tra yêu cầu kết hợp kết quả từ content key, in taxonomy, field query là tất cả hay chỉ 1 */ if (isset($args['join'])) { $join = $args['join']; } else { $join = 'and'; } $query_join = ''; switch ($join) { case 'or': if ($query_content_key) { $query_join .= " AND `object_id` IN (" . $query_content_key . ") "; } if ($query_in_taxonomy) { $query_join .= " OR `object_id` IN (" . $query_in_taxonomy . ") "; } $query_join .= " OR `object_id` IN (" . $query_field . ") "; break; case 'and': if ($query_content_key) { $query_join .= " AND `object_id` IN (" . $query_content_key . ") "; } if ($query_in_taxonomy) { $query_join .= " AND `object_id` IN (" . $query_in_taxonomy . ") "; } $query_join .= " AND `object_id` IN (" . $query_field . ") "; break; default: if ($query_content_key) { $query_join .= " AND `object_id` IN (" . $query_content_key . ") "; } if ($query_in_taxonomy) { $query_join .= " AND `object_id` IN (" . $query_in_taxonomy . ") "; } $query_join .= " AND `object_id` IN (" . $query_field . ") "; } /** Kết thúc các query lấy các content id thỏa mãn yêu cầu */ /** Order theo 1 field và limit */ if (isset($args['order'])) { $order_by = $args['order']; } else { $order_by = 'public_time,desc,number'; } if (isset($args['limit'])) { $limit = $args['limit']; } else { $limit = get_option(array('section' => 'system_setting', 'key' => 'post_per_page', 'default_value' => '12')); } if (isset($args['offset']) and is_numeric($args['offset'])) { $offset = $args['offset']; } else { $offset = 0; } if (isset($args['paged'])) { $paged = $args['paged']; } else { $paged = get_current_pagination(); } $paged = $paged - 1; if ($paged < 0) { $paged = 0; } /** Tạo query ORDER */ $ex = explode(',', $order_by); $ex = array_map("trim", $ex); $order_field = $ex[0]; $order = strtoupper($ex[1]); if (isset($ex[2])) { $numerically = $ex[2]; } else { $numerically = FALSE; } if ($numerically == 'number') { $order_query = " AND `name` = '" . $order_field . "' ORDER BY CAST(val AS unsigned) " . $order . " "; } else { $order_query = " AND `name` = '" . $order_field . "' ORDER BY `val` " . $order . " "; } /** Tạo query LIMIT */ if (is_numeric($limit)) { $limit_query = " LIMIT {$limit} "; } else { $limit_query = ''; } /** Tạo query OFFSET */ if ($limit == FALSE) { $offset_query = ''; } else { $offset_query_page = $paged * $limit; $offset_query_page = $offset_query_page + $offset; $offset_query = " OFFSET {$offset_query_page} "; } /** Tạo câu lệnh select từ chuỗi các id thỏa mãn */ $result = array(); $sql = "SELECT `object_id`" . " FROM `" . DB_PREFIX . "field`" . " WHERE `object_type` = 'content'" . " " . $query_join . " " . " " . $order_query . " "; $hmdb->Query($sql); $total_result = $hmdb->RowCount(); $sql = "SELECT `object_id`" . " FROM `" . DB_PREFIX . "field`" . " WHERE `object_type` = 'content'" . " " . $query_join . " " . " " . $order_query . " " . $limit_query . " " . $offset_query . " "; $hmdb->Query($sql); $base = get_current_uri(); if ($base == '') { $base = '/'; } $hmcontent->set_val(array('key' => 'total_result', 'val' => $total_result)); $hmcontent->set_val(array('key' => 'paged', 'val' => $paged + 1)); $hmcontent->set_val(array('key' => 'perpage', 'val' => $limit)); $hmcontent->set_val(array('key' => 'base', 'val' => $base)); while ($row = $hmdb->Row()) { $result[] = $row->object_id; } return $result; }
return $this->get_menu($args); } /** Hiển thị 1 menu */ public function get_menu($args = array()) { /** kiếm tra và add giá trị mặc định */ if (isset($args['parent'])) { $parent = $args['parent']; } else { $parent = FALSE; } if (isset($args['wrapper'])) { $wrapper = $args['wrapper']; } else { $wrapper = 'ul'; } if (isset($args['wrapper_class'])) { $wrapper_class = $args['wrapper_class']; } else { $wrapper_class = FALSE; } if (isset($args['wrapper_id'])) { $wrapper_id = $args['wrapper_id']; } else { $wrapper_id = FALSE; } if (isset($args['item'])) { $item = $args['item']; } else { $item = 'li'; } if (isset($args['item_class'])) { $item_class = $args['item_class']; } else { $item_class = ''; } if (isset($args['item_id'])) { $item_id = $args['item_id']; } else { $item_id = ''; } if (isset($args['permalink_class'])) { $permalink_class = $args['permalink_class']; } else { $permalink_class = ''; } if (isset($args['permalink_attr'])) { $permalink_attr = $args['permalink_attr']; } else { $permalink_attr = ''; } if (isset($args['permalink_before'])) { $permalink_before = $args['permalink_before']; } else { $permalink_before = ''; } if (isset($args['permalink_after'])) { $permalink_after = $args['permalink_after']; } else { $permalink_after = ''; } if (isset($args['echo'])) { $echo = $args['echo']; } else { $echo = TRUE; } $name = $args['name']; if (is_numeric($parent)) { $menu_id = $parent; } else { $menu_id = get_option('section=theme_setting&key=' . $name); } $output_html = ''; /** wrapper_class */ if ($wrapper_class) { $wrapper_class = ' class="' . $wrapper_class . '"'; } /** wrapper_id */ if ($wrapper_id) { $wrapper_id = ' id="' . $wrapper_id . '"'; } /** open wrapper */ $output_html .= '<' . $wrapper . $wrapper_class . $wrapper_id . '>' . "\n"; /** load menu item */ $tableName = DB_PREFIX . "object"; $whereArray = array('parent' => MySQL::SQLValue($menu_id), 'key' => MySQL::SQLValue('menu_item')); $this->SelectRows($tableName, $whereArray, NULL, 'order_number', 'ASC'); while ($row = $this->Row()) { $menu_item[] = $row; } /** menu item */ foreach ($menu_item as $this_menu_item) { $id = $this_menu_item->id; $menu_name = get_men_val(array('name' => 'menu_name', 'id' => $id)); $menu_class = get_men_val(array('name' => 'menu_class', 'id' => $id)); $menu_attr = get_men_val(array('name' => 'menu_attr', 'id' => $id)); $menu_icon = get_men_val(array('name' => 'menu_icon', 'id' => $id)); $menu_request_uri = get_men_val(array('name' => 'menu_request_uri', 'id' => $id)); if ($menu_attr != '') { $menu_attr = ' ' . $menu_attr; } if ($menu_class != '') { $menu_class = ' ' . $menu_class; } /** item href */ if (is_numeric($menu_request_uri)) { $data_uri = get_uri_data("id={$menu_request_uri}"); $href = SITE_URL . FOLDER_PATH . $data_uri->uri; $object_type = $data_uri->object_type; $object_id = $data_uri->object_id; $menu_request_uri_html = ' href="' . $href . '"'; $data_object_html = ' data-' . $object_type . '="' . $object_id . '"'; } else { $menu_request_uri_html = ' href="#"'; $data_object_html = ''; $object_type = FALSE; $object_id = FALSE; } /** item_class */ $in_page_class = ''; if (is_taxonomy()) { $current_uri = get_current_uri(); $data_current_uri = get_uri_data("uri={$current_uri}"); $current_object_id = $data_current_uri->object_id; if ($object_type == 'taxonomy' and $object_id == $current_object_id) { $in_page_class = ' current_page'; } } if ($item_class) { $item_class_html = ' class="' . $item_class . $in_page_class . ' menu-' . $id . '"'; } else { $item_class_html = ' class="menu-' . $id . $in_page_class . '"'; } /** item_id */ if ($item_id) { $item_id_html = ' id="' . $item_id . ' menu-' . $id . '"'; } else { $item_id_html = ' id="menu-' . $id . '"'; } /** open item */ $output_html .= '<' . $item . $item_class_html . $item_id_html . $data_object_html . '>' . "\n"; /** permalink before */ $output_html .= $permalink_before; /** permalink_class */ if ($permalink_class) { $permalink_class_html = ' class="' . $permalink_class . $menu_class . '"'; } else { $permalink_class_html = ''; } /** permalink */ $output_html .= '<a' . $menu_request_uri_html . $menu_attr . $permalink_class_html . '>' . $menu_name . '</a>' . "\n"; /** permalink after */ $output_html .= $permalink_after; /** sub menu */ if ($this->has_sub_menu($id)) { $args['parent'] = $id; $args['echo'] = FALSE; $args['wrapper_class'] = 'sub-menu'; $args['wrapper_id'] = ''; $output_html .= $this->get_menu($args); } /** close item */ $output_html .= '</' . $item . '>' . "\n"; } /** close wrapper */ $output_html .= '</' . $wrapper . '>' . "\n"; if ($echo == TRUE) { echo $output_html; } else { return $output_html;
function hm_title() { hook_action('before_hm_title'); global $hmcontent; global $hmtaxonomy; $request = get_current_uri(); $request_data = get_uri_data(array('uri' => $request)); if ($request == '') { $home_title = get_option(array('section' => 'system_setting', 'key' => 'website_name', 'default_value' => 'Một trang web sử dụng HoaMaiCMS')); if ($home_title != '') { $title = '<title>' . $home_title . '</title>' . "\n\r"; } else { $title = FALSE; } return hook_filter('hm_title', $title); } else { if ($request_data != FALSE) { $object_type = $request_data->object_type; $object_id = $request_data->object_id; switch ($object_type) { case 'content': $content_data = content_data_by_id($object_id); $title = $content_data['content']->name; $title = '<title>' . $title . '</title>' . "\n\r"; return hook_filter('hm_title', $title); break; case 'taxonomy': $taxonomy_data = taxonomy_data_by_id($object_id); $title = $taxonomy_data['taxonomy']->name; $title = '<title>' . $title . '</title>' . "\n\r"; return hook_filter('hm_title', $title); break; } } else { return FALSE; } } hook_action('after_hm_title'); }
// 载入框架核心函数库 require BOMB . 'core' . DS . 'core.fn.php'; // 载入框架数据库操作函数 require BOMB . 'core' . DS . 'db.fn.php'; // 载入程序全局函数(程序公用函数库) require APP . 'funcs' . DS . 'app.fn.php'; // 取消自动转义 transcribe(); // 如果用户没有设置site_domain,则自动配置生成site_domain if (!($site_domain = conf('app', 'site_domain'))) { $GLOBALS['app']['site_domain'] = gen_site_domain(); } // 获取当前请求URL $GLOBALS['request']['url'] = get_current_url(); // 获取请求URI $GLOBALS['request']['uri'] = get_current_uri(); // 解析URI,如果不存在则响应404 if (!parse_uri($GLOBALS['request']['uri'])) { show_404(); } // 挂载钩子 mount_hooks($GLOBALS['request']['uri']); /** * base controller */ abstract class _Control { public function __construct() { } }
function hm_seo_display_meta_keywords() { global $hmcontent; global $hmtaxonomy; $request = get_current_uri(); $request_data = get_uri_data(array('uri' => $request)); if ($request_data != FALSE) { $object_type = $request_data->object_type; $object_id = $request_data->object_id; switch ($object_type) { case 'content': $keywords = get_con_val("name=meta_keywords&id=" . $object_id); echo '<meta name="keywords" content="' . $keywords . '" />' . "\n\r"; break; case 'taxonomy': $keywords = get_tax_val("name=meta_keywords&id=" . $object_id); echo '<meta name="keywords" content="' . $keywords . '" />' . "\n\r"; break; } } else { return FALSE; } }
<?php /** * Đây là tệp tin xử lý đường dẫn * Vị trí : /hm_routing.php */ if (!defined('BASEPATH')) { exit('403'); } /** Lấy uri trang đang xem */ $request_slug = get_current_uri(); $segments = explode('/', $request_slug); /** Kiểm tra segments 1 có phải là 1 module */ $modules = $hmmodule->hmmodule; if ($segments[0] == HM_ADMINCP_DIR and $segments[1] == '') { /** Admin cp */ require_once BASEPATH . HM_ADMINCP_DIR . '/index.php'; } elseif (isset($modules[$module_key])) { /** Module */ $module = $modules[$module_key]; if (is_array($module)) { $module_name = $module['module_name']; $module_key = $module['module_key']; $module_dir = $module['module_dir']; $module_index = $module['module_index']; if (file_exists(BASEPATH . HM_MODULE_DIR . '/' . $module_dir . '/' . $module_index)) { require_once BASEPATH . HM_MODULE_DIR . '/' . $module_dir . '/' . $module_index; } else { hm_exit('Không tìm thấy file "' . $module_index . '" của module "' . $module_key . '"'); } } else {