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