6
6
7
7
function getUrl (): ?string
8
8
{
9
- $ skipParams = ['url ' , 'instagram_token ' , ' facebook_token ' ];
9
+ $ skipParams = ['url ' , 'settings ' ];
10
10
$ url = getParam ('url ' );
11
11
12
12
if (!$ url ) {
@@ -30,6 +30,12 @@ function getParam(string $paramName): ?string
30
30
return $ _GET [$ paramName ] ?? null ;
31
31
}
32
32
33
+ function getJsonSettings (): array
34
+ {
35
+ $ jsonString = getParam ('settings ' ) ?: '{} ' ;
36
+ return json_decode ($ jsonString , true , 512 , JSON_THROW_ON_ERROR );
37
+ }
38
+
33
39
function getEscapedUrl (): ?string
34
40
{
35
41
$ url = getUrl ();
@@ -148,7 +154,7 @@ function printCode(?string $code, bool $asHtml = true): void
148
154
form { background: #EEE; border-bottom: solid 1px #DDD; color: #666; padding: 3em 1.5em; }
149
155
fieldset { border: none; padding: 0; }
150
156
label { display: block; cursor: pointer; font-weight: bold; }
151
- input[type="url"] { border: none; background: white; border-radius: 2px; box-sizing: border-box; width: 100%; margin: 5px 0; font-size: 1.3em; padding: 0.5em; color: #666; }
157
+ input[type="url"], textarea { border: none; background: white; border-radius: 2px; box-sizing: border-box; min- width: 100%; margin: 5px 0; font-size: 1.3em; padding: 0.5em; color: #666; }
152
158
button, summary { font-size: 1.6rem; font-weight: bold; font-family: Arial; background: yellowgreen; border: none; border-radius: 3px; padding: 0.3em 1em; cursor: pointer; margin-top: 5px; }
153
159
button:hover, summary:hover { background: black; color: white; }
154
160
details {
@@ -159,7 +165,7 @@ function printCode(?string $code, bool $asHtml = true): void
159
165
width: max-content;
160
166
margin: auto;
161
167
}
162
-
168
+ .helptext { font-weight: normal; font-size: 0.75em; }
163
169
/* result */
164
170
main { padding: 1.5em; }
165
171
main h1, main h2 { font-size: 2em; color: #666; letter-spacing: -0.02em; }
@@ -179,12 +185,17 @@ function printCode(?string $code, bool $asHtml = true): void
179
185
<input type="url" name="url" autofocus placeholder="http://" value="<?php echo getEscapedUrl (); ?> ">
180
186
</label>
181
187
<label>
182
- <span>Instagram Token:</span>
183
- <input type="text" name="instagram_token" placeholder="1234|5678" value="<?php echo getParam ('instagram_token ' ); ?> ">
184
- </label>
185
- <label>
186
- <span>Facebook Token:</span>
187
- <input type="text" name="facebook_token" placeholder="1234|5678" value="<?php echo getParam ('facebook_token ' ); ?> ">
188
+ <span>Settings:</span>
189
+ <?php
190
+ $ placeholderJson = json_encode (['instagram:token ' => null ], JSON_PRETTY_PRINT );
191
+ $ currentJson = getJsonSettings ();
192
+ ?>
193
+ <textarea name="settings" rows="3" placeholder='<?php echo $ placeholderJson ; ?> '><?php
194
+ echo !empty ($ currentJson )
195
+ ? json_encode ($ currentJson , JSON_PRETTY_PRINT | JSON_FORCE_OBJECT )
196
+ : '' ;
197
+ ?> </textarea>
198
+ <span class="helptext">Add settings like "instagram:token", "facebook:token", ...</span>
188
199
</label>
189
200
</fieldset>
190
201
@@ -208,11 +219,12 @@ function printCode(?string $code, bool $asHtml = true): void
208
219
]);
209
220
210
221
$ embed ->setSettings (
211
- [
212
- 'twitch:parent ' => $ _SERVER ['SERVER_NAME ' ] === 'localhost ' ? null : $ _SERVER ['SERVER_NAME ' ],
213
- 'instagram:token ' => getParam ('instagram_token ' ),
214
- 'facebook:token ' => getParam ('facebook_token ' ),
215
- ]
222
+ array_merge (
223
+ [
224
+ 'twitch:parent ' => $ _SERVER ['SERVER_NAME ' ] === 'localhost ' ? null : $ _SERVER ['SERVER_NAME ' ],
225
+ ],
226
+ getJsonSettings ()
227
+ )
216
228
);
217
229
$ info = $ embed ->get (getUrl ());
218
230
} catch (Exception $ exception ) {
0 commit comments