Source of file BlogExtension.php
Size: 4,995 Bytes - Last Modified: 2021-12-24T05:17:49+00:00
/var/www/docs.ssmods.com/process/src/src/Extensions/BlogExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 | <?php namespace Innoweb\SocialMeta\Extensions; use SilverStripe\Control\Controller; use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\Core\Config\Config; use SilverStripe\CMS\Model\SiteTree; class BlogExtension extends \SilverStripe\CMS\Model\SiteTreeExtension { public function getSocialMetaTitle() { $config = $this->owner->getSocialMetaConfig(); $siteName = $config->getSocialMetaValue('SiteName'); $divider = Config::inst()->get(SiteTree::class, 'title_divider'); $controller = Controller::curr(); if (is_a($controller, ContentController::class)) { if ($category = $controller->getCurrentCategory()) { if ($category->MetaTitle) { return $category->MetaTitle; } if ($category->Title) { return $category->Title . $divider . $siteName; } } elseif ($tag = $controller->getCurrentTag()) { if ($tag->MetaTitle) { return $tag->MetaTitle; } if ($tag->Title) { return $tag->Title . $divider . $siteName; } } } return null; } public function getSocialMetaDescription() { $controller = Controller::curr(); if (is_a($controller, ContentController::class)) { if (($category = $controller->getCurrentCategory()) && $category->MetaDescription) { return $category->MetaDescription; } elseif (($tag = $controller->getCurrentTag()) && $tag->MetaDescription) { return $tag->MetaDescription; } } return null; } public function getSocialMetaCanonicalURL() { $controller = Controller::curr(); if (is_a($controller, ContentController::class)) { // get pagination page $page = ''; $posts = $controller->PaginatedList(); if (($pageNum = (int)$posts->getPageStart()) > 0) { $page = '?' . $posts->getPaginationGetVar() . '=' . $pageNum; } // get specific URL for archive, categories and tags if ($controller->getArchiveYear() || $controller->getArchiveMonth() || $controller->getArchiveDay()) { $year = $controller->getArchiveYear(); $month = $controller->getArchiveMonth(); $day = $controller->getArchiveDay(); if ($day && $month && $year) { return $controller->join_links($controller->AbsoluteLink(), "archive", $year, $month, $day, $page); } elseif ($month && $year) { return $controller->join_links($controller->AbsoluteLink(), "archive", $year, $month, $page); } elseif ($year) { return $controller->join_links($controller->AbsoluteLink(), "archive", $year, $page); } } elseif ($category = $controller->getCurrentCategory()) { if ($category->MetaCanonicalURL) { return $category->MetaCanonicalURL; } else { return $controller->join_links($controller->AbsoluteLink(), "category", $category->URLSegment, $page); } } elseif ($tag = $controller->getCurrentTag()) { if ($tag->MetaCanonicalURL) { return $tag->MetaCanonicalURL; } else { return $controller->join_links($controller->AbsoluteLink(), "tag", $tag->URLSegment, $page); } } elseif (strlen($page) > 0) { return $controller->join_links($controller->AbsoluteLink(), $page); } } return null; } public function getSocialMetaImage() { $controller = Controller::curr(); if (is_a($controller, ContentController::class)) { if ($category = $controller->getCurrentCategory()) { if (($image = $category->MetaImage()) && $image->exists()) { return $image; } } elseif ($tag = $controller->getCurrentTag()) { if (($image = $tag->MetaImage()) && $image->exists()) { return $image; } } } return null; } public function getSocialMetaExtraMeta() { $controller = Controller::curr(); if (is_a($controller, ContentController::class)) { if ($category = $controller->getCurrentCategory()) { if ($category->ExtraMeta) { return $category->ExtraMeta; } } elseif ($tag = $controller->getCurrentTag()) { if ($tag->ExtraMeta) { return $tag->ExtraMeta; } } } return null; } } |