liberty
[ class tree: liberty ] [ index: liberty ] [ all elements ]

Source for file data.sort.php

Documentation is available at data.sort.php

  1. <?php
  2. /**
  3.  * This plugin will sort the lines within a {sort} block
  4.  *
  5.  * @package  liberty
  6.  * @subpackage plugins_data
  7.  */
  8.  
  9. /**
  10.  * definitions
  11.  */
  12. define( 'PLUGIN_GUID_DATASORT', 'datasort' );
  13. global $gLibertySystem;
  14. $pluginParams = array (
  15.     'tag'           => 'SORT',
  16.     'auto_activate' => FALSE,
  17.     'requires_pair' => TRUE,
  18.     'load_function' => 'data_sort',
  19.     'title'         => 'Sort',
  20.     'help_page'     => 'DataPluginSort',
  21.     'description'   => tra( "This plugin will sort the lines within a {sort} block." ),
  22.     'help_function' => 'data_sort_help',
  23.     'syntax'        => "{sort sort= }".tra( "Lines to be sorted" )."{sort}",
  24.     'plugin_type'   => DATA_PLUGIN
  25. );
  26. $gLibertySystem->registerPlugin( PLUGIN_GUID_DATASORT, $pluginParams );
  27. $gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATASORT );
  28.  
  29. /**
  30.  * Help Function
  31.  */
  32. function data_sort_help() {
  33.     $help ='
  34.         <table class="data help">
  35.             <tr>
  36.                 <th>'.tra( 'Key' ).'</th>
  37.                 <th>'.tra( 'Value' ).'</th>
  38.                 <th>'.tra( 'Comments' ).'</th>
  39.             </tr>
  40.             <tr class="even">
  41.                 <td>'.'sort' .'</td>
  42.                 <td>'.tra( "key-words").'<br />'.tra("(optional)").'</td>
  43.                 <td>'.tra( 'Will sort the lines in the desired direction.  Choices are:' ).'<strong>asc</strong>, <strong>desc</strong>, <strong>reverse</strong>, <strong>shuffle</strong>'.tra( 'Default:' ).'<strong>asc</strong>'.'</td>
  44.             </tr>
  45.         </table>'.
  46.         tra( "Example: " ).'{sort sort=shuffle}<br />Line 1<br />Line 2<br />Line 3<br />{sort}';
  47.     return $help;
  48. }
  49.  
  50. /**
  51.  * Load Function - data_sort
  52.  * 
  53.  * @param pData string
  54.  * @param pParams array
  55.  * @param pCommonObject object
  56.  * @param pParseHash array
  57.  */
  58. function data_sort( $pData, $pParams, $pCommonObject, $pParseHash ) {
  59.     $sort = ( !empty( $pParams['sort'] )) ? $pParams['sort'] : 'asc';
  60.     $lines = explode( "\n", $pData );
  61.     if( $sort == "asc" ) {
  62.         sort( $lines );
  63.     } elseif( $sort == "desc" ) {
  64.         rsort( $lines );
  65.     } elseif( $sort == "reverse" ) {
  66.         $lines = array_reverse( $lines );
  67.     } elseif( $sort == "shuffle" ) {
  68.         srand(( float )microtime() * 1000000 );
  69.         shuffle( $lines );
  70.     }
  71.     reset( $lines );
  72.     if( is_array( $lines )) {
  73.         $pData = implode( "\n", $lines );
  74.     }
  75.  
  76.     $parseHash['content_id'] = $pParseHash['content_id'];
  77.     $parseHash['user_id']    = $pParseHash['user_id'];
  78.     $parseHash['no_cache']   = TRUE;
  79.     $parseHash['data']       = trim( $pData );
  80.     return $pCommonObject->parseData( $parseHash );
  81. }
  82. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:21 +0000 by phpDocumentor 1.5.0-lsces