| Total Complexity | 1 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | */ |
||
| 11 | class Smilies extends Parser implements ParserInterface |
||
| 12 | { |
||
| 13 | private $smilies = [ |
||
| 14 | ':)' => 'smile.gif', |
||
| 15 | ':-)' => 'smile.gif', |
||
| 16 | ';)' => 'wink.gif', |
||
| 17 | ';-)' => 'wink.gif', |
||
| 18 | ':-|' => 'neutral.gif', |
||
| 19 | ':D' => 'laugh.gif', |
||
| 20 | ':-D' => 'laugh.gif', |
||
| 21 | ':(' => 'sad.gif', |
||
| 22 | ':-(' => 'sad.gif', |
||
| 23 | ':P' => 'tongue1.gif', |
||
| 24 | ':p' => 'tongue1.gif', |
||
| 25 | ':-P' => 'tongue1.gif', |
||
| 26 | ':-/' => 'confused.gif', |
||
| 27 | ':/' => 'damn.gif', |
||
| 28 | ':[' => 'mad.gif', |
||
| 29 | ':-[' => 'mad.gif', |
||
| 30 | ':|' => 'zonk.gif', |
||
| 31 | ':]' => 'squared.gif', |
||
| 32 | ':d' => 'teeth.gif' |
||
| 33 | ]; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $text |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | public function parse($text) |
||
| 40 | { |
||
| 41 | $text = $this->hashBlock($text, ['code', 'a']); |
||
| 42 | $text = $this->hashInline($text, 'img'); |
||
| 43 | |||
| 44 | $text = Pattern::template('(?<=^|[\n \>]|\.)(@)') |
||
| 45 | ->alteration(array_keys($this->smilies)) |
||
| 46 | ->build() |
||
| 47 | ->replace($text) |
||
| 48 | ->callback(function (Detail $match) { |
||
| 49 | $smiley = $match->get(1); |
||
| 50 | $link = $this->smilies[$smiley]; |
||
| 51 | return '<img class="img-smile" alt="' . $smiley . '" title="' . $smiley . '" src="/img/smilies/' . $link . '">'; |
||
| 52 | }); |
||
| 53 | |||
| 54 | $text = $this->unhash($text); |
||
| 55 | |||
| 59 |