/[drupal]/contributions/modules/subscription/subscription.module
ViewVC logotype

Diff of /contributions/modules/subscription/subscription.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.11, Mon Dec 5 13:55:44 2005 UTC revision 1.12, Tue Apr 4 17:47:22 2006 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /* $Id: subscription.module,v 1.10 2005/09/30 06:41:49 ee Exp $ */  /* $Id: subscription.module,v 1.11 2005/12/05 13:55:44 weitzman Exp $ */
3    
4  function subscription_help($section) {  function subscription_help($section) {
5    switch ($section) {    switch ($section) {
# Line 121  function subscription_admin_channels() { Line 121  function subscription_admin_channels() {
121    $avail_channels = subscription_get_available_channels();    $avail_channels = subscription_get_available_channels();
122    if (!empty($_POST)) {    if (!empty($_POST)) {
123      $edit = $_POST['edit'];      $edit = $_POST['edit'];
124      if (empty($edit['name'])) {      $cid = db_next_id("subscription_channels", "cid");
125        form_set_error("name", t("The name is empty"));      db_query("INSERT INTO subscription_channels (cid,name,id,daily) VALUES (%d,'%s','%s',%d)", $cid, $edit['name'], $edit['id'], $edit['daily']);
126      }      drupal_set_message(t("Channel created succesfully"));
     else {  
       $cid = db_next_id("subscription_channels", "cid");  
       db_query("INSERT INTO subscription_channels (cid,name,id,daily) VALUES (%d,'%s','%s',%d)", $cid, $edit['name'], $edit['id'], $edit['daily']);  
       drupal_set_message(t("Channel created succesfully"));  
     }  
127    }    }
128    $channels = subscription_getchannels();    $channels = subscription_getchannels();
129    $table = array();    $table = array();
# Line 146  function subscription_admin_channels() { Line 141  function subscription_admin_channels() {
141    foreach ($avail_channels as $channel) {    foreach ($avail_channels as $channel) {
142      $channel_select[$channel['id']] = $channel['name'];      $channel_select[$channel['id']] = $channel['name'];
143    }    }
144    $form = '';    $form['name'] = array(
145    $form .= form_textfield(t('name'), 'name', '', 30, 30);      '#type' => 'textfield',
146    $form .= form_select(t('channel'), 'id', 0, $channel_select);      '#title' => t('name'),
147    $form .= form_select(t('daily'), 'daily', 0, array(t('instant'), t('daily')));      '#default_value' => '',
148    $form .= form_submit(t("Save"), "save");      '#size' => 30,
149        '#maxlength' => 30,
150    $form = form($form);    );
151    $page .= "<h2>". t("Add channel") .'</h2><p>'. $form .'</p>';    $form['id'] = array(
152    echo theme('page', $page);      '#type' => 'select',
153        '#title' => t('channel'),
154        '#default_value' => 0,
155        '#options' => $channel_select,
156      );
157      $form['daily'] = array(
158        '#type' => 'select',
159        '#title' => t('daily'),
160        '#default_value' => 0,
161        '#options' => array(t('instant'), t('daily')),
162      );
163      $form["save"] = array(
164        '#type' => 'submit',
165        '#value' => t("Save"),
166      );
167      $page .= "<h2>". t("Add channel") .'</h2><p>'. drupal_get_form('subscription_admin_channels', $form) .'</p>';
168      return $page;
169    }
170    /**
171     * Form validation for the "Add channel" field above.
172     */
173    function subscription_admin_channels_validate($form_id, &$form) {
174      global $form_values;
175      if (!$form['name']) {
176        form_set_error('name', t("The name is empty"));
177      }
178  }  }
179  /**  /**
180   * remove a channel   * remove a channel
# Line 223  function subscription_comment($op, $comm Line 243  function subscription_comment($op, $comm
243      if ($user->subscription_auto && !subscription_is_subscribed('comment', array('nid' => $comment['nid']))) {      if ($user->subscription_auto && !subscription_is_subscribed('comment', array('nid' => $comment['nid']))) {
244          subscription_store('comment', array('nid' => $comment['nid']));          subscription_store('comment', array('nid' => $comment['nid']));
245      }      }
246      $parent_node = node_load(array('nid' => $comment['nid']));      $parent_node = node_load($comment['nid']);
247      $new_object = (array_merge($comment, array('parent_uid' => $parent_node->uid)));      $new_object = (array_merge($comment, array('parent_uid' => $parent_node->uid)));
248      $newobject = array('comment' => array($comment));      $newobject = array('comment' => array($comment));
249      subscription_trigger($newobject);      subscription_trigger($newobject);
# Line 498  function subscription_user($type, &$edit Line 518  function subscription_user($type, &$edit
518          foreach ($channels as $channel) {          foreach ($channels as $channel) {
519            $channel_select[$channel['cid']] = $channel['name'];            $channel_select[$channel['cid']] = $channel['name'];
520          }          }
521            $form['subscription'] = array(
522          $group = form_select(t('Default channel'),            '#type' => 'fieldset',
523                'subscription_channel',            '#title' => t('Subscription settings'),
524                subscription_get_default_channel(),            '#weight' => 2,
525                $channel_select,          );
526                t('Select the destination for new subscriptions.'));          $form['subscription']['subscription_channel'] = array(
527          $group .= form_checkbox(t('Automatically subscribe to those posts in which you have participated.'),            '#type' => 'select',
528                'subscription_auto',            '#title' => t('Default channel'),
529                1,            '#default_value' => subscription_get_default_channel(),
530                isset($edit->subscriptions_auto) ? $edit->subscriptions_auto : $account->subscriptions_auto);            '#options' => $channel_select,
531          }            '#description' => t('Select the destination for new subscriptions.'),
532          return array(array('title '=> t('Subscription settings'), 'data' => form_group(t('Subscription settings'), $group), 'weight' => 2));          );
533        case 'view':          $form['subscription']['subscription_auto'] = array(
534          if (user_access('manage subscriptions')  && $user->uid != $account->uid) {            '#type' => 'checkbox',
535            $links[] = l(t("Subscribe to content created by this user"), 'subscription/add/user/all/' . $account->uid);            '#title' => t('Automatically subscribe to those posts in which you have participated.'),
536            $links[] = l(t("Subscribe to comments to this user's content"), 'subscription/add/user/comment/' . $account->uid);            '#return_value' => 1,
537            return array(t('Subscriptions') => theme('item_list', $links));            '#default_value' => isset($edit->subscription_auto) ? $edit->subscription_auto : $account->subscription_auto,
538          }          );
539            return $form;
540          }
541        case 'view':
542          if (user_access('manage subscriptions')  && $user->uid != $account->uid) {
543            $links[] = l(t("Subscribe to content created by this user"), 'subscription/add/user/all/' . $account->uid);
544            $links[] = l(t("Subscribe to comments to this user's content"), 'subscription/add/user/comment/' . $account->uid);
545            return array(t('Subscriptions') => theme('item_list', $links));
546          }
547    }    }
548  }  }
549    
# Line 578  function subscription_list() { Line 606  function subscription_list() {
606    $page = "<h1>Current subscriptions</h1>";    $page = "<h1>Current subscriptions</h1>";
607    if ($roles != array()) {    if ($roles != array()) {
608      foreach ($roles as $role) {      foreach ($roles as $role) {
609        $table[] = array($role['object'], _subscription_condition_readable($role['condition']), $role['name'], l('delete', 'subscription/del/'.$role['sid']), form_checkbox('', 'merge'.$role['sid']));        $form = array( 'subscription_list_merge'.$role['sid'] => array(
610      }          '#type' => 'checkbox',
611      $form = theme("table", array(t("Object"), t("Condition"), t("Channel"), t("Function"), t("Merge")), $table);          '#title' => '',
612      $form .= form_submit(t("Merge"));        ));
613      $page .= form($form);        $table[] = array($role['object'],
614                           _subscription_condition_readable($role['condition']),
615                           $role['name'],
616                           l('delete', 'subscription/del/'.$role['sid']),
617                           drupal_get_form('subscription_list_'.$role['sid'], $form)
618                          );
619        }
620        $page .= theme("table", array(t("Object"), t("Condition"), t("Channel"), t("Function"), t("Merge")), $table);
621        $form = array( 'subscription_list_submit' => array(
622          '#type' => 'submit',
623          '#value' => t("Merge"),
624        ));
625        $page .= drupal_get_form('subscription_list_submit', $form);
626    }    }
627    else {    else {
628      $page .= t("Currently there are no subscriptions.");      $page .= t("Currently there are no subscriptions.");
# Line 594  function subscription_list() { Line 634  function subscription_list() {
634    $page .= "<h1>". t("Available special subscriptions") ."</h1>";    $page .= "<h1>". t("Available special subscriptions") ."</h1>";
635    $page .= theme('item_list', module_invoke_all('subscription', 'special'));    $page .= theme('item_list', module_invoke_all('subscription', 'special'));
636    
637    print theme("page", $page);    return $page;
638  }  }
639  /**  /**
640   *   *
# Line 615  function _subscription_condition_readabl Line 655  function _subscription_condition_readabl
655   * Settings menu to the administration section   * Settings menu to the administration section
656   */   */
657  function subscription_settings() {  function subscription_settings() {
658    $output = form_select(t('Default mode for non-digest events'),    $form['subscription_instant_mode'] = array(
659      'subscription_instant_mode',      '#type' => 'select',
660      variable_get('subscription_instant_mode', 0),      '#title' => t('Default mode for non-digest events'),
661      array('0' => 'instant (small sites)', '1' => 'cronned (big sites)'),      '#default_value' => variable_get('subscription_instant_mode', 0),
662      t('When to notify on new content: immediately after content is created (suggested for small sites), or after next cron run (suggested for big sites) '));      '#options' => array('0' => 'instant (small sites)', '1' => 'cronned (big sites)'),
663    return $output;      '#description' => t('When to notify on new content: immediately after content is created (suggested for small sites), or after next cron run (suggested for big sites) '),
664      );
665      return $form;
666  }  }
667  /* DEFAULT CHANNELS */  /* DEFAULT CHANNELS */
668  function subscription_simpleformatter($object, $type) {  function subscription_simpleformatter($object, $type) {

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.2