MyBB Community Forums

Full Version: [Support] Open Graph Metas
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Open Graph Metas
This thread dedicates to the plugin support.

The plugin will enable forums/threads/etc. pages to show Open Graph metas for social websites integration.

Extend site: https://community.mybb.com/mods.php?acti...w&pid=1366
GitHub repo: https://github.com/yuliu/mybb-plugin-open-graph-metas/

Test your site/pages with Facebook sharing debugger: https://developers.facebook.com/tools/debug/ (requires Facebook login)

Features:
  • Output Open Graph metas for forum modules. Read the Open Graph protocol: https://ogp.me/.
  • No template editing requires.
  • Search-engine-friendly-URLs-aware og:url.
  • Customizable fallback description for og:description, now via file editing.
  • Customizable fallback image for og:image, now via file editing.
  • Customizable og:image for threads/posts, now via file editing.
  • Supported modules:
    • Forums
    • Threads (linear view mode)
    • Posts (threaded view mode)
    • Member profiles
    • ... more will come!
  • Partially supported modules:
    • Help page
    • Member list
    • Portal
    • Search
    • Calendar
    • ... more will come!

Requirement:
  • MyBB 1.8.x

Install:
  1. Download & unzip.
  2. Upload files under Upload/ folder, please maintain the folder structure.
  3. Turn to MyBB's AdminCP > Configuration > Plugins, find Open Graph Metas and activate it.

Uninstall & Removal:
  1. Turn to MyBB's AdminCP > Configuration > Plugins, find Open Graph Metas and deactivate it.
  2. Remove file ./inc/plugins/open_graph_metas.php from your server.

Suggestions & Bug report (either is OK):

Other relevant plugins:
[For 1.6] Facebook Open Graph Meta Tags: https://community.mybb.com/thread-93386.html
[For 1.8] MySEO, improve SEO OnPage in your forum: https://community.mybb.com/thread-166864.html
[For 1.8] SEO Titles & Open Graph: https://community.mybb.com/thread-109253.html
[For 1.6] Google SEO 1.6.8 [EOL]: https://community.mybb.com/thread-101262.html
It would be super if it supported xThreads image file fields. Also, I think you should make it friendly with Google SEO links.
(2020-05-05, 02:11 AM)Omar G. Wrote: [ -> ]It would be super if it supported xThreads image file fields. Also, I think you should make it friendly with Google SEO links.

It'd be helpful if more info about xThreads's image file fileds is given.

And.. by "Google SEO links" you mean a specific SEO plugin?
(2020-05-05, 02:46 AM)noyle Wrote: [ -> ]And.. by "Google SEO links" you mean a specific SEO plugin?

I was referring specifically to the usage of the get_thread_url and similar functions.

(2020-05-05, 02:46 AM)noyle Wrote: [ -> ]It'd be helpful if more info about xThreads's image file fileds is given.

What I did in my plugin was to add a setting which builds a select for all existing thread fields. I suppose you could add two in case administrators want to use a specific thumbnail. Since you are hooking at showthread_end you should be able to get all fields data at that point.
(2020-05-05, 05:43 AM)Omar G. Wrote: [ -> ]I was referring specifically to the usage of the get_thread_url and similar functions.

Yep the plugin is made bearing the mind that the URL will adapt when $mybb->seo_support is on or off.

(2020-05-05, 05:43 AM)Omar G. Wrote: [ -> ]What I did in my plugin was to add a setting which builds a select for all existing thread fields. I suppose you could add two in case administrators want to use a specific thumbnail. Since you are hooking at showthread_end you should be able to get all fields data at that point.

Currently the plugin hooks to showthread_threaded and showthread_linear for threads module for displaying post message content for a specific post and page, respectively.

Haven't tried xThread but I imagine if a plugin would add some dedicated fields like a image banner or a featured photo, that should be exactly the thing to be added.
(2020-05-05, 06:01 AM)noyle Wrote: [ -> ]Yep the plugin is made bearing the mind that the URL will adapt when $mybb->seo_support is on or off.

Yes, but not with Google SEO (plugin) URLs because it uses the core functions, which I think is the correct approach to be plugin friendly.

With this I see some issues, like when you visit directly ./showthread.php?tid=x&mode=threaded. The generated URL is invalid.

You save yourself a lot of trouble just by using the core functions.

(2020-05-05, 06:01 AM)noyle Wrote: [ -> ]Haven't tried xThread but I imagine if a plugin would add some dedicated fields like a image banner or a featured photo, that should be exactly the thing to be added.

Yes, that is pretty much what should be expected. I suppose you could try to fetch the first inserted image from the post as well (that would be more MyBB friendly than xThread friendly).

It also has a setting to display the first post in every page, so it might be the case where an administrator wants to output the thread meta data only for all posts in it. Of course this might be too much to ask. I could send a pull request once you get a solid release (as it seems you expect the code to change highly in upcoming releases).

Edit: Sorry for hijacking your non-development thread Toungue
(2020-05-05, 07:14 AM)Omar G. Wrote: [ -> ]Yes, but not with Google SEO (plugin) URLs because it uses the core functions, which I think is the correct approach to be plugin friendly.

With this I see some issues, like when you visit directly ./showthread.php?tid=x&mode=threaded. The generated URL is invalid.

You save yourself a lot of trouble just by using the core functions.

Yes there's a problem with threaded mode view. I was goofy that I didn't check $threadmode doesn't exist in linear mode view. Had fixed that issue hours ago locally.

(2020-05-05, 07:14 AM)Omar G. Wrote: [ -> ]Yes, that is pretty much what should be expected. I suppose you could try to fetch the first inserted image from the post as well (that would be more MyBB friendly than xThread friendly).

Here's my plan for the og:image meta:
  1. 3rd party plugin's field like featured image goes first, only just I haven't yet integrated any.
  2. Loop through all attached images in posts in a page, choose the first one met some criteria (eg. size > XX|YY).
  3. (*) Loop through all images using [img] in posts in a page, choose the first one.
  4. Fallback to use the first post author's avatar.
  5. Fallback to default setting of a logo specified by admin.
  6. Fallback to setting of theme logo.

(*) It's not ideal without image size checking, and not applicable with size checking but without cache support.

(2020-05-05, 07:14 AM)Omar G. Wrote: [ -> ]It also has a setting to display the first post in every page, so it might be the case where an administrator wants to output the thread meta data only for all posts in it. Of course this might be too much to ask. I could send a pull request once you get a solid release (as it seems you expect the code to change highly in upcoming releases).

Do you mean that some plugins (maybe xThread) allows the first post of a thread to be displayed in paged linear mode view? I don't know how would it get achieved but it seems to me that the possible mechanism for doing so may be incompatible to this plugin. However, I could add a switch to support such feature.

Yeah I recognize that Twitter card can be supported simultaneously, and maybe WordPress card (not sure). So I also plan to change this "Open Graph Metas" to something maybe "Social Integration???". Also I'm not so sure about adding additional settings into the database because current way looks ancient, sort of Angel . And if I would do so, I'll definitely change the plugin folder structure.

(2020-05-05, 07:14 AM)Omar G. Wrote: [ -> ]Edit: Sorry for hijacking your non-development thread Toungue

That's OK. Questions, feedback & suggestions are all welcome.
This would be nice Smile I am looking forward to first stable release and then I will replace my hard coded values in templates for this one!
Quote:Do you mean that some plugins (maybe xThread) allows the first post of a thread to be displayed in paged linear mode view? I don't know how would it get achieved but it seems to me that the possible mechanism for doing so may be incompatible to this plugin.

Yes, basically only xThreads that I know of. So it might be the case that for a thread page the administrator wants to assign open graph meta data from the first post to all the page (thus, posts are seen as comments only, like a blog).

But it might be out of the scope of this plugin. Maybe only adding a setting to assign the first post data to all the thread pages would suffice.

Quote:Here's my plan for the og:image meta:

Seems reasonable. I suppose you can add a post field to cache the post image data so you don't have to loop through all the message on each page load to find a fitted [img] image.

(Also, note that regarding both points here responded to, xThreads works on a per forum basis, for both image file fields and displaying the first post in all pages, thus either it might require you adding some on per forum basis settings for it or simply adding some hooks so that external plugins can modify some values themselves. This is why I mentioned I could send a PR if it was too much asking.)
(2020-05-07, 01:39 PM)Eldenroot Wrote: [ -> ]This would be nice Smile I am looking forward to first stable release and then I will replace my hard coded values in templates for this one!
0.2 is the most recent / first stable release: https://community.mybb.com/mods.php?acti...6&bid=4389

Recommended settings (requires manual file editing to ./inc/plugins/open_graph_metas.php):

// Default logo, if not blank, will be used as fallback for og:image.
define('OPEN_GRAPH_METAS_DEFAULT_LOGO', 'Your_LOGO_URL');             // <--- replace Your_LOGO_URL with your full logo URL.

// Default description, if not blank, will be used as fallback for og:description.
define('OPEN_GRAPH_METAS_DEFAULT_DESC', 'Board_Desc');             // <--- replace Board_Desc with desired board description.

/**
 * Use attachment (image type) as og:image for threads:
 * 0 - none and fallback will be used.
 * 1 - full attachment if possible, otherwise fallback will be used.
 * 2 - thumbnail if possible, otherwise fallback will be used.
 */
define('OPEN_GRAPH_METAS_THREAD_IMAGE_USE_ATTACHMENT', 2);             // 2 or 0 is the suggested value.

/**
 * Use attachment (image type) as og:image for posts:
 * 0 - none and fallback will be used.
 * 1 - full attachment if possible, otherwise fallback will be used.
 * 2 - thumbnail if possible, otherwise fallback will be used.
 */
define('OPEN_GRAPH_METAS_POST_IMAGE_USE_ATTACHMENT', 2);             // 2 or 0 is the suggested value.

/**
 * Fallback image for og:image for threads:
 * 0 - fallback to default logo.
 * 1 - poster's avatar.
 */
define('OPEN_GRAPH_METAS_THREAD_IMAGE_FALLBACK', 1);       // change 1 to 0, if you want show LOGO instead of user avatar.

/**
 * Fallback image for og:image for posts:
 * 0 - fallback to default logo.
 * 1 - poster's avatar.
 */
define('OPEN_GRAPH_METAS_POST_IMAGE_FALLBACK', 1);      // change 1 to 0, if you want show LOGO instead of user avatar.
Pages: 1 2