FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
wordpress-plugin/src/UI/PageLayoutComponent.php at main · simpleanalytics/wordpress-plugin · GitHub
simpleanalytics
/
wordpress-plugin
Public
Notifications
You must be signed in to change notification settings
Fork
7
Star
4
Code
Issues
2
Pull requests
1
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
wordpress-plugin
/
src
/
UI
/
PageLayoutComponent.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
195 lines (179 loc) · 8.09 KB
Breadcrumbs
wordpress-plugin
/
src
/
UI
/
PageLayoutComponent.php
Copy path
File metadata and controls
195 lines (179 loc) · 8.09 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
namespace
SimpleAnalytics
\
UI
;
use
SimpleAnalytics
\
Settings
\{
AdminPage
,
Tab
};
use
function
SimpleAnalytics
\
get_icon
;
use
const
SimpleAnalytics
\
PLUGIN_URL
;
class
PageLayoutComponent
{
private
const
DASHBOARD_URL
=
'
https://dashboard.simpleanalytics.com/?utm_source=wordpress&utm_medium=plugin&utm_content=go_to_dashboard_button
'
;
private
const
SIGNUP_URL
=
'
https://www.simpleanalytics.com/signup?utm_source=wordpress&utm_medium=plugin&utm_content=signup_link
'
;
/**
* @readonly
* @var \SimpleAnalytics\Settings\AdminPage
*/
private
$
page
;
public
function
__construct
(
AdminPage
$
page
)
{
$
this
->
page
=
$
page
;
}
public
function
__invoke
():
void
{
$
currentTab
=
$
this
->
getCurrentTab
(
$
this
->
page
->
getTabs
());
?>
<style>
#wpwrap {
background: white;
}
#wpcontent {
padding-left: 0;
}
</style>
<template shadowrootmode="open">
<link rel="preconnect" href="https://fonts.bunny.net">
<link rel="stylesheet" href="
<?php
echo
PLUGIN_URL
?>
build/css/settings.css">
<form method="post" action="options.php">
<!-- Hidden fields -->
<?php
settings_fields
(
$
this
->
page
->
getOptionGroup
(
$
currentTab
));
?>
<!-- Header / Nav -->
<header class="pt-5 bg-primaryBg">
<div class="mx-auto max-w-3xl flex-col justify-between gap-5 sm:flex sm:items-baseline">
<div class="flex items-center">
<!-- Logo -->
<a
href="
<?php
echo
esc_url
(
self
::
DASHBOARD_URL
);
?>
"
target="_blank"
class="text-base font-semibold leading-6 text-gray-900"
>
<img
alt="SimpleAnalytics logo"
src="
<?php
echo
PLUGIN_URL
?>
logo.svg"
class="mr-2 inline-block h-10 w-auto text-primary"
>
</a>
<!-- "Open Dashboard" link -->
<a
href="
<?php
echo
esc_url
(
self
::
DASHBOARD_URL
);
?>
"
target="_blank"
class="inline-flex items-center rounded bg-white px-2 py-1 text-xs font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
<?php
echo
get_icon
(
'
external
'
)->
class
(
'
w-3.5 h-3.5 mr-0.5
'
);
?>
Open Dashboard
</a>
</div>
<!-- Tabs -->
<div class="mt-4 sm:mt-0">
<?php
(
new
TabListComponent
(
$
this
->
page
->
getSlug
(),
$
currentTab
,
$
this
->
page
->
getTabs
()))();
?>
</div>
</div>
</header>
<!-- Fields / Layout -->
<div class="mx-auto max-w-3xl bg-white px-4 py-6 sm:px-4 lg:px-0">
<div class="border-b border-gray-900/10 pb-7">
<?php
if
(
$
currentTab
->
getSlug
() ===
'
general
'
):
?>
<?php
$
this
->
renderGeneralTabIntro
();
?>
<?php
endif
;
?>
<?php
$
currentTab
->
render
();
?>
</div>
<?php
if
(
$
currentTab
->
getSlug
() !==
'
general
'
):
?>
<div class="mt-6 flex items-center justify-start gap-x-6">
<button
type="submit"
class="rounded-md px-3 py-2 text-sm font-semibold text-white shadow-sm bg-primary hover:bg-red-500 focus-visible:outline-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2"
>
Save Changes
</button>
</div>
<?php
endif
;
?>
</div>
</form>
<script>
/**
* Add value as a new line to textarea
*
* @param textarea HTMLTextAreaElement
* @param value string
*/
function sa_textarea_add_value(textarea, value) {
if (textarea.value.includes(value)) {
return;
}
if (textarea.value.trim() === "") {
textarea.value = value;
} else {
textarea.value += `\n${value}`;
}
}
</script>
</template>
<script>
// Polyfill in case the browser has no support for shadowRootMode
// 1. https://developer.chrome.com/docs/css-ui/declarative-shadow-dom#polyfill
// 2. https://caniuse.com/mdn-html_elements_template_shadowrootmode
(function attachShadowRoots(root) {
root.querySelectorAll("template[shadowrootmode]").forEach(template => {
const mode = template.getAttribute("shadowrootmode");
const shadowRoot = template.parentNode.attachShadow({ mode });
shadowRoot.appendChild(template.content);
template.remove();
attachShadowRoots(shadowRoot);
});
})(document);
</script>
<?php
}
protected
function
getCurrentTab
(
array
$
tabs
):
Tab
{
$
currentTabSlug
=
$
_GET
[
'
tab
'
] ??
$
tabs
[
0
]->
getSlug
();
return
$
this
->
findTabBySlug
(
$
tabs
,
$
currentTabSlug
) ??
$
tabs
[
0
];
}
protected
function
findTabBySlug
(
array
$
tabs
,
string
$
slug
): ?
Tab
{
foreach
(
$
tabs
as
$
tab
) {
if
(
$
tab
->
getSlug
() ===
$
slug
)
return
$
tab
;
}
return
null
;
}
protected
function
renderGeneralTabIntro
():
void
{
?>
<div class="mb-7" style="max-width: 64ch;">
<p class="text-sm text-gray-700">
Simple Analytics is now added to your WordPress site.
</p>
<p class="mt-4 text-sm text-gray-700">
The plugin collects pageviews in a privacy-first way, without cookies or personal data.
</p>
<p class="mt-4 text-sm text-gray-700">
Your stats will appear in
<a class="text-primary hover:underline" target="_blank" href="
<?php
echo
esc_url
(
self
::
DASHBOARD_URL
);
?>
">
the Simple Analytics dashboard
</a>
within a few minutes.
</p>
<p class="mt-4 text-sm text-gray-700">
To avoid tracking your own visits, go to the "Ignore Rules" tab and ignore visits from logged-in admins.
You can also add your own IP address there.
</p>
<p class="mt-4 text-sm text-gray-700">
To automatically track downloads, outbound links, and email clicks, go to the "Events" tab and enable "Collect automated events".
</p>
<p class="mt-4 text-sm text-gray-700">
No account yet? Create one at
<a class="text-primary hover:underline" target="_blank" href="
<?php
echo
esc_url
(
self
::
SIGNUP_URL
);
?>
">
simpleanalytics.com.
</a>
You can start with a free trial and choose a free or paid plan later.
</p>
<p class="mt-6">
<a
href="
<?php
echo
esc_url
(
self
::
DASHBOARD_URL
);
?>
"
target="_blank"
class="inline-flex items-center rounded bg-primary px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-500"
>
Open dashboard
</a>
</p>
</div>
<?php
}
}
Back
|
FazBrowse Home
|
New Git URL