expose types JSON-LD incl. configured expiration dates, resolves #1045

This commit is contained in:
El RIDO 2023-01-15 08:04:21 +01:00
parent e84a8694e4
commit bf7d2f05b6
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
2 changed files with 31 additions and 4 deletions

View File

@ -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: *');

View File

@ -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
*/