Hi,
habe gerade einen Codeschnipsel aus dem 2.2 phpbb gefunden:
Code: Alles auswählen
// Replace magic urls of form http://xxx.xxx., www.xxx. and xxx@xxx.xxx.
// Cuts down displayed size of link if over 50 chars, turns absolute links
// into relative versions when the server/script path matches the link
function magic_url($server_protocol, $server_name, $server_port, $script_path)
{
static $match;
static $replace;
$server_port = ($server_port <> 80 ) ? ':' . trim($server_port) . '/' : '/';
if (!is_array($match))
{
$match = $replace = array();
// Be sure to not let the matches cross over. ;)
// relative urls for this board
$match[] = '#(^|[\n ]|\()(' . preg_quote($server_protocol . trim($server_name) . $server_port . preg_replace('/^\/?(.*?)(\/)?$/', '$1', trim($script_path)), '#') . ')/(.*?([^ \t\n\r<"\'\)]*)?)#i';
$replace[] = '$1<!-- l --><a href="$2/$3" target="_blank">$3</a><!-- l -->';
// matches a xxxx://aaaaa.bbb.cccc. ...
$match[] = '#(^|[\n ]|\()([\w]+?://.*?([^ \t\n\r<"\'\)]*)?)#ie';
$replace[] = "'\$1<!-- m --><a href=\"\$2\" target=\"_blank\">' . ((strlen('\$2') > 55) ? substr('\$2', 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- m -->'";
// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
$match[] = '#(^|[\n ]|\()(www\.[\w\-]+\.[\w\-.\~]+(?:/[^ \t\n\r<"\'\)]*)?)#ie';
$replace[] = "'\$1<!-- w --><a href=\"http://\$2\" target=\"_blank\">' . ((strlen('\$2') > 55) ? substr(str_replace(' ', '%20', '\$2'), 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- w -->'";
// matches an email@domain type address at the start of a line, or after a space.
$match[] = '#(^|[\n ]|\()([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)#ie';
$replace[] = "'\$1<!-- e --><a href=\"mailto:\$2\">' . ((strlen('\$2') > 55) ? substr('\$2', 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- e -->'";
}
/* IMPORTANT NOTE (Developer inability to do advanced regular expressions) - Acyd Burn:
Transforming < (<) to << in order to bypass the inability of preg_replace
supporting multi-character sequences (POSIX - [..]). Since all message text is specialchared by
default a match against < will always fail, since it is a < sequence within the text.
Replacing with << and switching back thereafter produces no problems, because < will never show up with < in
the same text (due to this specialcharing). The < is put in front of < to let the url break gracefully.
I hope someone can lend me a hand here, telling me how to achive the wanted result without switching to ereg_replace.
*/
$this->message = preg_replace($match, $replace, str_replace('<', '<<', $this->message));
$this->message = str_replace('<<', '<', $this->message);
}
kann man diesen evtl. irgendwie in die bbcode.php einbauen? der Force Word Wrap MOD wird ja von viewtopic.php mit word_wrap_pass($message) aufgerufen und dann könnte man doch bestimmt den anderen code auch von da aus aufrufen und seine arbeit verrichten lassen?
Wenn das gehen würde wären die Probleme die so oft hier auftauchen von wegen Tabellenbreite etc. bei langen Links und Wörtern endgültig mit diesen beiden MOD's kombiniert Geschichte...