view_unpublished.module in view_unpublished 5
File
view_unpublished.module
View source
<?php
function view_unpublished_perm() {
$perms = array(
'use view_unpublished module',
'view all unpublished content',
'edit all unpublished content',
);
$types = db_query("select type from {node_type}");
$i = 0;
while ($type = db_result($types, $i++)) {
$perms[] = 'view unpublished ' . $type . ' content';
$perms[] = 'edit unpublished ' . $type . ' content';
}
return $perms;
}
function view_unpublished_menu($may_cache) {
$items = array();
if (!$may_cache) {
if (is_numeric(arg(1)) && arg(0) == 'node' && user_access('use view_unpublished module') && !user_access('administer nodes')) {
$node = node_load(arg(1));
if ($node->status == 0 && (user_access('view unpublished ' . $node->type . ' content') || user_access('view all unpublished content'))) {
$items[] = array(
'path' => 'node/' . arg(1),
'title' => t('View'),
'callback' => 'node_page_view',
'callback arguments' => array(
$node,
),
'type' => MENU_CALLBACK,
'access' => true,
);
}
if ($node->status == 0 && (user_access('edit unpublished ' . $node->type . ' content') || user_access('edit all unpublished content'))) {
$items[] = array(
'path' => 'node/' . arg(1) . '/edit',
'title' => t('Edit'),
'callback' => 'node_page_edit',
'callback arguments' => array(
$node,
),
'access' => true,
'weight' => 1,
'type' => MENU_LOCAL_TASK,
);
}
}
}
return $items;
}
function view_unpublished_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'update':
if (is_numeric(arg(1)) && arg(0) == 'node' && arg(2) == 'edit' && user_access('use view_unpublished module') && !user_access('administer nodes')) {
if ($node->status == 0 && (user_access('view unpublished ' . $node->type . ' content') || user_access('view all unpublished content'))) {
drupal_goto("node/{$node->nid}");
}
}
break;
}
}