Skip to content

Commit

Permalink
added support for API version r6
Browse files Browse the repository at this point in the history
* Added support for API version r6 (beta)
* Fixed dynamically calling class properties error message
* Added support for new networks
* Fixed sorting of networks on networks page
* Updated "tested up to" version
  • Loading branch information
EricBusch committed Nov 8, 2024
1 parent 0f19d06 commit 583d66f
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 37 deletions.
26 changes: 26 additions & 0 deletions classes/class-dfrapi-configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function load_settings() {
array(
'access_id' => '',
'secret_key' => '',
'api_version' => 'r5',
'transport_method' => 'curl',
'disable_api' => 'no',
'zanox_connection_key' => '',
Expand Down Expand Up @@ -85,6 +86,7 @@ function register_settings() {
add_settings_section( 'api_settings', __( 'Datafeedr API Settings', 'datafeedr-api' ), array( &$this, 'section_api_settings_desc' ), $this->page );
add_settings_field( 'access_id', __( 'API Access ID', 'datafeedr-api' ), array( &$this, 'field_access_id' ), $this->page, 'api_settings' );
add_settings_field( 'secret_key', __( 'API Secret Key', 'datafeedr-api' ), array( &$this, 'field_secret_key' ), $this->page, 'api_settings' );
add_settings_field( 'api_version', __( 'API Version', 'datafeedr-api' ), array( &$this, 'field_api_version' ), $this->page, 'api_settings' );
// add_settings_field( 'transport_method', __( 'Transport Method', 'datafeedr-api' ), array( &$this, 'field_transport_method' ), $this->page, 'api_settings' );

/*
Expand Down Expand Up @@ -148,6 +150,21 @@ function field_secret_key() {
<?php
}

function field_api_version() {
?>
<p>
<input type="radio" value="r5" name="<?php echo $this->key; ?>[api_version]" <?php checked( $this->options['api_version'], 'r5', true ); ?> /> <?php _e( 'r5', 'datafeedr-api' ); ?>
</p>
<p>
<input type="radio" value="r6" name="<?php echo $this->key; ?>[api_version]" <?php checked( $this->options['api_version'], 'r6', true ); ?> /> <?php _e( 'r6 (beta)', 'datafeedr-api' ); ?>
</p>
<p class="description">
<?php _e( 'Opt into the r6 version of the API. It is still in beta but it is much faster than r5. Problems?', 'datafeedr-api' ); ?>
<a href="mailto:<?php echo DFRAPI_SUPPORT_EMAIL; ?>"><?php _e( 'Email us', 'datafeedr-api' ); ?></a>.
</p>
<?php
}

function section_ph_api_settings_desc() {
echo __( 'If you want to use the Partnerize affiliate network, add your ', 'datafeedr-api' );
echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/195-how-to-find-your-partnerize-publisher-id-and-api-keys" target="_blank" title="' . __( 'Learn how to find your Partnerize Keys', 'datafeedr-api' ) . '">';
Expand Down Expand Up @@ -361,6 +378,15 @@ function validate( $input ) {
$new_input['secret_key'] = trim( $value );
}

// Validate "api_version"
if ( $key === 'api_version' ) {
$api_version = trim( $value );

$new_input['api_version'] = in_array( $api_version, dfrapi_get_valid_api_versions(), true )
? $api_version
: dfrapi_get_default_api_version();
}

// Validate "transport_method"
if ( $key === 'transport_method' ) {
$new_input['transport_method'] = trim( $value );
Expand Down
1 change: 1 addition & 0 deletions classes/class-dfrapi-networks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Dfrapi_Networks {
private $page = 'dfrapi-networks';
private $key;
private $all_networks;
public $options;

public function __construct() {

Expand Down
14 changes: 10 additions & 4 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ a.dfrapi_plan_link
.network_logo_30x30_affiliate4you { background-image: url(../images/networks/30x30/affiliate4you.jpg); }
.network_logo_30x30_affiliatefuture { background-image: url(../images/networks/30x30/affiliatefuture.jpg); }
.network_logo_30x30_affiliatefuture_coupons { background-image: url(../images/networks/30x30/affiliatefuture-coupons.jpg); }
.network_logo_30x30_ascend { background-image: url(../images/networks/30x30/ascend.jpg); }
.network_logo_30x30_avelon { background-image: url(../images/networks/30x30/avelon.jpg); }
.network_logo_30x30_awin { background-image: url(../images/networks/30x30/awin.jpg); }
.network_logo_30x30_awin_coupons { background-image: url(../images/networks/30x30/awin-coupons.jpg); }
.network_logo_30x30_affiliator { background-image: url(../images/networks/30x30/affiliator.jpg); }
Expand All @@ -539,8 +541,8 @@ a.dfrapi_plan_link
.network_logo_30x30_clixgalore { background-image: url(../images/networks/30x30/clixgalore.jpg); }
.network_logo_30x30_commissionfactory { background-image: url(../images/networks/30x30/commissionfactory.jpg); }
.network_logo_30x30_commissionfactory_coupons { background-image: url(../images/networks/30x30/commissionfactory-coupons.jpg); }
.network_logo_30x30_commissionjunction { background-image: url(../images/networks/30x30/commissionjunction.jpg); }
.network_logo_30x30_commissionjunction_coupons { background-image: url(../images/networks/30x30/commissionjunction-coupons.jpg); }
.network_logo_30x30_cj { background-image: url(../images/networks/30x30/cj.jpg); }
.network_logo_30x30_cj_coupons { background-image: url(../images/networks/30x30/cj-coupons.jpg); }
.network_logo_30x30_commissionmonster { background-image: url(../images/networks/30x30/commissionmonster.jpg); }
.network_logo_30x30_connexity { background-image: url(../images/networks/30x30/connexity.jpg); }
.network_logo_30x30_daisycon { background-image: url(../images/networks/30x30/daisycon.jpg); }
Expand All @@ -567,6 +569,7 @@ a.dfrapi_plan_link
.network_logo_30x30_paidonresults { background-image: url(../images/networks/30x30/paidonresults.jpg); }
.network_logo_30x30_paidonresults_coupons { background-image: url(../images/networks/30x30/paidonresults-coupons.jpg); }
.network_logo_30x30_partnerads { background-image: url(../images/networks/30x30/partnerads.jpg); }
.network_logo_30x30_partnerboost { background-image: url(../images/networks/30x30/partnerboost.jpg); }
.network_logo_30x30_partnerize { background-image: url(../images/networks/30x30/partnerize.jpg); }
.network_logo_30x30_pepperjam { background-image: url(../images/networks/30x30/pepperjam.jpg); }
.network_logo_30x30_pepperjam_coupons { background-image: url(../images/networks/30x30/pepperjam-coupons.jpg); }
Expand Down Expand Up @@ -600,6 +603,8 @@ a.dfrapi_plan_link
.network_logo_16x16_affiliate4you { background-image: url(../images/networks/16x16/affiliate4you.jpg); }
.network_logo_16x16_affiliatefuture { background-image: url(../images/networks/16x16/affiliatefuture.jpg); }
.network_logo_16x16_affiliatefuture_coupons { background-image: url(../images/networks/16x16/affiliatefuture-coupons.jpg); }
.network_logo_16x16_ascend { background-image: url(../images/networks/16x16/ascend.jpg); }
.network_logo_16x16_avelon { background-image: url(../images/networks/16x16/avelon.jpg); }
.network_logo_16x16_awin { background-image: url(../images/networks/16x16/awin.jpg); }
.network_logo_16x16_awin_coupons { background-image: url(../images/networks/16x16/awin-coupons.jpg); }
.network_logo_16x16_affiliator { background-image: url(../images/networks/16x16/affiliator.jpg); }
Expand All @@ -621,8 +626,8 @@ a.dfrapi_plan_link
.network_logo_16x16_clixgalore { background-image: url(../images/networks/16x16/clixgalore.jpg); }
.network_logo_16x16_commissionfactory { background-image: url(../images/networks/16x16/commissionfactory.jpg); }
.network_logo_16x16_commissionfactory_coupons { background-image: url(../images/networks/16x16/commissionfactory-coupons.jpg); }
.network_logo_16x16_commissionjunction { background-image: url(../images/networks/16x16/commissionjunction.jpg); }
.network_logo_16x16_commissionjunction_coupons { background-image: url(../images/networks/16x16/commissionjunction-coupons.jpg); }
.network_logo_16x16_cj { background-image: url(../images/networks/16x16/cj.jpg); }
.network_logo_16x16_cj_coupons { background-image: url(../images/networks/16x16/cj-coupons.jpg); }
.network_logo_16x16_commissionmonster { background-image: url(../images/networks/16x16/commissionmonster.jpg); }
.network_logo_16x16_connexity { background-image: url(../images/networks/16x16/connexity.jpg); }
.network_logo_16x16_daisycon { background-image: url(../images/networks/16x16/daisycon.jpg); }
Expand All @@ -649,6 +654,7 @@ a.dfrapi_plan_link
.network_logo_16x16_paidonresults { background-image: url(../images/networks/16x16/paidonresults.jpg); }
.network_logo_16x16_paidonresults_coupons { background-image: url(../images/networks/16x16/paidonresults-coupons.jpg); }
.network_logo_16x16_partnerads { background-image: url(../images/networks/16x16/partnerads.jpg); }
.network_logo_16x16_partnerboost { background-image: url(../images/networks/16x16/partnerboost.jpg); }
.network_logo_16x16_partnerize { background-image: url(../images/networks/16x16/partnerize.jpg); }
.network_logo_16x16_pepperjam { background-image: url(../images/networks/16x16/pepperjam.jpg); }
.network_logo_16x16_pepperjam_coupons { background-image: url(../images/networks/16x16/pepperjam-coupons.jpg); }
Expand Down
7 changes: 4 additions & 3 deletions datafeedr-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
License: GPL v3
Requires PHP: 7.4
Requires at least: 3.8
Tested up to: 6.6-RC2
Version: 1.3.19
Tested up to: 6.7-RC4
Version: 1.3.20
Datafeedr API Plugin
Copyright (C) 2024, Datafeedr - help@datafeedr.com
Expand All @@ -32,7 +32,7 @@
/**
* Define constants.
*/
define( 'DFRAPI_VERSION', '1.3.19' );
define( 'DFRAPI_VERSION', '1.3.20' );
define( 'DFRAPI_URL', plugin_dir_url( __FILE__ ) ); // https://example.com/wp-content/plugins/datafeedr-api/
define( 'DFRAPI_PATH', plugin_dir_path( __FILE__ ) ); // /absolute/path/to/wp-content/plugins/datafeedr-api/
define( 'DFRAPI_BASENAME', plugin_basename( __FILE__ ) ); // datafeedr-api/datafeedr-api.php
Expand All @@ -49,6 +49,7 @@
define( 'DFRAPI_REPORT_BUG_URL', 'https://datafeedr.me/contact' );
define( 'DFRAPI_ASK_QUESTION_URL', 'https://datafeedr.me/contact' );
define( 'DFRAPI_EMAIL_US_URL', 'https://datafeedr.me/contact' );
define( 'DFRAPI_SUPPORT_EMAIL', 'help@datafeedr.com' );
define( 'DFRAPI_COMPLEX_QUERY_SCORE', 10000 );
define( 'DFRAPI_EXCESSIVE_MERCHANT_COUNT', 1000 );

Expand Down
90 changes: 66 additions & 24 deletions functions/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,44 @@ function dfrapi_get_datafeedr_secret_key() {
return ! empty( $secret_key ) ? $secret_key : false;
}

/**
* Returns the user's Datafeedr API Version or the default.
*
* @return string
*/
function dfrapi_get_datafeedr_api_version() {

$configuration = (array) get_option( 'dfrapi_configuration', [] );

if ( ! isset( $configuration['api_version'] ) ) {
return dfrapi_get_default_api_version();
}

$api_version = trim( $configuration['api_version'] );

return in_array( $api_version, dfrapi_get_valid_api_versions(), true )
? $api_version
: dfrapi_get_default_api_version();
}

/**
* Returns the valid API versions.
*
* @return array
*/
function dfrapi_get_valid_api_versions() {
return [ 'r5', 'r6' ];
}

/**
* Returns the default API version.
*
* @return string
*/
function dfrapi_get_default_api_version() {
return 'r5';
}

/**
* Returns the user's API requests usage as a percentage of their total requests allowed.
*
Expand Down Expand Up @@ -369,20 +407,20 @@ function dfrapi_output_api_error( $data ) {
$error = @$data['dfrapi_api_error'];
$params = @$data['dfrapi_api_error']['params'];
?>
<div class="dfrapi_api_error">
<div class="dfrapi_head"><?php _e( 'Datafeedr API Error', 'datafeedr-api' ); ?></div>
<div class="dfrapi_msg">
<strong><?php _e( 'Message:', 'datafeedr-api' ); ?></strong> <?php echo $error['msg']; ?>
</div>
<div class="dfrapi_code"><strong><?php _e( 'Code:', 'datafeedr-api' ); ?></strong> <?php echo $error['code']; ?>
</div>
<div class="dfrapi_class">
<strong><?php _e( 'Class:', 'datafeedr-api' ); ?></strong> <?php echo $error['class']; ?></div>
<div class="dfrapi_api_error">
<div class="dfrapi_head"><?php _e( 'Datafeedr API Error', 'datafeedr-api' ); ?></div>
<div class="dfrapi_msg">
<strong><?php _e( 'Message:', 'datafeedr-api' ); ?></strong> <?php echo $error['msg']; ?>
</div>
<div class="dfrapi_code"><strong><?php _e( 'Code:', 'datafeedr-api' ); ?></strong> <?php echo $error['code']; ?>
</div>
<div class="dfrapi_class">
<strong><?php _e( 'Class:', 'datafeedr-api' ); ?></strong> <?php echo $error['class']; ?></div>
<?php if ( is_array( $params ) ) : ?>
<div class="dfrps_query"><strong><?php _e( 'Query:', 'datafeedr-api' ); ?></strong>
<span><?php echo dfrapi_display_api_request( $params ); ?></span></div>
<div class="dfrps_query"><strong><?php _e( 'Query:', 'datafeedr-api' ); ?></strong>
<span><?php echo dfrapi_display_api_request( $params ); ?></span></div>
<?php endif; ?>
</div>
</div>
<?php
}

Expand Down Expand Up @@ -564,20 +602,20 @@ function dfrapi_html_output_api_error( $data ) {
$error = $data['dfrapi_api_error'];
$params = @$data['dfrapi_api_error']['params'];
?>
<div class="dfrapi_api_error">
<div class="dfrapi_head"><?php _e( 'Datafeedr API Error', 'datafeedr-api' ); ?></div>
<div class="dfrapi_msg">
<strong><?php _e( 'Message:', 'datafeedr-api' ); ?></strong> <?php echo $error['msg']; ?>
</div>
<div class="dfrapi_code"><strong><?php _e( 'Code:', 'datafeedr-api' ); ?></strong> <?php echo $error['code']; ?>
</div>
<div class="dfrapi_class">
<strong><?php _e( 'Class:', 'datafeedr-api' ); ?></strong> <?php echo $error['class']; ?></div>
<div class="dfrapi_api_error">
<div class="dfrapi_head"><?php _e( 'Datafeedr API Error', 'datafeedr-api' ); ?></div>
<div class="dfrapi_msg">
<strong><?php _e( 'Message:', 'datafeedr-api' ); ?></strong> <?php echo $error['msg']; ?>
</div>
<div class="dfrapi_code"><strong><?php _e( 'Code:', 'datafeedr-api' ); ?></strong> <?php echo $error['code']; ?>
</div>
<div class="dfrapi_class">
<strong><?php _e( 'Class:', 'datafeedr-api' ); ?></strong> <?php echo $error['class']; ?></div>
<?php if ( is_array( $params ) ) : ?>
<div class="dfrapi_query"><strong><?php _e( 'Query:', 'datafeedr-api' ); ?></strong>
<span><?php echo dfrapi_helper_display_api_request( $params ); ?></span></div>
<div class="dfrapi_query"><strong><?php _e( 'Query:', 'datafeedr-api' ); ?></strong>
<span><?php echo dfrapi_helper_display_api_request( $params ); ?></span></div>
<?php endif; ?>
</div>
</div>
<?php
}

Expand Down Expand Up @@ -1869,6 +1907,10 @@ function dfrapi_api_get_all_networks( $nids = array() ) {
}
dfrapi_update_transient_whitelist( $option_name );

usort( $networks, function ( $a, $b ) {
return strnatcasecmp( $a['name'], $b['name'] );
} );

return array_filter( $networks, static function ( $network ) {
return ! in_array( absint( $network['_id'] ), dfrapi_inactive_networks(), true );
} );
Expand Down
24 changes: 20 additions & 4 deletions hooks/global/affiliate-ids.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

defined( 'ABSPATH' ) || exit;

/**
* Set the API Version "url" and "scheme".
*/
function dfrapi_update_api_version_params( $options ) {
if ( dfrapi_get_datafeedr_api_version() === 'r6' ) {
$options['host'] = 'api6.datafeedr.com';
$options['https'] = 'https';
}

return $options;
}

add_filter( 'dfrapi_api_options', 'dfrapi_update_api_version_params' );

/**
* Modify affiliate ID if product is a Zanox product.
* Replaces $affiliate_id with "zmid".
Expand All @@ -21,8 +35,8 @@ function dfrapi_get_zanox_zmid( $affiliate_id, $product, $networks ) {
* Modify affiliate ID if product is a Partnerize product.
* Replaces $affiliate_id with "camref".
*
* @return string Affiliate ID.
* @since 1.0.66
* @return string Affiliate ID.
*/
function dfrapi_get_ph_camref( $affiliate_id, $product, $networks ) {
if ( isset( $product['source'] ) && preg_match( "/\bPartnerize\b/", $product['source'] ) ) {
Expand All @@ -39,8 +53,8 @@ function dfrapi_get_ph_camref( $affiliate_id, $product, $networks ) {
* Modify affiliate ID if product is a Effiliation product.
* Replaces $affiliate_id with "affiliate ID".
*
* @return string Affiliate ID.
* @since 1.0.81
* @return string Affiliate ID.
*/
function dfrapi_get_effiliation_affiliate_id( $affiliate_id, $product, $networks ) {
if ( isset( $product['source'] ) && preg_match( "/\bEffiliation\b/", $product['source'] ) ) {
Expand Down Expand Up @@ -106,12 +120,14 @@ function dfrapi_insert_adservice_mid_into_affiliate_link( $url, $product, $track
/**
* Insert Adspace ID into Belboon affiliate links.
*
* @param string $url
* @since 1.0.124
*
* @param array $product
* @param string $affiliate_id
*
* @param string $url
*
* @return string
* @since 1.0.124
*/
function dfrapi_insert_belboon_adspace_id_into_affiliate_link( $url, $product, $affiliate_id ): string {

Expand Down
Binary file added images/networks/16x16/ascend.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/networks/16x16/avelon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added images/networks/16x16/cj.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/networks/16x16/commissionjunction.jpg
Binary file not shown.
Binary file added images/networks/16x16/partnerboost.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/networks/30x30/ascend.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/networks/30x30/avelon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added images/networks/30x30/cj.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/networks/30x30/commissionjunction.jpg
Binary file not shown.
Binary file added images/networks/30x30/partnerboost.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Requires PHP: 7.4
Requires at least: 3.8
Tested up to: 6.6-RC2
Stable tag: 1.3.19
Tested up to: 6.7-RC4
Stable tag: 1.3.20

Connect to the Datafeedr API.

Expand Down Expand Up @@ -74,6 +74,13 @@ Our support area can be found here: [https://datafeedrapi.helpscoutdocs.com/](ht

== Changelog ==

= 1.3.20 - 2024/11/08 =
* Added support for API version r6 (beta)
* Fixed dynamically calling class properties error message
* Added support for new networks
* Fixed sorting of networks on networks page
* Updated "tested up to" version

= 1.3.19 - 2024/07/05 =
* Fixed "tested up to" version

Expand Down

0 comments on commit 583d66f

Please sign in to comment.