PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.5.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.5.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 2.5.0, at includes/seo/class-schema-factory.php

245 lines 9.1 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 'Review' => [
111 'required' => ['@type', 'itemReviewed', 'reviewRating', 'author'],
112 'recommended' => ['reviewBody', 'datePublished', 'publisher'],
113 'optional' => ['name', 'url']
114 ],
115 'HowTo' => [
116 'required' => ['@type', 'name', 'step'],
117 'recommended' => ['image', 'totalTime', 'estimatedCost', 'tool', 'supply'],
118 'optional' => ['description', 'prepTime', 'difficulty', 'yield', 'video']
119 ],
120 'VideoObject' => [
121 'required' => ['@type', 'name', 'description', 'thumbnailUrl', 'uploadDate'],
122 'recommended' => ['contentUrl', 'embedUrl', 'duration'],
123 'optional' => ['interactionStatistic', 'expires', 'regionsAllowed']
124 ]
125 ];
126
127 /**
128 * Schema.org context URL
129 * PRESERVED: Exact same value from original Schema_Generator
130 *
131 * @since 1.0.0
132 * @var string
133 */
134 private string $schema_context = 'https://schema.org';
135
136 /**
137 * Get all supported schema types
138 * Simplified: Context filtering moved to config files
139 *
140 * @since 1.0.0
141 *
142 * @return array Array of all supported schema types
143 */
144 public function get_all_supported_types(): array {
145 return array_keys($this->supported_schema_types);
146 }
147
148 /**
149 * Check if schema type is supported
150 * PRESERVED: Exact same method logic from original Schema_Generator
151 *
152 * @since 1.0.0
153 *
154 * @param string $schema_type Schema type to check
155 * @return bool True if supported, false otherwise
156 */
157 public function is_supported_schema_type(string $schema_type): bool {
158 return isset($this->supported_schema_types[$schema_type]);
159 }
160
161 /**
162 * Get schema type specification
163 * PRESERVED: Returns exact same data structure as original Schema_Generator
164 *
165 * @since 1.0.0
166 *
167 * @param string $schema_type Schema type
168 * @return array Schema type specification
169 */
170 public function get_schema_specification(string $schema_type): array {
171 return $this->supported_schema_types[$schema_type] ?? [];
172 }
173
174 /**
175 * Normalize schema type name to proper Schema.org format
176 *
177 * @since 1.0.0
178 *
179 * @param string $schema_type Schema type to normalize
180 * @return string Normalized schema type
181 */
182 public function normalize_schema_type(string $schema_type): string {
183 // Handle Schema.org camelCase requirements
184 $schema_cases = [
185 'localbusiness' => 'LocalBusiness',
186 'softwareapplication' => 'SoftwareApplication',
187 'blogposting' => 'BlogPosting',
188 'technicalarticle' => 'TechnicalArticle',
189 'newsarticle' => 'NewsArticle',
190 'scholarlyarticle' => 'ScholarlyArticle',
191 'faqpage' => 'FAQPage',
192 'howto' => 'HowTo',
193 'videoobject' => 'VideoObject'
194 ];
195
196 $key = strtolower($schema_type);
197 return $schema_cases[$key] ?? ucfirst($schema_type);
198 }
199
200 /**
201 * Create base schema structure
202 * PRESERVED: Exact same method logic from original Schema_Generator
203 *
204 * @since 1.0.0
205 *
206 * @param string $schema_type Schema type
207 * @return array Base schema structure
208 */
209 public function create_base_schema(string $schema_type): array {
210 return [
211 '@context' => $this->schema_context,
212 '@type' => $schema_type
213 ];
214 }
215
216 // Removed error schema creation - moved to Schema_Builder where it belongs
217
218 // Removed auto-detection logic - over-engineered and rarely used
219 // Schema types are now explicitly selected by users
220
221 /**
222 * Get schema context URL
223 * PRESERVED: Returns exact same value as original Schema_Generator
224 *
225 * @since 1.0.0
226 *
227 * @return string Schema context URL
228 */
229 public function get_schema_context(): string {
230 return $this->schema_context;
231 }
232
233 /**
234 * Get all supported schema types
235 * PRESERVED: Returns exact same data structure as original Schema_Generator
236 *
237 * @since 1.0.0
238 *
239 * @return array All supported schema types with specifications
240 */
241 public function get_all_schema_types(): array {
242 return $this->supported_schema_types;
243 }
244 }
245