upadted feedback module
didn't repatched it for email notification since rules hooks semmes to be added to the module added the old patch for memory
This commit is contained in:
@@ -80,6 +80,51 @@ function feedback_entity_info() {
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info().
|
||||
*/
|
||||
function feedback_entity_property_info() {
|
||||
$info = array();
|
||||
$properties = &$info['feedback']['properties'];
|
||||
|
||||
$properties['fid'] = array(
|
||||
'label' => t('Feedback ID'),
|
||||
'type' => 'integer',
|
||||
'description' => t('The Feedback ID'),
|
||||
'schema field' => 'fid',
|
||||
);
|
||||
$properties['status'] = array(
|
||||
'label' => t("Status"),
|
||||
'type' => 'integer',
|
||||
'description' => t("0 for new, 1 for processed"),
|
||||
'schema field' => 'status',
|
||||
);
|
||||
$properties['author'] = array(
|
||||
'label' => t("Author"),
|
||||
'type' => 'user',
|
||||
'description' => t("The author of the feedback."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'required' => TRUE,
|
||||
'schema field' => 'uid',
|
||||
);
|
||||
$properties['message'] = array(
|
||||
'label' => t("Title"),
|
||||
'description' => t("The feedback message."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'schema field' => 'message',
|
||||
'required' => TRUE,
|
||||
);
|
||||
$properties['timestamp'] = array(
|
||||
'label' => t("Date created"),
|
||||
'type' => 'date',
|
||||
'schema field' => 'timestamp',
|
||||
'description' => t("The date the feedback was created."),
|
||||
);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_field_extra_fields().
|
||||
*/
|
||||
@@ -287,11 +332,22 @@ function feedback_form($form, &$form_state) {
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
foreach ($feedbacks as $fid => $feedback) {
|
||||
$form['messages'][$fid]['#feedback'] = $feedback;
|
||||
$form['messages'][$fid]['submitted'] = array('#markup' => t('@feedback-author !feedback-date:', array('@feedback-author' => format_username($feedback), '!feedback-date' => format_date($feedback->timestamp, 'small'))));
|
||||
$form['messages'][$fid] = array(
|
||||
'#type' => 'container',
|
||||
'#attributes' => array('class' => array('feedback-entry')),
|
||||
'#feedback' => $feedback,
|
||||
);
|
||||
$form['messages'][$fid]['submitted'] = array(
|
||||
'#markup' => t('@feedback-author !feedback-date:', array(
|
||||
'@feedback-author' => format_username($feedback),
|
||||
'!feedback-date' => format_date($feedback->timestamp, 'small'),
|
||||
)),
|
||||
);
|
||||
$form['messages'][$fid]['submitted']['#prefix'] = '<div class="feedback-submitted">';
|
||||
$form['messages'][$fid]['submitted']['#suffix'] = '</div>';
|
||||
$form['messages'][$fid]['body'] = feedback_build_content($feedback, 'widget');
|
||||
feedback_build_content($feedback, 'widget');
|
||||
$form['messages'][$fid]['body'] = $feedback->content;
|
||||
unset($feedback->content);
|
||||
$form['messages'][$fid]['body']['#prefix'] = '<div class="feedback-body">';
|
||||
$form['messages'][$fid]['body']['#suffix'] = '</div>';
|
||||
}
|
||||
@@ -549,235 +605,6 @@ function feedback_user_delete($account) {
|
||||
feedback_delete_multiple($fids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_action_info().
|
||||
*/
|
||||
function feedback_action_info() {
|
||||
return array(
|
||||
'feedback_process_action' => array(
|
||||
'label' => t('Process entry'),
|
||||
'type' => 'feedback',
|
||||
'configurable' => FALSE,
|
||||
'behavior' => array('changes_property'),
|
||||
'triggers' => array('feedback_insert', 'feedback_update'),
|
||||
),
|
||||
'feedback_open_action' => array(
|
||||
'label' => t('Open entry'),
|
||||
'type' => 'feedback',
|
||||
'configurable' => FALSE,
|
||||
'behavior' => array('changes_property'),
|
||||
'triggers' => array('feedback_insert', 'feedback_update'),
|
||||
),
|
||||
'feedback_delete_action' => array(
|
||||
'label' => t('Delete entry'),
|
||||
'type' => 'feedback',
|
||||
'configurable' => FALSE,
|
||||
'triggers' => array('feedback_insert', 'feedback_update'),
|
||||
),
|
||||
'feedback_send_email_action' => array(
|
||||
'label' => t('Send e-mail of feedback'),
|
||||
'type' => 'feedback',
|
||||
'configurable' => TRUE,
|
||||
'triggers' => array('feedback_insert', 'feedback_update'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_trigger_info().
|
||||
*/
|
||||
function feedback_trigger_info() {
|
||||
return array(
|
||||
'feedback' => array(
|
||||
'feedback_insert' => array(
|
||||
'label' => t('New feedback is added.'),
|
||||
),
|
||||
'feedback_update' => array(
|
||||
'label' => t('Feedback is marked processed or open.'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_feedback_insert().
|
||||
*/
|
||||
function feedback_feedback_insert($entry) {
|
||||
$aids = trigger_get_assigned_actions('feedback_insert');
|
||||
if (!$aids) {
|
||||
return;
|
||||
}
|
||||
|
||||
$context = array(
|
||||
'group' => 'feedback',
|
||||
'hook' => 'feedback_insert',
|
||||
);
|
||||
|
||||
foreach ($aids as $aid => $info) {
|
||||
actions_do($aid, $entry, $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_feedback_update().
|
||||
*/
|
||||
function feedback_feedback_update($entry) {
|
||||
$aids = trigger_get_assigned_actions('feedback_update');
|
||||
if (!$aids) {
|
||||
return;
|
||||
}
|
||||
|
||||
$context = array(
|
||||
'group' => 'feedback',
|
||||
'hook' => 'feedback_update',
|
||||
);
|
||||
|
||||
foreach ($aids as $aid => $info) {
|
||||
actions_do($aid, $entry, $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status of an entry to processed.
|
||||
*
|
||||
* @ingroup actions
|
||||
*/
|
||||
function feedback_process_action($entry, $context) {
|
||||
$entry->status = FEEDBACK_PROCESSED;
|
||||
drupal_write_record('feedback', $entry, 'fid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status of an entry to open.
|
||||
*
|
||||
* @ingroup actions
|
||||
*/
|
||||
function feedback_open_action($entry, $context) {
|
||||
$entry->status = FEEDBACK_OPEN;
|
||||
drupal_write_record('feedback', $entry, 'fid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a feedback entry.
|
||||
*
|
||||
* @ingroup actions
|
||||
*/
|
||||
function feedback_delete_action($entry, $context) {
|
||||
feedback_delete($entry->fid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a form definition so the Feedback send email action can be configured.
|
||||
*
|
||||
* @param $context
|
||||
* Default values (if we are editing an existing action instance).
|
||||
* @return
|
||||
* Form definition.
|
||||
*/
|
||||
function feedback_send_email_action_form($context = array()) {
|
||||
// Set default values for form.
|
||||
$context += array(
|
||||
'recipients' => '',
|
||||
'subject' => '',
|
||||
'message' => '',
|
||||
);
|
||||
|
||||
$form['recipients'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Recipients'),
|
||||
'#default_value' => $context['recipients'],
|
||||
'#description' => t("Example: 'webmaster@example.com' or 'dev@example.com,support@example.com'. To specify multiple recipients, separate each e-mail address with a comma."),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['subject'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Subject'),
|
||||
'#default_value' => $context['subject'],
|
||||
'#maxlength' => '254',
|
||||
'#description' => t('The subject of the message.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['message'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Message'),
|
||||
'#default_value' => $context['message'],
|
||||
'#cols' => '80',
|
||||
'#rows' => '20',
|
||||
'#description' => t('The message that should be sent. You may include the following variables: !uid, !username, !usermail, !useragent (of the user who gave the feedback), !site_name, !status, !message, !url, !date.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the send e-mail action form submission.
|
||||
*/
|
||||
function feedback_send_email_action_validate($form, &$form_state) {
|
||||
if (empty($form_state['values']['recipients'])) {
|
||||
form_set_error('recipients', t('You must enter one or more recipients.'));
|
||||
}
|
||||
else {
|
||||
$recipients = explode(',', $form_state['values']['recipients']);
|
||||
foreach ($recipients as $recipient) {
|
||||
if (!valid_email_address(trim($recipient))) {
|
||||
form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the send e-mail action form submission.
|
||||
*/
|
||||
function feedback_send_email_action_submit($form, $form_state) {
|
||||
// Process the HTML form to store configuration. The keyed array that
|
||||
// we return will be serialized to the database.
|
||||
$params = array(
|
||||
'recipients' => $form_state['values']['recipients'],
|
||||
'subject' => $form_state['values']['subject'],
|
||||
'message' => $form_state['values']['message'],
|
||||
);
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the feedback send e-mail action.
|
||||
*/
|
||||
function feedback_send_email_action($entry, $context) {
|
||||
$account = user_load($entry->uid);
|
||||
$from = variable_get('site_name', 'Drupal') . ' <' . variable_get('site_mail', '') . '>';
|
||||
$params = array('entry' => $entry, 'account' => $account, 'context' => $context);
|
||||
// Send the e-mail to the recipients using the site default language.
|
||||
drupal_mail('feedback', 'send_email_action', $context['recipients'], language_default(), $params, $from);
|
||||
watchdog('feedback', 'Feedback information sent to %recipients', array('%recipients' => $context['recipients']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_mail().
|
||||
*/
|
||||
function feedback_mail($key, &$message, $params) {
|
||||
$language = $message['language'];
|
||||
$entry = $params['entry'];
|
||||
$account = $params['account'];
|
||||
$context = $params['context'];
|
||||
$variables = array(
|
||||
'!site_name' => variable_get('site_name', 'Drupal'),
|
||||
'!uid' => $account->uid,
|
||||
'!username' => $account->name ? $account->name : t('Anonymous'),
|
||||
'!usermail' => $account->mail ? $account->mail : t('unknown'),
|
||||
'!status' => $entry->status ? t('Processed') : t('Open'),
|
||||
'!message' => $entry->message,
|
||||
'!url' => url($entry->location, array('absolute' => TRUE, 'language' => $language)),
|
||||
'!useragent' => $entry->useragent,
|
||||
'!date' => format_date($entry->timestamp, 'small', '', NULL, $language->language),
|
||||
);
|
||||
$subject = strtr($context['subject'], $variables);
|
||||
$body = strtr($context['message'], $variables);
|
||||
$message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
|
||||
$message['body'][] = drupal_html_to_text($body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_mollom_form_list().
|
||||
*/
|
||||
@@ -820,3 +647,23 @@ function feedback_views_api() {
|
||||
'path' => drupal_get_path('module', 'feedback') . '/views',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_feedback_insert().
|
||||
*/
|
||||
function feedback_feedback_insert($entry) {
|
||||
// Trigger rule if Rules is enabled
|
||||
if (module_exists('rules')) {
|
||||
rules_invoke_event('feedback_insert', $entry);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_feedback_update().
|
||||
*/
|
||||
function feedback_feedback_update($entry) {
|
||||
// Trigger rule if Rules is enabled
|
||||
if (module_exists('rules')) {
|
||||
rules_invoke_event('feedback_update', $entry);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user