| 1 |
<?php
|
| 2 |
// $Id: comment.api.php,v 1.12 2009/10/10 13:37:09 dries 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 was built; the module may modify the structured content.
|
| 77 |
*
|
| 78 |
* This hook is called after the content has been assembled in a structured array
|
| 79 |
* and may be used for doing processing which requires that the complete comment
|
| 80 |
* content structure has been built.
|
| 81 |
*
|
| 82 |
* If the module wishes to act on the rendered HTML of the comment rather than the
|
| 83 |
* structured content array, it may use this hook to add a #post_render callback.
|
| 84 |
* Alternatively, it could also implement hook_preprocess_comment(). See
|
| 85 |
* drupal_render() and theme() documentation respectively for details.
|
| 86 |
*
|
| 87 |
* @param $build
|
| 88 |
* A renderable array representing the comment.
|
| 89 |
*
|
| 90 |
* @see comment_build()
|
| 91 |
*/
|
| 92 |
function hook_comment_build_alter($build) {
|
| 93 |
// Check for the existence of a field added by another module.
|
| 94 |
if ($build['#build_mode'] == 'full' && isset($build['an_additional_field'])) {
|
| 95 |
// Change its weight.
|
| 96 |
$build['an_additional_field']['#weight'] = -10;
|
| 97 |
}
|
| 98 |
|
| 99 |
// Add a #post_render callback to act on the rendered HTML of the comment.
|
| 100 |
$build['#post_render'][] = 'my_module_comment_post_render';
|
| 101 |
}
|
| 102 |
|
| 103 |
/**
|
| 104 |
* The comment is being published by the moderator.
|
| 105 |
*
|
| 106 |
* @param $comment
|
| 107 |
* Passes in the comment the action is being performed on.
|
| 108 |
* @return
|
| 109 |
* Nothing.
|
| 110 |
*/
|
| 111 |
function hook_comment_publish($comment) {
|
| 112 |
drupal_set_message(t('Comment: @subject has been published', array('@subject' => $comment->subject)));
|
| 113 |
}
|
| 114 |
|
| 115 |
/**
|
| 116 |
* The comment is being unpublished by the moderator.
|
| 117 |
*
|
| 118 |
* @param $comment
|
| 119 |
* Passes in the comment the action is being performed on.
|
| 120 |
* @return
|
| 121 |
* Nothing.
|
| 122 |
*/
|
| 123 |
function hook_comment_unpublish($comment) {
|
| 124 |
drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->subject)));
|
| 125 |
}
|
| 126 |
|
| 127 |
/**
|
| 128 |
* The comment is being deleted by the moderator.
|
| 129 |
*
|
| 130 |
* @param $comment
|
| 131 |
* Passes in the comment the action is being performed on.
|
| 132 |
* @return
|
| 133 |
* Nothing.
|
| 134 |
*/
|
| 135 |
function hook_comment_delete($comment) {
|
| 136 |
drupal_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->subject)));
|
| 137 |
}
|
| 138 |
|
| 139 |
/**
|
| 140 |
* @} End of "addtogroup hooks".
|
| 141 |
*/
|