function chapter_show_data($id)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_action('chapter_show_data');
    if (!$hmdb->Query("SELECT * FROM " . DB_PREFIX . "content WHERE `status` = 'chapter' AND `parent` = '{$id}' ORDER BY id DESC")) {
        $hmdb->Kill();
    }
    $array_cha = array();
    while ($row = $hmdb->Row()) {
        $data_cha = content_data_by_id($row->id);
        $array_cha[] = array('id' => $row->id, 'name' => $row->name, 'slug' => $row->slug, 'public_time' => date('d-m-Y H:i', $data_cha['field']['public_time']));
    }
    $array['chapter'] = $array_cha;
    return hook_filter('chapter_show_data', json_encode($array, TRUE));
}
function request_suggest($key)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    global $hmtaxonomy;
    global $hmcontent;
    $return = '';
    $input_name = hm_post('input', '');
    $key = trim($key);
    $key = str_replace(' ', '-', $key);
    if ($key != '') {
        $tableName = DB_PREFIX . 'request_uri';
        $hmdb->Query("SELECT * FROM `" . $tableName . "` WHERE `uri` LIKE '%" . $key . "%' LIMIT 10");
        while ($row = $hmdb->Row()) {
            $id = $row->id;
            $object_id = $row->object_id;
            $object_type = $row->object_type;
            $uri = $row->uri;
            $suggest_label = '';
            $object_name = '';
            switch ($object_type) {
                case 'taxonomy':
                    $tax_data = taxonomy_data_by_id($object_id);
                    $tax_key = $tax_data['taxonomy']->key;
                    $taxonomy = $hmtaxonomy->hmtaxonomy;
                    $suggest_label = $taxonomy[$tax_key]['taxonomy_name'];
                    $object_name = get_tax_val('name=name&id=' . $object_id);
                    break;
                case 'content':
                    $con_data = content_data_by_id($object_id);
                    $con_key = $con_data['content']->key;
                    $content = $hmcontent->hmcontent;
                    $suggest_label = $content[$con_key]['content_name'];
                    $object_name = get_con_val('name=name&id=' . $object_id);
                    break;
            }
            $return .= '<li>';
            $return .= '<p data-id="' . $id . '" data-input="' . $input_name . '" data-name="' . $object_name . '" object_id="' . $object_id . '" object_type="' . $object_type . '">';
            $return .= '<span class="suggest_label">' . $suggest_label . ': </span><b>' . $object_name . '</b>';
            $return .= '</p>';
            $return .= '</li>';
        }
    }
    return $return;
}
                global $args;
                require_once BASEPATH . HM_ADMINCP_DIR . '/' . LAYOUT_DIR . '/' . 'chapter_view.php';
            }
        } else {
            /** Không tồn tại content có id như request, hiển thị giao diện 404 */
            function admin_content_page()
            {
                require_once BASEPATH . HM_ADMINCP_DIR . '/' . LAYOUT_DIR . '/' . 'admincp_404.php';
            }
        }
        break;
    case 'restore':
        break;
    default:
        if (isset_content_id($id)) {
            $args = content_data_by_id($id);
            /** Hiển thị các bản thay đổi của content có id như request */
            function admin_content_page()
            {
                global $args;
                require_once BASEPATH . HM_ADMINCP_DIR . '/' . LAYOUT_DIR . '/' . 'chapter_all.php';
            }
        } else {
            /** Không tồn tại content có id như request, hiển thị giao diện 404 */
            function admin_content_page()
            {
                require_once BASEPATH . HM_ADMINCP_DIR . '/' . LAYOUT_DIR . '/' . 'admincp_404.php';
            }
        }
}
/** fontend */
function content_ajax_add_chapter($id)
{
    global $hmcontent;
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_action('content_ajax_add_chapter');
    if (isset_content_id($id) == TRUE) {
        $args_con = content_data_by_id($id);
        $key = $args_con['content']->key;
        $args = array('content_key' => $key, 'parent' => $id, 'status' => 'chapter');
        return content_ajax_add($args);
    }
}
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');
}
 /** Tạo bản xem nội dung các field của 1 content */
 public function build_field_content_blockquote($args = array())
 {
     if (isset($args['id'])) {
         $id = $args['id'];
     } else {
         $id = NULL;
     }
     if (isset($args['default_value'])) {
         $default_value = $args['default_value'];
     } else {
         $default_value = array();
     }
     $return = array();
     if (isset_content_id($id)) {
         $data = content_data_by_id($id);
         $content_key = $data['content']->key;
         if ($this->isset_content(array('content_key' => $content_key))) {
             $content = $this->hmcontent;
             $i = 1;
             foreach ($content[$content_key]['content_field'] as $field) {
                 $return[$i]['field_name'] = $field['nice_name'];
                 if (isset($default_value[$field['name']])) {
                     $return[$i]['field_val'] = $default_value[$field['name']];
                 } else {
                     $return[$i]['field_val'] = get_con_val(array('name' => $field['name'], 'id' => $id));
                 }
                 $i++;
             }
         }
     }
     return $return;
 }