Jump to content
  • Sign Up

[PoC] Linking imgur-Images in Postings (Vanilla Forums Plugin)


Tiscan.8345

Recommended Posts

(( Usually I would have sent this by private message but it seems like I can't (yet?) use the private messaging system ))

 

This is just a **very** (VERY!) simple "Proof of concept" that it shouldn't be *that* hard to write a simple plugin for Vanilla Forums to allow users on the Forum to post links to images that are hosted on imgur. I wrote it after reading [a thread](https://en-forum.guildwars2.com/discussion/comment/114270#Comment_114270 "a thread") where @"Gaile Gray.6029" mentions that they don't want to allow external images because of security concerns. I guess because they don't wanna leak IP-adresses to random external websites.

 

Probably @"Lawton Campbell.8517" can take a look at it and think about adding something like it to the forum :smile:

 

$PluginInfo['ArenaExtension'] = [ 'Name' => 'ArenaNet Extensions',

'Description' => 'Very simple proof of concept for imgur-images.',

'Version' => '0.1',

'Author' => 'Tiscan.8345',

'RequiredApplications' => ['Vanilla' => '>=2.3'],

'MobileFriendly' => true,

'License' => 'Public Domain' ];

 

class ArenaExtensionPlugin extends Gdn_Plugin {

 

public function Format_Links_Handler($sender, $args) {

 

$mixed =& $args['Mixed'];

$regexp = "]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";

 

if (preg_match_all("/$regexp/siU", $mixed, $matches, PREG_SET_ORDER)) {

 

foreach ($matches as $match) {

if (preg_match('#http(s?):\/\/i\.imgur\.com\/[a-zA-Z0-9]{6,8}(\.jpg|\.gif|\.png)#i', $match[2])) {

$mixed = str_replace($match[0], ''.$match%5B2%5D.'', $mixed);

}

}

 

}

 

}

 

}

 

It basically turns every link in a posting that looks like an imgur link (https://i.imgur.com/2eDEevQ.png) into an img-tag. To install it, just create a file like "class.arenaextension.plugin.php" in a folder called "plugins/ArenaExtension" and thats pretty much it. Right now it turns all imgur-links into images - a better solution would probably be to only turn links into images that are surrounded by line-breaks.

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...