| 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 [wikipedia] Tag |
|---|
| 7 | * |
|---|
| 8 | * @author Torben Brodt |
|---|
| 9 | * @package com.woltlab.wcf.data.message.bbcode.wikipedia |
|---|
| 10 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-3.0.html> |
|---|
| 11 | */ |
|---|
| 12 | class WikipediaBBCode implements BBCode { |
|---|
| 13 | protected $url = 'http://%s.wikipedia.org/wiki/%s'; |
|---|
| 14 | protected $defaultlang = 'en'; |
|---|
| 15 | |
|---|
| 16 | /** |
|---|
| 17 | * @see BBCode::getParsedTag() |
|---|
| 18 | */ |
|---|
| 19 | public function getParsedTag($openingTag, $content, $closingTag, BBCodeParser $parser) { |
|---|
| 20 | $lang = WCF::getLanguage()->get('wcf.bbcode.wikipedia.prefix'); |
|---|
| 21 | $lang = $lang == 'wcf.bbcode.wikipedia.prefix' ? $this->defaultlang : $lang; |
|---|
| 22 | $lang = isset($openingTag['attributes'][0]) ? $openingTag['attributes'][0] : $lang; |
|---|
| 23 | $url = $content; |
|---|
| 24 | |
|---|
| 25 | // remove base |
|---|
| 26 | if(preg_match('/.+\.wikipedia\.org\/wiki\/(.+)$/', $content, $hits)) { |
|---|
| 27 | $text = $hits[1]; |
|---|
| 28 | $text = urldecode($text); |
|---|
| 29 | } else { |
|---|
| 30 | $text = $url; |
|---|
| 31 | $url = str_replace(' ', '_', $url); |
|---|
| 32 | $url = urlencode($url); |
|---|
| 33 | $url = ucfirst($url); |
|---|
| 34 | $url = sprintf($this->url, $lang, $url); |
|---|
| 35 | } |
|---|
| 36 | $text = str_replace('_', ' ', $text); |
|---|
| 37 | |
|---|
| 38 | if ($parser->getOutputType() == 'text/html') { |
|---|
| 39 | return '<a href="'.$url.'" style="background-image:url(\''.RELATIVE_WCF_DIR.'icon/wysiwyg/wikipediaM.png\');background-repeat:no-repeat;background-position:left;padding-left:25px">'.$text.'</a>'; |
|---|
| 40 | } |
|---|
| 41 | else if ($parser->getOutputType() == 'text/plain') { |
|---|
| 42 | return $url; |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | ?> |
|---|