Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.php
More file actions
Latest commit
159 lines (146 loc) · 4.2 KB
/
Copy pathplugin.php
File metadata and controls
159 lines (146 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* Plugin.php
*
* This file is part of the Xpressengine package.
*
* PHP version 7
*
* @category GoogleAnalytics
* @package Xpressengine\Plugins\GoogleAnalytics
* @author XE Developers <developers@xpressengine.com>
* @copyright 2019 Copyright XEHub Corp. <https://www.xehub.io>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL
* @link https://xpressengine.io
*/
namespaceXpressengine\Plugins\GoogleAnalytics;
useIlluminate\Support\Facades\Artisan;
useRoute;
useValidator;
useView;
useXeFrontend;
useXeRegister;
useXpressengine\Plugin\AbstractPlugin;
useXpressengine\Translation\Translator;
/**
* Plugin
*
* @category GoogleAnalytics
* @package Xpressengine\Plugins\GoogleAnalytics
* @author XE Developers <developers@xpressengine.com>
* @copyright 2019 Copyright XEHub Corp. <https://www.xehub.io>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL
* @link https://xpressengine.io
*/
class Plugin extends AbstractPlugin
{
/**
* boot
*
* @return void
*/
publicfunctionboot()
{
Validator::extend('ga_json', function ($attribute, $value) {
return'json' === $value->getClientOriginalExtension();
});
Validator::replacer('ga_json', function ($message, $attribute, $rule, $parameters) {
returnxe_trans('validation.mimes', ['attribute' => $attribute, 'values' => 'json']);
});
View::addNamespace('ga', __DIR__ . '/views');
Translator::alias('google_analytics', 'ga');
$this->routes();
$this->intercepts();
}
/**
* register
*
* @return void
*/
publicfunctionregister()
{
app()->singleton(Handler::class, function ($app) {
returnnewHandler(
$app,
newSetting($app['xe.config'], $app['xe.storage'], $app['xe.keygen'])
);
}, true);
app()->alias(Handler::class, 'xe.ga');
}
/**
* get setting uri
*
* @return string
*/
publicfunctiongetSettingsURI()
{
returnroute('ga::setting.edit');
}
/**
* add route
*
* @return void
*/
privatefunctionroutes()
{
Route::group(
['namespace' => 'Xpressengine\\Plugins\\GoogleAnalytics\\Controllers', 'as' => 'ga::'],
function () {
requireplugins_path('google_analytics/routes.php');
}
);
}
/**
* register intercept
*
* @return void
*/
privatefunctionintercepts()
{
intercept(
'Presenter@make',
'googleAnalytics.addScript',
function ($target, $id, $data = [], $mergeData = [], $html = true, $api = false) {
/** @var \Illuminate\Routing\Route $route */
$route = app('router')->current();
if ($route && in_array('settings', $route->middleware()) === false) {
$setting = app('xe.ga')->getSetting();
if ($setting->get('trackingId')) {
XeFrontend::html('ga:tracking')->content(
$this->getTrackingCode($setting->get('trackingId'), $setting->get('domain', 'auto'),$setting->get('allClick'))
)->load();
}
}
return$target($id, $data, $mergeData, $html, $api);
}
);
}
/**
* get tracking code
*
* @param string $trackingId tracking id
* @param string $domain domain
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
privatefunctiongetTrackingCode($trackingId, $domain = 'auto', $allClick = null)
{
returnview('ga::tracking', compact('trackingId', 'domain','allClick'));
}
/**
* uninstall
*
* @return void
*/
publicfunctionuninstall()
{
app('xe.ga')->getSetting()->destroy();
}
publicfunctioninstall()
{
Artisan::call('translation:import',[
'name'=>'google_analytics',
'--path' => str_replace(base_path(),'.',self::path('langs/lang.php'))
]);
}
}