'large', self::DEFAULT_IMAGE => '', self::FRAMED => 'N', self::ITEMS => 1 ]; private $db = null; public function __construct() { $this->db = new Database(); } public static function init() { return new General(); } public function settings() { add_settings_section( self::SECTION, 'Default Settings', [ $this, 'display_section' ], self::PAGE ); add_settings_field( self::IMAGE_SIZE, 'Default Image Size', [ $this, 'display_image_size' ], self::PAGE, self::SECTION, [] ); add_settings_field( self::DEFAULT_IMAGE, 'Default Image', [ $this, 'display_default_image' ], self::PAGE, self::SECTION, [] ); add_settings_field( self::FRAMED, 'Default Image Frame', [ $this, 'display_framed' ], self::PAGE, self::SECTION, [] ); add_settings_field( self::ITEMS, 'Default Number of Items', [ $this, 'display_items' ], self::PAGE, self::SECTION, [] ); $args = [ 'type' => 'array', 'description' => 'Default options for Affiliate Bridge', 'sanitize_callback' => [ $this, 'process_input' ], 'default' => self::DEFAULTS ]; register_setting( self::OPT, self::OPT, $args ); } public function load_settings() { return get_option( self::OPT ); } public function display() { if ( isset( $_GET[ 'action' ] ) && isset( $_GET[ 'step' ] ) ) { $this->do_action( $_GET[ 'action'], $_GET[ 'step' ] ); } else { ?>

Affiliate Bridge :: Default Settings

display_shortcode_help(); ?>
download_ebay_cats( $step ); } } public function display_section() { echo "These are the default settings for Affiliate Bridge. They can be overridden by the settings for specific sources."; } public function display_image_size() { $settings = $this->load_settings(); ?>
load_settings(); ?>
<?php echo __( 'def', AB_PLUGIN_DOMAIN ) ?> load_settings(); ?>
load_settings(); ?>
1, Multiple Items will be shown in a table', AB_PLUGIN_DOMAIN ); ?> [ 'column' => 'id', 'operator' => '=', 'condition' => '1' ] ]; $results = $this->db->get( 'ebay_cats', $wheres ); $version = 'N/A'; $date = 'Never'; if ( is_array( $results ) && ( isset( $results[ 0 ]->version ) && isset( $results[ 0 ]->category_name ) ) ) { $version = $results[ 0 ]->version; $date = $results[ 0 ]->category_name; } ?>
TODO: Shortcode Help goes here!
'; } public function set_errors( $errors ) { if ( count( $errors ) ) { foreach( $errors as $code => $msg ) { add_settings_error( self::OPT, $code, $msg, 'notice-error is-dismissible' ); } } } public function set_warnings( $warnings ) { if ( count( $warnings ) ) { foreach( $warnings as $code => $msg ) { add_settings_error( self::OPT, $code, $msg, 'notice-warning is-dismissible' ); } } } public function set_success() { $code = 'saved'; $msg = __( 'Default Options Saved Successfully', AB_PLUGIN_DOMAIN ); add_settings_error( self::OPT, $code, $msg, 'notice-success is-dismissible' ); } public function process_input() { if( isset( $_POST[ 'submit' ] ) ) { $input = [ self::IMAGE_SIZE => $_POST[ self::IMAGE_SIZE ], self::DEFAULT_IMAGE => $_POST[ self::DEFAULT_IMAGE ], self::FRAMED => $_POST[ self::FRAMED ], self::ITEMS => $_POST[ self::ITEMS ] ]; } else { return; } $data = $this->sanitize_input( $input ); $check = $this->validate_input( $data ); $current = get_option( self::OPT ); if( ! count( $check[ 0 ] ) ) { $this->set_success(); return $data; } else { $this->set_errors( $check[ 0 ] ); return $current; } } private function sanitize_input( $input ) { $clean = array(); $clean[ self::IMAGE_SIZE ] = ( isset( $input[ self::IMAGE_SIZE ] ) ) ? sanitize_text_field( $input[ self::IMAGE_SIZE ] ) : ''; $clean[ self::DEFAULT_IMAGE ] = ( isset( $input[ self::DEFAULT_IMAGE ] ) ) ? sanitize_text_field( $input[ self::DEFAULT_IMAGE ] ) : ''; $clean[ self::FRAMED ] = ( isset( $input[ self::FRAMED ] ) ) ? sanitize_text_field( $input[ self::FRAMED ] ) : ''; $clean[ self::ITEMS ] = ( isset( $input[ self::ITEMS ] ) ) ? sanitize_text_field( $input[ self::ITEMS ] ) : ''; return $clean; } private function validate_input( $input ) { $errors = $warnings = []; $image_sizes = [ 'small', 'medium', 'large' ]; if( ! isset( $input[ self::IMAGE_SIZE ] ) || ! in_array( $input[ self::IMAGE_SIZE ], $image_sizes ) ) { $errors[ self::IMAGE_SIZE ] = __( 'Invalid Default Image Size Selected. Please select one of the valid options.', AB_PLUGIN_DOMAIN ); } if( ! isset( $input[ self::DEFAULT_IMAGE ] ) || isset( $input[ self::DEFAULT_IMAGE ] ) && ! $this->is_valid_url( $input[ self::DEFAULT_IMAGE ] ) ) { $errors[ self::DEFAULT_IMAGE ] = __( 'Invalid Default Image URL. Please use a valid URL.', AB_PLUGIN_DOMAIN ); } $frames = [ 'N', 'Y', 'C' ]; if( ! isset( $input[ self::FRAMED ] ) || ! in_array( $input[ self::FRAMED ], $frames ) ) { $errors[ self::FRAMED ] = __( 'Invalid Default Frame Selected. Please select on of the valid options.', AB_PLUGIN_DOMAIN ); } if( ! isset( $input[ self::ITEMS ] ) || isset( $input[ self::ITEMS ] ) && ! is_numeric( $input[ SELF::ITEMS ] ) ) { $errors[ self::ITEMS ] = __( 'Invalid Default Number of Items. Please use valid number.', AB_PLUGIN_DOMAIN ); } return [ $errors, $warnings ]; } private function is_valid_url( $file ) { $fp = @fopen( $file, 'r' ); if( $fp !== false ) { fclose( $fp ); } return $fp; } private function download_ebay_cats( $step ) { $api = new eBay_API(); $session_id = $api->get_session_id(); $token = $api->get_token(); switch( $step ) { case 1: if ( $token === '' ) { $this->download_ebay_cats_get_auth( $api, $session_id ); } else { $this->download_ebay_cats_step_1( $api ); } break; case 2: $submit = $_POST[ 'submit' ]; if ( $submit === 'Back to Settings' ) { wp_safe_redirect( 'admin.php?page=affiliate-bridge-backend' ); exit(); } elseif ( $submit === 'Download Category List') { $this->download_ebay_cats_step_2( $api ); } break; } } private function download_ebay_cats_get_auth( &$api, $session_id ) { $runame = Trading_API::RUNAME; ?>

Affiliate Bridge :: Download eBay Category List :: Authorization

'disabled' ] ); ?>
get_local_category_list_version(); $ebay_version = $api->make_call( 'get_ebay_category_list_version' ); $ebay_version = $ebay_version->get_payload(); if ( $local_version != $ebay_version ) { $download = true; $title = 'Step 1'; $url = 'admin.php?page=affiliate-bridge-backend&action=download-ebay-cats&step=2'; } else { $download = false; $title = 'Up-To-Date'; $url = 'admin.php?page=affiliate-bridge-backend'; } ?>

Affiliate Bridge :: Download eBay Category List ::

make_call( 'get_ebay_category_list' ); $categories = $categories->get_payload(); $this->save_categories( $version, $categories ); ?>

Affiliate Bridge :: Download eBay Category List :: Complete

[ 'column' => 'id', 'operator' => '=', 'condition' => '1' ] ]; $results = $this->db->get( 'ebay_cats', $wheres ); if ( is_array( $results ) && isset( $results[ 0 ]->version ) ) { return $results[ 0 ]->version; } else { return false; } } private function save_categories( $version, $categories ) { $now = new DateTime(); $data = [ 'category_id' => '', 'category_level' => '', 'category_name' => $now->format( 'Y-m-d H:i:s' ), 'parent_id' => '', 'version' => $version, ]; $this->db->insert( 'ebay_cats', $data ); $data = []; foreach( $categories as $cat ) { $data = []; $data = [ 'category_id' => $cat[ 'category_id' ], 'category_level' => $cat[ 'category_level' ], 'category_name' => $cat[ 'category_name' ], 'parent_id' => $cat[ 'parent_id' ], 'version' => $version ]; $this->db->insert( 'ebay_cats', $data ); } } } }