Index: modules/premium/premium.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/premium/premium.module,v retrieving revision 1.2 diff -u -r1.2 premium.module --- modules/premium/premium.module 28 Jan 2006 19:15:22 -0000 1.2 +++ modules/premium/premium.module 27 Feb 2006 01:05:25 -0000 @@ -2,7 +2,7 @@ /** * @file Restrict access to the full body of premium content */ - + /** * Implementation of hook_help() */ @@ -58,11 +58,11 @@ ); $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 $form; @@ -80,7 +80,7 @@ */ function premium_nodeapi(&$node, $op, $teaser) { switch ($op) { - + case 'delete': case 'insert': case 'update': @@ -90,19 +90,19 @@ } if ($node->premium) { _premium_offset($node, $start_ts = 0, $end_ts = 0); - db_query('INSERT INTO {premium} (nid, start_ts, end_ts) VALUES ( %d, %d, %d )' - , $node->nid, $start_ts, $end_ts); + db_query('INSERT INTO {premium} (nid, rid, start_ts, end_ts) VALUES ( %d, %d, %d, %d )' + , $node->nid, $node->premium, $start_ts, $end_ts); } return; - + case 'load': return array('premium' => (int) db_result(db_query( - 'SELECT 1 FROM {premium} WHERE nid = %d + 'SELECT rid FROM {premium} WHERE nid = %d AND ( start_ts = 0 OR start_ts > NOW()) AND end_ts < NOW()', $node->nid))); - + case 'view': global $user; - if (!$node->premium || user_access('access premium content')) { + if (!$node->premium || ($node->premium == 2 && $user->uid) || in_array($node->premium, array_keys($user->roles))) { return; // not premium content or user has privileges } if ($teaser) { @@ -114,7 +114,7 @@ return; // access granted explicitly } } - + $node->body = theme('premium_body', $node); } return; @@ -128,23 +128,26 @@ */ function premium_form_alter($form_id, &$form) { $type = $form['type']['#value']; - $title = t('Access restricted for non-premium users'); - + $title = t('Access to full article'); + switch ($form_id) { - + case $type.'_node_settings': - $form['workflow']["node_options_$type"]['#options']['premium'] = $title; - if (in_array('premium', variable_get("node_options_{$type}",array()))) { - $form['workflow']["node_options_$type"]['#default_value'][] = 'premium'; - } + $form['workflow']["node_{$type}_premium"] = array( + '#type' => 'select', + '#title' => $title, + '#default_value' => variable_get("node_{$type}_premium", 0), + '#options' => _premium_get_roles(), + ); return; - case $type.'_node_form': $node = $form['#node']; - $premium = (int) $node->nid ? $node->premium : in_array('premium', variable_get("node_options_{$type}",array())); - $form['options']['premium'] = $title; + $premium = (int) $node->nid ? $node->premium : variable_get("node_{$type}_premium", 0); $form['options']['premium'] = array( - '#type' => 'checkbox', '#title' => $title, '#default_value' => $premium, + '#type' => 'select', + '#title' => $title, + '#default_value' => $premium, + '#options' => _premium_get_roles(), ); return; } @@ -157,9 +160,9 @@ $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); @@ -173,6 +176,14 @@ return; } +function _premium_get_roles() { + $roles[0] = t("-- Open to all users --"); + foreach(user_roles(TRUE) as $rid=>$name) { + $roles[$rid] = $name; + } + return $roles; +} + /** * Reformat the message body with a premium content message */ Index: modules/premium/premium.mysql =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/premium/premium.mysql,v retrieving revision 1.1 diff -u -r1.1 premium.mysql --- modules/premium/premium.mysql 25 Dec 2005 21:58:52 -0000 1.1 +++ modules/premium/premium.mysql 26 Feb 2006 21:24:51 -0000 @@ -2,6 +2,7 @@ CREATE TABLE premium ( nid INT NOT NULL, + rid INT NOT NULL, start_ts INT, end_ts INT, PRIMARY KEY(nid)