Index: premium/premium.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/premium/premium.info,v
retrieving revision 1.1
diff -u -p -r1.1 premium.info
--- premium/premium.info	21 Aug 2007 19:02:02 -0000	1.1
+++ premium/premium.info	9 Jul 2008 22:21:18 -0000
@@ -1,3 +1,4 @@
 ; $Id: premium.info,v 1.1 2007/08/21 19:02:02 vauxia Exp $
-name = Premium
-description = Restrict access to premium content.
+name=Premium
+description=Restrict access to premium content.
+core=6.x
Index: premium/premium.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/premium/premium.module,v
retrieving revision 1.7
diff -u -p -r1.7 premium.module
--- premium/premium.module	21 Aug 2007 19:02:02 -0000	1.7
+++ premium/premium.module	9 Jul 2008 22:21:18 -0000
@@ -1,44 +1,47 @@
-<?php /* $Id: premium.module,v 1.7 2007/08/21 19:02:02 vauxia Exp $ */
+<?php
+// $Id: premium.module,v 1.7 2007/08/21 19:02:02 vauxia Exp $
 /**
- * @file Restrict access to the full body of premium content
+ * @file
+ * Restrict access to the full body of premium content
  */
 
-function premium_menu($may_cache) {
-  $items = array();
-  if ($may_cache) {
-    $items[] = array('path' => 'admin/settings/premium',
-      'title' => t('Premium'),
-      'description' => t('Settings for access control to premium content.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => 'premium_settings',
-      'access' => user_access('administer site configuration'));
-  }
+/**
+ * Implementation of hook_menu().
+ */
+function premium_menu() {
+  $items['admin/settings/premium'] = array(
+    'title' => 'Premium',
+    'description' => 'Settings for access control of premium content.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('premium_settings'),
+    'access arguments' => array('administer site configuration'),
+  );
   return $items;
 }
- 
+
 /**
- * Implementation of hook_perm()
+ * Implementation of hook_perm().
  */
 function premium_perm() {
   return array('access premium content');
 }
 
 /**
- * Implementation of hook_cron()
+ * Implementation of hook_cron().
  */
 function premium_cron() {
   $ts = time();
-  db_query("DELETE FROM {premium} WHERE start_ts < $ts AND end_ts != 0 AND end_ts < $ts");
+  db_query("DELETE FROM {premium} WHERE start_ts < $ts AND end_ts <> 0 AND end_ts < $ts");
 }
 
 /**
- * Implementation of hook_nodeapi()
+ * Implementation of hook_nodeapi().
  */
 function premium_nodeapi(&$node, $op, $teaser) {
   $node->premium = _premium_node($node);
 
   switch ($op) {
-    
+
     case 'insert':
     case 'delete':
     case 'update':
@@ -47,19 +50,19 @@ function premium_nodeapi(&$node, $op, $t
         if ($op == 'delete') return;
       }
       if ($node->premium) {
-       $start_ts = $end_ts = 0 ;
+        $start_ts = $end_ts = 0 ;
         _premium_offset($node, $start_ts, $end_ts);
-        db_query('INSERT INTO {premium} (nid, start_ts, end_ts) 
+        db_query('INSERT INTO {premium} (nid, start_ts, end_ts)
           VALUES ( %d, %d, %d )', $node->nid, $start_ts, $end_ts);
       }
       return;
-      
+
     case 'load':
       $ts = time();
       return array('premium' => (int) db_result(db_query(
-          "SELECT 1 FROM {premium}  WHERE nid = %d 
+          "SELECT 1 FROM {premium}  WHERE nid = %d
           AND ( start_ts = 0 OR start_ts > $ts) AND end_ts < $ts", $node->nid)));
-      
+
     case 'view':
       $node->premium_access = true;
 
@@ -71,42 +74,42 @@ function premium_nodeapi(&$node, $op, $t
         return;                  // not viewing the body
       }
       foreach (module_implements('premium_access') as $name) {
-        $function = $name.'_premium_access';
+        $function = $name .'_premium_access';
         if ($function($user, $node)) {
           return;                // access granted explicitly
         }
       }
-  
+
       $node->premium_access = false;
       $node->content['body']['#value'] = theme('premium_body', $node);
   }
   return;
-} 
+}
 
 /**
- * Implementation of hook_form_alter()
- * 
- * Add the Premium checkbox to the node editing options and default settings
- * The Premium flag will behave like other options (published, promote, etc)
+ * Implementation of hook_form_alter().
+ *
+ * Add the Premium checkbox to the node editing options and default settings.
+ * The Premium flag will behave like other options (published, promote, etc).
  */
-function premium_form_alter($form_id, &$form) {
+function premium_form_alter(&$form, &$form_state, $form_id) {
   $type = $form['type']['#value'];
   $title = t('Access restricted for non-premium users');
   switch ($form_id) {
-    
+
     case 'node_type_form':
       $form['workflow']['node_options']['#options']['premium'] = $title;
       if (_premium_node($type)) {
         $form['workflow']['node_options']['#default_value'][] = 'premium';
       }
       return;
-      
-    case $type.'_node_form':
+
+    case $type .'_node_form':
       if (user_access('administer nodes')) {
         $node = $form['#node'];
         $form['options']['premium'] = array(
-          '#type' => 'checkbox', 
-          '#title' => $title, 
+          '#type' => 'checkbox',
+          '#title' => $title,
           '#default_value' => _premium_node($node),
         );
       }
@@ -119,43 +122,44 @@ function premium_form_alter($form_id, &$
  */
 function premium_settings() {
   $form = array();
-  
+
   // timeframe for premium + update existing nodes
   $form['premium_mode'] = array(
-    '#type'          => 'radios', 
-    '#title'         => t('Mode'), 
-    '#default_value' => variable_get('premium_mode', '0'), 
+    '#type'          => 'radios',
+    '#title'         => t('Mode'),
+    '#default_value' => variable_get('premium_mode', '0'),
     '#options'       => array(
-      '0' => t('Premium items are permanently restricted'), 
-      'archive' => t('Protect archives only: Items switch to premium status after a specified period'), 
-      'latest' => t('Protect latest content only: Items switch to non-premium status after a specified period'), 
+      '0' => t('Premium items are permanently restricted'),
+      'archive' => t('Protect archives only: Items switch to premium status after a specified period'),
+      'latest' => t('Protect latest content only: Items switch to non-premium status after a specified period'),
     ),
   );
-  
+
   $form['premium_time_count'] = array(
-    '#type'          => 'select', 
-    '#title'         => t('Count'), 
-    '#default_value' => variable_get('premium_time_count', '2'), 
-    '#options'       => array(1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, 
-      10=>10, 11=>11, 12=>12, 13=>13, 14=>14, 15=>15), 
+    '#type'          => 'select',
+    '#title'         => t('Count'),
+    '#default_value' => variable_get('premium_time_count', '2'),
+    '#options'       => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6,
+                          7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12,
+                          13 => 13, 14 => 14, 15 => 15),
   );
-  
+
   $form['premium_time_unit'] = array(
-    '#type'          => 'select', 
-    '#title'         => t('Unit'), 
-    '#default_value' => variable_get('premium_time_unit', 'W'), 
-    '#options'       => array('D' => t('Days'), 
-        'W' => t('Weeks'), 
-        'M' => t('Months'), 
-        'Y' => t('Years')), 
+    '#type'          => 'select',
+    '#title'         => t('Unit'),
+    '#default_value' => variable_get('premium_time_unit', 'W'),
+    '#options'       => array('D' => t('Days'),
+        'W' => t('Weeks'),
+        'M' => t('Months'),
+        'Y' => t('Years')),
   );
-  
+
   $form['premium_message'] = array(
-    '#type'          => 'textarea', 
-    '#title'         => t('Premium body text'), 
-    '#default_value' => variable_get('premium_message', t('Full text available to premium subscribers only')), 
-    '#cols'          => 60, 
-    '#rows'          => 30, 
+    '#type'          => 'textarea',
+    '#title'         => t('Premium body text'),
+    '#default_value' => variable_get('premium_message', t('Full text available to premium subscribers only')),
+    '#cols'          => 60,
+    '#rows'          => 30,
     '#description'   => t('When a visitor doesn\'t have access to a premium item they will see this message instead of its full text')
   );
   return system_settings_form($form);
@@ -166,44 +170,55 @@ function premium_settings() {
  * Calculate time offset for auto-aging / auto-archiving
  */
 function _premium_offset($node, &$start_ts, &$end_ts) {
-  $c = variable_get('premium_time_count',2);
-  $u = variable_get('premium_time_unit','W');
+  $c = variable_get('premium_time_count', 2);
+  $u = variable_get('premium_time_unit', 'W');
   $s = $node->created;
-  
+
   switch ( variable_get('premium_mode', '0') ) {
-    
+
     case 'archive' :             // public first, premium after awhile
-      $start_ts = mktime(date('H',$s)+($u=='H')*$c, 0, 0, date('m',$s)+($u=='M')*$c,
-        date('d',$s)+($u=='D')*$c+($u=='W')*$c*7, date('y',$s)+($u=='Y')*$c);
+      $start_ts = mktime(date('H', $s)+($u=='H')*$c, 0, 0, date('m', $s)+($u=='M')*$c,
+        date('d', $s)+($u=='D')*$c+($u=='W')*$c*7, date('y', $s)+($u=='Y')*$c);
       return;
-    
+
     case 'latest' :             // premium first, ages to general availability
-      $end_ts   = mktime(date('H',$s)+($u=='H')*$c, 0, 0, date('m',$s)+($u=='M')*$c,
-        date('d',$s)+($u=='D')*$c+($u=='W')*$c*7, date('y',$s)+($u=='Y')*$c);
+      $end_ts   = mktime(date('H', $s)+($u=='H')*$c, 0, 0, date('m', $s)+($u=='M')*$c,
+        date('d', $s)+($u=='D')*$c+($u=='W')*$c*7, date('y', $s)+($u=='Y')*$c);
       return;
   }
   return;
 }
 
 /**
- * Establish premium settings for a node or node type
+ * Establish premium settings for a node or node type.
  */
 function _premium_node($node) {
   // This is a node type: use default settings
   if (is_string($node)) {
-    return in_array('premium', variable_get("node_options_{$node}",array()));
+    return in_array('premium', variable_get("node_options_{$node}", array()));
   }
 
   // Already has a value
   if (isset($node->premium)) return $node->premium;
 
   // Use default settings for this node type
-  return in_array('premium', variable_get("node_options_{$node->type}",array()));
+  return in_array('premium', variable_get("node_options_{$node->type}", array()));
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function premium_theme() {
+  return array(
+    'premium_body' => array(
+      'arguments' => array('node' => NULL),
+    ),
+  );
 }
 
 /**
  * Reformat the message body with a premium content message
  */
 function theme_premium_body($node) {
-  return check_markup($node->teaser, $node->format, FALSE) . '<div class="premium-message">'.variable_get('premium_message', t('Full text available to premium subscribers only')).'</div>';
+  return check_markup($node->teaser, $node->format, FALSE) .'<div class="premium-message">'. variable_get('premium_message', t('Full text available to premium subscribers only')) .'</div>';
 }
