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 '
';
}
echo '
' . __( 'You have unsaved changes', DFRAPI_DOMAIN ) . '
';
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 = '
| |
' . __( 'Network', DFRAPI_DOMAIN ) . ' |
' . __( 'Type', DFRAPI_DOMAIN ) . ' |
' . __( 'Affiliate ID', DFRAPI_DOMAIN ) . ' (' . __( 'required', DFRAPI_DOMAIN ) . ') |
' . __( 'Tracking ID', DFRAPI_DOMAIN ) . ' (' . __( 'optional', DFRAPI_DOMAIN ) . ') |
';
$i=0;
foreach ( $this->all_networks as $network ) {
$i++;
$checked = ( array_key_exists( $network['_id'], (array) $this->options['ids'] ) ) ? ' checked="checked"' : '';
$type = ( $network['type'] == 'products' ) ? __( 'products', DFRAPI_DOMAIN ) : __( 'coupons', DFRAPI_DOMAIN );
$type_class = ( $network['type'] == 'products' ) ? ' dfrapi_label-info"' : ' dfrapi_label-success';
$no_products = ( $network['product_count'] < 1 ) ? 'no_products' : '';
$alternate = ( $i % 2 ) ? '' : ' alternate';
if ( $network['group'] == $group_name ) {
$html .= '
|
|
|
' . ucfirst( $type ) . '
|
';
if ( $group_name == 'Zanox' ) {
$html .= '' . $this->zanox_adspace( $network['_id'], @$this->options['ids'][$network['_id']]['aid'] ) . ' | ';
} else {
$html .= ' | ';
}
$html .= '
|
';
}
}
$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