<?php
function publishcontent_perm() {
  $perms = array('view 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[] = 'publish '. $type .' content';
  }
  return $perms;
}

function publishcontent_menu($may_cache) {
  $items = array();
  if (!$may_cache) {
    if ( arg(0) == 'node' && is_numeric(arg(1)) && !user_access('administer nodes')) {
      $node = node_load(arg(1));
      $type = $node->type;
      if ($node->status == 0 && (user_access('view unpublished '. $type .' content') || user_access('view all unpublished content'))) {
        $items[] = array(
          'path' => 'node/'. arg(1), 
          'title' => t('View'),
          'callback' => 'node_page_view',
          'callback arguments' => arg(1),
          'access' => user_access('view unpublished '. $type .' content'),
          'type' => MENU_CALLBACK,
        );
      }
    }
  }
  return $items;
}

function publishcontent_form_alter($form_id, &$form) {
// First we need to know if the user is admin or not.
  if(!user_access('administer nodes')){
// Second we need to find out what the node type is
    if (is_numeric(arg(1)) && arg(0) == 'node') {
      $node = node_load(arg(1));
      $type = $node->type;
    }elseif(arg(0) == 'node' && arg(1) == 'add') {
      $type = arg(2);
      $node->status = 1;
    }
// Now that we have the type we can define the form id
// and execute the conditional hook_form_alter w/ the 
// correct #access
    $type_form = $type.'_node_form';
    if($form_id == $type_form){
      $form['options'] = array(
        '#type' => 'fieldset',
        '#access' => user_access('publish '. $type .' content'),
        '#title' => t('Publishing options'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
        '#weight' => 25,
      );
      $form['options']['status'] = array(
        '#type' => 'checkbox', 
        '#title' => t('Published'), 
        '#default_value' => $node->status
      );
    }
  }
}