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

Diff of /contributions/modules/subscriptions_og/subscriptions_og.module

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

revision 1.1.2.52, Tue Apr 29 22:02:01 2008 UTC revision 1.1.2.53, Wed Jun 25 21:37:42 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: subscriptions_og.module,v 1.1.2.51 2008/04/14 16:35:30 develCuy Exp $  // $Id: subscriptions_og.module,v 1.1.2.52 2008/04/29 22:02:01 develCuy Exp $
3    
4  /**  /**
5   * @file   * @file
6   * Subscriptions to Organic Groups.   * Subscriptions to Organic Groups.
7   *   *
8   * Subscriptions_og extends the subscription module to allow users to subscribe   * Subscriptions_og extends the Subscription module to allow users to subscribe
9   * by group. This is very similar to what the subscribe_taxonomy module does   * to groups. This is very similar to what the subscribe_taxonomy module does for
10   * for taxonomy terms. If a user subscribes to a group he will receive   * taxonomy terms. If a user subscribes to a group he will receive  notifications
11   * notifications each time a node is published to that group. The user can also   * each time a node is published to that group. The user can also select to
12   * select to receive notifications when such a node is updated or commented.   * receive notifications when such node is updated or commented.
13   */   */
14    
15  include_once drupal_get_path('module', 'subscriptions_og') .'/subscriptions_og_views.inc';  /**
16     * Implementation of hook_init().
17     */
18    function subscriptions_og_init() {
19      // Retrieve module base path
20      global $_subscriptions_og_path;
21      $_subscriptions_og_path = drupal_get_path('module', 'subscriptions_og') . '/';
22    
23      // Retrieve group content types
24      global $_subscriptions_og_group_types;
25      $_subscriptions_og_group_types =
26        function_exists('og_get_types') ?
27          og_get_types('group') :
28          variable_get('og_node_types', array('og'))
29      ;
30    
31      // Determine to use og our built-in node groups distinguish
32      global $_subscriptions_og_node_groups_distinguish;
33      $_subscriptions_og_node_groups_distinguish =
34        function_exists('og_node_groups_distinguish') ?
35          'og_node_groups_distinguish' :
36          'subscriptions_og_node_groups_distinguish'
37      ;
38    
39      // Load views integration functions
40      include_once $_subscriptions_og_path .'subscriptions_og_views.inc';
41    }
42    
43  /**  /**
44   * Implementation of hook_menu().   * Implementation of hook_menu().
# Line 28  function subscriptions_og_menu($may_cach Line 54  function subscriptions_og_menu($may_cach
54    if (!$may_cache && arg(0) == 'og' && arg(1) == 'users' && is_numeric($group_nid)) {    if (!$may_cache && arg(0) == 'og' && arg(1) == 'users' && is_numeric($group_nid)) {
55      if ($node = node_load($group_nid)) {      if ($node = node_load($group_nid)) {
56        $items[] = array(        $items[] = array(
57          'path' => "og/users/". $group_nid ."/subscriptions",          'path' => 'og/users/'. $group_nid .'/subscriptions',
58          'type' => MENU_LOCAL_TASK,          'type' => MENU_LOCAL_TASK,
59          'title' => t('Subscriptions'),          'title' => t('Subscriptions'),
60          'callback' => 'og_menu_check',          'callback' => 'og_menu_check',
# Line 41  function subscriptions_og_menu($may_cach Line 67  function subscriptions_og_menu($may_cach
67          'access' => og_is_node_admin($node),          'access' => og_is_node_admin($node),
68        );        );
69        $items[] = array(        $items[] = array(
70          'path' => "og/users/". $group_nid ."/subscriptions/members",          'path' => 'og/users/'. $group_nid .'/subscriptions/members',
71          'type' => MENU_DEFAULT_LOCAL_TASK,          'type' => MENU_DEFAULT_LOCAL_TASK,
72          'title' => t('Members'),          'title' => t('Members'),
73        );        );
74        $items[] = array(        $items[] = array(
75          'path' => "og/users/". $group_nid ."/subscriptions/nonmembers",          'path' => 'og/users/'. $group_nid .'/subscriptions/nonmembers',
76          'type' => MENU_LOCAL_TASK,          'type' => MENU_LOCAL_TASK,
77          'title' => t('Non-members'),          'title' => t('Non-members'),
78          'callback' => 'og_menu_check',          'callback' => 'og_menu_check',
# Line 101  function subscriptions_og_group_subscrip Line 127  function subscriptions_og_group_subscrip
127        $query = og_list_users_sql(0, 0, 'ou.is_admin DESC, ou.is_active ASC, u.name ASC');        $query = og_list_users_sql(0, 0, 'ou.is_admin DESC, ou.is_active ASC, u.name ASC');
128        break;        break;
129      case 'nonmembers':      case 'nonmembers':
130        $query = "        $query = '
131  SELECT  SELECT
132    u.uid    u.uid
133  FROM  FROM
# Line 109  FROM Line 135  FROM
135    {users} u ON    {users} u ON
136      s.recipient_uid = u.uid      s.recipient_uid = u.uid
137  WHERE  WHERE
138    s.field = 'group_nid' AND    s.field = "group_nid" AND
139    s.value = %d AND    s.value = %d AND
140    u.status > 0 AND    u.status > 0 AND
141    u.uid NOT IN(SELECT uid FROM {og_uid} WHERE nid = %d)    u.uid NOT IN(SELECT uid FROM {og_uid} WHERE nid = %d)
142  ORDER BY  ORDER BY
143    u.name ASC    u.name ASC
144        ";        ';
145        break;        break;
146    }    }
147    $rs = pager_query($query, 50, 0, NULL, $group->nid, $group->nid);    $rs = pager_query($query, 50, 0, NULL, $group->nid, $group->nid);
# Line 306  function subscriptions_og_subscriptions( Line 332  function subscriptions_og_subscriptions(
332   * @see subscritions_ui_node_form()   * @see subscritions_ui_node_form()
333   */   */
334  function _subscriptions_og_node_options($account, $node) {  function _subscriptions_og_node_options($account, $node) {
335      global $_subscriptions_og_node_groups_distinguish;
336    
337    $options = array();    $options = array();
338    $omits   = variable_get('subscriptions_omitted_og', array());    $omits   = variable_get('subscriptions_omitted_og', array());
# Line 313  function _subscriptions_og_node_options( Line 340  function _subscriptions_og_node_options(
340    if (!og_is_group_type($node->type)) { // not a groups node    if (!og_is_group_type($node->type)) { // not a groups node
341    
342      // Retrieve accessible nodes - Prevents showing Private groups      // Retrieve accessible nodes - Prevents showing Private groups
343      $node_groups = subscriptions_og_node_groups_distinguish($node->og_groups_both, TRUE);      $node_groups =
344          $_subscriptions_og_node_groups_distinguish($node->og_groups_both, FALSE);
345      $node_groups = $node_groups['accessible'];      $node_groups = $node_groups['accessible'];
346    
347      if (count($node_groups)) {      if (count($node_groups)) {
348        // Fetch group nodes        // Fetch group nodes
349        $query = "        $query = '
350    SELECT    SELECT
351      nid, type      nid, type
352    FROM    FROM
353      {node} n      {node} n
354    WHERE    WHERE
355      nid IN(". str_repeat("%d,", count($node_groups)-1) ."%d)      nid IN('. str_repeat('%d,', count($node_groups)-1) .'%d)
356        ";        ';
357        $rs = call_user_func_array('db_query', array_merge(array($query), array_keys($node_groups)));        $rs = call_user_func_array(
358            'db_query', array_merge(array($query), array_keys($node_groups))
359          );
360        $groups_types = array();        $groups_types = array();
361        while ($group = db_fetch_object($rs)) {        while ($group = db_fetch_object($rs)) {
362          $groups_types[$group->nid] = $group->type;          $groups_types[$group->nid] = $group->type;
# Line 360  function _subscriptions_og_node_options( Line 390  function _subscriptions_og_node_options(
390        );        );
391      }      }
392    }    }
393    
394    $options['group_nid']['weight'] = -3;    $options['group_nid']['weight'] = -3;
395    
396    return $options;    return $options;
397  }  }
398    
# Line 391  function _subscriptions_og_types() { Line 423  function _subscriptions_og_types() {
423  function _subscriptions_og_unset_array_items($array, $pattern) {  function _subscriptions_og_unset_array_items($array, $pattern) {
424    foreach ($pattern as $key => $value) {    foreach ($pattern as $key => $value) {
425      if (is_array($value))      if (is_array($value))
426        $array[$key] = _subscriptions_og_unset_array_items($array[$key], $pattern[$key]);        $array[$key] =
427            _subscriptions_og_unset_array_items($array[$key], $pattern[$key]);
428      else {      else {
429        unset($array[$pattern[$key]]);        unset($array[$pattern[$key]]);
430      }      }
# Line 411  function subscriptions_og_group_confirm_ Line 444  function subscriptions_og_group_confirm_
444    // Optionally, $_subscriptions_og_history_values stores values of    // Optionally, $_subscriptions_og_history_values stores values of
445    // $_subscriptions_og_history    // $_subscriptions_og_history
446    global $_subscriptions_og_history_values;    global $_subscriptions_og_history_values;
447    $_subscriptions_og_history[] = 'subscriptions_og_group_confirm_subscribe_submit';    $_subscriptions_og_history[] =
448        'subscriptions_og_group_confirm_subscribe_submit';
449    $_subscriptions_og_history_values['subscriptions_og_group_confirm_subscribe_submit'] =    $_subscriptions_og_history_values['subscriptions_og_group_confirm_subscribe_submit'] =
450      $form_values;      $form_values;
451  }  }
# Line 468  function subscriptions_og_attach_subscri Line 502  function subscriptions_og_attach_subscri
502    $form['subscription']['#parameters'][1] =& $node;    $form['subscription']['#parameters'][1] =& $node;
503    
504    // Apply corresponding changes for subscriptions controls    // Apply corresponding changes for subscriptions controls
505    subscriptions_og_form_alter('subscriptions_ui_node_form', $form['subscription']);    subscriptions_og_form_alter(
506        'subscriptions_ui_node_form', $form['subscription']
507      );
508    
509    // Remove not corresponding options    // Remove not corresponding options
510    foreach ($form['subscription']['params']['#value'] as $key => $type) {    foreach ($form['subscription']['params']['#value'] as $key => $type) {
# Line 502  function subscriptions_og_attach_subscri Line 538  function subscriptions_og_attach_subscri
538  function subscriptions_og_form_alter($form_id, &$form) {  function subscriptions_og_form_alter($form_id, &$form) {
539    global $user;    global $user;
540    global $_subscriptions_og_history;    global $_subscriptions_og_history;
541      global $_subscriptions_og_group_types;
542    
543    // Replace "Email notification" section with the same "Subscribe" fieldset    // Replace "Email notification" section with the same "Subscribe" fieldset
544    // subscriptions controls.    // subscriptions controls.
# Line 525  function subscriptions_og_form_alter($fo Line 562  function subscriptions_og_form_alter($fo
562    
563    // Identify if current is an OG node form.    // Identify if current is an OG node form.
564    if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form') {    if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form') {
565      $group_types = variable_get('og_node_types', array());      $group_types = $_subscriptions_og_group_types;
566      if (in_array($form['#node']->type, $group_types)) {      if (in_array($form['#node']->type, $group_types)) {
567        $group_nid = $form['#node']->nid;        $group_nid = $form['#node']->nid;
568        // Grouping "Group" settings        // Grouping "Group" settings
# Line 546  function subscriptions_og_form_alter($fo Line 583  function subscriptions_og_form_alter($fo
583        $new_form['subscriptions_og_autosubs_'. $group_nid] = array(        $new_form['subscriptions_og_autosubs_'. $group_nid] = array(
584          '#type' => 'checkbox',          '#type' => 'checkbox',
585          '#title' => t('New members are subscribed to notifications automatically.'),          '#title' => t('New members are subscribed to notifications automatically.'),
586          '#description' => t('If checked then new group members will have'.          '#description' => t('If checked then new group members will have "subscribe to this post" enabled by default.'),
           ' "subscribe to this post" enabled by default.'),  
587          '#default_value' =>          '#default_value' =>
588            variable_get('subscriptions_og_autosubs_'. $group_nid, 0),            variable_get('subscriptions_og_autosubs_'. $group_nid, 0),
589        );        );
# Line 592  function subscriptions_og_form_alter($fo Line 628  function subscriptions_og_form_alter($fo
628            $defaults->send_comments = $i;            $defaults->send_comments = $i;
629          }          }
630          elseif (!is_object($defaults)) {          elseif (!is_object($defaults)) {
631            if (_subscriptions_get_setting('send_comments', $form['account']['#value']))            if (
632                _subscriptions_get_setting('send_comments',
633                $form['account']['#value'])
634              )
635              $defaults = (object)array('send_comments' => $i);              $defaults = (object)array('send_comments' => $i);
636          }          }
637    
# Line 605  function subscriptions_og_form_alter($fo Line 644  function subscriptions_og_form_alter($fo
644    
645            // Implements auto-subscription when a user is asked to be joined            // Implements auto-subscription when a user is asked to be joined
646            if (            if (
647              variable_get('subscriptions_og_autosubs_'. $values[$i]['value'], 0) &&              variable_get(
648              in_array('og_confirm_subscribe', $_subscriptions_og_history)) {                'subscriptions_og_autosubs_'. $values[$i]['value'], 0
649              $form['wrapper']['subscriptions']['#default_value'][$i -1] = 1;              ) &&
650                in_array('og_confirm_subscribe', $_subscriptions_og_history)
651              ) {
652    
653                // Get subscription checkbox id thanks to function current()
654                $checkbox_id = current(
655                  // Get key of given item in an array
656                  array_keys(
657                    // Filter array, get item with value equal to 'To this group'
658                    preg_grep(
659                      '/^'. t('To this group') .'$/',
660                      $form['wrapper']['subscriptions']['#options'])
661                  )
662                );
663    
664                // Activate subscription checkbox
665                $form['wrapper']['subscriptions']['#default_value']['sog_autosubs'] =
666                  $checkbox_id;
667            }            }
668          }          }
669        }        }
# Line 650  function subscriptions_og_form_alter($fo Line 706  function subscriptions_og_form_alter($fo
706      );      );
707    
708      $select[0] = '<'. t('none') .'>';      $select[0] = '<'. t('none') .'>';
709      $select = array_merge($select, variable_get('og_node_types', array('og')));  
710        $select = array_merge($select, subscription_og_get_group_types());
711    
712      $form['group']['subscriptions_restricted_og'] = array(      $form['group']['subscriptions_restricted_og'] = array(
713        '#type'          => 'select',        '#type'          => 'select',
714        '#title'         => t('Restricted group types'),        '#title'         => t('Restricted group types'),
715        '#default_value' => variable_get('subscriptions_restricted_og', array()),        '#default_value' => variable_get('subscriptions_restricted_og', array()),
716        '#options'       => $select,        '#options'       => $select,
717        '#description'   => t("For the selected group types only those groups will be listed on the user's group subscription page (user/#uid/subscriptions/group) in which either the user is a member or to which the user has already subscribed."),        '#description'   => t('For the selected group types only those groups will be listed on the user\'s group subscription page (user/#uid/subscriptions/group) in which either the user is a member or to which the user has already subscribed.'),
718        '#multiple'      => TRUE,        '#multiple'      => TRUE,
719      );      );
720      $form['group']['subscriptions_omitted_og'] = array(      $form['group']['subscriptions_omitted_og'] = array(
# Line 668  function subscriptions_og_form_alter($fo Line 725  function subscriptions_og_form_alter($fo
725        '#description'   => t('Select group types which should be <strong>omitted</strong> from subscription listings. Users will not be able to subscribe to groups of this type.'),        '#description'   => t('Select group types which should be <strong>omitted</strong> from subscription listings. Users will not be able to subscribe to groups of this type.'),
726        '#multiple'      => TRUE,        '#multiple'      => TRUE,
727      );      );
   
 /*  EXCLUDED  
     $form['group']['subscriptions_autosubs_og'] = array(  
      '#type' => 'checkbox',  
      '#title' => t('New members of a group are subscribed automatically.'),  
      '#default_value' => variable_get('subscriptions_autosubs_og', 0),  
     );  
 */  
728      $form['group']['subscriptions_og_list_joined_only'] = array(      $form['group']['subscriptions_og_list_joined_only'] = array(
729       '#type' => 'checkbox',       '#type' => 'checkbox',
730       '#title' => t('Limit listing of subscriptions in account(user/#uid/subscriptions/group) to those where user is member.'),       '#title' => t('Limit listing of subscriptions in account(user/#uid/subscriptions/group) to those where user is member.'),
# Line 684  function subscriptions_og_form_alter($fo Line 733  function subscriptions_og_form_alter($fo
733    
734    }    }
735  }  }
736    /**
737     * Return an array of group types with their description.
738     */
739    function subscription_og_get_group_types() {
740      global $_subscriptions_og_group_types;
741      $types = node_get_types();
742      $group_types = array();
743      foreach ($types as $type) {
744        if (in_array($type->type, $_subscriptions_og_group_types))
745          $group_types[$type->type] = t($type->name);
746      }
747    
748      return $group_types;
749    }
750    
751  /**  /**
752   * Returns a list of group subscriptions by group type.   * Returns a list of group subscriptions by group type.
# Line 696  function subscriptions_og_form_alter($fo Line 759  function subscriptions_og_form_alter($fo
759   * @see _subscriptions_og_types(), subscriptions_og_group_type_form()   * @see _subscriptions_og_types(), subscriptions_og_group_type_form()
760   */   */
761  function subscriptions_og_page_group_type($account, $form) {  function subscriptions_og_page_group_type($account, $form) {
762      global $_subscriptions_og_group_types;
763    
764    // traverse the group types    // traverse the group types
765    $group_types = variable_get('og_node_types', array());    $group_types = $_subscriptions_og_group_types;
766    
767    // omit undesired group types from listing    // omit undesired group types from listing
768    $omits = variable_get('subscriptions_omitted_og', array());    $omits = variable_get('subscriptions_omitted_og', array());
# Line 707  function subscriptions_og_page_group_typ Line 771  function subscriptions_og_page_group_typ
771    }    }
772    
773    if (count($group_types)) {    if (count($group_types)) {
774      $query = "      $query = '
775  SELECT  SELECT
776    nt.type,    nt.type,
777    nt.name    nt.name
778  FROM  FROM
779    {node_type} nt    {node_type} nt
780  WHERE  WHERE
781    nt.type IN('". implode("','", $group_types) ."')    nt.type IN("'. implode('","', $group_types) .'")
782      ";      ';
783      $rs = db_query($query);      $rs = db_query($query);
784        $group_types = array();
785      while ($gt = db_fetch_object($rs)) {      while ($gt = db_fetch_object($rs)) {
786        $group_types[$gt->type] = $gt;        $group_types[$gt->type] = $gt;
787      }      }
# Line 758  function subscriptions_og_group_type_for Line 823  function subscriptions_og_group_type_for
823    if (!is_object($account))    if (!is_object($account))
824      $account = user_load(array('uid' => 0));      $account = user_load(array('uid' => 0));
825    
826    $sql = db_rewrite_sql("    $sql = db_rewrite_sql('
827  SELECT  SELECT
828    s.value, s.send_interval, s.author_uid,    s.value, s.send_interval, s.author_uid,
829    s.send_comments, s.send_updates, n.type, n.title    s.send_comments, s.send_updates, n.type, n.title
# Line 769  FROM Line 834  FROM
834    {subscriptions} s ON    {subscriptions} s ON
835      g.nid = s.value      g.nid = s.value
836  WHERE  WHERE
837    s.module = 'node' AND    s.module = "node" AND
838    s.field = 'group_nid' AND    s.field = "group_nid" AND
839    s.recipient_uid = %d    s.recipient_uid = %d
840  ORDER BY  ORDER BY
841    s.author_uid    s.author_uid
842    ", 'n', 'group_nid');    ', 'n', 'group_nid');
843    $result = db_query($sql, $uid);    $result = db_query($sql, $uid);
844    $user_subscriptions = array();    $user_subscriptions = array();
845    while ($s = db_fetch_array($result)) {    while ($s = db_fetch_array($result)) {
# Line 794  ORDER BY Line 859  ORDER BY
859    
860    // Load list of types with their joinable groups    // Load list of types with their joinable groups
861    if (count($group_types)) {    if (count($group_types)) {
862      $query = "      $query = '
863  SELECT  SELECT
864    n.*,    n.*,
865    g.private    g.private
# Line 803  FROM Line 868  FROM
868    {og} g ON    {og} g ON
869      n.nid = g.nid      n.nid = g.nid
870  WHERE  WHERE
871    n.type IN('". implode("','", array_keys($group_types)) ."')    n.type IN("'. implode('","', array_keys($group_types)) .'")
872      ";      ';
873    
874      $rs = db_query($query);      $rs = db_query($query);
875      while ($group = db_fetch_object($rs)) {      while ($group = db_fetch_object($rs)) {
# Line 815  WHERE Line 880  WHERE
880    $account_groups =& array_keys($account->og_groups);    $account_groups =& array_keys($account->og_groups);
881    
882    // Determines if must restrict or no subscriptions listing in user account    // Determines if must restrict or no subscriptions listing in user account
883    $list_joined_only = variable_get("subscriptions_og_list_joined_only", FALSE);    $list_joined_only = variable_get('subscriptions_og_list_joined_only', FALSE);
884    
885      $types_to_restrict = variable_get('subscriptions_restricted_og', array());
886    
887    // Construct groups subscriptions form    // Construct groups subscriptions form
888    foreach ($group_types as $type) {    foreach ($group_types as $type) {
# Line 831  WHERE Line 898  WHERE
898        '#theme' => 'subscriptions_form_table',        '#theme' => 'subscriptions_form_table',
899      );      );
900      $subscriptions_type = $subscriptions[$type->type];      $subscriptions_type = $subscriptions[$type->type];
     $types_to_restrict = variable_get('subscriptions_restricted_og', array());  
901      // Check if $type->type is a rectricted group type      // Check if $type->type is a rectricted group type
902      if (!in_array($type->type, $types_to_restrict)) {      if (!in_array($type->type, $types_to_restrict)) {
903        $tree = $groups_by_types[$type->type];        $tree = $groups_by_types[$type->type];
# Line 845  WHERE Line 911  WHERE
911        ) {        ) {
912          $subscriptions_groups_by_type[$type->type] = $groups_by_types[$type->type];          $subscriptions_groups_by_type[$type->type] = $groups_by_types[$type->type];
913        }        }
   
914        if ($tree = $subscriptions_groups_by_type[$type->type]) {        if ($tree = $subscriptions_groups_by_type[$type->type]) {
915          // Get tree with full group nodes          // Get tree with full group nodes
916          $full_tree = $groups_by_types[$type->type];          $full_tree = $groups_by_types[$type->type];
917          // Construct groups tree according to user groups          // Construct groups tree according to user groups
918          foreach ($full_tree as $group_nid => $group) {          foreach ($full_tree as $group_nid => $group) {
919            // If user is member of given group            // If user is member of given group or is subscribed to.
920            if (            if (
921              in_array($group_nid, $user_groups) ||              in_array($group_nid, $user_groups) ||
922              in_array($group_nid, $user_subscriptions)              in_array($group_nid, $user_subscriptions)
# Line 865  WHERE Line 930  WHERE
930          }          }
931          $form[$type->type][1] = array(          $form[$type->type][1] = array(
932            '#type' => 'item',            '#type' => 'item',
933            '#description' => '<div>'. t("Only groups that you have already subscribed to or that you are a member of are listed here. You may be able to subscribe to other groups from their group home pages.") .'</div>',            '#description' => '<div>'. ($list_joined_only ?
934                  t('Only groups that you are already a member will be listed here. You may be able to subscribe to other groups from their group home pages.') :
935                  t('Only groups that you have already subscribed to or that you are a member of are listed here. You may be able to subscribe to other groups from their group home pages.')
936                ).
937                '</div>',
938          );          );
939        }        }
940      }      }
941      $defaults = array();      $defaults = array();
942      if (isset($tree)) {      if (isset($tree)) {
943        foreach ($tree as $group) {        foreach ($tree as $group) {
944          if ($account->uid == 0 || ((!$group->private && !$list_joined_only) || in_array($group->nid, $account_groups)))          if (
945              // Don't care about resctrictions if this form is called from
946              // Subscriptions default settings
947              $account->uid == 0 || (
948                // If is a private group, user must be joined to
949                ($group->private ? in_array($group->nid, $account_groups) : TRUE) &&
950                // If enabled, limit list to groups where user is already a member
951                ($list_joined_only ? in_array($group->nid, $account_groups) : TRUE)
952              )
953            ) {
954            subscriptions_og_group_form(            subscriptions_og_group_form(
955              $form[$type->type][0], $subscriptions_type[$group->nid],              $form[$type->type][0], $subscriptions_type[$group->nid],
956              $defaults, $group, $uid, $account);              $defaults, $group, $uid, $account);
957            }
958        }        }
959      }      }
960      else {      else {
961        $form[$type->type]['info']['#value'] = '<p>'. t("Only groups that you have already subscribed to or that you are a member of are listed here. You may be able to subscribe to other groups from their group home pages.") .'</p>';        if ($list_joined_only) {
962            $form[$type->type]['info']['#value'] = '<p>'. ($list_joined_only ?
963                  t('Only groups that you are already a member will be listed here. You may be able to subscribe to other groups from their group home pages.') :
964                  t('Only groups that you have already subscribed to or that you are a member of are listed here. You may be able to subscribe to other groups from their group home pages.')
965                ).
966              '</p>';
967          }
968      }      }
969      $form[$type->type][0]['defaults'] = array(      $form[$type->type][0]['defaults'] = array(
970        '#type' => 'value',        '#type' => 'value',
# Line 952  function subscriptions_og_group_form(&$f Line 1037  function subscriptions_og_group_form(&$f
1037   * Implementation of hook_disable().   * Implementation of hook_disable().
1038   */   */
1039  function subscriptions_og_disable() {  function subscriptions_og_disable() {
1040    db_query("DELETE FROM {subscriptions_queue} WHERE module = 'node' AND field = 'group_nid'");    // Prevent unsent notifications to be sent after module is deactivate.
1041      db_query('DELETE FROM {subscriptions_queue} WHERE module = "node" AND field = "group_nid"');
1042  }  }
1043    
1044  /*  /*
# Line 965  function subscriptions_og_disable() { Line 1051  function subscriptions_og_disable() {
1051  function subscriptions_og_count_user_subscriptions($count, $uid) {  function subscriptions_og_count_user_subscriptions($count, $uid) {
1052    $type   = _subscriptions_og_types();    $type   = _subscriptions_og_types();
1053    $fields = $type['group']['fields'];    $fields = $type['group']['fields'];
1054    $query = "    $query = '
1055  SELECT count(*)  SELECT count(*)
1056  FROM {subscriptions}  FROM {subscriptions}
1057  WHERE  WHERE
1058    module = 'node' AND    module = "node" AND
1059    field = 'group_nid' AND    field = "group_nid" AND
1060    recipient_uid = %d    recipient_uid = %d
1061    ";    ';
1062    $count[$fields[0]][$fields[1]] = db_result(db_query($query, $uid));    $count[$fields[0]][$fields[1]] = db_result(db_query($query, $uid));
1063    return $count;    return $count;
1064  }  }
# Line 1006  function subscriptions_og_og($op, $gid, Line 1092  function subscriptions_og_og($op, $gid,
1092            $params[$i+1]['field'] == 'group_nid' &&            $params[$i+1]['field'] == 'group_nid' &&
1093            !$subscriptions[$i+1]            !$subscriptions[$i+1]
1094          ) {          ) {
1095              // Deactivate auto-subscription if user is joined to group by
1096              // maintainer (from og/users/group_nid/add_user)
1097            $no_autosubs = TRUE;            $no_autosubs = TRUE;
1098          }          }
1099        }        }
# Line 1040  function subscriptions_og_mailkeys() { Line 1128  function subscriptions_og_mailkeys() {
1128    return array('subscriptions-node-group_nid');    return array('subscriptions-node-group_nid');
1129  }  }
1130    
1131    if (!function_exists('og_node_groups_distinguish')) {
1132  /**    /**
1133   * It is modified copy of og_node_groups_distinguish (For temporary use).     * It is a modified copy of og_node_groups_distinguish for backwards
1134   *     * compatibility with og 6.x against og 7.x.
1135   * Iterate over a set of groups and separate out those that are inaccessible to the current user.     *
1136   * Don't return groups of which the current user is a member. Used in og_form_add_og_audience() and node.tpl.php.     * Iterate over a set of groups and separate out those that are inaccessible to the current user.
1137   *     * Don't return groups of which the current user is a member. Used in og_form_add_og_audience() and node.tpl.php.
1138   * @return array     *
1139   *   A two element array containing 'accessible' and 'inaccessible' keys.     * @return array
1140   **/     *   A two element array containing 'accessible' and 'inaccessible' keys.
1141  function subscriptions_og_node_groups_distinguish($groups_names_both, $return_joined = FALSE) {     **/
1142    global $user;    function subscriptions_og_node_groups_distinguish($groups_names_both, $exclude_joined = TRUE) {
1143        global $user;
1144    $current_groups = array('accessible' => array(), 'inaccessible' => array());  
1145    if (empty($groups_names_both)) {      $current_groups = array('accessible' => array(), 'inaccessible' => array());
1146      // Do nothing.      if (empty($groups_names_both)) {
1147    }        // Do nothing.
   else {  
     $placeholders = array_fill(0, count($groups_names_both), '%d');  
     $sql = 'SELECT n.nid FROM {node} n WHERE n.nid IN ('. implode(', ', $placeholders). ')';  
     $result = db_query(db_rewrite_sql($sql), array_keys($groups_names_both));  
     while ($row = db_fetch_object($result)) {  
       $current_groups['accessible'][$row->nid]['title'] = $groups_names_both[$row->nid];  
1148      }      }
1149      foreach ($groups_names_both as $gid => $title) {      else {
1150        if (!in_array($gid, array_keys($current_groups['accessible']))) {        $placeholders = array_fill(0, count($groups_names_both), '%d');
1151          $current_groups['inaccessible'][$gid] = $gid;        $sql = 'SELECT n.nid FROM {node} n WHERE n.nid IN ('. implode(', ', $placeholders). ')';
1152          $result = db_query(db_rewrite_sql($sql), array_keys($groups_names_both));
1153          while ($row = db_fetch_object($result)) {
1154            $current_groups['accessible'][$row->nid]['title'] = $groups_names_both[$row->nid];
1155          }
1156          foreach ($groups_names_both as $gid => $title) {
1157            if (!in_array($gid, array_keys($current_groups['accessible']))) {
1158              $current_groups['inaccessible'][$gid] = $gid;
1159            }
1160          }
1161          if ($exclude_joined) {
1162            // Don't return groups that the user has already joined (default).
1163            $current_groups['accessible'] = array_diff_assoc($current_groups['accessible'], $user->og_groups);
1164        }        }
1165      }      }
1166      if (!$return_joined)  
1167        // There is no point in returning groups that the user has already joined.      return $current_groups;
       $current_groups['accessible'] = array_diff_assoc($current_groups['accessible'], $user->og_groups);  
1168    }    }
   
   return $current_groups;  
1169  }  }
   
1170  /**  /**
1171   * Returns a list of groups by given group types.   * Returns a list of groups by given group types.
1172   *   *
1173   * @param $group_types   * @param $group_types
1174   *   Format: Array('type1', ..., 'typeN')   *   Format: Array('type1', ..., 'typeN')
1175   *   To be populated by og_node_types system variable by default. If   *   To be populated by $_subscriptions_og_group_types global variable by default. If
1176   *   provided, only those groups of given types will be listed.   *   provided, only those groups of given types will be listed.
1177   *   *
1178   * @return   * @return
1179   *   Array of nodes of types in $group_types.   *   Array of nodes of types in $group_types.
1180   */   */
1181  function subscriptions_og_get_groups_by_types($group_types = array()) {  function subscriptions_og_get_groups_by_types($group_types = array()) {
1182      global $_subscriptions_og_group_types;
1183    
1184    if (!count($group_types)) {    if (!count($group_types)) {
1185      $group_types = variable_get('og_node_types', array());      $group_types = $_subscriptions_og_group_types;
1186    }    }
1187    if (count($group_types)) {    if (count($group_types)) {
1188      $query = "      $query = '
1189  SELECT  SELECT
1190    n.*,    n.*,
1191    n.title name,    n.title name,
# Line 1101  SELECT Line 1193  SELECT
1193  FROM  FROM
1194    {node} n    {node} n
1195  WHERE  WHERE
1196    n.type IN('". implode("','", $group_types) ."')    n.type IN("'. implode('","', $group_types) .'")
1197      ";      ';
1198    
1199      $rs = db_query($query);      $rs = db_query($query);
1200      while ($group = db_fetch_object($rs)) {      while ($group = db_fetch_object($rs)) {
# Line 1111  WHERE Line 1203  WHERE
1203    }    }
1204    return $groups;    return $groups;
1205  }  }
1206    
1207    /**
1208     * Implementation of hook_help().
1209     */
1210    function subscriptions_og_help($section) {
1211      global $locale;
1212      global $_subscriptions_og_path;
1213    
1214      // Look for README file
1215      $readme_file = 'po/README.'.$locale .'.txt';
1216      if (!file_exists($_subscriptions_og_path . $readme_file))
1217        $readme_file = 'README.txt';
1218    
1219      switch ($section) {
1220        case 'admin/help/subscriptions_og':
1221          return t('<p>Allows users to subscribe to organic groups.</p>');
1222          break;
1223        case 'admin/help#subscriptions_og':
1224          return t('!README_file contents: <pre>!README_contents</pre><br />', array(
1225            '!README_file' => $readme_file,
1226            '!README_contents' => file_get_contents($_subscriptions_og_path . $readme_file),
1227          ));
1228          break;
1229      }
1230    }

Legend:
Removed from v.1.1.2.52  
changed lines
  Added in v.1.1.2.53

  ViewVC Help
Powered by ViewVC 1.1.2