PDA

View Full Version : Png link auto embed(convert)


mobster46
02-05-2017, 08:04 AM
How can I automatically convert a picture when I add a link?

For example
http://travian-reports.net/tr/img/154441a5f4e.png

I do not want it to appear as a link.

I find auto youtube embed(https://vborg.vbsupport.ru/showthread.php?t=261296)
but ı dont find image link convert.

MarkFL
02-05-2017, 08:42 AM
Create a plugin hooked at "postbit_display_start" with the code:

$post['pagetext'] = preg_replace('/\[url\](http.*?\.png)\[\/url\]/', 'https://vborg.vbsupport.ru/', $post['pagetext']);

Stratis
02-08-2017, 05:47 PM
Mark to include more, png, gif, jpeg, etc ?

Thanks in advanced :)

mobster46
02-10-2017, 04:12 AM
Create a plugin hooked at "postbit_display_start" with the code:

$post['pagetext'] = preg_replace('/\[url\](http.*?\.png)\[\/url\]/', 'https://vborg.vbsupport.ru/', $post['pagetext']);

Mark to include more, png, gif, jpeg, etc ?

Thanks in advanced

MarkFL
02-10-2017, 04:36 AM
Mark to include more, png, gif, jpeg, etc ?

Thanks in advanced

You may recall I had to add some code because of post caching...please post the entire content of the plugin I put on your site, and I will modify it to include more file extensions. :)

mobster46
02-10-2017, 07:31 AM
You may recall I had to add some code because of post caching...please post the entire content of the plugin I put on your site, and I will modify it to include more file extensions. :)

I do not know what you add: D

Stratis
02-13-2017, 02:52 PM
I do not know what you add: D

admincp

Plugins & Products -> Plugin Manager -> You must remember the title to see it, maybe at top.
Read and i thing you will understand which is..

* If you press on the title you will see the code :)

mobster46
02-13-2017, 04:34 PM
admincp

Plugins & Products -> Plugin Manager -> You must remember the title to see it, maybe at top.
Read and i thing you will understand which is..

* If you press on the title you will see the code :)

There is not.

--------------- Added 1487010990 at 1487010990 ---------------

https://vborg.vbsupport.ru/external/2017/02/7.png

--------------- Added 1487011022 at 1487011022 ---------------

https://vborg.vbsupport.ru/external/2017/02/8.png

--------------- Added 1487011282 at 1487011282 ---------------

ok ı see. sory

true?

$content = preg_replace('/\[URL\](http.*?\.png)\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);
$content = preg_replace('/\[URL\](http.*?\.jpg)\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);

if ($content != $post['pagetext'])
{
global $vbulletin;
$pagetext = $content;
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$post['pagetext_html'] = $bbcode_parser->parse($pagetext, $post['forumid'], 1);
$post['pagetext_html'] = html_entity_decode($post['pagetext_html']);
}

BadgerDog
02-16-2017, 03:46 PM
This looks interesting ..

So, for clarity, if I create a plugin titled with some name and hooked at "postbit_display_start" with the code:

$content = preg_replace('/\[URL\](http.*?\.png)\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);
$content = preg_replace('/\[URL\](http.*?\.jpg)\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);

if ($content != $post['pagetext'])
{
global $vbulletin;
$pagetext = $content;
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$post['pagetext_html'] = $bbcode_parser->parse($pagetext, $post['forumid'], 1);
$post['pagetext_html'] = html_entity_decode($post['pagetext_html']);
}

Then the site will automatically display all links that were PNG and JPG as pictures?

Regards,
Doug

MarkFL
02-16-2017, 04:12 PM
What you would want for the first line is:

$content = preg_replace('/\[URL\](http.*?\.(png|jpg|gif))\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);

BadgerDog
02-16-2017, 04:15 PM
What you would want for the first line is:

$content = preg_replace('/\[URL\](http.*?\.(png|jpg|gif))\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);

Thank you Mark ... :)

You are always so gracious and helpful on this site... :up:

Regards,
Doug

Stratis
02-16-2017, 05:14 PM
What you would want for the first line is:

$content = preg_replace('/\[URL\](http.*?\.(png|jpg|gif))\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);

is this the final?

$content = preg_replace('/\[URL\](http.*?\.(png|jpg|gif))\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);
if ($content != $post['pagetext'])
{
global $vbulletin;
$pagetext = $content;
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$post['pagetext_html'] = $bbcode_parser->parse($pagetext, $post['forumid'], 1);
$post['pagetext_html'] = html_entity_decode($post['pagetext_html']);
}
because in post #2 you do not have all this code :)

Thank you very much

MarkFL
02-16-2017, 05:21 PM
is this the final?

$content = preg_replace('/\[URL\](http.*?\.(png|jpg|gif))\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);
if ($content != $post['pagetext'])
{
global $vbulletin;
$pagetext = $content;
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$post['pagetext_html'] = $bbcode_parser->parse($pagetext, $post['forumid'], 1);
$post['pagetext_html'] = html_entity_decode($post['pagetext_html']);
}
because in post #2 you do not have all this code :)

Thank you very much

Post #2 was what worked on my local dev site, but then I realized it worked for me because I have post caching turned off there...so, I revised the code to reparse the post for the OP, who has post caching turned on.

Stratis
02-16-2017, 05:59 PM
Ok, I have "Cached Posts Lifespan" to zero (0)
so i will use the first line. Thanks Mark.

MarkFL
02-16-2017, 06:12 PM
Ok, I have "Cached Posts Lifespan" to zero (0)
so i will use the first line. Thanks Mark.

In that case, you would want:

$post['pagetext'] = preg_replace('/\[URL\](http.*?\.(png|jpg|gif))\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);

:)

Stratis
02-16-2017, 06:19 PM
Yes, Yes :)

--------------- Added 1487278112 at 1487278112 ---------------

I forgot to ask, I want to recognize when link images turn to img, is there a way to put in code some title that I would like and to show at the bottom of the image?

or attribute to see when hover image :D

BadgerDog
02-21-2017, 12:22 PM
Ok, for my clarity and so I don't screw it up ... :)

Is this the code I need to use to create the plugin discussed?

$post['pagetext'] = preg_replace('/\[URL\](http.*?\.(png|jpg|gif))\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);
if ($content != $post['pagetext'])
{
global $vbulletin;
$pagetext = $content;
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$post['pagetext_html'] = $bbcode_parser->parse($pagetext, $post['forumid'], 1);
$post['pagetext_html'] = html_entity_decode($post['pagetext_html']);
}

Thanks .. :)

Regards,
Doug

MarkFL
02-21-2017, 12:52 PM
Ok, for my clarity and so I don't screw it up ... :)

Is this the code I need to use to create the plugin discussed?



Thanks .. :)

Regards,
Doug

You want:

$content = preg_replace('/\[URL\](http.*?\.(png|jpg|gif))\[\/URL\]/i', 'https://vborg.vbsupport.ru/', $post['pagetext']);

if ($content != $post['pagetext'])
{
global $vbulletin;
$pagetext = $content;
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$post['pagetext_html'] = $bbcode_parser->parse($pagetext, $post['forumid'], 1);
$post['pagetext_html'] = html_entity_decode($post['pagetext_html']);
}

BadgerDog
02-21-2017, 01:10 PM
You want:

$content = preg_replace('/\[URL\](http.*?\.(png|jpg|gif))\[\/URL\]/i', '$1', $post['pagetext']);

if ($content != $post['pagetext'])
{
global $vbulletin;
$pagetext = $content;
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$post['pagetext_html'] = $bbcode_parser->parse($pagetext, $post['forumid'], 1);
$post['pagetext_html'] = html_entity_decode($post['pagetext_html']);
}

Thanks again .. :up:

Regards,
Doug