Page 1 of 1
Phoca Open Graph + Helix 3 blog image
Posted: 18 Mar 2024, 15:32
by componentegd
Hello! I'm using Phoca Open Graph with a Helix 3 based template. It comes with a Blog Image option to be the cover of the article.
Is it possible to someone help me add or make a change to phoca open graph get that image?
This site still uses Joomla 3 and is using the latests Phoca open graph for joomla 3.
Thanks in advance!
Re: Phoca Open Graph + Helix 3 blog image
Posted: 18 Mar 2024, 17:19
by Jan
Hi, the displaying of image in the plugin is the following:
https://www.phoca.cz/documentation/90-p ... open-graph
So to somehow change the selecing image ordering, the code needs to be customized directly
Jan
Re: Phoca Open Graph + Helix 3 blog image
Posted: 19 Mar 2024, 15:10
by componentegd
Hi Jan! How are you doing?
Thanks for the input. I was able to succeed editing it.
I'll post here the edited part of the main file in case someone needs.
The file is phocaopengraph.php
Code: Select all
// Image
$pictures = '';
if (isset($row->images)) {
//$pictures = json_decode($row->images);
$pictures = (is_string($row->images) ? json_decode($row->images) : $row->images);
}
//begin full IMAGE from helix 3
// get article image
$images = json_decode($row->images);
//Article Attribute
$art_attribs = new JRegistry(json_decode( $row->attribs ));
$art_image = $art_attribs->get('spfeatured_image');
$img_size = "_large";
//Basename
$basename = basename($art_image);
//Thumb
$thumbnail = JPATH_ROOT . '/' . dirname($art_image) . '/' . JFile::stripExt($basename) . $img_size . '.' . JFile::getExt($basename);
if(file_exists($thumbnail)) {
$heliximage = JURI::root(true) . '/' . dirname($art_image) . '/' . JFile::stripExt($basename) . $img_size . '.' . JFile::getExt($basename);
}elseif(isset($images->image_intro) && !empty($images->image_intro)){
$heliximage = htmlspecialchars($images->image_intro);
}
// end of full image from helix 3
$imgSet = 0;
if ($this->params->get('image'.$suffix, '') != '' && $parameterImage == 1) {
$this->renderTag('og:image', $this->setImage($this->params->get('image'.$suffix, '')), $type);
$imgSet = 1;
} else if ($thisImg != ''){
$this->renderTag('og:image', $this->setImage($thisImg), $type);
$imgSet = 1;
} else if ($heliximage != ''){ //test if there is a image from helix blog options
$this->renderTag('og:image', $this->setImage($heliximage), $type);
$imgSet = 1;
} else if (isset($pictures->{'image_intro'}) && $pictures->{'image_intro'} != '') {
$this->renderTag('og:image', $this->setImage($pictures->{'image_intro'}), $type);
$imgSet = 1;
} else if (isset($pictures->{'image_fulltext'}) && $pictures->{'image_fulltext'} != '') {
$this->renderTag('og:image', $this->setImage($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] != '') {
$this->renderTag('og:image', $this->setImage($src[1]), $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 = 'images/phocaopengraph/'.(int)$row->id.'.jpg';
} else if (JFile::exists($path . '/' . (int)$row->id.'.png')) {
$imgPath = 'images/phocaopengraph/'.(int)$row->id.'.png';
} else if (JFile::exists($path . '/' . (int)$row->id.'.gif')) {
$imgPath = 'images/phocaopengraph/'.(int)$row->id.'.gif';
}
if ($imgPath != '') {
$this->renderTag('og:image', $this->setImage($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', $this->setImage($this->params->get('image'.$suffix, '')), $type);
}
// END IMAGE
Re: Phoca Open Graph + Helix 3 blog image
Posted: 25 Mar 2024, 01:44
by Jan
Ok, thank you, Jan