Advertisement
Guest User

Untitled

a guest
Feb 18th, 2014
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 358.68 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. Plugin Name: MarketPress
  6.  
  7. Version: 2.9.1
  8.  
  9. Plugin URI: http://premium.wpmudev.org/project/e-commerce/
  10.  
  11. Description: The complete WordPress ecommerce plugin - works perfectly with BuddyPress and Multisite too to create a social marketplace, where you can take a percentage! Activate the plugin, adjust your settings then add some products to your store.
  12.  
  13. Author: WPMU DEV
  14.  
  15. Author URI: http://premium.wpmudev.org/
  16.  
  17. Text Domain: mp
  18.  
  19. WDP ID: 144
  20.  
  21.  
  22.  
  23. Copyright 2009-2014 Incsub (http://incsub.com)
  24.  
  25. Author - Aaron Edwards
  26.  
  27. Contributors - Arnold Bailey, Jonathan Cowher, Ryan Welcher, Marko Miljus, Aristeides Stathopoulos, Jeffri H, Coleman Stevenson, Enzo Maddalena
  28.  
  29.  
  30.  
  31. This program is free software; you can redistribute it and/or modify
  32.  
  33. it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
  34.  
  35. the Free Software Foundation.
  36.  
  37.  
  38.  
  39. This program is distributed in the hope that it will be useful,
  40.  
  41. but WITHOUT ANY WARRANTY; without even the implied warranty of
  42.  
  43. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  44.  
  45. GNU General Public License for more details.
  46.  
  47.  
  48.  
  49. You should have received a copy of the GNU General Public License
  50.  
  51. along with this program; if not, write to the Free Software
  52.  
  53. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  54.  
  55. */
  56.  
  57.  
  58.  
  59. class MarketPress {
  60.  
  61.  
  62.  
  63. var $version = '2.9.1';
  64.  
  65. var $location;
  66.  
  67. var $plugin_dir = '';
  68.  
  69. var $plugin_url = '';
  70.  
  71. var $plugin_file = '';
  72.  
  73. var $product_template;
  74.  
  75. var $product_taxonomy_template;
  76.  
  77. var $product_list_template;
  78.  
  79. var $store_template;
  80.  
  81. var $checkout_template;
  82.  
  83. var $orderstatus_template;
  84.  
  85. var $language = '';
  86.  
  87. var $checkout_error = false;
  88.  
  89. var $cart_cache = false;
  90.  
  91. var $is_shop_page = false;
  92.  
  93. var $global_cart = false;
  94.  
  95. var $skip_shipping_notice = false;
  96.  
  97. var $weight_printed = false;
  98.  
  99. var $defaults = array(
  100.  
  101. /* IMPORTANT! DO NOT CHANGE THE ORDER OF THESE ARGUMENTS!
  102.  
  103. REQUIRED FOR BACKWARDS COMPATABILITY. IF YOU NEED TO
  104.  
  105. ADD AN ADDITIONAL DEFAULT ADD IT TO THE END OF EACH ARRAY */
  106.  
  107. 'list_products' => array(
  108.  
  109. 'echo' => true,
  110.  
  111. 'paginate' => NULL,
  112.  
  113. 'page' => NULL,
  114.  
  115. 'per_page' => NULL,
  116.  
  117. 'order_by' => NULL,
  118.  
  119. 'order' => NULL,
  120.  
  121. 'category' => NULL,
  122.  
  123. 'tag' => NULL,
  124.  
  125. 'list_view'=> NULL,
  126.  
  127. 'filters' => NULL,
  128.  
  129. ),
  130.  
  131. 'related_products' => array(
  132.  
  133. 'product_id' => NULL,
  134.  
  135. 'relate_by' => 'both',
  136.  
  137. 'echo' => false,
  138.  
  139. 'limit' => NULL,
  140.  
  141. 'simple_list' => NULL,
  142.  
  143. ),
  144.  
  145. );
  146.  
  147.  
  148.  
  149. function __construct() {
  150.  
  151. //setup our variables
  152.  
  153. $this->init_vars();
  154.  
  155.  
  156.  
  157. //initialize session
  158.  
  159. $this->start_session();
  160.  
  161.  
  162.  
  163. //install plugin
  164.  
  165. register_activation_hook( __FILE__, array($this, 'install') );
  166.  
  167.  
  168.  
  169. if ( ! defined( 'MP_LITE' ) ) {
  170.  
  171. //load dashboard notice
  172.  
  173. global $wpmudev_notices;
  174.  
  175. $wpmudev_notices[] = array( 'id'=> 144,'name'=> 'MarketPress', 'screens' => array( 'edit-product', 'product', 'edit-product_category', 'edit-product_tag', 'product_page_marketpress-orders', 'product_page_marketpress', 'settings_page_marketpress-ms-network' ) );
  176.  
  177. include_once( $this->plugin_dir . 'dash-notice/wpmudev-dash-notification.php' );
  178.  
  179. }
  180.  
  181.  
  182.  
  183. //load template functions
  184.  
  185. require_once( $this->plugin_dir . 'template-functions.php' );
  186.  
  187.  
  188.  
  189. //load shortcodes
  190.  
  191. include_once( $this->plugin_dir . 'marketpress-shortcodes.php' );
  192.  
  193.  
  194.  
  195. //load oembed
  196.  
  197. include_once( $this->plugin_dir . 'marketpress-oembed.php');
  198.  
  199.  
  200.  
  201. //load stats
  202.  
  203. include_once( $this->plugin_dir . 'marketpress-stats.php' );
  204.  
  205.  
  206.  
  207. //load sitewide features if WPMU
  208.  
  209. if (is_multisite()) {
  210.  
  211. include_once( $this->plugin_dir . 'marketpress-ms.php' );
  212.  
  213. $network_settings = get_site_option( 'mp_network_settings' );
  214.  
  215. if ( $network_settings['global_cart'] )
  216.  
  217. $this->global_cart = true;
  218.  
  219. }
  220.  
  221.  
  222.  
  223. //localize the plugin
  224.  
  225. add_action( 'plugins_loaded', array(&$this, 'localization'), 9 );
  226.  
  227.  
  228.  
  229. //load APIs and plugins
  230.  
  231. add_action( 'plugins_loaded', array(&$this, 'load_plugins') );
  232.  
  233.  
  234.  
  235. //load importers
  236.  
  237. add_action( 'plugins_loaded', array(&$this, 'load_importers') );
  238.  
  239.  
  240.  
  241. //custom post type
  242.  
  243. add_action( 'init', array(&$this, 'register_custom_posts'), 0 ); //super high priority
  244.  
  245. add_filter( 'request', array(&$this, 'handle_edit_screen_filter') );
  246.  
  247.  
  248.  
  249. //edit products page
  250.  
  251. add_filter( 'manage_product_posts_columns', array(&$this, 'edit_products_columns') );
  252.  
  253. add_action( 'manage_product_posts_custom_column', array(&$this, 'edit_products_custom_columns') );
  254.  
  255. add_action( 'restrict_manage_posts', array(&$this, 'edit_products_filter') );
  256.  
  257.  
  258.  
  259. add_filter( 'post_row_actions', array(&$this, 'edit_products_custom_row_actions'), 10, 2);
  260.  
  261. add_filter( 'admin_action_copy-product', array(&$this, 'edit_products_copy_action') );
  262.  
  263.  
  264.  
  265. //manage orders page
  266.  
  267. add_filter( 'manage_product_page_marketpress-orders_columns', array(&$this, 'manage_orders_columns') );
  268.  
  269. add_action( 'manage_mp_order_posts_custom_column', array(&$this, 'manage_orders_custom_columns') );
  270.  
  271.  
  272.  
  273. //Plug admin pages
  274.  
  275. add_action( 'admin_menu', array(&$this, 'add_menu_items') );
  276.  
  277. add_action( 'admin_print_styles', array(&$this, 'admin_css') );
  278.  
  279. add_action( 'admin_print_scripts', array(&$this, 'admin_script_post') );
  280.  
  281. add_action( 'admin_notices', array(&$this, 'admin_nopermalink_warning') );
  282.  
  283. add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'plugin_action_link'), 10, 2);
  284.  
  285. add_action( 'wp_ajax_mp-hide-help', array(&$this, 'hide_help') );
  286.  
  287.  
  288.  
  289. //Meta boxes
  290.  
  291. add_action( 'add_meta_boxes_product', array(&$this, 'meta_boxes') );
  292.  
  293. add_action( 'wp_insert_post', array(&$this, 'save_product_meta'), 10, 2 );
  294.  
  295. add_filter( 'enter_title_here', array(&$this, 'filter_title') );
  296.  
  297.  
  298.  
  299. //Templates and Rewrites
  300.  
  301. add_action( 'wp', array(&$this, 'load_store_templates') );
  302.  
  303. add_action( 'template_redirect', array(&$this, 'load_store_theme') );
  304.  
  305. add_action( 'pre_get_posts', array(&$this, 'remove_canonical') );
  306.  
  307. add_filter( 'rewrite_rules_array', array(&$this, 'add_rewrite_rules') );
  308.  
  309. add_filter( 'query_vars', array(&$this, 'add_queryvars') );
  310.  
  311. add_action( 'option_rewrite_rules', array(&$this, 'check_rewrite_rules') );
  312.  
  313. add_action( 'init', array(&$this, 'flush_rewrite_check'), 99 );
  314.  
  315. if ( !defined('MP_HIDE_MENUS') ) { //allows you to hide MP menus
  316.  
  317. add_filter( 'wp_list_pages', array(&$this, 'filter_list_pages'), 10, 2 );
  318.  
  319. add_filter( 'wp_nav_menu_objects', array(&$this, 'filter_nav_menu'), 10, 2 );
  320.  
  321. }
  322.  
  323.  
  324.  
  325. /* enqueue lightbox - this will just register the styles/scripts
  326.  
  327. the won't actually be output unless they're needed */
  328.  
  329. add_action('wp_enqueue_scripts', array(&$this, 'enqueue_lightbox'));
  330.  
  331.  
  332.  
  333. //Payment gateway returns
  334.  
  335. add_action( 'pre_get_posts', array(&$this, 'handle_gateway_returns'), 1 );
  336.  
  337.  
  338.  
  339. //Store cart handling
  340.  
  341. add_action( 'template_redirect', array(&$this, 'store_script') ); //only on front pages
  342.  
  343. /* use both actions so logged in and not logged in users can send this AJAX request */
  344.  
  345. add_action( 'wp_ajax_nopriv_mp-update-cart', array(&$this, 'update_cart') );
  346.  
  347. add_action( 'wp_ajax_mp-update-cart', array(&$this, 'update_cart') );
  348.  
  349. add_action( 'wp_ajax_mp-province-field', 'mp_province_field' ); //province field callback for shipping form
  350.  
  351. add_action( 'wp_ajax_nopriv_mp-province-field', 'mp_province_field' );
  352.  
  353. add_action( 'wp_ajax_mp-orders-export', array(&$this, 'export_orders_csv') );
  354.  
  355. add_action( 'wp_logout', array(&$this, 'logout_clear_session') ); //see http://premium.wpmudev.org/forums/topic/security-issue-with-marketpress
  356.  
  357.  
  358.  
  359. add_action( 'wp_ajax_nopriv_get_products_list', array(&$this, 'get_products_list') );
  360.  
  361. add_action( 'wp_ajax_get_products_list', array(&$this, 'get_products_list') );
  362.  
  363.  
  364.  
  365. //Relies on post thumbnails for products
  366.  
  367. add_action( 'after_setup_theme', array(&$this, 'post_thumbnails'), 9999 );
  368.  
  369.  
  370.  
  371. //Add widgets
  372.  
  373. if (!$this->get_setting('disable_cart', 0))
  374.  
  375. add_action( 'widgets_init', create_function('', 'return register_widget("MarketPress_Shopping_Cart");') );
  376.  
  377.  
  378.  
  379. add_action( 'widgets_init', create_function('', 'return register_widget("MarketPress_Product_List");') );
  380.  
  381. add_action( 'widgets_init', create_function('', 'return register_widget("MarketPress_Categories_Widget");') );
  382.  
  383. add_action( 'widgets_init', create_function('', 'return register_widget("MarketPress_Tag_Cloud_Widget");') );
  384.  
  385.  
  386.  
  387. // Edit profile
  388.  
  389. add_action( 'profile_update', array(&$this, 'user_profile_update') );
  390.  
  391. add_action( 'edit_user_profile', array(&$this, 'user_profile_fields') );
  392.  
  393. add_action( 'show_user_profile', array(&$this, 'user_profile_fields') );
  394.  
  395.  
  396.  
  397. //update install script if necessary
  398.  
  399. if (get_option('mp_version') != $this->version) {
  400.  
  401. $this->install();
  402.  
  403. }
  404.  
  405. }
  406.  
  407.  
  408.  
  409. function install() {
  410.  
  411. $old_settings = get_option('mp_settings');
  412.  
  413. $old_version = get_option('mp_version');
  414.  
  415.  
  416.  
  417. //our default settings
  418.  
  419. $default_settings = array (
  420.  
  421. 'base_country' => 'US',
  422.  
  423. 'tax' => array (
  424.  
  425. 'rate' => 0,
  426.  
  427. 'label' => __('Taxes', 'mp'),
  428.  
  429. 'tax_shipping' => 1,
  430.  
  431. 'tax_inclusive' => 0,
  432.  
  433. 'tax_digital' => 1,
  434.  
  435. 'downloadable_address' => 0
  436.  
  437. ),
  438.  
  439. 'currency' => 'USD',
  440.  
  441. 'curr_symbol_position' => 1,
  442.  
  443. 'curr_decimal' => 1,
  444.  
  445. 'disable_cart' => 0,
  446.  
  447. 'hide_popup' => 0,
  448.  
  449. 'inventory_threshhold' => 3,
  450.  
  451. 'inventory_remove' => 0,
  452.  
  453. 'max_downloads' => 5,
  454.  
  455. 'download_order_limit' => 1,
  456.  
  457. 'force_login' => 0,
  458.  
  459. 'ga_ecommerce' => 'none',
  460.  
  461. 'special_instructions' => 0,
  462.  
  463. 'store_theme' => 'icons',
  464.  
  465. 'show_img' => 1,
  466.  
  467. 'product_img_height' => 150,
  468.  
  469. 'product_img_width' => 150,
  470.  
  471. 'list_img_height' => 150,
  472.  
  473. 'list_img_width' => 150,
  474.  
  475. 'show_excerpt' => 1,
  476.  
  477. 'per_page' => 20,
  478.  
  479. 'order_by' => 'title',
  480.  
  481. /* Translators: change default slugs here */
  482.  
  483. 'slugs' => array (
  484.  
  485. 'store' => __('store', 'mp'),
  486.  
  487. 'products' => __('products', 'mp'),
  488.  
  489. 'cart' => __('shopping-cart', 'mp'),
  490.  
  491. 'orderstatus' => __('order-status', 'mp'),
  492.  
  493. 'category' => __('category', 'mp'),
  494.  
  495. 'tag' => __('tag', 'mp')
  496.  
  497. ),
  498.  
  499. 'product_button_type' => 'addcart',
  500.  
  501. 'show_quantity' => 1,
  502.  
  503. 'product_img_size' => 'medium',
  504.  
  505. 'show_lightbox' => 1,
  506.  
  507. 'disable_large_image' => 0,
  508.  
  509. 'list_view' => 'grid',
  510.  
  511. 'list_button_type' => 'addcart',
  512.  
  513. 'show_thumbnail' => 1,
  514.  
  515. 'list_img_size' => 'thumbnail',
  516.  
  517. 'paginate' => 1,
  518.  
  519. 'show_filters' => 1,
  520.  
  521. 'order' => 'DESC',
  522.  
  523. 'show_purchase_breadcrumbs' => 1,
  524.  
  525. 'shipping' => array (
  526.  
  527. 'allowed_countries' => array ('CA', 'US'),
  528.  
  529. 'method' => 'flat-rate',
  530.  
  531. 'system' => 'english'
  532.  
  533. ),
  534.  
  535. 'gateways' => array (
  536.  
  537. 'paypal-express' => array (
  538.  
  539. 'locale' => 'US',
  540.  
  541. 'currency' => 'USD',
  542.  
  543. 'mode' => 'sandbox'
  544.  
  545. ),
  546.  
  547. 'paypal-chained' => array (
  548.  
  549. 'currency' => 'USD',
  550.  
  551. 'mode' => 'sandbox'
  552.  
  553. )
  554.  
  555. ),
  556.  
  557. 'msg' => array (
  558.  
  559. 'product_list' => '',
  560.  
  561. 'order_status' => __('<p>If you have any questions about your order please do not hesitate to contact us.</p>', 'mp'),
  562.  
  563. 'cart' => '',
  564.  
  565. 'shipping' => __('<p>Please enter your shipping information in the form below to proceed with your order.</p>', 'mp'),
  566.  
  567. 'checkout' => '',
  568.  
  569. 'confirm_checkout' => __('<p>You are almost done! Please do a final review of your order to make sure everything is correct then click the "Confirm Payment" button.</p>', 'mp'),
  570.  
  571. 'success' => __('<p>Thank you for your order! We appreciate your business, and please come back often to check out our new products.</p>', 'mp')
  572.  
  573. ),
  574.  
  575. 'store_email' => get_option("admin_email"),
  576.  
  577. 'email' => array (
  578.  
  579. 'new_order_subject' => __('Your Order Confirmation (ORDERID)', 'mp'),
  580.  
  581. 'new_order_txt' => __("Thank you for your order CUSTOMERNAME!
  582.  
  583.  
  584.  
  585. Your order has been received, and any items to be shipped will be processed as soon as possible. Please refer to your Order ID (ORDERID) whenever contacting us.
  586.  
  587. Here is a confirmation of your order details:
  588.  
  589.  
  590.  
  591. Order Information:
  592.  
  593. ORDERINFO
  594.  
  595.  
  596.  
  597. Shipping Information:
  598.  
  599. SHIPPINGINFO
  600.  
  601.  
  602.  
  603. Payment Information:
  604.  
  605. PAYMENTINFO
  606.  
  607.  
  608.  
  609. ORDERNOTES
  610.  
  611.  
  612.  
  613. You can track the latest status of your order here: TRACKINGURL
  614.  
  615.  
  616.  
  617. Thanks again!", 'mp'),
  618.  
  619. 'shipped_order_subject' => __('Your Order Has Been Shipped! (ORDERID)', 'mp'),
  620.  
  621. 'shipped_order_txt' => __("Dear CUSTOMERNAME,
  622.  
  623.  
  624.  
  625. Your order has been shipped! Depending on the shipping method and your location it should be arriving shortly. Please refer to your Order ID (ORDERID) whenever contacting us.
  626.  
  627. Here is a confirmation of your order details:
  628.  
  629.  
  630.  
  631. Order Information:
  632.  
  633. ORDERINFO
  634.  
  635.  
  636.  
  637. Shipping Information:
  638.  
  639. SHIPPINGINFO
  640.  
  641.  
  642.  
  643. Payment Information:
  644.  
  645. PAYMENTINFO
  646.  
  647.  
  648.  
  649. ORDERNOTES
  650.  
  651.  
  652.  
  653. You can track the latest status of your order here: TRACKINGURL
  654.  
  655.  
  656.  
  657. Thanks again!", 'mp')
  658.  
  659. ),
  660.  
  661. 'social' => array(
  662.  
  663. 'pinterest' => array(
  664.  
  665. 'show_pinit_button' => 'off',
  666.  
  667. 'show_pin_count' => 'none'
  668.  
  669. ),
  670.  
  671. ),
  672.  
  673. 'related_products' => array(
  674.  
  675. 'show' => 1,
  676.  
  677. 'relate_by' => 'both',
  678.  
  679. 'simple_list' => 0,
  680.  
  681. 'show_limit' => 3
  682.  
  683. ),
  684.  
  685. 'image_alignment_single' => 'alignleft',
  686.  
  687. 'image_alignment_list' => 'alignleft',
  688.  
  689. );
  690.  
  691.  
  692.  
  693. //filter default settings
  694.  
  695. $default_settings = apply_filters( 'mp_default_settings', $default_settings );
  696.  
  697. $settings = wp_parse_args( (array)$old_settings, $default_settings );
  698.  
  699. update_option( 'mp_settings', $settings );
  700.  
  701.  
  702.  
  703. //2.1.4 update
  704.  
  705. if ( version_compare($old_version, '2.1.4', '<') )
  706.  
  707. $this->update_214();
  708.  
  709.  
  710.  
  711. //only run these on first install
  712.  
  713. if ( empty($old_settings) ) {
  714.  
  715.  
  716.  
  717. //define settings that don't need to autoload for efficiency
  718.  
  719. add_option( 'mp_coupons', '', '', 'no' );
  720.  
  721. add_option( 'mp_store_page', '', '', 'no' );
  722.  
  723.  
  724.  
  725. //create store page
  726.  
  727. add_action( 'admin_init', array(&$this, 'create_store_page') );
  728.  
  729.  
  730.  
  731. //add cart widget to first sidebar
  732.  
  733. add_action( 'widgets_init', array(&$this, 'add_default_widget'), 11 );
  734.  
  735. }
  736.  
  737.  
  738.  
  739. //add action to flush rewrite rules after we've added them for the first time
  740.  
  741. update_option('mp_flush_rewrite', 1);
  742.  
  743.  
  744.  
  745. update_option( 'mp_version', $this->version );
  746.  
  747. }
  748.  
  749.  
  750.  
  751. //run on 2.1.4 update to fix price sorts
  752.  
  753. function update_214() {
  754.  
  755. global $wpdb;
  756.  
  757.  
  758.  
  759. $posts = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product'");
  760.  
  761.  
  762.  
  763. foreach ($posts as $post_id) {
  764.  
  765. $meta = get_post_custom($post_id);
  766.  
  767. //unserialize
  768.  
  769. foreach ($meta as $key => $val) {
  770.  
  771. $meta[$key] = maybe_unserialize($val[0]);
  772.  
  773. if (!is_array($meta[$key]) && $key != "mp_is_sale" && $key != "mp_track_inventory" && $key != "mp_product_link" && $key != "mp_file" && $key != "mp_price_sort")
  774.  
  775. $meta[$key] = array($meta[$key]);
  776.  
  777. }
  778.  
  779.  
  780.  
  781. //fix price sort field if missing
  782.  
  783. if ( empty($meta["mp_price_sort"]) && is_array($meta["mp_price"]) ) {
  784.  
  785. if ( $meta["mp_is_sale"] && $meta["mp_sale_price"][0] )
  786.  
  787. $sort_price = $meta["mp_sale_price"][0];
  788.  
  789. else
  790.  
  791. $sort_price = $meta["mp_price"][0];
  792.  
  793. update_post_meta($post_id, 'mp_price_sort', $sort_price);
  794.  
  795. }
  796.  
  797. }
  798.  
  799. }
  800.  
  801.  
  802.  
  803. function localization() {
  804.  
  805. // Load up the localization file if we're using WordPress in a different language
  806.  
  807. // Place it in this plugin's "languages" folder and name it "mp-[value in wp-config].mo"
  808.  
  809. $mu_plugins = wp_get_mu_plugins();
  810.  
  811. $lang_dir = dirname(plugin_basename($this->plugin_file)) . '/marketpress-includes/languages/';
  812.  
  813. $custom_path = WP_LANG_DIR . '/marketpress/mp-' . get_locale() . '.mo';
  814.  
  815.  
  816.  
  817. if ( file_exists($custom_path) ) {
  818.  
  819. load_textdomain('mp', $custom_path);
  820.  
  821. } elseif ( in_array($this->plugin_file, $mu_plugins) ) {
  822.  
  823. load_muplugin_textdomain('mp', $lang_dir);
  824.  
  825. } else {
  826.  
  827. load_plugin_textdomain('mp', false, $lang_dir);
  828.  
  829. }
  830.  
  831.  
  832.  
  833. //setup language code for jquery datepicker translation
  834.  
  835. $temp_locales = explode('_', get_locale());
  836.  
  837. $this->language = ($temp_locales[0]) ? $temp_locales[0] : 'en';
  838.  
  839. }
  840.  
  841.  
  842.  
  843. function init_vars() {
  844.  
  845. //setup proper directories
  846.  
  847. $this->plugin_file = __FILE__;
  848.  
  849. $this->plugin_dir = plugin_dir_path(__FILE__) . 'marketpress-includes/';
  850.  
  851. $this->plugin_url = plugin_dir_url(__FILE__) . 'marketpress-includes/';
  852.  
  853.  
  854.  
  855. //load data structures
  856.  
  857. require_once( $this->plugin_dir . 'marketpress-data.php' );
  858.  
  859. }
  860.  
  861.  
  862.  
  863. /* Only load code that needs BuddyPress to run once BP is loaded and initialized. */
  864.  
  865. function load_bp_features() {
  866.  
  867. include_once( $this->plugin_dir . 'marketpress-bp.php' );
  868.  
  869. }
  870.  
  871.  
  872.  
  873. function load_importers() {
  874.  
  875. include_once( $this->plugin_dir . 'marketpress-importers.php' );
  876.  
  877. }
  878.  
  879.  
  880.  
  881. function load_plugins() {
  882.  
  883. if (is_network_admin() || !$this->get_setting('disable_cart')) {
  884.  
  885. //load shipping plugin API
  886.  
  887. require_once( $this->plugin_dir . 'marketpress-shipping.php' );
  888.  
  889. $this->load_shipping_plugins();
  890.  
  891.  
  892.  
  893. //load gateway plugin API
  894.  
  895. require_once( $this->plugin_dir . 'marketpress-gateways.php' );
  896.  
  897. $this->load_gateway_plugins();
  898.  
  899. }
  900.  
  901. }
  902.  
  903.  
  904.  
  905. function load_shipping_plugins() {
  906.  
  907.  
  908.  
  909. //save shipping method. Put here to be before plugin is loaded
  910.  
  911. if (isset($_POST['shipping_settings'])) {
  912.  
  913. $settings = get_option('mp_settings');
  914.  
  915. $settings['shipping']['method'] = $_POST['mp']['shipping']['method'];
  916.  
  917. $settings['shipping']['calc_methods'] = isset($_POST['mp']['shipping']['calc_methods']) ? $_POST['mp']['shipping']['calc_methods'] : array();
  918.  
  919. update_option('mp_settings', $settings);
  920.  
  921. }
  922.  
  923.  
  924.  
  925. //get shipping plugins dir
  926.  
  927. $dir = $this->plugin_dir . 'plugins-shipping/';
  928.  
  929.  
  930.  
  931. //search the dir for files
  932.  
  933. $shipping_plugins = array();
  934.  
  935. if ( !is_dir( $dir ) )
  936.  
  937. return;
  938.  
  939. if ( ! $dh = opendir( $dir ) )
  940.  
  941. return;
  942.  
  943. while ( ( $plugin = readdir( $dh ) ) !== false ) {
  944.  
  945. if ( substr( $plugin, -4 ) == '.php' )
  946.  
  947. $shipping_plugins[] = $dir . $plugin;
  948.  
  949. }
  950.  
  951. closedir( $dh );
  952.  
  953. sort( $shipping_plugins );
  954.  
  955.  
  956.  
  957. //include them suppressing errors
  958.  
  959. foreach ($shipping_plugins as $file)
  960.  
  961. @include_once( $file );
  962.  
  963.  
  964.  
  965. //allow plugins from an external location to register themselves
  966.  
  967. do_action('mp_load_shipping_plugins');
  968.  
  969.  
  970.  
  971. //load chosen plugin class
  972.  
  973. global $mp_shipping_plugins, $mp_shipping_active_plugins;
  974.  
  975. $shipping = $this->get_setting('shipping');
  976.  
  977.  
  978.  
  979. if ($this->get_setting('shipping->method') == 'calculated') {
  980.  
  981. //load just the calculated ones
  982.  
  983. foreach ((array)$mp_shipping_plugins as $code => $plugin) {
  984.  
  985. if ($plugin[2]) {
  986.  
  987. if ( isset($shipping['calc_methods'][$code]) && class_exists($plugin[0]) && !$plugin[3] )
  988.  
  989. $mp_shipping_active_plugins[$code] = new $plugin[0];
  990.  
  991. }
  992.  
  993. }
  994.  
  995. } else {
  996.  
  997. //load only and all calculated ones
  998.  
  999. $class = isset($mp_shipping_plugins[$shipping['method']][0]) ? $mp_shipping_plugins[$shipping['method']][0] : '';
  1000.  
  1001. if (class_exists($class))
  1002.  
  1003. $mp_shipping_active_plugins[$shipping['method']] = new $class;
  1004.  
  1005. }
  1006.  
  1007. }
  1008.  
  1009.  
  1010.  
  1011. function load_gateway_plugins() {
  1012.  
  1013.  
  1014.  
  1015. //save settings from screen. Put here to be before plugin is loaded
  1016.  
  1017. if (isset($_POST['gateway_settings'])) {
  1018.  
  1019. $settings = get_option('mp_settings');
  1020.  
  1021.  
  1022.  
  1023. //see if there are checkboxes checked
  1024.  
  1025. if ( isset( $_POST['mp']['gateways']['allowed'] ) ) {
  1026.  
  1027. $settings['gateways']['allowed'] = $_POST['mp']['gateways']['allowed'];
  1028.  
  1029. } else {
  1030.  
  1031. //blank array if no checkboxes
  1032.  
  1033. $settings['gateways']['allowed'] = array();
  1034.  
  1035. }
  1036.  
  1037.  
  1038.  
  1039. update_option('mp_settings', $settings);
  1040.  
  1041. }
  1042.  
  1043.  
  1044.  
  1045. //get gateway plugins dir
  1046.  
  1047. $dir = $this->plugin_dir . 'plugins-gateway/';
  1048.  
  1049.  
  1050.  
  1051. //search the dir for files
  1052.  
  1053. $gateway_plugins = array();
  1054.  
  1055. if ( !is_dir( $dir ) )
  1056.  
  1057. return;
  1058.  
  1059. if ( ! $dh = opendir( $dir ) )
  1060.  
  1061. return;
  1062.  
  1063. while ( ( $plugin = readdir( $dh ) ) !== false ) {
  1064.  
  1065. if ( substr( $plugin, -4 ) == '.php' )
  1066.  
  1067. $gateway_plugins[] = $dir . '/' . $plugin;
  1068.  
  1069. }
  1070.  
  1071. closedir( $dh );
  1072.  
  1073. sort( $gateway_plugins );
  1074.  
  1075.  
  1076.  
  1077. //include them suppressing errors
  1078.  
  1079. foreach ($gateway_plugins as $file)
  1080.  
  1081. include( $file );
  1082.  
  1083.  
  1084.  
  1085. //allow plugins from an external location to register themselves
  1086.  
  1087. do_action('mp_load_gateway_plugins');
  1088.  
  1089.  
  1090.  
  1091. //load chosen plugin classes
  1092.  
  1093. global $mp_gateway_plugins, $mp_gateway_active_plugins;
  1094.  
  1095. $gateways = $this->get_setting('gateways');
  1096.  
  1097. $network_settings = get_site_option( 'mp_network_settings' );
  1098.  
  1099.  
  1100.  
  1101. foreach ((array)$mp_gateway_plugins as $code => $plugin) {
  1102.  
  1103. $class = $plugin[0];
  1104.  
  1105. //if global cart is enabled force it
  1106.  
  1107. if ( $this->global_cart ) {
  1108.  
  1109. if ( $code == $network_settings['global_gateway'] && class_exists($class) ) {
  1110.  
  1111. $mp_gateway_active_plugins[] = new $class;
  1112.  
  1113. break;
  1114.  
  1115. }
  1116.  
  1117. } else {
  1118.  
  1119. if ( isset( $gateways['allowed'] ) && in_array($code, (array)$gateways['allowed']) && class_exists($class) && !$plugin[3] )
  1120.  
  1121. $mp_gateway_active_plugins[] = new $class;
  1122.  
  1123. }
  1124.  
  1125. }
  1126.  
  1127. }
  1128.  
  1129.  
  1130.  
  1131. /*
  1132.  
  1133. * function get_setting
  1134.  
  1135. * @param string $key A setting key, or -> separated list of keys to go multiple levels into an array
  1136.  
  1137. * @param mixed $default Returns when setting is not set
  1138.  
  1139. *
  1140.  
  1141. * an easy way to get to our settings array without undefined indexes
  1142.  
  1143. */
  1144.  
  1145. function get_setting($key, $default = null) {
  1146.  
  1147. $settings = get_option( 'mp_settings' );
  1148.  
  1149. $keys = explode('->', $key);
  1150.  
  1151. array_map('trim', $keys);
  1152.  
  1153. if (count($keys) == 1)
  1154.  
  1155. $setting = isset($settings[$keys[0]]) ? $settings[$keys[0]] : $default;
  1156.  
  1157. else if (count($keys) == 2)
  1158.  
  1159. $setting = isset($settings[$keys[0]][$keys[1]]) ? $settings[$keys[0]][$keys[1]] : $default;
  1160.  
  1161. else if (count($keys) == 3)
  1162.  
  1163. $setting = isset($settings[$keys[0]][$keys[1]][$keys[2]]) ? $settings[$keys[0]][$keys[1]][$keys[2]] : $default;
  1164.  
  1165. else if (count($keys) == 4)
  1166.  
  1167. $setting = isset($settings[$keys[0]][$keys[1]][$keys[2]][$keys[3]]) ? $settings[$keys[0]][$keys[1]][$keys[2]][$keys[3]] : $default;
  1168.  
  1169.  
  1170.  
  1171. return apply_filters( "mp_setting_".implode('', $keys), $setting, $default );
  1172.  
  1173. }
  1174.  
  1175.  
  1176.  
  1177. function update_setting($key, $value) {
  1178.  
  1179. $settings = get_option( 'mp_settings' );
  1180.  
  1181. $settings[$key] = $value;
  1182.  
  1183. return update_option('mp_settings', $settings);
  1184.  
  1185. }
  1186.  
  1187.  
  1188.  
  1189. function handle_gateway_returns($wp_query) {
  1190.  
  1191. if ( is_admin() ) return;
  1192.  
  1193.  
  1194.  
  1195. //listen for gateway IPN returns and tie them in to proper gateway plugin
  1196.  
  1197. if(!empty($wp_query->query_vars['paymentgateway'])) {
  1198.  
  1199. do_action( 'mp_handle_payment_return_' . $wp_query->query_vars['paymentgateway'] );
  1200.  
  1201. // exit();
  1202.  
  1203. }
  1204.  
  1205. }
  1206.  
  1207.  
  1208.  
  1209. function remove_canonical($wp_query) {
  1210.  
  1211. if ( is_admin() ) return;
  1212.  
  1213.  
  1214.  
  1215. //stop canonical problems with virtual pages redirecting
  1216.  
  1217. $page = get_query_var('pagename');
  1218.  
  1219. if ($page == 'cart' || $page == 'orderstatus' || $page == 'product_list') {
  1220.  
  1221. remove_action('template_redirect', 'redirect_canonical');
  1222.  
  1223. }
  1224.  
  1225. }
  1226.  
  1227.  
  1228.  
  1229. function admin_nopermalink_warning() {
  1230.  
  1231. //warns admins if permalinks are not enabled on the blog
  1232.  
  1233. if ( current_user_can('manage_options') && !get_option('permalink_structure') )
  1234.  
  1235. echo '<div class="error"><p>'.__('You must enable Pretty Permalinks</a> to use MarketPress - <a href="options-permalink.php">Enable now &raquo;</a>', 'mp').'</p></div>';
  1236.  
  1237. }
  1238.  
  1239.  
  1240.  
  1241. function plugin_action_link($links, $file) {
  1242.  
  1243. // the anchor tag and href to the URL we want. For a "Settings" link, this needs to be the url of your settings page
  1244.  
  1245. $settings_link = '<a href="' . admin_url('edit.php?post_type=product&page=marketpress') . '">' . __('Settings', 'mp') . '</a>';
  1246.  
  1247. // add the link to the list
  1248.  
  1249. array_unshift($links, $settings_link);
  1250.  
  1251. return $links;
  1252.  
  1253. }
  1254.  
  1255.  
  1256.  
  1257. function add_menu_items() {
  1258.  
  1259. //only process the manage orders page for editors and above and if orders hasn't been disabled
  1260.  
  1261. if (current_user_can('edit_others_posts') && !$this->get_setting('disable_cart')) {
  1262.  
  1263. $num_posts = wp_count_posts('mp_order'); //get pending order count
  1264.  
  1265. $count = $num_posts->order_received + $num_posts->order_paid;
  1266.  
  1267. if ( $count > 0 )
  1268.  
  1269. $count_output = '&nbsp;<span class="update-plugins"><span class="updates-count count-' . $count . '">' . $count . '</span></span>';
  1270.  
  1271. else
  1272.  
  1273. $count_output = '';
  1274.  
  1275. $orders_page = add_submenu_page('edit.php?post_type=product', __('Manage Orders', 'mp'), __('Manage Orders', 'mp') . $count_output, 'edit_others_posts', 'marketpress-orders', array(&$this, 'orders_page'));
  1276.  
  1277. }
  1278.  
  1279.  
  1280.  
  1281. $page = add_submenu_page('edit.php?post_type=product', __('Store Settings', 'mp'), __('Store Settings', 'mp'), 'manage_options', 'marketpress', array(&$this, 'admin_page'));
  1282.  
  1283. add_action( 'admin_print_scripts-' . $page, array(&$this, 'admin_script_settings') );
  1284.  
  1285. add_action( 'admin_print_styles-' . $page, array(&$this, 'admin_css_settings') );
  1286.  
  1287.  
  1288.  
  1289. if ( !defined('WPMUDEV_REMOVE_BRANDING') ) {
  1290.  
  1291. add_action( "load-{$page}", array( &$this, 'add_help_tab' ) );
  1292.  
  1293. }
  1294.  
  1295. }
  1296.  
  1297.  
  1298.  
  1299. function add_help_tab() {
  1300.  
  1301. get_current_screen()->add_help_tab( array(
  1302.  
  1303. 'id' => 'marketpress-help',
  1304.  
  1305. 'title' => __('MarketPress Instructions', 'mp'),
  1306.  
  1307. 'content' => '<iframe src="http://premium.wpmudev.org/wdp-un.php?action=help&id=144" width="100%" height="600px"></iframe>'
  1308.  
  1309. ) );
  1310.  
  1311. }
  1312.  
  1313.  
  1314.  
  1315. function admin_css() {
  1316.  
  1317. wp_enqueue_style( 'mp-admin-css', $this->plugin_url . 'css/marketpress.css', false, $this->version);
  1318.  
  1319. }
  1320.  
  1321.  
  1322.  
  1323. //enqeue js on custom post edit screen
  1324.  
  1325. function admin_script_post() {
  1326.  
  1327. global $current_screen;
  1328.  
  1329. if ($current_screen->id == 'product')
  1330.  
  1331. wp_enqueue_script( 'mp-post', $this->plugin_url . 'js/post-screen.js', array('jquery'), $this->version);
  1332.  
  1333. }
  1334.  
  1335.  
  1336.  
  1337. //enqeue css on product settings screen
  1338.  
  1339. function admin_css_settings() {
  1340.  
  1341. wp_enqueue_style( 'jquery-datepicker-css', $this->plugin_url . 'datepicker/css/smoothness/jquery-ui-1.10.3.custom.min.css', false, $this->version);
  1342.  
  1343. wp_enqueue_style( 'jquery-colorpicker-css', $this->plugin_url . 'colorpicker/css/colorpicker.css', false, $this->version);
  1344.  
  1345. }
  1346.  
  1347.  
  1348.  
  1349. //enqeue js on product settings screen
  1350.  
  1351. function admin_script_settings() {
  1352.  
  1353. wp_enqueue_script( 'jquery-colorpicker', $this->plugin_url . 'colorpicker/js/colorpicker.js', array('jquery'), $this->version);
  1354.  
  1355. wp_enqueue_script( 'jquery-ui-datepicker');//use built in version
  1356.  
  1357.  
  1358.  
  1359. //only load languages for datepicker if not english (or it will show Chinese!)
  1360.  
  1361. if ($this->language != 'en')
  1362.  
  1363. wp_enqueue_script( 'jquery-datepicker-i18n', $this->plugin_url . 'datepicker/js/jquery-ui-i18n.min.js', array('jquery', 'jquery-ui-core', 'jquery-datepicker'), $this->version);
  1364.  
  1365.  
  1366.  
  1367. if (!defined('WPMUDEV_REMOVE_BRANDING') && intval($this->get_setting('hide_popup')) < 3) {
  1368.  
  1369. wp_enqueue_script( 'mp-need-help', $this->plugin_url . 'js/need-help.js', array('jquery'), $this->version);
  1370.  
  1371. $new_count = intval($this->get_setting('hide_popup')) + 1;
  1372.  
  1373. $this->update_setting('hide_popup', $new_count);
  1374.  
  1375. }
  1376.  
  1377. }
  1378.  
  1379.  
  1380.  
  1381. //ties into the ajax request to disable help popup if clicked
  1382.  
  1383. function hide_help() {
  1384.  
  1385. $this->update_setting('hide_popup', 3);
  1386.  
  1387. }
  1388.  
  1389.  
  1390.  
  1391. //ajax cart handling for store frontend
  1392.  
  1393. function store_script() {
  1394.  
  1395. //setup ajax cart javascript
  1396.  
  1397. wp_enqueue_script( 'mp-ajax-js', $this->plugin_url . 'js/ajax-cart.js', array('jquery'), $this->version );
  1398.  
  1399.  
  1400.  
  1401. //get all product category links for access in js
  1402.  
  1403. $vars = array(
  1404.  
  1405. 'ajaxUrl' => admin_url('admin-ajax.php', (is_ssl() ? 'https': 'http')),
  1406.  
  1407. 'emptyCartMsg' => __('Are you sure you want to remove all items from your cart?', 'mp'),
  1408.  
  1409. 'successMsg' => __('Item(s) Added!', 'mp'),
  1410.  
  1411. 'imgUrl' => $this->plugin_url.'images/loading.gif',
  1412.  
  1413. 'addingMsg' => __('Adding to your cart...', 'mp'),
  1414.  
  1415. 'outMsg' => __('In Your Cart', 'mp'),
  1416.  
  1417. 'showFilters' => $this->get_setting('show_filters'),
  1418.  
  1419. 'links' => array('-1' => home_url($this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products'))),
  1420.  
  1421. );
  1422.  
  1423.  
  1424.  
  1425. if ( 'product_category' == get_query_var('taxonomy') && '' != get_query_var('term') ) {
  1426.  
  1427. $cat = get_term_by('slug', get_query_var('term'), 'product_category');
  1428.  
  1429. $vars['productCategory'] = $cat->term_id;
  1430.  
  1431. } else {
  1432.  
  1433. $vars['productCategory'] = '-1';
  1434.  
  1435. }
  1436.  
  1437.  
  1438.  
  1439. $terms = get_terms('product_category');
  1440.  
  1441.  
  1442.  
  1443. if ( is_array($terms) ) {
  1444.  
  1445. foreach ( $terms as $term ) {
  1446.  
  1447. $vars['links'][$term->term_id] = get_term_link($term);
  1448.  
  1449. }
  1450.  
  1451. }
  1452.  
  1453.  
  1454.  
  1455. // declare the variables we need to access in js
  1456.  
  1457. wp_localize_script('mp-ajax-js', 'MP_Ajax', $vars);
  1458.  
  1459. }
  1460.  
  1461.  
  1462.  
  1463. //loads the jquery lightbox plugin
  1464.  
  1465. function enqueue_lightbox() {
  1466.  
  1467. if ( !$this->get_setting('show_lightbox') )
  1468.  
  1469. return;
  1470.  
  1471.  
  1472.  
  1473. wp_enqueue_style('mp-lightbox', $this->plugin_url . 'lightbox/style/lumebox.css', false, $this->version); //we enqueue styles on every page just in case of shortcodes http://wp.mu/8ou
  1474.  
  1475. wp_register_script('mp-lightbox', $this->plugin_url . 'lightbox/js/jquery.lumebox.min.js', array('jquery'), $this->version, true); //we just register the script here - we can output selectively later
  1476.  
  1477.  
  1478.  
  1479. // declare the variables we need to access in js
  1480.  
  1481. $js_vars = array( 'graphicsDir' => $this->plugin_url . 'lightbox/style/' );
  1482.  
  1483. wp_localize_script('mp-lightbox', 'lumeboxOptions', $js_vars);
  1484.  
  1485. }
  1486.  
  1487.  
  1488.  
  1489. //if cart widget is not in a sidebar, add it to the top of the first sidebar. Only runs at initial install
  1490.  
  1491. function add_default_widget() {
  1492.  
  1493. if (!is_active_widget(false, false, 'mp_cart_widget')) {
  1494.  
  1495. $sidebars_widgets = wp_get_sidebars_widgets();
  1496.  
  1497. if ( is_array($sidebars_widgets) ) {
  1498.  
  1499. foreach ( $sidebars_widgets as $sidebar => $widgets ) {
  1500.  
  1501. if ( 'wp_inactive_widgets' == $sidebar )
  1502.  
  1503. continue;
  1504.  
  1505.  
  1506.  
  1507. if ( is_array($widgets) ) {
  1508.  
  1509. array_unshift($widgets, 'mp_cart_widget-1');
  1510.  
  1511. $sidebars_widgets[$sidebar] = $widgets;
  1512.  
  1513. wp_set_sidebars_widgets( $sidebars_widgets );
  1514.  
  1515. $settings = array();
  1516.  
  1517. $settings[1] = array( 'title' => __('Shopping Cart', 'mp'), 'custom_text' => '', 'show_thumbnail' => 1, 'size' => 25 );
  1518.  
  1519. $settings['_multiwidget'] = 1;
  1520.  
  1521. update_option( 'widget_mp_cart_widget', $settings );
  1522.  
  1523. return true;
  1524.  
  1525. }
  1526.  
  1527. }
  1528.  
  1529. }
  1530.  
  1531. }
  1532.  
  1533. }
  1534.  
  1535.  
  1536.  
  1537. //creates the store page on install and updates
  1538.  
  1539. function create_store_page($old_slug = false) {
  1540.  
  1541. global $wpdb;
  1542.  
  1543.  
  1544.  
  1545. //remove old page if updating
  1546.  
  1547. if ($old_slug && $old_slug != $this->get_setting('slugs->store')) {
  1548.  
  1549. $old_post_id = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s AND post_type = 'page'", $old_slug) );
  1550.  
  1551. $old_post = get_post($old_post_id);
  1552.  
  1553.  
  1554.  
  1555. $old_post->post_name = $this->get_setting('slugs->store');
  1556.  
  1557. wp_update_post($old_post);
  1558.  
  1559. }
  1560.  
  1561.  
  1562.  
  1563. //insert new page if not existing
  1564.  
  1565. $page_count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->posts . " WHERE post_name = %s AND post_type = 'page'", $this->get_setting('slugs->store')) );
  1566.  
  1567. if ( !$page_count ) {
  1568.  
  1569.  
  1570.  
  1571. //default page content
  1572.  
  1573. $content = '<p>' . __('Welcome to our online store! Feel free to browse around:', 'mp') . '</p>';
  1574.  
  1575. $content .= '[mp_store_navigation]';
  1576.  
  1577. $content .= '<p>' . __('Check out our most popular products:', 'mp') . '</p>';
  1578.  
  1579. $content .= '[mp_popular_products]';
  1580.  
  1581. $content .= '<p>' . __('Browse by category:', 'mp') . '</p>';
  1582.  
  1583. $content .= '[mp_list_categories]';
  1584.  
  1585. $content .= '<p>' . __('Browse by tag:', 'mp') . '</p>';
  1586.  
  1587. $content .= '[mp_tag_cloud]';
  1588.  
  1589.  
  1590.  
  1591. $id = wp_insert_post( array('post_title' => __('Store', 'mp'), 'post_name' => $this->get_setting('slugs->store'), 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => $content ) );
  1592.  
  1593. update_option('mp_store_page', $id);
  1594.  
  1595. }
  1596.  
  1597. }
  1598.  
  1599.  
  1600.  
  1601. function register_custom_posts() {
  1602.  
  1603. global $wp_version;
  1604.  
  1605.  
  1606.  
  1607. // Register product categories
  1608.  
  1609. register_taxonomy('product_category', 'product', apply_filters('mp_register_product_category', array(
  1610.  
  1611. 'hierarchical' => true,
  1612.  
  1613. 'label' => __('Product Categories', 'mp'),
  1614.  
  1615. 'singular_label' => __('Product Category', 'mp'),
  1616.  
  1617. 'rewrite' => array(
  1618.  
  1619. 'with_front' => false,
  1620.  
  1621. 'slug' => $this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products') . '/' . $this->get_setting('slugs->category')
  1622.  
  1623. ),
  1624.  
  1625. )));
  1626.  
  1627.  
  1628.  
  1629. // Register product tags
  1630.  
  1631. register_taxonomy('product_tag', 'product', apply_filters('mp_register_product_tag', array(
  1632.  
  1633. 'hierarchical' => false,
  1634.  
  1635. 'label' => __('Product Tags', 'mp'),
  1636.  
  1637. 'singular_label' => __('Product Tag', 'mp'),
  1638.  
  1639. 'rewrite' => array(
  1640.  
  1641. 'with_front' => false,
  1642.  
  1643. 'slug' => $this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products') . '/' . $this->get_setting('slugs->tag')
  1644.  
  1645. ),
  1646.  
  1647. )));
  1648.  
  1649.  
  1650.  
  1651. //get proper icon format
  1652.  
  1653. $icon = version_compare($wp_version, '3.8', '>=') ? 'dashicons-cart' : $this->plugin_url . 'images/marketpress-icon.png';
  1654.  
  1655.  
  1656.  
  1657. // Register custom product post type
  1658.  
  1659. register_post_type('product' , apply_filters('mp_register_post_type', array(
  1660.  
  1661. 'labels' => array(
  1662.  
  1663. 'name' => __('Products', 'mp'),
  1664.  
  1665. 'singular_name' => __('Product', 'mp'),
  1666.  
  1667. 'menu_name' => __('Products', 'mp'),
  1668.  
  1669. 'all_items' => __('Products', 'mp'),
  1670.  
  1671. 'add_new' => __('Create New', 'mp'),
  1672.  
  1673. 'add_new_item' => __('Create New Product', 'mp'),
  1674.  
  1675. 'edit_item' => __('Edit Product', 'mp'),
  1676.  
  1677. 'edit' => __('Edit', 'mp'),
  1678.  
  1679. 'new_item' => __('New Product', 'mp'),
  1680.  
  1681. 'view_item' => __('View Product', 'mp'),
  1682.  
  1683. 'search_items' => __('Search Products', 'mp'),
  1684.  
  1685. 'not_found' => __('No Products Found', 'mp'),
  1686.  
  1687. 'not_found_in_trash' => __('No Products found in Trash', 'mp'),
  1688.  
  1689. 'view' => __('View Product', 'mp')
  1690.  
  1691. ),
  1692.  
  1693. 'description' => __('Products for your e-commerce store.', 'mp'),
  1694.  
  1695. 'public' => true,
  1696.  
  1697. 'show_ui' => true,
  1698.  
  1699. 'publicly_queryable' => true,
  1700.  
  1701. 'capability_type' => 'page',
  1702.  
  1703. 'hierarchical' => false,
  1704.  
  1705. 'menu_icon' => $icon,
  1706.  
  1707. 'rewrite' => array(
  1708.  
  1709. 'slug' => $this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products'),
  1710.  
  1711. 'with_front' => false
  1712.  
  1713. ),
  1714.  
  1715. 'query_var' => true,
  1716.  
  1717. 'supports' => array(
  1718.  
  1719. 'title',
  1720.  
  1721. 'editor',
  1722.  
  1723. 'author',
  1724.  
  1725. 'excerpt',
  1726.  
  1727. 'revisions',
  1728.  
  1729. 'thumbnail',
  1730.  
  1731. ),
  1732.  
  1733. 'taxonomies' => array(
  1734.  
  1735. 'product_category',
  1736.  
  1737. 'product_tag',
  1738.  
  1739. ),
  1740.  
  1741. )));
  1742.  
  1743.  
  1744.  
  1745. //register the orders post type
  1746.  
  1747. register_post_type('mp_order', apply_filters('mp_register_post_type_mp_order', array(
  1748.  
  1749. 'labels' => array('name' => __('Orders', 'mp'),
  1750.  
  1751. 'singular_name' => __('Order', 'mp'),
  1752.  
  1753. 'edit' => __('Edit', 'mp'),
  1754.  
  1755. 'view_item' => __('View Order', 'mp'),
  1756.  
  1757. 'search_items' => __('Search Orders', 'mp'),
  1758.  
  1759. 'not_found' => __('No Orders Found', 'mp')
  1760.  
  1761. ),
  1762.  
  1763. 'description' => __('Orders from your e-commerce store.', 'mp'),
  1764.  
  1765. 'public' => false,
  1766.  
  1767. 'show_ui' => false,
  1768.  
  1769. 'capability_type' => apply_filters('mp_orders_capability', 'page'),
  1770.  
  1771. 'hierarchical' => false,
  1772.  
  1773. 'rewrite' => false,
  1774.  
  1775. 'query_var' => false,
  1776.  
  1777. 'supports' => array(),
  1778.  
  1779. )));
  1780.  
  1781.  
  1782.  
  1783. //register custom post statuses for our orders
  1784.  
  1785. register_post_status( 'order_received', array(
  1786.  
  1787. 'label' => __('Received', 'mp'),
  1788.  
  1789. 'label_count' => array( __('Received <span class="count">(%s)</span>', 'mp'), __('Received <span class="count">(%s)</span>', 'mp') ),
  1790.  
  1791. 'post_type' => 'mp_order',
  1792.  
  1793. 'public' => false
  1794.  
  1795. ) );
  1796.  
  1797. register_post_status( 'order_paid', array(
  1798.  
  1799. 'label' => __('Paid', 'mp'),
  1800.  
  1801. 'label_count' => array( __('Paid <span class="count">(%s)</span>', 'mp'), __('Paid <span class="count">(%s)</span>', 'mp') ),
  1802.  
  1803. 'post_type' => 'mp_order',
  1804.  
  1805. 'public' => false
  1806.  
  1807. ) );
  1808.  
  1809. register_post_status( 'order_shipped', array(
  1810.  
  1811. 'label' => __('Shipped', 'mp'),
  1812.  
  1813. 'label_count' => array( __('Shipped <span class="count">(%s)</span>', 'mp'), __('Shipped <span class="count">(%s)</span>', 'mp') ),
  1814.  
  1815. 'post_type' => 'mp_order',
  1816.  
  1817. 'public' => false
  1818.  
  1819. ) );
  1820.  
  1821. register_post_status( 'order_closed', array(
  1822.  
  1823. 'label' => __('Closed', 'mp'),
  1824.  
  1825. 'label_count' => array( __('Closed <span class="count">(%s)</span>', 'mp'), __('Closed <span class="count">(%s)</span>', 'mp') ),
  1826.  
  1827. 'post_type' => 'mp_order',
  1828.  
  1829. 'public' => false
  1830.  
  1831. ) );
  1832.  
  1833. register_post_status( 'trash', array(
  1834.  
  1835. 'label' => _x( 'Trash', 'post' ),
  1836.  
  1837. 'label_count' => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ),
  1838.  
  1839. 'show_in_admin_status_list' => true,
  1840.  
  1841. 'post_type' => 'mp_order',
  1842.  
  1843. 'public' => false
  1844.  
  1845. ) );
  1846.  
  1847. }
  1848.  
  1849.  
  1850.  
  1851. //necessary to mod array directly rather than with add_theme_support() to play nice with other themes. See http://www.wptavern.com/forum/plugins-hacks/1751-need-help-enabling-post-thumbnails-custom-post-type.html
  1852.  
  1853. function post_thumbnails() {
  1854.  
  1855. global $_wp_theme_features;
  1856.  
  1857.  
  1858.  
  1859. if( !isset( $_wp_theme_features['post-thumbnails'] ) )
  1860.  
  1861. $_wp_theme_features['post-thumbnails'] = array( array( 'product' ) );
  1862.  
  1863. else if ( is_array( $_wp_theme_features['post-thumbnails'] ) )
  1864.  
  1865. $_wp_theme_features['post-thumbnails'][0][] = 'product';
  1866.  
  1867. }
  1868.  
  1869.  
  1870.  
  1871. // This function clears the rewrite rules and forces them to be regenerated
  1872.  
  1873. function flush_rewrite_check() {
  1874.  
  1875. if ( get_option('mp_flush_rewrite') ) {
  1876.  
  1877. flush_rewrite_rules();
  1878.  
  1879. delete_option('mp_flush_rewrite');
  1880.  
  1881. }
  1882.  
  1883. }
  1884.  
  1885.  
  1886.  
  1887. function add_rewrite_rules($rules) {
  1888.  
  1889. $new_rules = array();
  1890.  
  1891.  
  1892.  
  1893. //product list
  1894.  
  1895. $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products') . '/?$'] = 'index.php?pagename=product_list';
  1896.  
  1897. $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products') . '/page/?([0-9]{1,})/?$'] = 'index.php?pagename=product_list&paged=$matches[1]';
  1898.  
  1899.  
  1900.  
  1901. //checkout page
  1902.  
  1903. $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->cart') . '/?$'] = 'index.php?pagename=cart';
  1904.  
  1905. $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->cart') . '/([^/]+)/?$'] = 'index.php?pagename=cart&checkoutstep=$matches[1]';
  1906.  
  1907.  
  1908.  
  1909. //order status page
  1910.  
  1911. $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->orderstatus') . '/?$'] = 'index.php?pagename=orderstatus';
  1912.  
  1913. $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->orderstatus') . '/([^/]+)/?$'] = 'index.php?pagename=orderstatus&order_id=$matches[1]';
  1914.  
  1915.  
  1916.  
  1917. //ipn handling for payment gateways
  1918.  
  1919. $new_rules[$this->get_setting('slugs->store') . '/payment-return/(.+)'] = 'index.php?paymentgateway=$matches[1]';
  1920.  
  1921.  
  1922.  
  1923. return array_merge($new_rules, $rules);
  1924.  
  1925. }
  1926.  
  1927.  
  1928.  
  1929. //unfortunately some plugins flush rewrites before the init hook so they kill custom post type rewrites. This function verifies they are in the final array and flushes if not
  1930.  
  1931. function check_rewrite_rules($value) {
  1932.  
  1933.  
  1934.  
  1935. //prevent an infinite loop by only
  1936.  
  1937. if ( ! post_type_exists( 'product' ) )
  1938.  
  1939. return $value;
  1940.  
  1941.  
  1942.  
  1943. if ( is_array($value) && !in_array('index.php?product=$matches[1]&paged=$matches[2]', $value) ) {
  1944.  
  1945. update_option('mp_flush_rewrite', 1);
  1946.  
  1947. } else {
  1948.  
  1949. return $value;
  1950.  
  1951. }
  1952.  
  1953. }
  1954.  
  1955.  
  1956.  
  1957. function add_queryvars($vars) {
  1958.  
  1959. // This function add the checkout queryvars to the list that WordPress is looking for.
  1960.  
  1961. if(!in_array('checkoutstep', $vars))
  1962.  
  1963. $vars[] = 'checkoutstep';
  1964.  
  1965.  
  1966.  
  1967. if(!in_array('order_id', $vars))
  1968.  
  1969. $vars[] = 'order_id';
  1970.  
  1971.  
  1972.  
  1973. if(!in_array('paymentgateway', $vars))
  1974.  
  1975. $vars[] = 'paymentgateway';
  1976.  
  1977.  
  1978.  
  1979. return $vars;
  1980.  
  1981. }
  1982.  
  1983.  
  1984.  
  1985. /**
  1986.  
  1987. * Securely starts our session for handling cart info, etc
  1988.  
  1989. */
  1990.  
  1991. function start_session() {
  1992. $sess_id = session_id();
  1993.  
  1994. if ( !empty($sess_id) ) {
  1995. $temp_sess = $_SESSION;
  1996. session_destroy(); //destroy the possibly unsafe session (maybe from another plugin)
  1997. }
  1998.  
  1999. $httponly = true; //session cookies not available to javascript? (true = safest)
  2000. $session_hashes = array('sha512', 'sha384', 'sha256', 'sha224', 'sha1');
  2001. $secure = false; //force https?
  2002. $session_name = 'mp_session';
  2003. $hash_algos = hash_algos();
  2004.  
  2005. //attempt to set the hashing algorithm starting strongest to least strong
  2006. foreach ( $session_hashes as $session_hash ) {
  2007. if ( in_array($session_hash, $hash_algos) ) {
  2008. ini_set('session.hash_function', $session_hash);
  2009. break;
  2010. }
  2011. }
  2012.  
  2013. // How many bits per character of the hash.
  2014. // The possible values are '4' (0-9, a-f), '5' (0-9, a-v), and '6' (0-9, a-z, A-Z, "-", ",").
  2015. ini_set('session.hash_bits_per_character', 5);
  2016.  
  2017. // Force the session to only use cookies, not URL variables.
  2018. ini_set('session.use_only_cookies', 1);
  2019.  
  2020. // Get session cookie parameters
  2021. $cookie_params = session_get_cookie_params();
  2022.  
  2023. // Set the cookie parameters
  2024. session_set_cookie_params($cookie_params['lifetime'], $cookie_params['path'], $cookie_params['domain'], $secure, $httponly);
  2025.  
  2026. // Change the session name
  2027. session_name($session_name);
  2028.  
  2029. // Start the session
  2030. session_start();
  2031.  
  2032. // Regenerate the session and delete the old one.
  2033. session_regenerate_id(true);
  2034.  
  2035. // Restore any old $_SESSION variables
  2036. if ( isset($temp_sess) ) {
  2037. $_SESSION = array_merge($_SESSION, $temp_sess);
  2038. }
  2039.  
  2040.  
  2041.  
  2042. function logout_clear_session() {
  2043.  
  2044. //clear personal info
  2045.  
  2046. unset($_SESSION['mp_shipping_info']);
  2047.  
  2048. unset($_SESSION['mp_billing_info']);
  2049.  
  2050.  
  2051.  
  2052. //remove coupon code
  2053.  
  2054. if (is_multisite()) {
  2055.  
  2056. global $blog_id;
  2057.  
  2058. unset($_SESSION['mp_cart_coupon_' . $blog_id]);
  2059.  
  2060. } else {
  2061.  
  2062. unset($_SESSION['mp_cart_coupon']);
  2063.  
  2064. }
  2065.  
  2066. }
  2067.  
  2068.  
  2069.  
  2070. //scans post type at template_redirect to apply custom themeing to products
  2071.  
  2072. function load_store_templates() {
  2073.  
  2074. global $wp_query, $mp_wpmu, $mp_gateway_active_plugins;
  2075.  
  2076.  
  2077.  
  2078. //only filter public side
  2079.  
  2080. if (is_admin()) return;
  2081.  
  2082.  
  2083.  
  2084. //load proper theme for single product page display
  2085.  
  2086. if ($wp_query->is_single && $wp_query->query_vars['post_type'] == 'product') {
  2087.  
  2088.  
  2089.  
  2090. //check for custom theme templates
  2091.  
  2092. $product_name = get_query_var('product');
  2093.  
  2094. $product_id = (int) $wp_query->get_queried_object_id();
  2095.  
  2096.  
  2097.  
  2098. //serve download if it exists
  2099.  
  2100. $this->serve_download($product_id);
  2101.  
  2102.  
  2103.  
  2104. $templates = array();
  2105.  
  2106. if ( $product_name )
  2107.  
  2108. $templates[] = "mp_product-$product_name.php";
  2109.  
  2110. if ( $product_id )
  2111.  
  2112. $templates[] = "mp_product-$product_id.php";
  2113.  
  2114. $templates[] = "mp_product.php";
  2115.  
  2116.  
  2117.  
  2118. //if custom template exists load it
  2119.  
  2120. if ($this->product_template = locate_template($templates)) {
  2121.  
  2122. add_filter( 'template_include', array(&$this, 'custom_product_template') );
  2123.  
  2124. } else {
  2125.  
  2126. //otherwise load the page template and use our own theme
  2127.  
  2128. $wp_query->is_single = null;
  2129.  
  2130. $wp_query->is_page = 1;
  2131.  
  2132. add_filter( 'the_content', array(&$this, 'product_theme'), 99 );
  2133.  
  2134.  
  2135.  
  2136. //genesis fixes
  2137.  
  2138. remove_action( 'genesis_entry_content', 'genesis_do_post_image' );
  2139.  
  2140. remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
  2141.  
  2142. remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
  2143.  
  2144. add_action('genesis_entry_content', 'the_content');
  2145.  
  2146. }
  2147.  
  2148.  
  2149.  
  2150. $this->is_shop_page = true;
  2151.  
  2152. wp_enqueue_script('mp-lightbox');
  2153.  
  2154. }
  2155.  
  2156.  
  2157.  
  2158. //load proper theme for main store page
  2159.  
  2160. $slugs = $this->get_setting('slugs');
  2161.  
  2162. if ($wp_query->query_vars['pagename'] == $this->get_setting('slugs->store')) {
  2163.  
  2164.  
  2165.  
  2166. //check for custom theme template
  2167.  
  2168. $templates = array("mp_store.php");
  2169.  
  2170.  
  2171.  
  2172. //if custom template exists load it
  2173.  
  2174. if ($this->store_template = locate_template($templates)) {
  2175.  
  2176. add_filter( 'template_include', array(&$this, 'custom_store_template') );
  2177.  
  2178. } else {
  2179.  
  2180. //otherwise load the page template and use our own theme
  2181.  
  2182. add_filter( 'the_content', array(&$this, 'store_theme'), 99 );
  2183.  
  2184. }
  2185.  
  2186.  
  2187.  
  2188. $this->is_shop_page = true;
  2189.  
  2190. }
  2191.  
  2192.  
  2193.  
  2194. //load proper theme for checkout page
  2195.  
  2196. if ($wp_query->query_vars['pagename'] == 'cart') {
  2197.  
  2198. //process cart updates
  2199.  
  2200. $this->update_cart();
  2201.  
  2202.  
  2203.  
  2204. //if global cart is on forward to main site checkout
  2205.  
  2206. if ( $this->global_cart && is_object($mp_wpmu) && !$mp_wpmu->is_main_site() ) {
  2207.  
  2208. wp_redirect( mp_cart_link(false, true) );
  2209.  
  2210. exit;
  2211.  
  2212. }
  2213.  
  2214.  
  2215.  
  2216. // Redirect to https if forced to use SSL by a payment gateway
  2217.  
  2218. if (get_query_var('checkoutstep')) {
  2219.  
  2220. foreach ((array)$mp_gateway_active_plugins as $plugin) {
  2221.  
  2222. if ($plugin->force_ssl) {
  2223.  
  2224. if ( !is_ssl() ) {
  2225.  
  2226. wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  2227.  
  2228. exit();
  2229.  
  2230. }
  2231.  
  2232. }
  2233.  
  2234. }
  2235.  
  2236. }
  2237.  
  2238.  
  2239.  
  2240. //force login if required
  2241.  
  2242. if (!is_user_logged_in() && $this->get_setting('force_login') && get_query_var('checkoutstep')) {
  2243.  
  2244. wp_redirect( wp_login_url( mp_checkout_step_url( get_query_var('checkoutstep') ) ) );
  2245.  
  2246. exit();
  2247.  
  2248. }
  2249.  
  2250.  
  2251.  
  2252. //setup shopping cart javascript
  2253.  
  2254. wp_enqueue_script( 'mp-store-js', $this->plugin_url . 'js/store.js', array('jquery'), $this->version );
  2255.  
  2256.  
  2257.  
  2258. //check for custom theme template
  2259.  
  2260. $templates = array("mp_cart.php");
  2261.  
  2262.  
  2263.  
  2264. //if custom template exists load it
  2265.  
  2266. if ($this->checkout_template = locate_template($templates)) {
  2267.  
  2268. add_filter( 'template_include', array(&$this, 'custom_checkout_template') );
  2269.  
  2270. add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
  2271.  
  2272. add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
  2273.  
  2274. add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
  2275.  
  2276. } else {
  2277.  
  2278. //otherwise load the page template and use our own theme
  2279.  
  2280. add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
  2281.  
  2282. add_filter( 'the_title', array(&$this, 'page_title_output'), 99 );
  2283.  
  2284. add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
  2285.  
  2286. add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
  2287.  
  2288. add_filter( 'the_content', array(&$this, 'checkout_theme'), 99 );
  2289.  
  2290. }
  2291.  
  2292.  
  2293.  
  2294. $wp_query->is_page = 1;
  2295.  
  2296. $wp_query->is_singular = 1;
  2297.  
  2298. $wp_query->is_404 = null;
  2299.  
  2300. $wp_query->post_count = 1;
  2301.  
  2302.  
  2303.  
  2304. $this->is_shop_page = true;
  2305.  
  2306. }
  2307.  
  2308.  
  2309.  
  2310. //load proper theme for order status page
  2311.  
  2312. if ($wp_query->query_vars['pagename'] == 'orderstatus') {
  2313.  
  2314.  
  2315.  
  2316. //check for custom theme template
  2317.  
  2318. $templates = array("mp_orderstatus.php");
  2319.  
  2320.  
  2321.  
  2322. //if custom template exists load it
  2323.  
  2324. if ($this->orderstatus_template = locate_template($templates)) {
  2325.  
  2326. add_filter( 'template_include', array(&$this, 'custom_orderstatus_template') );
  2327.  
  2328. add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
  2329.  
  2330. add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
  2331.  
  2332. add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
  2333.  
  2334. } else {
  2335.  
  2336. //otherwise load the page template and use our own theme
  2337.  
  2338. add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
  2339.  
  2340. add_filter( 'the_title', array(&$this, 'page_title_output'), 99 );
  2341.  
  2342. add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
  2343.  
  2344. add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
  2345.  
  2346. add_filter( 'the_content', array(&$this, 'orderstatus_theme'), 99 );
  2347.  
  2348. }
  2349.  
  2350.  
  2351.  
  2352. $wp_query->is_page = 1;
  2353.  
  2354. $wp_query->is_singular = 1;
  2355.  
  2356. $wp_query->is_404 = null;
  2357.  
  2358. $wp_query->post_count = 1;
  2359.  
  2360.  
  2361.  
  2362. $this->is_shop_page = true;
  2363.  
  2364. }
  2365.  
  2366.  
  2367.  
  2368. //load proper theme for product listings
  2369.  
  2370. if ($wp_query->query_vars['pagename'] == 'product_list') {
  2371.  
  2372.  
  2373.  
  2374. //check for custom theme template
  2375.  
  2376. $templates = array("mp_productlist.php");
  2377.  
  2378.  
  2379.  
  2380. //if custom template exists load it
  2381.  
  2382. if ($this->product_list_template = locate_template($templates)) {
  2383.  
  2384.  
  2385.  
  2386. //call a custom query posts for this listing
  2387.  
  2388. //setup pagination
  2389.  
  2390. if ($this->get_setting('paginate')) {
  2391.  
  2392. //figure out perpage
  2393.  
  2394. $paginate_query = '&posts_per_page='.$this->get_setting('per_page');
  2395.  
  2396.  
  2397.  
  2398. //figure out page
  2399.  
  2400. if ($wp_query->query_vars['paged'])
  2401.  
  2402. $paginate_query .= '&paged='.intval($wp_query->query_vars['paged']);
  2403.  
  2404. } else {
  2405.  
  2406. $paginate_query = '&nopaging=true';
  2407.  
  2408. }
  2409.  
  2410.  
  2411.  
  2412. //get order by
  2413.  
  2414. if ($this->get_setting('order_by') == 'price')
  2415.  
  2416. $order_by_query = '&meta_key=mp_price&orderby=mp_price';
  2417.  
  2418. else if ($this->get_setting('order_by') == 'sales')
  2419.  
  2420. $order_by_query = '&meta_key=mp_sales_count&orderby=mp_sales_count';
  2421.  
  2422. else
  2423.  
  2424. $order_by_query = '&orderby='.$this->get_setting('order_by');
  2425.  
  2426.  
  2427.  
  2428. //get order direction
  2429.  
  2430. $order_query = '&order='.$this->get_setting('order');
  2431.  
  2432.  
  2433.  
  2434. //The Query
  2435.  
  2436. query_posts('post_type=product' . $paginate_query . $order_by_query . $order_query);
  2437.  
  2438.  
  2439.  
  2440. add_filter( 'template_include', array(&$this, 'custom_product_list_template') );
  2441.  
  2442. add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
  2443.  
  2444. add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
  2445.  
  2446. add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
  2447.  
  2448. } else {
  2449.  
  2450. //otherwise load the page template and use our own theme
  2451.  
  2452. add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
  2453.  
  2454. add_filter( 'the_title', array(&$this, 'page_title_output'), 99 );
  2455.  
  2456. add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
  2457.  
  2458. add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
  2459.  
  2460. add_filter( 'the_content', array(&$this, 'product_list_theme'), 99 );
  2461.  
  2462. add_filter( 'the_excerpt', array(&$this, 'product_list_theme'), 99 );
  2463.  
  2464.  
  2465.  
  2466. //genesis fixes
  2467.  
  2468. remove_action( 'genesis_entry_content', 'genesis_do_post_image' );
  2469.  
  2470. remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
  2471.  
  2472. remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
  2473.  
  2474. add_action('genesis_entry_content', 'the_content');
  2475.  
  2476. }
  2477.  
  2478.  
  2479.  
  2480. $wp_query->is_page = 1;
  2481.  
  2482. //$wp_query->is_singular = 1;
  2483.  
  2484. $wp_query->is_404 = null;
  2485.  
  2486. $wp_query->post_count = 1;
  2487.  
  2488.  
  2489.  
  2490. $this->is_shop_page = true;
  2491.  
  2492. }
  2493.  
  2494.  
  2495.  
  2496. //load proper theme for product category or tag listings
  2497.  
  2498. if ( isset( $wp_query->query_vars['taxonomy'] ) && ( $wp_query->query_vars['taxonomy'] == 'product_category' || $wp_query->query_vars['taxonomy'] == 'product_tag' ) ) {
  2499.  
  2500. $templates = array();
  2501.  
  2502.  
  2503.  
  2504. if ($wp_query->query_vars['taxonomy'] == 'product_category') {
  2505.  
  2506.  
  2507.  
  2508. $cat_name = get_query_var('product_category');
  2509.  
  2510. $cat_id = absint( $wp_query->get_queried_object_id() );
  2511.  
  2512. if ( $cat_name )
  2513.  
  2514. $templates[] = "mp_category-$cat_name.php";
  2515.  
  2516. if ( $cat_id )
  2517.  
  2518. $templates[] = "mp_category-$cat_id.php";
  2519.  
  2520. $templates[] = "mp_category.php";
  2521.  
  2522.  
  2523.  
  2524. } else if ($wp_query->query_vars['taxonomy'] == 'product_tag') {
  2525.  
  2526.  
  2527.  
  2528. $tag_name = get_query_var('product_tag');
  2529.  
  2530. $tag_id = absint( $wp_query->get_queried_object_id() );
  2531.  
  2532. if ( $tag_name )
  2533.  
  2534. $templates[] = "mp_tag-$tag_name.php";
  2535.  
  2536. if ( $tag_id )
  2537.  
  2538. $templates[] = "mp_tag-$tag_id.php";
  2539.  
  2540. $templates[] = "mp_tag.php";
  2541.  
  2542.  
  2543.  
  2544. }
  2545.  
  2546.  
  2547.  
  2548. //defaults
  2549.  
  2550. $templates[] = "mp_taxonomy.php";
  2551.  
  2552. $templates[] = "mp_productlist.php";
  2553.  
  2554.  
  2555.  
  2556. if ( !is_admin() && isset($_GET['product_category']) && is_numeric($_GET['product_category']) ) {
  2557.  
  2558. $link = get_term_link( (int)get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy'] );
  2559.  
  2560. wp_redirect($link);
  2561.  
  2562. exit;
  2563.  
  2564. }
  2565.  
  2566.  
  2567.  
  2568. //if custom template exists load it
  2569.  
  2570. if ($this->product_taxonomy_template = locate_template($templates)) {
  2571.  
  2572.  
  2573.  
  2574. //call a custom query posts for this listing
  2575.  
  2576. $taxonomy_query = '&' . $wp_query->query_vars['taxonomy'] . '=' . get_query_var($wp_query->query_vars['taxonomy']);
  2577.  
  2578.  
  2579.  
  2580. //setup pagination
  2581.  
  2582. if ($this->get_setting('paginate')) {
  2583.  
  2584. //figure out perpage
  2585.  
  2586. $paginate_query = '&posts_per_page='.$this->get_setting('per_page');
  2587.  
  2588.  
  2589.  
  2590. //figure out page
  2591.  
  2592. if ($wp_query->query_vars['paged'])
  2593.  
  2594. $paginate_query .= '&paged='.intval($wp_query->query_vars['paged']);
  2595.  
  2596. } else {
  2597.  
  2598. $paginate_query = '&nopaging=true';
  2599.  
  2600. }
  2601.  
  2602.  
  2603.  
  2604. //get order by
  2605.  
  2606. if ($this->get_setting('order_by') == 'price')
  2607.  
  2608. $order_by_query = '&meta_key=mp_price&orderby=mp_price';
  2609.  
  2610. else if ($this->get_setting('order_by') == 'sales')
  2611.  
  2612. $order_by_query = '&meta_key=mp_sales_count&orderby=mp_sales_count';
  2613.  
  2614. else
  2615.  
  2616. $order_by_query = '&orderby='.$this->get_setting('order_by');
  2617.  
  2618.  
  2619.  
  2620. //get order direction
  2621.  
  2622. $order_query = '&order='.$this->get_setting('order');
  2623.  
  2624.  
  2625.  
  2626. //The Query
  2627.  
  2628. query_posts('post_type=product' . $taxonomy_query . $paginate_query . $order_by_query . $order_query);
  2629.  
  2630.  
  2631.  
  2632. add_filter( 'template_include', array(&$this, 'custom_product_taxonomy_template'));
  2633.  
  2634. add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
  2635.  
  2636. add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
  2637.  
  2638. add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
  2639.  
  2640. } else {
  2641.  
  2642. //otherwise load the page template and use our own list theme. We don't use theme's taxonomy as not enough control
  2643.  
  2644. $wp_query->is_page = 1;
  2645.  
  2646. //$wp_query->is_singular = 1;
  2647.  
  2648. $wp_query->is_404 = null;
  2649.  
  2650. $wp_query->post_count = 1;
  2651.  
  2652. //$wp_query->queried_object_id = get_option('mp_store_page');
  2653.  
  2654. add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
  2655.  
  2656. add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
  2657.  
  2658. add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
  2659.  
  2660. add_filter( 'the_title', array(&$this, 'page_title_output'), 99, 2 );
  2661.  
  2662. add_filter( 'the_content', array(&$this, 'product_taxonomy_list_theme'), 99 );
  2663.  
  2664. add_filter( 'the_excerpt', array(&$this, 'product_taxonomy_list_theme'), 99 );
  2665.  
  2666.  
  2667.  
  2668. //genesis fixes
  2669.  
  2670. remove_action( 'genesis_entry_content', 'genesis_do_post_image' );
  2671.  
  2672. remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
  2673.  
  2674. remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
  2675.  
  2676. add_action('genesis_entry_content', 'the_content');
  2677.  
  2678. }
  2679.  
  2680.  
  2681.  
  2682. $this->is_shop_page = true;
  2683.  
  2684. }
  2685.  
  2686.  
  2687.  
  2688. //load shop specific items
  2689.  
  2690. if ($this->is_shop_page) {
  2691.  
  2692. //fixes a nasty bug in BP theme's functions.php file which always loads the activity stream if not a normal page
  2693.  
  2694. remove_all_filters('page_template');
  2695.  
  2696.  
  2697.  
  2698. //prevents 404 for virtual pages
  2699.  
  2700. status_header( 200 );
  2701.  
  2702. }
  2703.  
  2704. }
  2705.  
  2706.  
  2707.  
  2708. //loads the selected theme css files
  2709.  
  2710. function load_store_theme() {
  2711.  
  2712. if ( $this->get_setting('store_theme') == 'none' || current_theme_supports('mp_style') ) {
  2713.  
  2714. return;
  2715.  
  2716. } else if (file_exists($this->plugin_dir . 'themes/' . $this->get_setting('store_theme') . '.css')) {
  2717.  
  2718. wp_enqueue_style( 'mp-store-theme', $this->plugin_url . 'themes/' . $this->get_setting('store_theme') . '.css', false, $this->version );
  2719.  
  2720. } else if (file_exists(WP_CONTENT_DIR . '/marketpress-styles/' . $this->get_setting('store_theme') . '.css')) {
  2721.  
  2722. wp_enqueue_style( 'mp-store-theme', content_url( '/marketpress-styles/' . $this->get_setting('store_theme') . '.css' ), false, $this->version );
  2723.  
  2724. }
  2725.  
  2726. }
  2727.  
  2728.  
  2729.  
  2730. //list store themes in dropdown
  2731.  
  2732. function store_themes_select() {
  2733.  
  2734.  
  2735.  
  2736. //get theme dir
  2737.  
  2738. $theme_dir = $this->plugin_dir . 'themes/';
  2739.  
  2740.  
  2741.  
  2742. //scan directory for theme css files
  2743.  
  2744. $theme_list = array();
  2745.  
  2746. if ($handle = @opendir($theme_dir)) {
  2747.  
  2748. while (false !== ($file = readdir($handle))) {
  2749.  
  2750. if (($pos = strrpos($file, '.css')) !== false) {
  2751.  
  2752. $value = substr($file, 0, $pos);
  2753.  
  2754. if (is_readable("$theme_dir/$file")) {
  2755.  
  2756. $theme_data = get_file_data( "$theme_dir/$file", array('name' => 'MarketPress Style') );
  2757.  
  2758. if (is_array($theme_data))
  2759.  
  2760. $theme_list[$value] = $theme_data['name'];
  2761.  
  2762. }
  2763.  
  2764. }
  2765.  
  2766. }
  2767.  
  2768.  
  2769.  
  2770. @closedir($handle);
  2771.  
  2772. }
  2773.  
  2774.  
  2775.  
  2776. //scan wp-content/marketpress-styles/ directory for theme css files
  2777.  
  2778. $theme_dir = WP_CONTENT_DIR . '/marketpress-styles/';
  2779.  
  2780. if ($handle = @opendir($theme_dir)) {
  2781.  
  2782. while (false !== ($file = readdir($handle))) {
  2783.  
  2784. if (($pos = strrpos($file, '.css')) !== false) {
  2785.  
  2786. $value = substr($file, 0, $pos);
  2787.  
  2788. if (is_readable("$theme_dir/$file")) {
  2789.  
  2790. $theme_data = get_file_data( "$theme_dir/$file", array('name' => 'MarketPress Style') );
  2791.  
  2792. if (is_array($theme_data))
  2793.  
  2794. $theme_list[$value] = $theme_data['name'];
  2795.  
  2796. }
  2797.  
  2798. }
  2799.  
  2800. }
  2801.  
  2802.  
  2803.  
  2804. @closedir($handle);
  2805.  
  2806. }
  2807.  
  2808.  
  2809.  
  2810. //sort the themes
  2811.  
  2812. asort($theme_list);
  2813.  
  2814.  
  2815.  
  2816. //check network permissions
  2817.  
  2818. if (is_multisite()) {
  2819.  
  2820. $allowed_list = array();
  2821.  
  2822. $network_settings = get_site_option( 'mp_network_settings' );
  2823.  
  2824.  
  2825.  
  2826. foreach ($theme_list as $value => $name) {
  2827.  
  2828. if ($network_settings['allowed_themes'][$value] == 'full')
  2829.  
  2830. $allowed_list[$value] = $name;
  2831.  
  2832. else if ($network_settings['allowed_themes'][$value] == 'supporter' && function_exists('is_pro_site') && is_pro_site(false, $network_settings['themes_pro_level'][$value]))
  2833.  
  2834. $allowed_list[$value] = $name;
  2835.  
  2836. else if (is_super_admin()) //super admins can access all installed themes
  2837.  
  2838. $allowed_list[$value] = $name;
  2839.  
  2840. }
  2841.  
  2842. $theme_list = $allowed_list;
  2843.  
  2844. }
  2845.  
  2846.  
  2847.  
  2848. echo '<select name="mp[store_theme]">';
  2849.  
  2850. foreach ($theme_list as $value => $name) {
  2851.  
  2852. $disabled = (defined('MP_LITE') && $value != 'icons') ? ' disabled="disabled"' : '';
  2853.  
  2854. ?><option value="<?php echo $value ?>"<?php selected($this->get_setting('store_theme'), $value); echo $disabled; ?>><?php echo $name ?></option><?php
  2855.  
  2856. }
  2857.  
  2858. ?>
  2859.  
  2860. <option value="none"<?php selected($this->get_setting('store_theme'), 'none') ?>><?php _e('None - Custom theme template', 'mp') ?></option>
  2861.  
  2862. </select>
  2863.  
  2864. <?php
  2865.  
  2866. }
  2867.  
  2868.  
  2869.  
  2870. //filter the custom single product template
  2871.  
  2872. function custom_product_template($template) {
  2873.  
  2874. return $this->product_template;
  2875.  
  2876. }
  2877.  
  2878.  
  2879.  
  2880. //filter the custom store template
  2881.  
  2882. function custom_store_template($template) {
  2883.  
  2884. return $this->store_template;
  2885.  
  2886. }
  2887.  
  2888.  
  2889.  
  2890. //filter the custom checkout template
  2891.  
  2892. function custom_checkout_template($template) {
  2893.  
  2894. return $this->checkout_template;
  2895.  
  2896. }
  2897.  
  2898.  
  2899.  
  2900. //filter the custom orderstatus template
  2901.  
  2902. function custom_orderstatus_template($template) {
  2903.  
  2904. return $this->orderstatus_template;
  2905.  
  2906. }
  2907.  
  2908.  
  2909.  
  2910. //filter the custom product taxonomy template
  2911.  
  2912. function custom_product_taxonomy_template($template) {
  2913.  
  2914. return $this->product_taxonomy_template;
  2915.  
  2916. }
  2917.  
  2918.  
  2919.  
  2920. //filter the custom product list template
  2921.  
  2922. function custom_product_list_template($template) {
  2923.  
  2924. return $this->product_list_template;
  2925.  
  2926. }
  2927.  
  2928.  
  2929.  
  2930. //adds our links to theme nav menus using wp_list_pages()
  2931.  
  2932. function filter_list_pages($list, $args) {
  2933.  
  2934.  
  2935.  
  2936. if ($args['depth'] == 1)
  2937.  
  2938. return $list;
  2939.  
  2940.  
  2941.  
  2942. $temp_break = strpos($list, mp_store_link(false, true) . '"');
  2943.  
  2944.  
  2945.  
  2946. //if we can't find the page for some reason skip
  2947.  
  2948. if ($temp_break === false)
  2949.  
  2950. return $list;
  2951.  
  2952.  
  2953.  
  2954. $break = strpos($list, '</a>', $temp_break) + 4;
  2955.  
  2956.  
  2957.  
  2958. $nav = substr($list, 0, $break);
  2959.  
  2960.  
  2961.  
  2962. if ( !$this->get_setting('disable_cart') ) {
  2963.  
  2964. $nav .= '<ul class="children"><li class="page_item'. ((get_query_var('pagename') == 'product_list') ? ' current_page_item' : '') . '"><a href="' . mp_products_link(false, true) . '" title="' . __('Products', 'mp') . '">' . __('Products', 'mp') . '</a></li>';
  2965.  
  2966. $nav .= '<li class="page_item'. ((get_query_var('pagename') == 'cart') ? ' current_page_item' : '') . '"><a href="' . mp_cart_link(false, true) . '" title="' . __('Shopping Cart', 'mp') . '">' . __('Shopping Cart', 'mp') . '</a></li>';
  2967.  
  2968. $nav .= '<li class="page_item'. ((get_query_var('pagename') == 'orderstatus') ? ' current_page_item' : '') . '"><a href="' . mp_orderstatus_link(false, true) . '" title="' . __('Order Status', 'mp') . '">' . __('Order Status', 'mp') . '</a></li>
  2969.  
  2970. </ul>
  2971.  
  2972. ';
  2973.  
  2974. } else {
  2975.  
  2976. $nav .= '
  2977.  
  2978. <ul>
  2979.  
  2980. <li class="page_item'. ((get_query_var('pagename') == 'product_list') ? ' current_page_item' : '') . '"><a href="' . mp_products_link(false, true) . '" title="' . __('Products', 'mp') . '">' . __('Products', 'mp') . '</a></li>
  2981.  
  2982. </ul>
  2983.  
  2984. ';
  2985.  
  2986. }
  2987.  
  2988. $nav .= substr($list, $break);
  2989.  
  2990.  
  2991.  
  2992. return $nav;
  2993.  
  2994. }
  2995.  
  2996.  
  2997.  
  2998. //adds our links to custom theme nav menus using wp_nav_menu()
  2999.  
  3000. function filter_nav_menu($list, $args = array()) {
  3001.  
  3002. $store_object = false;
  3003.  
  3004.  
  3005.  
  3006. if ($args->depth == 1)
  3007.  
  3008. return $list;
  3009.  
  3010.  
  3011.  
  3012. //find store page
  3013.  
  3014. $store_url = mp_store_link(false, true);
  3015.  
  3016. $store_page = get_option('mp_store_page');
  3017.  
  3018. foreach($list as $menu_item) {
  3019.  
  3020. if ((isset($menu_item->object_id) and $menu_item->object_id == $store_page) || $menu_item->url == $store_url) {
  3021.  
  3022. $store_object = $menu_item;
  3023.  
  3024. break;
  3025.  
  3026. }
  3027.  
  3028. }
  3029.  
  3030.  
  3031.  
  3032. if ($store_object) {
  3033.  
  3034. $obj_products = clone $store_object;
  3035.  
  3036. $obj_products->title = __('Products', 'mp');
  3037.  
  3038. $obj_products->menu_item_parent = $store_object->ID;
  3039.  
  3040. $obj_products->ID = '99999999999';
  3041.  
  3042. $obj_products->db_id = '99999999999';
  3043.  
  3044. $obj_products->post_name = '99999999999';
  3045.  
  3046. $obj_products->url = mp_products_link(false, true);
  3047.  
  3048. $obj_products->current = (get_query_var('pagename') == 'product_list') ? true : false;
  3049.  
  3050. $obj_products->current_item_ancestor = (get_query_var('pagename') == 'product_list') ? true : false;
  3051.  
  3052. $list[] = $obj_products;
  3053.  
  3054.  
  3055.  
  3056. //if cart disabled return only the products menu item
  3057.  
  3058. if ($this->get_setting('disable_cart'))
  3059.  
  3060. return $list;
  3061.  
  3062.  
  3063.  
  3064. $obj_cart = clone $store_object;
  3065.  
  3066. $obj_cart->title = __('Shopping Cart', 'mp');
  3067.  
  3068. $obj_cart->menu_item_parent = $store_object->ID;
  3069.  
  3070. $obj_cart->ID = '99999999999';
  3071.  
  3072. $obj_cart->db_id = '99999999999';
  3073.  
  3074. $obj_cart->post_name = '99999999999';
  3075.  
  3076. $obj_cart->url = mp_cart_link(false, true);
  3077.  
  3078. $obj_cart->current = (get_query_var('pagename') == 'cart') ? true : false;
  3079.  
  3080. $obj_cart->current_item_ancestor = (get_query_var('pagename') == 'cart') ? true : false;
  3081.  
  3082. $list[] = $obj_cart;
  3083.  
  3084.  
  3085.  
  3086. $obj_order = clone $store_object;
  3087.  
  3088. $obj_order->title = __('Order Status', 'mp');
  3089.  
  3090. $obj_order->menu_item_parent = $store_object->ID;
  3091.  
  3092. $obj_order->ID = '99999999999';
  3093.  
  3094. $obj_order->db_id = '99999999999';
  3095.  
  3096. $obj_order->post_name = '99999999999';
  3097.  
  3098. $obj_order->url = mp_orderstatus_link(false, true);
  3099.  
  3100. $obj_order->current = (get_query_var('pagename') == 'orderstatus') ? true : false;
  3101.  
  3102. $obj_order->current_item_ancestor = (get_query_var('pagename') == 'orderstatus') ? true : false;
  3103.  
  3104. $list[] = $obj_order;
  3105.  
  3106. }
  3107.  
  3108.  
  3109.  
  3110. return $list;
  3111.  
  3112. }
  3113.  
  3114.  
  3115.  
  3116. function wp_title_output($title, $sep, $seplocation) {
  3117.  
  3118. // Determines position of the separator and direction of the breadcrumb
  3119.  
  3120. if ( 'right' == $seplocation )
  3121.  
  3122. return $this->page_title_output($title, true) . " $sep ";
  3123.  
  3124. else
  3125.  
  3126. return " $sep " . $this->page_title_output($title, true);
  3127.  
  3128. }
  3129.  
  3130.  
  3131.  
  3132. //filters the titles for our custom pages
  3133.  
  3134. function page_title_output($title, $id = false) {
  3135.  
  3136. global $wp_query;
  3137.  
  3138.  
  3139.  
  3140. //filter out nav titles
  3141.  
  3142. if (!empty($title) && $id === false)
  3143.  
  3144. return $title;
  3145.  
  3146.  
  3147.  
  3148. //taxonomy pages
  3149.  
  3150. if (isset($wp_query->query_vars['taxonomy']) && ($wp_query->query_vars['taxonomy'] == 'product_category' || $wp_query->query_vars['taxonomy'] == 'product_tag') && $wp_query->post->ID == $id) {
  3151.  
  3152. if ($wp_query->query_vars['taxonomy'] == 'product_category') {
  3153.  
  3154. $term = get_term_by('slug', get_query_var('product_category'), 'product_category');
  3155.  
  3156. return sprintf( __('Product Category: %s', 'mp'), $term->name );
  3157.  
  3158. } else if ($wp_query->query_vars['taxonomy'] == 'product_tag') {
  3159.  
  3160. $term = get_term_by('slug', get_query_var('product_tag'), 'product_tag');
  3161.  
  3162. return sprintf( __('Product Tag: %s', 'mp'), $term->name );
  3163.  
  3164. }
  3165.  
  3166. }
  3167.  
  3168.  
  3169.  
  3170. switch ($wp_query->query_vars['pagename']) {
  3171.  
  3172. case 'cart':
  3173.  
  3174. if ( isset($wp_query->query_vars['checkoutstep']) ) {
  3175.  
  3176. if ($wp_query->query_vars['checkoutstep'] == 'shipping')
  3177.  
  3178. return $this->download_only_cart($this->get_cart_contents()) ? __('Checkout Information', 'mp') : __('Shipping Information', 'mp');
  3179.  
  3180. else if ($wp_query->query_vars['checkoutstep'] == 'checkout')
  3181.  
  3182. return __('Payment Information', 'mp');
  3183.  
  3184. else if ($wp_query->query_vars['checkoutstep'] == 'confirm-checkout')
  3185.  
  3186. return __('Confirm Your Purchase', 'mp');
  3187.  
  3188. else if ($wp_query->query_vars['checkoutstep'] == 'confirmation')
  3189.  
  3190. return __('Order Confirmation', 'mp');
  3191.  
  3192. else
  3193.  
  3194. return __('Your Shopping Cart', 'mp');
  3195.  
  3196. } else {
  3197.  
  3198. return __('Your Shopping Cart', 'mp');
  3199.  
  3200. }
  3201.  
  3202. break;
  3203.  
  3204.  
  3205.  
  3206. case 'orderstatus':
  3207.  
  3208. return __('Track Your Order', 'mp');
  3209.  
  3210. break;
  3211.  
  3212.  
  3213.  
  3214. case 'product_list':
  3215.  
  3216. return __('Products', 'mp');
  3217.  
  3218. break;
  3219.  
  3220.  
  3221.  
  3222. default:
  3223.  
  3224. return $title;
  3225.  
  3226. }
  3227.  
  3228. }
  3229.  
  3230.  
  3231.  
  3232. //this is the default theme added to single product listings
  3233.  
  3234. function product_theme($content) {
  3235.  
  3236. global $post;
  3237.  
  3238.  
  3239.  
  3240. //don't filter outside of the loop
  3241.  
  3242. if ( !in_the_loop() )
  3243.  
  3244. return $content;
  3245.  
  3246.  
  3247.  
  3248. //add thumbnail
  3249.  
  3250. if ($this->get_setting('show_img')) {
  3251.  
  3252. $content = mp_product_image( false, 'single' ) . $content;
  3253.  
  3254. }
  3255.  
  3256.  
  3257.  
  3258. $content .= '<div class="mp_product_meta">';
  3259.  
  3260. $content .= mp_product_price(false);
  3261.  
  3262. $content .= mp_buy_button(false, 'single');
  3263.  
  3264. $content .= '</div>';
  3265.  
  3266.  
  3267.  
  3268. $content .= mp_category_list($post->ID, '<div class="mp_product_categories">' . __( 'Categorized in ', 'mp' ), ', ', '</div>');
  3269.  
  3270. $content .= mp_pinit_button($post->ID);
  3271.  
  3272.  
  3273.  
  3274. //$content .= mp_tag_list($post->ID, '<div class="mp_product_tags">', ', ', '</div>');
  3275.  
  3276.  
  3277.  
  3278. $content .= mp_related_products( $post->ID );
  3279.  
  3280.  
  3281.  
  3282.  
  3283.  
  3284. return $content;
  3285.  
  3286. }
  3287.  
  3288.  
  3289.  
  3290. //this is the default theme added to the checkout page
  3291.  
  3292. function store_theme($content) {
  3293.  
  3294. //don't filter outside of the loop
  3295.  
  3296. if ( !in_the_loop() )
  3297.  
  3298. return $content;
  3299.  
  3300.  
  3301.  
  3302. return $content;
  3303.  
  3304. }
  3305.  
  3306.  
  3307.  
  3308. //this is the default theme added to the checkout page
  3309.  
  3310. function checkout_theme($content) {
  3311.  
  3312. global $wp_query;
  3313.  
  3314.  
  3315.  
  3316. //don't filter outside of the loop
  3317.  
  3318. if ( !in_the_loop() )
  3319.  
  3320. return $content;
  3321.  
  3322.  
  3323.  
  3324. $content = mp_show_cart('checkout', null, false);
  3325.  
  3326.  
  3327.  
  3328. return $content;
  3329.  
  3330. }
  3331.  
  3332.  
  3333.  
  3334. //this is the default theme added to the order status page
  3335.  
  3336. function orderstatus_theme($content) {
  3337.  
  3338. //don't filter outside of the loop
  3339.  
  3340. if ( !in_the_loop() )
  3341.  
  3342. return $content;
  3343.  
  3344.  
  3345.  
  3346. mp_order_status();
  3347.  
  3348. return $content;
  3349.  
  3350. }
  3351.  
  3352.  
  3353.  
  3354. //this is the default theme added to product listings
  3355.  
  3356. function product_list_theme($content) {
  3357.  
  3358. //don't filter outside of the loop
  3359.  
  3360. if ( !in_the_loop() )
  3361.  
  3362. return $content;
  3363.  
  3364.  
  3365.  
  3366. $msgs = $this->get_setting('msg');
  3367.  
  3368. $content .= do_shortcode($msgs['product_list']);
  3369.  
  3370. $content .= mp_list_products(array('echo' => false));
  3371.  
  3372.  
  3373.  
  3374. return $content;
  3375.  
  3376. }
  3377.  
  3378.  
  3379.  
  3380. //this is the default theme added to product taxonomies
  3381.  
  3382. function product_taxonomy_list_theme($content) {
  3383.  
  3384. //don't filter outside of the loop
  3385.  
  3386. if ( !in_the_loop() )
  3387.  
  3388. return $content;
  3389.  
  3390.  
  3391.  
  3392. $msgs = $this->get_setting('msg');
  3393.  
  3394. $content = do_shortcode($msgs['product_list']);
  3395.  
  3396. $content .= mp_list_products(array('echo' => false));
  3397.  
  3398.  
  3399.  
  3400. return $content;
  3401.  
  3402. }
  3403.  
  3404.  
  3405.  
  3406. /**
  3407.  
  3408. * ajax handler
  3409.  
  3410. * @return string html of products list, and optionally pagination
  3411.  
  3412. */
  3413.  
  3414. function get_products_list(){
  3415.  
  3416. global $wp_query;
  3417.  
  3418.  
  3419.  
  3420. $ret = array('products'=>false, 'pagination'=>false);
  3421.  
  3422. $args = wp_parse_args(array(
  3423.  
  3424. 'echo' => false,
  3425.  
  3426. 'filters' => false,
  3427.  
  3428. ), $this->defaults['list_products']);
  3429.  
  3430.  
  3431.  
  3432. if ( isset($_POST['order']) ) {
  3433.  
  3434. $o = explode('-',$_POST['order']);
  3435.  
  3436.  
  3437.  
  3438. // column
  3439.  
  3440. if(isset($o[0]) && in_array($o[0], array('date','title','price','sales'))) {
  3441.  
  3442. $args['order_by'] = $o[0];
  3443.  
  3444. }
  3445.  
  3446.  
  3447.  
  3448. // direction
  3449.  
  3450. if(isset($o[1]) && in_array($o[1], array('asc','desc'))) {
  3451.  
  3452. $args['order'] = strtoupper($o[1]);
  3453.  
  3454. }
  3455.  
  3456. }
  3457.  
  3458.  
  3459.  
  3460. if ( isset($_POST['product_category']) && is_numeric($_POST['product_category']) ) {
  3461.  
  3462. $term = get_term_by( 'id', $_POST['product_category'], 'product_category' );
  3463.  
  3464. $args['category'] = $term->slug;
  3465.  
  3466. }
  3467.  
  3468.  
  3469.  
  3470. if ( isset($_POST['page']) && is_numeric($_POST['page']) ) {
  3471.  
  3472. $args['page'] = $_POST['page'];
  3473.  
  3474. }
  3475.  
  3476.  
  3477.  
  3478. $ret['products'] = mp_list_products($args);
  3479.  
  3480.  
  3481.  
  3482. header('Content-type: application/json');
  3483.  
  3484. echo json_encode($ret);
  3485.  
  3486. exit;
  3487.  
  3488. }
  3489.  
  3490.  
  3491.  
  3492. //adds the "filter by product category" to the edit products screen
  3493.  
  3494. function edit_products_filter() {
  3495.  
  3496. global $current_screen;
  3497.  
  3498.  
  3499.  
  3500. if ( $current_screen->id == 'edit-product' ) {
  3501.  
  3502. $selected_category = !empty( $_GET['product_category'] ) ? $_GET['product_category'] : null;
  3503.  
  3504. $dropdown_options = array('taxonomy' => 'product_category', 'show_option_all' => __('View all categories'), 'hide_empty' => 0, 'hierarchical' => 1,
  3505.  
  3506. 'show_count' => 0, 'orderby' => 'name', 'name' => 'product_category', 'selected' => $selected_category );
  3507.  
  3508. wp_dropdown_categories($dropdown_options);
  3509.  
  3510. }
  3511.  
  3512. }
  3513.  
  3514.  
  3515.  
  3516. //adjusts the query vars on the products/order management screens.
  3517.  
  3518. function handle_edit_screen_filter($request) {
  3519.  
  3520. if ( is_admin() ) {
  3521.  
  3522. global $current_screen;
  3523.  
  3524.  
  3525.  
  3526. if ( $current_screen->id == 'edit-product' ) {
  3527.  
  3528. //Switches the product_category ids to slugs as you can't query custom taxonomys with ids
  3529.  
  3530. if ( !empty( $request['product_category'] ) ) {
  3531.  
  3532. $cat = get_term_by('id', $request['product_category'], 'product_category');
  3533.  
  3534. $request['product_category'] = $cat->slug;
  3535.  
  3536. }
  3537.  
  3538. } else if ( $current_screen->id == 'product_page_marketpress-orders' && !isset($_GET['post_status']) ) {
  3539.  
  3540. //set the post status when on "All" to everything but closed
  3541.  
  3542. $request['post_status'] = 'order_received,order_paid,order_shipped';
  3543.  
  3544. }
  3545.  
  3546. }
  3547.  
  3548.  
  3549.  
  3550. return $request;
  3551.  
  3552. }
  3553.  
  3554.  
  3555.  
  3556. //adds our custom column headers to edit products screen
  3557.  
  3558. function edit_products_columns($old_columns) {
  3559.  
  3560. global $post_status;
  3561.  
  3562.  
  3563.  
  3564. $columns['cb'] = '<input type="checkbox" />';
  3565.  
  3566. $columns['thumbnail'] = __('Thumbnail', 'mp');
  3567.  
  3568. $columns['title'] = __('Product Name', 'mp');
  3569.  
  3570. $columns['variations'] = __('Variations', 'mp');
  3571.  
  3572. $columns['sku'] = __('SKU', 'mp');
  3573.  
  3574. $columns['pricing'] = __('Price', 'mp');
  3575.  
  3576. if ( !$this->get_setting('disable_cart') ) {
  3577.  
  3578. $columns['stock'] = __('Stock', 'mp');
  3579.  
  3580. $columns['sales'] = __('Sales', 'mp');
  3581.  
  3582. }
  3583.  
  3584. $columns['product_categories'] = __('Product Categories', 'mp');
  3585.  
  3586. $columns['product_tags'] = __('Product Tags', 'mp');
  3587.  
  3588.  
  3589.  
  3590.  
  3591.  
  3592. /*
  3593.  
  3594. if ( !in_array( $post_status, array('pending', 'draft', 'future') ) )
  3595.  
  3596. $columns['reviews'] = __('Reviews', 'mp');
  3597.  
  3598. //*/
  3599.  
  3600.  
  3601.  
  3602. return $columns;
  3603.  
  3604. }
  3605.  
  3606.  
  3607.  
  3608. //adds our custom column content
  3609.  
  3610. function edit_products_custom_columns($column) {
  3611.  
  3612. global $post;
  3613.  
  3614.  
  3615.  
  3616. //$screen = get_current_screen();
  3617.  
  3618. //echo "screen->id=[". $screen->id ."]<br />";
  3619.  
  3620. //apply_filters( 'bulk_actions-' . $screen->id, $this->_actions );
  3621.  
  3622.  
  3623.  
  3624. $meta = get_post_custom();
  3625.  
  3626. //unserialize
  3627.  
  3628. foreach ($meta as $key => $val) {
  3629.  
  3630. $meta[$key] = maybe_unserialize($val[0]);
  3631.  
  3632. if (!is_array($meta[$key]) && $key != "mp_is_sale" && $key != "mp_track_inventory" && $key != "mp_product_link")
  3633.  
  3634. $meta[$key] = array($meta[$key]);
  3635.  
  3636. }
  3637.  
  3638.  
  3639.  
  3640. switch ($column) {
  3641.  
  3642. case "thumbnail":
  3643.  
  3644. echo '<a href="' . get_edit_post_link() . '" title="' . __('Edit &raquo;') . '">';
  3645.  
  3646. if (has_post_thumbnail()) {
  3647.  
  3648. the_post_thumbnail(array(50,50), array('title' => ''));
  3649.  
  3650. } else {
  3651.  
  3652. echo '<img width="50" height="50" src="'.apply_filters('mp_default_product_img', $this->plugin_url.'images/default-product.png').'">';
  3653.  
  3654. }
  3655.  
  3656. echo '</a>';
  3657.  
  3658. break;
  3659.  
  3660.  
  3661.  
  3662. case "variations":
  3663.  
  3664. if (isset($meta["mp_var_name"]) && is_array($meta["mp_var_name"]) && count($meta["mp_var_name"]) > 1) {
  3665.  
  3666. foreach ($meta["mp_var_name"] as $value) {
  3667.  
  3668. echo esc_attr($value) . '<br />';
  3669.  
  3670. }
  3671.  
  3672. } else {
  3673.  
  3674. _e('N/A', 'mp');
  3675.  
  3676. }
  3677.  
  3678. break;
  3679.  
  3680.  
  3681.  
  3682. case "sku":
  3683.  
  3684. if (isset($meta["mp_var_name"]) && is_array($meta["mp_var_name"])) {
  3685.  
  3686. foreach ((array)$meta["mp_sku"] as $value) {
  3687.  
  3688. echo esc_attr($value) . '<br />';
  3689.  
  3690. }
  3691.  
  3692. } else {
  3693.  
  3694. _e('N/A', 'mp');
  3695.  
  3696. }
  3697.  
  3698. break;
  3699.  
  3700.  
  3701.  
  3702. case "pricing":
  3703.  
  3704. if (isset($meta["mp_price"]) && is_array($meta["mp_price"])) {
  3705.  
  3706. foreach ($meta["mp_price"] as $key => $value) {
  3707.  
  3708. if (isset($meta["mp_is_sale"]) && $meta["mp_is_sale"] && isset($meta["mp_sale_price"][$key])) {
  3709.  
  3710. echo '<del>'.$this->format_currency('', $value).'</del> ';
  3711.  
  3712. echo $this->format_currency('', $meta["mp_sale_price"][$key]) . '<br />';
  3713.  
  3714. } else {
  3715.  
  3716. echo $this->format_currency('', $value) . '<br />';
  3717.  
  3718. }
  3719.  
  3720. }
  3721.  
  3722. } else {
  3723.  
  3724. echo $this->format_currency('', 0);
  3725.  
  3726. }
  3727.  
  3728. break;
  3729.  
  3730.  
  3731.  
  3732. case "sales":
  3733.  
  3734. echo number_format_i18n(isset($meta["mp_sales_count"][0]) ? $meta["mp_sales_count"][0] : 0);
  3735.  
  3736. break;
  3737.  
  3738.  
  3739.  
  3740. case "stock":
  3741.  
  3742. if (isset($meta["mp_track_inventory"]) && $meta["mp_track_inventory"]) {
  3743.  
  3744. foreach ((array)$meta["mp_inventory"] as $value) {
  3745.  
  3746. $inventory = ($value) ? $value : 0;
  3747.  
  3748. if ($inventory == 0)
  3749.  
  3750. $class = 'mp-inv-out';
  3751.  
  3752. else if ($inventory <= $this->get_setting('inventory_threshhold'))
  3753.  
  3754. $class = 'mp-inv-warn';
  3755.  
  3756. else
  3757.  
  3758. $class = 'mp-inv-full';
  3759.  
  3760.  
  3761.  
  3762. echo '<span class="' . $class . '">' . number_format_i18n($inventory) . '</span><br />';
  3763.  
  3764. }
  3765.  
  3766. } else {
  3767.  
  3768. _e('N/A', 'mp');
  3769.  
  3770. }
  3771.  
  3772. break;
  3773.  
  3774.  
  3775.  
  3776. case "product_categories":
  3777.  
  3778. echo mp_category_list();
  3779.  
  3780. break;
  3781.  
  3782.  
  3783.  
  3784. case "product_tags":
  3785.  
  3786. echo mp_tag_list();
  3787.  
  3788. break;
  3789.  
  3790.  
  3791.  
  3792. case "reviews":
  3793.  
  3794. echo '<div class="post-com-count-wrapper">
  3795.  
  3796. <a href="edit-comments.php?p=913" title="0 pending" class="post-com-count"><span class="comment-count">0</span></a>
  3797.  
  3798. </div>';
  3799.  
  3800. break;
  3801.  
  3802. }
  3803.  
  3804. }
  3805.  
  3806.  
  3807.  
  3808. // Adds a custom row action for Copying/Cloning a Product
  3809.  
  3810. function edit_products_custom_row_actions($actions, $post) {
  3811.  
  3812. $action = 'copy-product';
  3813.  
  3814.  
  3815.  
  3816. if ( ($post->post_type == "product") && (!isset($actions[$action])) ) {
  3817.  
  3818.  
  3819.  
  3820. $post_type_object = get_post_type_object( $post->post_type );
  3821.  
  3822. if ( $post_type_object ) {
  3823.  
  3824. if ( current_user_can('edit_pages') ) {
  3825.  
  3826. $copy_link = add_query_arg( 'action', $action );
  3827.  
  3828. $copy_link = add_query_arg( 'post', $post->ID, $copy_link );
  3829.  
  3830. $copy_link = wp_nonce_url( $copy_link, "{$action}-{$post->post_type}_{$post->ID}" );
  3831.  
  3832. $actions[$action] = '<a href="'. $copy_link .'">'. __('Copy', 'mp') .'</a>';
  3833.  
  3834. }
  3835.  
  3836. }
  3837.  
  3838. }
  3839.  
  3840. return $actions;
  3841.  
  3842. }
  3843.  
  3844.  
  3845.  
  3846. function edit_products_copy_action() {
  3847.  
  3848.  
  3849.  
  3850. $action = 'copy-product';
  3851.  
  3852. if ((isset($_GET['action'])) && ($_GET['action'] == "copy-product")) {
  3853.  
  3854.  
  3855.  
  3856. $sendback_href = remove_query_arg( array('_wpnonce', 'mp-action', 'post', 'trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
  3857.  
  3858.  
  3859.  
  3860. if (isset($_GET['post']))
  3861.  
  3862. $product_id = intval($_GET['post']);
  3863.  
  3864. else
  3865.  
  3866. wp_redirect($sendback_href);
  3867.  
  3868.  
  3869.  
  3870. if (isset($_GET['post_type']))
  3871.  
  3872. $post_type = esc_attr($_GET['post_type']);
  3873.  
  3874. else
  3875.  
  3876. wp_redirect($sendback_href);
  3877.  
  3878.  
  3879.  
  3880. if ( (!isset($_GET['_wpnonce'])) || !wp_verify_nonce($_GET['_wpnonce'], "{$action}-{$post_type}_{$product_id}") )
  3881.  
  3882. wp_redirect($sendback_href);
  3883.  
  3884.  
  3885.  
  3886. $product = (array)get_post_to_edit( $product_id );
  3887.  
  3888. $product['ID'] = 0; // Zero out the Product ID to force insert of new item
  3889.  
  3890. $product['post_status'] = 'draft';
  3891.  
  3892. $product['post_author'] = get_current_user_id();
  3893.  
  3894.  
  3895.  
  3896. $new_product_id = wp_insert_post($product);
  3897.  
  3898. if (($new_product_id) && (!is_wp_error($$new_product_id))) {
  3899.  
  3900.  
  3901.  
  3902. //If we have the a valid new product ID we copy the product meta...
  3903.  
  3904. $product_meta_keys = get_post_custom_keys($product_id);
  3905.  
  3906. if (!empty($product_meta_keys)) {
  3907.  
  3908. foreach ($product_meta_keys as $meta_key) {
  3909.  
  3910. $meta_values = get_post_custom_values($meta_key, $product_id);
  3911.  
  3912.  
  3913.  
  3914. foreach ($meta_values as $meta_value) {
  3915.  
  3916. $meta_value = maybe_unserialize($meta_value);
  3917.  
  3918. add_post_meta($new_product_id, $meta_key, $meta_value);
  3919.  
  3920. }
  3921.  
  3922. }
  3923.  
  3924. }
  3925.  
  3926.  
  3927.  
  3928. // ... thne we copy the product taxonomy terms
  3929.  
  3930. $product_taxonomies = get_object_taxonomies($post_type);
  3931.  
  3932. if (!empty($product_taxonomies)) {
  3933.  
  3934. foreach ($product_taxonomies as $product_taxonomy) {
  3935.  
  3936. $product_terms = wp_get_object_terms($product_id, $product_taxonomy, array( 'orderby' => 'term_order' ));
  3937.  
  3938. if (($product_terms) && (count($product_terms))) {
  3939.  
  3940. $terms = array();
  3941.  
  3942. foreach($product_terms as $product_term)
  3943.  
  3944. $terms[] = $product_term->slug;
  3945.  
  3946. }
  3947.  
  3948. wp_set_object_terms($new_product_id, $terms, $product_taxonomy);
  3949.  
  3950. }
  3951.  
  3952. }
  3953.  
  3954. }
  3955.  
  3956. }
  3957.  
  3958. wp_redirect($sendback_href);
  3959.  
  3960. die();
  3961.  
  3962. }
  3963.  
  3964.  
  3965.  
  3966. //adds our custom column headers
  3967.  
  3968. function manage_orders_columns($old_columns) {
  3969.  
  3970. global $post_status;
  3971.  
  3972.  
  3973.  
  3974. $columns['cb'] = '<input type="checkbox" />';
  3975.  
  3976.  
  3977.  
  3978. $columns['mp_orders_status'] = __('Status', 'mp');
  3979.  
  3980. $columns['mp_orders_id'] = __('Order ID', 'mp');
  3981.  
  3982. $columns['mp_orders_date'] = __('Order Date', 'mp');
  3983.  
  3984. $columns['mp_orders_name'] = __('From', 'mp');
  3985.  
  3986. $columns['mp_orders_items'] = __('Items', 'mp');
  3987.  
  3988. $columns['mp_orders_shipping'] = __('Shipping', 'mp');
  3989.  
  3990. $columns['mp_orders_tax'] = __('Tax', 'mp');
  3991.  
  3992. $columns['mp_orders_discount'] = __('Discount', 'mp');
  3993.  
  3994. $columns['mp_orders_total'] = __('Total', 'mp');
  3995.  
  3996.  
  3997.  
  3998. return $columns;
  3999.  
  4000. }
  4001.  
  4002.  
  4003.  
  4004. //adds our custom column content
  4005.  
  4006. function manage_orders_custom_columns($column) {
  4007.  
  4008. global $post;
  4009.  
  4010. $meta = get_post_custom();
  4011.  
  4012. //unserialize
  4013.  
  4014. foreach ($meta as $key => $val)
  4015.  
  4016. $meta[$key] = array_map('maybe_unserialize', $val);
  4017.  
  4018.  
  4019.  
  4020. switch ($column) {
  4021.  
  4022.  
  4023.  
  4024. case "mp_orders_status":
  4025.  
  4026. if ($post->post_status == 'order_received')
  4027.  
  4028. $text = __('Received', 'mp');
  4029.  
  4030. else if ($post->post_status == 'order_paid')
  4031.  
  4032. $text = __('Paid', 'mp');
  4033.  
  4034. else if ($post->post_status == 'order_shipped')
  4035.  
  4036. $text = __('Shipped', 'mp');
  4037.  
  4038. else if ($post->post_status == 'order_closed')
  4039.  
  4040. $text = __('Closed', 'mp');
  4041.  
  4042. else if ($post->post_status == 'trash')
  4043.  
  4044. $text = __('Trashed', 'mp');
  4045.  
  4046.  
  4047.  
  4048. ?><a class="mp_order_status" href="edit.php?post_type=product&page=marketpress-orders&order_id=<?php echo $post->ID; ?>" title="<?php echo __('View Order Details', 'mp'); ?>"><?php echo $text ?></a><?php
  4049.  
  4050. break;
  4051.  
  4052.  
  4053.  
  4054. case "mp_orders_date":
  4055.  
  4056. $t_time = get_the_time(__('Y/m/d g:i:s A'));
  4057.  
  4058. $m_time = $post->post_date;
  4059.  
  4060. $time = get_post_time('G', true, $post);
  4061.  
  4062.  
  4063.  
  4064. $time_diff = time() - $time;
  4065.  
  4066.  
  4067.  
  4068. if ( $time_diff > 0 && $time_diff < 24*60*60 )
  4069.  
  4070. $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
  4071.  
  4072. else
  4073.  
  4074. $h_time = mysql2date(__('Y/m/d'), $m_time);
  4075.  
  4076. echo '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
  4077.  
  4078. break;
  4079.  
  4080.  
  4081.  
  4082. case "mp_orders_id":
  4083.  
  4084. $title = _draft_or_post_title();
  4085.  
  4086. ?>
  4087.  
  4088. <strong><a class="row-title" href="edit.php?post_type=product&page=marketpress-orders&order_id=<?php echo $post->ID; ?>" title="<?php echo esc_attr(sprintf(__('View &#8220;%s&#8221;', 'mp'), $title)); ?>"><?php echo $title ?></a></strong>
  4089.  
  4090. <?php
  4091.  
  4092. $actions = array();
  4093.  
  4094. if ($post->post_status == 'order_received') {
  4095.  
  4096. $actions['paid'] = "<a title='" . esc_attr(__('Mark as Paid', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=paid&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Paid', 'mp') . "</a>";
  4097.  
  4098. $actions['shipped'] = "<a title='" . esc_attr(__('Mark as Shipped', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=shipped&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Shipped', 'mp') . "</a>";
  4099.  
  4100. $actions['closed'] = "<a title='" . esc_attr(__('Mark as Closed', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=closed&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Closed', 'mp') . "</a>";
  4101.  
  4102. } else if ($post->post_status == 'order_paid') {
  4103.  
  4104. $actions['shipped'] = "<a title='" . esc_attr(__('Mark as Shipped', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=shipped&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Shipped', 'mp') . "</a>";
  4105.  
  4106. $actions['closed'] = "<a title='" . esc_attr(__('Mark as Closed', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=closed&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Closed', 'mp') . "</a>";
  4107.  
  4108. } else if ($post->post_status == 'order_shipped') {
  4109.  
  4110. $actions['closed'] = "<a title='" . esc_attr(__('Mark as Closed', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=closed&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Closed', 'mp') . "</a>";
  4111.  
  4112. } else if ($post->post_status == 'order_closed') {
  4113.  
  4114. $actions['received'] = "<a title='" . esc_attr(__('Mark as Received', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=received&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Received', 'mp') . "</a>";
  4115.  
  4116. $actions['paid'] = "<a title='" . esc_attr(__('Mark as Paid', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=paid&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Paid', 'mp') . "</a>";
  4117.  
  4118. $actions['shipped'] = "<a title='" . esc_attr(__('Mark as Shipped', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=shipped&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Shipped', 'mp') . "</a>";
  4119.  
  4120. }
  4121.  
  4122.  
  4123.  
  4124. if ((isset($_GET['post_status'])) && ($_GET['post_status'] == "trash")) {
  4125.  
  4126. $actions['delete'] = "<a title='" . esc_attr(__('Delete', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=delete&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Delete Permanently', 'mp') . "</a>";
  4127.  
  4128. } else {
  4129.  
  4130. $actions['trash'] = "<a title='" . esc_attr(__('Trash', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=trash&amp;post=' . $post->ID), 'update-order-status' ) . "'>" . __('Trash', 'mp') . "</a>";
  4131.  
  4132. }
  4133.  
  4134.  
  4135.  
  4136. $action_count = count($actions);
  4137.  
  4138. $i = 0;
  4139.  
  4140. echo '<div class="row-actions">';
  4141.  
  4142. foreach ( $actions as $action => $link ) {
  4143.  
  4144. ++$i;
  4145.  
  4146. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  4147.  
  4148. echo "<span class='$action'>$link$sep</span>";
  4149.  
  4150. }
  4151.  
  4152. echo '</div>';
  4153.  
  4154. break;
  4155.  
  4156.  
  4157.  
  4158. case "mp_orders_name":
  4159.  
  4160. echo esc_attr($meta["mp_shipping_info"][0]['name']) . ' (<a href="mailto:' . urlencode($meta["mp_shipping_info"][0]['name']) . ' &lt;' . esc_attr($meta["mp_shipping_info"][0]['email']) . '&gt;?subject=' . urlencode(sprintf(__('Regarding Your Order (%s)', 'mp'), $post->post_title)) . '">' . esc_attr($meta["mp_shipping_info"][0]['email']) . '</a>)';
  4161.  
  4162. break;
  4163.  
  4164.  
  4165.  
  4166. case "mp_orders_items":
  4167.  
  4168. echo number_format_i18n($meta["mp_order_items"][0]);
  4169.  
  4170. break;
  4171.  
  4172.  
  4173.  
  4174. case "mp_orders_shipping":
  4175.  
  4176. echo $this->format_currency('', $meta["mp_shipping_total"][0]);
  4177.  
  4178. break;
  4179.  
  4180.  
  4181.  
  4182. case "mp_orders_tax":
  4183.  
  4184. echo $this->format_currency('', $meta["mp_tax_total"][0]);
  4185.  
  4186. break;
  4187.  
  4188.  
  4189.  
  4190. case "mp_orders_discount":
  4191.  
  4192. if (isset($meta["mp_discount_info"][0]) && $meta["mp_discount_info"][0])
  4193.  
  4194. echo $meta["mp_discount_info"][0]['discount'];
  4195.  
  4196. else
  4197.  
  4198. _e('N/A', 'mp');
  4199.  
  4200. break;
  4201.  
  4202.  
  4203.  
  4204. case "mp_orders_total":
  4205.  
  4206. echo $this->format_currency('', $meta["mp_order_total"][0]);
  4207.  
  4208. break;
  4209.  
  4210.  
  4211.  
  4212. }
  4213.  
  4214. }
  4215.  
  4216.  
  4217.  
  4218. //filters label in new product title field
  4219.  
  4220. function filter_title($post) {
  4221.  
  4222. global $post_type;
  4223.  
  4224.  
  4225.  
  4226. if ($post_type != 'product')
  4227.  
  4228. return $post;
  4229.  
  4230.  
  4231.  
  4232. return __( 'Enter Product title here', 'mp' );
  4233.  
  4234. }
  4235.  
  4236.  
  4237.  
  4238. //adds our custom meta boxes the the product edit screen
  4239.  
  4240. function meta_boxes() {
  4241.  
  4242. global $wp_meta_boxes;
  4243.  
  4244.  
  4245.  
  4246. add_meta_box('mp-meta-details', __('Product Details', 'mp'), array(&$this, 'meta_details'), 'product', 'normal', 'high');
  4247.  
  4248.  
  4249.  
  4250. //only add these boxes if orders are enabled
  4251.  
  4252. if (!$this->get_setting('disable_cart')) {
  4253.  
  4254.  
  4255.  
  4256. //only display metabox if shipping plugin ties into it
  4257.  
  4258. if ( has_action('mp_shipping_metabox') && 'none' != $this->get_setting('shipping->method') )
  4259.  
  4260. add_meta_box('mp-meta-shipping', __('Shipping', 'mp'), array(&$this, 'meta_shipping'), 'product', 'normal', 'high');
  4261.  
  4262.  
  4263.  
  4264. //for product downloads
  4265.  
  4266. add_meta_box('mp-meta-download', __('Product Download', 'mp'), array(&$this, 'meta_download'), 'product', 'normal', 'high');
  4267.  
  4268. }
  4269.  
  4270.  
  4271.  
  4272. //all this junk is to reorder the metabox array to move the featured image box to the top right below submit box. User order will override
  4273.  
  4274. if ( isset( $wp_meta_boxes['product']['side']['low']['postimagediv'] ) ) {
  4275.  
  4276. $imagediv = $wp_meta_boxes['product']['side']['low']['postimagediv'];
  4277.  
  4278. unset( $wp_meta_boxes['product']['side']['low']['postimagediv'] );
  4279.  
  4280. $submitdiv = $wp_meta_boxes['product']['side']['core']['submitdiv'];
  4281.  
  4282. unset( $wp_meta_boxes['product']['side']['core']['submitdiv'] );
  4283.  
  4284. $new_core['submitdiv'] = $submitdiv;
  4285.  
  4286. $new_core['postimagediv'] = $imagediv;
  4287.  
  4288. $wp_meta_boxes['product']['side']['core'] = array_merge( $new_core, $wp_meta_boxes['product']['side']['core']) ;
  4289.  
  4290. //filter title
  4291.  
  4292. $wp_meta_boxes['product']['side']['core']['postimagediv']['title'] = __('Product Image', 'mp');
  4293.  
  4294. }
  4295.  
  4296. }
  4297.  
  4298.  
  4299.  
  4300. //Save our post meta when a product is created or updated
  4301.  
  4302. function save_product_meta($post_id, $post = null) {
  4303.  
  4304. //skip quick edit
  4305.  
  4306. if ( defined('DOING_AJAX') )
  4307.  
  4308. return;
  4309.  
  4310.  
  4311.  
  4312. if ( $post->post_type == "product" && isset( $_POST['mp_product_meta'] ) ) {
  4313.  
  4314. $meta = get_post_custom($post_id);
  4315.  
  4316. foreach ($meta as $key => $val) {
  4317.  
  4318. $meta[$key] = maybe_unserialize($val[0]);
  4319.  
  4320. if (!is_array($meta[$key]) && $key != "mp_is_sale" && $key != "mp_track_inventory" && $key != "mp_product_link")
  4321.  
  4322. $meta[$key] = array($meta[$key]);
  4323.  
  4324. }
  4325.  
  4326.  
  4327.  
  4328. //price function
  4329.  
  4330. $func_curr = '$price = round(preg_replace("/[^0-9.]/", "", $price), 2);return ($price) ? $price : 0;';
  4331.  
  4332.  
  4333.  
  4334. //sku function
  4335.  
  4336. $func_sku = 'return preg_replace("/[^a-zA-Z0-9_-]/", "", $value);';
  4337.  
  4338.  
  4339.  
  4340. update_post_meta($post_id, 'mp_var_name', $_POST['mp_var_name']);
  4341.  
  4342. update_post_meta($post_id, 'mp_sku', array_map(create_function('$value', $func_sku), (array)$_POST['mp_sku']));
  4343.  
  4344. update_post_meta($post_id, 'mp_price', array_map(create_function('$price', $func_curr), (array)$_POST['mp_price']));
  4345.  
  4346. update_post_meta($post_id, 'mp_is_sale', isset($_POST['mp_is_sale']) ? 1 : 0);
  4347.  
  4348. update_post_meta($post_id, 'mp_sale_price', array_map(create_function('$price', $func_curr), (array)$_POST['mp_sale_price']));
  4349.  
  4350. update_post_meta($post_id, 'mp_track_inventory', isset($_POST['mp_track_inventory']) ? 1 : 0);
  4351.  
  4352. update_post_meta($post_id, 'mp_inventory', array_map('intval', (array)$_POST['mp_inventory']));
  4353.  
  4354. //track limit
  4355.  
  4356. update_post_meta($post_id, 'mp_track_limit', isset($_POST['mp_track_limit']) ? 1 : 0);
  4357.  
  4358. if( isset($_POST['mp_track_limit']) ){
  4359.  
  4360. //fill the array with the value of mp_limit
  4361.  
  4362. update_post_meta($post_id, 'mp_limit', array_fill(0, count((array)$_POST['mp_price']) , isset( $_POST['mp_limit'] ) ? $_POST['mp_limit'] : 1 ) );
  4363.  
  4364. }else{
  4365.  
  4366. //empty the array
  4367.  
  4368. update_post_meta($post_id, 'mp_limit',array());
  4369.  
  4370. }
  4371.  
  4372.  
  4373.  
  4374. //personalization fields
  4375.  
  4376. $mp_has_custom_field = $mp_custom_field_required = array();
  4377.  
  4378. foreach ((array)$_POST['mp_price'] as $key => $null) {
  4379.  
  4380. $mp_has_custom_field[$key] = isset($_POST['mp_has_custom_field'][$key]) ? 1 : 0;
  4381.  
  4382. $mp_custom_field_required[$key] = isset($_POST['mp_custom_field_required'][$key]) ? 1 : 0;
  4383.  
  4384. }
  4385.  
  4386. update_post_meta($post_id, 'mp_has_custom_field', $mp_has_custom_field);
  4387.  
  4388. update_post_meta($post_id, 'mp_custom_field_required', $mp_custom_field_required);
  4389.  
  4390.  
  4391.  
  4392. if (isset($_POST['mp_custom_field_per'])) {
  4393.  
  4394. update_post_meta($post_id, 'mp_custom_field_per', (array)$_POST['mp_custom_field_per']);
  4395.  
  4396. }
  4397.  
  4398.  
  4399.  
  4400. if (isset($_POST['mp_custom_field_label'])) {
  4401.  
  4402. update_post_meta($post_id, 'mp_custom_field_label', array_map('trim', (array)$_POST['mp_custom_field_label']));
  4403.  
  4404. }
  4405.  
  4406.  
  4407.  
  4408.  
  4409.  
  4410. //save true first variation price for sorting
  4411.  
  4412. if ( isset($_POST['mp_is_sale']) )
  4413.  
  4414. $sort_price = round($_POST['mp_sale_price'][0], 2);
  4415.  
  4416. else
  4417.  
  4418. $sort_price = round($_POST['mp_price'][0], 2);
  4419.  
  4420. update_post_meta($post_id, 'mp_price_sort', $sort_price);
  4421.  
  4422.  
  4423.  
  4424. //if changing delete flag so emails will be sent again
  4425.  
  4426. if ( $_POST['mp_inventory'] != $meta['mp_inventory'] )
  4427.  
  4428. delete_post_meta($product_id, 'mp_stock_email_sent');
  4429.  
  4430.  
  4431.  
  4432. update_post_meta( $post_id, 'mp_product_link', esc_url_raw($_POST['mp_product_link']) );
  4433.  
  4434.  
  4435.  
  4436. update_post_meta($post_id, 'mp_is_special_tax', isset($_POST['mp_is_special_tax']) ? 1 : 0);
  4437.  
  4438. $tax_rate = round(preg_replace("/[^0-9.]/", "", $_POST['mp_special_tax']), 3) * .01;
  4439.  
  4440. update_post_meta($post_id, 'mp_special_tax', $tax_rate);
  4441.  
  4442.  
  4443.  
  4444. //set sales count to zero if none set
  4445.  
  4446. $sale_count = ($meta["mp_sales_count"][0]) ? $meta["mp_sales_count"][0] : 0;
  4447.  
  4448. update_post_meta($post_id, 'mp_sales_count', $sale_count);
  4449.  
  4450.  
  4451.  
  4452. //for shipping plugins to save their meta values
  4453.  
  4454. $mp_shipping = maybe_unserialize($meta["mp_shipping"][0]);
  4455.  
  4456. if ( !is_array($mp_shipping) )
  4457.  
  4458. $mp_shipping = array();
  4459.  
  4460.  
  4461.  
  4462. update_post_meta( $post_id, 'mp_shipping', apply_filters('mp_save_shipping_meta', $mp_shipping) );
  4463.  
  4464.  
  4465.  
  4466. //download url
  4467.  
  4468. update_post_meta( $post_id, 'mp_file', esc_url_raw($_POST['mp_file']) );
  4469.  
  4470.  
  4471.  
  4472. //for any other plugin to hook into
  4473.  
  4474. do_action( 'mp_save_product_meta', $post_id, $meta );
  4475.  
  4476. }
  4477.  
  4478. }
  4479.  
  4480.  
  4481.  
  4482. // Make sure that product meta keys are present, set to sensible defaults
  4483.  
  4484. function get_meta_details( $post_id ) {
  4485.  
  4486. $meta = get_post_custom($post_id);
  4487.  
  4488. //unserialize
  4489.  
  4490. foreach ($meta as $key => $val) {
  4491.  
  4492. $meta[$key] = maybe_unserialize($val[0]);
  4493.  
  4494. if (!is_array($meta[$key]) && $key != "mp_is_sale" && $key != "mp_track_inventory" && $key != "mp_product_link" && $key != "mp_file" && $key != "mp_is_special_tax" && $key != "mp_special_tax" && $key != 'mp_track_limit')
  4495.  
  4496. $meta[$key] = array($meta[$key]);
  4497.  
  4498. }
  4499.  
  4500.  
  4501.  
  4502. $defaults = array(
  4503.  
  4504. 'mp_is_sale' => '',
  4505.  
  4506. 'mp_track_inventory' => '',
  4507.  
  4508. 'mp_price' => array(),
  4509.  
  4510. 'mp_product_link' => '',
  4511.  
  4512. 'mp_is_special_tax' => '',
  4513.  
  4514. 'mp_file' => '',
  4515.  
  4516. 'mp_shipping' => array(''),
  4517.  
  4518. 'mp_track_limit' => '',
  4519.  
  4520. 'mp_limit' => array(),
  4521.  
  4522. );
  4523.  
  4524.  
  4525.  
  4526. //Set default value if key is not already set.
  4527.  
  4528. return wp_parse_args($meta, $defaults);
  4529.  
  4530. }
  4531.  
  4532.  
  4533.  
  4534. //The Product Details meta box
  4535.  
  4536. function meta_details() {
  4537.  
  4538. global $post;
  4539.  
  4540. $meta = $this->get_meta_details( $post->ID );
  4541.  
  4542. ?>
  4543.  
  4544. <?php if ( defined( 'MP_LITE' ) ) { ?>
  4545.  
  4546. <a class="mp-pro-update" href="http://premium.wpmudev.org/project/e-commerce/" title="<?php _e('Upgrade Now', 'mp'); ?> &raquo;"><?php _e('Upgrade to enable item personalization &raquo;', 'mp'); ?></a><br />
  4547.  
  4548. <?php } ?>
  4549.  
  4550. <input type="hidden" name="mp_product_meta" value="1" />
  4551.  
  4552. <table class="widefat" id="mp_product_variations_table">
  4553.  
  4554. <thead>
  4555.  
  4556. <tr>
  4557.  
  4558. <th scope="col" class="mp_var_col"><?php _e('Variation Name', 'mp') ?></th>
  4559.  
  4560. <th scope="col" class="mp_sku_col" title="<?php _e('Stock Keeping Unit - Your custom Product ID number', 'mp'); ?>"><?php _e('SKU', 'mp') ?></th>
  4561.  
  4562. <th scope="col" class="mp_price_col"><?php _e('Price', 'mp') ?></th>
  4563.  
  4564. <th scope="col" class="mp_sale_col"><label title="<?php _e('When checked these override the normal price.', 'mp'); ?>"><input type="checkbox" id="mp_is_sale" name="mp_is_sale" value="1"<?php checked($meta["mp_is_sale"], '1'); ?> /> <?php _e('Sale Price', 'mp') ?></label></th>
  4565.  
  4566. <th scope="col" class="mp_inv_col"><label title="<?php _e('When checked inventory tracking will be enabled.', 'mp'); ?>"><input type="checkbox" id="mp_track_inventory" name="mp_track_inventory" value="1"<?php checked($meta["mp_track_inventory"], '1'); ?> /> <?php _e('Inventory', 'mp') ?></label></th>
  4567.  
  4568. <th scope="col" class="mp_custom_field_col" title="<?php _e('Should this product be personalizable by the customer?', 'mp'); ?>"><?php _e('Personalize', 'mp') ?></th>
  4569.  
  4570. <th scope="col" class="mp_var_remove"></th>
  4571.  
  4572. </tr>
  4573.  
  4574. </thead>
  4575.  
  4576. <tbody>
  4577.  
  4578. <?php
  4579.  
  4580. if (isset($meta["mp_price"]) && $meta["mp_price"]) {
  4581.  
  4582. //if download enabled only show first variation
  4583.  
  4584. $meta["mp_price"] = (empty($meta["mp_file"]) && empty($meta["mp_product_link"])) ? $meta["mp_price"] : array($meta["mp_price"][0]);
  4585.  
  4586. $count = 1;
  4587.  
  4588. $last = count($meta["mp_price"]);
  4589.  
  4590. foreach ($meta["mp_price"] as $key => $price) {
  4591.  
  4592. ?>
  4593.  
  4594. <tr class="variation">
  4595.  
  4596. <td class="mp_var_col"><input type="text" name="mp_var_name[]" value="<?php echo esc_attr($meta["mp_var_name"][$key]); ?>" /></td>
  4597.  
  4598. <td class="mp_sku_col"><input type="text" name="mp_sku[]" value="<?php echo esc_attr($meta["mp_sku"][$key]); ?>" /></td>
  4599.  
  4600. <td class="mp_price_col"><?php echo $this->format_currency(); ?><input type="text" name="mp_price[]" value="<?php echo isset($meta["mp_price"][$key]) ? $this->display_currency($meta["mp_price"][$key]) : '0.00'; ?>" /></td>
  4601.  
  4602. <td class="mp_sale_col"><?php echo $this->format_currency(); ?><input type="text" name="mp_sale_price[]" value="<?php echo isset($meta["mp_sale_price"][$key]) ? $this->display_currency($meta["mp_sale_price"][$key]) : $this->display_currency($meta["mp_price"][$key]); ?>" disabled="disabled" /></td>
  4603.  
  4604. <td class="mp_inv_col"><input type="text" name="mp_inventory[]" value="<?php echo isset($meta["mp_inventory"][$key]) ? intval($meta["mp_inventory"][$key]) : 0; ?>" disabled="disabled" /></td>
  4605.  
  4606. <td class="mp_custom_field_col"><input type="checkbox" class="mp_has_custom_field" name="mp_has_custom_field[<?php echo $key; ?>]" value="1" <?php checked(!defined('MP_LITE') && isset($meta['mp_has_custom_field'][$key]) && $meta['mp_has_custom_field'][$key]); echo defined('MP_LITE') ? ' disabled="disabled"' : ''; ?> /></td>
  4607.  
  4608. <td class="mp_var_remove">
  4609.  
  4610. <?php if ($count == $last) { ?><a href="#mp_product_variations_table" title="<?php _e('Remove Variation', 'mp'); ?>">x</a><?php } ?>
  4611.  
  4612. </td>
  4613.  
  4614. </tr>
  4615.  
  4616. <tr class="variation-custom-field <?php echo (defined('MP_LITE') || !isset($meta['mp_has_custom_field'][$key]) || !$meta['mp_has_custom_field'][$key]) ? ' variation-custom-field-hidden' : ''; ?>">
  4617.  
  4618. <td class="mp_custom_label_col" colspan="1">
  4619.  
  4620. <input type="hidden" class="mp_custom_field_type" name="mp_custom_field_type[<?php echo $key; ?>]" value="input" />
  4621.  
  4622. <input type="hidden" class="mp_custom_field_per" name="mp_custom_field_per[<?php echo $key; ?>]" value="quantity" />
  4623.  
  4624. <label class="mp_custom_field_label"><?php _e('Description:', 'mp'); ?></label>
  4625.  
  4626. <input type="text" class="mp_custom_field_value" name="mp_custom_field_label[<?php echo $key; ?>]" value="<?php echo isset($meta['mp_custom_field_label'][$key]) ? esc_attr($meta['mp_custom_field_label'][$key]) : ''; ?>" />
  4627.  
  4628. <label class="mp_custom_field_required_label">
  4629.  
  4630. <input type="checkbox" class="mp_custom_field_required" name="mp_custom_field_required[<?php echo $key; ?>]" value="1" <?php echo checked(isset($meta['mp_custom_field_required'][$key]) && $meta['mp_custom_field_required'][$key]); ?> /> <?php _e('Required', 'mp'); ?></label>
  4631.  
  4632. </td>
  4633.  
  4634. <td>&nbsp;</td>
  4635.  
  4636. </tr>
  4637.  
  4638. <?php
  4639.  
  4640. $count++;
  4641.  
  4642. }
  4643.  
  4644. } else {
  4645.  
  4646. ?>
  4647.  
  4648. <tr class="variation">
  4649.  
  4650. <td class="mp_var_col"><input type="text" name="mp_var_name[]" value="" /></td>
  4651.  
  4652. <td class="mp_sku_col"><input type="text" name="mp_sku[]" value="" /></td>
  4653.  
  4654. <td class="mp_price_col"><?php echo $this->format_currency(); ?><input type="text" name="mp_price[]" value="0.00" /></td>
  4655.  
  4656. <td class="mp_sale_col"><?php echo $this->format_currency(); ?><input type="text" name="mp_sale_price[]" value="0.00" disabled="disabled" /></td>
  4657.  
  4658. <td class="mp_inv_col"><input type="text" name="mp_inventory[]" value="0" disabled="disabled" /></td>
  4659.  
  4660. <td class="mp_custom_field_col"><input type="checkbox" class="mp_has_custom_field" name="mp_has_custom_field[]" value="1"<?php echo defined('MP_LITE') ? ' disabled="disabled"' : ''; ?> /></td>
  4661.  
  4662. <td class="mp_var_remove"><a href="#mp_product_variations_table" title="<?php _e('Remove Variation', 'mp'); ?>">x</a></td>
  4663.  
  4664. </tr>
  4665.  
  4666. <tr class="variation-custom-field variation-custom-field-hidden">
  4667.  
  4668. <td class="mp_custom_label_col" colspan="5">
  4669.  
  4670. <input type="hidden" class="mp_custom_field_type" name="mp_custom_field_type[]" value="input" />
  4671.  
  4672. <input type="hidden" class="mp_custom_field_per" name="mp_custom_field_per[]" value="quantity" />
  4673.  
  4674. <label class="mp_custom_field_label"><?php _e('Description:', 'mp'); ?></label> <input type="text" class="mp_custom_field_value" name="mp_custom_field_label[]" value="" />
  4675.  
  4676. <input type="checkbox" class="mp_custom_field_required" name="mp_custom_field_required[]" value="1" /> <label class="mp_custom_field_required_label"><?php _e('Required:', 'mp'); ?></label>
  4677.  
  4678. </td>
  4679.  
  4680. <td>&nbsp;</td>
  4681.  
  4682. </tr>
  4683.  
  4684. <?php
  4685.  
  4686. }
  4687.  
  4688. ?>
  4689.  
  4690. </tbody>
  4691.  
  4692. </table>
  4693.  
  4694. <?php if (empty($meta["mp_file"]) && empty($meta["mp_product_link"])) { ?>
  4695.  
  4696. <div id="mp_add_vars"><a href="#mp_product_variations_table"><?php _e('Add Variation', 'mp'); ?></a></div>
  4697.  
  4698. <?php } else { ?>
  4699.  
  4700. <span class="description" id="mp_variation_message"><?php _e('Product variations are not allowed for Downloadable or Externally Linked products.', 'mp') ?></span>
  4701.  
  4702. <?php } ?>
  4703.  
  4704.  
  4705.  
  4706. <div id="mp_product_link_div">
  4707.  
  4708. <label title="<?php _e('Some examples are linking to a song/album in iTunes, or linking to a product on another site with your own affiliate link.', 'mp'); ?>"><?php _e('External Link', 'mp'); ?>:<br /><small><?php _e('When set this overrides the purchase button with a link to this URL.', 'mp'); ?></small><br />
  4709.  
  4710. <input type="text" style="width: 100%;" id="mp_product_link" name="mp_product_link" value="<?php echo esc_url($meta["mp_product_link"]); ?>" /></label>
  4711.  
  4712. </div>
  4713.  
  4714.  
  4715.  
  4716. <div id="mp_tax_rate_div">
  4717.  
  4718. <label title="<?php esc_attr_e('Depending on local tax laws, some items are tax-free or a have different sales tax rate. You can set that here.', 'mp'); ?>"><input type="checkbox" id="mp_is_special_tax" name="mp_is_special_tax" value="1" <?php checked($meta["mp_is_special_tax"]); ?>/> <?php _e('Special Tax Rate?', 'mp'); ?></label>
  4719.  
  4720. <label id="mp_special_tax"<?php echo ($meta["mp_is_special_tax"]) ? '' : ' style="display:none;"'; ?>><?php _e('Rate:', 'mp'); ?> <input type="text" size="2" name="mp_special_tax" value="<?php echo isset($meta["mp_special_tax"]) ? round($meta["mp_special_tax"] * 100, 3) : 0; ?>" />%</label>
  4721.  
  4722. </div>
  4723.  
  4724.  
  4725.  
  4726. <div id="mp_cart_limit_div">
  4727.  
  4728. <label title="<?php esc_attr_e('Limit the order to a certain amount of this product.', 'mp'); ?>">
  4729.  
  4730. <input type="checkbox" id="mp_track_limit" name="mp_track_limit" value="1" <?php checked($meta['mp_track_limit']); ?> /> <?php _e('Limit Per Order?','mp');?>
  4731.  
  4732. </label>
  4733.  
  4734.  
  4735.  
  4736. <label id="mp_limit"<?php echo ($meta['mp_track_limit']) ? '' :' style="display:none;"';?> ><?php _e('Limit:', 'mp');?>
  4737.  
  4738. <input type="text" size="2" name="mp_limit" value="<?php echo isset( $meta['mp_limit'][0]) ? intval($meta['mp_limit'][0]) : '1' ;?>" /></label>
  4739.  
  4740.  
  4741.  
  4742. </div>
  4743.  
  4744.  
  4745.  
  4746. <?php do_action( 'mp_details_metabox' ); ?>
  4747.  
  4748. <div class="clear"></div>
  4749.  
  4750. <?php
  4751.  
  4752. }
  4753.  
  4754.  
  4755.  
  4756. //The Shipping meta box
  4757.  
  4758. function meta_shipping() {
  4759.  
  4760. global $post;
  4761.  
  4762. $settings = get_option('mp_settings');
  4763.  
  4764. $mp_shipping = get_post_meta($post->ID, 'mp_shipping', true);
  4765.  
  4766. $mp_shipping = $mp_shipping ? maybe_unserialize($mp_shipping) : array();
  4767.  
  4768.  
  4769.  
  4770. //tie in for shipping plugins
  4771.  
  4772. do_action( 'mp_shipping_metabox', $mp_shipping, $settings );
  4773.  
  4774. }
  4775.  
  4776.  
  4777.  
  4778. //The Product Download meta box
  4779.  
  4780. function meta_download() {
  4781.  
  4782. global $post;
  4783.  
  4784. $file = get_post_meta($post->ID, 'mp_file', true);
  4785.  
  4786. ?>
  4787.  
  4788. <label><?php _e('File URL', 'mp'); ?>:<br /><input type="text" size="50" id="mp_file" class="mp_file" name="mp_file" value="<?php echo esc_attr($file); ?>" /></label>
  4789.  
  4790. <input id="mp_upload_button" class="button-secondary" type="button" value="<?php _e('Upload File', 'mp'); ?>" /><br />
  4791.  
  4792. <?php
  4793.  
  4794. //display allowed filetypes if WPMU
  4795.  
  4796. if (is_multisite()) {
  4797.  
  4798. echo '<span class="description">Allowed Filetypes: '.implode(', ', explode(' ', get_site_option('upload_filetypes'))).'</span>';
  4799.  
  4800. if (is_super_admin()) {
  4801.  
  4802. echo '<p>Super Admin: You can change allowed filetypes for your network <a href="' . network_admin_url('settings.php#upload_filetypes') . '">here &raquo;</a></p>';
  4803.  
  4804. }
  4805.  
  4806. }
  4807.  
  4808.  
  4809.  
  4810. do_action( 'mp_download_metabox' );
  4811.  
  4812. }
  4813.  
  4814.  
  4815.  
  4816. //returns the calculated price adjusted for sales, formatted or not
  4817.  
  4818. function product_price($product_id, $variation = 0, $format = false) {
  4819.  
  4820.  
  4821.  
  4822. $meta = get_post_custom($product_id);
  4823.  
  4824. //unserialize
  4825.  
  4826. foreach ($meta as $key => $val) {
  4827.  
  4828. $meta[$key] = maybe_unserialize($val[0]);
  4829.  
  4830. if (!is_array($meta[$key]) && $key != "mp_is_sale" && $key != "mp_track_inventory" && $key != "mp_product_link")
  4831.  
  4832. $meta[$key] = array($meta[$key]);
  4833.  
  4834. }
  4835.  
  4836.  
  4837.  
  4838. if (is_array($meta["mp_price"])) {
  4839.  
  4840. if ($meta["mp_is_sale"]) {
  4841.  
  4842. $price = $meta["mp_sale_price"][$variation];
  4843.  
  4844. } else {
  4845.  
  4846. $price = $meta["mp_price"][$variation];
  4847.  
  4848. }
  4849.  
  4850. }
  4851.  
  4852.  
  4853.  
  4854. $price = ($price) ? $price : 0;
  4855.  
  4856. $price = $this->display_currency($price);
  4857.  
  4858.  
  4859.  
  4860. $price = apply_filters( 'mp_product_price', $price, $product_id );
  4861.  
  4862.  
  4863.  
  4864. if ($format)
  4865.  
  4866. return $this->format_currency('', $price);
  4867.  
  4868. else
  4869.  
  4870. return $price;
  4871.  
  4872. }
  4873.  
  4874.  
  4875.  
  4876. //returns the calculated price for shipping. Returns False if shipping address is not available
  4877.  
  4878. function shipping_price($format = false, $cart = false) {
  4879.  
  4880. global $mp_shipping_active_plugins;
  4881.  
  4882.  
  4883.  
  4884. //grab cart for just this blog
  4885.  
  4886. if (!$cart)
  4887.  
  4888. $cart = $this->get_cart_contents();
  4889.  
  4890.  
  4891.  
  4892. //get total after any coupons
  4893.  
  4894. $totals = array();
  4895.  
  4896. foreach ($cart as $product_id => $variations) {
  4897.  
  4898. foreach ($variations as $variation => $data) {
  4899.  
  4900. $totals[] = $this->before_tax_price($data['price'], $product_id) * $data['quantity'];
  4901.  
  4902. }
  4903.  
  4904. }
  4905.  
  4906.  
  4907.  
  4908. $total = array_sum($totals);
  4909.  
  4910.  
  4911.  
  4912. $coupon_code = $this->get_coupon_code();
  4913.  
  4914. if ( $coupon = $this->coupon_value($coupon_code, $total) )
  4915.  
  4916. $total = $coupon['new_total'];
  4917.  
  4918.  
  4919.  
  4920. //get address
  4921.  
  4922. $meta = get_user_meta(get_current_user_id(), 'mp_shipping_info', true);
  4923.  
  4924. $address1 = isset($_SESSION['mp_shipping_info']['address1']) ? $_SESSION['mp_shipping_info']['address1'] : (isset($meta['address1']) ? $meta['address1'] : '');
  4925.  
  4926. $address2 = isset($_SESSION['mp_shipping_info']['address2']) ? $_SESSION['mp_shipping_info']['address2'] : (isset($meta['address2']) ? $meta['address2'] : '');
  4927.  
  4928. $city = isset($_SESSION['mp_shipping_info']['city']) ? $_SESSION['mp_shipping_info']['city'] : (isset($meta['city']) ? $meta['city'] : '');
  4929.  
  4930. $state = isset($_SESSION['mp_shipping_info']['state']) ? $_SESSION['mp_shipping_info']['state'] : (isset($meta['state']) ? $meta['state'] : '');
  4931.  
  4932. $zip = isset($_SESSION['mp_shipping_info']['zip']) ? $_SESSION['mp_shipping_info']['zip'] : (isset($meta['zip']) ? $meta['zip'] : '');
  4933.  
  4934. $country = isset($_SESSION['mp_shipping_info']['country']) ? $_SESSION['mp_shipping_info']['country'] : (isset($meta['country']) ? $meta['country'] : '');
  4935.  
  4936. $selected_option = isset($_SESSION['mp_shipping_info']['shipping_sub_option']) ? $_SESSION['mp_shipping_info']['shipping_sub_option'] : null;
  4937.  
  4938.  
  4939.  
  4940. //check required fields
  4941.  
  4942. if ( empty($address1) || empty($city) || empty($zip) || empty($country) || !(is_array($cart) && count($cart)) )
  4943.  
  4944. return false;
  4945.  
  4946.  
  4947.  
  4948. //don't charge shipping if only digital products
  4949.  
  4950. if ( $this->download_only_cart($cart) ) {
  4951.  
  4952. $price = 0;
  4953.  
  4954. } else if ( $this->get_setting('shipping->method') == 'calculated' && isset($_SESSION['mp_shipping_info']['shipping_option']) && isset($mp_shipping_active_plugins[$_SESSION['mp_shipping_info']['shipping_option']]) ) {
  4955.  
  4956. //shipping plugins tie into this to calculate their shipping cost
  4957.  
  4958. $price = apply_filters( 'mp_calculate_shipping_'.$_SESSION['mp_shipping_info']['shipping_option'], 0, $total, $cart, $address1, $address2, $city, $state, $zip, $country, $selected_option );
  4959.  
  4960. } else {
  4961.  
  4962. //shipping plugins tie into this to calculate their shipping cost
  4963.  
  4964. $price = apply_filters( 'mp_calculate_shipping_'.$this->get_setting('shipping->method'), 0, $total, $cart, $address1, $address2, $city, $state, $zip, $country, $selected_option );
  4965.  
  4966. }
  4967.  
  4968.  
  4969.  
  4970. //calculate extra shipping
  4971.  
  4972. $extras = array();
  4973.  
  4974. foreach ($cart as $product_id => $variations) {
  4975.  
  4976. $shipping_meta = get_post_meta($product_id, 'mp_shipping', true);
  4977.  
  4978. foreach ($variations as $variation => $data) {
  4979.  
  4980. if (!$data['download'])
  4981.  
  4982. $extras[] = $shipping_meta['extra_cost'] * $data['quantity'];
  4983.  
  4984. }
  4985.  
  4986. }
  4987.  
  4988. $extra = array_sum($extras);
  4989.  
  4990.  
  4991.  
  4992. //merge
  4993.  
  4994. $price = round($price + $extra, 2);
  4995.  
  4996.  
  4997.  
  4998. //boot if shipping plugin didn't return at least 0
  4999.  
  5000. if (empty($price))
  5001.  
  5002. return false;
  5003.  
  5004.  
  5005.  
  5006. if ($format)
  5007.  
  5008. return $this->format_currency('', $price);
  5009.  
  5010. else
  5011.  
  5012. return $price;
  5013.  
  5014. }
  5015.  
  5016.  
  5017.  
  5018. //returns the calculated price for shipping after tax. For display only.
  5019.  
  5020. function shipping_tax_price($shipping_price) {
  5021.  
  5022.  
  5023.  
  5024. if ( !$this->get_setting('tax->tax_shipping') || !$this->get_setting('tax->tax_inclusive') )
  5025.  
  5026. return $shipping_price;
  5027.  
  5028.  
  5029.  
  5030. //get address
  5031.  
  5032. $meta = get_user_meta(get_current_user_id(), 'mp_shipping_info', true);
  5033.  
  5034.  
  5035.  
  5036. if (!isset($meta['state'])) {
  5037.  
  5038. $meta['state'] = '';
  5039.  
  5040. }
  5041.  
  5042. if (!isset($meta['country'])) {
  5043.  
  5044. $meta['country'] = '';
  5045.  
  5046. }
  5047.  
  5048.  
  5049.  
  5050. $state = isset($_SESSION['mp_shipping_info']['state']) ? $_SESSION['mp_shipping_info']['state'] : $meta['state'];
  5051.  
  5052. $country = isset($_SESSION['mp_shipping_info']['country']) ? $_SESSION['mp_shipping_info']['country'] : $meta['country'];
  5053.  
  5054.  
  5055.  
  5056. //if we've skipped the shipping page and no address is set, use base for tax calculation
  5057.  
  5058. if ($this->get_setting('tax->tax_inclusive') || $this->get_setting('shipping->method') == 'none') {
  5059.  
  5060. if (empty($country))
  5061.  
  5062. $country = $this->get_setting('base_country');
  5063.  
  5064. if (empty($state))
  5065.  
  5066. $state = $this->get_setting('base_province');
  5067.  
  5068. }
  5069.  
  5070.  
  5071.  
  5072. //check required fields
  5073.  
  5074. if ( empty($country) || $shipping_price <= 0 ) {
  5075.  
  5076. return false;
  5077.  
  5078. }
  5079.  
  5080.  
  5081.  
  5082. switch ($this->get_setting('base_country')) {
  5083.  
  5084. case 'US':
  5085.  
  5086. //USA taxes are only for orders delivered inside the state
  5087.  
  5088. if ($country == 'US' && $state == $this->get_setting('base_province'))
  5089.  
  5090. $price = round(($shipping_price * $this->get_setting('tax->rate')), 2);
  5091.  
  5092. break;
  5093.  
  5094.  
  5095.  
  5096. case 'CA':
  5097.  
  5098. //Canada tax is for all orders in country, based on province shipped to. We're assuming the rate is a combination of GST/PST/etc.
  5099.  
  5100. if ( $country == 'CA' && array_key_exists($state, $this->canadian_provinces) ) {
  5101.  
  5102. if (!is_null($this->get_setting("tax->canada_rate->$state")))
  5103.  
  5104. $price = round(($shipping_price * $this->get_setting("tax->canada_rate->$state")), 2);
  5105.  
  5106. else //backwards compat with pre 2.2 if per province rates are not set
  5107.  
  5108. $price = round(($shipping_price * $this->get_setting('tax->rate')), 2);
  5109.  
  5110. }
  5111.  
  5112. break;
  5113.  
  5114.  
  5115.  
  5116. case 'AU':
  5117.  
  5118. //Australia taxes orders in country
  5119.  
  5120. if ($country == 'AU')
  5121.  
  5122. $price = round(($shipping_price * $this->get_setting('tax->rate')), 2);
  5123.  
  5124. break;
  5125.  
  5126.  
  5127.  
  5128. default:
  5129.  
  5130. //EU countries charge VAT within the EU
  5131.  
  5132. if ( in_array($this->get_setting('base_country'), $this->eu_countries) ) {
  5133.  
  5134. if (in_array($country, $this->eu_countries))
  5135.  
  5136. $price = round(($shipping_price * $this->get_setting('tax->rate')), 2);
  5137.  
  5138. } else {
  5139.  
  5140. //all other countries use the tax outside preference
  5141.  
  5142. if ($this->get_setting('tax->tax_outside') || (!$this->get_setting('tax->tax_outside') && $country == $this->get_setting('base_country')))
  5143.  
  5144. $price = round(($shipping_price * $this->get_setting('tax->rate')), 2);
  5145.  
  5146. }
  5147.  
  5148. break;
  5149.  
  5150. }
  5151.  
  5152. if (empty($price))
  5153.  
  5154. $price = 0;
  5155.  
  5156.  
  5157.  
  5158. $price = apply_filters( 'mp_shipping_tax_price', $price, $shipping_price, $country, $state );
  5159.  
  5160.  
  5161.  
  5162. $price += $shipping_price;
  5163.  
  5164.  
  5165.  
  5166. return $price;
  5167.  
  5168. }
  5169.  
  5170.  
  5171.  
  5172. function get_display_shipping($order) {
  5173.  
  5174. return (float)(isset($order->mp_shipping_with_tax) ? $order->mp_shipping_with_tax : $order->mp_tax_shipping);
  5175.  
  5176. }
  5177.  
  5178.  
  5179.  
  5180. //returns the calculated price for taxes based on a bunch of foreign tax laws.
  5181.  
  5182. function tax_price($format = false, $cart = false) {
  5183.  
  5184.  
  5185.  
  5186. //grab cart for just this blog
  5187.  
  5188. if (!$cart)
  5189.  
  5190. $cart = $this->get_cart_contents();
  5191.  
  5192.  
  5193.  
  5194. //get address
  5195.  
  5196. $meta = get_user_meta(get_current_user_id(), 'mp_shipping_info', true);
  5197.  
  5198.  
  5199.  
  5200. if (!isset($meta['state'])) {
  5201.  
  5202. $meta['state'] = '';
  5203.  
  5204. }
  5205.  
  5206. if (!isset($meta['country'])) {
  5207.  
  5208. $meta['country'] = '';
  5209.  
  5210. }
  5211.  
  5212.  
  5213.  
  5214. $state = isset($_SESSION['mp_shipping_info']['state']) ? $_SESSION['mp_shipping_info']['state'] : $meta['state'];
  5215.  
  5216. $country = isset($_SESSION['mp_shipping_info']['country']) ? $_SESSION['mp_shipping_info']['country'] : $meta['country'];
  5217.  
  5218.  
  5219.  
  5220. //if we've skipped the shipping page and no address is set, use base for tax calculation
  5221.  
  5222. if ($this->download_only_cart($cart) || $this->get_setting('tax->tax_inclusive') || $this->get_setting('shipping->method') == 'none') {
  5223.  
  5224. if (empty($country))
  5225.  
  5226. $country = $this->get_setting('base_country');
  5227.  
  5228. if (empty($state))
  5229.  
  5230. $state = $this->get_setting('base_province');
  5231.  
  5232. }
  5233.  
  5234.  
  5235.  
  5236. //get total after any coupons
  5237.  
  5238. $totals = array();
  5239.  
  5240. $special_totals = array();
  5241.  
  5242. foreach ($cart as $product_id => $variations) {
  5243.  
  5244. //check for special rate
  5245.  
  5246. $special = (bool)get_post_meta($product_id, 'mp_is_special_tax', true);
  5247.  
  5248. if ($special)
  5249.  
  5250. $special_rate = get_post_meta($product_id, 'mp_special_tax', true);
  5251.  
  5252. foreach ($variations as $variation => $data) {
  5253.  
  5254. //if not taxing digital goods, skip them completely
  5255.  
  5256. if ( !$this->get_setting('tax->tax_digital') && isset($data['download']) && is_array($data['download']) )
  5257.  
  5258. continue;
  5259.  
  5260.  
  5261.  
  5262. if ($special)
  5263.  
  5264. $special_totals[] = ($this->before_tax_price($data['price'], $product_id) * $data['quantity']) * $special_rate;
  5265.  
  5266. else
  5267.  
  5268. $totals[] = $this->before_tax_price($data['price'], false) * $data['quantity'];
  5269.  
  5270. }
  5271.  
  5272. }
  5273.  
  5274.  
  5275.  
  5276. $total = array_sum($totals);
  5277.  
  5278. $special_total = array_sum($special_totals);
  5279.  
  5280.  
  5281.  
  5282. $coupon_code = $this->get_coupon_code();
  5283.  
  5284. if ( $coupon = $this->coupon_value($coupon_code, $total) )
  5285.  
  5286. $total = $coupon['new_total'];
  5287.  
  5288.  
  5289.  
  5290. //add in shipping?
  5291.  
  5292. if ( $this->get_setting('tax->tax_shipping') && ($shipping_price = $this->shipping_price()) )
  5293.  
  5294. $total += $shipping_price;
  5295.  
  5296.  
  5297.  
  5298. //check required fields
  5299.  
  5300. if ( empty($country) || !(is_array($cart) && count($cart)) || ($total + $special_total) <= 0 ) {
  5301.  
  5302. return false;
  5303.  
  5304. }
  5305.  
  5306.  
  5307.  
  5308. switch ($this->get_setting('base_country')) {
  5309.  
  5310. case 'US':
  5311.  
  5312. //USA taxes are only for orders delivered inside the state
  5313.  
  5314. if ($country == 'US' && $state == $this->get_setting('base_province'))
  5315.  
  5316. $price = round(($total * $this->get_setting('tax->rate')) + $special_total, 2);
  5317.  
  5318. break;
  5319.  
  5320.  
  5321.  
  5322. case 'CA':
  5323.  
  5324. //Canada tax is for all orders in country, based on province shipped to. We're assuming the rate is a combination of GST/PST/etc.
  5325.  
  5326. if ( $country == 'CA' && array_key_exists($state, $this->canadian_provinces) ) {
  5327.  
  5328. if (!is_null($this->get_setting("tax->canada_rate->$state")))
  5329.  
  5330. $price = round(($total * $this->get_setting("tax->canada_rate->$state")) + $special_total, 2);
  5331.  
  5332. else //backwards compat with pre 2.2 if per province rates are not set
  5333.  
  5334. $price = round(($total * $this->get_setting('tax->rate')) + $special_total, 2);
  5335.  
  5336. }
  5337.  
  5338. break;
  5339.  
  5340.  
  5341.  
  5342. case 'AU':
  5343.  
  5344. //Australia taxes orders in country
  5345.  
  5346. if ($country == 'AU')
  5347.  
  5348. $price = round(($total * $this->get_setting('tax->rate')) + $special_total, 2);
  5349.  
  5350. break;
  5351.  
  5352.  
  5353.  
  5354. default:
  5355.  
  5356. //EU countries charge VAT within the EU
  5357.  
  5358. if ( in_array($this->get_setting('base_country'), $this->eu_countries) ) {
  5359.  
  5360. if (in_array($country, $this->eu_countries))
  5361.  
  5362. $price = round(($total * $this->get_setting('tax->rate')) + $special_total, 2);
  5363.  
  5364. } else {
  5365.  
  5366. //all other countries use the tax outside preference
  5367.  
  5368. if ($this->get_setting('tax->tax_outside') || (!$this->get_setting('tax->tax_outside') && $country == $this->get_setting('base_country')))
  5369.  
  5370. $price = round(($total * $this->get_setting('tax->rate')) + $special_total, 2);
  5371.  
  5372. }
  5373.  
  5374. break;
  5375.  
  5376. }
  5377.  
  5378. if (empty($price))
  5379.  
  5380. $price = 0;
  5381.  
  5382.  
  5383.  
  5384. $price = apply_filters( 'mp_tax_price', $price, $total, $cart, $country, $state );
  5385.  
  5386.  
  5387.  
  5388. if ($format)
  5389.  
  5390. return $this->format_currency('', $price);
  5391.  
  5392. else
  5393.  
  5394. return $price;
  5395.  
  5396. }
  5397.  
  5398.  
  5399.  
  5400. //returns the before tax price for a given amount based on a bunch of foreign tax laws.
  5401.  
  5402. function before_tax_price($tax_price, $product_id = false) {
  5403.  
  5404.  
  5405.  
  5406. //if tax inclusve pricing is turned off just return given price
  5407.  
  5408. if (!$this->get_setting('tax->tax_inclusive'))
  5409.  
  5410. return $tax_price;
  5411.  
  5412.  
  5413.  
  5414. if ($product_id && get_post_meta($product_id, 'mp_is_special_tax', true)) {
  5415.  
  5416. $rate = get_post_meta($product_id, 'mp_special_tax', true);
  5417.  
  5418. } else {
  5419.  
  5420. //figure out rate in case its based on a canadian base province
  5421.  
  5422. $rate = ('CA' == $this->get_setting('tax->base_country')) ? $this->get_setting('tax->canada_rate'.$this->get_setting('base_province')) : $this->get_setting('tax->rate');
  5423.  
  5424. }
  5425.  
  5426.  
  5427.  
  5428. //return round($tax_price / ($rate + 1), 2);
  5429.  
  5430. return $tax_price / ($rate + 1); //do not round this to avoid rounding errors in tax calculation
  5431.  
  5432. }
  5433.  
  5434.  
  5435.  
  5436. //returns contents of shopping cart cookie
  5437.  
  5438. function get_cart_cookie($global = false) {
  5439.  
  5440. global $blog_id;
  5441.  
  5442. $blog_id = (is_multisite()) ? $blog_id : 1;
  5443.  
  5444.  
  5445.  
  5446. $cookie_id = 'mp_globalcart_' . COOKIEHASH;
  5447.  
  5448.  
  5449.  
  5450. if (isset($_COOKIE[$cookie_id])) {
  5451.  
  5452. $global_cart = unserialize($_COOKIE[$cookie_id]);
  5453.  
  5454. } else {
  5455.  
  5456. $global_cart = array($blog_id => array());
  5457.  
  5458. }
  5459.  
  5460.  
  5461.  
  5462. if ($global) {
  5463.  
  5464. return $global_cart;
  5465.  
  5466. } else {
  5467.  
  5468. if (isset($global_cart[$blog_id])) {
  5469.  
  5470. return $global_cart[$blog_id];
  5471.  
  5472. } else {
  5473.  
  5474. return array();
  5475.  
  5476. }
  5477.  
  5478. }
  5479.  
  5480. }
  5481.  
  5482.  
  5483.  
  5484. //saves global cart array to cookie
  5485.  
  5486. function set_global_cart_cookie($global_cart) {
  5487.  
  5488. $cookie_id = 'mp_globalcart_' . COOKIEHASH;
  5489.  
  5490.  
  5491.  
  5492. //set cookie
  5493.  
  5494. $expire = time() + 2592000; //1 month expire
  5495.  
  5496. setcookie($cookie_id, serialize($global_cart), $expire, COOKIEPATH, COOKIE_DOMAIN);
  5497.  
  5498.  
  5499.  
  5500. // Set the cookie variable as well, sometimes updating the cache doesn't work
  5501.  
  5502. $_COOKIE[$cookie_id] = serialize($global_cart);
  5503.  
  5504.  
  5505.  
  5506. //mark cache for updating
  5507.  
  5508. $this->cart_cache = false;
  5509.  
  5510. }
  5511.  
  5512.  
  5513.  
  5514. //saves cart array to cookie
  5515.  
  5516. function set_cart_cookie($cart) {
  5517.  
  5518. global $blog_id, $mp_gateway_active_plugins;
  5519.  
  5520. $blog_id = (is_multisite()) ? $blog_id : 1;
  5521.  
  5522.  
  5523.  
  5524. $global_cart = $this->get_cart_cookie(true);
  5525.  
  5526.  
  5527.  
  5528. if ($this->global_cart && count($global_cart = $this->get_cart_cookie(true)) >= $mp_gateway_active_plugins[0]->max_stores && !isset($global_cart[$blog_id])) {
  5529.  
  5530. $this->cart_checkout_error(sprintf(__("Sorry, currently it's not possible to checkout with items from more than %s stores.", 'mp'), $mp_gateway_active_plugins[0]->max_stores));
  5531.  
  5532. } else {
  5533.  
  5534. $global_cart[$blog_id] = $cart;
  5535.  
  5536. }
  5537.  
  5538.  
  5539.  
  5540. //update cache
  5541.  
  5542. $this->set_global_cart_cookie($global_cart);
  5543.  
  5544. }
  5545.  
  5546.  
  5547.  
  5548. //returns the full array of cart contents
  5549.  
  5550. function get_cart_contents($global = false) {
  5551.  
  5552. global $blog_id;
  5553.  
  5554. $blog_id = (is_multisite()) ? $blog_id : 1;
  5555.  
  5556. $current_blog_id = $blog_id;
  5557.  
  5558.  
  5559.  
  5560. //check cache
  5561.  
  5562. if ($this->cart_cache) {
  5563.  
  5564. if ($global) {
  5565.  
  5566. return $this->cart_cache;
  5567.  
  5568. } else {
  5569.  
  5570. if (isset($this->cart_cache[$blog_id])) {
  5571.  
  5572. return $this->cart_cache[$blog_id];
  5573.  
  5574. } else {
  5575.  
  5576. return array();
  5577.  
  5578. }
  5579.  
  5580. }
  5581.  
  5582. }
  5583.  
  5584.  
  5585.  
  5586. $global_cart = $this->get_cart_cookie(true);
  5587.  
  5588. if (!is_array($global_cart))
  5589.  
  5590. return array();
  5591.  
  5592.  
  5593.  
  5594. $full_cart = array();
  5595.  
  5596. foreach ($global_cart as $bid => $cart) {
  5597.  
  5598.  
  5599.  
  5600. if (is_multisite())
  5601.  
  5602. switch_to_blog($bid);
  5603.  
  5604.  
  5605.  
  5606. $full_cart[$bid] = array();
  5607.  
  5608. foreach ($cart as $product_id => $variations) {
  5609.  
  5610. $product = get_post($product_id);
  5611.  
  5612.  
  5613.  
  5614. if ( empty($product) ) {
  5615.  
  5616. continue;
  5617.  
  5618. }
  5619.  
  5620.  
  5621.  
  5622. $full_cart[$bid][$product_id] = array();
  5623.  
  5624. foreach ($variations as $variation => $quantity) {
  5625.  
  5626. //check stock
  5627.  
  5628. if (get_post_meta($product_id, 'mp_track_inventory', true)) {
  5629.  
  5630. $stock = maybe_unserialize(get_post_meta($product_id, 'mp_inventory', true));
  5631.  
  5632. if (!is_array($stock))
  5633.  
  5634. $stock[0] = $stock;
  5635.  
  5636. if ($stock[$variation] < $quantity) {
  5637.  
  5638. $this->cart_checkout_error( sprintf(__("Sorry, we don't have enough of %1$s in stock. Your cart quantity has been changed to %2$s.", 'mp'), $product->post_title, number_format_i18n($stock[$variation])) );
  5639.  
  5640. $quantity = $stock[$variation];
  5641.  
  5642. }
  5643.  
  5644. }
  5645.  
  5646.  
  5647.  
  5648. //check limit if tracking on or downloadable
  5649.  
  5650. if (get_post_meta($product_id, 'mp_track_limit', true) || ( $this->get_setting('download_order_limit', 1) && $file = get_post_meta($product_id, 'mp_file', true) ) ) {
  5651.  
  5652.  
  5653.  
  5654. //if tracking is on and (no file or file with limit override off)
  5655.  
  5656. if (get_post_meta($product_id, 'mp_track_limit', true) && ( empty($file) || !$this->get_setting('download_order_limit', 1) ) ) {
  5657.  
  5658. $limit = maybe_unserialize(get_post_meta($product_id, 'mp_limit', true));
  5659.  
  5660. } else {
  5661.  
  5662. $limit = array($variation => 1);
  5663.  
  5664. }
  5665.  
  5666.  
  5667.  
  5668. if ($limit[$variation] && $limit[$variation] < $quantity) {
  5669.  
  5670. $this->cart_checkout_error( sprintf(__('Sorry, there is a per order limit of %1$s for "%2$s". Your cart quantity has been changed to %3$s.', 'mp'), number_format_i18n($limit[$variation]), $product->post_title, number_format_i18n($limit[$variation])) );
  5671.  
  5672. $quantity = $limit[$variation];
  5673.  
  5674. }
  5675.  
  5676. }
  5677.  
  5678.  
  5679.  
  5680. $skus = maybe_unserialize(get_post_meta($product_id, 'mp_sku', true));
  5681.  
  5682. if (!is_array($skus))
  5683.  
  5684. $skus[0] = $skus;
  5685.  
  5686. $var_names = maybe_unserialize(get_post_meta($product_id, 'mp_var_name', true));
  5687.  
  5688. if (is_array($var_names) && count($var_names) > 1)
  5689.  
  5690. $name = $product->post_title . ': ' . $var_names[$variation];
  5691.  
  5692. else
  5693.  
  5694. $name = $product->post_title;
  5695.  
  5696.  
  5697.  
  5698. //get if downloadable
  5699.  
  5700. if ( $download_url = get_post_meta($product_id, 'mp_file', true) )
  5701.  
  5702. $download = array('url' => $download_url, 'downloaded' => 0);
  5703.  
  5704. else
  5705.  
  5706. $download = false;
  5707.  
  5708.  
  5709.  
  5710. $full_cart[$bid][$product_id][$variation] = array('SKU' => $skus[$variation], 'name' => $name, 'url' => get_permalink($product_id), 'price' => $this->product_price($product_id, $variation), 'quantity' => $quantity, 'download' => $download);
  5711.  
  5712. }
  5713.  
  5714. }
  5715.  
  5716. }
  5717.  
  5718.  
  5719.  
  5720. if (is_multisite())
  5721.  
  5722. switch_to_blog($current_blog_id);
  5723.  
  5724.  
  5725.  
  5726. //save to cache
  5727.  
  5728. $this->cart_cache = $full_cart;
  5729.  
  5730.  
  5731.  
  5732. if ($global) {
  5733.  
  5734. return $full_cart;
  5735.  
  5736. } else {
  5737.  
  5738. if (isset($full_cart[$blog_id])) {
  5739.  
  5740. return $full_cart[$blog_id];
  5741.  
  5742. } else {
  5743.  
  5744. return array();
  5745.  
  5746. }
  5747.  
  5748. }
  5749.  
  5750. }
  5751.  
  5752.  
  5753.  
  5754. //receives a post and updates cookie variables for cart
  5755.  
  5756. function update_cart() {
  5757.  
  5758. global $blog_id, $mp_gateway_active_plugins;
  5759.  
  5760. $blog_id = (is_multisite()) ? $blog_id : 1;
  5761.  
  5762. $current_blog_id = $blog_id;
  5763.  
  5764.  
  5765.  
  5766. $cart = $this->get_cart_cookie();
  5767.  
  5768.  
  5769.  
  5770. if (isset($_POST['empty_cart'])) { //empty cart contents
  5771.  
  5772.  
  5773.  
  5774. //clear all blog products only if global checkout enabled
  5775.  
  5776. if ($this->global_cart)
  5777.  
  5778. $this->set_global_cart_cookie(array());
  5779.  
  5780. else
  5781.  
  5782. $this->set_cart_cookie(array());
  5783.  
  5784.  
  5785.  
  5786. if (defined('DOING_AJAX') && DOING_AJAX) {
  5787.  
  5788. ?>
  5789.  
  5790. <div class="mp_cart_empty">
  5791.  
  5792. <?php _e('There are no items in your cart.', 'mp') ?>
  5793.  
  5794. </div>
  5795.  
  5796. <div id="mp_cart_actions_widget">
  5797.  
  5798. <a class="mp_store_link" href="<?php mp_products_link(true, true); ?>"><?php _e('Browse Products &raquo;', 'mp') ?></a>
  5799.  
  5800. </div>
  5801.  
  5802. <?php
  5803.  
  5804. exit;
  5805.  
  5806. }
  5807.  
  5808.  
  5809.  
  5810. } else if (isset($_POST['product_id'])) { //add a product to cart
  5811.  
  5812.  
  5813.  
  5814. //if not valid product_id return
  5815.  
  5816. $product_id = apply_filters('mp_product_id_add_to_cart', intval($_POST['product_id']));
  5817.  
  5818. $product = get_post($product_id);
  5819.  
  5820. if (!$product || $product->post_type != 'product' || $product->post_status != 'publish')
  5821.  
  5822. return false;
  5823.  
  5824.  
  5825.  
  5826. //get quantity
  5827.  
  5828. $quantity = (isset($_POST['quantity'])) ? intval(abs($_POST['quantity'])) : 1;
  5829.  
  5830.  
  5831.  
  5832. //get variation
  5833.  
  5834. $variation = (isset($_POST['variation'])) ? intval(abs($_POST['variation'])) : 0;
  5835.  
  5836.  
  5837.  
  5838. //check max stores
  5839.  
  5840. if ($this->global_cart && count($global_cart = $this->get_cart_cookie(true)) >= $mp_gateway_active_plugins[0]->max_stores && !isset($global_cart[$blog_id])) {
  5841.  
  5842. if (defined('DOING_AJAX') && DOING_AJAX) {
  5843.  
  5844. echo 'error||' . sprintf(__("Sorry, currently it's not possible to checkout with items from more than %s stores.", 'mp'), $mp_gateway_active_plugins[0]->max_stores);
  5845.  
  5846. exit;
  5847.  
  5848. } else {
  5849.  
  5850. $this->cart_checkout_error(sprintf(__("Sorry, currently it's not possible to checkout with items from more than %s stores.", 'mp'), $mp_gateway_active_plugins[0]->max_stores));
  5851.  
  5852. return false;
  5853.  
  5854. }
  5855.  
  5856. }
  5857.  
  5858.  
  5859.  
  5860. //calculate new quantity
  5861.  
  5862. $new_quantity = $cart[$product_id][$variation] + $quantity;
  5863.  
  5864.  
  5865.  
  5866. //check stock
  5867.  
  5868. if (get_post_meta($product_id, 'mp_track_inventory', true)) {
  5869.  
  5870. $stock = maybe_unserialize(get_post_meta($product_id, 'mp_inventory', true));
  5871.  
  5872. if (!is_array($stock))
  5873.  
  5874. $stock[0] = $stock;
  5875.  
  5876. if ($stock[$variation] < $new_quantity) {
  5877.  
  5878. if (defined('DOING_AJAX') && DOING_AJAX) {
  5879.  
  5880. echo 'error||' . sprintf(__("Sorry, we don't have enough of this item in stock. (%s remaining)", 'mp'), number_format_i18n($stock[$variation]-$cart[$product_id][$variation]));
  5881.  
  5882. exit;
  5883.  
  5884. } else {
  5885.  
  5886. $this->cart_checkout_error( sprintf(__("Sorry, we don't have enough of this item in stock. (%s remaining)", 'mp'), number_format_i18n($stock[$variation]-$cart[$product_id][$variation])) );
  5887.  
  5888. return false;
  5889.  
  5890. }
  5891.  
  5892. }
  5893.  
  5894. //send ajax leftover stock
  5895.  
  5896. if (defined('DOING_AJAX') && DOING_AJAX) {
  5897.  
  5898. $return = array_sum($stock)-$new_quantity . '||';
  5899.  
  5900. }
  5901.  
  5902. } else {
  5903.  
  5904. //send ajax always stock if stock checking turned off
  5905.  
  5906. if (defined('DOING_AJAX') && DOING_AJAX) {
  5907.  
  5908. $return = 1 . '||';
  5909.  
  5910. }
  5911.  
  5912. }
  5913.  
  5914.  
  5915.  
  5916. //check limit if tracking on or downloadable
  5917.  
  5918. if (get_post_meta($product_id, 'mp_track_limit', true) || $file = get_post_meta($product_id, 'mp_file', true)) {
  5919.  
  5920. $limit = empty($file) ? maybe_unserialize(get_post_meta($product_id, 'mp_limit', true)) : array($variation => 1);
  5921.  
  5922. if ($limit[$variation] && $limit[$variation] < $new_quantity) {
  5923.  
  5924. if (defined('DOING_AJAX') && DOING_AJAX) {
  5925.  
  5926. echo 'error||' . sprintf(__('Sorry, there is a per order limit of %1$s for "%2$s".', 'mp'), number_format_i18n($limit[$variation]), $product->post_title);
  5927.  
  5928. exit;
  5929.  
  5930. } else {
  5931.  
  5932. $this->cart_checkout_error( sprintf(__('Sorry, there is a per order limit of %1$s for "%2$s".', 'mp'), number_format_i18n($limit[$variation]), $product->post_title) );
  5933.  
  5934. return false;
  5935.  
  5936. }
  5937.  
  5938. }
  5939.  
  5940. }
  5941.  
  5942.  
  5943.  
  5944. $cart[$product_id][$variation] = $new_quantity;
  5945.  
  5946.  
  5947.  
  5948. //save items to cookie
  5949.  
  5950. $this->set_cart_cookie($cart);
  5951.  
  5952.  
  5953.  
  5954. //if running via ajax return updated cart and die
  5955.  
  5956. if (defined('DOING_AJAX') && DOING_AJAX) {
  5957.  
  5958. $return .= mp_show_cart('widget', false, false);
  5959.  
  5960. echo $return;
  5961.  
  5962. exit;
  5963.  
  5964. }
  5965.  
  5966. } else if (isset($_POST['update_cart_submit'])) { //update cart contents
  5967.  
  5968. $global_cart = $this->get_cart_cookie(true);
  5969.  
  5970.  
  5971.  
  5972.  
  5973.  
  5974. //process quantity updates
  5975.  
  5976. if (is_array($_POST['quant'])) {
  5977.  
  5978. foreach ($_POST['quant'] as $pbid => $quant) {
  5979.  
  5980. list($bid, $product_id, $variation) = split(':', $pbid);
  5981.  
  5982.  
  5983.  
  5984. if (is_multisite())
  5985.  
  5986. switch_to_blog($bid);
  5987.  
  5988.  
  5989.  
  5990. $quant = intval(abs($quant));
  5991.  
  5992.  
  5993.  
  5994. if ($quant) {
  5995.  
  5996. //check stock
  5997.  
  5998. if (get_post_meta($product_id, 'mp_track_inventory', true)) {
  5999.  
  6000. $stock = maybe_unserialize(get_post_meta($product_id, 'mp_inventory', true));
  6001.  
  6002. if (!is_array($stock))
  6003.  
  6004. $stock[0] = $stock;
  6005.  
  6006. if ($stock[$variation] < $quant) {
  6007.  
  6008. $left = (($stock[$variation]-intval($global_cart[$bid][$product_id][$variation])) < 0) ? 0 : ($stock[$variation]-intval($global_cart[$bid][$product_id][$variation]));
  6009.  
  6010. $this->cart_checkout_error( sprintf(__('Sorry, there is not enough stock for "%s". (%s remaining)', 'mp'), get_the_title($product_id), number_format_i18n($left)) );
  6011.  
  6012. continue;
  6013.  
  6014. }
  6015.  
  6016. }
  6017.  
  6018. //check limit if tracking on or downloadable
  6019.  
  6020. if (get_post_meta($product_id, 'mp_track_limit', true) || $file = get_post_meta($product_id, 'mp_file', true)) {
  6021.  
  6022. $limit = empty($file) ? maybe_unserialize(get_post_meta($product_id, 'mp_limit', true)) : array($variation => 1);
  6023.  
  6024. if ($limit[$variation] && $limit[$variation] < $quant) {
  6025.  
  6026. $this->cart_checkout_error( sprintf(__('Sorry, there is a per order limit of %1$s for "%2$s".', 'mp'), number_format_i18n($limit[$variation]), get_the_title($product_id)) );
  6027.  
  6028. continue;
  6029.  
  6030. }
  6031.  
  6032. }
  6033.  
  6034.  
  6035.  
  6036. $global_cart[$bid][$product_id][$variation] = $quant;
  6037.  
  6038. } else {
  6039.  
  6040. unset($global_cart[$bid][$product_id][$variation]);
  6041.  
  6042. }
  6043.  
  6044. }
  6045.  
  6046.  
  6047.  
  6048. if (is_multisite())
  6049.  
  6050. switch_to_blog($current_blog_id);
  6051.  
  6052. }
  6053.  
  6054.  
  6055.  
  6056. //remove items
  6057.  
  6058. if (isset($_POST['remove']) && is_array($_POST['remove'])) {
  6059.  
  6060. foreach ($_POST['remove'] as $pbid) {
  6061.  
  6062. list($bid, $product_id, $variation) = split(':', $pbid);
  6063.  
  6064. unset($global_cart[$bid][$product_id][$variation]);
  6065.  
  6066. }
  6067.  
  6068.  
  6069.  
  6070. $this->cart_update_message( __('Item(s) Removed', 'mp') );
  6071.  
  6072. }
  6073.  
  6074.  
  6075.  
  6076. //check for empty blogid carts and unset them to avoid errors on global cart
  6077.  
  6078. foreach ($global_cart as $bid => $data) {
  6079.  
  6080.  
  6081.  
  6082. foreach ($data as $product_id => $product) {
  6083.  
  6084. if (!count($product))
  6085.  
  6086. unset($global_cart[$bid][$product_id]);
  6087.  
  6088. }
  6089.  
  6090.  
  6091.  
  6092. if (!count($global_cart[$bid]))
  6093.  
  6094. unset($global_cart[$bid]);
  6095.  
  6096. }
  6097.  
  6098.  
  6099.  
  6100. //save items to cookie
  6101.  
  6102. $this->set_global_cart_cookie($global_cart);
  6103.  
  6104.  
  6105.  
  6106. //add coupon code
  6107.  
  6108. if (!empty($_POST['coupon_code'])) {
  6109.  
  6110.  
  6111.  
  6112.  
  6113.  
  6114. if ($this->check_coupon($_POST['coupon_code'])) {
  6115.  
  6116.  
  6117.  
  6118.  
  6119.  
  6120. //get coupon code
  6121.  
  6122. //set a flag so all other coupons will be processed
  6123.  
  6124. $can_apply = $this->coupon_applicable( $_POST['coupon_code'], $product_id );
  6125.  
  6126. //check the flag before applying the coupon
  6127.  
  6128. if( $can_apply ) {
  6129.  
  6130.  
  6131.  
  6132. if (is_multisite()) {
  6133.  
  6134. global $blog_id;
  6135.  
  6136. $_SESSION['mp_cart_coupon_' . $blog_id] = $_POST['coupon_code'];
  6137.  
  6138. } else {
  6139.  
  6140. $_SESSION['mp_cart_coupon'] = $_POST['coupon_code'];
  6141.  
  6142. }
  6143.  
  6144.  
  6145.  
  6146. $this->cart_update_message( __('Coupon Successfully Applied', 'mp') );
  6147.  
  6148. }else{
  6149.  
  6150. $this->cart_checkout_error( __('Coupon Was Not Applied', 'mp') );
  6151.  
  6152. }
  6153.  
  6154. } else {
  6155.  
  6156. $this->cart_checkout_error( __('Invalid Coupon Code', 'mp') );
  6157.  
  6158. }
  6159.  
  6160. }
  6161.  
  6162.  
  6163.  
  6164. } else if (isset($_GET['remove_coupon'])) {
  6165.  
  6166.  
  6167.  
  6168. //remove coupon code
  6169.  
  6170. if (is_multisite()) {
  6171.  
  6172. global $blog_id;
  6173.  
  6174. unset($_SESSION['mp_cart_coupon_' . $blog_id]);
  6175.  
  6176. } else {
  6177.  
  6178. unset($_SESSION['mp_cart_coupon']);
  6179.  
  6180. }
  6181.  
  6182. $this->cart_update_message( __('Coupon Removed', 'mp') );
  6183.  
  6184.  
  6185.  
  6186. } else if (isset($_POST['mp_shipping_submit'])) { //save shipping info
  6187.  
  6188.  
  6189.  
  6190. //check checkout info
  6191.  
  6192. if (!is_email($_POST['email']))
  6193.  
  6194. $this->cart_checkout_error( __('Please enter a valid Email Address.', 'mp'), 'email');
  6195.  
  6196.  
  6197.  
  6198. //only require these fields if not a download only cart
  6199.  
  6200. if ((!$this->download_only_cart($this->get_cart_contents()) || $this->global_cart || $this->get_setting('tax->downloadable_address')) && $this->get_setting('shipping->method') != 'none') {
  6201.  
  6202.  
  6203.  
  6204. if (empty($_POST['name']))
  6205.  
  6206. $this->cart_checkout_error( __('Please enter your Full Name.', 'mp'), 'name');
  6207.  
  6208.  
  6209.  
  6210. if (empty($_POST['address1']))
  6211.  
  6212. $this->cart_checkout_error( __('Please enter your Street Address.', 'mp'), 'address1');
  6213.  
  6214.  
  6215.  
  6216. if (empty($_POST['city']))
  6217.  
  6218. $this->cart_checkout_error( __('Please enter your City.', 'mp'), 'city');
  6219.  
  6220.  
  6221.  
  6222. if (($_POST['country'] == 'US' || $_POST['country'] == 'CA') && empty($_POST['state']))
  6223.  
  6224. $this->cart_checkout_error( __('Please enter your State/Province/Region.', 'mp'), 'state');
  6225.  
  6226.  
  6227.  
  6228. if ($_POST['country'] == 'US' && !array_key_exists(strtoupper($_POST['state']), $this->usa_states))
  6229.  
  6230. $this->cart_checkout_error( __('Please enter a valid two-letter State abbreviation.', 'mp'), 'state');
  6231.  
  6232. else if ($_POST['country'] == 'CA' && !array_key_exists(strtoupper($_POST['state']), $this->canadian_provinces))
  6233.  
  6234. $this->cart_checkout_error( __('Please enter a valid two-letter Canadian Province abbreviation.', 'mp'), 'state');
  6235.  
  6236. else
  6237.  
  6238. $_POST['state'] = strtoupper($_POST['state']);
  6239.  
  6240.  
  6241.  
  6242. if (empty($_POST['zip']) && $_POST['country'] != 'IE') //no postal code in Ireland
  6243.  
  6244. $this->cart_checkout_error( __('Please enter your Zip/Postal Code.', 'mp'), 'zip');
  6245.  
  6246.  
  6247.  
  6248. if (empty($_POST['country']) || strlen($_POST['country']) != 2)
  6249.  
  6250. $this->cart_checkout_error( __('Please enter your Country.', 'mp'), 'country');
  6251.  
  6252.  
  6253.  
  6254. if ($_POST['no_shipping_options'] == '1') {
  6255.  
  6256. $this->cart_checkout_error( __('No valid shipping options found. Please check your address carefully.', 'mp' ), 'no_shipping_options');
  6257.  
  6258. }
  6259.  
  6260. }
  6261.  
  6262.  
  6263.  
  6264. // Process Personalization
  6265.  
  6266. if (isset($_POST['mp_custom_fields']) && count($_POST['mp_custom_fields'])) {
  6267.  
  6268. foreach($_POST['mp_custom_fields'] as $cf_key => $cf_items) {
  6269.  
  6270.  
  6271.  
  6272. list($bid, $product_id, $variation) = split(':', $cf_key);
  6273.  
  6274.  
  6275.  
  6276. if (!isset($product_id)) continue;
  6277.  
  6278. if (!isset($variation)) continue;
  6279.  
  6280.  
  6281.  
  6282. $mp_has_custom_field = get_post_meta(intval($product_id), 'mp_has_custom_field', true);
  6283.  
  6284.  
  6285.  
  6286. if (isset($mp_has_custom_field) && isset($mp_has_custom_field[intval($variation)]) && $mp_has_custom_field[intval($variation)]) {
  6287.  
  6288. $mp_custom_field_required = get_post_meta(intval($product_id), 'mp_custom_field_required', true);
  6289.  
  6290.  
  6291.  
  6292. if (isset($mp_custom_field_required) && isset($mp_custom_field_required[intval($variation)]) && $mp_custom_field_required[intval($variation)]) {
  6293.  
  6294.  
  6295.  
  6296. foreach($cf_items as $idx => $cf_item) {
  6297.  
  6298. if (empty($cf_item)) {
  6299.  
  6300. $this->cart_checkout_error( __('Required product extra information.', 'mp' ), 'custom_fields_'. $product_id .'_'. $variation);
  6301.  
  6302. break;
  6303.  
  6304. } else {
  6305.  
  6306. $cf_items[$idx] = trim(strip_tags(stripslashes($cf_item)));
  6307.  
  6308. }
  6309.  
  6310. }
  6311.  
  6312. $_POST['mp_custom_fields'][$cf_key] = $cf_items;
  6313.  
  6314. }
  6315.  
  6316. }
  6317.  
  6318. }
  6319.  
  6320. }
  6321.  
  6322.  
  6323.  
  6324. //save to session
  6325.  
  6326. global $current_user;
  6327.  
  6328. $meta = get_user_meta($current_user->ID, 'mp_shipping_info', true);
  6329.  
  6330. $_SESSION['mp_shipping_info']['email'] = isset($_POST['email']) ? trim(stripslashes($_POST['email'])) : (isset($meta['email']) ? $meta['email']: $current_user->user_email);
  6331.  
  6332. $_SESSION['mp_shipping_info']['name'] = isset($_POST['name']) ? trim(stripslashes($_POST['name'])) : (isset($meta['name']) ? $meta['name'] : $current_user->user_firstname . ' ' . $current_user->user_lastname);
  6333.  
  6334. $_SESSION['mp_shipping_info']['address1'] = isset($_POST['address1']) ? trim(stripslashes($_POST['address1'])) : $meta['address1'];
  6335.  
  6336. $_SESSION['mp_shipping_info']['address2'] = isset($_POST['address2']) ? trim(stripslashes($_POST['address2'])) : $meta['address2'];
  6337.  
  6338. $_SESSION['mp_shipping_info']['city'] = isset($_POST['city']) ? trim(stripslashes($_POST['city'])) : $meta['city'];
  6339.  
  6340. $_SESSION['mp_shipping_info']['state'] = isset($_POST['state']) ? trim(stripslashes($_POST['state'])) : $meta['state'];
  6341.  
  6342. $_SESSION['mp_shipping_info']['zip'] = isset($_POST['zip']) ? trim(stripslashes($_POST['zip'])) : $meta['zip'];
  6343.  
  6344. $_SESSION['mp_shipping_info']['country'] = isset($_POST['country']) ? trim($_POST['country']) : $meta['country'];
  6345.  
  6346. $_SESSION['mp_shipping_info']['phone'] = isset($_POST['phone']) ? preg_replace('/[^0-9-\(\) ]/', '', trim($_POST['phone'])) : $meta['phone'];
  6347.  
  6348. if (isset($_POST['special_instructions']))
  6349.  
  6350. $_SESSION['mp_shipping_info']['special_instructions'] = trim(stripslashes($_POST['special_instructions']));
  6351.  
  6352.  
  6353.  
  6354. //Handle and store Product Custom field data
  6355.  
  6356. if (isset($_POST['mp_custom_fields']))
  6357.  
  6358. $_SESSION['mp_shipping_info']['mp_custom_fields'] = $_POST['mp_custom_fields'];
  6359.  
  6360.  
  6361.  
  6362. //for checkout plugins
  6363.  
  6364. do_action( 'mp_shipping_process' );
  6365.  
  6366.  
  6367.  
  6368. //save to user meta
  6369.  
  6370. if ($current_user->ID)
  6371.  
  6372. update_user_meta($current_user->ID, 'mp_shipping_info', $_SESSION['mp_shipping_info']);
  6373.  
  6374.  
  6375.  
  6376. //if no errors send to next checkout step
  6377.  
  6378. if ($this->checkout_error == false) {
  6379.  
  6380.  
  6381.  
  6382. //check for $0 checkout to skip gateways
  6383.  
  6384.  
  6385.  
  6386. //loop through cart items
  6387.  
  6388. $global_cart = $this->get_cart_contents(true);
  6389.  
  6390. if (!$this->global_cart) //get subset if needed
  6391.  
  6392. $selected_cart[$blog_id] = $global_cart[$blog_id];
  6393.  
  6394. else
  6395.  
  6396. $selected_cart = $global_cart;
  6397.  
  6398.  
  6399.  
  6400. $totals = array();
  6401.  
  6402. $shipping_prices = array();
  6403.  
  6404. $tax_prices = array();
  6405.  
  6406. foreach ($selected_cart as $bid => $cart) {
  6407.  
  6408.  
  6409.  
  6410. if (is_multisite())
  6411.  
  6412. switch_to_blog($bid);
  6413.  
  6414.  
  6415.  
  6416. foreach ($cart as $product_id => $variations) {
  6417.  
  6418. foreach ($variations as $data) {
  6419.  
  6420. $totals[] = $data['price'] * $data['quantity'];
  6421.  
  6422. }
  6423.  
  6424. }
  6425.  
  6426. if ( ($shipping_price = $this->shipping_price()) !== false )
  6427.  
  6428. $shipping_prices[] = $shipping_price;
  6429.  
  6430.  
  6431.  
  6432. if ( ($tax_price = $this->tax_price()) !== false )
  6433.  
  6434. $tax_prices[] = $tax_price;
  6435.  
  6436. }
  6437.  
  6438.  
  6439.  
  6440. //go back to original blog
  6441.  
  6442. if (is_multisite())
  6443.  
  6444. switch_to_blog($current_blog_id);
  6445.  
  6446.  
  6447.  
  6448. $total = array_sum($totals);
  6449.  
  6450.  
  6451.  
  6452. //coupon line
  6453.  
  6454. if ( $coupon = $this->coupon_value($this->get_coupon_code(), $total) )
  6455.  
  6456. $total = $coupon['new_total'];
  6457.  
  6458.  
  6459.  
  6460. //shipping
  6461.  
  6462. if ( $shipping_price = array_sum($shipping_prices) )
  6463.  
  6464. $total = $total + $shipping_price;
  6465.  
  6466.  
  6467.  
  6468. //tax line
  6469.  
  6470. if ( $tax_price = array_sum($tax_prices) )
  6471.  
  6472. $total = $total + $tax_price;
  6473.  
  6474.  
  6475.  
  6476. if ($total > 0) {
  6477.  
  6478. $network_settings = get_site_option( 'mp_network_settings' );
  6479.  
  6480. //can we skip the payment form page?
  6481.  
  6482. if ( $this->global_cart ) {
  6483.  
  6484. $skip = apply_filters('mp_payment_form_skip_' . $network_settings['global_gateway'], false);
  6485.  
  6486. } else {
  6487.  
  6488. $skip = apply_filters('mp_payment_form_skip_' . $this->get_setting('gateways->allowed->0'), false);
  6489.  
  6490. }
  6491.  
  6492. if ( (!$this->global_cart && count($this->get_setting('gateways->allowed', array())) > 1) || !$skip ) {
  6493.  
  6494. wp_safe_redirect(mp_checkout_step_url('checkout'));
  6495.  
  6496. exit;
  6497.  
  6498. } else {
  6499.  
  6500. if ( $this->global_cart )
  6501.  
  6502. $_SESSION['mp_payment_method'] = $network_settings['global_gateway'];
  6503.  
  6504. else
  6505.  
  6506. $_SESSION['mp_payment_method'] = $this->get_setting('gateways->allowed->0');
  6507.  
  6508. do_action( 'mp_payment_submit_' . $_SESSION['mp_payment_method'], $this->get_cart_contents($this->global_cart), $_SESSION['mp_shipping_info'] );
  6509.  
  6510. //if no errors send to next checkout step
  6511.  
  6512. if ($this->checkout_error == false) {
  6513.  
  6514. wp_safe_redirect(mp_checkout_step_url('confirm-checkout'));
  6515.  
  6516. exit;
  6517.  
  6518. } else {
  6519.  
  6520. wp_safe_redirect(mp_checkout_step_url('checkout'));
  6521.  
  6522. exit;
  6523.  
  6524. }
  6525.  
  6526. }
  6527.  
  6528. } else { //empty price, create order already
  6529.  
  6530. //loop through and create orders
  6531.  
  6532. foreach ($selected_cart as $bid => $cart) {
  6533.  
  6534. $totals = array();
  6535.  
  6536. if (is_multisite())
  6537.  
  6538. switch_to_blog($bid);
  6539.  
  6540.  
  6541.  
  6542. foreach ($cart as $product_id => $variations) {
  6543.  
  6544. foreach ($variations as $data) {
  6545.  
  6546. $totals[] = $data['price'] * $data['quantity'];
  6547.  
  6548. }
  6549.  
  6550. }
  6551.  
  6552. $total = array_sum($totals);
  6553.  
  6554.  
  6555.  
  6556. //coupon line
  6557.  
  6558. if ( $coupon = $this->coupon_value($this->get_coupon_code(), $total) )
  6559.  
  6560. $total = $coupon['new_total'];
  6561.  
  6562.  
  6563.  
  6564. //shipping
  6565.  
  6566. if ( ($shipping_price = $this->shipping_price()) !== false )
  6567.  
  6568. $total = $total + $shipping_price;
  6569.  
  6570.  
  6571.  
  6572. //tax line
  6573.  
  6574. if ( ($tax_price = $this->tax_price()) !== false )
  6575.  
  6576. $total = $total + $tax_price;
  6577.  
  6578.  
  6579.  
  6580. //setup our payment details
  6581.  
  6582. $timestamp = time();
  6583.  
  6584. $payment_info['gateway_public_name'] = __('Manual Checkout', 'mp');
  6585.  
  6586. $payment_info['gateway_private_name'] = __('Manual Checkout', 'mp');
  6587.  
  6588. $payment_info['method'] = __('N/A - Free order', 'mp');
  6589.  
  6590. $payment_info['transaction_id'] = __('N/A', 'mp');
  6591.  
  6592. $payment_info['status'][$timestamp] = __('Completed', 'mp');
  6593.  
  6594. $payment_info['total'] = $total;
  6595.  
  6596. $payment_info['currency'] = $this->get_setting('currency');
  6597.  
  6598. $this->create_order(false, $cart, $_SESSION['mp_shipping_info'], $payment_info, true);
  6599.  
  6600. }
  6601.  
  6602.  
  6603.  
  6604. //go back to original blog
  6605.  
  6606. if (is_multisite())
  6607.  
  6608. switch_to_blog($current_blog_id);
  6609.  
  6610.  
  6611.  
  6612. $_SESSION['mp_payment_method'] = 'manual'; //so we don't get an error message on confirmation page
  6613.  
  6614.  
  6615.  
  6616. //redirect to final page
  6617.  
  6618. wp_safe_redirect(mp_checkout_step_url('confirmation'));
  6619.  
  6620. exit;
  6621.  
  6622. }
  6623.  
  6624. }
  6625.  
  6626.  
  6627.  
  6628. } else if (isset($_POST['mp_choose_gateway'])) { //check and save payment info
  6629.  
  6630. $_SESSION['mp_payment_method'] = $_POST['mp_choose_gateway'];
  6631.  
  6632. //processing script is only for selected gateway plugin
  6633.  
  6634. do_action( 'mp_payment_submit_' . $_SESSION['mp_payment_method'], $this->get_cart_contents($this->global_cart), $_SESSION['mp_shipping_info'] );
  6635.  
  6636. //if no errors send to next checkout step
  6637.  
  6638. if ($this->checkout_error == false) {
  6639.  
  6640. wp_safe_redirect(mp_checkout_step_url('confirm-checkout'));
  6641.  
  6642. exit;
  6643.  
  6644. }
  6645.  
  6646. } else if (isset($_POST['mp_payment_confirm'])) { //create order and process payment
  6647.  
  6648.  
  6649.  
  6650. //check to be sure each product is still available
  6651.  
  6652. $final_cart = $this->get_cart_contents( $this->global_cart );
  6653.  
  6654. if( is_array( $final_cart ) ) {
  6655.  
  6656. foreach($final_cart as $prod_id => $details) {
  6657.  
  6658. if (get_post_meta( $prod_id, 'mp_track_inventory', true ) ) {
  6659.  
  6660. $stock = maybe_unserialize(get_post_meta($prod_id, 'mp_inventory', true));
  6661.  
  6662. if( isset( $stock[0] ) && $stock[0] === 0 ) {
  6663.  
  6664. $this->cart_checkout_error( __("Sorry, one or more products are no longer available. Please review your cart.", 'mp') );
  6665.  
  6666. }
  6667.  
  6668. }
  6669.  
  6670. }
  6671.  
  6672. }
  6673.  
  6674.  
  6675.  
  6676. //wrap the action as it may trigger errors as well
  6677.  
  6678. if($this->checkout_error == false) {
  6679.  
  6680. do_action( 'mp_payment_confirm_' . $_SESSION['mp_payment_method'], $this->get_cart_contents($this->global_cart), $_SESSION['mp_shipping_info'] );
  6681.  
  6682. }
  6683.  
  6684.  
  6685.  
  6686. //if no errors send to next checkout step
  6687.  
  6688. if ($this->checkout_error == false) {
  6689.  
  6690. wp_safe_redirect(mp_checkout_step_url('confirmation'));
  6691.  
  6692. exit;
  6693.  
  6694. }
  6695.  
  6696. }
  6697.  
  6698. }
  6699.  
  6700.  
  6701.  
  6702. function cart_update_message($msg) {
  6703.  
  6704. $content = 'return "<div id=\"mp_cart_updated_msg\">' . $msg . '</div>";';
  6705.  
  6706. add_filter( 'mp_cart_updated_msg', create_function('', $content) );
  6707.  
  6708. }
  6709.  
  6710.  
  6711.  
  6712. function cart_checkout_error($msg, $context = 'checkout') {
  6713.  
  6714. $msg = str_replace('"', '\"', $msg); //prevent double quotes from causing errors.
  6715.  
  6716. $content = 'return "<div class=\"mp_checkout_error\">' . $msg . '</div>";';
  6717.  
  6718. add_action( 'mp_checkout_error_' . $context, create_function('', $content) );
  6719.  
  6720. $this->checkout_error = true;
  6721.  
  6722. }
  6723.  
  6724.  
  6725.  
  6726. //returns any coupon code saved in $_SESSION. Will only reliably work on checkout pages
  6727.  
  6728. function get_coupon_code() {
  6729.  
  6730. //get coupon code
  6731.  
  6732. if (is_multisite()) {
  6733.  
  6734. global $blog_id;
  6735.  
  6736. $coupon_code = isset($_SESSION['mp_cart_coupon_' . $blog_id]) ? $_SESSION['mp_cart_coupon_' . $blog_id] : false;
  6737.  
  6738. } else {
  6739.  
  6740. $coupon_code = isset($_SESSION['mp_cart_coupon']) ? $_SESSION['mp_cart_coupon'] : false;
  6741.  
  6742. }
  6743.  
  6744.  
  6745.  
  6746. return $coupon_code;
  6747.  
  6748. }
  6749.  
  6750.  
  6751.  
  6752. //checks a coupon code for validity. Return boolean
  6753.  
  6754. function check_coupon($code) {
  6755.  
  6756. $coupon_code = preg_replace('/[^A-Z0-9_-]/', '', strtoupper($code));
  6757.  
  6758.  
  6759.  
  6760. //empty code
  6761.  
  6762. if (!$coupon_code)
  6763.  
  6764. return false;
  6765.  
  6766.  
  6767.  
  6768. $coupons = get_option('mp_coupons');
  6769.  
  6770.  
  6771.  
  6772. //allow short circuit of coupon codes
  6773.  
  6774. $return = apply_filters('mp_coupon_check', null, $coupon_code, $coupons);
  6775.  
  6776. if ( !is_null($return) )
  6777.  
  6778. return $return;
  6779.  
  6780.  
  6781.  
  6782. //no record for code
  6783.  
  6784. if (!isset($coupons[$coupon_code]) || !is_array($coupons[$coupon_code]))
  6785.  
  6786. return false;
  6787.  
  6788.  
  6789.  
  6790. //start date not valid yet
  6791.  
  6792. if (time() < $coupons[$coupon_code]['start'])
  6793.  
  6794. return false;
  6795.  
  6796.  
  6797.  
  6798. //if end date and expired
  6799.  
  6800. if ($coupons[$coupon_code]['end'] && time() > $coupons[$coupon_code]['end'])
  6801.  
  6802. return false;
  6803.  
  6804.  
  6805.  
  6806. //check remaining uses
  6807.  
  6808. if ($coupons[$coupon_code]['uses'] && (intval($coupons[$coupon_code]['uses']) - intval(@$coupons[$coupon_code]['used'])) <= 0)
  6809.  
  6810. return false;
  6811.  
  6812.  
  6813.  
  6814. //everything passed so it's valid
  6815.  
  6816. return true;
  6817.  
  6818. }
  6819.  
  6820.  
  6821.  
  6822.  
  6823.  
  6824. /**
  6825.  
  6826. * Checks a coupon to see if it can be applied to a product.
  6827.  
  6828. *
  6829.  
  6830. * @param string The coupon code
  6831.  
  6832. * @param int The product ID we are checking
  6833.  
  6834. */
  6835.  
  6836. function coupon_applicable( $code, $product_id ) {
  6837.  
  6838. //
  6839.  
  6840. $can_apply = true;
  6841.  
  6842. $coupons = get_option('mp_coupons');
  6843.  
  6844.  
  6845.  
  6846. //check for the applies to setting
  6847.  
  6848. $applies_to = !empty( $coupons[ $code ]['applies_to'] ) ? $coupons[ $code ]['applies_to'] : false;
  6849.  
  6850. if( $applies_to ) {
  6851.  
  6852.  
  6853.  
  6854. $what = $applies_to['type']; // the type will be 'product', 'category'
  6855.  
  6856. $item_id = $applies_to['id']; // the is is either id post ID or the term ID depending on the above
  6857.  
  6858.  
  6859.  
  6860. switch( $what ) {
  6861.  
  6862. case 'product':
  6863.  
  6864. $can_apply = ( $product_id == $item_id ) ? true : false;
  6865.  
  6866. break;
  6867.  
  6868.  
  6869.  
  6870. case 'category':
  6871.  
  6872. $terms = get_the_terms( $product_id, 'product_category' );
  6873.  
  6874. if(!empty( $terms) && !is_wp_error( $terms ) ) {
  6875.  
  6876. $can_apply = false;
  6877.  
  6878. foreach( $terms as $term) {
  6879.  
  6880. if( $term->term_id == $item_id ) {
  6881.  
  6882. $can_apply = true;
  6883.  
  6884. }
  6885.  
  6886. }
  6887.  
  6888. }
  6889.  
  6890. break;
  6891.  
  6892.  
  6893.  
  6894. default:
  6895.  
  6896. }
  6897.  
  6898. }
  6899.  
  6900.  
  6901.  
  6902. return $can_apply;
  6903.  
  6904. }
  6905.  
  6906.  
  6907.  
  6908.  
  6909.  
  6910. //get coupon value. Returns array(discount, new_total) or false for invalid code
  6911.  
  6912. function coupon_value($code, $total) {
  6913.  
  6914. if ($this->check_coupon($code)) {
  6915.  
  6916. $coupons = get_option('mp_coupons');
  6917.  
  6918. $coupon_code = preg_replace('/[^A-Z0-9_-]/', '', strtoupper($code));
  6919.  
  6920. if ($coupons[$coupon_code]['discount_type'] == 'amt') {
  6921.  
  6922. $new_total = round($total - $coupons[$coupon_code]['discount'], 2);
  6923.  
  6924. $new_total = ($new_total < 0) ? 0.00 : $new_total;
  6925.  
  6926. $discount = '-' . $this->format_currency('', $coupons[$coupon_code]['discount']);
  6927.  
  6928. $return = array('discount' => $discount, 'new_total' => $new_total);
  6929.  
  6930. } else {
  6931.  
  6932. $new_total = round($total - ($total * ($coupons[$coupon_code]['discount'] * 0.01)), 2);
  6933.  
  6934. $new_total = ($new_total < 0) ? 0.00 : $new_total;
  6935.  
  6936. $discount = '-' . $coupons[$coupon_code]['discount'] . '%';
  6937.  
  6938. $return = array('discount' => $discount, 'new_total' => $new_total);
  6939.  
  6940. }
  6941.  
  6942. return apply_filters('mp_coupon_value', $return, $code, $total);
  6943.  
  6944. } else {
  6945.  
  6946. return false;
  6947.  
  6948. }
  6949.  
  6950. }
  6951.  
  6952.  
  6953.  
  6954. //record coupon use. Returns boolean successful
  6955.  
  6956. function use_coupon($code) {
  6957.  
  6958. if ($this->check_coupon($code)) {
  6959.  
  6960. $coupons = get_option('mp_coupons');
  6961.  
  6962. $coupon_code = preg_replace('/[^A-Z0-9_-]/', '', strtoupper($code));
  6963.  
  6964.  
  6965.  
  6966. //increment count
  6967.  
  6968. if ( isset($coupons[$coupon_code]) ) {
  6969.  
  6970. $coupons[$coupon_code]['used']++;
  6971.  
  6972. update_option('mp_coupons', $coupons);
  6973.  
  6974. }
  6975.  
  6976. do_action('mp_coupon_use', $coupon_code);
  6977.  
  6978.  
  6979.  
  6980. return true;
  6981.  
  6982. } else {
  6983.  
  6984. return false;
  6985.  
  6986. }
  6987.  
  6988. }
  6989.  
  6990.  
  6991.  
  6992. //returns a new unique order id.
  6993.  
  6994. function generate_order_id() {
  6995.  
  6996. global $wpdb;
  6997.  
  6998.  
  6999.  
  7000. $count = true;
  7001.  
  7002. while ($count) { //make sure it's unique
  7003.  
  7004. $order_id = substr(sha1(uniqid('')), rand(1, 24), 12);
  7005.  
  7006. $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->posts . " WHERE post_title = %s AND post_type = 'mp_order'", $order_id) );
  7007.  
  7008. }
  7009.  
  7010.  
  7011.  
  7012. $order_id = apply_filters( 'mp_order_id', $order_id ); //Very important to make sure order numbers are unique and not sequential if filtering
  7013.  
  7014.  
  7015.  
  7016. //save it to session
  7017.  
  7018. $_SESSION['mp_order'] = $order_id;
  7019.  
  7020.  
  7021.  
  7022. return $order_id;
  7023.  
  7024. }
  7025.  
  7026.  
  7027.  
  7028. //called on checkout to create a new order
  7029.  
  7030. function create_order($order_id, $cart, $shipping_info, $payment_info, $paid, $user_id = false, $shipping_total = false, $tax_total = false, $coupon_code = false) {
  7031.  
  7032. global $wpdb;
  7033.  
  7034.  
  7035.  
  7036. //order id can be null
  7037.  
  7038. if (empty($order_id))
  7039.  
  7040. $order_id = $this->generate_order_id();
  7041.  
  7042. else if ($this->get_order($order_id)) //don't continue if the order exists
  7043.  
  7044. return false;
  7045.  
  7046.  
  7047.  
  7048. //insert post type
  7049.  
  7050. $order = array();
  7051.  
  7052. $order['post_title'] = $order_id;
  7053.  
  7054. $order['post_name'] = $order_id;
  7055.  
  7056. $order['post_content'] = serialize($cart).serialize($shipping_info); //this is purely so you can search by cart contents
  7057.  
  7058. $order['post_status'] = ($paid) ? 'order_paid' : 'order_received';
  7059.  
  7060. $order['post_type'] = 'mp_order';
  7061.  
  7062. $post_id = wp_insert_post($order);
  7063.  
  7064.  
  7065.  
  7066. /* add post meta */
  7067.  
  7068.  
  7069.  
  7070. //filter tax included products in cart
  7071.  
  7072. $filtered_cart = $cart;
  7073.  
  7074. foreach ($cart as $product_id => $variations) {
  7075.  
  7076. foreach ($variations as $variation => $data) {
  7077.  
  7078. // store before tax price
  7079.  
  7080. // if tax_inclusive==true, before_tax_price() rounds to two decimal places
  7081.  
  7082. // the original price cannot be accurately calculated on the order tracking page with just the before_tax_price value
  7083.  
  7084. $filtered_cart[$product_id][$variation]['before_tax_price'] = $this->before_tax_price($data['price'], $product_id);
  7085.  
  7086. }
  7087.  
  7088. }
  7089.  
  7090.  
  7091.  
  7092. //cart info
  7093.  
  7094. add_post_meta($post_id, 'mp_cart_info', $filtered_cart, true);
  7095.  
  7096. //shipping info
  7097.  
  7098. add_post_meta($post_id, 'mp_shipping_info', $shipping_info, true);
  7099.  
  7100. //payment info
  7101.  
  7102. add_post_meta($post_id, 'mp_payment_info', $payment_info, true);
  7103.  
  7104.  
  7105.  
  7106. //loop through cart items
  7107.  
  7108. foreach ($cart as $product_id => $variations) {
  7109.  
  7110. foreach ($variations as $variation => $data) {
  7111.  
  7112. $items[] = $data['quantity'];
  7113.  
  7114.  
  7115.  
  7116. //adjust product stock quantities
  7117.  
  7118. if (get_post_meta($product_id, 'mp_track_inventory', true)) {
  7119.  
  7120. $stock = maybe_unserialize(get_post_meta($product_id, 'mp_inventory', true));
  7121.  
  7122. if (!is_array($stock))
  7123.  
  7124. $stock[0] = $stock;
  7125.  
  7126. $stock[$variation] = $stock[$variation] - $data['quantity'];
  7127.  
  7128. update_post_meta($product_id, 'mp_inventory', $stock);
  7129.  
  7130.  
  7131.  
  7132. //send low stock notification if needed
  7133.  
  7134. if ($stock[$variation] <= $this->get_setting('inventory_threshold')) {
  7135.  
  7136. $this->low_stock_notification($product_id, $variation, $stock[$variation]);
  7137.  
  7138. }
  7139.  
  7140. } //check stock
  7141.  
  7142.  
  7143.  
  7144. //update sales count
  7145.  
  7146. $count = get_post_meta($product_id, 'mp_sales_count', true);
  7147.  
  7148. $count = $count + $data['quantity'];
  7149.  
  7150. update_post_meta($product_id, 'mp_sales_count', $count);
  7151.  
  7152.  
  7153.  
  7154. //for plugins into product sales
  7155.  
  7156. do_action( 'mp_product_sale', $product_id, $variation, $data, $paid );
  7157.  
  7158. }
  7159.  
  7160.  
  7161.  
  7162. //set product to draft if completly out of stock
  7163.  
  7164. if (get_post_meta($product_id, 'mp_track_inventory', true)) {
  7165.  
  7166. $stock = maybe_unserialize(get_post_meta($product_id, 'mp_inventory', true));
  7167.  
  7168. if (!is_array($stock))
  7169.  
  7170. $stock[0] = $stock;
  7171.  
  7172.  
  7173.  
  7174. if ($this->get_setting('inventory_remove') && !array_sum($stock)) {
  7175.  
  7176. $post = get_post( $product_id );
  7177.  
  7178. $wpdb->update( $wpdb->posts, array( 'post_status' => 'draft' ), array( 'ID' => $post->ID ) );
  7179.  
  7180. clean_post_cache( $post->ID );
  7181.  
  7182. $old_status = $post->post_status;
  7183.  
  7184. $post->post_status = 'draft';
  7185.  
  7186. wp_transition_post_status( 'draft', $old_status, $post );
  7187.  
  7188.  
  7189.  
  7190. do_action( 'edit_post', $post->ID, $post );
  7191.  
  7192. do_action( 'save_post', $post->ID, $post );
  7193.  
  7194. do_action( 'wp_insert_post', $post->ID, $post );
  7195.  
  7196. }
  7197.  
  7198. }
  7199.  
  7200. }
  7201.  
  7202. $item_count = array_sum($items);
  7203.  
  7204.  
  7205.  
  7206. //coupon info
  7207.  
  7208. $code = $coupon_code ? $coupon_code : $this->get_coupon_code();
  7209.  
  7210. if ( $coupon = $this->coupon_value($code, 9999999999) ) {
  7211.  
  7212. add_post_meta($post_id, 'mp_discount_info', array('code' => $code, 'discount' => $coupon['discount']), true);
  7213.  
  7214.  
  7215.  
  7216. //mark coupon as used
  7217.  
  7218. $this->use_coupon($code);
  7219.  
  7220. }
  7221.  
  7222.  
  7223.  
  7224. //payment info
  7225.  
  7226. add_post_meta($post_id, 'mp_order_total', $payment_info['total'], true);
  7227.  
  7228.  
  7229.  
  7230. $mp_shipping_total = ($shipping_total ? $shipping_total : $this->shipping_price(false, $cart));
  7231.  
  7232. add_post_meta($post_id, 'mp_shipping_total', $mp_shipping_total, true);
  7233.  
  7234. add_post_meta($post_id, 'mp_shipping_with_tax', $this->shipping_tax_price($mp_shipping_total), true);
  7235.  
  7236.  
  7237.  
  7238. add_post_meta($post_id, 'mp_tax_total', ($tax_total ? $tax_total : $this->tax_price(false, $cart)), true);
  7239.  
  7240. add_post_meta($post_id, 'mp_order_items', $item_count, true);
  7241.  
  7242.  
  7243.  
  7244. add_post_meta($post_id, 'mp_tax_inclusive', $this->get_setting('tax->tax_inclusive'), true);
  7245.  
  7246. add_post_meta($post_id, 'mp_tax_shipping', $this->get_setting('tax->tax_shipping'), true);
  7247.  
  7248.  
  7249.  
  7250. $timestamp = time();
  7251.  
  7252. add_post_meta($post_id, 'mp_received_time', $timestamp, true);
  7253.  
  7254.  
  7255.  
  7256. //set paid time if we already have a confirmed payment
  7257.  
  7258. if ($paid) {
  7259.  
  7260. add_post_meta($post_id, 'mp_paid_time', $timestamp, true);
  7261.  
  7262. do_action( 'mp_order_paid', $this->get_order($order_id) );
  7263.  
  7264. }
  7265.  
  7266.  
  7267.  
  7268. //empty cart cookie
  7269.  
  7270. $this->set_cart_cookie(array());
  7271.  
  7272.  
  7273.  
  7274. //clear coupon code
  7275.  
  7276. if (is_multisite()) {
  7277.  
  7278. global $blog_id;
  7279.  
  7280. unset($_SESSION['mp_cart_coupon_' . $blog_id]);
  7281.  
  7282. } else {
  7283.  
  7284. unset($_SESSION['mp_cart_coupon']);
  7285.  
  7286. }
  7287.  
  7288.  
  7289.  
  7290. //save order history
  7291.  
  7292. if (!$user_id)
  7293.  
  7294. $user_id = get_current_user_id();
  7295.  
  7296.  
  7297.  
  7298. if ($user_id) { //save to user_meta if logged in
  7299.  
  7300.  
  7301.  
  7302. if (is_multisite()) {
  7303.  
  7304. global $blog_id;
  7305.  
  7306. $meta_id = 'mp_order_history_' . $blog_id;
  7307.  
  7308. } else {
  7309.  
  7310. $meta_id = 'mp_order_history';
  7311.  
  7312. }
  7313.  
  7314.  
  7315.  
  7316. $orders = get_user_meta($user_id, $meta_id, true);
  7317.  
  7318. $timestamp = time();
  7319.  
  7320. $orders[$timestamp] = array('id' => $order_id, 'total' => $payment_info['total']);
  7321.  
  7322. update_user_meta($user_id, $meta_id, $orders);
  7323.  
  7324.  
  7325.  
  7326. } else { //save to cookie instead
  7327.  
  7328.  
  7329.  
  7330. if (is_multisite()) {
  7331.  
  7332. global $blog_id;
  7333.  
  7334. $cookie_id = 'mp_order_history_' . $blog_id . '_' . COOKIEHASH;
  7335.  
  7336. } else {
  7337.  
  7338. $cookie_id = 'mp_order_history_' . COOKIEHASH;
  7339.  
  7340. }
  7341.  
  7342.  
  7343.  
  7344. if (isset($_COOKIE[$cookie_id]))
  7345.  
  7346. $orders = unserialize($_COOKIE[$cookie_id]);
  7347.  
  7348.  
  7349.  
  7350. $timestamp = time();
  7351.  
  7352. $orders[$timestamp] = array('id' => $order_id, 'total' => $payment_info['total']);
  7353.  
  7354.  
  7355.  
  7356. //set cookie
  7357.  
  7358. $expire = time() + 31536000; //1 year expire
  7359.  
  7360. setcookie($cookie_id, serialize($orders), $expire, COOKIEPATH, COOKIEDOMAIN);
  7361.  
  7362. }
  7363.  
  7364.  
  7365.  
  7366. //hook for new orders
  7367.  
  7368. do_action( 'mp_new_order', $this->get_order($order_id) );
  7369.  
  7370.  
  7371.  
  7372. //send new order email
  7373.  
  7374. $this->order_notification($order_id);
  7375.  
  7376.  
  7377.  
  7378. //if paid and the cart is only digital products mark it shipped
  7379.  
  7380. if ($paid && $this->download_only_cart($cart)) {
  7381.  
  7382. $this->skip_shipping_notice = true;
  7383.  
  7384. $this->update_order_status($order_id, 'shipped');
  7385.  
  7386. }
  7387.  
  7388.  
  7389.  
  7390. return $order_id;
  7391.  
  7392. }
  7393.  
  7394.  
  7395.  
  7396. //returns the full order details as an object
  7397.  
  7398. function get_order($order_id) {
  7399.  
  7400. $id = (is_int($order_id)) ? $order_id : $this->order_to_post_id($order_id);
  7401.  
  7402.  
  7403.  
  7404. if (empty($id))
  7405.  
  7406. return false;
  7407.  
  7408.  
  7409.  
  7410.  
  7411.  
  7412.  
  7413.  
  7414. $order = get_post($id);
  7415.  
  7416. if (!$order)
  7417.  
  7418. return false;
  7419.  
  7420.  
  7421.  
  7422. $meta = get_post_custom($id);
  7423.  
  7424.  
  7425.  
  7426. //unserialize a and add to object
  7427.  
  7428. foreach ($meta as $key => $val)
  7429.  
  7430. $order->$key = maybe_unserialize($meta[$key][0]);
  7431.  
  7432.  
  7433.  
  7434. return $order;
  7435.  
  7436. }
  7437.  
  7438.  
  7439.  
  7440. //serves the 'order_paid' : 'order_received'
  7441.  
  7442. function export_orders_csv() {
  7443.  
  7444. global $wpdb;
  7445.  
  7446.  
  7447.  
  7448. //check permissions
  7449.  
  7450. $post_type_object = get_post_type_object('mp_order');
  7451.  
  7452. if ( !current_user_can($post_type_object->cap->edit_posts) )
  7453.  
  7454. wp_die(__('Cheatin&#8217; uh?'));
  7455.  
  7456.  
  7457.  
  7458. $query = "SELECT ID, post_title, post_date, post_status FROM {$wpdb->posts} WHERE post_type = 'mp_order'";
  7459.  
  7460.  
  7461.  
  7462. if (isset($_POST['order_status']) && $_POST['order_status'] != 'all')
  7463.  
  7464. $query .= $wpdb->prepare(' AND post_status = %s', $_POST['order_status']);
  7465.  
  7466.  
  7467.  
  7468. // If a month is specified in the querystring, load that month
  7469.  
  7470. if ( isset($_POST['m']) && $_POST['m'] > 0 ) {
  7471.  
  7472. $_POST['m'] = '' . preg_replace('|[^0-9]|', '', $_POST['m']);
  7473.  
  7474. $query .= " AND YEAR($wpdb->posts.post_date)=" . substr($_POST['m'], 0, 4);
  7475.  
  7476. if ( strlen($_POST['m']) > 5 )
  7477.  
  7478. $query .= " AND MONTH($wpdb->posts.post_date)=" . substr($_POST['m'], 4, 2);
  7479.  
  7480. if ( strlen($_POST['m']) > 7 )
  7481.  
  7482. $query .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($_POST['m'], 6, 2);
  7483.  
  7484. if ( strlen($_POST['m']) > 9 )
  7485.  
  7486. $query .= " AND HOUR($wpdb->posts.post_date)=" . substr($_POST['m'], 8, 2);
  7487.  
  7488. if ( strlen($_POST['m']) > 11 )
  7489.  
  7490. $query .= " AND MINUTE($wpdb->posts.post_date)=" . substr($_POST['m'], 10, 2);
  7491.  
  7492. if ( strlen($_POST['m']) > 13 )
  7493.  
  7494. $query .= " AND SECOND($wpdb->posts.post_date)=" . substr($_POST['m'], 12, 2);
  7495.  
  7496. }
  7497.  
  7498.  
  7499.  
  7500. $query .= " ORDER BY post_date DESC";
  7501.  
  7502.  
  7503.  
  7504. $orders = $wpdb->get_results($query);
  7505.  
  7506.  
  7507.  
  7508. // Keep up to 12MB in memory, if becomes bigger write to temp file
  7509.  
  7510. $file = fopen('php://temp/maxmemory:'. (12*1024*1024), 'r+');
  7511.  
  7512. fputcsv( $file, array('order_id', 'status', 'received_date', 'paid_date', 'shipped_date', 'tax', 'shipping', 'total', 'coupon_discount', 'coupon_code', 'item_count', 'items', 'email', 'name', 'address1', 'address2', 'city', 'state', 'zipcode', 'country', 'phone', 'shipping_method', 'shipping_method_option', 'special_instructions', 'gateway', 'gateway_method', 'payment_currency', 'transaction_id' ) );
  7513.  
  7514.  
  7515.  
  7516. //loop through orders and add rows
  7517.  
  7518. foreach ($orders as $order) {
  7519.  
  7520. $meta = get_post_custom($order->ID);
  7521.  
  7522.  
  7523.  
  7524. //unserialize a and add to object
  7525.  
  7526. foreach ($meta as $key => $val)
  7527.  
  7528. $order->$key = maybe_unserialize($meta[$key][0]);
  7529.  
  7530.  
  7531.  
  7532. $fields = array();
  7533.  
  7534. $fields['order_id'] = $order->post_title;
  7535.  
  7536. $fields['status'] = $order->post_status;
  7537.  
  7538. $fields['received_date'] = $order->post_date;
  7539.  
  7540. $fields['paid_date'] = isset($order->mp_paid_time) ? date('Y-m-d H:i:s', $order->mp_paid_time) : null;
  7541.  
  7542. $fields['shipped_date'] = isset($order->mp_shipped_time) ? date('Y-m-d H:i:s', $order->mp_paid_time) : null;
  7543.  
  7544. $fields['tax'] = $order->mp_tax_total;
  7545.  
  7546. $fields['shipping'] = $order->mp_shipping_total;
  7547.  
  7548. $fields['total'] = $order->mp_order_total;
  7549.  
  7550. $fields['coupon_discount'] = @$order->mp_discount_info['discount'];
  7551.  
  7552. $fields['coupon_code'] = @$order->mp_discount_info['code'];
  7553.  
  7554. $fields['item_count'] = $order->mp_order_items;
  7555.  
  7556. //items
  7557.  
  7558. if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) {
  7559.  
  7560. foreach ($order->mp_cart_info as $product_id => $variations) {
  7561.  
  7562. foreach ($variations as $variation => $data) {
  7563.  
  7564. if (!empty($fields['items']))
  7565.  
  7566. $fields['items'] .= "\r\n";
  7567.  
  7568. if (!empty($data['SKU']))
  7569.  
  7570. $fields['items'] .= '[' . $data['SKU'] . '] ';
  7571.  
  7572. $fields['items'] .= $data['name'] . ': ' . number_format_i18n($data['quantity']) . ' * ' . number_format_i18n($data['price'], 2) . ' ' . $order->mp_payment_info['currency'];
  7573.  
  7574. /*
  7575.  
  7576. $cf_key = $bid .':'. $product_id .':'. $variation;
  7577.  
  7578. if (isset($order->mp_shipping_info['mp_custom_fields'][$cf_key])) {
  7579.  
  7580. $cf_items = $order->mp_shipping_info['mp_custom_fields'][$cf_key];
  7581.  
  7582.  
  7583.  
  7584. $mp_custom_field_label = get_post_meta($product_id, 'mp_custom_field_label', true);
  7585.  
  7586. if (isset($mp_custom_field_label[$variation]))
  7587.  
  7588. $label_text = esc_attr($mp_custom_field_label[$variation]);
  7589.  
  7590. else
  7591.  
  7592. $label_text = __('Product Personalization', 'mp');
  7593.  
  7594.  
  7595.  
  7596. $fields['items'] .= "\r\n\t" . $label_text .": ";
  7597.  
  7598. foreach($cf_items as $idx => $cf_item) {
  7599.  
  7600. $item_cnt = intval($idx)+1;
  7601.  
  7602. $fields['items'] .= $cf_item;
  7603.  
  7604. }
  7605.  
  7606. }
  7607.  
  7608. */
  7609.  
  7610. }
  7611.  
  7612. }
  7613.  
  7614. } else {
  7615.  
  7616. $fields['items'] = 'N/A';
  7617.  
  7618. }
  7619.  
  7620.  
  7621.  
  7622. $fields['email'] = @$order->mp_shipping_info['email'];
  7623.  
  7624. $fields['name'] = @$order->mp_shipping_info['name'];
  7625.  
  7626. $fields['address1'] = @$order->mp_shipping_info['address1'];
  7627.  
  7628. $fields['address2'] = @$order->mp_shipping_info['address2'];
  7629.  
  7630. $fields['city'] = @$order->mp_shipping_info['city'];
  7631.  
  7632. $fields['state'] = @$order->mp_shipping_info['state'];
  7633.  
  7634. $fields['zipcode'] = @$order->mp_shipping_info['zip'];
  7635.  
  7636. $fields['country'] = @$order->mp_shipping_info['country'];
  7637.  
  7638. $fields['phone'] = @$order->mp_shipping_info['phone'];
  7639.  
  7640. $fields['shipping_method'] = @$order->mp_shipping_info['shipping_option'];
  7641.  
  7642. $fields['shipping_method_option'] = @$order->mp_shipping_info['shipping_sub_option'];
  7643.  
  7644. $fields['special_instructions'] = @$order->mp_shipping_info['special_instructions'];
  7645.  
  7646. $fields['gateway'] = @$order->mp_payment_info['gateway_private_name'];
  7647.  
  7648. $fields['gateway_method'] = @$order->mp_payment_info['method'];
  7649.  
  7650. $fields['payment_currency'] = @$order->mp_payment_info['currency'];
  7651.  
  7652. $fields['transaction_id'] = @$order->mp_payment_info['transaction_id'];
  7653.  
  7654.  
  7655.  
  7656. fputcsv( $file, $fields );
  7657.  
  7658. }
  7659.  
  7660.  
  7661.  
  7662. //create our filename
  7663.  
  7664. $filename = 'orders_export';
  7665.  
  7666. $filename .= isset($_POST['m']) ? '_' . $_POST['m'] : '';
  7667.  
  7668. $filename .= '_' . time() . '.csv';
  7669.  
  7670.  
  7671.  
  7672. //serve the file
  7673.  
  7674. rewind($file);
  7675.  
  7676. ob_end_clean(); //kills any buffers set by other plugins
  7677.  
  7678. header('Content-Description: File Transfer');
  7679.  
  7680. header('Content-Type: text/csv');
  7681.  
  7682. header('Content-Disposition: attachment; filename="'.$filename.'"');
  7683.  
  7684. header('Content-Transfer-Encoding: binary');
  7685.  
  7686. header('Expires: 0');
  7687.  
  7688. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  7689.  
  7690. header('Pragma: public');
  7691.  
  7692. $output = stream_get_contents($file);
  7693.  
  7694. $output = "\xEF\xBB\xBF" . $output; // UTF-8 BOM
  7695.  
  7696. header('Content-Length: ' . strlen($output));
  7697.  
  7698. fclose($file);
  7699.  
  7700. die($output);
  7701.  
  7702. }
  7703.  
  7704.  
  7705.  
  7706. //converts the pretty order id to an actual post ID
  7707.  
  7708. function order_to_post_id($order_id) {
  7709.  
  7710. global $wpdb;
  7711.  
  7712. return $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type = 'mp_order'", $order_id));
  7713.  
  7714. }
  7715.  
  7716.  
  7717.  
  7718. //$new_status can be 'received', 'paid', 'shipped', 'closed'
  7719.  
  7720. function update_order_status($order_id, $new_status) {
  7721.  
  7722. global $wpdb;
  7723.  
  7724.  
  7725.  
  7726. $statuses = array('received' => 'order_received', 'paid' => 'order_paid', 'shipped' => 'order_shipped', 'closed' => 'order_closed', 'trash' => 'trash', 'delete' => 'delete');
  7727.  
  7728. if (!array_key_exists($new_status, $statuses))
  7729.  
  7730. return false;
  7731.  
  7732.  
  7733.  
  7734. //get the order
  7735.  
  7736. $order = $this->get_order($order_id);
  7737.  
  7738. if (!$order)
  7739.  
  7740. return false;
  7741.  
  7742.  
  7743.  
  7744. // If we are transitioning the status from 'trash' to some other vlaue we want to decrement the product variation quantities.
  7745.  
  7746. if (($order->post_status == "trash") && ($new_status != "delete") && ($new_status != 'trash')) {
  7747.  
  7748. if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) {
  7749.  
  7750. foreach ($order->mp_cart_info as $product_id => $variations) {
  7751.  
  7752.  
  7753.  
  7754. if (!get_post_meta($product_id, 'mp_track_inventory', true))
  7755.  
  7756. continue;
  7757.  
  7758.  
  7759.  
  7760. $mp_inventory = get_post_meta($product_id, 'mp_inventory', true);
  7761.  
  7762. if (!$mp_inventory)
  7763.  
  7764. continue;
  7765.  
  7766.  
  7767.  
  7768. $_PRODUCT_INVENTORY_CHANGED = false;
  7769.  
  7770. foreach ($variations as $variation => $data) {
  7771.  
  7772. if (array_key_exists($variation, $mp_inventory)) {
  7773.  
  7774. $mp_inventory[$variation] -= $data['quantity'];
  7775.  
  7776. $_PRODUCT_INVENTORY_CHANGED = true;
  7777.  
  7778. }
  7779.  
  7780. }
  7781.  
  7782. if ($_PRODUCT_INVENTORY_CHANGED) {
  7783.  
  7784. update_post_meta($product_id, 'mp_inventory', $mp_inventory);
  7785.  
  7786. }
  7787.  
  7788. }
  7789.  
  7790. }
  7791.  
  7792. }
  7793.  
  7794. switch ($new_status) {
  7795.  
  7796.  
  7797.  
  7798. case 'paid':
  7799.  
  7800. //update paid time, can't be adjusted as we don't want to loose gateway info
  7801.  
  7802. if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
  7803.  
  7804. update_post_meta($order->ID, 'mp_paid_time', time());
  7805.  
  7806. do_action( 'mp_order_paid', $order );
  7807.  
  7808. }
  7809.  
  7810. break;
  7811.  
  7812.  
  7813.  
  7814. case 'shipped':
  7815.  
  7816. //update paid time if paid step was skipped
  7817.  
  7818. if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
  7819.  
  7820. update_post_meta($order->ID, 'mp_paid_time', time());
  7821.  
  7822. do_action( 'mp_order_paid', $order );
  7823.  
  7824. }
  7825.  
  7826.  
  7827.  
  7828. //update shipped time, can be adjusted
  7829.  
  7830. update_post_meta($order->ID, 'mp_shipped_time', time());
  7831.  
  7832. do_action( 'mp_order_shipped', $order );
  7833.  
  7834.  
  7835.  
  7836. //send email
  7837.  
  7838. $this->order_shipped_notification($order->ID);
  7839.  
  7840. break;
  7841.  
  7842.  
  7843.  
  7844. case 'closed':
  7845.  
  7846. //update paid time if paid step was skipped
  7847.  
  7848. if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
  7849.  
  7850. update_post_meta($order->ID, 'mp_paid_time', time());
  7851.  
  7852. do_action( 'mp_order_paid', $order );
  7853.  
  7854. }
  7855.  
  7856.  
  7857.  
  7858. //update shipped time if shipped step was skipped
  7859.  
  7860. if (!get_post_meta($order->ID, 'mp_shipped_time', true)) {
  7861.  
  7862. update_post_meta($order->ID, 'mp_shipped_time', time());
  7863.  
  7864. do_action( 'mp_order_shipped', $order );
  7865.  
  7866. }
  7867.  
  7868.  
  7869.  
  7870. //update closed
  7871.  
  7872. update_post_meta($order->ID, 'mp_closed_time', time());
  7873.  
  7874. do_action( 'mp_order_closed', $order );
  7875.  
  7876. break;
  7877.  
  7878.  
  7879.  
  7880. case 'trash':
  7881.  
  7882. if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) {
  7883.  
  7884. foreach ($order->mp_cart_info as $product_id => $variations) {
  7885.  
  7886.  
  7887.  
  7888. if (!get_post_meta($product_id, 'mp_track_inventory', true))
  7889.  
  7890. continue;
  7891.  
  7892.  
  7893.  
  7894. $mp_inventory = get_post_meta($product_id, 'mp_inventory', true);
  7895.  
  7896. if (!$mp_inventory)
  7897.  
  7898. continue;
  7899.  
  7900.  
  7901.  
  7902. $_PRODUCT_INVENTORY_CHANGED = false;
  7903.  
  7904. foreach ($variations as $variation => $data) {
  7905.  
  7906. if (array_key_exists($variation, $mp_inventory)) {
  7907.  
  7908. $mp_inventory[$variation] += $data['quantity'];
  7909.  
  7910. $_PRODUCT_INVENTORY_CHANGED = true;
  7911.  
  7912. }
  7913.  
  7914. }
  7915.  
  7916.  
  7917.  
  7918. if ($_PRODUCT_INVENTORY_CHANGED) {
  7919.  
  7920. update_post_meta($product_id, 'mp_inventory', $mp_inventory);
  7921.  
  7922. }
  7923.  
  7924.  
  7925.  
  7926. }
  7927.  
  7928. }
  7929.  
  7930. break;
  7931.  
  7932.  
  7933.  
  7934. case 'delete':
  7935.  
  7936. wp_delete_post( $order_id );
  7937.  
  7938. break;
  7939.  
  7940.  
  7941.  
  7942. }
  7943.  
  7944.  
  7945.  
  7946. if ( $statuses[$new_status] == $order->post_status )
  7947.  
  7948. return;
  7949.  
  7950.  
  7951.  
  7952. $wpdb->update( $wpdb->posts, array( 'post_status' => $statuses[$new_status] ), array( 'ID' => $order->ID ) );
  7953.  
  7954.  
  7955.  
  7956. $old_status = $order->post_status;
  7957.  
  7958. $order->post_status = $statuses[$new_status];
  7959.  
  7960. wp_transition_post_status($statuses[$new_status], $old_status, $order);
  7961.  
  7962. }
  7963.  
  7964.  
  7965.  
  7966. //checks if a given cart is only downloadable products
  7967.  
  7968. function download_only_cart($cart) {
  7969.  
  7970. foreach ((array)$cart as $product_id => $variations) {
  7971.  
  7972. foreach ((array)$variations as $variation => $data) {
  7973.  
  7974. if (!is_array($data['download']))
  7975.  
  7976. return false;
  7977.  
  7978. }
  7979.  
  7980. }
  7981.  
  7982. return true;
  7983.  
  7984. }
  7985.  
  7986.  
  7987.  
  7988. //returns formatted download url for a given product. Returns false if no download
  7989.  
  7990. function get_download_url($product_id, $order_id) {
  7991.  
  7992. $url = get_post_meta($product_id, 'mp_file', true);
  7993.  
  7994. if (!$url)
  7995.  
  7996. return false;
  7997.  
  7998.  
  7999.  
  8000. return get_permalink($product_id) . "?orderid=$order_id";
  8001.  
  8002. }
  8003.  
  8004.  
  8005.  
  8006. //serves a downloadble product file
  8007.  
  8008. function serve_download($product_id) {
  8009.  
  8010.  
  8011.  
  8012. if (!isset($_GET['orderid']))
  8013.  
  8014. return false;
  8015.  
  8016.  
  8017.  
  8018. //get the order
  8019.  
  8020. $order = $this->get_order($_GET['orderid']);
  8021.  
  8022. if (!$order)
  8023.  
  8024. wp_die( __('Sorry, the link is invalid for this download.', 'mp') );
  8025.  
  8026.  
  8027.  
  8028. //check that order is paid
  8029.  
  8030. if ($order->post_status == 'order_received')
  8031.  
  8032. wp_die( __('Sorry, your order has been marked as unpaid.', 'mp') );
  8033.  
  8034.  
  8035.  
  8036. $url = get_post_meta($product_id, 'mp_file', true);
  8037.  
  8038.  
  8039.  
  8040. //get cart count
  8041.  
  8042. if (isset($order->mp_cart_info[$product_id][0]['download']))
  8043.  
  8044. $download = $order->mp_cart_info[$product_id][0]['download'];
  8045.  
  8046.  
  8047.  
  8048. //if new url is not set try to grab it from the order history
  8049.  
  8050. if (!$url && isset($download['url']))
  8051.  
  8052. $url = $download['url'];
  8053.  
  8054. else if (!$url)
  8055.  
  8056. wp_die( __('Whoops, we were unable to find the file for this download. Please contact us for help.', 'mp') );
  8057.  
  8058.  
  8059.  
  8060. //check for too many downloads
  8061.  
  8062. $max_downloads = $this->get_setting('max_downloads', 5);
  8063.  
  8064. if (intval($download['downloaded']) >= $max_downloads)
  8065.  
  8066. wp_die( sprintf( __("Sorry, our records show you've downloaded this file %d out of %d times allowed. Please contact us if you still need help.", 'mp'), intval($download['downloaded']), $max_downloads ) );
  8067.  
  8068.  
  8069.  
  8070. //for plugins to hook into the download script. Don't forget to increment the download count, then exit!
  8071.  
  8072. do_action('mp_serve_download', $url, $order, $download);
  8073.  
  8074.  
  8075.  
  8076. //allows you to simply filter the url
  8077.  
  8078. $url = apply_filters('mp_download_url', $url, $order, $download);
  8079.  
  8080.  
  8081.  
  8082. //if your getting out of memory errors with large downloads, you can use a redirect instead, it's not so secure though
  8083.  
  8084. if ( defined('MP_LARGE_DOWNLOADS') && MP_LARGE_DOWNLOADS ) {
  8085.  
  8086. //attempt to record a download attempt
  8087.  
  8088. if (isset($download['downloaded'])) {
  8089.  
  8090. $order->mp_cart_info[$product_id][0]['download']['downloaded'] = $download['downloaded'] + 1;
  8091.  
  8092. update_post_meta($order->ID, 'mp_cart_info', $order->mp_cart_info);
  8093.  
  8094. }
  8095.  
  8096. wp_redirect($url);
  8097.  
  8098. exit;
  8099.  
  8100. } else {
  8101.  
  8102.  
  8103.  
  8104. //create unique filename
  8105.  
  8106. $ext = ltrim(strrchr(basename($url), '.'), '.');
  8107.  
  8108. $filename = sanitize_file_name( strtolower( get_the_title($product_id) ) . '.' . $ext );
  8109.  
  8110.  
  8111.  
  8112. // Determine if this file is in our server
  8113.  
  8114. $dirs = wp_upload_dir();
  8115.  
  8116. $location = str_replace($dirs['baseurl'], $dirs['basedir'], $url);
  8117.  
  8118. if ( file_exists($location) ) {
  8119.  
  8120. $tmp = $location;
  8121.  
  8122. $not_delete = true;
  8123.  
  8124. } else {
  8125.  
  8126. require_once(ABSPATH . '/wp-admin/includes/file.php');
  8127.  
  8128.  
  8129.  
  8130. $tmp = download_url($url); //we download the url so we can serve it via php, completely obfuscating original source
  8131.  
  8132.  
  8133.  
  8134. if ( is_wp_error($tmp) ) {
  8135.  
  8136. @unlink($tmp);
  8137.  
  8138. trigger_error("MarketPress was unable to download the file $url for serving as download: ".$tmp->get_error_message(), E_USER_WARNING);
  8139.  
  8140. wp_die( __('Whoops, there was a problem loading up this file for your download. Please contact us for help.', 'mp') );
  8141.  
  8142. }
  8143.  
  8144. }
  8145.  
  8146.  
  8147.  
  8148. if (file_exists($tmp)) {
  8149.  
  8150. ob_end_clean(); //kills any buffers set by other plugins
  8151.  
  8152. header('Content-Description: File Transfer');
  8153.  
  8154. header('Content-Type: application/octet-stream');
  8155.  
  8156. header('Content-Disposition: attachment; filename="'.$filename.'"');
  8157.  
  8158. header('Content-Transfer-Encoding: binary');
  8159.  
  8160. header('Expires: 0');
  8161.  
  8162. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  8163.  
  8164. header('Pragma: public');
  8165.  
  8166. header('Content-Length: ' . filesize($tmp));
  8167.  
  8168. //readfile($tmp); //seems readfile chokes on large files
  8169.  
  8170. $chunksize = 1 * (1024 * 1024); // how many bytes per chunk
  8171.  
  8172. $buffer = '';
  8173.  
  8174. $cnt = 0;
  8175.  
  8176. $handle = fopen( $tmp, 'rb' );
  8177.  
  8178. if ( $handle === false ) {
  8179.  
  8180. trigger_error("MarketPress was unable to read the file $tmp for serving as download.", E_USER_WARNING);
  8181.  
  8182. return false;
  8183.  
  8184. }
  8185.  
  8186. while ( !feof( $handle ) ) {
  8187.  
  8188. $buffer = fread( $handle, $chunksize );
  8189.  
  8190. echo $buffer;
  8191.  
  8192. ob_flush();
  8193.  
  8194. flush();
  8195.  
  8196. if ( $retbytes ) {
  8197.  
  8198. $cnt += strlen( $buffer );
  8199.  
  8200. }
  8201.  
  8202. }
  8203.  
  8204. fclose( $handle );
  8205.  
  8206.  
  8207.  
  8208. if (!$not_delete)
  8209.  
  8210. @unlink($tmp);
  8211.  
  8212. }
  8213.  
  8214.  
  8215.  
  8216. //attempt to record a download attempt
  8217.  
  8218. if (isset($download['downloaded'])) {
  8219.  
  8220. $order->mp_cart_info[$product_id][0]['download']['downloaded'] = $download['downloaded'] + 1;
  8221.  
  8222. update_post_meta($order->ID, 'mp_cart_info', $order->mp_cart_info);
  8223.  
  8224. }
  8225.  
  8226. exit;
  8227.  
  8228. }
  8229.  
  8230.  
  8231.  
  8232. return false;
  8233.  
  8234. }
  8235.  
  8236.  
  8237.  
  8238. // Update profile fields
  8239.  
  8240. function user_profile_update() {
  8241.  
  8242. $user_id = $_REQUEST['user_id'];
  8243.  
  8244. $fields = array( 'email', 'name', 'address1', 'address2', 'city', 'state', 'zip', 'country', 'phone' );
  8245.  
  8246.  
  8247.  
  8248. //shipping fields
  8249.  
  8250. $meta = array();
  8251.  
  8252. foreach ( $fields as $field ) {
  8253.  
  8254. if ( isset($_POST['mp_shipping_info'][$field]) )
  8255.  
  8256. $meta[$field] = $_POST['mp_shipping_info'][$field];
  8257.  
  8258. else
  8259.  
  8260. $meta[$field] = '';
  8261.  
  8262. }
  8263.  
  8264. update_user_meta($user_id, 'mp_shipping_info', $meta);
  8265.  
  8266.  
  8267.  
  8268. // Billing Info
  8269.  
  8270. $meta = array();
  8271.  
  8272. foreach ( $fields as $field ) {
  8273.  
  8274. if ( isset($_POST['mp_billing_info'][$field]) )
  8275.  
  8276. $meta[$field] = $_POST['mp_billing_info'][$field];
  8277.  
  8278. else
  8279.  
  8280. $meta[$field] = '';
  8281.  
  8282. }
  8283.  
  8284. update_user_meta($user_id, 'mp_billing_info', $meta);
  8285.  
  8286. }
  8287.  
  8288.  
  8289.  
  8290. function user_profile_fields() {
  8291.  
  8292. global $current_user;
  8293.  
  8294. $fields = array( 'email', 'name', 'address1', 'address2', 'city', 'state', 'zip', 'country', 'phone' );
  8295.  
  8296.  
  8297.  
  8298. if (isset($_REQUEST['user_id'])) {
  8299.  
  8300. $user_id = $_REQUEST['user_id'];
  8301.  
  8302. } else {
  8303.  
  8304. $user_id = $current_user->ID;
  8305.  
  8306. }
  8307.  
  8308.  
  8309.  
  8310. //initialize variables
  8311.  
  8312. $meta = get_user_meta($user_id, 'mp_shipping_info', true);
  8313.  
  8314. foreach ( $fields as $field ) {
  8315.  
  8316. if ( !empty($_SESSION['mp_shipping_info'][$field]) )
  8317.  
  8318. $$field = $_SESSION['mp_shipping_info'][$field];
  8319.  
  8320. else if ( !empty($meta[$field]) )
  8321.  
  8322. $$field = $meta[$field];
  8323.  
  8324. else
  8325.  
  8326. $$field = '';
  8327.  
  8328. }
  8329.  
  8330. if ( empty($country) )
  8331.  
  8332. $country = $this->get_setting('base_country');
  8333.  
  8334.  
  8335.  
  8336. ?>
  8337.  
  8338. <h3><?php _e('Shipping Info', 'mp'); ?></h3>
  8339.  
  8340. <table class="form-table">
  8341.  
  8342. <tr>
  8343.  
  8344. <th align="right"><label for="mp_shipping_info_email"><?php _e('Email:', 'mp'); ?>&nbsp;</label></th><td>
  8345.  
  8346. <?php echo apply_filters( 'mp_shipping_info_error_email', ''); ?>
  8347.  
  8348. <input size="35" id="mp_shipping_info_email" name="mp_shipping_info[email]" type="text" value="<?php echo esc_attr($email); ?>" /></td>
  8349.  
  8350. </tr>
  8351.  
  8352. <tr>
  8353.  
  8354. <th align="right"><label for="mp_shipping_info_name"><?php _e('Full Name:', 'mp'); ?>&nbsp;</label></th><td>
  8355.  
  8356. <?php echo apply_filters( 'mp_checkout_error_name', ''); ?>
  8357.  
  8358. <input size="35" id="mp_shipping_info_name" name="mp_shipping_info[name]" type="text" value="<?php echo esc_attr($name); ?>" /> </td>
  8359.  
  8360. </tr>
  8361.  
  8362. <tr>
  8363.  
  8364. <th align="right"><label for="mp_shipping_info_address1"><?php _e('Address:', 'mp'); ?>&nbsp;</label></th><td>
  8365.  
  8366. <?php echo apply_filters( 'mp_shipping_info_error_address1', ''); ?>
  8367.  
  8368. <input size="45" id="mp_shipping_info_address1" name="mp_shipping_info[address1]" type="text" value="<?php echo esc_attr($address1); ?>" /><br />
  8369.  
  8370. <small><em><?php _e('Street address, P.O. box, company name, c/o', 'mp'); ?></em></small>
  8371.  
  8372. </td>
  8373.  
  8374. </tr>
  8375.  
  8376. <tr>
  8377.  
  8378. <th align="right"><label for="mp_shipping_info_address2"><?php _e('Address 2:', 'mp'); ?>&nbsp;</label></th><td>
  8379.  
  8380. <?php echo apply_filters( 'mp_shipping_info_error_address2', ''); ?>
  8381.  
  8382. <input size="45" id="mp_shipping_info_address2" name="mp_shipping_info[address2]" type="text" value="<?php echo esc_attr($address2); ?>" /><br />
  8383.  
  8384. <small><em><?php _e('Apartment, suite, unit, building, floor, etc.', 'mp'); ?></em></small>
  8385.  
  8386. </td>
  8387.  
  8388. </tr>
  8389.  
  8390. <tr>
  8391.  
  8392. <th align="right"><label for="mp_shipping_info_city"><?php _e('City:', 'mp'); ?>&nbsp;</label></th><td>
  8393.  
  8394. <?php echo apply_filters( 'mp_shipping_info_error_city', ''); ?>
  8395.  
  8396. <input size="25" id="mp_shipping_info_city" name="mp_shipping_info[city]" type="text" value="<?php echo esc_attr($city); ?>" /></td>
  8397.  
  8398. </tr>
  8399.  
  8400. <tr>
  8401.  
  8402. <th align="right"><label for="mp_shipping_info_state"><?php _e('State/Province/Region:', 'mp'); ?>&nbsp;</label></th><td>
  8403.  
  8404. <?php echo apply_filters( 'mp_shipping_info_error_state', ''); ?>
  8405.  
  8406. <input size="15" id="mp_shipping_info_state" name="mp_shipping_info[state]" type="text" value="<?php echo esc_attr($state); ?>" /></td>
  8407.  
  8408. </tr>
  8409.  
  8410. <tr>
  8411.  
  8412. <th align="right"><label for="mp_shipping_info_zip"><?php _e('Postal/Zip Code:', 'mp'); ?>&nbsp;</label></th><td>
  8413.  
  8414. <?php echo apply_filters( 'mp_shipping_info_error_zip', ''); ?>
  8415.  
  8416. <input size="10" id="mp_shipping_info_zip" name="mp_shipping_info[zip]" type="text" value="<?php echo esc_attr($zip); ?>" /></td>
  8417.  
  8418. </tr>
  8419.  
  8420. <tr>
  8421.  
  8422. <th align="right"><label for="mp_shipping_info_country"><?php _e('Country:', 'mp'); ?>&nbsp;</label></th><td>
  8423.  
  8424. <?php echo apply_filters( 'mp_shipping_info_error_country', ''); ?>
  8425.  
  8426. <select id="mp_shipping_info_country" name="mp_shipping_info[country]">
  8427.  
  8428. <?php
  8429.  
  8430. foreach ($this->get_setting('shipping->allowed_countries') as $code) {
  8431.  
  8432. ?><option value="<?php echo $code; ?>"<?php selected($country, $code); ?>><?php echo esc_attr($this->countries[$code]); ?></option><?php
  8433.  
  8434. }
  8435.  
  8436. ?>
  8437.  
  8438. </select>
  8439.  
  8440. </td>
  8441.  
  8442. </tr>
  8443.  
  8444. <tr>
  8445.  
  8446. <th align="right"><label for="mp_shipping_info_phone"><?php _e('Phone Number:', 'mp'); ?>&nbsp;</label></th><td>
  8447.  
  8448. <?php echo apply_filters( 'mp_shipping_info_error_phone', ''); ?>
  8449.  
  8450. <input size="20" id="mp_shipping_info_phone" name="mp_shipping_info[phone]" type="text" value="<?php echo esc_attr($phone); ?>" /></td>
  8451.  
  8452. </tr>
  8453.  
  8454. </table>
  8455.  
  8456. <?php
  8457.  
  8458.  
  8459.  
  8460. //initialize variables
  8461.  
  8462. $meta = get_user_meta($user_id, 'mp_billing_info', true);
  8463.  
  8464. foreach ( $fields as $field ) {
  8465.  
  8466. if ( !empty($_SESSION['mp_billing_info'][$field]) )
  8467.  
  8468. $$field = $_SESSION['mp_billing_info'][$field];
  8469.  
  8470. else if ( !empty($meta[$field]) )
  8471.  
  8472. $$field = $meta[$field];
  8473.  
  8474. else
  8475.  
  8476. $$field = '';
  8477.  
  8478. }
  8479.  
  8480. if ( empty($country) )
  8481.  
  8482. $country = $this->get_setting('base_country');
  8483.  
  8484. ?>
  8485.  
  8486. <h3><?php _e('Billing Info', 'mp'); ?> <a class="add-new-h2" href="javascript:mp_copy_billing('mp_billing_info');"><?php _e('Same as Shipping', 'mp'); ?></a></h3>
  8487.  
  8488. <table class="form-table">
  8489.  
  8490. <tr>
  8491.  
  8492. <th align="right"><label for="mp_billing_info_email"><?php _e('Email:', 'mp'); ?>&nbsp;</label></th><td>
  8493.  
  8494. <?php echo apply_filters( 'mp_billing_info_error_email', ''); ?>
  8495.  
  8496. <input size="35" id="mp_billing_info_email" name="mp_billing_info[email]" type="text" value="<?php echo esc_attr($email); ?>" /></td>
  8497.  
  8498. </tr>
  8499.  
  8500. <tr>
  8501.  
  8502. <th align="right"><label for="mp_billing_info_name"><?php _e('Full Name:', 'mp'); ?>&nbsp;</label></th><td>
  8503.  
  8504. <?php echo apply_filters( 'mp_billing_info_error_name', ''); ?>
  8505.  
  8506. <input size="35" id="mp_billing_info_name" name="mp_billing_info[name]" type="text" value="<?php echo esc_attr($name); ?>" /> </td>
  8507.  
  8508. </tr>
  8509.  
  8510. <tr>
  8511.  
  8512. <th align="right"><label for="mp_billing_info_address1"><?php _e('Address:', 'mp'); ?>&nbsp;</label></th><td>
  8513.  
  8514. <?php echo apply_filters( 'mp_billing_info_error_address1', ''); ?>
  8515.  
  8516. <input size="45" id="mp_billing_info_address1" name="mp_billing_info[address1]" type="text" value="<?php echo esc_attr($address1); ?>" /><br />
  8517.  
  8518. <small><em><?php _e('Street address, P.O. box, company name, c/o', 'mp'); ?></em></small>
  8519.  
  8520. </td>
  8521.  
  8522. </tr>
  8523.  
  8524. <tr>
  8525.  
  8526. <th align="right"><label for="mp_billing_info_address2"><?php _e('Address 2:', 'mp'); ?>&nbsp;</label></th><td>
  8527.  
  8528. <?php echo apply_filters( 'mp_billing_info_error_address2', ''); ?>
  8529.  
  8530. <input size="45" id="mp_billing_info_address2" name="mp_billing_info[address2]" type="text" value="<?php echo esc_attr($address2); ?>" /><br />
  8531.  
  8532. <small><em><?php _e('Apartment, suite, unit, building, floor, etc.', 'mp'); ?></em></small>
  8533.  
  8534. </td>
  8535.  
  8536. </tr>
  8537.  
  8538. <tr>
  8539.  
  8540. <th align="right"><label for="mp_billing_info_city"><?php _e('City:', 'mp'); ?>&nbsp;</label></th><td>
  8541.  
  8542. <?php echo apply_filters( 'mp_billing_info_error_city', ''); ?>
  8543.  
  8544. <input size="25" id="mp_billing_info_city" name="mp_billing_info[city]" type="text" value="<?php echo esc_attr($city); ?>" /></td>
  8545.  
  8546. </tr>
  8547.  
  8548. <tr>
  8549.  
  8550. <th align="right"><label for="mp_billing_info_state"><?php _e('State/Province/Region:', 'mp'); ?>&nbsp;</label></th><td>
  8551.  
  8552. <?php echo apply_filters( 'mp_billing_info_error_state', ''); ?>
  8553.  
  8554. <input size="15" id="mp_billing_info_state" name="mp_billing_info[state]" type="text" value="<?php echo esc_attr($state); ?>" /></td>
  8555.  
  8556. </tr>
  8557.  
  8558. <tr>
  8559.  
  8560. <th align="right"><label for="mp_billing_info_zip"><?php _e('Postal/Zip Code:', 'mp'); ?>&nbsp;</label></th><td>
  8561.  
  8562. <?php echo apply_filters( 'mp_billing_info_error_zip', ''); ?>
  8563.  
  8564. <input size="10" id="mp_billing_info_zip" name="mp_billing_info[zip]" type="text" value="<?php echo esc_attr($zip); ?>" /></td>
  8565.  
  8566. </tr>
  8567.  
  8568. <tr>
  8569.  
  8570. <th align="right"><label for="mp_billing_info_country"><?php _e('Country:', 'mp'); ?>&nbsp;</label></th><td>
  8571.  
  8572. <?php echo apply_filters( 'mp_billing_info_error_country', ''); ?>
  8573.  
  8574. <select id="mp_billing_info_country" name="mp_billing_info[country]">
  8575.  
  8576. <?php
  8577.  
  8578. foreach ($this->get_setting('shipping->allowed_countries') as $code) {
  8579.  
  8580. ?><option value="<?php echo $code; ?>"<?php selected($country, $code); ?>><?php echo esc_attr($this->countries[$code]); ?></option><?php
  8581.  
  8582. }
  8583.  
  8584. ?>
  8585.  
  8586. </select>
  8587.  
  8588. </td>
  8589.  
  8590. </tr>
  8591.  
  8592. <tr>
  8593.  
  8594. <th align="right"><label for="mp_billing_info_phone"><?php _e('Phone Number:', 'mp'); ?>&nbsp;</label></th><td>
  8595.  
  8596. <?php echo apply_filters( 'mp_billing_info_error_phone', ''); ?>
  8597.  
  8598. <input size="20" id="mp_billing_info_phone" name="mp_billing_info[phone]" type="text" value="<?php echo esc_attr($phone); ?>" /></td>
  8599.  
  8600. </tr>
  8601.  
  8602. </table>
  8603.  
  8604. <script type="text/javascript">
  8605.  
  8606. function mp_copy_billing(prefix) {
  8607.  
  8608. _mp_profile_billing_fields = ['email', 'name', 'address1', 'address2', 'city', 'state', 'zip', 'country', 'phone'];
  8609.  
  8610.  
  8611.  
  8612. for (_i=0; _i<_mp_profile_billing_fields.length; _i++) {
  8613.  
  8614. jQuery('form #'+prefix+'_'+_mp_profile_billing_fields[_i]).val(jQuery('form #mp_shipping_info_'+_mp_profile_billing_fields[_i]).val());
  8615.  
  8616. }
  8617.  
  8618. }
  8619.  
  8620. </script>
  8621.  
  8622. <?php
  8623.  
  8624. }
  8625.  
  8626.  
  8627.  
  8628. //called by payment gateways to update order statuses
  8629.  
  8630. function update_order_payment_status($order_id, $status, $paid) {
  8631.  
  8632. //get the order
  8633.  
  8634. $order = $this->get_order($order_id);
  8635.  
  8636. if (!$order)
  8637.  
  8638. return false;
  8639.  
  8640.  
  8641.  
  8642. //get old status
  8643.  
  8644. $payment_info = $order->mp_payment_info;
  8645.  
  8646. $timestamp = time();
  8647.  
  8648. $payment_info['status'][$timestamp] = $status;
  8649.  
  8650. //update post meta
  8651.  
  8652. update_post_meta($order->ID, 'mp_payment_info', $payment_info);
  8653.  
  8654.  
  8655.  
  8656. if ($paid) {
  8657.  
  8658. if ($order->post_status == 'order_received') {
  8659.  
  8660. $this->update_order_status($order->ID, 'paid');
  8661.  
  8662.  
  8663.  
  8664. //if paid and the cart is only digital products mark it shipped
  8665.  
  8666. if (is_array($order->mp_cart_info) && $this->download_only_cart($order->mp_cart_info))
  8667.  
  8668. $this->update_order_status($order->ID, 'shipped');
  8669.  
  8670. } else {
  8671.  
  8672. //update payment time if somehow it was skipped
  8673.  
  8674. if (!get_post_meta($order->ID, 'mp_paid_time', true))
  8675.  
  8676. update_post_meta($order->ID, 'mp_paid_time', time());
  8677.  
  8678. }
  8679.  
  8680. } else {
  8681.  
  8682. $this->update_order_status($order->ID, 'received');
  8683.  
  8684. }
  8685.  
  8686.  
  8687.  
  8688. //return merged payment info
  8689.  
  8690. return $payment_info;
  8691.  
  8692. }
  8693.  
  8694.  
  8695.  
  8696. //filters wp_mail headers
  8697.  
  8698. function mail($to, $subject, $msg) {
  8699.  
  8700.  
  8701.  
  8702. //remove any other filters
  8703.  
  8704. remove_all_filters( 'wp_mail_from' );
  8705.  
  8706. remove_all_filters( 'wp_mail_from_name' );
  8707.  
  8708.  
  8709.  
  8710. //add our own filters
  8711.  
  8712. add_filter( 'wp_mail_from_name', create_function('', 'return get_bloginfo("name");') );
  8713.  
  8714. add_filter( 'wp_mail_from', create_function('', '$settings = get_option("mp_settings");return isset($settings["store_email"]) ? $settings["store_email"] : get_option("admin_email");') );
  8715.  
  8716.  
  8717.  
  8718. return wp_mail($to, $subject, $msg);
  8719.  
  8720. }
  8721.  
  8722.  
  8723.  
  8724. //replaces shortcodes in email msgs with dynamic content
  8725.  
  8726. function filter_email($order, $text, $escape = false) {
  8727.  
  8728. global $blog_id;
  8729.  
  8730. $bid = (is_multisite()) ? $blog_id : 1;
  8731.  
  8732.  
  8733.  
  8734. //// order info
  8735.  
  8736. if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) {
  8737.  
  8738. $order_info = $order_info_sku = __('Items:', 'mp') . "\n";
  8739.  
  8740. foreach ($order->mp_cart_info as $product_id => $variations) {
  8741.  
  8742. foreach ($variations as $variation => $data) {
  8743.  
  8744. $order_info .= "\t" . $data['name'] . ': ' . number_format_i18n($data['quantity']) . ' * ' . number_format_i18n($data['price'], 2) . ' = '. number_format_i18n($data['price'] * $data['quantity'], 2) . ' ' . $order->mp_payment_info['currency'] . "\n";
  8745.  
  8746. $order_info_sku .= "\t" . $data['name'] . ' - ' . $data['sku'] . ': ' . number_format_i18n($data['quantity']) . ' * ' . number_format_i18n($data['price'], 2) . ' = '. number_format_i18n($data['price'] * $data['quantity'], 2) . ' ' . $order->mp_payment_info['currency'] . "\n";
  8747.  
  8748.  
  8749.  
  8750. //show download link if set
  8751.  
  8752. if ($order->post_status != 'order_received' && $download_url = $this->get_download_url($product_id, $order->post_title)) {
  8753.  
  8754. $order_info .= "\t\t" . __('Download: ', 'mp') . $download_url . "\n";
  8755.  
  8756. $order_info_sku .= "\t\t" . __('Download: ', 'mp') . $download_url . "\n";
  8757.  
  8758. }
  8759.  
  8760.  
  8761.  
  8762. // FPM: Product Custom Fields
  8763.  
  8764. $cf_key = $bid .':'. $product_id .':'. $variation;
  8765.  
  8766. if (isset($order->mp_shipping_info['mp_custom_fields'][$cf_key])) {
  8767.  
  8768. $cf_items = $order->mp_shipping_info['mp_custom_fields'][$cf_key];
  8769.  
  8770.  
  8771.  
  8772. $mp_custom_field_label = get_post_meta($product_id, 'mp_custom_field_label', true);
  8773.  
  8774. if (isset($mp_custom_field_label[$variation]))
  8775.  
  8776. $label_text = esc_attr($mp_custom_field_label[$variation]);
  8777.  
  8778. else
  8779.  
  8780. $label_text = __('Product Personalization: ', 'mp');
  8781.  
  8782.  
  8783.  
  8784. $order_info .= "\t\t" . $label_text ."\n";
  8785.  
  8786. $order_info_sku .= "\t\t" . $label_text ."\n";
  8787.  
  8788. foreach($cf_items as $idx => $cf_item) {
  8789.  
  8790. $item_cnt = intval($idx)+1;
  8791.  
  8792. $order_info .= "\t\t\t" . $item_cnt .". ". $cf_item ."\n";
  8793.  
  8794. $order_info_sku .= "\t\t\t" . $item_cnt .". ". $cf_item ."\n";
  8795.  
  8796. }
  8797.  
  8798. }
  8799.  
  8800. $order_info .= "\n";
  8801.  
  8802. $order_info_sku .= "\n";
  8803.  
  8804. }
  8805.  
  8806. }
  8807.  
  8808. $order_info .= "\n";
  8809.  
  8810. $order_info_sku .= "\n";
  8811.  
  8812. }
  8813.  
  8814. //coupon line
  8815.  
  8816. if ( $order->mp_discount_info ) {
  8817.  
  8818. if (false !== strpos($order->mp_discount_info['discount'], '%'))
  8819.  
  8820. $discount = str_replace('%', '%%', $order->mp_discount_info['discount']); //have to escape % sign so sprintf doesn't choke
  8821.  
  8822. else
  8823.  
  8824. $discount = preg_replace("/&([A-Za-z]+|#x[\dA-Fa-f]+|#\d+);/", "", $order->mp_discount_info['discount']) . ' ' . $order->mp_payment_info['currency'];
  8825.  
  8826. $order_info .= "\n" . __('Coupon Discount:', 'mp') . ' ' . $discount;
  8827.  
  8828. $order_info_sku .= "\n" . __('Coupon Discount:', 'mp') . ' ' . $discount;
  8829.  
  8830. }
  8831.  
  8832. //shipping line
  8833.  
  8834. if ( $order->mp_shipping_total ) {
  8835.  
  8836. $order_info .= "\n" . __('Shipping:', 'mp') . ' ' . number_format_i18n($this->get_display_shipping($order), 2) . ' ' . $order->mp_payment_info['currency'];
  8837.  
  8838. $order_info_sku .= "\n" . __('Shipping:', 'mp') . ' ' . number_format_i18n($this->get_display_shipping($order), 2) . ' ' . $order->mp_payment_info['currency'];
  8839.  
  8840. }
  8841.  
  8842. //tax line
  8843.  
  8844. if ( $order->mp_tax_total ) {
  8845.  
  8846. $order_info .= "\n" . esc_html($this->get_setting('tax->label', __('Taxes', 'mp'))) . ': ' . number_format_i18n((float)$order->mp_tax_total, 2) . ' ' . $order->mp_payment_info['currency'];
  8847.  
  8848. $order_info_sku .= "\n" . esc_html($this->get_setting('tax->label', __('Taxes', 'mp'))) . ': ' . number_format_i18n((float)$order->mp_tax_total, 2) . ' ' . $order->mp_payment_info['currency'];
  8849.  
  8850. }
  8851.  
  8852. //total line
  8853.  
  8854. $order_info .= "\n" . __('Order Total:', 'mp') . ' ' . number_format_i18n((float)$order->mp_order_total, 2) . ' ' . $order->mp_payment_info['currency'];
  8855.  
  8856. $order_info_sku .= "\n" . __('Order Total:', 'mp') . ' ' . number_format_i18n((float)$order->mp_order_total, 2) . ' ' . $order->mp_payment_info['currency'];
  8857.  
  8858.  
  8859.  
  8860. //// Shipping Info
  8861.  
  8862.  
  8863.  
  8864. if ((is_array($order->mp_cart_info) && $this->download_only_cart($order->mp_cart_info)) || $this->get_setting('shipping->method') == 'none') { //if the cart is only digital products
  8865.  
  8866. $shipping_info = __('No shipping required for this order.', 'mp');
  8867.  
  8868. } else {
  8869.  
  8870. $shipping_info = __('Full Name:', 'mp') . ' ' . $order->mp_shipping_info['name'];
  8871.  
  8872. $shipping_info .= "\n" . __('Address:', 'mp') . ' ' . $order->mp_shipping_info['address1'];
  8873.  
  8874. if ($order->mp_shipping_info['address2'])
  8875.  
  8876. $shipping_info .= "\n" . __('Address 2:', 'mp') . ' ' . $order->mp_shipping_info['address2'];
  8877.  
  8878. $shipping_info .= "\n" . __('City:', 'mp') . ' ' . $order->mp_shipping_info['city'];
  8879.  
  8880. if (!empty($order->mp_shipping_info['state']))
  8881.  
  8882. $shipping_info .= "\n" . __('State/Province/Region:', 'mp') . ' ' . $order->mp_shipping_info['state'];
  8883.  
  8884. $shipping_info .= "\n" . __('Postal/Zip Code:', 'mp') . ' ' . $order->mp_shipping_info['zip'];
  8885.  
  8886. $shipping_info .= "\n" . __('Country:', 'mp') . ' ' . $order->mp_shipping_info['country'];
  8887.  
  8888. if (!empty($order->mp_shipping_info['phone']))
  8889.  
  8890. $shipping_info .= "\n" . __('Phone Number:', 'mp') . ' ' . $order->mp_shipping_info['phone'];
  8891.  
  8892.  
  8893.  
  8894. // If actually shipped show method, else customer's shipping choice.
  8895.  
  8896. if (isset($order->mp_shipping_info['method']) && $order->mp_shipping_info['method'] != 'other')
  8897.  
  8898. $shipping_info .= "\n" . __('Shipping Method:', 'mp') . ' ' . $order->mp_shipping_info['method'];
  8899.  
  8900. elseif (! empty($order->mp_shipping_info['shipping_option']) )
  8901.  
  8902. $shipping_info .= "\n" . __('Shipping Method:', 'mp') . ' ' . strtoupper($order->mp_shipping_info['shipping_option']) . ' ' .$order->mp_shipping_info['shipping_sub_option'] ;
  8903.  
  8904.  
  8905.  
  8906. if (!empty($order->mp_shipping_info['tracking_num']))
  8907.  
  8908. $shipping_info .= "\n" . __('Tracking Number:', 'mp') . ' ' . $order->mp_shipping_info['tracking_num'];
  8909.  
  8910. }
  8911.  
  8912.  
  8913.  
  8914. if (!empty($order->mp_shipping_info['special_instructions']))
  8915.  
  8916. $shipping_info .= "\n" . __('Special Instructions:', 'mp') . ' ' . $order->mp_shipping_info['special_instructions'];
  8917.  
  8918.  
  8919.  
  8920. $order_notes = '';
  8921.  
  8922. if (!empty($order->mp_order_notes))
  8923.  
  8924. $order_notes = __('Order Notes:', 'mp') . "\n" . $order->mp_order_notes;
  8925.  
  8926.  
  8927.  
  8928. //// Payment Info
  8929.  
  8930. $payment_info = __('Payment Method:', 'mp') . ' ' . $order->mp_payment_info['gateway_public_name'];
  8931.  
  8932.  
  8933.  
  8934. if ($order->mp_payment_info['method'])
  8935.  
  8936. $payment_info .= "\n" . __('Payment Type:', 'mp') . ' ' . $order->mp_payment_info['method'];
  8937.  
  8938.  
  8939.  
  8940. if ($order->mp_payment_info['transaction_id'])
  8941.  
  8942. $payment_info .= "\n" . __('Transaction ID:', 'mp') . ' ' . $order->mp_payment_info['transaction_id'];
  8943.  
  8944.  
  8945.  
  8946. $payment_info .= "\n" . __('Payment Total:', 'mp') . ' ' . number_format_i18n((float)$order->mp_payment_info['total'], 2) . ' ' . $order->mp_payment_info['currency'];
  8947.  
  8948. $payment_info .= "\n\n";
  8949.  
  8950. if ($order->post_status == 'order_received') {
  8951.  
  8952. $payment_info .= __('Your payment for this order is not yet complete. Here is the latest status:', 'mp') . "\n";
  8953.  
  8954. $statuses = $order->mp_payment_info['status'];
  8955.  
  8956. krsort($statuses); //sort with latest status at the top
  8957.  
  8958. $status = reset($statuses);
  8959.  
  8960. $timestamp = key($statuses);
  8961.  
  8962. $payment_info .= $this->format_date($timestamp) . ': ' . $status;
  8963.  
  8964. } else {
  8965.  
  8966. $payment_info .= __('Your payment for this order is complete.', 'mp');
  8967.  
  8968. }
  8969.  
  8970.  
  8971.  
  8972. //total
  8973.  
  8974. $order_total = number_format_i18n((float)$order->mp_payment_info['total'], 2) . ' ' . $order->mp_payment_info['currency'];
  8975.  
  8976.  
  8977.  
  8978. //tracking URL
  8979.  
  8980. $tracking_url = apply_filters('wpml_marketpress_tracking_url', mp_orderstatus_link(false, true) . $order->post_title . '/');
  8981.  
  8982.  
  8983.  
  8984. //setup filters
  8985.  
  8986. $search = array('CUSTOMERNAME', 'ORDERID', 'ORDERINFO', 'ORDERINFOSKU', 'SHIPPINGINFO', 'PAYMENTINFO', 'TOTAL', 'TRACKINGURL', 'ORDERNOTES');
  8987.  
  8988. $replace = array($order->mp_shipping_info['name'], $order->post_title, $order_info, $order_info_sku, $shipping_info, $payment_info, $order_total, $tracking_url, $order_notes);
  8989.  
  8990.  
  8991.  
  8992. //escape for sprintf() if required
  8993.  
  8994. if ($escape) {
  8995.  
  8996. $replace = array_map( create_function('$a', 'return str_replace("%","%%",$a);'), $replace );
  8997.  
  8998. }
  8999.  
  9000.  
  9001.  
  9002. //replace
  9003.  
  9004. $text = str_replace($search, $replace, $text);
  9005.  
  9006.  
  9007.  
  9008. return $text;
  9009.  
  9010. }
  9011.  
  9012.  
  9013.  
  9014. //sends email for new orders
  9015.  
  9016. function order_notification($order_id) {
  9017.  
  9018.  
  9019.  
  9020. //get the order
  9021.  
  9022. $order = $this->get_order($order_id);
  9023.  
  9024. if (!$order)
  9025.  
  9026. return false;
  9027.  
  9028.  
  9029.  
  9030. $subject = apply_filters('mp_order_notification_subject', $this->filter_email($order, stripslashes($this->get_setting('email->new_order_subject'))), $order);
  9031.  
  9032. $msg = apply_filters('mp_order_notification_body', $this->filter_email($order, stripslashes($this->get_setting('email->new_order_txt'))), $order);
  9033.  
  9034. $msg = apply_filters('mp_order_notification_' . $_SESSION['mp_payment_method'], $msg, $order );
  9035.  
  9036.  
  9037.  
  9038. $this->mail($order->mp_shipping_info['email'], $subject, $msg);
  9039.  
  9040.  
  9041.  
  9042. //send message to admin
  9043.  
  9044. $subject = __('New Order Notification: ORDERID', 'mp');
  9045.  
  9046. $msg = __("A new order (ORDERID) was created in your store:
  9047.  
  9048.  
  9049.  
  9050. Order Information:
  9051.  
  9052. ORDERINFOSKU
  9053.  
  9054.  
  9055.  
  9056. Shipping Information:
  9057.  
  9058. SHIPPINGINFO
  9059.  
  9060.  
  9061.  
  9062. Email: %s
  9063.  
  9064.  
  9065.  
  9066. Payment Information:
  9067.  
  9068. PAYMENTINFO
  9069.  
  9070.  
  9071.  
  9072. You can manage this order here: %s", 'mp');
  9073.  
  9074.  
  9075.  
  9076. $subject = $this->filter_email($order, $subject);
  9077.  
  9078. $subject = apply_filters( 'mp_order_notification_admin_subject', $subject, $order );
  9079.  
  9080. $msg = $this->filter_email($order, $msg, true);
  9081.  
  9082. $msg = sprintf($msg, $order->mp_shipping_info['email'], admin_url('edit.php?post_type=product&page=marketpress-orders&order_id=') . $order->ID);
  9083.  
  9084. $msg = apply_filters( 'mp_order_notification_admin_msg', $msg, $order );
  9085.  
  9086. $store_email = $this->get_setting('store_email') ? $this->get_setting('store_email') : get_option("admin_email");
  9087.  
  9088. $this->mail($store_email, $subject, $msg);
  9089.  
  9090. }
  9091.  
  9092.  
  9093.  
  9094. //sends email for orders marked as shipped
  9095.  
  9096. function order_shipped_notification($order_id) {
  9097.  
  9098.  
  9099.  
  9100. //get the order
  9101.  
  9102. $order = $this->get_order($order_id);
  9103.  
  9104. if (!$order)
  9105.  
  9106. return false;
  9107.  
  9108.  
  9109.  
  9110. //skip notice for paid download only carts
  9111.  
  9112. if ($this->skip_shipping_notice)
  9113.  
  9114. return false;
  9115.  
  9116.  
  9117.  
  9118. $subject = apply_filters('mp_shipped_order_notification_subject', stripslashes($this->get_setting('email->shipped_order_subject')), $order);
  9119.  
  9120. $subject = $this->filter_email($order, $subject);
  9121.  
  9122. $msg = apply_filters( 'mp_shipped_order_notification_body', stripslashes($this->get_setting('email->shipped_order_txt')), $order );
  9123.  
  9124. $msg = $this->filter_email($order, $msg);
  9125.  
  9126. $msg = apply_filters( 'mp_shipped_order_notification', $msg, $order );
  9127.  
  9128.  
  9129.  
  9130. $this->mail($order->mp_shipping_info['email'], $subject, $msg);
  9131.  
  9132.  
  9133.  
  9134. }
  9135.  
  9136.  
  9137.  
  9138. //sends email to admin for low stock notification
  9139.  
  9140. function low_stock_notification($product_id, $variation, $stock) {
  9141.  
  9142.  
  9143.  
  9144. //skip if sent already and not 0
  9145.  
  9146. if ( get_post_meta($product_id, 'mp_stock_email_sent', true) && $stock > 0 )
  9147.  
  9148. return;
  9149.  
  9150.  
  9151.  
  9152. $var_names = maybe_unserialize(get_post_meta($product_id, 'mp_var_name', true));
  9153.  
  9154. if (is_array($var_names) && count($var_names) > 1)
  9155.  
  9156. $name = get_the_title($product_id) . ': ' . $var_names[$variation];
  9157.  
  9158. else
  9159.  
  9160. $name = get_the_title($product_id);
  9161.  
  9162.  
  9163.  
  9164. $subject = __('Low Product Inventory Notification', 'mp');
  9165.  
  9166. $msg = __('This message is being sent to notify you of low stock of a product in your online store according to your preferences.
  9167.  
  9168.  
  9169.  
  9170. Product: %s
  9171.  
  9172. Current Inventory: %s
  9173.  
  9174. Link: %s
  9175.  
  9176.  
  9177.  
  9178. Edit Product: %s
  9179.  
  9180. Notification Preferences: %s', 'mp');
  9181.  
  9182. $msg = sprintf($msg, $name, number_format_i18n($stock), get_permalink($product_id), get_edit_post_link($product_id), admin_url('edit.php?post_type=product&page=marketpress#mp-inventory-setting'));
  9183.  
  9184. $msg = apply_filters( 'mp_low_stock_notification', $msg, $product_id );
  9185.  
  9186. $store_email = $this->get_setting('store_email') ? $this->get_setting('store_email') : get_option("admin_email");
  9187.  
  9188. $this->mail($store_email, $subject, $msg);
  9189.  
  9190.  
  9191.  
  9192. //save so we don't send an email every time
  9193.  
  9194. update_post_meta($product_id, 'mp_stock_email_sent', 1);
  9195.  
  9196. }
  9197.  
  9198.  
  9199.  
  9200. //round and display currency with padded zeros
  9201.  
  9202. function display_currency( $amount ) {
  9203.  
  9204.  
  9205.  
  9206. if ( $this->get_setting('curr_decimal') === '0' )
  9207.  
  9208. return number_format( round( $amount ), 0, '.', '');
  9209.  
  9210. else
  9211.  
  9212. return number_format( round( $amount, 2 ), 2, '.', '');
  9213.  
  9214. }
  9215.  
  9216.  
  9217.  
  9218. //display currency symbol
  9219.  
  9220. function format_currency($currency = '', $amount = false) {
  9221.  
  9222.  
  9223.  
  9224. if (!$currency)
  9225.  
  9226. $currency = $this->get_setting('currency', 'USD');
  9227.  
  9228.  
  9229.  
  9230. // get the currency symbol
  9231.  
  9232. $symbol = $this->currencies[$currency][1];
  9233.  
  9234. // if many symbols are found, rebuild the full symbol
  9235.  
  9236. $symbols = explode(', ', $symbol);
  9237.  
  9238. if (is_array($symbols)) {
  9239.  
  9240. $symbol = "";
  9241.  
  9242. foreach ($symbols as $temp) {
  9243.  
  9244. $symbol .= '&#x'.$temp.';';
  9245.  
  9246. }
  9247.  
  9248. } else {
  9249.  
  9250. $symbol = '&#x'.$symbol.';';
  9251.  
  9252. }
  9253.  
  9254.  
  9255.  
  9256. //check decimal option
  9257.  
  9258. if ( $this->get_setting('curr_decimal') === '0' ) {
  9259.  
  9260. $decimal_place = 0;
  9261.  
  9262. $zero = '0';
  9263.  
  9264. } else {
  9265.  
  9266. $decimal_place = 2;
  9267.  
  9268. $zero = '0.00';
  9269.  
  9270. }
  9271.  
  9272.  
  9273.  
  9274. //format currency amount according to preference
  9275.  
  9276. if ($amount) {
  9277.  
  9278.  
  9279.  
  9280. if ($this->get_setting('curr_symbol_position') == 1 || !$this->get_setting('curr_symbol_position'))
  9281.  
  9282. return $symbol . number_format_i18n($amount, $decimal_place);
  9283.  
  9284. else if ($this->get_setting('curr_symbol_position') == 2)
  9285.  
  9286. return $symbol . ' ' . number_format_i18n($amount, $decimal_place);
  9287.  
  9288. else if ($this->get_setting('curr_symbol_position') == 3)
  9289.  
  9290. return number_format_i18n($amount, $decimal_place) . $symbol;
  9291.  
  9292. else if ($this->get_setting('curr_symbol_position') == 4)
  9293.  
  9294. return number_format_i18n($amount, $decimal_place) . ' ' . $symbol;
  9295.  
  9296.  
  9297.  
  9298. } else if ($amount === false) {
  9299.  
  9300. return $symbol;
  9301.  
  9302. } else {
  9303.  
  9304. if ($this->get_setting('curr_symbol_position') == 1 || !$this->get_setting('curr_symbol_position'))
  9305.  
  9306. return $symbol . $zero;
  9307.  
  9308. else if ($this->get_setting('curr_symbol_position') == 2)
  9309.  
  9310. return $symbol . ' ' . $zero;
  9311.  
  9312. else if ($this->get_setting('curr_symbol_position') == 3)
  9313.  
  9314. return $zero . $symbol;
  9315.  
  9316. else if ($this->get_setting('curr_symbol_position') == 4)
  9317.  
  9318. return $zero . ' ' . $symbol;
  9319.  
  9320. }
  9321.  
  9322. }
  9323.  
  9324.  
  9325.  
  9326. //translates a gmt timestamp into local timezone for display
  9327.  
  9328. function format_date($gmt_timestamp) {
  9329.  
  9330. return date_i18n( get_option('date_format') . ' - ' . get_option('time_format'), $gmt_timestamp + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
  9331.  
  9332. }
  9333.  
  9334.  
  9335.  
  9336. //replaces wp_trim_excerpt in our custom loops
  9337.  
  9338. function product_excerpt($excerpt, $content, $product_id, $excerpt_more = null) {
  9339.  
  9340. if (is_null($excerpt_more))
  9341.  
  9342. $excerpt_more = ' <a class="mp_product_more_link" href="' . get_permalink($product_id) . '">' . __('More Info &raquo;', 'mp') . '</a>';
  9343.  
  9344. if ($excerpt) {
  9345.  
  9346. return apply_filters('get_the_excerpt', $excerpt) . $excerpt_more;
  9347.  
  9348. } else {
  9349.  
  9350. $text = strip_shortcodes( $content );
  9351.  
  9352. //$text = apply_filters('the_content', $text);
  9353.  
  9354. $text = str_replace(']]>', ']]&gt;', $text);
  9355.  
  9356. $text = strip_tags($text);
  9357.  
  9358. $excerpt_length = apply_filters('excerpt_length', 55);
  9359.  
  9360. $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
  9361.  
  9362. if ( count($words) > $excerpt_length ) {
  9363.  
  9364. array_pop($words);
  9365.  
  9366. $text = implode(' ', $words);
  9367.  
  9368. $text = $text . $excerpt_more;
  9369.  
  9370. } else {
  9371.  
  9372. $text = implode(' ', $words);
  9373.  
  9374. }
  9375.  
  9376. }
  9377.  
  9378. return $text;
  9379.  
  9380. }
  9381.  
  9382.  
  9383.  
  9384. //returns the js needed to record ecommerce transactions. $project should be an array of id, title
  9385.  
  9386. function create_ga_ecommerce($order) {
  9387.  
  9388.  
  9389.  
  9390. if (!is_object($order))
  9391.  
  9392. return false;
  9393.  
  9394.  
  9395.  
  9396. //so that certain products can be excluded from tracking
  9397.  
  9398. $order = apply_filters( 'mp_ga_ecommerce', $order );
  9399.  
  9400.  
  9401.  
  9402. if ($this->get_setting('ga_ecommerce') == 'old') {
  9403.  
  9404.  
  9405.  
  9406. $js = '<script type="text/javascript">
  9407.  
  9408. try{
  9409.  
  9410. pageTracker._addTrans(
  9411.  
  9412. "'.esc_js($order->post_title).'", // order ID - required
  9413.  
  9414. "'.esc_js(get_bloginfo('blogname')).'", // affiliation or store name
  9415.  
  9416. "'.$order->mp_order_total.'", // total - required
  9417.  
  9418. "'.$order->mp_tax_total.'", // tax
  9419.  
  9420. "'.$order->mp_shipping_total.'", // shipping
  9421.  
  9422. "'.esc_js($order->mp_shipping_info['city']).'", // city
  9423.  
  9424. "'.esc_js($order->mp_shipping_info['state']).'", // state or province
  9425.  
  9426. "'.esc_js($order->mp_shipping_info['country']).'" // country
  9427.  
  9428. );';
  9429.  
  9430.  
  9431.  
  9432. if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) {
  9433.  
  9434. foreach ($order->mp_cart_info as $product_id => $variations) {
  9435.  
  9436. foreach ($variations as $variation => $data) {
  9437.  
  9438. $sku = !empty($data['SKU']) ? esc_js($data['SKU']) : $product_id;
  9439.  
  9440. $js .= 'pageTracker._addItem(
  9441.  
  9442. "'.esc_js($order->post_title).'", // order ID - necessary to associate item with transaction
  9443.  
  9444. "'.$sku.'", // SKU/code - required
  9445.  
  9446. "'.esc_js($data['name']).'", // product name
  9447.  
  9448. "'.$data['price'].'", // unit price - required
  9449.  
  9450. "'.$data['quantity'].'" // quantity - required
  9451.  
  9452. );';
  9453.  
  9454. }
  9455.  
  9456. }
  9457.  
  9458. }
  9459.  
  9460. $js .= 'pageTracker._trackTrans(); //submits transaction to the Analytics servers
  9461.  
  9462. } catch(err) {}
  9463.  
  9464. </script>
  9465.  
  9466. ';
  9467.  
  9468.  
  9469.  
  9470. } else if ($this->get_setting('ga_ecommerce') == 'new') {
  9471.  
  9472.  
  9473.  
  9474. $js = '<script type="text/javascript">
  9475.  
  9476. _gaq.push(["_addTrans",
  9477.  
  9478. "'.esc_attr($order->post_title).'", // order ID - required
  9479.  
  9480. "'.esc_attr(get_bloginfo('blogname')).'", // affiliation or store name
  9481.  
  9482. "'.$order->mp_order_total.'", // total - required
  9483.  
  9484. "'.$order->mp_tax_total.'", // tax
  9485.  
  9486. "'.$order->mp_shipping_total.'", // shipping
  9487.  
  9488. "'.esc_attr($order->mp_shipping_info['city']).'", // city
  9489.  
  9490. "'.esc_attr($order->mp_shipping_info['state']).'", // state or province
  9491.  
  9492. "'.esc_attr($order->mp_shipping_info['country']).'" // country
  9493.  
  9494. ]);';
  9495.  
  9496.  
  9497.  
  9498. if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) {
  9499.  
  9500. foreach ($order->mp_cart_info as $product_id => $variations) {
  9501.  
  9502. foreach ($variations as $variation => $data) {
  9503.  
  9504. $sku = !empty($data['SKU']) ? esc_attr($data['SKU']) : $product_id;
  9505.  
  9506. $js .= '_gaq.push(["_addItem",
  9507.  
  9508. "'.esc_attr($order->post_title).'", // order ID - necessary to associate item with transaction
  9509.  
  9510. "'.$sku.'", // SKU/code - required
  9511.  
  9512. "'.esc_attr($data['name']).'", // product name
  9513.  
  9514. "", // category
  9515.  
  9516. "'.$data['price'].'", // unit price - required
  9517.  
  9518. "'.$data['quantity'].'" // quantity - required
  9519.  
  9520. ]);';
  9521.  
  9522. }
  9523.  
  9524. }
  9525.  
  9526. }
  9527.  
  9528. $js .= '_gaq.push(["_trackTrans"]);
  9529.  
  9530. </script>
  9531.  
  9532. ';
  9533.  
  9534.  
  9535.  
  9536. //add info for subblog if our GA plugin is installed
  9537.  
  9538. if (class_exists('Google_Analytics_Async')) {
  9539.  
  9540.  
  9541.  
  9542. $js = '<script type="text/javascript">
  9543.  
  9544. _gaq.push(["b._addTrans",
  9545.  
  9546. "'.esc_attr($order->post_title).'", // order ID - required
  9547.  
  9548. "'.esc_attr(get_bloginfo('blogname')).'", // affiliation or store name
  9549.  
  9550. "'.$order->mp_order_total.'", // total - required
  9551.  
  9552. "'.$order->mp_tax_total.'", // tax
  9553.  
  9554. "'.$order->mp_shipping_total.'", // shipping
  9555.  
  9556. "'.esc_attr($order->mp_shipping_info['city']).'", // city
  9557.  
  9558. "'.esc_attr($order->mp_shipping_info['state']).'", // state or province
  9559.  
  9560. "'.esc_attr($order->mp_shipping_info['country']).'" // country
  9561.  
  9562. ]);';
  9563.  
  9564.  
  9565.  
  9566. if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) {
  9567.  
  9568. foreach ($order->mp_cart_info as $product_id => $variations) {
  9569.  
  9570. foreach ($variations as $variation => $data) {
  9571.  
  9572. $sku = !empty($data['SKU']) ? esc_attr($data['SKU']) : $product_id;
  9573.  
  9574. $js .= '_gaq.push(["b._addItem",
  9575.  
  9576. "'.esc_attr($order->post_title).'", // order ID - necessary to associate item with transaction
  9577.  
  9578. "'.$sku.'", // SKU/code - required
  9579.  
  9580. "'.esc_attr($data['name']).'", // product name
  9581.  
  9582. "", // category
  9583.  
  9584. "'.$data['price'].'", // unit price - required
  9585.  
  9586. "'.$data['quantity'].'" // quantity - required
  9587.  
  9588. ]);';
  9589.  
  9590. }
  9591.  
  9592. }
  9593.  
  9594. }
  9595.  
  9596. $js .= '_gaq.push(["b._trackTrans"]);
  9597.  
  9598. </script>
  9599.  
  9600. ';
  9601.  
  9602. }
  9603.  
  9604.  
  9605.  
  9606. } else if( $this->get_setting('ga_ecommerce') == 'universal' ) {
  9607.  
  9608. // add the UA code
  9609.  
  9610.  
  9611.  
  9612. $js = '<script type="text/javascript">
  9613.  
  9614. ga("require", "ecommerce", "ecommerce.js");
  9615.  
  9616. ga("ecommerce:addTransaction", {
  9617.  
  9618. "id": "'.esc_attr($order->post_title).'", // Transaction ID. Required.
  9619.  
  9620. "affiliation": "'.esc_attr(get_bloginfo('blogname')).'", // Affiliation or store name.
  9621.  
  9622. "revenue": "'.$order->mp_order_total.'", // Grand Total.
  9623.  
  9624. "shipping": "'.$order->mp_shipping_total.'", // Shipping.
  9625.  
  9626. "tax": "'.$order->mp_tax_total.'" // Tax.
  9627.  
  9628. });';
  9629.  
  9630. //loop the items
  9631.  
  9632. if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) {
  9633.  
  9634. foreach ($order->mp_cart_info as $product_id => $variations) {
  9635.  
  9636. foreach ($variations as $variation => $data) {
  9637.  
  9638. $sku = !empty($data['SKU']) ? esc_attr($data['SKU']) : $product_id;
  9639.  
  9640. $js .= 'ga("ecommerce:addItem", {
  9641.  
  9642. "id": "'.esc_attr($order->post_title).'", // Transaction ID. Required.
  9643.  
  9644. "name": "'.esc_attr($data['name']).'", // Product name. Required.
  9645.  
  9646. "sku": "'.$sku.'", // SKU/code.
  9647.  
  9648. "category": "", // Category or variation.
  9649.  
  9650. "price": "'.$data['price'].'", // Unit price.
  9651.  
  9652. "quantity": "'.$data['quantity'].'" // Quantity.
  9653.  
  9654. });';
  9655.  
  9656. }
  9657.  
  9658. }
  9659.  
  9660. }
  9661.  
  9662.  
  9663.  
  9664. $js .='ga("ecommerce:send");<script>';
  9665.  
  9666. }
  9667.  
  9668.  
  9669.  
  9670. //add to footer
  9671.  
  9672. if ( !empty($js) ) {
  9673.  
  9674. $function = "echo '$js';";
  9675.  
  9676. add_action( 'wp_footer', create_function('', $function), 99999 );
  9677.  
  9678. }
  9679.  
  9680. }
  9681.  
  9682.  
  9683.  
  9684. //displays the detail page of an order
  9685.  
  9686. function single_order_page() {
  9687.  
  9688. $order = $this->get_order((int)$_GET['order_id']);
  9689.  
  9690.  
  9691.  
  9692. if ( !$order )
  9693.  
  9694. wp_die(__('Invalid Order ID', 'mp'));
  9695.  
  9696.  
  9697.  
  9698. $max_downloads = $this->get_setting('max_downloads', 5);
  9699.  
  9700.  
  9701.  
  9702. //save tracking number
  9703.  
  9704. if (isset($_POST['mp_tracking_number'])) {
  9705.  
  9706. $order->mp_shipping_info['tracking_num'] = stripslashes(trim($_POST['mp_tracking_number']));
  9707.  
  9708. $order->mp_shipping_info['method'] = stripslashes(trim($_POST['mp_shipping_method']));
  9709.  
  9710. update_post_meta($order->ID, 'mp_shipping_info', $order->mp_shipping_info);
  9711.  
  9712.  
  9713.  
  9714. if (isset($_POST['add-tracking-shipped'])) {
  9715.  
  9716. $this->update_order_status($order->ID, 'shipped');
  9717.  
  9718. $order->post_status = 'order_shipped';
  9719.  
  9720. ?><div class="updated fade"><p><?php _e('This order has been marked as Shipped.', 'mp'); ?></p></div><?php
  9721.  
  9722. }
  9723.  
  9724.  
  9725.  
  9726. if (!current_user_can('unfiltered_html'))
  9727.  
  9728. $_POST['mp_order_notes'] = wp_filter_post_kses(trim(stripslashes($_POST['mp_order_notes'])));
  9729.  
  9730.  
  9731.  
  9732. $order->mp_order_notes = stripslashes($_POST['mp_order_notes']);
  9733.  
  9734. update_post_meta($order->ID, 'mp_order_notes', $_POST['mp_order_notes']);
  9735.  
  9736. ?><div class="updated fade"><p><?php _e('Order details have been saved!', 'mp'); ?></p></div><?php
  9737.  
  9738. }
  9739.  
  9740. ?>
  9741.  
  9742. <div class="wrap">
  9743.  
  9744. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/shopping-cart.png'; ?>" /></div>
  9745.  
  9746. <h2><?php echo sprintf(__('Order Details (%s)', 'mp'), esc_attr($order->post_title)); ?></h2>
  9747.  
  9748.  
  9749.  
  9750. <div id="poststuff" class="metabox-holder mp-settings has-right-sidebar">
  9751.  
  9752.  
  9753.  
  9754. <div id="side-info-column" class="inner-sidebar">
  9755.  
  9756. <div id='side-sortables' class='meta-box-sortables'>
  9757.  
  9758.  
  9759.  
  9760. <div id="submitdiv" class="postbox mp-order-actions">
  9761.  
  9762. <h3 class='hndle'><span><?php _e('Order Actions', 'mp'); ?></span></h3>
  9763.  
  9764. <div class="inside">
  9765.  
  9766. <div id="submitpost" class="submitbox">
  9767.  
  9768. <div class="misc-pub-section"><strong><?php _e('Change Order Status:', 'mp'); ?></strong></div>
  9769.  
  9770. <?php
  9771.  
  9772. $actions = array();
  9773.  
  9774. if ($order->post_status == 'order_received') {
  9775.  
  9776. $actions['received current'] = __('Received', 'mp');
  9777.  
  9778. $actions['paid'] = "<a title='" . esc_attr(__('Mark as Paid', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=paid&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Paid', 'mp') . "</a>";
  9779.  
  9780. $actions['shipped'] = "<a title='" . esc_attr(__('Mark as Shipped', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=shipped&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Shipped', 'mp') . "</a>";
  9781.  
  9782. $actions['closed'] = "<a title='" . esc_attr(__('Mark as Closed', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=closed&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Closed', 'mp') . "</a>";
  9783.  
  9784. $actions['trash'] = "<a title='" . esc_attr(__('Trash', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=trash&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Trash', 'mp') . "</a>";
  9785.  
  9786. } else if ($order->post_status == 'order_paid') {
  9787.  
  9788. $actions['received'] = __('Received', 'mp');
  9789.  
  9790. $actions['paid current'] = __('Paid', 'mp');
  9791.  
  9792. $actions['shipped'] = "<a title='" . esc_attr(__('Mark as Shipped', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=shipped&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Shipped', 'mp') . "</a>";
  9793.  
  9794. $actions['closed'] = "<a title='" . esc_attr(__('Mark as Closed', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=closed&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Closed', 'mp') . "</a>";
  9795.  
  9796. $actions['trash'] = "<a title='" . esc_attr(__('Trash', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=trash&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Trash', 'mp') . "</a>";
  9797.  
  9798. } else if ($order->post_status == 'order_shipped') {
  9799.  
  9800. $actions['received'] = __('Received', 'mp');
  9801.  
  9802. $actions['paid'] = __('Paid', 'mp');
  9803.  
  9804. $actions['shipped current'] = __('Shipped', 'mp');
  9805.  
  9806. $actions['closed'] = "<a title='" . esc_attr(__('Mark as Closed', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=closed&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Closed', 'mp') . "</a>";
  9807.  
  9808. $actions['trash'] = "<a title='" . esc_attr(__('Trash', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=trash&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Trash', 'mp') . "</a>";
  9809.  
  9810. } else if ($order->post_status == 'order_closed') {
  9811.  
  9812. $actions['received'] = "<a title='" . esc_attr(__('Mark as Received', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=received&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Received', 'mp') . "</a>";
  9813.  
  9814. $actions['paid'] = "<a title='" . esc_attr(__('Mark as Paid', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=paid&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Paid', 'mp') . "</a>";
  9815.  
  9816. $actions['shipped'] = "<a title='" . esc_attr(__('Mark as Shipped', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=shipped&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Shipped', 'mp') . "</a>";
  9817.  
  9818. $actions['closed current'] = __('Closed', 'mp');
  9819.  
  9820. $actions['trash'] = "<a title='" . esc_attr(__('Trash', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=trash&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Trash', 'mp') . "</a>";
  9821.  
  9822. } else if ($order->post_status == "trash") {
  9823.  
  9824. $actions['received'] = "<a title='" . esc_attr(__('Mark as Received', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=received&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Received', 'mp') . "</a>";
  9825.  
  9826. $actions['paid'] = "<a title='" . esc_attr(__('Mark as Paid', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=paid&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Paid', 'mp') . "</a>";
  9827.  
  9828. $actions['shipped'] = "<a title='" . esc_attr(__('Mark as Shipped', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=shipped&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Shipped', 'mp') . "</a>";
  9829.  
  9830. $actions['closed'] = "<a title='" . esc_attr(__('Mark as Closed', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=closed&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Closed', 'mp') . "</a>";
  9831.  
  9832. $actions['delete'] = "<a title='" . esc_attr(__('Delete', 'mp')) . "' href='" . wp_nonce_url( admin_url( 'edit.php?post_type=product&amp;page=marketpress-orders&amp;action=delete&amp;post=' . $order->ID), 'update-order-status' ) . "'>" . __('Delete', 'mp') . "</a>";
  9833.  
  9834.  
  9835.  
  9836. }
  9837.  
  9838.  
  9839.  
  9840. $action_count = count($actions);
  9841.  
  9842. $i = 0;
  9843.  
  9844. echo '<div id="mp-single-statuses" class="misc-pub-section">';
  9845.  
  9846. foreach ( $actions as $action => $link ) {
  9847.  
  9848. ++$i;
  9849.  
  9850. ( $i == $action_count ) ? $sep = '' : $sep = ' &raquo; ';
  9851.  
  9852. echo "<span class='$action'>$link</span>$sep";
  9853.  
  9854. }
  9855.  
  9856. echo '</div>';
  9857.  
  9858. ?>
  9859.  
  9860.  
  9861.  
  9862. <div id="major-publishing-actions">
  9863.  
  9864. <form id="mp-single-order-form" action="<?php echo admin_url('edit.php'); ?>" method="get">
  9865.  
  9866. <div id="mp-single-order-buttons">
  9867.  
  9868. <input type="hidden" name="post_type" class="post_status_page" value="product" />
  9869.  
  9870. <input type="hidden" name="page" class="post_status_page" value="marketpress-orders" />
  9871.  
  9872. <input name="save" class="button-primary" id="publish" tabindex="1" value="<?php _e('&laquo; Back', 'mp'); ?>" type="submit" />
  9873.  
  9874. </div>
  9875.  
  9876. </form>
  9877.  
  9878. <div class="clear"></div>
  9879.  
  9880. </div>
  9881.  
  9882. </div>
  9883.  
  9884. </div>
  9885.  
  9886. </div>
  9887.  
  9888.  
  9889.  
  9890. <div id="mp-order-status" class="postbox">
  9891.  
  9892. <h3 class='hndle'><span><?php _e('Current Status', 'mp'); ?></span></h3>
  9893.  
  9894. <div class="inside">
  9895.  
  9896. <?php
  9897.  
  9898. //get times
  9899.  
  9900. $received = $this->format_date($order->mp_received_time);
  9901.  
  9902. if (isset($order->mp_paid_time) && $order->mp_paid_time)
  9903.  
  9904. $paid = $this->format_date($order->mp_paid_time);
  9905.  
  9906. if (isset($order->mp_shipped_time) && $order->mp_shipped_time)
  9907.  
  9908. $shipped = $this->format_date($order->mp_shipped_time);
  9909.  
  9910. if (isset($order->mp_closed_time) && $order->mp_closed_time)
  9911.  
  9912. $closed = $this->format_date($order->mp_closed_time);
  9913.  
  9914.  
  9915.  
  9916. if ($order->post_status == 'order_received') {
  9917.  
  9918. echo '<div id="major-publishing-actions" class="misc-pub-section">' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></div>';
  9919.  
  9920. } else if ($order->post_status == 'order_paid') {
  9921.  
  9922. echo '<div id="major-publishing-actions" class="misc-pub-section">' . __('Paid:', 'mp') . ' <strong>' . $paid . '</strong></div>';
  9923.  
  9924. echo '<div class="misc-pub-section">' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></div>';
  9925.  
  9926. } else if ($order->post_status == 'order_shipped') {
  9927.  
  9928. echo '<div id="major-publishing-actions" class="misc-pub-section">' . __('Shipped:', 'mp') . ' <strong>' . $shipped . '</strong></div>';
  9929.  
  9930. echo '<div class="misc-pub-section">' . __('Paid:', 'mp') . ' <strong>' . $paid . '</strong></div>';
  9931.  
  9932. echo '<div class="misc-pub-section">' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></div>';
  9933.  
  9934. } else if ($order->post_status == 'order_closed') {
  9935.  
  9936. echo '<div id="major-publishing-actions" class="misc-pub-section">' . __('Closed:', 'mp') . ' <strong>' . $closed . '</strong></div>';
  9937.  
  9938. echo '<div class="misc-pub-section">' . __('Shipped:', 'mp') . ' <strong>' . $shipped . '</strong></div>';
  9939.  
  9940. echo '<div class="misc-pub-section">' . __('Paid:', 'mp') . ' <strong>' . $paid . '</strong></div>';
  9941.  
  9942. echo '<div class="misc-pub-section">' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></div>';
  9943.  
  9944. } else if ($order->post_status == 'trash') {
  9945.  
  9946. echo '<div id="major-publishing-actions" class="misc-pub-section">' . __('Trashed', 'mp') . '</div>';
  9947.  
  9948. }
  9949.  
  9950.  
  9951.  
  9952. ?>
  9953.  
  9954. </div>
  9955.  
  9956. </div>
  9957.  
  9958.  
  9959.  
  9960. <div id="mp-order-payment" class="postbox">
  9961.  
  9962. <h3 class='hndle'><span><?php _e('Payment Information', 'mp'); ?></span></h3>
  9963.  
  9964. <div class="inside">
  9965.  
  9966. <div id="mp_payment_gateway" class="misc-pub-section">
  9967.  
  9968. <?php _e('Payment Gateway:', 'mp'); ?>
  9969.  
  9970. <strong><?php echo $order->mp_payment_info['gateway_private_name']; ?></strong>
  9971.  
  9972. </div>
  9973.  
  9974. <?php if ($order->mp_payment_info['method']) { ?>
  9975.  
  9976. <div id="mp_payment_method" class="misc-pub-section">
  9977.  
  9978. <?php _e('Payment Type:', 'mp'); ?>
  9979.  
  9980. <strong><?php echo $order->mp_payment_info['method']; ?></strong>
  9981.  
  9982. </div>
  9983.  
  9984. <?php } ?>
  9985.  
  9986. <?php if ($order->mp_payment_info['transaction_id']) { ?>
  9987.  
  9988. <div id="mp_transaction" class="misc-pub-section">
  9989.  
  9990. <?php _e('Transaction ID:', 'mp'); ?>
  9991.  
  9992. <strong><?php echo $order->mp_payment_info['transaction_id']; ?></strong>
  9993.  
  9994. </div>
  9995.  
  9996. <?php } ?>
  9997.  
  9998. <div id="major-publishing-actions" class="misc-pub-section">
  9999.  
  10000. <?php _e('Payment Total:', 'mp'); ?>
  10001.  
  10002. <strong><?php echo $this->format_currency($order->mp_payment_info['currency'], $order->mp_payment_info['total']) . ' ' . $order->mp_payment_info['currency']; ?></strong>
  10003.  
  10004. </div>
  10005.  
  10006. </div>
  10007.  
  10008. </div>
  10009.  
  10010.  
  10011.  
  10012. <?php if (is_array($order->mp_payment_info['status']) && count($order->mp_payment_info['status'])) { ?>
  10013.  
  10014. <div id="mp-order-payment-history" class="postbox">
  10015.  
  10016. <h3 class='hndle'><span><?php _e('Payment Transaction History', 'mp'); ?></span></h3>
  10017.  
  10018. <div class="inside">
  10019.  
  10020. <?php
  10021.  
  10022. $statuses = $order->mp_payment_info['status'];
  10023.  
  10024. krsort($statuses); //sort with latest status at the top
  10025.  
  10026. $first = true;
  10027.  
  10028. foreach ($statuses as $timestamp => $status) {
  10029.  
  10030. if ($first) {
  10031.  
  10032. echo '<div id="major-publishing-actions" class="misc-pub-section">';
  10033.  
  10034. $first = false;
  10035.  
  10036. } else {
  10037.  
  10038. echo '<div id="mp_payment_gateway" class="misc-pub-section">';
  10039.  
  10040. }
  10041.  
  10042. ?>
  10043.  
  10044. <strong><?php echo $this->format_date($timestamp); ?>:</strong>
  10045.  
  10046. <?php echo esc_html($status); ?>
  10047.  
  10048. </div>
  10049.  
  10050. <?php } ?>
  10051.  
  10052.  
  10053.  
  10054. </div>
  10055.  
  10056. </div>
  10057.  
  10058. <?php } ?>
  10059.  
  10060.  
  10061.  
  10062. </div></div>
  10063.  
  10064.  
  10065.  
  10066. <div id="post-body">
  10067.  
  10068. <div id="post-body-content">
  10069.  
  10070.  
  10071.  
  10072. <div id='normal-sortables' class='meta-box-sortables'>
  10073.  
  10074.  
  10075.  
  10076. <div id="mp-order-products" class="postbox">
  10077.  
  10078. <h3 class='hndle'><span><?php _e('Order Information', 'mp'); ?></span></h3>
  10079.  
  10080. <div class="inside">
  10081.  
  10082.  
  10083.  
  10084. <table id="mp-order-product-table" class="widefat">
  10085.  
  10086. <thead><tr>
  10087.  
  10088. <th class="mp_cart_col_thumb">&nbsp;</th>
  10089.  
  10090. <th class="mp_cart_col_sku"><?php _e('SKU', 'mp'); ?></th>
  10091.  
  10092. <th class="mp_cart_col_product"><?php _e('Item', 'mp'); ?></th>
  10093.  
  10094. <th class="mp_cart_col_quant"><?php _e('Quantity', 'mp'); ?></th>
  10095.  
  10096. <th class="mp_cart_col_price"><?php _e('Price', 'mp'); ?></th>
  10097.  
  10098. <th class="mp_cart_col_subtotal"><?php _e('Subtotal', 'mp'); ?></th>
  10099.  
  10100. <th class="mp_cart_col_downloads"><?php _e('Downloads', 'mp'); ?></th>
  10101.  
  10102. </tr></thead>
  10103.  
  10104. <tbody>
  10105.  
  10106. <?php
  10107.  
  10108. global $blog_id;
  10109.  
  10110. $bid = (is_multisite()) ? $blog_id : 1; // FPM
  10111.  
  10112.  
  10113.  
  10114. if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) {
  10115.  
  10116. foreach ($order->mp_cart_info as $product_id => $variations) {
  10117.  
  10118. //for compatibility for old orders from MP 1.0
  10119.  
  10120. if (isset($variations['name'])) {
  10121.  
  10122. $data = $variations;
  10123.  
  10124. echo '<tr>';
  10125.  
  10126. echo ' <td class="mp_cart_col_thumb">' . mp_product_image( false, 'widget', $product_id ) . '</td>';
  10127.  
  10128. echo ' <td class="mp_cart_col_sku">' . esc_attr($data['SKU']) . '</td>';
  10129.  
  10130. echo ' <td class="mp_cart_col_product"><a href="' . get_permalink($product_id) . '">' . esc_attr($data['name']) . '</a></td>';
  10131.  
  10132. echo ' <td class="mp_cart_col_quant">' . number_format_i18n($data['quantity']) . '</td>';
  10133.  
  10134. echo ' <td class="mp_cart_col_price">' . $this->format_currency('', $data['price']) . '</td>';
  10135.  
  10136. echo ' <td class="mp_cart_col_subtotal">' . $this->format_currency('', $data['price'] * $data['quantity']) . '</td>';
  10137.  
  10138. echo ' <td class="mp_cart_col_downloads">' . __('N/A', 'mp') . '</td>';
  10139.  
  10140. echo '</tr>';
  10141.  
  10142. } else {
  10143.  
  10144. foreach ($variations as $variation => $data) {
  10145.  
  10146. echo '<tr>';
  10147.  
  10148. echo ' <td class="mp_cart_col_thumb">' . mp_product_image( false, 'widget', $product_id ) . '</td>';
  10149.  
  10150. echo ' <td class="mp_cart_col_sku">' . esc_attr($data['SKU']) . '</td>';
  10151.  
  10152. echo ' <td class="mp_cart_col_product"><a href="' . get_permalink($product_id) . '">' . esc_attr($data['name']) . '</a>';
  10153.  
  10154.  
  10155.  
  10156. //Output product custom field information
  10157.  
  10158. $cf_key = $bid .':'. $product_id .':'. $variation;
  10159.  
  10160. if (isset($order->mp_shipping_info['mp_custom_fields'][$cf_key])) {
  10161.  
  10162. $cf_item = $order->mp_shipping_info['mp_custom_fields'][$cf_key];
  10163.  
  10164.  
  10165.  
  10166. $mp_custom_field_label = get_post_meta($product_id, 'mp_custom_field_label', true);
  10167.  
  10168. if (isset($mp_custom_field_label[$variation]))
  10169.  
  10170. $label_text = esc_attr($mp_custom_field_label[$variation]);
  10171.  
  10172. else
  10173.  
  10174. $label_text = __('Product Personalization:', 'mp');
  10175.  
  10176.  
  10177.  
  10178. echo '<div class="mp_cart_custom_fields">'. $label_text .'<ol>';
  10179.  
  10180. foreach ($cf_item as $item) {
  10181.  
  10182. echo '<li>'. $item .'</li>';
  10183.  
  10184. }
  10185.  
  10186. echo '</ol></div>';
  10187.  
  10188. }
  10189.  
  10190.  
  10191.  
  10192. echo '</td>';
  10193.  
  10194. echo ' <td class="mp_cart_col_quant">' . number_format_i18n($data['quantity']) . '</td>';
  10195.  
  10196. echo ' <td class="mp_cart_col_price">' . $this->format_currency('', $data['price']) . '</td>';
  10197.  
  10198. echo ' <td class="mp_cart_col_subtotal">' . $this->format_currency('', $data['price'] * $data['quantity']) . '</td>';
  10199.  
  10200. if (is_array($data['download']))
  10201.  
  10202. echo ' <td class="mp_cart_col_downloads">' . number_format_i18n($data['download']['downloaded']) . (($data['download']['downloaded'] >= $max_downloads) ? __(' (Limit Reached)', 'mp') : '') . '</td>';
  10203.  
  10204. else
  10205.  
  10206. echo ' <td class="mp_cart_col_downloads">' . __('N/A', 'mp') . '</td>';
  10207.  
  10208. echo '</tr>';
  10209.  
  10210. }
  10211.  
  10212. }
  10213.  
  10214. }
  10215.  
  10216. } else {
  10217.  
  10218. echo '<tr><td colspan="7">' . __('No products could be found for this order', 'mp') . '</td></tr>';
  10219.  
  10220. }
  10221.  
  10222. ?>
  10223.  
  10224. </tbody>
  10225.  
  10226. </table><br />
  10227.  
  10228.  
  10229.  
  10230. <?php //coupon line
  10231.  
  10232. if ( isset($order->mp_discount_info) ) { ?>
  10233.  
  10234. <h3><?php _e('Coupon Discount:', 'mp'); ?></h3>
  10235.  
  10236. <p><?php echo $order->mp_discount_info['discount']; ?> (<?php echo $order->mp_discount_info['code']; ?>)</p>
  10237.  
  10238. <?php } ?>
  10239.  
  10240.  
  10241.  
  10242. <?php //shipping line
  10243.  
  10244. if ( $order->mp_shipping_total ) { ?>
  10245.  
  10246. <h3><?php _e('Shipping:', 'mp'); ?></h3>
  10247.  
  10248. <p><?php echo $this->format_currency('', $order->mp_shipping_total) . ' ( ' . strtoupper(isset($order->mp_shipping_info['shipping_option']) ? $order->mp_shipping_info['shipping_option'] : '') . ' ' . (isset($order->mp_shipping_info['shipping_sub_option']) ? $order->mp_shipping_info['shipping_sub_option'] : '') . ' )'; ?></p>
  10249.  
  10250. <?php } ?>
  10251.  
  10252.  
  10253.  
  10254. <?php //tax line
  10255.  
  10256. if ( $order->mp_tax_total ) { ?>
  10257.  
  10258. <h3><?php echo esc_html($this->get_setting('tax->label', __('Taxes', 'mp'))); ?>:</h3>
  10259.  
  10260. <p><?php echo $this->format_currency('', $order->mp_tax_total); ?></p>
  10261.  
  10262. <?php } ?>
  10263.  
  10264.  
  10265.  
  10266. <h3><?php _e('Cart Total:', 'mp'); ?></h3>
  10267.  
  10268. <p><?php echo $this->format_currency('', $order->mp_order_total); ?></p>
  10269.  
  10270.  
  10271.  
  10272. <?php //special instructions line
  10273.  
  10274. if ( !empty($order->mp_shipping_info['special_instructions']) ) { ?>
  10275.  
  10276. <h3><?php _e('Special Instructions:', 'mp'); ?></h3>
  10277.  
  10278. <p><?php echo wpautop(esc_html($order->mp_shipping_info['special_instructions'])); ?></p>
  10279.  
  10280. <?php } ?>
  10281.  
  10282.  
  10283.  
  10284. </div>
  10285.  
  10286. </div>
  10287.  
  10288.  
  10289.  
  10290. <form id="mp-shipping-form" action="" method="post">
  10291.  
  10292. <div id="mp-order-shipping-info" class="postbox">
  10293.  
  10294. <h3 class='hndle'><span><?php _e('Shipping Information', 'mp'); ?></span></h3>
  10295.  
  10296. <div class="inside">
  10297.  
  10298. <h3><?php _e('Address:', 'mp'); ?></h3>
  10299.  
  10300. <table>
  10301.  
  10302. <tr>
  10303.  
  10304. <td align="right"><?php _e('Full Name:', 'mp'); ?></td><td>
  10305.  
  10306. <?php esc_attr_e($order->mp_shipping_info['name']); ?></td>
  10307.  
  10308. </tr>
  10309.  
  10310.  
  10311.  
  10312. <tr>
  10313.  
  10314. <td align="right"><?php _e('Email:', 'mp'); ?></td><td>
  10315.  
  10316. <?php esc_attr_e($order->mp_shipping_info['email']); ?></td>
  10317.  
  10318. </tr>
  10319.  
  10320.  
  10321.  
  10322. <tr>
  10323.  
  10324. <td align="right"><?php _e('Address:', 'mp'); ?></td>
  10325.  
  10326. <td><?php esc_attr_e($order->mp_shipping_info['address1']); ?></td>
  10327.  
  10328. </tr>
  10329.  
  10330.  
  10331.  
  10332. <?php if ($order->mp_shipping_info['address2']) { ?>
  10333.  
  10334. <tr>
  10335.  
  10336. <td align="right"><?php _e('Address 2:', 'mp'); ?></td>
  10337.  
  10338. <td><?php esc_attr_e($order->mp_shipping_info['address2']); ?></td>
  10339.  
  10340. </tr>
  10341.  
  10342. <?php } ?>
  10343.  
  10344.  
  10345.  
  10346. <tr>
  10347.  
  10348. <td align="right"><?php _e('City:', 'mp'); ?></td>
  10349.  
  10350. <td><?php esc_attr_e($order->mp_shipping_info['city']); ?></td>
  10351.  
  10352. </tr>
  10353.  
  10354.  
  10355.  
  10356. <?php if ($order->mp_shipping_info['state']) { ?>
  10357.  
  10358. <tr>
  10359.  
  10360. <td align="right"><?php _e('State/Province/Region:', 'mp'); ?></td>
  10361.  
  10362. <td><?php esc_attr_e($order->mp_shipping_info['state']); ?></td>
  10363.  
  10364. </tr>
  10365.  
  10366. <?php } ?>
  10367.  
  10368.  
  10369.  
  10370. <tr>
  10371.  
  10372. <td align="right"><?php _e('Postal/Zip Code:', 'mp'); ?></td>
  10373.  
  10374. <td><?php esc_attr_e($order->mp_shipping_info['zip']); ?></td>
  10375.  
  10376. </tr>
  10377.  
  10378.  
  10379.  
  10380. <tr>
  10381.  
  10382. <td align="right"><?php _e('Country:', 'mp'); ?></td>
  10383.  
  10384. <td><?php echo $this->countries[$order->mp_shipping_info['country']]; ?></td>
  10385.  
  10386. </tr>
  10387.  
  10388.  
  10389.  
  10390. <?php if ($order->mp_shipping_info['phone']) { ?>
  10391.  
  10392. <tr>
  10393.  
  10394. <td align="right"><?php _e('Phone Number:', 'mp'); ?></td>
  10395.  
  10396. <td><?php esc_attr_e($order->mp_shipping_info['phone']); ?></td>
  10397.  
  10398. </tr>
  10399.  
  10400. <?php } ?>
  10401.  
  10402. </table>
  10403.  
  10404.  
  10405.  
  10406. <h3><?php _e('Cost:', 'mp'); ?></h3>
  10407.  
  10408. <p><?php echo $this->format_currency('', $order->mp_shipping_total) . ' ( ' . strtoupper(isset($order->mp_shipping_info['shipping_option']) ? $order->mp_shipping_info['shipping_option'] : '') . ' ' . (isset($order->mp_shipping_info['shipping_sub_option']) ? $order->mp_shipping_info['shipping_sub_option'] : '') . ' )'; ?></p>
  10409.  
  10410.  
  10411.  
  10412. <h3><?php _e('Shipping Method & Tracking Number:', 'mp'); ?></h3>
  10413.  
  10414. <p>
  10415.  
  10416. <select name="mp_shipping_method">
  10417.  
  10418. <option value="other"><?php _e('Choose Method:', 'mp'); ?></option>
  10419.  
  10420. <option value="UPS"<?php selected(@$order->mp_shipping_info['method'], 'UPS'); ?>>UPS</option>
  10421.  
  10422. <option value="FedEx"<?php selected(@$order->mp_shipping_info['method'], 'FedEx'); ?>>FedEx</option>
  10423.  
  10424. <option value="USPS"<?php selected(@$order->mp_shipping_info['method'], 'USPS'); ?>>USPS</option>
  10425.  
  10426. <option value="DHL"<?php selected(@$order->mp_shipping_info['method'], 'DHL'); ?>>DHL</option>
  10427.  
  10428. <option value="other"<?php selected(@$order->mp_shipping_info['method'], 'other'); ?>><?php _e('Other', 'mp'); ?></option>
  10429.  
  10430. <?php do_action('mp_shipping_tracking_select', @$order->mp_shipping_info['method']); ?>
  10431.  
  10432. </select>
  10433.  
  10434. <input type="text" name="mp_tracking_number" value="<?php esc_attr_e(isset($order->mp_shipping_info['tracking_num']) ? $order->mp_shipping_info['tracking_num'] : ''); ?>" size="25" />
  10435.  
  10436. <input type="submit" class="button-secondary" name="add-tracking" value="<?php _e('Save &raquo;', 'mp'); ?>" /><?php if ($order->post_status == 'order_received' ||$order->post_status == 'order_paid') { ?> <input type="submit" class="button-secondary" name="add-tracking-shipped" value="<?php _e('Save & Mark as Shipped &raquo;', 'mp'); ?>" /><?php } ?>
  10437.  
  10438. </p>
  10439.  
  10440.  
  10441.  
  10442. <?php //note line if set by gateway
  10443.  
  10444. if ( $order->mp_payment_info['note'] ) { ?>
  10445.  
  10446. <h3><?php _e('Special Note:', 'mp'); ?></h3>
  10447.  
  10448. <p><?php esc_html_e($order->mp_payment_info['note']); ?></p>
  10449.  
  10450. <?php } ?>
  10451.  
  10452.  
  10453.  
  10454. <?php do_action('mp_single_order_display_shipping', $order); ?>
  10455.  
  10456.  
  10457.  
  10458. </div>
  10459.  
  10460. </div>
  10461.  
  10462.  
  10463.  
  10464. <div id="mp-order-notes" class="postbox">
  10465.  
  10466. <h3 class='hndle'><span><?php _e('Order Notes', 'mp'); ?></span> - <span class="description"><?php _e('These notes will be displayed on the order status page', 'mp'); ?></span></h3>
  10467.  
  10468. <div class="inside">
  10469.  
  10470. <p>
  10471.  
  10472. <textarea name="mp_order_notes" rows="5" style="width: 100%;"><?php echo esc_textarea(isset($order->mp_order_notes) ? $order->mp_order_notes : ''); ?></textarea><br />
  10473.  
  10474. <input type="submit" class="button-secondary" name="save-note" value="<?php _e('Save &raquo;', 'mp'); ?>" />
  10475.  
  10476. </p>
  10477.  
  10478. </div>
  10479.  
  10480. </div>
  10481.  
  10482. </form>
  10483.  
  10484.  
  10485.  
  10486. <?php do_action('mp_single_order_display_box', $order); ?>
  10487.  
  10488.  
  10489.  
  10490. </div>
  10491.  
  10492.  
  10493.  
  10494. <div id='advanced-sortables' class='meta-box-sortables'>
  10495.  
  10496. </div>
  10497.  
  10498.  
  10499.  
  10500. </div>
  10501.  
  10502. </div>
  10503.  
  10504. <br class="clear" />
  10505.  
  10506. </div><!-- /poststuff -->
  10507.  
  10508.  
  10509.  
  10510. </div><!-- /wrap -->
  10511.  
  10512. <?php
  10513.  
  10514. }
  10515.  
  10516.  
  10517.  
  10518. function orders_page() {
  10519.  
  10520.  
  10521.  
  10522. //load single order view if id is set
  10523.  
  10524. if (isset($_GET['order_id'])) {
  10525.  
  10526. $this->single_order_page();
  10527.  
  10528. return;
  10529.  
  10530. }
  10531.  
  10532.  
  10533.  
  10534. //force post type
  10535.  
  10536. global $wpdb, $post_type, $wp_query, $wp_locale, $current_screen;
  10537.  
  10538. $post_type = 'mp_order';
  10539.  
  10540. $_GET['post_type'] = $post_type;
  10541.  
  10542.  
  10543.  
  10544. $post_type_object = get_post_type_object($post_type);
  10545.  
  10546.  
  10547.  
  10548. if ( !current_user_can($post_type_object->cap->edit_posts) )
  10549.  
  10550. wp_die(__('Cheatin&#8217; uh?'));
  10551.  
  10552.  
  10553.  
  10554. $pagenum = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 0;
  10555.  
  10556. if ( empty($pagenum) )
  10557.  
  10558. $pagenum = 1;
  10559.  
  10560. $per_page = 'edit_' . $post_type . '_per_page';
  10561.  
  10562. $per_page = (int) get_user_option( $per_page );
  10563.  
  10564. if ( empty( $per_page ) || $per_page < 1 )
  10565.  
  10566. $per_page = 20;
  10567.  
  10568. // @todo filter based on type
  10569.  
  10570. $per_page = apply_filters( 'edit_' . $post_type . '_per_page', $per_page );
  10571.  
  10572.  
  10573.  
  10574. // Handle bulk actions
  10575.  
  10576. if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['bulk_edit']) || isset($_GET['action'])
  10577.  
  10578. || (isset($_GET['delete_all'])) || (isset($_GET['delete_all2'])) ) {
  10579.  
  10580. check_admin_referer('update-order-status');
  10581.  
  10582. $sendback = remove_query_arg( array('received', 'paid', 'shipped', 'closed', 'trash', 'delete', 'ids', 'delete_all', 'delete_all2'), wp_get_referer() );
  10583.  
  10584.  
  10585.  
  10586. if ( ( $_GET['action'] != -1 || $_GET['action2'] != -1 ) && ( isset($_GET['post']) || isset($_GET['ids']) ) ) {
  10587.  
  10588. $post_ids = isset($_GET['post']) ? array_map( 'intval', (array) $_GET['post'] ) : explode(',', $_GET['ids']);
  10589.  
  10590. $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
  10591.  
  10592. } else if ( isset( $_GET['delete_all'] ) || isset( $_GET['delete_all2'] ) )
  10593.  
  10594. $doaction = 'delete_all';
  10595.  
  10596.  
  10597.  
  10598. switch ( $doaction ) {
  10599.  
  10600. case 'received':
  10601.  
  10602. $received = 0;
  10603.  
  10604. foreach( (array) $post_ids as $post_id ) {
  10605.  
  10606. $this->update_order_status($post_id, 'received');
  10607.  
  10608. $received++;
  10609.  
  10610. }
  10611.  
  10612. $msg = sprintf( _n( '%s order marked as Received.', '%s orders marked as Received.', $received, 'mp' ), number_format_i18n( $received ) );
  10613.  
  10614. break;
  10615.  
  10616. case 'paid':
  10617.  
  10618. $paid = 0;
  10619.  
  10620. foreach( (array) $post_ids as $post_id ) {
  10621.  
  10622. $this->update_order_status($post_id, 'paid');
  10623.  
  10624. $paid++;
  10625.  
  10626. }
  10627.  
  10628. $msg = sprintf( _n( '%s order marked as Paid.', '%s orders marked as Paid.', $paid, 'mp' ), number_format_i18n( $paid ) );
  10629.  
  10630. break;
  10631.  
  10632. case 'shipped':
  10633.  
  10634. $shipped = 0;
  10635.  
  10636. foreach( (array) $post_ids as $post_id ) {
  10637.  
  10638. $this->update_order_status($post_id, 'shipped');
  10639.  
  10640. $shipped++;
  10641.  
  10642. }
  10643.  
  10644. $msg = sprintf( _n( '%s order marked as Shipped.', '%s orders marked as Shipped.', $shipped, 'mp' ), number_format_i18n( $shipped ) );
  10645.  
  10646. break;
  10647.  
  10648. case 'closed':
  10649.  
  10650. $closed = 0;
  10651.  
  10652. foreach( (array) $post_ids as $post_id ) {
  10653.  
  10654. $this->update_order_status($post_id, 'closed');
  10655.  
  10656. $closed++;
  10657.  
  10658. }
  10659.  
  10660. $msg = sprintf( _n( '%s order Closed.', '%s orders Closed.', $closed, 'mp' ), number_format_i18n( $closed ) );
  10661.  
  10662. break;
  10663.  
  10664.  
  10665.  
  10666. case 'trash':
  10667.  
  10668. $trashed = 0;
  10669.  
  10670. foreach( (array) $post_ids as $post_id ) {
  10671.  
  10672. $this->update_order_status($post_id, 'trash');
  10673.  
  10674. $trashed++;
  10675.  
  10676. }
  10677.  
  10678. $msg = sprintf( _n( '%s order moved to Trash.', '%s orders moved to Trash.', $trashed, 'mp' ), number_format_i18n( $trashed ) );
  10679.  
  10680. break;
  10681.  
  10682.  
  10683.  
  10684. case 'delete':
  10685.  
  10686. $deleted = 0;
  10687.  
  10688. foreach( (array) $post_ids as $post_id ) {
  10689.  
  10690. $this->update_order_status($post_id, 'delete');
  10691.  
  10692. $deleted++;
  10693.  
  10694. }
  10695.  
  10696. $msg = sprintf( _n( '%s order Deleted.', '%s orders Deleted.', $deleted, 'mp' ), number_format_i18n( $deleted ) );
  10697.  
  10698. break;
  10699.  
  10700.  
  10701.  
  10702. case 'delete_all':
  10703.  
  10704. $mp_orders = get_posts('post_type=mp_order&post_status=trash&numberposts=-1');
  10705.  
  10706. if ($mp_orders) {
  10707.  
  10708. $deleted = 0;
  10709.  
  10710. foreach($mp_orders as $mp_order) {
  10711.  
  10712. $this->update_order_status($mp_order->ID, 'delete');
  10713.  
  10714. $deleted++;
  10715.  
  10716. }
  10717.  
  10718. $msg = sprintf( _n( '%s order Deleted.', '%s orders Deleted.', $deleted, 'mp' ), number_format_i18n( $deleted ) );
  10719.  
  10720. }
  10721.  
  10722. break;
  10723.  
  10724. }
  10725.  
  10726.  
  10727.  
  10728. }
  10729.  
  10730.  
  10731.  
  10732. $avail_post_stati = wp_edit_posts_query();
  10733.  
  10734.  
  10735.  
  10736. $num_pages = $wp_query->max_num_pages;
  10737.  
  10738.  
  10739.  
  10740. $mode = 'list';
  10741.  
  10742. ?>
  10743.  
  10744.  
  10745.  
  10746. <div class="wrap">
  10747.  
  10748. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/shopping-cart.png'; ?>" /></div>
  10749.  
  10750. <h2><?php _e('Manage Orders', 'mp');
  10751.  
  10752. if ( isset($_GET['s']) && $_GET['s'] )
  10753.  
  10754. printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() ); ?>
  10755.  
  10756. </h2>
  10757.  
  10758.  
  10759.  
  10760. <?php if ( isset($msg) ) { ?>
  10761.  
  10762. <div class="updated fade"><p>
  10763.  
  10764. <?php echo $msg; ?>
  10765.  
  10766. </p></div>
  10767.  
  10768. <?php } ?>
  10769.  
  10770.  
  10771.  
  10772. <form id="posts-filter" action="<?php echo admin_url('edit.php'); ?>" method="get">
  10773.  
  10774.  
  10775.  
  10776. <ul class="subsubsub">
  10777.  
  10778. <?php
  10779.  
  10780. if ( empty($locked_post_status) ) :
  10781.  
  10782. $status_links = array();
  10783.  
  10784. $num_posts = wp_count_posts( $post_type, 'readable' );
  10785.  
  10786. $class = '';
  10787.  
  10788. $allposts = '';
  10789.  
  10790.  
  10791.  
  10792. $total_posts = array_sum( (array) $num_posts );
  10793.  
  10794.  
  10795.  
  10796. // Subtract post types that are not included in the admin all list.
  10797.  
  10798. foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
  10799.  
  10800. $total_posts -= $num_posts->$state;
  10801.  
  10802.  
  10803.  
  10804. $class = empty($class) && empty($_GET['post_status']) ? ' class="current"' : '';
  10805.  
  10806. $status_links[] = "<li><a href='edit.php?page=marketpress-orders&post_type=product{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
  10807.  
  10808.  
  10809.  
  10810. foreach ( get_post_stati(array(), 'objects') as $status_key => $status ) {
  10811.  
  10812. $class = '';
  10813.  
  10814.  
  10815.  
  10816. $status_name = $status->name;
  10817.  
  10818.  
  10819.  
  10820. if ( !in_array( $status_name, $avail_post_stati ) )
  10821.  
  10822. continue;
  10823.  
  10824.  
  10825.  
  10826. if ( empty( $num_posts->$status_name ) )
  10827.  
  10828. continue;
  10829.  
  10830.  
  10831.  
  10832. if ( isset($_GET['post_status']) && $status_name == $_GET['post_status'] )
  10833.  
  10834. $class = ' class="current"';
  10835.  
  10836.  
  10837.  
  10838. $status_links[$status_key] = "<li><a href='edit.php?page=marketpress-orders&amp;post_status=$status_name&amp;post_type=product'$class>" . sprintf( _n( $status->label_count[0], $status->label_count[1], $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>';
  10839.  
  10840. }
  10841.  
  10842.  
  10843.  
  10844. // Kludge. There has to be a better way to order stati. If present we want to 'trash' key always at the end.
  10845.  
  10846. // Maybe if we were properly inheriting WP_List_Table.
  10847.  
  10848. if (isset($status_links['trash'])) {
  10849.  
  10850. $trash_item = $status_links['trash'];
  10851.  
  10852. unset($status_links['trash']);
  10853.  
  10854. $status_links['trash'] = $trash_item;
  10855.  
  10856. }
  10857.  
  10858. echo implode( " |</li>\n", $status_links ) . '</li>';
  10859.  
  10860. unset( $status_links );
  10861.  
  10862. endif;
  10863.  
  10864. ?>
  10865.  
  10866. </ul>
  10867.  
  10868.  
  10869.  
  10870. <p class="search-box">
  10871.  
  10872. <label class="screen-reader-text" for="post-search-input"><?php _e('Search Orders', 'mp'); ?>:</label>
  10873.  
  10874. <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" />
  10875.  
  10876. <input type="submit" value="<?php _e('Search Orders', 'mp'); ?>" class="button" />
  10877.  
  10878. </p>
  10879.  
  10880.  
  10881.  
  10882. <input type="hidden" name="post_type" class="post_status_page" value="product" />
  10883.  
  10884. <input type="hidden" name="page" class="post_status_page" value="marketpress-orders" />
  10885.  
  10886. <?php if (!empty($_GET['post_status'])) { ?>
  10887.  
  10888. <input type="hidden" name="post_status" class="post_status_page" value="<?php echo esc_attr($_GET['post_status']); ?>" />
  10889.  
  10890. <?php } ?>
  10891.  
  10892.  
  10893.  
  10894. <?php if ( have_posts() ) { ?>
  10895.  
  10896.  
  10897.  
  10898. <div class="tablenav">
  10899.  
  10900. <?php
  10901.  
  10902. $page_links = paginate_links( array(
  10903.  
  10904. 'base' => add_query_arg( 'paged', '%#%' ),
  10905.  
  10906. 'format' => '',
  10907.  
  10908. 'prev_text' => __('&laquo;'),
  10909.  
  10910. 'next_text' => __('&raquo;'),
  10911.  
  10912. 'total' => $num_pages,
  10913.  
  10914. 'current' => $pagenum
  10915.  
  10916. ));
  10917.  
  10918.  
  10919.  
  10920. ?>
  10921.  
  10922.  
  10923.  
  10924. <div class="alignleft actions">
  10925.  
  10926. <select name="action">
  10927.  
  10928. <option value="-1" selected="selected"><?php _e('Change Status', 'mp'); ?></option>
  10929.  
  10930. <option value="received"><?php _e('Received', 'mp'); ?></option>
  10931.  
  10932. <option value="paid"><?php _e('Paid', 'mp'); ?></option>
  10933.  
  10934. <option value="shipped"><?php _e('Shipped', 'mp'); ?></option>
  10935.  
  10936. <option value="closed"><?php _e('Closed', 'mp'); ?></option>
  10937.  
  10938. <?php if ((isset($_GET['post_status'])) && ($_GET['post_status'] == 'trash')) { ?>
  10939.  
  10940. <option value="delete"><?php _e('Delete', 'mp'); ?></option>
  10941.  
  10942. <?php } else { ?>
  10943.  
  10944. <option value="trash"><?php _e('Trash', 'mp'); ?></option>
  10945.  
  10946. <?php } ?>
  10947.  
  10948. </select>
  10949.  
  10950. <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
  10951.  
  10952. <?php wp_nonce_field('update-order-status'); ?>
  10953.  
  10954.  
  10955.  
  10956. <?php // view filters
  10957.  
  10958. if ( !is_singular() ) {
  10959.  
  10960. $arc_query = $wpdb->prepare("SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = %s ORDER BY post_date DESC", $post_type);
  10961.  
  10962.  
  10963.  
  10964. $arc_result = $wpdb->get_results( $arc_query );
  10965.  
  10966.  
  10967.  
  10968. $month_count = count($arc_result);
  10969.  
  10970.  
  10971.  
  10972. if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) {
  10973.  
  10974. $m = isset($_GET['m']) ? (int)$_GET['m'] : 0;
  10975.  
  10976. ?>
  10977.  
  10978. <select name='m'>
  10979.  
  10980. <option<?php selected( $m, 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
  10981.  
  10982. <?php
  10983.  
  10984. foreach ($arc_result as $arc_row) {
  10985.  
  10986. if ( $arc_row->yyear == 0 )
  10987.  
  10988. continue;
  10989.  
  10990. $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
  10991.  
  10992.  
  10993.  
  10994. if ( $arc_row->yyear . $arc_row->mmonth == $m )
  10995.  
  10996. $default = ' selected="selected"';
  10997.  
  10998. else
  10999.  
  11000. $default = '';
  11001.  
  11002.  
  11003.  
  11004. echo "<option$default value='" . esc_attr("$arc_row->yyear$arc_row->mmonth") . "'>";
  11005.  
  11006. echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
  11007.  
  11008. echo "</option>\n";
  11009.  
  11010. }
  11011.  
  11012. ?>
  11013.  
  11014. </select>
  11015.  
  11016. <?php } ?>
  11017.  
  11018.  
  11019.  
  11020. <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
  11021.  
  11022. <?php } ?>
  11023.  
  11024.  
  11025.  
  11026. <?php
  11027.  
  11028. if ((isset($_GET['post_status'])) && ($_GET['post_status'] == 'trash')) {
  11029.  
  11030. submit_button( __( 'Empty Trash' ), 'button-secondary apply', 'delete_all', false );
  11031.  
  11032. }
  11033.  
  11034. ?>
  11035.  
  11036. </div>
  11037.  
  11038.  
  11039.  
  11040. <?php if ( $page_links ) { ?>
  11041.  
  11042. <div class="tablenav-pages"><?php
  11043.  
  11044. $count_posts = $post_type_object->hierarchical ? $wp_query->post_count : $wp_query->found_posts;
  11045.  
  11046. $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
  11047.  
  11048. number_format_i18n( ( $pagenum - 1 ) * $per_page + 1 ),
  11049.  
  11050. number_format_i18n( min( $pagenum * $per_page, $count_posts ) ),
  11051.  
  11052. number_format_i18n( $count_posts ),
  11053.  
  11054. $page_links
  11055.  
  11056. );
  11057.  
  11058. echo $page_links_text;
  11059.  
  11060. ?></div>
  11061.  
  11062. <?php } ?>
  11063.  
  11064.  
  11065.  
  11066. <div class="clear"></div>
  11067.  
  11068. </div>
  11069.  
  11070.  
  11071.  
  11072. <div class="clear"></div>
  11073.  
  11074.  
  11075.  
  11076. <table class="widefat <?php echo $post_type_object->hierarchical ? 'page' : 'post'; ?> fixed" cellspacing="0">
  11077.  
  11078. <thead>
  11079.  
  11080. <tr>
  11081.  
  11082. <?php print_column_headers( $current_screen ); ?>
  11083.  
  11084. </tr>
  11085.  
  11086. </thead>
  11087.  
  11088.  
  11089.  
  11090. <tfoot>
  11091.  
  11092. <tr>
  11093.  
  11094. <?php print_column_headers($current_screen, false); ?>
  11095.  
  11096. </tr>
  11097.  
  11098. </tfoot>
  11099.  
  11100.  
  11101.  
  11102. <tbody>
  11103.  
  11104. <?php
  11105.  
  11106. if ( function_exists('post_rows') ) {
  11107.  
  11108. post_rows();
  11109.  
  11110. } else {
  11111.  
  11112. $wp_list_table = _get_list_table('WP_Posts_List_Table');
  11113.  
  11114. $wp_list_table->display_rows();
  11115.  
  11116. }
  11117.  
  11118. ?>
  11119.  
  11120. </tbody>
  11121.  
  11122. </table>
  11123.  
  11124.  
  11125.  
  11126. <div class="tablenav">
  11127.  
  11128.  
  11129.  
  11130. <?php
  11131.  
  11132. if ( $page_links )
  11133.  
  11134. echo "<div class='tablenav-pages'>$page_links_text</div>";
  11135.  
  11136. ?>
  11137.  
  11138.  
  11139.  
  11140. <div class="alignleft actions">
  11141.  
  11142. <select name="action2">
  11143.  
  11144. <option value="-1" selected="selected"><?php _e('Change Status', 'mp'); ?></option>
  11145.  
  11146. <option value="received"><?php _e('Received', 'mp'); ?></option>
  11147.  
  11148. <option value="paid"><?php _e('Paid', 'mp'); ?></option>
  11149.  
  11150. <option value="shipped"><?php _e('Shipped', 'mp'); ?></option>
  11151.  
  11152. <option value="closed"><?php _e('Closed', 'mp'); ?></option>
  11153.  
  11154. <?php if ((isset($_GET['post_status'])) && ($_GET['post_status'] == 'trash')) { ?>
  11155.  
  11156. <option value="delete"><?php _e('Delete', 'mp'); ?></option>
  11157.  
  11158. <?php } else { ?>
  11159.  
  11160. <option value="trash"><?php _e('Trash', 'mp'); ?></option>
  11161.  
  11162. <?php } ?>
  11163.  
  11164. </select>
  11165.  
  11166. <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
  11167.  
  11168. <?php
  11169.  
  11170. if ((isset($_GET['post_status'])) && ($_GET['post_status'] == 'trash')) {
  11171.  
  11172. submit_button( __( 'Empty Trash' ), 'button-secondary apply', 'delete_all2', false );
  11173.  
  11174. }
  11175.  
  11176. ?>
  11177.  
  11178.  
  11179.  
  11180. <br class="clear" />
  11181.  
  11182. </div>
  11183.  
  11184. <br class="clear" />
  11185.  
  11186. </div>
  11187.  
  11188.  
  11189.  
  11190. <?php } else { // have_posts() ?>
  11191.  
  11192. <div class="clear"></div>
  11193.  
  11194. <p><?php _e('No Orders Yet', 'mp'); ?></p>
  11195.  
  11196. <?php } ?>
  11197.  
  11198.  
  11199.  
  11200. </form>
  11201.  
  11202.  
  11203.  
  11204. <?php if (!isset($_GET['post_status']) || $_GET['post_status'] != 'trash') { ?>
  11205.  
  11206. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/download.png'; ?>" /></div>
  11207.  
  11208. <h2><?php _e('Export Orders', 'mp'); ?></h2>
  11209.  
  11210. <?php if ( defined( 'MP_LITE' ) ) { ?>
  11211.  
  11212. <a class="mp-pro-update" href="http://premium.wpmudev.org/project/e-commerce/" title="<?php _e('Upgrade Now', 'mp'); ?> &raquo;"><?php _e('Upgrade to enable CSV order exports &raquo;', 'mp'); ?></a><br />
  11213.  
  11214. <?php } ?>
  11215.  
  11216. <form action="<?php echo admin_url('admin-ajax.php?action=mp-orders-export'); ?>" method="post">
  11217.  
  11218. <?php
  11219.  
  11220. $months = $wpdb->get_results( $wpdb->prepare( "
  11221.  
  11222. SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
  11223.  
  11224. FROM $wpdb->posts
  11225.  
  11226. WHERE post_type = %s
  11227.  
  11228. ORDER BY post_date DESC
  11229.  
  11230. ", 'mp_order' ) );
  11231.  
  11232.  
  11233.  
  11234. $month_count = count( $months );
  11235.  
  11236.  
  11237.  
  11238. if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
  11239.  
  11240. return;
  11241.  
  11242.  
  11243.  
  11244. $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
  11245.  
  11246. ?>
  11247.  
  11248. <select name='m'>
  11249.  
  11250. <option<?php selected( $m, 0 ); ?> value='0'><?php _e( 'Show all dates' ); ?></option>
  11251.  
  11252. <?php
  11253.  
  11254. foreach ( $months as $arc_row ) {
  11255.  
  11256. if ( 0 == $arc_row->year )
  11257.  
  11258. continue;
  11259.  
  11260.  
  11261.  
  11262. $month = zeroise( $arc_row->month, 2 );
  11263.  
  11264. $year = $arc_row->year;
  11265.  
  11266.  
  11267.  
  11268. printf( "<option %s value='%s'>%s</option>\n",
  11269.  
  11270. selected( $m, $year . $month, false ),
  11271.  
  11272. esc_attr( $arc_row->year . $month ),
  11273.  
  11274. $wp_locale->get_month( $month ) . " $year"
  11275.  
  11276. );
  11277.  
  11278. }
  11279.  
  11280.  
  11281.  
  11282. $status = isset( $_GET['post_status'] ) ? $_GET['post_status'] : 'all';
  11283.  
  11284. ?>
  11285.  
  11286. </select>
  11287.  
  11288. <select name="order_status">
  11289.  
  11290. <option<?php selected( $status, 'all' ); ?> value="all" selected="selected"><?php _e('All Statuses', 'mp'); ?></option>
  11291.  
  11292. <option<?php selected( $status, 'order_received' ); ?> value="order_received"><?php _e('Received', 'mp'); ?></option>
  11293.  
  11294. <option<?php selected( $status, 'order_paid' ); ?> value="order_paid"><?php _e('Paid', 'mp'); ?></option>
  11295.  
  11296. <option<?php selected( $status, 'order_shipped' ); ?> value="order_shipped"><?php _e('Shipped', 'mp'); ?></option>
  11297.  
  11298. <option<?php selected( $status, 'order_closed' ); ?> value="order_closed"><?php _e('Closed', 'mp'); ?></option>
  11299.  
  11300. </select>
  11301.  
  11302. <input type="submit" value="<?php _e('Download &raquo;', 'mp'); ?>" name="export_orders" class="button-secondary"<?php echo defined( 'MP_LITE' ) ? ' disabled="disabled"' : ''; ?> />
  11303.  
  11304. </form>
  11305.  
  11306.  
  11307.  
  11308.  
  11309.  
  11310. <br class="clear">
  11311.  
  11312. <?php } ?>
  11313.  
  11314. </div>
  11315.  
  11316. <?php
  11317.  
  11318. }
  11319.  
  11320.  
  11321.  
  11322. function admin_page() {
  11323.  
  11324. global $wpdb;
  11325.  
  11326.  
  11327.  
  11328. //double-check rights
  11329.  
  11330. if(!current_user_can('manage_options')) {
  11331.  
  11332. echo "<p>" . __('Nice Try...', 'mp') . "</p>"; //If accessed properly, this message doesn't appear.
  11333.  
  11334. return;
  11335.  
  11336. }
  11337.  
  11338.  
  11339.  
  11340. $settings = get_option('mp_settings');
  11341.  
  11342. ?>
  11343.  
  11344. <div class="wrap">
  11345.  
  11346. <h3 class="nav-tab-wrapper">
  11347.  
  11348. <?php
  11349.  
  11350. $tab = ( !empty($_GET['tab']) ) ? $_GET['tab'] : 'main';
  11351.  
  11352.  
  11353.  
  11354. if (!$this->get_setting('disable_cart')) {
  11355.  
  11356. $tabs = array(
  11357.  
  11358. 'coupons' => __('Coupons', 'mp'),
  11359.  
  11360. 'presentation' => __('Presentation', 'mp'),
  11361.  
  11362. 'messages' => __('Messages', 'mp'),
  11363.  
  11364. 'shipping' => __('Shipping', 'mp'),
  11365.  
  11366. 'gateways' => __('Payments', 'mp'),
  11367.  
  11368. 'shortcodes' => __('Shortcodes', 'mp'),
  11369.  
  11370. 'importers' => __('Importers', 'mp')
  11371.  
  11372. );
  11373.  
  11374. } else {
  11375.  
  11376. $tabs = array(
  11377.  
  11378. 'presentation' => __('Presentation', 'mp'),
  11379.  
  11380. 'shortcodes' => __('Shortcodes', 'mp'),
  11381.  
  11382. 'importers' => __('Importers', 'mp')
  11383.  
  11384. );
  11385.  
  11386. }
  11387.  
  11388. $tabhtml = array();
  11389.  
  11390.  
  11391.  
  11392. // If someone wants to remove or add a tab
  11393.  
  11394. $tabs = apply_filters( 'marketpress_tabs', $tabs );
  11395.  
  11396.  
  11397.  
  11398. $class = ( 'main' == $tab ) ? ' nav-tab-active' : '';
  11399.  
  11400. $tabhtml[] = ' <a href="' . admin_url( 'edit.php?post_type=product&amp;page=marketpress' ) . '" class="nav-tab'.$class.'">' . __('General', 'mp') . '</a>';
  11401.  
  11402.  
  11403.  
  11404. foreach ( $tabs as $stub => $title ) {
  11405.  
  11406. $class = ( $stub == $tab ) ? ' nav-tab-active' : '';
  11407.  
  11408. $tabhtml[] = ' <a href="' . admin_url( 'edit.php?post_type=product&amp;page=marketpress&amp;tab=' . $stub ) . '" class="nav-tab'.$class.'">'.$title.'</a>';
  11409.  
  11410. }
  11411.  
  11412.  
  11413.  
  11414. echo implode( "\n", $tabhtml );
  11415.  
  11416. ?>
  11417.  
  11418. </h3>
  11419.  
  11420. <div class="clear"></div>
  11421.  
  11422.  
  11423.  
  11424. <?php
  11425.  
  11426. switch( $tab ) {
  11427.  
  11428. //---------------------------------------------------//
  11429.  
  11430. case "main":
  11431.  
  11432.  
  11433.  
  11434. //save settings
  11435.  
  11436. if (isset($_POST['marketplace_settings'])) {
  11437.  
  11438.  
  11439.  
  11440. //allow plugins to verify settings before saving
  11441.  
  11442. if (isset($_POST['mp']['tax']['canada_rate'])) {
  11443.  
  11444. foreach ($_POST['mp']['tax']['canada_rate'] as $key => $rate) {
  11445.  
  11446. $tax_rate = $rate * .01;
  11447.  
  11448. $_POST['mp']['tax']['canada_rate'][$key] = ($tax_rate < 1 && $tax_rate >= 0) ? $tax_rate : 0;
  11449.  
  11450. }
  11451.  
  11452. } else {
  11453.  
  11454. $tax_rate = $_POST['mp']['tax']['rate'] * .01;
  11455.  
  11456. $_POST['mp']['tax']['rate'] = ($tax_rate < 1 && $tax_rate >= 0) ? $tax_rate : 0;
  11457.  
  11458. }
  11459.  
  11460. $settings = array_merge($settings, apply_filters('mp_main_settings_filter', $_POST['mp']));
  11461.  
  11462. update_option('mp_settings', $settings);
  11463.  
  11464.  
  11465.  
  11466. echo '<div class="updated fade"><p>'.__('Settings saved.', 'mp').'</p></div>';
  11467.  
  11468. }
  11469.  
  11470. ?>
  11471.  
  11472. <script type="text/javascript">
  11473.  
  11474. jQuery(document).ready(function($) {
  11475.  
  11476. $("#mp-country-select, #mp-currency-select").change(function() {
  11477.  
  11478. $("#mp-main-form").submit();
  11479.  
  11480. });
  11481.  
  11482. });
  11483.  
  11484. </script>
  11485.  
  11486. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/settings.png'; ?>" /></div>
  11487.  
  11488. <h2><?php _e('General Settings', 'mp'); ?></h2>
  11489.  
  11490. <div id="poststuff" class="metabox-holder mp-settings">
  11491.  
  11492.  
  11493.  
  11494. <form id="mp-main-form" method="post" action="edit.php?post_type=product&amp;page=marketpress&amp;tab=main">
  11495.  
  11496. <input type="hidden" name="marketplace_settings" value="1" />
  11497.  
  11498.  
  11499.  
  11500. <div class="postbox location-settings">
  11501.  
  11502. <h3 class='hndle'><span><?php _e('Location Settings', 'mp') ?></span></h3>
  11503.  
  11504. <div class="inside">
  11505.  
  11506. <span class="description"><?php _e('This is the base location that shipping and tax rates will be calculated from.', 'mp') ?></span>
  11507.  
  11508. <table class="form-table">
  11509.  
  11510. <tr>
  11511.  
  11512. <th scope="row"><?php _e('Base Country', 'mp') ?></th>
  11513.  
  11514. <td>
  11515.  
  11516. <select id="mp-country-select" name="mp[base_country]">
  11517.  
  11518. <?php
  11519.  
  11520. foreach ($this->countries as $key => $value) {
  11521.  
  11522. ?><option value="<?php echo $key; ?>"<?php selected($this->get_setting('base_country'), $key); ?>><?php echo esc_attr($value); ?></option><?php
  11523.  
  11524. }
  11525.  
  11526. ?>
  11527.  
  11528. </select>
  11529.  
  11530. </td>
  11531.  
  11532. </tr>
  11533.  
  11534.  
  11535.  
  11536. <?php
  11537.  
  11538. switch ($this->get_setting('base_country')) {
  11539.  
  11540. case 'US':
  11541.  
  11542. $list = $this->usa_states;
  11543.  
  11544. break;
  11545.  
  11546.  
  11547.  
  11548. case 'CA':
  11549.  
  11550. $list = $this->canadian_provinces;
  11551.  
  11552. break;
  11553.  
  11554.  
  11555.  
  11556. case 'GB':
  11557.  
  11558. $list = $this->uk_counties;
  11559.  
  11560. break;
  11561.  
  11562.  
  11563.  
  11564. case 'AU':
  11565.  
  11566. $list = $this->australian_states;
  11567.  
  11568. break;
  11569.  
  11570.  
  11571.  
  11572. default:
  11573.  
  11574. $list = false;
  11575.  
  11576. }
  11577.  
  11578.  
  11579.  
  11580. //only show if correct country
  11581.  
  11582. if (is_array($list)) {
  11583.  
  11584. ?>
  11585.  
  11586. <tr>
  11587.  
  11588. <th scope="row"><?php _e('Base State/Province/Region', 'mp') ?></th>
  11589.  
  11590. <td>
  11591.  
  11592. <select name="mp[base_province]">
  11593.  
  11594. <?php
  11595.  
  11596. foreach ($list as $key => $value) {
  11597.  
  11598. ?><option value="<?php echo esc_attr($key); ?>"<?php selected($this->get_setting('base_province'), $key); ?>><?php echo esc_attr($value); ?></option><?php
  11599.  
  11600. }
  11601.  
  11602. ?>
  11603.  
  11604. </select>
  11605.  
  11606. </td>
  11607.  
  11608. </tr>
  11609.  
  11610. <?php }
  11611.  
  11612. //only show if correct country or US province
  11613.  
  11614. if ( is_array($list) || in_array( $this->get_setting('base_country'), array('UM','AS','FM','GU','MH','MP','PW','PR','PI') ) ) {
  11615.  
  11616. ?>
  11617.  
  11618. <tr>
  11619.  
  11620. <th scope="row"><?php _e('Base Zip/Postal Code', 'mp') ?></th>
  11621.  
  11622. <td>
  11623.  
  11624. <input value="<?php echo esc_attr($this->get_setting('base_zip')); ?>" size="10" name="mp[base_zip]" type="text" />
  11625.  
  11626. </td>
  11627.  
  11628. </tr>
  11629.  
  11630. <?php } ?>
  11631.  
  11632. </table>
  11633.  
  11634. </div>
  11635.  
  11636. </div>
  11637.  
  11638.  
  11639.  
  11640. <div class="postbox tax-settings">
  11641.  
  11642. <h3 class='hndle'><span><?php _e('Tax Settings', 'mp') ?></span></h3>
  11643.  
  11644. <div class="inside">
  11645.  
  11646. <table class="form-table">
  11647.  
  11648. <?php
  11649.  
  11650. switch ($this->get_setting('base_country')) {
  11651.  
  11652. case 'US':
  11653.  
  11654. ?>
  11655.  
  11656. <tr>
  11657.  
  11658. <th scope="row"><?php echo sprintf(__('%s Tax Rate', 'mp'), esc_attr($this->usa_states[$this->get_setting('base_province', 'CA')])); ?></th>
  11659.  
  11660. <td>
  11661.  
  11662. <input value="<?php echo $this->get_setting('tax->rate') * 100; ?>" size="3" name="mp[tax][rate]" type="text" style="text-align:right;" />%
  11663.  
  11664. </td>
  11665.  
  11666. </tr>
  11667.  
  11668. <?php
  11669.  
  11670. break;
  11671.  
  11672.  
  11673.  
  11674. case 'CA':
  11675.  
  11676. ?>
  11677.  
  11678. <tr>
  11679.  
  11680. <th scope="row"><a href="http://sbinfocanada.about.com/od/pst/a/PSTecommerce.htm" target="_blank"><?php _e('Total Tax Rates (VAT,GST,PST,HST)', 'mp'); ?></a></th>
  11681.  
  11682. <td>
  11683.  
  11684. <span class="description"><a href="http://en.wikipedia.org/wiki/Sales_taxes_in_Canada" target="_blank"><?php _e('Current Rates &raquo;', 'mp'); ?></a></span>
  11685.  
  11686. <table cellspacing="0" cellpadding="0">
  11687.  
  11688. <?php foreach ($this->canadian_provinces as $key => $label) { ?>
  11689.  
  11690. <tr>
  11691.  
  11692. <td style="padding: 0 5px;"><label for="mp_tax_<?php echo $key; ?>"><?php echo esc_attr($label); ?></label></td>
  11693.  
  11694. <td style="padding: 0 5px;"><input value="<?php echo $this->get_setting("tax->canada_rate->$key") * 100; ?>" size="3" id="mp_tax_<?php echo $key; ?>" name="mp[tax][canada_rate][<?php echo $key; ?>]" type="text" style="text-align:right;" />%</td>
  11695.  
  11696. </tr>
  11697.  
  11698. <?php } ?>
  11699.  
  11700. </table>
  11701.  
  11702. </td>
  11703.  
  11704. </tr>
  11705.  
  11706. <?php
  11707.  
  11708. break;
  11709.  
  11710.  
  11711.  
  11712. case 'GB':
  11713.  
  11714. ?>
  11715.  
  11716. <tr>
  11717.  
  11718. <th scope="row"><?php _e('VAT Tax Rate', 'mp') ?></th>
  11719.  
  11720. <td>
  11721.  
  11722. <input value="<?php echo $this->get_setting('tax->rate') * 100; ?>" size="3" name="mp[tax][rate]" type="text" style="text-align:right;" />%
  11723.  
  11724. </td>
  11725.  
  11726. </tr>
  11727.  
  11728. <?php
  11729.  
  11730. break;
  11731.  
  11732.  
  11733.  
  11734. case 'AU':
  11735.  
  11736. ?>
  11737.  
  11738. <tr>
  11739.  
  11740. <th scope="row"><?php _e('GST Tax Rate', 'mp') ?></th>
  11741.  
  11742. <td>
  11743.  
  11744. <input value="<?php echo $this->get_setting('tax->rate') * 100; ?>" size="3" name="mp[tax][rate]" type="text" style="text-align:right;" />%
  11745.  
  11746. </td>
  11747.  
  11748. </tr>
  11749.  
  11750. <?php
  11751.  
  11752. break;
  11753.  
  11754.  
  11755.  
  11756. default:
  11757.  
  11758. //in european union
  11759.  
  11760. if ( in_array($this->get_setting('base_country'), $this->eu_countries) ) {
  11761.  
  11762. ?>
  11763.  
  11764. <tr>
  11765.  
  11766. <th scope="row"><?php _e('VAT Tax Rate', 'mp') ?></th>
  11767.  
  11768. <td>
  11769.  
  11770. <input value="<?php echo $this->get_setting('tax->rate') * 100; ?>" size="3" name="mp[tax][rate]" type="text" style="text-align:right;" />%
  11771.  
  11772. </td>
  11773.  
  11774. </tr>
  11775.  
  11776. <?php
  11777.  
  11778. } else { //all other countries
  11779.  
  11780. ?>
  11781.  
  11782. <tr>
  11783.  
  11784. <th scope="row"><?php _e('Country Total Tax Rate (VAT, GST, Etc.)', 'mp') ?></th>
  11785.  
  11786. <td>
  11787.  
  11788. <input value="<?php echo $this->get_setting('tax->rate') * 100; ?>" size="3" name="mp[tax][rate]" type="text" style="text-align:right;" />%
  11789.  
  11790. </td>
  11791.  
  11792. </tr>
  11793.  
  11794. <tr>
  11795.  
  11796. <th scope="row"><?php _e('Tax Orders Outside Your Base Country?', 'mp'); ?></th>
  11797.  
  11798. <td>
  11799.  
  11800. <label><input value="1" name="mp[tax][tax_outside]" type="radio"<?php checked($this->get_setting('tax->tax_outside'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  11801.  
  11802. <label><input value="0" name="mp[tax][tax_outside]" type="radio"<?php checked($this->get_setting('tax->tax_outside'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  11803.  
  11804. </td>
  11805.  
  11806. </tr>
  11807.  
  11808. <?php
  11809.  
  11810. }
  11811.  
  11812. break;
  11813.  
  11814. }
  11815.  
  11816. ?>
  11817.  
  11818. <tr>
  11819.  
  11820. <th scope="row"><?php _e('Tax Label', 'mp') ?></th>
  11821.  
  11822. <td>
  11823.  
  11824. <input value="<?php echo esc_attr($this->get_setting('tax->label', __('Taxes', 'mp'))); ?>" size="10" name="mp[tax][label]" type="text" />
  11825.  
  11826. <br /><span class="description"><?php _e('The label shown for the tax line item in the cart. Taxes, VAT, GST, etc.', 'mp') ?></span>
  11827.  
  11828. </td>
  11829.  
  11830. </tr>
  11831.  
  11832. <tr>
  11833.  
  11834. <th scope="row"><?php _e('Apply Tax To Shipping Fees?', 'mp') ?></th>
  11835.  
  11836. <td>
  11837.  
  11838. <label><input value="1" name="mp[tax][tax_shipping]" type="radio"<?php checked($this->get_setting('tax->tax_shipping'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  11839.  
  11840. <label><input value="0" name="mp[tax][tax_shipping]" type="radio"<?php checked($this->get_setting('tax->tax_shipping'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  11841.  
  11842. <br /><span class="description"><?php _e('Please see your local tax laws. Most areas charge tax on shipping fees.', 'mp') ?></span>
  11843.  
  11844. </td>
  11845.  
  11846. </tr>
  11847.  
  11848. <tr>
  11849.  
  11850. <th scope="row"><?php _e('Enter Prices Inclusive of Tax?', 'mp') ?></th>
  11851.  
  11852. <td>
  11853.  
  11854. <label><input value="1" name="mp[tax][tax_inclusive]" type="radio"<?php checked($this->get_setting('tax->tax_inclusive'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  11855.  
  11856. <label><input value="0" name="mp[tax][tax_inclusive]" type="radio"<?php checked($this->get_setting('tax->tax_inclusive'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  11857.  
  11858. <br /><span class="description"><?php _e('Enabling this option allows you to enter and show all prices inclusive of tax, while still listing the tax total as a line item in shopping carts. Please see your local tax laws.', 'mp') ?></span>
  11859.  
  11860. </td>
  11861.  
  11862. </tr>
  11863.  
  11864. <tr>
  11865.  
  11866. <th scope="row"><?php _e("Apply Tax to Downloadable Products?", 'mp') ?></th>
  11867.  
  11868. <td>
  11869.  
  11870. <label><input value="1" name="mp[tax][tax_digital]" type="radio"<?php checked($this->get_setting('tax->tax_digital'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  11871.  
  11872. <label><input value="0" name="mp[tax][tax_digital]" type="radio"<?php checked($this->get_setting('tax->tax_digital'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  11873.  
  11874. <br /><span class="description"><?php _e('Please see your local tax laws. Note if this is enabled and a downloadable only cart, rates will be the default for your base location.', 'mp') ?></span>
  11875.  
  11876. </td>
  11877.  
  11878. </tr>
  11879.  
  11880. <tr>
  11881.  
  11882. <th scope="row"><?php _e("Collect Address on Downloadable Only Cart?", 'mp') ?></th>
  11883.  
  11884. <td>
  11885.  
  11886. <label><input value="1" name="mp[tax][downloadable_address]" type="radio"<?php checked($this->get_setting('tax->downloadable_address'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  11887.  
  11888. <label><input value="0" name="mp[tax][downloadable_address]" type="radio"<?php checked($this->get_setting('tax->downloadable_address', 0), 0) ?> /> <?php _e('No', 'mp') ?></label>
  11889.  
  11890. <br /><span class="description"><?php _e("If you need to tax downloadable products and don't want to default to the rates to your base location, enable this to always collect the shipping address.", 'mp') ?></span>
  11891.  
  11892. </td>
  11893.  
  11894. </tr>
  11895.  
  11896. </table>
  11897.  
  11898. </div>
  11899.  
  11900. </div>
  11901.  
  11902.  
  11903.  
  11904. <div class="postbox">
  11905.  
  11906. <h3 class='hndle'><span><?php _e('Currency Settings', 'mp') ?></span></h3>
  11907.  
  11908. <div class="inside">
  11909.  
  11910. <span class="description"><?php _e('These preferences affect display only. Your payment gateway of choice may not support every currency listed here.', 'mp') ?></span>
  11911.  
  11912. <table class="form-table">
  11913.  
  11914. <tr valign="top">
  11915.  
  11916. <th scope="row"><?php _e('Store Currency', 'mp') ?></th>
  11917.  
  11918. <td>
  11919.  
  11920. <select id="mp-currency-select" name="mp[currency]">
  11921.  
  11922. <?php
  11923.  
  11924. foreach ($this->currencies as $key => $value) {
  11925.  
  11926. ?><option value="<?php echo $key; ?>"<?php selected($this->get_setting('currency'), $key); ?>><?php echo esc_attr($value[0]) . ' - ' . $this->format_currency($key); ?></option><?php
  11927.  
  11928. }
  11929.  
  11930. ?>
  11931.  
  11932. </select>
  11933.  
  11934. </td>
  11935.  
  11936. </tr>
  11937.  
  11938. <tr valign="top">
  11939.  
  11940. <th scope="row"><?php _e('Currency Symbol Position', 'mp') ?></th>
  11941.  
  11942. <td>
  11943.  
  11944. <label><input value="1" name="mp[curr_symbol_position]" type="radio"<?php checked($this->get_setting('curr_symbol_position'), 1); ?>>
  11945.  
  11946. <?php echo $this->format_currency($this->get_setting('currency')); ?>100</label><br />
  11947.  
  11948. <label><input value="2" name="mp[curr_symbol_position]" type="radio"<?php checked($this->get_setting('curr_symbol_position'), 2); ?>>
  11949.  
  11950. <?php echo $this->format_currency($this->get_setting('currency')); ?> 100</label><br />
  11951.  
  11952. <label><input value="3" name="mp[curr_symbol_position]" type="radio"<?php checked($this->get_setting('curr_symbol_position'), 3); ?>>
  11953.  
  11954. 100<?php echo $this->format_currency($this->get_setting('currency')); ?></label><br />
  11955.  
  11956. <label><input value="4" name="mp[curr_symbol_position]" type="radio"<?php checked($this->get_setting('curr_symbol_position'), 4); ?>>
  11957.  
  11958. 100 <?php echo $this->format_currency($this->get_setting('currency')); ?></label>
  11959.  
  11960. </td>
  11961.  
  11962. </tr>
  11963.  
  11964. <tr valign="top">
  11965.  
  11966. <th scope="row"><?php _e('Show Decimal in Prices', 'mp') ?></th>
  11967.  
  11968. <td>
  11969.  
  11970. <label><input value="1" name="mp[curr_decimal]" type="radio"<?php checked( ( ($this->get_setting('curr_decimal') !== 0) ? 1 : 0 ), 1); ?>>
  11971.  
  11972. <?php _e('Yes', 'mp') ?></label>
  11973.  
  11974. <label><input value="0" name="mp[curr_decimal]" type="radio"<?php checked($this->get_setting('curr_decimal'), 0); ?>>
  11975.  
  11976. <?php _e('No', 'mp') ?></label>
  11977.  
  11978. </td>
  11979.  
  11980. </tr>
  11981.  
  11982. </table>
  11983.  
  11984. </div>
  11985.  
  11986. </div>
  11987.  
  11988.  
  11989.  
  11990. <div class="postbox">
  11991.  
  11992. <h3 class='hndle'><span><?php _e('Miscellaneous Settings', 'mp') ?></span></h3>
  11993.  
  11994. <div class="inside">
  11995.  
  11996. <table class="form-table">
  11997.  
  11998. <tr id="mp-inventory-setting">
  11999.  
  12000. <th scope="row"><?php _e('Inventory Warning Threshold', 'mp') ?></th>
  12001.  
  12002. <td>
  12003.  
  12004. <span class="description"><?php _e('At what low stock count do you want to be warned for products you have enabled inventory tracking for?', 'mp') ?></span><br />
  12005.  
  12006. <select name="mp[inventory_threshhold]">
  12007.  
  12008. <?php
  12009.  
  12010. $inventory_threshhold = $this->get_setting('inventory_threshhold', 3);
  12011.  
  12012. for ($i=0; $i<=100; $i++) {
  12013.  
  12014. $selected = ($inventory_threshhold == $i) ? ' selected="selected"' : '';
  12015.  
  12016. echo '<option value="' . $i . '"' . $selected . '">' . $i . '</option>';
  12017.  
  12018. }
  12019.  
  12020. ?>
  12021.  
  12022. </select>
  12023.  
  12024. </td>
  12025.  
  12026. </tr>
  12027.  
  12028. <tr valign="top">
  12029.  
  12030. <th scope="row"><?php _e('Hide Out of Stock Products', 'mp') ?></th>
  12031.  
  12032. <td>
  12033.  
  12034. <label><input value="1" name="mp[inventory_remove]" type="radio"<?php checked($this->get_setting('inventory_remove'), 1); ?>> <?php _e('Yes', 'mp') ?></label>
  12035.  
  12036. <label><input value="0" name="mp[inventory_remove]" type="radio"<?php checked($this->get_setting('inventory_remove'), 0); ?>> <?php _e('No', 'mp') ?></label>
  12037.  
  12038. <br /><span class="description"><?php _e('This will set the product to draft if inventory of all variations is gone.', 'mp') ?></span>
  12039.  
  12040. </td>
  12041.  
  12042. </tr>
  12043.  
  12044. <tr id="mp-downloads-setting">
  12045.  
  12046. <th scope="row"><?php _e('Maximum Downloads', 'mp') ?></th>
  12047.  
  12048. <td>
  12049.  
  12050. <span class="description"><?php _e('How many times may a customer download a file they have purchased? (It\'s best to set this higher than one in case they have any problems downloading)', 'mp') ?></span><br />
  12051.  
  12052. <select name="mp[max_downloads]">
  12053.  
  12054. <?php
  12055.  
  12056. $max_downloads = $this->get_setting('max_downloads', 5);
  12057.  
  12058. for ($i=1; $i<=100; $i++) {
  12059.  
  12060. $selected = ($max_downloads == $i) ? ' selected="selected"' : '';
  12061.  
  12062. echo '<option value="' . $i . '"' . $selected . '">' . $i . '</option>';
  12063.  
  12064. }
  12065.  
  12066. ?>
  12067.  
  12068. </select>
  12069.  
  12070. </td>
  12071.  
  12072. </tr>
  12073.  
  12074. <tr valign="top">
  12075.  
  12076. <th scope="row"><?php _e('Limit Digital Products Per-order', 'mp') ?></th>
  12077.  
  12078. <td>
  12079.  
  12080. <label><input value="1" name="mp[download_order_limit]" type="radio"<?php checked($this->get_setting('download_order_limit', 1), 1); ?>> <?php _e('Yes', 'mp') ?></label>
  12081.  
  12082. <label><input value="0" name="mp[download_order_limit]" type="radio"<?php checked($this->get_setting('download_order_limit'), 0); ?>> <?php _e('No', 'mp') ?></label>
  12083.  
  12084. <br /><span class="description"><?php _e('This will prevent multiples of the same downloadable product form being added to the cart. Per-product custom limits will override this.', 'mp') ?></span>
  12085.  
  12086. </td>
  12087.  
  12088. </tr>
  12089.  
  12090. <tr>
  12091.  
  12092. <th scope="row"><?php _e('Force Login', 'mp') ?></th>
  12093.  
  12094. <td>
  12095.  
  12096. <?php $force_login = ($this->get_setting('force_login')) ? 1 : 0; ?>
  12097.  
  12098. <label><input value="1" name="mp[force_login]" type="radio"<?php checked($force_login, 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  12099.  
  12100. <label><input value="0" name="mp[force_login]" type="radio"<?php checked($force_login, 0) ?> /> <?php _e('No', 'mp') ?></label>
  12101.  
  12102. <br /><span class="description"><?php _e('Whether or not customers must be registered and logged in to checkout. (Not recommended: Enabling this can lower conversions)', 'mp') ?></span>
  12103.  
  12104. </td>
  12105.  
  12106. </tr>
  12107.  
  12108. <tr>
  12109.  
  12110. <th scope="row"><?php _e('Product Listings Only', 'mp') ?></th>
  12111.  
  12112. <td>
  12113.  
  12114. <label><input value="1" name="mp[disable_cart]" type="radio"<?php checked($this->get_setting('disable_cart'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  12115.  
  12116. <label><input value="0" name="mp[disable_cart]" type="radio"<?php checked($this->get_setting('disable_cart'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  12117.  
  12118. <br /><span class="description"><?php _e('This option turns MarketPress into more of a product listing plugin, disabling shopping carts, checkout, and order management. This is useful if you simply want to list items you can buy in a store somewhere else, optionally linking the "Buy Now" buttons to an external site. Some examples are a car dealership, or linking to songs/albums in itunes, or linking to products on another site with your own affiliate links.', 'mp') ?></span>
  12119.  
  12120. </td>
  12121.  
  12122. </tr>
  12123.  
  12124. <tr>
  12125.  
  12126. <th scope="row"><?php _e('Google Analytics Ecommerce Tracking', 'mp') ?></th>
  12127.  
  12128. <td>
  12129.  
  12130. <?php if ( defined( 'MP_LITE' ) ) { ?>
  12131.  
  12132. <a class="mp-pro-update" href="http://premium.wpmudev.org/project/e-commerce/" title="<?php _e('Upgrade Now', 'mp'); ?> &raquo;"><?php _e('Upgrade to enable Google Analytics Ecommerce Tracking &raquo;', 'mp'); ?></a><br />
  12133.  
  12134. <?php } ?>
  12135.  
  12136. <select name="mp[ga_ecommerce]"<?php echo defined( 'MP_LITE' ) ? ' disabled="disabled"' : ''; ?>>
  12137.  
  12138. <option value="none"<?php selected($this->get_setting('ga_ecommerce'), 'none') ?>><?php _e('None', 'mp') ?></option>
  12139.  
  12140. <option value="new"<?php selected($this->get_setting('ga_ecommerce'), 'new') ?>><?php _e('Asynchronous Tracking Code', 'mp') ?></option>
  12141.  
  12142. <option value="old"<?php selected($this->get_setting('ga_ecommerce'), 'old') ?>><?php _e('Old Tracking Code', 'mp') ?></option>
  12143.  
  12144. <option value="universal"<?php selected($this->get_setting('ga_ecommerce'), 'universal') ?>><?php _e('Universal Analytics', 'mp') ?></option>
  12145.  
  12146. </select>
  12147.  
  12148. <br /><span class="description"><?php _e('If you already use Google Analytics for your website, you can track detailed ecommerce information by enabling this setting. Choose whether you are using the new asynchronous or old tracking code. Before Google Analytics can report ecommerce activity for your website, you must enable ecommerce tracking on the profile settings page for your website. Also keep in mind that some gateways do not reliably show the receipt page, so tracking may not be accurate in those cases. It is recommended to use the PayPal gateway for the most accurate data. <a href="http://analytics.blogspot.com/2009/05/how-to-use-ecommerce-tracking-in-google.html" target="_blank">More information &raquo;</a>', 'mp') ?></span>
  12149.  
  12150. </td>
  12151.  
  12152. </tr>
  12153.  
  12154. <tr>
  12155.  
  12156. <th scope="row"><?php _e('Special Instructions Field', 'mp') ?></th>
  12157.  
  12158. <td>
  12159.  
  12160. <label><input value="1" name="mp[special_instructions]" type="radio"<?php checked($this->get_setting('special_instructions'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  12161.  
  12162. <label><input value="0" name="mp[special_instructions]" type="radio"<?php checked($this->get_setting('special_instructions'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  12163.  
  12164. <br /><span class="description"><?php printf(__('Enabling this field will display a textbox on the shipping checkout page for users to enter special instructions for their order. Useful for product personalization, etc. Note you may want to <a href="%s">adjust the message on the shipping page.', 'mp'), admin_url('edit.php?post_type=product&page=marketpress&tab=messages#mp_msgs_shipping')); ?></span>
  12165.  
  12166. </td>
  12167.  
  12168. </tr>
  12169.  
  12170. </table>
  12171.  
  12172. </div>
  12173.  
  12174. </div>
  12175.  
  12176.  
  12177.  
  12178. <?php
  12179.  
  12180. //for adding additional settings for a shipping module
  12181.  
  12182. do_action('mp_general_settings');
  12183.  
  12184. ?>
  12185.  
  12186.  
  12187.  
  12188. <p class="submit">
  12189.  
  12190. <input class="button-primary" type="submit" name="submit_settings" value="<?php _e('Save Changes', 'mp') ?>" />
  12191.  
  12192. </p>
  12193.  
  12194. </form>
  12195.  
  12196. </div>
  12197.  
  12198. <?php
  12199.  
  12200. break;
  12201.  
  12202.  
  12203.  
  12204.  
  12205.  
  12206. //---------------------------------------------------//
  12207.  
  12208. case "coupons":
  12209.  
  12210.  
  12211.  
  12212. $coupons = get_option('mp_coupons');
  12213.  
  12214. if (!is_array($coupons)) $coupons = array();
  12215.  
  12216.  
  12217.  
  12218. //delete checked coupons
  12219.  
  12220. if (isset($_POST['allcoupon_delete'])) {
  12221.  
  12222. //check nonce
  12223.  
  12224. check_admin_referer('mp_coupons');
  12225.  
  12226.  
  12227.  
  12228. if (is_array($_POST['coupons_checks'])) {
  12229.  
  12230. //loop through and delete
  12231.  
  12232. foreach ($_POST['coupons_checks'] as $del_code)
  12233.  
  12234. unset($coupons[$del_code]);
  12235.  
  12236.  
  12237.  
  12238. update_option('mp_coupons', $coupons);
  12239.  
  12240. //display message confirmation
  12241.  
  12242. echo '<div class="updated fade"><p>'.__('Coupon(s) succesfully deleted.', 'mp').'</p></div>';
  12243.  
  12244. }
  12245.  
  12246. }
  12247.  
  12248.  
  12249.  
  12250. //save or add coupon
  12251.  
  12252. if (isset($_POST['submit_settings'])) {
  12253.  
  12254. //check nonce
  12255.  
  12256. check_admin_referer('mp_coupons');
  12257.  
  12258.  
  12259.  
  12260. $error = false;
  12261.  
  12262.  
  12263.  
  12264. $new_coupon_code = preg_replace('/[^A-Z0-9_-]/', '', strtoupper($_POST['coupon_code']));
  12265.  
  12266. if (empty($new_coupon_code))
  12267.  
  12268. $error[] = __('Please enter a valid Coupon Code', 'mp');
  12269.  
  12270.  
  12271.  
  12272. $coupons[$new_coupon_code]['discount'] = round($_POST['discount'], 2);
  12273.  
  12274. if ($coupons[$new_coupon_code]['discount'] <= 0)
  12275.  
  12276. $error[] = __('Please enter a valid Discount Amount', 'mp');
  12277.  
  12278.  
  12279.  
  12280. $coupons[$new_coupon_code]['discount_type'] = $_POST['discount_type'];
  12281.  
  12282. if ($coupons[$new_coupon_code]['discount_type'] != 'amt' && $coupons[$new_coupon_code]['discount_type'] != 'pct')
  12283.  
  12284. $error[] = __('Please choose a valid Discount Type', 'mp');
  12285.  
  12286.  
  12287.  
  12288. $coupons[$new_coupon_code]['start'] = strtotime($_POST['start']);
  12289.  
  12290. if ($coupons[$new_coupon_code]['start'] === false)
  12291.  
  12292. $error[] = __('Please enter a valid Start Date', 'mp');
  12293.  
  12294.  
  12295.  
  12296. $coupons[$new_coupon_code]['end'] = strtotime($_POST['end']);
  12297.  
  12298. if ($coupons[$new_coupon_code]['end'] && $coupons[$new_coupon_code]['end'] < $coupons[$new_coupon_code]['start'])
  12299.  
  12300. $error[] = __('Please enter a valid End Date not earlier than the Start Date', 'mp');
  12301.  
  12302.  
  12303.  
  12304. $coupons[$new_coupon_code]['uses'] = (is_numeric($_POST['uses'])) ? (int)$_POST['uses'] : '';
  12305.  
  12306.  
  12307.  
  12308. // applies to
  12309.  
  12310. $applies_to = $_POST['applies_to'];
  12311.  
  12312. switch( $applies_to ) {
  12313.  
  12314. case 'all':
  12315.  
  12316.  
  12317.  
  12318. $coupons[$new_coupon_code]['applies_to'] = '';
  12319.  
  12320. break;
  12321.  
  12322.  
  12323.  
  12324. case 'category';
  12325.  
  12326. $coupons[$new_coupon_code]['applies_to']['type'] = $_POST['applies_to'];
  12327.  
  12328. $coupons[$new_coupon_code]['applies_to']['id'] = $_POST['coupon_category'];
  12329.  
  12330. if( empty( $_POST['coupon_category'] ) ) {
  12331.  
  12332. $error[] = __('Please choose a Product Category to apply the coupon to', 'mp');
  12333.  
  12334. }
  12335.  
  12336. break;
  12337.  
  12338.  
  12339.  
  12340. case 'product':
  12341.  
  12342. $coupons[$new_coupon_code]['applies_to']['type'] = $_POST['applies_to'];
  12343.  
  12344. $coupons[$new_coupon_code]['applies_to']['id'] = $_POST['coupon_product'];
  12345.  
  12346. if( empty( $_POST['coupon_product'] ) ) {
  12347.  
  12348. $error[] = __('Please choose an Individual Product to apply the coupon to', 'mp');
  12349.  
  12350. }
  12351.  
  12352. break;
  12353.  
  12354.  
  12355.  
  12356. }
  12357.  
  12358.  
  12359.  
  12360.  
  12361.  
  12362. if (!$error) {
  12363.  
  12364. update_option('mp_coupons', $coupons);
  12365.  
  12366. $new_coupon_code = '';
  12367.  
  12368. echo '<div class="updated fade"><p>'.__('Coupon succesfully saved.', 'mp').'</p></div>';
  12369.  
  12370. }
  12371.  
  12372. }
  12373.  
  12374.  
  12375.  
  12376. //if editing a coupon
  12377.  
  12378. $new_coupon_code = isset($_GET['code']) ? $_GET['code'] : null;
  12379.  
  12380. ?>
  12381.  
  12382. <script type="text/javascript">
  12383.  
  12384. jQuery(document).ready(function ($) {
  12385.  
  12386. jQuery.datepicker.setDefaults(jQuery.datepicker.regional['<?php echo $this->language; ?>']);
  12387.  
  12388. jQuery('.pickdate').datepicker({dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, minDate: 0, firstDay: <?php echo (get_option('start_of_week')=='0') ? 7 : get_option('start_of_week'); ?>});
  12389.  
  12390. });
  12391.  
  12392. </script>
  12393.  
  12394. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/service.png'; ?>" /></div>
  12395.  
  12396. <h2><?php _e('Coupons', 'mp') ?></h2>
  12397.  
  12398. <p><?php _e('You can create, delete, or update coupon codes for your store here.', 'mp') ?></p>
  12399.  
  12400.  
  12401.  
  12402. <?php
  12403.  
  12404. $apage = isset( $_GET['apage'] ) ? intval( $_GET['apage'] ) : 1;
  12405.  
  12406. $num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 10;
  12407.  
  12408.  
  12409.  
  12410. $coupon_list = get_option('mp_coupons');
  12411.  
  12412. $total = (is_array($coupon_list)) ? count($coupon_list) : 0;
  12413.  
  12414.  
  12415.  
  12416. if ($total)
  12417.  
  12418. $coupon_list = array_slice($coupon_list, intval(($apage-1) * $num), intval($num), true);
  12419.  
  12420.  
  12421.  
  12422. $coupon_navigation = paginate_links( array(
  12423.  
  12424. 'base' => add_query_arg( 'apage', '%#%' ),
  12425.  
  12426. // 'base' => add_query_arg( 'apage', '%#%' ).$url2, //@todo: What is $url2???
  12427.  
  12428. 'format' => '',
  12429.  
  12430. 'total' => ceil($total / $num),
  12431.  
  12432. 'current' => $apage
  12433.  
  12434. ));
  12435.  
  12436. $page_link = ($apage > 1) ? '&amp;apage='.$apage : '';
  12437.  
  12438. ?>
  12439.  
  12440.  
  12441.  
  12442. <form id="form-coupon-list" action="edit.php?post_type=product&amp;page=marketpress&amp;tab=coupons<?php echo $page_link; ?>" method="post">
  12443.  
  12444. <?php wp_nonce_field('mp_coupons') ?>
  12445.  
  12446. <div class="tablenav">
  12447.  
  12448. <?php if ( $coupon_navigation ) echo "<div class='tablenav-pages'>$coupon_navigation</div>"; ?>
  12449.  
  12450.  
  12451.  
  12452. <div class="alignleft">
  12453.  
  12454. <input type="submit" value="<?php _e('Delete', 'mp') ?>" name="allcoupon_delete" class="button-secondary delete" />
  12455.  
  12456. <br class="clear" />
  12457.  
  12458. </div>
  12459.  
  12460. </div>
  12461.  
  12462.  
  12463.  
  12464. <br class="clear" />
  12465.  
  12466.  
  12467.  
  12468. <?php
  12469.  
  12470. // define the columns to display, the syntax is 'internal name' => 'display name'
  12471.  
  12472. $posts_columns = array(
  12473.  
  12474. 'code' => __('Coupon Code', 'mp'),
  12475.  
  12476. 'discount' => __('Discount', 'mp'),
  12477.  
  12478. 'start' => __('Start Date', 'mp'),
  12479.  
  12480. 'end' => __('Expire Date', 'mp'),
  12481.  
  12482. 'used' => __('Used', 'mp'),
  12483.  
  12484. 'remaining' => __('Remaining Uses', 'mp'),
  12485.  
  12486. 'applies_to' => __('Applies to', 'mp'),
  12487.  
  12488. 'edit' => __('Edit', 'mp')
  12489.  
  12490. );
  12491.  
  12492. ?>
  12493.  
  12494.  
  12495.  
  12496. <table width="100%" cellpadding="3" cellspacing="3" class="widefat">
  12497.  
  12498. <thead>
  12499.  
  12500. <tr>
  12501.  
  12502. <th scope="col" class="check-column"><input type="checkbox" /></th>
  12503.  
  12504. <?php foreach($posts_columns as $column_id => $column_display_name) {
  12505.  
  12506. $col_url = $column_display_name;
  12507.  
  12508. ?>
  12509.  
  12510. <th scope="col"><?php echo $col_url ?></th>
  12511.  
  12512. <?php } ?>
  12513.  
  12514. </tr>
  12515.  
  12516. </thead>
  12517.  
  12518. <tbody id="the-list">
  12519.  
  12520. <?php
  12521.  
  12522. if ( is_array($coupon_list) && count($coupon_list) ) {
  12523.  
  12524. $bgcolor = $class = '';
  12525.  
  12526. foreach ($coupon_list as $coupon_code => $coupon) {
  12527.  
  12528.  
  12529.  
  12530. $class = ('alternate' == $class) ? '' : 'alternate';
  12531.  
  12532.  
  12533.  
  12534. //assign classes based on coupon availability
  12535.  
  12536. $class = ($this->check_coupon($coupon_code)) ? $class . ' coupon-active' : $class . ' coupon-inactive';
  12537.  
  12538.  
  12539.  
  12540. echo '<tr class="'.$class.' blog-row">
  12541.  
  12542. <th scope="row" class="check-column">
  12543.  
  12544. <input type="checkbox" name="coupons_checks[]"" value="'.$coupon_code.'" />
  12545.  
  12546. </th>';
  12547.  
  12548.  
  12549.  
  12550. foreach( $posts_columns as $column_name=>$column_display_name ) {
  12551.  
  12552. switch($column_name) {
  12553.  
  12554. case 'code': ?>
  12555.  
  12556. <th scope="row">
  12557.  
  12558. <?php echo $coupon_code; ?>
  12559.  
  12560. </th>
  12561.  
  12562. <?php
  12563.  
  12564. break;
  12565.  
  12566.  
  12567.  
  12568. case 'discount': ?>
  12569.  
  12570. <th scope="row">
  12571.  
  12572. <?php
  12573.  
  12574. if ($coupon['discount_type'] == 'pct') {
  12575.  
  12576. echo $coupon['discount'].'%';
  12577.  
  12578. } else if ($coupon['discount_type'] == 'amt') {
  12579.  
  12580. echo $this->format_currency('', $coupon['discount']);
  12581.  
  12582. }
  12583.  
  12584. ?>
  12585.  
  12586. </th>
  12587.  
  12588. <?php
  12589.  
  12590. break;
  12591.  
  12592.  
  12593.  
  12594. case 'start': ?>
  12595.  
  12596. <th scope="row">
  12597.  
  12598. <?php echo date_i18n( get_option('date_format'), $coupon['start'] ); ?>
  12599.  
  12600. </th>
  12601.  
  12602. <?php
  12603.  
  12604. break;
  12605.  
  12606.  
  12607.  
  12608. case 'end': ?>
  12609.  
  12610. <th scope="row">
  12611.  
  12612. <?php echo ($coupon['end']) ? date_i18n( get_option('date_format'), $coupon['end'] ) : __('No End', 'mp'); ?>
  12613.  
  12614. </th>
  12615.  
  12616. <?php
  12617.  
  12618. break;
  12619.  
  12620.  
  12621.  
  12622. case 'used': ?>
  12623.  
  12624. <th scope="row">
  12625.  
  12626. <?php echo isset($coupon['used']) ? number_format_i18n($coupon['used']) : 0; ?>
  12627.  
  12628. </th>
  12629.  
  12630. <?php
  12631.  
  12632. break;
  12633.  
  12634.  
  12635.  
  12636. case 'remaining': ?>
  12637.  
  12638. <th scope="row">
  12639.  
  12640. <?php
  12641.  
  12642. if ($coupon['uses'])
  12643.  
  12644. echo number_format_i18n(intval($coupon['uses']) - intval(@$coupon['used']));
  12645.  
  12646. else
  12647.  
  12648. _e('Unlimited', 'mp');
  12649.  
  12650. ?>
  12651.  
  12652. </th>
  12653.  
  12654. <?php
  12655.  
  12656. break;
  12657.  
  12658.  
  12659.  
  12660.  
  12661.  
  12662. // RW -
  12663.  
  12664. case 'applies_to':
  12665.  
  12666. ?>
  12667.  
  12668. <th scope="row">
  12669.  
  12670. <?php
  12671.  
  12672. if( !empty( $coupon['applies_to'] ) ) {
  12673.  
  12674. $type = $coupon['applies_to']['type'];
  12675.  
  12676. $id = $coupon['applies_to']['id'];
  12677.  
  12678. //check to make sure the category or product still exists
  12679.  
  12680. $details = ( $type == 'category') ? get_term($id , 'product_category'): get_post( $id );
  12681.  
  12682. if(is_null( $details ) ) {
  12683.  
  12684. $item = ( $type == 'category') ? 'Category' : 'Product';
  12685.  
  12686. printf( __( 'Associated %s Deleted', $item , 'mp' ), $item );
  12687.  
  12688. }else{
  12689.  
  12690. $name = ( $type == 'category') ? $details->name : $details->post_title;
  12691.  
  12692. $display = ( $type == 'category') ? 'All %s' : '%s';
  12693.  
  12694. printf( __( $display, $name, 'mp' ), $name );
  12695.  
  12696. }
  12697.  
  12698. }else{
  12699.  
  12700. _e('All Products','mp');
  12701.  
  12702. }
  12703.  
  12704. ?>
  12705.  
  12706. </th>
  12707.  
  12708. <?php
  12709.  
  12710. break;
  12711.  
  12712. // /RW
  12713.  
  12714.  
  12715.  
  12716. case 'edit': ?>
  12717.  
  12718. <th scope="row">
  12719.  
  12720. <a href="edit.php?post_type=product&amp;page=marketpress&amp;tab=coupons<?php echo $page_link; ?>&amp;code=<?php echo $coupon_code; ?>#add_coupon"><?php _e('Edit', 'mp') ?>&raquo;</a>
  12721.  
  12722. </th>
  12723.  
  12724. <?php
  12725.  
  12726. break;
  12727.  
  12728.  
  12729.  
  12730. }
  12731.  
  12732. }
  12733.  
  12734. ?>
  12735.  
  12736. </tr>
  12737.  
  12738. <?php
  12739.  
  12740. }
  12741.  
  12742. } else {
  12743.  
  12744. $bgcolor = ''; ?>
  12745.  
  12746. <tr style='background-color: <?php echo $bgcolor; ?>'>
  12747.  
  12748. <td colspan="7"><?php _e('No coupons yet.', 'mp') ?></td>
  12749.  
  12750. </tr>
  12751.  
  12752. <?php
  12753.  
  12754. } // end if coupons
  12755.  
  12756. ?>
  12757.  
  12758.  
  12759.  
  12760. </tbody>
  12761.  
  12762. <tfoot>
  12763.  
  12764. <tr>
  12765.  
  12766. <th scope="col" class="check-column"><input type="checkbox" /></th>
  12767.  
  12768. <?php foreach($posts_columns as $column_id => $column_display_name) {
  12769.  
  12770. $col_url = $column_display_name;
  12771.  
  12772. ?>
  12773.  
  12774. <th scope="col"><?php echo $col_url ?></th>
  12775.  
  12776. <?php } ?>
  12777.  
  12778. </tr>
  12779.  
  12780. </tfoot>
  12781.  
  12782. </table>
  12783.  
  12784.  
  12785.  
  12786. <div class="tablenav">
  12787.  
  12788. <?php if ( $coupon_navigation ) echo "<div class='tablenav-pages'>$coupon_navigation</div>"; ?>
  12789.  
  12790. </div>
  12791.  
  12792.  
  12793.  
  12794. <div id="poststuff" class="metabox-holder mp-settings">
  12795.  
  12796.  
  12797.  
  12798. <div class="postbox">
  12799.  
  12800. <h3 class='hndle'><span>
  12801.  
  12802. <?php
  12803.  
  12804. if ( isset($_GET['code']) || (isset( $error ) && $error) ) {
  12805.  
  12806. _e('Edit Coupon', 'mp');
  12807.  
  12808. } else {
  12809.  
  12810. _e('Add Coupon', 'mp');
  12811.  
  12812. }
  12813.  
  12814. ?></span></h3>
  12815.  
  12816. <div class="inside">
  12817.  
  12818. <?php
  12819.  
  12820. //display error message if it exists
  12821.  
  12822. if ( isset( $error ) && $error ) {
  12823.  
  12824. ?><div class="error"><p><?php echo implode("<br>\n", $error); ?></p></div><?php
  12825.  
  12826. }
  12827.  
  12828.  
  12829.  
  12830. //setup defaults
  12831.  
  12832. if (isset($coupons[$new_coupon_code]))
  12833.  
  12834. $discount = (isset($coupons[$new_coupon_code]['discount']) && isset($coupons[$new_coupon_code]['discount_type']) && $coupons[$new_coupon_code]['discount_type'] == 'amt') ? round($coupons[$new_coupon_code]['discount'], 2) : $coupons[$new_coupon_code]['discount'];
  12835.  
  12836. else
  12837.  
  12838. $discount = '';
  12839.  
  12840. $discount_type = isset($coupons[$new_coupon_code]['discount_type']) ? $coupons[$new_coupon_code]['discount_type'] : '';
  12841.  
  12842. $start = !empty($coupons[$new_coupon_code]['start']) ? date('Y-m-d', $coupons[$new_coupon_code]['start']) : date('Y-m-d');
  12843.  
  12844. $end = !empty($coupons[$new_coupon_code]['end']) ? date('Y-m-d', $coupons[$new_coupon_code]['end']) : '';
  12845.  
  12846. $uses = isset($coupons[$new_coupon_code]['uses']) ? $coupons[$new_coupon_code]['uses'] : '';
  12847.  
  12848. //
  12849.  
  12850. $applies_to = ( isset($coupons[$new_coupon_code]['applies_to']['type'] ) ) ? $coupons[$new_coupon_code]['applies_to']['type'] : 'all';
  12851.  
  12852. $applies_to_id = ( isset( $coupons[$new_coupon_code]['applies_to']['id'] ) ) ? $coupons[$new_coupon_code]['applies_to']['id'] : '';
  12853.  
  12854. ?>
  12855.  
  12856. <table id="add_coupon">
  12857.  
  12858. <thead>
  12859.  
  12860. <tr>
  12861.  
  12862. <th>
  12863.  
  12864. <?php _e('Coupon Code', 'mp') ?><br />
  12865.  
  12866. <small style="font-weight: normal;"><?php _e('Letters and Numbers only', 'mp') ?></small>
  12867.  
  12868. </th>
  12869.  
  12870. <th><?php _e('Discount', 'mp') ?></th>
  12871.  
  12872. <th><?php _e('Start Date', 'mp') ?></th>
  12873.  
  12874. <th>
  12875.  
  12876. <?php _e('Expire Date', 'mp') ?><br />
  12877.  
  12878. <small style="font-weight: normal;"><?php _e('No end if blank', 'mp') ?></small>
  12879.  
  12880. </th>
  12881.  
  12882. <th>
  12883.  
  12884. <?php _e('Allowed Uses', 'mp') ?><br />
  12885.  
  12886. <small style="font-weight: normal;"><?php _e('Unlimited if blank', 'mp') ?></small>
  12887.  
  12888. </th>
  12889.  
  12890. <!-- category/listing -->
  12891.  
  12892. <th>
  12893.  
  12894. <?php _e('Applies To', 'mp');?>
  12895.  
  12896. </th>
  12897.  
  12898. <!-- /category/listing -->
  12899.  
  12900. </tr>
  12901.  
  12902. </thead>
  12903.  
  12904. <tbody>
  12905.  
  12906. <tr>
  12907.  
  12908. <td>
  12909.  
  12910. <input value="<?php echo $new_coupon_code ?>" name="coupon_code" type="text" style="text-transform: uppercase;" />
  12911.  
  12912. </td>
  12913.  
  12914. <td>
  12915.  
  12916. <input value="<?php echo $discount; ?>" size="3" name="discount" type="text" />
  12917.  
  12918. <select name="discount_type">
  12919.  
  12920. <option value="amt"<?php selected($discount_type, 'amt') ?>><?php echo $this->format_currency(); ?></option>
  12921.  
  12922. <option value="pct"<?php selected($discount_type, 'pct') ?>>%</option>
  12923.  
  12924. </select>
  12925.  
  12926. </td>
  12927.  
  12928. <td>
  12929.  
  12930. <input value="<?php echo $start; ?>" class="pickdate" size="11" name="start" type="text" />
  12931.  
  12932. </td>
  12933.  
  12934. <td>
  12935.  
  12936. <input value="<?php echo $end; ?>" class="pickdate" size="11" name="end" type="text" />
  12937.  
  12938. </td>
  12939.  
  12940. <td>
  12941.  
  12942. <input value="<?php echo $uses; ?>" size="4" name="uses" type="text" />
  12943.  
  12944. </td>
  12945.  
  12946. <td>
  12947.  
  12948. <select id="applies_to" name="applies_to">
  12949.  
  12950. <option value="all" <?php selected($applies_to, 'all');?>><?php _e('All Products','mp');?></option>
  12951.  
  12952. <option value="category" <?php selected($applies_to, 'category');?>><?php _e('Product Category','mp');?></option>
  12953.  
  12954. <option value="product" <?php selected($applies_to, 'product');?>><?php _e('Product','mp');?></option>
  12955.  
  12956. </select>
  12957.  
  12958. <script type="text/javascript">
  12959.  
  12960. jQuery(document).ready(function ($) {
  12961.  
  12962. $('#applies_to').change(function(){
  12963.  
  12964. var type = 'coupon_' + $(this).val();
  12965.  
  12966. switch(type) {
  12967.  
  12968. case 'coupon_all':
  12969.  
  12970. $('#coupon_category').hide();
  12971.  
  12972. $('#coupon_product').hide();
  12973.  
  12974. break;
  12975.  
  12976. case 'coupon_category':
  12977.  
  12978. $('#coupon_category').show();
  12979.  
  12980. $('#coupon_product').hide();
  12981.  
  12982. break;
  12983.  
  12984. case 'coupon_product':
  12985.  
  12986. $('#coupon_category').hide();
  12987.  
  12988. $('#coupon_product').show();
  12989.  
  12990. break;
  12991.  
  12992. default:
  12993.  
  12994. }
  12995.  
  12996. });
  12997.  
  12998. })
  12999.  
  13000. </script>
  13001.  
  13002. <?php
  13003.  
  13004. //get all the product categories
  13005.  
  13006. $product_cats = get_terms( array( 'product_category'), array( 'hide_empty' => false ) );
  13007.  
  13008. if( !is_wp_error( $product_cats ) && count( $product_cats ) > 0 ) {
  13009.  
  13010. $cat_style = ( $applies_to == 'category' ) ? '' : 'style="display:none;"';
  13011.  
  13012.  
  13013.  
  13014. $cat_select = '<select name="coupon_category" id="coupon_category" '. $cat_style .' >%s</select>';
  13015.  
  13016. $cat_options = '';
  13017.  
  13018. foreach($product_cats as $cat) {
  13019.  
  13020. $cat_options .= '<option value="'.$cat->term_id.'" '. selected( $applies_to_id, $cat->term_id, false ). ' >'.$cat->name.'</option>';
  13021.  
  13022. }
  13023.  
  13024. printf( $cat_select, $cat_options );
  13025.  
  13026. }else{
  13027.  
  13028. _e('No Product Categories','mp');
  13029.  
  13030. }
  13031.  
  13032.  
  13033.  
  13034. //get all the products
  13035.  
  13036.  
  13037.  
  13038. $products = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => -1 ) );
  13039.  
  13040. if( !is_wp_error( $products ) ) {
  13041.  
  13042. if( $products->post_count > 500) {
  13043.  
  13044. ?>
  13045.  
  13046. <label id="coupon_product" <?php echo ( $applies_to == 'product' ) ? '' : 'style="display:none;"';?>><?php _e('Post ID','mp');?>
  13047.  
  13048. <input type="text" value="<?php echo ( $applies_to == 'product' ) ? $applies_to_id : ''; ?>" name="coupon_product" />
  13049.  
  13050. </label>
  13051.  
  13052. <?php
  13053.  
  13054. }else{
  13055.  
  13056. $style = ( $applies_to == 'category' ) ? '' : 'style="display:none;"';
  13057.  
  13058. $product_select = '<select name="coupon_product" id="coupon_product" '. $style .' >%s</select>';
  13059.  
  13060. $product_options = '';
  13061.  
  13062. foreach($products->posts as $product) {
  13063.  
  13064. $product_options .= '<option value="'.$product->ID.'" '. selected( $applies_to_id, $product->ID, false ). ' >'.$product->post_title.'</option>';
  13065.  
  13066. }
  13067.  
  13068. printf( $product_select, $product_options );
  13069.  
  13070. }
  13071.  
  13072. }
  13073.  
  13074. ?>
  13075.  
  13076. </td>
  13077.  
  13078. </tr>
  13079.  
  13080. </tbody>
  13081.  
  13082. </table>
  13083.  
  13084.  
  13085.  
  13086. <p class="submit">
  13087.  
  13088. <input class="button-primary" type="submit" name="submit_settings" value="<?php _e('Save Coupon', 'mp') ?>" />
  13089.  
  13090. </p>
  13091.  
  13092. </div>
  13093.  
  13094. </div>
  13095.  
  13096.  
  13097.  
  13098. </div>
  13099.  
  13100. </form>
  13101.  
  13102. <?php
  13103.  
  13104. break;
  13105.  
  13106.  
  13107.  
  13108.  
  13109.  
  13110. //---------------------------------------------------//
  13111.  
  13112. case "presentation":
  13113.  
  13114.  
  13115.  
  13116. //save settings
  13117.  
  13118. if (isset($_POST['marketplace_settings'])) {
  13119.  
  13120. //get old store slug
  13121.  
  13122. $old_slug = $this->get_setting('slugs->store');
  13123.  
  13124.  
  13125.  
  13126. //filter slugs
  13127.  
  13128. $_POST['mp']['slugs'] = array_map('sanitize_title', (array)$_POST['mp']['slugs']);
  13129.  
  13130.  
  13131.  
  13132. // Fixing http://premium.wpmudev.org/forums/topic/store-page-content-overwritten
  13133.  
  13134. $new_slug = $_POST['mp']['slugs']['store'];
  13135.  
  13136. $new_post_id = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s AND post_type = 'page'", $new_slug) );
  13137.  
  13138.  
  13139.  
  13140. if ($new_slug != $old_slug && $new_post_id != 0) {
  13141.  
  13142. echo '<div class="error fade"><p>'.__('Store base URL conflicts with another page', 'mp').'</p></div>';
  13143.  
  13144. } else {
  13145.  
  13146. $settings = array_merge($settings, apply_filters('mp_presentation_settings_filter', $_POST['mp']));
  13147.  
  13148. update_option('mp_settings', $settings);
  13149.  
  13150.  
  13151.  
  13152. $this->create_store_page($old_slug);
  13153.  
  13154.  
  13155.  
  13156. //schedule flush rewrite rules due to product slugs on next page load (too late to do it here)
  13157.  
  13158. update_option('mp_flush_rewrite', 1);
  13159.  
  13160.  
  13161.  
  13162. echo '<div class="updated fade"><p>'.__('Settings saved.', 'mp').'</p></div>';
  13163.  
  13164. }
  13165.  
  13166. }
  13167.  
  13168. ?>
  13169.  
  13170. <script type="text/javascript">
  13171.  
  13172. jQuery(document).ready(function($){
  13173.  
  13174. $('input[name="mp[related_products][show]"]').change(function(){
  13175.  
  13176. var $this = $(this),
  13177.  
  13178. $section = $('.presentation-related-products-settings');
  13179.  
  13180.  
  13181.  
  13182. if ( $this.val() == 1 )
  13183.  
  13184. $section.slideDown(300);
  13185.  
  13186. else
  13187.  
  13188. $section.slideUp(300);
  13189.  
  13190. });
  13191.  
  13192. });
  13193.  
  13194. </script>
  13195.  
  13196. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/my_work.png'; ?>" /></div>
  13197.  
  13198. <h2><?php _e('Presentation Settings', 'mp'); ?></h2>
  13199.  
  13200. <div id="poststuff" class="metabox-holder mp-settings">
  13201.  
  13202.  
  13203.  
  13204. <form method="post" action="edit.php?post_type=product&amp;page=marketpress&amp;tab=presentation">
  13205.  
  13206. <input type="hidden" name="marketplace_settings" value="1" />
  13207.  
  13208.  
  13209.  
  13210. <div class="postbox presentation-general-settings">
  13211.  
  13212. <h3 class='hndle'><span><?php _e('General Settings', 'mp') ?></span></h3>
  13213.  
  13214. <div class="inside">
  13215.  
  13216. <table class="form-table">
  13217.  
  13218. <tr>
  13219.  
  13220. <th scope="row"><?php _e('Store Style', 'mp') ?></th>
  13221.  
  13222. <td>
  13223.  
  13224. <?php if ( defined( 'MP_LITE' ) ) { ?>
  13225.  
  13226. <a class="mp-pro-update" href="http://premium.wpmudev.org/project/e-commerce/" title="<?php _e('Upgrade Now', 'mp'); ?> &raquo;"><?php _e('Upgrade to enable all styles &raquo;', 'mp'); ?></a><br />
  13227.  
  13228. <?php } ?>
  13229.  
  13230. <?php $this->store_themes_select(); ?>
  13231.  
  13232. <br /><span class="description"><?php _e('This option changes the built-in css styles for store pages.', 'mp') ?></span>
  13233.  
  13234. <?php if ((is_multisite() && is_super_admin()) || !is_multisite()) { ?>
  13235.  
  13236. <br /><span class="description"><?php printf(__('For a custom css style, save your css file with the "MarketPress Style: NAME" header in the "%s/marketpress-styles/" folder and it will appear in this list so you may select it. You can also select "None" and create custom theme templates and css to make your own completely unique store design. More information on that <a href="%sthemes/Themeing_MarketPress.txt">here &raquo;</a>', 'mp'), WP_CONTENT_DIR, $this->plugin_url); ?></span>
  13237.  
  13238. <h4><?php _e('Full-featured MarketPress Themes:', 'mp') ?></h4>
  13239.  
  13240. <div class="mp-theme-preview"><a title="<?php _e('Download Now &raquo;', 'mp') ?>" href="http://premium.wpmudev.org/project/frame-market-theme/"><img alt="FrameMarket Theme" src="http://premium.wpmudev.org/wp-content/projects/219/listing-image-thumb.png" />
  13241.  
  13242. <strong><?php _e('FrameMarket/GridMarket', 'mp') ?></strong></a><br />
  13243.  
  13244. <?php _e('The ultimate MarkePress theme brings visual perfection to WordPress e-commerce. This professional front-end does all the work for you!', 'mp') ?></div>
  13245.  
  13246. <div class="mp-theme-preview"><a title="<?php _e('Download Now &raquo;', 'mp') ?>" href="http://premium.wpmudev.org/project/simplemarket/"><img alt="SimpleMarket Theme" src="http://premium.wpmudev.org/wp-content/projects/237/listing-image-thumb.png" />
  13247.  
  13248. <strong><?php _e('SimpleMarket', 'mp') ?></strong></a><br />
  13249.  
  13250. <?php _e('The SimpleMarket Theme uses an HTML 5 responsive design so your e-commerce site looks great across all screen-sizes and devices such as smartphones or tablets!', 'mp') ?></div>
  13251.  
  13252. <?php } ?>
  13253.  
  13254. </td>
  13255.  
  13256. </tr>
  13257.  
  13258. <tr>
  13259.  
  13260. <th scope="row"><?php _e('Show breadcrumbs for purchase process?', 'mp') ?></th>
  13261.  
  13262. <td>
  13263.  
  13264. <label><input value="1" name="mp[show_purchase_breadcrumbs]" type="radio"<?php checked($this->get_setting('show_purchase_breadcrumbs'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13265.  
  13266. <label><input value="0" name="mp[show_purchase_breadcrumbs]" type="radio"<?php checked($this->get_setting('show_purchase_breadcrumbs'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  13267.  
  13268. <br /><span class="description"><?php _e('Show previous, current and next steps when a customer is purchasing their cart, shown below the title.', 'mp') ?></span>
  13269.  
  13270. </td>
  13271.  
  13272. </tr>
  13273.  
  13274. </table>
  13275.  
  13276. </div>
  13277.  
  13278. </div>
  13279.  
  13280.  
  13281.  
  13282. <div class="postbox presentation-single-product-settings">
  13283.  
  13284. <h3 class='hndle'><span><?php _e('Single Product Settings', 'mp') ?></span></h3>
  13285.  
  13286. <div class="inside">
  13287.  
  13288. <table class="form-table">
  13289.  
  13290. <tr>
  13291.  
  13292. <th scope="row"><?php _e('Checkout Button Type', 'mp') ?></th>
  13293.  
  13294. <td>
  13295.  
  13296. <label><input value="addcart" name="mp[product_button_type]" type="radio"<?php checked($this->get_setting('product_button_type'), 'addcart') ?> /> <?php _e('Add To Cart', 'mp') ?></label><br />
  13297.  
  13298. <label><input value="buynow" name="mp[product_button_type]" type="radio"<?php checked($this->get_setting('product_button_type'), 'buynow') ?> /> <?php _e('Buy Now', 'mp') ?></label>
  13299.  
  13300. </td>
  13301.  
  13302. </tr>
  13303.  
  13304. <tr>
  13305.  
  13306. <th scope="row"><?php _e('Show Quantity Option', 'mp') ?></th>
  13307.  
  13308. <td>
  13309.  
  13310. <label><input value="1" name="mp[show_quantity]" type="radio"<?php checked($this->get_setting('show_quantity'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13311.  
  13312. <label><input value="0" name="mp[show_quantity]" type="radio"<?php checked($this->get_setting('show_quantity'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  13313.  
  13314. </td>
  13315.  
  13316. </tr>
  13317.  
  13318. <tr>
  13319.  
  13320. <th scope="row"><?php _e('Show Product Image', 'mp') ?></th>
  13321.  
  13322. <td>
  13323.  
  13324. <label><input value="1" name="mp[show_img]" type="radio"<?php checked($this->get_setting('show_img'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13325.  
  13326. <label><input value="0" name="mp[show_img]" type="radio"<?php checked($this->get_setting('show_img'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  13327.  
  13328. </td>
  13329.  
  13330. </tr>
  13331.  
  13332. <tr>
  13333.  
  13334. <th scope="row"><?php _e('Product Image Size', 'mp') ?></th>
  13335.  
  13336. <td>
  13337.  
  13338. <label><input value="thumbnail" name="mp[product_img_size]" type="radio"<?php checked($this->get_setting('product_img_size'), 'thumbnail') ?> /> <a href="options-media.php"><?php _e('WP Thumbnail size', 'mp') ?></a></label><br />
  13339.  
  13340. <label><input value="medium" name="mp[product_img_size]" type="radio"<?php checked($this->get_setting('product_img_size'), 'medium') ?> /> <a href="options-media.php"><?php _e('WP Medium size', 'mp') ?></a></label><br />
  13341.  
  13342. <label><input value="large" name="mp[product_img_size]" type="radio"<?php checked($this->get_setting('product_img_size'), 'large') ?> /> <a href="options-media.php"><?php _e('WP Large size', 'mp') ?></a></label><br />
  13343.  
  13344. <label><input value="custom" name="mp[product_img_size]" type="radio"<?php checked($this->get_setting('product_img_size'), 'custom') ?> /> <?php _e('Custom', 'mp') ?></label>:&nbsp;&nbsp;
  13345.  
  13346. <label><?php _e('Height', 'mp') ?><input size="3" name="mp[product_img_height]" value="<?php echo esc_attr($this->get_setting('product_img_height')) ?>" type="text" /></label>&nbsp;
  13347.  
  13348. <label><?php _e('Width', 'mp') ?><input size="3" name="mp[product_img_width]" value="<?php echo esc_attr($this->get_setting('product_img_width')) ?>" type="text" /></label>
  13349.  
  13350. </td>
  13351.  
  13352. </tr>
  13353.  
  13354. <tr>
  13355.  
  13356. <th scope="row"><?php _e('Product Image Alignment', 'mp'); ?></th>
  13357.  
  13358. <td>
  13359.  
  13360. <?php
  13361.  
  13362. $alignments = array(
  13363.  
  13364. 'alignnone' => __('None', 'mp'),
  13365.  
  13366. 'aligncenter' => __('Center', 'mp'),
  13367.  
  13368. 'alignleft' => __('Left', 'mp'),
  13369.  
  13370. 'alignright' => __('Right', 'mp'),
  13371.  
  13372. );
  13373.  
  13374. foreach ( $alignments as $value => $label ) :
  13375.  
  13376. $input_id = 'mp-image-align-single' . $value; ?>
  13377.  
  13378. <label for="<?php echo $input_id; ?>"><input value="<?php echo $value; ?>" type="radio" name="mp[image_alignment_single]" id="<?php echo $input_id; ?>" <?php checked($this->get_setting('image_alignment_single'), $value); ?> /> <?php echo $label; ?></label><?php
  13379.  
  13380. endforeach; ?>
  13381.  
  13382. </td>
  13383.  
  13384. </tr>
  13385.  
  13386. <tr>
  13387.  
  13388. <th scope="row"><?php _e('Show Image Lightbox', 'mp') ?></th>
  13389.  
  13390. <td>
  13391.  
  13392. <label><input value="1" name="mp[show_lightbox]" type="radio"<?php checked($this->get_setting('show_lightbox'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13393.  
  13394. <label><input value="0" name="mp[show_lightbox]" type="radio"<?php checked($this->get_setting('show_lightbox'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  13395.  
  13396. <br /><span class="description"><?php _e('Makes clicking the single product image open an instant zoomed preview.', 'mp') ?></span>
  13397.  
  13398. </td>
  13399.  
  13400. </tr>
  13401.  
  13402. <tr>
  13403.  
  13404. <th scope="row"><?php _e('Disable Large Image display', 'mp') ?></th>
  13405.  
  13406. <td>
  13407.  
  13408. <label><input value="1" name="mp[disable_large_image]" type="radio"<?php checked($this->get_setting('disable_large_image'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13409.  
  13410. <label><input value="0" name="mp[disable_large_image]" type="radio"<?php checked($this->get_setting('disable_large_image'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  13411.  
  13412. <br /><span class="description"><?php _e('Disables "Display Larger Image" function. Clicking a product image will not display a larger image.', 'mp') ?></span>
  13413.  
  13414. </td>
  13415.  
  13416. </tr>
  13417.  
  13418. <tr>
  13419.  
  13420. <th scope="row"><?php _e('Show Related Products', 'mp') ?></th>
  13421.  
  13422. <td>
  13423.  
  13424. <label><input value="1" name="mp[related_products][show]" type="radio"<?php checked($this->get_setting('related_products->show'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13425.  
  13426. <label><input value="0" name="mp[related_products][show]" type="radio"<?php checked($this->get_setting('related_products->show'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  13427.  
  13428. </td>
  13429.  
  13430. </table>
  13431.  
  13432. </div>
  13433.  
  13434. </div>
  13435.  
  13436.  
  13437.  
  13438. <div class="postbox presentation-related-products-settings"<?php echo $this->get_setting('related_products->show', true) ? '' : ' style="display:none"'; ?>>
  13439.  
  13440. <h3 class='hndle'><span><?php _e('Related Products Settings', 'mp') ?></span></h3>
  13441.  
  13442. <div class="inside">
  13443.  
  13444. <table class="form-table">
  13445.  
  13446. <tr>
  13447.  
  13448. <th scope="row"><?php _e('Related Product Limit', 'mp') ?></th>
  13449.  
  13450. <td>
  13451.  
  13452. <label><input name="mp[related_products][show_limit]" type="text" size="2" value="<?php echo intval($this->get_setting('related_products->show_limit') ); ?>" /></label>
  13453.  
  13454. </td>
  13455.  
  13456. </tr>
  13457.  
  13458. <tr>
  13459.  
  13460. <th scope="row"><?php _e('Relate Products By', 'mp') ?></th>
  13461.  
  13462. <td>
  13463.  
  13464. <select name="mp[related_products][relate_by]">
  13465.  
  13466. <option value="both" <?php checked($this->get_setting('related_products->relate_by'), 'both'); ?>><?php _e('Category &amp; Tags', 'mp'); ?></option>
  13467.  
  13468. <option value="category" <?php checked($this->get_setting('related_products->relate_by'), 'category'); ?>><?php _e('Category Only', 'mp'); ?></option>
  13469.  
  13470. <option value="tags" <?php checked($this->get_setting('related_products->relate_by'), 'tags'); ?>><?php _e('Tags Only', 'mp'); ?></option>
  13471.  
  13472. </select>
  13473.  
  13474. </td>
  13475.  
  13476. </tr>
  13477.  
  13478. <tr>
  13479.  
  13480. <th scope="row"><?php _e('Show Related Products As Simple List', 'mp') ?></th>
  13481.  
  13482. <td>
  13483.  
  13484. <label><input value="1" name="mp[related_products][simple_list]" type="radio"<?php checked($this->get_setting('related_products->simple_list'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13485.  
  13486. <label><input value="0" name="mp[related_products][simple_list]" type="radio"<?php checked($this->get_setting('related_products->simple_list'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  13487.  
  13488. <br /><span class="description"><?php _e('Setting to "No" will use the List/Grid View setting.', 'mp') ?></span>
  13489.  
  13490. </td>
  13491.  
  13492. </tr>
  13493.  
  13494. </table>
  13495.  
  13496. </div>
  13497.  
  13498. </div>
  13499.  
  13500.  
  13501.  
  13502. <div class="postbox presentation-product-list-settings">
  13503.  
  13504. <h3 class='hndle'><span><?php _e('Product List Settings', 'mp') ?></span></h3>
  13505.  
  13506. <div class="inside">
  13507.  
  13508. <table class="form-table">
  13509.  
  13510. <tr>
  13511.  
  13512. <th scope="row"><?php _e('Product List View', 'mp') ?></th>
  13513.  
  13514. <td>
  13515.  
  13516. <label><input value="list" name="mp[list_view]" type="radio"<?php checked($this->get_setting('list_view', 'grid'), 'list') ?> /> <?php _e('List View', 'mp') ?></label><br />
  13517.  
  13518. <label><input value="grid" name="mp[list_view]" type="radio"<?php checked($this->get_setting('list_view', 'grid'), 'grid') ?> /> <?php _e('Grid View', 'mp') ?></label>
  13519.  
  13520. </td>
  13521.  
  13522. </tr>
  13523.  
  13524. <tr>
  13525.  
  13526. <th scope="row"><?php _e('Checkout Button Type', 'mp') ?></th>
  13527.  
  13528. <td>
  13529.  
  13530. <label><input value="addcart" name="mp[list_button_type]" type="radio"<?php checked($this->get_setting('list_button_type'), 'addcart') ?> /> <?php _e('Add To Cart', 'mp') ?></label><br />
  13531.  
  13532. <label><input value="buynow" name="mp[list_button_type]" type="radio"<?php checked($this->get_setting('list_button_type'), 'buynow') ?> /> <?php _e('Buy Now', 'mp') ?></label>
  13533.  
  13534. </td>
  13535.  
  13536. </tr>
  13537.  
  13538. <tr>
  13539.  
  13540. <th scope="row"><?php _e('Show Product Thumbnail', 'mp') ?></th>
  13541.  
  13542. <td>
  13543.  
  13544. <label><input value="1" name="mp[show_thumbnail]" type="radio"<?php checked($this->get_setting('show_thumbnail'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13545.  
  13546. <label><input value="0" name="mp[show_thumbnail]" type="radio"<?php checked($this->get_setting('show_thumbnail'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  13547.  
  13548. </td>
  13549.  
  13550. </tr>
  13551.  
  13552. <tr>
  13553.  
  13554. <th scope="row"><?php _e('Product Thumbnail Size', 'mp') ?></th>
  13555.  
  13556. <td>
  13557.  
  13558. <label><input value="thumbnail" name="mp[list_img_size]" type="radio"<?php checked($this->get_setting('list_img_size'), 'thumbnail') ?> /> <a href="options-media.php"><?php _e('WP Thumbnail size', 'mp') ?></a></label><br />
  13559.  
  13560. <label><input value="medium" name="mp[list_img_size]" type="radio"<?php checked($this->get_setting('list_img_size'), 'medium') ?> /> <a href="options-media.php"><?php _e('WP Medium size', 'mp') ?></a></label><br />
  13561.  
  13562. <label><input value="large" name="mp[list_img_size]" type="radio"<?php checked($this->get_setting('list_img_size'), 'large') ?> /> <a href="options-media.php"><?php _e('WP Large size', 'mp') ?></a></label><br />
  13563.  
  13564. <label><input value="custom" name="mp[list_img_size]" type="radio"<?php checked($this->get_setting('list_img_size'), 'custom') ?> /> <?php _e('Custom', 'mp') ?></label>:&nbsp;&nbsp;
  13565.  
  13566. <label><?php _e('Height', 'mp') ?><input size="3" name="mp[list_img_height]" value="<?php echo esc_attr($this->get_setting('list_img_height')) ?>" type="text" /></label>&nbsp;
  13567.  
  13568. <label><?php _e('Width', 'mp') ?><input size="3" name="mp[list_img_width]" value="<?php echo esc_attr($this->get_setting('list_img_width')) ?>" type="text" /></label>
  13569.  
  13570. </td>
  13571.  
  13572. <tr>
  13573.  
  13574. <th scope="row"><?php _e('Product Thumbnail Alignment', 'mp'); ?></th>
  13575.  
  13576. <td>
  13577.  
  13578. <?php
  13579.  
  13580. $alignments = array(
  13581.  
  13582. 'alignnone' => __('None', 'mp'),
  13583.  
  13584. 'aligncenter' => __('Center', 'mp'),
  13585.  
  13586. 'alignleft' => __('Left', 'mp'),
  13587.  
  13588. 'alignright' => __('Right', 'mp'),
  13589.  
  13590. );
  13591.  
  13592. foreach ( $alignments as $value => $label ) :
  13593.  
  13594. $input_id = 'mp-image-align-list' . $value; ?>
  13595.  
  13596. <label for="<?php echo $input_id; ?>"><input value="<?php echo $value; ?>" type="radio" name="mp[image_alignment_list]" id="<?php echo $input_id; ?>" <?php checked($this->get_setting('image_alignment_list'), $value); ?> /> <?php echo $label; ?></label><?php
  13597.  
  13598. endforeach; ?>
  13599.  
  13600. </td>
  13601.  
  13602. </tr>
  13603.  
  13604. </tr>
  13605.  
  13606. <tr>
  13607.  
  13608. <th scope="row"><?php _e('Show Excerpts', 'mp') ?></th>
  13609.  
  13610. <td>
  13611.  
  13612. <label><input value="1" name="mp[show_excerpt]" type="radio"<?php checked($this->get_setting('show_excerpt'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13613.  
  13614. <label><input value="0" name="mp[show_excerpt]" type="radio"<?php checked($this->get_setting('show_excerpt'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  13615.  
  13616. </td>
  13617.  
  13618. </tr>
  13619.  
  13620. <tr>
  13621.  
  13622. <th scope="row"><?php _e('Paginate Products', 'mp') ?></th>
  13623.  
  13624. <td>
  13625.  
  13626. <label><input value="1" name="mp[paginate]" type="radio"<?php checked($this->get_setting('paginate'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13627.  
  13628. <label><input value="0" name="mp[paginate]" type="radio"<?php checked($this->get_setting('paginate'), 0) ?> /> <?php _e('No', 'mp') ?></label>&nbsp;&nbsp;
  13629.  
  13630. <label><input value="<?php echo esc_attr($this->get_setting('per_page', 20)) ?>" name="mp[per_page]" type="text" size="2" /> <?php _e('Products per page', 'mp') ?></label>
  13631.  
  13632. </td>
  13633.  
  13634. </tr>
  13635.  
  13636. <tr>
  13637.  
  13638. <th scope="row"><?php _e('Order Products By', 'mp') ?></th>
  13639.  
  13640. <td>
  13641.  
  13642. <select name="mp[order_by]">
  13643.  
  13644. <option value="title"<?php selected($this->get_setting('order_by'), 'title') ?>><?php _e('Product Name', 'mp') ?></option>
  13645.  
  13646. <option value="date"<?php selected($this->get_setting('order_by'), 'date') ?>><?php _e('Publish Date', 'mp') ?></option>
  13647.  
  13648. <option value="ID"<?php selected($this->get_setting('order_by'), 'ID') ?>><?php _e('Product ID', 'mp') ?></option>
  13649.  
  13650. <option value="author"<?php selected($this->get_setting('order_by'), 'author') ?>><?php _e('Product Author', 'mp') ?></option>
  13651.  
  13652. <option value="sales"<?php selected($this->get_setting('order_by'), 'sales') ?>><?php _e('Number of Sales', 'mp') ?></option>
  13653.  
  13654. <option value="price"<?php selected($this->get_setting('order_by'), 'price') ?>><?php _e('Product Price', 'mp') ?></option>
  13655.  
  13656. <option value="rand"<?php selected($this->get_setting('order_by'), 'rand') ?>><?php _e('Random', 'mp') ?></option>
  13657.  
  13658. </select>
  13659.  
  13660. <label><input value="DESC" name="mp[order]" type="radio"<?php checked($this->get_setting('order'), 'DESC') ?> /> <?php _e('Descending', 'mp') ?></label>
  13661.  
  13662. <label><input value="ASC" name="mp[order]" type="radio"<?php checked($this->get_setting('order'), 'ASC') ?> /> <?php _e('Ascending', 'mp') ?></label>
  13663.  
  13664. </td>
  13665.  
  13666. </tr>
  13667.  
  13668. <tr>
  13669.  
  13670. <th scope="row"><?php _e('Show Product Filters', 'mp') ?></th>
  13671.  
  13672. <td>
  13673.  
  13674. <label><input value="1" name="mp[show_filters]" type="radio"<?php checked($this->get_setting('show_filters'), 1) ?> /> <?php _e('Yes', 'mp') ?></label>
  13675.  
  13676. <label><input value="0" name="mp[show_filters]" type="radio"<?php checked($this->get_setting('show_filters'), 0) ?> /> <?php _e('No', 'mp') ?></label>
  13677.  
  13678. <br />
  13679.  
  13680. <span class="description"><?php _e('Show "Product Category" and "Order By" filters at the top of listings pages. Uses AJAX for instant updates based on user selection.', 'mp') ?></span>
  13681.  
  13682. </td>
  13683.  
  13684. </tr>
  13685.  
  13686. </table>
  13687.  
  13688. </div>
  13689.  
  13690. </div>
  13691.  
  13692.  
  13693.  
  13694. <div class="postbox store-url-slugs">
  13695.  
  13696. <h3 class='hndle'><span><?php _e('Store URL Slugs', 'mp') ?></span> - <span class="description"><?php _e('Customizes the url structure of your store', 'mp') ?></span></h3>
  13697.  
  13698. <div class="inside">
  13699.  
  13700. <table class="form-table">
  13701.  
  13702. <tr valign="top">
  13703.  
  13704. <th scope="row"><?php _e('Store Base', 'mp') ?></th>
  13705.  
  13706. <td>/<input type="text" name="mp[slugs][store]" value="<?php echo esc_attr($this->get_setting('slugs->store')); ?>" size="20" maxlength="50" />/<br />
  13707.  
  13708. <span class="description"><?php _e('This page will be created so you can change it\'s content and the order in which it appears in navigation menus if your theme supports it.', 'mp') ?></span></td>
  13709.  
  13710. </tr>
  13711.  
  13712. <tr valign="top">
  13713.  
  13714. <th scope="row"><?php _e('Products List', 'mp') ?></th>
  13715.  
  13716. <td>/<?php echo esc_attr($this->get_setting('slugs->store')); ?>/<input type="text" name="mp[slugs][products]" value="<?php echo esc_attr($this->get_setting('slugs->products')); ?>" size="20" maxlength="50" />/</td>
  13717.  
  13718. </tr>
  13719.  
  13720. <tr valign="top">
  13721.  
  13722. <th scope="row"><?php _e('Shopping Cart Page', 'mp') ?></th>
  13723.  
  13724. <td>/<?php echo esc_attr($this->get_setting('slugs->store')); ?>/<input type="text" name="mp[slugs][cart]" value="<?php echo esc_attr($this->get_setting('slugs->cart')); ?>" size="20" maxlength="50" />/</td>
  13725.  
  13726. </tr>
  13727.  
  13728. <tr valign="top">
  13729.  
  13730. <th scope="row"><?php _e('Order Status Page', 'mp') ?></th>
  13731.  
  13732. <td>/<?php echo esc_attr($this->get_setting('slugs->store')); ?>/<input type="text" name="mp[slugs][orderstatus]" value="<?php echo esc_attr($this->get_setting('slugs->orderstatus')); ?>" size="20" maxlength="50" />/</td>
  13733.  
  13734. </tr>
  13735.  
  13736. <tr valign="top">
  13737.  
  13738. <th scope="row"><?php _e('Product Category', 'mp') ?></th>
  13739.  
  13740. <td>/<?php echo esc_attr($this->get_setting('slugs->store')); ?>/<?php echo esc_attr($this->get_setting('slugs->products')); ?>/<input type="text" name="mp[slugs][category]" value="<?php echo esc_attr($this->get_setting('slugs->category')); ?>" size="20" maxlength="50" />/</td>
  13741.  
  13742. </tr>
  13743.  
  13744. <tr valign="top">
  13745.  
  13746. <th scope="row"><?php _e('Product Tag', 'mp') ?></th>
  13747.  
  13748. <td>/<?php echo esc_attr($this->get_setting('slugs->store')); ?>/<?php echo esc_attr($this->get_setting('slugs->products')); ?>/<input type="text" name="mp[slugs][tag]" value="<?php echo esc_attr($this->get_setting('slugs->tag')); ?>" size="20" maxlength="50" />/</td>
  13749.  
  13750. </tr>
  13751.  
  13752. </table>
  13753.  
  13754. </div>
  13755.  
  13756. </div>
  13757.  
  13758.  
  13759.  
  13760. <!-- pinterest Rich Pins/oEmbed -->
  13761.  
  13762. <div class="postbox presentation-social">
  13763.  
  13764. <h3 class="hndle"><span><?php _e('Social','mp');?></span></h3>
  13765.  
  13766. <div class="inside">
  13767.  
  13768. <img src="<?php echo $this->plugin_url; ?>images/134x35_pinterest_logo.png" width="134" height="35" alt="Pinterest">
  13769.  
  13770. <table class="form-table">
  13771.  
  13772. <tr>
  13773.  
  13774. <th scope="row"><?php _e('Show "Pin It" button','mp');?></th>
  13775.  
  13776. <td>
  13777.  
  13778. <label><input value="off" name="mp[social][pinterest][show_pinit_button]" type="radio"<?php checked($this->get_setting('social->pinterest->show_pinit_button'), 'off') ?> /> <?php _e('Off', 'mp') ?></label><br/>
  13779.  
  13780. <label><input value="single_view" name="mp[social][pinterest][show_pinit_button]" type="radio"<?php checked($this->get_setting('social->pinterest->show_pinit_button'), 'single_view') ?> /> <?php _e('Single View', 'mp') ?></label><br/>
  13781.  
  13782. <label><input value="all_view" name="mp[social][pinterest][show_pinit_button]" type="radio"<?php checked($this->get_setting('social->pinterest->show_pinit_button'), 'all_view') ?> /> <?php _e('All View', 'mp') ?></label>
  13783.  
  13784. </td>
  13785.  
  13786. </tr>
  13787.  
  13788. <tr>
  13789.  
  13790. <th scope="row"><?php _e('Pin Count','mp');?></th>
  13791.  
  13792. <td>
  13793.  
  13794. <label><input value="none" name="mp[social][pinterest][show_pin_count]" type="radio"<?php checked($this->get_setting('social->pinterest->show_pin_count'), 'none') ?> /> <?php _e('None', 'mp') ?></label><br/>
  13795.  
  13796. <label><input value="above" name="mp[social][pinterest][show_pin_count]" type="radio"<?php checked($this->get_setting('social->pinterest->show_pin_count'), 'above') ?> /> <?php _e('Above', 'mp') ?></label><br/>
  13797.  
  13798. <label><input value="beside" name="mp[social][pinterest][show_pin_count]" type="radio"<?php checked($this->get_setting('social->pinterest->show_pin_count'), 'beside') ?> /> <?php _e('Beside', 'mp') ?></label>
  13799.  
  13800. </td>
  13801.  
  13802. </tr>
  13803.  
  13804. </table>
  13805.  
  13806. </div>
  13807.  
  13808. </div><!-- /pinterest Rich Pins/oEmbed -->
  13809.  
  13810. <?php do_action('mp_presentation_settings'); ?>
  13811.  
  13812.  
  13813.  
  13814. <p class="submit">
  13815.  
  13816. <input class="button-primary" type="submit" name="submit_settings" value="<?php _e('Save Changes', 'mp') ?>" />
  13817.  
  13818. </p>
  13819.  
  13820. </form>
  13821.  
  13822. </div>
  13823.  
  13824. <?php
  13825.  
  13826. break;
  13827.  
  13828.  
  13829.  
  13830.  
  13831.  
  13832. //---------------------------------------------------//
  13833.  
  13834. case "messages":
  13835.  
  13836. //save settings
  13837.  
  13838. if (isset($_POST['messages_settings'])) {
  13839.  
  13840.  
  13841.  
  13842. //remove html from emails
  13843.  
  13844. $_POST['mp']['email'] = array_map('wp_filter_nohtml_kses', (array)$_POST['mp']['email']);
  13845.  
  13846.  
  13847.  
  13848. //filter msg inputs if necessary
  13849.  
  13850. if (!current_user_can('unfiltered_html')) {
  13851.  
  13852. $_POST['mp']['msg'] = array_map('wp_kses_post', (array)$_POST['mp']['msg']);
  13853.  
  13854. }
  13855.  
  13856.  
  13857.  
  13858. //strip slashes
  13859.  
  13860. $_POST['mp']['msg'] = array_map('stripslashes', (array)$_POST['mp']['msg']);
  13861.  
  13862. $_POST['mp']['email'] = array_map('stripslashes', (array)$_POST['mp']['email']);
  13863.  
  13864.  
  13865.  
  13866. //wpautop
  13867.  
  13868. $_POST['mp']['msg'] = array_map('wpautop', (array)$_POST['mp']['msg']);
  13869.  
  13870.  
  13871.  
  13872. $settings = array_merge($settings, apply_filters('mp_messages_settings_filter', $_POST['mp']));
  13873.  
  13874. update_option('mp_settings', $settings);
  13875.  
  13876.  
  13877.  
  13878. echo '<div class="updated fade"><p>'.__('Settings saved.', 'mp').'</p></div>';
  13879.  
  13880. }
  13881.  
  13882. ?>
  13883.  
  13884. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/messages.png'; ?>" /></div>
  13885.  
  13886. <h2><?php _e('Messages Settings', 'mp'); ?></h2>
  13887.  
  13888. <div id="poststuff" class="metabox-holder mp-settings">
  13889.  
  13890.  
  13891.  
  13892. <form id="mp-messages-form" method="post" action="edit.php?post_type=product&amp;page=marketpress&amp;tab=messages">
  13893.  
  13894. <input type="hidden" name="messages_settings" value="1" />
  13895.  
  13896.  
  13897.  
  13898. <div class="postbox email-notifications">
  13899.  
  13900. <h3 class='hndle'><span><?php _e('Email Notifications', 'mp') ?></span></h3>
  13901.  
  13902. <div class="inside">
  13903.  
  13904. <table class="form-table">
  13905.  
  13906. <tr>
  13907.  
  13908. <th scope="row"><?php _e('Store Admin Email', 'mp'); ?></th>
  13909.  
  13910. <td>
  13911.  
  13912. <?php $store_email = $this->get_setting('store_email') ? $this->get_setting('store_email') : get_option("admin_email"); ?>
  13913.  
  13914. <span class="description"><?php _e('The email address that new order notifications are sent to and received from.', 'mp') ?></span><br />
  13915.  
  13916. <input type="text" name="mp[store_email]" value="<?php echo esc_attr($store_email); ?>" maxlength="150" size="50" />
  13917.  
  13918. </td>
  13919.  
  13920. </tr>
  13921.  
  13922. <tr>
  13923.  
  13924. <th scope="row"><?php _e('New Order', 'mp'); ?></th>
  13925.  
  13926. <td>
  13927.  
  13928. <span class="description"><?php _e('The email text sent to your customer to confirm a new order. These codes will be replaced with order details: CUSTOMERNAME, ORDERID, ORDERINFO, SHIPPINGINFO, PAYMENTINFO, TOTAL, TRACKINGURL, ORDERNOTES. No HTML allowed.', 'mp') ?></span><br />
  13929.  
  13930. <label><?php _e('Subject:', 'mp'); ?><br />
  13931.  
  13932. <input type="text" class="mp_emails_sub" name="mp[email][new_order_subject]" value="<?php echo esc_attr($this->get_setting('email->new_order_subject')); ?>" maxlength="150" /></label><br />
  13933.  
  13934. <label><?php _e('Text:', 'mp'); ?><br />
  13935.  
  13936. <textarea class="mp_emails_txt" name="mp[email][new_order_txt]"><?php echo esc_textarea($this->get_setting('email->new_order_txt')); ?></textarea>
  13937.  
  13938. </label>
  13939.  
  13940. </td>
  13941.  
  13942. </tr>
  13943.  
  13944. <tr>
  13945.  
  13946. <th scope="row"><?php _e('Order Shipped', 'mp'); ?></th>
  13947.  
  13948. <td>
  13949.  
  13950. <span class="description"><?php _e('The email text sent to your customer when you mark an order as "Shipped". These codes will be replaced with order details: CUSTOMERNAME, ORDERID, ORDERINFO, SHIPPINGINFO, PAYMENTINFO, TOTAL, TRACKINGURL, ORDERNOTES. No HTML allowed.', 'mp') ?></span><br />
  13951.  
  13952. <label><?php _e('Subject:', 'mp'); ?><br />
  13953.  
  13954. <input type="text" class="mp_emails_sub" name="mp[email][shipped_order_subject]" value="<?php echo esc_attr($this->get_setting('email->shipped_order_subject')); ?>" maxlength="150" /></label><br />
  13955.  
  13956. <label><?php _e('Text:', 'mp'); ?><br />
  13957.  
  13958. <textarea class="mp_emails_txt" name="mp[email][shipped_order_txt]"><?php echo esc_textarea($this->get_setting('email->shipped_order_txt')); ?></textarea>
  13959.  
  13960. </label>
  13961.  
  13962. </td>
  13963.  
  13964. </tr>
  13965.  
  13966. </table>
  13967.  
  13968. </div>
  13969.  
  13970. </div>
  13971.  
  13972.  
  13973.  
  13974. <div class="postbox mp-pages-msgs store-pages">
  13975.  
  13976. <h3 class='hndle'><span><?php _e('Store Pages', 'mp') ?></span></h3>
  13977.  
  13978. <div class="inside">
  13979.  
  13980. <table class="form-table">
  13981.  
  13982. <tr>
  13983.  
  13984. <th scope="row"><?php _e('Store Page', 'mp'); ?></th>
  13985.  
  13986. <td>
  13987.  
  13988. <span class="description"><?php _e('The main store page is an actual page on your site. You can edit it here:', 'mp') ?></span>
  13989.  
  13990. <?php
  13991.  
  13992. $post_id = get_option('mp_store_page');
  13993.  
  13994. edit_post_link(__('Edit Page &raquo;', 'mp'), '', '', $post_id);
  13995.  
  13996. ?>
  13997.  
  13998. </td>
  13999.  
  14000. </tr>
  14001.  
  14002. <tr>
  14003.  
  14004. <th scope="row"><?php _e('Product Listing Pages', 'mp'); ?></th>
  14005.  
  14006. <td>
  14007.  
  14008. <span class="description"><?php _e('Displayed at the top of the product listing pages. Optional, HTML allowed.', 'mp') ?></span><br />
  14009.  
  14010. <?php wp_editor( $this->get_setting('msg->product_list'), 'product_list', array('textarea_name'=>'mp[msg][product_list]') ); ?>
  14011.  
  14012. </td>
  14013.  
  14014. </tr>
  14015.  
  14016. <tr>
  14017.  
  14018. <th scope="row"><?php _e('Order Status Page', 'mp'); ?></th>
  14019.  
  14020. <td>
  14021.  
  14022. <span class="description"><?php _e('Displayed at the top of the Order Status page. Optional, HTML allowed.', 'mp') ?></span><br />
  14023.  
  14024. <?php wp_editor( $this->get_setting('msg->order_status'), 'order_status', array('textarea_name'=>'mp[msg][order_status]') ); ?>
  14025.  
  14026. </td>
  14027.  
  14028. </tr>
  14029.  
  14030. </table>
  14031.  
  14032. </div>
  14033.  
  14034. </div>
  14035.  
  14036.  
  14037.  
  14038. <div class="postbox mp-pages-msgs stopping-cart-pages">
  14039.  
  14040. <h3 class='hndle'><span><?php _e('Shopping Cart Pages', 'mp') ?></span></h3>
  14041.  
  14042. <div class="inside">
  14043.  
  14044. <table class="form-table">
  14045.  
  14046. <tr>
  14047.  
  14048. <th scope="row"><?php _e('Shopping Cart Page', 'mp'); ?></th>
  14049.  
  14050. <td>
  14051.  
  14052. <span class="description"><?php _e('Displayed at the top of the Shopping Cart page. Optional, HTML allowed.', 'mp') ?></span><br />
  14053.  
  14054. <?php wp_editor( $this->get_setting('msg->cart'), 'cart', array('textarea_name'=>'mp[msg][cart]') ); ?>
  14055.  
  14056. </td>
  14057.  
  14058. </tr>
  14059.  
  14060. <tr id="mp_msgs_shipping">
  14061.  
  14062. <th scope="row"><?php _e('Shipping Form Page', 'mp'); ?></th>
  14063.  
  14064. <td>
  14065.  
  14066. <span class="description"><?php _e('Displayed at the top of the Shipping Form page. Optional, HTML allowed.', 'mp') ?></span><br />
  14067.  
  14068. <?php wp_editor( $this->get_setting('msg->shipping'), 'shipping', array('textarea_name'=>'mp[msg][shipping]') ); ?>
  14069.  
  14070. </td>
  14071.  
  14072. </tr>
  14073.  
  14074. <tr>
  14075.  
  14076. <th scope="row"><?php _e('Payment Form Page', 'mp'); ?></th>
  14077.  
  14078. <td>
  14079.  
  14080. <span class="description"><?php _e('Displayed at the top of the Payment Form page. Optional, HTML allowed.', 'mp') ?></span><br />
  14081.  
  14082. <?php wp_editor( $this->get_setting('msg->checkout'), 'checkout', array('textarea_name'=>'mp[msg][checkout]') ); ?>
  14083.  
  14084. </td>
  14085.  
  14086. </tr>
  14087.  
  14088. <tr>
  14089.  
  14090. <th scope="row"><?php _e('Order Confirmation Page', 'mp'); ?></th>
  14091.  
  14092. <td>
  14093.  
  14094. <span class="description"><?php _e('Displayed at the top of the final Order Confirmation page. HTML allowed.', 'mp') ?></span><br />
  14095.  
  14096. <?php wp_editor( $this->get_setting('msg->confirm_checkout'), 'confirm_checkout', array('textarea_name'=>'mp[msg][confirm_checkout]') ); ?>
  14097.  
  14098. </td>
  14099.  
  14100. </tr>
  14101.  
  14102. <tr>
  14103.  
  14104. <th scope="row"><?php _e('Order Complete Page', 'mp'); ?></th>
  14105.  
  14106. <td>
  14107.  
  14108. <span class="description"><?php _e('Displayed at the top of the page notifying customers of a successful order. HTML allowed.', 'mp') ?></span><br />
  14109.  
  14110. <?php wp_editor( $this->get_setting('msg->success'), 'success', array('textarea_name'=>'mp[msg][success]') ); ?>
  14111.  
  14112. </td>
  14113.  
  14114. </tr>
  14115.  
  14116. </table>
  14117.  
  14118. </div>
  14119.  
  14120. </div>
  14121.  
  14122.  
  14123.  
  14124. <?php
  14125.  
  14126. //for adding additional messages
  14127.  
  14128. do_action('mp_messages_settings', $settings);
  14129.  
  14130. ?>
  14131.  
  14132.  
  14133.  
  14134. <p class="submit">
  14135.  
  14136. <input class="button-primary" type="submit" name="submit_settings" value="<?php _e('Save Changes', 'mp') ?>" />
  14137.  
  14138. </p>
  14139.  
  14140. </form>
  14141.  
  14142. </div>
  14143.  
  14144. <?php
  14145.  
  14146. break;
  14147.  
  14148.  
  14149.  
  14150.  
  14151.  
  14152. //---------------------------------------------------//
  14153.  
  14154. case "shipping":
  14155.  
  14156. global $mp_shipping_plugins;
  14157.  
  14158.  
  14159.  
  14160. //save settings from screen. Put here to be before plugin is loaded
  14161.  
  14162. if (isset($_POST['shipping_settings'])) {
  14163.  
  14164. $settings = get_option('mp_settings');
  14165.  
  14166. //allow plugins to verify settings before saving
  14167.  
  14168. $settings = array_merge($settings, apply_filters('mp_shipping_settings_filter', $_POST['mp']));
  14169.  
  14170. update_option('mp_settings', $settings);
  14171.  
  14172. echo '<div class="updated fade"><p>'.__('Settings saved.', 'mp').'</p></div>';
  14173.  
  14174. }
  14175.  
  14176. ?>
  14177.  
  14178. <script type="text/javascript">
  14179.  
  14180. jQuery(document).ready(function ($) {
  14181.  
  14182. $("#mp-select-all").click(function() {
  14183.  
  14184. $("#mp-target-countries input[type='checkbox']").attr('checked', true);
  14185.  
  14186. return false;
  14187.  
  14188. });
  14189.  
  14190. $("#mp-select-eu").click(function() {
  14191.  
  14192. $("#mp-target-countries input[type='checkbox'].eu").attr('checked', true);
  14193.  
  14194. return false;
  14195.  
  14196. });
  14197.  
  14198. $("#mp-select-none").click(function() {
  14199.  
  14200. $("#mp-target-countries input[type='checkbox']").attr('checked', false);
  14201.  
  14202. return false;
  14203.  
  14204. });
  14205.  
  14206. $(".mp-shipping-method").change(function() {
  14207.  
  14208. $("#mp-shipping-form").submit();
  14209.  
  14210. });
  14211.  
  14212. });
  14213.  
  14214. </script>
  14215.  
  14216. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/delivery.png'; ?>" /></div>
  14217.  
  14218. <h2><?php _e('Shipping Settings', 'mp'); ?></h2>
  14219.  
  14220. <div id="poststuff" class="metabox-holder mp-settings">
  14221.  
  14222.  
  14223.  
  14224. <form id="mp-shipping-form" method="post" action="edit.php?post_type=product&amp;page=marketpress&amp;tab=shipping">
  14225.  
  14226. <input type="hidden" name="shipping_settings" value="1" />
  14227.  
  14228.  
  14229.  
  14230. <div id="mp_flat_rate" class="postbox">
  14231.  
  14232. <h3 class='hndle'><span><?php _e('General Settings', 'mp') ?></span></h3>
  14233.  
  14234. <div class="inside">
  14235.  
  14236. <table class="form-table">
  14237.  
  14238.  
  14239.  
  14240. <tr>
  14241.  
  14242. <th scope="row"><?php _e('Choose Target Countries', 'mp') ?></th>
  14243.  
  14244. <td>
  14245.  
  14246. <div><?php _e('Select:', 'mp') ?> <a id="mp-select-all" href="#"><?php _e('All', 'mp') ?></a>&nbsp; <a id="mp-select-eu" href="#"><?php _e('EU', 'mp') ?></a>&nbsp; <a id="mp-select-none" href="#"><?php _e('None', 'mp') ?></a></div>
  14247.  
  14248. <div id="mp-target-countries">
  14249.  
  14250. <?php
  14251.  
  14252. foreach ($this->countries as $code => $name) {
  14253.  
  14254. ?><label><input type="checkbox"<?php echo (in_array($code, $this->eu_countries)) ? ' class="eu"' : ''; ?> name="mp[shipping][allowed_countries][]" value="<?php echo $code; ?>"<?php echo (in_array($code, $this->get_setting('shipping->allowed_countries', array()))) ? ' checked="checked"' : ''; ?> /> <?php echo esc_attr($name); ?></label><br /><?php
  14255.  
  14256. }
  14257.  
  14258. ?>
  14259.  
  14260. </div><br />
  14261.  
  14262. <span class="description"><?php _e('These are the countries you will sell and ship to.', 'mp') ?></span>
  14263.  
  14264. </td>
  14265.  
  14266. </tr>
  14267.  
  14268.  
  14269.  
  14270. <tr>
  14271.  
  14272. <th scope="row"><?php _e('Select Shipping Method', 'mp') ?></th>
  14273.  
  14274. <td>
  14275.  
  14276. <select name="mp[shipping][method]" class="mp-shipping-method">
  14277.  
  14278. <option value="none"<?php selected($this->get_setting('shipping->method'), 'none'); ?>><?php _e('No Shipping', 'mp'); ?></option>
  14279.  
  14280. <?php
  14281.  
  14282. $calculated_methods = 0;
  14283.  
  14284. foreach ((array)$mp_shipping_plugins as $code => $plugin) {
  14285.  
  14286. if ($plugin[2]) {
  14287.  
  14288. $calculated_methods++;
  14289.  
  14290. continue;
  14291.  
  14292. }
  14293.  
  14294. ?><option value="<?php echo $code; ?>"<?php selected($this->get_setting('shipping->method'), $code); ?>><?php echo esc_attr($plugin[1]); ?></option><?php
  14295.  
  14296. }
  14297.  
  14298. if ($calculated_methods) {
  14299.  
  14300. ?><option value="calculated"<?php selected($this->get_setting('shipping->method'), 'calculated'); ?>><?php _e('Calculated Options', 'mp'); ?></option><?php
  14301.  
  14302. }
  14303.  
  14304. ?>
  14305.  
  14306. </select>
  14307.  
  14308. </td>
  14309.  
  14310. </tr>
  14311.  
  14312. <?php
  14313.  
  14314. if ($calculated_methods && $this->get_setting('shipping->method') == 'calculated') {
  14315.  
  14316. ?>
  14317.  
  14318. <tr>
  14319.  
  14320. <th scope="row"><?php _e('Select Shipping Options', 'mp') ?></th>
  14321.  
  14322. <td>
  14323.  
  14324. <?php if ( defined( 'MP_LITE' ) ) { ?>
  14325.  
  14326. <a class="mp-pro-update" href="http://premium.wpmudev.org/project/e-commerce/" title="<?php _e('Upgrade Now', 'mp'); ?> &raquo;"><?php _e('Upgrade to enable Calculated Shipping options &raquo;', 'mp'); ?></a><br />
  14327.  
  14328. <?php } ?>
  14329.  
  14330. <span class="description"><?php _e('Select which calculated shipping methods the customer will be able to choose from:', 'mp') ?></span><br />
  14331.  
  14332. <?php
  14333.  
  14334. foreach ((array)$mp_shipping_plugins as $code => $plugin) {
  14335.  
  14336. if (!$plugin[2]) continue; //skip non calculated
  14337.  
  14338. ?><label><input type="checkbox" class="mp-shipping-method" name="mp[shipping][calc_methods][<?php echo $code; ?>]" value="<?php echo $code; ?>"<?php echo $this->get_setting("shipping->calc_methods->$code") ? ' checked="checked"' : ''; echo defined( 'MP_LITE' ) ? ' disabled="disabled"' : ''; ?> /> <?php echo esc_attr($plugin[1]); ?></label><br /><?php
  14339.  
  14340. }
  14341.  
  14342. ?>
  14343.  
  14344. </td>
  14345.  
  14346. </tr>
  14347.  
  14348. <?php
  14349.  
  14350. }
  14351.  
  14352. ?>
  14353.  
  14354. <tr>
  14355.  
  14356. <th scope="row"><?php _e('Measurement System', 'mp') ?></th>
  14357.  
  14358. <td>
  14359.  
  14360. <label><input value="english" name="mp[shipping][system]" type="radio"<?php checked($this->get_setting('shipping->system'), 'english') ?> /> <?php _e('Engish (Pounds)', 'mp') ?></label>
  14361.  
  14362. <label><input value="metric" name="mp[shipping][system]" type="radio"<?php checked($this->get_setting('shipping->system'), 'metric') ?> /> <?php _e('Metric (Kilograms)', 'mp') ?></label>
  14363.  
  14364. </td>
  14365.  
  14366. </tr>
  14367.  
  14368. </table>
  14369.  
  14370. </div>
  14371.  
  14372. </div>
  14373.  
  14374.  
  14375.  
  14376. <?php
  14377.  
  14378. //for adding additional settings for a shipping module
  14379.  
  14380. do_action('mp_shipping_settings', $settings);
  14381.  
  14382. ?>
  14383.  
  14384.  
  14385.  
  14386. <p class="submit">
  14387.  
  14388. <input class="button-primary" type="submit" name="submit_settings" value="<?php _e('Save Changes', 'mp') ?>" />
  14389.  
  14390. </p>
  14391.  
  14392. </form>
  14393.  
  14394. </div>
  14395.  
  14396. <?php
  14397.  
  14398. break;
  14399.  
  14400.  
  14401.  
  14402.  
  14403.  
  14404. //---------------------------------------------------//
  14405.  
  14406. case "gateways":
  14407.  
  14408. global $mp_gateway_plugins;
  14409.  
  14410.  
  14411.  
  14412. //save settings
  14413.  
  14414. if (isset($_POST['gateway_settings'])) {
  14415.  
  14416. if ( isset( $_POST['mp'] ) ) {
  14417.  
  14418. $filtered_settings = apply_filters('mp_gateway_settings_filter', $_POST['mp']);
  14419.  
  14420. //allow plugins to verify settings before saving
  14421.  
  14422. $settings = array_merge($settings, $filtered_settings);
  14423.  
  14424. update_option('mp_settings', $settings);
  14425.  
  14426. }
  14427.  
  14428. echo '<div class="updated fade"><p>'.__('Settings saved.', 'mp').'</p></div>';
  14429.  
  14430. }
  14431.  
  14432. ?>
  14433.  
  14434. <script type="text/javascript">
  14435.  
  14436. jQuery(document).ready(function ($) {
  14437.  
  14438. $("input.mp_allowed_gateways").change(function() {
  14439.  
  14440. $("#mp-gateways-form").submit();
  14441.  
  14442. });
  14443.  
  14444. });
  14445.  
  14446. </script>
  14447.  
  14448. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/credit-cards.png'; ?>" /></div>
  14449.  
  14450. <h2><?php _e('Payment Settings', 'mp'); ?></h2>
  14451.  
  14452. <div id="poststuff" class="metabox-holder mp-settings">
  14453.  
  14454.  
  14455.  
  14456. <form id="mp-gateways-form" method="post" action="edit.php?post_type=product&amp;page=marketpress&amp;tab=gateways">
  14457.  
  14458. <input type="hidden" name="gateway_settings" value="1" />
  14459.  
  14460.  
  14461.  
  14462. <?php if (!$this->global_cart) { ?>
  14463.  
  14464. <div id="mp_gateways" class="postbox">
  14465.  
  14466. <h3 class='hndle'><span><?php _e('General Settings', 'mp') ?></span></h3>
  14467.  
  14468. <div class="inside">
  14469.  
  14470. <table class="form-table">
  14471.  
  14472. <tr>
  14473.  
  14474. <th scope="row"><?php _e('Select Payment Gateway(s)', 'mp') ?></th>
  14475.  
  14476. <td>
  14477.  
  14478. <?php
  14479.  
  14480. //check network permissions
  14481.  
  14482. if (is_multisite() && !is_main_site() && !is_super_admin()) {
  14483.  
  14484. $network_settings = get_site_option( 'mp_network_settings' );
  14485.  
  14486. foreach ((array)$mp_gateway_plugins as $code => $plugin) {
  14487.  
  14488. if ($network_settings['allowed_gateways'][$code] == 'full') {
  14489.  
  14490. $allowed_plugins[$code] = $plugin;
  14491.  
  14492. } else if ($network_settings['allowed_gateways'][$code] == 'supporter' && function_exists('is_pro_site') && is_pro_site(false, $network_settings['gateways_pro_level'][$code]) ) {
  14493.  
  14494.  
  14495.  
  14496. $allowed_plugins[$code] = $plugin;
  14497.  
  14498. }
  14499.  
  14500. }
  14501.  
  14502. $mp_gateway_plugins = $allowed_plugins;
  14503.  
  14504. }
  14505.  
  14506.  
  14507.  
  14508. foreach ((array)$mp_gateway_plugins as $code => $plugin) {
  14509.  
  14510. if ($plugin[3]) { //if demo
  14511.  
  14512. ?><label><input type="checkbox" class="mp_allowed_gateways" name="mp[gateways][allowed][]" value="<?php echo $code; ?>" disabled="disabled" /> <?php echo esc_attr($plugin[1]); ?></label> <a class="mp-pro-update" href="http://premium.wpmudev.org/project/e-commerce" title="<?php _e('Upgrade', 'mp'); ?> &raquo;"><?php _e('Pro Only &raquo;', 'mp'); ?></a><br /><?php
  14513.  
  14514. } else {
  14515.  
  14516. ?><label><input type="checkbox" class="mp_allowed_gateways" name="mp[gateways][allowed][]" value="<?php echo $code; ?>"<?php echo (in_array($code, $this->get_setting('gateways->allowed', array()))) ? ' checked="checked"' : ''; ?> /> <?php echo esc_attr($plugin[1]); ?></label><br /><?php
  14517.  
  14518. }
  14519.  
  14520. }
  14521.  
  14522. ?>
  14523.  
  14524. </td>
  14525.  
  14526. </tr>
  14527.  
  14528. </table>
  14529.  
  14530. </div>
  14531.  
  14532. </div>
  14533.  
  14534. <?php } ?>
  14535.  
  14536.  
  14537.  
  14538. <?php
  14539.  
  14540. //for adding additional settings for a payment gateway plugin
  14541.  
  14542. do_action('mp_gateway_settings', $settings);
  14543.  
  14544. ?>
  14545.  
  14546.  
  14547.  
  14548. <p class="submit">
  14549.  
  14550. <input class="button-primary" type="submit" name="submit_settings" value="<?php _e('Save Changes', 'mp') ?>" />
  14551.  
  14552. </p>
  14553.  
  14554. </form>
  14555.  
  14556. </div>
  14557.  
  14558. <?php
  14559.  
  14560. break;
  14561.  
  14562.  
  14563.  
  14564.  
  14565.  
  14566. //---------------------------------------------------//
  14567.  
  14568. case "shortcodes":
  14569.  
  14570. ?>
  14571.  
  14572. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/help.png'; ?>" /></div>
  14573.  
  14574. <h2><?php _e('MarketPress Shortcodes', 'mp'); ?></h2>
  14575.  
  14576. <div id="poststuff" class="metabox-holder mp-settings">
  14577.  
  14578.  
  14579.  
  14580. <!--
  14581.  
  14582. <div class="postbox">
  14583.  
  14584. <h3 class='hndle'><span><?php _e('General Information', 'mp') ?></span></h3>
  14585.  
  14586. <div class="inside">
  14587.  
  14588. <iframe src="http://premium.wpmudev.org/wdp-un.php?action=help&id=144" width="100%" height="400px"></iframe>
  14589.  
  14590. </div>
  14591.  
  14592. </div>
  14593.  
  14594. -->
  14595.  
  14596.  
  14597.  
  14598. <div class="postbox">
  14599.  
  14600. <h3 class='hndle'><span><?php _e('Shortcodes', 'mp') ?></span></h3>
  14601.  
  14602. <div class="inside">
  14603.  
  14604. <p><?php _e('Shortcodes allow you to include dynamic store content in posts and pages on your site. Simply type or paste them into your post or page content where you would like them to appear. Optional attributes can be added in a format like <em>[shortcode attr1="value" attr2="value"]</em>.', 'mp') ?></p>
  14605.  
  14606. <table class="form-table">
  14607.  
  14608. <tr>
  14609.  
  14610. <th scope="row"><?php _e('Product Tag Cloud', 'mp') ?></th>
  14611.  
  14612. <td>
  14613.  
  14614. <strong>[mp_tag_cloud]</strong> -
  14615.  
  14616. <span class="description"><?php _e('Displays a cloud or list of your product tags.', 'mp') ?></span>
  14617.  
  14618. <a href="http://codex.wordpress.org/Template_Tags/wp_tag_cloud"><?php _e('Optional Attributes &raquo;', 'mp') ?></a>
  14619.  
  14620. </td>
  14621.  
  14622. </tr>
  14623.  
  14624. <tr>
  14625.  
  14626. <th scope="row"><?php _e('Product Categories List', 'mp') ?></th>
  14627.  
  14628. <td>
  14629.  
  14630. <strong>[mp_list_categories]</strong> -
  14631.  
  14632. <span class="description"><?php _e('Displays an HTML list of your product categories.', 'mp') ?></span>
  14633.  
  14634. <a href="http://codex.wordpress.org/Template_Tags/wp_list_categories"><?php _e('Optional Attributes &raquo;', 'mp') ?></a>
  14635.  
  14636. </td>
  14637.  
  14638. </tr>
  14639.  
  14640. <tr>
  14641.  
  14642. <th scope="row"><?php _e('Product Categories Dropdown', 'mp') ?></th>
  14643.  
  14644. <td>
  14645.  
  14646. <strong>[mp_dropdown_categories]</strong> -
  14647.  
  14648. <span class="description"><?php _e('Displays an HTML dropdown of your product categories.', 'mp') ?></span>
  14649.  
  14650. <a href="http://codex.wordpress.org/Template_Tags/wp_dropdown_categories"><?php _e('Optional Attributes &raquo;', 'mp') ?></a>
  14651.  
  14652. </td>
  14653.  
  14654. </tr>
  14655.  
  14656. <tr>
  14657.  
  14658. <th scope="row"><?php _e('Popular Products List', 'mp') ?></th>
  14659.  
  14660. <td>
  14661.  
  14662. <strong>[mp_popular_products]</strong> -
  14663.  
  14664. <span class="description"><?php _e('Displays a list of popular products ordered by sales.', 'mp') ?></span>
  14665.  
  14666. <p>
  14667.  
  14668. <strong><?php _e('Optional Attributes:', 'mp') ?></strong>
  14669.  
  14670. <ul class="mp-shortcode-options">
  14671.  
  14672. <li><?php _e('"number" - max number of products to display. Defaults to 5.', 'mp') ?></li>
  14673.  
  14674. <li><?php _e('Example:', 'mp') ?> <em>[mp_popular_products number="5"]</em></li>
  14675.  
  14676. </ul></p>
  14677.  
  14678. </td>
  14679.  
  14680. </tr>
  14681.  
  14682. <tr>
  14683.  
  14684. <th scope="row"><?php _e('Related Products', 'mp') ?></th>
  14685.  
  14686. <td>
  14687.  
  14688. <strong>[mp_related_products]</strong> -
  14689.  
  14690. <span class="description"><?php _e('Displays a products related to the one being viewed.', 'mp') ?></span>
  14691.  
  14692. <p>
  14693.  
  14694. <strong><?php _e('Optional Attributes:', 'mp') ?></strong>
  14695.  
  14696. <ul class="mp-shortcode-options">
  14697.  
  14698. <li><?php _e('"product_id" - The product to show related items for.', 'mp') ?></li>
  14699.  
  14700. <li><?php _e('"relate_by" - Whether to limit the related items to products in the same category, tags or both. Defaults to the value set in presentation settings..', 'mp') ?></li>
  14701.  
  14702. <li><?php _e('"limit" - How many related items to show. Defaults to the value set in presentation settings.', 'mp') ?></li>
  14703.  
  14704. <li><?php _e('"simple_list" - Whether to display the items as a simple list or based on the list/grid view setting. Defaults to the value set in presentation settings.', 'mp') ?></li>
  14705.  
  14706. <li><?php _e('Example:', 'mp') ?> <em>[mp_related_products product_id="12345" in_same_category="1" in_same_tags="1" limit="3" simple_list="0"]</em></li>
  14707.  
  14708. </ul></p>
  14709.  
  14710. </td>
  14711.  
  14712. </tr>
  14713.  
  14714. <tr>
  14715.  
  14716. <th scope="row"><?php _e('Products List', 'mp') ?></th>
  14717.  
  14718. <td>
  14719.  
  14720. <strong>[mp_list_products]</strong> -
  14721.  
  14722. <span class="description"><?php _e('Displays a list of products according to preference. Optional attributes default to the values in Presentation Settings -> Product List.', 'mp') ?></span>
  14723.  
  14724. <p>
  14725.  
  14726. <strong><?php _e('Optional Attributes:', 'mp') ?></strong>
  14727.  
  14728. <ul class="mp-shortcode-options">
  14729.  
  14730. <li><?php _e('"paginate" - Whether to paginate the product list. This is useful to only show a subset.', 'mp') ?></li>
  14731.  
  14732. <li><?php _e('"page" - The page number to display in the product list if "paginate" is set to true.', 'mp') ?></li>
  14733.  
  14734. <li><?php _e('"per_page" - How many products to display in the product list if "paginate" is set to true.', 'mp') ?></li>
  14735.  
  14736. <li><?php _e('"order_by" - What field to order products by. Can be: title, date, ID, author, price, sales, rand (random).', 'mp') ?></li>
  14737.  
  14738. <li><?php _e('"order" - Direction to order products by. Can be: DESC, ASC', 'mp') ?></li>
  14739.  
  14740. <li><?php _e('"category" - Limits list to a specific product category. Use the category Slug', 'mp') ?></li>
  14741.  
  14742. <li><?php _e('"tag" - Limits list to a specific product tag. Use the tag Slug', 'mp') ?></li>
  14743.  
  14744. <li><?php _e('"list_view" - 1 for list view, 0 (default) for grid view', 'mp') ?></li>
  14745.  
  14746. <li><?php _e('Example:', 'mp') ?> <em>[mp_list_products paginate="true" page="1" per_page="10" order_by="price" order="DESC" category="downloads"]</em></li>
  14747.  
  14748. <li><?php _e('"filters" - 1 to show product filters, 0 to not show filters', 'mp') ?></li>
  14749.  
  14750. </ul></p>
  14751.  
  14752. </td>
  14753.  
  14754. </tr>
  14755.  
  14756. <tr>
  14757.  
  14758. <th scope="row"><?php _e('Single Product', 'mp') ?></th>
  14759.  
  14760. <td>
  14761.  
  14762. <strong>[mp_product]</strong> -
  14763.  
  14764. <span class="description"><?php _e('Displays a single product according to preference.', 'mp') ?></span>
  14765.  
  14766. <p>
  14767.  
  14768. <strong><?php _e('Optional Attributes:', 'mp') ?></strong>
  14769.  
  14770. <ul class="mp-shortcode-options">
  14771.  
  14772. <li><?php _e('"product_id" - The ID of the product to display. This is the Post ID, you can find it in the url of a product edit page.', 'mp') ?></li>
  14773.  
  14774. <li><?php _e('"title" - Whether to display the product title.', 'mp') ?></li>
  14775.  
  14776. <li><?php _e('"content" - Whether and what type of content to display. Options are false/0, "full", or "excerpt". Default "full"', 'mp') ?></li>
  14777.  
  14778. <li><?php _e('"image" - Whether and what context of image size to display. Options are false/0, "single", or "list". Default "single"', 'mp') ?></li>
  14779.  
  14780. <li><?php _e('"meta" - Whether to display the product meta (price, buy button).', 'mp') ?></li>
  14781.  
  14782. <li><?php _e('Example:', 'mp') ?> <em>[mp_product product_id="1" title="1" content="excerpt" image="single" meta="1"]</em></li>
  14783.  
  14784. </ul></p>
  14785.  
  14786. </td>
  14787.  
  14788. </tr>
  14789.  
  14790. <tr>
  14791.  
  14792. <th scope="row"><?php _e('Product Image', 'mp') ?></th>
  14793.  
  14794. <td>
  14795.  
  14796. <strong>[mp_product_image]</strong> -
  14797.  
  14798. <span class="description"><?php _e('Displays the featured image of a given product.', 'mp') ?></span>
  14799.  
  14800. <p>
  14801.  
  14802. <strong><?php _e('Optional Attributes:', 'mp') ?></strong>
  14803.  
  14804. <ul class="mp-shortcode-options">
  14805.  
  14806. <li><?php _e('"product_id" - The ID for the product. This is the Post ID, you can find it in the url of a product edit page. Optional if shortcode is in the loop.', 'mp') ?></li>
  14807.  
  14808. <li><?php _e('"context" - What context for preset size options. Options are list, single, or widget, default single.', 'mp') ?></li>
  14809.  
  14810. <li><?php _e('"size" - Set a custom pixel width/height. If omitted defaults to the size set by "context".', 'mp') ?></li>
  14811.  
  14812. <li><?php _e('"align" - Set the alignment of the image. If omitted defaults to the alignment set in presentation settings.', 'mp') ?></li>
  14813.  
  14814. <li><?php _e('Example:', 'mp') ?> <em>[mp_product_image product_id="1" size="150" align="left"]</em></li>
  14815.  
  14816. </ul></p>
  14817.  
  14818. </td>
  14819.  
  14820. </tr>
  14821.  
  14822. <tr>
  14823.  
  14824. <th scope="row"><?php _e('Product Buy Button', 'mp') ?></th>
  14825.  
  14826. <td>
  14827.  
  14828. <strong>[mp_buy_button]</strong> -
  14829.  
  14830. <span class="description"><?php _e('Displays the buy or add to cart button.', 'mp') ?></span>
  14831.  
  14832. <p>
  14833.  
  14834. <strong><?php _e('Optional Attributes:', 'mp') ?></strong>
  14835.  
  14836. <ul class="mp-shortcode-options">
  14837.  
  14838. <li><?php _e('"product_id" - The ID for the product. This is the Post ID, you can find it in the url of a product edit page. Optional if shortcode is in the loop.', 'mp') ?></li>
  14839.  
  14840. <li><?php _e('"context" - What context for display. Options are list or single, default single which shows all variations.', 'mp') ?></li>
  14841.  
  14842. <li><?php _e('Example:', 'mp') ?> <em>[mp_buy_button product_id="1" context="single"]</em></li>
  14843.  
  14844. </ul></p>
  14845.  
  14846. </td>
  14847.  
  14848. </tr>
  14849.  
  14850. <tr>
  14851.  
  14852. <th scope="row"><?php _e('Product Price', 'mp') ?></th>
  14853.  
  14854. <td>
  14855.  
  14856. <strong>[mp_product_price]</strong> -
  14857.  
  14858. <span class="description"><?php _e('Displays the product price (and sale price).', 'mp') ?></span>
  14859.  
  14860. <p>
  14861.  
  14862. <strong><?php _e('Optional Attributes:', 'mp') ?></strong>
  14863.  
  14864. <ul class="mp-shortcode-options">
  14865.  
  14866. <li><?php _e('"product_id" - The ID for the product. This is the Post ID, you can find it in the url of a product edit page. Optional if shortcode is in the loop.', 'mp') ?></li>
  14867.  
  14868. <li><?php _e('"label" - A label to prepend to the price. Defaults to "Price: ".', 'mp') ?></li>
  14869.  
  14870. <li><?php _e('Example:', 'mp') ?> <em>[mp_product_price product_id="1" label="Buy this thing now!"]</em></li>
  14871.  
  14872. </ul></p>
  14873.  
  14874. </td>
  14875.  
  14876. </tr>
  14877.  
  14878. <tr>
  14879.  
  14880. <th scope="row"><?php _e('Product SKU', 'mp') ?></th>
  14881.  
  14882. <td>
  14883.  
  14884. <strong>[mp_product_sku]</strong> -
  14885.  
  14886. <span class="description"><?php _e('Displays the product SKU number(s).', 'mp') ?></span>
  14887.  
  14888. <p>
  14889.  
  14890. <strong><?php _e('Optional Attributes:', 'mp') ?></strong>
  14891.  
  14892. <ul class="mp-shortcode-options">
  14893.  
  14894. <li><?php _e('"product_id" - The ID for the product. This is the Post ID, you can find it in the url of a product edit page. Optional if shortcode is in the loop.', 'mp') ?></li>
  14895.  
  14896. <li><?php _e('"seperator" - If there are variation, what to seperate the list of SKUs with. Defaults to a comma ", ".', 'mp') ?></li>
  14897.  
  14898. <li><?php _e('Example:', 'mp') ?> <em>[mp_product_sku product_id="1" seperator=", "]</em></li>
  14899.  
  14900. </ul></p>
  14901.  
  14902. </td>
  14903.  
  14904. </tr>
  14905.  
  14906. <tr>
  14907.  
  14908. <th scope="row"><?php _e('Product Meta', 'mp') ?></th>
  14909.  
  14910. <td>
  14911.  
  14912. <strong>[mp_product_meta]</strong> -
  14913.  
  14914. <span class="description"><?php _e('Displays the full product meta box with price and buy now/add to cart button.', 'mp') ?></span>
  14915.  
  14916. <p>
  14917.  
  14918. <strong><?php _e('Optional Attributes:', 'mp') ?></strong>
  14919.  
  14920. <ul class="mp-shortcode-options">
  14921.  
  14922. <li><?php _e('"product_id" - The ID for the product. This is the Post ID, you can find it in the url of a product edit page. Optional if shortcode is in the loop.', 'mp') ?></li>
  14923.  
  14924. <li><?php _e('"label" - A label to prepend to the price. Defaults to "Price: ".', 'mp') ?></li>
  14925.  
  14926. <li><?php _e('"context" - What context for display. Options are list or single, default single which shows all variations.', 'mp') ?></li>
  14927.  
  14928. <li><?php _e('Example:', 'mp') ?> <em>[mp_product_meta product_id="1" label="Buy this thing now!"]</em></li>
  14929.  
  14930. </ul></p>
  14931.  
  14932. </td>
  14933.  
  14934. </tr>
  14935.  
  14936. <tr>
  14937.  
  14938. <th scope="row"><?php _e('Store Links', 'mp') ?></th>
  14939.  
  14940. <td>
  14941.  
  14942. <strong>[mp_cart_link]</strong> -
  14943.  
  14944. <span class="description"><?php _e('Displays a link or url to the current shopping cart page.', 'mp') ?></span><br />
  14945.  
  14946. <strong>[mp_store_link]</strong> -
  14947.  
  14948. <span class="description"><?php _e('Displays a link or url to the current store page.', 'mp') ?></span><br />
  14949.  
  14950. <strong>[mp_products_link]</strong> -
  14951.  
  14952. <span class="description"><?php _e('Displays a link or url to the current products list page.', 'mp') ?></span><br />
  14953.  
  14954. <strong>[mp_orderstatus_link]</strong> -
  14955.  
  14956. <span class="description"><?php _e('Displays a link or url to the order status page.', 'mp') ?></span><br />
  14957.  
  14958. <p>
  14959.  
  14960. <strong><?php _e('Optional Attributes:', 'mp') ?></strong>
  14961.  
  14962. <ul class="mp-shortcode-options">
  14963.  
  14964. <li><?php _e('"url" - Whether to return a clickable link or url. Can be: true, false. Defaults to showing link.', 'mp') ?></li>
  14965.  
  14966. <li><?php _e('"link_text" - The text to show in the link.', 'mp') ?></li>
  14967.  
  14968. <li><?php _e('Example:', 'mp') ?> <em>[mp_cart_link link_text="Go here!"]</em></li>
  14969.  
  14970. </ul></p>
  14971.  
  14972. </td>
  14973.  
  14974. </tr>
  14975.  
  14976. <tr>
  14977.  
  14978. <th scope="row"><?php _e('Store Navigation List', 'mp') ?></th>
  14979.  
  14980. <td>
  14981.  
  14982. <strong>[mp_store_navigation]</strong> -
  14983.  
  14984. <span class="description"><?php _e('Displays a list of links to your store pages.', 'mp') ?></span>
  14985.  
  14986. </td>
  14987.  
  14988. </tr>
  14989.  
  14990. </table>
  14991.  
  14992. </div>
  14993.  
  14994. </div>
  14995.  
  14996.  
  14997.  
  14998. <?php
  14999.  
  15000. //for adding additional help content boxes
  15001.  
  15002. do_action('mp_help_page', $settings);
  15003.  
  15004. ?>
  15005.  
  15006. </div>
  15007.  
  15008. <?php
  15009.  
  15010. break;
  15011.  
  15012.  
  15013.  
  15014. //---------------------------------------------------//
  15015.  
  15016. case "importers":
  15017.  
  15018. ?>
  15019.  
  15020. <div class="icon32"><img src="<?php echo $this->plugin_url . 'images/import.png'; ?>" /></div>
  15021.  
  15022. <form id="mp-import-form" method="post" action="<?php echo admin_url('edit.php?post_type=product&page=marketpress&tab=importers'); ?>" enctype="multipart/form-data">
  15023.  
  15024. <h2><?php _e('Import Products', 'mp'); ?></h2>
  15025.  
  15026. <div id="poststuff" class="metabox-holder mp-importer">
  15027.  
  15028. <?php do_action('marketpress_add_importer'); ?>
  15029.  
  15030. </div>
  15031.  
  15032. </form>
  15033.  
  15034. </div>
  15035.  
  15036. <?php
  15037.  
  15038. break;
  15039.  
  15040.  
  15041.  
  15042. } //end switch
  15043.  
  15044.  
  15045.  
  15046. //hook to create a new admin screen.
  15047.  
  15048. do_action('marketpress_add_screen', $tab);
  15049.  
  15050.  
  15051.  
  15052. echo '</div>';
  15053.  
  15054.  
  15055.  
  15056. }
  15057.  
  15058.  
  15059.  
  15060. /**
  15061.  
  15062. * This function will convert old style arguments (broken out into variables) and convert into an array
  15063.  
  15064. * @param mixed $args
  15065.  
  15066. * @param array $defaults
  15067.  
  15068. * @return array
  15069.  
  15070. */
  15071.  
  15072. function parse_args( $args, $defaults ) {
  15073.  
  15074. if ( !isset($args[0]) )
  15075.  
  15076. return $defaults;
  15077.  
  15078.  
  15079.  
  15080. if ( (isset($args[0]) && is_array($args[0])) || (isset($args[0]) && !is_numeric($args[0]) && !is_bool($args[0])) )
  15081.  
  15082. return wp_parse_args($args[0], $defaults);
  15083.  
  15084.  
  15085.  
  15086. $tmp_args = array();
  15087.  
  15088.  
  15089.  
  15090. foreach ( $defaults as $key => $value ) {
  15091.  
  15092. $val = array_shift($args);
  15093.  
  15094. $tmp_args[$key] = !is_null($val) ? $val : $value;
  15095.  
  15096. }
  15097.  
  15098.  
  15099.  
  15100. return $tmp_args;
  15101.  
  15102. }
  15103.  
  15104. } //end class
  15105.  
  15106.  
  15107.  
  15108. global $mp;
  15109.  
  15110. $mp = new MarketPress();
  15111.  
  15112.  
  15113.  
  15114.  
  15115.  
  15116. //Shopping cart widget
  15117.  
  15118. class MarketPress_Shopping_Cart extends WP_Widget {
  15119.  
  15120.  
  15121.  
  15122. function MarketPress_Shopping_Cart() {
  15123.  
  15124. $widget_ops = array('classname' => 'mp_cart_widget', 'description' => __('Shows dynamic shopping cart contents along with a checkout button for your MarketPress store.', 'mp') );
  15125.  
  15126. $this->WP_Widget('mp_cart_widget', __('Shopping Cart', 'mp'), $widget_ops);
  15127.  
  15128. }
  15129.  
  15130.  
  15131.  
  15132. function widget($args, $instance) {
  15133.  
  15134. global $mp;
  15135.  
  15136.  
  15137.  
  15138. if ( get_query_var('pagename') == 'cart' )
  15139.  
  15140. return;
  15141.  
  15142.  
  15143.  
  15144. if ($instance['only_store_pages'] && !mp_is_shop_page())
  15145.  
  15146. return;
  15147.  
  15148.  
  15149.  
  15150. extract( $args );
  15151.  
  15152.  
  15153.  
  15154. echo $before_widget;
  15155.  
  15156. $title = $instance['title'];
  15157.  
  15158. if ( !empty( $title ) ) { echo $before_title . apply_filters('widget_title', $title) . $after_title; };
  15159.  
  15160.  
  15161.  
  15162. if ( !empty($instance['custom_text']) )
  15163.  
  15164. echo '<div class="custom_text">' . $instance['custom_text'] . '</div>';
  15165.  
  15166.  
  15167.  
  15168. echo '<div class="mp_cart_widget_content">';
  15169.  
  15170. mp_show_cart('widget');
  15171.  
  15172. echo '</div>';
  15173.  
  15174.  
  15175.  
  15176. echo $after_widget;
  15177.  
  15178. }
  15179.  
  15180.  
  15181.  
  15182. function update( $new_instance, $old_instance ) {
  15183.  
  15184. $instance = $old_instance;
  15185.  
  15186. $instance['title'] = stripslashes( wp_filter_nohtml_kses( $new_instance['title']) );
  15187.  
  15188. $instance['custom_text'] = stripslashes( wp_filter_kses( $new_instance['custom_text']) );
  15189.  
  15190. $instance['only_store_pages'] = !empty($new_instance['only_store_pages']) ? 1 : 0;
  15191.  
  15192. /*
  15193.  
  15194. $instance['show_thumbnail'] = !empty($new_instance['show_thumbnail']) ? 1 : 0;
  15195.  
  15196. $instance['size'] = !empty($new_instance['size']) ? intval($new_instance['size']) : 25;
  15197.  
  15198. */
  15199.  
  15200.  
  15201.  
  15202. return $instance;
  15203.  
  15204. }
  15205.  
  15206.  
  15207.  
  15208. function form( $instance ) {
  15209.  
  15210. $instance = wp_parse_args( (array) $instance, array( 'title' => __('Shopping Cart', 'mp'), 'custom_text' => '', 'only_store_pages' => 0 ) );
  15211.  
  15212. $title = $instance['title'];
  15213.  
  15214. $custom_text = $instance['custom_text'];
  15215.  
  15216. $only_store_pages = isset( $instance['only_store_pages'] ) ? (bool) $instance['only_store_pages'] : false;
  15217.  
  15218. /*
  15219.  
  15220. $show_thumbnail = isset( $instance['show_thumbnail'] ) ? (bool) $instance['show_thumbnail'] : false;
  15221.  
  15222. $size = !empty($instance['size']) ? intval($instance['size']) : 25;
  15223.  
  15224. */
  15225.  
  15226. ?>
  15227.  
  15228. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'mp') ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
  15229.  
  15230. <p><label for="<?php echo $this->get_field_id('custom_text'); ?>"><?php _e('Custom Text:', 'mp') ?><br />
  15231.  
  15232. <textarea class="widefat" id="<?php echo $this->get_field_id('custom_text'); ?>" name="<?php echo $this->get_field_name('custom_text'); ?>"><?php echo esc_attr($custom_text); ?></textarea></label>
  15233.  
  15234. </p>
  15235.  
  15236. <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('only_store_pages'); ?>" name="<?php echo $this->get_field_name('only_store_pages'); ?>"<?php checked( $only_store_pages ); ?> />
  15237.  
  15238. <label for="<?php echo $this->get_field_id('only_store_pages'); ?>"><?php _e( 'Only show on store pages', 'mp' ); ?></label></p>
  15239.  
  15240. <?php
  15241.  
  15242. /* Disable untill we can mod the cart
  15243.  
  15244. <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_thumbnail'); ?>" name="<?php echo $this->get_field_name('show_thumbnail'); ?>"<?php checked( $show_thumbnail ); ?> />
  15245.  
  15246. <label for="<?php echo $this->get_field_id('show_thumbnail'); ?>"><?php _e( 'Show Thumbnail', 'mp' ); ?></label><br />
  15247.  
  15248. <label for="<?php echo $this->get_field_id('size'); ?>"><?php _e('Thumbnail Size:', 'mp') ?> <input id="<?php echo $this->get_field_id('size'); ?>" name="<?php echo $this->get_field_name('size'); ?>" type="text" size="3" value="<?php echo $size; ?>" /></label></p>
  15249.  
  15250. */
  15251.  
  15252. }
  15253.  
  15254. }
  15255.  
  15256.  
  15257.  
  15258. //Product listing widget
  15259.  
  15260. class MarketPress_Product_List extends WP_Widget {
  15261.  
  15262.  
  15263.  
  15264. function MarketPress_Product_List() {
  15265.  
  15266. $widget_ops = array('classname' => 'mp_product_list_widget', 'description' => __('Shows a customizable list of products from your MarketPress store.', 'mp') );
  15267.  
  15268. $this->WP_Widget('mp_product_list_widget', __('Product List', 'mp'), $widget_ops);
  15269.  
  15270. }
  15271.  
  15272.  
  15273.  
  15274. function widget($args, $instance) {
  15275.  
  15276. global $mp;
  15277.  
  15278.  
  15279.  
  15280. if ($instance['only_store_pages'] && !mp_is_shop_page())
  15281.  
  15282. return;
  15283.  
  15284.  
  15285.  
  15286. extract( $args );
  15287.  
  15288.  
  15289.  
  15290. echo $before_widget;
  15291.  
  15292. $title = $instance['title'];
  15293.  
  15294. if ( !empty( $title ) ) { echo $before_title . apply_filters('widget_title', $title) . $after_title; };
  15295.  
  15296.  
  15297.  
  15298. if ( !empty($instance['custom_text']) )
  15299.  
  15300. echo '<div id="custom_text">' . $instance['custom_text'] . '</div>';
  15301.  
  15302.  
  15303.  
  15304. /* setup our custom query */
  15305.  
  15306.  
  15307.  
  15308. //setup taxonomy if applicable
  15309.  
  15310. if ($instance['taxonomy_type'] == 'category') {
  15311.  
  15312. $taxonomy_query = '&product_category=' . $instance['taxonomy'];
  15313.  
  15314. } else if ($instance['taxonomy_type'] == 'tag') {
  15315.  
  15316. $taxonomy_query = '&product_tag=' . $instance['taxonomy'];
  15317.  
  15318. } else {
  15319.  
  15320. $taxonomy_query = '';
  15321.  
  15322. }
  15323.  
  15324.  
  15325.  
  15326. //figure out perpage
  15327.  
  15328. if (isset($instance['num_products']) && intval($instance['num_products']) > 0) {
  15329.  
  15330. $paginate_query = '&posts_per_page='.intval($instance['num_products']).'&paged=1';
  15331.  
  15332. } else {
  15333.  
  15334. $paginate_query = '&posts_per_page=10&paged=1';
  15335.  
  15336. }
  15337.  
  15338.  
  15339.  
  15340. //get order by
  15341.  
  15342. if ($instance['order_by']) {
  15343.  
  15344. if ($instance['order_by'] == 'price')
  15345.  
  15346. $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num';
  15347.  
  15348. else if ($instance['order_by'] == 'sales')
  15349.  
  15350. $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num';
  15351.  
  15352. else
  15353.  
  15354. $order_by_query = '&orderby='.$instance['order_by'];
  15355.  
  15356. } else {
  15357.  
  15358. $order_by_query = '&orderby=title';
  15359.  
  15360. }
  15361.  
  15362.  
  15363.  
  15364. //get order direction
  15365.  
  15366. if ($instance['order']) {
  15367.  
  15368. $order_query = '&order='.$instance['order'];
  15369.  
  15370. } else {
  15371.  
  15372. $order_query = '&orderby=DESC';
  15373.  
  15374. }
  15375.  
  15376.  
  15377.  
  15378. //The Query
  15379.  
  15380. $custom_query = new WP_Query('post_type=product' . $taxonomy_query . $paginate_query . $order_by_query . $order_query);
  15381.  
  15382.  
  15383.  
  15384. //do we have products?
  15385.  
  15386. if (count($custom_query->posts)) {
  15387.  
  15388. echo '<ul id="mp_product_list">';
  15389.  
  15390. foreach ($custom_query->posts as $post) {
  15391.  
  15392.  
  15393.  
  15394. echo '<li '.mp_product_class(false, 'mp_product', $post->ID).'>';
  15395.  
  15396. echo '<h3 class="mp_product_name"><a href="' . get_permalink( $post->ID ) . '">' . esc_attr($post->post_title) . '</a></h3>';
  15397.  
  15398. if ($instance['show_thumbnail'])
  15399.  
  15400. mp_product_image( true, 'widget', $post->ID, $instance['size'] );
  15401.  
  15402.  
  15403.  
  15404. if ($instance['show_excerpt'])
  15405.  
  15406. echo '<div class="mp_product_content">' . $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID) . '</div>';
  15407.  
  15408.  
  15409.  
  15410. if ($instance['show_price'] || $instance['show_button']) {
  15411.  
  15412. echo '<div class="mp_product_meta">';
  15413.  
  15414.  
  15415.  
  15416. if ($instance['show_price'])
  15417.  
  15418. echo mp_product_price(false, $post->ID, '');
  15419.  
  15420.  
  15421.  
  15422. if ($instance['show_button'])
  15423.  
  15424. echo mp_buy_button(false, 'list', $post->ID);
  15425.  
  15426.  
  15427.  
  15428. echo '</div>';
  15429.  
  15430. }
  15431.  
  15432. echo '</li>';
  15433.  
  15434. }
  15435.  
  15436. echo '</ul>';
  15437.  
  15438. } else {
  15439.  
  15440. ?>
  15441.  
  15442. <div class="widget-error">
  15443.  
  15444. <?php _e('No Products', 'mp') ?>
  15445.  
  15446. </div>
  15447.  
  15448. <?php
  15449.  
  15450. }
  15451.  
  15452.  
  15453.  
  15454. echo $after_widget;
  15455.  
  15456. }
  15457.  
  15458.  
  15459.  
  15460. function update( $new_instance, $old_instance ) {
  15461.  
  15462. $instance = $old_instance;
  15463.  
  15464. $instance['title'] = stripslashes( wp_filter_nohtml_kses( $new_instance['title'] ) );
  15465.  
  15466. $instance['custom_text'] = stripslashes( wp_filter_kses( $new_instance['custom_text'] ) );
  15467.  
  15468.  
  15469.  
  15470. $instance['num_products'] = intval($new_instance['num_products']);
  15471.  
  15472. $instance['order_by'] = $new_instance['order_by'];
  15473.  
  15474. $instance['order'] = $new_instance['order'];
  15475.  
  15476. $instance['taxonomy_type'] = $new_instance['taxonomy_type'];
  15477.  
  15478. $instance['taxonomy'] = ($new_instance['taxonomy_type']) ? sanitize_title($new_instance['taxonomy']) : '';
  15479.  
  15480.  
  15481.  
  15482. $instance['show_thumbnail'] = !empty($new_instance['show_thumbnail']) ? 1 : 0;
  15483.  
  15484. $instance['size'] = !empty($new_instance['size']) ? intval($new_instance['size']) : 50;
  15485.  
  15486. $instance['show_excerpt'] = !empty($new_instance['show_excerpt']) ? 1 : 0;
  15487.  
  15488. $instance['show_price'] = !empty($new_instance['show_price']) ? 1 : 0;
  15489.  
  15490. $instance['show_button'] = !empty($new_instance['show_button']) ? 1 : 0;
  15491.  
  15492.  
  15493.  
  15494. $instance['only_store_pages'] = !empty($new_instance['only_store_pages']) ? 1 : 0;
  15495.  
  15496.  
  15497.  
  15498. return $instance;
  15499.  
  15500. }
  15501.  
  15502.  
  15503.  
  15504. function form( $instance ) {
  15505.  
  15506. $instance = wp_parse_args( (array) $instance, array( 'title' => __('Our Products', 'mp'), 'custom_text' => '', 'num_products' => 10, 'order_by' => 'title', 'order' => 'DESC', 'show_thumbnail' => 1, 'size' => 50, 'only_store_pages' => 0 ) );
  15507.  
  15508. $title = $instance['title'];
  15509.  
  15510. $custom_text = $instance['custom_text'];
  15511.  
  15512.  
  15513.  
  15514. $num_products = intval($instance['num_products']);
  15515.  
  15516. $order_by = $instance['order_by'];
  15517.  
  15518. $order = $instance['order'];
  15519.  
  15520. $taxonomy_type = isset($instance['taxonomy_type']) ? $instance['taxonomy_type'] : '';
  15521.  
  15522. $taxonomy = isset($instance['taxonomy']) ? $instance['taxonomy'] : '';
  15523.  
  15524.  
  15525.  
  15526. $show_thumbnail = isset( $instance['show_thumbnail'] ) ? (bool) $instance['show_thumbnail'] : false;
  15527.  
  15528. $size = !empty($instance['size']) ? intval($instance['size']) : 50;
  15529.  
  15530. $show_excerpt = isset( $instance['show_excerpt'] ) ? (bool) $instance['show_excerpt'] : false;
  15531.  
  15532. $show_price = isset( $instance['show_price'] ) ? (bool) $instance['show_price'] : false;
  15533.  
  15534. $show_button = isset( $instance['show_button'] ) ? (bool) $instance['show_button'] : false;
  15535.  
  15536.  
  15537.  
  15538. $only_store_pages = isset( $instance['only_store_pages'] ) ? (bool) $instance['only_store_pages'] : false;
  15539.  
  15540. ?>
  15541.  
  15542. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'mp') ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
  15543.  
  15544. <p><label for="<?php echo $this->get_field_id('custom_text'); ?>"><?php _e('Custom Text:', 'mp') ?><br />
  15545.  
  15546. <textarea class="widefat" id="<?php echo $this->get_field_id('custom_text'); ?>" name="<?php echo $this->get_field_name('custom_text'); ?>"><?php echo esc_attr($custom_text); ?></textarea></label>
  15547.  
  15548. </p>
  15549.  
  15550.  
  15551.  
  15552. <h3><?php _e('List Settings', 'mp'); ?></h3>
  15553.  
  15554. <p>
  15555.  
  15556. <label for="<?php echo $this->get_field_id('num_products'); ?>"><?php _e('Number of Products:', 'mp') ?> <input id="<?php echo $this->get_field_id('num_products'); ?>" name="<?php echo $this->get_field_name('num_products'); ?>" type="text" size="3" value="<?php echo $num_products; ?>" /></label><br />
  15557.  
  15558. </p>
  15559.  
  15560. <p>
  15561.  
  15562. <label for="<?php echo $this->get_field_id('order_by'); ?>"><?php _e('Order Products By:', 'mp') ?></label><br />
  15563.  
  15564. <select id="<?php echo $this->get_field_id('order_by'); ?>" name="<?php echo $this->get_field_name('order_by'); ?>">
  15565.  
  15566. <option value="title"<?php selected($order_by, 'title') ?>><?php _e('Product Name', 'mp') ?></option>
  15567.  
  15568. <option value="date"<?php selected($order_by, 'date') ?>><?php _e('Publish Date', 'mp') ?></option>
  15569.  
  15570. <option value="ID"<?php selected($order_by, 'ID') ?>><?php _e('Product ID', 'mp') ?></option>
  15571.  
  15572. <option value="author"<?php selected($order_by, 'author') ?>><?php _e('Product Author', 'mp') ?></option>
  15573.  
  15574. <option value="sales"<?php selected($order_by, 'sales') ?>><?php _e('Number of Sales', 'mp') ?></option>
  15575.  
  15576. <option value="price"<?php selected($order_by, 'price') ?>><?php _e('Product Price', 'mp') ?></option>
  15577.  
  15578. <option value="rand"<?php selected($order_by, 'rand') ?>><?php _e('Random', 'mp') ?></option>
  15579.  
  15580. </select><br />
  15581.  
  15582. <label><input value="DESC" name="<?php echo $this->get_field_name('order'); ?>" type="radio"<?php checked($order, 'DESC') ?> /> <?php _e('Descending', 'mp') ?></label>
  15583.  
  15584. <label><input value="ASC" name="<?php echo $this->get_field_name('order'); ?>" type="radio"<?php checked($order, 'ASC') ?> /> <?php _e('Ascending', 'mp') ?></label>
  15585.  
  15586. </p>
  15587.  
  15588. <p>
  15589.  
  15590. <label><?php _e('Taxonomy Filter:', 'mp') ?></label><br />
  15591.  
  15592. <select id="<?php echo $this->get_field_id('taxonomy_type'); ?>" name="<?php echo $this->get_field_name('taxonomy_type'); ?>">
  15593.  
  15594. <option value=""<?php selected($taxonomy_type, '') ?>><?php _e('No Filter', 'mp') ?></option>
  15595.  
  15596. <option value="category"<?php selected($taxonomy_type, 'category') ?>><?php _e('Category', 'mp') ?></option>
  15597.  
  15598. <option value="tag"<?php selected($taxonomy_type, 'tag') ?>><?php _e('Tag', 'mp') ?></option>
  15599.  
  15600. </select>
  15601.  
  15602. <input id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>" type="text" size="17" value="<?php echo $taxonomy; ?>" title="<?php _e('Enter the Slug', 'mp'); ?>" />
  15603.  
  15604. </p>
  15605.  
  15606.  
  15607.  
  15608. <h3><?php _e('Display Settings', 'mp'); ?></h3>
  15609.  
  15610. <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_thumbnail'); ?>" name="<?php echo $this->get_field_name('show_thumbnail'); ?>"<?php checked( $show_thumbnail ); ?> />
  15611.  
  15612. <label for="<?php echo $this->get_field_id('show_thumbnail'); ?>"><?php _e( 'Show Thumbnail', 'mp' ); ?></label><br />
  15613.  
  15614. <label for="<?php echo $this->get_field_id('size'); ?>"><?php _e('Thumbnail Size:', 'mp') ?> <input id="<?php echo $this->get_field_id('size'); ?>" name="<?php echo $this->get_field_name('size'); ?>" type="text" size="3" value="<?php echo $size; ?>" /></label></p>
  15615.  
  15616.  
  15617.  
  15618. <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_excerpt'); ?>" name="<?php echo $this->get_field_name('show_excerpt'); ?>"<?php checked( $show_excerpt ); ?> />
  15619.  
  15620. <label for="<?php echo $this->get_field_id('show_excerpt'); ?>"><?php _e( 'Show Excerpt', 'mp' ); ?></label><br />
  15621.  
  15622. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_price'); ?>" name="<?php echo $this->get_field_name('show_price'); ?>"<?php checked( $show_price ); ?> />
  15623.  
  15624. <label for="<?php echo $this->get_field_id('show_price'); ?>"><?php _e( 'Show Price', 'mp' ); ?></label><br />
  15625.  
  15626. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_button'); ?>" name="<?php echo $this->get_field_name('show_button'); ?>"<?php checked( $show_button ); ?> />
  15627.  
  15628. <label for="<?php echo $this->get_field_id('show_button'); ?>"><?php _e( 'Show Buy Button', 'mp' ); ?></label></p>
  15629.  
  15630.  
  15631.  
  15632. <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('only_store_pages'); ?>" name="<?php echo $this->get_field_name('only_store_pages'); ?>"<?php checked( $only_store_pages ); ?> />
  15633.  
  15634. <label for="<?php echo $this->get_field_id('only_store_pages'); ?>"><?php _e( 'Only show on store pages', 'mp' ); ?></label></p>
  15635.  
  15636. <?php
  15637.  
  15638. }
  15639.  
  15640. }
  15641.  
  15642.  
  15643.  
  15644. //Product categories widget
  15645.  
  15646. class MarketPress_Categories_Widget extends WP_Widget {
  15647.  
  15648.  
  15649.  
  15650. function MarketPress_Categories_Widget() {
  15651.  
  15652. $widget_ops = array( 'classname' => 'mp_categories_widget', 'description' => __( "A list or dropdown of product categories from your MarketPress store.", 'mp' ) );
  15653.  
  15654. $this->WP_Widget('mp_categories_widget', __('Product Categories', 'mp'), $widget_ops);
  15655.  
  15656. }
  15657.  
  15658.  
  15659.  
  15660. function widget( $args, $instance ) {
  15661.  
  15662.  
  15663.  
  15664. if ($instance['only_store_pages'] && !mp_is_shop_page())
  15665.  
  15666. return;
  15667.  
  15668.  
  15669.  
  15670. extract( $args );
  15671.  
  15672.  
  15673.  
  15674. $title = apply_filters('widget_title', empty( $instance['title'] ) ? __('Product Categories', 'mp') : $instance['title'], $instance, $this->id_base);
  15675.  
  15676. $c = $instance['count'] ? '1' : '0';
  15677.  
  15678. $h = $instance['hierarchical'] ? '1' : '0';
  15679.  
  15680. $d = $instance['dropdown'] ? '1' : '0';
  15681.  
  15682.  
  15683.  
  15684. echo $before_widget;
  15685.  
  15686. if ( $title )
  15687.  
  15688. echo $before_title . $title . $after_title;
  15689.  
  15690.  
  15691.  
  15692. $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
  15693.  
  15694.  
  15695.  
  15696. if ( $d ) {
  15697.  
  15698. $cat_args['show_option_none'] = __('Select Category');
  15699.  
  15700. $cat_args['taxonomy'] = 'product_category';
  15701.  
  15702. $cat_args['id'] = 'mp_category_dropdown';
  15703.  
  15704. mp_dropdown_categories( true, $cat_args );
  15705.  
  15706. } else {
  15707.  
  15708. ?>
  15709.  
  15710. <ul id="mp_category_list">
  15711.  
  15712. <?php
  15713.  
  15714. $cat_args['title_li'] = '';
  15715.  
  15716. $cat_args['taxonomy'] = 'product_category';
  15717.  
  15718. wp_list_categories( $cat_args );
  15719.  
  15720. ?>
  15721.  
  15722. </ul>
  15723.  
  15724. <?php
  15725.  
  15726. }
  15727.  
  15728.  
  15729.  
  15730. echo $after_widget;
  15731.  
  15732. }
  15733.  
  15734.  
  15735.  
  15736. function update( $new_instance, $old_instance ) {
  15737.  
  15738. $instance = $old_instance;
  15739.  
  15740. $instance['title'] = strip_tags($new_instance['title']);
  15741.  
  15742. $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
  15743.  
  15744. $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
  15745.  
  15746. $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
  15747.  
  15748. $instance['only_store_pages'] = !empty($new_instance['only_store_pages']) ? 1 : 0;
  15749.  
  15750.  
  15751.  
  15752. return $instance;
  15753.  
  15754. }
  15755.  
  15756.  
  15757.  
  15758. function form( $instance ) {
  15759.  
  15760. //Defaults
  15761.  
  15762. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'only_store_pages' => 0 ) );
  15763.  
  15764. $title = esc_attr( $instance['title'] );
  15765.  
  15766. $count = isset($instance['count']) ? (bool) $instance['count'] :false;
  15767.  
  15768. $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
  15769.  
  15770. $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
  15771.  
  15772. $only_store_pages = isset( $instance['only_store_pages'] ) ? (bool) $instance['only_store_pages'] : false;
  15773.  
  15774. ?>
  15775.  
  15776. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
  15777.  
  15778. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
  15779.  
  15780.  
  15781.  
  15782. <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
  15783.  
  15784. <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Show as dropdown' ); ?></label><br />
  15785.  
  15786.  
  15787.  
  15788. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
  15789.  
  15790. <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show product counts', 'mp' ); ?></label><br />
  15791.  
  15792.  
  15793.  
  15794. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
  15795.  
  15796. <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
  15797.  
  15798.  
  15799.  
  15800. <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('only_store_pages'); ?>" name="<?php echo $this->get_field_name('only_store_pages'); ?>"<?php checked( $only_store_pages ); ?> />
  15801.  
  15802. <label for="<?php echo $this->get_field_id('only_store_pages'); ?>"><?php _e( 'Only show on store pages', 'mp' ); ?></label></p>
  15803.  
  15804. <?php
  15805.  
  15806. }
  15807.  
  15808. }
  15809.  
  15810.  
  15811.  
  15812. //Product tags cloud
  15813.  
  15814. class MarketPress_Tag_Cloud_Widget extends WP_Widget {
  15815.  
  15816.  
  15817.  
  15818. function MarketPress_Tag_Cloud_Widget() {
  15819.  
  15820. $widget_ops = array( 'classname' => 'mp_tag_cloud_widget', 'description' => __( "Your most used product tags in cloud format from your MarketPress store.") );
  15821.  
  15822. $this->WP_Widget('mp_tag_cloud_widget', __('Product Tag Cloud', 'mp'), $widget_ops);
  15823.  
  15824. }
  15825.  
  15826.  
  15827.  
  15828. function widget( $args, $instance ) {
  15829.  
  15830.  
  15831.  
  15832. if ($instance['only_store_pages'] && !mp_is_shop_page())
  15833.  
  15834. return;
  15835.  
  15836.  
  15837.  
  15838. extract($args);
  15839.  
  15840. $current_taxonomy = 'product_tag';
  15841.  
  15842. if ( !empty($instance['title']) ) {
  15843.  
  15844. $title = $instance['title'];
  15845.  
  15846. }
  15847.  
  15848. $title = apply_filters('widget_title', $title, $instance, $this->id_base);
  15849.  
  15850.  
  15851.  
  15852. echo $before_widget;
  15853.  
  15854. if ( $title )
  15855.  
  15856. echo $before_title . $title . $after_title;
  15857.  
  15858. echo '<div>';
  15859.  
  15860. wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
  15861.  
  15862. echo "</div>\n";
  15863.  
  15864. echo $after_widget;
  15865.  
  15866. }
  15867.  
  15868.  
  15869.  
  15870. function update( $new_instance, $old_instance ) {
  15871.  
  15872. $instance['title'] = strip_tags(stripslashes($new_instance['title']));
  15873.  
  15874. $instance['only_store_pages'] = !empty($new_instance['only_store_pages']) ? 1 : 0;
  15875.  
  15876. return $instance;
  15877.  
  15878. }
  15879.  
  15880.  
  15881.  
  15882. function form( $instance ) {
  15883.  
  15884. $instance = wp_parse_args( (array) $instance, array( 'title' => __('Product Tags', 'mp'), 'only_store_pages' => 0 ) );
  15885.  
  15886. $only_store_pages = isset( $instance['only_store_pages'] ) ? (bool) $instance['only_store_pages'] : false;
  15887.  
  15888. ?>
  15889.  
  15890. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  15891.  
  15892. <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
  15893.  
  15894.  
  15895.  
  15896. <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('only_store_pages'); ?>" name="<?php echo $this->get_field_name('only_store_pages'); ?>"<?php checked( $only_store_pages ); ?> />
  15897.  
  15898. <label for="<?php echo $this->get_field_id('only_store_pages'); ?>"><?php _e( 'Only show on store pages', 'mp' ); ?></label></p>
  15899.  
  15900. <?php
  15901.  
  15902. }
  15903.  
  15904. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement