ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  {
17  global $DIC;
18 
20  $ilDB = $DIC->database();
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 $DIC;
64 
66  $lng = $DIC->language();
67 
68  $path = self::_getSmileyDir();
69 
70  if (!is_dir($path)) {
71  ilUtil::sendInfo($lng->txt('chatroom_smilies_dir_not_exists'));
73 
74  if (!is_dir($path)) {
75  ilUtil::sendFailure($lng->txt('chatroom_smilies_dir_not_available'));
76  return false;
77  } else {
78  $smilies = array(
79  "icon_smile.gif",
80  "icon_wink.gif",
81  "icon_laugh.gif",
82  "icon_sad.gif",
83  "icon_shocked.gif",
84  "icon_tongue.gif",
85  "icon_cool.gif",
86  "icon_eek.gif",
87  "icon_angry.gif",
88  "icon_flush.gif",
89  "icon_idea.gif",
90  "icon_thumbup.gif",
91  "icon_thumbdown.gif",
92  );
93 
94  foreach ($smilies as $smiley) {
95  copy("templates/default/images/emoticons/$smiley", $path . "/$smiley");
96  }
97 
98  self::_insertDefaultValues();
99  ilUtil::sendSuccess($lng->txt('chatroom_smilies_initialized'));
100  }
101  }
102 
103  if (!is_writable($path)) {
104  ilUtil::sendInfo($lng->txt('chatroom_smilies_dir_not_writable'));
105  }
106 
107  return true;
108  }
109 
114  public static function _getSmileyDir()
115  {
116  return ilUtil::getWebspaceDir() . '/chatroom/smilies';
117  }
118 
123  public static function _getSmilies()
124  {
125  global $DIC;
126 
128  $ilDB = $DIC->database();
129 
130  $res = $ilDB->query("SELECT smiley_id, smiley_keywords, smiley_path FROM chatroom_smilies");
131  $result = array();
132 
133  while ($row = $ilDB->fetchAssoc($res)) {
134  $result[] = array(
135  "smiley_id" => $row['smiley_id'],
136  "smiley_keywords" => $row['smiley_keywords'],
137  "smiley_path" => $row['smiley_path'],
138  "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $row['smiley_path']
139  );
140  }
141 
142  return $result;
143  }
144 
150  public static function _deleteMultipleSmilies($ids = array())
151  {
152  global $DIC;
153 
155  $ilDB = $DIC->database();
156 
157  $smilies = self::_getSmiliesById($ids);
158 
159  if (count($smilies) <= 0) {
160  return;
161  }
162 
163  $sql_parts = array();
164 
165  foreach ($smilies as $s) {
166  unlink($s["smiley_fullpath"]);
167  $sql_parts[] = "smiley_id = " . $ilDB->quote($s["smiley_id"], 'integer');
168  }
169 
170  $ilDB->manipulate("DELETE FROM chatroom_smilies WHERE " . implode(" OR ", $sql_parts));
171  }
172 
178  public static function _getSmiliesById($ids = array())
179  {
180  global $DIC;
181 
183  $ilDB = $DIC->database();
184 
185  if (!count($ids)) {
186  return;
187  }
188 
189  $sql = "SELECT smiley_id, smiley_keywords, smiley_path FROM chatroom_smilies WHERE ";
190 
191  $sql_parts = array();
192 
193  foreach ($ids as $id) {
194  $sql_parts[] .= "smiley_id = " . $ilDB->quote($id, "integer");
195  }
196 
197  $sql .= join(" OR ", $sql_parts);
198  $res = $ilDB->query($sql);
199  $result = array();
200 
201  while ($row = $ilDB->fetchAssoc($res)) {
202  $result[] = array(
203  "smiley_id" => $row['smiley_id'],
204  "smiley_keywords" => $row['smiley_keywords'],
205  "smiley_path" => $row['smiley_path'],
206  "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $row['smiley_path']
207  );
208  }
209 
210  return $result;
211  }
212 
218  public static function _updateSmiley($data)
219  {
220  global $DIC;
221 
223  $ilDB = $DIC->database();
224 
225  $ilDB->manipulateF(
226  "UPDATE chatroom_smilies
227  SET smiley_keywords = %s
228  WHERE
229  smiley_id = %s",
230  array('text', 'integer'),
231  array($data["smiley_keywords"], $data["smiley_id"])
232  );
233 
234  if ($data["smiley_path"]) {
235  $sm = self::_getSmiley($data["smiley_id"]);
236  unlink($sm["smiley_fullpath"]);
237  $ilDB->manipulateF(
238  "UPDATE chatroom_smilies
239  SET smiley_path = %s
240  WHERE
241  smiley_id = %s",
242  array('text', 'integer'),
243  array($data["smiley_path"], $data["smiley_id"])
244  );
245  }
246  }
247 
255  public static function _getSmiley($a_id)
256  {
257  global $DIC;
258 
260  $ilDB = $DIC->database();
261 
262  $res = $ilDB->queryF(
263  "
264  SELECT smiley_id, smiley_keywords, smiley_path
265  FROM chatroom_smilies
266  WHERE smiley_id = %s ",
267  array('integer'),
268  array($a_id)
269  );
270 
271  if ($ilDB->numRows($res)) {
272  while ($row = $ilDB->fetchAssoc($res)) {
273  return array(
274  "smiley_id" => $row['smiley_id'],
275  "smiley_keywords" => $row['smiley_keywords'],
276  "smiley_path" => $row['smiley_path'],
277  "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $row['smiley_path']
278  );
279  }
280  }
281 
282  throw new Exception('smiley with id $a_id not found');
283  }
284 
289  public static function getSmiliesBasePath()
290  {
291  return 'chatroom/smilies';
292  }
293 
298  public static function _deleteSmiley($a_id)
299  {
300  global $DIC;
301 
303  $ilDB = $DIC->database();
304 
305  try {
306  $smiley = self::_getSmiley($a_id);
307  $path = ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $smiley["smiley_path"];
308 
309  if (is_file($path)) {
310  unlink($path);
311  }
312 
313  $ilDB->manipulateF(
314  "DELETE FROM chatroom_smilies
315  WHERE
316  smiley_id = %s",
317  array('integer'),
318  array($a_id)
319  );
320  } catch (Exception $e) {
321  }
322  }
323 
329  public static function _storeSmiley($keywords, $path)
330  {
331  global $DIC;
332 
334  $ilDB = $DIC->database();
335 
336  $stmt = $ilDB->prepareManip(
337  "
338  INSERT INTO chatroom_smilies (smiley_id, smiley_keywords, smiley_path)
339  VALUES (?, ?, ?)",
340  array(
341  "integer", "text", "text"
342  )
343  );
344  $row = array(
345  $ilDB->nextId("chatroom_smilies"),
346  $keywords,
347  $path
348  );
349  $stmt->execute($row);
350  }
351 
357  public static function _prepareKeywords($words)
358  {
359  $keywordscheck = true;
360 
361  // check keywords
362  $keywords_unchecked = explode("\n", $words);
363  if (count($keywords_unchecked) <= 0) {
364  $keywordscheck = false;
365  }
366 
367  if ($keywordscheck) {
368  $keywords = array();
369 
370  foreach ($keywords_unchecked as $word) {
371  if (trim($word)) {
372  $keywords[] = trim($word);
373  }
374  }
375  }
376 
377  if ($keywordscheck && count($keywords) <= 0) {
378  $keywordscheck = false;
379  }
380 
381  if ($keywordscheck) {
382  return $keywords;
383  } else {
384  return array();
385  }
386  }
387 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$path
Definition: aliased.php:25
$result
$stmt
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
$s
Definition: pwgen.php:45
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
foreach($_POST as $key=> $value) $res
$lng
$values
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$row
static _getSmileyDir()
Path to smilies.
static getSmiliesBasePath()
Returns smilies basepath.
static _prepareKeywords($words)
Trims given keywords and returns them in one array.
global $ilDB
static getWebspaceDir($mode="filesystem")
get webspace directory
Class ilChatroomSmilies.
$data
Definition: bench.php:6