| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
<span class="code-comment">* 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.16 2005/10/30 15:17:13 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 |
// |
|---|
| 27 |
// First we do the setmodules stuff for the admin cp. |
|---|
| 28 |
// |
|---|
| 29 |
if( !empty($setmodules) )</span> |
|---|
| 30 |
<span class="code-keyword">{ |
|---|
| 31 |
$filename = basename(__FILE__); |
|---|
| 32 |
$module['general']['smilies'] = $filename; |
|---|
| 33 |
|
|---|
| 34 |
return; |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
define('IN_PHPBB', 1); |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
<span class="code-comment">// Load default header |
|---|
| 41 |
// |
|---|
| 42 |
if( isset($_GET['export_pack']) && $_GET['export_pack'] == "send" )</span> |
|---|
| 43 |
<span class="code-keyword">{ |
|---|
| 44 |
$no_page_header = true; |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
$root_path = './../';</span> |
|---|
| 48 |
<span class="code-lang">require($root_path . 'extension.inc'); |
|---|
| 49 |
require($root_path . 'include/functions_check.' . $phpEx); |
|---|
| 50 |
require('./pagestart.' . $phpEx); |
|---|
| 51 |
$cancel = ( isset($_POST['cancel']) ) ? true : false; |
|---|
| 52 |
$no_page_header = $cancel;</span> |
|---|
| 53 |
<span class="code-lang"> |
|---|
| 54 |
include($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_smilies_upload.' . $phpEx); |
|---|
| 55 |
|
|---|
| 56 |
if ($cancel) |
|---|
| 57 |
{ |
|---|
| 58 |
redirect('admin/' . append_sid("admin_smilies.$phpEx")); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
<span class="code-comment">// Check to see what mode we should operate in. |
|---|
| 63 |
// |
|---|
| 64 |
if( isset($_POST['mode']) || isset($_GET['mode']) )</span> |
|---|
| 65 |
<span class="code-keyword">{ |
|---|
| 66 |
$mode = ( isset($_POST['mode']) ) ? $_POST['mode'] : $_GET['mode']; |
|---|
| 67 |
$mode = htmlspecialchars($mode); |
|---|
| 68 |
} |
|---|
| 69 |
else |
|---|
| 70 |
{ |
|---|
| 71 |
$mode = ""; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
$delimeter = '=+:'; |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
<span class="code-comment">// Read a listing of uploaded smilies for use in the add or edit smliey code... |
|---|
| 78 |
// |
|---|
| 79 |
$dir = @opendir($root_path . $config['smilies_path']);</span> |
|---|
| 80 |
<span class="code-lang"> |
|---|
| 81 |
while($file = @readdir($dir)) |
|---|
| 82 |
{ |
|---|
| 83 |
if( !@is_dir(phpbb_realpath($root_path . $config['smilies_path'] . '/' . $file)) ) |
|---|
| 84 |
{ |
|---|
| 85 |
$img_size = @getimagesize($root_path . $config['smilies_path'] . '/' . $file); |
|---|
| 86 |
|
|---|
| 87 |
if( $img_size[0] && $img_size[1] ) |
|---|
| 88 |
{ |
|---|
| 89 |
$smiley_images[] = $file; |
|---|
| 90 |
} |
|---|
| 91 |
else if( eregi('.pak$', $file) ) |
|---|
| 92 |
{ |
|---|
| 93 |
$smiley_paks[] = $file; |
|---|
| 94 |
} |
|---|
| 95 |
} |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
@closedir($dir); |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
<span class="code-comment">// Select main mode |
|---|
| 102 |
// |
|---|
| 103 |
if( isset($_GET['import_pack']) || isset($_POST['import_pack']) )</span> |
|---|
| 104 |
<span class="code-keyword">{ |
|---|
| 105 |
|
|---|
| 106 |
// Import a list a "Smiley Pack" |
|---|
| 107 |
// |
|---|
| 108 |
$smile_pak = ( isset($_POST['smile_pak']) ) ? $_POST['smile_pak'] : $_GET['smile_pak']; |
|---|
| 109 |
$clear_current = ( isset($_POST['clear_current']) ) ? $_POST['clear_current'] : $_GET['clear_current']; |
|---|
| 110 |
$replace_existing = ( isset($_POST['replace']) ) ? $_POST['replace'] : $_GET['replace']; |
|---|
| 111 |
|
|---|
| 112 |
if ( !empty($smile_pak) ) |
|---|
| 113 |
{ |
|---|
| 114 |
|
|---|
| 115 |
// The user has already selected a smile_pak file.. Import it. |
|---|
| 116 |
// |
|---|
| 117 |
if( !empty($clear_current) ) |
|---|
| 118 |
{ |
|---|
| 119 |
$sql = "DELETE |
|---|
| 120 |
FROM " . SMILIES_TABLE; |
|---|
| 121 |
$db->sql_query($sql); |
|---|
| 122 |
$cache->destroy('_smilies'); |
|---|
| 123 |
} |
|---|
| 124 |
else |
|---|
| 125 |
{ |
|---|
| 126 |
$sql = "SELECT code |
|---|
| 127 |
FROM ". SMILIES_TABLE; |
|---|
| 128 |
$result = $db->sql_query($sql); |
|---|
| 129 |
|
|---|
| 130 |
$cur_smilies = $db->sql_fetchrowset($result); |
|---|
| 131 |
|
|---|
| 132 |
for( $i = 0; $i < count($cur_smilies); $i++ ) |
|---|
| 133 |
{ |
|---|
| 134 |
$k = $cur_smilies[$i]['code']; |
|---|
| 135 |
$smiles[$k] = 1; |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
$fcontents = @file($root_path . $config['smilies_path'] . '/'. $smile_pak); |
|---|
| 140 |
|
|---|
| 141 |
if( empty($fcontents) ) |
|---|
| 142 |
{ |
|---|
| 143 |
trigger_error("Couldn't read smiley pak file"); |
|---|
| 144 |
return; |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
for( $i = 0; $i < count($fcontents); $i++ ) |
|---|
| 148 |
{ |
|---|
| 149 |
$smile_data = explode($delimeter, trim(addslashes($fcontents[$i]))); |
|---|
| 150 |
|
|---|
| 151 |
for( $j = 2; $j < count($smile_data); $j++) |
|---|
| 152 |
{ |
|---|
| 153 |
|
|---|
| 154 |
// Replace > and < with the proper html_entities for matching. |
|---|
| 155 |
// |
|---|
| 156 |
$smile_data[$j] = str_replace("<", "<", $smile_data[$j]); |
|---|
| 157 |
$smile_data[$j] = str_replace(">", ">", $smile_data[$j]); |
|---|
| 158 |
$k = $smile_data[$j]; |
|---|
| 159 |
|
|---|
| 160 |
if( $smiles[$k] == 1 ) |
|---|
| 161 |
{ |
|---|
| 162 |
if( !empty($replace_existing) ) |
|---|
| 163 |
{ |
|---|
| 164 |
$sql = "UPDATE " . SMILIES_TABLE . " |
|---|
| 165 |
SET smile_url = '" . str_replace("\'", "''", $smile_data[0]) . "', emoticon = '" . str_replace("\'", "''", $smile_data[1]) . "' |
|---|
| 166 |
WHERE code = '" . str_replace("\'", "''", $smile_data[$j]) . "'"; |
|---|
| 167 |
} |
|---|
| 168 |
else |
|---|
| 169 |
{ |
|---|
| 170 |
$sql = ''; |
|---|
| 171 |
} |
|---|
| 172 |
} |
|---|
| 173 |
else |
|---|
| 174 |
{ |
|---|
| 175 |
$sql = "INSERT INTO " . SMILIES_TABLE . " (code, smile_url, emoticon) |
|---|
| 176 |
VALUES('" . str_replace("\'", "''", $smile_data[$j]) . "', '" . str_replace("\'", "''", $smile_data[0]) . "', '" . str_replace("\'", "''", $smile_data[1]) . "')"; |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
if( $sql != '' ) |
|---|
| 180 |
{ |
|---|
| 181 |
$result = $db->sql_query($sql); |
|---|
| 182 |
$cache->destroy('_smilies'); |
|---|
| 183 |
} |
|---|
| 184 |
} |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 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>"); |
|---|
| 188 |
|
|---|
| 189 |
trigger_error($message); |
|---|
| 190 |
return; |
|---|
| 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->display("body"); |
|---|
| 231 |
} |
|---|
| 232 |
} |
|---|
| 233 |
else if( isset($_POST['export_pack']) || isset($_GET['export_pack']) ) |
|---|
| 234 |
{ |
|---|
| 235 |
|
|---|
| 236 |
// Export our smiley config as a smiley pak... |
|---|
| 237 |
// |
|---|
| 238 |
if ( $_GET['export_pack'] == "send" ) |
|---|
| 239 |
{ |
|---|
| 240 |
$sql = "SELECT * |
|---|
| 241 |
FROM " . SMILIES_TABLE; |
|---|
| 242 |
$result = $db->sql_query($sql); |
|---|
| 243 |
|
|---|
| 244 |
$resultset = $db->sql_fetchrowset($result); |
|---|
| 245 |
|
|---|
| 246 |
$smile_pak = ""; |
|---|
| 247 |
for($i = 0; $i < count($resultset); $i++ ) |
|---|
| 248 |
{ |
|---|
| 249 |
$smile_pak .= $resultset[$i]['smile_url'] . $delimeter; |
|---|
| 250 |
$smile_pak .= $resultset[$i]['emoticon'] . $delimeter; |
|---|
| 251 |
$smile_pak .= $resultset[$i]['code'] . "\n"; |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
header("Content-Type: text/x-delimtext; name=\"smiles.pak\""); |
|---|
| 255 |
header("Content-disposition: attachment; filename=smiles.pak"); |
|---|
| 256 |
|
|---|
| 257 |
gc($smile_pak); |
|---|
| 258 |
} |
|---|
| 259 |
|
|---|
| 260 |
$message = sprintf($lang['export_smiles'], "<a href=\"" . append_sid("admin_smilies.$phpEx?export_pack=send") . "\">", "</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>"); |
|---|
| 261 |
|
|---|
| 262 |
trigger_error($message); |
|---|
| 263 |
return; |
|---|
| 264 |
|
|---|
| 265 |
} |
|---|
| 266 |
else if( isset($_POST['upload']) || isset($_GET['upload']) ) |
|---|
| 267 |
{ |
|---|
| 268 |
|
|---|
| 269 |
// Admin has selected to add a smiley. |
|---|
| 270 |
// |
|---|
| 271 |
|
|---|
| 272 |
$template->set_filenames(array( |
|---|
| 273 |
"body" => "../admin/smilie_upload_body.tpl") |
|---|
| 274 |
); |
|---|
| 275 |
|
|---|
| 276 |
$ini_val = ( phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var'; |
|---|
| 277 |
$form_enctype = ( @$ini_val('file_uploads') == '0' || strtolower(@$ini_val('file_uploads') == 'off') || phpversion() == '4.0.4pl1' || ( phpversion() < '4.0.3' && @$ini_val('open_basedir') != '' ) ) ? '' : 'enctype="multipart/form-data"'; |
|---|
| 278 |
|
|---|
| 279 |
if( !empty($form_enctype) ) { |
|---|
| 280 |
$template->assign_block_vars('switch_uploads', array()); |
|---|
| 281 |
} |
|---|
| 282 |
else { |
|---|
| 283 |
$template->assign_block_vars('switch_no_uploads', array( |
|---|
| 284 |
'L_SORRY' => $lang['su_sorry'] ) |
|---|
| 285 |
); |
|---|
| 286 |
} |
|---|
| 287 |
|
|---|
| 288 |
$s_hidden_fields = '<input type="hidden" name="mode" value="addnew" />'; |
|---|
| 289 |
|
|---|
| 290 |
$template->assign_vars(array( |
|---|
| 291 |
"S_FORM_ENCTYPE" => $form_enctype, |
|---|
| 292 |
'S_PROFILE_ACTION' => append_sid('admin_smilies.' . $phpEx), |
|---|
| 293 |
'L_SMILIES_UPLOAD' => $lang['su_upload_smilies'], |
|---|
| 294 |
'L_UPLOAD_EXPLAIN' => $lang['su_upload_explain'], |
|---|
| 295 |
'L_UPLOAD_FILE' => $lang['su_file'], |
|---|
| 296 |
'L_UPLOAD_NAME' => $lang['su_upload_name'], |
|---|
| 297 |
'L_DEFAULT_NAME' => $lang['su_default_name'], |
|---|
| 298 |
'L_NAME_EXPLAIN' => $lang['su_name_explain'], |
|---|
| 299 |
'L_UPLOADED_SMILIES' => $lang['su_uploaded'], |
|---|
| 300 |
'L_AUTO_ADD' => $lang['su_auto_add'], |
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
"S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"), |
|---|
| 304 |
"S_HIDDEN_FIELDS" => $s_hidden_fields) |
|---|
| 305 |
); |
|---|
| 306 |
|
|---|
| 307 |
$template->display("body"); |
|---|
| 308 |
} |
|---|
| 309 |
else if ( $mode != "" ) |
|---|
| 310 |
{ |
|---|
| 311 |
switch( $mode ) |
|---|
| 312 |
{ |
|---|
| 313 |
case 'delete': |
|---|
| 314 |
|
|---|
| 315 |
// Admin has selected to delete a smiley. |
|---|
| 316 |
// |
|---|
| 317 |
|
|---|
| 318 |
$smiley_id = ( !empty($_POST['id']) ) ? intval($_POST['id']) : intval($_GET['id']); |
|---|
| 319 |
|
|---|
| 320 |
$confirm = isset($_POST['confirm']); |
|---|
| 321 |
|
|---|
| 322 |
if( $confirm ) |
|---|
| 323 |
{ |
|---|
| 324 |
$sql = 'SELECT smile_url FROM ' . SMILIES_TABLE . ' WHERE smilies_id = ' . $smiley_id; |
|---|
| 325 |
$result = $db->sql_query($sql); |
|---|
| 326 |
$smile_data = $db->sql_fetchrow($result); |
|---|
| 327 |
|
|---|
| 328 |
$sql = 'DELETE FROM ' . SMILIES_TABLE . ' WHERE smilies_id = ' . $smiley_id; |
|---|
| 329 |
$db->sql_query($sql); |
|---|
| 330 |
@unlink($root_path . $config['smilies_path'] . '/' . $smile_data['smile_url']); |
|---|
| 331 |
$message = $lang['smiley_del_success']; |
|---|
| 332 |
|
|---|
| 333 |
$cache->destroy('_smilies'); |
|---|
| 334 |
$message = $message . "<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>"); |
|---|
| 335 |
trigger_error($message); |
|---|
| 336 |
|
|---|
| 337 |
} |
|---|
| 338 |
else |
|---|
| 339 |
{ |
|---|
| 340 |
|
|---|
| 341 |
$template->set_filenames(array( |
|---|
| 342 |
'body' => '../admin/confirm_body.tpl') |
|---|
| 343 |
); |
|---|
| 344 |
|
|---|
| 345 |
$hidden_fields = '<input type="hidden" name="mode" value="delete" /><input type="hidden" name="id" value="' . $smiley_id . '" />'; |
|---|
| 346 |
|
|---|
| 347 |
$template->assign_vars(array( |
|---|
| 348 |
'MESSAGE_TITLE' => $lang['confirm'], |
|---|
| 349 |
'MESSAGE_TEXT' => $lang['confirm_delete_smiley'], |
|---|
| 350 |
|
|---|
| 351 |
'L_YES' => $lang['yes'], |
|---|
| 352 |
'L_NO' => $lang['no'], |
|---|
| 353 |
|
|---|
| 354 |
'S_CONFIRM_ACTION' => append_sid("admin_smilies.$phpEx"), |
|---|
| 355 |
'S_HIDDEN_FIELDS' => $hidden_fields) |
|---|
| 356 |
); |
|---|
| 357 |
$template->display('body'); |
|---|
| 358 |
} |
|---|
| 359 |
return; |
|---|
| 360 |
break; |
|---|
| 361 |
|
|---|
| 362 |
case 'edit': |
|---|
| 363 |
|
|---|
| 364 |
// Admin has selected to edit a smiley. |
|---|
| 365 |
// |
|---|
| 366 |
foreach( $_POST AS $key => $value ) { |
|---|
| 367 |
if ( preg_match('/^smile_id_(\d+)$/', $key, $match) ) { |
|---|
| 368 |
$smile_id = $match[1]; |
|---|
| 369 |
$smile_code = ( isset($_POST['smile_id_code_' . $smile_id]) ? trim($_POST['smile_id_code_' . $smile_id]) : '' ); |
|---|
| 370 |
$smile_emotion = ( isset($_POST['smile_id_desc_' . $smile_id]) ? htmlspecialchars(trim($_POST['smile_id_desc_' . $smile_id])) : '' ); |
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
if ( $smile_code == '' ) |
|---|
| 374 |
{ |
|---|
| 375 |
trigger_error($lang['fields_empty']); |
|---|
| 376 |
return; |
|---|
| 377 |
} |
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
// Convert < and > to proper htmlentities for parsing. |
|---|
| 381 |
// |
|---|
| 382 |
$smile_code = str_replace('<', '<', $smile_code); |
|---|
| 383 |
$smile_code = str_replace('>', '>', $smile_code); |
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
// Proceed with updating the smiley table. |
|---|
| 387 |
// |
|---|
| 388 |
$sql = "UPDATE " . SMILIES_TABLE . " |
|---|
| 389 |
SET code = '" . $db->sql_escape($smile_code) . "', emoticon = '" . $db->sql_escape($smile_emotion) . "' |
|---|
| 390 |
WHERE smilies_id = $smile_id"; |
|---|
| 391 |
$db->sql_query($sql); |
|---|
| 392 |
} |
|---|
| 393 |
} |
|---|
| 394 |
$cache->destroy('_smilies'); |
|---|
| 395 |
|
|---|
| 396 |
$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>"); |
|---|
| 397 |
|
|---|
| 398 |
trigger_error ($message); |
|---|
| 399 |
|
|---|
| 400 |
break; |
|---|
| 401 |
|
|---|
| 402 |
case "savenew": |
|---|
| 403 |
|
|---|
| 404 |
// Admin has submitted changes while adding a new smiley. |
|---|
| 405 |
// |
|---|
| 406 |
|
|---|
| 407 |
// |
|---|
| 408 |
// Get the submitted data being careful to ensure the the data |
|---|
| 409 |
// we recieve and process is only the data we are looking for. |
|---|
| 410 |
// |
|---|
| 411 |
$smile_code = ( isset($_POST['smile_code']) ) ? $_POST['smile_code'] : ''; |
|---|
| 412 |
$smile_url = ( isset($_POST['smile_url']) ) ? $_POST['smile_url'] : ''; |
|---|
| 413 |
$smile_url = phpbb_ltrim(basename($smile_url), "'"); |
|---|
| 414 |
$smile_emotion = ( isset($_POST['smile_emotion']) ) ? htmlspecialchars(trim($_POST['smile_emotion'])) : ''; |
|---|
| 415 |
$smile_code = trim($smile_code); |
|---|
| 416 |
$smile_url = trim($smile_url); |
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
if ($smile_code == '' || $smile_url == '') |
|---|
| 420 |
{ |
|---|
| 421 |
trigger_error($lang['fields_empty']); |
|---|
| 422 |
return; |
|---|
| 423 |
} |
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
// Convert < and > to proper htmlentities for parsing. |
|---|
| 427 |
// |
|---|
| 428 |
$smile_code = str_replace('<', '<', $smile_code); |
|---|
| 429 |
$smile_code = str_replace('>', '>', $smile_code); |
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
// Save the data to the smiley table. |
|---|
| 433 |
// |
|---|
| 434 |
$sql = "INSERT INTO " . SMILIES_TABLE . " (code, smile_url, emoticon) |
|---|
| 435 |
VALUES ('" . str_replace("\'", "''", $smile_code) . "', '" . str_replace("\'", "''", $smile_url) . "', '" . str_replace("\'", "''", $smile_emotion) . "')"; |
|---|
| 436 |
$db->sql_query($sql); |
|---|
| 437 |
|
|---|
| 438 |
$cache->destroy('_smilies'); |
|---|
| 439 |
|
|---|
| 440 |
$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>"); |
|---|
| 441 |
|
|---|
| 442 |
trigger_error($message); |
|---|
| 443 |
return; |
|---|
| 444 |
break; |
|---|
| 445 |
case "addnew": |
|---|
| 446 |
|
|---|
| 447 |
$emoticon = ( isset($_POST['emoticon']) ? trim(htmlspecialchars($_POST['emoticon'])) : '' ); |
|---|
| 448 |
$code = ( isset($_POST['code']) ? trim(htmlspecialchars($_POST['code'])) : '' ); |
|---|
| 449 |
$temp = str_replace(array('<', '>'), array('<', '>'), array($code, $emoticon)); |
|---|
| 450 |
$code = $temp[0]; |
|---|
| 451 |
$emoticon = $temp[1]; |
|---|
| 452 |
|
|---|
| 453 |
if ( !$code || !$emoticon ) { |
|---|
| 454 |
trigger_error($lang['su_cc_fail']); |
|---|
| 455 |
} |
|---|
| 456 |
|
|---|
| 457 |
$image_file = ( isset($_FILES['imagefile']) ? $_FILES['imagefile'] : '' ); |
|---|
| 458 |
$uploaded_filename = check_upload_image($image_file, $config['smilies_path'] . '/'); |
|---|
| 459 |
$uploaded_filename = $uploaded_filename['filename']; |
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
$sql = 'SELECT COUNT(*) AS count FROM ' . SMILIES_TABLE . ' WHERE code = \'' . str_replace("\'", "''", $code) . '\''; |
|---|
| 463 |
$result = $db->sql_query($sql); |
|---|
| 464 |
$row = $db->sql_fetchrow($result); |
|---|
| 465 |
if( $row['count'] ) { |
|---|
| 466 |
trigger_error($lang['su_cc_found']); |
|---|
| 467 |
} |
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
$sql = 'INSERT INTO ' . SMILIES_TABLE . " (code, smile_url, emoticon) |
|---|
| 471 |
VALUES ('" . str_replace("\'", "''", $code) . "', '" . str_replace("\'", "''", $uploaded_filename) . "', '" . str_replace("\'", "''", $emoticon) . "')"; |
|---|
| 472 |
|
|---|
| 473 |
$db->sql_query($sql); |
|---|
| 474 |
|
|---|
| 475 |
$cache->destroy('_smilies'); |
|---|
| 476 |
|
|---|
| 477 |
$message = $lang['su_upload_succesful'] . "<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>"); |
|---|
| 478 |
trigger_error($message); |
|---|
| 479 |
return; |
|---|
| 480 |
break; |
|---|
| 481 |
} |
|---|
| 482 |
} |
|---|
| 483 |
else |
|---|
| 484 |
{ |
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
// This is the main display of the page before the admin has selected |
|---|
| 488 |
// any options. |
|---|
| 489 |
// |
|---|
| 490 |
|
|---|
| 491 |
$template->set_filenames(array( |
|---|
| 492 |
"body" => "../admin/smile_list_body.tpl") |
|---|
| 493 |
); |
|---|
| 494 |
|
|---|
| 495 |
$template->assign_vars(array( |
|---|
| 496 |
'S_HIDDEN_FIELDS' => '<input type="hidden" name="mode" value="edit" />', |
|---|
| 497 |
"S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx")) |
|---|
| 498 |
); |
|---|
| 499 |
|
|---|
| 500 |
$inline_columns = 4; |
|---|
| 501 |
$inline_rows = 5; |
|---|
| 502 |
$window_columns = 4; |
|---|
| 503 |
|
|---|
| 504 |
$smilies = $cache->obtain_smilies(); |
|---|
| 505 |
|
|---|
| 506 |
$num_smilies = sizeof($smilies); |
|---|
| 507 |
|
|---|
| 508 |
if ( $num_smilies ) |
|---|
| 509 |
{ |
|---|
| 510 |
$smilies_count = $num_smilies; |
|---|
| 511 |
$smilies_split_row = $window_columns - 1; |
|---|
| 512 |
|
|---|
| 513 |
$s_colspan = 0; |
|---|
| 514 |
$row = 0; |
|---|
| 515 |
$col = 0; |
|---|
| 516 |
|
|---|
| 517 |
foreach ( $smilies AS $smile_id => $smile_ary ) { |
|---|
| 518 |
if (!$col) |
|---|
| 519 |
{ |
|---|
| 520 |
$template->assign_block_vars('smilies_row', array()); |
|---|
| 521 |
} |
|---|
| 522 |
|
|---|
| 523 |
$smile_ary['code'] = str_replace('<', '<', $smile_ary['code']); |
|---|
| 524 |
$smile_ary['code'] = str_replace('>', '>', $smile_ary['code']); |
|---|
| 525 |
$smile_ary['code'] = str_replace('"', '"', $smile_ary['code']); |
|---|
| 526 |
$smile_ary['code'] = str_replace('\\\'', '\'', $smile_ary['code']); |
|---|
| 527 |
|
|---|
| 528 |
$template->assign_block_vars('smilies_row.smilies_col', array( |
|---|
| 529 |
'SMILEY_ID' => $smile_id, |
|---|
| 530 |
'SMILEY_CODE' => $smile_ary['code'], |
|---|
| 531 |
'SMILEY_IMG' => $root_path . $config['smilies_path'] . '/' . $smile_ary['smile_url'], |
|---|
| 532 |
'SMILEY_DESC' => $smile_ary['emoticon'], |
|---|
| 533 |
'SMILEY_FILENAME' => $smile_ary['smile_url'], |
|---|
| 534 |
'U_SMILEY_DELETE' => append_sid("admin_smilies.$phpEx?mode=delete&id=" . $smile_id)) |
|---|
| 535 |
); |
|---|
| 536 |
|
|---|
| 537 |
$s_colspan = max($s_colspan, $col + 1); |
|---|
| 538 |
|
|---|
| 539 |
if ($col == $smilies_split_row) |
|---|
| 540 |
{ |
|---|
| 541 |
$col = 0; |
|---|
| 542 |
$row++; |
|---|
| 543 |
} |
|---|
| 544 |
else |
|---|
| 545 |
{ |
|---|
| 546 |
$col++; |
|---|
| 547 |
} |
|---|
| 548 |
} |
|---|
| 549 |
} |
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 |
// Spit out the page. |
|---|
| 553 |
// |
|---|
| 554 |
$template->display("body"); |
|---|
| 555 |
} |
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
<span class="code-comment">// Page Footer |
|---|
| 559 |
// |
|---|
| 560 |
include('./page_footer_admin.'.$phpEx); |
|---|
| 561 |
|
|---|
| 562 |
?> |
|---|