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 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 = "<a\s[^>]*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], '<img src="'.$match[2].'" />', $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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...