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.13 2004/03/25 15:57:20 acydburn 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');
52 require('./pagestart.' . $phpEx);
55 // Check to see what mode we should operate in.
57 if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
59 $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
60 $mode = htmlspecialchars($mode);
70 // Read a listing of uploaded smilies for use in the add or edit smliey code...
72 $dir = @opendir($phpbb_root_path . $board_config['smilies_path']);
74 while($file = @readdir($dir))
76 if( !@is_dir(phpbb_realpath($phpbb_root_path . $board_config['smilies_path'] . '/' . $file)) )
78 $img_size = @getimagesize($phpbb_root_path . $board_config['smilies_path'] . '/' . $file);
80 if( $img_size[0] && $img_size[1] )
82 $smiley_images[] = $file;
84 else if( eregi('.pak$', $file) )
86 $smiley_paks[] = $file;
96 if( isset($HTTP_GET_VARS['import_pack']) || isset($HTTP_POST_VARS['import_pack']) )
99 // Import a list a "Smiley Pack"
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) )
108 // The user has already selected a smile_pak file.. Import it.
110 if( !empty($clear_current) )
113 FROM " . SMILIES_TABLE;
114 if( !$result = $db->sql_query($sql) )
116 message_die(GENERAL_ERROR, "Couldn't delete current smilies", "", __LINE__, __FILE__, $sql);
122 FROM ". SMILIES_TABLE;
123 if( !$result = $db->sql_query($sql) )
125 message_die(GENERAL_ERROR, "Couldn't get current smilies", "", __LINE__, __FILE__, $sql);
128 $cur_smilies = $db->sql_fetchrowset($result);
130 for( $i = 0; $i < count($cur_smilies); $i++ )
132 $k = $cur_smilies[$i]['code'];
137 $fcontents = @file($phpbb_root_path . $board_config['smilies_path'] . '/'. $smile_pak);
139 if( empty($fcontents) )
141 message_die(GENERAL_ERROR, "Couldn't read smiley pak file", "", __LINE__, __FILE__, $sql);
144 for( $i = 0; $i < count($fcontents); $i++ )
146 $smile_data = explode($delimeter, trim(addslashes($fcontents[$i])));
148 for( $j = 2; $j < count($smile_data); $j++)
151 // Replace > and < with the proper html_entities for matching.
153 $smile_data[$j] = str_replace("<", "<", $smile_data[$j]);
154 $smile_data[$j] = str_replace(">", ">", $smile_data[$j]);
155 $k = $smile_data[$j];
157 if( $smiles[$k] == 1 )
159 if( !empty($replace_existing) )
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]) . "'";
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]) . "')";
178 $result = $db->sql_query($sql);
181 message_die(GENERAL_ERROR, "Couldn't update smilies!", "", __LINE__, __FILE__, $sql);
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);
195 // Display the script to get the smile_pak cfg file...
197 $smile_paks_select = "<select name='smile_pak'><option value=''>" . $lang['Select_pak'] . "</option>";
198 while( list($key, $value) = @each($smiley_paks) )
200 if ( !empty($value) )
202 $smile_paks_select .= "<option>" . $value . "</option>";
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")
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)
229 $template->pparse("body");
232 else if( isset($HTTP_POST_VARS['export_pack']) || isset($HTTP_GET_VARS['export_pack']) )
235 // Export our smiley config as a smiley pak...
237 if ( $HTTP_GET_VARS['export_pack'] == "send" )
240 FROM " . SMILIES_TABLE;
241 if( !$result = $db->sql_query($sql) )
243 message_die(GENERAL_ERROR, "Could not get smiley list", "", __LINE__, __FILE__, $sql);
246 $resultset = $db->sql_fetchrowset($result);
249 for($i = 0; $i < count($resultset); $i++ )
251 $smile_pak .= $resultset[$i]['smile_url'] . $delimeter;
252 $smile_pak .= $resultset[$i]['emoticon'] . $delimeter;
253 $smile_pak .= $resultset[$i]['code'] . "\n";
256 header("Content-Type: text/x-delimtext; name=\"smiles.pak\"");
257 header("Content-disposition: attachment; filename=smiles.pak");
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']) )
272 // Admin has selected to add a smiley.
275 $template->set_filenames(array(
276 "body" => "admin/smile_edit_body.tpl")
280 for( $i = 0; $i < count($smiley_images); $i++ )
282 $filename_list .= '<option value="' . $smiley_images[$i] . '">' . $smiley_images[$i] . '</option>';
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'])
305 $template->pparse("body");
307 else if ( $mode != "" )
313 // Admin has selected to delete a smiley.
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);
324 message_die(GENERAL_ERROR, "Couldn't delete smiley", "", __LINE__, __FILE__, $sql);
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);
334 // Admin has selected to edit a smiley.
337 $smiley_id = ( !empty($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
338 $smiley_id = intval($smiley_id);
341 FROM " . SMILIES_TABLE . "
342 WHERE smilies_id = " . $smiley_id;
343 $result = $db->sql_query($sql);
346 message_die(GENERAL_ERROR, 'Could not obtain emoticon information', "", __LINE__, __FILE__, $sql);
348 $smile_data = $db->sql_fetchrow($result);
351 for( $i = 0; $i < count($smiley_images); $i++ )
353 if( $smiley_images[$i] == $smile_data['smile_url'] )
355 $smiley_selected = "selected=\"selected\"";
356 $smiley_edit_img = $smiley_images[$i];
360 $smiley_selected = "";
363 $filename_list .= '<option value="' . $smiley_images[$i] . '"' . $smiley_selected . '>' . $smiley_images[$i] . '</option>';
366 $template->set_filenames(array(
367 "body" => "admin/smile_edit_body.tpl")
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'])
393 $template->pparse("body");
398 // Admin has submitted changes while editing a smiley.
402 // Get the submitted data, being careful to ensure that we only
403 // accept the data we are looking for.
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 == '')
413 message_die(MESSAGE, $lang['Fields_empty']);
417 // Convert < and > to proper htmlentities for parsing.
419 $smile_code = str_replace('<', '<', $smile_code);
420 $smile_code = str_replace('>', '>', $smile_code);
423 // Proceed with updating the smiley table.
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)) )
430 message_die(GENERAL_ERROR, "Couldn't update smilies info", "", __LINE__, __FILE__, $sql);
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);
440 // Admin has submitted changes while adding a new smiley.
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.
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 == '')
454 message_die(MESSAGE, $lang['Fields_empty']);
458 // Convert < and > to proper htmlentities for parsing.
460 $smile_code = str_replace('<', '<', $smile_code);
461 $smile_code = str_replace('>', '>', $smile_code);
464 // Save the data to the smiley table.
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);
471 message_die(GENERAL_ERROR, "Couldn't insert new smiley", "", __LINE__, __FILE__, $sql);
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);
484 // This is the main display of the page before the admin has selected
488 FROM " . SMILIES_TABLE;
489 $result = $db->sql_query($sql);
492 message_die(GENERAL_ERROR, "Couldn't obtain smileys from database", "", __LINE__, __FILE__, $sql);
495 $smilies = $db->sql_fetchrowset($result);
497 $template->set_filenames(array(
498 "body" => "admin/smile_list_body.tpl")
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'],
514 "S_HIDDEN_FIELDS" => $s_hidden_fields,
515 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"))
519 // Loop throuh the rows of smilies setting block vars for the template.
521 for($i = 0; $i < count($smilies); $i++)
524 // Replace htmlentites for < and > with actual character.
526 $smilies[$i]['code'] = str_replace('<', '<', $smilies[$i]['code']);
527 $smilies[$i]['code'] = str_replace('>', '>', $smilies[$i]['code']);
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,
536 "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'],
537 "CODE" => $smilies[$i]['code'],
538 "EMOT" => $smilies[$i]['emoticon'],
540 "U_SMILEY_EDIT" => append_sid("admin_smilies.$phpEx?mode=edit&id=" . $smilies[$i]['smilies_id']),
541 "U_SMILEY_DELETE" => append_sid("admin_smilies.$phpEx?mode=delete&id=" . $smilies[$i]['smilies_id']))
546 // Spit out the page.
548 $template->pparse("body");
554 include('./page_footer_admin.'.$phpEx);