From bf7d2f05b65ecee3a15f185b917b6f4c95a3b0da Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 15 Jan 2023 08:04:21 +0100 Subject: [PATCH 1/2] expose types JSON-LD incl. configured expiration dates, resolves #1045 --- lib/Controller.php | 18 ++++++++++++++---- tst/JsonApiTest.php | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/Controller.php b/lib/Controller.php index 66376e40..6a76e74a 100644 --- a/lib/Controller.php +++ b/lib/Controller.php @@ -425,10 +425,13 @@ class Controller */ private function _jsonld($type) { - if ( - $type !== 'paste' && $type !== 'comment' && - $type !== 'pastemeta' && $type !== 'commentmeta' - ) { + if (!in_array($type, array( + 'comment', + 'commentmeta', + 'paste', + 'pastemeta', + 'types', + ))) { $type = ''; } $content = '{}'; @@ -440,6 +443,13 @@ class Controller file_get_contents($file) ); } + if ($type === 'types') { + $content = str_replace( + '"' . implode('", "', array_keys($this->_conf->getDefaults()['expire_options'])) . '"', + '"' . implode('", "', array_keys($this->_conf->getSection('expire_options'))) . '"', + $content + ); + } header('Content-type: application/ld+json'); header('Access-Control-Allow-Origin: *'); diff --git a/tst/JsonApiTest.php b/tst/JsonApiTest.php index 9630face..37c69978 100644 --- a/tst/JsonApiTest.php +++ b/tst/JsonApiTest.php @@ -252,6 +252,23 @@ class JsonApiTest extends PHPUnit_Framework_TestCase ), $content, 'outputs data correctly'); } + /** + * @runInSeparateProcess + */ + public function testJsonLdTypes() + { + $_GET['jsonld'] = 'types'; + ob_start(); + new Controller; + $content = ob_get_contents(); + ob_end_clean(); + $this->assertEquals(str_replace( + '?jsonld=', + '/?jsonld=', + file_get_contents(PUBLIC_PATH . '/js/types.jsonld') + ), $content, 'outputs data correctly'); + } + /** * @runInSeparateProcess */ From 3a4e5ed0c9f7cb54bb73114da63a99abe3748722 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 15 Jan 2023 14:45:10 +0100 Subject: [PATCH 2/2] unnecessary string concatenation --- lib/Controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Controller.php b/lib/Controller.php index 6a76e74a..82b246ab 100644 --- a/lib/Controller.php +++ b/lib/Controller.php @@ -445,8 +445,8 @@ class Controller } if ($type === 'types') { $content = str_replace( - '"' . implode('", "', array_keys($this->_conf->getDefaults()['expire_options'])) . '"', - '"' . implode('", "', array_keys($this->_conf->getSection('expire_options'))) . '"', + implode('", "', array_keys($this->_conf->getDefaults()['expire_options'])), + implode('", "', array_keys($this->_conf->getSection('expire_options'))), $content ); }