router = $_router; // server protocol $protocol = empty($_SERVER['HTTPS']) ? 'http' : 'https'; // domain name $domain = $_SERVER['SERVER_NAME']; // server port $port = $_SERVER['SERVER_PORT']; $disp_port = (($protocol === 'http' && $port == 80) || ($protocol === 'https' && $port == 443)) ? '' : ":$port"; // put em all together to get the complete base URL $this->base_url = "${protocol}://${domain}${disp_port}"; } /** * @param string $url * @param SEOInterface $element * @param array $parameters * * @return string */ public function getMetaData(string $url, SEOInterface $element, array $parameters): string { $metaDatas = ''; if($element->getTitle() !== '') { $title = $element->getTitle(); foreach ($parameters as $parameter => $replace){ $title = str_replace($parameter,$replace,$title); } $metaDatas .= ''.$title.''."\n"; $metaDatas .= ''."\n"; $metaDatas .= ''."\n"; } if($element->getDescription() !== '') { $description = $element->getDescription(); foreach ($parameters as $parameter => $replace){ $description = str_replace($parameter,$replace,$description); } $metaDatas .= ''."\n"; $metaDatas .= ''."\n"; $metaDatas .= ''."\n"; } if($element->getKeywords() !== '') { $keywords = $element->getKeywords(); foreach ($parameters as $parameter => $replace){ $keywords = str_replace($parameter,$replace,$keywords); } $metaDatas .= ''."\n"; } if($url !== '') { $metaDatas .= ''."\n"; $metaDatas .= ''."\n"; } if($element->getSeoAbsolutePathImage() !== '') { $metaDatas .= ''."\n"; $metaDatas .= ''."\n"; } if($element->getOgType() !== '') { $metaDatas .= ''."\n"; } if($element->getTwitterCard() !== '') { $metaDatas .= ''."\n"; } $metaDatas .= ''."\n"; return $metaDatas; } /** * @param string $url * @param string $lang * @param array $seo * * @return string */ public function getMetaDataFromArray(string $url, string $lang, array $seo): string { $metaDatas = ''; if(isset($seo['title'])) { $title = $seo['title']; $metaDatas .= ''.$title.''."\n"; $metaDatas .= ''."\n"; $metaDatas .= ''."\n"; } if(isset($seo['description'])) { $description = $seo['description']; $metaDatas .= ''."\n"; $metaDatas .= ''."\n"; $metaDatas .= ''."\n"; } if(isset($seo['keywords'])) { $keywords = $seo['keywords']; $metaDatas .= ''."\n"; } if($url !== '') { $metaDatas .= ''."\n"; $metaDatas .= ''."\n"; } if(isset($seo['AbsolutePathImage'])) { $metaDatas .= ''."\n"; $metaDatas .= ''."\n"; } if(isset($seo['OgType'])) { $metaDatas .= ''."\n"; } if(isset($seo['TwitterCard'])) { $metaDatas .= ''."\n"; } $metaDatas .= ''."\n"; return $metaDatas; } /** * @param SEOInterface $first * @param SEOInterface $second */ public function combineSEO(SEOInterface $first, SEOInterface $second): void { $title = $first->getTitle().' - '.$second->getTitle(); $description = $first->getDescription().' - '.$second->getDescription(); $keywords = $first->getKeywords().' - '.$second->getKeywords(); $second->setTitle($title); $second->setDescription($description); $second->setKeywords($keywords); } }