<?php

/*
 * Implementation of hook_menu
*/
function commentextra_menu() {
  $items['comment/publish/%'] = array(
    'title' => 'Publish comment',
    'page callback' => 'comment_publish',
    'access arguments' => array('administer comments'),
    'type' => MENU_CALLBACK,
    'page arguments' => array(2),
    'file' => 'commentextra.admin.inc',
  );
  $items['comment/unpublish/%'] = array(
    'title' => 'Unpublish comment',
    'page callback' => 'comment_unpublish',
    'access arguments' => array('administer comments'),
    'type' => MENU_CALLBACK,
    'page arguments' => array(2),
    'file' => 'commentextra.admin.inc',
  );

  return $items;
}
/*
 * Implementation of hook_views_api
*/
function commentextra_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'commentextra'),
  );
}

function commentextra_action_info() {
  return array(
    'comment_publish_action' => array(
      'description' => t('Publish comment'),
      'type' => 'comment',
      'configurable' => FALSE,
      'hooks' => array(
        'comment' => array('insert', 'update'),
      )
    ),
  );
}

function comment_publish_action($comment, $context = array()) {
  if (isset($comment->cid)) {
    $cid = $comment->cid;
    $subject = $comment->subject;
  }
  else {
    $cid = $context['cid'];
    $subject = db_result(db_query("SELECT subject FROM {comments} WHERE cid = %d", $cid));
  }
  db_query('UPDATE {comments} SET status = %d WHERE cid = %d', COMMENT_PUBLISHED, $cid);
  watchdog('action', 'Published comment %subject.', array('%subject' => $subject));
}
