Running Drupal 5.1 on Windows 2003 and IIS:

Everything is working fine except when a non-existent node number is put into the querystring, a php error is returned to to log:

Example:

http://www.example.com/index.php?q=node/410

Will return

Invalid argument supplied for foreach() in C:\Inetpub\Dept Web Site\includes\common.inc(1342) : eval()'d code on line 12.

if

node/410 is not a valid node id

This is more of an annoyance than anything else but it seems that some webbots go looking for non-existent nodes and "load up" my error log...

Thanks

Wade

Comments

john morahan’s picture

Do you have any custom PHP code in your blocks? If so, please post it.

hedroom’s picture

All of my blocks are created by the views module, with the exception of 3 others (Navigation, Login & Who's Online). I did load the DHTML Menus module and I'm using the DHTML-Navigation block as is.

This is the "Page specific visibility settings" code for the blocks created by the Views Module (added after the block is created)

  // This snippet returns TRUE if the node we are
  // currently viewing is tagged with a term which belongs
  // to the 'desired_vocab' and we are not in edit mode (arg(2)).

  $desired_vocab = 59; // put here the vocabulary ID you're interested in

  if ( arg(0) == 'node' and is_numeric(arg(1)) and arg(2) == FALSE ) {
    // Yes, we're viewing a node in view mode.

   $node = node_load(arg(1)); // cached
    foreach ($node->taxonomy as $term) {
      if ($term->tid == $desired_vocab) {
        return TRUE;
      }
    }   
  }
  return FALSE;

Thanks,

Wade

john morahan’s picture

If you're on a node/### page for a node that doesn't exist, the node_load() will fail and $node->taxonomy won't be there. Try this:

  // This snippet returns TRUE if the node we are
  // currently viewing is tagged with a term which belongs
  // to the 'desired_vocab' and we are not in edit mode (arg(2)).

  $desired_vocab = 59; // put here the vocabulary ID you're interested in

  if ( arg(0) == 'node' and is_numeric(arg(1)) and arg(2) == FALSE ) {
    // Yes, we're viewing a node in view mode.

    $node = node_load(arg(1)); // cached
    if (is_array($node->taxonomy)) {
      foreach ($node->taxonomy as $term) {
        if ($term->tid == $desired_vocab) {
          return TRUE;
        }
      }
    }
  }
  return FALSE;
hedroom’s picture

Thanks John!

That was the problem... Your revised code did the trick.

The original code was taken form the "PHP snippets" section of the Customization handbook (http://drupal.org/node/69076).

I'll post your code there.

Also, even though no errors are thrown now, the system just returns the taxonomy list (?q=taxonomy/term/11) of the front page term instead of "page not found" [when a non-existent node is requested].

I had 39 blocks with the "defective" code. Here is the sql statement I used to fix it:

UPDATE `blocks` 
SET `pages` = REPLACE(`pages`,'    foreach ($node->taxonomy as $term) {
      if ($term->tid == $desired_vocab) {
        return TRUE;
      }
    }', '    if (is_array($node->taxonomy)) {
      foreach ($node->taxonomy as $term) {
        if ($term->tid == $desired_vocab) {
          return TRUE;
        }
      }
    }')

Thanks again,

Wade