PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 1.0.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v1.0.0
2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.10.0 All 48 releases
thinkrank / includes / seo / class-schema-factory.php

class-schema-factory.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 1.0.0, at includes/seo/class-schema-factory.php

234 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Schema Factory Class
4 *
5 * Handles schema type instantiation, configuration, and registry management.
6 * Extracted from Schema_Generator to follow Single Responsibility Principle.
7 * Maintains exact same functionality and data structures as original implementation.
8 *
9 * @package ThinkRank\SEO
10 * @since 1.0.0
11 */
12
13 declare(strict_types=1);
14
15 namespace ThinkRank\SEO;
16
17 // Prevent direct access
18 if (!defined('ABSPATH')) {
19 exit;
20 }
21
22 /**
23 * Schema Factory Class
24 *
25 * Manages schema type registry, instantiation, and configuration.
26 * Preserves all existing schema type definitions and specifications.
27 *
28 * @since 1.0.0
29 */
30 class Schema_Factory {
31
32 /**
33 * Supported schema types with their Schema.org specifications
34 * PRESERVED: Exact same data structure from original Schema_Generator
35 *
36 * @since 1.0.0
37 * @var array
38 */
39 private array $supported_schema_types = [
40 'Article' => [
41 'required' => ['@type', 'headline', 'author', 'datePublished'],
42 'recommended' => ['description', 'image', 'dateModified', 'publisher', 'mainEntityOfPage'],
43 'optional' => ['wordCount', 'keywords', 'articleSection', 'articleBody']
44 ],
45 'BlogPosting' => [
46 'required' => ['@type', 'headline', 'author', 'datePublished'],
47 'recommended' => ['description', 'image', 'dateModified', 'publisher', 'mainEntityOfPage'],
48 'optional' => ['wordCount', 'keywords', 'blogPost', 'comment']
49 ],
50 'TechnicalArticle' => [
51 'required' => ['@type', 'headline', 'author', 'datePublished'],
52 'recommended' => ['description', 'image', 'dateModified', 'publisher', 'mainEntityOfPage'],
53 'optional' => ['wordCount', 'keywords', 'articleSection', 'articleBody', 'dependencies', 'proficiencyLevel']
54 ],
55 'NewsArticle' => [
56 'required' => ['@type', 'headline', 'author', 'datePublished'],
57 'recommended' => ['description', 'image', 'dateModified', 'publisher', 'mainEntityOfPage'],
58 'optional' => ['wordCount', 'keywords', 'articleSection', 'articleBody', 'dateline', 'printColumn', 'printEdition', 'printPage', 'printSection']
59 ],
60 'ScholarlyArticle' => [
61 'required' => ['@type', 'headline', 'author', 'datePublished'],
62 'recommended' => ['description', 'image', 'dateModified', 'publisher', 'mainEntityOfPage'],
63 'optional' => ['wordCount', 'keywords', 'articleSection', 'articleBody', 'citation', 'pageStart', 'pageEnd', 'pagination']
64 ],
65 'Report' => [
66 'required' => ['@type', 'headline', 'author', 'datePublished'],
67 'recommended' => ['description', 'image', 'dateModified', 'publisher', 'mainEntityOfPage'],
68 'optional' => ['wordCount', 'keywords', 'articleSection', 'articleBody', 'reportNumber']
69 ],
70 'Product' => [
71 'required' => ['@type', 'name', 'description'],
72 'recommended' => ['image', 'offers', 'brand', 'sku', 'gtin', 'review', 'aggregateRating'],
73 'optional' => ['category', 'manufacturer', 'mpn', 'productID']
74 ],
75 'Organization' => [
76 'required' => ['@type', 'name', 'url'],
77 'recommended' => ['logo', 'contactPoint', 'sameAs', 'address'],
78 'optional' => ['founder', 'foundingDate', 'description']
79 ],
80 'WebSite' => [
81 'required' => ['@type', 'name', 'url'],
82 'recommended' => ['description', 'author', 'publisher', 'potentialAction'],
83 'optional' => ['sameAs', 'inLanguage']
84 ],
85 'FAQPage' => [
86 'required' => ['@type', 'mainEntity'],
87 'recommended' => ['about', 'author'],
88 'optional' => ['name', 'description', 'url', 'dateModified']
89 ],
90 'LocalBusiness' => [
91 'required' => ['@type', 'name', 'address'],
92 'recommended' => ['telephone', 'url', 'openingHours', 'geo', 'priceRange'],
93 'optional' => ['description', 'logo', 'contactPoint', 'sameAs', 'paymentAccepted', 'currenciesAccepted']
94 ],
95 'Person' => [
96 'required' => ['@type', 'name'],
97 'recommended' => ['url', 'image'],
98 'optional' => ['jobTitle', 'worksFor', 'sameAs', 'description']
99 ],
100 'SoftwareApplication' => [
101 'required' => ['@type', 'name', 'applicationCategory'],
102 'recommended' => ['description', 'url', 'offers', 'creator', 'features', 'aggregateRating'],
103 'optional' => ['alternateName', 'version', 'operatingSystem', 'fileSize', 'license', 'downloadUrl', 'screenshot']
104 ],
105 'Event' => [
106 'required' => ['@type', 'name', 'startDate', 'location'],
107 'recommended' => ['endDate', 'description', 'image', 'offers', 'performer'],
108 'optional' => ['eventStatus', 'eventAttendanceMode', 'url', 'organizer']
109 ],
110 'HowTo' => [
111 'required' => ['@type', 'name', 'step'],
112 'recommended' => ['image', 'totalTime', 'estimatedCost', 'tool', 'supply'],
113 'optional' => ['description', 'prepTime', 'difficulty', 'yield', 'video']
114 ]
115 ];
116
117 /**
118 * Schema.org context URL
119 * PRESERVED: Exact same value from original Schema_Generator
120 *
121 * @since 1.0.0
122 * @var string
123 */
124 private string $schema_context = 'https://schema.org';
125
126 /**
127 * Get all supported schema types
128 * Simplified: Context filtering moved to config files
129 *
130 * @since 1.0.0
131 *
132 * @return array Array of all supported schema types
133 */
134 public function get_all_supported_types(): array {
135 return array_keys($this->supported_schema_types);
136 }
137
138 /**
139 * Check if schema type is supported
140 * PRESERVED: Exact same method logic from original Schema_Generator
141 *
142 * @since 1.0.0
143 *
144 * @param string $schema_type Schema type to check
145 * @return bool True if supported, false otherwise
146 */
147 public function is_supported_schema_type(string $schema_type): bool {
148 return isset($this->supported_schema_types[$schema_type]);
149 }
150
151 /**
152 * Get schema type specification
153 * PRESERVED: Returns exact same data structure as original Schema_Generator
154 *
155 * @since 1.0.0
156 *
157 * @param string $schema_type Schema type
158 * @return array Schema type specification
159 */
160 public function get_schema_specification(string $schema_type): array {
161 return $this->supported_schema_types[$schema_type] ?? [];
162 }
163
164 /**
165 * Normalize schema type name to proper Schema.org format
166 *
167 * @since 1.0.0
168 *
169 * @param string $schema_type Schema type to normalize
170 * @return string Normalized schema type
171 */
172 public function normalize_schema_type(string $schema_type): string {
173 // Handle Schema.org camelCase requirements
174 $schema_cases = [
175 'localbusiness' => 'LocalBusiness',
176 'softwareapplication' => 'SoftwareApplication',
177 'blogposting' => 'BlogPosting',
178 'technicalarticle' => 'TechnicalArticle',
179 'newsarticle' => 'NewsArticle',
180 'scholarlyarticle' => 'ScholarlyArticle',
181 'faqpage' => 'FAQPage',
182 'howto' => 'HowTo'
183 ];
184
185 $key = strtolower($schema_type);
186 return $schema_cases[$key] ?? ucfirst($schema_type);
187 }
188
189 /**
190 * Create base schema structure
191 * PRESERVED: Exact same method logic from original Schema_Generator
192 *
193 * @since 1.0.0
194 *
195 * @param string $schema_type Schema type
196 * @return array Base schema structure
197 */
198 public function create_base_schema(string $schema_type): array {
199 return [
200 '@context' => $this->schema_context,
201 '@type' => $schema_type
202 ];
203 }
204
205 // Removed error schema creation - moved to Schema_Builder where it belongs
206
207 // Removed auto-detection logic - over-engineered and rarely used
208 // Schema types are now explicitly selected by users
209
210 /**
211 * Get schema context URL
212 * PRESERVED: Returns exact same value as original Schema_Generator
213 *
214 * @since 1.0.0
215 *
216 * @return string Schema context URL
217 */
218 public function get_schema_context(): string {
219 return $this->schema_context;
220 }
221
222 /**
223 * Get all supported schema types
224 * PRESERVED: Returns exact same data structure as original Schema_Generator
225 *
226 * @since 1.0.0
227 *
228 * @return array All supported schema types with specifications
229 */
230 public function get_all_schema_types(): array {
231 return $this->supported_schema_types;
232 }
233 }
234