Created
July 4, 2021 09:25
-
-
Save codeeshop-oc/841a67382aa30b28e4b35c73a45a12b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function getLinkData($meta_tags = []) { | |
$title = $description = $image = $url = $domain = $youtube_id = ''; | |
if(!empty($meta_tags)) { | |
$url = ($meta_tags['url']); | |
$sourceUrl = parse_url($url); | |
try { | |
$domain = $sourceUrl['host']; | |
if(!empty($meta_tags['title'])) { | |
$title = $meta_tags['title']; | |
} elseif(!empty($meta_tags['og:title'])) { | |
$title = $meta_tags['og:title']; | |
} elseif(!empty($meta_tags['twitter:title'])) { | |
$title = $meta_tags['twitter:title']; | |
} | |
if(!empty($meta_tags['description'])) { | |
$description = $meta_tags['description']; | |
} elseif(!empty($meta_tags['og:description'])) { | |
$description = $meta_tags['og:description']; | |
} elseif(!empty($meta_tags['twitter:description'])) { | |
$description = $meta_tags['twitter:description']; | |
} | |
if(!empty($meta_tags['twitter:image'])) { | |
$image = $meta_tags['twitter:image']; | |
} elseif(!empty($meta_tags['og:image'])) { | |
$image = $meta_tags['og:image']; | |
} | |
}catch(Exception $e){ | |
} | |
} | |
if($url) { | |
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match); | |
$youtube_id = !empty($match[1]) ? $match[1] : ''; | |
} | |
return [ | |
'youtube_id' => $youtube_id, | |
'title' => $this->replaceExtraCode($title), | |
'description' => $this->replaceExtraCode($description), | |
'img' => $this->replaceExtraCode($image), | |
'domain' => $this->replaceExtraCode($domain), | |
'url' => $this->replaceExtraCode($url), | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment