summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--comment_notify.install23
-rw-r--r--comment_notify.lib.inc97
-rw-r--r--comment_notify.module35
-rw-r--r--comment_notify.test10
4 files changed, 87 insertions, 78 deletions
diff --git a/comment_notify.install b/comment_notify.install
index 7022974..504f4b0 100644
--- a/comment_notify.install
+++ b/comment_notify.install
@@ -6,11 +6,12 @@
*/
/**
- * Implementation of hook_install().
+ * Implements hook_install().
*/
function comment_notify_install() {
- // Create entries for existing comments.
+ // Create entries for existing comments.
+
$comments_select = db_select('comment', 'c');
$comments_select->join('users', 'u', 'c.uid = u.uid');
$comments_select->addField('c', 'cid');
@@ -19,30 +20,30 @@ function comment_notify_install() {
$comments_select->addExpression('md5(c.mail || coalesce(u.mail, u.init) || c.uid || c.name || c.nid)', 'notify_hash');
}
else {
- $comments_select->addExpression('md5(concat(c.mail, ifnull(u.mail, u.init), c.uid, c.name, c.nid))', 'notify_hash');
+ $comments_select->addExpression('md5(concat(c.mail, ifnull(u.mail, u.init), c.uid, c.name, c.nid))', 'notify_hash');
}
$comments_select->addField('c', 'cid');
-
+
// Set module weight low so that other modules act on the comment first.
db_insert('comment_notify')->from($comments_select)->execute();
db_update('system')->
- fields(array(
- 'weight' => 10
- ))
- ->condition('name', 'comment_notify');
+ fields(array(
+ 'weight' => 10
+ ))
+ ->condition('name', 'comment_notify');
}
/**
- * Implementation of hook_uninstall().
+ * Implements hook_uninstall().
*/
function comment_notify_uninstall() {
variable_del('node_notify_default_mailtext');
db_delete('variable')
- ->where('name', "comment_notify_%", 'LIKE');
+ ->where('name', "comment_notify_%", 'LIKE');
}
/**
- * Implementation of hook_schema().
+ * Implements hook_schema().
*/
function comment_notify_schema() {
$schema['comment_notify'] = array(
diff --git a/comment_notify.lib.inc b/comment_notify.lib.inc
index acc9b33..f330e89 100644
--- a/comment_notify.lib.inc
+++ b/comment_notify.lib.inc
@@ -1,5 +1,5 @@
<?php
-// $Id;
+// $Id$
/**
* @file
@@ -9,7 +9,7 @@
/**
* Get the notification preferences for a specific user.
- *
+ *
* @param integer $uid
* @return StdClass
*/
@@ -21,14 +21,15 @@ function comment_notify_get_user_notification_setting($uid) {
}
// Handle anonymous users with defaults.
if ($uid == 0) {
- $users[0] = new StdClass();
- $users[0]->comment_notify = comment_notify_variable_registry_get('default_registered_mailalert');
+ $users[0] = new stdClass();
+ $users[0]->comment_notify = comment_notify_variable_registry_get('default_registered_mailalert');
$users[0]->node_notify = comment_notify_variable_registry_get('node_notify_default_mailalert');
- } else {
+ }
+ else {
$result = db_select('comment_notify_user_settings', 'cnus')
- ->fields('cnus')
- ->condition('uid', $uid)
- ->execute();
+ ->fields('cnus')
+ ->condition('uid', $uid)
+ ->execute();
$users[$uid] = $result->fetchObject();
}
}
@@ -37,7 +38,7 @@ function comment_notify_get_user_notification_setting($uid) {
/**
* Remove comment notification preferences for a user.
- *
+ *
* @param integer $uid
* @return boolean
*/
@@ -49,7 +50,7 @@ function comment_notify_delete_user_notification_setting($uid) {
/**
* Get a user's default preference for comment notification.
- *
+ *
* @param integer $uid
* @return integer
*/
@@ -60,9 +61,9 @@ function comment_notify_get_user_comment_notify_preference($uid) {
/**
* Get a user's default preference for node update notification.
- *
+ *
* This is notification on nodes where the user is the author.
- *
+ *
* @param integer $uid
* @return integer
*/
@@ -73,7 +74,7 @@ function comment_notify_get_user_node_notify_preference($uid) {
/**
* Sets the notification preferences for a specific user.
- *
+ *
* @param integer $uid
* @param integer $node_notification
* @param integer $comment_notification
@@ -88,12 +89,13 @@ function comment_notify_set_user_notification_setting($uid, $node_notification =
$fields['node_notify'] = $node_notification;
}
if (!is_null($comment_notification)) {
- $fields['comment_notify'] = $comment_notification;
+ $fields['comment_notify'] = $comment_notification;
}
if (comment_notify_get_user_notification_setting($uid)) {
$query = db_update('comment_notify_user_settings');
$query->condition('uid', $uid);
- } else {
+ }
+ else {
$query = db_insert('comment_notify_user_settings');
}
return (bool)$query
@@ -103,7 +105,7 @@ function comment_notify_set_user_notification_setting($uid, $node_notification =
/**
* Add a notification against a comment.
- *
+ *
* @param integer $cid
* @param integer $notify
* @param string $notify_hash
@@ -112,16 +114,16 @@ function comment_notify_set_user_notification_setting($uid, $node_notification =
function comment_notify_add_notification($cid, $notify, $notify_hash) {
return (bool)db_insert('comment_notify')
->fields(array(
- 'cid' => $cid,
+ 'cid' => $cid,
'notify' => $notify,
- 'notify_hash' =>$notify_hash,
+ 'notify_hash' => $notify_hash,
))
->execute();
}
/**
* Remove all the notifications linked with a comment
- *
+ *
* @param integer $cid
* @return boolean
*/
@@ -133,7 +135,7 @@ function comment_notify_remove_all_notifications($cid) {
/**
* Updated a notification with a different notification type
- *
+ *
* @param integer $cid
* @param integer $notify
* @return boolean
@@ -149,7 +151,7 @@ function comment_notify_update_notification($cid, $notify) {
/**
* Returns TRUE if the owner of this comment notification has already been notified.
- *
+ *
* @param integer $cid
* @return boolean
*/
@@ -164,12 +166,12 @@ function comment_notify_is_notification_already_sent($cid) {
/**
* Get the unique identification hash for a comment notification record.
- *
+ *
* @param integer $cid
* @return string
*/
function comment_notify_get_notify_hash($cid) {
- return db_select('comment_notify', 'cn')
+ return db_select('comment_notify', 'cn')
->fields('cn', array('notify_hash'))
->condition('cid', $cid)
->execute()
@@ -178,12 +180,12 @@ function comment_notify_get_notify_hash($cid) {
/**
* Get the type of notification for a comment notification record.
- *
+ *
* @param integer $cid
* @return integer
*/
function comment_notify_get_notification_type($cid) {
- return db_select('comment_notify', 'cn')
+ return db_select('comment_notify', 'cn')
->fields('cn', array('notify'))
->condition('cid', $cid)
->execute()
@@ -192,7 +194,7 @@ function comment_notify_get_notification_type($cid) {
/**
* Returns the thread which a comment belongs to.
- *
+ *
* @param integer $cid
* @return string
* The thread identifier.
@@ -207,7 +209,7 @@ function comment_notify_get_thread($cid) {
/**
* Get a list of mails which need to be contacted for a node.
- *
+ *
* @param integer $nid
* @return QueryStatement
*/
@@ -229,20 +231,20 @@ function comment_notify_get_watchers($nid) {
$query->addField('c', 'mail', 'cmail');
$query->addField('u', 'init', 'uinit');
$query->addField('u', 'mail', 'umail');
-
+
return $query->execute();
}
/**
* Record that the owner of a comment notification request has already been notified.
- *
+ *
* @param integer $cid
* @return boolean
*/
function comment_notify_mark_comment_as_notified($cid) {
return (bool)db_update('comment_notify')
->fields(array(
- 'notified' => 1,
+ 'notified' => 1,
))
->condition('cid', $cid)
->execute();
@@ -253,62 +255,63 @@ function comment_notify_mark_comment_as_notified($cid) {
*
* If the email belongs to a user, it will unsubscribe all of their comment notify records.
* If it does not, then it will unsubscribe all anonymous users.
- *
+ *
* @param string $mail
* @return boolean
*/
function comment_notify_unsubscribe_by_email($mail) {
$update_query = db_update('comment_notify');
$update_query->fields(array('notify' => 0));
-
+
$comment_query = db_select('comment', 'c');
$comment_query->fields('c', array('cid'));
-
+
$uid = db_select('users', 'u')
->fields('u', array('uid'))
->condition('mail', $mail)
->execute()
->fetchField();
if ($uid) {
- $comment_query->condition('uid', $uid);
- } else {
+ $comment_query->condition('uid', $uid);
+ }
+ else {
$comment_query->condition('mail', $mail);
}
$update_query->condition('cid', $comment_query, 'IN');
-
+
return (bool)$update_query->execute();
}
/**
* Unsubscribe all comment notification requests associated with a hash.
- *
+ *
* This is used in the unsubscribe link.
- *
+ *
* @param string $hash
* @return boolean
*/
function comment_notify_unsubscribe_by_hash($hash) {
return (bool)db_update('comment_notify')
->fields(array(
- 'notify' => 0,
+ 'notify' => 0,
))
->condition('notify_hash', $hash)
->execute();
}
-
+
/**
* Helper function to centralize variable management and defaults.
- *
+ *
* All variables full under the "comment_notify" psuedo namespace. This ensures
* consistancy, and eliminates some verbosity in the calling code. In addition
* by storing all of the variables in one place, we avoid repeating duplicate
* defaults which are harder to maintain.
- *
+ *
* @param string $name
* @return mixed
*/
function comment_notify_variable_registry_get($name) {
- $variables = array ();
+ $variables = array();
$variables['author_subject'] = '[site:name] :: new comment for your post.';
$variables['available_alerts'] = array(COMMENT_NOTIFY_NODE, COMMENT_NOTIFY_COMMENT);
$variables['default_anon_mailalert'] = COMMENT_NOTIFY_NODE;
@@ -318,8 +321,8 @@ function comment_notify_variable_registry_get($name) {
$variables['comment_notify_default_registered_mailalert'] = COMMENT_NOTIFY_DISABLED;
$variables['watcher_subject'] = '[site:name] :: new comment on [node:title]';
$variables['comment_notify_default_mailtext'] = DEFAULT_MAILTEXT;
- $variables['node_types'] = array('article' =>'article');
-
+ $variables['node_types'] = array('article' => 'article');
+
// Errors
$variables['error_anonymous_email_missing'] = 'If you want to subscribe to comments you must supply a valid e-mail address.';
return variable_get("comment_notify_" . $name, $variables[$name]);
@@ -327,7 +330,7 @@ function comment_notify_variable_registry_get($name) {
/**
* Helper function to centralize setting variables.
- *
+ *
* @param string $name
* @param mixed $value
* @return boolean
@@ -338,7 +341,7 @@ function comment_notify_variable_registry_set($name, $value) {
/**
* Helper function to tokenize a piece of text for a comment notify mail.
- *
+ *
* @param string $text
* @param StdClass $comment
* A comment object.
diff --git a/comment_notify.module b/comment_notify.module
index baeed19..d2ab930 100644
--- a/comment_notify.module
+++ b/comment_notify.module
@@ -94,8 +94,8 @@ function comment_notify_form_comment_form_alter(&$form, &$form_state, $form_id)
$available_options = _comment_notify_options();
- drupal_add_css(drupal_get_path('module', 'comment_notify') .'/comment_notify.css');
- drupal_add_js(drupal_get_path('module', 'comment_notify') .'/comment_notify.js');
+ drupal_add_css(drupal_get_path('module', 'comment_notify') . '/comment_notify.css');
+ drupal_add_js(drupal_get_path('module', 'comment_notify') . '/comment_notify.js');
// Add the checkbox for anonymous users and set the default based on admin settings.
if ($user->uid == 0) {
@@ -150,7 +150,7 @@ function comment_notify_form_comment_form_alter(&$form, &$form_state, $form_id)
}
/**
- * Implement of hook_permission().
+ * Implements hook_permission().
*/
function comment_notify_permission() {
return array(
@@ -166,7 +166,7 @@ function comment_notify_permission() {
}
/**
- * Implement of hook_menu().
+ * Implements hook_menu().
*/
function comment_notify_menu() {
@@ -213,7 +213,8 @@ function comment_notify_menu() {
function comment_notify_disable_page($hash) {
if (comment_notify_unsubscribe_by_hash($hash)) {
drupal_set_message(t('Your comment follow-up notification for this post was disabled. Thanks.'));
- } else {
+ }
+ else {
drupal_set_message(t('Sorry, there was a problem unsubscribing from notifications.'));
}
return ' ';
@@ -285,7 +286,7 @@ function comment_notify_form_alter(&$form, &$form_state, $form_id) {
if (!($form_id == 'user_register_form' || $form_id == 'user_profile_form')) {
return;
}
- elseif ($form['#user_category'] != 'account'){
+ elseif ($form['#user_category'] != 'account') {
return;
}
@@ -306,7 +307,7 @@ function comment_notify_form_alter(&$form, &$form_state, $form_id) {
// Only show the node followup UI if the user has permission to create nodes.
$nodes = FALSE;
foreach (node_type_get_names() as $type) {
- if (user_access('create '. $type .' content')) {
+ if (user_access('create ' . $type . ' content')) {
$nodes = TRUE;
break;
}
@@ -428,7 +429,7 @@ function _comment_notify_mailalert($comment) {
if (!empty($author->comment_notify_settings->node_notify) && $author->node_notify_mailalert == 1 && $user->uid != $author->uid && node_access('view', $node, $author)) {
// Get the author's language.
$language = user_preferred_language($author);
- $raw_values = array (
+ $raw_values = array(
'subject' => comment_notify_variable_registry_get('author_subject'),
'body' => comment_notify_variable_registry_get('node_notify_default_mailtext'), //JS @todo:change this.
);
@@ -451,7 +452,7 @@ function _comment_notify_mailalert($comment) {
$umail = empty($alert->umail) ? $alert->uinit : $alert->umail;
$mail = empty($alert->cmail) ? $umail : $alert->cmail;
- $relevant_thread = substr($thread, 0, drupal_strlen($alert->thread) -1);
+ $relevant_thread = drupal_substr($thread, 0, drupal_strlen($alert->thread) -1);
if ($alert->notify == COMMENT_NOTIFY_COMMENT && strcmp($relevant_thread . '/', $alert->thread) != 0) {
continue;
}
@@ -472,7 +473,7 @@ function _comment_notify_mailalert($comment) {
continue;
}
- $raw_values = array (
+ $raw_values = array(
'subject' => comment_notify_variable_registry_get('watcher_subject'),
'body' => comment_notify_variable_registry_get('comment_notify_default_mailtext'), //JS @todo:change this var name.
);
@@ -490,7 +491,7 @@ function _comment_notify_mailalert($comment) {
// Make the mail link to user's /edit, unless it's an anonymous user.
if ($alert->uid != 0) {
- $user_mail = l($mail, 'user/'. $alert->uid .'/edit');
+ $user_mail = l($mail, 'user/' . $alert->uid . '/edit');
}
else {
$user_mail = check_plain($mail);
@@ -502,8 +503,8 @@ function _comment_notify_mailalert($comment) {
'Notified: !user_mail',
array('!user_mail' => $user_mail),
WATCHDOG_NOTICE,
- l(t('source comment'), 'node/'. $nid, array(
- 'fragment' => 'comment-'. $alert->cid,
+ l(t('source comment'), 'node/' . $nid, array(
+ 'fragment' => 'comment-' . $alert->cid,
))
);
@@ -518,7 +519,7 @@ function _comment_notify_mailalert($comment) {
}
/**
- * Implement of hook_mail().
+ * Implements hook_mail().
*/
function comment_notify_mail($key, &$message, $params) {
$message['subject'] = $params['subject'];
@@ -571,10 +572,10 @@ function comment_notify_settings() {
$default[] = $type;
// If they don't have the ability to leave contact info, then we make a report
- if (isset($enabled_types[$type]) && $enabled_types[$type] && variable_get('comment_anonymous_'. $type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
+ if (isset($enabled_types[$type]) && $enabled_types[$type] && variable_get('comment_anonymous_' . $type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
$account = drupal_anonymous_user();
if (user_access('subscribe to comments', $account)) {
- $anonymous_problems[] = l(t('@content-type', array('@content-type' => $name)), 'admin/content/node-type/'. $type);
+ $anonymous_problems[] = l(t('@content-type', array('@content-type' => $name)), 'admin/content/node-type/' . $type);
}
}
}
@@ -679,7 +680,7 @@ function comment_notify_tokens($type, $tokens, array $data = array(), array $opt
return;
}
$replacements = array();
- $replacements['comment:unsubscribe_url'] = url('comment_notify/disable/'. $hash, array('absolute' => TRUE));
+ $replacements['comment:unsubscribe_url'] = url('comment_notify/disable/' . $hash, array('absolute' => TRUE));
return $replacements;
}
diff --git a/comment_notify.test b/comment_notify.test
index 9fc1167..8816a9e 100644
--- a/comment_notify.test
+++ b/comment_notify.test
@@ -1,6 +1,10 @@
<?php
// $Id$
+/**
+ * @file
+ * Creates tests for comment_notify module.
+ */
class CommentNotifyTestCase extends DrupalWebTestCase {
/**
* Implementation of getInfo().
@@ -52,7 +56,7 @@ class CommentNotifyTestCase extends DrupalWebTestCase {
$this->assertText(t($expected_error));
// Try again with an e-mail address.
- $contact_1 = array('mail' => $this->randomName() .'@'. $this->randomName());
+ $contact_1 = array('mail' => $this->randomName() . '@' . $this->randomName());
$anonymous_comment_1 = $this->postCommentNotifyComment($this->node, $this->randomName(), $this->randomName(), TRUE, $subscribe_1, $contact_1);
// Confirm that the notification is saved.
@@ -61,7 +65,7 @@ class CommentNotifyTestCase extends DrupalWebTestCase {
// Notify type 2 - replies to a comment.
$subscribe_2 = array('notify' => TRUE, 'notify_type' => 2);
- $contact_2 = array('mail' => $this->randomName() .'@'. $this->randomName());
+ $contact_2 = array('mail' => $this->randomName() . '@' . $this->randomName());
$anonymous_comment_2 = $this->postCommentNotifyComment($this->node, $this->randomName(), $this->randomName(), TRUE, $subscribe_2, $contact_2);
// Confirm that the notification is saved.
@@ -74,7 +78,7 @@ class CommentNotifyTestCase extends DrupalWebTestCase {
// Notify type 0 (i.e. only one mode is enabled).
variable_set('comment_notify_available_alerts', array(1 => 0, 2 => 2));
$subscribe_0 = array('notify' => TRUE);
- $contact_0 = array('mail' => $this->randomName() .'@'. $this->randomName());
+ $contact_0 = array('mail' => $this->randomName() . '@' . $this->randomName());
$anonymous_comment_0 = $this->postCommentNotifyComment($this->node, $this->randomName(), $this->randomName(), TRUE, $subscribe_0, $contact_0);
// Confirm that the notification is saved.