ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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.

@global ilLanguage $lng

Returns
boolean

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

132 {
133 global $lng;
134
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
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 _getSmileyDir()
Path to smilies.
static _insertDefaultValues()
Inserts default smiley set.
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:40
$path
Definition: index.php:22

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

Referenced by ilChatroomAdminSmileyTask\editSmiliesObject().

+ 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.

@global ilDBMySQL $ilDB

Parameters
array$ids

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

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 }
static _getSmiliesById($ids=array())
Fetches smilies from database by id.
global $ilDB

References $ilDB, and _getSmiliesById().

+ Here is the call graph for this function:

◆ _deleteSmiley()

static ilChatroomSmilies::_deleteSmiley (   $a_id)
static

Deletes smiliey by given id from database.

@global ilDBMySQL $ilDB

Parameters
integer$a_id

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

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 }
static _getSmiley($a_id)
Looks up and returns smiley with id, throws exception if id is not found.
static getWebspaceDir($mode="filesystem")
get webspace directory

References $ilDB, $path, _getSmiley(), and ilUtil\getWebspaceDir().

Referenced by ilChatroomAdminSmileyTask\deleteSmileyObject().

+ 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.

@global ilDBMySQL $ilDB

Parameters
integer$a_id
Returns
string

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

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

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

Referenced by _deleteSmiley(), _updateSmiley(), and ilChatroomAdminSmileyTask\showEditSmileyEntryFormObject().

+ 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.

109 {
110 return ilUtil::getWebspaceDir() . '/chatroom/smilies';
111 }

References ilUtil\getWebspaceDir().

Referenced by _checkSetup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getSmilies()

static ilChatroomSmilies::_getSmilies ( )
static

Fetches smilies from database.

    @return array

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

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 }

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

Referenced by ilChatroomSmiliesGUI\_getExistingSmiliesTable(), and ilChatroomInitialTask\executeDefault().

+ 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.

351 {
352 return ilUtil::getWebspaceDir() . '/chatroom/smilies/';
353 }

References ilUtil\getWebspaceDir().

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

+ 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.

@global ilDBMySQL $ilDB

Parameters
array$ids
Returns
array

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

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 }

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

Referenced by _deleteMultipleSmilies().

+ 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 {
121 }
static _setupFolder()
Setup directory.
static _setupDatabase()
Creates table and sequence.

References _insertDefaultValues(), _setupDatabase(), and _setupFolder().

+ Here is the call graph for this function:

◆ _insertDefaultValues()

static ilChatroomSmilies::_insertDefaultValues ( )
staticprivate

Inserts default smiley set.

@global ilDBMySQL $ilDB

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

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 }

References $ilDB, and $row.

Referenced by _checkSetup(), and _initial().

+ Here is the caller graph for this function:

◆ _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.

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 }

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

+ Here is the caller graph for this function:

◆ _setupDatabase()

static ilChatroomSmilies::_setupDatabase ( )
staticprivate

Creates table and sequence.

@global 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 }

References $ilDB.

Referenced by _initial().

+ Here is the caller graph for this function:

◆ _setupFolder()

static ilChatroomSmilies::_setupFolder ( )
staticprivate

Setup directory.

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

94 {
95 $path = ilUtil::getWebspaceDir() . '/chatroom/smilies';
96
97 if( !is_dir( $path ) )
98 {
99 mkdir( $path, 0755, true );
100 }
101 }

References $path, and ilUtil\getWebspaceDir().

Referenced by _initial().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeSmiley()

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

Stores smiley with given keywords and path in database.

@global ilDBMySQL $ilDB

Parameters
array$keywords
string$path

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

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 }

References $ilDB, $path, and $row.

Referenced by ilChatroomAdminSmileyTask\uploadSmileyObject().

+ 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"])

@global ilDBMySQL $ilDB

Parameters
array$data

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

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 }
$data

References $data, $ilDB, and _getSmiley().

Referenced by ilChatroomAdminSmileyTask\updateSmiliesObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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