vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Adding user profile picture to open graph (https://vborg.vbsupport.ru/showthread.php?t=324116)

SilverBoy 01-03-2017 06:39 PM

Adding user profile picture to open graph
 
Hi

In my CMS articles I displays the avatars of the author of the article, but because the image is small (60×60 px) Facebook didn't grab it when I share the link to Facebook.

So I think in adding user profile picture (Big size) as a variable to the opengraph array.

The question is ..
How I can get the profile picture in every article?
then how I can add it to opengraph array?

Thanks in advance.

MarkFL 01-03-2017 06:56 PM

Assuming you have the user's userid in $userid, you can get the URL of their profile pic as follows:

PHP Code:

$ppuserinfo fetch_userinfo($userid8);

if (
$vbulletin->options['usefileavatar'])
{
    
$ppuserinfo['profilepicurl'] = $vbulletin->options['profilepicurl'] . '/profilepic' $ppuserinfo['userid'] . '_' $ppuserinfo['profilepicrevision'] . '.gif';

    if (!
file_exists($ppuserinfo['profilepicurl']))
    {
        
$ppuserinfo['profilepicrevision'] = 0;
    }
}
else
{
    
$ppuserinfo['profilepicurl'] = 'image.php?' $vbulletin->session->vars['sessionurl'] . 'u=' $ppuserinfo['userid'] . "&dateline=$ppuserinfo[profilepicdateline]&type=profile";
}

$profilepicexists $ppuserinfo['profilepicrevision'] OR $ppuserinfo['profilepicdateline']; 

Now, if the variable $profilepicexists evaluates to true, the URL of the profile pic is in $ppuserinfo['profilepicurl']. :)

SilverBoy 01-03-2017 06:59 PM

Thank you mark, I will give it a try, but how I can inject the profilepic to the opengraph array?
I tried it manually by adding link to the image in the top of vbcms_content_article template but Facebook ignore it and don't add it to the og:images !!

MarkFL 01-03-2017 07:05 PM

I don't know what key you wish to use for the $opengraph array, but suppose with wish to use the key "profilepicurl', then you could add:

PHP Code:

if ($profilepicexists)
{
    
$opengraph['profilepicurl'] = $ppuserinfo['profilepicurl'];



SilverBoy 01-03-2017 07:11 PM

I want to use og:image property.

MarkFL 01-03-2017 07:20 PM

Quote:

Originally Posted by SilverBoy (Post 2580269)
I want to use og:image property.

I don't know what that is...I thought you wanted to store the URL of the profile pic in the specified array. :)

I have negligible experience with the CMS articles feature of vB, but I thought I would be able to give you a leg up on getting the data you want into the array. :D

MarkFL 01-03-2017 07:23 PM

After a quick google search, it appears you need a meta tag in your template, and you will have to register the URL variable for your template, and your meta tag would then look something like:

HTML Code:

<meta property="og:image" content="{vb:raw profilepicurl}" />

SilverBoy 01-03-2017 07:24 PM

:D
When you share a link in FB, the image that appears as thumbnail comes from this property.
If you open any page in sharing debugger tools you will see all properties that FB uses from your page.
https://developers.facebook.com/tools/debug/sharing/

--------------- Added [DATE]1483478739[/DATE] at [TIME]1483478739[/TIME] ---------------

Stupid Q
How I can register the variable?

--------------- Added [DATE]1483479009[/DATE] at [TIME]1483479009[/TIME] ---------------

PHP Code:

 $ppuserinfo fetch_userinfo($userid8); 

Sorry, #8 here what is mean?

MarkFL 01-03-2017 07:33 PM

Suppose you have the name of the template to which you wish to send the variable in $template_name, then in your plugin, you could use

PHP Code:

if ($profilepicexists)
{
    
vB_Template::preRegister($template_name, array('profilepicurl' => $ppuserinfo['profilepicurl']));



SilverBoy 01-03-2017 07:39 PM

Here is my plugin, is it right?

Hook: vbcms_article_populate_end(vbulletin cms)
Name: Add profile picture as meta tag
Order: 5
Code:
PHP Code:

$ppuserinfo fetch_userinfo($userid8);

if (
$vbulletin->options['usefileavatar'])
{
    
$ppuserinfo['profilepicurl'] = $vbulletin->options['profilepicurl'] . '/profilepic' $ppuserinfo['userid'] . '_' $ppuserinfo['profilepicrevision'] . '.gif';

    if (!
file_exists($ppuserinfo['profilepicurl']))
    {
        
$ppuserinfo['profilepicrevision'] = 0;
    }
}
else
{
    
$ppuserinfo['profilepicurl'] = 'image.php?' $vbulletin->session->vars['sessionurl'] . 'u=' $ppuserinfo['userid'] . "&amp;dateline=$ppuserinfo[profilepicdateline]&amp;type=profile";
}

$profilepicexists $ppuserinfo['profilepicrevision'] OR $ppuserinfo['profilepicdateline'];
if (
$profilepicexists)
{
    
vB_Template::preRegister(vbcms_content_article_page, array('profilepicurl' => $ppuserinfo['profilepicurl']));


--------------- Added [DATE]1483479854[/DATE] at [TIME]1483479854[/TIME] ---------------

It didn't work !!

Here is what I get in my source code
HTML Code:

<meta property="og:image" content="" />


All times are GMT. The time now is 03:49 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01136 seconds
  • Memory Usage 1,765KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_html_printable
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete