Commit 3a99699d authored by jcnventura's avatar jcnventura

Use new D7 system queue

Fix links in individual comments when not yet in node-specific db
parent 2831322b
.print-link {
/* Use these for links above the content */
text-align: left;
/* Use these for links in a corner of the content */
/*
float:left;
float: left;
*/
}
......@@ -21,7 +20,3 @@
img.print-icon-margin {
padding-left: 4px;
}
label.printmail-label {
float: right;
}
.print-link {
/* Use these for links above the content */
display: block;
......@@ -6,9 +5,9 @@
padding-bottom: 0.5em;
/* Use these for links in a corner of the content */
/*
position:relative;
position: relative;
bottom: 0.5em;
float:right;
float: right;
*/
}
......@@ -31,8 +30,3 @@ img.print-icon {
img.print-icon-margin {
padding-right: 4px;
}
label.printmail-label {
width: 175px;
float: left;
}
......@@ -70,7 +70,6 @@ function print_print_link() {
'format' => 'html',
'text' => t('Printer-friendly version'),
'description' => t('Display a printer-friendly version of this page.'),
'permission' => 'access print',
'path' => 'print',
'class' => 'print-page',
'icon' => 'print_icon.gif',
......@@ -311,13 +310,26 @@ function _print_get_title($path) {
*/
function print_insert_link($path = NULL, $node = NULL) {
if (function_exists('print_ui_insert_link')) {
return print_ui_insert_link('html', $path, $node);
return print_ui_insert_link(print_print_link(), $path, $node);
}
else {
return FALSE;
}
}
/**
* Check if the link to the PF version is allowed depending on the settings
*
* @param $args
* array containing the possible parameters:
* teaser, node, type, path
* @return
* FALSE if not allowed, TRUE otherwise
*/
function print_link_allowed($args) {
return (user_access('access print'));
}
/**
* Implements hook_contextual_links_view_alter().
*/
......
......@@ -287,7 +287,7 @@ function _print_var_generator($node, $message = NULL, $cid = NULL) {
for ($i = 0; $i < $max; $i++) {
$pfp_links .= '[' . ($i + 1) . '] ' . check_plain($urls[$i]) . "<br />\n";
}
$print['pfp_links'] = "<p><strong>" . t('Links') . "</strong><br />$pfp_links</p>";
$print['pfp_links'] = "<p><strong>" . t('Links') . "</strong><br />$pfp_links</p>";
}
}
......
label.printmail-label {
float: right;
}
label.printmail-label {
width: 175px;
float: left;
}
......@@ -62,14 +62,12 @@ function print_mail_settings() {
$form['settings']['print_mail_send_option_default']['#options']['plain-attachment'] = t('Plain Text with Attachment');
}
if (module_exists('job_queue')) {
$form['settings']['print_mail_job_queue'] = array(
'#type' => 'checkbox',
'#title' => t('Send emails using Job Queue'),
'#default_value' => variable_get('print_mail_job_queue', PRINT_MAIL_JOB_QUEUE_DEFAULT),
'#description' => t("Selecting this option, email delivery will be performed by the Job Queue module during each cron run. Leaving this unselected, the email will be sent immediately, but the site will take slightly longer to reply to the user."),
);
}
$form['settings']['print_mail_job_queue'] = array(
'#type' => 'checkbox',
'#title' => t('Send emails using queue'),
'#default_value' => variable_get('print_mail_job_queue', PRINT_MAIL_JOB_QUEUE_DEFAULT),
'#description' => t("Selecting this option, email delivery will be performed by the system queue during each cron run. Leaving this unselected, the email will be sent immediately, but the site will take slightly longer to reply to the user."),
);
$form['settings']['print_mail_display_sys_urllist'] = array(
'#type' => 'checkbox',
......
......@@ -181,7 +181,7 @@ function print_mail_form($form, &$form_state) {
* @ingroup forms
*/
function theme_print_mail_form($form) {
drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
drupal_add_css(drupal_get_path('module', 'print_mail') . '/css/print_mail.theme.css');
$content = '';
foreach (element_children($form) as $key) {
$tmp = drupal_render($form[$key]);
......@@ -297,36 +297,24 @@ function print_mail_form_submit($form, &$form_state) {
$params['body'] = theme('print', array('print' => $print, 'type' => $link['format'], 'node' => $node));
$ok = FALSE;
if (function_exists('job_queue_add') && variable_get('print_mail_job_queue', PRINT_MAIL_JOB_QUEUE_DEFAULT)) {
$use_job_queue = TRUE;
$this_file = drupal_get_path('module', 'print_mail') . '/print_mail.inc';
}
else {
$use_job_queue = FALSE;
$use_job_queue = variable_get('print_mail_job_queue', PRINT_MAIL_JOB_QUEUE_DEFAULT);
if ($use_job_queue) {
$queue = DrupalQueue::get('print_mail_send');
}
$addresses = explode(', ', $form_state['values']['txt_to_addrs']);
foreach ($addresses as $to) {
// Call to hook_print_mail_before_send in order to know if the mail can be sent
// Handlers must return TRUE or FALSE
$can_send = module_invoke_all('print_mail_before_send', $node, $to, $from, $params);
if (!in_array(FALSE, $can_send)) {
if ($use_job_queue) {
// Use job queue to send mails during cron runs
job_queue_add('drupal_mail', t('print_mail: From %from', array('%from' => $from)), array('print_mail', $print_mail_send_option_default, $to, language_default(), $params, $from, TRUE), $this_file, TRUE);
}
else {
// Send mail immediately using Drupal's mail handler
$ret = drupal_mail('print_mail', $print_mail_send_option_default, $to, language_default(), $params, $from, TRUE);
}
if ($ret['result'] || $use_job_queue) {
// Call to hook_print_mail_after_send in order to provide information to other modules.
module_invoke_all('print_mail_after_send', $node, $to, $from, $params);
flood_register_event('print_mail');
$ok = TRUE;
}
if ($use_job_queue) {
// Use job queue to send mails during cron runs
$queue->createItem(array('module' => 'print_mail', 'key' => $print_mail_send_option_default, 'to' => $to, 'language' => language_default(), 'params' => $params, 'from' => $from));
}
else {
// Send mail immediately using Drupal's mail handler
$ret = drupal_mail('print_mail', $print_mail_send_option_default, $to, language_default(), $params, $from);
}
if ($use_job_queue || $ret['result']) {
flood_register_event('print_mail');
$ok = TRUE;
}
}
if ($ok) {
......@@ -350,61 +338,6 @@ function print_mail_form_submit($form, &$form_state) {
$form_state['redirect'] = preg_replace('!^book/export/html/!', 'node/', $form_state['values']['path']);
}
/**
* Implements hook_mail().
*/
function print_mail_mail($key, &$message, $params) {
$message['subject'] = $params['subject'];
switch ($key) {
case 'sendpage':
$message['body'][] = check_plain($params['body']);
$message['headers']['Content-Type'] = 'text/html; charset=utf-8';
break;
case 'sendlink':
// Generate plain-text and html versions of message with link
$sendlink_plain = $params['message'] . '\n\n' . $params['link'];
$sendlink_html = $params['message'] . '<br/><br/>' . l($params['title'], $params['link']);
// Send HTML-only version if MIME library not present
if (!class_exists('Mail_mime')) {
$message['body'][] = check_plain($sendlink_html);
$message['headers']['Content-Type'] = 'text/html; charset=utf-8';
break;
}
// no break on purpose
case 'plain-attachment':
case 'inline-attachment':
// Configure new MIME object
$mime = new Mail_mime("\n");
$mime_params['html_encoding'] = '7bit';
// Pass message contents into MIME object
switch ($key) {
case 'sendlink':
$mime->setTxtBody($sendlink_plain);
$mime->setHTMLBody($sendlink_html);
break;
case 'inline-attachment':
$mime->setHTMLBody($params['body']);
// no break on purpose
case 'plain-attachment':
$mime->setTxtBody($params['message']);
$mime->addAttachment($params['body'], 'text/html', 'Attachment.html', FALSE);
break;
}
// Store MIME message output in message array
$message['body'][] = check_plain($mime->get($mime_params));
$message['headers'] = $mime->headers($message['headers']);
// Strip special characters from Content-Type header
// Required to prevent mime_header_encode() from disrupting Content-Type header
$message['headers']['Content-Type'] = preg_replace('/[^\x20-\x7E]/', '', $message['headers']['Content-Type']);
break;
}
}
/**
* Callback function for the preg_replace_callback replacing spaces with %20
*
......
......@@ -21,7 +21,6 @@ function print_mail_print_link() {
'format' => 'mail',
'text' => t('Send by email'),
'description' => t('Send this page by email.'),
'permission' => 'access send by email',
'path' => 'printmail',
'class' => 'print-mail',
'icon' => 'mail_icon.gif',
......@@ -133,14 +132,73 @@ function print_mail_node_delete($node) {
}
/**
* Implements hook_job_queue_functions().
* Implements hook_cron_queue_info().
*/
function print_mail_job_queue_functions() {
// @todo convert this to D7 job queue
$functions['print_mail'] = array(
'title' => t('Send by email'),
function print_mail_cron_queue_info() {
$queues['print_mail_send'] = array(
'worker callback' => 'print_mail_send',
'time' => 60,
);
return $functions;
return $queues;
}
function print_mail_send($data) {
drupal_mail($data['module'], $data['key'], $data['to'], $data['language'], $data['params'], $data['from']);
}
/**
* Implements hook_mail().
*/
function print_mail_mail($key, &$message, $params) {
$message['subject'] = $params['subject'];
switch ($key) {
case 'sendpage':
$message['body'][] = check_plain($params['body']);
$message['headers']['Content-Type'] = 'text/html; charset=utf-8';
break;
case 'sendlink':
// Generate plain-text and html versions of message with link
$sendlink_plain = $params['message'] . '\n\n' . $params['link'];
$sendlink_html = $params['message'] . '<br/><br/>' . l($params['title'], $params['link']);
// Send HTML-only version if MIME library not present
if (!class_exists('Mail_mime')) {
$message['body'][] = check_plain($sendlink_html);
$message['headers']['Content-Type'] = 'text/html; charset=utf-8';
break;
}
// no break on purpose
case 'plain-attachment':
case 'inline-attachment':
// Configure new MIME object
$mime = new Mail_mime("\n");
$mime_params['html_encoding'] = '7bit';
// Pass message contents into MIME object
switch ($key) {
case 'sendlink':
$mime->setTxtBody($sendlink_plain);
$mime->setHTMLBody($sendlink_html);
break;
case 'inline-attachment':
$mime->setHTMLBody($params['body']);
// no break on purpose
case 'plain-attachment':
$mime->setTxtBody($params['message']);
$mime->addAttachment($params['body'], 'text/html', 'Attachment.html', FALSE);
break;
}
// Store MIME message output in message array
$message['body'][] = check_plain($mime->get($mime_params));
$message['headers'] = $mime->headers($message['headers']);
// Strip special characters from Content-Type header
// Required to prevent mime_header_encode() from disrupting Content-Type header
$message['headers']['Content-Type'] = preg_replace('/[^\x20-\x7E]/', '', $message['headers']['Content-Type']);
break;
}
}
/**
......@@ -199,13 +257,26 @@ function _print_mail_access($permission) {
*/
function print_mail_insert_link($path = NULL, $node = NULL) {
if (function_exists('print_ui_insert_link')) {
return print_ui_insert_link('mail', $path, $node);
return print_ui_insert_link(print_mail_print_link(), $path, $node);
}
else {
return FALSE;
}
}
/**
* Check if the link to send by email is allowed depending on the settings
*
* @param $args
* array containing the possible parameters:
* teaser, node, type, path
* @return
* FALSE if not allowed, TRUE otherwise
*/
function print_mail_link_allowed($args) {
return (user_access('access send by email'));
}
/**
* Implements hook_nollom_form_list().
*/
......
......@@ -30,7 +30,6 @@ function print_pdf_print_link() {
'format' => 'pdf',
'text' => t('PDF version'),
'description' => t('Display a PDF version of this page.'),
'permission' => 'access PDF version',
'path' => 'printpdf',
'class' => 'print-pdf',
'icon' => 'pdf_icon.gif',
......@@ -309,13 +308,28 @@ function print_pdf_node_delete($node) {
*/
function print_pdf_insert_link($path = NULL, $node = NULL) {
if (function_exists('print_ui_insert_link')) {
return print_ui_insert_link('pdf', $path, $node);
return print_ui_insert_link(print_pdf_print_link(), $path, $node);
}
else {
return FALSE;
}
}
/**
* Check if the link to the PDF version is allowed depending on the settings
*
* @param $args
* array containing the possible parameters:
* teaser, node, type, path
* @return
* FALSE if not allowed, TRUE otherwise
*/
function print_pdf_link_allowed($args) {
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
return (user_access('access PDF version') && (!empty($print_pdf_pdf_tool)));
}
/**
* Find out the version of the TCPDF library
*/
......
......@@ -137,7 +137,7 @@ function print_ui_block_view($delta = '') {
$link_pos = variable_get('print_' . $link['format'] . '_link_pos', array(PRINT_UI_LINK_POS_DEFAULT => PRINT_UI_LINK_POS_DEFAULT));
if (!(empty($link_pos['block']))) {
$links = print_ui_insert_link($link['format'], NULL, $node);
$links = print_ui_insert_link($link, NULL, $node);
if (!empty($links)) {
$block['content'] .= $links;
}
......@@ -166,7 +166,7 @@ function print_ui_help($path, $arg) {
if (function_exists($function)) {
$link = call_user_func_array($function, array());
$links .= print_ui_insert_link($link['format']);
$links .= print_ui_insert_link($link);
}
}
if ($links) {
......@@ -188,7 +188,7 @@ function print_ui_node_view_alter(&$build) {
$link_pos = variable_get('print_html_link_pos', array(PRINT_UI_LINK_POS_DEFAULT => PRINT_UI_LINK_POS_DEFAULT));
if (!empty($link_pos['link'])) {
$format = theme('print_ui_format_link', 'html');
$format = theme('print_ui_format_link', array('format' => 'html'));
switch ($book_link) {
case 1:
......@@ -231,7 +231,7 @@ function print_ui_node_view($node, $view_mode) {
foreach (array('node', 'comment') as $type) {
$allowed_type = print_ui_link_allowed($link, array('type' => $type, 'node' => $node, 'view_mode' => $view_mode));
if ($allowed_type) {
drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
drupal_add_css(drupal_get_path('module', 'print_ui') . '/css/print_ui.theme.css');
$links = array();
$format = theme('print_ui_format_link', array('format' => $link['format']));
......@@ -278,7 +278,7 @@ function print_ui_node_view($node, $view_mode) {
}
if (!empty($link_pos['corner'])) {
$corner_markup .= print_ui_insert_link($link['format'], NULL, $node);
$corner_markup .= print_ui_insert_link($link, NULL, $node);
}
}
}
......@@ -491,15 +491,14 @@ function theme_print_ui_format_link($vars) {
if ($link['format'] == $format) {
$link_class = variable_get('print_' . $link['format'] . '_link_class', $link['class']);
@todo new_window
// @todo new_window
$new_window = ($format == 'html') ? variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT) : FALSE;
$new_window = ($format == 'pdf') ? (variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT) == 1) : FALSE;
$show_link = variable_get('print_' . $link['format'] . '_show_link', PRINT_UI_SHOW_LINK_DEFAULT);
$link_text = filter_xss(variable_get('print_' . $link['format'] . '_link_text', $link['text']));
$img = drupal_get_path('module', 'print') . '/icons/' . $link['icon'];
if ($show_link >= 2) {
$html = TRUE;
$img = drupal_get_path('module', 'print') . '/icons/' . $link['icon'];
switch ($show_link) {
case 2:
$text = theme('image', array('path' => $img, 'alt' => $link_text, 'title' => $link_text, 'attributes' => array('class' => array('print-icon'))));
......@@ -508,6 +507,7 @@ function theme_print_ui_format_link($vars) {
$text = theme('image', array('path' => $img, 'alt' => $link_text, 'title' => $link_text, 'attributes' => array('class' => array('print-icon', 'print-icon-margin')))) . $link_text;
break;
}
$html = TRUE;
}
else {
$text = $link_text;
......@@ -539,57 +539,48 @@ function theme_print_ui_format_link($vars) {
* @return
* string with the HTML link to the printer-friendly page
*/
function print_ui_insert_link($format, $path = NULL, $node = NULL) {
foreach (module_implements('print_link') as $module) {
$function = $module . '_print_link';
if (function_exists($function)) {
$link = call_user_func_array($function, array());
if ($link['format'] == $format) {
if ($node !== NULL) {
$nid = $node->nid;
$path = 'node/' . $nid;
$allowed_type = print_ui_link_allowed($link, array('node' => $node));
}
else {
if ($path === NULL) {
$nid = preg_replace('!^node/!', '', $_GET['q']);
$path = $_GET['q'];
}
else {
$nid = NULL;
}
$allowed_type = print_ui_link_allowed($link, array('path' => $path));
}
function print_ui_insert_link($link, $path = NULL, $node = NULL) {
if ($node !== NULL) {
$nid = $node->nid;
$path = 'node/' . $nid;
$allowed_type = print_ui_link_allowed($link, array('node' => $node));
}
else {
if ($path === NULL) {
$nid = preg_replace('!^node/!', '', $_GET['q']);
$path = $_GET['q'];
}
else {
$nid = NULL;
}
$allowed_type = print_ui_link_allowed($link, array('path' => $path));
}
if ($allowed_type) {
if ($nid !== NULL) {
if ($allowed_type === PRINT_UI_ALLOW_BOOK_LINK) {
$path = 'book/export/html/' . $nid;
}
else {
if (variable_get('print_' . $format . '_link_use_alias', PRINT_UI_LINK_USE_ALIAS_DEFAULT) && ($alias = drupal_lookup_path('alias', $path))) {
$path = $alias;
}
else {
$path = $nid;
}
}
$path = $link['path'] . '/' . $path;
$query = _print_ui_query_string_encode($_GET, array('q'));
}
else {
$query = NULL;
}
drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
$format2 = theme('print_ui_format_link', array('format' => $format));
return '<span class="print_html">' . l($format2['text'], $path, array('attributes' => $format2['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format2['html'])) . '</span>';
if ($allowed_type) {
if ($nid !== NULL) {
if ($allowed_type === PRINT_UI_ALLOW_BOOK_LINK) {
$path = 'book/export/html/' . $nid;
}
else {
if (variable_get('print_' . $link['format'] . '_link_use_alias', PRINT_UI_LINK_USE_ALIAS_DEFAULT) && ($alias = drupal_lookup_path('alias', $path))) {
$path = $alias;
}
else {
return FALSE;
$path = $nid;
}
}
$path = $link['path'] . '/' . $path;
$query = _print_ui_query_string_encode($_GET, array('q'));
}
else {
$query = NULL;
}
drupal_add_css(drupal_get_path('module', 'print_ui') . '/css/print_ui.theme.css');
$format = theme('print_ui_format_link', array('format' => $link['format']));
return '<span class="print_html">' . l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) . '</span>';
}
else {
return FALSE;
}
}
......@@ -613,11 +604,13 @@ function print_ui_link_allowed($link, $args) {
return FALSE;
}
}
if (!user_access($link['permission'])) {
// If the user is not allowed
return FALSE;
$link_allowed_func = $link['module'] . '_link_allowed';
if (function_exists($link_allowed_func)) {
if (!$link_allowed_func($args)) {
// If the format-specific function disallows the link
return FALSE;
}
}
// @todo empty($print_pdf_pdf_tool) => return FALSE
if (!empty($args['path'])) {
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
if (ctype_digit($nid)) {
......@@ -639,8 +632,7 @@ function print_ui_link_allowed($link, $args) {
if (!isset($res[$link['format']][$node->nid])) {
$res[$link['format']][$node->nid] = db_query("SELECT comments FROM {" . $link['module'] . "_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))->fetchField();
}
// @todo only $res?
$display_comment = $res ? intval($res[$link['format']][$node->nid]) : variable_get('print_' . $link['format'] . '_display_comment_' . $node_type, PRINT_UI_TYPE_COMMENT_LINK_DEFAULT);
$display_comment = ($res[$link['format']][$node->nid] !== FALSE) ? $res[$link['format']][$node->nid] : variable_get('print_' . $link['format'] . '_display_comment_' . $node_type, PRINT_UI_TYPE_COMMENT_LINK_DEFAULT);
if ($display_comment) {
return PRINT_UI_ALLOW_NORMAL_LINK;
}
......
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