]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/admin/admin_smilies.php
update brief bio
[www.vanrenterghem.biz.git] / phpBB2_old / admin / admin_smilies.php
1 <?php
2 /***************************************************************************
3 *                               admin_smilies.php
4 *                              -------------------
5 *     begin                : Thu May 31, 2001
6 *     copyright            : (C) 2001 The phpBB Group
7 *     email                : support@phpbb.com
8 *
9 *     $Id: admin_smilies.php,v 1.22.2.13 2004/03/25 15:57:20 acydburn Exp $
10 *
11 ****************************************************************************/
13 /***************************************************************************
14  *
15  *   This program is free software; you can redistribute it and/or modify
16  *   it under the terms of the GNU General Public License as published by
17  *   the Free Software Foundation; either version 2 of the License, or
18  *   (at your option) any later version.
19  *
20  ***************************************************************************/
22 /**************************************************************************
23 *       This file will be used for modifying the smiley settings for a board.
24 **************************************************************************/
26 define('IN_PHPBB', 1);
28 //
29 // First we do the setmodules stuff for the admin cp.
30 //
31 if( !empty($setmodules) )
32 {
33         $filename = basename(__FILE__);
34         $module['General']['Smilies'] = $filename;
36         return;
37 }
39 //
40 // Load default header
41 //
42 if( isset($HTTP_GET_VARS['export_pack']) )
43 {
44         if ( $HTTP_GET_VARS['export_pack'] == "send" )
45         {       
46                 $no_page_header = true;
47         }
48 }
50 $phpbb_root_path = "./../";
51 require($phpbb_root_path . 'extension.inc');
52 require('./pagestart.' . $phpEx);
54 //
55 // Check to see what mode we should operate in.
56 //
57 if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
58 {
59         $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
60         $mode = htmlspecialchars($mode);
61 }
62 else
63 {
64         $mode = "";
65 }
67 $delimeter  = '=+:';
69 //
70 // Read a listing of uploaded smilies for use in the add or edit smliey code...
71 //
72 $dir = @opendir($phpbb_root_path . $board_config['smilies_path']);
74 while($file = @readdir($dir))
75 {
76         if( !@is_dir(phpbb_realpath($phpbb_root_path . $board_config['smilies_path'] . '/' . $file)) )
77         {
78                 $img_size = @getimagesize($phpbb_root_path . $board_config['smilies_path'] . '/' . $file);
80                 if( $img_size[0] && $img_size[1] )
81                 {
82                         $smiley_images[] = $file;
83                 }
84                 else if( eregi('.pak$', $file) )
85                 {       
86                         $smiley_paks[] = $file;
87                 }
88         }
89 }
91 @closedir($dir);
93 //
94 // Select main mode
95 //
96 if( isset($HTTP_GET_VARS['import_pack']) || isset($HTTP_POST_VARS['import_pack']) )
97 {
98         //
99         // Import a list a "Smiley Pack"
100         //
101         $smile_pak = ( isset($HTTP_POST_VARS['smile_pak']) ) ? $HTTP_POST_VARS['smile_pak'] : $HTTP_GET_VARS['smile_pak'];
102         $clear_current = ( isset($HTTP_POST_VARS['clear_current']) ) ? $HTTP_POST_VARS['clear_current'] : $HTTP_GET_VARS['clear_current'];
103         $replace_existing = ( isset($HTTP_POST_VARS['replace']) ) ? $HTTP_POST_VARS['replace'] : $HTTP_GET_VARS['replace'];
105         if ( !empty($smile_pak) )
106         {
107                 //
108                 // The user has already selected a smile_pak file.. Import it.
109                 //
110                 if( !empty($clear_current)  )
111                 {
112                         $sql = "DELETE 
113                                 FROM " . SMILIES_TABLE;
114                         if( !$result = $db->sql_query($sql) )
115                         {
116                                 message_die(GENERAL_ERROR, "Couldn't delete current smilies", "", __LINE__, __FILE__, $sql);
117                         }
118                 }
119                 else
120                 {
121                         $sql = "SELECT code 
122                                 FROM ". SMILIES_TABLE;
123                         if( !$result = $db->sql_query($sql) )
124                         {
125                                 message_die(GENERAL_ERROR, "Couldn't get current smilies", "", __LINE__, __FILE__, $sql);
126                         }
128                         $cur_smilies = $db->sql_fetchrowset($result);
130                         for( $i = 0; $i < count($cur_smilies); $i++ )
131                         {
132                                 $k = $cur_smilies[$i]['code'];
133                                 $smiles[$k] = 1;
134                         }
135                 }
137                 $fcontents = @file($phpbb_root_path . $board_config['smilies_path'] . '/'. $smile_pak);
139                 if( empty($fcontents) )
140                 {
141                         message_die(GENERAL_ERROR, "Couldn't read smiley pak file", "", __LINE__, __FILE__, $sql);
142                 }
144                 for( $i = 0; $i < count($fcontents); $i++ )
145                 {
146                         $smile_data = explode($delimeter, trim(addslashes($fcontents[$i])));
148                         for( $j = 2; $j < count($smile_data); $j++)
149                         {
150                                 //
151                                 // Replace > and < with the proper html_entities for matching.
152                                 //
153                                 $smile_data[$j] = str_replace("<", "&lt;", $smile_data[$j]);
154                                 $smile_data[$j] = str_replace(">", "&gt;", $smile_data[$j]);
155                                 $k = $smile_data[$j];
157                                 if( $smiles[$k] == 1 )
158                                 {
159                                         if( !empty($replace_existing) )
160                                         {
161                                                 $sql = "UPDATE " . SMILIES_TABLE . " 
162                                                         SET smile_url = '" . str_replace("\'", "''", $smile_data[0]) . "', emoticon = '" . str_replace("\'", "''", $smile_data[1]) . "' 
163                                                         WHERE code = '" . str_replace("\'", "''", $smile_data[$j]) . "'";
164                                         }
165                                         else
166                                         {
167                                                 $sql = '';
168                                         }
169                                 }
170                                 else
171                                 {
172                                         $sql = "INSERT INTO " . SMILIES_TABLE . " (code, smile_url, emoticon)
173                                                 VALUES('" . str_replace("\'", "''", $smile_data[$j]) . "', '" . str_replace("\'", "''", $smile_data[0]) . "', '" . str_replace("\'", "''", $smile_data[1]) . "')";
174                                 }
176                                 if( $sql != '' )
177                                 {
178                                         $result = $db->sql_query($sql);
179                                         if( !$result )
180                                         {
181                                                 message_die(GENERAL_ERROR, "Couldn't update smilies!", "", __LINE__, __FILE__, $sql);
182                                         }
183                                 }
184                         }
185                 }
187                 $message = $lang['smiley_import_success'] . "<br /><br />" . sprintf($lang['Click_return_smileadmin'], "<a href=\"" . append_sid("admin_smilies.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
189                 message_die(GENERAL_MESSAGE, $message);
190                 
191         }
192         else
193         {
194                 //
195                 // Display the script to get the smile_pak cfg file...
196                 //
197                 $smile_paks_select = "<select name='smile_pak'><option value=''>" . $lang['Select_pak'] . "</option>";
198                 while( list($key, $value) = @each($smiley_paks) )
199                 {
200                         if ( !empty($value) ) 
201                         {
202                                 $smile_paks_select .= "<option>" . $value . "</option>";
203                         }
204                 }
205                 $smile_paks_select .= "</select>";
207                 $hidden_vars = "<input type='hidden' name='mode' value='import'>";      
209                 $template->set_filenames(array(
210                         "body" => "admin/smile_import_body.tpl")
211                 );
213                 $template->assign_vars(array(
214                         "L_SMILEY_TITLE" => $lang['smiley_title'],
215                         "L_SMILEY_EXPLAIN" => $lang['smiley_import_inst'],
216                         "L_SMILEY_IMPORT" => $lang['smiley_import'],
217                         "L_SELECT_LBL" => $lang['choose_smile_pak'],
218                         "L_IMPORT" => $lang['import'],
219                         "L_CONFLICTS" => $lang['smile_conflicts'],
220                         "L_DEL_EXISTING" => $lang['del_existing_smileys'], 
221                         "L_REPLACE_EXISTING" => $lang['replace_existing'], 
222                         "L_KEEP_EXISTING" => $lang['keep_existing'], 
224                         "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
225                         "S_SMILE_SELECT" => $smile_paks_select,
226                         "S_HIDDEN_FIELDS" => $hidden_vars)
227                 );
229                 $template->pparse("body");
230         }
232 else if( isset($HTTP_POST_VARS['export_pack']) || isset($HTTP_GET_VARS['export_pack']) )
234         //
235         // Export our smiley config as a smiley pak...
236         //
237         if ( $HTTP_GET_VARS['export_pack'] == "send" )
238         {       
239                 $sql = "SELECT * 
240                         FROM " . SMILIES_TABLE;
241                 if( !$result = $db->sql_query($sql) )
242                 {
243                         message_die(GENERAL_ERROR, "Could not get smiley list", "", __LINE__, __FILE__, $sql);
244                 }
246                 $resultset = $db->sql_fetchrowset($result);
248                 $smile_pak = "";
249                 for($i = 0; $i < count($resultset); $i++ )
250                 {
251                         $smile_pak .= $resultset[$i]['smile_url'] . $delimeter;
252                         $smile_pak .= $resultset[$i]['emoticon'] . $delimeter;
253                         $smile_pak .= $resultset[$i]['code'] . "\n";
254                 }
256                 header("Content-Type: text/x-delimtext; name=\"smiles.pak\"");
257                 header("Content-disposition: attachment; filename=smiles.pak");
259                 echo $smile_pak;
261                 exit;
262         }
264         $message = sprintf($lang['export_smiles'], "<a href=\"" . append_sid("admin_smilies.$phpEx?export_pack=send", true) . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_smileadmin'], "<a href=\"" . append_sid("admin_smilies.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
266         message_die(GENERAL_MESSAGE, $message);
269 else if( isset($HTTP_POST_VARS['add']) || isset($HTTP_GET_VARS['add']) )
271         //
272         // Admin has selected to add a smiley.
273         //
275         $template->set_filenames(array(
276                 "body" => "admin/smile_edit_body.tpl")
277         );
279         $filename_list = "";
280         for( $i = 0; $i < count($smiley_images); $i++ )
281         {
282                 $filename_list .= '<option value="' . $smiley_images[$i] . '">' . $smiley_images[$i] . '</option>';
283         }
285         $s_hidden_fields = '<input type="hidden" name="mode" value="savenew" />';
287         $template->assign_vars(array(
288                 "L_SMILEY_TITLE" => $lang['smiley_title'],
289                 "L_SMILEY_CONFIG" => $lang['smiley_config'],
290                 "L_SMILEY_EXPLAIN" => $lang['smile_desc'],
291                 "L_SMILEY_CODE" => $lang['smiley_code'],
292                 "L_SMILEY_URL" => $lang['smiley_url'],
293                 "L_SMILEY_EMOTION" => $lang['smiley_emot'],
294                 "L_SUBMIT" => $lang['Submit'],
295                 "L_RESET" => $lang['Reset'],
297                 "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smiley_images[0], 
299                 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"), 
300                 "S_HIDDEN_FIELDS" => $s_hidden_fields, 
301                 "S_FILENAME_OPTIONS" => $filename_list, 
302                 "S_SMILEY_BASEDIR" => $phpbb_root_path . $board_config['smilies_path'])
303         );
305         $template->pparse("body");
307 else if ( $mode != "" )
309         switch( $mode )
310         {
311                 case 'delete':
312                         //
313                         // Admin has selected to delete a smiley.
314                         //
316                         $smiley_id = ( !empty($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
317                         $smiley_id = intval($smiley_id);
319                         $sql = "DELETE FROM " . SMILIES_TABLE . "
320                                 WHERE smilies_id = " . $smiley_id;
321                         $result = $db->sql_query($sql);
322                         if( !$result )
323                         {
324                                 message_die(GENERAL_ERROR, "Couldn't delete smiley", "", __LINE__, __FILE__, $sql);
325                         }
327                         $message = $lang['smiley_del_success'] . "<br /><br />" . sprintf($lang['Click_return_smileadmin'], "<a href=\"" . append_sid("admin_smilies.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
329                         message_die(GENERAL_MESSAGE, $message);
330                         break;
332                 case 'edit':
333                         //
334                         // Admin has selected to edit a smiley.
335                         //
337                         $smiley_id = ( !empty($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
338                         $smiley_id = intval($smiley_id);
340                         $sql = "SELECT *
341                                 FROM " . SMILIES_TABLE . "
342                                 WHERE smilies_id = " . $smiley_id;
343                         $result = $db->sql_query($sql);
344                         if( !$result )
345                         {
346                                 message_die(GENERAL_ERROR, 'Could not obtain emoticon information', "", __LINE__, __FILE__, $sql);
347                         }
348                         $smile_data = $db->sql_fetchrow($result);
350                         $filename_list = "";
351                         for( $i = 0; $i < count($smiley_images); $i++ )
352                         {
353                                 if( $smiley_images[$i] == $smile_data['smile_url'] )
354                                 {
355                                         $smiley_selected = "selected=\"selected\"";
356                                         $smiley_edit_img = $smiley_images[$i];
357                                 }
358                                 else
359                                 {
360                                         $smiley_selected = "";
361                                 }
363                                 $filename_list .= '<option value="' . $smiley_images[$i] . '"' . $smiley_selected . '>' . $smiley_images[$i] . '</option>';
364                         }
366                         $template->set_filenames(array(
367                                 "body" => "admin/smile_edit_body.tpl")
368                         );
370                         $s_hidden_fields = '<input type="hidden" name="mode" value="save" /><input type="hidden" name="smile_id" value="' . $smile_data['smilies_id'] . '" />';
372                         $template->assign_vars(array(
373                                 "SMILEY_CODE" => $smile_data['code'],
374                                 "SMILEY_EMOTICON" => $smile_data['emoticon'],
376                                 "L_SMILEY_TITLE" => $lang['smiley_title'],
377                                 "L_SMILEY_CONFIG" => $lang['smiley_config'],
378                                 "L_SMILEY_EXPLAIN" => $lang['smile_desc'],
379                                 "L_SMILEY_CODE" => $lang['smiley_code'],
380                                 "L_SMILEY_URL" => $lang['smiley_url'],
381                                 "L_SMILEY_EMOTION" => $lang['smiley_emot'],
382                                 "L_SUBMIT" => $lang['Submit'],
383                                 "L_RESET" => $lang['Reset'],
385                                 "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smiley_edit_img, 
387                                 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
388                                 "S_HIDDEN_FIELDS" => $s_hidden_fields, 
389                                 "S_FILENAME_OPTIONS" => $filename_list, 
390                                 "S_SMILEY_BASEDIR" => $phpbb_root_path . $board_config['smilies_path'])
391                         );
393                         $template->pparse("body");
394                         break;
396                 case "save":
397                         //
398                         // Admin has submitted changes while editing a smiley.
399                         //
401                         //
402                         // Get the submitted data, being careful to ensure that we only
403                         // accept the data we are looking for.
404                         //
405                         $smile_code = ( isset($HTTP_POST_VARS['smile_code']) ) ? trim($HTTP_POST_VARS['smile_code']) : trim($HTTP_GET_VARS['smile_code']);
406                         $smile_url = ( isset($HTTP_POST_VARS['smile_url']) ) ? trim($HTTP_POST_VARS['smile_url']) : trim($HTTP_GET_VARS['smile_url']);
407                         $smile_emotion = ( isset($HTTP_POST_VARS['smile_emotion']) ) ? trim($HTTP_POST_VARS['smile_emotion']) : trim($HTTP_GET_VARS['smile_emotion']);
408                         $smile_id = ( isset($HTTP_POST_VARS['smile_id']) ) ? intval($HTTP_POST_VARS['smile_id']) : intval($HTTP_GET_VARS['smile_id']);
410                         // If no code was entered complain ...
411                         if ($smile_code == '' || $smile_url == '')
412                         {
413                                 message_die(MESSAGE, $lang['Fields_empty']);
414                         }
416                         //
417                         // Convert < and > to proper htmlentities for parsing.
418                         //
419                         $smile_code = str_replace('<', '&lt;', $smile_code);
420                         $smile_code = str_replace('>', '&gt;', $smile_code);
422                         //
423                         // Proceed with updating the smiley table.
424                         //
425                         $sql = "UPDATE " . SMILIES_TABLE . "
426                                 SET code = '" . str_replace("\'", "''", $smile_code) . "', smile_url = '" . str_replace("\'", "''", $smile_url) . "', emoticon = '" . str_replace("\'", "''", $smile_emotion) . "'
427                                 WHERE smilies_id = $smile_id";
428                         if( !($result = $db->sql_query($sql)) )
429                         {
430                                 message_die(GENERAL_ERROR, "Couldn't update smilies info", "", __LINE__, __FILE__, $sql);
431                         }
433                         $message = $lang['smiley_edit_success'] . "<br /><br />" . sprintf($lang['Click_return_smileadmin'], "<a href=\"" . append_sid("admin_smilies.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
435                         message_die(GENERAL_MESSAGE, $message);
436                         break;
438                 case "savenew":
439                         //
440                         // Admin has submitted changes while adding a new smiley.
441                         //
443                         //
444                         // Get the submitted data being careful to ensure the the data
445                         // we recieve and process is only the data we are looking for.
446                         //
447                         $smile_code = ( isset($HTTP_POST_VARS['smile_code']) ) ? $HTTP_POST_VARS['smile_code'] : $HTTP_GET_VARS['smile_code'];
448                         $smile_url = ( isset($HTTP_POST_VARS['smile_url']) ) ? $HTTP_POST_VARS['smile_url'] : $HTTP_GET_VARS['smile_url'];
449                         $smile_emotion = ( isset($HTTP_POST_VARS['smile_emotion']) ) ? $HTTP_POST_VARS['smile_emotion'] : $HTTP_GET_VARS['smile_emotion'];
451                         // If no code was entered complain ...
452                         if ($smile_code == '' || $smile_url == '')
453                         {
454                                 message_die(MESSAGE, $lang['Fields_empty']);
455                         }
457                         //
458                         // Convert < and > to proper htmlentities for parsing.
459                         //
460                         $smile_code = str_replace('<', '&lt;', $smile_code);
461                         $smile_code = str_replace('>', '&gt;', $smile_code);
463                         //
464                         // Save the data to the smiley table.
465                         //
466                         $sql = "INSERT INTO " . SMILIES_TABLE . " (code, smile_url, emoticon)
467                                 VALUES ('" . str_replace("\'", "''", $smile_code) . "', '" . str_replace("\'", "''", $smile_url) . "', '" . str_replace("\'", "''", $smile_emotion) . "')";
468                         $result = $db->sql_query($sql);
469                         if( !$result )
470                         {
471                                 message_die(GENERAL_ERROR, "Couldn't insert new smiley", "", __LINE__, __FILE__, $sql);
472                         }
474                         $message = $lang['smiley_add_success'] . "<br /><br />" . sprintf($lang['Click_return_smileadmin'], "<a href=\"" . append_sid("admin_smilies.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
476                         message_die(GENERAL_MESSAGE, $message);
477                         break;
478         }
480 else
483         //
484         // This is the main display of the page before the admin has selected
485         // any options.
486         //
487         $sql = "SELECT *
488                 FROM " . SMILIES_TABLE;
489         $result = $db->sql_query($sql);
490         if( !$result )
491         {
492                 message_die(GENERAL_ERROR, "Couldn't obtain smileys from database", "", __LINE__, __FILE__, $sql);
493         }
495         $smilies = $db->sql_fetchrowset($result);
497         $template->set_filenames(array(
498                 "body" => "admin/smile_list_body.tpl")
499         );
501         $template->assign_vars(array(
502                 "L_ACTION" => $lang['Action'],
503                 "L_SMILEY_TITLE" => $lang['smiley_title'],
504                 "L_SMILEY_TEXT" => $lang['smile_desc'],
505                 "L_DELETE" => $lang['Delete'],
506                 "L_EDIT" => $lang['Edit'],
507                 "L_SMILEY_ADD" => $lang['smile_add'],
508                 "L_CODE" => $lang['Code'],
509                 "L_EMOT" => $lang['Emotion'],
510                 "L_SMILE" => $lang['Smile'],
511                 "L_IMPORT_PACK" => $lang['import_smile_pack'],
512                 "L_EXPORT_PACK" => $lang['export_smile_pack'],
513                 
514                 "S_HIDDEN_FIELDS" => $s_hidden_fields, 
515                 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"))
516         );
518         //
519         // Loop throuh the rows of smilies setting block vars for the template.
520         //
521         for($i = 0; $i < count($smilies); $i++)
522         {
523                 //
524                 // Replace htmlentites for < and > with actual character.
525                 //
526                 $smilies[$i]['code'] = str_replace('&lt;', '<', $smilies[$i]['code']);
527                 $smilies[$i]['code'] = str_replace('&gt;', '>', $smilies[$i]['code']);
528                 
529                 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
530                 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
532                 $template->assign_block_vars("smiles", array(
533                         "ROW_COLOR" => "#" . $row_color,
534                         "ROW_CLASS" => $row_class,
535                         
536                         "SMILEY_IMG" =>  $phpbb_root_path . $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'], 
537                         "CODE" => $smilies[$i]['code'],
538                         "EMOT" => $smilies[$i]['emoticon'],
539                         
540                         "U_SMILEY_EDIT" => append_sid("admin_smilies.$phpEx?mode=edit&amp;id=" . $smilies[$i]['smilies_id']), 
541                         "U_SMILEY_DELETE" => append_sid("admin_smilies.$phpEx?mode=delete&amp;id=" . $smilies[$i]['smilies_id']))
542                 );
543         }
545         //
546         // Spit out the page.
547         //
548         $template->pparse("body");
551 //
552 // Page Footer
553 //
554 include('./page_footer_admin.'.$phpEx);
556 ?>