| 1 |
<?php
|
| 2 |
// $Id: comment.api.php,v 1.11 2009/08/17 13:10:45 webchick Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Hooks provided by the Comment module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* @addtogroup hooks
|
| 11 |
* @{
|
| 12 |
*/
|
| 13 |
|
| 14 |
/**
|
| 15 |
* The comment passed validation and is about to be saved.
|
| 16 |
*
|
| 17 |
* Modules may make changes to the comment before it is saved to the database.
|
| 18 |
*
|
| 19 |
* @param $comment
|
| 20 |
* The comment object.
|
| 21 |
*/
|
| 22 |
function hook_comment_presave($comment) {
|
| 23 |
// Remove leading & trailing spaces from the comment subject.
|
| 24 |
$comment->subject = trim($comment->subject);
|
| 25 |
}
|
| 26 |
|
| 27 |
/**
|
| 28 |
* The comment is being inserted.
|
| 29 |
*
|
| 30 |
* @param $comment
|
| 31 |
* The comment object.
|
| 32 |
*/
|
| 33 |
function hook_comment_insert($comment) {
|
| 34 |
// Reindex the node when comments are added.
|
| 35 |
search_touch_node($comment->nid);
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* The comment is being updated.
|
| 40 |
*
|
| 41 |
* @param $comment
|
| 42 |
* The comment object.
|
| 43 |
*/
|
| 44 |
function hook_comment_update($comment) {
|
| 45 |
// Reindex the node when comments are updated.
|
| 46 |
search_touch_node($comment->nid);
|
| 47 |
}
|
| 48 |
|
| 49 |
/**
|
| 50 |
* Comments are being loaded from the database.
|
| 51 |
*
|
| 52 |
* @param $comments
|
| 53 |
* An array of comment objects indexed by cid.
|
| 54 |
*/
|
| 55 |
function hook_comment_load($comments) {
|
| 56 |
$result = db_query('SELECT cid, foo FROM {mytable} WHERE cid IN (:cids)', array(':cids' => array_keys($comments)));
|
| 57 |
foreach ($result as $record) {
|
| 58 |
$comments[$record->cid]->foo = $record->foo;
|
| 59 |
}
|
| 60 |
}
|
| 61 |
|
| 62 |
/**
|
| 63 |
* The comment is being viewed. This hook can be used to add additional data to the comment before theming.
|
| 64 |
*
|
| 65 |
* @param $comment
|
| 66 |
* Passes in the comment the action is being performed on.
|
| 67 |
* @return
|
| 68 |
* Nothing.
|
| 69 |
*/
|
| 70 |
function hook_comment_view($comment) {
|
| 71 |
// how old is the comment
|
| 72 |
$comment->time_ago = time() - $comment->changed;
|
| 73 |
}
|
| 74 |
|
| 75 |
/**
|
| 76 |
* The comment is being published by the moderator.
|
| 77 |
*
|
| 78 |
* @param $comment
|
| 79 |
* Passes in the comment the action is being performed on.
|
| 80 |
* @return
|
| 81 |
* Nothing.
|
| 82 |
*/
|
| 83 |
function hook_comment_publish($comment) {
|
| 84 |
drupal_set_message(t('Comment: @subject has been published', array('@subject' => $comment->subject)));
|
| 85 |
}
|
| 86 |
|
| 87 |
/**
|
| 88 |
* The comment is being unpublished by the moderator.
|
| 89 |
*
|
| 90 |
* @param $comment
|
| 91 |
* Passes in the comment the action is being performed on.
|
| 92 |
* @return
|
| 93 |
* Nothing.
|
| 94 |
*/
|
| 95 |
function hook_comment_unpublish($comment) {
|
| 96 |
drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->subject)));
|
| 97 |
}
|
| 98 |
|
| 99 |
/**
|
| 100 |
* The comment is being deleted by the moderator.
|
| 101 |
*
|
| 102 |
* @param $comment
|
| 103 |
* Passes in the comment the action is being performed on.
|
| 104 |
* @return
|
| 105 |
* Nothing.
|
| 106 |
*/
|
| 107 |
function hook_comment_delete($comment) {
|
| 108 |
drupal_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->subject)));
|
| 109 |
}
|
| 110 |
|
| 111 |
/**
|
| 112 |
* @} End of "addtogroup hooks".
|
| 113 |
*/
|