66
77function getUrl (): ?string
88{
9- $ url = $ _GET ['url ' ] ?? null ;
9+ $ skipParams = ['url ' , 'settings ' ];
10+ $ url = getParam ('url ' );
1011
11- if (empty ( $ url) ) {
12+ if (! $ url ) {
1213 return null ;
1314 }
1415
1516 //fix for unescaped urls
1617 foreach ($ _GET as $ name => $ value ) {
17- if ($ name === ' url ' ) {
18+ if (in_array ( $ name, $ skipParams , true ) ) {
1819 continue ;
1920 }
2021
@@ -24,6 +25,17 @@ function getUrl(): ?string
2425 return $ url ;
2526}
2627
28+ function getParam (string $ paramName ): ?string
29+ {
30+ return $ _GET [$ paramName ] ?? null ;
31+ }
32+
33+ function getJsonSettings (): array
34+ {
35+ $ jsonString = getParam ('settings ' ) ?: '{} ' ;
36+ return json_decode ($ jsonString , true , 512 , JSON_THROW_ON_ERROR );
37+ }
38+
2739function getEscapedUrl (): ?string
2840{
2941 $ url = getUrl ();
@@ -120,7 +132,6 @@ function printCode(?string $code, bool $asHtml = true): void
120132 'cms ' => 'printText ' ,
121133 'language ' => 'printText ' ,
122134 'languages ' => 'printArray ' ,
123- 'cms ' => 'printText ' ,
124135];
125136?>
126137
@@ -143,7 +154,7 @@ function printCode(?string $code, bool $asHtml = true): void
143154 form { background: #EEE; border-bottom: solid 1px #DDD; color: #666; padding: 3em 1.5em; }
144155 fieldset { border: none; padding: 0; }
145156 label { display: block; cursor: pointer; font-weight: bold; }
146- 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; }
147158 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; }
148159 button:hover, summary:hover { background: black; color: white; }
149160 details {
@@ -154,7 +165,7 @@ function printCode(?string $code, bool $asHtml = true): void
154165 width: max-content;
155166 margin: auto;
156167 }
157-
168+ .helptext { font-weight: normal; font-size: 0.75em; }
158169 /* result */
159170 main { padding: 1.5em; }
160171 main h1, main h2 { font-size: 2em; color: #666; letter-spacing: -0.02em; }
@@ -173,6 +184,19 @@ function printCode(?string $code, bool $asHtml = true): void
173184 <span>Url to test:</span>
174185 <input type="url" name="url" autofocus placeholder="http://" value="<?php echo getEscapedUrl (); ?> ">
175186 </label>
187+ <label>
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>
199+ </label>
176200 </fieldset>
177201
178202 <fieldset class="action">
@@ -182,7 +206,7 @@ function printCode(?string $code, bool $asHtml = true): void
182206 </fieldset>
183207 </form>
184208
185- <?php if (getUrl ()): ?>
209+ <?php if (getUrl ()) : ?>
186210 <main>
187211 <h1>Result:</h1>
188212
@@ -193,10 +217,16 @@ function printCode(?string $code, bool $asHtml = true): void
193217 'Accept-Language ' => 'en-US,en;q=0.2 ' ,
194218 'Cache-Control ' => 'max-age=0,no-cache ' ,
195219 ]);
220+
221+ $ embed ->setSettings (
222+ array_merge (
223+ [
224+ 'twitch:parent ' => $ _SERVER ['SERVER_NAME ' ] === 'localhost ' ? null : $ _SERVER ['SERVER_NAME ' ],
225+ ],
226+ getJsonSettings ()
227+ )
228+ );
196229 $ info = $ embed ->get (getUrl ());
197- $ info ->setSettings ([
198- 'twitch:parent ' => $ _SERVER ['SERVER_NAME ' ] === 'localhost ' ? null : $ _SERVER ['SERVER_NAME ' ],
199- ]);
200230 } catch (Exception $ exception ) {
201231 echo '<pre> ' ;
202232 echo $ exception ;
@@ -206,7 +236,7 @@ function printCode(?string $code, bool $asHtml = true): void
206236 ?>
207237
208238 <table>
209- <?php foreach ($ detectors as $ name => $ fn ): ?>
239+ <?php foreach ($ detectors as $ name => $ fn ) : ?>
210240 <tr>
211241 <th><?php echo $ name ; ?> </th>
212242 <td><?php $ fn ($ info ->$ name ); ?> </td>
@@ -250,7 +280,7 @@ function printCode(?string $code, bool $asHtml = true): void
250280 </tr>
251281 </table>
252282
253- <?php if (method_exists ($ info , 'getApi ' )): ?>
283+ <?php if (method_exists ($ info , 'getApi ' )) : ?>
254284 <h2>API data</h2>
255285
256286 <table>
0 commit comments