PDA

View Full Version : Auto Parse Onsite URL's


Mr Blunt
06-29-2005, 10:00 PM
This post is basically the same as lone text file in the zip.
Download is merely available for convenience.
Here goes.......


If anyone can improve upon this and/or find a way to make this a plugin, SPEAK UP!! Personally I think something like this should be standard, but hey, can't have it all.


By default, vbulletin autoparses all links so most won't need a hack like this.
However, I don't like offsite links so I made a plugin to clear the checkbox.

https://vborg.vbsupport.ru/showthread.php?t=91390

But I love onsite links like to other threads and files which reside on my subdomain, so I put together a few file edits that will automatically call the url parser if the subdomain name is found anywhere in the text message. It's no surprise your just adding a bit more code to any/all lines which check if the parse url's box is checked, because the line that follows these is what calls the parser.


The only quirk that people find odd is that it's an "all or nothing" type thing. If the message has a mixture of onsite AND offsite url's, all links will parse. Meaning it checks the message in "one lump".


Please note you can pick and choose from these file modifications!!
Each one works independantly and the file names should clue you as to what's what.


This is by no means complete!!
It merely works....
Call it a "works in progress", LOL.


In /editpost.php find this:
$checked['parseurl'] = 'checked="checked"';

Change to this:
$checked['parseurl'] = ($postinfo['parseurl']) ? 'checked="checked"' : '';


In /private.php find this:
if ($vbulletin->GPC['parseurl'])

Change to this:
if ($vbulletin->GPC['parseurl'] OR stristr($vbulletin->GPC['message'], $_SERVER['HTTP_HOST']))


ALSO In /private.php find this:
'parseurl' => true,

Change to this:
'parseurl' => false,


In /profile.php find this:
$signature = convert_url_to_bbcode($signature);

Change to this:
if (stristr($signature, $_SERVER['HTTP_HOST']))
{
$signature = convert_url_to_bbcode($signature);
}


In /usernote.php find this:
if ($vbulletin->GPC['parseurl'])

Change to this:
if ($vbulletin->GPC['parseurl'] OR stristr($vbulletin->GPC['message'], $_SERVER['HTTP_HOST']))


In /includes/class_dm.php find this:
if ($this->info['parseurl'])

Change to this:
if ($this->info['parseurl'] OR stristr($pagetext, $_SERVER['HTTP_HOST']))

Allan
07-13-2005, 07:06 PM
screen please :)

Mr Blunt
07-16-2005, 07:49 PM
Screen shot of what, Allen?
There's nothing to take a picture of.

merk
07-16-2005, 10:42 PM
Be careful, it looks like you're only changing some HTML in a signature when its an internal link. That might be okay for what you want to do, but it means the HTML is still there if it isnt for a subdomain.

Could open up some awful security problems if im reading it right.

Andreas
08-04-2005, 10:32 PM
A maybe easier, generalized and more failsafe approach:

In functions_newpost.php
FIND

// ###################### Start convert_url_to_bbcode_callback #######################


ABOVE that ADD

function autoparse_onsite($url)
{
$parsed = parse_url($url);
if (stripos($parsed['host'], getenv('HTTP_HOST')) !== false)
{
return '' . $url . '';
}
else
{
return $url;
}
}


FIND

$urlSearchArray = array(
"#(^|(?<=[^_a-z0-9-=\]\"'/@]|(?<=" . $taglist . ")\]))((https?|ftp|gopher|news|telnet)://|www\.)((\[(?!/)|[^\s[^$!`\"'|{}<>])+)(?!\[/url|\[/img)(?=[,.]*(\)\s|\)$|[\s[]|$))#siU"
);

$urlReplaceArray = array(
"\\2\\4"
);


REPLACE that with

$urlSearchArray = array(
"#(^|(?<=[^_a-z0-9-=\]\"'/@]|(?<=" . $taglist . ")\]))((https?|ftp|gopher|news|telnet)://|www\.)((\[(?!/)|[^\s[^$!`\"'|{}<>])+)(?!\[/url|\[/img)(?=[,.]*(\)\s|\)$|[\s[]|$))#siUe"
);

$urlReplaceArray = array("autoparse_onsite('\\2\\4')");



This should take care of only autoparsing "onsite" URLs everywhere - no need to mess with Checkbox settings.
Please not that it, if for xample the Board is running on http://forum.yourdomain.com and a User posts http://www.yourdomain.com, this will not be autoparsed.
Also, if a User posts http://forum.yourdomain.com.mydomain.com/smth/doesntmatter.php or http://www.foo.bar.forum.yourdomain.com.mydomain.com/smth/doesntmatter.php it will be autoparsed.

@Merk
There are no security issues with these Modifications.
convert_url_to_bbcode() just wraps [url] around URLs - that's it.

Mr Blunt
08-24-2005, 08:44 AM
Thank You KirbyDE for stepping in!!

It was very rude of me to neglect this thread and I DO apologize. I've been in a pretty deep learning mode for a couple months because I've needed a greater understanding of vbulletin for a long long time and I'm happy to say I'm coming along nicely.

Back when Kirby posted this, I DID attempt his edit one time and it didn't work for my site ... and rather than question him ... I thought best to just sit back and stay inside my learning environment for a bit longer.

It's not a good excuse, but it's the only one I have.
Give me some time and I'll play with this again.

Andreas
08-24-2005, 09:02 AM
Hmm, before I posted this snippet I tested it on localhost and it seemed to work just fine.

Mr Blunt
08-24-2005, 11:42 AM
OK, first try, no workie.
All links parse with Full WYSIWYG Editing, no matter what checkbox says.

I switched to Basic editor and got this error:
Fatal error: Call to undefined function: stripos() in /home/testforum/includes/functions_newpost.php on line 137
So I searched, found, and added this vbulletin function above Kirby's new function to get the basic editor WORKING CORRECTLY!!

line 1922-1938 of class_bbcode.php

if (!function_exists('stripos'))
{
/**
* Case-insensitive version of strpos(). Defined if it does not exist.
*
* @param string Text to search for
* @param string Text to search in
* @param int Position to start search at
*
* @param int|false Position of text if found, false otherwise
*/
function stripos($haystack, $needle, $offset = 0)
{
$foundstring = stristr(substr($haystack, $offset), $needle);
return $foundstring === false ? false : strlen($haystack) - strlen($foundstring);
}
}

The Full Editor still parses all links but I'm still playing.
:D
I believe we need to play with the 'function parse_wysiwyg_anchor'.

Andreas
08-24-2005, 11:53 AM
Uuh, yeah - stripos() is only available on PHP 5, haven't thought of that :)

Not sure about the WYSIWYG Editor, never tried that as I do not use it.

Mr Blunt
08-24-2005, 11:56 AM
I have played with it and had some success ..... so let me continue.
I bet I can get this one, Kirby!!

Mr Blunt
08-24-2005, 02:37 PM
OK, how bad is this going to screw up other things??
:D
This works for me so far, but I haven't tested very much.

Here's the old vbulletin tag wrapper for wysiwyg url's

// ###################### Start parse_wysiwyg_anchor #######################
function parse_wysiwyg_anchor($aoptions, $text)
{
$href = parse_wysiwyg_tag_attribute('href=', $aoptions);

if (substr($href, 0, 7) == 'mailto:')
{
$tag = 'email';
$href = substr($href, 7);
}
else
{
$tag = 'url';
}
$tag = strtoupper($tag);

return "[$tag=\"$href\"]" . parse_wysiwyg_recurse('a', $text, 'parse_wysiwyg_anchor') . "[/$tag]";
}

Here's a proposed replacement:

// ###################### Start parse_wysiwyg_anchor #######################
function parse_wysiwyg_anchor($aoptions, $text)
{
$href = parse_wysiwyg_tag_attribute('href=', $aoptions);

if (substr($href, 0, 7) == 'mailto:')
{
$tag = 'email';
$href = substr($href, 7);
}
else
{
$parsed = parse_url($href);
if (stripos($parsed['host'], getenv('HTTP_HOST')) !== false)
{
$tag = 'url';
}
else
{
$tag = '';
return $href;
}
}
$tag = strtoupper($tag);

return "[$tag=\"$href\"]" . parse_wysiwyg_recurse('a', $text, 'parse_wysiwyg_anchor') . "[/$tag]";
}

I only showed the whole thing so y'all don't have to research to answer question.
Naturally, editing instructions would be much shorter if the code looks good.


And funny thing about this edit is I didn't need to define the stripos so either it's using the one I defined in functions_newpost.php or else for some reason it's able to use class_bbcode.php WHEN THE TOP OF THE SCRIPT CLEARLY REQUIRES class_bbcode_alt.php (notice the _alt and that file doesn't define stripos) because obviously I'm not using php5.
:scratcheshead:


Edited to say ....
... this whole post pertains to functions_wysiwyg.php

Andreas
08-24-2005, 03:13 PM
Hmm, for me WYSIWYG works without the additional modifications.

I just typed (in WYSIWYG, autoaprse was checked)

http://www.foobar.com

and it did not parse it.

Did you paste a URL? AFAIK there is no way to stop this from "parsing" (at least not at server-side), as this already generates <a> Tags in the Text submitted by the User, eg. the Server does not even have to detect the Links.

Mr Blunt
08-24-2005, 03:24 PM
Most people cut n paste links sooooo yes, that's what I was doing for many of my tests (not all, no).

My proposed modification removes the tags even if the link was C&P'ed, I believe. The link will "appear to be" a link in the edit window, but will unparse when you finally post the message .... and I also remove any text which a link might be trying to hide behind (that's why I return the $href without $text).

Andreas
08-24-2005, 03:33 PM
I applied your modification, but that completely stops me from being able to post URLs in WYSIWYG - at least using the Icons.
If I manually wrap it in [url] it does parse - but only one time.
If I preview or edit it, it won't work until I wrap it again.

Mr Blunt
08-24-2005, 03:49 PM
The steps I have been told for the "insert link" icon are:

Type text in message window which you will want displayed.
Highlight text.
Click Icon.
Copy your link to the box including the http://
Click OK

When I do this .... if the link was onsite .... the text will display and link will be hidden inside of it.

If the link is not onsite ... then only the unparsed link is returned to the browser and the original highlighted text is gone forever.


hmmmm ...... LOL ..... so if the href was the only text ..... would the whole thing be nullified ... hence why you got nothing?? But if so, why did my test work??

Edited to say I tried the insert a link icon again and didn't highlight any text .... the link parsed and displayed again .... so I'll bet you didn't have http on the front because without that (or without a normal www.) vbulletin has no idea it's even a link.

Andreas
08-24-2005, 03:55 PM
Well I just clicked the Icon and entered the URL.

If I do it your way, I just get the URL as Text, not as a link.
But this has nothing to do with autoparsing, as I explicitly specified that this should be a Link.

If this is what you want (don't parse any URLs that are not onsite), then it does work.
But if you only want to turn off autoparsing, it does not work.

Mr Blunt
08-24-2005, 04:00 PM
Well yes :D this is the desired effect I'm MAINLY looking for.

But once it "works" then it can be backed off a bit here or there with things like custom usergroup permissions for ability to override links or something.
:banana:

Andreas
08-24-2005, 04:06 PM
I C.

I thought you wanted to disable autoparsing.

Well, then you could also use a totally different approach:

Create a Plugin that overwrites handle_bbcode_url and checks if the URL is onsite or not.
If it is, preceed normally, if not just return the URL as Text.

Mr Blunt
08-24-2005, 04:24 PM
The main purpose for this hack is so cookies don't get passed arround with clicks.
We ask our members to open a new browser and cut n paste their links to new window.

But naturally there are many things we still DO want to link to such as forum threads, files, images, smilies, etc.... as long as they reside on our site already somewhere.

But once this works .... then I forsee things like making a whitelist of safe sites and ability to override if qualified ... like by giving control back to the checkbox for admins/mods/whoever.

Ultimately I expect this to turn into a product, but I'll have to design it before I'll know where I need hooks.

Andreas
08-24-2005, 04:35 PM
Erm ... Cookies will be send to the destination Server (if the Users Cookie Configuration allows that), no matter if there is a link or the User opens a new Window/Tab?

Mr Blunt
08-24-2005, 05:03 PM
Erm ... Cookies will be send to the destination Server (if the Users Cookie Configuration allows that), no matter if there is a link or the User opens a new Window/Tab?
All cookies on the user's pc get sent to destination??

I thought it was just the cookie from previous site and next site going to after leaving.

In other words I open browser to say msn.com
Now I open my site's bookmark
Now I come here to vb.org
Now I close browser

I thought msn would see my site's cookie (and theirs).
And vb.org would see my site's cookie (and theirs).
And my site would see all 3.

Or would all 3 sites see all 1001 (j/k) cookies that reside on my pc??
:eyepopping:
If it's just the "2 or 3" referencing cookies which get passed, then my method works .... as long as my members abide by the "open new browser and obviously not on our website before pasting the link" clause which my members made for themselves.

If not .... then what the F am I making this for and why in the H was I told differently by my site's members what's the GD point of not posting links when it just don't matter.
:D:banana::D
I said all that with a big smile .... not sour grapes.

Andreas
08-24-2005, 05:19 PM
All cookies on the user's pc get sent to destination??
All Cookies are being sent back to the Sites that set them, if the Users Firewall/Cookie Configuration allows that (and there are no Proxies invloved somewhere in the middle that filter out Cookies).

Cookies are bound to Domains.
There is no way (except buggy Browsers) they can be send to other Domains then those which set them.

Trampy
12-17-2005, 10:46 PM
Anybody get this to work on 3.5.2?

Doesn't work at all on it

Mr Blunt
12-18-2005, 02:56 AM
No, it doesn't work.
This needs a major makeover.
And unfortunately I don't know when I'll have time to do so.
I have a lot of other things going on in my life right now.

I do apologize.
I'll send you a PM when I get to it.

Trampy
12-18-2005, 02:43 PM
Thanks for your response. I have used the mod or a type of it for ages. It is a shame that it can't be shut off in 3.5.2. Your hard work is appreciated. I think at this point I'm going back to 3.0.7.

Thanks.