ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilChatroomSmilies.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
15 private static function _insertDefaultValues()
16 {
20 global $ilDB;
21
22 $values = array(
23 array("icon_smile.gif", ":)\n:-)\n:smile:"),
24 array("icon_wink.gif", ";)\n;-)\n:wink:"),
25 array("icon_laugh.gif", ":D\n:-D\n:laugh:\n:grin:\n:biggrin:"),
26 array("icon_sad.gif", ":(\n:-(\n:sad:"),
27 array("icon_shocked.gif", ":o\n:-o\n:shocked:"),
28 array("icon_tongue.gif", ":p\n:-p\n:tongue:"),
29 array("icon_cool.gif", ":cool:"),
30 array("icon_eek.gif", ":eek:"),
31 array("icon_angry.gif", ":||\n:-||\n:angry:"),
32 array("icon_flush.gif", ":flush:"),
33 array("icon_idea.gif", ":idea:"),
34 array("icon_thumbup.gif", ":thumbup:"),
35 array("icon_thumbdown.gif", ":thumbdown:"),
36 );
37
38 $stmt = $ilDB->prepareManip(
39 "
40 INSERT INTO chatroom_smilies (smiley_id, smiley_keywords, smiley_path)
41 VALUES (?, ?, ?)",
42 array("integer", "text", "text")
43 );
44
45 foreach ($values as $val) {
46 $row = array(
47 $ilDB->nextId("chatroom_smilies"),
48 $val[1],
49 $val[0]
50 );
51 $stmt->execute($row);
52 }
53 }
54
61 public static function _checkSetup()
62 {
63 global $lng;
64
66
67 if (!is_dir($path)) {
68 ilUtil::sendInfo($lng->txt('chatroom_smilies_dir_not_exists'));
70
71 if (!is_dir($path)) {
72 ilUtil::sendFailure($lng->txt('chatroom_smilies_dir_not_available'));
73 return false;
74 } else {
75 $smilies = array(
76 "icon_smile.gif",
77 "icon_wink.gif",
78 "icon_laugh.gif",
79 "icon_sad.gif",
80 "icon_shocked.gif",
81 "icon_tongue.gif",
82 "icon_cool.gif",
83 "icon_eek.gif",
84 "icon_angry.gif",
85 "icon_flush.gif",
86 "icon_idea.gif",
87 "icon_thumbup.gif",
88 "icon_thumbdown.gif",
89 );
90
91 foreach ($smilies as $smiley) {
92 copy("templates/default/images/emoticons/$smiley", $path . "/$smiley");
93 }
94
95 self::_insertDefaultValues();
96 ilUtil::sendSuccess($lng->txt('chatroom_smilies_initialized'));
97 }
98 }
99
100 if (!is_writable($path)) {
101 ilUtil::sendInfo($lng->txt('chatroom_smilies_dir_not_writable'));
102 }
103
104 return true;
105 }
106
111 public static function _getSmileyDir()
112 {
113 return ilUtil::getWebspaceDir() . '/chatroom/smilies';
114 }
115
120 public static function _getSmilies()
121 {
125 global $ilDB;
126
127 $res = $ilDB->query("SELECT smiley_id, smiley_keywords, smiley_path FROM chatroom_smilies");
128 $result = array();
129
130 while ($row = $ilDB->fetchAssoc($res)) {
131 $result[] = array(
132 "smiley_id" => $row['smiley_id'],
133 "smiley_keywords" => $row['smiley_keywords'],
134 "smiley_path" => $row['smiley_path'],
135 "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $row['smiley_path']
136 );
137 }
138
139 return $result;
140 }
141
147 public static function _deleteMultipleSmilies($ids = array())
148 {
149 global $ilDB;
150
151 $smilies = self::_getSmiliesById($ids);
152
153 if (count($smilies) <= 0) {
154 return;
155 }
156
157 $sql_parts = array();
158
159 foreach ($smilies as $s) {
160 unlink($s["smiley_fullpath"]);
161 $sql_parts[] = "smiley_id = " . $ilDB->quote($s["smiley_id"], 'integer');
162 }
163
164 $ilDB->manipulate("DELETE FROM chatroom_smilies WHERE " . implode(" OR ", $sql_parts));
165 }
166
172 public static function _getSmiliesById($ids = array())
173 {
177 global $ilDB;
178
179 if (!count($ids)) {
180 return;
181 }
182
183 $sql = "SELECT smiley_id, smiley_keywords, smiley_path FROM chatroom_smilies WHERE ";
184
185 $sql_parts = array();
186
187 foreach ($ids as $id) {
188 $sql_parts[] .= "smiley_id = " . $ilDB->quote($id, "integer");
189 }
190
191 $sql .= join(" OR ", $sql_parts);
192 $res = $ilDB->query($sql);
193 $result = array();
194
195 while ($row = $ilDB->fetchAssoc($res)) {
196 $result[] = array(
197 "smiley_id" => $row['smiley_id'],
198 "smiley_keywords" => $row['smiley_keywords'],
199 "smiley_path" => $row['smiley_path'],
200 "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $row['smiley_path']
201 );
202 }
203
204 return $result;
205 }
206
212 public static function _updateSmiley($data)
213 {
217 global $ilDB;
218
219 $ilDB->manipulateF(
220 "UPDATE chatroom_smilies
221 SET smiley_keywords = %s
222 WHERE
223 smiley_id = %s",
224 array('text', 'integer'),
225 array($data["smiley_keywords"], $data["smiley_id"])
226 );
227
228 if ($data["smiley_path"]) {
229 $sm = self::_getSmiley($data["smiley_id"]);
230 unlink($sm["smiley_fullpath"]);
231 $ilDB->manipulateF(
232 "UPDATE chatroom_smilies
233 SET smiley_path = %s
234 WHERE
235 smiley_id = %s",
236 array('text', 'integer'),
237 array($data["smiley_path"], $data["smiley_id"])
238 );
239 }
240 }
241
249 public static function _getSmiley($a_id)
250 {
254 global $ilDB;
255
256 $res = $ilDB->queryF(
257 "
258 SELECT smiley_id, smiley_keywords, smiley_path
259 FROM chatroom_smilies
260 WHERE smiley_id = %s ",
261 array('integer'),
262 array($a_id)
263 );
264
265 if ($ilDB->numRows($res)) {
266 while ($row = $ilDB->fetchAssoc($res)) {
267 return array(
268 "smiley_id" => $row['smiley_id'],
269 "smiley_keywords" => $row['smiley_keywords'],
270 "smiley_path" => $row['smiley_path'],
271 "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $row['smiley_path']
272 );
273 }
274 }
275
276 throw new Exception('smiley with id $a_id not found');
277 }
278
283 public static function getSmiliesBasePath()
284 {
285 return 'chatroom/smilies';
286 }
287
292 public static function _deleteSmiley($a_id)
293 {
297 global $ilDB;
298
299 try {
300 $smiley = self::_getSmiley($a_id);
301 $path = ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $smiley["smiley_path"];
302
303 if (is_file($path)) {
304 unlink($path);
305 }
306
307 $ilDB->manipulateF(
308 "DELETE FROM chatroom_smilies
309 WHERE
310 smiley_id = %s",
311 array('integer'),
312 array($a_id)
313 );
314 } catch (Exception $e) {
315 }
316 }
317
323 public static function _storeSmiley($keywords, $path)
324 {
328 global $ilDB;
329
330 $stmt = $ilDB->prepareManip(
331 "
332 INSERT INTO chatroom_smilies (smiley_id, smiley_keywords, smiley_path)
333 VALUES (?, ?, ?)",
334 array(
335 "integer", "text", "text"
336 )
337 );
338 $row = array(
339 $ilDB->nextId("chatroom_smilies"),
340 $keywords,
341 $path
342 );
343 $stmt->execute($row);
344 }
345
351 public static function _prepareKeywords($words)
352 {
353 $keywordscheck = true;
354
355 // check keywords
356 $keywords_unchecked = explode("\n", $words);
357 if (count($keywords_unchecked) <= 0) {
358 $keywordscheck = false;
359 }
360
361 if ($keywordscheck) {
362 $keywords = array();
363
364 foreach ($keywords_unchecked as $word) {
365 if (trim($word)) {
366 $keywords[] = trim($word);
367 }
368 }
369 }
370
371 if ($keywordscheck && count($keywords) <= 0) {
372 $keywordscheck = false;
373 }
374
375 if ($keywordscheck) {
376 return $keywords;
377 } else {
378 return array();
379 }
380 }
381}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomSmilies.
static _getSmileyDir()
Path to smilies.
static _checkSetup()
Checks if smiley folder is available; if not it will try to create folder and performs actions for an...
static _deleteMultipleSmilies($ids=array())
Deletes multiple smilies by given id array.
static getSmiliesBasePath()
Returns smilies basepath.
static _prepareKeywords($words)
Trims given keywords and returns them in one array.
static getWebspaceDir($mode="filesystem")
get webspace directory
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(!array_key_exists('StateId', $_REQUEST)) $id
global $lng
Definition: privfeed.php:17
$s
Definition: pwgen.php:45
foreach($_POST as $key=> $value) $res
global $ilDB