function views_post_excerpt($post_excerpt, $post_content, $post_password, $chars = 200) { if (!empty($post_password)) { if (!isset($_COOKIE['wp-postpass_' . COOKIEHASH]) || $_COOKIE['wp-postpass_' . COOKIEHASH] != $post_password) { return __('There is no excerpt because this is a protected post.', 'wp-postviews'); } } if (empty($post_excerpt)) { return snippet_text(strip_tags($post_content), $chars); } else { return $post_excerpt; } }
function expand_ratings_template($template, $post_data, $post_ratings_data = null, $max_post_title_chars = 0, $is_main_loop = true) { global $post; // Get global variables $ratings_image = get_option('postratings_image'); $ratings_max = intval(get_option('postratings_max')); $ratings_custom = intval(get_option('postratings_customrating')); $ratings_options = get_option('postratings_options'); if (is_object($post_data)) { $post_id = $post_data->ID; } else { $post_id = $post_data; } // Most likely from coming from Widget if (isset($post_data->ratings_users)) { $post_ratings_users = intval($post_data->ratings_users); $post_ratings_score = intval($post_data->ratings_score); $post_ratings_average = floatval($post_data->ratings_average); // Most Likely coming from the_ratings_vote or the_ratings_rate } else { if (isset($post_ratings_data->ratings_users)) { $post_ratings_users = intval($post_ratings_data->ratings_users); $post_ratings_score = intval($post_ratings_data->ratings_score); $post_ratings_average = floatval($post_ratings_data->ratings_average); } else { if (get_the_ID() != $post_id) { $post_ratings_data = get_post_custom($post_id); } else { $post_ratings_data = get_post_custom(); } $post_ratings_users = is_array($post_ratings_data) && array_key_exists('ratings_users', $post_ratings_data) ? intval($post_ratings_data['ratings_users'][0]) : 0; $post_ratings_score = is_array($post_ratings_data) && array_key_exists('ratings_score', $post_ratings_data) ? intval($post_ratings_data['ratings_score'][0]) : 0; $post_ratings_average = is_array($post_ratings_data) && array_key_exists('ratings_average', $post_ratings_data) ? floatval($post_ratings_data['ratings_average'][0]) : 0; } } if ($post_ratings_score == 0 || $post_ratings_users == 0) { $post_ratings = 0; $post_ratings_average = 0; $post_ratings_percentage = 0; } else { $post_ratings = round($post_ratings_average, 1); $post_ratings_percentage = round($post_ratings_score / $post_ratings_users / $ratings_max * 100, 2); } $post_ratings_text = '<span class="post-ratings-text" id="ratings_' . $post_id . '_text"></span>'; // Get the image's alt text if ($ratings_custom && $ratings_max == 2) { if ($post_ratings_score > 0) { $post_ratings_score = '+' . $post_ratings_score; } $post_ratings_alt_text = sprintf(_n('%s rating', '%s rating', $post_ratings_score, 'wp-postratings'), number_format_i18n($post_ratings_score)) . __(',', 'wp-postratings') . ' ' . sprintf(_n('%s vote', '%s votes', $post_ratings_users, 'wp-postratings'), number_format_i18n($post_ratings_users)); } else { $post_ratings_score = number_format_i18n($post_ratings_score); $post_ratings_alt_text = sprintf(_n('%s vote', '%s votes', $post_ratings_users, 'wp-postratings'), number_format_i18n($post_ratings_users)) . __(',', 'wp-postratings') . ' ' . __('average', 'wp-postratings') . ': ' . number_format_i18n($post_ratings_average, 2) . ' ' . __('out of', 'wp-postratings') . ' ' . number_format_i18n($ratings_max); } // Check for half star $insert_half = 0; $average_diff = abs(floor($post_ratings_average) - $post_ratings); if ($average_diff >= 0.25 && $average_diff <= 0.75) { $insert_half = ceil($post_ratings_average); } elseif ($average_diff > 0.75) { $insert_half = ceil($post_ratings); } // Replace the variables $value = $template; if (strpos($template, '%RATINGS_IMAGES%') !== false) { $post_ratings_images = get_ratings_images($ratings_custom, $ratings_max, $post_ratings, $ratings_image, $post_ratings_alt_text, $insert_half); $value = str_replace("%RATINGS_IMAGES%", $post_ratings_images, $value); } if (strpos($template, '%RATINGS_IMAGES_VOTE%') !== false) { $ratings_texts = get_option('postratings_ratingstext'); $post_ratings_images = get_ratings_images_vote($post_id, $ratings_custom, $ratings_max, $post_ratings, $ratings_image, $post_ratings_alt_text, $insert_half, $ratings_texts); $value = str_replace("%RATINGS_IMAGES_VOTE%", $post_ratings_images, $value); } $value = str_replace("%RATINGS_ALT_TEXT%", $post_ratings_alt_text, $value); $value = str_replace("%RATINGS_TEXT%", $post_ratings_text, $value); $value = str_replace("%RATINGS_MAX%", number_format_i18n($ratings_max), $value); $value = str_replace("%RATINGS_SCORE%", $post_ratings_score, $value); $value = str_replace("%RATINGS_AVERAGE%", number_format_i18n($post_ratings_average, 2), $value); $value = str_replace("%RATINGS_PERCENTAGE%", number_format_i18n($post_ratings_percentage, 2), $value); $value = str_replace("%RATINGS_USERS%", number_format_i18n($post_ratings_users), $value); // Post Template Variables $post_link = get_permalink($post_data); $post_title = get_the_title($post_data); if ($max_post_title_chars > 0) { $post_title = snippet_text($post_title, $max_post_title_chars); } $value = str_replace("%POST_ID%", $post_id, $value); $value = str_replace("%POST_TITLE%", $post_title, $value); $value = str_replace("%POST_URL%", $post_link, $value); if (strpos($template, '%POST_EXCERPT%') !== false) { if (get_the_ID() != $post_id) { $post =& get_post($post_id); } $post_excerpt = ratings_post_excerpt($post_id, $post->post_excerpt, $post->post_content, $post->post_password); $value = str_replace("%POST_EXCERPT%", $post_excerpt, $value); } if (strpos($template, '%POST_CONTENT%') !== false) { if (get_the_ID() != $post_id) { $post =& get_post($post_id); } $value = str_replace("%POST_CONTENT%", get_the_content(), $value); } // Google Rich Snippet $ratings_options['richsnippet'] = isset($ratings_options['richsnippet']) ? $ratings_options['richsnippet'] : 1; if ($ratings_options['richsnippet'] && (is_single() || is_page()) && $is_main_loop && $post_ratings_average > 0) { $itemtype = apply_filters('wp_postratings_schema_itemtype', 'itemscope itemtype="http://schema.org/Article"'); if (empty($post_excerpt)) { $post_excerpt = ratings_post_excerpt($post_id, $post->post_excerpt, $post->post_content, $post->post_password); } $post_meta = '<meta itemprop="headline" content="' . esc_attr($post_title) . '" />'; $post_meta .= '<meta itemprop="description" content="' . wp_kses($post_excerpt, array()) . '" />'; $post_meta .= '<meta itemprop="datePublished" content="' . get_the_time('c') . '" />'; $post_meta .= '<meta itemprop="url" content="' . $post_link . '" />'; if (has_post_thumbnail()) { $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(null)); if (!empty($thumbnail)) { $post_meta .= '<meta itemprop="image" content="' . $thumbnail[0] . '" />'; } } $ratings_meta = '<div style="display: none;" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">'; $ratings_meta .= '<meta itemprop="bestRating" content="' . $ratings_max . '" />'; $ratings_meta .= '<meta itemprop="worstRating" content="1" />'; $ratings_meta .= '<meta itemprop="ratingValue" content="' . $post_ratings_average . '" />'; $ratings_meta .= '<meta itemprop="ratingCount" content="' . $post_ratings_users . '" />'; $ratings_meta .= '</div>'; $value = empty($itemtype) ? $value . $ratings_meta : $value . $post_meta . $ratings_meta; } return apply_filters('expand_ratings_template', $value); }
function get_mostemailed($mode = '', $limit = 10, $chars = 0, $echo = true) { global $wpdb, $post; $temp_post = $post; $where = ''; $temp = ''; if (!empty($mode) && $mode != 'both') { $where = "post_type = '{$mode}'"; } else { $where = '1=1'; } $mostemailed = $wpdb->get_results("SELECT {$wpdb->posts}.*, COUNT({$wpdb->email}.email_postid) AS email_total FROM {$wpdb->email} LEFT JOIN {$wpdb->posts} ON {$wpdb->email}.email_postid = {$wpdb->posts}.ID WHERE post_date < '" . current_time('mysql') . "' AND {$where} AND post_password = '' AND post_status = 'publish' GROUP BY {$wpdb->email}.email_postid ORDER BY email_total DESC LIMIT {$limit}"); if ($mostemailed) { if ($chars > 0) { foreach ($mostemailed as $post) { $post_title = get_the_title(); $email_total = intval($post->email_total); $temp .= "<li><a href=\"" . get_permalink() . "\">" . snippet_text($post_title, $chars) . "</a> - " . sprintf(_n('%s email', '%s emails', $email_total, 'wp-email'), number_format_i18n($email_total)) . "</li>\n"; } } else { foreach ($mostemailed as $post) { $post_title = get_the_title(); $email_total = intval($post->email_total); $temp .= "<li><a href=\"" . get_permalink() . "\">{$post_title}</a> - " . sprintf(_n('%s email', '%s emails', $email_total, 'wp-email'), number_format_i18n($email_total)) . "</li>\n"; } } } else { $temp = '<li>' . __('N/A', 'wp-email') . '</li>' . "\n"; } $post = $temp_post; if ($echo) { echo $temp; } else { return $temp; } }
function expand_ratings_template($template, $post_id, $post_ratings_data = null, $max_post_title_chars = 0) { global $post; global $txt_vote; global $txt_votes; global $txt_average; global $txt_out_of; $temp_post = $post; // Get global variables $ratings_image = get_option('postratings_image'); $ratings_max = intval(get_option('postratings_max')); $ratings_custom = intval(get_option('postratings_customrating')); // Get post related variables if (is_null($post_ratings_data)) { # Orig: #$post_ratings_data = get_post_custom($post_id); #get data from PriceDB $post_ratings_data = lhg_get_post_ratings_data($post_id); # Orig: #$post_ratings_users = intval($post_ratings_data['ratings_users'][0]); #$post_ratings_score = intval($post_ratings_data['ratings_score'][0]); #$post_ratings_average = floatval($post_ratings_data['ratings_average'][0]); $post_ratings_users = intval($post_ratings_data['ratings_users']); $post_ratings_score = intval($post_ratings_data['ratings_score']); $post_ratings_average = floatval($post_ratings_data['ratings_average']); } else { $post_ratings_users = intval($post_ratings_data->ratings_users); $post_ratings_score = intval($post_ratings_data->ratings_score); $post_ratings_average = floatval($post_ratings_data->ratings_average); } if ($post_ratings_score == 0 || $post_ratings_users == 0) { $post_ratings = 0; $post_ratings_average = 0; $post_ratings_percentage = 0; } else { $post_ratings = round($post_ratings_average, 1); $post_ratings_percentage = round($post_ratings_score / $post_ratings_users / $ratings_max * 100, 1); } $post_ratings_text = '<span class="post-ratings-text" id="ratings_' . $post_id . '_text"></span>'; // Get the image's alt text if ($ratings_custom && $ratings_max == 2) { if ($post_ratings_score > 0) { $post_ratings_score = '+' . $post_ratings_score; } $post_ratings_alt_text = sprintf(_n('%s ' . $txt_vote, '%s ' . $txt_vote, $post_ratings_score, 'wp-postratings'), number_format_i18n($post_ratings_score)) . __(',', 'wp-postratings') . ' ' . sprintf(_n('%s ' . $txt_vote, '%s ' . $txt_votes, $post_ratings_users, 'wp-postratings'), number_format_i18n($post_ratings_users)); } else { $post_ratings_score = number_format_i18n($post_ratings_score); $post_ratings_alt_text = sprintf(_n('%s ' . $txt_vote, '%s ' . $txt_votes, $post_ratings_users, 'wp-postratings'), number_format_i18n($post_ratings_users)) . __(',', 'wp-postratings') . ' ' . __($txt_average, 'wp-postratings') . ': ' . number_format_i18n($post_ratings_average, 1) . ' ' . __($txt_out_of, 'wp-postratings') . ' ' . number_format_i18n($ratings_max); } // Check for half star $insert_half = 0; $average_diff = abs(floor($post_ratings_average) - $post_ratings); if ($average_diff >= 0.25 && $average_diff <= 0.75) { $insert_half = ceil($post_ratings_average); } elseif ($average_diff > 0.75) { $insert_half = ceil($post_ratings); } // Replace the variables $value = $template; if (strpos($template, '%RATINGS_IMAGES%') !== false) { $post_ratings_images = get_ratings_images($ratings_custom, $ratings_max, $post_ratings, $ratings_image, $post_ratings_alt_text, $insert_half); $value = str_replace("%RATINGS_IMAGES%", $post_ratings_images, $value); } if (strpos($template, '%RATINGS_IMAGES_VOTE%') !== false) { $ratings_texts = get_option('postratings_ratingstext'); $post_ratings_images = get_ratings_images_vote($post_id, $ratings_custom, $ratings_max, $post_ratings, $ratings_image, $post_ratings_alt_text, $insert_half, $ratings_texts); $value = str_replace("%RATINGS_IMAGES_VOTE%", $post_ratings_images, $value); //$value .= "AA"; } //$image = self::get_post_image($post_id,$imgsize) ; $image = get_the_post_thumbnail($post_id); if (strpos($template, '%POST_IMAGE%') !== false) { $post_link = get_permalink($post_id); $value = str_replace("%POST_IMAGE%", '<a href="' . $post_link . '">' . $image . "</a>", $value); } if (strpos($template, '%PRICE%') !== false) { //$myFile = "/home/wordpressftp/amazon.txt"; //$fh = fopen($myFile, 'a') or die("can't open file"); //$stringData = $post->ID.";".$newPrice."\n"; //fwrite($fh, $stringData); //fclose($fh); $myFile = "/home/wordpressftp/amazon.txt"; $file = file($myFile); $file = array_reverse($file); foreach ($file as $f) { if (strpos($f, $post_id) !== false) { $out = "OUT:" . $post_id . ":" . $f . " "; $price = explode(";", $f); //return chop($price[1]); } else { } } $value = str_replace("%PRICE%", chop($price[1]), $value); } $value = str_replace("%RATINGS_ALT_TEXT%", $post_ratings_alt_text, $value); $value = str_replace("%RATINGS_TEXT%", $post_ratings_text, $value); $value = str_replace("%RATINGS_MAX%", number_format_i18n($ratings_max), $value); $value = str_replace("%RATINGS_SCORE%", $post_ratings_score, $value); $value = str_replace("%RATINGS_AVERAGE%", number_format_i18n($post_ratings_average, 2), $value); $value = str_replace("%RATINGS_PERCENTAGE%", number_format_i18n($post_ratings_percentage, 2), $value); $value = str_replace("%RATINGS_USERS%", number_format_i18n($post_ratings_users), $value); if (strpos($template, '%POST_URL%') !== false) { $post_link = get_permalink($post_id); $value = str_replace("%POST_URL%", $post_link, $value); } if (strpos($template, '%POST_TITLE%') !== false) { $post_title = get_the_title($post_id); if ($max_post_title_chars > 0) { $post_title = snippet_text($post_title, $max_post_title_chars); } $value = str_replace("%POST_TITLE%", $post_title, $value); } if (strpos($template, '%POST_EXCERPT%') !== false) { if ($post->ID != $post_id) { $post =& get_post($post_id); } $post_excerpt = ratings_post_excerpt($post_id, $post->post_excerpt, $post->post_content, $post->post_password); $value = str_replace("%POST_EXCERPT%", $post_excerpt, $value); } if (strpos($template, '%POST_CONTENT%') !== false) { if ($post->ID != $post_id) { $post =& get_post($post_id); } $value = str_replace("%POST_CONTENT%", get_the_content(), $value); } // Return value $post = $temp_post; return apply_filters('expand_ratings_template', htmlspecialchars_decode($value)); }
function get_downloads_category($cat_id = 0, $limit = 10, $chars = 0, $display = true) { global $wpdb, $user_ID; if (is_array($cat_id)) { $category_sql = "file_category IN (" . join(',', $cat_id) . ')'; } else { $category_sql = "file_category = {$cat_id}"; } $output = ''; $files = $wpdb->get_results("SELECT * FROM {$wpdb->downloads} WHERE {$category_sql} AND file_permission != -2 ORDER BY file_date DESC LIMIT {$limit}"); if ($files) { $current_user = wp_get_current_user(); $file_extensions_images = file_extension_images(); $download_categories = get_option('download_categories'); $template_download_most_temp = get_option('download_template_most'); foreach ($files as $file) { $file_permission = intval($file->file_permission); $template_download_most = $template_download_most_temp; if ($file_permission > 0 && intval($current_user->wp_user_level) >= $file_permission && intval($user_ID) > 0 || $file_permission == 0 && intval($user_ID) > 0 || $file_permission == -1) { $template_download_most = stripslashes($template_download_most[0]); } else { $template_download_most = stripslashes($template_download_most[1]); } if ($chars > 0) { $file_name = snippet_text(stripslashes($file->file_name), $chars); } else { $file_name = stripslashes($file->file_name); } $template_download_most = str_replace("%FILE_ID%", $file->file_id, $template_download_most); $template_download_most = str_replace("%FILE%", stripslashes($file->file), $template_download_most); $template_download_most = str_replace("%FILE_NAME%", $file_name, $template_download_most); $template_download_most = str_replace("%FILE_EXT%", file_extension(stripslashes($file->file)), $template_download_most); $template_download_most = str_replace("%FILE_ICON%", file_extension_image(stripslashes($file->file), $file_extensions_images), $template_download_most); $template_download_most = str_replace("%FILE_DESCRIPTION%", stripslashes($file->file_des), $template_download_most); $template_download_most = str_replace("%FILE_SIZE%", format_filesize($file->file_size), $template_download_most); $template_download_most = str_replace("%FILE_SIZE_DEC%", format_filesize_dec($file->file_size), $template_download_most); $template_download_most = str_replace("%FILE_CATEGORY_ID%", intval($file->file_category), $template_download_most); $template_download_most = str_replace("%FILE_CATEGORY_NAME%", stripslashes($download_categories[intval($file->file_category)]), $template_download_most); $template_download_most = str_replace("%FILE_DATE%", mysql2date(get_option('date_format'), gmdate('Y-m-d H:i:s', $file->file_date)), $template_download_most); $template_download_most = str_replace("%FILE_TIME%", mysql2date(get_option('time_format'), gmdate('Y-m-d H:i:s', $file->file_date)), $template_download_most); $template_download_most = str_replace("%FILE_UPDATED_DATE%", mysql2date(get_option('date_format'), gmdate('Y-m-d H:i:s', $file->file_updated_date)), $template_download_most); $template_download_most = str_replace("%FILE_UPDATED_TIME%", mysql2date(get_option('time_format'), gmdate('Y-m-d H:i:s', $file->file_updated_date)), $template_download_most); $template_download_most = str_replace("%FILE_HITS%", number_format_i18n($file->file_hits), $template_download_most); $template_download_most = str_replace("%FILE_DOWNLOAD_URL%", download_file_url($file->file_id, $file->file), $template_download_most); $output .= $template_download_most; } } else { $output = '<li>' . __('N/A', 'wp-downloadmanager') . '</li>' . "\n"; } if ($display) { echo $output; } else { return $output; } }
/** * 获取浏览次数最多的文章列表 * 目前没有用 */ public function get_most_viewed($mode = '', $limit = 10, $chars = 0, $display = true) { global $wpdb; $views_options = get_option('views_options'); $where = ''; $temp = ''; $output = ''; if (!empty($mode) && $mode != 'both') { if (is_array($mode)) { $mode = implode("','", $mode); $where = "post_type IN ('" . $mode . "')"; } else { $where = "post_type = '{$mode}'"; } } else { $where = '1=1'; } $most_viewed = $wpdb->get_results("SELECT DISTINCT {$wpdb->posts}.*, (meta_value+0) AS views FROM {$wpdb->posts} LEFT JOIN {$wpdb->postmeta} ON {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID WHERE post_date < '" . current_time('mysql') . "' AND {$where} AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT {$limit}"); if ($most_viewed) { foreach ($most_viewed as $post) { $post_views = intval($post->views); $post_title = get_the_title($post); if ($chars > 0) { $post_title = snippet_text($post_title, $chars); } $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars); } } else { } }
$file_time = mysql2date(get_option('time_format'), gmdate('Y-m-d H:i:s', $file->file_date)); $file_updated_date = mysql2date(get_option('date_format'), gmdate('Y-m-d H:i:s', $file->file_updated_date)); $file_updated_time = mysql2date(get_option('time_format'), gmdate('Y-m-d H:i:s', $file->file_updated_date)); $file_last_downloaded_date = mysql2date(get_option('date_format'), gmdate('Y-m-d H:i:s', $file->file_last_downloaded_date)); $file_last_downloaded_time = mysql2date(get_option('time_format'), gmdate('Y-m-d H:i:s', $file->file_last_downloaded_date)); $file_hits = intval($file->file_hits); $file_permission = file_permission($file->file_permission); $file_name_actual = basename($file_name); if ($i % 2 == 0) { $style = ''; } else { $style = ' class="alternate"'; } echo "<tr{$style}>\n"; echo '<td valign="top">' . number_format_i18n($file_id) . '</td>' . "\n"; echo "<td>{$file_nicename}<br /><strong>»</strong> <i dir=\"ltr\">" . snippet_text($file_name, 45) . "</i><br /><br /><i>" . sprintf(__('Last Updated: %s, %s', 'wp-downloadmanager'), $file_updated_time, $file_updated_date) . "</i><br /><i>" . sprintf(__('Last Downloaded: %s, %s', 'wp-downloadmanager'), $file_last_downloaded_time, $file_last_downloaded_date) . "</i></td>\n"; echo '<td style="text-align: center;">' . format_filesize($file_size) . '</td>' . "\n"; echo '<td style="text-align: center;">' . number_format_i18n($file_hits) . '</td>' . "\n"; echo '<td style="text-align: center;">' . $file_permission . '</td>' . "\n"; echo '<td style="text-align: center;">' . $file_categories[$file_cat] . '</td>' . "\n"; echo "<td>{$file_time}, {$file_date}</td>\n"; echo "<td style=\"text-align: center;\"><a href=\"{$base_page}&mode=edit&id={$file_id}\" class=\"edit\">" . __('Edit', 'wp-downloadmanager') . "</a></td>\n"; echo "<td style=\"text-align: center;\"><a href=\"{$base_page}&mode=delete&id={$file_id}\" class=\"delete\">" . __('Delete', 'wp-downloadmanager') . "</a></td>\n"; echo '</tr>'; $i++; } } else { echo '<tr><td colspan="9" align="center"><strong>' . __('No Files Found', 'wp-downloadmanager') . '</strong></td></tr>'; } ?> </table>
function get_post_category_list($mode = '', $view_type = 'normal', $output_type = 'content', $time_span = 'total', $order_type = 'views', $order_by = 'DESC', $limit = 10, $chars = 0) { global $wpdb, $post; for ($i = 0; $i < $limit; $i++) { $pv_views[$i] = array('title' => '', 'views' => '', 'time' => ''); } if (!empty($mode) && $mode != 'both') { $mode = "post_type = '{$mode}'"; } else { $mode = '1=1'; } if ($time_span == 'today') { $time_span = 'post_views_today'; } else { if ($time_span == 'week') { $time_span = 'post_views_week'; } else { if ($time_span == 'month') { $time_span = 'post_views_month'; } else { if ($time_span == 'halfyear') { $time_span = 'post_views_halfyear'; } else { if ($time_span == 'year') { $time_span = 'post_views_year'; } else { $time_span = 'post_views_total'; } } } } } $user_cat_tag = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) INNER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id and {$wpdb->term_taxonomy}.taxonomy = 'category') INNER JOIN {$wpdb->terms} ON ( {$wpdb->terms}.term_id = {$wpdb->term_taxonomy}.term_id) "; $groupby = " group by {$wpdb->term_taxonomy}.term_id"; $order_by = strtolower($order_by); if ($orderby != 'asc') { $orderby = 'desc'; } $sql = "SELECT {$wpdb->terms}.term_id as id, {$wpdb->terms}.name as name, sum(" . $time_span . " + 0) AS views, latest_view_time FROM {$wpdb->posts} LEFT JOIN " . WP_POST_VIEWS_TABLE . " ON " . WP_POST_VIEWS_TABLE . ".post_id = {$wpdb->posts}.ID {$user_cat_tag} WHERE post_date < '" . current_time('mysql') . "' AND post_status = 'publish' AND " . WP_POST_VIEWS_TABLE . ".view_type = '" . $view_type . "' AND " . WP_POST_VIEWS_TABLE . ".output_type = '" . $output_type . "' AND {$mode} AND post_password = '' {$groupby} ORDER BY {$order_type} {$order_by} LIMIT {$limit}"; $post_viewed = $wpdb->get_results($sql); $count = 0; if ($post_viewed) { foreach ($post_viewed as $post) { $post_views = intval($post->views); $post_title = $post->name; if ($chars > 0) { if (!function_exists('cut_str')) { $post_title = snippet_text($post_title, $chars); } else { $post_title = cut_str($post_title, $chars); } } $pv_views[$count] = array('title' => '<a href="' . get_category_link($post->id) . '" class="dashedline" >' . $post_title . '</a>', 'views' => number_format($post_views), 'time' => "", 'post_id' => ""); $count++; } } return $pv_views; }