The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. November 21, 2008, 12:43:37 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Redirect all off site urls  (Read 1054 times)
SEOidiot
Journeyman
***
Offline Offline

Posts: 71


^ Hes a pint sized Ned Flanders


View Profile
« on: July 26, 2008, 03:45:03 PM »

Hey everyone, been a while  Wink

Im looking for a way to redirect every off site link from a site to a redirection page for checking first...

Eg
Some twat posts a link in his comment / post that goes to some site we dont like, instead of going straight there its intercepted and then redirects to a php page for checking against the list of approved links....

Friend suggested the method would be better than my current fuck it 404 approach but im struggling with either the regex or the best way to approach and i dont wanna spoil his holiday any more Wink

Logged

<mango>Yummmmmmmmmmmmm</mango>
<pie>ewwwwwwwwwww</pie>
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Online Online

Posts: 595



View Profile
« Reply #1 on: July 26, 2008, 07:19:57 PM »

Can you show me what a link looks like on your page? Is this a forum or something like that, or can we expect just regular HTML with <a tags?

I can write the regex for you.
Logged

SEOidiot
Journeyman
***
Offline Offline

Posts: 71


^ Hes a pint sized Ned Flanders


View Profile
« Reply #2 on: July 27, 2008, 01:28:36 AM »

If you dont mind give me a ping on IM and we can look through them

Thanks matey

BTW i will post the solution here for all to abuse use
Logged

<mango>Yummmmmmmmmmmmm</mango>
<pie>ewwwwwwwwwww</pie>
SEOidiot
Journeyman
***
Offline Offline

Posts: 71


^ Hes a pint sized Ned Flanders


View Profile
« Reply #3 on: July 27, 2008, 03:54:13 PM »

OK so maybe this may be of use to others but... what i want to do is intercept all outbound links in a forum (SMF) and change the links to go through a jump page first: -

SMF handles the censored word filter as follows (Seems as good a place as any, unless we dive in to display.php instead??)

In load.php:  -

Code:
// Replace all vulgar words with respective proper words. (substring or whole words..)
function &censorText(&$text)
{
global $modSettings, $options, $settings, $txt;
static $censor_vulgar = null, $censor_proper;

if ((!empty($options['show_no_censored']) && $settings['allow_no_censored']) || empty($modSettings['censor_vulgar']))
return $text;

// If they haven't yet been loaded, load them.
if ($censor_vulgar == null)
{
$censor_vulgar = explode("\n", $modSettings['censor_vulgar']);
$censor_proper = explode("\n", $modSettings['censor_proper']);

// Quote them for use in regular expressions.
for ($i = 0, $n = count($censor_vulgar); $i < $n; $i++)
{
$censor_vulgar[$i] = strtr(preg_quote($censor_vulgar[$i], '/'), array('\\\\\\*' => '[*]', '\\*' => '[^\s]*?', '&' => '&amp;'));
$censor_vulgar[$i] = (empty($modSettings['censorWholeWord']) ? '/' . $censor_vulgar[$i] . '/' : '/(?<=^|\W)' . $censor_vulgar[$i] . '(?=$|\W)/') . (empty($modSettings['censorIgnoreCase']) ? '' : 'i') . ((empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8' ? 'u' : '');

if (strpos($censor_vulgar[$i], '\'') !== false)
{
$censor_proper[count($censor_vulgar)] = $censor_proper[$i];
$censor_vulgar[count($censor_vulgar)] = strtr($censor_vulgar[$i], array('\'' => '&#039;'));
}
}
}

// Censoring isn't so very complicated :P.
$text = preg_replace($censor_vulgar, $censor_proper, $text);
return $text;
}

So what i want to do is also change all outbounds to www.forum.com/outbound?link=originalURL

Censored words filter as it stands cant do this so we have to step in and add some code to match urls then swap out

Perhaps along the lines of: -

(Excuse the following bollocks)

preg_match_all('/<a href="(.+?)" title=\"(.+?)" target=\"_blank\">/', $text, $fixedtext);
then add the forum.com/outbound?link= to the front and return $text

?? or am i making no sense?

Logged

<mango>Yummmmmmmmmmmmm</mango>
<pie>ewwwwwwwwwww</pie>
Bompa
Administrator
Expert
*****
Offline Offline

Posts: 208


View Profile WWW
« Reply #4 on: July 27, 2008, 06:38:05 PM »

The censored words filter seems like a logical place to start, however, I don't have a
copy of smf here, but is there a BBcode parser?

Maybe that would not be broad enough tho.

Also, if I type variations like this?

http://google.com
www.google.com
google.com

The first two become clickable, what code does that?

just a thought.

Bomps
« Last Edit: July 27, 2008, 06:42:39 PM by Bompa » Logged

SEOidiot
Journeyman
***
Offline Offline

Posts: 71


^ Hes a pint sized Ned Flanders


View Profile
« Reply #5 on: July 28, 2008, 11:37:56 AM »

I did mess with the auto url code and now all (well most) outgoing links go through a jump page and only approved ones jump out again....

Logged

<mango>Yummmmmmmmmmmmm</mango>
<pie>ewwwwwwwwwww</pie>
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5141


:sniffle: Humor was so much easier before.


View Profile
« Reply #6 on: July 28, 2008, 01:19:43 PM »

SEOI I am out of the country but will take a look at this either tonight or tomorrow, sorry for the delay matey.

Best,
/p
Logged

If I can't be Mr. Root then I don't want to play.
SEOidiot
Journeyman
***
Offline Offline

Posts: 71


^ Hes a pint sized Ned Flanders


View Profile
« Reply #7 on: July 28, 2008, 02:05:37 PM »

Thanks, its sorted now, not ellegant but working Smiley
Logged

<mango>Yummmmmmmmmmmmm</mango>
<pie>ewwwwwwwwwww</pie>
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!