ILIAS  release_4-4 Revision
ilChatroomSmilies Class Reference

Class ilChatroomSmilies. More...

+ Collaboration diagram for ilChatroomSmilies:

Static Public Member Functions

static _getSmileyDir ()
 Path to smilies. More...
 
static _initial ()
 Performs initial setup (db, dirs, default data) More...
 
static _checkSetup ()
 Checks if smiley folder is available; if not it will try to create folder and performs actions for an initial smiley set. More...
 
static _getSmilies ()
 Fetches smilies from database. More...
 
static _getSmiley ($a_id)
 Looks up and returns smiley with id, throws exception if id is not found. More...
 
static _getSmiliesById ($ids=array())
 Fetches smilies from database by id. More...
 
static _deleteMultipleSmilies ($ids=array())
 Deletes multiple smilies by given id array. More...
 
static _updateSmiley ($data)
 Updates smiley in DB by keyword and id from given array ($data["smiley_keywords"], $data["smiley_id"]) More...
 
static _getSmiliesBasePath ()
 Returns smilies basepath. More...
 
static _deleteSmiley ($a_id)
 Deletes smiliey by given id from database. More...
 
static _storeSmiley ($keywords, $path)
 Stores smiley with given keywords and path in database. More...
 
static _prepareKeywords ($words)
 Trims given keywords and returns them in one array. More...
 

Static Private Member Functions

static _setupDatabase ()
 Creates table and sequence. More...
 
static _insertDefaultValues ()
 Inserts default smiley set. More...
 
static _setupFolder ()
 Setup directory. More...
 

Detailed Description

Class ilChatroomSmilies.

Author
Jan Posselt jposs.nosp@m.elt@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$

Definition at line 13 of file class.ilChatroomSmilies.php.

Member Function Documentation

◆ _checkSetup()

static ilChatroomSmilies::_checkSetup ( )
static

Checks if smiley folder is available; if not it will try to create folder and performs actions for an initial smiley set.

ilLanguage $lng

Returns
boolean

Definition at line 131 of file class.ilChatroomSmilies.php.

References $lng, $path, ilUtil\makeDirParents(), ilUtil\sendFailure(), ilUtil\sendInfo(), and ilUtil\sendSuccess().

Referenced by ilChatroomSmileyTask\editSmiliesObject().

132  {
133  global $lng;
134 
135  $path = self::_getSmileyDir();
136 
137  if( !is_dir( $path ) )
138  {
139  ilUtil::sendInfo( $lng->txt( 'chatroom_smilies_dir_not_exists' ) );
141 
142  if( !is_dir( $path ) )
143  {
144  ilUtil::sendFailure( $lng->txt( 'chatroom_smilies_dir_not_available' ) );
145  return false;
146  }
147  else
148  {
149  $smilies = array(
150  "icon_smile.gif",
151  "icon_wink.gif",
152  "icon_laugh.gif",
153  "icon_sad.gif",
154  "icon_shocked.gif",
155  "icon_tongue.gif",
156  "icon_cool.gif",
157  "icon_eek.gif",
158  "icon_angry.gif",
159  "icon_flush.gif",
160  "icon_idea.gif",
161  "icon_thumbup.gif",
162  "icon_thumbdown.gif",
163  );
164 
165  foreach( $smilies as $smiley )
166  {
167  copy( "templates/default/images/emoticons/$smiley", $path . "/$smiley" );
168  }
169 
170  self::_insertDefaultValues();
171  ilUtil::sendSuccess( $lng->txt( 'chatroom_smilies_initialized' ) );
172  }
173  }
174 
175  if( !is_writable( $path ) )
176  {
177  ilUtil::sendInfo( $lng->txt( 'chatroom_smilies_dir_not_writable' ) );
178  }
179 
180  return true;
181  }
static sendSuccess($a_info="", $a_keep=false)
Send Success 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.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:40
$path
Definition: index.php:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _deleteMultipleSmilies()

static ilChatroomSmilies::_deleteMultipleSmilies (   $ids = array())
static

Deletes multiple smilies by given id array.

ilDBMySQL $ilDB

Parameters
array$ids

Definition at line 290 of file class.ilChatroomSmilies.php.

Referenced by ilChatroomSmileyTask\confirmedDeleteMultipleObject().

291  {
292  global $ilDB;
293 
294  $smilies = self::_getSmiliesById( $ids );
295 
296  if( count( $smilies ) <= 0 )
297  return;
298 
299  $sql_parts = array();
300 
301  foreach( $smilies as $s )
302  {
303  unlink( $s["smiley_fullpath"] );
304  $sql_parts[] = "smiley_id = " . $ilDB->quote( $s["smiley_id"], 'integer' );
305  }
306 
307  $ilDB->manipulate( "DELETE FROM chatroom_smilies WHERE " . join( " OR ", $sql_parts ) );
308  }
+ Here is the caller graph for this function:

◆ _deleteSmiley()

static ilChatroomSmilies::_deleteSmiley (   $a_id)
static

Deletes smiliey by given id from database.

ilDBMySQL $ilDB

Parameters
integer$a_id

Definition at line 361 of file class.ilChatroomSmilies.php.

References $path, and ilUtil\getWebspaceDir().

Referenced by ilChatroomSmileyTask\deleteSmileyObject().

362  {
363  global $ilDB;
364 
365  try
366  {
367  $smiley = self::_getSmiley( $a_id );
368  $path = ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $smiley["smiley_path"];
369 
370  if( is_file( $path ) )
371  unlink( $path );
372 
373  $ilDB->manipulateF(
374  "DELETE FROM chatroom_smilies
375  WHERE
376  smiley_id = %s",
377  array('integer'),
378  array($a_id)
379  );
380  }
381  catch(Exception $e)
382  {
383 
384  }
385  }
$path
Definition: index.php:22
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getSmiley()

static ilChatroomSmilies::_getSmiley (   $a_id)
static

Looks up and returns smiley with id, throws exception if id is not found.

ilDBMySQL $ilDB

Parameters
integer$a_id
Returns
string

Definition at line 219 of file class.ilChatroomSmilies.php.

References $res, $result, and ilUtil\getWebspaceDir().

Referenced by ilChatroomSmileyTask\showDeleteSmileyFormObject(), and ilChatroomSmileyTask\showEditSmileyEntryFormObject().

220  {
221  global $ilDB;
222 
223  $res = $ilDB->queryF( "
224  SELECT smiley_id, smiley_keywords, smiley_path
225  FROM chatroom_smilies
226  WHERE smiley_id = %s ",
227  array('integer'), array($a_id)
228  );
229 
230  if( $res->numRows() )
231  {
232  $tmp = $res->fetchRow();
233  $result = array(
234  "smiley_id" => $tmp[0],
235  "smiley_keywords" => $tmp[1],
236  "smiley_path" => $tmp[2],
237  "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $tmp[2]
238  );
239  return $result;
240  }
241  throw new Exception( 'smiley with id $a_id not found' );
242  }
$result
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getSmileyDir()

static ilChatroomSmilies::_getSmileyDir ( )
static

Path to smilies.

Returns
string

Definition at line 108 of file class.ilChatroomSmilies.php.

References ilUtil\getWebspaceDir().

109  {
110  return ilUtil::getWebspaceDir() . '/chatroom/smilies';
111  }
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:

◆ _getSmilies()

static ilChatroomSmilies::_getSmilies ( )
static

Fetches smilies from database.

Returns
array

Definition at line 188 of file class.ilChatroomSmilies.php.

References $res, $result, and ilUtil\getWebspaceDir().

Referenced by ilChatroomSmiliesGUI\_getExistingSmiliesTable(), ilChatroomViewTask\cancelJoin(), ilChatroomInitialTask\executeDefault(), and ilChatroomBlockGUI\getHTML().

189  {
190  global $ilDB;
191 
192  $res = $ilDB->query(
193  "SELECT smiley_id, smiley_keywords, smiley_path
194  FROM chatroom_smilies"
195  );
196  $result = array();
197 
198  for( $i = 0; $i < $res->numRows(); $i++ )
199  {
200  $tmp = $res->fetchRow();
201  $result[] = array(
202  "smiley_id" => $tmp[0],
203  "smiley_keywords" => $tmp[1],
204  "smiley_path" => $tmp[2],
205  "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $tmp[2]
206  );
207  }
208  return $result;
209  }
$result
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getSmiliesBasePath()

static ilChatroomSmilies::_getSmiliesBasePath ( )
static

Returns smilies basepath.

Returns
string

Definition at line 350 of file class.ilChatroomSmilies.php.

References ilUtil\getWebspaceDir().

Referenced by ilChatroomSmileyTask\updateSmiliesObject(), and ilChatroomSmileyTask\uploadSmileyObject().

351  {
352  return ilUtil::getWebspaceDir() . '/chatroom/smilies/';
353  }
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getSmiliesById()

static ilChatroomSmilies::_getSmiliesById (   $ids = array())
static

Fetches smilies from database by id.

ilDBMySQL $ilDB

Parameters
array$ids
Returns
array

Definition at line 251 of file class.ilChatroomSmilies.php.

References $res, $result, and ilUtil\getWebspaceDir().

Referenced by ilChatroomSmileyTask\deleteMultipleObject().

252  {
253  global $ilDB;
254 
255  if( !count( $ids ) )
256  return;
257 
258  $sql = "SELECT smiley_id, smiley_keywords, smiley_path FROM chatroom_smilies WHERE ";
259 
260  $sql_parts = array();
261 
262  foreach( $ids as $id )
263  {
264  $sql_parts[] .= "smiley_id = " . $ilDB->quote( $id, "integer" );
265  }
266 
267  $sql .= join( " OR ", $sql_parts );
268  $res = $ilDB->query( $sql );
269  $result = array();
270 
271  for( $i = 0; $i < $res->numRows(); $i++ )
272  {
273  $tmp = $res->fetchRow();
274  $result[] = array(
275  "smiley_id" => $tmp[0],
276  "smiley_keywords" => $tmp[1],
277  "smiley_path" => $tmp[2],
278  "smiley_fullpath" => ilUtil::getWebspaceDir() . '/chatroom/smilies/' . $tmp[2]
279  );
280  }
281  return $result;
282  }
$result
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _initial()

static ilChatroomSmilies::_initial ( )
static

Performs initial setup (db, dirs, default data)

Definition at line 116 of file class.ilChatroomSmilies.php.

117  {
118  self::_setupDatabase();
119  self::_insertDefaultValues();
120  self::_setupFolder();
121  }

◆ _insertDefaultValues()

static ilChatroomSmilies::_insertDefaultValues ( )
staticprivate

Inserts default smiley set.

ilDBMySQL $ilDB

Definition at line 53 of file class.ilChatroomSmilies.php.

References $row.

54  {
55  global $ilDB;
56 
57  $values = array(
58  array("icon_smile.gif", ":)\n:-)\n:smile:"),
59  array("icon_wink.gif", ";)\n;-)\n:wink:"),
60  array("icon_laugh.gif", ":D\n:-D\n:laugh:\n:grin:\n:biggrin:"),
61  array("icon_sad.gif", ":(\n:-(\n:sad:"),
62  array("icon_shocked.gif", ":o\n:-o\n:shocked:"),
63  array("icon_tongue.gif", ":p\n:-p\n:tongue:"),
64  array("icon_cool.gif", ":cool:"),
65  array("icon_eek.gif", ":eek:"),
66  array("icon_angry.gif", ":||\n:-||\n:angry:"),
67  array("icon_flush.gif", ":flush:"),
68  array("icon_idea.gif", ":idea:"),
69  array("icon_thumbup.gif", ":thumbup:"),
70  array("icon_thumbdown.gif", ":thumbdown:"),
71  );
72 
73  $stmt = $ilDB->prepare("
74  INSERT INTO chatroom_smilies (smiley_id, smiley_keywords, smiley_path)
75  VALUES (?, ?, ?)",
76  array( "integer", "text", "text" )
77  );
78 
79  foreach( $values as $val )
80  {
81  $row = array(
82  $ilDB->nextID( "chatroom_smilies" ),
83  $val[1],
84  $val[0]
85  );
86  $stmt->execute( $row );
87  }
88  }

◆ _prepareKeywords()

static ilChatroomSmilies::_prepareKeywords (   $words)
static

Trims given keywords and returns them in one array.

Parameters
string$words
Returns
array

Definition at line 419 of file class.ilChatroomSmilies.php.

Referenced by ilChatroomSmileyTask\updateSmiliesObject(), and ilChatroomSmileyTask\uploadSmileyObject().

420  {
421  $keywordscheck = true;
422 
423  // check keywords
424  $keywords_unchecked = explode( "\n", $words );
425  if( count( $keywords_unchecked ) <= 0 )
426  $keywordscheck = false;
427 
428  if( $keywordscheck )
429  {
430  $keywords = array();
431 
432  foreach( $keywords_unchecked as $word )
433  {
434  if( trim( $word ) )
435  $keywords[] = trim( $word );
436  }
437  }
438 
439  if( $keywordscheck && count( $keywords ) <= 0 )
440  $keywordscheck = false;
441 
442  if( $keywordscheck )
443  return $keywords;
444  else
445  return array();
446  }
+ Here is the caller graph for this function:

◆ _setupDatabase()

static ilChatroomSmilies::_setupDatabase ( )
staticprivate

Creates table and sequence.

ilDBMySQL $ilDB

Definition at line 21 of file class.ilChatroomSmilies.php.

22  {
23  global $ilDB;
24 
25  $fields = array(
26  'smiley_id' => array(
27  'type' => 'integer',
28  'length' => 4,
29  ),
30  'smiley_keywords' => array(
31  'type' => 'text',
32  'length' => 100,
33  ),
34  'smiley_path' => array(
35  'type' => 'text',
36  'length' => 200,
37  )
38  );
39 
40  //$ilDB->dropTable( "chatroom_smilies" );
41  //$ilDB->dropTable( "chatroom_smilies_seq" );
42 
43  $ilDB->createTable( 'chatroom_smilies', $fields );
44  $ilDB->addPrimaryKey( 'chatroom_smilies', array('smiley_id') );
45  $ilDB->createSequence( 'chatroom_smilies' );
46  }

◆ _setupFolder()

static ilChatroomSmilies::_setupFolder ( )
staticprivate

Setup directory.

Definition at line 93 of file class.ilChatroomSmilies.php.

References $path, and ilUtil\getWebspaceDir().

94  {
95  $path = ilUtil::getWebspaceDir() . '/chatroom/smilies';
96 
97  if( !is_dir( $path ) )
98  {
99  mkdir( $path, 0755, true );
100  }
101  }
$path
Definition: index.php:22
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:

◆ _storeSmiley()

static ilChatroomSmilies::_storeSmiley (   $keywords,
  $path 
)
static

Stores smiley with given keywords and path in database.

ilDBMySQL $ilDB

Parameters
array$keywords
string$path

Definition at line 394 of file class.ilChatroomSmilies.php.

References $path, and $row.

Referenced by ilChatroomSmileyTask\uploadSmileyObject().

395  {
396  global $ilDB;
397 
398  $stmt = $ilDB->prepare( "
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  }
$path
Definition: index.php:22
+ Here is the caller graph for this function:

◆ _updateSmiley()

static ilChatroomSmilies::_updateSmiley (   $data)
static

Updates smiley in DB by keyword and id from given array ($data["smiley_keywords"], $data["smiley_id"])

ilDBMySQL $ilDB

Parameters
array$data

Definition at line 317 of file class.ilChatroomSmilies.php.

References $data.

Referenced by ilChatroomSmileyTask\updateSmiliesObject().

318  {
319  global $ilDB;
320 
321  $ilDB->manipulateF(
322  "UPDATE chatroom_smilies
323  SET smiley_keywords = %s
324  WHERE
325  smiley_id = %s",
326  array('text', 'integer'),
327  array($data["smiley_keywords"], $data["smiley_id"])
328  );
329 
330  if( $data["smiley_path"] )
331  {
332  $sm = self::_getSmiley( $data["smiley_id"] );
333  unlink( $sm["smiley_fullpath"] );
334  $ilDB->manipulateF(
335  "UPDATE chatroom_smilies
336  SET smiley_path = %s
337  WHERE
338  smiley_id = %s",
339  array('text', 'integer'),
340  array($data["smiley_path"], $data["smiley_id"])
341  );
342  }
343  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: