I had a view on the og-plugin.
Sometimes people like to work with very specific Preview-Pictures that are not included in the article.
For this case you offered the possibility to upload a picture with articleid.jpg to the folder images/phocaopengraph
This is a very smart solution. I like this!
My problem: I cant use this, if there is any other picture in my article.
Because in the priority ordering - taking the og:image from images/phocaopengraph is behind all the others.
I would like to set this behaviour first. First of all, the plugin should watch if there is a picture in images/phocaopengraph , if there is no picture it can have a look for all the other possibilities.
Could you please help me, to set the ordering in the right way?
Code: Select all
// Image
$pictures = '';
if (isset($row->images)) {
$pictures = json_decode($row->images);
}
$imgSet = 0;
if ($this->params->get('image'.$suffix, '') != '' && $parameterImage == 1) {
$this->renderTag('og:image', JURI::base(false).$this->params->get('image'.$suffix, ''), $type);
$imgSet = 1;
} else if ($thisImg != ''){
$this->renderTag('og:image', JURI::base(false).$thisImg, $type);
$imgSet = 1;
} else if (isset($pictures->{'image_intro'}) && $pictures->{'image_intro'} != '') {
$this->renderTag('og:image', JURI::base(false).$pictures->{'image_intro'}, $type);
$imgSet = 1;
} else if (isset($pictures->{'image_fulltext'}) && $pictures->{'image_fulltext'} != '') {
$this->renderTag('og:image', JURI::base(false).$pictures->{'image_fulltext'}, $type);
$imgSet = 1;
} else {
// Try to find image in article
$fulltext = '';
if (isset($row->fulltext) && $row->fulltext != '') {
$fulltext = $row->fulltext;
}
$introtext = '';
if (isset($row->introtext) && $row->introtext != '') {
$introtext = $row->introtext;
}
$content = $introtext . $fulltext;
preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $src);
if (isset($src[1]) && $src[1] != '') {
$absU = 0;
// Test if this link is absolute http:// then do not change it
$pos1 = strpos($src[1], 'http://');
if ($pos1 === false) {
} else {
$absU = 1;
}
// Test if this link is absolute https:// then do not change it
$pos2 = strpos($src[1], 'https://');
if ($pos2 === false) {
} else {
$absU = 1;
}
if ($absU == 1) {
$linkImg = $src[1];
} else {
$linkImg = JURI::base(false).$src[1];
if ($src[1][0] == '/') {
$myURI = new \Joomla\Uri\Uri(JURI::base(false));
$myURI->setPath($src[1]);
$linkImg = $myURI->toString();
} else {
$linkImg = JURI::base(false).$src[1];
}
}
$this->renderTag('og:image', $linkImg, $type);
//$this->renderTag('og:image', JURI::base(false).$src[1], $type);
$imgSet = 1;
}
// Try to find image in images/phocaopengraph folder
if ($imgSet == 0) {
if (isset($row->id) && (int)$row->id > 0) {
jimport( 'joomla.filesystem.file' );
$imgPath = '';
$path = JPATH_ROOT . '/images/phocaopengraph/';
if (JFile::exists($path . '/' . (int)$row->id.'.jpg')) {
$imgPath = JURI::base(false) . 'images/phocaopengraph/'.(int)$row->id.'.jpg';
} else if (JFile::exists($path . '/' . (int)$row->id.'.png')) {
$imgPath = JURI::base(false) . 'images/phocaopengraph/'.(int)$row->id.'.png';
} else if (JFile::exists($path . '/' . (int)$row->id.'.gif')) {
$imgPath = JURI::base(false) . 'images/phocaopengraph/'.(int)$row->id.'.gif';
}
if ($imgPath != '') {
$this->renderTag('og:image', $imgPath, $type);
$imgSet = 1;
}
}
}
}
// If still image not set and parameter Image is set as last, then try to add the parameter image
if ($imgSet == 0 && $this->params->get('image'.$suffix, '') != '' && $parameterImage == 0) {
$this->renderTag('og:image', JURI::base(false).$this->params->get('image'.$suffix, ''), $type);
}
// END IMAGE