You are here

function _simpleads_redirect in SimpleAds 7

Menu callback. Redirect Ads. If user is Admin -> redirect to Ad edit page, otherwise redirect to target URL.

1 string reference to '_simpleads_redirect'
simpleads_menu in ./simpleads.module
Implements hook_menu().

File

./simpleads.module, line 408

Code

function _simpleads_redirect($nid) {
  global $user;
  drupal_page_is_cacheable(FALSE);
  if (is_numeric($nid)) {
    $node = node_load($nid);
    $url = "";
    $default_message = t("You have been redirected here because you have permission to edit ads.\n      Please log out from the site or open the site in different browser if you wish to test that the ad redirection is correct.");
    $message = variable_get('simpleads_redirect_message', $default_message);
    $show_message = variable_get('simpleads_redirect_message_show', TRUE);
    $delta = variable_get('simpleads_redirect_delta', 'default');
    if (isset($node->field_ad_url[$node->language]) && !empty($node->field_ad_url[$node->language][0]['value'])) {
      $url = $node->field_ad_url[$node->language][0]['value'];
      if (user_access('administer nodes') || user_access('access ad node')) {
        if ($show_message) {
          drupal_set_message(filter_xss($message), 'warning');
        }
        drupal_goto('node/' . $node->nid);
      }
      else {
        _simpleads_save_click($node);
        $url = _simpleads_validate_url($url);
        module_invoke_all('simpleads_redirect', $url, $delta);
      }
    }
    else {
      return t('URL Address is not specified');
    }
  }
  return ' ';
}