| 1 |
<?php |
<?php |
| 2 |
// $Id: affiliates.module,v 1.1.4.5.2.15 2009/04/08 16:47:21 paulbooker Exp $ |
// $Id: affiliates.module,v 1.1.4.5.2.16 2009/04/16 08:53:30 paulbooker Exp $ |
| 3 |
|
|
| 4 |
// Portions Copyright 2006 http://2bits.com |
// Portions Copyright 2006 http://2bits.com |
| 5 |
define ('AFFILIATE_BUTTONS_DIRECTORY_RELATIVE_FILES', '/affiliates'); |
define ('AFFILIATE_BUTTONS_DIRECTORY_RELATIVE_FILES', '/affiliates'); |
| 21 |
define('AFFILIATE_CRON_INTERVAL', 'affiliate_cron_interval'); |
define('AFFILIATE_CRON_INTERVAL', 'affiliate_cron_interval'); |
| 22 |
define('AFFILIATE_INTRODUCTION', 'affiliate_introduction'); |
define('AFFILIATE_INTRODUCTION', 'affiliate_introduction'); |
| 23 |
define('AFFILIATE_USERPOINTS_TID', 'affiliate_userpoints_tid'); |
define('AFFILIATE_USERPOINTS_TID', 'affiliate_userpoints_tid'); |
| 24 |
|
define('AFFILIATE_DENIED_URI_REFERRERS', 'affiliate_denied_uri_referrers'); |
| 25 |
|
define('AFFILIATE_DENIED_IPS', 'affiliate_denied_ips'); |
| 26 |
|
define('AFFILIATE_DENIED_USERS', 'affiliate_denied_users'); |
| 27 |
|
|
| 28 |
function affiliates_help($section) { |
function affiliates_help($section) { |
| 29 |
switch ($section) { |
switch ($section) { |
| 238 |
array(300, 600, 1800, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800), 'format_interval'), |
array(300, 600, 1800, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800), 'format_interval'), |
| 239 |
'#description' => t('How often to refresh the top users data. Requires cron to be running at a more frequent rate than this value to really take effect.'), |
'#description' => t('How often to refresh the top users data. Requires cron to be running at a more frequent rate than this value to really take effect.'), |
| 240 |
); |
); |
| 241 |
|
|
| 242 |
|
$form['affiliates_settings']['spam'] = array( |
| 243 |
|
'#type' => 'fieldset', |
| 244 |
|
'#title' => t('Spam'), |
| 245 |
|
'#collapsible' => TRUE, |
| 246 |
|
'#collapsed' => TRUE, |
| 247 |
|
); |
| 248 |
|
|
| 249 |
|
$form['affiliates_settings']['spam'][AFFILIATE_DENIED_URI_REFERRERS] = array( |
| 250 |
|
'#type' => 'textarea', |
| 251 |
|
'#title' => t('Denied by referrer URI'), |
| 252 |
|
'#default_value' => variable_get(AFFILIATE_DENIED_URI_REFERRERS,""), |
| 253 |
|
'#size' => 70, |
| 254 |
|
'#rows' => 4, |
| 255 |
|
'#description' => t('List all referral URI that will not be allocated affiliate points'), |
| 256 |
|
); |
| 257 |
|
|
| 258 |
|
$form['affiliates_settings']['spam'][AFFILIATE_DENIED_IPS] = array( |
| 259 |
|
'#type' => 'textarea', |
| 260 |
|
'#title' => t('Denied by IP'), |
| 261 |
|
'#default_value' => variable_get(AFFILIATE_DENIED_IPS,""), |
| 262 |
|
'#size' => 70, |
| 263 |
|
'#rows' => 4, |
| 264 |
|
'#description' => t('List all IP that will not be allocated affiliate points'), |
| 265 |
|
); |
| 266 |
|
|
| 267 |
|
$form['affiliates_settings']['spam'][AFFILIATE_DENIED_USERS] = array( |
| 268 |
|
'#type' => 'textarea', |
| 269 |
|
'#title' => t('Denied by User'), |
| 270 |
|
'#default_value' => variable_get(AFFILIATE_DENIED_USERS,""), |
| 271 |
|
'#size' => 70, |
| 272 |
|
'#rows' => 4, |
| 273 |
|
'#description' => t('List all users that will not be allocated affiliate points'), |
| 274 |
|
); |
| 275 |
|
|
| 276 |
$form['affiliates_settings']['content'] = array( |
$form['affiliates_settings']['content'] = array( |
| 277 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 964 |
$affiliates['#title'] = t('Affiliates'); |
$affiliates['#title'] = t('Affiliates'); |
| 965 |
$affiliates['#weight'] = 8; |
$affiliates['#weight'] = 8; |
| 966 |
$account->content['Affiliates'] = $affiliates; |
$account->content['Affiliates'] = $affiliates; |
| 967 |
|
|
| 968 |
|
if (user_access('administer affiliates')) { |
| 969 |
|
$result = db_query("SELECT DISTINCT referer |
| 970 |
|
FROM {affiliates} |
| 971 |
|
WHERE user_id = %d |
| 972 |
|
ORDER BY id DESC |
| 973 |
|
LIMIT 100", $account->uid); |
| 974 |
|
while ($data = db_fetch_object($result)) { |
| 975 |
|
$referrers .= $data->referer . "\n"; |
| 976 |
|
} |
| 977 |
|
$referrers = array( |
| 978 |
|
'#type' => 'textarea', |
| 979 |
|
'#title' => t('Recent referrers'), |
| 980 |
|
'#value' => $referrers, |
| 981 |
|
'#size' => 70, |
| 982 |
|
'#rows' => 4, |
| 983 |
|
); |
| 984 |
|
$account->content['Affiliates'][] = $referrers; |
| 985 |
|
} |
| 986 |
} |
} |
| 987 |
|
break; |
| 988 |
|
case 'form': |
| 989 |
|
if (user_access('administer affiliates')) { |
| 990 |
|
if ($category == 'account') { |
| 991 |
|
$form['affiliates'] = array( |
| 992 |
|
'#type' => 'fieldset', |
| 993 |
|
'#title' => t('Affiliate settings'), |
| 994 |
|
'#collapsible' => FALSE, |
| 995 |
|
'#weight' => 4, |
| 996 |
|
'#tree' => FALSE, |
| 997 |
|
); |
| 998 |
|
$form['affiliates']['delete_affiliate_points'] = array( |
| 999 |
|
'#type' => 'checkbox', |
| 1000 |
|
'#title' => t('Delete affiliate points for this user'), |
| 1001 |
|
'#description' => t('To delete all affiliate points for this user, click this checkbox and then click the save button at the bottom of this page.'), |
| 1002 |
|
); |
| 1003 |
|
return $form; |
| 1004 |
|
} |
| 1005 |
|
} |
| 1006 |
|
break; |
| 1007 |
|
case 'update': |
| 1008 |
|
if ($edit['delete_affiliate_points']) { |
| 1009 |
|
affiliates_delete_points($account->uid); |
| 1010 |
|
} |
| 1011 |
|
break; |
| 1012 |
|
case 'delete': |
| 1013 |
|
affiliates_delete_points($account->uid); |
| 1014 |
|
break; |
| 1015 |
} |
} |
| 1016 |
} |
} |
| 1017 |
|
|
| 1018 |
|
function affiliates_delete_points($user_id) { |
| 1019 |
|
db_query('DELETE FROM {affiliates} WHERE user_id=%d', $user_id); |
| 1020 |
|
$affiliate_records_deleted = db_affected_rows(); |
| 1021 |
|
if ($affiliate_records_deleted) { |
| 1022 |
|
//affiliate records deleted |
| 1023 |
|
$account = user_load(array('uid' => $user_id)); |
| 1024 |
|
drupal_set_message(t("%username's affiliate records has been deleted.", array('%username' => $account->name))); |
| 1025 |
|
} |
| 1026 |
|
} |
| 1027 |
|
|
| 1028 |
function affiliates_list() { |
function affiliates_list() { |
| 1029 |
global $user, $base_url; |
global $user, $base_url; |
| 1030 |
$output = "<br/>" . nl2br(variable_get(AFFILIATE_INTRODUCTION,'')) . "<br/>"; |
$output = "<br/>" . nl2br(variable_get(AFFILIATE_INTRODUCTION,'')) . "<br/>"; |
| 1092 |
print theme('page', $obj->data); |
print theme('page', $obj->data); |
| 1093 |
} |
} |
| 1094 |
|
|
| 1095 |
|
function affiliates_click_denied() { |
| 1096 |
|
global $user; |
| 1097 |
|
$denied_users = explode(",", variable_get(AFFILIATE_DENIED_USERS,'')); |
| 1098 |
|
if (in_array($user->name, $denied_users)) return TRUE; |
| 1099 |
|
$ip = ip_address(); |
| 1100 |
|
$denied_ips = explode(",", variable_get(AFFILIATE_DENIED_IPS,'')); |
| 1101 |
|
if (in_array($ip, $denied_ips)) return TRUE; |
| 1102 |
|
$denied_uri_referrers = explode(",", variable_get(AFFILIATE_DENIED_URI_REFERRERS,'')); |
| 1103 |
|
foreach ($denied_uri_referrers as $referrer) { |
| 1104 |
|
if (strstr($_SERVER['HTTP_REFERER'], $referrer)) return TRUE; |
| 1105 |
|
} |
| 1106 |
|
$timeout_flag = _check_timeout_query(); |
| 1107 |
|
if ($timeout_flag) return TRUE; |
| 1108 |
|
return FALSE; |
| 1109 |
|
} |
| 1110 |
|
|
| 1111 |
function affiliates_click() { |
function affiliates_click() { |
| 1112 |
$cookie_value = md5(microtime()); |
$cookie_value = md5(microtime()); |
| 1113 |
$timeout_flag = true; |
$timeout_flag = true; |
| 1115 |
$uid = (int)arg(1); |
$uid = (int)arg(1); |
| 1116 |
$ad_id = (int)arg(2); |
$ad_id = (int)arg(2); |
| 1117 |
|
|
| 1118 |
$timeout_flag = _check_timeout_query(); |
$affiliates_click_denied = affiliates_click_denied(); |
| 1119 |
//If there's no cookie, proceed. |
//If there's no cookie, proceed. |
| 1120 |
if (!$_COOKIE['aff']) { |
if (!$_COOKIE['aff']) { |
| 1121 |
setcookie('aff', $cookie_value, time() + 86400); |
setcookie('aff', $cookie_value, time() + 86400); |
| 1122 |
} |
} |
| 1123 |
|
|
| 1124 |
if ((!$timeout_flag) && user_access('affiliate click')) { |
if ((!$affiliates_click_denied) && user_access('affiliate click')) { |
| 1125 |
//Only log the hit if it looks like this isn't a cheater and the user has permissions. |
//Only log the hit if it looks like this isn't a cheater and the user has permissions. |
| 1126 |
db_query("INSERT INTO {affiliates} ( |
db_query("INSERT INTO {affiliates} ( |
| 1127 |
user_id, cookie_id, ip, referer, ad_id, click_time) |
user_id, cookie_id, ip, referer, ad_id, click_time) |