All pastes #519796 Raw Edit

Unnamed

public php v1 · immutable
#519796 ·published 2007-05-29 19:27 UTC
rendered paste body
function fd_hot_list($type = '', $timescale = 'today', $offset = 0, $length = 5, $cat = '') {	$time_start = ''; $time_end = time();	switch($timescale) {		case 'today': $time_start = $time_end - (60 * 60 * 24); break;		case 'week': $time_start = $time_end - (60 * 60 * 24 * 7); break;		case 'month': $time_start = $time_end - (60 * 60 * 24 * 30); break;		case 'ever': $time_start = '';	}	if($time_start != '') $time_start = fd_dt2sql($time_start); $time_end = fd_dt2sql($time_end);		if($type = 'hits') {		$top_hits = fd_hot_tophits($time_start, $time_end, $offset, $length, $cat);		echo "<ul>";		foreach($top_hits as $post_id => $counts) {			echo "<li><a href='".get_permalink($post_id)."'>".get_the_title($post_id)."</a> ($counts views)</li>";		}		echo "</ul>";	}}function fd_hot_tophits($time_start = '', $time_end = '', $offset = 0, $length = 5, $cat = '') {	global $wpdb; $tbl = $wpdb->prefix.'hot_hits';		$timescale = "'1'";	if($time_start != '') {		$timescale .= " and date > '$time_start'";	}	if($time_end != '') {		$timescale .= " and date < '$time_end'";	}	$query = "SELECT post_id FROM $tbl WHERE $timescale";	$results = $wpdb->get_col($query);	foreach($results as $result) { $hitcounts[$result] = $hitcounts[$result] + 1; }	arsort($hitcounts); //$sorted_ids = array_keys($hitcounts);	if($length > count($hitcounts)) $length = count($hitcounts);	return array_slice($hitcounts, $offset, $length, true);}