/[drupal]/contributions/modules/bandwidth/bandwidth.module
ViewVC logotype

Diff of /contributions/modules/bandwidth/bandwidth.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Thu Oct 30 17:55:27 2008 UTC revision 1.3, Thu Oct 30 19:23:36 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: bandwidth.module,v 1.2 2008/10/30 17:55:27 yrocq Exp $
3    
4  /**  /**
5   * Bandwidth Module   * Bandwidth Module
# Line 10  Line 10 
10  /**  /**
11   * Bandwidth management   * Bandwidth management
12   */   */
   
  /**  
   * Get or set current bandwidth  
   * @param bandwidth to set  
   * @return current bandwidth  
   **/  
   
 function bandwidth_current_bandwidth($bandwidth='')  
 {  
   static $current_bandwidth;  
   
   if(bandwidth_is_valid_bandwidth($bandwidth)) {  
     $current_bandwidth = $bandwidth;  
   }  
   
   return $current_bandwidth;  
 }  
13    
14  /**  /**
15   * Get prefered bandwidth for a user   * Get prefered bandwidth for a user
# Line 105  function bandwidth_is_valid_bandwidth($b Line 88  function bandwidth_is_valid_bandwidth($b
88    return in_array($bandwidth, array_keys(bandwidth_get_bandwidthes()));    return in_array($bandwidth, array_keys(bandwidth_get_bandwidthes()));
89  }  }
90    
91    function bandwidth_path_contains_bandwidth($path)
92    {
93      $path_array = explode('/',$path);
94      return bandwidth_is_valid_bandwidth($path_array[0]);
95    }
96    
97  /**  /**
98   * Pages   * Pages
99   */   */
# Line 148  function bandwidth_block($op = 'list', $ Line 137  function bandwidth_block($op = 'list', $
137            if (user_access('choose bandwidth')) {            if (user_access('choose bandwidth')) {
138              return array(              return array(
139                'subject' => t('Choose bandwidth'),                'subject' => t('Choose bandwidth'),
140                'content' => theme('bandwidth_choice')                'content' => theme('bandwidth_choice', $_GET['q'])
141              );              );
142            }            }
143            break;            break;
# Line 163  function bandwidth_init() Line 152  function bandwidth_init()
152  {  {
153    $path_array = explode('/', $_GET['q']);    $path_array = explode('/', $_GET['q']);
154    
155    if (in_array($path_array[0], array_keys(bandwidth_get_bandwidthes()))) {    if (bandwidth_is_valid_bandwidth($path_array[0])) {
156      bandwidth_current_bandwidth(array_shift($path_array));      bandwidth_set_user_bandwidth(array_shift($path_array));
157      $_GET['q'] = implode('/', $path_array);      $_GET['q'] = implode('/', $path_array);
   
158      // Parse the path again without the leading bandwidth      // Parse the path again without the leading bandwidth
159      drupal_init_language();      drupal_init_language();
160    
# Line 201  function bandwidth_theme() Line 189  function bandwidth_theme()
189  {  {
190      return array(      return array(
191        'bandwidth_choice' => array(        'bandwidth_choice' => array(
192          'arguments' => array(),          'arguments' => array('path' => NULL),
193        ),        ),
194      );      );
195  }  }
# Line 239  function bandwidth_user($op, &$edit, &$a Line 227  function bandwidth_user($op, &$edit, &$a
227    
228  function custom_url_rewrite_outbound(&$path, &$options, $original_path)  function custom_url_rewrite_outbound(&$path, &$options, $original_path)
229  {  {
230    $path_array = explode('/',$path);    // If it is a link to change bandwidth (changeBandwidth argument in the query)
231    // Add bandwidth prefix if not already present    // We alter the link and clear the query
232    if (!bandwidth_is_valid_bandwidth($path_array[0])) {    if (strstr($options['query'], 'changeBandwidth=')) {
233      $options['prefix'] = bandwidth_get_user_bandwidth().'/'.$options['prefix'];      $bandwidth = str_replace('changeBandwidth=', '', $options['query']);
234        unset($options['query']);
235    }    }
236      else
237      {
238        if (!bandwidth_path_contains_bandwidth($path)) {
239          $bandwidth = bandwidth_get_user_bandwidth();
240        }
241      }
242    
243      $options['prefix'] = $bandwidth.'/'.$options['prefix'];
244  }  }
245    
246  /**  /**
247   * Theme functions   * Theme functions
248   */   */
249    
250  function theme_bandwidth_choice() {  function theme_bandwidth_choice($path) {
251      if (bandwidth_path_contains_bandwidth($path)) {
252        $path_array = explode('/', $path);
253        array_shift($path);
254        $path = implode('/', $path_array);
255      }
256    foreach (bandwidth_get_bandwidthes() as $key => $value) {    foreach (bandwidth_get_bandwidthes() as $key => $value) {
257      $bandwidthes[] = l($value,'bandwidth/'.$key, array('query' => drupal_get_destination()));      $bandwidthes[] = l($value,$path,array("query" => array('changeBandwidth' => $key)));
258    }    }
259    return theme_item_list($bandwidthes);    return theme_item_list($bandwidthes);
260  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2