Blame Identity/Webenv/phpBB/3.0.4/includes/acp/acp_icons.php

ef5584
ef5584
/**
ef5584
*
ef5584
* @package acp
ef5584
* @version $Id: acp_icons.php 8974 2008-10-06 13:23:41Z acydburn $
ef5584
* @copyright (c) 2005 phpBB Group
ef5584
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
ef5584
*
ef5584
*/
ef5584
ef5584
/**
ef5584
* @ignore
ef5584
*/
ef5584
if (!defined('IN_PHPBB'))
ef5584
{
ef5584
	exit;
ef5584
}
ef5584
ef5584
/**
ef5584
* @todo [smilies] check regular expressions for special char replacements (stored specialchared in db)
ef5584
* @package acp
ef5584
*/
ef5584
class acp_icons
ef5584
{
ef5584
	var $u_action;
ef5584
ef5584
	function main($id, $mode)
ef5584
	{
ef5584
		global $db, $user, $auth, $template, $cache;
ef5584
		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
ef5584
ef5584
		$user->add_lang('acp/posting');
ef5584
ef5584
		// Set up general vars
ef5584
		$action = request_var('action', '');
ef5584
		$action = (isset($_POST['add'])) ? 'add' : $action;
ef5584
		$action = (isset($_POST['edit'])) ? 'edit' : $action;
ef5584
		$action = (isset($_POST['import'])) ? 'import' : $action;
ef5584
		$icon_id = request_var('id', 0);
ef5584
ef5584
		$mode = ($mode == 'smilies') ? 'smilies' : 'icons';
ef5584
ef5584
		$this->tpl_name = 'acp_icons';
ef5584
ef5584
		// What are we working on?
ef5584
		switch ($mode)
ef5584
		{
ef5584
			case 'smilies':
ef5584
				$table = SMILIES_TABLE;
ef5584
				$lang = 'SMILIES';
ef5584
				$fields = 'smiley';
ef5584
				$img_path = $config['smilies_path'];
ef5584
			break;
ef5584
ef5584
			case 'icons':
ef5584
				$table = ICONS_TABLE;
ef5584
				$lang = 'ICONS';
ef5584
				$fields = 'icons';
ef5584
				$img_path = $config['icons_path'];
ef5584
			break;
ef5584
		}
ef5584
ef5584
		$this->page_title = 'ACP_' . $lang;
ef5584
ef5584
		// Clear some arrays
ef5584
		$_images = $_paks = array();
ef5584
		$notice = '';
ef5584
ef5584
		// Grab file list of paks and images
ef5584
		if ($action == 'edit' || $action == 'add' || $action == 'import')
ef5584
		{
ef5584
			$imglist = filelist($phpbb_root_path . $img_path, '');
ef5584
ef5584
			foreach ($imglist as $path => $img_ary)
ef5584
			{
ef5584
				if (empty($img_ary))
ef5584
				{
ef5584
					continue;
ef5584
				}
ef5584
ef5584
				asort($img_ary, SORT_STRING);
ef5584
ef5584
				foreach ($img_ary as $img)
ef5584
				{
ef5584
					$img_size = getimagesize($phpbb_root_path . $img_path . '/' . $path . $img);
ef5584
ef5584
					if (!$img_size[0] || !$img_size[1] || strlen($img) > 255)
ef5584
					{
ef5584
						continue;
ef5584
					}
ef5584
ef5584
					$_images[$path . $img]['file'] = $path . $img;
ef5584
					$_images[$path . $img]['width'] = $img_size[0];
ef5584
					$_images[$path . $img]['height'] = $img_size[1];
ef5584
				}
ef5584
			}
ef5584
			unset($imglist);
ef5584
ef5584
			if ($dir = @opendir($phpbb_root_path . $img_path))
ef5584
			{
ef5584
				while (($file = readdir($dir)) !== false)
ef5584
				{
ef5584
					if (is_file($phpbb_root_path . $img_path . '/' . $file) && preg_match('#\.pak$#i', $file))
ef5584
					{
ef5584
						$_paks[] = $file;
ef5584
					}
ef5584
				}
ef5584
				closedir($dir);
ef5584
ef5584
				if (!empty($_paks))
ef5584
				{
ef5584
					asort($_paks, SORT_STRING);
ef5584
				}
ef5584
			}
ef5584
		}
ef5584
ef5584
		// What shall we do today? Oops, I believe that's trademarked ...
ef5584
		switch ($action)
ef5584
		{
ef5584
			case 'edit':
ef5584
				unset($_images);
ef5584
				$_images = array();
ef5584
ef5584
			// no break;
ef5584
ef5584
			case 'add':
ef5584
ef5584
				$smilies = $default_row = array();
ef5584
				$smiley_options = $order_list = $add_order_list = '';
ef5584
ef5584
				if ($action == 'add' && $mode == 'smilies')
ef5584
				{
ef5584
					$sql = 'SELECT *
ef5584
						FROM ' . SMILIES_TABLE . '
ef5584
						ORDER BY smiley_order';
ef5584
					$result = $db->sql_query($sql);
ef5584
ef5584
					while ($row = $db->sql_fetchrow($result))
ef5584
					{
ef5584
						if (empty($smilies[$row['smiley_url']]))
ef5584
						{
ef5584
							$smilies[$row['smiley_url']] = $row;
ef5584
						}
ef5584
					}
ef5584
					$db->sql_freeresult($result);
ef5584
ef5584
					if (sizeof($smilies))
ef5584
					{
ef5584
						foreach ($smilies as $row)
ef5584
						{
ef5584
							$selected = false;
ef5584
ef5584
							if (!$smiley_options)
ef5584
							{
ef5584
								$selected = true;
ef5584
								$default_row = $row;
ef5584
							}
ef5584
							$smiley_options .= '<option value="' . $row['smiley_url'] . '"' . (($selected) ? ' selected="selected"' : '') . '>' . $row['smiley_url'] . '</option>';
ef5584
ef5584
							$template->assign_block_vars('smile', array(
ef5584
								'SMILEY_URL'	=> addslashes($row['smiley_url']),
ef5584
								'CODE'			=> addslashes($row['code']),
ef5584
								'EMOTION'		=> addslashes($row['emotion']),
ef5584
								'WIDTH'			=> $row['smiley_width'],
ef5584
								'HEIGHT'		=> $row['smiley_height'],
ef5584
								'ORDER'			=> $row['smiley_order'] + 1,
ef5584
							));
ef5584
						}
ef5584
					}
ef5584
				}
ef5584
				
ef5584
				$sql = "SELECT *
ef5584
					FROM $table
ef5584
					ORDER BY {$fields}_order " . (($icon_id || $action == 'add') ? 'DESC' : 'ASC');
ef5584
				$result = $db->sql_query($sql);
ef5584
				
ef5584
				$data = array();
ef5584
				$after = false;
ef5584
				$display = 0;
ef5584
				$order_lists = array('', '');
ef5584
				$add_order_lists = array('', '');
ef5584
				$display_count = 0;
ef5584
				
ef5584
				while ($row = $db->sql_fetchrow($result))
ef5584
				{
ef5584
					if ($action == 'add')
ef5584
					{
ef5584
						unset($_images[$row[$fields . '_url']]);
ef5584
					}
ef5584
ef5584
ef5584
					if ($row[$fields . '_id'] == $icon_id)
ef5584
					{
ef5584
						$after = true;
ef5584
						$display = $row['display_on_posting'];
ef5584
						$data[$row[$fields . '_url']] = $row;
ef5584
					}
ef5584
					else
ef5584
					{
ef5584
						if ($action == 'edit' && !$icon_id)
ef5584
						{
ef5584
							$data[$row[$fields . '_url']] = $row;
ef5584
						}
ef5584
ef5584
						$selected = '';
ef5584
						if (!empty($after))
ef5584
						{
ef5584
							$selected = ' selected="selected"';
ef5584
							$after = false;
ef5584
						}
ef5584
						if ($row['display_on_posting'])
ef5584
						{
ef5584
							$display_count++;
ef5584
						}
ef5584
						$after_txt = ($mode == 'smilies') ? $row['code'] : $row['icons_url'];
ef5584
						$order_lists[$row['display_on_posting']] = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . $selected . '>' . sprintf($user->lang['AFTER_' . $lang], ' -> ' . $after_txt) . '</option>' . $order_lists[$row['display_on_posting']];
ef5584
ef5584
						if (!empty($default_row))
ef5584
						{
ef5584
							$add_order_lists[$row['display_on_posting']] = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . (($row[$fields . '_id'] == $default_row['smiley_id']) ? ' selected="selected"' : '') . '>' . sprintf($user->lang['AFTER_' . $lang], ' -> ' . $after_txt) . '</option>' . $add_order_lists[$row['display_on_posting']];
ef5584
						}
ef5584
					}
ef5584
				}
ef5584
				$db->sql_freeresult($result);
ef5584
ef5584
				$order_list = '<option value="1"' . ((!isset($after)) ? ' selected="selected"' : '') . '>' . $user->lang['FIRST'] . '</option>';
ef5584
				$add_order_list = '<option value="1">' . $user->lang['FIRST'] . '</option>';
ef5584
ef5584
				if ($action == 'add')
ef5584
				{
ef5584
					$data = $_images;
ef5584
				}
ef5584
ef5584
				$colspan = (($mode == 'smilies') ? '7' : '5');
ef5584
				$colspan += ($icon_id) ? 1 : 0;
ef5584
				$colspan += ($action == 'add') ? 2 : 0;
ef5584
				
ef5584
				$template->assign_vars(array(
ef5584
					'S_EDIT'		=> true,
ef5584
					'S_SMILIES'		=> ($mode == 'smilies') ? true : false,
ef5584
					'S_ADD'			=> ($action == 'add') ? true : false,
ef5584
					
ef5584
					'S_ORDER_LIST_DISPLAY'		=> $order_list . $order_lists[1],
ef5584
					'S_ORDER_LIST_UNDISPLAY'	=> $order_list . $order_lists[0],
ef5584
					'S_ORDER_LIST_DISPLAY_COUNT'	=> $display_count + 1,
ef5584
ef5584
					'L_TITLE'		=> $user->lang['ACP_' . $lang],
ef5584
					'L_EXPLAIN'		=> $user->lang['ACP_' . $lang . '_EXPLAIN'],
ef5584
					'L_CONFIG'		=> $user->lang[$lang . '_CONFIG'],
ef5584
					'L_URL'			=> $user->lang[$lang . '_URL'],
ef5584
					'L_LOCATION'	=> $user->lang[$lang . '_LOCATION'],
ef5584
					'L_WIDTH'		=> $user->lang[$lang . '_WIDTH'],
ef5584
					'L_HEIGHT'		=> $user->lang[$lang . '_HEIGHT'],
ef5584
					'L_ORDER'		=> $user->lang[$lang . '_ORDER'],
ef5584
					'L_NO_ICONS'	=> $user->lang['NO_' . $lang . '_' . strtoupper($action)],
ef5584
ef5584
					'COLSPAN'		=> $colspan,
ef5584
					'ID'			=> $icon_id,
ef5584
ef5584
					'U_BACK'		=> $this->u_action,
ef5584
					'U_ACTION'		=> $this->u_action . '&action=' . (($action == 'add') ? 'create' : 'modify'),
ef5584
				));
ef5584
ef5584
				foreach ($data as $img => $img_row)
ef5584
				{
ef5584
					$template->assign_block_vars('items', array(
ef5584
						'IMG'		=> $img,
ef5584
						'A_IMG'		=> addslashes($img),
ef5584
						'IMG_SRC'	=> $phpbb_root_path . $img_path . '/' . $img,
ef5584
ef5584
						'CODE'		=> ($mode == 'smilies' && isset($img_row['code'])) ? $img_row['code'] : '',
ef5584
						'EMOTION'	=> ($mode == 'smilies' && isset($img_row['emotion'])) ? $img_row['emotion'] : '',
ef5584
ef5584
						'S_ID'				=> (isset($img_row[$fields . '_id'])) ? true : false,
ef5584
						'ID'				=> (isset($img_row[$fields . '_id'])) ? $img_row[$fields . '_id'] : 0,
ef5584
						'WIDTH'				=> (!empty($img_row[$fields .'_width'])) ? $img_row[$fields .'_width'] : $img_row['width'],
ef5584
						'HEIGHT'			=> (!empty($img_row[$fields .'_height'])) ? $img_row[$fields .'_height'] : $img_row['height'],
ef5584
						'POSTING_CHECKED'	=> (!empty($img_row['display_on_posting']) || $action == 'add') ? ' checked="checked"' : '',
ef5584
					));
ef5584
				}
ef5584
ef5584
				// Ok, another row for adding an addition code for a pre-existing image...
ef5584
				if ($action == 'add' && $mode == 'smilies' && sizeof($smilies))
ef5584
				{
ef5584
					$template->assign_vars(array(
ef5584
						'S_ADD_CODE'		=> true,
ef5584
ef5584
						'S_IMG_OPTIONS'		=> $smiley_options,
ef5584
						
ef5584
						'S_ADD_ORDER_LIST_DISPLAY'		=> $add_order_list . $add_order_lists[1],
ef5584
						'S_ADD_ORDER_LIST_UNDISPLAY'	=> $add_order_list . $add_order_lists[0],
ef5584
						
ef5584
						'IMG_SRC'			=> $phpbb_root_path . $img_path . '/' . $default_row['smiley_url'],
ef5584
						'IMG_PATH'			=> $img_path,
ef5584
						'PHPBB_ROOT_PATH'	=> $phpbb_root_path,
ef5584
ef5584
						'CODE'				=> $default_row['code'],
ef5584
						'EMOTION'			=> $default_row['emotion'],
ef5584
ef5584
						'WIDTH'				=> $default_row['smiley_width'],
ef5584
						'HEIGHT'			=> $default_row['smiley_height'],
ef5584
					));
ef5584
				}
ef5584
ef5584
				return;
ef5584
	
ef5584
			break;
ef5584
ef5584
			case 'create':
ef5584
			case 'modify':
ef5584
ef5584
				// Get items to create/modify
ef5584
				$images = (isset($_POST['image'])) ? array_keys(request_var('image', array('' => 0))) : array();
ef5584
				
ef5584
				// Now really get the items
ef5584
				$image_id		= (isset($_POST['id'])) ? request_var('id', array('' => 0)) : array();
ef5584
				$image_order	= (isset($_POST['order'])) ? request_var('order', array('' => 0)) : array();
ef5584
				$image_width	= (isset($_POST['width'])) ? request_var('width', array('' => 0)) : array();
ef5584
				$image_height	= (isset($_POST['height'])) ? request_var('height', array('' => 0)) : array();
ef5584
				$image_add		= (isset($_POST['add_img'])) ? request_var('add_img', array('' => 0)) : array();
ef5584
				$image_emotion	= utf8_normalize_nfc(request_var('emotion', array('' => ''), true));
ef5584
				$image_code		= utf8_normalize_nfc(request_var('code', array('' => ''), true));
ef5584
				$image_display_on_posting = (isset($_POST['display_on_posting'])) ? request_var('display_on_posting', array('' => 0)) : array();
ef5584
ef5584
				// Ok, add the relevant bits if we are adding new codes to existing emoticons...
ef5584
				if (!empty($_POST['add_additional_code']))
ef5584
				{
ef5584
					$add_image			= request_var('add_image', '');
ef5584
					$add_code			= utf8_normalize_nfc(request_var('add_code', '', true));
ef5584
					$add_emotion		= utf8_normalize_nfc(request_var('add_emotion', '', true));
ef5584
ef5584
					if ($add_image && $add_emotion && $add_code)
ef5584
					{
ef5584
						$images[] = $add_image;
ef5584
						$image_add[$add_image] = true;
ef5584
ef5584
						$image_code[$add_image] = $add_code;
ef5584
						$image_emotion[$add_image] = $add_emotion;
ef5584
						$image_width[$add_image] = request_var('add_width', 0);
ef5584
						$image_height[$add_image] = request_var('add_height', 0);
ef5584
ef5584
						if (!empty($_POST['add_display_on_posting']))
ef5584
						{
ef5584
							$image_display_on_posting[$add_image] = 1;
ef5584
						}
ef5584
ef5584
						$image_order[$add_image] = request_var('add_order', 0);
ef5584
					}
ef5584
				}
ef5584
ef5584
				$icons_updated = 0;
ef5584
				$errors = array();
ef5584
				foreach ($images as $image)
ef5584
				{
ef5584
					if ($mode == 'smilies' && ($image_emotion[$image] == '' || $image_code[$image] == ''))
ef5584
					{
ef5584
						$errors[$image] = 'SMILIE_NO_' . (($image_emotion[$image] == '') ? 'EMOTION' : 'CODE');
ef5584
					}
ef5584
					else if ($action == 'create' && !isset($image_add[$image]))
ef5584
					{
ef5584
						// skip images where add wasn't checked
ef5584
					}
ef5584
					else
ef5584
					{
ef5584
						if ($image_width[$image] == 0 || $image_height[$image] == 0)
ef5584
						{
ef5584
							$img_size = getimagesize($phpbb_root_path . $img_path . '/' . $image);
ef5584
							$image_width[$image] = $img_size[0];
ef5584
							$image_height[$image] = $img_size[1];
ef5584
						}
ef5584
ef5584
						$img_sql = array(
ef5584
							$fields . '_url'		=> $image,
ef5584
							$fields . '_width'		=> $image_width[$image],
ef5584
							$fields . '_height'		=> $image_height[$image],
ef5584
							'display_on_posting'	=> (isset($image_display_on_posting[$image])) ? 1 : 0,
ef5584
						);
ef5584
ef5584
						if ($mode == 'smilies')
ef5584
						{
ef5584
							$img_sql = array_merge($img_sql, array(
ef5584
								'emotion'	=> $image_emotion[$image],
ef5584
								'code'		=> $image_code[$image])
ef5584
							);
ef5584
						}
ef5584
ef5584
						// Image_order holds the 'new' order value
ef5584
						if (!empty($image_order[$image]))
ef5584
						{
ef5584
							$img_sql = array_merge($img_sql, array(
ef5584
								$fields . '_order'	=>	$image_order[$image])
ef5584
							);
ef5584
ef5584
							// Since we always add 'after' an item, we just need to increase all following + the current by one
ef5584
							$sql = "UPDATE $table
ef5584
								SET {$fields}_order = {$fields}_order + 1
ef5584
								WHERE {$fields}_order >= {$image_order[$image]}";
ef5584
							$db->sql_query($sql);
ef5584
ef5584
							// If we adjust the order, we need to adjust all other orders too - they became inaccurate...
ef5584
							foreach ($image_order as $_image => $_order)
ef5584
							{
ef5584
								if ($_image == $image)
ef5584
								{
ef5584
									continue;
ef5584
								}
ef5584
ef5584
								if ($_order >= $image_order[$image])
ef5584
								{
ef5584
									$image_order[$_image]++;
ef5584
								}
ef5584
							}
ef5584
						}
ef5584
ef5584
						if ($action == 'modify'  && !empty($image_id[$image]))
ef5584
						{
ef5584
							$sql = "UPDATE $table
ef5584
								SET " . $db->sql_build_array('UPDATE', $img_sql) . "
ef5584
								WHERE {$fields}_id = " . $image_id[$image];
ef5584
							$db->sql_query($sql);
ef5584
							$icons_updated++;
ef5584
						}
ef5584
						else if ($action !== 'modify')
ef5584
						{
ef5584
							$sql = "INSERT INTO $table " . $db->sql_build_array('INSERT', $img_sql);
ef5584
							$db->sql_query($sql);
ef5584
							$icons_updated++;
ef5584
						}
ef5584
						
ef5584
 					}
ef5584
				}
ef5584
				
ef5584
				$cache->destroy('_icons');
ef5584
				$cache->destroy('sql', $table);
ef5584
				
ef5584
				$level = E_USER_NOTICE;
ef5584
				switch ($icons_updated)
ef5584
				{
ef5584
					case 0:
ef5584
						$suc_lang = "{$lang}_NONE";
ef5584
						$level = E_USER_WARNING;
ef5584
						break;
ef5584
						
ef5584
					case 1:
ef5584
						$suc_lang = "{$lang}_ONE";
ef5584
						break;
ef5584
						
ef5584
					default:
ef5584
						$suc_lang = $lang;
ef5584
				}
ef5584
				$errormsgs = '';
ef5584
				foreach ($errors as $img => $error)
ef5584
				{
ef5584
					$errormsgs .= '
' . sprintf($user->lang[$error], $img);
ef5584
				}
ef5584
				if ($action == 'modify')
ef5584
				{
ef5584
					trigger_error($user->lang[$suc_lang . '_EDITED'] . $errormsgs . adm_back_link($this->u_action), $level);
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					trigger_error($user->lang[$suc_lang . '_ADDED'] . $errormsgs . adm_back_link($this->u_action), $level);
ef5584
				}
ef5584
ef5584
			break;
ef5584
ef5584
			case 'import':
ef5584
ef5584
				$pak = request_var('pak', '');
ef5584
				$current = request_var('current', '');
ef5584
ef5584
				if ($pak != '')
ef5584
				{
ef5584
					$order = 0;
ef5584
ef5584
					if (!($pak_ary = @file($phpbb_root_path . $img_path . '/' . $pak)))
ef5584
					{
ef5584
						trigger_error($user->lang['PAK_FILE_NOT_READABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
					}
ef5584
ef5584
					// Make sure the pak_ary is valid
ef5584
					foreach ($pak_ary as $pak_entry)
ef5584
					{
ef5584
						if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data))
ef5584
						{
ef5584
							if ((sizeof($data[1]) != 4 && $mode == 'icons') ||
ef5584
								((sizeof($data[1]) != 6 || (empty($data[1][4]) || empty($data[1][5]))) && $mode == 'smilies' ))
ef5584
							{
ef5584
								trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
							}
ef5584
						}
ef5584
						else
ef5584
						{
ef5584
							trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
						}
ef5584
					}
ef5584
ef5584
ef5584
					// The user has already selected a smilies_pak file
ef5584
					if ($current == 'delete')
ef5584
					{
ef5584
						switch ($db->sql_layer)
ef5584
						{
ef5584
							case 'sqlite':
ef5584
							case 'firebird':
ef5584
								$db->sql_query('DELETE FROM ' . $table);
ef5584
							break;
ef5584
ef5584
							default:
ef5584
								$db->sql_query('TRUNCATE TABLE ' . $table);
ef5584
							break;
ef5584
						}
ef5584
ef5584
						switch ($mode)
ef5584
						{
ef5584
							case 'smilies':
ef5584
							break;
ef5584
ef5584
							case 'icons':
ef5584
								// Reset all icon_ids
ef5584
								$db->sql_query('UPDATE ' . TOPICS_TABLE . ' SET icon_id = 0');
ef5584
								$db->sql_query('UPDATE ' . POSTS_TABLE . ' SET icon_id = 0');
ef5584
							break;
ef5584
						}
ef5584
					}
ef5584
					else
ef5584
					{
ef5584
						$cur_img = array();
ef5584
ef5584
						$field_sql = ($mode == 'smilies') ? 'code' : 'icons_url';
ef5584
ef5584
						$sql = "SELECT $field_sql
ef5584
							FROM $table";
ef5584
						$result = $db->sql_query($sql);
ef5584
ef5584
						while ($row = $db->sql_fetchrow($result))
ef5584
						{
ef5584
							++$order;
ef5584
							$cur_img[$row[$field_sql]] = 1;
ef5584
						}
ef5584
						$db->sql_freeresult($result);
ef5584
					}
ef5584
ef5584
					foreach ($pak_ary as $pak_entry)
ef5584
					{
ef5584
						$data = array();
ef5584
						if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data))
ef5584
						{
ef5584
							if ((sizeof($data[1]) != 4 && $mode == 'icons') ||
ef5584
								(sizeof($data[1]) != 6 && $mode == 'smilies'))
ef5584
							{
ef5584
								trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
							}
ef5584
ef5584
							// Stripslash here because it got addslashed before... (on export)
ef5584
							$img = stripslashes($data[1][0]);
ef5584
							$width = stripslashes($data[1][1]);
ef5584
							$height = stripslashes($data[1][2]);
ef5584
							$display_on_posting = stripslashes($data[1][3]);
ef5584
ef5584
							if (isset($data[1][4]) && isset($data[1][5]))
ef5584
							{
ef5584
								$emotion = stripslashes($data[1][4]);
ef5584
								$code = stripslashes($data[1][5]);
ef5584
							}
ef5584
ef5584
							if ($current == 'replace' &&
ef5584
								(($mode == 'smilies' && !empty($cur_img[$code])) ||
ef5584
								($mode == 'icons' && !empty($cur_img[$img]))))
ef5584
							{
ef5584
								$replace_sql = ($mode == 'smilies') ? $code : $img;
ef5584
								$sql = array(
ef5584
									$fields . '_url'		=> $img,
ef5584
									$fields . '_height'		=> (int) $height,
ef5584
									$fields . '_width'		=> (int) $width,
ef5584
									'display_on_posting'	=> (int) $display_on_posting,
ef5584
								);
ef5584
ef5584
								if ($mode == 'smilies')
ef5584
								{
ef5584
									$sql = array_merge($sql, array(
ef5584
										'emotion'				=> $emotion,
ef5584
									));
ef5584
								}
ef5584
ef5584
								$sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql) . "
ef5584
									WHERE $field_sql = '" . $db->sql_escape($replace_sql) . "'";
ef5584
								$db->sql_query($sql);
ef5584
							}
ef5584
							else
ef5584
							{
ef5584
								++$order;
ef5584
ef5584
								$sql = array(
ef5584
									$fields . '_url'	=> $img,
ef5584
									$fields . '_height'	=> (int) $height,
ef5584
									$fields . '_width'	=> (int) $width,
ef5584
									$fields . '_order'	=> (int) $order,
ef5584
									'display_on_posting'=> (int) $display_on_posting,
ef5584
								);
ef5584
ef5584
								if ($mode == 'smilies')
ef5584
								{
ef5584
									$sql = array_merge($sql, array(
ef5584
										'code'				=> $code,
ef5584
										'emotion'			=> $emotion,
ef5584
									));
ef5584
								}
ef5584
								$db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql));
ef5584
							}
ef5584
						}
ef5584
					}
ef5584
ef5584
					$cache->destroy('_icons');
ef5584
					$cache->destroy('sql', $table);
ef5584
ef5584
					trigger_error($user->lang[$lang . '_IMPORT_SUCCESS'] . adm_back_link($this->u_action));
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					$pak_options = '';
ef5584
ef5584
					foreach ($_paks as $pak)
ef5584
					{
ef5584
						$pak_options .= '<option value="' . $pak . '">' . htmlspecialchars($pak) . '</option>';
ef5584
					}
ef5584
ef5584
					$template->assign_vars(array(
ef5584
						'S_CHOOSE_PAK'		=> true,
ef5584
						'S_PAK_OPTIONS'		=> $pak_options,
ef5584
ef5584
						'L_TITLE'			=> $user->lang['ACP_' . $lang],
ef5584
						'L_EXPLAIN'			=> $user->lang['ACP_' . $lang . '_EXPLAIN'],
ef5584
						'L_NO_PAK_OPTIONS'	=> $user->lang['NO_' . $lang . '_PAK'],
ef5584
						'L_CURRENT'			=> $user->lang['CURRENT_' . $lang],
ef5584
						'L_CURRENT_EXPLAIN'	=> $user->lang['CURRENT_' . $lang . '_EXPLAIN'],
ef5584
						'L_IMPORT_SUBMIT'	=> $user->lang['IMPORT_' . $lang],
ef5584
ef5584
						'U_BACK'		=> $this->u_action,
ef5584
						'U_ACTION'		=> $this->u_action . '&action=import',
ef5584
						)
ef5584
					);
ef5584
				}
ef5584
			break;
ef5584
ef5584
			case 'export':
ef5584
ef5584
				$this->page_title = 'EXPORT_' . $lang;
ef5584
				$this->tpl_name = 'message_body';
ef5584
ef5584
				$template->assign_vars(array(
ef5584
					'MESSAGE_TITLE'		=> $user->lang['EXPORT_' . $lang],
ef5584
					'MESSAGE_TEXT'		=> sprintf($user->lang['EXPORT_' . $lang . '_EXPLAIN'], '', ''),
ef5584
ef5584
					'S_USER_NOTICE'		=> true,
ef5584
					)
ef5584
				);
ef5584
ef5584
				return;
ef5584
ef5584
			break;
ef5584
ef5584
			case 'send':
ef5584
ef5584
				$sql = "SELECT *
ef5584
					FROM $table
ef5584
					ORDER BY {$fields}_order";
ef5584
				$result = $db->sql_query($sql);
ef5584
ef5584
				$pak = '';
ef5584
				while ($row = $db->sql_fetchrow($result))
ef5584
				{
ef5584
					$pak .= "'" . addslashes($row[$fields . '_url']) . "', ";
ef5584
					$pak .= "'" . addslashes($row[$fields . '_width']) . "', ";
ef5584
					$pak .= "'" . addslashes($row[$fields . '_height']) . "', ";
ef5584
					$pak .= "'" . addslashes($row['display_on_posting']) . "', ";
ef5584
ef5584
					if ($mode == 'smilies')
ef5584
					{
ef5584
						$pak .= "'" . addslashes($row['emotion']) . "', ";
ef5584
						$pak .= "'" . addslashes($row['code']) . "', ";
ef5584
					}
ef5584
ef5584
					$pak .= "\n";
ef5584
				}
ef5584
				$db->sql_freeresult($result);
ef5584
ef5584
				if ($pak != '')
ef5584
				{
ef5584
					garbage_collection();
ef5584
ef5584
					header('Pragma: public');
ef5584
ef5584
					// Send out the Headers
ef5584
					header('Content-Type: text/x-delimtext; name="' . $mode . '.pak"');
ef5584
					header('Content-Disposition: inline; filename="' . $mode . '.pak"');
ef5584
					echo $pak;
ef5584
ef5584
					flush();
ef5584
					exit;
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					trigger_error($user->lang['NO_' . strtoupper($fields) . '_EXPORT'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
				}
ef5584
ef5584
			break;
ef5584
ef5584
			case 'delete':
ef5584
ef5584
				if (confirm_box(true))
ef5584
				{
ef5584
					$sql = "DELETE FROM $table
ef5584
						WHERE {$fields}_id = $icon_id";
ef5584
					$db->sql_query($sql);
ef5584
ef5584
					switch ($mode)
ef5584
					{
ef5584
						case 'smilies':
ef5584
						break;
ef5584
ef5584
						case 'icons':
ef5584
							// Reset appropriate icon_ids
ef5584
							$db->sql_query('UPDATE ' . TOPICS_TABLE . "
ef5584
								SET icon_id = 0
ef5584
								WHERE icon_id = $icon_id");
ef5584
ef5584
							$db->sql_query('UPDATE ' . POSTS_TABLE . "
ef5584
								SET icon_id = 0
ef5584
								WHERE icon_id = $icon_id");
ef5584
						break;
ef5584
					}
ef5584
ef5584
					$notice = $user->lang[$lang . '_DELETED'];
ef5584
ef5584
					$cache->destroy('_icons');
ef5584
					$cache->destroy('sql', $table);
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
ef5584
						'i'			=> $id,
ef5584
						'mode'		=> $mode,
ef5584
						'id'		=> $icon_id,
ef5584
						'action'	=> 'delete',
ef5584
					)));
ef5584
				}
ef5584
ef5584
			break;
ef5584
ef5584
			case 'move_up':
ef5584
			case 'move_down':
ef5584
ef5584
				// Get current order id...
ef5584
				$sql = "SELECT {$fields}_order as current_order
ef5584
					FROM $table
ef5584
					WHERE {$fields}_id = $icon_id";
ef5584
				$result = $db->sql_query($sql);
ef5584
				$current_order = (int) $db->sql_fetchfield('current_order');
ef5584
				$db->sql_freeresult($result);
ef5584
ef5584
				if ($current_order == 0 && $action == 'move_up')
ef5584
				{
ef5584
					break;
ef5584
				}
ef5584
ef5584
				// on move_down, switch position with next order_id...
ef5584
				// on move_up, switch position with previous order_id...
ef5584
				$switch_order_id = ($action == 'move_down') ? $current_order + 1 : $current_order - 1;
ef5584
ef5584
				//
ef5584
				$sql = "UPDATE $table
ef5584
					SET {$fields}_order = $current_order
ef5584
					WHERE {$fields}_order = $switch_order_id
ef5584
						AND {$fields}_id <> $icon_id";
ef5584
				$db->sql_query($sql);
ef5584
ef5584
				// Only update the other entry too if the previous entry got updated
ef5584
				if ($db->sql_affectedrows())
ef5584
				{
ef5584
					$sql = "UPDATE $table
ef5584
						SET {$fields}_order = $switch_order_id
ef5584
						WHERE {$fields}_order = $current_order
ef5584
							AND {$fields}_id = $icon_id";
ef5584
					$db->sql_query($sql);
ef5584
				}
ef5584
ef5584
				$cache->destroy('_icons');
ef5584
				$cache->destroy('sql', $table);
ef5584
ef5584
			break;
ef5584
		}
ef5584
ef5584
		// By default, check that image_order is valid and fix it if necessary
ef5584
		$sql = "SELECT {$fields}_id AS order_id, {$fields}_order AS fields_order
ef5584
			FROM $table
ef5584
			ORDER BY display_on_posting DESC, {$fields}_order";
ef5584
		$result = $db->sql_query($sql);
ef5584
ef5584
		if ($row = $db->sql_fetchrow($result))
ef5584
		{
ef5584
			$order = 0;
ef5584
			do
ef5584
			{
ef5584
				++$order;
ef5584
				if ($row['fields_order'] != $order)
ef5584
				{
ef5584
					$db->sql_query("UPDATE $table
ef5584
						SET {$fields}_order = $order
ef5584
						WHERE {$fields}_id = " . $row['order_id']);
ef5584
				}
ef5584
			}
ef5584
			while ($row = $db->sql_fetchrow($result));
ef5584
		}
ef5584
		$db->sql_freeresult($result);
ef5584
ef5584
		$template->assign_vars(array(
ef5584
			'L_TITLE'			=> $user->lang['ACP_' . $lang],
ef5584
			'L_EXPLAIN'			=> $user->lang['ACP_' . $lang . '_EXPLAIN'],
ef5584
			'L_IMPORT'			=> $user->lang['IMPORT_' . $lang],
ef5584
			'L_EXPORT'			=> $user->lang['EXPORT_' . $lang],
ef5584
			'L_NOT_DISPLAYED'	=> $user->lang[$lang . '_NOT_DISPLAYED'],
ef5584
			'L_ICON_ADD'		=> $user->lang['ADD_' . $lang],
ef5584
			'L_ICON_EDIT'		=> $user->lang['EDIT_' . $lang],
ef5584
ef5584
			'NOTICE'			=> $notice,
ef5584
			'COLSPAN'			=> ($mode == 'smilies') ? 5 : 3,
ef5584
ef5584
			'S_SMILIES'			=> ($mode == 'smilies') ? true : false,
ef5584
ef5584
			'U_ACTION'			=> $this->u_action,
ef5584
			'U_IMPORT'			=> $this->u_action . '&action=import',
ef5584
			'U_EXPORT'			=> $this->u_action . '&action=export',
ef5584
			)
ef5584
		);
ef5584
ef5584
		$spacer = false;
ef5584
ef5584
		$sql = "SELECT *
ef5584
			FROM $table
ef5584
			ORDER BY {$fields}_order ASC";
ef5584
		$result = $db->sql_query($sql);
ef5584
ef5584
		while ($row = $db->sql_fetchrow($result))
ef5584
		{
ef5584
			$alt_text = ($mode == 'smilies') ? $row['code'] : '';
ef5584
ef5584
			$template->assign_block_vars('items', array(
ef5584
				'S_SPACER'		=> (!$spacer && !$row['display_on_posting']) ? true : false,
ef5584
				'ALT_TEXT'		=> $alt_text,
ef5584
				'IMG_SRC'		=> $phpbb_root_path . $img_path . '/' . $row[$fields . '_url'],
ef5584
				'WIDTH'			=> $row[$fields . '_width'],
ef5584
				'HEIGHT'		=> $row[$fields . '_height'],
ef5584
				'CODE'			=> (isset($row['code'])) ? $row['code'] : '',
ef5584
				'EMOTION'		=> (isset($row['emotion'])) ? $row['emotion'] : '',
ef5584
				'U_EDIT'		=> $this->u_action . '&action=edit&id=' . $row[$fields . '_id'],
ef5584
				'U_DELETE'		=> $this->u_action . '&action=delete&id=' . $row[$fields . '_id'],
ef5584
				'U_MOVE_UP'		=> $this->u_action . '&action=move_up&id=' . $row[$fields . '_id'],
ef5584
				'U_MOVE_DOWN'	=> $this->u_action . '&action=move_down&id=' . $row[$fields . '_id'])
ef5584
			);
ef5584
ef5584
			if (!$spacer && !$row['display_on_posting'])
ef5584
			{
ef5584
				$spacer = true;
ef5584
			}
ef5584
		}
ef5584
		$db->sql_freeresult($result);
ef5584
	}
ef5584
}
ef5584
ef5584
?>