Settings page.
Version: 3.1
Author: Joseph Hawes
Author URI: http://www.josephhawes.co.uk/
License: GPL2
*/
/*
Copyright 2014 Joseph Hawes (email: joe@josephhawes.co.uk)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//Settings
$plugin_settings = array(
'plugin_name' => 'Auction Nudge',
'custom_field_prefix' => 'an',
'shortcode' => 'auction-nudge',
'request_item_endpoint' => '//www.auctionnudge.com/item_build/js/',
'request_profile_endpoint' => '//www.auctionnudge.com/profile_build/js/',
'request_feedback_endpoint' => '//www.auctionnudge.com/feedback_build/js/',
'request_ad_endpoint' => '//www.auctionnudge.com/ad_build/iframe/',
'username_bad' => array('.', "\$", '!'),
'username_good' => array('__dot__', '__dollar__', '__bang__'),
'item_parameter_groups' => array(
'feed' => array(
'name' => 'Feed options',
'description' => 'Enter your eBay username'
),
'display' => array(
'name' => 'Display options',
'description' => 'Customise your feed'
),
'advanced' => array(
'name' => 'Advanced options',
'description' => ''
)
),
//Item tool parameters
'item_parameters' => array(
//Step one
'item_SellerID' => array(
'name' => 'item_SellerID',
'id' => 'item_SellerID',
'tip' => 'This is your eBay ID (username) that is associated to your eBay account. This is the username you are known by on eBay and appears on your listings.',
'group' => 'feed',
'title' => 'eBay user ID'
),
'item_siteid' => array(
'name' => 'item_siteid',
'id' => 'item_siteid',
'tip' => 'This is usually where your items are listed. Which site you choose will determine which site you link to and what currency is displayed.',
'type' => 'select',
'options' => array(
'0' => 'eBay US',
'3' => 'eBay UK',
'2' => 'eBay Canada',
'15' => 'eBay Australia',
'23' => 'eBay Belgium',
'77' => 'eBay Germany',
'71' => 'eBay France',
'186' => 'eBay Spain',
'16' => 'eBay Austria',
'101' => 'eBay Italy',
'146' => 'eBay Netherlands',
'205' => 'eBay Ireland',
'193' => 'eBay Switzerland'
),
'default' => '3',
'group' => 'feed',
'title' => 'eBay site'
),
//Step two
'item_theme' => array(
'name' => 'item_theme',
'id' => 'item_theme',
'tip' => 'Your items will display differently on your site depending on which theme you choose. You can also control how your listings appear using custom CSS rules, go to the \'Help / FAQ\' page for more details.',
'type' => 'select',
'options' => array(
'columns' => 'Column View',
'carousel' => 'Carousel',
'simple_list' => 'Simple List',
'details' => 'Image and Details',
'images_only' => 'Images Only',
'grid' => 'Grid View',
'unstyled' => 'Unstyled (advanced)'
),
'default' => 'columns',
'group' => 'display',
'title' => 'Theme'
),
'item_MaxEntries' => array(
'name' => 'item_MaxEntries',
'id' => 'item_MaxEntries',
'tip' => 'This is the maximum number of items you want display. The most items Auction Nudge can display is 100.',
'group' => 'display',
'title' => 'Number of items to show',
'default' => '6'
),
'item_carousel_scroll' => array(
'name' => 'item_carousel_scroll',
'id' => 'item_carousel_scroll',
'tip' => 'This option specifies how may items will be visible in the carousel at one time. Use in conjunction with \'Item width\' to set the overall carousel width, i.e. 140px * 4 = 560px.',
'group' => 'display',
'title' => 'Number of items to scroll',
'default' => '4'
),
'item_carousel_width' => array(
'name' => 'item_carousel_width',
'id' => 'item_carousel_width',
'tip' => 'This options specifies how wide each item in the carousel will be. Use in conjunction with \'Number of items to scroll\' to set the overall carousel width, i.e. 140px * 4 = 560px.',
'group' => 'display',
'title' => 'Item width',
'default' => '140px'
),
'item_carousel_auto' => array(
'name' => 'item_carousel_auto',
'id' => 'item_carousel_auto',
'tip' => 'This option specifies how often, in seconds the carousel should auto scroll. If set to 0 auto scroll is disabled.',
'group' => 'display',
'title' => 'Auto scroll',
'default' => '0'
),
'item_grid_cols' => array(
'name' => 'item_grid_cols',
'id' => 'item_grid_cols',
'tip' => 'Use this option to specify how many columns to display in grid view.',
'group' => 'display',
'title' => 'Grid columns',
'default' => '2'
),
'item_grid_width' => array(
'name' => 'item_grid_width',
'id' => 'item_grid_width',
'tip' => 'Use this option to specify how wide the grid should be. This can be specified in either pixels (px) or as a percentage (%)',
'group' => 'display',
'title' => 'Grid width',
'default' => '100%'
),
'item_show_logo' => array(
'name' => 'item_show_logo',
'id' => 'item_show_logo',
'tip' => 'This option specifies if you want to display the eBay logo with your listings.',
'type' => 'radio',
'group' => 'display',
'title' => 'Show eBay Logo?',
'default' => '1',
'options' => array(
'1' => 'Yes',
'0' => 'No'
),
),
//Advanced
'item_sortOrder' => array(
'name' => 'item_sortOrder',
'id' => 'item_sortOrder',
'tip' => 'This option adjusts the order of the items shown.',
'type' => 'select',
'options' => array(
'' => 'Items Ending First',
'StartTimeNewest' => 'Newly-Listed First',
'PricePlusShippingLowest' => 'Price + Shipping: Lowest First',
'PricePlusShippingHighest' => 'Price + Shipping: Highest First',
'BestMatch' => 'Best Match'
),
'group' => 'advanced',
'title' => 'Sort order'
),
'item_keyword' => array(
'name' => 'item_keyword',
'id' => 'item_keyword',
'tip' => 'By specifying a keyword, only items which contain that keyword in their title will be displayed. Keywords can contain multiple words and up to 5 keywords may be specified. Keywords are separated with a colon (:) and this acts as an OR operator. For example the keywords “red:dark blue:black” will display all items with either “red” or “dark blue” or “black” in their title.',
'group' => 'advanced',
'title' => 'Filter by keyword'
),
'item_categoryId' => array(
'name' => 'item_categoryId',
'id' => 'item_categoryId',
'tip' => 'By specifying an eBay category ID only items which are listed in this category will be displayed. You can specify up to 3 different category IDs by separating with a colon (:) for example 123:456:789 See the Help/FAQ page for help on obtaining category IDs.',
'group' => 'advanced',
'title' => 'Filter by category ID'
)
),
//Ad tool parameters
'ad_parameters' => array(
//Step one
'ad_SellerID' => array(
'name' => 'ad_SellerID',
'id' => 'ad_SellerID',
'tip' => 'This is your eBay ID (username) that is associated to your eBay account. This is the username you are known by on eBay and appears on your listings.',
'group' => 'feed',
'title' => 'eBay user ID'
),
'ad_siteid' => array(
'name' => 'ad_siteid',
'id' => 'ad_siteid',
'tip' => 'This is usually where your items are listed. Which site you choose will determine which site you link to and what currency is displayed.',
'type' => 'select',
'options' => array(
'0' => 'eBay US',
'3' => 'eBay UK',
'2' => 'eBay Canada',
'15' => 'eBay Australia',
'23' => 'eBay Belgium',
'77' => 'eBay Germany',
'71' => 'eBay France',
'186' => 'eBay Spain',
'16' => 'eBay Austria',
'101' => 'eBay Italy',
'146' => 'eBay Netherlands',
'205' => 'eBay Ireland',
'193' => 'eBay Switzerland'
),
'default' => '3',
'group' => 'feed',
'title' => 'eBay site'
),
//Step two
'ad_format' => array(
'name' => 'ad_format',
'id' => 'ad_format',
'tip' => 'Choose from the following list of standard ad sizes.',
'type' => 'select',
'options' => array(
'300x250' => 'Medium rectangle (300px x 250px)',
'336x280' => 'Large rectangle (336px x 280px)',
'250x250' => 'Square (250px x 250px)',
'120x600' => 'Skyscraper (120px x 600px)',
'728x90' => 'Leaderboard (728px x 90px)',
'160x600' => 'Wide skyscraper (160px x 600px)'
),
'default' => '300x250',
'group' => 'display',
'title' => 'Ad size'
),
'ad_theme' => array(
'name' => 'ad_theme',
'id' => 'ad_theme',
'tip' => 'Specifying a colour will change how the ad appears in order to better integrate with your site.',
'type' => 'select',
'options' => array(
'green' => 'Green',
'red' => 'Red',
'blue' => 'Blue',
'orange' => 'Orange',
'grey' => 'Grey',
'pink' => 'Pink'
),
'default' => 'green',
'group' => 'display',
'title' => 'Ad colour'
),
'ad_carousel_auto' => array(
'name' => 'ad_carousel_auto',
'id' => 'ad_carousel_auto',
'tip' => 'This option specifies how often, in seconds the ad should auto scroll. If set to 0 auto scroll is disabled.',
'group' => 'display',
'title' => 'Auto scroll?',
'default' => '5'
),
'ad_blank_noitems' => array(
'name' => 'ad_blank_noitems',
'id' => 'ad_blank_noitems',
'tip' => 'This option enables you to show nothing in the ad space if you do not have any active listings.',
'type' => 'radio',
'group' => 'display',
'title' => 'Blank ad if no listings?',
'default' => '0',
'options' => array(
'1' => 'Yes',
'0' => 'No'
),
),
'ad_hide_username' => array(
'name' => 'ad_hide_username',
'id' => 'ad_hide_username',
'tip' => 'This option hides your eBay username and instead displays \'Our items on eBay\' next to your feedback score.',
'type' => 'radio',
'group' => 'display',
'title' => 'Hide eBay User ID?',
'default' => '0',
'options' => array(
'1' => 'Yes',
'0' => 'No'
),
),
//Advanced
'ad_sortOrder' => array(
'name' => 'ad_sortOrder',
'id' => 'ad_sortOrder',
'tip' => 'This option adjusts the order of the items shown.',
'type' => 'select',
'options' => array(
'' => 'Items Ending First',
'StartTimeNewest' => 'Newly-Listed First',
'PricePlusShippingLowest' => 'Price + Shipping: Lowest First',
'PricePlusShippingHighest' => 'Price + Shipping: Highest First',
'BestMatch' => 'Best Match'
),
'group' => 'advanced',
'title' => 'Sort order'
),
'ad_keyword' => array(
'name' => 'ad_keyword',
'id' => 'ad_keyword',
'tip' => 'By specifying a keyword, only items which contain that keyword in their title will be displayed. Keywords can contain multiple words and up to 5 keywords may be specified. Keywords are separated with a colon (:) and this acts as an OR operator. For example the keywords “red:dark blue:black” will display all items with either “red” or “dark blue” or “black” in their title.',
'group' => 'advanced',
'title' => 'Filter by keyword'
),
'ad_categoryId' => array(
'name' => 'ad_categoryId',
'id' => 'ad_categoryId',
'tip' => 'By specifying an eBay category ID only items which are listed in this category will be displayed. You can specify up to 3 different category IDs by separating with a colon (:) for example 123:456:789 See the Help/FAQ page for help on obtaining category IDs.',
'group' => 'advanced',
'title' => 'Filter by category ID'
)
),
//Profile tool parameters
'profile_parameters' => array(
'profile_UserID' => array(
'name' => 'profile_UserID',
'id' => 'profile_UserID',
'tip' => 'This is your eBay ID (username) that is associated to your eBay account. This is the username you are known by on eBay and appears on your listings.',
'title' => 'eBay user ID'
),
'profile_siteid' => array(
'name' => 'profile_siteid',
'id' => 'profile_siteid',
'tip' => 'This is the site where your eBay account is registered. Although selecting any site will link your badge to your feedback profile, selecting your \'home\' site will ensure your current items are also displayed.',
'type' => 'select',
'options' => array(
'0' => 'eBay US',
'3' => 'eBay UK',
'2' => 'eBay Canada',
'15' => 'eBay Australia',
'23' => 'eBay Belgium',
'77' => 'eBay Germany',
'71' => 'eBay France',
'186' => 'eBay Spain',
'16' => 'eBay Austria',
'101' => 'eBay Italy',
'146' => 'eBay Netherlands',
'205' => 'eBay Ireland',
'193' => 'eBay Switzerland'
),
'default' => '3',
'title' => 'eBay site'
),
'profile_theme' => array(
'name' => 'profile_theme',
'id' => 'profile_theme',
'tip' => 'Your profile information will display differently on your site depending on which theme you choose.',
'type' => 'select',
'options' => array(
'star_grey' => 'Grey Star',
'badge' => 'Rectangular Badge',
'simple_details' => 'Simple Details'
),
'default' => 'star_grey',
'title' => 'Theme'
)
),
//Feedback tool parameters
'feedback_parameters' => array(
'feedback_UserID' => array(
'name' => 'feedback_UserID',
'id' => 'feedback_UserID',
'tip' => 'This is your eBay ID (username) that is associated to your eBay account. This is the username you are known by on eBay and appears on your listings.',
'title' => 'eBay user ID'
),
'feedback_siteid' => array(
'name' => 'feedback_siteid',
'id' => 'feedback_siteid',
'tip' => 'This is the site where your eBay account is registered. Although selecting any site will link your badge to your feedback profile, selecting your \'home\' site will ensure your current items are also displayed.',
'type' => 'select',
'options' => array(
'0' => 'eBay US',
'3' => 'eBay UK',
'2' => 'eBay Canada',
'15' => 'eBay Australia',
'23' => 'eBay Belgium',
'77' => 'eBay Germany',
'71' => 'eBay France',
'186' => 'eBay Spain',
'16' => 'eBay Austria',
'101' => 'eBay Italy',
'146' => 'eBay Netherlands',
'205' => 'eBay Ireland',
'193' => 'eBay Switzerland'
),
'default' => '3',
'title' => 'eBay site'
),
'feedback_limit' => array(
'name' => 'feedback_limit',
'id' => 'feedback_limit',
'tip' => 'This number determines how many feedback entries will be displayed.',
'title' => 'Entries to show (1-25)',
'default' => '5'
),
'feedback_type' => array(
'name' => 'feedback_type',
'id' => 'feedback_type',
'tip' => 'Determines the type of feedback entries displayed.',
'type' => 'select',
'options' => array(
'FeedbackReceived' => 'All feedback received',
'FeedbackLeft' => 'All feedback left for others',
'FeedbackReceivedAsBuyer' => 'Feedback received as a buyer',
'FeedbackReceivedAsSeller' => 'Feedback received as a seller'
),
'default' => 'FeedbackReceived',
'title' => 'Feedback type'
)
)
);
/**
* ========================================================
* ==================== UTILITY ===========================
* ========================================================
*/
function unprefix($key) {
$search = array('item_', 'ad_', 'profile_', 'feedback_');
$replace = array('', '', '', '');
return str_replace($search, $replace, $key);
}
function an_build_snippet($tool = 'LISTINGS', $parameters){
global $plugin_settings;
//Build URL data
$url_data = '';
foreach($parameters as $p_key => $p_value) {
//If we have a value
if($p_value !== '') {
//Un prefix keys
$p_key = unprefix($p_key);
//Process certain parameters
switch($p_key) {
case 'UserID':
case 'SellerID':
$p_value = str_replace($plugin_settings['username_bad'], $plugin_settings['username_good'], $p_value);
break;
}
//Add data
$url_data .= $p_key . '/' . $p_value . '/';
}
}
//Sort out some naughty characters
$search = array('%');
$replace = array('%25');
$src = str_replace($search, $replace, $url_data);
//Build snippet
switch($tool) {
case 'PROFILE' :
$out = '';
$out .= '
To begin you must obtain your code snippet from the Auction Nudge websitehere (shown as "Copy the code snippet onto your site") and paste it into the box below.
' . "\n";
echo '
You can then call <?php an_items(); ?> from within your theme files to embed Your eBay Listings where desired.
To begin you must obtain your code snippet from the Auction Nudge websitehere (shown as "Copy the code snippet onto your site") and paste it into the box below.
' . "\n";
echo '
You can then call <?php an_profile(); ?> from within your theme files to embed Your eBay Profile where desired.
To begin you must obtain your code snippet from the Auction Nudge websitehere (shown as "Copy the code snippet onto your site") and paste it into the box below.
' . "\n";
echo '
You can then call <?php an_feedback(); ?> from within your theme files to embed Your eBay Feedback where desired.
Entering a default eBay user ID here means you don\'t need to keep re-entering it on each page / post where you want to use Auction Nudge.
';
echo '
Your eBay ID is the username that is associated to your eBay account and appears on your listings.
' . "\n";
}
/**
* Output eBay ID option
*/
function an_ebay_user_setting() {
$options = get_option('an_options');
echo '' . "\n";
}
/**
* CSS text
*/
function an_css_text() {
echo '
You can modify the appearance of Auction Nudge by pasting CSS rules into this box.
' . "\n";
echo '
Ensure you target Auction Nudge content by starting your rules with div.auction-nudge. For example div.auction-nudge a { color: red } to make all Auction Nudge links red. You can find more information and demos on modifying the appearance of Auction Nudge here.
' . "\n";
} else {
return '';
}
}
function an_get_widget_title($instance) {
return (! empty($instance['an_widget_title'])) ? strip_tags($instance['an_widget_title']) : false;
}
function an_build_widget_title_input($instance, $count, $widget_field_name) {
$field = array(
'name' => 'an_widget_title',
'id' => 'an_widget_title',
'tip' => 'A title to appear above the widget (optional)',
'title' => 'Widget Title'
);
$set_value = (isset($instance[$field['name']])) ? $instance[$field['name']] : '';
$field['name'] = $widget_field_name;
an_create_custom_field_input($field, $count, $set_value);
}
class Auction_Nudge_Listings_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'an_listings_widget',
'Your eBay Listings',
array(
'description' => 'Use this widget to add your active eBay listings to your site, the feed will update itself automatically (note: only one set of eBay listings can be loaded per page)'
)
);
}
public function widget($args, $instance) {
echo '' . "\n";
}
public function form($instance) {
global $plugin_settings;
$count = 0;
echo '
' . "\n";
}
public function update($new_instance, $old_instance) {
global $plugin_settings;
$instance = array();
$instance['an_widget_title'] = an_get_widget_title($new_instance);
foreach($plugin_settings['item_parameters'] as $field) {
$instance[$field['name']] = (trim($new_instance[$field['name']]) !== '') ? strip_tags($new_instance[$field['name']]) : '';
}
return $instance;
}
}
class Auction_Nudge_Ads_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'an_ads_widget',
'Your eBay Ads',
array(
'description' => 'Use this widget to create interactive banner ads containing your active eBay items. A selection of the common ad sizes are available which will automatically update themselves.'
)
);
}
public function widget($args, $instance) {
echo '' . "\n";
}
public function form($instance) {
global $plugin_settings;
$count = 0;
echo '
' . "\n";
echo '' . "\n";
}
echo ' ' . "\n";
echo '' . "\n";
}
public function update($new_instance, $old_instance) {
global $plugin_settings;
$instance = array();
$instance['an_widget_title'] = an_get_widget_title($new_instance);
foreach($plugin_settings['ad_parameters'] as $field) {
$instance[$field['name']] = (trim($new_instance[$field['name']]) !== '') ? strip_tags($new_instance[$field['name']]) : '';
}
return $instance;
}
}
class Auction_Nudge_Profile_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'an_profile_widget',
'Your eBay Profile',
array(
'description' => 'Use this widget to display information about your eBay profile such as feedback score and date of registration. Different themes / badges are available.'
)
);
}
public function widget($args, $instance) {
echo '' . "\n";
}
public function form($instance) {
global $plugin_settings;
$count = 0;
echo '
' . "\n";
}
public function update($new_instance, $old_instance) {
global $plugin_settings;
$instance = array();
$instance['an_widget_title'] = an_get_widget_title($new_instance);
foreach($plugin_settings['profile_parameters'] as $field) {
$instance[$field['name']] = (trim($new_instance[$field['name']]) !== '') ? strip_tags($new_instance[$field['name']]) : '';
}
return $instance;
}
}
class Auction_Nudge_Feedback_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'an_feedback_widget',
'Your eBay Feedback',
array(
'description' => 'Use this widget to display up to 25 of your most recent eBay feedback comments. The feedback shown is live and will update once more feedback is received.'
)
);
}
public function widget($args, $instance) {
echo '' . "\n";
}
public function form($instance) {
global $plugin_settings;
$count = 0;
echo '