/usr/share/php/texy/src/Texy/modules/TexyEmoticonModule.php is in php-texy 2.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | <?php
/**
* This file is part of the Texy! (http://texy.info)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/
/**
* Emoticon module.
*
* @author David Grudl
*/
final class TexyEmoticonModule extends TexyModule
{
/** @var array supported emoticons and image files */
public $icons = array(
':-)' => 'smile.gif',
':-(' => 'sad.gif',
';-)' => 'wink.gif',
':-D' => 'biggrin.gif',
'8-O' => 'eek.gif',
'8-)' => 'cool.gif',
':-?' => 'confused.gif',
':-x' => 'mad.gif',
':-P' => 'razz.gif',
':-|' => 'neutral.gif',
);
/** @var string CSS class for emoticons */
public $class;
/** @var string root of relative images (default value is $texy->imageModule->root) */
public $root;
/** @var string physical location of images on server (default value is $texy->imageModule->fileRoot) */
public $fileRoot;
public function __construct($texy)
{
$this->texy = $texy;
$texy->allowed['emoticon'] = FALSE;
$texy->addHandler('emoticon', array($this, 'solve'));
$texy->addHandler('beforeParse', array($this, 'beforeParse'));
}
public function beforeParse()
{
if (empty($this->texy->allowed['emoticon'])) {
return;
}
krsort($this->icons);
$pattern = array();
foreach ($this->icons as $key => $foo) {
$pattern[] = preg_quote($key, '#') . '+'; // last char can be repeated
}
$this->texy->registerLinePattern(
array($this, 'pattern'),
'#(?<=^|[\\x00-\\x20])(' . implode('|', $pattern) . ')#',
'emoticon',
'#' . implode('|', $pattern) . '#'
);
}
/**
* Callback for: :-))).
*
* @param TexyLineParser
* @param array regexp matches
* @param string pattern name
* @return TexyHtml|string|FALSE
*/
public function pattern($parser, $matches)
{
$match = $matches[0];
$tx = $this->texy;
// find the closest match
foreach ($this->icons as $emoticon => $foo) {
if (strncmp($match, $emoticon, strlen($emoticon)) === 0) {
return $tx->invokeAroundHandlers('emoticon', $parser, array($emoticon, $match));
}
}
return FALSE; // tohle se nestane
}
/**
* Finish invocation.
*
* @param TexyHandlerInvocation handler invocation
* @param string
* @param string
* @return TexyHtml|FALSE
*/
public function solve($invocation, $emoticon, $raw)
{
$tx = $this->texy;
$file = $this->icons[$emoticon];
$el = TexyHtml::el('img');
$el->attrs['src'] = Texy::prependRoot($file, $this->root === NULL ? $tx->imageModule->root : $this->root);
$el->attrs['alt'] = $raw;
$el->attrs['class'][] = $this->class;
// file path
$file = rtrim($this->fileRoot === NULL ? $tx->imageModule->fileRoot : $this->fileRoot, '/\\') . '/' . $file;
if (@is_file($file)) { // intentionally @
$size = @getImageSize($file); // intentionally @
if (is_array($size)) {
$el->attrs['width'] = $size[0];
$el->attrs['height'] = $size[1];
}
}
$tx->summary['images'][] = $el->attrs['src'];
return $el;
}
}
|