Plugin Directory

Changeset 412894


Ignore:
Timestamp:
07/21/2011 02:25:02 AM (14 years ago)
Author:
mdbitz
Message:

Version 1.7.2

Location:
wordpress-amazon-associate/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • wordpress-amazon-associate/trunk/AmazonProduct.php

    r410533 r412894  
    171171        // get Locale
    172172        $locale = $wpaa->getGeoLocale( $options['locale'] );
     173        //validate Product Exists
     174        if( ! $wpaa->getCacheHandler()->productExists( $options['asin'], $locale ) ) {
     175            $locale = $wpaa->getLocale();
     176        }
     177
    173178        // Append service url
    174179        $outputStr .= WPAA_URIHandler::getRemoteContentURI( $locale ) . '?';
  • wordpress-amazon-associate/trunk/WPAA.php

    r410863 r412894  
    205205     * @var String
    206206     */
    207     protected $version = '1.7.1';
     207    protected $version = '1.7.2';
    208208
    209209    /**
     
    211211     * @var String
    212212     */
    213     protected $last_updated = '07-16-2011';
     213    protected $last_updated = '07-20-2011';
    214214
    215215    /**
     
    281281            add_filter('comment_text', array(&$this,'filter_amazon_associate_tag'), 25);
    282282        }
     283        // add amazon rel="nofilter" filter
     284        add_filter('the_content', array(&$this, 'filter_rel_nofollow'), 20 );
    283285        // insert product preview code if enabled
    284286        if( $this->options['ProductPreview'] === true ) {
     
    305307        }
    306308        echo $content;
     309    }
     310
     311    /**
     312     * Filter content and add rel="nofollow" to Amazon Links
     313     *
     314     * @param string $content
     315     * @return string
     316     */
     317    public function filter_rel_nofollow($content) {
     318        preg_match_all('~<a.*>~isU',$content,$matches);
     319        for ( $i = 0; $i <= sizeof($matches[0]) - 1; $i++){
     320            if ( !preg_match( '~nofollow~is', $matches[0][$i])
     321                    && (preg_match('~http://www.amazon.~', $matches[0][$i]) )){
     322                $result = trim($matches[0][$i],">");
     323                $result .= ' rel="nofollow">';
     324                $content = str_replace($matches[0][$i], $result, $content);
     325            }
     326        }
     327        return $content;
    307328    }
    308329
     
    320341        foreach ($filtered_matches as $key => $match) {
    321342            $orig_str = $match;
    322             $new_str = $orig_str;
    323             if( $this->modules[self::MODULE_IP2NATION]->isInstalled() && $this->options['LocaleByGeoIP'] ) {
    324                 $new_str = $this->localize_static_tag( $new_str );
    325             }
     343            $new_str = $orig_str;
     344            if( $this->modules[self::MODULE_IP2NATION]->isInstalled() && $this->options['LocaleByGeoIP'] ) {
     345                $new_str = $this->localize_static_tag( $new_str );
     346            }
    326347            $new_str = $this->replace_associate_tag( $new_str );
    327348            if( $orig_str != $new_str ) {
     
    605626        if( is_null( $locale ) || empty( $locale ) ) {
    606627            // Admin Localization
    607             if( function_exists('wp_get_current_user') && function_exists('current_user_can') ) {
    608                 if ( current_user_can('manage_options') ) {
    609                     if( $this->options['CVEnabled'] && $this->options['CVLocale'] != '' ) {
    610                         return $this->options['CVLocale'];
    611                     }
    612                 }
    613             }
     628            if( function_exists('wp_get_current_user') && function_exists('current_user_can') ) {
     629                if ( current_user_can('manage_options') ) {
     630                    if( $this->options['CVEnabled'] && $this->options['CVLocale'] != '' ) {
     631                        return $this->options['CVLocale'];
     632                    }
     633                }
     634            }
    614635            // Get Geo Locale if enabled
    615636            if(  $this->modules[self::MODULE_IP2NATION]->isInstalled() && $this->options['LocaleByGeoIP'] ) {
     
    867888        }
    868889
    869         // migration of Widgets Enabled :: Version < 2.0.0 Upgrade
     890        // migration of Widgets Enabled :: Version < 1.7.0 Upgrade
    870891        if( isset( $this->options['AmazonCarouselWidget'])) {
    871892            $this->modules[self::MODULE_AMAZON_WIDGETS]->updateSettings( $this->options );
     
    879900        }
    880901
    881         // update AWSValid with current settings :: Version < 2.0.0 Upgrade
     902        // update AWSValid with current settings :: Version < 1.7.0 Upgrade
    882903        if( is_null( $this->options['AWSValid'] ) ) {
    883904            $this->options['AWSValid'] = $this->validateCredentials();
  • wordpress-amazon-associate/trunk/WPAA/CacheHandler.php

    r410533 r412894  
    149149
    150150    /**
     151     * check if Amazon Product exists in given locale
     152     * @global WPAA $wpaa
     153     * @global WPDB $wpdb
     154     * @param string $id
     155     * @param string $locale
     156     * @param string $type
     157     * @param string $responseGroup
     158     */
     159    public function productExists( $id, $locale=null, $type="ASIN", $responseGroup=null ) {
     160        global $wpaa;
     161        global $wpdb;
     162        $locale = $wpaa->getGeoLocale( $locale );
     163
     164        if( $this->_enabled ) { // cache is enabled
     165            $cache_index = $locale . $id . $type . $responseGroup;
     166            if( isset( $this->_cache[$cache_index] ) ) { // check php cache
     167                $result = $this->_cache[$cache_index];
     168                return $result->isSuccess();
     169            } else {
     170                //lookup product in db cache
     171                $sql = $wpdb->prepare( "Select data, updated_ts FROM `$this->_table` WHERE id='%s' AND locale='%s' AND type='%s' AND response_group='%s';", $id, $locale, $type, $responseGroup );
     172                $result = $wpdb->get_row( $sql );
     173
     174                //product not in cache
     175                if( is_null( $result ) ) {
     176                    $result = $this->getProductByAPI($id, $locale, $type, $responseGroup);
     177                    //cache result in db
     178                    $sql = $wpdb->insert( $this->_table, array( 'id' => $id, 'locale' => $locale, 'type' => $type, 'response_group' => $responseGroup, 'data' => serialize( $result ), 'updated_ts' => date( 'Y-m-d', time() ) ) );
     179                    // cache result in php
     180                    $this->_cache[$cache_index] = $result;
     181                    return $result->isSuccess();
     182                } else {
     183
     184                    // cache has expired
     185                    if( $this->_expire > 0  && strtotime ( '+' . $this->_expire . ' day' , strtotime( $result->updated_ts ) ) < time() ) {
     186                        $result = $this->getProductByAPI($id, $locale, $type, $responseGroup);
     187                        //cache result in db
     188                        $sql = $wpdb->update( $this->_table, array( 'data' => serialize( $result ), 'updated_ts' => date( 'Y-m-d', time() ) ), array( 'id' => $id, 'locale' => $locale, 'type' => $type, 'response_group' => $responseGroup ) );
     189                        // cache result in php
     190                        $this->_cache[$cache_index] = $result;
     191                        // if product does not exist for locale then get product from default locale
     192                        return $result->isSuccess();
     193                    } else {
     194                        //unserialize db cache
     195                        $result = unserialize($result->data);
     196                        // cache result in php
     197                        $this->_cache[$cache_index] = $result;
     198                        return $result->isSuccess();
     199                    }
     200                }
     201            }
     202        } else { // cache is disabled
     203            $result = $this->getProductByAPI($id, $locale, $type, $responseGroup);
     204            // if product does not exist for locale then get product from default locale
     205            return $result->isSuccess();
     206        }
     207    }
     208
     209    /**
    151210     * get Product from Amazon Product API
    152211     * @global WPAA $wpaa
  • wordpress-amazon-associate/trunk/readme.txt

    r410533 r412894  
    45451. **Amazon Product Linking**
    4646
    47 1. **Amazon Product Link Filtering**
     471. **Amazon Product Link Associate Tag filtering & update with rel="nofollow"**
    4848
    49491. **Amazon Product Preview**
     
    187187
    188188The full project changelogs can be found at [http://labs.mdbitz.com/wordpress/wordpress-amazon-associate-plugin/changelog](http://labs.mdbitz.com/wordpress/wordpress-amazon-associate-plugin/changelog/?utm_source=wordpress&utm_medium=plugin-readme&utm_campaign=plugin)
     189
     190= 1.7.2 - 07/20/2011 =
     191* Added check to Enhanced add to confirm product exists for Geo-Localization if not defaults to primary locale
     192* Static Amazon Product links updated with rel="nofollow" automatically
     193
     194= 1.7.1 - 07/16/2011 =
     195* Content Viewer Module - Update to check if wp_get_current_user exists to resolve WordPress issue
    189196
    190197= 1.7.0 - 07/15/2011 =
  • wordpress-amazon-associate/trunk/wordpress_amazon_associate.php

    r410863 r412894  
    55  Description: Quickly and eaily monetize your webiste through the integration of Amazon products and widgets tagged with your associate id.
    66  Author: MDBitz - Matthew John Denton
    7   Version: 1.7.1
     7  Version: 1.7.2
    88  Requires at least: 3.0.0
    99  Author URI: http://labs.mdbitz.com
     
    4444require_once plugin_dir_path(__FILE__) . 'WPAA.php';
    4545spl_autoload_register(array('WPAA', 'autoload'));
    46 $wpaa = new WPAA();
     46$wpaa = new WPAA( );
     47
     48// deactivation
     49register_deactivation_hook( __FILE__, 'wpaa_deactivate');
     50
     51/**
     52 * send site uninstall information
     53 */
     54function wpaa_deactivate() {
     55    if( function_exists('curl_init') ) {
     56        $handle   = curl_init('http://mdbitz.com/installs.php?app=WPAA&uninstall=true&site=' . site_url() );
     57        if (false !== $handle) {
     58            curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
     59            curl_setopt($handle, CURLOPT_NOBODY, true);
     60            $response = curl_exec($handle);
     61            curl_close($handle);
     62        }
     63    }
     64}
     65
     66// deactivation
     67register_activation_hook( __FILE__, 'wpaa_activate');
     68
     69/**
     70 * send site activation information
     71 */
     72function wpaa_activate() {
     73    if( function_exists('curl_init') ) {
     74        $handle   = curl_init('http://mdbitz.com/installs.php?app=WPAA&activate=true&site=' . site_url() );
     75        if (false !== $handle) {
     76            curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
     77            curl_setopt($handle, CURLOPT_NOBODY, true);
     78            $response = curl_exec($handle);
     79            curl_close($handle);
     80        }
     81    }
     82}
Note: See TracChangeset for help on using the changeset viewer.