| 1 |
<?php |
| 2 |
function usces_filter_get_post_metadata( $null, $object_id, $meta_key, $single){ |
| 3 |
global $wpdb; |
| 4 |
$query = $wpdb->prepare("SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s", $object_id, $meta_key); |
| 5 |
$metas = $wpdb->get_col($query); |
| 6 |
if ( !empty($metas) ) { |
| 7 |
return array_map('maybe_unserialize', $metas); |
| 8 |
} |
| 9 |
|
| 10 |
if ($single) |
| 11 |
return ''; |
| 12 |
else |
| 13 |
return array(); |
| 14 |
} |
| 15 |
|
| 16 |
function usces_action_reg_orderdata( $args ){ |
| 17 |
global $wpdb, $usces; |
| 18 |
$options = get_option('usces'); |
| 19 |
extract($args); |
| 20 |
|
| 21 |
/* Register decorated order id ***************************************************/ |
| 22 |
$olimit = 0; |
| 23 |
if( ! $options['system']['dec_orderID_flag'] ){ |
| 24 |
$dec_order_id = str_pad($order_id, $options['system']['dec_orderID_digit'], "0", STR_PAD_LEFT); |
| 25 |
}else{ |
| 26 |
$otable = $wpdb->prefix . 'usces_order_meta'; |
| 27 |
while( $ukey = usces_get_key( $options['system']['dec_orderID_digit'] ) ){ |
| 28 |
$ores = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $otable WHERE meta_key = %s AND meta_value = %s LIMIT 1", 'dec_order_id', $ukey)); |
| 29 |
if( !$ores || 100 < $olimit ) |
| 30 |
break; |
| 31 |
$olimit++; |
| 32 |
} |
| 33 |
$dec_order_id = $ukey; |
| 34 |
} |
| 35 |
$dec_order_id = apply_filters( 'usces_filter_dec_order_id_prefix', $options['system']['dec_orderID_prefix'], $args ) . apply_filters( 'usces_filter_dec_order_id', $dec_order_id, $args ); |
| 36 |
|
| 37 |
if( 100 < $olimit ){ |
| 38 |
$usces->set_order_meta_value('dec_order_id', uniqid(), $order_id); |
| 39 |
}else{ |
| 40 |
$usces->set_order_meta_value('dec_order_id', $dec_order_id, $order_id); |
| 41 |
} |
| 42 |
unset($dec_order_id, $otable, $olimit, $ukey, $ores); |
| 43 |
/***********************************************************************************/ |
| 44 |
} |
| 45 |
|
| 46 |
function usces_action_reg_orderdata_stocks($args){ |
| 47 |
global $usces; |
| 48 |
extract($args); |
| 49 |
|
| 50 |
foreach($cart as $cartrow){ |
| 51 |
$sku = urldecode($cartrow['sku']); |
| 52 |
$zaikonum = $usces->getItemZaikoNum( $cartrow['post_id'], $sku ); |
| 53 |
if($zaikonum == '') continue; |
| 54 |
$zaikonum = $zaikonum - $cartrow['quantity']; |
| 55 |
$usces->updateItemZaikoNum( $cartrow['post_id'], $sku, $zaikonum ); |
| 56 |
if($zaikonum <= 0) $usces->updateItemZaiko( $cartrow['post_id'], $sku, 2 ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
function usces_action_ogp_meta(){ |
| 61 |
global $usces, $post; |
| 62 |
if( empty($post) || !$usces->is_item($post) || !is_single() ) |
| 63 |
return; |
| 64 |
|
| 65 |
$item = $usces->get_item( $post->ID ); |
| 66 |
$pictid = $usces->get_mainpictid($item['itemCode']); |
| 67 |
$image_info = wp_get_attachment_image_src( $pictid, 'thumbnail' ); |
| 68 |
|
| 69 |
$ogs['title'] = $item['itemName']; |
| 70 |
$ogs['type'] = 'product'; |
| 71 |
$ogs['description'] = strip_tags( get_the_title($post->ID) ); |
| 72 |
$ogs['url'] = get_permalink($post->ID); |
| 73 |
$ogs['image'] = $image_info[0]; |
| 74 |
$ogs['site_name'] = get_option('blogname'); |
| 75 |
$ogs = apply_filters( 'usces_filter_ogp_meta', $ogs, $post->ID ); |
| 76 |
|
| 77 |
foreach( $ogs as $key => $value ){ |
| 78 |
echo "\n" . '<meta property="og:' . $key . '" content="' . $value . '">'; |
| 79 |
} |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
function wc_purchase_nonce($html, $payments, $acting_flag, $rand, $purchase_disabled){ |
| 84 |
if( strpos($html, 'wc_nonce') || !in_array( $payments['settlement'], array('COD', 'installment', 'transferAdvance', 'transferDeferred', 'acting_zeus_card')) ) |
| 85 |
return $html; |
| 86 |
$wc_nonce = wp_create_nonce('wc_purchase_nonce'); |
| 87 |
$html .= wp_nonce_field( 'wc_purchase_nonce', 'wc_nonce', false, false )."\n"; |
| 88 |
return $html; |
| 89 |
} |
| 90 |
|
| 91 |
function wc_purchase_nonce_check(){ |
| 92 |
global $usces; |
| 93 |
$entry = $usces->cart->get_entry(); |
| 94 |
if( !isset($entry['order']['payment_name']) || empty($entry['order']['payment_name']) ){ |
| 95 |
wp_redirect( home_url() ); |
| 96 |
exit; |
| 97 |
} |
| 98 |
|
| 99 |
$payments = usces_get_payments_by_name($entry['order']['payment_name']); |
| 100 |
if( !in_array( $payments['settlement'], array('COD', 'installment', 'transferAdvance', 'transferDeferred' )) ) |
| 101 |
return true; |
| 102 |
|
| 103 |
$nonce = isset($_REQUEST['wc_nonce']) ? $_REQUEST['wc_nonce'] : ''; |
| 104 |
if( wp_verify_nonce($nonce, 'wc_purchase_nonce') ) |
| 105 |
return true; |
| 106 |
|
| 107 |
wp_redirect( home_url() ); |
| 108 |
exit; |
| 109 |
} |
| 110 |
|
| 111 |
function wc_mkdir(){ |
| 112 |
global $usces; |
| 113 |
if( is_admin() && !WCUtils::is_blank($usces->options['logs_path']) && false !== strpos($_SERVER['SERVER_SOFTWARE'],'Apache')){ |
| 114 |
$welcart_file_dir = $usces->options['logs_path'] . '/welcart'; |
| 115 |
$logs_dir = $welcart_file_dir . '/logs'; |
| 116 |
if( !file_exists($welcart_file_dir) ){ |
| 117 |
$res = @mkdir($welcart_file_dir, 0700); |
| 118 |
if(!$res){ |
| 119 |
$msg = '<div class="error"><p>下記のディレクトリーを、所有� |
| 120 |
:' . get_current_user() . '、パーミッション:700 で作成してください。 <br />' . $welcart_file_dir . '</p></div>'; |
| 121 |
add_action('admin_notices', $c = create_function('', 'echo "' . addcslashes($msg,'"') . '";')); |
| 122 |
} |
| 123 |
} |
| 124 |
$stat = stat($welcart_file_dir); |
| 125 |
print_r($stat); |
| 126 |
die(); |
| 127 |
if( is_writable($welcart_file_dir) ){ |
| 128 |
$res = @mkdir($logs_dir, 0700); |
| 129 |
if(!$res){ |
| 130 |
$msg = '<div class="error"><p>下記のディレクトリーを、所有� |
| 131 |
:' . get_current_user() . '、パーミッション:700 で作成してください。 <br />' . $welcart_file_dir . '</p></div>'; |
| 132 |
add_action('admin_notices', $c = create_function('', 'echo "' . addcslashes($msg,'"') . '";')); |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
?> |