Error message when combining Phoca Open Graph with DPCalendar

Phoca plugins - support for all Phoca plugins except Phoca Gallery plugins
jdiamond
Phoca Newbie
Phoca Newbie
Posts: 1
Joined: 09 Jun 2019, 18:38

Error message when combining Phoca Open Graph with DPCalendar

Post by jdiamond » 09 Jun 2019, 18:49

I see the following error from Phoca Open Graph plugin when viewing DPCalendar events:

Code: Select all

[06-Jun-2019 17:47:47 UTC] PHP Warning:  json_decode() expects parameter 1 to be string, object given in /home/nydi/public_html/plugins/content/phocaopengraph/phocaopengraph.php on line 97
Some debugging has shown that the problem is that the event item passed to onContentAfterDisplay has an $item->images of type object.

As I understand the interface, plugins are supposed to check if the passed item is an article and only if so treat it as string.

For the moment I have hacked in the following patch:

Code: Select all

--- plugins/content/phocaopengraph/phocaopengraph.php.orig      2019-06-06 13:54:44.873000000 -0400                                                
+++ plugins/content/phocaopengraph/phocaopengraph.php   2019-06-08 11:49:13.195000000 -0400                                                        
@@ -94,7 +94,8 @@
                plgContentPhocaOpenGraphHelper::renderTag('og:type', $this->params->get('type'.$suffix, 'article'), $type);                        

                // Image
-               $pictures = json_decode($row->images);
+               // JMD: Need to check if this is a string before decoding json!                                                                    
+               $pictures = (is_string($row->images) ? json_decode($row->images) : $row->images);                                                  

                if ($this->params->get('image'.$suffix, '') != '') {
                        plgContentPhocaOpenGraphHelper::renderTag('og:image', JURI::base(false).$this->params->get('image'.$suffix, ''), $type);   
Would it be possible to apply this fix in the next version of the Open Graph plugin?

Josh

User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 41217
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Error message when combining Phoca Open Graph with DPCalendar

Post by Jan » 11 Jun 2019, 13:22

Hi, thank you for the info, I will add it to next release.

Jan
If you find Phoca extensions useful, please support the project

Post Reply