Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
We need this to be done, so may be it will be useful for someone else as well.
Thanks,
Gennady
<?php
//This is add-on to Drupal's User Referral module - http://drupal.org/project/referral
//to generate referral links and have them available for the email blast
//links are saved into users table as well as printed on the screen
//1) copy this code to newly created referral_links.php in your Drupal root
//2) change path to your Drupal root just few lines down in the code: chdir('/WebSites/www.drupal.my/');
//3) add new column to users table in the database: referral_link, varchar, 11
//4) go to the page in your browser - this will run the script: http://www.drupal.my/referral_links.php
define('REFERRAL_HEX_START', 7);
define('REFERRAL_HEX_LENGTH', 4);
//set the working directory to your Drupal root
chdir('/WebSites/www.drupal.my/');
//require the bootstrap include
require_once './includes/bootstrap.inc';
//Load Drupal
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//(loads everything, but doesn't render anything)
print "Generating Referral Links for All Users: ";
print '<table><tr><td>uid</td><td>referral_link</td></tr>';
$result = db_query('SELECT uid FROM users order by uid');
while ($data = db_fetch_object($result)) {
$referral_uid = $data->uid;
print '<tr><td>'.$referral_uid.'</td>';
$referral_link =_referral_uid2ref($referral_uid);
print '<td>'.$referral_link.'</td></tr>'; //8 hexadigits in my case
//insert link into added to users column: referral_link, varchar, 11
db_query("UPDATE users SET referral_link = '%s' WHERE uid = %d", $referral_link, $referral_uid);
}
print '</table>';
function _referral_uid2ref($uid) {
if ($uid) {
if (is_numeric($uid)) {
$ref = dechex(_referral_hex_seed() + $uid);
return $ref;
}
}
return FALSE;
}
function _referral_hex_seed() {
global $base_url;
$seed = hexdec(_referral_asc2hex(substr($base_url, REFERRAL_HEX_START, REFERRAL_HEX_LENGTH)));
return $seed;
}
?>