Development

Changeset 7550

You must first sign up to be able to contribute.

Changeset 7550

Show
Ignore:
Timestamp:
02/20/08 07:23:01 (5 months ago)
Author:
xavier
Message:

sfPropelActAsTaggableBehaviorPlugin: tag_cloud helper with custom links function - refs #2923 (thanks, Will !)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelActAsTaggableBehaviorPlugin/trunk/lib/helper/TagsHelper.php

    r4111 r7550  
    22/* 
    33 * This file is part of the sfPropelActAsTaggableBehavior package. 
    4  *  
     4 * 
    55 * (c) 2007 Xavier Lacot <xavier@lacot.org> 
    6  *  
     6 * 
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
    99 */ 
    1010 
     11/** 
     12 * Generates a tag cloud from a tags array. 
     13 * 
     14 * @param   array   $tags     The tags array. This array must associate the tags 
     15 * to their weight. The metgod sfPropelActAsTaggableToolkit::normalize() is here 
     16 * to help generate such an array 
     17 * 
     18 * @param   mixed   $route    The route name to be used in the tag. If using the& 
     19 * link_to_remote function, this parameter acts as the remote options array 
     20 * 
     21 * @param   array   $options  Optionnal options array for formating the link. 
     22 * Supported keys are: 
     23 *  * class:  html class to be applied to the tags list 
     24 *  * link_funktion: custom function to be used for generating each tag link 
     25 *  * link_options: html options to be applied to the generated link 
     26 */ 
    1127function tag_cloud($tags, $route, $options = array()) 
    1228{ 
     
    1531  if(count($tags) > 0) 
    1632  { 
    17     $emphasizers_begin = array(-2 => '<small><small>',  
    18                                -1 => '<small>',  
    19                                 0 => '',  
    20                                 1 => '<big>',  
     33    $emphasizers_begin = array(-2 => '<small><small>', 
     34                               -1 => '<small>', 
     35                                0 => '', 
     36                                1 => '<big>', 
    2137                                2 => '<big><big>'); 
    22     $emphasizers_end = array(-2 => '</small></small>',  
    23                              -1 => '</small>',  
    24                               0 => '',  
    25                               1 => '</big>',  
     38    $emphasizers_end = array(-2 => '</small></small>', 
     39                             -1 => '</small>', 
     40                              0 => '', 
     41                              1 => '</big>', 
    2642                              2 => '</big></big>'); 
    2743 
     44    $custom_route = is_string($route) && false !== strpos($route, '%s'); 
     45 
     46    if (!$custom_route) 
     47    { 
     48      $route_link = $route; 
     49    } 
     50 
    2851    $class = isset($options['class']) ? $options['class'] : 'tag-cloud'; 
     52    $link_function = isset($options['link_function']) ? $options['link_function'] : 'link_to'; 
     53    $link_options = isset($options['link_options']) ? $options['link_options'] : array(); 
     54    $link_options['rel'] = 'tag'; 
    2955    $result = '<ul class="'.$class.'">'; 
    3056 
    3157    foreach ($tags as $name => $count) 
    3258    { 
    33       $link = link_to($name, 
    34                       $route.$name,  
    35                       array('rel' => 'tag')); 
     59      if ($custom_route) 
     60      { 
     61        $route_link = sprintf($route, $name); 
     62      } 
    3663 
     64      $link = $link_function($name, $route_link, $link_options); 
    3765      $result .= ' 
    3866                  <li>'.$emphasizers_begin[$count].$link.$emphasizers_end[$count].'</li>'; 
     
    5785    { 
    5886      $link = link_to($tag, 
    59                       $route.$tag,  
     87                      $route.$tag, 
    6088                      array('rel' => 'tag')); 
    6189 
     
    81109    } 
    82110 
    83     $emphasizers_begin = array(-2 => '<small><small>',  
    84                                -1 => '<small>',  
    85                                 0 => '',  
    86                                 1 => '<big>',  
     111    $emphasizers_begin = array(-2 => '<small><small>', 
     112                               -1 => '<small>', 
     113                                0 => '', 
     114                                1 => '<big>', 
    87115                                2 => '<big><big>'); 
    88     $emphasizers_end = array(-2 => '</small></small>',  
    89                              -1 => '</small>',  
    90                               0 => '',  
    91                               1 => '</big>',  
     116    $emphasizers_end = array(-2 => '</small></small>', 
     117                             -1 => '</small>', 
     118                              0 => '', 
     119                              1 => '</big>', 
    92120                              2 => '</big></big>'); 
    93121 
     
    99127    { 
    100128      $link = link_to($name, 
    101                       $route.$name,  
     129                      $route.$name, 
    102130                      array('rel' => 'tag')); 
    103131      $related_link = link_to($add,