PluginProbe
Welcart e-Commerce / 2.11.34
Welcart e-Commerce v2.11.34
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.34, at functions/utility.php

1,739 lines 49.5 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 ( is_array( $value ) ) {
897 foreach ( $value as $k => $v ) {
898 $_SESSION['usces_entry']['custom_order'][ $key ][ trim( $v ) ] = trim( $v );
899 }
900 } else {
901 $_SESSION['usces_entry']['custom_order'][ $key ] = trim( $value );
902 }
903 }
904 }
905 }
906
907 foreach ( $meta as $key => $entry ) {
908 $essential = $entry['essential'];
909 if ( 1 === (int) $essential ) {
910 $name = $entry['name'];
911 $means = $entry['means'];
912 if ( 2 === (int) $means ) { /* Text */
913 if ( isset( $_POST['custom_order'][ $key ] ) && WCUtils::is_blank( $_POST['custom_order'][ $key ] ) ) {
914 $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
915 }
916 } else {
917 if ( ! isset( $_POST['custom_order'][ $key ] ) || '#NONE#' == $_POST['custom_order'][ $key ] ) {
918 $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
919 }
920 }
921 }
922 }
923
924 return $mes;
925 }
926
927 /**
928 * Check custom customer
929 *
930 * @param string $mes Message.
931 * @return string
932 */
933 function usces_filter_customer_check_custom_customer( $mes ) {
934
935 $meta = usces_has_custom_field_meta( 'customer' );
936 foreach ( $meta as $key => $entry ) {
937 $essential = $entry['essential'];
938 if ( 1 === (int) $essential ) {
939 $name = $entry['name'];
940 $means = $entry['means'];
941 if ( 2 === (int) $means ) { /* Text */
942 if ( WCUtils::is_blank( $_POST['custom_customer'][ $key ] ) ) {
943 $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
944 }
945 } else {
946 if ( ! isset( $_POST['custom_customer'][ $key ] ) || '#NONE#' == $_POST['custom_customer'][ $key ] ) {
947 $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
948 }
949 }
950 }
951 }
952
953 return $mes;
954 }
955
956 /**
957 * Check custom delivery
958 *
959 * @param string $mes Message.
960 * @return string
961 */
962 function usces_filter_delivery_check_custom_delivery( $mes ) {
963
964 if ( isset( $_POST['delivery']['delivery_flag'] ) && 1 === (int) $_POST['delivery']['delivery_flag'] ) {
965 $meta = usces_has_custom_field_meta( 'delivery' );
966 foreach ( $meta as $key => $entry ) {
967 $essential = $entry['essential'];
968 if ( 1 === (int) $essential ) {
969 $name = $entry['name'];
970 $means = $entry['means'];
971 if ( 2 === (int) $means ) { /* Text */
972 if ( WCUtils::is_blank( $_POST['custom_delivery'][ $key ] ) ) {
973 $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
974 }
975 } else {
976 if ( ! isset( $_POST['custom_delivery'][ $key ] ) || '#NONE#' == $_POST['custom_delivery'][ $key ] ) {
977 $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
978 }
979 }
980 }
981 }
982 }
983
984 return $mes;
985 }
986
987 /**
988 * Check custom member
989 *
990 * @param string $mes Message.
991 * @return string
992 */
993 function usces_filter_member_check_custom_member( $mes ) {
994
995 unset( $_SESSION['usces_member']['custom_member'] );
996 if ( isset( $_POST['custom_member'] ) ) {
997 foreach ( $_POST['custom_member'] as $key => $value ) {
998 if ( is_array( $value ) ) {
999 foreach ( $value as $k => $v ) {
1000 $_SESSION['usces_member']['custom_member'][ $key ][ trim( $v ) ] = trim( $v );
1001 }
1002 } else {
1003 $_SESSION['usces_member']['custom_member'][ $key ] = trim( $value );
1004 }
1005 }
1006 }
1007
1008 $meta = usces_has_custom_field_meta( 'member' );
1009 foreach ( $meta as $key => $entry ) {
1010 $essential = $entry['essential'];
1011 if ( 1 === (int) $essential ) {
1012 $name = $entry['name'];
1013 $means = $entry['means'];
1014 if ( 2 === (int) $means ) { /* Text */
1015 if ( WCUtils::is_blank( $_POST['custom_member'][ $key ] ) ) {
1016 $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
1017 }
1018 } else {
1019 if ( ! isset( $_POST['custom_member'][ $key ] ) || '#NONE#' == $_POST['custom_member'][ $key ] ) {
1020 $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
1021 }
1022 }
1023 }
1024 }
1025
1026 return $mes;
1027 }
1028
1029 /**
1030 * Dashboard widget
1031 */
1032 function usces_dashboard_setup() {
1033 wp_add_dashboard_widget( 'usces_db_widget', 'Welcart Information', 'usces_db_widget' );
1034 }
1035
1036 /**
1037 * Admin login
1038 *
1039 * @return void
1040 */
1041 function usces_admin_login_head() {
1042 ?>
1043 <script type='text/javascript'>
1044 (function($) {
1045 usces = {
1046 settings: {
1047 url: 'http://www.welcart.com/varch/varch.php',
1048 type: 'POST',
1049 cache: false
1050 },
1051 varch : function() {
1052 var s = usces.settings;
1053 s.data = "action=varch_ajax&ID=usces_varch&ver=" + <?php wel_esc_script_e( $_SERVER['HTTP_HOST'] ); ?>;
1054 $.ajax( s );
1055 return false;
1056 }
1057 };
1058 usces.varch();
1059 })(jQuery);
1060 </script>
1061 <?php
1062 }
1063
1064 /**
1065 * Entity decode
1066 *
1067 * @param string $str Text.
1068 * @param string $ftype File extension.
1069 * @return string
1070 */
1071 function usces_entity_decode( $str, $ftype ) {
1072 if ( is_null( $str ) ) {
1073 return $str;
1074 }
1075 $pos = strpos( $str, '&' );
1076 if ( false !== $pos ) {
1077 $str = htmlspecialchars_decode( $str, ENT_COMPAT );
1078 }
1079 if ( 'csv' == $ftype ) {
1080 $str = str_replace( '"', '""', $str );
1081 }
1082 return $str;
1083 }
1084
1085 /**
1086 * Is entity
1087 *
1088 * @param string $entity Entity.
1089 * @return bool
1090 */
1091 function usces_is_entity( $entity ) {
1092 $temp = substr( $entity, 0, 1 );
1093 $temp .= substr( $entity, -1, 1 );
1094 if ( '&;' != $temp ) {
1095 return false;
1096 } else {
1097 return true;
1098 }
1099 }
1100
1101 /**
1102 * Print log
1103 *
1104 * @param mixed $var Value.
1105 */
1106 function usces_p( $var ) {
1107 echo '<pre>' . print_r( $var, true ) . '</pre>';
1108 }
1109
1110 /**
1111 * Random Key Generator
1112 *
1113 * @param int $digit Digits.
1114 * @return string
1115 */
1116 function usces_get_key( $digit ) {
1117 $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1118 $max = strlen( $chars ) - 1;
1119 $str = '';
1120 for ( $i = 0; $i < $digit; $i++ ) {
1121 $rand = mt_rand( 0, $max );
1122 $str .= $chars[ $rand ];
1123 }
1124 return $str;
1125 }
1126
1127 /**
1128 * Welcart.com connection
1129 *
1130 * @param array $params Parameters.
1131 */
1132 function usces_wcsite_connection( $params ) {
1133 if ( extension_loaded( 'curl' ) ) {
1134 $conn = curl_init();
1135 curl_setopt( $conn, CURLOPT_CONNECTTIMEOUT, 2 );
1136 curl_setopt( $conn, CURLOPT_FOLLOWLOCATION, 1 );
1137 curl_setopt( $conn, CURLOPT_RETURNTRANSFER, 1 );
1138 curl_setopt( $conn, CURLOPT_HEADER, true );
1139 $user_agent = 'Welcart ' . USCES_VERSION;
1140 curl_setopt( $conn, CURLOPT_USERAGENT, $user_agent );
1141 $url = 'http://endpoint.welcart.org/point1/';
1142 curl_setopt( $conn, CURLOPT_URL, $url );
1143 curl_setopt( $conn, CURLOPT_POST, true );
1144 curl_setopt( $conn, CURLOPT_POSTFIELDS, $params );
1145 $response = curl_exec( $conn );
1146 unset( $conn );
1147 }
1148 }
1149
1150 /**
1151 * Daily event
1152 */
1153 function usces_schedule_event() {
1154 $gmt_offset = get_option( 'gmt_offset' );
1155 $now = current_time( 'timestamp', 0 );
1156 $timestamp = mktime( 3, 0, 0, date( 'n', $now ), date( 'j', $now ), date( 'Y', $now ) ) - ( $gmt_offset * 3600 );
1157 wp_schedule_event( $timestamp, 'daily', 'wc_cron' );
1158 }
1159
1160 /**
1161 * Weekly event
1162 */
1163 function usces_wevent() {
1164 if ( wp_next_scheduled( 'wc_cron_w' ) ) {
1165 return;
1166 }
1167 $now = current_time( 'timestamp' );
1168 wp_schedule_event( $now, 'weekly', 'wc_cron_w' );
1169 }
1170
1171 /**
1172 * Cron execution
1173 */
1174 function usces_cronw_do() {
1175 usces_wcsite_activate();
1176 }
1177
1178 /**
1179 * Cron execution
1180 */
1181 function usces_cron_do() {
1182 usces_clearup_lostkey();
1183 usces_clearup_acting_data();
1184 usces_clearup_acting_log();
1185 Log_List_Table::clearup();
1186 wel_clearup_log_credit_input();
1187 }
1188
1189 /**
1190 * Linefeed code conversion
1191 *
1192 * @param string $value Text.
1193 * @return string
1194 */
1195 function usces_change_line_break( $value ) {
1196 $cr = array( "\r\n", "\r" );
1197 $value = trim( $value );
1198 $value = str_replace( $cr, "\n", $value );
1199 return $value;
1200 }
1201
1202 /**
1203 * 荷物追跡・問い合わせURL
1204 *
1205 * @param string $delivery_company �
1206 �送会社名.
1207 * @param string $tracking_number 追跡番号(カンマ区切りで複数).
1208 */
1209 function usces_get_delivery_company_url( $delivery_company, $tracking_number ) {
1210 $url = '';
1211 switch ( $delivery_company ) {
1212 case 'クロネコヤマト':
1213 case 'ヤマト運輸':
1214 case 'クロネコメール便':
1215 if ( ! empty( $tracking_number ) ) {
1216 if ( false !== strpos( $tracking_number, ',' ) ) {
1217 $br = ( usces_is_html_mail() ) ? '<br>' : "\r\n";
1218 $number = explode( ',', $tracking_number );
1219 foreach ( $number as $n ) {
1220 $pno = str_replace( '-', '', $n );
1221 $url .= 'https://member.kms.kuronekoyamato.co.jp/parcel/detail?pno=' . $pno . $br;
1222 }
1223 } else {
1224 $pno = str_replace( '-', '', $tracking_number );
1225 $url = 'https://member.kms.kuronekoyamato.co.jp/parcel/detail?pno=' . $pno;
1226 }
1227 } else {
1228 $url = 'https://toi.kuronekoyamato.co.jp/cgi-bin/tneko';
1229 }
1230 break;
1231
1232 case '佐川急便':
1233 if ( ! empty( $tracking_number ) ) {
1234 if ( false !== strpos( $tracking_number, ',' ) ) {
1235 $br = ( usces_is_html_mail() ) ? '<br>' : "\r\n";
1236 $number = explode( ',', $tracking_number );
1237 foreach ( $number as $n ) {
1238 $url .= 'https://k2k.sagawa-exp.co.jp/p/web/okurijosearch.do?okurijoNo=' . $n . $br;
1239 }
1240 } else {
1241 $url = 'https://k2k.sagawa-exp.co.jp/p/web/okurijosearch.do?okurijoNo=' . $tracking_number;
1242 }
1243 } else {
1244 $url = 'https://k2k.sagawa-exp.co.jp/p/sagawa/web/okurijoinput.jsp';
1245 }
1246 break;
1247
1248 case '日本郵便':
1249 case 'ゆうパック':
1250 case 'クリックポスト':
1251 case 'レターパック':
1252 if ( ! empty( $tracking_number ) ) {
1253 if ( false !== strpos( $tracking_number, ',' ) ) {
1254 $number = array_slice( explode( ',', $tracking_number ), 0, 10 );
1255 $no = '';
1256 for ( $i = 1; $i <= 10; $i++ ) {
1257 $n = isset( $number[ $i - 1 ] ) ? trim( $number[ $i - 1 ] ) : '';
1258 $no .= 'requestNo' . $i . '=' . $n . '&';
1259 }
1260 $url = 'https://trackings.post.japanpost.jp/services/srv/search?' . $no;
1261 } else {
1262 $url = 'https://trackings.post.japanpost.jp/services/srv/search?requestNo1=' . $tracking_number . '&';
1263 }
1264 $url .= 'search.x=66&search.y=25&startingUrlPatten=&locale=ja';
1265 } else {
1266 $url = 'https://trackings.post.japanpost.jp/services/srv/search/';
1267 }
1268 break;
1269
1270 case '日本通運':
1271 $url = 'https://www.nipponexpress.com/jp/ja/tracking/';
1272 break;
1273
1274 case '西濃運輸':
1275 case '西武運輸':
1276 if ( ! empty( $tracking_number ) ) {
1277 if ( false !== strpos( $tracking_number, ',' ) ) {
1278 $number = explode( ',', $tracking_number );
1279 $no = '';
1280 $i = 1;
1281 foreach ( $number as $n ) {
1282 $no .= 'GNPNO' . $i . '=' . $n . '&';
1283 $i++;
1284 }
1285 $url = 'https://track.seino.co.jp/cgi-bin/gnpquery.pgm?' . rtrim( $no, '&' );
1286 } else {
1287 $url = 'https://track.seino.co.jp/cgi-bin/gnpquery.pgm?GNPNO1=' . $tracking_number;
1288 }
1289 } else {
1290 $url = 'https://track.seino.co.jp/kamotsu/GempyoNoShokai.do';
1291 }
1292 break;
1293
1294 case '福山通運':
1295 if ( ! empty( $tracking_number ) ) {
1296 if ( false !== strpos( $tracking_number, ',' ) ) {
1297 $br = ( usces_is_html_mail() ) ? '<br>' : "\r\n";
1298 $number = explode( ',', $tracking_number );
1299 foreach ( $number as $n ) {
1300 $url .= 'https://corp.fukutsu.co.jp/situation/tracking_no_hunt/' . $n . $br;
1301 }
1302 } else {
1303 $url = 'https://corp.fukutsu.co.jp/situation/tracking_no_hunt/' . $tracking_number;
1304 }
1305 } else {
1306 $url = 'https://corp.fukutsu.co.jp/situation/tracking_no';
1307 }
1308 break;
1309
1310 case '名鉄運輸':
1311 $url = 'https://ap.meitetsuunyu.co.jp/webtrace/webtsuiseki/webtsuiseki.aspx';
1312 break;
1313
1314 case '新潟運輸':
1315 $url = 'https://www2.nuis.co.jp/kzz80011.htm';
1316 break;
1317
1318 case 'トナミ運輸':
1319 $url = 'https://trc1.tonami.co.jp/trc/search3/excSearch3';
1320 break;
1321
1322 case '第一貨物':
1323 $url = 'https://www.daiichi-kamotsu.co.jp/chase/contact_num/';
1324 break;
1325
1326 case '飛騨倉庫運輸':
1327 case '濃飛倉庫運輸':
1328 $url = 'https://www.nohhi.co.jp/support/';
1329 break;
1330
1331 default:
1332 $url = '';
1333 }
1334 $url = apply_filters( 'usces_filter_delivery_company_url', $url, $delivery_company, $tracking_number );
1335 return $url;
1336 }
1337
1338 /**
1339 * Serialization
1340 *
1341 * @param mixed $data Data.
1342 * @return string
1343 */
1344 function usces_serialize( $data ) {
1345 if ( ! is_array( $data ) ) {
1346 return $data;
1347 }
1348 return json_encode( $data );
1349 }
1350
1351 /**
1352 * Unserialize
1353 *
1354 * @param mixed $data Data.
1355 * @return array
1356 */
1357 function usces_unserialize( $data ) {
1358 if ( is_array( $data ) || is_null( $data ) ) {
1359 return $data;
1360 }
1361 return @json_decode( $data, true );
1362 }
1363
1364 /**
1365 * Check trans_id
1366 *
1367 * @param string $key Key.
1368 * @return bool
1369 */
1370 function usces_check_trans_id( $key ) {
1371 global $wpdb;
1372
1373 $access_table_name = $wpdb->prefix . 'usces_access';
1374 $query = $wpdb->prepare( "SELECT ID FROM $access_table_name WHERE acc_key = %s AND acc_str1 = %s", 'wc_trans_id', $key );
1375 $id = $wpdb->get_var( $query );
1376 return ( NULL != $id ) ? false : true;
1377 }
1378
1379 /**
1380 * Save trans_id
1381 *
1382 * @param string $key Key.
1383 * @param string $acting Acting type.
1384 * @return bool
1385 */
1386 function usces_save_trans_id( $key, $acting = 'acting' ) {
1387 global $wpdb;
1388
1389 $access_table_name = $wpdb->prefix . 'usces_access';
1390 $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 );
1391 $res = $wpdb->query( $query );
1392 return $res;
1393 }
1394
1395 /**
1396 * Is date
1397 *
1398 * @param mixed $date Date.
1399 * @return bool
1400 */
1401 function usces_is_date( $date ) {
1402
1403 if ( empty( $date ) ) {
1404 return false;
1405 }
1406
1407 try {
1408 new DateTime( $date );
1409 list( $year, $month, $day ) = explode( '-', $date );
1410 $res = checkdate( (int) $month, (int) $day, (int) $year );
1411 return $res;
1412 } catch ( Exception $e ) {
1413 return false;
1414 }
1415 }
1416
1417 /**
1418 * Payment service suspended
1419 */
1420 function usces_payment_service_suspended() {
1421 $payment_method = usces_get_system_option( 'usces_payment_method', 'sort' );
1422 foreach ( $payment_method as $payment ) {
1423 if ( 'acting_yahoo_wallet' == $payment['settlement'] && 'activate' == $payment['use'] ) {
1424 $payment['use'] = 'deactivate';
1425 usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1426 } elseif ( 'acting_veritrans_card' == $payment['settlement'] && 'activate' == $payment['use'] ) {
1427 $payment['use'] = 'deactivate';
1428 usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1429 } elseif ( 'acting_veritrans_conv' == $payment['settlement'] && 'activate' == $payment['use'] ) {
1430 $payment['use'] = 'deactivate';
1431 usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1432 }
1433 }
1434 $settlement_selected = get_option( 'usces_settlement_selected', array() );
1435 if ( is_array( $settlement_selected ) && 0 < count( $settlement_selected ) ) {
1436 $settlement_selected = array_diff( $settlement_selected, array( 'yahoo', 'veritrans' ) );
1437 $settlement_selected = array_values( $settlement_selected );
1438 update_option( 'usces_settlement_selected', $settlement_selected );
1439 }
1440 $available_settlement = get_option( 'usces_available_settlement', array() );
1441 if ( is_array( $available_settlement ) && 0 < count( $available_settlement ) ) {
1442 $available_settlement = array_diff( $available_settlement, array( 'Yahoo!ウォレット', 'ベリトランス Air-Web' ) );
1443 update_option( 'usces_available_settlement', $available_settlement );
1444 }
1445 }
1446
1447 /**
1448 * Whether the file is reserved.
1449 *
1450 * @param string $file_path File name.
1451 * @param int $dir 0:welcart-uptemp, 1:usces_logs.
1452 * @return boolean $res True if reserved, false otherwise.
1453 */
1454 function usces_is_reserved_file( $file_path, $dir = 0 ) {
1455
1456 $real_file_path = realpath( $file_path );
1457 $real_base_path = ( 1 === $dir ) ? realpath( USCES_WP_CONTENT_DIR . '/uploads/usces_logs' ) . DIRECTORY_SEPARATOR : realpath( WP_CONTENT_DIR . USCES_UPLOAD_TEMP ) . DIRECTORY_SEPARATOR;
1458 if ( false === $real_file_path || 0 !== strpos( $real_file_path, $real_base_path ) ) {
1459 // Traversal attempt.
1460 return false;
1461 }
1462
1463 $reserved_file = array(
1464 'progress.txt',
1465 'log.txt',
1466 'db-progress.txt',
1467 'db-log.txt',
1468 'member_login_failed.log',
1469 'ip_addresses_blocked.log',
1470 );
1471
1472 $path_parts = pathinfo( $file_path );
1473 if ( in_array( $path_parts['basename'], $reserved_file, true ) ) {
1474 $res = true;
1475 } else {
1476 $res = false;
1477 }
1478
1479 return $res;
1480 }
1481
1482 /**
1483 * Whether the current page is a cart page.
1484 *
1485 * @return boolean True if cart page, false other page.
1486 */
1487 function wel_is_cart_page() {
1488 global $usces;
1489 $request_uri = ( ! isset( $_SERVER['REQUEST_URI'] ) || empty( $_SERVER['REQUEST_URI'] ) ) ? '' : $_SERVER['REQUEST_URI'];
1490 return $usces->is_cart_page( $request_uri );
1491 }
1492
1493 /**
1494 * Whether the current page is a member page.
1495 *
1496 * @return boolean True if member page, false other page.
1497 */
1498 function wel_is_member_page() {
1499 global $usces;
1500 $request_uri = ( ! isset( $_SERVER['REQUEST_URI'] ) || empty( $_SERVER['REQUEST_URI'] ) ) ? '' : $_SERVER['REQUEST_URI'];
1501 return $usces->is_member_page( $request_uri );
1502 }
1503
1504 /**
1505 * Leave the old function name, assuming customization.
1506 *
1507 * @param string $str Text.
1508 * @return string
1509 */
1510 function usces_remove_script( $str ) {
1511 return wel_esc_script( $str );
1512 }
1513
1514 /**
1515 * Remove script tag
1516 *
1517 * @param string $str Text.
1518 * @return string
1519 */
1520 function wel_esc_script( $str ) {
1521
1522 if ( empty( $str ) ) {
1523 return $str;
1524 }
1525
1526 $pattern = array(
1527 '/<script\b[^>]*>/i',
1528 '/<\/script>/i',
1529 );
1530
1531 $replacement = array(
1532 '&lt;script&gt;',
1533 '&lt;/script&gt;',
1534 );
1535
1536 $str = preg_replace( $pattern, $replacement, $str );
1537 $str = preg_replace( '/<([^>]+)\s+onerror\s*=\s*[^>]*?>/i', '<$1>', $str );
1538 $str = preg_replace( '/=\s*alert\s*\(/i', '=', $str );
1539 $str = preg_replace( '/<([^>]+)\s+on\w+\s*=\s*(?!["\'])([^>]*?)>/i', '<$1$2>', $str );
1540
1541 return $str;
1542 }
1543
1544 /**
1545 * Escape and Echo script tag
1546 *
1547 * @param string $str Text.
1548 */
1549 function wel_esc_script_e( $str ) {
1550
1551 if ( empty( $str ) ) {
1552 return;
1553 }
1554
1555 $pattern = array(
1556 '/<script\b[^>]*>/i',
1557 '/<\/script>/i',
1558 );
1559
1560 $replacement = array(
1561 '&lt;script&gt;',
1562 '&lt;/script&gt;',
1563 );
1564
1565 $str = preg_replace( $pattern, $replacement, $str );
1566 $str = preg_replace( '/<([^>]+)\s+onerror\s*=\s*[^>]*?>/i', '<$1>', $str );
1567 $str = preg_replace( '/=\s*alert\s*\(/i', '=', $str );
1568 $str = preg_replace( '/<([^>]+)\s+on\w+\s*=\s*(?!["\'])([^>]*?)>/i', '<$1$2>', $str );
1569
1570 echo $str; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1571 }
1572
1573 /**
1574 * Object for filter_input_array_recursive().
1575 */
1576 class FilterObject {
1577
1578 private $filter;
1579 private $options;
1580
1581 /**
1582 * Constructor.
1583 *
1584 * @param int $filter same as ones for filter_input().
1585 * @param mixed $options same as ones for filter_input().
1586 */
1587 public function __construct( $filter = FILTER_DEFAULT, $options = FILTER_REQUIRE_SCALAR ) {
1588 $this->filter = $filter;
1589 $this->options = $options;
1590 }
1591
1592 public function getFilter() {
1593 return $this->filter;
1594 }
1595
1596 public function getOptions() {
1597 return $this->options;
1598 }
1599
1600 }
1601
1602 /**
1603 * Apply filter_input() recursively.
1604 *
1605 * @param int $type INPUT_GET, INPUT_POST, INPUT_COOKIE or INPUT_REQUEST.
1606 * @param array $filters Multi-demensional array,
1607 * which contains FilterObject for each leaf.
1608 * @return array
1609 */
1610 function filter_input_array_recursive( $type, array $filters ) {
1611 static $recursive_static;
1612 static $flag_match;
1613 static $is_not_array;
1614 static $filter_array;
1615 static $types;
1616 if ( ! $flag_match ) {
1617 /* initialize static variables */
1618 $types = array(
1619 'INPUT_GET' => $_GET,
1620 'INPUT_POST' => $_POST,
1621 'INPUT_COOKIE' => $_COOKIE,
1622 'INPUT_REQUEST' => $_REQUEST,
1623 );
1624 $flag_match = function( $v, $f ) {
1625 return (int) ( isset( $v['flags'] ) ? $v['flags'] : $v ) & $f;
1626 };
1627 $is_not_array = function( $v ) {
1628 return ! is_array( $v );
1629 };
1630 $filter_array = function( $v ) {
1631 return ! is_array( $v ) ? $v : false;
1632 };
1633 }
1634 $recursive = $recursive_static;
1635 if ( ! $recursive ) {
1636 /* only for first loop */
1637 $type = (int) $type;
1638 if ( ! isset( $types[ $type ] ) ) {
1639 throw new \InvalidArgumentException(
1640 'unknown super global var type'
1641 );
1642 }
1643 $var = $types[ $type ];
1644 $recursive_static = true;
1645 } else {
1646 /* after first loop */
1647 $var = $type;
1648 }
1649 $ret = array();
1650 foreach ( $filters as $key => $value ) {
1651 if ( is_array( $value ) ) {
1652 // apply child filters.
1653 $ret[ $key ] = filter_input_array_recursive(
1654 isset( $var[ $key ] ) ? $var[ $key ] : array(),
1655 $value
1656 );
1657 } else {
1658 if ( ! ( $value instanceof FilterObject ) ) {
1659 // create default FilterObject for invalid leaf.
1660 $value = new FilterObject;
1661 }
1662 $filter = $value->getFilter();
1663 $options = $value->getOptions();
1664 // check if key exists...
1665 // true -> apply filter_var() with supplied filter and options.
1666 // false -> regard as null.
1667 try {
1668 $ret[ $key ] =
1669 isset( $var[ $key ] ) ?
1670 filter_var( $var[ $key ], $filter, $options ) :
1671 null
1672 ;
1673 } catch ( Exception $e ) {
1674 $recursive_static = false;
1675 throw $e;
1676 }
1677 if ( $flag_match( $options, FILTER_FORCE_ARRAY | FILTER_REQUIRE_ARRAY ) ) {
1678 // differently from filter_input(),
1679 // this function prevent unexpected non-array value
1680 // or multi-demensional array.
1681 if ( $flag_match( $options, FILTER_FORCE_ARRAY ) ) {
1682 // eliminate arrays.
1683 $ret[ $key ] = array_filter( (array) $ret[ $key ], $is_not_array );
1684 } else {
1685 // change arrays into false.
1686 $ret[ $key ] = array_map( $filter_array, (array) $ret[ $key ] );
1687 }
1688 }
1689 }
1690 }
1691 if ( ! $recursive ) {
1692 /* only for first loop */
1693 $recursive_static = false;
1694 }
1695 return $ret;
1696 }
1697
1698 /**
1699 * Remove the path from the uploaded file name and perform escape processing.
1700 *
1701 * @param string $file_name File Name.
1702 *
1703 * @return string
1704 */
1705 function wel_esc_upload_file_name( $file_name ) {
1706 $filenames = explode( '/', urldecode( $file_name ) );
1707 end( $filenames );
1708
1709 return wel_esc_script( $filenames[0] );
1710 }
1711
1712 /**
1713 * If the input data is a serialized object, sanitize it.
1714 *
1715 * @param string $data text.
1716 *
1717 * @return mixed|object|string
1718 */
1719 function wel_safe_text_serialize( $data ) {
1720 if ( ! is_serialized( $data ) ) {
1721 return $data; // シリアライズされていないなら、そのまま返す
1722 }
1723
1724 $result = unserialize( $data, [ 'allowed_classes' => false ] ); // オブジェクトを展開しない
1725
1726 // �
1727 �列またはオブジェクトの場合、再帰的に無害化
1728 if ( is_array( $result ) ) {
1729 array_walk_recursive( $result, function ( &$value ) {
1730 $value = sanitize_text_field( $value ); // 文字列を無害化
1731 } );
1732 } elseif ( is_object( $result ) ) {
1733 return sanitize_text_field( $result );
1734 } else {
1735 return sanitize_text_field( $result );
1736 }
1737
1738 return maybe_serialize( $result );
1739 }