Index: premium.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/premium/premium.module,v retrieving revision 1.11 diff -u -p -r1.11 premium.module --- premium.module 30 Jul 2008 03:16:23 -0000 1.11 +++ premium.module 30 Jul 2008 05:05:49 -0000 @@ -125,7 +125,29 @@ function premium_form_alter($form_id, &$ */ function premium_settings() { $form = array(); - + $form['#validate'] = array('premium_settings_save' => array()); + + foreach(node_get_types('names') as $type => $value) { + if(_premium_node($type)) { + $is_premium[$type] = $type; + } else { + $is_premium[$type] = 0; + } + } + + $form['premium_node_types'] = array( + '#type' => 'checkboxes', + '#options' => node_get_types('names'), + '#title' => t('Node Types'), + '#default_value' => $is_premium, + ); + + $form['premium_bulk_update'] = array( + '#type' => 'checkbox', + '#title' => t('Make existing nodes premium'), + '#description' => t('Checking this box will update all existing nodes of the types selected above with the current premium settings.'), + ); + // timeframe for premium + update existing nodes $form['premium_mode'] = array( '#type' => 'radios', @@ -172,20 +194,51 @@ function premium_settings() { return system_settings_form($form); } +/** + * Save premium-ness as set on admin/settings/premium to each type + */ +function premium_settings_save($form_id, $form_values) { + $types = $form_values["premium_node_types"]; + + foreach($types as $type => $premium) { + $node_options = variable_get('node_options_' . $type, array()); + if (in_array("premium", $node_options)) { + $premium_key = array_search("premium", $node_options); + unset($node_options[$premium_key]); + } + if ($types[$type]) { + $node_options = array_merge($node_options, array("premium")); + $premium_types[] = "'$types[$type]'"; + } + variable_set('node_options_' . $type, $node_options); + } + + if ($form_values["premium_bulk_update"]) { + $types = implode(',',$premium_types); + db_query("DELETE from {premium}"); + $result = db_query("SELECT nid, created from {node} WHERE type IN ($types)"); + while ($row = db_fetch_object($result)) { + $start_ts = $end_ts = 0; + $count = $form_values["premium_time_count"]; + $unit = $form_values["premium_unit_count"]; + $mode = $form_values["premium_mode"]; + _premium_offset($row->created, $start_ts, $end_ts, $mode, $count, $unit); + db_query('INSERT INTO {premium} VALUES (%d, %d, %d)', + $row->nid, $start_ts, $end_ts); + } + } +} /** * Calculate time offset for auto-aging / auto-archiving */ -function _premium_offset($ts, &$start_ts, &$end_ts, $mode, $count, $unitnit) { - $c = variable_get('premium_time_count', 2); - $unit = variable_get('premium_time_unit', 'W'); - $ts = $node->created; - +function _premium_offset($ts, &$start_ts, &$end_ts, $mode, $count, $unit) { + switch ($mode) { case 'archive' : // public first, premium after awhile $start_ts = mktime( - date('H', $ts)+($unit == 'H')*$count, 0, 0, + date('H', $ts)+($unit=='H')*$count, 0, 0, date('m', $ts)+($unit=='M')*$count, date('d', $ts)+($unit=='D')*$count+($unit=='W')*$count*7, date('y', $ts)+($unit=='Y')*$count