1
0

3 Incheckningar 59a632ac36 ... a5f02cf26f

Upphovsman SHA1 Meddelande Datum
  sark a5f02cf26f Merge branch 'main' of git.slotsspot.com:sark/new-templane 1 månad sedan
  sark 41a45642b9 add contains 1 månad sedan
  sark 073fa0cee4 fix chema 1 månad sedan
3 ändrade filer med 109 tillägg och 12 borttagningar
  1. 35 12
      resources/view/partials/schema.php
  2. 5 0
      src/Pages/page.php
  3. 69 0
      src/helpers.php

+ 35 - 12
resources/view/partials/schema.php

@@ -74,7 +74,7 @@ $schemaGraph[] = $casinoBrand;
 $schemaGraph[] = [
     "@type" => "WebSite",
     "url" => $currentDomain,
-    "name" => $settingsContent['title-h1'],
+    "name" => $seo['title'] ?? $pageData['title'],
     "publisher" => [
         "@id" => $currentUrl . "#organization"
     ]
@@ -144,7 +144,7 @@ $schemaGraph[] = [
         [
             "@type" => "ListItem",
             "position" => 1,
-            "name" => $settingsJsonld['breadcrumb_home_name'] ?? $settingsContent['title-h1'],
+            "name" => $settingsJsonld['breadcrumb_home_name'] ?? ($seo['title'] ?? $pageData['title']),
             "item" => $currentUrl
         ]
     ]
@@ -152,13 +152,12 @@ $schemaGraph[] = [
 
 // 8. FAQPage
 if (!empty($faqItems)) {
-    $schemaGraph[] = [
-        "@type" => "FAQPage",
-        "mainEntityOfPage" => [
-            "@id" => $currentUrl . "#webpage"
-        ],
-        "mainEntity" => array_map(function ($item) {
-            return [
+    $faqQuestions = [];
+    foreach ($faqItems as $item) {
+        // Support both formats: content FAQ (question/answer) and pages FAQ (extra_fields)
+        if (isset($item['question']) && isset($item['answer'])) {
+            // Content FAQ format
+            $faqQuestions[] = [
                 "@type" => "Question",
                 "name" => htmlspecialchars($item['question']),
                 "acceptedAnswer" => [
@@ -166,8 +165,32 @@ if (!empty($faqItems)) {
                     "text" => htmlspecialchars($item['answer'])
                 ]
             ];
-        }, $faqItems)
-    ];
+        } elseif (isset($item['extra_fields']) && is_array($item['extra_fields'])) {
+            // Pages FAQ format - check extra_fields
+            foreach ($item['extra_fields'] as $faqItem) {
+                if (isset($faqItem['question']) && isset($faqItem['answer'])) {
+                    $faqQuestions[] = [
+                        "@type" => "Question",
+                        "name" => htmlspecialchars($faqItem['question']),
+                        "acceptedAnswer" => [
+                            "@type" => "Answer",
+                            "text" => htmlspecialchars($faqItem['answer'])
+                        ]
+                    ];
+                }
+            }
+        }
+    }
+    
+    if (!empty($faqQuestions)) {
+        $schemaGraph[] = [
+            "@type" => "FAQPage",
+            "mainEntityOfPage" => [
+                "@id" => $currentUrl . "#webpage"
+            ],
+            "mainEntity" => $faqQuestions
+        ];
+    }
 }
 
 // 9. SoftwareApplication (if app fields are filled)
@@ -175,7 +198,7 @@ if (!empty($settingsJsonld['download_url']) || !empty($settingsJsonld['app_name'
     $schemaGraph[] = [
         "@type" => "SoftwareApplication",
         "@id" => $currentUrl . "#app",
-        "name" => $settingsJsonld['app_name'] ?? ($settingsContent['title-h1'] . " App"),
+        "name" => $settingsJsonld['app_name'] ?? (($seo['title'] ?? $pageData['title']) . " App"),
         "operatingSystem" => $settingsJsonld['operating_system'] ?? "Android, iOS",
         "applicationCategory" => $settingsJsonld['application_category'] ?? "GameApplication",
         "provider" => [

+ 5 - 0
src/Pages/page.php

@@ -50,6 +50,10 @@ $pageContent = $currentPage['content'] ?? '';
 // Получаем топ контент из extra_fields
 $topContent = $extraFields['top_content'] ?? '';
 
+// Подготавливаем содержание для контента
+$headings = getContainsByText($pageContent);
+$pageContent = addIdToHInText($pageContent, $headings);
+
 // Получаем FAQ для этой страницы
 $faqItems = $faqModel->getByMorphable('page', $currentPage['id']);
 
@@ -80,6 +84,7 @@ return ViewRender($layoutFile, [
     'pageContent' => $pageContent,
     'pageData' => $currentPage,
     'topContent' => $topContent,
+    'headings' => $headings,
     'currentDomain' => $currentDomain,
     'currentUrl' => $currentUrl,
     'isHomepage' => !empty($currentPage['is_homepage']),

+ 69 - 0
src/helpers.php

@@ -32,6 +32,75 @@ class Score
         return self::$tmpArray;
     }
 }
+function getContainsByText(?string $text): array
+{
+    $h2Array = [];
+    $h3 = [];
+    $activeId = '';
+
+    preg_match_all('/<h2[^>]*>(.*?)<\/h2>|<h3[^>]*>(.*?)<\/h3>/i', $text, $matches);
+
+    if (empty($matches[0])) {
+        return [];
+    }
+
+    foreach ($matches[1] as $key => $textH2) {
+        if (empty($textH2) && isset($matches[2][$key]) && ! empty($matches[2][$key])) {
+            $h3[] = [
+                'id' => Str::slug($matches[2][$key]),
+                'text' => $matches[2][$key],
+            ];
+
+            continue;
+        }
+
+        if (! empty($h3)) {
+            $h2Array[$activeId]['h3'] = $h3;
+        }
+
+        $h3 = [];
+        $activeText = $textH2;
+        $activeId = Str::slug($textH2);
+        $h2Array[$activeId] = [
+            'id' => $activeId,
+            'text' => $activeText,
+            'h3' => $h3,
+        ];
+    }
+
+    if (! empty($h3)) {
+        $h2Array[$activeId]['h3'] = $h3;
+    }
+
+    return $h2Array;
+}
+
+function addIdToHInText(?string $text, array $h2AnchorsArray = []): ?string
+{
+    if (empty($h2AnchorsArray)) {
+        $h2AnchorsArray = getContainsByText($text);
+    }
+
+    foreach ($h2AnchorsArray as $data) {
+        if (empty($data['text'])) {
+            continue;
+        }
+
+        $h2Pattern = '/<h2([^>]*)>'.preg_quote($data['text'], '/').'<\/h2>/i';
+        $replacementH2 = "<h2\$1 id=\"{$data['id']}\">".str_replace('$', '\\$', $data['text']).'</h2>';
+        $text = preg_replace($h2Pattern, $replacementH2, $text);
+
+        if (! empty($data['h3'])) {
+            foreach ($data['h3'] as $h3data) {
+                $h3Pattern = '/<h3([^>]*)>'.preg_quote($h3data['text'], '/').'<\/h3>/i';
+                $replacementH3 = "<h3\$1 id=\"{$h3data['id']}\">".str_replace('$', '\\$', $h3data['text']).'</h3>';
+                $text = preg_replace($h3Pattern, $replacementH3, $text);
+            }
+        }
+    }
+
+    return $text;
+}
 
 function array_to_csv_download($array, $filename = "export.csv", $delimiter = ";") {
     $maxArray = [];