| 1 | <?php |
|---|
| 2 | require_once(WCF_DIR.'lib/data/message/bbcode/BBCodeParser.class.php'); |
|---|
| 3 | require_once(WCF_DIR.'lib/data/message/bbcode/BBCode.class.php'); |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * BBCode for [google] Tag |
|---|
| 7 | * |
|---|
| 8 | * @author Torben Brodt |
|---|
| 9 | * @package com.woltlab.wcf.data.message.bbcode.google |
|---|
| 10 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-3.0.html> |
|---|
| 11 | */ |
|---|
| 12 | class GoogleBBCode implements BBCode { |
|---|
| 13 | protected $url = 'http://www.google.%s/search?q=%s'; |
|---|
| 14 | protected $defaultlang = 'com'; |
|---|
| 15 | |
|---|
| 16 | /** |
|---|
| 17 | * @see BBCode::getParsedTag() |
|---|
| 18 | */ |
|---|
| 19 | public function getParsedTag($openingTag, $content, $closingTag, BBCodeParser $parser) { |
|---|
| 20 | $lang = WCF::getLanguage()->get('wcf.bbcode.google.suffix'); |
|---|
| 21 | $lang = $lang == 'wcf.bbcode.google.suffix' ? $this->defaultlang : $lang; |
|---|
| 22 | $lang = isset($openingTag['attributes'][0]) ? $openingTag['attributes'][0] : $lang; |
|---|
| 23 | if(strpos($lang, 'http://') === false) { |
|---|
| 24 | $url = $content; |
|---|
| 25 | |
|---|
| 26 | // remove base |
|---|
| 27 | if(strpos($content, '.google.')) { |
|---|
| 28 | $var = parse_url($url); |
|---|
| 29 | parse_str($var['query'], $output); |
|---|
| 30 | $text = $output['q']; |
|---|
| 31 | } else { |
|---|
| 32 | $text = $url; |
|---|
| 33 | $url = urlencode($url); |
|---|
| 34 | $url = sprintf($this->url, $lang, $url); |
|---|
| 35 | } |
|---|
| 36 | } else { // url format |
|---|
| 37 | $url = $lang; |
|---|
| 38 | $text = $content; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | if ($parser->getOutputType() == 'text/html') { |
|---|
| 42 | return '<a href="'.$url.'" class="google" style="background-image:url(\''.RELATIVE_WCF_DIR.'icon/wysiwyg/googleS.png\');background-repeat:no-repeat;background-position:left;padding-left:25px">'.$text.'</a>'; |
|---|
| 43 | } |
|---|
| 44 | else if ($parser->getOutputType() == 'text/plain') { |
|---|
| 45 | return $url; |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | ?> |
|---|