Cannot make it work with webform module

Amir Simantov - March 29, 2009 - 10:56
Project:Global Redirect
Version:6.x-1.2
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi,

I have followed http://drupal.org/node/164526#comment-259353 and it works fine.

I then tried to add another conditional redirect which does not work properly. Following is the code I added. What happens is that I the inner condition always returns true and then goto alway happen - even is the node is owned by the user.

    if (preg_match('/^node\/([0-9]+)\/submissions?/',$request)==1) // Works fine
    {
if($node->uid != $user->uid) // Returns true always
{
drupal_goto('<front>');
}
    }

Here is the code in its context (the function) -

function globalredirect_init() {
global $language;
global $user;
global $node;

  /**
   * We need to do a test to make sure we only clean up URL's for the main request. This stops modules such as
   * the Ad Module which had its own script in its folder doing a bootstrap which invoked hook_init and caused some banners to get "cleaned up"
   * See issues: http://drupal.org/node/205810 and http://drupal.org/node/278615
   */
  if ($_SERVER['SCRIPT_NAME'] != $GLOBALS['base_path'] .'index.php') return FALSE;

  /**
   * If the site is in offline mode there is little point doing any of this as you might end up redirecting to a 503.
   */
  if (variable_get('site_offline', 0) == 1) return FALSE;

  /**
   * Use of menu_get_item should be optional as it appears in some situations it causes WSOD's...
   */
  $menu_check = variable_get('globalredirect_menu_check', GLOBALREDIRECT_FEATURE_DISABLED);

  // Amir added - http://drupal.org/node/164526#comment-259353
  // Get the request string (minus trailing slash e.g. node/123/)
    $request = preg_replace('/\/$/', '', $_REQUEST['q']);

    if (preg_match('/^node\/([0-9]+)$/',$request,$matches)==1 && $query_string == "")
    {
        $node = node_load($matches[1], NULL, TRUE);
      if ($node->type == "webform")
      {
            drupal_goto('<front>');
//            drupal_goto("/","",NULL,404);
      }

    }

// Amir added - In order to redirect from the pattern of /node/5/submissions  AND /node/5/submission/43 (this is why the question mark in the end)
    if (preg_match('/^node\/([0-9]+)\/submissions?/',$request)==1)
    {
if($node->uid != $user->uid)
{
drupal_goto('<front>');
}
    }

Any help will be really appreciated.

Thank!

#1

Amir Simantov - April 1, 2009 - 20:27

Addition: I have found that the node is null in this context. So, how can I get it?

#2

Amir Simantov - April 2, 2009 - 16:49

Update: Done it inside webform_submission_access which is in webform.module file.

Still, would like to know why $node was null...

 
 

Drupal is a registered trademark of Dries Buytaert.