Преглед изворни кода

Merge remote-tracking branch 'origin/master' into php8

github-actions[bot] пре 3 година
родитељ
комит
476aa0d3f1
2 измењених фајлова са 31 додато и 4 уклоњено
  1. 14 4
      lib/Controller.php
  2. 17 0
      tst/JsonApiTest.php

+ 14 - 4
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: *');

+ 17 - 0
tst/JsonApiTest.php

@@ -253,6 +253,23 @@ class JsonApiTest extends 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
      */