schema_factory = new Schema_Factory(); } /** * Build schema markup for specific type * PRESERVED: Maintains exact same building logic from original Schema_Generator * * @since 1.0.0 * * @param string $schema_type Schema type to build * @param array $data Content data for schema building * @param string $context Context type ('site', 'post', 'page', etc.) * @return array Built schema markup */ public function build_schema(string $schema_type, array $data, string $context): array { // Normalize and validate schema type $schema_type = $this->schema_factory->normalize_schema_type($schema_type); if (!$this->schema_factory->is_supported_schema_type($schema_type)) { return $this->create_error_schema('Unsupported schema type: ' . $schema_type); } // Get base schema structure $schema = $this->schema_factory->create_base_schema($schema_type); // Populate schema with data based on type switch ($schema_type) { case 'Article': case 'BlogPosting': case 'TechnicalArticle': case 'NewsArticle': case 'ScholarlyArticle': case 'Report': $schema = $this->populate_article_schema($schema, $data, $context); break; case 'Product': $schema = $this->populate_product_schema($schema, $data, $context); break; case 'Organization': $schema = $this->populate_organization_schema($schema, $data, $context); break; case 'WebSite': $schema = $this->populate_website_schema($schema, $data, $context); break; case 'WebPage': $schema = $this->populate_webpage_schema($schema, $data, $context); break; case 'FAQPage': $schema = $this->populate_faq_schema($schema, $data, $context); break; case 'LocalBusiness': $schema = $this->populate_local_business_schema($schema, $data, $context); break; case 'Person': $schema = $this->populate_person_schema($schema, $data, $context); break; case 'SoftwareApplication': $schema = $this->populate_software_application_schema($schema, $data, $context); break; case 'Event': $schema = $this->populate_event_schema($schema, $data, $context); break; case 'HowTo': $schema = $this->populate_howto_schema($schema, $data, $context); break; case 'Review': $schema = $this->populate_review_schema($schema, $data, $context); break; case 'VideoObject': $schema = $this->populate_video_object_schema($schema, $data, $context); break; default: $schema = $this->populate_generic_schema($schema, $data, $context); break; } return $schema; } /** * Get JSON-LD formatted output * PRESERVED: Exact same method logic from original Schema_Generator * * @since 1.0.0 * * @param array $schema Schema markup array * @return string JSON-LD formatted string */ public function get_json_ld_output(array $schema): string { // Ensure proper JSON-LD structure if (!isset($schema['@context'])) { $schema['@context'] = $this->schema_factory->get_schema_context(); } // Clean up empty values $schema = $this->clean_schema_array($schema); // Generate JSON-LD with proper formatting. Include the HEX flags so a // in any field is emitted as <\/script> and can't break out // of the surrounding