$o_value) { $output[$o_key] = trim($o_value); } return $output; } /** * 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; } } /** * Ads... */ 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'); /** * Username change */ 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); } /** * Helpful upgrade notification */ 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!
' . strip_tags($new_plugin_metadata->upgrade_notice); } } add_action('in_plugin_update_message-auction-nudge/auctionnudge.php', 'an_show_upgrade_notification', 10, 2); /** * Modify plugin action links */ 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_auction-nudge/auctionnudge.php', 'an_add_action_links'); /** * ================= CUSTOM FIELDS ======================== */ /** * Create the custom fields box */ function an_create_custom_fields_box() { foreach(array('post', 'page') as $post_type) { add_meta_box('an-custom-fields', an_get_config('plugin_name'), 'an_create_custom_field_form', $post_type, 'normal', 'high'); } } /** * Create the custom field form */ function an_create_custom_field_form() { global $post; //Get post meta $post_meta = get_post_meta($post->ID); $out = '
' . "\n"; //Tabs $out .= '' . "\n"; //Item tool $out .= '
' . "\n"; $out .= '
' . "\n"; $out .= '

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_get_config('shortcode') . ' tool="listings"]

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

' . "\n"; $out .= ' Help' . "\n"; $out .= '


Auction Nudge Pro is coming!
Find out more »

' . "\n"; $out .= '
' . "\n"; $out .= '

Your eBay Listings

' . "\n"; //Get stored post meta values $tool_parameters = an_request_parameters_from_assoc_array('item', $post_meta, false); $out .= an_create_tool_custom_fields('item', $tool_parameters); $out .= '
' . "\n"; //Show Ad tool? if(an_get_option('an_ads_disable') == false) { //Ad tool $out .= '' . "\n"; } //Profile tool $out .= '' . "\n"; //Feedback tool $out .= '' . "\n"; $out .= '
' . "\n"; $out .= '
' . "\n"; echo $out; } /** * Create fields for tool */ function an_create_tool_custom_fields($tool_key, $tool_params, $field_name_format = '%s') { $out = ''; $current_group = false; //Iterate over each field foreach(an_get_config($tool_key . '_parameters') as $field) { //Does this tool have groups? if($tool_has_groups = (an_get_config($tool_key . '_parameter_groups') !== false)) { $parameter_groups = an_get_config($tool_key . '_parameter_groups'); $group = $parameter_groups[$field['group']]; //Output group? if($current_group != $group) { //Close previous fieldset? if($current_group !== false) { $out .= ' ' . "\n"; $out .= '' . "\n"; } $out .= '
' . "\n"; $out .= ' ' . $group['name'] . '' . "\n"; $out .= '
' . "\n"; $out .= '

' . $group['description'] . '

' . "\n"; $current_group = $group; } } //Get saved custom field value if(array_key_exists($field['name'], $tool_params)) { //Is array? if(is_array($tool_params[$field['name']])) { $set_value = $tool_params[$field['name']][0]; } else { $set_value = $tool_params[$field['name']]; } } else { $set_value = false; } //Update field names $field['name'] = sprintf($field_name_format, $field['name']); //Defaults... //Do we have a default? if(array_key_exists('default', $field)) { //Do we need to maintain old defaults? //This is used when a parameter is added/updated and the default is changed, //but we don't want to force existing users to use it //... //If tool has existing data and there is an old default value if((sizeof($tool_params) && array_key_exists($tool_key . '_siteid', $tool_params)) && array_key_exists('default_old', $field)) { //Set the old default $field['default'] = $field['default_old']; } //No default } else { $field['default'] = false; } //Get the input $out .= an_create_custom_field_input($field, $set_value); } if($tool_has_groups) { $out .= '
' . "\n"; $out .= '
' . "\n"; } return $out; } /** * Create the custom fields inputs */ function an_create_custom_field_input($field, $set_value = false) { $out = ''; //ID $field['id'] = an_unprefix($field['id']); //Container $out .= '
' . "\n"; //Label $out .= ' ' . "\n"; $out .= '
' . "\n"; //Default type if(! array_key_exists('type', $field)) { $field['type'] = 'text'; } //Create input $out .= an_create_input($field, $set_value); //Tip if($field['tip']) { $out .= ' ' . "\n"; echo '' . "\n"; echo ' Help' . "\n"; echo '
' . "\n"; echo ' Joe\'s mug' . "\n"; echo '

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

' . "\n"; echo '

I highly recommend watching the Walk-through 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 ' Walk-through Video' . "\n"; echo ' Plugin Help' . "\n"; echo ' Rate the plugin ' . "\n"; echo '
' . "\n"; echo '

' . an_get_config('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 Walk-through 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 Walk-through 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"; echo '
' . "\n"; echo '
'; } /** * Settings page tabs */ 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'); //General... //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'); //Requests add_settings_section('an_request', 'Caching', 'an_request_text', 'an_general'); add_settings_field('an_local_requests', 'Use WordPress Cache?', 'an_local_requests_setting', 'an_general', 'an_request'); //Within Your Theme... //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'); } } add_action('admin_init', 'an_admin_settings'); /** * eBay defaults */ 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'); //Option set? if(is_array($options) && array_key_exists('an_ebay_user', $options)) { $ebay_user_setting = $options['an_ebay_user']; } else { $ebay_user_setting = ''; } echo '' . "\n"; echo '?' . "\n"; echo '
' . "\n"; echo '' . "\n"; echo 'Update every instance ?' . "\n"; echo '
' . "\n"; } /** * Output eBay site option */ function an_ebay_site_setting() { $options = get_option('an_options'); //Option set? if(is_array($options) && array_key_exists('an_ebay_site', $options)) { $ebay_site_setting = $options['an_ebay_site']; } else { $ebay_site_setting = '0'; } $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"; } /** * Request text */ function an_request_text() { echo '

The plugin utilises the in-built WordPress caching mechanism to deliver Auction Nudge content, increasing performance.

' . "\n"; echo '

If you are experiencing issues with Auction Nudge (like if nothing is displayed), try changing this setting to "No". Don\'t worry, other caching mechanisms are still in place.

' . "\n"; } /** * Local Requests option */ function an_local_requests_setting() { $options = get_option('an_options'); $an_local_requests = isset($options['an_local_requests']) ? $options['an_local_requests'] : '1'; echo '' . "\n"; } /** * ==================== LEGACY ============================ */ /** * 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"; }