'SORT',
'auto_activate' => FALSE,
'requires_pair' => TRUE,
'load_function' => 'data_sort',
'title' => 'Sort',
'help_page' => 'DataPluginSort',
'description' => tra( "This plugin will sort the lines within a {sort} block." ),
'help_function' => 'data_sort_help',
'syntax' => "{sort sort= }".tra( "Lines to be sorted" )."{sort}",
'plugin_type' => DATA_PLUGIN
);
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATASORT, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATASORT );
/**
* Help Function
*/
function data_sort_help() {
$help ='
| '.tra( 'Key' ).' |
'.tra( 'Value' ).' |
'.tra( 'Comments' ).' |
| '.'sort' .' |
'.tra( "key-words").' '.tra("(optional)").' |
'.tra( 'Will sort the lines in the desired direction. Choices are:' ).'asc, desc, reverse, shuffle'.tra( 'Default:' ).'asc'.' |
'.
tra( "Example: " ).'{sort sort=shuffle}
Line 1
Line 2
Line 3
{sort}';
return $help;
}
/**
* Load Function
*/
function data_sort( $pData, $pParams, $pCommonObject, $pParseHash ) {
$sort = ( !empty( $pParams['sort'] )) ? $pParams['sort'] : 'asc';
$lines = explode( "\n", $pData );
if( $sort == "asc" ) {
sort( $lines );
} elseif( $sort == "desc" ) {
rsort( $lines );
} elseif( $sort == "reverse" ) {
$lines = array_reverse( $lines );
} elseif( $sort == "shuffle" ) {
srand(( float )microtime() * 1000000 );
shuffle( $lines );
}
reset( $lines );
if( is_array( $lines )) {
$pData = implode( "\n", $lines );
}
$parseHash['content_id'] = $pParseHash['content_id'];
$parseHash['user_id'] = $pParseHash['user_id'];
$parseHash['no_cache'] = TRUE;
$parseHash['data'] = trim( $pData );
return $pCommonObject->parseData( $parseHash );
}
?>