diff --git a/includes/simplenews.admin.inc b/includes/simplenews.admin.inc index c0efd07..c0d3110 100644 --- a/includes/simplenews.admin.inc +++ b/includes/simplenews.admin.inc @@ -354,7 +354,7 @@ function simplenews_admin_categories() { /** * Form builder function, display a list of SimpleNews categories. * - * @ingroup theming + * @ingroup themeable */ function theme_simplenews_admin_categories($variables) { $form = $variables['form']; @@ -416,6 +416,7 @@ function simplenews_admin_category_form($form, &$form_state, $edit = array()) { 'new_account' => 'none', 'opt_inout' => 'double', 'block' => 1, + 'page' => 0, 'format' => $config->get('simplenews_format'), 'priority' => $config->get('simplenews_priority'), 'receipt' => $config->get('simplenews_receipt'), @@ -494,6 +495,14 @@ function simplenews_admin_category_form($form, &$form_state, $edit = array()) { '#description' => t('A subscription block will be provided for this newsletter category. Anonymous and authenticated users can subscribe and unsubscribe using this block.'), ); + // Provide subscription page for this category. + $form['subscription']['page'] = array( + '#type' => 'checkbox', + '#title' => t('Subscription page'), + '#default_value' => $edit['page'], + '#description' => t('A subscription page will be provided for this newsletter category at the URL newsletter/subscriptions/[tid]'), + ); + $form['email'] = array( '#type' => 'fieldset', '#title' => t('Email settings'), @@ -1819,7 +1828,7 @@ function simplenews_count_subscriptions($tid) { * @return string * HTML string containing an image tag. * - * @ingroup theming + * @ingroup themeable */ function theme_simplenews_status($variables) { $source = $variables['source']; @@ -1878,7 +1887,7 @@ function theme_simplenews_status($variables) { /** * Theme SimpleNews issues and subscriptions filter form. * - * @ingroup theming + * @ingroup themeable */ function theme_simplenews_filter_form($variables) { $form = $variables['form']; @@ -1893,7 +1902,7 @@ function theme_simplenews_filter_form($variables) { /** * Theme SimpleNews subscriptions administration filter form. * - * @ingroup theming + * @ingroup themeable */ function theme_simplenews_subscription_filter_form($variables) { // TODO: Should this theme simplenews_subscription_filter_form be declared in hook_theme()? diff --git a/includes/simplenews.subscription.inc b/includes/simplenews.subscription.inc index 09885fd..860d3b3 100644 --- a/includes/simplenews.subscription.inc +++ b/includes/simplenews.subscription.inc @@ -246,6 +246,23 @@ function simplenews_block_form_submit($form, &$form_state) { } } +/** + * Page callback: Generates a subscription signup page. + */ +function simplenews_subscriptions_signup_page($newsletter_id = NULL) { + if (!is_null($newsletter_id)) { + $newsletters = simplenews_categories_load_multiple(array(), array('block' => '1', 'show_all' => FALSE)); + + // Only display a block if $newsletter_id is a valid newsletter term id. + if (in_array($newsletter_id, array_keys($newsletters))) { + $theme_hook_suggestions = array('simplenews_block__' . $newsletter_id, 'simplenews_block'); + $variables = array('tid' => $newsletter_id, 'use_form' => TRUE); + return theme($theme_hook_suggestions, $variables); + } + } + return; +} + /** * FAPI PAGE subscription form. * diff --git a/simplenews.install b/simplenews.install index 6c0bf97..09ce2da 100644 --- a/simplenews.install +++ b/simplenews.install @@ -89,6 +89,13 @@ function simplenews_schema() { 'not null' => TRUE, 'default' => 0, ), + 'page' => array( + 'description' => 'For this category a subscription page is available.', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), ), 'primary key' => array('tid'), ); @@ -341,6 +348,10 @@ function simplenews_schema() { return $schema; } +/****************************************************************************** + * Install / Uninstall hooks + ******************************************************************************/ + /** * Implements hook_install(). */ @@ -388,6 +399,10 @@ function simplenews_uninstall() { $config->delete(); } +/****************************************************************************** + * Update hooks + ******************************************************************************/ + /** * Convert variables to config. */ @@ -411,6 +426,25 @@ function simplenews_update_1001() { db_query("ALTER TABLE {simplenews_subscriber} MODIFY mail VARCHAR (255) NOT NULL;"); } +/** + * Add the 'page' column to the simplenews database table. + */ +function simplenews_update_1002() { + $schema = array( + 'description' => 'For this category a subscription page is available.', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ); + db_add_field('simplenews_category', 'page', $schema); + + return t('Added a subscription page option for each simplenews category.'); +} + +/****************************************************************************** + * Helper functions + ******************************************************************************/ /** * Create SimpleNews node type. diff --git a/simplenews.module b/simplenews.module index b4036aa..b7ae4c4 100644 --- a/simplenews.module +++ b/simplenews.module @@ -246,6 +246,14 @@ function simplenews_menu() { 'access arguments' => array('subscribe to newsletters'), 'file' => 'includes/simplenews.subscription.inc', ); + $items['newsletter/subscriptions/%'] = array( + 'title' => 'Your newsletter subscriptions', + 'type' => MENU_CALLBACK, + 'page callback' => 'simplenews_subscriptions_signup_page', + 'page arguments' => array(2), + 'access arguments' => array('subscribe to newsletters'), + 'file' => 'includes/simplenews.subscription.inc', + ); $items['node/%node/simplenews'] = array( 'title' => 'Newsletter', @@ -1887,6 +1895,7 @@ function simplenews_category_save($category) { 'new_account' => $category->new_account, 'opt_inout' => $category->opt_inout, 'block' => $category->block, + 'page' => $category->page, )) ->execute(); module_invoke_all('simplenews_category_update', $category); @@ -2290,7 +2299,7 @@ function simplenews_theme() { * * @see simplenews-block.tpl.php * - * @ingroup theming + * @ingroup themeable */ function template_preprocess_simplenews_block(&$variables) { $config = config('simplenews.settings'); @@ -2306,7 +2315,16 @@ function template_preprocess_simplenews_block(&$variables) { $variables['rssfeed'] = ''; // Block content variables - $variables['message'] = check_plain($config->get('simplenews_block_message_' . $tid)); + $message = check_plain($config->get('simplenews_block_message_' . $tid)); + if (isset($message) && !empty($message)) { + $variables['message'] = $message; + } + else { + $message_string = 'Subscription for the @category newsletter:'; + $substitutions = array('@category' => $category->name); + $variables['message'] = t($message_string, $substitutions); + } + if (user_access('subscribe to newsletters')) { module_load_include('inc', 'simplenews', 'simplenews.subscription'); $variables['form'] = backdrop_get_form('simplenews_block_form_' . $tid); @@ -2317,19 +2335,29 @@ function template_preprocess_simplenews_block(&$variables) { $recent = simplenews_recent_newsletters($tid, $config->get('simplenews_block_quantity_' . $tid)); $variables['issue_list'] = ''; if ($recent) { - $variables['issue_list'] = theme('item_list', array('items' => $recent, 'title' => t('Previous issues'), 'type' => 'ul')); + $variables['issue_list'] = theme('item_list', array('items' => $recent, 'title' => t('Previous issues'))); } $variables['rssfeed'] = theme('feed_icon', array('url' => 'taxonomy/term/' . $tid . '/feed', 'title' => t('@newsletter feed', array('@newsletter' => _simplenews_newsletter_name($category))))); // Block content control variables - $variables['use_form'] = $config->get('simplenews_block_interface_' . $tid); + $variables['use_form'] = TRUE; + $block_settings = $config->get('simplenews_block_interface_' . $tid); + if (isset($block_settings)) { + $variables['use_form'] = $block_settings; + } $variables['use_issue_link'] = $config->get('simplenews_block_link_' . $tid); $variables['use_issue_list'] = $config->get('simplenews_block_previous_' . $tid); $variables['use_rss'] = $config->get('simplenews_block_rss_' . $tid); // Additional variables - $variables['subscribed'] = empty($user->uid) ? FALSE : (simplenews_user_is_subscribed($user->mail, $tid) == TRUE); - $variables['user'] = !empty($user->uid); + $variables['user'] = FALSE; + $variables['subscribed'] = FALSE; + if (!empty($user->uid)) { + $variables['user'] = TRUE; + if (simplenews_user_is_subscribed($user->mail, $tid)) { + $variables['subscribed'] = TRUE; + } + } } /** @@ -2339,7 +2367,7 @@ function template_preprocess_simplenews_block(&$variables) { * * @see simplenews-multi-block.tpl.php * - * @ingroup theming + * @ingroup themeable */ function template_preprocess_simplenews_multi_block(&$variables) { // Block content variables @@ -2450,7 +2478,7 @@ function theme_simplenews_field($variables) { * * @see simplenews-newsletter-body.tpl.php * - * @ingroup theming + * @ingroup themeable */ function template_preprocess_simplenews_newsletter_body(&$variables) { // We don't want to include links and comments in the email. @@ -2477,7 +2505,7 @@ function template_preprocess_simplenews_newsletter_body(&$variables) { * * @see simplenews-newsletter-footer.tpl.php * - * @ingroup theming + * @ingroup themeable */ function template_preprocess_simplenews_newsletter_footer(&$variables) { // We don't want to include links and comments in the email.