HEX
Server: Apache
System: Linux 4485441ca2e2 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 11:03:07 UTC 2025 aarch64
User: (1000)
PHP: 8.2.24
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/ganryu_shop/boot/grys_func.php
<?php

require_once GANRYU_SHOP_ROOT.'/libs/paramconfig/grys_paramConfig.php';
require_once GANRYU_SHOP_ROOT.'/libs/GanryuEpsCredit.php';



class grys_upload_file{
	var $tmppath;
	var $realname;
	var $needsClean;

	static function imageType($data){
		if (preg_match('/^GIF/', $data)){
			return "gif";
		}
		else if (preg_match('/^\x89PNG/', $data)){
			return "png";
		}
		else if (preg_match('/^\xff\xd8/', $data) && preg_match('/\xff\xd9$/', $data)){
			return "jpeg";
		}
		return null;
	}

	function inputFile($nm){
		if (!array_key_exists($nm, $_FILES)){
			return false;
		}
		$f = $_FILES[$nm];
		$this->tmppath = $f['tmp_name'];
		$this->realname = $f['name'];
		$this->needsClean = false;
		return true;
	}
	function inputFromTmp($tmppath, $realname){
		$this->tmppath = $tmppath;
		$this->realname = $realname;
		$this->needsClean = true;
		return true;
	}
	function inputFromBinary($bin){
		$this->tmppath = '/tmp/'.md5(uniqid(rand(10000,99999)));
		$this->realname = null;
		$this->needsClean = true;
		file_put_contents($this->tmppath, $bin);
		return true;
	}
	
	function isImageFile(){
		$data = file_get_contents($this->tmppath);
		$type = self::imageType($data);
		return $type != null;
	}
	
	
	
	function resizeRect($w, $h){
		$data = file_get_contents($this->tmppath);
		$type = self::imageType($data);
		if ($type == "gif"){
			$gd = imagecreatefromgif($this->tmppath);
		}
		else if ($type == "jpeg"){
			$gd = imagecreatefromjpeg($this->tmppath);
		}
		else if ($type == "png"){
			$gd = imagecreatefrompng($this->tmppath);
		}
		else{
			return false;
		}
		
		$w0 = imagesx($gd);
		$h0 = imagesy($gd);
		$rw = $w / $w0;
		$rh = $h / $h0;
		if ($rw < $rh) $r = $rh;
		else $r = $rw;
		$x0 = $w0/2-($w/$r)/2;
		$y0 = $h0/2-($h/$r)/2;
		$gd2 = imagecreatetruecolor($w, $h);
		imagecopyresampled($gd2, $gd, 0, 0, $x0, $y0, $w, $h, $w/$r, $h/$r);
		
		$ss = md5(uniqid(rand(10000, 99999)));
		
		$tmppath = '/tmp/'.$ss;
		$realname = $this->realname;
		imagepng($gd2, $tmppath);
		
		
		$f = new grys_upload_file();
		$f->inputFromTmp($tmppath, $realname);
		return $f;
	}


	function clean(){
		if ($this->needsClean){
			if (file_exists($this->tmppath)){
				unlink($this->tmppath);
			}
		}
	}
	
	function binary(){
		return file_get_contents($this->tmppath);
	}


}


class grys_sqlbinder{

	function __construct($sql, $bind){
		$this->sql = $sql;
		$this->bind = $bind;
	}
	
	function prepare(){
		$sql = preg_replace_callback('/:(\w+)/', array($this, '_replace'), $this->sql);
		return $sql;
	}
	
	function _replace($m){
		if (array_key_exists($m[1], $this->bind) && !is_null($this->bind[$m[1]])){
			return "'".esc_sql($this->bind[$m[1]])."'";
		}
		return "null";
	}
}

function grys_mail($setup){
	$to = isset($setup['to'])?$setup['to']:'';
	$subject = isset($setup['subject'])?$setup['subject']:'no title';
	$headers = isset($setup['headers'])?$setup['headers']:array();
	$body = isset($setup['body'])?$setup['body']:'';
	$realto = $to;
	
	if (!$to) return false;
	
	if (preg_match('/^(.*)<([^>]*@[^>]*)>$/', $to, $m)){
		$realto = $m[2];
	}
	
	$headers['Content-Type'] = 'text/plain; charset=utf-8';
	$headers['Content-Transfer-Encoding'] = '8bit';
	
	$sendheader = "";
	foreach ($headers as $nm=>$hdr){
		$isenc = false;
		for($i = 0; $i < strlen($hdr); $i++){
			if (ord($hdr[$i]) >= 0x80){
				$isenc = true;
				break;
			}
		}
		if ($isenc){
			if (preg_match('/^(.*)<([^>\x80-\xff]*@[^>\x80-\xff]*)>$/', $hdr, $m)){
				$hdr = '=?UTF-8?B?'.base64_encode($m[1])."?=".'<'.$m[2].'>';
			}
			else{
				$hdr = '=?UTF-8?B?'.base64_encode($hdr)."?=";
			}
		}
		$sendheader .= "$nm: $hdr\r\n";
	}
	$subject = '=?UTF-8?B?'.base64_encode($subject)."?=";
	
//	$realto = "y_uehara_y@hotmail.com";

//	$res = mail($realto, $subject, $body, $sendheader);
	$res = wp_mail($realto, $subject, $body, $sendheader);
	return $res;
}

function grys_eps_config($target="production"){
//	$target = "develop";
	
	if ($target == "develop"){
		$config = array(
			'contract_code'=>'63965080',
			'send_encode'=>'EUC-JP',
			'receive_encode'=>'Shift_JIS',
			'inner_encode'=>'UTF-8',
			'url'=>array(
				'create_purchase'=>'https://beta.epsilon.jp/cgi-bin/order/receive_order3.cgi',
				'get_sales'=>'https://beta.epsilon.jp/cgi-bin/order/getsales2.cgi',
				'create_regularly_cancel'=>'https://beta.epsilon.jp/cgi-bin/order/regularly_cancel.cgi',
			)
		);
		return $config;
	}
	if ($target == "production"){
		$config = array(
			'contract_code'=>'63965080',
			'send_encode'=>'EUC-JP',
			'receive_encode'=>'Shift_JIS',
			'inner_encode'=>'UTF-8',
			'url'=>array(
				'create_purchase'=>'https://secure.epsilon.jp/cgi-bin/order/receive_order3.cgi',
				'get_sales'=>'https://secure.epsilon.jp/cgi-bin/order/getsales2.cgi',
				'create_regularly_cancel'=>'https://secure.epsilon.jp/cgi-bin/order/regularly_cancel.cgi',
			)
		);
		return $config;
	}
	return false;

}

function grys_eps_purchase($target, $data){
	$conf = grys_eps_config($target);
	if (!$conf){
		return false;
	}
	$es = new GanryuEpsCredit($conf);
	$res = $es->connectPurchase($data);
	return $res;
}
function grys_eps_fanclub_purchase($target, $data){
	$conf = grys_eps_config($target);
	if (!$conf){
		return false;
	}
	$es = new GanryuEpsCredit($conf);
	$res = $es->connectFanclubPurchase($data);
	return $res;
}
function grys_eps_fanclub_cancel($target, $data){
	$conf = grys_eps_config($target);
	if (!$conf){
		return false;
	}
	$es = new GanryuEpsCredit($conf);
	$res = $es->connectFanclubCancel($data);
	return $res;
}


function grys_eps_getsales($target, $code){
	$conf = grys_eps_config($target);
	if (!$conf){
		return false;
	}
	$es = new GanryuEpsCredit($conf);
	$res = $es->connectGetSales($code);
	return $res;
}

function grys_text_replace($txt, $rep){
	$txt = preg_replace_callback('/\[\[(\w+)\]\]/', function($m) use($rep){
		$key = $m[1];
		if (!array_key_exists($key, $rep)){
			return "[[$key]]";
		}
		return $rep[$key];
	}, $txt);

	return $txt;
}

function grys_pagetitle(){
	$page = grys_getvalue('page_action');
	global $grys_boot;
	return $grys_boot->doAction('Shopping', 'globalTitle', array($page));
}
function grys_sns_url(){
	global $grys_boot;
	return $grys_boot->doAction('Shopping', 'globalSnsUrl');
}

function grys_post_link($aid){
	$adata = get_post($aid);
	if (strlen($adata->post_type) > 4 && substr($adata->post_type,0,4)=='grjm'){
		$url = home_url().'/?'.$adata->post_type.'='.$adata->post_name;
	}
	else{
		$url = get_permalink($adata);
	}
	return $url;
}
function grys_post_name($aid){
	$adata = get_post($aid);
	return $adata->post_title;
}
function grys_shorten($v, $num, $more="..."){
	if (mb_strlen($v) >= $num){
		$v = mb_substr($v, 0, $num).$more;
	}
	return $v;
}

function grys_tablename($v){
	global $wpdb;
	$prefix = $wpdb->prefix;
	return $prefix."_ganryu_shop_".$v;
}

function grys_getvalue($v){
	if (!array_key_exists($v, $_GET)){
		return null;
	}
	return $_GET[$v];
}

function grys_postvalue($v){
	if (!array_key_exists($v, $_POST)){
		return null;
	}
	return $_POST[$v];
}


function grys_request_path($withquery = false){
	$homeurl = home_url();
	if (preg_match('/^https?:\/\/[^\/]+(.*)$/', $homeurl, $m)){
		$path = $m[1];
		$reqpath = getenv('REQUEST_URI');
		if (!$withquery){
			$qpos = strpos("?", $reqpath);
			$qpos = strpos($reqpath, "?");
			if ($qpos !== false){
				$reqpath = substr($reqpath, 0, $qpos);
			}
		}
		
		if (substr($reqpath, 0, strlen($path)) == $path){
			return substr($reqpath, strlen($path));
		}
	}
	return null;
}

function grys_get_cart_cookie(){
	$nm = "grys_cart";
	if (!array_key_exists($nm, $_COOKIE)){
		return "";
	}
	return $_COOKIE[$nm];
}

function grys_set_cookie($nm, $v, $expire){
	$home = home_url();
	if (preg_match('/^https?:\/\/([^\/]+)(.*)$/', $home, $m)){
		$domain = $m[1];
		$path = $m[2];
	}
	else{
		return;
	}
	if ($path == ""){
		$path = "/";
	}
	setcookie($nm, $v, $expire, $path, $domain);
}
function grys_set_cart_cookie($v){
	grys_set_cookie("grys_cart" , $v, 0);
}
function grys_set_shopping_cookie($v){
	grys_set_cookie("grys_shopping_ss" , $v, 0);
}
function grys_set_fanclub_cookie($v){
	grys_set_cookie("grys_fanclub_ss" , $v, 0);
}


function grys_ymdhis($v){
	if (strlen($v) < 14) return $v;
	return substr($v, 0, 4).'/'.substr($v, 4, 2).'/'.substr($v, 6, 2).' '.substr($v, 8, 2).':'.substr($v, 10, 2).':'.substr($v, 12, 2);
}
function grys_ymd($v){
	if (strlen($v) < 8) return $v;
	return substr($v, 0, 4).'/'.substr($v, 4, 2).'/'.substr($v, 6, 2);
}
function grys_date_mdw($v){
	$ret = substr($v, 4, 2).'月'.substr($v, 6, 2)."日";
	$w = date('w', strtotime($v));
	$wdt = "日月火水木金土";
	$ret .= '('.mb_substr($wdt, $w, 1).')';
	return $ret;
}

function grys_check_number($v){
	return preg_match('/^\d+$/', $v);
}
function grys_check_number_minus($v){
	return preg_match('/^-?\d+$/', $v);
}
function grys_check_email($v){
//	return preg_match('/^[\w-.]+@[\w-.]+$/', $v);
	return preg_match('/\A([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+\z/', $v);
}
function grys_check_kana($v){
	return preg_match('/^[ア-ヴー]+$/u', $v);
}
function grys_stock_label($v){
	if ($v <= 0) return "在庫切れ";
	if ($v <= 10) return "残りわずか";
	return "在庫あり";
}

function grys_admin_only(){
	$user = wp_get_current_user();
	if (!in_array('administrator', $user->roles)){
		exit;
	}
}


function grys_prefecture_list(){
	return grys_paramConfig::getList('prefecture');
}

function grys_prefecture_name($v){
	return grys_paramConfig::getValue('prefecture', $v);
}

function grys_js($v){
	$v = preg_replace_callback('/([\x00-\x20\'\"\\\\])/', 
		function($m){
			return "\\x".sprintf('%02x', ord($m[1]));
		}
		, $v);
	return $v;
}
function grys_options($list, $selectedvalue=null, $conf=array('id','value')){
	$html = "";
	foreach ($list as $dt){
		$selected = ($selectedvalue != null && ($dt[$conf[0]] == $selectedvalue))?"selected":"";
		$html .= '<option value="'.esc_html($dt[$conf[0]]).'" '.$selected.'>'.esc_html($dt[$conf[1]]).'</option>';
	}
	return $html;
}


function grys_get_shopping_value($tg, $val=null){
	if ($tg == "shopping_session"){
		$key = "grys_shopping_ss";
		if (!array_key_exists($key, $_COOKIE)){
			return null;
		}
		return $_COOKIE[$key];
	}
	if ($tg == "cachename"){
		return "shopping_".$val;
	}
	if ($tg == "cacheexpire"){
		return 60*60;
	}
	
}
function grys_get_fanclub_value($tg, $val=null){
	if ($tg == "fanclub_session"){
		$key = "grys_fanclub_ss";
		if (!array_key_exists($key, $_COOKIE)){
			return null;
		}
		return $_COOKIE[$key];
	}
	if ($tg == "cachename"){
		return "fanclub_".$val;
	}
	if ($tg == "cacheexpire"){
		return 60*60;
	}
	
}

function grys_generate_session($n=16){
	$v = "";
	for($i = 0; $i < $n; $i++){
		$r = rand(0, 61);
		if ($r < 10){
			$v .= chr(ord('0')+$r);
		}
		else if ($r < 10+26){
			$v .= chr(ord('A')+($r-10));
		}
		else {
			$v .= chr(ord('a')+($r-10-26));
		}
	}
	return $v;
}


function h($v){
	return htmlspecialchars($v);
}

function grys_deliv_status($st){
	if ($st == 1) return "配送待ち";
	if ($st == 2) return "配送済み";
	return "";
}
function grys_payment_status($st){
	if ($st == 1) return "入金待ち";
	if ($st == 2) return "入金済み";
	return "";
}