This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ function menu_main() { require_once('ui_main.php'); } function submenu_addnewlink() { require_once('ui_addnewlink.php'); } function submenu_linktrack() { require_once('ui_track.php'); } function add_mysetting() { add_menu_page('Affiliate Link Cloaking','Link Cloaking',8, __FILE__,'menu_main', get_bloginfo('url').'/wp-content/plugins/affiliate-link-cloaking/img/AffIcon_16.png' ); add_submenu_page(__FILE__,'Add New Link','Add New Link',8,'affiliate-link-cloaking/ui_addnewlink.php','submenu_addnewlink'); add_submenu_page(__FILE__,'Link Status','Link Status',8,'affiliate-link-cloaking/ui_track.php','submenu_linktrack'); } add_action('admin_menu', 'add_mysetting'); ///////////////////////////////////////////////////////////////////////////////////////////////// require_once('dbtable.php'); global $afflctable; $afflctable=new afflinkcloaking_dbtable(); /////////////////////////////////////////////////////////////////////////////////////////////// function afflc_autoshortlink($content) { global $afflctable; $alllinks = $afflctable->GetAllLinks(); foreach( $alllinks as $onelink ) { if ( 1 == $onelink->autoshortlink ) { $shortlink=get_bloginfo('url').'/'.$onelink->cloaklink; $content = str_replace( $onelink->afflink, $shortlink , $content ); } } return $content; } add_filter('the_content', 'afflc_autoshortlink'); /////////////////////////////////////////////////////////////////////////////////////////////// add_action('init', 'redirectandtrack'); function redirectandtrack() { global $afflctable; $tmp_clink=substr($_SERVER["REQUEST_URI"],1); $curlink=$afflctable->GetLinkByCloakLink($tmp_clink); if ( isset($curlink) ) { $tmp_visitorcookie = $tmp_clink.$_SERVER["REMOTE_ADDR"].time(); if ( !isset( $_COOKIE[$tmp_clink] ) ) { $cookiedomain = get_bloginfo('url'); $cookiedomain = str_ireplace('http://','',$cookiedomain); $cookiedomain = str_ireplace('www','',$cookiedomain); if ( substr( $cookiedomain,strlen($cookiedomain)-1,1 ) == '/' ) $cookiedomain = substr( $cookiedomain, 0, strlen($cookiedomain)-1 ); setcookie($tmp_clink, $tmp_visitorcookie, time()+3600*24*30 , '/' , $cookiedomain ); } else { $tmp_visitorcookie=$_COOKIE[$tmp_clink]; } $afflctable->AddTrack($_SERVER["REMOTE_ADDR"], $_SERVER["HTTP_REFERER"], $_SERVER["HTTP_USER_AGENT"], $tmp_visitorcookie, $curlink->id); $afflctable->AnalyseStatisticsDaily( time(), $curlink->id ); wp_redirect( $curlink->afflink, 302); exit; } } ///////////////////////////////////////////////////////////////////////////////////////////// add_filter('cron_schedules', 'afflinkcloaking_cron_add_maintaintime' ); register_activation_hook(__FILE__, 'afflinkcloaking_ActiveTableMaintain' ); add_action('afflinkcloaking_action_tablemaintain', 'afflinkcloaking_TableMaintain' ); register_deactivation_hook(__FILE__, 'afflinkcloaking_DeactiveTableMaintain' ); function afflinkcloaking_cron_add_maintaintime() { $schedules['maintain'] = array( 'interval' => 86400, 'display' => __('maintain') ); return $schedules; } function afflinkcloaking_ActiveTableMaintain() { if ( !wp_get_schedule('afflinkcloaking_action_tablemaintain') ) wp_schedule_event(time(), 'maintain', 'afflinkcloaking_action_tablemaintain'); } function afflinkcloaking_TableMaintain() { global $afflctable; $afflctable->MaintainDate(); } function afflinkcloaking_DeactiveTableMaintain() { wp_clear_scheduled_hook('afflinkcloaking_action_tablemaintain'); } ?>