? .DS_Store
? affiliates.336656.1.patch
Index: affiliates.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/affiliates/Attic/affiliates.module,v
retrieving revision 1.1.4.5.2.2
diff -r1.1.4.5.2.2 affiliates.module
13c13,18
< define('AFFILIATE_PERIOD_INTERVAL',       'affiliate_period_interval');
---
> define('AFFILIATE_TOP_USERS_PERIOD_INTERVAL',       'affiliate_top_users_period_interval');
> define('AFFILIATE_TOP_CLIMBERS_PAGE',        'affiliate_top_climbers_page');
> define('AFFILIATE_TOP_CLIMBERS_BLOCK',       'affiliate_top_climbers_block');
> define('AFFILIATE_TOP_CLIMBERS_COUNT_PAGE',  'affiliate_top_climbers_count_page');
> define('AFFILIATE_TOP_CLIMBERS_COUNT_BLOCK', 'affiliate_top_climbers_count_block');
> define('AFFILIATE_TOP_CLIMBERS_PERIOD_INTERVAL',       'affiliate_top_climbers_period_interval');
23,24d27
<     case 'admin/settings/affiliates':
<       return t('<p>$Revision: 1.1.4.5.2.2 $ $Date: 2008/10/24 22:06:52 $</p>A module that allows affiliate click-throughs to be tracked.');
89a93,99
>      $items['affiliates/top_climbers'] = array(
>       'title' => t('Top Affiliate Climbers'),
>       'page callback' => 'affiliates_top_climbers',
>       'access arguments' => array('access content'),
>       'type' => MENU_HIDE,
>     );
>     
105,106c115,116
<   
<   $form['affiliates_settings']['revenue'] = array(
---
>  
>   $form['affiliates_settings']['configuration'] = array(
108,109c118,119
<     '#title' => t('Revenue'),
<     '#collapsible' => FALSE,
---
>     '#title' => t('Configuration'),
>     '#collapsible' => TRUE,
112,119d121
< 	
<   $form['affiliates_settings']['revenue'][AFFILIATE_HOMEPAGE_PROFILE] = array(
<     '#type'          => 'select',
<     '#title'         => t('Home Page Profile Field'),
<     '#default_value' => variable_get(AFFILIATE_HOMEPAGE_PROFILE, 0),
<     '#options'       => _get_profile_fields(),
<     '#description'   => t('Select the profile field that users put their home page in. This will be displayed in the top users block and page.'),
<   );
121c123
<   $form['affiliates_settings']['configuration'] = array(
---
>   $form['affiliates_settings']['configuration']['top_users'] = array(
123,125c125,127
<     '#title' => t('Configuration'),
<     '#collapsible' => FALSE,
<     '#collapsed' => FALSE,
---
>     '#title' => t('Top Users'),
>     '#collapsible' => TRUE,
>     '#collapsed' => TRUE,
128c130
<   $form['affiliates_settings']['configuration'][AFFILIATE_TOP_USERS_COUNT_PAGE] = array(
---
>   $form['affiliates_settings']['configuration']['top_users'][AFFILIATE_TOP_USERS_COUNT_PAGE] = array(
136c138
<   $form['affiliates_settings']['configuration'][AFFILIATE_TOP_USERS_COUNT_BLOCK] = array(
---
>   $form['affiliates_settings']['configuration']['top_users'][AFFILIATE_TOP_USERS_COUNT_BLOCK] = array(
144c146
<   $form['affiliates_settings']['configuration'][AFFILIATE_PERIOD_INTERVAL] = array(
---
>   $form['affiliates_settings']['configuration']['top_users'][AFFILIATE_TOP_USERS_PERIOD_INTERVAL] = array(
147c149
<     '#default_value' => variable_get(AFFILIATE_PERIOD_INTERVAL, 259200),
---
>     '#default_value' => variable_get(AFFILIATE_TOP_USERS_PERIOD_INTERVAL, 259200),
151a154,185
>   
>    $form['affiliates_settings']['configuration']['top_climbers'] = array(
>     '#type' => 'fieldset',
>     '#title' => t('Top Climbers'),
>     '#collapsible' => TRUE,
>     '#collapsed' => TRUE,
>   );
>   
>   $form['affiliates_settings']['configuration']['top_climbers'][AFFILIATE_TOP_CLIMBERS_COUNT_PAGE] = array(
>     '#type'          => 'select',
>     '#title'         => t('Top Climbers Count For Page'),
>     '#default_value' => variable_get(AFFILIATE_TOP_CLIMBERS_COUNT_PAGE, 5),
>     '#options'       => array(5 => 5, 10 => 10, 25 => 25, 50 => 50, 100 => 100), 
>     '#description'   => t('Number of users to show in top climbers page.'),
>   );
> 
>   $form['affiliates_settings']['configuration']['top_climbers'][AFFILIATE_TOP_CLIMBERS_COUNT_BLOCK] = array(
>     '#type'          => 'select',
>     '#title'         => t('Top Climbers Count For Block'),
>     '#default_value' => variable_get(AFFILIATE_TOP_CLIMBERS_COUNT_BLOCK, 5),
>     '#options'       => array(5 => 5, 10 => 10, 25 => 25, 50 => 50, 100 => 100), 
>     '#description'   => t('Number of users to show in top climbers block.'),
>   );
> 
>   $form['affiliates_settings']['configuration']['top_climbers'][AFFILIATE_TOP_CLIMBERS_PERIOD_INTERVAL] = array(
>     '#type'          => 'select',
>     '#title'         => t('Period for top climbers block and page'),
>     '#default_value' => variable_get(AFFILIATE_TOP_CLIMBERS_PERIOD_INTERVAL, 259200),
>     '#options'       => drupal_map_assoc(
>       array(86400, 172800, 259200, 259200, 432000, 604800, 1209600, 2592000), 'format_interval'),
>     '#description'   => t('How long will the "period" be as shown in the top climbers page.'),
>   );
173,174c207,208
<     '#collapsible' => FALSE,
<     '#collapsed' => FALSE,
---
>     '#collapsible' => TRUE,
>     '#collapsed' => TRUE,
179c213
<     '#title'         => t("User Text"),
---
>     '#title'         => t('User Text'),
183c217
<     '#description'   => t("Text to instruct users to copy/paste to earn affiliate credits."),
---
>     '#description'   => t('Text to instruct users to copy/paste to earn affiliate credits.'),
193a228,234
>   
>    $form['affiliates_settings']['revenue'] = array(
>     '#type' => 'fieldset',
>     '#title' => t('Revenue'),
>     '#collapsible' => TRE,
>     '#collapsed' => TRUE,
>   );	
194a236,243
>    $form['affiliates_settings']['revenue'][AFFILIATE_HOMEPAGE_PROFILE] = array(
>     '#type'          => 'select',
>     '#title'         => t('Home Page Profile Field'),
>     '#default_value' => variable_get(AFFILIATE_HOMEPAGE_PROFILE, 0),
>     '#options'       => _get_profile_fields(),
>     '#description'   => t('Select the profile field that users put their home page in. This will be displayed in the top users block and page.'),
>   );
>   
208a258
>     _get_top_climbers_page();
212a263,264
>     _get_top_climbers_block();
> 
531a584,645
> function _get_top_climbers_page() {
> 
>   $limit = variable_get(AFFILIATE_TOP_CLIMBERS_COUNT_PAGE, 5); 
>   $homepage_profile = variable_get(AFFILIATE_HOMEPAGE_PROFILE, ''); 
>   
>   $result=db_query('SELECT s.user_id, u.name , (s.period_points - s.previous_period_points) AS period_climb, pv.value AS homepage
>     FROM {affiliates_summary} s INNER JOIN {users} u ON u.uid = s.user_id 
>     LEFT JOIN {profile_values} pv ON (u.uid = pv.uid AND pv.fid = %d)
>     GROUP BY s.user_id
>     ORDER BY period_climb DESC LIMIT %d', $homepage_profile, $limit);
>     
>   $rank = 1;
>   while ($data = db_fetch_object($result)) {
>     $name = ($data->homepage) ? l($data->name, $data->homepage) : $data->name;
>     $rows[] = array(
>       array('data' => $rank++),
>       array('data' => $name),
>       array('data' => $data->period_climb),
>       array('data' => l('view profile', 'user/' . $data->user_id)),
>     );
>   }
> 
>   if (!$rows) {
>     $rows[] = array(array('data' => t('No clicks yet'), 'colspan' => '2'));
>   }
> 
>   $header = array('Rank', 'User', 'Climb', 'Profile');
> 
>   $output = theme('table', $header, $rows);
> 
>   cache_set(AFFILIATE_TOP_CLIMBERS_PAGE, $output);
> }
> 
> function _get_top_climbers_block() {
> 
>   $limit = variable_get(AFFILIATE_TOP_CLIMBERS_COUNT_BLOCK, 5);
>   $homepage_profile = variable_get(AFFILIATE_HOMEPAGE_PROFILE, '');
> 
>     $result=db_query('SELECT s.user_id, u.name , (s.period_points - s.previous_period_points) AS period_climb, pv.value AS homepage
>     FROM {affiliates_summary} s INNER JOIN {users} u ON u.uid = s.user_id 
>     LEFT JOIN {profile_values} pv ON (u.uid = pv.uid AND pv.fid = %d)
>     GROUP BY s.user_id
>     ORDER BY period_climb DESC LIMIT %d', $homepage_profile, $limit);
>     
>    while ($data = db_fetch_object($result)) {
>     $name = ($data->homepage) ? l($data->name, $data->homepage) : $data->name;
>     $rows[] = array(
>       array('data' => $name),
>       array('data' => $data->period_climb),
>       array('data' => l('view', 'user/' . $data->user_id)),
>     );
>   }
> 
>   if (!$rows) {
>     $rows[] = array(array('data' => t('No clicks yet'), 'colspan' => '3'));
>   } 
> 
>   $output = theme('table', array(), $rows); 
>   cache_set(AFFILIATE_TOP_CLIMBERS_BLOCK, $output);
> }
> 
> 
534c648,649
<   $period = time() - variable_get(AFFILIATE_PERIOD_INTERVAL, 86400);
---
>   $period = time() - variable_get(AFFILIATE_TOP_USERS_PERIOD_INTERVAL, 86400);
>   $last_period = time() -  (2 * variable_get(AFFILIATE_TOP_USERS_PERIOD_INTERVAL, 86400));
543a659
>     previous_period_points INT(10),
548c664
<     SELECT a.user_id, SUM(aa.points) as lp, 0
---
>     SELECT a.user_id, SUM(aa.points) as lp, 0, 0
566a683,696
>     
>     // Additional SQL wizardry to update the previous period
>   db_query("UPDATE {affiliates_summary} s,
>     (
>       SELECT a.user_id, SUM(aa.points) AS lp
>       FROM {affiliates} a, {affiliates_ads} aa
>       WHERE a.click_time >= %d
>       AND a.click_time < %d
>       AND a.ad_id = aa.ad_id
>       GROUP BY a.user_id
>       LIMIT %d
>       ) q
>     SET s.previous_period_points = lp
>     WHERE q.user_id = s.user_id", $last_period,$period, $limit);
652a783,788
> function affiliates_top_climbers() {
>   // This is generated in affiliates_cron() because it stands to be a pretty beefy query and won't scale otherwise.
>   $obj = cache_get(AFFILIATE_TOP_CLIMBERS_PAGE);
>   print theme('page', $obj->data);
> }
> 
720a857
>       $block[2]['info'] = t('Top Affiliate climbers For Period');
741,742c878,879
<           $block['content'] = $output;
<         break;
---
>          $block['content'] = $output;
>          break;
747c884
<           $output .= '<br/>' . t('Leading affiliates for the last @period', array('@period' => format_interval(variable_get(AFFILIATE_PERIOD_INTERVAL, 259200))));
---
>           $output .= '<br/>' . t('Leading affiliates for the last @period', array('@period' => format_interval(variable_get(AFFILIATE_TOP_USERS_PERIOD_INTERVAL, 259200))));
755,756c892,907
<           $block['content'] = $output;
<         break;
---
>          $block['content'] = $output;
>          break;
>          
>           case 2:
>           $block['subject'] = t('Top Affiliate Climbers For Period');
> 
>           $output .= '<br/>' . t('Leading affiliate climbers over the last two  @period periods', array('@period' => format_interval(variable_get(AFFILIATE_TOP_CLIMBERS_PERIOD_INTERVAL, 259200))));
>           if ($obj = cache_get(AFFILIATE_TOP_CLIMBERS_BLOCK)) {
>             $output .= '<br/>' . $obj->data;
>           }
>           else {
>             $output .= '<br/>' . t('No clicks yet.');
>           }
> 
>          $block['content'] = $output;
>          break;
