| 1 |
<?php |
| 2 |
/** |
| 3 |
* Yatra SEO Helper Functions |
| 4 |
* |
| 5 |
* Production-ready clean SEO implementation using the new SEOService architecture. |
| 6 |
* All new SEO functionality should use SEOService and SEOManager directly. |
| 7 |
* |
| 8 |
* @package Yatra |
| 9 |
*/ |
| 10 |
|
| 11 |
/** |
| 12 |
* Helper function to get SEO title for current page |
| 13 |
* Useful for manual calls or custom implementations |
| 14 |
* |
| 15 |
* @return string The SEO title for current page |
| 16 |
* @throws \InvalidArgumentException If SEO manager is not available |
| 17 |
*/ |
| 18 |
function yatra_get_seo_title(): string { |
| 19 |
try { |
| 20 |
if (!class_exists('\Yatra\Managers\SEOManager')) { |
| 21 |
throw new \InvalidArgumentException('SEO Manager not available'); |
| 22 |
} |
| 23 |
|
| 24 |
return \Yatra\Managers\SEOManager::filterDocumentTitle(''); |
| 25 |
} catch (\Exception $e) { |
| 26 |
|
| 27 |
return ''; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Helper function to output SEO meta tags for current page |
| 33 |
* Useful for manual calls or custom implementations |
| 34 |
* |
| 35 |
* @return void |
| 36 |
* @throws \InvalidArgumentException If SEO manager is not available |
| 37 |
*/ |
| 38 |
function yatra_output_seo_meta_tags(): void { |
| 39 |
try { |
| 40 |
if (!class_exists('\Yatra\Managers\SEOManager')) { |
| 41 |
throw new \InvalidArgumentException('SEO Manager not available'); |
| 42 |
} |
| 43 |
|
| 44 |
\Yatra\Managers\SEOManager::outputSEOMetaTags(); |
| 45 |
} catch (\Exception $e) { |
| 46 |
// Fail silently to avoid breaking page rendering |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Helper function to get SEO service for specific page type and object |
| 52 |
* Useful for custom SEO implementations |
| 53 |
* |
| 54 |
* @param string $pageType The page type |
| 55 |
* @param mixed $pageObject The page object |
| 56 |
* @return \Yatra\Services\SEOService The SEO service instance |
| 57 |
* @throws \InvalidArgumentException If SEO service is not available or page type is invalid |
| 58 |
*/ |
| 59 |
function yatra_get_seo_service(string $pageType, $pageObject = null): \Yatra\Services\SEOService { |
| 60 |
try { |
| 61 |
if (!class_exists('\Yatra\Services\SEOService')) { |
| 62 |
throw new \InvalidArgumentException('SEO Service not available'); |
| 63 |
} |
| 64 |
|
| 65 |
// Validate page type |
| 66 |
$validTypes = [ |
| 67 |
\Yatra\Services\SEOService::PAGE_TYPE_TRIP, |
| 68 |
\Yatra\Services\SEOService::PAGE_TYPE_TRIP_ARCHIVE, |
| 69 |
\Yatra\Services\SEOService::PAGE_TYPE_DESTINATION, |
| 70 |
\Yatra\Services\SEOService::PAGE_TYPE_ACTIVITY, |
| 71 |
\Yatra\Services\SEOService::PAGE_TYPE_CATEGORY, |
| 72 |
\Yatra\Services\SEOService::PAGE_TYPE_DESTINATION_LISTING, |
| 73 |
\Yatra\Services\SEOService::PAGE_TYPE_ACTIVITY_LISTING, |
| 74 |
\Yatra\Services\SEOService::PAGE_TYPE_CATEGORY_LISTING, |
| 75 |
]; |
| 76 |
|
| 77 |
if (!in_array($pageType, $validTypes, true)) { |
| 78 |
throw new \InvalidArgumentException('Invalid page type: ' . $pageType); |
| 79 |
} |
| 80 |
|
| 81 |
return \Yatra\Services\SEOService::forPage($pageType, $pageObject); |
| 82 |
} catch (\Exception $e) { |
| 83 |
|
| 84 |
throw $e; |
| 85 |
} |
| 86 |
} |
| 87 |
|