WP eCommerce - Version 3.8.13-beta

Version Description

Download this release

Release Info

Developer garyc40
Plugin Icon 128x128 WP eCommerce
Version 3.8.13-beta
Comparing to
See all releases

Code changes from version 3.8.12.1 to 3.8.13-beta

Files changed (171) hide show
  1. .gitignore +1 -1
  2. readme.md +1 -1
  3. readme.txt +36 -34
  4. wp-shopping-cart.php +55 -25
  5. wpsc-admin/admin-form-functions.php +0 -196
  6. wpsc-admin/admin.php +30 -3
  7. wpsc-admin/ajax.php +49 -3
  8. wpsc-admin/css/admin.css +23 -14
  9. wpsc-admin/css/media.css +26 -0
  10. wpsc-admin/db-upgrades/routines/4.php +2 -1
  11. wpsc-admin/db-upgrades/routines/5.php +49 -0
  12. wpsc-admin/db-upgrades/routines/6.php +11 -0
  13. wpsc-admin/db-upgrades/routines/7.php +36 -0
  14. wpsc-admin/db-upgrades/upgrade.php +1 -1
  15. wpsc-admin/display-coupon-add.php +2 -1
  16. wpsc-admin/display-coupon-edit.php +1 -1
  17. wpsc-admin/display-items.page.php +9 -23
  18. wpsc-admin/includes/display-items-functions.php +119 -146
  19. wpsc-admin/includes/product-variation-list-table.class.php +16 -2
  20. wpsc-admin/includes/product-variations-page.class.php +2 -0
  21. wpsc-admin/includes/purchase-log-list-table-class.php +1 -1
  22. wpsc-admin/includes/purchase-logs-page/packing-slip.php +2 -0
  23. wpsc-admin/includes/save-data.functions.php +2 -2
  24. wpsc-admin/includes/settings-tabs/admin.php +1 -1
  25. wpsc-admin/includes/settings-tabs/gateway.php +2 -2
  26. wpsc-admin/init.php +42 -52
  27. wpsc-admin/js/admin.js +3 -3
  28. wpsc-admin/js/media.js +392 -0
  29. wpsc-admin/js/product-variations.js +25 -2
  30. wpsc-admin/js/variations.js +8 -2
  31. wpsc-admin/media.php +95 -0
  32. wpsc-admin/settings-page.php +14 -5
  33. wpsc-admin/users.php +8 -0
  34. wpsc-components/marketplace-core-v1/library/Sputnik.php +597 -0
  35. wpsc-components/marketplace-core-v1/library/Sputnik/API.php +238 -0
  36. wpsc-components/marketplace-core-v1/library/Sputnik/API/Auth.php +133 -0
  37. wpsc-components/marketplace-core-v1/library/Sputnik/Admin.php +973 -0
  38. wpsc-components/marketplace-core-v1/library/Sputnik/Library/Plugin.php +128 -0
  39. wpsc-components/marketplace-core-v1/library/Sputnik/Library/Plugin/Base.php +109 -0
  40. wpsc-components/marketplace-core-v1/library/Sputnik/Library/Plugin/Dynamic.php +85 -0
  41. wpsc-components/marketplace-core-v1/library/Sputnik/Library/TwitterOAuth.php +147 -0
  42. wpsc-components/marketplace-core-v1/library/Sputnik/Library/TwitterOAuth/Internal.php +242 -0
  43. wpsc-components/marketplace-core-v1/library/Sputnik/Library/TwitterOAuth/LICENSE +22 -0
  44. wpsc-components/marketplace-core-v1/library/Sputnik/List/Account.php +162 -0
  45. wpsc-components/marketplace-core-v1/library/Sputnik/List/Install.php +466 -0
  46. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Consumer.php +16 -0
  47. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/DataStore.php +27 -0
  48. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Exception.php +7 -0
  49. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Request.php +261 -0
  50. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Server.php +222 -0
  51. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/SignatureMethod.php +54 -0
  52. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/SignatureMethod/HMAC/SHA1.php +29 -0
  53. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/SignatureMethod/PLAINTEXT.php +34 -0
  54. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/SignatureMethod/RSA/SHA1.php +68 -0
  55. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Token.php +31 -0
  56. wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Util.php +152 -0
  57. wpsc-components/marketplace-core-v1/library/Sputnik/Pointers.php +57 -0
  58. wpsc-components/marketplace-core-v1/library/Sputnik/ThemeUpgrader.php +55 -0
  59. wpsc-components/marketplace-core-v1/library/Sputnik/Theme_Upgrader.php +55 -0
  60. wpsc-components/marketplace-core-v1/library/Sputnik/Updater.php +198 -0
  61. wpsc-components/marketplace-core-v1/library/Sputnik/Upgrader.php +55 -0
  62. wpsc-components/marketplace-core-v1/library/Sputnik/Upgrader/Skin.php +65 -0
  63. wpsc-components/marketplace-core-v1/library/Sputnik/View.php +80 -0
  64. wpsc-components/marketplace-core-v1/library/Sputnik/View/Account.php +140 -0
  65. wpsc-components/marketplace-core-v1/library/Sputnik/View/Auth.php +34 -0
  66. wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser.php +120 -0
  67. wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser/Grid.php +318 -0
  68. wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser/List.php +82 -0
  69. wpsc-components/marketplace-core-v1/library/Sputnik/View/Info.php +202 -0
  70. wpsc-components/marketplace-core-v1/library/Sputnik/View/Install.php +80 -0
  71. wpsc-components/marketplace-core-v1/library/Sputnik/View/Install/Skin.php +64 -0
  72. wpsc-components/marketplace-core-v1/library/Sputnik/View/Mini.php +32 -0
  73. wpsc-components/marketplace-core-v1/library/Sputnik/View/Upgrade.php +53 -0
  74. wpsc-components/marketplace-core-v1/library/Sputnik/index.php +2 -0
  75. wpsc-components/marketplace-core-v1/marketplace-core-v1.php +20 -0
  76. wpsc-components/marketplace-core-v1/static/admin.css +487 -0
  77. wpsc-components/marketplace-core-v1/static/admin.js +103 -0
  78. wpsc-components/marketplace-core-v1/static/gray-star.png +0 -0
  79. wpsc-components/marketplace-core-v1/static/grid.png +0 -0
  80. wpsc-components/marketplace-core-v1/static/icon16.png +0 -0
  81. wpsc-components/marketplace-core-v1/static/icon32.png +0 -0
  82. wpsc-components/marketplace-core-v1/static/icons.png +0 -0
  83. wpsc-components/marketplace-core-v1/static/jquery.masonry.js +10 -0
  84. wpsc-components/marketplace-core-v1/static/logo.png +0 -0
  85. wpsc-components/marketplace-core-v1/static/modal.css +1628 -0
  86. wpsc-components/marketplace-core-v1/static/modal.js +313 -0
  87. wpsc-components/marketplace-core-v1/static/sputnik.css +63 -0
  88. wpsc-components/marketplace-core-v1/static/sputnik.js +5 -0
  89. wpsc-components/marketplace-core-v1/static/star.png +0 -0
  90. wpsc-components/merchant-core-v2/helpers/admin.php +1 -1
  91. wpsc-components/merchant-core-v2/helpers/checkout.php +172 -5
  92. wpsc-components/merchant-core-v2/helpers/gateways.php +96 -0
  93. wpsc-includes/breadcrumbs.class.php → wpsc-components/theme-engine-v1/classes/breadcrumbs.php +1 -3
  94. wpsc-components/theme-engine-v1/classes/hide-subcatsprods-in-cat.php +61 -0
  95. wpsc-admin/includes/settings-tabs/presentation.php → wpsc-components/theme-engine-v1/classes/settings-tab-presentation.php +1 -1
  96. wpsc-components/theme-engine-v1/classes/wpsc-products-by-category.php +135 -0
  97. wpsc-components/theme-engine-v1/helpers/admin.php +14 -0
  98. wpsc-components/theme-engine-v1/helpers/ajax.php +1112 -0
  99. wpsc-components/theme-engine-v1/helpers/cart.php +122 -0
  100. wpsc-components/theme-engine-v1/helpers/checkout.php +402 -0
  101. wpsc-components/theme-engine-v1/helpers/form.php +87 -0
  102. wpsc-components/theme-engine-v1/helpers/page.php +1393 -0
  103. wpsc-components/theme-engine-v1/helpers/product.php +868 -0
  104. wpsc-components/theme-engine-v1/helpers/query.php +612 -0
  105. wpsc-components/theme-engine-v1/helpers/rewrite.php +71 -0
  106. wpsc-components/theme-engine-v1/helpers/rss.php +28 -0
  107. wpsc-components/theme-engine-v1/helpers/shipping.php +150 -0
  108. wpsc-includes/shortcode.functions.php → wpsc-components/theme-engine-v1/helpers/shortcodes.php +15 -2
  109. wpsc-components/theme-engine-v1/helpers/template-tags.php +1749 -0
  110. wpsc-components/theme-engine-v1/helpers/template.php +283 -0
  111. wpsc-components/theme-engine-v1/helpers/thumbnails.php +68 -0
  112. wpsc-includes/rss_template.php → wpsc-components/theme-engine-v1/rss/rss.php +1 -1
  113. wpsc-components/theme-engine-v1/templates/compatibility.css +50 -0
  114. wpsc-components/theme-engine-v1/templates/functions/wpsc-transaction_results_functions.php +130 -0
  115. wpsc-components/theme-engine-v1/templates/functions/wpsc-user_log_functions.php +792 -0
  116. wpsc-components/theme-engine-v1/templates/wpsc-account-downloads.php +40 -0
  117. wpsc-components/theme-engine-v1/templates/wpsc-account-edit-profile.php +28 -0
  118. wpsc-components/theme-engine-v1/templates/wpsc-account-purchase-history.php +55 -0
  119. wpsc-components/theme-engine-v1/templates/wpsc-cart_widget.php +66 -0
  120. wpsc-components/theme-engine-v1/templates/wpsc-category-list.php +19 -0
  121. wpsc-components/theme-engine-v1/templates/wpsc-category_widget.php +68 -0
  122. wpsc-components/theme-engine-v1/templates/wpsc-default.css +1102 -0
  123. wpsc-components/theme-engine-v1/templates/wpsc-featured_product.php +38 -0
  124. wpsc-components/theme-engine-v1/templates/wpsc-grid_view.php +181 -0
  125. wpsc-components/theme-engine-v1/templates/wpsc-images/bulletpoint.gif +0 -0
  126. wpsc-components/theme-engine-v1/templates/wpsc-images/cart.png +0 -0
  127. wpsc-components/theme-engine-v1/templates/wpsc-images/delete.png +0 -0
  128. wpsc-components/theme-engine-v1/templates/wpsc-images/gold-star.gif +0 -0
  129. wpsc-components/theme-engine-v1/templates/wpsc-images/grey-star.gif +0 -0
  130. wpsc-components/theme-engine-v1/templates/wpsc-images/icon_window_collapse.gif +0 -0
  131. wpsc-components/theme-engine-v1/templates/wpsc-images/icon_window_expand.gif +0 -0
  132. wpsc-components/theme-engine-v1/templates/wpsc-images/indicator.gif +0 -0
  133. wpsc-components/theme-engine-v1/templates/wpsc-images/no_stock.gif +0 -0
  134. wpsc-components/theme-engine-v1/templates/wpsc-images/noimage.png +0 -0
  135. wpsc-components/theme-engine-v1/templates/wpsc-images/outofstock.png +0 -0
  136. wpsc-components/theme-engine-v1/templates/wpsc-images/sale.png +0 -0
  137. wpsc-components/theme-engine-v1/templates/wpsc-images/yes_stock.gif +0 -0
  138. wpsc-components/theme-engine-v1/templates/wpsc-images/yes_stock.png +0 -0
  139. wpsc-components/theme-engine-v1/templates/wpsc-list_view.php +154 -0
  140. wpsc-components/theme-engine-v1/templates/wpsc-products_page.php +238 -0
  141. wpsc-components/theme-engine-v1/templates/wpsc-shopping_cart_page.php +488 -0
  142. wpsc-components/theme-engine-v1/templates/wpsc-single_product.php +217 -0
  143. wpsc-components/theme-engine-v1/templates/wpsc-transaction_results.php +14 -0
  144. wpsc-components/theme-engine-v1/templates/wpsc-user-log.php +55 -0
  145. wpsc-components/theme-engine-v1/theme-engine-v1.php +95 -0
  146. wpsc-components/theme-engine-v1/widgets/admin_menu_widget.php +113 -0
  147. wpsc-components/theme-engine-v1/widgets/cart.php +34 -0
  148. {wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/category_widget.php +8 -9
  149. {wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/donations_widget.php +27 -27
  150. {wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/latest_product_widget.php +4 -4
  151. {wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/price_range_widget.php +1 -1
  152. {wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/product_tag_widget.php +14 -14
  153. {wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/shopping_cart_widget.php +3 -3
  154. {wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/specials_widget.php +2 -2
  155. wpsc-components/theme-engine-v1/widgets/tagging_functions.php +166 -0
  156. wpsc-core/js/wp-e-commerce.js +15 -16
  157. wpsc-core/js/wpsc_colorbox.css +1 -25
  158. wpsc-core/wpsc-constants.php +9 -41
  159. wpsc-core/wpsc-deprecated.php +417 -20
  160. wpsc-core/wpsc-functions.php +47 -1377
  161. wpsc-core/wpsc-includes.php +2 -11
  162. wpsc-core/wpsc-installer.php +2 -2
  163. wpsc-includes/ajax.functions.php +1 -989
  164. wpsc-includes/cart-item.class.php +641 -0
  165. wpsc-includes/cart.class.php +32 -867
  166. wpsc-includes/category.functions.php +6 -493
  167. wpsc-includes/checkout.class.php +2 -415
  168. wpsc-includes/coupons.class.php +64 -59
  169. wpsc-includes/cron.php +13 -6
  170. wpsc-includes/customer.php +464 -0
  171. wpsc-includes/display.functions.php +0 -22
.gitignore CHANGED
@@ -1,2 +1,2 @@
1
  cookbooks
2
- tmp
1
  cookbooks
2
+ tmp
readme.md CHANGED
@@ -15,7 +15,7 @@ If you're looking for general user support, please submit your support request o
15
  Development status
16
  -------------------------
17
 
18
- * The latest stable version is [3.8.12.1](http://wordpress.org/extend/plugins/wp-e-commerce).
19
  * Active development version: 3.8.13-dev (branch [master](https://github.com/wp-e-commerce/WP-e-Commerce))
20
  * [Roadmap for 3.8.13](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Roadmap)
21
  * [3.8.13 tickets](https://github.com/wp-e-commerce/wp-e-commerce/issues?milestone=11&sort=updated&state=open)
15
  Development status
16
  -------------------------
17
 
18
+ * The latest stable version is [3.8.12](http://wordpress.org/extend/plugins/wp-e-commerce).
19
  * Active development version: 3.8.13-dev (branch [master](https://github.com/wp-e-commerce/WP-e-Commerce))
20
  * [Roadmap for 3.8.13](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Roadmap)
21
  * [3.8.13 tickets](https://github.com/wp-e-commerce/wp-e-commerce/issues?milestone=11&sort=updated&state=open)
readme.txt CHANGED
@@ -2,15 +2,15 @@
2
  Contributors: mufasa, garyc40, JustinSainton
3
  Donate link: http://getshopped.org
4
  Tags: e-commerce, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax
5
- Requires at least: 3.4
6
- Tested up to: 3.6
7
  Stable tag: 3.8.12.1
8
 
9
  WP e-Commerce is a free WordPress Shopping Cart Plugin that lets customers buy your products, services and digital downloads online.
10
 
11
  == Description ==
12
 
13
- We make setting up an ecommerce shop easy, and with over 2.4 Million downloads, we have unparalleled experience.
14
 
15
  Features:
16
 
@@ -146,6 +146,39 @@ After upgrading from earlier versions look for link "Update Store". This will up
146
 
147
  == Changelog ==
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  = 3.8.12.1 =
150
  * Fix: Fatal error in wpsc_product_list_exclude_child_categories() due to other themes
151
  or plugins calling get_posts() before the main query is set up
@@ -669,37 +702,6 @@ After upgrading from earlier versions look for link "Update Store". This will up
669
  * Fix: Checking (or unchecking) Stock checkbox when editing product causes variation table columns to break.
670
  * Fix: jQuery 1.6 incompatibility with attr( 'className' ).
671
 
672
-
673
- = 3.8.5 =
674
- * New: Added hooks to support WPML.
675
- * New: Links to WP e-Commerce documentation for individual payment gateways.
676
- * Change: User can specify 0 in thumbnail width or height to make it scale proportional.
677
- * Change: Show display name, not internal name for shipping method on purchase log view.
678
- * Change: Presentation settings page is restored to WPEC Settings page when WooTheme is activated.
679
- * Fix: Add to cart using Donation widget causes the page to reload and the item is added twice.
680
- * Fix: Free-shipping discount causes tax to be calculated incorrectly.
681
- * Fix: Paypal Buy Now button passes the wrong price to Paypal if product is on sale.
682
- * Fix: Thumbnail sizes are not generated correctly.
683
- * Fix: Broken output buffering rendering wpsc_add_advanced_options hook useless.
684
- * Fix: Paypal Pro doesn't properly account for discount and coupon.
685
- * Fix: IPN doesn't work on Paypal Standard.
686
- * Fix: IPN doesn't work on Paypal Pro gateway.
687
- * Fix: Paypal Express doesn't handle discounts.
688
- * Fix: Paypal Express doesn't handle IPN.
689
- * Fix: Paypal Express doesn't send purchase receipt after a payment is accepted on Paypal.
690
- * Fix: Paypal Express doesn't include item description, quantity, tax etc. in email receipts.
691
- * Fix: Invalid country code in Paypal Pro and Express, should be GB instead of UK
692
- * Fix: Take Discount into account when DoExpressCheckout in Paypal Express gateway.
693
- * Fix: Category checkout form sets don't work.
694
- * Fix: Incorrect Product display mode selected when ['view_type'] is set and 'show_advanced_search' is disabled.
695
- * Fix: PHP notice in wpsc-transaction_results_functions.php.
696
- * Fix: attr('checked') == true always evaluates to false. Use is(':checked') instead.
697
- * Fix: jQuery 1.6 select by attribute incompatibility.
698
- * Fix: Price tag is added to RSS even when there is no price.
699
- * Fix: Span tag is not closed in issue 598.
700
- * Fix: Faulty php tag in template (issue 589).
701
- * Fix: PHP Notices when checking out with shipping disabled.
702
-
703
  == Frequently Asked Questions ==
704
 
705
  = How do I customize WP e-Commerce =
2
  Contributors: mufasa, garyc40, JustinSainton
3
  Donate link: http://getshopped.org
4
  Tags: e-commerce, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax
5
+ Requires at least: 3.5
6
+ Tested up to: 3.7
7
  Stable tag: 3.8.12.1
8
 
9
  WP e-Commerce is a free WordPress Shopping Cart Plugin that lets customers buy your products, services and digital downloads online.
10
 
11
  == Description ==
12
 
13
+ We make setting up an ecommerce shop easy, and with over 2.6 Million downloads, we have unparalleled experience.
14
 
15
  Features:
16
 
146
 
147
  == Changelog ==
148
 
149
+ = 3.8.13 =
150
+
151
+ * New: Product Media UI.
152
+ * New: Cart Item Meta API
153
+ * New: 'wpsc_after_checkout_cart_rows' action.
154
+ * New: Add 'wpsc_default_dimension_unit' and 'wpsc_default_weight_unit' filters.
155
+ * New: Add 'wpsc_save_product_order' action and use it to save category product order in the term_relationships table.
156
+ * New: Add logic filter for coupons. We currently have one for properties, this should sufficiently round out the extensibility for the UI.
157
+ * New: Allow gateway images to be filtered.
158
+ * New: Allow multiple comma-separated categories in coupon conditions.
159
+ * New: Product Gallery metabox.
160
+ * Change: Better Customer API.
161
+ * Change: Prepend (WPEC) to widget names in wp-admin
162
+ * Change: Replace default noimage.png with a better image.
163
+ * Change: Updated NL language
164
+ * Change: Updated german language strings
165
+ * Fix: Add preg_quote() to coupon regexes that intend to parse strings. Fixes issue where unexpected results occur when strings contain slashes, or really, any regex-oriented characters.
166
+ * Fix: Change wpsc_get_remaining_quantity() to call the method dynamically, rather than statically. The previous behaviour caused a strict standards warning.
167
+ * Fix: Database Upgrade Routine to rename old _wpsc_* product metadata array keys so they no longer include the '_wpsc_' prefix
168
+ * Fix: In Purchase log admin screen, item count is sum of quantity field rather than count of rows
169
+ * Fix: Invert logic on shipping ZIP code check in core theme files.
170
+ * Fix: Modify behavior in Download CSV functionality to properly convert region IDs to regions.
171
+ * Fix: Modify wpsc_update_item_quantity() to listen for wpsc_quantity_update, reverting to $_POST['quantity'] only if it exists.
172
+ * Fix: PHP strict warnings.
173
+ * Fix: Properly quote SKUs in CSV file.
174
+ * Fix: Rename generically named function.
175
+ * Fix: Stock and sale price empty values should be preserved.
176
+ * Fix: Variation thumbnail size in admin screen.
177
+ * Fix: cart is not initialized when some shipping modules are triggered
178
+ * Fix: redundant product thumbnail is displayed on category / single product list.
179
+ * Fix: variation checkbox column width in WP 3.7.
180
+ * Fix: Out of stock message for variations now correctly shows variation of product for the title, rather than main product.
181
+
182
  = 3.8.12.1 =
183
  * Fix: Fatal error in wpsc_product_list_exclude_child_categories() due to other themes
184
  or plugins calling get_posts() before the main query is set up
702
  * Fix: Checking (or unchecking) Stock checkbox when editing product causes variation table columns to break.
703
  * Fix: jQuery 1.6 incompatibility with attr( 'className' ).
704
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
705
  == Frequently Asked Questions ==
706
 
707
  = How do I customize WP e-Commerce =
wp-shopping-cart.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WP e-Commerce
4
  * Plugin URI: http://getshopped.org/
5
  * Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://getshopped.org" target="_blank">GetShopped.org</a> | <a href="http://getshopped.org/forums/" target="_blank">Support Forum</a> | <a href="http://docs.getshopped.org/" target="_blank">Documentation</a>
6
- * Version: 3.8.12.1
7
  * Author: Instinct Entertainment
8
  * Author URI: http://getshopped.org/
9
  **/
@@ -17,7 +17,8 @@
17
  */
18
  class WP_eCommerce {
19
  private $components = array(
20
- 'merchant' => array(),
 
21
  );
22
 
23
  /**
@@ -26,9 +27,9 @@ class WP_eCommerce {
26
  * @uses add_action() Attaches to 'plugins_loaded' hook
27
  * @uses add_action() Attaches to 'wpsc_components' hook
28
  */
29
- function WP_eCommerce() {
30
  add_action( 'plugins_loaded' , array( $this, 'init' ), 8 );
31
- add_action( 'wpsc_components', array( $this, '_register_core_components' ) );
32
  }
33
 
34
  /**
@@ -56,19 +57,35 @@ class WP_eCommerce {
56
  }
57
 
58
  /**
59
- * @todo we need documentation finished here
60
  *
61
- * @param array $components
 
62
  *
63
- * @return array
 
 
 
64
  */
65
  public function _register_core_components( $components ) {
66
  $components['merchant']['core-v2'] = array(
67
- 'title' => __( 'WP e-Commerce Merchant API v2', 'wpsc' ),
68
  'includes' =>
69
  WPSC_FILE_PATH . '/wpsc-components/merchant-core-v2/merchant-core-v2.php'
70
  );
71
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  return $components;
73
  }
74
 
@@ -92,13 +109,31 @@ class WP_eCommerce {
92
  define( 'WPSC_URL', plugins_url( '', __FILE__ ) );
93
 
94
  //load text domain
95
- if( !load_plugin_textdomain( 'wpsc', false, '../languages/' ) )
96
  load_plugin_textdomain( 'wpsc', false, dirname( plugin_basename( __FILE__ ) ) . '/wpsc-languages/' );
97
 
98
  // Finished starting
99
  do_action( 'wpsc_started' );
100
  }
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  /**
103
  * Setup the WPEC core constants
104
  *
@@ -129,6 +164,9 @@ class WP_eCommerce {
129
  // WPEC Table names and related constants
130
  wpsc_core_constants_table_names();
131
 
 
 
 
132
  // Uploads directory info
133
  wpsc_core_constants_uploads();
134
 
@@ -143,6 +181,7 @@ class WP_eCommerce {
143
  * @uses do_action() Calls 'wpsc_includes' which runs after WPEC files have been included
144
  */
145
  function includes() {
 
146
  require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-functions.php' );
147
  require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-installer.php' );
148
  require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-includes.php' );
@@ -186,17 +225,11 @@ class WP_eCommerce {
186
  // Legacy action
187
  do_action( 'wpsc_before_init' );
188
 
189
- // Setup the customer ID just in case to make sure it's set up correctly
190
- _wpsc_action_create_customer_id( 'create' );
191
-
192
  // Setup the core WPEC globals
193
  wpsc_core_setup_globals();
194
 
195
- // Setup the core WPEC cart
196
- wpsc_core_setup_cart();
197
-
198
- // Load the thumbnail sizes
199
- wpsc_core_load_thumbnail_sizes();
200
 
201
  // Load the purchase log statuses
202
  wpsc_core_load_purchase_log_statuses();
@@ -210,9 +243,6 @@ class WP_eCommerce {
210
  // Load the shipping modules
211
  wpsc_core_load_shipping_modules();
212
 
213
- // Set page title array for important WPSC pages
214
- wpsc_core_load_page_titles();
215
-
216
  // WPEC is fully loaded
217
  do_action( 'wpsc_loaded' );
218
  }
@@ -226,10 +256,10 @@ class WP_eCommerce {
226
  */
227
  function install() {
228
  global $wp_version;
229
- if((float)$wp_version < 3.0){
230
- deactivate_plugins(plugin_basename(__FILE__)); // Deactivate ourselves
231
- wp_die( __('Looks like you\'re running an older version of WordPress, you need to be running at least WordPress 3.0 to use WP e-Commerce 3.8', 'wpsc'), __('WP e-Commerce 3.8 not compatible', 'wpsc'), array('back_link' => true));
232
- return;
233
  }
234
  define( 'WPSC_FILE_PATH', dirname( __FILE__ ) );
235
  require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-installer.php' );
@@ -256,5 +286,5 @@ class WP_eCommerce {
256
  $wpec = new WP_eCommerce();
257
 
258
  // Activation
259
- register_activation_hook( __FILE__, array( $wpec, 'install' ) );
260
  register_deactivation_hook( __FILE__, array( $wpec, 'deactivate' ) );
3
  * Plugin Name: WP e-Commerce
4
  * Plugin URI: http://getshopped.org/
5
  * Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://getshopped.org" target="_blank">GetShopped.org</a> | <a href="http://getshopped.org/forums/" target="_blank">Support Forum</a> | <a href="http://docs.getshopped.org/" target="_blank">Documentation</a>
6
+ * Version: 3.8.13-beta
7
  * Author: Instinct Entertainment
8
  * Author URI: http://getshopped.org/
9
  **/
17
  */
18
  class WP_eCommerce {
19
  private $components = array(
20
+ 'merchant' => array(),
21
+ 'marketplace' => array(),
22
  );
23
 
24
  /**
27
  * @uses add_action() Attaches to 'plugins_loaded' hook
28
  * @uses add_action() Attaches to 'wpsc_components' hook
29
  */
30
+ function __construct() {
31
  add_action( 'plugins_loaded' , array( $this, 'init' ), 8 );
32
+ add_filter( 'wpsc_components', array( $this, '_register_core_components' ) );
33
  }
34
 
35
  /**
57
  }
58
 
59
  /**
60
+ * New WPSC components API.
61
  *
62
+ * Allows for modular coupling of different functionalities within WPSC.
63
+ * This is the way we'll be introducing cutting-edge APIs
64
  *
65
+ * @since 3.8.9.5
66
+ *
67
+ * @param array $components
68
+ * @return array $components
69
  */
70
  public function _register_core_components( $components ) {
71
  $components['merchant']['core-v2'] = array(
72
+ 'title' => __( 'WP e-Commerce Merchant API v2', 'wpsc' ),
73
  'includes' =>
74
  WPSC_FILE_PATH . '/wpsc-components/merchant-core-v2/merchant-core-v2.php'
75
  );
76
 
77
+ $components['theme-engine']['core-v1'] = array(
78
+ 'title' => __( 'WP e-Commerce Theme Engine v1', 'wpsc' ),
79
+ 'includes' =>
80
+ WPSC_FILE_PATH . '/wpsc-components/theme-engine-v1/theme-engine-v1.php'
81
+ );
82
+
83
+ $components['marketplace']['core-v1'] = array(
84
+ 'title' => __( 'WP e-Commerce Marketplace API v1', 'wpsc' ),
85
+ 'includes' =>
86
+ WPSC_FILE_PATH . '/wpsc-components/marketplace-core-v1/marketplace-core-v1.php'
87
+ );
88
+
89
  return $components;
90
  }
91
 
109
  define( 'WPSC_URL', plugins_url( '', __FILE__ ) );
110
 
111
  //load text domain
112
+ if ( ! load_plugin_textdomain( 'wpsc', false, '../languages/' ) )
113
  load_plugin_textdomain( 'wpsc', false, dirname( plugin_basename( __FILE__ ) ) . '/wpsc-languages/' );
114
 
115
  // Finished starting
116
  do_action( 'wpsc_started' );
117
  }
118
 
119
+ function setup_table_names() {
120
+ global $wpdb;
121
+ $wpdb->wpsc_meta = WPSC_TABLE_META;
122
+ $wpdb->wpsc_also_bought = WPSC_TABLE_ALSO_BOUGHT;
123
+ $wpdb->wpsc_region_tax = WPSC_TABLE_REGION_TAX;
124
+ $wpdb->wpsc_coupon_codes = WPSC_TABLE_COUPON_CODES;
125
+ $wpdb->wpsc_cart_contents = WPSC_TABLE_CART_CONTENTS;
126
+ $wpdb->wpsc_claimed_stock = WPSC_TABLE_CLAIMED_STOCK;
127
+ $wpdb->wpsc_currency_list = WPSC_TABLE_CURRENCY_LIST;
128
+ $wpdb->wpsc_purchase_logs = WPSC_TABLE_PURCHASE_LOGS;
129
+ $wpdb->wpsc_checkout_forms = WPSC_TABLE_CHECKOUT_FORMS;
130
+ $wpdb->wpsc_cart_itemmeta = WPSC_TABLE_CART_ITEM_META; // required for _get_meta_table()
131
+ $wpdb->wpsc_cart_item_meta = WPSC_TABLE_CART_ITEM_META;
132
+ $wpdb->wpsc_product_rating = WPSC_TABLE_PRODUCT_RATING;
133
+ $wpdb->wpsc_download_status = WPSC_TABLE_DOWNLOAD_STATUS;
134
+ $wpdb->wpsc_submitted_form_data = WPSC_TABLE_SUBMITTED_FORM_DATA;
135
+ }
136
+
137
  /**
138
  * Setup the WPEC core constants
139
  *
164
  // WPEC Table names and related constants
165
  wpsc_core_constants_table_names();
166
 
167
+ // setup wpdb table name attributes
168
+ $this->setup_table_names();
169
+
170
  // Uploads directory info
171
  wpsc_core_constants_uploads();
172
 
181
  * @uses do_action() Calls 'wpsc_includes' which runs after WPEC files have been included
182
  */
183
  function includes() {
184
+ require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-meta-init.php' );
185
  require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-functions.php' );
186
  require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-installer.php' );
187
  require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-includes.php' );
225
  // Legacy action
226
  do_action( 'wpsc_before_init' );
227
 
 
 
 
228
  // Setup the core WPEC globals
229
  wpsc_core_setup_globals();
230
 
231
+ // Setup the customer ID just in case to make sure it's set up correctly
232
+ add_action( 'init', '_wpsc_action_setup_customer', 1 );
 
 
 
233
 
234
  // Load the purchase log statuses
235
  wpsc_core_load_purchase_log_statuses();
243
  // Load the shipping modules
244
  wpsc_core_load_shipping_modules();
245
 
 
 
 
246
  // WPEC is fully loaded
247
  do_action( 'wpsc_loaded' );
248
  }
256
  */
257
  function install() {
258
  global $wp_version;
259
+
260
+ if ( ( float ) $wp_version < 3.0 ) {
261
+ deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate ourselves
262
+ wp_die( __( 'Looks like you\'re running an older version of WordPress, you need to be running at least WordPress 3.0 to use WP e-Commerce 3.8', 'wpsc' ), __( 'WP e-Commerce 3.8 not compatible', 'wpsc' ), array( 'back_link' => true ) );
263
  }
264
  define( 'WPSC_FILE_PATH', dirname( __FILE__ ) );
265
  require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-installer.php' );
286
  $wpec = new WP_eCommerce();
287
 
288
  // Activation
289
+ register_activation_hook( __FILE__ , array( $wpec, 'install' ) );
290
  register_deactivation_hook( __FILE__, array( $wpec, 'deactivate' ) );
wpsc-admin/admin-form-functions.php CHANGED
@@ -254,201 +254,5 @@ function wpsc_right_now() {
254
  <?php
255
  }
256
 
257
-
258
- function wpsc_packing_slip( $purchase_id ) {
259
- echo "<!DOCTYPE html><html><meta http-equiv=\"content-type\" content=\"text-html; charset=utf-8\"><head><title>" . __( 'Packing Slip', 'wpsc' ) . "</title></head><body id='wpsc-packing-slip'>";
260
- global $wpdb;
261
- $purch_sql = $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`=%d", $purchase_id );
262
- $purch_data = $wpdb->get_row( $purch_sql, ARRAY_A ) ;
263
-
264
- $cartsql = $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`=%d", $purchase_id );
265
- $cart_log = $wpdb->get_results($cartsql,ARRAY_A) ;
266
- $j = 0;
267
-
268
- if($cart_log != null) {
269
- echo "<div class='packing_slip'>\n\r";
270
- echo apply_filters( 'wpsc_packing_slip_header', '<h2>' . esc_html__( 'Packing Slip', 'wpsc' ) . "</h2>\n\r" );
271
- echo "<strong>". esc_html__( 'Order', 'wpsc' )." #</strong> ".$purchase_id."<br /><br />\n\r";
272
-
273
- echo "<table>\n\r";
274
-
275
- $form_sql = $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_SUBMITTED_FORM_DATA."` WHERE `log_id` = %d", $purchase_id );
276
- $input_data = $wpdb->get_results($form_sql,ARRAY_A);
277
-
278
- foreach($input_data as $input_row) {
279
- $rekeyed_input[$input_row['form_id']] = $input_row;
280
- }
281
-
282
-
283
- if($input_data != null) {
284
- $form_data = $wpdb->get_results( "SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `active` = '1' ORDER BY `checkout_order`" , ARRAY_A );
285
-
286
- foreach($form_data as $form_field) {
287
-
288
- switch($form_field['type']) {
289
- case 'country':
290
- $region_count_sql = $wpdb->prepare( "SELECT COUNT(`regions`.`id`) FROM `".WPSC_TABLE_REGION_TAX."` AS `regions` INNER JOIN `".WPSC_TABLE_CURRENCY_LIST."` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('%s')", $purch_data['billing_country'] );
291
- $delivery_region_count = $wpdb->get_var( $region_count_sql );
292
-
293
- if(is_numeric($purch_data['billing_region']) && ($delivery_region_count > 0))
294
- echo " <tr><td>".esc_html__('State', 'wpsc').":</td><td>".wpsc_get_region($purch_data['billing_region'])."</td></tr>\n\r";
295
-
296
- echo " <tr><td>" . esc_html( $form_field['name'] ) . ":</td><td>" . esc_html( $rekeyed_input[$form_field['id']]['value'] ) . "</td></tr>\n\r";
297
- break;
298
-
299
- case 'delivery_country':
300
-
301
- if(is_numeric($purch_data['shipping_region']) && ($delivery_region_count > 0))
302
- echo " <tr><td>".esc_html__('State', 'wpsc').":</td><td>".wpsc_get_region($purch_data['shipping_region'])."</td></tr>\n\r";
303
-
304
- echo " <tr><td>" . esc_html( $form_field['name'] ) . ":</td><td>" . esc_html( $rekeyed_input[ $form_field['id']]['value'] ) . "</td></tr>\n\r";
305
- break;
306
-
307
- case 'heading':
308
-
309
- if($form_field['name'] == "Hidden Fields")
310
- continue;
311
- else
312
- echo " <tr class='heading'><td colspan='2'><strong>" . esc_html( $form_field['name'] ) . ":</strong></td></tr>\n\r";
313
- break;
314
-
315
- default:
316
- if ($form_field['name']=="State" && !empty($purch_data['billing_region']) || $form_field['name']=="State" && !empty($purch_data['billing_region']))
317
- echo "";
318
- else
319
- echo " <tr><td>" . esc_html( $form_field['name'] ) . ":</td><td>".
320
- ( isset( $rekeyed_input[$form_field['id']] ) ? esc_html( $rekeyed_input[$form_field['id']]['value'] ) : '' ) .
321
- "</td></tr>\n\r";
322
- break;
323
- }
324
-
325
- }
326
- } else {
327
- echo " <tr><td>".esc_html__('Name', 'wpsc').":</td><td>".$purch_data['firstname']." ".$purch_data['lastname']."</td></tr>\n\r";
328
- echo " <tr><td>".esc_html__('Address', 'wpsc').":</td><td>".$purch_data['address']."</td></tr>\n\r";
329
- echo " <tr><td>".esc_html__('Phone', 'wpsc').":</td><td>".$purch_data['phone']."</td></tr>\n\r";
330
- echo " <tr><td>".esc_html__('Email', 'wpsc').":</td><td>".$purch_data['email']."</td></tr>\n\r";
331
- }
332
-
333
- if ( 2 == get_option( 'payment_method' ) ) {
334
- $gateway_name = '';
335
- global $nzshpcrt_gateways;
336
-
337
- foreach( $nzshpcrt_gateways as $gateway ) {
338
- if ( $purch_data['gateway'] != 'testmode' ) {
339
- if ( $gateway['internalname'] == $purch_data['gateway'] ) {
340
- $gateway_name = $gateway['name'];
341
- }
342
- } else {
343
- $gateway_name = esc_html__('Manual Payment', 'wpsc');
344
- }
345
- }
346
- }
347
-
348
- echo "</table>\n\r";
349
-
350
-
351
- do_action ('wpsc_packing_slip_extra_info',$purchase_id);
352
-
353
-
354
- echo "<table class='packing_slip'>";
355
-
356
- echo "<tr>";
357
- echo " <th>".esc_html__('Quantity', 'wpsc')." </th>";
358
-
359
- echo " <th>".esc_html__('Name', 'wpsc')."</th>";
360
-
361
-
362
- echo " <th>".esc_html__('Price', 'wpsc')." </th>";
363
-
364
- echo " <th>".esc_html__('Shipping', 'wpsc')." </th>";
365
- echo '<th>' . esc_html__('Tax', 'wpsc') . '</th>';
366
- echo '</tr>';
367
- $endtotal = 0;
368
- $all_donations = true;
369
- $all_no_shipping = true;
370
- $file_link_list = array();
371
- $total_shipping = 0;
372
- foreach($cart_log as $cart_row) {
373
- $alternate = "";
374
- $j++;
375
- if(($j % 2) != 0) {
376
- $alternate = "class='alt'";
377
- }
378
- // product ID will be $cart_row['prodid']. need to fetch name and stuff
379
-
380
- $variation_list = '';
381
-
382
- if($cart_row['donation'] != 1) {
383
- $all_donations = false;
384
- }
385
-
386
- if($cart_row['no_shipping'] != 1) {
387
- $shipping = $cart_row['pnp'];
388
- $total_shipping += $shipping;
389
- $all_no_shipping = false;
390
- } else {
391
- $shipping = 0;
392
- }
393
-
394
- $price = $cart_row['price'] * $cart_row['quantity'];
395
- $gst = $price - ($price / (1+($cart_row['gst'] / 100)));
396
-
397
- if($gst > 0) {
398
- $tax_per_item = $gst / $cart_row['quantity'];
399
- }
400
-
401
-
402
- echo "<tr $alternate>";
403
-
404
-
405
- echo " <td>";
406
- echo $cart_row['quantity'];
407
- echo " </td>";
408
-
409
- echo " <td>";
410
- echo apply_filters( 'the_title', $cart_row['name'] );
411
- echo $variation_list;
412
- echo " </td>";
413
-
414
-
415
- echo " <td>";
416
- echo wpsc_currency_display( $price );
417
- echo " </td>";
418
-
419
- echo " <td>";
420
- echo wpsc_currency_display($shipping );
421
- echo " </td>";
422
-
423
-
424
-
425
- echo '<td>';
426
- echo wpsc_currency_display( $cart_row['tax_charged'] );
427
- echo '</td>';
428
- echo '</tr>';
429
- }
430
-
431
- echo "</table>";
432
- echo '<table class="packing-slip-totals">';
433
- if ( floatval( $purch_data['discount_value'] ) )
434
- echo '<tr><th>'.esc_html__('Discount', 'wpsc').'</th><td>(' . wpsc_currency_display( $purch_data['discount_value'] ) . ')</td></tr>';
435
-
436
- echo '<tr><th>'.esc_html__('Base Shipping','wpsc').'</th><td>' . wpsc_currency_display( $purch_data['base_shipping'] ) . '</td></tr>';
437
- echo '<tr><th>'.esc_html__('Total Shipping','wpsc').'</th><td>' . wpsc_currency_display( $purch_data['base_shipping'] + $total_shipping ) . '</td></tr>';
438
- //wpec_taxes
439
- if($purch_data['wpec_taxes_total'] != 0.00)
440
- {
441
- echo '<tr><th>'.esc_html__('Taxes','wpsc').'</th><td>' . wpsc_currency_display( $purch_data['wpec_taxes_total'] ) . '</td></tr>';
442
- }
443
- echo '<tr><th>'.esc_html__('Total Price','wpsc').'</th><td>' . wpsc_currency_display( $purch_data['totalprice'] ) . '</td></tr>';
444
- echo '</table>';
445
-
446
- echo "</div>\n\r";
447
- } else {
448
- echo "<br />".esc_html__('This users cart was empty', 'wpsc');
449
- }
450
-
451
- }
452
-
453
  function wpsc_product_item_row() {
454
  }
254
  <?php
255
  }
256
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  function wpsc_product_item_row() {
258
  }
wpsc-admin/admin.php CHANGED
@@ -24,6 +24,8 @@ require_once( WPSC_FILE_PATH . '/wpsc-admin/init.php' );
24
  require_once( WPSC_FILE_PATH . '/wpsc-admin/ajax-and-init.php' );
25
  require_once( WPSC_FILE_PATH . '/wpsc-admin/display-options-settings.page.php' );
26
  require_once( WPSC_FILE_PATH . '/wpsc-admin/db-upgrades/upgrade.php' );
 
 
27
 
28
  if ( ( isset( $_SESSION['wpsc_activate_debug_page'] ) && ( $_SESSION['wpsc_activate_debug_page'] == true ) ) || ( defined( 'WPSC_ADD_DEBUG_PAGE' ) && ( constant( 'WPSC_ADD_DEBUG_PAGE' ) == true ) ) )
29
  require_once( WPSC_FILE_PATH . '/wpsc-admin/display-debug.page.php' );
@@ -59,6 +61,29 @@ function wpsc_query_vars_product_list( $vars ){
59
  return $vars;
60
  }
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  /**
63
  * setting the screen option to between 1 and 999
64
  *
@@ -479,12 +504,13 @@ function wpsc_meta_boxes() {
479
  remove_meta_box( 'wpsc_product_categorydiv' , 'wpsc-product', 'core' );
480
  }
481
 
 
482
  add_meta_box( 'wpsc_price_control_forms', __('Price Control', 'wpsc'), 'wpsc_price_control_forms', $pagename, 'side', 'low' );
483
  add_meta_box( 'wpsc_stock_control_forms', __('Stock Control', 'wpsc'), 'wpsc_stock_control_forms', $pagename, 'side', 'low' );
484
  add_meta_box( 'wpsc_product_taxes_forms', __('Taxes', 'wpsc'), 'wpsc_product_taxes_forms', $pagename, 'side', 'low' );
485
  add_meta_box( 'wpsc_additional_desc', __('Additional Description', 'wpsc'), 'wpsc_additional_desc', $pagename, 'normal', 'high' );
486
  add_meta_box( 'wpsc_product_download_forms', __('Product Download', 'wpsc'), 'wpsc_product_download_forms', $pagename, 'normal', 'high' );
487
- add_meta_box( 'wpsc_product_image_forms', __('Product Images', 'wpsc'), 'wpsc_product_image_forms', $pagename, 'normal', 'high' );
488
  if ( ! empty( $post->ID ) && ! wpsc_product_has_variations( $post->ID ) )
489
  add_meta_box( 'wpsc_product_shipping_forms', __('Shipping', 'wpsc'), 'wpsc_product_shipping_forms_metabox', $pagename, 'normal', 'high' );
490
  add_meta_box( 'wpsc_product_advanced_forms', __('Advanced Settings', 'wpsc'), 'wpsc_product_advanced_forms', $pagename, 'normal', 'high' );
@@ -1506,10 +1532,11 @@ if ( ! get_option( 'wpsc_hide_3.8.9_notices' ) )
1506
  * @uses get_option() Gets option from the database given string
1507
  */
1508
  function _wpsc_admin_notices_3dot8dot11() {
1509
- $message = '<p>' . __( 'You are currently using WPeC 3.8.11. We have included a fix for a <a href="%1$s">bug on the User Account management page</a>. We are able to fix this automatically on most sites, but it appears that you have made changes to your wpsc-user-log.php page. For that reason, we have some <a href="%2$s">simple instructions for you to follow</a> to resolve the issue. We are sorry for the inconvenience.' , 'wpsc' ) . '</p>';
1510
- $message .= "\n<p>" . __( '<a href="%3$s">Hide this warning</a>', 'wpsc' ) . '</p>';
1511
  $message = sprintf(
1512
  $message,
 
1513
  'https://github.com/wp-e-commerce/WP-e-Commerce/issues/359',
1514
  'http://docs.getshopped.org/documentation/3-8-11-user-logs',
1515
  add_query_arg( 'dismiss_3811_upgrade_notice', 1 )
24
  require_once( WPSC_FILE_PATH . '/wpsc-admin/ajax-and-init.php' );
25
  require_once( WPSC_FILE_PATH . '/wpsc-admin/display-options-settings.page.php' );
26
  require_once( WPSC_FILE_PATH . '/wpsc-admin/db-upgrades/upgrade.php' );
27
+ require_once( WPSC_FILE_PATH . '/wpsc-admin/media.php' );
28
+ require_once( WPSC_FILE_PATH . '/wpsc-admin/users.php' );
29
 
30
  if ( ( isset( $_SESSION['wpsc_activate_debug_page'] ) && ( $_SESSION['wpsc_activate_debug_page'] == true ) ) || ( defined( 'WPSC_ADD_DEBUG_PAGE' ) && ( constant( 'WPSC_ADD_DEBUG_PAGE' ) == true ) ) )
31
  require_once( WPSC_FILE_PATH . '/wpsc-admin/display-debug.page.php' );
61
  return $vars;
62
  }
63
 
64
+ /**
65
+ * Admin Edit Posts Order
66
+ *
67
+ * @since 3.8.12
68
+ * @access public
69
+ *
70
+ * @param string $orderby_sql Order by SQL.
71
+ * @return string Filtered order by SQL.
72
+ */
73
+ function wpsc_admin_edit_posts_orderby( $orderby_sql ) {
74
+ global $wp_query, $wpdb;
75
+ if ( 'dragndrop' == get_option( 'wpsc_sort_by' ) ) {
76
+ if ( function_exists( 'is_main_query' ) && is_main_query() && 'wpsc-product' == get_query_var( 'post_type' ) && is_tax( 'wpsc_product_category' ) ) {
77
+ if ( ! empty( $orderby_sql ) )
78
+ $orderby_sql = ', ' . $orderby_sql;
79
+ $orderby_sql = " {$wpdb->term_relationships}.term_order ASC" . $orderby_sql;
80
+ remove_filter( 'posts_orderby', 'wpsc_admin_edit_posts_orderby' );
81
+ }
82
+ }
83
+ return $orderby_sql;
84
+ }
85
+ add_filter( 'posts_orderby', 'wpsc_admin_edit_posts_orderby' );
86
+
87
  /**
88
  * setting the screen option to between 1 and 999
89
  *
504
  remove_meta_box( 'wpsc_product_categorydiv' , 'wpsc-product', 'core' );
505
  }
506
 
507
+ add_meta_box( 'wpsc_product_gallery', __( 'Product Gallery', 'wpsc' ), 'wpsc_product_gallery', $pagename, 'side', 'low' );
508
  add_meta_box( 'wpsc_price_control_forms', __('Price Control', 'wpsc'), 'wpsc_price_control_forms', $pagename, 'side', 'low' );
509
  add_meta_box( 'wpsc_stock_control_forms', __('Stock Control', 'wpsc'), 'wpsc_stock_control_forms', $pagename, 'side', 'low' );
510
  add_meta_box( 'wpsc_product_taxes_forms', __('Taxes', 'wpsc'), 'wpsc_product_taxes_forms', $pagename, 'side', 'low' );
511
  add_meta_box( 'wpsc_additional_desc', __('Additional Description', 'wpsc'), 'wpsc_additional_desc', $pagename, 'normal', 'high' );
512
  add_meta_box( 'wpsc_product_download_forms', __('Product Download', 'wpsc'), 'wpsc_product_download_forms', $pagename, 'normal', 'high' );
513
+
514
  if ( ! empty( $post->ID ) && ! wpsc_product_has_variations( $post->ID ) )
515
  add_meta_box( 'wpsc_product_shipping_forms', __('Shipping', 'wpsc'), 'wpsc_product_shipping_forms_metabox', $pagename, 'normal', 'high' );
516
  add_meta_box( 'wpsc_product_advanced_forms', __('Advanced Settings', 'wpsc'), 'wpsc_product_advanced_forms', $pagename, 'normal', 'high' );
1532
  * @uses get_option() Gets option from the database given string
1533
  */
1534
  function _wpsc_admin_notices_3dot8dot11() {
1535
+ $message = '<p>' . __( 'You are currently using WPeC %1$s. We introduced a regression in WPeC 3.8.10 which affects your customer user account page. We have included a fix for a <a href="%2$s">bug on the User Account management page</a>. We are able to fix this automatically on most sites, but it appears that you have made changes to your wpsc-user-log.php page. For that reason, we have some <a href="%3$s">simple instructions for you to follow</a> to resolve the issue. We are sorry for the inconvenience.' , 'wpsc' ) . '</p>';
1536
+ $message .= "\n<p>" . __( '<a href="%4$s">Hide this warning</a>', 'wpsc' ) . '</p>';
1537
  $message = sprintf(
1538
  $message,
1539
+ WPSC_VERSION,
1540
  'https://github.com/wp-e-commerce/WP-e-Commerce/issues/359',
1541
  'http://docs.getshopped.org/documentation/3-8-11-user-logs',
1542
  add_query_arg( 'dismiss_3811_upgrade_notice', 1 )
wpsc-admin/ajax.php CHANGED
@@ -20,15 +20,19 @@ function _wpsc_ajax_verify_nonce( $ajax_action ) {
20
  elseif ( isset( $_REQUEST['_wpnonce'] ) )
21
  $nonce = $_REQUEST['_wpnonce'];
22
  else
23
- return new WP_Error( 'wpsc_ajax_invalid_nonce', __( 'Your session has expired. Please refresh the page and try again.', 'wpsc' ) );
24
 
25
  // validate nonce
26
  if ( ! wp_verify_nonce( $nonce, 'wpsc_ajax_' . $ajax_action ) )
27
- return new WP_Error( 'wpsc_ajax_invalid_nonce', __( 'Your session has expired. Please refresh the page and try again.', 'wpsc' ) );
28
 
29
  return true;
30
  }
31
 
 
 
 
 
32
  /**
33
  * Verify AJAX callback and call it if it exists.
34
  *
@@ -68,7 +72,11 @@ function _wpsc_ajax_fire_callback( $ajax_action ) {
68
  */
69
  function _wpsc_ajax_handler() {
70
  $ajax_action = str_replace( '-', '_', $_REQUEST['wpsc_action'] );
71
- $result = _wpsc_ajax_verify_nonce( $ajax_action );
 
 
 
 
72
 
73
  if ( ! is_wp_error( $result ) )
74
  $result = _wpsc_ajax_fire_callback( $ajax_action );
@@ -530,6 +538,10 @@ function _wpsc_ajax_save_product_order() {
530
  $failed[] = $product_id;
531
  }
532
 
 
 
 
 
533
  if ( ! empty( $failed ) ) {
534
  $error_data = array(
535
  'failed_ids' => $failed,
@@ -543,6 +555,39 @@ function _wpsc_ajax_save_product_order() {
543
  );
544
  }
545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
  /**
547
  * Update Checkout fields order
548
  *
@@ -752,6 +797,7 @@ function _wpsc_ajax_add_tax_rate() {
752
  */
753
  function wpsc_product_variations_table() {
754
  check_admin_referer( 'wpsc_product_variations_table' );
 
755
  require_once( WPSC_FILE_PATH . '/wpsc-admin/includes/product-variations-page.class.php' );
756
  $page = new WPSC_Product_Variations_Page();
757
  $page->display();
20
  elseif ( isset( $_REQUEST['_wpnonce'] ) )
21
  $nonce = $_REQUEST['_wpnonce'];
22
  else
23
+ return _wpsc_error_invalid_nonce();
24
 
25
  // validate nonce
26
  if ( ! wp_verify_nonce( $nonce, 'wpsc_ajax_' . $ajax_action ) )
27
+ return _wpsc_error_invalid_nonce();
28
 
29
  return true;
30
  }
31
 
32
+ function _wpsc_error_invalid_nonce() {
33
+ return new WP_Error( 'wpsc_ajax_invalid_nonce', __( 'Your session has expired. Please refresh the page and try again.', 'wpsc' ) );
34
+ }
35
+
36
  /**
37
  * Verify AJAX callback and call it if it exists.
38
  *
72
  */
73
  function _wpsc_ajax_handler() {
74
  $ajax_action = str_replace( '-', '_', $_REQUEST['wpsc_action'] );
75
+
76
+ if ( is_callable( '_wpsc_ajax_verify_' . $ajax_action ) )
77
+ $result = call_user_func( '_wpsc_ajax_verify_' . $ajax_action );
78
+ else
79
+ $result = _wpsc_ajax_verify_nonce( $ajax_action );
80
 
81
  if ( ! is_wp_error( $result ) )
82
  $result = _wpsc_ajax_fire_callback( $ajax_action );
538
  $failed[] = $product_id;
539
  }
540
 
541
+ // Validate data before exposing to action
542
+ $category = isset( $_POST['category_id'] ) ? get_term_by( 'slug', $_POST['category_id'], 'wpsc_product_category' ) : false;
543
+ do_action( 'wpsc_save_product_order', $products, $category );
544
+
545
  if ( ! empty( $failed ) ) {
546
  $error_data = array(
547
  'failed_ids' => $failed,
555
  );
556
  }
557
 
558
+ /**
559
+ * Save Category Product Order
560
+ *
561
+ * Note that this uses the 'term_order' field in the 'term_relationships' table to store
562
+ * the order. Although this column presently seems to be unused by WordPress, the intention
563
+ * is it should be used to store the order of terms associates to a post, not the order
564
+ * of posts as we are doing. This shouldn't be an issue for WPEC unless WordPress adds a UI
565
+ * for this. More info at http://core.trac.wordpress.org/ticket/9547
566
+ *
567
+ * @since 3.9
568
+ * @access private
569
+ *
570
+ * @uses $wpdb WordPress database object used for queries
571
+ */
572
+ function _wpsc_save_category_product_order( $products, $category ) {
573
+ global $wpdb;
574
+
575
+ // Only save category product order if in category
576
+ if ( ! $category )
577
+ return;
578
+
579
+ // Save product order in term_relationships table
580
+ foreach ( $products as $order => $product_id ) {
581
+ $wpdb->update( $wpdb->term_relationships,
582
+ array( 'term_order' => $order ),
583
+ array( 'object_id' => $product_id, 'term_taxonomy_id' => $category->term_taxonomy_id ),
584
+ array( '%d' ),
585
+ array( '%d', '%d' )
586
+ );
587
+ }
588
+ }
589
+ add_action( 'wpsc_save_product_order', '_wpsc_save_category_product_order', 10, 2 );
590
+
591
  /**
592
  * Update Checkout fields order
593
  *
797
  */
798
  function wpsc_product_variations_table() {
799
  check_admin_referer( 'wpsc_product_variations_table' );
800
+ set_current_screen( 'wpsc-product' );
801
  require_once( WPSC_FILE_PATH . '/wpsc-admin/includes/product-variations-page.class.php' );
802
  $page = new WPSC_Product_Variations_Page();
803
  $page->display();
wpsc-admin/css/admin.css CHANGED
@@ -2,9 +2,6 @@
2
  * This is the new WPSC Admin CSS file
3
 
4
  */
5
- table.wp-list-table .column-title {
6
- width: 26%;
7
- }
8
  table.wp-list-table .column-featured {
9
  width: 30px;
10
  }
@@ -1831,10 +1828,6 @@ table.purchase-logs tr:hover .column-id .delete {
1831
  border-bottom-style:dashed;
1832
  }
1833
 
1834
- .js #wpsc-product-variations-wrapper tbody td, .js #wpsc-product-variations-wrapper tbody th {
1835
- border-bottom-style:solid;
1836
- }
1837
-
1838
  #wpsc-product-variations-wrapper div.updated,
1839
  #wpsc-product-variations-wrapper div.error {
1840
  margin: 15px 0 2px;
@@ -1906,24 +1899,38 @@ table.purchase-logs tr:hover .column-id .delete {
1906
 
1907
  .wpsc-product-variations-tabs {
1908
  background: #F1F1F1;
1909
- border-bottom: 1px solid #ccc;
1910
- padding: 10px 10px 0;
1911
  margin: 0;
 
 
 
 
 
 
 
 
 
 
 
1912
  }
1913
 
1914
  .wpsc-product-variations-tabs li {
1915
- display: inline-block;
1916
- margin: 0 4px 2px 0;
1917
  }
1918
 
1919
  .wpsc-product-variations-tabs a {
1920
- background-color: #fff;
1921
- border-color: #ccc #ccc #fff;
 
1922
  border-style: solid;
1923
  border-width: 1px 1px 0;
 
1924
  color: #aaa;
1925
  padding: 5px 7px 3px;
1926
  text-decoration: none;
 
1927
 
1928
  border-top-left-radius: 3px;
1929
  border-top-right-radius: 3px;
@@ -1938,12 +1945,14 @@ table.purchase-logs tr:hover .column-id .delete {
1938
  }
1939
 
1940
  .wpsc-product-variations-tabs .active a {
 
1941
  border-bottom-width: 1px;
1942
  color: #333;
1943
- margin-bottom: 2px;
1944
  }
1945
 
1946
  .wpsc-product-variations-tab-content {
 
1947
  padding: 0 10px;
1948
  }
1949
 
2
  * This is the new WPSC Admin CSS file
3
 
4
  */
 
 
 
5
  table.wp-list-table .column-featured {
6
  width: 30px;
7
  }
1828
  border-bottom-style:dashed;
1829
  }
1830
 
 
 
 
 
1831
  #wpsc-product-variations-wrapper div.updated,
1832
  #wpsc-product-variations-wrapper div.error {
1833
  margin: 15px 0 2px;
1899
 
1900
  .wpsc-product-variations-tabs {
1901
  background: #F1F1F1;
1902
+ border-bottom: 1px solid #dfdfdf;
1903
+ padding: 5px 4px 0;
1904
  margin: 0;
1905
+ width: 100%;
1906
+ }
1907
+
1908
+ .wpsc-product-variations-tabs:before,
1909
+ .wpsc-product-variations-tabs:after {
1910
+ display: table;
1911
+ content: "";
1912
+ }
1913
+
1914
+ .wpsc-product-variations-tabs:after {
1915
+ clear: both;
1916
  }
1917
 
1918
  .wpsc-product-variations-tabs li {
1919
+ float: left;
1920
+ margin: 0 4px 0 0;
1921
  }
1922
 
1923
  .wpsc-product-variations-tabs a {
1924
+ display: block;
1925
+ background-color: #f1f1f1;
1926
+ border-color: #dfdfdf #dfdfdf #fff;
1927
  border-style: solid;
1928
  border-width: 1px 1px 0;
1929
+ line-height: 1em;
1930
  color: #aaa;
1931
  padding: 5px 7px 3px;
1932
  text-decoration: none;
1933
+ vertical-align: middle;
1934
 
1935
  border-top-left-radius: 3px;
1936
  border-top-right-radius: 3px;
1945
  }
1946
 
1947
  .wpsc-product-variations-tabs .active a {
1948
+ background: #fff;
1949
  border-bottom-width: 1px;
1950
  color: #333;
1951
+ margin-bottom: -1px;
1952
  }
1953
 
1954
  .wpsc-product-variations-tab-content {
1955
+ clear: both;
1956
  padding: 0 10px;
1957
  }
1958
 
wpsc-admin/css/media.css ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wpsc-featured-label {
2
+ position: absolute;
3
+ bottom: 0;
4
+ left: 0;
5
+ right: 0;
6
+ background: #f1f1f1;
7
+ background-image: -webkit-gradient(linear, left top, left bottom, from(#f1f1f1), to(#e1e1e1));
8
+ background-image: -webkit-linear-gradient(top, #f1f1f1, #e1e1e1);
9
+ background-image: -moz-linear-gradient(top, #f1f1f1, #e1e1e1);
10
+ background-image: -o-linear-gradient(top, #f1f1f1, #e1e1e1);
11
+ background-image: linear-gradient(to bottom, #f1f1f1, #e1e1e1);
12
+ box-shadow: 0 0 0 1px rgba( 0, 0, 0, 0.15 );
13
+ font-weight: bold;
14
+ text-align: center;
15
+ color: rgb(70, 70, 70);
16
+ max-height: 100%;
17
+ padding: 5px 10px;
18
+ outline: 0 none;
19
+ opacity: 0.95;
20
+ line-height: 1em;
21
+ }
22
+
23
+ .selection-view .wpsc-featured-label {
24
+ font-size:7px;
25
+ padding: 2px 0;
26
+ }
wpsc-admin/db-upgrades/routines/4.php CHANGED
@@ -19,7 +19,8 @@ function _wpsc_maybe_update_user_log_file() {
19
  '3.8.10' => '09e2cb9c753587c9228a4e9e8008a82f',
20
  );
21
 
22
- wpsc_flush_theme_transients( true );
 
23
 
24
  //Make sure the theme has actually been moved.
25
  $file = wpsc_get_template_file_path( 'wpsc-user-log.php' );
19
  '3.8.10' => '09e2cb9c753587c9228a4e9e8008a82f',
20
  );
21
 
22
+ if ( function_exists( 'wpsc_flush_theme_transients' ) )
23
+ wpsc_flush_theme_transients( true );
24
 
25
  //Make sure the theme has actually been moved.
26
  $file = wpsc_get_template_file_path( 'wpsc-user-log.php' );
wpsc-admin/db-upgrades/routines/5.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function _wpsc_db_upgrade_5() {
4
+ _wpsc_maybe_update_product_meta_array_keys();
5
+ }
6
+
7
+ /**
8
+ * Rename old _wpsc_* product metadata array keys so they no longer include the '_wpsc_' prefix
9
+ * See https://github.com/wp-e-commerce/WP-e-Commerce/issues/492 for details
10
+ */
11
+ function _wpsc_maybe_update_product_meta_array_keys() {
12
+ global $wpdb;
13
+
14
+ $product_ids = $wpdb->get_col( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_wpsc_product_metadata' AND meta_value LIKE '%_wpsc_%'" );
15
+
16
+ foreach ( $product_ids as $product_id ) {
17
+ $metadata_needs_saving = false;
18
+ $product_metadata = get_post_meta( $product_id, '_wpsc_product_metadata', true );
19
+ if ( is_array( $product_metadata ) ) {
20
+ foreach ( $product_metadata as $meta_key => $meta_value ) {
21
+ if ( '_wpsc_' === substr( $meta_key, 0, 6 ) ) {
22
+ /*
23
+ Typical meta keys that need renaming are:
24
+ wpsc_url_name
25
+ _wpsc_sku
26
+ _wpsc_dimensions
27
+ _wpsc_engraved
28
+ _wpsc_can_have_uploaded_image
29
+ _wpsc_unpublish_oos
30
+ */
31
+ $new_meta_key = substr( $meta_key, 6 );
32
+
33
+ // remove the old (_wpsc_ prefixed) metadata from the array
34
+ unset ( $product_metadata[ $meta_key ] );
35
+ $metadata_needs_saving = true;
36
+
37
+ // If metadata doesn't already exist with the new non-prefixed key, add it to the array
38
+ // This check ensures that we don't overwrite newer product metadata
39
+ if ( ! isset( $product_metadata[ $new_meta_key ] ) ) {
40
+ $product_metadata[ $new_meta_key ] = $meta_value;
41
+ }
42
+ }
43
+ }
44
+ }
45
+ if ( $metadata_needs_saving ) {
46
+ update_post_meta( $product_id, '_wpsc_product_metadata', $product_metadata );
47
+ }
48
+ }
49
+ }
wpsc-admin/db-upgrades/routines/6.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function _wpsc_db_upgrade_6() {
4
+ _wpsc_maybe_create_meta_tables();
5
+ }
6
+
7
+ function _wpsc_maybe_create_meta_tables() {
8
+
9
+ _wpsc_create_cart_item_meta_table();
10
+ _wpsc_meta_migrate_wpsc_cart_item();
11
+ }
wpsc-admin/db-upgrades/routines/7.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function _wpsc_db_upgrade_7() {
4
+ _wpsc_migrate_user_meta();
5
+ }
6
+
7
+ function _wpsc_migrate_user_meta() {
8
+ global $wpdb;
9
+
10
+ $sql = "
11
+ SELECT *
12
+ FROM {$wpdb->usermeta}
13
+ WHERE
14
+ meta_key LIKE '_wpsc_%customer_profile';
15
+ ";
16
+
17
+ $results = $wpdb->get_results( $sql );
18
+
19
+ foreach ( $results as $row ) {
20
+ preg_match( '/_wpsc_(.*)customer_profile/', $row->meta_key, $matches );
21
+ $blog_prefix = $matches[1];
22
+
23
+ $profile = maybe_unserialize( $row->meta_value );
24
+
25
+ foreach ( $profile as $key => $value ) {
26
+ $internal_key = "{$blog_prefix}_wpsc_{$key}";
27
+ $current_value = get_user_meta( $row->user_id, $internal_key, true );
28
+
29
+ if ( $current_value === '' && $value ) {
30
+ update_user_meta( $row->user_id, $internal_key, $value );
31
+ }
32
+ }
33
+
34
+ delete_user_meta( $row->user_id, $row->meta_key );
35
+ }
36
+ }
wpsc-admin/db-upgrades/upgrade.php CHANGED
@@ -14,7 +14,7 @@
14
  * @since 3.8.9
15
  */
16
  function _wpsc_maybe_upgrade() {
17
- $current_db_ver = get_option( 'wpsc_db_version', 0 );
18
 
19
  if ( ! _wpsc_needs_upgrade() )
20
  return;
14
  * @since 3.8.9
15
  */
16
  function _wpsc_maybe_upgrade() {
17
+ $current_db_ver = (int) get_option( 'wpsc_db_version', 0 );
18
 
19
  if ( ! _wpsc_needs_upgrade() )
20
  return;
wpsc-admin/display-coupon-add.php CHANGED
@@ -20,7 +20,7 @@
20
  <label for="add-coupon-code"><?php _e( 'Discount', 'wpsc' ); ?></label>
21
  </th>
22
  <td>
23
- <input name="add_discount" id="add-coupon-code" type="number" class="small-text"/>
24
  <span class="description"><?php _e( 'The discount amount', 'wpsc' ); ?></span>
25
  </td>
26
  </tr>
@@ -108,6 +108,7 @@
108
  <option value="begins"><?php _e( 'Begins with', 'wpsc' ); ?></option>
109
  <option value="ends"><?php _e( 'Ends with', 'wpsc' ); ?></option>
110
  <option value="category"><?php _e( 'In Category', 'wpsc' ); ?></option>
 
111
  </select>
112
 
113
  <input type="text" name="rules[value][]" style="width: 150px;"/>
20
  <label for="add-coupon-code"><?php _e( 'Discount', 'wpsc' ); ?></label>
21
  </th>
22
  <td>
23
+ <input name="add_discount" id="add-coupon-code" type="number" class="small-text" min="0" />
24
  <span class="description"><?php _e( 'The discount amount', 'wpsc' ); ?></span>
25
  </td>
26
  </tr>
108
  <option value="begins"><?php _e( 'Begins with', 'wpsc' ); ?></option>
109
  <option value="ends"><?php _e( 'Ends with', 'wpsc' ); ?></option>
110
  <option value="category"><?php _e( 'In Category', 'wpsc' ); ?></option>
111
+ <?php echo apply_filters( 'wpsc_coupon_rule_logic_options', '' ); ?>
112
  </select>
113
 
114
  <input type="text" name="rules[value][]" style="width: 150px;"/>
wpsc-admin/display-coupon-edit.php CHANGED
@@ -37,7 +37,7 @@ $coupon = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_COUP
37
  <label for="edit_coupon_amount"><?php _e( 'Discount', 'wpsc' ); ?></label>
38
  </th>
39
  <td>
40
- <input name="edit_coupon_amount" id="edit_coupon_amount" type="number" value="<?php esc_attr_e( $coupon['value'] ); ?>" class="small-text"/>
41
  <span class="description"><?php _e( 'The discount amount', 'wpsc' ); ?></span>
42
  </td>
43
  </tr>
37
  <label for="edit_coupon_amount"><?php _e( 'Discount', 'wpsc' ); ?></label>
38
  </th>
39
  <td>
40
+ <input name="edit_coupon_amount" id="edit_coupon_amount" type="number" value="<?php esc_attr_e( $coupon['value'] ); ?>" class="small-text" min="0" />
41
  <span class="description"><?php _e( 'The discount amount', 'wpsc' ); ?></span>
42
  </td>
43
  </tr>
wpsc-admin/display-items.page.php CHANGED
@@ -85,11 +85,12 @@ add_action( 'wpsc_manage_products_column_image', '_wpsc_manage_products_column_i
85
  * @param int $post_id Post ID
86
  * @param boolean $has_variations Whether the product has variations
87
  *
88
- * @uses esc_html_e() Safe HTML with translation
89
- * @uses get_post_meta() Gets post meta given key and post_id
90
- * @uses maybe_unserialize() Unserialize value only if it was serialized.
91
- * @uses wpsc_convert_weight() Does weight conversions
92
- * @uses esc_html() Makes sure things are safe
 
93
  */
94
  function _wpsc_manage_products_column_weight( $post, $post_id, $has_variations ) {
95
  if( $has_variations ) {
@@ -117,22 +118,7 @@ function _wpsc_manage_products_column_weight( $post, $post_id, $has_variations )
117
 
118
  $unit = $product_data['meta']['_wpsc_product_metadata']['weight_unit'];
119
 
120
- switch( $unit ) {
121
- case "pound":
122
- $unit = __(" lbs.", "wpsc");
123
- break;
124
- case "ounce":
125
- $unit = __(" oz.", "wpsc");
126
- break;
127
- case "gram":
128
- $unit = __(" g", "wpsc");
129
- break;
130
- case "kilograms":
131
- case "kilogram":
132
- $unit = __(" kgs.", "wpsc");
133
- break;
134
- }
135
- echo $weight.$unit;
136
  echo '<div id="inline_' . $post->ID . '_weight" class="hidden">' . esc_html( $weight ) . '</div>';
137
  }
138
  add_action( 'wpsc_manage_products_column_weight', '_wpsc_manage_products_column_weight', 10, 3 );
@@ -572,7 +558,7 @@ function wpsc_update_featured_products() {
572
  exit;
573
  }
574
 
575
- add_filter( 'page_row_actions','my_action_row', 10, 2 );
576
 
577
  /**
578
  * @param $actions
@@ -584,7 +570,7 @@ add_filter( 'page_row_actions','my_action_row', 10, 2 );
584
  * @uses esc_url() Makes sure the URL is safe, we like safe
585
  * @uses esc_html_x() Displays translated string with gettext context
586
  */
587
- function my_action_row( $actions, $post ) {
588
 
589
  if ( $post->post_type != "wpsc-product" )
590
  return $actions;
85
  * @param int $post_id Post ID
86
  * @param boolean $has_variations Whether the product has variations
87
  *
88
+ * @uses esc_html_e() Safe HTML with translation
89
+ * @uses get_post_meta() Gets post meta given key and post_id
90
+ * @uses maybe_unserialize() Unserialize value only if it was serialized.
91
+ * @uses wpsc_convert_weight() Does weight conversions
92
+ * @uses esc_html() Makes sure things are safe
93
+ * @uses wpsc_weight_unit_display() Gets weight unit for display
94
  */
95
  function _wpsc_manage_products_column_weight( $post, $post_id, $has_variations ) {
96
  if( $has_variations ) {
118
 
119
  $unit = $product_data['meta']['_wpsc_product_metadata']['weight_unit'];
120
 
121
+ echo $weight . wpsc_weight_unit_display( $unit );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  echo '<div id="inline_' . $post->ID . '_weight" class="hidden">' . esc_html( $weight ) . '</div>';
123
  }
124
  add_action( 'wpsc_manage_products_column_weight', '_wpsc_manage_products_column_weight', 10, 3 );
558
  exit;
559
  }
560
 
561
+ add_filter( 'page_row_actions','wpsc_action_row', 10, 2 );
562
 
563
  /**
564
  * @param $actions
570
  * @uses esc_url() Makes sure the URL is safe, we like safe
571
  * @uses esc_html_x() Displays translated string with gettext context
572
  */
573
+ function wpsc_action_row( $actions, $post ) {
574
 
575
  if ( $post->post_type != "wpsc-product" )
576
  return $actions;
wpsc-admin/includes/display-items-functions.php CHANGED
@@ -416,6 +416,110 @@ function wpsc_product_shipping_forms_metabox() {
416
  wpsc_product_shipping_forms();
417
  }
418
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419
  function wpsc_product_shipping_forms( $product = false, $field_name_prefix = 'meta[_wpsc_product_metadata]', $bulk = false ) {
420
  if ( ! $product )
421
  $product_id = get_the_ID();
@@ -428,16 +532,16 @@ function wpsc_product_shipping_forms( $product = false, $field_name_prefix = 'me
428
 
429
  $defaults = array(
430
  'weight' => '',
431
- 'weight_unit' => '',
432
  'dimensions' => array(),
433
  'shipping' => array(),
434
  'no_shipping' => '',
435
  'display_weight_as' => '',
436
  );
437
  $dimensions_defaults = array(
438
- 'height_unit' => '',
439
- 'width_unit' => '',
440
- 'length_unit' => '',
441
  'height' => 0,
442
  'width' => 0,
443
  'length' => 0,
@@ -458,18 +562,8 @@ function wpsc_product_shipping_forms( $product = false, $field_name_prefix = 'me
458
 
459
  $weight = wpsc_convert_weight( $weight, 'pound', $weight_unit );
460
 
461
- $dimension_units = array(
462
- 'in' => __( 'inches', 'wpsc' ),
463
- 'cm' => __( 'cm', 'wpsc' ),
464
- 'meter' => __( 'meters', 'wpsc' )
465
- );
466
-
467
- $weight_units = array(
468
- 'pound' => __( 'pounds', 'wpsc' ),
469
- 'ounce' => __( 'ounces', 'wpsc' ),
470
- 'gram' => __( 'grams', 'wpsc' ),
471
- 'kilogram' => __( 'kilograms', 'wpsc' )
472
- );
473
 
474
  $measurements = $dimensions;
475
  $measurements['weight'] = $weight;
@@ -718,23 +812,20 @@ function wpsc_product_external_link_forms() {
718
  </table>
719
  <?php
720
  }
721
- function wpsc_product_image_forms() {
722
-
723
- global $post;
724
-
725
- edit_multiple_image_gallery( $post );
726
-
727
- ?>
728
-
729
- <p><strong <?php if ( isset( $display ) ) echo $display; ?>><a href="media-upload.php?parent_page=wpsc-edit-products&amp;post_id=<?php echo $post->ID; ?>&amp;type=image&amp;tab=gallery&amp;TB_iframe=1&amp;width=640&amp;height=566" class="thickbox" title="<?php esc_attr_e( 'Manage Product Images', 'wpsc' ); ?>"><?php esc_html_e( 'Manage Product Images', 'wpsc' ); ?></a></strong></p>
730
- <?php
731
- }
732
  function wpsc_additional_desc() {
733
  ?>
734
  <textarea name='additional_description' id='additional_description' cols='40' rows='5' ><?php echo esc_textarea( get_post_field( 'post_excerpt', get_the_ID() ) ); ?></textarea>
735
  <?php
736
 
737
  }
 
 
 
 
 
 
 
 
738
  function wpsc_product_download_forms() {
739
  global $post, $wpdb, $wpsc_product_defaults;
740
  $product_data = get_post_custom( $post->ID );
@@ -815,12 +906,6 @@ if ( version_compare( get_bloginfo( 'version' ), '3.5', '<' ) ) {
815
  * Modifications to Media Gallery
816
  */
817
 
818
- if ( ( isset( $_REQUEST['parent_page'] ) && ( $_REQUEST['parent_page'] == 'wpsc-edit-products' ) ) ) {
819
- add_filter( 'media_upload_tabs', 'wpsc_media_upload_tab_gallery', 12 );
820
- add_filter( 'media_upload_form_url', 'wpsc_media_upload_url', 9, 1 );
821
- add_action( 'admin_head', 'wpsc_gallery_css_mods' );
822
- }
823
- add_filter( 'gettext', 'wpsc_filter_delete_text', 12 , 3 );
824
  add_filter( 'attachment_fields_to_edit', 'wpsc_attachment_fields', 11, 2 );
825
  add_filter( 'attachment_fields_to_save', 'wpsc_save_attachment_fields', 9, 2 );
826
  add_filter( 'gettext_with_context', 'wpsc_filter_gettex_with_context', 12, 4);
@@ -837,7 +922,7 @@ add_filter( 'gettext_with_context', 'wpsc_filter_gettex_with_context', 12, 4);
837
  function wpsc_filter_gettex_with_context( $translation, $text, $context, $domain ) {
838
 
839
  if ( 'Taxonomy Parent' == $context && 'Parent' == $text && isset($_GET['taxonomy']) && 'wpsc-variation' == $_GET['taxonomy'] ) {
840
- $translations = &get_translations_for_domain( $domain );
841
  return $translations->translate( 'Variation Set', 'wpsc' );
842
  //this will never happen, this is here only for gettext to pick up the translation
843
  return __( 'Variation Set', 'wpsc' );
@@ -845,29 +930,6 @@ function wpsc_filter_gettex_with_context( $translation, $text, $context, $domain
845
  return $translation;
846
  }
847
 
848
- /*
849
- * This filter translates string before it is displayed
850
- * specifically for the words 'Use as featured image' with 'Use as Product Thumbnail' when the user is selecting a Product Thumbnail
851
- * using media gallery.
852
- *
853
- * @todo As this feature is entirely cosmetic and breaks with WP_DEBUG on in WP 3.5+, we've removed the filter for it. Will revisit the functionality in 3.9 when we look at new media workflows.
854
- * @param $translation The current translation
855
- * @param $text The text being translated
856
- * @param $domain The domain for the translation
857
- * @return string The translated / filtered text.
858
- */
859
- function wpsc_filter_feature_image_text( $translation, $text, $domain ) {
860
- if ( 'Use as featured image' == $text && isset( $_REQUEST['post_id'] ) ) {
861
- $post = get_post( $_REQUEST['post_id'] );
862
- if ( $post->post_type != 'wpsc-product' ) return $translation;
863
- $translations = &get_translations_for_domain( $domain );
864
- return $translations->translate( 'Use as Product Thumbnail', 'wpsc' );
865
- //this will never happen, this is here only for gettexr to pick up the translation
866
- return __( 'Use as Product Thumbnail', 'wpsc' );
867
- }
868
-
869
- return $translation;
870
- }
871
  function wpsc_attachment_fields( $form_fields, $post ) {
872
  $out = '';
873
 
@@ -981,95 +1043,6 @@ function wpsc_save_attachment_fields( $post, $attachment ) {
981
 
982
  return $post;
983
  }
984
- function wpsc_media_upload_url( $form_action_url ) {
985
-
986
- $form_action_url = esc_url( add_query_arg( array( 'parent_page'=>'wpsc-edit-products' ) ) );
987
-
988
- return $form_action_url;
989
-
990
- }
991
- function wpsc_gallery_css_mods() {
992
-
993
- print '<style type="text/css">
994
- #gallery-settings *{
995
- display:none;
996
- }
997
- a.wp-post-thumbnail {
998
- color:green;
999
- }
1000
- #media-upload a.del-link {
1001
- color:red;
1002
- }
1003
- #media-upload a.wp-post-thumbnail {
1004
- margin-left:0px;
1005
- }
1006
- td.savesend input.button {
1007
- display:none;
1008
- }
1009
- </style>';
1010
- print '
1011
- <script type="text/javascript">
1012
- jQuery(function(){
1013
- jQuery("td.A1B1").each(function(){
1014
-
1015
- var target = jQuery(this).next();
1016
- jQuery("p > input.button", this).appendTo(target);
1017
-
1018
- });
1019
-
1020
- jQuery("a.wp-post-thumbnail").each(function(){
1021
- var product_image = jQuery(this).text();
1022
- if (product_image == "' . __( 'Use as featured image' ) . '") {
1023
- jQuery(this).text("' . __( 'Use as Product Thumbnail', 'wpsc' ) . '");
1024
- }
1025
- });
1026
- });
1027
-
1028
- </script>';
1029
- }
1030
- function wpsc_media_upload_tab_gallery( $tabs ) {
1031
-
1032
- unset( $tabs['gallery'] );
1033
- $tabs['gallery'] = __( 'Product Image Gallery', 'wpsc' );
1034
-
1035
- return $tabs;
1036
- }
1037
- function wpsc_filter_delete_text( $translation, $text, $domain ) {
1038
-
1039
- if ( 'Delete' == $text && isset( $_REQUEST['post_id'] ) && isset( $_REQUEST['parent_page'] ) ) {
1040
- $translations = &get_translations_for_domain( $domain );
1041
- return $translations->translate( 'Trash' ) ;
1042
- }
1043
- return $translation;
1044
- }
1045
- function edit_multiple_image_gallery( $post ) {
1046
- global $wpdb;
1047
-
1048
- // Make sure thumbnail isn't duplicated
1049
- if ( $post->ID > 0 ) {
1050
- if ( has_post_thumbnail( $post->ID ) )
1051
- echo get_the_post_thumbnail( $post->ID, 'admin-product-thumbnails' );
1052
-
1053
- $args = array(
1054
- 'post_type' => 'attachment',
1055
- 'numberposts' => -1,
1056
- 'post_status' => null,
1057
- 'post_parent' => $post->ID,
1058
- 'orderby' => 'menu_order',
1059
- 'order' => 'ASC'
1060
- );
1061
-
1062
- $attached_images = (array)get_posts( $args );
1063
-
1064
- if ( count( $attached_images ) > 0 ) {
1065
- foreach ( $attached_images as $images ) {
1066
- $attached_image = wp_get_attachment_image( $images->ID, 'admin-product-thumbnails' );
1067
- echo $attached_image. '&nbsp;';
1068
- }
1069
- }
1070
-
1071
- }
1072
- }
1073
 
1074
  /**
1075
  * wpsc_save_quickedit_box function
416
  wpsc_product_shipping_forms();
417
  }
418
 
419
+ /**
420
+ * Dimension Units
421
+ *
422
+ * @since 3.8.13
423
+ *
424
+ * @return array List of valid dimension units.
425
+ */
426
+ function wpsc_dimension_units() {
427
+ return array(
428
+ 'in' => __( 'inches', 'wpsc' ),
429
+ 'cm' => __( 'cm', 'wpsc' ),
430
+ 'meter' => __( 'meters', 'wpsc' )
431
+ );
432
+ }
433
+
434
+ /**
435
+ * Weight Units
436
+ *
437
+ * @since 3.8.13
438
+ *
439
+ * @return array List of valid weight units.
440
+ */
441
+ function wpsc_weight_units() {
442
+ return array(
443
+ 'pound' => __( 'pounds', 'wpsc' ),
444
+ 'ounce' => __( 'ounces', 'wpsc' ),
445
+ 'gram' => __( 'grams', 'wpsc' ),
446
+ 'kilogram' => __( 'kilograms', 'wpsc' )
447
+ );
448
+ }
449
+
450
+ /**
451
+ * Weight Unit Display
452
+ *
453
+ * Returns a weight unit abbreviation for display.
454
+ *
455
+ * @since 3.8.13
456
+ *
457
+ * @param string $unit Weight unit.
458
+ * @return string Weight unit string.
459
+ */
460
+ function wpsc_weight_unit_display( $unit ) {
461
+ switch ( $unit ) {
462
+ case 'pound' :
463
+ return __( ' lbs.', 'wpsc' );
464
+ case 'ounce' :
465
+ return __( ' oz.', 'wpsc' );
466
+ case 'gram' :
467
+ return __( ' g', 'wpsc' );
468
+ case 'kilograms' :
469
+ case 'kilogram' :
470
+ return __( ' kgs.', 'wpsc' );
471
+ }
472
+ return '';
473
+ }
474
+
475
+ /**
476
+ * Validate Dimension Unit
477
+ *
478
+ * Returns a valid dimensions unit.
479
+ * If the unit is not set or invalid it will be filtered using 'wpsc_default_dimension_unit'
480
+ * so that an alternative default unit can be set.
481
+ *
482
+ * @since 3.8.13
483
+ *
484
+ * @param string $unit Dimension unit.
485
+ * @return string Dimension unit string.
486
+ *
487
+ * @uses wpsc_default_dimension_unit
488
+ */
489
+ function wpsc_validate_dimension_unit( $unit = '' ) {
490
+ $default_unit = apply_filters( 'wpsc_default_dimension_unit', $unit );
491
+ if ( empty( $unit ) && array_key_exists( $default_unit, wpsc_dimension_units() ) )
492
+ $unit = $default_unit;
493
+ return $unit;
494
+ }
495
+
496
+ /**
497
+ * Validate Weight Unit
498
+ *
499
+ * Returns a valid weight unit.
500
+ * If the unit is not set or invalid it will be filtered using 'wpsc_default_weight_unit'
501
+ * so that an alternative default unit can be set.
502
+ *
503
+ * @since 3.8.13
504
+ *
505
+ * @param string $unit Weight unit.
506
+ * @return string Weight unit string.
507
+ *
508
+ * @uses wpsc_default_weight_unit
509
+ */
510
+ function wpsc_validate_weight_unit( $unit = '' ) {
511
+ $default_unit = apply_filters( 'wpsc_default_weight_unit', $unit );
512
+ if ( empty( $unit ) && array_key_exists( $default_unit, wpsc_weight_units() ) )
513
+ $unit = $default_unit;
514
+ return $unit;
515
+ }
516
+
517
+ /**
518
+ * Product Shipping Forms
519
+ *
520
+ * @uses wpsc_validate_weight_unit()
521
+ * @uses wpsc_validate_dimension_unit()
522
+ */
523
  function wpsc_product_shipping_forms( $product = false, $field_name_prefix = 'meta[_wpsc_product_metadata]', $bulk = false ) {
524
  if ( ! $product )
525
  $product_id = get_the_ID();
532
 
533
  $defaults = array(
534
  'weight' => '',
535
+ 'weight_unit' => wpsc_validate_weight_unit(),
536
  'dimensions' => array(),
537
  'shipping' => array(),
538
  'no_shipping' => '',
539
  'display_weight_as' => '',
540
  );
541
  $dimensions_defaults = array(
542
+ 'height_unit' => wpsc_validate_dimension_unit(),
543
+ 'width_unit' => wpsc_validate_dimension_unit(),
544
+ 'length_unit' => wpsc_validate_dimension_unit(),
545
  'height' => 0,
546
  'width' => 0,
547
  'length' => 0,
562
 
563
  $weight = wpsc_convert_weight( $weight, 'pound', $weight_unit );
564
 
565
+ $dimension_units = wpsc_dimension_units();
566
+ $weight_units = wpsc_weight_units();
 
 
 
 
 
 
 
 
 
 
567
 
568
  $measurements = $dimensions;
569
  $measurements['weight'] = $weight;
812
  </table>
813
  <?php
814
  }
 
 
 
 
 
 
 
 
 
 
 
815
  function wpsc_additional_desc() {
816
  ?>
817
  <textarea name='additional_description' id='additional_description' cols='40' rows='5' ><?php echo esc_textarea( get_post_field( 'post_excerpt', get_the_ID() ) ); ?></textarea>
818
  <?php
819
 
820
  }
821
+
822
+ function wpsc_product_gallery( $post ) {
823
+ $upload_iframe_src = esc_url( get_upload_iframe_src( 'image', $post->ID ) );
824
+ ?>
825
+ <p class="hide-if-no-js"><a title="<? esc_attr_e( 'Add product gallery images', 'wpsc' ); ?>" href="<?php echo $upload_iframe_src; ?>" id="wpsc-manage-product-gallery" class="thickbox"><?php esc_html_e( 'Add product gallery images', 'wpsc' ); ?></a></p>
826
+ <?php
827
+ }
828
+
829
  function wpsc_product_download_forms() {
830
  global $post, $wpdb, $wpsc_product_defaults;
831
  $product_data = get_post_custom( $post->ID );
906
  * Modifications to Media Gallery
907
  */
908
 
 
 
 
 
 
 
909
  add_filter( 'attachment_fields_to_edit', 'wpsc_attachment_fields', 11, 2 );
910
  add_filter( 'attachment_fields_to_save', 'wpsc_save_attachment_fields', 9, 2 );
911
  add_filter( 'gettext_with_context', 'wpsc_filter_gettex_with_context', 12, 4);
922
  function wpsc_filter_gettex_with_context( $translation, $text, $context, $domain ) {
923
 
924
  if ( 'Taxonomy Parent' == $context && 'Parent' == $text && isset($_GET['taxonomy']) && 'wpsc-variation' == $_GET['taxonomy'] ) {
925
+ $translations = get_translations_for_domain( $domain );
926
  return $translations->translate( 'Variation Set', 'wpsc' );
927
  //this will never happen, this is here only for gettext to pick up the translation
928
  return __( 'Variation Set', 'wpsc' );
930
  return $translation;
931
  }
932
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
933
  function wpsc_attachment_fields( $form_fields, $post ) {
934
  $out = '';
935
 
1043
 
1044
  return $post;
1045
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1046
 
1047
  /**
1048
  * wpsc_save_quickedit_box function
wpsc-admin/includes/product-variation-list-table.class.php CHANGED
@@ -206,14 +206,28 @@ class WPSC_Product_Variation_List_Table extends WP_List_Table {
206
 
207
  public function column_title( $item ) {
208
  $title = implode( ', ', $this->object_terms_cache[$item->ID] );
209
- $thumbnail = wpsc_the_product_thumbnail( 50, 50, $item->ID, '' );
210
  $show_edit_link = apply_filters( 'wpsc_show_product_variations_edit_action', true, $item );
211
 
 
 
 
 
212
  if ( ! $thumbnail )
213
  $thumbnail = WPSC_CORE_IMAGES_URL . '/no-image-uploaded.gif';
214
  ?>
215
  <div class="wpsc-product-variation-thumbnail">
216
- <a data-title="<?php echo esc_attr( $title ); ?>" href="<?php echo esc_url( admin_url( 'media-upload.php?post_id=' . $item->ID . '&TB_iframe=1&width=640&height=566&product_variation=1' ) ) ?>">
 
 
 
 
 
 
 
 
 
 
217
  <img id="wpsc-variation-thumbnail-<?php echo $item->ID; ?>" src="<?php echo esc_url( $thumbnail ); ?>" alt="" />
218
  </a>
219
  </div>
206
 
207
  public function column_title( $item ) {
208
  $title = implode( ', ', $this->object_terms_cache[$item->ID] );
209
+ $thumbnail = wpsc_the_product_thumbnail( false, false, $item->ID, 'manage-products' );
210
  $show_edit_link = apply_filters( 'wpsc_show_product_variations_edit_action', true, $item );
211
 
212
+ $nonce = wp_create_nonce( "wpsc_ajax_get_variation_gallery_{$item->ID}" );
213
+ $save_gallery_nonce = wp_create_nonce( "wpsc_ajax_update_gallery_{$item->ID}" );
214
+ $get_gallery_nonce = wp_create_nonce( "wpsc_ajax_get_gallery_{$item->ID}" );
215
+
216
  if ( ! $thumbnail )
217
  $thumbnail = WPSC_CORE_IMAGES_URL . '/no-image-uploaded.gif';
218
  ?>
219
  <div class="wpsc-product-variation-thumbnail">
220
+ <a
221
+ target="_blank"
222
+ data-featured-nonce="<?php echo esc_attr( wp_create_nonce( "update-post_{$item->ID}" ) ); ?>"
223
+ data-nonce="<?php echo esc_attr( $nonce ); ?>"
224
+ data-save-gallery-nonce="<?php echo esc_attr( $save_gallery_nonce ); ?>"
225
+ data-get-gallery-nonce="<?php echo esc_attr( $get_gallery_nonce ); ?>"
226
+ data-image-id="<?php echo get_post_thumbnail_id( $item->ID ); ?>"
227
+ data-id="<?php echo $item->ID; ?>"
228
+ data-title="<?php echo esc_attr( $title ); ?>"
229
+ href="<?php echo esc_url( admin_url( 'media-upload.php?post_id=' . $item->ID . '&width=640&height=566&product_variation=1' ) ) ?>"
230
+ >
231
  <img id="wpsc-variation-thumbnail-<?php echo $item->ID; ?>" src="<?php echo esc_url( $thumbnail ); ?>" alt="" />
232
  </a>
233
  </div>
wpsc-admin/includes/product-variations-page.class.php CHANGED
@@ -99,6 +99,8 @@ class WPSC_Product_Variations_Page {
99
  wp_enqueue_script( 'jquery-color' );
100
  wp_enqueue_script( 'utils' );
101
  wp_enqueue_script( 'jquery-query' );
 
 
102
 
103
  $callback = "callback_tab_{$this->current_tab}";
104
  if ( ! is_callable( array( $this, "callback_tab_{$this->current_tab}" ) ) )
99
  wp_enqueue_script( 'jquery-color' );
100
  wp_enqueue_script( 'utils' );
101
  wp_enqueue_script( 'jquery-query' );
102
+ wp_enqueue_media( array( 'post' => absint( $_REQUEST['product_id'] ) ) );
103
+
104
 
105
  $callback = "callback_tab_{$this->current_tab}";
106
  if ( ! is_callable( array( $this, "callback_tab_{$this->current_tab}" ) ) )
wpsc-admin/includes/purchase-log-list-table-class.php CHANGED
@@ -73,7 +73,7 @@ class WPSC_Purchase_Log_List_Table extends WP_List_Table {
73
  $selects = array( 'p.id', 'p.totalprice AS amount', 'p.processed AS status', 'p.track_id', 'p.date' );
74
  $selects[] = '
75
  (
76
- SELECT COUNT(*) FROM ' . WPSC_TABLE_CART_CONTENTS . ' AS c
77
  WHERE c.purchaseid = p.id
78
  ) AS item_count';
79
 
73
  $selects = array( 'p.id', 'p.totalprice AS amount', 'p.processed AS status', 'p.track_id', 'p.date' );
74
  $selects[] = '
75
  (
76
+ SELECT SUM(quantity) FROM ' . WPSC_TABLE_CART_CONTENTS . ' AS c
77
  WHERE c.purchaseid = p.id
78
  ) AS item_count';
79
 
wpsc-admin/includes/purchase-logs-page/packing-slip.php CHANGED
@@ -104,6 +104,7 @@
104
  <th><?php echo esc_html_x( 'Order ID', 'packing slip', 'wpsc' ); ?></th>
105
  <th><?php echo esc_html_x( 'Shipping Method', 'packing slip', 'wpsc' ); ?></th>
106
  <th><?php echo esc_html_x( 'Payment Method', 'packing slip', 'wpsc' ); ?></th>
 
107
  </tr>
108
  </thead>
109
  <tbody>
@@ -112,6 +113,7 @@
112
  <td><?php echo wpsc_purchaselog_details_purchnumber(); ?></td>
113
  <td><?php echo wpsc_display_purchlog_shipping_method(); ?></td>
114
  <td><?php echo wpsc_display_purchlog_paymentmethod(); ?></td>
 
115
  </tr>
116
  </tbody>
117
  </table>
104
  <th><?php echo esc_html_x( 'Order ID', 'packing slip', 'wpsc' ); ?></th>
105
  <th><?php echo esc_html_x( 'Shipping Method', 'packing slip', 'wpsc' ); ?></th>
106
  <th><?php echo esc_html_x( 'Payment Method', 'packing slip', 'wpsc' ); ?></th>
107
+ <?php wpsc_purchaselog_order_summary_headers(); ?>
108
  </tr>
109
  </thead>
110
  <tbody>
113
  <td><?php echo wpsc_purchaselog_details_purchnumber(); ?></td>
114
  <td><?php echo wpsc_display_purchlog_shipping_method(); ?></td>
115
  <td><?php echo wpsc_display_purchlog_paymentmethod(); ?></td>
116
+ <?php wpsc_purchaselog_order_summary(); ?>
117
  </tr>
118
  </tbody>
119
  </table>
wpsc-admin/includes/save-data.functions.php CHANGED
@@ -187,8 +187,8 @@ function wpsc_admin_category_forms_add() {
187
  ?>
188
  <h4><?php esc_html_e( 'Restrict to Target Markets', 'wpsc' )?></h4>
189
  <div class='form-field'>
190
- <?php if( @extension_loaded( 'suhosin' ) ) : ?>
191
- <em><?php esc_html__( "The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature then disable the suhosin extension, if you can not do this, you will need to contact your hosting provider.", 'wpsc' ); ?></em>
192
  <?php else: ?>
193
  <div class='multiple-select-container'>
194
  <span><?php esc_html_e( 'Select', 'wpsc' ); ?> <a href='' class='wpsc_select_all'><?php esc_html_e( 'All', 'wpsc' ); ?></a>&nbsp; <a href='' class='wpsc_select_none'><?php esc_html_e( 'None', 'wpsc' ); ?></a></span><br />
187
  ?>
188
  <h4><?php esc_html_e( 'Restrict to Target Markets', 'wpsc' )?></h4>
189
  <div class='form-field'>
190
+ <?php if ( wpsc_is_suhosin_enabled() ) : ?>
191
+ <em><?php esc_html_e( "The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature then disable the suhosin extension, if you can not do this, you will need to contact your hosting provider.", 'wpsc' ); ?></em>
192
  <?php else: ?>
193
  <div class='multiple-select-container'>
194
  <span><?php esc_html_e( 'Select', 'wpsc' ); ?> <a href='' class='wpsc_select_all'><?php esc_html_e( 'All', 'wpsc' ); ?></a>&nbsp; <a href='' class='wpsc_select_none'><?php esc_html_e( 'None', 'wpsc' ); ?></a></span><br />
wpsc-admin/includes/settings-tabs/admin.php CHANGED
@@ -61,7 +61,7 @@ class WPSC_Settings_Tab_Admin extends WPSC_Settings_Tab {
61
  <input type='radio' value='1' name='wpsc_options[wpsc_check_mime_types]' id='wpsc_check_mime_types1' <?php echo $wpsc_check_mime_types2; ?> /> <label for='wpsc_check_mime_types1'><?php _e('No', 'wpsc');?></label><br />
62
 
63
  <span class="wpscsmall description">
64
- <?php esc_html_e( 'Warning: Disabling this exposes your site to greater possibility of malicious files being uploaded, we recommend installing the Fileinfo extention for PHP rather than disabling this.', 'wpsc' ); ?>
65
  </span>
66
  </td>
67
  </tr>
61
  <input type='radio' value='1' name='wpsc_options[wpsc_check_mime_types]' id='wpsc_check_mime_types1' <?php echo $wpsc_check_mime_types2; ?> /> <label for='wpsc_check_mime_types1'><?php _e('No', 'wpsc');?></label><br />
62
 
63
  <span class="wpscsmall description">
64
+ <?php esc_html_e( 'Warning: Disabling this exposes your site to greater possibility of malicious files being uploaded, we recommend installing the Fileinfo extension for PHP rather than disabling this.', 'wpsc' ); ?>
65
  </span>
66
  </td>
67
  </tr>
wpsc-admin/includes/settings-tabs/gateway.php CHANGED
@@ -74,14 +74,14 @@ class WPSC_Settings_Tab_Gateway extends WPSC_Settings_Tab {
74
  <table id='wpsc-payment-gateway-settings' class='wpsc-edit-module-options wp-list-table widefat plugins'>
75
  <thead>
76
  <tr>
77
- <th scope="col" id="wpsc-gateway-active" class="manage-column"><?php _e( 'Active', 'wpsc' ); ?></th>
78
  <th scope="col" id="wpsc-gateway-name" class="manage-column column-name"><?php _e( 'Payment Gateway', 'wpsc' ); ?></th>
79
  <th scope="col" id="wpsc-gateway-display-name" class="manage-column column-description"><?php _e( 'Display Name', 'wpsc' ); ?></th>
80
  </tr>
81
  </thead>
82
  <tfoot>
83
  <tr>
84
- <th scope="col" id="wpsc-gateway-active" class="manage-column"><?php _e( 'Active', 'wpsc' ); ?></th>
85
  <th scope="col" id="wpsc-gateway-name" class="manage-column column-name"><?php _e( 'Payment Gateway', 'wpsc' ); ?></th>
86
  <th scope="col" id="wpsc-gateway-display-name" class="manage-column column-description"><?php _e( 'Display Name', 'wpsc' ); ?></th>
87
  </tr>
74
  <table id='wpsc-payment-gateway-settings' class='wpsc-edit-module-options wp-list-table widefat plugins'>
75
  <thead>
76
  <tr>
77
+ <th scope="col" id="wpsc-gateway-active" class="manage-column"></th>
78
  <th scope="col" id="wpsc-gateway-name" class="manage-column column-name"><?php _e( 'Payment Gateway', 'wpsc' ); ?></th>
79
  <th scope="col" id="wpsc-gateway-display-name" class="manage-column column-description"><?php _e( 'Display Name', 'wpsc' ); ?></th>
80
  </tr>
81
  </thead>
82
  <tfoot>
83
  <tr>
84
+ <th scope="col" id="wpsc-gateway-active" class="manage-column"></th>
85
  <th scope="col" id="wpsc-gateway-name" class="manage-column column-name"><?php _e( 'Payment Gateway', 'wpsc' ); ?></th>
86
  <th scope="col" id="wpsc-gateway-display-name" class="manage-column column-description"><?php _e( 'Display Name', 'wpsc' ); ?></th>
87
  </tr>
wpsc-admin/init.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  function wpsc_ajax_sales_quarterly() {
4
- $lastdate = $_POST['add_start'];
5
  $date = preg_split( '/-/', $lastdate );
6
  if ( !isset( $date[0] ) )
7
  $date[0] = 0;
@@ -29,7 +29,7 @@ if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action']
29
 
30
  function wpsc_delete_file() {
31
  $product_id = absint( $_REQUEST['product_id'] );
32
- $file_name = basename( $_REQUEST['file_name'] );
33
  check_admin_referer( 'delete_file_' . $file_name );
34
 
35
  _wpsc_delete_file( $product_id, $file_name );
@@ -95,7 +95,7 @@ function wpsc_purchase_log_csv() {
95
  if ( 'key' == $_REQUEST['rss_key'] && current_user_can( 'manage_options' ) ) {
96
  if ( isset( $_REQUEST['start_timestamp'] ) && isset( $_REQUEST['end_timestamp'] ) ) {
97
  $start_timestamp = $_REQUEST['start_timestamp'];
98
- $end_timestamp = $_REQUEST['end_timestamp'];
99
  $start_end_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN '%d' AND '%d' ORDER BY `date` DESC";
100
  $start_end_sql = apply_filters( 'wpsc_purchase_log_start_end_csv', $start_end_sql );
101
  $data = $wpdb->get_results( $wpdb->prepare( $start_end_sql, $start_timestamp, $end_timestamp ), ARRAY_A );
@@ -124,39 +124,42 @@ function wpsc_purchase_log_csv() {
124
 
125
  $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' AND `type` != 'heading' ORDER BY `checkout_order` DESC;";
126
  $form_data = $wpdb->get_results( $form_sql, ARRAY_A );
127
- $csv = 'Purchase ID, Price, Firstname, Lastname, Email, Order Status, Data, ';
128
 
129
  $headers_array = array(
130
- _x( 'Purchase ID', 'purchase log csv headers', 'wpsc' ),
131
  _x( 'Purchase Total', 'purchase log csv headers', 'wpsc' ),
132
  );
133
  $headers2_array = array(
134
  _x( 'Payment Gateway', 'purchase log csv headers', 'wpsc' ),
135
- _x( 'Payment Status', 'purchase log csv headers', 'wpsc' ),
136
- _x( 'Purchase Date', 'purchase log csv headers', 'wpsc' ),
137
  );
138
  $form_headers_array = array();
139
- $headers3_array = array();
140
 
141
  $output = '';
142
 
143
- foreach ( (array)$form_data as $form_field ) {
144
  if ( empty ( $form_field['unique_name'] ) ) {
145
  $form_headers_array[] = $form_field['name'];
146
  } else {
147
- $form_headers_array[] = $form_field['unique_name'];
 
148
  }
149
  }
150
 
151
- foreach ( (array)$data as $purchase ) {
152
  $form_headers = '';
153
  $output .= "\"" . $purchase['id'] . "\","; //Purchase ID
154
  $output .= "\"" . $purchase['totalprice'] . "\","; //Purchase Total
155
- foreach ( (array)$form_data as $form_field ) {
156
  $collected_data_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = '" . $purchase['id'] . "' AND `form_id` = '" . $form_field['id'] . "' LIMIT 1";
157
  $collected_data = $wpdb->get_results( $collected_data_sql, ARRAY_A );
158
  $collected_data = $collected_data[0];
159
- $output .= "\"" . $collected_data['value'] . "\","; // get form fields
 
 
 
 
160
  }
161
 
162
  if ( isset( $wpsc_gateways[$purchase['gateway']] ) && isset( $wpsc_gateways[$purchase['gateway']]['display_name'] ) )
@@ -173,17 +176,30 @@ function wpsc_purchase_log_csv() {
173
  $cartsql = "SELECT `prodid`, `quantity`, `name` FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase['id'] . "";
174
  $cart = $wpdb->get_results( $cartsql, ARRAY_A );
175
 
176
- if( $count < count( $cart ) )
177
  $count = count( $cart );
 
 
 
 
178
  // Go through all products in cart and display quantity and sku
179
- foreach ( (array)$cart as $item ) {
180
  $skuvalue = get_product_meta( $item['prodid'], 'sku', true );
181
  if( empty( $skuvalue ) )
182
  $skuvalue = __( 'N/A', 'wpsc' );
183
  $output .= "\"" . $item['quantity'] . "\",";
184
- $output .= "\"" . str_replace( '"', '\"', $item['name'] ) . "\"";
185
- $output .= "," . $skuvalue."," ;
 
 
 
 
 
 
 
 
186
  }
 
187
  $output .= "\n"; // terminates the row/line in the CSV file
188
  }
189
  // Get the most number of products and create a header for them
@@ -200,8 +216,10 @@ function wpsc_purchase_log_csv() {
200
  $headers3 = '"' . implode( '","', $headers3 ) . '"';
201
 
202
  $headers = apply_filters( 'wpsc_purchase_log_csv_headers', $headers . $form_headers . $headers2 . $headers3, $data, $form_data );
203
- $output = apply_filters( 'wpsc_purchase_log_csv_output', $output, $data, $form_data );
 
204
  do_action( 'wpsc_purchase_log_csv' );
 
205
  header( 'Content-Type: text/csv' );
206
  header( 'Content-Disposition: inline; filename="' . $csv_name . '"' );
207
  echo $headers . "\n". $output;
@@ -254,20 +272,6 @@ function wpsc_admin_sale_rss() {
254
  if ( isset( $_GET['action'] ) && ( 'purchase_log' == $_GET['action'] ) )
255
  add_action( 'admin_init', 'wpsc_admin_sale_rss' );
256
 
257
- function wpsc_display_invoice() {
258
- $purchase_id = (int)$_REQUEST['purchaselog_id'];
259
- add_action('wpsc_packing_slip', 'wpsc_packing_slip');
260
- do_action('wpsc_before_packing_slip', $purchase_id);
261
- do_action('wpsc_packing_slip', $purchase_id);
262
- exit();
263
- }
264
- //other actions are here
265
- if ( isset( $_GET['display_invoice'] ) && ( 'true' == $_GET['display_invoice'] ) )
266
- add_action( 'admin_init', 'wpsc_display_invoice', 0 );
267
-
268
- if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc_display_invoice' == $_REQUEST['wpsc_admin_action'] ) )
269
- add_action( 'admin_init', 'wpsc_display_invoice' );
270
-
271
  /**
272
  * Purchase log ajax code starts here
273
  */
@@ -297,16 +301,15 @@ function wpsc_purchlog_clear_download_items() {
297
  global $wpdb;
298
  if ( is_numeric( $_GET['purchaselog_id'] ) ) {
299
  $purchase_id = (int)$_GET['purchaselog_id'];
300
- $downloadable_items = $wpdb->get_results( "SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `purchid` IN ('$purchase_id')", ARRAY_A );
301
 
302
- $clear_locks_sql = "UPDATE`" . WPSC_TABLE_DOWNLOAD_STATUS . "` SET `ip_number` = '' WHERE `purchid` IN ('$purchase_id')";
303
- $wpdb->query( $clear_locks_sql );
304
  $cleared = true;
305
 
306
  $email_form_field = $wpdb->get_var( "SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `checkout_order` ASC LIMIT 1" );
307
- $email_address = $wpdb->get_var( "SELECT `value` FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id`='{$purchase_id}' AND `form_id` = '{$email_form_field}' LIMIT 1" );
308
 
309
- foreach ( (array)$downloadable_items as $downloadable_item ) {
310
  $download_links .= add_query_arg(
311
  'downloadid',
312
  $downloadable_item['uniqueid'],
@@ -315,14 +318,14 @@ function wpsc_purchlog_clear_download_items() {
315
  }
316
 
317
 
318
- wp_mail( $email_address, __( 'The administrator has unlocked your file', 'wpsc' ), str_replace( "[download_links]", $download_links, __( 'Dear CustomerWe are pleased to advise you that your order has been updated and your downloads are now active.Please download your purchase using the links provided below.[download_links]Thank you for your custom.', 'wpsc' ) ), "From: " . get_option( 'return_email' ) . "" );
319
-
320
 
321
  $sendback = wp_get_referer();
322
 
323
  if ( isset( $cleared ) ) {
324
  $sendback = add_query_arg( 'cleared', $cleared, $sendback );
325
  }
 
326
  wp_redirect( $sendback );
327
  exit();
328
  }
@@ -680,19 +683,6 @@ function wpsc_delete_variation_set() {
680
  if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-variation-set' == $_REQUEST['wpsc_admin_action'] ) )
681
  add_action( 'admin_init', 'wpsc_delete_variation_set' );
682
 
683
- function wpsc_force_flush_theme_transients() {
684
- // Flush transients
685
- wpsc_flush_theme_transients( true );
686
-
687
- // Bounce back
688
- $sendback = wp_get_referer();
689
- wp_redirect( $sendback );
690
-
691
- exit();
692
- }
693
- if ( isset( $_REQUEST['wpsc_flush_theme_transients'] ) && ( $_REQUEST['wpsc_flush_theme_transients'] == 'true' ) )
694
- add_action( 'admin_init', 'wpsc_force_flush_theme_transients' );
695
-
696
  function wpsc_backup_theme() {
697
  $wp_theme_path = get_stylesheet_directory();
698
  wpsc_recursive_copy( $wp_theme_path, WPSC_THEME_BACKUP_DIR );
1
  <?php
2
 
3
  function wpsc_ajax_sales_quarterly() {
4
+ $lastdate = sanitize_text_field( $_POST['add_start'] );
5
  $date = preg_split( '/-/', $lastdate );
6
  if ( !isset( $date[0] ) )
7
  $date[0] = 0;
29
 
30
  function wpsc_delete_file() {
31
  $product_id = absint( $_REQUEST['product_id'] );
32
+ $file_name = basename( $_REQUEST['file_name'] );
33
  check_admin_referer( 'delete_file_' . $file_name );
34
 
35
  _wpsc_delete_file( $product_id, $file_name );
95
  if ( 'key' == $_REQUEST['rss_key'] && current_user_can( 'manage_options' ) ) {
96
  if ( isset( $_REQUEST['start_timestamp'] ) && isset( $_REQUEST['end_timestamp'] ) ) {
97
  $start_timestamp = $_REQUEST['start_timestamp'];
98
+ $end_timestamp = $_REQUEST['end_timestamp'];
99
  $start_end_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN '%d' AND '%d' ORDER BY `date` DESC";
100
  $start_end_sql = apply_filters( 'wpsc_purchase_log_start_end_csv', $start_end_sql );
101
  $data = $wpdb->get_results( $wpdb->prepare( $start_end_sql, $start_timestamp, $end_timestamp ), ARRAY_A );
124
 
125
  $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' AND `type` != 'heading' ORDER BY `checkout_order` DESC;";
126
  $form_data = $wpdb->get_results( $form_sql, ARRAY_A );
 
127
 
128
  $headers_array = array(
129
+ _x( 'Purchase ID' , 'purchase log csv headers', 'wpsc' ),
130
  _x( 'Purchase Total', 'purchase log csv headers', 'wpsc' ),
131
  );
132
  $headers2_array = array(
133
  _x( 'Payment Gateway', 'purchase log csv headers', 'wpsc' ),
134
+ _x( 'Payment Status' , 'purchase log csv headers', 'wpsc' ),
135
+ _x( 'Purchase Date' , 'purchase log csv headers', 'wpsc' ),
136
  );
137
  $form_headers_array = array();
 
138
 
139
  $output = '';
140
 
141
+ foreach ( (array) $form_data as $form_field ) {
142
  if ( empty ( $form_field['unique_name'] ) ) {
143
  $form_headers_array[] = $form_field['name'];
144
  } else {
145
+ $prefix = false === strstr( $form_field['unique_name'], 'billing' ) ? _x( 'Shipping ', 'purchase log csv header field prefix', 'wpsc' ) : _x( 'Billing ', 'purchase log csv header field prefix', 'wpsc' );
146
+ $form_headers_array[] = $prefix . $form_field['name'];
147
  }
148
  }
149
 
150
+ foreach ( (array) $data as $purchase ) {
151
  $form_headers = '';
152
  $output .= "\"" . $purchase['id'] . "\","; //Purchase ID
153
  $output .= "\"" . $purchase['totalprice'] . "\","; //Purchase Total
154
+ foreach ( (array) $form_data as $form_field ) {
155
  $collected_data_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = '" . $purchase['id'] . "' AND `form_id` = '" . $form_field['id'] . "' LIMIT 1";
156
  $collected_data = $wpdb->get_results( $collected_data_sql, ARRAY_A );
157
  $collected_data = $collected_data[0];
158
+
159
+ if ( ( 'billingstate' == $form_field['unique_name'] || 'shippingstate' == $form_field['unique_name'] ) && is_numeric( $collected_data['value'] ) )
160
+ $output .= "\"" . wpsc_get_state_by_id( $collected_data['value'], 'code' ) . "\","; // get form fields
161
+ else
162
+ $output .= "\"" . str_replace( array( "\r", "\r\n", "\n" ), ' ', $collected_data['value'] ) . "\","; // get form fields
163
  }
164
 
165
  if ( isset( $wpsc_gateways[$purchase['gateway']] ) && isset( $wpsc_gateways[$purchase['gateway']]['display_name'] ) )
176
  $cartsql = "SELECT `prodid`, `quantity`, `name` FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase['id'] . "";
177
  $cart = $wpdb->get_results( $cartsql, ARRAY_A );
178
 
179
+ if ( $count < count( $cart ) )
180
  $count = count( $cart );
181
+
182
+ $items = count( $cart );
183
+ $i = 1;
184
+
185
  // Go through all products in cart and display quantity and sku
186
+ foreach ( (array) $cart as $item ) {
187
  $skuvalue = get_product_meta( $item['prodid'], 'sku', true );
188
  if( empty( $skuvalue ) )
189
  $skuvalue = __( 'N/A', 'wpsc' );
190
  $output .= "\"" . $item['quantity'] . "\",";
191
+ $output .= "\"" . str_replace( '"', '\"', $item['name'] ) . "\",";
192
+
193
+ if ( $items <= 1 )
194
+ $output .= "\"" . $skuvalue . "\"" ;
195
+ elseif ( $items > 1 && $i != $items )
196
+ $output .= "\"" . $skuvalue . "\"," ;
197
+ else
198
+ $output .= "\"" . $skuvalue . "\"" ;
199
+
200
+ $i++;
201
  }
202
+
203
  $output .= "\n"; // terminates the row/line in the CSV file
204
  }
205
  // Get the most number of products and create a header for them
216
  $headers3 = '"' . implode( '","', $headers3 ) . '"';
217
 
218
  $headers = apply_filters( 'wpsc_purchase_log_csv_headers', $headers . $form_headers . $headers2 . $headers3, $data, $form_data );
219
+ $output = apply_filters( 'wpsc_purchase_log_csv_output' , $output, $data, $form_data );
220
+
221
  do_action( 'wpsc_purchase_log_csv' );
222
+
223
  header( 'Content-Type: text/csv' );
224
  header( 'Content-Disposition: inline; filename="' . $csv_name . '"' );
225
  echo $headers . "\n". $output;
272
  if ( isset( $_GET['action'] ) && ( 'purchase_log' == $_GET['action'] ) )
273
  add_action( 'admin_init', 'wpsc_admin_sale_rss' );
274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  /**
276
  * Purchase log ajax code starts here
277
  */
301
  global $wpdb;
302
  if ( is_numeric( $_GET['purchaselog_id'] ) ) {
303
  $purchase_id = (int)$_GET['purchaselog_id'];
304
+ $downloadable_items = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `purchid` = %d", $purchase_id ), ARRAY_A );
305
 
306
+ $wpdb->update( WPSC_TABLE_DOWNLOAD_STATUS, array( 'ip_number' => '' ), array( 'purchid' => $purchase_id ), '%s', '%d' );
 
307
  $cleared = true;
308
 
309
  $email_form_field = $wpdb->get_var( "SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `checkout_order` ASC LIMIT 1" );
310
+ $email_address = $wpdb->get_var( $wpdb->prepare( "SELECT `value` FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = '{$email_form_field}' LIMIT 1", $purchase_id ) );
311
 
312
+ foreach ( (array) $downloadable_items as $downloadable_item ) {
313
  $download_links .= add_query_arg(
314
  'downloadid',
315
  $downloadable_item['uniqueid'],
318
  }
319
 
320
 
321
+ wp_mail( $email_address, __( 'The administrator has unlocked your file', 'wpsc' ), str_replace( "[download_links]", $download_links, __( 'Dear CustomerWe are pleased to advise you that your order has been updated and your downloads are now active.Please download your purchase using the links provided below.[download_links]Thank you for your custom.', 'wpsc' ) ), "From: " . get_option( 'return_email' ) );
 
322
 
323
  $sendback = wp_get_referer();
324
 
325
  if ( isset( $cleared ) ) {
326
  $sendback = add_query_arg( 'cleared', $cleared, $sendback );
327
  }
328
+
329
  wp_redirect( $sendback );
330
  exit();
331
  }
683
  if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-variation-set' == $_REQUEST['wpsc_admin_action'] ) )
684
  add_action( 'admin_init', 'wpsc_delete_variation_set' );
685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
686
  function wpsc_backup_theme() {
687
  $wp_theme_path = get_stylesheet_directory();
688
  wpsc_recursive_copy( $wp_theme_path, WPSC_THEME_BACKUP_DIR );
wpsc-admin/js/admin.js CHANGED
@@ -10,7 +10,7 @@
10
  data['wpsc_action'] = data['action'];
11
  data['action'] = 'wpsc_ajax';
12
 
13
- $.post(ajaxurl, data, handler, 'json');
14
  };
15
 
16
  /**
@@ -24,7 +24,7 @@
24
  data['wpsc_action'] = data['action'];
25
  data['action'] = 'wpsc_ajax';
26
 
27
- $.get(ajaxurl, data, handler, 'json');
28
  };
29
 
30
  if( pagenow == 'edit-wpsc_product_category' ) {
@@ -155,7 +155,7 @@
155
  return false;
156
  });
157
 
158
- })(jQuery);
159
 
160
  jQuery(document).ready(function(){
161
  jQuery('td.hidden_alerts img').each(function(){
10
  data['wpsc_action'] = data['action'];
11
  data['action'] = 'wpsc_ajax';
12
 
13
+ return $.post(ajaxurl, data, handler, 'json');
14
  };
15
 
16
  /**
24
  data['wpsc_action'] = data['action'];
25
  data['action'] = 'wpsc_ajax';
26
 
27
+ return $.get(ajaxurl, data, handler, 'json');
28
  };
29
 
30
  if( pagenow == 'edit-wpsc_product_category' ) {
155
  return false;
156
  });
157
 
158
+ }(jQuery));
159
 
160
  jQuery(document).ready(function(){
161
  jQuery('td.hidden_alerts img').each(function(){
wpsc-admin/js/media.js ADDED
@@ -0,0 +1,392 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*global _, WPSC_Media, Backbone, alert, WPSC, wp, wpsc_refresh_variation_iframe, wpsc_set_variation_product_thumbnail, jQuery, WPRemoveThumbnail */
2
+ (function($) {
3
+ "use strict";
4
+ window.WPSC = window.WPSC || {};
5
+
6
+ /**
7
+ * Inspired by Cocktail (https://github.com/onsi/cocktail/) but with some
8
+ * important modifications.
9
+ *
10
+ * Mixing an object into a class' prototype will make sure that object is
11
+ * extended from previous Mixins / oroginal prototype.
12
+ *
13
+ * Primitive values can also be mixed in.
14
+ *
15
+ * @param {Object} object The original object
16
+ * @param {...Object} mixins Mixins
17
+ */
18
+ window.WPSC.mixin = function( clss ) {
19
+ var modules = _.rest( arguments );
20
+ var chain = {};
21
+
22
+ _.each( modules, function( module ) {
23
+ var override = module._mixin_override || [];
24
+ module = _.omit( module, [ '_mixin_override'] );
25
+
26
+ _.each( module, function( value, key ) {
27
+ if ( _.contains( override, key ) ) {
28
+ chain[key] = [value];
29
+ return;
30
+ }
31
+
32
+ if ( _.isFunction( value ) ) {
33
+ if ( clss.prototype[key] )
34
+ chain[key] = [clss.prototype[key]];
35
+
36
+ chain[key].push( value );
37
+ } else if ( _.isObject( value ) ) {
38
+ chain[key] = chain[key] || [{}];
39
+ if ( clss.prototype[key] )
40
+ chain[key] = [clss.prototype[key]];
41
+
42
+ chain[key].push( _.extend( {}, chain[key][0], value ) );
43
+ } else {
44
+ chain[key] = chain[key] || [];
45
+ chain[key].push( value );
46
+ }
47
+ } );
48
+ } );
49
+
50
+ _.each( chain, function( values, key ) {
51
+ var last = _.last( values );
52
+
53
+ if ( ! _.isFunction( last ) ) {
54
+ clss.prototype[key] = last;
55
+ return;
56
+ }
57
+
58
+ clss.prototype[key] = function() {
59
+ var ret, args = arguments, that = this;
60
+ _.each( values, function( fn ) {
61
+ var fnRet = fn.apply( that, args );
62
+ ret =
63
+ _.isUndefined( fnRet ) ?
64
+ ret :
65
+ fnRet;
66
+ });
67
+
68
+ return ret;
69
+ };
70
+ } );
71
+ };
72
+
73
+ var media = window.wp.media;
74
+
75
+ var backup = _.clone( media.view.settings.post );
76
+
77
+ media.controller.wpsc = {
78
+ ProductGallery: media.controller.Library.extend({
79
+ defaults: _.defaults({
80
+ id : 'wpsc-product-gallery',
81
+ filterable : 'uploaded',
82
+ multiple : 'add',
83
+ toolbar : 'wpsc-save-gallery',
84
+ title : WPSC_Media.l10n.productMediaTitle,
85
+ priority : 50,
86
+ library : media.query( { type: 'image' } ),
87
+ syncSelection: false
88
+ }, media.controller.Library.prototype.defaults ),
89
+
90
+ initialize: function( options ) {
91
+ options = options || {};
92
+ var selection = new media.model.wpsc.ProductGallerySelection(
93
+ [],
94
+ {
95
+ postId: media.model.settings.post.id,
96
+ multiple: this.get( 'multiple' ),
97
+ updateNonce: options.updateNonce || WPSC_Media.updateGalleryNonce,
98
+ getNonce: options.getNonce || WPSC_Media.getGalleryNonce
99
+ }
100
+ );
101
+ this.set(
102
+ 'selection',
103
+ selection
104
+ );
105
+
106
+ var models = options.models || WPSC_Media.gallery;
107
+
108
+ // work around for backbone.js 0.9.2
109
+ if ( _.isUndefined( Backbone.Collection.prototype.set ) ) {
110
+ // force parse the response
111
+ models = selection.parse( models );
112
+ selection.reset( models );
113
+ } else {
114
+ selection.set( models, { parse: true } );
115
+ }
116
+
117
+ media.controller.Library.prototype.initialize.apply( this, arguments );
118
+
119
+ this.on( 'select', function() {
120
+ selection.save_gallery();
121
+ } );
122
+
123
+ this.on( 'reset', function() {
124
+ selection.get_gallery();
125
+ }) ;
126
+
127
+ this.get( 'library' ).observe( selection );
128
+ }
129
+ })
130
+ };
131
+
132
+ media.model.wpsc = {
133
+ ProductGallerySelection: media.model.Selection.extend( {
134
+ initialize: function( models, options ) {
135
+ media.model.Selection.prototype.initialize.apply( this, [models, options] );
136
+ this.postId = options && options.postId;
137
+ this.updateNonce = options.updateNonce || WPSC_Media.updateGalleryNonce;
138
+ this.getNonce = options.getNonce || WPSC_Media.getGalleryNonce;
139
+ },
140
+
141
+ save_gallery: function( options ) {
142
+ options = _.extend( options || {}, {
143
+ data: {
144
+ items: this.pluck( 'id' )
145
+ },
146
+ success: function( resp, status, xhr ) {
147
+ // in case of backbone 0.9.2
148
+ if ( _.isUndefined( this.set ) ) {
149
+ // force parse the response
150
+ resp.obj = this.parse( resp.obj, xhr );
151
+ this.reset( resp.obj );
152
+ } else {
153
+ this.set( resp.obj, { parse: true } );
154
+ }
155
+ },
156
+ error: function( resp ) {
157
+ alert( resp.error.messages.join( "\n" ) );
158
+ }
159
+ } );
160
+ this.sync( 'update', this, options );
161
+ },
162
+
163
+ get_gallery: function( options ) {
164
+ options = _.extend( options || {}, {
165
+ success: function( resp, status, xhr ) {
166
+ // in case of backbone 0.9.2
167
+ if ( _.isUndefined( this.set ) ) {
168
+ // force parse the response
169
+ resp.obj = this.parse( resp.obj, xhr );
170
+ this.reset( resp.obj );
171
+ } else {
172
+ this.set( resp.obj, { parse: true } );
173
+ }
174
+ wpsc_refresh_variation_iframe();
175
+ },
176
+ error: function( resp ) {
177
+ alert( resp.error.messages.join( "\n" ) );
178
+ }
179
+ } );
180
+ this.sync( 'read', this, options );
181
+ },
182
+
183
+ sync: function( method, collection, options ) {
184
+ var data;
185
+ options = options ? _.clone( options ) : {};
186
+
187
+ options.success = _.bind( options.success, this );
188
+ options.error = _.bind( options.error, this );
189
+
190
+ switch (method) {
191
+ case 'read':
192
+ options.data = options.data || {};
193
+ data = _.defaults( {
194
+ action: 'get_product_gallery',
195
+ nonce : this.getNonce,
196
+ postId: this.postId
197
+ }, options.data );
198
+ break;
199
+
200
+ case 'update':
201
+ options.data = options.data || {};
202
+ data = _.defaults( {
203
+ action: 'save_product_gallery',
204
+ nonce : this.updateNonce,
205
+ items : this.pluck( 'id' ),
206
+ postId: this.postId
207
+ }, options.data );
208
+ break;
209
+
210
+ case 'create':
211
+ case 'delete':
212
+ // do nothing for now
213
+ break;
214
+ }
215
+
216
+ $.wpsc_post( data ).done( function( resp, status, xhr ) {
217
+ if ( resp.is_successful ) {
218
+ options.success( resp, status, xhr );
219
+ } else {
220
+ options.error( resp, status, xhr );
221
+ }
222
+ } );
223
+ }
224
+ } )
225
+ };
226
+
227
+ media.view.wpsc = {
228
+ };
229
+
230
+ /**
231
+ * Extend the MediaFrame.Post class so that we can inject a custom tab
232
+ * dynamically using JavaScript.
233
+ */
234
+ WPSC.mixin(
235
+ media.view.MediaFrame.Post,
236
+ {
237
+ wpsc: {
238
+ saveGalleryStatusBar: function( view ) {
239
+ this.selectionStatusToolbar(view);
240
+ },
241
+ saveGalleryToolbar: function( toolbar ) {
242
+ this.createSelectToolbar( toolbar, {
243
+ text : WPSC_Media.l10n.saveGallery,
244
+ state: this.options.state,
245
+ reset: false
246
+ } );
247
+ },
248
+ createStates: function() {
249
+ this.states.add( new media.controller.wpsc.ProductGallery( { models: this.options.models, updateNonce: this.options.updateNonce, getNonce: this.options.getNonce } ) );
250
+ },
251
+ bindHandlers: function() {
252
+ this.on( 'toolbar:create:wpsc-save-gallery', this.wpsc.saveGalleryToolbar, this );
253
+ this.on( 'toolbar:render:wpsc-save-gallery', this.wpsc.saveGalleryStatusBar, this );
254
+ }
255
+ },
256
+
257
+ initialize: function() {
258
+ if ( ! this.options.models )
259
+ this.options.models = WPSC_Media.gallery;
260
+
261
+ if ( ! this.options.updateNonce )
262
+ this.options.updateNonce = WPSC_Media.updateGalleryNonce;
263
+
264
+ if ( ! this.options.getNonce )
265
+ this.options.getNonce = WPSC_Media.getGalleryNonce;
266
+
267
+ this.wpsc.createStates.apply( this );
268
+ this.wpsc.bindHandlers.apply( this );
269
+ }
270
+ }
271
+ );
272
+
273
+ /**
274
+ * Extend media.view.Attachment
275
+ */
276
+ WPSC.mixin(
277
+ media.view.Attachment,
278
+ {
279
+ render: function() {
280
+ if ( this.controller.state().id != 'wpsc-product-gallery' )
281
+ return;
282
+
283
+ if ( this.model.id != media.view.settings.post.featuredImageId )
284
+ return;
285
+
286
+ this.$el.find( '.thumbnail' ).append('<span class="wpsc-featured-label">featured</span>');
287
+ }
288
+ }
289
+ );
290
+
291
+ WPSC_Media.open = function( options ) {
292
+ var workflow;
293
+
294
+ media.view.settings.post.id = options.id;
295
+ media.view.settings.post.featuredImageId = options.featuredId;
296
+ media.view.settings.post.nonce = options.featuredNonce;
297
+ media.model.settings.post = media.view.settings.post;
298
+ media.editor.remove( 'wpsc-variation-media' );
299
+ media.editor.add( 'wpsc-variation-media', {
300
+ models: options.models,
301
+ updateNonce: options.galleryUpdateNonce,
302
+ getNonce: options.galleryGetNonce
303
+ });
304
+ workflow = media.editor.open( 'wpsc-variation-media' );
305
+ };
306
+
307
+ var oldEditorOpen = media.editor.open;
308
+ media.editor.open = function( id ) {
309
+ if ( id == 'content' ) {
310
+ if ( media.view.settings.post.id == backup.id ) {
311
+ // always make sure the backup copy is up to date
312
+ backup = _.clone( media.view.settings.post );
313
+ } else {
314
+ // if the frame was opened for a variation previously, this time
315
+ // restore the globals from the backup
316
+ media.view.settings.post = _.clone( backup );
317
+ media.model.settings.post = media.view.settings.post;
318
+ }
319
+ }
320
+ return oldEditorOpen.apply( this, arguments );
321
+ };
322
+
323
+ // hack the set featured image function
324
+ wp.media.featuredImage.set = function( id ) {
325
+ var settings = wp.media.view.settings;
326
+ var currentId = settings.post.id;
327
+
328
+ settings.post.featuredImageId = id;
329
+
330
+ wp.media.post( 'set-post-thumbnail', {
331
+ json: true,
332
+ post_id: settings.post.id,
333
+ thumbnail_id: settings.post.featuredImageId,
334
+ _wpnonce: settings.post.nonce
335
+ }).done( function( html ) {
336
+ if ( currentId == backup.id ) {
337
+ wpsc_refresh_variation_iframe();
338
+ $( '.inside', '#postimagediv' ).html( html );
339
+ } else {
340
+ wpsc_set_variation_product_thumbnail( currentId, $( html ).find( 'img' ).attr( 'src' ), id );
341
+ }
342
+ });
343
+ };
344
+
345
+ // hack the Remove thumbnail link so that it refreshes the variation iframe
346
+ // after the AJAX request is processed
347
+ WPRemoveThumbnail = function(nonce){
348
+ $.post(ajaxurl, {
349
+ action:"set-post-thumbnail", post_id: $('#post_ID').val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
350
+ }, function(str){
351
+ if ( str == '0' ) {
352
+ alert( setPostThumbnailL10n.error );
353
+ } else {
354
+ WPSetThumbnailHTML(str);
355
+ wpsc_refresh_variation_iframe();
356
+ }
357
+ }
358
+ );
359
+ };
360
+
361
+
362
+ $(function() {
363
+ $('#wpsc-manage-product-gallery').on('click', function( e ) {
364
+ var frame;
365
+
366
+ e.preventDefault();
367
+ e.stopPropagation();
368
+
369
+ frame = wp.media({
370
+ state: 'wpsc-product-gallery',
371
+ states: [ new wp.media.controller.wpsc.ProductGallery() ]
372
+ });
373
+
374
+ frame.on( 'toolbar:create:wpsc-save-gallery', function(toolbar) {
375
+ this.createSelectToolbar( toolbar, {
376
+ text : WPSC_Media.l10n.saveGallery,
377
+ state: this.options.state
378
+ } );
379
+ }, frame );
380
+ frame.on( 'toolbar:render:wpsc-save-gallery', function( view ) {
381
+ view.set( 'selection', new media.view.Selection({
382
+ controller: this,
383
+ collection: this.state().get( 'selection' ),
384
+ priority: -40,
385
+ editable: this.state().get('editable')
386
+ }).render());
387
+ }, frame );
388
+
389
+ frame.open();
390
+ });
391
+ });
392
+ }(jQuery));
wpsc-admin/js/product-variations.js CHANGED
@@ -53,8 +53,31 @@
53
  };
54
 
55
  var event_variation_thumbnail_click = function() {
56
- var t = $(this);
57
- window.parent.wpsc_display_thickbox(t.data('title'), t.attr('href'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  return false;
59
  };
60
 
53
  };
54
 
55
  var event_variation_thumbnail_click = function() {
56
+ var t = $( this ), postId = t.data( 'id' ), nonce = t.data( 'nonce' );
57
+
58
+ $.wpsc_post(
59
+ {
60
+ action: 'get_variation_gallery',
61
+ nonce: nonce,
62
+ id: postId
63
+ },
64
+ function( response ) {
65
+ if ( ! response.is_successful ) {
66
+ alert( response.error.messages.join( "\n" ) );
67
+ return;
68
+ }
69
+
70
+ window.parent.WPSC_Media.open({
71
+ id: postId,
72
+ featuredId: response.obj.featuredId,
73
+ models: response.obj.models,
74
+ galleryUpdateNonce: t.data( 'save-gallery-nonce' ),
75
+ galleryGetNonce: t.data( 'get-gallery-nonce' ),
76
+ featuredNonce: t.data( 'featured-nonce' )
77
+ });
78
+ }
79
+ );
80
+
81
  return false;
82
  };
83
 
wpsc-admin/js/variations.js CHANGED
@@ -46,9 +46,15 @@ var wpsc_display_thickbox = function(title, url) {
46
  tb_show(WPSC_Variations.thickbox_title.replace('%s', title), url);
47
  };
48
 
49
- var wpsc_set_variation_product_thumbnail = function(id, src) {
50
  var iframe = jQuery('#wpsc_product_variation_forms iframe');
51
- iframe.contents().find('#wpsc-variation-thumbnail-' + id).attr('src', src);
 
 
 
 
 
 
52
  };
53
 
54
  (function($) {
46
  tb_show(WPSC_Variations.thickbox_title.replace('%s', title), url);
47
  };
48
 
49
+ var wpsc_set_variation_product_thumbnail = function(id, src, thumbId) {
50
  var iframe = jQuery('#wpsc_product_variation_forms iframe');
51
+ var el = iframe.contents().find('#wpsc-variation-thumbnail-' + id);
52
+ el.attr('src', src);
53
+ el.parent().data( 'image-id', thumbId );
54
+ };
55
+
56
+ var wpsc_refresh_variation_iframe = function() {
57
+ jQuery('#wpsc_product_variation_forms iframe')[0].contentWindow.location.reload();
58
  };
59
 
60
  (function($) {
wpsc-admin/media.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'admin_enqueue_scripts', '_wpsc_action_enqueue_media_scripts' );
4
+ add_action( 'admin_enqueue_scripts', '_wpsc_action_enqueue_media_styles' );
5
+ add_action( 'admin_footer', '_wpsc_action_print_media_templates' );
6
+
7
+ function _wpsc_action_enqueue_media_scripts() {
8
+ $current_screen = get_current_screen();
9
+
10
+ if ( in_array( $current_screen->id, array( 'wpsc-product-variations-iframe', 'wpsc-product' ) ) ) {
11
+ $post = get_post();
12
+ if ( ! $post )
13
+ $id = absint( $_REQUEST['product_id'] );
14
+ else
15
+ $id = $post->ID;
16
+
17
+ $gallery = _wpsc_get_product_gallery_json( $id );
18
+ wp_enqueue_script( 'wpsc-media', WPSC_URL . '/wpsc-admin/js/media.js', array( 'media-editor', 'wp-e-commerce-admin', 'post' ), WPSC_VERSION );
19
+ wp_localize_script( 'wpsc-media', 'WPSC_Media', array(
20
+ 'l10n' => array(
21
+ 'productMediaTitle' => __( 'Add Images to Product Gallery', 'wpsc' ),
22
+ 'saveGallery' => __( 'Set Product Images', 'wpsc' ),
23
+ ),
24
+ 'gallery' => $gallery,
25
+ 'updateGalleryNonce' => wp_create_nonce( 'wpsc_ajax_update_gallery_' . $id ),
26
+ 'getGalleryNonce' => wp_create_nonce( 'wpsc_ajax_get_gallery_' . $id )
27
+ ) );
28
+ }
29
+ }
30
+
31
+ function _wpsc_action_enqueue_media_styles() {
32
+ $current_screen = get_current_screen();
33
+
34
+ if ( 'wpsc-product' == $current_screen->id )
35
+ wp_enqueue_style( 'wpsc-media', WPSC_URL . '/wpsc-admin/css/media.css', array( 'media-views' ), WPSC_VERSION );
36
+ }
37
+
38
+ function _wpsc_action_print_media_templates() {
39
+ ?>
40
+ <script type="text/html" id="tmpl-wpsc-featured-image">
41
+ <div class="wpsc-media-featured-image">
42
+ <span class="title"><?php _e( 'Featured image', 'wpsc' ); ?></span>
43
+ <a class="edit-selection" href="#"><?php _ex( 'Edit', 'edit featured image', 'wpsc' ); ?></a>
44
+ </div>
45
+ <div class="wpsc-selection-view"></div>
46
+ </script>
47
+ <?php
48
+ }
49
+
50
+ function _wpsc_ajax_verify_get_variation_gallery() {
51
+ return _wpsc_ajax_verify_nonce( 'get_variation_gallery_' . absint( $_REQUEST['id'] ) );
52
+ }
53
+
54
+ function _wpsc_ajax_get_variation_gallery() {
55
+ $id = absint( $_REQUEST['id'] );
56
+
57
+ $gallery = _wpsc_get_product_gallery_json( $id );
58
+
59
+ return array(
60
+ 'models' => $gallery,
61
+ 'featuredId' => wpsc_the_product_thumbnail_id( $id )
62
+ );
63
+ }
64
+
65
+ function _wpsc_ajax_verify_save_product_gallery() {
66
+ return _wpsc_ajax_verify_nonce( 'update_gallery_' . absint( $_REQUEST['postId'] ) );
67
+ }
68
+
69
+ function _wpsc_ajax_verify_get_product_gallery() {
70
+ return _wpsc_ajax_verify_nonce( 'get_gallery_' . absint( $_REQUEST['postId'] ) );
71
+ }
72
+
73
+ function _wpsc_ajax_save_product_gallery() {
74
+ $id = absint( $_REQUEST['postId'] );
75
+ $items = array_map( 'absint', $_REQUEST['items'] );
76
+ $thumb = get_post_thumbnail_id( $id );
77
+
78
+ // always make sure the thumbnail is included
79
+ if ( $thumb && ! in_array( $thumb, $items ) )
80
+ $items[] = $thumb;
81
+
82
+ $result = wpsc_set_product_gallery( $id, $items );
83
+
84
+ return _wpsc_get_product_gallery_json( $id );
85
+ }
86
+
87
+ function _wpsc_ajax_get_product_gallery() {
88
+ $id = absint( $_REQUEST['postId'] );
89
+ return _wpsc_get_product_gallery_json( $id );
90
+ }
91
+
92
+ function _wpsc_get_product_gallery_json( $id ) {
93
+ $attachments = wpsc_get_product_gallery( $id );
94
+ return array_map( 'wp_prepare_attachment_for_js', $attachments );
95
+ }
wpsc-admin/settings-page.php CHANGED
@@ -203,7 +203,6 @@ final class WPSC_Settings_Page {
203
  public static function init() {
204
  self::$default_tabs = array(
205
  'general' => _x( 'General' , 'General settings tab in Settings->Store page' , 'wpsc' ),
206
- 'presentation' => _x( 'Presentation', 'Presentation settings tab in Settings->Store page', 'wpsc' ),
207
  'admin' => _x( 'Admin' , 'Admin settings tab in Settings->Store page' , 'wpsc' ),
208
  'taxes' => _x( 'Taxes' , 'Taxes settings tab in Settings->Store page' , 'wpsc' ),
209
  'shipping' => _x( 'Shipping' , 'Shipping settings tab in Settings->Store page' , 'wpsc' ),
@@ -378,10 +377,10 @@ final class WPSC_Settings_Page {
378
 
379
  if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'submit_options' ) ) {
380
  check_admin_referer( 'update-options', 'wpsc-update-options' );
381
-
382
  $this->save_options();
383
  do_action( 'wpsc_save_' . $this->current_tab_id . '_settings', $this->current_tab );
384
-
385
  $query_args = array();
386
  if ( is_callable( array( $this->current_tab, 'callback_submit_options' ) ) ) {
387
  $additional_query_args = $this->current_tab->callback_submit_options();
@@ -445,6 +444,7 @@ final class WPSC_Settings_Page {
445
  */
446
  private function submit_url() {
447
  $location = add_query_arg( 'tab', $this->current_tab_id );
 
448
  return $location;
449
  }
450
 
@@ -476,14 +476,14 @@ final class WPSC_Settings_Page {
476
  <div id="options_<?php echo esc_attr( $this->current_tab_id ); ?>" class="tab-content">
477
  <?php
478
  if ( is_callable( array( $this->current_tab, 'display' ) ) ) {
 
479
  $this->current_tab->display();
 
480
  }
481
  ?>
482
 
483
  <?php do_action( 'wpsc_' . $this->current_tab_id . '_settings_page' ); ?>
484
  <div class="submit">
485
- <input type='hidden' name='wpsc_admin_action' value='submit_options' />
486
- <?php wp_nonce_field( 'update-options', 'wpsc-update-options' ); ?>
487
  <?php if ( $this->current_tab->is_submit_button_displayed() ): ?>
488
  <?php submit_button( __( 'Save Changes' ) ); ?>
489
  <?php endif ?>
@@ -706,3 +706,12 @@ final class WPSC_Settings_Page {
706
  }
707
 
708
  WPSC_Settings_Page::init();
 
 
 
 
 
 
 
 
 
203
  public static function init() {
204
  self::$default_tabs = array(
205
  'general' => _x( 'General' , 'General settings tab in Settings->Store page' , 'wpsc' ),
 
206
  'admin' => _x( 'Admin' , 'Admin settings tab in Settings->Store page' , 'wpsc' ),
207
  'taxes' => _x( 'Taxes' , 'Taxes settings tab in Settings->Store page' , 'wpsc' ),
208
  'shipping' => _x( 'Shipping' , 'Shipping settings tab in Settings->Store page' , 'wpsc' ),
377
 
378
  if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'submit_options' ) ) {
379
  check_admin_referer( 'update-options', 'wpsc-update-options' );
380
+
381
  $this->save_options();
382
  do_action( 'wpsc_save_' . $this->current_tab_id . '_settings', $this->current_tab );
383
+
384
  $query_args = array();
385
  if ( is_callable( array( $this->current_tab, 'callback_submit_options' ) ) ) {
386
  $additional_query_args = $this->current_tab->callback_submit_options();
444
  */
445
  private function submit_url() {
446
  $location = add_query_arg( 'tab', $this->current_tab_id );
447
+ $location = apply_filters( 'wpsc_settings_page_submit_url', $location, $this, $this->current_tab );
448
  return $location;
449
  }
450
 
476
  <div id="options_<?php echo esc_attr( $this->current_tab_id ); ?>" class="tab-content">
477
  <?php
478
  if ( is_callable( array( $this->current_tab, 'display' ) ) ) {
479
+ do_action( 'wpsc_before_settings_tab', $this, $this->current_tab );
480
  $this->current_tab->display();
481
+ do_action( 'wpsc_after_settings_tab', $this, $this->current_tab );
482
  }
483
  ?>
484
 
485
  <?php do_action( 'wpsc_' . $this->current_tab_id . '_settings_page' ); ?>
486
  <div class="submit">
 
 
487
  <?php if ( $this->current_tab->is_submit_button_displayed() ): ?>
488
  <?php submit_button( __( 'Save Changes' ) ); ?>
489
  <?php endif ?>
706
  }
707
 
708
  WPSC_Settings_Page::init();
709
+
710
+ add_action( 'wpsc_after_settings_tab', '_wpsc_action_after_settings_tab' );
711
+
712
+ function _wpsc_action_after_settings_tab() {
713
+ ?>
714
+ <input type='hidden' name='wpsc_admin_action' value='submit_options' />
715
+ <?php
716
+ wp_nonce_field( 'update-options', 'wpsc-update-options' );
717
+ }
wpsc-admin/users.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'user_profile_update_errors', '_wpsc_action_user_update_errors', 10, 3 );
4
+
5
+ function _wpsc_action_user_update_errors( $errors, $update, $user ) {
6
+ if ( $user->role == 'wpsc_anonymous' )
7
+ unset( $errors->errors['empty_email'] );
8
+ }
wpsc-components/marketplace-core-v1/library/Sputnik.php ADDED
@@ -0,0 +1,597 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Main class
4
+ *
5
+ * @package Sputnik
6
+ * @subpackage Public API
7
+ */
8
+
9
+ /**
10
+ * Main class
11
+ *
12
+ * @package Sputnik
13
+ * @subpackage Public API
14
+ */
15
+ class Sputnik {
16
+ /**
17
+ * Minimum version of WordPress that Sputnik requires
18
+ */
19
+ const MINVERSION = '3.2';
20
+
21
+ /**
22
+ * Base URI for store URLs
23
+ */
24
+ const SITE_BASE = 'http://www.wpeconomy.org';
25
+
26
+ /**
27
+ * Base URI for API URLs
28
+ */
29
+ const API_BASE = 'http://api.wpeconomy.org';
30
+
31
+ /**
32
+ * OAuth client key
33
+ */
34
+ const OAUTH_KEY = '2lOEJMYjLho3';
35
+
36
+ /**
37
+ * OAuth client secret
38
+ *
39
+ * Not so secret any more.
40
+ */
41
+ const OAUTH_SECRET = 'mPGuYG1DTt3DuoQtpimidEusg9WhoxRxJaXozkYVmf7q1QwM';
42
+
43
+ /**
44
+ * Path to Sputnik
45
+ * @var string
46
+ */
47
+ public static $path = '';
48
+
49
+ /**
50
+ * Cache of purchased plugins API data
51
+ */
52
+ protected static $purchased = false;
53
+
54
+ /**
55
+ * Installed plugin IDs
56
+ */
57
+ protected static $installed = array();
58
+
59
+ /**
60
+ * Enabled plugins which haven't been purchased
61
+ */
62
+ protected static $invalid = array();
63
+
64
+ /**
65
+ * Plugins which have been suspended remotely
66
+ */
67
+ protected static $suspended = array();
68
+
69
+ /**
70
+ * Register everything we need
71
+ */
72
+ public static function bootstrap() {
73
+
74
+ spl_autoload_register(array(get_class(), 'autoload'));
75
+
76
+ self::$installed = get_option('sputnik_installed', array());
77
+ self::$suspended = get_option('sputnik_suspended', array());
78
+
79
+ //add_action('activated_plugin', array(get_class(), 'clear_installed'));
80
+ //add_action('deactivated_plugin', array(get_class(), 'clear_installed'));
81
+
82
+ // 'deactivated_plugin' runs before saving, so we have to do this instead:
83
+ add_action('update_option_active_plugins', array(get_class(), 'clear_installed'));
84
+
85
+ add_action( 'plugins_loaded', array(get_class(), 'loaded'));
86
+ add_action( 'init', array(get_class(), 'init'));
87
+ add_action( 'init', array( get_class(), 'check_for_saas_push' ) );
88
+ add_action( 'init', array( get_class(), 'thumbnails' ) );
89
+ add_action( 'init', array( get_class(), 'credentials' ) );
90
+ add_action( 'wp', array( get_class(), 'show_login_form' ) );
91
+ add_filter( 'extra_plugin_headers', array(get_class(), 'extra_headers'));
92
+ add_filter( 'extra_theme_headers', array(get_class(), 'extra_headers'));
93
+
94
+ add_action( 'wpsc_update_purchase_log_status', array( get_class(), 'push_sales_data' ), 10, 4 );
95
+ add_action( 'init', array( get_class(), 'sales_data_postback' ) );
96
+
97
+ add_filter( 'wpsc_purchase_log_customer_notification_raw_message', array( get_class(), 'add_download_link' ), 10, 2 );
98
+ add_action( 'wpsc_transaction_results_shutdown' , array( get_class(), 'add_download_link_page' ), 10, 3 );
99
+
100
+ Sputnik_Admin::bootstrap();
101
+ Sputnik_Updater::bootstrap();
102
+ Sputnik_Pointers::bootstrap();
103
+ }
104
+
105
+ public static function add_download_link( $message, $notification ) {
106
+ $cart_contents = $notification->get_purchase_log()->get_cart_contents();
107
+
108
+ $products = '';
109
+
110
+ foreach ( $cart_contents as $product ) {
111
+ $download_link = get_post_meta( $product->prodid, '_download_url', true );
112
+ $download_link = esc_url( add_query_arg( 'marketplace', Sputnik_API::domain(), $download_link ) );
113
+ $products .= "\n" . '<a href="' . $download_link . '">Download ' . $product->name . '</a>' . "\n";
114
+ }
115
+
116
+ return $message . $products;
117
+ }
118
+
119
+ public static function show_login_form() {
120
+ if ( ! isset( $_GET['marketplace'] ) )
121
+ return;
122
+
123
+ $url = 'http://www.wpeconomy.org/products-page/add/?framed=true&marketplace=' . urlencode( esc_url_raw( Sputnik_API::domain() ) );
124
+
125
+ $auth = Sputnik_API::auth_request( $url, false );
126
+ ?>
127
+ <html>
128
+ <head>
129
+ <script type="text/javascript" src="<?php echo home_url( $GLOBALS['wp_scripts']->registered['jquery']->src ); ?>"></script>
130
+ <script type="text/javascript">
131
+ jQuery(window).load(function() {
132
+ jQuery( '#add_form' ).load( '<?php echo esc_url( $auth ); ?>' );
133
+ });
134
+ </script>
135
+ </head>
136
+ <body>
137
+ <div id="add_form"></div>
138
+ </body>
139
+ </html>
140
+ <?php
141
+ die;
142
+ }
143
+
144
+ public function add_download_link_page( $purchase_log_object, $sessionid, $display_to_screen ) {
145
+ if ( ! $display_to_screen )
146
+ return;
147
+
148
+ $cart_contents = $purchase_log_object->get_cart_contents();
149
+
150
+ $products = '';
151
+
152
+ foreach ( $cart_contents as $product ) {
153
+ $download_link = get_post_meta( $product->prodid, '_download_url', true );
154
+ $download_link = esc_url( add_query_arg( 'marketplace', Sputnik_API::domain(), $download_link ) );
155
+ $products .= "\n" . '<a href="' . $download_link . '">Download ' . $product->name . '</a>' . "\n";
156
+ }
157
+
158
+ echo $products;
159
+ }
160
+
161
+ /**
162
+ * Callback for 'plugins_loaded' action
163
+ */
164
+ public static function loaded() {
165
+ do_action('sputnik_loaded');
166
+ }
167
+
168
+ /**
169
+ * Callback for 'init' action
170
+ */
171
+ public static function init() {
172
+ do_action('sputnik_init');
173
+ }
174
+
175
+ public static function thumbnails() {
176
+ if ( ! isset( $_REQUEST['thumbnails'] ) || ( isset( $_REQUEST['thumbnails'] ) && 'true' !== $_REQUEST['thumbnails'] ) )
177
+ return;
178
+
179
+ $thumbs = array( 'width' => get_option( 'product_image_width' ), 'height' => get_option( 'product_image_height' ) );
180
+
181
+ echo json_encode( $thumbs );
182
+ die;
183
+ }
184
+
185
+ public static function check_for_saas_push() {
186
+
187
+ if ( ! isset( $_REQUEST['json_product_push'] ) || ( isset( $_REQUEST['json_product_push'] ) && 'true' !== $_REQUEST['json_product_push'] ) )
188
+ return;
189
+
190
+ error_reporting( E_ERROR );
191
+
192
+ if ( ! empty( $_POST['product'] ) ) {
193
+ $product = stripslashes( $_POST['product'] );
194
+ $product = json_decode( $product );
195
+
196
+ $download_url = Sputnik::API_BASE . '/download/' . $product->post_name . '.zip';
197
+ $thumb_url = $product->thumbnail_url;
198
+
199
+ //Check if local product exists - if so, update it, if not, don't.
200
+ $local = get_posts( array(
201
+ 'pagename' => $product->post_name,
202
+ 'post_type' => 'wpsc-product',
203
+ 'post_status' => 'publish',
204
+ 'numberposts' => 1 )
205
+ );
206
+
207
+ $user_check = get_user_by( 'email', $product->author_email );
208
+
209
+ if ( $user_check ) {
210
+ $product->post_author = $user_check->ID;
211
+
212
+ if ( ! in_array( 'vendor-administrator', $user_check->roles ) )
213
+ $user_check->add_role( 'vendor-administrator' );
214
+ }
215
+ else {
216
+ $product->post_author = wp_insert_user( array( 'role' => 'vendor-administrator', 'user_email' => $product->author_email, 'user_pass' => wp_generate_password(), 'user_login' => $product->author_email ) );
217
+ }
218
+
219
+ $product = (array) $product;
220
+ unset( $product['guid'] );
221
+ unset( $product['post_date_gmt'] );
222
+ unset( $product['post_date'] );
223
+
224
+ require_once(ABSPATH . 'wp-admin/includes/media.php');
225
+ require_once(ABSPATH . 'wp-admin/includes/file.php');
226
+ require_once(ABSPATH . 'wp-admin/includes/image.php');
227
+
228
+ if ( ! empty( $local ) ) {
229
+ $product['ID'] = $local[0]->ID;
230
+ $new_id = wp_update_post( $product );
231
+ } else {
232
+ unset( $product['ID'] );
233
+ // Doesn't exist, create it. Then, after created, add download URL and thumbnail.
234
+ $new_id = wp_insert_post( $product );
235
+ }
236
+
237
+ update_post_meta( $new_id, '_download_url', $download_url );
238
+
239
+ foreach ( $product['meta'] as $key => $val ) {
240
+ if ( '_wpsc_product_metadata' == $key )
241
+ continue;
242
+
243
+ if ( '_wpsc_currency' == $key )
244
+ continue;
245
+
246
+ update_post_meta( $new_id, $key, $val[0] );
247
+ }
248
+
249
+
250
+
251
+ $thumb = media_sideload_image( $thumb_url, $new_id, 'Product Thumbnail' );
252
+
253
+ if ( ! is_wp_error( $thumb ) ) {
254
+ $thumbnail_id = get_posts( array( 'post_type' => 'attachment', 'post_parent' => $new_id ) );
255
+
256
+ if ( ! empty( $thumbnail_id ) ) {
257
+
258
+ $thumbnail = set_post_thumbnail( $new_id, $thumbnail_id[0]->ID );
259
+ echo json_encode( array( 'set_thumbnail' => $thumbnail, 'post_id' => $new_id ) );
260
+ die;
261
+ }
262
+ die;
263
+ }
264
+ die;
265
+ }
266
+
267
+ exit;
268
+ }
269
+
270
+ public static function credentials() {
271
+
272
+ if ( ! isset( $_REQUEST['credential_request'] ) || ( isset( $_REQUEST['credential_request'] ) && 'true' !== $_REQUEST['credential_request'] ) )
273
+ return;
274
+
275
+ if ( ! isset( $_SERVER['HTTP_X_CREDENTIALS_REQUEST'] ) )
276
+ return;
277
+
278
+ die( json_encode( get_option( 'wpsc_payment_gateway_paypal_digital_goods' ) ) );
279
+
280
+ }
281
+
282
+ /**
283
+ * Pushes sales data back to Baikonur
284
+ *
285
+ * Only pushes once. Accounts for annoying potential edge case of status-switching admins
286
+ *
287
+ * @param WPSC_Purchase_Log object $purchase_log Purchase Log object
288
+ * @return void
289
+ */
290
+ public static function push_sales_data( $purchase_log_id, $current_status, $old_status, $purchase_log ) {
291
+
292
+ $purchase_log = new WPSC_Purchase_Log( $purchase_log_id );
293
+
294
+ $id = absint( $purchase_log->get( 'id' ) );
295
+
296
+ //Also checking is_order_received, as that's what Manual Payments do.
297
+ if ( $purchase_log->is_transaction_completed() || $purchase_log->is_order_received() ) {
298
+
299
+ $pushed_to_sass = wpsc_get_meta( $id, '_pushed_to_wpeconomy', 'purchase_log' );
300
+
301
+ if ( empty( $pushed_to_saas ) ) {
302
+
303
+ $data = $purchase_log->get_data();
304
+ $cart_contents = $purchase_log->get_cart_contents();
305
+
306
+ //We want to push sales data - but naturally, IDs will differ, even names could potentially.
307
+ //So we add the slug to the object we POST
308
+ foreach ( $cart_contents as $key => $cart_item ) {
309
+ $slug = get_post_field( 'post_name', $cart_item->prodid );
310
+ $cart_contents[ $key ]->slug = $slug;
311
+ }
312
+
313
+ $args = array(
314
+ 'body' => array( 'data' => json_encode( $data ), 'cart_contents' => json_encode( $cart_contents ) )
315
+ );
316
+
317
+ $request = wp_remote_post( 'http://www.wpeconomy.org/?sales_data=true', $args );
318
+ $response = wp_remote_retrieve_response_code( $request );
319
+
320
+ //For some reason, if the site is down, we want the ability to ensure we can grab the sale later.
321
+ $success = ( 200 === $response );
322
+
323
+ wpsc_update_meta( $id, '_pushed_to_wpeconomy', $success, 'purchase_log' );
324
+ }
325
+ }
326
+ }
327
+
328
+ public static function sales_data_postback() {
329
+ if ( ! isset( $_REQUEST['sales_data'] ) )
330
+ return;
331
+
332
+ $data = json_decode( stripslashes( $_POST['data'] ) );
333
+ $cart_contents = json_decode( stripslashes( $_POST['cart_contents'] ) );
334
+
335
+ //Unset purchase log ID, since we're inserting a new one.
336
+ $data = ( array ) $data;
337
+
338
+ unset( $data['id'] );
339
+
340
+ $purchase_log = new WPSC_Purchase_Log( $data );
341
+ $purchase_log->save();
342
+ $purchase_log_id = $purchase_log->get( 'id' );
343
+
344
+ global $wpdb;
345
+
346
+ //We need to update the proper product ID, name and purchase ID
347
+ foreach ( $cart_contents as $cart_item ) {
348
+
349
+ $product = new WP_Query( array( 'post_type' => 'wpsc-product', 'pagename' => $cart_item->slug ) );
350
+ $product = $product->get_posts();
351
+ $product = $product[0];
352
+
353
+ $cart_item = ( array ) $cart_item;
354
+
355
+ unset( $cart_item['id'] );
356
+ unset( $cart_item['slug'] );
357
+
358
+ $cart_item['prodid'] = $product->ID;
359
+ $cart_item['name'] = $product->post_title;
360
+ $cart_item['purchaseid'] = $purchase_log_id;
361
+
362
+ $wpdb->insert( WPSC_TABLE_CART_CONTENTS, $cart_item );
363
+ }
364
+
365
+ die;
366
+ }
367
+
368
+
369
+ /**
370
+ * Register our extra plugin metadata headers
371
+ */
372
+ public static function extra_headers($headers) {
373
+ $headers[] = 'Sputnik ID';
374
+ $headers[] = 'Requires WPEC Version';
375
+ $headers[] = 'Compatible to WPEC Version';
376
+ return $headers;
377
+ }
378
+
379
+ /**
380
+ * Autoload a Sputnik class
381
+ *
382
+ * @param string $class
383
+ */
384
+ public static function autoload($class) {
385
+ if (strpos($class, 'Sputnik') !== 0) {
386
+ return;
387
+ }
388
+
389
+ $file = str_replace('_', '/', $class);
390
+ if (file_exists(self::$path . '/library/' . $file . '.php')) {
391
+ require_once(self::$path . '/library/' . $file . '.php');
392
+ }
393
+ }
394
+
395
+ /**
396
+ * Get available modules
397
+ *
398
+ * @return array Available plugins (array of meta objects)
399
+ */
400
+ public static function get_available() {
401
+ $plugins = Sputnik_API::get_all();
402
+ return $plugins['body'];
403
+ }
404
+
405
+ /**
406
+ * Get popular tags
407
+ *
408
+ * @return array
409
+ */
410
+ public static function get_tags() {
411
+ $tags = Sputnik_API::get_tags();
412
+ return $tags['body'];
413
+ }
414
+
415
+ /**
416
+ * Return whether an account is linked to Sputnik
417
+ *
418
+ * @return bool
419
+ */
420
+ public static function account_is_linked() {
421
+ $token = get_option('sputnik_oauth_access', false);
422
+ return (is_array($token) && !empty($token['oauth_token']));
423
+ }
424
+
425
+ /**
426
+ * Get account information
427
+ *
428
+ * @return stdObject
429
+ */
430
+ public static function get_account() {
431
+ $account = get_transient('sputnik_account');
432
+ if ($account === false) {
433
+ $account = Sputnik_API::get_account();
434
+ $account = $account['body'];
435
+ set_transient('sputnik_account', $account, 3600);
436
+ }
437
+
438
+ return $account;
439
+ }
440
+
441
+ /**
442
+ * Forces an update to the account information from the server
443
+ *
444
+ * @return stdObject
445
+ */
446
+ public static function update_account() {
447
+ delete_transient( 'sputnik_account' );
448
+
449
+ $account = Sputnik_API::get_account();
450
+
451
+ set_transient( 'sputnik_account', $account['body'], 60*60*12 );
452
+
453
+ return $account['body'];
454
+ }
455
+
456
+ /**
457
+ * Get purchased plugins
458
+ *
459
+ * @return array Plugin slugs
460
+ */
461
+ public static function get_purchased() {
462
+ // This should be cached in a transient
463
+ if (self::$purchased === false) {
464
+ $purchased = Sputnik_API::get_purchased();
465
+ self::$purchased = $purchased['body'];
466
+ }
467
+ return self::$purchased;
468
+ }
469
+
470
+ /**
471
+ * Check if a plugin has been purchased
472
+ *
473
+ * @param string $plugin Plugin slug
474
+ * @return boolean
475
+ */
476
+ public static function is_purchased($plugin) {
477
+ if (is_object($plugin)) {
478
+ $plugin = $plugin->slug;
479
+ }
480
+
481
+ try {
482
+ $account = self::get_account();
483
+ return in_array($plugin, (array) $account->purchased);
484
+ }
485
+ catch (Exception $e) {
486
+ return false;
487
+ }
488
+ }
489
+
490
+ /**
491
+ * Check if a plugin has been suspended
492
+ *
493
+ * @param string $plugin Plugin slug
494
+ * @return boolean
495
+ */
496
+ public static function is_suspended($plugin) {
497
+ if (is_object($plugin)) {
498
+ $plugin = $plugin->slug;
499
+ }
500
+
501
+ return array_key_exists($plugin, self::$suspended);
502
+ }
503
+
504
+ /**
505
+ * Suspend a plugin
506
+ *
507
+ * For internal use by {@see Sputnik_Updater} only
508
+ * @param string $plugin Plugin slug
509
+ */
510
+ public static function suspend_plugin($plugin, $file, $data) {
511
+ // Check that the updater was the one that issued the command
512
+ if (!Sputnik_Updater::confirm_suspend($plugin, $data)) {
513
+ return false;
514
+ }
515
+
516
+ self::$suspended[$plugin] = $data;
517
+ deactivate_plugins(array($file), true);
518
+ update_option('sputnik_suspended', self::$suspended);
519
+ return true;
520
+ }
521
+
522
+ /**
523
+ * Get a single module
524
+ *
525
+ * @param string $id
526
+ * @return stdObject
527
+ */
528
+ public static function get_plugin($id, $user = 0) {
529
+ $plugin = Sputnik_API::get_single($id, $user);
530
+ return $plugin['body'];
531
+ }
532
+
533
+ public static function get_from_file($file) {
534
+ if (empty(self::$installed)) {
535
+ self::$installed = self::load_installed();
536
+ }
537
+
538
+ if (!empty(self::$installed[$file])) {
539
+ return self::$installed[$file];
540
+ }
541
+
542
+ return null;
543
+ }
544
+
545
+ public static function check($file, $callback = null) {
546
+ $file = plugin_basename($file);
547
+
548
+ $plugin = self::get_from_file($file);
549
+
550
+ if (!self::is_purchased($plugin['Sputnik ID'])) {
551
+ $plugin['sputnik_error'] = 'not_purchased';
552
+ self::$invalid[] = $plugin;
553
+ return false;
554
+ }
555
+
556
+ if ($callback !== null) {
557
+ call_user_func($callback);
558
+ }
559
+ return true;
560
+ }
561
+
562
+ public static function get_installed($force = false) {
563
+ if (empty(self::$installed) || $force === true) {
564
+ self::$installed = self::load_installed();
565
+ }
566
+
567
+ return self::$installed;
568
+ }
569
+
570
+ protected static function load_installed() {
571
+ if (!function_exists('get_plugins')) {
572
+ require_once(ABSPATH . 'wp-admin/includes/plugin.php');
573
+ }
574
+
575
+ $all = get_plugins();
576
+ $plugins = array();
577
+ foreach ($all as $file => $plugin) {
578
+ if (empty($plugin['Sputnik ID'])) {
579
+ continue;
580
+ }
581
+ $plugins[$file] = $plugin;
582
+ }
583
+
584
+ update_option('sputnik_installed', $plugins);
585
+
586
+ return $plugins;
587
+ }
588
+
589
+ public static function clear_installed() {
590
+ delete_option('sputnik_installed');
591
+ self::$installed = self::load_installed();
592
+ }
593
+
594
+ public static function get_invalid() {
595
+ return self::$invalid;
596
+ }
597
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/API.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_API {
4
+ /**
5
+ * @var Sputnik_API_Auth
6
+ */
7
+ protected static $auth = null;
8
+
9
+ /**
10
+ * For sites like GetShopped that will distribute Sputnik with a plugin to sell WP plugins,
11
+ * we override the domain. This is because we need to ensure Baikonur receives the Saas domain,
12
+ * not the end-user domain. Only relevant where Sputnik is available to an end-user, not a Saas.
13
+ */
14
+ protected static $domain_override = 'http://getshopped.org';
15
+
16
+ public static function get_all($page = 1, $params = null) {
17
+ $url = '/';
18
+ if ($page !== 1) {
19
+ $url = sprintf('/page/%d', $page);
20
+ }
21
+
22
+ return self::request($url, $params);
23
+ }
24
+
25
+ public static function search($query, $page = 1) {
26
+ $url = '/search';
27
+ if ($page !== 1) {
28
+ $url = sprintf('/search/page/%d', $page);
29
+ }
30
+ $params = array(
31
+ 'query' => $query
32
+ );
33
+
34
+ return self::request($url, $params);
35
+ }
36
+
37
+ public static function get_single($name, $user = 0) {
38
+ $params = array(
39
+ 'name' => $name
40
+ );
41
+ if ($user !== 0) {
42
+ $params['user'] = $user;
43
+ }
44
+
45
+ return self::request('/info', $params);
46
+ }
47
+
48
+ public static function rate_product($name, $rating) {
49
+ self::authenticate();
50
+
51
+ $url = sprintf('/info/%s/rate', $name);
52
+ $parameters = array('rating' => (int) $rating);
53
+ $auth_header = self::$auth->get_auth_header($url, 'POST', $parameters);
54
+ $options = array(
55
+ 'method' => 'POST',
56
+ 'headers' => array(
57
+ 'Authorization' => $auth_header
58
+ )
59
+ );
60
+ return self::request($url, $parameters, $options);
61
+ }
62
+
63
+ public static function get_tags() {
64
+ return self::request('/tags');
65
+ }
66
+
67
+ protected static function authenticate() {
68
+ $token = get_option('sputnik_oauth_access', false);
69
+
70
+ if ($token == false) {
71
+ throw new Exception('Need to authenticate first', 1);
72
+ }
73
+ self::$auth = new Sputnik_API_Auth(Sputnik::OAUTH_KEY, Sputnik::OAUTH_SECRET, $token['oauth_token'], $token['oauth_token_secret']);
74
+ }
75
+
76
+ public static function auth_request( $callback = '', $redirect = true ) {
77
+ self::$auth = new Sputnik_API_Auth( Sputnik::OAUTH_KEY, Sputnik::OAUTH_SECRET);
78
+ $callback_url = empty( $callback ) ? Sputnik_Admin::build_url( array( 'oauth' => 'callback' ) ) : $callback;
79
+ $token = self::$auth->get_request_token( $callback_url );
80
+
81
+ update_option( 'sputnik_oauth_request', $token );
82
+
83
+ $auth_url = self::$auth->get_authorize_url( $token );
84
+
85
+ //Modifying to add marketplace and user email to query string.
86
+ if ( $redirect ) {
87
+ wp_redirect( add_query_arg( array( 'domain' => self::domain(), 'user' => rawurlencode( wp_get_current_user()->user_email ) ), $auth_url ) );
88
+ exit;
89
+ } else {
90
+ return $auth_url;
91
+ }
92
+ }
93
+
94
+ public static function auth_access() {
95
+
96
+ if( isset( $_REQUEST['denied'] ) ) {
97
+
98
+ $return_url = Sputnik_Admin::build_url( array( 'auth' => 'denied' ) );
99
+
100
+ } else {
101
+ $request = get_option('sputnik_oauth_request', false);
102
+
103
+ self::$auth = new Sputnik_API_Auth(Sputnik::OAUTH_KEY, Sputnik::OAUTH_SECRET, $request['oauth_token'], $request['oauth_token_secret']);
104
+ $access = self::$auth->get_access_token($_REQUEST['oauth_verifier']);
105
+
106
+ update_option('sputnik_oauth_access', $access);
107
+
108
+ $args = array();
109
+ if ( ! empty( $_REQUEST['oauth_buy'] ) )
110
+ $args['oauth_buy'] = $_REQUEST['oauth_buy'];
111
+ $return_url = Sputnik_Admin::build_url( $args );
112
+ }
113
+
114
+ delete_option('sputnik_oauth_request');
115
+
116
+ // Close the authentication popup ?>
117
+ <!DOCTYPE html><html>
118
+ <head>
119
+ <title><?php _e( 'Redirecting ...', 'wpsc' ); ?></title>
120
+ <script type="text/javascript">
121
+ parent.location = '<?php echo $return_url; ?>';
122
+ window.close();
123
+ </script>
124
+ </head>
125
+ <body>&nbsp;</body>
126
+ </html><?php
127
+ die();
128
+ }
129
+
130
+ public static function get_account() {
131
+ self::authenticate();
132
+
133
+ $url = '/account';
134
+ $request = self::$auth->sign($url);
135
+ return self::request($request->to_url());
136
+ }
137
+
138
+ public static function get_purchased() {
139
+ self::authenticate();
140
+
141
+ $url = '/account/purchased';
142
+ $request = self::$auth->sign($url);
143
+ return self::request($request->to_url());
144
+ }
145
+
146
+ public static function get_own() {
147
+ self::authenticate();
148
+
149
+ $url = '/account/myplugins';
150
+ $request = self::$auth->sign($url);
151
+ return self::request($request->to_url());
152
+ }
153
+
154
+ public static function sign_download(&$url, &$args) {
155
+ self::authenticate();
156
+
157
+ if (!isset($args['headers'])) {
158
+ $args['headers'] = array();
159
+ }
160
+
161
+ $oauth = self::$auth->sign($url);
162
+
163
+ $url = $oauth->to_url();
164
+ }
165
+
166
+ public static function get_auth_for_download($url) {
167
+ self::authenticate();
168
+
169
+ return self::$auth->get_auth_header($url);
170
+ }
171
+
172
+ /* Purchase Methods */
173
+
174
+ public static function get_checkout_token( $product_slug ) {
175
+ self::authenticate();
176
+
177
+ $url = '/purchase/get_checkout_token';
178
+
179
+ $request = self::$auth->sign( $url, 'GET', array(
180
+ 'product_slug' => $product_slug,
181
+ 'redirect_uri' => Sputnik_Admin::build_url( array( '_wpnonce' => wp_create_nonce( 'sputnik_install-plugin_' . $product_slug ) ) )
182
+ )
183
+ );
184
+
185
+ $response = self::request( $request->to_url(), array(), array( 'timeout' => 25 ) );
186
+
187
+ return $response;
188
+ }
189
+
190
+
191
+ /* Helper Methods */
192
+
193
+ public static function request($url, $params = null, $args = array()) {
194
+ if ( ! empty( $params ) )
195
+ $url = add_query_arg( $params, $url );
196
+
197
+ $defaults = array('method' => 'GET');
198
+ $args = wp_parse_args($args, $defaults);
199
+
200
+ if (strpos($url, 'http') !== 0) {
201
+ $url = Sputnik::API_BASE . $url;
202
+ }
203
+
204
+ $args['timeout'] = 25;
205
+
206
+ $args['headers']['X-WP-Domain'] = self::domain();
207
+
208
+ $request = wp_remote_request( $url, $args );
209
+
210
+ if (is_wp_error($request)) {
211
+ throw new Exception($request->get_error_message());
212
+ }
213
+
214
+ if ($request['response']['code'] !== 200) {
215
+ throw new Exception($request['body'], $request['response']['code']);
216
+ }
217
+
218
+ $result = json_decode($request['body']);
219
+ if ($result === null) {
220
+ throw new Exception($request['body'], $request['response']['code']);
221
+ }
222
+ $request['body'] = $result;
223
+
224
+ return $request;
225
+ }
226
+
227
+ public static function domain() {
228
+ $wp_install = home_url( '/' );
229
+
230
+ if ( is_multisite() )
231
+ $wp_install = network_site_url( '/' );
232
+
233
+ if ( ! empty( self::$domain_override ) )
234
+ $wp_install = self::$domain_override;
235
+
236
+ return $wp_install;
237
+ }
238
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/API/Auth.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Sputnik OAuth class
5
+ */
6
+ class Sputnik_API_Auth {
7
+ public function __construct($key, $secret, $token = null, $token_secret = null) {
8
+ $this->sha1_method = new Sputnik_OAuth_SignatureMethod_HMAC_SHA1();
9
+ $this->consumer = new Sputnik_OAuth_Consumer($key, $secret);
10
+ if (!empty($token) && !empty($token_secret)) {
11
+ $this->token = new Sputnik_OAuth_Consumer($token, $token_secret);
12
+ } else {
13
+ $this->token = NULL;
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Get a request_token from Twitter
19
+ *
20
+ * @return array A key/value array containing oauth_token and oauth_token_secret
21
+ */
22
+ public function get_request_token($callback = null) {
23
+ $parameters = array();
24
+ if (!empty($callback)) {
25
+ $parameters['oauth_callback'] = $callback;
26
+ }
27
+ $request = $this->request('/auth/request_token', 'GET', $parameters);
28
+ $token = Sputnik_OAuth_Util::parse_parameters($request);
29
+ $this->token = new Sputnik_OAuth_Consumer($token['oauth_token'], $token['oauth_token_secret']);
30
+ return $token;
31
+ }
32
+
33
+ /**
34
+ * Get the authorize URL
35
+ *
36
+ * @return string
37
+ */
38
+ public function get_authorize_url($token) {
39
+ if (is_array($token)) {
40
+ $token = $token['oauth_token'];
41
+ }
42
+ return Sputnik::SITE_BASE . "/oauth/authorize?oauth_token={$token}";
43
+ }
44
+
45
+ /**
46
+ * Exchange request token and secret for an access token and
47
+ * secret, to sign API calls.
48
+ *
49
+ * @return array("oauth_token" => "the-access-token",
50
+ * "oauth_token_secret" => "the-access-secret",
51
+ * "user_id" => "9436992",
52
+ * "screen_name" => "abraham")
53
+ */
54
+ public function get_access_token($verifier = false) {
55
+ $parameters = array();
56
+ if (!empty($verifier)) {
57
+ $parameters['oauth_verifier'] = $verifier;
58
+ }
59
+ $request = $this->request('/auth/access_token', 'GET', $parameters);
60
+ $token = Sputnik_OAuth_Util::parse_parameters($request);
61
+ $this->token = new Sputnik_OAuth_Consumer($token['oauth_token'], $token['oauth_token_secret']);
62
+ return $token;
63
+ }
64
+
65
+ /**
66
+ * Format and sign an OAuth / API request
67
+ */
68
+ public function sign($url, $method = 'GET', $parameters = array()) {
69
+ if (strpos($url, 'http') !== 0) {
70
+ $url = Sputnik::API_BASE . $url;
71
+ }
72
+ $request = Sputnik_OAuth_Request::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
73
+ $request->sign_request($this->sha1_method, $this->consumer, $this->token);
74
+ return $request;
75
+ }
76
+
77
+ /**
78
+ * Format and sign an OAuth / API request
79
+ */
80
+ public function get_auth_header($url, $method = 'GET', $parameters = array()) {
81
+ if (strpos($url, 'http') !== 0) {
82
+ $url = Sputnik::API_BASE . $url;
83
+ }
84
+ $request = Sputnik_OAuth_Request::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
85
+ $request->sign_request($this->sha1_method, $this->consumer, $this->token);
86
+ $header = $request->to_header($this->sha1_method, $this->consumer, $this->token);
87
+
88
+ // We want to remove the 'Authorization' bit from the start
89
+ return substr($header, 15);
90
+ }
91
+
92
+ /**
93
+ * Format and sign an OAuth / API request, and execute it
94
+ */
95
+ public function request($url, $method, $parameters) {
96
+ $request = $this->sign($url, $method, $parameters);
97
+
98
+ switch ($method) {
99
+ case 'GET':
100
+ return $this->http($request->to_url(), 'GET');
101
+ default:
102
+ return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
103
+ }
104
+ }
105
+
106
+ protected function http($url, $method, $postfields = NULL) {
107
+ $args = array(
108
+ 'method' => $method,
109
+ );
110
+
111
+ switch ($method) {
112
+ case 'POST':
113
+ if (!empty($postfields)) {
114
+ $args['body'] = $postfields;
115
+ }
116
+ break;
117
+ }
118
+
119
+ $response = wp_remote_request($url, $args);
120
+ //echo '<pre />' . debug_print_backtrace();
121
+ //echo '<pre />' . print_r( $url, 1 );
122
+ //echo '<pre />' . print_r( $response, 1 );
123
+
124
+ if (is_wp_error($response)) {
125
+ throw new Exception($response->get_error_message());
126
+ }
127
+
128
+ if ($response['response']['code'] !== 200) {
129
+ throw new Exception($response['body']);
130
+ }
131
+ return $response['body'];
132
+ }
133
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Admin.php ADDED
@@ -0,0 +1,973 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_Admin {
4
+ protected static $page_is_current = false;
5
+ protected static $list_table;
6
+
7
+ protected static $page = 'dash';
8
+
9
+ public static function bootstrap() {
10
+ add_action( 'admin_init', array(__CLASS__, 'init'), 0);
11
+ add_action( 'all_admin_notices', array(__CLASS__, 'report_errors'));
12
+
13
+ add_action( 'admin_menu', array(__CLASS__, 'menu'));
14
+
15
+ add_action( 'admin_head-wpsc-product_page_sputnik', array(__CLASS__, 'admin_head_page'));
16
+ add_action( 'admin_head-wpsc-product_page_sputnik-account', array(__CLASS__, 'admin_head_page'));
17
+ add_action( 'install_plugins_pre_plugin-information', array(__CLASS__, 'maybe_info'), 0);
18
+ add_action( 'load-update.php', array(__CLASS__, 'maybe_redirect_update'));
19
+ add_filter( 'plugin_row_meta', array(__CLASS__, 'add_row_note'), 10, 3);
20
+ add_action( 'wp_ajax_sputnik_rate', array(__CLASS__, 'set_rating'));
21
+ }
22
+
23
+ public static function init() {
24
+ add_action('admin_print_styles', array(__CLASS__, 'styles'));
25
+ add_action('admin_print_scripts', array(__CLASS__, 'scripts'));
26
+
27
+ global $plugin_page;
28
+
29
+ if ( $plugin_page !== 'sputnik' && $plugin_page !== 'sputnik-account' )
30
+ return;
31
+
32
+ // Run most OAuth stuff now, before output
33
+ if (!empty($_GET['oauth'])) {
34
+ if ($_GET['oauth'] == 'request') {
35
+ $redirect_url = '';
36
+ if ( ! empty( $_REQUEST['oauth_buy'] ) ) {
37
+ $redirect_url = self::build_url( array( 'oauth' => 'callback' ) );
38
+ $redirect_url = add_query_arg( 'oauth_buy', $_REQUEST['oauth_buy'], $redirect_url );
39
+ }
40
+ Sputnik_API::auth_request( $redirect_url );
41
+ }
42
+ if ($_GET['oauth'] == 'callback') {
43
+ Sputnik_API::auth_access();
44
+ }
45
+ if ($_GET['oauth'] == 'reset') {
46
+ delete_option('sputnik_oauth_request');
47
+ delete_option('sputnik_oauth_access');
48
+ delete_transient('sputnik_account');
49
+
50
+ wp_redirect(self::build_url());
51
+ }
52
+ }
53
+
54
+ switch (true) {
55
+ case isset($_GET['info']):
56
+ self::$page = 'info';
57
+ break;
58
+ case isset($_GET['buy']):
59
+ self::$page = 'buy';
60
+ break;
61
+ case isset($_GET['paid']):
62
+ self::$page = 'paid';
63
+ break;
64
+ case isset($_GET['install']):
65
+ self::$page = 'install';
66
+ break;
67
+ case isset($_GET['upgrade']):
68
+ self::$page = 'upgrade';
69
+ break;
70
+ case isset($_GET['cancel_payment']):
71
+ self::$page = 'cancel_payment';
72
+ break;
73
+ case $plugin_page === 'wpsc-product_page_sputnik-account':
74
+ self::$page = 'account';
75
+ $GLOBALS['tab'] = 'account';
76
+ break;
77
+ default:
78
+ self::$page = 'dash';
79
+ break;
80
+ }
81
+
82
+ // Avoid having to specify this for every page
83
+ if (self::$page !== 'dash' && self::$page !== 'account') {
84
+ $_GET['noheader'] = true;
85
+ }
86
+ }
87
+
88
+ public static function report_errors() {
89
+ $invalid = Sputnik::get_invalid();
90
+ if (empty($invalid)) {
91
+ return;
92
+ }
93
+ ?>
94
+ <div class="error"><p><?php _e('The following plugins are disabled:', 'sputnik') ?></p>
95
+ <ul>
96
+ <?php
97
+ foreach ($invalid as $plugin) {
98
+ if (empty($plugin['sputnik_error'])) {
99
+ $plugin['sputnik_error'] = 'unknown';
100
+ }
101
+ switch ($plugin['sputnik_error']) {
102
+ case 'not_purchased':
103
+ $error = __('Not purchased', 'sputnik');
104
+ break;
105
+ default:
106
+ $error = __('Unknown error', 'sputnik');
107
+ break;
108
+ }
109
+ ?>
110
+ <li><?php echo esc_html($plugin['Name']) ?> &mdash; <?php echo $error ?></li>
111
+ <?php
112
+ }
113
+ ?>
114
+ </ul>
115
+ </div>
116
+ <?php
117
+ }
118
+
119
+ /**
120
+ * Adds a note to all plugins handled by us on the plugin screen
121
+ */
122
+ public static function add_row_note($meta, $file, $data) {
123
+ if (empty($data['Sputnik ID'])) {
124
+ return $meta;
125
+ }
126
+ echo '<a class="sputnik-plugin-row-note" href="' . self::build_url() . '"><span class="powered">' . __('Powered by WPEConomy', 'sputnik') . '</span><span class="corner"></span></a>';
127
+ return $meta;
128
+ }
129
+
130
+ public static function admin_head_page() {
131
+ if (self::$page === 'dash') {
132
+ self::$list_table = new Sputnik_List_Install();
133
+ $pagenum = self::$list_table->get_pagenum();
134
+ self::$list_table->prepare_items();
135
+ }
136
+ elseif (self::$page === 'account') {
137
+ self::$list_table = new Sputnik_List_Account();
138
+ $pagenum = self::$list_table->get_pagenum();
139
+ self::$list_table->prepare_items();
140
+ }
141
+
142
+ add_action('sputnik_messages', array(__CLASS__, 'admin_notices'));
143
+ }
144
+
145
+ public static function load_page() {
146
+ //Sputnik_API::auth_or_redirect();
147
+ }
148
+
149
+ public static function styles() {
150
+ wp_enqueue_style('sputnik', plugins_url( 'static/sputnik.css', Sputnik::$path . '/wpsc-marketplace' ), false, '20110924');
151
+ }
152
+
153
+ public static function scripts() {
154
+ wp_enqueue_script('sputnik_js', plugins_url( 'static/sputnik.js', Sputnik::$path . '/wpsc-marketplace' ), array('jquery', 'common'), '20110924' );
155
+ }
156
+
157
+ public static function connect_notice() {
158
+ if ( self::$page_is_current != true )
159
+ return;
160
+
161
+ if ( ! current_user_can( 'install_plugins' ) )
162
+ return;
163
+
164
+ $oauth_url = self::build_url(array('oauth' => 'request', 'TB_iframe' => true));
165
+
166
+
167
+ ?>
168
+ <div class="sputnik-message updated">
169
+ <p>
170
+ <?php _e( '<strong>WPEConomy is now installed!</strong> &#8211; Get started by linking with your account!', 'wpsc' ); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
171
+ <?php _e( "If you haven't created an account yet, don't worry, you will be prompted to do so.", 'wpsc') ?>
172
+ </p>
173
+ <a href="<?php echo esc_html( $oauth_url ); ?>" class="thickbox button button-primary thickbox`"><?php _e( 'Link your account now', 'sputnik' ); ?></a>
174
+ </div>
175
+ <?php
176
+ }
177
+
178
+ public static function admin_notices() {
179
+ if ( isset( $_GET['payment_cancelled'] ) ) {
180
+ self::print_message( __( 'Payment cancelled.', 'sputnik' ) );
181
+ }
182
+ }
183
+
184
+ protected static function print_message($message = '') {
185
+ ?>
186
+ <div id="message" class="updated below-h2">
187
+ <p><?php echo $message; ?></p>
188
+ </div>
189
+ <?php
190
+ }
191
+
192
+ public static function menu_order($menu_order) {
193
+ $real = array();
194
+
195
+ foreach ( $menu_order as $index => $item ) {
196
+ if ( $item != 'sputnik' )
197
+ $real[] = $item;
198
+
199
+ if ( $index == 0 )
200
+ $real[] = 'sputnik';
201
+ }
202
+
203
+ return $real;
204
+ }
205
+
206
+ public static function menu() {
207
+ $hooks[] = add_submenu_page( 'edit.php?post_type=wpsc-product', _x('Add-Ons', 'page title', 'sputnik'), _x('Add-Ons', 'menu title', 'sputnik'), 'install_plugins', 'sputnik', array(__CLASS__, 'page') );
208
+ $hooks[] = 'plugin-install.php';
209
+ foreach ($hooks as $hook) {
210
+ add_action("admin_print_styles-$hook", array(__CLASS__, 'page_styles'));
211
+ add_action("admin_print_scripts-$hook", array(__CLASS__, 'page_scripts'));
212
+ }
213
+ }
214
+
215
+ public static function build_url($args = array()) {
216
+ $url = add_query_arg( array( 'post_type' => 'wpsc-product', 'page' => 'sputnik' ), admin_url( 'edit.php' ) );
217
+
218
+ if (!empty($args)) {
219
+ $url = add_query_arg( $args, $url );
220
+ }
221
+ return $url;
222
+ }
223
+
224
+ public static function build_account_url($args = array()) {
225
+ $url = add_query_arg( array( 'post_type' => 'wpsc-product', 'page' => 'sputnik-account' ), admin_url( 'edit.php' ) );
226
+ if (!empty($args)) {
227
+ $url = add_query_arg( $args, $url );
228
+ }
229
+ return $url;
230
+ }
231
+
232
+ public static function page_styles() {
233
+ self::$page_is_current = true;
234
+ wp_enqueue_style('sputnik-page', plugins_url( 'static/admin.css', Sputnik::$path . '/wpsc-marketplace' ), array('thickbox'), '20110924');
235
+ ?>
236
+ <style type-"text/css">
237
+ #sputnik-page .icon32 {
238
+ background: url(<?php echo WPSC_CORE_IMAGES_URL; ?>/icon32.png) no-repeat left center;
239
+ }
240
+ </style>
241
+ <?php
242
+ }
243
+
244
+ public static function page_scripts() {
245
+ wp_enqueue_script('jquery-masonry', plugins_url( 'static/jquery.masonry.js', Sputnik::$path . '/wpsc-marketplace' ), array('jquery'), '20110901' );
246
+ wp_enqueue_script( 'paypal', 'https://www.paypalobjects.com/js/external/dg.js' );
247
+ wp_enqueue_script('sputnik_js', plugins_url( 'static/admin.js', Sputnik::$path . '/wpsc-marketplace' ), array( 'jquery', 'jquery-masonry', 'thickbox', 'paypal' ), '20110924' );
248
+
249
+ $l10n = array(
250
+ 'plugin_information' => __('Plugin Information:', 'sputnik'),
251
+ 'ays' => __('Are you sure you want to install this plugin?', 'sputnik')
252
+ );
253
+
254
+ if ( ! empty( $_REQUEST['oauth_buy'] ) ) {
255
+ $plugin = Sputnik::get_plugin( $_REQUEST['oauth_buy'] );
256
+ $status = self::install_status( $plugin );
257
+ $l10n['buy_id'] = $plugin->slug;
258
+ $l10n['buy_href'] = $status['url'];
259
+ }
260
+
261
+ wp_localize_script('sputnik_js', 'sputnikL10n', $l10n );
262
+ }
263
+
264
+ public static function page() {
265
+ global $current_user;
266
+
267
+ switch (self::$page) {
268
+ case 'info':
269
+ return self::info($_GET['info']);
270
+ case 'buy':
271
+ return self::purchase($_GET['buy']);
272
+ case 'paid':
273
+ return self::paid($_GET['paid']);
274
+ case 'cancel_payment':
275
+ return self::cancel_payment($_GET['cancel_payment']);
276
+ case 'install':
277
+ return self::install($_GET['install']);
278
+ case 'upgrade':
279
+ return self::upgrade($_GET['upgrade']);
280
+ default:
281
+ return self::other_pages();
282
+ }
283
+ }
284
+
285
+ public static function maybe_info() {
286
+ $plugin = $_REQUEST['plugin'];
287
+ if (strpos($plugin, 'sputnik-') !== 0) {
288
+ return;
289
+ }
290
+
291
+ $plugin = substr($plugin, 8);
292
+ self::info($plugin);
293
+
294
+ die();
295
+ }
296
+
297
+ protected static function info($plugin) {
298
+ global $tab;
299
+ require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
300
+
301
+ try {
302
+ if ( Sputnik::account_is_linked() ) {
303
+ $account = Sputnik::get_account();
304
+ $api = Sputnik::get_plugin( $plugin, $account->ID );
305
+ } else {
306
+ $api = Sputnik::get_plugin( $plugin );
307
+ }
308
+ } catch (Exception $e) {
309
+ status_header(500);
310
+ iframe_header( __('Plugin Install', 'sputnik') );
311
+ echo $e->getMessage();
312
+ iframe_footer();
313
+ die();
314
+ }
315
+
316
+ $plugins_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
317
+ 'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
318
+ 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
319
+ 'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
320
+ 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
321
+ 'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
322
+
323
+ $plugins_section_titles = array(
324
+ 'description' => _x('Description', 'Plugin installer section title', 'sputnik'),
325
+ 'installation' => _x('Installation', 'Plugin installer section title', 'sputnik'),
326
+ 'faq' => _x('FAQ', 'Plugin installer section title', 'sputnik'),
327
+ 'screenshots' => _x('Screenshots', 'Plugin installer section title', 'sputnik'),
328
+ 'changelog' => _x('Changelog', 'Plugin installer section title', 'sputnik'),
329
+ 'other_notes' => _x('Other Notes', 'Plugin installer section title', 'sputnik')
330
+ );
331
+ //Sanitize HTML
332
+ $api->sections = (array) $api->sections;
333
+ $api->author = links_add_target($api->author, '_blank');
334
+ foreach ( $api->sections as $section_name => $content )
335
+ $api->sections[$section_name] = wp_kses($content, $plugins_allowedtags);
336
+
337
+ $api->screenshots = (array) $api->screenshots;
338
+ foreach ( $api->screenshots as &$data ) {
339
+ if (!isset($data->caption) || !isset($data->location)) {
340
+ continue;
341
+ }
342
+
343
+ $data->caption = wp_kses($data->caption, $plugins_allowedtags);
344
+ $data->location = esc_url($data->location, array('http', 'https'));
345
+ }
346
+ unset($data);
347
+
348
+ foreach ( array( 'version', 'requires', 'tested', 'homepage', 'downloaded', 'slug', 'requires_wpec', 'tested_wpec' ) as $key ) {
349
+ if ( isset( $api->$key ) )
350
+ $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
351
+ }
352
+
353
+ $section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English.
354
+ if ( empty($section) || (!isset($api->sections[ $section ]) && ($section !== 'screenshots' || empty($api->screenshots))) )
355
+ $section = array_shift( $section_titles = array_keys((array)$api->sections) );
356
+
357
+ global $body_id;
358
+ $body_id = 'sputnik-plugin-information';
359
+ iframe_header( __('Plugin Install', 'sputnik') );
360
+ ?>
361
+ <div class="alignleft fyi">
362
+ <h1><?php echo $api->name ?></h1>
363
+ <?php if ( ! empty($api->download_link) && ( current_user_can('install_plugins') || current_user_can('update_plugins') ) ) : ?>
364
+ <p class="action-button">
365
+ <?php
366
+ $status = self::install_status($api);
367
+ switch ( $status['status'] ) {
368
+ case 'purchase':
369
+ default:
370
+ if ( $status['url'] )
371
+ echo '<a href="' . $status['url'] . '" target="_parent" id="' . $plugin . '" class="button-primary buy">' . sprintf(__('<span>$%.2f</span> Buy &amp; Install', 'sputnik'), $api->price) . '</a>';
372
+ break;
373
+ case 'install':
374
+ if ( $status['url'] )
375
+ echo '<a href="' . $status['url'] . '" class="button-primary install" title="' . __('You have already purchased, install now', 'sputnik') . '">' . __('Install Now', 'sputnik') . '</a>';
376
+ break;
377
+ case 'update_available':
378
+ if ( $status['url'] )
379
+ echo '<a href="' . $status['url'] . '" class="button-primary install">' . __('Install Update Now', 'sputnik') .'</a>';
380
+ break;
381
+ case 'newer_installed':
382
+ echo '<a>' . sprintf(__('Newer Version (%s) Installed', 'sputnik'), $status['version']) . '</a>';
383
+ break;
384
+ case 'latest_installed':
385
+ echo '<a>' . __('Latest Version Installed', 'sputnik') . '</a>';
386
+ break;
387
+ }
388
+ ?>
389
+ </p>
390
+ <?php endif; ?>
391
+ <?php
392
+ echo "<div id='plugin-information-header'>\n";
393
+ echo "<ul id='sidemenu'>\n";
394
+ foreach ( (array)$api->sections as $section_name => $content ) {
395
+ if ( isset( $plugins_section_titles[ $section_name ] ) )
396
+ $title = $plugins_section_titles[ $section_name ];
397
+ else
398
+ $title = ucwords( str_replace( '_', ' ', $section_name ) );
399
+
400
+ $class = ( $section_name == $section ) ? ' class="current"' : '';
401
+ $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
402
+ $href = esc_url($href);
403
+ $san_section = esc_attr($section_name);
404
+ echo "\t<li><a name='$san_section' href='$href'$class>$title</a></li>\n";
405
+ }
406
+ if (!empty($api->screenshots)) {
407
+ $title = $plugins_section_titles['screenshots'];
408
+ $class = ( 'screenshots' == $section ) ? ' class="current"' : '';
409
+ $href = add_query_arg( array('tab' => $tab, 'section' => 'screenshots') );
410
+ $href = esc_url($href);
411
+ echo "\t<li><a name='screenshots' href='$href'$class>$title</a></li>\n";
412
+ }
413
+ echo "</ul>\n";
414
+ echo "</div>\n";
415
+ ?>
416
+ <h2 class="mainheader"><?php /* translators: For Your Information */ _e('FYI', 'sputnik') ?></h2>
417
+ <ul>
418
+ <?php if ( ! empty($api->version) ) : ?>
419
+ <li><strong><?php _e('Version:', 'sputnik') ?></strong> <?php echo $api->version ?></li>
420
+ <?php endif; if ( ! empty($api->author) ) : ?>
421
+ <li><strong><?php _e('Author:', 'sputnik') ?></strong> <?php echo $api->author ?></li>
422
+ <?php endif; if ( ! empty($api->last_updated) ) : ?>
423
+ <li><strong><?php _e('Last Updated:', 'sputnik') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php
424
+ printf( __('%s ago', 'sputnik'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li>
425
+ <?php endif; if ( ! empty($api->requires) ) : ?>
426
+ <li><strong><?php _e('Requires WordPress Version:', 'sputnik') ?></strong> <?php printf(__('%s or higher', 'sputnik'), $api->requires) ?></li>
427
+ <?php endif; if ( ! empty($api->tested) ) : ?>
428
+ <li><strong><?php _e('Compatible up to:', 'sputnik') ?></strong> <?php echo $api->tested ?></li>
429
+ <?php endif; if ( ! empty($api->requires_wpec) ) : ?>
430
+ <li><strong><?php _e('Requires WPeC Version:', 'sputnik') ?></strong> <?php printf(__('%s or higher', 'sputnik'), $api->requires_wpec) ?></li>
431
+ <?php endif; if ( ! empty($api->tested_wpec) ) : ?>
432
+ <li><strong><?php _e('Compatible up to WPEC Version:', 'sputnik') ?></strong> <?php echo $api->tested_wpec ?></li>
433
+ <?php endif; if ( ! empty($api->downloaded) ) : ?>
434
+ <li><strong><?php _e('Downloaded:', 'sputnik') ?></strong> <?php printf(_n('%s time', '%s times', $api->downloaded, 'sputnik'), number_format_i18n($api->downloaded)) ?></li>
435
+ <?php endif; if ( ! empty($api->homepage) ) : ?>
436
+ <li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage &#187;', 'sputnik') ?></a></li>
437
+ <?php endif; ?>
438
+ </ul>
439
+ </div>
440
+ <div id="section-holder" class="wrap">
441
+ <?php
442
+ if ( !empty($api->tested) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->tested)), $api->tested, '>') )
443
+ echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.', 'sputnik') . '</p></div>';
444
+
445
+ else if ( !empty($api->requires) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->requires)), $api->requires, '<') )
446
+ echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.', 'sputnik') . '</p></div>';
447
+
448
+ else if ( !empty($api->requires_wpec) && version_compare( substr( WPSC_VERSION, 0, strlen($api->requires_wpec)), $api->requires_wpec, '<') )
449
+ echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WP E-Commerce.', 'sputnik') . '</p></div>';
450
+
451
+ else if ( !empty($api->tested_wpec) && version_compare( substr( WPSC_VERSION, 0, strlen($api->tested_wpec)), $api->tested_wpec, '<') )
452
+ echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your version of WP E-Commerce.', 'sputnik') . '</p></div>';
453
+
454
+ foreach ( $api->sections as $section_name => $content ) {
455
+ if ( isset( $plugins_section_titles[ $section_name ] ) )
456
+ $title = $plugins_section_titles[ $section_name ];
457
+ else
458
+ $title = ucwords( str_replace( '_', ' ', $section_name ) );
459
+
460
+ $content = links_add_base_url($content, $api->permalink);
461
+ $content = links_add_target($content, '_blank');
462
+
463
+ $san_section = esc_attr($title);
464
+
465
+ $display = ( $section_name == $section ) ? 'block' : 'none';
466
+
467
+ echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
468
+ echo "\t\t<h2 class='long-header'>$title</h2>";
469
+ echo $content;
470
+ echo "\t</div>\n";
471
+ }
472
+
473
+ if (!empty($api->screenshots)) {
474
+ $display = ( 'screenshots' == $section ) ? 'block' : 'none';
475
+ echo "\t<div id='section-screenshots' class='section' style='display: {$display};'>\n";
476
+ echo "\t\t<h2 class='long-header'>Screenshots</h2>\n";
477
+ echo "\t\t<ol>\n";
478
+ foreach ($api->screenshots as $data) {
479
+ echo "\t\t\t<li><img src='{$data->location}' class='screenshot' /><p>{$data->caption}</p></li>\n";
480
+ }
481
+ echo "\t\t</ol>\n";
482
+ echo "\t</div>\n";
483
+ }
484
+
485
+ echo "</div>\n";
486
+
487
+ iframe_footer();
488
+ die();
489
+ }
490
+
491
+ /**
492
+ * Set the rating for a given plugin
493
+ */
494
+ public static function set_rating() {
495
+ header('Content-Type: application/json; charset=utf-8');
496
+ try {
497
+ $rating = absint($_POST['rating']);
498
+ Sputnik_API::rate_product($_POST['product'], $rating);
499
+ echo json_encode(array('success' => true, 'rating' => $rating));
500
+ }
501
+ catch (Exception $e) {
502
+ status_header(500);
503
+ echo json_encode(array('success' => false, 'error' => $e->getMessage()));
504
+ }
505
+ die();
506
+ }
507
+
508
+ /**
509
+ * Determine the action we can perform on a plugin
510
+ *
511
+ * @param stdClass $api API data
512
+ * @param boolean $loop Prevents further loops when called recursively
513
+ * @return array Keys 'status', 'url', 'version'
514
+ */
515
+ public static function install_status($api, $loop = false) {
516
+ // Default to a "new" plugin
517
+ $status = 'install';
518
+ $url = false;
519
+
520
+ // Check to see if this plugin is known to be installed, and has an update awaiting it.
521
+ $update_plugins = get_site_transient('update_plugins');
522
+ if (is_object($update_plugins) && isset($update_plugins->response)) {
523
+ foreach ((array) $update_plugins->response as $file => $plugin) {
524
+ if (!empty($plugin->sputnik_id) && $plugin->sputnik_id === $api->slug) {
525
+ $status = 'update_available';
526
+ $version = $plugin->new_version;
527
+ if ( current_user_can('update_plugins') )
528
+ $url = wp_nonce_url(self::build_url(array('upgrade' => $file)), 'sputnik_upgrade-plugin_' . $file);
529
+ break;
530
+ }
531
+ }
532
+ }
533
+
534
+ if ('install' == $status) {
535
+ $installed = get_plugins();
536
+ $real = false;
537
+ foreach ($installed as $plugin) {
538
+ if (!empty($plugin['Sputnik ID']) && $plugin['Sputnik ID'] === $api->slug) {
539
+ $real = $plugin;
540
+ break;
541
+ }
542
+ }
543
+
544
+ if ($real === false) {
545
+ if (current_user_can('install_plugins')) {
546
+ $url = wp_nonce_url(self::build_url(array('install' => $api->slug)), 'sputnik_install-plugin_' . $api->slug);
547
+ }
548
+ } else {
549
+ if (version_compare($api->version, $plugin['Version'], '=')){
550
+ $status = 'latest_installed';
551
+ } elseif (version_compare($api->version, $plugin['Version'], '<')) {
552
+ $status = 'newer_installed';
553
+ $version = $plugin['Version'];
554
+ } else {
555
+ // If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
556
+ if (!$loop) {
557
+ delete_site_transient('update_plugins');
558
+ wp_update_plugins();
559
+ return self::install_status($api, true);
560
+ }
561
+
562
+ // Otherwise, we'll need to tell the user there's an update, though we have no idea how they can get it
563
+ $status = 'update_available';
564
+ }
565
+ }
566
+ }
567
+
568
+ if (!Sputnik::is_purchased($api)) {
569
+ $status = 'purchase';
570
+ $url = wp_nonce_url(self::build_url(array('buy' => $api->slug)), 'sputnik_install-plugin_' . $api->slug);
571
+ }
572
+
573
+ if ( ! Sputnik::account_is_linked() )
574
+ $url = self::build_url( array(
575
+ 'oauth' => 'request',
576
+ 'oauth_buy' => $api->slug,
577
+ 'TB_iframe' => true,
578
+ ) );
579
+
580
+ return compact('status', 'url', 'version');
581
+ }
582
+
583
+ protected static function header( $account ) {
584
+ if ($account !== false) {
585
+ $tabs = array(
586
+ 'dash' => __('Store', 'sputnik'),
587
+ 'account' => __('Your Account', 'sputnik'),
588
+ );
589
+ $hrefs = array(
590
+ 'dash' => self::build_url(),
591
+ 'account' => menu_page_url( 'sputnik-account', false ),
592
+ );
593
+
594
+ $current = self::$page;
595
+ }
596
+ ?>
597
+ <div class="wrap" id="sputnik-page">
598
+ <?php screen_icon(); ?>
599
+ <h2>Marketplace <?php self::account_link(); ?>
600
+ </h2>
601
+ <?php
602
+ do_action('sputnik_messages');
603
+ }
604
+
605
+ protected static function footer() {?>
606
+ <div id="sputnik-footer">
607
+ <p class="logo-holder"><a href="http://wpeconomy.org/" class="renku-logo-no-img">Marketplace Powered by WPEconomy</a></p>
608
+ <nav><p><a href="http://www.wpeconomy.org/documentation/developers/">Developer Tools</a> | <a href="http://twitter.com/WPEconomy">@WPEconomy</a> | <a href="http://www.wpeconomy.org/documentation/marketplace/faqs/">FAQ</a></p></nav>
609
+ </div>
610
+ </div>
611
+ <?php
612
+ }
613
+
614
+ protected static function account_link() {
615
+ if ( Sputnik::account_is_linked() && 'dash' == self::$page )
616
+ echo '<a href="edit.php?post_type=wpsc-product&amp;page=sputnik-account" class="add-new-h2">Your Account</a>';
617
+ }
618
+
619
+ protected static function other_pages() {
620
+ global $tab;
621
+
622
+ $account = false;
623
+ try {
624
+ $account = Sputnik::get_account();
625
+ }
626
+ catch (Exception $e) {
627
+ if ($e->getCode() === 401) {
628
+ delete_option('sputnik_oauth_access');
629
+ delete_option('sputnik_oauth_request');
630
+ }
631
+ elseif ( $e->getCode() !== 1 ) {
632
+ echo '<p>' . sprintf(__('Problem: %s', 'sputnik'), $e->getMessage() ). '</p>';
633
+ }
634
+ }
635
+
636
+ self::header( $account );
637
+
638
+ if ( Sputnik::account_is_linked() ) {
639
+ self::auth();
640
+ ?>
641
+ <div class="account-card">
642
+ <div class="block">
643
+ <?php echo get_avatar($account->email) ?>
644
+ <p class="lead-in">Logged in as</p>
645
+ <h3><?php echo esc_html($account->name) ?></h3>
646
+ <p><?php printf(__('<a href="%s">Log out</a> of your account', 'sputnik'), self::build_url(array('oauth' => 'reset'))) ?></p>
647
+ </div>
648
+ <div class="block">
649
+ <p>Email: <code><?php echo $account->email ?></code></p>
650
+ <?php if ( $tab != 'purchased' ): ?>
651
+ <p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you can install right now">Available</abbr>', 'sputnik'), count( self::$list_table->items )) ?></p>
652
+ <?php endif; ?>
653
+ <p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you have bought from the store">Purchased</abbr>', 'sputnik'), count( $account->purchased ) ) ?></p>
654
+ </div>
655
+ </div>
656
+ <?php
657
+ }
658
+ self::$list_table->views();
659
+ self::$list_table->display();
660
+ self::footer();
661
+ }
662
+
663
+ /**
664
+ * Output the main landing page for the Sputnik administration screen.
665
+ */
666
+ protected static function dashboard() { ?>
667
+ <p><?php _e('Some text about WPEconomy goes here! This will eventually be replaced with a dashboard-like interface, including latest news, etc.', 'sputnik'); ?></p>
668
+
669
+ <h4><?php _e('Search', 'sputnik') ?></h4>
670
+ <p class="install-help"><?php _e('Search for plugins by keyword.', 'sputnik') ?></p>
671
+ <?php Sputnik_Admin::search_form(); ?>
672
+
673
+ <h4><?php _e('Popular tags') ?></h4>
674
+ <p class="install-help"><?php _e('You may also browse based on the most popular tags on the store:', 'sputnik') ?></p>
675
+ <?php
676
+ echo '<p class="popular-tags">';
677
+
678
+ try {
679
+ $api_tags = Sputnik::get_tags();
680
+
681
+ //Set up the tags in a way which can be interpreted by wp_generate_tag_cloud()
682
+ $tags = array();
683
+ foreach ($api_tags as $tag) {
684
+ $tags[ $tag->name ] = (object) array(
685
+ 'link' => esc_url( self::build_url(array('tab' => 'search', 's' => urlencode($tag->name))) ),
686
+ 'name' => $tag->name,
687
+ 'id' => sanitize_title_with_dashes($tag->name),
688
+ 'count' => $tag->count
689
+ );
690
+ }
691
+ echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%s plugin', 'sputnik'), 'multiple_text' => __('%s plugins', 'sputnik') ) );
692
+ }
693
+ catch (Exception $e) {
694
+ echo $e->getMessage();
695
+ }
696
+ echo '</p><br class="clear" />';
697
+ }
698
+
699
+ public static function account() {
700
+ self::$page = 'account';
701
+ $account = false;
702
+ try {
703
+ $account = Sputnik::get_account();
704
+ }
705
+ catch (Exception $e) {
706
+ if ($e->getCode() === 1) {
707
+ $GLOBALS['tab'] = 'auth';
708
+ return self::other_pages();
709
+ }
710
+ elseif ($e->getCode() === 401) {
711
+ delete_option('sputnik_oauth_access');
712
+ delete_option('sputnik_oauth_request');
713
+ $GLOBALS['tab'] = 'auth';
714
+ return self::other_pages();
715
+ }
716
+ else {
717
+ self::header('Account', $account);
718
+ echo '<p>' . sprintf(__('Problem: %s', 'sputnik'), $e->getMessage()) . '</p>';
719
+ self::footer();
720
+
721
+ return;
722
+ }
723
+ }
724
+
725
+ self::header('Account', $account);
726
+ ?>
727
+ <div class="account-card">
728
+ <div class="block">
729
+ <?php echo get_avatar($account->email) ?>
730
+ <p class="lead-in">Logged in as</p>
731
+ <h3><?php echo esc_html($account->name) ?></h3>
732
+ <p><?php printf(__('<a href="%s">Log out</a> of your account', 'sputnik'), self::build_url(array('oauth' => 'reset'))) ?></p>
733
+ </div>
734
+ <div class="block">
735
+ <p>Email: <code><?php echo $account->email ?></code></p>
736
+ <p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you can install right now">Available</abbr>', 'sputnik'), count($account->purchased)) ?></p>
737
+ <p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you have bought from the store">Purchased</abbr>', 'sputnik'), count(self::$list_table->items)) ?></p>
738
+ </div>
739
+ </div>
740
+
741
+ <?php
742
+ self::$list_table->views();
743
+ self::$list_table->display();
744
+ self::footer();
745
+ }
746
+
747
+ protected static function auth() {
748
+ $oauth_url = self::build_url(array('oauth' => 'request', 'TB_iframe' => true));
749
+
750
+ if ( isset( $_GET['auth'] ) && $_GET['auth'] == 'denied' ) {
751
+ self::print_message( __( 'Authorization cancelled.', 'sputnik' ) );
752
+ }
753
+ }
754
+
755
+ /**
756
+ * When a user clicks a plugin's "Buy Now" button, setup a payment flow.
757
+ *
758
+ * @param string $plugin_id
759
+ */
760
+ protected static function purchase( $plugin_id ) {
761
+
762
+ $plugin = Sputnik::get_plugin( $plugin_id );
763
+
764
+ if( Sputnik::is_purchased( $plugin->slug ) ) {
765
+ wp_redirect( self::build_url( array( 'install' => $plugin_id ) ) );
766
+ die();
767
+ }
768
+
769
+ // Request a checkout token from the Baikonur REST API for this product (associate user ID in custom field?)
770
+ $response = Sputnik_API::get_checkout_token( $plugin_id );
771
+
772
+ // Redirect to PayPal with token in checkout URL
773
+ wp_redirect( $response['body']->checkout_uri );
774
+ exit;
775
+ }
776
+
777
+ /**
778
+ * When a user returns from the server after making a payment, update their account,
779
+ * close the PayPal iframe & redirect to the installation page for the plugin they
780
+ * just purchased.
781
+ *
782
+ * @param string $product_slug the slug of the product just purchased
783
+ */
784
+ protected static function paid( $product_slug ) {
785
+
786
+ check_admin_referer( 'sputnik_install-plugin_' . $product_slug );
787
+
788
+ // Update Sputnik account to include newly purchased plugin
789
+ Sputnik::update_account();
790
+
791
+ $install_url = self::build_url(array('install' => $product_slug));
792
+ $install_url = add_query_arg('_wpnonce', wp_create_nonce('sputnik_install-plugin_' . $product_slug), $install_url);
793
+ $install_url = add_query_arg(array('TB_iframe' => true), $install_url);
794
+
795
+ self::iframe_closer( self::build_url(array('run-installer' => urlencode($install_url))), __( 'Installing ... ', 'sputnik' ) );
796
+ }
797
+
798
+ /**
799
+ * When a user cancels a payment, we need to close the PayPal iframe & redirect
800
+ * back to Sputnik with a notice.
801
+ *
802
+ * @param string $plugin_id the slug of the plugin just purchased
803
+ */
804
+ protected static function cancel_payment() {
805
+
806
+ $cancelled_url = self::build_url( array( 'payment_cancelled' => true ) );
807
+
808
+ self::iframe_closer( $cancelled_url, __( 'Payment Cancelled', 'sputnik' ) );
809
+ }
810
+
811
+ protected static function install($id) {
812
+
813
+ include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
814
+
815
+ try {
816
+ $api = Sputnik::get_plugin($id);
817
+ }
818
+ catch (Exception $e) {
819
+ status_header(500);
820
+ iframe_header( __('Plugin Install', 'sputnik') );
821
+ echo $e->getMessage();
822
+ iframe_footer();
823
+ die();
824
+ }
825
+
826
+ if (!Sputnik::is_purchased($api->slug)) {
827
+ wp_redirect(self::build_url(array('buy' => $id)));
828
+ die();
829
+ }
830
+
831
+ if ( ! current_user_can('install_plugins') )
832
+ wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'sputnik'));
833
+
834
+ include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
835
+
836
+ check_admin_referer('sputnik_install-plugin_' . $api->slug);
837
+
838
+ global $body_id;
839
+ $body_id = 'sputnik-install';
840
+ iframe_header( __('Plugin Install', 'sputnik') );
841
+
842
+ $title = sprintf( __('Installing Plugin: %s', 'sputnik'), $api->name . ' ' . $api->version );
843
+ $nonce = 'sputnik_install-plugin_' . $id;
844
+ $url = 'update.php?action=install-plugin&plugin=' . $id;
845
+ if ( isset($_GET['from']) )
846
+ $url .= '&from=' . urlencode(stripslashes($_GET['from']));
847
+
848
+ $type = 'web'; //Install plugin type, From Web or an Upload.erro
849
+
850
+ ini_set( 'display_errors', '1' );
851
+ error_reporting( E_ALL );
852
+
853
+ if ( $api->is_theme )
854
+ $upgrader = new Sputnik_ThemeUpgrader( new Sputnik_Upgrader_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
855
+ else
856
+ $upgrader = new Sputnik_Upgrader( new Sputnik_Upgrader_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
857
+
858
+ $upgrader->install($api->download_link);
859
+
860
+ iframe_footer();
861
+ die();
862
+ }
863
+
864
+ protected static function upgrade($file) {
865
+ include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
866
+
867
+ try {
868
+ $data = Sputnik::get_from_file($file);
869
+ if ($data === null) {
870
+ throw new Exception(__('Plugin not found', 'sputnik'));
871
+ }
872
+ $id = $data['Sputnik ID'];
873
+ $api = Sputnik::get_plugin($id);
874
+ }
875
+ catch (Exception $e) {
876
+ status_header(500);
877
+ iframe_header( __('Update Plugin', 'sputnik') );
878
+ echo $e->getMessage();
879
+ iframe_footer();
880
+ die();
881
+ }
882
+
883
+ if (!Sputnik::is_purchased($id)) {
884
+ wp_redirect(self::build_url(array('buy' => $id)));
885
+ die();
886
+ }
887
+
888
+ if ( ! current_user_can('install_plugins') )
889
+ wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'sputnik'));
890
+
891
+ include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
892
+
893
+ check_admin_referer('sputnik_upgrade-plugin_' . $file);
894
+
895
+ global $body_id;
896
+ $body_id = 'sputnik-upgrade';
897
+ iframe_header( __('Update Plugin', 'sputnik') );
898
+
899
+ $title = sprintf( __('Updating Plugin: %s', 'sputnik'), $api->name . ' ' . $api->version );
900
+ $nonce = 'sputnik_upgrade-plugin_' . $id;
901
+ $url = 'update.php?action=upgrade-plugin&plugin=' . $id;
902
+ if ( isset($_GET['from']) )
903
+ $url .= '&from=' . urlencode(stripslashes($_GET['from']));
904
+
905
+ $type = 'web'; //Install plugin type, From Web or an Upload.
906
+ $plugin = $id;
907
+
908
+ if ( $api->is_theme )
909
+ $upgrader = new Sputnik_ThemeUpgrader( new Sputnik_Upgrader_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
910
+ else
911
+ $upgrader = new Sputnik_Upgrader( new Sputnik_Upgrader_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
912
+
913
+ $upgrader->upgrade($file);
914
+
915
+ iframe_footer();
916
+ die();
917
+ }
918
+
919
+ public static function search_form(){
920
+ $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
921
+ $term = isset($_REQUEST['s']) ? esc_attr($_REQUEST['s']) : '';
922
+
923
+ ?><form id="search-plugins" method="get" action="">
924
+ <input type="hidden" name="page" value="sputnik" />
925
+ <input type="hidden" name="post_type" value="wpsc-product" />
926
+ <input type="hidden" name="tab" value="search" />
927
+ <input type="text" name="s" value="<?php echo esc_attr($term) ?>" />
928
+ <?php submit_button( __( 'Search Plugins' ), 'button', '', false ); ?>
929
+ </form><?php
930
+ }
931
+
932
+ /**
933
+ * When a user cancels a payment or returns after making a payment, we need to
934
+ * close the PayPal iframe.
935
+ *
936
+ * @param string $redirect_url The URL to load in the parent window.
937
+ * @param string $title optional The title attribute for the page.
938
+ */
939
+ public static function iframe_closer( $redirect_url, $title = null ) {
940
+ if (empty($title)) {
941
+ $title = __('Redirecting...', 'sputnik');
942
+ }
943
+ ?>
944
+ <!DOCTYPE html><html>
945
+ <head>
946
+ <title><?php echo $title; ?></title>
947
+ <script type="text/javascript">if (window!=top) {top.location.replace("<?php echo $redirect_url; ?>");}</script>
948
+ </head>
949
+ <body>&nbsp;</body>
950
+ </html>
951
+ <?php
952
+ die();
953
+ }
954
+
955
+ public static function maybe_redirect_update() {
956
+ if (empty($_GET['action']) || $_GET['action'] !== 'upgrade-plugin' || empty($_REQUEST['plugin'])) {
957
+ return;
958
+ }
959
+ $file = trim($_REQUEST['plugin']);
960
+
961
+ $data = Sputnik::get_from_file($file);
962
+ if ($data === null || empty($data['Sputnik ID'])) {
963
+ return;
964
+ }
965
+
966
+ $url = self::build_url(array('upgrade' => $file));
967
+ // wp_nonce_url also does a esc_html, so do it ourselves
968
+ $url = add_query_arg('_wpnonce', wp_create_nonce('sputnik_upgrade-plugin_' . $file), $url);
969
+ wp_redirect($url);
970
+
971
+ die();
972
+ }
973
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Library/Plugin.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A new way of using the WordPress API
5
+ *
6
+ * @package Sputnik
7
+ * @subpackage Public Utilities
8
+ */
9
+ class Sputnik_Library_Plugin extends Sputnik_Library_Plugin_Base {
10
+ /**
11
+ * Register hooks automatically
12
+ *
13
+ * Ensure you call this from your child class
14
+ *
15
+ * @param boolean $enable_prefixes Whether to enable prefixed methods (i.e. `action_init` or `filter_the_title`)
16
+ */
17
+ protected static function register_hooks($enable_prefixes = false) {
18
+ if (function_exists('get_called_class') && false) {
19
+ $class = get_called_class();
20
+ }
21
+ else {
22
+ $trace = debug_backtrace();
23
+ $class = $trace[1]['class'];
24
+ }
25
+ self::_register_hooks($enable_prefixes, $class);
26
+ }
27
+
28
+ /**
29
+ * Add a method as a filter
30
+ *
31
+ * This is exactly the same as {@see add_filter()} but instead of passing
32
+ * a full callback, only the method needs to be passed in.
33
+ *
34
+ * @param string $hook Filter name
35
+ * @param string $method Method name on current class, or priority (as an int)
36
+ * @param int $priority Specify the order in which the functions associated with a particular action are executed (default: 10)
37
+ * @param int $accepted_args Number of parameters which callback accepts (default: corresponds to method prototype)
38
+ * @param string $class Internal use only
39
+ */
40
+ protected static function add_filter($hook, $method = null, $priority = 10, $params = null, $class = null) {
41
+ if ($method === null) {
42
+ $method = $hook;
43
+ }
44
+ elseif (is_int($method)) {
45
+ $priority = $method;
46
+ $method = $hook;
47
+ }
48
+
49
+ if ($class === null) {
50
+ if (function_exists('get_called_class') && false) {
51
+ $class = get_called_class();
52
+ }
53
+ else {
54
+ $trace = debug_backtrace();
55
+ do {
56
+ array_shift($trace);
57
+ }
58
+ while (empty($trace[0]['class']) && !empty($trace));
59
+ if (empty($trace)) {
60
+ throw new BadMethodCallException('Must be called from a class');
61
+ }
62
+ $class = $trace[0]['class'];
63
+ }
64
+ }
65
+
66
+ if (!method_exists($class, $method)) {
67
+ throw new InvalidArgumentException('Method does not exist');
68
+ }
69
+
70
+ if ($params === null) {
71
+ $ref = new ReflectionMethod($class, $method);
72
+ $params = $ref->getNumberOfParameters();
73
+ }
74
+
75
+ return add_filter($hook, array($class, $method), $priority, $params);
76
+ }
77
+
78
+ /**
79
+ * Add a method as a action
80
+ *
81
+ * This is exactly the same as {@see add_action()} but instead of passing
82
+ * a full callback, only the method needs to be passed in.
83
+ *
84
+ * @internal This is duplication, but ensures consistency with WordPress API
85
+ * @param string $hook Action name
86
+ * @param string $method Method name on current class, or priority (as an int)
87
+ * @param int $priority Specify the order in which the functions associated with a particular action are executed (default: 10)
88
+ * @param int $accepted_args Number of parameters which callback accepts (default: corresponds to method prototype)
89
+ * @param string $class Internal use only
90
+ */
91
+ protected static function add_action($hook, $method = null, $priority = 10, $params = null, $class = null) {
92
+ if ($method === null) {
93
+ $method = $hook;
94
+ }
95
+ elseif (is_int($method)) {
96
+ $priority = $method;
97
+ $method = $hook;
98
+ }
99
+
100
+ if ($class === null) {
101
+ if (function_exists('get_called_class') && false) {
102
+ $class = get_called_class();
103
+ }
104
+ else {
105
+ $trace = debug_backtrace();
106
+ do {
107
+ array_shift($trace);
108
+ }
109
+ while (empty($trace[0]['class']) && !empty($trace));
110
+ if (empty($trace)) {
111
+ throw new BadMethodCallException('Must be called from a class');
112
+ }
113
+ $class = $trace[0]['class'];
114
+ }
115
+ }
116
+
117
+ if (!method_exists($class, $method)) {
118
+ throw new InvalidArgumentException('Method does not exist');
119
+ }
120
+
121
+ if ($params === null) {
122
+ $ref = new ReflectionMethod($class, $method);
123
+ $params = $ref->getNumberOfParameters();
124
+ }
125
+
126
+ return add_action($hook, array($class, $method), $priority, $params);
127
+ }
128
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Library/Plugin/Base.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A new way of using the WordPress API
5
+ *
6
+ * @package Sputnik
7
+ * @subpackage Public Utilities
8
+ */
9
+ class Sputnik_Library_Plugin_Base {
10
+ /**
11
+ * Register hooks
12
+ *
13
+ * @see Sputnik_Library_Plugin::register_hooks
14
+ * @see Sputnik_Library_Plugin_Dynamic::register_hooks
15
+ * @param boolean|array $prefixes True for default (`action_`/`filter_`), array with keys "action" & "filter" or false
16
+ * @param string|object $parent Object to register from
17
+ */
18
+ public static function _register_hooks($prefixes, $parent) {
19
+ $is_sane = self::check_eaccelerator_saneness();
20
+ if (!$is_sane) {
21
+ // This will be replaced with something better soon
22
+ throw new Exception('eAccelerator is configured to strip doc comments, cannot continue');
23
+ }
24
+
25
+ $enable_prefixes = true;
26
+ if ($prefixes === false) {
27
+ $enable_prefixes = false;
28
+ }
29
+ elseif ($prefixes === true) {
30
+ $prefixes = array('filter' => 'filter_', 'action' => 'action_');
31
+ }
32
+
33
+ $self = new ReflectionClass($parent);
34
+ foreach ($self->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
35
+ $params = $method->getNumberOfParameters();
36
+ $doc = $method->getDocComment();
37
+ if (!empty($doc) && preg_match('#^\s+\*\s*@wp-nohook#im', $doc) !== 0) {
38
+ continue;
39
+ }
40
+
41
+ $hooks = array('filter' => array(), 'action' => array());
42
+
43
+ if ($enable_prefixes === true) {
44
+ // If either prefix is blank, always hook
45
+ if ($prefixes['filter'] === '' || $prefixes['action'] === '') {
46
+ $hooks['filter'][$method->name] = 10;
47
+ }
48
+
49
+ // Method starts with filter prefix
50
+ elseif ($enable_prefixes === true && strpos($method->name, $prefixes['filter']) === 0) {
51
+ $hook = substr($method->name, strlen($prefixes['filter']));
52
+ $hooks['action'][$hook] = 10;
53
+ }
54
+
55
+ // Method starts with action prefix
56
+ elseif ($enable_prefixes === true && strpos($method->name, $prefixes['action']) === 0) {
57
+ $hook = substr($method->name, strlen($prefixes['action']));
58
+ $hooks['action'][$hook] = 10;
59
+ }
60
+ }
61
+
62
+ // If we haven't hooked anything yet, check phpdoc
63
+ if (empty($hooks['filter']) && empty($hooks['action'])) {
64
+ if (empty($doc) || (strpos($doc, '@wp-filter') === false && strpos($doc, '@wp-action') === false)) {
65
+ continue;
66
+ }
67
+
68
+ preg_match_all('#^\s+\*\s*@wp-(action|filter)\s+([\w-]+)(\s*\d+)?#im', $doc, $matches, PREG_SET_ORDER);
69
+ if (empty($matches)) {
70
+ continue;
71
+ }
72
+ foreach ($matches as $match) {
73
+ $type = $match[1];
74
+ $hook = $match[2];
75
+ $priority = 10;
76
+ if (!empty($match[3])) {
77
+ $priority = (int) $match[3];
78
+ }
79
+
80
+ $hooks[$type][$hook] = $priority;
81
+ }
82
+ }
83
+
84
+ foreach ($hooks['filter'] as $hook => $priority) {
85
+ call_user_func(array($parent, 'add_filter'), $hook, $method->name, $priority, $params, $parent);
86
+ }
87
+ foreach ($hooks['action'] as $hook => $priority) {
88
+ call_user_func(array($parent, 'add_action'), $hook, $method->name, $priority, $params, $parent);
89
+ }
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Check if eAccelerator is loaded, and if so, is sane
95
+ *
96
+ * @internal If you can find me, it's sane.
97
+ * @return boolean True if doc comments are fine, false otherwise
98
+ */
99
+ private static function check_eaccelerator_saneness() {
100
+ if (!extension_loaded('eaccelerator') && !extension_loaded('eAccelerator')) {
101
+ return true;
102
+ }
103
+
104
+ $method = new ReflectionMethod('Sputnik_Library_Plugin_Base', 'check_eaccelerator_saneness');
105
+ $comment = $method->getDocComment();
106
+
107
+ return (strpos($comment, "If you can find me, it's sane.") !== false);
108
+ }
109
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Library/Plugin/Dynamic.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A new way of using the WordPress API
5
+ *
6
+ * @package Sputnik
7
+ * @subpackage Public Utilities
8
+ */
9
+ class Sputnik_Library_Plugin extends Sputnik_Library_Plugin_Base {
10
+ /**
11
+ * Register hooks
12
+ *
13
+ * Ensure you call this from your child class
14
+ *
15
+ * @param boolean $enable_prefixes Whether to enable prefixed methods (i.e. `action_init` or `filter_the_title`)
16
+ */
17
+ protected function register_hooks($enable_prefixes = false) {
18
+ $this->_register_hooks($enable_prefixes, $this);
19
+ }
20
+
21
+ /**
22
+ * Add a method as a filter
23
+ *
24
+ * This is exactly the same as {@see add_filter()} but instead of passing
25
+ * a full callback, only the method needs to be passed in.
26
+ *
27
+ * @param string $hook Filter name
28
+ * @param string $method Method name on current class, or priority (as an int)
29
+ * @param int $priority Specify the order in which the functions associated with a particular action are executed (default: 10)
30
+ * @param int $accepted_args Number of parameters which callback accepts (default: corresponds to method prototype)
31
+ */
32
+ protected function add_filter($hook, $method = null, $priority = 10, $params = null) {
33
+ if ($method === null) {
34
+ $method = $hook;
35
+ }
36
+ elseif (is_int($method)) {
37
+ $priority = $method;
38
+ $method = $hook;
39
+ }
40
+
41
+ if (!method_exists($this, $method)) {
42
+ throw new InvalidArgumentException('Method does not exist');
43
+ }
44
+
45
+ if ($params === null) {
46
+ $ref = new ReflectionMethod($this, $method);
47
+ $params = $ref->getNumberOfParameters();
48
+ }
49
+
50
+ return add_filter($hook, array($this, $method), $priority, $params);
51
+ }
52
+
53
+ /**
54
+ * Add a method as a action
55
+ *
56
+ * This is exactly the same as {@see add_action()} but instead of passing
57
+ * a full callback, only the method needs to be passed in.
58
+ *
59
+ * @internal This is duplication, but ensures consistency with WordPress API
60
+ * @param string $hook Action name
61
+ * @param string|int $method Method name on current class, or priority (as an int)
62
+ * @param int $priority Specify the order in which the functions associated with a particular action are executed (default: 10)
63
+ * @param int $accepted_args Number of parameters which callback accepts (default: corresponds to method prototype)
64
+ */
65
+ protected function add_action($hook, $method = null, $priority = 10, $params = null) {
66
+ if ($method === null) {
67
+ $method = $hook;
68
+ }
69
+ elseif (is_int($method)) {
70
+ $priority = $method;
71
+ $method = $hook;
72
+ }
73
+
74
+ if (!method_exists($this, $method)) {
75
+ throw new InvalidArgumentException('Method does not exist');
76
+ }
77
+
78
+ if ($params === null) {
79
+ $ref = new ReflectionMethod($this, $method);
80
+ $params = $ref->getNumberOfParameters();
81
+ }
82
+
83
+ return add_action($hook, array($this, $method), $priority, $params);
84
+ }
85
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Library/TwitterOAuth.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Twitter OAuth library, based on Abraham Williams'
5
+ *
6
+ * This class extends the original and replaces OAuth* classes with
7
+ * Sputnik_OAuth_* classes, in addition to adapting it for WP_Http
8
+ *
9
+ * @package Sputnik
10
+ * @subpackage Public Utilities
11
+ */
12
+ class Sputnik_Library_TwitterOAuth extends Sputnik_Library_TwitterOAuth_Internal {
13
+
14
+ /**
15
+ * construct TwitterOAuth object
16
+ * @internal Converted OAuth* to Sputnik_OAuth_*
17
+ */
18
+ function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
19
+ $this->sha1_method = new Sputnik_OAuth_SignatureMethod_HMAC_SHA1();
20
+ $this->consumer = new Sputnik_OAuth_Consumer($consumer_key, $consumer_secret);
21
+ if (!empty($oauth_token) && !empty($oauth_token_secret)) {
22
+ $this->token = new Sputnik_OAuth_Consumer($oauth_token, $oauth_token_secret);
23
+ } else {
24
+ $this->token = NULL;
25
+ }
26
+ }
27
+
28
+
29
+ /**
30
+ * Get a request_token from Twitter
31
+ *
32
+ * @internal Converted OAuth* to Sputnik_OAuth_*
33
+ * @returns a key/value array containing oauth_token and oauth_token_secret
34
+ */
35
+ function getRequestToken($oauth_callback = NULL) {
36
+ $parameters = array();
37
+ if (!empty($oauth_callback)) {
38
+ $parameters['oauth_callback'] = $oauth_callback;
39
+ }
40
+ $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
41
+ $token = Sputnik_OAuth_Util::parse_parameters($request);
42
+ $this->token = new Sputnik_OAuth_Consumer($token['oauth_token'], $token['oauth_token_secret']);
43
+ return $token;
44
+ }
45
+
46
+ /**
47
+ * Exchange request token and secret for an access token and
48
+ * secret, to sign API calls.
49
+ *
50
+ * @internal Converted OAuth* to Sputnik_OAuth_*
51
+ * @returns array("oauth_token" => "the-access-token",
52
+ * "oauth_token_secret" => "the-access-secret",
53
+ * "user_id" => "9436992",
54
+ * "screen_name" => "abraham")
55
+ */
56
+ function getAccessToken($oauth_verifier = FALSE) {
57
+ $parameters = array();
58
+ if (!empty($oauth_verifier)) {
59
+ $parameters['oauth_verifier'] = $oauth_verifier;
60
+ }
61
+ $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
62
+ $token = Sputnik_OAuth_Util::parse_parameters($request);
63
+ $this->token = new Sputnik_OAuth_Consumer($token['oauth_token'], $token['oauth_token_secret']);
64
+ return $token;
65
+ }
66
+
67
+ /**
68
+ * One time exchange of username and password for access token and secret.
69
+ *
70
+ * @internal Converted OAuth* to Sputnik_OAuth_*
71
+ * @returns array("oauth_token" => "the-access-token",
72
+ * "oauth_token_secret" => "the-access-secret",
73
+ * "user_id" => "9436992",
74
+ * "screen_name" => "abraham",
75
+ * "x_auth_expires" => "0")
76
+ */
77
+ function getXAuthToken($username, $password) {
78
+ $parameters = array();
79
+ $parameters['x_auth_username'] = $username;
80
+ $parameters['x_auth_password'] = $password;
81
+ $parameters['x_auth_mode'] = 'client_auth';
82
+ $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
83
+ $token = Sputnik_OAuth_Util::parse_parameters($request);
84
+ $this->token = new Sputnik_OAuth_Consumer($token['oauth_token'], $token['oauth_token_secret']);
85
+ return $token;
86
+ }
87
+
88
+ /**
89
+ * Format and sign an OAuth / API request
90
+ *
91
+ * @internal Converted OAuth* to Sputnik_OAuth_*
92
+ */
93
+ function oAuthRequest($url, $method, $parameters) {
94
+ if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
95
+ $url = "{$this->host}{$url}.{$this->format}";
96
+ }
97
+ $request = Sputnik_OAuth_Request::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
98
+ $request->sign_request($this->sha1_method, $this->consumer, $this->token);
99
+ switch ($method) {
100
+ case 'GET':
101
+ return $this->http($request->to_url(), 'GET');
102
+ default:
103
+ return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Make an HTTP request
109
+ *
110
+ * @internal Adapted for WP_Http
111
+ * @return API results
112
+ */
113
+ function http($url, $method, $postfields = NULL) {
114
+ $this->http_info = null; // this is never used
115
+ $options = array(
116
+ 'method' => $method,
117
+ 'timeout' => $this->timeout,
118
+ 'user-agent' => $this->useragent,
119
+ 'sslverify' => $this->ssl_verifypeer
120
+ );
121
+
122
+ switch ($method) {
123
+ case 'POST':
124
+ if (!empty($postfields)) {
125
+ $options['body'] = $postfields;
126
+ }
127
+ break;
128
+ case 'DELETE':
129
+ if (!empty($postfields)) {
130
+ $url = "{$url}?{$postfields}";
131
+ }
132
+ }
133
+
134
+ $response = wp_remote_request($url, $options);
135
+
136
+ if (is_wp_error($response)) {
137
+ $this->http_code = null;
138
+ $this->http_header = array();
139
+ return false;
140
+ }
141
+
142
+ $this->http_code = $response['response']['code'];
143
+ $this->http_header = $response['headers'];
144
+
145
+ return $response['body'];
146
+ }
147
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Library/TwitterOAuth/Internal.php ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * Abraham Williams (abraham@abrah.am) http://abrah.am
5
+ *
6
+ * The first PHP Library to support OAuth for Twitter's REST API.
7
+ */
8
+
9
+ /**
10
+ * Twitter OAuth class
11
+ */
12
+ class Sputnik_Library_TwitterOAuth_Internal {
13
+ /* Contains the last HTTP status code returned. */
14
+ public $http_code;
15
+ /* Contains the last API call. */
16
+ public $url;
17
+ /* Set up the API root URL. */
18
+ public $host = "https://api.twitter.com/1/";
19
+ /* Set timeout default. */
20
+ public $timeout = 30;
21
+ /* Set connect timeout. */
22
+ public $connecttimeout = 30;
23
+ /* Verify SSL Cert. */
24
+ public $ssl_verifypeer = FALSE;
25
+ /* Respons format. */
26
+ public $format = 'json';
27
+ /* Decode returned json data. */
28
+ public $decode_json = TRUE;
29
+ /* Contains the last HTTP headers returned. */
30
+ public $http_info;
31
+ /* Set the useragnet. */
32
+ public $useragent = 'TwitterOAuth v0.2.0-beta2';
33
+ /* Immediately retry the API call if the response was not successful. */
34
+ //public $retry = TRUE;
35
+
36
+
37
+
38
+
39
+ /**
40
+ * Set API URLS
41
+ */
42
+ function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; }
43
+ function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; }
44
+ function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; }
45
+ function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
46
+
47
+ /**
48
+ * Debug helpers
49
+ */
50
+ function lastStatusCode() { return $this->http_status; }
51
+ function lastAPICall() { return $this->last_api_call; }
52
+
53
+ /**
54
+ * construct TwitterOAuth object
55
+ */
56
+ function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
57
+ $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
58
+ $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
59
+ if (!empty($oauth_token) && !empty($oauth_token_secret)) {
60
+ $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
61
+ } else {
62
+ $this->token = NULL;
63
+ }
64
+ }
65
+
66
+
67
+ /**
68
+ * Get a request_token from Twitter
69
+ *
70
+ * @returns a key/value array containing oauth_token and oauth_token_secret
71
+ */
72
+ function getRequestToken($oauth_callback = NULL) {
73
+ $parameters = array();
74
+ if (!empty($oauth_callback)) {
75
+ $parameters['oauth_callback'] = $oauth_callback;
76
+ }
77
+ $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
78
+ $token = OAuthUtil::parse_parameters($request);
79
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
80
+ return $token;
81
+ }
82
+
83
+ /**
84
+ * Get the authorize URL
85
+ *
86
+ * @returns a string
87
+ */
88
+ function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
89
+ if (is_array($token)) {
90
+ $token = $token['oauth_token'];
91
+ }
92
+ if (empty($sign_in_with_twitter)) {
93
+ return $this->authorizeURL() . "?oauth_token={$token}";
94
+ } else {
95
+ return $this->authenticateURL() . "?oauth_token={$token}";
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Exchange request token and secret for an access token and
101
+ * secret, to sign API calls.
102
+ *
103
+ * @returns array("oauth_token" => "the-access-token",
104
+ * "oauth_token_secret" => "the-access-secret",
105
+ * "user_id" => "9436992",
106
+ * "screen_name" => "abraham")
107
+ */
108
+ function getAccessToken($oauth_verifier = FALSE) {
109
+ $parameters = array();
110
+ if (!empty($oauth_verifier)) {
111
+ $parameters['oauth_verifier'] = $oauth_verifier;
112
+ }
113
+ $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
114
+ $token = OAuthUtil::parse_parameters($request);
115
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
116
+ return $token;
117
+ }
118
+
119
+ /**
120
+ * One time exchange of username and password for access token and secret.
121
+ *
122
+ * @returns array("oauth_token" => "the-access-token",
123
+ * "oauth_token_secret" => "the-access-secret",
124
+ * "user_id" => "9436992",
125
+ * "screen_name" => "abraham",
126
+ * "x_auth_expires" => "0")
127
+ */
128
+ function getXAuthToken($username, $password) {
129
+ $parameters = array();
130
+ $parameters['x_auth_username'] = $username;
131
+ $parameters['x_auth_password'] = $password;
132
+ $parameters['x_auth_mode'] = 'client_auth';
133
+ $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
134
+ $token = OAuthUtil::parse_parameters($request);
135
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
136
+ return $token;
137
+ }
138
+
139
+ /**
140
+ * GET wrapper for oAuthRequest.
141
+ */
142
+ function get($url, $parameters = array()) {
143
+ $response = $this->oAuthRequest($url, 'GET', $parameters);
144
+ if ($this->format === 'json' && $this->decode_json) {
145
+ return json_decode($response);
146
+ }
147
+ return $response;
148
+ }
149
+
150
+ /**
151
+ * POST wrapper for oAuthRequest.
152
+ */
153
+ function post($url, $parameters = array()) {
154
+ $response = $this->oAuthRequest($url, 'POST', $parameters);
155
+ if ($this->format === 'json' && $this->decode_json) {
156
+ return json_decode($response);
157
+ }
158
+ return $response;
159
+ }
160
+
161
+ /**
162
+ * DELETE wrapper for oAuthReqeust.
163
+ */
164
+ function delete($url, $parameters = array()) {
165
+ $response = $this->oAuthRequest($url, 'DELETE', $parameters);
166
+ if ($this->format === 'json' && $this->decode_json) {
167
+ return json_decode($response);
168
+ }
169
+ return $response;
170
+ }
171
+
172
+ /**
173
+ * Format and sign an OAuth / API request
174
+ */
175
+ function oAuthRequest($url, $method, $parameters) {
176
+ if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
177
+ $url = "{$this->host}{$url}.{$this->format}";
178
+ }
179
+ $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
180
+ $request->sign_request($this->sha1_method, $this->consumer, $this->token);
181
+ switch ($method) {
182
+ case 'GET':
183
+ return $this->http($request->to_url(), 'GET');
184
+ default:
185
+ return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Make an HTTP request
191
+ *
192
+ * @return API results
193
+ */
194
+ function http($url, $method, $postfields = NULL) {
195
+ $this->http_info = array();
196
+ $ci = curl_init();
197
+ /* Curl settings */
198
+ curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
199
+ curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
200
+ curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
201
+ curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
202
+ curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
203
+ curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
204
+ curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
205
+ curl_setopt($ci, CURLOPT_HEADER, FALSE);
206
+
207
+ switch ($method) {
208
+ case 'POST':
209
+ curl_setopt($ci, CURLOPT_POST, TRUE);
210
+ if (!empty($postfields)) {
211
+ curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
212
+ }
213
+ break;
214
+ case 'DELETE':
215
+ curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
216
+ if (!empty($postfields)) {
217
+ $url = "{$url}?{$postfields}";
218
+ }
219
+ }
220
+
221
+ curl_setopt($ci, CURLOPT_URL, $url);
222
+ $response = curl_exec($ci);
223
+ $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
224
+ $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
225
+ $this->url = $url;
226
+ curl_close ($ci);
227
+ return $response;
228
+ }
229
+
230
+ /**
231
+ * Get the header info to store.
232
+ */
233
+ function getHeader($ch, $header) {
234
+ $i = strpos($header, ':');
235
+ if (!empty($i)) {
236
+ $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
237
+ $value = trim(substr($header, $i + 2));
238
+ $this->http_header[$key] = $value;
239
+ }
240
+ return strlen($header);
241
+ }
242
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Library/TwitterOAuth/LICENSE ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2009 Abraham Williams - http://abrah.am - abraham@poseurte.ch
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
wpsc-components/marketplace-core-v1/library/Sputnik/List/Account.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_List_Account extends Sputnik_List_Install {
4
+ protected $view = 'grid';
5
+ protected $connect_error = false;
6
+
7
+ public function prepare_items() {
8
+ require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
9
+
10
+ global $tabs, $tab, $paged, $type, $term;
11
+
12
+ wp_reset_vars( array( 'tab' ) );
13
+
14
+ $paged = $this->get_pagenum();
15
+
16
+ // These are the tabs which are shown on the page
17
+ $tabs = array();
18
+ $tabs['purchased'] = __( 'Purchased Plugins', 'wpsc' );
19
+ $tabs['yours'] = __( 'Your Plugins', 'wpsc' );
20
+
21
+ $nonmenu_tabs = array( ); //Valid actions to perform which do not have a Menu item.
22
+
23
+ $tabs = apply_filters( 'install_plugins_tabs', $tabs );
24
+ $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
25
+
26
+ // If a non-valid menu tab has been selected, and its not a non-menu action.
27
+ if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
28
+ $tab = key( $tabs );
29
+
30
+ $args = array();
31
+
32
+ try {
33
+ switch ( $tab ) {
34
+ case 'yours':
35
+ add_filter('sputnik_install_row_action_links', array(__CLASS__, 'mangle_action_for_own'), 10, 2);
36
+ add_filter('sputnik_install_grid_action_links', array(__CLASS__, 'mangle_action_for_own'), 10, 2);
37
+ $api = Sputnik_API::get_own();
38
+ break;
39
+
40
+ default:
41
+ case 'purchased':
42
+ $api = Sputnik_API::get_purchased();
43
+ break;
44
+ }
45
+ }
46
+ catch (Exception $e) {
47
+ $this->connect_error = true;
48
+ return false;
49
+ }
50
+
51
+ if (!empty($_REQUEST['view'])) {
52
+ switch ($_REQUEST['view']) {
53
+ case 'grid':
54
+ case 'list':
55
+ $this->view = $_REQUEST['view'];
56
+ break;
57
+ default:
58
+ $this->view = 'grid';
59
+ break;
60
+ }
61
+ } else {
62
+ $this->view = 'grid';
63
+ }
64
+
65
+ $this->items = $api['body'];
66
+
67
+ if (isset($api['headers']['x-pagecount'])) {
68
+ $this->set_pagination_args( array(
69
+ 'total_items' => $api['headers']['x-pagecount'],
70
+ 'per_page' => 30,
71
+ ) );
72
+ }
73
+ }
74
+
75
+ public function no_items() {
76
+ global $tab;
77
+ echo '<p>';
78
+ if ($tab === 'yours') {
79
+ _e( "You haven't created any plugins yet. Check out our <a href='http://developer.renku.me/'>developer documentation</a> to find out how!", 'wpsc' );
80
+ }
81
+ else {
82
+ printf(__( "You haven't purchased any plugins yet. Why not <a href='%s'>buy some</a>?", 'wpsc' ), Sputnik_Admin::build_url());
83
+ }
84
+ echo '</p>';
85
+ }
86
+
87
+ public function get_views() {
88
+ global $tabs, $tab;
89
+
90
+ $display_tabs = array();
91
+ foreach ( (array) $tabs as $action => $text ) {
92
+ $class = ( $action == $tab ) ? ' class="current"' : '';
93
+ $bits = array('tab' => $action);
94
+ if ($this->view !== 'grid') {
95
+ $bits['view'] = $this->view;
96
+ }
97
+ $href = Sputnik_Admin::build_account_url($bits);
98
+ $display_tabs['plugin-install-'.$action] = "<a href='$href'$class>$text</a>";
99
+ }
100
+
101
+ return $display_tabs;
102
+ }
103
+
104
+ public function display_grid() {
105
+ extract( $this->_args );
106
+
107
+ $this->display_tablenav( 'top' );
108
+ ?>
109
+ <div class="grid-view">
110
+ <?php
111
+ $this->display_rows_or_placeholder();
112
+ ?>
113
+ </div>
114
+ <?php
115
+ $this->display_tablenav( 'bottom' );
116
+ }
117
+
118
+ public function display_tablenav( $which ) {
119
+ global $tab;
120
+
121
+ if ($tab === 'account')
122
+ return;
123
+
124
+ $account = Sputnik::get_account();
125
+ if ( 'top' == $which ) { ?>
126
+ <div class="tablenav top">
127
+ <div class="alignright actions">
128
+ <?php
129
+ switch ($this->view) {
130
+ case 'list':
131
+ $view = 'grid';
132
+ $name = __('Grid', 'wpsc' );
133
+ break;
134
+ case 'grid':
135
+ $view = 'list';
136
+ $name = __('List', 'wpsc' );
137
+ break;
138
+ }
139
+ ?>
140
+ <!-- <a href="<?php echo add_query_arg('view', $view) ?>" class="view-as-<?php echo $view; ?> button"><?php echo $name ?></a> -->
141
+ </div>
142
+ <?php
143
+ $this->pagination($which);
144
+ ?>
145
+ <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
146
+ <br class="clear" />
147
+ </div>
148
+ <?php } else { ?>
149
+ <div class="tablenav bottom">
150
+ <?php $this->pagination($which); ?>
151
+ <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
152
+ <br class="clear" />
153
+ </div>
154
+ <?php
155
+ }
156
+ }
157
+
158
+ public static function mangle_action_for_own($actions, $plugin) {
159
+ $actions[] = sprintf('<a href="%s" class="button edit">%s</a>', sprintf(Sputnik::SITE_BASE . '/your-products/edit/%d', $plugin->product_id), _x('Edit', 'edit own product', 'wpsc' ));
160
+ return $actions;
161
+ }
162
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/List/Install.php ADDED
@@ -0,0 +1,466 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_List_Install extends WP_List_Table {
4
+ protected $view = 'grid';
5
+ protected $connect_error = false;
6
+
7
+ public function ajax_user_can() {
8
+ return current_user_can('install_plugins');
9
+ }
10
+
11
+ public function prepare_items() {
12
+ require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
13
+
14
+ global $tabs, $tab, $paged, $type, $term;
15
+
16
+ wp_reset_vars( array( 'tab' ) );
17
+
18
+ $paged = $this->get_pagenum();
19
+
20
+ // These are the tabs which are shown on the page
21
+ $tabs = array();
22
+ $tabs['dashboard'] = __( 'Search', 'wpsc' );
23
+
24
+ if ( Sputnik::account_is_linked() ) {
25
+ $tabs['purchased'] = __( 'Purchased Plugins', 'wpsc' );
26
+ } elseif ( $tab == 'purchased' ) {
27
+ wp_redirect( Sputnik_Admin::build_url() );
28
+ exit;
29
+ }
30
+
31
+ if ( 'search' == $tab )
32
+ $tabs['search'] = __( 'Search Results', 'wpsc' );
33
+ $tabs['featured'] = _x( 'Featured', 'Plugin Installer', 'wpsc' );
34
+ $tabs['popular'] = _x( 'Popular', 'Plugin Installer', 'wpsc' );
35
+ $tabs['new'] = _x( 'Newest', 'Plugin Installer', 'wpsc' );
36
+ $tabs['updated'] = _x( 'Recently Updated', 'Plugin Installer', 'wpsc' );
37
+ $tabs['price'] = _x( 'Lowest Priced', 'Plugin Installer', 'wpsc' );
38
+
39
+ $nonmenu_tabs = array( 'account' ); //Valid actions to perform which do not have a Menu item.
40
+
41
+ $tabs = apply_filters( 'install_plugins_tabs', $tabs );
42
+ $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
43
+
44
+ // If a non-valid menu tab has been selected, and its not a non-menu action.
45
+ if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
46
+ $tab = key( $tabs );
47
+
48
+ $args = array();
49
+
50
+ try {
51
+ switch ( $tab ) {
52
+ case 'purchased':
53
+ $api = Sputnik_API::get_purchased();
54
+ break;
55
+
56
+ case 'search':
57
+ $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
58
+ $api = Sputnik_API::search($term);
59
+ break;
60
+
61
+ case 'account':
62
+ $api = Sputnik_API::get_purchased();
63
+ break;
64
+
65
+ case 'featured':
66
+ case 'popular':
67
+ case 'new':
68
+ case 'updated':
69
+ case 'price':
70
+ default:
71
+ $api = Sputnik_API::get_all($paged, array('browse' => $tab));
72
+ break;
73
+ }
74
+ }
75
+ catch (Exception $e) {
76
+ $this->connect_error = true;
77
+ return false;
78
+ }
79
+
80
+ if (!empty($_REQUEST['view'])) {
81
+ switch ($_REQUEST['view']) {
82
+ case 'grid':
83
+ case 'list':
84
+ $this->view = $_REQUEST['view'];
85
+ break;
86
+ default:
87
+ $this->view = 'grid';
88
+ break;
89
+ }
90
+ } else {
91
+ $this->view = 'grid';
92
+ }
93
+
94
+ $this->items = $api['body'];
95
+
96
+ $total_items = isset( $api['headers']['x-pagecount'] ) ? $api['headers']['x-pagecount'] : -1;
97
+
98
+ $this->set_pagination_args( array(
99
+ 'total_items' => $total_items,
100
+ 'per_page' => 30,
101
+ ) );
102
+ }
103
+
104
+ public function no_items() {
105
+ global $tab;
106
+
107
+ echo '<p>';
108
+ if ( $tab == 'purchased' )
109
+ printf( __( "You haven't purchased any add-ons yet. <a href='%s'>Browse our add-on collection.</a>", 'wpsc' ), Sputnik_Admin::build_url() );
110
+ else
111
+ _e( 'No plugins match your request.', 'wpsc' );
112
+ echo '</p>';
113
+ }
114
+
115
+ public function get_views() {
116
+ global $tabs, $tab;
117
+
118
+ $display_tabs = array();
119
+ foreach ( (array) $tabs as $action => $text ) {
120
+ $class = ( $action == $tab ) ? ' class="current"' : '';
121
+ $bits = array('tab' => $action);
122
+ if ($this->view !== 'grid') {
123
+ $bits['view'] = $this->view;
124
+ }
125
+ $href = Sputnik_Admin::build_url($bits);
126
+ $display_tabs['plugin-install-'.$action] = "<a href='$href'$class>$text</a>";
127
+ }
128
+
129
+ return $display_tabs;
130
+ }
131
+
132
+ public function display() {
133
+ if ($this->connect_error) {
134
+ ?>
135
+ <div class="connect-error">
136
+ <h2>Whoops!</h2>
137
+ <p>We don't appear to be able to connect to the WPEConomy server right now.
138
+ Try again later!</p>
139
+ </div>
140
+ <?php
141
+ return;
142
+ }
143
+ switch ($this->view) {
144
+ case 'list':
145
+ parent::display();
146
+ break;
147
+ default:
148
+ $this->display_grid();
149
+ break;
150
+ }
151
+ }
152
+
153
+ public function display_grid() {
154
+ extract( $this->_args );
155
+
156
+ $this->display_tablenav( 'top' );
157
+ ?>
158
+ <div class="grid-view">
159
+ <?php
160
+ $this->display_rows_or_placeholder();
161
+ ?>
162
+ </div>
163
+ <?php
164
+ $this->display_tablenav( 'bottom' );
165
+ }
166
+
167
+ public function display_tablenav( $which ) {
168
+ global $tab;
169
+
170
+ if ($tab === 'account')
171
+ return;
172
+
173
+ if ( ! Sputnik::account_is_linked() )
174
+ return;
175
+
176
+ $account = Sputnik::get_account();
177
+ if ( 'top' == $which ) { ?>
178
+ <div class="tablenav top">
179
+ <div class="alignright actions">
180
+ <?php
181
+ if ( in_array( $tab, array( 'dashboard', 'search' ) ) ) {
182
+ ?>
183
+ <?php Sputnik_Admin::search_form(); ?>
184
+ <?php
185
+ }
186
+
187
+ switch ($this->view) {
188
+ case 'list':
189
+ $view = 'grid';
190
+ $name = __('Grid', 'wpsc' );
191
+ break;
192
+ case 'grid':
193
+ $view = 'list';
194
+ $name = __('List', 'wpsc' );
195
+ break;
196
+ }
197
+ ?>
198
+ <!--<a href="<?php echo add_query_arg('view', $view) ?>" class="view-as-<?php echo $view; ?> button"><?php echo $name ?></a>-->
199
+ </div>
200
+ <?php
201
+ $this->pagination($which);
202
+ ?>
203
+ <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
204
+ <br class="clear" />
205
+ </div>
206
+ <?php } else { ?>
207
+ <div class="tablenav bottom">
208
+ <?php $this->pagination($which); ?>
209
+ <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
210
+ <br class="clear" />
211
+ </div>
212
+ <?php
213
+ }
214
+ }
215
+
216
+ public function get_table_classes() {
217
+ extract( $this->_args );
218
+
219
+ return array( 'plugin-install', 'widefat', $plural );
220
+ }
221
+
222
+ public function get_columns() {
223
+ return array(
224
+ 'name' => _x( 'Name', 'plugin name', 'wpsc' ),
225
+ 'version' => __( 'Version', 'wpsc' ),
226
+ 'price' => __( 'Action', 'wpsc' ),
227
+ 'rating' => __( 'Rating', 'wpsc' ),
228
+ 'description' => __( 'Description', 'wpsc' ),
229
+ );
230
+ }
231
+
232
+ public function display_rows() {
233
+ $plugins_allowedtags = array(
234
+ 'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
235
+ 'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
236
+ 'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
237
+ 'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
238
+ );
239
+
240
+ list( $columns, $hidden ) = $this->get_column_info();
241
+
242
+ $style = array();
243
+ foreach ( $columns as $column_name => $column_display_name ) {
244
+ $style[ $column_name ] = in_array( $column_name, $hidden ) ? 'style="display:none;"' : '';
245
+ }
246
+
247
+ foreach ( (array) $this->items as $plugin ) {
248
+ $plugin->title = wp_kses( $plugin->name, $plugins_allowedtags );
249
+ //Limit description to 400char, and remove any HTML.
250
+ $plugin->description = strip_tags( $plugin->description );
251
+ if ( strlen( $plugin->description ) > 400 )
252
+ $plugin->description = mb_substr( $plugin->description, 0, 400 ) . '&#8230;';
253
+ //remove any trailing entities
254
+ $plugin->description = preg_replace( '/&[^;\s]{0,6}$/', '', $plugin->description );
255
+ //strip leading/trailing & multiple consecutive lines
256
+ $plugin->description = trim( $plugin->description );
257
+ $plugin->description = preg_replace( "|(\r?\n)+|", "\n", $plugin->description );
258
+ //\n => <br>
259
+ $plugin->description = nl2br( $plugin->description );
260
+ $plugin->version = wp_kses( $plugin->version, $plugins_allowedtags );
261
+ $plugin->price = sprintf('$%.2f', $plugin->price);
262
+ if ($plugin->price === '$0.00') {
263
+ $plugin->price = _x('Free', 'plugin price', 'wpsc' );
264
+ }
265
+
266
+ $plugin->author = $plugin->author;
267
+ if (!empty($plugin->author))
268
+ $plugin->author = ' <cite>' . sprintf( __( 'By %s', 'wpsc' ), $plugin->author ) . '.</cite>';
269
+
270
+ $plugin->author = wp_kses( $plugin->author, $plugins_allowedtags );
271
+
272
+ switch ($this->view) {
273
+ case 'list':
274
+ self::display_row($plugin, $style);
275
+ break;
276
+ default:
277
+ self::display_as_grid($plugin, $style);
278
+ break;
279
+ }
280
+ }
281
+ }
282
+
283
+ protected static function display_row($plugin, $style) {
284
+ $name = strip_tags( $plugin->name . ' ' . $plugin->version );
285
+ $action_links = array();
286
+ $action_links[] = '<a href="' . Sputnik_Admin::build_url(array('info' => $plugin->slug, 'TB_iframe' => true))
287
+ . '" class="thickbox info" title="' .
288
+ esc_attr( sprintf( __( 'More information about %s', 'wpsc' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
289
+
290
+ $purchase_link = $plugin->price;
291
+
292
+ if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
293
+ $status = Sputnik_Admin::install_status( $plugin );
294
+
295
+ switch ( $status['status'] ) {
296
+ case 'purchase':
297
+ if ( $status['url'] ) {
298
+ $purchase_link = '<a id="' . $plugin->slug . '" class="button-primary buy" href="' . $status['url'] . '" title="'
299
+ . esc_attr(sprintf(__( 'Buy %s', 'wpsc' ), $name)) . '">' . sprintf(__('<span>%s</span> Buy Now</a>', 'wpsc' ), $plugin->price);
300
+ }
301
+ break;
302
+ case 'install':
303
+ if ( $status['url'] ) {
304
+ $status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 700, 'height' => 550), $status['url']);
305
+ $purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
306
+ . esc_attr(sprintf(__( 'Install %s', 'wpsc' ), $name)) . '">' . __('Install', 'wpsc' ) . '</a>';
307
+ }
308
+ else {
309
+ $purchase_link = '<span title="' . esc_attr__('Cannot auto-install, report this as a bug', 'wpsc' ) . '">'
310
+ . __('Install', 'wpsc' ) . '</span>';
311
+ }
312
+ break;
313
+ case 'update_available':
314
+ if ( $status['url'] ) {
315
+ $status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 700, 'height' => 550), $status['url']);
316
+ $purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
317
+ . esc_attr(sprintf(__( 'Update to version %s', 'wpsc' ), $status['version'])) . '">' . __('Update', 'wpsc' ) . '</a>';
318
+ }
319
+ else {
320
+ $purchase_link = '<span title="' . esc_attr__('Cannot auto-install, report this as a bug', 'wpsc' ) . '">'
321
+ . __('Update', 'wpsc' ) . '</span>';
322
+ }
323
+ break;
324
+ case 'latest_installed':
325
+ case 'newer_installed':
326
+ $purchase_link = '<span title="' . esc_attr__('This plugin is already installed and is up to date', 'wpsc' ) . ' ">'
327
+ . __('Installed', 'wpsc' ) . '</span>';
328
+ break;
329
+ }
330
+ }
331
+
332
+ $action_links = apply_filters( 'sputnik_install_row_action_links', $action_links, $plugin );
333
+ ?>
334
+ <tr>
335
+ <td class="name column-name"<?php echo $style['name']; ?>><strong><?php echo $plugin->title; ?></strong>
336
+ <div class="action-links"><?php if ( !empty( $action_links ) ) echo implode( ' | ', $action_links ); ?></div>
337
+ </td>
338
+ <td class="vers column-version"<?php echo $style['version']; ?>><?php echo $plugin->version; ?></td>
339
+ <td class="vers column-price"<?php echo $style['price']; ?>><?php echo $purchase_link; ?></td>
340
+ <td style="display:none" class="vers column-rating"<?php echo $style['rating']; ?>>
341
+ <div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->rating->count, 'wpsc' ), number_format_i18n( $plugin->rating->count ) ) ?>">
342
+ <div class="star star-rating" style="width: <?php echo (int) (20 * $plugin->rating->average) ?>px"></div>
343
+ <?php
344
+ $color = get_user_option('admin_color');
345
+ if ( empty($color) || 'fresh' == $color )
346
+ $star_url = admin_url( 'images/stars.png?v=20110615' ); // 'Fresh' Gray star for list tables
347
+ else
348
+ $star_url = admin_url( 'images/stars.png?v=20110615' ); // 'Classic' Blue star
349
+ ?>
350
+ <div class="star star5"><img src="<?php echo $star_url; ?>" alt="" /></div>
351
+ <div class="star star4"><img src="<?php echo $star_url; ?>" alt="" /></div>
352
+ <div class="star star3"><img src="<?php echo $star_url; ?>" alt="" /></div>
353
+ <div class="star star2"><img src="<?php echo $star_url; ?>" alt="" /></div>
354
+ <div class="star star1"><img src="<?php echo $star_url; ?>" alt="" /></div>
355
+ </div>
356
+ </td>
357
+ <td class="desc column-description"<?php echo $style['description']; ?>><?php echo $plugin->description, $plugin->author; ?></td>
358
+ </tr>
359
+ <?php
360
+ }
361
+
362
+ protected static function display_as_grid($plugin, $style) {
363
+
364
+ $name = strip_tags( $plugin->name . ' ' . $plugin->version );
365
+ $action_links = array();
366
+ $action_links[] = '<a href="' . Sputnik_Admin::build_url(array('info' => $plugin->slug, 'TB_iframe' => true))
367
+ . '" class="thickbox button info" title="' .
368
+ esc_attr( sprintf( __( 'More information about %s', 'wpsc' ), $name ) ) . '">' . __( 'Details', 'wpsc' ) . '</a>';
369
+
370
+ $purchase_link = $plugin->price;
371
+
372
+ if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
373
+ $status = Sputnik_Admin::install_status( $plugin );
374
+
375
+ switch ( $status['status'] ) {
376
+ case 'purchase':
377
+ if ( $status['url'] ) {
378
+ $purchase_link = '<a id="' . $plugin->slug . '" class="button-primary buy status" href="' . $status['url'] . '" title="'
379
+ . esc_attr(sprintf(__( 'Buy %s', 'wpsc' ), $name)) . '">' . __('Buy Now', 'wpsc' ) . '</a>';
380
+ }
381
+ break;
382
+ case 'install':
383
+ if ( $status['url'] ) {
384
+ $status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 700, 'height' => 550), $status['url']);
385
+ $purchase_link = '<a class="button install status" href="' . $status['url'] . '" title="'
386
+ . esc_attr(sprintf(__( 'Install %s', 'wpsc' ), $name)) . '">' . __('Install', 'wpsc' ) . '</a>';
387
+ }
388
+ else {
389
+ $purchase_link = '<span class="status" title="' . esc_attr__('Cannot auto-install, report this as a bug', 'wpsc' ) . '">'
390
+ . __('Install', 'wpsc' ) . '</span>';
391
+ }
392
+ break;
393
+ case 'update_available':
394
+ if ( $status['url'] ) {
395
+ $status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 700, 'height' => 550), $status['url']);
396
+ $purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
397
+ . esc_attr(sprintf(__( 'Update to version %s', 'wpsc' ), $status['version'])) . '">' . __('Update', 'wpsc' ) . '</a>';
398
+ }
399
+ else {
400
+ $purchase_link = '<span class="status" title="' . esc_attr__('Cannot auto-install, report this as a bug', 'wpsc' ) . '">'
401
+ . __('Update', 'wpsc' ) . '</span>';
402
+ }
403
+ break;
404
+ case 'latest_installed':
405
+ case 'newer_installed':
406
+ $purchase_link = '<span class="status" title="' . esc_attr__('This plugin is already installed and is up to date', 'wpsc' ) . ' ">'
407
+ . __('Installed', 'wpsc' ) . '</span>';
408
+ break;
409
+ }
410
+ }
411
+
412
+ $action_links = apply_filters( 'sputnik_install_grid_action_links', $action_links, $plugin );
413
+
414
+ $thumb = false;
415
+ if (isset($plugin->thumb) && $plugin->thumb !== false) {
416
+ $thumb = $plugin->thumb;
417
+ }
418
+ if ( 'klarna-payment-gateway' == $plugin->slug )
419
+ $thumb = 'https://github.com/JustinSainton/Klarna/raw/assets/thumb.png';
420
+ ?>
421
+ <div>
422
+ <div class="sputnik-plugin<?php if ($thumb !== false) echo ' has-thumb'; ?>">
423
+ <div class="sputnik-card">
424
+ <?php
425
+ if ( $thumb !== false ):
426
+ ?>
427
+ <div class="sputnik-plugin-thumb">
428
+ <img src="<?php echo esc_url($thumb) ?>" alt="<?php echo esc_attr($name) ?> Thumbnail">
429
+ </div>
430
+ <?php
431
+ endif;
432
+ ?>
433
+ <div class="sputnik-plugin-details">
434
+ <h4><?php echo $name ?></h4>
435
+ <span class="price"><?php echo $plugin->price ?></span>
436
+ <p><?php echo $plugin->description ?></p>
437
+ <?php if ( isset( $plugin->rating ) && isset( $plugin->rating->count ) ): ?>
438
+ <div class="footer" style="display:none">
439
+ <div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->rating->count, 'wpsc' ), number_format_i18n( $plugin->rating->count ) ) ?>">
440
+ <div class="star star-rating" style="width: <?php echo (int) (20 * $plugin->rating->average) ?>px"></div>
441
+ <?php
442
+ $color = get_user_option('admin_color');
443
+ if ( empty($color) || 'fresh' == $color )
444
+ $star_url = admin_url( 'images/stars.png?v=20110615' ); // 'Fresh' Gray star for list tables
445
+ else
446
+ $star_url = admin_url( 'images/stars.png?v=20110615' ); // 'Classic' Blue star
447
+ ?>
448
+ <div class="star star5"><img src="<?php echo $star_url; ?>" alt="" /></div>
449
+ <div class="star star4"><img src="<?php echo $star_url; ?>" alt="" /></div>
450
+ <div class="star star3"><img src="<?php echo $star_url; ?>" alt="" /></div>
451
+ <div class="star star2"><img src="<?php echo $star_url; ?>" alt="" /></div>
452
+ <div class="star star1"><img src="<?php echo $star_url; ?>" alt="" /></div>
453
+ </div>
454
+ </div>
455
+ <?php endif; ?>
456
+ </div>
457
+ </div>
458
+ </div>
459
+ <div class="sputnik-plugin-actions">
460
+ <?php if ( !empty( $action_links ) ) echo implode( ' ', $action_links ); ?>
461
+ <?php echo $purchase_link; ?>
462
+ </div>
463
+ </div>
464
+ <?php
465
+ }
466
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Consumer.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_OAuth_Consumer {
4
+ public $key;
5
+ public $secret;
6
+
7
+ function __construct($key, $secret, $callback_url=NULL) {
8
+ $this->key = $key;
9
+ $this->secret = $secret;
10
+ $this->callback_url = $callback_url;
11
+ }
12
+
13
+ function __toString() {
14
+ return "Sputnik_OAuth_Consumer[key=$this->key,secret=$this->secret]";
15
+ }
16
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/DataStore.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_OAuth_DataStore {
4
+ function lookup_consumer($consumer_key) {
5
+ // implement me
6
+ }
7
+
8
+ function lookup_token($consumer, $token_type, $token) {
9
+ // implement me
10
+ }
11
+
12
+ function lookup_nonce($consumer, $token, $nonce, $timestamp) {
13
+ // implement me
14
+ }
15
+
16
+ function new_request_token($consumer, $callback = null) {
17
+ // return a new token attached to this consumer
18
+ }
19
+
20
+ function new_access_token($token, $consumer, $verifier = null) {
21
+ // return a new access token attached to this consumer
22
+ // for the user associated with this token if the request token
23
+ // is authorized
24
+ // should also invalidate the request token
25
+ }
26
+
27
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Exception.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Generic exception class
4
+ */
5
+ class Sputnik_OAuth_Exception extends Exception {
6
+ // pass
7
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Request.php ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_OAuth_Request {
4
+ protected $parameters;
5
+ protected $http_method;
6
+ protected $http_url;
7
+ // for debug purposes
8
+ public $base_string;
9
+ public static $version = '1.0';
10
+ public static $POST_INPUT = 'php://input';
11
+
12
+ function __construct($http_method, $http_url, $parameters=NULL) {
13
+ $parameters = ($parameters) ? $parameters : array();
14
+ $parameters = array_merge( Sputnik_OAuth_Util::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
15
+ $this->parameters = $parameters;
16
+ $this->http_method = $http_method;
17
+ $this->http_url = $http_url;
18
+ }
19
+
20
+
21
+ /**
22
+ * attempt to build up a request from what was passed to the server
23
+ */
24
+ public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) {
25
+ $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
26
+ ? 'http'
27
+ : 'https';
28
+ $http_url = ($http_url) ? $http_url : $scheme .
29
+ '://' . $_SERVER['SERVER_NAME'] .
30
+ ':' .
31
+ $_SERVER['SERVER_PORT'] .
32
+ $_SERVER['REQUEST_URI'];
33
+ $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD'];
34
+
35
+ // We weren't handed any parameters, so let's find the ones relevant to
36
+ // this request.
37
+ // If you run XML-RPC or similar you should use this to provide your own
38
+ // parsed parameter-list
39
+ if (!$parameters) {
40
+ // Find request headers
41
+ $request_headers = Sputnik_OAuth_Util::get_headers();
42
+
43
+ // Parse the query-string to find GET parameters
44
+ $parameters = Sputnik_OAuth_Util::parse_parameters($_SERVER['QUERY_STRING']);
45
+
46
+ // It's a POST request of the proper content-type, so parse POST
47
+ // parameters and add those overriding any duplicates from GET
48
+ if ($http_method == "POST"
49
+ && isset($request_headers['Content-Type'])
50
+ && strstr($request_headers['Content-Type'],
51
+ 'application/x-www-form-urlencoded')
52
+ ) {
53
+ $post_data = Sputnik_OAuth_Util::parse_parameters(
54
+ file_get_contents(self::$POST_INPUT)
55
+ );
56
+ $parameters = array_merge($parameters, $post_data);
57
+ }
58
+
59
+ // We have a Authorization-header with OAuth data. Parse the header
60
+ // and add those overriding any duplicates from GET or POST
61
+ if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') {
62
+ $header_parameters = Sputnik_OAuth_Util::split_header(
63
+ $request_headers['Authorization']
64
+ );
65
+ $parameters = array_merge($parameters, $header_parameters);
66
+ }
67
+
68
+ }
69
+
70
+ return new Sputnik_OAuth_Request($http_method, $http_url, $parameters);
71
+ }
72
+
73
+ /**
74
+ * pretty much a helper function to set up the request
75
+ */
76
+ public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {
77
+ $parameters = ($parameters) ? $parameters : array();
78
+ $defaults = array("oauth_version" => Sputnik_OAuth_Request::$version,
79
+ "oauth_nonce" => Sputnik_OAuth_Request::generate_nonce(),
80
+ "oauth_timestamp" => Sputnik_OAuth_Request::generate_timestamp(),
81
+ "oauth_consumer_key" => $consumer->key);
82
+ if ($token)
83
+ $defaults['oauth_token'] = $token->key;
84
+
85
+ $parameters = array_merge($defaults, $parameters);
86
+
87
+ return new Sputnik_OAuth_Request($http_method, $http_url, $parameters);
88
+ }
89
+
90
+ public function set_parameter($name, $value, $allow_duplicates = true) {
91
+ if ($allow_duplicates && isset($this->parameters[$name])) {
92
+ // We have already added parameter(s) with this name, so add to the list
93
+ if (is_scalar($this->parameters[$name])) {
94
+ // This is the first duplicate, so transform scalar (string)
95
+ // into an array so we can add the duplicates
96
+ $this->parameters[$name] = array($this->parameters[$name]);
97
+ }
98
+
99
+ $this->parameters[$name][] = $value;
100
+ } else {
101
+ $this->parameters[$name] = $value;
102
+ }
103
+ }
104
+
105
+ public function get_parameter($name) {
106
+ return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
107
+ }
108
+
109
+ public function get_parameters() {
110
+ return $this->parameters;
111
+ }
112
+
113
+ public function unset_parameter($name) {
114
+ unset($this->parameters[$name]);
115
+ }
116
+
117
+ /**
118
+ * The request parameters, sorted and concatenated into a normalized string.
119
+ * @return string
120
+ */
121
+ public function get_signable_parameters() {
122
+ // Grab all parameters
123
+ $params = $this->parameters;
124
+
125
+ // Remove oauth_signature if present
126
+ // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
127
+ if (isset($params['oauth_signature'])) {
128
+ unset($params['oauth_signature']);
129
+ }
130
+
131
+ return Sputnik_OAuth_Util::build_http_query($params);
132
+ }
133
+
134
+ /**
135
+ * Returns the base string of this request
136
+ *
137
+ * The base string defined as the method, the url
138
+ * and the parameters (normalized), each urlencoded
139
+ * and the concated with &.
140
+ */
141
+ public function get_signature_base_string() {
142
+ $parts = array(
143
+ $this->get_normalized_http_method(),
144
+ $this->get_normalized_http_url(),
145
+ $this->get_signable_parameters()
146
+ );
147
+
148
+ $parts = Sputnik_OAuth_Util::urlencode_rfc3986($parts);
149
+
150
+ return implode('&', $parts);
151
+ }
152
+
153
+ /**
154
+ * just uppercases the http method
155
+ */
156
+ public function get_normalized_http_method() {
157
+ return strtoupper($this->http_method);
158
+ }
159
+
160
+ /**
161
+ * parses the url and rebuilds it to be
162
+ * scheme://host/path
163
+ */
164
+ public function get_normalized_http_url() {
165
+ $parts = parse_url($this->http_url);
166
+
167
+ $scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http';
168
+ $port = (isset($parts['port'])) ? $parts['port'] : (($scheme == 'https') ? '443' : '80');
169
+ $host = (isset($parts['host'])) ? strtolower($parts['host']) : '';
170
+ $path = (isset($parts['path'])) ? $parts['path'] : '';
171
+
172
+ if (($scheme == 'https' && $port != '443')
173
+ || ($scheme == 'http' && $port != '80')) {
174
+ $host = "$host:$port";
175
+ }
176
+ return "$scheme://$host$path";
177
+ }
178
+
179
+ /**
180
+ * builds a url usable for a GET request
181
+ */
182
+ public function to_url() {
183
+ $post_data = $this->to_postdata();
184
+ $out = $this->get_normalized_http_url();
185
+ if ($post_data) {
186
+ $out .= '?'.$post_data;
187
+ }
188
+ return $out;
189
+ }
190
+
191
+ /**
192
+ * builds the data one would send in a POST request
193
+ */
194
+ public function to_postdata() {
195
+ return Sputnik_OAuth_Util::build_http_query($this->parameters);
196
+ }
197
+
198
+ /**
199
+ * builds the Authorization: header
200
+ */
201
+ public function to_header($realm=null) {
202
+ $first = true;
203
+ if($realm) {
204
+ $out = 'Authorization: OAuth realm="' . Sputnik_OAuth_Util::urlencode_rfc3986($realm) . '"';
205
+ $first = false;
206
+ } else
207
+ $out = 'Authorization: OAuth';
208
+
209
+ $total = array();
210
+ foreach ($this->parameters as $k => $v) {
211
+ if (substr($k, 0, 5) != "oauth") continue;
212
+ if (is_array($v)) {
213
+ throw new Sputnik_OAuth_Exception('Arrays not supported in headers');
214
+ }
215
+ $out .= ($first) ? ' ' : ',';
216
+ $out .= Sputnik_OAuth_Util::urlencode_rfc3986($k) .
217
+ '="' .
218
+ Sputnik_OAuth_Util::urlencode_rfc3986($v) .
219
+ '"';
220
+ $first = false;
221
+ }
222
+ return $out;
223
+ }
224
+
225
+ public function __toString() {
226
+ return $this->to_url();
227
+ }
228
+
229
+
230
+ public function sign_request($signature_method, $consumer, $token) {
231
+ $this->set_parameter(
232
+ "oauth_signature_method",
233
+ $signature_method->get_name(),
234
+ false
235
+ );
236
+ $signature = $this->build_signature($signature_method, $consumer, $token);
237
+ $this->set_parameter("oauth_signature", $signature, false);
238
+ }
239
+
240
+ public function build_signature($signature_method, $consumer, $token) {
241
+ $signature = $signature_method->build_signature($this, $consumer, $token);
242
+ return $signature;
243
+ }
244
+
245
+ /**
246
+ * util function: current timestamp
247
+ */
248
+ private static function generate_timestamp() {
249
+ return time();
250
+ }
251
+
252
+ /**
253
+ * util function: current nonce
254
+ */
255
+ private static function generate_nonce() {
256
+ $mt = microtime();
257
+ $rand = mt_rand();
258
+
259
+ return md5($mt . $rand); // md5s look nicer than numbers
260
+ }
261
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Server.php ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_OAuth_Server {
4
+ protected $timestamp_threshold = 1200; // in seconds, twenty minutes
5
+ protected $version = '1.0'; // hi blaine
6
+ protected $signature_methods = array();
7
+
8
+ protected $data_store;
9
+
10
+ function __construct($data_store) {
11
+ $this->data_store = $data_store;
12
+ }
13
+
14
+ public function add_signature_method($signature_method) {
15
+ $this->signature_methods[$signature_method->get_name()] =
16
+ $signature_method;
17
+ }
18
+
19
+ // high level functions
20
+
21
+ /**
22
+ * process a request_token request
23
+ * returns the request token on success
24
+ */
25
+ public function fetch_request_token(&$request) {
26
+ $this->get_version($request);
27
+
28
+ $consumer = $this->get_consumer($request);
29
+
30
+ // no token required for the initial token request
31
+ $token = NULL;
32
+
33
+ $this->check_signature($request, $consumer, $token);
34
+
35
+ // Rev A change
36
+ $callback = $request->get_parameter('oauth_callback');
37
+ $new_token = $this->data_store->new_request_token($consumer, $callback);
38
+
39
+ return $new_token;
40
+ }
41
+
42
+ /**
43
+ * process an access_token request
44
+ * returns the access token on success
45
+ */
46
+ public function fetch_access_token(&$request) {
47
+ $this->get_version($request);
48
+
49
+ $consumer = $this->get_consumer($request);
50
+
51
+ // requires authorized request token
52
+ $token = $this->get_token($request, $consumer, "request");
53
+
54
+ $this->check_signature($request, $consumer, $token);
55
+
56
+ // Rev A change
57
+ $verifier = $request->get_parameter('oauth_verifier');
58
+ $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
59
+
60
+ return $new_token;
61
+ }
62
+
63
+ /**
64
+ * verify an api call, checks all the parameters
65
+ */
66
+ public function verify_request(&$request) {
67
+ $this->get_version($request);
68
+ $consumer = $this->get_consumer($request);
69
+ $token = $this->get_token($request, $consumer, "access");
70
+ $this->check_signature($request, $consumer, $token);
71
+ return array($consumer, $token);
72
+ }
73
+
74
+ // Internals from here
75
+ /**
76
+ * version 1
77
+ */
78
+ private function get_version(&$request) {
79
+ $version = $request->get_parameter("oauth_version");
80
+ if (!$version) {
81
+ // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
82
+ // Chapter 7.0 ("Accessing Protected Ressources")
83
+ $version = '1.0';
84
+ }
85
+ if ($version !== $this->version) {
86
+ throw new Sputnik_OAuth_Exception("OAuth version '$version' not supported");
87
+ }
88
+ return $version;
89
+ }
90
+
91
+ /**
92
+ * figure out the signature with some defaults
93
+ */
94
+ private function get_signature_method($request) {
95
+ $signature_method = $request instanceof Sputnik_OAuth_Request
96
+ ? $request->get_parameter("oauth_signature_method")
97
+ : NULL;
98
+
99
+ if (!$signature_method) {
100
+ // According to chapter 7 ("Accessing Protected Ressources") the signature-method
101
+ // parameter is required, and we can't just fallback to PLAINTEXT
102
+ throw new Sputnik_OAuth_Exception('No signature method parameter. This parameter is required');
103
+ }
104
+
105
+ if (!in_array($signature_method,
106
+ array_keys($this->signature_methods))) {
107
+ throw new Sputnik_OAuth_Exception(
108
+ "Signature method '$signature_method' not supported " .
109
+ "try one of the following: " .
110
+ implode(", ", array_keys($this->signature_methods))
111
+ );
112
+ }
113
+ return $this->signature_methods[$signature_method];
114
+ }
115
+
116
+ /**
117
+ * try to find the consumer for the provided request's consumer key
118
+ */
119
+ private function get_consumer($request) {
120
+ $consumer_key = $request instanceof Sputnik_OAuth_Request
121
+ ? $request->get_parameter("oauth_consumer_key")
122
+ : NULL;
123
+
124
+ if (!$consumer_key) {
125
+ throw new Sputnik_OAuth_Exception("Invalid consumer key");
126
+ }
127
+
128
+ $consumer = $this->data_store->lookup_consumer($consumer_key);
129
+ if (!$consumer) {
130
+ throw new Sputnik_OAuth_Exception("Invalid consumer");
131
+ }
132
+
133
+ return $consumer;
134
+ }
135
+
136
+ /**
137
+ * try to find the token for the provided request's token key
138
+ */
139
+ private function get_token($request, $consumer, $token_type="access") {
140
+ $token_field = $request instanceof Sputnik_OAuth_Request
141
+ ? $request->get_parameter('oauth_token')
142
+ : NULL;
143
+
144
+ $token = $this->data_store->lookup_token(
145
+ $consumer, $token_type, $token_field
146
+ );
147
+ if (!$token) {
148
+ throw new Sputnik_OAuth_Exception("Invalid $token_type token: $token_field");
149
+ }
150
+ return $token;
151
+ }
152
+
153
+ /**
154
+ * all-in-one function to check the signature on a request
155
+ * should guess the signature method appropriately
156
+ */
157
+ private function check_signature($request, $consumer, $token) {
158
+ // this should probably be in a different method
159
+ $timestamp = $request instanceof Sputnik_OAuth_Request
160
+ ? $request->get_parameter('oauth_timestamp')
161
+ : NULL;
162
+ $nonce = $request instanceof Sputnik_OAuth_Request
163
+ ? $request->get_parameter('oauth_nonce')
164
+ : NULL;
165
+
166
+ $this->check_timestamp($timestamp);
167
+ $this->check_nonce($consumer, $token, $nonce, $timestamp);
168
+
169
+ $signature_method = $this->get_signature_method($request);
170
+
171
+ $signature = $request->get_parameter('oauth_signature');
172
+ $valid_sig = $signature_method->check_signature(
173
+ $request,
174
+ $consumer,
175
+ $token,
176
+ $signature
177
+ );
178
+
179
+ if (!$valid_sig) {
180
+ throw new Sputnik_OAuth_Exception("Invalid signature");
181
+ }
182
+ }
183
+
184
+ /**
185
+ * check that the timestamp is new enough
186
+ */
187
+ private function check_timestamp($timestamp) {
188
+ if( ! $timestamp )
189
+ throw new Sputnik_OAuth_Exception(
190
+ 'Missing timestamp parameter. The parameter is required'
191
+ );
192
+
193
+ // verify that timestamp is recentish
194
+ $now = time();
195
+ if (abs($now - $timestamp) > $this->timestamp_threshold) {
196
+ throw new Sputnik_OAuth_Exception(
197
+ "Expired timestamp, yours $timestamp, ours $now"
198
+ );
199
+ }
200
+ }
201
+
202
+ /**
203
+ * check that the nonce is not repeated
204
+ */
205
+ private function check_nonce($consumer, $token, $nonce, $timestamp) {
206
+ if( ! $nonce )
207
+ throw new Sputnik_OAuth_Exception(
208
+ 'Missing nonce parameter. The parameter is required'
209
+ );
210
+
211
+ // verify that the nonce is uniqueish
212
+ $found = $this->data_store->lookup_nonce(
213
+ $consumer,
214
+ $token,
215
+ $nonce,
216
+ $timestamp
217
+ );
218
+ if ($found) {
219
+ throw new Sputnik_OAuth_Exception("Nonce already used: $nonce");
220
+ }
221
+ }
222
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/SignatureMethod.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A class for implementing a Signature Method
5
+ * See section 9 ("Signing Requests") in the spec
6
+ */
7
+ abstract class Sputnik_OAuth_SignatureMethod {
8
+ /**
9
+ * Needs to return the name of the Signature Method (ie HMAC-SHA1)
10
+ * @return string
11
+ */
12
+ abstract public function get_name();
13
+
14
+ /**
15
+ * Build up the signature
16
+ * NOTE: The output of this function MUST NOT be urlencoded.
17
+ * the encoding is handled in Sputnik_OAuth_Request when the final
18
+ * request is serialized
19
+ * @param Sputnik_OAuth_Request $request
20
+ * @param Sputnik_OAuth_Consumer $consumer
21
+ * @param Sputnik_OAuth_Token $token
22
+ * @return string
23
+ */
24
+ abstract public function build_signature($request, $consumer, $token);
25
+
26
+ /**
27
+ * Verifies that a given signature is correct
28
+ * @param Sputnik_OAuth_Request $request
29
+ * @param Sputnik_OAuth_Consumer $consumer
30
+ * @param Sputnik_OAuth_Token $token
31
+ * @param string $signature
32
+ * @return bool
33
+ */
34
+ public function check_signature($request, $consumer, $token, $signature) {
35
+ $built = $this->build_signature($request, $consumer, $token);
36
+
37
+ // Check for zero length, although unlikely here
38
+ if (strlen($built) == 0 || strlen($signature) == 0) {
39
+ return false;
40
+ }
41
+
42
+ if (strlen($built) != strlen($signature)) {
43
+ return false;
44
+ }
45
+
46
+ // Avoid a timing leak with a (hopefully) time insensitive compare
47
+ $result = 0;
48
+ for ($i = 0; $i < strlen($signature); $i++) {
49
+ $result |= ord($built{$i}) ^ ord($signature{$i});
50
+ }
51
+
52
+ return $result == 0;
53
+ }
54
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/SignatureMethod/HMAC/SHA1.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
5
+ * where the Signature Base String is the text and the key is the concatenated values (each first
6
+ * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
7
+ * character (ASCII code 38) even if empty.
8
+ * - Chapter 9.2 ("HMAC-SHA1")
9
+ */
10
+ class Sputnik_OAuth_SignatureMethod_HMAC_SHA1 extends Sputnik_OAuth_SignatureMethod {
11
+ function get_name() {
12
+ return "HMAC-SHA1";
13
+ }
14
+
15
+ public function build_signature($request, $consumer, $token) {
16
+ $base_string = $request->get_signature_base_string();
17
+ $request->base_string = $base_string;
18
+
19
+ $key_parts = array(
20
+ $consumer->secret,
21
+ ($token) ? $token->secret : ""
22
+ );
23
+
24
+ $key_parts = Sputnik_OAuth_Util::urlencode_rfc3986($key_parts);
25
+ $key = implode('&', $key_parts);
26
+
27
+ return base64_encode(hash_hmac('sha1', $base_string, $key, true));
28
+ }
29
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/SignatureMethod/PLAINTEXT.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * The PLAINTEXT method does not provide any security protection and SHOULD only be used
5
+ * over a secure channel such as HTTPS. It does not use the Signature Base String.
6
+ * - Chapter 9.4 ("PLAINTEXT")
7
+ */
8
+ class Sputnik_OAuth_SignatureMethod_PLAINTEXT extends Sputnik_OAuth_SignatureMethod {
9
+ public function get_name() {
10
+ return "PLAINTEXT";
11
+ }
12
+
13
+ /**
14
+ * oauth_signature is set to the concatenated encoded values of the Consumer Secret and
15
+ * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
16
+ * empty. The result MUST be encoded again.
17
+ * - Chapter 9.4.1 ("Generating Signatures")
18
+ *
19
+ * Please note that the second encoding MUST NOT happen in the SignatureMethod, as
20
+ * Sputnik_OAuth_Request handles this!
21
+ */
22
+ public function build_signature($request, $consumer, $token) {
23
+ $key_parts = array(
24
+ $consumer->secret,
25
+ ($token) ? $token->secret : ""
26
+ );
27
+
28
+ $key_parts = Sputnik_OAuth_Util::urlencode_rfc3986($key_parts);
29
+ $key = implode('&', $key_parts);
30
+ $request->base_string = $key;
31
+
32
+ return $key;
33
+ }
34
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/SignatureMethod/RSA/SHA1.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in
5
+ * [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for
6
+ * EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a
7
+ * verified way to the Service Provider, in a manner which is beyond the scope of this
8
+ * specification.
9
+ * - Chapter 9.3 ("RSA-SHA1")
10
+ */
11
+ abstract class Sputnik_OAuth_SignatureMethod_RSA_SHA1 extends Sputnik_OAuth_SignatureMethod {
12
+ public function get_name() {
13
+ return "RSA-SHA1";
14
+ }
15
+
16
+ // Up to the SP to implement this lookup of keys. Possible ideas are:
17
+ // (1) do a lookup in a table of trusted certs keyed off of consumer
18
+ // (2) fetch via http using a url provided by the requester
19
+ // (3) some sort of specific discovery code based on request
20
+ //
21
+ // Either way should return a string representation of the certificate
22
+ protected abstract function fetch_public_cert(&$request);
23
+
24
+ // Up to the SP to implement this lookup of keys. Possible ideas are:
25
+ // (1) do a lookup in a table of trusted certs keyed off of consumer
26
+ //
27
+ // Either way should return a string representation of the certificate
28
+ protected abstract function fetch_private_cert(&$request);
29
+
30
+ public function build_signature($request, $consumer, $token) {
31
+ $base_string = $request->get_signature_base_string();
32
+ $request->base_string = $base_string;
33
+
34
+ // Fetch the private key cert based on the request
35
+ $cert = $this->fetch_private_cert($request);
36
+
37
+ // Pull the private key ID from the certificate
38
+ $privatekeyid = openssl_get_privatekey($cert);
39
+
40
+ // Sign using the key
41
+ $ok = openssl_sign($base_string, $signature, $privatekeyid);
42
+
43
+ // Release the key resource
44
+ openssl_free_key($privatekeyid);
45
+
46
+ return base64_encode($signature);
47
+ }
48
+
49
+ public function check_signature($request, $consumer, $token, $signature) {
50
+ $decoded_sig = base64_decode($signature);
51
+
52
+ $base_string = $request->get_signature_base_string();
53
+
54
+ // Fetch the public key cert based on the request
55
+ $cert = $this->fetch_public_cert($request);
56
+
57
+ // Pull the public key ID from the certificate
58
+ $publickeyid = openssl_get_publickey($cert);
59
+
60
+ // Check the computed signature against the one passed in the query
61
+ $ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
62
+
63
+ // Release the key resource
64
+ openssl_free_key($publickeyid);
65
+
66
+ return $ok == 1;
67
+ }
68
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Token.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_OAuth_Token {
4
+ // access tokens and request tokens
5
+ public $key;
6
+ public $secret;
7
+
8
+ /**
9
+ * key = the token
10
+ * secret = the token secret
11
+ */
12
+ function __construct($key, $secret) {
13
+ $this->key = $key;
14
+ $this->secret = $secret;
15
+ }
16
+
17
+ /**
18
+ * generates the basic string serialization of a token that a server
19
+ * would respond to request_token and access_token calls with
20
+ */
21
+ function to_string() {
22
+ return "oauth_token=" .
23
+ Sputnik_OAuth_Util::urlencode_rfc3986($this->key) .
24
+ "&oauth_token_secret=" .
25
+ Sputnik_OAuth_Util::urlencode_rfc3986($this->secret);
26
+ }
27
+
28
+ function __toString() {
29
+ return $this->to_string();
30
+ }
31
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/OAuth/Util.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_OAuth_Util {
4
+ public static function urlencode_rfc3986($input) {
5
+ if (is_array($input)) {
6
+ return array_map(array('Sputnik_OAuth_Util', 'urlencode_rfc3986'), $input);
7
+ } else if (is_scalar($input)) {
8
+ return str_replace(
9
+ '+',
10
+ ' ',
11
+ str_replace('%7E', '~', rawurlencode($input))
12
+ );
13
+ } else {
14
+ return '';
15
+ }
16
+ }
17
+
18
+
19
+ // This decode function isn't taking into consideration the above
20
+ // modifications to the encoding process. However, this method doesn't
21
+ // seem to be used anywhere so leaving it as is.
22
+ public static function urldecode_rfc3986($string) {
23
+ return urldecode($string);
24
+ }
25
+
26
+ // Utility function for turning the Authorization: header into
27
+ // parameters, has to do some unescaping
28
+ // Can filter out any non-oauth parameters if needed (default behaviour)
29
+ // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement.
30
+ // see http://code.google.com/p/oauth/issues/detail?id=163
31
+ public static function split_header($header, $only_allow_oauth_parameters = true) {
32
+ $params = array();
33
+ if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
34
+ foreach ($matches[1] as $i => $h) {
35
+ $params[$h] = Sputnik_OAuth_Util::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
36
+ }
37
+ if (isset($params['realm'])) {
38
+ unset($params['realm']);
39
+ }
40
+ }
41
+ return $params;
42
+ }
43
+
44
+ // helper to try to sort out headers for people who aren't running apache
45
+ public static function get_headers() {
46
+ if (function_exists('apache_request_headers')) {
47
+ // we need this to get the actual Authorization: header
48
+ // because apache tends to tell us it doesn't exist
49
+ $headers = apache_request_headers();
50
+
51
+ // sanitize the output of apache_request_headers because
52
+ // we always want the keys to be Cased-Like-This and arh()
53
+ // returns the headers in the same case as they are in the
54
+ // request
55
+ $out = array();
56
+ foreach ($headers AS $key => $value) {
57
+ $key = str_replace(
58
+ " ",
59
+ "-",
60
+ ucwords(strtolower(str_replace("-", " ", $key)))
61
+ );
62
+ $out[$key] = $value;
63
+ }
64
+ } else {
65
+ // otherwise we don't have apache and are just going to have to hope
66
+ // that $_SERVER actually contains what we need
67
+ $out = array();
68
+ if( isset($_SERVER['CONTENT_TYPE']) )
69
+ $out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
70
+ if( isset($_ENV['CONTENT_TYPE']) )
71
+ $out['Content-Type'] = $_ENV['CONTENT_TYPE'];
72
+
73
+ foreach ($_SERVER as $key => $value) {
74
+ if (substr($key, 0, 5) == "HTTP_") {
75
+ // this is chaos, basically it is just there to capitalize the first
76
+ // letter of every word that is not an initial HTTP and strip HTTP
77
+ // code from przemek
78
+ $key = str_replace(
79
+ " ",
80
+ "-",
81
+ ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
82
+ );
83
+ $out[$key] = $value;
84
+ }
85
+ }
86
+ }
87
+ return $out;
88
+ }
89
+
90
+ // This function takes a input like a=b&a=c&d=e and returns the parsed
91
+ // parameters like this
92
+ // array('a' => array('b','c'), 'd' => 'e')
93
+ public static function parse_parameters( $input ) {
94
+ if (!isset($input) || !$input) return array();
95
+
96
+ $pairs = explode('&', $input);
97
+
98
+ $parsed_parameters = array();
99
+ foreach ($pairs as $pair) {
100
+ $split = explode('=', $pair, 2);
101
+ $parameter = Sputnik_OAuth_Util::urldecode_rfc3986($split[0]);
102
+ $value = isset($split[1]) ? Sputnik_OAuth_Util::urldecode_rfc3986($split[1]) : '';
103
+
104
+ if (isset($parsed_parameters[$parameter])) {
105
+ // We have already recieved parameter(s) with this name, so add to the list
106
+ // of parameters with this name
107
+
108
+ if (is_scalar($parsed_parameters[$parameter])) {
109
+ // This is the first duplicate, so transform scalar (string) into an array
110
+ // so we can add the duplicates
111
+ $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
112
+ }
113
+
114
+ $parsed_parameters[$parameter][] = $value;
115
+ } else {
116
+ $parsed_parameters[$parameter] = $value;
117
+ }
118
+ }
119
+ return $parsed_parameters;
120
+ }
121
+
122
+ public static function build_http_query($params) {
123
+ if (!$params) return '';
124
+
125
+ // Urlencode both keys and values
126
+ $keys = Sputnik_OAuth_Util::urlencode_rfc3986(array_keys($params));
127
+ $values = Sputnik_OAuth_Util::urlencode_rfc3986(array_values($params));
128
+ $params = array_combine($keys, $values);
129
+
130
+ // Parameters are sorted by name, using lexicographical byte value ordering.
131
+ // Ref: Spec: 9.1.1 (1)
132
+ uksort($params, 'strcmp');
133
+
134
+ $pairs = array();
135
+ foreach ($params as $parameter => $value) {
136
+ if (is_array($value)) {
137
+ // If two or more parameters share the same name, they are sorted by their value
138
+ // Ref: Spec: 9.1.1 (1)
139
+ // June 12th, 2010 - changed to sort because of issue 164 by hidetaka
140
+ sort($value, SORT_STRING);
141
+ foreach ($value as $duplicate_value) {
142
+ $pairs[] = $parameter . '=' . $duplicate_value;
143
+ }
144
+ } else {
145
+ $pairs[] = $parameter . '=' . $value;
146
+ }
147
+ }
148
+ // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
149
+ // Each name-value pair is separated by an '&' character (ASCII code 38)
150
+ return implode('&', $pairs);
151
+ }
152
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Pointers.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_Pointers {
4
+
5
+ public static function bootstrap() {
6
+ add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
7
+
8
+ }
9
+
10
+ public static function enqueue_scripts() {
11
+ $enqueue = false;
12
+
13
+ $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
14
+
15
+ if ( ! in_array( 'wpsc_marketplace_pointer', $dismissed ) ) {
16
+ $enqueue = true;
17
+ add_action( 'admin_print_footer_scripts', array( __CLASS__, 'print_footer_scripts' ) );
18
+ }
19
+
20
+ if ( $enqueue ) {
21
+ // Enqueue pointers
22
+ wp_enqueue_script( 'wp-pointer' );
23
+ wp_enqueue_style( 'wp-pointer' );
24
+ }
25
+ }
26
+
27
+ public static function print_footer_scripts() {
28
+ $content = '<h3>' . __( 'New Feature: WPeC Add-Ons' ) . '</h3>';
29
+ $content .= '<p>' . __( 'Ever wanted to be able to find an extension for your e-commerce store, purchase, install and activate it right from WordPress? Now you can!', 'wpsc' ) . '</p>';
30
+ $content .= '<p>' . __( 'Find the latest and greatest free and premium plugins from the WP E-Commerce community in our <a href="' . Sputnik_Admin::build_url() . '">Add-Ons page</a>.', 'wpsc' ) . '</p>';
31
+ ?>
32
+ <script type="text/javascript">// <![CDATA[
33
+ jQuery(document).ready(function($) {
34
+ var wpsc_target;
35
+
36
+ $('#menu-posts-wpsc-product div ul li a[href$="page=sputnik"]').attr( 'id', 'marketplace-link' );
37
+
38
+ wpsc_target = $('#menu-posts-wpsc-product').hasClass('wp-has-current-submenu') ? $('#marketplace-link') : $('#menu-posts-wpsc-product');
39
+
40
+ wpsc_target.pointer({
41
+ content: '<?php echo $content; ?>',
42
+ position: {
43
+ edge: 'left',
44
+ align: 'center'
45
+ },
46
+ close: function() {
47
+ $.post( ajaxurl, {
48
+ pointer: 'wpsc_marketplace_pointer',
49
+ action: 'dismiss-wp-pointer'
50
+ });
51
+ }
52
+ }).pointer('open');
53
+ });
54
+ // ]]></script>
55
+ <?php
56
+ }
57
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/ThemeUpgrader.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sputnik_ThemeUpgrader extends Theme_Upgrader {
3
+ public function download_package($package) {
4
+ if (!preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package)) {
5
+ return $package; //must be a local file..
6
+ }
7
+
8
+ if (empty($package)) {
9
+ return new WP_Error('no_package', $this->strings['no_package']);
10
+ }
11
+
12
+ $this->skin->feedback('downloading_package', $package);
13
+
14
+ $download_file = self::download($package);
15
+
16
+ if (is_wp_error($download_file)) {
17
+ return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
18
+ }
19
+
20
+ return $download_file;
21
+ }
22
+
23
+ protected static function download( $url, $timeout = 300 ) {
24
+ //WARNING: The file is not automatically deleted, The script must unlink() the file.
25
+ if ( ! $url )
26
+ return new WP_Error('http_no_url', __('Invalid URL Provided.'));
27
+
28
+ $tmpfname = wp_tempnam($url);
29
+ if ( ! $tmpfname )
30
+ return new WP_Error('http_no_file', __('Could not create Temporary file.'));
31
+
32
+ $args = array(
33
+ 'timeout' => $timeout,
34
+ 'stream' => true,
35
+ 'filename' => $tmpfname,
36
+ 'headers' => array( 'X-WP-Domain' => Sputnik_API::domain() )
37
+ );
38
+
39
+ Sputnik_API::sign_download($url, $args);
40
+
41
+ $response = wp_remote_get($url, $args);
42
+
43
+ if ( is_wp_error( $response ) ) {
44
+ unlink( $tmpfname );
45
+ return $response;
46
+ }
47
+
48
+ if ( 200 != wp_remote_retrieve_response_code( $response ) ){
49
+ unlink( $tmpfname );
50
+ return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
51
+ }
52
+
53
+ return $tmpfname;
54
+ }
55
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Theme_Upgrader.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sputnik_ThemeUpgrader extends Theme_Upgrader {
3
+ public function download_package($package) {
4
+ if (!preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package)) {
5
+ return $package; //must be a local file..
6
+ }
7
+
8
+ if (empty($package)) {
9
+ return new WP_Error('no_package', $this->strings['no_package']);
10
+ }
11
+
12
+ $this->skin->feedback('downloading_package', $package);
13
+
14
+ $download_file = self::download($package);
15
+
16
+ if (is_wp_error($download_file)) {
17
+ return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
18
+ }
19
+
20
+ return $download_file;
21
+ }
22
+
23
+ protected static function download( $url, $timeout = 300 ) {
24
+ //WARNING: The file is not automatically deleted, The script must unlink() the file.
25
+ if ( ! $url )
26
+ return new WP_Error('http_no_url', __('Invalid URL Provided.'));
27
+
28
+ $tmpfname = wp_tempnam($url);
29
+ if ( ! $tmpfname )
30
+ return new WP_Error('http_no_file', __('Could not create Temporary file.'));
31
+
32
+ $args = array(
33
+ 'timeout' => $timeout,
34
+ 'stream' => true,
35
+ 'filename' => $tmpfname,
36
+ 'headers' => array( 'X-WP-Domain' => Sputnik_API::domain() )
37
+ );
38
+
39
+ Sputnik_API::sign_download($url, $args);
40
+
41
+ $response = wp_remote_get($url, $args);
42
+
43
+ if ( is_wp_error( $response ) ) {
44
+ unlink( $tmpfname );
45
+ return $response;
46
+ }
47
+
48
+ if ( 200 != wp_remote_retrieve_response_code( $response ) ){
49
+ unlink( $tmpfname );
50
+ return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
51
+ }
52
+
53
+ return $tmpfname;
54
+ }
55
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Updater.php ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_Updater {
4
+ public static function bootstrap() {
5
+ add_filter('pre_set_site_transient_update_plugins', array(get_class(), 'mangle_update_plugins'));
6
+ add_filter('pre_set_site_transient_update_themes', array(get_class(), 'mangle_update_themes'));
7
+ add_action('admin_action_update-selected', array(get_class(), 'prepare_bulk_mangle'));
8
+ }
9
+
10
+ public static function mangle_update_plugins($plugins) {
11
+ // WP saves once before checking, in case it fails
12
+ static $tried = false;
13
+ if (!$tried) {
14
+ $tried = true;
15
+ return $plugins;
16
+ }
17
+
18
+ $ours = Sputnik::get_installed(true);
19
+
20
+ if (empty($ours)) {
21
+ return $plugins;
22
+ }
23
+
24
+ $data = array();
25
+ $files = array();
26
+ foreach ($ours as $file => $plugin) {
27
+ // If something accidentally slipped in...
28
+ if (empty($plugin['Sputnik ID'])) {
29
+ // ...ignore it.
30
+ continue;
31
+ }
32
+
33
+ $name = $plugin['Sputnik ID'];
34
+
35
+ $files[$name] = $file;
36
+ $data[$name] = $plugin['Version'];
37
+ }
38
+
39
+ $url = Sputnik::API_BASE . '/version';
40
+
41
+ $options = array(
42
+ 'headers' => array(
43
+ 'X-WP-Domain' => self::domain(),
44
+ )
45
+ );
46
+ $url = add_query_arg('plugins', urlencode(json_encode($data)), $url);
47
+ $req = wp_remote_get($url, $options);
48
+ if (is_wp_error($req) || $req['response']['code'] !== 200) {
49
+ return $plugins;
50
+ }
51
+
52
+ $response = json_decode($req['body']);
53
+
54
+ if (empty($response)) {
55
+ return $plugins;
56
+ }
57
+
58
+ foreach ($response as $name => $result) {
59
+ $file = $files[$name];
60
+
61
+ if ($result->status === 410) {
62
+ self::$suspended[$name] = $result;
63
+ Sputnik::suspend_plugin($name, $file, $result);
64
+ continue;
65
+ }
66
+ if ($result->status !== 200) {
67
+ continue;
68
+ }
69
+
70
+ $info = (object) array(
71
+ 'package' => $result->location,
72
+ 'url' => $result->url,
73
+ 'new_version' => $result->version,
74
+ 'slug' => 'sputnik-' . $name,
75
+ 'sputnik_id' => $name
76
+ );
77
+ $plugins->response[$file] = $info;
78
+ }
79
+
80
+ return $plugins;
81
+ }
82
+
83
+ public static function mangle_update_themes( $themes ) {
84
+ // WP saves once before checking, in case it fails
85
+ static $tried = false;
86
+ if ( ! $tried) {
87
+ $tried = true;
88
+ return $themes;
89
+ }
90
+
91
+ $ours = Sputnik::get_installed( true );
92
+
93
+ if ( empty( $ours ) ) {
94
+ return $themes;
95
+ }
96
+
97
+ $data = array();
98
+ $files = array();
99
+ foreach ( $ours as $file => $theme ) {
100
+ // If something accidentally slipped in...
101
+ if ( empty( $theme['Sputnik ID'] ) ) {
102
+ // ...ignore it.
103
+ continue;
104
+ }
105
+
106
+ $name = $theme['Sputnik ID'];
107
+
108
+ $files[$name] = $file;
109
+ $data[$name] = $theme['Version'];
110
+ }
111
+
112
+ $url = Sputnik::API_BASE . '/version';
113
+
114
+ $options = array(
115
+ 'headers' => array(
116
+ 'X-WP-Domain' => self::domain(),
117
+ )
118
+ );
119
+ $url = add_query_arg( 'themes', urlencode( json_encode( $data ) ), $url );
120
+ $req = wp_remote_get( $url, $options );
121
+ if (is_wp_error($req) || $req['response']['code'] !== 200) {
122
+ return $themes;
123
+ }
124
+
125
+ $response = json_decode( $req['body'] );
126
+
127
+ if ( empty( $response ) ) {
128
+ return $themes;
129
+ }
130
+
131
+ foreach ( $response as $name => $result ) {
132
+ $file = $files[$name];
133
+
134
+ if ( $result->status === 410 ) {
135
+ self::$suspended[$name] = $result;
136
+ Sputnik::suspend_plugin( $name, $file, $result );
137
+ continue;
138
+ }
139
+ if ( $result->status !== 200 ) {
140
+ continue;
141
+ }
142
+
143
+ $info = (object) array(
144
+ 'package' => $result->location,
145
+ 'url' => $result->url,
146
+ 'new_version' => $result->version,
147
+ 'slug' => 'sputnik-' . $name,
148
+ 'sputnik_id' => $name
149
+ );
150
+ $themes->response[$file] = $info;
151
+ }
152
+
153
+ return $themes;
154
+ }
155
+
156
+ /**
157
+ * Callback for {@see Sputnik} to confirm suspension
158
+ *
159
+ * The use of this confirmation system is to ensure that only the updater
160
+ * can disable other plugins.
161
+ */
162
+ public static function confirm_suspend($plugin, $data) {
163
+ return (isset(self::$suspended[$plugin]) && self::$suspended[$plugin] === $data);
164
+ }
165
+
166
+ public static function mangle_bulk($current) {
167
+ return $current;
168
+ }
169
+
170
+ public static function prepare_bulk_mangle() {
171
+ add_filter('http_request_args', array(get_class(), 'mangle_bulk_http'), 10, 2);
172
+ }
173
+
174
+ public static function mangle_bulk_http($r, $url) {
175
+
176
+ if (strpos($url, Sputnik::API_BASE) === false) {
177
+ return $r;
178
+ }
179
+
180
+ $auth_header = Sputnik_API::get_auth_for_download($url);
181
+ list($key, $auth_header) = explode(':', $auth_header);
182
+
183
+ $r['headers']['X-WP-Domain'] = Sputnik_API::domain();
184
+ $r['headers']['Authorization'] = $auth_header;
185
+
186
+ return $r;
187
+ }
188
+
189
+ protected static function domain() {
190
+ $wp_install = home_url( '/' );
191
+
192
+ if ( is_multisite() )
193
+ $wp_install = network_site_url();
194
+
195
+ $wp_install = parse_url( $wp_install );
196
+ return $wp_install['host'];
197
+ }
198
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Upgrader.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sputnik_Upgrader extends Plugin_Upgrader {
3
+ public function download_package($package) {
4
+ if (!preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package)) {
5
+ return $package; //must be a local file..
6
+ }
7
+
8
+ if (empty($package)) {
9
+ return new WP_Error('no_package', $this->strings['no_package']);
10
+ }
11
+
12
+ $this->skin->feedback('downloading_package', $package);
13
+
14
+ $download_file = self::download($package);
15
+
16
+ if (is_wp_error($download_file)) {
17
+ return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
18
+ }
19
+
20
+ return $download_file;
21
+ }
22
+
23
+ protected static function download( $url, $timeout = 300 ) {
24
+ //WARNING: The file is not automatically deleted, The script must unlink() the file.
25
+ if ( ! $url )
26
+ return new WP_Error('http_no_url', __('Invalid URL Provided.'));
27
+
28
+ $tmpfname = wp_tempnam($url);
29
+ if ( ! $tmpfname )
30
+ return new WP_Error('http_no_file', __('Could not create Temporary file.'));
31
+
32
+ $args = array(
33
+ 'timeout' => $timeout,
34
+ 'stream' => true,
35
+ 'filename' => $tmpfname,
36
+ 'headers' => array( 'X-WP-Domain' => Sputnik_API::domain() )
37
+ );
38
+
39
+ Sputnik_API::sign_download($url, $args);
40
+
41
+ $response = wp_remote_get($url, $args);
42
+
43
+ if ( is_wp_error( $response ) ) {
44
+ unlink( $tmpfname );
45
+ return $response;
46
+ }
47
+
48
+ if ( 200 != wp_remote_retrieve_response_code( $response ) ){
49
+ unlink( $tmpfname );
50
+ return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
51
+ }
52
+
53
+ return $tmpfname;
54
+ }
55
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/Upgrader/Skin.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_Upgrader_Skin extends WP_Upgrader_Skin {
4
+ public $api;
5
+ public $type;
6
+
7
+ function __construct($args = array()) {
8
+ $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
9
+ $args = wp_parse_args($args, $defaults);
10
+
11
+ $this->type = $args['type'];
12
+ $this->api = isset($args['api']) ? $args['api'] : array();
13
+
14
+ parent::__construct($args);
15
+ }
16
+
17
+ function before() {
18
+
19
+ if ( ! empty( $this->api ) ) {
20
+ $asset_type = $this->api->is_theme ? 'theme' : 'plugin';
21
+ $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the %s <strong>%s %s</strong>.'), $asset_type, $this->api->name, $this->api->version);
22
+ }
23
+
24
+ echo '<script>if (window.parent.tb_showIframe) { window.parent.tb_showIframe(); }</script>';
25
+ }
26
+
27
+ function after() {
28
+
29
+ $plugin_file = $this->upgrader->plugin_info();
30
+
31
+ $install_actions = array();
32
+
33
+ $from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins';
34
+
35
+ // One-Click flow
36
+ if (!empty($_GET['also']) && $_GET['also'] == 'activate') {
37
+ if (!$this->result || is_wp_error($this->result)) {
38
+ show_message(__('Cannot activate plugin.', 'wpsc' ));
39
+ }
40
+ else {
41
+ show_message(__('Activating the plugin&#8230;', 'wpsc' ));
42
+ echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=0&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) .'"></iframe>';
43
+ }
44
+ }
45
+ else {
46
+ $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin', 'wpsc' ) . '" target="_parent">' . __('Activate Plugin', 'wpsc' ) . '</a>';
47
+
48
+ if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
49
+ $install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network', 'wpsc' ) . '" target="_parent">' . __('Network Activate', 'wpsc' ) . '</a>';
50
+ unset( $install_actions['activate_plugin'] );
51
+ }
52
+ }
53
+
54
+ $install_actions['store'] = '<a href="' . Sputnik_Admin::build_url() . '" title="' . esc_attr__('Return to Store', 'wpsc' ) . '" target="_parent" class="close">' . __('Return to Store', 'wpsc' ) . '</a>';
55
+
56
+
57
+ if (!$this->result || is_wp_error($this->result)) {
58
+ unset( $install_actions['activate_plugin'] );
59
+ unset( $install_actions['network_activate'] );
60
+ }
61
+ $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file);
62
+ if ( ! empty($install_actions) )
63
+ $this->feedback(implode(' | ', (array)$install_actions));
64
+ }
65
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Sputnik_View {
4
+ protected $title = 'WATWATWATWAT';
5
+
6
+ public function __construct($title) {
7
+ $this->title = $title;
8
+ }
9
+
10
+ public function render() {
11
+ $this->header();
12
+ $this->display();
13
+ $this->footer();
14
+ }
15
+
16
+ protected function header($title = false, $account = false) {
17
+ if (func_num_args() !== 0) {
18
+ debug_print_backtrace();
19
+ die();
20
+ }
21
+
22
+ $title = $this->title;
23
+
24
+ $account = false;
25
+ try {
26
+ $account = Sputnik::get_account();
27
+ }
28
+ catch (Exception $e) {
29
+ //
30
+ }
31
+ if ($account !== false) {
32
+ $tabs = array(
33
+ 'dash' => __('Store', 'sputnik'),
34
+ 'account' => __('Your Account', 'sputnik'),
35
+ );
36
+ $hrefs = array(
37
+ 'dash' => Sputnik_Admin::build_url(),
38
+ 'account' => menu_page_url( 'sputnik-account', false ),
39
+ );
40
+
41
+ $current = Sputnik_Admin::$page;
42
+ }
43
+ ?>
44
+ <div class="wrap" id="sputnik-page">
45
+ <?php
46
+ if ($account !== false) {
47
+ ?>
48
+ <?php screen_icon( 'sputnik' ); ?>
49
+ <h2 class="nav-tab-wrapper">
50
+ <?php
51
+ foreach ($tabs as $page => $title) {
52
+ ?>
53
+ <a href="<?php echo $hrefs[$page] ?>" class="nav-tab<?php if ($current === $page) echo ' nav-tab-active';?>"><?php echo $title ?></a>
54
+ <?php
55
+ }
56
+ ?>
57
+ </h2>
58
+ <?php
59
+ }
60
+ elseif ($title !== false) {
61
+ ?>
62
+ <?php screen_icon( 'sputnik' ); ?>
63
+ <h2><?php echo $title ?></h2>
64
+ <?php
65
+ }
66
+ ?>
67
+
68
+ <?php
69
+ do_action('sputnik_messages');
70
+ }
71
+
72
+ protected function footer() {?>
73
+ <div id="sputnik-footer">
74
+ <p class="logo-holder"><a href="http://wpeconomy.org/" class="renku-logo">WPEconomy</a></p>
75
+ <nav><p><a href="http://www.wpeconomy.org/documentation/developers/"><?php _e('Developer Tools', 'sputnik') ?></a> | <a href="http://twitter.com/WPEconomy">@WPEconomy</a> | <a href="http://www.wpeconomy.org/documentation/marketplace/faqs/"><?php _e('FAQ', 'sputnik') ?></a></p></nav>
76
+ </div>
77
+ </div>
78
+ <?php
79
+ }
80
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View/Account.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Account browser view
4
+ *
5
+ * @package Sputnik
6
+ * @subpackage Admin View
7
+ */
8
+
9
+ /**
10
+ * Account browser view
11
+ *
12
+ * @package Sputnik
13
+ * @subpackage Admin View
14
+ */
15
+ class Sputnik_View_Account extends Sputnik_View_Browser {
16
+ protected $title = 'Account';
17
+
18
+ protected function header() {
19
+ parent::header();
20
+ $account = Sputnik::get_account();
21
+ ?>
22
+ <div class="account-card">
23
+ <div class="block">
24
+ <?php echo get_avatar($account->email) ?>
25
+ <p class="lead-in"><?php _e('Logged in as', 'sputnik') ?></p>
26
+ <h3><?php echo esc_html($account->name) ?></h3>
27
+ <p><?php printf(__('<a href="%s">Log out</a> of your account', 'sputnik'), Sputnik_Admin::build_url(array('oauth' => 'reset'))) ?></p>
28
+ </div>
29
+ <div class="block">
30
+ <p><?php printf(__('Email: %s', 'sputnik'), '<code>' . $account->email . '</code>') ?></p>
31
+ <p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you can install right now">Available</abbr>', 'sputnik'), count($account->purchased)) ?></p>
32
+ <p class="stat"><?php printf(__('<strong>%d</strong> <abbr title="Plugins you have bought from the store">Purchased</abbr>', 'sputnik'), $this->count) ?></p>
33
+ </div>
34
+ </div>
35
+
36
+ <?php
37
+ }
38
+
39
+ public function get_view_url($view) {
40
+ $bits = array('tab' => $view);
41
+ if ($this->view->id !== 'grid') {
42
+ $bits['view'] = $this->view->id;
43
+ }
44
+ return Sputnik_Admin::build_account_url($bits);
45
+ }
46
+
47
+ public function get_tabs() {
48
+ $tabs = array();
49
+ $tabs['purchased'] = __( 'Purchased Plugins', 'sputnik' );
50
+ $tabs['yours'] = __( 'Your Plugins', 'sputnik' );
51
+ return $tabs;
52
+ }
53
+
54
+ public function get_data($tab) {
55
+ try {
56
+ switch ( $tab ) {
57
+ case 'yours':
58
+ add_filter('sputnik_install_row_action_links', array(__CLASS__, 'mangle_action_for_own'), 10, 2);
59
+ add_filter('sputnik_install_grid_action_links', array(__CLASS__, 'mangle_action_for_own'), 10, 2);
60
+ $api = Sputnik_API::get_own();
61
+ break;
62
+
63
+ default:
64
+ case 'purchased':
65
+ $api = Sputnik_API::get_purchased();
66
+ break;
67
+ }
68
+ }
69
+ catch (Exception $e) {
70
+ $this->connect_error = true;
71
+ return false;
72
+ }
73
+
74
+ $this->count = count($api['body']);
75
+
76
+ if ($tab === 'yours') {
77
+ $api['body'][] = (object) array(
78
+ 'slug' => '__add_new',
79
+ 'name' => __('Add Your Plugin', 'sputnik'),
80
+ 'description' => __('List your plugin on the WPEconomy store. Read our developer documentation and get started!', 'sputnik'),
81
+ 'rating' => (object) array('average' => 0, 'count' => 0),
82
+ 'price' => 0,
83
+ 'version' => '',
84
+ 'author' => '',
85
+ 'author_slug' => '',
86
+ 'thumb' => false
87
+ );
88
+ }
89
+
90
+ $count = 1;
91
+ if (!empty($api['headers']['x-pagecount'])) {
92
+ $count = $api['headers']['x-pagecount'];
93
+ }
94
+
95
+ return array('items' => $api['body'], 'pages' => $count);
96
+ }
97
+
98
+ public function get_views() {
99
+ global $tabs, $tab;
100
+
101
+ $display_tabs = array();
102
+ foreach ( (array) $tabs as $action => $text ) {
103
+ $class = ( $action == $tab ) ? ' class="current"' : '';
104
+ $bits = array('tab' => $action);
105
+ if ($this->view !== 'grid') {
106
+ $bits['view'] = $this->view;
107
+ }
108
+ $href = Sputnik_Admin::build_account_url($bits);
109
+ $display_tabs['plugin-install-'.$action] = "<a href='$href'$class>$text</a>";
110
+ }
111
+
112
+ return $display_tabs;
113
+ }
114
+
115
+ public function no_items() {
116
+ global $tab;
117
+ echo '<p>';
118
+ if ($tab === 'yours') {
119
+ _e( "You haven't created any plugins yet. Check out our <a href='http://developer.renku.me/'>developer documentation</a> to find out how!", 'sputnik' );
120
+ }
121
+ else {
122
+ printf(__( "You haven't purchased any plugins yet. Why not <a href='%s'>buy some</a>?", 'sputnik' ), Sputnik_Admin::build_url());
123
+ }
124
+ echo '</p>';
125
+ }
126
+
127
+ public static function mangle_action_for_own($actions, $plugin) {
128
+ if ($plugin->slug === '__add_new') {
129
+ return $actions;
130
+ }
131
+
132
+ $actions[] = sprintf(
133
+ '<a href="%s" class="button edit" title="%s">%s</a>',
134
+ sprintf(Sputnik::SITE_BASE . '/plugins/%d/edit/', $plugin->product_id),
135
+ esc_attr(sprintf(_x('Edit %s', 'Edit button title', 'sputnik'), $plugin->name)),
136
+ _x('Edit', 'Edit button text', 'sputnik')
137
+ );
138
+ return $actions;
139
+ }
140
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View/Auth.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Authentication handler view
4
+ *
5
+ * @package Sputnik
6
+ * @subpackage Admin View
7
+ */
8
+
9
+ /**
10
+ * Authentication handler view
11
+ *
12
+ * @package Sputnik
13
+ * @subpackage Admin View
14
+ */
15
+ class Sputnik_View_Auth extends Sputnik_View {
16
+ public function __construct() {
17
+ parent::__construct(false);
18
+ }
19
+ public function render() {
20
+ if ( isset( $_GET['auth'] ) && $_GET['auth'] == 'denied' ) {
21
+ Sputnik_Admin::add_message( __( 'Account linking cancelled. Please note that you need to link your account in order to access the store.', 'sputnik' ) );
22
+ }
23
+
24
+ $this->header();
25
+ $oauth_url = Sputnik_Admin::build_url(array('oauth' => 'request'));
26
+
27
+ ?>
28
+ <div id="sputnik-auth">
29
+ <iframe src="<?php echo $oauth_url; ?>"></iframe>
30
+ </div>
31
+ <?php
32
+ $this->footer();
33
+ }
34
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product browser view
4
+ *
5
+ * @package Sputnik
6
+ * @subpackage Admin View
7
+ */
8
+
9
+ /**
10
+ * Product browser view
11
+ *
12
+ * @package Sputnik
13
+ * @subpackage Admin View
14
+ */
15
+ class Sputnik_View_Browser extends Sputnik_View {
16
+ protected $title = 'Browse';
17
+
18
+ protected $view = null;
19
+ public $view_type = 'grid';
20
+ protected $connect_error = false;
21
+
22
+ public function __construct() {
23
+ $class = 'Sputnik_View_Browser_Grid';
24
+ if (!empty($_REQUEST['view'])) {
25
+ switch ($_REQUEST['view']) {
26
+ case 'list':
27
+ $class = 'Sputnik_View_Browser_List';
28
+ break;
29
+ case 'grid':
30
+ default:
31
+ $class = 'Sputnik_View_Browser_Grid';
32
+ break;
33
+ }
34
+ }
35
+
36
+ $this->view = new $class();
37
+ $this->view->parent = $this;
38
+ $this->view->prepare_items();
39
+ }
40
+
41
+ public function get_view_url($view) {
42
+ $bits = array('tab' => $view);
43
+ if ($this->view->id !== 'grid') {
44
+ $bits['view'] = $this->view->id;
45
+ }
46
+ return Sputnik_Admin::build_url($bits);
47
+ }
48
+
49
+ protected function display() {
50
+ $this->view->views();
51
+ $this->view->display();
52
+ }
53
+
54
+ public function get_tabs() {
55
+ return array();
56
+
57
+ global $tab;
58
+ $tabs = array();
59
+ $tabs['dashboard'] = __( 'Search', 'sputnik' );
60
+ if ( 'search' == $tab )
61
+ $tabs['search'] = __( 'Search Results', 'sputnik' );
62
+ $tabs['featured'] = _x( 'Featured', 'Plugin Installer', 'sputnik' );
63
+ $tabs['popular'] = _x( 'Popular', 'Plugin Installer', 'sputnik' );
64
+ $tabs['new'] = _x( 'Newest', 'Plugin Installer', 'sputnik' );
65
+ $tabs['updated'] = _x( 'Recently Updated', 'Plugin Installer', 'sputnik' );
66
+ $tabs['price'] = _x( 'Lowest Priced', 'Plugin Installer', 'sputnik' );
67
+ return $tabs;
68
+ }
69
+
70
+ public function get_data($tab) {
71
+ global $paged;
72
+ try {
73
+ switch ( $tab ) {
74
+ case 'search':
75
+ $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
76
+ $api = Sputnik_API::search($term);
77
+ break;
78
+
79
+ case 'account':
80
+ $api = Sputnik_API::get_purchased();
81
+ break;
82
+
83
+ case 'featured':
84
+ case 'popular':
85
+ case 'new':
86
+ case 'updated':
87
+ case 'price':
88
+ default:
89
+ $api = Sputnik_API::get_all($paged, array('browse' => $tab));
90
+ break;
91
+ }
92
+ }
93
+ catch (Exception $e) {
94
+ $this->connect_error = true;
95
+ return false;
96
+ }
97
+
98
+ return array('items' => $api['body'], 'pages' => $api['headers']['x-pagecount']);
99
+ }
100
+
101
+ public function no_items() {
102
+ echo '<p>' . __( 'No plugins match your request.', 'sputnik' ) . '</p>';
103
+ }
104
+
105
+ public function footer() {
106
+ ?>
107
+ <script type="text/html" id="tmpl-sputnik-modal">
108
+ <div class="sputnik-modal">
109
+ <h3 class="sputnik-modal-title">{{ title }}</h3>
110
+ <a class="sputnik-modal-close" href="" title="<?php esc_attr_e('Close'); ?>">&times;</a>
111
+ </div>
112
+ <div class="sputnik-modal-backdrop">
113
+ <div></div>
114
+ </div>
115
+ </script>
116
+ <?php
117
+
118
+ parent::footer();
119
+ }
120
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser/Grid.php ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_View_Browser_Grid extends WP_List_Table {
4
+ public $id = 'grid';
5
+
6
+ protected $connect_error = false;
7
+
8
+ public function __construct() {
9
+ parent::__construct(array(
10
+ 'screen' => 'sputnik-browser'
11
+ ));
12
+ }
13
+
14
+ public function ajax_user_can() {
15
+ return current_user_can('install_plugins');
16
+ }
17
+
18
+ public function old_prepare_items() {
19
+ $this->parent->prepare_items();
20
+ }
21
+
22
+ public function prepare_items() {
23
+ require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
24
+
25
+ global $tabs, $tab, $paged, $type, $term;
26
+
27
+ wp_reset_vars( array( 'tab' ) );
28
+
29
+ $paged = $this->get_pagenum();
30
+
31
+ // These are the tabs which are shown on the page
32
+ $tabs = $this->parent->get_tabs();
33
+
34
+ $nonmenu_tabs = array( 'account' ); //Valid actions to perform which do not have a Menu item.
35
+
36
+ $tabs = apply_filters( 'install_plugins_tabs', $tabs );
37
+ $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
38
+
39
+ // If a non-valid menu tab has been selected, and its not a non-menu action.
40
+ if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
41
+ $tab = key( $tabs );
42
+
43
+ $args = array();
44
+
45
+ $data = $this->parent->get_data($tab);
46
+ $this->items = $data['items'];
47
+
48
+ $this->set_pagination_args( array(
49
+ 'total_items' => $data['pages'],
50
+ 'per_page' => 30,
51
+ ) );
52
+ }
53
+
54
+ public function no_items() {
55
+ $this->parent->no_items();
56
+ }
57
+
58
+ public function get_views() {
59
+ global $tabs, $tab;
60
+
61
+ $display_tabs = array();
62
+ foreach ( (array) $tabs as $action => $text ) {
63
+ $class = ( $action == $tab ) ? ' class="current"' : '';
64
+ $href = $this->parent->get_view_url($action);
65
+ $display_tabs['sputnik-browse-' . $action] = "<a href='$href'$class>$text</a>";
66
+ }
67
+
68
+ return $display_tabs;
69
+ }
70
+
71
+ public function view_switcher() {
72
+ $modes = array(
73
+ 'list' => __('List View', 'sputnik'),
74
+ 'grid' => __('Grid View', 'sputnik')
75
+ );
76
+ $current_mode = $this->parent->view_type;
77
+ ?>
78
+ <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
79
+ <div class="view-switch">
80
+ <?php
81
+ foreach ( $modes as $mode => $title ) {
82
+ $class = ( $current_mode == $mode ) ? 'class="current"' : '';
83
+ echo "<a href='" . esc_url( add_query_arg( 'view', $mode, $_SERVER['REQUEST_URI'] ) ) . "' $class><img id='view-switch-$mode' src='" . esc_url( includes_url( 'images/blank.gif' ) ) . "' width='20' height='20' title='$title' alt='$title' /></a>\n";
84
+ }
85
+ ?>
86
+ </div>
87
+ <?php
88
+ }
89
+
90
+ public function pagination( $which ) {
91
+ global $mode;
92
+
93
+ parent::pagination( $which );
94
+
95
+ if ( 'top' == $which )
96
+ $this->view_switcher();
97
+ }
98
+
99
+ public function display() {
100
+ if ($this->connect_error) {
101
+ ?>
102
+ <div class="connect-error">
103
+ <h2>Whoops!</h2>
104
+ <p>We don't appear to be able to connect to the WPEconomy server right now.
105
+ Try again later!</p>
106
+ </div>
107
+ <?php
108
+ return;
109
+ }
110
+
111
+ $this->display_grid();
112
+ }
113
+
114
+ protected function display_grid() {
115
+ extract( $this->_args );
116
+
117
+ $this->display_tablenav( 'top' );
118
+ ?>
119
+ <div class="grid-view">
120
+ <?php
121
+ $this->display_rows_or_placeholder();
122
+ ?>
123
+ </div>
124
+ <?php
125
+ $this->display_tablenav( 'bottom' );
126
+ }
127
+
128
+ public function display_tablenav( $which ) {
129
+ global $tab;
130
+
131
+ if ($tab === 'account')
132
+ return;
133
+
134
+ $account = Sputnik::get_account();
135
+ if ( 'top' == $which ) { ?>
136
+ <div class="tablenav top">
137
+ <div class="alignright account">
138
+ <?php printf(__('Logged in as %s', 'sputnik'), '<a href="' . menu_page_url( 'sputnik-account', false ) . '" class="account-link">' . $account->name . '</a>') ?>
139
+ <?php
140
+ if ($tab === 'search') {
141
+ ?>
142
+ <?php Sputnik_Admin::search_form(); ?>
143
+ <?php
144
+ }
145
+ ?>
146
+ </div>
147
+ <?php
148
+ $this->pagination($which);
149
+ ?>
150
+ <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
151
+ <br class="clear" />
152
+ </div>
153
+ <?php } else { ?>
154
+ <div class="tablenav bottom">
155
+ <?php $this->pagination($which); ?>
156
+ <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
157
+ <br class="clear" />
158
+ </div>
159
+ <?php
160
+ }
161
+ }
162
+
163
+ public function get_table_classes() {
164
+ extract( $this->_args );
165
+
166
+ return array( 'plugin-install', 'widefat', $plural );
167
+ }
168
+
169
+ public function get_columns() {
170
+ return array(
171
+ 'name' => _x( 'Name', 'plugin name', 'sputnik' ),
172
+ 'version' => __( 'Version', 'sputnik' ),
173
+ 'price' => __( 'Action', 'sputnik' ),
174
+ 'rating' => __( 'Rating', 'sputnik' ),
175
+ 'description' => __( 'Description', 'sputnik' ),
176
+ );
177
+ }
178
+
179
+ public function display_rows() {
180
+ $plugins_allowedtags = array(
181
+ 'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
182
+ 'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
183
+ 'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
184
+ 'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
185
+ );
186
+
187
+ list( $columns, $hidden ) = $this->get_column_info();
188
+
189
+ $style = array();
190
+ foreach ( $columns as $column_name => $column_display_name ) {
191
+ $style[ $column_name ] = in_array( $column_name, $hidden ) ? 'style="display:none;"' : '';
192
+ }
193
+
194
+ foreach ( (array) $this->items as $plugin ) {
195
+
196
+ $plugin->name = wp_kses( $plugin->name, $plugins_allowedtags );
197
+ //Limit description to 400char, and remove any HTML.
198
+ $plugin->description = strip_tags( $plugin->description );
199
+ if ( strlen( $plugin->description ) > 400 )
200
+ $plugin->description = mb_substr( $plugin->description, 0, 400 ) . '&#8230;';
201
+ //remove any trailing entities
202
+ $plugin->description = preg_replace( '/&[^;\s]{0,6}$/', '', $plugin->description );
203
+ //strip leading/trailing & multiple consecutive lines
204
+ $plugin->description = trim( $plugin->description );
205
+ $plugin->description = preg_replace( "|(\r?\n)+|", "\n", $plugin->description );
206
+ //\n => <br>
207
+ $plugin->description = nl2br( $plugin->description );
208
+ $plugin->version = wp_kses( $plugin->version, $plugins_allowedtags );
209
+ $plugin->price = sprintf('$%.2f', $plugin->price);
210
+ if ($plugin->price === '$0.00') {
211
+ $plugin->price = _x('Free', 'plugin price', 'sputnik');
212
+ }
213
+
214
+ $plugin->author = $plugin->author;
215
+ if (!empty($plugin->author))
216
+ $plugin->author = ' <cite>' . sprintf( __( 'By %s', 'sputnik' ), $plugin->author ) . '.</cite>';
217
+
218
+ $plugin->author = wp_kses( $plugin->author, $plugins_allowedtags );
219
+
220
+ $this->display_row($plugin, $style);
221
+ }
222
+ }
223
+
224
+ protected function display_row($plugin, $style) {
225
+ $name = strip_tags( $plugin->name . ' ' . $plugin->version );
226
+ $action_links = array();
227
+ $action_links[] = '<a href="' . Sputnik_Admin::build_url(array('info' => $plugin->slug, 'TB_iframe' => true))
228
+ . '" class="thickbox button info" title="' .
229
+ esc_attr( sprintf( __( 'More information about %s', 'sputnik' ), $name ) ) . '">' . __( 'Details', 'sputnik' ) . '</a>';
230
+
231
+ $purchase_link = $plugin->price;
232
+
233
+ if ($plugin->slug === '__add_new') {
234
+ $status = 'addown';
235
+ $name = $plugin->name;
236
+ $action_links = array();
237
+ $action_links[] = '<a href="http://developer.renku.me/" class="thickbox button info">' . __( 'Documentation', 'sputnik' ) . '</a>';
238
+ $purchase_link = '<a class="button-primary addown status" href="' . Sputnik::SITE_BASE . '/plugins/add/">' . esc_html__('Add Now', 'sputnik') . '</a>';
239
+ }
240
+ elseif ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
241
+ $status = Sputnik_Admin::install_status( $plugin );
242
+
243
+ switch ( $status['status'] ) {
244
+ case 'purchase':
245
+ if ( $status['url'] ) {
246
+ $purchase_link = '<a id="' . $plugin->slug .'" class="button-primary buy status" href="' . $status['url'] . '" title="'
247
+ . esc_attr(sprintf(__( 'Buy %s', 'sputnik'), $name)) . '">' . __('Buy Now', 'sputnik') . '</a>';
248
+ }
249
+ break;
250
+ case 'install':
251
+ if ( $status['url'] ) {
252
+ $status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 700, 'height' => 550), $status['url']);
253
+ $purchase_link = '<a class="button install status" href="' . $status['url'] . '" title="'
254
+ . esc_attr(sprintf(__( 'Install %s', 'sputnik'), $name)) . '">' . __('Install', 'sputnik') . '</a>';
255
+ }
256
+ else {
257
+ $purchase_link = '<span class="status" title="' . esc_attr__('Cannot auto-install, report this as a bug', 'sputnik') . '">'
258
+ . __('Install', 'sputnik') . '</span>';
259
+ }
260
+ break;
261
+ case 'update_available':
262
+ if ( $status['url'] ) {
263
+ $status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 700, 'height' => 550), $status['url']);
264
+ $purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
265
+ . esc_attr(sprintf(__( 'Update to version %s', 'sputnik'), $status['version'])) . '">' . __('Update', 'sputnik') . '</a>';
266
+ }
267
+ else {
268
+ $purchase_link = '<span class="status" title="' . esc_attr__('Cannot auto-install, report this as a bug', 'sputnik') . '">'
269
+ . __('Update', 'sputnik') . '</span>';
270
+ }
271
+ break;
272
+ case 'latest_installed':
273
+ case 'newer_installed':
274
+ $purchase_link = '<span class="status" title="' . esc_attr__('This plugin is already installed and is up to date', 'sputnik') . ' ">'
275
+ . __('Installed', 'sputnik') . '</span>';
276
+ break;
277
+ }
278
+ }
279
+
280
+ $action_links = apply_filters( 'sputnik_install_grid_action_links', $action_links, $plugin );
281
+
282
+ $thumb = false;
283
+ if (isset($plugin->thumb) && $plugin->thumb !== false) {
284
+ $thumb = $plugin->thumb;
285
+ }
286
+ ?>
287
+ <div>
288
+ <div class="sputnik-plugin<?php if ($thumb !== false) echo ' has-thumb'; if ($status === 'addown') echo ' addown'; ?>">
289
+ <div class="sputnik-card">
290
+ <?php
291
+ if ($thumb !== false):
292
+ ?>
293
+ <div class="sputnik-plugin-thumb">
294
+ <img src="<?php echo esc_url($thumb) ?>" alt="<?php echo esc_attr($name) ?> Thumbnail">
295
+ </div>
296
+ <?php
297
+ endif;
298
+ ?>
299
+ <div class="sputnik-plugin-details">
300
+ <h4><?php echo $name ?></h4>
301
+ <span class="price"><?php echo $plugin->price ?></span>
302
+ <p><?php echo $plugin->description ?></p>
303
+ <div class="footer">
304
+ <div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->rating->count, 'sputnik' ), number_format_i18n( $plugin->rating->count ) ) ?>">
305
+ <div class="star star-rating" style="width: <?php echo (int) (20 * $plugin->rating->average) ?>px"></div>
306
+ </div>
307
+ </div>
308
+ </div>
309
+ </div>
310
+ </div>
311
+ <div class="sputnik-plugin-actions">
312
+ <?php if ( !empty( $action_links ) ) echo implode( ' ', $action_links ); ?>
313
+ <?php echo $purchase_link; ?>
314
+ </div>
315
+ </div>
316
+ <?php
317
+ }
318
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View/Browser/List.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_View_Browser_List extends Sputnik_View_Browser_Grid {
4
+ public $id = 'list';
5
+
6
+ protected function display_grid() {
7
+ WP_List_Table::display();
8
+ }
9
+ protected function display_row($plugin, $style) {
10
+ $name = strip_tags( $plugin->name . ' ' . $plugin->version );
11
+ $action_links = array();
12
+ $action_links[] = '<a href="' . Sputnik_Admin::build_url(array('info' => $plugin->slug, 'TB_iframe' => true))
13
+ . '" class="button thickbox info" title="' .
14
+ esc_attr( sprintf( __( 'More information about %s', 'sputnik' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
15
+
16
+ $purchase_link = $plugin->price;
17
+
18
+ if ($plugin->slug === '__add_new') {
19
+ $status = 'addown';
20
+ $style['name'] .= ' class="addown"';
21
+ $action_links = array();
22
+ $action_links[] = '<a href="http://developer.renku.me/" class="thickbox button info">' . __( 'Documentation', 'sputnik' ) . '</a>';
23
+ $purchase_link = '<a class="button-primary addown" href="' . Sputnik::SITE_BASE . '/plugins/add/" title="Add New Plugin">' . esc_html__('Add Now', 'sputnik') . '</a>';
24
+ }
25
+ elseif ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
26
+ $status = Sputnik_Admin::install_status( $plugin );
27
+
28
+ switch ( $status['status'] ) {
29
+ case 'purchase':
30
+ if ( $status['url'] ) {
31
+ $purchase_link = '<a id="' . $plugin->slug . '" class="button-primary buy" href="' . $status['url'] . '" title="'
32
+ . esc_attr(sprintf(__( 'Buy %s', 'sputnik'), $name)) . '">' . sprintf(__('<span>%s</span> Buy Now</a>', 'sputnik'), $plugin->price);
33
+ }
34
+ break;
35
+ case 'install':
36
+ if ( $status['url'] ) {
37
+ $status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 700, 'height' => 550), $status['url']);
38
+ $purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
39
+ . esc_attr(sprintf(__( 'Install %s', 'sputnik'), $name)) . '">' . __('Install', 'sputnik') . '</a>';
40
+ }
41
+ else {
42
+ $purchase_link = '<span title="' . esc_attr__('Cannot auto-install, report this as a bug', 'sputnik') . '">'
43
+ . __('Install', 'sputnik') . '</span>';
44
+ }
45
+ break;
46
+ case 'update_available':
47
+ if ( $status['url'] ) {
48
+ $status['url'] = add_query_arg(array('TB_iframe' => true, 'width' => 700, 'height' => 550), $status['url']);
49
+ $purchase_link = '<a class="button install" href="' . $status['url'] . '" title="'
50
+ . esc_attr(sprintf(__( 'Update to version %s', 'sputnik'), $status['version'])) . '">' . __('Update', 'sputnik') . '</a>';
51
+ }
52
+ else {
53
+ $purchase_link = '<span title="' . esc_attr__('Cannot auto-install, report this as a bug', 'sputnik') . '">'
54
+ . __('Update', 'sputnik') . '</span>';
55
+ }
56
+ break;
57
+ case 'latest_installed':
58
+ case 'newer_installed':
59
+ $purchase_link = '<span title="' . esc_attr__('This plugin is already installed and is up to date', 'sputnik') . ' ">'
60
+ . __('Installed', 'sputnik') . '</span>';
61
+ break;
62
+ }
63
+ }
64
+
65
+ $action_links = apply_filters( 'sputnik_install_row_action_links', $action_links, $plugin );
66
+ ?>
67
+ <tr>
68
+ <td class="name column-name"<?php echo $style['name']; ?>><strong><?php echo $plugin->name; ?></strong>
69
+ <div class="action-links"><?php if ( !empty( $action_links ) ) echo implode( ' ', $action_links ); ?></div>
70
+ </td>
71
+ <td class="vers column-version"<?php echo $style['version']; ?>><?php echo $plugin->version; ?></td>
72
+ <td class="vers column-price"<?php echo $style['price']; ?>><?php echo $purchase_link; ?></td>
73
+ <td class="vers column-rating"<?php echo $style['rating']; ?>>
74
+ <div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->rating->count, 'sputnik' ), number_format_i18n( $plugin->rating->count ) ) ?>">
75
+ <div class="star star-rating" style="width: <?php echo (int) (20 * $plugin->rating->average) ?>px"></div>
76
+ </div>
77
+ </td>
78
+ <td class="desc column-description"<?php echo $style['description']; ?>><?php echo $plugin->description, $plugin->author; ?></td>
79
+ </tr>
80
+ <?php
81
+ }
82
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View/Info.php ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin information view
4
+ *
5
+ * @package Sputnik
6
+ * @subpackage Admin View
7
+ */
8
+
9
+ /**
10
+ * Plugin information view
11
+ *
12
+ * @package Sputnik
13
+ * @subpackage Admin View
14
+ */
15
+ class Sputnik_View_Info extends Sputnik_View_Mini {
16
+ protected $body_id = 'sputnik-plugin-information';
17
+
18
+ protected $plugin;
19
+ protected $api;
20
+
21
+ public function __construct() {
22
+ parent::__construct( __('Plugin Information', 'sputnik') );
23
+ $this->plugin = $_GET['info'];
24
+
25
+ try {
26
+ $account = Sputnik::get_account();
27
+ $this->api = Sputnik::get_plugin($this->plugin, $account->ID);
28
+ }
29
+ catch (Exception $e) {
30
+ status_header(500);
31
+ iframe_header( __('', 'sputnik') );
32
+ echo $e->getMessage();
33
+ iframe_footer();
34
+ die();
35
+ }
36
+ }
37
+ public function display() {
38
+ global $tab;
39
+ require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
40
+
41
+ $api = $this->api;
42
+
43
+ $plugins_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
44
+ 'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
45
+ 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
46
+ 'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
47
+ 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
48
+ 'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
49
+
50
+ $plugins_section_titles = array(
51
+ 'description' => _x('Description', 'Plugin installer section title', 'sputnik'),
52
+ 'installation' => _x('Installation', 'Plugin installer section title', 'sputnik'),
53
+ 'faq' => _x('FAQ', 'Plugin installer section title', 'sputnik'),
54
+ 'screenshots' => _x('Screenshots', 'Plugin installer section title', 'sputnik'),
55
+ 'changelog' => _x('Changelog', 'Plugin installer section title', 'sputnik'),
56
+ 'other_notes' => _x('Other Notes', 'Plugin installer section title', 'sputnik')
57
+ );
58
+ //Sanitize HTML
59
+ $api->sections = (array) $api->sections;
60
+ $api->author = links_add_target($api->author, '_blank');
61
+ foreach ( $api->sections as $section_name => $content )
62
+ $api->sections[$section_name] = wp_kses($content, $plugins_allowedtags);
63
+
64
+ $api->screenshots = (array) $api->screenshots;
65
+ foreach ( $api->screenshots as &$data ) {
66
+ if (!isset($data->caption) || !isset($data->location)) {
67
+ continue;
68
+ }
69
+
70
+ $data->caption = wp_kses($data->caption, $plugins_allowedtags);
71
+ $data->location = esc_url($data->location, array('http', 'https'));
72
+ }
73
+ unset($data);
74
+
75
+ foreach ( array( 'version', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
76
+ if ( isset( $api->$key ) )
77
+ $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
78
+ }
79
+
80
+ $section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English.
81
+ if ( empty($section) || (!isset($api->sections[ $section ]) && ($section !== 'screenshots' || empty($api->screenshots))) )
82
+ $section = array_shift( $section_titles = array_keys((array)$api->sections) );
83
+
84
+ ?>
85
+ <div class="alignleft fyi">
86
+ <h1><?php echo $api->name ?></h1>
87
+ <?php if ( ! empty($api->download_link) && ( current_user_can('install_plugins') || current_user_can('update_plugins') ) ) : ?>
88
+ <p class="action-button">
89
+ <?php
90
+ $status = Sputnik_Admin::install_status($api);
91
+ switch ( $status['status'] ) {
92
+ case 'purchase':
93
+ default:
94
+ if ( $status['url'] )
95
+ echo '<a href="' . $status['url'] . '" target="_parent" class="button-primary buy">' . sprintf(__('<span>$%.2f</span> Buy &amp; Install', 'sputnik'), $api->price) . '</a>';
96
+ break;
97
+ case 'install':
98
+ if ( $status['url'] )
99
+ echo '<a href="' . $status['url'] . '" class="button-primary install" title="' . __('You have already purchased, install now', 'sputnik') . '">' . __('Install Now', 'sputnik') . '</a>';
100
+ break;
101
+ case 'update_available':
102
+ if ( $status['url'] )
103
+ echo '<a href="' . $status['url'] . '" class="button-primary install">' . __('Install Update Now', 'sputnik') .'</a>';
104
+ break;
105
+ case 'newer_installed':
106
+ echo '<a>' . sprintf(__('Newer Version (%s) Installed', 'sputnik'), $status['version']) . '</a>';
107
+ break;
108
+ case 'latest_installed':
109
+ echo '<a>' . __('Latest Version Installed', 'sputnik') . '</a>';
110
+ break;
111
+ }
112
+ ?>
113
+ </p>
114
+ <?php endif; ?>
115
+ <?php
116
+ echo "<div id='plugin-information-header'>\n";
117
+ echo "<ul id='sidemenu'>\n";
118
+ foreach ( (array)$api->sections as $section_name => $content ) {
119
+ if ( isset( $plugins_section_titles[ $section_name ] ) )
120
+ $title = $plugins_section_titles[ $section_name ];
121
+ else
122
+ $title = ucwords( str_replace( '_', ' ', $section_name ) );
123
+
124
+ $class = ( $section_name == $section ) ? ' class="current"' : '';
125
+ $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
126
+ $href = esc_url($href);
127
+ $san_section = esc_attr($section_name);
128
+ echo "\t<li><a name='$san_section' href='$href'$class>$title</a></li>\n";
129
+ }
130
+ if (!empty($api->screenshots)) {
131
+ $title = $plugins_section_titles['screenshots'];
132
+ $class = ( 'screenshots' == $section ) ? ' class="current"' : '';
133
+ $href = add_query_arg( array('tab' => $tab, 'section' => 'screenshots') );
134
+ $href = esc_url($href);
135
+ echo "\t<li><a name='screenshots' href='$href'$class>$title</a></li>\n";
136
+ }
137
+ echo "</ul>\n";
138
+ echo "</div>\n";
139
+ ?>
140
+ <h2 class="mainheader"><?php /* translators: For Your Information */ _e('FYI', 'sputnik') ?></h2>
141
+ <ul>
142
+ <?php if ( ! empty($api->version) ) : ?>
143
+ <li><strong><?php _e('Version:', 'sputnik') ?></strong> <?php echo $api->version ?></li>
144
+ <?php endif; if ( ! empty($api->author) ) : ?>
145
+ <li><strong><?php _e('Author:', 'sputnik') ?></strong> <?php echo $api->author ?></li>
146
+ <?php endif; if ( ! empty($api->last_updated) ) : ?>
147
+ <li><strong><?php _e('Last Updated:', 'sputnik') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php
148
+ printf( __('%s ago', 'sputnik'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li>
149
+ <?php endif; if ( ! empty($api->requires) ) : ?>
150
+ <li><strong><?php _e('Requires WordPress Version:', 'sputnik') ?></strong> <?php printf(__('%s or higher', 'sputnik'), $api->requires) ?></li>
151
+ <?php endif; if ( ! empty($api->tested) ) : ?>
152
+ <li><strong><?php _e('Compatible up to:', 'sputnik') ?></strong> <?php echo $api->tested ?></li>
153
+ <?php endif; if ( ! empty($api->downloaded) ) : ?>
154
+ <li><strong><?php _e('Downloaded:', 'sputnik') ?></strong> <?php printf(_n('%s time', '%s times', $api->downloaded, 'sputnik'), number_format_i18n($api->downloaded)) ?></li>
155
+ <?php endif; if ( ! empty($api->homepage) ) : ?>
156
+ <li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage &#187;', 'sputnik') ?></a></li>
157
+ <?php endif; ?>
158
+ </ul>
159
+
160
+ </div>
161
+ <div id="section-holder" class="wrap">
162
+ <?php
163
+ if ( !empty($api->tested) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->tested)), $api->tested, '>') )
164
+ echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.', 'sputnik') . '</p></div>';
165
+
166
+ else if ( !empty($api->requires) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->requires)), $api->requires, '<') )
167
+ echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.', 'sputnik') . '</p></div>';
168
+
169
+ foreach ( $api->sections as $section_name => $content ) {
170
+ if ( isset( $plugins_section_titles[ $section_name ] ) )
171
+ $title = $plugins_section_titles[ $section_name ];
172
+ else
173
+ $title = ucwords( str_replace( '_', ' ', $section_name ) );
174
+
175
+ $content = links_add_base_url($content, $api->permalink);
176
+ $content = links_add_target($content, '_blank');
177
+
178
+ $san_section = esc_attr($title);
179
+
180
+ $display = ( $section_name == $section ) ? 'block' : 'none';
181
+
182
+ echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
183
+ echo "\t\t<h2 class='long-header'>$title</h2>";
184
+ echo $content;
185
+ echo "\t</div>\n";
186
+ }
187
+
188
+ if (!empty($api->screenshots)) {
189
+ $display = ( 'screenshots' == $section ) ? 'block' : 'none';
190
+ echo "\t<div id='section-screenshots' class='section' style='display: {$display};'>\n";
191
+ echo "\t\t<h2 class='long-header'>Screenshots</h2>\n";
192
+ echo "\t\t<ol>\n";
193
+ foreach ($api->screenshots as $data) {
194
+ echo "\t\t\t<li><img src='{$data->location}' class='screenshot' /><p>{$data->caption}</p></li>\n";
195
+ }
196
+ echo "\t\t</ol>\n";
197
+ echo "\t</div>\n";
198
+ }
199
+
200
+ echo "</div>\n";
201
+ }
202
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View/Install.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Popup installer view
4
+ *
5
+ * @package Sputnik
6
+ * @subpackage Admin View
7
+ */
8
+
9
+ /**
10
+ * Popup installer view
11
+ *
12
+ * @package Sputnik
13
+ * @subpackage Admin View
14
+ */
15
+ class Sputnik_View_Install extends Sputnik_View_Mini {
16
+ protected $body_id = 'sputnik-install';
17
+
18
+ protected $id;
19
+ protected $nonce_prefix = 'sputnik_install-plugin_';
20
+ protected $title_format = 'Installing Plugin: %s';
21
+ protected $upgrader = null;
22
+ protected $api = null;
23
+
24
+ public function __construct() {
25
+ parent::__construct(__('Plugin Install', 'sputnik'));
26
+ $this->id = $_GET['install'];
27
+ $this->title = __('Installing Plugin: %s', 'sputnik');
28
+ }
29
+
30
+ protected function prepare() {
31
+ include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
32
+
33
+ try {
34
+ $this->api = $api = Sputnik::get_plugin($this->id);
35
+ }
36
+ catch (Exception $e) {
37
+ status_header(500);
38
+
39
+ $this->header();
40
+ echo '<p>' . $e->getMessage() . '</p>';
41
+ $this->footer();
42
+ return;
43
+ }
44
+
45
+ if (!Sputnik::is_purchased($this->api->slug)) {
46
+ wp_redirect(Sputnik_Admin::build_url(array('buy' => $this->id)));
47
+ die();
48
+ }
49
+
50
+ if ( ! current_user_can('install_plugins') )
51
+ wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'sputnik'));
52
+
53
+ check_admin_referer($this->nonce_prefix . $this->api->slug);
54
+
55
+ include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
56
+
57
+ $title = sprintf( $this->title_format, $this->api->name . ' ' . $this->api->version );
58
+ $nonce = $this->nonce_prefix . $this->id;
59
+ $url = 'update.php?action=install-plugin&plugin=' . $this->id;
60
+ if ( isset($_GET['from']) )
61
+ $url .= '&from=' . urlencode(stripslashes($_GET['from']));
62
+
63
+ $type = 'web'; //Install plugin type, From Web or an Upload.
64
+
65
+ if ( $this->api->is_theme )
66
+ $this->upgrader = new Sputnik_ThemeUpgrader( new Sputnik_View_Install_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
67
+ else
68
+ $this->upgrader = new Sputnik_Upgrader( new Sputnik_View_Install_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
69
+
70
+ }
71
+
72
+ public function render() {
73
+ $this->prepare();
74
+ $this->header();
75
+ add_filter('http_request_args', array('Sputnik_Updater', 'mangle_http'), 10, 2);
76
+ $this->upgrader->install($this->api->download_link);
77
+ remove_filter('http_request_args', array('Sputnik_Updater', 'mangle_http'), 10, 2);
78
+ $this->footer();
79
+ }
80
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View/Install/Skin.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sputnik_View_Install_Skin extends WP_Upgrader_Skin {
4
+ public $api;
5
+ public $type;
6
+
7
+ function __construct($args = array()) {
8
+ $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
9
+ $args = wp_parse_args($args, $defaults);
10
+
11
+ $this->type = $args['type'];
12
+ $this->api = isset($args['api']) ? $args['api'] : array();
13
+
14
+ parent::__construct($args);
15
+ }
16
+
17
+ function before() {
18
+ if ( ! empty( $this->api ) ) {
19
+ $asset_type = $this->api->is_theme ? 'theme' : 'plugin';
20
+ $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the %s <strong>%s %s</strong>.'), $asset_type, $this->api->name, $this->api->version);
21
+ }
22
+
23
+ echo '<script>if (window.parent.tb_showIframe) { window.parent.tb_showIframe(); }</script>';
24
+ }
25
+
26
+ function after() {
27
+
28
+ $plugin_file = $this->upgrader->plugin_info();
29
+
30
+ $install_actions = array();
31
+
32
+ $from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins';
33
+
34
+ // One-Click flow
35
+ if (!empty($_GET['also']) && $_GET['also'] == 'activate') {
36
+ if (!$this->result || is_wp_error($this->result)) {
37
+ show_message(__('Cannot activate plugin.', 'sputnik'));
38
+ }
39
+ else {
40
+ show_message(__('Activating the plugin&#8230;', 'sputnik'));
41
+ echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=0&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) .'"></iframe>';
42
+ }
43
+ }
44
+ else {
45
+ $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin', 'sputnik') . '" target="_parent">' . __('Activate Plugin', 'sputnik') . '</a>';
46
+
47
+ if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
48
+ $install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network', 'sputnik') . '" target="_parent">' . __('Network Activate', 'sputnik') . '</a>';
49
+ unset( $install_actions['activate_plugin'] );
50
+ }
51
+ }
52
+
53
+ $install_actions['store'] = '<a href="' . Sputnik_Admin::build_url() . '" title="' . esc_attr__('Return to Store', 'sputnik') . '" target="_parent" class="close">' . __('Return to Store', 'sputnik') . '</a>';
54
+
55
+
56
+ if (!$this->result || is_wp_error($this->result)) {
57
+ unset( $install_actions['activate_plugin'] );
58
+ unset( $install_actions['network_activate'] );
59
+ }
60
+ $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file);
61
+ if ( ! empty($install_actions) )
62
+ $this->feedback(implode(' | ', (array)$install_actions));
63
+ }
64
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View/Mini.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mini view superclass
4
+ *
5
+ * @package Sputnik
6
+ * @subpackage Admin View
7
+ */
8
+
9
+ /**
10
+ * Mini view superclass
11
+ *
12
+ * This is used for embedded views, appearing in an iframe
13
+ *
14
+ * @package Sputnik
15
+ * @subpackage Admin View
16
+ */
17
+ abstract class Sputnik_View_Mini extends Sputnik_View {
18
+ protected $body_id = 'sputnik-unknown';
19
+
20
+ protected function header() {
21
+ define( 'IFRAME_REQUEST', true );
22
+
23
+ global $body_id;
24
+ $body_id = $this->body_id;
25
+ iframe_header($this->title);
26
+ }
27
+
28
+ protected function footer() {
29
+ iframe_footer();
30
+ die();
31
+ }
32
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/View/Upgrade.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Popup upgrader view
4
+ *
5
+ * @package Sputnik
6
+ * @subpackage Admin View
7
+ */
8
+
9
+ /**
10
+ * Popup upgrader view
11
+ *
12
+ * @package Sputnik
13
+ * @subpackage Admin View
14
+ */
15
+ class Sputnik_View_Upgrade extends Sputnik_View_Install {
16
+ protected $file;
17
+
18
+ public function __construct() {
19
+ parent::__construct();
20
+ $this->title = __('Update Plugin', 'sputnik');
21
+
22
+ $this->body_id = 'sputnik-upgrade';
23
+ $this->nonce_prefix = 'sputnik_upgrade-plugin_';
24
+ $this->title_format = __('Updating Plugin: %s', 'sputnik');
25
+ }
26
+
27
+ protected function prepare() {
28
+ try {
29
+ $this->file = $_GET['upgrade'];
30
+ $data = Sputnik::get_from_file($file);
31
+ if ($data === null) {
32
+ throw new Exception(__('Plugin not found', 'sputnik'));
33
+ }
34
+ $this->id = $data['Sputnik ID'];
35
+ }
36
+ catch (Exception $e) {
37
+ status_header(500);
38
+ iframe_header( __('Update Plugin', 'sputnik') );
39
+ echo $e->getMessage();
40
+ iframe_footer();
41
+ die();
42
+ }
43
+
44
+ parent::prepare();
45
+ }
46
+
47
+ public function render() {
48
+ $this->prepare();
49
+ $this->header();
50
+ $this->upgrader->upgrade($this->file);
51
+ $this->footer();
52
+ }
53
+ }
wpsc-components/marketplace-core-v1/library/Sputnik/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden.
wpsc-components/marketplace-core-v1/marketplace-core-v1.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! empty( $_GET['wpsc_enable_marketplace'] ) )
4
+ update_option( '_wpsc_enable_marketplace', true );
5
+
6
+ if ( ! empty( $_GET['wpsc_disable_marketplace'] ) )
7
+ update_option( '_wpsc_enable_marketplace', false );
8
+
9
+ add_action( 'wpsc_includes', 'wpec_beta_marketplace_bootstrap', 12 );
10
+
11
+ function wpec_beta_marketplace_bootstrap() {
12
+ if ( ! get_option( '_wpsc_enable_marketplace', false ) )
13
+ return;
14
+
15
+ if ( ! class_exists( 'Sputnik' ) ) {
16
+ require_once( dirname( __FILE__ ) . '/library/Sputnik.php' );
17
+ Sputnik::$path = dirname( __FILE__ );
18
+ Sputnik::bootstrap();
19
+ }
20
+ }
wpsc-components/marketplace-core-v1/static/admin.css ADDED
@@ -0,0 +1,487 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #screen-options-link-wrap, #contextual-help-link-wrap {
2
+ }
3
+ #screen-meta a.show-settings {
4
+
5
+ }
6
+
7
+ /*#sputnik-footer {
8
+ background: url("header.png") repeat scroll 0 0 #AB0108;
9
+ background: rgba(0, 0, 255, 0.1);
10
+ height: 50px;
11
+ margin: 25px -15px 10px 0;
12
+ padding: 0 24px 0 10px;
13
+
14
+ color: rgba(255, 255, 255, 0.49);
15
+ font-size: 13px;
16
+ line-height: 50px;
17
+
18
+ border-radius: 8px 0 0 8px;
19
+ -moz-border-radius: 8px 0 0 8px;
20
+ -webkit-border-radius: 8px 0 0 8px;
21
+ }*/
22
+
23
+ #sputnik-page .sep {
24
+ margin: 0 12px 0 0;
25
+ font-size: 23px;
26
+ }
27
+
28
+ #sputnik-page h3 {
29
+ color: #999;
30
+ font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif;
31
+ font-size: 23px;
32
+ line-height: 29px;
33
+ font-weight: normal;
34
+ margin: 0 0 0 40px;
35
+ padding: 9px 15px 4px 0;
36
+ }
37
+
38
+ #sputnik-page .account-link {
39
+ margin-right: 8px;
40
+ }
41
+
42
+ #sputnik-page .aux-links {
43
+ float: right;
44
+ clear: both;
45
+ margin: 10px;
46
+ }
47
+ #sputnik-header p {
48
+ margin-top: 0;
49
+ margin-bottom: 0;
50
+ }
51
+
52
+ #sputnik-header a, #sputnik-footer a {
53
+ /*color: rgba(255, 255, 255, 0.78);*/
54
+ text-decoration: none;
55
+ }
56
+ #sputnik-header a:hover, #sputnik-footer a:hover {
57
+ color: #f00;
58
+ }
59
+
60
+ #sputnik-footer {
61
+ margin-top: 10px;
62
+ text-align: center;
63
+ border-top: 1px solid #DFDFDF;
64
+
65
+ overflow: auto;
66
+ padding: 10px 20px;
67
+
68
+ background: #fcfcfc;
69
+ background: -moz-radial-gradient(top, #F0F0F0, #FFFFFF 80%);
70
+ background: -webkit-radial-gradient(top, #F0F0F0, #FFFFFF 80%);
71
+ background: -ms-radial-gradient(top, #F0F0F0, #FFFFFF 80%);
72
+ background: -o-radial-gradient(top, #F0F0F0, #FFFFFF 80%);
73
+ background: radial-gradient(top, #F0F0F0, #FFFFFF 80%);
74
+ }
75
+ #sputnik-footer .logo-holder {
76
+ float: left;
77
+ }
78
+ #sputnik-footer .renku-logo {
79
+ background: url("logo.png") no-repeat scroll center center transparent;
80
+ text-indent: -9999px;
81
+ width: 47px;
82
+ height: 22px;
83
+ display: block;
84
+ }
85
+ #sputnik-footer nav {
86
+ float: right;
87
+ }
88
+
89
+ #sputnik-auth, #sputnik-page .connect-error {
90
+ font-size: 20px;
91
+ font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif;
92
+ line-height: 1.6em;
93
+ color: #777;
94
+ max-width: 500px;
95
+ }
96
+ #sputnik-auth .buttons {
97
+ text-align: right;
98
+ }
99
+ #sputnik-auth .button {
100
+ font-size: 15px !important;
101
+ }
102
+
103
+ #sputnik-page .connect-error {
104
+ clear: both;
105
+ }
106
+ #sputnik-page a.view-as-list,
107
+ #sputnik-page a.view-as-grid {
108
+ background-image: url('icons.png'), linear-gradient(bottom, rgb(237,237,237) 38%, rgb(255,255,255) 85%);
109
+ background-image: url('icons.png'), -o-linear-gradient(bottom, rgb(237,237,237) 38%, rgb(255,255,255) 85%);
110
+ background-image: url('icons.png'), -moz-linear-gradient(bottom, rgb(237,237,237) 38%, rgb(255,255,255) 85%);
111
+ background-image: url('icons.png'), -webkit-linear-gradient(bottom, rgb(237,237,237) 38%, rgb(255,255,255) 85%);
112
+ background-image: url('icons.png'), -ms-linear-gradient(bottom, rgb(237,237,237) 38%, rgb(255,255,255) 85%);
113
+ background-repeat: no-repeat, repeat-x, repeat-x, repeat-x, repeat-x;
114
+ }
115
+ #sputnik-page a.view-as-list {
116
+ background-position: right 2px, left top;
117
+ padding: 6px 32px 6px 6px;
118
+ }
119
+ #sputnik-page a.view-as-grid {
120
+ background-position: 31px -69px, left top;
121
+ padding: 7px 32px 6px 7px;
122
+ }
123
+ #sputnik-page .tablenav-pages {
124
+ display: none;
125
+ }
126
+ #sputnik-page .tablenav {
127
+ margin-top: 0;
128
+ height: auto;
129
+ position: relative;
130
+ bottom: 18px;
131
+ }
132
+ .grid-view {
133
+ margin: 0 0 15px;
134
+ clear: both;
135
+ overflow: auto;
136
+ }
137
+
138
+ /* Buy buttons */
139
+ .button.buy span {
140
+ border-right: 1px solid #C6C6C6;
141
+ border-right: 1px solid rgba(0, 0, 0, 0.2);
142
+ padding-right: 5px;
143
+ }
144
+ .button-primary.buy span {
145
+ border-right: 1px solid #529DC0;
146
+ border-right: 1px solid rgba(255, 255, 255, 0.2);
147
+ padding-right: 5px;
148
+ }
149
+ .action-button .buy span {
150
+ padding-right: 7px;
151
+ margin-right: 2px;
152
+ }
153
+
154
+ .sputnik-plugin {
155
+ width: 200px;
156
+ padding: 0;
157
+ margin: 10px 25px 5px 0;
158
+ float: left;
159
+ height: 210px;
160
+ }
161
+ .sputnik-card {
162
+ width: 200px;
163
+ height: 200px;
164
+ border: 1px solid #cfcfcf;
165
+ box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.22);
166
+
167
+ position: relative;
168
+ overflow: hidden;
169
+ }
170
+ .sputnik-plugin-thumb, .sputnik-plugin-details {
171
+ position: absolute;
172
+ }
173
+ .sputnik-plugin-thumb {
174
+ display: none;
175
+ }
176
+ .sputnik-plugin-details {
177
+ height: 180px;
178
+ width: 176px;
179
+ background: #F9F9F9;
180
+ padding: 10px 12px;
181
+ overflow: hidden;
182
+ position: relative;
183
+ }
184
+ .sputnik-plugin-details h4 {
185
+ margin: 0 0 14px;
186
+ width: 75%;
187
+ }
188
+ .sputnik-plugin-details .footer {
189
+ position: absolute;
190
+ width: 176px;
191
+ bottom: 0;
192
+ right: 12px;
193
+ height: 20px;
194
+ padding: 8px 0;
195
+ background: #F9F9F9;
196
+ line-height: 19px;
197
+ }
198
+ .sputnik-plugin-details .price {
199
+ position: absolute;
200
+ right: 12px;
201
+ top: 10px;
202
+ }
203
+ .sputnik-plugin-details .footer .star-holder {
204
+ position: absolute;
205
+ right: 0;
206
+ }
207
+ .sputnik-plugin-actions {
208
+ width: 200px;
209
+ margin: 10px 2px;
210
+ line-height: 22px;
211
+ }
212
+ .sputnik-plugin-actions .button {
213
+ display: inline-block;
214
+ }
215
+ .sputnik-plugin-actions .status {
216
+ float: right;
217
+ }
218
+
219
+ .sputnik-plugin.has-thumb .sputnik-card {
220
+ -o-transition: 0.4s;
221
+ -moz-transition: 0.4s;
222
+ -webkit-transition: 0.4s;
223
+ }
224
+ .sputnik-plugin.has-thumb .sputnik-plugin-thumb {
225
+ display: block;
226
+ }
227
+ .sputnik-plugin.has-thumb .sputnik-plugin-thumb img {
228
+ max-width:100%;
229
+ }
230
+ .sputnik-plugin.has-thumb .sputnik-plugin-details {
231
+ top: 166px;
232
+ background: rgba(250,250,250,0.7);
233
+ -o-transition: 0.4s;
234
+ -moz-transition: 0.4s;
235
+ -webkit-transition: 0.4s;
236
+ }
237
+ .sputnik-plugin.has-thumb:hover .sputnik-plugin-details {
238
+ top: 0;
239
+ background: #F9F9F9;
240
+ }
241
+
242
+ .sputnik-button {
243
+ background: rgb(215, 215, 215);
244
+ background: rgba(255, 255, 255, 0.5);
245
+ background: -moz-linear-gradient(
246
+ center top, rgba(255, 255, 255, 0.5) 0pt,
247
+ rgba(235, 235, 235, 0.5) 50%,
248
+ rgba(215, 215, 215, 0.5) 52%,
249
+ rgba(240, 240, 240, 0.5) 100%)
250
+ repeat scroll 0 0 transparent;
251
+ background: -webkit-gradient(
252
+ linear, left top, left bottom,
253
+ color-stop(0, rgba(255, 255, 255, 0.5)),
254
+ color-stop(0.5, rgba(235, 235, 235, 0.5)),
255
+ color-stop(0.52, rgba(215, 215, 215, 0.5)),
256
+ color-stop(1, rgba(240, 240, 240, 0.5)))
257
+ repeat scroll 0 0 transparent;
258
+
259
+ border: 1px solid rgba(165, 175, 185, 0.75);
260
+ box-shadow: 0 0 2px rgba(255, 255, 255, 0.65) inset;
261
+ color: #000;
262
+ text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
263
+ padding: 4px 12px;
264
+ border-radius: 3px;
265
+ margin-bottom: 1.3em;
266
+ cursor: pointer;
267
+ display: inline-block;
268
+ text-decoration: none;
269
+ }
270
+ .sputnik-button:hover {
271
+ color: #000;
272
+ }
273
+ .sputnik-button.buy, .sputnik-button.install {
274
+ background: #55a802 55%;
275
+ background: -moz-linear-gradient(center top, #93c85e 30%, #55a802 55%) repeat scroll 0 0 transparent;
276
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0.3, #93c85e), color-stop(0.55, #55a802)) repeat scroll 0 0 transparent;
277
+ border-color: #3A7404;
278
+ color: #fff;
279
+ text-shadow: 0 -1px 0 #3a7404;
280
+ }
281
+ .sputnik-button.disabled {
282
+ border: 1px solid rgba(165, 175, 185, 0.5);
283
+ cursor: default;
284
+ color: #888;
285
+ }
286
+ .sputnik-button span {
287
+ border-right: 1px solid rgba(255, 255, 255, 0.3);
288
+ padding-right: 6px;
289
+ margin-right: 5px;
290
+ display: inline-block;
291
+ }
292
+
293
+ /* iframed windows */
294
+ .toplevel_page_sputnik #TB_iframeContent {
295
+ margin-bottom: -3px;
296
+ }
297
+ #sputnik-install, #sputnik-upgrade {
298
+ padding: 0 20px;
299
+ }
300
+
301
+ #sputnik-plugin-information {
302
+ background: url('fyi-back.png') repeat-y #fff;
303
+ height: auto;
304
+ min-height: 100%;
305
+ }
306
+
307
+ #sputnik-plugin-information #plugin-information-header {
308
+ margin: 0;
309
+ padding: 0 5px;
310
+ font-weight: bold;
311
+ position: relative;
312
+ height: auto;
313
+ border: 0;
314
+ background: transparent;
315
+ }
316
+ #sputnik-plugin-information ul#sidemenu {
317
+ font-weight: normal;
318
+ margin: 0;
319
+ padding: 0;
320
+ float: none;
321
+ }
322
+ #sputnik-plugin-information #sidemenu li {
323
+ display: block;
324
+ text-align: left;
325
+ }
326
+ #sputnik-plugin-information #sidemenu a {
327
+ color: #ddd;
328
+ background: transparent;
329
+ border: none;
330
+ float: none;
331
+ padding: 0;
332
+ }
333
+ #sputnik-plugin-information #sidemenu a.current {
334
+ color: #fff;
335
+ font-weight: bold;
336
+ }
337
+
338
+ #sputnik-plugin-information .mainheader {
339
+ }
340
+
341
+ /* Install sidemenu */
342
+ #sputnik-plugin-information p.action-button {
343
+ width: 100%;
344
+ padding-bottom: 0;
345
+ margin-bottom: 10px;
346
+ margin-top: 10px;
347
+ -webkit-border-top-left-radius: 3px;
348
+ -webkit-border-bottom-left-radius: 3px;
349
+ border-top-left-radius: 3px;
350
+ border-bottom-left-radius: 3px;
351
+ }
352
+
353
+ #sputnik-plugin-information .action-button a {
354
+ text-align: center;
355
+ font-weight: bold;
356
+ text-decoration: none;
357
+ display: block;
358
+ line-height: 2em;
359
+ }
360
+
361
+ #sputnik-plugin-information #section-header h2 {
362
+ clear: none !important;
363
+ margin-right: 200px;
364
+ }
365
+
366
+ #sputnik-plugin-information .fyi {
367
+ margin: 0;
368
+ padding: 0 10px 50px;
369
+ width: 210px;
370
+ height: 100%;
371
+ background-color: #333;
372
+ color: #aaa;
373
+ }
374
+
375
+ #sputnik-plugin-information .fyi a {
376
+ color: #fff;
377
+ }
378
+
379
+ #sputnik-plugin-information .fyi h1 {
380
+ font-size: 1.6em;
381
+ margin-bottom: 0;
382
+ margin-right: 0;
383
+ padding: 10px 0;
384
+ }
385
+
386
+ #sputnik-plugin-information .fyi h2.mainheader {
387
+ display: none;
388
+ }
389
+
390
+ #sputnik-plugin-information .fyi ul {
391
+ padding: 10px 5px 10px 7px;
392
+ margin: 0;
393
+ list-style: none;
394
+ -webkit-border-bottom-left-radius: 3px;
395
+ border-bottom-left-radius: 3px;
396
+ }
397
+
398
+ #sputnik-plugin-information .fyi li {
399
+ margin-right: 0;
400
+ }
401
+
402
+ #sputnik-plugin-information .fyi strong {
403
+ color: #bbb;
404
+ }
405
+
406
+ #sputnik-plugin-information #section-holder {
407
+ padding: 10px;
408
+ margin-left: 240px;
409
+ margin-top: 0;
410
+ }
411
+
412
+ #sputnik-plugin-information .section ul,
413
+ #sputnik-plugin-information .section ol {
414
+ margin-left: 16px;
415
+ list-style-type: square;
416
+ list-style-image: none;
417
+ }
418
+
419
+ #sputnik-plugin-information #section-screenshots ol {
420
+ list-style: none;
421
+ margin: 0;
422
+ text-align: center;
423
+ }
424
+
425
+ #sputnik-plugin-information #section-screenshots li {
426
+ margin-bottom: 18px;
427
+ }
428
+
429
+ #sputnik-plugin-information #section-screenshots li img {
430
+ vertical-align: text-top;
431
+ max-width: 100%;
432
+ width: auto;
433
+ height: auto;
434
+ border: 1px solid #ccc;
435
+ padding: 7px;
436
+ }
437
+
438
+ #sputnik-plugin-information #section-screenshots li p {
439
+ font-style: italic;
440
+ padding-left: 20px;
441
+ padding-bottom: 2em;
442
+ }
443
+
444
+ #sputnik-plugin-information #section-screenshots ol,
445
+ #sputnik-plugin-information .updated,
446
+ #sputnik-plugin-information pre {
447
+ margin-right: 0;
448
+ }
449
+
450
+ #sputnik-plugin-information pre {
451
+ padding: 7px;
452
+ overflow: auto;
453
+ }
454
+
455
+ /* Account page */
456
+ #sputnik-page .account-card {
457
+ max-width: 800px;
458
+ overflow: hidden;
459
+ background: #fafafa;
460
+ border: 1px solid #ccc;
461
+ padding: 10px;
462
+ margin-top: 20px;
463
+ }
464
+ #sputnik-page .account-card .block {
465
+ width: 50%;
466
+ max-width: 400px;
467
+ float: left;
468
+ }
469
+ #sputnik-page .account-card img {
470
+ float: left;
471
+ background: #fff;
472
+ padding: 5px;
473
+ border: 1px solid #ddd;
474
+ }
475
+ #sputnik-page .account-card h3, #sputnik-page .account-card p {
476
+ margin-left: 130px;
477
+ }
478
+ #sputnik-page .account-card .lead-in {
479
+ margin-top: 0.5em;
480
+ margin-bottom: 0;
481
+ }
482
+ #sputnik-page .account-card .stat strong {
483
+ font-size: 16px;
484
+ }
485
+ #sputnik-page table.widefat tr td {
486
+ vertical-align: middle;
487
+ }
wpsc-components/marketplace-core-v1/static/admin.js ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+ if ( sputnikL10n.buy_id && sputnikL10n.buy_href ) {
3
+ var dg = new PAYPAL.apps.DGFlow({trigger:sputnikL10n.buy_id});
4
+ dg.startFlow(sputnikL10n.buy_href);
5
+ }
6
+ $('#menu-posts-wpsc-product div ul li a[href$="page=sputnik-account"]').parent('li').remove();
7
+ $('.grid-view').masonry({
8
+ selector: '.plugin'
9
+ });
10
+
11
+ $('#rateme').mousemove(function (event) {
12
+ var score = Sputnik.rating_from_event(event);
13
+ $('#rateme .star-rating').width(score * 20);
14
+ }).mouseleave(function () {
15
+ $('#rateme .star-rating').width($(this).data('rating') * 20);
16
+ }).click(function (event) {
17
+ var score = Sputnik.rating_from_event(event);
18
+ jQuery.post(ajaxurl, {
19
+ action: 'sputnik_rate',
20
+ rating: score,
21
+ product: $(this).data('productid')
22
+ }, function (data) {
23
+ $('#rateme').data('rating', data.rating);
24
+ $('#rateme .star-rating').width(data.rating * 20);
25
+ alert('Rating set!');
26
+ });
27
+ });
28
+
29
+ $('.thickbox.info').click(function () {
30
+
31
+ var href = $(this).attr('href');
32
+ var dim = Sputnik.window_dimensions();
33
+ href += '&width=' + Math.min(Math.max(dim[0] - 50, 300), 700)
34
+ + '&height=' + Math.min(Math.max(dim[1] - 100, 250), 550);
35
+ tb_show('', href);
36
+ this.blur();
37
+
38
+ $('#TB_title').css({'background-color':'#222','color':'#cfcfcf'});
39
+ $('#TB_ajaxWindowTitle').html('<strong>' + sputnikL10n.plugin_information + '</strong>&nbsp;' + $(this).attr('title') );
40
+
41
+ return false;
42
+ });
43
+
44
+ $('.button.install').click(function () {
45
+ tb_click.call(this);
46
+ return false;
47
+ });
48
+
49
+ $('#sputnik-install a.close,#sputnik-upgrade a.close').click(function () {
50
+ if (window.parent !== window) {
51
+ window.parent.tb_remove();
52
+ return false;
53
+ }
54
+ });
55
+
56
+ $('.buy').click(function(){
57
+ var href = $(this).attr('href');
58
+ if (href.indexOf('TB_iframe') !== -1) {
59
+ tb_show($(this).attr('title'), href);
60
+ return false;
61
+ }
62
+
63
+ var dg = new PAYPAL.apps.DGFlow({trigger:$(this).attr('id')});
64
+ dg.startFlow($(this).attr('href'));
65
+ return false;
66
+ });
67
+
68
+ var $_GET = getQueryParams(window.location.search);
69
+ if($_GET['run-installer'] != null && $_GET['run-installer'].length > 0 && $('div').closest('#TB_window').size() == 0){
70
+ var t = 'Installing ...';
71
+ var a = $_GET['run-installer'];
72
+
73
+ tb_show(t,a,false);
74
+ }
75
+
76
+ function getQueryParams(qs) {
77
+ qs = qs.split("+").join(" ");
78
+ var params = {},
79
+ tokens,
80
+ re = /[?&]?([^=]+)=([^&]*)/g;
81
+
82
+ while (tokens = re.exec(qs)) {
83
+ params[decodeURIComponent(tokens[1])]
84
+ = decodeURIComponent(tokens[2]);
85
+ }
86
+ return params;
87
+ }
88
+ });
89
+
90
+ var Sputnik = {
91
+ rating_from_event: function (event) {
92
+ var score = (event.pageX - jQuery(event.target).offset().left) / 20;
93
+ return Math.floor(score) + 1;
94
+ },
95
+ window_dimensions: function () {
96
+ var de = document.documentElement;
97
+ var width = window.innerWidth || self.innerWidth
98
+ || (de&&de.clientWidth) || document.body.clientWidth;
99
+ var height = window.innerHeight || self.innerHeight
100
+ || (de&&de.clientHeight) || document.body.clientHeight;
101
+ return [width, height];
102
+ }
103
+ };
wpsc-components/marketplace-core-v1/static/gray-star.png ADDED
Binary file
wpsc-components/marketplace-core-v1/static/grid.png ADDED
Binary file
wpsc-components/marketplace-core-v1/static/icon16.png ADDED
Binary file
wpsc-components/marketplace-core-v1/static/icon32.png ADDED
Binary file
wpsc-components/marketplace-core-v1/static/icons.png ADDED
Binary file
wpsc-components/marketplace-core-v1/static/jquery.masonry.js ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * jQuery Masonry v2.0.110901
3
+ * A dynamic layout plugin for jQuery
4
+ * The flip-side of CSS Floats
5
+ * http://masonry.desandro.com
6
+ *
7
+ * Licensed under the MIT license.
8
+ * Copyright 2011 David DeSandro
9
+ */
10
+ (function(a,b,c){var d=b.event,e;d.special.smartresize={setup:function(){b(this).bind("resize",d.special.smartresize.handler)},teardown:function(){b(this).unbind("resize",d.special.smartresize.handler)},handler:function(a,b){var c=this,d=arguments;a.type="smartresize",e&&clearTimeout(e),e=setTimeout(function(){jQuery.event.handle.apply(c,d)},b==="execAsap"?0:100)}},b.fn.smartresize=function(a){return a?this.bind("smartresize",a):this.trigger("smartresize",["execAsap"])},b.Mason=function(a,c){this.element=b(c),this._create(a),this._init()};var f=["position","height"];b.Mason.settings={isResizable:!0,isAnimated:!1,animationOptions:{queue:!1,duration:500},gutterWidth:0,isRTL:!1,isFitWidth:!1},b.Mason.prototype={_filterFindBricks:function(a){var b=this.options.itemSelector;return b?a.filter(b).add(a.find(b)):a},_getBricks:function(a){var b=this._filterFindBricks(a).css({position:"absolute"}).addClass("masonry-brick");return b},_create:function(c){this.options=b.extend(!0,{},b.Mason.settings,c),this.styleQueue=[],this.reloadItems();var d=this.element[0].style;this.originalStyle={};for(var e=0,g=f.length;e<g;e++){var h=f[e];this.originalStyle[h]=d[h]||""}this.element.css({position:"relative"}),this.horizontalDirection=this.options.isRTL?"right":"left",this.offset={};var i=b(document.createElement("div"));this.element.prepend(i),this.offset.y=Math.round(i.position().top),this.options.isRTL?(i.css({"float":"right",display:"inline-block"}),this.offset.x=Math.round(this.element.outerWidth()-i.position().left)):this.offset.x=Math.round(i.position().left),i.remove();var j=this;setTimeout(function(){j.element.addClass("masonry")},0),this.options.isResizable&&b(a).bind("smartresize.masonry",function(){j.resize()})},_init:function(a){this._getColumns("masonry"),this._reLayout(a)},option:function(a,c){b.isPlainObject(a)&&(this.options=b.extend(!0,this.options,a))},layout:function(a,c){var d,e,f,g,h,i;for(var j=0,k=a.length;j<k;j++){d=b(a[j]),e=Math.ceil(d.outerWidth(!0)/this.columnWidth),e=Math.min(e,this.cols);if(e===1)this._placeBrick(d,this.colYs);else{f=this.cols+1-e,g=[];for(i=0;i<f;i++)h=this.colYs.slice(i,i+e),g[i]=Math.max.apply(Math,h);this._placeBrick(d,g)}}var l={};l.height=Math.max.apply(Math,this.colYs)-this.offset.y,this.options.isFitWidth&&(l.width=this.cols*this.columnWidth-this.options.gutterWidth),this.styleQueue.push({$el:this.element,style:l});var m=this.isLaidOut?this.options.isAnimated?"animate":"css":"css",n=this.options.animationOptions,o;for(j=0,k=this.styleQueue.length;j<k;j++)o=this.styleQueue[j],o.$el[m](o.style,n);this.styleQueue=[],c&&c.call(a),this.isLaidOut=!0},_getColumns:function(){var a=this.options.isFitWidth?this.element.parent():this.element,b=a.width();this.columnWidth=this.options.columnWidth||this.$bricks.outerWidth(!0)||b,this.columnWidth+=this.options.gutterWidth,this.cols=Math.floor((b+this.options.gutterWidth)/this.columnWidth),this.cols=Math.max(this.cols,1)},_placeBrick:function(a,b){var c=Math.min.apply(Math,b),d=0;for(var e=0,f=b.length;e<f;e++)if(b[e]===c){d=e;break}var g={top:c};g[this.horizontalDirection]=this.columnWidth*d+this.offset.x,this.styleQueue.push({$el:a,style:g});var h=c+a.outerHeight(!0),i=this.cols+1-f;for(e=0;e<i;e++)this.colYs[d+e]=h},resize:function(){var a=this.cols;this._getColumns("masonry"),this.cols!==a&&this._reLayout()},_reLayout:function(a){var b=this.cols;this.colYs=[];while(b--)this.colYs.push(this.offset.y);this.layout(this.$bricks,a)},reloadItems:function(){this.$bricks=this._getBricks(this.element.children())},reload:function(a){this.reloadItems(),this._init(a)},appended:function(a,b,c){if(b){this._filterFindBricks(a).css({top:this.element.height()});var d=this;setTimeout(function(){d._appended(a,c)},1)}else this._appended(a,c)},_appended:function(a,b){var c=this._getBricks(a);this.$bricks=this.$bricks.add(c),this.layout(c,b)},remove:function(a){this.$bricks=this.$bricks.not(a),a.remove()},destroy:function(){this.$bricks.removeClass("masonry-brick").each(function(){this.style.position="",this.style.top="",this.style.left=""});var c=this.element[0].style;for(var d=0,e=f.length;d<e;d++){var g=f[d];c[g]=this.originalStyle[g]}this.element.unbind(".masonry").removeClass("masonry").removeData("masonry"),b(a).unbind(".masonry")}},b.fn.imagesLoaded=function(a){function h(){--e<=0&&this.src!==f&&(setTimeout(g),d.unbind("load error",h))}function g(){a.call(b,d)}var b=this,d=b.find("img").add(b.filter("img")),e=d.length,f="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";e||g(),d.bind("load error",h).each(function(){if(this.complete||this.complete===c){var a=this.src;this.src=f,this.src=a}});return b};var g=function(a){this.console&&console.error(a)};b.fn.masonry=function(a){if(typeof a=="string"){var c=Array.prototype.slice.call(arguments,1);this.each(function(){var d=b.data(this,"masonry");if(!d)g("cannot call methods on masonry prior to initialization; attempted to call method '"+a+"'");else{if(!b.isFunction(d[a])||a.charAt(0)==="_"){g("no such method '"+a+"' for masonry instance");return}d[a].apply(d,c)}})}else this.each(function(){var c=b.data(this,"masonry");c?(c.option(a||{}),c._init()):b.data(this,"masonry",new b.Mason(a,this))});return this}})(window,jQuery);
wpsc-components/marketplace-core-v1/static/logo.png ADDED
Binary file
wpsc-components/marketplace-core-v1/static/modal.css ADDED
@@ -0,0 +1,1628 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Base Styles
3
+ */
4
+ .sputnik-modal,
5
+ .sputnik-frame {
6
+ font-family: sans-serif;
7
+ font-size: 12px;
8
+ }
9
+
10
+ .sputnik-frame input,
11
+ .sputnik-frame textarea {
12
+ padding: 6px 8px;
13
+ line-height: 16px;
14
+ }
15
+
16
+ .sputnik-frame select,
17
+ .wp-admin .sputnik-frame select {
18
+ line-height: 28px;
19
+ margin-top: 3px;
20
+ }
21
+
22
+ .sputnik-frame a {
23
+ border-bottom: none;
24
+ color: #21759b;
25
+ }
26
+
27
+ .sputnik-frame a:hover {
28
+ color: #d54e21;
29
+ }
30
+
31
+ .sputnik-frame a.button {
32
+ color: #333;
33
+ }
34
+
35
+ .sputnik-frame a.button:hover {
36
+ color: #222;
37
+ }
38
+
39
+ .sputnik-frame a.button-primary,
40
+ .sputnik-frame a.button-primary:hover {
41
+ color: #fff;
42
+ }
43
+
44
+ .sputnik-frame input[type="text"],
45
+ .sputnik-frame input[type="password"],
46
+ .sputnik-frame input[type="number"],
47
+ .sputnik-frame input[type="search"],
48
+ .sputnik-frame input[type="email"],
49
+ .sputnik-frame input[type="url"],
50
+ .sputnik-frame textarea,
51
+ .sputnik-frame select {
52
+ font-family: sans-serif;
53
+ font-size: 12px;
54
+ -moz-box-sizing: border-box;
55
+ -webkit-box-sizing: border-box;
56
+ -ms-box-sizing: border-box; /* ie8 only */
57
+ box-sizing: border-box;
58
+ -webkit-border-radius: 3px;
59
+ border-radius: 3px;
60
+ border-width: 1px;
61
+ border-style: solid;
62
+ border-color: #dfdfdf;
63
+ }
64
+
65
+ .sputnik-frame select {
66
+ height: 24px;
67
+ padding: 2px;
68
+ }
69
+
70
+ .sputnik-frame input:disabled,
71
+ .sputnik-frame textarea:disabled,
72
+ .sputnik-frame input[readonly],
73
+ .sputnik-frame textarea[readonly] {
74
+ background-color: #eee;
75
+ }
76
+
77
+ .sputnik-frame input[type="search"] {
78
+ -webkit-appearance: textfield;
79
+ }
80
+
81
+ .sputnik-frame :-moz-placeholder {
82
+ color: #a9a9a9;
83
+ }
84
+
85
+ /**
86
+ * Modal
87
+ */
88
+ .sputnik-modal {
89
+ position: fixed;
90
+ top: 30px;
91
+ left: 30px;
92
+ right: 30px;
93
+ bottom: 30px;
94
+ z-index: 160000;
95
+ }
96
+
97
+ .sputnik-modal-backdrop {
98
+ position: fixed;
99
+ top: 0;
100
+ left: 0;
101
+ right: 0;
102
+ bottom: 0;
103
+ min-height: 360px;
104
+ background: #000;
105
+ opacity: 0.7;
106
+ z-index: 159900;
107
+ }
108
+
109
+ .sputnik-modal-close {
110
+ position: absolute;
111
+ top: 7px;
112
+ right: 7px;
113
+ width: 30px;
114
+ height: 30px;
115
+ z-index: 1000;
116
+ }
117
+ .sputnik-modal-close span {
118
+ display: block;
119
+ margin: 8px auto 0;
120
+ width: 15px;
121
+ height: 15px;
122
+ background-position: -100px 0;
123
+ }
124
+
125
+ .sputnik-modal-close:active {
126
+ outline: 0;
127
+ }
128
+
129
+ .sputnik-modal-content {
130
+ position: absolute;
131
+ top: 0;
132
+ left: 0;
133
+ right: 0;
134
+ bottom: 0;
135
+ overflow: auto;
136
+ min-height: 300px;
137
+ background: #fff;
138
+ }
139
+
140
+ .sputnik-modal-icon {
141
+ background-image: url(../images/uploader-icons.png);
142
+ background-repeat: no-repeat;
143
+ }
144
+
145
+ /**
146
+ * Sidebar
147
+ */
148
+ .sputnik-sidebar {
149
+ position: absolute;
150
+ top: 0;
151
+ right: 0;
152
+ bottom: 0;
153
+ width: 267px;
154
+ padding: 0 16px 24px;
155
+ z-index: 75;
156
+ background: #f5f5f5;
157
+ border-left: 1px solid #dfdfdf;
158
+ overflow: auto;
159
+ -webkit-overflow-scrolling: touch;
160
+ }
161
+
162
+ .hide-toolbar .sputnik-sidebar {
163
+ bottom: 0;
164
+ }
165
+
166
+ .sputnik-sidebar .sidebar-title {
167
+ font-weight: 200;
168
+ font-size: 20px;
169
+ margin: 0;
170
+ padding: 12px 10px 10px;
171
+ line-height: 28px;
172
+ }
173
+
174
+ .sputnik-sidebar .sidebar-content {
175
+ padding: 0 10px;
176
+ margin-bottom: 130px;
177
+ }
178
+
179
+ .sputnik-sidebar .search {
180
+ display: block;
181
+ width: 100%;
182
+ }
183
+
184
+ .sputnik-sidebar h3 {
185
+ position: relative;
186
+ font-weight: bold;
187
+ text-transform: uppercase;
188
+ font-size: 12px;
189
+ color: #777;
190
+ text-shadow: 0 1px 0 #fff;
191
+ margin: 24px 0 8px;
192
+ }
193
+
194
+ .sputnik-sidebar .setting {
195
+ display: block;
196
+ float: left;
197
+ width: 100%;
198
+ margin: 1px 0;
199
+ }
200
+
201
+ .sputnik-sidebar .setting label {
202
+ display: block;
203
+ }
204
+
205
+ .sputnik-sidebar .setting .link-to-custom {
206
+ margin: 3px 0;
207
+ }
208
+
209
+ .sputnik-sidebar .setting span {
210
+ min-width: 30%;
211
+ margin-right: 4%;
212
+ font-size: 12px;
213
+ }
214
+
215
+ .sputnik-sidebar .setting select {
216
+ max-width: 65%;
217
+ }
218
+
219
+ .sputnik-sidebar .setting input[type="checkbox"] {
220
+ width: auto;
221
+ float: none;
222
+ margin-top: 8px;
223
+ padding: 0;
224
+ }
225
+
226
+ .sputnik-sidebar .setting span,
227
+ .compat-item label span {
228
+ float: left;
229
+ min-height: 22px;
230
+ padding-top: 8px;
231
+ line-height: 16px;
232
+ text-align: right;
233
+ font-weight: normal;
234
+ color: #999;
235
+ text-shadow: 0 1px 0 #fff;
236
+ }
237
+
238
+ .sputnik-sidebar .setting input,
239
+ .sputnik-sidebar .setting textarea {
240
+ width: 65%;
241
+ float: right;
242
+ }
243
+
244
+ .sputnik-sidebar .setting textarea,
245
+ .compat-item .field textarea {
246
+ height: 62px;
247
+ resize: vertical;
248
+ }
249
+
250
+ .sputnik-sidebar select {
251
+ margin-top: 3px;
252
+ }
253
+
254
+ .compat-item {
255
+ float: left;
256
+ width: 100%;
257
+ overflow: hidden;
258
+ }
259
+
260
+ .compat-item table {
261
+ width: 100%;
262
+ table-layout: fixed;
263
+ border-spacing: 0;
264
+ border: 0;
265
+ }
266
+
267
+ .compat-item tr {
268
+ padding: 2px 0;
269
+ display: block;
270
+ overflow: hidden;
271
+ }
272
+
273
+ .compat-item .label,
274
+ .compat-item .field {
275
+ display: block;
276
+ margin: 0;
277
+ padding: 0;
278
+ }
279
+
280
+ .compat-item .label {
281
+ min-width: 30%;
282
+ margin-right: 4%;
283
+ float: left;
284
+ text-align: right;
285
+ }
286
+
287
+ .compat-item .label span {
288
+ display: block;
289
+ width: 100%;
290
+ }
291
+
292
+ .compat-item .field {
293
+ float: right;
294
+ width: 65%;
295
+ padding-right: 1px;
296
+ }
297
+
298
+ .compat-item .field input {
299
+ width: 100%;
300
+ margin: 0;
301
+ }
302
+
303
+
304
+ /**
305
+ * Menu
306
+ */
307
+ .sputnik-menu {
308
+ position: absolute;
309
+ top: 0;
310
+ left: 0;
311
+ right: 0;
312
+ bottom: 0;
313
+ margin: 0;
314
+ padding: 16px 0;
315
+ border-right: 1px solid #d9d9d9;
316
+ box-shadow: inset -6px 0 6px -6px rgba( 0, 0, 0, 0.2 );
317
+ -webkit-user-select: none;
318
+ -moz-user-select: none;
319
+ -ms-user-select: none;
320
+ user-select: none;
321
+ }
322
+
323
+ .sputnik-menu > a {
324
+ display: block;
325
+ position: relative;
326
+ padding: 4px 20px;
327
+ margin: 0;
328
+ line-height: 18px;
329
+ font-size: 14px;
330
+ color: #21759B;
331
+ text-shadow: 0 1px 0 #fff;
332
+ text-decoration: none;
333
+ }
334
+
335
+ .sputnik-menu > a:hover {
336
+ color: #21759B;
337
+ background: rgba( 0, 0, 0, 0.04 );
338
+ }
339
+
340
+ .sputnik-menu > a:active {
341
+ outline: none;
342
+ }
343
+
344
+ .sputnik-menu .active,
345
+ .sputnik-menu .active:hover {
346
+ color: #333;
347
+ font-weight: bold;
348
+ }
349
+
350
+ .sputnik-menu .separator {
351
+ height: 0;
352
+ margin: 12px 20px;
353
+ padding: 0;
354
+ border-top: 1px solid #dfdfdf;
355
+ border-bottom: 1px solid #fff;
356
+ }
357
+
358
+ /**
359
+ * Menu
360
+ */
361
+ .sputnik-router {
362
+ position: relative;
363
+ padding: 0 6px;
364
+ margin: 0;
365
+ clear: both;
366
+ -webkit-user-select: none;
367
+ -moz-user-select: none;
368
+ -ms-user-select: none;
369
+ user-select: none;
370
+ }
371
+
372
+ .sputnik-router > a {
373
+ position: relative;
374
+ float: left;
375
+ padding: 2px 10px;
376
+ margin: 0;
377
+ height: 18px;
378
+ line-height: 18px;
379
+ font-size: 14px;
380
+ border-right: 1px solid #dfdfdf;
381
+ text-shadow: 0 1px 0 #fff;
382
+ text-decoration: none;
383
+ }
384
+
385
+ .sputnik-router > a:last-child {
386
+ border-right: 0;
387
+ }
388
+
389
+ .sputnik-router > a:active,
390
+ .sputnik-router > a:focus {
391
+ outline: none;
392
+ }
393
+
394
+ .sputnik-router .active,
395
+ .sputnik-router .active:hover {
396
+ color: #333;
397
+ }
398
+
399
+ .sputnik-router .active:after {
400
+ content: '';
401
+ display: block;
402
+ margin: -100px auto 0;
403
+ width: 7px;
404
+ height: 7px;
405
+ background: #fff;
406
+ box-shadow: 1px 1px 1px rgba( 0, 0, 0, 0.2 );
407
+ z-index: 300;
408
+
409
+ -webkit-transform: rotate( 45deg ) translate( 75px, 75px );
410
+ -moz-transform: rotate( 45deg ) translate( 75px, 75px );
411
+ -ms-transform: rotate( 45deg ) translate( 75px, 75px );
412
+ -o-transform: rotate( 45deg ) translate( 75px, 75px );
413
+ transform: rotate( 45deg ) translate( 75px, 75px );
414
+ }
415
+
416
+ /**
417
+ * Frame
418
+ */
419
+ .sputnik-frame {
420
+ overflow: hidden;
421
+ position: absolute;
422
+ top: 0;
423
+ left: 0;
424
+ right: 0;
425
+ bottom: 0;
426
+ }
427
+
428
+ .sputnik-frame-menu {
429
+ position: absolute;
430
+ top: 0;
431
+ left: 0;
432
+ bottom: 0;
433
+ width: 199px;
434
+ z-index: 150;
435
+ }
436
+
437
+ .sputnik-frame-title {
438
+ position: absolute;
439
+ top: 0;
440
+ left: 200px;
441
+ right: 0;
442
+ height: 45px;
443
+ z-index: 200;
444
+ }
445
+
446
+ .sputnik-frame-router {
447
+ position: absolute;
448
+ top: 45px;
449
+ left: 200px;
450
+ right: 0;
451
+ height: 30px;
452
+ z-index: 200;
453
+ border-bottom: 1px solid #dfdfdf;
454
+ box-shadow: 0 4px 4px -4px rgba( 0, 0, 0, 0.1 );
455
+ }
456
+
457
+ .sputnik-frame-content {
458
+ position: absolute;
459
+ top: 75px;
460
+ left: 200px;
461
+ right: 0;
462
+ bottom: 61px;
463
+ height: auto;
464
+ width: auto;
465
+ margin: 0;
466
+ overflow: auto;
467
+ }
468
+
469
+ .sputnik-frame-toolbar {
470
+ position: absolute;
471
+ left: 200px;
472
+ right: 0;
473
+ bottom: 0;
474
+ height: 60px;
475
+ z-index: 100;
476
+ border: 0 solid #dfdfdf;
477
+ border-width: 1px 0 0 0;
478
+ box-shadow: 0 -4px 4px -4px rgba( 0, 0, 0, 0.1 );
479
+ }
480
+
481
+ .sputnik-frame.hide-menu .sputnik-frame-title,
482
+ .sputnik-frame.hide-menu .sputnik-frame-router,
483
+ .sputnik-frame.hide-menu .sputnik-frame-toolbar,
484
+ .sputnik-frame.hide-menu .sputnik-frame-content {
485
+ left: 0;
486
+ }
487
+
488
+ .sputnik-frame.hide-menu .sputnik-frame-menu {
489
+ left: -200px;
490
+ }
491
+
492
+ .sputnik-frame.hide-toolbar .sputnik-frame-content {
493
+ bottom: 0;
494
+ }
495
+
496
+ .sputnik-frame.hide-toolbar .sputnik-frame-toolbar {
497
+ bottom: -61px;
498
+ }
499
+
500
+ .sputnik-frame.hide-router .sputnik-frame-content {
501
+ top: 45px;
502
+ }
503
+
504
+ .sputnik-frame.hide-router .sputnik-frame-router {
505
+ display: none;
506
+ }
507
+
508
+ .sputnik-frame.hide-router .sputnik-frame-title {
509
+ border-bottom: 1px solid #dfdfdf;
510
+ box-shadow: 0 4px 4px -4px rgba( 0, 0, 0, 0.1 );
511
+ }
512
+
513
+ .sputnik-frame .sputnik-toolbar .add-to-gallery {
514
+ display: none;
515
+ }
516
+
517
+ .sputnik-frame-title h1 {
518
+ padding: 0 16px;
519
+ font-size: 22px;
520
+ font-weight: 200;
521
+ line-height: 45px;
522
+ margin: 0;
523
+ }
524
+
525
+ /**
526
+ * Iframes
527
+ */
528
+ .sputnik-frame .sputnik-iframe {
529
+ overflow: hidden;
530
+ }
531
+
532
+ .sputnik-frame .sputnik-iframe,
533
+ .sputnik-frame .sputnik-iframe iframe {
534
+ height: 100%;
535
+ width: 100%;
536
+ border: 0;
537
+ }
538
+
539
+ /**
540
+ * Attachment Browser Filters
541
+ */
542
+ .sputnik-frame select.attachment-filters {
543
+ margin-top: 11px;
544
+ margin-right: 10px;
545
+ }
546
+
547
+ /**
548
+ * Search
549
+ */
550
+ .sputnik-frame .search {
551
+ margin-top: 11px;
552
+ padding: 4px;
553
+ line-height: 18px;
554
+ font-size: 13px;
555
+ color: #464646;
556
+ font-family: sans-serif;
557
+ -webkit-appearance: none;
558
+ }
559
+
560
+ .sputnik-toolbar-secondary .search {
561
+ margin-right: 16px;
562
+ }
563
+
564
+ /**
565
+ * Attachments
566
+ */
567
+ .attachments {
568
+ margin: 0;
569
+ padding-right: 16px;
570
+ -webkit-overflow-scrolling: touch;
571
+ }
572
+
573
+ /**
574
+ * Attachment
575
+ */
576
+ .attachment {
577
+ position: relative;
578
+ float: left;
579
+
580
+ padding: 0;
581
+ margin: 0 10px 20px;
582
+ color: #464646;
583
+ list-style: none;
584
+ text-align: center;
585
+
586
+ -webkit-user-select: none;
587
+ -moz-user-select: none;
588
+ -ms-user-select: none;
589
+ -o-user-select: none;
590
+ user-select: none;
591
+ }
592
+
593
+ .selected.attachment {
594
+ box-shadow:
595
+ 0 0 0 1px #fff,
596
+ 0 0 0 3px #ccc;
597
+ }
598
+
599
+ .details.attachment {
600
+ box-shadow:
601
+ 0 0 0 1px #fff,
602
+ 0 0 0 5px #1e8cbe;
603
+ }
604
+
605
+ .attachment-preview {
606
+ position: relative;
607
+ width: 199px;
608
+ height: 199px;
609
+ box-shadow:
610
+ inset 0 0 15px rgba( 0, 0, 0, 0.1 ),
611
+ inset 0 0 0 1px rgba( 0, 0, 0, 0.05 );
612
+ background: #eee;
613
+ cursor: pointer;
614
+ }
615
+
616
+ .attachment .icon {
617
+ margin: 0 auto;
618
+ overflow: hidden;
619
+ padding-top: 20%;
620
+ }
621
+
622
+ .attachment .thumbnail {
623
+ display: block;
624
+ position: absolute;
625
+ top: 0;
626
+ left: 0;
627
+ margin: 0 auto;
628
+ overflow: hidden;
629
+ max-width: 100%;
630
+ max-height: 100%;
631
+ }
632
+
633
+ .attachment-preview .thumbnail:after {
634
+ content: '';
635
+ display: block;
636
+ position: absolute;
637
+ top: 0;
638
+ left: 0;
639
+ right: 0;
640
+ bottom: 0;
641
+ box-shadow: inset 0 0 0 1px rgba( 0, 0, 0, 0.1 );
642
+ overflow: hidden;
643
+ }
644
+
645
+ .attachment .thumbnail img {
646
+ top: 0;
647
+ left: 0;
648
+ }
649
+
650
+ .attachment .thumbnail .centered {
651
+ position: absolute;
652
+ top: 0;
653
+ left: 0;
654
+ width: 100%;
655
+ height: 100%;
656
+ -webkit-transform: translate( 50%, 50% );
657
+ -moz-transform: translate( 50%, 50% );
658
+ -ms-transform: translate( 50%, 50% );
659
+ -o-transform: translate( 50%, 50% );
660
+ transform: translate( 50%, 50% );
661
+ }
662
+
663
+ .attachment .thumbnail .centered img {
664
+ -webkit-transform: translate( -50%, -50% );
665
+ -moz-transform: translate( -50%, -50% );
666
+ -ms-transform: translate( -50%, -50% );
667
+ -o-transform: translate( -50%, -50% );
668
+ transform: translate( -50%, -50% );
669
+ }
670
+
671
+ .attachment .filename {
672
+ position: absolute;
673
+ left: 0;
674
+ right: 0;
675
+ bottom: 0;
676
+ overflow: hidden;
677
+ max-height: 100%;
678
+
679
+ word-wrap: break-word;
680
+ text-align: center;
681
+ font-weight: bold;
682
+ background: rgba( 255, 255, 255, 0.8 );
683
+ box-shadow: inset 0 0 0 1px rgba( 0, 0, 0, 0.15 );
684
+ }
685
+
686
+ .attachment .filename div {
687
+ padding: 5px 10px;
688
+ }
689
+
690
+ .attachment-preview .thumbnail {
691
+ width: 199px;
692
+ height: 199px;
693
+ }
694
+
695
+ .attachment .thumbnail img {
696
+ position: absolute;
697
+ }
698
+
699
+ .attachment .close {
700
+ display: none;
701
+ position: absolute;
702
+ top: 5px;
703
+ right: 5px;
704
+ height: 22px;
705
+ width: 22px;
706
+ padding: 0;
707
+ font-size: 20px;
708
+ line-height: 20px;
709
+ text-align: center;
710
+ text-decoration: none;
711
+ color: #464646;
712
+ background-color: #fff;
713
+ background-position: -96px 4px;
714
+ border-width: 0;
715
+ border-radius: 3px;
716
+ box-shadow: 0 0 0 1px rgba( 0, 0, 0, 0.3 );
717
+ }
718
+
719
+ .attachment .close:hover {
720
+ box-shadow: 0 0 0 1px rgba( 0, 0, 0, 0.6 );
721
+ }
722
+
723
+ .attachment:hover .close {
724
+ display: block;
725
+ }
726
+
727
+ .attachment .check {
728
+ display: none;
729
+ height: 24px;
730
+ width: 24px;
731
+ position: absolute;
732
+ top: -7px;
733
+ right: -7px;
734
+ outline: none;
735
+
736
+ border: 1px solid #fff;
737
+ border-radius: 3px;
738
+ box-shadow: 0 0 0 1px rgba( 0, 0, 0, 0.4 );
739
+
740
+ background: #f1f1f1;
741
+ background-image: -webkit-gradient(linear, left top, left bottom, from(#f1f1f1), to(#e1e1e1));
742
+ background-image: -webkit-linear-gradient(top, #f1f1f1, #e1e1e1);
743
+ background-image: -moz-linear-gradient(top, #f1f1f1, #e1e1e1);
744
+ background-image: -o-linear-gradient(top, #f1f1f1, #e1e1e1);
745
+ background-image: linear-gradient(to bottom, #f1f1f1, #e1e1e1);
746
+ }
747
+
748
+ .attachment .check div {
749
+ background-position: -1px 0;
750
+ height: 15px;
751
+ width: 15px;
752
+ margin: 5px;
753
+ }
754
+
755
+ .attachment .check:hover div {
756
+ background-position: -40px 0;
757
+ }
758
+
759
+ .attachment.selected .check {
760
+ display: block;
761
+ }
762
+
763
+ .attachment.details .check {
764
+ box-shadow: 0 0 0 1px #1e8cbe;
765
+
766
+ background: #1e8cbe;
767
+ background-image: -webkit-gradient(linear, left top, left bottom, from(#1e8cbe), to(#0074a2));
768
+ background-image: -webkit-linear-gradient(top, #1e8cbe, #0074a2);
769
+ background-image: -moz-linear-gradient(top, #1e8cbe, #0074a2);
770
+ background-image: -o-linear-gradient(top, #1e8cbe, #0074a2);
771
+ background-image: linear-gradient(to bottom, #1e8cbe, #0074a2);
772
+ }
773
+
774
+ .attachment.details .check div {
775
+ background-position: -21px 0;
776
+ }
777
+
778
+ .attachment.details .check:hover div {
779
+ background-position: -60px 0;
780
+ }
781
+
782
+ .sputnik-frame .attachment .describe {
783
+ position: relative;
784
+ display: block;
785
+ width: 100%;
786
+ margin: -1px 0 0;
787
+ padding: 8px;
788
+ font-size: 12px;
789
+ border-radius: 0;
790
+ }
791
+
792
+ /**
793
+ * Attachments Browser
794
+ */
795
+ .sputnik-frame .attachments-browser {
796
+ position: relative;
797
+ width: 100%;
798
+ height: 100%;
799
+ overflow: hidden;
800
+ }
801
+
802
+ .attachments-browser .sputnik-toolbar {
803
+ right: 300px;
804
+ height: 50px;
805
+ }
806
+
807
+ .attachments-browser .sputnik-toolbar-primary > .sputnik-button,
808
+ .attachments-browser .sputnik-toolbar-primary > .sputnik-button-group,
809
+ .attachments-browser .sputnik-toolbar-secondary > .sputnik-button,
810
+ .attachments-browser .sputnik-toolbar-secondary > .sputnik-button-group {
811
+ margin-top: 10px;
812
+ }
813
+
814
+ .attachments-browser .attachments,
815
+ .attachments-browser .uploader-inline {
816
+ position: absolute;
817
+ top: 50px;
818
+ left: 0;
819
+ right: 300px;
820
+ bottom: 0;
821
+ overflow: auto;
822
+ }
823
+
824
+ .attachments-browser .instructions {
825
+ display: inline-block;
826
+ margin-top: 16px;
827
+ line-height: 18px;
828
+ font-size: 13px;
829
+ color: #999;
830
+ }
831
+
832
+ /**
833
+ * Progress Bar
834
+ */
835
+ .sputnik-progress-bar {
836
+ position: relative;
837
+ height: 10px;
838
+ width: 70%;
839
+ margin: 10px auto;
840
+ border-radius: 10px;
841
+ background: #dfdfdf;
842
+ background: rgba( 0, 0, 0, 0.1 );
843
+ }
844
+
845
+ .sputnik-progress-bar div {
846
+ height: 10px;
847
+ min-width: 20px;
848
+ width: 0;
849
+ background: #aaa;
850
+ background: rgba( 0, 0, 0, 0.2 );
851
+ border-radius: 10px;
852
+ -webkit-transition: width 300ms;
853
+ -moz-transition: width 300ms;
854
+ -ms-transition: width 300ms;
855
+ -o-transition: width 300ms;
856
+ transition: width 300ms;
857
+ }
858
+
859
+ .sputnik-uploader-status .sputnik-progress-bar {
860
+ display: none;
861
+ width: 100%;
862
+ }
863
+
864
+ .uploading.sputnik-uploader-status .sputnik-progress-bar {
865
+ display: block;
866
+ }
867
+
868
+ .attachment-preview .sputnik-progress-bar {
869
+ position: absolute;
870
+ top: 50%;
871
+ left: 15%;
872
+ width: 70%;
873
+ margin: -5px 0 0 0;
874
+ }
875
+
876
+ .sputnik-uploader-status {
877
+ position: relative;
878
+ margin: 0 auto;
879
+ padding-bottom: 10px;
880
+ max-width: 400px;
881
+ }
882
+
883
+ .sputnik-sidebar .sputnik-uploader-status {
884
+ border-bottom: 1px solid #dfdfdf;
885
+ box-shadow: 0 1px 0 #fff;
886
+ }
887
+
888
+ .uploader-inline .sputnik-uploader-status h3 {
889
+ display: none;
890
+ }
891
+
892
+ .sputnik-uploader-status .upload-details {
893
+ display: none;
894
+ font-size: 12px;
895
+ color: #666;
896
+ text-shadow: 0 1px 0 #fff;
897
+ }
898
+
899
+ .uploading.sputnik-uploader-status .upload-details {
900
+ display: block;
901
+ }
902
+
903
+ .sputnik-uploader-status .upload-detail-separator {
904
+ padding: 0 4px;
905
+ }
906
+
907
+ .sputnik-uploader-status .upload-count {
908
+ color: #464646;
909
+ }
910
+
911
+ .sputnik-uploader-status .upload-dismiss-errors,
912
+ .sputnik-uploader-status .upload-errors {
913
+ display: none;
914
+ }
915
+
916
+ .errors.sputnik-uploader-status .upload-dismiss-errors,
917
+ .errors.sputnik-uploader-status .upload-errors {
918
+ display: block;
919
+ }
920
+
921
+ .sputnik-uploader-status .upload-dismiss-errors {
922
+ text-decoration: none;
923
+ }
924
+
925
+ .sputnik-sidebar .sputnik-uploader-status .upload-dismiss-errors {
926
+ position: absolute;
927
+ top: 0;
928
+ right: 0;
929
+ }
930
+
931
+ .upload-errors .upload-error {
932
+ margin: 8px auto 0 auto;
933
+ padding: 8px;
934
+ border: 1px #c00 solid;
935
+ background: #ffebe8;
936
+ border-radius: 3px;
937
+ }
938
+
939
+ .upload-errors .upload-error-label {
940
+ padding: 2px 4px;
941
+ margin-right: 8px;
942
+ font-weight: bold;
943
+ color: #fff;
944
+ background: #e00;
945
+ background-image: -webkit-gradient(linear, left top, left bottom, from(#e00), to(#a00));
946
+ background-image: -webkit-linear-gradient(top, #e00, #a00);
947
+ background-image: -moz-linear-gradient(top, #e00, #a00);
948
+ background-image: -o-linear-gradient(top, #e00, #a00);
949
+ background-image: linear-gradient(to bottom, #e00, #a00);
950
+ border-radius: 3px;
951
+ }
952
+
953
+ .upload-errors .upload-error-message {
954
+ display: block;
955
+ padding-top: 8px;
956
+ color: #b44;
957
+ word-wrap: break-word;
958
+ }
959
+
960
+ .uploader-window {
961
+ position: fixed;
962
+ top: 0;
963
+ left: 0;
964
+ right: 0;
965
+ bottom: 0;
966
+ background: rgba( 0, 86, 132, 0.9 );
967
+
968
+ z-index: 250000;
969
+ display: none;
970
+ text-align: center;
971
+ opacity: 0;
972
+
973
+ -webkit-transition: opacity 250ms;
974
+ -moz-transition: opacity 250ms;
975
+ -ms-transition: opacity 250ms;
976
+ -o-transition: opacity 250ms;
977
+ transition: opacity 250ms;
978
+ }
979
+
980
+ .uploader-window-content {
981
+ position: absolute;
982
+ top: 10px;
983
+ left: 10px;
984
+ right: 10px;
985
+ bottom: 10px;
986
+ border: 1px dashed #fff;
987
+ }
988
+
989
+ .uploader-window h3 {
990
+ position: absolute;
991
+ top: 50%;
992
+ left: 0;
993
+ right: 0;
994
+ -webkit-transform: translateY( -50% );
995
+ -moz-transform: translateY( -50% );
996
+ -ms-transform: translateY( -50% );
997
+ -o-transform: translateY( -50% );
998
+ transform: translateY( -50% );
999
+
1000
+ font-size: 20px;
1001
+ font-weight: 200;
1002
+ color: #fff;
1003
+ padding: 0;
1004
+ }
1005
+
1006
+ .uploader-window .sputnik-progress-bar {
1007
+ margin-top: 20px;
1008
+ max-width: 300px;
1009
+ background: transparent;
1010
+ border-color: #fff;
1011
+ display: none;
1012
+ }
1013
+
1014
+ .uploader-window .sputnik-progress-bar div {
1015
+ background: #fff;
1016
+ }
1017
+
1018
+ .uploading .uploader-window .sputnik-progress-bar {
1019
+ display: block;
1020
+ }
1021
+
1022
+ .sputnik-frame .uploader-inline {
1023
+ margin: 20px;
1024
+ padding: 20px;
1025
+ text-align: center;
1026
+ }
1027
+
1028
+ .uploader-inline-content {
1029
+ position: absolute;
1030
+ top: 30%;
1031
+ left: 0;
1032
+ right: 0;
1033
+ }
1034
+
1035
+ .uploader-inline-content .upload-ui {
1036
+ margin: 4em 0;
1037
+ }
1038
+
1039
+ .uploader-inline-content .post-upload-ui {
1040
+ margin-bottom: 2em;
1041
+ }
1042
+
1043
+ .uploader-inline .has-upload-message .upload-ui {
1044
+ margin: 0 0 4em;
1045
+ }
1046
+
1047
+ .uploader-inline h3 {
1048
+ font-size: 20px;
1049
+ line-height: 28px;
1050
+ font-weight: 200;
1051
+ margin-bottom: 1.6em;
1052
+ }
1053
+
1054
+ .uploader-inline .has-upload-message .upload-instructions {
1055
+ font-size: 14px;
1056
+ color: #464646;
1057
+ font-weight: normal;
1058
+ }
1059
+
1060
+ .uploader-inline .drop-instructions {
1061
+ display: none;
1062
+ }
1063
+
1064
+ .supports-drag-drop .uploader-inline .drop-instructions {
1065
+ display: block;
1066
+ }
1067
+
1068
+ .uploader-inline p {
1069
+ font-size: 12px;
1070
+ }
1071
+
1072
+ .uploader-inline .sputnik-progress-bar {
1073
+ display: none;
1074
+ }
1075
+
1076
+ .uploading.uploader-inline .sputnik-progress-bar {
1077
+ display: block;
1078
+ }
1079
+
1080
+ .uploader-inline .browser {
1081
+ display: inline-block !important;
1082
+ }
1083
+
1084
+ /**
1085
+ * Selection
1086
+ */
1087
+ .sputnik-selection {
1088
+ position: absolute;
1089
+ top: 0;
1090
+ left: 0;
1091
+ right: 350px;
1092
+ height: 60px;
1093
+ padding: 0 0 0 16px;
1094
+ overflow: hidden;
1095
+ white-space: nowrap;
1096
+ }
1097
+
1098
+ .sputnik-selection .selection-info {
1099
+ display: inline-block;
1100
+ font-size: 12px;
1101
+ height: 60px;
1102
+ margin-right: 10px;
1103
+ vertical-align: top;
1104
+ }
1105
+
1106
+ .sputnik-selection.empty,
1107
+ .sputnik-selection.editing {
1108
+ display: none;
1109
+ }
1110
+
1111
+ .sputnik-selection.one .edit-selection {
1112
+ display: none;
1113
+ }
1114
+
1115
+ .sputnik-selection .count {
1116
+ display: block;
1117
+ padding-top: 12px;
1118
+ font-size: 14px;
1119
+ line-height: 20px;
1120
+ font-weight: bold;
1121
+ }
1122
+
1123
+ .sputnik-selection .selection-info a {
1124
+ display: block;
1125
+ float: left;
1126
+ padding: 1px 8px;
1127
+ margin: 1px 8px 1px -8px;
1128
+ line-height: 16px;
1129
+ text-decoration: none;
1130
+ border-right: 1px solid #dfdfdf;
1131
+ color: #21759B;
1132
+ }
1133
+
1134
+ .sputnik-selection .selection-info a:hover {
1135
+ background: #21759B;
1136
+ color: #fff;
1137
+ border-color: transparent;
1138
+ }
1139
+
1140
+ .sputnik-selection .selection-info a:last-child {
1141
+ border-right: 0;
1142
+ margin-right: 0;
1143
+ }
1144
+
1145
+ .sputnik-selection .selection-info .clear-selection {
1146
+ color: red;
1147
+ }
1148
+
1149
+ .sputnik-selection .selection-info .clear-selection:hover {
1150
+ background: red;
1151
+ }
1152
+
1153
+ .sputnik-selection .selection-view {
1154
+ display: inline-block;
1155
+ vertical-align: top;
1156
+ }
1157
+
1158
+ .sputnik-selection .attachments {
1159
+ display: inline-block;
1160
+ height: 48px;
1161
+ margin-top: 5px;
1162
+ overflow: hidden;
1163
+ vertical-align: top;
1164
+ }
1165
+
1166
+ .sputnik-selection .attachment .icon {
1167
+ width: 50%;
1168
+ }
1169
+
1170
+ .attachment.selection.selected {
1171
+ box-shadow: none;
1172
+ }
1173
+
1174
+ .attachment.selection.details {
1175
+ box-shadow:
1176
+ 0 0 0 1px #fff,
1177
+ 0 0 0 4px #1e8cbe;
1178
+ }
1179
+
1180
+ .sputnik-selection .attachment.selection.details {
1181
+ box-shadow:
1182
+ 0 0 0 1px #fff,
1183
+ 0 0 0 3px #1e8cbe;
1184
+ }
1185
+
1186
+ .sputnik-selection:after {
1187
+ content: '';
1188
+ display: block;
1189
+ position: absolute;
1190
+ top: 0;
1191
+ right: 0;
1192
+ bottom: 0;
1193
+ width: 25px;
1194
+ background-image: -webkit-gradient(linear, right top, left top, from( rgba( 255, 255, 255, 1 ) ), to( rgba( 255, 255, 255, 0 ) ));
1195
+ background-image: -webkit-linear-gradient(right, rgba( 255, 255, 255, 1 ) , rgba( 255, 255, 255, 0 ) );
1196
+ background-image: -moz-linear-gradient(right, rgba( 255, 255, 255, 1 ) , rgba( 255, 255, 255, 0 ) );
1197
+ background-image: -o-linear-gradient(right, rgba( 255, 255, 255, 1 ) , rgba( 255, 255, 255, 0 ) );
1198
+ background-image: linear-gradient(to left, rgba( 255, 255, 255, 1 ) , rgba( 255, 255, 255, 0 ) );
1199
+ }
1200
+
1201
+ .sputnik-selection .attachment .filename {
1202
+ display: none;
1203
+ }
1204
+
1205
+ /**
1206
+ * Spinner
1207
+ */
1208
+
1209
+ .sputnik-frame .spinner {
1210
+ background: url(../images/wpspin.gif) no-repeat;
1211
+ background-size: 16px 16px;
1212
+ display: none;
1213
+ opacity: 0.7;
1214
+ filter: alpha(opacity=70);
1215
+ width: 16px;
1216
+ height: 16px;
1217
+ margin: 0;
1218
+ }
1219
+
1220
+ .sputnik-sidebar .settings-save-status {
1221
+ background: #f5f5f5;
1222
+ float: right;
1223
+ text-transform: none;
1224
+ z-index: 10;
1225
+ }
1226
+
1227
+ .sputnik-sidebar .settings-save-status .spinner {
1228
+ margin: 0 5px 0;
1229
+ }
1230
+
1231
+ .sputnik-sidebar .settings-save-status .saved {
1232
+ float: right;
1233
+ display: none;
1234
+ }
1235
+
1236
+ .sputnik-sidebar .save-waiting .settings-save-status .spinner,
1237
+ .sputnik-sidebar .save-complete .settings-save-status .saved {
1238
+ display: block;
1239
+ }
1240
+
1241
+ /**
1242
+ * Attachment Details
1243
+ */
1244
+ .attachment-details {
1245
+ position: relative;
1246
+ overflow: auto;
1247
+ }
1248
+
1249
+ .attachment-info {
1250
+ overflow: hidden;
1251
+ min-height: 60px;
1252
+ margin-bottom: 16px;
1253
+ line-height: 18px;
1254
+ color: #999;
1255
+ border-bottom: 1px solid #e5e5e5;
1256
+ box-shadow: 0 1px 0 #fff;
1257
+ padding-bottom: 11px;
1258
+ }
1259
+
1260
+ .attachment-info .filename {
1261
+ font-weight: bold;
1262
+ color: #464646;
1263
+ word-wrap: break-word;
1264
+ }
1265
+
1266
+ .attachment-info .thumbnail {
1267
+ position: relative;
1268
+ float: left;
1269
+ max-width: 120px;
1270
+ max-height: 120px;
1271
+ margin-top: 5px;
1272
+ margin-right: 10px;
1273
+ margin-bottom: 5px;
1274
+ }
1275
+
1276
+ .uploading .attachment-info .thumbnail {
1277
+ width: 120px;
1278
+ height: 80px;
1279
+ box-shadow: inset 0 0 15px rgba( 0, 0, 0, 0.1 );
1280
+ }
1281
+
1282
+ .uploading .attachment-info .sputnik-progress-bar {
1283
+ margin-top: 35px;
1284
+ }
1285
+
1286
+ .attachment-info .thumbnail:after {
1287
+ content: '';
1288
+ display: block;
1289
+ position: absolute;
1290
+ top: 0;
1291
+ left: 0;
1292
+ right: 0;
1293
+ bottom: 0;
1294
+ box-shadow: inset 0 0 0 1px rgba( 0, 0, 0, 0.15 );
1295
+ overflow: hidden;
1296
+ }
1297
+
1298
+ .attachment-info .thumbnail img {
1299
+ display: block;
1300
+ max-width: 120px;
1301
+ max-height: 120px;
1302
+ margin: 0 auto;
1303
+ }
1304
+
1305
+ .attachment-info .details {
1306
+ float: left;
1307
+ font-size: 12px;
1308
+ max-width: 100%;
1309
+ }
1310
+
1311
+ .attachment-info .edit-attachment,
1312
+ .attachment-info .refresh-attachment,
1313
+ .attachment-info .delete-attachment {
1314
+ display: block;
1315
+ text-decoration: none;
1316
+ white-space: nowrap;
1317
+ }
1318
+
1319
+ .attachment-info .refresh-attachment,
1320
+ .attachment-details.needs-refresh .attachment-info .edit-attachment {
1321
+ display: none;
1322
+ }
1323
+
1324
+ .attachment-details.needs-refresh .attachment-info .refresh-attachment,
1325
+ .attachment-info .edit-attachment {
1326
+ display: block;
1327
+ }
1328
+
1329
+ .attachment-info .delete-attachment {
1330
+ color: #bc0b0b;
1331
+ }
1332
+
1333
+ .attachment-info .delete-attachment:hover {
1334
+ color: red;
1335
+ }
1336
+
1337
+ /**
1338
+ * Attachment Display Settings
1339
+ */
1340
+ .attachment-display-settings {
1341
+ width: 100%;
1342
+ float: left;
1343
+ overflow: hidden;
1344
+ }
1345
+
1346
+ .attachment-display-settings h4 {
1347
+ margin: 1.4em 0 0.4em;
1348
+ }
1349
+
1350
+ .gallery-settings {
1351
+ overflow: hidden;
1352
+ }
1353
+
1354
+ /**
1355
+ * Embed from URL
1356
+ */
1357
+ .embed-url {
1358
+ display: block;
1359
+ position: relative;
1360
+ padding: 0 16px 7px;
1361
+ margin: 0;
1362
+ z-index: 250;
1363
+ background: #fff;
1364
+ border-bottom: 1px solid #dfdfdf;
1365
+ box-shadow: 0 4px 4px -4px rgba( 0, 0, 0, 0.1 );
1366
+ font-size: 18px;
1367
+ font-weight: 200;
1368
+ }
1369
+
1370
+ .sputnik-frame .embed-url input {
1371
+ font-size: 18px;
1372
+ padding: 12px 14px;
1373
+ width: 100%;
1374
+ min-width: 200px;
1375
+ box-shadow: inset 2px 2px 4px -2px rgba( 0, 0, 0, 0.1 );
1376
+ }
1377
+
1378
+ .sputnik-frame .embed-url .spinner {
1379
+ position: absolute;
1380
+ top: 16px;
1381
+ right: 26px;
1382
+ }
1383
+
1384
+ .sputnik-frame .embed-loading .embed-url .spinner {
1385
+ display: block;
1386
+ }
1387
+
1388
+ .embed-link-settings,
1389
+ .embed-image-settings {
1390
+ position: absolute;
1391
+ background: #f5f5f5;
1392
+ top: 57px;
1393
+ left: 0;
1394
+ right: 0;
1395
+ bottom: 0;
1396
+ padding: 16px 16px 32px;
1397
+ overflow: auto;
1398
+ }
1399
+
1400
+ .sputnik-embed .thumbnail {
1401
+ max-width: 100%;
1402
+ max-height: 200px;
1403
+ position: relative;
1404
+ float: left;
1405
+ }
1406
+
1407
+ .sputnik-embed .thumbnail img {
1408
+ max-height: 200px;
1409
+ display: block;
1410
+ }
1411
+
1412
+ .sputnik-embed .thumbnail:after {
1413
+ content: '';
1414
+ display: block;
1415
+ position: absolute;
1416
+ top: 0;
1417
+ left: 0;
1418
+ right: 0;
1419
+ bottom: 0;
1420
+ box-shadow: inset 0 0 0 1px rgba( 0, 0, 0, 0.1 );
1421
+ overflow: hidden;
1422
+ }
1423
+
1424
+ .sputnik-embed .setting {
1425
+ width: 100%;
1426
+ margin-top: 10px;
1427
+ float: left;
1428
+ display: block;
1429
+ clear: both;
1430
+ }
1431
+
1432
+ .sputnik-embed .setting span {
1433
+ display: block;
1434
+ width: 200px;
1435
+ font-size: 13px;
1436
+ line-height: 24px;
1437
+ color: #999;
1438
+ text-shadow: 0 1px 0 #fff;
1439
+ }
1440
+
1441
+ .sputnik-embed .setting .button-group {
1442
+ margin: 2px 0;
1443
+ }
1444
+
1445
+ .sputnik-embed .setting input,
1446
+ .sputnik-embed .setting textarea {
1447
+ display: block;
1448
+ width: 100%;
1449
+ max-width: 400px;
1450
+ margin: 1px 0;
1451
+ }
1452
+
1453
+ /**
1454
+ * IE7 Fixes
1455
+ */
1456
+ .ie7 .sputnik-frame .attachments-browser {
1457
+ position: static;
1458
+ }
1459
+
1460
+ .ie7 .sputnik-frame .embed-url input {
1461
+ margin-top: 4px;
1462
+ width: 90%;
1463
+ }
1464
+
1465
+ .ie7 .compat-item {
1466
+ width: 99%;
1467
+ }
1468
+
1469
+ .ie7 .attachment-display-settings {
1470
+ width: auto;
1471
+ }
1472
+
1473
+ .ie7 .attachment-preview,
1474
+ .ie7 .attachment-preview .thumbnail {
1475
+ width: 120px;
1476
+ height: 120px;
1477
+ }
1478
+
1479
+ .ie7 .sputnik-frame .attachment .describe {
1480
+ width: 102px;
1481
+ }
1482
+
1483
+ .ie7 .sputnik-sidebar .setting select {
1484
+ max-width: 55%;
1485
+ }
1486
+
1487
+ .ie7 .sputnik-sidebar .setting input,
1488
+ .ie7 .sputnik-sidebar .setting textarea {
1489
+ width: 55%;
1490
+ }
1491
+
1492
+ .ie7 .sputnik-sidebar .setting .link-to-custom {
1493
+ float: left;
1494
+ }
1495
+
1496
+ @media only screen and (max-width: 960px) {
1497
+ .sputnik-frame-content .sputnik-toolbar-primary .search,
1498
+ .sputnik-frame-content .sputnik-toolbar-secondary .attachment-filters {
1499
+ max-width: 120px;
1500
+ }
1501
+ }
1502
+
1503
+ /**
1504
+ * Responsive layout
1505
+ */
1506
+ @media only screen and (max-width: 900px) {
1507
+ .sputnik-frame-menu {
1508
+ width: 139px;
1509
+ }
1510
+
1511
+ .sputnik-menu > a {
1512
+ padding: 4px 10px;
1513
+ }
1514
+
1515
+ .sputnik-frame-title,
1516
+ .sputnik-frame-router,
1517
+ .sputnik-frame-content,
1518
+ .sputnik-frame-toolbar {
1519
+ left: 140px;
1520
+ }
1521
+
1522
+ .sputnik-sidebar {
1523
+ width: 159px;
1524
+ padding: 0 10px 24px;
1525
+ }
1526
+
1527
+ .attachments-browser .attachments,
1528
+ .attachments-browser .uploader-inline,
1529
+ .attachments-browser .sputnik-toolbar {
1530
+ right: 180px;
1531
+ }
1532
+
1533
+ .sputnik-sidebar .setting input,
1534
+ .sputnik-sidebar .setting textarea,
1535
+ .sputnik-sidebar .setting span,
1536
+ .compat-item label span {
1537
+ float: none;
1538
+ }
1539
+
1540
+ .sputnik-sidebar .setting span,
1541
+ .compat-item label span {
1542
+ text-align: inherit;
1543
+ display: block;
1544
+ min-height: 16px;
1545
+ margin: 0;
1546
+ padding: 8px 2px 0;
1547
+ }
1548
+
1549
+ .sputnik-sidebar .setting input,
1550
+ .sputnik-sidebar .setting textarea,
1551
+ .sputnik-sidebar .setting select {
1552
+ width: 98%;
1553
+ max-width: none;
1554
+ }
1555
+
1556
+ .sputnik-sidebar .setting select.columns {
1557
+ width: auto;
1558
+ }
1559
+
1560
+ .sputnik-frame input,
1561
+ .sputnik-frame textarea,
1562
+ .sputnik-frame .search {
1563
+ padding: 3px 6px;
1564
+ }
1565
+
1566
+ .sputnik-frame-content .attachment .icon {
1567
+ top: 40%;
1568
+ }
1569
+
1570
+ .sputnik-selection {
1571
+ min-width: 120px;
1572
+ }
1573
+
1574
+ .sputnik-selection:after {
1575
+ background: none;
1576
+ }
1577
+
1578
+ .sputnik-selection .attachments {
1579
+ display: none;
1580
+ }
1581
+
1582
+ .sputnik-menu .separator {
1583
+ margin: 12px 10px;
1584
+ }
1585
+ }
1586
+
1587
+ @media only screen and (max-width: 800px) {
1588
+ .sputnik-frame-content .sputnik-toolbar .instructions {
1589
+ display: none;
1590
+ }
1591
+ }
1592
+
1593
+ @media only screen and (max-width: 680px) {
1594
+ .sputnik-frame-content .sputnik-toolbar .search,
1595
+ .sputnik-frame-content .sputnik-toolbar .attachment-filters {
1596
+ max-width: 85px;
1597
+ }
1598
+ }
1599
+
1600
+ /* Use the same min-width as in the admin */
1601
+ @media only screen and (max-width: 600px) {
1602
+ .sputnik-modal {
1603
+ width: 540px;
1604
+ position: absolute;
1605
+ }
1606
+
1607
+ .sputnik-modal-backdrop {
1608
+ width: 600px;
1609
+ position: absolute;
1610
+ }
1611
+ }
1612
+
1613
+ /**
1614
+ * HiDPI Displays
1615
+ */
1616
+ @media print,
1617
+ (-o-min-device-pixel-ratio: 5/4),
1618
+ (-webkit-min-device-pixel-ratio: 1.25),
1619
+ (min-resolution: 120dpi) {
1620
+ .sputnik-modal-icon {
1621
+ background-image: url(../images/uploader-icons-2x.png);
1622
+ background-size: 134px 15px;
1623
+ }
1624
+
1625
+ .sputnik-frame .spinner {
1626
+ background-image: url(../images/wpspin-2x.gif);
1627
+ }
1628
+ }
wpsc-components/marketplace-core-v1/static/modal.js ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ window.sputnik = window.sputnik || {};
2
+
3
+ (function($){
4
+ sputnik = function( attributes ) {
5
+ //if ( media.view.MediaFrame.Post )
6
+ // return new media.view.MediaFrame.Post( attributes ).render().attach().open();
7
+ };
8
+
9
+ _.extend( sputnik, { model: {}, view: {}, controller: {} });
10
+
11
+ // Link any localized strings.
12
+ //l10n = media.model.l10n = _.isUndefined( _wpMediaModelsL10n ) ? {} : _wpMediaModelsL10n;
13
+
14
+ _.extend( sputnik, {
15
+ /**
16
+ * sputnik.template( id )
17
+ *
18
+ * Fetches a template by id.
19
+ *
20
+ * @param {string} id A string that corresponds to a DOM element with an id prefixed with "tmpl-".
21
+ * For example, "attachment" maps to "tmpl-attachment".
22
+ * @return {function} A function that lazily-compiles the template requested.
23
+ */
24
+ template: _.memoize( function( id ) {
25
+ var compiled,
26
+ options = {
27
+ evaluate: /<#([\s\S]+?)#>/g,
28
+ interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
29
+ escape: /\{\{([\s\S]+?)\}\}/g
30
+ };
31
+
32
+ return function( data ) {
33
+ compiled = compiled || _.template( $( '#tmpl-' + id ).html(), null, options );
34
+ return compiled( data );
35
+ };
36
+ }),
37
+ });
38
+
39
+ sputnik.controller.Region = function( options ) {
40
+ _.extend( this, _.pick( options || {}, 'id', 'controller' ) );
41
+
42
+ this.on( 'activate:empty', this.empty, this );
43
+ this.mode('empty');
44
+ };
45
+
46
+ // Use Backbone's self-propagating `extend` inheritance method.
47
+ sputnik.controller.Region.extend = Backbone.Model.extend;
48
+
49
+ _.extend( sputnik.controller.Region.prototype, Backbone.Events, {
50
+ trigger: (function() {
51
+ var eventSplitter = /\s+/,
52
+ trigger = Backbone.Events.trigger;
53
+
54
+ return function( events ) {
55
+ var mode = ':' + this._mode,
56
+ modeEvents = events.split( eventSplitter ).join( mode ) + mode;
57
+
58
+ trigger.apply( this, arguments );
59
+ trigger.apply( this, [ modeEvents ].concat( _.rest( arguments ) ) );
60
+ return this;
61
+ };
62
+ }()),
63
+
64
+ mode: function( mode ) {
65
+ if ( mode ) {
66
+ this.trigger('deactivate');
67
+ this._mode = mode;
68
+ return this.trigger('activate');
69
+ }
70
+ return this._mode;
71
+ },
72
+
73
+ view: function( view ) {
74
+ var previous = this._view,
75
+ mode = this._mode,
76
+ id = this.id;
77
+
78
+ // If no argument is provided, return the current view.
79
+ if ( ! view )
80
+ return previous;
81
+
82
+ // If we're attempting to switch to the current view, bail.
83
+ if ( view === previous )
84
+ return;
85
+
86
+ // Add classes to the new view.
87
+ if ( id )
88
+ view.$el.addClass( 'region-' + id );
89
+
90
+ if ( mode )
91
+ view.$el.addClass( 'mode-' + mode );
92
+
93
+ // Remove the hide class.
94
+ // this.$el.removeClass( 'hide-' + subview );
95
+
96
+ if ( previous ) {
97
+ // Replace the view in place.
98
+ previous.$el.replaceWith( view.$el );
99
+
100
+ // Fire the view's `destroy` event if it exists.
101
+ if ( previous.destroy )
102
+ previous.destroy();
103
+ // Undelegate events.
104
+ previous.undelegateEvents();
105
+ }
106
+
107
+ this._view = view;
108
+ },
109
+
110
+ empty: function() {
111
+ this.view( new Backbone.View() );
112
+ }
113
+ });
114
+
115
+ sputnik.model.Plugin = Backbone.Model.extend({
116
+ defaults: {
117
+ title: '',
118
+ version: '',
119
+ tested: '',
120
+ requires: '',
121
+ rating: 0,
122
+ user_rating: 0,
123
+ }
124
+ })
125
+
126
+ /*sputnik.model.Plugin = Backbone.Model.extend({
127
+ sync: function( method, model, options ) {
128
+ if ( 'read' === method ) {
129
+ options = options || {};
130
+ options.context = this;
131
+ options.data = _.extend( options.data || {}, {
132
+ action: 'sputnik-get-plugin',
133
+ id: this.id
134
+ });
135
+ return media.ajax( options );
136
+ }
137
+ },
138
+
139
+ parse: function( resp, xhr ) {
140
+ if ( ! resp )
141
+ return resp;
142
+
143
+ // Convert date strings into Date objects.
144
+ resp.date = new Date( resp.date );
145
+ resp.modified = new Date( resp.modified );
146
+ return resp;
147
+ }
148
+ }, {
149
+ create: function( attrs ) {
150
+ return Attachments.all.push( attrs );
151
+ },
152
+
153
+ get: _.memoize( function( id, attachment ) {
154
+ return Attachments.all.push( attachment || { id: id } );
155
+ })
156
+ });*/
157
+
158
+
159
+ /**
160
+ * wp.media.view.Frame
161
+ */
162
+ sputnik.view.Frame = Backbone.View.extend({
163
+ className: 'sputnik-frame',
164
+ regions: ['menu', 'content'],
165
+
166
+ initialize: function() {
167
+ this._createRegions();
168
+ this._createStates();
169
+
170
+ _.defaults( this.options, {
171
+ title: '',
172
+ modal: true
173
+ });
174
+
175
+ // Initialize modal container view.
176
+ if ( this.options.modal ) {
177
+ this.modal = new sputnik.view.Modal({
178
+ controller: this,
179
+ $content: this.$el,
180
+ title: this.options.title
181
+ });
182
+ }
183
+ },
184
+
185
+ _createRegions: function() {
186
+ // Clone the regions array.
187
+ this.regions = this.regions ? this.regions.slice() : [];
188
+
189
+ // Initialize regions.
190
+ _.each( this.regions, function( region ) {
191
+ this[ region ] = new sputnik.controller.Region({
192
+ controller: this,
193
+ id: region
194
+ });
195
+ }, this );
196
+ },
197
+
198
+ _createStates: function() {
199
+ // Create the default `states` collection.
200
+ this.states = new Backbone.Collection();
201
+
202
+ // Ensure states have a reference to the frame.
203
+ this.states.on( 'add', function( model ) {
204
+ model.frame = this;
205
+ }, this );
206
+ },
207
+
208
+ render: function() {
209
+ if ( this.modal )
210
+ this.modal.render();
211
+
212
+ var els = _.map( this.regions, function( region ) {
213
+ return this[ region ].view().el;
214
+ }, this );
215
+
216
+ // Detach the current views to maintain event bindings.
217
+ $( els ).detach();
218
+ this.$el.html( els );
219
+
220
+ return this;
221
+ },
222
+
223
+ reset: function() {
224
+ this.states.invoke( 'trigger', 'reset' );
225
+ }
226
+ });
227
+
228
+ // Make the `Frame` a `StateMachine`.
229
+ //_.extend( media.view.Frame.prototype, media.controller.StateMachine.prototype );
230
+
231
+ // Map some of the modal's methods to the frame.
232
+ _.each(['open','close','attach','detach'], function( method ) {
233
+ sputnik.view.Frame.prototype[ method ] = function( view ) {
234
+ if ( this.modal )
235
+ this.modal[ method ].apply( this.modal, arguments );
236
+ return this;
237
+ };
238
+ });
239
+
240
+ sputnik.view.Modal = Backbone.View.extend({
241
+ tagName: 'div',
242
+ template: sputnik.template('sputnik-modal'),
243
+
244
+ events: {
245
+ 'click .sputnik-modal-backdrop, .sputnik-modal-close' : 'closeHandler'
246
+ },
247
+
248
+ initialize: function() {
249
+ //this.controller = this.options.controller;
250
+
251
+ _.defaults( this.options, {
252
+ container: document.body,
253
+ title: ''
254
+ });
255
+ },
256
+
257
+ render: function() {
258
+ // Ensure content div exists.
259
+ this.options.$content = this.options.$content || $('<div />');
260
+
261
+ // Detach the content element from the DOM to prevent
262
+ // `this.$el.html()` from garbage collecting its events.
263
+ this.options.$content.detach();
264
+
265
+ this.$el.html( this.template({
266
+ title: this.options.title
267
+ }) );
268
+
269
+ this.options.$content.addClass('sputnik-modal-content');
270
+ this.$('.sputnik-modal').append( this.options.$content );
271
+ return this;
272
+ },
273
+
274
+ attach: function() {
275
+ this.$el.appendTo( this.options.container );
276
+ //this.controller.trigger( 'attach', this.controller );
277
+ return this;
278
+ },
279
+
280
+ detach: function() {
281
+ this.$el.detach();
282
+ //this.controller.trigger( 'detach', this.controller );
283
+ return this;
284
+ },
285
+
286
+ open: function() {
287
+ this.$el.show();
288
+ //this.controller.trigger( 'open', this.controller );
289
+ return this;
290
+ },
291
+
292
+ close: function() {
293
+ this.$el.hide();
294
+ //this.controller.trigger( 'close', this.controller );
295
+ return this;
296
+ },
297
+
298
+ closeHandler: function( event ) {
299
+ event.preventDefault();
300
+ this.close();
301
+ },
302
+
303
+ content: function( $content ) {
304
+ // Detach any existing content to prevent events from being lost.
305
+ if ( this.options.$content )
306
+ this.options.$content.detach();
307
+
308
+ // Set and render the content.
309
+ this.options.$content = ( $content instanceof Backbone.View ) ? $content.$el : $content;
310
+ return this.render();
311
+ }
312
+ });
313
+ })(jQuery);
wpsc-components/marketplace-core-v1/static/sputnik.css ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ div.sputnik-message {
2
+ margin: 5px 0 15px;
3
+ background-color: rgb( 237, 249, 255 );
4
+ border-style: solid;
5
+ border-width: 1px 1px 1px 4px;
6
+ border-color: rgb(204, 222, 230) rgb(204, 222, 230) rgb(204, 222, 230) rgb(33, 117, 155) ;
7
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
8
+ padding: 1px 12px;
9
+ position: relative;
10
+ }
11
+ div.sputnik-message p {
12
+ padding: 2px;
13
+ margin: 0.5em 0px;
14
+ font-size: 14px;
15
+ line-height: 1.5em;
16
+ }
17
+ div.sputnik-message .button {
18
+ position: absolute;
19
+ right: 12px;
20
+ top: 10px;
21
+ font-size: 20px;
22
+ padding: 0px 15px 2px;
23
+ line-height: 41px;
24
+ height: 43px;
25
+ }
26
+
27
+
28
+ .sputnik-plugin-row-note {
29
+ display: block;
30
+ float: right;
31
+ height: 30px;
32
+ width: 200px;
33
+ line-height: 30px;
34
+ margin-right: -7px;
35
+ margin-top: -7px;
36
+ }
37
+ .sputnik-plugin-row-note:hover {
38
+ background: #D94C45;
39
+ }
40
+ .sputnik-plugin-row-note:hover .powered {
41
+ display: block;
42
+ }
43
+ .sputnik-plugin-row-note:hover .corner {
44
+ display: none;
45
+ }
46
+
47
+ .sputnik-plugin-row-note .powered {
48
+ display: none;
49
+ text-align: center;
50
+ color: #fff;
51
+ }
52
+
53
+ .sputnik-plugin-row-note .corner {
54
+ border-left: 15px solid transparent;
55
+ border-top: 15px solid transparent;
56
+ border-right: 15px solid #D94C45;
57
+ border-bottom: 15px solid #D94C45;
58
+
59
+ display: block;
60
+ float: right;
61
+ height: 0;
62
+ width: 0;
63
+ }
wpsc-components/marketplace-core-v1/static/sputnik.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+ $('.sputnik-message').insertAfter( $('div.wrap h2:first') );
3
+ //$('#menu-posts-wpsc-product').before('<li class="wp-not-current-submenu wp-menu-separator"><div class="separator"></div></li>');
4
+ $('#menu-posts-wpsc-product div ul li a[href$="page=sputnik-account"]').parent('li').remove();
5
+ });
wpsc-components/marketplace-core-v1/static/star.png ADDED
Binary file
wpsc-components/merchant-core-v2/helpers/admin.php CHANGED
@@ -78,7 +78,7 @@ function _wpsc_filter_merchant_v2_gateway_form( $form, $selected_gateway ) {
78
  $output = ob_get_clean();
79
  $return = array(
80
  'name' => $selected_gateway_data['name'],
81
- 'form_fields' => $output . $selected_gateway_data['form'](),
82
  'has_submit_button' => 0,
83
  );
84
  }
78
  $output = ob_get_clean();
79
  $return = array(
80
  'name' => $selected_gateway_data['name'],
81
+ 'form_fields' => $output . call_user_func( $selected_gateway_data['form'] ),
82
  'has_submit_button' => 0,
83
  );
84
  }
wpsc-components/merchant-core-v2/helpers/checkout.php CHANGED
@@ -4,15 +4,16 @@ add_filter( 'wpsc_get_gateway_list', '_wpsc_filter_merchant_v2_get_gateway_list'
4
 
5
  function _wpsc_filter_merchant_v2_get_gateway_list() {
6
  ob_start();
7
- while (wpsc_have_gateways()) : wpsc_the_gateway(); ?>
8
  <div class="custom_gateway">
9
  <label><input type="radio" value="<?php echo wpsc_gateway_internal_name();?>" <?php echo wpsc_gateway_is_checked(); ?> name="custom_gateway" class="custom_gateway"/><?php echo wpsc_gateway_name(); ?>
10
- <?php if( wpsc_show_gateway_image() ): ?>
11
- <img src="<?php echo wpsc_gateway_image_url(); ?>" alt="<?php echo wpsc_gateway_name(); ?>" style="position:relative; top:5px;" />
12
- <?php endif; ?>
 
13
  </label>
14
 
15
- <?php if(wpsc_gateway_form_fields()): ?>
16
  <table class='wpsc_checkout_table <?php echo wpsc_gateway_form_field_style();?>'>
17
  <?php echo wpsc_gateway_form_fields();?>
18
  </table>
@@ -22,6 +23,172 @@ function _wpsc_filter_merchant_v2_get_gateway_list() {
22
  return ob_get_clean();
23
  }
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  add_filter( 'wpsc_gateway_count', '_wpsc_filter_merchant_v2_gateway_count' );
26
 
27
  function _wpsc_filter_merchant_v2_gateway_count( $count ) {
4
 
5
  function _wpsc_filter_merchant_v2_get_gateway_list() {
6
  ob_start();
7
+ while ( wpsc_have_gateways() ) : wpsc_the_gateway(); ?>
8
  <div class="custom_gateway">
9
  <label><input type="radio" value="<?php echo wpsc_gateway_internal_name();?>" <?php echo wpsc_gateway_is_checked(); ?> name="custom_gateway" class="custom_gateway"/><?php echo wpsc_gateway_name(); ?>
10
+ <?php if ( wpsc_show_gateway_image() ):
11
+ $gateway_image = '<img src="' . esc_url( wpsc_gateway_image_url() ) . '" alt="' . esc_attr( wpsc_gateway_name() ) . '" style="position:relative; top:5px;" />';
12
+ echo apply_filters( 'wpsc_gateway_image', $gateway_image, wpsc_gateway_internal_name() );
13
+ endif; ?>
14
  </label>
15
 
16
+ <?php if ( wpsc_gateway_form_fields() ) : ?>
17
  <table class='wpsc_checkout_table <?php echo wpsc_gateway_form_field_style();?>'>
18
  <?php echo wpsc_gateway_form_fields();?>
19
  </table>
23
  return ob_get_clean();
24
  }
25
 
26
+ function _wpsc_filter_merchant_v2_payment_method_form_fields( $fields ) {
27
+ $selected_value = isset( $_POST['wpsc_payment_method'] )
28
+ ? $_POST['wpsc_payment_method']
29
+ : '';
30
+
31
+ if ( empty( $selected_value ) ) {
32
+ $current_purchase_log_id = wpsc_get_customer_meta( 'current_purchase_log_id' );
33
+ $purchase_log = new WPSC_Purchase_Log( $current_purchase_log_id );
34
+ $selected_value = $purchase_log->get( 'gateway' );
35
+ }
36
+
37
+ foreach ( _wpsc_merchant_v2_get_active_gateways() as $gateway ) {
38
+ $gateway = (object) $gateway;
39
+ $title = $gateway->name;
40
+ if ( ! empty( $gateway->image ) )
41
+ $title .= ' <img src="' . $gateway->image . '" alt="' . $gateway->name . '" />';
42
+
43
+ $field = array(
44
+ 'title' => $title,
45
+ 'type' => 'radio',
46
+ 'value' => $gateway->internalname,
47
+ 'name' => 'wpsc_payment_method',
48
+ 'checked' => $selected_value == $gateway->internalname,
49
+ );
50
+
51
+ $fields[] = $field;
52
+ }
53
+
54
+ // check the first payment gateway by default
55
+ if ( empty( $selected_value ) )
56
+ $fields[0]['checked'] = true;
57
+
58
+ return $fields;
59
+ }
60
+
61
+ add_filter(
62
+ 'wpsc_payment_method_form_fields',
63
+ '_wpsc_filter_merchant_v2_payment_method_form_fields'
64
+ );
65
+
66
+ function _wpsc_filter_merchant_v2_field_after( $output, $field, $r ) {
67
+ if ( $field['name'] != 'wpsc_payment_method' )
68
+ return $output;
69
+
70
+ foreach ( _wpsc_merchant_v2_get_active_gateways() as $gateway ) {
71
+ if ( $gateway['internalname'] == $field['value'] ) {
72
+ $extra_form = _wpsc_merchant_v2_get_gateway_form( $gateway );
73
+ $extra_form = _wpsc_merchant_v2_hack_gateway_field_names( $extra_form, $gateway );
74
+ if ( ! empty( $extra_form ) ) {
75
+ $output .= '<table class="wpsc-payment-gateway-extra-form wpsc-payment-gateway-extra-form-' . $gateway['internalname'] . '"><tbody>';
76
+ $output .= $extra_form;
77
+ $output .= '</tbody></table>';
78
+ }
79
+ break;
80
+ }
81
+ }
82
+
83
+ return $output;
84
+ }
85
+ add_filter( 'wpsc_field_after', '_wpsc_filter_merchant_v2_field_after', 10, 3 );
86
+
87
+ function _wpsc_merchant_v2_hack_gateway_field_names( $extra_form, $gateway ) {
88
+ $fields = array(
89
+ 'card_number',
90
+ 'card_number1',
91
+ 'card_number2',
92
+ 'card_number3',
93
+ 'card_number4',
94
+ 'expiry',
95
+ 'card_code',
96
+ 'cctype',
97
+ );
98
+
99
+ $regexp = '/(name\s*=\s*[\'"])(' . implode( '|', $fields ) . ')(["\'\[])/';
100
+ $replace = '/$1extra_form[' . $gateway['internalname'] . '][$2]$3';
101
+ $extra_form = preg_replace( $regexp, $replace, $extra_form );
102
+ return $extra_form;
103
+ }
104
+
105
+ function _wpsc_merchant_v2_get_active_gateways() {
106
+ global $nzshpcrt_gateways;
107
+ static $gateways = null;
108
+
109
+ if ( is_null( $gateways ) ) {
110
+ $active = get_option( 'custom_gateway_options' );
111
+ foreach ( $nzshpcrt_gateways as $gateway ) {
112
+ if ( in_array( $gateway['internalname'], (array) $active ) )
113
+ $gateways[] = $gateway;
114
+ }
115
+ }
116
+
117
+ return $gateways;
118
+ }
119
+
120
+ function _wpsc_merchant_v2_get_gateway_form( $gateway ) {
121
+ global $gateway_checkout_form_fields, $wpsc_gateway_error_messages;
122
+
123
+ $submitted_gateway = isset( $_POST['wpsc_payment_method'] )
124
+ ? $_POST['wpsc_payment_method']
125
+ : '';
126
+
127
+ $error = array(
128
+ 'card_number' => '',
129
+ 'expdate' => '',
130
+ 'card_code' => '',
131
+ 'cctype' => '',
132
+ );
133
+
134
+ if (
135
+ ! empty( $submitted_gateway )
136
+ && $submitted_gateway == $gateway['internalname']
137
+ && is_array( $wpsc_gateway_error_messages )
138
+ )
139
+ $error = array_merge( $error, $wpsc_gateway_error_messages );
140
+
141
+ $classes = array();
142
+ foreach ( array( 'card_number', 'expdate', 'card_code', 'cctype' ) as $field ) {
143
+ if ( empty( $error[$field] ) )
144
+ $classes[$field] = '';
145
+ else
146
+ $classes[$field] = 'class="validation-error"';
147
+ }
148
+
149
+ // Match fields to gateway
150
+ switch ( $gateway['internalname'] ) {
151
+ case 'paypal_pro' : // legacy
152
+ case 'wpsc_merchant_paypal_pro' :
153
+ $output = sprintf(
154
+ $gateway_checkout_form_fields[$gateway['internalname']],
155
+ $classes['card_number'], $error['card_number'],
156
+ $classes['expdate'], $error['expdate'],
157
+ $classes['card_code'], $error['card_code'],
158
+ $classes['cctype'], $error['cctype']
159
+ );
160
+ break;
161
+
162
+ case 'authorize' :
163
+ case 'paypal_payflow' :
164
+ $output = @sprintf( $gateway_checkout_form_fields[$gateway['internalname']], $classes['card_number'], $error['card_number'],
165
+ $classes['expdate'], $error['expdate'],
166
+ $classes['card_code'], $error['card_code']
167
+ );
168
+ break;
169
+
170
+ case 'eway' :
171
+ case 'bluepay' :
172
+ $output = sprintf( $gateway_checkout_form_fields[$gateway['internalname']], $classes['card_number'], $error['card_number'],
173
+ $classes['expdate'], $error['expdate']
174
+ );
175
+ break;
176
+ case 'linkpoint' :
177
+ $output = sprintf( $gateway_checkout_form_fields[$gateway['internalname']], $classes['card_number'], $error['card_number'],
178
+ $classes['expdate'], $error['expdate']
179
+ );
180
+ break;
181
+
182
+ }
183
+
184
+ if ( isset( $output ) && ! empty( $output ) )
185
+ return $output;
186
+ elseif ( isset( $gateway_checkout_form_fields[$gateway['internalname']] ) )
187
+ return $gateway_checkout_form_fields[$gateway['internalname']];
188
+ return '';
189
+ }
190
+
191
+
192
  add_filter( 'wpsc_gateway_count', '_wpsc_filter_merchant_v2_gateway_count' );
193
 
194
  function _wpsc_filter_merchant_v2_gateway_count( $count ) {
wpsc-components/merchant-core-v2/helpers/gateways.php CHANGED
@@ -1,4 +1,23 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  /**
4
  * The WPSC Gateway functions
@@ -220,3 +239,80 @@ add_action(
220
  function _wpsc_merchant_v2_before_shopping_cart() {
221
  $GLOBALS['wpsc_gateway'] = new wpsc_gateways();
222
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+ /**
3
+ * nzshpcrt_get_gateways()
4
+ *
5
+ * Deprecated function for returning the merchants global
6
+ *
7
+ * @global array $nzshpcrt_gateways
8
+ * @return array
9
+ */
10
+ function nzshpcrt_get_gateways() {
11
+
12
+ global $nzshpcrt_gateways;
13
+
14
+ if ( !is_array( $nzshpcrt_gateways ) )
15
+ wpsc_core_load_gateways();
16
+
17
+ return $nzshpcrt_gateways;
18
+
19
+ }
20
+
21
 
22
  /**
23
  * The WPSC Gateway functions
239
  function _wpsc_merchant_v2_before_shopping_cart() {
240
  $GLOBALS['wpsc_gateway'] = new wpsc_gateways();
241
  }
242
+
243
+ add_filter(
244
+ '_wpsc_merchant_v2_validate_payment_method',
245
+ '_wpsc_action_merchant_v2_validate_payment_method',
246
+ 10,
247
+ 2
248
+ );
249
+
250
+ function _wpsc_action_merchant_v2_validate_payment_method( $valid, $controller ) {
251
+ $fields = array(
252
+ 'card_number',
253
+ 'card_number1',
254
+ 'card_number2',
255
+ 'card_number3',
256
+ 'card_number4',
257
+ 'card_code',
258
+ 'cctype',
259
+ );
260
+
261
+ $selected_gateway = $_POST['wpsc_payment_method'];
262
+ if (
263
+ ! isset( $_POST['extra_form'] )
264
+ || ! isset( $_POST['extra_form'][$selected_gateway] )
265
+ )
266
+ return $valid;
267
+
268
+ $extra = $_POST['extra_form'][$selected_gateway];
269
+ $card_number_error = false;
270
+ $messages = array();
271
+ foreach ( $fields as $field ) {
272
+ if ( isset( $extra[$field] ) && trim( $extra[$field] ) == '' ) {
273
+ switch ( $field ) {
274
+ case 'card_number':
275
+ case 'card_number1':
276
+ case 'card_number2':
277
+ case 'card_number3':
278
+ case 'card_number4':
279
+ if ( $card_number_error )
280
+ continue;
281
+
282
+ $messages['card_number'] = __( 'Please enter a valid credit card number', 'wpsc' );
283
+ $card_number_error = true;
284
+ break;
285
+ case 'card_code':
286
+ $messages[$field] = __( 'Please enter a valid CVV', 'wpsc' );
287
+ break;
288
+ case 'cctype':
289
+ $messages[$field] = __( 'Please select a valid credit card type', 'wpsc' );
290
+ break;
291
+ }
292
+ }
293
+ }
294
+
295
+ if ( ! empty( $extra['expiry'] ) )
296
+ foreach ( array( 'month', 'year' ) as $element ) {
297
+ if (
298
+ empty( $extra['expiry'][$element] )
299
+ || ! is_numeric( $extra['expiry'][$element] )
300
+ ) {
301
+ $messages['expdate'] = __( 'Please specify a valid expiration date.', 'wpsc' );
302
+ break;
303
+ }
304
+ }
305
+
306
+ if ( ! empty( $messages ) ) {
307
+ foreach ( $messages as $field => $message ) {
308
+ $controller->message_collection->add( $message, 'validation' );
309
+ }
310
+ $GLOBALS['wpsc_gateway_error_messages'] = $messages;
311
+ return false;
312
+ }
313
+
314
+ foreach ( $extra as $key => $value ) {
315
+ $_POST[$key] = $value;
316
+ }
317
+ return true;
318
+ }
wpsc-includes/breadcrumbs.class.php → wpsc-components/theme-engine-v1/classes/breadcrumbs.php RENAMED
@@ -259,6 +259,4 @@ class wpsc_breadcrumbs {
259
  }
260
  }
261
 
262
- }
263
-
264
- ?>
259
  }
260
  }
261
 
262
+ }
 
 
wpsc-components/theme-engine-v1/classes/hide-subcatsprods-in-cat.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * wpsc_display_products_page class
5
+ *
6
+ * Shows only products from current category, but not from subcategories.
7
+ *
8
+ * @access public
9
+ * @return void
10
+ */
11
+
12
+ class WPSC_Hide_subcatsprods_in_cat {
13
+ var $q;
14
+
15
+ function get_posts( &$q ) {
16
+ $this->q =& $q;
17
+ if ( ( !isset($q->query_vars['taxonomy']) || ( "wpsc_product_category" != $q->query_vars['taxonomy'] )) )
18
+ return false;
19
+
20
+ add_action( 'posts_where', array( &$this, 'where' ) );
21
+ add_action( 'posts_join', array( &$this, 'join' ) );
22
+ }
23
+
24
+ function where( $where ) {
25
+ global $wpdb;
26
+
27
+ remove_action( 'posts_where', array( &$this, 'where' ) );
28
+
29
+ $term_id=$wpdb->get_var($wpdb->prepare('SELECT term_id FROM '.$wpdb->terms.' WHERE slug = %s ', $this->q->query_vars['term']));
30
+
31
+ if ( !is_numeric( $term_id ) || $term_id < 1 )
32
+ return $where;
33
+
34
+ $term_taxonomy_id = $wpdb->get_var($wpdb->prepare('SELECT term_taxonomy_id FROM '.$wpdb->term_taxonomy.' WHERE term_id = %d and taxonomy = %s', $term_id, $this->q->query_vars['taxonomy']));
35
+
36
+ if ( !is_numeric($term_taxonomy_id) || $term_taxonomy_id < 1)
37
+ return $where;
38
+
39
+ $field = preg_quote( "$wpdb->term_relationships.term_taxonomy_id", '#' );
40
+
41
+ $just_one = $wpdb->prepare( " AND $wpdb->term_relationships.term_taxonomy_id = %d ", $term_taxonomy_id );
42
+ if ( preg_match( "#AND\s+$field\s+IN\s*\(\s*(?:['\"]?\d+['\"]?\s*,\s*)*['\"]?\d+['\"]?\s*\)#", $where, $matches ) )
43
+ $where = str_replace( $matches[0], $just_one, $where );
44
+ else
45
+ $where .= $just_one;
46
+
47
+ return $where;
48
+ }
49
+
50
+ function join($join){
51
+ global $wpdb;
52
+ remove_action( 'posts_where', array( &$this, 'where' ) );
53
+ remove_action( 'posts_join', array( &$this, 'join' ) );
54
+ if( strpos($join, "JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)" ) ){
55
+ return $join;
56
+ }
57
+ $join .= " JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
58
+ return $join;
59
+ }
60
+ }
61
+
wpsc-admin/includes/settings-tabs/presentation.php → wpsc-components/theme-engine-v1/classes/settings-tab-presentation.php RENAMED
@@ -470,7 +470,7 @@ class WPSC_Settings_Tab_Presentation extends WPSC_Settings_Tab {
470
  <tr id="wpsc-grid-settings">
471
  <th scope="row"><?php esc_html_e( 'Grid view settings:', 'wpsc' ) ?></th>
472
  <td>
473
- <input type='number' name='wpsc_options[grid_number_per_row]' id='grid_number_per_row' size='2' value='<?php esc_attr_e( get_option( 'grid_number_per_row' ) ); ?>' />
474
  <label for='grid_number_per_row'><?php esc_html_e( 'Products Per Row', 'wpsc' ); ?></label><br />
475
 
476
  <input type='hidden' value='0' name='wpsc_options[show_images_only]' />
470
  <tr id="wpsc-grid-settings">
471
  <th scope="row"><?php esc_html_e( 'Grid view settings:', 'wpsc' ) ?></th>
472
  <td>
473
+ <input type='number' min="0" name='wpsc_options[grid_number_per_row]' id='grid_number_per_row' size='2' value='<?php esc_attr_e( get_option( 'grid_number_per_row' ) ); ?>' />
474
  <label for='grid_number_per_row'><?php esc_html_e( 'Products Per Row', 'wpsc' ); ?></label><br />
475
 
476
  <input type='hidden' value='0' name='wpsc_options[show_images_only]' />
wpsc-components/theme-engine-v1/classes/wpsc-products-by-category.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * wpsc_products_by_category class.
4
+ *
5
+ */
6
+ class wpsc_products_by_category {
7
+
8
+ var $sql_components = array( );
9
+
10
+ /**
11
+ * wpsc_products_by_category function.
12
+ *
13
+ * @access public
14
+ * @param mixed $query
15
+ * @return void
16
+ */
17
+ function wpsc_products_by_category( $query ) {
18
+ global $wpdb;
19
+ $q = $query->query_vars;
20
+
21
+
22
+ // Category stuff for nice URLs
23
+ if ( !empty( $q['wpsc_product_category'] ) && !$query->is_singular ) {
24
+ $q['taxonomy'] = 'wpsc_product_category';
25
+ $q['term'] = $q['wpsc_product_category'];
26
+ $in_cats = '';
27
+ $join = " INNER JOIN $wpdb->term_relationships
28
+ ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
29
+ INNER JOIN $wpdb->term_taxonomy
30
+ ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
31
+ ";
32
+ if(isset($q['meta_key']))
33
+ $join .= " INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) ";
34
+
35
+ $whichcat = " AND $wpdb->term_taxonomy.taxonomy = '{$q['taxonomy']}' ";
36
+
37
+ $term_data = get_term_by( 'slug', $q['term'], $q['taxonomy'] );
38
+
39
+ if( is_object( $term_data ) )
40
+ $in_cats = array( $term_data->term_id );
41
+
42
+ if('0' != get_option('show_subcatsprods_in_cat') && is_object($term_data)){
43
+ $term_children_data = get_term_children( $term_data->term_id, $q['taxonomy'] );
44
+ $in_cats = array_reverse( array_merge( $in_cats, $term_children_data ) );
45
+ }
46
+ if( is_array( $in_cats ) ){
47
+ $in_cats = "'" . implode( "', '", $in_cats ) . "'";
48
+ $whichcat .= "AND $wpdb->term_taxonomy.term_id IN ($in_cats)";
49
+ }
50
+
51
+ $post_type_object = get_post_type_object( 'wpsc-product' );
52
+ $permitted_post_statuses = current_user_can( $post_type_object->cap->edit_posts ) ? "'private', 'draft', 'pending', 'publish'" : "'publish'";
53
+
54
+ $whichcat .= " AND $wpdb->posts.post_status IN ($permitted_post_statuses) ";
55
+ $groupby = "{$wpdb->posts}.ID";
56
+
57
+ $this->sql_components['join'] = $join;
58
+ $this->sql_components['fields'] = "{$wpdb->posts}.*, {$wpdb->term_taxonomy}.term_id, {$wpdb->term_relationships}.term_order";
59
+ $this->sql_components['group_by'] = $groupby;
60
+
61
+ //what about ordering by price
62
+ if(isset($q['meta_key']) && '_wpsc_price' == $q['meta_key']){
63
+ $whichcat .= " AND $wpdb->postmeta.meta_key = '_wpsc_price'";
64
+ }else{
65
+ $this->sql_components['order_by'] = "{$wpdb->term_taxonomy}.term_id";
66
+
67
+ // Term Taxonomy ID Ordering
68
+ if ( $q['orderby'] == 'menu_order' ) {
69
+ if ( $term_data ) {
70
+ $this->sql_components['order_by'] = "{$wpdb->term_relationships}.term_order ASC";
71
+ }
72
+ }
73
+ }
74
+ $this->sql_components['where'] = $whichcat;
75
+ add_filter( 'posts_join', array( &$this, 'join_sql' ) );
76
+ add_filter( 'posts_where', array( &$this, 'where_sql' ) );
77
+ add_filter( 'posts_fields', array( &$this, 'fields_sql' ) );
78
+ add_filter( 'posts_orderby', array( &$this, 'order_by_sql' ) );
79
+ add_filter( 'posts_groupby', array( &$this, 'group_by_sql' ) );
80
+ }
81
+ }
82
+
83
+ function join_sql( $sql ) {
84
+ if ( isset( $this->sql_components['join'] ) )
85
+ $sql = $this->sql_components['join'];
86
+
87
+ remove_filter( 'posts_join', array( &$this, 'join_sql' ) );
88
+ return $sql;
89
+ }
90
+
91
+ function where_sql( $sql ) {
92
+ if ( isset( $this->sql_components['where'] ) )
93
+ $sql = $this->sql_components['where'];
94
+
95
+ remove_filter( 'posts_where', array( &$this, 'where_sql' ) );
96
+ return $sql;
97
+ }
98
+
99
+ function order_by_sql( $sql ) {
100
+ $order_by_parts = array( );
101
+ $order_by_parts[] = $sql;
102
+
103
+ if ( isset( $this->sql_components['order_by'] ) )
104
+ $order_by_parts[] = $this->sql_components['order_by'];
105
+
106
+ $order_by_parts = array_reverse( $order_by_parts );
107
+ $sql = implode( ',', $order_by_parts );
108
+
109
+ remove_filter( 'posts_orderby', array( &$this, 'order_by_sql' ) );
110
+ return $sql;
111
+ }
112
+
113
+ function fields_sql( $sql ) {
114
+ if ( isset( $this->sql_components['fields'] ) )
115
+ $sql = $this->sql_components['fields'];
116
+
117
+ remove_filter( 'posts_fields', array( &$this, 'fields_sql' ) );
118
+ return $sql;
119
+ }
120
+
121
+ function group_by_sql( $sql ) {
122
+ if ( isset( $this->sql_components['group_by'] ) )
123
+ $sql = $this->sql_components['group_by'];
124
+
125
+ remove_filter( 'posts_groupby', array( &$this, 'group_by_sql' ) );
126
+ return $sql;
127
+ }
128
+
129
+ function request_sql( $sql ) {
130
+ echo $sql . "<br />";
131
+ remove_filter( 'posts_request', array( &$this, 'request_sql' ) );
132
+ return $sql;
133
+ }
134
+ }
135
+
wpsc-components/theme-engine-v1/helpers/admin.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'wpsc_register_settings_tabs', '_wpsc_te_v1_register_settings_tabs', 10, 1 );
4
+ add_action( 'wpsc_load_settings_tab_class', '_wpsc_te_v1_load_settings_tab_class', 10, 1 );
5
+
6
+ function _wpsc_te_v1_register_settings_tabs( $page_instance ) {
7
+ $page_instance->register_tab( 'presentation', _x( 'Presentation', 'Presentation settings tab in Settings->Store page', 'wpsc' ) );
8
+ }
9
+
10
+ function _wpsc_te_v1_load_settings_tab_class( $page_instance ) {
11
+ $current_tab_id = $page_instance->get_current_tab_id();
12
+ if ( in_array( $current_tab_id, array( 'presentation' ) ) )
13
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/classes/settings-tab-presentation.php' );
14
+ }
wpsc-components/theme-engine-v1/helpers/ajax.php ADDED
@@ -0,0 +1,1112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ add_action('wp_ajax_wpsc_shipping_same_as_billing', 'wpsc_shipping_same_as_billing');
3
+ add_action( 'wp_ajax_shipping_same_as_billing_update', 'wpsc_update_shipping_quotes_on_shipping_same_as_billing' );
4
+ add_action( 'wp_ajax_nopriv_shipping_same_as_billing_update', 'wpsc_update_shipping_quotes_on_shipping_same_as_billing' );
5
+
6
+ if ( isset( $_GET['termsandconds'] ) && 'true' == $_GET['termsandconds'] )
7
+ add_action( 'init', 'wpsc_show_terms_and_conditions' );
8
+
9
+ if ( isset( $_REQUEST['wpsc_action'] ) && ($_REQUEST['wpsc_action'] == 'submit_checkout') )
10
+ add_action( 'init', 'wpsc_submit_checkout', 10, 0 );
11
+
12
+ if ( isset( $_REQUEST['wpsc_action'] ) && ($_REQUEST['wpsc_action'] == 'cart_html_page') )
13
+ add_action( 'init', 'wpsc_cart_html_page', 110 );
14
+
15
+ if ( get_option( 'wpsc_also_bought' ) == 1 )
16
+ add_action( 'wpsc_submit_checkout', 'wpsc_populate_also_bought_list' );
17
+
18
+ if ( isset( $_REQUEST['get_rating_count'] ) && ($_REQUEST['get_rating_count'] == 'true') && is_numeric( $_POST['product_id'] ) )
19
+ add_action( 'init', 'wpsc_get_rating_count' );
20
+
21
+ if ( isset( $_REQUEST['wpsc_ajax_action'] ) && ($_REQUEST['wpsc_ajax_action'] == 'special_widget' || $_REQUEST['wpsc_ajax_action'] == 'donations_widget') )
22
+ add_action( 'init', 'wpsc_special_widget' );
23
+
24
+ if ( isset( $_REQUEST['wpsc_ajax_action'] ) && (($_REQUEST['wpsc_ajax_action'] == 'empty_cart') || (isset($_GET['sessionid']) && ($_GET['sessionid'] > 0))) )
25
+ add_action( 'init', 'wpsc_empty_cart' );
26
+
27
+ if ( isset( $_POST['coupon_num'] ) )
28
+ add_action( 'init', 'wpsc_coupon_price' );
29
+
30
+ if ( isset( $_REQUEST['wpsc_ajax_action'] ) && 'add_to_cart' == $_REQUEST['wpsc_ajax_action'] )
31
+ add_action( 'init', 'wpsc_add_to_cart' );
32
+
33
+ if ( isset( $_REQUEST['wpsc_update_quantity'] ) && ($_REQUEST['wpsc_update_quantity'] == 'true') )
34
+ add_action( 'init', 'wpsc_update_item_quantity' );
35
+
36
+ if ( isset( $_REQUEST['wpsc_ajax_action'] ) && ($_REQUEST['wpsc_ajax_action'] == 'rate_product') )
37
+ add_action( 'init', 'wpsc_update_product_rating' );
38
+
39
+ add_action( 'wp_ajax_add_to_cart' , 'wpsc_add_to_cart' );
40
+ add_action( 'wp_ajax_nopriv_add_to_cart', 'wpsc_add_to_cart' );
41
+ add_action( 'wp_ajax_get_cart' , 'wpsc_get_cart' );
42
+ add_action( 'wp_ajax_nopriv_get_cart', 'wpsc_get_cart' );
43
+ add_action( 'wp_ajax_update_shipping_price' , 'wpsc_update_shipping_price' );
44
+ add_action( 'wp_ajax_nopriv_update_shipping_price', 'wpsc_update_shipping_price' );
45
+ add_action( 'wp_ajax_update_product_price' , 'wpsc_update_product_price' );
46
+ add_action( 'wp_ajax_nopriv_update_product_price', 'wpsc_update_product_price' );
47
+ add_action( 'wp_ajax_update_location' , 'wpsc_update_location' );
48
+ add_action( 'wp_ajax_nopriv_update_location', 'wpsc_update_location' );
49
+ add_action( 'wp_ajax_change_tax' , 'wpsc_change_tax' );
50
+ add_action( 'wp_ajax_nopriv_change_tax', 'wpsc_change_tax' );
51
+ add_action( 'wp_ajax_change_profile_country' , '_wpsc_change_profile_country' );
52
+ add_action( 'wp_ajax_nopriv_change_profile_country', '_wpsc_change_profile_country' );
53
+
54
+
55
+ /**
56
+ * WP eCommerce AJAX and Init functions
57
+ *
58
+ * These are the WPSC AJAX and Init functions
59
+ *
60
+ * @package wp-e-commerce
61
+ * @since 3.7
62
+ */
63
+ function wpsc_special_widget() {
64
+ wpsc_add_to_cart();
65
+ }
66
+
67
+ /**
68
+ * add_to_cart function, used through ajax and in normal page loading.
69
+ * No parameters, returns nothing
70
+ */
71
+ function wpsc_add_to_cart() {
72
+ global $wpsc_cart;
73
+
74
+ /// default values
75
+ $default_parameters['variation_values'] = null;
76
+ $default_parameters['quantity'] = 1;
77
+ $default_parameters['provided_price'] = null;
78
+ $default_parameters['comment'] = null;
79
+ $default_parameters['time_requested'] = null;
80
+ $default_parameters['custom_message'] = null;
81
+ $default_parameters['file_data'] = null;
82
+ $default_parameters['is_customisable'] = false;
83
+ $default_parameters['meta'] = null;
84
+
85
+ $provided_parameters = array();
86
+ $post_type_object = get_post_type_object( 'wpsc-product' );
87
+ $permitted_post_statuses = current_user_can( $post_type_object->cap->edit_posts ) ? array( 'private', 'draft', 'pending', 'publish' ) : array( 'publish' );
88
+
89
+ /// sanitise submitted values
90
+ $product_id = apply_filters( 'wpsc_add_to_cart_product_id' , (int) $_POST['product_id'] );
91
+ $product = apply_filters( 'wpsc_add_to_cart_product_object', get_post( $product_id, OBJECT, 'display' ) );
92
+
93
+ if ( ! in_array( $product->post_status, $permitted_post_statuses ) || 'wpsc-product' != $product->post_type )
94
+ return false;
95
+
96
+ // compatibility with older themes
97
+ if ( isset( $_POST['wpsc_quantity_update'] ) && is_array( $_POST['wpsc_quantity_update'] ) ) {
98
+ $_POST['wpsc_quantity_update'] = $_POST['wpsc_quantity_update'][$product_id];
99
+ }
100
+
101
+ if(isset($_POST['variation'])){
102
+ foreach ( (array) $_POST['variation'] as $key => $variation ) {
103
+ $provided_parameters['variation_values'][ (int) $key ] = (int) $variation;
104
+ }
105
+
106
+ if ( count( $provided_parameters['variation_values'] ) > 0 ) {
107
+ $variation_product_id = wpsc_get_child_object_in_terms( $product_id, $provided_parameters['variation_values'], 'wpsc-variation' );
108
+ if ( $variation_product_id > 0 ) {
109
+ $product_id = $variation_product_id;
110
+ }
111
+ }
112
+
113
+ }
114
+
115
+ if ( (isset( $_POST['quantity'] ) && $_POST['quantity'] > 0) && (!isset( $_POST['wpsc_quantity_update'] )) ) {
116
+ $provided_parameters['quantity'] = (int) $_POST['quantity'];
117
+ } else if ( isset( $_POST['wpsc_quantity_update'] ) ) {
118
+ $wpsc_cart->remove_item( $_POST['key'] );
119
+ $provided_parameters['quantity'] = (int) $_POST['wpsc_quantity_update'];
120
+ }
121
+
122
+ if ( isset( $_POST['is_customisable'] ) &&
123
+ 'true' == $_POST['is_customisable'] ) {
124
+ $provided_parameters['is_customisable'] = true;
125
+
126
+ if ( isset( $_POST['custom_text'] ) ) {
127
+ $provided_parameters['custom_message'] = stripslashes( $_POST['custom_text'] );
128
+ }
129
+ if ( isset( $_FILES['custom_file'] ) ) {
130
+ $provided_parameters['file_data'] = $_FILES['custom_file'];
131
+ }
132
+ }
133
+
134
+ if ( isset( $_POST['donation_price'] ) && ( (float) $_POST['donation_price'] > 0 ) ) {
135
+ $provided_parameters['provided_price'] = (float) $_POST['donation_price'];
136
+ }
137
+
138
+ $parameters = array_merge( $default_parameters, (array) $provided_parameters );
139
+
140
+ $cart_item = $wpsc_cart->set_item( $product_id, $parameters );
141
+
142
+ if ( is_object( $cart_item ) ) {
143
+ do_action( 'wpsc_add_to_cart', $product, $cart_item );
144
+ $cart_messages[] = str_replace( "[product_name]", $cart_item->get_title(), __( 'You just added "[product_name]" to your cart.', 'wpsc' ) );
145
+ } else {
146
+ if ( $parameters['quantity'] <= 0 ) {
147
+ $cart_messages[] = __( 'Sorry, but you cannot add zero items to your cart', 'wpsc' );
148
+ } else if ( $wpsc_cart->get_remaining_quantity( $product_id, $parameters['variation_values'], $parameters['quantity'] ) > 0 ) {
149
+ $quantity = $wpsc_cart->get_remaining_quantity( $product_id, $parameters['variation_values'], $parameters['quantity'] );
150
+ $cart_messages[] = sprintf( _n( 'Sorry, but there is only %s of this item in stock.', 'Sorry, but there are only %s of this item in stock.', $quantity, 'wpsc' ), $quantity );
151
+ } else {
152
+ $cart_messages[] = sprintf( __( 'Sorry, but the item "%s" is out of stock.', 'wpsc' ), $cart_item->get_title() );
153
+ }
154
+ }
155
+
156
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
157
+ $json_response = array( 'cart_messages' => $cart_messages, 'product_id' => $product_id, 'cart_total' => wpsc_cart_total() );
158
+
159
+ $output = _wpsc_ajax_get_cart( false, $cart_messages );
160
+
161
+ $json_response = $json_response + $output;
162
+
163
+ if ( is_numeric( $product_id ) && 1 == get_option( 'fancy_notifications' ) )
164
+ $json_response['fancy_notification'] = str_replace( array( "\n", "\r" ), array( '\n', '\r' ), fancy_notification_content( $cart_messages ) );
165
+
166
+ $json_response = apply_filters( 'wpsc_add_to_cart_json_response', $json_response );
167
+
168
+ die( json_encode( $json_response ) );
169
+ }
170
+ }
171
+
172
+ function wpsc_get_cart() {
173
+ _wpsc_ajax_get_cart();
174
+ }
175
+
176
+ /* 19-02-09
177
+ * add cart button function used for php template tags and shortcodes
178
+ */
179
+
180
+ function wpsc_add_to_cart_button( $product_id, $return = false ) {
181
+ global $wpdb,$wpsc_variations;
182
+ $output = '';
183
+ if ( $product_id > 0 ) {
184
+ // grab the variation form fields here
185
+ $wpsc_variations = new wpsc_variations( $product_id );
186
+ if ( $return )
187
+ ob_start();
188
+ ?>
189
+ <div class='wpsc-add-to-cart-button'>
190
+ <form class='wpsc-add-to-cart-button-form' id='product_<?php echo esc_attr( $product_id ) ?>' action='' method='post'>
191
+ <?php do_action( 'wpsc_add_to_cart_button_form_begin' ); ?>
192
+ <div class='wpsc_variation_forms'>
193
+ <?php while ( wpsc_have_variation_groups() ) : wpsc_the_variation_group(); ?>
194
+ <p>
195
+ <label for='<?php echo wpsc_vargrp_form_id(); ?>'><?php echo esc_html( wpsc_the_vargrp_name() ) ?>:</label>
196
+ <select class='wpsc_select_variation' name='variation[<?php echo wpsc_vargrp_id(); ?>]' id='<?php echo wpsc_vargrp_form_id(); ?>'>
197
+ <?php while ( wpsc_have_variations() ): wpsc_the_variation(); ?>
198
+ <option value='<?php echo wpsc_the_variation_id(); ?>' <?php echo wpsc_the_variation_out_of_stock(); ?>><?php echo esc_html( wpsc_the_variation_name() ); ?></option>
199
+ <?php endwhile; ?>
200
+ </select>
201
+ </p>
202
+ <?php endwhile; ?>
203
+ </div>
204
+ <input type='hidden' name='wpsc_ajax_action' value='add_to_cart' />
205
+ <input type='hidden' name='product_id' value='<?php echo $product_id; ?>' />
206
+ <input type='submit' id='product_<?php echo $product_id; ?>_submit_button' class='wpsc_buy_button' name='Buy' value='<?php echo __( 'Add To Cart', 'wpsc' ); ?>' />
207
+ <?php do_action( 'wpsc_add_to_cart_button_form_end' ); ?>
208
+ </form>
209
+ </div>
210
+ <?php
211
+
212
+ if ( $return )
213
+ return ob_get_clean();
214
+ }
215
+ }
216
+
217
+ /* 19-02-09
218
+ * add to cart shortcode function used for shortcodes calls the function in
219
+ * product_display_functions.php
220
+ */
221
+
222
+ function add_to_cart_shortcode( $content = '' ) {
223
+ static $fancy_notification_output = false;
224
+ if ( ! in_the_loop() )
225
+ return $content;
226
+
227
+ if ( preg_match_all( "/\[add_to_cart=([\d]+)\]/", $content, $matches ) ) {
228
+ foreach ( $matches[1] as $key => $product_id ) {
229
+ $original_string = $matches[0][$key];
230
+ $output = wpsc_add_to_cart_button( $product_id, true );
231
+ $content = str_replace( $original_string, $output, $content );
232
+ }
233
+
234
+ if ( ! $fancy_notification_output ) {
235
+ $content .= wpsc_fancy_notifications( true );
236
+ $fancy_notification_output = true;
237
+ }
238
+ }
239
+ return $content;
240
+ }
241
+
242
+ /**
243
+ * empty cart function, used through ajax and in normal page loading.
244
+ * No parameters, returns nothing
245
+ */
246
+ function wpsc_empty_cart() {
247
+ global $wpsc_cart;
248
+ $wpsc_cart->empty_cart( false );
249
+
250
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
251
+ $output = _wpsc_ajax_get_cart( false );
252
+ die( json_encode( $output ) );
253
+ }
254
+ }
255
+
256
+ /**
257
+ * coupons price, used through ajax and in normal page loading.
258
+ * No parameters, returns nothing
259
+ */
260
+ function wpsc_coupon_price( $currCoupon = '' ) {
261
+ global $wpsc_cart, $wpsc_coupons;
262
+ if ( isset( $_POST['coupon_num'] ) && $_POST['coupon_num'] != '' ) {
263
+ $coupon = esc_sql( $_POST['coupon_num'] );
264
+ wpsc_update_customer_meta( 'coupon', $coupon );
265
+ $wpsc_coupons = new wpsc_coupons( $coupon );
266
+
267
+ if ( $wpsc_coupons->validate_coupon() ) {
268
+ $discountAmount = $wpsc_coupons->calculate_discount();
269
+ $wpsc_cart->apply_coupons( $discountAmount, $coupon );
270
+ $wpsc_coupons->errormsg = false;
271
+ } else {
272
+ $wpsc_coupons->errormsg = true;
273
+ $wpsc_cart->coupons_amount = 0;
274
+ $wpsc_cart->coupons_name = '';
275
+ wpsc_delete_customer_meta( 'coupon' );
276
+ }
277
+ } else if ( (!isset( $_POST['coupon_num'] ) || $_POST['coupon_num'] == '') && $currCoupon == '' ) {
278
+ $wpsc_cart->coupons_amount = 0;
279
+ $wpsc_cart->coupons_name = '';
280
+ } else if ( $currCoupon != '' ) {
281
+ $coupon = esc_sql( $currCoupon );
282
+ wpsc_update_customer_meta( 'coupon', $coupon );
283
+ $wpsc_coupons = new wpsc_coupons( $coupon );
284
+
285
+ if ( $wpsc_coupons->validate_coupon() ) {
286
+ $discountAmount = $wpsc_coupons->calculate_discount();
287
+ $wpsc_cart->apply_coupons( $discountAmount, $coupon );
288
+ $wpsc_coupons->errormsg = false;
289
+ }
290
+ }
291
+ }
292
+
293
+ /**
294
+ * update quantity function, used through ajax and in normal page loading.
295
+ * No parameters, returns nothing
296
+ */
297
+ function wpsc_update_item_quantity() {
298
+ global $wpsc_cart;
299
+
300
+ if ( is_numeric( $_POST['key'] ) ) {
301
+ $key = (int)$_POST['key'];
302
+
303
+ $quantity = isset( $_POST['wpsc_quantity_update'] ) ? $_POST['wpsc_quantity_update'] : '';
304
+
305
+ if ( isset( $_POST['quantity'] ) )
306
+ $quantity = $_POST['quantity'];
307
+
308
+ if ( $quantity > 0 ) {
309
+ // if the quantity is greater than 0, update the item;
310
+ $parameters['quantity'] = (int) $quantity;
311
+ $wpsc_cart->edit_item( $key, $parameters );
312
+ } else {
313
+ // if the quantity is 0, remove the item.
314
+ $wpsc_cart->remove_item( $key );
315
+ }
316
+
317
+ $coupon = wpsc_get_customer_meta( 'coupon' );
318
+ if ( $coupon ) {
319
+ wpsc_coupon_price( $coupon );
320
+ }
321
+ }
322
+ $die = ! ( ( isset( $_REQUEST['wpsc_ajax_action'] ) && 'true' == $_REQUEST['wpsc_ajax_action'] ) || ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) );
323
+ _wpsc_ajax_get_cart( $die );
324
+ }
325
+
326
+
327
+ function wpsc_update_product_rating() {
328
+ global $wpdb;
329
+ $nowtime = time();
330
+ $product_id = absint( $_POST['product_id'] );
331
+ $ip_number = $_SERVER['REMOTE_ADDR'];
332
+ $rating = absint( $_POST['product_rating'] );
333
+
334
+ $cookie_data = explode( ",", $_COOKIE['voting_cookie'][$product_id] );
335
+
336
+ if ( is_numeric( $cookie_data[0] ) && ($cookie_data[0] > 0) ) {
337
+ $vote_id = absint( $cookie_data[0] );
338
+ $wpdb->update( WPSC_TABLE_PRODUCT_RATING, array(
339
+ 'rated' => $rating
340
+ ), array( 'id' => $vote_id ) );
341
+ } else {
342
+ $wpdb->insert( WPSC_TABLE_PRODUCT_RATING, array(
343
+ 'ipnum' => $ip_number,
344
+ 'productid' => $product_id,
345
+ 'rated' => $rating,
346
+ 'time' => $nowtime
347
+ ) );
348
+ $data = $wpdb->get_results( "SELECT `id`,`rated` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `ipnum`='" . $ip_number . "' AND `productid` = '" . $product_id . "' AND `rated` = '" . $rating . "' AND `time` = '" . $nowtime . "' ORDER BY `id` DESC LIMIT 1", ARRAY_A );
349
+ $vote_id = $data[0]['id'];
350
+ setcookie( "voting_cookie[$prodid]", ($vote_id . "," . $rating ), time() + (60 * 60 * 24 * 360) );
351
+ }
352
+ if ( $_POST['ajax'] == 'true' ) {
353
+
354
+ exit();
355
+ }
356
+ }
357
+
358
+ /**
359
+ * update_shipping_price function, used through ajax and in normal page loading.
360
+ * No parameters, returns nothing
361
+ */
362
+ function wpsc_update_shipping_price() {
363
+ global $wpsc_cart;
364
+ $quote_shipping_method = $_POST['method'];
365
+ $quote_shipping_option = $_POST['option'];
366
+
367
+ if(!empty($quote_shipping_option) && !empty($quote_shipping_method)){
368
+ $wpsc_cart->update_shipping( $quote_shipping_method, $quote_shipping_option );
369
+
370
+ echo "
371
+ if(jQuery('.pricedisplay.checkout-shipping .pricedisplay')){
372
+ jQuery('.pricedisplay.checkout-shipping > .pricedisplay:first').html(\"" . wpsc_cart_shipping() . "\");
373
+ jQuery('.shoppingcart .pricedisplay.checkout-shipping > .pricedisplay:first').html(\"" . wpsc_cart_shipping() . "\");
374
+ } else {
375
+ jQuery('.pricedisplay.checkout-shipping').html(\"" . wpsc_cart_shipping() . "\");}";
376
+ echo "
377
+ if (jQuery('#coupons_amount .pricedisplay').size() > 0) {
378
+ jQuery('#coupons_amount .pricedisplay').html(\"" . wpsc_coupon_amount() . "\");
379
+ } else {
380
+ jQuery('#coupons_amount').html(\"" . wpsc_coupon_amount() . "\");
381
+ }
382
+ ";
383
+ echo "jQuery('.pricedisplay.checkout-total').html(\"" . wpsc_cart_total() . "\");\n\r";
384
+ }
385
+ exit();
386
+ }
387
+
388
+ /**
389
+ * update_shipping_price function, used through ajax and in normal page loading.
390
+ * No parameters, returns nothing
391
+ */
392
+ function wpsc_get_rating_count() {
393
+ global $wpdb, $wpsc_cart;
394
+ $prodid = $_POST['product_id'];
395
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `productid` = %d", $prodid ) );
396
+ echo $count . "," . absint( $prodid );
397
+ exit();
398
+ }
399
+
400
+ /**
401
+ * update_product_page_price function, used through ajax with variations
402
+ * No parameters, returns nothing
403
+ */
404
+ function wpsc_update_product_price() {
405
+ if ( empty( $_POST['product_id'] ) || ! is_numeric( $_POST['product_id'] ) )
406
+ return;
407
+
408
+ $from = '';
409
+ $change_price = true;
410
+ $product_id = (int) $_POST['product_id'];
411
+ $variations = array();
412
+ $response = array(
413
+ 'product_id' => $product_id,
414
+ 'variation_found' => false,
415
+ );
416
+ if ( ! empty( $_POST['variation'] ) ) {
417
+ foreach ( $_POST['variation'] as $variation ) {
418
+ if ( is_numeric( $variation ) ) {
419
+ $variations[] = (int)$variation;
420
+ }
421
+ }
422
+
423
+ do_action( 'wpsc_update_variation_product', $product_id, $variations );
424
+
425
+ $stock = wpsc_check_variation_stock_availability( $product_id, $variations );
426
+
427
+ if ( $stock !== false ) {
428
+ $response['variation_found'] = true;
429
+ if ( $stock === 0 ) {
430
+ $response += array(
431
+ 'product_msg' => __( 'Sorry, but this variation is out of stock.', 'wpsc' ),
432
+ 'variation_msg' => __( 'Variation not in stock', 'wpsc' ),
433
+ 'stock_available' => false,
434
+ );
435
+ } else {
436
+ $response += array(
437
+ 'variation_msg' => __( 'Product in stock', 'wpsc' ),
438
+ 'stock_available' => true,
439
+ );
440
+ }
441
+
442
+ if ( $change_price ) {
443
+ $old_price = wpsc_calculate_price( $product_id, $variations, false );
444
+ $you_save_amount = wpsc_you_save( array( 'product_id' => $product_id, 'type' => 'amount', 'variations' => $variations ) );
445
+ $you_save_percentage = wpsc_you_save( array( 'product_id' => $product_id, 'variations' => $variations ) );
446
+ $price = wpsc_calculate_price( $product_id, $variations, true );
447
+ $response += array(
448
+ 'old_price' => wpsc_currency_display( $old_price, array( 'display_as_html' => false ) ),
449
+ 'numeric_old_price' => (float) $old_price,
450
+ 'you_save' => wpsc_currency_display( $you_save_amount, array( 'display_as_html' => false ) ) . "! (" . $you_save_percentage . "%)",
451
+ 'price' => $from . wpsc_currency_display( $price, array( 'display_as_html' => false ) ),
452
+ 'numeric_price' => (float) $price,
453
+ );
454
+ }
455
+ }
456
+ }
457
+
458
+ echo json_encode( $response );
459
+ exit();
460
+ }
461
+
462
+ /**
463
+ * update location function, used through ajax and in normal page loading.
464
+ * No parameters, returns nothing
465
+ */
466
+ function wpsc_update_location() {
467
+ global $wpdb, $wpsc_cart;
468
+
469
+ $delivery_country = '';
470
+ $billing_country = '';
471
+ if ( ! empty( $_POST['country'] ) ) {
472
+ $delivery_country = $_POST['country'];
473
+ $billing_country = wpsc_get_customer_meta( 'billing_country' );
474
+ $delivery_region = wpsc_get_customer_meta( 'shipping_region' );
475
+ $billing_region = wpsc_get_customer_meta( 'billing_region' );
476
+ $shipping_zipcode = wpsc_get_customer_meta( 'shipping_zipcode' );
477
+
478
+ if ( ! $billing_country )
479
+ wpsc_update_customer_meta( 'billing_country', $_POST['country'] );
480
+
481
+ if ( ! empty( $_POST['region'] ) ) {
482
+ $delivery_region = $_POST['region'];
483
+ if ( ! $billing_region )
484
+ $billing_region = $_POST['region'];
485
+ } else if ( ! $billing_region ) {
486
+ $billing_region = $delivery_region = get_option( 'base_region' );
487
+ }
488
+
489
+ if ( ! $delivery_region )
490
+ $delivery_region = $billing_region;
491
+ }
492
+
493
+ if ( ! empty( $_POST['zipcode'] ) )
494
+ $shipping_zipcode = $_POST['zipcode'];
495
+
496
+ $delivery_region_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('%s')", $delivery_country ) );
497
+ if ( $delivery_region_count < 1 )
498
+ $delivery_region = '';
499
+
500
+ $selected_region_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('%s')", $billing_country ) );
501
+ if ( $selected_region_count < 1 )
502
+ $billing_region = '';
503
+
504
+ wpsc_update_customer_meta( 'shipping_country' , $delivery_country );
505
+ wpsc_update_customer_meta( 'shipping_region' , $delivery_region );
506
+ wpsc_update_customer_meta( 'billing_country' , $billing_country );
507
+ wpsc_update_customer_meta( 'billing_region' , $billing_region );
508
+ wpsc_update_customer_meta( 'shipping_zip' , $shipping_zipcode );
509
+
510
+ $wpsc_cart->update_location();
511
+ $wpsc_cart->get_shipping_method();
512
+ $wpsc_cart->get_shipping_option();
513
+ if ( $wpsc_cart->selected_shipping_method != '' ) {
514
+ $wpsc_cart->update_shipping( $wpsc_cart->selected_shipping_method, $wpsc_cart->selected_shipping_option );
515
+ }
516
+
517
+ if ( wpsc_get_customer_meta( 'shipping_same_as_billing' ) && ( $delivery_country != $billing_country || $delivery_region != $billing_region ) )
518
+ wpsc_update_customer_meta( 'shipping_same_as_billing', false );
519
+
520
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && 'update_location' == $_REQUEST['action'] )
521
+ exit;
522
+ }
523
+
524
+ function wpsc_cart_html_page() {
525
+ require_once(WPSC_FILE_PATH . "/wpsc-includes/shopping_cart_container.php");
526
+ exit();
527
+ }
528
+
529
+ /**
530
+ * Populate Also Bought List
531
+ * Runs on checking out and populates the also bought list.
532
+ */
533
+ function wpsc_populate_also_bought_list() {
534
+ global $wpdb, $wpsc_cart, $wpsc_coupons;
535
+
536
+ $new_also_bought_data = array();
537
+ foreach ( $wpsc_cart->cart_items as $outer_cart_item ) {
538
+ $new_also_bought_data[$outer_cart_item->product_id] = array();
539
+ foreach ( $wpsc_cart->cart_items as $inner_cart_item ) {
540
+ if ( $outer_cart_item->product_id != $inner_cart_item->product_id ) {
541
+ $new_also_bought_data[$outer_cart_item->product_id][$inner_cart_item->product_id] = $inner_cart_item->quantity;
542
+ } else {
543
+ continue;
544
+ }
545
+ }
546
+ }
547
+
548
+ $insert_statement_parts = array();
549
+ foreach ( $new_also_bought_data as $new_also_bought_id => $new_also_bought_row ) {
550
+ $new_other_ids = array_keys( $new_also_bought_row );
551
+ $also_bought_data = $wpdb->get_results( $wpdb->prepare( "SELECT `id`, `associated_product`, `quantity` FROM `" . WPSC_TABLE_ALSO_BOUGHT . "` WHERE `selected_product` IN(%d) AND `associated_product` IN('" . implode( "','", $new_other_ids ) . "')", $new_also_bought_id ), ARRAY_A );
552
+ $altered_new_also_bought_row = $new_also_bought_row;
553
+
554
+ foreach ( (array)$also_bought_data as $also_bought_row ) {
555
+ $quantity = $new_also_bought_row[$also_bought_row['associated_product']] + $also_bought_row['quantity'];
556
+
557
+ unset( $altered_new_also_bought_row[$also_bought_row['associated_product']] );
558
+ $wpdb->update(
559
+ WPSC_TABLE_ALSO_BOUGHT,
560
+ array(
561
+ 'quantity' => $quantity
562
+ ),
563
+ array(
564
+ 'id' => $also_bought_row['id']
565
+ ),
566
+ '%d',
567
+ '%d'
568
+ );
569
+ }
570
+
571
+ if ( count( $altered_new_also_bought_row ) > 0 ) {
572
+ foreach ( $altered_new_also_bought_row as $associated_product => $quantity ) {
573
+ $insert_statement_parts[] = "(" . absint( esc_sql( $new_also_bought_id ) ) . "," . absint( esc_sql( $associated_product ) ) . "," . absint( esc_sql( $quantity ) ) . ")";
574
+ }
575
+ }
576
+ }
577
+
578
+ if ( count( $insert_statement_parts ) > 0 ) {
579
+ $insert_statement = "INSERT INTO `" . WPSC_TABLE_ALSO_BOUGHT . "` (`selected_product`, `associated_product`, `quantity`) VALUES " . implode( ",\n ", $insert_statement_parts );
580
+ $wpdb->query( $insert_statement );
581
+ }
582
+ }
583
+
584
+ /**
585
+ * submit checkout function, used through ajax and in normal page loading.
586
+ * No parameters, returns nothing
587
+ */
588
+ function wpsc_submit_checkout( $collected_data = true ) {
589
+ global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways;
590
+
591
+ $num_items = 0;
592
+ $use_shipping = 0;
593
+ $disregard_shipping = 0;
594
+
595
+ do_action( 'wpsc_before_submit_checkout' );
596
+
597
+ $error_messages = wpsc_get_customer_meta( 'checkout_misc_error_messages' );
598
+ if ( ! is_array( $error_messages ) )
599
+ $error_messages = array();
600
+ $wpsc_checkout = new wpsc_checkout();
601
+ $selected_gateways = get_option( 'custom_gateway_options' );
602
+ $submitted_gateway = isset( $_POST['custom_gateway'] ) ? $_POST['custom_gateway'] : '';
603
+ $options = get_option( 'custom_shipping_options' );
604
+ if ( $collected_data ) {
605
+ $form_validity = $wpsc_checkout->validate_forms();
606
+ extract( $form_validity ); // extracts $is_valid and $error_messages
607
+
608
+ if ( wpsc_has_tnc() && ( ! isset( $_POST['agree'] ) || $_POST['agree'] != 'yes' ) ) {
609
+ $error_messages[] = __( 'Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc' );
610
+ $is_valid = false;
611
+ }
612
+ } else {
613
+ $is_valid = true;
614
+ $error_messages = array();
615
+ }
616
+
617
+ $selectedCountry = $wpdb->get_results( $wpdb->prepare( "SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode = '%s' ", wpsc_get_customer_meta( 'shipping_country' ) ), ARRAY_A );
618
+ foreach ( $wpsc_cart->cart_items as $cartitem ) {
619
+ if( ! empty( $cartitem->meta[0]['no_shipping'] ) ) continue;
620
+ $categoriesIDs = $cartitem->category_id_list;
621
+ foreach ( (array)$categoriesIDs as $catid ) {
622
+ if ( is_array( $catid ) )
623
+ $countries = wpsc_get_meta( $catid[0], 'target_market', 'wpsc_category' );
624
+ else
625
+ $countries = wpsc_get_meta( $catid, 'target_market', 'wpsc_category' );
626
+
627
+ if ( !empty($countries) && !in_array( $selectedCountry[0]['id'], (array)$countries ) ) {
628
+ $errormessage = sprintf( __( '%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc' ), $cartitem->get_title(), $selectedCountry[0]['country'] );
629
+ wpsc_update_customer_meta( 'category_shipping_conflict', $errormessage );
630
+ $is_valid = false;
631
+ }
632
+ }
633
+ //count number of items, and number of items using shipping
634
+ $num_items++;
635
+ if ( $cartitem->uses_shipping != 1 )
636
+ $disregard_shipping++;
637
+ else
638
+ $use_shipping++;
639
+
640
+ }
641
+ if ( array_search( $submitted_gateway, $selected_gateways ) !== false )
642
+ wpsc_update_customer_meta( 'selected_gateway', $submitted_gateway );
643
+ else
644
+ $is_valid = false;
645
+
646
+ if ( $collected_data ) {
647
+ if ( get_option( 'do_not_use_shipping' ) == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && ( $num_items != $disregard_shipping ) ) {
648
+ $error_messages[] = __( 'You must select a shipping method, otherwise we cannot process your order.', 'wpsc' );
649
+ $is_valid = false;
650
+ }
651
+ if ( (get_option( 'do_not_use_shipping' ) != 1) && (in_array( 'ups', (array)$options )) && ! wpsc_get_customer_meta( 'shipping_zip' ) && ( $num_items != $disregard_shipping ) ) {
652
+ wpsc_update_customer_meta( 'category_shipping_conflict', __( 'Please enter a Zipcode and click calculate to proceed', 'wpsc' ) );
653
+ $is_valid = false;
654
+ }
655
+ }
656
+
657
+ wpsc_update_customer_meta( 'checkout_misc_error_messages', $error_messages );
658
+
659
+ if ( $is_valid == true ) {
660
+ wpsc_delete_customer_meta( 'category_shipping_conflict' );
661
+ // check that the submitted gateway is in the list of selected ones
662
+ $sessionid = (mt_rand( 100, 999 ) . time());
663
+ wpsc_update_customer_meta( 'checkout_session_id', $sessionid );
664
+ $subtotal = $wpsc_cart->calculate_subtotal();
665
+ if ( $wpsc_cart->has_total_shipping_discount() == false )
666
+ $base_shipping = $wpsc_cart->calculate_base_shipping();
667
+ else
668
+ $base_shipping = 0;
669
+
670
+ $delivery_country = $wpsc_cart->delivery_country;
671
+ $delivery_region = $wpsc_cart->delivery_region;
672
+
673
+ if ( wpsc_uses_shipping ( ) ) {
674
+ $shipping_method = $wpsc_cart->selected_shipping_method;
675
+ $shipping_option = $wpsc_cart->selected_shipping_option;
676
+ } else {
677
+ $shipping_method = '';
678
+ $shipping_option = '';
679
+ }
680
+ if ( isset( $_POST['how_find_us'] ) )
681
+ $find_us = $_POST['how_find_us'];
682
+ else
683
+ $find_us = '';
684
+
685
+ //keep track of tax if taxes are exclusive
686
+ $wpec_taxes_controller = new wpec_taxes_controller();
687
+ if ( !$wpec_taxes_controller->wpec_taxes_isincluded() ) {
688
+ $tax = $wpsc_cart->calculate_total_tax();
689
+ $tax_percentage = $wpsc_cart->tax_percentage;
690
+ } else {
691
+ $tax = 0.00;
692
+ $tax_percentage = 0.00;
693
+ }
694
+ $total = $wpsc_cart->calculate_total_price();
695
+ $args = array(
696
+ 'totalprice' => $total,
697
+ 'statusno' => '0',
698
+ 'sessionid' => $sessionid,
699
+ 'user_ID' => (int) $user_ID,
700
+ 'date' => time(),
701
+ 'gateway' => $submitted_gateway,
702
+ 'billing_country' => $wpsc_cart->selected_country,
703
+ 'shipping_country' => $delivery_country,
704
+ 'billing_region' => $wpsc_cart->selected_region,
705
+ 'shipping_region' => $delivery_region,
706
+ 'base_shipping' => $base_shipping,
707
+ 'shipping_method' => $shipping_method,
708
+ 'shipping_option' => $shipping_option,
709
+ 'plugin_version' => WPSC_VERSION,
710
+ 'discount_value' => $wpsc_cart->coupons_amount,
711
+ 'discount_data' => $wpsc_cart->coupons_name,
712
+ 'find_us' => $find_us,
713
+ 'wpec_taxes_total' => $tax,
714
+ 'wpec_taxes_rate' => $tax_percentage,
715
+ );
716
+ $purchase_log = new WPSC_Purchase_Log( $args );
717
+ $purchase_log->save();
718
+ $purchase_log_id = $purchase_log->get( 'id' );
719
+ if ( $collected_data )
720
+ $wpsc_checkout->save_forms_to_db( $purchase_log_id );
721
+ $wpsc_cart->save_to_db( $purchase_log_id );
722
+ $wpsc_cart->submit_stock_claims( $purchase_log_id );
723
+ if( !isset( $our_user_id ) && isset( $user_ID ))
724
+ $our_user_id = $user_ID;
725
+ $wpsc_cart->log_id = $purchase_log_id;
726
+ do_action( 'wpsc_submit_checkout', array( "purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id ) );
727
+ do_action( 'wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log );
728
+ }
729
+ }
730
+
731
+ /**
732
+ * wpsc_change_tax function, used through ajax and in normal page loading.
733
+ * No parameters, returns nothing
734
+ */
735
+ function wpsc_change_tax() {
736
+ global $wpdb, $wpsc_cart;
737
+
738
+ $form_id = absint( $_POST['form_id'] );
739
+
740
+ $wpsc_selected_country = $wpsc_cart->selected_country;
741
+ $wpsc_selected_region = $wpsc_cart->selected_region;
742
+
743
+ $wpsc_delivery_country = $wpsc_cart->delivery_country;
744
+ $wpsc_delivery_region = $wpsc_cart->delivery_region;
745
+
746
+
747
+ $previous_country = wpsc_get_customer_meta( 'billing_country' );
748
+ if ( isset( $_POST['billing_country'] ) ) {
749
+ $wpsc_selected_country = $_POST['billing_country'];
750
+ wpsc_update_customer_meta( 'billing_country', $wpsc_selected_country );
751
+ }
752
+
753
+ if ( isset( $_POST['billing_region'] ) ) {
754
+ $wpsc_selected_region = absint( $_POST['billing_region'] );
755
+ wpsc_update_customer_meta( 'billing_region', $wpsc_selected_region );
756
+ }
757
+
758
+ $check_country_code = $wpdb->get_var( $wpdb->prepare( "SELECT `country`.`isocode` FROM `" . WPSC_TABLE_REGION_TAX . "` AS `region` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `region`.`country_id` = `country`.`id` WHERE `region`.`id` = %d LIMIT 1", wpsc_get_customer_meta( 'billing_region' ) ) );
759
+
760
+ if ( wpsc_get_customer_meta( 'billing_country' ) != $check_country_code ) {
761
+ $wpsc_selected_region = null;
762
+ }
763
+
764
+ if ( isset( $_POST['shipping_country'] ) ) {
765
+ $wpsc_delivery_country = $_POST['shipping_country'];
766
+ wpsc_update_customer_meta( 'shipping_country', $wpsc_delivery_country );
767
+ }
768
+ if ( isset( $_POST['shipping_region'] ) ) {
769
+ $wpsc_delivery_region = absint( $_POST['shipping_region'] );
770
+ wpsc_update_customer_meta( 'shipping_region', $wpsc_delivery_region );
771
+ }
772
+
773
+ $check_country_code = $wpdb->get_var( $wpdb->prepare( "SELECT `country`.`isocode` FROM `" . WPSC_TABLE_REGION_TAX . "` AS `region` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `region`.`country_id` = `country`.`id` WHERE `region`.`id` = %d LIMIT 1", $wpsc_delivery_region ) );
774
+
775
+ if ( $wpsc_delivery_country != $check_country_code ) {
776
+ $wpsc_delivery_region = null;
777
+ }
778
+
779
+
780
+ $wpsc_cart->update_location();
781
+ $wpsc_cart->get_shipping_method();
782
+ $wpsc_cart->get_shipping_option();
783
+ if ( $wpsc_cart->selected_shipping_method != '' ) {
784
+ $wpsc_cart->update_shipping( $wpsc_cart->selected_shipping_method, $wpsc_cart->selected_shipping_option );
785
+ }
786
+
787
+ $tax = $wpsc_cart->calculate_total_tax();
788
+ $total = wpsc_cart_total();
789
+ $total_input = wpsc_cart_total(false);
790
+ if($wpsc_cart->coupons_amount >= wpsc_cart_total(false) && !empty($wpsc_cart->coupons_amount)){
791
+ $total = 0;
792
+ }
793
+ if ( $wpsc_cart->total_price < 0 ) {
794
+ $wpsc_cart->coupons_amount += $wpsc_cart->total_price;
795
+ $wpsc_cart->total_price = null;
796
+ $wpsc_cart->calculate_total_price();
797
+ }
798
+ ob_start();
799
+
800
+ include_once( wpsc_get_template_file_path( 'wpsc-cart_widget.php' ) );
801
+ $output = ob_get_contents();
802
+
803
+ ob_end_clean();
804
+ $delivery_country = wpsc_get_customer_meta( 'shipping_country' );
805
+ $output = str_replace( Array( "\n", "\r" ), Array( "\\n", "\\r" ), addslashes( $output ) );
806
+ if ( get_option( 'lock_tax' ) == 1 ) {
807
+ echo "jQuery('#current_country').val('" . esc_js( $delivery_country ) . "'); \n";
808
+ if ( $delivery_country == 'US' && get_option( 'lock_tax' ) == 1 ) {
809
+ $output = wpsc_shipping_region_list( $delivery_country, wpsc_get_customer_meta( 'shipping_region' ) );
810
+ $output = str_replace( Array( "\n", "\r" ), Array( "\\n", "\\r" ), addslashes( $output ) );
811
+ echo "jQuery('#region').remove();\n\r";
812
+ echo "jQuery('#change_country').append(\"" . $output . "\");\n\r";
813
+ }
814
+ }
815
+
816
+
817
+ foreach ( $wpsc_cart->cart_items as $key => $cart_item ) {
818
+ echo "jQuery('#shipping_$key').html(\"" . wpsc_currency_display( $cart_item->shipping ) . "\");\n\r";
819
+ }
820
+
821
+ echo "jQuery('#checkout_shipping').html(\"" . wpsc_cart_shipping() . "\");\n\r";
822
+
823
+ echo "jQuery('div.shopping-cart-wrapper').html('$output');\n";
824
+ if ( get_option( 'lock_tax' ) == 1 ) {
825
+ echo "jQuery('.shipping_country').val('" . esc_js( $delivery_country ) . "') \n";
826
+ $sql = $wpdb->prepare( "SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`= '%s'", $delivery_country );
827
+ $country_name = $wpdb->get_var( $sql );
828
+ echo "jQuery('.shipping_country_name').html('" . $country_name . "') \n";
829
+ }
830
+
831
+
832
+ $form_selected_country = null;
833
+ $form_selected_region = null;
834
+ $onchange_function = null;
835
+
836
+ if ( ! empty( $_POST['billing_country'] ) && $_POST['billing_country'] != 'undefined' && !isset( $_POST['shipping_country'] ) ) {
837
+ $form_selected_country = $wpsc_selected_country;
838
+ $form_selected_region = $wpsc_selected_region;
839
+ $onchange_function = 'set_billing_country';
840
+ } else if ( ! empty( $_POST['shipping_country'] ) && $_POST['shipping_country'] != 'undefined' && !isset( $_POST['billing_country'] ) ) {
841
+ $form_selected_country = $wpsc_delivery_country;
842
+ $form_selected_region = $wpsc_delivery_region;
843
+ $onchange_function = 'set_shipping_country';
844
+ }
845
+
846
+ if ( ($form_selected_country != null) && ($onchange_function != null) ) {
847
+ $region_list = $wpdb->get_results( $wpdb->prepare( "SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN('%s') AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", $form_selected_country ), ARRAY_A );
848
+ if ( $region_list != null ) {
849
+ $title = (empty($_POST['billing_country']))?'shippingstate':'billingstate';
850
+ $output = "<select name='collected_data[" . $form_id . "][1]' class='current_region' onchange='$onchange_function(\"region_country_form_$form_id\", \"$form_id\");' title='" . $title . "'>\n\r";
851
+
852
+ foreach ( $region_list as $region ) {
853
+ if ( $form_selected_region == $region['id'] ) {
854
+ $selected = "selected='selected'";
855
+ } else {
856
+ $selected = "";
857
+ }
858
+ $output .= " <option value='" . $region['id'] . "' $selected>" . htmlspecialchars( $region['name'] ) . "</option>\n\r";
859
+ }
860
+ $output .= "</select>\n\r";
861
+
862
+ $output = str_replace( Array( "\n", "\r" ), Array( "\\n", "\\r" ), addslashes( $output ) );
863
+ echo "jQuery('#region_select_$form_id').html(\"" . $output . "\");\n\r";
864
+ echo "
865
+ var wpsc_checkout_table_selector = jQuery('#region_select_$form_id').parents('.wpsc_checkout_table').attr('class');
866
+ wpsc_checkout_table_selector = wpsc_checkout_table_selector.replace(' ','.');
867
+ wpsc_checkout_table_selector = '.'+wpsc_checkout_table_selector;
868
+ jQuery(wpsc_checkout_table_selector + ' input.billing_region').attr('disabled', 'disabled');
869
+ jQuery(wpsc_checkout_table_selector + ' input.shipping_region').attr('disabled', 'disabled');
870
+ jQuery(wpsc_checkout_table_selector + ' .billing_region').parent().parent().hide();
871
+ jQuery(wpsc_checkout_table_selector + ' .shipping_region').parent().parent().hide();
872
+ ";
873
+ } else {
874
+ if ( get_option( 'lock_tax' ) == 1 ) {
875
+ echo "jQuery('#region').hide();";
876
+ }
877
+ echo "jQuery('#region_select_$form_id').html('');\n\r";
878
+ echo "
879
+ var wpsc_checkout_table_selector = jQuery('#region_select_$form_id').parents('.wpsc_checkout_table').attr('class');
880
+ wpsc_checkout_table_selector = wpsc_checkout_table_selector.replace(' ','.');
881
+ wpsc_checkout_table_selector = '.'+wpsc_checkout_table_selector;
882
+ jQuery(wpsc_checkout_table_selector + ' input.billing_region').removeAttr('disabled');
883
+ jQuery(wpsc_checkout_table_selector + ' input.shipping_region').removeAttr('disabled');
884
+ jQuery(wpsc_checkout_table_selector + ' .billing_region').parent().parent().show();
885
+ jQuery(wpsc_checkout_table_selector + ' .shipping_region').parent().parent().show();
886
+ ";
887
+ }
888
+ }
889
+
890
+ if ( $tax > 0 ) {
891
+ echo "jQuery(\"tr.total_tax\").show();\n\r";
892
+ } else {
893
+ echo "jQuery(\"tr.total_tax\").hide();\n\r";
894
+ }
895
+ echo "jQuery('#checkout_tax').html(\"<span class='pricedisplay'>" . wpsc_cart_tax() . "</span>\");\n\r";
896
+ echo "jQuery('#checkout_total').html(\"{$total}<input id='shopping_cart_total_price' type='hidden' value='{$total_input}' />\");\n\r";
897
+ exit();
898
+ }
899
+
900
+ function _wpsc_change_profile_country() {
901
+ global $wpdb;
902
+
903
+ $country_field_id = absint( $_REQUEST['form_id'] );
904
+ $country = $_REQUEST['country'];
905
+
906
+ $sql = $wpdb->prepare( 'SELECT unique_name FROM `'.WPSC_TABLE_CHECKOUT_FORMS.'` WHERE `id`= %d', $country_field_id );
907
+ $country_field_unique_name = $wpdb->get_var( $sql );
908
+
909
+ $has_regions = wpsc_has_regions( $country );
910
+ $response = array( 'has_regions' => $has_regions );
911
+
912
+ $region_unique_name = 'shippingstate';
913
+ if ( $country_field_unique_name == 'billingcountry' )
914
+ $region_unique_name = 'billingstate';
915
+
916
+ $sql = $wpdb->prepare( 'SELECT id FROM ' . WPSC_TABLE_CHECKOUT_FORMS . ' WHERE unique_name=%s AND active="1"', $region_unique_name );
917
+ $response['region_field_id'] = $wpdb->get_var( $sql );
918
+
919
+ if ( $has_regions )
920
+ $response['html'] = "<select name='collected_data[" . $country_field_id . "][1]'>" . nzshpcrt_region_list( $country, '' ) . "</select>";
921
+
922
+ echo json_encode( $response );
923
+ exit;
924
+ }
925
+
926
+ function wpsc_shipping_same_as_billing(){
927
+ wpsc_update_customer_meta( 'shipping_same_as_billing', $_POST['wpsc_shipping_same_as_billing'] );
928
+ }
929
+
930
+ function wpsc_update_shipping_quotes_on_shipping_same_as_billing() {
931
+ global $wpsc_cart;
932
+
933
+ wpsc_update_location();
934
+
935
+ if ( get_option( 'do_not_use_shipping' ) )
936
+ die( '-1' );
937
+
938
+ if ( ! wpsc_have_shipping_quote() ) {
939
+ die( '0' );
940
+ }
941
+ else {
942
+ ?>
943
+ <tr class="wpsc_shipping_info">
944
+ <td colspan="5">
945
+ <?php _e( 'Please choose a country below to calculate your shipping costs', 'wpsc' ); ?>
946
+ </td>
947
+ </tr>
948
+
949
+ <?php if ( ! wpsc_have_shipping_quote() ) : // No valid shipping quotes ?>
950
+ <?php if ( ! wpsc_have_valid_shipping_zipcode() ) : ?>
951
+ <tr class='wpsc_update_location'>
952
+ <td colspan='5' class='shipping_error' >
953
+ <?php _e('Please provide a Zipcode and click Calculate in order to continue.', 'wpsc'); ?>
954
+ </td>
955
+ </tr>
956
+ <?php else: ?>
957
+ <tr class='wpsc_update_location_error'>
958
+ <td colspan='5' class='shipping_error' >
959
+ <?php _e('Sorry, online ordering is unavailable to this destination and/or weight. Please double check your destination details.', 'wpsc'); ?>
960
+ </td>
961
+ </tr>
962
+ <?php endif; ?>
963
+ <?php endif; ?>
964
+ <tr class='wpsc_change_country'>
965
+ <td colspan='5'>
966
+ <form name='change_country' id='change_country' action='' method='post'>
967
+ <?php echo wpsc_shipping_country_list();?>
968
+ <input type='hidden' name='wpsc_update_location' value='true' />
969
+ <input type='submit' name='wpsc_submit_zipcode' value='Calculate' />
970
+ </form>
971
+ </td>
972
+ </tr>
973
+
974
+ <?php if (wpsc_have_morethanone_shipping_quote()) :?>
975
+ <?php while (wpsc_have_shipping_methods()) : wpsc_the_shipping_method(); ?>
976
+ <?php if (!wpsc_have_shipping_quotes()) { continue; } // Don't display shipping method if it doesn't have at least one quote ?>
977
+ <tr class='wpsc_shipping_header'><td class='shipping_header' colspan='5'><?php echo wpsc_shipping_method_name().__(' - Choose a Shipping Rate', 'wpsc'); ?> </td></tr>
978
+ <?php while (wpsc_have_shipping_quotes()) : wpsc_the_shipping_quote(); ?>
979
+ <tr class='<?php echo wpsc_shipping_quote_html_id(); ?>'>
980
+ <td class='wpsc_shipping_quote_name wpsc_shipping_quote_name_<?php echo wpsc_shipping_quote_html_id(); ?>' colspan='3'>
981
+ <label for='<?php echo wpsc_shipping_quote_html_id(); ?>'><?php echo wpsc_shipping_quote_name(); ?></label>
982
+ </td>
983
+ <td class='wpsc_shipping_quote_price wpsc_shipping_quote_price_<?php echo wpsc_shipping_quote_html_id(); ?>' style='text-align:center;'>
984
+ <label for='<?php echo wpsc_shipping_quote_html_id(); ?>'><?php echo wpsc_shipping_quote_value(); ?></label>
985
+ </td>
986
+ <td class='wpsc_shipping_quote_radio wpsc_shipping_quote_radio_<?php echo wpsc_shipping_quote_html_id(); ?>' style='text-align:center;'>
987
+ <?php if(wpsc_have_morethanone_shipping_methods_and_quotes()): ?>
988
+ <input type='radio' id='<?php echo wpsc_shipping_quote_html_id(); ?>' <?php echo wpsc_shipping_quote_selected_state(); ?> onclick='switchmethod("<?php echo wpsc_shipping_quote_name(); ?>", "<?php echo wpsc_shipping_method_internal_name(); ?>")' value='<?php echo wpsc_shipping_quote_value(true); ?>' name='shipping_method' />
989
+ <?php else: ?>
990
+ <input <?php echo wpsc_shipping_quote_selected_state(); ?> disabled='disabled' type='radio' id='<?php echo wpsc_shipping_quote_html_id(); ?>' value='<?php echo wpsc_shipping_quote_value(true); ?>' name='shipping_method' />
991
+ <?php wpsc_update_shipping_single_method(); ?>
992
+ <?php endif; ?>
993
+ </td>
994
+ </tr>
995
+ <?php endwhile; ?>
996
+ <?php endwhile; ?>
997
+ <?php endif; ?>
998
+
999
+ <?php wpsc_update_shipping_multiple_methods(); ?>
1000
+
1001
+ <?php
1002
+
1003
+ }
1004
+ exit;
1005
+
1006
+ }
1007
+
1008
+ function _wpsc_get_alternate_html( $cart_messages ) {
1009
+ // These shenanigans are necessary for two reasons.
1010
+ // 1) Some hook into POST, some GET, some REQUEST. They check for the conditional params below.
1011
+ // 2) Most functions properly die() - that means that our output buffer stops there and won't continue on for our purposes.
1012
+ // If there is a better way to get that output without dying, I'm all ears. A nice slow HTTP request for now.
1013
+
1014
+ $cookies = array();
1015
+ foreach ( $_COOKIE as $name => $value ) {
1016
+ if ( 'PHPSESSID' == $name )
1017
+ continue;
1018
+
1019
+ $cookies[] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) );
1020
+ }
1021
+
1022
+ wpsc_serialize_shopping_cart();
1023
+
1024
+ $javascript = wp_remote_retrieve_body(
1025
+ wp_remote_post(
1026
+ add_query_arg( array( 'wpsc_action' => 'wpsc_get_alternate_html', 'ajax' => 'true', 'wpsc_ajax_action' => 'add_to_cart' ), home_url() ),
1027
+ array(
1028
+ 'body' =>
1029
+ array(
1030
+ 'cart_messages' => $cart_messages, 'ajax' => 'true', 'wpsc_ajax_action' => 'add_to_cart', 'product_id' => empty( $_REQUEST['product_id'] ) ? '' : $_REQUEST['product_id'], '_wpsc_compat_ajax' => true
1031
+ ),
1032
+
1033
+ 'cookies' => $cookies,
1034
+ 'user-agent' => $_SERVER['HTTP_USER_AGENT']
1035
+ )
1036
+ )
1037
+ );
1038
+ return $javascript;
1039
+ }
1040
+
1041
+ /**
1042
+ * Returns the jQuery that is likely included in calls to this action. For back compat only, will be deprecated soon.
1043
+ * Couldn't think up a better way to return this output, which most often will end in die(), without die()ing early ourselves.
1044
+ *
1045
+ * @param array $cart_messages [description]
1046
+ */
1047
+ function _wpsc_ajax_return_alternate_html() {
1048
+ $cart_messages = empty( $_POST['cart_messages'] ) ? array() : (array) $_POST['cart_messages'];
1049
+ do_action( 'wpsc_alternate_cart_html', $cart_messages );
1050
+ die;
1051
+ }
1052
+
1053
+ if ( isset( $_REQUEST['wpsc_action'] ) && 'wpsc_get_alternate_html' == $_REQUEST['wpsc_action'] )
1054
+ add_action( 'init', '_wpsc_ajax_return_alternate_html' );
1055
+
1056
+ /**
1057
+ * Returns the Cart Widget
1058
+ *
1059
+ * @param boolean $die Whether or not to return the output (for new JSON requests) or to die() on the old $output / action.
1060
+ * @param array $cart_message An array of cart messages to be optionally passed. Primarily passed via wpsc_add_to_cart().
1061
+ *
1062
+ * @since 3.8.11
1063
+ * @return mixed Returns an array of output data, alternatively
1064
+ */
1065
+ function _wpsc_ajax_get_cart( $die = true, $cart_messages = array() ) {
1066
+ $return = array();
1067
+
1068
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
1069
+ ob_start();
1070
+ include_once( wpsc_get_template_file_path( 'wpsc-cart_widget.php' ) );
1071
+
1072
+ $output = ob_get_contents();
1073
+ ob_end_clean();
1074
+ $output = str_replace( array( '\n', '\r' ), '', $output );
1075
+
1076
+ $return['widget_output'] = $output;
1077
+ $return['core_images_url'] = WPSC_CORE_IMAGES_URL;
1078
+
1079
+ if ( 1 == get_option( 'show_sliding_cart' ) || empty( $cart_messages ) ) {
1080
+ if ( wpsc_cart_item_count() ) {
1081
+ $_SESSION['slider_state'] = 1;
1082
+ $return['sliding_cart_state'] = 'show';
1083
+ } else {
1084
+ $_SESSION['slider_state'] = 0;
1085
+ $return['sliding_cart_state'] = 'hide';
1086
+ }
1087
+ }
1088
+
1089
+ $action_output = '';
1090
+ if ( has_action( 'wpsc_alternate_cart_html' ) && empty( $_REQUEST['_wpsc_compat_ajax'] ) ) {
1091
+ //Deprecated action. Do not use. We now have a custom JS event called 'wpsc_fancy_notification'. There is access to the complete $json_response object.
1092
+ ob_start();
1093
+
1094
+ echo _wpsc_get_alternate_html( $cart_messages );
1095
+ $action_output = ob_get_contents();
1096
+ $output = '';
1097
+ ob_end_clean();
1098
+ }
1099
+
1100
+ if ( ! empty( $action_output ) ) {
1101
+ _wpsc_doing_it_wrong( 'wpsc_alternate_cart_html', __( 'As of WPeC 3.8.11, it is improper to hook into "wpsc_alternate_cart_html" to output javascript. We now have a custom javascript event called "wpsc_fancy_notification" you can hook into.', 'wpsc' ), '3.8.11' );
1102
+ $return['wpsc_alternate_cart_html'] = $action_output;
1103
+ }
1104
+ }
1105
+
1106
+ if ( $die ) {
1107
+ echo $output . $action_output;
1108
+ die();
1109
+ } else {
1110
+ return $return;
1111
+ }
1112
+ }
wpsc-components/theme-engine-v1/helpers/cart.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * have cart items function, no parameters
5
+ * @return boolean true if there are cart items left
6
+ */
7
+ function wpsc_have_cart_items() {
8
+ global $wpsc_cart;
9
+ return $wpsc_cart->have_cart_items();
10
+ }
11
+
12
+ function wpsc_the_cart_item() {
13
+ global $wpsc_cart;
14
+ return $wpsc_cart->the_cart_item();
15
+ }
16
+
17
+ /**
18
+ * cart item key function, no parameters
19
+ * @return integer - the cart item key from the array in the cart object
20
+ */
21
+ function wpsc_the_cart_item_key() {
22
+ global $wpsc_cart;
23
+ return $wpsc_cart->current_cart_item;
24
+ }
25
+
26
+ /**
27
+ * cart item name function, no parameters
28
+ * @return string the cart item name
29
+ */
30
+ function wpsc_cart_item_name( $context = 'display' ) {
31
+ global $wpsc_cart;
32
+ $product_name = apply_filters( 'wpsc_cart_item_name', $wpsc_cart->cart_item->get_title(), $wpsc_cart->cart_item->product_id );
33
+ return $product_name;
34
+ }
35
+ /**
36
+ * cart item quantity function, no parameters
37
+ * @return string the selected quantity of items
38
+ */
39
+ function wpsc_cart_item_product_id() {
40
+ global $wpsc_cart;
41
+ return $wpsc_cart->cart_item->product_id;
42
+ }
43
+ /**
44
+ * cart item quantity function, no parameters
45
+ * @return string the selected quantity of items
46
+ */
47
+ function wpsc_cart_item_quantity() {
48
+ global $wpsc_cart;
49
+ return $wpsc_cart->cart_item->quantity;
50
+ }
51
+
52
+ function wpsc_cart_item_quantity_single_prod($id) {
53
+ global $wpsc_cart;
54
+ return $wpsc_cart;
55
+ }
56
+
57
+ /**
58
+ * cart item price function, no parameters
59
+ * @return string the cart item price multiplied by the quantity, with a currency sign
60
+ */
61
+ function wpsc_cart_item_price($forDisplay = true) {
62
+ global $wpsc_cart;
63
+ if($forDisplay){
64
+ return wpsc_currency_display($wpsc_cart->cart_item->total_price);
65
+ }else{
66
+ return $wpsc_cart->cart_item->total_price;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * cart item individual single price function, no parameters
72
+ * @return string the cart individual single item price (1 quantity)
73
+ */
74
+ function wpsc_cart_single_item_price($forDisplay = true) {
75
+ global $wpsc_cart;
76
+ if($forDisplay){
77
+ return wpsc_currency_display(($wpsc_cart->cart_item->total_price) / ($wpsc_cart->cart_item->quantity));
78
+ }else{
79
+ return ($wpsc_cart->cart_item->total_price / $wpsc_cart->cart_item->quantity);
80
+ }
81
+ }
82
+
83
+ /**
84
+ * cart item shipping function, no parameters
85
+ * @return string the cart item price multiplied by the quantity, with a currency sign
86
+ */
87
+ function wpsc_cart_item_shipping($forDisplay = true) {
88
+ global $wpsc_cart;
89
+ if($forDisplay){
90
+ return wpsc_currency_display($wpsc_cart->cart_item->shipping);
91
+ }else{
92
+ return $wpsc_cart->cart_item->shipping;
93
+ }
94
+ }
95
+
96
+ /**
97
+ * cart item url function, no parameters
98
+ * @return string the cart item url
99
+ */
100
+ function wpsc_cart_item_url() {
101
+ global $wpsc_cart;
102
+ return apply_filters( 'wpsc_cart_item_url', $wpsc_cart->cart_item->product_url, $wpsc_cart->cart_item->product_id );
103
+ }
104
+
105
+ /**
106
+ * cart item image function
107
+ * returns the url to the to the cart item thumbnail image, if a width and height is specified, it resizes the thumbnail image to that size using the preview code (which caches the thumbnail also)
108
+ * @param integer width
109
+ * @param integer height
110
+ * @return string url to the to the cart item thumbnail image
111
+ */
112
+ function wpsc_cart_item_image( $width = 31, $height = 31 ) {
113
+ global $wpsc_cart;
114
+
115
+ $cart_image = wpsc_the_product_thumbnail( $width, $height, $wpsc_cart->cart_item->product_id, "shopping_cart");
116
+
117
+ if( is_ssl() )
118
+ $cart_image = str_replace( 'http://', 'https://', $cart_image );
119
+
120
+ return apply_filters( 'wpsc_cart_item_image', $cart_image, $wpsc_cart->cart_item->product_id );
121
+ }
122
+
wpsc-components/theme-engine-v1/helpers/checkout.php ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * returns true or false depending on whether there are checkout items or not
5
+ * @access public
6
+ *
7
+ * @since 3.7
8
+ * @return (boolean)
9
+ */
10
+ function wpsc_have_checkout_items() {
11
+ global $wpsc_checkout;
12
+ return $wpsc_checkout->have_checkout_items();
13
+ }
14
+
15
+ /**
16
+ * The checkout item sets the checkout item to the next one in the loop
17
+ * @access public
18
+ *
19
+ * @since 3.7
20
+ * @return the checkout item array
21
+ */
22
+ function wpsc_the_checkout_item() {
23
+ global $wpsc_checkout;
24
+ return $wpsc_checkout->the_checkout_item();
25
+ }
26
+
27
+ /**
28
+ * Checks shipping details
29
+ * @access public
30
+ *
31
+ * @since 3.7
32
+ * @return (boolean)
33
+ */
34
+ function wpsc_is_shipping_details() {
35
+ global $wpsc_checkout;
36
+ if ( $wpsc_checkout->checkout_item->unique_name == 'delivertoafriend' && get_option( 'shippingsameasbilling' ) == '1' ) {
37
+ return true;
38
+ } else {
39
+ return false;
40
+ }
41
+ }
42
+
43
+ /**
44
+ * returns the class for shipping and billing forms
45
+ * @access public
46
+ *
47
+ * @since 3.8
48
+ * @param $additional_classes (string) additional classes to be
49
+ * @return
50
+ */
51
+ function wpsc_the_checkout_details_class($additional_classes = ''){
52
+ if(wpsc_is_shipping_details())
53
+ echo "class='wpsc_shipping_forms ".$additional_classes."'";
54
+ else
55
+ echo "class='wpsc_billing_forms ".$additional_classes."'";
56
+
57
+ }
58
+
59
+ /**
60
+ * Checks to see is user login form needs to be displayed
61
+ * @access public
62
+ *
63
+ * @since 3.8
64
+ * @return (boolean) true or false
65
+ */
66
+ function wpsc_show_user_login_form(){
67
+ if(!is_user_logged_in() && get_option('users_can_register') && get_option('require_register'))
68
+ return true;
69
+ else
70
+ return false;
71
+ }
72
+
73
+ /**
74
+ * checks to see whether the country and categories selected have conflicts
75
+ * i.e products of this category cannot be shipped to selected country
76
+ * @access public
77
+ *
78
+ * @since 3.8
79
+ * @return (boolean) true or false
80
+ */
81
+ function wpsc_has_category_and_country_conflict(){
82
+ $conflict = wpsc_get_customer_meta( 'category_shipping_conflict' );
83
+ return ( ! empty( $conflict ) );
84
+ }
85
+
86
+ /**
87
+ * Have valid shipping zipcode
88
+ * Logic was modified in 3.8.9 to check if the Calculate button was ever actually hit
89
+ * @see http://code.google.com/p/wp-e-commerce/issues/detail?id=1014
90
+ *
91
+ * @access public
92
+ *
93
+ * @since 3.8
94
+ * @return (boolean) true or false
95
+ */
96
+ function wpsc_have_valid_shipping_zipcode(){
97
+ $zip = wpsc_get_customer_meta( 'shipping_zip' );
98
+
99
+ if( ! $zip || ( __( 'Your Zipcode', 'wpsc' ) == $zip ) && ( wpsc_get_customer_meta( 'update_location' ) ) )
100
+ return false;
101
+ else
102
+ return true;
103
+
104
+ }
105
+
106
+ /**
107
+ * show find us checks whether the 'how you found us' drop down should be displayed
108
+ * @access public
109
+ *
110
+ * @since 3.8
111
+ * @return (boolean) true or false
112
+ */
113
+ function wpsc_show_find_us(){
114
+ if(get_option('display_find_us') == '1')
115
+ return true;
116
+ else
117
+ return false;
118
+ }
119
+
120
+ /**
121
+ * disregard state fields - checks to see whether selected country has regions or not,
122
+ * depending on the scenario will return wither a true or false
123
+ * @access public
124
+ *
125
+ * @since 3.8
126
+ * @return (boolean) true or false
127
+ */
128
+ function wpsc_disregard_shipping_state_fields(){
129
+ global $wpsc_checkout;
130
+ if ( ! wpsc_uses_shipping() ):
131
+ $delivery_country = wpsc_get_customer_meta( 'shipping_country' );
132
+ if ( 'shippingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions( $delivery_country ) )
133
+ return true;
134
+ else
135
+ return false;
136
+ elseif ( 'billingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions( wpsc_get_customer_meta( 'billing_country' ) ) ):
137
+ return true;
138
+ endif;
139
+ }
140
+
141
+ function wpsc_disregard_billing_state_fields(){
142
+ global $wpsc_checkout;
143
+ if ( 'billingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions( wpsc_get_customer_meta( 'billing_country' ) ) )
144
+ return true;
145
+ return false;
146
+ }
147
+
148
+
149
+ function wpsc_shipping_details() {
150
+ global $wpsc_checkout;
151
+ if ( stristr( $wpsc_checkout->checkout_item->unique_name, 'shipping' ) != false ) {
152
+
153
+ return ' wpsc_shipping_forms';
154
+ } else {
155
+ return "";
156
+ }
157
+ }
158
+
159
+ function wpsc_the_checkout_item_error_class( $as_attribute = true ) {
160
+ global $wpsc_checkout, $wpsc_checkout_error_messages;
161
+
162
+ $class_name = '';
163
+
164
+ if ( ! empty( $wpsc_checkout_error_messages ) && isset( $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] ) && $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] != '' ) {
165
+ $class_name = 'validation-error';
166
+ }
167
+ if ( ($as_attribute == true ) ) {
168
+ $output = "class='" . $class_name . wpsc_shipping_details() . "'";
169
+ } else {
170
+ $output = $class_name;
171
+ }
172
+ return $output;
173
+ }
174
+
175
+ function wpsc_the_checkout_item_error() {
176
+ global $wpsc_checkout, $wpsc_checkout_error_messages;
177
+ $output = false;
178
+ if ( ! empty( $wpsc_checkout_error_messages ) && isset( $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] ) && $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] != '' ) {
179
+ $output = $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id];
180
+ }
181
+
182
+ return $output;
183
+ }
184
+
185
+ function wpsc_the_checkout_CC_validation() {
186
+ global $wpsc_gateway_error_messages;
187
+
188
+ $output = '';
189
+ if ( ! empty( $wpsc_gateway_error_messages ) && ! empty( $wpsc_gateway_error_messages['card_number'] ) )
190
+ $output = $wpsc_gateway_error_messages['card_number'];
191
+
192
+ return $output;
193
+ }
194
+
195
+ function wpsc_the_checkout_CC_validation_class() {
196
+ global $wpsc_gateway_error_messages;
197
+ if ( empty( $wpsc_gateway_error_messages ) )
198
+ return '';
199
+
200
+ return empty( $wpsc_gateway_error_messages['card_number'] ) ? '' : 'class="validation-error"';
201
+ }
202
+
203
+ function wpsc_the_checkout_CCexpiry_validation_class() {
204
+ global $wpsc_gateway_error_messages;
205
+
206
+ if ( empty( $wpsc_gateway_error_messages ) )
207
+ return '';
208
+
209
+ return empty( $wpsc_gateway_error_messages['expdate'] ) ? '' : 'class="validation-error"';
210
+ }
211
+
212
+ function wpsc_the_checkout_CCexpiry_validation() {
213
+ global $wpsc_gateway_error_messages;
214
+
215
+ if ( empty( $wpsc_gateway_error_messages ) )
216
+ return '';
217
+
218
+ return empty( $wpsc_gateway_error_messages['expdate'] ) ? '' : $wpsc_gateway_error_messages['expdate'];
219
+ }
220
+
221
+ function wpsc_the_checkout_CCcvv_validation_class() {
222
+ global $wpsc_gateway_error_messages;
223
+
224
+ if ( empty( $wpsc_gateway_error_messages ) )
225
+ return '';
226
+
227
+ return empty( $wpsc_gateway_error_messages['card_code'] ) ? '' : 'class="validation-error"';
228
+ }
229
+
230
+ function wpsc_the_checkout_CCcvv_validation() {
231
+ global $wpsc_gateway_error_messages;
232
+
233
+ if ( empty( $wpsc_gateway_error_messages ) )
234
+ return '';
235
+
236
+ return empty( $wpsc_gateway_error_messages['card_code'] ) ? '' : $wpsc_gateway_error_messages['card_code'];
237
+ }
238
+
239
+ function wpsc_the_checkout_CCtype_validation_class() {
240
+ global $wpsc_gateway_error_messages;
241
+
242
+ if ( empty( $wpsc_gateway_error_messages ) )
243
+ return '';
244
+
245
+ return empty( $wpsc_gateway_error_messages['cctype'] ) ? '' : 'class="validation-error"';
246
+ }
247
+
248
+ function wpsc_the_checkout_CCtype_validation() {
249
+ global $wpsc_gateway_error_messages;
250
+
251
+ if ( empty( $wpsc_gateway_error_messages ) )
252
+ return '';
253
+
254
+ return empty( $wpsc_gateway_error_messages['cctype'] ) ? '' : $wpsc_gateway_error_messages['cctype'];
255
+ }
256
+
257
+ function wpsc_checkout_form_is_header() {
258
+ global $wpsc_checkout;
259
+ if ( $wpsc_checkout->checkout_item->type == 'heading' ) {
260
+ $output = true;
261
+ } else {
262
+ $output = false;
263
+ }
264
+ return $output;
265
+ }
266
+
267
+ function wpsc_checkout_form_name() {
268
+ global $wpsc_checkout;
269
+ return $wpsc_checkout->form_name();
270
+ }
271
+
272
+ function wpsc_checkout_form_element_id() {
273
+ global $wpsc_checkout;
274
+ return $wpsc_checkout->form_element_id();
275
+ }
276
+
277
+ function wpsc_checkout_form_field() {
278
+ global $wpsc_checkout;
279
+ return $wpsc_checkout->form_field();
280
+ }
281
+
282
+ function wpsc_shipping_region_list( $selected_country, $selected_region, $shippingdetails = false ) {
283
+ global $wpdb;
284
+ $output = '';
285
+ $region_data = $wpdb->get_results( $wpdb->prepare( "SELECT `regions`.* FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN(%s) ORDER BY name ASC", $selected_country ), ARRAY_A );
286
+ $js = '';
287
+ if ( !$shippingdetails ) {
288
+ $js = "onchange='submit_change_country();'";
289
+ }
290
+ if ( count( $region_data ) > 0 ) {
291
+ $output .= "<select name='region' id='region' " . $js . " >";
292
+ foreach ( $region_data as $region ) {
293
+ $selected = '';
294
+ if ( $selected_region == $region['id'] ) {
295
+ $selected = "selected='selected'";
296
+ }
297
+ $output .= "<option $selected value='{$region['id']}'>" . esc_attr( htmlspecialchars( $region['name'] ) ). "</option>";
298
+ }
299
+ $output .= "";
300
+
301
+ $output .= "</select>";
302
+ } else {
303
+ $output .= " ";
304
+ }
305
+ return $output;
306
+ }
307
+
308
+ function wpsc_shipping_country_list( $shippingdetails = false ) {
309
+ global $wpdb, $wpsc_shipping_modules, $wpsc_country_data;
310
+ $js = '';
311
+ $output = '';
312
+ if ( !$shippingdetails ) {
313
+ $output = "<input type='hidden' name='wpsc_ajax_actions' value='update_location' />";
314
+ $js = " onchange='submit_change_country();'";
315
+ }
316
+ $selected_country = (string) wpsc_get_customer_meta( 'shipping_country' );
317
+ $selected_region = (string) wpsc_get_customer_meta( 'shipping_region' );
318
+
319
+ if ( empty( $selected_country ) )
320
+ $selected_country = esc_attr( get_option( 'base_country' ) );
321
+
322
+ if ( empty( $selected_region ) )
323
+ $selected_region = esc_attr( get_option( 'base_region' ) );
324
+
325
+ if ( empty( $wpsc_country_data ) )
326
+ $country_data = $wpdb->get_results( "SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `visible`= '1' ORDER BY `country` ASC", ARRAY_A );
327
+ else
328
+ $country_data = $wpsc_country_data;
329
+
330
+ $acceptable_countries = wpsc_get_acceptable_countries();
331
+
332
+ $output .= wpsc_get_country_dropdown( array(
333
+ 'name' => 'country',
334
+ 'id' => 'current_country',
335
+ 'additional_attributes' => $js,
336
+ 'acceptable_ids' => $acceptable_countries,
337
+ 'selected' => $selected_country,
338
+ 'placeholder' => '',
339
+ ) );
340
+
341
+ $output .= wpsc_shipping_region_list( $selected_country, $selected_region, $shippingdetails );
342
+
343
+ if ( isset( $_POST['wpsc_update_location'] ) && $_POST['wpsc_update_location'] == 'true' ) {
344
+ wpsc_update_customer_meta( 'update_location', true );
345
+ } else {
346
+ wpsc_delete_customer_meta( 'update_location' );
347
+ }
348
+
349
+ $zipvalue = (string) wpsc_get_customer_meta( 'shipping_zip' );
350
+ if ( ! empty( $_POST['zipcode'] ) )
351
+ $zipvalue = $_POST['zipcode'];
352
+
353
+ $zip_code_text = __( 'Your Zipcode', 'wpsc' );
354
+
355
+ if ( ( $zipvalue != '' ) && ( $zipvalue != $zip_code_text ) ) {
356
+ $color = '#000';
357
+ wpsc_update_customer_meta( 'shipping_zip', $zipvalue );
358
+ } else {
359
+ $zipvalue = $zip_code_text;
360
+ $color = '#999';
361
+ }
362
+
363
+ $uses_zipcode = false;
364
+ $custom_shipping = get_option( 'custom_shipping_options' );
365
+ foreach ( (array)$custom_shipping as $shipping ) {
366
+ if ( isset( $wpsc_shipping_modules[$shipping]->needs_zipcode ) && $wpsc_shipping_modules[$shipping]->needs_zipcode == true ) {
367
+ $uses_zipcode = true;
368
+ }
369
+ }
370
+
371
+ if ( $uses_zipcode ) {
372
+ $output .= " <input type='text' style='color:" . $color . ";' onclick='if (this.value==\"" . esc_js( $zip_code_text ) . "\") {this.value=\"\";this.style.color=\"#000\";}' onblur='if (this.value==\"\") {this.style.color=\"#999\"; this.value=\"" . esc_js( $zip_code_text ) . "\"; }' value='" . esc_attr( $zipvalue ) . "' size='10' name='zipcode' id='zipcode'>";
373
+ }
374
+ return $output;
375
+ }
376
+
377
+ function wpsc_get_gateway_list() {
378
+ return apply_filters( 'wpsc_get_gateway_list', '' );
379
+ }
380
+
381
+ function wpsc_gateway_list() {
382
+ echo wpsc_get_gateway_list();
383
+ }
384
+
385
+ function wpsc_gateway_count() {
386
+ return apply_filters( 'wpsc_gateway_count', 0 );
387
+ }
388
+
389
+ function wpsc_get_gateway_hidden_field() {
390
+ $output = sprintf(
391
+ '<input name="custom_gateway" value="%s" type="hidden" />',
392
+ apply_filters( 'wpsc_gateway_hidden_field_value', '' )
393
+ );
394
+
395
+ return $output;
396
+ }
397
+
398
+ function wpsc_gateway_hidden_field() {
399
+ do_action( 'wpsc_before_gateway_hidden_field' );
400
+ echo wpsc_get_gateway_hidden_field();
401
+ do_action( 'wpsc_after_gateway_hidden_field' );
402
+ }
wpsc-components/theme-engine-v1/helpers/form.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function nzshpcrt_country_list( $selected_country = null ) {
4
+ return _wpsc_country_dropdown_options( array(
5
+ 'selected' => $selected_country,
6
+ ) );
7
+ }
8
+
9
+ function nzshpcrt_region_list( $selected_country = null, $selected_region = null ) {
10
+ global $wpdb;
11
+
12
+ if ( $selected_region == null )
13
+ $selected_region = get_option( 'base_region' );
14
+
15
+ $output = "";
16
+ $region_list = $wpdb->get_results( $wpdb->prepare( "SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN(%s) AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", $selected_country ), ARRAY_A );
17
+
18
+ if ( $region_list != null ) {
19
+ foreach ( $region_list as $region ) {
20
+ if ( $selected_region == $region['id'] ) {
21
+ $selected = "selected='selected'";
22
+ } else {
23
+ $selected = "";
24
+ }
25
+
26
+ $output .= "<option value='" . $region['id'] . "' $selected>" . $region['name'] . "</option>\r\n";
27
+ }
28
+ } else {
29
+ $output .= "<option value=''>" . esc_html__( 'None', 'wpsc' ) . "</option>\r\n";
30
+ }
31
+
32
+ return $output;
33
+ }
34
+
35
+ function nzshpcrt_form_field_list( $selected_field = null ) {
36
+ global $wpdb;
37
+ $output = "<option value=''>" . esc_html__( 'Please choose', 'wpsc' ) . "</option>";
38
+ $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1';";
39
+ $form_data = $wpdb->get_results( $form_sql, ARRAY_A );
40
+
41
+ foreach ( (array)$form_data as $form ) {
42
+ $selected = '';
43
+ if ( $selected_field == $form['id'] ) {
44
+ $selected = "selected='selected'";
45
+ }
46
+ $output .= "<option value='" . $form['id'] . "' $selected>" . $form['name'] . "</option>";
47
+ }
48
+
49
+ return $output;
50
+ }
51
+
52
+ function wpsc_parent_category_list( $taxonomies, $args, $parent, $current_term_id ) {
53
+ $myterms = get_terms( $taxonomies, $args );
54
+ $output = "<select name='category_parent'>";
55
+ $output .="<option value='0'>" . __( 'No Parent', 'wpsc' ) . "</option>";
56
+ $output .= wpsc_category_options(0, null, null, 0, $current_term_id );
57
+ $output .="</select>";
58
+
59
+ return $output;
60
+ }
61
+
62
+ /*
63
+ * Displays the category forms for adding and editing products
64
+ * Recurses to generate the branched view for subcategories
65
+ */
66
+ function wpsc_category_options( $group_id, $this_category = null, $category_id = null, $iteration = 0, $selected_id = null ) {
67
+ global $wpdb;
68
+ $selected_term = get_term($selected_id,'wpsc_product_category');
69
+ $values = get_terms( 'wpsc_product_category', 'hide_empty=0&parent=' . $group_id );
70
+ $selected = "";
71
+ $output = "";
72
+
73
+ foreach ( (array)$values as $option ) {
74
+ if ( $option->term_id != $this_category ) {
75
+ if ( isset($selected_term->parent) && $selected_term->parent == $option->term_id ) {
76
+ $selected = "selected='selected'";
77
+ }
78
+
79
+ $output .= "<option $selected value='" . $option->term_id . "'>" . str_repeat( "-", $iteration ) . esc_html( $option->name ) . "</option>\r\n";
80
+ $output .= wpsc_category_options( $option->term_id, $this_category, $option->term_id, $iteration + 1, $selected_id );
81
+ $selected = "";
82
+ }
83
+ }
84
+
85
+ return $output;
86
+ }
87
+
wpsc-components/theme-engine-v1/helpers/page.php ADDED
@@ -0,0 +1,1393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'wpsc_loaded', 'wpsc_core_load_page_titles' );
4
+ add_action( 'init', 'wpsc_register_core_theme_files' );
5
+ add_action( 'wpsc_move_theme', 'wpsc_flush_theme_transients', 10, true );
6
+ add_action( 'wpsc_switch_theme', 'wpsc_flush_theme_transients', 10, true );
7
+ add_action( 'switch_theme', 'wpsc_flush_theme_transients', 10, true );
8
+ add_action('admin_init','wpsc_theme_admin_notices');
9
+ add_action( 'update_option_product_image_width' , 'wpsc_cache_to_upload' );
10
+ add_action( 'update_option_product_image_height' , 'wpsc_cache_to_upload' );
11
+ add_action( 'update_option_single_view_image_width' , 'wpsc_cache_to_upload' );
12
+ add_action( 'update_option_single_view_image_height', 'wpsc_cache_to_upload' );
13
+ add_action( 'update_option_category_image_width' , 'wpsc_cache_to_upload' );
14
+ add_action( 'update_option_category_image_height' , 'wpsc_cache_to_upload' );
15
+ add_action('template_redirect', 'wpsc_all_products_on_page');
16
+ add_action('post_thumbnail_html','wpsc_the_featured_image_fix', 10, 2);
17
+ add_filter( 'aioseop_description', 'wpsc_set_aioseop_description' );
18
+ add_filter('request', 'wpsc_remove_page_from_query_string');
19
+
20
+ //Potentially unnecessary, as I believe this option is deprecated
21
+ add_action( 'update_option_show_categorybrands' , 'wpsc_cache_to_upload' );
22
+
23
+ if ( ! is_admin() )
24
+ add_action( 'init', 'wpsc_enqueue_user_script_and_css' );
25
+
26
+ if ( isset( $_REQUEST['wpsc_flush_theme_transients'] ) && ( $_REQUEST['wpsc_flush_theme_transients'] == 'true' ) )
27
+ add_action( 'admin_init', 'wpsc_force_flush_theme_transients' );
28
+
29
+ if ( isset( $_GET['wpsc_user_dynamic_css'] ) && 'true' == $_GET['wpsc_user_dynamic_css'] )
30
+ add_action( 'plugins_loaded', 'wpsc_user_dynamic_css', 1 );
31
+
32
+ if ( ! is_admin() )
33
+ add_filter('request','wpec_remap_shop_subpages');
34
+
35
+ if(get_option( 'wpsc_hide_featured_products' ) == 1)
36
+ add_action( 'wpsc_top_of_products_page', 'wpsc_display_featured_products_page', 12 );
37
+
38
+ $show_subcatsprods_in_cat = get_option( 'show_subcatsprods_in_cat' );
39
+ if(!$show_subcatsprods_in_cat)
40
+ add_action( 'init', 'wpsc_hidesubcatprods_init' );
41
+
42
+ /**
43
+ * wpsc_register_theme_file( $file_name )
44
+ *
45
+ * Adds a file name to a global list of
46
+ *
47
+ * @param string $file_name Name of file to add to global list of files
48
+ */
49
+ function wpsc_register_theme_file( $file_name ) {
50
+ global $wpec_theme_files;
51
+
52
+ if ( !in_array( $file_name, (array)$wpec_theme_files ) )
53
+ $wpec_theme_files[] = $file_name;
54
+ }
55
+
56
+ /**
57
+ * wpsc_register_core_theme_files()
58
+ *
59
+ * Registers the core WPEC files into the global array
60
+ */
61
+ function wpsc_register_core_theme_files() {
62
+ wpsc_register_theme_file( 'wpsc-single_product.php' );
63
+ wpsc_register_theme_file( 'wpsc-grid_view.php' );
64
+ wpsc_register_theme_file( 'wpsc-list_view.php' );
65
+ wpsc_register_theme_file( 'wpsc-products_page.php' );
66
+ wpsc_register_theme_file( 'wpsc-shopping_cart_page.php' );
67
+ wpsc_register_theme_file( 'wpsc-transaction_results.php' );
68
+ wpsc_register_theme_file( 'wpsc-user-log.php' );
69
+ wpsc_register_theme_file( 'wpsc-cart_widget.php' );
70
+ wpsc_register_theme_file( 'wpsc-featured_product.php' );
71
+ wpsc_register_theme_file( 'wpsc-category-list.php' );
72
+ wpsc_register_theme_file( 'wpsc-category_widget.php' );
73
+ // Let other plugins register their theme files
74
+ do_action( 'wpsc_register_core_theme_files' );
75
+ }
76
+
77
+ /**
78
+ * wpsc_get_theme_files()
79
+ *
80
+ * Returns the global wpec_theme_files
81
+ *
82
+ * @global array $wpec_theme_files
83
+ * @return array
84
+ */
85
+ function wpsc_get_theme_files() {
86
+ global $wpec_theme_files;
87
+ if ( empty( $wpec_theme_files ) )
88
+ return array();
89
+ else
90
+ return apply_filters( 'wpsc_get_theme_files', (array)array_values( $wpec_theme_files ) );
91
+ }
92
+
93
+ /**
94
+ * wpsc_flush_theme_transients()
95
+ *
96
+ * This function will delete the temporary values stored in WordPress transients
97
+ * for all of the additional WPEC theme files and their locations. This is
98
+ * mostly used when the active theme changes, or when files are moved around. It
99
+ * does a complete flush of all possible path/url combinations of files.
100
+ *
101
+ * @uses wpsc_get_theme_files
102
+ */
103
+ function wpsc_flush_theme_transients( $force = false ) {
104
+
105
+ if ( true === $force || isset( $_REQUEST['wpsc_flush_theme_transients'] ) && !empty( $_REQUEST['wpsc_flush_theme_transients'] ) ) {
106
+
107
+ // Loop through current theme files and remove transients
108
+ if ( $theme_files = wpsc_get_theme_files() ) {
109
+ foreach( $theme_files as $file ) {
110
+ delete_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file );
111
+ delete_transient( WPEC_TRANSIENT_THEME_URL_PREFIX . $file );
112
+ }
113
+
114
+ delete_transient( 'wpsc_theme_path' );
115
+
116
+ return true;
117
+ }
118
+ }
119
+
120
+ // No files were registered so return false
121
+ return false;
122
+ }
123
+
124
+ function wpsc_force_flush_theme_transients() {
125
+ // Flush transients
126
+ wpsc_flush_theme_transients( true );
127
+
128
+ // Bounce back
129
+ $sendback = wp_get_referer();
130
+ wp_redirect( $sendback );
131
+
132
+ exit();
133
+ }
134
+
135
+ /**
136
+ * wpsc_check_theme_location()
137
+ *
138
+ * Check theme location, compares the active theme and the themes within WPSC_CORE_THEME_PATH
139
+ * finds files of the same name.
140
+ *
141
+ * @access public
142
+ * @since 3.8
143
+ * @param null
144
+ * @return $results (Array) of Files OR false if no similar files are found
145
+ */
146
+ function wpsc_check_theme_location() {
147
+ // Get the current theme
148
+ $current_theme = get_stylesheet_directory();
149
+
150
+ // Load up the files in the current theme
151
+ $current_theme_files = wpsc_list_product_templates( $current_theme . '/' );
152
+
153
+ // Load up the files in the wpec themes folder
154
+ $wpsc_template_files = wpsc_list_product_templates( WPSC_CORE_THEME_PATH );
155
+
156
+ // Compare the two
157
+ $results = array_intersect( $current_theme_files, $wpsc_template_files );
158
+
159
+ // Return the differences
160
+ if ( count( $results ) > 0 )
161
+ return $results;
162
+
163
+ // No differences so return false
164
+ else
165
+ return false;
166
+ }
167
+
168
+ /**
169
+ * wpsc_list_product_templates( $path = '' )
170
+ *
171
+ * Lists the files within the WPSC_CORE_THEME_PATH directory
172
+ *
173
+ * @access public
174
+ * @since 3.8
175
+ * @param $path - you can provide a path to find the files within it
176
+ * @return $templates (Array) List of files
177
+ */
178
+ function wpsc_list_product_templates( $path = '' ) {
179
+
180
+ $selected_theme = get_option( 'wpsc_selected_theme' );
181
+
182
+ // If no path, then try to make some assuptions
183
+ if ( empty( $path ) ) {
184
+ if ( file_exists( WPSC_OLD_THEMES_PATH . $selected_theme . '/' . $selected_theme . '.css' ) ) {
185
+ $path = WPSC_OLD_THEMES_PATH . $selected_theme . '/';
186
+ } else {
187
+ $path = WPSC_CORE_THEME_PATH;
188
+ }
189
+ }
190
+
191
+ // Open the path and get the file names
192
+ $dh = opendir( $path );
193
+ while ( ( $file = readdir( $dh ) ) !== false ) {
194
+ if ( $file != "." && $file != ".." && !strstr( $file, ".svn" ) && !strstr( $file, "images" ) && is_file( $path . $file ) ) {
195
+ $templates[] = $file;
196
+ }
197
+ }
198
+
199
+ // Return template names
200
+ return $templates;
201
+ }
202
+
203
+ /**
204
+ * Displays the theme upgrade notice
205
+ * @access public
206
+ *
207
+ * @since 3.8
208
+ * @param null
209
+ * @return null
210
+ */
211
+ function wpsc_theme_upgrade_notice() { ?>
212
+
213
+ <div id="message" class="updated fade">
214
+ <p><?php printf( __( '<strong>WP e-Commerce is ready</strong>. If you plan on editing the look of your site, you should <a href="%1s">update your active theme</a> to include the additional WP e-Commerce files. <a href="%2s">Click here</a> to ignore and remove this box.', 'wpsc' ), admin_url( 'admin.php?page=wpsc-settings&tab=presentation' ), admin_url( 'admin.php?page=wpsc-settings&tab=presentation&wpsc_notices=theme_ignore' ) ) ?></p>
215
+ </div>
216
+
217
+ <?php
218
+ }
219
+
220
+ /**
221
+ * Displays the database update notice
222
+ * @access public
223
+ *
224
+ * @since 3.8
225
+ * @param null
226
+ * @return null
227
+ */
228
+ function wpsc_database_update_notice() { ?>
229
+
230
+ <div class="error fade">
231
+ <p><?php printf( __( '<strong>Your WP e-Commerce data needs to be updated</strong>. You\'ve upgraded from a previous version of the WP e-Commerce plugin, and your store needs updating.<br>You should <a href="%1s">update your database</a> for your store to continue working.', 'wpsc' ), admin_url( 'index.php?page=wpsc-update' ) ) ?></p>
232
+ </div>
233
+
234
+ <?php
235
+ }
236
+
237
+
238
+ function wpsc_theme_admin_notices() {
239
+ // Database update notice is most important
240
+ if ( get_option ( 'wpsc_version' ) < 3.8 ) {
241
+
242
+ add_action ( 'admin_notices', 'wpsc_database_update_notice' );
243
+
244
+ // If that's not an issue check if theme updates required
245
+ } else {
246
+
247
+ if ( get_option('wpsc_ignore_theme','') == '' ) {
248
+ add_option('wpsc_ignore_theme',false);
249
+ }
250
+ if (!get_option('wpsc_ignore_theme')) {
251
+ add_action( 'admin_notices', 'wpsc_theme_upgrade_notice' );
252
+ }
253
+
254
+ }
255
+
256
+ // Flag config inconsistencies
257
+ if ( 1 == get_option( 'require_register' ) && 1 != get_option( 'users_can_register' )) {
258
+ add_action( 'admin_notices', 'wpsc_turn_on_wp_register' );
259
+ }
260
+
261
+ }
262
+
263
+ function wpsc_turn_on_wp_register() {?>
264
+
265
+ <div id="message" class="updated fade">
266
+ <p><?php printf( __( '<strong>Store Settings</strong>: You have set \'users must register before checkout\', for this to work you need to check \'Anyone can register\' in your WordPress <a href="%1s">General Settings</a>.', 'wpsc' ), admin_url( 'options-general.php' ) ) ?></p>
267
+ </div>
268
+
269
+ <?php
270
+
271
+
272
+ }
273
+
274
+ /**
275
+ * wpsc_get_template_file_url( $file )
276
+ *
277
+ * Checks the active theme folder for the particular file, if it exists then
278
+ * return the active theme url, otherwise return the global wpsc_theme_url
279
+ *
280
+ * @access public
281
+ * @since 3.8
282
+ * @param $file string filename
283
+ * @return PATH to the file
284
+ */
285
+ function wpsc_get_template_file_url( $file = '' ) {
286
+ // If we're not looking for a file, do not proceed
287
+ if ( empty( $file ) )
288
+ return;
289
+
290
+ // Look for file in stylesheet
291
+ if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
292
+ $file_url = get_stylesheet_directory_uri() . '/' . $file;
293
+
294
+ // Look for file in template
295
+ } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
296
+ $file_url = get_template_directory_uri() . '/' . $file;
297
+
298
+ // Backwards compatibility
299
+ } else {
300
+ // Look in old theme url
301
+ $selected_theme_check = WPSC_OLD_THEMES_PATH . get_option( 'wpsc_selected_theme' ) . '/' . str_ireplace( 'wpsc-', '', $file );
302
+ // Check the selected theme
303
+ if ( file_exists( $selected_theme_check ) ) {
304
+
305
+ $file_url = WPSC_OLD_THEMES_URL . get_option( 'wpsc_selected_theme' ) . '/' . str_ireplace( 'wpsc-', '', $file );
306
+ // Use the bundled theme CSS
307
+ } else {
308
+ $file_url = WPSC_CORE_THEME_URL . $file;
309
+ }
310
+ }
311
+
312
+ if ( is_ssl() )
313
+ $file_url = str_replace('http://', 'https://', $file_url);
314
+
315
+ // Return filtered result
316
+ return apply_filters( WPEC_TRANSIENT_THEME_URL_PREFIX . $file, $file_url );
317
+ }
318
+
319
+ /**
320
+ * wpsc_user_enqueues products function,
321
+ * enqueue all javascript and CSS for wp ecommerce
322
+ */
323
+ function wpsc_enqueue_user_script_and_css() {
324
+ global $wp_styles, $wpsc_theme_url, $wp_query;
325
+ /**
326
+ * added by xiligroup.dev to be compatible with touchshop
327
+ */
328
+ if ( has_filter( 'wpsc_enqueue_user_script_and_css' ) && apply_filters( 'wpsc_mobile_scripts_css_filters', false ) ) {
329
+ do_action( 'wpsc_enqueue_user_script_and_css' );
330
+ } else {
331
+ /**
332
+ * end of added by xiligroup.dev to be compatible with touchshop
333
+ */
334
+ $scheme = is_ssl() ? 'https' : 'http';
335
+ $version_identifier = WPSC_VERSION . "." . WPSC_MINOR_VERSION;
336
+
337
+ $category_id = wpsc_get_current_category_id();
338
+
339
+ if( get_option( 'wpsc_share_this' ) == 1 ) {
340
+ $remote_protocol = is_ssl() ? 'https://ws' : 'http://w';
341
+ wp_enqueue_script( 'sharethis', $remote_protocol . '.sharethis.com/button/buttons.js', array(), false, true );
342
+ }
343
+
344
+ wp_enqueue_script( 'jQuery' );
345
+ wp_enqueue_script( 'wp-e-commerce', WPSC_CORE_JS_URL . '/wp-e-commerce.js', array( 'jquery' ), $version_identifier );
346
+ wp_enqueue_script( 'wp-e-commerce-dynamic', home_url( '/index.php?wpsc_user_dynamic_js=true', $scheme ), false, $version_identifier );
347
+
348
+ wp_localize_script( 'wp-e-commerce', 'wpsc_ajax', array(
349
+ 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
350
+ 'spinner' => esc_url( admin_url( 'images/wpspin_light.gif' ) ),
351
+ 'no_quotes' => __( 'It appears that there are no shipping quotes for the shipping information provided. Please check the information and try again.', 'wpsc' )
352
+ )
353
+ );
354
+
355
+ wp_enqueue_script( 'livequery', WPSC_URL . '/wpsc-admin/js/jquery.livequery.js', array( 'jquery' ), '1.0.3' );
356
+ if( get_option( 'product_ratings' ) == 1 )
357
+ wp_enqueue_script( 'jquery-rating', WPSC_CORE_JS_URL . '/jquery.rating.js', array( 'jquery' ), $version_identifier );
358
+ wp_enqueue_script( 'wp-e-commerce-legacy', WPSC_CORE_JS_URL . '/user.js', array( 'jquery' ), WPSC_VERSION . WPSC_MINOR_VERSION );
359
+ if ( get_option( 'show_thumbnails_thickbox' ) == 1 ){
360
+ $lightbox = get_option('wpsc_lightbox', 'thickbox');
361
+ if( $lightbox == 'thickbox' ) {
362
+ wp_enqueue_script( 'wpsc-thickbox', WPSC_CORE_JS_URL . '/thickbox.js', array( 'jquery' ), 'Instinct_e-commerce' );
363
+ wp_enqueue_style( 'wpsc-thickbox', WPSC_CORE_JS_URL . '/thickbox.css', false, $version_identifier, 'all' );
364
+ } elseif( $lightbox == 'colorbox' ) {
365
+ wp_enqueue_script( 'colorbox-min', WPSC_CORE_JS_URL . '/jquery.colorbox-min.js', array( 'jquery' ), 'Instinct_e-commerce' );
366
+ wp_enqueue_script( 'wpsc_colorbox', WPSC_CORE_JS_URL . '/wpsc_colorbox.js', array( 'jquery', 'colorbox-min' ), 'Instinct_e-commerce' );
367
+ wp_enqueue_style( 'wpsc-colorbox-css', WPSC_CORE_JS_URL . '/wpsc_colorbox.css', false, $version_identifier, 'all' );
368
+ }
369
+ }
370
+ wp_enqueue_style( 'wpsc-theme-css', wpsc_get_template_file_url( 'wpsc-' . get_option( 'wpsc_selected_theme' ) . '.css' ), false, $version_identifier, 'all' );
371
+ wp_enqueue_style( 'wpsc-theme-css-compatibility', wpsc_get_template_file_url( 'compatibility.css' ), array( 'wpsc-theme-css' ), $version_identifier, 'all' );
372
+
373
+ if ( function_exists( 'wp_add_inline_style' ) )
374
+ wp_add_inline_style( 'wpsc-theme-css', wpsc_get_user_dynamic_css() );
375
+ else
376
+ wp_enqueue_style( 'wp-e-commerce-dynamic', wpsc_get_dynamic_user_css_url(), array( 'wpsc-theme-css' ), $version_identifier );
377
+
378
+ if( get_option( 'product_ratings' ) == 1 )
379
+ wp_enqueue_style( 'wpsc-product-rater', WPSC_CORE_JS_URL . '/product_rater.css', false, $version_identifier, 'all' );
380
+
381
+ }
382
+
383
+
384
+ if ( !defined( 'WPSC_MP3_MODULE_USES_HOOKS' ) && function_exists( 'listen_button' ) ) {
385
+
386
+ function wpsc_legacy_add_mp3_preview( $product_id, &$product_data ) {
387
+ global $wpdb;
388
+ if ( function_exists( 'listen_button' ) ) {
389
+ $file_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id` = %d LIMIT 1", $product_data['file'] ), ARRAY_A );
390
+ if ( $file_data != null ) {
391
+ echo listen_button( $file_data['idhash'], $file_data['id'] );
392
+ }
393
+ }
394
+ }
395
+
396
+ add_action( 'wpsc_product_before_description', 'wpsc_legacy_add_mp3_preview', 10, 2 );
397
+ }
398
+ }
399
+
400
+ /**
401
+ * Checks the category slug for a display type, if none set returns default
402
+ * << May need reworking to be more specific to the taxonomy type >>
403
+ * @access public
404
+ *
405
+ * @since 3.8
406
+ * @param $slug(string)
407
+ * @return $slug either from db or 'default' if none set
408
+ */
409
+
410
+ function wpsc_get_the_category_display($slug){
411
+ global $wpdb;
412
+ $default_display_type = get_option('product_view');
413
+ if ( !empty($slug) && is_string($slug) ) {
414
+ $category_id = wpsc_get_the_category_id($slug , 'slug');
415
+ $display_type = wpsc_get_categorymeta( $category_id, 'display_type' );
416
+ }
417
+ if(!empty($display_type))
418
+ return $display_type;
419
+ else
420
+ return $default_display_type;
421
+ }
422
+
423
+ /**
424
+ * wpsc display products function
425
+ * @return string - html displaying one or more products
426
+ */
427
+ function wpsc_display_products_page( $query ) {global $wpdb, $wpsc_query,$wp_query, $wp_the_query;
428
+
429
+ remove_filter('the_title','wpsc_the_category_title');
430
+
431
+ // If the data is coming from a shortcode parse the values into the args variable,
432
+ // I did it this was to preserve backwards compatibility
433
+ if(!empty($query)){
434
+ $args = array();
435
+
436
+ $args['post_type'] = 'wpsc-product';
437
+ if(!empty($query['product_id']) && is_array($query['product_id'])){
438
+ $args['post__in'] = $query['product_id'];
439
+ }elseif(is_string($query['product_id'])){
440
+ $args['post__in'] = (array)$query['product_id'];
441
+ }
442
+ if(!empty($query['old_product_id'])){
443
+ $post_id = wpsc_get_the_new_id($query['old_product_id']);
444
+ $args['post__in'] = (array)$post_id;
445
+ }
446
+ if(!empty($query['price']) && 'sale' != $query['price']){
447
+ $args['meta_key'] = '_wpsc_price';
448
+ $args['meta_value'] = $query['price'];
449
+ }elseif(!empty($query['price']) && 'sale' == $query['price']){
450
+ $args['meta_key'] = '_wpsc_special_price';
451
+ $args['meta_compare'] = '>=';
452
+ $args['meta_value'] = '1';
453
+ }
454
+ if(!empty($query['product_name'])){
455
+ $args['pagename'] = $query['product_name'];
456
+ }
457
+ if(!empty($query['category_id'])){
458
+ $term = get_term($query['category_id'],'wpsc_product_category');
459
+ $id = wpsc_get_meta($query['category_id'], 'category_id','wpsc_old_category');
460
+ if( !empty($id)){
461
+ $term = get_term($id,'wpsc_product_category');
462
+ $args['wpsc_product_category'] = $term->slug;
463
+ $args['wpsc_product_category__in'] = $term->term_id;
464
+ }else{
465
+ $args['wpsc_product_category'] = $term->slug;
466
+ $args['wpsc_product_category__in'] = $term->term_id;
467
+ }
468
+ }
469
+ if(!empty($query['category_url_name'])){
470
+ $args['wpsc_product_category'] = $query['category_url_name'];
471
+ }
472
+ $orderby = ( !empty($query['sort_order']) ) ? $query['sort_order'] : null;
473
+
474
+ $args = array_merge( $args, wpsc_product_sort_order_query_vars($orderby) );
475
+
476
+ if(!empty($query['order'])){
477
+ $args['order'] = $query['order'];
478
+ }
479
+ if(!empty($query['limit_of_items']) && '1' == get_option('use_pagination')){
480
+ $args['posts_per_page'] = $query['limit_of_items'];
481
+ }
482
+ if(!empty($query['number_per_page']) && '1' == get_option('use_pagination')){
483
+ $args['posts_per_page'] = $query['number_per_page'];
484
+ $args['paged'] = $query['page'];
485
+ }
486
+ if( '0' == get_option('use_pagination') ){
487
+ $args['nopaging'] = true;
488
+ $args['posts_per_page'] = '-1';
489
+ }
490
+ if(!empty($query['tag'])){
491
+ $args['product_tag'] = $query['tag'];
492
+ }
493
+ query_posts( $args );
494
+ }
495
+ // swap the wpsc_query objects
496
+
497
+ $GLOBALS['nzshpcrt_activateshpcrt'] = true;
498
+
499
+ // Pretty sure this single_product code is legacy...but fixing it up just in case.
500
+ // get the display type for the selected category
501
+ if(!empty($temp_wpsc_query->query_vars['term']))
502
+ $display_type = wpsc_get_the_category_display($temp_wpsc_query->query_vars['term']);
503
+ elseif( !empty( $args['wpsc_product_category'] ) )
504
+ $display_type = wpsc_get_the_category_display($args['wpsc_product_category']);
505
+ else
506
+ $display_type = 'default';
507
+
508
+ $saved_display = wpsc_get_customer_meta( 'display_type' );
509
+ $display_type = ! empty( $saved_display ) ? $saved_display : wpsc_check_display_type();
510
+
511
+ ob_start();
512
+ if( 'wpsc-product' == $wp_query->post->post_type && !is_archive() && $wp_query->post_count <= 1 )
513
+ include( wpsc_get_template_file_path( 'wpsc-single_product.php' ) );
514
+ else
515
+ wpsc_include_products_page_template($display_type);
516
+
517
+ $output = ob_get_contents();
518
+ ob_end_clean();
519
+ $output = str_replace('\$','$', $output);
520
+
521
+ if ( ! empty( $query ) ) {
522
+ wp_reset_query();
523
+ wp_reset_postdata();
524
+ }
525
+ return $output;
526
+ }
527
+
528
+ /**
529
+ * Checks if wpsc-single_product.php has been moved to the active theme, if it has then include the
530
+ * template from the active theme.
531
+ * @access public
532
+ *
533
+ * @since 3.8
534
+ * @param $content content of the page
535
+ * @return $content with wpsc-single_product content if its a single product
536
+ */
537
+ function wpsc_single_template( $content ) {
538
+ global $wpdb, $post, $wp_query, $wpsc_query, $_wpsc_is_in_custom_loop;
539
+ if ( ! in_the_loop() )
540
+ return $content;
541
+
542
+ //if we dont belong here exit out straight away
543
+ if((!isset($wp_query->is_product)) && !isset($wp_query->query_vars['wpsc_product_category']))return $content;
544
+
545
+ // If we are a single products page
546
+ if ( !is_archive() && $wp_query->post_count > 0 && 'wpsc-product' == $wp_query->post->post_type && $wp_query->post_count <= 1 ) {
547
+ remove_filter( "the_content", "wpsc_single_template", 12 );
548
+ $single_theme_path = wpsc_get_template_file_path( 'wpsc-single_product.php' );
549
+ if( isset( $wp_query->query_vars['preview'] ) && $wp_query->query_vars['preview'])
550
+ $is_preview = 'true';
551
+ else
552
+ $is_preview = 'false';
553
+ $wpsc_temp_query = new WP_Query( array( 'p' => $wp_query->post->ID , 'post_type' => 'wpsc-product','posts_per_page'=>1, 'preview' => $is_preview ) );
554
+
555
+ list( $wp_query, $wpsc_temp_query ) = array( $wpsc_temp_query, $wp_query ); // swap the wpsc_query object
556
+ $_wpsc_is_in_custom_loop = true;
557
+ ob_start();
558
+ include( $single_theme_path );
559
+ $content = ob_get_contents();
560
+ ob_end_clean();
561
+ list( $wp_query, $wpsc_temp_query ) = array( $wpsc_temp_query, $wp_query ); // swap the wpsc_query objects back
562
+ $_wpsc_is_in_custom_loop = false;
563
+ }
564
+
565
+ return $content;
566
+ }
567
+
568
+ function wpsc_is_viewable_taxonomy(){
569
+ global $wp_query;
570
+ if(isset($wp_query->query_vars['taxonomy']) && ('wpsc_product_category' == $wp_query->query_vars['taxonomy'] || 'product_tag' == $wp_query->query_vars['taxonomy'] ) || isset($wp_query->query_vars['wpsc_product_category']))
571
+ return true;
572
+ else
573
+ return false;
574
+ }
575
+
576
+ function _wpsc_is_in_custom_loop() {
577
+ global $_wpsc_is_in_custom_loop;
578
+ return (bool) $_wpsc_is_in_custom_loop;
579
+ }
580
+
581
+ /**
582
+ * Checks and replaces the Page title with the category title if on a category page
583
+ *
584
+ * @since 3.8
585
+ * @access public
586
+ *
587
+ * @param string $title The Page Title
588
+ * @param int $id The Page ID
589
+ * @return string $title The new title
590
+ *
591
+ * @uses in_the_loop() Returns true if you are in the loop
592
+ * @uses _wpsc_is_in_custom_loop() Returns true if in the WPSC custom loop
593
+ * @uses is_tax() Returns true if you are on the supplied registered taxonomy
594
+ * @uses get_term_by() Gets term object by defined item, and what you pass
595
+ * @uses get_query_var() Gets query var from wp_query
596
+ */
597
+ function wpsc_the_category_title( $title='', $id='' ){
598
+
599
+ if ( ! empty( $id ) )
600
+ _wpsc_deprecated_argument( __FUNCTION__, '3.8.10', 'The $id param is not used. If you are trying to get the title of the category use get_term' );
601
+
602
+ if ( ! in_the_loop() || _wpsc_is_in_custom_loop() )
603
+ return $title;
604
+
605
+ $term = null;
606
+ if ( is_tax( 'wpsc_product_category' ) ){
607
+ $term = get_term_by( 'slug', get_query_var( 'wpsc_product_category' ),'wpsc_product_category' );
608
+ } elseif ( is_tax( 'product_tag' ) ){
609
+ $term = get_term_by( 'slug', get_query_var( 'term' ),'product_tag' );
610
+ } // is_tax
611
+
612
+ if ( $term )
613
+ return $term->name;
614
+
615
+ return $title;
616
+
617
+ }
618
+
619
+ //handles replacing the tags in the pages
620
+ function wpsc_products_page( $content = '' ) {
621
+ global $wpdb, $wp_query, $wpsc_query, $wpsc_query_vars, $_wpsc_is_in_custom_loop;
622
+ $output = '';
623
+ if ( ! in_the_loop() )
624
+ return $content;
625
+ if ( preg_match( "/\[productspage\]/", $content ) ) {
626
+ global $more;
627
+ $more = 0;
628
+ remove_filter( 'the_content', 'wpautop' );
629
+
630
+ list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query object
631
+ $_wpsc_is_in_custom_loop = true;
632
+
633
+ $GLOBALS['nzshpcrt_activateshpcrt'] = true;
634
+
635
+ // get the display type for the productspage
636
+ $display_type = wpsc_check_display_type();
637
+ if ( get_option( 'show_search' ) && get_option( 'show_advanced_search' ) ) {
638
+ $saved_display = wpsc_get_customer_meta( 'display_type' );
639
+ if ( ! empty( $saved_display ) )
640
+ $display_type = $saved_display;
641
+ }
642
+
643
+ ob_start();
644
+ wpsc_include_products_page_template($display_type);
645
+ $is_single = false;
646
+ $output .= ob_get_contents();
647
+ ob_end_clean();
648
+ $output = str_replace( '$', '\$', $output );
649
+
650
+ if ( $wp_query->post_count > 0 ) {
651
+ $product_id = $wp_query->post->ID;
652
+ $product_meta = get_post_meta( $product_id, '_wpsc_product_metadata', true );
653
+
654
+ list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query objects back
655
+
656
+ $_wpsc_is_in_custom_loop = false;
657
+
658
+ if ( ($is_single == false) || ($product_meta['enable_comments'] == '0') )
659
+ wp_reset_postdata();
660
+ }
661
+ $wp_query->current_post = $wp_query->post_count;
662
+ return preg_replace( "/(<p>)*\[productspage\](<\/p>)*/", $output, $content );
663
+ } elseif(is_archive() && wpsc_is_viewable_taxonomy()){
664
+
665
+ remove_filter( 'the_content', 'wpautop' );
666
+ return wpsc_products_page('[productspage]');
667
+ } else {
668
+ return $content;
669
+ }
670
+ }
671
+
672
+ /**
673
+ * wpsc_the_category_template swaps the template used for product categories with pageif archive template is being used use
674
+ * @access public
675
+ *
676
+ * @since 3.8
677
+ * @param $template (string) template path
678
+ * @return $template (string)
679
+ */
680
+ function wpsc_the_category_template($template){
681
+ global $wp_query;
682
+ //this bit of code makes sure we use a nice standard page template for our products
683
+ if(wpsc_is_viewable_taxonomy() && false !== strpos($template,'archive'))
684
+ return str_ireplace('archive', 'page',$template);
685
+ else
686
+ return $template;
687
+
688
+ }
689
+
690
+ /**
691
+ * Returns current product category ID or default category ID if one is set. If one is not set and there is no current category, returns empty string
692
+ * @return mixed
693
+ */
694
+ function wpsc_get_current_category_id() {
695
+ global $wp_query;
696
+
697
+ $category_id = '';
698
+
699
+ if ( isset( $wp_query ) && isset( $wp_query->query_vars['taxonomy'] ) && ('wpsc_product_category' == $wp_query->query_vars['taxonomy'] ) || is_numeric( get_option( 'wpsc_default_category' ) ) )
700
+ $category_id = isset( $wp_query->query_vars['term'] ) && is_string( $wp_query->query_vars['term'] ) ? wpsc_get_category_id( $wp_query->query_vars['term'], 'slug' ) : get_option( 'wpsc_default_category' );
701
+
702
+ return $category_id;
703
+ }
704
+
705
+ /**
706
+ * Returns Dynamic User CSS URL
707
+ *
708
+ * This produces the cached CSS file if it exists and the uploads folder is writeable.
709
+ * If the folder is not writeable, we return the dynamic URL
710
+ * If the folder is writeable, but for some reason a cached copy of the CSS doesn't exist, we attempt to create it and return that URL.
711
+ *
712
+ * @since 3.8.9
713
+ * @return string
714
+ */
715
+
716
+ function wpsc_get_dynamic_user_css_url() {
717
+
718
+ $uploads_dir = wp_upload_dir();
719
+ $upload_folder = $uploads_dir['path'];
720
+
721
+ if ( is_writable( $upload_folder ) && file_exists( $upload_folder . '/wpsc_cached_styles.css' ) )
722
+ return add_query_arg( 'timestamp', get_option( 'wpsc_dynamic_css_hash', time() ), $uploads_dir['url'] . '/wpsc_cached_styles.css' );
723
+
724
+ if ( ! is_writable( $upload_folder ) )
725
+ return add_query_arg( 'wpsc_user_dynamic_css', 'true', home_url( 'index.php' ) );
726
+
727
+ if ( is_writable( $upload_folder ) && ! file_exists( $upload_folder . '/wpsc_cached_styles.css' ) )
728
+ return wpsc_cache_to_upload();
729
+ }
730
+
731
+ /**
732
+ * Moves dynamically generated input into a file in the uploads folder.
733
+ * Also updates CSS hash timestamp. Timestamp is appended to URL
734
+ *
735
+ * @since 3.8.9
736
+ * @return mixed File URL on successful move, false on failure
737
+ */
738
+ function wpsc_cache_to_upload() {
739
+
740
+ $uploads_dir = wp_upload_dir();
741
+ $upload_folder = $uploads_dir['path'];
742
+ $path = $upload_folder . '/wpsc_cached_styles.css';
743
+
744
+ if ( ! is_writable( $upload_folder ) )
745
+ return false;
746
+
747
+ if ( false === file_put_contents( $path, wpsc_get_user_dynamic_css() ) )
748
+ return false;
749
+
750
+ $timestamp = time();
751
+
752
+ update_option( 'wpsc_dynamic_css_hash', $timestamp );
753
+
754
+ return add_query_arg( 'timestamp', $timestamp, $uploads_dir['url'] . '/wpsc_cached_styles.css' );
755
+
756
+ }
757
+
758
+ /**
759
+ * Prints dynamic CSS. This function is run either when the dynamic URL is hit, or when we need to grab new CSS to cache.
760
+ *
761
+ * @since 3.8.9
762
+ * @return CSS
763
+ */
764
+ function wpsc_user_dynamic_css() {
765
+
766
+ header( 'Content-Type: text/css' );
767
+ header( 'Expires: ' . gmdate( 'r', mktime( 0, 0, 0, date( 'm' ), ( date( 'd' ) + 12 ), date( 'Y' ) ) ) );
768
+ header( 'Cache-Control: public, must-revalidate, max-age=86400' );
769
+ header( 'Pragma: public' );
770
+
771
+ echo wpsc_get_user_dynamic_css();
772
+ exit;
773
+ }
774
+
775
+ /**
776
+ * Returns dynamic CSS as string. This function is run either when the dynamic URL is hit, or when we need to grab new CSS to cache.
777
+ *
778
+ * @since 3.8.9
779
+ * @return string
780
+ */
781
+ function wpsc_get_user_dynamic_css() {
782
+ global $wpdb;
783
+
784
+ ob_start();
785
+
786
+ if ( ! defined( 'WPSC_DISABLE_IMAGE_SIZE_FIXES' ) || (constant( 'WPSC_DISABLE_IMAGE_SIZE_FIXES' ) != true ) ) {
787
+
788
+ $thumbnail_width = get_option( 'product_image_width' );
789
+
790
+ if ( $thumbnail_width <= 0 )
791
+ $thumbnail_width = 96;
792
+
793
+ $thumbnail_height = get_option( 'product_image_height' );
794
+
795
+ if ( $thumbnail_height <= 0 )
796
+ $thumbnail_height = 96;
797
+
798
+ $single_thumbnail_width = get_option( 'single_view_image_width' );
799
+ $single_thumbnail_height = get_option( 'single_view_image_height' );
800
+
801
+ if ( $single_thumbnail_width <= 0 )
802
+ $single_thumbnail_width = 128;
803
+
804
+ $category_height = get_option( 'category_image_height' );
805
+ $category_width = get_option( 'category_image_width' );
806
+ ?>
807
+
808
+ /*
809
+ * Default View Styling
810
+ */
811
+ div.default_product_display div.textcol{
812
+ margin-left: <?php echo $thumbnail_width + 10; ?>px !important;
813
+ min-height: <?php echo $thumbnail_height; ?>px;
814
+ _height: <?php echo $thumbnail_height; ?>px;
815
+ }
816
+
817
+ div.default_product_display div.textcol div.imagecol{
818
+ position:absolute;
819
+ top:0px;
820
+ left: 0px;
821
+ margin-left: -<?php echo $thumbnail_width + 10; ?>px !important;
822
+ }
823
+
824
+ div.default_product_display div.textcol div.imagecol a img {
825
+ width: <?php echo $thumbnail_width; ?>px;
826
+ height: <?php echo $thumbnail_height; ?>px;
827
+ }
828
+
829
+ .wpsc_category_grid_item {
830
+ display:block;
831
+ float:left;
832
+ width: <?php echo $category_width; ?>px;
833
+ height: <?php echo $category_height; ?>px;
834
+ }
835
+ .wpsc_category_grid_item span{
836
+ position:relative;
837
+ top:<?php echo ($thumbnail_height - 2)/9; ?>px;
838
+ }
839
+ div.default_product_display div.item_no_image a {
840
+ width: <?php echo $thumbnail_width - 2; ?>px;
841
+ }
842
+
843
+ div.default_product_display .imagecol img.no-image, #content div.default_product_display .imagecol img.no-image {
844
+ width: <?php echo $thumbnail_width; ?>px;
845
+ height: <?php echo $thumbnail_height; ?>px;
846
+ }
847
+
848
+ <?php do_action( 'wpsc_dynamic_css' ); ?>
849
+
850
+ /*
851
+ * Single View Styling
852
+ */
853
+
854
+ div.single_product_display div.item_no_image {
855
+ width: <?php echo $single_thumbnail_width - 2; ?>px;
856
+ height: <?php echo $single_thumbnail_height - 2; ?>px;
857
+ }
858
+ div.single_product_display div.item_no_image a {
859
+ width: <?php echo $single_thumbnail_width - 2; ?>px;
860
+ }
861
+
862
+ div.single_product_display div.textcol{
863
+ margin-left: <?php echo $single_thumbnail_width + 10; ?>px !important;
864
+ min-height: <?php echo $single_thumbnail_height; ?>px;
865
+ _height: <?php echo $single_thumbnail_height; ?>px;
866
+ }
867
+
868
+
869
+ div.single_product_display div.textcol div.imagecol{
870
+ position:absolute;
871
+
872
+ margin-left: -<?php echo $single_thumbnail_width + 10; ?>px !important;
873
+ }
874
+
875
+ div.single_product_display div.textcol div.imagecol a img {
876
+ width: <?php echo $single_thumbnail_width; ?>px;
877
+ height: <?php echo $single_thumbnail_height; ?>px;
878
+ }
879
+
880
+ <?php
881
+ }
882
+ if ( (isset($_GET['brand']) && is_numeric( $_GET['brand'] )) || (get_option( 'show_categorybrands' ) == 3) ) {
883
+ $brandstate = 'block';
884
+ $categorystate = 'none';
885
+ } else {
886
+ $brandstate = 'none';
887
+ $categorystate = 'block';
888
+ }
889
+ ?>
890
+ div#categorydisplay{
891
+ display: <?php echo $categorystate; ?>;
892
+ }
893
+
894
+ div#branddisplay{
895
+ display: <?php echo $brandstate; ?>;
896
+ }
897
+ <?php
898
+
899
+ $css = ob_get_contents();
900
+
901
+ ob_end_clean();
902
+
903
+ return $css;
904
+ }
905
+
906
+ function wpsc_get_the_new_id($prod_id){
907
+ global $wpdb;
908
+ $post_id = (int)$wpdb->get_var($wpdb->prepare( "SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE meta_key = %s AND `meta_value` = %d LIMIT 1", '_wpsc_original_id', $prod_id ));
909
+ return $post_id;
910
+
911
+ }
912
+
913
+ /**
914
+ * This switched between the 3 view types on category and products pages and includes the necessary tempalte part
915
+ * @access public
916
+ *
917
+ * @since 3.8
918
+ * @param $display_type
919
+ * @return NULL
920
+ */
921
+ function wpsc_include_products_page_template($display_type = 'default'){
922
+ if ( isset( $_GET['view_type'] ) && get_option( 'show_search' ) && get_option( 'show_advanced_search' ) ) {
923
+ switch ( $_GET['view_type'] ) {
924
+ case 'grid':
925
+ $display_type = 'grid';
926
+ wpsc_update_customer_meta( 'display_type', $display_type );
927
+ break;
928
+
929
+ case 'list':
930
+ $display_type = 'list';
931
+ wpsc_update_customer_meta( 'display_type', $display_type );
932
+ break;
933
+
934
+ case 'default':
935
+ $display_type = 'default';
936
+ wpsc_update_customer_meta( 'display_type', $display_type );
937
+ break;
938
+
939
+ default:
940
+ break;
941
+ }
942
+ }
943
+ // switch the display type, based on the display type variable...
944
+ switch ( $display_type ) {
945
+ case "grid":
946
+ include( wpsc_get_template_file_path( 'wpsc-grid_view.php' ) );
947
+ break; // only break if we have the function;
948
+
949
+ case "list":
950
+ include( wpsc_get_template_file_path( 'wpsc-list_view.php' ) );
951
+ break; // only break if we have the file;
952
+ default:
953
+ include( wpsc_get_template_file_path( 'wpsc-products_page.php' ) );
954
+ break;
955
+ }
956
+
957
+ }
958
+
959
+ function wpsc_thesis_compat( $loop ) {
960
+ $loop[1] = 'page';
961
+ return $loop;
962
+ }
963
+
964
+ // Template tags
965
+ function wpsc_all_products_on_page(){
966
+ global $wp_query,$wpsc_query;
967
+ do_action('wpsc_swap_the_template');
968
+ $products_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
969
+ $term = get_query_var( 'wpsc_product_category' );
970
+ $tax_term = get_query_var ('product_tag' );
971
+ $obj = $wp_query->get_queried_object();
972
+
973
+ $id = isset( $obj->ID ) ? $obj->ID : null;
974
+
975
+ if( get_query_var( 'post_type' ) == 'wpsc-product' || $term || $tax_term || ( $id == $products_page_id )){
976
+
977
+ $templates = array();
978
+
979
+ if ( $term && ! is_single() ) {
980
+ array_push( $templates, "taxonomy-wpsc_product_category-{$term}.php", 'taxonomy-wpsc_product_category.php' );
981
+ }
982
+
983
+ if ( $tax_term && ! is_single() ) {
984
+ array_push( $templates, "taxonomy-product_tag-{$tax_term}.php", 'taxonomy-product_tag.php' );
985
+ }
986
+
987
+
988
+ // Attempt to use the [productspage]'s custom page template as a higher priority than the normal page.php template
989
+ if ( false !== $productspage_page_template = get_post_meta($products_page_id, '_wp_page_template', true) )
990
+ array_push( $templates, $productspage_page_template );
991
+
992
+ array_push( $templates, 'page.php', 'single.php' );
993
+
994
+ if ( is_single() )
995
+ array_unshift( $templates, 'single-wpsc-product.php' );
996
+
997
+ // have to pass 'page' as the template type. This is lame, btw, and needs a rewrite in 4.0
998
+ if ( ! $template = get_query_template( 'page', $templates ) )
999
+ $template = get_index_template();
1000
+
1001
+ add_filter( 'thesis_custom_loop', 'wpsc_thesis_compat' );
1002
+
1003
+ include( $template );
1004
+ exit;
1005
+ }
1006
+ }
1007
+
1008
+ /**
1009
+ * wpsc_count_themes_in_uploads_directory, does exactly what the name says
1010
+ */
1011
+ function wpsc_count_themes_in_uploads_directory() {
1012
+ $uploads_dir = false;
1013
+ if ( is_dir( WPSC_OLD_THEMES_PATH.get_option('wpsc_selected_theme').'/' ) )
1014
+ $uploads_dir = @opendir( WPSC_OLD_THEMES_PATH.get_option('wpsc_selected_theme').'/' ); // might cause problems if dir doesnt exist
1015
+
1016
+ if ( !$uploads_dir )
1017
+ return false;
1018
+
1019
+ $file_names = array( );
1020
+ while ( ($file = @readdir( $uploads_dir )) !== false ) {
1021
+ if ( is_dir( WPSC_OLD_THEMES_PATH . get_option('wpsc_selected_theme') . '/' . $file ) && ($file != "..") && ($file != ".") && ($file != ".svn") )
1022
+ $file_names[] = $file;
1023
+
1024
+ }
1025
+ @closedir( $uploads_dir );
1026
+ return count( $file_names );
1027
+ }
1028
+
1029
+ function wpsc_place_shopping_cart( $content = '' ) {
1030
+ if ( ! in_the_loop() )
1031
+ return $content;
1032
+
1033
+ if ( preg_match( "/\[shoppingcart\]/", $content ) ) {
1034
+ // BEGIN: compatibility fix for outdated theme files still relying on sessions
1035
+ $_SESSION['coupon_numbers' ] = wpsc_get_customer_meta( 'coupon' );
1036
+ $_SESSION['wpsc_checkout_misc_error_messages' ] = wpsc_get_customer_meta( 'checkout_misc_error_messages' );
1037
+ $_SESSION['categoryAndShippingCountryConflict'] = wpsc_get_customer_meta( 'category_shipping_conflict' );
1038
+ $_SESSION['shippingSameBilling' ] = wpsc_get_customer_meta( 'shipping_same_as_billing' );
1039
+ $_SESSION['wpsc_checkout_user_error_messages' ] = wpsc_get_customer_meta( 'registration_error_messages' );
1040
+ // END: compatibility fix
1041
+ $GLOBALS['nzshpcrt_activateshpcrt'] = true;
1042
+ if ( ! defined( 'DONOTCACHEPAGE' ) )
1043
+ define( 'DONOTCACHEPAGE', true );
1044
+
1045
+ // call this function to detect conflicts when the cart page is first loaded, otherwise
1046
+ // any conflict messages will only be displayed on the next page load
1047
+ wpsc_get_acceptable_countries();
1048
+ ob_start();
1049
+ do_action( 'wpsc_before_shopping_cart_page' );
1050
+ include( wpsc_get_template_file_path( 'wpsc-shopping_cart_page.php' ) );
1051
+ do_action( 'wpsc_after_shopping_cart_page' );
1052
+ $output = ob_get_contents();
1053
+ ob_end_clean();
1054
+ $output = str_replace( '$', '\$', $output );
1055
+ wpsc_delete_customer_meta( 'checkout_misc_error_messages' );
1056
+ wpsc_delete_customer_meta( 'category_shipping_conflict' );
1057
+ wpsc_delete_customer_meta( 'registration_error_messages' );
1058
+ wpsc_delete_customer_meta( 'checkout_error_messages' );
1059
+ wpsc_delete_customer_meta( 'gateway_error_messages' );
1060
+ return preg_replace( "/(<p>)*\[shoppingcart\](<\/p>)*/", $output, $content );
1061
+ } else {
1062
+ return $content;
1063
+ }
1064
+ }
1065
+
1066
+ function wpsc_transaction_results( $content = '' ) {
1067
+ if ( ! in_the_loop() )
1068
+ return $content;
1069
+
1070
+ if ( preg_match( "/\[transactionresults\]/", $content ) ) {
1071
+ define( 'DONOTCACHEPAGE', true );
1072
+ ob_start();
1073
+ include( wpsc_get_template_file_path( 'wpsc-transaction_results.php' ) );
1074
+ $output = ob_get_contents();
1075
+ ob_end_clean();
1076
+ $output = preg_replace( '#(?<!\\\\)(\\$|\\\\)#', '\\\\$1', $output );
1077
+ return preg_replace( "/(<p>)*\[transactionresults\](<\/p>)*/", $output, $content );
1078
+ } else {
1079
+ return $content;
1080
+ }
1081
+ }
1082
+
1083
+ function wpsc_user_log( $content = '' ) {
1084
+ if ( ! in_the_loop() )
1085
+ return $content;
1086
+ if ( preg_match( "/\[userlog\]/", $content ) ) {
1087
+ define( 'DONOTCACHEPAGE', true );
1088
+
1089
+ ob_start();
1090
+
1091
+ include( wpsc_get_template_file_path('wpsc-user-log.php') );
1092
+ $output = ob_get_clean();
1093
+ $content = preg_replace( "/(<p>)*\[userlog\](<\/p>)*/", '[userlog]', $content );
1094
+ return str_replace( '[userlog]', $output, $content );
1095
+ } else {
1096
+ return $content;
1097
+ }
1098
+ }
1099
+
1100
+ function wpsc_get_the_post_id_by_shortcode( $shortcode ) {
1101
+
1102
+ $shortcode_options = array(
1103
+ '[productspage]' => 'product_list_url',
1104
+ '[shoppingcart]' => 'shopping_cart_url',
1105
+ '[checkout]' => 'shopping_cart_url',
1106
+ '[transactionresults]' => 'transact_url',
1107
+ '[userlog]' => 'user_account_url'
1108
+ );
1109
+
1110
+ if ( ! isset( $shortcode_options[$shortcode] ) )
1111
+ return 0;
1112
+
1113
+ $page_ids = get_option( 'wpsc_shortcode_page_ids', false );
1114
+
1115
+ if ( $page_ids === false ) {
1116
+ wpsc_update_permalink_slugs();
1117
+ $page_ids = get_option( 'wpsc_shortcode_page_ids', false );
1118
+ }
1119
+
1120
+ $post_id = isset( $page_ids[$shortcode] ) ? $page_ids[$shortcode] : null;
1121
+
1122
+ // For back compat
1123
+ $post_id = apply_filters( 'wpec_get_the_post_id_by_shortcode', $post_id );
1124
+
1125
+ return apply_filters( 'wpsc_get_the_post_id_by_shortcode', $post_id, $shortcode );
1126
+
1127
+ }
1128
+
1129
+ function wpec_remap_shop_subpages( $vars ) {
1130
+ if( empty( $vars ) )
1131
+ return $vars;
1132
+ $reserved_names = array('[shoppingcart]','[userlog]','[transactionresults]');
1133
+ foreach($reserved_names as $reserved_name){
1134
+ if ( isset( $vars['taxonomy'] ) && $vars['taxonomy'] == 'wpsc_product_category' && $isset( $vars['term'] ) && $vars['term'] == $page->post_name ) {
1135
+ $page_id = wpsc_get_the_post_id_by_shortcode( $reserved_name );
1136
+ $page = get_post( $page_id );
1137
+ return array( 'page_id' => $page->ID );
1138
+ }
1139
+ }
1140
+ return $vars;
1141
+ }
1142
+
1143
+ function wpsc_remove_page_from_query_string($query_string)
1144
+ {
1145
+
1146
+ if ( isset($query_string['name']) && $query_string['name'] == 'page' && isset($query_string['page']) ) {
1147
+ unset($query_string['name']);
1148
+ list($delim, $page_index) = explode( '/', $query_string['page'] );
1149
+
1150
+ $query_string['paged'] = $page_index;
1151
+ }
1152
+
1153
+ if ( isset($query_string['wpsc-product']) && 'page' == $query_string['wpsc-product'] )
1154
+ $query_string['wpsc-product'] = '';
1155
+
1156
+ if ( isset($query_string['name']) && is_numeric($query_string['name']) ) {
1157
+ $query_string['paged'] = $query_string['name'];
1158
+ $query_string['page'] = '/'.$query_string['name'];
1159
+
1160
+ $query_string['posts_per_page'] = get_option('wpsc_products_per_page');
1161
+ }
1162
+ if ( isset($query_string['wpsc-product']) && is_numeric($query_string['wpsc-product']) )
1163
+ unset( $query_string['wpsc-product'] );
1164
+
1165
+ if ( isset($query_string['wpsc_product_category']) && 'page' == $query_string['wpsc_product_category'] )
1166
+ unset( $query_string['wpsc_product_category'] );
1167
+ if ( isset($query_string['name']) && is_numeric($query_string['name']) )
1168
+ unset( $query_string['name'] );
1169
+ if ( isset($query_string['term']) && 'page' == $query_string['term'] ) {
1170
+ unset( $query_string['term'] );
1171
+ unset( $query_string['taxonomy'] );
1172
+ }
1173
+ return $query_string;
1174
+ }
1175
+
1176
+ function is_products_page(){
1177
+ global $post;
1178
+
1179
+ if ( empty( $post ) || ! is_object( $post ) || empty( $post->ID ) )
1180
+ return false;
1181
+
1182
+ $product_page_id = wpsc_get_the_post_id_by_shortcode( '[productspage]' );
1183
+
1184
+ return $post->ID == $product_page_id;
1185
+
1186
+ }
1187
+
1188
+ /**
1189
+ * wpsc_display_products_page function.
1190
+ *
1191
+ * @access public
1192
+ * @param mixed $query
1193
+ * @return void
1194
+ */
1195
+ function wpsc_display_featured_products_page() {
1196
+ global $wp_query;
1197
+ $sticky_array = get_option( 'sticky_products' );
1198
+ if ( (is_front_page() || is_home() || is_products_page() ) && !empty( $sticky_array ) && $wp_query->post_count > 1) {
1199
+ $query = get_posts( array(
1200
+ 'post__in' => $sticky_array,
1201
+ 'post_type' => 'wpsc-product',
1202
+ 'orderby' => 'rand',
1203
+ 'numberposts' => 1,
1204
+ 'posts_per_page' => 1
1205
+ ) );
1206
+
1207
+ if ( count( $query ) > 0 ) {
1208
+
1209
+ $GLOBALS['nzshpcrt_activateshpcrt'] = true;
1210
+ $image_width = get_option( 'product_image_width' );
1211
+ $image_height = get_option( 'product_image_height' );
1212
+ $featured_product_theme_path = wpsc_get_template_file_path( 'wpsc-featured_product.php' );
1213
+ ob_start();
1214
+ include_once($featured_product_theme_path);
1215
+ $is_single = false;
1216
+ $output .= ob_get_contents();
1217
+ ob_end_clean();
1218
+
1219
+ //Begin outputting featured product. We can worry about templating later, or folks can just CSS it up.
1220
+ echo $output;
1221
+ //End output
1222
+ }
1223
+ }
1224
+ }
1225
+
1226
+ function wpsc_hidesubcatprods_init() {
1227
+ $hide_subcatsprods = new WPSC_Hide_subcatsprods_in_cat;
1228
+ add_action( 'pre_get_posts', array( &$hide_subcatsprods, 'get_posts' ) );
1229
+ }
1230
+
1231
+ function wpsc_the_featured_image_fix( $stuff, $post_ID ){
1232
+ global $wp_query;
1233
+
1234
+ $is_tax = is_tax( 'wpsc_product_category' );
1235
+
1236
+ $queried_object = get_queried_object();
1237
+ $is_single = is_single() && $queried_object->ID == $post_ID && get_post_type() == 'wpsc-product';
1238
+
1239
+ if ( $is_tax || $is_single ) {
1240
+ $header_image = get_header_image();
1241
+ $stuff = '';
1242
+
1243
+ if ( $header_image )
1244
+ $stuff = '<img src="' . esc_url( $header_image ) . '" width="' . HEADER_IMAGE_WIDTH . '" height="' . HEADER_IMAGE_HEIGHT . '" alt="" />';
1245
+ }
1246
+
1247
+ remove_action('post_thumbnail_html','wpsc_the_featured_image_fix');
1248
+
1249
+ return $stuff;
1250
+ }
1251
+
1252
+ // check for all in one SEO pack and the is_static_front_page function
1253
+ if ( is_callable( array( "All_in_One_SEO_Pack", 'is_static_front_page' ) ) ) {
1254
+
1255
+ function wpsc_change_aioseop_home_title( $title ) {
1256
+ global $aiosp, $aioseop_options;
1257
+
1258
+ if ( (get_class( $aiosp ) == 'All_in_One_SEO_Pack') && $aiosp->is_static_front_page() ) {
1259
+ $aiosp_home_title = $aiosp->internationalize( $aioseop_options['aiosp_home_title'] );
1260
+ $new_title = wpsc_obtain_the_title();
1261
+ if ( $new_title != '' ) {
1262
+ $title = str_replace( $aiosp_home_title, $new_title, $title );
1263
+ }
1264
+ }
1265
+ return $title;
1266
+ }
1267
+
1268
+ add_filter( 'aioseop_home_page_title', 'wpsc_change_aioseop_home_title' );
1269
+ }
1270
+
1271
+ /**
1272
+ * wpsc_obtain_the_title function, for replaacing the page title with the category or product
1273
+ * @return string - the new page title
1274
+ */
1275
+ function wpsc_obtain_the_title() {
1276
+ global $wpdb, $wp_query, $wpsc_title_data;
1277
+ $output = null;
1278
+ $category_id = null;
1279
+ if( !isset( $wp_query->query_vars['wpsc_product_category']) && !isset( $wp_query->query_vars['wpsc-product']))
1280
+ return;
1281
+
1282
+ if ( !isset( $wp_query->query_vars['wpsc_product_category'] ) && isset($wp_query->query_vars['wpsc-product']) )
1283
+ $wp_query->query_vars['wpsc_product_category'] = 0;
1284
+
1285
+
1286
+ if ( isset( $wp_query->query_vars['taxonomy'] ) && 'wpsc_product_category' == $wp_query->query_vars['taxonomy'] || isset($wp_query->query_vars['wpsc_product_category']))
1287
+ $category_id = wpsc_get_the_category_id($wp_query->query_vars['wpsc_product_category'],'slug');
1288
+
1289
+ if ( $category_id > 0 ) {
1290
+
1291
+ if ( isset( $wpsc_title_data['category'][$category_id] ) ) {
1292
+ $output = $wpsc_title_data['category'][$category_id];
1293
+ } else {
1294
+ $term = get_term($category_id, 'wpsc_product_category');
1295
+ $output = $term->name;
1296
+ $wpsc_title_data['category'][$category_id] = $output;
1297
+ }
1298
+ }
1299
+
1300
+ if ( !isset( $_GET['wpsc-product'] ) )
1301
+ $_GET['wpsc-product'] = 0;
1302
+
1303
+ if ( !isset( $wp_query->query_vars['wpsc-product'] ) )
1304
+ $wp_query->query_vars['wpsc-product'] = '';
1305
+
1306
+ if ( isset( $wp_query->query_vars['wpsc-product'] ) || is_string( $_GET['wpsc-product'] ) ) {
1307
+ $product_name = $wp_query->query_vars['wpsc-product'];
1308
+ if ( isset( $wpsc_title_data['product'][$product_name] ) ) {
1309
+ $product_list = array( );
1310
+ $full_product_name = $wpsc_title_data['product'][$product_name];
1311
+ } else if ( $product_name != '' ) {
1312
+ $product_id = $wp_query->post->ID;
1313
+ $full_product_name = $wpdb->get_var( $wpdb->prepare( "SELECT `post_title` FROM `$wpdb->posts` WHERE `ID`= %d LIMIT 1", $product_id ) );
1314
+ $wpsc_title_data['product'][$product_name] = $full_product_name;
1315
+ } else {
1316
+ if(isset($_REQUEST['product_id'])){
1317
+ $product_id = absint( $_REQUEST['product_id'] );
1318
+ $product_name = $wpdb->get_var( $wpdb->prepare( "SELECT `post_title` FROM `$wpdb->posts` WHERE `ID`= %d LIMIT 1", $product_id ) );
1319
+ $full_product_name = $wpdb->get_var( $wpdb->prepare( "SELECT `post_title` FROM `$wpdb->posts` WHERE `ID`= %d LIMIT 1", $product_id ) );
1320
+ $wpsc_title_data['product'][$product_name] = $full_product_name;
1321
+ }else{
1322
+ //This has to exist, otherwise we would have bailed earlier.
1323
+ $category = $wp_query->query_vars['wpsc_product_category'];
1324
+ $cat_term = get_term_by('slug',$wp_query->query_vars['wpsc_product_category'], 'wpsc_product_category');
1325
+ $full_product_name = $cat_term->name;
1326
+ }
1327
+ }
1328
+ $output = $full_product_name;
1329
+ }
1330
+
1331
+ if ( isset( $full_product_name ) && ($full_product_name != null) )
1332
+ $output = esc_html( $full_product_name );
1333
+ $seperator = ' | ';
1334
+ $seperator = apply_filters('wpsc_the_wp_title_seperator' , $seperator);
1335
+ return $output.$seperator;
1336
+ }
1337
+
1338
+ /**
1339
+ * Return category or product description depending on queried item
1340
+ */
1341
+ function wpsc_obtain_the_description() {
1342
+
1343
+ $output = null;
1344
+
1345
+ // Return Category Description
1346
+ if ( is_numeric( get_query_var('category_id') ) ) {
1347
+ $output = wpsc_get_categorymeta( get_query_var('category_id'), 'description' );
1348
+ } else if ( ! empty($_GET['category']) ) {
1349
+ $output = wpsc_get_categorymeta( absint( $_GET['category'] ), 'description' );
1350
+ }
1351
+
1352
+ // Return product content as description if product page
1353
+ if ( !empty($_GET['product_id'] ) && is_numeric( $_GET['product_id'] ) ) {
1354
+ $product = get_post(absint( $_GET['product_id'] ));
1355
+ $output = $product->post_content;
1356
+ }
1357
+
1358
+ return $output;
1359
+ }
1360
+
1361
+ function wpsc_set_aioseop_description( $data ) {
1362
+ $replacement_data = wpsc_obtain_the_description();
1363
+ if ( $replacement_data != '' ) {
1364
+ $data = $replacement_data;
1365
+ }
1366
+ return $data;
1367
+ }
1368
+
1369
+ /**
1370
+ * this page url function, returns the URL of this page
1371
+ * @return string - the URL of the current page
1372
+ */
1373
+ function wpsc_this_page_url() {
1374
+ global $wpsc_query, $wp_query;
1375
+ if ( $wpsc_query->is_single === true ) {
1376
+ $output = get_permalink( $wp_query->post->ID );
1377
+ } else if ( isset( $wpsc_query->category ) && $wpsc_query->category != null ) {
1378
+ $output = wpsc_category_url( $wpsc_query->category );
1379
+ if ( $wpsc_query->query_vars['page'] > 1 ) {
1380
+ if ( get_option( 'permalink_structure' ) ) {
1381
+ $output .= "page/{$wpsc_query->query_vars['page']}/";
1382
+ } else {
1383
+ $output = add_query_arg( 'page_number', $wpsc_query->query_vars['page'], $output );
1384
+ }
1385
+ }
1386
+ } elseif ( isset( $id ) ) {
1387
+ $output = get_permalink( $id );
1388
+ } else {
1389
+ $output = get_permalink( get_the_ID() );
1390
+ }
1391
+ return $output;
1392
+ }
1393
+
wpsc-components/theme-engine-v1/helpers/product.php ADDED
@@ -0,0 +1,868 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ add_action( 'save_post', 'wpsc_refresh_page_urls', 10, 2 );
3
+ add_action( 'wpsc_theme_footer', 'wpsc_fancy_notifications' );
4
+
5
+ if ( get_option( 'wpsc_replace_page_title' ) == 1 )
6
+ add_filter( 'wp_title', 'wpsc_replace_wp_title', 10, 2 );
7
+ add_filter( 'post_type_link', 'wpsc_product_link', 10, 3 );
8
+
9
+ /**
10
+ * wpsc_product_link function.
11
+ * Gets the product link, hooks into post_link
12
+ * Uses the currently selected, only associated or first listed category for the term URL
13
+ * If the category slug is the same as the product slug, it prefixes the product slug with "product/" to counteract conflicts
14
+ *
15
+ * @access public
16
+ * @return void
17
+ */
18
+ function wpsc_product_link( $permalink, $post, $leavename ) {
19
+ global $wp_query, $wpsc_page_titles, $wpsc_query, $wp_current_filter;
20
+ $rewritecode = array(
21
+ '%wpsc_product_category%',
22
+ $leavename ? '' : '%postname%',
23
+ );
24
+ if ( is_object( $post ) ) {
25
+ // In wordpress 2.9 we got a post object
26
+ $post_id = $post->ID;
27
+ } else {
28
+ // In wordpress 3.0 we get a post ID
29
+ $post_id = $post;
30
+ $post = get_post( $post_id );
31
+ }
32
+
33
+ // Only applies to WPSC products, don't stop on permalinks of other CPTs
34
+ // Fixes http://code.google.com/p/wp-e-commerce/issues/detail?id=271
35
+ if ($post->post_type != 'wpsc-product')
36
+ return $permalink;
37
+
38
+ $permalink_structure = get_option( 'permalink_structure' );
39
+
40
+ // This may become customiseable later
41
+ $our_permalink_structure = str_replace( basename( home_url() ), '', $wpsc_page_titles['products'] ) . "/%wpsc_product_category%/%postname%/";
42
+ // Mostly the same conditions used for posts, but restricted to items with a post type of "wpsc-product "
43
+
44
+ if ( '' != $permalink_structure && !in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
45
+ $product_categories = wpsc_get_product_terms( $post_id, 'wpsc_product_category' );
46
+ $product_category_slugs = array( );
47
+ foreach ( $product_categories as $product_category ) {
48
+ $product_category_slugs[] = $product_category->slug;
49
+ }
50
+ // If the product is associated with multiple categories, determine which one to pick
51
+ if ( count( $product_categories ) == 0 ) {
52
+ $category_slug = 'uncategorized';
53
+ } elseif ( count( $product_categories ) > 1 ) {
54
+ if ( (isset( $wp_query->query_vars['products'] ) && $wp_query->query_vars['products'] != null) && in_array( $wp_query->query_vars['products'], $product_category_slugs ) ) {
55
+ $product_category = $wp_query->query_vars['products'];
56
+ } else {
57
+ $link = $product_categories[0]->slug;
58
+ if ( ! in_array( 'wp_head', $wp_current_filter) && isset( $wpsc_query->query_vars['wpsc_product_category'] ) ) {
59
+ $current_cat = $wpsc_query->query_vars['wpsc_product_category'];
60
+ if ( in_array( $current_cat, $product_category_slugs ) )
61
+ $link = $current_cat;
62
+ }
63
+
64
+ $product_category = $link;
65
+ }
66
+ $category_slug = $product_category;
67
+ } else {
68
+ // If the product is associated with only one category, we only have one choice
69
+ if ( !isset( $product_categories[0] ) )
70
+ $product_categories[0] = '';
71
+
72
+ $product_category = $product_categories[0];
73
+
74
+ if ( !is_object( $product_category ) )
75
+ $product_category = new stdClass();
76
+
77
+ if ( !isset( $product_category->slug ) )
78
+ $product_category->slug = null;
79
+
80
+ $category_slug = $product_category->slug;
81
+ }
82
+
83
+ $post_name = $post->post_name;
84
+
85
+ if ( get_option( 'product_category_hierarchical_url', 0 ) ) {
86
+ $selected_term = get_term_by( 'slug', $category_slug, 'wpsc_product_category' );
87
+ if ( is_object( $selected_term ) ) {
88
+ $term_chain = array( $selected_term->slug );
89
+ while ( $selected_term->parent ) {
90
+ $selected_term = get_term( $selected_term->parent, 'wpsc_product_category' );
91
+ array_unshift( $term_chain, $selected_term->slug );
92
+ }
93
+ $category_slug = implode( '/', $term_chain );
94
+ }
95
+ }
96
+
97
+ if( isset( $category_slug ) && empty( $category_slug ) )
98
+ $category_slug = 'product';
99
+
100
+ $category_slug = apply_filters( 'wpsc_product_permalink_cat_slug', $category_slug, $post_id );
101
+
102
+ $rewritereplace = array(
103
+ $category_slug,
104
+ $post_name
105
+ );
106
+
107
+ $permalink = str_replace( $rewritecode, $rewritereplace, $our_permalink_structure );
108
+ $permalink = user_trailingslashit( $permalink, 'single' );
109
+
110
+ $permalink = home_url( $permalink );
111
+ }
112
+ return apply_filters( 'wpsc_product_permalink', $permalink, $post->ID );
113
+ }
114
+
115
+ /**
116
+ * wpsc_list_categories function.
117
+ *
118
+ * @access public
119
+ * @param string $callback_function - The function name you want to use for displaying the data
120
+ * @param mixed $parameters (default: null) - the additional parameters to the callback function
121
+ * @param int $category_id. (default: 0) - The category id defaults to zero, for displaying all categories
122
+ * @param int $level. (default: 0)
123
+ */
124
+ function wpsc_list_categories($callback_function, $parameters = null, $category_id = 0, $level = 0) {
125
+ global $wpdb,$category_data;
126
+ $output = '';
127
+ $category_list = get_terms('wpsc_product_category','hide_empty=0&parent='.$category_id);
128
+ if($category_list != null) {
129
+ foreach((array)$category_list as $category) {
130
+ $callback_output = $callback_function($category, $level, $parameters);
131
+ if(is_array($callback_output)) {
132
+ $output .= array_shift($callback_output);
133
+ } else {
134
+ $output .= $callback_output;
135
+ }
136
+ $output .= wpsc_list_categories($callback_function, $parameters , $category->term_id, ($level+1));
137
+ if(is_array($callback_output) && (isset($callback_output[1]))) {
138
+ $output .= $callback_output[1];
139
+ }
140
+ }
141
+ }
142
+ return $output;
143
+ }
144
+
145
+ /**
146
+ * Gets the Function Parent Image link and checks whether Image should be displayed or not
147
+ *
148
+ */
149
+ function wpsc_parent_category_image($show_thumbnails , $category_image , $width, $height, $grid=false, $show_name){
150
+
151
+ if(!$show_thumbnails) return;
152
+
153
+ if($category_image == WPSC_CATEGORY_URL){
154
+ if(!$show_name) return;
155
+ ?>
156
+ <span class='wpsc_category_image item_no_image ' style='width:<?php echo $width; ?>px; height: <?php echo $height; ?>px;'>
157
+ <span class='link_substitute' >
158
+ <span><?php _e('N/A', 'wpsc'); ?></span>
159
+ </span>
160
+ </span>
161
+ <?php
162
+ }else{
163
+ ?><img src='<?php echo $category_image; ?>' width='<?php echo $width; ?>' height='<?php echo $height; ?>' /><?php
164
+ }
165
+ }
166
+ /// category template tags start here
167
+
168
+ /**
169
+ * wpsc starts category query function
170
+ * gets passed the query and makes it into a global variable, then starts capturing the html for the category loop
171
+ */
172
+ function wpsc_start_category_query($arguments = array()) {
173
+ global $wpdb, $wpsc_category_query;
174
+ $wpsc_category_query = $arguments;
175
+ ob_start();
176
+ }
177
+
178
+ /**
179
+ * wpsc print category name function
180
+ * places the shortcode for the category name
181
+ */
182
+ function wpsc_print_category_name() {
183
+ echo "[wpsc_category_name]";
184
+ }
185
+
186
+ /**
187
+ * wpsc print category description function
188
+ * places the shortcode for the category description, accepts parameters for the description container
189
+ * @param string starting HTML element
190
+ * @param string ending HTML element
191
+ */
192
+ function wpsc_print_category_description($start_element = '', $end_element = '') {
193
+ global $wpsc_category_query;
194
+ $wpsc_category_query['description_container'] = array('start_element' => $start_element, 'end_element' => $end_element);
195
+ echo "[wpsc_category_description]";
196
+ }
197
+
198
+ /**
199
+ * wpsc print category url function
200
+ * places the shortcode for the category URL
201
+ */
202
+ function wpsc_print_category_url() {
203
+ echo "[wpsc_category_url]";
204
+ }
205
+
206
+ /**
207
+ * wpsc print category id function
208
+ * places the shortcode for the category URL
209
+ */
210
+ function wpsc_print_category_id() {
211
+ echo "[wpsc_category_id]";
212
+ }
213
+
214
+ /**
215
+ * wpsc print category classes function
216
+ * places classes for the category including selected state
217
+ *
218
+ * please note that "current category" means the category that we are in now,
219
+ * and not the category that we are printing for
220
+ *
221
+ * @param $category_to_print - the category for which we should print classes
222
+ * @param $echo - whether to echo the result (true) or return (false)
223
+ */
224
+ function wpsc_print_category_classes($category_to_print = false, $echo = true) {
225
+ global $wp_query, $wpdb;
226
+
227
+ //if we are in wpsc category page then get the current category
228
+ $curr_cat = false;
229
+ $term = get_query_var( 'wpsc_product_category' );
230
+ if ( ! $term && get_query_var( 'taxonomy' ) == 'wpsc_product_category' )
231
+ $term = get_query_var( 'term' );
232
+ if ( $term )
233
+ $curr_cat = get_term_by( 'slug', $term, 'wpsc_product_category' );
234
+
235
+ //check if we are in wpsc category page and that we have a term_id of the category to print
236
+ //this is done here because none of the following matters if we don't have one of those and we can
237
+ //safely return
238
+ if(isset($category_to_print['term_id']) && $curr_cat){
239
+
240
+ //we will need a list of current category parents for the following if statement
241
+ $curr_cat_parents = wpsc_get_term_parents($curr_cat->term_id, 'wpsc_product_category');
242
+
243
+ //if current category is the same as the one we are printing - then add wpsc-current-cat class
244
+ if( $category_to_print['term_id'] == $curr_cat->term_id )
245
+ $result = ' wpsc-current-cat ';
246
+ //else check if the category that we are printing is parent of current category
247
+ elseif ( in_array($category_to_print['term_id'], $curr_cat_parents) )
248
+ $result = ' wpsc-cat-ancestor ';
249
+ }
250
+ if( isset($result) )
251
+ if($echo)
252
+ echo $result;
253
+ else
254
+ return $result;
255
+ }
256
+
257
+ /**
258
+ * wpsc print subcategory function
259
+ * places the shortcode for the subcategories, accepts parameters for the subcategories container, have this as <ul> and </ul> if using a list
260
+ * @param string starting HTML element
261
+ * @param string ending HTML element
262
+ */
263
+ function wpsc_print_subcategory($start_element = '', $end_element = '') {
264
+ global $wpsc_category_query;
265
+ $wpsc_category_query['subcategory_container'] = array('start_element' => $start_element, 'end_element' => $end_element);
266
+ echo "[wpsc_subcategory]";
267
+ }
268
+ function wpsc_print_category_classes_section(){
269
+ echo "[wpsc_category_classes]";
270
+ }
271
+
272
+ /**
273
+ * wpsc print category image function
274
+ * places the shortcode for the category image, accepts parameters for width and height
275
+ * @param integer width
276
+ * @param integer height
277
+ */
278
+ function wpsc_print_category_image($width = null, $height = null) {
279
+ global $wpsc_category_query;
280
+ $wpsc_category_query['image_size'] = array('width' => $width, 'height' => $height);
281
+ echo "[wpsc_category_image]";
282
+ }
283
+
284
+ /**
285
+ * wpsc print category products count function
286
+ * places the shortcode for the category product count, accepts parameters for the container element
287
+ * @param string starting HTML element
288
+ * @param string ending HTML element
289
+ */
290
+ function wpsc_print_category_products_count($start_element = '', $end_element = '') {
291
+ global $wpsc_category_query;
292
+ $wpsc_category_query['products_count'] = array('start_element' => $start_element, 'end_element' => $end_element);
293
+ echo "[wpsc_category_products_count]";
294
+ }
295
+
296
+ /**
297
+ * wpsc end category query function
298
+ */
299
+ function wpsc_end_category_query() {
300
+ global $wpdb, $wpsc_category_query;
301
+ $category_html = ob_get_clean();
302
+ echo wpsc_display_category_loop($wpsc_category_query, $category_html);
303
+ unset($GLOBALS['wpsc_category_query']);
304
+ }
305
+
306
+ /**
307
+ * wpsc category loop function
308
+ * This function recursively loops through the categories to display the category tree.
309
+ * This function also generates a tree of categories at the same time
310
+ * WARNING: as this function is recursive, be careful what you do with it.
311
+ * @param array the category query
312
+ * @param string the category html
313
+ * @param array the category array branch, is an internal value, leave it alone.
314
+ * @return string - the finished category html
315
+ */
316
+ function wpsc_display_category_loop($query, $category_html, &$category_branch = null){
317
+ static $category_count_data = array(); // the array tree is stored in this
318
+
319
+ if( isset($query['parent_category_id']) )
320
+ $category_id = absint($query['parent_category_id']);
321
+ else
322
+ $category_id = 0;
323
+ $category_data = get_terms('wpsc_product_category','hide_empty=0&parent='.$category_id, OBJECT, 'display');
324
+ $output ='';
325
+
326
+ // if the category branch is identical to null, make it a reference to $category_count_data
327
+ if($category_branch === null) {
328
+ $category_branch =& $category_count_data;
329
+ }
330
+ $allowed_tags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array(), 'b'=> array());
331
+
332
+ $allowedtags = apply_filters('wpsc_category_description_allowed_tags' , $allowed_tags);
333
+
334
+ foreach((array)$category_data as $category_row) {
335
+
336
+ // modifys the query for the next round
337
+ $modified_query = $query;
338
+ $modified_query['parent_category_id'] = $category_row->term_id;
339
+
340
+ // gets the count of products associated with this category
341
+ $category_count = $category_row->count;
342
+
343
+
344
+ // Sticks the category description in
345
+ $category_description = '';
346
+ if($category_row->description != '' && ! empty( $query['description_container'] ) ) {
347
+ $start_element = $query['description_container']['start_element'];
348
+ $end_element = $query['description_container']['end_element'];
349
+ $category_description = $start_element.wpautop(wptexturize( wp_kses( $category_row->description, $allowedtags ))).$end_element;
350
+ }
351
+
352
+
353
+ // Creates the list of classes on the category item
354
+ $category_classes = wpsc_print_category_classes((array)$category_row, false);
355
+
356
+ // Set the variables for this category
357
+ $category_branch[$category_row->term_id]['children'] = array();
358
+ $category_branch[$category_row->term_id]['count'] = (int)$category_count;
359
+
360
+
361
+ // Recurse into the next level of categories
362
+ $sub_categories = wpsc_display_category_loop($modified_query, $category_html, $category_branch[$category_row->term_id]['children']);
363
+
364
+ // grab the product count from the subcategories
365
+ foreach((array)$category_branch[$category_row->term_id]['children'] as $child_category) {
366
+ $category_branch[$category_row->term_id]['count'] += (int)$child_category['count'];
367
+ }
368
+
369
+ // stick the category count array together here
370
+ // this must run after the subcategories and the count of products belonging to them has been obtained
371
+
372
+ $category_count = $category_branch[$category_row->term_id]['count'];
373
+
374
+ $start_element = '';
375
+ $end_element = '';
376
+
377
+ if (isset($query['products_count']['start_element'])) {
378
+ $start_element = $query['products_count']['start_element'];
379
+ }
380
+
381
+ if (isset($query['products_count']['end_element'])) {
382
+ $end_element = $query['products_count']['end_element'];
383
+ }
384
+
385
+ $category_count_html = $start_element.$category_count.$end_element;
386
+
387
+
388
+ if ( isset( $query['subcategory_container'] ) && ! empty( $sub_categories ) ) {
389
+ $start_element = $query['subcategory_container']['start_element'];
390
+ $end_element = $query['subcategory_container']['end_element'];
391
+ $sub_categories = $start_element.$sub_categories.$end_element;
392
+ }
393
+
394
+ // get the category images
395
+ $category_image = wpsc_place_category_image($category_row->term_id, $modified_query);
396
+
397
+ if ( empty( $query['image_size']['width'] ) ) {
398
+ if ( ! wpsc_category_grid_view() )
399
+ $width = wpsc_get_categorymeta( $category_row->term_id, 'image_width' );
400
+ if ( empty( $width ) )
401
+ $width = get_option( 'category_image_width' );
402
+ } else {
403
+ $width = $query['image_size']['width'];
404
+ }
405
+
406
+ if ( empty( $query['image_size']['height'] ) ) {
407
+ if ( ! wpsc_category_grid_view() )
408
+ $height = wpsc_get_categorymeta( $category_row->term_id, 'image_height' );
409
+ if ( empty( $height ) )
410
+ $height = get_option( 'category_image_height' );
411
+ } else {
412
+ $height = $query['image_size']['height'];
413
+ }
414
+
415
+ $category_image = wpsc_get_categorymeta($category_row->term_id, 'image');
416
+ $category_image_html = '';
417
+ if(($query['show_thumbnails'] == 1)) {
418
+ if((!empty($category_image)) && is_file(WPSC_CATEGORY_DIR.$category_image)) {
419
+ $category_image_html = "<img src='".WPSC_CATEGORY_URL."$category_image' alt='{$category_row->name}' title='{$category_row->name}' style='width: {$width}px; height: {$height}px;' class='wpsc_category_image' />";
420
+ } elseif( isset( $query['show_name'] ) && 1 == $query['show_name']) {
421
+ $category_image_html .= "<span class='wpsc_category_image item_no_image ' style='width: {$width}px; height: {$height}px;'>\n\r";
422
+ $category_image_html .= " <span class='link_substitute' >\n\r";
423
+ $category_image_html .= " <span>".__('N/A','wpsc')."</span>\n\r";
424
+ $category_image_html .= " </span>\n\r";
425
+ $category_image_html .= "</span>\n\r";
426
+ }
427
+
428
+ }
429
+
430
+
431
+ // get the list of products associated with this category.
432
+ $tags_to_replace = array('[wpsc_category_name]',
433
+ '[wpsc_category_description]',
434
+ '[wpsc_category_url]',
435
+ '[wpsc_category_id]',
436
+ '[wpsc_category_classes]',
437
+ '[wpsc_category_image]',
438
+ '[wpsc_subcategory]',
439
+ '[wpsc_category_products_count]');
440
+
441
+ $content_to_place = array(
442
+ esc_html($category_row->name),
443
+ $category_description,
444
+ esc_url( get_term_link( $category_row->slug, 'wpsc_product_category' ) ),
445
+ $category_row->term_id,
446
+ $category_classes,
447
+ $category_image_html,
448
+ $sub_categories,
449
+ $category_count_html);
450
+
451
+ // Stick all the category html together and concatenate it to the previously generated HTML
452
+ $output .= str_replace($tags_to_replace, $content_to_place ,$category_html);
453
+ }
454
+ return $output;
455
+ }
456
+
457
+ /**
458
+ * wpsc category image function
459
+ * if no parameters are passed, the category is not resized, otherwise it is resized to the specified dimensions
460
+ * @param integer category id
461
+ * @param array category query array
462
+ * @return string - the category image URL, or the URL of the resized version
463
+ */
464
+ function wpsc_place_category_image($category_id, $query) {
465
+ // show the full sized image for the product, if supplied with dimensions, will resize image to those.
466
+ $width = (isset($query['image_size']['width'])) ? ($query['image_size']['width']) : get_option('category_image_width');
467
+ $height = (isset($query['image_size']['height'])) ? ($query['image_size']['height']) : get_option('category_image_height');
468
+ $image_url = "index.php?wpsc_request_image=true&category_id=".$category_id."&width=".$width."&height=".$height;
469
+ return htmlspecialchars($image_url);
470
+ }
471
+
472
+ /// category template tags end here
473
+
474
+ /**
475
+ * wpsc_category_url function, makes permalink to the category or
476
+ * @param integer category ID, can be 0
477
+ * @param boolean permalink compatibility, adds a prefix to prevent permalink namespace conflicts
478
+ */
479
+ function wpsc_category_url($category_id, $permalink_compatibility = false) {
480
+ return get_term_link( $category_id, 'wpsc_product_category');
481
+ }
482
+
483
+
484
+ function wpsc_is_in_category() {
485
+ global $wpdb, $wp_query;
486
+ $is_in_category = false;
487
+ if(isset($wp_query->query_vars['wpsc_product_category'] ) && !empty($wp_query->query_vars['wpsc_product_category'])) {
488
+ $is_in_category = true;
489
+ } else if(isset($_GET['wpsc_product_category']) && !empty($_GET['wpsc_product_category'])) {
490
+ $is_in_category = true;
491
+ }
492
+
493
+ return $is_in_category;
494
+ }
495
+
496
+
497
+ /**
498
+ * Uses a category's, (in the wpsc_product_category taxonomy), slug to find its
499
+ * ID, then returns it.
500
+ *
501
+ * @param string $category_slug The slug of the category who's ID we want.
502
+ * @return (int | bool) Returns the integer ID of the category if found, or a
503
+ * boolean false if the category is not found.
504
+ *
505
+ * @todo Cache the results of this somewhere. It could save quite a few trips
506
+ * to the MySQL server.
507
+ *
508
+ * @author John Beales ( johnbeales.com )
509
+ */
510
+ function wpsc_category_id($category_slug = '') {
511
+ if(empty($category_slug))
512
+ $category_slug = get_query_var( 'wpsc_product_category' );
513
+ elseif(array_key_exists('wpsc_product_category', $_GET))
514
+ $category_slug = $_GET['wpsc_product_category'];
515
+
516
+ if(!empty($category_slug)) {
517
+ $category = get_term_by('slug', $category_slug, 'wpsc_product_category');
518
+ if(!empty($category->term_id)){
519
+ return $category->term_id;
520
+ } else {
521
+ return false;
522
+ }
523
+ } else {
524
+ return false;
525
+ }
526
+ }
527
+
528
+
529
+ /**
530
+ * wpsc_category_image function, Gets the category image or returns false
531
+ * @param integer category ID, can be 0
532
+ * @return string url to the category image
533
+ */
534
+ function wpsc_category_image($category_id = null) {
535
+ if($category_id < 1)
536
+ $category_id = wpsc_category_id();
537
+ $category_image = wpsc_get_categorymeta($category_id, 'image');
538
+ $category_path = WPSC_CATEGORY_DIR.basename($category_image);
539
+ $category_url = WPSC_CATEGORY_URL.basename($category_image);
540
+ if(file_exists($category_path) && is_file($category_path))
541
+ return $category_url;
542
+ return false;
543
+ }
544
+
545
+
546
+ /**
547
+ * wpsc_category_description function, Gets the category description
548
+ * @param integer category ID, can be 0
549
+ * @return string category description
550
+ */
551
+ function wpsc_category_description($category_id = null) {
552
+ if($category_id < 1)
553
+ $category_id = wpsc_category_id();
554
+ $category = get_term_by('id', $category_id, 'wpsc_product_category');
555
+ return $category->description;
556
+ }
557
+
558
+ function wpsc_category_name($category_id = null) {
559
+ if($category_id < 1)
560
+ $category_id = wpsc_category_id();
561
+ $category = get_term_by('id', $category_id, 'wpsc_product_category');
562
+ return $category->name;
563
+ }
564
+
565
+ function nzshpcrt_display_categories_groups() {
566
+ global $wpdb;
567
+
568
+ return $output;
569
+ }
570
+
571
+ /** wpsc list subcategories function
572
+ used to get an array of all the subcategories of a category.
573
+ */
574
+ function wpsc_list_subcategories($category_id = null) {
575
+ global $wpdb,$category_data;
576
+
577
+ $category_list = $wpdb->get_col( $wpdb->prepare( "SELECT `id` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `category_parent` = %d", $category_id ) );
578
+
579
+ if($category_list != null) {
580
+ foreach($category_list as $subcategory_id) {
581
+ $category_list = array_merge((array)$category_list, (array)wpsc_list_subcategories($subcategory_id));
582
+ }
583
+ }
584
+ return $category_list;
585
+ }
586
+
587
+ /**
588
+ * wpsc_show_category_thumbnails function
589
+ * @return bool - whether to show category thumbnails or not
590
+ */
591
+ function wpsc_show_category_thumbnails(){
592
+ if(get_option('show_category_thumbnails') && wpsc_category_image())
593
+ return true;
594
+ else
595
+ return false;
596
+ }
597
+
598
+ /**
599
+ * wpsc_show_category_description function
600
+ * @return bool - whether to show category description or not
601
+ */
602
+ function wpsc_show_category_description(){
603
+ return get_option('wpsc_category_description');
604
+ }
605
+
606
+ /**
607
+ * wpsc buy now button code products function
608
+ * Sorry about the ugly code, this is just to get the functionality back, buy now will soon be overhauled, and this function will then be completely different
609
+ * @return string - html displaying one or more products
610
+ */
611
+ function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) {
612
+
613
+ $product_id = absint($product_id);
614
+
615
+ $product = get_post( $product_id );
616
+ $supported_gateways = array( 'wpsc_merchant_paypal_standard', 'paypal_multiple' );
617
+ $selected_gateways = get_option( 'custom_gateway_options' );
618
+
619
+ if ( $replaced_shortcode )
620
+ ob_start();
621
+
622
+ if ( in_array( 'wpsc_merchant_paypal_standard', (array) $selected_gateways ) ) {
623
+ if ( $product_id > 0 ) {
624
+
625
+ $post_meta = get_post_meta( $product_id, '_wpsc_product_metadata', true );
626
+ $shipping = isset( $post_meta['shipping'] ) ? $post_meta['shipping']['local'] : '';
627
+ $price = get_post_meta( $product_id, '_wpsc_price', true );
628
+ $special_price = get_post_meta( $product_id, '_wpsc_special_price', true );
629
+
630
+ if ( $special_price )
631
+ $price = $special_price;
632
+
633
+ if ( wpsc_uses_shipping ( ) ) {
634
+ $handling = get_option( 'base_local_shipping' );
635
+ } else {
636
+ $handling = $shipping;
637
+ }
638
+
639
+ $has_variants = wpsc_product_has_variations( $product_id );
640
+
641
+ $src = apply_filters( 'wpsc_buy_now_button_src', _x( 'https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc' ) );
642
+ $classes = apply_filters( 'wpsc_buy_now_button_class', "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}" );
643
+
644
+ $button_html = sprintf( '<input%1$s class="wpsc-buy-now-button wpsc-buy-now-button-%2$s" type="image" name="submit" border="0" src="%3$s" alt="%4$s" />',
645
+ disabled( $has_variants, true, false ),
646
+ esc_attr( $product_id ),
647
+ esc_url( $src ),
648
+ esc_attr__( 'PayPal - The safer, easier way to pay online', 'wpsc' )
649
+ );
650
+
651
+ $button_html = apply_filters( 'wpsc_buy_now_button_html', $button_html, $product_id );
652
+ ?>
653
+ <form class="<?php echo esc_attr( sanitize_html_class( $classes, '' ) ); ?>" id="buy-now-product_<?php echo $product_id; ?>" target="paypal" action="<?php echo esc_url( home_url() ); ?>" method="post">
654
+ <input type="hidden" name="wpsc_buy_now_callback" value="1" />
655
+ <input type="hidden" name="product_id" value="<?php echo esc_attr( $product_id ); ?>" />
656
+ <?php
657
+ if ( $has_variants ) :
658
+ // grab the variation form fields here
659
+ $wpsc_variations = new wpsc_variations( $product_id );
660
+ while ( wpsc_have_variation_groups() ) : wpsc_the_variation_group();
661
+ printf('<input type="hidden" class="variation-value" name="variation[%1$d]" id="%2$s" value="0"/>', wpsc_vargrp_id(), wpsc_vargrp_form_id() );
662
+ endwhile;
663
+ endif; /* END wpsc_product_has_variations */
664
+ ?>
665
+ <?php if ( get_option( 'multi_add' ) ) : ?>
666
+ <label for="quantity"><?php esc_html_e( 'Quantity', 'wpsc' ); ?></label>
667
+ <input type="text" size="4" id="quantity" name="quantity" value="" /><br />
668
+ <?php else: ?>
669
+ <input type="hidden" name="quantity" value="1" />
670
+ <?php endif ?>
671
+ <?php echo $button_html; ?>
672
+ <img alt='' border='0' width='1' height='1' src='<?php echo esc_url( _x( 'https://www.paypal.com/en_US/i/scr/pixel.gif', 'PayPal Pixel', 'wpsc' ) ); ?>' />
673
+ </form>
674
+ <?php
675
+ }
676
+ }
677
+ if ( $replaced_shortcode )
678
+ return ob_get_clean();
679
+ }
680
+
681
+ /**
682
+ * Displays products that were bought along with the product defined by $product_id.
683
+ * This functionality will be deprecated and be provided by a plugin in a future version.
684
+ */
685
+ function wpsc_also_bought( $product_id ) {
686
+ global $wpdb;
687
+
688
+ if ( get_option( 'wpsc_also_bought' ) == 0 ) {
689
+ return '';
690
+ }
691
+
692
+ // To be made customiseable in a future release
693
+ $also_bought_limit = 3;
694
+ $element_widths = 96;
695
+ $image_display_height = 96;
696
+ $image_display_width = 96;
697
+
698
+ // Filter will be used by a plugin to provide 'Also Bought' functionality when this is deprecated from core.
699
+ // Filter is currently private and should not be used by plugin/theme devs as it may only be temporary.
700
+ $output = apply_filters( '_wpsc_also_bought', '', $product_id );
701
+ if ( ! empty( $output ) ) {
702
+ return $output;
703
+ }
704
+
705
+ // If above filter returns output then the following is ignore and can be deprecated in future.
706
+ $also_bought = $wpdb->get_results( $wpdb->prepare( "SELECT `" . $wpdb->posts . "`.* FROM `" . WPSC_TABLE_ALSO_BOUGHT . "`, `" . $wpdb->posts . "` WHERE `selected_product`= %d AND `" . WPSC_TABLE_ALSO_BOUGHT . "`.`associated_product` = `" . $wpdb->posts . "`.`id` AND `" . $wpdb->posts . "`.`post_status` IN('publish','protected') ORDER BY `" . WPSC_TABLE_ALSO_BOUGHT . "`.`quantity` DESC LIMIT $also_bought_limit", $product_id ), ARRAY_A );
707
+ if ( is_array( $also_bought ) && count( $also_bought ) > 0 ) {
708
+ $output .= '<h2 class="prodtitles wpsc_also_bought">' . __( 'People who bought this item also bought', 'wpsc' ) . '</h2>';
709
+ $output .= '<div class="wpsc_also_bought">';
710
+ foreach ( $also_bought as $also_bought_data ) {
711
+ $output .= '<div class="wpsc_also_bought_item" style="width: ' . $element_widths . 'px;">';
712
+ if ( get_option( 'show_thumbnails' ) == 1 ) {
713
+ $image_path = wpsc_the_product_thumbnail( $image_display_width, $image_display_height, $also_bought_data['ID'] );
714
+ if ( $image_path ) {
715
+ $output .= '<a href="' . esc_attr( get_permalink( $also_bought_data['ID'] ) ) . '" class="preview_link" rel="' . esc_attr( sanitize_html_class( get_the_title( $also_bought_data['ID'] ) ) ) . '">';
716
+ $output .= '<img src="' . esc_attr( $image_path ) . '" id="product_image_' . $also_bought_data['ID'] . '" class="product_image" />';
717
+ $output .= '</a>';
718
+ } else {
719
+ if ( get_option( 'product_image_width' ) != '' ) {
720
+ $width_and_height = 'width="' . $image_display_height . '" height="' . $image_display_height . '" ';
721
+ } else {
722
+ $width_and_height = '';
723
+ }
724
+ $output .= '<img src="' . WPSC_CORE_THEME_URL . '/wpsc-images/noimage.png" title="' . esc_attr( get_the_title( $also_bought_data['ID'] ) ) . '" alt="' . esc_attr( get_the_title( $also_bought_data['ID'] ) ) . '" id="product_image_' . $also_bought_data['ID'] . '" class="product_image" ' . $width_and_height . '/>';
725
+ }
726
+ }
727
+
728
+ $output .= '<a class="wpsc_product_name" href="' . get_permalink( $also_bought_data['ID'] ) . '">' . get_the_title( $also_bought_data['ID'] ) . '</a>';
729
+ if ( ! wpsc_product_is_donation( $also_bought_data['ID'] ) ) {
730
+ // Ideally use the wpsc_the_product_price_display() function here but needs some tweaking
731
+ $price = get_product_meta( $also_bought_data['ID'], 'price', true );
732
+ $special_price = get_product_meta( $also_bought_data['ID'], 'special_price', true );
733
+ if ( ! empty( $special_price ) ) {
734
+ $output .= '<span style="text-decoration: line-through;">' . wpsc_currency_display( $price ) . '</span>';
735
+ $output .= wpsc_currency_display( $special_price );
736
+ } else {
737
+ $output .= wpsc_currency_display( $price );
738
+ }
739
+ }
740
+ $output .= '</div>';
741
+ }
742
+ $output .= '</div>';
743
+ $output .= '<br clear="all" />';
744
+ }
745
+ return $output;
746
+ }
747
+
748
+ /**
749
+ * Get the URL of the loading animation image.
750
+ * Can be filtered using the wpsc_loading_animation_url filter.
751
+ */
752
+ function wpsc_loading_animation_url() {
753
+ return apply_filters( 'wpsc_loading_animation_url', WPSC_CORE_THEME_URL . 'wpsc-images/indicator.gif' );
754
+ }
755
+
756
+ function fancy_notifications() {
757
+ return wpsc_fancy_notifications( true );
758
+ }
759
+ function wpsc_fancy_notifications( $return = false ) {
760
+ static $already_output = false;
761
+
762
+ if ( $already_output )
763
+ return '';
764
+
765
+ $output = "";
766
+ if ( get_option( 'fancy_notifications' ) == 1 ) {
767
+ $output = "";
768
+ $output .= "<div id='fancy_notification'>\n\r";
769
+ $output .= " <div id='loading_animation'>\n\r";
770
+ $output .= '<img id="fancy_notificationimage" title="' . esc_attr__( 'Loading', 'wpsc' ) . '" alt="' . esc_attr__( 'Loading', 'wpsc' ) . '" src="' . wpsc_loading_animation_url() . '" />' . __( 'Updating', 'wpsc' ) . "...\n\r";
771
+ $output .= " </div>\n\r";
772
+ $output .= " <div id='fancy_notification_content'>\n\r";
773
+ $output .= " </div>\n\r";
774
+ $output .= "</div>\n\r";
775
+ }
776
+
777
+ $already_output = true;
778
+
779
+ if ( $return )
780
+ return $output;
781
+ else
782
+ echo $output;
783
+ }
784
+
785
+ function fancy_notification_content( $cart_messages ) {
786
+ $siteurl = get_option( 'siteurl' );
787
+ $output = '';
788
+ foreach ( (array)$cart_messages as $cart_message ) {
789
+ $output .= "<span>" . $cart_message . "</span><br />";
790
+ }
791
+ $output .= "<a href='" . get_option( 'shopping_cart_url' ) . "' class='go_to_checkout'>" . __( 'Go to Checkout', 'wpsc' ) . "</a>";
792
+ $output .= "<a href='#' onclick='jQuery(\"#fancy_notification\").css(\"display\", \"none\"); return false;' class='continue_shopping'>" . __( 'Continue Shopping', 'wpsc' ) . "</a>";
793
+ return $output;
794
+ }
795
+
796
+ /*
797
+ * wpsc product url function, gets the URL of a product,
798
+ * Deprecated, all parameters past the first unused. use get_permalink
799
+ */
800
+
801
+ function wpsc_product_url( $product_id, $category_id = null, $escape = true ) {
802
+ $post = get_post($product_id);
803
+ if ( isset($post->post_parent) && $post->post_parent > 0) {
804
+ return get_permalink($post->post_parent);
805
+ } else {
806
+ return get_permalink($product_id);
807
+ }
808
+ }
809
+
810
+ function external_link( $product_id ) {
811
+ $link = get_product_meta( $product_id, 'external_link', true );
812
+ if ( !stristr( $link, 'http://' ) ) {
813
+ $link = 'http://' . $link;
814
+ }
815
+ $target = wpsc_product_external_link_target( $product_id );
816
+ $output .= "<input class='wpsc_buy_button' type='button' value='" . wpsc_product_external_link_text( $product_id, __( 'Buy Now', 'wpsc' ) ) . "' onclick='return gotoexternallink(\"$link\", \"$target\")'>";
817
+ return $output;
818
+ }
819
+
820
+ /**
821
+ * wpsc_refresh_page_urls
822
+ *
823
+ * Refresh page urls when pages are updated
824
+ *
825
+ * @param int $post_id
826
+ * @param object $post
827
+ * @uses wpsc_update_permalink_slugs()
828
+ * @return int $post_id
829
+ */
830
+ function wpsc_refresh_page_urls( $post_id, $post ) {
831
+
832
+ if ( ! current_user_can( 'manage_options' ) )
833
+ return;
834
+
835
+ if ( 'page' != $post->post_type )
836
+ return;
837
+
838
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
839
+ return;
840
+
841
+ if ( ! in_array( $post->post_status, array( 'publish', 'private' ) ) )
842
+ return;
843
+
844
+ wpsc_update_permalink_slugs();
845
+
846
+ return $post_id;
847
+ }
848
+
849
+ function wpsc_replace_wp_title( $input ) {
850
+ global $wpdb, $wp_query;
851
+ $output = wpsc_obtain_the_title();
852
+ if ( $output != null ) {
853
+ return $output;
854
+ }
855
+ return $input;
856
+ }
857
+
858
+ function wpsc_replace_bloginfo_title( $input, $show ) {
859
+ global $wpdb, $wp_query;
860
+ if ( $show == 'description' ) {
861
+ $output = wpsc_obtain_the_title();
862
+ if ( $output != null ) {
863
+ return $output;
864
+ }
865
+ }
866
+ return $input;
867
+ }
868
+
wpsc-components/theme-engine-v1/helpers/query.php ADDED
@@ -0,0 +1,612 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // switch $wp_query and $wpsc_query at the beginning and the end of wp_nav_menu()
3
+ add_action( 'pre_get_posts', '_wpsc_pre_get_posts_reset_taxonomy_globals', 1 );
4
+ add_action( 'template_redirect', 'wpsc_start_the_query', 8 );
5
+ add_action( 'wp', 'wpsc_force_ssl' );
6
+ if ( is_ssl() ) {
7
+ add_filter( 'option_product_list_url', 'wpsc_add_https_to_page_url_options' );
8
+ add_filter( 'option_shopping_cart_url', 'wpsc_add_https_to_page_url_options' );
9
+ add_filter( 'option_transact_url', 'wpsc_add_https_to_page_url_options' );
10
+ add_filter( 'option_user_account_url', 'wpsc_add_https_to_page_url_options' );
11
+ }
12
+
13
+
14
+ add_filter( 'wp_nav_menu_args', 'wpsc_switch_the_query', 99 );
15
+ add_filter( 'request', 'wpsc_filter_query_request' );
16
+ add_filter( 'pre_get_posts', 'wpsc_split_the_query', 8 );
17
+ add_filter( 'parse_query', 'wpsc_mark_product_query', 12 );
18
+ add_filter( 'query_vars', 'wpsc_query_vars' );
19
+ if ( get_option( 'product_category_hierarchical_url' ) )
20
+ add_filter( 'request', 'wpsc_filter_request' );
21
+
22
+ /**
23
+ * Fixes for some inconsistencies about $wp_query when viewing WPEC pages.
24
+ *
25
+ * Causes the following URLs to work (with pagination enabled):
26
+ *
27
+ * /products-page/ (product listing)
28
+ * /products-page/car-audio/ (existing product category)
29
+ * /products-page/car-audio/page/2/ (existing product category, page 2)
30
+ * /products-page/page/2/ (product listing, page 2)
31
+ * /products-page/checkout/ (existing built-in sub page)
32
+ * /products-page/anotherpage/ (another sub page that may exist)
33
+ *
34
+ * @param string $q Query String
35
+ */
36
+ function wpsc_filter_query_request( $args ) {
37
+ global $wpsc_page_titles;
38
+ if ( is_admin() )
39
+ return $args;
40
+
41
+ $is_sub_page = ! empty( $args['wpsc_product_category'] )
42
+ && 'page' != $args['wpsc_product_category']
43
+ && ! term_exists( $args['wpsc_product_category'], 'wpsc_product_category' );
44
+
45
+ // Make sure no 404 error is thrown for any sub pages of products-page
46
+ if ( $is_sub_page ) {
47
+ // Probably requesting a page that is a sub page of products page
48
+ $pagename = "{$wpsc_page_titles['products']}/{$args['wpsc_product_category']}";
49
+ if ( isset($args['name']) ) {
50
+ $pagename .= "/{$args['name']}";
51
+ }
52
+ $args = array();
53
+ $args['pagename'] = $pagename;
54
+ }
55
+
56
+ // When product page is set to display all products or a category, and pagination is enabled, $wp_query is messed up
57
+ // and is_home() is true. This fixes that.
58
+ $needs_pagination_fix = isset( $args['post_type'] )
59
+ && ! empty( $args['wpsc_product_category'] )
60
+ && 'wpsc-product' == $args['post_type']
61
+ && ! empty( $args['wpsc-product'] )
62
+ && 'page' == $args['wpsc_product_category'];
63
+ if ( $needs_pagination_fix ) {
64
+ $default_category = get_option( 'wpsc_default_category' );
65
+ if ( $default_category == 'all' || $default_category != 'list' ) {
66
+ $page = $args['wpsc-product'];
67
+ $args = array();
68
+ $args['pagename'] = "{$wpsc_page_titles['products']}";
69
+ $args['page'] = $page;
70
+ }
71
+ }
72
+ return $args;
73
+ }
74
+
75
+ function _wpsc_menu_exists( $args ) {
76
+ $args = (object) $args;
77
+ // Get the nav menu based on the requested menu
78
+ $menu = wp_get_nav_menu_object( $args->menu );
79
+
80
+ // Get the nav menu based on the theme_location
81
+ if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) )
82
+ $menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
83
+
84
+ // get the first menu that has items if we still can't find a menu
85
+ if ( ! $menu && ! $args->theme_location ) {
86
+ $menus = wp_get_nav_menus();
87
+ foreach ( $menus as $menu_maybe ) {
88
+ if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id ) ) {
89
+ $menu = $menu_maybe;
90
+ break;
91
+ }
92
+ }
93
+ }
94
+
95
+ // If the menu exists, get its items.
96
+ if ( $menu && ! is_wp_error( $menu ) && ! isset( $menu_items ) )
97
+ $menu_items = wp_get_nav_menu_items( $menu->term_id );
98
+
99
+ // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists
100
+ if ( ( ! $menu || is_wp_error( $menu ) || ( isset( $menu_items ) && empty( $menu_items ) && ! $args->theme_location ) ) )
101
+ return false;
102
+
103
+ // If no fallback function was specified and the menu doesn't exists, bail.
104
+ if ( ! $menu || is_wp_error( $menu ) || empty( $menu_items ) )
105
+ return false;
106
+
107
+ return (bool) $menu;
108
+ }
109
+
110
+ function _wpsc_switch_the_query( $stuff = '' ) {
111
+ global $wp_query, $wpsc_query;
112
+ list( $wp_query, $wpsc_query ) = array( $wpsc_query, $wp_query );
113
+ return $stuff;
114
+ }
115
+
116
+ /**
117
+ * Switch $wp_query and $wpsc_query when outputting the navigation menu, but only if we're on a product
118
+ * category page.
119
+ *
120
+ * We need to do this because the function _wp_menu_item_classes_by_context(), which generates classes
121
+ * for menu items, depends on $wp_query. As a result, without this fix, when viewing a product category
122
+ * page, the corresponding product category menu item will not be highlighted.
123
+ *
124
+ * Because there are no action hooks in wp_nav_menu(), we have to use two filters that are applied at
125
+ * the beginning and the end of the function.
126
+ *
127
+ * @param mixed $stuff
128
+ * @return mixed
129
+ */
130
+ function wpsc_switch_the_query( $args ) {
131
+ global $wp_query, $wpsc_query;
132
+ $qv = $wpsc_query->query_vars;
133
+ if ( ! empty( $qv['wpsc_product_category'] ) && ! empty( $qv['taxonomy'] ) && ! empty( $qv['term'] ) && ! is_single() && _wpsc_menu_exists( $args ) ) {
134
+ _wpsc_switch_the_query();
135
+ add_filter( 'wp_nav_menu', '_wpsc_switch_the_query', 99 );
136
+ }
137
+ return $args;
138
+ }
139
+
140
+ function _wpsc_pre_get_posts_reset_taxonomy_globals( $query ) {
141
+ global $wp_the_query;
142
+
143
+ if ( is_admin() || $query !== $wp_the_query )
144
+ return;
145
+
146
+ if ( ! $query->get( 'page' ) && ! $query->get( 'paged' ) )
147
+ return;
148
+
149
+ if ( ! get_option( 'use_pagination' ) )
150
+ return;
151
+
152
+ if ( ! is_page( wpsc_get_the_post_id_by_shortcode( '[productspage]' ) ) && ! $query->get( 'wpsc_product_category' ) )
153
+ return;
154
+
155
+ $query->set( 'posts_per_page', get_option( 'wpsc_products_per_page' ) );
156
+
157
+ $post_type_object = get_post_type_object( 'wpsc-product' );
158
+
159
+ if ( current_user_can( $post_type_object->cap->edit_posts ) )
160
+ $query->set( 'post_status', 'private,draft,pending,publish' );
161
+ else
162
+ $query->set( 'post_status', 'publish' );
163
+ }
164
+
165
+ /**
166
+ * wpsc_start_the_query
167
+ */
168
+ function wpsc_start_the_query() {
169
+ global $wpsc_page_titles, $wp_query, $wpsc_query, $wpsc_query_vars;
170
+
171
+ $is_404 = false;
172
+ if ( null == $wpsc_query ) {
173
+ if( ( $wp_query->is_404 && !empty($wp_query->query_vars['paged']) ) || (isset( $wp_query->query['pagename']) && strpos( $wp_query->query['pagename'] , $wpsc_page_titles['products'] ) !== false ) && !isset($wp_query->post)){
174
+ global $post;
175
+ $is_404 = true;
176
+ if( !isset( $wp_query->query_vars['wpsc_product_category'] ) && ! isset( $wp_query->query_vars['product_tag'] ) )
177
+ $wp_query = new WP_Query('post_type=wpsc-product&name='.$wp_query->query_vars['name']);
178
+
179
+ if(isset($wp_query->post->ID))
180
+ $post = $wp_query->post;
181
+ else
182
+ $wpsc_query_vars['wpsc_product_category'] = $wp_query->query_vars['name'];
183
+ }
184
+ if ( count( $wpsc_query_vars ) <= 1 ) {
185
+ $post_type_object = get_post_type_object( 'wpsc-product' );
186
+ $wpsc_query_vars = array(
187
+ 'post_status' => apply_filters( 'wpsc_product_display_status', array( 'publish' ) ),
188
+ 'post_parent' => 0,
189
+ 'order' => apply_filters( 'wpsc_product_order', get_option( 'wpsc_product_order', 'ASC' ) )
190
+ );
191
+ if($wp_query->query_vars['preview'])
192
+ $wpsc_query_vars['post_status'] = 'any';
193
+
194
+ if( isset( $_GET['product_order'] ) )
195
+ $wpsc_query_vars['order'] = $_GET['product_order'];
196
+
197
+ if(isset($wp_query->query_vars['product_tag'])){
198
+ $wpsc_query_vars['product_tag'] = $wp_query->query_vars['product_tag'];
199
+ $wpsc_query_vars['taxonomy'] = get_query_var( 'taxonomy' );
200
+ $wpsc_query_vars['term'] = get_query_var( 'term' );
201
+ }elseif( isset($wp_query->query_vars['wpsc_product_category']) ){
202
+ $wpsc_query_vars['wpsc_product_category'] = $wp_query->query_vars['wpsc_product_category'];
203
+ $wpsc_query_vars['taxonomy'] = get_query_var( 'taxonomy' );
204
+ $wpsc_query_vars['term'] = get_query_var( 'term' );
205
+ }else{
206
+ $wpsc_query_vars['post_type'] = 'wpsc-product';
207
+ $wpsc_query_vars['pagename'] = wpsc_get_page_slug( '[productspage]' );
208
+ }
209
+ if(1 == get_option('use_pagination')){
210
+ $wpsc_query_vars['nopaging'] = false;
211
+
212
+ $wpsc_query_vars['posts_per_page'] = get_option('wpsc_products_per_page');
213
+
214
+ $wpsc_query_vars['paged'] = get_query_var('paged');
215
+ if(isset($wpsc_query_vars['paged']) && empty($wpsc_query_vars['paged'])){
216
+ $wpsc_query_vars['paged'] = get_query_var('page');
217
+
218
+ }
219
+
220
+ }
221
+
222
+ $orderby = ( isset( $_GET['product_order'] ) ) ? 'title' : null;
223
+ $wpsc_query_vars = array_merge( $wpsc_query_vars, wpsc_product_sort_order_query_vars($orderby) );
224
+
225
+ add_filter( 'pre_get_posts', 'wpsc_generate_product_query', 11 );
226
+
227
+ $wpsc_query = new WP_Query( $wpsc_query_vars );
228
+
229
+ //for 3.1 :|
230
+ if(empty($wpsc_query->posts) && isset($wpsc_query->tax_query) && isset($wp_query->query_vars['wpsc_product_category'])){
231
+ $wpsc_query_vars = array();
232
+ $wpsc_query_vars['wpsc_product_category'] = $wp_query->query_vars['wpsc_product_category'];
233
+ if(1 == get_option('use_pagination')){
234
+ $wpsc_query_vars['posts_per_page'] = get_option('wpsc_products_per_page');
235
+ $wpsc_query_vars['paged'] = get_query_var('paged');
236
+ if(empty($wpsc_query_vars['paged']))
237
+ $wpsc_query_vars['paged'] = get_query_var('page');
238
+ }
239
+ $wpsc_query = new WP_Query( $wpsc_query_vars );
240
+
241
+ }
242
+ }
243
+ }
244
+
245
+ if( $is_404 || ( ( isset($wpsc_query->post_count) && $wpsc_query->post_count == 0 ) && isset($wpsc_query_vars['wpsc_product_category'] ) )){
246
+
247
+ $args = array_merge($wp_query->query, array('posts_per_page' => get_option('wpsc_products_per_page')));
248
+ $wp_query = new WP_Query($args);
249
+
250
+ if( empty( $wp_query->posts ) ){
251
+ $product_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
252
+ $wp_query = new WP_Query( 'page_id='.$product_page_id);
253
+ }
254
+ }
255
+ if ( isset( $wp_query->post->ID ) )
256
+ $post_id = $wp_query->post->ID;
257
+ else
258
+ $post_id = 0;
259
+
260
+ if ( get_permalink( $post_id ) == get_option( 'shopping_cart_url' ) )
261
+ $_SESSION['wpsc_has_been_to_checkout'] = true;
262
+ }
263
+
264
+ /**
265
+ * Returns page slug that corresponds to a given WPEC-specific shortcode.
266
+ *
267
+ * @since 3.8.10
268
+ *
269
+ * @uses wpsc_get_the_post_id_by_shortcode() Gets page ID of shortcode.
270
+ * @uses get_post_field() Returns post name of page ID.
271
+ *
272
+ * @param string $shortcode Shortcode of WPEC-specific page, e.g. '[productspage]''
273
+ * @return string Post slug
274
+ */
275
+ function wpsc_get_page_slug( $shortcode ) {
276
+ $id = wpsc_get_the_post_id_by_shortcode( $shortcode );
277
+ return get_post_field( 'post_name', $id );
278
+ }
279
+
280
+ /**
281
+ * Obtain the necessary product sort order query variables based on the specified product sort order.
282
+ * If no sort order is specified, the sort order configured in Dashboard -> Settings -> Store -> Presentation -> 'Sort Product By' is used.
283
+ *
284
+ * @param string $orderby optional product sort order
285
+ * @return array Array of query variables
286
+ */
287
+ function wpsc_product_sort_order_query_vars( $orderby = null ) {
288
+ if ( is_null($orderby) )
289
+ $orderby = get_option( 'wpsc_sort_by' );
290
+
291
+ $query_vars = array();
292
+
293
+ switch ( $orderby ) {
294
+
295
+ case "dragndrop":
296
+ $query_vars["orderby"] = 'menu_order';
297
+ break;
298
+
299
+ case "name":
300
+ $query_vars["orderby"] = 'title';
301
+ break;
302
+
303
+ //This only works in WP 3.0.
304
+ case "price":
305
+ add_filter( 'posts_join', 'wpsc_add_meta_table' );
306
+ add_filter( 'posts_where', 'wpsc_add_meta_table_where' );
307
+ $query_vars["meta_key"] = '_wpsc_price';
308
+ $query_vars["orderby"] = 'meta_value_num';
309
+ break;
310
+
311
+ case "id":
312
+ $query_vars["orderby"] = 'ID';
313
+ break;
314
+ default:
315
+ // Allow other WordPress 'ordery' values as defined in http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
316
+ $query_vars["orderby"] = $orderby;
317
+ break;
318
+ }
319
+ return $query_vars;
320
+ }
321
+
322
+ /**
323
+ * wpsc_query_vars function.
324
+ * adds in the post_type and wpsc_item query vars
325
+ *
326
+ * @since 3.8
327
+ * @access public
328
+ * @param mixed $vars
329
+ * @return void
330
+ */
331
+ function wpsc_query_vars( $vars ) {
332
+ // post_type is used to specify that we are looking for products
333
+ $vars[] = "post_type";
334
+ // wpsc_item is used to find items that could be either a product or a product category, it defaults to category, then tries products
335
+ $vars[] = "wpsc_item";
336
+ return $vars;
337
+ }
338
+
339
+ /**
340
+ * wpsc_query_modifier function.
341
+ *
342
+ * @since 3.8
343
+ * @access public
344
+ * @param object - reference to $wp_query
345
+ * @return $query
346
+ */
347
+ function wpsc_split_the_query( $query ) {
348
+ global $wpsc_page_titles, $wpsc_query, $wpsc_query_vars;
349
+ // These values are to be dynamically defined
350
+ $products_page = $wpsc_page_titles['products'];
351
+ $checkout_page = $wpsc_page_titles['checkout'];
352
+ $userlog_page = $wpsc_page_titles['userlog'];
353
+ $transaction_results_page = $wpsc_page_titles['transaction_results'];
354
+
355
+ // otherwise, check if we are looking at a product, if so, duplicate the query and swap the old one out for a products page request
356
+ // JS - 6.4.1020 - Added is_admin condition, as the products condition broke categories in backend
357
+ if ( !empty($query->query_vars['pagename']) && ($query->query_vars['pagename'] == $products_page) || isset( $query->query_vars['products'] ) && !is_admin() ) {
358
+ // store a copy of the wordpress query
359
+ $wpsc_query_data = $query->query;
360
+
361
+ // wipe and replace the query vars
362
+ $query->query = array();
363
+ $query->query['pagename'] = "$products_page";
364
+ $query->query_vars['pagename'] = "$products_page";
365
+ $query->query_vars['name'] = '';
366
+ $query->query_vars['post_type'] = '';
367
+
368
+ $query->queried_object = get_page_by_path( $query->query['pagename'] );
369
+
370
+ if ( !empty( $query->queried_object ) )
371
+ $query->queried_object_id = (int)$query->queried_object->ID;
372
+ else
373
+ unset( $query->queried_object );
374
+
375
+ unset( $query->query_vars['products'] );
376
+ unset( $query->query_vars['name'] );
377
+ unset( $query->query_vars['taxonomy'] );
378
+ unset( $query->query_vars['term'] );
379
+ unset( $query->query_vars['wpsc_item'] );
380
+
381
+ $query->is_singular = true;
382
+ $query->is_page = true;
383
+ $query->is_tax = false;
384
+ $query->is_archive = false;
385
+ $query->is_single = false;
386
+
387
+ if ( ($wpsc_query_vars == null ) ) {
388
+ unset( $wpsc_query_data['pagename'] );
389
+ $wpsc_query_vars = $wpsc_query_data;
390
+ }
391
+ }
392
+
393
+ add_filter( 'redirect_canonical', 'wpsc_break_canonical_redirects', 10, 2 );
394
+ remove_filter( 'pre_get_posts', 'wpsc_split_the_query', 8 );
395
+ }
396
+
397
+ /**
398
+ * wpsc_generate_product_query function.
399
+ *
400
+ * @access public
401
+ * @param mixed $query
402
+ * @return void
403
+ */
404
+ function wpsc_generate_product_query( $query ) {
405
+ global $wp_query;
406
+ $prod_page = wpsc_get_the_post_id_by_shortcode('[productspage]');
407
+ $prod_page = get_post($prod_page);
408
+ remove_filter( 'pre_get_posts', 'wpsc_generate_product_query', 11 );
409
+ $query->query_vars['taxonomy'] = null;
410
+ $query->query_vars['term'] = null;
411
+
412
+ // default product selection
413
+ if ( $query->query_vars['pagename'] != '' ) {
414
+ $query->query_vars['post_type'] = 'wpsc-product';
415
+ $query->query_vars['pagename'] = '';
416
+ $query->is_page = false;
417
+ $query->is_tax = false;
418
+ $query->is_archive = true;
419
+ $query->is_singular = false;
420
+ $query->is_single = false;
421
+ }
422
+
423
+ // If wpsc_item is not null, we are looking for a product or a product category, check for category
424
+ if ( isset( $query->query_vars['wpsc_item'] ) && ($query->query_vars['wpsc_item'] != '') ) {
425
+ $test_term = get_term_by( 'slug', $query->query_vars['wpsc_item'], 'wpsc_product_category' );
426
+ if ( $test_term->slug == $query->query_vars['wpsc_item'] ) {
427
+ // if category exists (slug matches slug), set products to value of wpsc_item
428
+ $query->query_vars['products'] = $query->query_vars['wpsc_item'];
429
+ } else {
430
+ // otherwise set name to value of wpsc_item
431
+ $query->query_vars['name'] = $query->query_vars['wpsc_item'];
432
+ }
433
+ }
434
+
435
+ if ( isset( $query->query_vars['products'] ) && ($query->query_vars['products'] != null) && ($query->query_vars['name'] != null) ) {
436
+ unset( $query->query_vars['taxonomy'] );
437
+ unset( $query->query_vars['term'] );
438
+ $query->query_vars['post_type'] = 'wpsc-product';
439
+ $query->is_tax = false;
440
+ $query->is_archive = true;
441
+ $query->is_singular = false;
442
+ $query->is_single = false;
443
+ }
444
+ if( isset($wp_query->query_vars['wpsc_product_category']) && !isset($wp_query->query_vars['wpsc-product'])){
445
+ $query->query_vars['wpsc_product_category'] = $wp_query->query_vars['wpsc_product_category'];
446
+ $query->query_vars['taxonomy'] = $wp_query->query_vars['taxonomy'];
447
+ $query->query_vars['term'] = $wp_query->query_vars['term'];
448
+ }elseif( '' != ($default_category = get_option('wpsc_default_category')) && !isset($wp_query->query_vars['wpsc-product'])){
449
+ $default_term = get_term($default_category,'wpsc_product_category');
450
+ if(!empty($default_term) && empty($wp_query->query_vars['category_name'])){
451
+ $query->query_vars['taxonomy'] = 'wpsc_product_category';
452
+ $query->query_vars['term'] = $default_term->slug;
453
+ $query->is_tax = true;
454
+ }elseif(isset($wp_query->query_vars['name']) && $wp_query->is_404 && $wp_query->query_vars['category_name'] != $prod_page->post_name){
455
+ unset( $query->query_vars['taxonomy'] );
456
+ unset( $query->query_vars['term'] );
457
+ $query->query_vars['wpsc-product'] = $wp_query->query_vars['name'];
458
+ $query->query_vars['name'] = $wp_query->query_vars['name'];
459
+
460
+ }else{
461
+ $query->is_tax = true;
462
+ $term = get_term_by('slug',$wp_query->query_vars['name'], 'wpsc_product_category' );
463
+ if(!empty($term)){
464
+ $query->query_vars['taxonomy'] = 'wpsc_product_category';
465
+ $query->query_vars['wpsc_product_category__in'] = array($term->term_taxonomy_id);
466
+ $query->query_vars['wpsc_product_category'] = $wp_query->query_vars['name'];
467
+ $query->query_vars['term'] = $wp_query->query_vars['name'];
468
+ }elseif(is_numeric($default_category)){
469
+ $query->query_vars['taxonomy'] = 'wpsc_product_category';
470
+ }else{
471
+ $query->is_tax = false;
472
+ }
473
+ }
474
+ }
475
+ //If Product Tag Taxonomy
476
+ if (isset($wp_query->query_vars['product_tag']) && $wp_query->query_vars['product_tag']){
477
+ $query->query_vars['product_tag'] = $wp_query->query_vars['product_tag'];
478
+ $query->query_vars['term'] = $wp_query->query_vars['term'];
479
+ $query->query_vars['taxonomy'] = 'product_tag';
480
+ $query->is_tax = true;
481
+ }
482
+ if(1 == get_option('use_pagination')){
483
+ $query->query_vars['posts_per_page'] = get_option('wpsc_products_per_page');
484
+ if( isset( $_GET['items_per_page'] ) ) {
485
+ if ( is_numeric( $_GET['items_per_page'] ) ) {
486
+ $query->query_vars['posts_per_page'] = (int) $_GET['items_per_page'];
487
+ } elseif ( $_GET['items_per_page'] == 'all' ) {
488
+ $query->query_vars['posts_per_page'] = -1;
489
+ $query->query_vars['nopaging'] = 1;
490
+ }
491
+ }
492
+ } else {
493
+ $query->query_vars['posts_per_page'] = -1;
494
+ $query->query_vars['nopaging'] = 1;
495
+ }
496
+ if ( $query->is_tax == true )
497
+ new wpsc_products_by_category( $query );
498
+ return $query;
499
+ }
500
+
501
+ function wpsc_mark_product_query( $query ) {
502
+
503
+ if ( isset( $query->query_vars['post_type'] ) && ($query->query_vars['post_type'] == 'wpsc-product') )
504
+ $query->is_product = true;
505
+
506
+ return $query;
507
+ }
508
+
509
+ /**
510
+ * add meta table where section for ordering by price
511
+ *
512
+ */
513
+ function wpsc_add_meta_table_where($where){
514
+ global $wpdb;
515
+
516
+ remove_filter( 'posts_where', 'wpsc_add_meta_table_where' );
517
+
518
+ return $where . ' AND ' . $wpdb->postmeta . '.meta_key = "_wpsc_price"';
519
+ }
520
+
521
+ /**
522
+ * add meta table join section for ordering by price
523
+ *
524
+ */
525
+ function wpsc_add_meta_table($join){
526
+ global $wpdb;
527
+ remove_filter( 'posts_join', 'wpsc_add_meta_table' );
528
+ if(strpos($join, "INNER JOIN ON (".$wpdb->posts.".ID = ".$wpdb->postmeta.".post_id)") !== false){
529
+ return ' JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts. '.ID = ' . $wpdb->postmeta . '.post_id';
530
+ }else{
531
+ return $join;
532
+ }
533
+ }
534
+
535
+ function wpsc_break_canonical_redirects( $redirect_url, $requested_url ) {
536
+ global $wp_query;
537
+
538
+ if ( ( isset( $wp_query->query_vars['products'] ) && ($wp_query->query_vars['products'] != '') ) || ( isset( $wp_query->query_vars['products'] ) && $wp_query->query_vars['products'] != 'wpsc_item') )
539
+ return false;
540
+
541
+ if ( stristr( $requested_url, $redirect_url ) )
542
+ return false;
543
+
544
+ return $redirect_url;
545
+ }
546
+
547
+ function wpsc_filter_request( $q ) {
548
+ if ( empty( $q['wpsc-product'] ) )
549
+ return $q;
550
+
551
+ $components = explode( '/', $q['wpsc-product'] );
552
+ $end_node = array_pop( $components );
553
+ $parent_node = array_pop( $components );
554
+
555
+ $posts = get_posts( array(
556
+ 'post_type' => 'wpsc-product',
557
+ 'name' => $end_node,
558
+ ) );
559
+
560
+ if ( ! empty( $posts ) ) {
561
+ $q['wpsc-product'] = $q['name'] = $end_node;
562
+ if ( !empty( $parent_node ) )
563
+ $q['wpsc_product_category'] = $parent_node;
564
+ } else {
565
+ $q['wpsc_product_category'] = $end_node;
566
+ unset( $q['name'] );
567
+ unset( $q['wpsc-product'] );
568
+ }
569
+ return $q;
570
+ }
571
+
572
+ /**
573
+ * if the user is on a checkout page, force SSL if that option is so set
574
+ */
575
+ function wpsc_force_ssl() {
576
+ global $wp_query;
577
+ if ( '1' == get_option( 'wpsc_force_ssl' ) &&
578
+ ! is_ssl() &&
579
+ ! empty ( $wp_query->post->post_content ) &&
580
+ false !== strpos( $wp_query->post->post_content, '[shoppingcart]' ) ) {
581
+ $sslurl = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
582
+ wp_redirect( $sslurl );
583
+ exit;
584
+ }
585
+ }
586
+
587
+ /**
588
+ * wpsc_add_https_to_page_url_options( $url )
589
+ *
590
+ * Forces SSL onto option URLs
591
+ *
592
+ * @param string $url
593
+ * @return string
594
+ */
595
+ function wpsc_add_https_to_page_url_options( $url ) {
596
+ return str_replace( 'http://', 'https://', $url );
597
+ }
598
+
599
+ /**
600
+ * Checks if current page is shopping cart, and it should be SSL, but is not.
601
+ * Used primarily for str_replacing links or content for https
602
+ *
603
+ * @since 3.8.8.1
604
+ * @deprecated 3.8.8.2
605
+ * @return boolean true if we're on the shopping cart page and should be ssl, false if not
606
+ */
607
+ function wpsc_is_ssl() {
608
+ global $wp_query;
609
+
610
+ return '1' == get_option( 'wpsc_force_ssl' ) && ! is_ssl() && false !== strpos( $wp_query->post->post_content, '[shoppingcart]' );
611
+ }
612
+
wpsc-components/theme-engine-v1/helpers/rewrite.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ add_filter( 'rewrite_rules_array', 'wpsc_taxonomy_rewrite_rules' );
3
+
4
+ /**
5
+ * wpsc_taxonomy_rewrite_rules function.
6
+ * Adds in new rewrite rules for categories, products, category pages, and ambiguities (either categories or products)
7
+ * Also modifies the rewrite rules for product URLs to add in the post type.
8
+ *
9
+ * @since 3.8
10
+ * @access public
11
+ * @param array $rewrite_rules
12
+ * @return array - the modified rewrite rules
13
+ */
14
+ function wpsc_taxonomy_rewrite_rules( $rewrite_rules ) {
15
+ global $wpsc_page_titles;
16
+ $products_page = $wpsc_page_titles['products'];
17
+ $checkout_page = $wpsc_page_titles['checkout'];
18
+ $target_string = "index.php?product";
19
+ $replacement_string = "index.php?post_type=wpsc-product&product";
20
+ $target_rule_set_query_var = 'products';
21
+
22
+ $target_rule_set = array( );
23
+ foreach ( $rewrite_rules as $rewrite_key => $rewrite_query ) {
24
+ if ( stristr( $rewrite_query, "index.php?product" ) ) {
25
+ $rewrite_rules[$rewrite_key] = str_replace( $target_string, $replacement_string, $rewrite_query );
26
+ }
27
+ if ( stristr( $rewrite_query, "$target_rule_set_query_var=" ) ) {
28
+ $target_rule_set[] = $rewrite_key;
29
+ }
30
+ }
31
+
32
+ $new_rewrite_rules[$products_page . '/(.+?)/product/([^/]+)/comment-page-([0-9]{1,})/?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&name=$matches[2]&cpage=$matches[3]';
33
+ $new_rewrite_rules[$products_page . '/(.+?)/product/([^/]+)/?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&name=$matches[2]';
34
+ $new_rewrite_rules[$products_page . '/(.+?)/([^/]+)/comment-page-([0-9]{1,})/?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&wpsc_item=$matches[2]&cpage=$matches[3]';
35
+ $new_rewrite_rules[$products_page . '/(.+?)/([^/]+)?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&wpsc_item=$matches[2]';
36
+
37
+ $last_target_rule = array_pop( $target_rule_set );
38
+
39
+ $rebuilt_rewrite_rules = array( );
40
+ foreach ( $rewrite_rules as $rewrite_key => $rewrite_query ) {
41
+ if ( $rewrite_key == $last_target_rule ) {
42
+ $rebuilt_rewrite_rules = array_merge( $rebuilt_rewrite_rules, $new_rewrite_rules );
43
+ }
44
+ $rebuilt_rewrite_rules[$rewrite_key] = $rewrite_query;
45
+ }
46
+
47
+ // fix pagination issue with product category hirarchical URL
48
+ if ( get_option( 'product_category_hierarchical_url', false ) ) {
49
+ $rule = $rebuilt_rewrite_rules[$products_page . '/(.+?)/page/?([0-9]{1,})/?$'];
50
+ unset( $rebuilt_rewrite_rules[$products_page . '/(.+?)/page/?([0-9]{1,})/?$'] );
51
+ $rebuilt_rewrite_rules = array_merge(
52
+ array(
53
+ '(' . $products_page . ')/page/([0-9]+)/?' => 'index.php?pagename=$matches[1]&page=$matches[2]',
54
+ $products_page . '/(.+?)(/.+?)?/page/?([0-9]{1,})/?$' => 'index.php?wpsc_product_category=$matches[1]&wpsc-product=$matches[2]&page=$matches[3]',
55
+ ),
56
+ $rebuilt_rewrite_rules
57
+ );
58
+ }
59
+
60
+ // fix pagination in WordPress 3.4
61
+ if ( version_compare( get_bloginfo( 'version' ), '3.4', '>=' ) ) {
62
+ $rebuilt_rewrite_rules = array_merge(
63
+ array(
64
+ '(' . $products_page . ')/([0-9]+)/?$' => 'index.php?pagename=$matches[1]&page=$matches[2]',
65
+ ),
66
+ $rebuilt_rewrite_rules
67
+ );
68
+ }
69
+ return $rebuilt_rewrite_rules;
70
+ }
71
+
wpsc-components/theme-engine-v1/helpers/rss.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'wp_head', 'wpsc_product_list_rss_feed' );
4
+
5
+ if ( isset( $_REQUEST['wpsc_action'] ) && ($_REQUEST['wpsc_action'] == "rss") ) {
6
+ add_action( 'template_redirect', 'wpsc_product_rss', 80 );
7
+ }
8
+
9
+ function wpsc_product_rss() {
10
+ global $wp_query, $wpsc_query, $_wpsc_is_in_custom_loop;
11
+ list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query object
12
+ $_wpsc_is_in_custom_loop = true;
13
+ header( "Content-Type: application/xml; charset=UTF-8" );
14
+ header( 'Content-Disposition: inline; filename="E-Commerce_Product_List.rss"' );
15
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/rss/rss.php' );
16
+ list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query object
17
+ $_wpsc_is_in_custom_loop = false;
18
+ exit();
19
+ }
20
+
21
+ function wpsc_product_list_rss_feed() {
22
+ $rss_url = get_option('siteurl');
23
+ $rss_url = add_query_arg( 'wpsc_action', 'rss', $rss_url );
24
+ $rss_url = str_replace('&', '&amp;', $rss_url);
25
+ $rss_url = esc_url( $rss_url ); // URL santization - IMPORTANT!
26
+
27
+ echo "<link rel='alternate' type='application/rss+xml' title='" . get_option( 'blogname' ) . " Product List RSS' href='{$rss_url}'/>";
28
+ }
wpsc-components/theme-engine-v1/helpers/shipping.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * have shipping methods function, no parameters
5
+ * @return boolean
6
+ */
7
+ function wpsc_have_shipping_methods() {
8
+ global $wpsc_cart;
9
+ return $wpsc_cart->have_shipping_methods();
10
+ }
11
+ /**
12
+ * the shipping method function, no parameters
13
+ * @return boolean
14
+ */
15
+ function wpsc_the_shipping_method() {
16
+ global $wpsc_cart;
17
+ return $wpsc_cart->the_shipping_method();
18
+ }
19
+ /**
20
+ * the shipping method name function, no parameters
21
+ * @return string shipping method name
22
+ */
23
+ function wpsc_shipping_method_name() {
24
+ global $wpsc_cart, $wpsc_shipping_modules;
25
+ $name = '';
26
+ if ( ! empty( $wpsc_cart->shipping_method ) && isset( $wpsc_shipping_modules[$wpsc_cart->shipping_method] ) ) {
27
+ $name = $wpsc_shipping_modules[$wpsc_cart->shipping_method]->getName();
28
+ }
29
+ return apply_filters( 'wpsc_shipping_method_name', $name );
30
+ }
31
+
32
+
33
+ /**
34
+ * the shipping method internal name function, no parameters
35
+ * @return string shipping method internal name
36
+ */
37
+ function wpsc_shipping_method_internal_name() {
38
+ global $wpsc_cart, $wpsc_shipping_modules;
39
+ return $wpsc_cart->shipping_method;
40
+ }
41
+
42
+
43
+ /**
44
+ * have shipping quotes function, no parameters
45
+ * @return string the cart item url
46
+ */
47
+ function wpsc_have_shipping_quotes() {
48
+ global $wpsc_cart;
49
+ return $wpsc_cart->have_shipping_quotes();
50
+ }
51
+
52
+ /**
53
+ * the shipping quote function, no parameters
54
+ * @return string the cart item url
55
+ */
56
+ function wpsc_the_shipping_quote() {
57
+ global $wpsc_cart;
58
+ return $wpsc_cart->the_shipping_quote();
59
+ }
60
+
61
+ /**
62
+ * the shipping quote name function, no parameters
63
+ * @return string shipping quote name
64
+ */
65
+ function wpsc_shipping_quote_name() {
66
+ global $wpsc_cart;
67
+ return apply_filters( 'wpsc_shipping_quote_name', $wpsc_cart->shipping_quote['name'] );
68
+ }
69
+
70
+ /**
71
+ * the shipping quote value function, no parameters
72
+ * @return string shipping quote value
73
+ */
74
+ function wpsc_shipping_quote_value( $numeric = false ) {
75
+ global $wpsc_cart;
76
+
77
+ $value = apply_filters( 'wpsc_shipping_quote_value', $wpsc_cart->shipping_quote['value'] );
78
+
79
+ return ( $numeric ) ? $value : wpsc_currency_display( $value );
80
+
81
+ }
82
+
83
+ /**
84
+ * the shipping quote html ID function, no parameters
85
+ * @return string shipping quote html ID
86
+ */
87
+ function wpsc_shipping_quote_html_id() {
88
+ global $wpsc_cart;
89
+ return $wpsc_cart->shipping_method."_".$wpsc_cart->current_shipping_quote;
90
+ }
91
+
92
+ /**
93
+ * the shipping quote selected state function, no parameters
94
+ * @return string true or false
95
+ */
96
+ function wpsc_shipping_quote_selected_state() {
97
+ global $wpsc_cart;
98
+ if(($wpsc_cart->selected_shipping_method == $wpsc_cart->shipping_method) && ($wpsc_cart->selected_shipping_option == $wpsc_cart->shipping_quote['name']) ) {
99
+ $wpsc_cart->selected_shipping_amount = $wpsc_cart->base_shipping;
100
+ return "checked='checked'";
101
+ } else {
102
+ return "";
103
+ }
104
+ }
105
+ function wpsc_have_morethanone_shipping_quote(){
106
+ global $wpsc_cart, $wpsc_shipping_modules;
107
+
108
+ // if it's fixed rate shipping, and all the prices are the same, then there aren't really options.
109
+ if ( count($wpsc_cart->shipping_methods) == 1 && $wpsc_cart->shipping_methods[0] == 'flatrate' ) {
110
+ $last_price = false;
111
+ $first_quote_name = false;
112
+
113
+ $quotes = $wpsc_shipping_modules['flatrate']->getQuote();
114
+ if ( empty( $quotes ) )
115
+ return false;
116
+
117
+ foreach ((array)$quotes as $name => $quote) {
118
+ if (!$first_quote_name) $first_quote_name = $name;
119
+ if ($last_price !== false && $quote != $last_price) return true;
120
+ $last_price = $quote;
121
+ }
122
+ $wpsc_cart->rewind_shipping_methods();
123
+
124
+ $wpsc_cart->update_shipping('flatrate', $name);
125
+ return false;
126
+ }
127
+ return true;
128
+ }
129
+
130
+ function wpsc_have_morethanone_shipping_methods_and_quotes(){
131
+ global $wpsc_cart;
132
+
133
+ if(count($wpsc_cart->shipping_quotes) > 1 || count($wpsc_cart->shipping_methods) > 1 || count($wpsc_cart->shipping_quotes) == $wpsc_cart->shipping_quote_count){
134
+ return true;
135
+ }else{
136
+ return false;
137
+ }
138
+ }
139
+ /**
140
+ * Whether or not there is a valid shipping quote/option available to the customer when checking out
141
+ *
142
+ * @return bool
143
+ */
144
+ function wpsc_have_shipping_quote(){
145
+ global $wpsc_cart;
146
+ if ($wpsc_cart->shipping_quote_count > 0 || count($wpsc_cart->shipping_quotes) > 0) {
147
+ return true;
148
+ }
149
+ return false;
150
+ }
wpsc-includes/shortcode.functions.php → wpsc-components/theme-engine-v1/helpers/shortcodes.php RENAMED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * WP eCommerce shortcode definitions
4
  *
@@ -63,7 +67,6 @@ function wpsc_products_shorttag($atts) {
63
 
64
  return wpsc_display_products_page($query);
65
  }
66
- add_shortcode('wpsc_products', 'wpsc_products_shorttag');
67
 
68
  /**
69
  * Shows the WPSC buy now button
@@ -78,4 +81,14 @@ function wpsc_buy_now_shortcode($atts){
78
  return $output;
79
  }
80
 
81
- add_shortcode('buy_now_button', 'wpsc_buy_now_shortcode');
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+ add_shortcode('buy_now_button', 'wpsc_buy_now_shortcode');
3
+ add_shortcode('wpsc_products', 'wpsc_products_shorttag');
4
+ add_shortcode('showcategories', 'wpsc_show_categories');
5
+
6
  /**
7
  * WP eCommerce shortcode definitions
8
  *
67
 
68
  return wpsc_display_products_page($query);
69
  }
 
70
 
71
  /**
72
  * Shows the WPSC buy now button
81
  return $output;
82
  }
83
 
84
+ //displays a list of categories when the code [showcategories] is present in a post or page.
85
+ function wpsc_show_categories( $content ) {
86
+
87
+ ob_start();
88
+ include( wpsc_get_template_file_path( 'wpsc-category-list.php' ) );
89
+ $output = ob_get_contents();
90
+
91
+ ob_end_clean();
92
+ return $output;
93
+
94
+ }
wpsc-components/theme-engine-v1/helpers/template-tags.php ADDED
@@ -0,0 +1,1749 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * wpsc display products function
5
+ * Used to determine whether to display products on the page
6
+ * @return boolean - true for yes, false for no
7
+ */
8
+ function wpsc_display_products() {
9
+ $post = get_queried_object();
10
+ $product_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
11
+ //we have to display something, if we are not displaying categories, then we must display products
12
+ $output = true;
13
+ if ( wpsc_display_categories () && isset ( $post->ID ) ) {
14
+ if ( get_option( 'wpsc_default_category' ) == 'list' && $post->ID == $product_page_id )
15
+ $output = false;
16
+
17
+ if ( isset( $_GET['range'] ) || isset( $_GET['category'] ) )
18
+ $output = true;
19
+ }
20
+ return $output;
21
+ }
22
+
23
+ /**
24
+ * is single product function, determines if we are viewing a single product
25
+ * @return boolean - true, or false...
26
+ */
27
+ function wpsc_is_single_product() {
28
+ return is_single() && get_post_type() == 'wpsc-product';
29
+ }
30
+
31
+ /**
32
+ * category class function, categories can have a specific class, this gets that
33
+ * @return string - the class of the selected category
34
+ */
35
+ function wpsc_category_class() {
36
+ global $wpdb, $wp_query;
37
+
38
+ $category_nice_name = '';
39
+ if ( 'wpsc_product_category' == $wp_query->query_vars['taxonomy'] ) {
40
+ $catid = wpsc_get_the_category_id($wp_query->query_vars['term'],'slug');
41
+ } else {
42
+ $catid = get_option( 'wpsc_default_category' );
43
+ if ( $catid == 'all+list' ) {
44
+ $catid = 'all';
45
+ }
46
+ }
47
+
48
+ if ( (int)$catid > 0 ){
49
+ $term = get_term($catid, 'wpsc_product_category');
50
+ $category_nice_name = $term->slug;
51
+ }else if ( $catid == 'all' ){
52
+ $category_nice_name = 'all-categories';
53
+ }
54
+ return $category_nice_name;
55
+ }
56
+
57
+ /**
58
+ * category transition function, finds the transition between categories
59
+ * @return string - the class of the selected category
60
+ */
61
+ function wpsc_current_category_name() {
62
+ global $wp_query;
63
+ $term_data = get_term( $wp_query->post->term_id, 'wpsc_product_category' );
64
+
65
+ return $term_data->name;
66
+ }
67
+
68
+ /**
69
+ * category transition function, finds the transition between categories
70
+ * @return string - the class of the selected category
71
+ */
72
+ function wpsc_category_transition() {
73
+ //removed because it was not working in 3.8 RC2 see first changest after
74
+ //http://plugins.trac.wordpress.org/changeset/357529/wp-e-commerce/
75
+ return false;
76
+
77
+ }
78
+ /**
79
+ * wpsc show fb like function, check whether to show facebook like
80
+ * @return boolean true if option is on, otherwise, false
81
+ */
82
+
83
+ function wpsc_show_fb_like(){
84
+ if('on' == get_option('wpsc_facebook_like'))
85
+ return true;
86
+ else
87
+ return false;
88
+ }
89
+ /**
90
+ * wpsc have products function, the product loop
91
+ * @return boolean true while we have products, otherwise, false
92
+ */
93
+ function wpsc_have_products() {
94
+ return have_posts();
95
+ }
96
+
97
+ /**
98
+ * wpsc the product function, gets the next product,
99
+ * @return nothing
100
+ */
101
+ function wpsc_the_product() {
102
+ global $wpsc_custom_meta, $wpsc_variations;
103
+ the_post();
104
+ $wpsc_custom_meta = new wpsc_custom_meta( get_the_ID() );
105
+ $wpsc_variations = new wpsc_variations( get_the_ID() );
106
+ }
107
+
108
+ /**
109
+ * wpsc the product id function,
110
+ * @return integer - the product ID
111
+ */
112
+ function wpsc_the_product_id() {
113
+ return get_the_ID();
114
+ }
115
+
116
+ /**
117
+ * wpsc edit the product link function
118
+ * @return string - a link to edit this product
119
+ */
120
+ function wpsc_edit_the_product_link( $link = null, $before = '', $after = '', $id = 0 ) {
121
+ global $wpsc_query, $current_user, $table_prefix, $wp_query;
122
+ if ( $link == null )
123
+ $link = __( 'Edit', 'wpsc' );
124
+
125
+ $product_id = $wp_query->post->ID;
126
+ if ( $id > 0 )
127
+ $product_id = $id;
128
+
129
+ $output = '';
130
+ if(is_user_logged_in()){
131
+ get_currentuserinfo();
132
+ if ( $current_user->{$table_prefix . 'capabilities'}['administrator'] == 1 )
133
+ $output = $before . '<a class="wpsc_edit_product" href="' . esc_attr( get_edit_post_link( $product_id ) ) . '">' . $link . '</a>' . $after;
134
+
135
+ }
136
+ return $output;
137
+ }
138
+
139
+ /**
140
+ * wpsc the product title function
141
+ * @return string - the product title
142
+ */
143
+ function wpsc_the_product_title( $post = 0 ) {
144
+ return get_the_title( $post );
145
+ }
146
+
147
+ /**
148
+ * wpsc product description function
149
+ * @return string - the product description
150
+ */
151
+ function wpsc_the_product_description() {
152
+ $content = get_the_content( __( 'Read the rest of this entry &raquo;', 'wpsc' ) );
153
+ return do_shortcode( wpautop( $content,1 ) );
154
+ }
155
+
156
+ /**
157
+ * wpsc additional product description function
158
+ * TODO make this work with the tabbed multiple product descriptions, may require another loop
159
+ * @return string - the additional description
160
+ */
161
+ function wpsc_the_product_additional_description() {
162
+ global $post;
163
+
164
+ if ( !empty( $post->post_excerpt ) )
165
+ return $post->post_excerpt;
166
+ else
167
+ return false;
168
+ }
169
+
170
+ /**
171
+ * wpsc product permalink function
172
+ * @return string - the URL to the single product page for this product
173
+ */
174
+ function wpsc_the_product_permalink() {
175
+ global $wp_query;
176
+ return get_permalink();
177
+ }
178
+
179
+ /**
180
+ * wpsc external link function
181
+ * @return string - the product price
182
+ */
183
+ function wpsc_product_external_link( $id = null ) {
184
+ if ( is_numeric( $id ) && ( $id > 0 ) )
185
+ $id = absint( $id );
186
+ else
187
+ $id = get_the_ID();
188
+
189
+ $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true );
190
+ if ( isset( $product_meta['external_link'] ) ) {
191
+ $external_link = $product_meta['external_link'];
192
+ return esc_url( $external_link );
193
+ }
194
+ }
195
+
196
+ /**
197
+ * wpsc external link text function
198
+ * @return string - the product external link text
199
+ */
200
+ function wpsc_product_external_link_text( $id = null, $default = null ) {
201
+ if ( is_numeric( $id ) && ( $id > 0 ) )
202
+ $id = absint( $id );
203
+ else
204
+ $id = get_the_ID();
205
+
206
+ $external_link_text = __( 'Buy Now', 'wpsc' );
207
+ if ( $default != null ) {
208
+ $external_link_text = $default;
209
+ }
210
+
211
+ $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true );
212
+ if ( isset( $product_meta['external_link_text'] ) && !empty( $product_meta['external_link_text'] ) ) {
213
+ $external_link_text = $product_meta['external_link_text'];
214
+ }
215
+ return esc_html( $external_link_text );
216
+ }
217
+
218
+ /**
219
+ * wpsc external link target function
220
+ * @return string - the product external link target
221
+ */
222
+ function wpsc_product_external_link_target( $id = null, $external_link_target = '' ) {
223
+ if ( is_numeric( $id ) && ( $id > 0 ) )
224
+ $id = absint( $id );
225
+ else
226
+ $id = get_the_ID();
227
+
228
+ $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true );
229
+ if ( isset( $product_meta['external_link_target'] ) && !empty( $product_meta['external_link_target'] ) ) {
230
+ $external_link_target = $product_meta['external_link_target'];
231
+ }
232
+ return esc_attr( $external_link_target );
233
+ }
234
+
235
+ /**
236
+ * wpsc product sku function
237
+ * @return string - the product price
238
+ */
239
+ function wpsc_product_sku( $id = null ) {
240
+ if ( is_numeric( $id ) && ( $id > 0 ) )
241
+ $id = absint( $id );
242
+ else
243
+ $id = get_the_ID();
244
+
245
+ $product_sku = get_post_meta( $id, '_wpsc_sku', true );
246
+
247
+ return esc_attr( $product_sku );
248
+ }
249
+
250
+ function wpsc_has_pages_top(){if(wpsc_has_pages() && ((get_option('wpsc_page_number_position') == 1) || (get_option('wpsc_page_number_position') == 3)))
251
+ return true;
252
+ else
253
+ return false;
254
+ }
255
+
256
+
257
+ function wpsc_has_pages_bottom(){
258
+ if(wpsc_has_pages() && ((get_option('wpsc_page_number_position') == 2) || (get_option('wpsc_page_number_position') == 3)))
259
+ return true;
260
+ else
261
+ return false;
262
+ }
263
+
264
+ /**
265
+ * Used in wpsc_pagination to generate the links in pagination
266
+ * @access public
267
+ *
268
+ * @since 3.8
269
+ * @param $page int
270
+ * @return $output string, url
271
+ */
272
+ function wpsc_a_page_url($page=null) {
273
+ global $wp_query;
274
+ $output = '';
275
+ $curpage = $wp_query->query_vars['paged'];
276
+ if($page != '')
277
+ $wp_query->query_vars['paged'] = $page;
278
+ if($wp_query->is_single === true) {
279
+ $wp_query->query_vars['paged'] = $curpage;
280
+ return get_permalink($wp_query->post->ID);
281
+ } else {
282
+ if( 1 < $wp_query->query_vars['paged']) {
283
+ if(get_option('permalink_structure'))
284
+ $output .= "paged/{$wp_query->query_vars['paged']}/";
285
+ else
286
+ $output = add_query_arg('paged', '', $output);
287
+
288
+ }
289
+ return $output;
290
+ }
291
+ }
292
+ /**
293
+ * wpsc_pagination generates and returns the urls for pagination
294
+ * @access public
295
+ *
296
+ * @since 3.8
297
+ * @param $totalpages (INT) Number of pages,
298
+ * @param $per_page (INT) Number of products per page
299
+ * @param $current_page (INT) Current Product page number
300
+ * @param $page_link (STRING) URL of Page
301
+ *
302
+ * @return
303
+ */
304
+ function wpsc_pagination( $totalpages = '', $per_page = '', $current_page = '', $page_link = '' ) {
305
+ global $wp_query, $wpsc_query, $wp_the_query;
306
+
307
+ $num_paged_links = 4; //amount of links to show on either side of current page
308
+
309
+ $additional_links = '';
310
+
311
+ //additional links, items per page and products order
312
+ if( get_option('permalink_structure') != '' ){
313
+ $additional_links_separator = '?';
314
+ }else{
315
+ $additional_links_separator = '&';
316
+ }
317
+ if( !empty( $_GET['items_per_page'] ) ){
318
+ $additional_links = $additional_links_separator . 'items_per_page=' . $_GET['items_per_page'];
319
+ $additional_links_separator = '&';
320
+ }
321
+ if( !empty( $_GET['product_order'] ) )
322
+ $additional_links .= $additional_links_separator . 'product_order=' . $_GET['product_order'];
323
+
324
+ if ( ! empty( $_GET['range'] ) )
325
+ $additional_links .= $additional_links_separator . 'range=' . $_GET['range'];
326
+
327
+ $additional_links = apply_filters('wpsc_pagination_additional_links', $additional_links);
328
+ //end of additional links
329
+
330
+ if(empty($totalpages)){
331
+ $totalpages = $wp_query->max_num_pages;
332
+ }
333
+ if(empty($per_page))
334
+ $per_page = (int)get_option('wpsc_products_per_page');
335
+
336
+ $current_page = absint( get_query_var('paged') );
337
+ if($current_page == 0)
338
+ $current_page = 1;
339
+
340
+ if(empty($page_link))
341
+ $page_link = wpsc_a_page_url();
342
+
343
+ //if there is no pagination
344
+ if(!get_option('permalink_structure')) {
345
+ $category = '?';
346
+
347
+ if( ! empty( $wp_query->query_vars['wpsc_product_category'] ) )
348
+ $category = '?wpsc_product_category='.$wp_query->query_vars['wpsc_product_category'];
349
+ if(isset($wp_query->query_vars['wpsc_product_category']) && is_string($wp_query->query_vars['wpsc_product_category'])){
350
+ $page_link = get_option('blogurl').$category.'&amp;paged';
351
+ }else{
352
+ $page_link = get_option('product_list_url').$category.'&amp;paged';
353
+ }
354
+
355
+ $separator = '=';
356
+ }else{
357
+ global $wpsc_query;
358
+
359
+ $separator = 'page/';
360
+
361
+ if ( isset( $wp_query->query_vars['wpsc_product_category'] ) ) {
362
+ $category_id = get_term_by( 'slug', $wp_query->query_vars['wpsc_product_category'], 'wpsc_product_category' );
363
+ $page_link = trailingslashit( get_term_link( $category_id, 'wpsc_product_category' ) );
364
+ // in case we're displaying a category using shortcode, need to use the page's URL instead of the taxonomy URL
365
+ if ( $wp_the_query->is_page() ) {
366
+ $page = $wp_the_query->get_queried_object();
367
+ if ( preg_match( '/\[wpsc\_products[^\]]*category_id=/', $page->post_content ) ) {
368
+ $page_link = trailingslashit( get_permalink( $page->ID ) );
369
+ $separator = '';
370
+ }
371
+ }
372
+ } elseif ( is_tax( 'product_tag' ) ) {
373
+ $tag = get_queried_object();
374
+ $page_link = trailingslashit( get_term_link( (int) $tag->term_id, 'product_tag' ) );
375
+ } elseif ( $wpsc_query->is_front_page() ) {
376
+ $page_link = trailingslashit( home_url() );
377
+ } else {
378
+ $page_link = trailingslashit( get_option( 'product_list_url' ) );
379
+ $separator = '';
380
+ }
381
+
382
+ if ( version_compare( get_bloginfo( 'version' ), '3.4', '<' ) )
383
+ $separator = 'page/';
384
+ }
385
+
386
+ // If there's only one page, return now and don't bother
387
+ if($totalpages == 1)
388
+ return;
389
+ // Pagination Prefix
390
+ $output = __('Pages: ','wpsc');
391
+ if(get_option('permalink_structure')){
392
+ // Should we show the FIRST PAGE link?
393
+ if($current_page > 1)
394
+ $output .= "<a href=\"". esc_url( $page_link . $additional_links ) . "\" title=\"" . __('First Page', 'wpsc') . "\">" . __('&laquo; First', 'wpsc') . "</a>";
395
+
396
+ // Should we show the PREVIOUS PAGE link?
397
+ if($current_page > 1) {
398
+ $previous_page = $current_page - 1;
399
+ if( $previous_page == 1 )
400
+ $output .= " <a href=\"". esc_url( $page_link . $additional_links ) . "\" title=\"" . __('Previous Page', 'wpsc') . "\">" . __('&lt; Previous', 'wpsc') . "</a>";
401
+ else
402
+ $output .= " <a href=\"". esc_url( $page_link .$separator. $previous_page . $additional_links ) . "\" title=\"" . __('Previous Page', 'wpsc') . "\">" . __('&lt; Previous', 'wpsc') . "</a>";
403
+ }
404
+ $i =$current_page - $num_paged_links;
405
+ $count = 1;
406
+ if($i <= 0) $i =1;
407
+ while($i < $current_page){
408
+ if($count <= $num_paged_links){
409
+ if($count == 1)
410
+ $output .= " <a href=\"". esc_url( $page_link . $additional_links ) . "\" title=\"" . sprintf( __('Page %s', 'wpsc'), $i ) . " \">".$i."</a>";
411
+ else
412
+ $output .= " <a href=\"". esc_url( $page_link .$separator. $i . '/' . $additional_links ) . "\" title=\"" . sprintf( __('Page %s', 'wpsc'), $i ) . " \">".$i."</a>";
413
+ }
414
+ $i++;
415
+ $count++;
416
+ }
417
+ // Current Page Number
418
+ if($current_page > 0)
419
+ $output .= "<span class='current'>$current_page</span>";
420
+
421
+ //Links after Current Page
422
+ $i = $current_page + $num_paged_links;
423
+ $count = 1;
424
+
425
+ if($current_page < $totalpages){
426
+ while(($i) > $current_page){
427
+
428
+ if($count < $num_paged_links && ($count+$current_page) <= $totalpages){
429
+ $output .= " <a href=\"". esc_url( $page_link .$separator. ($count+$current_page) . '/' .$additional_links ) . "\" title=\"" . sprintf( __('Page %s', 'wpsc'), ($count+$current_page) ) . "\">".($count+$current_page)."</a>";
430
+ $i++;
431
+ }else{
432
+ break;
433
+ }
434
+ $count ++;
435
+ }
436
+ }
437
+
438
+ if($current_page < $totalpages) {
439
+ $next_page = $current_page + 1;
440
+ $output .= "<a href=\"". esc_url( $page_link .$separator. $next_page . '/' . $additional_links ) . "\" title=\"" . __('Next Page', 'wpsc') . "\">" . __('Next &gt;', 'wpsc') . "</a>";
441
+ }
442
+ // Should we show the LAST PAGE link?
443
+ if($current_page < $totalpages) {
444
+ $output .= "<a href=\"". esc_url( $page_link .$separator. $totalpages . '/' . $additional_links ) . "\" title=\"" . __('Last Page', 'wpsc') . "\">" . __('Last &raquo;', 'wpsc') . "</a>";
445
+ }
446
+ } else {
447
+ // Should we show the FIRST PAGE link?
448
+ if($current_page > 1)
449
+ $output .= "<a href=\"". remove_query_arg('paged' ) . "\" title=\"" . __('First Page', 'wpsc') . "\">" . __('&laquo; First', 'wpsc') . "</a>";
450
+
451
+ // Should we show the PREVIOUS PAGE link?
452
+ if($current_page > 1) {
453
+ $previous_page = $current_page - 1;
454
+ if( $previous_page == 1 )
455
+ $output .= " <a href=\"". remove_query_arg( 'paged' ) . $additional_links . "\" title=\"" . __('Previous Page', 'wpsc') . "\">" . __('&lt; Previous', 'wpsc') . "</a>";
456
+ else
457
+ $output .= " <a href=\"". add_query_arg( 'paged', ($current_page - 1) ) . $additional_links . "\" title=\"" . __('Previous Page', 'wpsc') . "\">" . __('&lt; Previous', 'wpsc') . "</a>";
458
+ }
459
+ $i =$current_page - $num_paged_links;
460
+ $count = 1;
461
+ if($i <= 0) $i =1;
462
+ while($i < $current_page){
463
+ if($count <= $num_paged_links){
464
+ if($i == 1)
465
+ $output .= " <a href=\"". remove_query_arg('paged' ) . "\" title=\"" . sprintf( __('Page %s', 'wpsc'), $i ) . " \">".$i."</a>";
466
+ else
467
+ $output .= " <a href=\"". add_query_arg('paged', $i ) . "\" title=\"" . sprintf( __('Page %s', 'wpsc'), $i ) . " \">".$i."</a>";
468
+ }
469
+ $i++;
470
+ $count++;
471
+ }
472
+ // Current Page Number
473
+ if($current_page > 0)
474
+ $output .= "<span class='current'>$current_page</span>";
475
+
476
+ //Links after Current Page
477
+ $i = $current_page + $num_paged_links;
478
+ $count = 1;
479
+
480
+ if($current_page < $totalpages){
481
+ while(($i) > $current_page){
482
+
483
+ if($count < $num_paged_links && ($count+$current_page) <= $totalpages){
484
+ $output .= " <a href=\"". add_query_arg( 'paged', ($count+$current_page) ) . "\" title=\"" . sprintf( __('Page %s', 'wpsc'), ($count+$current_page) ) . "\">".($count+$current_page)."</a>";
485
+ $i++;
486
+ }else{
487
+ break;
488
+ }
489
+ $count ++;
490
+ }
491
+ }
492
+
493
+ if($current_page < $totalpages) {
494
+ $next_page = $current_page + 1;
495
+ $output .= "<a href=\"". add_query_arg( 'paged', $next_page ) . "\" title=\"" . __('Next Page', 'wpsc') . "\">" . __('Next &gt;', 'wpsc') . "</a>";
496
+ }
497
+ // Should we show the LAST PAGE link?
498
+ if($current_page < $totalpages) {
499
+ $output .= "<a href=\"". add_query_arg( 'paged', $totalpages ) . "\" title=\"" . __('Last Page', 'wpsc') . "\">" . __('Last &raquo;', 'wpsc') . "</a>";
500
+ }
501
+ }
502
+ // Return the output.
503
+ echo apply_filters( 'wpsc_pagination', $output, $totalpages, $per_page, $current_page, $page_link );
504
+ }
505
+
506
+ /**
507
+ * wpsc_show_stock_availability
508
+ *
509
+ * Checks to see whether stock symbols need to be shown
510
+ * @return boolean - true is the option has been checked false otherwise
511
+ */
512
+ function wpsc_show_stock_availability(){
513
+ if( get_option('list_view_quantity') == 1 )
514
+ return true;
515
+ else
516
+ return false;
517
+ }
518
+
519
+ /**
520
+ * wpsc product image function
521
+ *
522
+ * if no parameters are passed, the image is not resized, otherwise it is resized to the specified dimensions
523
+ *
524
+ * @param integer attachment_ID
525
+ * @param integer width
526
+ * @param integer height
527
+ * @return string - the product image URL, or the URL of the resized version
528
+ */
529
+ function wpsc_product_image( $attachment_id = 0, $width = null, $height = null ) {
530
+ // Do some dancing around the image size
531
+ if ( ( ( $width >= 10 ) && ( $height >= 10 ) ) && ( ( $width <= 1024 ) && ( $height <= 1024 ) ) )
532
+ $intermediate_size = "wpsc-{$width}x{$height}";
533
+
534
+ // Get image url if we have enough info
535
+ if ( ( $attachment_id > 0 ) && ( !empty( $intermediate_size ) ) ) {
536
+
537
+ // Get all the required information about the attachment
538
+ $uploads = wp_upload_dir();
539
+ $image_meta = get_post_meta( $attachment_id, '' );
540
+ $file_path = get_attached_file( $attachment_id );
541
+
542
+ // Clean up the meta array
543
+ foreach ( $image_meta as $meta_name => $meta_value )
544
+ $image_meta[$meta_name] = maybe_unserialize( array_pop( $meta_value ) );
545
+
546
+
547
+ $attachment_metadata = $image_meta['_wp_attachment_metadata'];
548
+ // Determine if we already have an image of this size
549
+ if ( isset( $attachment_metadata['sizes'] ) && (count( $attachment_metadata['sizes'] ) > 0) && ( isset( $attachment_metadata['sizes'][$intermediate_size] ) ) ) {
550
+ $intermediate_image_data = image_get_intermediate_size( $attachment_id, $intermediate_size );
551
+ $image_url = $intermediate_image_data['url'];
552
+ } else {
553
+ $image_url = home_url( "index.php?wpsc_action=scale_image&attachment_id={$attachment_id}&width=$width&height=$height" );
554
+ }
555
+ // Not enough info so attempt to fallback
556
+ } else {
557
+
558
+ if ( !empty( $attachment_id ) ) {
559
+ $image_url = home_url( "index.php?wpsc_action=scale_image&attachment_id={$attachment_id}&width=$width&height=$height" );
560
+ } else {
561
+ $image_url = false;
562
+ }
563
+
564
+ }
565
+ if(empty($image_url) && !empty($file_path)){
566
+ $image_meta = get_post_meta( $attachment_id, '_wp_attached_file' );
567
+ if ( ! empty( $image_meta ) )
568
+ $image_url = $uploads['baseurl'].'/'.$image_meta[0];
569
+ }
570
+ if( is_ssl() ) str_replace('http://', 'https://', $image_url);
571
+
572
+ return apply_filters( 'wpsc_product_image', $image_url );
573
+ }
574
+
575
+ function wpsc_product_no_image_fallback( $image_url = '' ) {
576
+ if ( !empty( $image_url ) )
577
+ return $image_url;
578
+ else
579
+ return apply_filters( 'wpsc_product_noimage', WPSC_CORE_THEME_URL . 'wpsc-images/noimage.png' );
580
+ }
581
+ add_filter( 'wpsc_product_image', 'wpsc_product_no_image_fallback' );
582
+
583
+
584
+ /**
585
+ * wpsc show pnp function
586
+ * @return boolean - true if display_pnp is 1 false otherwise
587
+ */
588
+ function wpsc_show_pnp(){
589
+ global $post;
590
+ if(1 == get_option('display_pnp'))
591
+ return true;
592
+ return false;
593
+ }
594
+
595
+ /**
596
+ * wpsc product price function
597
+ * @return string - the product price
598
+ */
599
+ function wpsc_the_product_price( $no_decimals = false, $only_normal_price = false, $product_id = 0 ) {
600
+ global $wpsc_query, $wpsc_variations, $wpdb;
601
+
602
+ if ( ! $product_id )
603
+ $product_id = get_the_ID();
604
+
605
+ if ( wpsc_product_has_variations( $product_id ) ) {
606
+ $from_text = __( ' from %s', 'wpsc' );
607
+ $from_text = apply_filters( 'wpsc_product_variation_text', $from_text );
608
+ $output = wpsc_product_variation_price_from( $product_id, array(
609
+ 'from_text' => $from_text,
610
+ 'only_normal_price' => $only_normal_price,
611
+ ) );
612
+ } else {
613
+ $price = $full_price = get_post_meta( $product_id, '_wpsc_price', true );
614
+
615
+ if ( ! $only_normal_price ) {
616
+ $special_price = get_post_meta( $product_id, '_wpsc_special_price', true );
617
+
618
+ if ( ( $full_price > $special_price ) && ( $special_price > 0 ) )
619
+ $price = $special_price;
620
+ }
621
+
622
+ if ( $no_decimals == true )
623
+ $price = array_shift( explode( ".", $price ) );
624
+
625
+ $price = apply_filters( 'wpsc_do_convert_price', $price, $product_id );
626
+ $args = array(
627
+ 'display_as_html' => false,
628
+ 'display_decimal_point' => ! $no_decimals
629
+ );
630
+ $output = wpsc_currency_display( $price, $args );
631
+ }
632
+ return $output;
633
+ }
634
+
635
+ /**
636
+ * wpsc display categories function
637
+ * Used to determine whether to display products on the page
638
+ * @return boolean - true for yes, false for no
639
+ */
640
+ function wpsc_display_categories() {
641
+ global $wp_query;
642
+ $output = false;
643
+ if ( !is_numeric( get_option( 'wpsc_default_category' ) ) && ! get_query_var( 'product_tag' ) ) {
644
+
645
+ if ( isset( $wp_query->query_vars['products'] ) )
646
+ $category_id = $wp_query->query_vars['products'];
647
+ else if ( isset( $_GET['products'] ) )
648
+ $category_id = $_GET['products'];
649
+
650
+ // if we have no categories, and no search, show the group list
651
+ if ( is_numeric( get_option( 'wpsc_default_category' ) ) || (isset( $product_id ) && is_numeric( $product_id )) )
652
+ $output = true;
653
+ if ( (get_option( 'wpsc_default_category' ) == 'all+list'))
654
+ $output = true;
655
+
656
+ if (get_option( 'wpsc_default_category' ) == 'list' && (!isset($wp_query->query_vars['wpsc_product_category']) || !isset($wp_query->query_vars['product_tag']) && get_option('wpsc_display_categories')))
657
+ $output = true;
658
+
659
+ }
660
+
661
+ if ( isset( $category_id ) && $category_id > 0 )
662
+ $output = false;
663
+ if ( get_option( 'wpsc_display_categories' ))
664
+ $output = true;
665
+
666
+ return $output;
667
+ }
668
+
669
+ /**
670
+ * wpsc product creation time function
671
+ * @return string - the product price
672
+ */
673
+ function wpsc_product_creation_time( $format = null ) {
674
+ global $wpsc_query;
675
+
676
+ if ( $format == null )
677
+ $format = "Y-m-d H:i:s";
678
+
679
+ return mysql2date( $format, $wpsc_query->product['date_added'] );
680
+ }
681
+
682
+ /**
683
+ * wpsc check variation stock availability function
684
+ * @return string - the product price
685
+ */
686
+ function wpsc_check_variation_stock_availability( $product_id, $variations ) {
687
+ global $wpdb;
688
+ $selected_post = get_posts( array(
689
+ 'post_parent' => $product_id,
690
+ 'post_type' => "wpsc-product",
691
+ 'post_status' => 'any',
692
+ 'suppress_filters' => true,
693
+ 'numberposts' => -1,
694
+ ) );
695
+
696
+ $selected_variation = false;
697
+
698
+ foreach ( $selected_post as $variation ) {
699
+ $matches = 0;
700
+ $terms = wpsc_get_product_terms( $variation->ID, 'wpsc-variation' );
701
+ foreach ( $terms as $term ) {
702
+ if ( in_array( $term->term_id, $variations ) )
703
+ $matches++;
704
+ }
705
+
706
+ if ( $matches == count( $variations ) ) {
707
+ $selected_variation = $variation->ID;
708
+ }
709
+ }
710
+
711
+ if ( ! $selected_variation )
712
+ return false;
713
+
714
+ if ( wpsc_product_has_stock( $selected_variation ) ) {
715
+ $stock = get_product_meta( $selected_variation, 'stock', true );
716
+ if ( $stock === '' )
717
+ return true;
718
+
719
+ return (int) $stock;
720
+ }
721
+
722
+ return 0;
723
+ }
724
+
725
+ /**
726
+ * wpsc product has stock function
727
+ * @return boolean - true if the product has stock or does not use stock, false if it does not
728
+ */
729
+ function wpsc_product_has_stock( $id = null ) {
730
+ global $wpdb;
731
+ // maybe do wpsc_clear_stock_claims first?
732
+ if ( is_numeric( $id ) && ( $id > 0 ) )
733
+ $id = absint( $id );
734
+ else
735
+ $id = get_the_ID();
736
+
737
+ $stock = get_post_meta( $id, '_wpsc_stock', true );
738
+ if ( $stock === '' )
739
+ return true;
740
+
741
+ $variations = get_children( array( "post_type" => "wpsc-product", "post_parent" => $id ) );
742
+ $filter_name = empty( $variations ) ? 'wpsc_product_stock' : 'wpsc_product_variation_stock';
743
+ $stock = apply_filters( $filter_name, (int) $stock, $id );
744
+
745
+ if ( ! empty( $variations ) ) {
746
+ foreach ( $variations as $variation ) {
747
+ if ( wpsc_product_has_stock( $variation->ID ) )
748
+ return true;
749
+ }
750
+ } elseif ( $stock > 0 ) {
751
+ $claimed_stock = $wpdb->get_var("SELECT SUM(`stock_claimed`) FROM `".WPSC_TABLE_CLAIMED_STOCK."` WHERE `product_id` IN($id)");
752
+ if( $stock - $claimed_stock > 0 )
753
+ return true;
754
+ }
755
+
756
+ return false;
757
+ }
758
+
759
+ /**
760
+ * wpsc_is_product_external( $product_id = 0 )
761
+ *
762
+ * Checks if current product is external.
763
+ *
764
+ * @param int $product_id
765
+ */
766
+ function wpsc_is_product_external( $product_id = 0 ) {
767
+
768
+ // Get product ID if incorrect value was passed
769
+ if ( empty( $product_id ) || !is_numeric( $product_id ) )
770
+ $product_id = wpsc_the_product_id();
771
+
772
+ // Get external link
773
+ $external_link = wpsc_product_external_link( $product_id );
774
+
775
+ // Use external if set
776
+ if ( !empty( $external_link ) )
777
+ return true;
778
+ else
779
+ return false;
780
+ }
781
+
782
+ /**
783
+ * wpsc product remaining stock function
784
+ * @return integer - the amount of remaining stock, or null if product is stockless
785
+ */
786
+ function wpsc_product_remaining_stock( $id = null ) {
787
+ if ( is_numeric( $id ) && ($id > 0) )
788
+ $id = absint( $id );
789
+ else
790
+ $id = get_the_ID();
791
+
792
+ $is_limited_stock = get_post_meta( $id, '_wpsc_stock', true );
793
+
794
+ if ( is_numeric( $is_limited_stock ) ) {
795
+ $product_stock = get_post_meta( $id, '_wpsc_stock', true );
796
+ return absint( $product_stock );
797
+ } else {
798
+ return null;
799
+ }
800
+ }
801
+
802
+ /**
803
+ * wpsc is donation function
804
+ * @return boolean - true if it is a donation, otherwise false
805
+ */
806
+ function wpsc_product_is_donation( $id = null ) {
807
+ if ( is_numeric( $id ) && ($id > 0) )
808
+ $id = absint( $id );
809
+ else
810
+ $id = get_the_ID();
811
+
812
+ $is_donation = get_post_meta( $id, '_wpsc_is_donation', true );
813
+ if ( $is_donation == 1 )
814
+ return true;
815
+ else
816
+ return false;
817
+
818
+ }
819
+
820
+ /**
821
+ * wpsc product on special function
822
+ * @return boolean - true if the product is on special, otherwise false
823
+ */
824
+ function wpsc_product_on_special( $id = 0 ) {
825
+ static $on_special = array();
826
+
827
+ global $wpsc_query, $wpdb;
828
+
829
+ if ( ! $id )
830
+ $id = get_the_ID();
831
+
832
+ if ( ! isset( $on_special[$id] ) ) {
833
+ // don't rely on product sales price if it has variations
834
+ if ( wpsc_product_has_variations( $id ) ) {
835
+ $sql = $wpdb->prepare("
836
+ SELECT p.id, CAST(pm.meta_value AS DECIMAL(10, 2)) AS sale_price
837
+ FROM {$wpdb->posts} AS p
838
+ INNER JOIN {$wpdb->postmeta} AS pm ON pm.post_id = p.id AND pm.meta_key = '_wpsc_special_price' AND pm.meta_value != '0' AND pm.meta_value != ''
839
+ INNER JOIN {$wpdb->postmeta} AS pm2 ON pm2.post_id = p.id AND pm2.meta_key = '_wpsc_stock' AND pm2.meta_value != '0'
840
+ INNER JOIN {$wpdb->postmeta} AS pm3 ON pm3.post_id = p.id AND pm3.meta_key = '_wpsc_price' AND CAST(pm3.meta_value AS DECIMAL(10,2)) > CAST(pm.meta_value AS DECIMAL(10,2))
841
+ WHERE
842
+ p.post_type = 'wpsc-product'
843
+ AND
844
+ p.post_parent = %d
845
+ ORDER BY sale_price ASC
846
+ ", $id );
847
+
848
+ $results = $wpdb->get_results( $sql );
849
+
850
+ $on_special[$id] = ! empty( $results );
851
+ } else {
852
+ $price = get_product_meta( $id, 'price', true );
853
+ $special_price = get_product_meta( $id, 'special_price', true );
854
+ $on_special[$id] = $special_price > 0 && $price > $special_price;
855
+ }
856
+ }
857
+
858
+ return $on_special[$id];
859
+ }
860
+
861
+ /**
862
+ * wpsc product is modifiable function
863
+ * @return boolean - true if the product has a file
864
+ */
865
+ function wpsc_product_is_customisable() {
866
+ global $wpsc_query, $wpdb;
867
+ $id = get_the_ID();
868
+ $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true );
869
+ if ( (isset($product_meta['engraved']) && $product_meta['engraved'] == true) || (isset($product_meta['can_have_uploaded_image']) && $product_meta['can_have_uploaded_image'] == true) )
870
+ return true;
871
+
872
+ return false;
873
+ }
874
+
875
+ /**
876
+ * wpsc product has personal text function
877
+ * @return boolean - true if the product has a file
878
+ */
879
+ function wpsc_product_has_personal_text() {
880
+ global $wpsc_query, $wpdb;
881
+ $id = get_the_ID();
882
+ $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true );
883
+ if ( isset($product_meta['engraved']) && $product_meta['engraved'] == true )
884
+ return true;
885
+
886
+ return false;
887
+ }
888
+
889
+ /**
890
+ * wpsc product has personal file function
891
+ * @return boolean - true if the product has a file
892
+ */
893
+ function wpsc_product_has_supplied_file() {
894
+ global $wpsc_query, $wpdb;
895
+ $id = get_the_ID();
896
+ $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true );
897
+ if ( isset($product_meta['can_have_uploaded_image']) && $product_meta['can_have_uploaded_image'] == true )
898
+ return true;
899
+
900
+ return false;
901
+ }
902
+
903
+ /**
904
+ * wpsc product postage and packaging function
905
+ * @return string - currently only valid for flat rate
906
+ */
907
+ function wpsc_product_postage_and_packaging() {
908
+ if ( isset( $id ) && is_numeric( $id ) && ($id > 0) )
909
+ $id = absint( $id );
910
+ else
911
+ $id = get_the_ID();
912
+
913
+ $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true );
914
+ if ( isset( $product_meta['shipping'] ) && is_array( $product_meta['shipping'] ) && 1 != $product_meta['no_shipping'])
915
+ return wpsc_currency_display( apply_filters( 'wpsc_product_postage_and_packaging', $product_meta['shipping']['local'] ) );
916
+ else
917
+ return wpsc_currency_display( 0 );
918
+
919
+
920
+ }
921
+
922
+ /**
923
+ * WPSC Product Image
924
+ *
925
+ * Gets the product image URL. Uses the post thumbnail if set.
926
+ *
927
+ * @param int $width Image width
928
+ * @param int $height Image height
929
+ * @param int $product_id Product ID
930
+ * @return string The URL to the thumbnail image
931
+ *
932
+ * @uses wpsc_the_product_thumbnail_id() Get the product thumbnail ID
933
+ */
934
+ function wpsc_the_product_image( $width = '', $height = '', $product_id = '' ) {
935
+ if ( empty( $product_id ) )
936
+ $product_id = get_the_ID();
937
+
938
+ // If variation, get parent product
939
+ $product = get_post( $product_id );
940
+ if ( $product->post_parent > 0 )
941
+ $product_id = $product->post_parent;
942
+
943
+ $src = false;
944
+
945
+ $product_thumbnail_id = wpsc_the_product_thumbnail_id( $product_id );
946
+ $src = wp_get_attachment_image_src( $product_thumbnail_id, 'large' );
947
+ $src = is_array( $src ) ? $src[0] : $src;
948
+
949
+ if ( is_ssl() && ! empty( $src ) )
950
+ $src = str_replace( 'http://', 'https://', $src );
951
+
952
+ // WordPress's esc_url() function strips out spaces, so encode them here to ensure they don't get stripped out
953
+ // Ref: http://core.trac.wordpress.org/ticket/23605
954
+ $src = str_replace( ' ', '%20', $src );
955
+
956
+ return apply_filters( 'wpsc_product_image', $src );
957
+ }
958
+
959
+ /**
960
+ * wpsc check display type
961
+ *
962
+ * Check the display view for the selected category
963
+ *
964
+ * @return string - display type
965
+ */
966
+ function wpsc_check_display_type(){
967
+ global $wpsc_query, $post;
968
+ if(isset($wpsc_query->query_vars['taxonomy']) && 'wpsc_product_category' == $wpsc_query->query_vars['taxonomy'] && is_string($wpsc_query->query_vars['term']) && 1 < $wpsc_query->post_count)
969
+ $display_type = wpsc_get_the_category_display($wpsc_query->query_vars['term']);
970
+ else
971
+ $display_type = get_option('product_view');
972
+ return $display_type;
973
+ }
974
+
975
+ /**
976
+ * wpsc product thumbnail function
977
+ *
978
+ * Show the thumbnail image for the product
979
+ *
980
+ * @return string - the URL to the thumbnail image
981
+ */
982
+ function wpsc_the_product_thumbnail( $width = null, $height = null, $product_id = 0, $page = false ) {
983
+ $thumbnail = false;
984
+ $display = wpsc_check_display_type();
985
+
986
+ // Get the product ID if none was passed
987
+ if ( empty( $product_id ) )
988
+ $product_id = get_the_ID();
989
+
990
+ // Load the product
991
+ $product = get_post( $product_id );
992
+
993
+ $thumbnail_id = wpsc_the_product_thumbnail_id( $product_id );
994
+
995
+ // If no thumbnail found for item, get it's parent image (props. TJM)
996
+ if ( ! $thumbnail_id && $product->post_parent )
997
+ $thumbnail_id = wpsc_the_product_thumbnail_id( $product->post_parent );
998
+
999
+ if ( ! $page ) {
1000
+ if ( is_single() )
1001
+ $page = 'single';
1002
+ else
1003
+ $page = 'products-page';
1004
+ }
1005
+
1006
+ if ( ! $width && ! $height ) {
1007
+ $width = get_option( 'product_image_width' );
1008
+ $height = get_option( 'product_image_height' );
1009
+
1010
+ // Overwrite height & width if custom dimensions exist for thumbnail_id
1011
+ if ( 'grid' != $display && 'products-page' == $page && isset( $thumbnail_id ) ) {
1012
+ $custom_width = get_post_meta( $thumbnail_id, '_wpsc_custom_thumb_w', true );
1013
+ $custom_height = get_post_meta( $thumbnail_id, '_wpsc_custom_thumb_h', true );
1014
+
1015
+ if ( ! empty( $custom_width ) && ! empty( $custom_height ) ) {
1016
+ $width = $custom_width;
1017
+ $height = $custom_height;
1018
+ }
1019
+ } elseif ( $page == 'single' && isset( $thumbnail_id ) ) {
1020
+ $custom_thumbnail = get_post_meta( $thumbnail_id, '_wpsc_selected_image_size', true );
1021
+
1022
+ if ( ! $custom_thumbnail ) {
1023
+ $custom_thumbnail = 'medium-single-product';
1024
+ $current_size = image_get_intermediate_size( $thumbnail_id, $custom_thumbnail );
1025
+ $settings_width = get_option( 'single_view_image_width' );
1026
+ $settings_height = get_option( 'single_view_image_height' );
1027
+
1028
+ if ( ! $current_size || ( $current_size['width'] != $settings_width && $current_size['height'] != $settings_height ) )
1029
+ _wpsc_regenerate_thumbnail_size( $thumbnail_id, $custom_thumbnail );
1030
+ }
1031
+ $src = wp_get_attachment_image_src( $thumbnail_id, $custom_thumbnail );
1032
+
1033
+ if ( ! empty( $src ) && is_string( $src[0] ) )
1034
+ $thumbnail = $src[0];
1035
+ } elseif ( $page == 'manage-products' && isset( $thumbnail_id ) ) {
1036
+ $current_size = image_get_intermediate_size( $thumbnail_id, 'admin-product-thumbnails' );
1037
+
1038
+ if ( ! $current_size )
1039
+ _wpsc_regenerate_thumbnail_size( $thumbnail_id, 'admin-product-thumbnails' );
1040
+
1041
+ $src = wp_get_attachment_image_src( $thumbnail_id, 'admin-product-thumbnails' );
1042
+
1043
+ if ( ! empty( $src ) && is_string( $src[0] ) )
1044
+ $thumbnail = $src[0];
1045
+ }
1046
+ }
1047
+
1048
+ // Calculate the height based on the ratio of the original dimensions.
1049
+ if ( $height == 0 || $width == 0 ) {
1050
+ $attachment_meta = get_post_meta( $thumbnail_id, '_wp_attachment_metadata', false );
1051
+ $original_width = $attachment_meta[0]['width'];
1052
+ $original_height = $attachment_meta[0]['height'];
1053
+
1054
+ if ( $width != 0 ) {
1055
+ $height = ( $original_height / $original_width ) * $width;
1056
+ $height = round( $height, 0 );
1057
+ } elseif ( $height != 0 ) {
1058
+ $width = ( $original_width / $original_height ) * $height;
1059
+ $width = round( $width, 0 );
1060
+ }
1061
+ }
1062
+
1063
+ if ( ! $thumbnail && isset( $thumbnail_id ) )
1064
+ $thumbnail = wpsc_product_image( $thumbnail_id, $width, $height );
1065
+
1066
+ if ( ! empty( $thumbnail ) && is_ssl() )
1067
+ $thumbnail = str_replace( 'http://', 'https://', $thumbnail );
1068
+
1069
+ // WordPress's esc_url() function strips out spaces, so encode them here to ensure they don't get stripped out
1070
+ // Ref: http://core.trac.wordpress.org/ticket/23605
1071
+ $thumbnail = str_replace( ' ', '%20', $thumbnail );
1072
+
1073
+ return $thumbnail;
1074
+ }
1075
+
1076
+ /**
1077
+ * Return the class(es) that should be applied to a product image's <a> tag.
1078
+ *
1079
+ * If the thickbox effect is enabled for product images (presentation setting), the thickbox class name is included
1080
+ *
1081
+ * This function is called from theme files when outputting product img tags
1082
+ *
1083
+ * @since 3.8
1084
+ * @return string space-separated list of class names (for use in a class="") attribute
1085
+ */
1086
+ function wpsc_the_product_image_link_classes() {
1087
+ $classes = array( );
1088
+ if ( get_option( 'show_thumbnails_thickbox' ) )
1089
+ $classes[] = 'thickbox';
1090
+
1091
+ $classes[] = 'preview_link';
1092
+
1093
+ $classes = apply_filters( 'wpsc_the_product_image_link_classes', $classes );
1094
+ return implode( ' ', $classes );
1095
+ }
1096
+
1097
+ /**
1098
+ * wpsc product comment link function
1099
+ * @return string - javascript required to make the intense debate link work
1100
+ */
1101
+ function wpsc_product_comment_link() {
1102
+ // add the product comment link
1103
+ global $wpsc_query;
1104
+
1105
+ if ( get_option( 'wpsc_enable_comments' ) == 1 ) {
1106
+ $enable_for_product = get_product_meta( get_the_ID(), 'enable_comments' );
1107
+
1108
+ if ( (get_option( 'wpsc_comments_which_products' ) == 1 && $enable_for_product == '') || $enable_for_product == 'yes' ) {
1109
+ $original = array( "&", "'", ":", "/", "@", "?", "=" );
1110
+ $entities = array( "%26", "%27", "%3A", "%2F", "%40", "%3F", "%3D" );
1111
+
1112
+ $output = "<div class=\"clear comments\">
1113
+ <script src='https://www.intensedebate.com/js/getCommentLink.php?acct=" . get_option( "wpsc_intense_debate_account_id" ) . "&postid=product_" . $wpsc_query->product['id'] . "&posttitle=" . urlencode( get_the_title() ) . "&posturl=" . str_replace( $original, $entities, get_permalink( get_the_ID() ) ) . "&posttime=" . urlencode( date( 'Y-m-d h:i:s', time() ) ) . "&postauthor=author_" . get_the_ID() . "' type='text/javascript' defer='defer'></script>
1114
+ </div>";
1115
+ }
1116
+ }
1117
+ return $output;
1118
+ }
1119
+
1120
+ /**
1121
+ * wpsc product comments function
1122
+ * @return string - javascript for the intensedebate comments
1123
+ */
1124
+ function wpsc_product_comments() {
1125
+ global $wpsc_query;
1126
+ $output = '';
1127
+ // add the product comments
1128
+ if ( get_option( 'wpsc_enable_comments' ) == 1 ) {
1129
+ $enable_for_product = get_product_meta( $wpsc_query->product['id'], 'enable_comments' );
1130
+
1131
+ if ( (get_option( 'wpsc_comments_which_products' ) == 1 && $enable_for_product == '') || $enable_for_product == 'yes' ) {
1132
+ $output = "<script>
1133
+ var idcomments_acct = '" . esc_js( get_option( 'wpsc_intense_debate_account_id' ) ) . "';
1134
+ var idcomments_post_id = 'product_" . $wpsc_query->product['id'] . "';
1135
+ var idcomments_post_url = encodeURIComponent('" . get_permalink( $wpsc_query->product['id'] ) . "');
1136
+ </script>
1137
+ <span id=\"IDCommentsPostTitle\" style=\"display:none\"></span>
1138
+ <script type='text/javascript' src='https://www.intensedebate.com/js/genericCommentWrapperV2.js'></script>
1139
+ ";
1140
+ }
1141
+ }
1142
+ return $output;
1143
+ }
1144
+
1145
+ /**
1146
+ * wpsc have custom meta function
1147
+ * @return boolean - true while we have custom meta to display
1148
+ */
1149
+ function wpsc_have_custom_meta() {
1150
+ global $wpsc_custom_meta;
1151
+ return esc_html( $wpsc_custom_meta->have_custom_meta() );
1152
+ }
1153
+
1154
+ /**
1155
+ * wpsc the custom meta function
1156
+ * @return nothing - iterate through the custom meta vallues
1157
+ */
1158
+ function wpsc_the_custom_meta() {
1159
+ global $wpsc_custom_meta;
1160
+ return esc_html( $wpsc_custom_meta->the_custom_meta() );
1161
+ }
1162
+
1163
+ /**
1164
+ * wpsc custom meta name function
1165
+ * @return string - the custom metal name
1166
+ */
1167
+ function wpsc_custom_meta_name() {
1168
+ global $wpsc_custom_meta;
1169
+ return esc_html( $wpsc_custom_meta->custom_meta_values['meta_key'] );
1170
+ }
1171
+
1172
+ /**
1173
+ * wpsc custom meta value function
1174
+ * @return string - the custom meta value
1175
+ */
1176
+ function wpsc_custom_meta_value() {
1177
+ global $wpsc_custom_meta;
1178
+ return esc_html( $wpsc_custom_meta->custom_meta_values['meta_value'] );
1179
+ }
1180
+
1181
+ /**
1182
+ * wpsc have variation groups function
1183
+ * @return boolean - true while we have variation groups
1184
+ */
1185
+ function wpsc_have_variation_groups() {
1186
+ global $wpsc_variations;
1187
+ return $wpsc_variations->have_variation_groups();
1188
+ }
1189
+
1190
+ /**
1191
+ * wpsc the variation group function
1192
+ * @return nothing - iterate through the variation groups
1193
+ */
1194
+ function wpsc_the_variation_group() {
1195
+ global $wpsc_variations;
1196
+ $wpsc_variations->the_variation_group();
1197
+ }
1198
+
1199
+ /**
1200
+ * wpsc have variations function
1201
+ * @return boolean - true while we have variations
1202
+ */
1203
+ function wpsc_have_variations() {
1204
+ global $wpsc_variations;
1205
+ return $wpsc_variations->have_variations();
1206
+ }
1207
+
1208
+ /**
1209
+ * wpsc the variation function
1210
+ * @return nothing - iterate through the variations
1211
+ */
1212
+ function wpsc_the_variation() {
1213
+ global $wpsc_variations;
1214
+ $wpsc_variations->the_variation();
1215
+ }
1216
+
1217
+
1218
+ function wpsc_product_has_multicurrency() {
1219
+ global $wpdb, $wpsc_query;
1220
+
1221
+ $currency = get_product_meta(get_the_ID(),'currency',true);
1222
+ if ( ! empty( $currency ) )
1223
+ return true;
1224
+ else
1225
+ return false;
1226
+ }
1227
+
1228
+ function wpsc_display_product_multicurrency() {
1229
+ global $wpdb, $wpsc_query;
1230
+
1231
+ $results = get_product_meta(get_the_ID(),'currency',true);
1232
+ if ( count( $results ) > 0 ) {
1233
+ foreach ( (array)$results as $isocode => $curr ) {
1234
+ echo apply_filters( 'wpsc_display_product_multicurrency', '<span class="wpscsmall pricefloatright pricedisplay">' . $isocode . ': ' . wpsc_currency_display( $curr, array( 'isocode' => $isocode ) ) . '</span><br />', $isocode, $curr );
1235
+ }
1236
+ }
1237
+
1238
+ return false;
1239
+ }
1240
+
1241
+ /**
1242
+ * wpsc variation group name function
1243
+ * @return string - the variation group name
1244
+ */
1245
+ function wpsc_the_vargrp_name() {
1246
+ global $wpsc_variations;
1247
+ return apply_filters( 'wpsc_vargrp_name', $wpsc_variations->variation_group->name, $wpsc_variations->variation_group );
1248
+ }
1249
+
1250
+ /**
1251
+ * wpsc variation group form ID function
1252
+ * @return string - the variation group form id, for labels and the like
1253
+ */
1254
+ function wpsc_vargrp_form_id() {
1255
+ // generate the variation group form ID;
1256
+ global $wpsc_variations, $wpsc_variations;
1257
+ $product_id = get_the_ID();
1258
+ $form_id = "variation_select_{$product_id}_{$wpsc_variations->variation_group->term_id}";
1259
+ return $form_id;
1260
+ }
1261
+
1262
+ /**
1263
+ * wpsc variation group ID function
1264
+ * @return integer - the variation group ID
1265
+ */
1266
+ function wpsc_vargrp_id() {
1267
+ global $wpsc_variations;
1268
+ return $wpsc_variations->variation_group->term_id;
1269
+ }
1270
+
1271
+ /**
1272
+ * wpsc the variation name function
1273
+ * @return string - the variation name
1274
+ */
1275
+ function wpsc_the_variation_name() {
1276
+ global $wpsc_variations;
1277
+ return esc_html( apply_filters( 'wpsc_variation_name', $wpsc_variations->variation->name ) );
1278
+ }
1279
+
1280
+ /**
1281
+ * wpsc the variation ID function
1282
+ * @return integer - the variation ID
1283
+ */
1284
+ function wpsc_the_variation_id() {
1285
+ global $wpsc_variations;
1286
+ return $wpsc_variations->variation->term_id;
1287
+ }
1288
+
1289
+ /**
1290
+ * wpsc the variation out_of_stock function
1291
+ * @return string - HTML attribute to disable select options and radio buttons
1292
+ */
1293
+ function wpsc_the_variation_out_of_stock() {
1294
+ global $wpsc_query, $wpdb, $wpsc_variations;
1295
+ $out_of_stock = false;
1296
+
1297
+ // If there is more than one variation group we cannot determine a stock status for individual variations
1298
+ // Also, if the item is not stock limited, there is no need to check variation stock status
1299
+ $product_id = get_the_ID();
1300
+
1301
+ $stock = get_product_meta( $product_id, 'stock', true );
1302
+ if ( ($wpsc_variations->variation_group_count == 1) && is_numeric( $stock ) && isset( $wpsc_variations->variation->slug ) ) {
1303
+
1304
+ $product_id = get_the_ID();
1305
+ $variation_group_id = $wpsc_variations->variation_group->term_id;
1306
+ $variation_id = $wpsc_variations->variation->term_id;
1307
+
1308
+ $wpq = array( 'variations' => $wpsc_variations->variation->slug,
1309
+ 'post_status' => 'inherit',
1310
+ 'post_type' => 'wpsc-product',
1311
+ 'post_parent' => $product_id );
1312
+ $query = new WP_Query( $wpq );
1313
+
1314
+ if ( $query->post_count != 1 ) {
1315
+ // Should never happen
1316
+ return FALSE;
1317
+ }
1318
+
1319
+ $variation_product_id = $query->posts[0]->ID;
1320
+
1321
+ $stock = get_product_meta( $variation_product_id, "stock" );
1322
+ $stock = $stock[0];
1323
+ if ( $stock < 1 ) {
1324
+ $out_of_stock = true;
1325
+ }
1326
+ }
1327
+
1328
+ if ( $out_of_stock == true )
1329
+ return "disabled='disabled'";
1330
+ else
1331
+ return '';
1332
+
1333
+ }
1334
+
1335
+ /**
1336
+ * wpsc product rater function
1337
+ * @return string - HTML to display the product rater
1338
+ */
1339
+ function wpsc_product_rater() {
1340
+ global $wpsc_query;
1341
+ $product_id = get_the_ID();
1342
+ $output = '';
1343
+ if ( get_option( 'product_ratings' ) == 1 ) {
1344
+ $output .= "<div class='product_footer'>";
1345
+
1346
+ $output .= "<div class='product_average_vote'>";
1347
+ $output .= "<strong>" . __( 'Avg. Customer Rating', 'wpsc' ) . ":</strong>";
1348
+ $output .= wpsc_product_existing_rating( $product_id );
1349
+ $output .= "</div>";
1350
+
1351
+ $output .= "<div class='product_user_vote'>";
1352
+
1353
+ $output .= "<strong><span id='rating_" . $product_id . "_text'>" . __( 'Your Rating', 'wpsc' ) . ":</span>";
1354
+ $output .= "<span class='rating_saved' id='saved_" . $product_id . "_text'> " . __( 'Saved', 'wpsc' ) . "</span>";
1355
+ $output .= "</strong>";
1356
+
1357
+ $output .= wpsc_product_new_rating( $product_id );
1358
+ $output .= "</div>";
1359
+ $output .= "</div>";
1360
+ }
1361
+ return $output;
1362
+ }
1363
+
1364
+ function wpsc_product_existing_rating( $product_id ) {
1365
+ global $wpdb;
1366
+ $get_average = $wpdb->get_results( $wpdb->prepare( "SELECT AVG(`rated`) AS `average`, COUNT(*) AS `count` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `productid`= %d ", $product_id ), ARRAY_A );
1367
+ $average = floor( $get_average[0]['average'] );
1368
+ $count = $get_average[0]['count'];
1369
+ $output = " <span class='votetext'>";
1370
+ for ( $l = 1; $l <= $average; ++$l ) {
1371
+ $output .= "<img class='goldstar' src='" . WPSC_CORE_IMAGES_URL . "/gold-star.png' alt='$l' title='$l' />";
1372
+ }
1373
+ $remainder = 5 - $average;
1374
+ for ( $l = 1; $l <= $remainder; ++$l ) {
1375
+ $output .= "<img class='goldstar' src='" . WPSC_CORE_IMAGES_URL . "/grey-star.png' alt='$l' title='$l' />";
1376
+ }
1377
+ $output .= "<span class='vote_total'>&nbsp;(<span id='vote_total_{$product_id}'>" . $count . "</span>)</span> \r\n";
1378
+ $output .= "</span> \r\n";
1379
+ return $output;
1380
+ }
1381
+
1382
+ function wpsc_product_new_rating( $product_id ) {
1383
+ global $wpdb;
1384
+
1385
+ $cookie_data = '';
1386
+ if (isset($_COOKIE['voting_cookie'][$product_id])) {
1387
+ $cookie_data = explode( ",", $_COOKIE['voting_cookie'][$product_id] );
1388
+ }
1389
+
1390
+ $vote_id = 0;
1391
+
1392
+ if ( isset($cookie_data[0]) && is_numeric( $cookie_data[0] ) )
1393
+ $vote_id = absint( $cookie_data[0] );
1394
+
1395
+ $previous_vote = 1;
1396
+ if ( $vote_id > 0 )
1397
+ $previous_vote = $wpdb->get_var( "SELECT `rated` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `id`='" . $vote_id . "' LIMIT 1" );
1398
+
1399
+ $output = "<form class='wpsc_product_rating' method='post'>\n";
1400
+ $output .= " <input type='hidden' name='wpsc_ajax_action' value='rate_product' />\n";
1401
+ $output .= " <input type='hidden' class='wpsc_rating_product_id' name='product_id' value='{$product_id}' />\n";
1402
+ $output .= " <select class='wpsc_select_product_rating' name='product_rating'>\n";
1403
+ $output .= " <option " . (($previous_vote == '1') ? "selected='selected'" : '') . " value='1'>1</option>\n";
1404
+ $output .= " <option " . (($previous_vote == '2') ? "selected='selected'" : '') . " value='2'>2</option>\n";
1405
+ $output .= " <option " . (($previous_vote == '3') ? "selected='selected'" : '') . " value='3'>3</option>\n";
1406
+ $output .= " <option " . (($previous_vote == '4') ? "selected='selected'" : '') . " value='4'>4</option>\n";
1407
+ $output .= " <option " . (($previous_vote == '5') ? "selected='selected'" : '') . " value='5'>5</option>\n";
1408
+ $output .= " </select>\n";
1409
+ $output .= " <input type='submit' value='" . __( 'Save', 'wpsc' ) . "'>";
1410
+ $output .= " </form>";
1411
+ return $output;
1412
+ }
1413
+
1414
+ /**
1415
+ * wpsc has pages function
1416
+ * @return boolean - true if we have pages
1417
+ */
1418
+ function wpsc_has_pages() {
1419
+ if(1 == get_option('use_pagination'))
1420
+ return true;
1421
+ else
1422
+ return false;
1423
+
1424
+ }
1425
+
1426
+ /**
1427
+ * this is for the multi adding property, it checks to see whether multi adding is enabled;
1428
+ *
1429
+ */
1430
+ function wpsc_has_multi_adding() {
1431
+ if ( get_option( 'multi_add' ) == 1 && (get_option( 'addtocart_or_buynow' ) != 1) ) {
1432
+ return true;
1433
+ } else {
1434
+ return false;
1435
+ }
1436
+ }
1437
+
1438
+ /**
1439
+ * wpsc product count function
1440
+ * @return string - the page URL
1441
+ */
1442
+ function wpsc_product_count() {
1443
+ global $wp_query;
1444
+ return count($wp_query->posts);
1445
+ }
1446
+
1447
+ //The following code was removed from WP 3.8, present in 3.7 - Not sure why it was removed and not refactored. (JS)
1448
+
1449
+ /**
1450
+ * wpsc the variation price function
1451
+ * @return string - the variation price
1452
+ */
1453
+ function wpsc_the_variation_price( $return_as_numeric = false ) {
1454
+ global $wpdb, $wpsc_variations;
1455
+ if ( $wpsc_variations->variation_count > 0 ) {
1456
+
1457
+ $product_id = get_the_ID();
1458
+ $wpq = array(
1459
+ 'variations' => $wpsc_variations->variation->slug,
1460
+ 'post_status' => array( 'inherit', 'publish' ),
1461
+ 'post_type' => 'wpsc-product',
1462
+ 'post_parent' => $product_id
1463
+ );
1464
+
1465
+ $query = new WP_Query( $wpq );
1466
+ // Should never happen
1467
+ if ( $query->post_count != 1 )
1468
+ return false;
1469
+
1470
+ $variation_product_id = $query->posts[0]->ID;
1471
+
1472
+ $price = get_product_meta( $variation_product_id, 'price',true );
1473
+ $special_price = get_product_meta( $variation_product_id, 'special_price', true );
1474
+
1475
+ if ( $special_price < $price && $special_price > 0 )
1476
+ $price = $special_price;
1477
+
1478
+ $price = apply_filters( 'wpsc_do_convert_price', $price, $product_id, $variation_product_id );
1479
+ $output = $return_as_numeric ? $price : wpsc_currency_display( $price, array( 'display_as_html' => false ) );
1480
+ } else {
1481
+ $output = false;
1482
+ }
1483
+
1484
+ return $output;
1485
+ }
1486
+
1487
+ /**
1488
+ * wpsc the variation stock function
1489
+ * @return mixed - Stock level for the variation or FALSE if it can't be calculated
1490
+ */
1491
+ function wpsc_the_variation_stock() {
1492
+ global $wpdb, $wpsc_variations;
1493
+
1494
+ if ( $wpsc_variations->variation_count > 0 ) {
1495
+
1496
+ $product_id = get_the_ID();
1497
+
1498
+ $wpq = array( 'variations' => $wpsc_variations->variation->slug,
1499
+ 'post_status' => 'inherit',
1500
+ 'post_type' => 'wpsc-product',
1501
+ 'post_parent' => $product_id );
1502
+
1503
+ $query = new WP_Query( $wpq );
1504
+
1505
+ // Should never happen
1506
+ if ( $query->post_count != 1 )
1507
+ return false;
1508
+
1509
+ // Get the stock count
1510
+ $vp_id = $query->posts[0]->ID;
1511
+ $stock = get_product_meta( $vp_id, "stock" );
1512
+ $stock[0] = apply_filters( 'wpsc_product_variation_stock', $stock[0], $id );
1513
+ $output = $stock[0];
1514
+ } else {
1515
+ return false;
1516
+ }
1517
+
1518
+ return $output;
1519
+ }
1520
+
1521
+ /**
1522
+ * wpsc_category_grid_view function
1523
+ * @return bool - whether the category is in grid view or not
1524
+ */
1525
+ function wpsc_category_grid_view(){
1526
+ if(get_option('wpsc_category_grid_view') == 1)
1527
+ return true;
1528
+ else
1529
+ return false;
1530
+ }
1531
+
1532
+ /**
1533
+ * wpsc_show_thumbnails function
1534
+ * @return bool - whether to show thumbnails or not
1535
+ */
1536
+ function wpsc_show_thumbnails(){
1537
+ return get_option('show_thumbnails');
1538
+ }
1539
+
1540
+ /**
1541
+ * gold_cart_display_gallery function
1542
+ * @return bool - whether to show gold cart gallery or not
1543
+ */
1544
+ function gold_cart_display_gallery(){
1545
+ return function_exists('gold_shpcrt_display_gallery');
1546
+ }
1547
+
1548
+ function wpsc_remove_currency_code( $args ) {
1549
+
1550
+ $args['display_currency_symbol'] = false;
1551
+ $args['display_currency_code'] = false;
1552
+
1553
+ return $args;
1554
+ }
1555
+
1556
+ function wpsc_you_save( $args = null ){
1557
+
1558
+ $defaults = array(
1559
+ 'product_id' => false,
1560
+ 'type' => 'percentage',
1561
+ 'variations' => false
1562
+ );
1563
+
1564
+ $args = wp_parse_args( $args, $defaults );
1565
+ extract( $args, EXTR_SKIP );
1566
+
1567
+ global $wpdb;
1568
+
1569
+ if ( ! $product_id )
1570
+ if(function_exists('wpsc_the_product_id')){
1571
+ //select the variation ID with lowest price
1572
+ $product_id = $wpdb->get_var('SELECT `posts`.`id` FROM ' . $wpdb->posts . ' `posts` JOIN ' . $wpdb->postmeta . ' `postmeta` ON `posts`.`id` = `postmeta`.`post_id` WHERE `posts`.`post_parent` = ' . wpsc_the_product_id() . ' AND `posts`.`post_type` = "wpsc-product" AND `posts`.`post_status` = "inherit" AND `postmeta`.`meta_key`="_wpsc_price" ORDER BY (`postmeta`.`meta_value`)+0 ASC LIMIT 1');
1573
+ if(!$product_id)
1574
+ $product_id=wpsc_the_product_id();
1575
+ }
1576
+
1577
+ if ( ! $product_id )
1578
+ return 0;
1579
+
1580
+ $regular_price = wpsc_calculate_price( $product_id, $variations, false );
1581
+ $sale_price = wpsc_calculate_price( $product_id, $variations, true );
1582
+
1583
+ switch( $type ){
1584
+ case "amount":
1585
+ return $regular_price - $sale_price;
1586
+ break;
1587
+
1588
+ default:
1589
+ if ( $regular_price == 0 )
1590
+ return 0;
1591
+ else
1592
+ return number_format( ( $regular_price - $sale_price ) / $regular_price * 100, 2 );
1593
+ }
1594
+ }
1595
+
1596
+ function wpsc_the_product_price_display( $args = array() ) {
1597
+ if ( empty( $args['id'] ) )
1598
+ $id = get_the_ID();
1599
+ else
1600
+ $id = (int) $args['id'];
1601
+
1602
+ $defaults = array(
1603
+ 'id' => $id,
1604
+ 'old_price_text' => __( 'Old Price: %s', 'wpsc' ),
1605
+ 'price_text' => __( 'Price: %s', 'wpsc' ),
1606
+ /* translators : %1$s is the saved amount text, %2$s is the saved percentage text, %% is the percentage sign */
1607
+ 'you_save_text' => __( 'You save: %s', 'wpsc' ),
1608
+ 'old_price_class' => 'pricedisplay wpsc-product-old-price ' . $id,
1609
+ 'old_price_before' => '<p %s>',
1610
+ 'old_price_after' => '</p>',
1611
+ 'old_price_amount_id' => 'old_product_price_' . $id,
1612
+ 'old_price_amount_class' => 'oldprice',
1613
+ 'old_price_amount_before' => '<span class="%1$s" id="%2$s">',
1614
+ 'old_price_amount_after' => '</span>',
1615
+ 'price_amount_id' => 'product_price_' . $id,
1616
+ 'price_class' => 'pricedisplay wpsc-product-price ' . $id,
1617
+ 'price_before' => '<p %s>',
1618
+ 'price_after' => '</p>',
1619
+ 'price_amount_class' => 'currentprice pricedisplay ' . $id,
1620
+ 'price_amount_before' => '<span class="%1$s" id="%2$s">',
1621
+ 'price_amount_after' => '</span>',
1622
+ 'you_save_class' => 'pricedisplay wpsc-product-you-save product_' . $id,
1623
+ 'you_save_before' => '<p %s>',
1624
+ 'you_save_after' => '</p>',
1625
+ 'you_save_amount_id' => 'yousave_' . $id,
1626
+ 'you_save_amount_class' => 'yousave',
1627
+ 'you_save_amount_before' => '<span class="%1$s" id="%2$s">',
1628
+ 'you_save_amount_after' => '</span>',
1629
+ 'output_price' => true,
1630
+ 'output_old_price' => true,
1631
+ 'output_you_save' => true,
1632
+ );
1633
+
1634
+ $r = wp_parse_args( $args, $defaults );
1635
+ extract( $r );
1636
+
1637
+ // if the product has no variations, these amounts are straight forward...
1638
+ $old_price = wpsc_product_normal_price( $id );
1639
+ $current_price = wpsc_the_product_price( false, false, $id );
1640
+ $you_save = wpsc_you_save( 'type=amount' ) . '! (' . wpsc_you_save() . '%)';
1641
+ $you_save_percentage = wpsc_you_save();
1642
+
1643
+ $show_old_price = $show_you_save = wpsc_product_on_special( $id );
1644
+
1645
+ // but if the product has variations and at least one of the variations is on special, we have
1646
+ // a few edge cases...
1647
+ if ( wpsc_product_has_variations( $id ) && wpsc_product_on_special( $id ) ) {
1648
+ // generally it doesn't make sense to display "you save" amount unless the user has selected
1649
+ // a specific variation
1650
+ $show_you_save = false;
1651
+
1652
+ $old_price_number = wpsc_product_variation_price_from( $id, array( 'only_normal_price' => true ) );
1653
+ $current_price_number = wpsc_product_variation_price_from( $id );
1654
+
1655
+ // if coincidentally, one of the variations are not on special, but its price is equal to
1656
+ // or lower than the lowest variation sale price, old price should be hidden, and current
1657
+ // price should reflect the "normal" price, not the sales price, to avoid confusion
1658
+ if ( $old_price_number == $current_price_number ) {
1659
+ $show_old_price = false;
1660
+ $current_price = wpsc_product_normal_price( $id );
1661
+ }
1662
+ }
1663
+
1664
+ // replace placeholders in arguments with correct values
1665
+ $old_price_class = apply_filters( 'wpsc_the_product_price_display_old_price_class', $old_price_class, $id );
1666
+ $old_price_amount_class = apply_filters( 'wpsc_the_product_price_display_old_price_amount_class', $old_price_amount_class, $id );
1667
+ $attributes = 'class="' . esc_attr( $old_price_class ) . '"';
1668
+ if ( ! $show_old_price )
1669
+ $attributes .= ' style="display:none;"';
1670
+ $old_price_before = sprintf( $old_price_before, $attributes );
1671
+ $old_price_amount_before = sprintf( $old_price_amount_before, esc_attr( $old_price_amount_class ), esc_attr( $old_price_amount_id ) );
1672
+
1673
+ $price_class = 'class="' . esc_attr( apply_filters( 'wpsc_the_product_price_display_price_class', esc_attr( $price_class ), $id ) ) . '"';
1674
+ $price_amount_class = apply_filters( 'wpsc_the_product_price_display_price_amount_class', esc_attr( $price_amount_class ), $id );
1675
+ $price_before = sprintf( $price_before, $price_class );
1676
+ $price_amount_before = sprintf( $price_amount_before, esc_attr( $price_amount_class ), esc_attr( $price_amount_id ) );
1677
+
1678
+ $you_save_class = apply_filters( 'wpsc_the_product_price_display_you_save_class', $you_save_class, $id );
1679
+ $you_save_amount_class = apply_filters( 'wpsc_the_product_price_display_you_save_amount_class', $you_save_amount_class, $id );
1680
+ $attributes = 'class="' . esc_attr( $you_save_class ) . '"';
1681
+ if ( ! $show_you_save )
1682
+ $attributes .= ' style="display:none;"';
1683
+ $you_save_before = sprintf( $you_save_before, $attributes );
1684
+ $you_save_amount_before = sprintf( $you_save_amount_before, esc_attr( $you_save_amount_class ), esc_attr( $you_save_amount_id ) );
1685
+ $you_save = wpsc_currency_display ( $you_save );
1686
+
1687
+ $old_price = $old_price_amount_before . $old_price . $old_price_amount_after;
1688
+ $current_price = $price_amount_before . $current_price . $price_amount_after;
1689
+ $you_save = $you_save_amount_before . $you_save . $you_save_amount_after;
1690
+
1691
+ $old_price_text = sprintf( $old_price_text, $old_price );
1692
+ $price_text = sprintf( $price_text, $current_price );
1693
+ $you_save_text = sprintf( $you_save_text, $you_save );
1694
+
1695
+ if ( $output_old_price )
1696
+ echo $old_price_before . $old_price_text . $old_price_after . "\n";
1697
+
1698
+ if ( $output_price )
1699
+ echo $price_before . $price_text . $price_after . "\n";
1700
+
1701
+ if ( $output_you_save )
1702
+ echo $you_save_before . $you_save_text . $you_save_after . "\n";
1703
+ }
1704
+
1705
+ /**
1706
+ * wpsc_form_action
1707
+ *
1708
+ * Echo the form action for use in the template files
1709
+ *
1710
+ * @global <type> $wpec_form_action
1711
+ * @return <type>
1712
+ */
1713
+ function wpsc_form_action() {
1714
+ echo wpsc_get_form_action();
1715
+ }
1716
+ /**
1717
+ * wpsc_get_form_action
1718
+ *
1719
+ * Return the form action for use in the template files
1720
+ *
1721
+ * @global <type> $wpec_form_action
1722
+ * @return <type>
1723
+ */
1724
+ function wpsc_get_form_action() {
1725
+ global $wpec_form_action;
1726
+
1727
+ $product_id = wpsc_the_product_id();
1728
+
1729
+ // Function has already ran in this page load
1730
+ if ( isset( $wpec_form_action ) ) {
1731
+ $action = $wpec_form_action;
1732
+
1733
+ // No global so figure it out
1734
+ } else {
1735
+
1736
+ // Use external if set
1737
+ if ( wpsc_is_product_external() ) {
1738
+ $action = wpsc_product_external_link( $product_id );
1739
+
1740
+ // Otherwise use this page
1741
+ } else {
1742
+ $action = wpsc_this_page_url();
1743
+ }
1744
+ }
1745
+
1746
+ // Return form action
1747
+ return $action;
1748
+ }
1749
+
wpsc-components/theme-engine-v1/helpers/template.php ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ add_action( 'wp', 'wpsc_select_theme_functions', 10, 1 );
3
+ add_filter( 'body_class', 'wpsc_body_class' );
4
+
5
+ /**
6
+ * wpsc_is_product function.
7
+ *
8
+ * @since 3.8
9
+ * @access public
10
+ * @return boolean
11
+ */
12
+ function wpsc_is_product() {
13
+ global $wp_query, $rewrite_rules;
14
+ $tmp = false;
15
+
16
+ if ( isset( $wp_query->is_product ) )
17
+ $tmp = $wp_query->is_product;
18
+
19
+ return $tmp;
20
+ }
21
+
22
+ /**
23
+ * wpsc_is_product function.
24
+ *
25
+ * @since 3.8
26
+ * @access public
27
+ * @return boolean
28
+ */
29
+ function wpsc_is_checkout() {
30
+ global $wp_query, $rewrite_rules;
31
+ $tmp = false;
32
+
33
+ if ( isset( $wp_query->is_checkout ) )
34
+ $tmp = $wp_query->is_checkout;
35
+
36
+ return $tmp;
37
+ }
38
+
39
+ /**
40
+ * wpsc_get_product_template function.
41
+ *
42
+ * @since 3.8
43
+ * @access public
44
+ * @return void
45
+ */
46
+ function wpsc_get_template( $template ) {
47
+ return get_query_template( $template );
48
+ }
49
+
50
+ /**
51
+ * wpsc_product_template_fallback function.
52
+ *
53
+ * @since 3.8
54
+ * @access public
55
+ * @param mixed $template_path
56
+ * @return string - the corrected template path
57
+ */
58
+ function wpsc_template_fallback( $template_path ) {
59
+
60
+ $prospective_file_name = basename( "{$template_path}.php" );
61
+ $prospective_file_path = trailingslashit( WPSC_CORE_THEME_PATH ) . $prospective_file_name;
62
+
63
+ if ( !file_exists( $prospective_file_path ) )
64
+ exit( $prospective_file_path );
65
+
66
+ return $prospective_file_path;
67
+ }
68
+
69
+ function wpsc_products_template_fallback() {
70
+ return wpsc_template_fallback( 'products' );
71
+ }
72
+
73
+ function wpsc_checkout_template_fallback() {
74
+ return wpsc_template_fallback( 'checkout' );
75
+ }
76
+
77
+ /**
78
+ * wpsc_template_loader function.
79
+ *
80
+ * @since 3.8
81
+ * @access public
82
+ * @return void
83
+ */
84
+ function wpsc_template_loader() {
85
+ global $wp_query;
86
+
87
+ if ( wpsc_is_product() && $template = wpsc_get_template( 'products' ) ) {
88
+ include( $template );
89
+ exit();
90
+ }
91
+
92
+ if ( wpsc_is_checkout() && $template = wpsc_get_template( 'checkout' ) ) {
93
+ include( $template );
94
+ exit();
95
+ }
96
+ }
97
+
98
+ /**
99
+ * select_wpsc_theme_functions function, provides a place to override the e-commece theme path
100
+ * add to switch "theme's functions file
101
+ * © with xiligroup dev
102
+ */
103
+ function wpsc_select_theme_functions() {
104
+ $selected_theme = get_option( 'wpsc_selected_theme' );
105
+ if ( !empty( $selected_theme ) && file_exists( WPSC_CORE_THEME_PATH . '/' . WPSC_THEME_DIR . '.php' ) )
106
+ include_once( WPSC_CORE_THEME_PATH . '/' . WPSC_THEME_DIR . '.php' );
107
+ }
108
+
109
+ /**
110
+ * Body Class Filter
111
+ * @modified: 2009-10-14 by Ben
112
+ * @description: Adds additional wpsc classes to the body tag.
113
+ * @param: $classes = Array of body classes
114
+ * @return: (Array) of classes
115
+ */
116
+ function wpsc_body_class( $classes ) {
117
+ global $wp_query, $wpsc_query;
118
+ $post_id = 0;
119
+ if ( isset( $wp_query->post->ID ) )
120
+ $post_id = $wp_query->post->ID;
121
+ $page_url = get_permalink( $post_id );
122
+
123
+ // If on a product or category page...
124
+ if ( get_option( 'product_list_url' ) == $page_url ) {
125
+
126
+ $classes[] = 'wpsc';
127
+
128
+ if ( !is_array( $wpsc_query->query ) )
129
+ $classes[] = 'wpsc-home';
130
+
131
+ if ( wpsc_is_single_product ( ) ) {
132
+ $classes[] = 'wpsc-single-product';
133
+ if ( absint( $wpsc_query->products[0]['id'] ) > 0 ) {
134
+ $classes[] = 'wpsc-single-product-' . $wpsc_query->products[0]['id'];
135
+ }
136
+ }
137
+
138
+ if ( wpsc_is_in_category() && !wpsc_is_single_product() )
139
+ $classes[] = 'wpsc-category';
140
+
141
+ if ( isset( $wpsc_query->query_vars['category_id'] ) && absint( $wpsc_query->query_vars['category_id'] ) > 0 )
142
+ $classes[] = 'wpsc-category-' . $wpsc_query->query_vars['category_id'];
143
+
144
+ }
145
+
146
+ // If viewing the shopping cart...
147
+ if ( get_option( 'shopping_cart_url' ) == $page_url ) {
148
+ $classes[] = 'wpsc';
149
+ $classes[] = 'wpsc-shopping-cart';
150
+ }
151
+
152
+ // If viewing the transaction...
153
+ if ( get_option( 'transact_url' ) == $page_url ) {
154
+ $classes[] = 'wpsc';
155
+ $classes[] = 'wpsc-transaction-details';
156
+ }
157
+
158
+ // If viewing your account...
159
+ if ( get_option( 'user_account_url' ) == $page_url ) {
160
+ $classes[] = 'wpsc';
161
+ $classes[] = 'wpsc-user-account';
162
+ }
163
+
164
+ return $classes;
165
+ }
166
+
167
+ /**
168
+ * Checks the active theme folder for the particular file, if it exists then return the active theme directory otherwise
169
+ * return the global wpsc_theme_path
170
+ * @access public
171
+ *
172
+ * @since 3.8
173
+ * @param $file string filename
174
+ * @return PATH to the file
175
+ */
176
+ function wpsc_get_template_file_path( $file = '' ){
177
+
178
+ // If we're not looking for a file, do not proceed
179
+ if ( empty( $file ) )
180
+ return;
181
+
182
+ // No cache, so find one and set it
183
+ if ( false === ( $file_path = get_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file ) ) ) {
184
+ // Look for file in stylesheet
185
+ if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
186
+ $file_path = get_stylesheet_directory() . '/' . $file;
187
+
188
+ // Look for file in template
189
+ } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
190
+ $file_path = get_template_directory() . '/' . $file;
191
+
192
+ // Backwards compatibility
193
+ } else {
194
+ // Look in old theme path
195
+ $selected_theme_check = WPSC_OLD_THEMES_PATH . get_option( 'wpsc_selected_theme' ) . '/' . str_ireplace( 'wpsc-', '', $file );
196
+
197
+ // Check the selected theme
198
+ if ( file_exists( $selected_theme_check ) ) {
199
+ $file_path = $selected_theme_check;
200
+
201
+ // Use the bundled file
202
+ } else {
203
+ $file_path = path_join( WPSC_CORE_THEME_PATH, $file );
204
+ }
205
+ }
206
+ // Save the transient and update it every 12 hours
207
+ if ( !empty( $file_path ) )
208
+ set_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file, $file_path, 60 * 60 * 12 );
209
+
210
+ }elseif(!file_exists($file_path)){
211
+ delete_transient(WPEC_TRANSIENT_THEME_PATH_PREFIX . $file);
212
+ wpsc_get_template_file_path($file);
213
+ }
214
+
215
+ // Return filtered result
216
+ return apply_filters( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file, $file_path );
217
+ }
218
+
219
+ /**
220
+ * Featured Product
221
+ *
222
+ * Refactoring Featured Product Plugin to utilize Sticky Post Status, available since WP 2.7
223
+ * also utilizes Featured Image functionality, available as post_thumbnail since 2.9, Featured Image since 3.0
224
+ * Main differences - Removed 3.8 conditions, removed meta box from admin, changed meta_values
225
+ * Removes shortcode, as it automatically ties in to top_of_page hook if sticky AND featured product exists.
226
+ *
227
+ * @package wp-e-commerce
228
+ * @since 3.8
229
+ */
230
+ function wpsc_the_sticky_image( $product_id ) {
231
+ $attached_images = (array)get_posts( array(
232
+ 'post_type' => 'attachment',
233
+ 'numberposts' => 1,
234
+ 'post_status' => null,
235
+ 'post_parent' => $product_id,
236
+ 'orderby' => 'menu_order',
237
+ 'order' => 'ASC'
238
+ ) );
239
+ if ( has_post_thumbnail( $product_id ) ) {
240
+ add_image_size( 'featured-product-thumbnails', 540, 260, TRUE );
241
+ $image = get_the_post_thumbnail( $product_id, 'featured-product-thumbnails' );
242
+ return $image;
243
+ } elseif ( !empty( $attached_images ) ) {
244
+ $attached_image = $attached_images[0];
245
+ $image_link = wpsc_product_image( $attached_image->ID, 540, 260 );
246
+ return '<img src="' . $image_link . '" alt="" />';
247
+ } else {
248
+ return false;
249
+ }
250
+ }
251
+
252
+ /**
253
+ * WPSC canonical URL function
254
+ * Needs a recent version
255
+ * @since 3.7
256
+ * @param int product id
257
+ * @return bool true or false
258
+ */
259
+ function wpsc_change_canonical_url( $url = '' ) {
260
+ global $wpdb, $wp_query, $wpsc_page_titles;
261
+
262
+ if ( $wp_query->is_single == true && 'wpsc-product' == $wp_query->query_vars['post_type']) {
263
+ $url = get_permalink( $wp_query->get_queried_object()->ID );
264
+ }
265
+ return apply_filters( 'wpsc_change_canonical_url', $url );
266
+ }
267
+
268
+ add_filter( 'aioseop_canonical_url', 'wpsc_change_canonical_url' );
269
+
270
+ function wpsc_insert_canonical_url() {
271
+ $wpsc_url = wpsc_change_canonical_url( null );
272
+ echo "<link rel='canonical' href='$wpsc_url' />\n";
273
+ }
274
+
275
+ function wpsc_canonical_url() {
276
+ $wpsc_url = wpsc_change_canonical_url( null );
277
+ if ( $wpsc_url != null ) {
278
+ remove_action( 'wp_head', 'rel_canonical' );
279
+ add_action( 'wp_head', 'wpsc_insert_canonical_url' );
280
+ }
281
+ }
282
+ add_action( 'template_redirect', 'wpsc_canonical_url' );
283
+
wpsc-components/theme-engine-v1/helpers/thumbnails.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'wpsc_loaded', 'wpsc_core_load_thumbnail_sizes' );
4
+ add_action( 'after_setup_theme', 'wpsc_check_thumbnail_support', 99 );
5
+ add_filter( 'intermediate_image_sizes_advanced', 'wpsc_intermediate_image_sizes_advanced', 10, 1 );
6
+
7
+ function wpsc_check_thumbnail_support() {
8
+ if ( !current_theme_supports( 'post-thumbnails' ) ) {
9
+ add_theme_support( 'post-thumbnails' );
10
+ add_action( 'init', 'wpsc_remove_post_type_thumbnail_support' );
11
+ }
12
+ }
13
+
14
+ function wpsc_remove_post_type_thumbnail_support() {
15
+ remove_post_type_support( 'post', 'thumbnail' );
16
+ remove_post_type_support( 'page', 'thumbnail' );
17
+ }
18
+
19
+ function wpsc_intermediate_image_sizes_advanced($sizes){
20
+ $sizes['small-product-thumbnail']=array(
21
+ "width" => get_option( 'product_image_width' ),
22
+ "height" => get_option( 'product_image_height' ),
23
+ "crop" => get_option( 'wpsc_crop_thumbnails', false )
24
+ );
25
+ $sizes['medium-single-product']=array(
26
+ "width" => get_option( 'single_view_image_width' ),
27
+ "height" => get_option( 'single_view_image_height' ),
28
+ "crop" => get_option( 'wpsc_crop_thumbnails', false )
29
+ );
30
+ $sizes['featured-product-thumbnails']=array(
31
+ "width" => 425,
32
+ "height" => 215,
33
+ "crop" => get_option( 'wpsc_crop_thumbnails', true )
34
+ );
35
+ $sizes['admin-product-thumbnails']=array(
36
+ "width" => 38,
37
+ "height" => 38,
38
+ "crop" => get_option( 'wpsc_crop_thumbnails', true )
39
+ );
40
+ $sizes['product-thumbnails']=array(
41
+ "width" => get_option( 'product_image_width' ),
42
+ "height" => get_option( 'product_image_height' ),
43
+ "crop" => get_option( 'wpsc_crop_thumbnails', false )
44
+ );
45
+ $sizes['gold-thumbnails']=array(
46
+ "width" => get_option( 'wpsc_gallery_image_width' ),
47
+ "height" => get_option( 'wpsc_gallery_image_height' ),
48
+ "crop" => get_option( 'wpsc_crop_thumbnails', false )
49
+ );
50
+ return $sizes;
51
+ }
52
+
53
+ /**
54
+ *
55
+ * wpsc_core_load_thumbnail_sizes()
56
+ *
57
+ * Load up the WPEC core thumbnail sizes
58
+ * @todo Remove hardcoded sizes
59
+ */
60
+ function wpsc_core_load_thumbnail_sizes() {
61
+ // Add image sizes for products
62
+ add_image_size( 'product-thumbnails', get_option( 'product_image_width' ), get_option( 'product_image_height' ), get_option( 'wpsc_crop_thumbnails', false ) );
63
+ add_image_size( 'gold-thumbnails', get_option( 'wpsc_gallery_image_width' ), get_option( 'wpsc_gallery_image_height' ), get_option( 'wpsc_crop_thumbnails', false ) );
64
+ add_image_size( 'admin-product-thumbnails', 38, 38, get_option( 'wpsc_crop_thumbnails', true ) );
65
+ add_image_size( 'featured-product-thumbnails', 425, 215, get_option( 'wpsc_crop_thumbnails', true ) );
66
+ add_image_size( 'small-product-thumbnail', get_option( 'product_image_width' ), get_option( 'product_image_height' ), get_option( 'wpsc_crop_thumbnails', false ) );
67
+ add_image_size( 'medium-single-product', get_option( 'single_view_image_width' ), get_option( 'single_view_image_height' ), get_option( 'wpsc_crop_thumbnails', false) );
68
+ }
wpsc-includes/rss_template.php → wpsc-components/theme-engine-v1/rss/rss.php RENAMED
@@ -15,7 +15,7 @@
15
  <guid><![CDATA[<?php echo wpsc_the_product_permalink(); ?>]]></guid>
16
  <g:price><![CDATA[<?php echo wpsc_product_normal_price(true); ?>]]></g:price>
17
  <g:image_link><![CDATA[<?php echo wpsc_the_product_thumbnail(); ?>]]></g:image_link>
18
- </item>
19
  <?php endwhile; ?>
20
  </channel>
21
  </rss>
15
  <guid><![CDATA[<?php echo wpsc_the_product_permalink(); ?>]]></guid>
16
  <g:price><![CDATA[<?php echo wpsc_product_normal_price(true); ?>]]></g:price>
17
  <g:image_link><![CDATA[<?php echo wpsc_the_product_thumbnail(); ?>]]></g:image_link>
18
+ </item>
19
  <?php endwhile; ?>
20
  </channel>
21
  </rss>
wpsc-components/theme-engine-v1/templates/compatibility.css ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Generalised theme compatibility fixes, the shopping cart does not need bullets
3
+ */
4
+
5
+ li.widget_wp_shopping_cart ul {
6
+ list-style-image: none !important;
7
+ list-style-type: none !important;
8
+ }
9
+
10
+ li.widget_wp_shopping_cart ul li {
11
+ list-style-image: none !important;
12
+ list-style-type: none !important;
13
+ background: none !important;
14
+ }
15
+
16
+ li.widget_wp_shopping_cart ul li:before{
17
+ /* Countermand any content properties like the one in the default wordpress theme. */
18
+ content: "" !important;
19
+ }
20
+
21
+
22
+ div.categorydisplay ul li:before{
23
+ /* Countermand any content properties like the one in the default wordpress theme. */
24
+ content: "" !important;
25
+ }
26
+
27
+ a.additional_description_link img {
28
+ margin:0px 3px 0px 0px;
29
+ }
30
+
31
+ div.textcol form {
32
+ min-width: 300px;
33
+ }
34
+
35
+ div.wpsc_loading_animation {
36
+ visibility: hidden;
37
+ }
38
+
39
+ #idc-container-parent{
40
+ clear:both;
41
+
42
+ }
43
+ table.wpsc_checkout_table label{
44
+ display:inline;
45
+ padding-right:10px;
46
+ }
47
+ aside.widget_wpsc_product_specials span.oldprice {
48
+ text-decoration: line-through;
49
+ color: #666;
50
+ }
wpsc-components/theme-engine-v1/templates/functions/wpsc-transaction_results_functions.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * transaction_results function main function for creating the purchase reports, transaction results page, and email receipts
5
+ * @access public
6
+ *
7
+ * @since 3.7
8
+ * @param $sessionid (string) unique session id
9
+ * @param echo_to_screen (boolean) whether to output the results or return them (potentially redundant)
10
+ * @param $transaction_id (int) the transaction id
11
+ */
12
+ function transaction_results( $sessionid, $display_to_screen = true, $transaction_id = null ) {
13
+ global $message_html, $echo_to_screen, $wpsc_cart, $purchase_log;
14
+
15
+ // pre-3.8.9 variable
16
+ $echo_to_screen = $display_to_screen;
17
+
18
+ $purchase_log_object = new WPSC_Purchase_Log( $sessionid, 'sessionid' );
19
+
20
+ // compatibility with pre-3.8.9 templates where they use a global
21
+ // $purchase_log object which is simply just a database row
22
+ $purchase_log = $purchase_log_object->get_data();
23
+
24
+ // pre-3.8.9 templates also use this global variable
25
+ $message_html = wpsc_get_transaction_html_output( $purchase_log_object );
26
+
27
+ $wpsc_cart->empty_cart();
28
+
29
+ do_action( 'wpsc_transaction_results_shutdown', $purchase_log_object, $sessionid, $display_to_screen );
30
+
31
+ return $message_html;
32
+ }
33
+
34
+ function wpsc_transaction_html_output() {
35
+ global $message_html;
36
+ echo $message_html;
37
+ }
38
+
39
+ function wpsc_transaction_theme() {
40
+ global $wpdb, $user_ID, $nzshpcrt_gateways, $sessionid, $cart_log_id, $errorcode;
41
+ $errorcode = '';
42
+ $transactid = '';
43
+ $dont_show_transaction_results = false;
44
+ if ( isset( $_GET['sessionid'] ) )
45
+ $sessionid = $_GET['sessionid'];
46
+
47
+ if ( !isset( $_GET['sessionid'] ) && isset( $_GET['ms'] ) )
48
+ $sessionid = $_GET['ms'];
49
+
50
+ if ( isset( $_GET['gateway'] ) && 'google' == $_GET['gateway'] ) {
51
+ wpsc_google_checkout_submit();
52
+ wpsc_delete_customer_meta( 'checkout_session_id' );
53
+ }
54
+
55
+ $selected_gateway = wpsc_get_customer_meta( 'selected_gateway' );
56
+ if ( $selected_gateway && in_array( $selected_gateway, array( 'paypal_certified', 'wpsc_merchant_paypal_express' ) ) )
57
+ $sessionid = wpsc_get_customer_meta( 'paypal_express_sessionid' );
58
+
59
+ if ( isset( $_REQUEST['eway'] ) && '1' == $_REQUEST['eway'] )
60
+ $sessionid = $_GET['result'];
61
+ elseif ( isset( $_REQUEST['eway'] ) && '0' == $_REQUEST['eway'] )
62
+ echo wpsc_get_customer_meta( 'eway_message' );
63
+ elseif ( isset( $_REQUEST['payflow'] ) && '1' == $_REQUEST['payflow'] ){
64
+ echo wpsc_get_customer_meta( 'payflow_message' );
65
+ wpsc_delete_customer_meta( 'payflow_message' );
66
+ }
67
+
68
+ $dont_show_transaction_results = false;
69
+
70
+ if ( $selected_gateway ) {
71
+ // Replaces the ugly if else for gateways
72
+ switch( $selected_gateway ){
73
+ case 'paypal_certified':
74
+ case 'wpsc_merchant_paypal_express':
75
+ echo wpsc_get_customer_meta( 'paypal_express_message' );
76
+
77
+ $reshash = wpsc_get_customer_meta( 'paypal_express_reshash' );
78
+ if( isset( $reshash['PAYMENTINFO_0_TRANSACTIONTYPE'] ) && in_array( $reshash['PAYMENTINFO_0_TRANSACTIONTYPE'], array( 'expresscheckout', 'cart' ) ) )
79
+ $dont_show_transaction_results = false;
80
+ else
81
+ $dont_show_transaction_results = true;
82
+ break;
83
+ case 'dps':
84
+ $sessionid = decrypt_dps_response();
85
+ break;
86
+ //paystation was not updating the purchase logs for successful payment - this is ugly as need to have the databse update done in one place by all gatways on a sucsessful transaction hook not some within the gateway and some within here and some not at all??? This is getting a major overhaul but for here and now it just needs to work for the gold cart people!
87
+ case 'paystation':
88
+ $ec = $_GET['ec'];
89
+ $result= $_GET['em'];
90
+
91
+ if($result == 'Transaction successful' && $ec == 0)
92
+ $processed_id = '3';
93
+
94
+ if($result == 'Insufficient Funds' && $ec == 5){
95
+ $processed_id = '6';
96
+
97
+ $payment_instructions = printf( __( 'Sorry your transaction was not accepted due to insufficient funds <br /><a href="%1$s">Click here to go back to checkout page</a>.', 'wpsc' ), get_option( "shopping_cart_url" ) );
98
+ }
99
+ if ( $processed_id )
100
+ wpsc_update_purchase_log_status( $sessionid, $processed_id, 'sessionid' );
101
+
102
+ break;
103
+ case 'wpsc_merchant_paymentexpress' :
104
+ // Payment Express sends back there own session id, which is temporarily stored in the Auth field
105
+ // so just swapping that over here
106
+ $result = $wpdb->get_var( $wpdb->prepare( "SELECT `sessionid` FROM `" .WPSC_TABLE_PURCHASE_LOGS. "` WHERE `authcode` = %s", $sessionid ) );
107
+ if($result != null){
108
+ // just in case they are using an older version old gold cart (pre 2.9.5)
109
+ $sessionid = $result;
110
+ $dont_show_transaction_results = true;
111
+ }
112
+ break;
113
+ case 'eway_hosted':
114
+ $sessionid = decrypt_eway_uk_response();
115
+ break;
116
+ //default filter for other payment gateways to use
117
+ default:
118
+ $sessionid = apply_filters('wpsc_previous_selected_gateway_' . $selected_gateway, $sessionid);
119
+ break;
120
+ }
121
+ }
122
+
123
+ if( ! $dont_show_transaction_results ) {
124
+ if ( !empty($sessionid) ){
125
+ $cart_log_id = $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= %s LIMIT 1", $sessionid ) );
126
+ return transaction_results( $sessionid, true );
127
+ }else
128
+ printf( __( 'Sorry your transaction was not accepted.<br /><a href="%1$s">Click here to go back to checkout page</a>.', 'wpsc' ), get_option( "shopping_cart_url" ) );
129
+ }
130
+ }
wpsc-components/theme-engine-v1/templates/functions/wpsc-user_log_functions.php ADDED
@@ -0,0 +1,792 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * WP eCommerce User Account class
5
+ *
6
+ * This class is responsible for theming the User Account page.
7
+ *
8
+ * @package wp-e-commerce
9
+ * @since 3.8
10
+ */
11
+ global $wpdb, $user_ID, $wpsc_purchlog_statuses, $separator;
12
+
13
+ if ( get_option( 'permalink_structure' ) != '' )
14
+ $separator = "?";
15
+ else
16
+ $separator = "&amp;";
17
+
18
+ function validate_form_data() {
19
+
20
+ global $wpdb, $user_ID, $wpsc_purchlog_statuses;
21
+
22
+ $any_bad_inputs = false;
23
+ $changes_saved = false;
24
+ $bad_input_message = '';
25
+ $_SESSION['collected_data'] = null;
26
+
27
+ if ( ! empty($_POST['collected_data']) ) {
28
+
29
+ if( ! wp_verify_nonce( $_POST['_wpsc_user_profile'], 'wpsc_user_profile') )
30
+ die( __( 'It would appear either you are trying to hack into this account, or your session has expired. Hoping for the latter.', 'wpsc' ) );
31
+
32
+ foreach ( (array)$_POST['collected_data'] as $value_id => $value ) {
33
+ $form_sql = $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `id` = %d LIMIT 1", $value_id );
34
+ $form_data = $wpdb->get_row( $form_sql, ARRAY_A );
35
+ $bad_input = false;
36
+ if ( $form_data['mandatory'] == 1 ) {
37
+ switch ( $form_data['type'] ) {
38
+ case "email":
39
+ if ( !preg_match( "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-.]+\.[a-zA-Z]{2,5}$/", $value ) ) {
40
+ $any_bad_inputs = true;
41
+ $bad_input = true;
42
+ }
43
+ break;
44
+
45
+ case "delivery_country":
46
+ if ( ($value != null ) ) {
47
+ wpsc_update_customer_meta( 'shipping_country', $value );
48
+ }
49
+ break;
50
+
51
+ default:
52
+ if ( empty( $value ) )
53
+ $bad_input = true;
54
+ break;
55
+ }
56
+ if ( $bad_input === true ) {
57
+
58
+ switch ( $form_data['name'] ) {
59
+ case __( 'First Name', 'wpsc' ):
60
+ $bad_input_message .= __( 'Please enter a valid name', 'wpsc' ) . "";
61
+ break;
62
+
63
+ case __( 'Last Name', 'wpsc' ):
64
+ $bad_input_message .= __( 'Please enter a valid surname', 'wpsc' ) . "";
65
+ break;
66
+
67
+ case __( 'Email', 'wpsc' ):
68
+ $bad_input_message .= __( 'Please enter a valid email address', 'wpsc' ) . "";
69
+ break;
70
+
71
+ case __( 'Address 1', 'wpsc' ):
72
+ case __( 'Address 2', 'wpsc' ):
73
+ $bad_input_message .= __( 'Please enter a valid address', 'wpsc' ) . "";
74
+ break;
75
+
76
+ case __( 'City', 'wpsc' ):
77
+ $bad_input_message .= __( 'Please enter your town or city.', 'wpsc' ) . "";
78
+ break;
79
+
80
+ case __( 'Phone', 'wpsc' ):
81
+ $bad_input_message .= __( 'Please enter a valid phone number', 'wpsc' ) . "";
82
+ break;
83
+
84
+ case __( 'Country', 'wpsc' ):
85
+ $bad_input_message .= __( 'Please select your country from the list.', 'wpsc' ) . "";
86
+ break;
87
+
88
+ default:
89
+ $bad_input_message .= sprintf(__( 'Please enter a valid <span class="wpsc_error_msg_field_name">%s</span>.', 'wpsc' ), esc_html($form_data['name']) );
90
+ break;
91
+ }
92
+ $bad_input_message .= "<br />";
93
+ } else {
94
+ $meta_data[$value_id] = $value;
95
+ }
96
+ } else {
97
+ $meta_data[$value_id] = $value;
98
+ }
99
+ }
100
+ $meta_data = apply_filters( 'wpsc_user_log_update', $meta_data, $user_ID );
101
+ wpsc_update_customer_meta( 'checkout_details', $meta_data );
102
+ }
103
+ if ( $changes_saved ) {
104
+ $message = __( 'Thanks, your changes have been saved.', 'wpsc' );
105
+ } else {
106
+ $message = $bad_input_message;
107
+ }
108
+ return apply_filters( 'wpsc_profile_message', $message );
109
+ }
110
+
111
+ /**
112
+ * wpsc_display_form_fields()
113
+ *
114
+ * This function displays each of the form fields. Each of them are filterable via 'wpsc_account_form_field_$tag' where tag is permalink-styled name or uniquename.
115
+ * i.e. First Name under Shipping would be 'wpsc_account_form_field_shippingfirstname' - while Your Billing Details would be filtered
116
+ * via 'wpsc_account_form_field_your-billing-details'.
117
+ *
118
+ * @global <type> $wpdb
119
+ * @global <type> $user_ID
120
+ * @global <type> $wpsc_purchlog_statuses
121
+ * @global <type> $gateway_checkout_form_fields
122
+ */
123
+ function wpsc_display_form_fields() {
124
+ // Field display and Data saving function
125
+
126
+ global $wpdb, $user_ID, $wpsc_purchlog_statuses, $gateway_checkout_form_fields, $wpsc_checkout;
127
+
128
+ if ( empty( $wpsc_checkout ) )
129
+ $wpsc_checkout = new WPSC_Checkout();
130
+
131
+ $meta_data = wpsc_get_customer_meta( 'checkout_details' );
132
+ $meta_data = apply_filters( 'wpsc_user_log_get', $meta_data, $user_ID );
133
+
134
+ $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' ORDER BY `checkout_set`, `checkout_order`;";
135
+ $form_data = $wpdb->get_results( $form_sql, ARRAY_A );
136
+ foreach ( $form_data as $form_field ) {
137
+ if ( !empty( $form_field['unique_name'] ) ) {
138
+ $ff_tag = $form_field['unique_name'];
139
+ } else {
140
+ $ff_tag = esc_html( strtolower( str_replace( ' ', '-', $form_field['name'] ) ) );
141
+ }
142
+
143
+ if(!empty($meta_data[$form_field['id']]) && !is_array($meta_data[$form_field['id']]))
144
+ $meta_data[$form_field['id']] = esc_html( $meta_data[$form_field['id']] );
145
+
146
+ if ( $form_field['type'] == 'heading' ) {
147
+ echo "
148
+ <tr>
149
+ <td colspan='2'>\n\r";
150
+ echo "<strong>" . apply_filters( 'wpsc_account_form_field_' . $ff_tag, esc_html( $form_field['name'] ) ) . "</strong>";
151
+ echo "
152
+ </td>
153
+ </tr>\n\r";
154
+ } else {
155
+
156
+ $display = '';
157
+ if ( in_array( $form_field['unique_name'], array( 'shippingstate', 'billingstate' ) ) ) {
158
+ if ( $form_field['unique_name'] == 'shippingstate' )
159
+ $country_field_id = wpsc_get_country_form_id_by_type( 'delivery_country' );
160
+ else
161
+ $country_field_id = wpsc_get_country_form_id_by_type( 'country' );
162
+
163
+ $country = is_array( $meta_data[$country_field_id] ) ? $meta_data[$country_field_id][0] : $meta_data[$country_field_id];
164
+ if ( wpsc_has_regions( $country ) )
165
+ $display = ' style="display:none;"';
166
+ }
167
+
168
+ echo "
169
+ <tr{$display}>
170
+ <td align='left'>\n\r";
171
+ echo apply_filters( 'wpsc_account_form_field_' . $ff_tag, $form_field['name'] );
172
+ if ( $form_field['mandatory'] == 1 )
173
+ echo " *";
174
+ echo "
175
+ </td>\n\r
176
+ <td align='left'>\n\r";
177
+
178
+ switch ( $form_field['type'] ) {
179
+ case "city":
180
+ case "delivery_city":
181
+ echo "<input type='text' value='" . $meta_data[$form_field['id']] . "' name='collected_data[" . $form_field['id'] . "]' />";
182
+ break;
183
+
184
+ case "address":
185
+ case "delivery_address":
186
+ case "textarea":
187
+ echo "<textarea name='collected_data[" . $form_field['id'] . "]'>" . $meta_data[$form_field['id']] . "</textarea>";
188
+ break;
189
+
190
+ case "text":
191
+ $value = isset( $meta_data[$form_field['id']] ) ? $meta_data[$form_field['id']] : '';
192
+ echo "<input type='text' value='" . $value . "' name='collected_data[" . $form_field['id'] . "]' />";
193
+ break;
194
+
195
+ case "region":
196
+ case "delivery_region":
197
+ echo "<select name='collected_data[" . $form_field['id'] . "]'>" . nzshpcrt_region_list( $_SESSION['collected_data'][$form_field['id']] ) . "</select>";
198
+ break;
199
+
200
+
201
+ case "country":
202
+ if (is_array($meta_data[$form_field['id']]))
203
+ $country_code = ($meta_data[$form_field['id']][0]);
204
+ else
205
+ $country_code = ($meta_data[$form_field['id']]);
206
+ $html_id = 'wpsc-profile-billing-country';
207
+ $js = "onchange=\"wpsc_set_profile_country('{$html_id}', '" . $form_field['id'] . "');\"";
208
+
209
+ echo "<select id='{$html_id}' {$js} name='collected_data[" . $form_field['id'] . "][0]' >" . nzshpcrt_country_list( $country_code ) . "</select>";
210
+
211
+ if ( wpsc_has_regions( $country_code ) ) {
212
+ $region = isset( $meta_data[$form_field['id']][1] ) ? $meta_data[$form_field['id']][1] : '';
213
+ echo "<br /><select name='collected_data[" . $form_field['id'] . "][1]'>" . nzshpcrt_region_list( $country_code, $region ) . "</select>";
214
+ }
215
+
216
+
217
+ break;
218
+
219
+ case "delivery_country":
220
+ if (is_array($meta_data[$form_field['id']]))
221
+ $country_code = ($meta_data[$form_field['id']][0]);
222
+ else
223
+ $country_code = ($meta_data[$form_field['id']]);
224
+ $html_id = 'wpsc-profile-shipping-country';
225
+ $js = "onchange=\"wpsc_set_profile_country('{$html_id}', '" . $form_field['id'] . "');\"";
226
+
227
+ echo "<select id='{$html_id}' {$js} name='collected_data[" . $form_field['id'] . "][0]' >" . nzshpcrt_country_list( $country_code ) . "</select>";
228
+ if( wpsc_has_regions( $country_code ) ) {
229
+ $region = isset( $meta_data[$form_field['id']][1] ) ? $meta_data[$form_field['id']][1] : '';
230
+ echo "<br /><select name='collected_data[" . $form_field['id'] . "][1]'>" . nzshpcrt_region_list( $country_code, $region ) . "</select>";
231
+ }
232
+ break;
233
+ case "email":
234
+ echo "<input type='text' value='" . $meta_data[$form_field['id']] . "' name='collected_data[" . $form_field['id'] . "]' />";
235
+ break;
236
+
237
+ case "select":
238
+ $options = $wpsc_checkout->get_checkout_options( $form_field['id'] );
239
+ $selected = isset( $meta_data[$form_field['id']] ) ? $meta_data[$form_field['id']] : null;
240
+
241
+ ?>
242
+ <select name='collected_data[<?php echo esc_attr( $form_field['id'] ); ?>]'>
243
+ <option value="-1"><?php _ex( 'Select an Option', 'Dropdown default on user log page', 'wpsc' ); ?></option>
244
+ <?php foreach ( $options as $label => $value ): ?>
245
+ <option <?php selected( $value, $selected ); ?> value="<?php echo esc_attr( $value ); ?>"><?php echo esc_html( $label ); ?></option>
246
+ <?php endforeach ?>
247
+ </select>
248
+ <?php
249
+ break;
250
+
251
+ case 'checkbox':
252
+ case 'radio':
253
+ $checked_values = isset( $meta_data[$form_field['id']] ) ? (array) $meta_data[$form_field['id']] : array();
254
+ $options = $wpsc_checkout->get_checkout_options( $form_field['id'] );
255
+ $field_name = "collected_data[{$form_field['id']}]";
256
+ if ( $form_field['type'] == 'checkbox' )
257
+ $field_name .= '[]';
258
+ foreach ( $options as $label => $value ) {
259
+ ?>
260
+ <label>
261
+ <input <?php checked( in_array( $value, $checked_values ) ); ?> type="<?php echo $form_field['type']; ?>" id="" name="collected_data[<?php echo esc_attr( $form_field['id'] ); ?>][]" value="<?php echo esc_attr( $value ); ?>" />
262
+ <?php echo esc_html( $label ); ?>
263
+ </label><br />
264
+ <?php
265
+ }
266
+ break;
267
+
268
+ default:
269
+ $value = isset( $meta_data[$form_field['id']] ) ? $meta_data[$form_field['id']] : '';
270
+ echo "<input type='text' value='" . $value . "' name='collected_data[" . $form_field['id'] . "]' />";
271
+ break;
272
+ }
273
+ echo wp_nonce_field( 'wpsc_user_profile', '_wpsc_user_profile' );
274
+ echo "
275
+ </td>
276
+ </tr>\n\r";
277
+
278
+ }
279
+ }
280
+ /* Returns an empty array at this point, empty in regards to fields, does show the internalname though. Needs to be reconsidered, even if it did work, need to check
281
+ * functionality and PCI_DSS compliance
282
+
283
+ if ( isset( $gateway_checkout_form_fields ) )
284
+ {
285
+ echo $gateway_checkout_form_fields;
286
+ }
287
+ */
288
+ }
289
+
290
+ function wpsc_has_downloads() {
291
+ global $wpdb, $user_ID, $files, $links, $products;
292
+
293
+ $purchases = $wpdb->get_results( "SELECT `id`, `processed` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE user_ID = " . (int)$user_ID . "" );
294
+ $rowcount = count( $purchases );
295
+
296
+ if ( $rowcount >= 1 ) {
297
+ $perchidstr = "(";
298
+ $perchids = array();
299
+ foreach( (array)$purchases as $purchase ) {
300
+ $is_transaction = wpsc_check_purchase_processed( $purchase->processed );
301
+ if( $is_transaction ) {
302
+ $perchids[] = $purchase->id;
303
+ }
304
+ }
305
+ if(!empty($perchids)){
306
+ $perchidstr .= implode( ',', $perchids );
307
+ $perchidstr .= ")";
308
+ $sql = "SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `purchid` IN " . $perchidstr . " AND `active` IN ('1') ORDER BY `datetime` DESC";
309
+ $products = $wpdb->get_results( $sql, ARRAY_A );
310
+ $products = apply_filters( 'wpsc_has_downloads_products', $products );
311
+ }
312
+ }
313
+
314
+ foreach ( (array)$products as $key => $product ) {
315
+ if( empty( $product['uniqueid'] ) ) { // if the uniqueid is not equal to null, its "valid", regardless of what it is
316
+ $links[] = home_url( '/?downloadid=' . $product['id'] );
317
+ } else {
318
+ $links[] = home_url( '/?downloadid=' . $product['uniqueid'] );
319
+ }
320
+ $sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE id = %d", $product['fileid'] );
321
+ $file = $wpdb->get_results( $sql, ARRAY_A );
322
+ $files[] = $file[0];
323
+ }
324
+ if ( count( $files ) > 0 ) {
325
+ return true;
326
+ } else {
327
+ return false;
328
+ }
329
+ }
330
+
331
+ function wpsc_has_purchases() {
332
+
333
+ global $wpdb, $user_ID, $wpsc_purchlog_statuses, $gateway_checkout_form_fields, $purchase_log, $col_count;
334
+
335
+ /*
336
+ * this finds the earliest timedit-profile in the shopping cart and sorts out the timestamp system for the month by month display
337
+ */
338
+
339
+ $earliest_record_sql = "SELECT MIN(`date`) AS `date` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date`!=''";
340
+ $earliest_record = $wpdb->get_results( $earliest_record_sql, ARRAY_A );
341
+
342
+ if ( $earliest_record[0]['date'] != null ) {
343
+ $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' AND `display_log` = '1';";
344
+ $col_count = 4; //+ count( $form_data );
345
+ $sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `user_ID` IN ('" . $user_ID . "') ORDER BY `date` DESC";
346
+ $purchase_log = $wpdb->get_results( $sql, ARRAY_A );
347
+
348
+ return true;
349
+ } else {
350
+
351
+ return false;
352
+ }
353
+ }
354
+
355
+ function wpsc_has_purchases_this_month() {
356
+ global $wpdb, $user_ID, $wpsc_purchlog_statuses, $gateway_checkout_form_fields, $purchase_log, $col_count;
357
+
358
+ $i = 0;
359
+ $subtotal = 0;
360
+
361
+ if ( $purchase_log != null )
362
+ return true;
363
+ else
364
+ return false;
365
+ }
366
+
367
+ /**
368
+ * Displays the Account Page tabs
369
+ *
370
+ * @access public
371
+ * @since 3.8.10
372
+ *
373
+ */
374
+ function wpsc_user_profile_links( $args = array() ) {
375
+ global $current_tab, $separator;
376
+
377
+ $defaults = array (
378
+ 'before_link_list' => '',
379
+ 'after_link_list' => '',
380
+ 'before_link_item' => '',
381
+ 'after_link_item' => '',
382
+ 'link_separator' => '|'
383
+ );
384
+
385
+ $args = wp_parse_args( $args, $defaults );
386
+
387
+ $profile_tabs = apply_filters( 'wpsc_user_profile_tabs', array(
388
+ 'purchase_history' => __( 'Purchase History', 'wpsc' ),
389
+ 'edit_profile' => __( 'Your Details', 'wpsc' ),
390
+ 'downloads' => __( 'Your Downloads', 'wpsc' )
391
+ ) );
392
+
393
+ echo $args['before_link_list'];
394
+
395
+ $i = 0;
396
+ $user_account_url = get_option( 'user_account_url' );
397
+ $links = array();
398
+ foreach ( $profile_tabs as $tab_id => $tab_title ) :
399
+ $tab_link = $args['before_link_item'];
400
+ $tab_url = add_query_arg( 'tab', $tab_id, $user_account_url );
401
+ $tab_link = sprintf(
402
+ '<a href="%1$s" class="%2$s">%3$s</a>',
403
+ esc_url( $tab_url ),
404
+ esc_attr( $current_tab == $tab_id ? 'current' : '' ),
405
+ $tab_title
406
+ );
407
+ $tab_link .= $args['after_link_item'];
408
+ $links[] = $tab_link;
409
+ endforeach;
410
+
411
+ echo implode( $args['link_separator'], $links );
412
+
413
+ echo $args['after_link_list'];
414
+ }
415
+
416
+ function wpsc_user_purchases() {
417
+ global $wpdb, $user_ID, $wpsc_purchlog_statuses, $gateway_checkout_form_fields, $purchase_log, $col_count, $nzshpcrt_gateways;
418
+
419
+ $i = 0;
420
+ $subtotal = 0;
421
+
422
+ do_action( 'wpsc_pre_purchase_logs' );
423
+
424
+ foreach ( (array) $purchase_log as $purchase ) {
425
+ $status_state = "expand";
426
+ $status_style = "display:none;";
427
+ $alternate = "";
428
+ $i++;
429
+
430
+ if ( ($i % 2) != 0 )
431
+ $alternate = "alt";
432
+
433
+ echo "<tr class='$alternate'>\n\r";
434
+ echo " <td class='status processed'>";
435
+ echo "<a href=\"#\" onclick=\"return show_details_box('status_box_" . $purchase['id'] . "','log_expander_icon_" . $purchase['id'] . "');\">";
436
+
437
+ if ( !empty($_GET['id']) && $_GET['id'] == $purchase['id'] ) {
438
+ $status_state = "collapse";
439
+ $status_style = "style='display: block;'";
440
+ }
441
+
442
+ echo "<img class=\"log_expander_icon\" id=\"log_expander_icon_" . $purchase['id'] . "\" src=\"" . WPSC_CORE_IMAGES_URL . "/icon_window_$status_state.gif\" alt=\"\" title=\"\" />";
443
+
444
+ echo "<span id='form_group_" . $purchase['id'] . "_text'>" . __( 'Details', 'wpsc' ) . "</span>";
445
+ echo "</a>";
446
+ echo " </td>\n\r";
447
+
448
+ echo " <td class='date'>";
449
+ echo date( "jS M Y", $purchase['date'] );
450
+ echo " </td>\n\r";
451
+
452
+ echo " <td class='price'>";
453
+ $country = get_option( 'country_form_field' );
454
+ if ( $purchase['shipping_country'] != '' ) {
455
+ $billing_country = $purchase['billing_country'];
456
+ $shipping_country = $purchase['shipping_country'];
457
+ } elseif ( !empty($country)) {
458
+ $country_sql = $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = %d LIMIT 1", $purchase['id'] ,get_option( 'country_form_field' ) );
459
+ $country_data = $wpdb->get_results( $country_sql, ARRAY_A );
460
+ $billing_country = $country_data[0]['value'];
461
+ $shipping_country = $country_data[0]['value'];
462
+ }
463
+ echo wpsc_currency_display( $purchase['totalprice'], array('display_as_html' => false) );
464
+ $subtotal += $purchase['totalprice'];
465
+ echo " </td>\n\r";
466
+
467
+
468
+ if ( get_option( 'payment_method' ) == 2 ) {
469
+ echo " <td class='payment_method'>";
470
+ $gateway_name = '';
471
+ foreach ( (array)$nzshpcrt_gateways as $gateway ) {
472
+ if ( $purchase['gateway'] != 'testmode' ) {
473
+ if ( $gateway['internalname'] == $purchase['gateway'] ) {
474
+ $gateway_name = $gateway['name'];
475
+ }
476
+ } else {
477
+ $gateway_name = __( "Manual Payment", 'wpsc' );
478
+ }
479
+ }
480
+ echo $gateway_name;
481
+ echo " </td>\n\r";
482
+ }
483
+
484
+ echo "</tr>\n\r";
485
+ echo "<tr>\n\r";
486
+ echo " <td colspan='$col_count' class='details'>\n\r";
487
+ echo " <div id='status_box_" . $purchase['id'] . "' class='order_status' style=\"$status_style\">\n\r";
488
+ echo " <div>\n\r";
489
+
490
+ //order status code lies here
491
+ //check what $purchase['processed'] reflects in the $wpsc_purchlog_statuses array
492
+ $status_name = wpsc_find_purchlog_status_name( $purchase['processed'] );
493
+ echo " <strong class='form_group'>" . __( 'Order Status', 'wpsc' ) . ":</strong>\n\r";
494
+ echo $status_name . "<br /><br />";
495
+
496
+ do_action( 'wpsc_user_log_after_order_status', $purchase );
497
+
498
+ //written by allen
499
+ $usps_id = get_option( 'usps_user_id' );
500
+ if ( $usps_id != null ) {
501
+ $XML1 = "<TrackFieldRequest USERID=\"$usps_id\"><TrackID ID=\"" . $purchase['track_id'] . "\"></TrackID></TrackFieldRequest>";
502
+ $ch = curl_init();
503
+ curl_setopt( $ch, CURLOPT_URL, "http://secure.shippingapis.com/ShippingAPITest.dll?" );
504
+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
505
+ curl_setopt( $ch, CURLOPT_POST, 1 );
506
+ curl_setopt( $ch, CURLOPT_HEADER, 0 );
507
+ $postdata = "API=TrackV2&XML=" . $XML1;
508
+ curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
509
+
510
+ $parser = new xml2array;
511
+ $parsed = $parser->parse( $result );
512
+ $parsed = $parsed[0]['children'][0]['children'];
513
+ if ( $purchase['track_id'] != null ) {
514
+ echo "<br /><br />";
515
+ echo " <strong class='form_group'>" . __( 'Shipping Address', 'wpsc' ) . "</strong>\n\r";
516
+ echo "<table>";
517
+ foreach ( (array)$parsed as $parse ) {
518
+ if ( $parse['name'] == "TRACKSUMMARY" )
519
+ foreach ( (array)$parse['children'] as $attrs ) {
520
+ if ( $attrs['name'] != "EVENT" )
521
+ $attrs['name'] = str_replace( "EVENT", "", $attrs['name'] );
522
+ $bar = ucfirst( strtolower( $attrs['name'] ) );
523
+ echo "<tr><td>" . $bar . "</td><td>" . $attrs['tagData'] . "</td></tr>";
524
+ }
525
+ }
526
+ echo "</table>";
527
+ }
528
+ echo "<br /><br />";
529
+ }
530
+ //end of written by allen
531
+ //cart contents display starts here;
532
+ echo " <strong class='form_group'>" . __( 'Order Details', 'wpsc' ) . ":</strong>\n\r";
533
+ $cartsql = $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`= %d", $purchase['id'] );
534
+ $cart_log = $wpdb->get_results( $cartsql, ARRAY_A );
535
+ $j = 0;
536
+ // /*
537
+ if ( $cart_log != null ) {
538
+ echo "<table class='logdisplay'>";
539
+ echo "<tr class='toprow2'>";
540
+
541
+ echo " <th class='details_name'>";
542
+ _e( 'Name', 'wpsc' );
543
+ echo " </th>";
544
+
545
+ echo " <th class='details_quantity'>";
546
+ _e( 'Quantity', 'wpsc' );
547
+ echo " </th>";
548
+
549
+ echo " <th class='details_price'>";
550
+ _e( 'Price', 'wpsc' );
551
+ echo " </th>";
552
+
553
+ echo " <th class='details_tax'>";
554
+ _e( 'GST', 'wpsc' );
555
+ echo " </th>";
556
+
557
+ echo " <th class='details_shipping'>";
558
+ _e( 'Shipping', 'wpsc' );
559
+ echo " </th>";
560
+
561
+ echo " <th class='details_total'>";
562
+ _e( 'Total', 'wpsc' );
563
+ echo " </th>";
564
+
565
+ echo "</tr>";
566
+
567
+ $gsttotal = false;
568
+ $endtotal = $total_shipping = 0;
569
+ foreach ( (array)$cart_log as $cart_row ) {
570
+ $alternate = "";
571
+ $j++;
572
+
573
+ if ( ($j % 2) != 0 )
574
+ $alternate = "alt";
575
+
576
+ $variation_list = '';
577
+
578
+ $billing_country = !empty($country_data[0]['value']) ? $country_data[0]['value'] : '';
579
+ $shipping_country = !empty($country_data[0]['value']) ? $country_data[0]['value'] : '';
580
+
581
+ $shipping = $cart_row['pnp'];
582
+ $total_shipping += $shipping;
583
+ echo "<tr class='$alternate'>";
584
+
585
+ echo " <td class='details_name'>";
586
+ echo apply_filters( 'the_title', $cart_row['name'] );
587
+ echo $variation_list;
588
+ echo " </td>";
589
+
590
+ echo " <td class='details_quantity'>";
591
+ echo $cart_row['quantity'];
592
+ echo " </td>";
593
+
594
+ echo " <td class='details_price'>";
595
+ $price = $cart_row['price'] * $cart_row['quantity'];
596
+ echo wpsc_currency_display( $price );
597
+ echo " </td>";
598
+
599
+ echo " <td class='details_tax'>";
600
+ $gst = $cart_row['tax_charged'];
601
+ if( $gst > 0)
602
+ $gsttotal += $gst;
603
+ echo wpsc_currency_display( $gst , array('display_as_html' => false) );
604
+ echo " </td>";
605
+
606
+ echo " <td class='details_shipping'>";
607
+ echo wpsc_currency_display( $shipping , array('display_as_html' => false) );
608
+ echo " </td>";
609
+
610
+ echo " <td class='details_total'>";
611
+ $endtotal += $price;
612
+ echo wpsc_currency_display( ( $shipping + $price ), array('display_as_html' => false) );
613
+ echo " </td>";
614
+
615
+ echo '</tr>';
616
+ }
617
+ echo "<tr>";
618
+
619
+ echo " <td>";
620
+ echo " </td>";
621
+
622
+ echo " <td>";
623
+ echo " </td>";
624
+
625
+ echo " <td>";
626
+ echo " <td>";
627
+ echo " </td>";
628
+ echo " </td>";
629
+
630
+ echo " <td class='details_totals_labels'>";
631
+ echo "<strong>" . __( 'Total Shipping', 'wpsc' ) . ":</strong><br />";
632
+ echo "<strong>" . __( 'Total Tax', 'wpsc' ) . ":</strong><br />";
633
+ echo "<strong>" . __( 'Final Total', 'wpsc' ) . ":</strong>";
634
+ echo " </td>";
635
+
636
+ echo " <td class='details_totals_labels'>";
637
+ $total_shipping += $purchase['base_shipping'];
638
+ $endtotal += $total_shipping;
639
+ $endtotal += $purchase['wpec_taxes_total'];
640
+ echo wpsc_currency_display( $total_shipping, array('display_as_html' => false) ) . "<br />";
641
+ if ( $gsttotal ){ //if false then must be exclusive.. doesnt seem too reliable needs more testing
642
+ echo wpsc_currency_display( $gsttotal , array('display_as_html' => false) ). "<br />";
643
+ } else {
644
+ echo wpsc_currency_display( $purchase['wpec_taxes_total'] , array('display_as_html' => false) ). "<br />";
645
+ }
646
+ echo wpsc_currency_display( $endtotal , array('display_as_html' => false) );
647
+ echo " </td>";
648
+
649
+ echo '</tr>';
650
+
651
+ echo "</table>";
652
+ echo "<br />";
653
+
654
+ echo "<strong>" . __( 'Customer Details', 'wpsc' ) . ":</strong>";
655
+ echo "<table class='customer_details'>";
656
+
657
+
658
+ $usersql = $wpdb->prepare( "SELECT `".WPSC_TABLE_SUBMITTED_FORM_DATA."`.value, `".WPSC_TABLE_CHECKOUT_FORMS."`.* FROM `".WPSC_TABLE_CHECKOUT_FORMS."` LEFT JOIN `".WPSC_TABLE_SUBMITTED_FORM_DATA."` ON `".WPSC_TABLE_CHECKOUT_FORMS."`.id = `".WPSC_TABLE_SUBMITTED_FORM_DATA."`.`form_id` WHERE `".WPSC_TABLE_SUBMITTED_FORM_DATA."`.log_id = %d OR `".WPSC_TABLE_CHECKOUT_FORMS."`.type = 'heading' ORDER BY `".WPSC_TABLE_CHECKOUT_FORMS."`.`checkout_set`, `".WPSC_TABLE_CHECKOUT_FORMS."`.`checkout_order`", $purchase['id'] );
659
+ $formfields = $wpdb->get_results($usersql, ARRAY_A);
660
+ if ( !empty($formfields) ) {
661
+
662
+ foreach ( (array)$formfields as $form_field ) {
663
+ // If its a heading display the Name otherwise continue on
664
+ if( 'heading' == $form_field['type'] ){
665
+ echo " <tr><td colspan='2'>" . esc_html( $form_field['name'] ) . ":</td></tr>";
666
+ continue;
667
+ }
668
+
669
+ switch ($form_field['unique_name']){
670
+ case 'shippingcountry':
671
+ case 'billingcountry':
672
+ $country = maybe_unserialize($form_field['value']);
673
+ if(is_array($country))
674
+ $country = $country[0];
675
+ else
676
+ $country = $form_field['value'];
677
+
678
+ echo " <tr><td>" . esc_html( $form_field['name'] ) . ":</td><td>" . esc_html( $country ) . "</td></tr>";
679
+ break;
680
+
681
+ case 'billingstate':
682
+ case 'shippingstate':
683
+ if(is_numeric($form_field['value']))
684
+ $state = wpsc_get_state_by_id($form_field['value'],'name');
685
+ else
686
+ $state = $form_field['value'];
687
+
688
+ echo " <tr><td>" . esc_html( $form_field['name'] ) . ":</td><td>" . esc_html( $state ) . "</td></tr>";
689
+ break;
690
+
691
+ default:
692
+ echo " <tr><td>" . esc_html( $form_field['name'] ) . ":</td><td>" . esc_html( $form_field['value'] ) . "</td></tr>";
693
+
694
+ }
695
+ }
696
+ }
697
+
698
+ $payment_gateway_names = '';
699
+ $payment_gateway_names = get_option('payment_gateway_names');
700
+
701
+ foreach ( (array)$payment_gateway_names as $gatewayname ) {
702
+ //if the gateway has a custom name
703
+ if (!empty ($gatewayname) )
704
+ $display_name = $payment_gateway_names[$purchase_log[0]['gateway']];
705
+ else{
706
+ //if not fall back on default name
707
+ foreach ( (array)$nzshpcrt_gateways as $gateway ){
708
+ if ( $gateway['internalname'] == $purchase['gateway'])
709
+ $display_name = $gateway['name'];
710
+ }
711
+ }
712
+ }
713
+
714
+ echo " <tr><td>" . __( 'Payment Method', 'wpsc' ) . ":</td><td>" . $display_name . "</td></tr>";
715
+ echo " <tr><td>" . __( 'Purchase #', 'wpsc' ) . ":</td><td>" . $purchase['id'] . "</td></tr>";
716
+ if ( $purchase['transactid'] != '' ) {
717
+ echo " <tr><td>" . __( 'Transaction Id', 'wpsc' ) . ":</td><td>" . $purchase['transactid'] . "</td></tr>";
718
+ }
719
+ echo "</table>";
720
+ }
721
+ echo " </div>\n\r";
722
+ echo " </div>\n\r";
723
+ echo " </td>\n\r";
724
+ echo "</tr>\n\r";
725
+ }
726
+ }
727
+
728
+
729
+ /**
730
+ * Displays the Purchase History template
731
+ *
732
+ * @access private
733
+ * @since 3.8.10
734
+ *
735
+ */
736
+ function _wpsc_action_purchase_history_section() {
737
+ include( WPSC_CORE_THEME_PATH. '/wpsc-account-purchase-history.php' );
738
+ }
739
+ add_action( 'wpsc_user_profile_section_purchase_history', '_wpsc_action_purchase_history_section' );
740
+
741
+ /**
742
+ * Displays the Edit Profile template
743
+ *
744
+ * @access private
745
+ * @since 3.8.10
746
+ *
747
+ */
748
+ function _wpsc_action_edit_profile_section() {
749
+ include( WPSC_CORE_THEME_PATH . '/wpsc-account-edit-profile.php' );
750
+ }
751
+ add_action( 'wpsc_user_profile_section_edit_profile', '_wpsc_action_edit_profile_section' );
752
+
753
+ /**
754
+ * Displays the Downloads template
755
+ *
756
+ * @access private
757
+ * @since 3.8.10
758
+ *
759
+ */
760
+ function _wpsc_action_downloads_section() {
761
+ global $files, $products;
762
+
763
+ $items = array();
764
+ if ( wpsc_has_downloads() && ! empty( $files ) ) {
765
+ foreach ( $files as $key => $file ) {
766
+ $item = array();
767
+ if ( $products[$key]['downloads'] > 0 ) {
768
+ $url = add_query_arg(
769
+ 'downloadid',
770
+ $products[$key]['uniqueid'],
771
+ home_url()
772
+ );
773
+ $item['title'] = sprintf(
774
+ '<a href="%1$s">%2$s</a>',
775
+ esc_url( $url ),
776
+ esc_html( $file['post_title'] )
777
+ );
778
+ } else {
779
+ $item['title'] = esc_html( $file['post_title'] );
780
+ }
781
+
782
+ $item['downloads'] = $products[$key]['downloads'];
783
+ $item['datetime'] = date( get_option( 'date_format' ), strtotime( $products[$key]['datetime'] ) );
784
+ $items[] = (object) $item;
785
+ }
786
+ }
787
+
788
+ include( WPSC_CORE_THEME_PATH . '/wpsc-account-downloads.php' );
789
+ }
790
+ add_action( 'wpsc_user_profile_section_downloads', '_wpsc_action_downloads_section' );
791
+
792
+ ?>
wpsc-components/theme-engine-v1/templates/wpsc-account-downloads.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The Account > Downloads template.
4
+ *
5
+ * Displays the user account page.
6
+ *
7
+ * @package WPSC
8
+ * @since WPSC 3.8.10
9
+ */
10
+ ?>
11
+
12
+ <?php if ( empty( $items ) ) : ?>
13
+ <?php _e( 'You have not purchased any downloadable products yet.', 'wpsc' ); ?>
14
+ <?php else : ?>
15
+ <table class="logdisplay">
16
+ <thead>
17
+ <tr>
18
+ <th class="wpsc-user-log-file-name" scope="col"><?php _e( 'File Names', 'wpsc' ); ?> </th>
19
+ <th class="wpsc-user-log-downloads-left" scope="col"><?php _e( 'Downloads Left', 'wpsc' ); ?> </th>
20
+ <th class="wpsc-user-log-file-date" scope="col"><?php _e( 'Date', 'wpsc' ); ?> </th>
21
+ </tr>
22
+ </thead>
23
+
24
+ <tbody>
25
+ <?php foreach( $items as $key => $item ): ?>
26
+ <tr class="wpsc-user-log-file<?php echo ( $key %2 == 1 ) ? '' : ' alt'; ?>">
27
+ <td class="wpsc-user-log-file-name">
28
+ <?php echo $item->title; ?>
29
+ </td>
30
+ <td class="wpsc-user-log-downloads-left">
31
+ <?php echo esc_html( $item->downloads ); ?>
32
+ </td>
33
+ <td class="wpsc-user-log-file-date">
34
+ <?php echo esc_html( $item->datetime ); ?>
35
+ </td>
36
+ </tr>
37
+ <?php endforeach; ?>
38
+ </tbody>
39
+ </table>
40
+ <?php endif; ?>
wpsc-components/theme-engine-v1/templates/wpsc-account-edit-profile.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The Account > Edit Profile template.
4
+ *
5
+ * Displays the user account page.
6
+ *
7
+ * @package WPSC
8
+ * @since WPSC 3.8.10
9
+ */
10
+ ?>
11
+
12
+ <form method="post">
13
+
14
+ <?php echo validate_form_data(); ?>
15
+
16
+ <table>
17
+
18
+ <?php wpsc_display_form_fields(); ?>
19
+
20
+ <tr>
21
+ <td></td>
22
+ <td>
23
+ <input type="hidden" value="true" name="submitwpcheckout_profile" />
24
+ <input type="submit" value="<?php _e( 'Save Profile', 'wpsc' ); ?>" name="submit" />
25
+ </td>
26
+ </tr>
27
+ </table>
28
+ </form>
wpsc-components/theme-engine-v1/templates/wpsc-account-purchase-history.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The Account > Purchase History template.
4
+ *
5
+ * Displays the user's order history.
6
+ *
7
+ * @package WPSC
8
+ * @since WPSC 3.8.10
9
+ */
10
+ global $col_count; ?>
11
+
12
+ <?php if ( wpsc_has_purchases() ) : ?>
13
+
14
+ <table class="logdisplay">
15
+
16
+ <?php if ( wpsc_has_purchases_this_month() ) : ?>
17
+
18
+ <tr class="toprow">
19
+ <th class="status"><?php _e( 'Status', 'wpsc' ); ?></th>
20
+ <th class="date"><?php _e( 'Date', 'wpsc' ); ?></th>
21
+ <th class="price"><?php _e( 'Price', 'wpsc' ); ?></th>
22
+
23
+ <?php if ( get_option( 'payment_method' ) == 2 ) : ?>
24
+
25
+ <th class="payment_method"><?php _e( 'Payment Method', 'wpsc' ); ?></th>
26
+
27
+ <?php endif; ?>
28
+
29
+ </tr>
30
+
31
+ <?php wpsc_user_purchases(); ?>
32
+
33
+ <?php else : ?>
34
+
35
+ <tr>
36
+ <td colspan="<?php echo $col_count; ?>">
37
+
38
+ <?php _e( 'No transactions for this month.', 'wpsc' ); ?>
39
+
40
+ </td>
41
+ </tr>
42
+
43
+ <?php endif; ?>
44
+
45
+ </table>
46
+
47
+ <?php else : ?>
48
+
49
+ <table>
50
+ <tr>
51
+ <td><?php _e( 'There have not been any purchases yet.', 'wpsc' ); ?></td>
52
+ </tr>
53
+ </table>
54
+
55
+ <?php endif; ?>
wpsc-components/theme-engine-v1/templates/wpsc-cart_widget.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if(isset($cart_messages) && count($cart_messages) > 0) { ?>
2
+ <?php foreach((array)$cart_messages as $cart_message) { ?>
3
+ <span class="cart_message"><?php echo esc_html( $cart_message ); ?></span>
4
+ <?php } ?>
5
+ <?php } ?>
6
+
7
+ <?php if(wpsc_cart_item_count() > 0): ?>
8
+ <div class="shoppingcart">
9
+ <table>
10
+ <thead>
11
+ <tr>
12
+ <th id="product" colspan='2'><?php _e('Product', 'wpsc'); ?></th>
13
+ <th id="quantity"><?php _e('Qty', 'wpsc'); ?></th>
14
+ <th id="price"><?php _e('Price', 'wpsc'); ?></th>
15
+ <th id="remove">&nbsp;</th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ <?php while(wpsc_have_cart_items()): wpsc_the_cart_item(); ?>
20
+ <tr>
21
+ <td colspan='2' class='product-name'><?php do_action ( "wpsc_before_cart_widget_item_name" ); ?><a href="<?php echo esc_url( wpsc_cart_item_url() ); ?>"><?php echo wpsc_cart_item_name(); ?></a><?php do_action ( "wpsc_after_cart_widget_item_name" ); ?></td>
22
+ <td><?php echo wpsc_cart_item_quantity(); ?></td>
23
+ <td><?php echo wpsc_cart_item_price(); ?></td>
24
+ <td class="cart-widget-remove"><form action="" method="post" class="adjustform">
25
+ <input type="hidden" name="quantity" value="0" />
26
+ <input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>" />
27
+ <input type="hidden" name="wpsc_update_quantity" value="true" />
28
+ <input class="remove_button" type="submit" />
29
+ </form></td>
30
+ </tr>
31
+ <?php endwhile; ?>
32
+ </tbody>
33
+ <tfoot>
34
+ <tr class="cart-widget-total">
35
+ <td class="cart-widget-count">
36
+ <?php printf( _n('%d item', '%d items', wpsc_cart_item_count(), 'wpsc'), wpsc_cart_item_count() ); ?>
37
+ </td>
38
+ <td class="pricedisplay checkout-total" colspan='4'>
39
+ <?php _e('Subtotal:', 'wpsc'); ?> <?php echo wpsc_cart_total_widget( false, false ,false ); ?><br />
40
+ <small><?php _e( 'excluding discount, shipping and tax', 'wpsc' ); ?></small>
41
+ </td>
42
+ </tr>
43
+ <tr>
44
+ <td id='cart-widget-links' colspan="5">
45
+ <a target="_parent" href="<?php echo esc_url( get_option( 'shopping_cart_url' ) ); ?>" title="<?php esc_html_e('Checkout', 'wpsc'); ?>" class="gocheckout"><?php esc_html_e('Checkout', 'wpsc'); ?></a>
46
+ <form action="" method="post" class="wpsc_empty_the_cart">
47
+ <input type="hidden" name="wpsc_ajax_action" value="empty_cart" />
48
+ <a target="_parent" href="<?php echo esc_url( add_query_arg( 'wpsc_ajax_action', 'empty_cart', remove_query_arg( 'ajax' ) ) ); ?>" class="emptycart" title="<?php esc_html_e('Empty Your Cart', 'wpsc'); ?>"><?php esc_html_e('Clear cart', 'wpsc'); ?></a>
49
+ </form>
50
+ </td>
51
+ </tr>
52
+ </tfoot>
53
+ </table>
54
+ </div><!--close shoppingcart-->
55
+ <?php else: ?>
56
+ <p class="empty">
57
+ <?php _e('Your shopping cart is empty', 'wpsc'); ?><br />
58
+ <a target="_parent" href="<?php echo esc_url( get_option( 'product_list_url' ) ); ?>" class="visitshop" title="<?php esc_html_e('Visit Shop', 'wpsc'); ?>"><?php esc_html_e('Visit the shop', 'wpsc'); ?></a>
59
+ </p>
60
+ <?php endif; ?>
61
+
62
+ <?php
63
+ wpsc_google_checkout();
64
+
65
+
66
+ ?>
wpsc-components/theme-engine-v1/templates/wpsc-category-list.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * wpsc-category-shortcode is the code trigered by using the [showcategories] shortcode
4
+ * @package wp-e-commerce
5
+ * @since 3.8
6
+ */
7
+ ?>
8
+ <div class="wpsc_categories wpsc_category_grid group">
9
+ <?php wpsc_start_category_query(array('category_group'=> get_option('wpsc_default_category'), 'show_thumbnails'=> 1)); ?>
10
+ <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_grid_item <?php wpsc_print_category_classes_section(); ?>" title="<?php wpsc_print_category_name(); ?>">
11
+ <?php wpsc_print_category_image(); ?>
12
+ </a>
13
+ <?php wpsc_print_subcategory("", ""); ?>
14
+ <?php wpsc_end_category_query(); ?>
15
+
16
+ </div><!--close wpsc_categories-->
17
+
18
+ <?php
19
+ ?>
wpsc-components/theme-engine-v1/templates/wpsc-category_widget.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $curr_cat = get_term( $category_id, 'wpsc_product_category', ARRAY_A );
3
+ $category_list = get_terms( 'wpsc_product_category', 'hide_empty=0&parent=' . $category_id );
4
+ $link = get_term_link((int)$category_id , 'wpsc_product_category');
5
+ $category_image = wpsc_get_categorymeta( $curr_cat['term_id'], 'image' );
6
+ $category_image = WPSC_CATEGORY_URL . $category_image;
7
+ $show_name = $instance['show_name'];
8
+
9
+ if ( $grid ) : ?>
10
+
11
+ <a href="<?php echo esc_url( $link ); ?>" style="padding: 4px 4px 0 0; width:<?php echo $width; ?>px; height:<?php echo $height; ?>px;" title="<?php echo $curr_cat['name']; ?>" class="wpsc_category_grid_item">
12
+ <?php wpsc_parent_category_image( $show_thumbnails, $category_image , $width, $height, true ,$show_name); ?>
13
+ </a>
14
+
15
+ <?php wpsc_start_category_query( array( 'parent_category_id' => $category_id, 'show_thumbnails' => $show_thumbnails, 'show_name' => $show_name) ); ?>
16
+
17
+ <a href="<?php wpsc_print_category_url(); ?>" style="width:<?php echo $width; ?>px; height:<?php echo $height; ?>px" class="wpsc_category_grid_item" title="<?php wpsc_print_category_name(); ?>">
18
+ <?php wpsc_print_category_image( $width, $height ); ?>
19
+ </a>
20
+
21
+ <?php wpsc_print_subcategory( '', '' ); ?>
22
+
23
+ <?php wpsc_end_category_query(); ?>
24
+
25
+ <?php else : ?>
26
+ <div class="wpsc_categorisation_group" id="categorisation_group_<?php echo $category_id; ?>">
27
+ <ul class="wpsc_categories wpsc_top_level_categories">
28
+ <li class="wpsc_category_<?php echo $curr_cat['term_id']; wpsc_print_category_classes($curr_cat); ?>">
29
+ <?php if(! ($category_image == WPSC_CATEGORY_URL) ){ ?>
30
+ <a href="<?php echo esc_url( $link ); ?>" class="wpsc_category_image_link"><?php
31
+ wpsc_parent_category_image( $show_thumbnails, $category_image , $width, $height, false, $show_name ); ?></a>
32
+ <?php } ?>
33
+
34
+ <a href="<?php echo esc_url( $link ); ?>"><?php echo esc_html( $curr_cat['name'] ); ?></a>
35
+
36
+ <ul class="wpsc_categories wpsc_second_level_categories">
37
+
38
+ <?php wpsc_start_category_query( array( 'parent_category_id' => $category_id, 'show_thumbnails' => $show_thumbnails , 'show_name' => $show_name) ); ?>
39
+
40
+ <li class="wpsc_category_<?php wpsc_print_category_id(); wpsc_print_category_classes_section();?>">
41
+ <a href="<?php wpsc_print_category_url(); ?>" class="wpsc_category_image_link">
42
+
43
+ <?php wpsc_print_category_image( $width, $height ); ?>
44
+
45
+ </a>
46
+
47
+ <a href="<?php wpsc_print_category_url(); ?>" class="wpsc_category_link">
48
+
49
+ <?php wpsc_print_category_name(); ?>
50
+
51
+ <?php if ( 1 == get_option( 'show_category_count') ) wpsc_print_category_products_count( "(",")" ); ?>
52
+
53
+ </a>
54
+
55
+ <?php wpsc_print_subcategory( '<ul>', '</ul>' ); ?>
56
+
57
+ </li>
58
+
59
+ <?php wpsc_end_category_query(); ?>
60
+
61
+ </ul>
62
+ </li>
63
+ </ul>
64
+
65
+ <div class="clear_category_group"></div>
66
+ </div>
67
+
68
+ <?php endif; ?>
wpsc-components/theme-engine-v1/templates/wpsc-default.css ADDED
@@ -0,0 +1,1102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Theme Name: Default Theme
3
+ Theme URI: http://instinct.co.nz
4
+ Description: Default Theme
5
+ Version: 3.5
6
+ Author: Roy Ho
7
+ Author URI: http://instinct.co.nz
8
+ */
9
+
10
+ /*
11
+ * If you delete this file, you can expect your WP e-Commerce installation to break in some manner
12
+ * to create your own theme copy, and paste this file, change the names and alter to your tastes
13
+ */
14
+ /*-----UTILITY-----*/
15
+ .group:after {
16
+ content:" ";
17
+ display:block;
18
+ height:0;
19
+ clear:both;
20
+ visibility:hidden;
21
+ }
22
+ /*-----IE SPECIFIC STYLESHEET-----*/
23
+
24
+ /*-----UTILITY-----*/
25
+ /* for IE6 */
26
+ * html .group {
27
+ height:1%;
28
+ }
29
+
30
+ /* for IE7 */
31
+ *:first-childhtml .group {
32
+ min-height:1px;
33
+ }
34
+
35
+ /*-----GENERAL-----*/
36
+
37
+ #default_products_page_container .imagecol img, #list_view_products_page_container img, #grid_view_products_page_container img {
38
+ margin:0;
39
+ padding:0;
40
+ border:1px solid #ccc;
41
+ }
42
+
43
+ .wpsc_hidden{
44
+ display:none;
45
+ }
46
+
47
+ /*-----DEFAULT PRODUCT DISPLAY-----*/
48
+ #default_products_page_container {
49
+ width:100%;
50
+ position:relative;
51
+ line-height:1.2em;
52
+ }
53
+
54
+ #default_products_page_container .wpsc_page_numbers_top {
55
+ margin-bottom:20px;
56
+ }
57
+
58
+ #default_products_page_container .wpsc_page_numbers_bottom {
59
+ margin-top:20px;
60
+ }
61
+
62
+ .wpsc_category_grid_item {
63
+ text-align: center;
64
+ background: #EFEFEF;
65
+ border: 1px solid #CCC;
66
+ margin:10px;
67
+ text-decoration: none;
68
+ }
69
+
70
+ .wpsc_category_grid_item .item_no_image {
71
+ color:#000;
72
+ }
73
+
74
+
75
+ #default_products_page_container .wpsc_page_numbers_top a:link, #default_products_page_container .wpsc_page_numbers_top a:visited, #default_products_page_container .wpsc_page_numbers_bottom a:link, #default_products_page_container .wpsc_page_numbers_bottom a:visited {
76
+ padding:5px 4px;
77
+
78
+ }
79
+
80
+
81
+ #default_products_page_container .wpsc_page_numbers_top a:hover, #default_products_page_container .wpsc_page_numbers_top a:active, #default_products_page_container .wpsc_page_numbers_bottom a:hover, #default_products_page_container .wpsc_page_numbers_bottom a:active {
82
+
83
+ }
84
+
85
+ #default_products_page_container .wpsc_page_numbers_top span.current, #default_products_page_container .wpsc_page_numbers_top span.current, #default_products_page_container .wpsc_page_numbers_bottom span.current, #default_products_page_container .wpsc_page_numbers_bottom span.current {
86
+ padding:5px 4px;
87
+ }
88
+
89
+ .default_product_display {
90
+ margin-bottom:20px;
91
+ padding:10px;
92
+ position:relative;
93
+ }
94
+
95
+ .default_product_display .imagecol {
96
+
97
+ text-align: right;
98
+ display: table-cell;
99
+ vertical-align: middle;
100
+ min-height: 50px;
101
+ height: 100%;
102
+ overflow: auto;
103
+
104
+ }
105
+
106
+ .default_product_display .imagecol img.product_image {
107
+ background-color:#efefef;
108
+ }
109
+
110
+ .default_product_display .imagecol img.no-image, #content .default_product_display .imagecol img.no-image {
111
+ background-color:#EFEFEF;
112
+ display:block;
113
+ }
114
+
115
+ .default_product_display .productcol {
116
+ vertical-align: middle;
117
+ min-height: 50px;
118
+ }
119
+
120
+ .default_product_display h2.prodtitle, #content .default_product_display h2.prodtitle {
121
+ margin:0 0 5px 0;
122
+ line-height:1;
123
+ clear:none;
124
+ }
125
+
126
+ .default_product_display span.sale {
127
+ position:absolute;
128
+ top:-10px;
129
+ left:-10px;
130
+ text-indent:-9999px;
131
+ display:block;
132
+ }
133
+
134
+ .default_product_display .wpsc_description, #content .default_product_display .wpsc_description {
135
+ font-size:13px;
136
+ line-height:1.4em;
137
+ }
138
+
139
+ .default_product_display .additional_description, #content .default_product_display .additional_description {
140
+ font-size:13px;
141
+ line-height:1.4em;
142
+ margin:0;
143
+ }
144
+
145
+ .default_product_display .additional_description_container {
146
+ margin:20px 0;
147
+ }
148
+
149
+ .default_product_display a.additional_description_link:link, .default_product_display a.additional_description_link:visited {
150
+ text-decoration:underline;
151
+ color:#0062ce;
152
+ margin-left:5px;
153
+ }
154
+
155
+ .default_product_display a.additional_description_link:hover, .default_product_display a.additional_description_link:active {
156
+ text-decoration:none;
157
+ }
158
+
159
+ .default_product_display .additional_description {
160
+ display:none;
161
+ }
162
+
163
+ .default_product_display form.product_form fieldset, #content .default_product_display form.product_form fieldset {
164
+ border: none;
165
+ padding: 0px;
166
+ }
167
+
168
+ .default_product_display form.product_form fieldset legend, #content .default_product_display form.product_form fieldset legend {
169
+ font-size:18px;
170
+ font-weight: normal;
171
+ padding:0px;
172
+ }
173
+
174
+ .default_product_display .wpsc_variation_forms {
175
+ padding:2px;
176
+ margin-bottom:10px;
177
+ }
178
+
179
+ .wpsc_select_variation{
180
+ position:relative;
181
+ }
182
+
183
+ .default_product_display .wpsc_variation_forms table, #content .default_product_display .wpsc_variation_forms table, .default_product_display .wpsc_variation_forms table tr, #content .default_product_display .wpsc_variation_forms table tr, .default_product_display .wpsc_variation_forms table td, #content .default_product_display .wpsc_variation_forms table td {
184
+ border:none;
185
+ border-collapse:collapse;
186
+ margin:0;
187
+ }
188
+
189
+ .default_product_display .wpsc_variation_forms table td.col1, #content .default_product_display .wpsc_variation_forms table tr td.col1 {
190
+ width:10%;
191
+ text-align:left;
192
+ margin:0;
193
+ padding:2px;
194
+ }
195
+
196
+ .default_product_display .wpsc_variation_forms table td.col2, #content .default_product_display .wpsc_variation_forms table tr td.col2 {
197
+ width:80%;
198
+ text-align:left;
199
+ margin:0;
200
+ padding:2px;
201
+ }
202
+
203
+ .default_product_display .wpsc_variation_forms label {
204
+ font-family: Georgia, "Bitstream Charter", serif;
205
+ font-size:14px;
206
+ color:#000
207
+ }
208
+
209
+ .default_product_display .wpsc_variation_forms select {
210
+ margin:0;
211
+ min-width:100px;
212
+ max-width:200px;
213
+ }
214
+
215
+ .default_product_display .wpsc_quantity_update {
216
+ margin-bottom:10px;
217
+ padding-bottom:10px;
218
+ margin-left:10px;
219
+ }
220
+
221
+ .default_product_display .wpsc_quantity_update input, #content .default_product_display .wpsc_quantity_update input {
222
+ margin:0;
223
+ line-height:1.2em;
224
+ font-size:12px;
225
+ }
226
+
227
+
228
+ .default_product_display .wpsc_quantity_update label, #content .default_product_display .wpsc_quantity_update label {
229
+ font-family: Georgia, "Bitstream Charter", serif;
230
+ margin:0;
231
+ line-height:1.2em;
232
+ font-size:12px;
233
+ color:#F60;
234
+ }
235
+
236
+ .default_product_display .wpsc_product_price {
237
+ margin-bottom:10px;
238
+ font-size:16px;
239
+ padding:5px;
240
+ display:inline-block;
241
+ *zoom:1;
242
+ }
243
+
244
+ .default_product_display .is_variation,
245
+ .single_product_display .is_variation {
246
+ display: none;
247
+ }
248
+
249
+ .default_product_display .in_stock,
250
+ .single_product_display .in_stock {
251
+ position: relative;
252
+ background-image: url(wpsc-images/yes_stock.png);
253
+ background-repeat: no-repeat;
254
+ padding-left: 20px;
255
+ left:-5px;
256
+ }
257
+
258
+ .default_product_display .no_variation,
259
+ .single_product_display .no_variation,
260
+ .default_product_display .out_of_stock,
261
+ .single_product_display .out_of_stock {
262
+ position: relative;
263
+ background-image: url(wpsc-images/outofstock.png);
264
+ background-repeat: no-repeat;
265
+ padding-left: 20px;
266
+ left:-5px;
267
+ }
268
+
269
+
270
+ .default_product_display .wpsc_product_price p, #content .default_product_display .wpsc_product_price p {
271
+ margin:0;
272
+ }
273
+
274
+ .default_product_display .wpsc_product_price span.oldprice {
275
+ text-decoration:line-through;
276
+ color:#666;
277
+ }
278
+
279
+ .default_product_display p.soldout, #content .default_product_display p.soldout {
280
+ font-weight:bold;
281
+ font-size:14px;
282
+ color:#C33;
283
+ background:url(wpsc-images/outofstock.png) no-repeat scroll 0 2px transparent;
284
+ padding-left:18px;
285
+ margin:0;
286
+ }
287
+
288
+ .default_product_display div.wpsc_loading_animation {
289
+ visibility:hidden;
290
+ margin-top:5px;
291
+ }
292
+
293
+ .default_product_display div.wpsc_loading_animation img, #content .default_product_display div.wpsc_loading_animation img {
294
+ border:none;
295
+ }
296
+
297
+ .default_product_display .product_footer .product_average_vote strong {
298
+ font-size:0.8em;
299
+ float:left;
300
+ }
301
+
302
+ .default_product_display .product_footer .product_average_vote span {
303
+ font-size:0.8em;
304
+ float:left;
305
+ }
306
+
307
+ .default_product_display .product_footer .product_user_vote {
308
+ clear:both;
309
+ font-size:0.8em;
310
+ float:left;
311
+ }
312
+
313
+ .default_product_display .wpcart_gallery img, #content .default_product_display .wpcart_gallery img {
314
+ margin-right:6px;
315
+ border:1px solid #ccc;
316
+ }
317
+
318
+ .wpcart_gallery .attachment-gold-thumbnails, .imagecol .product_image{
319
+ cursor: -webkit-zoom-in;
320
+ cursor: -moz-zoom-in;
321
+ }
322
+
323
+
324
+ .single_product_display form.product_form .wpsc_buy_button_container,
325
+ #content .single_product_display form.product_form .wpsc_buy_button_container{
326
+ text-align: right;
327
+ }
328
+
329
+ .default_product_display .wpsc_buy_button_container{
330
+ float:right;
331
+ }
332
+
333
+ /*-----LIST VIEW PRODUCT DISPLAY-----*/
334
+ #list_view_products_page_container {
335
+ position:relative;
336
+ }
337
+
338
+ #list_view_products_page_container .wpsc_page_numbers_top {
339
+ margin-bottom:20px;
340
+ }
341
+
342
+ #list_view_products_page_container .wpsc_page_numbers_bottom {
343
+ margin-top:10px;
344
+ }
345
+
346
+ #list_view_products_page_container p, #content #list_view_products_page_container p {
347
+ line-height:1.2em;
348
+ margin:0;
349
+ padding:0;
350
+ }
351
+
352
+ #list_view_products_page_container span.sale {
353
+ display:none;
354
+ }
355
+
356
+
357
+ #list_view_products_page_container input, #content #list_view_products_page_container input, #list_view_products_page_container textarea, #content #list_view_products_page_container textarea {
358
+ margin:0;
359
+ padding:0;
360
+ }
361
+
362
+ table.list_productdisplay form.product_form {
363
+ display:inline;
364
+ }
365
+
366
+ table.list_productdisplay .quantity_container {
367
+ display:inline;
368
+ }
369
+
370
+ #content input.wpsc_buy_button{
371
+ font-size: 12px;
372
+ }
373
+
374
+ table.list_productdisplay .wpsc_buy_button_container {
375
+ display:inline;
376
+ position:relative;
377
+ }
378
+
379
+ table.list_productdisplay .wpsc_buy_button_container .wpsc_loading_animation {
380
+ position:absolute;
381
+ top:1px;
382
+ right:-85px;
383
+ *right:-100px;
384
+ font-size:10px;
385
+ width:100%;
386
+ vertical-align:middle;
387
+ line-height:1.2em;
388
+ }
389
+
390
+ table.list_productdisplay .wpsc_buy_button_container .wpsc_loading_animation img, #content table.list_productdisplay .wpsc_buy_button_container .wpsc_loading_animation img {
391
+ vertical-align:middle;
392
+ border:none;
393
+ float:left;
394
+ }
395
+
396
+ table.list_productdisplay .oldprice {
397
+ text-decoration:line-through;
398
+ }
399
+
400
+ #list_view_products_page_container table.list_productdisplay input.wpsc_buy_button, #content #list_view_products_page_container table.list_productdisplay input.wpsc_buy_button {
401
+ padding:5px;
402
+
403
+ }
404
+
405
+ table.list_productdisplay h2.prodtitle, #content table.list_productdisplay h2.prodtitle {
406
+ font-size:15px;
407
+ line-height:1.2em;
408
+ margin:0;
409
+ word-wrap: break-word;
410
+ }
411
+
412
+ table.list_productdisplay h2.prodtitle a:link, #content table.list_productdisplay h2.prodtitle a:link, table.list_productdisplay h2.prodtitle a:visited, #content table.list_productdisplay h2.prodtitle a:visited {
413
+ text-decoration:underline;
414
+ color:#006699;
415
+ }
416
+
417
+ table.list_productdisplay h2.prodtitle a:hover, #content table.list_productdisplay h2.prodtitle a:hover, table.list_productdisplay h2.prodtitle a:active, #content table.list_productdisplay h2.prodtitle a:active {
418
+ text-decoration:none;
419
+ }
420
+
421
+ table.list_productdisplay td.stock {
422
+ text-align:center;
423
+ }
424
+
425
+ table.list_productdisplay tr.alt {
426
+ background-color:#F8F8F8;
427
+ }
428
+
429
+ table.list_productdisplay p.soldout {
430
+ color:#C33;
431
+ }
432
+
433
+ /*-----SINGLE PRODUCTS PAGE-----*/
434
+ #single_product_page_container {
435
+ position:relative;
436
+ }
437
+
438
+ .single_product_display {
439
+ margin-bottom:20px;
440
+ padding:10px;
441
+ position:relative;
442
+ }
443
+
444
+ .imagecol {
445
+ margin-right:5px;
446
+ /* width:25%; */
447
+ float:left;
448
+ position:relative;
449
+ }
450
+
451
+ .single_product_display .imagecol img.product_image {
452
+ background-color:#efefef;
453
+ border:1px solid #ccc;
454
+ }
455
+
456
+ .single_product_display .imagecol img.no-image, #content .single_product_display .imagecol img.no-image {
457
+ background-color:#EFEFEF;
458
+ display:block;
459
+ }
460
+
461
+
462
+ .single_product_display .product_description, .single_product_display .single_additional_description {
463
+ font-size:14px;
464
+ line-height:1.2em;
465
+ margin:0 0 10px 0;
466
+ padding:0;
467
+ }
468
+
469
+ .single_product_display form.product_form fieldset, #content .single_product_display form.product_form fieldset {
470
+ border: none;
471
+ padding: 0px;
472
+ }
473
+
474
+ .single_product_display form.product_form fieldset legend, #content .single_product_display form.product_form fieldset legend {
475
+ font-size: 18px;
476
+ font-weight: normal;
477
+ padding: 0px;
478
+ }
479
+
480
+ .single_product_display form.product_form input, #content .single_product_display form.product_form input {
481
+ padding:2px;
482
+ margin:0;
483
+
484
+ line-height:1.2em;
485
+ font-size:14px;
486
+ }
487
+
488
+ .single_product_display form.product_form input.input_custom_text, #content .single_product_display form.product_form input.input_custom_text {
489
+ width:250px;
490
+ }
491
+
492
+ .single_product_display form.product_form fieldset p, #content .single_product_display form.product_form fieldset p {
493
+ margin:0 0 10px 0;
494
+ padding:0;
495
+ line-height:1.2em;
496
+ font-size:14px;
497
+ }
498
+
499
+ .default_product_display .wpsc_variation_forms {
500
+ padding:2px 0px 2px 0px;
501
+ margin-bottom:10px;
502
+ }
503
+
504
+ .single_product_display .wpsc_variation_forms table, #content .single_product_display .wpsc_variation_forms table, .single_product_display .wpsc_variation_forms table tr, #content .single_product_display .wpsc_variation_forms table tr, .single_product_display .wpsc_variation_forms table td, #content .single_product_display .wpsc_variation_forms table td {
505
+ border:none;
506
+ border-collapse:collapse;
507
+ margin:0;
508
+ }
509
+
510
+ .single_product_display .wpsc_variation_forms table td.col1, #content .single_product_display .wpsc_variation_forms table tr td.col1 {
511
+ width:10%;
512
+ text-align:left;
513
+ margin:0;
514
+ padding:2px;
515
+ }
516
+
517
+ .single_product_display .wpsc_variation_forms table td.col2, #content .single_product_display .wpsc_variation_forms table tr td.col2 {
518
+ width:80%;
519
+ text-align:left;
520
+ margin:0;
521
+ padding:2px;
522
+ }
523
+
524
+ .single_product_display .wpsc_variation_forms select {
525
+ margin:0;
526
+ min-width:100px;
527
+ max-width:200px;
528
+ }
529
+
530
+ .default_product_display .wpsc_quantity_update {
531
+ margin-bottom:10px;
532
+ padding-bottom:10px;
533
+ margin-left:10px;
534
+ }
535
+
536
+ .single_product_display .wpsc_quantity_update input, #content .single_product_display .wpsc_quantity_update input {
537
+ margin:0;
538
+ line-height:1.2em;
539
+ font-size:12px;
540
+ }
541
+
542
+
543
+ .single_product_display .wpsc_quantity_update label, #content .single_product_display .wpsc_quantity_update label {
544
+ font-family: Georgia, "Bitstream Charter", serif;
545
+ margin:0;
546
+ line-height:1.2em;
547
+ font-size:12px;
548
+ color:#F60;
549
+ }
550
+
551
+ .single_product_display .wpsc_product_price {
552
+ display: inline-block;
553
+ font-size: 16px;
554
+ margin-bottom: 10px;
555
+ padding: 5px;
556
+ }
557
+
558
+ .single_product_display .wpsc_product_price p, #content .single_product_display .wpsc_product_price p {
559
+ margin:0;
560
+ }
561
+
562
+ .single_product_display .wpsc_product_price span.oldprice {
563
+ text-decoration:line-through;
564
+ }
565
+
566
+ .single_product_display p.soldout {
567
+ font-weight:bold;
568
+ font-size:14px;
569
+ color:#C33;
570
+ background:url(wpsc-images/outofstock.png) no-repeat scroll 0 5px transparent;
571
+ padding-left:18px;
572
+ }
573
+
574
+ .single_product_display div.wpsc_loading_animation {
575
+ visibility:hidden;
576
+ }
577
+
578
+ .single_product_display .wpcart_gallery img, #content .single_product_display .wpcart_gallery img {
579
+ margin-right:6px;
580
+ border:1px solid #ccc;
581
+ }
582
+
583
+ .single_product_display .FB_like iframe {
584
+ border:none;
585
+ width:300px;
586
+ height:80px;
587
+ outline:none;
588
+ overflow:hidden;
589
+ }
590
+ /* ---- PRODUCT RATING STYLING ---- */
591
+
592
+ .wpsc_product_rating .star {
593
+ cursor:pointer;
594
+ text-indent:-999em;
595
+ display: block;
596
+ width: 18px;
597
+ width: 17px;
598
+ float: left;
599
+ }
600
+ .wpsc_product_rating .star a {
601
+ background-position:0 0;
602
+ display:block;
603
+ height:100%;
604
+ background:transparent url(wpsc-images/grey-star.png) no-repeat scroll 0 0;
605
+ outline: none;
606
+ }
607
+ .wpsc_product_rating .star a:hover {
608
+ background-position:0 0;
609
+ background:transparent url(wpsc-images/gold-star.png) no-repeat scroll 0 0;
610
+ }
611
+ .wpsc_product_rating .star a.selected {
612
+ background-position:0 0;
613
+ background:transparent url(wpsc-images/gold-star.png) no-repeat scroll 0 0;
614
+ }
615
+ .wpsc_product_rating .star a, .wpsc_product_rating .star a:focus {
616
+ outline: none;
617
+ }
618
+ div.product_footer{
619
+ position: relative;
620
+ clear: both;
621
+ padding: 0 !important;
622
+ width: 80%;
623
+ border-top: 1px dashed #ccc;
624
+ height: 35px;
625
+ margin-top: 1em;
626
+ }
627
+ div.product_footer strong{
628
+ display: block;
629
+ font-size: 7pt;
630
+ font-weight: normal;
631
+ }
632
+ div.product_average_vote{
633
+ position: absolute;
634
+ top: 0;
635
+ left: 0;
636
+ width: 50%;
637
+ float: left;
638
+ margin: 0 !important;
639
+ height: inherit;
640
+ }
641
+ div.product_user_vote{
642
+ position: absolute;
643
+ top: 0;
644
+ right: 0;
645
+ width: 30%;
646
+ margin: 0 !important;
647
+ height: inherit;
648
+ }
649
+ span.vote_total{
650
+ position: relative;
651
+ top: -3px;
652
+ left: 2px;
653
+ font-size: 7pt;
654
+ }
655
+ span.rating_saved{
656
+ color: #990000;
657
+ display: none;
658
+ }
659
+ /*-----FANCY NOTIFICATION STYLING-----*/
660
+ #fancy_notification{
661
+ position: absolute;
662
+ top: 0;
663
+ left: 0;
664
+ background: #ffffff;
665
+ border: 4px solid #cccccc;
666
+ display: none;
667
+ height: auto;
668
+ z-index: 9;
669
+ }
670
+ #fancy_notification #loading_animation{
671
+ display: none;
672
+ }
673
+ #fancy_notification #fancy_notification_content{
674
+ display: none;
675
+ width: 300px;
676
+ padding: 8px;
677
+ height: auto;
678
+ text-align: left;
679
+ margin: 0 !important;
680
+ }
681
+ #fancy_notification #fancy_notification_content span{
682
+ margin: 0 0 6px 0;
683
+ display: block;
684
+ font-weight: normal;
685
+ }
686
+ #fancy_notification #fancy_notification_content a{
687
+ display: block;
688
+ float: left;
689
+ margin-right: 6px;
690
+ margin-bottom: 3px;
691
+ }
692
+
693
+ /*-----SHOPPING CART-----*/
694
+ .shopping-cart-wrapper {
695
+ line-height:1.2em;
696
+ position:relative;
697
+ }
698
+
699
+ .shopping-cart-wrapper span.cart_message {
700
+ display:block;
701
+ padding:5px;
702
+ border:1px solid #dedede;
703
+ margin:10px 0;
704
+ }
705
+
706
+ .shopping-cart-wrapper .numberitems {
707
+ margin-bottom:5px;
708
+ display:block;
709
+ }
710
+
711
+ .shopping-cart-wrapper .shoppingcart {
712
+ padding:5px;
713
+ }
714
+
715
+ .shopping-cart-wrapper .shoppingcart table {
716
+ width:100%;
717
+ }
718
+
719
+ .shopping-cart-wrapper .shoppingcart table th {
720
+ font-family: Arial, sans-serif;
721
+ padding:2px;
722
+ }
723
+
724
+ .shopping-cart-wrapper .shoppingcart table th:first-child {
725
+ text-align: left;
726
+ }
727
+
728
+ .shopping-cart-wrapper .shoppingcart table tbody td {
729
+ padding:2px;
730
+ text-align:center;
731
+ }
732
+
733
+ .shopping-cart-wrapper .shoppingcart table .cart-widget-count{
734
+ width:70px;
735
+ }
736
+
737
+ .shopping-cart-wrapper .shoppingcart table tbody td, .shopping-cart-wrapper .shoppingcart table tbody td a {
738
+ text-decoration: none;
739
+ }
740
+
741
+ .shopping-cart-wrapper .shoppingcart table tbody td a:hover {
742
+ text-decoration: underline;
743
+ }
744
+
745
+ .shopping-cart-wrapper .remove_button {
746
+ background:url(wpsc-images/delete.png) no-repeat scroll 0 4px transparent;
747
+ width:14px;
748
+ text-indent:-9999px;
749
+ border:none;
750
+ outline:none;
751
+ *line-height:1;
752
+ cursor:pointer;
753
+ }
754
+
755
+ .shopping-cart-wrapper .shoppingcart table tbody td.cart-widget-remove{
756
+ padding:0px;
757
+ }
758
+
759
+ .shopping-cart-wrapper .checkout-shipping,
760
+ .shopping-cart-wrapper .checkout-tax,
761
+ .widget_wpsc_shopping_cart #cart-widget-links {
762
+ text-align: right;
763
+ padding: 0px 6px 0px 0px;
764
+ }
765
+
766
+ .widget_wpsc_shopping_cart .checkout-total, .widget_wpsc_shopping_cart .pluspostagetax {
767
+ text-align:right;
768
+ font-weight:bold;
769
+ }
770
+
771
+ .shopping-cart-wrapper .shoppingcart table tbody td.product-name{
772
+ text-align: left;
773
+ max-width: 90px;
774
+ word-wrap: break-word;
775
+ overflow: hidden;
776
+ }
777
+
778
+ .widget_wpsc_shopping_cart .cart-widget-total td {
779
+ border-top:solid 2px #000;
780
+ padding: 5px 6px 5px 5px;
781
+ }
782
+
783
+ .widget_wpsc_shopping_cart tr.cart-widget-shipping td {
784
+ border-top:1px solid #000;
785
+ }
786
+
787
+ .widget_wpsc_shopping_cart .shoppingcart{
788
+ position:relative;
789
+ }
790
+
791
+ .shopping-cart-wrapper a.emptycart:link, .shopping-cart-wrapper a.emptycart:visited {
792
+ text-decoration:none;
793
+ color:#666;
794
+ font-size:11px;
795
+ }
796
+
797
+ .shopping-cart-wrapper .gocheckout:active {
798
+ border:1px solid #ccc;
799
+ }
800
+
801
+ .shopping-cart-wrapper .empty {
802
+ margin-top:10px;
803
+ }
804
+ /*
805
+
806
+ .shopping-cart-wrapper a.visitshop:link, .shopping-cart-wrapper a.visitshop:visited {
807
+ text-decoration:underline;
808
+ font-size:12px;
809
+ color:#006699;
810
+ }
811
+
812
+ .shopping-cart-wrapper .empty {
813
+ margin-bottom:5px;
814
+ }
815
+ */
816
+
817
+ .shopping-cart-wrapper a.visitshop:hover, .shopping-cart-wrapper a.visitshop:active {
818
+ text-decoration:none;
819
+ }
820
+
821
+ /*-----CHECKOUT PAGE-----*/
822
+ #checkout_page_container {
823
+ position:relative;
824
+ clear:both;
825
+ }
826
+
827
+ #checkout_page_container textarea, #checkout_page_container input, #content #checkout_page_container textarea, #content #checkout_page_container input {
828
+ line-height:1.2em;
829
+ font-size:14px;
830
+ margin:0;
831
+ }
832
+
833
+ #checkout_page_container table.checkout_cart tr.header th{
834
+ text-align: center;
835
+ }
836
+
837
+ #checkout_page_container table.checkout_cart tr.header th:first-child{
838
+ text-align: left;
839
+ }
840
+
841
+ #checkout_page_container table.checkout_cart tr.wpsc_total_before_shipping td {
842
+
843
+ }
844
+
845
+ #checkout_page_container table.checkout_cart tr.wpsc_coupon_row td.coupon_code form{
846
+ text-align: right;
847
+ padding-right: 18px;
848
+ }
849
+
850
+ #checkout_page_container table.checkout_cart tr.wpsc_coupon_row td.coupon_code {
851
+ padding-left: 0px;
852
+ }
853
+
854
+ #checkout_page_container table.checkout_cart tr td, #content #checkout_page_container table.checkout_cart tr td {
855
+ margin:0;
856
+ padding:5px;
857
+ vertical-align:middle;
858
+ }
859
+
860
+ #checkout_page_container table.checkout_cart tr.wpsc_coupon_row td form input#coupon_num {
861
+ width: 293px;
862
+ padding: 0px;
863
+ margin: 0px 20px 0px 0px;
864
+ }
865
+
866
+ #checkout_page_container table.checkout_cart tr.wpsc_total_before_shipping td.wpsc_total_amount_before_shipping{
867
+ text-align: right;
868
+ }
869
+
870
+ #content #checkout_page_container p{
871
+ margin-bottom: 0px;
872
+ }
873
+
874
+ .wpsc_checkout_table input.text{
875
+ width:255px;
876
+ }
877
+
878
+ #content img#wpsc_checkout_gravatar{
879
+ float:left;
880
+ margin:0px 10px 10px 0px;
881
+ }
882
+
883
+ #checkout_page_container .wpsc_shipping_header {
884
+ background-color: #f5f5f5;
885
+ }
886
+
887
+ #checkout_page_container .total_price td.wpsc_totals{
888
+
889
+ }
890
+
891
+ #checkout_page_container .wpsc_make_purchase{
892
+ bottom: 20px;
893
+ float: right;
894
+ position: relative;
895
+ }
896
+
897
+ #checkout_page_container .total_price.total_shipping td{
898
+ border:none;
899
+ font-weight: normal;
900
+ }
901
+
902
+ #checkout_page_container .total_price.total_shipping td:first-child,
903
+ #checkout_page_container .total_price td:first-child {
904
+ padding-left: 50px;
905
+ }
906
+
907
+ #checkout_page_container .wpsc_shipping_quote_name,
908
+ #checkout_page_container .wpsc_shipping_quote_price,
909
+ #checkout_page_container .wpsc_shipping_quote_radio {
910
+ border-bottom: solid 1px #e1e1e1;
911
+ }
912
+
913
+ #checkout_page_container .wpsc_shipping_quote_name label,
914
+ #checkout_page_container .wpsc_shipping_quote_price label,
915
+ #checkout_page_container .wpsc_shipping_quote_radio label {
916
+ color:#000;
917
+ }
918
+
919
+ #content #checkout_page_container table.productcart tr td{
920
+ border-top:none;
921
+ padding-left: 0px;
922
+ }
923
+
924
+ #content #checkout_page_container table.productcart {
925
+ border: none;
926
+ }
927
+
928
+ #checkout_page_container table.checkout_cart tr.wpsc_coupon_row tr {
929
+ border-bottom: 0px;
930
+ }
931
+
932
+ #checkout_page_container p.validation-error {
933
+ clear:both;
934
+ color:red;
935
+ }
936
+
937
+ #content table.wpsc_checkout_table,
938
+ #content table.wpsc_checkout_table tr td {
939
+ border: none;
940
+ padding:0px;
941
+ vertical-align: top;
942
+ }
943
+
944
+ .wpsc-shopping-cart .asterix {
945
+ color:red;
946
+ }
947
+
948
+ #checkout_page_container img.product_image {
949
+ background-color:#efefef;
950
+ border:1px solid #ccc;
951
+ }
952
+
953
+ #checkout_page_container table.checkout_cart {
954
+ border:none;
955
+ }
956
+
957
+ #checkout_page_container table.checkout_cart tr, #content #checkout_page_container table.checkout_cart tr {
958
+ margin:0;
959
+ padding:0;
960
+ }
961
+
962
+ #content #checkout_page_container table.checkout_cart tr.wpsc_coupon_row td{
963
+ padding-top:15px;
964
+ padding-bottom: 15px;
965
+ padding-left: 0px;
966
+ }
967
+
968
+ #content #checkout_page_container table.checkout_cart tr.product_row td.wpsc_product_image img {
969
+ height: 31px;
970
+ width: 31px;
971
+ }
972
+
973
+ #content #checkout_page_container table.checkout_cart tr.product_row td, #content #checkout_page_container table.checkout_cart tr.product_row {
974
+ padding:2px 0px 1px 0px;
975
+ margin:0px;
976
+ line-height: 1;
977
+ }
978
+
979
+ #checkout_page_container table.checkout_cart td.firstcol {
980
+ vertical-align:middle;
981
+ text-align:center;
982
+ }
983
+
984
+ #checkout_page_container .coupon {
985
+ position:relative;
986
+ float:right;
987
+ margin:10px 0;
988
+ }
989
+
990
+ #checkout_page_container .coupon span.coupon_error {
991
+ position:absolute;
992
+ top:-24px;
993
+ left:156px;
994
+ color:#F30;
995
+ font-size:14px;
996
+ line-height:1.2em;
997
+ }
998
+
999
+ #checkout_page_container .col1 {
1000
+ float:left;
1001
+ width:320px;
1002
+ }
1003
+
1004
+ #checkout_page_container .col2 {
1005
+ float:right;
1006
+ width:320px;
1007
+ }
1008
+
1009
+ #checkout_page_container input.intra-field-label, #checkout_page_container textarea.intra-field-label{
1010
+ color:#bbb;
1011
+ }
1012
+
1013
+ #content #checkout_page_container table.checkout_cart tr.product_row td.wpsc_product_name {
1014
+ width: 200px;
1015
+ padding-left: 20px;
1016
+ }
1017
+
1018
+ .wpsc_registration_form {
1019
+ float:left;
1020
+ margin-top: 15px;
1021
+ width:300px;
1022
+ }
1023
+
1024
+ .wpsc_registration_form label {
1025
+ width:100px;
1026
+ display: inline-table;
1027
+ margin-bottom: 10px;
1028
+ }
1029
+
1030
+ .wpsc_registration_form fieldset {
1031
+ border: none;
1032
+ padding-left: 0px;
1033
+ padding-top: 12px;
1034
+ border-top-color: #E7E7E7;
1035
+
1036
+ border-top-style: solid;
1037
+ border-top-width: 2px;
1038
+ }
1039
+
1040
+ .wpsc_registration_form.wpsc_right_registration{
1041
+ border-left-style: solid;
1042
+ border-left-color: #E7E7E7;
1043
+ border-left-width: 2px;
1044
+ padding-left: 20px;
1045
+ }
1046
+
1047
+ .wpsc_signup_text {
1048
+ padding-top: 15px;
1049
+ font-size: 12px;
1050
+
1051
+ }
1052
+
1053
+ #shippingSameBilling{
1054
+ position:relative;
1055
+ right:10px;
1056
+ }
1057
+
1058
+ #shippingsameasbillingmessage{
1059
+ display:none;
1060
+ }
1061
+
1062
+ .wpsc_no_image{
1063
+ display: none;
1064
+ }
1065
+
1066
+ .clear{
1067
+ clear:both;
1068
+ }
1069
+
1070
+ /*-----Featured Image-----*/
1071
+ .item_text {
1072
+ float:left;
1073
+ width:33%;
1074
+ }
1075
+
1076
+ .item_text h2 a{
1077
+ color: #000000;
1078
+ font-family: Arial,sans-serif;
1079
+ font-weight: bold;
1080
+ text-decoration: none;
1081
+ }
1082
+
1083
+ .featured_item_image a img {
1084
+ float:right;
1085
+ width:80%;
1086
+ }
1087
+
1088
+ .wpsc_container.wpsc_featured{
1089
+ margin-top: 20px;
1090
+ margin-bottom: 20px;
1091
+ }
1092
+
1093
+
1094
+ .featured_product_price{
1095
+ font-style: oblique;
1096
+ margin-bottom: 10px;
1097
+ }
1098
+
1099
+ .wpsc_description a{
1100
+ text-decoration: none;
1101
+ font-size: 14px;
1102
+ }
wpsc-components/theme-engine-v1/templates/wpsc-featured_product.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ foreach ( $query as $product ) :
3
+ setup_postdata( $product );
4
+
5
+ global $post;
6
+ $old_post = $post;
7
+ $post = $product;
8
+ ?>
9
+ <div class="wpsc_container wpsc_featured">
10
+ <div class="featured_product_display">
11
+ <div class="featured_product_display_item product_view_<?php $product->ID; ?>">
12
+
13
+ <div class="item_text">
14
+ <h2><a href='<?php echo get_permalink( $product->ID ); ?>'><?php echo get_the_title( $product->ID ); ?></a></h2>
15
+ <div class="pricedisplay featured_product_price">
16
+ <?php esc_html_e( 'Price:', 'wpsc' ); ?> <?php echo wpsc_the_product_price(); ?>
17
+ </div>
18
+
19
+ <div class='wpsc_description'>
20
+ <?php echo wpsc_the_product_description(); ?> <a href='<?php echo get_permalink( $product->ID ); ?>'><?php esc_html_e( 'More Information&hellip;', 'wpsc' ); ?></a>
21
+ </div>
22
+
23
+ </div><?php if ( wpsc_the_product_thumbnail ( ) ) : ?>
24
+ <div class="featured_item_image">
25
+ <a href="<?php echo get_permalink( $product->ID ); ?>" title="<?php echo get_the_title( $product->ID ); ?>"><?php echo wpsc_the_sticky_image( wpsc_the_product_id() ); ?></a>
26
+ </div><?php else: ?>
27
+
28
+ <div class="item_no_image">
29
+ <a href="<?php echo get_the_title( $product->ID ); ?>"><span><?php esc_html_e( 'No Image Available', 'wpsc' ); ?></span></a>
30
+ </div><?php endif; ?>
31
+ </div>
32
+ <div class="clear"></div>
33
+ </div>
34
+ </div>
35
+
36
+ <?php endforeach;
37
+ $post = $old_post;
38
+ ?>
wpsc-components/theme-engine-v1/templates/wpsc-grid_view.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ global $wp_query;
3
+ $image_width = get_option('product_image_width');
4
+ $image_height = get_option('product_image_height');
5
+ ?>
6
+ <div id="grid_view_products_page_container">
7
+ <?php wpsc_output_breadcrumbs(); ?>
8
+
9
+ <?php do_action('wpsc_top_of_products_page'); // Plugin hook for adding things to the top of the products page, like the live search ?>
10
+
11
+ <?php if(wpsc_display_categories()): ?>
12
+ <?php if(get_option('wpsc_category_grid_view') == 1) :?>
13
+ <div class="wpsc_categories wpsc_category_grid group">
14
+ <?php wpsc_start_category_query(array('category_group'=> 1, 'show_thumbnails'=> 1)); ?>
15
+ <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_grid_item <?php wpsc_print_category_classes_section(); ?>" title="<?php wpsc_print_category_name();?>">
16
+ <?php wpsc_print_category_image(); ?>
17
+ </a>
18
+ <?php wpsc_print_subcategory("", ""); ?>
19
+ <?php wpsc_end_category_query(); ?>
20
+
21
+ </div><!--close wpsc_categories-->
22
+ <?php else:?>
23
+ <ul class="wpsc_categories">
24
+ <?php wpsc_start_category_query(array('category_group'=> 1, 'show_thumbnails'=> get_option('show_category_thumbnails'))); ?>
25
+ <li>
26
+ <?php wpsc_print_category_image(); ?>
27
+
28
+ <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_link <?php wpsc_print_category_classes_section(); ?>"><?php wpsc_print_category_name();?></a>
29
+ <?php if(get_option('wpsc_category_description')) :?>
30
+ <?php wpsc_print_category_description("<div class='wpsc_subcategory'>", "</div>"); ?>
31
+ <?php endif;?>
32
+
33
+ <?php wpsc_print_subcategory("<ul>", "</ul>"); ?>
34
+ </li>
35
+ <?php wpsc_end_category_query(); ?>
36
+ </ul>
37
+ <?php endif; ?>
38
+ <?php endif; ?>
39
+
40
+ <?php if(wpsc_display_products()): ?>
41
+ <?php if(wpsc_is_in_category()) : ?>
42
+ <div class="wpsc_category_details">
43
+ <?php if(get_option('show_category_thumbnails') && wpsc_category_image()) : ?>
44
+ <img src="<?php echo wpsc_category_image(); ?>" alt="<?php echo wpsc_category_name(); ?>" title="<?php echo wpsc_category_name(); ?>" />
45
+ <?php endif; ?>
46
+
47
+ <?php if(get_option('wpsc_category_description') && wpsc_category_description()) : ?>
48
+ <?php echo wpsc_category_description(); ?>
49
+ <?php endif; ?>
50
+ </div><!--close wpsc_category_details-->
51
+ <?php endif; ?>
52
+
53
+
54
+ <?php if(wpsc_has_pages_top()) : ?>
55
+ <div class="wpsc_page_numbers_top group">
56
+ <?php wpsc_pagination(); ?>
57
+ </div><!--close wpsc_page_numbers_top-->
58
+ <?php endif; ?>
59
+
60
+
61
+ <div class="product_grid_display group">
62
+ <?php while (wpsc_have_products()) : wpsc_the_product(); ?>
63
+ <div class="product_grid_item product_view_<?php echo wpsc_the_product_id(); ?>">
64
+
65
+ <?php if(wpsc_the_product_thumbnail()) :?>
66
+ <div class="item_image">
67
+ <a href="<?php echo wpsc_the_product_permalink(); ?>">
68
+ <img style="width:<?php echo get_option('product_image_width'); ?>px;height:<?php echo get_option('product_image_height'); ?>px" class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>" />
69
+ </a>
70
+ </div><!--close imte_image-->
71
+ <?php else: ?>
72
+ <div class="item_no_image">
73
+ <a href="<?php echo wpsc_the_product_permalink(); ?>">
74
+ <img class="no-image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php esc_attr_e( 'No Image', 'wpsc' ); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/noimage.png" width="<?php echo get_option('product_image_width'); ?>" height="<?php echo get_option('product_image_height'); ?>" />
75
+ </a>
76
+ </div><!--close item_no_image-->
77
+ <?php endif; ?>
78
+
79
+ <?php if(wpsc_product_on_special()) : ?><span class="sale"><?php _e('Sale', 'wpsc'); ?></span><?php endif; ?>
80
+ <?php if(get_option('show_images_only') != 1): ?>
81
+ <div class="grid_product_info">
82
+ <h2 class="prodtitle"><a href="<?php echo wpsc_the_product_permalink(); ?>" title="<?php echo wpsc_the_product_title(); ?>"><?php echo wpsc_the_product_title(); ?></a></h2>
83
+
84
+ <?php if((wpsc_the_product_description() != '') && (get_option('display_description') == 1)): ?>
85
+ <div class="grid_description"><?php echo wpsc_the_product_description(); ?></div>
86
+ <?php endif; ?>
87
+ <div class="price_container">
88
+ <?php wpsc_the_product_price_display( array( 'output_you_save' => false ) ); ?>
89
+ <?php if(wpsc_show_pnp()) : ?>
90
+ <p class="pricedisplay"><?php _e('Shipping', 'wpsc'); ?>:<span class="pp_price"><?php echo wpsc_product_postage_and_packaging(); ?></span></p>
91
+ <?php endif; ?>
92
+ </div><!--close price_container-->
93
+ <?php if(get_option('display_moredetails') == 1) : ?>
94
+ <a href="<?php echo wpsc_the_product_permalink(); ?>" class="more_details"><?php esc_html_e( 'More Details', 'wpsc' ); ?></a>
95
+ <?php endif; ?>
96
+ </div><!--close grid_product_info-->
97
+ <div class="grid_more_info">
98
+ <form class="product_form" enctype="multipart/form-data" action="<?php echo wpsc_this_page_url(); ?>" method="post" name="product_<?php echo wpsc_the_product_id(); ?>" id="product_<?php echo wpsc_the_product_id(); ?>" >
99
+ <?php do_action ( 'wpsc_product_form_fields_begin' ); ?>
100
+ <input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/>
101
+ <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/>
102
+
103
+
104
+ <?php if(get_option('display_variations') == 1) : ?>
105
+ <?php /** the variation group HTML and loop */ ?>
106
+ <?php if (wpsc_have_variation_groups()) : ?>
107
+ <fieldset><legend><?php _e('Product Options', 'wpsc'); ?></legend>
108
+ <div class="wpsc_variation_forms">
109
+ <table>
110
+ <?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
111
+ <tr><td class="col1"><label for="<?php echo wpsc_vargrp_form_id(); ?>"><?php echo wpsc_the_vargrp_name(); ?>:</label></td>
112
+ <?php /** the variation HTML and loop */?>
113
+ <td class="col2"><select class="wpsc_select_variation" name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>">
114
+ <?php while (wpsc_have_variations()) : wpsc_the_variation(); ?>
115
+ <option value="<?php echo wpsc_the_variation_id(); ?>" <?php echo wpsc_the_variation_out_of_stock(); ?>><?php echo wpsc_the_variation_name(); ?></option>
116
+ <?php endwhile; ?>
117
+ </select></td></tr>
118
+ <?php endwhile; ?>
119
+ </table>
120
+ <div id="variation_display_<?php echo wpsc_the_product_id(); ?>" class="is_variation"><?php _e('Combination of product variants is not available', 'wpsc'); ?></div>
121
+ </div><!--close wpsc_variation_forms-->
122
+ </fieldset>
123
+ <?php /** the variation group HTML and loop ends here */?>
124
+ <?php endif; ?>
125
+ <?php endif ?>
126
+ <?php if((get_option('display_addtocart') == 1) && (get_option('addtocart_or_buynow') !='1')) :?>
127
+ <?php if(wpsc_product_has_stock()) : ?>
128
+ <?php if(wpsc_has_multi_adding()): ?>
129
+ <div class="quantity_container">
130
+ <label class="wpsc_quantity_update" for="wpsc_quantity_update_<?php echo wpsc_the_product_id(); ?>"><?php _e('Quantity:', 'wpsc'); ?></label>
131
+ <input type="text" id="wpsc_quantity_update_<?php echo wpsc_the_product_id(); ?>" name="wpsc_quantity_update" size="2" value="1" />
132
+ <input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
133
+ <input type="hidden" name="wpsc_update_quantity" value="true" />
134
+ </div><!--close quantity_container-->
135
+ <?php endif ;?>
136
+ <input type="submit" value="<?php _e('Add To Cart', 'wpsc'); ?>" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button"/>
137
+ <?php else : ?>
138
+ <p class="soldout"><?php _e('Sorry, sold out!', 'wpsc'); ?></p>
139
+ <?php endif ; ?>
140
+ <?php endif; ?>
141
+
142
+
143
+ <div class="wpsc_loading_animation">
144
+ <img title="<?php esc_attr_e( 'Loading', 'wpsc' ); ?>" alt="<?php esc_attr_e( 'Loading', 'wpsc' ); ?>" src="<?php echo wpsc_loading_animation_url(); ?>" />
145
+ <?php _e('Updating cart...', 'wpsc'); ?>
146
+ </div><!--close wpsc_loading_animation-->
147
+ <?php do_action ( 'wpsc_product_form_fields_end' ); ?>
148
+ </form>
149
+ </div><!--close grid_more_info-->
150
+
151
+ <?php if((get_option('display_addtocart') == 1) && (get_option('addtocart_or_buynow') == '1')) :?>
152
+ <?php echo wpsc_buy_now_button(wpsc_the_product_id()); ?>
153
+ <?php endif ; ?>
154
+
155
+ <?php endif; ?>
156
+ </div><!--close product_grid_item-->
157
+ <?php if((get_option('grid_number_per_row') > 0) && ((($wp_query->current_post +1) % get_option('grid_number_per_row')) == 0)) :?>
158
+ <div class="grid_view_clearboth"></div>
159
+ <?php endif ; ?>
160
+
161
+
162
+
163
+ <?php endwhile; ?>
164
+
165
+ <?php if(wpsc_product_count() == 0):?>
166
+ <p><?php _e('There are no products in this group.', 'wpsc'); ?></p>
167
+ <?php endif ; ?>
168
+
169
+
170
+ </div><!--close product_grid_display-->
171
+
172
+ <?php if(wpsc_has_pages_bottom()) : ?>
173
+ <div class="wpsc_page_numbers_bottom group">
174
+ <?php wpsc_pagination(); ?>
175
+ </div><!--close wpsc_page_numbers_bottom-->
176
+ <?php endif; ?>
177
+ <?php endif; ?>
178
+
179
+ <?php do_action( 'wpsc_theme_footer' ); ?>
180
+
181
+ </div><!--close grid_view_products_page_container-->
wpsc-components/theme-engine-v1/templates/wpsc-images/bulletpoint.gif ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/cart.png ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/delete.png ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/gold-star.gif ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/grey-star.gif ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/icon_window_collapse.gif ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/icon_window_expand.gif ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/indicator.gif ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/no_stock.gif ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/noimage.png ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/outofstock.png ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/sale.png ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/yes_stock.gif ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-images/yes_stock.png ADDED
Binary file
wpsc-components/theme-engine-v1/templates/wpsc-list_view.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ global $wp_query, $wpdb;
3
+ ?>
4
+ <div id="list_view_products_page_container">
5
+
6
+ <?php wpsc_output_breadcrumbs(); ?>
7
+
8
+ <?php do_action('wpsc_top_of_products_page'); // Plugin hook for adding things to the top of the products page, like the live search ?>
9
+
10
+ <?php if(wpsc_display_categories()): ?>
11
+ <?php if(wpsc_category_grid_view()) :?>
12
+ <div class="wpsc_categories wpsc_category_grid group">
13
+ <?php wpsc_start_category_query(array('category_group'=> 1, 'show_thumbnails'=> 1)); ?>
14
+ <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_grid_item <?php wpsc_print_category_classes_section(); ?>" title="<?php wpsc_print_category_name();?>">
15
+ <?php wpsc_print_category_image(); ?>
16
+ </a>
17
+ <?php wpsc_print_subcategory("", ""); ?>
18
+ <?php wpsc_end_category_query(); ?>
19
+ </div><!--close wpsc_categories-->
20
+ <?php else:?>
21
+ <ul class="wpsc_categories">
22
+ <?php wpsc_start_category_query(array('category_group'=> 1, 'show_thumbnails'=> get_option('show_category_thumbnails'))); ?>
23
+ <li>
24
+ <?php wpsc_print_category_image(); ?>
25
+
26
+ <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_link <?php wpsc_print_category_classes_section(); ?>"><?php wpsc_print_category_name();?></a>
27
+ <?php if(get_option('wpsc_category_description')) :?>
28
+ <?php wpsc_print_category_description("<div class='wpsc_subcategory'>", "</div>"); ?>
29
+ <?php endif;?>
30
+
31
+ <?php wpsc_print_subcategory("<ul>", "</ul>"); ?>
32
+ </li>
33
+ <?php wpsc_end_category_query(); ?>
34
+ </ul>
35
+ <?php endif; ?>
36
+ <?php endif; ?>
37
+
38
+
39
+
40
+
41
+ <?php if(wpsc_display_products()): ?>
42
+ <?php if(wpsc_is_in_category()) : ?>
43
+ <div class="wpsc_category_details">
44
+ <?php if(get_option('show_category_thumbnails') && wpsc_category_image()) : ?>
45
+ <img src='<?php echo wpsc_category_image(); ?>' alt='<?php echo wpsc_category_name(); ?>' title='<?php echo wpsc_category_name(); ?>' />
46
+ <?php endif; ?>
47
+
48
+ <?php if(get_option('wpsc_category_description') && wpsc_category_description()) : ?>
49
+ <?php echo wpsc_category_description(); ?>
50
+ <?php endif; ?>
51
+ </div><!--close wpsc_category_details-->
52
+ <?php endif; ?>
53
+
54
+ <?php if(wpsc_has_pages_top()) : ?>
55
+ <div class="wpsc_page_numbers_top">
56
+ <?php wpsc_pagination(); ?>
57
+ </div><!--close wpsc_page_numbers_top-->
58
+ <?php endif; ?>
59
+ <table class="list_productdisplay <?php echo wpsc_category_class(); ?>">
60
+ <?php /** start the product loop here */?>
61
+ <?php $alt = 0; ?>
62
+ <?php while (wpsc_have_products()) : wpsc_the_product(); ?>
63
+ <?php
64
+ $alt++;
65
+ if ($alt %2 == 1) { $alt_class = 'alt'; } else { $alt_class = ''; }
66
+ ?>
67
+ <tr class="product_view_<?php echo wpsc_the_product_id(); ?> <?php echo $alt_class;?>">
68
+ <td width="40%">
69
+ <h2 class="prodtitle">
70
+ <?php if(get_option('hide_name_link') == 1) : ?>
71
+ <?php echo wpsc_the_product_title(); ?>
72
+ <?php else: ?>
73
+ <a class="wpsc_product_title" href="<?php echo wpsc_the_product_permalink(); ?>"><?php echo wpsc_the_product_title(); ?></a>
74
+ <?php endif; ?>
75
+ <?php echo wpsc_edit_the_product_link(); ?>
76
+ </h2>
77
+ </td>
78
+ <?php if(wpsc_show_stock_availability()): ?>
79
+ <td class="stock">
80
+ <?php if(wpsc_product_has_stock()) : ?>
81
+ <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="in_stock"><?php _e('Product in stock', 'wpsc'); ?></div>
82
+ <?php else: ?>
83
+ <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="out_of_stock"><?php _e('Product not in stock', 'wpsc'); ?></div>
84
+ <?php endif; ?>
85
+ </td>
86
+ <?php endif; ?>
87
+
88
+ <td>
89
+ <?php do_action('wpsc_product_before_description', wpsc_the_product_id(), $wp_query->post); ?>
90
+ </td>
91
+ <td class='wpsc_price_td'>
92
+ <?php wpsc_the_product_price_display( array( 'output_you_save' => false ) ); ?>
93
+ </td>
94
+
95
+ <td>
96
+ <?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
97
+ <?php $action = wpsc_product_external_link(wpsc_the_product_id()); ?>
98
+ <?php else: ?>
99
+ <?php $action = wpsc_this_page_url(); ?>
100
+ <?php endif; ?>
101
+ <form class='product_form' id="product_<?php echo wpsc_the_product_id(); ?>" enctype="multipart/form-data" action="<?php echo $action; ?>" method="post" name="product_<?php echo wpsc_the_product_id(); ?>">
102
+ <?php do_action ( 'wpsc_product_form_fields_begin' ); ?>
103
+
104
+ <?php if(wpsc_has_multi_adding()): ?>
105
+ <div class="quantity_container">
106
+ <label class="wpsc_quantity_update" for="wpsc_quantity_update_<?php echo wpsc_the_product_id(); ?>"><?php _e('Quantity:', 'wpsc'); ?></label>
107
+ <input type="text" id="wpsc_quantity_update_<?php echo wpsc_the_product_id(); ?>" name="wpsc_quantity_update" size="2" value="1" />
108
+ <input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
109
+ <input type="hidden" name="wpsc_update_quantity" value="true" />
110
+ </div><!--close quantity_container-->
111
+ <?php endif ;?>
112
+ <input type="hidden" value="add_to_cart" name="wpsc_ajax_action" />
113
+ <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id" />
114
+
115
+ <?php if((get_option('hide_addtocart_button') == 0) && (get_option('addtocart_or_buynow') !='1')) : ?>
116
+ <?php if(wpsc_product_has_stock()) : ?>
117
+ <div class="wpsc_buy_button_container">
118
+ <?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
119
+ <?php $action = wpsc_product_external_link( wpsc_the_product_id() ); ?>
120
+ <input class="wpsc_buy_button" type="button" value="<?php echo wpsc_product_external_link_text( wpsc_the_product_id(), __( 'Buy Now', 'wpsc' ) ); ?>" onclick="return gotoexternallink('<?php echo $action; ?>', '<?php echo wpsc_product_external_link_target( wpsc_the_product_id() ); ?>')">
121
+ <?php else: ?>
122
+ <input type="submit" value="<?php _e('Add To Cart', 'wpsc'); ?>" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button" />
123
+ <?php endif; ?>
124
+ <div class="wpsc_loading_animation">
125
+ <img title="<?php esc_attr_e( 'Loading', 'wpsc' ); ?>" alt="<?php esc_attr_e( 'Loading', 'wpsc' ); ?>" src="<?php echo wpsc_loading_animation_url(); ?>" />
126
+ <?php _e('Updating cart...', 'wpsc'); ?>
127
+ </div><!--close wpsc_loading_animation-->
128
+ </div><!--close wpsc_buy_button_container-->
129
+ <?php else : ?>
130
+ <p class="soldout"><?php _e('This product has sold out.', 'wpsc'); ?></p>
131
+ <?php endif ; ?>
132
+ <?php endif ; ?>
133
+ <?php do_action ( 'wpsc_product_form_fields_end' ); ?>
134
+ </form>
135
+ </td>
136
+ </tr>
137
+ <?php endwhile; ?>
138
+ <?php /** end the product loop here */?>
139
+ </table>
140
+
141
+
142
+ <?php if(wpsc_product_count() == 0):?>
143
+ <p><?php _e('There are no products in this group.', 'wpsc'); ?></p>
144
+ <?php endif ; ?>
145
+
146
+ <?php do_action( 'wpsc_theme_footer' ); ?>
147
+
148
+ <?php if(wpsc_has_pages_bottom()) : ?>
149
+ <div class="wpsc_page_numbers_bottom">
150
+ <?php wpsc_pagination(); ?>
151
+ </div><!--close wpsc_page_numbers_bottom-->
152
+ <?php endif; ?>
153
+ <?php endif; ?>
154
+ </div><!--close list_view_products_page_container-->
wpsc-components/theme-engine-v1/templates/wpsc-products_page.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ global $wp_query;
3
+ $image_width = get_option('product_image_width');
4
+ /*
5
+ * Most functions called in this page can be found in the wpsc_query.php file
6
+ */
7
+ ?>
8
+ <div id="default_products_page_container" class="wrap wpsc_container">
9
+
10
+ <?php wpsc_output_breadcrumbs(); ?>
11
+
12
+ <?php do_action('wpsc_top_of_products_page'); // Plugin hook for adding things to the top of the products page, like the live search ?>
13
+ <?php if(wpsc_display_categories()): ?>
14
+ <?php if(wpsc_category_grid_view()) :?>
15
+ <div class="wpsc_categories wpsc_category_grid group">
16
+ <?php wpsc_start_category_query(array('category_group'=> get_option('wpsc_default_category'), 'show_thumbnails'=> 1)); ?>
17
+ <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_grid_item <?php wpsc_print_category_classes_section(); ?>" title="<?php wpsc_print_category_name(); ?>">
18
+ <?php wpsc_print_category_image(); ?>
19
+ </a>
20
+ <?php wpsc_print_subcategory("", ""); ?>
21
+ <?php wpsc_end_category_query(); ?>
22
+
23
+ </div><!--close wpsc_categories-->
24
+ <?php else:?>
25
+ <ul class="wpsc_categories">
26
+
27
+ <?php wpsc_start_category_query(array('category_group'=>get_option('wpsc_default_category'), 'show_thumbnails'=> get_option('show_category_thumbnails'))); ?>
28
+ <li>
29
+ <?php wpsc_print_category_image(); ?>
30
+
31
+ <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_link <?php wpsc_print_category_classes_section(); ?>" title="<?php wpsc_print_category_name(); ?>"><?php wpsc_print_category_name(); ?></a>
32
+ <?php if(wpsc_show_category_description()) :?>
33
+ <?php wpsc_print_category_description("<div class='wpsc_subcategory'>", "</div>"); ?>
34
+ <?php endif;?>
35
+
36
+ <?php wpsc_print_subcategory("<ul>", "</ul>"); ?>
37
+ </li>
38
+ <?php wpsc_end_category_query(); ?>
39
+ </ul>
40
+ <?php endif; ?>
41
+ <?php endif; ?>
42
+ <?php // */ ?>
43
+
44
+ <?php if(wpsc_display_products()): ?>
45
+
46
+ <?php if(wpsc_is_in_category()) : ?>
47
+ <div class="wpsc_category_details">
48
+ <?php if(wpsc_show_category_thumbnails()) : ?>
49
+ <img src="<?php echo wpsc_category_image(); ?>" alt="<?php echo wpsc_category_name(); ?>" />
50
+ <?php endif; ?>
51
+
52
+ <?php if(wpsc_show_category_description() && wpsc_category_description()) : ?>
53
+ <?php echo wpsc_category_description(); ?>
54
+ <?php endif; ?>
55
+ </div><!--close wpsc_category_details-->
56
+ <?php endif; ?>
57
+ <?php if(wpsc_has_pages_top()) : ?>
58
+ <div class="wpsc_page_numbers_top">
59
+ <?php wpsc_pagination(); ?>
60
+ </div><!--close wpsc_page_numbers_top-->
61
+ <?php endif; ?>
62
+
63
+
64
+ <div class="wpsc_default_product_list">
65
+ <?php /** start the product loop here */?>
66
+ <?php while (wpsc_have_products()) : wpsc_the_product(); ?>
67
+
68
+ <div class="default_product_display product_view_<?php echo wpsc_the_product_id(); ?> <?php echo wpsc_category_class(); ?> group">
69
+ <h2 class="prodtitle entry-title">
70
+ <?php if(get_option('hide_name_link') == 1) : ?>
71
+ <?php echo wpsc_the_product_title(); ?>
72
+ <?php else: ?>
73
+ <a class="wpsc_product_title" href="<?php echo esc_url( wpsc_the_product_permalink() ); ?>"><?php echo wpsc_the_product_title(); ?></a>
74
+ <?php endif; ?>
75
+ </h2>
76
+ <?php if(wpsc_show_thumbnails()) :?>
77
+ <div class="imagecol" style="width:<?php echo $image_width; ?>px;" id="imagecol_<?php echo wpsc_the_product_id(); ?>">
78
+ <?php if(wpsc_the_product_thumbnail()) :
79
+ ?>
80
+ <a rel="<?php echo wpsc_the_product_title(); ?>" class="<?php echo wpsc_the_product_image_link_classes(); ?>" href="<?php echo esc_url( wpsc_the_product_image() ); ?>">
81
+ <img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>"/>
82
+
83
+ </a>
84
+ <?php else: ?>
85
+ <a href="<?php echo esc_url( wpsc_the_product_permalink() ); ?>">
86
+ <img class="no-image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php esc_attr_e( 'No Image', 'wpsc' ); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/noimage.png" width="<?php echo get_option('product_image_width'); ?>" height="<?php echo get_option('product_image_height'); ?>" />
87
+ </a>
88
+ <?php endif; ?>
89
+ <?php
90
+ if(gold_cart_display_gallery()) :
91
+ echo gold_shpcrt_display_gallery(wpsc_the_product_id(), true);
92
+ endif;
93
+ ?>
94
+ </div><!--close imagecol-->
95
+ <?php endif; ?>
96
+ <div class="productcol" style="margin-left:<?php echo $image_width + 20; ?>px;" >
97
+
98
+
99
+
100
+ <?php
101
+ do_action('wpsc_product_before_description', wpsc_the_product_id(), $wp_query->post);
102
+ do_action('wpsc_product_addons', wpsc_the_product_id());
103
+ ?>
104
+
105
+
106
+ <div class="wpsc_description">
107
+ <?php echo wpsc_the_product_description(); ?>
108
+ </div><!--close wpsc_description-->
109
+
110
+ <?php if(wpsc_the_product_additional_description()) : ?>
111
+ <div class="additional_description_container">
112
+ <img class="additional_description_button" src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/icon_window_expand.gif" alt="<?php esc_html_e( 'Additional Description', 'wpsc' ); ?>" /><a href="<?php echo esc_url( wpsc_the_product_permalink() ); ?>" class="additional_description_link"><?php esc_html_e('More Details', 'wpsc'); ?>
113
+ </a>
114
+ <div class="additional_description">
115
+ <p><?php echo wpsc_the_product_additional_description(); ?></p>
116
+ </div><!--close additional_description-->
117
+ </div><!--close additional_description_container-->
118
+ <?php endif; ?>
119
+
120
+ <?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
121
+ <?php $action = wpsc_product_external_link(wpsc_the_product_id()); ?>
122
+ <?php else: ?>
123
+ <?php $action = wpsc_this_page_url(); ?>
124
+ <?php endif; ?>
125
+ <form class="product_form" enctype="multipart/form-data" action="<?php echo esc_url( $action ); ?>" method="post" name="product_<?php echo wpsc_the_product_id(); ?>" id="product_<?php echo wpsc_the_product_id(); ?>" >
126
+ <?php do_action ( 'wpsc_product_form_fields_begin' ); ?>
127
+ <?php /** the variation group HTML and loop */?>
128
+ <?php if (wpsc_have_variation_groups()) { ?>
129
+ <fieldset><legend><?php _e('Product Options', 'wpsc'); ?></legend>
130
+ <div class="wpsc_variation_forms">
131
+ <table>
132
+ <?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
133
+ <tr><td class="col1"><label for="<?php echo wpsc_vargrp_form_id(); ?>"><?php echo wpsc_the_vargrp_name(); ?>:</label></td>
134
+ <?php /** the variation HTML and loop */?>
135
+ <td class="col2"><select class="wpsc_select_variation" name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>">
136
+ <?php while (wpsc_have_variations()) : wpsc_the_variation(); ?>
137
+ <option value="<?php echo wpsc_the_variation_id(); ?>" <?php echo wpsc_the_variation_out_of_stock(); ?>><?php echo wpsc_the_variation_name(); ?></option>
138
+ <?php endwhile; ?>
139
+ </select></td></tr>
140
+ <?php endwhile; ?>
141
+ </table>
142
+ <div id="variation_display_<?php echo wpsc_the_product_id(); ?>" class="is_variation"><?php _e('Combination of product variants is not available', 'wpsc'); ?></div>
143
+ </div><!--close wpsc_variation_forms-->
144
+ </fieldset>
145
+ <?php } ?>
146
+ <?php /** the variation group HTML and loop ends here */?>
147
+
148
+ <!-- THIS IS THE QUANTITY OPTION MUST BE ENABLED FROM ADMIN SETTINGS -->
149
+ <?php if(wpsc_has_multi_adding()): ?>
150
+ <fieldset><legend><?php _e('Quantity', 'wpsc'); ?></legend>
151
+ <div class="wpsc_quantity_update">
152
+ <?php /*<label for="wpsc_quantity_update_<?php echo wpsc_the_product_id(); ?>"><?php _e('Quantity', 'wpsc'); ?>:</label>*/ ?>
153
+ <input type="text" id="wpsc_quantity_update_<?php echo wpsc_the_product_id(); ?>" name="wpsc_quantity_update" size="2" value="1" />
154
+ <input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
155
+ <input type="hidden" name="wpsc_update_quantity" value="true" />
156
+ </div><!--close wpsc_quantity_update-->
157
+ </fieldset>
158
+ <?php endif ;?>
159
+
160
+ <div class="wpsc_product_price">
161
+ <?php if( wpsc_show_stock_availability() ): ?>
162
+ <?php if(wpsc_product_has_stock()) : ?>
163
+ <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="in_stock"><?php _e('Product in stock', 'wpsc'); ?></div>
164
+ <?php else: ?>
165
+ <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="out_of_stock"><?php _e('Product not in stock', 'wpsc'); ?></div>
166
+ <?php endif; ?>
167
+ <?php endif; ?>
168
+ <?php if(wpsc_product_is_donation()) : ?>
169
+ <label for="donation_price_<?php echo wpsc_the_product_id(); ?>"><?php _e('Donation', 'wpsc'); ?>: </label>
170
+ <input type="text" id="donation_price_<?php echo wpsc_the_product_id(); ?>" name="donation_price" value="<?php echo wpsc_calculate_price(wpsc_the_product_id()); ?>" size="6" />
171
+
172
+ <?php else : ?>
173
+ <?php wpsc_the_product_price_display(); ?>
174
+
175
+ <!-- multi currency code -->
176
+ <?php if(wpsc_product_has_multicurrency()) : ?>
177
+ <?php echo wpsc_display_product_multicurrency(); ?>
178
+ <?php endif; ?>
179
+
180
+ <?php if(wpsc_show_pnp()) : ?>
181
+ <p class="pricedisplay"><?php _e('Shipping', 'wpsc'); ?>:<span class="pp_price"><?php echo wpsc_product_postage_and_packaging(); ?></span></p>
182
+ <?php endif; ?>
183
+ <?php endif; ?>
184
+ </div><!--close wpsc_product_price-->
185
+
186
+ <input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/>
187
+ <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/>
188
+
189
+ <!-- END OF QUANTITY OPTION -->
190
+ <?php if((get_option('hide_addtocart_button') == 0) && (get_option('addtocart_or_buynow') !='1')) : ?>
191
+ <?php if(wpsc_product_has_stock()) : ?>
192
+ <div class="wpsc_buy_button_container">
193
+ <div class="wpsc_loading_animation">
194
+ <img title="" alt="<?php esc_attr_e( 'Loading', 'wpsc' ); ?>" src="<?php echo wpsc_loading_animation_url(); ?>" />
195
+ <?php _e('Updating cart...', 'wpsc'); ?>
196
+ </div><!--close wpsc_loading_animation-->
197
+ <?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
198
+ <?php $action = wpsc_product_external_link( wpsc_the_product_id() ); ?>
199
+ <input class="wpsc_buy_button" type="submit" value="<?php echo wpsc_product_external_link_text( wpsc_the_product_id(), __( 'Buy Now', 'wpsc' ) ); ?>" onclick="return gotoexternallink('<?php echo esc_url( $action ); ?>', '<?php echo wpsc_product_external_link_target( wpsc_the_product_id() ); ?>')">
200
+ <?php else: ?>
201
+ <input type="submit" value="<?php _e('Add To Cart', 'wpsc'); ?>" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button"/>
202
+ <?php endif; ?>
203
+ </div><!--close wpsc_buy_button_container-->
204
+ <?php endif ; ?>
205
+ <?php endif ; ?>
206
+ <div class="entry-utility wpsc_product_utility">
207
+ <?php edit_post_link( __( 'Edit', 'wpsc' ), '<span class="edit-link">', '</span>' ); ?>
208
+ </div>
209
+ <?php do_action ( 'wpsc_product_form_fields_end' ); ?>
210
+ </form><!--close product_form-->
211
+
212
+ <?php if((get_option('hide_addtocart_button') == 0) && (get_option('addtocart_or_buynow')=='1')) : ?>
213
+ <?php echo wpsc_buy_now_button(wpsc_the_product_id()); ?>
214
+ <?php endif ; ?>
215
+
216
+ <?php echo wpsc_product_rater(); ?>
217
+
218
+
219
+ <?php // */ ?>
220
+ </div><!--close productcol-->
221
+ <?php if(wpsc_product_on_special()) : ?><span class="sale"><?php _e('Sale', 'wpsc'); ?></span><?php endif; ?>
222
+ </div><!--close default_product_display-->
223
+
224
+ <?php endwhile; ?>
225
+ <?php /** end the product loop here */?>
226
+ </div>
227
+ <?php if(wpsc_product_count() == 0):?>
228
+ <h3><?php _e('There are no products in this group.', 'wpsc'); ?></h3>
229
+ <?php endif ; ?>
230
+ <?php do_action( 'wpsc_theme_footer' ); ?>
231
+
232
+ <?php if(wpsc_has_pages_bottom()) : ?>
233
+ <div class="wpsc_page_numbers_bottom">
234
+ <?php wpsc_pagination(); ?>
235
+ </div><!--close wpsc_page_numbers_bottom-->
236
+ <?php endif; ?>
237
+ <?php endif; ?>
238
+ </div><!--close default_products_page_container-->
wpsc-components/theme-engine-v1/templates/wpsc-shopping_cart_page.php ADDED
@@ -0,0 +1,488 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ global $wpsc_cart, $wpdb, $wpsc_checkout, $wpsc_gateway, $wpsc_coupons, $wpsc_registration_error_messages;
3
+ $wpsc_checkout = new wpsc_checkout();
4
+ $alt = 0;
5
+ $coupon_num = wpsc_get_customer_meta( 'coupon' );
6
+ if( $coupon_num )
7
+ $wpsc_coupons = new wpsc_coupons( $coupon_num );
8
+
9
+ if(wpsc_cart_item_count() < 1) :
10
+ _e('Oops, there is nothing in your cart.', 'wpsc') . "<a href=" . esc_url( get_option( "product_list_url" ) ) . ">" . __('Please visit our shop', 'wpsc') . "</a>";
11
+ return;
12
+ endif;
13
+ ?>
14
+ <div id="checkout_page_container">
15
+ <h3><?php _e('Please review your order', 'wpsc'); ?></h3>
16
+ <table class="checkout_cart">
17
+ <tr class="header">
18
+ <th colspan="2" ><?php _e('Product', 'wpsc'); ?></th>
19
+ <th><?php _e('Quantity', 'wpsc'); ?></th>
20
+ <th><?php _e('Price', 'wpsc'); ?></th>
21
+ <th><?php _e('Total', 'wpsc'); ?></th>
22
+ <th>&nbsp;</th>
23
+ </tr>
24
+ <?php while (wpsc_have_cart_items()) : wpsc_the_cart_item(); ?>
25
+ <?php
26
+ $alt++;
27
+ if ($alt %2 == 1)
28
+ $alt_class = 'alt';
29
+ else
30
+ $alt_class = '';
31
+ ?>
32
+ <?php //this displays the confirm your order html ?>
33
+
34
+ <?php do_action ( "wpsc_before_checkout_cart_row" ); ?>
35
+ <tr class="product_row product_row_<?php echo wpsc_the_cart_item_key(); ?> <?php echo $alt_class;?>">
36
+
37
+ <td class="firstcol wpsc_product_image wpsc_product_image_<?php echo wpsc_the_cart_item_key(); ?>">
38
+ <?php if('' != wpsc_cart_item_image()): ?>
39
+ <?php do_action ( "wpsc_before_checkout_cart_item_image" ); ?>
40
+ <img src="<?php echo wpsc_cart_item_image(); ?>" alt="<?php echo wpsc_cart_item_name(); ?>" title="<?php echo wpsc_cart_item_name(); ?>" class="product_image" />
41
+ <?php do_action ( "wpsc_after_checkout_cart_item_image" ); ?>
42
+ <?php else:
43
+ /* I dont think this gets used anymore,, but left in for backwards compatibility */
44
+ ?>
45
+ <div class="item_no_image">
46
+ <?php do_action ( "wpsc_before_checkout_cart_item_image" ); ?>
47
+ <a href="<?php echo esc_url( wpsc_the_product_permalink() ); ?>">
48
+ <span><?php _e('No Image','wpsc'); ?></span>
49
+
50
+ </a>
51
+ <?php do_action ( "wpsc_after_checkout_cart_item_image" ); ?>
52
+ </div>
53
+ <?php endif; ?>
54
+ </td>
55
+
56
+ <td class="wpsc_product_name wpsc_product_name_<?php echo wpsc_the_cart_item_key(); ?>">
57
+ <?php do_action ( "wpsc_before_checkout_cart_item_name" ); ?>
58
+ <a href="<?php echo esc_url( wpsc_cart_item_url() );?>"><?php echo wpsc_cart_item_name(); ?></a>
59
+ <?php do_action ( "wpsc_after_checkout_cart_item_name" ); ?>
60
+ </td>
61
+
62
+ <td class="wpsc_product_quantity wpsc_product_quantity_<?php echo wpsc_the_cart_item_key(); ?>">
63
+ <form action="<?php echo esc_url( get_option( 'shopping_cart_url' ) ); ?>" method="post" class="adjustform qty">
64
+ <input type="text" name="quantity" size="2" value="<?php echo wpsc_cart_item_quantity(); ?>" />
65
+ <input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>" />
66
+ <input type="hidden" name="wpsc_update_quantity" value="true" />
67
+ <input type="submit" value="<?php _e('Update', 'wpsc'); ?>" />
68
+ </form>
69
+ </td>
70
+
71
+
72
+ <td><?php echo wpsc_cart_single_item_price(); ?></td>
73
+ <td class="wpsc_product_price wpsc_product_price_<?php echo wpsc_the_cart_item_key(); ?>"><span class="pricedisplay"><?php echo wpsc_cart_item_price(); ?></span></td>
74
+
75
+ <td class="wpsc_product_remove wpsc_product_remove_<?php echo wpsc_the_cart_item_key(); ?>">
76
+ <form action="<?php echo esc_url( get_option( 'shopping_cart_url' ) ); ?>" method="post" class="adjustform remove">
77
+ <input type="hidden" name="quantity" value="0" />
78
+ <input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>" />
79
+ <input type="hidden" name="wpsc_update_quantity" value="true" />
80
+ <input type="submit" value="<?php _e('Remove', 'wpsc'); ?>" />
81
+ </form>
82
+ </td>
83
+ </tr>
84
+ <?php do_action ( "wpsc_after_checkout_cart_row" ); ?>
85
+ <?php endwhile; ?>
86
+ <?php //this HTML displays coupons if there are any active coupons to use ?>
87
+
88
+ <?php do_action ( 'wpsc_after_checkout_cart_rows' ); ?>
89
+
90
+ <?php
91
+
92
+ if(wpsc_uses_coupons()): ?>
93
+
94
+ <tr class="wpsc_total_before_shipping">
95
+ <td colspan="3"><?php _e('Cost before shipping:','wpsc'); ?></td>
96
+ <td colspan="3" class="wpsc_total_amount_before_shipping"><?php echo wpsc_cart_total_widget(false,false,false);?></td>
97
+ </tr>
98
+ <?php if(wpsc_coupons_error()): ?>
99
+ <tr class="wpsc_coupon_row wpsc_coupon_error_row"><td colspan="6"><?php _e('Coupon is not valid.', 'wpsc'); ?></td></tr>
100
+ <?php endif; ?>
101
+ <tr class="wpsc_coupon_row">
102
+ <td colspan="2"><?php _e('Enter coupon code :', 'wpsc'); ?></td>
103
+ <td colspan="4" class="coupon_code">
104
+ <form method="post" action="<?php echo esc_url( get_option( 'shopping_cart_url' ) ); ?>">
105
+ <input type="text" name="coupon_num" id="coupon_num" value="<?php echo $wpsc_cart->coupons_name; ?>" />
106
+ <input type="submit" value="<?php _e('Update', 'wpsc') ?>" />
107
+ </form>
108
+ </td>
109
+ </tr>
110
+ <?php endif; ?>
111
+ </table>
112
+ <!-- cart contents table close -->
113
+ <?php if(wpsc_uses_shipping()): ?>
114
+ <p class="wpsc_cost_before"></p>
115
+ <?php endif; ?>
116
+ <?php //this HTML dispalys the calculate your order HTML ?>
117
+
118
+ <?php if(wpsc_has_category_and_country_conflict()): ?>
119
+ <p class='validation-error'><?php echo esc_html( wpsc_get_customer_meta( 'category_shipping_conflict' ) ); ?></p>
120
+ <?php endif; ?>
121
+
122
+ <?php if(isset($_SESSION['WpscGatewayErrorMessage']) && $_SESSION['WpscGatewayErrorMessage'] != '') :?>
123
+ <p class="validation-error"><?php echo $_SESSION['WpscGatewayErrorMessage']; ?></p>
124
+ <?php
125
+ endif;
126
+ ?>
127
+
128
+ <?php do_action('wpsc_before_shipping_of_shopping_cart'); ?>
129
+
130
+ <div id="wpsc_shopping_cart_container">
131
+ <?php if(wpsc_uses_shipping()) : ?>
132
+ <h2><?php _e('Calculate Shipping Price', 'wpsc'); ?></h2>
133
+ <table class="productcart">
134
+ <tr class="wpsc_shipping_info">
135
+ <td colspan="5">
136
+ <?php _e('Please specify shipping location below to calculate your shipping costs', 'wpsc'); ?>
137
+ </td>
138
+ </tr>
139
+
140
+ <?php if ( ! wpsc_have_shipping_quote() ) : // No valid shipping quotes ?>
141
+ <?php if ( ! wpsc_have_valid_shipping_zipcode() ) : ?>
142
+ <tr class='wpsc_update_location'>
143
+ <td colspan='5' class='shipping_error' >
144
+ <?php _e('Please provide a Zipcode and click Calculate in order to continue.', 'wpsc'); ?>
145
+ </td>
146
+ </tr>
147
+ <?php else: ?>
148
+ <tr class='wpsc_update_location_error'>
149
+ <td colspan='5' class='shipping_error' >
150
+ <?php _e('Sorry, online ordering is unavailable to this destination and/or weight. Please double check your destination details.', 'wpsc'); ?>
151
+ </td>
152
+ </tr>
153
+ <?php endif; ?>
154
+ <?php endif; ?>
155
+ <tr class='wpsc_change_country'>
156
+ <td colspan='5'>
157
+ <form name='change_country' id='change_country' action='' method='post'>
158
+ <?php echo wpsc_shipping_country_list();?>
159
+ <input type='hidden' name='wpsc_update_location' value='true' />
160
+ <input type='submit' name='wpsc_submit_zipcode' value='<?php esc_attr_e( 'Calculate', 'wpsc' ); ?>' />
161
+ </form>
162
+ </td>
163
+ </tr>
164
+
165
+ <?php if (wpsc_have_morethanone_shipping_quote()) :?>
166
+ <?php while (wpsc_have_shipping_methods()) : wpsc_the_shipping_method(); ?>
167
+ <?php if (!wpsc_have_shipping_quotes()) { continue; } // Don't display shipping method if it doesn't have at least one quote ?>
168
+ <tr class='wpsc_shipping_header'><td class='shipping_header' colspan='5'><?php echo wpsc_shipping_method_name().__(' - Choose a Shipping Rate', 'wpsc'); ?> </td></tr>
169
+ <?php while (wpsc_have_shipping_quotes()) : wpsc_the_shipping_quote(); ?>
170
+ <tr class='<?php echo wpsc_shipping_quote_html_id(); ?>'>
171
+ <td class='wpsc_shipping_quote_name wpsc_shipping_quote_name_<?php echo wpsc_shipping_quote_html_id(); ?>' colspan='3'>
172
+ <label for='<?php echo wpsc_shipping_quote_html_id(); ?>'><?php echo wpsc_shipping_quote_name(); ?></label>
173
+ </td>
174
+ <td class='wpsc_shipping_quote_price wpsc_shipping_quote_price_<?php echo wpsc_shipping_quote_html_id(); ?>' style='text-align:center;'>
175
+ <label for='<?php echo wpsc_shipping_quote_html_id(); ?>'><?php echo wpsc_shipping_quote_value(); ?></label>
176
+ </td>
177
+ <td class='wpsc_shipping_quote_radio wpsc_shipping_quote_radio_<?php echo wpsc_shipping_quote_html_id(); ?>' style='text-align:center;'>
178
+ <?php if(wpsc_have_morethanone_shipping_methods_and_quotes()): ?>
179
+ <input type='radio' id='<?php echo wpsc_shipping_quote_html_id(); ?>' <?php echo wpsc_shipping_quote_selected_state(); ?> onclick='switchmethod("<?php echo wpsc_shipping_quote_name(); ?>", "<?php echo wpsc_shipping_method_internal_name(); ?>")' value='<?php echo wpsc_shipping_quote_value(true); ?>' name='shipping_method' />
180
+ <?php else: ?>
181
+ <input <?php echo wpsc_shipping_quote_selected_state(); ?> disabled='disabled' type='radio' id='<?php echo wpsc_shipping_quote_html_id(); ?>' value='<?php echo wpsc_shipping_quote_value(true); ?>' name='shipping_method' />
182
+ <?php wpsc_update_shipping_single_method(); ?>
183
+ <?php endif; ?>
184
+ </td>
185
+ </tr>
186
+ <?php endwhile; ?>
187
+ <?php endwhile; ?>
188
+ <?php endif; ?>
189
+
190
+ <?php wpsc_update_shipping_multiple_methods(); ?>
191
+
192
+
193
+ <?php if (!wpsc_have_shipping_quote()) : // No valid shipping quotes ?>
194
+ </table>
195
+ </div>
196
+ </div>
197
+ <?php return; ?>
198
+ <?php endif; ?>
199
+ </table>
200
+ <?php endif; ?>
201
+
202
+ <?php
203
+ $wpec_taxes_controller = new wpec_taxes_controller();
204
+ if($wpec_taxes_controller->wpec_taxes_isenabled()):
205
+ ?>
206
+ <table class="productcart">
207
+ <tr class="total_price total_tax">
208
+ <td colspan="3">
209
+ <?php echo wpsc_display_tax_label(true); ?>
210
+ </td>
211
+ <td colspan="2">
212
+ <span id="checkout_tax" class="pricedisplay checkout-tax"><?php echo wpsc_cart_tax(); ?></span>
213
+ </td>
214
+ </tr>
215
+ </table>
216
+ <?php endif; ?>
217
+ <?php do_action('wpsc_before_form_of_shopping_cart'); ?>
218
+
219
+ <?php if( ! empty( $wpsc_registration_error_messages ) ): ?>
220
+ <p class="validation-error">
221
+ <?php
222
+ foreach( $wpsc_registration_error_messages as $user_error )
223
+ echo $user_error."<br />\n";
224
+ ?>
225
+ <?php endif; ?>
226
+
227
+ <?php if ( wpsc_show_user_login_form() && !is_user_logged_in() ): ?>
228
+ <p><?php _e('You must sign in or register with us to continue with your purchase', 'wpsc');?></p>
229
+ <div class="wpsc_registration_form">
230
+
231
+ <fieldset class='wpsc_registration_form'>
232
+ <h2><?php _e( 'Sign in', 'wpsc' ); ?></h2>
233
+ <?php
234
+ $args = array(
235
+ 'remember' => false,
236
+ 'redirect' => home_url( $_SERVER['REQUEST_URI'] )
237
+ );
238
+ wp_login_form( $args );
239
+ ?>
240
+ <div class="wpsc_signup_text"><?php _e('If you have bought from us before please sign in here to purchase', 'wpsc');?></div>
241
+ </fieldset>
242
+ </div>
243
+ <?php endif; ?>
244
+ <table class='wpsc_checkout_table wpsc_checkout_table_totals'>
245
+ <?php if(wpsc_uses_shipping()) : ?>
246
+ <tr class="total_price total_shipping">
247
+ <td class='wpsc_totals'>
248
+ <?php _e('Total Shipping:', 'wpsc'); ?>
249
+ </td>
250
+ <td class='wpsc_totals'>
251
+ <span id="checkout_shipping" class="pricedisplay checkout-shipping"><?php echo wpsc_cart_shipping(); ?></span>
252
+ </td>
253
+ </tr>
254
+ <?php endif; ?>
255
+
256
+ <?php if(wpsc_uses_coupons() && (wpsc_coupon_amount(false) > 0)): ?>
257
+ <tr class="total_price">
258
+ <td class='wpsc_totals'>
259
+ <?php _e('Discount:', 'wpsc'); ?>
260
+ </td>
261
+ <td class='wpsc_totals'>
262
+ <span id="coupons_amount" class="pricedisplay"><?php echo wpsc_coupon_amount(); ?></span>
263
+ </td>
264
+ </tr>
265
+ <?php endif ?>
266
+
267
+
268
+
269
+ <tr class='total_price'>
270
+ <td class='wpsc_totals'>
271
+ <?php _e('Total Price:', 'wpsc'); ?>
272
+ </td>
273
+ <td class='wpsc_totals'>
274
+ <span id='checkout_total' class="pricedisplay checkout-total"><?php echo wpsc_cart_total(); ?></span>
275
+ </td>
276
+ </tr>
277
+ </table>
278
+
279
+ <form class='wpsc_checkout_forms' action='<?php echo esc_url( get_option( 'shopping_cart_url' ) ); ?>' method='post' enctype="multipart/form-data">
280
+ <?php
281
+ /**
282
+ * Both the registration forms and the checkout details forms must be in the same form element as they are submitted together, you cannot have two form elements submit together without the use of JavaScript.
283
+ */
284
+ ?>
285
+
286
+ <?php if(wpsc_show_user_login_form()):
287
+ global $current_user;
288
+ get_currentuserinfo(); ?>
289
+
290
+ <div class="wpsc_registration_form">
291
+
292
+ <fieldset class='wpsc_registration_form wpsc_right_registration'>
293
+ <h2><?php _e('Join up now', 'wpsc');?></h2>
294
+
295
+ <label><?php _e('Username:', 'wpsc'); ?></label>
296
+ <input type="text" name="log" id="log" value="" size="20"/><br/>
297
+
298
+ <label><?php _e('Password:', 'wpsc'); ?></label>
299
+ <input type="password" name="pwd" id="pwd" value="" size="20" /><br />
300
+
301
+ <label><?php _e('E-mail', 'wpsc'); ?>:</label>
302
+ <input type="text" name="user_email" id="user_email" value="" size="20" /><br />
303
+ <div class="wpsc_signup_text"><?php _e('Signing up is free and easy! please fill out your details your registration will happen automatically as you checkout. Don\'t forget to use your details to login with next time!', 'wpsc');?></div>
304
+ </fieldset>
305
+
306
+ </div>
307
+ <div class="clear"></div>
308
+ <?php endif; // closes user login form
309
+ $misc_error_messages = wpsc_get_customer_meta( 'checkout_misc_error_messages' );
310
+ if( ! empty( $misc_error_messages ) ): ?>
311
+ <div class='login_error'>
312
+ <?php foreach( $misc_error_messages as $user_error ){?>
313
+ <p class='validation-error'><?php echo $user_error; ?></p>
314
+ <?php } ?>
315
+ </div>
316
+
317
+ <?php
318
+ endif;
319
+ ?>
320
+ <?php ob_start(); ?>
321
+ <table class='wpsc_checkout_table table-1'>
322
+ <?php $i = 0;
323
+ while (wpsc_have_checkout_items()) : wpsc_the_checkout_item(); ?>
324
+
325
+ <?php if(wpsc_checkout_form_is_header() == true){
326
+ $i++;
327
+ //display headers for form fields ?>
328
+ <?php if($i > 1):?>
329
+ </table>
330
+ <table class='wpsc_checkout_table table-<?php echo $i; ?>'>
331
+ <?php endif; ?>
332
+
333
+ <tr <?php echo wpsc_the_checkout_item_error_class();?>>
334
+ <td <?php wpsc_the_checkout_details_class(); ?> colspan='2'>
335
+ <h4><?php echo wpsc_checkout_form_name();?></h4>
336
+ </td>
337
+ </tr>
338
+ <?php if(wpsc_is_shipping_details()):?>
339
+ <tr class='same_as_shipping_row'>
340
+ <td colspan ='2'>
341
+ <?php $checked = '';
342
+ $shipping_same_as_billing = wpsc_get_customer_meta( 'shipping_same_as_billing' );
343
+ if(isset($_POST['shippingSameBilling']) && $_POST['shippingSameBilling'])
344
+ $shipping_same_as_billing = true;
345
+ elseif(isset($_POST['submit']) && !isset($_POST['shippingSameBilling']))
346
+ $shipping_same_as_billing = false;
347
+ wpsc_update_customer_meta( 'shipping_same_as_billing', $shipping_same_as_billing );
348
+ if( $shipping_same_as_billing )
349
+ $checked = 'checked="checked"';
350
+ ?>
351
+ <label for='shippingSameBilling'><?php _e('Same as billing address:','wpsc'); ?></label>
352
+ <input type='checkbox' value='true' name='shippingSameBilling' id='shippingSameBilling' <?php echo $checked; ?> />
353
+ <br/><span id="shippingsameasbillingmessage"><?php _e('Your order will be shipped to the billing address', 'wpsc'); ?></span>
354
+ </td>
355
+ </tr>
356
+ <?php endif;
357
+
358
+ // Not a header so start display form fields
359
+ }elseif(wpsc_disregard_shipping_state_fields()){
360
+ ?>
361
+ <tr class='wpsc_hidden'>
362
+ <td class='<?php echo wpsc_checkout_form_element_id(); ?>'>
363
+ <label for='<?php echo wpsc_checkout_form_element_id(); ?>'>
364
+ <?php echo wpsc_checkout_form_name();?>
365
+ </label>
366
+ </td>
367
+ <td>
368
+ <?php echo wpsc_checkout_form_field();?>
369
+ <?php if(wpsc_the_checkout_item_error() != ''): ?>
370
+ <p class='validation-error'><?php echo wpsc_the_checkout_item_error(); ?></p>
371
+ <?php endif; ?>
372
+ </td>
373
+ </tr>
374
+ <?php
375
+ }elseif(wpsc_disregard_billing_state_fields()){
376
+ ?>
377
+ <tr class='wpsc_hidden'>
378
+ <td class='<?php echo wpsc_checkout_form_element_id(); ?>'>
379
+ <label for='<?php echo wpsc_checkout_form_element_id(); ?>'>
380
+ <?php echo wpsc_checkout_form_name();?>
381
+ </label>
382
+ </td>
383
+ <td>
384
+ <?php echo wpsc_checkout_form_field();?>
385
+ <?php if(wpsc_the_checkout_item_error() != ''): ?>
386
+ <p class='validation-error'><?php echo wpsc_the_checkout_item_error(); ?></p>
387
+ <?php endif; ?>
388
+ </td>
389
+ </tr>
390
+ <?php
391
+ }elseif( $wpsc_checkout->checkout_item->unique_name == 'billingemail'){ ?>
392
+ <?php $email_markup =
393
+ "<div class='wpsc_email_address'>
394
+ <p class='" . wpsc_checkout_form_element_id() . "'>
395
+ <label class='wpsc_email_address' for='" . wpsc_checkout_form_element_id() . "'>
396
+ " . __('Enter your email address', 'wpsc') . "
397
+ </label>
398
+ <p class='wpsc_email_address_p'>
399
+ <img src='https://secure.gravatar.com/avatar/empty?s=60&amp;d=mm' id='wpsc_checkout_gravatar' />
400
+ " . wpsc_checkout_form_field();
401
+
402
+ if(wpsc_the_checkout_item_error() != '')
403
+ $email_markup .= "<p class='validation-error'>" . wpsc_the_checkout_item_error() . "</p>";
404
+ $email_markup .= "</div>";
405
+ }else{ ?>
406
+ <tr>
407
+ <td class='<?php echo wpsc_checkout_form_element_id(); ?>'>
408
+ <label for='<?php echo wpsc_checkout_form_element_id(); ?>'>
409
+ <?php echo wpsc_checkout_form_name();?>
410
+ </label>
411
+ </td>
412
+ <td>
413
+ <?php echo wpsc_checkout_form_field();?>
414
+ <?php if(wpsc_the_checkout_item_error() != ''): ?>
415
+ <p class='validation-error'><?php echo wpsc_the_checkout_item_error(); ?></p>
416
+ <?php endif; ?>
417
+ </td>
418
+ </tr>
419
+
420
+ <?php }//endif; ?>
421
+
422
+ <?php endwhile; ?>
423
+
424
+ <?php
425
+ $buffer_contents = ob_get_contents();
426
+ ob_end_clean();
427
+ if(isset($email_markup))
428
+ echo $email_markup;
429
+ echo $buffer_contents;
430
+ ?>
431
+
432
+ <?php if (wpsc_show_find_us()) : ?>
433
+ <tr>
434
+ <td><label for='how_find_us'><?php _e('How did you find us' , 'wpsc'); ?></label></td>
435
+ <td>
436
+ <select name='how_find_us'>
437
+ <option value='Word of Mouth'><?php _e('Word of mouth' , 'wpsc'); ?></option>
438
+ <option value='Advertisement'><?php _e('Advertising' , 'wpsc'); ?></option>
439
+ <option value='Internet'><?php _e('Internet' , 'wpsc'); ?></option>
440
+ <option value='Customer'><?php _e('Existing Customer' , 'wpsc'); ?></option>
441
+ </select>
442
+ </td>
443
+ </tr>
444
+ <?php endif; ?>
445
+ <?php do_action('wpsc_inside_shopping_cart'); ?>
446
+
447
+ <?php //this HTML displays activated payment gateways ?>
448
+ <?php if(wpsc_gateway_count() > 1): // if we have more than one gateway enabled, offer the user a choice ?>
449
+ <tr>
450
+ <td colspan='2' class='wpsc_gateway_container'>
451
+ <h3><?php _e('Payment Type', 'wpsc');?></h3>
452
+ <?php wpsc_gateway_list(); ?>
453
+ </td>
454
+ </tr>
455
+ <?php else: // otherwise, there is no choice, stick in a hidden form ?>
456
+ <tr>
457
+ <td colspan="2" class='wpsc_gateway_container'>
458
+ <?php wpsc_gateway_hidden_field(); ?>
459
+ </td>
460
+ </tr>
461
+ <?php endif; ?>
462
+
463
+ <?php if(wpsc_has_tnc()) : ?>
464
+ <tr>
465
+ <td colspan='2'>
466
+ <label for="agree"><input id="agree" type='checkbox' value='yes' name='agree' /> <?php printf(__("I agree to the <a class='thickbox' target='_blank' href='%s' class='termsandconds'>Terms and Conditions</a>", "wpsc"), esc_url( home_url( "?termsandconds=true&amp;width=360&amp;height=400" ) ) ); ?> <span class="asterix">*</span></label>
467
+ </td>
468
+ </tr>
469
+ <?php endif; ?>
470
+ </table>
471
+
472
+ <!-- div for make purchase button -->
473
+ <div class='wpsc_make_purchase'>
474
+ <span>
475
+ <?php if(!wpsc_has_tnc()) : ?>
476
+ <input type='hidden' value='yes' name='agree' />
477
+ <?php endif; ?>
478
+ <input type='hidden' value='submit_checkout' name='wpsc_action' />
479
+ <input type='submit' value='<?php _e('Purchase', 'wpsc');?>' class='make_purchase wpsc_buy_button' />
480
+ </span>
481
+ </div>
482
+
483
+ <div class='clear'></div>
484
+ </form>
485
+ </div>
486
+ </div><!--close checkout_page_container-->
487
+ <?php
488
+ do_action('wpsc_bottom_of_shopping_cart');
wpsc-components/theme-engine-v1/templates/wpsc-single_product.php ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Setup globals
3
+ // @todo: Get these out of template
4
+ global $wp_query;
5
+
6
+ // Setup image width and height variables
7
+ // @todo: Investigate if these are still needed here
8
+ $image_width = get_option( 'single_view_image_width' );
9
+ $image_height = get_option( 'single_view_image_height' );
10
+ ?>
11
+
12
+ <div id="single_product_page_container">
13
+
14
+ <?php
15
+ // Breadcrumbs
16
+ wpsc_output_breadcrumbs();
17
+
18
+ // Plugin hook for adding things to the top of the products page, like the live search
19
+ do_action( 'wpsc_top_of_products_page' );
20
+ ?>
21
+
22
+ <div class="single_product_display group">
23
+ <?php
24
+ /**
25
+ * Start the product loop here.
26
+ * This is single products view, so there should be only one
27
+ */
28
+
29
+ while ( wpsc_have_products() ) : wpsc_the_product(); ?>
30
+ <div class="imagecol">
31
+ <?php if ( wpsc_the_product_thumbnail() ) : ?>
32
+ <a rel="<?php echo wpsc_the_product_title(); ?>" class="<?php echo wpsc_the_product_image_link_classes(); ?>" href="<?php echo esc_url( wpsc_the_product_image() ); ?>">
33
+ <img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>"/>
34
+ </a>
35
+ <?php
36
+ if ( function_exists( 'gold_shpcrt_display_gallery' ) )
37
+ echo gold_shpcrt_display_gallery( wpsc_the_product_id() );
38
+ ?>
39
+ <?php else: ?>
40
+ <a href="<?php echo esc_url( wpsc_the_product_permalink() ); ?>">
41
+ <img class="no-image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="No Image" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/noimage.png" width="<?php echo get_option('product_image_width'); ?>" height="<?php echo get_option('product_image_height'); ?>" />
42
+ </a>
43
+ <?php endif; ?>
44
+ </div><!--close imagecol-->
45
+
46
+ <div class="productcol">
47
+ <?php do_action('wpsc_product_before_description', wpsc_the_product_id(), $wp_query->post); ?>
48
+ <div class="product_description">
49
+ <?php echo wpsc_the_product_description(); ?>
50
+ </div><!--close product_description -->
51
+ <?php do_action( 'wpsc_product_addons', wpsc_the_product_id() ); ?>
52
+ <?php if ( wpsc_the_product_additional_description() ) : ?>
53
+ <div class="single_additional_description">
54
+ <p><?php echo wpsc_the_product_additional_description(); ?></p>
55
+ </div><!--close single_additional_description-->
56
+ <?php endif; ?>
57
+ <?php do_action( 'wpsc_product_addon_after_descr', wpsc_the_product_id() ); ?>
58
+ <?php
59
+ /**
60
+ * Custom meta HTML and loop
61
+ */
62
+ ?>
63
+ <?php if (wpsc_have_custom_meta()) : ?>
64
+ <div class="custom_meta">
65
+ <?php while ( wpsc_have_custom_meta() ) : wpsc_the_custom_meta(); ?>
66
+ <?php if (stripos(wpsc_custom_meta_name(),'g:') !== FALSE) continue; ?>
67
+ <strong><?php echo wpsc_custom_meta_name(); ?>: </strong><?php echo wpsc_custom_meta_value(); ?><br />
68
+ <?php endwhile; ?>
69
+ </div><!--close custom_meta-->
70
+ <?php endif; ?>
71
+ <?php
72
+ /**
73
+ * Form data
74
+ */
75
+ ?>
76
+ <form class="product_form" enctype="multipart/form-data" action="<?php echo esc_url( wpsc_this_page_url() ); ?>" method="post" name="1" id="product_<?php echo wpsc_the_product_id(); ?>">
77
+ <?php do_action ( 'wpsc_product_form_fields_begin' ); ?>
78
+ <?php if ( wpsc_product_has_personal_text() ) : ?>
79
+ <fieldset class="custom_text">
80
+ <legend><?php _e( 'Personalize Your Product', 'wpsc' ); ?></legend>
81
+ <p><?php _e( 'Complete this form to include a personalized message with your purchase.', 'wpsc' ); ?></p>
82
+ <textarea cols='55' rows='5' name="custom_text"></textarea>
83
+ </fieldset>
84
+ <?php endif; ?>
85
+
86
+ <?php if ( wpsc_product_has_supplied_file() ) : ?>
87
+
88
+ <fieldset class="custom_file">
89
+ <legend><?php _e( 'Upload a File', 'wpsc' ); ?></legend>
90
+ <p><?php _e( 'Select a file from your computer to include with this purchase.', 'wpsc' ); ?></p>
91
+ <input type="file" name="custom_file" />
92
+ </fieldset>
93
+ <?php endif; ?>
94
+ <?php /** the variation group HTML and loop */?>
95
+ <?php if (wpsc_have_variation_groups()) { ?>
96
+ <fieldset><legend><?php _e('Product Options', 'wpsc'); ?></legend>
97
+ <div class="wpsc_variation_forms">
98
+ <table>
99
+ <?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
100
+ <tr><td class="col1"><label for="<?php echo wpsc_vargrp_form_id(); ?>"><?php echo wpsc_the_vargrp_name(); ?>:</label></td>
101
+ <?php /** the variation HTML and loop */?>
102
+ <td class="col2"><select class="wpsc_select_variation" name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>">
103
+ <?php while (wpsc_have_variations()) : wpsc_the_variation(); ?>
104
+ <option value="<?php echo wpsc_the_variation_id(); ?>" <?php echo wpsc_the_variation_out_of_stock(); ?>><?php echo wpsc_the_variation_name(); ?></option>
105
+ <?php endwhile; ?>
106
+ </select></td></tr>
107
+ <?php endwhile; ?>
108
+ </table>
109
+ <div id="variation_display_<?php echo wpsc_the_product_id(); ?>" class="is_variation"><?php _e('Combination of product variants is not available', 'wpsc'); ?></div>
110
+ </div><!--close wpsc_variation_forms-->
111
+ </fieldset>
112
+ <?php } ?>
113
+ <?php /** the variation group HTML and loop ends here */?>
114
+
115
+ <?php
116
+ /**
117
+ * Quantity options - MUST be enabled in Admin Settings
118
+ */
119
+ ?>
120
+ <?php if(wpsc_has_multi_adding()): ?>
121
+ <fieldset><legend><?php _e('Quantity', 'wpsc'); ?></legend>
122
+ <div class="wpsc_quantity_update">
123
+ <input type="text" id="wpsc_quantity_update_<?php echo wpsc_the_product_id(); ?>" name="wpsc_quantity_update" size="2" value="1" />
124
+ <input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
125
+ <input type="hidden" name="wpsc_update_quantity" value="true" />
126
+ </div><!--close wpsc_quantity_update-->
127
+ </fieldset>
128
+ <?php endif ;?>
129
+ <div class="wpsc_product_price">
130
+ <?php if(wpsc_show_stock_availability()): ?>
131
+ <?php if(wpsc_product_has_stock()) : ?>
132
+ <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="in_stock"><?php _e('Product in stock', 'wpsc'); ?></div>
133
+ <?php else: ?>
134
+ <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="out_of_stock"><?php _e('Product not in stock', 'wpsc'); ?></div>
135
+ <?php endif; ?>
136
+ <?php endif; ?>
137
+ <?php if(wpsc_product_is_donation()) : ?>
138
+ <label for="donation_price_<?php echo wpsc_the_product_id(); ?>"><?php _e('Donation', 'wpsc'); ?>: </label>
139
+ <input type="text" id="donation_price_<?php echo wpsc_the_product_id(); ?>" name="donation_price" value="<?php echo wpsc_calculate_price(wpsc_the_product_id()); ?>" size="6" />
140
+ <?php else : ?>
141
+ <?php wpsc_the_product_price_display(); ?>
142
+ <!-- multi currency code -->
143
+ <?php if(wpsc_product_has_multicurrency()) : ?>
144
+ <?php echo wpsc_display_product_multicurrency(); ?>
145
+ <?php endif; ?>
146
+ <?php if(wpsc_show_pnp()) : ?>
147
+ <p class="pricedisplay"><?php _e('Shipping', 'wpsc'); ?>:<span class="pp_price"><?php echo wpsc_product_postage_and_packaging(); ?></span></p>
148
+ <?php endif; ?>
149
+ <?php endif; ?>
150
+ </div><!--close wpsc_product_price-->
151
+
152
+ <!-- ShareThis -->
153
+ <?php if ( get_option( 'wpsc_share_this' ) == 1 ): ?>
154
+ <div class="st_sharethis" displayText="ShareThis"></div>
155
+ <?php endif; ?>
156
+ <!-- End ShareThis -->
157
+
158
+ <input type="hidden" value="add_to_cart" name="wpsc_ajax_action" />
159
+ <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id" />
160
+ <?php if( wpsc_product_is_customisable() ) : ?>
161
+ <input type="hidden" value="true" name="is_customisable"/>
162
+ <?php endif; ?>
163
+
164
+ <?php
165
+ /**
166
+ * Cart Options
167
+ */
168
+ ?>
169
+
170
+ <?php if((get_option('hide_addtocart_button') == 0) && (get_option('addtocart_or_buynow') !='1')) : ?>
171
+ <?php if(wpsc_product_has_stock()) : ?>
172
+ <div class="wpsc_buy_button_container">
173
+ <?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
174
+ <?php $action = wpsc_product_external_link( wpsc_the_product_id() ); ?>
175
+ <input class="wpsc_buy_button" type="submit" value="<?php echo wpsc_product_external_link_text( wpsc_the_product_id(), __( 'Buy Now', 'wpsc' ) ); ?>" onclick="return gotoexternallink('<?php echo esc_url( $action ); ?>', '<?php echo wpsc_product_external_link_target( wpsc_the_product_id() ); ?>')">
176
+ <?php else: ?>
177
+ <input type="submit" value="<?php _e('Add To Cart', 'wpsc'); ?>" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button"/>
178
+ <?php endif; ?>
179
+ <div class="wpsc_loading_animation">
180
+ <img title="Loading" alt="Loading" src="<?php echo wpsc_loading_animation_url(); ?>" />
181
+ <?php _e('Updating cart...', 'wpsc'); ?>
182
+ </div><!--close wpsc_loading_animation-->
183
+ </div><!--close wpsc_buy_button_container-->
184
+ <?php else : ?>
185
+ <p class="soldout"><?php _e('This product has sold out.', 'wpsc'); ?></p>
186
+ <?php endif ; ?>
187
+ <?php endif ; ?>
188
+ <?php do_action ( 'wpsc_product_form_fields_end' ); ?>
189
+ </form><!--close product_form-->
190
+
191
+ <?php
192
+ if ( (get_option( 'hide_addtocart_button' ) == 0 ) && ( get_option( 'addtocart_or_buynow' ) == '1' ) )
193
+ echo wpsc_buy_now_button( wpsc_the_product_id() );
194
+
195
+ echo wpsc_product_rater();
196
+
197
+ echo wpsc_also_bought( wpsc_the_product_id() );
198
+
199
+ if(wpsc_show_fb_like()): ?>
200
+ <div class="FB_like">
201
+ <iframe src="https://www.facebook.com/plugins/like.php?href=<?php echo wpsc_the_product_permalink(); ?>&amp;layout=standard&amp;show_faces=true&amp;width=435&amp;action=like&amp;font=arial&amp;colorscheme=light" frameborder="0"></iframe>
202
+ </div><!--close FB_like-->
203
+ <?php endif; ?>
204
+ </div><!--close productcol-->
205
+ <form onsubmit="submitform(this);return false;" action="<?php echo esc_url( wpsc_this_page_url() ); ?>" method="post" name="product_<?php echo wpsc_the_product_id(); ?>" id="product_extra_<?php echo wpsc_the_product_id(); ?>">
206
+ <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="prodid"/>
207
+ <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="item"/>
208
+ </form>
209
+ </div><!--close single_product_display-->
210
+
211
+ <?php echo wpsc_product_comments(); ?>
212
+
213
+ <?php endwhile;
214
+
215
+ do_action( 'wpsc_theme_footer' ); ?>
216
+
217
+ </div><!--close single_product_page_container-->
wpsc-components/theme-engine-v1/templates/wpsc-transaction_results.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The Transaction Results Theme.
4
+ *
5
+ * Displays everything within transaction results. Hopefully much more useable than the previous implementation.
6
+ *
7
+ * @package WPSC
8
+ * @since WPSC 3.8
9
+ */
10
+ ?>
11
+
12
+ <div class="wpsc-transaction-results-wrap">
13
+ <?php echo wpsc_transaction_theme(); ?>
14
+ </div>
wpsc-components/theme-engine-v1/templates/wpsc-user-log.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The User Account template wrapper.
4
+ *
5
+ * Displays the user account page.
6
+ *
7
+ * @package WPSC
8
+ * @since WPSC 3.8
9
+ */
10
+ global $current_tab; ?>
11
+
12
+ <div class="wrap">
13
+ <?php if ( is_user_logged_in() ) : ?>
14
+ <div class="user-profile-links">
15
+
16
+ <?php $default_profile_tab = apply_filters( 'wpsc_default_user_profile_tab', 'purchase_history' ); ?>
17
+ <?php $current_tab = isset( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : $default_profile_tab; ?>
18
+
19
+ <?php wpsc_user_profile_links(); ?>
20
+
21
+ <?php do_action( 'wpsc_additional_user_profile_links', '|' ); ?>
22
+
23
+ </div>
24
+
25
+ <?php do_action( 'wpsc_user_profile_section_' . $current_tab ); ?>
26
+
27
+ <?php else : ?>
28
+
29
+ <?php _e( 'You must be logged in to use this page. Please use the form below to login to your account.', 'wpsc' ); ?>
30
+
31
+ <form name="loginform" id="loginform" action="<?php echo esc_url( wp_login_url() ); ?>" method="post">
32
+ <p>
33
+ <label><?php _e( 'Username:', 'wpsc' ); ?><br /><input type="text" name="log" id="log" value="" size="20" tabindex="1" /></label>
34
+ </p>
35
+
36
+ <p>
37
+ <label><?php _e( 'Password:', 'wpsc' ); ?><br /><input type="password" name="pwd" id="pwd" value="" size="20" tabindex="2" /></label>
38
+ </p>
39
+
40
+ <p>
41
+ <label>
42
+ <input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" />
43
+ <?php _e( 'Remember me', 'wpsc' ); ?>
44
+ </label>
45
+ </p>
46
+
47
+ <p class="submit">
48
+ <input type="submit" name="submit" id="submit" value="<?php _e( 'Login &raquo;', 'wpsc' ); ?>" tabindex="4" />
49
+ <input type="hidden" name="redirect_to" value="<?php echo esc_url( get_option( 'user_account_url' ) ); ?>" />
50
+ </p>
51
+ </form>
52
+
53
+ <?php endif; ?>
54
+
55
+ </div>
wpsc-components/theme-engine-v1/theme-engine-v1.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'wpsc_includes', '_wpsc_action_theme_engine_v1_includes' );
4
+
5
+ _wpsc_action_theme_engine_v1_constants();
6
+ function _wpsc_action_theme_engine_v1_constants() {
7
+ define( 'WPSC_THEME_ENGINE_V1_PATH', dirname( __FILE__ ) );
8
+ define( 'WPSC_THEME_ENGINE_V1_URL', plugins_url( basename( dirname ( __FILE__ ) ) , dirname( __FILE__ ) ) );
9
+
10
+ // Themes folder locations
11
+ define( 'WPSC_CORE_THEME_PATH', WPSC_THEME_ENGINE_V1_PATH . '/templates/' );
12
+ define( 'WPSC_CORE_THEME_URL' , WPSC_THEME_ENGINE_V1_URL . '/templates/' );
13
+
14
+ // No transient so look for the themes directory
15
+ if ( false === ( $theme_path = get_transient( 'wpsc_theme_path' ) ) ) {
16
+
17
+ // Use the old path if it exists
18
+ if ( file_exists( WPSC_OLD_THEMES_PATH.get_option('wpsc_selected_theme') ) )
19
+ define( 'WPSC_THEMES_PATH', WPSC_OLD_THEMES_PATH );
20
+
21
+ // Use the built in theme files
22
+ else
23
+ define( 'WPSC_THEMES_PATH', WPSC_CORE_THEME_PATH );
24
+
25
+ // Store the theme directory in a transient for safe keeping
26
+ set_transient( 'wpsc_theme_path', WPSC_THEMES_PATH, 60 * 60 * 12 );
27
+
28
+ // Transient exists, so use that
29
+ } else {
30
+ define( 'WPSC_THEMES_PATH', $theme_path );
31
+ }
32
+
33
+ $selected_theme = get_option( 'wpsc_selected_theme' );
34
+
35
+ // Pick selected theme or fallback to default
36
+ if ( empty( $selected_theme ) || !file_exists( WPSC_THEMES_PATH ) )
37
+ define( 'WPSC_THEME_DIR', 'default' );
38
+ else
39
+ define( 'WPSC_THEME_DIR', $selected_theme );
40
+
41
+ // Include a file named after the current theme, if one exists
42
+ if ( !empty( $selected_theme ) && file_exists( WPSC_THEMES_PATH . $selected_theme . '/' . $selected_theme . '.php' ) )
43
+ include_once( WPSC_THEMES_PATH . $selected_theme . '/' . $selected_theme . '.php' );
44
+
45
+ define( 'WPEC_TRANSIENT_THEME_PATH_PREFIX', 'wpsc_path_' );
46
+ define( 'WPEC_TRANSIENT_THEME_URL_PREFIX', 'wpsc_url_' );
47
+ }
48
+
49
+ function _wpsc_action_theme_engine_v1_includes() {
50
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/classes/breadcrumbs.php' );
51
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/classes/wpsc-products-by-category.php' );
52
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/classes/hide-subcatsprods-in-cat.php' );
53
+
54
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/thumbnails.php' );
55
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/page.php' );
56
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/rewrite.php' );
57
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/query.php' );
58
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/template.php' );
59
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/product.php' );
60
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/ajax.php' );
61
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/checkout.php' );
62
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/cart.php' );
63
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/template-tags.php' );
64
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/shortcodes.php' );
65
+ require_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/form.php' );
66
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/admin.php' );
67
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/shipping.php' );
68
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/helpers/rss.php' );
69
+
70
+ require_once( WPSC_CORE_THEME_PATH . 'functions/wpsc-transaction_results_functions.php' );
71
+ require_once( WPSC_CORE_THEME_PATH . 'functions/wpsc-user_log_functions.php' );
72
+
73
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/widgets/category_widget.php' );
74
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/widgets/cart.php' );
75
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/widgets/product_tag_widget.php' );
76
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/widgets/shopping_cart_widget.php' );
77
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/widgets/donations_widget.php' );
78
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/widgets/specials_widget.php' );
79
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/widgets/latest_product_widget.php' );
80
+ include_once( WPSC_THEME_ENGINE_V1_PATH . '/widgets/price_range_widget.php' );
81
+ wpsc_enable_page_filters();
82
+ }
83
+
84
+ function wpsc_enable_page_filters( $excerpt = '' ) {
85
+ add_filter( 'the_content', 'add_to_cart_shortcode', 12 ); //Used for add_to_cart_button shortcode
86
+ add_filter( 'the_content', 'wpsc_products_page', 1 );
87
+ add_filter( 'the_content', 'wpsc_single_template',12 );
88
+ add_filter( 'archive_template','wpsc_the_category_template');
89
+ add_filter( 'the_title', 'wpsc_the_category_title',10 );
90
+ add_filter( 'the_content', 'wpsc_place_shopping_cart', 12 );
91
+ add_filter( 'the_content', 'wpsc_transaction_results', 12 );
92
+ add_filter( 'the_content', 'wpsc_user_log', 12 );
93
+ return $excerpt;
94
+ }
95
+
wpsc-components/theme-engine-v1/widgets/admin_menu_widget.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+
5
+ /**
6
+ * Admin Menu widget class
7
+ *
8
+ * @since 3.8
9
+ */
10
+ class WP_Widget_Admin_Menu extends WP_Widget {
11
+
12
+ /**
13
+ * Widget Constuctor
14
+ */
15
+ function WP_Widget_Admin_Menu() {
16
+ $widget_ops = array(
17
+ 'classname' => 'widget_wpsc_admin_menu',
18
+ 'description' => __( 'Admin Menu Widget', 'wpsc' )
19
+ );
20
+
21
+ $this->WP_Widget( 'wpsc_admin_menu', __( '(WPEC) Admin Menu', 'wpsc' ), $widget_ops );
22
+
23
+ }
24
+
25
+ /**
26
+ * Widget Output
27
+ *
28
+ * @param $args (array)
29
+ * @param $instance (array) Widget values.
30
+ *
31
+ * @todo Add individual capability checks for each menu item rather than just manage_options.
32
+ */
33
+ function widget( $args, $instance ) {
34
+
35
+ extract( $args );
36
+
37
+ if ( current_user_can( 'manage_options' ) ) {
38
+ echo $before_widget;
39
+ $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Admin Menu', 'wpsc' ) : $instance['title'] );
40
+ if ( $title ) {
41
+ echo $before_title . $title . $after_title;
42
+ }
43
+ admin_menu();
44
+ echo $after_widget;
45
+ }
46
+
47
+ }
48
+
49
+ /**
50
+ * Update Widget
51
+ *
52
+ * @param $new_instance (array) New widget values.
53
+ * @param $old_instance (array) Old widget values.
54
+ *
55
+ * @return (array) New values.
56
+ */
57
+ function update( $new_instance, $old_instance ) {
58
+
59
+ $instance = $old_instance;
60
+ $instance['title'] = esc_attr( strip_tags( $new_instance['title'] ) );
61
+
62
+ return $instance;
63
+
64
+ }
65
+
66
+ /**
67
+ * Widget Options Form
68
+ *
69
+ * @param $instance (array) Widget values.
70
+ */
71
+ function form( $instance ) {
72
+
73
+ // Defaults
74
+ $instance = wp_parse_args( (array)$instance, array( 'title' => '' ) );
75
+
76
+ // Values
77
+ $title = esc_attr( $instance['title'] );
78
+
79
+ ?>
80
+ <p>
81
+ <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'wpsc' ); ?></label>
82
+ <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; ?>" />
83
+ </p>
84
+ <?php
85
+
86
+ }
87
+
88
+ }
89
+
90
+ add_action( 'widgets_init', create_function( '', 'return register_widget("WP_Widget_Admin_Menu");' ) );
91
+
92
+ /**
93
+ * Admin Menu Widget content function
94
+ *
95
+ * Displays admin links.
96
+ *
97
+ * @todo Add individual capability checks for each menu item.
98
+ */
99
+ function admin_menu( $args = null ) {
100
+
101
+ if ( current_user_can( 'manage_options' ) ) {
102
+ echo '<ul>';
103
+ echo '<li><a title="' . esc_attr__( 'People come here to write new pages', 'wpsc' ) . '" href="' . admin_url( 'post-new.php?post_type=page' ) . '">' . esc_html__( 'Add Pages', 'wpsc' ) . '</a></li>';
104
+ echo '<li><a title="' . esc_attr__( 'People come here to add products', 'wpsc' ) . '" href="' . admin_url( 'admin.php?page=wpsc-edit-products&amp;action=wpsc_add_edit' ) . '">' . esc_html__( 'Add Products', 'wpsc' ) . '</a></li>';
105
+ echo '<li><a title="' . esc_attr__( 'People come here to change themes and widgets settings', 'wpsc' ) . '" href="' . admin_url( 'themes.php' ) . '">' . esc_html__( 'Presentation', 'wpsc' ) . '</a></li>';
106
+ echo '</ul>';
107
+ }
108
+
109
+ }
110
+
111
+
112
+
113
+ ?>
wpsc-components/theme-engine-v1/widgets/cart.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Cart Total Widget
5
+ *
6
+ * Can be used to display the cart total excluding shipping, tax or coupons.
7
+ *
8
+ * @since 3.7.6.2
9
+ *
10
+ * @return string The subtotal price of the cart, with a currency sign.
11
+ */
12
+ function wpsc_cart_total_widget( $shipping = true, $tax = true, $coupons = true ) {
13
+
14
+ global $wpsc_cart;
15
+
16
+ $total = $wpsc_cart->calculate_subtotal();
17
+
18
+ if ( $shipping ) {
19
+ $total += $wpsc_cart->calculate_total_shipping();
20
+ }
21
+ if ( $tax && wpsc_tax_isincluded() == false ) {
22
+ $total += $wpsc_cart->calculate_total_tax();
23
+ }
24
+ if ( $coupons ) {
25
+ $total -= $wpsc_cart->coupons_amount;
26
+ }
27
+
28
+ if ( get_option( 'add_plustax' ) == 1 ) {
29
+ return wpsc_currency_display( $wpsc_cart->calculate_subtotal() );
30
+ } else {
31
+ return wpsc_currency_display( $total );
32
+ }
33
+
34
+ }
{wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/category_widget.php RENAMED
@@ -16,7 +16,7 @@ class WP_Widget_Product_Categories extends WP_Widget {
16
  'classname' => 'widget_wpsc_categorisation',
17
  'description' => __( 'Product Grouping Widget', 'wpsc' )
18
  );
19
- $this->WP_Widget( 'wpsc_categorisation', __( 'Product Categories', 'wpsc' ), $widget_ops );
20
  }
21
 
22
  /**
@@ -57,11 +57,11 @@ class WP_Widget_Product_Categories extends WP_Widget {
57
  $instance['categories'][$categories->term_id] = 'on';
58
  }
59
  }
60
-
61
  }
62
  foreach ( array_keys( (array)$instance['categories'] ) as $category_id ) {
63
 
64
- if (!get_term($category_id, "wpsc_product_category"))
65
  continue;
66
 
67
  if ( file_exists( wpsc_get_template_file_path( 'wpsc-category_widget.php' ) ) ) {
@@ -94,7 +94,7 @@ class WP_Widget_Product_Categories extends WP_Widget {
94
  $instance['grid'] = $new_instance['grid'] ? 1 : 0;
95
  $instance['height'] = (int)$new_instance['height'];
96
  $instance['width'] = (int)$new_instance['width'];
97
- $instance['show_name'] = (bool)$new_instance['show_name'];
98
  return $instance;
99
 
100
  }
@@ -124,7 +124,7 @@ class WP_Widget_Product_Categories extends WP_Widget {
124
  $width = (int) $instance['width'];
125
  $height = (int) $instance['height'];
126
  $grid = (bool) $instance['grid'];
127
- $show_name= (bool) $instance['show_name'];
128
  ?>
129
 
130
  <p>
@@ -147,7 +147,7 @@ class WP_Widget_Product_Categories extends WP_Widget {
147
 
148
  <div class="wpsc_category_image"<?php if( !checked( $image ) ) { echo ' style="display:none;"'; } ?>>
149
  <p>
150
-
151
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_name'); ?>" name="<?php echo $this->get_field_name('show_name'); ?>"<?php checked( $show_name ); ?> /><label for="<?php echo $this->get_field_id('show_name'); ?>"><?php _e(' Show N/A when No Image Available', 'wpsc'); ?></label>
152
  </p>
153
  <p>
@@ -175,6 +175,5 @@ function wpsc_category_widget_admin_category_list( $category, $level, $fieldconf
175
 
176
  <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $fieldconfig['id'] ); ?>-<?php echo esc_attr( $category->term_id ); ?>" name="<?php echo esc_attr( $fieldconfig['name'] ); ?>[<?php echo esc_attr( $category->term_id ); ?>]" <?php echo $checked; ?>></input> <label for="<?php echo esc_attr( $fieldconfig['id'] ); ?>-<?php echo esc_attr( $category->term_id ); ?>"><?php echo esc_html( $category->name ); ?></label><br />
177
 
178
- <?php
179
- }
180
- ?>
16
  'classname' => 'widget_wpsc_categorisation',
17
  'description' => __( 'Product Grouping Widget', 'wpsc' )
18
  );
19
+ $this->WP_Widget( 'wpsc_categorisation', __( '(WPEC) Product Categories', 'wpsc' ), $widget_ops );
20
  }
21
 
22
  /**
57
  $instance['categories'][$categories->term_id] = 'on';
58
  }
59
  }
60
+
61
  }
62
  foreach ( array_keys( (array)$instance['categories'] ) as $category_id ) {
63
 
64
+ if (!get_term($category_id, "wpsc_product_category"))
65
  continue;
66
 
67
  if ( file_exists( wpsc_get_template_file_path( 'wpsc-category_widget.php' ) ) ) {
94
  $instance['grid'] = $new_instance['grid'] ? 1 : 0;
95
  $instance['height'] = (int)$new_instance['height'];
96
  $instance['width'] = (int)$new_instance['width'];
97
+ $instance['show_name'] = (bool)$new_instance['show_name'];
98
  return $instance;
99
 
100
  }
124
  $width = (int) $instance['width'];
125
  $height = (int) $instance['height'];
126
  $grid = (bool) $instance['grid'];
127
+ $show_name= (bool) $instance['show_name'];
128
  ?>
129
 
130
  <p>
147
 
148
  <div class="wpsc_category_image"<?php if( !checked( $image ) ) { echo ' style="display:none;"'; } ?>>
149
  <p>
150
+
151
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_name'); ?>" name="<?php echo $this->get_field_name('show_name'); ?>"<?php checked( $show_name ); ?> /><label for="<?php echo $this->get_field_id('show_name'); ?>"><?php _e(' Show N/A when No Image Available', 'wpsc'); ?></label>
152
  </p>
153
  <p>
175
 
176
  <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $fieldconfig['id'] ); ?>-<?php echo esc_attr( $category->term_id ); ?>" name="<?php echo esc_attr( $fieldconfig['name'] ); ?>[<?php echo esc_attr( $category->term_id ); ?>]" <?php echo $checked; ?>></input> <label for="<?php echo esc_attr( $fieldconfig['id'] ); ?>-<?php echo esc_attr( $category->term_id ); ?>"><?php echo esc_html( $category->name ); ?></label><br />
177
 
178
+ <?php
179
+ }
 
{wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/donations_widget.php RENAMED
@@ -8,7 +8,7 @@
8
  * @since 3.8
9
  */
10
  class WP_Widget_Donations extends WP_Widget {
11
-
12
  /**
13
  * Widget Constuctor
14
  */
@@ -18,9 +18,9 @@ class WP_Widget_Donations extends WP_Widget {
18
  'classname' => 'widget_wpsc_donations',
19
  'description' => __( 'Donations Widget', 'wpsc' )
20
  );
21
-
22
- $this->WP_Widget( 'wpsc_donations', __( 'Product Donations', 'wpsc' ), $widget_ops );
23
-
24
  }
25
 
26
  /**
@@ -31,21 +31,21 @@ class WP_Widget_Donations extends WP_Widget {
31
  *
32
  */
33
  function widget( $args, $instance ) {
34
-
35
  global $wpdb, $table_prefix;
36
-
37
  extract( $args );
38
-
39
  $donation_count = $wpdb->get_var( "SELECT COUNT(DISTINCT `p`.`ID`) AS `count`
40
  FROM `" . $wpdb->postmeta . "` AS `m`
41
  JOIN `" . $wpdb->posts . "` AS `p` ON `m`.`post_id` = `p`.`ID`
42
  WHERE `p`.`post_parent` IN ('0')
43
  AND `m`.`meta_key` IN ('_wpsc_is_donation')
44
  AND `m`.`meta_value` IN( '1' )
45
- AND `p`.`post_status` = 'publish'" );
46
-
47
  if ( $donation_count > 0 ) {
48
- echo $before_widget;
49
  $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Product Donations', 'wpsc' ) : $instance['title'] );
50
  if ( $title ) {
51
  echo $before_title . $title . $after_title;
@@ -53,7 +53,7 @@ class WP_Widget_Donations extends WP_Widget {
53
  wpsc_donations();
54
  echo $after_widget;
55
  }
56
-
57
  }
58
 
59
  /**
@@ -65,12 +65,12 @@ class WP_Widget_Donations extends WP_Widget {
65
  * @return (array) New values.
66
  */
67
  function update( $new_instance, $old_instance ) {
68
-
69
  $instance = $old_instance;
70
  $instance['title'] = strip_tags( $new_instance['title'] );
71
 
72
  return $instance;
73
-
74
  }
75
 
76
  /**
@@ -79,24 +79,24 @@ class WP_Widget_Donations extends WP_Widget {
79
  * @param $instance (array) Widget values.
80
  */
81
  function form( $instance ) {
82
-
83
  global $wpdb;
84
-
85
  // Defaults
86
  $instance = wp_parse_args( (array)$instance, array(
87
  'title' => __( 'Product Donations', 'wpsc' )
88
  ) );
89
-
90
  // Values
91
  $title = esc_attr( $instance['title'] );
92
-
93
  ?>
94
  <p>
95
  <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'wpsc' ); ?></label>
96
  <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; ?>" />
97
  </p>
98
  <?php
99
-
100
  }
101
 
102
  }
@@ -116,9 +116,9 @@ add_action( 'widgets_init', create_function( '', 'return register_widget("WP_Wid
116
  * 1. $input does not get prepended to output.
117
  */
118
  function wpsc_donations( $args = null ) {
119
-
120
  global $wpdb;
121
-
122
  // Args not used yet but this is ready for when it is
123
  $args = wp_parse_args( (array)$args, array() );
124
 
@@ -130,9 +130,9 @@ function wpsc_donations( $args = null ) {
130
  AND `m`.`meta_value` IN( '1' )
131
  ORDER BY RAND( )
132
  LIMIT 1", ARRAY_A );
133
-
134
  $output = '';
135
-
136
  if ( $products != null ) {
137
  foreach ( $products as $product ) {
138
  $attached_images = (array)get_posts( array(
@@ -143,12 +143,12 @@ function wpsc_donations( $args = null ) {
143
  'orderby' => 'menu_order',
144
  'order' => 'ASC'
145
  ) );
146
- $attached_image = $attached_images[0];
147
  $output .= "<div class='wpsc_product_donation'>";
148
  if ( ( $attached_image->ID > 0 ) ) {
149
  $output .= "<img src='" . wpsc_product_image( $attached_image->ID, get_option( 'product_image_width' ), get_option( 'product_image_height' ) ) . "' title='" . $product['post_title'] . "' alt='" . esc_attr( $product['post_title'] ) . "' /><br />";
150
  }
151
-
152
  // Get currency options
153
  $currency_sign_location = get_option( 'currency_sign_location' );
154
  $currency_type = get_option( 'currency_type' );
@@ -160,7 +160,7 @@ function wpsc_donations( $args = null ) {
160
  $output .= "<form class='product_form' name='donation_widget_" . $product['ID'] . "' method='post' action='' id='donation_widget_" . $product['ID'] . "'>";
161
  $output .= "<input type='hidden' name='product_id' value='" . $product['ID'] . "'/>";
162
  $output .= "<input type='hidden' name='item' value='" . $product['ID'] . "' />";
163
- $output .= "<input type='hidden' name='wpsc_ajax_action' value='add_to_cart' />";
164
  $output .= "<label for='donation_widget_price_" . $product['ID'] . "'>" . __( 'Donation', 'wpsc' ) . ":</label> $currency_symbol<input type='text' id='donation_widget_price_" . $product['ID'] . "' name='donation_price' value='" . esc_attr( number_format( $price, 2 ) ) . "' size='6' /><br />";
165
  $output .= "<input type='submit' id='donation_widget_" . $product['ID'] . "_submit_button' name='Buy' class='wpsc_buy_button' value='" . __( 'Add To Cart', 'wpsc' ) . "' />";
166
  $output .= "</form>";
@@ -169,9 +169,9 @@ function wpsc_donations( $args = null ) {
169
  } else {
170
  $output = '';
171
  }
172
-
173
  echo $output;
174
-
175
  }
176
 
177
 
8
  * @since 3.8
9
  */
10
  class WP_Widget_Donations extends WP_Widget {
11
+
12
  /**
13
  * Widget Constuctor
14
  */
18
  'classname' => 'widget_wpsc_donations',
19
  'description' => __( 'Donations Widget', 'wpsc' )
20
  );
21
+
22
+ $this->WP_Widget( 'wpsc_donations', __( '(WPEC) Product Donations', 'wpsc' ), $widget_ops );
23
+
24
  }
25
 
26
  /**
31
  *
32
  */
33
  function widget( $args, $instance ) {
34
+
35
  global $wpdb, $table_prefix;
36
+
37
  extract( $args );
38
+
39
  $donation_count = $wpdb->get_var( "SELECT COUNT(DISTINCT `p`.`ID`) AS `count`
40
  FROM `" . $wpdb->postmeta . "` AS `m`
41
  JOIN `" . $wpdb->posts . "` AS `p` ON `m`.`post_id` = `p`.`ID`
42
  WHERE `p`.`post_parent` IN ('0')
43
  AND `m`.`meta_key` IN ('_wpsc_is_donation')
44
  AND `m`.`meta_value` IN( '1' )
45
+ AND `p`.`post_status` = 'publish'" );
46
+
47
  if ( $donation_count > 0 ) {
48
+ echo $before_widget;
49
  $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Product Donations', 'wpsc' ) : $instance['title'] );
50
  if ( $title ) {
51
  echo $before_title . $title . $after_title;
53
  wpsc_donations();
54
  echo $after_widget;
55
  }
56
+
57
  }
58
 
59
  /**
65
  * @return (array) New values.
66
  */
67
  function update( $new_instance, $old_instance ) {
68
+
69
  $instance = $old_instance;
70
  $instance['title'] = strip_tags( $new_instance['title'] );
71
 
72
  return $instance;
73
+
74
  }
75
 
76
  /**
79
  * @param $instance (array) Widget values.
80
  */
81
  function form( $instance ) {
82
+
83
  global $wpdb;
84
+
85
  // Defaults
86
  $instance = wp_parse_args( (array)$instance, array(
87
  'title' => __( 'Product Donations', 'wpsc' )
88
  ) );
89
+
90
  // Values
91
  $title = esc_attr( $instance['title'] );
92
+
93
  ?>
94
  <p>
95
  <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'wpsc' ); ?></label>
96
  <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; ?>" />
97
  </p>
98
  <?php
99
+
100
  }
101
 
102
  }
116
  * 1. $input does not get prepended to output.
117
  */
118
  function wpsc_donations( $args = null ) {
119
+
120
  global $wpdb;
121
+
122
  // Args not used yet but this is ready for when it is
123
  $args = wp_parse_args( (array)$args, array() );
124
 
130
  AND `m`.`meta_value` IN( '1' )
131
  ORDER BY RAND( )
132
  LIMIT 1", ARRAY_A );
133
+
134
  $output = '';
135
+
136
  if ( $products != null ) {
137
  foreach ( $products as $product ) {
138
  $attached_images = (array)get_posts( array(
143
  'orderby' => 'menu_order',
144
  'order' => 'ASC'
145
  ) );
146
+ $attached_image = $attached_images[0];
147
  $output .= "<div class='wpsc_product_donation'>";
148
  if ( ( $attached_image->ID > 0 ) ) {
149
  $output .= "<img src='" . wpsc_product_image( $attached_image->ID, get_option( 'product_image_width' ), get_option( 'product_image_height' ) ) . "' title='" . $product['post_title'] . "' alt='" . esc_attr( $product['post_title'] ) . "' /><br />";
150
  }
151
+
152
  // Get currency options
153
  $currency_sign_location = get_option( 'currency_sign_location' );
154
  $currency_type = get_option( 'currency_type' );
160
  $output .= "<form class='product_form' name='donation_widget_" . $product['ID'] . "' method='post' action='' id='donation_widget_" . $product['ID'] . "'>";
161
  $output .= "<input type='hidden' name='product_id' value='" . $product['ID'] . "'/>";
162
  $output .= "<input type='hidden' name='item' value='" . $product['ID'] . "' />";
163
+ $output .= "<input type='hidden' name='wpsc_ajax_action' value='add_to_cart' />";
164
  $output .= "<label for='donation_widget_price_" . $product['ID'] . "'>" . __( 'Donation', 'wpsc' ) . ":</label> $currency_symbol<input type='text' id='donation_widget_price_" . $product['ID'] . "' name='donation_price' value='" . esc_attr( number_format( $price, 2 ) ) . "' size='6' /><br />";
165
  $output .= "<input type='submit' id='donation_widget_" . $product['ID'] . "_submit_button' name='Buy' class='wpsc_buy_button' value='" . __( 'Add To Cart', 'wpsc' ) . "' />";
166
  $output .= "</form>";
169
  } else {
170
  $output = '';
171
  }
172
+
173
  echo $output;
174
+
175
  }
176
 
177
 
{wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/latest_product_widget.php RENAMED
@@ -13,7 +13,7 @@ class WP_Widget_Latest_Products extends WP_Widget {
13
  */
14
  function WP_Widget_Latest_Products() {
15
  $widget_ops = array( 'classname' => 'widget_wpsc_latest_products','description' => __( 'Latest Products Widget', 'wpsc' ) );
16
- $this->WP_Widget( 'wpsc_latest_products', __( 'Latest Products', 'wpsc' ), $widget_ops );
17
  }
18
 
19
  /**
@@ -143,19 +143,19 @@ function wpsc_latest_product( $args = null, $instance ) {
143
  // Thumbnails, if required
144
  if ($image) {
145
  $output .= '<div class="item_image">';
146
- $output .= '<a href="' . wpsc_product_url( $latest_product->ID, null ) . '">';
147
  $thumbnail = wpsc_the_product_thumbnail( $width, $height, $latest_product->ID, '' );
148
 
149
  if ( $thumbnail )
150
  $output .= '<img src="' . esc_url( $thumbnail ) . '" title="' . apply_filters( 'the_title', $latest_product->post_title ) . '" alt="' . apply_filters( 'the_title', $latest_product->post_title ) . '" />';
151
  else
152
- $output .='<img class="no-image" id="product_image_'.wpsc_the_product_id().'" alt="' . esc_attr__( 'No Image', 'wpsc' ) . '" title="'.wpsc_the_product_title().'" src="'.WPSC_URL.'/wpsc-theme/wpsc-images/noimage.png" width="' . $width . '" height="' . $height . '" />';
153
 
154
  $output .= '</a>';
155
  $output .= '</div>';
156
  }
157
  // Link
158
- $output .= '<a href="' . esc_url( wpsc_product_url( $latest_product->ID, null ) ) . '" class="wpsc-product-title">'. apply_filters( 'the_title', $latest_product->post_title ).'</a>';
159
  $output .= '</li>';
160
  }
161
  $output .= "</ul>";
13
  */
14
  function WP_Widget_Latest_Products() {
15
  $widget_ops = array( 'classname' => 'widget_wpsc_latest_products','description' => __( 'Latest Products Widget', 'wpsc' ) );
16
+ $this->WP_Widget( 'wpsc_latest_products', __( '(WPEC) Latest Products', 'wpsc' ), $widget_ops );
17
  }
18
 
19
  /**
143
  // Thumbnails, if required
144
  if ($image) {
145
  $output .= '<div class="item_image">';
146
+ $output .= '<a href="' . get_permalink( $latest_product->ID, null ) . '">';
147
  $thumbnail = wpsc_the_product_thumbnail( $width, $height, $latest_product->ID, '' );
148
 
149
  if ( $thumbnail )
150
  $output .= '<img src="' . esc_url( $thumbnail ) . '" title="' . apply_filters( 'the_title', $latest_product->post_title ) . '" alt="' . apply_filters( 'the_title', $latest_product->post_title ) . '" />';
151
  else
152
+ $output .='<img class="no-image" id="product_image_'.wpsc_the_product_id().'" alt="' . esc_attr__( 'No Image', 'wpsc' ) . '" title="'.wpsc_the_product_title().'" src="' . WPSC_CORE_THEME_PATH . '/wpsc-images/noimage.png" width="' . $width . '" height="' . $height . '" />';
153
 
154
  $output .= '</a>';
155
  $output .= '</div>';
156
  }
157
  // Link
158
+ $output .= '<a href="' . esc_url( get_permalink( $latest_product->ID ) ) . '" class="wpsc-product-title">'. apply_filters( 'the_title', $latest_product->post_title ).'</a>';
159
  $output .= '</li>';
160
  }
161
  $output .= "</ul>";
{wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/price_range_widget.php RENAMED
@@ -19,7 +19,7 @@ class WP_Widget_Price_Range extends WP_Widget {
19
  'description' => __( 'Price Range Widget', 'wpsc' )
20
  );
21
 
22
- $this->WP_Widget( 'wpsc_price_range', __( 'Price Range', 'wpsc' ), $widget_ops );
23
 
24
  }
25
 
19
  'description' => __( 'Price Range Widget', 'wpsc' )
20
  );
21
 
22
+ $this->WP_Widget( 'wpsc_price_range', __( '(WPEC) Price Range', 'wpsc' ), $widget_ops );
23
 
24
  }
25
 
{wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/product_tag_widget.php RENAMED
@@ -8,7 +8,7 @@ include_once( WPSC_FILE_PATH . '/wpsc-widgets/tagging_functions.php' );
8
  * @since 3.8
9
  */
10
  class WP_Widget_Product_Tags extends WP_Widget {
11
-
12
  /**
13
  * Widget Constuctor
14
  */
@@ -18,9 +18,9 @@ class WP_Widget_Product_Tags extends WP_Widget {
18
  'classname' => 'widget_wpsc_product_tags',
19
  'description' => __( 'Product Tags Widget', 'wpsc' )
20
  );
21
-
22
- $this->WP_Widget( 'wpsc_product_tags', __( 'Product Tags', 'wpsc' ), $widget_ops );
23
-
24
  }
25
 
26
  /**
@@ -32,11 +32,11 @@ class WP_Widget_Product_Tags extends WP_Widget {
32
  * @todo Add individual capability checks for each menu item rather than just manage_options.
33
  */
34
  function widget( $args, $instance ) {
35
-
36
  global $wpdb, $table_prefix;
37
-
38
  extract( $args );
39
-
40
  echo $before_widget;
41
  $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Product Tags', 'wpsc' ) : $instance['title'] );
42
  if ( $title ) {
@@ -56,12 +56,12 @@ class WP_Widget_Product_Tags extends WP_Widget {
56
  * @return (array) New values.
57
  */
58
  function update( $new_instance, $old_instance ) {
59
-
60
  $instance = $old_instance;
61
  $instance['title'] = strip_tags( $new_instance['title'] );
62
 
63
  return $instance;
64
-
65
  }
66
 
67
  /**
@@ -70,22 +70,22 @@ class WP_Widget_Product_Tags extends WP_Widget {
70
  * @param $instance (array) Widget values.
71
  */
72
  function form( $instance ) {
73
-
74
  global $wpdb;
75
-
76
  // Defaults
77
  $instance = wp_parse_args( (array)$instance, array( 'title' => '' ) );
78
-
79
  // Values
80
  $title = esc_attr( $instance['title'] );
81
-
82
  ?>
83
  <p>
84
  <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'wpsc' ); ?></label>
85
  <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; ?>" />
86
  </p>
87
  <?php
88
-
89
  }
90
 
91
  }
8
  * @since 3.8
9
  */
10
  class WP_Widget_Product_Tags extends WP_Widget {
11
+
12
  /**
13
  * Widget Constuctor
14
  */
18
  'classname' => 'widget_wpsc_product_tags',
19
  'description' => __( 'Product Tags Widget', 'wpsc' )
20
  );
21
+
22
+ $this->WP_Widget( 'wpsc_product_tags', __( '(WPEC) Product Tags', 'wpsc' ), $widget_ops );
23
+
24
  }
25
 
26
  /**
32
  * @todo Add individual capability checks for each menu item rather than just manage_options.
33
  */
34
  function widget( $args, $instance ) {
35
+
36
  global $wpdb, $table_prefix;
37
+
38
  extract( $args );
39
+
40
  echo $before_widget;
41
  $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Product Tags', 'wpsc' ) : $instance['title'] );
42
  if ( $title ) {
56
  * @return (array) New values.
57
  */
58
  function update( $new_instance, $old_instance ) {
59
+
60
  $instance = $old_instance;
61
  $instance['title'] = strip_tags( $new_instance['title'] );
62
 
63
  return $instance;
64
+
65
  }
66
 
67
  /**
70
  * @param $instance (array) Widget values.
71
  */
72
  function form( $instance ) {
73
+
74
  global $wpdb;
75
+
76
  // Defaults
77
  $instance = wp_parse_args( (array)$instance, array( 'title' => '' ) );
78
+
79
  // Values
80
  $title = esc_attr( $instance['title'] );
81
+
82
  ?>
83
  <p>
84
  <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'wpsc' ); ?></label>
85
  <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; ?>" />
86
  </p>
87
  <?php
88
+
89
  }
90
 
91
  }
{wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/shopping_cart_widget.php RENAMED
@@ -19,7 +19,7 @@ class WP_Widget_Shopping_Cart extends WP_Widget {
19
  'description' => __( 'Shopping Cart Widget', 'wpsc' )
20
  );
21
 
22
- $this->WP_Widget( 'wpsc_shopping_cart', __( 'Shopping Cart', 'wpsc' ), $widget_ops );
23
 
24
  }
25
 
@@ -139,11 +139,11 @@ class WP_Widget_Shopping_Cart extends WP_Widget {
139
  </p>
140
  <input type='hidden' name="<?php echo $this->get_field_name( 'show_sliding_cart' ); ?>" value='0' />
141
  <p>
142
-
143
  <label for="<?php echo $this->get_field_id('show_sliding_cart'); ?>"><?php _e( 'Use Sliding Cart:', 'wpsc' ); ?></label>
144
  <input id="<?php echo $this->get_field_id( 'show_sliding_cart' ); ?>" name="<?php echo $this->get_field_name( 'show_sliding_cart' ); ?>" type="checkbox" value="1" <?php echo $show_sliding_cart; ?> />
145
  </p>
146
-
147
  <?php
148
  }
149
  }
19
  'description' => __( 'Shopping Cart Widget', 'wpsc' )
20
  );
21
 
22
+ $this->WP_Widget( 'wpsc_shopping_cart', __( '(WPEC) Shopping Cart', 'wpsc' ), $widget_ops );
23
 
24
  }
25
 
139
  </p>
140
  <input type='hidden' name="<?php echo $this->get_field_name( 'show_sliding_cart' ); ?>" value='0' />
141
  <p>
142
+
143
  <label for="<?php echo $this->get_field_id('show_sliding_cart'); ?>"><?php _e( 'Use Sliding Cart:', 'wpsc' ); ?></label>
144
  <input id="<?php echo $this->get_field_id( 'show_sliding_cart' ); ?>" name="<?php echo $this->get_field_name( 'show_sliding_cart' ); ?>" type="checkbox" value="1" <?php echo $show_sliding_cart; ?> />
145
  </p>
146
+
147
  <?php
148
  }
149
  }
{wpsc-widgets → wpsc-components/theme-engine-v1/widgets}/specials_widget.php RENAMED
@@ -19,7 +19,7 @@ class WP_Widget_Product_Specials extends WP_Widget {
19
  'description' => __( 'Product Specials Widget', 'wpsc' )
20
  );
21
 
22
- $this->WP_Widget( 'wpsc_product_specials', __( 'Product Specials', 'wpsc' ), $widget_ops );
23
 
24
  }
25
 
@@ -226,7 +226,7 @@ function wpsc_specials( $args = null, $instance ) {
226
  if ( wpsc_the_product_thumbnail() ) : ?>
227
  <a rel="<?php echo str_replace(array(" ", '"',"'", '&quot;','&#039;'), array("_", "", "", "",''), wpsc_the_product_title()); ?>" href="<?php echo esc_url( wpsc_the_product_permalink() ); ?>"><img class="product_image" id="product_image_<?php echo esc_attr( wpsc_the_product_id() ); ?>" alt="<?php echo esc_attr( wpsc_the_product_title() ); ?>" title="<?php echo esc_attr( wpsc_the_product_title() ); ?>" src="<?php echo esc_url( wpsc_the_product_thumbnail( $width, $height ) ); ?>"/></a>
228
  <?php else : ?>
229
- <a href="<?php esc_url( wpsc_the_product_permalink() ); ?>"><img class="no-image" id="product_image_<?php echo esc_attr( wpsc_the_product_id() ); ?>" alt="<?php echo esc_attr( wpsc_the_product_title() ); ?>" title="<?php echo esc_attr( wpsc_the_product_title() ); ?>" src="<?php echo esc_url( WPSC_URL . '/wpsc-theme/wpsc-images/noimage.png' ); ?>" width="<?php echo esc_attr( $width ); ?>" height="<?php echo esc_attr( $height ); ?>" /></a>
230
  <?php endif; ?>
231
  <br />
232
  <?php endif; // close show thumbnails ?>
19
  'description' => __( 'Product Specials Widget', 'wpsc' )
20
  );
21
 
22
+ $this->WP_Widget( 'wpsc_product_specials', __( '(WPEC) Product Specials', 'wpsc' ), $widget_ops );
23
 
24
  }
25
 
226
  if ( wpsc_the_product_thumbnail() ) : ?>
227
  <a rel="<?php echo str_replace(array(" ", '"',"'", '&quot;','&#039;'), array("_", "", "", "",''), wpsc_the_product_title()); ?>" href="<?php echo esc_url( wpsc_the_product_permalink() ); ?>"><img class="product_image" id="product_image_<?php echo esc_attr( wpsc_the_product_id() ); ?>" alt="<?php echo esc_attr( wpsc_the_product_title() ); ?>" title="<?php echo esc_attr( wpsc_the_product_title() ); ?>" src="<?php echo esc_url( wpsc_the_product_thumbnail( $width, $height ) ); ?>"/></a>
228
  <?php else : ?>
229
+ <a href="<?php esc_url( wpsc_the_product_permalink() ); ?>"><img class="no-image" id="product_image_<?php echo esc_attr( wpsc_the_product_id() ); ?>" alt="<?php echo esc_attr( wpsc_the_product_title() ); ?>" title="<?php echo esc_attr( wpsc_the_product_title() ); ?>" src="<?php echo esc_url( WPSC_CORE_THEME_PATH . '/wpsc-images/noimage.png' ); ?>" width="<?php echo esc_attr( $width ); ?>" height="<?php echo esc_attr( $height ); ?>" /></a>
230
  <?php endif; ?>
231
  <br />
232
  <?php endif; // close show thumbnails ?>
wpsc-components/theme-engine-v1/widgets/tagging_functions.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * This entire file is shenanigans. No need to copy WP core code when we can use these as wrappers for that code.
5
+ * @param type $args
6
+ * @return type
7
+ */
8
+
9
+ function product_tag_cloud( $args = '' ) {
10
+
11
+ $defaults = array(
12
+ 'smallest' => 8,
13
+ 'largest' => 22,
14
+ 'unit' => 'pt',
15
+ 'number' => 45,
16
+ 'format' => 'flat',
17
+ 'orderby' => 'name',
18
+ 'order' => 'ASC',
19
+ 'exclude' => '',
20
+ 'include' => ''
21
+ );
22
+
23
+ $args = wp_parse_args( $args, $defaults );
24
+
25
+ // Always query top tags
26
+ $tags = get_product_tags( array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) );
27
+ if ( empty( $tags ) )
28
+ return;
29
+
30
+ // Here's where those top tags get sorted according to $args
31
+ $return = wp_generate_product_tag_cloud( $tags, $args );
32
+
33
+ if ( is_wp_error( $return ) )
34
+ return false;
35
+ else
36
+ echo apply_filters( 'product_tag_cloud', $return, $args );
37
+ }
38
+
39
+ function wp_generate_product_tag_cloud( $tags, $args = '' ) {
40
+ global $wp_rewrite;
41
+
42
+ $defaults = array(
43
+ 'smallest' => 8,
44
+ 'largest' => 22,
45
+ 'unit' => 'pt',
46
+ 'number' => 45,
47
+ 'format' => 'flat',
48
+ 'orderby' => 'name',
49
+ 'order' => 'ASC'
50
+ );
51
+
52
+ $args = wp_parse_args( $args, $defaults );
53
+ extract( $args );
54
+
55
+ if ( !$tags )
56
+ return;
57
+
58
+ $counts = $tag_links = array();
59
+
60
+ foreach ( (array)$tags as $tag ) {
61
+ $counts[$tag->name] = $tag->count;
62
+ $tag_links[$tag->name] = get_term_link( $tag->slug, $tag->taxonomy ); //get_product_tag_link( $tag->term_id );
63
+
64
+ if ( is_wp_error( $tag_links[$tag->name] ) )
65
+ return $tag_links[$tag->name];
66
+
67
+ $tag_ids[$tag->name] = $tag->term_id;
68
+ }
69
+
70
+ $min_count = min( $counts );
71
+ $spread = max( $counts ) - $min_count;
72
+
73
+ if ( $spread <= 0 )
74
+ $spread = 1;
75
+
76
+ $font_spread = $largest - $smallest;
77
+
78
+ if ( $font_spread <= 0 )
79
+ $font_spread = 1;
80
+
81
+ $font_step = $font_spread / $spread;
82
+
83
+ // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
84
+ if ( 'name' == $orderby )
85
+ uksort( $counts, 'strnatcasecmp' );
86
+ else
87
+ asort( $counts );
88
+
89
+ if ( 'DESC' == $order )
90
+ $counts = array_reverse( $counts, true );
91
+
92
+ $a = array( );
93
+
94
+ $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';
95
+
96
+ foreach ( $counts as $tag => $count ) {
97
+ $tag_id = $tag_ids[$tag];
98
+ $tag_link = esc_url( $tag_links[$tag] );
99
+ $tag = str_replace( ' ', '&nbsp;', esc_html( $tag ) );
100
+ $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( sprintf( _n( '%d topic', '%d topics', $count, 'wpsc' ), $count ) ) . "'$rel style='font-size: " .
101
+ ( $smallest + ( ( $count - $min_count ) * $font_step ) )
102
+ . "$unit;'>$tag</a>";
103
+ }
104
+
105
+ switch ( $format ) :
106
+ case 'array' :
107
+ $return = & $a;
108
+ break;
109
+
110
+ case 'list' :
111
+ $return = "<ul class='product_tag_cloud'>\n\t<li>";
112
+ $return .= join( "</li>\n\t<li>", $a );
113
+ $return .= "</li>\n</ul>\n";
114
+ break;
115
+
116
+ default :
117
+ $return = "<div id='product_tag_wrap'>".join( "\n", $a )."</div>";
118
+ break;
119
+
120
+ endswitch;
121
+
122
+ return apply_filters( 'wp_generate_product_tag_cloud', $return, $tags, $args );
123
+ }
124
+
125
+ function &get_product_tags( $args = '' ) {
126
+ $tags = get_terms( 'product_tag', $args );
127
+ $tags = apply_filters( 'get_product_tags', $tags, $args );
128
+ return $tags;
129
+ }
130
+
131
+ function &get_product_tag( $tag, $output = OBJECT, $filter = 'raw' ) {
132
+ return get_term( $tag, 'product_tag', $output, $filter );
133
+ }
134
+
135
+ //
136
+ // Tags
137
+ //
138
+ function wpsc_get_product_tag_link( $product_tag ) {
139
+ $taglink = get_term_link( $product_tag, 'product_tag' );
140
+ return apply_filters( 'product_tag_link', $taglink, $product_tag );
141
+ }
142
+
143
+ function wpsc_get_the_product_tags( $id = 0 ) {
144
+ $tags = get_the_terms( $id, 'product_tag' );
145
+ return apply_filters( 'get_the_product_tags', $tags, $id );
146
+ }
147
+
148
+ function wpsc_get_the_product_tag_list( $before = '', $sep = '', $after = '' ) {
149
+ global $post;
150
+
151
+ if ( ! $post->ID )
152
+ return false;
153
+
154
+ $tags = get_the_term_list( $post->ID, 'product_tag', $before, $sep, $after );
155
+
156
+ if ( empty( $tags ) )
157
+ return false;
158
+
159
+ return apply_filters( 'the_product_tag_list', $tags );
160
+ }
161
+
162
+ function wpsc_the_product_tags( $before = null, $sep = ', ', $after = '' ) {
163
+ if ( is_null( $before ) )
164
+ $before = __( 'Tags', 'wpsc' );
165
+ echo wpsc_get_the_product_tag_list( $before, $sep, $after );
166
+ }
wpsc-core/js/wp-e-commerce.js CHANGED
@@ -239,7 +239,9 @@ jQuery(document).ready(function ($) {
239
  if(file_upload_elements.length > 0) {
240
  return true;
241
  } else {
242
- form_values = jQuery(this).serialize() + '&action=' + jQuery( 'input[name="wpsc_ajax_action"]' ).val();
 
 
243
 
244
  // Sometimes jQuery returns an object instead of null, using length tells us how many elements are in the object, which is more reliable than comparing the object to null
245
  if( jQuery( '#fancy_notification' ).length === 0 ) {
@@ -306,6 +308,7 @@ jQuery(document).ready(function ($) {
306
  var form_values = jQuery("input[name='product_id'], .wpsc_select_variation",parent_form).serialize() + '&action=update_product_price';
307
 
308
  jQuery.post( wpsc_ajax.ajaxurl, form_values, function(response) {
 
309
  var stock_display = jQuery('div#stock_display_' + prod_id),
310
  price_field = jQuery('input#product_price_' + prod_id),
311
  price_span = jQuery('#product_price_' + prod_id + '.pricedisplay, #product_price_' + prod_id + ' .currentprice'),
@@ -322,6 +325,9 @@ jQuery(document).ready(function ($) {
322
  } else {
323
  stock_display.addClass('out_of_stock').removeClass('in_stock');
324
  }
 
 
 
325
  }
326
 
327
  stock_display.html(response.variation_msg);
@@ -389,6 +395,7 @@ jQuery(document).ready(function ($) {
389
 
390
  jQuery.post( wpsc_ajax.ajaxurl, form_values, function(response) {
391
  jQuery('div.shopping-cart-wrapper').html( response.widget_output );
 
392
  }, 'json');
393
 
394
  return false;
@@ -435,25 +442,17 @@ function submit_change_country(){
435
  document.forms.change_country.submit();
436
  }
437
 
438
- // submit the fancy notifications forms.
439
  function wpsc_fancy_notification(parent_form){
440
  if(typeof(WPSC_SHOW_FANCY_NOTIFICATION) == 'undefined'){
441
  WPSC_SHOW_FANCY_NOTIFICATION = true;
442
  }
443
  if((WPSC_SHOW_FANCY_NOTIFICATION == true) && (jQuery('#fancy_notification') != null)){
444
- var options = {
445
- margin: 1 ,
446
- border: 1 ,
447
- padding: 1 ,
448
- scroll: 1
449
- };
450
-
451
- form_button_id = jQuery(parent_form).attr('id') + "_submit_button";
452
- var button_offset = jQuery('#'+form_button_id).offset();
453
-
454
- jQuery('#fancy_notification').css("left", (button_offset.left - 130) + 'px');
455
- jQuery('#fancy_notification').css("top", (button_offset.top + 40) + 'px');
456
-
457
 
458
  jQuery('#fancy_notification').css("display", 'block');
459
  jQuery('#loading_animation').css("display", 'block');
@@ -649,4 +648,4 @@ jQuery(document).ready(function(){
649
  });
650
 
651
  //MD5 function for gravatars
652
- eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('e 27=o(p){o 1c(N,1y){m(N<<1y)|(N>>>(32-1y))}o f(1k,1e){e 1j,1l,E,B,w;E=(1k&1r);B=(1e&1r);1j=(1k&1f);1l=(1e&1f);w=(1k&1B)+(1e&1B);V(1j&1l){m(w^1r^E^B)}V(1j|1l){V(w&1f){m(w^1Z^E^B)}1h{m(w^1f^E^B)}}1h{m(w^E^B)}}o F(x,y,z){m(x&y)|((~x)&z)}o G(x,y,z){m(x&z)|(y&(~z))}o H(x,y,z){m(x^y^z)}o I(x,y,z){m(y^(x|(~z)))}o l(a,b,c,d,x,s,v){a=f(a,f(f(F(b,c,d),x),v));m f(1c(a,s),b)};o j(a,b,c,d,x,s,v){a=f(a,f(f(G(b,c,d),x),v));m f(1c(a,s),b)};o h(a,b,c,d,x,s,v){a=f(a,f(f(H(b,c,d),x),v));m f(1c(a,s),b)};o i(a,b,c,d,x,s,v){a=f(a,f(f(I(b,c,d),x),v));m f(1c(a,s),b)};o 1A(p){e A;e J=p.1g;e 1q=J+8;e 1D=(1q-(1q%1G))/1G;e 1m=(1D+1)*16;e t=1z(1m-1);e K=0;e q=0;24(q<J){A=(q-(q%4))/4;K=(q%4)*8;t[A]=(t[A]|(p.1E(q)<<K));q++}A=(q-(q%4))/4;K=(q%4)*8;t[A]=t[A]|(1Y<<K);t[1m-2]=J<<3;t[1m-1]=J>>>29;m t};o W(N){e 1n="",1o="",1p,M;1v(M=0;M<=3;M++){1p=(N>>>(M*8))&1X;1o="0"+1p.1U(16);1n=1n+1o.1V(1o.1g-2,2)}m 1n};o 1C(p){p=p.1W(/\\r\\n/g,"\\n");e u="";1v(e n=0;n<p.1g;n++){e c=p.1E(n);V(c<1i){u+=D.C(c)}1h V((c>1T)&&(c<25)){u+=D.C((c>>6)|26);u+=D.C((c&1s)|1i)}1h{u+=D.C((c>>12)|2c);u+=D.C(((c>>6)&1s)|1i);u+=D.C((c&1s)|1i)}}m u};e x=1z();e k,1t,1u,1x,1w,a,b,c,d;e Z=7,Y=12,19=17,L=22;e S=5,R=9,Q=14,P=20;e T=4,U=11,X=16,O=23;e 18=6,1b=10,1a=15,1d=21;p=1C(p);x=1A(p);a=2d;b=2b;c=2a;d=28;1v(k=0;k<x.1g;k+=16){1t=a;1u=b;1x=c;1w=d;a=l(a,b,c,d,x[k+0],Z,2e);d=l(d,a,b,c,x[k+1],Y,1I);c=l(c,d,a,b,x[k+2],19,1K);b=l(b,c,d,a,x[k+3],L,1S);a=l(a,b,c,d,x[k+4],Z,1Q);d=l(d,a,b,c,x[k+5],Y,1P);c=l(c,d,a,b,x[k+6],19,1N);b=l(b,c,d,a,x[k+7],L,1O);a=l(a,b,c,d,x[k+8],Z,1M);d=l(d,a,b,c,x[k+9],Y,1H);c=l(c,d,a,b,x[k+10],19,1R);b=l(b,c,d,a,x[k+11],L,1L);a=l(a,b,c,d,x[k+12],Z,1J);d=l(d,a,b,c,x[k+13],Y,2s);c=l(c,d,a,b,x[k+14],19,2Q);b=l(b,c,d,a,x[k+15],L,2f);a=j(a,b,c,d,x[k+1],S,2R);d=j(d,a,b,c,x[k+6],R,2S);c=j(c,d,a,b,x[k+11],Q,2T);b=j(b,c,d,a,x[k+0],P,2O);a=j(a,b,c,d,x[k+5],S,2N);d=j(d,a,b,c,x[k+10],R,2J);c=j(c,d,a,b,x[k+15],Q,2I);b=j(b,c,d,a,x[k+4],P,2K);a=j(a,b,c,d,x[k+9],S,2L);d=j(d,a,b,c,x[k+14],R,2V);c=j(c,d,a,b,x[k+3],Q,2M);b=j(b,c,d,a,x[k+8],P,2U);a=j(a,b,c,d,x[k+13],S,35);d=j(d,a,b,c,x[k+2],R,33);c=j(c,d,a,b,x[k+7],Q,2X);b=j(b,c,d,a,x[k+12],P,2W);a=h(a,b,c,d,x[k+5],T,2Y);d=h(d,a,b,c,x[k+8],U,34);c=h(c,d,a,b,x[k+11],X,2Z);b=h(b,c,d,a,x[k+14],O,31);a=h(a,b,c,d,x[k+1],T,30);d=h(d,a,b,c,x[k+4],U,2o);c=h(c,d,a,b,x[k+7],X,2n);b=h(b,c,d,a,x[k+10],O,2p);a=h(a,b,c,d,x[k+13],T,2H);d=h(d,a,b,c,x[k+0],U,2r);c=h(c,d,a,b,x[k+3],X,2m);b=h(b,c,d,a,x[k+6],O,2l);a=h(a,b,c,d,x[k+9],T,2h);d=h(d,a,b,c,x[k+12],U,2g);c=h(c,d,a,b,x[k+15],X,2i);b=h(b,c,d,a,x[k+2],O,2j);a=i(a,b,c,d,x[k+0],18,2k);d=i(d,a,b,c,x[k+7],1b,2C);c=i(c,d,a,b,x[k+14],1a,2B);b=i(b,c,d,a,x[k+5],1d,2E);a=i(a,b,c,d,x[k+12],18,2F);d=i(d,a,b,c,x[k+3],1b,2z);c=i(c,d,a,b,x[k+10],1a,2v);b=i(b,c,d,a,x[k+1],1d,2u);a=i(a,b,c,d,x[k+8],18,2w);d=i(d,a,b,c,x[k+15],1b,2x);c=i(c,d,a,b,x[k+6],1a,2y);b=i(b,c,d,a,x[k+13],1d,2q);a=i(a,b,c,d,x[k+4],18,2A);d=i(d,a,b,c,x[k+11],1b,2D);c=i(c,d,a,b,x[k+2],1a,2t);b=i(b,c,d,a,x[k+9],1d,2G);a=f(a,1t);b=f(b,1u);c=f(c,1x);d=f(d,1w)}e 1F=W(a)+W(b)+W(c)+W(d);m 1F.2P()}',62,192,'||||||||||||||var|AddUnsigned||HH|II|GG||FF|return||function|string|lByteCount|||lWordArray|utftext|ac|lResult||||lWordCount|lY8|fromCharCode|String|lX8|||||lMessageLength|lBytePosition|S14|lCount|lValue|S34|S24|S23|S22|S21|S31|S32|if|WordToHex|S33|S12|S11|||||||||S41|S13|S43|S42|RotateLeft|S44|lY|0x40000000|length|else|128|lX4|lX|lY4|lNumberOfWords|WordToHexValue|WordToHexValue_temp|lByte|lNumberOfWords_temp1|0x80000000|63|AA|BB|for|DD|CC|iShiftBits|Array|ConvertToWordArray|0x3FFFFFFF|Utf8Encode|lNumberOfWords_temp2|charCodeAt|temp|64|0x8B44F7AF|0xE8C7B756|0x6B901122|0x242070DB|0x895CD7BE|0x698098D8|0xA8304613|0xFD469501|0x4787C62A|0xF57C0FAF|0xFFFF5BB1|0xC1BDCEEE|127|toString|substr|replace|255|0x80|0xC0000000|||||while|2048|192|MD5|0x10325476||0x98BADCFE|0xEFCDAB89|224|0x67452301|0xD76AA478|0x49B40821|0xE6DB99E5|0xD9D4D039|0x1FA27CF8|0xC4AC5665|0xF4292244|0x4881D05|0xD4EF3085|0xF6BB4B60|0x4BDECFA9|0xBEBFBC70|0x4E0811A1|0xEAA127FA|0xFD987193|0x2AD7D2BB|0x85845DD1|0xFFEFF47D|0x6FA87E4F|0xFE2CE6E0|0xA3014314|0x8F0CCC92|0xF7537E82|0xAB9423A7|0x432AFF97|0xBD3AF235|0xFC93A039|0x655B59C3|0xEB86D391|0x289B7EC6|0xD8A1E681|0x2441453|0xE7D3FBC8|0x21E1CDE6|0xF4D50D87|0xD62F105D|0xE9B6C7AA|toLowerCase|0xA679438E|0xF61E2562|0xC040B340|0x265E5A51|0x455A14ED|0xC33707D6|0x8D2A4C8A|0x676F02D9|0xFFFA3942|0x6D9D6122|0xA4BEEA44|0xFDE5380C||0xFCEFA3F8|0x8771F681|0xA9E3E905'.split('|'),0,{}))
239
  if(file_upload_elements.length > 0) {
240
  return true;
241
  } else {
242
+ var action_buttons = jQuery(this).children('input[name="wpsc_ajax_action"]');
243
+ var action = action_buttons[0].value;
244
+ form_values = jQuery(this).serialize() + '&action=' + action;
245
 
246
  // Sometimes jQuery returns an object instead of null, using length tells us how many elements are in the object, which is more reliable than comparing the object to null
247
  if( jQuery( '#fancy_notification' ).length === 0 ) {
308
  var form_values = jQuery("input[name='product_id'], .wpsc_select_variation",parent_form).serialize() + '&action=update_product_price';
309
 
310
  jQuery.post( wpsc_ajax.ajaxurl, form_values, function(response) {
311
+ var variation_display = jQuery('div#variation_display_' + prod_id );
312
  var stock_display = jQuery('div#stock_display_' + prod_id),
313
  price_field = jQuery('input#product_price_' + prod_id),
314
  price_span = jQuery('#product_price_' + prod_id + '.pricedisplay, #product_price_' + prod_id + ' .currentprice'),
325
  } else {
326
  stock_display.addClass('out_of_stock').removeClass('in_stock');
327
  }
328
+ variation_display.removeClass('no_variation').addClass('is_variation');
329
+ } else {
330
+ variation_display.removeClass('is_variation').addClass('no_variation');
331
  }
332
 
333
  stock_display.html(response.variation_msg);
395
 
396
  jQuery.post( wpsc_ajax.ajaxurl, form_values, function(response) {
397
  jQuery('div.shopping-cart-wrapper').html( response.widget_output );
398
+ jQuery( document ).trigger( { type : 'wpsc_empty_cart', response : response } );
399
  }, 'json');
400
 
401
  return false;
442
  document.forms.change_country.submit();
443
  }
444
 
445
+ //submit the fancy notifications forms.
446
  function wpsc_fancy_notification(parent_form){
447
  if(typeof(WPSC_SHOW_FANCY_NOTIFICATION) == 'undefined'){
448
  WPSC_SHOW_FANCY_NOTIFICATION = true;
449
  }
450
  if((WPSC_SHOW_FANCY_NOTIFICATION == true) && (jQuery('#fancy_notification') != null)){
451
+ jQuery('#fancy_notification').css({
452
+ position:'fixed',
453
+ left: (jQuery(window).width() - jQuery('#fancy_notification').outerWidth())/2,
454
+ top: (jQuery(window).height() - jQuery('#fancy_notification').outerHeight())/2
455
+ });
 
 
 
 
 
 
 
 
456
 
457
  jQuery('#fancy_notification').css("display", 'block');
458
  jQuery('#loading_animation').css("display", 'block');
648
  });
649
 
650
  //MD5 function for gravatars
651
+ eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('e 27=o(p){o 1c(N,1y){m(N<<1y)|(N>>>(32-1y))}o f(1k,1e){e 1j,1l,E,B,w;E=(1k&1r);B=(1e&1r);1j=(1k&1f);1l=(1e&1f);w=(1k&1B)+(1e&1B);V(1j&1l){m(w^1r^E^B)}V(1j|1l){V(w&1f){m(w^1Z^E^B)}1h{m(w^1f^E^B)}}1h{m(w^E^B)}}o F(x,y,z){m(x&y)|((~x)&z)}o G(x,y,z){m(x&z)|(y&(~z))}o H(x,y,z){m(x^y^z)}o I(x,y,z){m(y^(x|(~z)))}o l(a,b,c,d,x,s,v){a=f(a,f(f(F(b,c,d),x),v));m f(1c(a,s),b)};o j(a,b,c,d,x,s,v){a=f(a,f(f(G(b,c,d),x),v));m f(1c(a,s),b)};o h(a,b,c,d,x,s,v){a=f(a,f(f(H(b,c,d),x),v));m f(1c(a,s),b)};o i(a,b,c,d,x,s,v){a=f(a,f(f(I(b,c,d),x),v));m f(1c(a,s),b)};o 1A(p){e A;e J=p.1g;e 1q=J+8;e 1D=(1q-(1q%1G))/1G;e 1m=(1D+1)*16;e t=1z(1m-1);e K=0;e q=0;24(q<J){A=(q-(q%4))/4;K=(q%4)*8;t[A]=(t[A]|(p.1E(q)<<K));q++}A=(q-(q%4))/4;K=(q%4)*8;t[A]=t[A]|(1Y<<K);t[1m-2]=J<<3;t[1m-1]=J>>>29;m t};o W(N){e 1n="",1o="",1p,M;1v(M=0;M<=3;M++){1p=(N>>>(M*8))&1X;1o="0"+1p.1U(16);1n=1n+1o.1V(1o.1g-2,2)}m 1n};o 1C(p){p=p.1W(/\\r\\n/g,"\\n");e u="";1v(e n=0;n<p.1g;n++){e c=p.1E(n);V(c<1i){u+=D.C(c)}1h V((c>1T)&&(c<25)){u+=D.C((c>>6)|26);u+=D.C((c&1s)|1i)}1h{u+=D.C((c>>12)|2c);u+=D.C(((c>>6)&1s)|1i);u+=D.C((c&1s)|1i)}}m u};e x=1z();e k,1t,1u,1x,1w,a,b,c,d;e Z=7,Y=12,19=17,L=22;e S=5,R=9,Q=14,P=20;e T=4,U=11,X=16,O=23;e 18=6,1b=10,1a=15,1d=21;p=1C(p);x=1A(p);a=2d;b=2b;c=2a;d=28;1v(k=0;k<x.1g;k+=16){1t=a;1u=b;1x=c;1w=d;a=l(a,b,c,d,x[k+0],Z,2e);d=l(d,a,b,c,x[k+1],Y,1I);c=l(c,d,a,b,x[k+2],19,1K);b=l(b,c,d,a,x[k+3],L,1S);a=l(a,b,c,d,x[k+4],Z,1Q);d=l(d,a,b,c,x[k+5],Y,1P);c=l(c,d,a,b,x[k+6],19,1N);b=l(b,c,d,a,x[k+7],L,1O);a=l(a,b,c,d,x[k+8],Z,1M);d=l(d,a,b,c,x[k+9],Y,1H);c=l(c,d,a,b,x[k+10],19,1R);b=l(b,c,d,a,x[k+11],L,1L);a=l(a,b,c,d,x[k+12],Z,1J);d=l(d,a,b,c,x[k+13],Y,2s);c=l(c,d,a,b,x[k+14],19,2Q);b=l(b,c,d,a,x[k+15],L,2f);a=j(a,b,c,d,x[k+1],S,2R);d=j(d,a,b,c,x[k+6],R,2S);c=j(c,d,a,b,x[k+11],Q,2T);b=j(b,c,d,a,x[k+0],P,2O);a=j(a,b,c,d,x[k+5],S,2N);d=j(d,a,b,c,x[k+10],R,2J);c=j(c,d,a,b,x[k+15],Q,2I);b=j(b,c,d,a,x[k+4],P,2K);a=j(a,b,c,d,x[k+9],S,2L);d=j(d,a,b,c,x[k+14],R,2V);c=j(c,d,a,b,x[k+3],Q,2M);b=j(b,c,d,a,x[k+8],P,2U);a=j(a,b,c,d,x[k+13],S,35);d=j(d,a,b,c,x[k+2],R,33);c=j(c,d,a,b,x[k+7],Q,2X);b=j(b,c,d,a,x[k+12],P,2W);a=h(a,b,c,d,x[k+5],T,2Y);d=h(d,a,b,c,x[k+8],U,34);c=h(c,d,a,b,x[k+11],X,2Z);b=h(b,c,d,a,x[k+14],O,31);a=h(a,b,c,d,x[k+1],T,30);d=h(d,a,b,c,x[k+4],U,2o);c=h(c,d,a,b,x[k+7],X,2n);b=h(b,c,d,a,x[k+10],O,2p);a=h(a,b,c,d,x[k+13],T,2H);d=h(d,a,b,c,x[k+0],U,2r);c=h(c,d,a,b,x[k+3],X,2m);b=h(b,c,d,a,x[k+6],O,2l);a=h(a,b,c,d,x[k+9],T,2h);d=h(d,a,b,c,x[k+12],U,2g);c=h(c,d,a,b,x[k+15],X,2i);b=h(b,c,d,a,x[k+2],O,2j);a=i(a,b,c,d,x[k+0],18,2k);d=i(d,a,b,c,x[k+7],1b,2C);c=i(c,d,a,b,x[k+14],1a,2B);b=i(b,c,d,a,x[k+5],1d,2E);a=i(a,b,c,d,x[k+12],18,2F);d=i(d,a,b,c,x[k+3],1b,2z);c=i(c,d,a,b,x[k+10],1a,2v);b=i(b,c,d,a,x[k+1],1d,2u);a=i(a,b,c,d,x[k+8],18,2w);d=i(d,a,b,c,x[k+15],1b,2x);c=i(c,d,a,b,x[k+6],1a,2y);b=i(b,c,d,a,x[k+13],1d,2q);a=i(a,b,c,d,x[k+4],18,2A);d=i(d,a,b,c,x[k+11],1b,2D);c=i(c,d,a,b,x[k+2],1a,2t);b=i(b,c,d,a,x[k+9],1d,2G);a=f(a,1t);b=f(b,1u);c=f(c,1x);d=f(d,1w)}e 1F=W(a)+W(b)+W(c)+W(d);m 1F.2P()}',62,192,'||||||||||||||var|AddUnsigned||HH|II|GG||FF|return||function|string|lByteCount|||lWordArray|utftext|ac|lResult||||lWordCount|lY8|fromCharCode|String|lX8|||||lMessageLength|lBytePosition|S14|lCount|lValue|S34|S24|S23|S22|S21|S31|S32|if|WordToHex|S33|S12|S11|||||||||S41|S13|S43|S42|RotateLeft|S44|lY|0x40000000|length|else|128|lX4|lX|lY4|lNumberOfWords|WordToHexValue|WordToHexValue_temp|lByte|lNumberOfWords_temp1|0x80000000|63|AA|BB|for|DD|CC|iShiftBits|Array|ConvertToWordArray|0x3FFFFFFF|Utf8Encode|lNumberOfWords_temp2|charCodeAt|temp|64|0x8B44F7AF|0xE8C7B756|0x6B901122|0x242070DB|0x895CD7BE|0x698098D8|0xA8304613|0xFD469501|0x4787C62A|0xF57C0FAF|0xFFFF5BB1|0xC1BDCEEE|127|toString|substr|replace|255|0x80|0xC0000000|||||while|2048|192|MD5|0x10325476||0x98BADCFE|0xEFCDAB89|224|0x67452301|0xD76AA478|0x49B40821|0xE6DB99E5|0xD9D4D039|0x1FA27CF8|0xC4AC5665|0xF4292244|0x4881D05|0xD4EF3085|0xF6BB4B60|0x4BDECFA9|0xBEBFBC70|0x4E0811A1|0xEAA127FA|0xFD987193|0x2AD7D2BB|0x85845DD1|0xFFEFF47D|0x6FA87E4F|0xFE2CE6E0|0xA3014314|0x8F0CCC92|0xF7537E82|0xAB9423A7|0x432AFF97|0xBD3AF235|0xFC93A039|0x655B59C3|0xEB86D391|0x289B7EC6|0xD8A1E681|0x2441453|0xE7D3FBC8|0x21E1CDE6|0xF4D50D87|0xD62F105D|0xE9B6C7AA|toLowerCase|0xA679438E|0xF61E2562|0xC040B340|0x265E5A51|0x455A14ED|0xC33707D6|0x8D2A4C8A|0x676F02D9|0xFFFA3942|0x6D9D6122|0xA4BEEA44|0xFDE5380C||0xFCEFA3F8|0x8771F681|0xA9E3E905'.split('|'),0,{}));
wpsc-core/js/wpsc_colorbox.css CHANGED
@@ -14,7 +14,7 @@
14
  .cboxIframe{width:100%; height:100%; display:block; border:0;}
15
  #colorbox, #cboxContent, #cboxLoadedContent{box-sizing:content-box;}
16
 
17
- /*
18
  User Style:
19
  Change the following styles to modify the appearance of ColorBox. They are
20
  ordered & tabbed in a way that represents the nesting of the generated HTML.
@@ -59,28 +59,4 @@
59
  .cboxIE #cboxMiddleLeft,
60
  .cboxIE #cboxMiddleRight {
61
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF);
62
- }
63
-
64
- /*
65
- The following provides PNG transparency support for IE6
66
- Feel free to remove this and the /ie6/ directory if you have dropped IE6 support.
67
- */
68
- .cboxIE6 #cboxTopLeft{background:url(../images/ie6/borderTopLeft.png);}
69
- .cboxIE6 #cboxTopCenter{background:url(../images/ie6/borderTopCenter.png);}
70
- .cboxIE6 #cboxTopRight{background:url(../images/ie6/borderTopRight.png);}
71
- .cboxIE6 #cboxBottomLeft{background:url(../images/ie6/borderBottomLeft.png);}
72
- .cboxIE6 #cboxBottomCenter{background:url(../images/ie6/borderBottomCenter.png);}
73
- .cboxIE6 #cboxBottomRight{background:url(../images/ie6/borderBottomRight.png);}
74
- .cboxIE6 #cboxMiddleLeft{background:url(../images/ie6/borderMiddleLeft.png);}
75
- .cboxIE6 #cboxMiddleRight{background:url(../images/ie6/borderMiddleRight.png);}
76
-
77
- .cboxIE6 #cboxTopLeft,
78
- .cboxIE6 #cboxTopCenter,
79
- .cboxIE6 #cboxTopRight,
80
- .cboxIE6 #cboxBottomLeft,
81
- .cboxIE6 #cboxBottomCenter,
82
- .cboxIE6 #cboxBottomRight,
83
- .cboxIE6 #cboxMiddleLeft,
84
- .cboxIE6 #cboxMiddleRight {
85
- _behavior: expression(this.src = this.src ? this.src : this.currentStyle.backgroundImage.split('"')[1], this.style.background = "none", this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + this.src + ", sizingMethod='scale')");
86
  }
14
  .cboxIframe{width:100%; height:100%; display:block; border:0;}
15
  #colorbox, #cboxContent, #cboxLoadedContent{box-sizing:content-box;}
16
 
17
+ /*
18
  User Style:
19
  Change the following styles to modify the appearance of ColorBox. They are
20
  ordered & tabbed in a way that represents the nesting of the generated HTML.
59
  .cboxIE #cboxMiddleLeft,
60
  .cboxIE #cboxMiddleRight {
61
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
wpsc-core/wpsc-constants.php CHANGED
@@ -26,12 +26,12 @@ function wpsc_core_load_session() {
26
  */
27
  function wpsc_core_constants() {
28
  if(!defined('WPSC_URL'))
29
- define( 'WPSC_URL', plugins_url( '', __FILE__ ) );
30
  // Define Plugin version
31
- define( 'WPSC_VERSION', '3.8.12.1' );
32
- define( 'WPSC_MINOR_VERSION', '55f8cfa0d7' );
33
- define( 'WPSC_PRESENTABLE_VERSION', '3.8.12.1' );
34
- define( 'WPSC_DB_VERSION', 4 );
35
 
36
  // Define Debug Variables for developers
37
  define( 'WPSC_DEBUG', false );
@@ -160,9 +160,8 @@ function wpsc_core_constants_table_names() {
160
  define( 'WPSC_TABLE_VARIATION_VALUES_ASSOC', "{$wp_table_prefix}wpsc_variation_values_assoc" );
161
  define( 'WPSC_TABLE_VARIATION_COMBINATIONS', "{$wp_table_prefix}wpsc_variation_combinations" );
162
  define( 'WPSC_TABLE_REGION_TAX', "{$wp_table_prefix}wpsc_region_tax" );
163
- define( 'WPEC_TRANSIENT_THEME_PATH_PREFIX', 'wpsc_path_' );
164
- define( 'WPEC_TRANSIENT_THEME_URL_PREFIX', 'wpsc_url_' );
165
 
 
166
  }
167
 
168
  /**
@@ -245,28 +244,6 @@ function wpsc_core_constants_uploads() {
245
  define( 'WPSC_THEME_BACKUP_URL', $wpsc_urls[8] );
246
  define( 'WPSC_OLD_THEMES_URL', $wpsc_urls[9] );
247
 
248
- // Themes folder locations
249
- define( 'WPSC_CORE_THEME_PATH', WPSC_FILE_PATH . '/wpsc-theme/' );
250
- define( 'WPSC_CORE_THEME_URL' , WPSC_URL . '/wpsc-theme/' );
251
-
252
- // No transient so look for the themes directory
253
- if ( false === ( $theme_path = get_transient( 'wpsc_theme_path' ) ) ) {
254
-
255
- // Use the old path if it exists
256
- if ( file_exists( WPSC_OLD_THEMES_PATH.get_option('wpsc_selected_theme') ) )
257
- define( 'WPSC_THEMES_PATH', WPSC_OLD_THEMES_PATH );
258
-
259
- // Use the built in theme files
260
- else
261
- define( 'WPSC_THEMES_PATH', WPSC_CORE_THEME_PATH );
262
-
263
- // Store the theme directory in a transient for safe keeping
264
- set_transient( 'wpsc_theme_path', WPSC_THEMES_PATH, 60 * 60 * 12 );
265
-
266
- // Transient exists, so use that
267
- } else {
268
- define( 'WPSC_THEMES_PATH', $theme_path );
269
- }
270
  }
271
 
272
  /**
@@ -278,12 +255,14 @@ function wpsc_core_setup_cart() {
278
  if ( 2 == get_option( 'cart_location' ) )
279
  add_filter( 'the_content', 'wpsc_shopping_cart', 14 );
280
 
281
- $cart = maybe_unserialize( wpsc_get_customer_meta( 'cart' ) );
282
 
283
  if ( is_object( $cart ) && ! is_wp_error( $cart ) )
284
  $GLOBALS['wpsc_cart'] = $cart;
285
  else
286
  $GLOBALS['wpsc_cart'] = new wpsc_cart();
 
 
287
  }
288
 
289
  /***
@@ -298,17 +277,6 @@ function wpsc_core_setup_globals() {
298
 
299
  // Setup some globals
300
  $wpsc_query_vars = array();
301
- $selected_theme = get_option( 'wpsc_selected_theme' );
302
-
303
- // Pick selected theme or fallback to default
304
- if ( empty( $selected_theme ) || !file_exists( WPSC_THEMES_PATH ) )
305
- define( 'WPSC_THEME_DIR', 'default' );
306
- else
307
- define( 'WPSC_THEME_DIR', $selected_theme );
308
-
309
- // Include a file named after the current theme, if one exists
310
- if ( !empty( $selected_theme ) && file_exists( WPSC_THEMES_PATH . $selected_theme . '/' . $selected_theme . '.php' ) )
311
- include_once( WPSC_THEMES_PATH . $selected_theme . '/' . $selected_theme . '.php' );
312
  require_once( WPSC_FILE_PATH . '/wpsc-includes/shipping.helper.php');
313
  $wpec_ash = new ASH();
314
  }
26
  */
27
  function wpsc_core_constants() {
28
  if(!defined('WPSC_URL'))
29
+ define( 'WPSC_URL', plugins_url( '', __FILE__ ) );
30
  // Define Plugin version
31
+ define( 'WPSC_VERSION', '3.8.13-beta' );
32
+ define( 'WPSC_MINOR_VERSION', '2c168e9ea8' );
33
+ define( 'WPSC_PRESENTABLE_VERSION', '3.8.13-beta' );
34
+ define( 'WPSC_DB_VERSION', 7 );
35
 
36
  // Define Debug Variables for developers
37
  define( 'WPSC_DEBUG', false );
160
  define( 'WPSC_TABLE_VARIATION_VALUES_ASSOC', "{$wp_table_prefix}wpsc_variation_values_assoc" );
161
  define( 'WPSC_TABLE_VARIATION_COMBINATIONS', "{$wp_table_prefix}wpsc_variation_combinations" );
162
  define( 'WPSC_TABLE_REGION_TAX', "{$wp_table_prefix}wpsc_region_tax" );
 
 
163
 
164
+ define( 'WPSC_TABLE_CART_ITEM_META', "{$wp_table_prefix}wpsc_cart_item_meta" );
165
  }
166
 
167
  /**
244
  define( 'WPSC_THEME_BACKUP_URL', $wpsc_urls[8] );
245
  define( 'WPSC_OLD_THEMES_URL', $wpsc_urls[9] );
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  }
248
 
249
  /**
255
  if ( 2 == get_option( 'cart_location' ) )
256
  add_filter( 'the_content', 'wpsc_shopping_cart', 14 );
257
 
258
+ $cart = maybe_unserialize( base64_decode( wpsc_get_customer_meta( 'cart' ) ) );
259
 
260
  if ( is_object( $cart ) && ! is_wp_error( $cart ) )
261
  $GLOBALS['wpsc_cart'] = $cart;
262
  else
263
  $GLOBALS['wpsc_cart'] = new wpsc_cart();
264
+
265
+ $GLOBALS['wpsc_cart']->get_shipping_method();
266
  }
267
 
268
  /***
277
 
278
  // Setup some globals
279
  $wpsc_query_vars = array();
 
 
 
 
 
 
 
 
 
 
 
280
  require_once( WPSC_FILE_PATH . '/wpsc-includes/shipping.helper.php');
281
  $wpec_ash = new ASH();
282
  }
wpsc-core/wpsc-deprecated.php CHANGED
@@ -12,26 +12,6 @@ function wpsc_cart_item_custom_message(){
12
  return false;
13
  }
14
 
15
- /**
16
- * nzshpcrt_get_gateways()
17
- *
18
- * Deprecated function for returning the merchants global
19
- *
20
- * @global array $nzshpcrt_gateways
21
- * @return array
22
- */
23
- function nzshpcrt_get_gateways() {
24
- _wpsc_deprecated_function( __FUNCTION__, '3.8' );
25
-
26
- global $nzshpcrt_gateways;
27
-
28
- if ( !is_array( $nzshpcrt_gateways ) )
29
- wpsc_core_load_gateways();
30
-
31
- return $nzshpcrt_gateways;
32
-
33
- }
34
-
35
  /**
36
  * wpsc_merchants_modules_deprecated()
37
  *
@@ -1341,3 +1321,420 @@ function wpsc_product_variation_price_available( $product_id, $from_text = false
1341
  );
1342
  return wpsc_product_variation_price_from( $product_id, $args );
1343
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  return false;
13
  }
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  /**
16
  * wpsc_merchants_modules_deprecated()
17
  *
1321
  );
1322
  return wpsc_product_variation_price_from( $product_id, $args );
1323
  }
1324
+
1325
+ /**
1326
+ * Deprecated function
1327
+ *
1328
+ * @deprecated 3.8.9
1329
+ */
1330
+ function wpsc_post_title_seo( $title ) {
1331
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.9' );
1332
+ global $wpdb, $page_id, $wp_query;
1333
+ $new_title = wpsc_obtain_the_title();
1334
+ if ( $new_title != '' ) {
1335
+ $title = $new_title;
1336
+ }
1337
+ return esc_html( $title );
1338
+ }
1339
+
1340
+ function wpsc_product_image_forms() {
1341
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13' );
1342
+
1343
+ global $post;
1344
+
1345
+ edit_multiple_image_gallery( $post );
1346
+
1347
+ ?>
1348
+
1349
+ <p><strong <?php if ( isset( $display ) ) echo $display; ?>><a href="media-upload.php?parent_page=wpsc-edit-products&amp;post_id=<?php echo $post->ID; ?>&amp;type=image&amp;tab=gallery&amp;TB_iframe=1&amp;width=640&amp;height=566" class="thickbox" title="<?php esc_attr_e( 'Manage Product Images', 'wpsc' ); ?>"><?php esc_html_e( 'Manage Product Images', 'wpsc' ); ?></a></strong></p>
1350
+ <?php
1351
+ }
1352
+
1353
+ function edit_multiple_image_gallery( $post ) {
1354
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13' );
1355
+
1356
+ global $wpdb;
1357
+
1358
+ // Make sure thumbnail isn't duplicated
1359
+ if ( $post->ID > 0 ) {
1360
+ if ( has_post_thumbnail( $post->ID ) )
1361
+ echo get_the_post_thumbnail( $post->ID, 'admin-product-thumbnails' );
1362
+
1363
+ $args = array(
1364
+ 'post_type' => 'attachment',
1365
+ 'numberposts' => -1,
1366
+ 'post_status' => null,
1367
+ 'post_parent' => $post->ID,
1368
+ 'orderby' => 'menu_order',
1369
+ 'order' => 'ASC'
1370
+ );
1371
+
1372
+ $attached_images = (array)get_posts( $args );
1373
+
1374
+ if ( count( $attached_images ) > 0 ) {
1375
+ foreach ( $attached_images as $images ) {
1376
+ $attached_image = wp_get_attachment_image( $images->ID, 'admin-product-thumbnails' );
1377
+ echo $attached_image. '&nbsp;';
1378
+ }
1379
+ }
1380
+
1381
+ }
1382
+ }
1383
+
1384
+ function wpsc_media_upload_tab_gallery( $tabs ) {
1385
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13' );
1386
+
1387
+ unset( $tabs['gallery'] );
1388
+ $tabs['gallery'] = __( 'Product Image Gallery', 'wpsc' );
1389
+
1390
+ return $tabs;
1391
+ }
1392
+
1393
+ function wpsc_media_upload_url( $form_action_url ) {
1394
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13' );
1395
+
1396
+ $form_action_url = esc_url( add_query_arg( array( 'parent_page'=>'wpsc-edit-products' ) ) );
1397
+
1398
+ return $form_action_url;
1399
+
1400
+ }
1401
+
1402
+ function wpsc_gallery_css_mods() {
1403
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13' );
1404
+
1405
+ print '<style type="text/css">
1406
+ #gallery-settings *{
1407
+ display:none;
1408
+ }
1409
+ a.wp-post-thumbnail {
1410
+ color:green;
1411
+ }
1412
+ #media-upload a.del-link {
1413
+ color:red;
1414
+ }
1415
+ #media-upload a.wp-post-thumbnail {
1416
+ margin-left:0px;
1417
+ }
1418
+ td.savesend input.button {
1419
+ display:none;
1420
+ }
1421
+ </style>';
1422
+ print '
1423
+ <script type="text/javascript">
1424
+ jQuery(function(){
1425
+ jQuery("td.A1B1").each(function(){
1426
+
1427
+ var target = jQuery(this).next();
1428
+ jQuery("p > input.button", this).appendTo(target);
1429
+
1430
+ });
1431
+
1432
+ jQuery("a.wp-post-thumbnail").each(function(){
1433
+ var product_image = jQuery(this).text();
1434
+ if (product_image == "' . __( 'Use as featured image' ) . '") {
1435
+ jQuery(this).text("' . __( 'Use as Product Thumbnail', 'wpsc' ) . '");
1436
+ }
1437
+ });
1438
+ });
1439
+
1440
+ </script>';
1441
+ }
1442
+
1443
+ function wpsc_filter_delete_text( $translation, $text, $domain ) {
1444
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13' );
1445
+
1446
+ if ( 'Delete' == $text && isset( $_REQUEST['post_id'] ) && isset( $_REQUEST['parent_page'] ) ) {
1447
+ $translations = &get_translations_for_domain( $domain );
1448
+ return $translations->translate( 'Trash' ) ;
1449
+ }
1450
+ return $translation;
1451
+ }
1452
+
1453
+ /*
1454
+ * This filter translates string before it is displayed
1455
+ * specifically for the words 'Use as featured image' with 'Use as Product Thumbnail' when the user is selecting a Product Thumbnail
1456
+ * using media gallery.
1457
+ *
1458
+ * @todo As this feature is entirely cosmetic and breaks with WP_DEBUG on in WP 3.5+, we've removed the filter for it. Will revisit the functionality in 3.9 when we look at new media workflows.
1459
+ * @param $translation The current translation
1460
+ * @param $text The text being translated
1461
+ * @param $domain The domain for the translation
1462
+ * @return string The translated / filtered text.
1463
+ */
1464
+ function wpsc_filter_feature_image_text( $translation, $text, $domain ) {
1465
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13' );
1466
+ if ( 'Use as featured image' == $text && isset( $_REQUEST['post_id'] ) ) {
1467
+ $post = get_post( $_REQUEST['post_id'] );
1468
+ if ( $post->post_type != 'wpsc-product' ) return $translation;
1469
+ $translations = &get_translations_for_domain( $domain );
1470
+ return $translations->translate( 'Use as Product Thumbnail', 'wpsc' );
1471
+ //this will never happen, this is here only for gettexr to pick up the translation
1472
+ return __( 'Use as Product Thumbnail', 'wpsc' );
1473
+ }
1474
+
1475
+ return $translation;
1476
+ }
1477
+
1478
+ function wpsc_display_invoice() {
1479
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13' );
1480
+ $purchase_id = (int)$_REQUEST['purchaselog_id'];
1481
+ add_action('wpsc_packing_slip', 'wpsc_packing_slip');
1482
+ do_action('wpsc_before_packing_slip', $purchase_id);
1483
+ do_action('wpsc_packing_slip', $purchase_id);
1484
+ exit();
1485
+ }
1486
+
1487
+ function wpsc_packing_slip( $purchase_id ) {
1488
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13' );
1489
+ echo "<!DOCTYPE html><html><meta http-equiv=\"content-type\" content=\"text-html; charset=utf-8\"><head><title>" . __( 'Packing Slip', 'wpsc' ) . "</title></head><body id='wpsc-packing-slip'>";
1490
+ global $wpdb;
1491
+ $purch_sql = $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`=%d", $purchase_id );
1492
+ $purch_data = $wpdb->get_row( $purch_sql, ARRAY_A ) ;
1493
+
1494
+ $cartsql = $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`=%d", $purchase_id );
1495
+ $cart_log = $wpdb->get_results($cartsql,ARRAY_A) ;
1496
+ $j = 0;
1497
+
1498
+ if($cart_log != null) {
1499
+ echo "<div class='packing_slip'>\n\r";
1500
+ echo apply_filters( 'wpsc_packing_slip_header', '<h2>' . esc_html__( 'Packing Slip', 'wpsc' ) . "</h2>\n\r" );
1501
+ echo "<strong>". esc_html__( 'Order', 'wpsc' )." #</strong> ".$purchase_id."<br /><br />\n\r";
1502
+
1503
+ echo "<table>\n\r";
1504
+
1505
+ $form_sql = $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_SUBMITTED_FORM_DATA."` WHERE `log_id` = %d", $purchase_id );
1506
+ $input_data = $wpdb->get_results($form_sql,ARRAY_A);
1507
+
1508
+ foreach($input_data as $input_row) {
1509
+ $rekeyed_input[$input_row['form_id']] = $input_row;
1510
+ }
1511
+
1512
+
1513
+ if($input_data != null) {
1514
+ $form_data = $wpdb->get_results( "SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `active` = '1' ORDER BY `checkout_order`" , ARRAY_A );
1515
+
1516
+ foreach($form_data as $form_field) {
1517
+
1518
+ switch($form_field['type']) {
1519
+ case 'country':
1520
+ $region_count_sql = $wpdb->prepare( "SELECT COUNT(`regions`.`id`) FROM `".WPSC_TABLE_REGION_TAX."` AS `regions` INNER JOIN `".WPSC_TABLE_CURRENCY_LIST."` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('%s')", $purch_data['billing_country'] );
1521
+ $delivery_region_count = $wpdb->get_var( $region_count_sql );
1522
+
1523
+ if(is_numeric($purch_data['billing_region']) && ($delivery_region_count > 0))
1524
+ echo " <tr><td>".esc_html__('State', 'wpsc').":</td><td>".wpsc_get_region($purch_data['billing_region'])."</td></tr>\n\r";
1525
+
1526
+ echo " <tr><td>" . esc_html( $form_field['name'] ) . ":</td><td>" . esc_html( $rekeyed_input[$form_field['id']]['value'] ) . "</td></tr>\n\r";
1527
+ break;
1528
+
1529
+ case 'delivery_country':
1530
+
1531
+ if(is_numeric($purch_data['shipping_region']) && ($delivery_region_count > 0))
1532
+ echo " <tr><td>".esc_html__('State', 'wpsc').":</td><td>".wpsc_get_region($purch_data['shipping_region'])."</td></tr>\n\r";
1533
+
1534
+ echo " <tr><td>" . esc_html( $form_field['name'] ) . ":</td><td>" . esc_html( $rekeyed_input[ $form_field['id']]['value'] ) . "</td></tr>\n\r";
1535
+ break;
1536
+
1537
+ case 'heading':
1538
+
1539
+ if($form_field['name'] == "Hidden Fields")
1540
+ continue;
1541
+ else
1542
+ echo " <tr class='heading'><td colspan='2'><strong>" . esc_html( $form_field['name'] ) . ":</strong></td></tr>\n\r";
1543
+ break;
1544
+
1545
+ default:
1546
+ if ($form_field['name']=="State" && !empty($purch_data['billing_region']) || $form_field['name']=="State" && !empty($purch_data['billing_region']))
1547
+ echo "";
1548
+ else
1549
+ echo " <tr><td>" . esc_html( $form_field['name'] ) . ":</td><td>".
1550
+ ( isset( $rekeyed_input[$form_field['id']] ) ? esc_html( $rekeyed_input[$form_field['id']]['value'] ) : '' ) .
1551
+ "</td></tr>\n\r";
1552
+ break;
1553
+ }
1554
+
1555
+ }
1556
+ } else {
1557
+ echo " <tr><td>".esc_html__('Name', 'wpsc').":</td><td>".$purch_data['firstname']." ".$purch_data['lastname']."</td></tr>\n\r";
1558
+ echo " <tr><td>".esc_html__('Address', 'wpsc').":</td><td>".$purch_data['address']."</td></tr>\n\r";
1559
+ echo " <tr><td>".esc_html__('Phone', 'wpsc').":</td><td>".$purch_data['phone']."</td></tr>\n\r";
1560
+ echo " <tr><td>".esc_html__('Email', 'wpsc').":</td><td>".$purch_data['email']."</td></tr>\n\r";
1561
+ }
1562
+
1563
+ if ( 2 == get_option( 'payment_method' ) ) {
1564
+ $gateway_name = '';
1565
+ global $nzshpcrt_gateways;
1566
+
1567
+ foreach( $nzshpcrt_gateways as $gateway ) {
1568
+ if ( $purch_data['gateway'] != 'testmode' ) {
1569
+ if ( $gateway['internalname'] == $purch_data['gateway'] ) {
1570
+ $gateway_name = $gateway['name'];
1571
+ }
1572
+ } else {
1573
+ $gateway_name = esc_html__('Manual Payment', 'wpsc');
1574
+ }
1575
+ }
1576
+ }
1577
+
1578
+ echo "</table>\n\r";
1579
+
1580
+
1581
+ do_action ('wpsc_packing_slip_extra_info',$purchase_id);
1582
+
1583
+
1584
+ echo "<table class='packing_slip'>";
1585
+
1586
+ echo "<tr>";
1587
+ echo " <th>".esc_html__('Quantity', 'wpsc')." </th>";
1588
+
1589
+ echo " <th>".esc_html__('Name', 'wpsc')."</th>";
1590
+
1591
+
1592
+ echo " <th>".esc_html__('Price', 'wpsc')." </th>";
1593
+
1594
+ echo " <th>".esc_html__('Shipping', 'wpsc')." </th>";
1595
+ echo '<th>' . esc_html__('Tax', 'wpsc') . '</th>';
1596
+ echo '</tr>';
1597
+ $endtotal = 0;
1598
+ $all_donations = true;
1599
+ $all_no_shipping = true;
1600
+ $file_link_list = array();
1601
+ $total_shipping = 0;
1602
+ foreach($cart_log as $cart_row) {
1603
+ $alternate = "";
1604
+ $j++;
1605
+ if(($j % 2) != 0) {
1606
+ $alternate = "class='alt'";
1607
+ }
1608
+ // product ID will be $cart_row['prodid']. need to fetch name and stuff
1609
+
1610
+ $variation_list = '';
1611
+
1612
+ if($cart_row['donation'] != 1) {
1613
+ $all_donations = false;
1614
+ }
1615
+
1616
+ if($cart_row['no_shipping'] != 1) {
1617
+ $shipping = $cart_row['pnp'];
1618
+ $total_shipping += $shipping;
1619
+ $all_no_shipping = false;
1620
+ } else {
1621
+ $shipping = 0;
1622
+ }
1623
+
1624
+ $price = $cart_row['price'] * $cart_row['quantity'];
1625
+ $gst = $price - ($price / (1+($cart_row['gst'] / 100)));
1626
+
1627
+ if($gst > 0) {
1628
+ $tax_per_item = $gst / $cart_row['quantity'];
1629
+ }
1630
+
1631
+
1632
+ echo "<tr $alternate>";
1633
+
1634
+
1635
+ echo " <td>";
1636
+ echo $cart_row['quantity'];
1637
+ echo " </td>";
1638
+
1639
+ echo " <td>";
1640
+ echo apply_filters( 'the_title', $cart_row['name'] );
1641
+ echo $variation_list;
1642
+ echo " </td>";
1643
+
1644
+
1645
+ echo " <td>";
1646
+ echo wpsc_currency_display( $price );
1647
+ echo " </td>";
1648
+
1649
+ echo " <td>";
1650
+ echo wpsc_currency_display($shipping );
1651
+ echo " </td>";
1652
+
1653
+
1654
+
1655
+ echo '<td>';
1656
+ echo wpsc_currency_display( $cart_row['tax_charged'] );
1657
+ echo '</td>';
1658
+ echo '</tr>';
1659
+ }
1660
+
1661
+ echo "</table>";
1662
+ echo '<table class="packing-slip-totals">';
1663
+ if ( floatval( $purch_data['discount_value'] ) )
1664
+ echo '<tr><th>'.esc_html__('Discount', 'wpsc').'</th><td>(' . wpsc_currency_display( $purch_data['discount_value'] ) . ')</td></tr>';
1665
+
1666
+ echo '<tr><th>'.esc_html__('Base Shipping','wpsc').'</th><td>' . wpsc_currency_display( $purch_data['base_shipping'] ) . '</td></tr>';
1667
+ echo '<tr><th>'.esc_html__('Total Shipping','wpsc').'</th><td>' . wpsc_currency_display( $purch_data['base_shipping'] + $total_shipping ) . '</td></tr>';
1668
+ //wpec_taxes
1669
+ if($purch_data['wpec_taxes_total'] != 0.00)
1670
+ {
1671
+ echo '<tr><th>'.esc_html__('Taxes','wpsc').'</th><td>' . wpsc_currency_display( $purch_data['wpec_taxes_total'] ) . '</td></tr>';
1672
+ }
1673
+ echo '<tr><th>'.esc_html__('Total Price','wpsc').'</th><td>' . wpsc_currency_display( $purch_data['totalprice'] ) . '</td></tr>';
1674
+ echo '</table>';
1675
+
1676
+ echo "</div>\n\r";
1677
+ } else {
1678
+ echo "<br />".esc_html__('This users cart was empty', 'wpsc');
1679
+ }
1680
+ }
1681
+
1682
+ //other actions are here
1683
+ if ( isset( $_GET['display_invoice'] ) && ( 'true' == $_GET['display_invoice'] ) )
1684
+ add_action( 'admin_init', 'wpsc_display_invoice', 0 );
1685
+
1686
+ if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc_display_invoice' == $_REQUEST['wpsc_admin_action'] ) )
1687
+ add_action( 'admin_init', 'wpsc_display_invoice' );
1688
+
1689
+
1690
+ /**
1691
+ * Disable SSL validation for Curl. Added/removed on a per need basis, like so:
1692
+ *
1693
+ * add_filter('http_api_curl', 'wpsc_curl_ssl');
1694
+ * remove_filter('http_api_curl', 'wpsc_curl_ssl');
1695
+ *
1696
+ * @param resource $ch
1697
+ * @return resource $ch
1698
+ **/
1699
+ function wpsc_curl_ssl( $ch ) {
1700
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13', __( "add_filter( 'https_ssl_verify', '__return_false' )", 'wpsc' ) );
1701
+
1702
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1703
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
1704
+ return $ch;
1705
+ }
1706
+
1707
+
1708
+ /**
1709
+ * Get cart item meta
1710
+ * @access public
1711
+ *
1712
+ * @deprecated since 3.8.13
1713
+ */
1714
+ function wpsc_get_cartmeta( $cart_item_id, $meta_key ) {
1715
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13', 'wpsc_get_cart_item_meta');
1716
+ return wpsc_get_cart_item_meta( $cart_item_id, $meta_key, true );
1717
+ }
1718
+
1719
+ /**
1720
+ * Update cart item meta
1721
+ * @access public
1722
+ *
1723
+ * @deprecated since 3.8.13
1724
+ */
1725
+ function wpsc_update_cartmeta( $cart_item_id, $meta_key, $meta_value ) {
1726
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13', 'wpsc_update_cart_item_meta');
1727
+ return wpsc_update_cart_item_meta( $cart_item_id, $meta_key, $meta_value );
1728
+ }
1729
+
1730
+ /**
1731
+ * Delete cart item meta
1732
+ * @access public
1733
+ *
1734
+ * @deprecated since 3.8.13
1735
+ */
1736
+ function wpsc_delete_cartmeta( $cart_item_id, $meta_key, $meta_value = '' ) {
1737
+ _wpsc_deprecated_function( __FUNCTION__, '3.8.13', 'wpsc_delete_cart_item_meta');
1738
+ return wpsc_delete_cart_item_meta( $cart_item_id, $meta_key, $meta_value );
1739
+ }
1740
+
wpsc-core/wpsc-functions.php CHANGED
@@ -10,7 +10,8 @@
10
  * @since 3.8
11
  */
12
 
13
- add_filter( 'term_name', 'wpsc_term_list_levels', 10, 2 );
 
14
 
15
  /**
16
  * When doing variation and product category drag&drop sort, we want to restrict
@@ -66,58 +67,6 @@ function wpsc_print_term_list_levels_script() {
66
  <?php
67
  }
68
 
69
- add_filter( 'intermediate_image_sizes_advanced', 'wpsc_intermediate_image_sizes_advanced', 10, 1 );
70
-
71
- function wpsc_intermediate_image_sizes_advanced($sizes){
72
- $sizes['small-product-thumbnail']=array(
73
- "width" => get_option( 'product_image_width' ),
74
- "height" => get_option( 'product_image_height' ),
75
- "crop" => get_option( 'wpsc_crop_thumbnails', false )
76
- );
77
- $sizes['medium-single-product']=array(
78
- "width" => get_option( 'single_view_image_width' ),
79
- "height" => get_option( 'single_view_image_height' ),
80
- "crop" => get_option( 'wpsc_crop_thumbnails', false )
81
- );
82
- $sizes['featured-product-thumbnails']=array(
83
- "width" => 425,
84
- "height" => 215,
85
- "crop" => get_option( 'wpsc_crop_thumbnails', true )
86
- );
87
- $sizes['admin-product-thumbnails']=array(
88
- "width" => 38,
89
- "height" => 38,
90
- "crop" => get_option( 'wpsc_crop_thumbnails', true )
91
- );
92
- $sizes['product-thumbnails']=array(
93
- "width" => get_option( 'product_image_width' ),
94
- "height" => get_option( 'product_image_height' ),
95
- "crop" => get_option( 'wpsc_crop_thumbnails', false )
96
- );
97
- $sizes['gold-thumbnails']=array(
98
- "width" => get_option( 'wpsc_gallery_image_width' ),
99
- "height" => get_option( 'wpsc_gallery_image_height' ),
100
- "crop" => get_option( 'wpsc_crop_thumbnails', false )
101
- );
102
- return $sizes;
103
- }
104
-
105
- /**
106
- *
107
- * wpsc_core_load_thumbnail_sizes()
108
- *
109
- * Load up the WPEC core thumbnail sizes
110
- * @todo Remove hardcoded sizes
111
- */
112
- function wpsc_core_load_thumbnail_sizes() {
113
- // Add image sizes for products
114
- add_image_size( 'product-thumbnails', get_option( 'product_image_width' ), get_option( 'product_image_height' ), get_option( 'wpsc_crop_thumbnails', false ) );
115
- add_image_size( 'gold-thumbnails', get_option( 'wpsc_gallery_image_width' ), get_option( 'wpsc_gallery_image_height' ), get_option( 'wpsc_crop_thumbnails', false ) );
116
- add_image_size( 'admin-product-thumbnails', 38, 38, get_option( 'wpsc_crop_thumbnails', true ) );
117
- add_image_size( 'featured-product-thumbnails', 425, 215, get_option( 'wpsc_crop_thumbnails', true ) );
118
- add_image_size( 'small-product-thumbnail', get_option( 'product_image_width' ), get_option( 'product_image_height' ), get_option( 'wpsc_crop_thumbnails', false ) );
119
- add_image_size( 'medium-single-product', get_option( 'single_view_image_width' ), get_option( 'single_view_image_height' ), get_option( 'wpsc_crop_thumbnails', false) );
120
- }
121
  /**
122
  * wpsc_core_load_checkout_data()
123
  *
@@ -214,21 +163,6 @@ function wpsc_core_load_purchase_log_statuses() {
214
  $wpsc_purchlog_statuses = apply_filters('wpsc_set_purchlog_statuses',$wpsc_purchlog_statuses);
215
  }
216
 
217
- /**
218
- * wpsc_core_load_page_titles()
219
- *
220
- * Load the WPEC page titles
221
- *
222
- * @global array $wpsc_page_titles
223
- */
224
- function wpsc_core_load_page_titles() {
225
- global $wpsc_page_titles;
226
- $wpsc_page_titles = apply_filters( 'wpsc_page_titles', false );
227
-
228
- if ( empty( $wpsc_page_titles ) )
229
- $wpsc_page_titles = wpsc_get_page_post_names();
230
- }
231
-
232
  /***
233
  * wpsc_core_load_gateways()
234
  *
@@ -271,7 +205,7 @@ function wpsc_core_load_gateways() {
271
  * the shipping directory for modules.
272
  */
273
  function wpsc_core_load_shipping_modules() {
274
- global $wpsc_shipping_modules, $wpsc_cart;
275
 
276
  $shipping_directory = WPSC_FILE_PATH . '/wpsc-shipping';
277
  $nzshpcrt_shipping_list = wpsc_list_dir( $shipping_directory );
@@ -284,7 +218,20 @@ function wpsc_core_load_shipping_modules() {
284
 
285
  $wpsc_shipping_modules = apply_filters( 'wpsc_shipping_modules', $wpsc_shipping_modules );
286
 
287
- if ( ! get_option( 'do_not_use_shipping' ) && empty( $wpsc_cart->selected_shipping_method ) )
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  $wpsc_cart->get_shipping_method();
289
  }
290
 
@@ -486,46 +433,6 @@ function wpsc_post_updated_messages( $messages ) {
486
  }
487
  add_filter( 'post_updated_messages', 'wpsc_post_updated_messages' );
488
 
489
- function wpsc_check_thumbnail_support() {
490
- if ( !current_theme_supports( 'post-thumbnails' ) ) {
491
- add_theme_support( 'post-thumbnails' );
492
- add_action( 'init', 'wpsc_remove_post_type_thumbnail_support' );
493
- }
494
- }
495
- add_action( 'after_setup_theme', 'wpsc_check_thumbnail_support', 99 );
496
-
497
- function wpsc_remove_post_type_thumbnail_support() {
498
- remove_post_type_support( 'post', 'thumbnail' );
499
- remove_post_type_support( 'page', 'thumbnail' );
500
- }
501
-
502
- function wpsc_filter_request( $q ) {
503
- if ( empty( $q['wpsc-product'] ) )
504
- return $q;
505
-
506
- $components = explode( '/', $q['wpsc-product'] );
507
- $end_node = array_pop( $components );
508
- $parent_node = array_pop( $components );
509
-
510
- $posts = get_posts( array(
511
- 'post_type' => 'wpsc-product',
512
- 'name' => $end_node,
513
- ) );
514
-
515
- if ( ! empty( $posts ) ) {
516
- $q['wpsc-product'] = $q['name'] = $end_node;
517
- if ( !empty( $parent_node ) )
518
- $q['wpsc_product_category'] = $parent_node;
519
- } else {
520
- $q['wpsc_product_category'] = $end_node;
521
- unset( $q['name'] );
522
- unset( $q['wpsc-product'] );
523
- }
524
- return $q;
525
- }
526
-
527
- if ( get_option( 'product_category_hierarchical_url' ) )
528
- add_filter( 'request', 'wpsc_filter_request' );
529
 
530
  /**
531
  * This serializes the shopping cart variable as a backup in case the
@@ -534,6 +441,9 @@ if ( get_option( 'product_category_hierarchical_url' ) )
534
  function wpsc_serialize_shopping_cart() {
535
  global $wpdb, $wpsc_start_time, $wpsc_cart;
536
 
 
 
 
537
  // avoid flooding transients with bots hitting feeds
538
  if ( is_feed() ) {
539
  wpsc_delete_all_customer_meta();
@@ -547,919 +457,28 @@ function wpsc_serialize_shopping_cart() {
547
  // because by now, some output must have been printed out
548
  $customer_id = wpsc_get_current_customer_id();
549
  if ( $customer_id )
550
- wpsc_update_customer_meta( 'cart', serialize( $wpsc_cart ) );
551
 
552
  return true;
553
  }
554
  add_action( 'shutdown', 'wpsc_serialize_shopping_cart' );
555
 
556
- add_filter( 'request', 'wpsc_filter_query_request' );
557
-
558
- /**
559
- * Fixes for some inconsistencies about $wp_query when viewing WPEC pages.
560
- *
561
- * Causes the following URLs to work (with pagination enabled):
562
- *
563
- * /products-page/ (product listing)
564
- * /products-page/car-audio/ (existing product category)
565
- * /products-page/car-audio/page/2/ (existing product category, page 2)
566
- * /products-page/page/2/ (product listing, page 2)
567
- * /products-page/checkout/ (existing built-in sub page)
568
- * /products-page/anotherpage/ (another sub page that may exist)
569
- *
570
- * @param string $q Query String
571
- */
572
- function wpsc_filter_query_request( $args ) {
573
- global $wpsc_page_titles;
574
- if ( is_admin() )
575
- return $args;
576
-
577
- $is_sub_page = ! empty( $args['wpsc_product_category'] )
578
- && 'page' != $args['wpsc_product_category']
579
- && ! term_exists( $args['wpsc_product_category'], 'wpsc_product_category' );
580
-
581
- // Make sure no 404 error is thrown for any sub pages of products-page
582
- if ( $is_sub_page ) {
583
- // Probably requesting a page that is a sub page of products page
584
- $pagename = "{$wpsc_page_titles['products']}/{$args['wpsc_product_category']}";
585
- if ( isset($args['name']) ) {
586
- $pagename .= "/{$args['name']}";
587
- }
588
- $args = array();
589
- $args['pagename'] = $pagename;
590
- }
591
-
592
- // When product page is set to display all products or a category, and pagination is enabled, $wp_query is messed up
593
- // and is_home() is true. This fixes that.
594
- $needs_pagination_fix = isset( $args['post_type'] )
595
- && ! empty( $args['wpsc_product_category'] )
596
- && 'wpsc-product' == $args['post_type']
597
- && ! empty( $args['wpsc-product'] )
598
- && 'page' == $args['wpsc_product_category'];
599
- if ( $needs_pagination_fix ) {
600
- $default_category = get_option( 'wpsc_default_category' );
601
- if ( $default_category == 'all' || $default_category != 'list' ) {
602
- $page = $args['wpsc-product'];
603
- $args = array();
604
- $args['pagename'] = "{$wpsc_page_titles['products']}";
605
- $args['page'] = $page;
606
- }
607
- }
608
- return $args;
609
- }
610
-
611
- function _wpsc_menu_exists( $args ) {
612
- $args = (object) $args;
613
- // Get the nav menu based on the requested menu
614
- $menu = wp_get_nav_menu_object( $args->menu );
615
-
616
- // Get the nav menu based on the theme_location
617
- if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) )
618
- $menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
619
-
620
- // get the first menu that has items if we still can't find a menu
621
- if ( ! $menu && ! $args->theme_location ) {
622
- $menus = wp_get_nav_menus();
623
- foreach ( $menus as $menu_maybe ) {
624
- if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id ) ) {
625
- $menu = $menu_maybe;
626
- break;
627
- }
628
- }
629
- }
630
-
631
- // If the menu exists, get its items.
632
- if ( $menu && ! is_wp_error( $menu ) && ! isset( $menu_items ) )
633
- $menu_items = wp_get_nav_menu_items( $menu->term_id );
634
-
635
- // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists
636
- if ( ( ! $menu || is_wp_error( $menu ) || ( isset( $menu_items ) && empty( $menu_items ) && ! $args->theme_location ) ) )
637
- return false;
638
-
639
- // If no fallback function was specified and the menu doesn't exists, bail.
640
- if ( ! $menu || is_wp_error( $menu ) || empty( $menu_items ) )
641
- return false;
642
-
643
- return (bool) $menu;
644
- }
645
-
646
- function _wpsc_switch_the_query( $stuff = '' ) {
647
- global $wp_query, $wpsc_query;
648
- list( $wp_query, $wpsc_query ) = array( $wpsc_query, $wp_query );
649
- return $stuff;
650
- }
651
-
652
- /**
653
- * Switch $wp_query and $wpsc_query when outputting the navigation menu, but only if we're on a product
654
- * category page.
655
- *
656
- * We need to do this because the function _wp_menu_item_classes_by_context(), which generates classes
657
- * for menu items, depends on $wp_query. As a result, without this fix, when viewing a product category
658
- * page, the corresponding product category menu item will not be highlighted.
659
- *
660
- * Because there are no action hooks in wp_nav_menu(), we have to use two filters that are applied at
661
- * the beginning and the end of the function.
662
- *
663
- * @param mixed $stuff
664
- * @return mixed
665
- */
666
- function wpsc_switch_the_query( $args ) {
667
- global $wp_query, $wpsc_query;
668
- $qv = $wpsc_query->query_vars;
669
- if ( ! empty( $qv['wpsc_product_category'] ) && ! empty( $qv['taxonomy'] ) && ! empty( $qv['term'] ) && ! is_single() && _wpsc_menu_exists( $args ) ) {
670
- _wpsc_switch_the_query();
671
- add_filter( 'wp_nav_menu', '_wpsc_switch_the_query', 99 );
672
- }
673
- return $args;
674
- }
675
-
676
- // switch $wp_query and $wpsc_query at the beginning and the end of wp_nav_menu()
677
- add_filter( 'wp_nav_menu_args', 'wpsc_switch_the_query', 99 );
678
-
679
- function _wpsc_pre_get_posts_reset_taxonomy_globals( $query ) {
680
- global $wp_the_query;
681
-
682
- if ( is_admin() || $query !== $wp_the_query )
683
- return;
684
-
685
- if ( ! $query->get( 'page' ) && ! $query->get( 'paged' ) )
686
- return;
687
-
688
- if ( ! get_option( 'use_pagination' ) )
689
- return;
690
-
691
- if ( ! is_page( wpsc_get_the_post_id_by_shortcode( '[productspage]' ) ) && ! $query->get( 'wpsc_product_category' ) )
692
- return;
693
-
694
- $query->set( 'posts_per_page', get_option( 'wpsc_products_per_page' ) );
695
-
696
- $post_type_object = get_post_type_object( 'wpsc-product' );
697
-
698
- if ( current_user_can( $post_type_object->cap->edit_posts ) )
699
- $query->set( 'post_status', 'private,draft,pending,publish' );
700
- else
701
- $query->set( 'post_status', 'publish' );
702
- }
703
- add_action( 'pre_get_posts', '_wpsc_pre_get_posts_reset_taxonomy_globals', 1 );
704
-
705
- /**
706
- * wpsc_start_the_query
707
- */
708
- function wpsc_start_the_query() {
709
- global $wpsc_page_titles, $wp_query, $wpsc_query, $wpsc_query_vars;
710
-
711
- $is_404 = false;
712
- if ( null == $wpsc_query ) {
713
- if( ( $wp_query->is_404 && !empty($wp_query->query_vars['paged']) ) || (isset( $wp_query->query['pagename']) && strpos( $wp_query->query['pagename'] , $wpsc_page_titles['products'] ) !== false ) && !isset($wp_query->post)){
714
- global $post;
715
- $is_404 = true;
716
- if( !isset( $wp_query->query_vars['wpsc_product_category'] ) && ! isset( $wp_query->query_vars['product_tag'] ) )
717
- $wp_query = new WP_Query('post_type=wpsc-product&name='.$wp_query->query_vars['name']);
718
-
719
- if(isset($wp_query->post->ID))
720
- $post = $wp_query->post;
721
- else
722
- $wpsc_query_vars['wpsc_product_category'] = $wp_query->query_vars['name'];
723
- }
724
- if ( count( $wpsc_query_vars ) <= 1 ) {
725
- $post_type_object = get_post_type_object( 'wpsc-product' );
726
- $wpsc_query_vars = array(
727
- 'post_status' => apply_filters( 'wpsc_product_display_status', array( 'publish' ) ),
728
- 'post_parent' => 0,
729
- 'order' => apply_filters( 'wpsc_product_order', get_option( 'wpsc_product_order', 'ASC' ) )
730
- );
731
- if($wp_query->query_vars['preview'])
732
- $wpsc_query_vars['post_status'] = 'any';
733
-
734
- if( isset( $_GET['product_order'] ) )
735
- $wpsc_query_vars['order'] = $_GET['product_order'];
736
-
737
- if(isset($wp_query->query_vars['product_tag'])){
738
- $wpsc_query_vars['product_tag'] = $wp_query->query_vars['product_tag'];
739
- $wpsc_query_vars['taxonomy'] = get_query_var( 'taxonomy' );
740
- $wpsc_query_vars['term'] = get_query_var( 'term' );
741
- }elseif( isset($wp_query->query_vars['wpsc_product_category']) ){
742
- $wpsc_query_vars['wpsc_product_category'] = $wp_query->query_vars['wpsc_product_category'];
743
- $wpsc_query_vars['taxonomy'] = get_query_var( 'taxonomy' );
744
- $wpsc_query_vars['term'] = get_query_var( 'term' );
745
- }else{
746
- $wpsc_query_vars['post_type'] = 'wpsc-product';
747
- $wpsc_query_vars['pagename'] = wpsc_get_page_slug( '[productspage]' );
748
- }
749
- if(1 == get_option('use_pagination')){
750
- $wpsc_query_vars['nopaging'] = false;
751
-
752
- $wpsc_query_vars['posts_per_page'] = get_option('wpsc_products_per_page');
753
-
754
- $wpsc_query_vars['paged'] = get_query_var('paged');
755
- if(isset($wpsc_query_vars['paged']) && empty($wpsc_query_vars['paged'])){
756
- $wpsc_query_vars['paged'] = get_query_var('page');
757
-
758
- }
759
-
760
- }
761
-
762
- $orderby = ( isset( $_GET['product_order'] ) ) ? 'title' : null;
763
- $wpsc_query_vars = array_merge( $wpsc_query_vars, wpsc_product_sort_order_query_vars($orderby) );
764
-
765
- add_filter( 'pre_get_posts', 'wpsc_generate_product_query', 11 );
766
-
767
- $wpsc_query = new WP_Query( $wpsc_query_vars );
768
-
769
- //for 3.1 :|
770
- if(empty($wpsc_query->posts) && isset($wpsc_query->tax_query) && isset($wp_query->query_vars['wpsc_product_category'])){
771
- $wpsc_query_vars = array();
772
- $wpsc_query_vars['wpsc_product_category'] = $wp_query->query_vars['wpsc_product_category'];
773
- if(1 == get_option('use_pagination')){
774
- $wpsc_query_vars['posts_per_page'] = get_option('wpsc_products_per_page');
775
- $wpsc_query_vars['paged'] = get_query_var('paged');
776
- if(empty($wpsc_query_vars['paged']))
777
- $wpsc_query_vars['paged'] = get_query_var('page');
778
- }
779
- $wpsc_query = new WP_Query( $wpsc_query_vars );
780
-
781
- }
782
- }
783
- }
784
-
785
- if( $is_404 || ( ( isset($wpsc_query->post_count) && $wpsc_query->post_count == 0 ) && isset($wpsc_query_vars['wpsc_product_category'] ) )){
786
-
787
- $args = array_merge($wp_query->query, array('posts_per_page' => get_option('wpsc_products_per_page')));
788
- $wp_query = new WP_Query($args);
789
-
790
- if( empty( $wp_query->posts ) ){
791
- $product_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
792
- $wp_query = new WP_Query( 'page_id='.$product_page_id);
793
- }
794
- }
795
- if ( isset( $wp_query->post->ID ) )
796
- $post_id = $wp_query->post->ID;
797
- else
798
- $post_id = 0;
799
-
800
- if ( get_permalink( $post_id ) == get_option( 'shopping_cart_url' ) )
801
- $_SESSION['wpsc_has_been_to_checkout'] = true;
802
- }
803
- add_action( 'template_redirect', 'wpsc_start_the_query', 8 );
804
-
805
- /**
806
- * Obtain the necessary product sort order query variables based on the specified product sort order.
807
- * If no sort order is specified, the sort order configured in Dashboard -> Settings -> Store -> Presentation -> 'Sort Product By' is used.
808
- *
809
- * @param string $orderby optional product sort order
810
- * @return array Array of query variables
811
- */
812
- function wpsc_product_sort_order_query_vars( $orderby = null ) {
813
- if ( is_null($orderby) )
814
- $orderby = get_option( 'wpsc_sort_by' );
815
-
816
- $query_vars = array();
817
-
818
- switch ( $orderby ) {
819
-
820
- case "dragndrop":
821
- $query_vars["orderby"] = 'menu_order';
822
- break;
823
-
824
- case "name":
825
- $query_vars["orderby"] = 'title';
826
- break;
827
-
828
- //This only works in WP 3.0.
829
- case "price":
830
- add_filter( 'posts_join', 'wpsc_add_meta_table' );
831
- add_filter( 'posts_where', 'wpsc_add_meta_table_where' );
832
- $query_vars["meta_key"] = '_wpsc_price';
833
- $query_vars["orderby"] = 'meta_value_num';
834
- break;
835
-
836
- case "id":
837
- $query_vars["orderby"] = 'ID';
838
- break;
839
- default:
840
- // Allow other WordPress 'ordery' values as defined in http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
841
- $query_vars["orderby"] = $orderby;
842
- break;
843
- }
844
- return $query_vars;
845
- }
846
-
847
-
848
- /**
849
- * add meta table where section for ordering by price
850
- *
851
- */
852
- function wpsc_add_meta_table_where($where){
853
- global $wpdb;
854
-
855
- remove_filter( 'posts_where', 'wpsc_add_meta_table_where' );
856
-
857
- return $where . ' AND ' . $wpdb->postmeta . '.meta_key = "_wpsc_price"';
858
- }
859
-
860
- /**
861
- * add meta table join section for ordering by price
862
- *
863
- */
864
- function wpsc_add_meta_table($join){
865
- global $wpdb;
866
- remove_filter( 'posts_join', 'wpsc_add_meta_table' );
867
- if(strpos($join, "INNER JOIN ON (".$wpdb->posts.".ID = ".$wpdb->postmeta.".post_id)") !== false){
868
- return ' JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts. '.ID = ' . $wpdb->postmeta . '.post_id';
869
- }else{
870
- return $join;
871
- }
872
- }
873
-
874
- /**
875
- * wpsc_taxonomy_rewrite_rules function.
876
- * Adds in new rewrite rules for categories, products, category pages, and ambiguities (either categories or products)
877
- * Also modifies the rewrite rules for product URLs to add in the post type.
878
- *
879
- * @since 3.8
880
- * @access public
881
- * @param array $rewrite_rules
882
- * @return array - the modified rewrite rules
883
- */
884
- function wpsc_taxonomy_rewrite_rules( $rewrite_rules ) {
885
- global $wpsc_page_titles;
886
- $products_page = $wpsc_page_titles['products'];
887
- $checkout_page = $wpsc_page_titles['checkout'];
888
- $target_string = "index.php?product";
889
- $replacement_string = "index.php?post_type=wpsc-product&product";
890
- $target_rule_set_query_var = 'products';
891
-
892
- $target_rule_set = array( );
893
- foreach ( $rewrite_rules as $rewrite_key => $rewrite_query ) {
894
- if ( stristr( $rewrite_query, "index.php?product" ) ) {
895
- $rewrite_rules[$rewrite_key] = str_replace( $target_string, $replacement_string, $rewrite_query );
896
- }
897
- if ( stristr( $rewrite_query, "$target_rule_set_query_var=" ) ) {
898
- $target_rule_set[] = $rewrite_key;
899
- }
900
- }
901
-
902
- $new_rewrite_rules[$products_page . '/(.+?)/product/([^/]+)/comment-page-([0-9]{1,})/?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&name=$matches[2]&cpage=$matches[3]';
903
- $new_rewrite_rules[$products_page . '/(.+?)/product/([^/]+)/?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&name=$matches[2]';
904
- $new_rewrite_rules[$products_page . '/(.+?)/([^/]+)/comment-page-([0-9]{1,})/?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&wpsc_item=$matches[2]&cpage=$matches[3]';
905
- $new_rewrite_rules[$products_page . '/(.+?)/([^/]+)?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&wpsc_item=$matches[2]';
906
-
907
- $last_target_rule = array_pop( $target_rule_set );
908
-
909
- $rebuilt_rewrite_rules = array( );
910
- foreach ( $rewrite_rules as $rewrite_key => $rewrite_query ) {
911
- if ( $rewrite_key == $last_target_rule ) {
912
- $rebuilt_rewrite_rules = array_merge( $rebuilt_rewrite_rules, $new_rewrite_rules );
913
- }
914
- $rebuilt_rewrite_rules[$rewrite_key] = $rewrite_query;
915
- }
916
-
917
- // fix pagination issue with product category hirarchical URL
918
- if ( get_option( 'product_category_hierarchical_url', false ) ) {
919
- $rule = $rebuilt_rewrite_rules[$products_page . '/(.+?)/page/?([0-9]{1,})/?$'];
920
- unset( $rebuilt_rewrite_rules[$products_page . '/(.+?)/page/?([0-9]{1,})/?$'] );
921
- $rebuilt_rewrite_rules = array_merge(
922
- array(
923
- '(' . $products_page . ')/page/([0-9]+)/?' => 'index.php?pagename=$matches[1]&page=$matches[2]',
924
- $products_page . '/(.+?)(/.+?)?/page/?([0-9]{1,})/?$' => 'index.php?wpsc_product_category=$matches[1]&wpsc-product=$matches[2]&page=$matches[3]',
925
- ),
926
- $rebuilt_rewrite_rules
927
- );
928
- }
929
-
930
- // fix pagination in WordPress 3.4
931
- if ( version_compare( get_bloginfo( 'version' ), '3.4', '>=' ) ) {
932
- $rebuilt_rewrite_rules = array_merge(
933
- array(
934
- '(' . $products_page . ')/([0-9]+)/?$' => 'index.php?pagename=$matches[1]&page=$matches[2]',
935
- ),
936
- $rebuilt_rewrite_rules
937
- );
938
- }
939
- return $rebuilt_rewrite_rules;
940
- }
941
-
942
- add_filter( 'rewrite_rules_array', 'wpsc_taxonomy_rewrite_rules' );
943
-
944
- /**
945
- * wpsc_query_vars function.
946
- * adds in the post_type and wpsc_item query vars
947
- *
948
- * @since 3.8
949
- * @access public
950
- * @param mixed $vars
951
- * @return void
952
- */
953
- function wpsc_query_vars( $vars ) {
954
- // post_type is used to specify that we are looking for products
955
- $vars[] = "post_type";
956
- // wpsc_item is used to find items that could be either a product or a product category, it defaults to category, then tries products
957
- $vars[] = "wpsc_item";
958
- return $vars;
959
- }
960
-
961
- add_filter( 'query_vars', 'wpsc_query_vars' );
962
-
963
- /**
964
- * wpsc_query_modifier function.
965
- *
966
- * @since 3.8
967
- * @access public
968
- * @param object - reference to $wp_query
969
- * @return $query
970
- */
971
- function wpsc_split_the_query( $query ) {
972
- global $wpsc_page_titles, $wpsc_query, $wpsc_query_vars;
973
- // These values are to be dynamically defined
974
- $products_page = $wpsc_page_titles['products'];
975
- $checkout_page = $wpsc_page_titles['checkout'];
976
- $userlog_page = $wpsc_page_titles['userlog'];
977
- $transaction_results_page = $wpsc_page_titles['transaction_results'];
978
-
979
- // otherwise, check if we are looking at a product, if so, duplicate the query and swap the old one out for a products page request
980
- // JS - 6.4.1020 - Added is_admin condition, as the products condition broke categories in backend
981
- if ( !empty($query->query_vars['pagename']) && ($query->query_vars['pagename'] == $products_page) || isset( $query->query_vars['products'] ) && !is_admin() ) {
982
- // store a copy of the wordpress query
983
- $wpsc_query_data = $query->query;
984
-
985
- // wipe and replace the query vars
986
- $query->query = array();
987
- $query->query['pagename'] = "$products_page";
988
- $query->query_vars['pagename'] = "$products_page";
989
- $query->query_vars['name'] = '';
990
- $query->query_vars['post_type'] = '';
991
-
992
- $query->queried_object = & get_page_by_path( $query->query['pagename'] );
993
-
994
- if ( !empty( $query->queried_object ) )
995
- $query->queried_object_id = (int)$query->queried_object->ID;
996
- else
997
- unset( $query->queried_object );
998
-
999
- unset( $query->query_vars['products'] );
1000
- unset( $query->query_vars['name'] );
1001
- unset( $query->query_vars['taxonomy'] );
1002
- unset( $query->query_vars['term'] );
1003
- unset( $query->query_vars['wpsc_item'] );
1004
-
1005
- $query->is_singular = true;
1006
- $query->is_page = true;
1007
- $query->is_tax = false;
1008
- $query->is_archive = false;
1009
- $query->is_single = false;
1010
-
1011
- if ( ($wpsc_query_vars == null ) ) {
1012
- unset( $wpsc_query_data['pagename'] );
1013
- $wpsc_query_vars = $wpsc_query_data;
1014
- }
1015
- }
1016
-
1017
- add_filter( 'redirect_canonical', 'wpsc_break_canonical_redirects', 10, 2 );
1018
- remove_filter( 'pre_get_posts', 'wpsc_split_the_query', 8 );
1019
- }
1020
-
1021
- /**
1022
- * wpsc_generate_product_query function.
1023
- *
1024
- * @access public
1025
- * @param mixed $query
1026
- * @return void
1027
- */
1028
- function wpsc_generate_product_query( $query ) {
1029
- global $wp_query;
1030
- $prod_page = wpsc_get_the_post_id_by_shortcode('[productspage]');
1031
- $prod_page = get_post($prod_page);
1032
- remove_filter( 'pre_get_posts', 'wpsc_generate_product_query', 11 );
1033
- $query->query_vars['taxonomy'] = null;
1034
- $query->query_vars['term'] = null;
1035
-
1036
- // default product selection
1037
- if ( $query->query_vars['pagename'] != '' ) {
1038
- $query->query_vars['post_type'] = 'wpsc-product';
1039
- $query->query_vars['pagename'] = '';
1040
- $query->is_page = false;
1041
- $query->is_tax = false;
1042
- $query->is_archive = true;
1043
- $query->is_singular = false;
1044
- $query->is_single = false;
1045
- }
1046
-
1047
- // If wpsc_item is not null, we are looking for a product or a product category, check for category
1048
- if ( isset( $query->query_vars['wpsc_item'] ) && ($query->query_vars['wpsc_item'] != '') ) {
1049
- $test_term = get_term_by( 'slug', $query->query_vars['wpsc_item'], 'wpsc_product_category' );
1050
- if ( $test_term->slug == $query->query_vars['wpsc_item'] ) {
1051
- // if category exists (slug matches slug), set products to value of wpsc_item
1052
- $query->query_vars['products'] = $query->query_vars['wpsc_item'];
1053
- } else {
1054
- // otherwise set name to value of wpsc_item
1055
- $query->query_vars['name'] = $query->query_vars['wpsc_item'];
1056
- }
1057
- }
1058
-
1059
- if ( isset( $query->query_vars['products'] ) && ($query->query_vars['products'] != null) && ($query->query_vars['name'] != null) ) {
1060
- unset( $query->query_vars['taxonomy'] );
1061
- unset( $query->query_vars['term'] );
1062
- $query->query_vars['post_type'] = 'wpsc-product';
1063
- $query->is_tax = false;
1064
- $query->is_archive = true;
1065
- $query->is_singular = false;
1066
- $query->is_single = false;
1067
- }
1068
- if( isset($wp_query->query_vars['wpsc_product_category']) && !isset($wp_query->query_vars['wpsc-product'])){
1069
- $query->query_vars['wpsc_product_category'] = $wp_query->query_vars['wpsc_product_category'];
1070
- $query->query_vars['taxonomy'] = $wp_query->query_vars['taxonomy'];
1071
- $query->query_vars['term'] = $wp_query->query_vars['term'];
1072
- }elseif( '' != ($default_category = get_option('wpsc_default_category')) && !isset($wp_query->query_vars['wpsc-product'])){
1073
- $default_term = get_term($default_category,'wpsc_product_category');
1074
- if(!empty($default_term) && empty($wp_query->query_vars['category_name'])){
1075
- $query->query_vars['taxonomy'] = 'wpsc_product_category';
1076
- $query->query_vars['term'] = $default_term->slug;
1077
- $query->is_tax = true;
1078
- }elseif(isset($wp_query->query_vars['name']) && $wp_query->is_404 && $wp_query->query_vars['category_name'] != $prod_page->post_name){
1079
- unset( $query->query_vars['taxonomy'] );
1080
- unset( $query->query_vars['term'] );
1081
- $query->query_vars['wpsc-product'] = $wp_query->query_vars['name'];
1082
- $query->query_vars['name'] = $wp_query->query_vars['name'];
1083
-
1084
- }else{
1085
- $query->is_tax = true;
1086
- $term = get_term_by('slug',$wp_query->query_vars['name'], 'wpsc_product_category' );
1087
- if(!empty($term)){
1088
- $query->query_vars['taxonomy'] = 'wpsc_product_category';
1089
- $query->query_vars['wpsc_product_category__in'] = array($term->term_taxonomy_id);
1090
- $query->query_vars['wpsc_product_category'] = $wp_query->query_vars['name'];
1091
- $query->query_vars['term'] = $wp_query->query_vars['name'];
1092
- }elseif(is_numeric($default_category)){
1093
- $query->query_vars['taxonomy'] = 'wpsc_product_category';
1094
- }else{
1095
- $query->is_tax = false;
1096
- }
1097
- }
1098
- }
1099
- //If Product Tag Taxonomy
1100
- if (isset($wp_query->query_vars['product_tag']) && $wp_query->query_vars['product_tag']){
1101
- $query->query_vars['product_tag'] = $wp_query->query_vars['product_tag'];
1102
- $query->query_vars['term'] = $wp_query->query_vars['term'];
1103
- $query->query_vars['taxonomy'] = 'product_tag';
1104
- $query->is_tax = true;
1105
- }
1106
- if(1 == get_option('use_pagination')){
1107
- $query->query_vars['posts_per_page'] = get_option('wpsc_products_per_page');
1108
- if( isset( $_GET['items_per_page'] ) ) {
1109
- if ( is_numeric( $_GET['items_per_page'] ) ) {
1110
- $query->query_vars['posts_per_page'] = (int) $_GET['items_per_page'];
1111
- } elseif ( $_GET['items_per_page'] == 'all' ) {
1112
- $query->query_vars['posts_per_page'] = -1;
1113
- $query->query_vars['nopaging'] = 1;
1114
- }
1115
- }
1116
- } else {
1117
- $query->query_vars['posts_per_page'] = -1;
1118
- $query->query_vars['nopaging'] = 1;
1119
- }
1120
- if ( $query->is_tax == true )
1121
- new wpsc_products_by_category( $query );
1122
- return $query;
1123
- }
1124
-
1125
- function wpsc_mark_product_query( $query ) {
1126
-
1127
- if ( isset( $query->query_vars['post_type'] ) && ($query->query_vars['post_type'] == 'wpsc-product') )
1128
- $query->is_product = true;
1129
-
1130
- return $query;
1131
- }
1132
- add_filter( 'pre_get_posts', 'wpsc_split_the_query', 8 );
1133
- add_filter( 'parse_query', 'wpsc_mark_product_query', 12 );
1134
-
1135
- /**
1136
- * wpsc_products_by_category class.
1137
- *
1138
- */
1139
- class wpsc_products_by_category {
1140
-
1141
- var $sql_components = array( );
1142
-
1143
- /**
1144
- * wpsc_products_by_category function.
1145
- *
1146
- * @access public
1147
- * @param mixed $query
1148
- * @return void
1149
- */
1150
- function wpsc_products_by_category( $query ) {
1151
- global $wpdb;
1152
- $q = $query->query_vars;
1153
-
1154
-
1155
- // Category stuff for nice URLs
1156
- if ( !empty( $q['wpsc_product_category'] ) && !$query->is_singular ) {
1157
- $q['taxonomy'] = 'wpsc_product_category';
1158
- $q['term'] = $q['wpsc_product_category'];
1159
- $in_cats = '';
1160
- $join = " INNER JOIN $wpdb->term_relationships
1161
- ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
1162
- INNER JOIN $wpdb->term_taxonomy
1163
- ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
1164
- ";
1165
- if(isset($q['meta_key']))
1166
- $join .= " INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) ";
1167
-
1168
- $whichcat = " AND $wpdb->term_taxonomy.taxonomy = '{$q['taxonomy']}' ";
1169
-
1170
- $term_data = get_term_by( 'slug', $q['term'], $q['taxonomy'] );
1171
-
1172
- if( is_object( $term_data ) )
1173
- $in_cats = array( $term_data->term_id );
1174
-
1175
- if('0' != get_option('show_subcatsprods_in_cat') && is_object($term_data)){
1176
- $term_children_data = get_term_children( $term_data->term_id, $q['taxonomy'] );
1177
- $in_cats = array_reverse( array_merge( $in_cats, $term_children_data ) );
1178
- }
1179
- if( is_array( $in_cats ) ){
1180
- $in_cats = "'" . implode( "', '", $in_cats ) . "'";
1181
- $whichcat .= "AND $wpdb->term_taxonomy.term_id IN ($in_cats)";
1182
- }
1183
-
1184
- $post_type_object = get_post_type_object( 'wpsc-product' );
1185
- $permitted_post_statuses = "'" . implode( "', '", $query->query_vars['post_status'] ) . "'";
1186
-
1187
- $whichcat .= " AND $wpdb->posts.post_status IN ($permitted_post_statuses) ";
1188
- $groupby = "{$wpdb->posts}.ID";
1189
-
1190
- $this->sql_components['join'] = $join;
1191
- $this->sql_components['fields'] = "{$wpdb->posts}.*, {$wpdb->term_taxonomy}.term_id";
1192
- $this->sql_components['group_by'] = $groupby;
1193
-
1194
- //what about ordering by price
1195
- if(isset($q['meta_key']) && '_wpsc_price' == $q['meta_key']){
1196
- $whichcat .= " AND $wpdb->postmeta.meta_key = '_wpsc_price'";
1197
- }else{
1198
-
1199
- $this->sql_components['order_by'] = "{$wpdb->term_taxonomy}.term_id";
1200
- }
1201
- $this->sql_components['where'] = $whichcat;
1202
- add_filter( 'posts_join', array( &$this, 'join_sql' ) );
1203
- add_filter( 'posts_where', array( &$this, 'where_sql' ) );
1204
- add_filter( 'posts_fields', array( &$this, 'fields_sql' ) );
1205
- add_filter( 'posts_orderby', array( &$this, 'order_by_sql' ) );
1206
- add_filter( 'posts_groupby', array( &$this, 'group_by_sql' ) );
1207
- }
1208
- }
1209
-
1210
- function join_sql( $sql ) {
1211
- if ( isset( $this->sql_components['join'] ) )
1212
- $sql = $this->sql_components['join'];
1213
-
1214
- remove_filter( 'posts_join', array( &$this, 'join_sql' ) );
1215
- return $sql;
1216
- }
1217
-
1218
- function where_sql( $sql ) {
1219
- if ( isset( $this->sql_components['where'] ) )
1220
- $sql = $this->sql_components['where'];
1221
-
1222
- remove_filter( 'posts_where', array( &$this, 'where_sql' ) );
1223
- return $sql;
1224
- }
1225
-
1226
- function order_by_sql( $sql ) {
1227
- $order_by_parts = array( );
1228
- $order_by_parts[] = $sql;
1229
-
1230
- if ( isset( $this->sql_components['order_by'] ) )
1231
- $order_by_parts[] = $this->sql_components['order_by'];
1232
-
1233
- $order_by_parts = array_reverse( $order_by_parts );
1234
- $sql = implode( ',', $order_by_parts );
1235
-
1236
- remove_filter( 'posts_orderby', array( &$this, 'order_by_sql' ) );
1237
- return $sql;
1238
- }
1239
-
1240
- function fields_sql( $sql ) {
1241
- if ( isset( $this->sql_components['fields'] ) )
1242
- $sql = $this->sql_components['fields'];
1243
-
1244
- remove_filter( 'posts_fields', array( &$this, 'fields_sql' ) );
1245
- return $sql;
1246
- }
1247
-
1248
- function group_by_sql( $sql ) {
1249
- if ( isset( $this->sql_components['group_by'] ) )
1250
- $sql = $this->sql_components['group_by'];
1251
-
1252
- remove_filter( 'posts_groupby', array( &$this, 'group_by_sql' ) );
1253
- return $sql;
1254
- }
1255
-
1256
- function request_sql( $sql ) {
1257
- echo $sql . "<br />";
1258
- remove_filter( 'posts_request', array( &$this, 'request_sql' ) );
1259
- return $sql;
1260
- }
1261
- }
1262
-
1263
- function wpsc_break_canonical_redirects( $redirect_url, $requested_url ) {
1264
- global $wp_query;
1265
-
1266
- if ( ( isset( $wp_query->query_vars['products'] ) && ($wp_query->query_vars['products'] != '') ) || ( isset( $wp_query->query_vars['products'] ) && $wp_query->query_vars['products'] != 'wpsc_item') )
1267
- return false;
1268
-
1269
- if ( stristr( $requested_url, $redirect_url ) )
1270
- return false;
1271
-
1272
- return $redirect_url;
1273
- }
1274
-
1275
- /**
1276
- * wpsc_is_product function.
1277
- *
1278
- * @since 3.8
1279
- * @access public
1280
- * @return boolean
1281
- */
1282
- function wpsc_is_product() {
1283
- global $wp_query, $rewrite_rules;
1284
- $tmp = false;
1285
-
1286
- if ( isset( $wp_query->is_product ) )
1287
- $tmp = $wp_query->is_product;
1288
-
1289
- return $tmp;
1290
- }
1291
-
1292
  /**
1293
- * wpsc_is_product function.
1294
  *
1295
  * @since 3.8
1296
  * @access public
1297
- * @return boolean
1298
- */
1299
- function wpsc_is_checkout() {
1300
- global $wp_query, $rewrite_rules;
1301
- $tmp = false;
1302
-
1303
- if ( isset( $wp_query->is_checkout ) )
1304
- $tmp = $wp_query->is_checkout;
1305
-
1306
- return $tmp;
1307
- }
1308
-
1309
- /**
1310
- * wpsc_product_link function.
1311
- * Gets the product link, hooks into post_link
1312
- * Uses the currently selected, only associated or first listed category for the term URL
1313
- * If the category slug is the same as the product slug, it prefixes the product slug with "product/" to counteract conflicts
1314
- *
1315
- * @access public
1316
  * @return void
1317
  */
1318
- function wpsc_product_link( $permalink, $post, $leavename ) {
1319
- global $wp_query, $wpsc_page_titles, $wpsc_query, $wp_current_filter;
1320
- $rewritecode = array(
1321
- '%wpsc_product_category%',
1322
- $leavename ? '' : '%postname%',
1323
- );
1324
- if ( is_object( $post ) ) {
1325
- // In wordpress 2.9 we got a post object
1326
- $post_id = $post->ID;
1327
- } else {
1328
- // In wordpress 3.0 we get a post ID
1329
- $post_id = $post;
1330
- $post = get_post( $post_id );
1331
- }
1332
-
1333
- // Only applies to WPSC products, don't stop on permalinks of other CPTs
1334
- // Fixes http://code.google.com/p/wp-e-commerce/issues/detail?id=271
1335
- if ($post->post_type != 'wpsc-product')
1336
- return $permalink;
1337
-
1338
- $permalink_structure = get_option( 'permalink_structure' );
1339
-
1340
- // This may become customiseable later
1341
- $our_permalink_structure = str_replace( basename( home_url() ), '', $wpsc_page_titles['products'] ) . "/%wpsc_product_category%/%postname%/";
1342
- // Mostly the same conditions used for posts, but restricted to items with a post type of "wpsc-product "
1343
-
1344
- if ( '' != $permalink_structure && !in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
1345
- $product_categories = wpsc_get_product_terms( $post_id, 'wpsc_product_category' );
1346
- $product_category_slugs = array( );
1347
- foreach ( $product_categories as $product_category ) {
1348
- $product_category_slugs[] = $product_category->slug;
1349
- }
1350
- // If the product is associated with multiple categories, determine which one to pick
1351
- if ( count( $product_categories ) == 0 ) {
1352
- $category_slug = 'uncategorized';
1353
- } elseif ( count( $product_categories ) > 1 ) {
1354
- if ( (isset( $wp_query->query_vars['products'] ) && $wp_query->query_vars['products'] != null) && in_array( $wp_query->query_vars['products'], $product_category_slugs ) ) {
1355
- $product_category = $wp_query->query_vars['products'];
1356
- } else {
1357
- $link = $product_categories[0]->slug;
1358
- if ( ! in_array( 'wp_head', $wp_current_filter) && isset( $wpsc_query->query_vars['wpsc_product_category'] ) ) {
1359
- $current_cat = $wpsc_query->query_vars['wpsc_product_category'];
1360
- if ( in_array( $current_cat, $product_category_slugs ) )
1361
- $link = $current_cat;
1362
- }
1363
-
1364
- $product_category = $link;
1365
- }
1366
- $category_slug = $product_category;
1367
- } else {
1368
- // If the product is associated with only one category, we only have one choice
1369
- if ( !isset( $product_categories[0] ) )
1370
- $product_categories[0] = '';
1371
-
1372
- $product_category = $product_categories[0];
1373
-
1374
- if ( !is_object( $product_category ) )
1375
- $product_category = new stdClass();
1376
-
1377
- if ( !isset( $product_category->slug ) )
1378
- $product_category->slug = null;
1379
-
1380
- $category_slug = $product_category->slug;
1381
- }
1382
-
1383
- $post_name = $post->post_name;
1384
-
1385
- if ( get_option( 'product_category_hierarchical_url', 0 ) ) {
1386
- $selected_term = get_term_by( 'slug', $category_slug, 'wpsc_product_category' );
1387
- if ( is_object( $selected_term ) ) {
1388
- $term_chain = array( $selected_term->slug );
1389
- while ( $selected_term->parent ) {
1390
- $selected_term = get_term( $selected_term->parent, 'wpsc_product_category' );
1391
- array_unshift( $term_chain, $selected_term->slug );
1392
- }
1393
- $category_slug = implode( '/', $term_chain );
1394
- }
1395
- }
1396
-
1397
- if( isset( $category_slug ) && empty( $category_slug ) )
1398
- $category_slug = 'product';
1399
-
1400
- $category_slug = apply_filters( 'wpsc_product_permalink_cat_slug', $category_slug, $post_id );
1401
-
1402
- $rewritereplace = array(
1403
- $category_slug,
1404
- $post_name
1405
- );
1406
-
1407
- $permalink = str_replace( $rewritecode, $rewritereplace, $our_permalink_structure );
1408
- $permalink = user_trailingslashit( $permalink, 'single' );
1409
 
1410
- $permalink = home_url( $permalink );
 
 
 
1411
  }
1412
- return apply_filters( 'wpsc_product_permalink', $permalink, $post->ID );
1413
- }
1414
- add_filter( 'post_type_link', 'wpsc_product_link', 10, 3 );
1415
 
1416
- /**
1417
- * wpsc_get_product_template function.
1418
- *
1419
- * @since 3.8
1420
- * @access public
1421
- * @return void
1422
- */
1423
- function wpsc_get_template( $template ) {
1424
- return get_query_template( $template );
1425
- }
1426
-
1427
- /**
1428
- * wpsc_product_template_fallback function.
1429
- *
1430
- * @since 3.8
1431
- * @access public
1432
- * @param mixed $template_path
1433
- * @return string - the corrected template path
1434
- */
1435
- function wpsc_template_fallback( $template_path ) {
1436
-
1437
- $prospective_file_name = basename( "{$template_path}.php" );
1438
- $prospective_file_path = trailingslashit( WPSC_CORE_THEME_PATH ) . $prospective_file_name;
1439
-
1440
- if ( !file_exists( $prospective_file_path ) )
1441
- exit( $prospective_file_path );
1442
-
1443
- return $prospective_file_path;
1444
- }
1445
-
1446
- function wpsc_products_template_fallback() {
1447
- return wpsc_template_fallback( 'products' );
1448
- }
1449
-
1450
- function wpsc_checkout_template_fallback() {
1451
- return wpsc_template_fallback( 'checkout' );
1452
- }
1453
-
1454
- /**
1455
- * wpsc_get_page_post_names function.
1456
- *
1457
- * @since 3.8
1458
- * @access public
1459
- * @return void
1460
- */
1461
- function wpsc_get_page_post_names() {
1462
- $wpsc_page['products'] = basename( get_option( 'product_list_url' ) );
1463
  $wpsc_page['checkout'] = basename( get_option( 'checkout_url' ) );
1464
  $wpsc_page['transaction_results'] = basename( get_option( 'transact_url' ) );
1465
  $wpsc_page['userlog'] = basename( get_option( 'user_account_url' ) );
@@ -1467,89 +486,6 @@ function wpsc_get_page_post_names() {
1467
  return $wpsc_page;
1468
  }
1469
 
1470
- /**
1471
- * wpsc_template_loader function.
1472
- *
1473
- * @since 3.8
1474
- * @access public
1475
- * @return void
1476
- */
1477
- function wpsc_template_loader() {
1478
- global $wp_query;
1479
-
1480
- if ( wpsc_is_product() && $template = wpsc_get_template( 'products' ) ) {
1481
- include( $template );
1482
- exit();
1483
- }
1484
-
1485
- if ( wpsc_is_checkout() && $template = wpsc_get_template( 'checkout' ) ) {
1486
- include( $template );
1487
- exit();
1488
- }
1489
- }
1490
-
1491
- /**
1492
- * select_wpsc_theme_functions function, provides a place to override the e-commece theme path
1493
- * add to switch "theme's functions file
1494
- * © with xiligroup dev
1495
- */
1496
- function wpsc_select_theme_functions() {
1497
- $selected_theme = get_option( 'wpsc_selected_theme' );
1498
- if ( !empty( $selected_theme ) && file_exists( WPSC_CORE_THEME_PATH . '/' . WPSC_THEME_DIR . '.php' ) )
1499
- include_once( WPSC_CORE_THEME_PATH . '/' . WPSC_THEME_DIR . '.php' );
1500
- }
1501
- add_action( 'wp', 'wpsc_select_theme_functions', 10, 1 );
1502
-
1503
- /**
1504
- * if the user is on a checkout page, force SSL if that option is so set
1505
- */
1506
- function wpsc_force_ssl() {
1507
- global $wp_query;
1508
- if ( '1' == get_option( 'wpsc_force_ssl' ) &&
1509
- ! is_ssl() &&
1510
- ! empty ( $wp_query->post->post_content ) &&
1511
- false !== strpos( $wp_query->post->post_content, '[shoppingcart]' ) ) {
1512
- $sslurl = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
1513
- wp_redirect( $sslurl );
1514
- exit;
1515
- }
1516
- }
1517
- add_action( 'wp', 'wpsc_force_ssl' );
1518
-
1519
-
1520
- /**
1521
- * Disable SSL validation for Curl. Added/removed on a per need basis, like so:
1522
- *
1523
- * add_filter('http_api_curl', 'wpsc_curl_ssl');
1524
- * remove_filter('http_api_curl', 'wpsc_curl_ssl');
1525
- *
1526
- * @param resource $ch
1527
- * @return resource $ch
1528
- **/
1529
- function wpsc_curl_ssl($ch) {
1530
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1531
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
1532
- return $ch;
1533
- }
1534
-
1535
- /**
1536
- * wpsc_add_https_to_page_url_options( $url )
1537
- *
1538
- * Forces SSL onto option URLs
1539
- *
1540
- * @param string $url
1541
- * @return string
1542
- */
1543
- function wpsc_add_https_to_page_url_options( $url ) {
1544
- return str_replace( 'http://', 'https://', $url );
1545
- }
1546
- if ( is_ssl() ) {
1547
- add_filter( 'option_product_list_url', 'wpsc_add_https_to_page_url_options' );
1548
- add_filter( 'option_shopping_cart_url', 'wpsc_add_https_to_page_url_options' );
1549
- add_filter( 'option_transact_url', 'wpsc_add_https_to_page_url_options' );
1550
- add_filter( 'option_user_account_url', 'wpsc_add_https_to_page_url_options' );
1551
- }
1552
-
1553
  function wpsc_cron() {
1554
  foreach ( wp_get_schedules() as $cron => $schedule ) {
1555
  if ( ! wp_next_scheduled( "wpsc_{$cron}_cron_task" ) )
@@ -1558,282 +494,6 @@ function wpsc_cron() {
1558
  }
1559
  add_action( 'init', 'wpsc_cron' );
1560
 
1561
- /**
1562
- * Checks if current page is shopping cart, and it should be SSL, but is not.
1563
- * Used primarily for str_replacing links or content for https
1564
- *
1565
- * @since 3.8.8.1
1566
- * @deprecated 3.8.8.2
1567
- * @return boolean true if we're on the shopping cart page and should be ssl, false if not
1568
- */
1569
- function wpsc_is_ssl() {
1570
- global $wp_query;
1571
-
1572
- return '1' == get_option( 'wpsc_force_ssl' ) && ! is_ssl() && false !== strpos( $wp_query->post->post_content, '[shoppingcart]' );
1573
- }
1574
-
1575
-
1576
- /**
1577
- * In case the user is not logged in, create a customer cookie with a unique
1578
- * ID to pair with the transient in the database.
1579
- *
1580
- * @access public
1581
- * @since 3.8.9
1582
- * @return string Customer ID
1583
- */
1584
- function wpsc_create_customer_id() {
1585
- $expire = time() + WPSC_CUSTOMER_DATA_EXPIRATION; // valid for 48 hours
1586
- $secure = is_ssl();
1587
- $id = '_' . wp_generate_password(); // make sure the ID is a string
1588
- $data = $id . $expire;
1589
- $hash = hash_hmac( 'md5', $data, wp_hash( $data ) );
1590
- // store ID, expire and hash to validate later
1591
- $cookie = $id . '|' . $expire . '|' . $hash;
1592
-
1593
- setcookie( WPSC_CUSTOMER_COOKIE, $cookie, $expire, WPSC_CUSTOMER_COOKIE_PATH, COOKIE_DOMAIN, $secure, true );
1594
- $_COOKIE[WPSC_CUSTOMER_COOKIE] = $cookie;
1595
- return $id;
1596
- }
1597
-
1598
- /**
1599
- * Make sure the customer cookie is not compromised.
1600
- *
1601
- * @access public
1602
- * @since 3.8.9
1603
- * @return mixed Return the customer ID if the cookie is valid, false if otherwise.
1604
- */
1605
- function wpsc_validate_customer_cookie() {
1606
- $cookie = $_COOKIE[WPSC_CUSTOMER_COOKIE];
1607
- list( $id, $expire, $hash ) = explode( '|', $cookie );
1608
- $data = $id . $expire;
1609
- $hmac = hash_hmac( 'md5', $data, wp_hash( $data ) );
1610
-
1611
- if ( $hmac != $hash )
1612
- return false;
1613
-
1614
- return $id;
1615
- }
1616
-
1617
- /**
1618
- * Merge anonymous customer data (stored in transient) with an account meta data when the customer
1619
- * logs in.
1620
- *
1621
- * This is done to preserve customer settings and cart.
1622
- *
1623
- * @since 3.8.9
1624
- * @access private
1625
- */
1626
- function _wpsc_merge_customer_data() {
1627
- $account_id = get_current_user_id();
1628
- $cookie_id = wpsc_validate_customer_cookie();
1629
-
1630
- if ( ! $cookie_id )
1631
- return;
1632
-
1633
- $cookie_data = get_transient( "wpsc_customer_meta_{$cookie_id}" );
1634
- if ( ! is_array( $cookie_data ) || empty( $cookie_data ) )
1635
- return;
1636
-
1637
- foreach ( $cookie_data as $key => $value ) {
1638
- wpsc_update_customer_meta( $key, $value, $account_id );
1639
- }
1640
-
1641
- delete_transient( "wpsc_customer_meta_{$cookie_id}" );
1642
- setcookie( WPSC_CUSTOMER_COOKIE, '', time() - 3600, WPSC_CUSTOMER_COOKIE_PATH, COOKIE_DOMAIN, is_ssl(), true );
1643
- unset( $_COOKIE[WPSC_CUSTOMER_COOKIE] );
1644
- }
1645
-
1646
- /**
1647
- * Get current customer ID.
1648
- *
1649
- * If the user is logged in, return the user ID. Otherwise return the ID associated
1650
- * with the customer's cookie.
1651
- *
1652
- * If $mode is set to 'create', WPEC will create the customer ID if it hasn't
1653
- * already been created yet.
1654
- *
1655
- * @access public
1656
- * @since 3.8.9
1657
- * @param string $mode Set to 'create' to create customer cookie and ID
1658
- * @return mixed User ID (if logged in) or customer cookie ID
1659
- */
1660
- function wpsc_get_current_customer_id( $mode = '' ) {
1661
- if ( is_user_logged_in() && isset( $_COOKIE[WPSC_CUSTOMER_COOKIE] ) )
1662
- _wpsc_merge_customer_data();
1663
-
1664
- if ( is_user_logged_in() )
1665
- return get_current_user_id();
1666
- elseif ( isset( $_COOKIE[WPSC_CUSTOMER_COOKIE] ) )
1667
- return wpsc_validate_customer_cookie();
1668
- elseif ( $mode == 'create' )
1669
- return wpsc_create_customer_id();
1670
-
1671
- return false;
1672
- }
1673
-
1674
- /**
1675
- * Return an array containing all metadata of a customer
1676
- *
1677
- * @access public
1678
- * @since 3.8.9
1679
- * @param mixed $id Customer ID. Default to the current user ID.
1680
- * @return WP_Error|array Return an array of metadata if no error occurs, WP_Error
1681
- * if otherwise.
1682
- */
1683
- function wpsc_get_all_customer_meta( $id = false ) {
1684
- global $wpdb;
1685
-
1686
- if ( ! $id )
1687
- $id = wpsc_get_current_customer_id();
1688
-
1689
- if ( ! $id )
1690
- return new WP_Error( 'wpsc_customer_meta_invalid_customer_id', __( 'Invalid customer ID', 'wpsc' ), $id );
1691
-
1692
- // take multisite into account
1693
- $blog_prefix = is_multisite() ? $wpdb->get_blog_prefix() : '';
1694
- if ( is_numeric( $id ) )
1695
- $profile = get_user_meta( $id, "_wpsc_{$blog_prefix}customer_profile", true );
1696
- else
1697
- $profile = get_transient( "wpsc_customer_meta_{$blog_prefix}{$id}" );
1698
-
1699
- if ( ! is_array( $profile ) )
1700
- $profile = array();
1701
-
1702
- return apply_filters( 'wpsc_get_all_customer_meta', $profile, $id );
1703
- }
1704
-
1705
- /**
1706
- * Get a customer meta value.
1707
- *
1708
- * @access public
1709
- * @since 3.8.9
1710
- * @param string $key Meta key
1711
- * @param int|string $id Customer ID. Optional, defaults to current customer
1712
- * @return mixed Meta value, or null if it doesn't exist or if the
1713
- * customer ID is invalid.
1714
- */
1715
- function wpsc_get_customer_meta( $key = '', $id = false ) {
1716
- global $wpdb;
1717
-
1718
- $profile = wpsc_get_all_customer_meta( $id );
1719
-
1720
- // attempt to regenerate current customer ID if it's invalid
1721
- if ( is_wp_error( $profile ) && ! $id ) {
1722
- wpsc_create_customer_id();
1723
- $profile = wpsc_get_all_customer_meta();
1724
- }
1725
-
1726
- if ( is_wp_error( $profile ) || ! array_key_exists( $key, $profile ) )
1727
- return null;
1728
-
1729
- return $profile[$key];
1730
- }
1731
-
1732
- /**
1733
- * Overwrite customer meta with an array of meta_key => meta_value.
1734
- *
1735
- * @access public
1736
- * @since 3.8.9
1737
- * @param array $profile Customer meta array
1738
- * @param int|string $id Customer ID. Optional. Defaults to current customer.
1739
- * @return boolean True if meta values are updated successfully. False
1740
- * if otherwise.
1741
- */
1742
- function wpsc_update_all_customer_meta( $profile, $id = false ) {
1743
- global $wpdb;
1744
-
1745
- if ( ! $id )
1746
- $id = wpsc_get_current_customer_id( 'create' );
1747
-
1748
- $blog_prefix = is_multisite() ? $wpdb->get_blog_prefix() : '';
1749
-
1750
- if ( is_numeric( $id ) )
1751
- return update_user_meta( $id, "_wpsc_{$blog_prefix}customer_profile", $profile );
1752
- else
1753
- return set_transient( "wpsc_customer_meta_{$blog_prefix}{$id}", $profile, WPSC_CUSTOMER_DATA_EXPIRATION );
1754
- }
1755
-
1756
- /**
1757
- * Update a customer meta.
1758
- *
1759
- * @access public
1760
- * @since 3.8.9
1761
- * @param string $key Meta key
1762
- * @param mixed $value Meta value
1763
- * @param string|int $id Customer ID. Optional. Defaults to current customer.
1764
- * @return boolean|WP_Error True if successful, false if not successful, WP_Error
1765
- * if there are any errors.
1766
- */
1767
- function wpsc_update_customer_meta( $key, $value, $id = false ) {
1768
- global $wpdb;
1769
-
1770
- if ( ! $id )
1771
- $id = wpsc_get_current_customer_id( 'create' );
1772
-
1773
- $profile = wpsc_get_all_customer_meta( $id );
1774
-
1775
- if ( is_wp_error( $profile ) )
1776
- return $profile;
1777
-
1778
- $profile[$key] = $value;
1779
-
1780
- return wpsc_update_all_customer_meta( $profile, $id );
1781
- }
1782
-
1783
- /**
1784
- * Delete customer meta.
1785
- *
1786
- * @access public
1787
- * @since 3.8.9
1788
- * @param string $key Meta key
1789
- * @param string|int $id Customer ID. Optional. Defaults to current customer.
1790
- * @return boolean|WP_Error True if successful. False if not successful. WP_Error
1791
- * if there are any errors.
1792
- */
1793
- function wpsc_delete_customer_meta( $key, $id = false ) {
1794
- $profile = wpsc_get_all_customer_meta( $id );
1795
-
1796
- if ( is_wp_error( $profile ) )
1797
- return $profile;
1798
-
1799
- if ( array_key_exists( $key, $profile ) )
1800
- unset( $profile[$key] );
1801
-
1802
- return wpsc_update_all_customer_meta( $profile, $id );
1803
- }
1804
-
1805
- /**
1806
- * Create customer ID upon 'plugins_loaded' to make sure there's one exists before
1807
- * anything else.
1808
- *
1809
- * @access private
1810
- * @since 3.8.9
1811
- */
1812
- function _wpsc_action_create_customer_id() {
1813
- wpsc_get_current_customer_id( 'create' );
1814
- }
1815
-
1816
- /**
1817
- * Delete all customer meta for a certain customer ID
1818
- *
1819
- * @since 3.8.9.4
1820
- * @param string|int $id Customer ID. Optional. Defaults to current customer
1821
- * @return boolean True if successful, False if otherwise
1822
- */
1823
- function wpsc_delete_all_customer_meta( $id = false ) {
1824
- global $wpdb;
1825
-
1826
- if ( ! $id )
1827
- $id = wpsc_get_current_customer_id();
1828
-
1829
- $blog_prefix = is_multisite() ? $wpdb->get_blog_prefix() : '';
1830
-
1831
- if ( is_numeric( $id ) )
1832
- return delete_user_meta( $id, "_wpsc_{$blog_prefix}customer_profile" );
1833
- else
1834
- return delete_transient( "wpsc_customer_meta_{$blog_prefix}{$id}" );
1835
- }
1836
-
1837
  /**
1838
  * Updates permalink slugs
1839
  *
@@ -1906,17 +566,27 @@ function wpsc_get_product_terms( $product_id, $tax, $field = '' ) {
1906
  }
1907
 
1908
  /**
1909
- * Returns page slug that corresponds to a given WPEC-specific shortcode.
1910
  *
1911
- * @since 3.8.10
 
 
 
 
 
 
 
 
1912
  *
1913
- * @uses wpsc_get_the_post_id_by_shortcode() Gets page ID of shortcode.
1914
- * @uses get_post_field() Returns post name of page ID.
1915
  *
1916
- * @param string $shortcode Shortcode of WPEC-specific page, e.g. '[productspage]''
1917
- * @return string Post slug
1918
  */
1919
- function wpsc_get_page_slug( $shortcode ) {
1920
- $id = wpsc_get_the_post_id_by_shortcode( $shortcode );
1921
- return get_post_field( 'post_name', $id );
 
 
 
1922
  }
 
10
  * @since 3.8
11
  */
12
 
13
+ if ( is_admin() )
14
+ add_filter( 'term_name', 'wpsc_term_list_levels', 10, 2 );
15
 
16
  /**
17
  * When doing variation and product category drag&drop sort, we want to restrict
67
  <?php
68
  }
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  /**
71
  * wpsc_core_load_checkout_data()
72
  *
163
  $wpsc_purchlog_statuses = apply_filters('wpsc_set_purchlog_statuses',$wpsc_purchlog_statuses);
164
  }
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  /***
167
  * wpsc_core_load_gateways()
168
  *
205
  * the shipping directory for modules.
206
  */
207
  function wpsc_core_load_shipping_modules() {
208
+ global $wpsc_shipping_modules;
209
 
210
  $shipping_directory = WPSC_FILE_PATH . '/wpsc-shipping';
211
  $nzshpcrt_shipping_list = wpsc_list_dir( $shipping_directory );
218
 
219
  $wpsc_shipping_modules = apply_filters( 'wpsc_shipping_modules', $wpsc_shipping_modules );
220
 
221
+ if ( ! get_option( 'do_not_use_shipping' ) )
222
+ add_action( 'wpsc_setup_customer', '_wpsc_action_get_shipping_method' );
223
+ }
224
+
225
+ /**
226
+ * If shipping is enabled and shipping methods have not been initialized, then
227
+ * do so.
228
+ *
229
+ * @access private
230
+ * @since 3.8.13
231
+ */
232
+ function _wpsc_action_get_shipping_method() {
233
+ global $wpsc_cart;
234
+ if ( empty( $wpsc_cart->selected_shipping_method ) )
235
  $wpsc_cart->get_shipping_method();
236
  }
237
 
433
  }
434
  add_filter( 'post_updated_messages', 'wpsc_post_updated_messages' );
435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
 
437
  /**
438
  * This serializes the shopping cart variable as a backup in case the
441
  function wpsc_serialize_shopping_cart() {
442
  global $wpdb, $wpsc_start_time, $wpsc_cart;
443
 
444
+ if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )
445
+ return;
446
+
447
  // avoid flooding transients with bots hitting feeds
448
  if ( is_feed() ) {
449
  wpsc_delete_all_customer_meta();
457
  // because by now, some output must have been printed out
458
  $customer_id = wpsc_get_current_customer_id();
459
  if ( $customer_id )
460
+ wpsc_update_customer_meta( 'cart', base64_encode( serialize( $wpsc_cart ) ) );
461
 
462
  return true;
463
  }
464
  add_action( 'shutdown', 'wpsc_serialize_shopping_cart' );
465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
  /**
467
+ * wpsc_get_page_post_names function.
468
  *
469
  * @since 3.8
470
  * @access public
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
  * @return void
472
  */
473
+ function wpsc_get_page_post_names() {
474
+ $wpsc_page['products'] = basename( get_option( 'product_list_url' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
 
476
+ if ( empty( $wpsc_page['products'] ) || false !== strpos( $wpsc_page['products'], '?page_id=' ) ) {
477
+ // Products page either doesn't exist, or is a draft
478
+ // Default to /product/xyz permalinks for products
479
+ $wpsc_page['products'] = 'product';
480
  }
 
 
 
481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
  $wpsc_page['checkout'] = basename( get_option( 'checkout_url' ) );
483
  $wpsc_page['transaction_results'] = basename( get_option( 'transact_url' ) );
484
  $wpsc_page['userlog'] = basename( get_option( 'user_account_url' ) );
486
  return $wpsc_page;
487
  }
488
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
  function wpsc_cron() {
490
  foreach ( wp_get_schedules() as $cron => $schedule ) {
491
  if ( ! wp_next_scheduled( "wpsc_{$cron}_cron_task" ) )
494
  }
495
  add_action( 'init', 'wpsc_cron' );
496
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
497
  /**
498
  * Updates permalink slugs
499
  *
566
  }
567
 
568
  /**
569
+ * Abstracts Suhosin check into a function. Used primarily in relation to target markets.
570
  *
571
+ * @since 3.8.9
572
+ * @return boolean
573
+ */
574
+ function wpsc_is_suhosin_enabled() {
575
+ return @ extension_loaded( 'suhosin' ) && @ ini_get( 'suhosin.post.max_vars' ) > 0 && @ ini_get( 'suhosin.post.max_vars' ) < 500;
576
+ }
577
+
578
+ /**
579
+ * wpsc_core_load_page_titles()
580
  *
581
+ * Load the WPEC page titles
 
582
  *
583
+ * @global array $wpsc_page_titles
 
584
  */
585
+ function wpsc_core_load_page_titles() {
586
+ global $wpsc_page_titles;
587
+ $wpsc_page_titles = apply_filters( 'wpsc_page_titles', false );
588
+
589
+ if ( empty( $wpsc_page_titles ) )
590
+ $wpsc_page_titles = wpsc_get_page_post_names();
591
  }
592
+
wpsc-core/wpsc-includes.php CHANGED
@@ -4,17 +4,17 @@ if ( defined( 'WPEC_LOAD_DEPRECATED' ) )
4
  require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-deprecated.php' );
5
 
6
  // Start including the rest of the plugin here
 
7
  require_once( WPSC_FILE_PATH . '/wpsc-includes/product-template.php' );
8
- require_once( WPSC_FILE_PATH . '/wpsc-includes/breadcrumbs.class.php' );
9
  require_once( WPSC_FILE_PATH . '/wpsc-includes/variations.class.php' );
10
  require_once( WPSC_FILE_PATH . '/wpsc-includes/ajax.functions.php' );
11
  require_once( WPSC_FILE_PATH . '/wpsc-includes/misc.functions.php' );
12
  require_once( WPSC_FILE_PATH . '/wpsc-includes/mimetype.php' );
13
  require_once( WPSC_FILE_PATH . '/wpsc-includes/cart.class.php' );
 
14
  require_once( WPSC_FILE_PATH . '/wpsc-includes/checkout.class.php' );
15
  require_once( WPSC_FILE_PATH . '/wpsc-includes/display.functions.php' );
16
  require_once( WPSC_FILE_PATH . '/wpsc-includes/theme.functions.php' );
17
- require_once( WPSC_FILE_PATH . '/wpsc-includes/shortcode.functions.php' );
18
  require_once( WPSC_FILE_PATH . '/wpsc-includes/coupons.class.php' );
19
  require_once( WPSC_FILE_PATH . '/wpsc-includes/category.functions.php' );
20
  require_once( WPSC_FILE_PATH . '/wpsc-includes/processing.functions.php' );
@@ -42,22 +42,13 @@ require_once( WPSC_FILE_PATH . '/wpsc-includes/currency_converter.inc.php' );
42
  require_once( WPSC_FILE_PATH . '/wpsc-includes/shopping_cart_functions.php' );
43
 
44
  // Themes
45
- require_once( WPSC_CORE_THEME_PATH . 'functions/wpsc-transaction_results_functions.php' );
46
- require_once( WPSC_CORE_THEME_PATH . 'functions/wpsc-user_log_functions.php' );
47
  require_once( WPSC_FILE_PATH . '/wpsc-includes/google-analytics.class.php' );
48
 
49
  require_once( WPSC_FILE_PATH . '/wpsc-admin/admin-form-functions.php' );
50
  require_once( WPSC_FILE_PATH . '/wpsc-shipping/library/shipwire_functions.php' );
51
 
52
  // Widgets
53
- include_once( WPSC_FILE_PATH . '/wpsc-widgets/product_tag_widget.php' );
54
- include_once( WPSC_FILE_PATH . '/wpsc-widgets/shopping_cart_widget.php' );
55
- include_once( WPSC_FILE_PATH . '/wpsc-widgets/donations_widget.php' );
56
- include_once( WPSC_FILE_PATH . '/wpsc-widgets/specials_widget.php' );
57
- include_once( WPSC_FILE_PATH . '/wpsc-widgets/latest_product_widget.php' );
58
- include_once( WPSC_FILE_PATH . '/wpsc-widgets/price_range_widget.php' );
59
  include_once( WPSC_FILE_PATH . '/wpsc-widgets/admin_menu_widget.php' );
60
- include_once( WPSC_FILE_PATH . '/wpsc-widgets/category_widget.php' );
61
 
62
  // Gregs ASH Shipping
63
  require_once( WPSC_FILE_PATH . '/wpsc-includes/shipping.helper.php' );
4
  require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-deprecated.php' );
5
 
6
  // Start including the rest of the plugin here
7
+ require_once( WPSC_FILE_PATH . '/wpsc-includes/customer.php' );
8
  require_once( WPSC_FILE_PATH . '/wpsc-includes/product-template.php' );
 
9
  require_once( WPSC_FILE_PATH . '/wpsc-includes/variations.class.php' );
10
  require_once( WPSC_FILE_PATH . '/wpsc-includes/ajax.functions.php' );
11
  require_once( WPSC_FILE_PATH . '/wpsc-includes/misc.functions.php' );
12
  require_once( WPSC_FILE_PATH . '/wpsc-includes/mimetype.php' );
13
  require_once( WPSC_FILE_PATH . '/wpsc-includes/cart.class.php' );
14
+ require_once( WPSC_FILE_PATH . '/wpsc-includes/cart-item.class.php' );
15
  require_once( WPSC_FILE_PATH . '/wpsc-includes/checkout.class.php' );
16
  require_once( WPSC_FILE_PATH . '/wpsc-includes/display.functions.php' );
17
  require_once( WPSC_FILE_PATH . '/wpsc-includes/theme.functions.php' );
 
18
  require_once( WPSC_FILE_PATH . '/wpsc-includes/coupons.class.php' );
19
  require_once( WPSC_FILE_PATH . '/wpsc-includes/category.functions.php' );
20
  require_once( WPSC_FILE_PATH . '/wpsc-includes/processing.functions.php' );
42
  require_once( WPSC_FILE_PATH . '/wpsc-includes/shopping_cart_functions.php' );
43
 
44
  // Themes
 
 
45
  require_once( WPSC_FILE_PATH . '/wpsc-includes/google-analytics.class.php' );
46
 
47
  require_once( WPSC_FILE_PATH . '/wpsc-admin/admin-form-functions.php' );
48
  require_once( WPSC_FILE_PATH . '/wpsc-shipping/library/shipwire_functions.php' );
49
 
50
  // Widgets
 
 
 
 
 
 
51
  include_once( WPSC_FILE_PATH . '/wpsc-widgets/admin_menu_widget.php' );
 
52
 
53
  // Gregs ASH Shipping
54
  require_once( WPSC_FILE_PATH . '/wpsc-includes/shipping.helper.php' );
wpsc-core/wpsc-installer.php CHANGED
@@ -398,7 +398,7 @@ function wpsc_create_upload_directories() {
398
  WPSC_USER_UPLOADS_DIR,
399
  WPSC_CACHE_DIR,
400
  WPSC_UPGRADES_DIR,
401
- WPSC_THEMES_PATH
402
  );
403
  foreach ( $folders as $folder ) {
404
  wp_mkdir_p( $folder );
@@ -588,7 +588,7 @@ function wpsc_create_or_update_tables( $debug = false ) {
588
  update_option( 'wpsc_database_check', $template_hash );
589
  return true;
590
  } else {
591
- return false;
592
  }
593
  }
594
 
398
  WPSC_USER_UPLOADS_DIR,
399
  WPSC_CACHE_DIR,
400
  WPSC_UPGRADES_DIR,
401
+ // WPSC_THEMES_PATH
402
  );
403
  foreach ( $folders as $folder ) {
404
  wp_mkdir_p( $folder );
588
  update_option( 'wpsc_database_check', $template_hash );
589
  return true;
590
  } else {
591
+ return $failure_reasons;
592
  }
593
  }
594
 
wpsc-includes/ajax.functions.php CHANGED
@@ -1,727 +1,5 @@
1
  <?php
2
 
3
- /**
4
- * WP eCommerce AJAX and Init functions
5
- *
6
- * These are the WPSC AJAX and Init functions
7
- *
8
- * @package wp-e-commerce
9
- * @since 3.7
10
- */
11
- function wpsc_special_widget() {
12
- wpsc_add_to_cart();
13
- }
14
-
15
- if ( isset( $_REQUEST['wpsc_ajax_action'] ) && ($_REQUEST['wpsc_ajax_action'] == 'special_widget' || $_REQUEST['wpsc_ajax_action'] == 'donations_widget') ) {
16
- add_action( 'init', 'wpsc_special_widget' );
17
- }
18
-
19
- function wpsc_add_to_cart() {
20
- global $wpsc_cart;
21
-
22
- /// default values
23
- $default_parameters['variation_values'] = null;
24
- $default_parameters['quantity'] = 1;
25
- $default_parameters['provided_price'] = null;
26
- $default_parameters['comment'] = null;
27
- $default_parameters['time_requested'] = null;
28
- $default_parameters['custom_message'] = null;
29
- $default_parameters['file_data'] = null;
30
- $default_parameters['is_customisable'] = false;
31
- $default_parameters['meta'] = null;
32
-
33
- $provided_parameters = array();
34
- $post_type_object = get_post_type_object( 'wpsc-product' );
35
- $permitted_post_statuses = current_user_can( $post_type_object->cap->edit_posts ) ? array( 'private', 'draft', 'pending', 'publish' ) : array( 'publish' );
36
-
37
- /// sanitise submitted values
38
- $product_id = apply_filters( 'wpsc_add_to_cart_product_id' , (int) $_POST['product_id'] );
39
- $product = apply_filters( 'wpsc_add_to_cart_product_object', get_post( $product_id, OBJECT, 'display' ) );
40
-
41
- if ( ! in_array( $product->post_status, $permitted_post_statuses ) || 'wpsc-product' != $product->post_type )
42
- return false;
43
-
44
- // compatibility with older themes
45
- if ( isset( $_POST['wpsc_quantity_update'] ) && is_array( $_POST['wpsc_quantity_update'] ) ) {
46
- $_POST['wpsc_quantity_update'] = $_POST['wpsc_quantity_update'][$product_id];
47
- }
48
-
49
- if(isset($_POST['variation'])){
50
- foreach ( (array) $_POST['variation'] as $key => $variation ) {
51
- $provided_parameters['variation_values'][ (int) $key ] = (int) $variation;
52
- }
53
-
54
- if ( count( $provided_parameters['variation_values'] ) > 0 ) {
55
- $variation_product_id = wpsc_get_child_object_in_terms( $product_id, $provided_parameters['variation_values'], 'wpsc-variation' );
56
- if ( $variation_product_id > 0 ) {
57
- $product_id = $variation_product_id;
58
- }
59
- }
60
-
61
- }
62
-
63
- if ( (isset( $_POST['quantity'] ) && $_POST['quantity'] > 0) && (!isset( $_POST['wpsc_quantity_update'] )) ) {
64
- $provided_parameters['quantity'] = (int) $_POST['quantity'];
65
- } else if ( isset( $_POST['wpsc_quantity_update'] ) ) {
66
- $wpsc_cart->remove_item( $_POST['key'] );
67
- $provided_parameters['quantity'] = (int) $_POST['wpsc_quantity_update'];
68
- }
69
-
70
- if ( isset( $_POST['is_customisable'] ) &&
71
- 'true' == $_POST['is_customisable'] ) {
72
- $provided_parameters['is_customisable'] = true;
73
-
74
- if ( isset( $_POST['custom_text'] ) ) {
75
- $provided_parameters['custom_message'] = stripslashes( $_POST['custom_text'] );
76
- }
77
- if ( isset( $_FILES['custom_file'] ) ) {
78
- $provided_parameters['file_data'] = $_FILES['custom_file'];
79
- }
80
- }
81
-
82
- if ( isset( $_POST['donation_price'] ) && ( (float) $_POST['donation_price'] > 0 ) ) {
83
- $provided_parameters['provided_price'] = (float) $_POST['donation_price'];
84
- }
85
-
86
- $parameters = array_merge( $default_parameters, (array) $provided_parameters );
87
-
88
- $cart_item = $wpsc_cart->set_item( $product_id, $parameters );
89
-
90
- if ( is_object( $cart_item ) ) {
91
- do_action( 'wpsc_add_to_cart', $product, $cart_item );
92
- $cart_messages[] = str_replace( "[product_name]", $cart_item->get_title(), __( 'You just added "[product_name]" to your cart.', 'wpsc' ) );
93
- } else {
94
- if ( $parameters['quantity'] <= 0 ) {
95
- $cart_messages[] = __( 'Sorry, but you cannot add zero items to your cart', 'wpsc' );
96
- } else if ( $wpsc_cart->get_remaining_quantity( $product_id, $parameters['variation_values'], $parameters['quantity'] ) > 0 ) {
97
- $quantity = $wpsc_cart->get_remaining_quantity( $product_id, $parameters['variation_values'], $parameters['quantity'] );
98
- $cart_messages[] = sprintf( _n( 'Sorry, but there is only %s of this item in stock.', 'Sorry, but there are only %s of this item in stock.', $quantity, 'wpsc' ), $quantity );
99
- } else {
100
- $cart_messages[] = sprintf( __( 'Sorry, but the item "%s" is out of stock.', 'wpsc' ), $product->post_title );
101
- }
102
- }
103
-
104
-
105
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
106
-
107
- $json_response = array( 'cart_messages' => $cart_messages, 'product_id' => $product_id, 'cart_total' => wpsc_cart_total() );
108
-
109
- $output = _wpsc_ajax_get_cart( false, $cart_messages );
110
-
111
- $json_response = $json_response + $output;
112
-
113
- if ( is_numeric( $product_id ) && 1 == get_option( 'fancy_notifications' ) )
114
- $json_response['fancy_notification'] = str_replace( array( "\n", "\r" ), array( '\n', '\r' ), fancy_notification_content( $cart_messages ) );
115
-
116
- die( json_encode( $json_response ) );
117
- }
118
- }
119
-
120
- add_action( 'wp_ajax_add_to_cart' , 'wpsc_add_to_cart' );
121
- add_action( 'wp_ajax_nopriv_add_to_cart', 'wpsc_add_to_cart' );
122
-
123
- // execute on POST and GET
124
- if ( isset( $_REQUEST['wpsc_ajax_action'] ) && 'add_to_cart' == $_REQUEST['wpsc_ajax_action'] ) {
125
- add_action( 'init', 'wpsc_add_to_cart' );
126
- }
127
-
128
- function wpsc_get_cart() {
129
- _wpsc_ajax_get_cart();
130
- }
131
-
132
- add_action( 'wp_ajax_get_cart' , 'wpsc_get_cart' );
133
- add_action( 'wp_ajax_nopriv_get_cart', 'wpsc_get_cart' );
134
-
135
- /**
136
- * empty cart function, used through ajax and in normal page loading.
137
- * No parameters, returns nothing
138
- */
139
- function wpsc_empty_cart() {
140
- global $wpsc_cart;
141
- $wpsc_cart->empty_cart( false );
142
-
143
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
144
- $output = _wpsc_ajax_get_cart( false );
145
- die( json_encode( $output ) );
146
- }
147
- }
148
-
149
- add_action( 'wp_ajax_empty_cart' , 'wpsc_empty_cart' );
150
- add_action( 'wp_ajax_nopriv_empty_cart', 'wpsc_empty_cart' );
151
-
152
- // execute on POST and GET
153
- if ( isset( $_REQUEST['wpsc_ajax_action'] ) && ( 'empty_cart' == $_REQUEST['wpsc_ajax_action'] || isset( $_GET['sessionid'] ) && $_GET['sessionid'] > 0 ) ) {
154
- add_action( 'init', 'wpsc_empty_cart' );
155
- }
156
-
157
- /**
158
- * coupons price, used through ajax and in normal page loading.
159
- * No parameters, returns nothing
160
- */
161
- function wpsc_coupon_price( $currCoupon = '' ) {
162
- global $wpsc_cart, $wpsc_coupons;
163
- if ( isset( $_POST['coupon_num'] ) && $_POST['coupon_num'] != '' ) {
164
- $coupon = esc_sql( $_POST['coupon_num'] );
165
- wpsc_update_customer_meta( 'coupon', $coupon );
166
- $wpsc_coupons = new wpsc_coupons( $coupon );
167
-
168
- if ( $wpsc_coupons->validate_coupon() ) {
169
- $discountAmount = $wpsc_coupons->calculate_discount();
170
- $wpsc_cart->apply_coupons( $discountAmount, $coupon );
171
- $wpsc_coupons->errormsg = false;
172
- } else {
173
- $wpsc_coupons->errormsg = true;
174
- $wpsc_cart->coupons_amount = 0;
175
- $wpsc_cart->coupons_name = '';
176
- wpsc_delete_customer_meta( 'coupon' );
177
- }
178
- } else if ( (!isset( $_POST['coupon_num'] ) || $_POST['coupon_num'] == '') && $currCoupon == '' ) {
179
- $wpsc_cart->coupons_amount = 0;
180
- $wpsc_cart->coupons_name = '';
181
- } else if ( $currCoupon != '' ) {
182
- $coupon = esc_sql( $currCoupon );
183
- wpsc_update_customer_meta( 'coupon', $coupon );
184
- $wpsc_coupons = new wpsc_coupons( $coupon );
185
-
186
- if ( $wpsc_coupons->validate_coupon() ) {
187
- $discountAmount = $wpsc_coupons->calculate_discount();
188
- $wpsc_cart->apply_coupons( $discountAmount, $coupon );
189
- $wpsc_coupons->errormsg = false;
190
- }
191
- }
192
- }
193
-
194
- // execute on POST and GET
195
- if ( isset( $_POST['coupon_num'] ) ) {
196
- add_action( 'init', 'wpsc_coupon_price' );
197
- }
198
-
199
- /**
200
- * update quantity function, used through ajax and in normal page loading.
201
- * No parameters, returns nothing
202
- */
203
- function wpsc_update_item_quantity() {
204
- global $wpsc_cart;
205
-
206
- if ( is_numeric( $_POST['key'] ) ) {
207
- $key = (int)$_POST['key'];
208
- if ( $_POST['quantity'] > 0 ) {
209
- // if the quantity is greater than 0, update the item;
210
- $parameters['quantity'] = (int)$_POST['quantity'];
211
- $wpsc_cart->edit_item( $key, $parameters );
212
- } else {
213
- // if the quantity is 0, remove the item.
214
- $wpsc_cart->remove_item( $key );
215
- }
216
- $coupon = wpsc_get_customer_meta( 'coupon' );
217
- if ( $coupon ) {
218
- wpsc_coupon_price( $coupon );
219
- }
220
- }
221
- $die = ! ( ( isset( $_REQUEST['wpsc_ajax_action'] ) && 'true' == $_REQUEST['wpsc_ajax_action'] ) || ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) );
222
-
223
- _wpsc_ajax_get_cart( $die );
224
- }
225
-
226
- function _wpsc_get_alternate_html() {
227
- // These shenanigans are necessary for two reasons.
228
- // 1) Some hook into POST, some GET, some REQUEST. They check for the conditional params below.
229
- // 2) Most functions properly die() - that means that our output buffer stops there and won't continue on for our purposes.
230
- // If there is a better way to get that output without dying, I'm all ears. A nice slow HTTP request for now.
231
- $javascript = wp_remote_retrieve_body(
232
- wp_remote_post(
233
- add_query_arg(
234
- array( 'ajax' => 'true', 'wpsc_action' => 'wpsc_get_alternate_html', 'ajax' => 'true', 'wpsc_ajax_action' => 'add_to_cart' ), home_url() ),
235
- array( 'body' =>
236
- array(
237
- 'cart_messages' => $cart_messages, 'ajax' => 'true', 'wpsc_ajax_action' => 'add_to_cart', 'product_id' => $_REQUEST['product_id']
238
- )
239
- )
240
- )
241
- );
242
- return $javascript;
243
- }
244
-
245
- /**
246
- * Returns the jQuery that is likely included in calls to this action. For back compat only, will be deprecated soon.
247
- * Couldn't think up a better way to return this output, which most often will end in die(), without die()ing early ourselves.
248
- *
249
- * @param array $cart_messages [description]
250
- */
251
- function _wpsc_ajax_return_alternate_html() {
252
- $cart_messages = is_array( $_POST['cart_messages'] ) ? $_POST['cart_messages'] : array();
253
-
254
- do_action( 'wpsc_alternate_cart_html', $cart_messages );
255
- die;
256
- }
257
-
258
- if ( isset( $_REQUEST['wpsc_action'] ) && 'wpsc_get_alternate_html' == $_REQUEST['wpsc_action'] )
259
- add_action( 'init', '_wpsc_ajax_return_alternate_html' );
260
-
261
- /**
262
- * Returns the Cart Widget
263
- *
264
- * @param boolean $die Whether or not to return the output (for new JSON requests) or to die() on the old $output / action.
265
- * @param array $cart_message An array of cart messages to be optionally passed. Primarily passed via wpsc_add_to_cart().
266
- *
267
- * @since 3.8.11
268
- * @return mixed Returns an array of output data, alternatively
269
- */
270
- function _wpsc_ajax_get_cart( $die = true, $cart_messages = array() ) {
271
- $return = array();
272
-
273
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
274
-
275
- ob_start();
276
- include_once( wpsc_get_template_file_path( 'wpsc-cart_widget.php' ) );
277
-
278
- $output = ob_get_contents();
279
- ob_end_clean();
280
- $output = str_replace( array( '\n', '\r' ), '', $output );
281
-
282
- $return['widget_output'] = $output;
283
- $return['core_images_url'] = WPSC_CORE_IMAGES_URL;
284
-
285
- if ( 1 == get_option( 'show_sliding_cart' ) || empty( $cart_messages ) ) {
286
- if ( wpsc_cart_item_count() ) {
287
- $_SESSION['slider_state'] = 1;
288
- $return['sliding_cart_state'] = 'show';
289
- } else {
290
- $_SESSION['slider_state'] = 0;
291
- $return['sliding_cart_state'] = 'hide';
292
- }
293
- }
294
-
295
- $action_output = '';
296
- if ( has_action( 'wpsc_alternate_cart_html' ) ) {
297
- //Deprecated action. Do not use. We now have a custom JS event called 'wpsc_fancy_notification'. There is access to the complete $json_response object.
298
- ob_start();
299
-
300
- echo _wpsc_get_alternate_html();
301
- $action_output = ob_get_contents();
302
-
303
- ob_end_clean();
304
- }
305
-
306
- if ( ! empty( $action_output ) ) {
307
- _wpsc_doing_it_wrong( 'wpsc_alternate_cart_html', __( 'As of WPeC 3.8.11, it is improper to hook into "wpsc_alternate_cart_html" to output javascript. We now have a custom javascript event called "wpsc_fancy_notification" you can hook into.', 'wpsc' ), '3.8.11' );
308
- $return['wpsc_alternate_cart_html'] = $action_output;
309
- }
310
- }
311
-
312
- if ( $die )
313
- die( $output . $action_output );
314
- else
315
- return $return;
316
- }
317
-
318
- // execute on POST and GET
319
- if ( isset( $_REQUEST['wpsc_update_quantity'] ) && ($_REQUEST['wpsc_update_quantity'] == 'true') ) {
320
- add_action( 'init', 'wpsc_update_item_quantity' );
321
- }
322
-
323
- function wpsc_update_product_rating() {
324
- global $wpdb;
325
- $nowtime = time();
326
- $product_id = absint( $_POST['product_id'] );
327
- $ip_number = $_SERVER['REMOTE_ADDR'];
328
- $rating = absint( $_POST['product_rating'] );
329
-
330
- $cookie_data = explode( ",", $_COOKIE['voting_cookie'][$product_id] );
331
-
332
- if ( is_numeric( $cookie_data[0] ) && ($cookie_data[0] > 0) ) {
333
- $vote_id = absint( $cookie_data[0] );
334
- $wpdb->update( WPSC_TABLE_PRODUCT_RATING, array(
335
- 'rated' => $rating
336
- ), array( 'id' => $vote_id ) );
337
- } else {
338
- $wpdb->insert( WPSC_TABLE_PRODUCT_RATING, array(
339
- 'ipnum' => $ip_number,
340
- 'productid' => $product_id,
341
- 'rated' => $rating,
342
- 'time' => $nowtime
343
- ) );
344
- $data = $wpdb->get_results( "SELECT `id`,`rated` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `ipnum`='" . $ip_number . "' AND `productid` = '" . $product_id . "' AND `rated` = '" . $rating . "' AND `time` = '" . $nowtime . "' ORDER BY `id` DESC LIMIT 1", ARRAY_A );
345
- $vote_id = $data[0]['id'];
346
- setcookie( "voting_cookie[$prodid]", ($vote_id . "," . $rating ), time() + (60 * 60 * 24 * 360) );
347
- }
348
- if ( $_POST['ajax'] == 'true' ) {
349
-
350
- exit();
351
- }
352
- }
353
-
354
- // execute on POST and GET
355
- if ( isset( $_REQUEST['wpsc_ajax_action'] ) && ($_REQUEST['wpsc_ajax_action'] == 'rate_product') ) {
356
- add_action( 'init', 'wpsc_update_product_rating' );
357
- }
358
-
359
-
360
- /**
361
- * update_shipping_price function, used through ajax and in normal page loading.
362
- * No parameters, returns nothing
363
- */
364
- function wpsc_update_shipping_price() {
365
- global $wpsc_cart;
366
- $quote_shipping_method = $_POST['method'];
367
- $quote_shipping_option = $_POST['option'];
368
-
369
- if ( ! empty( $quote_shipping_option ) && ! empty( $quote_shipping_method ) ) {
370
- $wpsc_cart->update_shipping( $quote_shipping_method, $quote_shipping_option );
371
-
372
- $json_response = array( 'shipping' => wpsc_cart_shipping(), 'coupon' => wpsc_coupon_amount(), 'cart_total' => wpsc_cart_total(), 'tax' => wpsc_cart_tax() );
373
-
374
- echo json_encode( $json_response );
375
- }
376
-
377
- exit();
378
- }
379
-
380
- add_action( 'wp_ajax_update_shipping_price' , 'wpsc_update_shipping_price' );
381
- add_action( 'wp_ajax_nopriv_update_shipping_price', 'wpsc_update_shipping_price' );
382
-
383
- /**
384
- * update_shipping_price function, used through ajax and in normal page loading.
385
- * No parameters, returns nothing
386
- */
387
- function wpsc_get_rating_count() {
388
- global $wpdb, $wpsc_cart;
389
- $prodid = $_POST['product_id'];
390
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `productid` = %d", $prodid ) );
391
- echo $count . "," . absint( $prodid );
392
- exit();
393
- }
394
-
395
- // execute on POST and GET
396
- if ( isset( $_REQUEST['get_rating_count'] ) && ($_REQUEST['get_rating_count'] == 'true') && is_numeric( $_POST['product_id'] ) ) {
397
- add_action( 'init', 'wpsc_get_rating_count' );
398
- }
399
-
400
- /**
401
- * update_product_page_price function, used through ajax with variations
402
- * No parameters, returns nothing
403
- */
404
- function wpsc_update_product_price() {
405
-
406
- if ( empty( $_POST['product_id'] ) || ! is_numeric( $_POST['product_id'] ) )
407
- return;
408
-
409
- $from = '';
410
- $change_price = true;
411
- $product_id = (int) $_POST['product_id'];
412
- $variations = array();
413
- $response = array(
414
- 'product_id' => $product_id,
415
- 'variation_found' => false,
416
- );
417
- if ( ! empty( $_POST['variation'] ) ) {
418
- foreach ( $_POST['variation'] as $variation ) {
419
- if ( is_numeric( $variation ) ) {
420
- $variations[] = (int)$variation;
421
- }
422
- }
423
-
424
- do_action( 'wpsc_update_variation_product', $product_id, $variations );
425
-
426
- $stock = wpsc_check_variation_stock_availability( $product_id, $variations );
427
-
428
- if ( $stock !== false ) {
429
- $response['variation_found'] = true;
430
- if ( $stock === 0 ) {
431
- $response += array(
432
- 'product_msg' => __( 'Sorry, but this variation is out of stock.', 'wpsc' ),
433
- 'variation_msg' => __( 'Variation not in stock', 'wpsc' ),
434
- 'stock_available' => false,
435
- );
436
- } else {
437
- $response += array(
438
- 'variation_msg' => __( 'Product in stock', 'wpsc' ),
439
- 'stock_available' => true,
440
- );
441
- }
442
-
443
- if ( $change_price ) {
444
- $old_price = wpsc_calculate_price( $product_id, $variations, false );
445
- $you_save_amount = wpsc_you_save( array( 'product_id' => $product_id, 'type' => 'amount', 'variations' => $variations ) );
446
- $you_save_percentage = wpsc_you_save( array( 'product_id' => $product_id, 'variations' => $variations ) );
447
- $price = wpsc_calculate_price( $product_id, $variations, true );
448
- $response += array(
449
- 'old_price' => wpsc_currency_display( $old_price, array( 'display_as_html' => false ) ),
450
- 'numeric_old_price' => (float) $old_price,
451
- 'you_save' => wpsc_currency_display( $you_save_amount, array( 'display_as_html' => false ) ) . "! (" . $you_save_percentage . "%)",
452
- 'price' => $from . wpsc_currency_display( $price, array( 'display_as_html' => false ) ),
453
- 'numeric_price' => (float) $price,
454
- );
455
- }
456
- }
457
- }
458
-
459
- echo json_encode( $response );
460
- exit();
461
- }
462
-
463
- add_action( 'wp_ajax_update_product_price' , 'wpsc_update_product_price' );
464
- add_action( 'wp_ajax_nopriv_update_product_price', 'wpsc_update_product_price' );
465
-
466
- // execute on POST and GET
467
- if ( isset( $_REQUEST['update_product_price'] ) && 'true' == $_REQUEST['update_product_price'] && ! empty( $_POST['product_id'] ) && is_numeric( $_POST['product_id'] ) ) {
468
- add_action( 'init', 'wpsc_update_product_price' );
469
- }
470
-
471
- /**
472
- * update location function, used through ajax and in normal page loading.
473
- * No parameters, returns nothing
474
- */
475
- function wpsc_update_location() {
476
- global $wpdb, $wpsc_cart;
477
-
478
- $delivery_country = '';
479
- $billing_country = '';
480
- if ( ! empty( $_POST['country'] ) ) {
481
- $delivery_country = $_POST['country'];
482
- $billing_country = wpsc_get_customer_meta( 'billing_country' );
483
- $delivery_region = wpsc_get_customer_meta( 'shipping_region' );
484
- $billing_region = wpsc_get_customer_meta( 'billing_region' );
485
- $shipping_zipcode = wpsc_get_customer_meta( 'shipping_zipcode' );
486
-
487
- if ( ! $billing_country )
488
- wpsc_update_customer_meta( 'billing_country', $_POST['country'] );
489
-
490
- if ( ! empty( $_POST['region'] ) ) {
491
- $delivery_region = $_POST['region'];
492
- if ( ! $billing_region )
493
- $billing_region = $_POST['region'];
494
- } else if ( ! $billing_region ) {
495
- $billing_region = $delivery_region = get_option( 'base_region' );
496
- }
497
-
498
- if ( ! $delivery_region )
499
- $delivery_region = $billing_region;
500
- }
501
-
502
- if ( ! empty( $_POST['zipcode'] ) )
503
- $shipping_zipcode = $_POST['zipcode'];
504
-
505
- $delivery_region_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('%s')", $delivery_country ) );
506
- if ( $delivery_region_count < 1 )
507
- $delivery_region = '';
508
-
509
- $selected_region_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('%s')", $billing_country ) );
510
- if ( $selected_region_count < 1 )
511
- $billing_region = '';
512
-
513
- wpsc_update_customer_meta( 'shipping_country' , $delivery_country );
514
- wpsc_update_customer_meta( 'shipping_region' , $delivery_region );
515
- wpsc_update_customer_meta( 'billing_country' , $billing_country );
516
- wpsc_update_customer_meta( 'billing_region' , $billing_region );
517
- wpsc_update_customer_meta( 'shipping_zip' , $shipping_zipcode );
518
-
519
- $wpsc_cart->update_location();
520
- $wpsc_cart->get_shipping_method();
521
- $wpsc_cart->get_shipping_option();
522
- if ( $wpsc_cart->selected_shipping_method != '' ) {
523
- $wpsc_cart->update_shipping( $wpsc_cart->selected_shipping_method, $wpsc_cart->selected_shipping_option );
524
- }
525
-
526
- if ( wpsc_get_customer_meta( 'shipping_same_as_billing' ) && ( $delivery_country != $billing_country || $delivery_region != $billing_region ) )
527
- wpsc_update_customer_meta( 'shipping_same_as_billing', false );
528
-
529
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && 'update_location' == $_REQUEST['action'] )
530
- exit;
531
- }
532
-
533
- add_action( 'wp_ajax_update_location' , 'wpsc_update_location' );
534
- add_action( 'wp_ajax_nopriv_update_location', 'wpsc_update_location' );
535
-
536
- // execute on POST and GET
537
- if ( isset( $_REQUEST['wpsc_ajax_actions'] ) && 'update_location' == $_REQUEST['wpsc_ajax_actions'] ) {
538
- add_action( 'init', 'wpsc_update_location' );
539
- }
540
-
541
-
542
- function wpsc_cart_html_page() {
543
- require_once(WPSC_FILE_PATH . "/wpsc-includes/shopping_cart_container.php");
544
- exit();
545
- }
546
-
547
- // execute on POST and GET
548
- if ( isset( $_REQUEST['wpsc_action'] ) && ($_REQUEST['wpsc_action'] == 'cart_html_page') ) {
549
- add_action( 'init', 'wpsc_cart_html_page', 110 );
550
- }
551
-
552
- // Populate Also Bought products on checkout
553
- if ( get_option( 'wpsc_also_bought' ) == 1 )
554
- add_action( 'wpsc_submit_checkout', 'wpsc_populate_also_bought_list' );
555
-
556
-
557
- /**
558
- * submit checkout function, used through ajax and in normal page loading.
559
- * No parameters, returns nothing
560
- */
561
- function wpsc_submit_checkout( $collected_data = true ) {
562
- global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways;
563
-
564
- $num_items = 0;
565
- $use_shipping = 0;
566
- $disregard_shipping = 0;
567
-
568
- do_action( 'wpsc_before_submit_checkout' );
569
-
570
- $error_messages = wpsc_get_customer_meta( 'checkout_misc_error_messages' );
571
- if ( ! is_array( $error_messages ) )
572
- $error_messages = array();
573
- $wpsc_checkout = new wpsc_checkout();
574
- $selected_gateways = get_option( 'custom_gateway_options' );
575
- $submitted_gateway = isset( $_POST['custom_gateway'] ) ? $_POST['custom_gateway'] : '';
576
- $options = get_option( 'custom_shipping_options' );
577
- if ( $collected_data ) {
578
- $form_validity = $wpsc_checkout->validate_forms();
579
- extract( $form_validity ); // extracts $is_valid and $error_messages
580
-
581
- if ( wpsc_has_tnc() && ( ! isset( $_POST['agree'] ) || $_POST['agree'] != 'yes' ) ) {
582
- $error_messages[] = __( 'Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc' );
583
- $is_valid = false;
584
- }
585
- } else {
586
- $is_valid = true;
587
- $error_messages = array();
588
- }
589
-
590
- $selectedCountry = $wpdb->get_results( $wpdb->prepare( "SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode = '%s' ", wpsc_get_customer_meta( 'shipping_country' ) ), ARRAY_A );
591
- foreach ( $wpsc_cart->cart_items as $cartitem ) {
592
- if( ! empty( $cartitem->meta[0]['no_shipping'] ) ) continue;
593
- $categoriesIDs = $cartitem->category_id_list;
594
- foreach ( (array)$categoriesIDs as $catid ) {
595
- if ( is_array( $catid ) )
596
- $countries = wpsc_get_meta( $catid[0], 'target_market', 'wpsc_category' );
597
- else
598
- $countries = wpsc_get_meta( $catid, 'target_market', 'wpsc_category' );
599
-
600
- if ( !empty($countries) && !in_array( $selectedCountry[0]['id'], (array)$countries ) ) {
601
- $errormessage = sprintf( __( '%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc' ), $cartitem->get_title(), $selectedCountry[0]['country'] );
602
- wpsc_update_customer_meta( 'category_shipping_conflict', $errormessage );
603
- $is_valid = false;
604
- }
605
- }
606
- //count number of items, and number of items using shipping
607
- $num_items++;
608
- if ( $cartitem->uses_shipping != 1 )
609
- $disregard_shipping++;
610
- else
611
- $use_shipping++;
612
-
613
- }
614
- if ( array_search( $submitted_gateway, $selected_gateways ) !== false )
615
- wpsc_update_customer_meta( 'selected_gateway', $submitted_gateway );
616
- else
617
- $is_valid = false;
618
-
619
- if ( $collected_data ) {
620
- if ( get_option( 'do_not_use_shipping' ) == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && ( $num_items != $disregard_shipping ) ) {
621
- $error_messages[] = __( 'You must select a shipping method, otherwise we cannot process your order.', 'wpsc' );
622
- $is_valid = false;
623
- }
624
- if ( (get_option( 'do_not_use_shipping' ) != 1) && (in_array( 'ups', (array)$options )) && ! wpsc_get_customer_meta( 'shipping_zip' ) && ( $num_items != $disregard_shipping ) ) {
625
- wpsc_update_customer_meta( 'category_shipping_conflict', __( 'Please enter a Zipcode and click calculate to proceed', 'wpsc' ) );
626
- $is_valid = false;
627
- }
628
- }
629
-
630
- wpsc_update_customer_meta( 'checkout_misc_error_messages', $error_messages );
631
-
632
- if ( $is_valid == true ) {
633
- wpsc_delete_customer_meta( 'category_shipping_conflict' );
634
- // check that the submitted gateway is in the list of selected ones
635
- $sessionid = (mt_rand( 100, 999 ) . time());
636
- wpsc_update_customer_meta( 'checkout_session_id', $sessionid );
637
- $subtotal = $wpsc_cart->calculate_subtotal();
638
- if ( $wpsc_cart->has_total_shipping_discount() == false )
639
- $base_shipping = $wpsc_cart->calculate_base_shipping();
640
- else
641
- $base_shipping = 0;
642
-
643
- $delivery_country = $wpsc_cart->delivery_country;
644
- $delivery_region = $wpsc_cart->delivery_region;
645
-
646
- if ( wpsc_uses_shipping ( ) ) {
647
- $shipping_method = $wpsc_cart->selected_shipping_method;
648
- $shipping_option = $wpsc_cart->selected_shipping_option;
649
- } else {
650
- $shipping_method = '';
651
- $shipping_option = '';
652
- }
653
- if ( isset( $_POST['how_find_us'] ) )
654
- $find_us = $_POST['how_find_us'];
655
- else
656
- $find_us = '';
657
-
658
- //keep track of tax if taxes are exclusive
659
- $wpec_taxes_controller = new wpec_taxes_controller();
660
- if ( !$wpec_taxes_controller->wpec_taxes_isincluded() ) {
661
- $tax = $wpsc_cart->calculate_total_tax();
662
- $tax_percentage = $wpsc_cart->tax_percentage;
663
- } else {
664
- $tax = 0.00;
665
- $tax_percentage = 0.00;
666
- }
667
- $total = $wpsc_cart->calculate_total_price();
668
- $args = array(
669
- 'totalprice' => $total,
670
- 'statusno' => '0',
671
- 'sessionid' => $sessionid,
672
- 'user_ID' => (int) $user_ID,
673
- 'date' => time(),
674
- 'gateway' => $submitted_gateway,
675
- 'billing_country' => $wpsc_cart->selected_country,
676
- 'shipping_country' => $delivery_country,
677
- 'billing_region' => $wpsc_cart->selected_region,
678
- 'shipping_region' => $delivery_region,
679
- 'base_shipping' => $base_shipping,
680
- 'shipping_method' => $shipping_method,
681
- 'shipping_option' => $shipping_option,
682
- 'plugin_version' => WPSC_VERSION,
683
- 'discount_value' => $wpsc_cart->coupons_amount,
684
- 'discount_data' => $wpsc_cart->coupons_name,
685
- 'find_us' => $find_us,
686
- 'wpec_taxes_total' => $tax,
687
- 'wpec_taxes_rate' => $tax_percentage,
688
- );
689
- $purchase_log = new WPSC_Purchase_Log( $args );
690
- $purchase_log->save();
691
- $purchase_log_id = $purchase_log->get( 'id' );
692
- if ( $collected_data )
693
- $wpsc_checkout->save_forms_to_db( $purchase_log_id );
694
- $wpsc_cart->save_to_db( $purchase_log_id );
695
- $wpsc_cart->submit_stock_claims( $purchase_log_id );
696
- if( !isset( $our_user_id ) && isset( $user_ID ))
697
- $our_user_id = $user_ID;
698
- $wpsc_cart->log_id = $purchase_log_id;
699
- do_action( 'wpsc_submit_checkout', array( "purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id ) );
700
- do_action( 'wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log );
701
- }
702
- }
703
-
704
- // execute on POST and GET
705
- if ( isset( $_REQUEST['wpsc_action'] ) && ($_REQUEST['wpsc_action'] == 'submit_checkout') ) {
706
- add_action( 'init', 'wpsc_submit_checkout', 10, 0 );
707
- }
708
-
709
- function wpsc_product_rss() {
710
- global $wp_query, $wpsc_query, $_wpsc_is_in_custom_loop;
711
- list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query object
712
- $_wpsc_is_in_custom_loop = true;
713
- header( "Content-Type: application/xml; charset=UTF-8" );
714
- header( 'Content-Disposition: inline; filename="E-Commerce_Product_List.rss"' );
715
- require_once(WPSC_FILE_PATH . '/wpsc-includes/rss_template.php');
716
- list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query object
717
- $_wpsc_is_in_custom_loop = false;
718
- exit();
719
- }
720
-
721
- if ( isset( $_REQUEST['wpsc_action'] ) && ($_REQUEST['wpsc_action'] == "rss") ) {
722
- add_action( 'template_redirect', 'wpsc_product_rss', 80 );
723
- }
724
-
725
  function wpsc_gateway_notification() {
726
  global $wpsc_gateways;
727
  $gateway_name = $_GET['gateway'];
@@ -734,188 +12,8 @@ function wpsc_gateway_notification() {
734
  exit();
735
  }
736
 
737
- // execute on POST and GET
738
- if ( isset( $_REQUEST['wpsc_action'] ) && ($_REQUEST['wpsc_action'] == 'gateway_notification') ) {
739
  add_action( 'init', 'wpsc_gateway_notification' );
740
- }
741
-
742
- if ( isset( $_GET['termsandconds'] ) && 'true' == $_GET['termsandconds'] ) {
743
- add_action( 'init', 'wpsc_show_terms_and_conditions' );
744
- }
745
-
746
- function wpsc_show_terms_and_conditions() {
747
-
748
- echo wpautop( wp_kses_post( get_option( 'terms_and_conditions' ) ) );
749
- die();
750
- }
751
-
752
-
753
- /**
754
- * wpsc_change_tax function, used through ajax and in normal page loading.
755
- * No parameters, returns nothing
756
- */
757
- function wpsc_change_tax() {
758
- global $wpdb, $wpsc_cart;
759
-
760
- $form_id = absint( $_POST['form_id'] );
761
-
762
- $wpsc_selected_country = $wpsc_cart->selected_country;
763
- $wpsc_selected_region = $wpsc_cart->selected_region;
764
-
765
- $wpsc_delivery_country = $wpsc_cart->delivery_country;
766
- $wpsc_delivery_region = $wpsc_cart->delivery_region;
767
-
768
-
769
- $previous_country = wpsc_get_customer_meta( 'billing_country' );
770
- if ( isset( $_POST['billing_country'] ) ) {
771
- $wpsc_selected_country = $_POST['billing_country'];
772
- wpsc_update_customer_meta( 'billing_country', $wpsc_selected_country );
773
- }
774
-
775
- if ( isset( $_POST['billing_region'] ) ) {
776
- $wpsc_selected_region = absint( $_POST['billing_region'] );
777
- wpsc_update_customer_meta( 'billing_region', $wpsc_selected_region );
778
- }
779
-
780
- $check_country_code = $wpdb->get_var( $wpdb->prepare( "SELECT `country`.`isocode` FROM `" . WPSC_TABLE_REGION_TAX . "` AS `region` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `region`.`country_id` = `country`.`id` WHERE `region`.`id` = %d LIMIT 1", wpsc_get_customer_meta( 'billing_region' ) ) );
781
-
782
- if ( wpsc_get_customer_meta( 'billing_country' ) != $check_country_code ) {
783
- $wpsc_selected_region = null;
784
- }
785
-
786
- if ( isset( $_POST['shipping_country'] ) ) {
787
- $wpsc_delivery_country = $_POST['shipping_country'];
788
- wpsc_update_customer_meta( 'shipping_country', $wpsc_delivery_country );
789
- }
790
- if ( isset( $_POST['shipping_region'] ) ) {
791
- $wpsc_delivery_region = absint( $_POST['shipping_region'] );
792
- wpsc_update_customer_meta( 'shipping_region', $wpsc_delivery_region );
793
- }
794
-
795
- $check_country_code = $wpdb->get_var( $wpdb->prepare( "SELECT `country`.`isocode` FROM `" . WPSC_TABLE_REGION_TAX . "` AS `region` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `region`.`country_id` = `country`.`id` WHERE `region`.`id` = %d LIMIT 1", $wpsc_delivery_region ) );
796
-
797
- if ( $wpsc_delivery_country != $check_country_code ) {
798
- $wpsc_delivery_region = null;
799
- }
800
-
801
- $wpsc_cart->update_location();
802
- $wpsc_cart->get_shipping_method();
803
- $wpsc_cart->get_shipping_option();
804
- if ( $wpsc_cart->selected_shipping_method != '' ) {
805
- $wpsc_cart->update_shipping( $wpsc_cart->selected_shipping_method, $wpsc_cart->selected_shipping_option );
806
- }
807
-
808
- $tax = $wpsc_cart->calculate_total_tax();
809
- $total = wpsc_cart_total();
810
- $total_input = wpsc_cart_total(false);
811
- if($wpsc_cart->coupons_amount >= wpsc_cart_total(false) && !empty($wpsc_cart->coupons_amount)){
812
- $total = 0;
813
- }
814
- if ( $wpsc_cart->total_price < 0 ) {
815
- $wpsc_cart->coupons_amount += $wpsc_cart->total_price;
816
- $wpsc_cart->total_price = null;
817
- $wpsc_cart->calculate_total_price();
818
- }
819
-
820
- $delivery_country = wpsc_get_customer_meta( 'shipping_country' );
821
- $output = _wpsc_ajax_get_cart( false );
822
- $output = $output['widget_output'];
823
-
824
- $json_response = array();
825
-
826
- $json_response['delivery_country'] = esc_js( $delivery_country );
827
- $json_response['widget_output'] = $output;
828
- $json_response['shipping_keys'] = array();
829
- $json_response['cart_shipping'] = wpsc_cart_shipping();
830
- $json_response['form_id'] = $form_id;
831
- $json_response['tax'] = $tax;
832
- $json_response['display_tax'] = wpsc_cart_tax();
833
- $json_response['total'] = $total;
834
- $json_response['total_input'] = $total_input;
835
-
836
- if ( get_option( 'lock_tax' ) == 1 ) {
837
-
838
- $json_response['lock_tax'] = get_option( 'lock_tax' );
839
- $json_response['country_name'] = wpsc_get_country( $delivery_country );
840
-
841
- if ( $delivery_country == 'US' || $delivery_country == 'CA' ) {
842
- $output = wpsc_shipping_region_list( $delivery_country, wpsc_get_customer_meta( 'shipping_region' ) );
843
- $output = str_replace( array( "\n", "\r" ), '', $output );
844
- $json_response['shipping_region_list'] = $output;
845
- }
846
- }
847
-
848
- foreach ( $wpsc_cart->cart_items as $key => $cart_item ) {
849
- $json_response['shipping_keys'][$key] = wpsc_currency_display( $cart_item->shipping );
850
- }
851
-
852
- $form_selected_country = null;
853
- $form_selected_region = null;
854
- $onchange_function = null;
855
-
856
- if ( ! empty( $_POST['billing_country'] ) && $_POST['billing_country'] != 'undefined' && ! isset( $_POST['shipping_country'] ) ) {
857
- $form_selected_country = $wpsc_selected_country;
858
- $form_selected_region = $wpsc_selected_region;
859
- $onchange_function = 'set_billing_country';
860
- } else if ( ! empty( $_POST['shipping_country'] ) && $_POST['shipping_country'] != 'undefined' && ! isset( $_POST['billing_country'] ) ) {
861
- $form_selected_country = $wpsc_delivery_country;
862
- $form_selected_region = $wpsc_delivery_region;
863
- $onchange_function = 'set_shipping_country';
864
- }
865
-
866
- if ( $form_selected_country != null && $onchange_function != null ) {
867
-
868
- $checkoutfields = 'set_shipping_country' == $onchange_function;
869
- $region_list = wpsc_country_region_list( $form_id, false, $form_selected_country, $form_selected_region, $form_id, $checkoutfields );
870
-
871
- if ( $region_list != null ) {
872
- $json_response['region_list'] = str_replace( array( "\n", "\r" ), '', $region_list );
873
- }
874
- }
875
-
876
- echo json_encode( $json_response );
877
- exit();
878
- }
879
-
880
- add_action( 'wp_ajax_change_tax' , 'wpsc_change_tax' );
881
- add_action( 'wp_ajax_nopriv_change_tax', 'wpsc_change_tax' );
882
-
883
- // execute on POST and GET
884
- if ( isset( $_REQUEST['wpsc_ajax_action'] ) && 'change_tax' == $_REQUEST['wpsc_ajax_action'] ) {
885
- add_action( 'init', 'wpsc_change_tax' );
886
- }
887
-
888
- function _wpsc_change_profile_country() {
889
- global $wpdb;
890
-
891
- $country_field_id = absint( $_REQUEST['form_id'] );
892
- $country = $_REQUEST['country'];
893
-
894
- $sql = $wpdb->prepare( 'SELECT unique_name FROM `'.WPSC_TABLE_CHECKOUT_FORMS.'` WHERE `id`= %d', $country_field_id );
895
- $country_field_unique_name = $wpdb->get_var( $sql );
896
-
897
- $has_regions = wpsc_has_regions( $country );
898
- $response = array( 'has_regions' => $has_regions );
899
-
900
- $region_unique_name = 'shippingstate';
901
- if ( $country_field_unique_name == 'billingcountry' )
902
- $region_unique_name = 'billingstate';
903
-
904
- $sql = $wpdb->prepare( 'SELECT id FROM ' . WPSC_TABLE_CHECKOUT_FORMS . ' WHERE unique_name=%s AND active="1"', $region_unique_name );
905
- $response['region_field_id'] = $wpdb->get_var( $sql );
906
-
907
- if ( $has_regions )
908
- $response['html'] = "<select name='collected_data[" . $country_field_id . "][1]'>" . nzshpcrt_region_list( $country, '' ) . "</select>";
909
-
910
- echo json_encode( $response );
911
- exit;
912
- }
913
-
914
- add_action( 'wp_ajax_change_profile_country' , '_wpsc_change_profile_country' );
915
- add_action( 'wp_ajax_nopriv_change_profile_country', '_wpsc_change_profile_country' );
916
-
917
- if ( isset( $_REQUEST['wpsc_ajax_action'] ) && $_REQUEST['wpsc_ajax_action'] == 'change_profile_country' )
918
- add_action( 'init', '_wpsc_change_profile_country' );
919
 
920
  /**
921
  * wpsc scale image function, dynamically resizes an image oif no image already exists of that size.
@@ -1100,90 +198,4 @@ function _wpsc_force_download_file( $file_id ) {
1100
  }else{
1101
  wp_die(__('Sorry something has gone wrong with your download!', 'wpsc'));
1102
  }
1103
- }
1104
-
1105
- function wpsc_shipping_same_as_billing(){
1106
- wpsc_update_customer_meta( 'shipping_same_as_billing', $_POST['wpsc_shipping_same_as_billing'] );
1107
- }
1108
-
1109
- add_action('wp_ajax_wpsc_shipping_same_as_billing', 'wpsc_shipping_same_as_billing');
1110
-
1111
- add_action( 'wp_ajax_shipping_same_as_billing_update', 'wpsc_update_shipping_quotes_on_shipping_same_as_billing' );
1112
- add_action( 'wp_ajax_nopriv_shipping_same_as_billing_update', 'wpsc_update_shipping_quotes_on_shipping_same_as_billing' );
1113
-
1114
- function wpsc_update_shipping_quotes_on_shipping_same_as_billing() {
1115
- global $wpsc_cart;
1116
-
1117
- wpsc_update_location();
1118
-
1119
- if ( get_option( 'do_not_use_shipping' ) )
1120
- die( '-1' );
1121
-
1122
- if ( ! wpsc_have_shipping_quote() ) {
1123
- die( '0' );
1124
- }
1125
- else {
1126
- ?>
1127
- <tr class="wpsc_shipping_info">
1128
- <td colspan="5">
1129
- <?php _e( 'Please choose a country below to calculate your shipping costs', 'wpsc' ); ?>
1130
- </td>
1131
- </tr>
1132
-
1133
- <?php if ( ! wpsc_have_shipping_quote() ) : // No valid shipping quotes ?>
1134
- <?php if ( wpsc_have_valid_shipping_zipcode() ) : ?>
1135
- <tr class='wpsc_update_location'>
1136
- <td colspan='5' class='shipping_error' >
1137
- <?php _e('Please provide a Zipcode and click Calculate in order to continue.', 'wpsc'); ?>
1138
- </td>
1139
- </tr>
1140
- <?php else : ?>
1141
- <tr class='wpsc_update_location_error'>
1142
- <td colspan='5' class='shipping_error' >
1143
- <?php _e('Sorry, online ordering is unavailable to this destination and/or weight. Please double check your destination details.', 'wpsc'); ?>
1144
- </td>
1145
- </tr>
1146
- <?php endif; ?>
1147
- <?php endif; ?>
1148
- <tr class='wpsc_change_country'>
1149
- <td colspan='5'>
1150
- <form name='change_country' id='change_country' action='' method='post'>
1151
- <?php echo wpsc_shipping_country_list();?>
1152
- <input type='hidden' name='wpsc_update_location' value='true' />
1153
- <input type='submit' name='wpsc_submit_zipcode' value='<?php esc_attr_e( 'Calculate', 'wpsc' ); ?>' />
1154
- </form>
1155
- </td>
1156
- </tr>
1157
-
1158
- <?php if (wpsc_have_morethanone_shipping_quote()) :?>
1159
- <?php while (wpsc_have_shipping_methods()) : wpsc_the_shipping_method(); ?>
1160
- <?php if ( ! wpsc_have_shipping_quotes() ) { continue; } // Don't display shipping method if it doesn't have at least one quote ?>
1161
- <tr class='wpsc_shipping_header'><td class='shipping_header' colspan='5'><?php echo wpsc_shipping_method_name().__(' - Choose a Shipping Rate', 'wpsc'); ?> </td></tr>
1162
- <?php while (wpsc_have_shipping_quotes()) : wpsc_the_shipping_quote(); ?>
1163
- <tr class='<?php echo wpsc_shipping_quote_html_id(); ?>'>
1164
- <td class='wpsc_shipping_quote_name wpsc_shipping_quote_name_<?php echo wpsc_shipping_quote_html_id(); ?>' colspan='3'>
1165
- <label for='<?php echo wpsc_shipping_quote_html_id(); ?>'><?php echo wpsc_shipping_quote_name(); ?></label>
1166
- </td>
1167
- <td class='wpsc_shipping_quote_price wpsc_shipping_quote_price_<?php echo wpsc_shipping_quote_html_id(); ?>' style='text-align:center;'>
1168
- <label for='<?php echo wpsc_shipping_quote_html_id(); ?>'><?php echo wpsc_shipping_quote_value(); ?></label>
1169
- </td>
1170
- <td class='wpsc_shipping_quote_radio wpsc_shipping_quote_radio_<?php echo wpsc_shipping_quote_html_id(); ?>' style='text-align:center;'>
1171
- <?php if(wpsc_have_morethanone_shipping_methods_and_quotes()): ?>
1172
- <input type='radio' id='<?php echo wpsc_shipping_quote_html_id(); ?>' <?php echo wpsc_shipping_quote_selected_state(); ?> onclick='switchmethod("<?php echo wpsc_shipping_quote_name(); ?>", "<?php echo wpsc_shipping_method_internal_name(); ?>")' value='<?php echo wpsc_shipping_quote_value(true); ?>' name='shipping_method' />
1173
- <?php else: ?>
1174
- <input <?php echo wpsc_shipping_quote_selected_state(); ?> disabled='disabled' type='radio' id='<?php echo wpsc_shipping_quote_html_id(); ?>' value='<?php echo wpsc_shipping_quote_value(true); ?>' name='shipping_method' />
1175
- <?php wpsc_update_shipping_single_method(); ?>
1176
- <?php endif; ?>
1177
- </td>
1178
- </tr>
1179
- <?php endwhile; ?>
1180
- <?php endwhile; ?>
1181
- <?php endif; ?>
1182
-
1183
- <?php wpsc_update_shipping_multiple_methods(); ?>
1184
-
1185
- <?php
1186
-
1187
- }
1188
- exit;
1189
  }
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  function wpsc_gateway_notification() {
4
  global $wpsc_gateways;
5
  $gateway_name = $_GET['gateway'];
12
  exit();
13
  }
14
 
15
+ if ( isset( $_REQUEST['wpsc_action'] ) && ($_REQUEST['wpsc_action'] == 'gateway_notification') )
 
16
  add_action( 'init', 'wpsc_gateway_notification' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  /**
19
  * wpsc scale image function, dynamically resizes an image oif no image already exists of that size.
198
  }else{
199
  wp_die(__('Sorry something has gone wrong with your download!', 'wpsc'));
200
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  }
wpsc-includes/cart-item.class.php ADDED
@@ -0,0 +1,641 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WP eCommerce Cart Item class
4
+ *
5
+ * This is the class for WP eCommerce Cart Items,
6
+ * The Cart Items class handles the same, but for cart items themselves.
7
+ *
8
+ *
9
+ * @package wp-e-commerce
10
+ * @since 3.9
11
+ * @subpackage wpsc-cart-classes
12
+ */
13
+
14
+
15
+ /**
16
+ * The WPSC Cart Items class
17
+ */
18
+ class wpsc_cart_item {
19
+
20
+ // Variation Cache
21
+ private static $variation_cache;
22
+
23
+ // each cart item contains a reference to the cart that it is a member of
24
+ var $cart;
25
+
26
+ // provided values
27
+ var $product_id;
28
+ var $variation_values;
29
+ var $product_variations;
30
+ var $variation_data;
31
+ var $quantity = 1;
32
+ var $provided_price;
33
+
34
+
35
+ //values from the database
36
+ var $product_name;
37
+ var $category_list = array();
38
+ var $category_id_list = array();
39
+ var $unit_price;
40
+ var $total_price;
41
+ var $taxable_price = 0;
42
+ var $tax = 0;
43
+ var $weight = 0;
44
+ var $shipping = 0;
45
+ var $sku = null;
46
+ var $product_url;
47
+ var $image_id;
48
+ var $thumbnail_image;
49
+ var $custom_tax_rate = null;
50
+ var $meta = array();
51
+
52
+ private $item_meta = array();
53
+
54
+ var $is_donation = false;
55
+ var $apply_tax = true;
56
+ var $priceandstock_id;
57
+
58
+ // user provided values
59
+ var $custom_message = null;
60
+ var $custom_file = null;
61
+
62
+
63
+
64
+ /**
65
+ * add cart item meta value
66
+ * @access public
67
+ * @param meta key name
68
+ * @param meta key value
69
+ * @return previous meta value if it existed, nothing otherwise
70
+ */
71
+ function delete_meta($key) {
72
+
73
+ if ( isset($this->item_meta[$key]) ) {
74
+ $value = $this->item_meta[$key];
75
+ unset( $this->item_meta[$key]);
76
+ return $value;
77
+ }
78
+
79
+ return;
80
+ }
81
+
82
+
83
+ /**
84
+ * update or add cart item meta value
85
+ * @access public
86
+ * @param meta key name
87
+ * @param meta key value
88
+ * @return previous meta value if it existed, null otherwise
89
+ */
90
+ function update_meta($key,$value=null) {
91
+
92
+ if ( !isset( $value ) ) {
93
+ $result = $this->delete_meta($key);
94
+ } else {
95
+ $result = isset($this->meta[$key])?$this->meta[$key]:null;
96
+ $this->item_meta[$key] = $value;
97
+ }
98
+
99
+ return $result;
100
+ }
101
+
102
+
103
+ /**
104
+ * get cart item meta value
105
+ * @access public
106
+ * @param meta key name, optional, empty returns all meta as an array
107
+ * @return previous meta value if it existed, null otherwise
108
+ */
109
+ function get_meta($key='') {
110
+
111
+ if ( empty($key) ) {
112
+ $result = $this->item_meta;
113
+ } else {
114
+ $result = isset($this->item_meta[$key])?$this->item_meta[$key]:null;
115
+ }
116
+
117
+ return $result;
118
+ }
119
+
120
+
121
+ public static function refresh_variation_cache() {
122
+ global $wpsc_cart;
123
+
124
+ $variation_product_ids = array();
125
+
126
+ foreach ( $wpsc_cart->get_items() as $cart_item ) {
127
+ if ( ! empty( $cart_item->variation_values ) )
128
+ $variation_product_ids[] = $cart_item->product_id;
129
+ }
130
+
131
+ if ( empty( $variation_product_ids ) )
132
+ return;
133
+
134
+ self::$variation_cache = wp_get_object_terms( $variation_product_ids, 'wpsc-variation', array( 'fields' => 'all_with_object_id' ) );
135
+
136
+ foreach ( self::$variation_cache as $term ) {
137
+ if ( ! array_key_exists( $term->object_id, self::$variation_cache ) )
138
+ self::$variation_cache[$term->object_id] = array();
139
+
140
+ self::$variation_cache[$term->object_id][$term->parent] = $term->name;
141
+ }
142
+
143
+ return self::$variation_cache;
144
+ }
145
+
146
+ /**
147
+ * wpsc_cart_item constructor, requires a product ID and the parameters for the product
148
+ * @access public
149
+ *
150
+ * @param integer the product ID
151
+ * @param array parameters
152
+ * @param objcet the cart object
153
+ * @return boolean true on sucess, false on failure
154
+ */
155
+ function wpsc_cart_item($product_id, $parameters, $cart) {
156
+ global $wpdb;
157
+ // still need to add the ability to limit the number of an item in the cart at once.
158
+ // each cart item contains a reference to the cart that it is a member of, this makes that reference
159
+ // The cart is in the cart item, which is in the cart, which is in the cart item, which is in the cart, which is in the cart item...
160
+ $this->cart = &$cart;
161
+
162
+
163
+ foreach($parameters as $name => $value) {
164
+ $this->$name = $value;
165
+ }
166
+
167
+
168
+ $this->product_id = absint($product_id);
169
+ // to preserve backwards compatibility, make product_variations a reference to variations.
170
+ $this->product_variations =& $this->variation_values;
171
+
172
+
173
+
174
+ if(($parameters['is_customisable'] == true) && ($parameters['file_data'] != null)) {
175
+ $this->save_provided_file($this->file_data);
176
+ }
177
+ $this->refresh_item();
178
+
179
+ if ( ! has_action( 'wpsc_add_item', array( 'wpsc_cart_item', 'refresh_variation_cache' ) ) )
180
+ add_action( 'wpsc_add_item', array( 'wpsc_cart_item', 'refresh_variation_cache' ) );
181
+
182
+ }
183
+
184
+ /**
185
+ * update item method, currently can only update the quantity
186
+ * will require the parameters to update (no, you cannot change the product ID, delete the item and make a new one)
187
+ * @access public
188
+ *
189
+ * @param integer quantity
190
+ * #@param array parameters
191
+ * @return boolean true on sucess, false on failure
192
+ */
193
+ function update_item($quantity) {
194
+ $this->quantity = (int)$quantity;
195
+ $this->refresh_item();
196
+ $this->update_claimed_stock();
197
+
198
+
199
+ }
200
+
201
+ /**
202
+ * refresh_item method, refreshes the item, calculates the prices, gets the name
203
+ * @access public
204
+ *
205
+ * @return array array of monetary and other values
206
+ */
207
+ function refresh_item() {
208
+ global $wpdb, $wpsc_shipping_modules, $wpsc_cart;
209
+ $product_id = $this->product_id;
210
+ $product = get_post( $this->product_id );
211
+ $product_meta = get_metadata( 'post', $this->product_id );
212
+ $this->sku = get_post_meta( $product_id, '_wpsc_sku', true );
213
+ $price = get_post_meta( $product_id, '_wpsc_price', true );
214
+ $special_price = get_post_meta( $product_id, '_wpsc_special_price', true );
215
+ $product_meta = get_post_meta( $product_id, '_wpsc_product_metadata' );
216
+ $this->stock = get_post_meta( $product_id, '_wpsc_stock', true );
217
+ $this->is_donation = get_post_meta( $product_id, '_wpsc_is_donation', true );
218
+
219
+ if ( isset( $special_price ) && $special_price > 0 && $special_price < $price )
220
+ $price = $special_price;
221
+ $priceandstock_id = 0;
222
+ $this->weight = isset( $product_meta[0]['weight'] ) ? $product_meta[0]["weight"] : 0;
223
+ // if we are using table rate price
224
+ if ( isset( $product_meta[0]['table_rate_price'] ) ) {
225
+ $levels = $product_meta[0]['table_rate_price'];
226
+ if ( ! empty( $levels['quantity'] ) ) {
227
+ foreach((array)$levels['quantity'] as $key => $qty) {
228
+ if ($this->quantity >= $qty) {
229
+ $unit_price = $levels['table_price'][$key];
230
+ if ($unit_price != '')
231
+ $price = $unit_price;
232
+ }
233
+ }
234
+ }
235
+ }
236
+
237
+ $price = apply_filters( 'wpsc_price', $price, $product_id );
238
+
239
+ // create the string containing the product name.
240
+ $this->product_name = $this->get_title( 'raw' );
241
+ $this->priceandstock_id = $priceandstock_id;
242
+ $this->meta = $product_meta;
243
+
244
+ // change no_shipping to boolean and invert it
245
+ if( isset( $product_meta[0]['no_shipping'] ) && $product_meta[0]['no_shipping'] == 1)
246
+ $this->uses_shipping = 0 ;
247
+ else
248
+ $this->uses_shipping = 1;
249
+
250
+ $quantity_limited = get_product_meta($product_id, 'stock', true);
251
+ $this->has_limited_stock = (bool)$quantity_limited;
252
+
253
+ if($this->is_donation == 1)
254
+ $this->unit_price = (float) $this->provided_price;
255
+ else
256
+ $this->unit_price = (float) $price;
257
+
258
+ $this->total_price = $this->unit_price * $this->quantity;
259
+ if ( $product->post_parent )
260
+ $category_data = get_the_product_category( $product->post_parent );
261
+ else
262
+ $category_data = get_the_product_category( $product_id );
263
+
264
+ $this->category_list = array();
265
+ $this->category_id_list = array();
266
+
267
+ foreach( (array) $category_data as $category_row ) {
268
+ $this->category_list[] = $category_row->slug;
269
+ $this->category_id_list[] = $category_row->term_id;
270
+ }
271
+
272
+ //wpec_taxes - calculate product tax and add to total price
273
+ $wpec_taxes_controller = new wpec_taxes_controller();
274
+ if ( $wpec_taxes_controller->wpec_taxes_isincluded() && $wpec_taxes_controller->wpec_taxes_isenabled() ){
275
+ $taxes = $wpec_taxes_controller->wpec_taxes_calculate_included_tax($this);
276
+ $this->tax_rate = $taxes['rate'];
277
+ $this->tax = $taxes['tax'];
278
+ }
279
+
280
+ $this->product_url = get_permalink( $product_id );
281
+
282
+ if( ! is_array( $this->variation_values ) )
283
+ $attach_parent = $product_id;
284
+ else
285
+ $attach_parent = $wpdb->get_var( $wpdb->prepare("SELECT post_parent FROM $wpdb->posts WHERE ID = %d", $product_id ) );
286
+
287
+
288
+ $att_img_args = array(
289
+ 'post_type' => 'attachment',
290
+ 'numberposts' => 1,
291
+ 'post_parent' => $attach_parent,
292
+ 'orderby' => 'menu_order',
293
+ 'order' => 'DESC'
294
+ );
295
+
296
+ $attached_image = get_posts( $att_img_args );
297
+
298
+
299
+ if ( $attached_image != null )
300
+ $this->thumbnail_image = array_shift( $attached_image );
301
+
302
+ $product_files = (array) get_posts( array(
303
+ 'post_type' => 'wpsc-product-file',
304
+ 'post_parent' => $this->product_id,
305
+ 'numberposts' => -1,
306
+ 'post_status' => 'inherit'
307
+ ) );
308
+
309
+ if(count($product_files) > 0) {
310
+ $this->file_id = null;
311
+ $this->is_downloadable = true;
312
+ } else {
313
+ $this->file_id = null;
314
+ $this->is_downloadable = false;
315
+ }
316
+
317
+ if ( isset( $this->cart->selected_shipping_method ) && isset( $wpsc_shipping_modules[$this->cart->selected_shipping_method] ) && is_callable( array( $wpsc_shipping_modules[$this->cart->selected_shipping_method], "get_item_shipping" ) ) )
318
+ $this->shipping = $wpsc_shipping_modules[$this->cart->selected_shipping_method]->get_item_shipping( $this );
319
+
320
+ // update the claimed stock here
321
+ $this->update_claimed_stock();
322
+
323
+ do_action_ref_array( 'wpsc_refresh_item', array( &$this ) );
324
+ }
325
+
326
+ public function get_title( $mode = 'display' ) {
327
+
328
+ if ( ! get_post_field( 'post_parent', $this->product_id ) )
329
+ return get_post_field( 'post_title', $this->product_id);
330
+
331
+ if ( empty( self::$variation_cache ) )
332
+ self::refresh_variation_cache();
333
+
334
+ $primary_product_id = get_post_field( 'post_parent', $this->product_id );
335
+ $title = get_post_field( 'post_title', $primary_product_id );
336
+
337
+ if ( isset( self::$variation_cache[$this->product_id] ) ) {
338
+ ksort( self::$variation_cache[$this->product_id] );
339
+ $vars = implode( ', ', self::$variation_cache[$this->product_id] );
340
+ $title .= ' (' . $vars . ')';
341
+ }
342
+
343
+ $title = apply_filters( 'wpsc_cart_product_title', $title, $this->product_id );
344
+
345
+ if ( $mode == 'display' )
346
+ $title = apply_filters( 'the_title', $title );
347
+
348
+ return $title;
349
+ }
350
+
351
+ /**
352
+ * Calculate shipping method
353
+ * if no parameter passed, takes the currently selected method
354
+ * @access public
355
+ *
356
+ * @param string shipping method
357
+ * @return boolean true on sucess, false on failure
358
+ */
359
+
360
+ function calculate_shipping($method = null) {
361
+ global $wpdb, $wpsc_cart, $wpsc_shipping_modules;
362
+ $shipping = '';
363
+ if($method === null)
364
+ $method = $this->cart->selected_shipping_method;
365
+
366
+ if( $method && isset( $wpsc_shipping_modules[$method] ) && method_exists( $wpsc_shipping_modules[$method], "get_item_shipping" ))
367
+ $shipping = $wpsc_shipping_modules[$method]->get_item_shipping($this);
368
+
369
+ if($method == $this->cart->selected_shipping_method && !empty( $shipping ) )
370
+ $this->shipping = $shipping;
371
+
372
+ return $shipping;
373
+ }
374
+
375
+ /**
376
+ * user provided file method
377
+ * @access public
378
+ * @param string shipping method
379
+ * @return boolean true on sucess, false on failure
380
+ */
381
+
382
+ function save_provided_file($file_data) {
383
+ global $wpdb;
384
+ $accepted_file_types['mime'][] = 'image/jpeg';
385
+ $accepted_file_types['mime'][] = 'image/gif';
386
+ $accepted_file_types['mime'][] = 'image/png';
387
+
388
+ $accepted_file_types['mime'][] = 'image/pjpeg'; // Added for IE compatibility
389
+ $accepted_file_types['mime'][] = 'image/x-png'; // Added for IE compatibility
390
+
391
+ $accepted_file_types['ext'][] = 'jpeg';
392
+ $accepted_file_types['ext'][] = 'jpg';
393
+ $accepted_file_types['ext'][] = 'gif';
394
+ $accepted_file_types['ext'][] = 'png';
395
+
396
+ $accepted_file_types = apply_filters( 'wpsc_customer_upload_accepted_file_types', $accepted_file_types );
397
+
398
+ $can_have_uploaded_image = get_product_meta($this->product_id,'product_metadata',true);
399
+ $product = get_post($this->product_id);
400
+ if(0 != $product->post_parent ){
401
+ $product = get_post($product->post_parent);
402
+ $can_have_uploaded_image = get_product_meta($product->ID,'product_metadata',true);
403
+ }
404
+ $can_have_uploaded_image = $can_have_uploaded_image['can_have_uploaded_image'];
405
+ if ('on' == $can_have_uploaded_image || 1 == $can_have_uploaded_image) {
406
+ $name_parts = explode('.',basename($file_data['name']));
407
+ $extension = array_pop($name_parts);
408
+
409
+ if ( ( (
410
+ array_search( strtolower( $file_data['type'] ), $accepted_file_types['mime'] ) !== false ) ||
411
+ get_option( 'wpsc_check_mime_types' ) == 1 ) &&
412
+ array_search( strtolower( $extension ), $accepted_file_types['ext'] ) !== false ) {
413
+
414
+ if(is_file(WPSC_USER_UPLOADS_DIR.$file_data['name'])) {
415
+ $name_parts = explode('.',basename($file_data['name']));
416
+ $extension = array_pop($name_parts);
417
+ $name_base = implode('.',$name_parts);
418
+ $file_data['name'] = null;
419
+ $num = 2;
420
+ // loop till we find a free file name, first time I get to do a do loop in yonks
421
+ do {
422
+ $test_name = "{$name_base}-{$num}.{$extension}";
423
+ if(!file_exists(WPSC_USER_UPLOADS_DIR.$test_name))
424
+ $file_data['name'] = $test_name;
425
+ $num++;
426
+ } while ($file_data['name'] == null);
427
+ }
428
+
429
+ $unique_id = sha1(uniqid(rand(),true));
430
+ if(move_uploaded_file($file_data['tmp_name'], WPSC_USER_UPLOADS_DIR.$file_data['name']) )
431
+ $this->custom_file = array(
432
+ 'file_name' => $file_data['name'],
433
+ 'mime_type' => $file_data['type'],
434
+ 'unique_id' => $unique_id
435
+ );
436
+
437
+ }
438
+ }
439
+ }
440
+
441
+
442
+ /**
443
+ * update_claimed_stock method
444
+ * Updates the claimed stock table, to prevent people from having more than the existing stock in their carts
445
+ * @access public
446
+ *
447
+ * no parameters, nothing returned
448
+ */
449
+ function update_claimed_stock() {
450
+ global $wpdb;
451
+
452
+ if($this->has_limited_stock == true) {
453
+ $current_datetime = date( "Y-m-d H:i:s" );
454
+ $wpdb->query($wpdb->prepare("REPLACE INTO `".WPSC_TABLE_CLAIMED_STOCK."`
455
+ ( `product_id` , `variation_stock_id` , `stock_claimed` , `last_activity` , `cart_id` )
456
+ VALUES
457
+ ('%d', '%d', '%s', '%s', '%s');",
458
+ $this->product_id,
459
+ $this->priceandstock_id,
460
+ $this->quantity,
461
+ $current_datetime,
462
+ $this->cart->unique_id));
463
+ }
464
+ }
465
+
466
+
467
+ /**
468
+ * save to database method
469
+ * @access public
470
+ *
471
+ * @param integer purchase log id
472
+ */
473
+ function save_to_db($purchase_log_id) {
474
+ global $wpdb, $wpsc_shipping_modules;
475
+
476
+ $method = $this->cart->selected_shipping_method;
477
+ $shipping = 0;
478
+
479
+ if( ! empty( $method ) && method_exists( $wpsc_shipping_modules[$method], "get_item_shipping" ) )
480
+ $shipping = $wpsc_shipping_modules[$this->cart->selected_shipping_method]->get_item_shipping( $this );
481
+
482
+ if( $this->cart->has_total_shipping_discount() )
483
+ $shipping = 0;
484
+
485
+ $shipping = apply_filters( 'wpsc_item_shipping_amount_db', $shipping, $this );
486
+
487
+ //initialize tax variables
488
+ $tax = 0;
489
+ $tax_rate = 0;
490
+
491
+ //wpec_taxes - calculate product tax and add to total price
492
+ $wpec_taxes_controller = new wpec_taxes_controller();
493
+
494
+ if($wpec_taxes_controller->wpec_taxes_isincluded() && $wpec_taxes_controller->wpec_taxes_isenabled()){
495
+ $taxes = $wpec_taxes_controller->wpec_taxes_calculate_included_tax($this);
496
+ $tax_rate = $taxes['rate'];
497
+ $tax = $taxes['tax'];
498
+ }
499
+
500
+ $wpdb->insert(
501
+ WPSC_TABLE_CART_CONTENTS,
502
+ array(
503
+ 'prodid' => $this->product_id,
504
+ 'name' => $this->get_title(),
505
+ 'purchaseid' => $purchase_log_id,
506
+ 'price' => $this->unit_price,
507
+ 'pnp' => $shipping,
508
+ 'tax_charged' => $tax,
509
+ 'gst' => $tax_rate,
510
+ 'quantity' => $this->quantity,
511
+ 'donation' => $this->is_donation,
512
+ 'no_shipping' => 0,
513
+ 'custom_message' => $this->custom_message,
514
+ 'files' => serialize($this->custom_file),
515
+ 'meta' => NULL
516
+ ),
517
+ array(
518
+ '%d',
519
+ '%s',
520
+ '%d',
521
+ '%f',
522
+ '%f',
523
+ '%f',
524
+ '%f',
525
+ '%s',
526
+ '%d',
527
+ '%d',
528
+ '%s',
529
+ '%s',
530
+ '%s'
531
+ )
532
+ );
533
+
534
+ $cart_item_id = $wpdb->get_var( "SELECT " . $wpdb->insert_id . " AS `id` FROM `".WPSC_TABLE_CART_CONTENTS."` LIMIT 1");
535
+
536
+ wpsc_add_cart_item_meta($cart_item_id, 'sku', $this->sku, true );
537
+
538
+ if ( !empty( $this->item_meta) ) {
539
+ foreach( $this->item_meta as $item_meta_key => $item_meta_value ) {
540
+ wpsc_add_cart_item_meta( $cart_item_id, $item_meta_key, $item_meta_value, true );
541
+ }
542
+ }
543
+
544
+ $downloads = get_option('max_downloads');
545
+ if($this->is_downloadable == true) {
546
+
547
+ $product_files = (array)get_posts(array(
548
+ 'post_type' => 'wpsc-product-file',
549
+ 'post_parent' => $this->product_id,
550
+ 'numberposts' => -1,
551
+ 'post_status' => 'inherit'
552
+ ));
553
+ foreach($product_files as $file){
554
+ // if the file is downloadable, check that the file is real
555
+ $unique_id = sha1(uniqid(mt_rand(), true));
556
+
557
+ $wpdb->insert(
558
+ WPSC_TABLE_DOWNLOAD_STATUS,
559
+ array(
560
+ 'product_id' => $this->product_id,
561
+ 'fileid' => $file->ID,
562
+ 'purchid' => $purchase_log_id,
563
+ 'cartid' => $cart_item_id,
564
+ 'uniqueid' => $unique_id,
565
+ 'downloads' => $downloads,
566
+ 'active' => 0,
567
+ 'datetime' => date( 'Y-m-d H:i:s' )
568
+ ),
569
+ array(
570
+ '%d',
571
+ '%d',
572
+ '%d',
573
+ '%d',
574
+ '%s',
575
+ '%s',
576
+ '%d',
577
+ '%s',
578
+ )
579
+ );
580
+
581
+ $download_id = $wpdb->get_var( "SELECT " . $wpdb->insert_id . " AS `id` FROM `".WPSC_TABLE_DOWNLOAD_STATUS."` LIMIT 1");
582
+ wpsc_update_meta($download_id, '_is_legacy', 'false', 'wpsc_downloads');
583
+ }
584
+
585
+ }
586
+
587
+ do_action('wpsc_save_cart_item', $cart_item_id, $this->product_id);
588
+ }
589
+
590
+ }
591
+
592
+
593
+ /**
594
+ * Comparison object that helps with ordering cart items
595
+ *
596
+ * @since 3.8.9
597
+ * @access private
598
+ */
599
+ class _WPSC_Comparison
600
+ {
601
+ private $orderby = '';
602
+ private $order = 'ASC';
603
+
604
+ /**
605
+ * Constructor
606
+ *
607
+ * @param string $orderby Field to order by
608
+ * @param string $order Order direction, defaults to ASC for ascending.
609
+ */
610
+ public function __construct( $orderby, $order = 'ASC' ) {
611
+ $this->orderby = $orderby;
612
+ $this->order = $order;
613
+ }
614
+
615
+ /**
616
+ * This compare method can be passed into usort when sorting an array of object
617
+ *
618
+ * @since 3.8.9
619
+ *
620
+ * @param object|array $a
621
+ * @param object|array $b
622
+ * @return int See usort() documentation for the meaning of this return value.
623
+ */
624
+ public function compare( $a, $b ) {
625
+ // cast them all to object, just in case any of them is an array
626
+ $a = (object) $a;
627
+ $b = (object) $b;
628
+
629
+ $key = $this->orderby;
630
+
631
+ $val_a = isset( $a->$key ) ? $a->$key : 0;
632
+ $val_b = isset( $b->$key ) ? $b->$key : 0;
633
+
634
+ $diff = $val_a - $val_b;
635
+
636
+ if ( $this->order != 'ASC' )
637
+ $diff = $diff * -1;
638
+
639
+ return $diff;
640
+ }
641
+ }
wpsc-includes/cart.class.php CHANGED
@@ -2,9 +2,8 @@
2
  /**
3
  * WP eCommerce Cart and Cart Item classes
4
  *
5
- * These are the classes for the WP eCommerce Cart and Cart Items,
6
  * The Cart class handles adding, removing and adjusting items in the cart, and totaling up the cost of the items in the cart.
7
- * The Cart Items class handles the same, but for cart items themselves.
8
  *
9
  *
10
  * @package wp-e-commerce
@@ -70,39 +69,6 @@ function wpsc_cart_total( $forDisplay = true ) {
70
 
71
  }
72
 
73
- /**
74
- * Cart Total Widget
75
- *
76
- * Can be used to display the cart total excluding shipping, tax or coupons.
77
- *
78
- * @since 3.7.6.2
79
- *
80
- * @return string The subtotal price of the cart, with a currency sign.
81
- */
82
- function wpsc_cart_total_widget( $shipping = true, $tax = true, $coupons = true ) {
83
-
84
- global $wpsc_cart;
85
-
86
- $total = $wpsc_cart->calculate_subtotal();
87
-
88
- if ( $shipping ) {
89
- $total += $wpsc_cart->calculate_total_shipping();
90
- }
91
- if ( $tax && wpsc_tax_isincluded() == false ) {
92
- $total += $wpsc_cart->calculate_total_tax();
93
- }
94
- if ( $coupons ) {
95
- $total -= $wpsc_cart->coupons_amount;
96
- }
97
-
98
- if ( get_option( 'add_plustax' ) == 1 ) {
99
- return wpsc_currency_display( $wpsc_cart->calculate_subtotal() );
100
- } else {
101
- return wpsc_currency_display( $total );
102
- }
103
-
104
- }
105
-
106
  /**
107
  * nzshpcrt_overall_total_price function, no parameters
108
  * @return string the total price of the cart, with a currency sign
@@ -223,62 +189,6 @@ function wpsc_cart_item_categories($get_ids = false) {
223
  }
224
  }
225
 
226
- /**
227
- * have cart items function, no parameters
228
- * @return boolean true if there are cart items left
229
- */
230
- function wpsc_have_cart_items() {
231
- global $wpsc_cart;
232
- return $wpsc_cart->have_cart_items();
233
- }
234
-
235
- function wpsc_the_cart_item() {
236
- global $wpsc_cart;
237
- return $wpsc_cart->the_cart_item();
238
- }
239
-
240
-
241
-
242
- /**
243
- * cart item key function, no parameters
244
- * @return integer - the cart item key from the array in the cart object
245
- */
246
- function wpsc_the_cart_item_key() {
247
- global $wpsc_cart;
248
- return $wpsc_cart->current_cart_item;
249
- }
250
-
251
- /**
252
- * cart item name function, no parameters
253
- * @return string the cart item name
254
- */
255
- function wpsc_cart_item_name( $context = 'display' ) {
256
- global $wpsc_cart;
257
- $product_name = apply_filters( 'wpsc_cart_item_name', $wpsc_cart->cart_item->get_title(), $wpsc_cart->cart_item->product_id );
258
- return $product_name;
259
- }
260
- /**
261
- * cart item quantity function, no parameters
262
- * @return string the selected quantity of items
263
- */
264
- function wpsc_cart_item_product_id() {
265
- global $wpsc_cart;
266
- return $wpsc_cart->cart_item->product_id;
267
- }
268
- /**
269
- * cart item quantity function, no parameters
270
- * @return string the selected quantity of items
271
- */
272
- function wpsc_cart_item_quantity() {
273
- global $wpsc_cart;
274
- return $wpsc_cart->cart_item->quantity;
275
- }
276
-
277
- function wpsc_cart_item_quantity_single_prod($id) {
278
- global $wpsc_cart;
279
- return $wpsc_cart;
280
- }
281
-
282
  /**
283
  * Product Maximum Cart Quantity
284
  *
@@ -295,6 +205,22 @@ function wpsc_product_max_cart_quantity( $product_id = 0 ) {
295
  return apply_filters( 'wpsc_product_max_cart_quantity', 10000, $product_id );
296
  }
297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  /**
299
  * Validate Product Cart Quantity
300
  * Checks that the quantity is within the permitted bounds and return a valid quantity.
@@ -307,11 +233,15 @@ function wpsc_product_max_cart_quantity( $product_id = 0 ) {
307
  * @return int The maximum quantity that can be added to the cart.
308
  *
309
  * @uses wpsc_product_max_cart_quantity Gets the maximum product cart quantity.
 
310
  */
311
  function wpsc_validate_product_cart_quantity( $quantity, $product_id = 0 ) {
312
  $max_quantity = wpsc_product_max_cart_quantity( $product_id );
 
313
  if ( $quantity > $max_quantity )
314
  return $max_quantity;
 
 
315
  return $quantity;
316
  }
317
 
@@ -339,72 +269,6 @@ function _wpsc_validate_cart_product_quantity( $product_id, $parameters, $cart )
339
  add_action( 'wpsc_add_item', '_wpsc_validate_cart_product_quantity', 10, 3 );
340
  add_action( 'wpsc_edit_item', '_wpsc_validate_cart_product_quantity', 10, 3 );
341
 
342
- /**
343
- * cart item price function, no parameters
344
- * @return string the cart item price multiplied by the quantity, with a currency sign
345
- */
346
- function wpsc_cart_item_price($forDisplay = true) {
347
- global $wpsc_cart;
348
- if($forDisplay){
349
- return wpsc_currency_display($wpsc_cart->cart_item->total_price);
350
- }else{
351
- return $wpsc_cart->cart_item->total_price;
352
- }
353
- }
354
-
355
- /**
356
- * cart item individual single price function, no parameters
357
- * @return string the cart individual single item price (1 quantity)
358
- */
359
- function wpsc_cart_single_item_price($forDisplay = true) {
360
- global $wpsc_cart;
361
- if($forDisplay){
362
- return wpsc_currency_display(($wpsc_cart->cart_item->total_price) / ($wpsc_cart->cart_item->quantity));
363
- }else{
364
- return ($wpsc_cart->cart_item->total_price / $wpsc_cart->cart_item->quantity);
365
- }
366
- }
367
-
368
- /**
369
- * cart item shipping function, no parameters
370
- * @return string the cart item price multiplied by the quantity, with a currency sign
371
- */
372
- function wpsc_cart_item_shipping($forDisplay = true) {
373
- global $wpsc_cart;
374
- if($forDisplay){
375
- return wpsc_currency_display($wpsc_cart->cart_item->shipping);
376
- }else{
377
- return $wpsc_cart->cart_item->shipping;
378
- }
379
- }
380
-
381
- /**
382
- * cart item url function, no parameters
383
- * @return string the cart item url
384
- */
385
- function wpsc_cart_item_url() {
386
- global $wpsc_cart;
387
- return apply_filters( 'wpsc_cart_item_url', $wpsc_cart->cart_item->product_url, $wpsc_cart->cart_item->product_id );
388
- }
389
-
390
- /**
391
- * cart item image function
392
- * returns the url to the to the cart item thumbnail image, if a width and height is specified, it resizes the thumbnail image to that size using the preview code (which caches the thumbnail also)
393
- * @param integer width
394
- * @param integer height
395
- * @return string url to the to the cart item thumbnail image
396
- */
397
- function wpsc_cart_item_image( $width = 31, $height = 31 ) {
398
- global $wpsc_cart;
399
-
400
- $cart_image = wpsc_the_product_thumbnail( $width, $height, $wpsc_cart->cart_item->product_id, "shopping_cart");
401
-
402
- if( is_ssl() )
403
- $cart_image = str_replace( 'http://', 'https://', $cart_image );
404
-
405
- return apply_filters( 'wpsc_cart_item_image', $cart_image, $wpsc_cart->cart_item->product_id );
406
- }
407
-
408
  /**
409
  * cart all shipping quotes, used for google checkout
410
  * returns all the quotes for a selected shipping method
@@ -442,154 +306,7 @@ function wpsc_empty_google_logs(){
442
  wpsc_delete_customer_meta( 'checkout_session_id' );
443
 
444
  }
445
- /**
446
- * have shipping methods function, no parameters
447
- * @return boolean
448
- */
449
- function wpsc_have_shipping_methods() {
450
- global $wpsc_cart;
451
- return $wpsc_cart->have_shipping_methods();
452
- }
453
- /**
454
- * the shipping method function, no parameters
455
- * @return boolean
456
- */
457
- function wpsc_the_shipping_method() {
458
- global $wpsc_cart;
459
- return $wpsc_cart->the_shipping_method();
460
- }
461
- /**
462
- * the shipping method name function, no parameters
463
- * @return string shipping method name
464
- */
465
- function wpsc_shipping_method_name() {
466
- global $wpsc_cart, $wpsc_shipping_modules;
467
- $name = '';
468
- if ( ! empty( $wpsc_cart->shipping_method ) && isset( $wpsc_shipping_modules[$wpsc_cart->shipping_method] ) )
469
- $name = $wpsc_shipping_modules[$wpsc_cart->shipping_method]->name;
470
 
471
- return apply_filters( 'wpsc_shipping_method_name', $name );
472
- }
473
-
474
-
475
- /**
476
- * the shipping method internal name function, no parameters
477
- * @return string shipping method internal name
478
- */
479
- function wpsc_shipping_method_internal_name() {
480
- global $wpsc_cart, $wpsc_shipping_modules;
481
- return $wpsc_cart->shipping_method;
482
- }
483
-
484
-
485
- /**
486
- * have shipping quotes function, no parameters
487
- * @return string the cart item url
488
- */
489
- function wpsc_have_shipping_quotes() {
490
- global $wpsc_cart;
491
- return $wpsc_cart->have_shipping_quotes();
492
- }
493
-
494
- /**
495
- * the shipping quote function, no parameters
496
- * @return string the cart item url
497
- */
498
- function wpsc_the_shipping_quote() {
499
- global $wpsc_cart;
500
- return $wpsc_cart->the_shipping_quote();
501
- }
502
-
503
- /**
504
- * the shipping quote name function, no parameters
505
- * @return string shipping quote name
506
- */
507
- function wpsc_shipping_quote_name() {
508
- global $wpsc_cart;
509
- return apply_filters( 'wpsc_shipping_quote_name', $wpsc_cart->shipping_quote['name'] );
510
- }
511
-
512
- /**
513
- * the shipping quote value function, no parameters
514
- * @return string shipping quote value
515
- */
516
- function wpsc_shipping_quote_value( $numeric = false ) {
517
- global $wpsc_cart;
518
-
519
- $value = apply_filters( 'wpsc_shipping_quote_value', $wpsc_cart->shipping_quote['value'] );
520
-
521
- return ( $numeric ) ? $value : wpsc_currency_display( $value );
522
-
523
- }
524
-
525
- /**
526
- * the shipping quote html ID function, no parameters
527
- * @return string shipping quote html ID
528
- */
529
- function wpsc_shipping_quote_html_id() {
530
- global $wpsc_cart;
531
- return $wpsc_cart->shipping_method."_".$wpsc_cart->current_shipping_quote;
532
- }
533
-
534
- /**
535
- * the shipping quote selected state function, no parameters
536
- * @return string true or false
537
- */
538
- function wpsc_shipping_quote_selected_state() {
539
- global $wpsc_cart;
540
- if(($wpsc_cart->selected_shipping_method == $wpsc_cart->shipping_method) && ($wpsc_cart->selected_shipping_option == $wpsc_cart->shipping_quote['name']) ) {
541
- $wpsc_cart->selected_shipping_amount = $wpsc_cart->base_shipping;
542
- return "checked='checked'";
543
- } else {
544
- return "";
545
- }
546
- }
547
- function wpsc_have_morethanone_shipping_quote(){
548
- global $wpsc_cart, $wpsc_shipping_modules;
549
-
550
- // if it's fixed rate shipping, and all the prices are the same, then there aren't really options.
551
- if ( count($wpsc_cart->shipping_methods) == 1 && $wpsc_cart->shipping_methods[0] == 'flatrate' ) {
552
- $last_price = false;
553
- $first_quote_name = false;
554
-
555
- $quotes = $wpsc_shipping_modules['flatrate']->getQuote();
556
- if ( empty( $quotes ) )
557
- return false;
558
-
559
- foreach ((array)$quotes as $name => $quote) {
560
- if (!$first_quote_name) $first_quote_name = $name;
561
- if ($last_price !== false && $quote != $last_price) return true;
562
- $last_price = $quote;
563
- }
564
- $wpsc_cart->rewind_shipping_methods();
565
-
566
- $wpsc_cart->update_shipping('flatrate', $name);
567
- return false;
568
- }
569
- return true;
570
- }
571
-
572
- function wpsc_have_morethanone_shipping_methods_and_quotes(){
573
- global $wpsc_cart;
574
-
575
- if(count($wpsc_cart->shipping_quotes) > 1 || count($wpsc_cart->shipping_methods) > 1 || count($wpsc_cart->shipping_quotes) == $wpsc_cart->shipping_quote_count){
576
- return true;
577
- }else{
578
- return false;
579
- }
580
- }
581
- /**
582
- * Whether or not there is a valid shipping quote/option available to the customer when checking out
583
- *
584
- * @return bool
585
- */
586
- function wpsc_have_shipping_quote(){
587
- global $wpsc_cart;
588
- if ($wpsc_cart->shipping_quote_count > 0 || count($wpsc_cart->shipping_quotes) > 0) {
589
- return true;
590
- }
591
- return false;
592
- }
593
  function wpsc_update_shipping_single_method(){
594
  global $wpsc_cart;
595
  if(!empty($wpsc_cart->shipping_method)) {
@@ -603,8 +320,10 @@ function wpsc_update_shipping_multiple_methods(){
603
  }
604
  }
605
 
606
- function wpsc_get_remaining_quantity($product_id, $variations = array(), $quantity = 1) {
607
- return wpsc_cart::get_remaining_quantity($product_id, $variations, $quantity);
 
 
608
  }
609
 
610
  /**
@@ -668,7 +387,6 @@ class wpsc_cart {
668
  $this->update_location();
669
  $this->wpsc_refresh_cart_items();
670
  $this->unique_id = sha1(uniqid(rand(), true));
671
- $this->get_shipping_method();
672
  }
673
 
674
  /**
@@ -1209,6 +927,7 @@ class wpsc_cart {
1209
  $total = $this->subtotal;
1210
  }
1211
  }
 
1212
  return $total;
1213
  }
1214
 
@@ -1466,6 +1185,12 @@ class wpsc_cart {
1466
  }
1467
  }
1468
 
 
 
 
 
 
 
1469
  /**
1470
  * cart loop methods
1471
  */
@@ -1642,563 +1367,3 @@ class wpsc_cart {
1642
 
1643
  }
1644
 
1645
- /**
1646
- * The WPSC Cart Items class
1647
- */
1648
- class wpsc_cart_item {
1649
-
1650
- // Variation Cache
1651
- private static $variation_cache;
1652
-
1653
- // each cart item contains a reference to the cart that it is a member of
1654
- var $cart;
1655
-
1656
- // provided values
1657
- var $product_id;
1658
- var $variation_values;
1659
- var $product_variations;
1660
- var $variation_data;
1661
- var $quantity = 1;
1662
- var $provided_price;
1663
-
1664
-
1665
- //values from the database
1666
- var $product_name;
1667
- var $category_list = array();
1668
- var $category_id_list = array();
1669
- var $unit_price;
1670
- var $total_price;
1671
- var $taxable_price = 0;
1672
- var $tax = 0;
1673
- var $weight = 0;
1674
- var $shipping = 0;
1675
- var $sku = null;
1676
- var $product_url;
1677
- var $image_id;
1678
- var $thumbnail_image;
1679
- var $custom_tax_rate = null;
1680
- var $meta = array();
1681
-
1682
- var $is_donation = false;
1683
- var $apply_tax = true;
1684
- var $priceandstock_id;
1685
-
1686
- // user provided values
1687
- var $custom_message = null;
1688
- var $custom_file = null;
1689
-
1690
- public static function refresh_variation_cache() {
1691
- global $wpsc_cart;
1692
-
1693
- $variation_product_ids = array();
1694
-
1695
- foreach ( $wpsc_cart->get_items() as $cart_item ) {
1696
- if ( ! empty( $cart_item->variation_values ) )
1697
- $variation_product_ids[] = $cart_item->product_id;
1698
- }
1699
-
1700
- if ( empty( $variation_product_ids ) )
1701
- return;
1702
-
1703
- self::$variation_cache = wp_get_object_terms( $variation_product_ids, 'wpsc-variation', array( 'fields' => 'all_with_object_id' ) );
1704
-
1705
- foreach ( self::$variation_cache as $term ) {
1706
- if ( ! array_key_exists( $term->object_id, self::$variation_cache ) )
1707
- self::$variation_cache[$term->object_id] = array();
1708
-
1709
- self::$variation_cache[$term->object_id][$term->parent] = $term->name;
1710
- }
1711
-
1712
- return self::$variation_cache;
1713
- }
1714
-
1715
- /**
1716
- * wpsc_cart_item constructor, requires a product ID and the parameters for the product
1717
- * @access public
1718
- *
1719
- * @param integer the product ID
1720
- * @param array parameters
1721
- * @param objcet the cart object
1722
- * @return boolean true on sucess, false on failure
1723
- */
1724
- function wpsc_cart_item($product_id, $parameters, $cart) {
1725
- global $wpdb;
1726
- // still need to add the ability to limit the number of an item in the cart at once.
1727
- // each cart item contains a reference to the cart that it is a member of, this makes that reference
1728
- // The cart is in the cart item, which is in the cart, which is in the cart item, which is in the cart, which is in the cart item...
1729
- $this->cart = &$cart;
1730
-
1731
-
1732
- foreach($parameters as $name => $value) {
1733
- $this->$name = $value;
1734
- }
1735
-
1736
-
1737
- $this->product_id = absint($product_id);
1738
- // to preserve backwards compatibility, make product_variations a reference to variations.
1739
- $this->product_variations =& $this->variation_values;
1740
-
1741
-
1742
-
1743
- if(($parameters['is_customisable'] == true) && ($parameters['file_data'] != null)) {
1744
- $this->save_provided_file($this->file_data);
1745
- }
1746
- $this->refresh_item();
1747
-
1748
- if ( ! has_action( 'wpsc_add_item', array( 'wpsc_cart_item', 'refresh_variation_cache' ) ) )
1749
- add_action( 'wpsc_add_item', array( 'wpsc_cart_item', 'refresh_variation_cache' ) );
1750
-
1751
- }
1752
-
1753
- /**
1754
- * update item method, currently can only update the quantity
1755
- * will require the parameters to update (no, you cannot change the product ID, delete the item and make a new one)
1756
- * @access public
1757
- *
1758
- * @param integer quantity
1759
- * #@param array parameters
1760
- * @return boolean true on sucess, false on failure
1761
- */
1762
- function update_item($quantity) {
1763
- $this->quantity = (int)$quantity;
1764
- $this->refresh_item();
1765
- $this->update_claimed_stock();
1766
-
1767
-
1768
- }
1769
-
1770
- /**
1771
- * refresh_item method, refreshes the item, calculates the prices, gets the name
1772
- * @access public
1773
- *
1774
- * @return array array of monetary and other values
1775
- */
1776
- function refresh_item() {
1777
- global $wpdb, $wpsc_shipping_modules, $wpsc_cart;
1778
- $product_id = $this->product_id;
1779
- $product = get_post( $this->product_id );
1780
- $product_meta = get_metadata( 'post', $this->product_id );
1781
- $this->sku = get_post_meta( $product_id, '_wpsc_sku', true );
1782
- $price = get_post_meta( $product_id, '_wpsc_price', true );
1783
- $special_price = get_post_meta( $product_id, '_wpsc_special_price', true );
1784
- $product_meta = get_post_meta( $product_id, '_wpsc_product_metadata' );
1785
- $this->stock = get_post_meta( $product_id, '_wpsc_stock', true );
1786
- $this->is_donation = get_post_meta( $product_id, '_wpsc_is_donation', true );
1787
-
1788
- if ( isset( $special_price ) && $special_price > 0 && $special_price < $price )
1789
- $price = $special_price;
1790
- $priceandstock_id = 0;
1791
- $this->weight = isset( $product_meta[0]['weight'] ) ? $product_meta[0]["weight"] : 0;
1792
- // if we are using table rate price
1793
- if ( isset( $product_meta[0]['table_rate_price'] ) ) {
1794
- $levels = $product_meta[0]['table_rate_price'];
1795
- if ( ! empty( $levels['quantity'] ) ) {
1796
- foreach((array)$levels['quantity'] as $key => $qty) {
1797
- if ($this->quantity >= $qty) {
1798
- $unit_price = $levels['table_price'][$key];
1799
- if ($unit_price != '')
1800
- $price = $unit_price;
1801
- }
1802
- }
1803
- }
1804
- }
1805
-
1806
- $price = apply_filters( 'wpsc_price', $price, $product_id );
1807
-
1808
- // create the string containing the product name.
1809
- $this->product_name = $this->get_title( 'raw' );
1810
- $this->priceandstock_id = $priceandstock_id;
1811
- $this->meta = $product_meta;
1812
-
1813
- // change no_shipping to boolean and invert it
1814
- if( isset( $product_meta[0]['no_shipping'] ) && $product_meta[0]['no_shipping'] == 1)
1815
- $this->uses_shipping = 0 ;
1816
- else
1817
- $this->uses_shipping = 1;
1818
-
1819
- $quantity_limited = get_product_meta($product_id, 'stock', true);
1820
- $this->has_limited_stock = (bool)$quantity_limited;
1821
-
1822
- if($this->is_donation == 1)
1823
- $this->unit_price = (float) $this->provided_price;
1824
- else
1825
- $this->unit_price = (float) $price;
1826
-
1827
- $this->total_price = $this->unit_price * $this->quantity;
1828
- if ( $product->post_parent )
1829
- $category_data = get_the_product_category( $product->post_parent );
1830
- else
1831
- $category_data = get_the_product_category( $product_id );
1832
-
1833
- $this->category_list = array();
1834
- $this->category_id_list = array();
1835
-
1836
- foreach( (array) $category_data as $category_row ) {
1837
- $this->category_list[] = $category_row->slug;
1838
- $this->category_id_list[] = $category_row->term_id;
1839
- }
1840
-
1841
- //wpec_taxes - calculate product tax and add to total price
1842
- $wpec_taxes_controller = new wpec_taxes_controller();
1843
- if ( $wpec_taxes_controller->wpec_taxes_isincluded() && $wpec_taxes_controller->wpec_taxes_isenabled() ){
1844
- $taxes = $wpec_taxes_controller->wpec_taxes_calculate_included_tax($this);
1845
- $this->tax_rate = $taxes['rate'];
1846
- $this->tax = $taxes['tax'];
1847
- }
1848
-
1849
- $this->product_url = wpsc_product_url( $product_id );
1850
-
1851
- if( ! is_array( $this->variation_values ) )
1852
- $attach_parent = $product_id;
1853
- else
1854
- $attach_parent = $wpdb->get_var( $wpdb->prepare("SELECT post_parent FROM $wpdb->posts WHERE ID = %d", $product_id ) );
1855
-
1856
-
1857
- $att_img_args = array(
1858
- 'post_type' => 'attachment',
1859
- 'numberposts' => 1,
1860
- 'post_parent' => $attach_parent,
1861
- 'orderby' => 'menu_order',
1862
- 'order' => 'DESC'
1863
- );
1864
-
1865
- $attached_image = get_posts( $att_img_args );
1866
-
1867
-
1868
- if ( $attached_image != null )
1869
- $this->thumbnail_image = array_shift( $attached_image );
1870
-
1871
- $product_files = (array) get_posts( array(
1872
- 'post_type' => 'wpsc-product-file',
1873
- 'post_parent' => $this->product_id,
1874
- 'numberposts' => -1,
1875
- 'post_status' => 'inherit'
1876
- ) );
1877
-
1878
- if(count($product_files) > 0) {
1879
- $this->file_id = null;
1880
- $this->is_downloadable = true;
1881
- } else {
1882
- $this->file_id = null;
1883
- $this->is_downloadable = false;
1884
- }
1885
-
1886
- if ( isset( $this->cart->selected_shipping_method ) && isset( $wpsc_shipping_modules[$this->cart->selected_shipping_method] ) && is_callable( array( $wpsc_shipping_modules[$this->cart->selected_shipping_method], "get_item_shipping" ) ) )
1887
- $this->shipping = $wpsc_shipping_modules[$this->cart->selected_shipping_method]->get_item_shipping( $this );
1888
-
1889
- // update the claimed stock here
1890
- $this->update_claimed_stock();
1891
-
1892
- do_action_ref_array( 'wpsc_refresh_item', array( &$this ) );
1893
- }
1894
-
1895
- public function get_title( $mode = 'display' ) {
1896
-
1897
- if ( ! get_post_field( 'post_parent', $this->product_id ) )
1898
- return get_post_field( 'post_title', $this->product_id);
1899
-
1900
- if ( empty( self::$variation_cache ) )
1901
- self::refresh_variation_cache();
1902
-
1903
- $primary_product_id = get_post_field( 'post_parent', $this->product_id );
1904
- $title = get_post_field( 'post_title', $primary_product_id );
1905
-
1906
- if ( isset( self::$variation_cache[$this->product_id] ) ) {
1907
- ksort( self::$variation_cache[$this->product_id] );
1908
- $vars = implode( ', ', self::$variation_cache[$this->product_id] );
1909
- $title .= ' (' . $vars . ')';
1910
- }
1911
-
1912
- $title = apply_filters( 'wpsc_cart_product_title', $title, $this->product_id );
1913
-
1914
- if ( $mode == 'display' )
1915
- $title = apply_filters( 'the_title', $title );
1916
-
1917
- return $title;
1918
- }
1919
-
1920
- /**
1921
- * Calculate shipping method
1922
- * if no parameter passed, takes the currently selected method
1923
- * @access public
1924
- *
1925
- * @param string shipping method
1926
- * @return boolean true on sucess, false on failure
1927
- */
1928
-
1929
- function calculate_shipping($method = null) {
1930
- global $wpdb, $wpsc_cart, $wpsc_shipping_modules;
1931
- $shipping = '';
1932
- if($method === null)
1933
- $method = $this->cart->selected_shipping_method;
1934
-
1935
- if( $method && isset( $wpsc_shipping_modules[$method] ) && method_exists( $wpsc_shipping_modules[$method], "get_item_shipping" ))
1936
- $shipping = $wpsc_shipping_modules[$method]->get_item_shipping($this);
1937
-
1938
- if($method == $this->cart->selected_shipping_method && !empty( $shipping ) )
1939
- $this->shipping = $shipping;
1940
-
1941
- return $shipping;
1942
- }
1943
-
1944
- /**
1945
- * user provided file method
1946
- * @access public
1947
- * @param string shipping method
1948
- * @return boolean true on sucess, false on failure
1949
- */
1950
-
1951
- function save_provided_file($file_data) {
1952
- global $wpdb;
1953
- $accepted_file_types['mime'][] = 'image/jpeg';
1954
- $accepted_file_types['mime'][] = 'image/gif';
1955
- $accepted_file_types['mime'][] = 'image/png';
1956
-
1957
- $accepted_file_types['mime'][] = 'image/pjpeg'; // Added for IE compatibility
1958
- $accepted_file_types['mime'][] = 'image/x-png'; // Added for IE compatibility
1959
-
1960
- $accepted_file_types['ext'][] = 'jpeg';
1961
- $accepted_file_types['ext'][] = 'jpg';
1962
- $accepted_file_types['ext'][] = 'gif';
1963
- $accepted_file_types['ext'][] = 'png';
1964
-
1965
- $accepted_file_types = apply_filters( 'wpsc_customer_upload_accepted_file_types', $accepted_file_types );
1966
-
1967
- $can_have_uploaded_image = get_product_meta($this->product_id,'product_metadata',true);
1968
- $product = get_post($this->product_id);
1969
- if(0 != $product->post_parent ){
1970
- $product = get_post($product->post_parent);
1971
- $can_have_uploaded_image = get_product_meta($product->ID,'product_metadata',true);
1972
- }
1973
- $can_have_uploaded_image = $can_have_uploaded_image['can_have_uploaded_image'];
1974
- if ('on' == $can_have_uploaded_image || 1 == $can_have_uploaded_image) {
1975
- $name_parts = explode('.',basename($file_data['name']));
1976
- $extension = array_pop($name_parts);
1977
-
1978
- if ( ( (
1979
- array_search( strtolower( $file_data['type'] ), $accepted_file_types['mime'] ) !== false ) ||
1980
- get_option( 'wpsc_check_mime_types' ) == 1 ) &&
1981
- array_search( strtolower( $extension ), $accepted_file_types['ext'] ) !== false ) {
1982
-
1983
- if(is_file(WPSC_USER_UPLOADS_DIR.$file_data['name'])) {
1984
- $name_parts = explode('.',basename($file_data['name']));
1985
- $extension = array_pop($name_parts);
1986
- $name_base = implode('.',$name_parts);
1987
- $file_data['name'] = null;
1988
- $num = 2;
1989
- // loop till we find a free file name, first time I get to do a do loop in yonks
1990
- do {
1991
- $test_name = "{$name_base}-{$num}.{$extension}";
1992
- if(!file_exists(WPSC_USER_UPLOADS_DIR.$test_name))
1993
- $file_data['name'] = $test_name;
1994
- $num++;
1995
- } while ($file_data['name'] == null);
1996
- }
1997
-
1998
- $unique_id = sha1(uniqid(rand(),true));
1999
- if(move_uploaded_file($file_data['tmp_name'], WPSC_USER_UPLOADS_DIR.$file_data['name']) )
2000
- $this->custom_file = array(
2001
- 'file_name' => $file_data['name'],
2002
- 'mime_type' => $file_data['type'],
2003
- 'unique_id' => $unique_id
2004
- );
2005
-
2006
- }
2007
- }
2008
- }
2009
-
2010
-
2011
- /**
2012
- * update_claimed_stock method
2013
- * Updates the claimed stock table, to prevent people from having more than the existing stock in their carts
2014
- * @access public
2015
- *
2016
- * no parameters, nothing returned
2017
- */
2018
- function update_claimed_stock() {
2019
- global $wpdb;
2020
-
2021
- if($this->has_limited_stock == true) {
2022
- $current_datetime = date( "Y-m-d H:i:s" );
2023
- $wpdb->query($wpdb->prepare("REPLACE INTO `".WPSC_TABLE_CLAIMED_STOCK."`
2024
- ( `product_id` , `variation_stock_id` , `stock_claimed` , `last_activity` , `cart_id` )
2025
- VALUES
2026
- ('%d', '%d', '%s', '%s', '%s');",
2027
- $this->product_id,
2028
- $this->priceandstock_id,
2029
- $this->quantity,
2030
- $current_datetime,
2031
- $this->cart->unique_id));
2032
- }
2033
- }
2034
-
2035
-
2036
- /**
2037
- * save to database method
2038
- * @access public
2039
- *
2040
- * @param integer purchase log id
2041
- */
2042
- function save_to_db($purchase_log_id) {
2043
- global $wpdb, $wpsc_shipping_modules;
2044
-
2045
- $method = $this->cart->selected_shipping_method;
2046
- $shipping = 0;
2047
-
2048
- if( ! empty( $method ) && method_exists( $wpsc_shipping_modules[$method], "get_item_shipping" ) )
2049
- $shipping = $wpsc_shipping_modules[$this->cart->selected_shipping_method]->get_item_shipping( $this );
2050
-
2051
- if( $this->cart->has_total_shipping_discount() )
2052
- $shipping = 0;
2053
-
2054
- $shipping = apply_filters( 'wpsc_item_shipping_amount_db', $shipping, $this );
2055
-
2056
- //initialize tax variables
2057
- $tax = 0;
2058
- $tax_rate = 0;
2059
-
2060
- //wpec_taxes - calculate product tax and add to total price
2061
- $wpec_taxes_controller = new wpec_taxes_controller();
2062
-
2063
- if($wpec_taxes_controller->wpec_taxes_isincluded() && $wpec_taxes_controller->wpec_taxes_isenabled()){
2064
- $taxes = $wpec_taxes_controller->wpec_taxes_calculate_included_tax($this);
2065
- $tax_rate = $taxes['rate'];
2066
- $tax = $taxes['tax'];
2067
- }
2068
-
2069
- $wpdb->insert(
2070
- WPSC_TABLE_CART_CONTENTS,
2071
- array(
2072
- 'prodid' => $this->product_id,
2073
- 'name' => $this->get_title(),
2074
- 'purchaseid' => $purchase_log_id,
2075
- 'price' => $this->unit_price,
2076
- 'pnp' => $shipping,
2077
- 'tax_charged' => $tax,
2078
- 'gst' => $tax_rate,
2079
- 'quantity' => $this->quantity,
2080
- 'donation' => $this->is_donation,
2081
- 'no_shipping' => 0,
2082
- 'custom_message' => $this->custom_message,
2083
- 'files' => serialize($this->custom_file),
2084
- 'meta' => NULL
2085
- ),
2086
- array(
2087
- '%d',
2088
- '%s',
2089
- '%d',
2090
- '%f',
2091
- '%f',
2092
- '%f',
2093
- '%f',
2094
- '%s',
2095
- '%d',
2096
- '%d',
2097
- '%s',
2098
- '%s',
2099
- '%s'
2100
- )
2101
- );
2102
-
2103
- $cart_id = $wpdb->get_var( "SELECT " . $wpdb->insert_id . " AS `id` FROM `".WPSC_TABLE_CART_CONTENTS."` LIMIT 1");
2104
-
2105
- wpsc_update_cartmeta($cart_id, 'sku', $this->sku);
2106
-
2107
- $downloads = get_option('max_downloads');
2108
- if($this->is_downloadable == true) {
2109
-
2110
- $product_files = (array)get_posts(array(
2111
- 'post_type' => 'wpsc-product-file',
2112
- 'post_parent' => $this->product_id,
2113
- 'numberposts' => -1,
2114
- 'post_status' => 'inherit'
2115
- ));
2116
- foreach($product_files as $file){
2117
- // if the file is downloadable, check that the file is real
2118
- $unique_id = sha1(uniqid(mt_rand(), true));
2119
-
2120
- $wpdb->insert(
2121
- WPSC_TABLE_DOWNLOAD_STATUS,
2122
- array(
2123
- 'product_id' => $this->product_id,
2124
- 'fileid' => $file->ID,
2125
- 'purchid' => $purchase_log_id,
2126
- 'cartid' => $cart_id,
2127
- 'uniqueid' => $unique_id,
2128
- 'downloads' => $downloads,
2129
- 'active' => 0,
2130
- 'datetime' => date( 'Y-m-d H:i:s' )
2131
- ),
2132
- array(
2133
- '%d',
2134
- '%d',
2135
- '%d',
2136
- '%d',
2137
- '%s',
2138
- '%s',
2139
- '%d',
2140
- '%s',
2141
- )
2142
- );
2143
-
2144
- $download_id = $wpdb->get_var( "SELECT " . $wpdb->insert_id . " AS `id` FROM `".WPSC_TABLE_DOWNLOAD_STATUS."` LIMIT 1");
2145
- wpsc_update_meta($download_id, '_is_legacy', 'false', 'wpsc_downloads');
2146
- }
2147
-
2148
- }
2149
-
2150
- do_action('wpsc_save_cart_item', $cart_id, $this->product_id);
2151
- }
2152
-
2153
- }
2154
-
2155
-
2156
- /**
2157
- * Comparison object that helps with ordering cart items
2158
- *
2159
- * @since 3.8.9
2160
- * @access private
2161
- */
2162
- class _WPSC_Comparison
2163
- {
2164
- private $orderby = '';
2165
- private $order = 'ASC';
2166
-
2167
- /**
2168
- * Constructor
2169
- *
2170
- * @param string $orderby Field to order by
2171
- * @param string $order Order direction, defaults to ASC for ascending.
2172
- */
2173
- public function __construct( $orderby, $order = 'ASC' ) {
2174
- $this->orderby = $orderby;
2175
- $this->order = $order;
2176
- }
2177
-
2178
- /**
2179
- * This compare method can be passed into usort when sorting an array of object
2180
- *
2181
- * @since 3.8.9
2182
- *
2183
- * @param object|array $a
2184
- * @param object|array $b
2185
- * @return int See usort() documentation for the meaning of this return value.
2186
- */
2187
- public function compare( $a, $b ) {
2188
- // cast them all to object, just in case any of them is an array
2189
- $a = (object) $a;
2190
- $b = (object) $b;
2191
-
2192
- $key = $this->orderby;
2193
-
2194
- $val_a = isset( $a->$key ) ? $a->$key : 0;
2195
- $val_b = isset( $b->$key ) ? $b->$key : 0;
2196
-
2197
- $diff = $val_a - $val_b;
2198
-
2199
- if ( $this->order != 'ASC' )
2200
- $diff = $diff * -1;
2201
-
2202
- return $diff;
2203
- }
2204
- }
2
  /**
3
  * WP eCommerce Cart and Cart Item classes
4
  *
5
+ * This is the class for the WP eCommerce Cart ,
6
  * The Cart class handles adding, removing and adjusting items in the cart, and totaling up the cost of the items in the cart.
 
7
  *
8
  *
9
  * @package wp-e-commerce
69
 
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  /**
73
  * nzshpcrt_overall_total_price function, no parameters
74
  * @return string the total price of the cart, with a currency sign
189
  }
190
  }
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  /**
193
  * Product Maximum Cart Quantity
194
  *
205
  return apply_filters( 'wpsc_product_max_cart_quantity', 10000, $product_id );
206
  }
207
 
208
+ /**
209
+ * Product Minimum Cart Quantity
210
+ *
211
+ * @since 3.8.13
212
+ * @access public
213
+ *
214
+ * @param int $prod_id Optional. Product ID.
215
+ * @return int The minimum quantity that can be added to the cart.
216
+ *
217
+ * @uses apply_filters Calls 'wpsc_product_min_cart_quantity' passing product ID.
218
+ */
219
+ function wpsc_product_min_cart_quantity( $product_id = 0 ) {
220
+ $product_id = absint( $product_id );
221
+ return apply_filters( 'wpsc_product_min_cart_quantity', 1, $product_id );
222
+ }
223
+
224
  /**
225
  * Validate Product Cart Quantity
226
  * Checks that the quantity is within the permitted bounds and return a valid quantity.
233
  * @return int The maximum quantity that can be added to the cart.
234
  *
235
  * @uses wpsc_product_max_cart_quantity Gets the maximum product cart quantity.
236
+ * @uses wpsc_product_min_cart_quantity Gets the minimum product cart quantity.
237
  */
238
  function wpsc_validate_product_cart_quantity( $quantity, $product_id = 0 ) {
239
  $max_quantity = wpsc_product_max_cart_quantity( $product_id );
240
+ $min_quantity = wpsc_product_min_cart_quantity( $product_id );
241
  if ( $quantity > $max_quantity )
242
  return $max_quantity;
243
+ if ( $quantity < $min_quantity )
244
+ return $min_quantity;
245
  return $quantity;
246
  }
247
 
269
  add_action( 'wpsc_add_item', '_wpsc_validate_cart_product_quantity', 10, 3 );
270
  add_action( 'wpsc_edit_item', '_wpsc_validate_cart_product_quantity', 10, 3 );
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  /**
273
  * cart all shipping quotes, used for google checkout
274
  * returns all the quotes for a selected shipping method
306
  wpsc_delete_customer_meta( 'checkout_session_id' );
307
 
308
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
  function wpsc_update_shipping_single_method(){
311
  global $wpsc_cart;
312
  if(!empty($wpsc_cart->shipping_method)) {
320
  }
321
  }
322
 
323
+ function wpsc_get_remaining_quantity( $product_id, $variations = array(), $quantity = 1 ) {
324
+ global $wpsc_cart;
325
+
326
+ return $wpsc_cart->get_remaining_quantity( $product_id, $variations, $quantity );
327
  }
328
 
329
  /**
387
  $this->update_location();
388
  $this->wpsc_refresh_cart_items();
389
  $this->unique_id = sha1(uniqid(rand(), true));
 
390
  }
391
 
392
  /**
927
  $total = $this->subtotal;
928
  }
929
  }
930
+
931
  return $total;
932
  }
933
 
1185
  }
1186
  }
1187
 
1188
+ public function empty_db( $purchase_log_id ) {
1189
+ global $wpdb;
1190
+ $sql = $wpdb->prepare( "DELETE FROM " . WPSC_TABLE_CART_CONTENTS . " WHERE purchaseid = %d", $purchase_log_id );
1191
+ $wpdb->query( $sql );
1192
+ }
1193
+
1194
  /**
1195
  * cart loop methods
1196
  */
1367
 
1368
  }
1369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
wpsc-includes/category.functions.php CHANGED
@@ -9,506 +9,31 @@
9
  * @since 3.7
10
  */
11
 
12
- /**
13
- * wpsc_list_categories function.
14
- *
15
- * @access public
16
- * @param string $callback_function - The function name you want to use for displaying the data
17
- * @param mixed $parameters (default: null) - the additional parameters to the callback function
18
- * @param int $category_id. (default: 0) - The category id defaults to zero, for displaying all categories
19
- * @param int $level. (default: 0)
20
- */
21
- function wpsc_list_categories($callback_function, $parameters = null, $category_id = 0, $level = 0) {
22
- global $wpdb,$category_data;
23
- $output = '';
24
- $category_list = get_terms('wpsc_product_category','hide_empty=0&parent='.$category_id);
25
- if($category_list != null) {
26
- foreach((array)$category_list as $category) {
27
- $callback_output = $callback_function($category, $level, $parameters);
28
- if(is_array($callback_output)) {
29
- $output .= array_shift($callback_output);
30
- } else {
31
- $output .= $callback_output;
32
- }
33
- $output .= wpsc_list_categories($callback_function, $parameters , $category->term_id, ($level+1));
34
- if(is_array($callback_output) && (isset($callback_output[1]))) {
35
- $output .= $callback_output[1];
36
- }
37
- }
38
- }
39
- return $output;
40
- }
41
-
42
-
43
- /**
44
- * Gets the Function Parent Image link and checks whether Image should be displayed or not
45
- *
46
- */
47
- function wpsc_parent_category_image($show_thumbnails , $category_image , $width, $height, $grid=false, $show_name){
48
-
49
- if(!$show_thumbnails) return;
50
-
51
- if($category_image == WPSC_CATEGORY_URL){
52
- if(!$show_name) return;
53
- ?>
54
- <span class='wpsc_category_image item_no_image ' style='width:<?php echo $width; ?>px; height: <?php echo $height; ?>px;'>
55
- <span class='link_substitute' >
56
- <span><?php _e('N/A', 'wpsc'); ?></span>
57
- </span>
58
- </span>
59
- <?php
60
- }else{
61
- ?><img src='<?php echo $category_image; ?>' width='<?php echo $width; ?>' height='<?php echo $height; ?>' /><?php
62
- }
63
- }
64
- /// category template tags start here
65
-
66
- /**
67
- * wpsc starts category query function
68
- * gets passed the query and makes it into a global variable, then starts capturing the html for the category loop
69
- */
70
- function wpsc_start_category_query($arguments = array()) {
71
- global $wpdb, $wpsc_category_query;
72
- $wpsc_category_query = $arguments;
73
- ob_start();
74
- }
75
-
76
- /**
77
- * wpsc print category name function
78
- * places the shortcode for the category name
79
- */
80
- function wpsc_print_category_name() {
81
- echo "[wpsc_category_name]";
82
- }
83
-
84
- /**
85
- * wpsc print category description function
86
- * places the shortcode for the category description, accepts parameters for the description container
87
- * @param string starting HTML element
88
- * @param string ending HTML element
89
- */
90
- function wpsc_print_category_description($start_element = '', $end_element = '') {
91
- global $wpsc_category_query;
92
- $wpsc_category_query['description_container'] = array('start_element' => $start_element, 'end_element' => $end_element);
93
- echo "[wpsc_category_description]";
94
- }
95
-
96
- /**
97
- * wpsc print category url function
98
- * places the shortcode for the category URL
99
- */
100
- function wpsc_print_category_url() {
101
- echo "[wpsc_category_url]";
102
- }
103
-
104
- /**
105
- * wpsc print category id function
106
- * places the shortcode for the category URL
107
- */
108
- function wpsc_print_category_id() {
109
- echo "[wpsc_category_id]";
110
- }
111
-
112
- /**
113
- * wpsc print category classes function
114
- * places classes for the category including selected state
115
- *
116
- * please note that "current category" means the category that we are in now,
117
- * and not the category that we are printing for
118
- *
119
- * @param $category_to_print - the category for which we should print classes
120
- * @param $echo - whether to echo the result (true) or return (false)
121
- */
122
- function wpsc_print_category_classes($category_to_print = false, $echo = true) {
123
- global $wp_query, $wpdb;
124
-
125
- //if we are in wpsc category page then get the current category
126
- $curr_cat = false;
127
- $term = get_query_var( 'wpsc_product_category' );
128
- if ( ! $term && get_query_var( 'taxonomy' ) == 'wpsc_product_category' )
129
- $term = get_query_var( 'term' );
130
- if ( $term )
131
- $curr_cat = get_term_by( 'slug', $term, 'wpsc_product_category' );
132
-
133
- //check if we are in wpsc category page and that we have a term_id of the category to print
134
- //this is done here because none of the following matters if we don't have one of those and we can
135
- //safely return
136
- if(isset($category_to_print['term_id']) && $curr_cat){
137
-
138
- //we will need a list of current category parents for the following if statement
139
- $curr_cat_parents = wpsc_get_term_parents($curr_cat->term_id, 'wpsc_product_category');
140
-
141
- //if current category is the same as the one we are printing - then add wpsc-current-cat class
142
- if( $category_to_print['term_id'] == $curr_cat->term_id )
143
- $result = ' wpsc-current-cat ';
144
- //else check if the category that we are printing is parent of current category
145
- elseif ( in_array($category_to_print['term_id'], $curr_cat_parents) )
146
- $result = ' wpsc-cat-ancestor ';
147
- }
148
- if( isset($result) )
149
- if($echo)
150
- echo $result;
151
- else
152
- return $result;
153
- }
154
-
155
-
156
  /**
157
  * wpsc_get_term_parents - get all parents of the term
158
  *
159
  * @param int $id - id of the term
160
- * @return array of term objects or empty array if anything went wrong or there were no parrents
161
  */
162
  function wpsc_get_term_parents( $term_id, $taxonomy ) {
163
- $term = &get_term( $term_id, $taxonomy );
164
 
165
- if(empty($term->parent))
166
  return array();
167
- $parent = &get_term( $term->parent, $taxonomy );
 
168
  if ( is_wp_error( $parent ) )
169
  return array();
170
 
171
  $parents = array( $parent->term_id );
172
 
173
  if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $parents ) ) {
174
- $parents = array_merge($parents, wpsc_get_term_parents( $parent->term_id, $taxonomy ));
175
  }
176
 
177
  return $parents;
178
  }
179
 
180
-
181
- /**
182
- * wpsc print subcategory function
183
- * places the shortcode for the subcategories, accepts parameters for the subcategories container, have this as <ul> and </ul> if using a list
184
- * @param string starting HTML element
185
- * @param string ending HTML element
186
- */
187
- function wpsc_print_subcategory($start_element = '', $end_element = '') {
188
- global $wpsc_category_query;
189
- $wpsc_category_query['subcategory_container'] = array('start_element' => $start_element, 'end_element' => $end_element);
190
- echo "[wpsc_subcategory]";
191
- }
192
- function wpsc_print_category_classes_section(){
193
- echo "[wpsc_category_classes]";
194
- }
195
-
196
- /**
197
- * wpsc print category image function
198
- * places the shortcode for the category image, accepts parameters for width and height
199
- * @param integer width
200
- * @param integer height
201
- */
202
- function wpsc_print_category_image($width = null, $height = null) {
203
- global $wpsc_category_query;
204
- $wpsc_category_query['image_size'] = array('width' => $width, 'height' => $height);
205
- echo "[wpsc_category_image]";
206
- }
207
-
208
- /**
209
- * wpsc print category products count function
210
- * places the shortcode for the category product count, accepts parameters for the container element
211
- * @param string starting HTML element
212
- * @param string ending HTML element
213
- */
214
- function wpsc_print_category_products_count($start_element = '', $end_element = '') {
215
- global $wpsc_category_query;
216
- $wpsc_category_query['products_count'] = array('start_element' => $start_element, 'end_element' => $end_element);
217
- echo "[wpsc_category_products_count]";
218
- }
219
-
220
- /**
221
- * wpsc end category query function
222
- */
223
- function wpsc_end_category_query() {
224
- global $wpdb, $wpsc_category_query;
225
- $category_html = ob_get_clean();
226
- echo wpsc_display_category_loop($wpsc_category_query, $category_html);
227
- unset($GLOBALS['wpsc_category_query']);
228
- }
229
-
230
- /**
231
- * wpsc category loop function
232
- * This function recursively loops through the categories to display the category tree.
233
- * This function also generates a tree of categories at the same time
234
- * WARNING: as this function is recursive, be careful what you do with it.
235
- * @param array the category query
236
- * @param string the category html
237
- * @param array the category array branch, is an internal value, leave it alone.
238
- * @return string - the finished category html
239
- */
240
- function wpsc_display_category_loop($query, $category_html, &$category_branch = null){
241
- static $category_count_data = array(); // the array tree is stored in this
242
-
243
- if( isset($query['parent_category_id']) )
244
- $category_id = absint($query['parent_category_id']);
245
- else
246
- $category_id = 0;
247
- $category_data = get_terms('wpsc_product_category','hide_empty=0&parent='.$category_id, OBJECT, 'display');
248
- $output ='';
249
-
250
- // if the category branch is identical to null, make it a reference to $category_count_data
251
- if($category_branch === null) {
252
- $category_branch =& $category_count_data;
253
- }
254
- $allowed_tags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array(), 'b'=> array());
255
-
256
- $allowedtags = apply_filters('wpsc_category_description_allowed_tags' , $allowed_tags);
257
-
258
- foreach((array)$category_data as $category_row) {
259
-
260
- // modifys the query for the next round
261
- $modified_query = $query;
262
- $modified_query['parent_category_id'] = $category_row->term_id;
263
-
264
- // gets the count of products associated with this category
265
- $category_count = $category_row->count;
266
-
267
-
268
- // Sticks the category description in
269
- $category_description = '';
270
- if($category_row->description != '' && ! empty( $query['description_container'] ) ) {
271
- $start_element = $query['description_container']['start_element'];
272
- $end_element = $query['description_container']['end_element'];
273
- $category_description = $start_element.wpautop(wptexturize( wp_kses( $category_row->description, $allowedtags ))).$end_element;
274
- }
275
-
276
-
277
- // Creates the list of classes on the category item
278
- $category_classes = wpsc_print_category_classes((array)$category_row, false);
279
-
280
- // Set the variables for this category
281
- $category_branch[$category_row->term_id]['children'] = array();
282
- $category_branch[$category_row->term_id]['count'] = (int)$category_count;
283
-
284
-
285
- // Recurse into the next level of categories
286
- $sub_categories = wpsc_display_category_loop($modified_query, $category_html, $category_branch[$category_row->term_id]['children']);
287
-
288
- // grab the product count from the subcategories
289
- foreach((array)$category_branch[$category_row->term_id]['children'] as $child_category) {
290
- $category_branch[$category_row->term_id]['count'] += (int)$child_category['count'];
291
- }
292
-
293
- // stick the category count array together here
294
- // this must run after the subcategories and the count of products belonging to them has been obtained
295
-
296
- $category_count = $category_branch[$category_row->term_id]['count'];
297
-
298
- $start_element = '';
299
- $end_element = '';
300
-
301
- if (isset($query['products_count']['start_element'])) {
302
- $start_element = $query['products_count']['start_element'];
303
- }
304
-
305
- if (isset($query['products_count']['end_element'])) {
306
- $end_element = $query['products_count']['end_element'];
307
- }
308
-
309
- $category_count_html = $start_element.$category_count.$end_element;
310
-
311
-
312
- if ( isset( $query['subcategory_container'] ) && ! empty( $sub_categories ) ) {
313
- $start_element = $query['subcategory_container']['start_element'];
314
- $end_element = $query['subcategory_container']['end_element'];
315
- $sub_categories = $start_element.$sub_categories.$end_element;
316
- }
317
-
318
- // get the category images
319
- $category_image = wpsc_place_category_image($category_row->term_id, $modified_query);
320
-
321
- if ( empty( $query['image_size']['width'] ) ) {
322
- if ( ! wpsc_category_grid_view() )
323
- $width = wpsc_get_categorymeta( $category_row->term_id, 'image_width' );
324
- if ( empty( $width ) )
325
- $width = get_option( 'category_image_width' );
326
- } else {
327
- $width = $query['image_size']['width'];
328
- }
329
-
330
- if ( empty( $query['image_size']['height'] ) ) {
331
- if ( ! wpsc_category_grid_view() )
332
- $height = wpsc_get_categorymeta( $category_row->term_id, 'image_height' );
333
- if ( empty( $height ) )
334
- $height = get_option( 'category_image_height' );
335
- } else {
336
- $height = $query['image_size']['height'];
337
- }
338
-
339
- $category_image = wpsc_get_categorymeta($category_row->term_id, 'image');
340
- $category_image_html = '';
341
- if(($query['show_thumbnails'] == 1)) {
342
- if((!empty($category_image)) && is_file(WPSC_CATEGORY_DIR.$category_image)) {
343
- $category_image_html = "<img src='".WPSC_CATEGORY_URL."$category_image' alt='{$category_row->name}' title='{$category_row->name}' style='width: {$width}px; height: {$height}px;' class='wpsc_category_image' />";
344
- } elseif( isset( $query['show_name'] ) && 1 == $query['show_name']) {
345
- $category_image_html .= "<span class='wpsc_category_image item_no_image ' style='width: {$width}px; height: {$height}px;'>\n\r";
346
- $category_image_html .= " <span class='link_substitute' >\n\r";
347
- $category_image_html .= " <span>".__('N/A','wpsc')."</span>\n\r";
348
- $category_image_html .= " </span>\n\r";
349
- $category_image_html .= "</span>\n\r";
350
- }
351
-
352
- }
353
-
354
-
355
- // get the list of products associated with this category.
356
- $tags_to_replace = array('[wpsc_category_name]',
357
- '[wpsc_category_description]',
358
- '[wpsc_category_url]',
359
- '[wpsc_category_id]',
360
- '[wpsc_category_classes]',
361
- '[wpsc_category_image]',
362
- '[wpsc_subcategory]',
363
- '[wpsc_category_products_count]');
364
-
365
- $content_to_place = array(
366
- esc_html($category_row->name),
367
- $category_description,
368
- esc_url( get_term_link( $category_row->slug, 'wpsc_product_category' ) ),
369
- $category_row->term_id,
370
- $category_classes,
371
- $category_image_html,
372
- $sub_categories,
373
- $category_count_html);
374
-
375
- // Stick all the category html together and concatenate it to the previously generated HTML
376
- $output .= str_replace($tags_to_replace, $content_to_place ,$category_html);
377
- }
378
- return $output;
379
- }
380
-
381
- /**
382
- * wpsc category image function
383
- * if no parameters are passed, the category is not resized, otherwise it is resized to the specified dimensions
384
- * @param integer category id
385
- * @param array category query array
386
- * @return string - the category image URL, or the URL of the resized version
387
- */
388
- function wpsc_place_category_image($category_id, $query) {
389
- // show the full sized image for the product, if supplied with dimensions, will resize image to those.
390
- $width = (isset($query['image_size']['width'])) ? ($query['image_size']['width']) : get_option('category_image_width');
391
- $height = (isset($query['image_size']['height'])) ? ($query['image_size']['height']) : get_option('category_image_height');
392
- $image_url = "index.php?wpsc_request_image=true&category_id=".$category_id."&width=".$width."&height=".$height;
393
- return htmlspecialchars($image_url);
394
- }
395
-
396
- /// category template tags end here
397
-
398
- /**
399
- * wpsc_category_url function, makes permalink to the category or
400
- * @param integer category ID, can be 0
401
- * @param boolean permalink compatibility, adds a prefix to prevent permalink namespace conflicts
402
- */
403
- function wpsc_category_url($category_id, $permalink_compatibility = false) {
404
- return get_term_link( $category_id, 'wpsc_product_category');
405
- }
406
-
407
-
408
- function wpsc_is_in_category() {
409
- global $wpdb, $wp_query;
410
- $is_in_category = false;
411
- if(isset($wp_query->query_vars['wpsc_product_category'] ) && !empty($wp_query->query_vars['wpsc_product_category'])) {
412
- $is_in_category = true;
413
- } else if(isset($_GET['wpsc_product_category']) && !empty($_GET['wpsc_product_category'])) {
414
- $is_in_category = true;
415
- }
416
-
417
- return $is_in_category;
418
- }
419
-
420
-
421
- /**
422
- * Uses a category's, (in the wpsc_product_category taxonomy), slug to find its
423
- * ID, then returns it.
424
- *
425
- * @param string $category_slug The slug of the category who's ID we want.
426
- * @return (int | bool) Returns the integer ID of the category if found, or a
427
- * boolean false if the category is not found.
428
- *
429
- * @todo Cache the results of this somewhere. It could save quite a few trips
430
- * to the MySQL server.
431
- *
432
- * @author John Beales ( johnbeales.com )
433
- */
434
- function wpsc_category_id($category_slug = '') {
435
- if(empty($category_slug))
436
- $category_slug = get_query_var( 'wpsc_product_category' );
437
- elseif(array_key_exists('wpsc_product_category', $_GET))
438
- $category_slug = $_GET['wpsc_product_category'];
439
-
440
- if(!empty($category_slug)) {
441
- $category = get_term_by('slug', $category_slug, 'wpsc_product_category');
442
- if(!empty($category->term_id)){
443
- return $category->term_id;
444
- } else {
445
- return false;
446
- }
447
- } else {
448
- return false;
449
- }
450
- }
451
-
452
-
453
- /**
454
- * wpsc_category_image function, Gets the category image or returns false
455
- * @param integer category ID, can be 0
456
- * @return string url to the category image
457
- */
458
- function wpsc_category_image($category_id = null) {
459
- if($category_id < 1)
460
- $category_id = wpsc_category_id();
461
- $category_image = wpsc_get_categorymeta($category_id, 'image');
462
- $category_path = WPSC_CATEGORY_DIR.basename($category_image);
463
- $category_url = WPSC_CATEGORY_URL.basename($category_image);
464
- if(file_exists($category_path) && is_file($category_path))
465
- return $category_url;
466
- return false;
467
- }
468
-
469
-
470
- /**
471
- * wpsc_category_description function, Gets the category description
472
- * @param integer category ID, can be 0
473
- * @return string category description
474
- */
475
- function wpsc_category_description($category_id = null) {
476
- if($category_id < 1)
477
- $category_id = wpsc_category_id();
478
- $category = get_term_by('id', $category_id, 'wpsc_product_category');
479
- return $category->description;
480
- }
481
-
482
- function wpsc_category_name($category_id = null) {
483
- if($category_id < 1)
484
- $category_id = wpsc_category_id();
485
- $category = get_term_by('id', $category_id, 'wpsc_product_category');
486
- return $category->name;
487
- }
488
-
489
- function nzshpcrt_display_categories_groups() {
490
- global $wpdb;
491
-
492
- return $output;
493
- }
494
-
495
- /** wpsc list subcategories function
496
- used to get an array of all the subcategories of a category.
497
- */
498
- function wpsc_list_subcategories($category_id = null) {
499
- global $wpdb,$category_data;
500
-
501
- $category_list = $wpdb->get_col( $wpdb->prepare( "SELECT `id` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `category_parent` = %d", $category_id ) );
502
-
503
- if($category_list != null) {
504
- foreach($category_list as $subcategory_id) {
505
- $category_list = array_merge((array)$category_list, (array)wpsc_list_subcategories($subcategory_id));
506
- }
507
- }
508
- return $category_list;
509
- }
510
-
511
-
512
  /**
513
  * wpsc_get_terms_category_sort_filter
514
  *
@@ -593,15 +118,3 @@ function wpsc_get_terms_variation_sort_filter($terms){
593
  }
594
  add_filter('get_terms','wpsc_get_terms_variation_sort_filter');
595
 
596
- /**
597
- * Abstracts Suhosin check into a function. Used primarily in relation to target markets.
598
- * May be deprecated or never publicly launched if we change how the target market variables work.
599
- *
600
- * @since 3.8.9
601
- * @return boolean
602
- */
603
- function wpsc_is_suhosin_enabled() {
604
- return @ extension_loaded( 'suhosin' ) && @ ini_get( 'suhosin.post.max_vars' ) > 0 && @ ini_get( 'suhosin.post.max_vars' ) < 500;
605
- }
606
-
607
- ?>
9
  * @since 3.7
10
  */
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  /**
13
  * wpsc_get_term_parents - get all parents of the term
14
  *
15
  * @param int $id - id of the term
16
+ * @return array of term objects or empty array if anything went wrong or there were no parents
17
  */
18
  function wpsc_get_term_parents( $term_id, $taxonomy ) {
19
+ $term = get_term( $term_id, $taxonomy );
20
 
21
+ if( empty( $term->parent ) )
22
  return array();
23
+
24
+ $parent = get_term( $term->parent, $taxonomy );
25
  if ( is_wp_error( $parent ) )
26
  return array();
27
 
28
  $parents = array( $parent->term_id );
29
 
30
  if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $parents ) ) {
31
+ $parents = array_merge( $parents, wpsc_get_term_parents( $parent->term_id, $taxonomy ) );
32
  }
33
 
34
  return $parents;
35
  }
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  /**
38
  * wpsc_get_terms_category_sort_filter
39
  *
118
  }
119
  add_filter('get_terms','wpsc_get_terms_variation_sort_filter');
120
 
 
 
 
 
 
 
 
 
 
 
 
 
wpsc-includes/checkout.class.php CHANGED
@@ -112,393 +112,6 @@ function wpsc_display_tax_label( $checkout = false ) {
112
  }
113
  }
114
 
115
- /**
116
- * returns true or false depending on whether there are checkout items or not
117
- * @access public
118
- *
119
- * @since 3.7
120
- * @return (boolean)
121
- */
122
- function wpsc_have_checkout_items() {
123
- global $wpsc_checkout;
124
- return $wpsc_checkout->have_checkout_items();
125
- }
126
-
127
- /**
128
- * The checkout item sets the checkout item to the next one in the loop
129
- * @access public
130
- *
131
- * @since 3.7
132
- * @return the checkout item array
133
- */
134
- function wpsc_the_checkout_item() {
135
- global $wpsc_checkout;
136
- return $wpsc_checkout->the_checkout_item();
137
- }
138
-
139
- /**
140
- * Checks shipping details
141
- * @access public
142
- *
143
- * @since 3.7
144
- * @return (boolean)
145
- */
146
- function wpsc_is_shipping_details() {
147
- global $wpsc_checkout;
148
- if ( $wpsc_checkout->checkout_item->unique_name == 'delivertoafriend' && get_option( 'shippingsameasbilling' ) == '1' ) {
149
- return true;
150
- } else {
151
- return false;
152
- }
153
- }
154
-
155
- /**
156
- * returns the class for shipping and billing forms
157
- * @access public
158
- *
159
- * @since 3.8
160
- * @param $additional_classes (string) additional classes to be
161
- * @return
162
- */
163
- function wpsc_the_checkout_details_class($additional_classes = ''){
164
- if(wpsc_is_shipping_details())
165
- echo "class='wpsc_shipping_forms ".$additional_classes."'";
166
- else
167
- echo "class='wpsc_billing_forms ".$additional_classes."'";
168
-
169
- }
170
-
171
- /**
172
- * Checks to see is user login form needs to be displayed
173
- * @access public
174
- *
175
- * @since 3.8
176
- * @return (boolean) true or false
177
- */
178
- function wpsc_show_user_login_form(){
179
- if(!is_user_logged_in() && get_option('users_can_register') && get_option('require_register'))
180
- return true;
181
- else
182
- return false;
183
- }
184
-
185
- /**
186
- * checks to see whether the country and categories selected have conflicts
187
- * i.e products of this category cannot be shipped to selected country
188
- * @access public
189
- *
190
- * @since 3.8
191
- * @return (boolean) true or false
192
- */
193
- function wpsc_has_category_and_country_conflict(){
194
- $conflict = wpsc_get_customer_meta( 'category_shipping_conflict' );
195
- return ( ! empty( $conflict ) );
196
- }
197
-
198
- /**
199
- * Have valid shipping zipcode
200
- * Logic was modified in 3.8.9 to check if the Calculate button was ever actually hit
201
- * @see http://code.google.com/p/wp-e-commerce/issues/detail?id=1014
202
- *
203
- * @access public
204
- *
205
- * @since 3.8
206
- * @return (boolean) true or false
207
- */
208
- function wpsc_have_valid_shipping_zipcode(){
209
- $zip = wpsc_get_customer_meta( 'shipping_zip' );
210
-
211
- if( ! $zip || ( __( 'Your Zipcode', 'wpsc' ) == $zip ) && ( wpsc_get_customer_meta( 'update_location' ) ) )
212
- return false;
213
- else
214
- return true;
215
-
216
- }
217
-
218
- /**
219
- * Checks to see whether terms and conditions are empty
220
- * @access public
221
- *
222
- * @since 3.8
223
- * @return (boolean) true or false
224
- */
225
- function wpsc_has_tnc(){
226
- if('' == get_option('terms_and_conditions'))
227
- return false;
228
- else
229
- return true;
230
- }
231
-
232
- /**
233
- * show find us checks whether the 'how you found us' drop down should be displayed
234
- * @access public
235
- *
236
- * @since 3.8
237
- * @return (boolean) true or false
238
- */
239
- function wpsc_show_find_us(){
240
- if(get_option('display_find_us') == '1')
241
- return true;
242
- else
243
- return false;
244
- }
245
-
246
- /**
247
- * disregard state fields - checks to see whether selected country has regions or not,
248
- * depending on the scenario will return wither a true or false
249
- * @access public
250
- *
251
- * @since 3.8
252
- * @return (boolean) true or false
253
- */
254
- function wpsc_disregard_shipping_state_fields(){
255
- global $wpsc_checkout;
256
- if ( ! wpsc_uses_shipping() ):
257
- $delivery_country = wpsc_get_customer_meta( 'shipping_country' );
258
- if ( 'shippingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions( $delivery_country ) )
259
- return true;
260
- else
261
- return false;
262
- elseif ( 'billingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions( wpsc_get_customer_meta( 'billing_country' ) ) ):
263
- return true;
264
- endif;
265
- }
266
-
267
- function wpsc_disregard_billing_state_fields(){
268
- global $wpsc_checkout;
269
- if ( 'billingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions( wpsc_get_customer_meta( 'billing_country' ) ) )
270
- return true;
271
- return false;
272
- }
273
-
274
-
275
- function wpsc_shipping_details() {
276
- global $wpsc_checkout;
277
- if ( stristr( $wpsc_checkout->checkout_item->unique_name, 'shipping' ) != false ) {
278
-
279
- return ' wpsc_shipping_forms';
280
- } else {
281
- return "";
282
- }
283
- }
284
-
285
- function wpsc_the_checkout_item_error_class( $as_attribute = true ) {
286
- global $wpsc_checkout, $wpsc_checkout_error_messages;
287
-
288
- $class_name = '';
289
-
290
- if ( ! empty( $wpsc_checkout_error_messages ) && isset( $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] ) && $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] != '' ) {
291
- $class_name = 'validation-error';
292
- }
293
- if ( ($as_attribute == true ) ) {
294
- $output = "class='" . $class_name . wpsc_shipping_details() . "'";
295
- } else {
296
- $output = $class_name;
297
- }
298
- return $output;
299
- }
300
-
301
- function wpsc_the_checkout_item_error() {
302
- global $wpsc_checkout, $wpsc_checkout_error_messages;
303
- $output = false;
304
- if ( ! empty( $wpsc_checkout_error_messages ) && isset( $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] ) && $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] != '' ) {
305
- $output = $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id];
306
- }
307
-
308
- return $output;
309
- }
310
-
311
- function wpsc_the_checkout_CC_validation() {
312
- global $wpsc_gateway_error_messages;
313
-
314
- $output = '';
315
- if ( ! empty( $wpsc_gateway_error_messages ) && ! empty( $wpsc_gateway_error_messages['card_number'] ) )
316
- $output = $wpsc_gateway_error_messages['card_number'];
317
-
318
- return $output;
319
- }
320
-
321
- function wpsc_the_checkout_CC_validation_class() {
322
- global $wpsc_gateway_error_messages;
323
- if ( empty( $wpsc_gateway_error_messages ) )
324
- return '';
325
-
326
- return empty( $wpsc_gateway_error_messages['card_number'] ) ? '' : 'class="validation-error"';
327
- }
328
-
329
- function wpsc_the_checkout_CCexpiry_validation_class() {
330
- global $wpsc_gateway_error_messages;
331
-
332
- if ( empty( $wpsc_gateway_error_messages ) )
333
- return '';
334
-
335
- return empty( $wpsc_gateway_error_messages['expdate'] ) ? '' : 'class="validation-error"';
336
- }
337
-
338
- function wpsc_the_checkout_CCexpiry_validation() {
339
- global $wpsc_gateway_error_messages;
340
-
341
- if ( empty( $wpsc_gateway_error_messages ) )
342
- return '';
343
-
344
- return empty( $wpsc_gateway_error_messages['expdate'] ) ? '' : $wpsc_gateway_error_messages['expdate'];
345
- }
346
-
347
- function wpsc_the_checkout_CCcvv_validation_class() {
348
- global $wpsc_gateway_error_messages;
349
-
350
- if ( empty( $wpsc_gateway_error_messages ) )
351
- return '';
352
-
353
- return empty( $wpsc_gateway_error_messages['card_code'] ) ? '' : 'class="validation-error"';
354
- }
355
-
356
- function wpsc_the_checkout_CCcvv_validation() {
357
- global $wpsc_gateway_error_messages;
358
-
359
- if ( empty( $wpsc_gateway_error_messages ) )
360
- return '';
361
-
362
- return empty( $wpsc_gateway_error_messages['card_code'] ) ? '' : $wpsc_gateway_error_messages['card_code'];
363
- }
364
-
365
- function wpsc_the_checkout_CCtype_validation_class() {
366
- global $wpsc_gateway_error_messages;
367
-
368
- if ( empty( $wpsc_gateway_error_messages ) )
369
- return '';
370
-
371
- return empty( $wpsc_gateway_error_messages['cctype'] ) ? '' : 'class="validation-error"';
372
- }
373
-
374
- function wpsc_the_checkout_CCtype_validation() {
375
- global $wpsc_gateway_error_messages;
376
-
377
- if ( empty( $wpsc_gateway_error_messages ) )
378
- return '';
379
-
380
- return empty( $wpsc_gateway_error_messages['cctype'] ) ? '' : $wpsc_gateway_error_messages['cctype'];
381
- }
382
-
383
- function wpsc_checkout_form_is_header() {
384
- global $wpsc_checkout;
385
- if ( $wpsc_checkout->checkout_item->type == 'heading' ) {
386
- $output = true;
387
- } else {
388
- $output = false;
389
- }
390
- return $output;
391
- }
392
-
393
- function wpsc_checkout_form_name() {
394
- global $wpsc_checkout;
395
- return $wpsc_checkout->form_name();
396
- }
397
-
398
- function wpsc_checkout_form_element_id() {
399
- global $wpsc_checkout;
400
- return $wpsc_checkout->form_element_id();
401
- }
402
-
403
- function wpsc_checkout_form_field() {
404
- global $wpsc_checkout;
405
- return $wpsc_checkout->form_field();
406
- }
407
-
408
- function wpsc_shipping_region_list( $selected_country, $selected_region, $shippingdetails = false ) {
409
- global $wpdb;
410
- $output = '';
411
- $region_data = $wpdb->get_results( $wpdb->prepare( "SELECT `regions`.* FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN(%s) ORDER BY name ASC", $selected_country ), ARRAY_A );
412
- $js = '';
413
- if ( !$shippingdetails ) {
414
- $js = "onchange='submit_change_country();'";
415
- }
416
- if ( count( $region_data ) > 0 ) {
417
- $output .= "<select name='region' id='region' " . $js . " >";
418
- foreach ( $region_data as $region ) {
419
- $selected = '';
420
- if ( $selected_region == $region['id'] ) {
421
- $selected = "selected='selected'";
422
- }
423
- $output .= "<option $selected value='{$region['id']}'>" . esc_attr( htmlspecialchars( $region['name'] ) ). "</option>";
424
- }
425
- $output .= "";
426
-
427
- $output .= "</select>";
428
- } else {
429
- $output .= " ";
430
- }
431
- return $output;
432
- }
433
-
434
- function wpsc_shipping_country_list( $shippingdetails = false ) {
435
- global $wpdb, $wpsc_shipping_modules, $wpsc_country_data;
436
- $js = '';
437
- $output = '';
438
- if ( !$shippingdetails ) {
439
- $output = "<input type='hidden' name='wpsc_ajax_actions' value='update_location' />";
440
- $js = " onchange='submit_change_country();'";
441
- }
442
- $selected_country = (string) wpsc_get_customer_meta( 'shipping_country' );
443
- $selected_region = (string) wpsc_get_customer_meta( 'shipping_region' );
444
-
445
- if ( empty( $selected_country ) )
446
- $selected_country = esc_attr( get_option( 'base_country' ) );
447
-
448
- if ( empty( $selected_region ) )
449
- $selected_region = esc_attr( get_option( 'base_region' ) );
450
-
451
- if ( empty( $wpsc_country_data ) )
452
- $country_data = $wpdb->get_results( "SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `visible`= '1' ORDER BY `country` ASC", ARRAY_A );
453
- else
454
- $country_data = $wpsc_country_data;
455
-
456
- $acceptable_countries = wpsc_get_acceptable_countries();
457
-
458
- $output .= wpsc_get_country_dropdown( array(
459
- 'name' => 'country',
460
- 'id' => 'current_country',
461
- 'additional_attributes' => $js,
462
- 'acceptable_ids' => $acceptable_countries,
463
- 'selected' => $selected_country,
464
- 'placeholder' => '',
465
- ) );
466
-
467
- $output .= wpsc_shipping_region_list( $selected_country, $selected_region, $shippingdetails );
468
-
469
- if ( isset( $_POST['wpsc_update_location'] ) && $_POST['wpsc_update_location'] == 'true' ) {
470
- wpsc_update_customer_meta( 'update_location', true );
471
- } else {
472
- wpsc_delete_customer_meta( 'update_location' );
473
- }
474
-
475
- $zipvalue = (string) wpsc_get_customer_meta( 'shipping_zip' );
476
- if ( ! empty( $_POST['zipcode'] ) )
477
- $zipvalue = $_POST['zipcode'];
478
-
479
- $zip_code_text = __( 'Your Zipcode', 'wpsc' );
480
-
481
- if ( ( $zipvalue != '' ) && ( $zipvalue != $zip_code_text ) ) {
482
- $color = '#000';
483
- wpsc_update_customer_meta( 'shipping_zip', $zipvalue );
484
- } else {
485
- $zipvalue = $zip_code_text;
486
- $color = '#999';
487
- }
488
-
489
- $uses_zipcode = false;
490
- $custom_shipping = get_option( 'custom_shipping_options' );
491
- foreach ( (array)$custom_shipping as $shipping ) {
492
- if ( isset( $wpsc_shipping_modules[$shipping]->needs_zipcode ) && $wpsc_shipping_modules[$shipping]->needs_zipcode == true ) {
493
- $uses_zipcode = true;
494
- }
495
- }
496
-
497
- if ( $uses_zipcode ) {
498
- $output .= " <input type='text' style='color:" . $color . ";' onclick='if (this.value==\"" . esc_js( $zip_code_text ) . "\") {this.value=\"\";this.style.color=\"#000\";}' onblur='if (this.value==\"\") {this.style.color=\"#999\"; this.value=\"" . esc_js( $zip_code_text ) . "\"; }' value='" . esc_attr( $zipvalue ) . "' size='10' name='zipcode' id='zipcode'>";
499
- }
500
- return $output;
501
- }
502
  /**
503
  * Cycles through the categories represented by the products in the cart.
504
  * Retrieves their target markets and returns an array of acceptable markets
@@ -562,6 +175,7 @@ function wpsc_get_acceptable_countries() {
562
  return $target_market_ids;
563
 
564
  }
 
565
  /**
566
  * The WPSC Checkout class
567
  */
@@ -574,7 +188,7 @@ class wpsc_checkout {
574
  var $current_checkout_item = -1;
575
  var $in_the_loop = false;
576
  //the ticket additions
577
- var $additional_fields = array( );
578
  var $formfield_count = 0;
579
 
580
  /**
@@ -1113,31 +727,4 @@ class wpsc_checkout {
1113
  }
1114
  }
1115
 
1116
- }
1117
-
1118
- function wpsc_get_gateway_list() {
1119
- return apply_filters( 'wpsc_get_gateway_list', '' );
1120
- }
1121
-
1122
- function wpsc_gateway_list() {
1123
- echo wpsc_get_gateway_list();
1124
- }
1125
-
1126
- function wpsc_gateway_count() {
1127
- return apply_filters( 'wpsc_gateway_count', 0 );
1128
- }
1129
-
1130
- function wpsc_get_gateway_hidden_field() {
1131
- $output = sprintf(
1132
- '<input name="custom_gateway" value="%s" type="hidden" />',
1133
- apply_filters( 'wpsc_gateway_hidden_field_value', '' )
1134
- );
1135
-
1136
- return $output;
1137
- }
1138
-
1139
- function wpsc_gateway_hidden_field() {
1140
- do_action( 'wpsc_before_gateway_hidden_field' );
1141
- echo wpsc_get_gateway_hidden_field();
1142
- do_action( 'wpsc_after_gateway_hidden_field' );
1143
  }
112
  }
113
  }
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  /**
116
  * Cycles through the categories represented by the products in the cart.
117
  * Retrieves their target markets and returns an array of acceptable markets
175
  return $target_market_ids;
176
 
177
  }
178
+
179
  /**
180
  * The WPSC Checkout class
181
  */
188
  var $current_checkout_item = -1;
189
  var $in_the_loop = false;
190
  //the ticket additions
191
+ var $additional_fields = array();
192
  var $formfield_count = 0;
193
 
194
  /**
727
  }
728
  }
729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
730
  }
wpsc-includes/coupons.class.php CHANGED
@@ -155,7 +155,7 @@ class wpsc_coupons {
155
  break;
156
 
157
  case 'contains'://Checks if the product name contains the condition value
158
- return preg_match( "/(.*)".$condition['value']."(.*)/", $product_data->post_title );
159
  break;
160
 
161
  case 'category'://Checks if the product category is the condition value
@@ -163,19 +163,24 @@ class wpsc_coupons {
163
  if ( $product_data->post_parent )
164
  $id = $product_data->post_parent;
165
 
166
- return has_term( $condition['value'], 'wpsc_product_category', $id );
 
 
 
 
 
167
  break;
168
 
169
  case 'not_contain'://Checks if the product name contains the condition value
170
- return ! preg_match( "/(.*)".$condition['value']."(.*)/", $product_data->post_title );
171
  break;
172
 
173
  case 'begins'://Checks if the product name begins with condition value
174
- return preg_match( "/^".$condition['value']."/", $product_data->post_title );
175
  break;
176
 
177
  case 'ends'://Checks if the product name ends with condition value
178
- return preg_match( "/".$c['value']."$/", $product_data->post_title );
179
  break;
180
  }
181
 
@@ -568,110 +573,110 @@ class wpsc_coupons {
568
  function compare_logic($c, $product_obj) {
569
  global $wpdb;
570
 
571
- if ($c['property'] == 'item_name') {
572
- $product_data = $wpdb->get_results("SELECT * FROM " . $wpdb->posts . " WHERE id='{$product_obj->product_id}'");
573
  $product_data = $product_data[0];
574
 
575
- switch($c['logic']) {
576
  case 'equal': //Checks if the product name is exactly the same as the condition value
577
- if ($product_data->post_title == $c['value']) {
578
-
579
- return true;
580
- }
581
  break;
582
 
583
  case 'greater'://Checks if the product name is not the same as the condition value
584
- if ($product_data->post_title > $c['value'])
585
- return true;
586
  break;
587
 
588
  case 'less'://Checks if the product name is not the same as the condition value
589
- if ($product_data->post_title < $c['value'])
590
- return true;
591
  break;
592
 
593
  case 'contains'://Checks if the product name contains the condition value
594
- preg_match("/(.*)".$c['value']."(.*)/", $product_data->post_title, $match);
595
- if (!empty($match))
596
- return true;
 
597
  break;
598
 
599
  case 'category'://Checks if the product category is the condition value
600
- if ( $product_data->post_parent ) {
601
- $categories = wpsc_get_product_terms( $product_data->post_parent, 'wpsc_product_category' );
602
- } else {
603
- $categories = wpsc_get_product_terms( $product_data->ID, 'wpsc_product_category' );
604
- }
605
- foreach ( $categories as $cat ) {
606
- if ( strtolower( $cat->name ) == strtolower( $c['value'] ) )
607
- return true;
608
- }
609
  break;
610
 
611
  case 'not_contain'://Checks if the product name contains the condition value
612
- preg_match("/(.*)".$c['value']."(.*)/", $product_data->post_title, $match);
613
- if (empty($match))
614
- return true;
 
615
  break;
616
 
617
  case 'begins'://Checks if the product name begins with condition value
618
- preg_match("/^".$c['value']."/", $product_data->post_title, $match);
619
- if (!empty($match))
620
- return true;
621
  break;
622
 
623
  case 'ends'://Checks if the product name ends with condition value
624
- preg_match("/".$c['value']."$/", $product_data->post_title, $match);
625
- if (!empty($match))
626
- return true;
627
  break;
628
 
629
  default:
630
  return false;
631
  }
632
- } else if ($c['property'] == 'item_quantity'){
633
 
634
- switch($c['logic']) {
635
  case 'equal'://Checks if the quantity of a product in the cart equals condition value
636
- if ($product_obj->quantity == (int)$c['value'])
637
- return true;
638
  break;
639
 
640
  case 'greater'://Checks if the quantity of a product is greater than the condition value
641
- if ($product_obj->quantity > $c['value'])
642
- return true;
643
  break;
644
 
645
  case 'less'://Checks if the quantity of a product is less than the condition value
646
- if ($product_obj->quantity < $c['value'])
647
- return true;
648
  break;
649
 
650
  case 'contains'://Checks if the product name contains the condition value
651
- preg_match("/(.*)".$c['value']."(.*)/", $product_obj->quantity, $match);
652
- if (!empty($match))
653
- return true;
654
  break;
655
 
656
  case 'not_contain'://Checks if the product name contains the condition value
657
- preg_match("/(.*)".$c['value']."(.*)/",$product_obj->quantity, $match);
658
- if (empty($match))
659
- return true;
660
  break;
661
 
662
  case 'begins'://Checks if the product name begins with condition value
663
- preg_match("/^".$c['value']."/", $product_obj->quantity, $match);
664
- if (!empty($match))
665
- return true;
666
  break;
667
 
668
  case 'ends'://Checks if the product name ends with condition value
669
- preg_match("/".$c['value']."$/",$product_obj->quantity, $match);
670
- if (!empty($match))
671
- return true;
672
- break;
673
  default:
674
- return false;
675
  }
676
  } else if ($c['property'] == 'total_quantity'){
677
  $total_quantity = wpsc_cart_item_count();
155
  break;
156
 
157
  case 'contains'://Checks if the product name contains the condition value
158
+ return preg_match( "/(.*)" . preg_quote( $condition['value'], '/' ) . "(.*)/", $product_data->post_title );
159
  break;
160
 
161
  case 'category'://Checks if the product category is the condition value
163
  if ( $product_data->post_parent )
164
  $id = $product_data->post_parent;
165
 
166
+ $category_condition = $condition['value'];
167
+ if ( false !== strpos( $category_condition, ',' ) ) {
168
+ $category_condition = explode( ',', $condition['value'] );
169
+ $category_condition = array_map( 'trim', $cond );
170
+ }
171
+ return has_term( $category_condition, 'wpsc_product_category', $id );
172
  break;
173
 
174
  case 'not_contain'://Checks if the product name contains the condition value
175
+ return ! preg_match( "/(.*)" . preg_quote( $condition['value'], '/' ) . "(.*)/", $product_data->post_title );
176
  break;
177
 
178
  case 'begins'://Checks if the product name begins with condition value
179
+ return preg_match( "/^" . preg_quote( $condition['value'], '/' ) . "/", $product_data->post_title );
180
  break;
181
 
182
  case 'ends'://Checks if the product name ends with condition value
183
+ return preg_match( "/" . preg_quote( $c['value'], '/' ) . "$/", $product_data->post_title );
184
  break;
185
  }
186
 
573
  function compare_logic($c, $product_obj) {
574
  global $wpdb;
575
 
576
+ if ( 'item_name' == $c['property'] ) {
577
+ $product_data = $wpdb->get_results( "SELECT * FROM " . $wpdb->posts . " WHERE id='{$product_obj->product_id}'" );
578
  $product_data = $product_data[0];
579
 
580
+ switch( $c['logic'] ) {
581
  case 'equal': //Checks if the product name is exactly the same as the condition value
582
+ if ( $product_data->post_title == $c['value'] )
583
+ return true;
 
 
584
  break;
585
 
586
  case 'greater'://Checks if the product name is not the same as the condition value
587
+ if ( $product_data->post_title > $c['value'] )
588
+ return true;
589
  break;
590
 
591
  case 'less'://Checks if the product name is not the same as the condition value
592
+ if ( $product_data->post_title < $c['value'] )
593
+ return true;
594
  break;
595
 
596
  case 'contains'://Checks if the product name contains the condition value
597
+ preg_match( "/(.*)" . preg_quote( $c['value'], '/' ) . "(.*)/", $product_data->post_title, $match );
598
+
599
+ if ( ! empty( $match ) )
600
+ return true;
601
  break;
602
 
603
  case 'category'://Checks if the product category is the condition value
604
+ if ( $product_data->post_parent ) {
605
+ $categories = wpsc_get_product_terms( $product_data->post_parent, 'wpsc_product_category' );
606
+ } else {
607
+ $categories = wpsc_get_product_terms( $product_data->ID, 'wpsc_product_category' );
608
+ }
609
+ foreach ( $categories as $cat ) {
610
+ if ( strtolower( $cat->name ) == strtolower( $c['value'] ) )
611
+ return true;
612
+ }
613
  break;
614
 
615
  case 'not_contain'://Checks if the product name contains the condition value
616
+ preg_match( "/(.*)" . preg_quote( $c['value'], '/' ) . "(.*)/", $product_data->post_title, $match );
617
+
618
+ if ( empty( $match ) )
619
+ return true;
620
  break;
621
 
622
  case 'begins'://Checks if the product name begins with condition value
623
+ preg_match( "/^" . preg_quote( $c['value'], '/' ) . "/", $product_data->post_title, $match );
624
+ if ( ! empty( $match ) )
625
+ return true;
626
  break;
627
 
628
  case 'ends'://Checks if the product name ends with condition value
629
+ preg_match( "/" . preg_quote( $c['value'], '/' ) . "$/", $product_data->post_title, $match );
630
+ if ( ! empty( $match ) )
631
+ return true;
632
  break;
633
 
634
  default:
635
  return false;
636
  }
637
+ } else if ( 'item_quantity' == $c['property'] ) {
638
 
639
+ switch( $c['logic'] ) {
640
  case 'equal'://Checks if the quantity of a product in the cart equals condition value
641
+ if ( $product_obj->quantity == (int) $c['value'] )
642
+ return true;
643
  break;
644
 
645
  case 'greater'://Checks if the quantity of a product is greater than the condition value
646
+ if ( $product_obj->quantity > $c['value'] )
647
+ return true;
648
  break;
649
 
650
  case 'less'://Checks if the quantity of a product is less than the condition value
651
+ if ( $product_obj->quantity < $c['value'] )
652
+ return true;
653
  break;
654
 
655
  case 'contains'://Checks if the product name contains the condition value
656
+ preg_match( "/(.*)" . $c['value'] . "(.*)/", $product_obj->quantity, $match );
657
+ if ( ! empty( $match ) )
658
+ return true;
659
  break;
660
 
661
  case 'not_contain'://Checks if the product name contains the condition value
662
+ preg_match("/(.*)".$c['value']."(.*)/",$product_obj->quantity, $match );
663
+ if ( empty( $match ) )
664
+ return true;
665
  break;
666
 
667
  case 'begins'://Checks if the product name begins with condition value
668
+ preg_match("/^".$c['value']."/", $product_obj->quantity, $match );
669
+ if ( ! empty( $match ) )
670
+ return true;
671
  break;
672
 
673
  case 'ends'://Checks if the product name ends with condition value
674
+ preg_match( "/" . $c['value'] . "$/", $product_obj->quantity, $match );
675
+ if ( ! empty( $match ) )
676
+ return true;
677
+ break;
678
  default:
679
+ return false;
680
  }
681
  } else if ($c['property'] == 'total_quantity'){
682
  $total_quantity = wpsc_cart_item_count();
wpsc-includes/cron.php CHANGED
@@ -27,11 +27,18 @@ function wpsc_clear_stock_claims() {
27
  function _wpsc_clear_customer_meta() {
28
  global $wpdb;
29
 
30
- $sql = $wpdb->prepare( "SELECT option_name FROM " . $wpdb->options . " WHERE option_name LIKE '_transient_timeout_wpsc_customer_meta_%%' AND option_value < %d", time() );
31
- $results = $wpdb->get_col( $sql );
32
-
33
- foreach ( $results as $row ) {
34
- $customer_id = str_replace( '_transient_timeout_wpsc_customer_meta_', '', $row );
35
- delete_transient( "wpsc_customer_meta_{$customer_id}" );
 
 
 
 
 
 
 
36
  }
37
  }
27
  function _wpsc_clear_customer_meta() {
28
  global $wpdb;
29
 
30
+ require_once( ABSPATH . 'wp-admin/includes/user.php' );
31
+
32
+ $sql = "
33
+ SELECT user_id
34
+ FROM {$wpdb->usermeta}
35
+ WHERE
36
+ meta_key = '_wpsc_last_active'
37
+ AND meta_value < UNIX_TIMESTAMP() - " . WPSC_CUSTOMER_DATA_EXPIRATION . "
38
+ ";
39
+
40
+ $ids = $wpdb->get_col( $sql );
41
+ foreach ( $ids as $id ) {
42
+ wp_delete_user( $id );
43
  }
44
  }
wpsc-includes/customer.php ADDED
@@ -0,0 +1,464 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'wpsc_set_cart_item' , '_wpsc_action_update_customer_last_active' );
4
+ add_action( 'wpsc_add_item' , '_wpsc_action_update_customer_last_active' );
5
+ add_action( 'wpsc_before_submit_checkout', '_wpsc_action_update_customer_last_active' );
6
+
7
+ /**
8
+ * Helper function for setting the customer cookie content and expiration
9
+ *
10
+ * @since 3.8.13
11
+ * @access private
12
+ * @param mixed $cookie Cookie data
13
+ * @param int $expire Expiration timestamp
14
+ */
15
+ function _wpsc_set_customer_cookie( $cookie, $expire ) {
16
+ $secure = is_ssl();
17
+ setcookie( WPSC_CUSTOMER_COOKIE, $cookie, $expire, WPSC_CUSTOMER_COOKIE_PATH, COOKIE_DOMAIN, $secure, true );
18
+
19
+ if ( $expire < time() )
20
+ unset( $_COOKIE[WPSC_CUSTOMER_COOKIE] );
21
+ else
22
+ $_COOKIE[WPSC_CUSTOMER_COOKIE] = $cookie;
23
+ }
24
+
25
+ /**
26
+ * In case the user is not logged in, create a new user account and store its ID
27
+ * in a cookie
28
+ *
29
+ * @access public
30
+ * @since 3.8.9
31
+ * @return string Customer ID
32
+ */
33
+ function _wpsc_create_customer_id() {
34
+ global $wp_roles;
35
+
36
+ $role = $wp_roles->get_role( 'wpsc_anonymous' );
37
+
38
+ if ( ! $role )
39
+ $wp_roles->add_role( 'wpsc_anonymous', __( 'Anonymous', 'wpsc' ) );
40
+
41
+ $username = '_' . wp_generate_password( 8, false, false );
42
+ $password = wp_generate_password( 12, false );
43
+
44
+ $id = wp_create_user( $username, $password );
45
+ $user = new WP_User( $id );
46
+ $user->set_role( 'wpsc_anonymous' );
47
+
48
+ update_user_meta( $id, '_wpsc_last_active', time() );
49
+
50
+ _wpsc_create_customer_id_cookie( $id );
51
+
52
+ return $id;
53
+ }
54
+
55
+ /**
56
+ * Set up a dummy user account for bots.
57
+ *
58
+ * This is not an ideal solution but it prevents third party plugins from failing
59
+ * because they rely on the customer meta being there no matter whether this request
60
+ * is by a bot or not.
61
+ *
62
+ * @since 3.8.13
63
+ * @access private
64
+ */
65
+ function _wpsc_maybe_setup_bot_user() {
66
+ if ( ! _wpsc_is_bot_user() )
67
+ return;
68
+
69
+ $username = '_wpsc_bot';
70
+ $wp_user = get_user_by( 'login', $username );
71
+
72
+ if ( $wp_user === false ) {
73
+ $password = wp_generate_password( 12, false );
74
+ $id = wp_create_user( $username, $password );
75
+ $user = new WP_User( $id );
76
+ $user->set_role( 'wpsc_anonymous' );
77
+ } else {
78
+ $id = $wp_user->ID;
79
+ }
80
+
81
+ // pretend that the cookie exists but don't actually need to use setcookie()
82
+ _wpsc_create_customer_id_cookie( $id, true );
83
+
84
+ return $id;
85
+ }
86
+
87
+ /**
88
+ * Create a cookie for a specific customer ID.
89
+ *
90
+ * You can also fake it by just assigning the cookie to $_COOKIE superglobal.
91
+ *
92
+ * @since 3.8.13
93
+ * @access private
94
+ * @param int $id Customer ID
95
+ * @param boolean $fake_it Defaults to false
96
+ */
97
+ function _wpsc_create_customer_id_cookie( $id, $fake_it = false ) {
98
+ $expire = time() + WPSC_CUSTOMER_DATA_EXPIRATION; // valid for 48 hours
99
+ $data = $id . $expire;
100
+ $hash = hash_hmac( 'md5', $data, wp_hash( $data ) );
101
+ $cookie = $id . '|' . $expire . '|' . $hash;
102
+
103
+ // store ID, expire and hash to validate later
104
+ if ( $fake_it )
105
+ $_COOKIE[WPSC_CUSTOMER_COOKIE] = $cookie;
106
+ else
107
+ _wpsc_set_customer_cookie( $cookie, $expire );
108
+ }
109
+
110
+ /**
111
+ * Make sure the customer cookie is not compromised.
112
+ *
113
+ * @access public
114
+ * @since 3.8.9
115
+ * @return mixed Return the customer ID if the cookie is valid, false if otherwise.
116
+ */
117
+ function _wpsc_validate_customer_cookie() {
118
+ if ( is_admin() || ! isset( $_COOKIE[WPSC_CUSTOMER_COOKIE] ) )
119
+ return;
120
+
121
+ $cookie = $_COOKIE[WPSC_CUSTOMER_COOKIE];
122
+ list( $id, $expire, $hash ) = $x = explode( '|', $cookie );
123
+ $data = $id . $expire;
124
+ $hmac = hash_hmac( 'md5', $data, wp_hash( $data ) );
125
+
126
+ $valid = true;
127
+
128
+ if ( ($hmac != $hash) || empty( $id ) || !is_numeric($id)) {
129
+ $valid = false;
130
+ } else {
131
+ // check to be sure the user still exists, could have been purged
132
+ $id = intval( $id );
133
+ $wp_user = get_user_by( 'id', $id );
134
+ if ( $wp_user === false ) {
135
+ $valid = false;
136
+ }
137
+ }
138
+
139
+ // if the cookie is invalid, just delete it and a new user will be generated
140
+ // later
141
+ if ( ! $valid ) {
142
+ unset( $_COOKIE[WPSC_CUSTOMER_COOKIE] );
143
+ _wpsc_set_customer_cookie( '', time() - 3600 );
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Get current customer ID.
149
+ *
150
+ * If the user is logged in, return the user ID. Otherwise return the ID associated
151
+ * with the customer's cookie.
152
+ *
153
+ * Implement your own system by hooking into 'wpsc_get_current_customer_id' filter.
154
+ *
155
+ * @access public
156
+ * @since 3.8.9
157
+ * @return mixed User ID (if logged in) or customer cookie ID
158
+ */
159
+ function wpsc_get_current_customer_id() {
160
+ $id = apply_filters( 'wpsc_get_current_customer_id', null );
161
+
162
+ if ( ! empty( $id ) )
163
+ return $id;
164
+
165
+ // if the user is logged in and the cookie is still there, delete the cookie
166
+ if ( is_user_logged_in() && isset( $_COOKIE[WPSC_CUSTOMER_COOKIE] ) ) {
167
+ _wpsc_set_customer_cookie( '', time() - 3600 );
168
+ }
169
+
170
+ // if the user is logged in we use the user id
171
+ if ( is_user_logged_in() ) {
172
+ return get_current_user_id();
173
+ } elseif ( isset( $_COOKIE[WPSC_CUSTOMER_COOKIE] ) ) {
174
+ list( $id, $expire, $hash ) = explode( '|', $_COOKIE[WPSC_CUSTOMER_COOKIE] );
175
+ return $id;
176
+ }
177
+
178
+ return _wpsc_create_customer_id();
179
+ }
180
+
181
+ /**
182
+ * Setup current user object and customer ID as well as cart.
183
+ *
184
+ * @uses do_action() Calls 'wpsc_setup_customer' after customer data is ready
185
+ *
186
+ * @access private
187
+ * @since 3.8.13
188
+ */
189
+ function _wpsc_action_setup_customer() {
190
+ // if the customer cookie is invalid, unset it
191
+ _wpsc_validate_customer_cookie();
192
+
193
+ // if this request is by a bot, prevent multiple account creation
194
+ _wpsc_maybe_setup_bot_user();
195
+
196
+ // initialize customer ID if it's not already there
197
+ wpsc_get_current_customer_id();
198
+
199
+ // setup the cart and restore its items
200
+ wpsc_core_setup_cart();
201
+
202
+ do_action( 'wpsc_setup_customer' );
203
+ }
204
+
205
+ /**
206
+ * Return the internal customer meta key, which depends on the blog prefix
207
+ * if this is a multi-site installation.
208
+ *
209
+ * @since 3.8.13
210
+ * @access private
211
+ * @param string $key Meta key
212
+ * @return string Internal meta key
213
+ */
214
+ function _wpsc_get_customer_meta_key( $key ) {
215
+ $blog_prefix = is_multisite() ? $wpdb->get_blog_prefix() : '';
216
+ return "{$blog_prefix}_wpsc_{$key}";
217
+ }
218
+
219
+ /**
220
+ * Delete all customer meta for a certain customer ID.
221
+ *
222
+ * Implement your own system by hooking into 'wpsc_delete_all_customer_meta'.
223
+ *
224
+ * @since 3.8.9.4
225
+ * @param string|int $id Customer ID. Optional. Defaults to current customer
226
+ * @return boolean True if successful, False if otherwise
227
+ */
228
+ function wpsc_delete_all_customer_meta( $id = false ) {
229
+ if ( ! $id )
230
+ $id = wpsc_get_current_customer_id();
231
+
232
+ $result = apply_filters( 'wpsc_delete_all_customer_meta', null, $id );
233
+
234
+ if ( $result )
235
+ return $result;
236
+
237
+ $meta = get_user_meta( $id );
238
+ $blog_prefix = is_multisite() ? $wpdb->get_blog_prefix() : '';
239
+ $key_pattern = "{$blog_prefix}_wpsc_";
240
+ $success = true;
241
+
242
+ foreach ( $meta as $key => $value ) {
243
+ if ( strpos( $key, $key_pattern ) === 0 )
244
+ $success = $success && delete_user_meta( $id, $key );
245
+ }
246
+
247
+ return $success;
248
+ }
249
+
250
+ /**
251
+ * Delete customer meta.
252
+ *
253
+ * Implement your own system by hooking into 'wpsc_delete_customer_meta'.
254
+ *
255
+ * @access public
256
+ * @since 3.8.9
257
+ * @param string $key Meta key
258
+ * @param string|int $id Customer ID. Optional. Defaults to current customer.
259
+ * @return boolean|WP_Error True if successful. False if not successful. WP_Error
260
+ * if there are any errors.
261
+ */
262
+ function wpsc_delete_customer_meta( $key, $id = false ) {
263
+ if ( ! $id )
264
+ $id = wpsc_get_current_customer_id();
265
+
266
+ $result = apply_filters( 'wpsc_delete_customer_meta', null, $key, $id );
267
+
268
+ if ( $result )
269
+ return $result;
270
+
271
+ return delete_user_meta( $id, _wpsc_get_customer_meta_key( $key ) );
272
+ }
273
+
274
+ /**
275
+ * Update a customer meta.
276
+ *
277
+ * Implement your own system by hooking into 'wpsc_update_customer_meta'.
278
+ *
279
+ * @access public
280
+ * @since 3.8.9
281
+ * @param string $key Meta key
282
+ * @param mixed $value Meta value
283
+ * @param string|int $id Customer ID. Optional. Defaults to current customer.
284
+ * @return boolean|WP_Error True if successful, false if not successful, WP_Error
285
+ * if there are any errors.
286
+ */
287
+ function wpsc_update_customer_meta( $key, $value, $id = false ) {
288
+ if ( ! $id )
289
+ $id = wpsc_get_current_customer_id();
290
+
291
+ $result = apply_filters( 'wpsc_update_customer_meta', null, $key, $value, $id );
292
+
293
+ if ( $result )
294
+ return $result;
295
+
296
+ return update_user_meta( $id, _wpsc_get_customer_meta_key( $key ), $value );
297
+ }
298
+
299
+ /**
300
+ * Overwrite customer meta with an array of meta_key => meta_value.
301
+ *
302
+ * Implement your own system by hooking into 'wpsc_update_all_customer_meta'.
303
+ *
304
+ * @access public
305
+ * @since 3.8.9
306
+ * @param array $profile Customer meta array
307
+ * @param int|string $id Customer ID. Optional. Defaults to current customer.
308
+ * @return boolean True if meta values are updated successfully. False
309
+ * if otherwise.
310
+ */
311
+ function wpsc_update_all_customer_meta( $profile, $id = false ) {
312
+ if ( ! $id )
313
+ $id = wpsc_get_current_customer_id();
314
+
315
+ $result = apply_filters( 'wpsc_update_all_customer_meta', null, $profile, $id );
316
+
317
+ if ( $result )
318
+ return $result;
319
+
320
+ wpsc_delete_all_customer_meta( $id );
321
+ $success = true;
322
+
323
+ foreach ( $profile as $key => $value ) {
324
+ $success = $success && wpsc_update_customer_meta( $key, $value, $id );
325
+ }
326
+
327
+ return $success;
328
+ }
329
+
330
+ /**
331
+ * Get a customer meta value.
332
+ *
333
+ * Implement your own system by hooking into 'wpsc_get_customer_meta'.
334
+ *
335
+ * @access public
336
+ * @since 3.8.9
337
+ * @param string $key Meta key
338
+ * @param int|string $id Customer ID. Optional, defaults to current customer
339
+ * @return mixed Meta value, or null if it doesn't exist or if the
340
+ * customer ID is invalid.
341
+ */
342
+ function wpsc_get_customer_meta( $key = '', $id = false ) {
343
+ if ( ! $id )
344
+ $id = wpsc_get_current_customer_id();
345
+
346
+ $result = apply_filters( 'wpsc_get_customer_meta', null, $key, $id );
347
+
348
+ if ( $result )
349
+ return $result;
350
+
351
+ return get_user_meta( $id, _wpsc_get_customer_meta_key( $key ), true );
352
+ }
353
+
354
+ /**
355
+ * Return an array containing all metadata of a customer
356
+ *
357
+ * Implement your own system by hooking into 'wpsc_get_all_customer_meta'.
358
+ *
359
+ * @access public
360
+ * @since 3.8.9
361
+ * @param mixed $id Customer ID. Default to the current user ID.
362
+ * @return WP_Error|array Return an array of metadata if no error occurs, WP_Error
363
+ * if otherwise.
364
+ */
365
+ function wpsc_get_all_customer_meta( $id = false ) {
366
+ global $wpdb;
367
+
368
+ if ( ! $id )
369
+ $id = wpsc_get_current_customer_id();
370
+
371
+ $result = apply_filters( 'wpsc_get_all_customer_meta', null, $id );
372
+
373
+ if ( $result )
374
+ return $result;
375
+
376
+ $meta = get_user_meta( $id );
377
+ $blog_prefix = is_multisite() ? $wpdb->get_blog_prefix() : '';
378
+ $key_pattern = "{$blog_prefix}_wpsc_";
379
+
380
+ $return = array();
381
+
382
+ foreach ( $meta as $key => $value ) {
383
+ if ( strpos( $key, $key_pattern ) === FALSE )
384
+ continue;
385
+
386
+ $short_key = str_replace( $key_pattern, '', $key );
387
+ $return[$short_key] = $value[0];
388
+ }
389
+
390
+ return $return;
391
+ }
392
+
393
+ /**
394
+ * Update the customer's last active time
395
+ *
396
+ * @access private
397
+ * @since 3.8.13
398
+ */
399
+ function _wpsc_action_update_customer_last_active() {
400
+ $id = wpsc_get_current_customer_id();
401
+
402
+ $user = get_user_by( 'id', $id );
403
+ if ( $user->role != 'wpsc_anonymous' )
404
+ return;
405
+
406
+ update_user_meta( $id, '_wpsc_last_active', time() );
407
+
408
+ // also extend cookie expiration
409
+ _wpsc_create_customer_id_cookie( $id );
410
+ }
411
+
412
+
413
+ /**
414
+ * Is the user an automata not worthy of a WPEC profile to hold shopping cart and other info
415
+ *
416
+ * @access public
417
+ * @since 3.8.13
418
+ */
419
+ function _wpsc_is_bot_user() {
420
+ if ( is_user_logged_in() )
421
+ return false;
422
+
423
+ if ( strpos( $_SERVER['REQUEST_URI'], '?wpsc_action=rss' ) )
424
+ return true;
425
+
426
+ // Cron jobs are not flesh originated
427
+ if ( defined('DOING_CRON') && DOING_CRON )
428
+ return true;
429
+
430
+ // XML RPC requests are probably from cybernetic beasts
431
+ if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
432
+ return true;
433
+
434
+ // coming to login first, after the user logs in we know they are a live being, until then they are something else
435
+ if ( strpos( $_SERVER['PHP_SELF'], 'wp-login' ) || strpos( $_SERVER['PHP_SELF'], 'wp-register' ) )
436
+ return true;
437
+
438
+ // even web servers talk to themselves when they think no one is listening
439
+ if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'wordpress' ) !== false )
440
+ return true;
441
+
442
+ // the user agent could be google bot, bing bot or some other bot, one would hope real user agents do not have the
443
+ // string 'bot|spider|crawler|preview' in them, there are bots that don't do us the kindness of identifying themselves as such,
444
+ // check for the user being logged in in a real user is using a bot to access content from our site
445
+ $bot_agents_patterns = apply_filters( 'wpsc_bot_user_agents', array(
446
+ 'robot',
447
+ 'bot',
448
+ 'crawler',
449
+ 'spider',
450
+ 'preview',
451
+ ) );
452
+
453
+ $pattern = '/(' . implode( '|', $bot_agents_patterns ) . ')/i';
454
+
455
+ if ( preg_match( $pattern, $_SERVER['HTTP_USER_AGENT'] ) )
456
+ return true;
457
+
458
+ // Are we feeding the masses?
459
+ if ( is_feed() )
460
+ return true;
461
+
462
+ // at this point we have eliminated all but the most obvious choice, a human (or cylon?)
463
+ return false;
464
+ }
wpsc-includes/display.functions.php CHANGED
@@ -8,404 +8,3 @@
8
  * @package wp-e-commerce
9
  * @since 3.7
10
  */
11
-
12
- /**
13
- * wpsc buy now button code products function
14
- * Sorry about the ugly code, this is just to get the functionality back, buy now will soon be overhauled, and this function will then be completely different
15
- * @return string - html displaying one or more products
16
- */
17
- function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) {
18
-
19
- $product_id = absint($product_id);
20
-
21
- $product = get_post( $product_id );
22
- $supported_gateways = array( 'wpsc_merchant_paypal_standard', 'paypal_multiple' );
23
- $selected_gateways = get_option( 'custom_gateway_options' );
24
-
25
- if ( $replaced_shortcode )
26
- ob_start();
27
-
28
- if ( in_array( 'wpsc_merchant_paypal_standard', (array) $selected_gateways ) ) {
29
- if ( $product_id > 0 ) {
30
-
31
- $post_meta = get_post_meta( $product_id, '_wpsc_product_metadata', true );
32
- $shipping = isset( $post_meta['shipp
8
  * @package wp-e-commerce
9
  * @since 3.7
10
  */