summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/menu.inc188
-rw-r--r--includes/theme.inc42
2 files changed, 191 insertions, 39 deletions
diff --git a/includes/menu.inc b/includes/menu.inc
index 30cc56cd6..8acbb28fe 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -493,6 +493,25 @@ function menu_in_active_trail($mid) {
}
/**
+ * Returns true when the menu item is in the active trail within a
+ * specific subsection of the menu tree.
+ *
+ * @param $mid
+ * The menu item being considered.
+ * @param $pid
+ * The root of the subsection of the menu tree in which to look.
+ */
+function menu_in_active_trail_in_submenu($mid, $pid) {
+ $trail = _menu_get_active_trail_in_submenu($pid);
+
+ if (!$trail) {
+ return FALSE;
+ }
+
+ return in_array($mid, $trail);
+}
+
+/**
* Populate the database representation of the menu.
*
* This need only be called at the start of pages that modify the menu.
@@ -708,6 +727,125 @@ function theme_menu_local_task($mid, $active, $primary) {
}
/**
+ * Returns an array containing the primary links.
+ * Can optionally descend from the root of the Primary links menu towards the
+ * current node for a specified number of levels and return that submenu.
+ * Used to generate a primary/secondary menu from different levels of one menu.
+ *
+ * @param $start_level
+ * This optional parameter can be used to retrieve a context-sensitive array
+ * of links at $start_level levels deep into the Primary links menu.
+ * The default is to return the top-level links.
+ * @param $pid
+ * The parent menu ID from which to search for children. Defaults to the
+ * menu_primary_menu setting.
+ * @return An array containing the themed links as the values. The keys of
+ * the array contain some extra encoded information about the results.
+ * The format of the key is {level}-{num}{-active}.
+ * level is the depth within the menu tree of this list.
+ * num is the number within this array, used only to make the key unique.
+ * -active is appended if this element is in the active trail.
+ */
+function menu_primary_links($start_level = 1, $pid = 0) {
+ if (!module_exist('menu')) {
+ return NULL;
+ }
+ if (!$pid) {
+ $pid = variable_get('menu_primary_menu', 0);
+ }
+ if (!$pid) {
+ return NULL;
+ }
+
+ if ($start_level < 1) {
+ $start_level = 1;
+ }
+
+ if ($start_level > 1) {
+ $trail = _menu_get_active_trail_in_submenu($pid);
+ if (!$trail) {
+ return NULL;
+ }
+ else {
+ $pid = $trail[$start_level - 1];
+ }
+ }
+
+ $menu = menu_get_menu();
+ if ($pid && is_array($menu['visible'][$pid]) && array_key_exists('children', $menu['visible'][$pid])) {
+ $count = 1;
+ foreach ($menu['visible'][$pid]['children'] as $cid) {
+ $index = "$start_level-$count";
+ if (menu_in_active_trail_in_submenu($cid, $pid)) {
+ $index .= "-active";
+ }
+ $links[$index] = menu_item_link($cid);
+ $count++;
+ }
+ }
+
+ // special case - provide link to admin/menu if primary links is empty.
+ if (is_null($links) && $start_level == 1 && $pid == variable_get('menu_primary_menu', 0)) {
+ $links['1-1'] = l(t('edit primary links'),'admin/menu');
+ }
+
+ return $links;
+}
+
+/**
+ * Returns an array containing the secondary links.
+ * Secondary links can be either a second level of the Primary links
+ * menu or generated from their own menu.
+ */
+function menu_secondary_links() {
+ $msm = variable_get('menu_secondary_menu', 0);
+ if ($msm == 0) {
+ return NULL;
+ }
+
+ if ($msm == variable_get('menu_primary_menu', 0)) {
+ return menu_primary_links(2, $msm);
+ }
+
+ return menu_primary_links(1, $msm);
+}
+
+/**
+ * Returns the themed HTML for primary and secondary links.
+ * Note that this function is overridden by most core themes because
+ * those themes display links in "link | link" format, not from a list.
+ * Also note that by default links rendered with this function are
+ * displayed with the same CSS as is used for the local tasks.
+ * If a theme wishes to render links from a ul it is expected that
+ * the theme will provide suitable CSS.
+ *
+ * @param $links
+ * An array containing links to render.
+ * @return
+ * A string containing the themed links.
+ *
+ * @ingroup themeable
+ */
+function theme_menu_links($links) {
+ if (!count($links)) {
+ return '';
+ }
+ $level_tmp = split('-', key($links));
+ $level = $level_tmp[0];
+ $output = "<ul class=\"links-$level\">\n";
+ foreach ($links as $index => $link) {
+ $output .= '<li';
+ if (stristr($index, 'active')) {
+ $output .= ' class="active"';
+ }
+ $output .= ">$link</li>\n";
+ }
+ $output .= '</ul>';
+
+ return $output;
+}
+
+/**
* @} End of "defgroup menu".
*/
@@ -734,6 +872,56 @@ function _menu_get_active_trail() {
}
/**
+ * Find the active trail through a specific subsection of the menu tree.
+ *
+ * @param $pid
+ * The root item from which the active trail must descend.
+ */
+function _menu_get_active_trail_in_submenu($pid) {
+ static $trails;
+ static $built;
+
+ if (!$built) {
+ // Find all menu items which point to the current node and for each
+ // follow the parents up the chain to build an active trail.
+ $built = TRUE;
+ $menu = menu_get_menu();
+ $path = $_GET['q'];
+ $count = 0;
+ while ($path && !$count) {
+ foreach ($menu['items'] as $key => $item) {
+ if (array_key_exists('path', $item) && $item['path'] == $path) {
+ $trails[$count] = array();
+ $mid = $key;
+ while ($mid && $menu['items'][$mid]) {
+ array_unshift($trails[$count], $mid);
+ $mid = $menu['items'][$mid]['pid'];
+ }
+ $count ++;
+ }
+ }
+ $path = substr($path, 0, strrpos($path, '/'));
+ }
+ }
+
+ if ($trails) {
+ foreach ($trails as $key => $trail) {
+ for ($i = 0 ; $i < count($trail); $i++) {
+ if ($trail[$i] == $pid) {
+ // create a trail from $pid to the current page inclusive.
+ for ( ; $i < count($trail) ; $i++) {
+ $subtrail[] = $trail[$i];
+ }
+ return $subtrail;
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
+
+/**
* Comparator routine for use in sorting menu items.
*/
function _menu_sort($a, $b) {
diff --git a/includes/theme.inc b/includes/theme.inc
index f345be9dc..c1bc54339 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -212,8 +212,6 @@ function path_to_theme() {
*/
function theme_get_settings($key = NULL) {
$defaults = array(
- 'primary_links' => array(),
- 'secondary_links' => array(),
'mission' => '',
'default_logo' => 1,
'logo_path' => '',
@@ -225,8 +223,6 @@ function theme_get_settings($key = NULL) {
'toggle_search' => 1,
'toggle_slogan' => 0,
'toggle_mission' => 1,
- 'toggle_primary_links' => 1,
- 'toggle_secondary_links' => 1,
'toggle_node_user_picture' => 0,
'toggle_comment_user_picture' => 0,
);
@@ -307,41 +303,6 @@ function theme_get_setting($setting_name, $refresh = FALSE) {
}
}
- foreach (array('primary', 'secondary') as $type) {
- // Get the data to populate the textfields, if the variable is not an array .. try to parse the old-style link format.
- $value = $settings[$type . '_links'];
-
- // Clear out existing (internal) values
- $settings[$type .'_links'] = array();
-
- // Get the amount of links to show, possibly expanding if there are more links defined than the count specifies.
- $count = variable_get($type . '_link_count', 5);
- if (isset($value['link']) && $count > sizeof($value['link'])) {
- $count = sizeof($value['link']);
- }
-
- if ($settings['toggle_' . $type . '_links']) {
- for ($i =0; $i < $count; $i++) {
- unset($attributes);
- if (!empty($value['text'][$i])) {
- if (!empty($value['description'][$i])) {
- $attributes['title'] = $value['description'][$i];
- }
- $text = $value['text'][$i];
- $link = $value['link'][$i];
- if (substr($link, 0, 7) == 'http://') {
- $settings[$type .'_links'][] = '<a href="'. check_url($link) .'"'. drupal_attributes($attributes) .'>'. check_plain($text) .'</a>';
- }
- else {
- $settings[$type .'_links'][] = l($text, $link, $attributes);
- }
- }
- }
- if ($settings[$type .'_links'] == array()) {
- $settings[$type .'_links'] = array(l(t('edit %type links', array('%type' => $type)),'admin/themes/settings'));
- }
- }
- }
}
return isset($settings[$setting_name]) ? $settings[$setting_name] : NULL;
@@ -509,6 +470,9 @@ function theme_status_messages() {
* A string containing the themed links.
*/
function theme_links($links, $delimiter = ' | ') {
+ if (!is_array($links)) {
+ return '';
+ }
return implode($delimiter, $links);
}