unpublished_nodes_redirect.module in Unpublished Nodes Redirect 7
File
unpublished_nodes_redirect.module
View source
<?php
function unpublished_nodes_redirect_menu() {
$items['admin/config/system/unpublished-nodes-redirect'] = array(
'title' => 'Unpublished Nodes Redirects',
'description' => 'Setup redirect paths for unpublished nodes.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'unpublished_nodes_redirect_admin_settings_form',
),
'access arguments' => array(
'administer site configuration',
),
'file path' => drupal_get_path('module', 'unpublished_nodes_redirect'),
'file' => 'unpublished_nodes_redirect.admin.inc',
);
return $items;
}
function unpublished_nodes_redirect_menu_alter(&$items) {
$items['node/%node']['access callback'] = 'unpublished_nodes_redirect_access_callback';
}
function unpublished_nodes_redirect_access_callback($op, $node, $account = NULL) {
if ($node->status == 0 && !user_is_logged_in()) {
if (variable_get('cron_semaphore', FALSE) === FALSE && $_SERVER['SCRIPT_NAME'] !== '/cron.php' && arg(3) !== 'run-cron') {
if (arg(0) != 'js') {
$redirect_path = variable_get($node->type . '_unpublished_redirect_path', '');
$response_code = variable_get($node->type . '_unpublished_redirect_response_code');
if (!empty($redirect_path) && $response_code != 0) {
drupal_goto($redirect_path, array(), $response_code);
}
}
}
}
return node_access($op, $node, $account);
}
function unpublished_nodes_redirect_module_implements_alter(&$implementations, $hook) {
if (isset($implementations['unpublished_nodes_redirect'])) {
switch ($hook) {
case 'menu_alter':
$group = $implementations['unpublished_nodes_redirect'];
unset($implementations['unpublished_nodes_redirect']);
$implementations['unpublished_nodes_redirect'] = $group;
break;
}
}
}