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

Source for file function.pagerabc.php

Documentation is available at function.pagerabc.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @link http://www.zikula.org
  6.  * @version $Id: function.pagerabc.php 24342 2008-06-06 12:03:14Z markwest $
  7.  * @author Peter Dudas <duda at bigfish dot hu>
  8.  * @package Zikula_Template_Plugins
  9.  * @subpackage Functions
  10.  */
  11.  
  12. /**
  13. * Smarty plugin
  14. * -------------------------------------------------------------
  15. * Type:     function
  16. * Name:     pagerabc
  17. * Purpose:  Displays alphabetical selection links
  18. * Version:  1.1
  19. * Date:     April 30, 2005
  20. * Author:   Peter Dudas <duda at bigfish dot hu>
  21. *           Martin Andersen; API links for ShortURL compliance
  22. * -------------------------------------------------------------
  23. *  Changes:   2002/09/25                 - created
  24. *             2005/04/30   msandersen    - Added Span with Pager class, uses API for links when link to API module, various tweaks
  25. *             2005/08/20   msandersen    - Changed forwardvars behaviour to be consistent with pager plugin:
  26. *                                          If forwardvars is not set, ALL the URL vars are forwarded.
  27. *                                          Fixed bug where if forwardvars weren't specifically set with "module,func" these core vars would not be used at all in the links
  28. *                                          Added support for use on the Startpage, where the vars are taken from the config starttype, startfunc, and startargs vars.
  29. *                                          Fixed the example below.
  30. *
  31. *  Examples:
  32. *    code:
  33. *    <!--[pagerabc posvar="abc" class_num="dl" class_numon="header" separator=" &nbsp;-&nbsp; " names="A,B;C,D;E,F;G,H;I,J;K,L;M,N,O;P,Q,R;S,T;U,V,W,X,Y,Z"]-->
  34. *
  35. *    result
  36. * <span class="pager">
  37. * <a class="header" href="index.php?module=Example&amp;abc=A,B">&nbspA,B
  38. * </a> &nbsp;-&nbsp; <a class="dl" href="index.php?module=Example&amp;abc=C,D">&nbspC,D
  39. * </a> &nbsp;-&nbsp; <a class="dl" href="index.php?module=Example&amp;abc=E,F">&nbspE,F
  40. * </a> &nbsp;-&nbsp; <a class="dl" href="index.php?module=Example&amp;abc=G,H">&nbspG,H
  41. * </a> &nbsp;-&nbsp; <a class="dl" href="index.php?module=Example&amp;abc=I,J">&nbspI,J
  42. * </a> &nbsp;-&nbsp; <a class="dl" href="index.php?module=Example&amp;abc=K,L">&nbspK,L
  43. * </a> &nbsp;-&nbsp; <a class="dl" href="index.php?module=Example&amp;abc=M,N,O">&nbspM,N,O
  44. * </a> &nbsp;-&nbsp; <a class="dl" href="index.php?module=Example&amp;abc=P,Q,R">&nbspP,Q,R
  45. * </a> &nbsp;-&nbsp; <a class="dl" href="index.php?module=Example&amp;abc=S,T">&nbspS,T
  46. * </a> &nbsp;-&nbsp; <a class="dl" href="index.php?module=Example&amp;abc=U,V,W,X,Y,Z">&nbspU,V,W,X,Y,Z
  47. * </a></span>
  48. *
  49. *
  50. * Parameters
  51. *     @param    string     $posvar           - name of the variable that contains the position data, eg "letter"
  52. *     @param    cvs        $forwardvars      - comma- semicolon- or space-delimited list of POST and GET variables to forward in the pager links. If unset, all vars are forwarded.
  53. *     @param    cvs        $additionalvars   - comma- semicolon- or space-delimited list of additional variable and value pairs to forward in the links. eg "foo=2,bar=4"
  54. *     @param    string     $class_num        - class for the pager links (<a> tags)
  55. *     @param    string     $class_numon      - class for the active page
  56. *     @param    string     $separator        - string to put between the letters, eg "|" makes | A | B | C | D |
  57. *     @param    string     $printempty       - print empty sel ('-')
  58. *     @param    string     $lang             - language
  59. *     @param    array      $names            - values to select from (array or csv)
  60. *     @param    string     $skin             - use predefined values (hu - hungarian ABC)
  61. */
  62. function smarty_function_pagerabc($params&$smarty)
  63. {
  64.     foreach($params as $tmp=>$value)    {
  65.         $tmp strtolower($tmp);
  66.         $$tmp $value;
  67.     }
  68.  
  69.     if (!isset($separator)) {
  70.         $separator ' | ';
  71.     }
  72.  
  73.     if (!isset($skin)) {
  74.         $skin '';
  75.     }
  76.  
  77.     if (empty($posvar))    {
  78.         $smarty->trigger_error('pagerabc: attribute posvar required');
  79.         return false;
  80.     }
  81.  
  82.     // set a default class
  83.     if (!isset($class_numon)) {
  84.         $class_numon 'pn-pagerselected';
  85.     }
  86.  
  87.     $out '<span class="pager">'."\n";
  88.  
  89.     if (!empty($names))    {
  90.         if (!is_array($names))    {
  91.             $names explode(';'$names);
  92.         }
  93.         if (!empty($values))    {
  94.             if (!is_array($values))    {
  95.                 $values explode(';'$values);
  96.             }
  97.         else    {
  98.             $values $names;
  99.         }
  100.     else    {
  101.         // predefined abc
  102.         if (strtolower($skin== 'hu'// Hungarian
  103.             $names  $values array('A','Á','B','C','D','E','É','F','G','H','I','Í','J','K','L','M','N','O','Ó','Ö','O','P','Q','R','S','T','U','Ú','Ü','U','V','W','X','Y','Z');
  104.           //$names  = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U'    ,'V','W','X','Y','Z');
  105.           //$values = array('A,Á','B','C','D','E,É','F','G','H','I,Í','J','K','L','M','N','O,Ó,Ö,O','P','Q','R','S','T','U,Ú,Ü,U','V','W','X','Y','Z');
  106.         else    {
  107.             $names  $values array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  108.         }
  109.     }
  110.  
  111.     // create an empty result set
  112.     $vars array();
  113.     $Request array_merge($_POST$_GET);
  114.  
  115.     $modname pnModGetName();
  116.     $name FormUtil::getPassedValue('name');
  117.     $module FormUtil::getPassedValue('module');
  118.     $type FormUtil::getPassedValue('type''user');
  119.     $func FormUtil::getPassedValue('func''main');
  120.  
  121.     // If startmodule, check startargs for posvar
  122.     if (empty($module&& empty($name)) {
  123.         $funcargs explode(','pnConfigGetVar('startargs'));
  124.         $arguments array();
  125.         foreach ($funcargs as $funcarg{
  126.             if (!empty($funcarg)) {
  127.                 $argument=explode('='$funcarg);
  128.                 if ($argument[0]==$posvar)
  129.                     $Request[$posvar$argument[1];
  130.             }
  131.         }
  132.     }
  133.  
  134.     // If $forwardvars set, add only listed vars to query string, else add all POST and GET vars
  135.     if (isset($forwardvars)) {
  136.         if (!is_array($forwardvars))    {
  137.             $forwardvars preg_split('/[,;\s]/'$forwardvars-1PREG_SPLIT_NO_EMPTY);
  138.         }
  139.         foreach ((array)$forwardvars as $key => $var)    {
  140.             if (!empty($varAND (!empty($Request[$var]))) {
  141.                 $vars[$var$Request[$var];
  142.                 //    if ($key !== 0) {
  143.                 //            $url .= '&';
  144.                 //    }
  145.                 // $url .= $val.'='.$Request[$val];
  146.             }
  147.         }
  148.     else {
  149.         $vars $Request;
  150.     }
  151.  
  152.     if (isset($additionalvars)) {
  153.         if (!is_array($additionalvars))    {
  154.             $additionalvars preg_split('/[,;\s]/'$additionalvars-1PREG_SPLIT_NO_EMPTY);
  155.         }
  156.         foreach ((array)$additionalvars as $var)    {
  157.             $additionalvar preg_split('/=/'$var);
  158.             if (!empty($var&& !empty($additionalvar[1])) {
  159.                 $vars[$additionalvar[0]] $additionalvar[1];
  160.                 //    $url .= '&'.$additionalvar[0].'='.$additionalvar[1];
  161.             }
  162.         }
  163.     }
  164.  
  165.     unset($vars['module']);
  166.     unset($vars['func']);
  167.     unset($vars['type']);
  168.     unset($vars[$posvar]);
  169.  
  170.     // Get module information
  171.     $modinfo pnModGetInfo(pnModGetIDFromName($modname));
  172.     // If link to API module, not an Admin mod, and ShortURLs set, use ModURL API instead
  173.     $modurl (($modinfo['type'== || $modinfo['type'== 3&& ($type == 'user'&& !pnConfigGetVar('ShortURLs'));
  174.     if (!$modurl// Non-API URLs
  175.         // Don't show default type and func for shorter URL
  176.         $query 'module='.$modname.($func!='main' '&func='.$func '').($type!='user' '&type='.$type '');
  177.         foreach($vars as $key=>$value)    {
  178.             if (is_array($value))    {
  179.                 foreach($value as $var{
  180.                     $query .= '&'.$key.'[]='.urlencode($var);
  181.                 }
  182.             elseif (!empty($value)) {
  183.                 $query .= '&'.$key.'='.urlencode($value);
  184.             }
  185.         }
  186.         $url $_SERVER['PHP_SELF'].'?'.$query;
  187.         // $link = '&';
  188.     }
  189.  
  190.     $tmp '';
  191.     if (isset($printempty&& $printempty == true)    {
  192.         if (!empty($class_num))    {
  193.             $tmp ' class="'.$class_num.'"';
  194.         }
  195.         $vars[$posvar'';
  196.         $urltemp ($modurl pnModURL($modname$type$func$vars$url.'&'.$posvar.'=');
  197.         $out .= '<a'.$tmp.' href="'.$urltemp.'">&nbsp;-'."\n</a>".$separator;
  198.     }
  199.  
  200.  
  201.     $tmp '';
  202.     foreach($names as $i => $name{
  203.         if (!empty($class_numon))    {
  204.             if (isset($Request[$posvar]&& $Request[$posvar== $values[$i])  {
  205.                 $tmp ' class="'.$class_numon.'"';
  206.             elseif (!empty($class_num))    {
  207.                 $tmp ' class="'.$class_num.'"';
  208.             else {
  209.                 $tmp '';
  210.             }
  211.         }
  212.         $vars[$posvar$values[$i];
  213.         $urltemp ($modurl pnModURL($modname$type$func$vars$url.'&'.$posvar.'='.$values[$i]);
  214.         $urltemp DataUtil::formatForDisplay($urltemp);
  215.         if ($i 0)    {
  216.             $out .= $separator;
  217.         }
  218.         $out .= '<a'.$tmp.' href="'.$urltemp.'">'.$name."</a>\n";
  219.     }
  220.     $out .= "</span>\n";
  221.     print $out;
  222. }

Documentation generated on Fri, 18 Jul 2008 21:45:33 +0200 by phpDocumentor 1.4.1