From 6cd24425231c0ce3c9bb87d385a123f61968f092 Mon Sep 17 00:00:00 2001
From: flow <f.weber@digi-info.de>
Date: Fri, 28 Jan 2011 18:14:16 +0100
Subject: [PATCH] port to drupal 7.

---
 special_menu_items.info    |   10 +--
 special_menu_items.install |   16 +--
 special_menu_items.module  |  232 ++++++++++++++++++++++++--------------------
 3 files changed, 132 insertions(+), 126 deletions(-)
 mode change 100644 => 100755 special_menu_items.info
 mode change 100644 => 100755 special_menu_items.module

diff --git special_menu_items.info special_menu_items.info
old mode 100644
new mode 100755
index 19e7177..0c85e07
--- special_menu_items.info
+++ special_menu_items.info
@@ -1,13 +1,7 @@
 ; $Id: special_menu_items.info,v 1.4 2009/11/16 16:58:01 servit Exp $
 name = Special menu items
 description = "Allow users to add placeholder and/or separator menu items."
-core = 6.x
+core = 7.x
 dependencies[] = menu
 
-
-; Information added by drupal.org packaging script on 2009-06-01
-version = "6.x-1.3"
-core = "6.x"
-project = "special_menu_items"
-datestamp = "1243846910"
-
+configure = admin/config/system/special_menu_items
\ No newline at end of file
diff --git special_menu_items.install special_menu_items.install
index 5b47990..61e4ccd 100644
--- special_menu_items.install
+++ special_menu_items.install
@@ -1,18 +1,12 @@
 <?php
-//$Id:
-/**
- * @file area_banner.install
- * Contains uninstall for functions used by special_menu_items
- */
-
+// $Id$
 
 /**
  * Implementation of hook_uninstall().
  */
 function special_menu_items_uninstall() {
-  variable_del('oldtheme_menu_item_link'); 
-  variable_del('special_menu_items_nolink_tag'); 
-  variable_del('special_menu_items_seperator_tag'); 
-  variable_del('special_menu_items_seperator_value'); 
-  
+  variable_del('special_menu_items_nolink_tag');
+  variable_del('special_menu_items_seperator_tag');
+  variable_del('special_menu_items_seperator_value');
+  variable_del('special_menu_items_menu_item_link');
 }
\ No newline at end of file
diff --git special_menu_items.module special_menu_items.module
old mode 100644
new mode 100755
index 53dc2a2..f24e666
--- special_menu_items.module
+++ special_menu_items.module
@@ -1,5 +1,5 @@
 <?php 
-//$Id: special_menu_items.module,v 1.6 2010/02/21 12:30:33 servit Exp $
+// $Id$
 
 /**
  * @file
@@ -17,24 +17,19 @@
 *Implementation of hook_menu()
 */
 function special_menu_items_menu() {
-  
-  //Add nolink and separator as a dummy pages.
-  $noLink    = 'nolink';
-  $separator = 'separator';
-  
-  $items[$noLink] = array(
-  'page callback' => 'special_menu_items_dummy',
-  'access callback'=>TRUE, 
-  'type' => MENU_CALLBACK,
+  $items['nolink'] = array(
+    'page callback' => 'special_menu_items_dummy',
+    'access callback' => TRUE, 
+    'type' => MENU_CALLBACK,
   );
   
-  $items[$separator] = array(
-  'page callback' => 'special_menu_items_dummy',
-  'access callback'=>TRUE,
-  'type' => MENU_CALLBACK,
+  $items['separator'] = array(
+    'page callback' => 'special_menu_items_dummy',
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
   );
   
-  $items['admin/settings/special_menu_items'] = array(
+  $items['admin/config/system/special_menu_items'] = array(
     'title' => 'Special Menu Items',
     'description' => 'Configure Special Menu Items.',
     'page callback' => 'drupal_get_form',
@@ -50,13 +45,42 @@ function special_menu_items_menu() {
 /**
  * Page callback
 */
-function special_menu_items_dummy()
-{
-  $output = 'This is a dummy page used for placeholder and separator menu items.
-  You should not be able to see this page';
-  return t($output);
+function special_menu_items_dummy() {
+  return t('This is a dummy page used for placeholder and separator menu items. You should not be able to see this page');
 }
 
+function special_menu_items_menu_link(array $variables) {
+  $element = $variables['element'];
+  $sub_menu = '';
+
+  // Add a class to the list item
+  if (in_array($element['#href'], array('nolink', 'separator'))) {
+    $element['#attributes']['class'][] = $element['#href'];
+    
+    if ($element['#below']) {
+      $sub_menu = drupal_render($element['#below']);
+    }
+    
+    switch ($element['#href']) {
+      case 'nolink':
+        $tag = variable_get('special_menu_items_nolink_tag', '<span>');
+        $title = strip_tags(l($element['#title'], $element['#href'], $element['#localized_options']));
+        $output = special_menu_items_render_menu_item($tag, $title);
+        break;
+        
+      case 'separator':
+        $output = variable_get('special_menu_items_separator_value', '<hr>');
+        break;
+    }
+    
+    return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
+  }
+  
+  // Call the original themeing function.
+  $theme_overwrite = variable_get('special_menu_items_menu_item_link', NULL);
+  return call_user_func($theme_overwrite, $variables);
+} 
+
 /**
  * Override of theme_menu_item()
  * This function will add a class to separator and nolink <li> tags for easier styling
@@ -64,151 +88,141 @@ function special_menu_items_dummy()
  *
  * @ingroup themeable
  */
+/*
 function special_menu_itemsoverwrite_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
   $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
   if (!empty($extra_class)) {
-    $class .= ' '. $extra_class;
+    $class .= ' ' . $extra_class;
   }
   if ($in_active_trail) {
     $class .= ' active-trail';
   }
   
-  if(strpos($link,'class="nolink"')!==false) {
-    $class.=' nolink-li';
+  if (strpos($link, 'class="nolink"') !== FALSE) {
+    $class .= ' nolink-li';
   }
-if(strpos($link,'class="separator"')!==false) {
-    $class.=' separator-li';
+  if (strpos($link, 'class="separator"') !== FALSE) {
+    $class .=' separator-li';
   }
-  return '<li class="'. $class .'">'. $link . $menu ."</li>\n";
+  return '<li class="' . $class . '">' . $link . $menu . "</li>\n";
 }
+*/
 
 /**
  * Override of theme_menu_item_link()
  * This function will render link if it is "nolink" or "separator". Otherwise it will call originally 
  * overwriten menu_item_link function. 
  */
+/*
 function special_menu_itemsoverwrite_menu_item_link($link) {   
-  $theme_overwrite=variable_get('oldtheme_menu_item_link',null);
+  $theme_overwrite = variable_get('oldtheme_menu_item_link', NULL);
   
   if (empty($link['localized_options'])) {
     $link['localized_options'] = array();
   }
   
-  if(strpos($link['href'], 'nolink') === 0) {
+  if (strpos($link['href'], 'nolink') === 0) {
     // Allow if the menu link is nolink:
     $link['localized_options']['html'] = TRUE;
     
     //Retrieve tag for nolink menu item
-    $tag=variable_get('special_menu_items_nolink_tag','<span>');
+    $tag = variable_get('special_menu_items_nolink_tag', '<span>');
     
     //Set class for nolink
-    $css='nolink';
+    $css = 'nolink';
  
     //Return HTML span instead of a link
-    return render_menu_item($tag,$link['title'],$css);
+    return render_menu_item($tag, $link['title'], $css);
   }
-  else if(strpos($link['href'], 'separator') === 0) {
+  elseif (strpos($link['href'], 'separator') === 0) {
     // Allow if the menu link is separator
     $link['localized_options']['html'] = TRUE;
     
     //Retrieve tags and value for separator menu item
-    $tag=variable_get('special_menu_items_separator_tag','<span>');
-    $value=variable_get('special_menu_items_separator_value','<hr>');
+    $tag=variable_get('special_menu_items_separator_tag', '<span>');
+    $value=variable_get('special_menu_items_separator_value', '<hr>');
     
     //Set class for separator
-    $css='separator';
+    $css = 'separator';
 
     //Return separator menu item
-    return render_menu_item($tag,$value,$css);
+    return render_menu_item($tag, $value, $css);
   }
   else
-     return call_user_func($theme_overwrite, $link);
+    return call_user_func($theme_overwrite, $link);
 }
+*/
 
 /**
  * Returns menu item rendered.
  */
-function render_menu_item($tag,$value,$css=null){
-$length=strlen($tag);
+function special_menu_items_render_menu_item($tag, $value, $css = NULL) {
+  $length = strlen($tag);
    
-    //Validate the tags
-      if($tag[0]=='<' && $tag[$length-1]=='>'){
-        $closingtag=str_replace('<','</',$tag);
-        if($css)
-            $tag=str_replace('>',' class="'.$css.'">',$tag);        
-      }
-      else{
-        if($css){       
-        $classtag='<'.$tag.' class="'.$css.'">';
-        $tag='<'.$tag.'>';
-        $closingtag=str_replace('<','</',$tag);
-        $tag=$classtag;
-        }
-        else{
-        $tag='<'.$tag.'>';
-        $closingtag=str_replace('<','</',$tag);
-        }
-      }  
-  return $tag.$value.$closingtag;
+  //Validate the tags
+  if ($tag[0] == '<' && $tag[$length - 1] == '>') {
+    $closingtag = str_replace('<', '</', $tag);
+    if ($css) {
+      $tag = str_replace('>', ' class="' . $css . '">', $tag);        
+    } 
+  } else {
+    if ($css) {       
+      $classtag = '<' . $tag . ' class="' . $css . '">';
+      $tag = '<' . $tag . '>';
+      $closingtag = str_replace('<', '</', $tag);
+      $tag = $classtag;
+    } else {
+      $tag = '<' . $tag . '>';
+      $closingtag = str_replace('<', '</', $tag);
+    }
+  }  
+
+  return $tag . $value . $closingtag;
 }
 
+
 /**
  * Implementation of hook_theme_registry_alter()
  * We replace theme_menu_item_link with our own function.
  */
-function special_menu_items_theme_registry_alter(&$theme_registry) {
-  
+function special_menu_items_theme_registry_alter(&$registry) {
   // Save previous value from registry in case another theme overwrites menu_item_link
-  $theme_overwrite = $theme_registry['menu_item_link']['function']; 
-  
-  //Store the value
-  variable_set('oldtheme_menu_item_link', $theme_overwrite);
-  
-  // Replace theme_menu_item_link with our special_menu_itemsoverwrite_menu_item_link. 
-   $theme_registry['menu_item_link']['function'] = 'special_menu_itemsoverwrite_menu_item_link';
-   $theme_registry['menu_item_link']['theme paths'] = drupal_get_path('module','special_menu_items');;
-   $theme_registry['menu_item']['function'] = 'special_menu_itemsoverwrite_menu_item';
+  variable_set('special_menu_items_menu_item_link', $registry['menu_link']['function']);
+  $registry['menu_link']['function'] = 'special_menu_items_menu_link';
 }
 
 /**
- * Implementation of hook_form_alter()
+ * Implementation of hook_form_FROM_ID_alter()
  * Description changed, added nolink and separator as path types.
  */
-function special_menu_items_form_alter(&$form, $form_state, $form_id) {
- 
-  if ($form_id=='menu_edit_item') {
-    $default_value=$form['menu']['link_path']['#default_value'];
-    
-      if(preg_match('/^nolink\/[0-9]+$/',$default_value))
-      {
-        $default_value='nolink';
-      }
-      else if(preg_match("/^separator\/[0-9]+$/",$default_value))
-      {
-        $default_value='separator';
-      }
-  
-    $form['menu']['link_path']['#default_value'] = $default_value;
-    $form['menu']['link_path']['#description']=  t('The path this menu item links to. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page, enter "nolink" to generate non-linkable item, enter "separator" to generate separator item.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')); 
-  } 
+function special_menu_items_form_menu_edit_item_alter(&$form, &$form_state) {
+  $default_value = $form['link_path']['#default_value'];
+
+  if (preg_match('/^nolink\/[0-9]+$/', $default_value)) {
+    $default_value = 'nolink';
+  } elseif (preg_match('/^separator\/[0-9]+$/', $default_value)) {
+    $default_value = 'separator';
+  }
+
+  $form['link_path']['#default_value'] = $default_value;
+  $form['link_path']['#description']=  t('The path this menu item links to. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page, enter "nolink" to generate non-linkable item, enter "separator" to generate separator item.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')); 
 }
 
 /**
  * Implementation of hook_init().
  */
 function special_menu_items_init() {
-
-  //Make breadcrumb of nolink menu item nonlinkable.
+  // Make breadcrumb of nolink menu item nonlinkable.
   $breadcrumb = drupal_get_breadcrumb();
 
-  foreach($breadcrumb as $key=>$crumb){
-    
-    if(strlen(strstr($crumb,'nolink'))>0) {
-      $crumb=strip_tags($crumb);
-      $tag=variable_get('special_menu_items_nolink_tag','<span>');
-      $breadcrumb[$key]=render_menu_item($tag,$crumb);      
+  foreach($breadcrumb as $key => $crumb){
+    if (strlen(strstr($crumb,'nolink')) > 0) {
+      $crumb = strip_tags($crumb);
+      $tag = variable_get('special_menu_items_nolink_tag', '<span>');
+      $breadcrumb[$key] = special_menu_items_render_menu_item($tag, $crumb);      
     }
   }
+  
   drupal_set_breadcrumb($breadcrumb);
 }
 
@@ -224,7 +238,6 @@ function special_menu_items_admin_settings_form() {
     '#title' => t('HTML tag for "nolink"'),
     '#description' => t('By default, Special Menu Items will use a span tag for the nolink menu item. Here you can specify your own tag.'),
     '#default_value' => variable_get('special_menu_items_nolink_tag', '<span>'),
-  
   );
   
   $form['special_menu_items_separator_tag'] = array(
@@ -232,32 +245,37 @@ function special_menu_items_admin_settings_form() {
     '#title' => t('HTML tag for "separator"'),
     '#description' => t('By default, Special Menu Items will use a span tag for the separator menu item. Here you can specify your own tag.'),
     '#default_value' => variable_get('special_menu_items_separator_tag', '<span>'),
-  
   );
-  
-    $form['special_menu_items_separator_value'] = array(
+
+  $form['special_menu_items_separator_value'] = array(
     '#type' => 'textfield',
     '#title' => t('Value to be displayed for the "separator"'),
     '#description' => t('By default, Special Menu Items will use a "&lt;hr&gt;" value for the separator. You can specify your own value for the separator.'),
     '#default_value' => variable_get('special_menu_items_separator_value', '<hr>'),
-  
   );
 
   return system_settings_form($form);
 }
 
-function special_menu_items_footer() {
-  if(strpos($_GET['q'],'admin/build/menu-customize')!== false)
-  {
+/**
+ * Implements hook_page_alter()
+ *
+ * @param $page
+ *   Nested array of renderable elements that make up the page.
+ *
+ * @see hook_page_build()
+ * @see drupal_render_page()
+ */
+function special_menu_items_page_alter(&$page) {
+  if (strpos($_GET['q'], 'admin/build/menu-customize') !== FALSE) {
     //do all links in db
     global $db_type;  
     if ($db_type == 'pgsql') {
-        db_query("UPDATE {menu_links} SET link_path=link_path||'/'||mlid WHERE (link_path='nolink' OR link_path='separator') AND hidden != -1");
+      db_query("UPDATE {menu_links} SET link_path=link_path||'/'||mlid WHERE (link_path='nolink' OR link_path='separator') AND hidden != -1");
     }
     else {
-        db_query("UPDATE {menu_links} SET link_path=CONCAT(CONCAT(link_path,'/'),mlid) WHERE (link_path='nolink' OR link_path='separator') AND hidden!=-1");
+      db_query("UPDATE {menu_links} SET link_path=CONCAT(CONCAT(link_path,'/'),mlid) WHERE (link_path='nolink' OR link_path='separator') AND hidden!=-1");
     }
-	
-	cache_clear_all();
+    cache_clear_all();
   }
 }
\ No newline at end of file
-- 
1.7.3.4

