Created
April 26, 2016 14:21
-
-
Save alrnz/36cccd1ceea414215f9a85699f1e4b9b to your computer and use it in GitHub Desktop.
TextlinkViewHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Sunzinet\SzNewsroom\ViewHelpers; | |
/** | |
* This file is part of the TYPO3 CMS project. | |
* It is free software; you can redistribute it and/or modify it under | |
* the terms of the GNU General Public License, either version 2 | |
* of the License, or any later version. | |
* For the full copyright and license information, please read the | |
* LICENSE.txt file that was distributed with this source code. | |
* The TYPO3 project - inspiring people to share! | |
* (c) 2016 Arne Lorenz (al@sunzinet.com) | |
*/ | |
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; | |
/** | |
* Replaces URLs in a Text with Links | |
* Example: | |
* {namespace newsrooom=Sunzinet\SzNewsroom\ViewHelpers} | |
* <newsrooom:textlink>Text comes here</newsrooom:textlink> | |
* | |
* @author Arne Lorenz <al@sunzinet.com> | |
*/ | |
class TextlinkViewHelper extends AbstractViewHelper | |
{ | |
/** | |
* @return string | |
*/ | |
public function render() | |
{ | |
$content = $this->renderChildren(); | |
$formatted_text = preg_replace( | |
'/(\b(www\.|http\:\/\/|https\:\/\/)\S+\b)/', | |
"<a target='_blank' href='$1'>$1</a>", | |
$content | |
); | |
return $formatted_text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment