PluginProbe
Welcart e-Commerce / 2.11.35
Welcart e-Commerce v2.11.35
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / functions / utility.php

utility.php in Welcart e-Commerce 2.11.35, at functions/utility.php

1,807 lines 51.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Utility
4 *
5 * @package Welcart
6 */
7
8 // phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL
9 // phpcs:disable WordPress.PHP.DevelopmentFunctions, WordPress.PHP.NoSilencedErrors
10
11 /**
12 * Upgrade 143
13 *
14 * @return bool
15 */
16 function usces_upgrade_143() {
17
18 $upgrade = (int) get_option( 'usces_upgrade3' );
19 if ( 0 !== $upgrade ) {
20 return true;
21 }
22
23 global $wpdb;
24 $table = $wpdb->prefix . 'usces_ordercart';
25 $wpdb->query( "ALTER TABLE $table CHANGE `cprice` `cprice` DECIMAL( 15, 2 ) NULL DEFAULT NULL" );
26 $wpdb->query( "ALTER TABLE $table CHANGE `price` `price` DECIMAL( 15, 2 ) NULL DEFAULT NULL" );
27 $wpdb->query( "ALTER TABLE $table CHANGE `tax` `tax` DECIMAL( 13, 2 ) NULL DEFAULT NULL" );
28
29 $upgrade += USCES_UP143;
30 update_option( 'usces_upgrade3', $upgrade );
31 usces_log( 'USCES_UP143 : Completed', 'db' );
32
33 return true;
34 }
35
36 /**
37 * Upgrade 141
38 *
39 * @return bool
40 */
41 function usces_upgrade_141() {
42
43 $upgrade = (int) get_option( 'usces_upgrade2' );
44 if ( 3 !== $upgrade ) {
45 return true;
46 }
47
48 global $wpdb, $usces;
49 $rets = array();
50
51 $options = get_option( 'usces', array() );
52 if ( empty( $options['tax_rate'] ) ) {
53 $options['tax_mode'] = 'include';
54 } else {
55 $options['tax_mode'] = 'exclude';
56 }
57 $options['tax_target'] = 'all';
58 update_option( 'usces', $options );
59
60 $order_table = $wpdb->prefix . 'usces_order';
61 $cart_table = $wpdb->prefix . 'usces_ordercart';
62 $cart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
63
64 $query = "SELECT ID, order_cart, order_condition FROM $order_table";
65 $results = $wpdb->get_results( $query );
66 if ( $results ) {
67 foreach ( $results as $order ) {
68
69 $query = $wpdb->prepare( "SELECT order_id FROM $cart_table WHERE order_id = %d", $order->ID );
70 $order_id = $wpdb->get_var( $query );
71 if ( $order_id == $order->ID ) {
72 continue;
73 }
74 $condition = wel_safe_maybe_unserialize( $order->order_condition );
75 if ( ! isset( $condition['tax_mode'] ) ) {
76 $condition['tax_mode'] = $options['tax_mode'];
77 }
78 if ( ! isset( $condition['tax_rate'] ) ) {
79 $condition['tax_rate'] = (int) $options['tax_rate'];
80 }
81 if ( ! isset( $condition['tax_target'] ) ) {
82 $condition['tax_target'] = $options['tax_target'];
83 }
84
85 $cart = wel_safe_unserialize( $order->order_cart );
86 foreach ( (array) $cart as $row_index => $value ) {
87 $product = wel_get_product( $value['post_id'] );
88 $item_code = $product['itemCode'];
89 $item_name = $product['itemName'];
90 $skus = $usces->get_skus( $value['post_id'], 'code' );
91 $sku_code = urldecode( $value['sku'] );
92 $sku_encoded = $value['sku'];
93 $sku = isset( $skus[ $sku_code ] ) ? $skus[ $sku_code ] : array( 'name' => 'notfound', 'cprice' => 0, 'unit' => '' );
94 $tax = 0;
95 $query = $wpdb->prepare(
96 "INSERT INTO $cart_table
97 (
98 order_id, group_id, row_index,
99 post_id, item_code, item_name,
100 sku_code, sku_name, cprice, price, quantity, unit,
101 tax, destination_id, cart_serial
102 ) VALUES (
103 %d, %d, %d,
104 %d, %s, %s,
105 %s, %s, %f, %f, %d, %s,
106 %f, %d, %s
107 )",
108 $order->ID, 0, $row_index,
109 $value['post_id'], $item_code, $item_name,
110 $sku_code, $sku['name'], $sku['cprice'], $value['price'], $value['quantity'], $sku['unit'],
111 $tax, NULL, $value['serial']
112 );
113 $wpdb->query( $query );
114
115 $cart_id = $wpdb->insert_id;
116 if ( $cart_id ) {
117 if ( $value['options'] ) {
118 foreach ( (array) $value['options'] as $okey => $ovalue ) {
119 $okey = urldecode( $okey );
120 if ( is_array( $ovalue ) ) {
121 $ovalue = serialize( $ovalue );
122 } else {
123 $ovalue = urldecode( $ovalue );
124 }
125 $oquery = $wpdb->prepare(
126 "INSERT INTO $cart_meta_table
127 (
128 cart_id, meta_type, meta_key, meta_value
129 ) VALUES (
130 %d, 'option', %s, %s
131 )",
132 $cart_id, $okey, $ovalue
133 );
134 $wpdb->query( $oquery );
135 }
136 }
137 if ( $value['advance'] ) {
138 foreach ( (array) $value['advance'] as $akey => $avalue ) {
139 $advance = wel_safe_maybe_unserialize( $avalue );
140 if ( is_array( $advance ) ) {
141 $post_id = $value['post_id'];
142 if ( is_array( $advance[ $post_id ][ $sku_encoded ] ) ) {
143 $akeys = array_keys( $advance[ $post_id ][ $sku_encoded ] );
144 foreach ( (array) $akeys as $akey ) {
145 $avalue = serialize( $advance[ $post_id ][ $sku_encoded ][ $akey ] );
146 $aquery = $wpdb->prepare(
147 "INSERT INTO $cart_meta_table
148 (
149 cart_id, meta_type, meta_key, meta_value
150 ) VALUES (
151 %d, 'advance', %s, %s
152 )",
153 $cart_id, $akey, $avalue
154 );
155 $wpdb->query( $aquery );
156 }
157 } else {
158 $akeys = array_keys( $advance );
159 $akey = ( empty( $akeys[0] ) ) ? 'advance' : $akeys[0];
160 $avalue = serialize( $advance );
161 $aquery = $wpdb->prepare(
162 "INSERT INTO $cart_meta_table
163 (
164 cart_id, meta_type, meta_key, meta_value
165 ) VALUES (
166 %d, 'advance', %s, %s
167 )",
168 $cart_id, $akey, $avalue
169 );
170 $wpdb->query( $aquery );
171 }
172 } else {
173 $avalue = urldecode( $avalue );
174 $aquery = $wpdb->prepare(
175 "INSERT INTO $cart_meta_table
176 (
177 cart_id, meta_type, meta_key, meta_value
178 ) VALUES (
179 %d, 'advance', 'advance', %s
180 )",
181 $cart_id, $avalue
182 );
183 $wpdb->query( $aquery );
184 }
185 }
186 }
187 }
188 }
189
190 $upquery = $wpdb->prepare(
191 "UPDATE $order_table SET order_condition = %s WHERE ID = %d",
192 serialize( $condition ), $order->ID
193 );
194 $wpdb->query( $upquery );
195 }
196 }
197 usces_log( 'USCES_UP141 : Completed : from ' . $upgrade, 'db' );
198 $upgrade += USCES_UP141;
199 update_option( 'usces_upgrade2', $upgrade );
200
201 return true;
202 }
203
204 /**
205 * Upgrade 14
206 *
207 * @return bool
208 */
209 function usces_upgrade_14() {
210
211 $upgrade = (int) get_option( 'usces_upgrade2' );
212 if ( 0 < $upgrade ) {
213 return true;
214 }
215
216 global $wpdb, $usces;
217 $rets = array();
218
219 $options = get_option( 'usces', array() );
220 if ( empty( $options['tax_rate'] ) ) {
221 $options['tax_mode'] = 'include';
222 } else {
223 $options['tax_mode'] = 'exclude';
224 }
225 $options['tax_target'] = 'all';
226 update_option( 'usces', $options );
227
228 $order_table = $wpdb->prefix . 'usces_order';
229 $cart_table = $wpdb->prefix . 'usces_ordercart';
230 $cart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
231
232 $query = "SELECT ID, order_cart, order_condition FROM $order_table";
233 $results = $wpdb->get_results( $query );
234 if ( $results ) {
235 foreach ( $results as $order ) {
236 $condition = wel_safe_maybe_unserialize( $order->order_condition );
237 if ( ! isset( $condition['tax_mode'] ) ) {
238 $condition['tax_mode'] = $options['tax_mode'];
239 }
240 if ( ! isset( $condition['tax_rate'] ) ) {
241 $condition['tax_rate'] = (int) $options['tax_rate'];
242 }
243 if ( ! isset( $condition['tax_target'] ) ) {
244 $condition['tax_target'] = $options['tax_target'];
245 }
246
247 $cart = wel_safe_unserialize( $order->order_cart );
248 foreach ( (array) $cart as $row_index => $value ) {
249 $product = wel_get_product( $value['post_id'] );
250 $item_code = $product['itemCode'];
251 $item_name = $product['itemName'];
252 $skus = $usces->get_skus( $value['post_id'], 'code' );
253 $sku_code = urldecode( $value['sku'] );
254 $sku_encoded = $value['sku'];
255 $sku = isset( $skus[ $sku_code ] ) ? $skus[ $sku_code ] : array( 'name' => 'notfound', 'cprice' => 0, 'unit' => '' );
256 $tax = 0;
257 $query = $wpdb->prepare(
258 "INSERT INTO $cart_table
259 (
260 order_id, group_id, row_index,
261 post_id, item_code, item_name,
262 sku_code, sku_name, cprice, price, quantity, unit,
263 tax, destination_id, cart_serial
264 ) VALUES (
265 %d, %d, %d,
266 %d, %s, %s,
267 %s, %s, %f, %f, %d, %s,
268 %f, %d, %s
269 )",
270 $order->ID, 0, $row_index,
271 $value['post_id'], $item_code, $item_name,
272 $sku_code, $sku['name'], $sku['cprice'], $value['price'], $value['quantity'], $sku['unit'],
273 $tax, NULL, $value['serial']
274 );
275 $wpdb->query( $query );
276
277 $cart_id = $wpdb->insert_id;
278 if ( $cart_id ) {
279 if ( $value['options'] ) {
280 foreach ( (array) $value['options'] as $okey => $ovalue ) {
281 $okey = urldecode( $okey );
282 if ( is_array( $ovalue ) ) {
283 $ovalue = serialize( $ovalue );
284 } else {
285 $ovalue = urldecode( $ovalue );
286 }
287 $oquery = $wpdb->prepare(
288 "INSERT INTO $cart_meta_table
289 (
290 cart_id, meta_type, meta_key, meta_value
291 ) VALUES (
292 %d, 'option', %s, %s
293 )",
294 $cart_id, $okey, $ovalue
295 );
296 $wpdb->query( $oquery );
297 }
298 }
299 if ( $value['advance'] ) {
300 foreach ( (array) $value['advance'] as $akey => $avalue ) {
301 $advance = wel_safe_maybe_unserialize( $avalue );
302 if ( is_array( $advance ) ) {
303 $post_id = $value['post_id'];
304 if ( is_array( $advance[ $post_id ][ $sku_encoded ] ) ) {
305 $akeys = array_keys( $advance[ $post_id ][ $sku_encoded ] );
306 foreach ( (array) $akeys as $akey ) {
307 $avalue = serialize( $advance[ $post_id ][ $sku_encoded ][ $akey ] );
308 $aquery = $wpdb->prepare(
309 "INSERT INTO $cart_meta_table
310 (
311 cart_id, meta_type, meta_key, meta_value
312 ) VALUES (
313 %d, 'advance', %s, %s
314 )",
315 $cart_id, $akey, $avalue
316 );
317 $wpdb->query( $aquery );
318 }
319 } else {
320 $akeys = array_keys( $advance );
321 $akey = ( empty( $akeys[0] ) ) ? 'advance' : $akeys[0];
322 $avalue = serialize( $advance );
323 $aquery = $wpdb->prepare(
324 "INSERT INTO $cart_meta_table
325 (
326 cart_id, meta_type, meta_key, meta_value
327 ) VALUES (
328 %d, 'advance', %s, %s
329 )",
330 $cart_id, $akey, $avalue
331 );
332 $wpdb->query( $aquery );
333 }
334 } else {
335 $avalue = urldecode( $avalue );
336 $aquery = $wpdb->prepare(
337 "INSERT INTO $cart_meta_table
338 (
339 cart_id, meta_type, meta_key, meta_value
340 ) VALUES (
341 %d, 'advance', 'advance', %s
342 )",
343 $cart_id, $avalue
344 );
345 $wpdb->query( $aquery );
346 }
347 }
348 }
349 }
350 }
351
352 $upquery = $wpdb->prepare(
353 "UPDATE $order_table SET order_condition = %s WHERE ID = %d",
354 serialize( $condition ), $order->ID
355 );
356 $wpdb->query( $upquery );
357 }
358 }
359 usces_log( 'USCES_UP14 : Completed : from ' . $upgrade, 'db' );
360 $upgrade += USCES_UP14;
361 update_option( 'usces_upgrade2', $upgrade );
362
363 return true;
364 }
365
366 /**
367 * Upgrade 07
368 *
369 * @return bool
370 */
371 function usces_upgrade_07() {
372
373 $upgrade = (int) get_option( 'usces_upgrade' );
374 if ( 0 !== $upgrade ) {
375 return true;
376 }
377
378 global $wpdb;
379 $rets = array();
380
381 $tablename = $wpdb->prefix . 'postmeta';
382 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'iopt_', '_iopt_') WHERE meta_key LIKE 'iopt_%'";
383 if ( $wpdb->query( $mquery ) ) {
384 $rets[] = 1;
385 }
386 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'isku_', '_isku_') WHERE meta_key LIKE 'isku_%'";
387 if ( $wpdb->query( $mquery ) ) {
388 $rets[] = 1;
389 }
390 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemCode', '_itemCode') WHERE meta_key LIKE 'itemCode'";
391 if( $wpdb->query( $mquery ) )
392 $rets[] = 1;
393
394 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemName', '_itemName') WHERE meta_key LIKE 'itemName'";
395 if ( $wpdb->query( $mquery ) ) {
396 $rets[] = 1;
397 }
398 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemRestriction', '_itemRestriction') WHERE meta_key LIKE 'itemRestriction'";
399 if ( $wpdb->query( $mquery ) ) {
400 $rets[] = 1;
401 }
402 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemPointrate', '_itemPointrate') WHERE meta_key LIKE 'itemPointrate'";
403 if ( $wpdb->query( $mquery ) ) {
404 $rets[] = 1;
405 }
406 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpNum1', '_itemGpNum1') WHERE meta_key LIKE 'itemGpNum1'";
407 if ( $wpdb->query( $mquery ) ) {
408 $rets[] = 1;
409 }
410 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpDis1', '_itemGpDis1') WHERE meta_key LIKE 'itemGpDis1'";
411 if ( $wpdb->query( $mquery ) ) {
412 $rets[] = 1;
413 }
414 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpNum2', '_itemGpNum2') WHERE meta_key LIKE 'itemGpNum2'";
415 if ( $wpdb->query( $mquery ) ) {
416 $rets[] = 1;
417 }
418 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpDis2', '_itemGpDis2') WHERE meta_key LIKE 'itemGpDis2'";
419 if ( $wpdb->query( $mquery ) ) {
420 $rets[] = 1;
421 }
422 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpDis3', '_itemGpDis3') WHERE meta_key LIKE 'itemGpDis3'";
423 if ( $wpdb->query( $mquery ) ) {
424 $rets[] = 1;
425 }
426 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpNum3', '_itemGpNum3') WHERE meta_key LIKE 'itemGpNum3'";
427 if ( $wpdb->query( $mquery ) ) {
428 $rets[] = 1;
429 }
430 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemShipping', '_itemShipping') WHERE meta_key LIKE 'itemShipping'";
431 if ( $wpdb->query( $mquery ) ) {
432 $rets[] = 1;
433 }
434 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemDeliveryMethod', '_itemDeliveryMethod') WHERE meta_key LIKE 'itemDeliveryMethod'";
435 if ( $wpdb->query( $mquery ) ) {
436 $rets[] = 1;
437 }
438 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemShippingCharge', '_itemShippingCharge') WHERE meta_key LIKE 'itemShippingCharge'";
439 if ( $wpdb->query( $mquery ) ) {
440 $rets[] = 1;
441 }
442 $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemIndividualSCharge', '_itemIndividualSCharge') WHERE meta_key LIKE 'itemIndividualSCharge'";
443 if ( $wpdb->query( $mquery ) ) {
444 $rets[] = 1;
445 }
446 usces_log( 'USCES_UP07 : ' . print_r( $rets, true ), 'db' );
447 $upgrade += USCES_UP07;
448 update_option( 'usces_upgrade', $upgrade );
449 return true;
450 }
451
452 /**
453 * Upgrade 11
454 *
455 * @return bool
456 */
457 function usces_upgrade_11() {
458
459 $options = get_option( 'usces', array() );
460 $upgrade = (int) get_option( 'usces_upgrade' );
461 if ( 1 !== $upgrade ) {
462 return true;
463 }
464
465 global $wpdb;
466 $rets = array();
467
468 /* ITEM SKU DATA */
469 $sort = (int) $options['system']['orderby_itemsku'];
470 if ( $sort ) {
471 $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_isku_' AND meta_key LIKE '_isku_%' ORDER BY post_id, meta_key";
472 } else {
473 $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_isku_' AND meta_key LIKE '_isku_%' ORDER BY post_id, meta_id";
474 }
475 $res = $wpdb->get_results( $query, ARRAY_A );
476
477 $conclusion = true;
478 $pre_post_id = 0;
479 $sort_id = 0;
480 $check_code = array();
481 $dep_num = array();
482 foreach ( (array) $res as $metarow ) {
483 $meta_value = wel_safe_unserialize( $metarow['meta_value'] );
484 $newvalue = array();
485 $newvalue['code'] = substr( $metarow['meta_key'], 6 );
486 if ( $pre_post_id == $metarow['post_id'] ) {
487 if ( in_array( $newvalue['code'], $check_code ) ) {
488 $newvalue['code'] .= 'dupricate_' . (int) $dep_num[ $newvalue['code'] ];
489 $dep_num[ $newvalue['code'] ]++;
490 }
491 } else {
492 $check_code = array();
493 $dep_num = array();
494 $sort_id = 0;
495 }
496 foreach ( (array) $meta_value as $k => $v ) {
497 switch ( $k ) {
498 case 'disp':
499 $newvalue['name'] = $v;
500 break;
501 case 'cprice':
502 $newvalue['cprice'] = $v;
503 break;
504 case 'price':
505 $newvalue['price'] = $v;
506 break;
507 case 'unit':
508 $newvalue['unit'] = $v;
509 break;
510 case 'zaikonum':
511 $newvalue['stocknum'] = $v;
512 break;
513 case 'zaiko':
514 $newvalue['stock'] = $v;
515 break;
516 case 'gptekiyo':
517 $newvalue['gp'] = $v;
518 break;
519 case 'charging_type':
520 break;
521 default:
522 $newvalue[ $k ] = $v;
523 }
524 }
525 $newvalue['sort'] = $sort_id;
526
527 $id = usces_add_sku( $metarow['post_id'], $newvalue, false );
528 $pre_post_id = $metarow['post_id'];
529 $check_code[] = $newvalue['code'];
530 $sort_id++;
531
532 $res_key = $metarow['post_id'] . '_' . $newvalue['code'];
533 if ( $id ) {
534 delete_post_meta( $metarow['post_id'], $metarow['meta_key'] );
535 $rets['sku'][ $res_key ] = 1;
536 } else {
537 $rets['sku'][ $res_key ] = 0;
538 usces_log( 'meta_id ' . $metarow['meta_id'] . ' : ' . __( 'This SKU-data has not been rebuilt.', 'usces' ), 'database_error.log' );
539 }
540 }
541
542 /* ITEM OPTION DATA */
543 $sort = (int) $options['system']['orderby_itemopt'];
544 if ( $sort ) {
545 $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_iopt_' AND meta_key LIKE '_iopt_%' ORDER BY post_id, meta_key";
546 } else {
547 $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_iopt_' AND meta_key LIKE '_iopt_%' ORDER BY post_id, meta_id";
548 }
549 $res = $wpdb->get_results( $query, ARRAY_A );
550
551 $conclusion = true;
552 $pre_post_id = 0;
553 $sort_id = 0;
554 $check_code = array();
555 $dep_num = array();
556 foreach ( (array) $res as $metarow ) {
557 $meta_value = wel_safe_unserialize( $metarow['meta_value'] );
558 $newvalue = array();
559 $newvalue['name'] = substr( $metarow['meta_key'], 6 );
560 if ( $pre_post_id == $metarow['post_id'] ) {
561 if ( in_array( $newvalue['name'], $check_code ) ) {
562 $newvalue['name'] .= 'dupricate_' . (int) $dep_num[ $newvalue['name'] ];
563 $dep_num[ $newvalue['name'] ]++;
564 }
565 } else {
566 $check_code = array();
567 $dep_num = array();
568 $sort_id = 0;
569 }
570 foreach ( (array) $meta_value as $k => $v ) {
571 switch ( $k ) {
572 case 'means':
573 $newvalue['means'] = $v;
574 break;
575 case 'essential':
576 $newvalue['essential'] = $v;
577 break;
578 case 'value':
579 if ( is_array( $v ) ) {
580 $nov = '';
581 foreach ( (array) $v as $vs ) {
582 if ( ! WCUtils::is_blank( $vs ) ) {
583 $nov .= $vs . "\n";
584 }
585 }
586 $newvalue['value'] = trim( $nov );
587 } else {
588 $newvalue['value'] = trim( $v );
589 }
590 break;
591 default:
592 $newvalue[ $k ] = trim( $v );
593 }
594 }
595 $newvalue['sort'] = $sort_id;
596
597 $id = usces_add_opt( $metarow['post_id'], $newvalue, false );
598 $pre_post_id = $metarow['post_id'];
599 $check_code[] = $newvalue['name'];
600 $sort_id++;
601
602 $res_key = $metarow['post_id'] . '_' . $newvalue['name'];
603 if ( $id ) {
604 delete_post_meta( $metarow['post_id'], $metarow['meta_key'] );
605 $rets['opt'][ $res_key ] = 1;
606 } else {
607 $rets['opt'][ $res_key ] = 0;
608 usces_log( 'meta_id ' . $metarow['meta_id'] . ' : ' . __( 'This Item-Option-data has not been rebuilt.', 'usces' ), 'database_error.log' );
609 }
610 }
611
612 /* PAYMENT METHOD DATA */
613 $payment = get_option( 'usces_payment_method' );
614 if ( empty( $payment ) ) {
615
616 $options = get_option( 'usces', array() );
617 $old_payment = isset( $options['payment_method'] ) ? $options['payment_method'] : '';
618 usces_log( 'old_payment : ' . print_r( $old_payment, true ), 'database_error.log' );
619 if ( ! empty( $old_payment ) && is_array( $old_payment ) ) {
620 foreach ( $old_payment as $key => $value ) {
621 $res_key = $key . '_' . $value['name'];
622 $id = usces_add_system_option( 'usces_payment_method', $value );
623 if ( $id ) {
624 $rets['payment'][ $res_key ] = 1;
625 } else {
626 $rets['payment'][ $res_key ] = 0;
627 usces_log( 'payment_method ' . $value['name'] . ' : ' . __( 'This Payment-Method-data has not been rebuilt.', 'usces' ), 'database_error.log' );
628 }
629 }
630 }
631 }
632
633 usces_log( 'USCES_UP11 : ' . print_r( $rets, true ), 'db' );
634
635 $upgrade += USCES_UP11;
636 update_option( 'usces_upgrade', $upgrade );
637
638 return true;
639 }
640
641 /**
642 * Output log data.
643 *
644 * @param mixed $log Log.
645 * @param string $file Output.
646 * @param string $type Type.
647 * @param string $key Key.
648 */
649 function usces_log( $log, $file, $type = '', $key = '' ) {
650 global $wpdb;
651
652 if ( 'db' == $file ) {
653
654 $table_name = $wpdb->prefix . 'usces_log';
655 $query = $wpdb->prepare( "INSERT INTO $table_name ( datetime, log, log_type, log_key ) VALUES( %s, %s, %s, %s )", current_time( 'mysql' ), $log, $type, $key );
656 $wpdb->query( $query );
657
658 } else {
659
660 $logdir = USCES_PLUGIN_DIR . '/logs';
661 $file_path = $logdir . '/' . $file;
662 if ( is_dir( $file_path ) ) {
663 return;
664 }
665
666 $htaccess_path = $logdir . '/.htaccess';
667 if ( ! file_exists( $htaccess_path ) ) {
668 if ( $ht = @fopen( $htaccess_path, 'w' ) ) {
669 fwrite( $ht, 'Order deny,allow' . "\n" );
670 fwrite( $ht, 'Deny from all' . "\n" );
671 fclose( $ht );
672 }
673 }
674
675 if ( is_writable( $file_path ) || ( 'db' != $file && 'test' == $type ) ) {
676 $log = date( '[Y-m-d H:i:s]', current_time( 'timestamp' ) ) . "\t" . $log . "\n";
677 if ( $fp = @fopen( $file_path, 'a' ) ) {
678 fwrite( $fp, $log );
679 fclose( $fp );
680 }
681 } else {
682
683 $type = 'unwritable';
684 $key = $file;
685 $table_name = $wpdb->prefix . 'usces_log';
686 $query = $wpdb->prepare( "INSERT INTO $table_name ( datetime, log, log_type, log_key ) VALUES( %s, %s, %s, %s )", current_time( 'mysql' ), $log, $type, $key );
687 $wpdb->query( $query );
688
689 }
690 }
691 }
692
693 /**
694 * Convenience store name
695 *
696 * @param string $code Convenience store code.
697 * @return string
698 */
699 function usces_get_conv_name( $code ) {
700 switch ( $code ) {
701 case 'D001':
702 $name = 'セブン-イレブン';
703 break;
704 case '010':
705 $name = 'セブンイレブン';
706 break;
707 case 'D002':
708 case '020':
709 $name = 'ローソン';
710 break;
711 case 'D015':
712 case '760':
713 $name = 'セイコーマート';
714 break;
715 case 'D405':
716 $name = 'ペイジー';
717 break;
718 case 'D003':
719 $name = 'サンクス';
720 break;
721 case 'D004':
722 $name = 'サークルK';
723 break;
724 case 'D040':
725 $name = 'サークルKサンクス';
726 break;
727 case 'D005':
728 case '080':
729 case 'D050':
730 $name = 'ミニストップ';
731 break;
732 case 'D010':
733 case 'D060':
734 $name = 'デイリーヤマザキ';
735 break;
736 case 'D011':
737 $name = 'ヤマザキデイリーストア';
738 break;
739 case 'D030':
740 case '030':
741 $name = 'ファミリーマート';
742 break;
743 case 'D401':
744 $name = '楽天Edy';
745 break;
746 case 'D404':
747 $name = '楽天銀行';
748 break;
749 case 'D406':
750 $name = 'ジャパネット銀行';
751 break;
752 case 'D407':
753 $name = 'Suicaインターネットサービス';
754 break;
755 case 'D451':
756 $name = 'ウェブマネー';
757 break;
758 case 'D452':
759 $name = 'ビットキャッシュ';
760 break;
761 case 'D453':
762 $name = 'JCBプレモカード';
763 break;
764 case 'P901':
765 $name = 'コンビニ払込票';
766 break;
767 case 'P902':
768 $name = 'コンビニ払込票(郵便振替対応)';
769 break;
770 case '050':
771 $name = 'デイリーヤマザキ・ヤマザキデイリーストア・タイムリー';
772 break;
773 case '060':
774 $name = 'サークルK・サンクス';
775 break;
776 case '110':
777 $name = 'am/pm';
778 break;
779 default:
780 $name = '';
781 }
782 return $name;
783 }
784
785 /**
786 * Payment Method Details
787 *
788 * @param array $usces_entries Entry data.
789 * @return string
790 */
791 function usces_payment_detail( $usces_entries ) {
792 global $usces;
793
794 $payments = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
795 $acting_flag = ( 'acting' == $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
796 $str = '';
797 switch ( $acting_flag ) {
798 case 'paypal.php':
799 break;
800
801 case 'epsilon.php':
802 break;
803
804 case 'acting_remise_card':
805 if ( isset( $usces_entries['order']['div'] ) ) {
806 switch ( $usces_entries['order']['div'] ) {
807 case '0':
808 $str = ' 一括払い';
809 break;
810 case '1':
811 $str = ' 分割(2回)';
812 break;
813 case '2':
814 $str = ' 分割(リボ払い)';
815 break;
816 }
817 }
818 break;
819
820 case 'acting_remise_conv':
821 break;
822
823 case 'transferAdvance':
824 if ( ! empty( $usces->options['tatransfer_limit'] ) ) {
825 $payment_detail = __( '(', 'usces' ) . sprintf( __( 'Payment is valid for %s days from the date of order.', 'usces' ), $usces->options['tatransfer_limit'] ) . __( ')', 'usces' );
826 $str = apply_filters( 'usces_filter_transferAdvance_payment_limit', $payment_detail, $usces->options['tatransfer_limit'] );
827 }
828 break;
829
830 case 'transferDeferred':
831 if ( ! empty( $usces->options['tatransfer_limit'] ) ) {
832 $payment_detail = __( '(', 'usces' ) . sprintf( __( 'Payment is valid for %s days from after the item arrives.', 'usces' ), $usces->options['tatransfer_limit'] ) . __( ')', 'usces' );
833 $str = apply_filters( 'usces_filter_transferDeferred_payment_limit', $payment_detail, $usces->options['tatransfer_limit'] );
834 }
835 break;
836 }
837
838 $str = apply_filters( 'usces_filter_payment_detail', $str, $usces_entries );
839 return $str;
840 }
841
842 /**
843 * Payment Method Details
844 *
845 * @param array $order_data Order data.
846 * @return string
847 */
848 function usces_payment_detail_confirm( $order_data ) {
849 global $usces;
850
851 $payments = usces_get_payments_by_name( $order_data['order_payment_name'] );
852 $acting_flag = ( 'acting' == $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
853 $str = '';
854 switch ( $acting_flag ) {
855 case 'paypal.php':
856 break;
857 case 'epsilon.php':
858 break;
859 case 'acting_remise_card':
860 break;
861 case 'acting_remise_conv':
862 break;
863
864 case 'transferAdvance':
865 if ( ! empty( $usces->options['tatransfer_limit'] ) && $usces->is_status( 'noreceipt', $order_data['order_status'] ) ) {
866 $payment_detail = "\n" . sprintf( __( 'Payment is valid for %s days from the date of order.', 'usces' ), $usces->options['tatransfer_limit'] );
867 $str = apply_filters( 'usces_filter_transferAdvance_payment_limit_confirm', $payment_detail, $usces->options['tatransfer_limit'] );
868 }
869 break;
870
871 case 'transferDeferred':
872 if ( ! empty( $usces->options['tatransfer_limit'] ) && $usces->is_status( 'noreceipt', $order_data['order_status'] ) ) {
873 $payment_detail = "\n" . sprintf( __( 'Payment is valid for %s days from after the item arrives.', 'usces' ), $usces->options['tatransfer_limit'] );
874 $str = apply_filters( 'usces_filter_transferDeferred_payment_limit_confirm', $payment_detail, $usces->options['tatransfer_limit'] );
875 }
876 break;
877 }
878
879 $str = apply_filters( 'usces_filter_payment_detail_confirm', $str, $order_data );
880 return $str;
881 }
882
883 /**
884 * Check custom order
885 *
886 * @param string $mes Message.
887 * @return string
888 */
889 function usces_filter_delivery_check_custom_order( $mes ) {
890
891 $meta = usces_has_custom_field_meta( 'order' );
892 if ( is_array( $meta ) ) {
893 unset( $_SESSION['usces_entry']['custom_order'] );
894 if ( isset( $_POST['custom_order'] ) ) {
895 foreach ( $_POST['custom_order'] as $key => $value ) {
896 if ( ! isset( $meta[ $key ] ) ) {
897 continue;
898 }
899 if ( is_array( $value ) ) {
900 foreach ( $value as $k => $v ) {
901 $_SESSION['usces_entry']['custom_order'][ $key ][ trim( $v ) ] = trim( $v );
902 }
903 } else {
904 $_SESSION['usces_entry']['custom_order'][ $key ] = trim( $value );
905 }
906 }
907 }
908 }
909
910 foreach ( $meta as $key => $entry ) {
911 $essential = $entry['essential'];
912 if ( 1 === (int) $essential ) {
913 $name = $entry['name'];
914 $means = $entry['means'];
915 if ( 2 === (int) $means ) { /* Text */
916 if ( isset( $_POST['custom_order'][ $key ] ) && WCUtils::is_blank( $_POST['custom_order'][ $key ] ) ) {
917 $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
918 }
919 } else {
920 if ( ! isset( $_POST['custom_order'][ $key ] ) || '#NONE#' == $_POST['custom_order'][ $key ] ) {
921 $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
922 }
923 }
924 }
925 }
926
927 return $mes;
928 }
929
930 /**
931 * Check custom customer
932 *
933 * @param string $mes Message.
934 * @return string
935 */
936 function usces_filter_customer_check_custom_customer( $mes ) {
937
938 $meta = usces_has_custom_field_meta( 'customer' );
939 foreach ( $meta as $key => $entry ) {
940 $essential = $entry['essential'];
941 if ( 1 === (int) $essential ) {
942 $name = $entry['name'];
943 $means = $entry['means'];
944 if ( 2 === (int) $means ) { /* Text */
945 if ( WCUtils::is_blank( $_POST['custom_customer'][ $key ] ) ) {
946 $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
947 }
948 } else {
949 if ( ! isset( $_POST['custom_customer'][ $key ] ) || '#NONE#' == $_POST['custom_customer'][ $key ] ) {
950 $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
951 }
952 }
953 }
954 }
955
956 return $mes;
957 }
958
959 /**
960 * Check custom delivery
961 *
962 * @param string $mes Message.
963 * @return string
964 */
965 function usces_filter_delivery_check_custom_delivery( $mes ) {
966
967 if ( isset( $_POST['delivery']['delivery_flag'] ) && 1 === (int) $_POST['delivery']['delivery_flag'] ) {
968 $meta = usces_has_custom_field_meta( 'delivery' );
969 foreach ( $meta as $key => $entry ) {
970 $essential = $entry['essential'];
971 if ( 1 === (int) $essential ) {
972 $name = $entry['name'];
973 $means = $entry['means'];
974 if ( 2 === (int) $means ) { /* Text */
975 if ( WCUtils::is_blank( $_POST['custom_delivery'][ $key ] ) ) {
976 $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
977 }
978 } else {
979 if ( ! isset( $_POST['custom_delivery'][ $key ] ) || '#NONE#' == $_POST['custom_delivery'][ $key ] ) {
980 $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
981 }
982 }
983 }
984 }
985 }
986
987 return $mes;
988 }
989
990 /**
991 * Check custom member
992 *
993 * @param string $mes Message.
994 * @return string
995 */
996 function usces_filter_member_check_custom_member( $mes ) {
997
998 unset( $_SESSION['usces_member']['custom_member'] );
999 if ( isset( $_POST['custom_member'] ) ) {
1000 foreach ( $_POST['custom_member'] as $key => $value ) {
1001 if ( is_array( $value ) ) {
1002 foreach ( $value as $k => $v ) {
1003 $_SESSION['usces_member']['custom_member'][ $key ][ trim( $v ) ] = trim( $v );
1004 }
1005 } else {
1006 $_SESSION['usces_member']['custom_member'][ $key ] = trim( $value );
1007 }
1008 }
1009 }
1010
1011 $meta = usces_has_custom_field_meta( 'member' );
1012 foreach ( $meta as $key => $entry ) {
1013 $essential = $entry['essential'];
1014 if ( 1 === (int) $essential ) {
1015 $name = $entry['name'];
1016 $means = $entry['means'];
1017 if ( 2 === (int) $means ) { /* Text */
1018 if ( WCUtils::is_blank( $_POST['custom_member'][ $key ] ) ) {
1019 $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
1020 }
1021 } else {
1022 if ( ! isset( $_POST['custom_member'][ $key ] ) || '#NONE#' == $_POST['custom_member'][ $key ] ) {
1023 $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
1024 }
1025 }
1026 }
1027 }
1028
1029 return $mes;
1030 }
1031
1032 /**
1033 * Dashboard widget
1034 */
1035 function usces_dashboard_setup() {
1036 wp_add_dashboard_widget( 'usces_db_widget', 'Welcart Information', 'usces_db_widget' );
1037 }
1038
1039 /**
1040 * Admin login
1041 *
1042 * @return void
1043 */
1044 function usces_admin_login_head() {
1045 ?>
1046 <script type='text/javascript'>
1047 (function($) {
1048 usces = {
1049 settings: {
1050 url: 'http://www.welcart.com/varch/varch.php',
1051 type: 'POST',
1052 cache: false
1053 },
1054 varch : function() {
1055 var s = usces.settings;
1056 s.data = "action=varch_ajax&ID=usces_varch&ver=" + <?php wel_esc_script_e( $_SERVER['HTTP_HOST'] ); ?>;
1057 $.ajax( s );
1058 return false;
1059 }
1060 };
1061 usces.varch();
1062 })(jQuery);
1063 </script>
1064 <?php
1065 }
1066
1067 /**
1068 * Entity decode
1069 *
1070 * @param string $str Text.
1071 * @param string $ftype File extension.
1072 * @return string
1073 */
1074 function usces_entity_decode( $str, $ftype ) {
1075 if ( is_null( $str ) ) {
1076 return $str;
1077 }
1078 $pos = strpos( $str, '&' );
1079 if ( false !== $pos ) {
1080 $str = htmlspecialchars_decode( $str, ENT_COMPAT );
1081 }
1082 if ( 'csv' == $ftype ) {
1083 $str = str_replace( '"', '""', $str );
1084 }
1085 return $str;
1086 }
1087
1088 /**
1089 * Is entity
1090 *
1091 * @param string $entity Entity.
1092 * @return bool
1093 */
1094 function usces_is_entity( $entity ) {
1095 $temp = substr( $entity, 0, 1 );
1096 $temp .= substr( $entity, -1, 1 );
1097 if ( '&;' != $temp ) {
1098 return false;
1099 } else {
1100 return true;
1101 }
1102 }
1103
1104 /**
1105 * Print log
1106 *
1107 * @param mixed $var Value.
1108 */
1109 function usces_p( $var ) {
1110 echo '<pre>' . print_r( $var, true ) . '</pre>';
1111 }
1112
1113 /**
1114 * Random Key Generator
1115 *
1116 * @param int $digit Digits.
1117 * @return string
1118 */
1119 function usces_get_key( $digit ) {
1120 $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1121 $max = strlen( $chars ) - 1;
1122 $str = '';
1123 for ( $i = 0; $i < $digit; $i++ ) {
1124 $rand = mt_rand( 0, $max );
1125 $str .= $chars[ $rand ];
1126 }
1127 return $str;
1128 }
1129
1130 /**
1131 * Welcart.com connection
1132 *
1133 * @param array $params Parameters.
1134 */
1135 function usces_wcsite_connection( $params ) {
1136 if ( extension_loaded( 'curl' ) ) {
1137 $conn = curl_init();
1138 curl_setopt( $conn, CURLOPT_CONNECTTIMEOUT, 2 );
1139 curl_setopt( $conn, CURLOPT_FOLLOWLOCATION, 1 );
1140 curl_setopt( $conn, CURLOPT_RETURNTRANSFER, 1 );
1141 curl_setopt( $conn, CURLOPT_HEADER, true );
1142 $user_agent = 'Welcart ' . USCES_VERSION;
1143 curl_setopt( $conn, CURLOPT_USERAGENT, $user_agent );
1144 $url = 'http://endpoint.welcart.org/point1/';
1145 curl_setopt( $conn, CURLOPT_URL, $url );
1146 curl_setopt( $conn, CURLOPT_POST, true );
1147 curl_setopt( $conn, CURLOPT_POSTFIELDS, $params );
1148 $response = curl_exec( $conn );
1149 unset( $conn );
1150 }
1151 }
1152
1153 /**
1154 * Daily event
1155 */
1156 function usces_schedule_event() {
1157 $gmt_offset = get_option( 'gmt_offset' );
1158 $now = current_time( 'timestamp', 0 );
1159 $timestamp = mktime( 3, 0, 0, date( 'n', $now ), date( 'j', $now ), date( 'Y', $now ) ) - ( $gmt_offset * 3600 );
1160 wp_schedule_event( $timestamp, 'daily', 'wc_cron' );
1161 }
1162
1163 /**
1164 * Weekly event
1165 */
1166 function usces_wevent() {
1167 if ( wp_next_scheduled( 'wc_cron_w' ) ) {
1168 return;
1169 }
1170 $now = current_time( 'timestamp' );
1171 wp_schedule_event( $now, 'weekly', 'wc_cron_w' );
1172 }
1173
1174 /**
1175 * Cron execution
1176 */
1177 function usces_cronw_do() {
1178 usces_wcsite_activate();
1179 }
1180
1181 /**
1182 * Cron execution
1183 */
1184 function usces_cron_do() {
1185 usces_clearup_lostkey();
1186 usces_clearup_acting_data();
1187 usces_clearup_acting_log();
1188 Log_List_Table::clearup();
1189 wel_clearup_log_credit_input();
1190 }
1191
1192 /**
1193 * Linefeed code conversion
1194 *
1195 * @param string $value Text.
1196 * @return string
1197 */
1198 function usces_change_line_break( $value ) {
1199 $cr = array( "\r\n", "\r" );
1200 $value = trim( $value );
1201 $value = str_replace( $cr, "\n", $value );
1202 return $value;
1203 }
1204
1205 /**
1206 * 荷物追跡・問い合わせURL
1207 *
1208 * @param string $delivery_company �
1209 �送会社名.
1210 * @param string $tracking_number 追跡番号(カンマ区切りで複数).
1211 */
1212 function usces_get_delivery_company_url( $delivery_company, $tracking_number ) {
1213 $url = '';
1214 switch ( $delivery_company ) {
1215 case 'クロネコヤマト':
1216 case 'ヤマト運輸':
1217 case 'クロネコメール便':
1218 if ( ! empty( $tracking_number ) ) {
1219 if ( false !== strpos( $tracking_number, ',' ) ) {
1220 $br = ( usces_is_html_mail() ) ? '<br>' : "\r\n";
1221 $number = explode( ',', $tracking_number );
1222 foreach ( $number as $n ) {
1223 $pno = str_replace( '-', '', $n );
1224 $url .= 'https://member.kms.kuronekoyamato.co.jp/parcel/detail?pno=' . $pno . $br;
1225 }
1226 } else {
1227 $pno = str_replace( '-', '', $tracking_number );
1228 $url = 'https://member.kms.kuronekoyamato.co.jp/parcel/detail?pno=' . $pno;
1229 }
1230 } else {
1231 $url = 'https://toi.kuronekoyamato.co.jp/cgi-bin/tneko';
1232 }
1233 break;
1234
1235 case '佐川急便':
1236 if ( ! empty( $tracking_number ) ) {
1237 if ( false !== strpos( $tracking_number, ',' ) ) {
1238 $br = ( usces_is_html_mail() ) ? '<br>' : "\r\n";
1239 $number = explode( ',', $tracking_number );
1240 foreach ( $number as $n ) {
1241 $url .= 'https://k2k.sagawa-exp.co.jp/p/web/okurijosearch.do?okurijoNo=' . $n . $br;
1242 }
1243 } else {
1244 $url = 'https://k2k.sagawa-exp.co.jp/p/web/okurijosearch.do?okurijoNo=' . $tracking_number;
1245 }
1246 } else {
1247 $url = 'https://k2k.sagawa-exp.co.jp/p/sagawa/web/okurijoinput.jsp';
1248 }
1249 break;
1250
1251 case '日本郵便':
1252 case 'ゆうパック':
1253 case 'クリックポスト':
1254 case 'レターパック':
1255 if ( ! empty( $tracking_number ) ) {
1256 if ( false !== strpos( $tracking_number, ',' ) ) {
1257 $number = array_slice( explode( ',', $tracking_number ), 0, 10 );
1258 $no = '';
1259 for ( $i = 1; $i <= 10; $i++ ) {
1260 $n = isset( $number[ $i - 1 ] ) ? trim( $number[ $i - 1 ] ) : '';
1261 $no .= 'requestNo' . $i . '=' . $n . '&';
1262 }
1263 $url = 'https://trackings.post.japanpost.jp/services/srv/search?' . $no;
1264 } else {
1265 $url = 'https://trackings.post.japanpost.jp/services/srv/search?requestNo1=' . $tracking_number . '&';
1266 }
1267 $url .= 'search.x=66&search.y=25&startingUrlPatten=&locale=ja';
1268 } else {
1269 $url = 'https://trackings.post.japanpost.jp/services/srv/search/';
1270 }
1271 break;
1272
1273 case '日本通運':
1274 $url = 'https://www.nipponexpress.com/jp/ja/tracking/';
1275 break;
1276
1277 case '西濃運輸':
1278 case '西武運輸':
1279 if ( ! empty( $tracking_number ) ) {
1280 if ( false !== strpos( $tracking_number, ',' ) ) {
1281 $number = explode( ',', $tracking_number );
1282 $no = '';
1283 $i = 1;
1284 foreach ( $number as $n ) {
1285 $no .= 'GNPNO' . $i . '=' . $n . '&';
1286 $i++;
1287 }
1288 $url = 'https://track.seino.co.jp/cgi-bin/gnpquery.pgm?' . rtrim( $no, '&' );
1289 } else {
1290 $url = 'https://track.seino.co.jp/cgi-bin/gnpquery.pgm?GNPNO1=' . $tracking_number;
1291 }
1292 } else {
1293 $url = 'https://track.seino.co.jp/kamotsu/GempyoNoShokai.do';
1294 }
1295 break;
1296
1297 case '福山通運':
1298 if ( ! empty( $tracking_number ) ) {
1299 if ( false !== strpos( $tracking_number, ',' ) ) {
1300 $br = ( usces_is_html_mail() ) ? '<br>' : "\r\n";
1301 $number = explode( ',', $tracking_number );
1302 foreach ( $number as $n ) {
1303 $url .= 'https://corp.fukutsu.co.jp/situation/tracking_no_hunt/' . $n . $br;
1304 }
1305 } else {
1306 $url = 'https://corp.fukutsu.co.jp/situation/tracking_no_hunt/' . $tracking_number;
1307 }
1308 } else {
1309 $url = 'https://corp.fukutsu.co.jp/situation/tracking_no';
1310 }
1311 break;
1312
1313 case '名鉄運輸':
1314 $url = 'https://ap.meitetsuunyu.co.jp/webtrace/webtsuiseki/webtsuiseki.aspx';
1315 break;
1316
1317 case '新潟運輸':
1318 $url = 'https://www2.nuis.co.jp/kzz80011.htm';
1319 break;
1320
1321 case 'トナミ運輸':
1322 $url = 'https://trc1.tonami.co.jp/trc/search3/excSearch3';
1323 break;
1324
1325 case '第一貨物':
1326 $url = 'https://www.daiichi-kamotsu.co.jp/chase/contact_num/';
1327 break;
1328
1329 case '飛騨倉庫運輸':
1330 case '濃飛倉庫運輸':
1331 $url = 'https://www.nohhi.co.jp/support/';
1332 break;
1333
1334 default:
1335 $url = '';
1336 }
1337 $url = apply_filters( 'usces_filter_delivery_company_url', $url, $delivery_company, $tracking_number );
1338 return $url;
1339 }
1340
1341 /**
1342 * Serialization
1343 *
1344 * @param mixed $data Data.
1345 * @return string
1346 */
1347 function usces_serialize( $data ) {
1348 if ( ! is_array( $data ) ) {
1349 return $data;
1350 }
1351 return json_encode( $data );
1352 }
1353
1354 /**
1355 * Unserialize
1356 *
1357 * @param mixed $data Data.
1358 * @return array
1359 */
1360 function usces_unserialize( $data ) {
1361 if ( is_array( $data ) || is_null( $data ) ) {
1362 return $data;
1363 }
1364 return @json_decode( $data, true );
1365 }
1366
1367 /**
1368 * Check trans_id
1369 *
1370 * @param string $key Key.
1371 * @return bool
1372 */
1373 function usces_check_trans_id( $key ) {
1374 global $wpdb;
1375
1376 $access_table_name = $wpdb->prefix . 'usces_access';
1377 $query = $wpdb->prepare( "SELECT ID FROM $access_table_name WHERE acc_key = %s AND acc_str1 = %s", 'wc_trans_id', $key );
1378 $id = $wpdb->get_var( $query );
1379 return ( NULL != $id ) ? false : true;
1380 }
1381
1382 /**
1383 * Save trans_id
1384 *
1385 * @param string $key Key.
1386 * @param string $acting Acting type.
1387 * @return bool
1388 */
1389 function usces_save_trans_id( $key, $acting = 'acting' ) {
1390 global $wpdb;
1391
1392 $access_table_name = $wpdb->prefix . 'usces_access';
1393 $query = $wpdb->prepare( "INSERT INTO $access_table_name ( acc_key, acc_type, acc_date, acc_str1 ) VALUES( %s, %s, NOW(), %s )", 'wc_trans_id', $acting, $key );
1394 $res = $wpdb->query( $query );
1395 return $res;
1396 }
1397
1398 /**
1399 * Is date
1400 *
1401 * @param mixed $date Date.
1402 * @return bool
1403 */
1404 function usces_is_date( $date ) {
1405
1406 if ( empty( $date ) ) {
1407 return false;
1408 }
1409
1410 try {
1411 new DateTime( $date );
1412 list( $year, $month, $day ) = explode( '-', $date );
1413 $res = checkdate( (int) $month, (int) $day, (int) $year );
1414 return $res;
1415 } catch ( Exception $e ) {
1416 return false;
1417 }
1418 }
1419
1420 /**
1421 * Payment service suspended
1422 */
1423 function usces_payment_service_suspended() {
1424 $payment_method = usces_get_system_option( 'usces_payment_method', 'sort' );
1425 foreach ( $payment_method as $payment ) {
1426 if ( 'acting_yahoo_wallet' == $payment['settlement'] && 'activate' == $payment['use'] ) {
1427 $payment['use'] = 'deactivate';
1428 usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1429 } elseif ( 'acting_veritrans_card' == $payment['settlement'] && 'activate' == $payment['use'] ) {
1430 $payment['use'] = 'deactivate';
1431 usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1432 } elseif ( 'acting_veritrans_conv' == $payment['settlement'] && 'activate' == $payment['use'] ) {
1433 $payment['use'] = 'deactivate';
1434 usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1435 }
1436 }
1437 $settlement_selected = get_option( 'usces_settlement_selected', array() );
1438 if ( is_array( $settlement_selected ) && 0 < count( $settlement_selected ) ) {
1439 $settlement_selected = array_diff( $settlement_selected, array( 'yahoo', 'veritrans' ) );
1440 $settlement_selected = array_values( $settlement_selected );
1441 update_option( 'usces_settlement_selected', $settlement_selected );
1442 }
1443 $available_settlement = get_option( 'usces_available_settlement', array() );
1444 if ( is_array( $available_settlement ) && 0 < count( $available_settlement ) ) {
1445 $available_settlement = array_diff( $available_settlement, array( 'Yahoo!ウォレット', 'ベリトランス Air-Web' ) );
1446 update_option( 'usces_available_settlement', $available_settlement );
1447 }
1448 }
1449
1450 /**
1451 * Whether the file is reserved.
1452 *
1453 * @param string $file_path File name.
1454 * @param int $dir 0:welcart-uptemp, 1:usces_logs.
1455 * @return boolean $res True if reserved, false otherwise.
1456 */
1457 function usces_is_reserved_file( $file_path, $dir = 0 ) {
1458
1459 $real_file_path = realpath( $file_path );
1460 $real_base_path = ( 1 === $dir ) ? realpath( USCES_WP_CONTENT_DIR . '/uploads/usces_logs' ) . DIRECTORY_SEPARATOR : realpath( WP_CONTENT_DIR . USCES_UPLOAD_TEMP ) . DIRECTORY_SEPARATOR;
1461 if ( false === $real_file_path || 0 !== strpos( $real_file_path, $real_base_path ) ) {
1462 // Traversal attempt.
1463 return false;
1464 }
1465
1466 $reserved_file = array(
1467 'progress.txt',
1468 'log.txt',
1469 'db-progress.txt',
1470 'db-log.txt',
1471 'member_login_failed.log',
1472 'ip_addresses_blocked.log',
1473 );
1474
1475 $path_parts = pathinfo( $file_path );
1476 if ( in_array( $path_parts['basename'], $reserved_file, true ) ) {
1477 $res = true;
1478 } else {
1479 $res = false;
1480 }
1481
1482 return $res;
1483 }
1484
1485 /**
1486 * Whether the current page is a cart page.
1487 *
1488 * @return boolean True if cart page, false other page.
1489 */
1490 function wel_is_cart_page() {
1491 global $usces;
1492 $request_uri = ( ! isset( $_SERVER['REQUEST_URI'] ) || empty( $_SERVER['REQUEST_URI'] ) ) ? '' : $_SERVER['REQUEST_URI'];
1493 return $usces->is_cart_page( $request_uri );
1494 }
1495
1496 /**
1497 * Whether the current page is a member page.
1498 *
1499 * @return boolean True if member page, false other page.
1500 */
1501 function wel_is_member_page() {
1502 global $usces;
1503 $request_uri = ( ! isset( $_SERVER['REQUEST_URI'] ) || empty( $_SERVER['REQUEST_URI'] ) ) ? '' : $_SERVER['REQUEST_URI'];
1504 return $usces->is_member_page( $request_uri );
1505 }
1506
1507 /**
1508 * Leave the old function name, assuming customization.
1509 *
1510 * @param string $str Text.
1511 * @return string
1512 */
1513 function usces_remove_script( $str ) {
1514 return wel_esc_script( $str );
1515 }
1516
1517 /**
1518 * Remove script tag
1519 *
1520 * @param string $str Text.
1521 * @return string
1522 */
1523 function wel_esc_script( $str ) {
1524
1525 if ( empty( $str ) ) {
1526 return $str;
1527 }
1528
1529 $pattern = array(
1530 '/<script\b[^>]*>/i',
1531 '/<\/script>/i',
1532 );
1533
1534 $replacement = array(
1535 '&lt;script&gt;',
1536 '&lt;/script&gt;',
1537 );
1538
1539 $str = preg_replace( $pattern, $replacement, $str );
1540 $str = preg_replace( '/<([^>]+)\s+onerror\s*=\s*[^>]*?>/i', '<$1>', $str );
1541 $str = preg_replace( '/=\s*alert\s*\(/i', '=', $str );
1542 $str = preg_replace( '/<([^>]+)\s+on\w+\s*=\s*(?!["\'])([^>]*?)>/i', '<$1$2>', $str );
1543
1544 return $str;
1545 }
1546
1547 /**
1548 * Escape and Echo script tag
1549 *
1550 * @param string $str Text.
1551 */
1552 function wel_esc_script_e( $str ) {
1553
1554 if ( empty( $str ) ) {
1555 return;
1556 }
1557
1558 $pattern = array(
1559 '/<script\b[^>]*>/i',
1560 '/<\/script>/i',
1561 );
1562
1563 $replacement = array(
1564 '&lt;script&gt;',
1565 '&lt;/script&gt;',
1566 );
1567
1568 $str = preg_replace( $pattern, $replacement, $str );
1569 $str = preg_replace( '/<([^>]+)\s+onerror\s*=\s*[^>]*?>/i', '<$1>', $str );
1570 $str = preg_replace( '/=\s*alert\s*\(/i', '=', $str );
1571 $str = preg_replace( '/<([^>]+)\s+on\w+\s*=\s*(?!["\'])([^>]*?)>/i', '<$1$2>', $str );
1572
1573 echo $str; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1574 }
1575
1576 /**
1577 * Object for filter_input_array_recursive().
1578 */
1579 class FilterObject {
1580
1581 private $filter;
1582 private $options;
1583
1584 /**
1585 * Constructor.
1586 *
1587 * @param int $filter same as ones for filter_input().
1588 * @param mixed $options same as ones for filter_input().
1589 */
1590 public function __construct( $filter = FILTER_DEFAULT, $options = FILTER_REQUIRE_SCALAR ) {
1591 $this->filter = $filter;
1592 $this->options = $options;
1593 }
1594
1595 public function getFilter() {
1596 return $this->filter;
1597 }
1598
1599 public function getOptions() {
1600 return $this->options;
1601 }
1602
1603 }
1604
1605 /**
1606 * Apply filter_input() recursively.
1607 *
1608 * @param int $type INPUT_GET, INPUT_POST, INPUT_COOKIE or INPUT_REQUEST.
1609 * @param array $filters Multi-demensional array,
1610 * which contains FilterObject for each leaf.
1611 * @return array
1612 */
1613 function filter_input_array_recursive( $type, array $filters ) {
1614 static $recursive_static;
1615 static $flag_match;
1616 static $is_not_array;
1617 static $filter_array;
1618 static $types;
1619 if ( ! $flag_match ) {
1620 /* initialize static variables */
1621 $types = array(
1622 'INPUT_GET' => $_GET,
1623 'INPUT_POST' => $_POST,
1624 'INPUT_COOKIE' => $_COOKIE,
1625 'INPUT_REQUEST' => $_REQUEST,
1626 );
1627 $flag_match = function( $v, $f ) {
1628 return (int) ( isset( $v['flags'] ) ? $v['flags'] : $v ) & $f;
1629 };
1630 $is_not_array = function( $v ) {
1631 return ! is_array( $v );
1632 };
1633 $filter_array = function( $v ) {
1634 return ! is_array( $v ) ? $v : false;
1635 };
1636 }
1637 $recursive = $recursive_static;
1638 if ( ! $recursive ) {
1639 /* only for first loop */
1640 $type = (int) $type;
1641 if ( ! isset( $types[ $type ] ) ) {
1642 throw new \InvalidArgumentException(
1643 'unknown super global var type'
1644 );
1645 }
1646 $var = $types[ $type ];
1647 $recursive_static = true;
1648 } else {
1649 /* after first loop */
1650 $var = $type;
1651 }
1652 $ret = array();
1653 foreach ( $filters as $key => $value ) {
1654 if ( is_array( $value ) ) {
1655 // apply child filters.
1656 $ret[ $key ] = filter_input_array_recursive(
1657 isset( $var[ $key ] ) ? $var[ $key ] : array(),
1658 $value
1659 );
1660 } else {
1661 if ( ! ( $value instanceof FilterObject ) ) {
1662 // create default FilterObject for invalid leaf.
1663 $value = new FilterObject;
1664 }
1665 $filter = $value->getFilter();
1666 $options = $value->getOptions();
1667 // check if key exists...
1668 // true -> apply filter_var() with supplied filter and options.
1669 // false -> regard as null.
1670 try {
1671 $ret[ $key ] =
1672 isset( $var[ $key ] ) ?
1673 filter_var( $var[ $key ], $filter, $options ) :
1674 null
1675 ;
1676 } catch ( Exception $e ) {
1677 $recursive_static = false;
1678 throw $e;
1679 }
1680 if ( $flag_match( $options, FILTER_FORCE_ARRAY | FILTER_REQUIRE_ARRAY ) ) {
1681 // differently from filter_input(),
1682 // this function prevent unexpected non-array value
1683 // or multi-demensional array.
1684 if ( $flag_match( $options, FILTER_FORCE_ARRAY ) ) {
1685 // eliminate arrays.
1686 $ret[ $key ] = array_filter( (array) $ret[ $key ], $is_not_array );
1687 } else {
1688 // change arrays into false.
1689 $ret[ $key ] = array_map( $filter_array, (array) $ret[ $key ] );
1690 }
1691 }
1692 }
1693 }
1694 if ( ! $recursive ) {
1695 /* only for first loop */
1696 $recursive_static = false;
1697 }
1698 return $ret;
1699 }
1700
1701 /**
1702 * Remove the path from the uploaded file name and perform escape processing.
1703 *
1704 * @param string $file_name File Name.
1705 *
1706 * @return string
1707 */
1708 function wel_esc_upload_file_name( $file_name ) {
1709 $filenames = explode( '/', urldecode( $file_name ) );
1710 end( $filenames );
1711
1712 return wel_esc_script( $filenames[0] );
1713 }
1714
1715 /**
1716 * If the input data is a serialized object, sanitize it.
1717 *
1718 * @param string $data text.
1719 *
1720 * @return mixed|object|string
1721 */
1722 function wel_safe_text_serialize( $data ) {
1723 if ( ! is_serialized( $data ) ) {
1724 return $data; // シリアライズされていないなら、そのまま返す
1725 }
1726
1727 $result = unserialize( $data, [ 'allowed_classes' => false ] ); // オブジェクトを展開しない
1728
1729 // �
1730 �列またはオブジェクトの場合、再帰的に無害化
1731 if ( is_array( $result ) ) {
1732 array_walk_recursive( $result, function ( &$value ) {
1733 $value = sanitize_text_field( $value ); // 文字列を無害化
1734 } );
1735 } elseif ( is_object( $result ) ) {
1736 return sanitize_text_field( $result );
1737 } else {
1738 return sanitize_text_field( $result );
1739 }
1740
1741 return maybe_serialize( $result );
1742 }
1743
1744 /**
1745 * Safely unserialize a value without restoring PHP objects.
1746 * Drop-in replacement for maybe_unserialize() that blocks PHP Object Injection.
1747 *
1748 * unserialize() with allowed_classes=false still returns a __PHP_Incomplete_Class
1749 * stand-in object for any object it encounters (it just refuses to instantiate the
1750 * real class). That stand-in has no __toString(), so callers that echo/concatenate
1751 * the result would still hit a fatal error on poisoned data. wel_strip_unserialized_objects()
1752 * replaces any such object with an empty string so the result is always safe to display.
1753 *
1754 * @param mixed $data Possibly serialized data.
1755 *
1756 * @return mixed
1757 */
1758 function wel_safe_maybe_unserialize( $data ) {
1759 if ( ! is_serialized( $data ) ) {
1760 return $data;
1761 }
1762
1763 $result = @unserialize( $data, array( 'allowed_classes' => false ) );
1764
1765 return wel_strip_unserialized_objects( $result );
1766 }
1767
1768 /**
1769 * Safely unserialize a value without restoring PHP objects.
1770 * Drop-in replacement for a bare unserialize() call.
1771 *
1772 * Unlike wel_safe_maybe_unserialize(), this keeps the semantics of unserialize()
1773 * itself: a value that is not valid serialized data yields false rather than being
1774 * returned untouched. Use this when replacing an existing unserialize() call so the
1775 * surrounding code keeps behaving the same way on malformed input.
1776 *
1777 * @param mixed $data Serialized data.
1778 *
1779 * @return mixed False if the data cannot be unserialized.
1780 */
1781 function wel_safe_unserialize( $data ) {
1782 $result = @unserialize( $data, array( 'allowed_classes' => false ) );
1783
1784 return wel_strip_unserialized_objects( $result );
1785 }
1786
1787 /**
1788 * Recursively replace any object found in a value with an empty string.
1789 *
1790 * @param mixed $value Value to sanitize.
1791 *
1792 * @return mixed
1793 */
1794 function wel_strip_unserialized_objects( $value ) {
1795 if ( is_object( $value ) ) {
1796 return '';
1797 }
1798
1799 if ( is_array( $value ) ) {
1800 foreach ( $value as $key => $item ) {
1801 $value[ $key ] = wel_strip_unserialized_objects( $item );
1802 }
1803 }
1804
1805 return $value;
1806 }
1807