Location: PHPKode > projects > cutenews aj-fork > 167/plugins/sort-by-xfield.php
<?php

/*
Plugin Name:	Sort By Xfield
Plugin URI:		http://www.xs4all.nl/~cvdtak/sortbyxfield_1.0.htm
Description:	Sorts the outputted news by an Xfield value
Version:		1.0
Author:			StealthEye

Application:	CuteNews
Required Framework: 1.0.0


	NOTE: This plugin requires that you already have the Xfields hack.

*/

add_filter('news-recordset','sort_by_xfields');

function sortcmp_xfields($a, $b) {
	global $xfieldsdata, $sortbyxfield, $all_news;

	// Get the news ID of both entries
	$news_a = explode('|', $all_news[$a]);
	$news_b = explode('|', $all_news[$b]);
	$newsid_a = $news_a[0];
	$newsid_b = $news_b[0];

	// Compare the Xfield values for each entry
	return strnatcasecmp($xfieldsdata[$newsid_a][$sortbyxfield], $xfieldsdata[$newsid_b][$sortbyxfield]);
}

function sort_by_xfields($all_news, $hookname) {
	global $sortbyxfield, $cutepath, $xfieldsaction, $xfieldsdata;

	// If the user has specified a "Sort By" field
	if (isset($sortbyxfield)) {
	
		// Make sure Xfields doesn't try to perform any special operations
		$xfieldsaction = 'noop';
		
		// Cause an error if xfields can't be loaded
		if (!is_file($cutepath.'/inc/xfields.mdu'))
			die('<p>Error loading Xfields.mdu</p>');

		// Include xfields
		#include_once($cutepath.'/inc/xfields.mdu');
		
		// Load Xfield information
		$xfieldsdata = xfieldsdataload();
		
		// Run the custom sort function
		uksort($all_news, 'sortcmp_xfields');
	}
	
	// return the news entries
	return $all_news;
}

?>
Return current item: cutenews aj-fork