-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
416 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* +----------------------------------------------------------------------+ | ||
* | ThinkSNS Plus | | ||
* +----------------------------------------------------------------------+ | ||
* | Copyright (c) 2017 Chengdu ZhiYiChuangXiang Technology Co., Ltd. | | ||
* +----------------------------------------------------------------------+ | ||
* | This source file is subject to version 2.0 of the Apache license, | | ||
* | that is bundled with this package in the file LICENSE, and is | | ||
* | available through the world-wide-web at the following url: | | ||
* | http://www.apache.org/licenses/LICENSE-2.0.html | | ||
* +----------------------------------------------------------------------+ | ||
* | Author: Slim Kit Group <[email protected]> | | ||
* | Homepage: www.thinksns.com | | ||
* +----------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Zhiyi\Plus\Http\Controllers\Admin; | ||
|
||
use Illuminate\Http\Response; | ||
use Illuminate\Http\JsonResponse; | ||
use Zhiyi\Plus\Support\Configuration; | ||
use Zhiyi\Plus\Http\Requests\Admin\UpdateWebClientRequest; | ||
|
||
class WebClientsController | ||
{ | ||
/** | ||
* Fetch web clients setting data. | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
* @author Seven Du <[email protected]> | ||
*/ | ||
public function fetch(): JsonResponse | ||
{ | ||
return response()->json([ | ||
'web' => [ | ||
'open' => (bool) config('http.web.open', false), | ||
'url' => (string) config('http.web.url', ''), | ||
], | ||
'spa' => [ | ||
'open' => (bool) config('http.spa.open', false), | ||
'url' => (string) config('http.spa.url', ''), | ||
], | ||
], 200); | ||
} | ||
|
||
/** | ||
* Update web clients settings. | ||
* | ||
* @param \Zhiyi\Plus\Http\Requests\Admin\UpdateWebClientRequest $request | ||
* @param \Zhiyi\Plus\Support\Configuration $config | ||
* @return \Illuminate\Http\Response | ||
* @author Seven Du <[email protected]> | ||
*/ | ||
public function update(UpdateWebClientRequest $request, Configuration $config): Response | ||
{ | ||
$config->set([ | ||
'http.web.open' => (bool) $request->input('web.open'), | ||
'http.web.url' => $request->input('web.url'), | ||
'http.spa.open' => (bool) $request->input('spa.open'), | ||
'http.spa.url' => $request->input('spa.url'), | ||
]); | ||
|
||
return response('', 204); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,88 +20,29 @@ | |
|
||
namespace Zhiyi\Plus\Http\Controllers; | ||
|
||
use Jenssegers\Agent\Agent; | ||
|
||
class HomeController | ||
{ | ||
public function welcome() | ||
/** | ||
* Home page. | ||
* | ||
* @param \Jenssegers\Agent\Agent $agent | ||
* @return mixed | ||
* @author Seven Du <[email protected]> | ||
*/ | ||
public function welcome(Agent $agent) | ||
{ | ||
$pcConfig = config('pc'); | ||
$h5Config = config('h5'); | ||
|
||
// 临时方案,后续会有骚操作 | ||
if ($h5Config && isset($h5Config['installed']) && $this->isMobile()) { | ||
return redirect()->route($h5Config['routeName']); | ||
} | ||
// If request client is mobile and opened SPA. | ||
if ($agent->isMobile() && config('http.spa.open')) { | ||
return redirect(config('http.spa.url')); | ||
|
||
if ($pcConfig && isset($pcConfig['installed']) && ! $this->isMobile()) { | ||
return redirect()->route($pcConfig['routeName']); | ||
// If web is opened. | ||
} elseif (config('http.web.open')) { | ||
return redirect(config('http.web.url')); | ||
} | ||
|
||
// By default, view welcome page. | ||
return view('welcome'); | ||
} | ||
|
||
public function isMobile() | ||
{ | ||
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备 | ||
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) { | ||
return true; | ||
} | ||
// 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息 | ||
if (isset($_SERVER['HTTP_VIA'])) { | ||
// 找不到为flase,否则为true | ||
|
||
return stristr($_SERVER['HTTP_VIA'], 'wap') ? true : false; | ||
} | ||
// 脑残法,判断手机发送的客户端标志,兼容性有待提高。其中'MicroMessenger'是电脑微信 | ||
if (isset($_SERVER['HTTP_USER_AGENT'])) { | ||
$clientkeywords = [ | ||
'nokia', | ||
'sony', | ||
'ericsson', | ||
'mot', | ||
'samsung', | ||
'htc', | ||
'sgh', | ||
'lg', | ||
'sharp', | ||
'sie-', | ||
'philips', | ||
'panasonic', | ||
'alcatel', | ||
'lenovo', | ||
'iphone', | ||
'ipod', | ||
'blackberry', | ||
'meizu', | ||
'android', | ||
'netfront', | ||
'symbian', | ||
'ucweb', | ||
'windowsce', | ||
'palm', | ||
'operamini', | ||
'operamobi', | ||
'openwave', | ||
'nexusone', | ||
'cldc', | ||
'midp', | ||
'wap', | ||
'mobile', | ||
'MicroMessenger', | ||
]; | ||
// 从HTTP_USER_AGENT中查找手机浏览器的关键字 | ||
if (preg_match('/('.implode('|', $clientkeywords).')/i', strtolower($_SERVER['HTTP_USER_AGENT']))) { | ||
return true; | ||
} | ||
} | ||
// 协议法,因为有可能不准确,放到最后判断 | ||
if (isset($_SERVER['HTTP_ACCEPT'])) { | ||
// 如果只支持wml并且不支持html那一定是移动设备 | ||
// 如果支持wml和html但是wml在html之前则是移动设备 | ||
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* +----------------------------------------------------------------------+ | ||
* | ThinkSNS Plus | | ||
* +----------------------------------------------------------------------+ | ||
* | Copyright (c) 2017 Chengdu ZhiYiChuangXiang Technology Co., Ltd. | | ||
* +----------------------------------------------------------------------+ | ||
* | This source file is subject to version 2.0 of the Apache license, | | ||
* | that is bundled with this package in the file LICENSE, and is | | ||
* | available through the world-wide-web at the following url: | | ||
* | http://www.apache.org/licenses/LICENSE-2.0.html | | ||
* +----------------------------------------------------------------------+ | ||
* | Author: Slim Kit Group <[email protected]> | | ||
* | Homepage: www.thinksns.com | | ||
* +----------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Zhiyi\Plus\Http\Requests\Admin; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class UpdateWebClientRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
* @author Seven Du <[email protected]> | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
* @author Seven Du <[email protected]> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'web' => 'array', | ||
'web.url' => 'nullable|string|url', | ||
'web.open' => 'nullable|boolean', | ||
'spa' => 'array', | ||
'spa.url' => 'nullable|string|url', | ||
'spa.open' => 'nullable|boolean', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.