Version Description
- New random product widget. A new sidebar widget allows you add a random product block to the site sidebar. Each time your customer opens or refreshes a page on your site, they will see one of your store products in the sidebar. Enable the new random product widget under AppearanceWidgets section in your Wordpress admin backend. Do not forget to add pictures to your products to bring site visitors attention to your store.
- Minor fixes and improvements.
Download this release
Release Info
Developer | Ecwid |
Plugin | Ecwid Ecommerce Shopping Cart |
Version | 5.5 |
Comparing to | |
See all releases |
Code changes from version 5.4.3 to 5.5
- css/admin.css +3 -1
- css/frontend.css +4 -0
- ecwid-shopping-cart.php +6 -2
- includes/class-ecwid-api.php +10 -0
- includes/class-ecwid-nav-menus.php +5 -1
- includes/class-ecwid-oauth.php +1 -0
- includes/class-ecwid-products.php +1 -1
- includes/class-ecwid-seo-links.php +3 -3
- includes/widgets.php +3 -0
- includes/widgets/class-ecwid-widget-random-product.php +71 -0
- js/nav-menu-frontend.js +30 -3
- js/store-editor-mce.js +4 -0
- js/store-editor-page.js +0 -2
- languages/ecwid-shopping-cart-ru_RU.mo +0 -0
- languages/ecwid-shopping-cart-ru_RU.po +6 -0
- lib/JSON.php +0 -806
- lib/ecwid_api_v3.php +46 -2
- lib/ecwid_catalog.php +1 -1
- lib/ecwid_platform.php +1 -8
- lib/ecwid_product.php +35 -0
- readme.txt +5 -2
- templates/sync.php +2 -14
css/admin.css
CHANGED
@@ -275,7 +275,9 @@ body[class*="_page_ecwid"] .ecwid-message {
|
|
275 |
content: "\e605";
|
276 |
}
|
277 |
|
278 |
-
#available-widgets .widget-top.ecwid-widget-recentlyviewed .widget-title:before
|
|
|
|
|
279 |
content: "\e600";
|
280 |
}
|
281 |
|
275 |
content: "\e605";
|
276 |
}
|
277 |
|
278 |
+
#available-widgets .widget-top.ecwid-widget-recentlyviewed .widget-title:before,
|
279 |
+
#available-widgets .widget-top.ecwid-widget-randomproduct .widget-title:before
|
280 |
+
{
|
281 |
content: "\e600";
|
282 |
}
|
283 |
|
css/frontend.css
CHANGED
@@ -60,3 +60,7 @@ html#ecwid_html body#ecwid_body .ecwid table {
|
|
60 |
font-size: 14px;
|
61 |
font-weight: 400;
|
62 |
}
|
|
|
|
|
|
|
|
60 |
font-size: 14px;
|
61 |
font-weight: 400;
|
62 |
}
|
63 |
+
|
64 |
+
.ecwid-random-product:not(.loaded) {
|
65 |
+
min-height: 290px;
|
66 |
+
}
|
ecwid-shopping-cart.php
CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.ecwid.com?source=wporg
|
|
5 |
Description: Ecwid is a free full-featured shopping cart. It can be easily integrated with any Wordpress blog and takes less than 5 minutes to set up.
|
6 |
Text Domain: ecwid-shopping-cart
|
7 |
Author: Ecwid Team
|
8 |
-
Version: 5.
|
9 |
Author URI: http://www.ecwid.com?source=wporg
|
10 |
*/
|
11 |
|
@@ -1342,6 +1342,10 @@ function ecwid_get_scriptjs_params( $force_lang = null ) {
|
|
1342 |
if ( Ecwid_Products::is_enabled() ) {
|
1343 |
$params .= '&data_sync_products=1';
|
1344 |
}
|
|
|
|
|
|
|
|
|
1345 |
|
1346 |
return $params;
|
1347 |
}
|
@@ -2556,7 +2560,7 @@ function ecwid_is_sso_enabled() {
|
|
2556 |
|
2557 |
$is_sso_enabled = false;
|
2558 |
|
2559 |
-
$is_apiv3_sso = ecwid_is_paid_account() && get_option('ecwid_is_sso_enabled') && $ecwid_oauth->has_scope('create_customers');
|
2560 |
$is_apiv1_sso = ecwid_is_paid_account() && get_option('ecwid_sso_secret_key');
|
2561 |
|
2562 |
$is_sso_enabled = $is_apiv3_sso || $is_apiv1_sso;
|
5 |
Description: Ecwid is a free full-featured shopping cart. It can be easily integrated with any Wordpress blog and takes less than 5 minutes to set up.
|
6 |
Text Domain: ecwid-shopping-cart
|
7 |
Author: Ecwid Team
|
8 |
+
Version: 5.5
|
9 |
Author URI: http://www.ecwid.com?source=wporg
|
10 |
*/
|
11 |
|
1342 |
if ( Ecwid_Products::is_enabled() ) {
|
1343 |
$params .= '&data_sync_products=1';
|
1344 |
}
|
1345 |
+
|
1346 |
+
if (is_active_widget(false, false, 'ecwidrandomproduct')) {
|
1347 |
+
$params .= '&data_rpw=1';
|
1348 |
+
}
|
1349 |
|
1350 |
return $params;
|
1351 |
}
|
2560 |
|
2561 |
$is_sso_enabled = false;
|
2562 |
|
2563 |
+
$is_apiv3_sso = ecwid_is_paid_account() && get_option('ecwid_is_sso_enabled') && $ecwid_oauth && $ecwid_oauth->has_scope('create_customers');
|
2564 |
$is_apiv1_sso = ecwid_is_paid_account() && get_option('ecwid_sso_secret_key');
|
2565 |
|
2566 |
$is_sso_enabled = $is_apiv3_sso || $is_apiv1_sso;
|
includes/class-ecwid-api.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class Ecwid_API {
|
5 |
+
public static function page_contains_product_browser( $page_id = 0 ) {
|
6 |
+
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-store-page.php';
|
7 |
+
|
8 |
+
return Ecwid_Store_Page::is_store_page( $page_id );
|
9 |
+
}
|
10 |
+
}
|
includes/class-ecwid-nav-menus.php
CHANGED
@@ -161,7 +161,11 @@ class Ecwid_Nav_Menus {
|
|
161 |
$counter = 0;
|
162 |
|
163 |
for ( $i = 0; $i < count($items); $i++ ) {
|
164 |
-
|
|
|
|
|
|
|
|
|
165 |
$item = $items[$i];
|
166 |
$items[$i]->menu_order = $i + 1;
|
167 |
|
161 |
$counter = 0;
|
162 |
|
163 |
for ( $i = 0; $i < count($items); $i++ ) {
|
164 |
+
|
165 |
+
if (!isset($items[$i])) {
|
166 |
+
continue;
|
167 |
+
}
|
168 |
+
|
169 |
$item = $items[$i];
|
170 |
$items[$i]->menu_order = $i + 1;
|
171 |
|
includes/class-ecwid-oauth.php
CHANGED
@@ -124,6 +124,7 @@ class Ecwid_OAuth {
|
|
124 |
|
125 |
update_option( 'ecwid_oauth_scope', $result->scope );
|
126 |
update_option( 'ecwid_api_check_time', 0 );
|
|
|
127 |
EcwidPlatform::cache_reset( 'all_categories' );
|
128 |
$this->api->save_token($result->access_token);
|
129 |
|
124 |
|
125 |
update_option( 'ecwid_oauth_scope', $result->scope );
|
126 |
update_option( 'ecwid_api_check_time', 0 );
|
127 |
+
update_option( 'ecwid_public_token', $result->public_token );
|
128 |
EcwidPlatform::cache_reset( 'all_categories' );
|
129 |
$this->api->save_token($result->access_token);
|
130 |
|
includes/class-ecwid-products.php
CHANGED
@@ -379,7 +379,7 @@ class Ecwid_Products {
|
|
379 |
$over = FALSE;
|
380 |
|
381 |
$offset = 0;
|
382 |
-
$limit =
|
383 |
if ($settings && @$settings['offset']) {
|
384 |
$offset = $settings['offset'];
|
385 |
}
|
379 |
$over = FALSE;
|
380 |
|
381 |
$offset = 0;
|
382 |
+
$limit = 20;
|
383 |
if ($settings && @$settings['offset']) {
|
384 |
$offset = $settings['offset'];
|
385 |
}
|
includes/class-ecwid-seo-links.php
CHANGED
@@ -101,8 +101,8 @@ class Ecwid_Seo_Links {
|
|
101 |
|
102 |
protected function get_seo_links_patterns() {
|
103 |
return array(
|
104 |
-
'
|
105 |
-
'
|
106 |
'cart',
|
107 |
'checkout',
|
108 |
'checkout\/shipping',
|
@@ -178,7 +178,7 @@ JS;
|
|
178 |
}
|
179 |
|
180 |
protected static function _get_pb_preg_pattern() {
|
181 |
-
return $pattern = '!.*-(p|c)([0-9]
|
182 |
}
|
183 |
|
184 |
public function build_rewrite_rules( ) {
|
101 |
|
102 |
protected function get_seo_links_patterns() {
|
103 |
return array(
|
104 |
+
'.*-p([0-9]+)(\/.*|\?.*)?',
|
105 |
+
'.*-c([0-9]+)(\/.*|\?.*)?',
|
106 |
'cart',
|
107 |
'checkout',
|
108 |
'checkout\/shipping',
|
178 |
}
|
179 |
|
180 |
protected static function _get_pb_preg_pattern() {
|
181 |
+
return $pattern = '!.*-(p|c)([0-9]+)(\/.*|\?.*)?$!';
|
182 |
}
|
183 |
|
184 |
public function build_rewrite_rules( ) {
|
includes/widgets.php
CHANGED
@@ -8,6 +8,8 @@ include_once "widgets/class-ecwid-widget-search.php";
|
|
8 |
include_once "widgets/class-ecwid-widget-store-link.php";
|
9 |
include_once "widgets/class-ecwid-widget-floating-shopping-cart.php";
|
10 |
include_once "widgets/class-ecwid-widget-vertical-categories-list.php";
|
|
|
|
|
11 |
|
12 |
if (ecwid_migrations_is_original_plugin_version_older_than('4.3')) {
|
13 |
include_once "widgets/class-ecwid-widget-vcategories.php";
|
@@ -33,6 +35,7 @@ function ecwid_sidebar_widgets_init() {
|
|
33 |
register_widget('Ecwid_Widget_Recently_Viewed');
|
34 |
register_widget('Ecwid_Widget_Floating_Shopping_Cart');
|
35 |
register_widget('Ecwid_Widget_Vertical_Categories_List');
|
|
|
36 |
|
37 |
if (ecwid_migrations_is_original_plugin_version_older_than('4.3')) {
|
38 |
register_widget('Ecwid_Widget_VCategories');
|
8 |
include_once "widgets/class-ecwid-widget-store-link.php";
|
9 |
include_once "widgets/class-ecwid-widget-floating-shopping-cart.php";
|
10 |
include_once "widgets/class-ecwid-widget-vertical-categories-list.php";
|
11 |
+
include_once "widgets/class-ecwid-widget-random-product.php";
|
12 |
+
|
13 |
|
14 |
if (ecwid_migrations_is_original_plugin_version_older_than('4.3')) {
|
15 |
include_once "widgets/class-ecwid-widget-vcategories.php";
|
35 |
register_widget('Ecwid_Widget_Recently_Viewed');
|
36 |
register_widget('Ecwid_Widget_Floating_Shopping_Cart');
|
37 |
register_widget('Ecwid_Widget_Vertical_Categories_List');
|
38 |
+
register_widget('Ecwid_Widget_Random_Product');
|
39 |
|
40 |
if (ecwid_migrations_is_original_plugin_version_older_than('4.3')) {
|
41 |
register_widget('Ecwid_Widget_VCategories');
|
includes/widgets/class-ecwid-widget-random-product.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ecwid_Widget_Random_Product extends WP_Widget {
|
3 |
+
|
4 |
+
function __construct() {
|
5 |
+
$widget_ops = array('classname' => 'widget_ecwid_random_product', 'description' => __("Displays a random product from your store to attract customer attention.", 'ecwid-shopping-cart') );
|
6 |
+
parent::__construct('ecwidrandomproduct', __('Random Product', 'ecwid-shopping-cart'), $widget_ops);
|
7 |
+
|
8 |
+
}
|
9 |
+
|
10 |
+
function widget($args, $instance) {
|
11 |
+
extract($args);
|
12 |
+
$title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']);
|
13 |
+
|
14 |
+
$product = Ecwid_Product::get_random_product();
|
15 |
+
|
16 |
+
$name = esc_attr($product->name);
|
17 |
+
|
18 |
+
$url = $product->link;
|
19 |
+
|
20 |
+
$content = <<<HTML
|
21 |
+
<div class="ecwid ecwid-random-product ecwid-SingleProduct-v2 ecwid-SingleProduct-v2-bordered ecwid-SingleProduct-v2-centered ecwid-Product ecwid-Product-$product->id" itemscope itemtype="http://schema.org/Product" data-single-product-id="$product->id">
|
22 |
+
<a href="$url"><div itemprop="image"></div></a>
|
23 |
+
<a href="$url"><div class="ecwid-title" itemprop="name" content="$name"></div></a>
|
24 |
+
<a href="$url"><div itemtype="http://schema.org/Offer" itemscope itemprop="offers">
|
25 |
+
<div class="ecwid-productBrowser-price ecwid-price" itemprop="price" content="$product->price" data-spw-price-location="button">
|
26 |
+
<div itemprop="priceCurrency"></div>
|
27 |
+
</div>
|
28 |
+
</div>
|
29 |
+
</a>
|
30 |
+
</div>
|
31 |
+
<script type="text/javascript">xProduct()</script>
|
32 |
+
HTML;
|
33 |
+
|
34 |
+
|
35 |
+
echo $before_widget;
|
36 |
+
|
37 |
+
if ( $title )
|
38 |
+
echo $before_title . $title . $after_title;
|
39 |
+
|
40 |
+
echo '<div>';
|
41 |
+
|
42 |
+
echo '<!-- noptimize -->';
|
43 |
+
echo ecwid_get_scriptjs_code();
|
44 |
+
echo $content;
|
45 |
+
|
46 |
+
echo '<!-- /noptimize -->';
|
47 |
+
echo '</div>';
|
48 |
+
|
49 |
+
echo $after_widget;
|
50 |
+
}
|
51 |
+
|
52 |
+
function update($new_instance, $old_instance){
|
53 |
+
$instance = $old_instance;
|
54 |
+
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
|
55 |
+
|
56 |
+
return $instance;
|
57 |
+
}
|
58 |
+
|
59 |
+
function form($instance){
|
60 |
+
$instance = wp_parse_args( (array) $instance, array('title'=>'') );
|
61 |
+
|
62 |
+
$title = htmlspecialchars($instance['title']);
|
63 |
+
|
64 |
+
if (!$title) {
|
65 |
+
$title = __('Random Product', 'ecwid-shopping-cart');
|
66 |
+
}
|
67 |
+
|
68 |
+
echo '<p><label for="' . $this->get_field_name('title') . '">' . __('Title:') . ' <input style="width:100%;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>';
|
69 |
+
}
|
70 |
+
|
71 |
+
}
|
js/nav-menu-frontend.js
CHANGED
@@ -18,10 +18,11 @@ jQuery(document).ready(function() {
|
|
18 |
|
19 |
Ecwid.OnPageLoaded.add(refreshEcwidMenuItemsSelection);
|
20 |
|
21 |
-
function refreshEcwidMenuItemsSelection() {
|
|
|
22 |
$allMenus = jQuery('ul').has('li.menu-item');
|
23 |
$allMenus.each(function (idx, el) {
|
24 |
-
var current = findCurrentEcwidMenuItem(el);
|
25 |
if (current) {
|
26 |
highlightCurrentMenuItem(el, current);
|
27 |
}
|
@@ -35,7 +36,33 @@ jQuery(document).ready(function() {
|
|
35 |
item.addClass('current-menu-item current_page_item');
|
36 |
}
|
37 |
|
38 |
-
function findCurrentEcwidMenuItem(menuElement) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
var specificMenuItem = findSpecificMenuItem(menuElement);
|
40 |
if (specificMenuItem) {
|
41 |
return specificMenuItem;
|
18 |
|
19 |
Ecwid.OnPageLoaded.add(refreshEcwidMenuItemsSelection);
|
20 |
|
21 |
+
function refreshEcwidMenuItemsSelection(page) {
|
22 |
+
|
23 |
$allMenus = jQuery('ul').has('li.menu-item');
|
24 |
$allMenus.each(function (idx, el) {
|
25 |
+
var current = findCurrentEcwidMenuItem(el, page);
|
26 |
if (current) {
|
27 |
highlightCurrentMenuItem(el, current);
|
28 |
}
|
36 |
item.addClass('current-menu-item current_page_item');
|
37 |
}
|
38 |
|
39 |
+
function findCurrentEcwidMenuItem(menuElement, page) {
|
40 |
+
|
41 |
+
if (page) {
|
42 |
+
var endswith = null;
|
43 |
+
if (page.type == 'CATEGORY') {
|
44 |
+
if (page.categoryId == 0) {
|
45 |
+
endswith = '';
|
46 |
+
} else {
|
47 |
+
endswith = 'c' + page.categoryId;
|
48 |
+
}
|
49 |
+
}else if (page.type == 'PRODUCT') {
|
50 |
+
endswith = 'p' + page.productId;
|
51 |
+
}
|
52 |
+
|
53 |
+
if (endswith != null) {
|
54 |
+
|
55 |
+
if (endswith == '') {
|
56 |
+
endswith = ec.config.baseUrl;
|
57 |
+
}
|
58 |
+
var selector = '>li a[href*="' + ec.config.baseUrl + '"]';
|
59 |
+
var exactCatalogPage = jQuery('>li a[href$="' + endswith + '"][href*="' + ec.config.baseUrl + '"]', menuElement).closest('li');
|
60 |
+
if (exactCatalogPage.length > 0) {
|
61 |
+
return exactCatalogPage;
|
62 |
+
}
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
var specificMenuItem = findSpecificMenuItem(menuElement);
|
67 |
if (specificMenuItem) {
|
68 |
return specificMenuItem;
|
js/store-editor-mce.js
CHANGED
@@ -179,6 +179,10 @@ tinymce.PluginManager.add( 'ecwid', function( editor ) {
|
|
179 |
}
|
180 |
} else if ( event.target.nodeName !== 'IMG' ) {
|
181 |
removeToolbar();
|
|
|
|
|
|
|
|
|
182 |
}
|
183 |
});
|
184 |
|
179 |
}
|
180 |
} else if ( event.target.nodeName !== 'IMG' ) {
|
181 |
removeToolbar();
|
182 |
+
|
183 |
+
if (event.target.nodeName == 'INPUT' && event.target.id == 'ecwid-edit-store-button') {
|
184 |
+
ecwid_open_store_popup();
|
185 |
+
}
|
186 |
}
|
187 |
});
|
188 |
|
js/store-editor-page.js
CHANGED
@@ -129,8 +129,6 @@ jQuery(document).ready(function() {
|
|
129 |
if (hasEcwid && button.length == 0) {
|
130 |
var button = jQuery('<input type="button" id="ecwid-edit-store-button" contenteditable="false" data-mce-bogus="true" value="' + ecwid_i18n.edit_store_appearance + '" />')
|
131 |
.appendTo(body);
|
132 |
-
|
133 |
-
button.click(ecwid_open_store_popup);
|
134 |
} else if (!hasEcwid && button.length > 0) {
|
135 |
tinymce.activeEditor.dom.remove(button);
|
136 |
}
|
129 |
if (hasEcwid && button.length == 0) {
|
130 |
var button = jQuery('<input type="button" id="ecwid-edit-store-button" contenteditable="false" data-mce-bogus="true" value="' + ecwid_i18n.edit_store_appearance + '" />')
|
131 |
.appendTo(body);
|
|
|
|
|
132 |
} else if (!hasEcwid && button.length > 0) {
|
133 |
tinymce.activeEditor.dom.remove(button);
|
134 |
}
|
languages/ecwid-shopping-cart-ru_RU.mo
CHANGED
Binary file
|
languages/ecwid-shopping-cart-ru_RU.po
CHANGED
@@ -1651,6 +1651,12 @@ msgstr "Последняя синхронизация"
|
|
1651 |
msgid "Not synchronized yet"
|
1652 |
msgstr "Не синхронизовано"
|
1653 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1654 |
#. Plugin Name of the plugin/theme
|
1655 |
msgid "Ecwid Shopping Cart"
|
1656 |
msgstr "Интернет-магазин Эквид"
|
1651 |
msgid "Not synchronized yet"
|
1652 |
msgstr "Не синхронизовано"
|
1653 |
|
1654 |
+
msgid "Random Product"
|
1655 |
+
msgstr "Случайный товар"
|
1656 |
+
|
1657 |
+
msgid "Displays a random product from your store to attract customer attention."
|
1658 |
+
msgstr "Показывает случайный товар из магазина, чтобы привлечь внимание покупателя."
|
1659 |
+
|
1660 |
#. Plugin Name of the plugin/theme
|
1661 |
msgid "Ecwid Shopping Cart"
|
1662 |
msgstr "Интернет-магазин Эквид"
|
lib/JSON.php
DELETED
@@ -1,806 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Converts to and from JSON format.
|
6 |
-
*
|
7 |
-
* JSON (JavaScript Object Notation) is a lightweight data-interchange
|
8 |
-
* format. It is easy for humans to read and write. It is easy for machines
|
9 |
-
* to parse and generate. It is based on a subset of the JavaScript
|
10 |
-
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
|
11 |
-
* This feature can also be found in Python. JSON is a text format that is
|
12 |
-
* completely language independent but uses conventions that are familiar
|
13 |
-
* to programmers of the C-family of languages, including C, C++, C#, Java,
|
14 |
-
* JavaScript, Perl, TCL, and many others. These properties make JSON an
|
15 |
-
* ideal data-interchange language.
|
16 |
-
*
|
17 |
-
* This package provides a simple encoder and decoder for JSON notation. It
|
18 |
-
* is intended for use with client-side Javascript applications that make
|
19 |
-
* use of HTTPRequest to perform server communication functions - data can
|
20 |
-
* be encoded into JSON notation for use in a client-side javascript, or
|
21 |
-
* decoded from incoming Javascript requests. JSON format is native to
|
22 |
-
* Javascript, and can be directly eval()'ed with no further parsing
|
23 |
-
* overhead
|
24 |
-
*
|
25 |
-
* All strings should be in ASCII or UTF-8 format!
|
26 |
-
*
|
27 |
-
* LICENSE: Redistribution and use in source and binary forms, with or
|
28 |
-
* without modification, are permitted provided that the following
|
29 |
-
* conditions are met: Redistributions of source code must retain the
|
30 |
-
* above copyright notice, this list of conditions and the following
|
31 |
-
* disclaimer. Redistributions in binary form must reproduce the above
|
32 |
-
* copyright notice, this list of conditions and the following disclaimer
|
33 |
-
* in the documentation and/or other materials provided with the
|
34 |
-
* distribution.
|
35 |
-
*
|
36 |
-
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
37 |
-
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
38 |
-
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
39 |
-
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
40 |
-
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
41 |
-
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
42 |
-
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
43 |
-
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
44 |
-
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
45 |
-
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
46 |
-
* DAMAGE.
|
47 |
-
*
|
48 |
-
* @category
|
49 |
-
* @package Services_JSON
|
50 |
-
* @author Michal Migurski <mike-json@teczno.com>
|
51 |
-
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
|
52 |
-
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
|
53 |
-
* @copyright 2005 Michal Migurski
|
54 |
-
* @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
|
55 |
-
* @license http://www.opensource.org/licenses/bsd-license.php
|
56 |
-
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
57 |
-
*/
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Marker constant for Services_JSON::decode(), used to flag stack state
|
61 |
-
*/
|
62 |
-
define('SERVICES_JSON_SLICE', 1);
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Marker constant for Services_JSON::decode(), used to flag stack state
|
66 |
-
*/
|
67 |
-
define('SERVICES_JSON_IN_STR', 2);
|
68 |
-
|
69 |
-
/**
|
70 |
-
* Marker constant for Services_JSON::decode(), used to flag stack state
|
71 |
-
*/
|
72 |
-
define('SERVICES_JSON_IN_ARR', 3);
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Marker constant for Services_JSON::decode(), used to flag stack state
|
76 |
-
*/
|
77 |
-
define('SERVICES_JSON_IN_OBJ', 4);
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Marker constant for Services_JSON::decode(), used to flag stack state
|
81 |
-
*/
|
82 |
-
define('SERVICES_JSON_IN_CMT', 5);
|
83 |
-
|
84 |
-
/**
|
85 |
-
* Behavior switch for Services_JSON::decode()
|
86 |
-
*/
|
87 |
-
define('SERVICES_JSON_LOOSE_TYPE', 16);
|
88 |
-
|
89 |
-
/**
|
90 |
-
* Behavior switch for Services_JSON::decode()
|
91 |
-
*/
|
92 |
-
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Converts to and from JSON format.
|
96 |
-
*
|
97 |
-
* Brief example of use:
|
98 |
-
*
|
99 |
-
* <code>
|
100 |
-
* // create a new instance of Services_JSON
|
101 |
-
* $json = new Services_JSON();
|
102 |
-
*
|
103 |
-
* // convert a complexe value to JSON notation, and send it to the browser
|
104 |
-
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
|
105 |
-
* $output = $json->encode($value);
|
106 |
-
*
|
107 |
-
* print($output);
|
108 |
-
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
|
109 |
-
*
|
110 |
-
* // accept incoming POST data, assumed to be in JSON notation
|
111 |
-
* $input = file_get_contents('php://input', 1000000);
|
112 |
-
* $value = $json->decode($input);
|
113 |
-
* </code>
|
114 |
-
*/
|
115 |
-
class Services_JSON
|
116 |
-
{
|
117 |
-
/**
|
118 |
-
* constructs a new JSON instance
|
119 |
-
*
|
120 |
-
* @param int $use object behavior flags; combine with boolean-OR
|
121 |
-
*
|
122 |
-
* possible values:
|
123 |
-
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
|
124 |
-
* "{...}" syntax creates associative arrays
|
125 |
-
* instead of objects in decode().
|
126 |
-
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
|
127 |
-
* Values which can't be encoded (e.g. resources)
|
128 |
-
* appear as NULL instead of throwing errors.
|
129 |
-
* By default, a deeply-nested resource will
|
130 |
-
* bubble up with an error, so all return values
|
131 |
-
* from encode() should be checked with isError()
|
132 |
-
*/
|
133 |
-
function Services_JSON($use = 0)
|
134 |
-
{
|
135 |
-
$this->use = $use;
|
136 |
-
}
|
137 |
-
|
138 |
-
/**
|
139 |
-
* convert a string from one UTF-16 char to one UTF-8 char
|
140 |
-
*
|
141 |
-
* Normally should be handled by mb_convert_encoding, but
|
142 |
-
* provides a slower PHP-only method for installations
|
143 |
-
* that lack the multibye string extension.
|
144 |
-
*
|
145 |
-
* @param string $utf16 UTF-16 character
|
146 |
-
* @return string UTF-8 character
|
147 |
-
* @access private
|
148 |
-
*/
|
149 |
-
function utf162utf8($utf16)
|
150 |
-
{
|
151 |
-
// oh please oh please oh please oh please oh please
|
152 |
-
if(function_exists('mb_convert_encoding')) {
|
153 |
-
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
|
154 |
-
}
|
155 |
-
|
156 |
-
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
|
157 |
-
|
158 |
-
switch(true) {
|
159 |
-
case ((0x7F & $bytes) == $bytes):
|
160 |
-
// this case should never be reached, because we are in ASCII range
|
161 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
162 |
-
return chr(0x7F & $bytes);
|
163 |
-
|
164 |
-
case (0x07FF & $bytes) == $bytes:
|
165 |
-
// return a 2-byte UTF-8 character
|
166 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
167 |
-
return chr(0xC0 | (($bytes >> 6) & 0x1F))
|
168 |
-
. chr(0x80 | ($bytes & 0x3F));
|
169 |
-
|
170 |
-
case (0xFFFF & $bytes) == $bytes:
|
171 |
-
// return a 3-byte UTF-8 character
|
172 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
173 |
-
return chr(0xE0 | (($bytes >> 12) & 0x0F))
|
174 |
-
. chr(0x80 | (($bytes >> 6) & 0x3F))
|
175 |
-
. chr(0x80 | ($bytes & 0x3F));
|
176 |
-
}
|
177 |
-
|
178 |
-
// ignoring UTF-32 for now, sorry
|
179 |
-
return '';
|
180 |
-
}
|
181 |
-
|
182 |
-
/**
|
183 |
-
* convert a string from one UTF-8 char to one UTF-16 char
|
184 |
-
*
|
185 |
-
* Normally should be handled by mb_convert_encoding, but
|
186 |
-
* provides a slower PHP-only method for installations
|
187 |
-
* that lack the multibye string extension.
|
188 |
-
*
|
189 |
-
* @param string $utf8 UTF-8 character
|
190 |
-
* @return string UTF-16 character
|
191 |
-
* @access private
|
192 |
-
*/
|
193 |
-
function utf82utf16($utf8)
|
194 |
-
{
|
195 |
-
// oh please oh please oh please oh please oh please
|
196 |
-
if(function_exists('mb_convert_encoding')) {
|
197 |
-
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
|
198 |
-
}
|
199 |
-
|
200 |
-
switch(strlen($utf8)) {
|
201 |
-
case 1:
|
202 |
-
// this case should never be reached, because we are in ASCII range
|
203 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
204 |
-
return $utf8;
|
205 |
-
|
206 |
-
case 2:
|
207 |
-
// return a UTF-16 character from a 2-byte UTF-8 char
|
208 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
209 |
-
return chr(0x07 & (ord($utf8{0}) >> 2))
|
210 |
-
. chr((0xC0 & (ord($utf8{0}) << 6))
|
211 |
-
| (0x3F & ord($utf8{1})));
|
212 |
-
|
213 |
-
case 3:
|
214 |
-
// return a UTF-16 character from a 3-byte UTF-8 char
|
215 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
216 |
-
return chr((0xF0 & (ord($utf8{0}) << 4))
|
217 |
-
| (0x0F & (ord($utf8{1}) >> 2)))
|
218 |
-
. chr((0xC0 & (ord($utf8{1}) << 6))
|
219 |
-
| (0x7F & ord($utf8{2})));
|
220 |
-
}
|
221 |
-
|
222 |
-
// ignoring UTF-32 for now, sorry
|
223 |
-
return '';
|
224 |
-
}
|
225 |
-
|
226 |
-
/**
|
227 |
-
* encodes an arbitrary variable into JSON format
|
228 |
-
*
|
229 |
-
* @param mixed $var any number, boolean, string, array, or object to be encoded.
|
230 |
-
* see argument 1 to Services_JSON() above for array-parsing behavior.
|
231 |
-
* if var is a strng, note that encode() always expects it
|
232 |
-
* to be in ASCII or UTF-8 format!
|
233 |
-
*
|
234 |
-
* @return mixed JSON string representation of input var or an error if a problem occurs
|
235 |
-
* @access public
|
236 |
-
*/
|
237 |
-
function encode($var)
|
238 |
-
{
|
239 |
-
switch (gettype($var)) {
|
240 |
-
case 'boolean':
|
241 |
-
return $var ? 'true' : 'false';
|
242 |
-
|
243 |
-
case 'NULL':
|
244 |
-
return 'null';
|
245 |
-
|
246 |
-
case 'integer':
|
247 |
-
return (int) $var;
|
248 |
-
|
249 |
-
case 'double':
|
250 |
-
case 'float':
|
251 |
-
return (float) $var;
|
252 |
-
|
253 |
-
case 'string':
|
254 |
-
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
|
255 |
-
$ascii = '';
|
256 |
-
$strlen_var = strlen($var);
|
257 |
-
|
258 |
-
/*
|
259 |
-
* Iterate over every character in the string,
|
260 |
-
* escaping with a slash or encoding to UTF-8 where necessary
|
261 |
-
*/
|
262 |
-
for ($c = 0; $c < $strlen_var; ++$c) {
|
263 |
-
|
264 |
-
$ord_var_c = ord($var{$c});
|
265 |
-
|
266 |
-
switch (true) {
|
267 |
-
case $ord_var_c == 0x08:
|
268 |
-
$ascii .= '\b';
|
269 |
-
break;
|
270 |
-
case $ord_var_c == 0x09:
|
271 |
-
$ascii .= '\t';
|
272 |
-
break;
|
273 |
-
case $ord_var_c == 0x0A:
|
274 |
-
$ascii .= '\n';
|
275 |
-
break;
|
276 |
-
case $ord_var_c == 0x0C:
|
277 |
-
$ascii .= '\f';
|
278 |
-
break;
|
279 |
-
case $ord_var_c == 0x0D:
|
280 |
-
$ascii .= '\r';
|
281 |
-
break;
|
282 |
-
|
283 |
-
case $ord_var_c == 0x22:
|
284 |
-
case $ord_var_c == 0x2F:
|
285 |
-
case $ord_var_c == 0x5C:
|
286 |
-
// double quote, slash, slosh
|
287 |
-
$ascii .= '\\'.$var{$c};
|
288 |
-
break;
|
289 |
-
|
290 |
-
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
|
291 |
-
// characters U-00000000 - U-0000007F (same as ASCII)
|
292 |
-
$ascii .= $var{$c};
|
293 |
-
break;
|
294 |
-
|
295 |
-
case (($ord_var_c & 0xE0) == 0xC0):
|
296 |
-
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
297 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
298 |
-
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
|
299 |
-
$c += 1;
|
300 |
-
$utf16 = $this->utf82utf16($char);
|
301 |
-
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
302 |
-
break;
|
303 |
-
|
304 |
-
case (($ord_var_c & 0xF0) == 0xE0):
|
305 |
-
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
306 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
307 |
-
$char = pack('C*', $ord_var_c,
|
308 |
-
ord($var{$c + 1}),
|
309 |
-
ord($var{$c + 2}));
|
310 |
-
$c += 2;
|
311 |
-
$utf16 = $this->utf82utf16($char);
|
312 |
-
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
313 |
-
break;
|
314 |
-
|
315 |
-
case (($ord_var_c & 0xF8) == 0xF0):
|
316 |
-
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
317 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
318 |
-
$char = pack('C*', $ord_var_c,
|
319 |
-
ord($var{$c + 1}),
|
320 |
-
ord($var{$c + 2}),
|
321 |
-
ord($var{$c + 3}));
|
322 |
-
$c += 3;
|
323 |
-
$utf16 = $this->utf82utf16($char);
|
324 |
-
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
325 |
-
break;
|
326 |
-
|
327 |
-
case (($ord_var_c & 0xFC) == 0xF8):
|
328 |
-
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
329 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
330 |
-
$char = pack('C*', $ord_var_c,
|
331 |
-
ord($var{$c + 1}),
|
332 |
-
ord($var{$c + 2}),
|
333 |
-
ord($var{$c + 3}),
|
334 |
-
ord($var{$c + 4}));
|
335 |
-
$c += 4;
|
336 |
-
$utf16 = $this->utf82utf16($char);
|
337 |
-
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
338 |
-
break;
|
339 |
-
|
340 |
-
case (($ord_var_c & 0xFE) == 0xFC):
|
341 |
-
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
342 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
343 |
-
$char = pack('C*', $ord_var_c,
|
344 |
-
ord($var{$c + 1}),
|
345 |
-
ord($var{$c + 2}),
|
346 |
-
ord($var{$c + 3}),
|
347 |
-
ord($var{$c + 4}),
|
348 |
-
ord($var{$c + 5}));
|
349 |
-
$c += 5;
|
350 |
-
$utf16 = $this->utf82utf16($char);
|
351 |
-
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
352 |
-
break;
|
353 |
-
}
|
354 |
-
}
|
355 |
-
|
356 |
-
return '"'.$ascii.'"';
|
357 |
-
|
358 |
-
case 'array':
|
359 |
-
/*
|
360 |
-
* As per JSON spec if any array key is not an integer
|
361 |
-
* we must treat the the whole array as an object. We
|
362 |
-
* also try to catch a sparsely populated associative
|
363 |
-
* array with numeric keys here because some JS engines
|
364 |
-
* will create an array with empty indexes up to
|
365 |
-
* max_index which can cause memory issues and because
|
366 |
-
* the keys, which may be relevant, will be remapped
|
367 |
-
* otherwise.
|
368 |
-
*
|
369 |
-
* As per the ECMA and JSON specification an object may
|
370 |
-
* have any string as a property. Unfortunately due to
|
371 |
-
* a hole in the ECMA specification if the key is a
|
372 |
-
* ECMA reserved word or starts with a digit the
|
373 |
-
* parameter is only accessible using ECMAScript's
|
374 |
-
* bracket notation.
|
375 |
-
*/
|
376 |
-
|
377 |
-
// treat as a JSON object
|
378 |
-
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
|
379 |
-
$properties = array_map(array($this, 'name_value'),
|
380 |
-
array_keys($var),
|
381 |
-
array_values($var));
|
382 |
-
|
383 |
-
foreach($properties as $property) {
|
384 |
-
if(Services_JSON::isError($property)) {
|
385 |
-
return $property;
|
386 |
-
}
|
387 |
-
}
|
388 |
-
|
389 |
-
return '{' . join(',', $properties) . '}';
|
390 |
-
}
|
391 |
-
|
392 |
-
// treat it like a regular array
|
393 |
-
$elements = array_map(array($this, 'encode'), $var);
|
394 |
-
|
395 |
-
foreach($elements as $element) {
|
396 |
-
if(Services_JSON::isError($element)) {
|
397 |
-
return $element;
|
398 |
-
}
|
399 |
-
}
|
400 |
-
|
401 |
-
return '[' . join(',', $elements) . ']';
|
402 |
-
|
403 |
-
case 'object':
|
404 |
-
$vars = get_object_vars($var);
|
405 |
-
|
406 |
-
$properties = array_map(array($this, 'name_value'),
|
407 |
-
array_keys($vars),
|
408 |
-
array_values($vars));
|
409 |
-
|
410 |
-
foreach($properties as $property) {
|
411 |
-
if(Services_JSON::isError($property)) {
|
412 |
-
return $property;
|
413 |
-
}
|
414 |
-
}
|
415 |
-
|
416 |
-
return '{' . join(',', $properties) . '}';
|
417 |
-
|
418 |
-
default:
|
419 |
-
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
|
420 |
-
? 'null'
|
421 |
-
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
|
422 |
-
}
|
423 |
-
}
|
424 |
-
|
425 |
-
/**
|
426 |
-
* array-walking function for use in generating JSON-formatted name-value pairs
|
427 |
-
*
|
428 |
-
* @param string $name name of key to use
|
429 |
-
* @param mixed $value reference to an array element to be encoded
|
430 |
-
*
|
431 |
-
* @return string JSON-formatted name-value pair, like '"name":value'
|
432 |
-
* @access private
|
433 |
-
*/
|
434 |
-
function name_value($name, $value)
|
435 |
-
{
|
436 |
-
$encoded_value = $this->encode($value);
|
437 |
-
|
438 |
-
if(Services_JSON::isError($encoded_value)) {
|
439 |
-
return $encoded_value;
|
440 |
-
}
|
441 |
-
|
442 |
-
return $this->encode(strval($name)) . ':' . $encoded_value;
|
443 |
-
}
|
444 |
-
|
445 |
-
/**
|
446 |
-
* reduce a string by removing leading and trailing comments and whitespace
|
447 |
-
*
|
448 |
-
* @param $str string string value to strip of comments and whitespace
|
449 |
-
*
|
450 |
-
* @return string string value stripped of comments and whitespace
|
451 |
-
* @access private
|
452 |
-
*/
|
453 |
-
function reduce_string($str)
|
454 |
-
{
|
455 |
-
$str = preg_replace(array(
|
456 |
-
|
457 |
-
// eliminate single line comments in '// ...' form
|
458 |
-
'#^\s*//(.+)$#m',
|
459 |
-
|
460 |
-
// eliminate multi-line comments in '/* ... */' form, at start of string
|
461 |
-
'#^\s*/\*(.+)\*/#Us',
|
462 |
-
|
463 |
-
// eliminate multi-line comments in '/* ... */' form, at end of string
|
464 |
-
'#/\*(.+)\*/\s*$#Us'
|
465 |
-
|
466 |
-
), '', $str);
|
467 |
-
|
468 |
-
// eliminate extraneous space
|
469 |
-
return trim($str);
|
470 |
-
}
|
471 |
-
|
472 |
-
/**
|
473 |
-
* decodes a JSON string into appropriate variable
|
474 |
-
*
|
475 |
-
* @param string $str JSON-formatted string
|
476 |
-
*
|
477 |
-
* @return mixed number, boolean, string, array, or object
|
478 |
-
* corresponding to given JSON input string.
|
479 |
-
* See argument 1 to Services_JSON() above for object-output behavior.
|
480 |
-
* Note that decode() always returns strings
|
481 |
-
* in ASCII or UTF-8 format!
|
482 |
-
* @access public
|
483 |
-
*/
|
484 |
-
function decode($str)
|
485 |
-
{
|
486 |
-
$str = $this->reduce_string($str);
|
487 |
-
|
488 |
-
switch (strtolower($str)) {
|
489 |
-
case 'true':
|
490 |
-
return true;
|
491 |
-
|
492 |
-
case 'false':
|
493 |
-
return false;
|
494 |
-
|
495 |
-
case 'null':
|
496 |
-
return null;
|
497 |
-
|
498 |
-
default:
|
499 |
-
$m = array();
|
500 |
-
|
501 |
-
if (is_numeric($str)) {
|
502 |
-
// Lookie-loo, it's a number
|
503 |
-
|
504 |
-
// This would work on its own, but I'm trying to be
|
505 |
-
// good about returning integers where appropriate:
|
506 |
-
// return (float)$str;
|
507 |
-
|
508 |
-
// Return float or int, as appropriate
|
509 |
-
return ((float)$str == (integer)$str)
|
510 |
-
? (integer)$str
|
511 |
-
: (float)$str;
|
512 |
-
|
513 |
-
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
|
514 |
-
// STRINGS RETURNED IN UTF-8 FORMAT
|
515 |
-
$delim = substr($str, 0, 1);
|
516 |
-
$chrs = substr($str, 1, -1);
|
517 |
-
$utf8 = '';
|
518 |
-
$strlen_chrs = strlen($chrs);
|
519 |
-
|
520 |
-
for ($c = 0; $c < $strlen_chrs; ++$c) {
|
521 |
-
|
522 |
-
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
523 |
-
$ord_chrs_c = ord($chrs{$c});
|
524 |
-
|
525 |
-
switch (true) {
|
526 |
-
case $substr_chrs_c_2 == '\b':
|
527 |
-
$utf8 .= chr(0x08);
|
528 |
-
++$c;
|
529 |
-
break;
|
530 |
-
case $substr_chrs_c_2 == '\t':
|
531 |
-
$utf8 .= chr(0x09);
|
532 |
-
++$c;
|
533 |
-
break;
|
534 |
-
case $substr_chrs_c_2 == '\n':
|
535 |
-
$utf8 .= chr(0x0A);
|
536 |
-
++$c;
|
537 |
-
break;
|
538 |
-
case $substr_chrs_c_2 == '\f':
|
539 |
-
$utf8 .= chr(0x0C);
|
540 |
-
++$c;
|
541 |
-
break;
|
542 |
-
case $substr_chrs_c_2 == '\r':
|
543 |
-
$utf8 .= chr(0x0D);
|
544 |
-
++$c;
|
545 |
-
break;
|
546 |
-
|
547 |
-
case $substr_chrs_c_2 == '\\"':
|
548 |
-
case $substr_chrs_c_2 == '\\\'':
|
549 |
-
case $substr_chrs_c_2 == '\\\\':
|
550 |
-
case $substr_chrs_c_2 == '\\/':
|
551 |
-
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
|
552 |
-
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
|
553 |
-
$utf8 .= $chrs{++$c};
|
554 |
-
}
|
555 |
-
break;
|
556 |
-
|
557 |
-
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
|
558 |
-
// single, escaped unicode character
|
559 |
-
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
|
560 |
-
. chr(hexdec(substr($chrs, ($c + 4), 2)));
|
561 |
-
$utf8 .= $this->utf162utf8($utf16);
|
562 |
-
$c += 5;
|
563 |
-
break;
|
564 |
-
|
565 |
-
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
|
566 |
-
$utf8 .= $chrs{$c};
|
567 |
-
break;
|
568 |
-
|
569 |
-
case ($ord_chrs_c & 0xE0) == 0xC0:
|
570 |
-
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
571 |
-
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
572 |
-
$utf8 .= substr($chrs, $c, 2);
|
573 |
-
++$c;
|
574 |
-
break;
|
575 |
-
|
576 |
-
case ($ord_chrs_c & 0xF0) == 0xE0:
|
577 |
-
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
578 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
579 |
-
$utf8 .= substr($chrs, $c, 3);
|
580 |
-
$c += 2;
|
581 |
-
break;
|
582 |
-
|
583 |
-
case ($ord_chrs_c & 0xF8) == 0xF0:
|
584 |
-
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
585 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
586 |
-
$utf8 .= substr($chrs, $c, 4);
|
587 |
-
$c += 3;
|
588 |
-
break;
|
589 |
-
|
590 |
-
case ($ord_chrs_c & 0xFC) == 0xF8:
|
591 |
-
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
592 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
593 |
-
$utf8 .= substr($chrs, $c, 5);
|
594 |
-
$c += 4;
|
595 |
-
break;
|
596 |
-
|
597 |
-
case ($ord_chrs_c & 0xFE) == 0xFC:
|
598 |
-
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
599 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
600 |
-
$utf8 .= substr($chrs, $c, 6);
|
601 |
-
$c += 5;
|
602 |
-
break;
|
603 |
-
|
604 |
-
}
|
605 |
-
|
606 |
-
}
|
607 |
-
|
608 |
-
return $utf8;
|
609 |
-
|
610 |
-
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
|
611 |
-
// array, or object notation
|
612 |
-
|
613 |
-
if ($str{0} == '[') {
|
614 |
-
$stk = array(SERVICES_JSON_IN_ARR);
|
615 |
-
$arr = array();
|
616 |
-
} else {
|
617 |
-
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
618 |
-
$stk = array(SERVICES_JSON_IN_OBJ);
|
619 |
-
$obj = array();
|
620 |
-
} else {
|
621 |
-
$stk = array(SERVICES_JSON_IN_OBJ);
|
622 |
-
$obj = new stdClass();
|
623 |
-
}
|
624 |
-
}
|
625 |
-
|
626 |
-
array_push($stk, array('what' => SERVICES_JSON_SLICE,
|
627 |
-
'where' => 0,
|
628 |
-
'delim' => false));
|
629 |
-
|
630 |
-
$chrs = substr($str, 1, -1);
|
631 |
-
$chrs = $this->reduce_string($chrs);
|
632 |
-
|
633 |
-
if ($chrs == '') {
|
634 |
-
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
635 |
-
return $arr;
|
636 |
-
|
637 |
-
} else {
|
638 |
-
return $obj;
|
639 |
-
|
640 |
-
}
|
641 |
-
}
|
642 |
-
|
643 |
-
//print("\nparsing {$chrs}\n");
|
644 |
-
|
645 |
-
$strlen_chrs = strlen($chrs);
|
646 |
-
|
647 |
-
for ($c = 0; $c <= $strlen_chrs; ++$c) {
|
648 |
-
|
649 |
-
$top = end($stk);
|
650 |
-
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
651 |
-
|
652 |
-
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
|
653 |
-
// found a comma that is not inside a string, array, etc.,
|
654 |
-
// OR we've reached the end of the character list
|
655 |
-
$slice = substr($chrs, $top['where'], ($c - $top['where']));
|
656 |
-
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
|
657 |
-
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
658 |
-
|
659 |
-
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
660 |
-
// we are in an array, so just push an element onto the stack
|
661 |
-
array_push($arr, $this->decode($slice));
|
662 |
-
|
663 |
-
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
664 |
-
// we are in an object, so figure
|
665 |
-
// out the property name and set an
|
666 |
-
// element in an associative array,
|
667 |
-
// for now
|
668 |
-
$parts = array();
|
669 |
-
|
670 |
-
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
671 |
-
// "name":value pair
|
672 |
-
$key = $this->decode($parts[1]);
|
673 |
-
$val = $this->decode($parts[2]);
|
674 |
-
|
675 |
-
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
676 |
-
$obj[$key] = $val;
|
677 |
-
} else {
|
678 |
-
$obj->$key = $val;
|
679 |
-
}
|
680 |
-
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
681 |
-
// name:value pair, where name is unquoted
|
682 |
-
$key = $parts[1];
|
683 |
-
$val = $this->decode($parts[2]);
|
684 |
-
|
685 |
-
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
686 |
-
$obj[$key] = $val;
|
687 |
-
} else {
|
688 |
-
$obj->$key = $val;
|
689 |
-
}
|
690 |
-
}
|
691 |
-
|
692 |
-
}
|
693 |
-
|
694 |
-
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
|
695 |
-
// found a quote, and we are not inside a string
|
696 |
-
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
|
697 |
-
//print("Found start of string at {$c}\n");
|
698 |
-
|
699 |
-
} elseif (($chrs{$c} == $top['delim']) &&
|
700 |
-
($top['what'] == SERVICES_JSON_IN_STR) &&
|
701 |
-
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
|
702 |
-
// found a quote, we're in a string, and it's not escaped
|
703 |
-
// we know that it's not escaped becase there is _not_ an
|
704 |
-
// odd number of backslashes at the end of the string so far
|
705 |
-
array_pop($stk);
|
706 |
-
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
|
707 |
-
|
708 |
-
} elseif (($chrs{$c} == '[') &&
|
709 |
-
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
710 |
-
// found a left-bracket, and we are in an array, object, or slice
|
711 |
-
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
|
712 |
-
//print("Found start of array at {$c}\n");
|
713 |
-
|
714 |
-
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
|
715 |
-
// found a right-bracket, and we're in an array
|
716 |
-
array_pop($stk);
|
717 |
-
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
718 |
-
|
719 |
-
} elseif (($chrs{$c} == '{') &&
|
720 |
-
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
721 |
-
// found a left-brace, and we are in an array, object, or slice
|
722 |
-
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
|
723 |
-
//print("Found start of object at {$c}\n");
|
724 |
-
|
725 |
-
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
|
726 |
-
// found a right-brace, and we're in an object
|
727 |
-
array_pop($stk);
|
728 |
-
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
729 |
-
|
730 |
-
} elseif (($substr_chrs_c_2 == '/*') &&
|
731 |
-
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
732 |
-
// found a comment start, and we are in an array, object, or slice
|
733 |
-
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
|
734 |
-
$c++;
|
735 |
-
//print("Found start of comment at {$c}\n");
|
736 |
-
|
737 |
-
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
|
738 |
-
// found a comment end, and we're in one now
|
739 |
-
array_pop($stk);
|
740 |
-
$c++;
|
741 |
-
|
742 |
-
for ($i = $top['where']; $i <= $c; ++$i)
|
743 |
-
$chrs = substr_replace($chrs, ' ', $i, 1);
|
744 |
-
|
745 |
-
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
746 |
-
|
747 |
-
}
|
748 |
-
|
749 |
-
}
|
750 |
-
|
751 |
-
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
752 |
-
return $arr;
|
753 |
-
|
754 |
-
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
755 |
-
return $obj;
|
756 |
-
|
757 |
-
}
|
758 |
-
|
759 |
-
}
|
760 |
-
}
|
761 |
-
}
|
762 |
-
|
763 |
-
/**
|
764 |
-
* @todo Ultimately, this should just call PEAR::isError()
|
765 |
-
*/
|
766 |
-
function isError($data, $code = null)
|
767 |
-
{
|
768 |
-
if (class_exists('pear')) {
|
769 |
-
return PEAR::isError($data, $code);
|
770 |
-
} elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
|
771 |
-
is_subclass_of($data, 'services_json_error'))) {
|
772 |
-
return true;
|
773 |
-
}
|
774 |
-
|
775 |
-
return false;
|
776 |
-
}
|
777 |
-
}
|
778 |
-
|
779 |
-
if (class_exists('PEAR_Error')) {
|
780 |
-
|
781 |
-
class Services_JSON_Error extends PEAR_Error
|
782 |
-
{
|
783 |
-
function Services_JSON_Error($message = 'unknown error', $code = null,
|
784 |
-
$mode = null, $options = null, $userinfo = null)
|
785 |
-
{
|
786 |
-
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
|
787 |
-
}
|
788 |
-
}
|
789 |
-
|
790 |
-
} else {
|
791 |
-
|
792 |
-
/**
|
793 |
-
* @todo Ultimately, this class shall be descended from PEAR_Error
|
794 |
-
*/
|
795 |
-
class Services_JSON_Error
|
796 |
-
{
|
797 |
-
function Services_JSON_Error($message = 'unknown error', $code = null,
|
798 |
-
$mode = null, $options = null, $userinfo = null)
|
799 |
-
{
|
800 |
-
|
801 |
-
}
|
802 |
-
}
|
803 |
-
|
804 |
-
}
|
805 |
-
|
806 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/ecwid_api_v3.php
CHANGED
@@ -76,6 +76,7 @@ class Ecwid_Api_V3
|
|
76 |
$result = EcwidPlatform::get_from_categories_cache($url);
|
77 |
if ( !$result ) {
|
78 |
$result = EcwidPlatform::fetch_url( $url );
|
|
|
79 |
}
|
80 |
|
81 |
if ($result['code'] != '200') {
|
@@ -88,6 +89,10 @@ class Ecwid_Api_V3
|
|
88 |
|
89 |
if ( !empty( $result->items ) ) {
|
90 |
foreach ( $result->items as $item ) {
|
|
|
|
|
|
|
|
|
91 |
Ecwid_Category::from_stdclass( $item );
|
92 |
}
|
93 |
}
|
@@ -184,12 +189,19 @@ class Ecwid_Api_V3
|
|
184 |
$params['cleanUrls'] = 'true';
|
185 |
}
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
$url = $this->build_request_url(
|
188 |
$this->_products_api_url,
|
189 |
$params
|
190 |
);
|
191 |
-
|
192 |
$result = EcwidPlatform::get_from_products_cache( $url );
|
|
|
193 |
if (!$result ) {
|
194 |
$result = EcwidPlatform::fetch_url( $url );
|
195 |
if ($result['code'] != '200') {
|
@@ -210,6 +222,8 @@ class Ecwid_Api_V3
|
|
210 |
}
|
211 |
}
|
212 |
|
|
|
|
|
213 |
return $result;
|
214 |
}
|
215 |
|
@@ -263,7 +277,7 @@ class Ecwid_Api_V3
|
|
263 |
)
|
264 |
);
|
265 |
|
266 |
-
if ($
|
267 |
return false;
|
268 |
}
|
269 |
$result = json_decode($result['data']);
|
@@ -373,6 +387,10 @@ class Ecwid_Api_V3
|
|
373 |
$profile = json_decode($result['data']);
|
374 |
|
375 |
EcwidPlatform::cache_set( self::PROFILE_CACHE_NAME, $profile, 60 * 5 );
|
|
|
|
|
|
|
|
|
376 |
|
377 |
return self::$profile;
|
378 |
}
|
@@ -478,4 +496,30 @@ class Ecwid_Api_V3
|
|
478 |
|
479 |
return $url . '?' . build_query($params);
|
480 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
}
|
76 |
$result = EcwidPlatform::get_from_categories_cache($url);
|
77 |
if ( !$result ) {
|
78 |
$result = EcwidPlatform::fetch_url( $url );
|
79 |
+
|
80 |
}
|
81 |
|
82 |
if ($result['code'] != '200') {
|
89 |
|
90 |
if ( !empty( $result->items ) ) {
|
91 |
foreach ( $result->items as $item ) {
|
92 |
+
if (Ecwid_Seo_Links::is_enabled()) {
|
93 |
+
$item->seo_link = $item->url;
|
94 |
+
}
|
95 |
+
|
96 |
Ecwid_Category::from_stdclass( $item );
|
97 |
}
|
98 |
}
|
189 |
$params['cleanUrls'] = 'true';
|
190 |
}
|
191 |
|
192 |
+
$params['enabled'] = 'true';
|
193 |
+
|
194 |
+
if (EcwidPlatform::get('hide_out_of_stock')) {
|
195 |
+
$params['inStock'] = 'true';
|
196 |
+
}
|
197 |
+
|
198 |
$url = $this->build_request_url(
|
199 |
$this->_products_api_url,
|
200 |
$params
|
201 |
);
|
202 |
+
|
203 |
$result = EcwidPlatform::get_from_products_cache( $url );
|
204 |
+
|
205 |
if (!$result ) {
|
206 |
$result = EcwidPlatform::fetch_url( $url );
|
207 |
if ($result['code'] != '200') {
|
222 |
}
|
223 |
}
|
224 |
|
225 |
+
$this->_maybe_remember_all_products($params, $result, $url);
|
226 |
+
|
227 |
return $result;
|
228 |
}
|
229 |
|
277 |
)
|
278 |
);
|
279 |
|
280 |
+
if ($result['code'] != '200') {
|
281 |
return false;
|
282 |
}
|
283 |
$result = json_decode($result['data']);
|
387 |
$profile = json_decode($result['data']);
|
388 |
|
389 |
EcwidPlatform::cache_set( self::PROFILE_CACHE_NAME, $profile, 60 * 5 );
|
390 |
+
|
391 |
+
if ($profile && isset($profile->settings) && isset($profile->settings->hideOutOfStockProductsInStorefront)) {
|
392 |
+
EcwidPlatform::set('hide_out_of_stock', $profile->settings->hideOutOfStockProductsInStorefront);
|
393 |
+
}
|
394 |
|
395 |
return self::$profile;
|
396 |
}
|
496 |
|
497 |
return $url . '?' . build_query($params);
|
498 |
}
|
499 |
+
|
500 |
+
protected function _maybe_remember_all_products($params, $result, $url)
|
501 |
+
{
|
502 |
+
$limiting_params = array(
|
503 |
+
'updatedFrom', 'keyword', 'category', 'productId'
|
504 |
+
);
|
505 |
+
|
506 |
+
$all = true;
|
507 |
+
foreach ($limiting_params as $param) {
|
508 |
+
if (array_key_exists($param, $params)) {
|
509 |
+
$all = false;
|
510 |
+
break;
|
511 |
+
}
|
512 |
+
}
|
513 |
+
|
514 |
+
if ($all) {
|
515 |
+
|
516 |
+
EcwidPlatform::store_in_products_cache('ecwid_total_products', $result->total);
|
517 |
+
|
518 |
+
if ($result->total < 100 && $result->count == $result->total) {
|
519 |
+
EcwidPlatform::store_in_products_cache('ecwid_all_products_request', $url);
|
520 |
+
} else {
|
521 |
+
EcwidPlatform::store_in_products_cache('ecwid_all_products_request', '');
|
522 |
+
}
|
523 |
+
}
|
524 |
+
}
|
525 |
}
|
lib/ecwid_catalog.php
CHANGED
@@ -126,7 +126,7 @@ class EcwidCatalog
|
|
126 |
}
|
127 |
|
128 |
$batch_result = $this->_get_apiv1_batch_result( $params );
|
129 |
-
if ( !isset($batch_result->main_category) ) {
|
130 |
$batch_result->main_category = null;
|
131 |
}
|
132 |
|
126 |
}
|
127 |
|
128 |
$batch_result = $this->_get_apiv1_batch_result( $params );
|
129 |
+
if ( $batch_result && !isset($batch_result->main_category) ) {
|
130 |
$batch_result->main_category = null;
|
131 |
}
|
132 |
|
lib/ecwid_platform.php
CHANGED
@@ -259,14 +259,7 @@ class EcwidPlatform {
|
|
259 |
|
260 |
return $transports;
|
261 |
}
|
262 |
-
|
263 |
-
static public function is_set_time_limit_available() {
|
264 |
-
return function_exists('set_time_limit' )
|
265 |
-
&& strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) == false
|
266 |
-
&& ! ini_get( 'safe_mode' );
|
267 |
-
}
|
268 |
-
|
269 |
-
|
270 |
static public function store_in_products_cache( $url, $data ) {
|
271 |
|
272 |
self::_store_in_cache($url, 'products', $data);
|
259 |
|
260 |
return $transports;
|
261 |
}
|
262 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
static public function store_in_products_cache( $url, $data ) {
|
264 |
|
265 |
self::_store_in_cache($url, 'products', $data);
|
lib/ecwid_product.php
CHANGED
@@ -52,6 +52,41 @@ class Ecwid_Product extends Ecwid_Catalog_Entry
|
|
52 |
return $p;
|
53 |
}
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
public static function get_without_loading($id, $fallback_object = null)
|
56 |
{
|
57 |
$p = new Ecwid_Product();
|
52 |
return $p;
|
53 |
}
|
54 |
|
55 |
+
public static function get_random_product()
|
56 |
+
{
|
57 |
+
$total = EcwidPlatform::get_from_products_cache('ecwid_total_products');
|
58 |
+
|
59 |
+
$all_products = false;
|
60 |
+
|
61 |
+
if ($total < 100 && $total > 0 && EcwidPlatform::get_from_products_cache('ecwid_all_products_request')) {
|
62 |
+
$all_products = EcwidPlatform::get_from_products_cache(
|
63 |
+
EcwidPlatform::get_from_products_cache('ecwid_all_products_request')
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
if ( $all_products ) {
|
68 |
+
$index = rand( 0, $total - 1 );
|
69 |
+
|
70 |
+
$result = json_decode($all_products['data']);
|
71 |
+
|
72 |
+
$random_product_id = $result->items[$index]->id;
|
73 |
+
} else {
|
74 |
+
$index = rand( 0, $total );
|
75 |
+
$offset = floor($index / 100) * 100;
|
76 |
+
|
77 |
+
$api = new Ecwid_Api_V3();
|
78 |
+
$result = $api->search_products(
|
79 |
+
array(
|
80 |
+
'offset' => $offset
|
81 |
+
)
|
82 |
+
);
|
83 |
+
|
84 |
+
$random_product_id = $result->items[$index - $offset]->id;
|
85 |
+
}
|
86 |
+
|
87 |
+
return Ecwid_Product::get_by_id( $random_product_id );
|
88 |
+
}
|
89 |
+
|
90 |
public static function get_without_loading($id, $fallback_object = null)
|
91 |
{
|
92 |
$p = new Ecwid_Product();
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: Ecwid
|
|
3 |
Tags: ecommerce, downloadable products, Facebook ecommerce, online store, paypal, product catalog, shop, shopping cart, store
|
4 |
Requires at least: 3.5
|
5 |
Tested up to: 4.8
|
6 |
-
Stable tag: 5.
|
7 |
|
8 |
Powerful, easy to use ecommerce shopping cart. Bank level PCI DSS Level 1 security. iPhone & Android apps. Superb support. Free plan available.
|
9 |
|
@@ -149,6 +149,10 @@ You can use Ecwid’s built-in import tools to copy your store products from any
|
|
149 |
* [Ecwid eCommerce Forums](https://www.ecwid.com/forums/forumdisplay.php?f=19)
|
150 |
|
151 |
== Changelog ==
|
|
|
|
|
|
|
|
|
152 |
= 5.4.3 =
|
153 |
- **Speed optimization for the plugin settings pages.** We improved the plugin admin settings code to make sure it requires less time and resources and thus works faster.
|
154 |
- **Fixed a bug in the integration with the Google XML Sitemaps plugin.** The sitemaps generated by that plugin might contain invalid data related to the store product pages. That was caused by a bug in the Ecwid plugin. We fixed that, your sitemap should work fine now.
|
@@ -162,7 +166,6 @@ You can use Ecwid’s built-in import tools to copy your store products from any
|
|
162 |
- **Fixed “Strict standards” code notices.** Some users may discover this notice on their site, if the debugging messages are not disabled in the Wordpress installation. That didn’t affect the store functionality, but looked odd. We fixed that — there should not be any warning messages displayed now.
|
163 |
- Minor fixes and improvements.
|
164 |
|
165 |
-
|
166 |
= 5.4.1 =
|
167 |
- Fixed an issue with the store page loading in the newest version 5.4. In some rare occasions, the store page might not display right after update to the version 5.4. We fixed the issue to make sure all stores are working well.
|
168 |
- Added a workaround for a conflict with the third party “Product Advisor for Ecwid” plugin. The “Product Advisor” plugin has a bug that prevents it from working correctly with the newest versions of the Ecwid plugin. When the Product advisor plugin is enabled, the site pages do not respond. We added a workaround to the Ecwid plugin to make sure the WP admin pages will work well for the “Product advisor”. So, if you’re using the “Product advisor” plugin and see any issue with your site now, please disable that plugin in your WP admin backend. We’re speaking with the author of the Product advisor plugin so there will hopefully be a solution soon.
|
3 |
Tags: ecommerce, downloadable products, Facebook ecommerce, online store, paypal, product catalog, shop, shopping cart, store
|
4 |
Requires at least: 3.5
|
5 |
Tested up to: 4.8
|
6 |
+
Stable tag: 5.5
|
7 |
|
8 |
Powerful, easy to use ecommerce shopping cart. Bank level PCI DSS Level 1 security. iPhone & Android apps. Superb support. Free plan available.
|
9 |
|
149 |
* [Ecwid eCommerce Forums](https://www.ecwid.com/forums/forumdisplay.php?f=19)
|
150 |
|
151 |
== Changelog ==
|
152 |
+
= 5.5 =
|
153 |
+
- **New random product widget.** A new sidebar widget allows you add a random product block to the site sidebar. Each time your customer opens or refreshes a page on your site, they will see one of your store products in the sidebar. Enable the new random product widget under Appearance→Widgets section in your Wordpress admin backend. Do not forget to add pictures to your products to bring site visitors’ attention to your store.
|
154 |
+
- Minor fixes and improvements.
|
155 |
+
|
156 |
= 5.4.3 =
|
157 |
- **Speed optimization for the plugin settings pages.** We improved the plugin admin settings code to make sure it requires less time and resources and thus works faster.
|
158 |
- **Fixed a bug in the integration with the Google XML Sitemaps plugin.** The sitemaps generated by that plugin might contain invalid data related to the store product pages. That was caused by a bug in the Ecwid plugin. We fixed that, your sitemap should work fine now.
|
166 |
- **Fixed “Strict standards” code notices.** Some users may discover this notice on their site, if the debugging messages are not disabled in the Wordpress installation. That didn’t affect the store functionality, but looked odd. We fixed that — there should not be any warning messages displayed now.
|
167 |
- Minor fixes and improvements.
|
168 |
|
|
|
169 |
= 5.4.1 =
|
170 |
- Fixed an issue with the store page loading in the newest version 5.4. In some rare occasions, the store page might not display right after update to the version 5.4. We fixed the issue to make sure all stores are working well.
|
171 |
- Added a workaround for a conflict with the third party “Product Advisor for Ecwid” plugin. The “Product Advisor” plugin has a bug that prevents it from working correctly with the newest versions of the Ecwid plugin. When the Product advisor plugin is enabled, the site pages do not respond. We added a workaround to the Ecwid plugin to make sure the WP admin pages will work well for the “Product advisor”. So, if you’re using the “Product advisor” plugin and see any issue with your site now, please disable that plugin in your WP admin backend. We’re speaking with the author of the Product advisor plugin so there will hopefully be a solution soon.
|
templates/sync.php
CHANGED
@@ -7,18 +7,7 @@ $api = new Ecwid_Api_V3(get_ecwid_store_id());
|
|
7 |
<script>
|
8 |
jQuery(document).ready(function() {
|
9 |
|
10 |
-
|
11 |
-
var set_time_limit_available = <?php echo EcwidPlatform::is_set_time_limit_available() ? 'true' : 'false'; ?>;
|
12 |
-
if (set_time_limit_available && typeof(EventSource) != 'undefined') {
|
13 |
-
sse_available = true;
|
14 |
-
}
|
15 |
-
|
16 |
-
if (sse_available && <?php echo ( get_option( Ecwid_Products::OPTION_NO_SSE ) ? '0' : '1') ?>) {
|
17 |
-
jQuery('#sse_on').html('YES');
|
18 |
-
} else {
|
19 |
-
jQuery('#sse_on').html('NO');
|
20 |
-
jQuery('#sync-container').addClass('no-sse');
|
21 |
-
}
|
22 |
|
23 |
jQuery('#ecwid_local_base_enabled').click(function() {
|
24 |
jQuery('#sync-container').css('display', (jQuery(this).is(':checked')) ? '' : 'none');
|
@@ -77,7 +66,7 @@ function do_no_sse_sync(mode, offset, limit, time) {
|
|
77 |
}
|
78 |
|
79 |
function process_no_sse_sync(data) {
|
80 |
-
var mode = 'deleted', offset = 0, limit =
|
81 |
|
82 |
var processed_updates = data.updated + data.created + data.deleted_disabled;
|
83 |
var processed_deletes = data.deleted + data.skipped_deleted;
|
@@ -164,7 +153,6 @@ jQuery('#sync-button-slow').click(function() {
|
|
164 |
<?php else: ?>
|
165 |
|
166 |
<div class="sync-block" id="sync-buttons">
|
167 |
-
<a id="sync-button"><?php _e('Synchronize products', 'ecwid-shopping-cart'); ?></a>
|
168 |
<a id="sync-button-slow"><?php _e('Synchronize products', 'ecwid-shopping-cart'); ?></a>
|
169 |
</div>
|
170 |
<div class="sync-block" id="updating">
|
7 |
<script>
|
8 |
jQuery(document).ready(function() {
|
9 |
|
10 |
+
jQuery('#sync-container').addClass('no-sse');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
jQuery('#ecwid_local_base_enabled').click(function() {
|
13 |
jQuery('#sync-container').css('display', (jQuery(this).is(':checked')) ? '' : 'none');
|
66 |
}
|
67 |
|
68 |
function process_no_sse_sync(data) {
|
69 |
+
var mode = 'deleted', offset = 0, limit = 20;
|
70 |
|
71 |
var processed_updates = data.updated + data.created + data.deleted_disabled;
|
72 |
var processed_deletes = data.deleted + data.skipped_deleted;
|
153 |
<?php else: ?>
|
154 |
|
155 |
<div class="sync-block" id="sync-buttons">
|
|
|
156 |
<a id="sync-button-slow"><?php _e('Synchronize products', 'ecwid-shopping-cart'); ?></a>
|
157 |
</div>
|
158 |
<div class="sync-block" id="updating">
|