Skip to content

Commit

Permalink
Merge branch '1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Mar 30, 2018
2 parents c2dffaf + d83ca60 commit 62b1cd2
Show file tree
Hide file tree
Showing 19 changed files with 416 additions and 166 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function server(ResponseFactory $response)
'agent' => $_SERVER['HTTP_USER_AGENT'],
'protocol' => $_SERVER['SERVER_PROTOCOL'],
'method' => $_SERVER['REQUEST_METHOD'],
'laravel_version' => app()::VERSION,
'laravel_version' => app()->getLaravelVersion(),
'max_upload_size' => ini_get('upload_max_filesize'),
'execute_time' => ini_get('max_execution_time').'',
'server_date' => date('Y年n月j日 H:i:s'),
Expand Down
69 changes: 69 additions & 0 deletions app/Http/Controllers/Admin/WebClientsController.php
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);
}
}
93 changes: 17 additions & 76 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
55 changes: 55 additions & 0 deletions app/Http/Requests/Admin/UpdateWebClientRequest.php
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',
];
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"fideloper/proxy": "~4.0",
"guzzlehttp/guzzle": "^6.3",
"intervention/image": "^2.3",
"jenssegers/agent": "^2.6",
"jpush/jpush": "^3.5",
"laravel/framework": "5.6.*",
"laravel/tinker": "~1.0",
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"babel-preset-env": "^1.6.1",
"babel-preset-stage-2": "^6.24.1",
"cross-env": "^5.1",
"laravel-mix": "^2.0"
"laravel-mix": "^2.0",
"vue-template-compiler": "^2.5.16"
},
"dependencies": {
"axios": "^0.18",
Expand All @@ -30,7 +31,8 @@
"markdown-it": "^8.4.0",
"opencollective": "^1.0.3",
"plus-message-bundle": "^1.0",
"vue": "^2.5.13",
"simkit-bootstrap-ui-kit": "^0.0.3",
"vue": "^2.5.16",
"vue-echarts-v3": "^1.0.18",
"vue-router": "^3.0.1",
"vuex": "^3.0.1",
Expand All @@ -41,4 +43,4 @@
"url": "https://opencollective.com/thinksns-plus",
"logo": "https://opencollective.com/thinksns-plus/logo.txt"
}
}
}
2 changes: 1 addition & 1 deletion public/assets/css/bootstrap.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/js/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/js/bootstrap.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/js/installer.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion resources/assets/admin/component/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ $lefyNavWidth: 240px;
<!-- The content container. -->
<router-view class="pull-right context-container"></router-view>
<!-- End content container. -->
<module-alert></module-alert>
</div>
</template>

Expand All @@ -86,6 +87,7 @@ import DefaultAvatar from '../icons/default-avatar';
// components.
import Nav from './Nav';
import Alert from '../components/modules/Alert';
const home = {
computed: {
Expand All @@ -98,7 +100,8 @@ const home = {
},
components: {
'system-nav': Nav,
'default-avatar': DefaultAvatar
'default-avatar': DefaultAvatar,
[Alert.name]: Alert,
}
};
Expand Down
20 changes: 0 additions & 20 deletions resources/assets/admin/component/Nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@
<span class="glyphicon glyphicon-cog __icon"></span>
系统设置
</router-link>
<a href="javascript:;" class="list-group-item __button" @click="clearSiteCache">
<span class="glyphicon glyphicon-cog __icon"></span>
清除缓存
</a>
<!-- <router-link class="list-group-item __button" to="/gold" active-class="active" >
<span class="glyphicon glyphicon-usd __icon"></span>
金币设置
</router-link> -->
<!-- CDN -->
<router-link class="list-group-item __button" to="/currency" active-class="active">
<span class="glyphicon glyphicon-asterisk __icon"></span>
积分设置
Expand Down Expand Up @@ -132,17 +123,6 @@ const nav = {
manages: MANAGES_GET
})
},
methods: {
clearSiteCache() {
request.get(createRequestURI('auxiliary/clear'),
{ validateStatus: status => status === 200})
.then(({data}) => {
window.alert('清除成功');
}).catch(({response: {data = {message: '获取失败'}} = {}}) => {
window.alert('清除失败');
});
}
},
created() {
this.$store.dispatch(MANAGES_SET, cb => request.get(
createRequestURI('manages'),
Expand Down
8 changes: 8 additions & 0 deletions resources/assets/admin/component/setting/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,22 @@
</form>
</div>
</div>

<!-- web clients -->
<web-clients />

</div>
</template>

<script>
import { SETTINGS_SITE_UPDATE } from '../../store/types';
import request, { createRequestURI } from '../../util/request';
import WebClients from '../../components/modules/setting/WebClients';
const settingBase = {
components: {
'web-clients': WebClients,
},
data: () => ({
btnLoading: false,
loadding: true,
Expand Down
Loading

0 comments on commit 62b1cd2

Please sign in to comment.