Great and useful module.

However it doesn't seem to work in my primary links. Working fine in the regular blocks though.

Hmmm

Phil

Comments

decafdennis’s picture

Title: Doesn't work in Primary links » Doesn't work in primary links
Status: Active » Needs review

In addition to what is in README.txt, the following code needs to be added to template.php as well:

function mytheme_links($links, $attributes = array('class' => 'links')) {
  foreach ($links as $key => $link) {
    if ($info = db_fetch_object(db_query("SELECT * FROM {nofollow} WHERE type = 'menu' AND id = '%s'", $link['href']))) {
      $follow = nofollow_dofollow_check($info);
      if (!$follow) {
        if (isset($link['attributes'])) {
          $links[$key]['attributes']['rel'] = 'nofollow';
        }
        else {
          $links[$key]['attributes'] = array('rel' => 'nofollow');
        }
      }
    }
  }
  
  return theme_links($links, $attributes);
}

Sorry, I don't have the time to create an actual patch.

shunshifu’s picture

Dennis rocks!

shunshifu’s picture

Strangely it works on some of the links but not others

The primary links on www.belt-buckle-knife.com . Most are set to

Dofoolow on every page except

Some are noffollowed others aren't. Yes I've reset my cache.

A bit perplexing.

Phil

decafdennis’s picture

Status: Needs review » Needs work

Is there a difference between internal links (simple Drupal paths) and external links (external URLs)?

Duplika’s picture

I've tried the above patch and it still doesn't work, neither with internal or external URL's.

decafdennis’s picture

Juanzo, did you change 'mytheme' into whatever the name of your theme is?

clm23’s picture

Hi,
I'm using drupal 5.1 and the garland_dropmenu theme,
and below is the code I placed into garland_dropmenu/template.php

I don't see any nofollow's except cart & checkout (as a result of ubercart).

Has anyone got this module to work ?

THx,
C

<?php
/**
 * Sets the body-tag class attribute.
 *
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
 */


function garland_dropmenu_links($links, $attributes = array('class' => 'links')) {
  foreach ($links as $key => $link) {
    if ($info = db_fetch_object(db_query("SELECT * FROM {nofollow} WHERE type = 'menu' AND id = '%s'", $link['href']))) {
      $follow = nofollow_dofollow_check($info);
      if (!$follow) {
        if (isset($link['attributes'])) {
          $links[$key]['attributes']['rel'] = 'nofollow';
        }
        else {
          $links[$key]['attributes'] = array('rel' => 'nofollow');
        }
      }
    }
  }
 
  return theme_links($links, $attributes);
}


function garland_dropmenu_menu_item_link ($item,$link_item) {
	    $q=db_query("SELECT * FROM {nofollow} WHERE type='menu' AND id='$link_item[path]'");
			$ob=db_fetch_object($q);
			$dofollow=nofollow_dofollow_check($ob);
			$options=!empty($item['description']) ? array('title' => $item['description']) : array();
			if (!$dofollow) $options['rel']="nofollow";
	    return l($item['title']. " $isit", $link_item['path'], $options, isset($item['query']) ? $item['query'] : NULL);
}
	
function garland_dropmenu_block ($block) {
  if (strstr($block->module, 'taxonomy_')) {
     // if this block is a taxonomy block of some sort - whether 
		 // taxonomy_context, taxonomy_menu etc
		 // then filter using patterns from nofollowlist
		 $block->content = preg_replace_callback('!<a.*?href="([^"]+)".*?>!', 'nofollow_link_replace', $block->content);
	}
  $output  = "<div class=\"block block-$block->module\" id=\"block-$block->module-$block->delta\">\n";
  $output .= " <h2 class=\"title\">$block->subject</h2>\n";
  $output .= " <div class=\"content\">$block->content</div>\n";
  $output .= "</div>\n";
  return $output;
}



function phptemplate_body_class($sidebar_left, $sidebar_right) {
  if ($sidebar_left != '' && $sidebar_right != '') {
    $class = 'sidebars';
  }
  else {
    if ($sidebar_left != '') {
      $class = 'sidebar-left';
    }
    if ($sidebar_right != '') {
      $class = 'sidebar-right';
    }
  }

  if (isset($class)) {
    print ' class="'. $class .'"';
  }
}

/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */
function phptemplate_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
  }
}

/**
 * Allow themable wrapping of all comments.
 */
function phptemplate_comment_wrapper($content, $type = null) {
  static $node_type;
  if (isset($type)) $node_type = $type;

  if (!$content || $node_type == 'forum') {
    return '<div id="comments">'. $content . '</div>';
  }
  else {
    return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
  }
}

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function _phptemplate_variables($hook, $vars) {
  if ($hook == 'page') {

    if ($secondary = menu_secondary_local_tasks()) {
      $output = '<span class="clear"></span>';
      $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
      $vars['tabs2'] = $output;
    }

    // Hook into color.module
    if (module_exists('color')) {
      _color_page_alter($vars);
    }
    return $vars;
  }
  return array();
}

/**
 * Returns the rendered local tasks. The default implementation renders
 * them as tabs.
 *
 * @ingroup themeable
 */
function phptemplate_menu_local_tasks() {
  $output = '';

  if ($primary = menu_primary_local_tasks()) {
    $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
  }

  return $output;
}

clm23’s picture

I thought I found bug on the last line (return) that would fix this.
But it still doesn't work.
The next step is to fall back to the basic garland menu and see what happens, but if anyone has got this working we'd really appreciate a pointer.
Thank you,
C

function garland_dropmenu_links($links, $attributes = array('class' => 'links')) {
  foreach ($links as $key => $link) {
    if ($info = db_fetch_object(db_query("SELECT * FROM {nofollow} WHERE type = 'menu' AND id = '%s'", $link['href']))) {
      $follow = nofollow_dofollow_check($info);
      if (!$follow) {
        if (isset($link['attributes'])) {
          $links[$key]['attributes']['rel'] = 'nofollow';
        }
        else {
          $links[$key]['attributes'] = array('rel' => 'nofollow');
        }
      }
    }
  }

  return garland_dropmenu_links($links, $attributes);
}

OliverColeman’s picture

Think I found the bug (the code in #1 is still required, of course): the if ($block->pages) statement and entire corresponding else code block need to be removed from function nofollow_dofollow_check($block) (lines 47 and 64-67) in nofollow.module, ie:

function nofollow_dofollow_check($block) {
      // Match path if necessary
      //if ($block->pages) {
        if ($block->visibility < 2) {
          $path = drupal_get_path_alias($_GET['q']);
          $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/';
          // Compare with the internal and path alias (if any).
          $page_match = preg_match($regexp, $path);
          if ($path != $_GET['q']) {
            $page_match = $page_match || preg_match($regexp, $_GET['q']);
          }
          // When $block->visibility has a value of 0, the block is displayed on
          // all pages except those listed in $block->pages. When set to 1, it
          // is displayed only on those pages listed in $block->pages.
          $page_match = !($block->visibility xor $page_match);
        }
        else {
          $page_match = drupal_eval($block->pages);
        }
      //}
      //else {
      //  $page_match = TRUE;
      //}
   return $page_match;
}