? p1
? patch
? permissions.patch
? sub.inc
? todo.txt
Index: subscriptions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/subscriptions/subscriptions.module,v
retrieving revision 1.62.2.45.2.6
diff -u -p -r1.62.2.45.2.6 subscriptions.module
--- subscriptions.module	26 Jul 2007 05:18:06 -0000	1.62.2.45.2.6
+++ subscriptions.module	26 Jul 2007 19:38:31 -0000
@@ -237,152 +237,27 @@ function subscriptions_settings() {
 function subscriptions_menu($may_cache) {
   global $user;  // we need the user to to build some urls
 
-  $items = array();
-  $items[] = array(
-    'path' => 'admin/settings/subscriptions',
-    'title' => t('Subscriptions'),
-    'description' => t('Enables site settings for user subscriptions.'),
-    'callback' => 'drupal_get_form',
-    'callback arguments' => 'subscriptions_settings',
-    'access' => user_access('administer site configuration'),
-    'type' => MENU_NORMAL_ITEM, // optional
-  );
-
-  if (variable_get('subscriptions_usersmenu', 1) && arg(0) == 'user' && is_numeric(arg(1))) {
-    $account = user_load(array('uid' => arg(1)));
-
-    // User subscription pages
-    if (($user->uid == $account->uid) || user_access('admin users subscriptions')) {
-      $items[] = array(
-        'path' => "user/". arg(1) ."/subscriptions",
-        'title' => t('Subscriptions'),
-        'callback' => 'subscriptions_page',
-        'access' => user_access('maintain own subscriptions'),
-        'type' => MENU_LOCAL_TASK,
-        'callback arguments' => array(arg(1), "content"),
-      );
-      // User Subscriptions submenus
-      if (module_exists('blog')) {
-        $items[] = array(
-          'path' => "user/". arg(1) ."/subscriptions/blogs",
-          'title' => t('blogs'),
-          'callback' => 'subscriptions_page',
-          'access' => user_access('subscribe to blogs'),
-          'type' => MENU_LOCAL_TASK,
-          'callback arguments' => array(arg(1), "blogs"),
-        );
-      }
-
-      // comment subscription
-      $items[] = array(
-        'path' => "user/". arg(1) ."/subscriptions/node",
-        'title' => t('threads'),
-        'callback' => 'subscriptions_page',
-        'access' => user_access('subscribe to content'),
-        'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1,
-        'callback arguments' => array(arg(1), "content"),
-      );
-
-      // Content type subscription
-      $items[] = array(
-        'path' => "user/". arg(1) ."/subscriptions/type",
-        'title' => t('content types'),
-        'callback' => 'subscriptions_page',
-        'access' => user_access('subscribe to content types'),
-        'type' => MENU_LOCAL_TASK,
-        'callback arguments' => array(arg(1), "type"),
-      );
-
-      // Taxonomy subscription
-      if (module_exists('taxonomy')) {
-        $items[] = array(
-          'path' => "user/". arg(1) ."/subscriptions/taxonomy",
-          'title' => t('categories'),
-          'callback' => 'subscriptions_page',
-          'access' => user_access('subscribe to taxonomy terms'),
-          'type' => MENU_LOCAL_TASK,
-          'callback arguments' => array(arg(1), "taxonomy"),
-        );
-      }
-
-      // RSS feed of subscriptions
-      $items[] = array(
-        'path' => "user/". arg(1) ."/subscriptions/feed",
-        'title' => t('rss feed'),
-        'access' => user_access('maintain own subscriptions'),
-        'callback' => 'subscriptions_feed',
-        'type' => MENU_LOCAL_TASK, 'weight' => 1,
-        'callback arguments' => array(arg(1), "feed"),
-      );
-    }
-  }
-
-  // My subscriptions pages
   if ($may_cache) {
-    $items[] = array(
-      'path' => 'subscriptions',
-      'title' => t('My subscriptions'),
-      'access' => user_access('subscribe to content'),
-      'callback' => 'subscriptions_page',
-      'type' => MENU_NORMAL_ITEM,
-      'callback arguments' => array($user->uid, "content"),
-    );
-
-    // comment subscription
-    $items[] = array(
-      'path' => "subscriptions/node",
-      'title' => t('threads'),
-      'callback' => 'subscriptions_page',
-      'access' => user_access('subscribe to content'),
-      'type' => MENU_DEFAULT_LOCAL_TASK,
-      'weight' => -1,
-      'callback arguments' => array($user->uid, "content"),
-    );
-
-    // User Subscriptions submenus
-    if (module_exists('blog')) {
-      $items[] = array(
-        'path' => "subscriptions/blogs",
-        'title' => t('blogs'),
-        'callback' => 'subscriptions_page',
-        'access' => user_access('subscribe to blogs'),
-        'type' => MENU_LOCAL_TASK,
-        'callback arguments' => array($user->uid, "blogs"),
-      );
-    }
+    $items = _subscriptions_menu();
 
-    // Content type subscription
     $items[] = array(
-      'path' => "subscriptions/type",
-      'title' => t('content types'),
-      'callback' => 'subscriptions_page',
-      'access' => user_access('subscribe to content types'),
-      'type' => MENU_LOCAL_TASK,
-      'callback arguments' => array($user->uid, "type"),
+      'path' => 'admin/settings/subscriptions',
+      'title' => t('Subscriptions'),
+      'description' => t('Enables site settings for user subscriptions.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'subscriptions_settings',
+      'access' => user_access('administer site configuration'),
     );
+  }
+  else {
+    if (variable_get('subscriptions_usersmenu', 1) && arg(0) == 'user' && is_numeric(arg(1))) {
+      $account = user_load(array('uid' => arg(1)));
 
-    // Taxonomy subscription
-    if (module_exists('taxonomy')) {
-      $items[] = array(
-        'path' => "subscriptions/taxonomy",
-        'title' => t('categories'),
-        'callback' => 'subscriptions_page',
-        'access' => user_access('subscribe to taxonomy terms'),
-        'type' => MENU_LOCAL_TASK,
-        'callback arguments' => array($user->uid, "taxonomy"),
-      );
+      // User subscription pages
+      if (($user->uid == $account->uid) || user_access('admin users subscriptions')) {
+        $items = _subscriptions_menu($account->uid);
+      }
     }
-
-    // RSS feed of subscriptions
-    $items[] = array(
-      'path' => "subscriptions/feed",
-      'title' => t('rss feed'),
-      'access' => user_access('subscribe to content'),
-      'callback' => 'subscriptions_feed',
-      'type' => MENU_LOCAL_TASK,
-      'weight' => 1,
-      'callback arguments' => array($user->uid, "feed"),
-    );
   }
 
   /* hiding reporting stub until there is content behind it
@@ -397,6 +272,56 @@ function subscriptions_menu($may_cache) 
   return $items;
 }
 
+function _subscriptions_menu($uid = NULL) {
+  global $user;
+  if (isset($uid)) {
+    $base = 'user/'. $uid .'/subscriptions';
+  }
+  else {
+    $uid = $user->uid;
+    $base = 'subscriptions';
+  }
+  $array = module_invoke_all('subscriptions', 'menu');
+  $type = MENU_DEFAULT_LOCAL_TASK;
+  $weight = -1;
+  foreach ($array as $stype => $v) {
+    if (user_access($v['access'])) {
+      $items[] = array(
+        'path' => $base .'/'. $stype,
+        'title' => $v['title'],
+        'callback' => 'subscriptions_page',
+        'access' => TRUE,
+        'type' => $type,
+        'weight' => $weight,
+        'callback arguments' => array($uid, $stype),
+      );
+      if ($type == MENU_DEFAULT_LOCAL_TASK) {
+        $items[] = array(
+          'path' => $base,
+          'title' => t('My subscriptions'),
+          'access' => TRUE,
+          'callback' => 'subscriptions_page',
+          'callback arguments' => array($uid, $stype),
+        );
+        // RSS feed of subscriptions
+        $items[] = array(
+          'path' => $base .'/feed',
+          'title' => t('rss feed'),
+          'access' => TRUE,
+          'callback' => 'subscriptions_feed',
+          'type' => MENU_LOCAL_TASK,
+          'weight' => 1,
+          'callback arguments' => array($uid, 'feed'),
+        );
+        $type = MENU_LOCAL_TASK;
+        $weight = 0;
+      }
+    }
+  }
+  return $items;
+}
+
+
 /**
  * Implementation of hook_simpletest
  */
@@ -614,7 +539,8 @@ function subscriptions_mailvars($sid, $s
 function subscriptions_types($object_type = NULL, $object_value = NULL) {
   static $info;
   if (!isset($info)) {
-    $info = module_invoke_all('subscriptions_info');
+    $info['stype'] = module_invoke_all('subscriptions', 'info', 'stype');
+    $info['ptype'] = module_invoke_all('subscriptions', 'info', 'ptype');
     foreach ($info as $_object_type => $record) {
       foreach ($record as $_object_value => $module) {
         // Empty module means subscriptions and as we prefix all our hooks with
@@ -1427,15 +1353,15 @@ function subscriptions_page($uid, $displ
     default:
       // set output by type
       switch ($display_type) {
-        case 'blogs':
+        case 'blog':
           $output = subscriptions_blogs($account);
           break;
 
-        case 'taxonomy':
+        case 'taxa':
           $output = subscriptions_taxa($account);
           break;
 
-        case 'content':
+        case 'node':
           $output = subscriptions_nodes($account);
           break;
 
@@ -1526,19 +1452,61 @@ function subscriptions_views_tables() {
   return $tables;
 }
 
-function subscriptions_subscriptions_info() {
-  return array(
-    'stype' =>  array(
-      'node' => '',
-      'type' => '',
-      'taxa' => '',
-      'blog' => '',
-    ),
-    'ptype' => array(
-      'node' => '',
-      'comment' => '',
-    ),
-  );
+function subscriptions_subscriptions($op) {
+  static $menu, $functions;
+  $args = func_get_args();
+  array_shift($args);
+  switch ($op) {
+    case 'menu':
+      if (isset($menu)) {
+        return $menu;
+      }
+      $menu = array(
+        'node' => array(
+          'access' => 'subscribe to content',
+          'title' => t('threads'),
+        ),
+        'type' => array(
+          'access' => 'subscribe to content types',
+          'title' => t('content types'),
+        ),
+      );
+      if (module_exists('blog')) {
+        $menu['blog'] = array(
+          'access' => 'subscribe to blogs',
+          'title' => t('blogs'),
+        );
+      }
+      if (module_exists('taxonomy')) {
+        $menu['taxa'] = array(
+          'access' => 'subscribe to taxonomy terms',
+          'title' => t('categories'),
+        );
+      }
+      return $menu;
+    case 'info':
+      $index = $args[0];
+      if (isset($functions)) {
+        return isset($functions[$index]) ? $functions[$index] : FALSE;
+      }
+      $functions = array(
+        'stype' =>  array(
+          'node' => '',
+          'type' => '',
+        ),
+        'ptype' => array(
+          'node' => '',
+          'comment' => '',
+        ),
+      );
+      if (module_exists('taxonomy')) {
+        $functions['stype']['taxa'] = '';
+      }
+      if (module_exists('blog')) {
+        $functions['stype']['blog'] = '';
+      }
+      return isset($functions[$index]) ? $functions[$index] : FALSE;
+  }
 }
 
 function subscriptions_mailvars_node($sid, $ssid, $placeholders, $sql_args) {
