Commit 6690a4ec authored by Dries's avatar Dries

- Patch #353480 by dereine, justinrandell: remove from hook_comment().

parent fbf4e0f1
...@@ -12,37 +12,99 @@ ...@@ -12,37 +12,99 @@
*/ */
/** /**
* Act on comments. * The comment is being inserted.
* *
* This hook allows modules to extend the comments system. * @param $form_values
* Passes in an array of form values submitted by the user.
* @return
* Nothing.
*/
function hook_comment_insert(&$form_values) {
$nid = $form_values['nid'];
cache_clear_all_like(drupal_url(array('id' => $nid)));
}
/**
* The user has just finished editing the comment and is trying to
* preview or submit it. This hook can be used to check or
* even modify the node. Errors should be set with form_set_error().
* *
* @param $a1 * @param $form_values
* Dependent on the action being performed. * Passes in an array of form values submitted by the user.
* - For "validate","update","insert", passes in an array of form values submitted by the user.
* - For all other operations, passes in the comment the action is being performed on.
* @param $op
* What kind of action is being performed. Possible values:
* - "insert": The comment is being inserted.
* - "update": The comment is being updated.
* - "view": The comment is being viewed. This hook can be used to add additional data to the comment before theming.
* - "validate": The user has just finished editing the comment and is
* trying to preview or submit it. This hook can be used to check or
* even modify the node. Errors should be set with form_set_error().
* - "publish": The comment is being published by the moderator.
* - "unpublish": The comment is being unpublished by the moderator.
* - "delete": The comment is being deleted by the moderator.
* @return * @return
* Dependent on the action being performed. * Nothing.
* - For all other operations, nothing.
*/ */
function hook_comment(&$a1, $op) { function hook_comment_validate(&$form_values) {
if ($op == 'insert' || $op == 'update') { // if the subject is the same as the comment.
$nid = $a1['nid']; if ($form_values['subject'] == $form_values['comment']) {
form_set_error('comment', t('you should write more text than in the subject'));
} }
}
/**
* The comment is being updated.
*
* @param $form_values
* Passes in an array of form values submitted by the user.
* @return
* Nothing.
*/
function hook_comment_update(&$form_values) {
$nid = $form_values['nid'];
cache_clear_all_like(drupal_url(array('id' => $nid))); cache_clear_all_like(drupal_url(array('id' => $nid)));
} }
/**
* The comment is being viewed. This hook can be used to add additional data to the comment before theming.
*
* @param $comment
* Passes in the comment the action is being performed on.
* @return
* Nothing.
*/
function hook_comment_view(&$comment) {
// how old is the comment
$comment->time_ago = time() - $comment->timestamp;
}
/**
* The comment is being published by the moderator.
*
* @param $form_values
* Passes in an array of form values submitted by the user.
* @return
* Nothing.
*/
function hook_comment_publish($form_values) {
drupal_set_message(t('Comment: @subject has been published', array('@subject' => $form_values['subject'])));
}
/**
* The comment is being unpublished by the moderator.
*
* @param $comment
* Passes in the comment the action is being performed on.
* @return
* Nothing.
*/
function hook_comment_unpublish(&$comment) {
drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->subject)));
}
/**
* The comment is being deleted by the moderator.
*
* @param $comment
* Passes in the comment the action is being performed on.
* @return
* Nothing.
*/
function hook_comment_delete(&$comment) {
drupal_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->subject)));
}
/** /**
* @} End of "addtogroup hooks". * @} End of "addtogroup hooks".
*/ */
...@@ -1990,7 +1990,7 @@ function _comment_update_node_statistics($nid) { ...@@ -1990,7 +1990,7 @@ function _comment_update_node_statistics($nid) {
} }
/** /**
* Invoke a hook_comment() operation in all modules. * Invoke a hook_comment_[$op]() operation in all modules.
* *
* @param &$comment * @param &$comment
* A comment object. * A comment object.
...@@ -2001,9 +2001,9 @@ function _comment_update_node_statistics($nid) { ...@@ -2001,9 +2001,9 @@ function _comment_update_node_statistics($nid) {
*/ */
function comment_invoke_comment(&$comment, $op) { function comment_invoke_comment(&$comment, $op) {
$return = array(); $return = array();
foreach (module_implements('comment') as $module) { foreach (module_implements('comment_' . $op) as $module) {
$function = $module . '_comment'; $function = $module . '_comment_' . $op;
$result = $function($comment, $op); $result = $function($comment);
if (isset($result) && is_array($result)) { if (isset($result) && is_array($result)) {
$return = array_merge($return, $result); $return = array_merge($return, $result);
} }
......
...@@ -659,19 +659,43 @@ function search_nodeapi_update($node) { ...@@ -659,19 +659,43 @@ function search_nodeapi_update($node) {
} }
/** /**
* Implementation of hook_comment(). * Implementation of hook_comment_insert().
*/ */
function search_comment($a1, $op) { function search_comment_insert($form_values) {
switch ($op) { // Reindex the node when comments are added.
// Reindex the node when comments are added or changed search_touch_node($form_values['nid']);
case 'insert': }
case 'update':
case 'delete': /**
case 'publish': * Implementation of hook_comment_update().
case 'unpublish': */
search_touch_node(is_array($a1) ? $a1['nid'] : $a1->nid); function search_comment_update($form_values) {
break; // Reindex the node when comments are changed.
} search_touch_node($form_values['nid']);
}
/**
* Implementation of hook_comment_delete().
*/
function search_comment_delete($comment) {
// Reindex the node when comments are deleted.
search_touch_node($comment->nid);
}
/**
* Implementation of hook_comment_publish().
*/
function search_comment_publish($form_values) {
// Reindex the node when comments are published.
search_touch_node($form_values['nid']);
}
/**
* Implementation of hook_comment_unpublish().
*/
function search_comment_unpublish($comment) {
// Reindex the node when comments are unpublished.
search_touch_node($comment->nid);
} }
/** /**
......
...@@ -303,15 +303,45 @@ function _trigger_normalize_comment_context($type, $comment) { ...@@ -303,15 +303,45 @@ function _trigger_normalize_comment_context($type, $comment) {
} }
/** /**
* Implementation of hook_comment(). * Implementation of hook_comment_insert().
*/ */
function trigger_comment($a1, $op) { function trigger_comment_insert($form_values) {
_trigger_coment($form_values, 'insert');
}
/**
* Implementation of hook_comment_update().
*/
function trigger_comment_update($form_values) {
_trigger_coment($form_values, 'update');
}
/**
* Implementation of hook_comment_delete().
*/
function trigger_comment_delete($comment) {
_trigger_coment($comment, 'delete');
}
/**
* Implementation of hook_comment_view().
*/
function trigger_comment_view($comment) {
_trigger_coment($comment, 'view');
}
/**
* Helper function for implementations of hook_comment_op().
*
* @param $a1
* Argument, which will be passed to the action.
* It can be a array of form values or a comment.
* @param $op
* What kind of action is being performed.
*/
function _trigger_comment($a1, $op) {
// Keep objects for reuse so that changes actions make to objects can persist. // Keep objects for reuse so that changes actions make to objects can persist.
static $objects; static $objects;
// We support a subset of operations.
if (!in_array($op, array('insert', 'update', 'delete', 'view'))) {
return;
}
$aids = _trigger_get_hook_aids('comment', $op); $aids = _trigger_get_hook_aids('comment', $op);
$context = array( $context = array(
'hook' => 'comment', 'hook' => 'comment',
......
...@@ -2037,17 +2037,14 @@ function user_forms() { ...@@ -2037,17 +2037,14 @@ function user_forms() {
} }
/** /**
* Implementation of hook_comment(). * Implementation of hook_comment_view().
*/ */
function user_comment(&$comment, $op) { function user_comment_view(&$comment) {
// Validate signature. if (variable_get('user_signatures', 0) && !empty($comment->signature)) {
if ($op == 'view') { $comment->signature = check_markup($comment->signature, $comment->format);
if (variable_get('user_signatures', 0) && !empty($comment->signature)) { }
$comment->signature = check_markup($comment->signature, $comment->format); else {
} $comment->signature = '';
else {
$comment->signature = '';
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment