add option for sending usage statistics

This commit is contained in:
printempw 2017-01-14 23:33:01 +08:00
parent 9486f19f5d
commit 5f9eb0b6fd
7 changed files with 33 additions and 5 deletions

View File

@ -136,6 +136,8 @@ class AdminController extends Controller
$form->textarea('comment_script')->rows(6)->description(OptionForm::AUTO_DETECT); $form->textarea('comment_script')->rows(6)->description(OptionForm::AUTO_DETECT);
$form->checkbox('allow_sending_statistic')->label(OptionForm::AUTO_DETECT)->hint(OptionForm::AUTO_DETECT);
})->handle(function() { })->handle(function() {
if (substr($_POST['site_url'], -1) == "/") if (substr($_POST['site_url'], -1) == "/")
$_POST['site_url'] = substr($_POST['site_url'], 0, -1); $_POST['site_url'] = substr($_POST['site_url'], 0, -1);

View File

@ -36,7 +36,8 @@ class AppServiceProvider extends ServiceProvider
Event::listen(Events\RenderingHeader::class, function($event) { Event::listen(Events\RenderingHeader::class, function($event) {
// provide some application information for javascript // provide some application information for javascript
$blessing = array_merge(Arr::except(config('app'), ['key', 'providers', 'aliases', 'cipher', 'log', 'url']), [ $blessing = array_merge(Arr::except(config('app'), ['key', 'providers', 'aliases', 'cipher', 'log', 'url']), [
'baseUrl' => url('/'), 'base_url' => url('/'),
'site_name' => option('site_name')
]); ]);
$event->addContent('<script>var blessing = '.json_encode($blessing).';</script>'); $event->addContent('<script>var blessing = '.json_encode($blessing).';</script>');

View File

@ -3,7 +3,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-07-29 11:53:11 * @Date: 2016-07-29 11:53:11
* @Last Modified by: printempw * @Last Modified by: printempw
* @Last Modified time: 2016-12-31 23:34:17 * @Last Modified time: 2017-01-14 22:05:22
*/ */
return [ return [
@ -20,6 +20,7 @@ return [
'custom_js' => '', 'custom_js' => '',
'allow_chinese_playername' => 'true', 'allow_chinese_playername' => 'true',
'comment_script' => '', 'comment_script' => '',
'allow_sending_statistic' => 'true',
'user_initial_score' => '1000', 'user_initial_score' => '1000',
'sign_gap_time' => '24', 'sign_gap_time' => '24',
'sign_score' => '10,100', 'sign_score' => '10,100',

View File

@ -2,7 +2,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-09-15 10:39:41 * @Date: 2016-09-15 10:39:41
* @Last Modified by: printempw * @Last Modified by: printempw
* @Last Modified time: 2016-12-17 18:47:02 * @Last Modified time: 2017-01-14 22:36:55
*/ */
'use strict'; 'use strict';
@ -22,7 +22,7 @@ function logout(with_out_confirm, callback) {
html: json.msg html: json.msg
}); });
window.setTimeout(function() { window.setTimeout(function() {
window.location = blessing.baseUrl; window.location = blessing.base_url;
}, 1000); }, 1000);
}); });
}); });
@ -36,7 +36,7 @@ function logout(with_out_confirm, callback) {
function do_logout(callback) { function do_logout(callback) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: blessing.baseUrl + "/auth/logout", url: blessing.base_url + "/auth/logout",
dataType: "json", dataType: "json",
success: function(json) { success: function(json) {
if (callback) callback(json); if (callback) callback(json);

View File

@ -83,6 +83,10 @@ auto_del_invalid_texture:
comment_script: comment_script:
title: Comment Script title: Comment Script
description: Placeholders are available in comment scripts. <code>{tid}</code> will be replaced with texture id, <code>{name}</code> will be replaced with texture name, <code>{url}</code> will be replaced with current URL. description: Placeholders are available in comment scripts. <code>{tid}</code> will be replaced with texture id, <code>{name}</code> will be replaced with texture name, <code>{url}</code> will be replaced with current URL.
allow_sending_statistic:
title: Statistics
label: Send usage statistics anonymously.
hint: Information about privacy will nerver be sent.
announ: announ:
title: Site Announcement title: Site Announcement

View File

@ -83,6 +83,10 @@ auto_del_invalid_texture:
comment_script: comment_script:
title: 评论代码 title: 评论代码
description: 评论代码内可使用占位符,<code>{tid}</code> 将会被自动替换为材质的 id<code>{name}</code> 会被替换为材质名称,<code>{url}</code> 会被替换为当前页面地址。 description: 评论代码内可使用占位符,<code>{tid}</code> 将会被自动替换为材质的 id<code>{name}</code> 会被替换为材质名称,<code>{url}</code> 会被替换为当前页面地址。
allow_sending_statistic:
title: 统计信息
label: 发送程序使用情况统计信息以帮助开发
hint: 隐私信息不会被收集
announ: announ:
title: 站点公告 title: 站点公告

View File

@ -128,6 +128,22 @@
</script> </script>
@endif @endif
@if (option('allow_sending_statistic'))
<script>
blessing.site_url = blessing.base_url;
$.ajax({
url: 'https://work.prinzeugen.net/statistics/feedback',
type: 'POST',
dataType: 'json',
data: blessing
}).done(function() {
console.log('Feedback sent. Thank you!');
});
</script>
@endif
@yield('script') @yield('script')
</body> </body>
</html> </html>