Phoca Open Graph + Helix 3 blog image

Phoca plugins - support for all Phoca plugins except Phoca Gallery plugins
User avatar
componentegd
Phoca Member
Phoca Member
Posts: 21
Joined: 31 Mar 2015, 22:39
Location: Rio de janeiro - Brazil
Contact:

Phoca Open Graph + Helix 3 blog image

Post 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!
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47887
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Phoca Open Graph + Helix 3 blog image

Post 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 :idea:

Jan
If you find Phoca extensions useful, please support the project
User avatar
componentegd
Phoca Member
Phoca Member
Posts: 21
Joined: 31 Mar 2015, 22:39
Location: Rio de janeiro - Brazil
Contact:

Re: Phoca Open Graph + Helix 3 blog image

Post by componentegd »

Jan wrote: 18 Mar 2024, 17:19 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 :idea:

Jan
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
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47887
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Phoca Open Graph + Helix 3 blog image

Post by Jan »

Ok, thank you, Jan
If you find Phoca extensions useful, please support the project
Post Reply