[CDB] Magic OGP links: thumbnails and descriptions

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Suggested Hosts
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
User avatar
Ger
Recognised Extension Developer
Posts: 1962
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

[CDB] Magic OGP links: thumbnails and descriptions

Post by Ger »

Extension Name:Magic OGP links: thumbnails and descriptions
Author: Ger

Extension Description: Fetch plain pasted "magic urls" to render as rich content with the Open Graph Protocol tags, just like you see on Facebook, Twitter, etc.

Extension Version: 1.0.0

Requirements:
  • phpBB 3.2
  • PHP 5.4+
  • cURL
  • Libxml
  • DOMDocument
  • DOMXPath
All of these are usually available on your server when you're on a descent host.

Visitors need Javascript for the rendering, otherwise the links appear as regular phpBB links.

Features:
  • Let users simply copy and paste their links without hassle
  • Parses the OGP image, title and description in a nice looking block
  • The entire block is the link
  • Falls back to regular HTML title and meta description when possible
  • Falls back to regular phpBB links when no (sufficient) OGP data is found
  • Fetches OGP data on posting so it doesn't impact each time on rendering
  • When posting with url=... tags the OGP data isn't fetched so your users can choose use regular links in their text when they want to
Screenshots:
Image


Extension Download: https://github.com/GerB/magicogp
Last edited by Ger on Mon Nov 13, 2017 2:27 pm, edited 4 times in total.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
JoshyPHP
Code Contributor
Posts: 1164
Joined: Mon Jul 11, 2011 12:28 am

Re: [3.2][ALPHA] Magic OGP URL: rich pasted links

Post by JoshyPHP »

I took a quick look at the repository. Looks alright. I think you can replace this block of code:

Code: Select all

// Search image_src if no img yet
if (!isset($this->values['image'])) {
	$domxpath = new \DOMXPath($doc);
	$elements = $domxpath->query("//link[@rel='image_src']");
	if ($elements->length > 0) {
		$domattr = $elements->item(0)->attributes->getNamedItem('href');
		if ($domattr) {
			$this->values['image'] = $domattr->value;
			$this->values['image_src'] = $domattr->value;
		}
	}
}

// Still no image? Try fetching the icon
if (!isset($this->values['image'])) {
	$domxpath = new \DOMXPath($doc);
	$elements = $domxpath->query("//link[@rel='icon']");
	if ($elements->length > 0) {
		$domattr = $elements->item(0)->attributes->getNamedItem('href');
		if ($domattr) {
			$this->values['image'] = $domattr->value;
			$this->values['image_src'] = $domattr->value;
		}
	}
}
...with this:

Code: Select all

foreach (['image_src', 'icon'] as $name)
{
	$value = $domxpath->evaluate('string(//link[@rel="' . $name . '"]/@href)');
	if ($value > '')
	{
		$this->values['image']     = $value;
		$this->values['image_src'] = $value;
		break;
	}
}
You may also want to look into those XPath queries, although it's not as useful since you need to retrieve the name of the OGP property too:

Code: Select all

//meta[starts-with(@property, "og:")]/@content
//meta[starts-with(@name,     "og:")]/@content
//meta[starts-with(@property, "og:")]/@value
I wrote the thing that does BBCodes in 3.2+.
User avatar
Ger
Recognised Extension Developer
Posts: 1962
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: [3.2][ALPHA] Magic OGP URL: rich pasted links

Post by Ger »

Thanks :)

Yeah, I copied that thingy later to check if it would make a difference. Code is still far from complete and can definitely use some optimisations here and there.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
Chrono
Registered User
Posts: 71
Joined: Fri Jul 12, 2002 2:52 am
Location: Chihuahua México
Name: Alfonso Camacho
Contact:

Re: [3.2][ALPHA] Magic OGP URL: rich pasted links

Post by Chrono »

Hey... thats a cool and awesome idea :D

Can I sugest at option to show the content in vertical? nice thumb in the left whit the summary in the right :D, or some size option to personalize the output of the content :)

Keep the good work.

Cheers!
www.degeneracionx.com - Anime, Games & Nothing Else.
Anime and Games Hispanic Community (Spanish only)
Sorry for my poor english
User avatar
SalazarAG
Registered User
Posts: 677
Joined: Mon Mar 30, 2015 10:48 am

Re: [3.2][ALPHA] Magic OGP URL: rich pasted links

Post by SalazarAG »

Hi! Excellent extension, but does it cause conflict with Media Embed?
I'm sorry for my English. Google Translator does a bad job. :D
User avatar
Toxyy
Registered User
Posts: 807
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek
Contact:

Re: [3.2][ALPHA] Magic OGP URL: rich pasted links

Post by Toxyy »

Is it responsive?
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

My extensions:
[3.2][BETA] Anonymous Posts || [3.2][BETA] Sticky Ad || [3.2][RC] Show User Activity ||
[3.2][DEV] User Delete Topics || [3.3][RC] Short Number Twig Extension
User avatar
Ger
Recognised Extension Developer
Posts: 1962
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: [3.2][ALPHA] Magic OGP URL: rich pasted links

Post by Ger »

SalazarAG wrote:
Fri Sep 15, 2017 1:45 am
Hi! Excellent extension, but does it cause conflict with Media Embed?
Haven't tried it yet. I'd say: take a test and let me know :P
This is the very first version of this extension, not much more than a proof-of-concept.
Toxyy wrote:
Fri Sep 15, 2017 4:36 am
Is it responsive?
It scales just like any other text and image in a post.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
Ger
Recognised Extension Developer
Posts: 1962
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: [3.2][ALPHA] Magic OGP URL: rich pasted links

Post by Ger »

Chrono wrote:
Thu Sep 14, 2017 7:31 pm
Can I sugest at option to show the content in vertical? nice thumb in the left whit the summary in the right :D, or some size option to personalize the output of the content :)
Missed this earlier.

I've added some simple styling in ./ext/ger/magicogp/styles/prosilver/theme/magicogp.css
If you want to, you can add or override these definitions in your own stylesheet.

You might want to do something like this:

Code: Select all

.ogpblock img {
	width: 150px;
}
.ogptext {
	width: calc(100% - 180px);
}
That should cover it. Be aware though that this extension is far from ready so I might change the default style definitions and that they mess with your additions.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
SalazarAG
Registered User
Posts: 677
Joined: Mon Mar 30, 2015 10:48 am

Re: [3.2][ALPHA] Magic OGP URL: rich pasted links

Post by SalazarAG »

Ger wrote:
Fri Sep 15, 2017 6:54 am
SalazarAG wrote:
Fri Sep 15, 2017 1:45 am
Hi! Excellent extension, but does it cause conflict with Media Embed?
Haven't tried it yet. I'd say: take a test and let me know :P
This is the very first version of this extension, not much more than a proof-of-concept.
Toxyy wrote:
Fri Sep 15, 2017 4:36 am
Is it responsive?
It scales just like any other text and image in a post.
Hi, I tested the two extensions and had no conflicts. Very good. Congratulations for your work.
I'm sorry for my English. Google Translator does a bad job. :D
User avatar
Ger
Recognised Extension Developer
Posts: 1962
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: [3.2][ALPHA] Magic OGP URL: rich pasted links

Post by Ger »

Thanks!
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
Ger
Recognised Extension Developer
Posts: 1962
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: [3.2][BETA] Magic OGP URL: rich pasted links

Post by Ger »

Most functions seem to be working well, so I upped this to BETA.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
Ger
Recognised Extension Developer
Posts: 1962
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: [3.2][RC] Magic OGP links: thumbnails and descriptions

Post by Ger »

I tweaked the styling a bit, see the updated screenshot in TS.
Since everything seems to work smoothly I intend to release this soon.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
Chrono
Registered User
Posts: 71
Joined: Fri Jul 12, 2002 2:52 am
Location: Chihuahua México
Name: Alfonso Camacho
Contact:

Re: [3.2][RC] Magic OGP links: thumbnails and descriptions

Post by Chrono »

Ger wrote:
Wed Oct 04, 2017 8:21 am
I tweaked the styling a bit, see the updated screenshot in TS.
Since everything seems to work smoothly I intend to release this soon.
Nice. Im gonna checkit out :)

Cheers!
www.degeneracionx.com - Anime, Games & Nothing Else.
Anime and Games Hispanic Community (Spanish only)
Sorry for my poor english
User avatar
</Solidjeuh>
Registered User
Posts: 1788
Joined: Tue Mar 29, 2016 3:45 am
Location: Aalst (Belgium)
Name: Andy Dm
Contact:

Re: [3.2][RC] Magic OGP links: thumbnails and descriptions

Post by </Solidjeuh> »

It should pull an image from the link, to share your post on social media like Facebook :lol:
Naaah it works great! Thank you!
User avatar
Theriddler1
Registered User
Posts: 449
Joined: Sat Aug 27, 2011 11:00 pm
Location: NL
Name: Theriddler❶
Contact:

Re: [3.2][RC] Magic OGP links: thumbnails and descriptions

Post by Theriddler1 »

tested your extension Ger, nice work but i can only see it parsed when previewing the post
after posting the link is not parsed anymore

example: https://peppersrusforum.nl/viewtopic.php?p=44321#p44321
Theriddler - Former Moderator @ phpBB.nl | phpBBservice.nl Team-member
Image My Extensions | buy me a beer Image
Locked

Return to “Extensions in Development”