You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
256 lines
9.7 KiB
PHP
256 lines
9.7 KiB
PHP
<?php
|
|
|
|
class HtmlTool {
|
|
|
|
public static function getLocalStaticUrlPart($isHttps = true){
|
|
$protocol = self::getRealProtocol($isHttps);
|
|
|
|
$staticDir = str_replace('\\', '/', Zc::C(ZcConfigConst::DirWsViewsStatic));
|
|
$staticHost = self::getStaticHost();
|
|
$staticDomain = $protocol . '://' . $staticHost;
|
|
$apiPath = (stripos($staticHost, 'api.') === 0 || stripos(Zc::C('static.domain'), '.api.') != false) ? '/' : '/api/';
|
|
return $staticDomain . $apiPath . $staticDir;
|
|
}
|
|
|
|
public static function isSecureMode() {
|
|
if (Zc::C('env') == 'live') {
|
|
return true;//强制https
|
|
}
|
|
if (isset($_SERVER['HTTPS'])) {
|
|
return in_array(strtolower($_SERVER['HTTPS']), array(1, 'on'));
|
|
}
|
|
// $_SERVER['SSL'] exists only in some specific configuration
|
|
if (isset($_SERVER['SSL'])) {
|
|
return in_array(strtolower($_SERVER['SSL']), array(1, 'on'));
|
|
}
|
|
// $_SERVER['REDIRECT_HTTPS'] exists only in some specific configuration
|
|
if (isset($_SERVER['REDIRECT_HTTPS'])) {
|
|
return in_array(strtolower($_SERVER['REDIRECT_HTTPS']), array(1, 'on'));
|
|
}
|
|
if (isset($_SERVER['HTTP_SSL'])) {
|
|
return in_array(strtolower($_SERVER['HTTP_SSL']), array(1, 'on'));
|
|
}
|
|
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
|
|
return strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https';
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 来自Yii框架的方法
|
|
* @param string $content
|
|
* @param string $doubleEncode
|
|
* @return string
|
|
*/
|
|
public static function encode($content, $doubleEncode = true) {
|
|
return htmlspecialchars($content, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', $doubleEncode);
|
|
}
|
|
|
|
public static function getStaticUrlPart($isHttps) {
|
|
return self::getLocalStaticUrlPart($isHttps);
|
|
}
|
|
|
|
public static function getRealProtocol($isHttps = true) {
|
|
if (Zc::C('static.domain') == $_SERVER['HTTP_HOST']) {
|
|
$protocol = self::isSecureMode() ? 'https' : 'http';
|
|
} elseif ($isHttps && (Zc::C('env') == 'live')) {
|
|
$protocol = 'https';
|
|
} else {
|
|
$protocol = ZcUrlHelper::getProtocol();
|
|
}
|
|
|
|
return $protocol;
|
|
}
|
|
|
|
public static function getStaticHost() {
|
|
$staticHostList = Zc::C('static.host.list');
|
|
return $staticHostList[array_rand($staticHostList, 1)];
|
|
}
|
|
|
|
public static function getStaticUrl($file, $isHttps = true) {
|
|
return self::getStaticUrlPart($isHttps) . $file;
|
|
}
|
|
|
|
public static function getMsOrderStaticFile($files, $forceTimestamp = null) {
|
|
if (empty($files)) {
|
|
return ;
|
|
}
|
|
return self::getStaticFile($files, $forceTimestamp);
|
|
}
|
|
|
|
/**
|
|
* 获取静态资源文件
|
|
*
|
|
* @param unknown_type $filename
|
|
*/
|
|
public static function getStaticFile($filename, $forceTimestamp = false) {
|
|
$staticUrlPart = self::getStaticUrlPart(true);
|
|
$files = array ();
|
|
$static = array ();
|
|
|
|
if (is_array($filename)) {
|
|
$files = $filename;
|
|
} elseif (is_string($filename)) {
|
|
$files[] = $filename;
|
|
}
|
|
if (!empty($files)) {
|
|
foreach ($files as $file) {
|
|
$timestamp = '';
|
|
if (strpos($file, '?') !== false) {
|
|
list ($file, $timestamp) = explode('?', $file);
|
|
$timestamp = empty($timestamp) ? '' : ('?' . $timestamp);
|
|
}
|
|
$timestamp = $forceTimestamp ? ('?' . $forceTimestamp) : $timestamp;
|
|
$ext = strrchr($file, '.');
|
|
$static[$ext][] = $file . $timestamp;
|
|
}
|
|
}
|
|
|
|
if (!empty($static)) {
|
|
$output = '';
|
|
foreach ($static as $ext => $files) {
|
|
switch (strtolower($ext)) {
|
|
case '.css' :
|
|
foreach ($files as $f) {
|
|
$output .= '<link rel="stylesheet" href="' . $staticUrlPart . 'css/' . $f . '" />' . "\n";
|
|
}
|
|
break;
|
|
case '.js' :
|
|
foreach ($files as $f) {
|
|
$output .= '<script src="' . $staticUrlPart . 'js/' . $f . '"></script>' . "\n";
|
|
}
|
|
break;
|
|
case '.jpg' :
|
|
case '.gif' :
|
|
case '.png' :
|
|
foreach ($files as $f) {
|
|
$output = $staticUrlPart . 'img/' . $f;
|
|
}
|
|
break;
|
|
default :
|
|
foreach ($files as $f) {
|
|
$output = $staticUrlPart . $f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
public static function getStaticCommonFile($files, $forceTimestamp = '') {
|
|
$static = array();
|
|
$staticDir = str_replace('\\', '/', Zc::C(ZcConfigConst::DirWsApp));
|
|
$apiPath = stripos(Zc::C('static.domain'), 'api.') === 0 ? '/' : '/api/';
|
|
$staticUrlPart = AppConst::getCurProtocol() . '://' . Zc::C('static.domain') . $apiPath . $staticDir . 'views/static_common/';
|
|
$files = is_array($files) ? $files : [$files];
|
|
foreach ($files as $file) {
|
|
$timestamp = '';
|
|
list ($file, $timestamp) = explode('?', $file);
|
|
$timestamp = empty($timestamp) ? '' : ('?' . $timestamp);
|
|
$timestamp = $forceTimestamp ? ('?' . $forceTimestamp) : $timestamp;
|
|
$ext = strrchr($file, '.');
|
|
$static[$ext][] = $file . $timestamp;
|
|
}
|
|
|
|
$output = '';
|
|
foreach ($static as $ext => $files) {
|
|
switch (strtolower($ext)) {
|
|
case '.css' :
|
|
foreach ($files as $f) {
|
|
$output .= '<link rel="stylesheet" href="' . $staticUrlPart . 'css/' . $f . '" />' . "\n";
|
|
}
|
|
break;
|
|
case '.js' :
|
|
foreach ($files as $f) {
|
|
$output .= '<script src="' . $staticUrlPart . 'js/' . $f . '"></script>' . "\n";
|
|
}
|
|
break;
|
|
default :
|
|
foreach ($files as $f) {
|
|
$output = $staticUrlPart . $f;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
public static function checkIsCloseSidebarMenu() {
|
|
$cookieKey = $_SESSION[SessionConst::mallId] . '_getSideBarCookieKey';
|
|
return $_COOKIE[$cookieKey] == 'close';
|
|
}
|
|
|
|
public static function getTbkOrderStaticFile($files, $forceTimestamp = null) {
|
|
if (empty($files)) {
|
|
return ;
|
|
}
|
|
return self::getStaticFile($files, $forceTimestamp);
|
|
}
|
|
|
|
public static function renderLogisticsStatus($logisticsStatus) {
|
|
switch ($logisticsStatus) {
|
|
case OrderPrintConst::logisticsActionGot:
|
|
return '已揽件';
|
|
case OrderPrintConst::logisticsActionSend:
|
|
return '派件';
|
|
case OrderPrintConst::logisticsActionSign:
|
|
return '签收';
|
|
case OrderPrintConst::logisticsActionRejection:
|
|
return '拒签';
|
|
case OrderPrintConst::logisticsActionReturn:
|
|
return '退件';
|
|
case OrderPrintConst::logisticsActionArrival:
|
|
case OrderPrintConst::logisticsActionDeparture:
|
|
return '流转中';
|
|
case OrderPrintConst::logisticsActionFail:
|
|
return '问题件';
|
|
case OrderPrintConst::logisticsActionStayInWarehouse:
|
|
return '留仓';
|
|
case OrderPrintConst::logisticsActionSignOnBehalf:
|
|
return '代收点代签';
|
|
case OrderPrintConst::logisticsActionOther:
|
|
return '其他';
|
|
case OrderPrintConst::logisticsActionInCabinet:
|
|
return '入代收点';
|
|
case OrderPrintConst::logisticsActionOutCabinet:
|
|
return '出代收点';
|
|
case OrderPrintConst::logisticsActionClearanceStart:
|
|
return '清关中';
|
|
case OrderPrintConst::logisticsActionClearanceFinish:
|
|
return '清关完成';
|
|
}
|
|
return '-';
|
|
}
|
|
|
|
public static function buildLogisticsWarningHtml($warningType, $logisticsStatus) {
|
|
if (in_array($logisticsStatus, OrderPrintConst::getLogisticsRejectActions())) {
|
|
return '<span class="label label-danger ws-normal">买家拒收</span>';
|
|
}
|
|
switch ($warningType) {
|
|
case OrderPrintConst::logisticsFilterOvertimeGot:
|
|
return '<span class="label label-danger ws-normal">超时未揽收</span>';
|
|
case OrderPrintConst::logisticsFilterOvertimeNoArrival:
|
|
return '<span class="label label-danger ws-normal">超时未流转</span>';
|
|
case OrderPrintConst::logisticsFilterOvertimeNoNewTrace:
|
|
return '<span class="label label-danger ws-normal">超时无物流更新</span>';
|
|
case OrderPrintConst::logisticsFilterOvertimeNoSign:
|
|
return '<span class="label label-danger ws-normal">超时未签收</span>';
|
|
case OrderPrintConst::logisticsFilterRejection:
|
|
return '<span class="label label-danger ws-normal">买家拒收</span>';
|
|
case OrderPrintConst::logisticsFilterAllocateStay:
|
|
return '<span class="label label-danger ws-normal">分拨停留</span>';
|
|
case OrderPrintConst::logisticsFilterNodeStayJZHW:
|
|
return '<span class="label label-danger ws-normal">江浙沪皖节点停留</span>';
|
|
case OrderPrintConst::logisticsFilterNodeStayJJJ:
|
|
return '<span class="label label-danger ws-normal">京津冀节点停留</span>';
|
|
case OrderPrintConst::logisticsFilterNodeStayTYSF:
|
|
return '<span class="label label-danger ws-normal">同意省份节点停留</span>';
|
|
case OrderPrintConst::logisticsFilterNodeStayBTSF:
|
|
return '<span class="label label-danger ws-normal">不同省份节点停留</span>';
|
|
case OrderPrintConst::logisticsFilterNodeStayXXN:
|
|
return '<span class="label label-danger ws-normal">任一地址在新疆、西藏或内蒙古节点停留</span>';
|
|
|
|
}
|
|
}
|
|
} |