2 /***************************************************************************
5 * begin : Thu May 31, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: admin_smilies.php,v 1.22.2.18 2006/04/13 09:56:48 grahamje Exp $
11 ****************************************************************************/
13 /***************************************************************************
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.
20 ***************************************************************************/
22 /**************************************************************************
23 * This file will be used for modifying the smiley settings for a board.
24 **************************************************************************/
26 define('IN_PHPBB', 1);
29 // First we do the setmodules stuff for the admin cp.
31 if( !empty($setmodules) )
33 $filename = basename(__FILE__);
34 $module['General']['Smilies'] = $filename;
40 // Load default header
42 if( isset($HTTP_GET_VARS['export_pack']) )
44 if ( $HTTP_GET_VARS['export_pack'] == "send" )
46 $no_page_header = true;
50 $phpbb_root_path = "./../";
51 require($phpbb_root_path . 'extension.inc');
53 $cancel = ( isset($HTTP_POST_VARS['cancel']) ) ? true : false;
54 $no_page_header = $cancel;
56 require('./pagestart.' . $phpEx);
60 redirect('admin/' . append_sid("admin_smilies.$phpEx", true));
64 // Check to see what mode we should operate in.
66 if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
68 $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
69 $mode = htmlspecialchars($mode);
79 // Read a listing of uploaded smilies for use in the add or edit smliey code...
81 $dir = @opendir($phpbb_root_path . $board_config['smilies_path']);
83 while($file = @readdir($dir))
85 if( !@is_dir(phpbb_realpath($phpbb_root_path . $board_config['smilies_path'] . '/' . $file)) )
87 $img_size = @getimagesize($phpbb_root_path . $board_config['smilies_path'] . '/' . $file);
89 if( $img_size[0] && $img_size[1] )
91 $smiley_images[] = $file;
93 else if( eregi('.pak$', $file) )
95 $smiley_paks[] = $file;
105 if( isset($HTTP_GET_VARS['import_pack']) || isset($HTTP_POST_VARS['import_pack']) )
108 // Import a list a "Smiley Pack"
110 $smile_pak = ( isset($HTTP_POST_VARS['smile_pak']) ) ? $HTTP_POST_VARS['smile_pak'] : $HTTP_GET_VARS['smile_pak'];
111 $clear_current = ( isset($HTTP_POST_VARS['clear_current']) ) ? $HTTP_POST_VARS['clear_current'] : $HTTP_GET_VARS['clear_current'];
112 $replace_existing = ( isset($HTTP_POST_VARS['replace']) ) ? $HTTP_POST_VARS['replace'] : $HTTP_GET_VARS['replace'];
114 if ( !empty($smile_pak) )
117 // The user has already selected a smile_pak file.. Import it.
119 if( !empty($clear_current) )
122 FROM " . SMILIES_TABLE;
123 if( !$result = $db->sql_query($sql) )
125 message_die(GENERAL_ERROR, "Couldn't delete current smilies", "", __LINE__, __FILE__, $sql);
131 FROM ". SMILIES_TABLE;
132 if( !$result = $db->sql_query($sql) )
134 message_die(GENERAL_ERROR, "Couldn't get current smilies", "", __LINE__, __FILE__, $sql);
137 $cur_smilies = $db->sql_fetchrowset($result);
139 for( $i = 0; $i < count($cur_smilies); $i++ )
141 $k = $cur_smilies[$i]['code'];
146 $fcontents = @file($phpbb_root_path . $board_config['smilies_path'] . '/'. $smile_pak);
148 if( empty($fcontents) )
150 message_die(GENERAL_ERROR, "Couldn't read smiley pak file", "", __LINE__, __FILE__, $sql);
153 for( $i = 0; $i < count($fcontents); $i++ )
155 $smile_data = explode($delimeter, trim(addslashes($fcontents[$i])));
157 for( $j = 2; $j < count($smile_data); $j++)
160 // Replace > and < with the proper html_entities for matching.
162 $smile_data[$j] = str_replace("<", "<", $smile_data[$j]);
163 $smile_data[$j] = str_replace(">", ">", $smile_data[$j]);
164 $k = $smile_data[$j];
166 if( $smiles[$k] == 1 )
168 if( !empty($replace_existing) )
170 $sql = "UPDATE " . SMILIES_TABLE . "
171 SET smile_url = '" . str_replace("\'", "''", $smile_data[0]) . "', emoticon = '" . str_replace("\'", "''", $smile_data[1]) . "'
172 WHERE code = '" . str_replace("\'", "''", $smile_data[$j]) . "'";
181 $sql = "INSERT INTO " . SMILIES_TABLE . " (code, smile_url, emoticon)
182 VALUES('" . str_replace("\'", "''", $smile_data[$j]) . "', '" . str_replace("\'", "''", $smile_data[0]) . "', '" . str_replace("\'", "''", $smile_data[1]) . "')";
187 $result = $db->sql_query($sql);
190 message_die(GENERAL_ERROR, "Couldn't update smilies!", "", __LINE__, __FILE__, $sql);
196 $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>");
198 message_die(GENERAL_MESSAGE, $message);
204 // Display the script to get the smile_pak cfg file...
206 $smile_paks_select = "<select name='smile_pak'><option value=''>" . $lang['Select_pak'] . "</option>";
207 while( list($key, $value) = @each($smiley_paks) )
209 if ( !empty($value) )
211 $smile_paks_select .= "<option>" . $value . "</option>";
214 $smile_paks_select .= "</select>";
216 $hidden_vars = "<input type='hidden' name='mode' value='import'>";
218 $template->set_filenames(array(
219 "body" => "admin/smile_import_body.tpl")
222 $template->assign_vars(array(
223 "L_SMILEY_TITLE" => $lang['smiley_title'],
224 "L_SMILEY_EXPLAIN" => $lang['smiley_import_inst'],
225 "L_SMILEY_IMPORT" => $lang['smiley_import'],
226 "L_SELECT_LBL" => $lang['choose_smile_pak'],
227 "L_IMPORT" => $lang['import'],
228 "L_CONFLICTS" => $lang['smile_conflicts'],
229 "L_DEL_EXISTING" => $lang['del_existing_smileys'],
230 "L_REPLACE_EXISTING" => $lang['replace_existing'],
231 "L_KEEP_EXISTING" => $lang['keep_existing'],
233 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
234 "S_SMILE_SELECT" => $smile_paks_select,
235 "S_HIDDEN_FIELDS" => $hidden_vars)
238 $template->pparse("body");
241 else if( isset($HTTP_POST_VARS['export_pack']) || isset($HTTP_GET_VARS['export_pack']) )
244 // Export our smiley config as a smiley pak...
246 if ( $HTTP_GET_VARS['export_pack'] == "send" )
249 FROM " . SMILIES_TABLE;
250 if( !$result = $db->sql_query($sql) )
252 message_die(GENERAL_ERROR, "Could not get smiley list", "", __LINE__, __FILE__, $sql);
255 $resultset = $db->sql_fetchrowset($result);
258 for($i = 0; $i < count($resultset); $i++ )
260 $smile_pak .= $resultset[$i]['smile_url'] . $delimeter;
261 $smile_pak .= $resultset[$i]['emoticon'] . $delimeter;
262 $smile_pak .= $resultset[$i]['code'] . "\n";
265 header("Content-Type: text/x-delimtext; name=\"smiles.pak\"");
266 header("Content-disposition: attachment; filename=smiles.pak");
273 $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>");
275 message_die(GENERAL_MESSAGE, $message);
278 else if( isset($HTTP_POST_VARS['add']) || isset($HTTP_GET_VARS['add']) )
281 // Admin has selected to add a smiley.
284 $template->set_filenames(array(
285 "body" => "admin/smile_edit_body.tpl")
289 for( $i = 0; $i < count($smiley_images); $i++ )
291 $filename_list .= '<option value="' . $smiley_images[$i] . '">' . $smiley_images[$i] . '</option>';
294 $s_hidden_fields = '<input type="hidden" name="mode" value="savenew" />';
296 $template->assign_vars(array(
297 "L_SMILEY_TITLE" => $lang['smiley_title'],
298 "L_SMILEY_CONFIG" => $lang['smiley_config'],
299 "L_SMILEY_EXPLAIN" => $lang['smile_desc'],
300 "L_SMILEY_CODE" => $lang['smiley_code'],
301 "L_SMILEY_URL" => $lang['smiley_url'],
302 "L_SMILEY_EMOTION" => $lang['smiley_emot'],
303 "L_SUBMIT" => $lang['Submit'],
304 "L_RESET" => $lang['Reset'],
306 "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smiley_images[0],
308 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
309 "S_HIDDEN_FIELDS" => $s_hidden_fields,
310 "S_FILENAME_OPTIONS" => $filename_list,
311 "S_SMILEY_BASEDIR" => $phpbb_root_path . $board_config['smilies_path'])
314 $template->pparse("body");
316 else if ( $mode != "" )
322 // Admin has selected to delete a smiley.
325 $smiley_id = ( !empty($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
326 $smiley_id = intval($smiley_id);
328 $confirm = isset($HTTP_POST_VARS['confirm']);
332 $sql = "DELETE FROM " . SMILIES_TABLE . "
333 WHERE smilies_id = " . $smiley_id;
334 $result = $db->sql_query($sql);
337 message_die(GENERAL_ERROR, "Couldn't delete smiley", "", __LINE__, __FILE__, $sql);
340 $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>");
342 message_die(GENERAL_MESSAGE, $message);
346 // Present the confirmation screen to the user
347 $template->set_filenames(array(
348 'body' => 'admin/confirm_body.tpl')
351 $hidden_fields = '<input type="hidden" name="mode" value="delete" /><input type="hidden" name="id" value="' . $smiley_id . '" />';
353 $template->assign_vars(array(
354 'MESSAGE_TITLE' => $lang['Confirm'],
355 'MESSAGE_TEXT' => $lang['Confirm_delete_smiley'],
357 'L_YES' => $lang['Yes'],
358 'L_NO' => $lang['No'],
360 'S_CONFIRM_ACTION' => append_sid("admin_smilies.$phpEx"),
361 'S_HIDDEN_FIELDS' => $hidden_fields)
363 $template->pparse('body');
369 // Admin has selected to edit a smiley.
372 $smiley_id = ( !empty($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
373 $smiley_id = intval($smiley_id);
376 FROM " . SMILIES_TABLE . "
377 WHERE smilies_id = " . $smiley_id;
378 $result = $db->sql_query($sql);
381 message_die(GENERAL_ERROR, 'Could not obtain emoticon information', "", __LINE__, __FILE__, $sql);
383 $smile_data = $db->sql_fetchrow($result);
386 for( $i = 0; $i < count($smiley_images); $i++ )
388 if( $smiley_images[$i] == $smile_data['smile_url'] )
390 $smiley_selected = "selected=\"selected\"";
391 $smiley_edit_img = $smiley_images[$i];
395 $smiley_selected = "";
398 $filename_list .= '<option value="' . $smiley_images[$i] . '"' . $smiley_selected . '>' . $smiley_images[$i] . '</option>';
401 $template->set_filenames(array(
402 "body" => "admin/smile_edit_body.tpl")
405 $s_hidden_fields = '<input type="hidden" name="mode" value="save" /><input type="hidden" name="smile_id" value="' . $smile_data['smilies_id'] . '" />';
407 $template->assign_vars(array(
408 "SMILEY_CODE" => $smile_data['code'],
409 "SMILEY_EMOTICON" => $smile_data['emoticon'],
411 "L_SMILEY_TITLE" => $lang['smiley_title'],
412 "L_SMILEY_CONFIG" => $lang['smiley_config'],
413 "L_SMILEY_EXPLAIN" => $lang['smile_desc'],
414 "L_SMILEY_CODE" => $lang['smiley_code'],
415 "L_SMILEY_URL" => $lang['smiley_url'],
416 "L_SMILEY_EMOTION" => $lang['smiley_emot'],
417 "L_SUBMIT" => $lang['Submit'],
418 "L_RESET" => $lang['Reset'],
420 "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smiley_edit_img,
422 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
423 "S_HIDDEN_FIELDS" => $s_hidden_fields,
424 "S_FILENAME_OPTIONS" => $filename_list,
425 "S_SMILEY_BASEDIR" => $phpbb_root_path . $board_config['smilies_path'])
428 $template->pparse("body");
433 // Admin has submitted changes while editing a smiley.
437 // Get the submitted data, being careful to ensure that we only
438 // accept the data we are looking for.
440 $smile_code = ( isset($HTTP_POST_VARS['smile_code']) ) ? trim($HTTP_POST_VARS['smile_code']) : '';
441 $smile_url = ( isset($HTTP_POST_VARS['smile_url']) ) ? trim($HTTP_POST_VARS['smile_url']) : '';
442 $smile_url = phpbb_ltrim(basename($smile_url), "'");
443 $smile_emotion = ( isset($HTTP_POST_VARS['smile_emotion']) ) ? htmlspecialchars(trim($HTTP_POST_VARS['smile_emotion'])) : '';
444 $smile_id = ( isset($HTTP_POST_VARS['smile_id']) ) ? intval($HTTP_POST_VARS['smile_id']) : 0;
445 $smile_code = trim($smile_code);
446 $smile_url = trim($smile_url);
448 // If no code was entered complain ...
449 if ($smile_code == '' || $smile_url == '')
451 message_die(GENERAL_MESSAGE, $lang['Fields_empty']);
455 // Convert < and > to proper htmlentities for parsing.
457 $smile_code = str_replace('<', '<', $smile_code);
458 $smile_code = str_replace('>', '>', $smile_code);
461 // Proceed with updating the smiley table.
463 $sql = "UPDATE " . SMILIES_TABLE . "
464 SET code = '" . str_replace("\'", "''", $smile_code) . "', smile_url = '" . str_replace("\'", "''", $smile_url) . "', emoticon = '" . str_replace("\'", "''", $smile_emotion) . "'
465 WHERE smilies_id = $smile_id";
466 if( !($result = $db->sql_query($sql)) )
468 message_die(GENERAL_ERROR, "Couldn't update smilies info", "", __LINE__, __FILE__, $sql);
471 $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>");
473 message_die(GENERAL_MESSAGE, $message);
478 // Admin has submitted changes while adding a new smiley.
482 // Get the submitted data being careful to ensure the the data
483 // we recieve and process is only the data we are looking for.
485 $smile_code = ( isset($HTTP_POST_VARS['smile_code']) ) ? $HTTP_POST_VARS['smile_code'] : '';
486 $smile_url = ( isset($HTTP_POST_VARS['smile_url']) ) ? $HTTP_POST_VARS['smile_url'] : '';
487 $smile_url = phpbb_ltrim(basename($smile_url), "'");
488 $smile_emotion = ( isset($HTTP_POST_VARS['smile_emotion']) ) ? htmlspecialchars(trim($HTTP_POST_VARS['smile_emotion'])) : '';
489 $smile_code = trim($smile_code);
490 $smile_url = trim($smile_url);
492 // If no code was entered complain ...
493 if ($smile_code == '' || $smile_url == '')
495 message_die(GENERAL_MESSAGE, $lang['Fields_empty']);
499 // Convert < and > to proper htmlentities for parsing.
501 $smile_code = str_replace('<', '<', $smile_code);
502 $smile_code = str_replace('>', '>', $smile_code);
505 // Save the data to the smiley table.
507 $sql = "INSERT INTO " . SMILIES_TABLE . " (code, smile_url, emoticon)
508 VALUES ('" . str_replace("\'", "''", $smile_code) . "', '" . str_replace("\'", "''", $smile_url) . "', '" . str_replace("\'", "''", $smile_emotion) . "')";
509 $result = $db->sql_query($sql);
512 message_die(GENERAL_ERROR, "Couldn't insert new smiley", "", __LINE__, __FILE__, $sql);
515 $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>");
517 message_die(GENERAL_MESSAGE, $message);
525 // This is the main display of the page before the admin has selected
529 FROM " . SMILIES_TABLE;
530 $result = $db->sql_query($sql);
533 message_die(GENERAL_ERROR, "Couldn't obtain smileys from database", "", __LINE__, __FILE__, $sql);
536 $smilies = $db->sql_fetchrowset($result);
538 $template->set_filenames(array(
539 "body" => "admin/smile_list_body.tpl")
542 $template->assign_vars(array(
543 "L_ACTION" => $lang['Action'],
544 "L_SMILEY_TITLE" => $lang['smiley_title'],
545 "L_SMILEY_TEXT" => $lang['smile_desc'],
546 "L_DELETE" => $lang['Delete'],
547 "L_EDIT" => $lang['Edit'],
548 "L_SMILEY_ADD" => $lang['smile_add'],
549 "L_CODE" => $lang['Code'],
550 "L_EMOT" => $lang['Emotion'],
551 "L_SMILE" => $lang['Smile'],
552 "L_IMPORT_PACK" => $lang['import_smile_pack'],
553 "L_EXPORT_PACK" => $lang['export_smile_pack'],
555 "S_HIDDEN_FIELDS" => $s_hidden_fields,
556 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"))
560 // Loop throuh the rows of smilies setting block vars for the template.
562 for($i = 0; $i < count($smilies); $i++)
565 // Replace htmlentites for < and > with actual character.
567 $smilies[$i]['code'] = str_replace('<', '<', $smilies[$i]['code']);
568 $smilies[$i]['code'] = str_replace('>', '>', $smilies[$i]['code']);
570 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
571 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
573 $template->assign_block_vars("smiles", array(
574 "ROW_COLOR" => "#" . $row_color,
575 "ROW_CLASS" => $row_class,
577 "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'],
578 "CODE" => $smilies[$i]['code'],
579 "EMOT" => $smilies[$i]['emoticon'],
581 "U_SMILEY_EDIT" => append_sid("admin_smilies.$phpEx?mode=edit&id=" . $smilies[$i]['smilies_id']),
582 "U_SMILEY_DELETE" => append_sid("admin_smilies.$phpEx?mode=delete&id=" . $smilies[$i]['smilies_id']))
587 // Spit out the page.
589 $template->pparse("body");
595 include('./page_footer_admin.'.$phpEx);