Version Description
- [+] The "Inline SEO catalog" option was added.
Download this release
Release Info
Developer | Ecwid |
Plugin | Ecwid Ecommerce Shopping Cart |
Version | 0.6 |
Comparing to | |
See all releases |
Code changes from version 0.4 to 0.6
- ecwid-shopping-cart.php +205 -64
- lib/JSON.php +806 -0
- lib/ecwid_catalog.php +239 -0
- lib/ecwid_product_api.php +168 -0
- readme.txt +29 -19
ecwid-shopping-cart.php
CHANGED
@@ -2,41 +2,44 @@
|
|
2 |
/*
|
3 |
Plugin Name: Ecwid Shopping Cart
|
4 |
Plugin URI: http://www.ecwid.com/
|
5 |
-
Description: Ecwid is free full-
|
6 |
Author: Ecwid Team
|
7 |
-
Version: 0.
|
8 |
Author URI: http://www.ecwid.com/
|
9 |
*/
|
10 |
|
11 |
register_activation_hook( __FILE__, 'ecwid_store_activate' );
|
12 |
register_deactivation_hook( __FILE__, 'ecwid_store_deactivate' );
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
add_action('
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
add_shortcode('
|
23 |
-
add_shortcode('
|
24 |
-
add_shortcode('
|
25 |
-
|
|
|
|
|
26 |
|
27 |
|
28 |
|
29 |
function ecwid_script_shortcode() {
|
30 |
$ecwid_protocol = get_ecwid_protocol();
|
31 |
$store_id = get_ecwid_store_id();
|
32 |
-
$s = "<div><script type=\"text/javascript\" src=\"$ecwid_protocol://
|
33 |
return $s;
|
34 |
}
|
35 |
|
36 |
|
37 |
function ecwid_minicart_shortcode() {
|
38 |
$ecwid_enable_minicart = get_option('ecwid_enable_minicart');
|
39 |
-
|
|
|
40 |
$s = <<<EOT
|
41 |
<div><script type="text/javascript"> xMinicart("style=","layout=attachToCategories"); </script></div>
|
42 |
EOT;
|
@@ -81,6 +84,11 @@ function ecwid_productbrowser_shortcode() {
|
|
81 |
$ecwid_pb_defaultview = get_option('ecwid_pb_defaultview');
|
82 |
$ecwid_pb_searchview = get_option('ecwid_pb_searchview');
|
83 |
|
|
|
|
|
|
|
|
|
|
|
84 |
if (empty($ecwid_pb_categoriesperrow)) {
|
85 |
$ecwid_pb_categoriesperrow = 3;
|
86 |
}
|
@@ -104,9 +112,35 @@ function ecwid_productbrowser_shortcode() {
|
|
104 |
$ecwid_pb_searchview = 'list';
|
105 |
}
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
$s = <<<EOT
|
108 |
-
<div> <script type="text/javascript"> xProductBrowser("categoriesPerRow=$ecwid_pb_categoriesperrow","views=grid($ecwid_pb_productspercolumn_grid,$ecwid_pb_productsperrow_grid) list($ecwid_pb_productsperpage_list) table($ecwid_pb_productsperpage_table)","categoryView=$ecwid_pb_defaultview","searchView=$ecwid_pb_searchview","style=");</script></div>
|
109 |
-
|
|
|
110 |
EOT;
|
111 |
return $s;
|
112 |
}
|
@@ -121,17 +155,13 @@ function ecwid_store_activate() {
|
|
121 |
<!-- Ecwid code end -->
|
122 |
|
123 |
EOT;
|
124 |
-
|
125 |
-
|
126 |
|
127 |
add_option("ecwid_enable_minicart", 'Y', '', 'yes');
|
128 |
add_option("ecwid_show_categories", 'Y', '', 'yes');
|
129 |
add_option("ecwid_show_search_box", '', '', 'yes');
|
130 |
|
131 |
-
/* old */
|
132 |
-
#add_option("ecwid_pb_itemsperrow", '3', '', 'yes');
|
133 |
-
#add_option("ecwid_pb_itemsperpage", '6', '', 'yes');
|
134 |
-
#add_option("ecwid_pb_searchresultsitemsperpage", '10', '', 'yes');
|
135 |
|
136 |
add_option("ecwid_pb_categoriesperrow", '3', '', 'yes');
|
137 |
|
@@ -143,7 +173,12 @@ EOT;
|
|
143 |
add_option("ecwid_pb_defaultview", 'grid', '', 'yes');
|
144 |
add_option("ecwid_pb_searchview", 'list', '', 'yes');
|
145 |
|
146 |
-
add_option("ecwid_enable_ssl", '', '', 'yes');
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
$id = get_option("ecwid_store_page_id");
|
149 |
$_tmp_page = null;
|
@@ -167,12 +202,15 @@ EOT;
|
|
167 |
}
|
168 |
|
169 |
}
|
170 |
-
function
|
171 |
-
|
172 |
-
|
|
|
|
|
173 |
$ecwid_page_id = get_option("ecwid_store_page_id");
|
174 |
$page_url = get_page_link($ecwid_page_id);
|
175 |
echo "<div id='' class='updated fade'><p><strong>Ecwid shopping cart is almost ready</strong>. Please visit <a href=\"$page_url\">the created page</a> to see your store with demo products. In order to finish the installation, please go to the <a href=\"options-general.php?page=ecwid_options_page\"><strong>Ecwid settings</strong></a> and configure the plugin.</p></div>";
|
|
|
176 |
}
|
177 |
|
178 |
function ecwid_store_deactivate() {
|
@@ -211,6 +249,12 @@ function ecwid_settings_api_init() {
|
|
211 |
register_setting('ecwid_options_page', 'ecwid_pb_defaultview');
|
212 |
register_setting('ecwid_options_page', 'ecwid_pb_searchview');
|
213 |
register_setting('ecwid_options_page', 'ecwid_enable_ssl');
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
}
|
215 |
|
216 |
function ecwid_options_add_page() {
|
@@ -231,9 +275,60 @@ function ecwid_options_do_page() {
|
|
231 |
$ecwid_pb_defaultview = get_option('ecwid_pb_defaultview');
|
232 |
$ecwid_pb_searchview = get_option('ecwid_pb_searchview');
|
233 |
|
|
|
|
|
|
|
234 |
$ecwid_enable_ssl = get_option('ecwid_enable_ssl');
|
235 |
-
|
236 |
$ecwid_page_id = get_option("ecwid_store_page_id");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
$_tmp_page = null;
|
238 |
$disabled = false;
|
239 |
if (!empty($ecwid_page_id) and ($ecwid_page_id > 0)) {
|
@@ -251,57 +346,68 @@ function ecwid_options_do_page() {
|
|
251 |
|
252 |
?>
|
253 |
<div class="wrap">
|
|
|
|
|
|
|
254 |
<h2>Ecwid settings</h2>
|
255 |
<form method="post" action="options.php">
|
256 |
<?php settings_fields('ecwid_options_page'); ?>
|
257 |
<table class="form-table">
|
|
|
258 |
<tr><th scope="row"><a href="http://kb.ecwid.com/Instruction-on-how-to-get-your-free-Store-ID-(for-WordPress)" target="_blank">Store ID</a>:</th>
|
259 |
<td><input type="text" name="ecwid_store_id" value="<?php if ($store_id != 1003) echo $store_id; ?>" /></td>
|
260 |
</tr>
|
261 |
-
|
262 |
-
|
263 |
-
<
|
264 |
-
Enable minicart attached to categories?</th>
|
265 |
-
<td><input type="checkbox" name="ecwid_enable_minicart" <?php if (!empty($ecwid_enable_minicart)) echo "checked=\"checked\"";?> <? echo $disabled_str; ?> />
|
266 |
-
<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt=""> If you added minicart to your blog's sidebar, please disable this option.
|
267 |
-
|
268 |
</td>
|
269 |
</tr>
|
270 |
<tr><th scope="row">
|
271 |
-
Show
|
272 |
-
|
273 |
</td>
|
274 |
</tr>
|
275 |
-
|
276 |
<tr><th scope="row">
|
277 |
-
|
278 |
-
<td><input type="checkbox" name="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
</td>
|
280 |
</tr>
|
281 |
|
282 |
-
|
283 |
-
<td><input type="text" name="ecwid_pb_categoriesperrow" value="<?php echo $ecwid_pb_categoriesperrow; ?>" <?php echo $disabled_str;?> /></td>
|
284 |
-
</tr>
|
285 |
|
286 |
-
<tr><th scope="row">
|
287 |
-
<td><input type="text" name="
|
288 |
-
</tr>
|
289 |
|
290 |
-
<
|
|
|
|
|
|
|
|
|
|
|
291 |
</tr>
|
292 |
|
293 |
-
<tr><th scope="row">Products per page in list mode</th>
|
294 |
-
<td><input type="text" name="ecwid_pb_productsperpage_list" value="<?php echo $ecwid_pb_productsperpage_list; ?>" <?php echo $disabled_str;?> /></td>
|
295 |
</tr>
|
296 |
|
297 |
-
<tr><th scope="row">Products per page in table mode</th>
|
298 |
-
<td><input type="text" name="ecwid_pb_productsperpage_table" value="<?php echo $ecwid_pb_productsperpage_table; ?>" <?php echo $disabled_str;?> /></td>
|
299 |
</tr>
|
300 |
|
301 |
|
302 |
-
<tr><th scope="row">Default view mode on product pages</th>
|
303 |
<td>
|
304 |
-
<select name="ecwid_pb_defaultview" <?php echo $disabled_str;?> >
|
305 |
<option value="grid" <?php if($ecwid_pb_defaultview == 'grid') echo 'selected="selected"' ?> >Grid mode</option>
|
306 |
<option value="list" <?php if($ecwid_pb_defaultview == 'list') echo 'selected="selected"' ?> >List mode</option>
|
307 |
<option value="table" <?php if($ecwid_pb_defaultview == 'table') echo 'selected="selected"' ?> >Table mode</option>
|
@@ -309,24 +415,52 @@ Enable minicart attached to categories?</th>
|
|
309 |
</td>
|
310 |
</tr>
|
311 |
|
312 |
-
<tr><th scope="row">Default view mode on search results</th>
|
313 |
<td>
|
314 |
-
<select name="ecwid_pb_searchview" <?php echo $disabled_str;?> >
|
315 |
<option value="grid" <?php if($ecwid_pb_searchview == 'grid') echo 'selected="selected"' ?> >Grid mode</option>
|
316 |
<option value="list" <?php if($ecwid_pb_searchview == 'list') echo 'selected="selected"' ?> >List mode</option>
|
317 |
<option value="table" <?php if($ecwid_pb_searchview == 'table') echo 'selected="selected"' ?> >Table mode</option>
|
318 |
</select>
|
319 |
</td>
|
320 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
|
322 |
-
<tr><th scope="row">
|
323 |
-
Enable the following option, if you use Ecwid on a secure HTTPS page
|
324 |
</th>
|
325 |
-
<td><input type="checkbox" name="ecwid_enable_ssl" <?php if (!empty($ecwid_enable_ssl)) echo "checked=\"checked\"";?> />
|
326 |
<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt=""> <a href="http://kb.ecwid.com/SSL-HTTPS" target="_blank">Information about Ecwid and SSL/HTTPS</a>
|
327 |
|
328 |
-
</td>
|
329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
|
331 |
</table>
|
332 |
<p class="submit">
|
@@ -396,6 +530,10 @@ with these ones:
|
|
396 |
|
397 |
}
|
398 |
|
|
|
|
|
|
|
|
|
399 |
?>
|
400 |
<div id="ecwid-instruction" >
|
401 |
<h4>Instruction on how to get your free Store ID</h4>
|
@@ -413,6 +551,9 @@ with these ones:
|
|
413 |
</ul>
|
414 |
<p>If you have any questions, feel free to ask them on <a href="http://www.ecwid.com/forums/">Ecwid forums</a> or <a href="http://www.ecwid.com/contact-us.html">contact Ecwid team</a>.</p>
|
415 |
</div>
|
|
|
|
|
|
|
416 |
</form>
|
417 |
|
418 |
|
@@ -472,7 +613,7 @@ class EcwidMinicartWidget extends WP_Widget {
|
|
472 |
|
473 |
$store_id = get_ecwid_store_id();
|
474 |
$ecwid_protocol = get_ecwid_protocol();
|
475 |
-
echo "<div><script type=\"text/javascript\" src=\"$ecwid_protocol://
|
476 |
|
477 |
|
478 |
$ecwid_page_id = get_option("ecwid_store_page_id");
|
@@ -523,7 +664,7 @@ class EcwidSearchWidget extends WP_Widget {
|
|
523 |
|
524 |
$store_id = get_ecwid_store_id();
|
525 |
$ecwid_protocol = get_ecwid_protocol();
|
526 |
-
echo "<div><script type=\"text/javascript\" src=\"$ecwid_protocol://
|
527 |
$ecwid_page_id = get_option("ecwid_store_page_id");
|
528 |
$page_url = get_page_link($ecwid_page_id);
|
529 |
$_tmp_page = get_page($ecwid_page_id);
|
@@ -572,7 +713,7 @@ class EcwidVCategoriesWidget extends WP_Widget {
|
|
572 |
|
573 |
$store_id = get_ecwid_store_id();
|
574 |
$ecwid_protocol = get_ecwid_protocol();
|
575 |
-
echo "<div><script type=\"text/javascript\" src=\"$ecwid_protocol://
|
576 |
$ecwid_page_id = get_option("ecwid_store_page_id");
|
577 |
$page_url = get_page_link($ecwid_page_id);
|
578 |
$_tmp_page = get_page($ecwid_page_id);
|
2 |
/*
|
3 |
Plugin Name: Ecwid Shopping Cart
|
4 |
Plugin URI: http://www.ecwid.com/
|
5 |
+
Description: Ecwid is a free full-featured shopping cart. It can be easily integreted with any Wordpress blog and takes less than 5 minutes to set up.
|
6 |
Author: Ecwid Team
|
7 |
+
Version: 0.6
|
8 |
Author URI: http://www.ecwid.com/
|
9 |
*/
|
10 |
|
11 |
register_activation_hook( __FILE__, 'ecwid_store_activate' );
|
12 |
register_deactivation_hook( __FILE__, 'ecwid_store_deactivate' );
|
13 |
|
14 |
+
define("APP_ECWID_COM","app.ecwid.com");
|
15 |
+
|
16 |
+
if ( is_admin() ){
|
17 |
+
add_action('admin_init', 'ecwid_settings_api_init');
|
18 |
+
add_action('admin_notices', 'ecwid_show_admin_message');
|
19 |
+
add_action('admin_menu', 'ecwid_options_add_page');
|
20 |
+
add_action('wp_dashboard_setup', 'ecwid_add_dashboard_widgets' );
|
21 |
+
} else {
|
22 |
+
add_shortcode('ecwid_script', 'ecwid_script_shortcode');
|
23 |
+
add_shortcode('ecwid_minicart', 'ecwid_minicart_shortcode');
|
24 |
+
add_shortcode('ecwid_searchbox', 'ecwid_searchbox_shortcode');
|
25 |
+
add_shortcode('ecwid_categories', 'ecwid_categories_shortcode');
|
26 |
+
add_shortcode('ecwid_productbrowser', 'ecwid_productbrowser_shortcode');
|
27 |
+
}
|
28 |
|
29 |
|
30 |
|
31 |
function ecwid_script_shortcode() {
|
32 |
$ecwid_protocol = get_ecwid_protocol();
|
33 |
$store_id = get_ecwid_store_id();
|
34 |
+
$s = "<div><script type=\"text/javascript\" src=\"$ecwid_protocol://" . APP_ECWID_COM . "/script.js?$store_id\"></script></div>";
|
35 |
return $s;
|
36 |
}
|
37 |
|
38 |
|
39 |
function ecwid_minicart_shortcode() {
|
40 |
$ecwid_enable_minicart = get_option('ecwid_enable_minicart');
|
41 |
+
$ecwid_show_categories = get_option('ecwid_show_categories');
|
42 |
+
if (!empty($ecwid_enable_minicart) && !empty($ecwid_show_categories)) {
|
43 |
$s = <<<EOT
|
44 |
<div><script type="text/javascript"> xMinicart("style=","layout=attachToCategories"); </script></div>
|
45 |
EOT;
|
84 |
$ecwid_pb_defaultview = get_option('ecwid_pb_defaultview');
|
85 |
$ecwid_pb_searchview = get_option('ecwid_pb_searchview');
|
86 |
|
87 |
+
$ecwid_mobile_catalog_link = get_option('ecwid_mobile_catalog_link');
|
88 |
+
$ecwid_default_category_id = get_option('ecwid_default_category_id');
|
89 |
+
|
90 |
+
$ecwid_noscript_seo_catalog = get_option('ecwid_noscript_seo_catalog');
|
91 |
+
|
92 |
if (empty($ecwid_pb_categoriesperrow)) {
|
93 |
$ecwid_pb_categoriesperrow = 3;
|
94 |
}
|
112 |
$ecwid_pb_searchview = 'list';
|
113 |
}
|
114 |
|
115 |
+
if (empty($ecwid_mobile_catalog_link)) {
|
116 |
+
$ecwid_mobile_catalog_link = "http://" . APP_ECWID_COM . "/jsp/{$store_id}/catalog";
|
117 |
+
}
|
118 |
+
|
119 |
+
if (empty($ecwid_default_category_id)) {
|
120 |
+
$ecwid_default_category_str = '';
|
121 |
+
} else {
|
122 |
+
$ecwid_default_category_str = ',"defaultCategoryId='. $ecwid_default_category_id .'"';
|
123 |
+
}
|
124 |
+
|
125 |
+
|
126 |
+
$ecwid_open_product = '';
|
127 |
+
if (!empty($ecwid_noscript_seo_catalog)) {
|
128 |
+
|
129 |
+
if (!empty($_GET['ecwid_product_id'])) {
|
130 |
+
$ecwid_open_product = '<script>document.location.hash = "ecwid:category=0&mode=product&product='. intval($_GET['ecwid_product_id']) .'";</script>';
|
131 |
+
} elseif (!empty($_GET['ecwid_category_id'])) {
|
132 |
+
$ecwid_default_category_str = ',"defaultCategoryId='. intval($_GET['ecwid_category_id']) .'"';
|
133 |
+
}
|
134 |
+
include_once(ABSPATH . 'wp-content/plugins/ecwid-shopping-cart/lib/ecwid_catalog.php');
|
135 |
+
$noscript_str = '<noscript>'. show_ecwid_catalog($store_id) . '</noscript>';
|
136 |
+
} else {
|
137 |
+
$noscript_str = "<noscript>Your browser does not support JavaScript.<a href=\"{$ecwid_mobile_catalog_link}\">HTML version of this store</a></noscript>";
|
138 |
+
}
|
139 |
+
|
140 |
$s = <<<EOT
|
141 |
+
<div> <script type="text/javascript"> xProductBrowser("categoriesPerRow=$ecwid_pb_categoriesperrow","views=grid($ecwid_pb_productspercolumn_grid,$ecwid_pb_productsperrow_grid) list($ecwid_pb_productsperpage_list) table($ecwid_pb_productsperpage_table)","categoryView=$ecwid_pb_defaultview","searchView=$ecwid_pb_searchview","style="$ecwid_default_category_str);</script></div>
|
142 |
+
{$noscript_str}
|
143 |
+
$ecwid_open_product
|
144 |
EOT;
|
145 |
return $s;
|
146 |
}
|
155 |
<!-- Ecwid code end -->
|
156 |
|
157 |
EOT;
|
158 |
+
add_option("ecwid_store_page_id", '', '', 'yes');
|
159 |
+
add_option("ecwid_store_id", '1003', '', 'yes');
|
160 |
|
161 |
add_option("ecwid_enable_minicart", 'Y', '', 'yes');
|
162 |
add_option("ecwid_show_categories", 'Y', '', 'yes');
|
163 |
add_option("ecwid_show_search_box", '', '', 'yes');
|
164 |
|
|
|
|
|
|
|
|
|
165 |
|
166 |
add_option("ecwid_pb_categoriesperrow", '3', '', 'yes');
|
167 |
|
173 |
add_option("ecwid_pb_defaultview", 'grid', '', 'yes');
|
174 |
add_option("ecwid_pb_searchview", 'list', '', 'yes');
|
175 |
|
176 |
+
add_option("ecwid_enable_ssl", '', '', 'yes');
|
177 |
+
|
178 |
+
add_option("ecwid_mobile_catalog_link", '', '', 'yes');
|
179 |
+
add_option("ecwid_default_category_id", '', '', 'yes');
|
180 |
+
|
181 |
+
add_option("ecwid_noscript_seo_catalog", '', '', 'yes');
|
182 |
|
183 |
$id = get_option("ecwid_store_page_id");
|
184 |
$_tmp_page = null;
|
202 |
}
|
203 |
|
204 |
}
|
205 |
+
function ecwid_show_admin_message() {
|
206 |
+
|
207 |
+
if (get_ecwid_store_id() != 1003) {
|
208 |
+
return;
|
209 |
+
} else {
|
210 |
$ecwid_page_id = get_option("ecwid_store_page_id");
|
211 |
$page_url = get_page_link($ecwid_page_id);
|
212 |
echo "<div id='' class='updated fade'><p><strong>Ecwid shopping cart is almost ready</strong>. Please visit <a href=\"$page_url\">the created page</a> to see your store with demo products. In order to finish the installation, please go to the <a href=\"options-general.php?page=ecwid_options_page\"><strong>Ecwid settings</strong></a> and configure the plugin.</p></div>";
|
213 |
+
}
|
214 |
}
|
215 |
|
216 |
function ecwid_store_deactivate() {
|
249 |
register_setting('ecwid_options_page', 'ecwid_pb_defaultview');
|
250 |
register_setting('ecwid_options_page', 'ecwid_pb_searchview');
|
251 |
register_setting('ecwid_options_page', 'ecwid_enable_ssl');
|
252 |
+
|
253 |
+
register_setting('ecwid_options_page', 'ecwid_mobile_catalog_link');
|
254 |
+
register_setting('ecwid_options_page', 'ecwid_default_category_id');
|
255 |
+
|
256 |
+
register_setting('ecwid_options_page', 'ecwid_noscript_seo_catalog');
|
257 |
+
|
258 |
}
|
259 |
|
260 |
function ecwid_options_add_page() {
|
275 |
$ecwid_pb_defaultview = get_option('ecwid_pb_defaultview');
|
276 |
$ecwid_pb_searchview = get_option('ecwid_pb_searchview');
|
277 |
|
278 |
+
$ecwid_mobile_catalog_link = get_option('ecwid_mobile_catalog_link');
|
279 |
+
$ecwid_default_category_id = get_option('ecwid_default_category_id');
|
280 |
+
$ecwid_noscript_seo_catalog = get_option('ecwid_noscript_seo_catalog');
|
281 |
$ecwid_enable_ssl = get_option('ecwid_enable_ssl');
|
|
|
282 |
$ecwid_page_id = get_option("ecwid_store_page_id");
|
283 |
+
|
284 |
+
$ecwid_noscript_seo_catalog_disabled = false;
|
285 |
+
$ecwid_noscript_seo_catalog_message = '<a href="http://kb.ecwid.com/Inline-SEO-Catalog" target="_blank">How it works</a>';
|
286 |
+
$ecwid_settings_message = false;
|
287 |
+
|
288 |
+
if ($store_id == 1003) {
|
289 |
+
$ecwid_noscript_seo_catalog_disabled = true;
|
290 |
+
$ecwid_noscript_seo_catalog_message = 'This option requires using Ecwid Product API. In order to enable it, please set up your Store ID first. Please note, that API is available for the paid Ecwid accounts only.';
|
291 |
+
if (!empty($ecwid_noscript_seo_catalog)) {
|
292 |
+
update_option('ecwid_noscript_seo_catalog', '');
|
293 |
+
$ecwid_noscript_seo_catalog = '';
|
294 |
+
}
|
295 |
+
} # demo store id
|
296 |
+
|
297 |
+
else if ($store_id != 1003 && empty($ecwid_noscript_seo_catalog)) {
|
298 |
+
$ecwid_noscript_seo_catalog_message = '<a href="http://kb.ecwid.com/Inline-SEO-Catalog" target="_blank">How Inline Seo Catalog works</a>. This option requires using Ecwid API which is available for the paid accounts only.';
|
299 |
+
}
|
300 |
+
else if ($store_id != 1003 && !empty($ecwid_noscript_seo_catalog)) {
|
301 |
+
|
302 |
+
include_once(ABSPATH . 'wp-content/plugins/ecwid-shopping-cart/lib/ecwid_product_api.php');
|
303 |
+
$api = new EcwidProductApi($store_id);
|
304 |
+
if (!empty($api)) {
|
305 |
+
$store_profile = $api->get_profile();
|
306 |
+
|
307 |
+
if ($api->error_code == 403) {
|
308 |
+
#free account, consider upgrade
|
309 |
+
$ecwid_noscript_seo_catalog_disabled = true;
|
310 |
+
$ecwid_noscript_seo_catalog_message = 'This option requires using Ecwid API which is available for the paid accounts only. Please consider upgrading your account to use it.';
|
311 |
+
update_option('ecwid_noscript_seo_catalog', '');
|
312 |
+
$ecwid_noscript_seo_catalog = '';
|
313 |
+
$ecwid_settings_message = 'The "Inline HTML catalog" option requires using Ecwid API which is available for the paid accounts only. Please consider upgrading your account to use it.';
|
314 |
+
|
315 |
+
}
|
316 |
+
else if ($api->error_code == 404) {
|
317 |
+
$ecwid_noscript_seo_catalog_message = 'We cannot connect to Ecwid servers using your Store ID. Is it correct?';
|
318 |
+
$ecwid_settings_message = 'We cannot connect to Ecwid servers using your Store ID. Is it correct?';
|
319 |
+
|
320 |
+
}
|
321 |
+
|
322 |
+
else if($api->error_code != '') {
|
323 |
+
$ecwid_noscript_seo_catalog_message = 'Connection to Ecwid servers failed. Error code: '. $api->error_code;
|
324 |
+
$ecwid_settings_message = 'Connection to Ecwid servers failed. Error code: '. $api->error_code;
|
325 |
+
}
|
326 |
+
} # no $api
|
327 |
+
else {
|
328 |
+
$ecwid_settings_message = 'We cannot include some essential files of Ecwid Shopping Cart module. It looks like it\'s corrupted. Try to re-install the module and contact Ecwid Team if it doesn\'t help.';
|
329 |
+
}
|
330 |
+
}
|
331 |
+
|
332 |
$_tmp_page = null;
|
333 |
$disabled = false;
|
334 |
if (!empty($ecwid_page_id) and ($ecwid_page_id > 0)) {
|
346 |
|
347 |
?>
|
348 |
<div class="wrap">
|
349 |
+
<?php if ($ecwid_settings_message)
|
350 |
+
echo "<div id='' class='updated fade'><p><strong>Error.</strong> $ecwid_settings_message</p></div>";
|
351 |
+
?>
|
352 |
<h2>Ecwid settings</h2>
|
353 |
<form method="post" action="options.php">
|
354 |
<?php settings_fields('ecwid_options_page'); ?>
|
355 |
<table class="form-table">
|
356 |
+
<tr><th colspan="2" style="padding:0px;margin:0px;"><h3 style="padding:0px;margin:0px;">General</h3></th></tr>
|
357 |
<tr><th scope="row"><a href="http://kb.ecwid.com/Instruction-on-how-to-get-your-free-Store-ID-(for-WordPress)" target="_blank">Store ID</a>:</th>
|
358 |
<td><input type="text" name="ecwid_store_id" value="<?php if ($store_id != 1003) echo $store_id; ?>" /></td>
|
359 |
</tr>
|
360 |
+
<tr><th scope="row">
|
361 |
+
<label for="ecwid_show_categories">Show horizontal categories?</label> </th>
|
362 |
+
<td><input type="checkbox" id="ecwid_show_categories" name="ecwid_show_categories" <?php if (!empty($ecwid_show_categories)) echo "checked=\"checked\""; echo $disabled_str; ?> />
|
|
|
|
|
|
|
|
|
363 |
</td>
|
364 |
</tr>
|
365 |
<tr><th scope="row">
|
366 |
+
<label for="ecwid_show_search_box">Show search box?</label> </th>
|
367 |
+
<td><input type="checkbox" id="ecwid_show_search_box" name="ecwid_show_search_box" <?php if (!empty($ecwid_show_search_box)) echo "checked=\"checked\"";?> <?php echo $disabled_str;?> />
|
368 |
</td>
|
369 |
</tr>
|
370 |
+
|
371 |
<tr><th scope="row">
|
372 |
+
<label for="ecwid_enable_minicart">Enable minicart attached to horizontal categories?</label></th>
|
373 |
+
<td><input type="checkbox" name="ecwid_enable_minicart" id="ecwid_enable_minicart" <?php if (!empty($ecwid_enable_minicart) && !empty($ecwid_show_categories)) echo "checked=\"checked\"";?>
|
374 |
+
<?php if (empty($ecwid_show_categories)) {
|
375 |
+
echo 'disabled = "disabled"';
|
376 |
+
}
|
377 |
+
else {
|
378 |
+
echo $disabled_str;
|
379 |
+
} ?> />
|
380 |
+
<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt=""> If you added minicart to your blog's sidebar, please disable this option.
|
381 |
+
|
382 |
</td>
|
383 |
</tr>
|
384 |
|
385 |
+
<tr><th colspan="2" style="padding:0px;margin:0px;"><h3 style="padding:0px;margin:0px;">Appearance</h3></th></tr>
|
|
|
|
|
386 |
|
387 |
+
<tr><th scope="row"><label for="ecwid_pb_categoriesperrow">Categories per row</label></th>
|
388 |
+
<td><input type="text" id="ecwid_pb_categoriesperrow" name="ecwid_pb_categoriesperrow" value="<?php echo $ecwid_pb_categoriesperrow; ?>" <?php echo $disabled_str;?> /></td>
|
389 |
+
</tr>
|
390 |
|
391 |
+
<tr><th scope="row"><label for="ecwid_pb_productspercolumn_grid">Products per column in grid mode</th>
|
392 |
+
<td><input type="text" id="ecwid_pb_productspercolumn_grid" name="ecwid_pb_productspercolumn_grid" value="<?php echo $ecwid_pb_productspercolumn_grid; ?>" <?php echo $disabled_str;?> /></td>
|
393 |
+
</tr>
|
394 |
+
|
395 |
+
<tr><th scope="row"><label for="ecwid_pb_productsperrow_grid">Products per row in grid mode</label></th>
|
396 |
+
<td><input type="text" id="ecwid_pb_productsperrow_grid" name="ecwid_pb_productsperrow_grid" value="<?php echo $ecwid_pb_productsperrow_grid; ?>" <?php echo $disabled_str;?> /></td>
|
397 |
</tr>
|
398 |
|
399 |
+
<tr><th scope="row"><label for="ecwid_pb_productsperpage_list">Products per page in list mode</label></th>
|
400 |
+
<td><input type="text" id="ecwid_pb_productsperpage_list" name="ecwid_pb_productsperpage_list" value="<?php echo $ecwid_pb_productsperpage_list; ?>" <?php echo $disabled_str;?> /></td>
|
401 |
</tr>
|
402 |
|
403 |
+
<tr><th scope="row"><label for="ecwid_pb_productsperpage_table">Products per page in table mode</label></th>
|
404 |
+
<td><input type="text" id="ecwid_pb_productsperpage_table" name="ecwid_pb_productsperpage_table" value="<?php echo $ecwid_pb_productsperpage_table; ?>" <?php echo $disabled_str;?> /></td>
|
405 |
</tr>
|
406 |
|
407 |
|
408 |
+
<tr><th scope="row"><label for="ecwid_pb_defaultview">Default view mode on product pages</label></th>
|
409 |
<td>
|
410 |
+
<select id="ecwid_pb_defaultview" name="ecwid_pb_defaultview" <?php echo $disabled_str;?> >
|
411 |
<option value="grid" <?php if($ecwid_pb_defaultview == 'grid') echo 'selected="selected"' ?> >Grid mode</option>
|
412 |
<option value="list" <?php if($ecwid_pb_defaultview == 'list') echo 'selected="selected"' ?> >List mode</option>
|
413 |
<option value="table" <?php if($ecwid_pb_defaultview == 'table') echo 'selected="selected"' ?> >Table mode</option>
|
415 |
</td>
|
416 |
</tr>
|
417 |
|
418 |
+
<tr><th scope="row"><label for="ecwid_pb_searchview">Default view mode on search results</label></th>
|
419 |
<td>
|
420 |
+
<select id="ecwid_pb_searchview" name="ecwid_pb_searchview" <?php echo $disabled_str;?> >
|
421 |
<option value="grid" <?php if($ecwid_pb_searchview == 'grid') echo 'selected="selected"' ?> >Grid mode</option>
|
422 |
<option value="list" <?php if($ecwid_pb_searchview == 'list') echo 'selected="selected"' ?> >List mode</option>
|
423 |
<option value="table" <?php if($ecwid_pb_searchview == 'table') echo 'selected="selected"' ?> >Table mode</option>
|
424 |
</select>
|
425 |
</td>
|
426 |
</tr>
|
427 |
+
|
428 |
+
<tr><th colspan="2" style="padding:0px;margin:0px;"><h3 style="padding:0px;margin:0px;">SEO</h3></th></tr>
|
429 |
+
|
430 |
+
<tr><th scope="row"><label for="ecwid_noscript_seo_catalog">
|
431 |
+
Enable the inline plain-HTML catalog(better SEO)</label>
|
432 |
+
</th>
|
433 |
+
<td><input id="ecwid_noscript_seo_catalog" type="checkbox" name="ecwid_noscript_seo_catalog" <?php if (!empty($ecwid_noscript_seo_catalog)) echo "checked=\"checked\""; if(!empty($ecwid_noscript_seo_catalog_disabled)) echo "disabled=\"disabled\""; ?> />
|
434 |
+
<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt=""> <?php echo $ecwid_noscript_seo_catalog_message; ?>
|
435 |
+
|
436 |
+
</td> </tr>
|
437 |
+
<tr><th scope="row"><label for="ecwid_mobile_catalog_link">
|
438 |
+
Full link to your mobile catalog</label>
|
439 |
+
</th>
|
440 |
+
<td><input id="ecwid_mobile_catalog_link" type="text" name="ecwid_mobile_catalog_link" value="<?php echo $ecwid_mobile_catalog_link; ?>" />
|
441 |
+
<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt=""> For example <em>http://mdemo.ecwid.com</em>. <a href="http://kb.ecwid.com/Mobile-Catalog" target="_blank">Information about Ecwid and mobile catalogs.</a>
|
442 |
+
|
443 |
+
</td> </tr>
|
444 |
+
|
445 |
+
<tr><th colspan="2" style="padding:0px;margin:0px;"><h3 style="padding:0px;margin:0px;">Advanced</h3></th></tr>
|
446 |
|
447 |
+
<tr><th scope="row"><label for="ecwid_enable_ssl">
|
448 |
+
Enable the following option, if you use Ecwid on a secure HTTPS page</label>
|
449 |
</th>
|
450 |
+
<td><input id="ecwid_enable_ssl" type="checkbox" name="ecwid_enable_ssl" <?php if (!empty($ecwid_enable_ssl)) echo "checked=\"checked\"";?> />
|
451 |
<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt=""> <a href="http://kb.ecwid.com/SSL-HTTPS" target="_blank">Information about Ecwid and SSL/HTTPS</a>
|
452 |
|
453 |
+
</td> </tr>
|
454 |
+
|
455 |
+
|
456 |
+
<tr><th scope="row"><label for="ecwid_default_category_id">
|
457 |
+
Default category ID</label>
|
458 |
+
</th>
|
459 |
+
<td><input id="ecwid_default_category_id" type="text" name="ecwid_default_category_id" value="<?php echo $ecwid_default_category_id; ?>"/>
|
460 |
+
<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt=""> <a href="http://kb.ecwid.com/Default-category-for-product-browser" target="_blank">What is it?</a>
|
461 |
+
|
462 |
+
</td> </tr>
|
463 |
+
|
464 |
|
465 |
</table>
|
466 |
<p class="submit">
|
530 |
|
531 |
}
|
532 |
|
533 |
+
?>
|
534 |
+
|
535 |
+
<?php
|
536 |
+
if ($store_id == '1003') {
|
537 |
?>
|
538 |
<div id="ecwid-instruction" >
|
539 |
<h4>Instruction on how to get your free Store ID</h4>
|
551 |
</ul>
|
552 |
<p>If you have any questions, feel free to ask them on <a href="http://www.ecwid.com/forums/">Ecwid forums</a> or <a href="http://www.ecwid.com/contact-us.html">contact Ecwid team</a>.</p>
|
553 |
</div>
|
554 |
+
<?php
|
555 |
+
}
|
556 |
+
?>
|
557 |
</form>
|
558 |
|
559 |
|
613 |
|
614 |
$store_id = get_ecwid_store_id();
|
615 |
$ecwid_protocol = get_ecwid_protocol();
|
616 |
+
echo "<div><script type=\"text/javascript\" src=\"$ecwid_protocol://" . APP_ECWID_COM . "/script.js?$store_id\"></script>";
|
617 |
|
618 |
|
619 |
$ecwid_page_id = get_option("ecwid_store_page_id");
|
664 |
|
665 |
$store_id = get_ecwid_store_id();
|
666 |
$ecwid_protocol = get_ecwid_protocol();
|
667 |
+
echo "<div><script type=\"text/javascript\" src=\"$ecwid_protocol://" . APP_ECWID_COM . "/script.js?$store_id\"></script>";
|
668 |
$ecwid_page_id = get_option("ecwid_store_page_id");
|
669 |
$page_url = get_page_link($ecwid_page_id);
|
670 |
$_tmp_page = get_page($ecwid_page_id);
|
713 |
|
714 |
$store_id = get_ecwid_store_id();
|
715 |
$ecwid_protocol = get_ecwid_protocol();
|
716 |
+
echo "<div><script type=\"text/javascript\" src=\"$ecwid_protocol://" . APP_ECWID_COM . "/script.js?$store_id\"></script>";
|
717 |
$ecwid_page_id = get_option("ecwid_store_page_id");
|
718 |
$page_url = get_page_link($ecwid_page_id);
|
719 |
$_tmp_page = get_page($ecwid_page_id);
|
lib/JSON.php
ADDED
@@ -0,0 +1,806 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_catalog.php
ADDED
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function show_ecwid($params) {
|
4 |
+
$store_id = $params['store_id'];
|
5 |
+
if (empty($store_id)) {
|
6 |
+
$store_id = '1003'; //demo mode
|
7 |
+
}
|
8 |
+
|
9 |
+
$list_of_views = $params['list_of_views'];
|
10 |
+
|
11 |
+
foreach ($list_of_views as $k=>$v) {
|
12 |
+
if (!in_array($v, array('list','grid','table'))) unset($list_of_views[$k]);
|
13 |
+
}
|
14 |
+
|
15 |
+
if ((!is_array($list_of_views)) || empty($list_of_views)) {
|
16 |
+
$list_of_views = array('list','grid','table');
|
17 |
+
}
|
18 |
+
|
19 |
+
$ecwid_pb_categoriesperrow = $params['ecwid_pb_categoriesperrow'];
|
20 |
+
if (empty($ecwid_pb_categoriesperrow)) {
|
21 |
+
$ecwid_pb_categoriesperrow = 3;
|
22 |
+
}
|
23 |
+
$ecwid_pb_productspercolumn_grid = $params['ecwid_pb_productspercolumn_grid'];
|
24 |
+
if (empty($ecwid_pb_productspercolumn_grid)) {
|
25 |
+
$ecwid_pb_productspercolumn_grid = 3;
|
26 |
+
}
|
27 |
+
$ecwid_pb_productsperrow_grid = $params['ecwid_pb_productsperrow_grid'];
|
28 |
+
if (empty($ecwid_pb_productsperrow_grid)) {
|
29 |
+
$ecwid_pb_productsperrow_grid = 3;
|
30 |
+
}
|
31 |
+
$ecwid_pb_productsperpage_list = $params['ecwid_pb_productsperpage_list'];
|
32 |
+
if (empty($ecwid_pb_productsperpage_list)) {
|
33 |
+
$ecwid_pb_productsperpage_list = 10;
|
34 |
+
}
|
35 |
+
$ecwid_pb_productsperpage_table = $params['ecwid_pb_productsperpage_table'];
|
36 |
+
if (empty($ecwid_pb_productsperpage_table)) {
|
37 |
+
$ecwid_pb_productsperpage_table = 20;
|
38 |
+
}
|
39 |
+
$ecwid_pb_defaultview = $params['ecwid_pb_defaultview'];
|
40 |
+
if (empty($ecwid_pb_defaultview) || !in_array($ecwid_pb_defaultview, $list_of_views)) {
|
41 |
+
$ecwid_pb_defaultview = 'grid';
|
42 |
+
}
|
43 |
+
$ecwid_pb_searchview = $params['ecwid_pb_searchview'];
|
44 |
+
if (empty($ecwid_pb_searchview) || !in_array($ecwid_pb_searchview, $list_of_views)) {
|
45 |
+
$ecwid_pb_searchview = 'list';
|
46 |
+
}
|
47 |
+
$ecwid_enable_html_mode = $params['ecwid_enable_html_mode'];
|
48 |
+
if (empty($ecwid_enable_html_mode)) {
|
49 |
+
$ecwid_enable_html_mode = false;
|
50 |
+
}
|
51 |
+
|
52 |
+
$ecwid_com = "app.ecwid.com";
|
53 |
+
|
54 |
+
|
55 |
+
$ecwid_default_category_id = $params['ecwid_default_category_id'];
|
56 |
+
|
57 |
+
$ecwid_show_seo_catalog = $params['ecwid_show_seo_catalog'];
|
58 |
+
if (empty($ecwid_show_seo_catalog)) {
|
59 |
+
$ecwid_show_seo_catalog = false;
|
60 |
+
}
|
61 |
+
|
62 |
+
$ecwid_mobile_catalog_link = $params['ecwid_mobile_catalog_link'];
|
63 |
+
if (empty($ecwid_mobile_catalog_link)) {
|
64 |
+
$ecwid_mobile_catalog_link = "http://$ecwid_com/jsp/$store_id/catalog";
|
65 |
+
}
|
66 |
+
|
67 |
+
$html_catalog = '';
|
68 |
+
if ($ecwid_show_seo_catalog) {
|
69 |
+
if (!empty($_GET['ecwid_product_id'])) {
|
70 |
+
$ecwid_open_product = '<script> if (!document.location.hash) document.location.hash = "ecwid:category=0&mode=product&product='. intval($_GET['ecwid_product_id']) .'";</script>';
|
71 |
+
} elseif (!empty($_GET['ecwid_category_id'])) {
|
72 |
+
$ecwid_default_category_id = intval($_GET['ecwid_category_id']);
|
73 |
+
}
|
74 |
+
$html_catalog = show_ecwid_catalog($store_id);
|
75 |
+
}
|
76 |
+
|
77 |
+
if (empty($html_catalog)) {
|
78 |
+
$html_catalog = "Your browser does not support JavaScript.<a href=\"{$ecwid_mobile_catalog_link}\">HTML version of this store</a>";
|
79 |
+
}
|
80 |
+
|
81 |
+
|
82 |
+
if (empty($ecwid_default_category_id)) {
|
83 |
+
$ecwid_default_category_str = '';
|
84 |
+
} else {
|
85 |
+
$ecwid_default_category_str = ',"defaultCategoryId='. $ecwid_default_category_id .'"';
|
86 |
+
}
|
87 |
+
|
88 |
+
$ecwid_is_secure_page = $params['ecwid_is_secure_page'];
|
89 |
+
if (empty ($ecwid_is_secure_page)) {
|
90 |
+
$ecwid_is_secure_page = false;
|
91 |
+
}
|
92 |
+
|
93 |
+
$protocol = "http";
|
94 |
+
if ($ecwid_is_secure_page) {
|
95 |
+
$protocol = "https";
|
96 |
+
}
|
97 |
+
|
98 |
+
$integration_code = <<<EOT
|
99 |
+
<div>
|
100 |
+
<script type="text/javascript" src="$protocol://$ecwid_com/script.js?$store_id"></script>
|
101 |
+
<script type="text/javascript"> xProductBrowser("categoriesPerRow=$ecwid_pb_categoriesperrow","views=grid($ecwid_pb_productspercolumn_grid,$ecwid_pb_productsperrow_grid) list($ecwid_pb_productsperpage_list) table($ecwid_pb_productsperpage_table)","categoryView=$ecwid_pb_defaultview","searchView=$ecwid_pb_searchview","style="$ecwid_default_category_str);</script>
|
102 |
+
</div>
|
103 |
+
<noscript>$html_catalog</noscript>
|
104 |
+
$ecwid_open_product
|
105 |
+
EOT;
|
106 |
+
|
107 |
+
return $integration_code;
|
108 |
+
}
|
109 |
+
|
110 |
+
function show_ecwid_catalog($ecwid_store_id) {
|
111 |
+
include_once "ecwid_product_api.php";
|
112 |
+
$ecwid_store_id = intval($ecwid_store_id);
|
113 |
+
$api = new EcwidProductApi($ecwid_store_id);
|
114 |
+
|
115 |
+
$ecwid_category_id = intval($_GET['ecwid_category_id']);
|
116 |
+
$ecwid_product_id = intval($_GET['ecwid_product_id']);
|
117 |
+
|
118 |
+
if (!empty($ecwid_product_id)) {
|
119 |
+
$params = array(
|
120 |
+
array("alias" => "p", "action" => "product", "params" => array("id" => $ecwid_product_id)),
|
121 |
+
array("alias" => "pf", "action" => "profile")
|
122 |
+
);
|
123 |
+
$batch_result = $api->get_batch_request($params);
|
124 |
+
$product = $batch_result["p"];
|
125 |
+
$profile = $batch_result["pf"];
|
126 |
+
}
|
127 |
+
else {
|
128 |
+
if (empty($ecwid_category_id)) {
|
129 |
+
$ecwid_category_id = 0;
|
130 |
+
}
|
131 |
+
$params = array(
|
132 |
+
array("alias" => "c", "action" => "categories", "params" => array("parent" => $ecwid_category_id)),
|
133 |
+
array("alias" => "p", "action" => "products", "params" => array("category" => $ecwid_category_id)),
|
134 |
+
array("alias" => "pf", "action" => "profile")
|
135 |
+
);
|
136 |
+
|
137 |
+
$batch_result = $api->get_batch_request($params);
|
138 |
+
|
139 |
+
$categories = $batch_result["c"];
|
140 |
+
$products = $batch_result["p"];
|
141 |
+
$profile = $batch_result["pf"];
|
142 |
+
}
|
143 |
+
$html = '';
|
144 |
+
|
145 |
+
if (is_array($product)) {
|
146 |
+
$html = "<div class='hproduct'>";
|
147 |
+
$html .= "<div class='ecwid_catalog_product_image photo'><img src='" . $product["thumbnailUrl"] . "'/></div>";
|
148 |
+
$html .= "<div class='ecwid_catalog_product_name fn'>" . htmlentities($product["name"]) . "</div>";
|
149 |
+
$html .= "<div class='ecwid_catalog_product_price price'>Price: " . $product["price"] . " " . $profile["currency"] . "</div>";
|
150 |
+
$html .= "<div class='ecwid_catalog_product_description description'>" . $product["description"] . "</div>";
|
151 |
+
$html .= "</div>";
|
152 |
+
} else {
|
153 |
+
if (is_array($categories)) {
|
154 |
+
foreach ($categories as $category) {
|
155 |
+
$category_url = ecwid_internal_construct_url($category["url"], array("ecwid_category_id" => $category["id"]));
|
156 |
+
$category_name = $category["name"];
|
157 |
+
$html .= "<div class='ecwid_catalog_category_name'><a href='" . $category_url . "'>" . $category_name . "</a><br /></div>";
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
if (is_array($products)) {
|
162 |
+
foreach ($products as $product) {
|
163 |
+
$product_url = ecwid_internal_construct_url($product["url"], array("ecwid_product_id" => $product["id"]));
|
164 |
+
$product_name = $product["name"];
|
165 |
+
$product_price = $product["price"] . " " . $profile["currency"];
|
166 |
+
$html .= "<div>";
|
167 |
+
$html .= "<span class='ecwid_product_name'><a href='" . $product_url . "'>" . $product_name . "</a></span>";
|
168 |
+
$html .= " <span class='ecwid_product_price'>" . $product_price . "</span>";
|
169 |
+
$html .= "</div>";
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
}
|
174 |
+
return $html;
|
175 |
+
}
|
176 |
+
|
177 |
+
function ecwid_is_api_enabled($ecwid_store_id) {
|
178 |
+
$ecwid_store_id = intval($ecwid_store_id);
|
179 |
+
$api = new EcwidProductApi($ecwid_store_id);
|
180 |
+
return $api->is_api_enabled();
|
181 |
+
}
|
182 |
+
|
183 |
+
function ecwid_internal_construct_url($url_with_anchor, $additional_get_params) {
|
184 |
+
$is_https = ($_SERVER["HTTPS"] == "on");
|
185 |
+
$port = $_SERVER["SERVER_PORT"];
|
186 |
+
$host = $_SERVER["HTTP_HOST"];
|
187 |
+
$path = $_SERVER["SCRIPT_NAME"];
|
188 |
+
// extract anchor
|
189 |
+
$url_fragments = parse_url($url_with_anchor);
|
190 |
+
$anchor = $url_fragments["fragment"];
|
191 |
+
// get params
|
192 |
+
$get_params = $_GET;
|
193 |
+
unset ($get_params["ecwid_category_id"]);
|
194 |
+
unset ($get_params["ecwid_product_id"]);
|
195 |
+
$get_params = array_merge($get_params, $additional_get_params);
|
196 |
+
|
197 |
+
// construct url
|
198 |
+
|
199 |
+
// add schema
|
200 |
+
$base_url = "";
|
201 |
+
if (!$is_https) {
|
202 |
+
$base_url = "http://";
|
203 |
+
} else {
|
204 |
+
$base_url = "https://";
|
205 |
+
}
|
206 |
+
|
207 |
+
// add hostname
|
208 |
+
$base_url .= $host;
|
209 |
+
|
210 |
+
// add port (if needed)
|
211 |
+
if (($is_https && ($port != 443)) || (!$is_https && ($port != 80))) {
|
212 |
+
$base_url .= ":" . $port;
|
213 |
+
}
|
214 |
+
|
215 |
+
// add path
|
216 |
+
$base_url .= $path;
|
217 |
+
|
218 |
+
// add GET parameters
|
219 |
+
if (count($get_params) > 0) {
|
220 |
+
$base_url .= "?";
|
221 |
+
$is_first = true;
|
222 |
+
foreach ($get_params as $key => $value) {
|
223 |
+
if (!$is_first) {
|
224 |
+
$base_url .= "&";
|
225 |
+
}
|
226 |
+
$base_url .= $key . "=" . $value;
|
227 |
+
$is_first = false;
|
228 |
+
}
|
229 |
+
}
|
230 |
+
|
231 |
+
// add url anchor (if needed)
|
232 |
+
if ($anchor != "") {
|
233 |
+
$base_url .= "#" . $anchor;
|
234 |
+
}
|
235 |
+
|
236 |
+
return $base_url;
|
237 |
+
}
|
238 |
+
|
239 |
+
?>
|
lib/ecwid_product_api.php
ADDED
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class EcwidProductApi {
|
4 |
+
var $store_id = '';
|
5 |
+
|
6 |
+
var $error = '';
|
7 |
+
|
8 |
+
var $error_code = '';
|
9 |
+
|
10 |
+
var $ECWID_PRODUCT_API_ENDPOINT = "http://app.ecwid.com/api/v1";
|
11 |
+
|
12 |
+
function __construct($store_id) {
|
13 |
+
$this->store_id = intval($store_id);
|
14 |
+
}
|
15 |
+
|
16 |
+
function EcwidProductApi($store_id) {
|
17 |
+
if(version_compare(PHP_VERSION,"5.0.0","<")) {
|
18 |
+
$this->__construct($store_id);
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
function internal_parse_json($json) {
|
23 |
+
if(version_compare(PHP_VERSION,"5.2.0",">=")) {
|
24 |
+
return json_decode($json, true);
|
25 |
+
}
|
26 |
+
include_once('JSON.php');
|
27 |
+
$json_parser = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
|
28 |
+
return $json_parser->decode($json);
|
29 |
+
}
|
30 |
+
|
31 |
+
function internal_fetch_url_libcurl($url) {
|
32 |
+
if (intval($timeout) <= 0)
|
33 |
+
$timeout = 90;
|
34 |
+
if (!function_exists('curl_init'))
|
35 |
+
return array("code"=>"0","data"=>"libcurl is not installed");
|
36 |
+
$headers[] = "Content-Type: application/x-www-form-urlencoded";
|
37 |
+
$ch = curl_init();
|
38 |
+
|
39 |
+
curl_setopt ($ch, CURLOPT_URL, $url);
|
40 |
+
curl_setopt ($ch, CURLOPT_HEADER, 0);
|
41 |
+
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
|
42 |
+
curl_setopt ($ch, CURLOPT_HTTPGET, 1);
|
43 |
+
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
|
44 |
+
|
45 |
+
$body = curl_exec ($ch);
|
46 |
+
$errno = curl_errno ($ch);
|
47 |
+
$error = curl_error($ch);
|
48 |
+
|
49 |
+
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
50 |
+
$result = array();
|
51 |
+
if( $error ) {
|
52 |
+
return array("code"=>"0","data"=>"libcurl error($errno): $error");
|
53 |
+
}
|
54 |
+
|
55 |
+
return array("code"=>$httpcode, "data"=>$body);
|
56 |
+
}
|
57 |
+
|
58 |
+
function process_request($url) {
|
59 |
+
$result = $this->internal_fetch_url_libcurl($url);
|
60 |
+
if ($result['code'] == 200) {
|
61 |
+
$this->error = '';
|
62 |
+
$this->error_code = '';
|
63 |
+
$json = $result['data'];
|
64 |
+
return $this->internal_parse_json($json);
|
65 |
+
} else {
|
66 |
+
$this->error = $result['data'];
|
67 |
+
$this->error_code = $result['code'];
|
68 |
+
return false;
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
function get_all_categories() {
|
73 |
+
$api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/categories";
|
74 |
+
$categories = $this->process_request($api_url);
|
75 |
+
return $categories;
|
76 |
+
}
|
77 |
+
|
78 |
+
function get_subcategories_by_id($parent_category_id = 0) {
|
79 |
+
$parent_category_id = intval($parent_category_id);
|
80 |
+
$api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/categories?parent=" .
|
81 |
+
$parent_category_id;
|
82 |
+
$categories = $this->process_request($api_url);
|
83 |
+
return $categories;
|
84 |
+
}
|
85 |
+
|
86 |
+
function get_all_products() {
|
87 |
+
$api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/products";
|
88 |
+
$products = $this->process_request($api_url);
|
89 |
+
return $products;
|
90 |
+
}
|
91 |
+
|
92 |
+
|
93 |
+
function get_products_by_category_id($category_id = 0) {
|
94 |
+
$category_id = intval($category_id);
|
95 |
+
$api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/products?category=" . $category_id;
|
96 |
+
$products = $this->process_request($api_url);
|
97 |
+
return $products;
|
98 |
+
}
|
99 |
+
|
100 |
+
function get_product($product_id) {
|
101 |
+
$product_id = intval($product_id);
|
102 |
+
$api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/product?id=" . $product_id;
|
103 |
+
$product = $this->process_request($api_url);
|
104 |
+
return $product;
|
105 |
+
}
|
106 |
+
|
107 |
+
function get_batch_request($params) {
|
108 |
+
if (!is_array($params)) {
|
109 |
+
return false;
|
110 |
+
} else {
|
111 |
+
$api_url = '';
|
112 |
+
foreach ($params as $param) {
|
113 |
+
$alias = $param["alias"];
|
114 |
+
$action = $param["action"];
|
115 |
+
$action_params = $param["params"];
|
116 |
+
if (!empty($api_url))
|
117 |
+
$api_url .= "&";
|
118 |
+
|
119 |
+
$api_url .= ($alias . "=" . $action);
|
120 |
+
|
121 |
+
// if there are the parameters - add it to url
|
122 |
+
if (is_array($action_params)) {
|
123 |
+
$action_param_str = "?";
|
124 |
+
$is_first = true;
|
125 |
+
foreach ($action_params as $action_param_name => $action_param_value) {
|
126 |
+
if (!$is_first) {
|
127 |
+
$action_param_str .= "&";
|
128 |
+
}
|
129 |
+
$action_param_str .= $action_param_name . "=" . $action_param_value;
|
130 |
+
$is_first = false;
|
131 |
+
}
|
132 |
+
$action_param_str = urlencode($action_param_str);
|
133 |
+
$api_url .= $action_param_str;
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
$api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/batch?". $api_url;
|
138 |
+
$data = $this->process_request($api_url);
|
139 |
+
return $data;
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
function get_random_products($count) {
|
144 |
+
$count = intval($count);
|
145 |
+
$api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/random_products?count=" . $count;
|
146 |
+
$random_products = $this->process_request($api_url);
|
147 |
+
return $random_products;
|
148 |
+
}
|
149 |
+
|
150 |
+
function get_profile() {
|
151 |
+
$api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/profile";
|
152 |
+
$profile = $this->process_request($api_url);
|
153 |
+
return $profile;
|
154 |
+
}
|
155 |
+
|
156 |
+
function is_api_enabled() {
|
157 |
+
// quick and lightweight request
|
158 |
+
$api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/profile";
|
159 |
+
$this->process_request($api_url);
|
160 |
+
if ($this->error_code === '') {
|
161 |
+
return true;
|
162 |
+
} else {
|
163 |
+
return false;
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
?>
|
readme.txt
CHANGED
@@ -2,31 +2,33 @@
|
|
2 |
Contributors: Ecwid Team
|
3 |
Tags: shopping cart, ecommerce, e-commerce, paypal, google checkout, 2checkout, store, shop, product catalog, inventory
|
4 |
Requires at least: 2.8
|
5 |
-
Tested up to:
|
6 |
-
Stable tag: 0.
|
7 |
|
8 |
-
Ecwid is a free full-
|
9 |
and takes less than 5 minutes to set up.
|
10 |
|
11 |
== Description ==
|
12 |
-
Ecwid is a free full-
|
13 |
-
|
14 |
-
with none of the hassles you don't.
|
15 |
|
16 |
-
There are
|
17 |
|
18 |
-
- It's
|
19 |
-
- It
|
20 |
-
- It
|
21 |
-
- It
|
22 |
-
-
|
23 |
-
-
|
24 |
-
-
|
|
|
|
|
25 |
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
|
|
30 |
|
31 |
== Installation ==
|
32 |
|
@@ -36,9 +38,17 @@ Full list of features:
|
|
36 |
|
37 |
== Frequently Asked Questions ==
|
38 |
|
39 |
-
[http://www.ecwid.com/faq.html](http://www.ecwid.com/faq.html)
|
|
|
40 |
|
41 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
= 0.4 =
|
43 |
- [+] Instruction in the plugin settings was updated.
|
44 |
- [+] New plugin option to use on secure pages was added.
|
@@ -50,7 +60,7 @@ Full list of features:
|
|
50 |
- [+] New built-in "ecwid_ProductBrowserURL" feature: http://kb.ecwid.com/ecwid_ProductBrowserURL
|
51 |
|
52 |
= 0.2 =
|
53 |
-
- [+] New
|
54 |
- [+] New options effecting the store appearance
|
55 |
- [!] Minor bugfixes
|
56 |
|
2 |
Contributors: Ecwid Team
|
3 |
Tags: shopping cart, ecommerce, e-commerce, paypal, google checkout, 2checkout, store, shop, product catalog, inventory
|
4 |
Requires at least: 2.8
|
5 |
+
Tested up to: 3.0
|
6 |
+
Stable tag: 0.6
|
7 |
|
8 |
+
Ecwid is a free full-featured shopping cart that can easily be added to any blog
|
9 |
and takes less than 5 minutes to set up.
|
10 |
|
11 |
== Description ==
|
12 |
+
Ecwid is a free full-featured shopping cart and an e-commerce solution that can easily be added to any blog or Facebook profile. It offers the performance and flexibility you need, with none of the hassles you don't.
|
13 |
+
"Ecwid" stands for "ecommerce widgets".
|
|
|
14 |
|
15 |
+
There are eight key advantages to Ecwid:
|
16 |
|
17 |
+
- It's free.
|
18 |
+
- It has AJAX everywhere and supports drag-and-drop.
|
19 |
+
- It can be easily integrated to any existing site or Facebook profile in minutes.
|
20 |
+
- It can be mirrored on many sites at the same time. Add your store to many sites, manage it from one place.
|
21 |
+
- Integration with social networks. Run your own store on Facebook, mySpace and many others.
|
22 |
+
- Simple to use and maintain. For both store owner and customer.
|
23 |
+
- Lightning fast. New-gen technologies make Ecwid much faster than usual
|
24 |
+
shopping carts regardless the hosting service you use.
|
25 |
+
- Seamless upgrades. You just wake up one day and enjoy new features.
|
26 |
|
27 |
+
Links
|
28 |
|
29 |
+
- You can see the demo there: [www.ecwid.com/demo-frontend.html](http://www.ecwid.com/demo-frontend.html)
|
30 |
+
- More features:
|
31 |
+
[www.ecwid.com/key-features.html](http://www.ecwid.com/key-features.html)
|
32 |
|
33 |
== Installation ==
|
34 |
|
38 |
|
39 |
== Frequently Asked Questions ==
|
40 |
|
41 |
+
- [http://www.ecwid.com/faq.html](http://www.ecwid.com/faq.html)
|
42 |
+
- [http://kb.ecwid.com](http://kb.ecwid.com)
|
43 |
|
44 |
== Changelog ==
|
45 |
+
= 0.6 =
|
46 |
+
- [+] The "Inline SEO catalog" option was added.
|
47 |
+
|
48 |
+
= 0.5 =
|
49 |
+
- [+] Plugin settings page was updated.
|
50 |
+
- [+] Two new options: "Full link to your mobile catalog" and "Default category ID".
|
51 |
+
|
52 |
= 0.4 =
|
53 |
- [+] Instruction in the plugin settings was updated.
|
54 |
- [+] New plugin option to use on secure pages was added.
|
60 |
- [+] New built-in "ecwid_ProductBrowserURL" feature: http://kb.ecwid.com/ecwid_ProductBrowserURL
|
61 |
|
62 |
= 0.2 =
|
63 |
+
- [+] New sidebar widgets were added: search box, minicart and vertical categories
|
64 |
- [+] New options effecting the store appearance
|
65 |
- [!] Minor bugfixes
|
66 |
|