key = 'dfrapi_networks'; $this->all_networks = dfrapi_api_get_all_networks(); add_action( 'init', array( &$this, 'load_settings' ) ); add_action( 'admin_init', array( &$this, 'register_settings' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_notices', array( $this, 'admin_notice' ) ); } function api_errors() { if ( array_key_exists( 'dfrapi_api_error', $this->all_networks ) ) { return $this->all_networks; } return false; } function admin_menu() { add_submenu_page( 'dfrapi', __( 'Networks — Datafeedr API', DFRAPI_DOMAIN ), __( 'Networks', DFRAPI_DOMAIN ), 'manage_options', $this->key, array( $this, 'output' ) ); } function admin_notice() { if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true && isset( $_GET['page'] ) && $this->key == $_GET['page'] ) { echo '

'; _e( 'Networks successfully updated!', DFRAPI_DOMAIN ); echo '

'; } } function output() { echo '
'; echo '

' . dfrapi_setting_pages( $this->page ) . ' — Datafeedr API

'; if ( $errors = $this->api_errors() ) { echo dfrapi_html_output_api_error( $errors ); } else { echo '
'; wp_nonce_field( 'update-options' ); settings_fields( $this->page ); do_settings_sections( $this->page); submit_button(); echo '
'; } echo ''; echo '
'; } function load_settings() { $this->options = (array) get_option( $this->key ); $this->options = array_merge( array( 'ids' => array(), ), $this->options ); } function register_settings() { register_setting( $this->page, $this->key, array( $this, 'validate' ) ); add_settings_section( 'networks', __( 'Select Networks', DFRAPI_DOMAIN ), array( &$this, 'section_networks_desc' ), $this->page ); add_settings_field( 'ids', __( 'Networks', DFRAPI_DOMAIN ), array( &$this, 'field_network_ids' ), $this->page, 'networks', array( 'label_for' => 'DFRAPI_HIDE_LABEL' ) ); } function section_networks_desc() { echo __( 'Select the affiliate networks you belong to, enter your affiliate ID for each then click [Save Changes].', DFRAPI_DOMAIN ); } function field_network_ids() { $groups = $this->get_network_group_names(); foreach ( $groups as $group ) { $num_networks_checked_in_group = $this->num_networks_checked_in_group( $group ); $active = ( $num_networks_checked_in_group != '' ) ? 'active' : ''; echo '
' . $group . ' ' . $this->num_missing_affiliate_ids_in_group( $group ) . ' ' . $num_networks_checked_in_group . ' ' . $this->num_networks_in_group( $group ) . ' ' . $this->num_merchants_in_group( $group ) . ' ' . $this->num_products_in_group( $group ) . '
' . $this->get_groups_networks( $group ) . '
'; } } function get_groups_networks( $group_name ) { $html = ' '; return $html; } function get_network_group_names() { $networks = $this->all_networks; $groups = array(); foreach ( $networks as $network ) { $groups[] = $network['group']; } return array_unique( $groups ); } /** * This returns '; $html .= ''; foreach( $adspaces as $adspace ) { $selected = selected( $selected_adspace, $adspace['id'], false ); $html .= ''; } $html .= ''; } return $html; } /** * This returns adspaces for a Zanox user. */ function get_zanox_adspaces() { $option_name = 'dfrapi_zanox_adspaces'; $use_cache = wp_using_ext_object_cache( false ); $adspaces = get_transient( $option_name ); wp_using_ext_object_cache( $use_cache ); if ( false === $adspaces || empty ( $adspaces ) ) { $zanox_keys = dfrapi_get_zanox_keys(); if ( !$zanox_keys ) { return array( 'zanox_error' => 'missing_keys' ); } else { $client = new Dfr_ZanoxAPIClient( $zanox_keys['connection_key'], $zanox_keys['secret_key'] ); $adspaces = $client->adspaces(); if ( $client->error() ) { return array( 'zanox_error' => $client->error() ); } else { $use_cache = wp_using_ext_object_cache( false ); set_transient( $option_name, $adspaces, HOUR_IN_SECONDS ); wp_using_ext_object_cache( $use_cache ); } } } dfrapi_update_transient_whitelist( $option_name ); return $adspaces; } function num_missing_affiliate_ids_in_group( $group_name ) { $count = 0; foreach ( $this->all_networks as $network ) { if ( $network['group'] == $group_name ) { if ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) { if ( trim( $this->options['ids'][$network['_id']]['aid'] ) == '' ) { $count++; } } } } if ( $count > 0 ) { $messages = $this->messages(); return '' . sprintf( translate_nooped_plural( $messages['num_missing'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . ' / '; } } function num_networks_checked_in_group( $group_name ) { $count = 0; foreach ( $this->all_networks as $network ) { if ( $network['group'] == $group_name ) { if ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) { $count++; } } } if ( $count > 0 ) { $messages = $this->messages(); return '' . sprintf( translate_nooped_plural( $messages['num_checked'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . ' / '; } } function num_networks_in_group( $group_name ) { $count = 0; foreach ( $this->all_networks as $network ) { if ( $network['group'] == $group_name ) { $count++; } } if ( $count > 0 ) { $messages = $this->messages(); return '' . sprintf( translate_nooped_plural( $messages['num_networks'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . ' / '; } } function num_merchants_in_group( $group_name ) { $count = 0; foreach ( $this->all_networks as $network ) { if ( $network['group'] == $group_name ) { $count += $network['merchant_count']; } } if ( $count > 0 ) { $messages = $this->messages(); return '' . sprintf( translate_nooped_plural( $messages['num_merchants'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . ' / '; } } function num_products_in_group( $group_name ) { $count = 0; foreach ( $this->all_networks as $network ) { if ( $network['group'] == $group_name ) { $count += $network['product_count']; } } if ( $count > 0 ) { $messages = $this->messages(); return '' . sprintf( translate_nooped_plural( $messages['num_products'], $count, DFRAPI_DOMAIN ), number_format( $count ) ) . ''; } } function messages() { return array( 'num_missing' => _n_noop( '%s missing affiliate ID', '%s missing affiliate IDs' ), 'num_checked' => _n_noop( '%s network selected', '%s networks selected' ), 'num_networks' => _n_noop( '%s network', '%s networks' ), 'num_merchants' => _n_noop( '%s merchant', '%s merchants' ), 'num_products' => _n_noop( '%s product', '%s products' ), ); } function map_link( $name ) { $links = array( 'AdRecord' => 'http://www.datafeedr.com/docs/item/252', 'Adtraction' => 'http://www.datafeedr.com/docs/item/261', 'Affiliate4You' => 'http://www.datafeedr.com/docs/item/265', 'AffiliateWindow' => 'http://www.datafeedr.com/docs/item/101', 'Affiliator' => 'http://www.datafeedr.com/docs/item/270', 'Affilinet' => 'http://www.datafeedr.com/docs/item/104', 'Amazon Local' => 'http://www.datafeedr.com/docs/item/275', 'APD' => 'http://www.datafeedr.com/docs/item/263', 'Avangate' => 'http://www.datafeedr.com/docs/item/188', 'AvantLink' => 'http://www.datafeedr.com/docs/item/190', 'Belboon' => 'http://www.datafeedr.com/docs/item/201', 'BettyMills' => 'http://www.datafeedr.com/docs/item/264', 'bol.com' => 'http://www.datafeedr.com/docs/item/253', 'ClickBank' => 'http://www.datafeedr.com/docs/item/106', 'ClixGalore' => 'http://www.datafeedr.com/docs/item/200', 'Commission Factory' => 'http://www.datafeedr.com/docs/item/193', 'Commission Junction' => 'http://www.datafeedr.com/docs/item/65', 'Commission Monster' => 'http://www.datafeedr.com/docs/item/109', 'Daisycon' => 'http://www.datafeedr.com/docs/item/196', 'DGM' => 'http://www.datafeedr.com/docs/item/263', 'Double.net' => 'http://www.datafeedr.com/docs/item/271', 'FamilyBlend' => 'http://www.datafeedr.com/docs/item/265', 'FlipKart' => 'http://www.datafeedr.com/docs/item/273', 'Impact Radius' => 'http://www.datafeedr.com/docs/item/268', 'LinkConnector' => 'http://www.datafeedr.com/docs/item/105', 'LinkShare' => 'http://www.datafeedr.com/docs/item/60', 'M4N' => 'http://www.datafeedr.com/docs/item/198', 'MyCommerce' => 'http://www.datafeedr.com/docs/item/111', 'OneNetworkDirect' => 'http://www.datafeedr.com/docs/item/112', 'Optimise' => 'http://www.datafeedr.com/docs/item/276', 'Paid on Results' => 'http://www.datafeedr.com/docs/item/189', 'Partner-ads' => 'http://www.datafeedr.com/docs/item/262', 'PepperJam' => 'http://www.datafeedr.com/docs/item/103', 'RegNow' => 'http://www.datafeedr.com/docs/item/111', 'RevResponse' => 'http://www.datafeedr.com/docs/item/197', 'ShareASale' => 'http://www.datafeedr.com/docs/item/108', 'SuperClix' => 'http://www.datafeedr.com/docs/item/256', 'TradeDoubler' => 'http://www.datafeedr.com/docs/item/113', 'TradeTracker' => 'http://www.datafeedr.com/docs/item/195', 'Webgains' => 'http://www.datafeedr.com/docs/item/114', 'Zanox' => 'http://www.datafeedr.com/docs/item/269', ); return $links[$name]; } function validate( $input ) { $new_input['ids'] = array(); if ( isset( $input['ids'] ) ) { foreach ( $input['ids'] as $k => $v ) { if ( isset( $v['nid'] ) ) { $new_input['ids'][$k] = $v; } } } return $new_input; } } // class Dfrapi_Networks } // class_exists check