An options box will be added to the edit page/post screen below the content editor. If you like the plugin, please show your appreciation by leaving a rating. Version: 5.0 Author: Joe Hawes Author URI: https://www.auctionnudge.com/ License: GPL2 */ //Settings $an_plugin_settings = array( 'plugin_name' => 'Auction Nudge', 'plugin_version' => '5.0', 'custom_field_prefix' => 'an', 'shortcode' => 'auction-nudge', 'request_item_endpoint' => '//www.auctionnudge.com/feed/item/js/', 'request_profile_endpoint' => '//www.auctionnudge.com/feed/profile/js/', 'request_feedback_endpoint' => '//www.auctionnudge.com/feed/feedback/js/', 'request_ad_endpoint' => '//www.auctionnudge.com/feed/ad/iframe/', 'username_bad' => array('.', "\$", '!', '*'), 'username_good' => array('__dot__', '__dollar__', '__bang__', '__star__'), '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 – the username you are known by on eBay and appears on your listings. This is not your store name.', 'group' => 'feed', 'title' => 'eBay Username' ), 'item_siteid' => array( 'name' => 'item_siteid', 'id' => 'item_siteid', 'tip' => 'This is where your items are usually listed. The site you choose will determine where 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' => '0', '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 change how these themes displaying your listings using CSS rules.', 'tip_link' => 'https://www.auctionnudge.com/customize/appearance', 'type' => 'select', 'options' => array( 'responsive' => 'Responsive', 'columns' => 'Column View', 'carousel' => 'Carousel', 'simple_list' => 'Simple List', 'details' => 'Image and Details', 'images_only' => 'Images Only', 'grid' => 'Grid View', 'unstyled' => 'Unstyled (advanced)' ), 'default' => 'responsive', 'group' => 'display', 'title' => 'Theme' ), 'item_cats_output' => array( 'name' => 'cats_output', 'id' => 'cats_output', 'tip' => 'Once enabled, a list of categories for your items (if you have items for sale in more than one category) will be displayed above your items. This allows users to filter your items by category. The categories shown are eBay categories and not custom/store categories which can not be displayed. Use the Category ID option (Advanced Options) to specify a starting category.', 'tip_link' => 'https://www.auctionnudge.com/help/options#category-list', 'type' => 'select', 'options' => array( 'dropdown' => 'Dropdown', 'unstyled' => 'Unstyled (advanced)', '' => 'None' ), 'default' => 'dropdown', 'group' => 'display', 'title' => 'Category List' ), 'item_MaxEntries' => array( 'name' => 'item_MaxEntries', 'id' => 'item_MaxEntries', 'tip' => 'This is the number of items you want display per page, the maximum value is 100. You can display multiple pages of items using the \'show multiple pages\' option below. Note: The \'Carousel\' theme can load a maximum of 100 items in total, as it does not support the \'show multiple pages\' option.', 'group' => 'display', 'title' => 'Items per Page', 'default' => '6' ), 'item_page' => array( 'name' => 'item_page', 'id' => 'item_page', 'tip' => 'If you enable this option and have more items listed than the value for the \'Items per Page\' option above, users can paginate between multiple pages of items.', 'type' => 'radio', 'group' => 'display', 'title' => 'Show Multiple Pages?', 'default' => 'init', 'options' => array( 'init' => 'Yes', '' => 'No' ) ), '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 alongside your listings.', 'type' => 'radio', 'group' => 'display', 'title' => 'Show eBay Logo?', 'default' => '1', 'options' => array( '1' => 'Yes', '0' => 'No' ) ), 'item_blank' => array( 'name' => 'item_blank', 'id' => 'item_blank', 'tip' => 'Enabling this option will open item links in a new browser tab.', 'type' => 'radio', 'group' => 'display', 'title' => 'Open Links in New Tab?', 'default' => '0', 'options' => array( '1' => 'Yes', '0' => 'No' ) ), 'item_img_size' => array( 'name' => 'item_img_size', 'id' => 'item_img_size', 'tip' => 'Specify in pixels the maximum image size. Depending on the image ratio, the image width or height will not exceed this size. At larger sizes, higher quality images (and therefore a larger file size) are used.', 'tip_link' => 'https://www.auctionnudge.com/customize/appearance#image-size', 'group' => 'display', 'title' => 'Image Size', 'default' => '120' ), //Advanced 'item_sortOrder' => array( 'name' => 'item_sortOrder', 'id' => 'item_sortOrder', 'tip' => 'This option adjusts the order in which items are 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_listing_type' => array( 'name' => 'item_listing_type', 'id' => 'item_listing_type', 'tip' => 'Filtering by listing type allows you to choose to only display items listed as either Auction or Buy It Now. Auction listings that have the Buy It Now option available will be displayed both when filtering by Auction and Buy It Now.', 'group' => 'advanced', 'title' => 'Listing Type', 'type' => 'select', 'options' => array( '' => 'All Listings', 'bin_only' => 'Buy It Now Only', 'auction_only' => 'Auction Only' ), ), '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. The keyword query can contain search operators, allowing for powerful searches to include/exclude certain keywords. Note: it is not possible to just use the minus sign (NOT) operator alone, another operator must be used to include items.', 'tip_link' => 'https://www.auctionnudge.com/help/options#keyword-filter', '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.', 'tip_link' => 'https://www.auctionnudge.com/help/options#category-filter', '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 – the username you are known by on eBay and appears on your listings. This is not your store name.', 'group' => 'feed', 'title' => 'eBay Username' ), 'ad_siteid' => array( 'name' => 'ad_siteid', 'id' => 'ad_siteid', 'tip' => 'This is where your items are usually listed. The site you choose will determine where 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' => '0', '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 Username?', '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.', 'tip_link' => 'https://www.auctionnudge.com/help/options#category-filter', '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 – the username you are known by on eBay and appears on your listings. This is not your store name.', 'title' => 'eBay Username' ), 'profile_siteid' => array( 'name' => 'profile_siteid', 'id' => 'profile_siteid', 'tip' => 'This is where your items are usually listed. The site you choose will determine where 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' => '0', 'title' => 'eBay Site' ), 'profile_theme' => array( 'name' => 'profile_theme', 'id' => 'profile_theme', 'tip' => 'Your profile will display differently on your site depending on which theme you choose.', 'type' => 'select', 'options' => array( 'overview' => 'Overview', 'star_grey' => 'Grey Star', 'badge' => 'Rectangular Badge', 'simple_details' => 'Simple Details' ), 'default' => 'overview', 'title' => 'Theme' ), 'profile_blank' => array( 'name' => 'profile_blank', 'id' => 'profile_blank', 'tip' => 'Enabling this option will open item links in a new browser tab.', 'type' => 'radio', 'group' => 'display', 'title' => 'Open Links in New Tab?', 'default' => '0', 'options' => array( '1' => 'Yes', '0' => 'No' ) ) ), //Feedback tool parameters 'feedback_parameters' => array( 'feedback_UserID' => array( 'name' => 'feedback_UserID', 'id' => 'feedback_UserID', 'tip' => 'This is your eBay ID – the username you are known by on eBay and appears on your listings. This is not your store name.', 'title' => 'eBay Username' ), 'feedback_siteid' => array( 'name' => 'feedback_siteid', 'id' => 'feedback_siteid', 'tip' => 'This is where your items are usually listed. The site you choose will determine where 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' => '0', 'title' => 'eBay Site' ), 'feedback_theme' => array( 'name' => 'feedback_theme', 'id' => 'feedback_theme', 'tip' => 'Your feedback will display differently on your site depending on which theme you choose.', 'type' => 'select', 'options' => array( 'profile_table' => 'Profile table', 'table' => 'Basic table' ), 'default' => 'profile_table', 'title' => 'Theme' ), '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-5)', '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' ), */ 'feedback_blank' => array( 'name' => 'feedback_blank', 'id' => 'feedback_blank', 'tip' => 'Enabling this option will open item links in a new browser tab.', 'type' => 'radio', 'group' => 'display', 'title' => 'Open Links in New Tab?', 'default' => '0', 'options' => array( '1' => 'Yes', '0' => 'No' ) ) ) ); /** * ======================================================== * ==================== 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 $an_plugin_settings; $profile_is_framed = false; //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($an_plugin_settings['username_bad'], $an_plugin_settings['username_good'], $p_value); break; case 'grid_width': $p_value = str_replace('%', '%25', $p_value); break; case 'theme': //Overview theme for profile tool if($tool == 'PROFILE' && $p_value == 'overview') { $profile_is_framed = true; } break; case 'keyword': //Only encode NEW logic if(strpos($p_value, ':') === false) { $p_value = str_replace(array(', ', '( ', ' )', '()'), array(',', '(', ')', ''), $p_value); $p_value = urlencode($p_value); $p_value = str_replace(array('+'), array('%20'), $p_value); } break; } //Add data $url_data .= $p_key . '/' . $p_value . '/'; } } //Build snippet switch($tool) { case 'PROFILE' : //JS if(! $profile_is_framed) { $out = ''; $out .= '
 
'; //Iframe } else { $url = str_replace('feed/profile/js', 'feed/profile/iframe', $an_plugin_settings['request_profile_endpoint']); $src = $url . $url_data; $profile_framed_width = '250px'; $profile_framed_height = '288px'; $out = ''; } break; case 'FEEDBACK' : $out = ''; $out .= '
 
'; break; case 'ADS' : if(an_get_option('an_ads_disable') == true) { $out = ''; break; } $format_dimensions = explode('x', $parameters['ad_format']); $out = ''; break; case 'LISTINGS' : default : $out = ''; $out .= '
 
'; break; } return $out; } function an_custom_fields_set() { global $post; $post_meta = get_post_meta($post->ID); return array_key_exists('item_siteid', $post_meta); } function an_propagate_username_change($an_new_username) { global $wpdb; //Update posts... $wpdb->query( $wpdb->prepare(" UPDATE $wpdb->postmeta SET meta_value = '%s' WHERE meta_key IN('item_SellerID', 'ad_SellerID', 'profile_UserID', 'feedback_UserID') ", $an_new_username) ); //Update widgets... //Ad widgets $an_widgets_options = get_option('widget_an_ads_widget'); foreach($an_widgets_options as &$an_widget_options) { if(is_array($an_widget_options) && array_key_exists('ad_SellerID', $an_widget_options)) { $an_widget_options['ad_SellerID'] = $an_new_username; } } update_option('widget_an_ads_widget', $an_widgets_options); //Feedback widgets $an_widgets_options = get_option('widget_an_feedback_widget'); foreach($an_widgets_options as &$an_widget_options) { if(is_array($an_widget_options) && array_key_exists('feedback_UserID', $an_widget_options)) { $an_widget_options['feedback_UserID'] = $an_new_username; } } update_option('widget_an_feedback_widget', $an_widgets_options); //Profile widgets $an_widgets_options = get_option('widget_an_profile_widget'); foreach($an_widgets_options as &$an_widget_options) { if(is_array($an_widget_options) && array_key_exists('profile_UserID', $an_widget_options)) { $an_widget_options['profile_UserID'] = $an_new_username; } } update_option('widget_an_profile_widget', $an_widgets_options); //Listings widget $an_widgets_options = get_option('widget_an_listings_widget'); foreach($an_widgets_options as &$an_widget_options) { if(is_array($an_widget_options) && array_key_exists('item_SellerID', $an_widget_options)) { $an_widget_options['item_SellerID'] = $an_new_username; } } update_option('widget_an_listings_widget', $an_widgets_options); } /** * ======================================================== * =================== FRONT END ========================== * ======================================================== */ /** * Shortcode */ function an_shortcode($shortcode_attrs){ global $post, $an_plugin_settings; //Get tool $tool = 'LISTINGS'; if(is_array($shortcode_attrs)) { $tool = $shortcode_attrs['tool']; $tool = strtoupper($tool); } //Get post meta $post_meta = get_post_meta($post->ID); //We don't have the data we need... if(! array_key_exists('item_siteid', $post_meta)) { //Woocommerce enabled and this is a shop page... if(function_exists('is_woocommerce') && is_woocommerce() && function_exists('is_shop') && is_shop()) { $post_meta = get_post_meta(woocommerce_get_page_id('shop')); } } //Build request parameters array $request_parameters = array(); switch($tool) { case 'PROFILE' : //Get custom values foreach($an_plugin_settings['profile_parameters'] as $field) { if(array_key_exists($field['name'], $post_meta)) { if(array_key_exists($field['name'], $post_meta)) { $request_parameters[$field['name']] = $post_meta[$field['name']][0]; } } } //Get snippet $out = an_build_snippet('PROFILE', $request_parameters); break; case 'FEEDBACK' : //Get custom values foreach($an_plugin_settings['feedback_parameters'] as $field) { if(array_key_exists($field['name'], $post_meta)) { $request_parameters[$field['name']] = $post_meta[$field['name']][0]; } } //Theme if(! array_key_exists('feedback_theme', $request_parameters) || ! $request_parameters['feedback_theme']) { $request_parameters['feedback_theme'] = 'table'; } //Get snippet $out = an_build_snippet('FEEDBACK', $request_parameters); break; case 'ADS' : //Get custom values foreach($an_plugin_settings['ad_parameters'] as $field) { if(array_key_exists($field['name'], $post_meta)) { $request_parameters[$field['name']] = $post_meta[$field['name']][0]; } } //Get snippet $out = an_build_snippet('ADS', $request_parameters); break; case 'LISTINGS' : default: //Get custom values foreach($an_plugin_settings['item_parameters'] as $field) { if(array_key_exists($field['name'], $post_meta)) { $request_parameters[$field['name']] = $post_meta[$field['name']][0]; } } //Get snippet $out = an_build_snippet('LISTINGS', $request_parameters); break; } return $out; } add_shortcode($an_plugin_settings['shortcode'], 'an_shortcode'); /** * Replace markers */ function an_the_content($content) { $options = get_option('an_options'); $old = array( '[an_items]', '[an_profile]', '[an_feedback]' ); $new = array( isset($options['an_items_code']) ? $options['an_items_code'] : '', isset($options['an_profile_code']) ? $options['an_profile_code'] : '', isset($options['an_feedback_code']) ? $options['an_feedback_code'] : '' ); return str_replace($old, $new, $content); } add_filter('the_content', 'an_the_content'); /** * Output version # */ function an_output_version() { global $an_plugin_settings; echo '' . "\n"; } add_action('wp_head','an_output_version'); /** * Output items */ function an_items() { echo an_get_option('an_items_code'); } /** * Output profile */ function an_profile() { echo an_get_option('an_profile_code'); } /** * Output feedback */ function an_feedback() { echo an_get_option('an_feedback_code'); } /** * ======================================================== * ================== ADMIN ONLY ========================== * ======================================================== */ function an_admin_init() { global $an_plugin_settings; //Permissions if(current_user_can('manage_options')) { //Add custom fields add_action( 'admin_head-post.php', 'an_get_setting_defaults' ); add_action( 'admin_head-post.php', 'an_create_custom_fields_box' ); add_action( 'admin_head-post-new.php', 'an_get_setting_defaults' ); add_action( 'admin_head-post-new.php', 'an_create_custom_fields_box' ); //Save custom fields add_action('save_post', 'an_save_custom_fields', 10, 2); //Add CSS wp_register_style('an_css', plugins_url('auctionnudge.css?' . $an_plugin_settings['plugin_version'], __FILE__)); wp_enqueue_style('an_css'); //Add JS wp_register_script('an_js', plugins_url('auctionnudge.js?' . $an_plugin_settings['plugin_version'], __FILE__), array('jquery')); wp_enqueue_script('an_js'); //Thickbox add_thickbox(); } } add_action('admin_init', 'an_admin_init'); function an_get_setting_defaults() { global $an_plugin_settings; //Get options $options = get_option('an_options'); //Check for default eBay Username if(array_key_exists('an_ebay_user', $options) && ! empty($options['an_ebay_user'])) { $an_plugin_settings['item_parameters']['item_SellerID']['default'] = $options['an_ebay_user']; $an_plugin_settings['ad_parameters']['ad_SellerID']['default'] = $options['an_ebay_user']; $an_plugin_settings['profile_parameters']['profile_UserID']['default'] = $options['an_ebay_user']; $an_plugin_settings['feedback_parameters']['feedback_UserID']['default'] = $options['an_ebay_user']; } //Check for default eBay site if(array_key_exists('an_ebay_site', $options) && ! empty($options['an_ebay_site'])) { $an_plugin_settings['item_parameters']['item_siteid']['default'] = $options['an_ebay_site']; $an_plugin_settings['ad_parameters']['ad_siteid']['default'] = $options['an_ebay_site']; $an_plugin_settings['profile_parameters']['profile_siteid']['default'] = $options['an_ebay_site']; $an_plugin_settings['feedback_parameters']['feedback_siteid']['default'] = $options['an_ebay_site']; } } function an_ads_disable() { $an_options = get_option('an_options'); //No settings present, or not the one we are looking for if(! is_array($an_options) || ! array_key_exists('an_ads_disable', $an_options)) { global $wpdb; //Check post meta $results = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "postmeta` WHERE `meta_key` LIKE '%ad_SellerID%'", ARRAY_A); //If post meta if(sizeof($results) > 0) { //Don't disable $an_options['an_ads_disable'] = false; //If no page meta } else { //Then check for widget meta WITH DATA $results = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "options` WHERE option_name LIKE 'widget_an_%_widget' AND option_value LIKE '%siteid%'", ARRAY_A); //If widget meta if(sizeof($results) > 0) { //Don't disable $an_options['an_ads_disable'] = false; //No widget meta either } else { //Disable $an_options['an_ads_disable'] = true; } } update_option('an_options', $an_options); } } add_action('admin_init', 'an_ads_disable'); function an_show_upgrade_notification($current_plugin_metadata, $new_plugin_metadata){ //Check Upgrade Notice if(isset($new_plugin_metadata->upgrade_notice) && strlen(trim($new_plugin_metadata->upgrade_notice)) > 0) { echo '

Important Update!
' . esc_html($new_plugin_metadata->upgrade_notice); } } add_action('in_plugin_update_message-auction-nudge/auctionnudge.php', 'an_show_upgrade_notification', 10, 2); function an_add_action_links($links) { $links_before = array(); $links_after = array( 'Settings', ); return array_merge($links_before, $links, $links_after); } add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'an_add_action_links' ); /** * ======================================================== * ================= CUSTOM FIELDS ======================== * ======================================================== */ /** * Create the custom fields box */ function an_create_custom_fields_box() { global $an_plugin_settings; foreach(array('post', 'page') as $post_type) { add_meta_box('an-custom-fields', $an_plugin_settings['plugin_name'], 'an_create_custom_field_form', $post_type, 'normal', 'high'); } } function an_get_set_value($post_id, $field_name) { $post_meta = get_post_meta($post_id, $field_name); if(empty($post_meta)) { return false; } else { return $post_meta[0]; } } /** * Create the custom field form */ function an_create_custom_field_form() { global $post, $an_plugin_settings; echo '
' . "\n"; echo '' . "\n"; //Item tool echo '
' . "\n"; echo '
' . "\n"; echo '

Use these options to specify which of your eBay items to display within your page/post.

Add the following shortcode within your content editor to specify where the items will appear:

[' . $an_plugin_settings['shortcode'] . ' tool="listings"]

Note: Only one set of eBay listings can be loaded per page.

' . "\n"; echo ' Quick Help Setup Video' . "\n"; echo '
' . "\n"; echo '

Your eBay Listings

' . "\n"; $current_group = false; $count = 0; foreach($an_plugin_settings['item_parameters'] as $field) { $group = $an_plugin_settings['item_parameter_groups'][$field['group']]; //Output group? if($current_group != $group) { //Close previous fieldset? if($current_group !== false) { echo '
' . "\n"; echo '' . "\n"; } echo '
' . "\n"; echo ' ' . $group['name'] . '' . "\n"; echo '
' . "\n"; echo '

' . $group['description'] . '

' . "\n"; $current_group = $group; } $set_value = an_get_set_value($post->ID, $field['name']); //Maintain old defaults //If: // - Custom fields data exists // - AND An empty string is a valid value // - AND There is no value already set if(an_custom_fields_set() && array_key_exists('options', $field) && array_key_exists('', $field['options'])) { //Set an empty string as the default $field['default'] = ''; //Allow empty string for this } elseif(an_custom_fields_set() && $field['name'] == 'item_img_size' && $set_value == '') { $field['default'] = ''; } an_create_custom_field_input($field, $count, $set_value); $count++; } echo '
' . "\n"; echo '
' . "\n"; echo '
' . "\n"; //Show Ad tool? if(an_get_option('an_ads_disable') == false) { //Ad tool echo '' . "\n"; echo '' . "\n"; } echo '
' . "\n"; echo ' ' . $group['name'] . '' . "\n"; echo '
' . "\n"; echo '

' . $group['description'] . '

' . "\n"; $current_group = $group; } $set_value = an_get_set_value($post->ID, $field['name']); an_create_custom_field_input($field, $count, $set_value); $count++; } echo '
' . "\n"; echo '
' . "\n"; echo '' . "\n"; } //Profile tool echo '' . "\n"; //Feedback tool echo '' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo '
' . "\n"; } /** * Create the custom fields inputs */ function an_create_custom_field_input($field, $count = false, $set_value = false) { global $an_plugin_settings; $out = ''; //Do we have a default? if(! array_key_exists('default', $field)) { $field['default'] = false; } $field['id'] = unprefix($field['id']); //Container $alt = ($count !== false && $count % 2) ? ' alt' : ''; $out .= '
' . "\n"; //Label $out .= ' ' . "\n"; $out .= '
' . "\n"; //Default type if(! array_key_exists('type', $field)) { $field['type'] = 'text'; } switch($field['type']) { case 'select' : $out .= ' ' . "\n"; break; case 'checkbox' : //Value submitted? $checked = false; if($set_value && ($set_value == 'true' || $set_value == $field['value'])) { $checked = true; } elseif($field['default'] == 'true') { $checked = true; } $value = ($field['value']) ? $field['value'] : 'true'; $out .= ' $description) { $checked = false; //Always use strings $value = (string)$value; //If we have a stored value if($set_value === $value) { $checked = true; //Otherwise is this the default value? } elseif($set_value === false && $value == $field['default']) { $checked = true; } $out .= '
' . "\n"; $out .= ' ' . "\n"; $out .= '
' . "\n"; } break; case 'text' : default : $out .= ' ' . "\n"; echo ' Quick Help' . "\n"; echo '
' . "\n"; echo ' ' . "\n"; echo '

Hi, I\'m Joe and I created this plugin.

' . "\n"; echo '

I highly recommend watching the Setup Video on how to use the plugin.

' . "\n"; echo '

Most common issues are solved by reading the Help section. Bugs and errors can be reported here. Please do this before leaving a poor review.

' . "\n"; echo '

If you like the plugin, please show your appreciation by leaving a rating. It really does help.

' . "\n"; echo '

Thanks!

' . "\n"; echo ' Watch the setup video' . "\n"; echo ' Read the Help section' . "\n"; echo ' Rate the plugin :)' . "\n"; echo '
' . "\n"; echo '

' . $an_plugin_settings['plugin_name'] . '

' . "\n"; echo '

To add Auction Nudge to your pages or posts, use the Auction Nudge box on the edit page. You can also add Auction Nudge to your theme as Widgets. The Settings below can be used to specify some defaults and style rules, but are not required.

' . "\n"; echo '

For more details on how to use the plugin, you can watch the Setup Video.

' . "\n"; //Tabs $active_tab = (isset($_GET['tab'])) ? $_GET['tab'] : 'general'; an_admin_tabs($active_tab); //Open form echo '
' . "\n"; settings_fields('an_options'); //Preserve value $an_options = get_option('an_options'); $an_ads_disable = ($an_options['an_ads_disable']) ? 1 : 0; echo ''; //Propagate username change? if(isset($an_options['an_username_propagate']) && $an_options['an_username_propagate'] == 'true') { an_propagate_username_change($an_options['an_ebay_user']); } //Which group of options are we showing? switch($active_tab) { case 'theme' : echo '
'; do_settings_sections('an_general'); echo '
'; echo '

To add Auction Nudge to your pages / posts use the Auction Nudge box on the edit page. The options on this page allow you to specify code snippets from within your theme if you are modifying your theme\'s PHP scripts.

' . "\n"; echo '

In most cases you will not need to use these options. If you are unsure how to use the plugin, I recommend checking out this quick Setup Video.

' . "\n"; echo '

To modify these options, click here.

' . "\n"; echo '' . "\n"; break; case 'general' : default : do_settings_sections('an_general'); echo '
'; do_settings_sections('an_theme'); echo '
'; break; } //Submit echo ' ' . "\n"; echo '
' . "\n"; //Help echo ' ' . "\n"; echo '
' . "\n"; echo '
'; } function an_admin_tabs($current = 'general') { $tabs = array( 'general' => 'General', 'theme' => 'Within Your Theme' ); $links = array(); foreach($tabs as $slug => $name) { if($slug == $current) { $links[] = '' . $name . ''; } else { $links[] = '' . $name . ''; } } echo ''; } /** * Define settings */ function an_admin_settings(){ //Permissions if(current_user_can('manage_options')) { register_setting('an_options', 'an_options', 'an_options_validate'); //Items add_settings_section('an_items', 'Your eBay Listings', 'an_items_text', 'an_theme'); add_settings_field('an_items_code_snippet', 'Insert code snippet', 'an_items_setting', 'an_theme', 'an_items'); //Profile add_settings_section('an_profile', 'Your eBay Profile', 'an_profile_text', 'an_theme'); add_settings_field('an_profile_code_snippet', 'Insert code snippet', 'an_profile_setting', 'an_theme', 'an_profile'); //Feedback add_settings_section('an_feedback', 'Your eBay Feedback', 'an_feedback_text', 'an_theme'); add_settings_field('an_feedback_code_snippet', 'Insert code snippet', 'an_feedback_setting', 'an_theme', 'an_feedback'); //eBay ID add_settings_section('an_ebay_defaults', 'Your eBay Defaults', 'an_ebay_defaults_text', 'an_general'); add_settings_field('an_ebay_user', 'eBay Username', 'an_ebay_user_setting', 'an_general', 'an_ebay_defaults'); add_settings_field('an_ebay_site', 'eBay Site', 'an_ebay_site_setting', 'an_general', 'an_ebay_defaults'); //CSS add_settings_section('an_css', 'Your CSS Rules', 'an_css_text', 'an_general'); add_settings_field('an_css_rules', 'Insert CSS Rules', 'an_css_setting', 'an_general', 'an_css'); } } add_action('admin_init', 'an_admin_settings'); /** * Items text */ function an_items_text() { echo '

To begin you must obtain your code snippet from the Auction Nudge website here (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 display Your eBay Listings where desired.

' . "\n"; } /** * Output items option */ function an_items_setting() { $options = get_option('an_options'); $an_items_code = isset($options['an_items_code']) ? $options['an_items_code'] : ''; echo '' . "\n"; } /** * Profile text */ function an_profile_text() { echo '

To begin you must obtain your code snippet from the Auction Nudge website here (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 display Your eBay Profile where desired.

' . "\n"; } /** * Output profile option */ function an_profile_setting() { $options = get_option('an_options'); $an_profile_code = isset($options['an_profile_code']) ? $options['an_profile_code'] : ''; echo '' . "\n"; } /** * Feedback text */ function an_feedback_text() { echo '

To begin you must obtain your code snippet from the Auction Nudge website here (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 display Your eBay Feedback where desired.

' . "\n"; } /** * Output feedback option */ function an_feedback_setting() { $options = get_option('an_options'); $an_feedback_code = isset($options['an_feedback_code']) ? $options['an_feedback_code'] : ''; echo '' . "\n"; } /** * eBay ID */ function an_ebay_defaults_text() { echo '

Entering a default eBay username and site here will save you from re-entering them on each page, post or widget where you want to use Auction Nudge.

' . "\n"; } /** * Output eBay ID option */ function an_ebay_user_setting() { $options = get_option('an_options'); echo '' . "\n"; echo '?' . "\n"; echo '
' . "\n"; echo '' . "\n"; echo 'Update every instance ?' . "\n"; echo '
' . "\n"; } /** * Output eBay site option */ function an_ebay_site_setting() { //global $an_plugin_settings; $options = get_option('an_options'); $siteids = 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' ); echo '' . "\n"; 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 '

For example div#auction-nudge-items a { color: red } will make all links displayed by the Your eBay Listings tool red. You can find more information and demos on modifying the appearance of Auction Nudge here.

' . "\n"; } /** * Output CSS option */ function an_css_setting() { $options = get_option('an_options'); $an_css_rules = isset($options['an_css_rules']) ? $options['an_css_rules'] : ''; echo '' . "\n"; } /** * Validate our options */ function an_options_validate($input) { $output = array(); foreach($input as $o_key => $o_value) { $output[$o_key] = trim($o_value); } return $output; } /** * Load custom CSS */ function an_load_css() { $options = get_option('an_options'); if(isset($options['an_css_rules'])) { echo '' . "\n"; } } add_action('wp_head', 'an_load_css'); /** * Get plugin options */ function an_get_option($option_key) { $options = get_option('an_options'); if(is_array($options) && array_key_exists($option_key, $options)) { return $options[$option_key]; } else { return false; } } /** * ======================================================== * ==================== WIDGETS =========================== * ======================================================== */ function an_display_widget_title($instance) { if(array_key_exists('an_widget_title', $instance) && $instance['an_widget_title']) { return '

' . $instance['an_widget_title'] . '

' . "\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']] : false; $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 $an_plugin_settings; $count = 0; echo '
' . "\n"; an_build_widget_title_input($instance, $count, $this->get_field_name('an_widget_title')); $count++; $current_group = false; foreach($an_plugin_settings['item_parameters'] as $field) { //Maintain old defaults if(sizeof($instance) > 0 && array_key_exists('options', $field) && array_key_exists('', $field['options'])) { //Set an empty string as the default $field['default'] = ''; } $group = $an_plugin_settings['item_parameter_groups'][$field['group']]; //Output group? if($current_group != $group) { //Close previous fieldset? if($current_group !== false) { echo '
' . "\n"; echo '' . "\n"; } echo '
' . "\n"; echo ' ' . $group['name'] . '' . "\n"; echo '
' . "\n"; echo '

' . $group['description'] . '

' . "\n"; $current_group = $group; } $set_value = (isset($instance[$field['name']])) ? $instance[$field['name']] : false; $field['name'] = $this->get_field_name($field['name']); an_create_custom_field_input($field, $count, $set_value); $count++; } echo '
' . "\n"; echo '
' . "\n"; echo '
' . "\n"; } public function update($new_instance, $old_instance) { global $an_plugin_settings; $instance = array(); $instance['an_widget_title'] = an_get_widget_title($new_instance); foreach($an_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 $an_plugin_settings; $count = 0; echo '
' . "\n"; an_build_widget_title_input($instance, $count, $this->get_field_name('an_widget_title')); $count++; $current_group = false; foreach($an_plugin_settings['ad_parameters'] as $field) { $group = $an_plugin_settings['item_parameter_groups'][$field['group']]; //Output group? if($current_group != $group) { //Close previous fieldset? if($current_group !== false) { echo '
' . "\n"; echo '' . "\n"; } echo '
' . "\n"; echo ' ' . $group['name'] . '' . "\n"; echo '
' . "\n"; echo '

' . $group['description'] . '

' . "\n"; $current_group = $group; } $set_value = (isset($instance[$field['name']])) ? $instance[$field['name']] : false; $field['name'] = $this->get_field_name($field['name']); an_create_custom_field_input($field, $count, $set_value); $count++; } echo '
' . "\n"; echo '
' . "\n"; echo '' . "\n"; } public function update($new_instance, $old_instance) { global $an_plugin_settings; $instance = array(); $instance['an_widget_title'] = an_get_widget_title($new_instance); foreach($an_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 $an_plugin_settings; $count = 0; echo '
' . "\n"; an_build_widget_title_input($instance, $count, $this->get_field_name('an_widget_title')); $count++; foreach($an_plugin_settings['profile_parameters'] as $field) { $set_value = (isset($instance[$field['name']])) ? $instance[$field['name']] : false; $field['name'] = $this->get_field_name($field['name']); an_create_custom_field_input($field, $count, $set_value); $count++; } echo '
' . "\n"; } public function update($new_instance, $old_instance) { global $an_plugin_settings; $instance = array(); $instance['an_widget_title'] = an_get_widget_title($new_instance); foreach($an_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 5 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 $an_plugin_settings; $count = 0; echo '
' . "\n"; an_build_widget_title_input($instance, $count, $this->get_field_name('an_widget_title')); $count++; foreach($an_plugin_settings['feedback_parameters'] as $field) { //Maintain old defaults if(sizeof($instance) > 0) { switch($field['name']) { case 'feedback_theme' : $field['default'] = 'table'; break; } } $set_value = (isset($instance[$field['name']])) ? $instance[$field['name']] : false; $field['name'] = $this->get_field_name($field['name']); an_create_custom_field_input($field, $count, $set_value); $count++; } echo '
' . "\n"; } public function update($new_instance, $old_instance) { global $an_plugin_settings; $instance = array(); $instance['an_widget_title'] = an_get_widget_title($new_instance); foreach($an_plugin_settings['feedback_parameters'] as $field) { $instance[$field['name']] = (trim($new_instance[$field['name']]) !== '') ? strip_tags($new_instance[$field['name']]) : ''; } return $instance; } } function an_widgets_init() { an_get_setting_defaults(); register_widget('Auction_Nudge_Listings_Widget'); if(an_get_option('an_ads_disable') == false) { register_widget('Auction_Nudge_Ads_Widget'); } register_widget('Auction_Nudge_Profile_Widget'); register_widget('Auction_Nudge_Feedback_Widget'); } add_action('widgets_init', 'an_widgets_init');