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

Source for file filter.backtotop.php

Documentation is available at filter.backtotop.php

  1. <?php
  2. /**
  3.  * @version  $Header$
  4.  * @package  liberty
  5.  * @subpackage plugins_filter
  6.  */
  7.  
  8. /**
  9.  * definitions ( guid character limit is 16 chars )
  10.  */
  11. define'PLUGIN_GUID_FILTERBACKTOTOP''filterbacktotop' );
  12.  
  13. global $gLibertySystem;
  14.  
  15. $pluginParams array (
  16.     'title'              => 'Back to Top',
  17.     'description'        => 'Add back to top link to headers.<br />We recommend that you add something like this to your CSS file:<br /><code>a.backtotop {display:block;text-align:right;}</code>',
  18.     'auto_activate'      => FALSE,
  19.     'plugin_type'        => FILTER_PLUGIN,
  20.  
  21.     // filter functions
  22.     'postparse_function' => 'backtotop_postparsefilter',
  23.  
  24.     // these settings are to get the plugin help working on content edit pages
  25.     'tag'                => 'backtotop',
  26.     'help_page'          => 'FilterPluginBacktoTop',
  27.     'help_function'      => 'backtotop_help',
  28.     'syntax'             => '{backtotop}',
  29. );
  30. $gLibertySystem->registerPluginPLUGIN_GUID_FILTERBACKTOTOP$pluginParams );
  31.  
  32. function backtotop_postparsefilter&$pData&$pFilterHash {
  33.     global $gBitSmarty;
  34.     ifpreg_match"/\{(backtotop[^\}]*)\}/i"$pData$backtotop )) {
  35.         // remove {backtotop} from page
  36.         $pData preg_replace'#(<p>)?'.preg_quote$backtotop[0]'#' ).'(</p>)?(\s*<[Bb][Rr]\s*/?>)?#'''$pData );
  37.         // default values
  38.         $params['min'1;
  39.         $params['max'6;
  40.         $params array_merge$paramsparse_xml_attributes$backtotop[1));
  41.  
  42.         $gBitSmarty->loadPlugin'smarty_function_biticon' );
  43.         $biticon array(
  44.             'ipackage' => 'icons',
  45.             'iname'    => 'go-top',
  46.             'iexplain' => 'Back to top',
  47.         );
  48.  
  49.         // get all headers into an array
  50.         preg_match_all"/<h(\d[^>]*)>.*?<\/h\d>/i"$pData$headers );
  51.         $link '<a class="backtotop" href="#content">'.smarty_function_biticon$biticon$gBitSmarty ).'</a>';
  52.         foreach$headers[0as $key => $header {
  53.             if$headers[1][$key>= $params['min'&& $headers[1][$key<= $params['max'{
  54.                 $pData str_replace$header$link.$header$pData );
  55.             }
  56.         }
  57.         $pData .= $link;
  58.     }
  59. }
  60.  
  61. function backtotop_help({
  62.     return
  63.         '<table class="data help">
  64.             <tr>
  65.                 <th>'.tra"Key" ).'</th>
  66.                 <th>'.tra"Type" ).'</th>
  67.                 <th>'.tra"Comments" ).'</th>
  68.             </tr>
  69.             <tr class="even">
  70.                 <td>min</td>
  71.                 <td>'.tra"numeric").'<br />('.tra("optional").')</td>
  72.                 <td>'.tra'If you specify 2 here, backtotop will only add links from h2 to h6 level.' ).'</td>
  73.             </tr>
  74.             <tr class="odd">
  75.                 <td>max</td>
  76.                 <td>'.tra"numeric").'<br />('.tra("optional").')</td>
  77.                 <td>'.tra'If you specify 3 here, backtotop will only add links from h1 to h3 level.' ).'</td>
  78.             </tr>
  79.         </table>'.
  80.         tra("Example: ").'{backtotop min=2 max=3}';
  81. }
  82. ?>

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