Pastoid

The page you are looking at now is at this URL: http://pastoid.com/byd

This paste was last updated on December 1, 2009 at 11:33 pm.

Pasted Coderaw

<?php
/**
 * @package Habari
 *
 */
 
class SortedPosts extends Posts
{
 
	/**
	 * At the moment, accepts:
	 * - 'dummy'
	 * - 'views'
	 */
	public static function get($paramarray = array(), $cb = 'dummy')
	{
		if (is_string($cb))
		{
			if (is_callable(array('SortedPosts', 'cmp_' . $type)))
			{
				$cb = array('SortedPosts', 'cmp_' . $type);
			} else {
				$cb = array('SortedPosts', 'cmp_dummy');
			}
		} else if (is_callable($cb))
		{
			// us it directly
		} else {
			// fall back
			$cb = array('SortedPosts', 'cmp_dummy');
		}
 
		$posts = parent::get($paramarray);
		$success = uasort($posts, $cb);
		return $posts;
	}
 
	public static function get_in_order($paramarray = array(), $idorder = array())
	{
		$posts = parent::get($paramarray);
		$maxPosts = count($posts);
 
		foreach($posts as $post)
		{
			$index = array_search($post->id, $idorder);
			$post->info->sort_order = ($index === FALSE) ? $maxPosts : $index;
			// error_log("Assigned " . (($index === FALSE) ? $maxPosts : $index) . " to " . $post->title);
		}
 
		$success = uasort($posts, array('SortedPosts', 'cmp_presort'));
		return $posts;
	}
 
	public static function cmp_presort($a, $b)
	{
		return ($a->info->sort_order < $b->info->sort_order) ? -1 : 1;
	}
 
	public static function cmp_views($a, $b)
	{
		$aview = ($a->viewcount) ? $a->viewcount : 0;
		$bview = ($b->viewcount) ? $b->viewcount : 0;
		// default to descending
		return ($aview > $bview) ? -1 : 1;
	}
 
 
	public static function cmp_dummy($a, $b)
	{
		return 1;
	}
 
}
?>
 

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 12
www.google.com 1
Is this paste spam?
<Hide