-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
231 lines (210 loc) · 7.64 KB
/
index.html
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Liste des fonctions - PHP Functions</title>
<!-- Metas SEO -->
<meta
name="description"
content="Plateforme de création de fonctions PHP sans serveur."
/>
<meta name="keywords" content="PHP, serverless, functions" />
<meta name="subject" content="Fonctions PHP" />
<meta name="copyright" content="Dimitri ONGOUA" />
<meta name="author" content="Dimitri ONGOUA" />
<meta name="identifier-url" content="https://php-funcs.netlify.app" />
<!-- Open Graph Metas -->
<meta property="og:title" content="Liste des fonctions - PHP Functions" />
<meta property="og:site_name" content="PHP Functions" />
<meta property="og:url" content="https://php-funcs.netlify.app" />
<meta
property="og:description"
content="Plateforme de création de fonctions PHP sans serveur."
/>
<meta property="og:type" content="website" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css"
/>
<!-- Font Awesome Icons -->
<script
defer
src="https://use.fontawesome.com/releases/v5.14.0/js/all.js"
></script>
<script
type="text/javascript"
src="https://identity.netlify.com/v1/netlify-identity-widget.js"
></script>
</head>
<body class="has-background-light is-hidden">
<section class="section pt-0">
<div class="container is-fullhd">
<div
class="notification is-light is-flex is-justify-content-space-between has-background-dark"
>
<h1 class="is-unselectable has-text-white">PHP Functions</h1>
<div class="field is-horizontal mb-0">
<div class="field-body">
<div class="field is-expanded">
<div class="field has-addons">
<p class="control is-expanded">
<input
class="input is-small"
type="text"
id="funcname"
placeholder="Nom de la fonction"
/>
</p>
<button
class="button is-small is-link is-warning"
onclick="create_function()"
>
<span class="icon is-small">
<i class="fa fa-plus-circle"></i>
</span>
<span>Créer la fonction</span>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="box">
<article class="media">
<div class="media-left is-hidden">
<figure class="image is-64x64">
<img src="" alt="Photo de profil" class="is-rounded" />
</figure>
</div>
<div class="media-content">
<div class="content mt-2">
<p>
<strong id="username">Dimitri ONGOUA</strong>
<br />
<a
class="is-size-7 is-clickable has-text-info"
onclick="netlifyIdentity.logout()"
>
Déconnexion
</a>
</p>
</div>
</div>
</article>
</div>
<div class="notification is-hidden message-no-functions">
<h2 class="title">Créez votre première fonction</h2>
Vous n'avez pas encore de fonctions. Vous pouvez en créer grâce à la
section en haut à droite.
</div>
<table class="table is-fullwidth is-hidden">
<thead>
<tr>
<th>Nom de la fonction</th>
<th>URL</th>
<th>Actions</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</section>
<script>
window.baseURL = "https://mende.alwaysdata.net/funcs";
netlifyIdentity.setLocale("fr");
netlifyIdentity.on("init", (user) => {
if (!user && !location.href.includes("gitpod")) {
location.href = "/login";
} else {
const username = user.user_metadata.full_name;
document.getElementById("username").textContent = username;
if (user.user_metadata.avatar_url) {
const img = document.querySelector("figure img");
img.setAttribute("src", user.user_metadata.avatar_url);
document.querySelector(".media-left").classList.remove("is-hidden");
}
get_functions();
document.querySelector("body").classList.remove("is-hidden");
}
});
netlifyIdentity.on("logout", () => {
location.href = "/login";
});
function create_function() {
checkUser();
const funcnameEl = document.querySelector("#funcname");
funcnameEl.setAttribute("disabled", "true");
if (!funcnameEl.value) return;
const user = netlifyIdentity.currentUser();
const func = {
owner: user.id,
name: funcnameEl.value,
code: "[pf::init]",
};
fetch(`${window.baseURL}/save`, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: `funcowner=${func.owner}&funcname=${func.name}&funccode=${func.code}`,
})
.then((res) => {
return res.json();
})
.then((res) => {
location.href = `edit?url=${window.baseURL}/${func.owner}/${func.name}`;
})
.catch((err) => {
funcnameEl.removeAttribute("disabled");
console.error(err);
});
}
function get_functions() {
checkUser();
const user = netlifyIdentity.currentUser();
const owner = user.id;
fetch(`${window.baseURL}/${owner}/functions`)
.then((res) => {
return res.json();
})
.then((res) => {
if (!res.funcs) {
document
.querySelector(".message-no-functions")
.classList.remove("is-hidden");
return;
}
document.querySelector("table").classList.toggle("is-hidden");
const listEl = document.querySelector("tbody");
res.funcs.forEach((func) => {
listEl.innerHTML += `<tr>
<th>
<a href="edit?url=${func.url}">${func.name}</a>
<p class="is-size-7" style="max-width: 300px">${func.desc}</p>
</th>
<th><a href="${func.url}" title="Cliquez pour tester" target="_blank" class="has-text-grey is-family-code has-text-weight-light is-size-7">${func.url}</a></th>
<td>
<div class="buttons are-small">
<a href="edit?url=${func.url}" class="button is-primary">
<span class="icon is-small"><i class="fa fa-keyboard"></i></span>
<span>Modifier</span>
</a>
</div>
</td>
</tr>`;
});
})
.catch((err) => {
console.error(err);
});
}
function checkUser() {
const user = netlifyIdentity.currentUser();
if (!user) {
location.href = "/login";
}
}
</script>
</body>
</html>