Sollte so rein theoretisch Funktionieren
PHP: URLBBCode.class.php
<?php
namespace wcf\system\bbcode;
use wcf\system\application\ApplicationHandler;
use wcf\system\request\RouteHandler;
use wcf\util\StringUtil;
/**
* Parses the [url] bbcode tag.
*
* @author Marcel Werk
* @copyright 2001-2015 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.bbcode
* @category Community Framework
*/
class URLBBCode extends AbstractBBCode {
/**
* @see \wcf\system\bbcode\IBBCode::getParsedTag()
*/
public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) {
$url = '';
if (isset($openingTag['attributes'][0])) {
$url = $openingTag['attributes'][0];
}
$noTitle = ($content == $url);
$url = StringUtil::decodeHTML($url);
// add protocol if necessary
if (!preg_match("/[a-z]:\/\//si", $url)) $url = 'http://'.$url;
return $this->getAnchorTag($url, (!$noTitle ? $content : ''), false);
}
/**
* Generates an anchor tag from given URL.
*
* @param string $url
* @param string $title
* @param boolean $encodeTitle
* @return string anchor tag
*/
private function getAnchorTag($url, $title = '', $encodeTitle = true) {
$url = StringUtil::trim($url);
$external = true;
if (ApplicationHandler::getInstance()->isInternalURL($url)) {
$external = false;
$url = preg_replace('~^https?://~', RouteHandler::getProtocol(), $url);
}
// cut visible url
if (empty($title)) {
// use URL and remove protocol and www subdomain
$title = preg_replace('~^(?:https?|ftps?)://(?:www\.)?~i', '', $url);
if (mb_strlen($title) > 60) {
$title = mb_substr($title, 0, 30) . StringUtil::HELLIP . mb_substr($title, -25);
}
if (!$encodeTitle) $title = StringUtil::encodeHTML($title);
}
return '<a href="'.StringUtil::encodeHTML($url).'"'.($external ? (' class="thumber externalURL"'.(EXTERNAL_LINK_REL_NOFOLLOW ? ' rel="nofollow"' : '').(EXTERNAL_LINK_TARGET_BLANK ? ' target="_blank"' : '')) : ' class="thumber"').'><img src="https://thumber.de/image/?size=SXXXL3DL&bg=transparent&url='.StringUtil::encodeHTML($url).'" /></a>';
}
}
Alles anzeigen