Commit 623f9bde authored by greggles's avatar greggles

#822924 by Dave Reid: Use token tree for help on Comment Notify settings fields.

parent 90002b08
......@@ -361,25 +361,3 @@ function comment_notify_variable_registry_set($name, $value) {
return variable_set("comment_notify_" . $name, $value);
}
/**
* Helper function to tokenize a piece of text for a comment notify mail.
*
* @param string $text
* @param StdClass $comment
* A comment object.
* @param StdClass $node
* A node object.
* @param StdClass $user
* A user object.
* @return string
* The processed string.
*/
function comment_notify_tokenize($text, $comment, $node, $user) {
$data = array(
'node' => $node,
'comment' => $comment,
'user' => $user,
);
return token_replace($text, $data);
}
......@@ -2,7 +2,10 @@
name = Comment Notify
description = "Comment follow-up e-mail notification for anonymous as well as registered users."
dependencies[] = comment
dependencies[] = token
core = 7.x
files[] = comment_notify.install
files[] = comment_notify.module
files[] = comment_notify.tokens.inc
files[] = comment_notify.inc
files[] = comment_notify.test
......@@ -13,7 +13,7 @@ define('COMMENT_NOTIFY_COMMENT', 2);
define('AUTHOR_MAILTEXT',
'Hi [user:name],
'Hi [comment:node:author],
You have received a comment on: "[node:title]"
......@@ -27,7 +27,7 @@ You can view the comment at the following url
You will receive emails like this for all replies to your posts. You can
disable this by logging in and changing the settings on your user account at
[user:edit-url].
[comment:node:author:edit-url].
-- [site:name] team
[site:url]');
......@@ -46,10 +46,10 @@ You can view the comment at the following url
[comment:url]
You can stop receiving emails when someone replies to this post,
by going to [comment:unsubscribe_url]
by going to [comment:unsubscribe-url]
You can set up auto-following feature for all future posts
by creating your own user with a few clicks here [site:url]/user/register
by creating your own user with a few clicks here [site:login-url]
-- [site:name] team
[site:url]');
......@@ -445,7 +445,7 @@ function _comment_notify_mailalert($comment) {
'body' => comment_notify_variable_registry_get('node_notify_default_mailtext'), //JS @todo:change this.
);
foreach ($raw_values as $k => $v) {
$message[$k] = comment_notify_tokenize(t($v), $comment, $node, $user);
$message[$k] = token_replace(t($v), array('comment' => $comment, 'node' => $node, 'user' => $user));
}
drupal_mail('comment_notify', 'comment_notify_mail', $author->mail, $language, $message);
......@@ -490,7 +490,7 @@ function _comment_notify_mailalert($comment) {
);
foreach ($raw_values as $k => $v) {
$message[$k] = comment_notify_tokenize(t($v), $comment, $node, $user);
$message[$k] = token_replace(t($v), array('comment' => $comment, 'node' => $node, 'user' => $user));
}
// array(
......@@ -644,12 +644,9 @@ function comment_notify_settings() {
'#description' => t('If this is checked, new users will receive e-mail notifications for follow-ups on their nodes by default until they individually disable the feature.'),
);
$token_help = "Need a theme_token_info :(";
$form['comment_notify_settings']['comment_notify_comment_notify_default_mailtext'] = array(
'#type' => 'textarea',
'#title' => t('Default mail text for sending out notifications to commenters'),
'#suffix' => $token_help,
'#default_value' => comment_notify_variable_registry_get('comment_notify_default_mailtext'),
'#return_value' => 1,
'#cols' => 80,
......@@ -659,13 +656,17 @@ function comment_notify_settings() {
$form['comment_notify_settings']['comment_notify_node_notify_default_mailtext'] = array(
'#type' => 'textarea',
'#title' => t('Default mail text for sending out the notifications to node authors'),
'#suffix' => $token_help,
'#default_value' => comment_notify_variable_registry_get('node_notify_default_mailtext'),
'#return_value' => 1,
'#cols' => 80,
'#rows' => 15
);
$form['comment_notify_settings']['token_help'] = array(
'#theme' => 'token_tree',
'#token_types' => array('comment'),
);
$form['#validate'] = array('comment_notify_settings_validate');
return system_settings_form($form);
......@@ -681,22 +682,3 @@ function comment_notify_settings_validate($form, &$form_state) {
}
}
function comment_notify_tokens($type, $tokens, array $data = array(), array $options = array()) {
module_load_include('inc', 'comment_notify', 'comment_notify');
// Add the tokens for unsubscribe links
if ($type != "comment" ||!isset($data['comment'])) {
return;
}
$cid = $data['comment']->cid;
$hash = comment_notify_get_notify_hash($cid);
if (!$hash) {
return;
}
$replacements = array();
$replacements['comment:unsubscribe_url'] = url('comment_notify/disable/' . $hash, array('absolute' => TRUE));
return $replacements;
}
<?php
// $Id$
/**
* @file
* Builds placeholder replacement tokens for comment_notify.module.
*/
/**
* Implements hook_token_info().
*/
function comment_notify_token_info() {
$info['tokens']['comment']['unsubscribe-url'] = array(
'name' => t('Unsubscribe URL'),
'description' => t('The URL to disable notifications for the comment.'),
);
return $info;
}
/**
* Implements hook_tokens().
*/
function comment_notify_tokens($type, $tokens, array $data = array(), array $options = array()) {
$url_options = array('absolute' => TRUE);
if (isset($options['language'])) {
$url_options['language'] = $options['language'];
$language_code = $options['language']->language;
}
else {
$language_code = NULL;
}
$sanitize = !empty($options['sanitize']);
$replacements = array();
if ($type == 'comment' && !empty($data['comment'])) {
$comment = $data['comment'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'unsubscribe-url':
module_load_include('inc', 'comment_notify', 'comment_notify');
if ($hash = comment_notify_get_notify_hash($cid)) {
$replacements[$original] = url('comment_notify/disable/' . $hash, $url_options);
}
break;
}
}
}
}
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