/[drupal]/contributions/modules/i18n/i18nmenu/i18nmenu.module
ViewVC logotype

Diff of /contributions/modules/i18n/i18nmenu/i18nmenu.module

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

revision 1.2.2.16, Tue Nov 3 17:53:24 2009 UTC revision 1.2.2.17, Thu Nov 5 17:33:35 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: i18nmenu.module,v 1.2.2.15 2009/08/29 21:08:24 hass Exp $  // $Id: i18nmenu.module,v 1.2.2.16 2009/11/03 17:53:24 jareyero Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 135  function i18nmenu_localize_tree(&$tree, Line 135  function i18nmenu_localize_tree(&$tree,
135  }  }
136    
137  /**  /**
138     * Return an array of localized links for a navigation menu.
139     */
140    function i18nmenu_menu_navigation_links($menu_name, $level = 0) {
141      // Don't even bother querying the menu table if no menu is specified.
142      if (empty($menu_name)) {
143        return array();
144      }
145    
146      // Get the menu hierarchy for the current page.
147      $tree = menu_tree_page_data($menu_name);
148      i18nmenu_localize_tree($tree);
149    
150      // Go down the active trail until the right level is reached.
151      while ($level-- > 0 && $tree) {
152        // Loop through the current level's items until we find one that is in trail.
153        while ($item = array_shift($tree)) {
154          if ($item['link']['in_active_trail']) {
155            // If the item is in the active trail, we continue in the subtree.
156            $tree = empty($item['below']) ? array() : $item['below'];
157            break;
158          }
159        }
160      }
161    
162      // Create a single level of links.
163      $links = array();
164      foreach ($tree as $item) {
165        if (!$item['link']['hidden']) {
166          $class = '';
167          $l = $item['link']['localized_options'];
168          $l['href'] = $item['link']['href'];
169          $l['title'] = $item['link']['title'];
170          if ($item['link']['in_active_trail']) {
171            $class = ' active-trail';
172          }
173          // Keyed with the unique mlid to generate classes in theme_links().
174          $links['menu-'. $item['link']['mlid'] . $class] = $l;
175        }
176      }
177      return $links;
178    }
179    
180    /**
181     * Replace standard primary and secondary links.
182     */
183    function i18nmenu_preprocess_page(&$vars) {
184      $vars['primary_links'] = i18nmenu_menu_navigation_links(variable_get('menu_primary_links_source', 'primary-links'));
185    
186      // If the secondary menu source is set as the primary menu, we display the
187      // second level of the primary menu.
188      if (variable_get('menu_secondary_links_source', 'secondary-links') == variable_get('menu_primary_links_source', 'primary-links')) {
189        $vars['secondary_links'] = i18nmenu_menu_navigation_links(variable_get('menu_primary_links_source', 'primary-links'), 1);
190      }
191      else {
192        $vars['secondary_links'] = i18nmenu_menu_navigation_links(variable_get('menu_secondary_links_source', 'secondary-links'), 0);
193      }
194    }
195    
196    /**
197   * Optionally insert/update and return a localized menu item title.   * Optionally insert/update and return a localized menu item title.
198   */   */
199  function _i18nmenu_get_item($link, $update = FALSE) {  function _i18nmenu_get_item($link, $update = FALSE) {

Legend:
Removed from v.1.2.2.16  
changed lines
  Added in v.1.2.2.17

  ViewVC Help
Powered by ViewVC 1.1.2