C:\xampp\php\pear\Text\Wiki\Parse\Default\Smiley.php


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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
/**
 * Default: Parses for smileys / emoticons tags
 *
 * This class implements a Text_Wiki_Rule to find source text marked as
 * smileys defined by symbols as ':)' , ':-)' or ':smile:'
 * The symbol is replaced with a token.
 *
 * PHP versions 4 and 5
 *
 * @category   Text
 * @package    Text_Wiki
 * @author     Bertrand Gugger <bertrand@toggg.com>
 * @copyright  2005 bertrand Gugger
 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
 * @version    CVS: $Id: Smiley.php 197527 2005-10-04 08:17:51Z toggg $
 * @link       http://pear.php.net/package/Text_Wiki
 */

/**
 * Smiley rule parser class for Default.
 *
 * @category   Text
 * @package    Text_Wiki
 * @author     Bertrand Gugger <bertrand@toggg.com>
 * @copyright  2005 bertrand Gugger
 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
 * @version    Release: @package_version@
 * @link       http://pear.php.net/package/Text_Wiki
 * @see        Text_Wiki_Parse::Text_Wiki_Parse()
 */
class Text_Wiki_Parse_Smiley extends Text_Wiki_Parse {

    
/**
     * Configuration keys for this rule
     * 'smileys' => array Smileys recognized by this rule, symbols key definitions:
     *              'symbol' => array ( 'name', 'description' [, 'variante', ...] ) as
     *                  ':)'  => array('smile', 'Smile'),
     *                  ':D'  => array('biggrin', 'Very Happy',':grin:'),
     *              the eventual elements after symbol and description are variantes
     *
     * 'auto_nose' => boolean enabling the auto nose feature:
     *                auto build a variante for 2 chars symbols by inserting a '-' as ':)' <=> ':-)'
     *
     * @access public
     * @var array 'config-key' => mixed config-value
     */
    
var $conf = array(
        
'smileys' => array(
            
':D'        => array('biggrin''Very Happy'':grin:'),
            
':)'        => array('smile''Smile''(:'),
            
':('        => array('sad''Sad''):'),
            
':o'        => array('surprised''Surprised'':eek:''o:'),
            
':shock:'   => array('eek''Shocked'),
            
':?'        => array('confused''Confused'':???:'),
            
'8)'        => array('cool''Cool''(8'),
            
':lol:'     => array('lol''Laughing'),
            
':x'        => array('mad''Mad'),
            
':P'        => array('razz''Razz'),
            
':oops:'    => array('redface''Embarassed'),
            
':cry:'     => array('cry''Crying or Very sad'),
            
':evil:'    => array('evil''Evil or Very Mad'),
            
':twisted:' => array('twisted''Twisted Evil'),
            
':roll:'    => array('rolleyes''Rolling Eyes'),
            
';)'        => array('wink''Wink''(;'),
            
':!:'       => array('exclaim''Exclamation'),
            
':?:'       => array('question''Question'),
            
':idea:'    => array('idea''Idea'),
            
':arrow:'   => array('arrow''Arrow'),
            
':|'        => array('neutral''Neutral''|:'),
            
':mrgreen:' => array('mrgreen''Mr. Green'),
        ),
        
'auto_nose' => true
    
);

    
/**
     * Definition array of smileys, variantes references their model
     * 'symbol' => array ( 'name', 'description')
     *
     * @access private
     * @var array 'config-key' => mixed config-value
     */
    
var $_smileys = array();

     
/**
     * Constructor.
     * We override the constructor to build up the regex from config
     *
     * @param object &$obj the base conversion handler
     * @return The parser object
     * @access public
     */
    
function Text_Wiki_Parse_Smiley(&$obj)
    {
        
$default $this->conf;
        
parent::Text_Wiki_Parse($obj);

        
// read the list of smileys to sort out variantes and :xxx: while building the regexp
        
$this->_smileys $this->getConf('smileys'$default['smileys']);
        
$autoNose $this->getConf('auto_nose'$default['auto_nose']);
        
$reg1 $reg2 '';
        
$sep1 ':(?:';
        
$sep2 '';
        foreach (
$this->_smileys as $smiley => $def) {
            for (
$i 1$i count($def); $i++) {
                if (
$i 1) {
                    
$cur $def[$i];
                    
$this->_smileys[$cur] = &$this->_smileys[$smiley];
                } else {
                    
$cur $smiley;
                }
                
$len strlen($cur);
                if ((
$cur{0} == ':') && ($len 2) && ($cur{$len 1} == ':')) {
                    
$reg1 .= $sep1 preg_quote(substr($cur1, -1), '#');
                    
$sep1 '|';
                    continue;
                }
                if (
$autoNose && ($len === 2)) {
                    
$variante $cur{0} . '-' $cur{1};
                    
$this->_smileys[$variante] = &$this->_smileys[$smiley];
                    
$cur preg_quote($cur{0}, '#') . '-?' preg_quote($cur{1}, '#');
                } else {
                    
$cur preg_quote($cur'#');
                }
                
$reg2 .= $sep2 $cur;
                
$sep2 '|';
            }
        }
        
$delim '[\n\r\s' $this->wiki->delim '$^]';
        
$this->regex '#(?<=' $delim .
             
')(' . ($reg1 $reg1 '):' . ($reg2 '|' '') : '') . $reg2 .
             
')(?=' $delim ')#i';
    }

    
/**
     * Generates a replacement token for the matched text.  Token options are:
     *     'symbol' => the original marker
     *     'name' => the name of the smiley
     *     'desc' => the description of the smiley
     *
     * @param array &$matches The array of matches from parse().
     * @return string Delimited token representing the smiley
     * @access public
     */
    
function process(&$matches)
    {
        
// tokenize
        
return $this->wiki->addToken($this->rule,
            array(
                
'symbol' => $matches[1],
                
'name'   => $this->_smileys[$matches[1]][0],
                
'desc'   => $this->_smileys[$matches[1]][1]
            ));
    }
}
?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586