Hi
Is there a way to custom Addtoany module or other share module, to share links with affiliate code?
Thanks
Omer
Omer, AddtoAny module doesn't have an API to change the links, so you would have to edit the code in the module. If you look at line 162, there is this:
if (is_object($node)) { $link_name = rawurlencode($node->title); $link_url = rawurlencode(url('node/'. $node->nid, array('absolute' => 1) )); } else { // Front page $link_name = rawurlencode(variable_get('page_title_front', variable_get('site_name', ''))); $link_url = rawurlencode(url('', array('absolute' => 1))); }
If you change this code to the following, it should work:
global $user; // Check if the user can act as an affiliate $aff_query = (user_access('act as affiliate')) ? "?a=". $user->uid : '';
if (is_object($node)) { $link_name = rawurlencode($node->title); $link_url = rawurlencode(url('node/'. $node->nid, array('absolute' => 1, 'query' => $aff_query) )); } else { // Front page $link_name = rawurlencode(variable_get('page_title_front', variable_get('site_name', ''))); $link_url = rawurlencode(url('', array('absolute' => 1, 'query' => $aff_query))); }
The code just checks if the user can be an affiliate, and if so, adds the aff string to the url.
Sincerely, Leighton Whiting
Omer,
AddtoAny module doesn't have an API to change the links, so you would have to edit the code in the module. If you look at line 162, there is this:
if (is_object($node)) {
$link_name = rawurlencode($node->title);
$link_url = rawurlencode(url('node/'. $node->nid, array('absolute' => 1) ));
} else { // Front page
$link_name = rawurlencode(variable_get('page_title_front', variable_get('site_name', '')));
$link_url = rawurlencode(url('', array('absolute' => 1)));
}
If you change this code to the following, it should work:
global $user;
// Check if the user can act as an affiliate
$aff_query = (user_access('act as affiliate')) ? "?a=". $user->uid : '';
if (is_object($node)) {
$link_name = rawurlencode($node->title);
$link_url = rawurlencode(url('node/'. $node->nid, array('absolute' => 1, 'query' => $aff_query) ));
} else { // Front page
$link_name = rawurlencode(variable_get('page_title_front', variable_get('site_name', '')));
$link_url = rawurlencode(url('', array('absolute' => 1, 'query' => $aff_query)));
}
The code just checks if the user can be an affiliate, and if so, adds the aff string to the url.
Sincerely,
Leighton Whiting