I was receiving this error when enabling the seo feature to print the comments in the page:
Notice: Undefined property: stdClass::$data in _fb_social_comments_seo() (line 288 of sites/all/modules/fb_social/plugins/fb_plugin/comments.inc).
Warning: Invalid argument supplied for foreach() in _fb_social_comments_seo_view() (line 301 of sites/all/modules/fb_social/plugins/fb_plugin/comments.inc).
This was only happening on pages without comments. The functions were not checking for null values. The fix I implemented is below. All I did was check if the variables existed via isset. I am not familiar with generating patches, if someone more experienced could take care of that it would be great.
Line 288
if(isset($result->$url->data)) {
$comments = _fb_social_comments_seo_view($result->$url->data);
} else {
$comments = "";
}
Line 301:
if(isset($comments)) {
foreach ($comments as $comment) {
$result .= '<li>' . fb_social_comments_seo_comment_view($comment);
if (isset($comment -> comments)){
$result .= '<ul>';
foreach ($comment -> comments -> data as $subcomment) {
$result .= '<li>' . fb_social_comments_seo_comment_view($subcomment) . '</li>';
}
$result .= '</ul>';
}
$result .= '</li>';
}
}
Comment | File | Size | Author |
---|---|---|---|
#5 | 1485838-fb-social-warning.patch | 604 bytes | klausi |
#2 | comments.inc_.patch | 716 bytes | johnzzon |
Comments
Comment #1
johnzzonActually the problem seems to be that Facebook changed the structure of the returned JSON.
One simple line fixed this for me:
Line 288 - Original
Line 288 - Fix:
Comment #2
johnzzonRight, gave this patch thingy a try, please correct me if I did it wrong.
Comment #3
TechNikh CreditAttribution: TechNikh commentedI had the same issue. The above patch fixed it.
Comment #4
klausipatch does not apply.
Comment #5
klausiRerolled.
Comment #6
pianomansam CreditAttribution: pianomansam commentedConfirmed that this is taken care of in 7.x-2.x-dev. Can we get this pushed to a non-dev version?
Comment #7
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedI was running the fb_social dev version and the patch still applied
Comment #8
cblanglois CreditAttribution: cblanglois commentedThis worked perfect for me, thanks!
Comment #8.0
cblanglois CreditAttribution: cblanglois commentedAfter nullify $comments if $result->$url->data is not set, otherwise return $comments gives error.
Comment #9
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedThere might be times when $comments is not defined.
add the following to top of function:
Comment #10
ferdi CreditAttribution: ferdi commentedCommitted , thanks !
Comment #13
ferdi CreditAttribution: ferdi commentedComment #15
trong.nguyen.tcec CreditAttribution: trong.nguyen.tcec commentedError in log:
PHP Fatal error: Function name must be a string in DOCUMENT_ROOT\modules\field_ui\field_ui.admin.inc on line 154
Try to use this code.