Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions includes/simplenews.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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 <code>newsletter/subscriptions/[tid]</code>'),
);

$form['email'] = array(
'#type' => 'fieldset',
'#title' => t('Email settings'),
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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'];
Expand All @@ -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()?
Expand Down
17 changes: 17 additions & 0 deletions includes/simplenews.subscription.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
34 changes: 34 additions & 0 deletions simplenews.install
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
Expand Down Expand Up @@ -341,6 +348,10 @@ function simplenews_schema() {
return $schema;
}

/******************************************************************************
* Install / Uninstall hooks
******************************************************************************/

/**
* Implements hook_install().
*/
Expand Down Expand Up @@ -388,6 +399,10 @@ function simplenews_uninstall() {
$config->delete();
}

/******************************************************************************
* Update hooks
******************************************************************************/

/**
* Convert variables to config.
*/
Expand All @@ -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.
Expand Down
46 changes: 37 additions & 9 deletions simplenews.module
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -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;
}
}
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down