66
77function getUrl (): ?string
88{
9- $ skipParams = ['url ' , 'instagram_token ' , ' facebook_token ' ];
9+ $ skipParams = ['url ' , 'settings ' ];
1010 $ url = getParam ('url ' );
1111
1212 if (!$ url ) {
@@ -30,6 +30,12 @@ function getParam(string $paramName): ?string
3030 return $ _GET [$ paramName ] ?? null ;
3131}
3232
33+ function getJsonSettings (): array
34+ {
35+ $ jsonString = getParam ('settings ' ) ?: '{} ' ;
36+ return json_decode ($ jsonString , true , 512 , JSON_THROW_ON_ERROR );
37+ }
38+
3339function getEscapedUrl (): ?string
3440{
3541 $ url = getUrl ();
@@ -148,7 +154,7 @@ function printCode(?string $code, bool $asHtml = true): void
148154 form { background: #EEE; border-bottom: solid 1px #DDD; color: #666; padding: 3em 1.5em; }
149155 fieldset { border: none; padding: 0; }
150156 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; }
152158 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; }
153159 button:hover, summary:hover { background: black; color: white; }
154160 details {
@@ -159,7 +165,7 @@ function printCode(?string $code, bool $asHtml = true): void
159165 width: max-content;
160166 margin: auto;
161167 }
162-
168+ .helptext { font-weight: normal; font-size: 0.75em; }
163169 /* result */
164170 main { padding: 1.5em; }
165171 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
179185 <input type="url" name="url" autofocus placeholder="http://" value="<?php echo getEscapedUrl (); ?> ">
180186 </label>
181187 <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>
188199 </label>
189200 </fieldset>
190201
@@ -208,11 +219,12 @@ function printCode(?string $code, bool $asHtml = true): void
208219 ]);
209220
210221 $ 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+ )
216228 );
217229 $ info = $ embed ->get (getUrl ());
218230 } catch (Exception $ exception ) {
0 commit comments