*/ require dirname(__FILE__) . "/global.php"; $type = substr($_REQUEST['type_c'], 0, -2); //忽略最后两位“_c” $md5key = filterRelativePath($_REQUEST['key']); $resdir = filterRelativePath($_REQUEST['res']); if ($_SERVER['HTTP_IF_NONE_MATCH'] == $md5key) { header("HTTP/1.1 304 Not Modified"); } else { if ($type == "js" || $type == "css") { $cacheFile = __FILES_PATH . "res_c/{$type}/{$resdir}/{$md5key}.{$type}"; if ($type == "css") { header("Content-Type: text/css"); } else { if ($type == "js") { header("Content-Type: application/javascript"); } } header("Content-Encoding: gzip"); header("Etag: " . $md5key); $expires = 365 * 86400; //客户端缓存1年 header("Pragma: public"); header("Cache-Control: maxage=" . $expires); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); $data = file_get_contents($cacheFile); echo gzencode($data); } else { logWarn("Unknown type: {$type}."); } }
/** * @brief enable/disable preview for selected format * * @param string format * @param bool enable (true = enable, false = disable, default = false) * @return bool */ public static function setPreview($format, $enable = 'false') { $enablePreviewProviders = \OCP\Config::getSystemValue('enabledPreviewProviders', null); if ($enable == 'true') { if ($enablePreviewProviders === null) { // set up default providers $enablePreviewProviders = array(); array_push($enablePreviewProviders, 'OC\\Preview\\Image', 'OC\\Preview\\MP3', 'OC\\Preview\\TXT', 'OC\\Preview\\MarkDown'); } if (!in_array($format, $enablePreviewProviders)) { array_push($enablePreviewProviders, $format); } } else { if (!($enablePreviewProviders == null)) { $enablePreviewProviders = array_diff($enablePreviewProviders, array($format)); } } if (!\OCP\Config::setSystemValue('enabledPreviewProviders', $enablePreviewProviders)) { logWarn("Failed to enable " . $format . " preview provider (config.php readonly?)"); return true; } }
function __auto_create_js_cache($files, $returnData = false) { //1. 检查文件是否存在,并取得最后修改时间 $loadFiles = array(); $check = ""; $resdir = ""; foreach ($files as $file) { $file = str_replace(array('//', '..'), array('/', ''), $file); if ($file == '' || substr($file, -3) != '.js') { continue; } if (substr($file, 0, 1) == '/') { $file = substr($file, 1); } $pathfile = __ROOT_PATH . 'res/js/' . $file; $modifyTime = @filemtime($pathfile); if ($modifyTime == false) { logWarn("Load JS ERROR - miss file: " . $pathfile); continue; } $resdir .= substr($file, 0, 1); //取文件名的第一个字母作为文件名 $check .= $file . '|' . $modifyTime . '|'; $loadFiles[] = array('file' => $file, 'mtime' => $modifyTime); } //2. 检查是否有缓存文件 $md5key = md5($check); $result = array('resdir' => $resdir, 'md5key' => $md5key); $cacheFile = __FILES_PATH . 'res_c/js/' . $resdir . '/' . $md5key . '.js'; if (file_exists($cacheFile)) { if ($returnData) { $result['data'] = file_get_contents($cacheFile); } return $result; } $data = ""; foreach ($loadFiles as $info) { //检查是否已是.min文件 $originFile = __ROOT_PATH . 'res/js/' . $info['file']; if (substr($info['file'], -7, 4) != '.min') { //转换为.min文件 $minFile = __FILES_PATH . 'res_c/jsmin/' . substr($info['file'], 0, -2) . $info['mtime'] . '.min.js'; if (file_exists($minFile) == false) { $str = JSMin::minify(file_get_contents($originFile)); if (file_exists(dirname($minFile)) == false) { mkdir(dirname($minFile), 0777, true); } file_put_contents($minFile, $str); } else { $str = file_get_contents($minFile); } } else { //源文件已是压缩过的,直接读取 $str = file_get_contents($originFile); } $data .= $str . "\r\n"; } if (file_exists(dirname($cacheFile)) == false) { mkdir(dirname($cacheFile), 0777, true); } file_put_contents($cacheFile, $data); if ($returnData) { $result['data'] = $data; } return $result; }
function __auto_create_css_cache($files, $returnData = false) { if (ResourceHelper::isExternalOpen() && defined("__EXTERNAL_RES_URL")) { $baseURL = __EXTERNAL_RES_URL; } else { $baseURL = __RESOURCE_BASE_URL; } //1. 检查文件是否存在,并取得最后修改时间 $loadFiles = array(); $check = ""; $resdir = ""; foreach ($files as $file) { $file = str_replace(array('//', '..'), array('/', ''), $file); if ($file == '' || substr($file, -4) != '.css') { continue; } if (substr($file, 0, 1) == '/') { $file = substr($file, 1); } $pathfile = __ROOT_PATH . 'res/css/' . $file; $modifyTime = @filemtime($pathfile); if ($modifyTime == false) { logWarn("Load CSS ERROR - miss file: " . $pathfile); continue; } $resdir .= substr($file, 0, 1); //取文件名的第一个字母作为文件名 $check .= $file . '|' . $modifyTime . '|'; $loadFiles[] = array('file' => $file, 'mtime' => $modifyTime); } //2. 检查是否有缓存文件 $md5key = md5($check); $result = array('resdir' => $resdir, 'md5key' => $md5key); $cacheFile = __FILES_PATH . 'res_c/css/' . $resdir . '/' . $md5key . '.css'; if (file_exists($cacheFile)) { if ($returnData) { $result['data'] = file_get_contents($cacheFile); } return $result; } $data = ""; foreach ($loadFiles as $info) { $originFile = __ROOT_PATH . 'res/css/' . $info['file']; $str = file_get_contents($originFile); $subBaseURL = $baseURL . "css/"; $subdir = dirname($info['file']); if ($subdir != "" && $subdir != ".") { $subBaseURL .= $subdir . "/"; } $str = FastPHP_CSSMin::minify($str, $subBaseURL); $data .= $str . "\r\n"; } if (file_exists(dirname($cacheFile)) == false) { mkdir(dirname($cacheFile), 0777, true); } file_put_contents($cacheFile, $data); if ($returnData) { $result['data'] = $data; } return $result; }
private function refundCallbackProcess($msg) { //付款信息 //支付状态是否变为支付成功 $result = $msg->tradeSuccess; $map['refundNumber'] = $msg->transactionId; $map['type'] = 'REFUND'; $billLogic = D('OrderBill', 'Logic'); $record = $billLogic->queryBill($map); if (count($record) == 0) { logWarn('Payment Webhook:cannot find matched bill refund record.'); echo 'success'; return; } $bill = $record[0]; if ($bill['totalAmount'] != $msg->transactionFee / 100) { //确认金额确实为业务产生的金额 logWarn('Payment Webhook:Refund total Fee not matched.'); echo 'success'; return; } //如果支付成功,则更新状态为SUCCESS,否则为FAILED $data['status'] = $result ? 'S' : 'F'; $data['billId'] = $bill['billId']; $billLogic->update($data); if ($bill['orderItemId'] == 0) { //如果orderItemId为0,则表示是整个订单取消 if ($result) { $orderLogic = D('Order', 'Logic'); $order = $orderLogic->findByOrderNumber($bill['orderNumber']); //update inventory $this->increaseInventoryByOrder($order['orderId']); if ($orderLogic->updateOrderStatus($order['orderId'], 'C2', 'C3') == false) { logWarn('Payment Webhook:Order/Order item status not match.'); return; } } } else { //Single order item refund //如果退款成功,更新orderitem状态 $orderItem = D('OrderItem', 'Logic')->getOrderItemById($bill['orderItemId']); if ($orderItem['status'] != 'C2') { logWarn('Payment Webhook:Order Item status not C2, return.'); return; } if ($result) { $orderItemData['status'] = 'C3'; D('OrderItem', 'Logic')->updateOrderItem($orderItemData, $bill['orderItemId']); //更新库存 $this->increaseInventoryByOrderItem($bill['orderItemId']); } } }