function xt_admin_ajax_tag_update() { $result = array('code' => 0, 'msg' => '', 'result' => array()); if (!current_user_can('manage_options')) { $result['code'] = 500; $result['msg'] = '您无权操作此功能'; } if (!isset($_POST['id']) || empty($_POST['id'])) { $result['code'] = 500; $result['msg'] = '未指定标签'; } if (!isset($_POST['sort']) || empty($_POST['sort'])) { $result['code'] = 500; $result['msg'] = '未指定标签排序'; } $id = intval(trim($_POST['id'])); $sort = intval($_POST['sort']); $cids = isset($_POST['cids']) ? $_POST['cids'] : ''; $currentCid = intval($_POST['cid']); if ($result['code'] == 0) { global $wpdb; if ($currentCid > 0) { echo 'update:[' . $wpdb->update(XT_TABLE_SHARE_TAG_CATALOG, array('sort' => $sort), array('id' => $id, 'cid' => $currentCid)) . ']'; } else { $wpdb->update(XT_TABLE_SHARE_TAG, array('sort' => $sort), array('id' => $id)); } $query = "SELECT t.*, tr.id AS tag_id FROM " . XT_TABLE_CATALOG . " AS t INNER JOIN " . XT_TABLE_SHARE_TAG_CATALOG . " AS tr ON t.id = tr.cid WHERE t.type = 'share' AND tr.id =" . $id . " ORDER BY t.sort ASC,t.count DESC"; $term = $wpdb->get_results($query); $old = array(); if (!empty($term)) { foreach ($term as $_term) { $old[] = $_term->id; } } $cids = array_map('intval', explode(',', $cids)); if (empty($cids)) { $cids = array(); } $deleteIds = array_diff($old, $cids); //delete $addIds = array_diff($cids, $old); //add if (!empty($deleteIds)) { foreach ($deleteIds as $del) { xt_delete_tag_catalog($del, $id); } } if (!empty($addIds)) { foreach ($addIds as $add) { xt_new_tag_catalog(array('cid' => $add, 'id' => $id)); } } $tag = xt_get_tag($id); if (!empty($addIds)) { global $wpdb; foreach ($addIds as $add) { //refresh count $count = xt_get_sharecount_bytagandcid($tag->title, $add); $wpdb->query("UPDATE " . XT_TABLE_SHARE_TAG_CATALOG . " SET count={$count} WHERE id=" . absint($id) . " AND cid=" . absint($add)); } } $term = $wpdb->get_results($query); //reload xt_update_catalog_terms_cache($id, $term); //sort and count if ($currentCid > 0) { $catalog = xt_get_catalog($currentCid); if (!empty($catalog)) { global $wpdb; $sql = "SELECT " . XT_TABLE_SHARE_TAG_CATALOG . ".cid," . XT_TABLE_SHARE_TAG_CATALOG . ".sort," . XT_TABLE_SHARE_TAG . ".id," . XT_TABLE_SHARE_TAG . ".title," . XT_TABLE_SHARE_TAG . ".is_hot," . XT_TABLE_SHARE_TAG_CATALOG . ".count," . XT_TABLE_SHARE_TAG . ".nums FROM " . XT_TABLE_SHARE_TAG_CATALOG . " INNER JOIN " . XT_TABLE_SHARE_TAG . " ON " . XT_TABLE_SHARE_TAG . ".id=" . XT_TABLE_SHARE_TAG_CATALOG . ".id WHERE " . XT_TABLE_SHARE_TAG_CATALOG . ".id={$id} AND " . XT_TABLE_SHARE_TAG_CATALOG . ".cid={$currentCid}"; if (isset($catalog->children) && !empty($catalog->children)) { $sql = "SELECT " . XT_TABLE_SHARE_TAG_CATALOG . ".cid," . XT_TABLE_SHARE_TAG_CATALOG . ".sort AS sort,min(" . XT_TABLE_SHARE_TAG_CATALOG . ".sort) AS childSort," . XT_TABLE_SHARE_TAG . ".id," . XT_TABLE_SHARE_TAG . ".title," . XT_TABLE_SHARE_TAG . ".is_hot,max(" . XT_TABLE_SHARE_TAG_CATALOG . ".count) AS count," . XT_TABLE_SHARE_TAG . ".nums FROM " . XT_TABLE_SHARE_TAG_CATALOG . " INNER JOIN " . XT_TABLE_SHARE_TAG . " ON " . XT_TABLE_SHARE_TAG . ".id=" . XT_TABLE_SHARE_TAG_CATALOG . ".id WHERE " . XT_TABLE_SHARE_TAG_CATALOG . ".id={$id} AND " . XT_TABLE_SHARE_TAG_CATALOG . ".cid in(" . $wpdb->escape($catalog->children) . ",{$currentCid}) GROUP BY " . XT_TABLE_SHARE_TAG . ".id ORDER BY sort ASC,childSort ASC," . XT_TABLE_SHARE_TAG_CATALOG . ".count DESC"; } $tag = $wpdb->get_row($sql); } } exit(xt_row_tag($tag, isset($_POST['alternate']) && $_POST['alternate'] ? 0 : 1, $currentCid)); } exit(json_encode($result)); }
function xt_screens() { global $xt, $wp_query, $xt_catalog, $xt_user, $xt_album, $xt_taobao_item, $xt_template_name; if (xt_is_404()) { if (is_home()) { xt_clear_404(); $xt->is_xintao = true; $xt->is_index = true; $xt_template_name = 'home'; } elseif (is_front_page()) { if (is_page(xt_base()) && !isset($wp_query->query_vars['xt_action'])) { xt_clear_404(); $xt->is_xintao = true; $xt->is_index = true; $xt_template_name = 'home'; } elseif (!isset($wp_query->query_vars['xt_action'])) { $xt->is_xintao = false; } } } if (is_404() && !$xt->is_xintao) { $xt->is_xintao = true; xt_set_404(); } if ($xt->is_xintao) { if (isset($_GET['invite']) && absint($_GET['invite']) > 0) { setcookie(XT_USER_PARENT, (string) $_GET['invite'], time() + 1296000, COOKIEPATH, COOKIE_DOMAIN); } $xt_share_param = isset($wp_query->query_vars['xt_param']) ? $wp_query->query_vars['xt_param'] : ''; if ($xt->is_shares) { query_shares($xt_share_param); if (isset($xt_share_param['s']) && !empty($xt_share_param['s'])) { //设置搜索词 $wp_query->set('s', $xt_share_param['s']); } if (absint($xt_share_param['cid']) > 0) { $_term = xt_get_catalog($xt_share_param['cid']); if (!empty($_term)) { $xt_catalog = $_term; } } } elseif ($xt->is_albums) { query_albums($xt_share_param); if (isset($xt_share_param['s']) && !empty($xt_share_param['s'])) { //设置搜索词 $wp_query->set('s', $xt_share_param['s']); } } elseif ($xt->is_share) { $xt_user = null; if (absint($xt_share_param) > 0) { query_shares(array('id' => absint($xt_share_param))); if (xt_have_shares()) { xt_the_share(); $xt_user = new WP_User(get_the_share_userid()); if (!empty($xt_user) && $xt_user->ID != 0) { xt_setup_single_userdata(); } else { xt_set_404(); } } else { xt_set_404(); } } else { xt_set_404(); } } elseif ($xt->is_user) { $xt_user = null; if (absint($xt_share_param) > 0) { $uid = absint($xt_share_param); $_user = wp_get_current_user(); if ($_user->exists()) { if ($_user->ID == $uid) { $xt_user = $_user; } } if (empty($xt_user) || $xt_user->ID == 0) { $_user = new WP_User($uid); if ($_user && $_user->ID != 0) { $xt_user = $_user; } } if (!empty($xt_user) && $xt_user->ID != 0) { xt_setup_single_userdata(); } } if (empty($xt_user) || $xt_user->ID == 0) { xt_set_404(); } } elseif ($xt->is_account) { $xt_user = wp_get_current_user(); if ($xt_user->exists()) { //xt_setup_single_userdata(); } else { xt_set_404(); wp_safe_redirect(site_url('wp-login.php')); exit; } } elseif ($xt->is_album) { $xt_user = null; $xt_album = null; if (absint($xt_share_param) > 0) { $xt_album = xt_get_album($xt_share_param); if (!empty($xt_album)) { $_user = wp_get_current_user(); if ($_user->exists()) { if ($_user->ID == $xt_album->user_id) { $xt_user = $_user; } else { $xt_user = new WP_User($xt_album->user_id); } } else { $xt_user = new WP_User($xt_album->user_id); } if (!empty($xt_user) && $xt_user->ID > 0) { xt_setup_single_userdata(); // query_albums(array ( // 'page' => 1, // 'album_per_page' => 20, // 'user_id' => $xt_album->user_id // )); //当前专辑所属用户的前20个专辑 query_shares(array('album_id' => absint($xt_share_param), 'page' => 1, 'share_per_page' => 40, 'user_id' => $xt_album->user_id)); } //当前专辑内的宝贝 } if (empty($xt_album) || empty($xt_user) || $xt_user->ID == 0) { xt_set_404(); } } } elseif ($xt->is_page) { } elseif ($xt->is_invite) { $xt_user = null; if (absint($xt_share_param) > 0) { $xt_user = new WP_User(absint($xt_share_param)); } if (empty($xt_user) || $xt_user->ID == 0) { xt_set_404(); } else { $user = wp_get_current_user(); if (!$user->exists()) { //15days setcookie(XT_USER_PARENT, (string) $xt_user->ID, time() + 1296000, COOKIEPATH, COOKIE_DOMAIN); } } } elseif ($xt->is_taobao) { $xt_taobao_item = xt_taobao_item($xt_share_param, "detail_url,num_iid,title,nick,props_name,cid,pic_url,num,location,price,post_fee,express_fee,ems_fee,item_img,prop_imgs"); if (is_wp_error($xt_taobao_item)) { xt_set_404(); } } if (xt_is_404()) { $xt_template_name = 'error404'; } if ($xt->is_login) { xt_load_template('xt-login', true, true); } elseif ($xt->is_jump) { xt_load_template('xt-jump', true, true); } elseif ($xt->is_sitemap) { xt_load_template('xt-sitemap', true, true); } else { xt_load_template('xt-template', true, true); } } }
public function updateAutoCatalog($params = array()) { if (isset($params['type']) && !empty($params['type']) && isset($params['cid']) && !empty($params['cid']) && isset($params['cids'])) { $type = $params['type']; $cid = intval($params['cid']); $cids = $params['cids']; $catalog = xt_get_catalog($cid); if (!empty($catalog) && in_array($type, array('taobao', 'paipai'))) { $cids = array_map('intval', explode(',', $cids)); global $wpdb; $olds = $wpdb->get_col('SELECT cid FROM ' . XT_TABLE_CATALOG_ITEMCAT . ' WHERE id=' . $cid . ' AND type=\'' . $type . '\''); $deleteCids = array_diff($olds, $cids); $addCids = array_diff($cids, $olds); if (!empty($deleteCids)) { $wpdb->query('DELETE FROM ' . XT_TABLE_CATALOG_ITEMCAT . ' WHERE id=' . $cid . ' AND cid in (' . implode(',', $deleteCids) . ')'); } if (!empty($addCids)) { foreach ($addCids as $_cid) { if ($_cid > 0) { $wpdb->insert(XT_TABLE_CATALOG_ITEMCAT, array('id' => $cid, 'cid' => $_cid, 'parent_id' => $catalog->parent, 'type' => $type)); } } } } return false; } }
function query($query_vars) { global $wpdb, $xt; $this->init(); $defaults = array('cid' => '', 'page' => 1, 'album_per_page' => xt_albumperpage(), 'user_id' => 0, 'no_found_rows' => 0, 's' => '', 'isFavorite' => 0, 'isShare' => 0, 'sortOrder' => '', 'album__in' => array()); $this->query_vars = wp_parse_args($query_vars, $defaults); do_action_ref_array('xt_pre_get_albums', array(&$this)); extract($this->query_vars, EXTR_SKIP); $page = absint($page); $album_per_page = absint($album_per_page); $table = $isFavorite ? XT_TABLE_FAVORITE : XT_TABLE_ALBUM; $fields = '*'; $join = ''; $where = ''; $order = "ORDER BY " . XT_TABLE_ALBUM . ".update_date_gmt DESC"; $groupby = ''; if (!empty($cid) && $cid > 0) { global $xt_catalog; if (empty($xt_catalog) || $xt_catalog->id != $cid) { $xt_catalog = xt_get_catalog($cid); } if (!empty($xt_catalog)) { if (isset($xt_catalog->children) && !empty($xt_catalog->children)) { $join .= " INNER JOIN " . XT_TABLE_ALBUM_CATALOG . " ON " . XT_TABLE_ALBUM_CATALOG . ".id = " . XT_TABLE_ALBUM . ".id "; $where .= " AND " . XT_TABLE_ALBUM_CATALOG . ".cid in(" . $wpdb->escape($xt_catalog->children) . "," . $cid . ") "; $groupby .= "GROUP BY " . XT_TABLE_ALBUM . ".id"; } else { $join .= " INNER JOIN " . XT_TABLE_ALBUM_CATALOG . " ON " . XT_TABLE_ALBUM_CATALOG . ".id = " . XT_TABLE_ALBUM . ".id "; $where .= $wpdb->prepare(" AND " . XT_TABLE_ALBUM_CATALOG . ".cid=%d ", $cid); } } } elseif ($cid == -1) { $join = ''; $where = ' AND ' . XT_TABLE_ALBUM . '.id NOT IN (SELECT ID FROM ' . XT_TABLE_ALBUM_CATALOG . ')'; } if ($isFavorite) { $join .= " INNER JOIN " . XT_TABLE_ALBUM . " ON " . XT_TABLE_FAVORITE . ".id=" . XT_TABLE_ALBUM . ".id "; } if ($user_id > 0) { if ($isFavorite) { $where .= $wpdb->prepare(" AND " . XT_TABLE_FAVORITE . ".user_id = %d AND " . XT_TABLE_FAVORITE . ".type=2", $user_id); } else { $where .= $wpdb->prepare(" AND " . XT_TABLE_ALBUM . ".user_id = %d ", $user_id); } } elseif (!empty($s)) { $where .= " AND (" . XT_TABLE_ALBUM . ".title like '%" . $wpdb->escape($s) . "%' OR " . XT_TABLE_ALBUM . ".user_name like '%" . $wpdb->escape($s) . "%') "; } if (!empty($album__in)) { $album__in = implode(',', array_map('absint', $album__in)); $where .= " AND " . XT_TABLE_ALBUM . ".id IN ({$album__in})"; } $today_time = xt_get_todaytime(); switch ($sortOrder) { case 'newest': default: $order = " ORDER BY " . XT_TABLE_ALBUM . ".update_date DESC"; break; case 'popular': $day7_time = $today_time - 604800; //7 days $fields .= ",(" . XT_TABLE_ALBUM . ".create_date > {$day7_time}) AS time_sort "; $order = " ORDER BY time_sort DESC," . XT_TABLE_ALBUM . ".fav_count DESC"; break; case 'hot': $day30_time = $today_time - 2592000; //30 days $fields .= ",(" . XT_TABLE_ALBUM . ".create_date > {$day30_time}) AS time_sort "; $order = " ORDER BY time_sort DESC," . XT_TABLE_ALBUM . ".fav_count DESC"; break; } if (!$no_found_rows && $page && $album_per_page) { $limits = $wpdb->prepare("LIMIT %d, %d", ($page - 1) * $album_per_page, $album_per_page); } else { $limits = ''; } if ($isFavorite) { $order = " ORDER BY " . XT_TABLE_FAVORITE . ".create_date DESC"; } $found_rows = ''; if (!$no_found_rows) { $found_rows = 'SQL_CALC_FOUND_ROWS'; } $sql = "SELECT {$found_rows} {$fields} FROM {$table} {$join} WHERE 1=1 {$where} {$order} {$limits}"; $paged_albums = $wpdb->get_results($sql); $paged_albums = apply_filters_ref_array('xt_the_albums', array($paged_albums, &$this)); $total_albums = -1; if (!$no_found_rows) { $total_albums = $wpdb->get_var('SELECT FOUND_ROWS()'); } unset($sql); $this->found_albums = $total_albums; $this->albums = $paged_albums; $this->album_count = count($paged_albums); if ($total_albums > 1) { $total_page = ceil($total_albums / $album_per_page); $_base = '#%#%'; if (isset($xt->is_albums) && $xt->is_albums) { $_base = xt_get_albums_search_url(array_merge($this->query_vars, array('page' => '%#%'))); } else { if (isset($_GET['page']) && $_GET['page'] == 'xt_menu_share') { $_base = add_query_arg('paged', '%#%', $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); } } $this->paginate_links = paginate_links(array('base' => $_base, 'format' => '', 'end_size' => 3, 'total' => $total_page, 'current' => $page, 'prev_text' => '上一页', 'next_text' => '下一页', 'mid_size' => 1, 'type' => isset($_GET['page']) && $_GET['page'] == 'xt_menu_share' ? 'plain' : 'list')); } return array('albums' => $paged_albums, 'total' => $total_albums); }
function xt_shareandtags($cid, $tags, $sortOrder) { global $wpdb; $tags = array_reverse($tags); $today_time = xt_get_todaytime(); $fields = "wp_xt_share.id,wp_xt_share.title,wp_xt_share.pic_url,wp_xt_share.from_type"; $order = ""; $join = ""; $groupby = "GROUP BY score"; $where = " WHERE 1=1 "; if (!empty($cid) && $cid > 0) { $xt_catalog = xt_get_catalog($cid); if (!empty($xt_catalog)) { if (isset($xt_catalog->children) && !empty($xt_catalog->children)) { $join .= " INNER JOIN " . XT_TABLE_SHARE_CATALOG . " ON " . XT_TABLE_SHARE_CATALOG . ".id = " . XT_TABLE_SHARE . ".id "; $where .= " AND " . XT_TABLE_SHARE_CATALOG . ".cid in(" . $wpdb->escape($xt_catalog->children) . "," . $cid . ") "; } else { $join .= " INNER JOIN " . XT_TABLE_SHARE_CATALOG . " ON " . XT_TABLE_SHARE_CATALOG . ".id = " . XT_TABLE_SHARE . ".id "; $where .= $wpdb->prepare(" AND " . XT_TABLE_SHARE_CATALOG . ".cid=%d ", $cid); } } } switch ($sortOrder) { case 'newest': default: $order = " ORDER BY " . XT_TABLE_SHARE . ".create_date DESC"; break; case 'popular': $day7_time = $today_time - 604800; //7 days $fields .= ",(UNIX_TIMESTAMP(" . XT_TABLE_SHARE . ".create_date) > {$day7_time}) AS time_sort "; $order = " ORDER BY time_sort DESC," . XT_TABLE_SHARE . ".fav_count DESC"; break; case 'hot': $day30_time = $today_time - 2592000; //30 days $fields .= ",(UNIX_TIMESTAMP(" . XT_TABLE_SHARE . ".create_date) > {$day30_time}) AS time_sort "; $order = " ORDER BY time_sort DESC," . XT_TABLE_SHARE . ".fav_count DESC"; break; } $againsts = array(); $results = array(); $whenthen = array(); if (!empty($tags)) { $length = count($tags); for ($i = 0; $i < $length; $i++) { $tag = $tags[$i]; $segment = xt_segment_unicode($wpdb->escape($tag->title), '+'); $againsts[] = "({$segment})"; $results[$i] = array('tag' => $tag->title, 'share' => false); $whenthen[] = " when (match(gm.content_match) against('{$segment}' IN BOOLEAN MODE)) = 1 then {$i} "; } $fields .= ",case " . implode('', $whenthen) . " END AS score "; $against = implode(' ', $againsts); $join .= " INNER JOIN wp_xt_share_match gm ON match(gm.content_match) against('{$against}' IN BOOLEAN MODE) AND gm.share_id=wp_xt_share.id "; $sql = "SELECT * FROM (SELECT {$fields} FROM wp_xt_share {$join} {$where} {$order}) AS temp {$groupby}"; $shares = $wpdb->get_results($sql); unset($sql); if (!empty($shares)) { foreach ($shares as $share) { for ($j = 0; $j < 12; $j++) { if ($share->score == $j) { $results[$j]['share'] = $share; continue; } } } } } return array_reverse($results); }
function _get_shares($args) { global $wpdb; $id = isset($args['id']) && absint($args['id']) ? absint($args['id']) : 0; $album_id = isset($args['album_id']) && absint($args['album_id']) ? absint($args['album_id']) : 0; if ($id > 0) { //single $result = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . XT_TABLE_SHARE . " g WHERE g.id = %d", $id)); if (!empty($result)) { return array('share' => array($result), 'total' => 1); } else { return array('share' => array(), 'total' => 0); } } $user_id = $args['user_id']; $sortOrder = $args['sortOrder']; $cid = $args['cid']; $share_per_page = $args['share_per_page']; $page = $args['page']; $s = $args['s']; $price = $args['price']; $isFavorite = $args['isFavorite']; $isHome = $args['isHome']; $fields = $args['fields']; $table = $album_id > 0 ? XT_TABLE_SHARE_ALBUM : ($isFavorite ? XT_TABLE_FAVORITE : XT_TABLE_SHARE); $join = ''; $where = ''; $groupby = ''; $order = ''; $pagination = ''; $found_rows = ''; if (!empty($cid) && $cid > 0) { global $xt_catalog; if (empty($xt_catalog) || $xt_catalog->id != $cid) { $xt_catalog = xt_get_catalog($cid); } if (!empty($xt_catalog)) { if (isset($xt_catalog->children) && !empty($xt_catalog->children)) { $join .= " INNER JOIN " . XT_TABLE_SHARE_CATALOG . " ON " . XT_TABLE_SHARE_CATALOG . ".id = " . XT_TABLE_SHARE . ".id "; $where .= " AND " . XT_TABLE_SHARE_CATALOG . ".cid in(" . $wpdb->escape($xt_catalog->children) . "," . $cid . ") "; $groupby .= "GROUP BY " . XT_TABLE_SHARE . ".id"; } else { $join .= " INNER JOIN " . XT_TABLE_SHARE_CATALOG . " ON " . XT_TABLE_SHARE_CATALOG . ".id = " . XT_TABLE_SHARE . ".id "; $where .= $wpdb->prepare(" AND " . XT_TABLE_SHARE_CATALOG . ".cid=%d ", $cid); } } } elseif ($cid == -1) { $join = ''; $where = ' AND ' . XT_TABLE_SHARE . '.id NOT IN (SELECT ID FROM ' . XT_TABLE_SHARE_CATALOG . ')'; } if (!empty($user_id) && $user_id > 0) { if ($isHome) { global $xt_pageuser_follows; if (!empty($xt_pageuser_follows) && is_array($xt_pageuser_follows)) { $followIds = implode(',', $xt_pageuser_follows); $where .= " AND " . XT_TABLE_SHARE . ".user_id in (" . $followIds . ") "; } } elseif ($isFavorite) { $where .= $wpdb->prepare(" AND " . XT_TABLE_FAVORITE . ".user_id = %d AND " . XT_TABLE_FAVORITE . ".type=1", $user_id); } elseif ($album_id > 0) { $where .= $wpdb->prepare(" AND " . XT_TABLE_SHARE_ALBUM . ".user_id = %d ", $user_id); } else { $where .= $wpdb->prepare(" AND " . XT_TABLE_SHARE . ".user_id = %d ", $user_id); } } if ($isFavorite) { $join .= " INNER JOIN " . XT_TABLE_SHARE . " ON " . XT_TABLE_FAVORITE . ".id=" . XT_TABLE_SHARE . ".id "; } elseif (!empty($s)) { $match_key = xt_segment_unicode($wpdb->escape($s), '+'); $join .= " INNER JOIN " . XT_TABLE_SHARE_MATCH . " gm ON match(gm.content_match) against('" . $match_key . "' IN BOOLEAN MODE) AND gm.share_id=" . XT_TABLE_SHARE . ".id "; } elseif ($album_id > 0) { $where .= $wpdb->prepare(" AND " . XT_TABLE_SHARE_ALBUM . ".album_id = %d ", $album_id); $join .= " INNER JOIN " . XT_TABLE_SHARE . " ON " . XT_TABLE_SHARE_ALBUM . ".id=" . XT_TABLE_SHARE . ".id "; } $fields .= " ,{$wpdb->usermeta}.meta_value as user_avatar"; $join .= " LEFT JOIN {$wpdb->usermeta} ON {$wpdb->usermeta}.user_id = " . XT_TABLE_SHARE . ".user_id AND {$wpdb->usermeta}.meta_key='" . XT_USER_AVATAR . "' "; if (!empty($price)) { $prices = xt_prices(); switch ($price) { case 'low': $where .= " AND " . XT_TABLE_SHARE . ".price <= " . $prices['low']['end']; break; case 'medium': $where .= " AND " . XT_TABLE_SHARE . ".price >= " . $prices['medium']['start'] . " AND " . XT_TABLE_SHARE . ".price <= " . $prices['medium']['end']; break; case 'high': $where .= " AND " . XT_TABLE_SHARE . ".price >= " . $prices['high']['start'] . " AND " . XT_TABLE_SHARE . ".price <= " . $prices['high']['end']; break; case 'higher': $where .= " AND " . XT_TABLE_SHARE . ".price >= " . $prices['higher']['start']; break; } } $today_time = xt_get_todaytime(); if ($isHome) { $order = " ORDER BY " . XT_TABLE_SHARE . ".create_date DESC"; } elseif ($isFavorite) { $order = " ORDER BY " . XT_TABLE_FAVORITE . ".create_date DESC"; } else { switch ($sortOrder) { case 'newest': default: $order = " ORDER BY " . XT_TABLE_SHARE . ".create_date DESC"; break; case 'popular': $day7_time = $today_time - 604800; //7 days $fields .= ",(UNIX_TIMESTAMP(" . XT_TABLE_SHARE . ".create_date) > {$day7_time}) AS time_sort "; $order = " ORDER BY time_sort DESC," . XT_TABLE_SHARE . ".fav_count DESC"; break; case 'hot': $day30_time = $today_time - 2592000; //30 days $fields .= ",(UNIX_TIMESTAMP(" . XT_TABLE_SHARE . ".create_date) > {$day30_time}) AS time_sort "; $order = " ORDER BY time_sort DESC," . XT_TABLE_SHARE . ".fav_count DESC"; break; } } if ($share_per_page && $page) { $pagination = $wpdb->prepare("LIMIT %d, %d", intval(($page - 1) * $share_per_page), intval($share_per_page)); } if (!empty($where)) { $where = ' WHERE 1=1 ' . $where; } if (!$args['no_found_rows']) { $found_rows = 'SQL_CALC_FOUND_ROWS'; } $sql = "SELECT {$found_rows} {$fields} FROM {$table} {$join} {$where} {$groupby} {$order} {$pagination}"; $paged_share_sql = apply_filters('xt_share_get_paged_share_sql', $sql, $sql); $paged_share = $wpdb->get_results($paged_share_sql); $total_share = -1; if (!$args['no_found_rows']) { $total_share = $wpdb->get_var('SELECT FOUND_ROWS()'); $max_num_pages = ceil($total_share / $args['share_per_page']); } unset($sql); return array('share' => $paged_share, 'total' => $total_share); }
function xt_insert_catalog($catalogdata) { global $wpdb; extract(stripslashes_deep($catalogdata), EXTR_SKIP); if ($parent > 0) { $_catalog = xt_get_catalog($parent); if (empty($_catalog)) { return 0; } } if (xt_catalog_exit(0, $title, $parent, $type)) { return 0; } $data = compact('title', 'pic', 'sort', 'parent', 'is_front', 'keywords', 'description', 'type'); if (isset($catalogdata['id'])) { $data['id'] = $catalogdata['id']; } if ($wpdb->insert(XT_TABLE_CATALOG, $data)) { if ($parent > 0) { $children = $wpdb->get_col('SELECT id FROM ' . XT_TABLE_CATALOG . ' WHERE parent=' . intval($parent)); if (!empty($children)) { $wpdb->update(XT_TABLE_CATALOG, array('children' => implode(',', $children)), array('id' => intval($parent))); } } return $wpdb->insert_id; } return 0; }
function query($query_vars) { global $wpdb; $this->init(); $defaults = array('page' => 1, 'tag_per_page' => 10, 'cid' => 0, 's' => ''); $this->query_vars = wp_parse_args($query_vars, $defaults); do_action_ref_array('xt_pre_get_tags', array(&$this)); extract($this->query_vars, EXTR_SKIP); $page = absint($page); $tag_per_page = absint($tag_per_page); $table = XT_TABLE_SHARE_TAG; $fields = XT_TABLE_SHARE_TAG . '.*'; $orderBy = XT_TABLE_SHARE_TAG . ".sort ASC," . XT_TABLE_SHARE_TAG . ".count DESC"; $join = ""; $totalJoin = ""; $where = ""; $groupby = ""; $totalgroupby = ""; if ($cid > 0) { global $xt_catalog; if (empty($xt_catalog) || $xt_catalog->id != $cid) { $xt_catalog = xt_get_catalog($cid); } if (!empty($xt_catalog)) { $table = XT_TABLE_SHARE_TAG_CATALOG; $orderBy = "sort ASC," . XT_TABLE_SHARE_TAG_CATALOG . ".count DESC"; $fields = XT_TABLE_SHARE_TAG_CATALOG . ".cid," . XT_TABLE_SHARE_TAG_CATALOG . ".sort," . XT_TABLE_SHARE_TAG . ".id," . XT_TABLE_SHARE_TAG . ".title," . XT_TABLE_SHARE_TAG . ".is_hot," . XT_TABLE_SHARE_TAG_CATALOG . ".count," . XT_TABLE_SHARE_TAG . ".nums "; $join = " INNER JOIN " . XT_TABLE_SHARE_TAG . " ON " . XT_TABLE_SHARE_TAG . ".id=" . XT_TABLE_SHARE_TAG_CATALOG . ".id "; if (isset($xt_catalog->children) && !empty($xt_catalog->children)) { $fields = XT_TABLE_SHARE_TAG_CATALOG . ".cid," . XT_TABLE_SHARE_TAG_CATALOG . ".sort AS sort,min(" . XT_TABLE_SHARE_TAG_CATALOG . ".sort) AS childSort," . XT_TABLE_SHARE_TAG . ".id," . XT_TABLE_SHARE_TAG . ".title," . XT_TABLE_SHARE_TAG . ".is_hot,max(" . XT_TABLE_SHARE_TAG_CATALOG . ".count) AS count," . XT_TABLE_SHARE_TAG . ".nums "; $orderBy = "sort ASC,childSort ASC," . XT_TABLE_SHARE_TAG_CATALOG . ".count DESC"; $where .= " AND " . XT_TABLE_SHARE_TAG_CATALOG . ".cid in(" . $wpdb->escape($xt_catalog->children) . "," . $cid . ") "; $groupby .= "GROUP BY " . XT_TABLE_SHARE_TAG . ".id"; $totalgroupby .= "GROUP BY " . XT_TABLE_SHARE_TAG_CATALOG . ".id"; } else { $where = $wpdb->prepare(" AND " . XT_TABLE_SHARE_TAG_CATALOG . ".cid=%d", $cid); $groupby .= "GROUP BY " . XT_TABLE_SHARE_TAG . ".id"; } } } elseif ($cid == -1) { $join = ''; $where = ' AND ' . XT_TABLE_SHARE_TAG . '.id NOT IN (SELECT ID FROM ' . XT_TABLE_SHARE_TAG_CATALOG . ')'; } if (!empty($s)) { $where .= ' AND ' . XT_TABLE_SHARE_TAG . '.title like \'%' . $wpdb->escape($s) . '%\''; if ($table != XT_TABLE_SHARE_TAG) { $totalJoin = " INNER JOIN " . XT_TABLE_SHARE_TAG . " ON " . XT_TABLE_SHARE_TAG . ".id=" . XT_TABLE_SHARE_TAG_CATALOG . ".id "; } } if ($page && $tag_per_page) { $limits = $wpdb->prepare("LIMIT %d, %d", ($page - 1) * $tag_per_page, $tag_per_page); } else { $limits = ''; } $sql = "SELECT {$fields} FROM {$table} {$join} WHERE 1=1 {$where} {$groupby} ORDER BY {$orderBy} {$limits}"; $paged_tags = $wpdb->get_results($sql); $total_sql = "SELECT COUNT(DISTINCT({$table}.id)) FROM {$table} {$totalJoin} WHERE 1=1 {$where}"; $total_tags = $wpdb->get_var($total_sql); unset($sql, $total_sql); $this->found_tags = $total_tags; $this->tags = $paged_tags; $this->tag_count = count($paged_tags); if ($total_tags > 1) { $total_page = ceil($total_tags / $tag_per_page); $this->paginate_links = paginate_links(array('base' => isset($_GET['page']) && $_GET['page'] == 'xt_menu_share' ? add_query_arg('paged', '%#%', $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) : '#%#%', 'format' => '', 'end_size' => 3, 'total' => $total_page, 'current' => $page, 'prev_text' => '上一页', 'next_text' => '下一页', 'mid_size' => 1)); } return array('tags' => $paged_tags, 'total' => $total_tags); }