Seite 1 von 1

Force Word Wrapping

Verfasst: 17.11.2004 12:10
von kokett
Hallo,

ich habe gerade diesen MOD installiert und er funktioniert auch wie gewünscht. Extrem lange Wörter werden getrennt und das Board wird nicht verunstaltet. Nun ändern dieser MOD leider nur Wörter und lässt lange Links unberührt. Ich habe in einem vBulletin Board gesehn das dort bei langen Links einfach http://www.irgendeinese.de/has... gemacht wird. Das sollte doch auch mit bbcode gehen, wenn man bei der Eingabe einen Link erkennt und ihn einfach in

Code: Alles auswählen

[url=derextremvielzulangelink]derverkürztelink...[/url]
setzt. Hat jemand schonmal sowas programmiert? Kennt jeman einen anderen MOD evtl. der sowas kann?

Verfasst: 17.11.2004 13:46
von kokett
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 <&lt; 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 <&lt; and switching back thereafter produces no problems, because < will never show up with &lt; in
			the same text (due to this specialcharing). The < is put in front of &lt; 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('<', '<&lt;', $this->message));
		$this->message = str_replace('<&lt;', '<', $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...