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
|
<?php
/**
* This class is a helper class for zophCode
*
* This file is part of Zoph.
*
* Zoph is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Zoph is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Zoph; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @author Jeroen Roos
* @package Zoph
*/
namespace zophCode;
use template\block;
use template\template;
/**
* Create smileys
* @author Jeroen Roos
* @package Zoph
*/
class smiley {
/** @var string smiley (e.g. ":-)") */
public $smiley;
/** @var string filename of smiley image */
public $file;
/** @var string short description */
public $description;
/** @var array containing all known smileys */
private static $smileys=array();
/**
* Create a new smiley object
* @param string smiley (e.g. ":-)")
* @param string filename of smiley image
* @param string short description
*/
private function __construct($smiley, $file, $description) {
$this->smiley=$smiley;
$this->file=$file;
$this->description=$description;
}
/**
* Get an array of all smiley objects
*/
public static function getArray() {
if (empty(static::$smileys)) {
static::createArray();
}
return static::$smileys;
}
/**
* Fill the static $smileys.
*/
private static function createArray() {
static::$smileys=array(
new smiley(":D", "icon_biggrin.gif", "Very Happy"),
new smiley(":-D", "icon_biggrin.gif", "Very Happy"),
new smiley(":grin:", "icon_biggrin.gif", "Very Happy"),
new smiley(":)", "icon_smile.gif", "Smile"),
new smiley(":-)", "icon_smile.gif", "Smile"),
new smiley(":smile:", "icon_smile.gif", "Smile"),
new smiley(":(", "icon_sad.gif", "Sad"),
new smiley(":-(", "icon_sad.gif", "Sad"),
new smiley(":sad:", "icon_sad.gif", "Sad"),
new smiley(":o", "icon_surprised.gif", "Surprised"),
new smiley(":-o", "icon_surprised.gif", "Surprised"),
new smiley(":eek:", "icon_surprised.gif", "Surprised"),
new smiley(":shock:", "icon_eek.gif", "Shocked"),
new smiley(":?", "icon_confused.gif", "Confused"),
new smiley(":-?", "icon_confused.gif", "Confused"),
new smiley(":???:", "icon_confused.gif", "Confused"),
new smiley("8)", "icon_cool.gif", "Cool"),
new smiley("8-)", "icon_cool.gif", "Cool"),
new smiley(":cool:", "icon_cool.gif", "Cool"),
new smiley(":lol:", "icon_lol.gif", "Laughing"),
new smiley(":x", "icon_mad.gif", "Mad"),
new smiley(":-x", "icon_mad.gif", "Mad"),
new smiley(":mad:", "icon_mad.gif", "Mad"),
new smiley(":P", "icon_razz.gif", "Razz"),
new smiley(":-P", "icon_razz.gif", "Razz"),
new smiley(":razz:", "icon_razz.gif", "Razz"),
new smiley(":oops:", "icon_redface.gif", "Embarassed"),
new smiley(":cry:", "icon_cry.gif", "Crying or Very sad"),
new smiley(":evil:", "icon_evil.gif", "Evil or Very Mad"),
new smiley(":twisted:", "icon_twisted.gif", "Twisted Evil"),
new smiley(":roll:", "icon_rolleyes.gif", "Rolling Eyes"),
new smiley(":wink:", "icon_wink.gif", "Wink"),
new smiley(";)", "icon_wink.gif", "Wink"),
new smiley(";-)", "icon_wink.gif", "Wink"),
new smiley(":!:", "icon_exclaim.gif", "Exclamation"),
new smiley(":?:", "icon_question.gif", "Question"),
new smiley(":idea:", "icon_idea.gif", "Idea"),
new smiley(":arrow:", "icon_arrow.gif", "Arrow"),
new smiley(":|", "icon_neutral.gif", "Neutral"),
new smiley(":-|", "icon_neutral.gif", "Neutral"),
new smiley(":neutral:", "icon_neutral.gif", "Neutral"),
new smiley(":mrgreen:", "icon_mrgreen.gif", "Mr. Green")
);
}
/**
* Get the smiley
*/
public function __toString() {
return (string) new block("img", array(
"src" => template::getImage("smileys/" . $this->file),
"alt" => $this->description,
"class" => "smiley",
"size" => null
));
}
/**
* Replace smileys in a message with image tags
* @param string Message
* @return string Message with image tags
*/
public static function processMessage($msg) {
$find=array();
$replace=array();
foreach (static::getArray() as $smiley) {
array_push($find, "/" . preg_quote($smiley->smiley) . "/");
array_push($replace, (string) $smiley);
}
return preg_replace($find, $replace, $msg);
}
/**
* Get an overview of all defined smileys
*/
public static function getOverview($title = false) {
return new block("smileys", array(
"title" => $title ? translate("Smileys you can use") : null,
"smileys" => static::getArray()
));
}
}
?>
|