Ticket #527: function.history.php
| File function.history.php, 1.9 kB (added by Lipki, 5 months ago) |
|---|
| Line | |
|---|---|
| 1 | <?php |
| 2 | /** |
| 3 | * @package jelix |
| 4 | * @subpackage jtpl_plugin |
| 5 | * @author Lepeltier kévin |
| 6 | * @copyright 2008 Lepeltier kévin |
| 7 | * @link http://www.jelix.org |
| 8 | * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * Adds the path followed by the user |
| 13 | * |
| 14 | * {history '>>', 'Your path : ', 5} |
| 15 | * |
| 16 | * <ol id="history"> |
| 17 | * <li value="0" class="label">Your path : </li> |
| 18 | * <li value="3" class="first"><a href="./?module=main&action=page&page=home">Home</a> >> </li> |
| 19 | * <li><a href="./?module=main&action=page&page=product">Product</a> >> </li> |
| 20 | * <li><a href="./?module=main&action=page&page=home">Home</a> >> </li> |
| 21 | * <li class="end"><a href="./?module=main&action=page&page=contact">Contact</a></li> |
| 22 | * </ol> |
| 23 | * |
| 24 | * Rendering example : |
| 25 | * |
| 26 | * Your path : Home >> Product >> Home >> Contact |
| 27 | * ¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯¯ |
| 28 | */ |
| 29 | |
| 30 | /** |
| 31 | * image plugin : write the url corresponding to the image |
| 32 | * |
| 33 | * @param jTpl $tpl template engine |
| 34 | * @param string $separator Symbol separating items |
| 35 | * @param array $label the label before placing items |
| 36 | * @param array $nb the number of items displayed by the plugin |
| 37 | */ |
| 38 | function jtpl_function_html_history($tpl, $separator = '', $label = false, $nb=null) { |
| 39 | |
| 40 | echo '<ol class="history">'; |
| 41 | if( $label ) echo '<li value="0" class="label">'.$label.'</li>'; |
| 42 | |
| 43 | $leng = count($_SESSION['HISTORY']); |
| 44 | $nb = ($nb !== null)? count($_SESSION['HISTORY'])-$nb:0; |
| 45 | $nb = ($nb < 0)? 0:$nb; |
| 46 | |
| 47 | for( $i = $nb; $i < $leng; $i++ ) { |
| 48 | $page = $_SESSION['HISTORY'][$i]; |
| 49 | echo '<li value="'.($i+1).'"'.($i==$nb?' class="first"':($i==$leng-1?' class="end"':'')).'>'; |
| 50 | if( $i!=$leng-1 ) echo '<a href="'.jUrl::get($page['action'], $page['params']).'" '.($page['title']!=''?'title="'.$page['title'].'"':'').'>'; |
| 51 | echo $_SESSION['HISTORY'][$i]['label']; |
| 52 | if( $i!=$leng-1 ) echo '</a>'; |
| 53 | echo ($i==$leng-1?'':$separator).'</li>'; |
| 54 | } |
| 55 | |
| 56 | echo '</ol>'; |
| 57 | |
| 58 | } |
| 59 | ?> |
