AmazoLinkenator Settings'; array_unshift($links, $settings_link); return $links; } $plugin = plugin_basename(__FILE__); add_filter("plugin_action_links_$plugin", 'AmazoLinkenator_settings_link' ); // build the class for all of this class AmazoLinkenator_Settings_Page { // Holds the values to be used in the fields callbacks private $options; // start your engines! public function __construct() { add_action( 'admin_menu', array( $this, 'AmazoLinkenator_add_plugin_page' ) ); add_action( 'admin_init', array( $this, 'AmazoLinkenator_page_init' ) ); } // add options page public function AmazoLinkenator_add_plugin_page() { // This page will be under "Settings" add_options_page( 'AmazoLinkenator Settings Admin', 'AmazoLinkenator Settings', 'manage_options', 'AmazoLinkenator_settings', array( $this, 'AmazoLinkenator_create_admin_page' ) ); } // options page callback public function AmazoLinkenator_create_admin_page() { // Set class property $this->options = get_option( 'AZLNK_options' ); ?>
'input', 'fieldsize' => '50', 'fieldmax' => '50') ); add_settings_field( 'AZLNK_enable_affiliator_posts', 'Enable AmazoLinkenator for post/page content?', array( $this, 'AZLNK_enable_affiliator_posts_callback' ), 'AmazoLinkenator_setting_admin', 'AmazoLinkenator_setting_section_id', // Section array('fieldtype' => 'checkbox', 'fieldsize' => null, 'fieldmax' => null ) ); add_settings_field( 'AZLNK_AZLNK_enable_comments', 'Enable AmazoLinkenator for Comments?', array( $this, 'AZLNK_enable_comments_callback' ), 'AmazoLinkenator_setting_admin', 'AmazoLinkenator_setting_section_id', // Section array('fieldtype' => 'checkbox', 'fieldsize' => null, 'fieldmax' => null ) ); add_settings_field( 'AZLNK_auto_shorten', 'Enable automatic shortening of the URL? ', array( $this, 'AZLNK_auto_shorten_callback' ), 'AmazoLinkenator_setting_admin', 'AmazoLinkenator_setting_section_id', // Section array('fieldtype' => 'text', 'fieldsize' => null, 'fieldmax' => null ) ); add_settings_field( 'AZLNK_bitly_token', 'Enter your Bit.ly Generic Access Token', array( $this, 'AZLNK_bitly_token_callback' ), 'AmazoLinkenator_setting_admin', 'AmazoLinkenator_setting_section_id', // Section array('fieldtype' => 'input', 'fieldsize' => '50', 'fieldmax' => '50') ); add_settings_field( 'AZLNK_donate_flag', 'Check to donate', array( $this, 'AZLNK_donate_flag_callback' ), 'AmazoLinkenator_setting_admin', 'AmazoLinkenator_setting_section_id', // Section array('fieldtype' => 'input', 'fieldsize' => '50', 'fieldmax' => '50') ); add_settings_field( 'AZLNK_donate_counter', 'Affiliate Donated Counter', array( $this, 'AZLNK_donate_counter_callback' ), 'AmazoLinkenator_setting_admin', 'AmazoLinkenator_setting_section_id', // Section array('fieldtype' => 'input', 'fieldsize' => '50', 'fieldmax' => '50') ); add_settings_field( 'AZLNK_affiliate_counter', 'Affiliate Links Inserted', array( $this, 'AZLNK_affiliate_counter_callback' ), 'AmazoLinkenator_setting_admin', 'AmazoLinkenator_setting_section_id', // Section array('fieldtype' => 'input', 'fieldsize' => '50', 'fieldmax' => '50') ); } // sanitize the settings fields on submit // @param array $input Contains all settings fields as array keys public function AmazoLinkenator_sanitize( $input ) { global $AZLNK_affiliate_counter; $new_input = array(); if( isset( $input['AZLNK_affiliate_key'] ) ) $new_input['AZLNK_affiliate_key'] = sanitize_text_field( $input['AZLNK_affiliate_key'] ); if( isset( $input['AZLNK_enable_comments'] ) ) $new_input['AZLNK_enable_comments'] = "1"; if( isset( $input['AZLNK_enable_affiliator_posts'] ) ) $new_input['AZLNK_enable_affiliator_posts'] = "1"; if( isset( $input['AZLNK_auto_shorten'] ) ) $new_input['AZLNK_auto_shorten'] = "1"; if( isset( $input['AZLNK_donate_flag'] ) ) $new_input['AZLNK_donate_flag'] = "1"; if( isset( $input['AZLNK_donate_counter'] ) ) $new_input['AZLNK_donate_counter'] = absint($input['AZLNK_donate_counter']); if( isset( $input['AZLNK_affiliate_counter'] ) ) $new_input['AZLNK_affiliate_counter'] = absint($input['AZLNK_affiliate_counter']); if( isset( $input['AZLNK_bitly_token'] ) ) $new_input['AZLNK_bitly_token'] = sanitize_text_field( $input['AZLNK_bitly_token'] ); return $new_input; } // print the Section text public function AmazoLinkenator_print_section_info() { print '

Settings for AmazoLinkenator

'; print '

Save your settings once after upgrading to the latest version.

'; } // api key callback public function AZLNK_affiliate_key_callback() { printf( '
Enter Your Amazon Affiliate Key. Make sure it is correct; it is not validated.
', isset( $this->options['AZLNK_affiliate_key'] ) ? esc_attr( $this->options['AZLNK_affiliate_key']) : '' ); } // content checkbox callback public function AZLNK_enable_affiliator_posts_callback() { printf( "
options[AZLNK_enable_affiliator_posts] , false ) . " />Check if you want to Affiliate the Amazon URLs in page/post content. URLs are affiliated only on content save/update.
", isset($this->options['AZLNK_enable_affiliator_posts'] ) ?'1' : '0' ); } // comment checkbox callback public function AZLNK_enable_comments_callback() { printf( "
options[AZLNK_enable_comments] , false ) . " />Check if you want to Affiliate the Amazon URLs in post comments. URLs in comments are only affiliated when the comment is saved or updated.
", isset($this->options['AZLNK_enable_comments'] ) ?'1' : '0' ); } // comment checkbox callback public function AZLNK_auto_shorten_callback() { printf( "
options[AZLNK_auto_shorten] , false ) . " />Check if you want to automatically shorten the URL (great for 'hiding' your Affiliate codes). URLs are only shortened when a post/page/comment is saved or updated. Requires you to set up an Bit.ly Application here https://bitly.com/a/create_oauth_app , and then get a 'Generic Access Token' here
https://bitly.com/a/oauth_apps. Enter your Bit.ly Generic Access Token below. You can check any shortened URLs here for a valid affiliate code.
", isset($this->options['AZLNK_auto_shorten'] ) ?'1' : '0' ); } // comment checkbox callback public function AZLNK_bitly_token_callback() { printf( '
Enter Your Bit.ly Generic Access Token. Invalid token codes will not shorten the URL. See above for info on getting your token.
Check your code with the Validate button below (after saving changes).
', isset( $this->options['AZLNK_bitly_token'] ) ? esc_attr( $this->options['AZLNK_bitly_token']) : '' ); } // donate flag callback public function AZLNK_donate_flag_callback() { printf( "
options[AZLNK_donate_flag] , false ) . " />Check if you allow us to use our Affiliate tag every 100 links - this helps support our plugin efforts.
", isset($this->options['AZLNK_donate_flag'] ) ?'1' : '0' ); } // donate counter public function AZLNK_donate_counter_callback() { printf( "
Count of how many times you let us use our Affiliate code - thanks for your support!
", isset( $this->options['AZLNK_donate_counter'] ) ? esc_attr( $this->options['AZLNK_donate_counter']) : '' ); } // affiliate counter public function AZLNK_affiliate_counter_callback() { printf( "
Count of your affiliate links added.
", isset( $this->options['AZLNK_affiliate_counter'] ) ? esc_attr( $this->options['AZLNK_affiliate_counter']) : '' ); } } // end of the class stuff if( is_admin() ) { $my_settings_page = new AmazoLinkenator_Settings_Page(); // closing bracket after credits // ---------------------------------------------------------------------------- // supporting functions // ---------------------------------------------------------------------------- // display the top info part of the page // ---------------------------------------------------------------------------- function AmazoLinkenator_info_top() { global $amazo_version; $image2 = plugin_dir_url( __FILE__ ) . '/assets/banner-772x250.png'; ?>

AmazoLinkenator

Adds your Amazon Affiliate Link to all Amazon product links, in posts/pages/comments.

from CellarWeb.com


AmazoLinkenator will automatically (without any effort on your part) use your Amazon Affiliate code in any Amazon URLs. This will happen for pages, posts, and comments (depending on your settings below). Because you don't have to do anything special to affiliate a URL, this plugin is great for sites with lots of authors - especially those that might try to sneak in their Affiliate codes (which can deprive you of your Affiliate revenue).

And no special steps are needed for any Amazon link. Just paste the Amazon product link in the page/post, and Publish. Your Amazon Affiliate link will automatically be added to the product URL.

And AmazoLinkenator also works with any Amazon product links that your site commenters might add. If anyone includes a link in their comment that has their Amazon Affiliate code, it will be replaced with your affiliate code. All automatically! (It's your site, so you should get the Affiliate revenue!)

URLs are affiliated only when posts/pages/comments are saved/updated/submitted. Any prior content will have your affiliate code if it is re-saved. A counter on the Settings screen shows the number of times that your Affiliate code is inserted in Amazon URLs.

All you need is a valid Amazon Affiliate Key; start here. There is no check for a valid Amazon Affiliate key.

Plus, there's an option to automatically shorten the affiliate URL. This is great for 'hiding' your Amazon Affilliate link code. You just need a free Bit.ly Generic Access Token (start here). Use the Validate button below to for a valid Bit.ly API Key.


Interested in a plugin that will stop comment spam? Without using captchas, hidden fields, or other things that just don't work (or are irritating)?    Check out our nifty FormSpammerTrap for Comments!  It just works!


CellarWeb.com'; echo '
Copyright © ' . $xstartyear . '- ' . date("Y") . ' by ' . $xname . ' and ' . $xcompanylink1 ; echo ' , All Rights Reserved. Released under GPL2 license.
This plugin, authors, and/or CellarWeb.com has no relationship to, or is not sponsored by, or is not approved by, Amazon or Bit.ly, other than being an Amazon Affiliate. Amazon has their own copyrights; so does Bit.ly

'; return; } // endcopyright --------------------------------------------------------- // ---------------------------------------------------------------------------- // ``end of admin area // ---------------------------------------------------------------------------- } // closing bracket for info/credits is_admin section // ---------------------------------------------------------------------------- // start of operational area that changes the comments box stuff // ---------------------------------------------------------------------------- $AZLNK_options = get_option( 'AZLNK_options' ); $AZLNK_affiliate_key = $AZLNK_options['AZLNK_affiliate_key']; $AZLNK_donate_counter = $AZLNK_options['AZLNK_donate_counter']; $AZLNK_affiliate_counter = $AZLNK_options['AZLNK_affiliate_counter']; // set up the filters to process things based on the options settings // preprocess comment after submitted to Affiliate URLs if enabled if ($AZLNK_options['AZLNK_enable_comments']) { add_filter( 'preprocess_comment' , 'AZLNK_url_affiliate_comment',11 ); } // preprocess posts/pages after submitted to Affiliate URLs if enabled if ($AZLNK_options['AZLNK_enable_affiliator_posts']) { add_filter( 'wp_insert_post_data', 'AZLNK_url_affiliate_post', '11', 2 ); } // ---------------------------------------------------------------------------- // end of add_actions and add_filters for posts/pages with comments open // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // here's where we do the work! // ---------------------------------------------------------------------------- function AZLNK_url_affiliate_comment ($commentdata ) { // Affiliate URLs in comments unset( $commentdata['comment_author_url'] ); $AZLNK_text = $commentdata['comment_content']; $AZLNK_affiliated= AZLNK_find_the_urls($AZLNK_text); $commentdata['comment_content']= $AZLNK_affiliated; return $commentdata; } function AZLNK_url_affiliate_post ($data , $postarr) { // Affiliate URLs in posts and pages $AZLNK_text = $data['post_content']; // do the work, then make all links clickable $data['post_content']= make_clickable(AZLNK_find_the_urls($AZLNK_text)); return$data; } // ---------------------------------------------------------------------------- // affiliate the urls function AZLNK_find_the_urls( $AZLNK_text ) { global $AZLNK_options; $AZLNK_options_array = $AZLNK_options; $AZLNK_bitly_token = $AZLNK_options['AZLNK_bitly_token']; $AZLNK_shorten_flag = $AZLNK_options['AZLNK_auto_shorten']; $AZLNK_affiliate_key = $AZLNK_options['AZLNK_affiliate_key']; // add space to beginning/end of the text to ensure affiliation if very-first/very-last string is a URL (ver 1.10a) $AZLNK_text = " " . $AZLNK_text . ' ' ; // regex to find all types of urls in the text // this regex was used prior to version 1.12, but didn't work with umlauts // $AZLNK_regex = "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i" ; // version 1.12 to allow for umlauts (from http://stackoverflow.com/questions/38414371/replace-all-urls-in-text-to-clickable-links-in-php ) $AZLNK_regex ='@(http(s)?://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])@'; preg_match_all($AZLNK_regex, $AZLNK_text, $AZLNK_urls_array) ;// put found urls in the $AZLNK_urls_array array // extract the elements of the first element to get a one-dimension array $AZLNK_urls_array = $AZLNK_urls_array[0]; $AZLNK_urls_array = array_unique($AZLNK_urls_array); // remove duplicate URLs foreach ($AZLNK_urls_array as $AZLNK_url_item) { // check if amzn.to , if so, reset $AZLNK_url_item to uncompressed version // urlencode to handle funny chars like umlauts $AZLNK_host = AZLNK_getHOst($AZLNK_url_item); if ( strpos($AZLNK_host, 'amazn.to')) { $AZLNK_url_item =AZLNK_bitly_expand_2016($url); $AZLNK_host = AZLNK_getHOst($AZLNK_url_item); // reset the host name after uncomplress } if ( strpos($AZLNK_host, 'amazon')) { if (strpos($AZLNK_text, $AZLNK_url_item)) { $AZLNK_affiliated_url = AZLNK_add_affiliate($AZLNK_url_item) ; $AZLNK_affiliated_url = str_replace('??','?', $AZLNK_affiliated_url); if ($AZLNK_shorten_flag == 1) { $AZLNK_new_url =AZLNK_bitly_url_shorten($AZLNK_affiliated_url, $AZLNK_bitly_token); } else {$AZLNK_new_url = $AZLNK_affiliated_url; } if (is_null($AZLNK_new_url)) {return $AZLNK_text ; } // some sort of error, so leave it alone $AZLNK_new_url = esc_url_raw($AZLNK_new_url) ; // sanitize, just in case $AZLNK_text = str_replace($AZLNK_url_item,$AZLNK_new_url,$AZLNK_text); } } } return $AZLNK_text ; } // ---------------------------------------------------------------------------- // atick in the affiliate value function AZLNK_add_affiliate($url) { global $AZLNK_options; $AZLNK_options_array = $AZLNK_options; $AZLNK_affiliate_key = $AZLNK_options['AZLNK_affiliate_key']; $AZLNK_bitly_token = $AZLNK_options['AZLNK_bitly_token']; $AZLNK_donate_counter = $AZLNK_options['AZLNK_donate_counter']; $AZLNK_affiliate_counter = $AZLNK_options['AZLNK_affiliate_counter']; $AZLNK_donate_flag = $AZLNK_options['AZLNK_donate_flag']; $url = urldecode($url); // set up the replace tag; check if time for the 'donate' tag (if enabled) if ( ($AZLNK_affiliate_counter % 100 == 0 )AND ($AZLNK_donate_flag == true ) ) { $AZLNK_donate_counter ++ ; $mod = array("tag" => "azlinkplugin-20"); $tag = "azlinkplugin-20"; } else { $mod = array("tag" => $AZLNK_affiliate_key); $tag =$AZLNK_affiliate_key; } // new function to replace the tag (version 1.10) $AZLNK_newURL = html_entity_decode(AZLNK_fix_the_query($url, $tag)); // update the counters that are shown in the options $AZLNK_affiliate_counter ++; $AZLNK_options['AZLNK_donate_counter'] = $AZLNK_donate_counter; $AZLNK_options['AZLNK_affiliate_counter']= $AZLNK_affiliate_counter; $AZLNK_xresults = update_option("AZLNK_options", $AZLNK_options); return $AZLNK_newURL; } // ---------------------------------------------------------------------------- // from http://www.sanwebe.com/2013/07/shorten-urls-bit-ly-api-php function AZLNK_bitly_url_shorten($AZLNK_long_URL, $AZLNK_access_token) { $url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$AZLNK_access_token.'&longUrl='.urlencode($AZLNK_long_URL); try { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $output = json_decode(curl_exec($ch)); } catch (Exception $e) { } if(isset($output)){return $output->data->url;} else {return $AZLNK_long_URL . " fail"; } } // ---------------------------------------------------------------------------- // expand the bitly url function AZLNK_bitly_expand_2016($url) { $ch = curl_init($url); curl_setopt($ch,CURLOPT_HEADER,true); // Get header information curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,false); $header = curl_exec($ch); $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header)); // Parse information for($i=0;$i

Click this button to test for valid Bit.ly API Key (Save Changes first!)


Results of Bit.ly API Key Validation Test


URL before Smashing:

URL after Smashing :

Huzzah! Valid Bitly API Key found! (Hopefully, it's yours!)"; } else {echo "

Bummer! Not a valid Bitly API Key! Check your Bit.ly Generic Access Token here.

"; } ?>
data->url);} else {return $url_smasher_long_url ; } } // ---------------------------------------------------------------------------- // all done! // ----------------------------------------------------------------------------