I have been trying to develop my own opengraph. I found some codes online and try to merge them but to no avail. I wonder if I have done it wrong.
// Try to find image in article
$img = 0;
$fulltext = '';
if (isset($row->fulltext) && $row->fulltext != '') {
$fulltext = $row->fulltext;
}
$introtext = '';
if (isset($row->introtext) && $row->introtext != '') {
$fulltext = $row->introtext;
}
$content = $introtext . $fulltext;
preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $src);
if (isset($src[1]) && $src[1] != '') {
$timage = htmlspecialchars($src[1]));
$img = 1;
}
$doc =& JFactory::getDocument();
$doc->addCustomTag( '
<meta property="og:title" content="'.$this->escape($this->item->title).'"/>
<meta property="og:type" content="article"/>
<meta property="og:image" content="'.$timage.'";/>
');
Second Code I am experimenting (I received the Undefined Variable : timage
function get_joomla_image($url)
{
if (preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $url, $match)) {
$timage = $match[1];
echo $match[1];
}
}
// get the corresponding thumbnail images
if (isset($match[1]) and !empty($match[1]))
{
$timage= htmlspecialchars(JURI::root().$match[1]);
}
$doc =& JFactory::getDocument();
$doc->addCustomTag( '
<meta name="og:image" content="'.$timage.'">
Thank you Joomla guru for your help.
var_dump($match);
to see what the variable contains?