schema.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. $settingsJsonld = settings('jsonld')->getAll();
  3. $schemaGraph = [];
  4. // 1. Organization
  5. $organizationSchema = [
  6. "@type" => "Organization",
  7. "@id" => $currentUrl . "#organization",
  8. "name" => $settingsJsonld['organization_name'] ?? ($seo['title'] ?? $pageContent['title']),
  9. "url" => $settingsJsonld['organization_url'] ?? $currentDomain,
  10. "logo" => !empty($settingsContent['header-logo']) ? $currentDomain . '/' . json_decode($settingsContent['header-logo'], true)['src'] : ''
  11. ];
  12. // Add sameAs if organization_same_as is filled
  13. if (!empty($settingsJsonld['organization_same_as'])) {
  14. $sameAsUrls = array_filter(array_map('trim', explode("\n", $settingsJsonld['organization_same_as'])));
  15. if (!empty($sameAsUrls)) {
  16. $organizationSchema["sameAs"] = $sameAsUrls;
  17. }
  18. }
  19. // Add license if filled
  20. if (!empty($settingsJsonld['license_url'])) {
  21. $organizationSchema["license"] = $settingsJsonld['license_url'];
  22. }
  23. $schemaGraph[] = $organizationSchema;
  24. // 2. Casino Brand
  25. $casinoBrand = [
  26. "@type" => ["Casino", "Brand"],
  27. "@id" => $currentUrl . "#brand-casino-entity",
  28. "name" => $seo['title'],
  29. "url" => $seo['canonical'] ?? $currentUrl,
  30. "image" => !empty($settingsContent['header-logo']) ? $currentDomain . '/' . json_decode($settingsContent['header-logo'], true)['src'] : '',
  31. "aggregateRating" => [
  32. "@type" => "AggregateRating",
  33. "ratingValue" => $settingsJsonld['rating_value'] ?? "5",
  34. "ratingCount" => $settingsJsonld['review_count'] ?? "150",
  35. "worstRating" => $settingsJsonld['worst_rating'] ?? "1",
  36. "bestRating" => $settingsJsonld['best_rating'] ?? "5"
  37. ],
  38. "priceRange" => "$",
  39. "openingHoursSpecification" => [
  40. [
  41. "@type" => "OpeningHoursSpecification",
  42. "dayOfWeek" => ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
  43. "opens" => "00:00",
  44. "closes" => "23:59"
  45. ]
  46. ],
  47. "parentOrganization" => [
  48. "@id" => $currentUrl . "#organization"
  49. ]
  50. ];
  51. // Add address if any field is filled
  52. if (!empty($settingsContent['address-street']) || !empty($settingsContent['address-city']) ||
  53. !empty($settingsContent['address-region']) || !empty($settingsContent['address-postal']) ||
  54. !empty($settingsContent['address-country'])) {
  55. $casinoBrand["address"] = [
  56. "@type" => "PostalAddress",
  57. "streetAddress" => $settingsContent['address-street'] ?? '',
  58. "addressLocality" => $settingsContent['address-city'] ?? '',
  59. "addressRegion" => $settingsContent['address-region'] ?? '',
  60. "postalCode" => $settingsContent['address-postal'] ?? '',
  61. "addressCountry" => $settingsContent['address-country'] ?? ''
  62. ];
  63. }
  64. $schemaGraph[] = $casinoBrand;
  65. // 3. WebSite
  66. $schemaGraph[] = [
  67. "@type" => "WebSite",
  68. "url" => $currentDomain,
  69. "name" => $settingsContent['title-h1'],
  70. "publisher" => [
  71. "@id" => $currentUrl . "#organization"
  72. ]
  73. ];
  74. // 4. WebPage
  75. $schemaGraph[] = [
  76. "@type" => "WebPage",
  77. "@id" => $currentUrl . "#webpage",
  78. "name" => $seo['title'],
  79. "description" => $seo['description'],
  80. "inLanguage" => $seo['extra_fields']['locale'] ?? 'en',
  81. "url" => $currentUrl,
  82. "dateModified" => $settingsContent['modified-date'] ?? date('Y-m-d'),
  83. "author" => [
  84. "@type" => "Person",
  85. "name" => $settingsContent['author-name'] ?? '',
  86. "image" => !empty($settingsContent['author-img']) ? $currentDomain . '/' . $settingsContent['author-img'] : '',
  87. "jobTitle" => "Casino Expert"
  88. ],
  89. "publisher" => [
  90. "@id" => $currentUrl . "#organization"
  91. ]
  92. ];
  93. // 5. Review
  94. $schemaGraph[] = [
  95. "@type" => "Review",
  96. "itemReviewed" => [
  97. "@id" => $currentUrl . "#brand-casino-entity"
  98. ],
  99. "reviewRating" => [
  100. "@type" => "Rating",
  101. "ratingValue" => "5",
  102. "bestRating" => "5"
  103. ],
  104. "author" => [
  105. "@id" => $currentUrl . "#organization"
  106. ],
  107. "name" => $seo['title'],
  108. "reviewBody" => $seo['description'],
  109. "datePublished" => $settingsContent['published-date'] ?? date('Y-m-d')
  110. ];
  111. // 6. Offer (if bonus fields are filled)
  112. if (!empty($settingsContent['bonus-name']) || !empty($settingsContent['bonus-description'])) {
  113. $schemaGraph[] = [
  114. "@type" => "Offer",
  115. "@id" => $currentUrl . "#offer",
  116. "name" => $settingsContent['bonus-name'] ?? '',
  117. "description" => $settingsContent['bonus-description'] ?? '',
  118. "url" => $settingsContent['bonus-url'] ?? $currentUrl,
  119. "price" => $settingsContent['bonus-price'] ?? '',
  120. "priceCurrency" => $settingsContent['bonus-currency'] ?? 'EUR',
  121. "availability" => "https://schema.org/InStock",
  122. "eligibleCustomerType" => "https://schema.org/NewCustomer",
  123. "offeredBy" => [
  124. "@id" => $currentUrl . "#organization"
  125. ]
  126. ];
  127. }
  128. // 7. BreadcrumbList
  129. $schemaGraph[] = [
  130. "@type" => "BreadcrumbList",
  131. "itemListElement" => [
  132. [
  133. "@type" => "ListItem",
  134. "position" => 1,
  135. "name" => $settingsJsonld['breadcrumb_home_name'] ?? $settingsContent['title-h1'],
  136. "item" => $currentUrl
  137. ]
  138. ]
  139. ];
  140. // 8. FAQPage
  141. if (!empty($faqItems)) {
  142. $schemaGraph[] = [
  143. "@type" => "FAQPage",
  144. "mainEntityOfPage" => [
  145. "@id" => $currentUrl . "#webpage"
  146. ],
  147. "mainEntity" => array_map(function ($item) {
  148. return [
  149. "@type" => "Question",
  150. "name" => htmlspecialchars($item['question']),
  151. "acceptedAnswer" => [
  152. "@type" => "Answer",
  153. "text" => htmlspecialchars($item['answer'])
  154. ]
  155. ];
  156. }, $faqItems)
  157. ];
  158. }
  159. // 9. SoftwareApplication (if app fields are filled)
  160. if (!empty($settingsJsonld['download_url']) || !empty($settingsJsonld['app_name'])) {
  161. $schemaGraph[] = [
  162. "@type" => "SoftwareApplication",
  163. "@id" => $currentUrl . "#app",
  164. "name" => $settingsJsonld['app_name'] ?? ($settingsContent['title-h1'] . " App"),
  165. "operatingSystem" => $settingsJsonld['operating_system'] ?? "Android, iOS",
  166. "applicationCategory" => $settingsJsonld['application_category'] ?? "GameApplication",
  167. "provider" => [
  168. "@id" => $currentUrl . "#organization"
  169. ],
  170. "offers" => [
  171. "@type" => "Offer",
  172. "price" => "0",
  173. "priceCurrency" => "EUR",
  174. "availability" => "https://schema.org/InStock"
  175. ],
  176. "downloadUrl" => $settingsJsonld['download_url'] ?? '',
  177. "aggregateRating" => [
  178. "@type" => "AggregateRating",
  179. "ratingValue" => $settingsJsonld['rating_value'] ?? "5",
  180. "ratingCount" => $settingsJsonld['review_count'] ?? "99",
  181. "worstRating" => $settingsJsonld['worst_rating'] ?? "1",
  182. "bestRating" => $settingsJsonld['best_rating'] ?? "5"
  183. ],
  184. "author" => [
  185. "@id" => $currentUrl . "#organization"
  186. ]
  187. ];
  188. }
  189. // Generate final JSON-LD
  190. $schemaMarkup = [
  191. "@context" => "https://schema.org",
  192. "@graph" => array_filter($schemaGraph) // Remove null entries
  193. ];
  194. echo json_encode($schemaMarkup, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
  195. ?>