| 1 |
<?php
|
| 2 |
// $Id: subscriptions_cck.module,v 1.4 2008/12/26 15:50:13 salvis Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
*
|
| 7 |
* Provide support of CCK fields by adding corresponding mailvars.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_subscriptions_tokens_list().
|
| 12 |
*
|
| 13 |
* Provide replacable tokens for mail_edit.
|
| 14 |
*
|
| 15 |
* @ingroup hooks
|
| 16 |
*/
|
| 17 |
function subscriptions_cck_subscriptions_tokens_list($mailkey, $options = array()) {
|
| 18 |
$tr = 't';
|
| 19 |
$variables = array('%fieldname' => '<fieldname>', '!content_type', $tr('content type'));
|
| 20 |
$tokens = array (
|
| 21 |
'!ccklabel_<fieldname>' => t('The label for the CCK field %fieldname, as defined for your !content_type.', $variables),
|
| 22 |
'!cckvalue1_<fieldname>' => t('The value(s) of the CCK field %fieldname, as defined for your !content_type, comma-separated.', $variables),
|
| 23 |
'!cckvalue2_<fieldname>' => t('The value(s) of the CCK field %fieldname, as defined for your !content_type, newline-separated.', $variables),
|
| 24 |
);
|
| 25 |
return $tokens;
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Implementation of hook_subscriptions_get_mailvars().
|
| 30 |
*
|
| 31 |
* Add the !cck... variables.
|
| 32 |
*
|
| 33 |
* @ingroup hooks
|
| 34 |
*/
|
| 35 |
function subscriptions_cck_subscriptions_get_mailvars($node) {
|
| 36 |
$mailvars = array();
|
| 37 |
if (isset($node->type) && ($fields = content_fields(NULL, $node->type))) {
|
| 38 |
foreach ($fields as $field_name => $field_info) {
|
| 39 |
if (isset($node->$field_name)) {
|
| 40 |
$values = $node->$field_name;
|
| 41 |
$formatteds = array();
|
| 42 |
foreach ($values as $value) {
|
| 43 |
if (!($formatted = html_entity_decode( content_format($field_info, $value, 'plain'), ENT_QUOTES, 'UTF-8'))) {
|
| 44 |
$formatted = content_format($field_info, $value, 'default');
|
| 45 |
}
|
| 46 |
$formatted = drupal_html_to_text($formatted);
|
| 47 |
$formatteds[] = $formatted;
|
| 48 |
}
|
| 49 |
$mailvars['!ccklabel_'. $field_name] = $field_info['widget']['label'];
|
| 50 |
$mailvars['!cckvalue1_'. $field_name] = implode(', ', $formatteds);
|
| 51 |
$mailvars['!cckvalue2_'. $field_name] = implode("\n", $formatteds);
|
| 52 |
}
|
| 53 |
}
|
| 54 |
}
|
| 55 |
return $mailvars;
|
| 56 |
}
|
| 57 |
|
| 58 |
|