diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-06-29 18:06:51 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-06-29 18:06:51 +0000 |
commit | 2348e7de6f9714496316ee42d5598efeb0faaee3 (patch) | |
tree | faf22908035129ddd942071cace661b068e1f7d6 /modules/comment | |
parent | 8dd8b0c22373106181d40e1bfa8af9c47dd127cb (diff) | |
download | brdo-2348e7de6f9714496316ee42d5598efeb0faaee3.tar.gz brdo-2348e7de6f9714496316ee42d5598efeb0faaee3.tar.bz2 |
- Patch #148410 by jvandyk: added rewrite of the actions module!
This is a very important patch, but one that is merely an enabler.
Hopefully we'll see more people submitting "action patches" in the
near future.
Thanks for the hard work and persistence, John. *If* you decide
to update the Drupal Pro Development book to Drupal 6, make sure
to add a chapter on actions. ;)
Diffstat (limited to 'modules/comment')
-rw-r--r-- | modules/comment/comment.module | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module index e65f88095..4478f2904 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -2086,3 +2086,107 @@ function int2vancode($i = 0) { function vancode2int($c = '00') { return base_convert(substr($c, 1), 36, 10); } + +/** + * Implementation of hook_hook_info(). + */ +function comment_hook_info() { + return array( + 'comment' => array( + 'comment' => array( + 'insert' => array( + 'runs when' => t('When a comment has been created'), + ), + 'update' => array( + 'runs when' => t('When a comment has been updated'), + ), + 'delete' => array( + 'runs when' => t('When a comment has been deleted') + ), + 'view' => array( + 'runs when' => t('When a comment is being viewed') + ), + ), + ), + ); +} + +/** + * Implementation of hook_action_info(). + */ +function comment_action_info() { + return array( + 'comment_unpublish_action' => array( + 'description' => t('Unpublish comment'), + 'type' => 'comment', + 'configurable' => FALSE, + 'hooks' => array( + 'comment' => array('insert', 'update', 'view'), + ) + ), + 'comment_unpublish_by_keyword_action' => array( + 'description' => t('Unpublish comment containing keyword(s)'), + 'type' => 'comment', + 'configurable' => TRUE, + 'hooks' => array( + 'comment' => array('insert', 'update'), + ) + ) + ); +} + +/** + * Drupal action to unpublish a comment. + * + * @param $context + * Keyed array. Must contain the id of the comment if $comment is not passed. + * @param $comment + * An optional comment object. + */ +function comment_unpublish_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_NOT_PUBLISHED, $cid); + watchdog('action', 'Unpublished comment %subject.', array('%subject' => $subject)); +} + +function comment_unpublish_by_keyword_action_form($context) { + $form['keywords'] = array( + '#title' => t('Keywords'), + '#type' => 'textarea', + '#description' => t('The comment will be unpublished if it contains any of the character sequences above. Use a comma-separated list of character sequences. Example: funny, bungee jumping, "Company, Inc.".'), + '#default_value' => isset($context['keywords']) ? drupal_implode_tags($context['keywords']) : '', + ); + return $form; +} + +function comment_unpublish_by_keyword_action_submit($form, $form_state) { + return array('keywords' => drupal_explode_tags($form_state['values']['keywords'])); +} + +/** + * Implementation of a configurable Drupal action. + * Unpublish a comment if it contains a certain string. + * + * @param $context + * An array providing more information about the context of the call to this action. + * Unused here since this action currently only supports the insert and update ops of + * the comment hook, both of which provide a complete $comment object. + * @param $comment + * A comment object. + */ +function comment_unpublish_by_keyword_action($comment, $context) { + foreach ($context['keywords'] as $keyword) { + if (strstr($comment->comment, $keyword) || strstr($comment->subject, $keyword)) { + db_query('UPDATE {comments} SET status = %d WHERE cid = %d', COMMENT_NOT_PUBLISHED, $comment->cid); + watchdog('action', 'Unpublished comment %subject.', array('%subject' => $comment->subject)); + break; + } + } +}
\ No newline at end of file |