array( 'name' => t('Newsletter issue'), 'module' => 'simplenews', 'description' => t('Create a newsletter issue to be sent to subscribed e-mail addresses.'), ), ); } /** * Implementation of hook_perm(). */ function simplenews_perm() { return array('view links in block', 'create newsletter', 'edit own newsletter', 'edit any newsletter', 'administer newsletters', 'send newsletter', 'subscribe to newsletters'); } /** * Implementation of hook_init(). */ function simplenews_init() { // only bother when we are not serving a cached page. check for which function that only exists afterwards if (function_exists('drupal_set_content')) { if (module_exists('views')) { include(drupal_get_path('module', 'simplenews') .'/simplenews_views.inc'); } } } /** * Implementation of hook_access(). */ function simplenews_access($op, $node) { global $user; if ($op == 'create') { if (user_access('create newsletter') || user_access('administer newsletters')) { return TRUE; } } if ($op == 'update' || $op == 'delete') { if (user_access('administer newsletters')) { return TRUE; } elseif (user_access('edit any newsletter')) { return TRUE; } elseif (user_access('edit own newsletter') && $user->uid == $node->uid) { return TRUE; } } } /** * Implementation of hook_menu(). */ function simplenews_menu($may_cache) { $items = array(); $administer = user_access('administer newsletters'); if ($may_cache) { $items[] = array('path' => 'node/add/simplenews', 'title' => t('Newsletter issue'), 'access' => user_access('create newsletter'), ); $items[] = array( 'path' => 'admin/content/newsletters', 'title' => t('Newsletters'), 'type' => MENU_NORMAL_ITEM, 'description' => t('Manage newsletters, subscriptions, and configuration options.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_admin_news'), 'access' => $administer, ); $items[] = array('path' => 'admin/content/newsletters/sent', 'title' => t('Sent issues'), 'access' => $administer, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_admin_news'), ); $items[] = array('path' => 'admin/content/newsletters/notsent', 'title' => t('Drafts'), 'access' => $administer, 'type' => MENU_LOCAL_TASK, 'weight' => -9, 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_admin_news', 'notsent'), ); $items[] = array('path' => 'admin/content/newsletters/types', 'title' => t('Newsletters'), 'access' => $administer, 'type' => MENU_LOCAL_TASK, 'weight' => -8, 'callback' => 'simplenews_types_overview', ); $items[] = array('path' => 'admin/content/newsletters/types/edit', 'title' => t('Newsletters'), 'access' => $administer, 'type' => MENU_CALLBACK, 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_admin_types_form'), ); $items[] = array('path' => 'admin/content/newsletters/types/delete', 'title' => t('Newsletters'), 'access' => $administer, 'type' => MENU_CALLBACK, 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_admin_types_delete'), ); $items[] = array('path' => 'admin/content/newsletters/types/list', 'title' => t('List newsletters'), 'access' => $administer, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array('path' => 'admin/content/newsletters/types/add', 'title' => t('Add newsletter'), 'access' => $administer, 'type' => MENU_LOCAL_TASK, 'weight' => -9, 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_admin_types_form'), ); $items[] = array( 'path' => 'admin/content/newsletters/subscriptions/delete', 'title' => t('Delete'), 'type' => MENU_CALLBACK, 'callback' => 'drupal_get_form', 'callback arguments' => 'simplenews_subscription_multiple_delete_confirm', 'access' => $administer, ); $items[] = array('path' => 'admin/content/newsletters/users', 'title' => t('Subscriptions'), 'access' => $administer, 'type' => MENU_LOCAL_TASK, 'weight' => -7, 'callback' => 'simplenews_subscription_admin', ); $items[] = array('path' => 'admin/content/newsletters/users/edit', 'title' => t('Subscriptions'), 'access' => $administer, 'type' => MENU_CALLBACK, 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_admin_users_form'), ); $items[] = array('path' => 'admin/content/newsletters/users/delete', 'title' => t('Subscriptions'), 'access' => $administer, 'type' => MENU_CALLBACK, 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_admin_users_delete'), ); $items[] = array('path' => 'admin/content/newsletters/users/list', 'title' => t('List subscriptions'), 'access' => $administer, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array('path' => 'admin/content/newsletters/users/import', 'title' => t('Import subscriptions'), 'access' => $administer, 'type' => MENU_LOCAL_TASK, 'weight' => -9, 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_subscription_list_add'), ); $items[] = array('path' => 'admin/content/newsletters/users/export', 'title' => t('Export subscriptions'), 'access' => $administer, 'type' => MENU_LOCAL_TASK, 'weight' => -8, 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_subscription_list_export'), ); $items[] = array('path' => 'admin/content/newsletters/settings', 'title' => t('Settings'), 'access' => $administer, 'type' => MENU_LOCAL_TASK, 'weight' => -6, 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_admin_settings'), ); $items[] = array('path' => 'admin/content/newsletters/settings/general', 'title' => t('General'), 'access' => $administer, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array('path' => 'newsletter/confirm', 'title' => t('Confirm newsletter subscriptions'), 'access' => user_access('subscribe to newsletters'), 'callback' => 'simplenews_confirm_subscription', 'type' => MENU_CALLBACK, ); $items[] = array('path' => 'newsletter/subscriptions', 'title' => t('Manage newsletter subscriptions'), 'access' => user_access('subscribe to newsletters'), 'callback' => 'drupal_get_form', 'callback arguments' => array('simplenews_subscription_manager_form'), 'type' => MENU_CALLBACK, ); } else { drupal_add_css(drupal_get_path('module', 'simplenews') .'/simplenews.css', 'module', 'all', TRUE); if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'newsletters' && arg(3) == 'settings') { $tree = taxonomy_get_tree(variable_get('simplenews_vid', '')); if ($tree) { $weight = -9; foreach ($tree as $newsletter) { $items[] = array('path' => 'admin/content/newsletters/settings/'. $newsletter->tid, 'title' => $newsletter->name, 'access' => $administer, 'type' => MENU_LOCAL_TASK, 'weight' => $weight++, ); } } } } return $items; } /** * Implementation of hook_form(). */ function simplenews_form(&$node) { $type = node_get_types('type', $node); global $user; if ($type->has_title) { $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#default_value' => $node->title, '#size' => 60, '#maxlength' => 128, '#required' => TRUE, ); } if ($type->has_body) { $form['body_filter']['body'] = array( '#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#rows' => 20, '#required' => ($type->min_word_count > 0), '#description' => t('This will be the body of your newsletter. Available variables are:') .' %site '. t('(the name of your website),') .' %uri '. t('(a link to your homepage),') .' %uri_brief '. t('(homepage link without the http://),') .' %mymail '. t('(your e-mail address),') .' %date '. t('(today\'s date),') .' %login_uri '. t('(link to login page).'), ); $form['body_filter']['format'] = filter_form($node->format); } if (!$sel1 = $node->s_format) { $sel1 = variable_get('simplenews_format', 'plain'); } if (!$sel2 = $node->priority) { $sel2 = variable_get('simplenews_priority', 0); } if (!$sel3 = $node->receipt) { $sel3 = variable_get('simplenews_receipt', 0); } $form['sending_options'] = array( '#type' => 'fieldset', '#title' => t('Newsletter sending options'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['sending_options']['s_format'] = array( '#type' => 'select', '#title' => t('Format'), '#default_value' => $sel1, '#options' => _simplenews_format_options(), ); $form['sending_options']['priority'] = array('#type' => 'select', '#title' => t('Priority'), '#default_value' => $sel2, '#options' => array(0 => t('none'), 1 => t('highest'), 2 => t('high'), 3 => t('normal'), 4 => t('low'), 5 => t('lowest')), ); $form['sending_options']['receipt'] = array('#type' => 'checkbox', '#title' => t('Request receipt'), '#return_value' => 1, '#default_value' => $sel3, ); if ($node->s_status == 0) { if (user_access('send newsletter')) { $options[0] = t("Don't send now"); $options[2] = t('Send one test newsletter to the test address'); $options[1] = t('Send newsletter'); $form['sending_options']['send'] = array( '#type' => 'radios', '#title' => t('Sending'), '#default_value' => $node->send ? $node->send : variable_get('simplenews_send', 0), '#options' => $options, ); } else { $options[0] = t("Don't send now"); $options[2] = t('Send one test newsletter to the test address'); $form['sending_options']['send'] = array('#type' => 'radios', '#title' => t('Sending'), '#default_value' => $node->send ? $node->send : 0, '#options' => $options, '#description' => t('You have no privileges to send this newsletter'), ); } if (variable_get('simplenews_test_address_override', 0)) { $form['sending_options']['test_address'] = array('#type' => 'textfield', '#title' => t('Test e-mail addresses'), '#default_value' => $node->test_address ? $node->test_address : variable_get('simplenews_test_address', ''), '#size' => 60, '#maxlength' => 128, '#description' => t('Supply a comma-separated list of e-mail addresses to be used as test addresses.'), ); } } else { $atts = array('disabled' => 'disabled'); $form['sending_options']['none'] = array('#type' => 'checkbox', '#title' => t('This newsletter has been sent'), '#return_value' => 0, '#attributes' => array('checked' => 'checked', 'disabled' => 'disabled'), ); } $form['s_status'] = array('#type' => 'hidden', '#value' => $node->s_status ? $node->s_status : 0); return $form; } /** * Implementation of hook_validate(). */ function simplenews_validate($node) { global $valid_mails; if ($node->send == 1) { if (!isset($node->taxonomy)) { $names = node_get_types('names', $node); form_set_error('', t('You should select content type %content_type in !newsletter_vocabulary before you can send this newsletter.', array('%content_type' => $names[$node->type], '!newsletter_vocabulary' => l(t('Newsletter vocabulary'), 'admin/content/taxonomy/edit/vocabulary/'. variable_get('simplenews_vid', ''))))); } elseif (!simplenews_validate_taxonomy($node->taxonomy)) { form_set_error('taxonomy', t('You should select a newsletter before you can send this newsletter.')); } } elseif ($node->send == 2) { if (variable_get('simplenews_test_address_override', 0)) { $mails = explode(',', $node->test_address); } else { $mails = explode(',', variable_get('simplenews_test_address', '')); } foreach ($mails as $mail) { $mail = trim($mail); if ($mail == '') { form_set_error('', t('Cannot send test newsletter: no valid test e-mail address specified.')); } elseif (!valid_email_address($mail)) { form_set_error('', t('Cannot send test newsletter to %mail: e-mail address invalid.', array('%mail' => $mail))); } else { $valid_mails[] = $mail; } } } } /** * Implementation of hook_submit(). */ function simplenews_submit(&$node) { global $valid_mails; if ($node->send == 2 && $valid_mails) { $node->test_address = $valid_mails; } } function simplenews_validate_taxonomy($taxonomy) { $vid = variable_get('simplenews_vid', ''); $result = db_query('SELECT tid FROM {term_data} WHERE vid = %d', $vid); while ($tid = db_fetch_object($result)) { $tids[] = $tid->tid; } if (isset($tids) && !empty($taxonomy)) { $taxes = array(); foreach ($taxonomy as $tax) { $taxes[] = $tax; } $selected_terms = array_intersect($tids, $taxes); return empty($selected_terms) ? FALSE : $selected_terms; } return FALSE; } /** * Implementation of hook_cron(). */ function simplenews_cron() { _simplenews_send(FALSE); } /** * Implementation of hook_insert(). * Saves extra node content to module database table. */ function simplenews_insert($node) { $term = simplenews_validate_taxonomy($node->taxonomy); $tid = is_array($term) ? array_values($term) : FALSE; $node->simplenews_tid = $tid ? $tid[0] : 0; //tid is also saved in this table since it is needed by _simplenews_send(), and the term_node table is //only updated after the execution of simplenews_insert(). It cannot be passed by a variable //since simplenews_cron() also calls _simplenews_send(). $s_status = ($node->send == 1 && user_access('send newsletter')) ? 1 : 0; db_query("INSERT INTO {simplenews_newsletters} (nid, vid, tid, s_status, s_format, priority, receipt) VALUES (%d, %d, %d, %d, '%s', %d, %d)", $node->nid, $node->vid, $node->simplenews_tid, $s_status, $node->s_format, $node->priority, $node->receipt); } /** * Implementation of hook_update(). */ function simplenews_update($node) { $term = simplenews_validate_taxonomy($node->taxonomy); $tid = is_array($term) ? array_values($term) : FALSE; $node->simplenews_tid = $tid ? $tid[0] : 0; if ($node->send == 1 && user_access('send newsletter')) { db_query("UPDATE {simplenews_newsletters} SET vid = %d, tid = %d, s_status = %d, s_format = '%s', priority = %d, receipt = %d WHERE nid = %d", $node->vid, $node->simplenews_tid, 1, $node->s_format, $node->priority, $node->receipt, $node->nid); } else { db_query("UPDATE {simplenews_newsletters} SET tid = %d, s_format = '%s', priority = %d, receipt = %d WHERE nid = %d", $node->simplenews_tid, $node->s_format, $node->priority, $node->receipt, $node->nid); } } /** * Implementation of hook_nodeapi(). */ function simplenews_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { if ($node->type == 'simplenews' && ($op == 'update' || $op == 'insert')) { if ($node->send == 1) { _simplenews_send(TRUE); drupal_set_message(t('Newsletter %newsletter is being sent', array('%newsletter' => $node->title))); } elseif ($node->send == 2) { simplenews_send_test($node); } } } /** * Implementation of hook_delete(). */ function simplenews_delete($node) { $result = db_query('DELETE FROM {simplenews_newsletters} WHERE nid = %d', $node->nid); if ($result) { drupal_set_message(t('Newsletter %title was successfully deleted.', array('%title' => $node->title))); } } /** * Implementation of hook_load(). */ function simplenews_load($node) { $newsletter = db_fetch_object(db_query('SELECT * FROM {simplenews_newsletters} WHERE nid = %d', $node->nid)); // Newsletter vid is stored in simplenews->vid. // This will prevent overwrite of node->vid. // A better solution would be a node->simplenews with all newsletter data. $newsletter->simplenews_vid = $newsletter->vid; unset($newsletter->vid); return $newsletter; } /** * Implementation of hook_taxonomy(). * * Deletes subscriptions to term when term is deleted, and cleans the blocks * table. */ function simplenews_taxonomy($op, $type, $array = NULL) { if ($type == 'term' && $op == 'delete' && $array['vid'] == variable_get('simplenews_vid', '')) { db_query('DELETE FROM {simplenews_snid_tid} WHERE tid = %d', $array['tid']); db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'simplenews', 'newsletter-'. $array['tid']); drupal_set_message(t('Deleted all subscriptions to newsletter %newsletter.', array('%newsletter' => $array['name']))); } elseif ($op == 'delete' && $type == 'vocabulary' && $array['vid'] == variable_get('simplenews_vid', '')) { variable_del('simplenews_vid'); } } /** * Implementation of hook_view(). */ function simplenews_view(&$node, $teaser = FALSE) { $node = simplenews_replace_vars($node, TRUE); $node = node_prepare($node, $teaser); return $node; } /** * Implementation of hook_form_alter(). */ function simplenews_form_alter($form_id, &$form) { $vid = variable_get('simplenews_vid', ''); // Newsletter vocabulary form if ($form_id == 'taxonomy_form_vocabulary' && isset($form['vid']) && $form['vid']['#value'] == $vid) { // Hide critical options from forum vocabulary. $form['help_forum_vocab'] = array( '#value' => t('This is the designated simplenews vocabulary. This vocabulary can not be deleted.'), '#weight' => -1, ); $form['nodes']['#required'] = TRUE; $form['nodes']['#description'] = t('Select content type(s) to be used as newsletter'); $form['multiple'] = array('#type' => 'value', '#value' => FALSE); // Prevent the vocabulary gets deleted unset($form['delete']); } } /** * Implementation of hook_user(). * * Checks whether an email address is subscribed to the newsletter when a new * user signs up. If so, changes uid from 0 to the new uid in * simplenews_subscriptions so that the user's subscription status is known when * he logs in. */ function simplenews_user($op, &$edit, &$account, $category = NULL) { switch ($op) { case 'insert': if ($edit['mail']) { $query = "SELECT snid FROM {simplenews_subscriptions} WHERE mail = '%s'"; if ($result = db_fetch_object(db_query($query, $edit['mail']))) { db_query("UPDATE {simplenews_subscriptions} SET uid = %d WHERE snid = %d", $edit['uid'], $result->snid); } } break; case 'update': if ($category == 'account' && $edit['mail']) { $query = "SELECT snid FROM {simplenews_subscriptions} WHERE uid = %d"; if ($result = db_fetch_object(db_query($query, $account->uid))) { db_query("DELETE FROM {simplenews_subscriptions} WHERE mail = '%s' AND uid = %d", $edit['mail'], 0); db_query("UPDATE {simplenews_subscriptions} SET mail = '%s' WHERE snid = %d", $edit['mail'], $result->snid); } else { $query = "SELECT snid FROM {simplenews_subscriptions} WHERE mail = '%s'"; if ($result = db_fetch_object(db_query($query, $edit['mail']))) { db_query("UPDATE {simplenews_subscriptions} SET uid = %d WHERE snid = %d", $account->uid, $result->snid); } } } // Activate/deactivate subscription when account is blocked/unblocked if ($category == 'account' && isset($edit['status'])) { if (variable_get('simplenews_sync_account', FALSE)) { db_query("UPDATE {simplenews_subscriptions} SET a_status = %d WHERE uid = %d", $edit['status'], $account->uid); } } if ($category == 'newsletter' && user_access('subscribe to newsletters')) { foreach ($edit['newsletters'] as $tid => $checked) { if ($checked) { simplenews_subscribe_user($account->mail, $tid, FALSE); } else { simplenews_unsubscribe_user($account->mail, $tid, FALSE); } } } break; case 'delete': if (variable_get('simplenews_sync_account', FALSE)) { // Delete subscription and all newsletter subscriptions. // We get the snid straight from the database because user_load() // can not be used in this stage. $snid = db_result(db_query("SELECT s.snid FROM {simplenews_subscriptions} s WHERE s.uid = %d", $account->uid)); db_query('DELETE FROM {simplenews_snid_tid} WHERE snid = %d', $snid); db_query('DELETE FROM {simplenews_subscriptions} WHERE snid = %d', $snid); } else { // Only remove uid from subscription data when account is removed db_query("UPDATE {simplenews_subscriptions} SET uid = 0 WHERE uid = %d", $account->uid); } break; case 'form': if ($category == 'newsletter' && user_access('subscribe to newsletters')) { $subscription = simplenews_get_user_subscription($account->mail); $form = _simplenews_subscription_manager_form($subscription); $form['subscriptions']['#title'] = t('Current newsletter subscriptions'); unset($form['update'], $form['subscriptions']['mail']); return $form; } break; case 'categories': if (user_access('subscribe to newsletters')) { $output[] = array('name' => 'newsletter', 'title' => t('My newsletters'), 'weight' => 10); } return $output; case 'view': global $user; if ($user->uid == $account->uid || user_access('administer users')) { $items = array(); $tree = taxonomy_get_tree(variable_get('simplenews_vid', '')); foreach ($tree as $newsletter) { if (db_num_rows(db_query('SELECT s.uid FROM {simplenews_subscriptions} s INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid WHERE s.uid = %d AND t.tid = %d', $account->uid, $newsletter->tid))) { $subscriptions[] = l($newsletter->name, 'taxonomy/term/'. $newsletter->tid); } } if ($subscriptions) { $subscriptions = implode(', ', $subscriptions); } else { $subscriptions = t('Currently no subscriptions'); } // When a user has no permission to subscribe and is not subscribed // we do not display the 'no subscriptions' message. if (user_access('subscribe to newsletters') || $subscriptions != t('Currently no subscriptions')) { $items[] = array('class' => 'item', 'title' => t('Current subscriptions'), 'value' => $subscriptions, ); } if (user_access('subscribe to newsletters')) { $items[] = array('class' => 'item', 'title' => t('Manage subscriptions'), 'value' => l(t('My newsletters'), 'user/'. $account->uid .'/edit/newsletter'), ); } return array(t('Newsletters') => $items); } break; } } /** * Implementation of hook_block(). */ function simplenews_block($op = 'list', $delta = 0, $edit = array()) { list($type, $tid) = explode('-', $delta); switch ($op) { case 'list': $blocks = array(); foreach (taxonomy_get_tree(variable_get('simplenews_vid', '')) as $newsletter) { $blocks['newsletter-'. $newsletter->tid] = array('info' => t('Newsletter: @title', array('@title' => $newsletter->name))); } return $blocks; case 'configure': $form['simplenews_block_'. $delta]['simplenews_block_m_status_'. $tid] = array('#type' => 'checkbox', '#title' => t('Display block message'), '#return_value' => 1, '#default_value' => variable_get('simplenews_block_m_status_'. $tid, 1), ); $form['simplenews_block_'. $delta]['simplenews_block_m_'. $tid] = array('#type' => 'textfield', '#title' => t('Block message'), '#size' => 60, '#maxlength' => 128, '#default_value' => variable_get('simplenews_block_m_'. $tid, t('Stay informed on our latest news!')), ); $form['simplenews_block_'. $delta]['simplenews_block_f_'. $tid] = array('#type' => 'checkbox', '#title' => t('Display subscription form'), '#return_value' => 1, '#description' => t('If selected a subscription form is displayed, if not selected a link to the subscription page is displayed.'), '#default_value' => variable_get('simplenews_block_f_'. $tid, 1), ); $form['simplenews_block_'. $delta]['simplenews_block_l_'. $tid] = array('#type' => 'checkbox', '#title' => t('Display link to previous issues'), '#return_value' => 1, '#default_value' => variable_get('simplenews_block_l_'. $tid, 1), '#description' => t('Links (to previous issues, previous issues and RSS-feed) are only displayed to users who have "view links in block" privileges.'), ); $form['simplenews_block_'. $delta]['simplenews_block_i_status_'. $tid] = array('#type' => 'checkbox', '#title' => t('Display previous issues'), '#return_value' => 1, '#default_value' => variable_get('simplenews_block_i_status_'. $tid, 0), ); $form['simplenews_block_'. $delta]['simplenews_block_i_'. $tid] = array('#type' => 'select', '#title' => t('Number of issues to display'), '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), '#default_value' => variable_get('simplenews_block_i_'. $tid, 5), ); $form['simplenews_block_'. $delta]['simplenews_block_r_'. $tid] = array('#type' => 'checkbox', '#title' => t('Display RSS-feed icon'), '#return_value' => 1, '#default_value' => variable_get('simplenews_block_r_'. $tid, 1), ); return $form; case 'save': variable_set('simplenews_block_m_status_'. $tid, $edit['simplenews_block_m_status_'. $tid]); variable_set('simplenews_block_m_'. $tid, $edit['simplenews_block_m_'. $tid]); variable_set('simplenews_block_f_'. $tid, $edit['simplenews_block_f_'. $tid]); variable_set('simplenews_block_l_'. $tid, $edit['simplenews_block_l_'. $tid]); variable_set('simplenews_block_i_status_'. $tid, $edit['simplenews_block_i_status_'. $tid]); variable_set('simplenews_block_i_'. $tid, $edit['simplenews_block_i_'. $tid]); variable_set('simplenews_block_r_'. $tid, $edit['simplenews_block_r_'. $tid]); break; case 'view': if ($type == 'newsletter') { if ($newsletter = taxonomy_get_term($tid)) { $block['subject'] = check_plain($newsletter->name); $block['content'] = theme('simplenews_block', _simplenews_block($newsletter->tid)); } } return $block; } } /** * Helper function: generate block content before theming * Collects data and applies access restriction */ function _simplenews_block($tid) { global $user; $block = array(); $recent = simplenews_recent_newsletters($tid, variable_get('simplenews_block_i_'. $tid, 5)); $block['subscribed'] = (simplenews_user_is_subscribed($user->mail, $tid) == TRUE); $block['user'] = !empty($user->uid); $block['tid'] = $tid; $block['message'] = check_plain(variable_get('simplenews_block_m_'. $tid, t('Stay informed on our latest news!'))); if (user_access('subscribe to newsletters')) { $block['form'] = drupal_get_form('simplenews_block_form_'. $tid); $block['subscription-link'] = l(t('Manage my subscriptions'), 'newsletter/subscriptions'); } if (user_access('view links in block') || user_access('administer newsletters')) { $block['newsletter-link'] = l(t('Previous issues'), 'taxonomy/term/'. $tid); $block['itemlist'] = theme('item_list', $recent, t('Previous issues'), 'ul'); $block['rssfeed'] = theme('feed_icon', url('taxonomy/term/'. $tid .'/0/feed')); } return $block; } /** * Simplenews themed block * Access restrictions have been applied. * $block contains all available data. See: _simplenews_block() */ function theme_simplenews_block($block) { $output = ''; if (variable_get('simplenews_block_m_status_'. $block['tid'], 1) && isset($block['message'])) { $output .= "
". $block['message'] ."
\n"; } if (variable_get('simplenews_block_f_'. $block['tid'], 1)) { $output .= $block['form']; } elseif (isset($block['subscription-link'])) { $output .= "". $block['subscription-link'] ."
\n"; } if (variable_get('simplenews_block_l_'. $block['tid'], 1) && isset($block['newsletter-link'])) { $output .= '