| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: affiliates.module,v 1.1.4.5.2.5 2009/01/01 16:30:41 kbahey Exp $ |
| 3 |
|
|
| 4 |
// Portions Copyright 2006 http://2bits.com |
// Portions Copyright 2006 http://2bits.com |
| 5 |
define ('AFFILIATE_BUTTONS_DIRECTORY_RELATIVE_FILES', '/images/affiliates'); |
define ('AFFILIATE_BUTTONS_DIRECTORY_RELATIVE_FILES', '/affiliates'); |
| 6 |
|
|
| 7 |
define('AFFILIATE_HOMEPAGE_PROFILE', 'affiliate_homepage_profile'); |
define('AFFILIATE_HOMEPAGE_PROFILE', 'affiliate_homepage_profile'); |
| 8 |
define('AFFILIATE_BLOCK_TEXT', 'affiliate_block_text'); |
define('AFFILIATE_BLOCK_TEXT', 'affiliate_block_text'); |
| 9 |
define('AFFILIATE_STATS_TEXT', 'affiliate_stats_text'); |
define('AFFILIATE_STATS_TEXT', 'affiliate_stats_text'); |
| 10 |
define('AFFILIATE_TOP_USERS_PAGE', 'affiliate_top_users_page'); |
define('AFFILIATE_TOP_USERS_PAGE', 'affiliate_top_users_page'); |
| 11 |
define('AFFILIATE_TOP_USERS_BLOCK', 'affiliate_top_users_block'); |
define('AFFILIATE_TOP_USERS_BLOCK', 'affiliate_top_users_block'); |
| 12 |
define('AFFILIATE_TOP_USERS_COUNT_PAGE', 'affiliate_top_users_count_page'); |
define('AFFILIATE_TOP_USERS_COUNT_PAGE', 'affiliate_top_users_count_page'); |
| 13 |
define('AFFILIATE_TOP_USERS_COUNT_BLOCK', 'affiliate_top_users_count_block'); |
define('AFFILIATE_TOP_USERS_COUNT_BLOCK', 'affiliate_top_users_count_block'); |
| 14 |
define('AFFILIATE_TOP_USERS_PERIOD_INTERVAL', 'affiliate_top_users_period_interval'); |
define('AFFILIATE_TOP_USERS_PERIOD_INTERVAL', 'affiliate_top_users_period_interval'); |
| 15 |
define('AFFILIATE_TOP_CLIMBERS_PAGE', 'affiliate_top_climbers_page'); |
define('AFFILIATE_TOP_CLIMBERS_PAGE', 'affiliate_top_climbers_page'); |
| 16 |
define('AFFILIATE_TOP_CLIMBERS_BLOCK', 'affiliate_top_climbers_block'); |
define('AFFILIATE_TOP_CLIMBERS_BLOCK', 'affiliate_top_climbers_block'); |
| 17 |
define('AFFILIATE_TOP_CLIMBERS_COUNT_PAGE', 'affiliate_top_climbers_count_page'); |
define('AFFILIATE_TOP_CLIMBERS_COUNT_PAGE', 'affiliate_top_climbers_count_page'); |
| 18 |
define('AFFILIATE_TOP_CLIMBERS_COUNT_BLOCK', 'affiliate_top_climbers_count_block'); |
define('AFFILIATE_TOP_CLIMBERS_COUNT_BLOCK', 'affiliate_top_climbers_count_block'); |
| 19 |
define('AFFILIATE_TOP_CLIMBERS_PERIOD_INTERVAL', 'affiliate_top_climbers_period_interval'); |
define('AFFILIATE_TOP_CLIMBERS_PERIOD_INTERVAL', 'affiliate_top_climbers_period_interval'); |
| 20 |
define('AFFILIATE_CLICK_IGNORE_INTERVAL', 'affiliate_click_ignore_interval'); |
define('AFFILIATE_CLICK_IGNORE_INTERVAL', 'affiliate_click_ignore_interval'); |
| 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'), |
| 24 |
|
|
| 25 |
function affiliates_help($section) { |
function affiliates_help($section) { |
| 26 |
switch ($section) { |
switch ($section) { |
| 31 |
} |
} |
| 32 |
|
|
| 33 |
function affiliates_perm() { |
function affiliates_perm() { |
| 34 |
return array('administer affiliates', 'view own affiliate stats', 'affiliate click'); |
//The view own stats permission isn't currently used. Leaving it here for future reference though. |
| 35 |
|
// return array('administer affiliates', 'view own affiliate stats', 'affiliate click'); |
| 36 |
|
return array('administer affiliates', 'affiliate click'); |
| 37 |
} |
} |
| 38 |
|
|
| 39 |
function affiliates_menu() { |
function affiliates_menu() { |
| 263 |
$form['affiliates_settings']['revenue'] = array( |
$form['affiliates_settings']['revenue'] = array( |
| 264 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 265 |
'#title' => t('Revenue'), |
'#title' => t('Revenue'), |
| 266 |
'#collapsible' => TRE, |
'#collapsible' => TRUE, |
| 267 |
'#collapsed' => TRUE, |
'#collapsed' => TRUE, |
| 268 |
); |
); |
| 269 |
|
|
| 373 |
'#default_value' => $affiliate->points, |
'#default_value' => $affiliate->points, |
| 374 |
'#size' => 3, |
'#size' => 3, |
| 375 |
'#maxlength' => 3, |
'#maxlength' => 3, |
| 376 |
|
'#required' => TRUE, |
| 377 |
); |
); |
| 378 |
|
|
| 379 |
$form['affiliate']['type'] = array( |
$form['affiliate']['type'] = array( |
| 397 |
'#type' => 'file', |
'#type' => 'file', |
| 398 |
'#title' => t('Upload a button'), |
'#title' => t('Upload a button'), |
| 399 |
'#size' => 40, |
'#size' => 40, |
| 400 |
'#description' => t('Please upload a button.') |
'#description' => t('Please upload a button.<br /><br /><b>OR</b> specify the button URL:') |
| 401 |
); |
); |
| 402 |
|
|
| 403 |
$form['affiliate']['anchor'] = array( |
$form['affiliate']['anchor'] = array( |
| 406 |
'#default_value' => $affiliate->anchor, |
'#default_value' => $affiliate->anchor, |
| 407 |
'#size' => 40, |
'#size' => 40, |
| 408 |
'#maxlength' => 120, |
'#maxlength' => 120, |
| 409 |
'#description' => t('If your button is hosted elsewhere, enter the URL here.') |
'#description' => t('If your button is hosted elsewhere, enter the URL here.') |
| 410 |
); |
); |
| 411 |
|
|
| 412 |
$form['affiliate']['redirect'] = array( |
$form['affiliate']['redirect'] = array( |
| 415 |
'#default_value' => $affiliate->redirect, |
'#default_value' => $affiliate->redirect, |
| 416 |
'#size' => 40, |
'#size' => 40, |
| 417 |
'#maxlength' => 80, |
'#maxlength' => 80, |
| 418 |
|
'#description' => t('If no redirect is specified, the home page will be used.') |
| 419 |
); |
); |
| 420 |
|
|
| 421 |
$form['affiliate']['order_by'] = array( |
$form['affiliate']['order_by'] = array( |
| 424 |
'#default_value' => $affiliate->order_by, |
'#default_value' => $affiliate->order_by, |
| 425 |
'#size' => 10, |
'#size' => 10, |
| 426 |
'#maxlength' => 5, |
'#maxlength' => 5, |
| 427 |
|
'#required' => TRUE, |
| 428 |
); |
); |
| 429 |
|
|
| 430 |
$form['affiliate']['status'] = array( |
$form['affiliate']['status'] = array( |
| 469 |
if (!is_numeric($form_values['order_by'])) { |
if (!is_numeric($form_values['order_by'])) { |
| 470 |
form_set_error('', t('You must enter a numeric order value')); |
form_set_error('', t('You must enter a numeric order value')); |
| 471 |
} |
} |
| 472 |
if (!$form_values['redirect']) { |
// if (!$form_values['redirect']) { |
| 473 |
form_set_error('', t('You must enter a redirect url')); |
// form_set_error('', t('You must enter a redirect url')); |
| 474 |
} |
// } |
| 475 |
if (!$form_values['status']) { |
if (!$form_values['status']) { |
| 476 |
form_set_error('', t('You must select a valid status')); |
form_set_error('', t('You must select a valid status')); |
| 477 |
} |
} |
| 1005 |
setcookie('aff', $cookie_value, time() + 86400); |
setcookie('aff', $cookie_value, time() + 86400); |
| 1006 |
} |
} |
| 1007 |
|
|
| 1008 |
if (!$timeout_flag) { |
if ((!$timeout_flag) && user_access('affiliate click')) { |
| 1009 |
//Only log the hit if it looks like this isn't a cheater. |
//Only log the hit if it looks like this isn't a cheater and the user has permissions. |
| 1010 |
db_query("INSERT INTO {affiliates} ( |
db_query("INSERT INTO {affiliates} ( |
| 1011 |
user_id, cookie_id, ip, referer, ad_id, click_time) |
user_id, cookie_id, ip, referer, ad_id, click_time) |
| 1012 |
VALUES |
VALUES |
| 1013 |
(%d, '%s', '%s', '%s', %d, %d)", |
(%d, '%s', '%s', '%s', %d, %d)", |
| 1014 |
$uid, $cookie_value, $_SERVER['REMOTE_ADDR'], filter_xss($_SERVER['HTTP_REFERER']), $ad_id, time()); |
$uid, $cookie_value, $_SERVER['REMOTE_ADDR'], filter_xss($_SERVER['HTTP_REFERER']), $ad_id, time()); |
| 1015 |
|
|
| 1016 |
|
// Record it in the userpoints |
| 1017 |
|
if (module_exists('userpoints')) { |
| 1018 |
|
$points = (int)db_result(db_query("SELECT points FROM {affiliates_ads} WHERE ad_id = %d", $ad_id)); |
| 1019 |
|
$params = array( |
| 1020 |
|
'points' => $points, |
| 1021 |
|
'uid' => $uid, |
| 1022 |
|
'operation' => 'affilate click', |
| 1023 |
|
'tid' => variable_get(AFFILIATE_USERPOINTS_TID, 0), |
| 1024 |
|
'reference' => 'affiliates' |
| 1025 |
|
); |
| 1026 |
|
userpoints_userpointsapi($params); |
| 1027 |
|
} |
| 1028 |
} |
} |
| 1029 |
|
|
| 1030 |
$redirect = db_result(db_query("SELECT redirect FROM {affiliates_ads} WHERE ad_id = %d", $ad_id)); |
$redirect = db_result(db_query("SELECT redirect FROM {affiliates_ads} WHERE ad_id = %d", $ad_id)); |
| 1031 |
|
|
|
// Record it in the userpoints |
|
|
if (module_exists('userpoints')) { |
|
|
$points = (int)db_result(db_query("SELECT points FROM {affiliates_ads} WHERE ad_id = %d", $ad_id)); |
|
|
userpoints_userpointsapi('points', $points, $uid, "affiliates"); |
|
|
} |
|
|
|
|
| 1032 |
if ($redirect) { |
if ($redirect) { |
| 1033 |
header("Location: " . $redirect); |
header("Location: " . $redirect); |
| 1034 |
} |
} |
| 1039 |
} |
} |
| 1040 |
|
|
| 1041 |
function affiliates_userpoints($op, $points = 0, $uid = 0, $event = 0) { |
function affiliates_userpoints($op, $points = 0, $uid = 0, $event = 0) { |
| 1042 |
|
global $base_url; |
| 1043 |
switch($op) { |
switch($op) { |
| 1044 |
case 'setting': |
case 'setting': |
| 1045 |
$group = 'affiliates'; |
$group = 'affiliates'; |
| 1047 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 1048 |
'#collapsible' => TRUE, |
'#collapsible' => TRUE, |
| 1049 |
'#collapsed' => TRUE, |
'#collapsed' => TRUE, |
| 1050 |
'#title' => t('%Points for nodevote', userpoints_translation()), |
'#title' => t('!Points for Affiliates', userpoints_translation()), |
| 1051 |
); |
); |
| 1052 |
|
|
| 1053 |
$form[$group][AFFILIATES_USERPOINTS] = array( |
//This form item is commented out as the value does not modify anything currently. It could be used later on as a modifier. |
| 1054 |
'#type' => 'textfield', |
// $form[$group][AFFILIATE_USERPOINTS] = array( |
| 1055 |
'#title' => t('%Points for affiliate click', userpoints_translation()), |
// '#type' => 'textfield', |
| 1056 |
'#default_value' => variable_get(AFFILIATES_USERPOINTS, 1), |
// '#title' => t('!Points for Affiliates clicks', userpoints_translation()), |
| 1057 |
'#size' => 5, |
// '#default_value' => variable_get(AFFILIATE_USERPOINTS, 1), |
| 1058 |
'#maxlength' => 5, |
// '#size' => 5, |
| 1059 |
|
// '#maxlength' => 5, |
| 1060 |
|
// ); |
| 1061 |
|
|
| 1062 |
|
$form[$group][AFFILIATE_USERPOINTS_TID] = array( |
| 1063 |
|
'#type' => 'select', |
| 1064 |
|
'#title' => t('Category'), |
| 1065 |
|
'#default_value' => variable_get(AFFILIATE_USERPOINTS_TID, 0), |
| 1066 |
|
'#options' => userpoints_get_categories(), |
| 1067 |
|
'#description' => t('Points for Affilates button click-throughs will be assigned to this category. You can modify what categories are available by modifying the <a href="!url"><b>Userpoints taxonomy</b></a>. Points values are set in the <a href="' . $base_url . '/affiliates/admin"><b>Affiliates Admin</b></a> section on a per button basis.', |
| 1068 |
|
array('!url' => url('admin/content/taxonomy/'. variable_get(USERPOINTS_CATEGORY_DEFAULT_VID, '')))), |
| 1069 |
); |
); |
| 1070 |
|
|
| 1071 |
return $form; |
return $form; |
| 1072 |
} |
} |
| 1073 |
} |
} |
| 1074 |
|
|
| 1075 |
function affiliates_block($op = 'list', $delta = 0) { |
function affiliates_block($op = 'list', $delta = 0) { |
| 1076 |
global $user; |
global $user, $base_url; |
| 1077 |
|
|
| 1078 |
switch($op) { |
switch($op) { |
| 1079 |
case 'list': |
case 'list': |
| 1094 |
else { |
else { |
| 1095 |
$output .= '<br/>' . t('No clicks yet.'); |
$output .= '<br/>' . t('No clicks yet.'); |
| 1096 |
} |
} |
| 1097 |
$output .= "<br/><a href=\"/affiliates/top_users\">more »</a>"; |
$output .= "<br/><a href=\"" . $base_url . "/affiliates/top_users\">more »</a>"; |
| 1098 |
|
|
| 1099 |
if ($user->uid) { |
if ($user->uid) { |
| 1100 |
$output .= "<br/><br/>You have " . _get_user_points($user->uid) . " points."; |
$output .= "<br/><br/>You have " . _get_user_points($user->uid) . " points."; |