/plugins/Emoticons/plugin.php

https://github.com/bk-amahi/esoTalk · PHP · 127 lines · 107 code · 18 blank · 2 comment · 0 complexity · 1039fb204d4f0517d661daf976984ddf MD5 · raw file

  1. <?php
  2. class Emoticons extends Plugin {
  3. var $id = "Emoticons";
  4. var $name = "Emoticons";
  5. var $version = "1.0.0";
  6. var $description = "Converts emoticon text entities into graphic emoticons";
  7. var $author = "esoTalk team";
  8. var $emoticonDir = "plugins/Emoticons/";
  9. var $emoticons = array();
  10. function init()
  11. {
  12. parent::init();
  13. $this->esoTalk->addToHead("<style type='text/css'>.emoticon {width:16px; height:16px; background:url({$this->emoticonDir}emoticons.png); background-repeat:no-repeat}</style>");
  14. // Add the formatter
  15. $this->esoTalk->formatter->addFormatter("emoticons", "Formatter_Emoticons");
  16. }
  17. }
  18. class Formatter_Emoticons {
  19. var $formatter;
  20. var $emoticons = array();
  21. function Formatter_Emoticons(&$formatter)
  22. {
  23. $this->formatter = &$formatter;
  24. // Define emoticons
  25. $this->emoticons[":)"] = "<img src='js/x.gif' style='background-position:0 0' alt=':)' class='emoticon'/>";
  26. $this->emoticons["=)"] = "<img src='js/x.gif' style='background-position:0 0' alt='=)' class='emoticon'/>";
  27. $this->emoticons[":D"] = "<img src='js/x.gif' style='background-position:0 -20px' alt=':D' class='emoticon'/>";
  28. $this->emoticons["=D"] = "<img src='js/x.gif' style='background-position:0 -20px' alt='=D' class='emoticon'/>";
  29. $this->emoticons["^_^"] = "<img src='js/x.gif' style='background-position:0 -40px' alt='^_^' class='emoticon'/>";
  30. $this->emoticons["^^"] = "<img src='js/x.gif' style='background-position:0 -40px' alt='^^' class='emoticon'/>";
  31. $this->emoticons[":("] = "<img src='js/x.gif' style='background-position:0 -60px' alt=':(' class='emoticon'/>";
  32. $this->emoticons["=("] = "<img src='js/x.gif' style='background-position:0 -60px' alt='=(' class='emoticon'/>";
  33. $this->emoticons["-_-"] = "<img src='js/x.gif' style='background-position:0 -80px' alt='-_-' class='emoticon'/>";
  34. $this->emoticons[";)"] = "<img src='js/x.gif' style='background-position:0 -100px' alt=';)' class='emoticon'/>";
  35. $this->emoticons["^_-"] = "<img src='js/x.gif' style='background-position:0 -100px' alt='^_-' class='emoticon'/>";
  36. $this->emoticons["~_-"] = "<img src='js/x.gif' style='background-position:0 -100px' alt='~_-' class='emoticon'/>";
  37. $this->emoticons["-_^"] = "<img src='js/x.gif' style='background-position:0 -100px' alt='-_^' class='emoticon'/>";
  38. $this->emoticons["-_~"] = "<img src='js/x.gif' style='background-position:0 -100px' alt='-_~' class='emoticon'/>";
  39. $this->emoticons["^_^;"] = "<img src='js/x.gif' style='background-position:0 -120px; width:18px' alt='^_^;' class='emoticon'/>";
  40. $this->emoticons["^^;"] = "<img src='js/x.gif' style='background-position:0 -120px; width:18px' alt='^^;' class='emoticon'/>";
  41. $this->emoticons[">_<"] = "<img src='js/x.gif' style='background-position:0 -140px' alt='&gt;_&lt;' class='emoticon'/>";
  42. $this->emoticons[":/"] = "<img src='js/x.gif' style='background-position:0 -160px' alt=':/' class='emoticon'/>";
  43. $this->emoticons["=/"] = "<img src='js/x.gif' style='background-position:0 -160px' alt='=/' class='emoticon'/>";
  44. $this->emoticons[":\\"] = "<img src='js/x.gif' style='background-position:0 -160px' alt=':&#92;' class='emoticon'/>";
  45. $this->emoticons["=\\"] = "<img src='js/x.gif' style='background-position:0 -160px' alt='=&#92;' class='emoticon'/>";
  46. $this->emoticons[":S"] = "<img src='js/x.gif' style='background-position:0 -160px' alt=':S' class='emoticon'/>";
  47. $this->emoticons["=S"] = "<img src='js/x.gif' style='background-position:0 -160px' alt='=S' class='emoticon'/>";
  48. $this->emoticons[":x"] = "<img src='js/x.gif' style='background-position:0 -180px' alt=':x' class='emoticon'/>";
  49. $this->emoticons["=x"] = "<img src='js/x.gif' style='background-position:0 -180px' alt='=x' class='emoticon'/>";
  50. $this->emoticons[":|"] = "<img src='js/x.gif' style='background-position:0 -180px' alt=':|' class='emoticon'/>";
  51. $this->emoticons["=|"] = "<img src='js/x.gif' style='background-position:0 -180px' alt='=|' class='emoticon'/>";
  52. $this->emoticons["'_'"] = "<img src='js/x.gif' style='background-position:0 -180px' alt='&#39;_&#39;' class='emoticon'/>";
  53. $this->emoticons["<_<"] = "<img src='js/x.gif' style='background-position:0 -200px' alt='&lt;_&lt;' class='emoticon'/>";
  54. $this->emoticons[">_>"] = "<img src='js/x.gif' style='background-position:0 -220px' alt='&gt;_&gt;' class='emoticon'/>";
  55. $this->emoticons["x_x"] = "<img src='js/x.gif' style='background-position:0 -240px' alt='x_x' class='emoticon'/>";
  56. $this->emoticons["o_O"] = "<img src='js/x.gif' style='background-position:0 -260px' alt='o_O' class='emoticon'/>";
  57. $this->emoticons["O_o"] = "<img src='js/x.gif' style='background-position:0 -260px' alt='O_o' class='emoticon'/>";
  58. $this->emoticons["o_0"] = "<img src='js/x.gif' style='background-position:0 -260px' alt='o_0' class='emoticon'/>";
  59. $this->emoticons["0_o"] = "<img src='js/x.gif' style='background-position:0 -260px' alt='0_o' class='emoticon'/>";
  60. $this->emoticons[";_;"] = "<img src='js/x.gif' style='background-position:0 -280px' alt=';_;' class='emoticon'/>";
  61. $this->emoticons[":'("] = "<img src='js/x.gif' style='background-position:0 -280px' alt=':&#39;(' class='emoticon'/>";
  62. $this->emoticons[":O"] = "<img src='js/x.gif' style='background-position:0 -300px' alt=':O' class='emoticon'/>";
  63. $this->emoticons["=O"] = "<img src='js/x.gif' style='background-position:0 -300px' alt='=O' class='emoticon'/>";
  64. $this->emoticons[":o"] = "<img src='js/x.gif' style='background-position:0 -300px' alt=':o' class='emoticon'/>";
  65. $this->emoticons["=o"] = "<img src='js/x.gif' style='background-position:0 -300px' alt='=o' class='emoticon'/>";
  66. $this->emoticons[":P"] = "<img src='js/x.gif' style='background-position:0 -320px' alt=':P' class='emoticon'/>";
  67. $this->emoticons["=P"] = "<img src='js/x.gif' style='background-position:0 -320px' alt='=P' class='emoticon'/>";
  68. $this->emoticons[";P"] = "<img src='js/x.gif' style='background-position:0 -320px' alt=';P' class='emoticon'/>";
  69. $this->emoticons[":["] = "<img src='js/x.gif' style='background-position:0 -340px' alt=':[' class='emoticon'/>";
  70. $this->emoticons["=["] = "<img src='js/x.gif' style='background-position:0 -340px' alt='=[' class='emoticon'/>";
  71. $this->emoticons[":3"] = "<img src='js/x.gif' style='background-position:0 -360px' alt=':3' class='emoticon'/>";
  72. $this->emoticons["=3"] = "<img src='js/x.gif' style='background-position:0 -360px' alt='=3' class='emoticon'/>";
  73. $this->emoticons["._.;"] = "<img src='js/x.gif' style='background-position:0 -380px; width:18px' alt='._.;' class='emoticon'/>";
  74. $this->emoticons["<(^.^)>"] = "<img src='js/x.gif' style='background-position:0 -400px; width:19px' alt='&lt;(^.^)&gt;' class='emoticon'/>";
  75. $this->emoticons["(>'.')>"] = "<img src='js/x.gif' style='background-position:0 -400px; width:19px' alt='(&gt;&#39;.&#39;)&gt;' class='emoticon'/>";
  76. $this->emoticons["(>^.^)>"] = "<img src='js/x.gif' style='background-position:0 -400px; width:19px' alt='(&gt;^.^)&gt;' class='emoticon'/>";
  77. $this->emoticons["-_-;"] = "<img src='js/x.gif' style='background-position:0 -420px; width:18px' alt='-_-;' class='emoticon'/>";
  78. $this->emoticons["(o^_^o)"] = "<img src='js/x.gif' style='background-position:0 -440px' alt='(o^_^o)' class='emoticon'/>";
  79. $this->emoticons["(^_^)/"] = "<img src='js/x.gif' style='background-position:0 -460px; width:19px' alt='(^_^)/' class='emoticon'/>";
  80. $this->emoticons[">:("] = "<img src='js/x.gif' style='background-position:0 -480px' alt='>:(' class='emoticon'/>";
  81. $this->emoticons[">:["] = "<img src='js/x.gif' style='background-position:0 -480px' alt='>:[' class='emoticon'/>";
  82. $this->emoticons["._."] = "<img src='js/x.gif' style='background-position:0 -500px' alt='._.' class='emoticon'/>";
  83. $this->emoticons["T_T"] = "<img src='js/x.gif' style='background-position:0 -520px' alt='T_T' class='emoticon'/>";
  84. $this->emoticons["XD"] = "<img src='js/x.gif' style='background-position:0 -540px' alt='XD' class='emoticon'/>";
  85. $this->emoticons["('<"] = "<img src='js/x.gif' style='background-position:0 -560px' alt='(&#39;&lt;' class='emoticon'/>";
  86. $this->emoticons["B)"] = "<img src='js/x.gif' style='background-position:0 -580px' alt='B)' class='emoticon'/>";
  87. $this->emoticons["XP"] = "<img src='js/x.gif' style='background-position:0 -600px' alt='XP' class='emoticon'/>";
  88. }
  89. function emoticon($match, $state)
  90. {
  91. $this->formatter->output .= $this->emoticons[desanitize($match)];
  92. return true;
  93. }
  94. function format()
  95. {
  96. $patterns = array();
  97. foreach ($this->emoticons as $k => $v) $patterns[] = preg_quote(sanitize($k), "/");
  98. $this->formatter->lexer->mapFunction("emoticon", array($this, "emoticon"));
  99. $allowedModes = $this->formatter->getModes($this->formatter->allowedModes["inline"]);
  100. foreach ($allowedModes as $mode) {
  101. $this->formatter->lexer->addSpecialPattern('(?<=^|[\s.,!<>])(?:' . implode("|", $patterns) . ')(?=[\s.,!<>)]|$)', $mode, "emoticon");
  102. }
  103. }
  104. function revert($string)
  105. {
  106. return strtr($string, array_flip($this->emoticons));
  107. }
  108. }
  109. ?>