diff options
| author | Meik Sievertsen <acydburn@phpbb.com> | 2003-10-19 15:26:14 +0000 | 
|---|---|---|
| committer | Meik Sievertsen <acydburn@phpbb.com> | 2003-10-19 15:26:14 +0000 | 
| commit | de53ffabb410f7db9eb807a2965b02d19e314cc0 (patch) | |
| tree | 2699cab5cf567f519ecaa135100616cd9f8b9e9a | |
| parent | 5ea7428e1b5b885d773aa1b29dfe015b9512bbf4 (diff) | |
| download | forums-de53ffabb410f7db9eb807a2965b02d19e314cc0.tar forums-de53ffabb410f7db9eb807a2965b02d19e314cc0.tar.gz forums-de53ffabb410f7db9eb807a2965b02d19e314cc0.tar.bz2 forums-de53ffabb410f7db9eb807a2965b02d19e314cc0.tar.xz forums-de53ffabb410f7db9eb807a2965b02d19e314cc0.zip  | |
mass add/edit smilies and icons
git-svn-id: file:///svn/phpbb/trunk@4613 89ea8834-ac86-4346-8a33-228a782c2dd0
| -rw-r--r-- | phpBB/adm/admin_icons.php | 712 | 
1 files changed, 381 insertions, 331 deletions
diff --git a/phpBB/adm/admin_icons.php b/phpBB/adm/admin_icons.php index b81c4ccd57..5a0d610940 100644 --- a/phpBB/adm/admin_icons.php +++ b/phpBB/adm/admin_icons.php @@ -1,23 +1,15 @@  <?php -/*************************************************************************** -*                               admin_icons.php -*                              ------------------- -*     begin                : Thu May 31, 2001 -*     copyright            : (C) 2001 The phpBB Group -*     email                : support@phpbb.com -* -*     $Id$ -* -****************************************************************************/ - -/*************************************************************************** - * - *   This program is free software; you can redistribute it and/or modify - *   it under the terms of the GNU General Public License as published by - *   the Free Software Foundation; either version 2 of the License, or - *   (at your option) any later version. - * - ***************************************************************************/ +// ------------------------------------------------------------- +// +// $Id$ +// +// FILENAME  : admin_icons.php  +// STARTED   : Thu Mar 13, 2003 +// COPYRIGHT : © 2001, 2003 phpBB Group +// WWW       : http://www.phpbb.com/ +// LICENCE   : GPL vs2.0 [ see /docs/COPYING ]  +//  +// -------------------------------------------------------------  if (!empty($setmodules))  { @@ -27,15 +19,15 @@ if (!empty($setmodules))  	}  	$filename = basename(__FILE__); -	$module['POST']['SMILE'] = $filename . $SID . '&mode=emoticons'; -	$module['POST']['ICONS'] = $filename . $SID . '&mode=icons'; +	$module['POST']['SMILE'] = "$filename$SID&mode=emoticons"; +	$module['POST']['ICONS'] = "$filename$SID&mode=icons";  	return;  }  define('IN_PHPBB', 1);  // Include files -$phpbb_root_path = '../'; +$phpbb_root_path = './../';  $phpEx = substr(strrchr(__FILE__, '.'), 1);  require('pagestart.' . $phpEx); @@ -46,9 +38,11 @@ if (!$auth->acl_get('a_icons'))  }  // Grab some basic parameters -$mode = (!empty($_REQUEST['mode'])) ? $_REQUEST['mode'] : ''; -$action = (!empty($_REQUEST['action'])) ? $_REQUEST['action'] : ((isset($_POST['add'])) ? 'add' : ''); -$id = (isset($_GET['id'])) ? intval($_GET['id']) : false; +$mode = request_var('mode', ''); +$action = request_var('action', ''); +$action = (isset($_POST['add'])) ? 'add' : $action; +$action = (isset($_POST['edit'])) ? 'edit' : $action; +$id = request_var('id', 0);  // What are we working on?  switch ($mode) @@ -70,27 +64,33 @@ switch ($mode)  // Clear some arrays  $_images = $_paks = array(); - +$notice = '';  // Grab file list of paks and images  if ($action == 'edit' || $action == 'add' || $action == 'import')  { +	$imglist = filelist($phpbb_root_path . $img_path, ''); +	 +	foreach ($imglist as $path => $img_ary) +	{ +		foreach ($img_ary as $img) +		{ +			$img_size = @getimagesize($phpbb_root_path . $img_path . '/' . $path . $img); + +			$_images[$path.$img]['file'] = $path.$img; +			$_images[$path.$img]['width'] = $img_size[0]; +			$_images[$path.$img]['height'] = $img_size[1]; +		} +	} +	unset($imglist); +  	$dir = @opendir($phpbb_root_path . $img_path);  	while ($file = @readdir($dir))  	{ -		if (is_file($phpbb_root_path . $img_path . '/' . $file)) +		if (is_file($phpbb_root_path . $img_path . '/' . $file) && preg_match('#\.pak$#i', $file))  		{ -			$img_size = @getimagesize($phpbb_root_path . $img_path . '/' . $file); - -			if (preg_match('#\.(gif|png|jpg)$#i', $file) || (!empty($img_size[0]) && !empty($img_size[1]))) -			{ -				$_images[] = $file; -			} -			elseif (preg_match('#\.pak$#i', $file)) -			{ -				$_paks[] = $file; -			} +			$_paks[] = $file;  		}  	}  	@closedir($dir); @@ -100,51 +100,40 @@ if ($action == 'edit' || $action == 'add' || $action == 'import')  // What shall we do today? Oops, I believe that's trademarked ...  switch ($action)  { -	case 'delete': - -		$db->sql_query('DELETE FROM ' . $table . '  -			WHERE ' . $fields . '_id = ' . intval($_GET['id'])); - -		switch ($mode) -		{ -			case 'emoticons': -				break; - -			case 'icons': -				// Reset appropriate icon_ids -				$db->sql_query('UPDATE ' . TOPICS_TABLE . '  -					SET icon_id = 0  -					WHERE icon_id = ' . intval($_GET['id'])); -				$db->sql_query('UPDATE ' . POSTS_TABLE . '  -					SET icon_id = 0  -					WHERE icon_id = ' . intval($_GET['id'])); -				break; -		} - -		trigger_error($user->lang[$lang . '_DELETED']); -		break; -  	case 'edit': +		unset($_images); +		$_images = array(); +  	case 'add':  		$order_list = ''; -		$existing_imgs = array(); -		$result = $db->sql_query('SELECT *  -			FROM ' . $table . '  -			ORDER BY ' . $fields . '_order DESC'); + +		$sql = "SELECT *  +			FROM $table  +			ORDER BY {$fields}_order " . (($id || $action == 'add') ? 'DESC' : 'ASC'); +		$result = $db->sql_query($sql); +  		if ($row = $db->sql_fetchrow($result))  		{  			do  			{ -				$existing_imgs[] = $row[$fields . '_url']; +				if ($action == 'add') +				{ +					unset($_images[$row[$fields . '_url']]); +				}  				if ($row[$fields . '_id'] == $id)  				{  					$after = TRUE; -					$data = $row; +					$data[$row[$fields . '_url']] = $row;  				}  				else  				{ +					if ($action == 'edit' && !$id) +					{ +						$data[$row[$fields . '_url']] = $row; +					} +					  					$selected = '';  					if (!empty($after))  					{ @@ -161,36 +150,16 @@ switch ($action)  		$db->sql_freeresult($result);  		$order_list = '<option value="1"' . ((!isset($after)) ? ' selected="selected"' : '') . '>' . $user->lang['FIRST'] . '</option>' . $order_list; -		 -		$imglist = filelist($phpbb_root_path . $img_path, ''); -		$filename_list = ''; -		foreach ($imglist as $path => $img_ary) +		if ($action == 'add')  		{ -			foreach ($img_ary as $img) -			{ -				$img = "$path$img"; +			$data = $_images; +		} -				if (!in_array($img, $existing_imgs) || $action == 'edit') -				{ -					if ((isset($data) && $img == $data[$fields . '_url']) ||  -						(!isset($data) && !isset($edit_img))) -					{ -						$selected = ' selected="selected"'; -						$edit_img = $img; -					} -					else -					{ -						$selected = ''; -					} +		$colspan = (($mode == 'emoticons') ? '7' : '5'); +		$colspan += ($id) ? 1 : 0; +		$colspan += ($action == 'add') ? 2 : 0; -					$filename_list .= '<option value="' . $img . '"' . htmlspecialchars($img) . $selected . '>' . $img . '</option>'; -				} -			} -		} -		unset($existing_imgs); -		unset($imglist); -	  		adm_page_header($user->lang[$lang]);  ?> @@ -199,78 +168,97 @@ switch ($action)  <p><?php echo $user->lang[$lang .'_EXPLAIN']; ?></p> -<script language="javascript" type="text/javascript" defer="defer"> -<!-- - -function update_image(newimage) -{ -	document.image.src = "<?php echo $phpbb_root_path . $img_path ?>/" + newimage; -} - -function update_image_dimensions() -{ -	if (document.image.height) +<form method="post" action="admin_icons.<?php echo $phpEx . $SID . "&mode=$mode&action=" . (($action == 'add') ? 'create' : 'modify'); ?>"> +<table class="bg" cellspacing="1" cellpadding="4" border="0" align="center"> +<tr> +	<th colspan="<?php echo $colspan; ?>"><?php echo $user->lang[$lang . '_CONFIG'] ?></th> +</tr> +<tr> +	<td class="cat"><?php echo $user->lang[$lang . '_URL'] ?></td> +	<td class="cat"><?php echo $user->lang[$lang . '_LOCATION'] ?></td> +<?php +	if ($mode == 'emoticons') +	{ +?> +	<td class="cat"><?php echo $user->lang[$lang . '_CODE'] ?></td> +	<td class="cat"><?php echo $user->lang[$lang . '_EMOTION'] ?></td> +<?php +	} +?> +	<td class="cat"><?php echo $user->lang[$lang . '_WIDTH'] ?></td> +	<td class="cat"><?php echo $user->lang[$lang . '_HEIGHT'] ?></td> +	<td class="cat"><?php echo $user->lang['DISPLAY_ON_POSTING'] ?></td> +<?php +	if ($id || $action == 'add')  	{ -		document.forms[0].height.value = document.image.height; -		document.forms[0].width.value = document.image.width; +?> +	<td class="cat"><?php echo $user->lang[$lang . '_ORDER'] ?></td> +<?php  	} -} - -//--> -</script> - -<form method="post" action="admin_icons.<?php echo $phpEx . $SID . "&mode=$mode&action=" . (($action == 'add') ? 'create' : 'modify'); ?>"><table class="bg" cellspacing="1" cellpadding="4" border="0" align="center"> -	<tr> -		<th colspan="2"><?php echo $user->lang[$lang . '_CONFIG'] ?></th> -	</tr> -	<tr> -		<td class="row1"><?php echo $user->lang[$lang . '_URL'] ?></td> -		<td class="row2"><select name="img" onchange="update_image(this.options[selectedIndex].value);"><?php echo $filename_list ?></select>   <img src="<?php echo $phpbb_root_path . $img_path . '/' . $edit_img ?>"  name="image" border="0" alt="" title="" onload="update_image_dimensions()" />  </td> -	</tr> +?> +<?php +	if ($action == 'add') +	{ +?> +	<td class="cat"><?php echo $user->lang['ADD'] ?></td> +<?php +	} +?> +</tr> +<?php +	$row = 0; +	foreach ($data as $img => $img_row) +	{ +		$row_class = (($row % 2) == 0) ? 'row1' : 'row2'; +?> +<tr> +	<td align="center" class="<?php echo $row_class; ?>"><img src="<?php echo $phpbb_root_path . $img_path . '/' . $img ?>" border="0" alt="" title="" /><input type="hidden" name="image[<?php echo $img; ?>]" value="1" /></td> +	<td valign="top" class="<?php echo $row_class; ?>">[<?php echo $img; ?>]</td>  <?php  	if ($mode == 'emoticons')  	{  ?> -	<tr> -		<td class="row1"><?php echo $user->lang[$lang . '_CODE'] ?></td> -		<td class="row2"><input class="post" type="text" name="code" value="<?php echo (!empty($data['code'])) ? $data['code'] : '' ?>" /></td> -	</tr> -	<tr> -		<td class="row1"><?php echo $user->lang[$lang . '_EMOTION'] ?></td> -		<td class="row2"><input class="post" type="text" name="emotion" value="<?php echo (!empty($data['emoticon'])) ? $data['emoticon'] : '' ?>" /></td> -	</tr> +		<td class="<?php echo $row_class; ?>"><input class="post" type="text" name="code[<?php echo $img; ?>]" value="<?php echo (!empty($img_row['code'])) ? $img_row['code'] : '' ?>" size="10" /></td> +		<td class="<?php echo $row_class; ?>"><input class="post" type="text" name="emotion[<?php echo $img; ?>]" value="<?php echo (!empty($img_row['emoticon'])) ? $img_row['emoticon'] : '' ?>" size="10" /></td>  <?php  	}  ?> -	<tr> -		<td class="row1"><?php echo $user->lang[$lang . '_WIDTH'] ?></td> -		<td class="row2"><input class="post" type="text" size="3" name="width" value="<?php echo (!empty($data[$fields .'_width'])) ? $data[$fields .'_width'] : '' ?>" /></td> -	</tr> -	<tr> -		<td class="row1"><?php echo $user->lang[$lang . '_HEIGHT'] ?></td> -		<td class="row2"><input class="post" type="text" size="3" name="height" value="<?php echo (!empty($data[$fields .'_height'])) ? $data[$fields .'_height'] : '' ?>" /></td> -	</tr> -	<tr> -		<td class="row1"><?php echo $user->lang['DISPLAY_ON_POSTING'] ?></td> -		<td class="row2"><input type="checkbox" name="display_on_posting" <?php echo (!empty($data['display_on_posting']) || !isset($data)) ? ' checked="checked"' : '' ?>/></td> -	</tr> -	<tr> -		<td class="row1"><?php echo $user->lang[$lang . '_ORDER'] ?></td> -		<td class="row2"><select name="order"><?php echo $order_list ?></select></td> -	</tr> -	<tr> -		<td class="cat" colspan="2" align="center"><?php  -			 -	if (!empty($data)) +	<td class="<?php echo $row_class; ?>"><input class="post" type="text" size="3" name="width[<?php echo $img; ?>]" value="<?php echo (!empty($img_row[$fields .'_width'])) ? $img_row[$fields .'_width'] : $img_row['width'] ?>" /></td> +	<td class="<?php echo $row_class; ?>"><input class="post" type="text" size="3" name="height[<?php echo $img; ?>]" value="<?php echo (!empty($img_row[$fields .'_height'])) ? $img_row[$fields .'_height'] : $img_row['height'] ?>" /></td> +	<td class="<?php echo $row_class; ?>"><input type="checkbox" name="display_on_posting[<?php echo $img; ?>]"<?php echo (!empty($img_row['display_on_posting']) || $action == 'add') ? ' checked="checked"' : '' ?> /></td> +<?php +		if ($id || $action == 'add') +		{ +?> +			<td class="<?php echo $row_class; ?>"><select name="order[<?php echo $img; ?>]"><?php echo $order_list ?></select></td> +<?php +		} +	 +		if ($action == 'add') +		{ +?> +			<td class="<?php echo $row_class; ?>"><input type="checkbox" name="add_img[<?php echo $img; ?>]" value="1" /><?php +	 +	} +?> +</tr> +<?php +	if (isset($img_row[$fields . '_id']))  	{ -?><input type="hidden" name="id" value="<?php echo $data[$fields . '_id'] ?>" /><?php +?><input type="hidden" name="id[<?php echo $img; ?>]" value="<?php echo $img_row[$fields . '_id'] ?>" /><?php  	} +	$row++; +} +?> +<tr> +	<td class="cat" colspan="<?php echo $colspan; ?>" align="center"><?php  +			  ?><input class="btnmain" type="submit" value="<?php echo $user->lang['SUBMIT'] ?>" /></td>  	</tr> @@ -283,100 +271,135 @@ function update_image_dimensions()  	case 'create':  	case 'modify': -		$image_id = intval($_POST['id']); -		$img = stripslashes($_POST['img']); -		$image_order = intval($_POST['order']); -		$image_width = intval($_POST['width']); -		$image_height = intval($_POST['height']); - -		if ($image_width == 0 || $image_height == 0) -		{ -			$img_size = @getimagesize($phpbb_root_path . $img_path . '/' . $img); -			$smile_width = $img_size[0]; -			$smile_height = $img_size[1]; -		} - -		$img_sql = array( -			$fields . '_url'	=>	$img, -			$fields . '_width'	=>	$image_width, -			$fields . '_height'	=>	$image_height, -			$fields . '_order'	=>	$image_order, -			'display_on_posting'=>	(!empty($_POST['display_on_posting'])) ? 1 : 0 -		); -		if ($mode == 'emoticons') -		{ -			$img_sql = array_merge($img_sql, array( -				'emoticon'	=>	stripslashes($_POST['emotion']), -				'code'		=>	htmlspecialchars(stripslashes($_POST['code'])) -			)); -		} - -		if ($action == 'modify') +		// Get items to create/modify +		$images = (isset($_POST['image'])) ? array_keys($_POST['image']) : array(); +		 +		// Now really get the items +		$image_id		= (isset($_POST['id'])) ? array_map('intval', $_POST['id']) : array(); +		$image_order	= (isset($_POST['order'])) ? array_map('intval', $_POST['order']) : array(); +		$image_width	= (isset($_POST['width'])) ? array_map('intval', $_POST['width']) : array(); +		$image_height	= (isset($_POST['height'])) ? array_map('intval', $_POST['height']) : array(); +		$image_add		= (isset($_POST['add_img'])) ? array_map('intval', $_POST['add_img']) : array(); +		$image_emotion	= request_var('emotion', ''); +		$image_code		= request_var('code', ''); +		$image_display_on_posting = (isset($_POST['display_on_posting'])) ? array_map('intval', $_POST['display_on_posting']) : array(); + +		foreach ($images as $image)  		{ -			$result = $db->sql_query('SELECT ' . $fields . '_order  -				FROM ' . $table . '  -				WHERE ' . $fields . "_id = $image_id"); -			$order_old = $db->sql_fetchfield($fields . '_order', 0, $result); - -			if ($order_old == $image_order) +			if (($mode == 'emoticons' && ($image_emotion[$image] == '' || $image_code[$image] == '')) || +				($action == 'create' && !isset($image_add[$image])))  			{ -				$no_update = TRUE; -			} - -			if ($order_old > $image_order) -			{ -				$sign = '+'; -				$where = $fields . "_order >= $image_order AND " . $fields . "_order < $order_old";  			}  			else  			{ -				$sign = '-'; -				$where = $fields . "_order > $order_old AND " . $fields . "_order < $image_order"; -				$sql[$fields . '_order'] = $image_order - 1; -			} -		} -		else -		{ -			$sign = '+'; -			$where = $fields . "_order > $image_order"; -		} +				if ($image_width[$image] == 0 || $image_height[$image] == 0) +				{ +					$img_size = @getimagesize($phpbb_root_path . $img_path . '/' . $image); +					$image_width[$image] = $img_size[0]; +					$image_height[$image] = $img_size[1]; +				} -		if (empty($no_update)) -		{ -			$sql = 'UPDATE ' . $table . ' -				SET ' . $fields . '_order = ' . $fields . "_order $sign 1 -				WHERE $where"; -			$db->sql_query($sql); +				$img_sql = array( +					$fields . '_url'	=>	$image, +					$fields . '_width'	=>	$image_width[$image], +					$fields . '_height'	=>	$image_height[$image], +					'display_on_posting'=>	(isset($image_display_on_posting[$image])) ? 1 : 0, +				); + +				if ($mode == 'emoticons') +				{ +					$img_sql = array_merge($img_sql, array( +						'emoticon'	=>	$image_emotion[$image], +						'code'		=>	$image_code[$image]) +					); +				} +				 +				if (!empty($image_order[$image])) +				{ +					$img_sql = array_merge($img_sql, array( +						$fields . '_order'	=>	$image_order[$image] . '.5') +					); +				} + +				if ($action == 'modify') +				{ +					$sql = "UPDATE $table +						SET " . $db->sql_build_array('UPDATE', $img_sql) . "  +						WHERE {$fields}_id = " . $image_id[$image]; +					$db->sql_query($sql); +				} +				else +				{ +					$sql = "INSERT INTO $table " . $db->sql_build_array('INSERT', $img_sql); +					$db->sql_query($sql); +				} + +				$update = FALSE; + +				if ($action == 'modify' && !empty($image_order[$image])) +				{ +					$update = TRUE; + +					$result = $db->sql_query("SELECT {$fields}_order  +						FROM $table +						WHERE {$fields}_id = " . $image_id[$image]); +					$order_old = $db->sql_fetchfield($fields . '_order', 0, $result); + +					if ($order_old == $image_order[$image]) +					{ +						$update = FALSE; +					} + +					if ($order_old > $image_order[$image]) +					{ +						$sign = '+'; +						$where = $fields . '_order >= ' . $image_order[$image] . " AND {$fields}_order < $order_old"; +					} +					else if ($order_old < $image_order[$image]) +					{ +						$sign = '-'; +						$where = "{$fields}_order > $order_old AND {$fields}_order < " . $image_order[$image]; +						$sql[$fields . '_order'] = $image_order[$image] - 1; +					} +				} + +				if ($update) +				{ +					$sql = "UPDATE $table +						SET {$fields}_order = {$fields}_order $sign 1 +						WHERE $where"; +					$db->sql_query($sql); +				} +			 +			}  		} +		 +		$cache->destroy('icons');  		if ($action == 'modify')  		{ -			$db->sql_query('UPDATE ' . $table . '  -				SET ' . $db->sql_build_array('UPDATE', $img_sql) . "  -				WHERE " . $fields . "_id = $image_id"); -			$cache->destroy('icons'); -  			trigger_error($user->lang[$lang . '_EDITED']);  		}  		else  		{ -			$db->sql_query('INSERT INTO ' . $table . ' ' . $db->sql_build_array('INSERT', $img_sql)); -			$cache->destroy('icons'); -  			trigger_error($user->lang[$lang . '_ADDED']);  		} +  		break;  	case 'import': -		if (!empty($_POST['pak'])) +		$pak = request_var('pak', ''); +		$current = request_var('current', ''); + +		if ($pak != '')  		{  			$order = 0;  			// The user has already selected a smilies_pak file -			if ($_POST['current'] == 'delete') +			if ($current == 'delete')  			{ -				$db->sql_query('TRUNCATE ' . $table); +				$db->sql_query("TRUNCATE $table");  				switch ($mode)  				{ @@ -397,23 +420,19 @@ function update_image_dimensions()  				$cur_img = array();  				$field_sql = ($mode == 'emoticons') ? 'code' : 'icons_url'; -				$result = $db->sql_query('SELECT ' . $field_sql . '  -					FROM ' . $table); -				if ($row = $db->sql_fetchrow($result)) +				$result = $db->sql_query("SELECT $field_sql FROM $table"); + +				while ($row = $db->sql_fetchrow($result))  				{ -					do -					{ -						++$order; -						$cur_img[$row[$field_sql]] = 1; -					} -					while ($row = $db->sql_fetchrow($result)); +					++$order; +					$cur_img[$row[$field_sql]] = 1;  				}  				$db->sql_freeresult($result);  			} -			if (!($pak_ary = @file($phpbb_root_path . $img_path . '/'. stripslashes($_POST['pak'])))) +			if (!($pak_ary = @file($phpbb_root_path . $img_path . '/' . $pak)))  			{ -				trigger_error('Could not read smiley pak file', E_USER_ERROR); +				trigger_error('Could not read pak file', E_USER_ERROR);  			}  			foreach ($pak_ary as $pak_entry) @@ -421,7 +440,7 @@ function update_image_dimensions()  				$data = array();  				if (preg_match_all("#'(.*?)', #", $pak_entry, $data))  				{ -					if ((sizeof($data[1]) == 5 && $mode == 'icons') ||  +					if ((sizeof($data[1]) != 3 && $mode == 'icons') ||   						(sizeof($data[1]) != 5 && $mode == 'emoticons'))  					{  						trigger_error($user->lang['WRONG_PAK_TYPE']); @@ -436,15 +455,15 @@ function update_image_dimensions()  						$code = htmlentities(stripslashes($data[1][4]));  					} -					if ($_POST['current'] == 'replace' &&  +					if ($current == 'replace' &&   						(($mode == 'emoticons' && !empty($cur_img[$code])) ||   						($mode == 'icons' && !empty($cur_img[$img]))))  					{  						$replace_sql = ($mode == 'emoticons') ? $code : $img;  						$sql = array(  							$fields . '_url'	=>	$img, -							$fields . '_height'	=>	intval($height), -							$fields . '_width'	=>	intval($width), +							$fields . '_height'	=>	(int) $height, +							$fields . '_width'	=>	(int) $width,  						);  						if ($mode == 'emoticons')  						{ @@ -462,10 +481,11 @@ function update_image_dimensions()  						$sql = array(  							$fields . '_url'	=>	$img, -							$fields . '_height'	=>	intval($height), -							$fields . '_width'	=>	intval($width), -							$fields . '_order'	=>	intval($order), +							$fields . '_height'	=>	(int) $height, +							$fields . '_width'	=>	(int) $width, +							$fields . '_order'	=>	(int) $order,  						); +  						if ($mode == 'emoticons')  						{  							$sql = array_merge($sql, array( @@ -480,22 +500,15 @@ function update_image_dimensions()  			}  			$cache->destroy('icons'); -  			trigger_error($user->lang[$lang . '_IMPORT_SUCCESS']);  		}  		else  		{ -			$paklist = filelist($phpbb_root_path . $img_path, '', 'pak'); -  			$pak_options = ''; -			if (count($paklist)) -			{ -				foreach ($paklist as $pak) -				{ -					$pak = substr($pak['path'], 1) . (($pak['path'] != '') ? '/' : '') . $pak['file']; -					$pak_options .= '<option>' . htmlspecialchars($pak) . '</option>'; -				} +			foreach ($_paks as $pak) +			{ +				$pak_options .= '<option value="' . $pak . '">' . htmlspecialchars($pak) . '</option>';  			}  			adm_page_header($user->lang[$lang]); @@ -505,19 +518,20 @@ function update_image_dimensions()  <p><?php echo $user->lang[$lang .'_EXPLAIN'] ?></p> -<form method="post" action="admin_icons.<?php echo $phpEx . $SID . '&mode=' . $mode . '&action=import'; ?>"><table class="bg" cellspacing="1" cellpadding="4" border="0" align="center"> -	<tr> -		<th colspan="2"><?php echo $user->lang[$lang . '_IMPORT'] ?></th> -	</tr> +<form method="post" action="admin_icons.<?php echo $phpEx . $SID . '&mode=' . $mode . '&action=import'; ?>"> +<table class="bg" cellspacing="1" cellpadding="4" border="0" align="center"> +<tr> +	<th colspan="2"><?php echo $user->lang[$lang . '_IMPORT'] ?></th> +</tr>  <?php  			if ($pak_options == '')  			{  ?> -	<tr> -		<td class="row1" colspan="2"><?php echo $user->lang['NO_' . $lang . '_PAK']; ?></td> -	</tr> +<tr> +	<td class="row1" colspan="2"><?php echo $user->lang['NO_' . $lang . '_PAK']; ?></td> +</tr>  <?php  			} @@ -525,17 +539,17 @@ function update_image_dimensions()  			{  ?> -	<tr> -		<td class="row2"><?php echo $user->lang['SELECT_PACKAGE'] ?></td> -		<td class="row1"><select name="pak"><?php echo $pak_options ?></select></td> -	</tr> -	<tr> -		<td class="row2"><?php echo $user->lang['CURRENT_' . $lang] ?><br /><span class="gensmall"><?php echo $user->lang['CURRENT_' . $lang . '_EXPLAIN'] ?></span></td> -		<td class="row1"><input type="radio" name="current" value="keep" checked="checked" /> <?php echo $user->lang['KEEP_ALL'] ?>   <input type="radio" name="current" value="replace" /> <?php echo $user->lang['REPLACE_MATCHES'] ?>   <input type="radio" name="current" value="delete" /> <?php echo $user->lang['DELETE_ALL'] ?> </td> -	</tr> -	<tr> -		<td class="cat" colspan="2" align="center"><input class="btnmain" name="import" type="submit" value="<?php echo $user->lang['IMPORT_' . $lang] ?>" /></td> +<tr> +	<td class="row2"><?php echo $user->lang['SELECT_PACKAGE'] ?></td> +	<td class="row1"><select name="pak"><?php echo $pak_options ?></select></td> +</tr> +<tr> +	<td class="row2"><?php echo $user->lang['CURRENT_' . $lang] ?><br /><span class="gensmall"><?php echo $user->lang['CURRENT_' . $lang . '_EXPLAIN'] ?></span></td> +	<td class="row1"><input type="radio" name="current" value="keep" checked="checked" /> <?php echo $user->lang['KEEP_ALL'] ?>   <input type="radio" name="current" value="replace" /> <?php echo $user->lang['REPLACE_MATCHES'] ?>   <input type="radio" name="current" value="delete" /> <?php echo $user->lang['DELETE_ALL'] ?> </td>  	</tr> +<tr> +	<td class="cat" colspan="2" align="center"><input class="btnmain" name="import" type="submit" value="<?php echo $user->lang['IMPORT_' . $lang] ?>" /></td> +</tr>  <?php  			} @@ -556,24 +570,23 @@ function update_image_dimensions()  	case 'send': -		$result = $db->sql_query('SELECT *  -			FROM ' . $table . "  -			ORDER BY {$fields}_order"); -		if ($row = $db->sql_fetchrow($result)) +		$sql = "SELECT *  +			FROM $table +			ORDER BY {$fields}_order"; +		$result = $db->sql_query($sql); + +		$pak = ''; +		while ($row = $db->sql_fetchrow($result))  		{ -			do +			$pak .= "'" . addslashes($row[$fields . '_url']) . "', "; +			$pak .= "'" . addslashes($row[$fields . '_height']) . "', "; +			$pak .= "'" . addslashes($row[$fields . '_width']) . "', "; +			if ($mode == 'emoticons')  			{ -				$pak .= "'" . addslashes($row[$fields . '_url']) . "', "; -				$pak .= "'" . addslashes($row[$fields . '_height']) . "', "; -				$pak .= "'" . addslashes($row[$fields . '_width']) . "', "; -				if ($mode == 'emoticons') -				{ -					$pak .= "'" . addslashes($row['emoticon']) . "', "; -					$pak .= "'" . addslashes($row['code']) . "', "; -				} -				$pak .= "\n"; +				$pak .= "'" . addslashes($row['emoticon']) . "', "; +				$pak .= "'" . addslashes($row['code']) . "', ";  			} -			while ($row = $db->sql_fetchrow($result)); +			$pak .= "\n";  		}  		$db->sql_freeresult($result); @@ -592,35 +605,66 @@ function update_image_dimensions()  		}  		break; +	case 'delete': + +		$db->sql_query("DELETE FROM $table  +			WHERE {$fields}_id = $id"); + +		switch ($mode) +		{ +			case 'emoticons': +				break; + +			case 'icons': +				// Reset appropriate icon_ids +				$db->sql_query('UPDATE ' . TOPICS_TABLE . "  +					SET icon_id = 0  +					WHERE icon_id = $id"); +				$db->sql_query('UPDATE ' . POSTS_TABLE . "  +					SET icon_id = 0  +					WHERE icon_id = $id"); +				break; +		} + +		$notice = $user->lang[$lang . '_DELETED']; +  	case 'move_up':  	case 'move_down': -		$image_order = intval($_GET['order']); -		$order_total = $image_order * 2 + (($action == 'move_up') ? -1 : 1); -		$sql = 'UPDATE ' . $table . ' -			SET ' . $fields . "_order = $order_total - " . $fields . '_order -			WHERE ' . $fields . "_order IN ($image_order, " . (($action == 'move_up') ? $image_order - 1 : $image_order + 1) . ')'; -		$db->sql_query($sql); +		if ($action != 'delete') +		{ +			$image_order = intval($_GET['order']); +			$order_total = $image_order * 2 + (($action == 'move_up') ? -1 : 1); -		$cache->destroy('icons'); +			$sql = 'UPDATE ' . $table . ' +				SET ' . $fields . "_order = $order_total - " . $fields . '_order +				WHERE ' . $fields . "_order IN ($image_order, " . (($action == 'move_up') ? $image_order - 1 : $image_order + 1) . ')'; +			$db->sql_query($sql); +			$cache->destroy('icons'); + +		}  		// No break; here, display the smilies admin back  	default:  		// By default, check that image_order is valid and fix it if necessary -		$result = $db->sql_query('SELECT * FROM ' . $table . ' ORDER BY ' . $fields . '_order'); +		$sql = "SELECT {$fields}_id AS order_id, {$fields}_order AS fields_order +			FROM $table +			ORDER BY {$fields}_order"; +		$result = $db->sql_query($sql); +  		if ($row = $db->sql_fetchrow($result))  		{  			$order = 0;  			do  			{  				++$order; -				if ($row[$fields . '_order'] != $order) +				if ($row['fields_order'] != $order)  				{ -					$db->sql_query('UPDATE ' . $table . ' -						SET ' . $fields . '_order = ' . $order . '  -						WHERE ' . $fields . '_id = ' . $row[$fields . '_id']); +					$db->sql_query("UPDATE $table +						SET {$fields}_order = $order +						WHERE {$fields}_id = " . $row['order_id']);  				}  			}  			while ($row = $db->sql_fetchrow($result)); @@ -636,37 +680,47 @@ function update_image_dimensions()  <p><?php echo $user->lang[$lang .'_EXPLAIN']; ?></p> -<form method="post" action="admin_icons.<?php echo $phpEx . $SID . '&mode=' . $mode ?>"><table cellspacing="1" cellpadding="0" border="0" align="center"> -	<tr> -		<td align="right">    <a href="admin_icons.<?php echo $phpEx . $SID . '&mode=' . $mode . '&action=import'; ?>"><?php echo $user->lang['IMPORT_' . $lang]; ?></a> | <a href="admin_icons.<?php echo $phpEx . $SID . '&mode=' . $mode . '&action=export'; ?>"><?php echo $user->lang['EXPORT_' . $lang]; ?></a></td> -	</tr> -	<tr> -		<td><table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0" align="center"> -			<tr> -				<th><?php echo $user->lang[$lang]; ?></th>  <?php -	if ($mode == 'emoticons') +	if ($notice != '')  	{  ?> -				<th><?php echo $user->lang['CODE']; ?></th> -				<th><?php echo $user->lang['EMOTION']; ?></th> +		<b style="color:green"><?php echo $notice; ?></b>  <?php - +	  	}  ?> -				<th><?php echo $user->lang['ACTION']; ?></th> -				<th><?php echo $user->lang['REORDER']; ?></th> -			</tr> -<?php +<form method="post" action="admin_icons.<?php echo $phpEx . $SID . '&mode=' . $mode ?>"> +<table cellspacing="1" cellpadding="0" border="0" align="center"> +<tr> +	<td align="right">    <a href="admin_icons.<?php echo $phpEx . $SID . '&mode=' . $mode . '&action=import'; ?>"><?php echo $user->lang['IMPORT_' . $lang]; ?></a> | <a href="admin_icons.<?php echo $phpEx . $SID . '&mode=' . $mode . '&action=export'; ?>"><?php echo $user->lang['EXPORT_' . $lang]; ?></a></td> +</tr> +<tr> +	<td> +		<table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0" align="center"> +		<tr> +			<th><?php echo $user->lang[$lang]; ?></th> +<?php +			if ($mode == 'emoticons') +			{ +?> +				<th><?php echo $user->lang['CODE']; ?></th> +				<th><?php echo $user->lang['EMOTION']; ?></th> +<?php +			} +?> +			<th><?php echo $user->lang['ACTION']; ?></th> +			<th><?php echo $user->lang['REORDER']; ?></th> +		</tr> +<?php  		$spacer = FALSE; -		$sql = 'SELECT *  -			FROM ' . $table . '  -			ORDER BY display_on_posting DESC, ' . $fields . '_order ASC'; +		$sql = "SELECT *  +			FROM $table +			ORDER BY display_on_posting DESC, {$fields}_order ASC";  		$result = $db->sql_query($sql);  		while ($row = $db->sql_fetchrow($result)) @@ -675,50 +729,46 @@ function update_image_dimensions()  			{  				$spacer = TRUE;  ?> -			<tr> -				<td class="row3" colspan="<?php echo ($mode == 'emoticons') ? 5 : 3; ?>" align="center"><?php echo $user->lang[$lang . '_NOT_DISPLAYED'] ?></td> -			</tr> +		<tr> +			<td class="row3" colspan="<?php echo ($mode == 'emoticons') ? 5 : 3; ?>" align="center"><?php echo $user->lang[$lang . '_NOT_DISPLAYED'] ?></td> +		</tr>  <?php  			}  			$row_class = ($row_class != 'row1') ? 'row1' : 'row2'; -  			$alt_text = ($mode == 'emoticon') ? htmlspecialchars($row['code']) : ''; -  ?> -	<tr> -				<td class="<?php echo $row_class; ?>" align="center"><img src="<?php echo './../' . $img_path . '/' . $row[$fields . '_url']; ?>" width="<?php echo $row[$fields . '_width']; ?>" height="<?php echo $row[$fields . '_height']; ?>" alt="<?php echo $alt_text; ?>" title="<?php echo $alt_text; ?>" /></td> +		<tr> +			<td class="<?php echo $row_class; ?>" align="center"><img src="<?php echo $phpbb_root_path . $img_path . '/' . $row[$fields . '_url']; ?>" width="<?php echo $row[$fields . '_width']; ?>" height="<?php echo $row[$fields . '_height']; ?>" alt="<?php echo $alt_text; ?>" title="<?php echo $alt_text; ?>" /></td>  <?php -	if ($mode == 'emoticons') -	{ - +			if ($mode == 'emoticons') +			{  ?>  				<td class="<?php echo $row_class; ?>" align="center"><?php echo htmlspecialchars($row['code']); ?></td>  				<td class="<?php echo $row_class; ?>" align="center"><?php echo $row['emoticon']; ?></td>  <?php - -	} - +			}  ?> -				<td class="<?php echo $row_class; ?>" align="center"><a href="<?php echo "admin_icons.$phpEx$SID&mode=$mode&action=edit&id=" . $row[$fields . '_id']; ?>"><?php echo $user->lang['EDIT']; ?></a> | <a href="<?php echo "admin_icons.$phpEx$SID&mode=$mode&action=delete&id=" . $row[$fields . '_id']; ?>"><?php echo $user->lang['DELETE']; ?></a></td> -				<td class="<?php echo $row_class; ?>" align="center"><a href="<?php echo "admin_icons.$phpEx$SID&mode=$mode&action=move_up&order=" . $row[$fields . '_order']; ?>"><?php echo $user->lang['MOVE_UP']; ?></a> <br /> <a href="<?php echo "admin_icons.$phpEx$SID&mode=$mode&action=move_down&order=" . $row[$fields . '_order']; ?>"><?php echo $user->lang['MOVE_DOWN']; ?></a></td> -			</tr> +			<td class="<?php echo $row_class; ?>" align="center"><a href="<?php echo "admin_icons.$phpEx$SID&mode=$mode&action=edit&id=" . $row[$fields . '_id']; ?>"><?php echo $user->lang['EDIT']; ?></a> | <a href="<?php echo "admin_icons.$phpEx$SID&mode=$mode&action=delete&id=" . $row[$fields . '_id']; ?>"><?php echo $user->lang['DELETE']; ?></a></td> +			<td class="<?php echo $row_class; ?>" align="center"><a href="<?php echo "admin_icons.$phpEx$SID&mode=$mode&action=move_up&order=" . $row[$fields . '_order']; ?>"><?php echo $user->lang['MOVE_UP']; ?></a> <br /> <a href="<?php echo "admin_icons.$phpEx$SID&mode=$mode&action=move_down&order=" . $row[$fields . '_order']; ?>"><?php echo $user->lang['MOVE_DOWN']; ?></a></td> +		</tr>  <?php  		}  		$db->sql_freeresult($result);  ?> -			<tr> -				<td class="cat" colspan="<?php echo ($mode == 'emoticons') ? 5 : 3; ?>" align="center"><input type="submit" name="add" value="<?php echo $user->lang['ADD_' . $lang]; ?>" class="btnmain" /></td> -			</tr> -		</table></td> -	</tr> -</table></form> +		<tr> +			<td class="cat" colspan="<?php echo ($mode == 'emoticons') ? 5 : 3; ?>" align="center"><input type="submit" name="add" value="<?php echo $user->lang['ADD_' . $lang]; ?>" class="btnmain" /> <input type="submit" name="edit" value="<?php echo $user->lang['EDIT_' . $lang]; ?>" class="btnmain" /></td> +		</tr> +		</table> +	</td> +</tr> +</table> +</form>  <?php -  		adm_page_footer();  		break;  | 
