1 rizwank 1.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.12 2002/12/22 15:34:01 psotfx Exp $
10 *
11 ****************************************************************************/
12
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 ***************************************************************************/
21
22 rizwank 1.1 /**************************************************************************
23 * This file will be used for modifying the smiley settings for a board.
24 **************************************************************************/
25
26 define('IN_PHPBB', 1);
27
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;
35
36 return;
37 }
38
39 //
40 // Load default header
41 //
42 if( isset($HTTP_GET_VARS['export_pack']) )
43 rizwank 1.1 {
44 if ( $HTTP_GET_VARS['export_pack'] == "send" )
45 {
46 $no_page_header = true;
47 }
48 }
49
50 $phpbb_root_path = "./../";
51 require($phpbb_root_path . 'extension.inc');
52 require('./pagestart.' . $phpEx);
53
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 }
61 else
62 {
63 $mode = "";
64 rizwank 1.1 }
65
66 $delimeter = '=+:';
67
68 //
69 // Read a listing of uploaded smilies for use in the add or edit smliey code...
70 //
71 $dir = @opendir($phpbb_root_path . $board_config['smilies_path']);
72
73 while($file = @readdir($dir))
74 {
75 if( !@is_dir(phpbb_realpath($phpbb_root_path . $board_config['smilies_path'] . '/' . $file)) )
76 {
77 $img_size = @getimagesize($phpbb_root_path . $board_config['smilies_path'] . '/' . $file);
78
79 if( $img_size[0] && $img_size[1] )
80 {
81 $smiley_images[] = $file;
82 }
83 else if( eregi('.pak$', $file) )
84 {
85 rizwank 1.1 $smiley_paks[] = $file;
86 }
87 }
88 }
89
90 @closedir($dir);
91
92 //
93 // Select main mode
94 //
95 if( isset($HTTP_GET_VARS['import_pack']) || isset($HTTP_POST_VARS['import_pack']) )
96 {
97 //
98 // Import a list a "Smiley Pack"
99 //
100 $smile_pak = ( isset($HTTP_POST_VARS['smile_pak']) ) ? $HTTP_POST_VARS['smile_pak'] : $HTTP_GET_VARS['smile_pak'];
101 $clear_current = ( isset($HTTP_POST_VARS['clear_current']) ) ? $HTTP_POST_VARS['clear_current'] : $HTTP_GET_VARS['clear_current'];
102 $replace_existing = ( isset($HTTP_POST_VARS['replace']) ) ? $HTTP_POST_VARS['replace'] : $HTTP_GET_VARS['replace'];
103
104 if ( !empty($smile_pak) )
105 {
106 rizwank 1.1 //
107 // The user has already selected a smile_pak file.. Import it.
108 //
109 if( !empty($clear_current) )
110 {
111 $sql = "DELETE
112 FROM " . SMILIES_TABLE;
113 if( !$result = $db->sql_query($sql) )
114 {
115 message_die(GENERAL_ERROR, "Couldn't delete current smilies", "", __LINE__, __FILE__, $sql);
116 }
117 }
118 else
119 {
120 $sql = "SELECT code
121 FROM ". SMILIES_TABLE;
122 if( !$result = $db->sql_query($sql) )
123 {
124 message_die(GENERAL_ERROR, "Couldn't get current smilies", "", __LINE__, __FILE__, $sql);
125 }
126
127 rizwank 1.1 $cur_smilies = $db->sql_fetchrowset($result);
128
129 for( $i = 0; $i < count($cur_smilies); $i++ )
130 {
131 $k = $cur_smilies[$i]['code'];
132 $smiles[$k] = 1;
133 }
134 }
135
136 $fcontents = @file($phpbb_root_path . $board_config['smilies_path'] . '/'. $smile_pak);
137
138 if( empty($fcontents) )
139 {
140 message_die(GENERAL_ERROR, "Couldn't read smiley pak file", "", __LINE__, __FILE__, $sql);
141 }
142
143 for( $i = 0; $i < count($fcontents); $i++ )
144 {
145 $smile_data = explode($delimeter, trim(addslashes($fcontents[$i])));
146
147 for( $j = 2; $j < count($smile_data); $j++)
148 rizwank 1.1 {
149 //
150 // Replace > and < with the proper html_entities for matching.
151 //
152 $smile_data[$j] = str_replace("<", "<", $smile_data[$j]);
153 $smile_data[$j] = str_replace(">", ">", $smile_data[$j]);
154 $k = $smile_data[$j];
155
156 if( $smiles[$k] == 1 )
157 {
158 if( !empty($replace_existing) )
159 {
160 $sql = "UPDATE " . SMILIES_TABLE . "
161 SET smile_url = '" . str_replace("\'", "''", $smile_data[0]) . "', emoticon = '" . str_replace("\'", "''", $smile_data[1]) . "'
162 WHERE code = '" . str_replace("\'", "''", $smile_data[$j]) . "'";
163 }
164 else
165 {
166 $sql = '';
167 }
168 }
169 rizwank 1.1 else
170 {
171 $sql = "INSERT INTO " . SMILIES_TABLE . " (code, smile_url, emoticon)
172 VALUES('" . str_replace("\'", "''", $smile_data[$j]) . "', '" . str_replace("\'", "''", $smile_data[0]) . "', '" . str_replace("\'", "''", $smile_data[1]) . "')";
173 }
174
175 if( $sql != '' )
176 {
177 $result = $db->sql_query($sql);
178 if( !$result )
179 {
180 message_die(GENERAL_ERROR, "Couldn't update smilies!", "", __LINE__, __FILE__, $sql);
181 }
182 }
183 }
184 }
185
186 $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>");
187
188 message_die(GENERAL_MESSAGE, $message);
189
190 rizwank 1.1 }
191 else
192 {
193 //
194 // Display the script to get the smile_pak cfg file...
195 //
196 $smile_paks_select = "<select name='smile_pak'><option value=''>" . $lang['Select_pak'] . "</option>";
197 while( list($key, $value) = @each($smiley_paks) )
198 {
199 if ( !empty($value) )
200 {
201 $smile_paks_select .= "<option>" . $value . "</option>";
202 }
203 }
204 $smile_paks_select .= "</select>";
205
206 $hidden_vars = "<input type='hidden' name='mode' value='import'>";
207
208 $template->set_filenames(array(
209 "body" => "admin/smile_import_body.tpl")
210 );
211 rizwank 1.1
212 $template->assign_vars(array(
213 "L_SMILEY_TITLE" => $lang['smiley_title'],
214 "L_SMILEY_EXPLAIN" => $lang['smiley_import_inst'],
215 "L_SMILEY_IMPORT" => $lang['smiley_import'],
216 "L_SELECT_LBL" => $lang['choose_smile_pak'],
217 "L_IMPORT" => $lang['import'],
218 "L_CONFLICTS" => $lang['smile_conflicts'],
219 "L_DEL_EXISTING" => $lang['del_existing_smileys'],
220 "L_REPLACE_EXISTING" => $lang['replace_existing'],
221 "L_KEEP_EXISTING" => $lang['keep_existing'],
222
223 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
224 "S_SMILE_SELECT" => $smile_paks_select,
225 "S_HIDDEN_FIELDS" => $hidden_vars)
226 );
227
228 $template->pparse("body");
229 }
230 }
231 else if( isset($HTTP_POST_VARS['export_pack']) || isset($HTTP_GET_VARS['export_pack']) )
232 rizwank 1.1 {
233 //
234 // Export our smiley config as a smiley pak...
235 //
236 if ( $HTTP_GET_VARS['export_pack'] == "send" )
237 {
238 $sql = "SELECT *
239 FROM " . SMILIES_TABLE;
240 if( !$result = $db->sql_query($sql) )
241 {
242 message_die(GENERAL_ERROR, "Could not get smiley list", "", __LINE__, __FILE__, $sql);
243 }
244
245 $resultset = $db->sql_fetchrowset($result);
246
247 $smile_pak = "";
248 for($i = 0; $i < count($resultset); $i++ )
249 {
250 $smile_pak .= $resultset[$i]['smile_url'] . $delimeter;
251 $smile_pak .= $resultset[$i]['emoticon'] . $delimeter;
252 $smile_pak .= $resultset[$i]['code'] . "\n";
253 rizwank 1.1 }
254
255 header("Content-Type: text/x-delimtext; name=\"smiles.pak\"");
256 header("Content-disposition: attachment; filename=smiles.pak");
257
258 echo $smile_pak;
259
260 exit;
261 }
262
263 $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>");
264
265 message_die(GENERAL_MESSAGE, $message);
266
267 }
268 else if( isset($HTTP_POST_VARS['add']) || isset($HTTP_GET_VARS['add']) )
269 {
270 //
271 // Admin has selected to add a smiley.
272 //
273
274 rizwank 1.1 $template->set_filenames(array(
275 "body" => "admin/smile_edit_body.tpl")
276 );
277
278 $filename_list = "";
279 for( $i = 0; $i < count($smiley_images); $i++ )
280 {
281 $filename_list .= '<option value="' . $smiley_images[$i] . '">' . $smiley_images[$i] . '</option>';
282 }
283
284 $s_hidden_fields = '<input type="hidden" name="mode" value="savenew" />';
285
286 $template->assign_vars(array(
287 "L_SMILEY_TITLE" => $lang['smiley_title'],
288 "L_SMILEY_CONFIG" => $lang['smiley_config'],
289 "L_SMILEY_EXPLAIN" => $lang['smile_desc'],
290 "L_SMILEY_CODE" => $lang['smiley_code'],
291 "L_SMILEY_URL" => $lang['smiley_url'],
292 "L_SMILEY_EMOTION" => $lang['smiley_emot'],
293 "L_SUBMIT" => $lang['Submit'],
294 "L_RESET" => $lang['Reset'],
295 rizwank 1.1
296 "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smiley_images[0],
297
298 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
299 "S_HIDDEN_FIELDS" => $s_hidden_fields,
300 "S_FILENAME_OPTIONS" => $filename_list,
301 "S_SMILEY_BASEDIR" => $phpbb_root_path . $board_config['smilies_path'])
302 );
303
304 $template->pparse("body");
305 }
306 else if ( $mode != "" )
307 {
308 switch( $mode )
309 {
310 case 'delete':
311 //
312 // Admin has selected to delete a smiley.
313 //
314
315 $smiley_id = ( !empty($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
316 rizwank 1.1
317 $sql = "DELETE FROM " . SMILIES_TABLE . "
318 WHERE smilies_id = " . $smiley_id;
319 $result = $db->sql_query($sql);
320 if( !$result )
321 {
322 message_die(GENERAL_ERROR, "Couldn't delete smiley", "", __LINE__, __FILE__, $sql);
323 }
324
325 $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>");
326
327 message_die(GENERAL_MESSAGE, $message);
328 break;
329
330 case 'edit':
331 //
332 // Admin has selected to edit a smiley.
333 //
334
335 $smiley_id = ( !empty($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
336
337 rizwank 1.1 $sql = "SELECT *
338 FROM " . SMILIES_TABLE . "
339 WHERE smilies_id = " . $smiley_id;
340 $result = $db->sql_query($sql);
341 if( !$result )
342 {
343 message_die(GENERAL_ERROR, 'Could not obtain emoticon information', "", __LINE__, __FILE__, $sql);
344 }
345 $smile_data = $db->sql_fetchrow($result);
346
347 $filename_list = "";
348 for( $i = 0; $i < count($smiley_images); $i++ )
349 {
350 if( $smiley_images[$i] == $smile_data['smile_url'] )
351 {
352 $smiley_selected = "selected=\"selected\"";
353 $smiley_edit_img = $smiley_images[$i];
354 }
355 else
356 {
357 $smiley_selected = "";
358 rizwank 1.1 }
359
360 $filename_list .= '<option value="' . $smiley_images[$i] . '"' . $smiley_selected . '>' . $smiley_images[$i] . '</option>';
361 }
362
363 $template->set_filenames(array(
364 "body" => "admin/smile_edit_body.tpl")
365 );
366
367 $s_hidden_fields = '<input type="hidden" name="mode" value="save" /><input type="hidden" name="smile_id" value="' . $smile_data['smilies_id'] . '" />';
368
369 $template->assign_vars(array(
370 "SMILEY_CODE" => $smile_data['code'],
371 "SMILEY_EMOTICON" => $smile_data['emoticon'],
372
373 "L_SMILEY_TITLE" => $lang['smiley_title'],
374 "L_SMILEY_CONFIG" => $lang['smiley_config'],
375 "L_SMILEY_EXPLAIN" => $lang['smile_desc'],
376 "L_SMILEY_CODE" => $lang['smiley_code'],
377 "L_SMILEY_URL" => $lang['smiley_url'],
378 "L_SMILEY_EMOTION" => $lang['smiley_emot'],
379 rizwank 1.1 "L_SUBMIT" => $lang['Submit'],
380 "L_RESET" => $lang['Reset'],
381
382 "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smiley_edit_img,
383
384 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
385 "S_HIDDEN_FIELDS" => $s_hidden_fields,
386 "S_FILENAME_OPTIONS" => $filename_list,
387 "S_SMILEY_BASEDIR" => $phpbb_root_path . $board_config['smilies_path'])
388 );
389
390 $template->pparse("body");
391 break;
392
393 case "save":
394 //
395 // Admin has submitted changes while editing a smiley.
396 //
397
398 //
399 // Get the submitted data, being careful to ensure that we only
400 rizwank 1.1 // accept the data we are looking for.
401 //
402 $smile_code = ( isset($HTTP_POST_VARS['smile_code']) ) ? trim($HTTP_POST_VARS['smile_code']) : trim($HTTP_GET_VARS['smile_code']);
403 $smile_url = ( isset($HTTP_POST_VARS['smile_url']) ) ? trim($HTTP_POST_VARS['smile_url']) : trim($HTTP_GET_VARS['smile_url']);
404 $smile_emotion = ( isset($HTTP_POST_VARS['smile_emotion']) ) ? trim($HTTP_POST_VARS['smile_emotion']) : trim($HTTP_GET_VARS['smile_emotion']);
405 $smile_id = ( isset($HTTP_POST_VARS['smile_id']) ) ? intval($HTTP_POST_VARS['smile_id']) : intval($HTTP_GET_VARS['smile_id']);
406
407 // If no code was entered complain ...
408 if ($smile_code == '' || $smile_url == '')
409 {
410 message_die(MESSAGE, $lang['Fields_empty']);
411 }
412
413 //
414 // Convert < and > to proper htmlentities for parsing.
415 //
416 $smile_code = str_replace('<', '<', $smile_code);
417 $smile_code = str_replace('>', '>', $smile_code);
418
419 //
420 // Proceed with updating the smiley table.
421 rizwank 1.1 //
422 $sql = "UPDATE " . SMILIES_TABLE . "
423 SET code = '" . str_replace("\'", "''", $smile_code) . "', smile_url = '" . str_replace("\'", "''", $smile_url) . "', emoticon = '" . str_replace("\'", "''", $smile_emotion) . "'
424 WHERE smilies_id = $smile_id";
425 if( !($result = $db->sql_query($sql)) )
426 {
427 message_die(GENERAL_ERROR, "Couldn't update smilies info", "", __LINE__, __FILE__, $sql);
428 }
429
430 $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>");
431
432 message_die(GENERAL_MESSAGE, $message);
433 break;
434
435 case "savenew":
436 //
437 // Admin has submitted changes while adding a new smiley.
438 //
439
440 //
441 // Get the submitted data being careful to ensure the the data
442 rizwank 1.1 // we recieve and process is only the data we are looking for.
443 //
444 $smile_code = ( isset($HTTP_POST_VARS['smile_code']) ) ? $HTTP_POST_VARS['smile_code'] : $HTTP_GET_VARS['smile_code'];
445 $smile_url = ( isset($HTTP_POST_VARS['smile_url']) ) ? $HTTP_POST_VARS['smile_url'] : $HTTP_GET_VARS['smile_url'];
446 $smile_emotion = ( isset($HTTP_POST_VARS['smile_emotion']) ) ? $HTTP_POST_VARS['smile_emotion'] : $HTTP_GET_VARS['smile_emotion'];
447
448 // If no code was entered complain ...
449 if ($smile_code == '' || $smile_url == '')
450 {
451 message_die(MESSAGE, $lang['Fields_empty']);
452 }
453
454 //
455 // Convert < and > to proper htmlentities for parsing.
456 //
457 $smile_code = str_replace('<', '<', $smile_code);
458 $smile_code = str_replace('>', '>', $smile_code);
459
460 //
461 // Save the data to the smiley table.
462 //
463 rizwank 1.1 $sql = "INSERT INTO " . SMILIES_TABLE . " (code, smile_url, emoticon)
464 VALUES ('" . str_replace("\'", "''", $smile_code) . "', '" . str_replace("\'", "''", $smile_url) . "', '" . str_replace("\'", "''", $smile_emotion) . "')";
465 $result = $db->sql_query($sql);
466 if( !$result )
467 {
468 message_die(GENERAL_ERROR, "Couldn't insert new smiley", "", __LINE__, __FILE__, $sql);
469 }
470
471 $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>");
472
473 message_die(GENERAL_MESSAGE, $message);
474 break;
475 }
476 }
477 else
478 {
479
480 //
481 // This is the main display of the page before the admin has selected
482 // any options.
483 //
484 rizwank 1.1 $sql = "SELECT *
485 FROM " . SMILIES_TABLE;
486 $result = $db->sql_query($sql);
487 if( !$result )
488 {
489 message_die(GENERAL_ERROR, "Couldn't obtain smileys from database", "", __LINE__, __FILE__, $sql);
490 }
491
492 $smilies = $db->sql_fetchrowset($result);
493
494 $template->set_filenames(array(
495 "body" => "admin/smile_list_body.tpl")
496 );
497
498 $template->assign_vars(array(
499 "L_ACTION" => $lang['Action'],
500 "L_SMILEY_TITLE" => $lang['smiley_title'],
501 "L_SMILEY_TEXT" => $lang['smile_desc'],
502 "L_DELETE" => $lang['Delete'],
503 "L_EDIT" => $lang['Edit'],
504 "L_SMILEY_ADD" => $lang['smile_add'],
505 rizwank 1.1 "L_CODE" => $lang['Code'],
506 "L_EMOT" => $lang['Emotion'],
507 "L_SMILE" => $lang['Smile'],
508 "L_IMPORT_PACK" => $lang['import_smile_pack'],
509 "L_EXPORT_PACK" => $lang['export_smile_pack'],
510
511 "S_HIDDEN_FIELDS" => $s_hidden_fields,
512 "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"))
513 );
514
515 //
516 // Loop throuh the rows of smilies setting block vars for the template.
517 //
518 for($i = 0; $i < count($smilies); $i++)
519 {
520 //
521 // Replace htmlentites for < and > with actual character.
522 //
523 $smilies[$i]['code'] = str_replace('<', '<', $smilies[$i]['code']);
524 $smilies[$i]['code'] = str_replace('>', '>', $smilies[$i]['code']);
525
526 rizwank 1.1 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
527 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
528
529 $template->assign_block_vars("smiles", array(
530 "ROW_COLOR" => "#" . $row_color,
531 "ROW_CLASS" => $row_class,
532
533 "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'],
534 "CODE" => $smilies[$i]['code'],
535 "EMOT" => $smilies[$i]['emoticon'],
536
537 "U_SMILEY_EDIT" => append_sid("admin_smilies.$phpEx?mode=edit&id=" . $smilies[$i]['smilies_id']),
538 "U_SMILEY_DELETE" => append_sid("admin_smilies.$phpEx?mode=delete&id=" . $smilies[$i]['smilies_id']))
539 );
540 }
541
542 //
543 // Spit out the page.
544 //
545 $template->pparse("body");
546 }
547 rizwank 1.1
548 //
549 // Page Footer
550 //
551 include('./page_footer_admin.'.$phpEx);
552
553 ?>
|