function search() { global $display; $catid = (int) Url::get('catid', 0); $total = (int) Url::get('total', 0); $page = (int) Url::get('page', 0); $tt = (int) Url::get('tt', 0); $keywords = Url::get('keywords'); require "./includes/sphinxapi.class.php"; EClassApi::getCats(); foreach (CGlobal::$allCategories as $value) { if ($value['parent_id'] == 0) { $cat_list[$value['id']] = $value['brief_name']; } } $category = $this->getCategory($keywords); foreach ($category as $row) { $row['brief_name'] = isset($cat_list[$row['level_1_category_id']]) && $cat_list[$row['level_1_category_id']] ? $cat_list[$row['level_1_category_id']] : "Khác"; $listCat[$row['level_1_category_id']] = array("level_1_category_id" => $row["level_1_category_id"], "brief_name" => $row['brief_name'], "count_ad" => $row['@count']); } $catActive = ''; $total_cat = 0; if ($listCat) { $catActive = $listCat[$catid]['brief_name']; $total_cat = count($listCat); } $i = 0; $allrecord = 0; $otherCat = ''; $cat_content = ""; foreach ($listCat as $cat) { $allrecord = $allrecord + $cat['count_ad']; } $display->add("cat_content", $cat_content); $display->add("CatActiveId", $catid); $display->add("catActive", $catActive); $display->add("listCat", $listCat); $display->add("allrecord", $allrecord); $display->add("total_cat", $total_cat); $pager = new Pager(); $limit = SEARCH_LIMIT; $pager->type = "search"; $pager->catid = $catid; $pager->total = $total; $pager->limit = $limit; $pager->page_param = 'page'; $pager->page = $page; $offset = $pager->get_offset(); $limit_from = $pager->limit_from(); $limit_to = $pager->limit_to(); //Sphinx search by Nova $q = $keywords; //$mode = SPH_MATCH_ALL; $mode = SPH_MATCH_EXTENDED2; //Init config $host = SPHINX_SERVER; $port = SPHINX_PORT; $index = 'enbac'; $filtervals = array(); //$ranker = SPH_RANK_PROXIMITY_BM25; $ranker = SPH_RANK_WORDCOUNT; $cl = new SphinxClient(); $cl->SetServer($host, $port); $cl->SetConnectTimeout(1); $cl->SetWeights(array(100, 1)); $cl->SetMatchMode($mode); $cl->SetFilter('level_1_category_id', array($catid)); $cl->SetFilter('status', array('1')); $cl->SetFieldWeights(array('user_name' => 10000, 'name' => 1000, 'description' => 1)); //$cl->SetSortMode( SPH_SORT_EXTENDED, 'up_time DESC' ); //$cl->SetSortMode( SPH_SORT_RELEVANCE);//Sort theo kq chính xác nhất //$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + ( user_karma + ln(pageviews) )*0.1"); $cl->SetSortMode(SPH_SORT_EXPR, "@weight"); //Sort theo trọng số $cl->SetLimits($offset, $limit, 10000); $cl->SetRankingMode($ranker); $cl->SetArrayResult(true); $res = $cl->Query($q, $index); if ($res && isset($res["matches"])) { if (is_array($res["matches"])) { foreach ($res["matches"] as $results) { $list_item_id[] = $results['id']; } } $comma_separated = join(",", $list_item_id); } if ($total) { if ($limit_to > $total) { $limit_to = $total; } $comma_separated = join(",", $list_item_id); if ($comma_separated) { //$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_category_id,category_id,description,original_image_url, img_server FROM item WHERE id IN ($comma_separated) AND status=1 ORDER BY up_time DESC"; $sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_category_id,category_id,description,original_image_url, img_server FROM item WHERE id IN ({$comma_separated}) AND status=1 ORDER BY find_in_set(id,'{$comma_separated}')"; $search_result = DB::query($sql); $pager->total = $total; $paging = $pager->page_link(); } } $item_array = array(); if ($search_result) { EClassApi::getCats(); $highlight = ''; if ($keywords) { $highlight = $str_search = str_replace(array('+', '/', '|', '-', '*'), "", $keywords); $highlight = EClassApi::trimSpace($highlight); $highlight = str_replace("'", '', $highlight); $highlight = str_replace("'", '', $highlight); $highlight = str_replace(""", '', $highlight); } $highlight1 = ''; if ($highlight) { $arr = explode(' ', $highlight); if ($arr) { $highlight = ""; foreach ($arr as $word) { $highlight = ($highlight ? $highlight . ', ' : '') . "'{$word}'"; $highlight1 = ($highlight1 ? $highlight1 . ',' : '') . $word; } } } while ($item = mysql_fetch_assoc($search_result)) { $item['profile_url'] = WEB_DIR . $item['user_name']; //$item['name'] = EClassApi::subString(strip_tags(EClassApi::filter_title($item['name'])), 0, 115, true); $item['name_hl'] = EClassApi::HighLightKeyword(strip_tags(EClassApi::filter_title($item['name'])), $highlight1); $item_time = TIME_NOW - $item['up_time']; //neu nho hon 1h thi tinh ra phut if ($item_time < 3600) { $item['item_time'] = floor($item_time / 60) . " phút trước đây"; } elseif ($item_time < 86400) { $item['item_time'] = floor($item_time / 3600) . " giờ trước đây"; } else { $item['item_time'] = date('\\n\\gà\\y j \\t\\há\\n\\g n', $item['up_time']); } //$item['description'] = String::display_sort_title(EClassApi::delDoubleSpace(EClassApi::trimSpace(strip_tags(EClassApi::post_db_parse_html($item['description'])))), 35); $item['description'] = EClassApi::HighLightKeyword(EClassApi::delDoubleSpace(EClassApi::trimSpace(strip_tags(EClassApi::post_db_parse_html(preg_replace('/\\[[0-9]{1,3}\\]/', '', $item['description']))))), $highlight1, 35, "background:yellow;font-size:14px;font-weight:bold;color:blue;"); $ebname = EClassApi::safe_title($item['name']); $ebname_tmp = substr(EClassApi::safe_title($item['name']), 0, 20); if (isset(CGlobal::$allCategories[$item['category_id']])) { $item['item_url'] = WEB_DIR . ECRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . $ebname . '&nice_name=' . CGlobal::$allCategories[$item['category_id']]['nice_name']); $item['item_url_tmp'] = WEB_ROOT . CGlobal::$allCategories[$item['category_id']]['nice_name'] . '/p' . $item['id'] . '/' . $ebname_tmp . '...'; } else { $item['item_url'] = WEB_DIR . ECRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . $ebname); $item['item_url_tmp'] = WEB_ROOT . 'p' . $item['id'] . '/' . $ebname_tmp . '...'; } if ($item['original_image_url']) { $item['original_image_url'] = EClassApi::getImageThumb($item['original_image_url'], 110, 0, 1, $item['img_server']); } $item['price'] = number_format($item['price'], 0, ',', '.'); $item_array[] = $item; } } $display->add('total_item_cat', $total); $display->add('name_item_cat', $catActive); $display->add('paging', $paging); $display->add('keywords', $keywords); $display->add('items', $item_array); $display->output('sphinx_search_ajax', false, 'sphinx_search'); }
function filter_link($link, $text) { if ($text = EClassApi::trimSpace(EClassApi::plainText($text))) { $text = EClassApi::strippedLink($text); if (strpos($link, 'http://chonmon.vn') === 0 || strpos($link, 'http://www.chonmon.vn') === 0 || strpos($link, 'chonmon.vn') === 0 || strpos($link, 'http://') === false) { return "<a href=\"{$link}\" target=\"_blank\">{$text}</a>"; } else { if (strpos($link, 'http://blog.chonmon.vn') === 0 || strpos($link, 'blog.chonmon.vn') === 0 || strpos($link, 'http://') === false) { return "<a href=\"{$link}\" target=\"_blank\">{$text}</a>"; } else { if (strpos($link, 'http://help.chonmon.vn') === 0 || strpos($link, 'help.chonmon.vn') === 0 || strpos($link, 'http://') === false) { return "<a href=\"{$link}\" target=\"_blank\">{$text}</a>"; } } } return "<a href=\"#\" rel=\"nofollow\" target=\"_blank\">...</a>"; } return ''; }
function note_edit() { $id = (int) Url::get('id', 0); $db_name = Url::get('db_name', ''); $note = EClassApi::trimSpace(Url::get('note', '')); if (!User::is_login()) { echo "not_login"; exit; } if (!User::have_permit(ADMIN_ITEM)) { echo "no_perm"; exit; } if ($id > 0) { $row = DB::fetch("SELECT note FROM {$db_name} WHERE id = {$id}"); if ($row) { $row['user_id_m'] = User::id(); $row['user_name_m'] = User::user_name(); $row['time_m'] = TIME_NOW; $row['note'] = $note ? addslashes($note) : ''; if (DB::update($db_name, $row, 'id=' . $id)) { echo 'success'; exit; } } else { echo 'unsuccess'; exit; } } else { echo "invalid"; exit; } }
function get_gallery_entry() { if (User::is_login()) { global $display; if ((User::have_permit(ADMIN_ITEM) || User::is_mod_cat()) && (int) Url::get('user_id', 0) && (int) Url::get('user_id', 0) != User::id()) { $user_id = (int) Url::get('user_id', 0); $display->add('user_id', $user_id); } else $user_id=User::id(); $search_value = ' user_id=' . $user_id . ' AND root_id=0 '; //search theo ngay thang nam //$year=(int)Url::get('year',date('Y')); $year = (int) Url::get('year', -1); //$mon= (int)Url::get('month',(int)date('m')); $mon = (int) Url::get('month', -1); $day = (int) Url::get('day', -1); if ($year == 0 )$year = -1; if ($mon == 0 )$mon = -1; if ($day == 0 )$day = -1; $created_time_from = 0; $created_time_to = 0; if ($year != -1) { if ($mon != -1) { if ($day != -1) { $created_time_from = mktime(0, 0, 0, $mon, $day, $year); $created_time_to = mktime(23, 59, 59, $mon, $day, $year); } else { $max_day = 31; if (in_array($mon, array(4, 6, 9, 11)) )$max_day = 30; elseif ($mon == 2) ($year % 4) ? $max_day = 28 : $max_day = 29; $created_time_from = mktime(0, 0, 0, $mon, 1, $year); $created_time_to = mktime(23, 59, 59, $mon, $max_day, $year); } } else { $created_time_from = mktime(0, 0, 0, 1, 1, $year); $created_time_to = mktime(23, 59, 59, 12, 31, $year); } } $y_arr = array(-1 => '-Lọc theo Năm-'); for ($i = 2008; $i <= date('Y'); $i++) { $y_arr[$i] = "---Năm $i-"; } $m_arr = array(-1 => '-Lọc theo Tháng-'); for ($i = 1; $i <= 12; $i++) { $m_arr[$i] = "---Tháng $i-"; } $d_arr = array(0 => '-Lọc theo Ngày-'); for ($i = 1; $i <= 31; $i++) { $d_arr[$i] = "---Ngày $i-"; } $display->add('option_year', EClassApi::getOption($y_arr, $year)); $display->add('option_month', EClassApi::getOption($m_arr, $mon)); $display->add('option_day', EClassApi::getOption($d_arr, $day)); if ($created_time_from) { $search_value .= ' AND time >= ' . $created_time_from; } if ($created_time_to) { $search_value .= ' AND time <= ' . $created_time_to; } $keywords = EClassApi::trimSpace(EClassApi::getParam('keywords')); $display->add('keywords', $keywords); if ($keywords) { $search_value .= ' AND des LIKE "%' . $keywords . '%" '; } $item_per_page = 20; $sql_count = 'SELECT count(*) AS total_img FROM item_image WHERE ' . $search_value; $total = DB::fetch($sql_count, 'total_img', 0); $paging = ''; $items = array(); $gallery_url = WEB_DIR . 'ajax.php' . Url::build_all(array('page_no')); if ($total) { $limit = ''; $paging = AjaxGalleryPaging($limit, $total, $item_per_page, 5, $gallery_url, 'gallery_content'); $sql = 'SELECT id, des, item_id, title, img_server, original_image_url, time FROM `item_image` WHERE ' . $search_value . ' ORDER BY id DESC ' . $limit; $re = DB::query($sql); if ($re) { while ($row = mysql_fetch_assoc($re)) { $row['image_url'] = $row['original_image_url']; $row['original_image_url'] = EClassApi::getImageThumb($row['original_image_url'], 100, 100, 0, $row['img_server']); $items[$row['id']] = $row; } } } $display->add('items', $items); $display->add('total', $total); $display->add('paging', $paging); $display->output('gallery_ajax_entry', false, 'Personal'); System::halt(); } else { echo "Bạn chưa đăng nhập hoặc đã thoát khỏi hệ thống - Hãy đăng nhập lại!"; } }
static function descriptionText($str) { $meta_desc = EClassApi::post_db_parse_html($str); $meta_desc = EClassApi::plainText(html_entity_decode($meta_desc, ENT_QUOTES, "UTF-8")); $meta_desc = str_replace('\'', '', $meta_desc); $meta_desc = str_replace('"', '', $meta_desc); return EClassApi::delDoubleSpace(EClassApi::trimSpace($meta_desc)); }
function edit_address() { if (!User::is_admin() && !User::have_permit('change_address')) { echo 'no_perm'; exit; } $uid = EClassApi::trimSpace($_POST['id']); if (isset($_POST['delete'])) { if (!empty($uid) && DB::delete_id('delivery_address', $uid)) { echo 'success'; } else { echo 'error'; } exit; } $did = EClassApi::trimSpace($_POST['district']); $tel = EClassApi::trimSpace($_POST['tel']); $full_name = $_POST['full_name']; $address = $_POST['address']; $note = $_POST['note']; $edit = $_POST['edit']; $edit_id = $_POST['edit_id']; $new_row = array('did' => $did, 'tel' => $tel, 'full_name' => $full_name, 'address' => $address, 'note' => $note, 'uid' => $uid); if ((int) $edit == 1) { if (!empty($uid) && !empty($did) && DB::update_id('delivery_address', $new_row, $edit_id)) { echo 'success'; } else { echo 'error'; } } else { if (!empty($uid) && !empty($did) && DB::insert('delivery_address', $new_row)) { echo 'success'; } else { echo 'error'; } } }