ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 public static function _initial()
16 {
17 self::_setupDatabase();
18 self::_insertDefaultValues();
20 }
21
25 private static function _setupDatabase()
26 {
30 global $ilDB;
31
32 $fields = array(
33 'smiley_id' => array(
34 'type' => 'integer',
35 'length' => 4,
36 ),
37 'smiley_keywords' => array(
38 'type' => 'text',
39 'length' => 100,
40 ),
41 'smiley_path' => array(
42 'type' => 'text',
43 'length' => 200,
44 )
45 );
46
47 //$ilDB->dropTable( "chatroom_smilies" );
48 //$ilDB->dropTable( "chatroom_smilies_seq" );
49
50 $ilDB->createTable('chatroom_smilies', $fields);
51 $ilDB->addPrimaryKey('chatroom_smilies', array('smiley_id'));
52 $ilDB->createSequence('chatroom_smilies');
53 }
54
58 private static function _insertDefaultValues()
59 {
63 global $ilDB;
64
65 $values = array(
66 array("icon_smile.gif", ":)\n:-)\n:smile:"),
67 array("icon_wink.gif", ";)\n;-)\n:wink:"),
68 array("icon_laugh.gif", ":D\n:-D\n:laugh:\n:grin:\n:biggrin:"),
69 array("icon_sad.gif", ":(\n:-(\n:sad:"),
70 array("icon_shocked.gif", ":o\n:-o\n:shocked:"),
71 array("icon_tongue.gif", ":p\n:-p\n:tongue:"),
72 array("icon_cool.gif", ":cool:"),
73 array("icon_eek.gif", ":eek:"),
74 array("icon_angry.gif", ":||\n:-||\n:angry:"),
75 array("icon_flush.gif", ":flush:"),
76 array("icon_idea.gif", ":idea:"),
77 array("icon_thumbup.gif", ":thumbup:"),
78 array("icon_thumbdown.gif", ":thumbdown:"),
79 );
80
81 $stmt = $ilDB->prepareManip("
82 INSERT INTO chatroom_smilies (smiley_id, smiley_keywords, smiley_path)
83 VALUES (?, ?, ?)",
84 array("integer", "text", "text")
85 );
86
87 foreach($values as $val)
88 {
89 $row = array(
90 $ilDB->nextId("chatroom_smilies"),
91 $val[1],
92 $val[0]
93 );
94 $stmt->execute($row);
95 }
96 }
97
101 private static function _setupFolder()
102 {
103 $path = ilUtil::getWebspaceDir() . '/chatroom/smilies';
104
105 if(!is_dir($path))
106 {
107 mkdir($path, 0755, true);
108 }
109 }
110
117 public static function _checkSetup()
118 {
119 global $lng;
120
122
123 if(!is_dir($path))
124 {
125 ilUtil::sendInfo($lng->txt('chatroom_smilies_dir_not_exists'));
127
128 if(!is_dir($path))
129 {
130 ilUtil::sendFailure($lng->txt('chatroom_smilies_dir_not_available'));
131 return false;
132 }
133 else
134 {
135 $smilies = array(
136 "icon_smile.gif",
137 "icon_wink.gif",
138 "icon_laugh.gif",
139 "icon_sad.gif",
140 "icon_shocked.gif",
141 "icon_tongue.gif",
142 "icon_cool.gif",
143 "icon_eek.gif",
144 "icon_angry.gif",
145 "icon_flush.gif",
146 "icon_idea.gif",
147 "icon_thumbup.gif",
148 "icon_thumbdown.gif",
149 );
150
151 foreach($smilies as $smiley)
152 {
153 copy("templates/default/images/emoticons/$smiley", $path . "/$smiley");
154 }
155
156 self::_insertDefaultValues();
157 ilUtil::sendSuccess($lng->txt('chatroom_smilies_initialized'));
158 }
159 }
160
161 if(!is_writable($path))
162 {
163 ilUtil::sendInfo($lng->txt('chatroom_smilies_dir_not_writable'));
164 }
165
166 return true;
167 }
168
173 public static function _getSmileyDir()
174 {
175 return ilUtil::getWebspaceDir() . '/chatroom/smilies';
176 }
177
182 public static function _getSmilies()
183 {
187 global $ilDB;
188
189 $res = $ilDB->query("SELECT smiley_id, smiley_keywords, smiley_path FROM chatroom_smilies");
190 $result = array();
191
192 while($row = $ilDB->fetchAssoc($res))
193 {
194 $result[] = array(
195 "smiley_id" => $row['smiley_id'],
196 "smiley_keywords" => $row['smiley_keywords'],
197 "smiley_path" => $row['smiley_path'],
198 "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $row['smiley_path']
199 );
200 }
201
202 return $result;
203 }
204
210 public static function _deleteMultipleSmilies($ids = array())
211 {
212 global $ilDB;
213
214 $smilies = self::_getSmiliesById($ids);
215
216 if(count($smilies) <= 0)
217 return;
218
219 $sql_parts = array();
220
221 foreach($smilies as $s)
222 {
223 unlink($s["smiley_fullpath"]);
224 $sql_parts[] = "smiley_id = " . $ilDB->quote($s["smiley_id"], 'integer');
225 }
226
227 $ilDB->manipulate("DELETE FROM chatroom_smilies WHERE " . implode(" OR ", $sql_parts));
228 }
229
235 public static function _getSmiliesById($ids = array())
236 {
240 global $ilDB;
241
242 if(!count($ids))
243 return;
244
245 $sql = "SELECT smiley_id, smiley_keywords, smiley_path FROM chatroom_smilies WHERE ";
246
247 $sql_parts = array();
248
249 foreach($ids as $id)
250 {
251 $sql_parts[] .= "smiley_id = " . $ilDB->quote($id, "integer");
252 }
253
254 $sql .= join(" OR ", $sql_parts);
255 $res = $ilDB->query($sql);
256 $result = array();
257
258 while($row = $ilDB->fetchAssoc($res))
259 {
260 $result[] = array(
261 "smiley_id" => $row['smiley_id'],
262 "smiley_keywords" => $row['smiley_keywords'],
263 "smiley_path" => $row['smiley_path'],
264 "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $row['smiley_path']
265 );
266 }
267
268 return $result;
269 }
270
276 public static function _updateSmiley($data)
277 {
281 global $ilDB;
282
283 $ilDB->manipulateF(
284 "UPDATE chatroom_smilies
285 SET smiley_keywords = %s
286 WHERE
287 smiley_id = %s",
288 array('text', 'integer'),
289 array($data["smiley_keywords"], $data["smiley_id"])
290 );
291
292 if($data["smiley_path"])
293 {
294 $sm = self::_getSmiley($data["smiley_id"]);
295 unlink($sm["smiley_fullpath"]);
296 $ilDB->manipulateF(
297 "UPDATE chatroom_smilies
298 SET smiley_path = %s
299 WHERE
300 smiley_id = %s",
301 array('text', 'integer'),
302 array($data["smiley_path"], $data["smiley_id"])
303 );
304 }
305 }
306
314 public static function _getSmiley($a_id)
315 {
319 global $ilDB;
320
321 $res = $ilDB->queryF("
322 SELECT smiley_id, smiley_keywords, smiley_path
323 FROM chatroom_smilies
324 WHERE smiley_id = %s ",
325 array('integer'), array($a_id)
326 );
327
328 if($ilDB->numRows($res))
329 {
330 while($row = $ilDB->fetchAssoc($res))
331 {
332 return array(
333 "smiley_id" => $row['smiley_id'],
334 "smiley_keywords" => $row['smiley_keywords'],
335 "smiley_path" => $row['smiley_path'],
336 "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $row['smiley_path']
337 );
338 }
339 }
340
341 throw new Exception('smiley with id $a_id not found');
342 }
343
348 public static function _getSmiliesBasePath()
349 {
350 return ilUtil::getWebspaceDir() . '/chatroom/smilies/';
351 }
352
357 public static function _deleteSmiley($a_id)
358 {
362 global $ilDB;
363
364 try
365 {
366 $smiley = self::_getSmiley($a_id);
367 $path = ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $smiley["smiley_path"];
368
369 if(is_file($path))
370 unlink($path);
371
372 $ilDB->manipulateF(
373 "DELETE FROM chatroom_smilies
374 WHERE
375 smiley_id = %s",
376 array('integer'),
377 array($a_id)
378 );
379 }
380 catch(Exception $e)
381 {
382
383 }
384 }
385
391 public static function _storeSmiley($keywords, $path)
392 {
396 global $ilDB;
397
398 $stmt = $ilDB->prepareManip("
399 INSERT INTO chatroom_smilies (smiley_id, smiley_keywords, smiley_path)
400 VALUES (?, ?, ?)",
401 array(
402 "integer", "text", "text"
403 )
404 );
405 $row = array(
406 $ilDB->nextId("chatroom_smilies"),
407 $keywords,
408 $path
409 );
410 $stmt->execute($row);
411 }
412
418 public static function _prepareKeywords($words)
419 {
420 $keywordscheck = true;
421
422 // check keywords
423 $keywords_unchecked = explode("\n", $words);
424 if(count($keywords_unchecked) <= 0)
425 $keywordscheck = false;
426
427 if($keywordscheck)
428 {
429 $keywords = array();
430
431 foreach($keywords_unchecked as $word)
432 {
433 if(trim($word))
434 $keywords[] = trim($word);
435 }
436 }
437
438 if($keywordscheck && count($keywords) <= 0)
439 $keywordscheck = false;
440
441 if($keywordscheck)
442 return $keywords;
443 else
444 return array();
445 }
446}
$result
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomSmilies.
static _setupFolder()
Setup directory.
static _getSmileyDir()
Path to smilies.
static _initial()
Performs initial setup (db, dirs, default data)
static _getSmiliesBasePath()
Returns smilies basepath.
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 _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.
global $lng
Definition: privfeed.php:17
global $ilDB