Visman 1 rok pred
rodič
commit
ea95760c46

+ 6 - 0
app/Controllers/Routing.php

@@ -182,6 +182,12 @@ class Routing
                     'Search:action',
                     'Search:action',
                     'SearchAction'
                     'SearchAction'
                 );
                 );
+                $r->add(
+                    $r::GET,
+                    '/opensearch.xml',
+                    'Misc:opensearch',
+                    'OpenSearch'
+                );
             }
             }
             // юзеры
             // юзеры
             if ($userRules->viewUsers) {
             if ($userRules->viewUsers) {

+ 10 - 0
app/Models/Page.php

@@ -342,6 +342,7 @@ abstract class Page extends Model
                 'href' => $this->canonical,
                 'href' => $this->canonical,
             ]);
             ]);
         }
         }
+
         if ($this->robots) {
         if ($this->robots) {
             $this->pageHeader('robots', 'meta', 11000, [
             $this->pageHeader('robots', 'meta', 11000, [
                 'name'    => 'robots',
                 'name'    => 'robots',
@@ -349,6 +350,15 @@ abstract class Page extends Model
             ]);
             ]);
         }
         }
 
 
+        if (1 === $this->user->g_search) {
+            $this->pageHeader('opensearch', 'link', 0, [
+                'rel'   => 'search',
+                'type'  => 'application/opensearchdescription+xml',
+                'href'  => $this->c->Router->link('OpenSearch'),
+                'title' => $this->fTitle,
+            ]);
+        }
+
         \uasort($this->pageHeaders, function (array $a, array $b) {
         \uasort($this->pageHeaders, function (array $a, array $b) {
             if ($a['weight'] === $b['weight']) {
             if ($a['weight'] === $b['weight']) {
                 return 0;
                 return 0;

+ 16 - 0
app/Models/Pages/Misc.php

@@ -17,6 +17,22 @@ use function \ForkBB\__;
 
 
 class Misc extends Page
 class Misc extends Page
 {
 {
+    public function opensearch(): Page
+    {
+        $this->nameTpl      = "opensearch";
+        $this->onlinePos    = null;
+        $this->onlineDetail = null;
+        $this->imageLink    = \preg_replace('%^(.*://(?:[^/]++)).*$%', '$1', $this->c->BASE_URL) . '/favicon.ico'; // ???? костыль O_o
+        $this->searchLink   = \strtr(
+            $this->c->Router->link('Search', ['keywords' => 'SEARCHTERMS']),
+            ['SEARCHTERMS' => '{searchTerms}']
+        );
+
+        $this->header('Content-type', 'application/xml; charset=utf-8');
+
+        return $this;
+    }
+
     /**
     /**
      * Пометка раздела прочитанным
      * Пометка раздела прочитанным
      */
      */

+ 8 - 0
app/templates/opensearch.forkbb.php

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
+  <ShortName>{{ $p->fTitle }}</ShortName>
+  <Description>{{ $p->fTitle }}</Description>
+  <InputEncoding>UTF-8</InputEncoding>
+  <Image width="16" height="16" type="image/x-icon">{{ $p->imageLink }}</Image>
+  <Url type="text/html" method="get" template="{{ $p->searchLink }}"/>
+</OpenSearchDescription>