Created
April 26, 2016 14:21
-
-
Save alrnz/948ef7d06f07a8ea455168b2667032e1 to your computer and use it in GitHub Desktop.
TwitterTextViewHelper
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; | |
/** | |
* Formats the tweet with links etc. | |
* | |
* Example: | |
* {namespace newsrooom=Sunzinet\SzNewsroom\ViewHelpers} | |
* <newsrooom:twitterText>Text comes here</newsrooom:twitterText> | |
* | |
* @author Arne Lorenz <al@sunzinet.com> | |
*/ | |
class TwitterTextViewHelper 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 | |
); | |
$formatted_text = preg_replace( | |
'/\#(\w+)/', | |
"<a target='_blank' href='https://twitter.com/hashtag/opitzinside?q=$1'>#$1</a>", | |
$formatted_text | |
); | |
$formatted_text = preg_replace( | |
'/\@(\w+)/', | |
"<a target='_blank' href='https://twitter.com/$1'>@$1</a>", | |
$formatted_text | |
); | |
return $formatted_text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment