mass add/edit smilies and icons

git-svn-id: file:///svn/phpbb/trunk@4613 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2003-10-19 15:26:14 +00:00
parent 5ea7428e1b
commit de53ffabb4

View file

@ -1,23 +1,15 @@
<?php <?php
/*************************************************************************** // -------------------------------------------------------------
* admin_icons.php //
* ------------------- // $Id$
* begin : Thu May 31, 2001 //
* copyright : (C) 2001 The phpBB Group // FILENAME : admin_icons.php
* email : support@phpbb.com // STARTED : Thu Mar 13, 2003
* // COPYRIGHT : © 2001, 2003 phpBB Group
* $Id$ // WWW : http://www.phpbb.com/
* // LICENCE : GPL vs2.0 [ see /docs/COPYING ]
****************************************************************************/ //
// -------------------------------------------------------------
/***************************************************************************
*
* 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.
*
***************************************************************************/
if (!empty($setmodules)) if (!empty($setmodules))
{ {
@ -27,15 +19,15 @@ if (!empty($setmodules))
} }
$filename = basename(__FILE__); $filename = basename(__FILE__);
$module['POST']['SMILE'] = $filename . $SID . '&amp;mode=emoticons'; $module['POST']['SMILE'] = "$filename$SID&amp;mode=emoticons";
$module['POST']['ICONS'] = $filename . $SID . '&amp;mode=icons'; $module['POST']['ICONS'] = "$filename$SID&amp;mode=icons";
return; return;
} }
define('IN_PHPBB', 1); define('IN_PHPBB', 1);
// Include files // Include files
$phpbb_root_path = '../'; $phpbb_root_path = './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1); $phpEx = substr(strrchr(__FILE__, '.'), 1);
require('pagestart.' . $phpEx); require('pagestart.' . $phpEx);
@ -46,9 +38,11 @@ if (!$auth->acl_get('a_icons'))
} }
// Grab some basic parameters // Grab some basic parameters
$mode = (!empty($_REQUEST['mode'])) ? $_REQUEST['mode'] : ''; $mode = request_var('mode', '');
$action = (!empty($_REQUEST['action'])) ? $_REQUEST['action'] : ((isset($_POST['add'])) ? 'add' : ''); $action = request_var('action', '');
$id = (isset($_GET['id'])) ? intval($_GET['id']) : false; $action = (isset($_POST['add'])) ? 'add' : $action;
$action = (isset($_POST['edit'])) ? 'edit' : $action;
$id = request_var('id', 0);
// What are we working on? // What are we working on?
switch ($mode) switch ($mode)
@ -70,27 +64,33 @@ switch ($mode)
// Clear some arrays // Clear some arrays
$_images = $_paks = array(); $_images = $_paks = array();
$notice = '';
// Grab file list of paks and images // Grab file list of paks and images
if ($action == 'edit' || $action == 'add' || $action == 'import') 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); $dir = @opendir($phpbb_root_path . $img_path);
while ($file = @readdir($dir)) 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); $_paks[] = $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;
}
} }
} }
@closedir($dir); @closedir($dir);
@ -100,51 +100,40 @@ if ($action == 'edit' || $action == 'add' || $action == 'import')
// What shall we do today? Oops, I believe that's trademarked ... // What shall we do today? Oops, I believe that's trademarked ...
switch ($action) 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': case 'edit':
unset($_images);
$_images = array();
case 'add': case 'add':
$order_list = ''; $order_list = '';
$existing_imgs = array();
$result = $db->sql_query('SELECT * $sql = "SELECT *
FROM ' . $table . ' FROM $table
ORDER BY ' . $fields . '_order DESC'); ORDER BY {$fields}_order " . (($id || $action == 'add') ? 'DESC' : 'ASC');
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result)) if ($row = $db->sql_fetchrow($result))
{ {
do do
{ {
$existing_imgs[] = $row[$fields . '_url']; if ($action == 'add')
{
unset($_images[$row[$fields . '_url']]);
}
if ($row[$fields . '_id'] == $id) if ($row[$fields . '_id'] == $id)
{ {
$after = TRUE; $after = TRUE;
$data = $row; $data[$row[$fields . '_url']] = $row;
} }
else else
{ {
if ($action == 'edit' && !$id)
{
$data[$row[$fields . '_url']] = $row;
}
$selected = ''; $selected = '';
if (!empty($after)) if (!empty($after))
{ {
@ -161,36 +150,16 @@ switch ($action)
$db->sql_freeresult($result); $db->sql_freeresult($result);
$order_list = '<option value="1"' . ((!isset($after)) ? ' selected="selected"' : '') . '>' . $user->lang['FIRST'] . '</option>' . $order_list; $order_list = '<option value="1"' . ((!isset($after)) ? ' selected="selected"' : '') . '>' . $user->lang['FIRST'] . '</option>' . $order_list;
$imglist = filelist($phpbb_root_path . $img_path, '');
$filename_list = ''; if ($action == 'add')
foreach ($imglist as $path => $img_ary)
{ {
foreach ($img_ary as $img) $data = $_images;
{
$img = "$path$img";
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 = '';
}
$filename_list .= '<option value="' . $img . '"' . htmlspecialchars($img) . $selected . '>' . $img . '</option>';
}
}
} }
unset($existing_imgs);
unset($imglist); $colspan = (($mode == 'emoticons') ? '7' : '5');
$colspan += ($id) ? 1 : 0;
$colspan += ($action == 'add') ? 2 : 0;
adm_page_header($user->lang[$lang]); adm_page_header($user->lang[$lang]);
?> ?>
@ -199,78 +168,97 @@ switch ($action)
<p><?php echo $user->lang[$lang .'_EXPLAIN']; ?></p> <p><?php echo $user->lang[$lang .'_EXPLAIN']; ?></p>
<script language="javascript" type="text/javascript" defer="defer"> <form method="post" action="admin_icons.<?php echo $phpEx . $SID . "&amp;mode=$mode&amp;action=" . (($action == 'add') ? 'create' : 'modify'); ?>">
<!-- <table class="bg" cellspacing="1" cellpadding="4" border="0" align="center">
<tr>
function update_image(newimage) <th colspan="<?php echo $colspan; ?>"><?php echo $user->lang[$lang . '_CONFIG'] ?></th>
{ </tr>
document.image.src = "<?php echo $phpbb_root_path . $img_path ?>/" + newimage; <tr>
} <td class="cat"><?php echo $user->lang[$lang . '_URL'] ?></td>
<td class="cat"><?php echo $user->lang[$lang . '_LOCATION'] ?></td>
function update_image_dimensions() <?php
{ if ($mode == 'emoticons')
if (document.image.height)
{ {
document.forms[0].height.value = document.image.height; ?>
document.forms[0].width.value = document.image.width; <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>
</script> <td class="cat"><?php echo $user->lang['DISPLAY_ON_POSTING'] ?></td>
<?php
<form method="post" action="admin_icons.<?php echo $phpEx . $SID . "&amp;mode=$mode&amp;action=" . (($action == 'add') ? 'create' : 'modify'); ?>"><table class="bg" cellspacing="1" cellpadding="4" border="0" align="center"> if ($id || $action == 'add')
<tr> {
<th colspan="2"><?php echo $user->lang[$lang . '_CONFIG'] ?></th> ?>
</tr> <td class="cat"><?php echo $user->lang[$lang . '_ORDER'] ?></td>
<tr> <?php
<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> &nbsp; <img src="<?php echo $phpbb_root_path . $img_path . '/' . $edit_img ?>" name="image" border="0" alt="" title="" onload="update_image_dimensions()" /> &nbsp;</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 <?php
if ($mode == 'emoticons') if ($mode == 'emoticons')
{ {
?> ?>
<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="row1"><?php echo $user->lang[$lang . '_CODE'] ?></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>
<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>
<?php <?php
} }
?> ?>
<tr> <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="row1"><?php echo $user->lang[$lang . '_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="row2"><input class="post" type="text" size="3" name="width" value="<?php echo (!empty($data[$fields .'_width'])) ? $data[$fields .'_width'] : '' ?>" /></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>
</tr> <?php
<tr> if ($id || $action == 'add')
<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> <td class="<?php echo $row_class; ?>"><select name="order[<?php echo $img; ?>]"><?php echo $order_list ?></select></td>
<tr> <?php
<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> if ($action == 'add')
<tr> {
<td class="row1"><?php echo $user->lang[$lang . '_ORDER'] ?></td> ?>
<td class="row2"><select name="order"><?php echo $order_list ?></select></td> <td class="<?php echo $row_class; ?>"><input type="checkbox" name="add_img[<?php echo $img; ?>]" value="1" /><?php
</tr>
<tr>
<td class="cat" colspan="2" align="center"><?php
if (!empty($data))
{
?><input type="hidden" name="id" value="<?php echo $data[$fields . '_id'] ?>" /><?php
} }
?>
</tr>
<?php
if (isset($img_row[$fields . '_id']))
{
?><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> ?><input class="btnmain" type="submit" value="<?php echo $user->lang['SUBMIT'] ?>" /></td>
</tr> </tr>
@ -283,100 +271,135 @@ function update_image_dimensions()
case 'create': case 'create':
case 'modify': case 'modify':
$image_id = intval($_POST['id']); // Get items to create/modify
$img = stripslashes($_POST['img']); $images = (isset($_POST['image'])) ? array_keys($_POST['image']) : array();
$image_order = intval($_POST['order']);
$image_width = intval($_POST['width']); // Now really get the items
$image_height = intval($_POST['height']); $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();
if ($image_width == 0 || $image_height == 0) foreach ($images as $image)
{ {
$img_size = @getimagesize($phpbb_root_path . $img_path . '/' . $img); if (($mode == 'emoticons' && ($image_emotion[$image] == '' || $image_code[$image] == '')) ||
$smile_width = $img_size[0]; ($action == 'create' && !isset($image_add[$image])))
$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')
{
$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)
{ {
$no_update = TRUE;
}
if ($order_old > $image_order)
{
$sign = '+';
$where = $fields . "_order >= $image_order AND " . $fields . "_order < $order_old";
} }
else else
{ {
$sign = '-'; if ($image_width[$image] == 0 || $image_height[$image] == 0)
$where = $fields . "_order > $order_old AND " . $fields . "_order < $image_order"; {
$sql[$fields . '_order'] = $image_order - 1; $img_size = @getimagesize($phpbb_root_path . $img_path . '/' . $image);
$image_width[$image] = $img_size[0];
$image_height[$image] = $img_size[1];
}
$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);
}
} }
} }
else
{ $cache->destroy('icons');
$sign = '+';
$where = $fields . "_order > $image_order";
}
if (empty($no_update))
{
$sql = 'UPDATE ' . $table . '
SET ' . $fields . '_order = ' . $fields . "_order $sign 1
WHERE $where";
$db->sql_query($sql);
}
if ($action == 'modify') 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']); trigger_error($user->lang[$lang . '_EDITED']);
} }
else else
{ {
$db->sql_query('INSERT INTO ' . $table . ' ' . $db->sql_build_array('INSERT', $img_sql));
$cache->destroy('icons');
trigger_error($user->lang[$lang . '_ADDED']); trigger_error($user->lang[$lang . '_ADDED']);
} }
break; break;
case 'import': case 'import':
if (!empty($_POST['pak'])) $pak = request_var('pak', '');
$current = request_var('current', '');
if ($pak != '')
{ {
$order = 0; $order = 0;
// The user has already selected a smilies_pak file // 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) switch ($mode)
{ {
@ -397,23 +420,19 @@ function update_image_dimensions()
$cur_img = array(); $cur_img = array();
$field_sql = ($mode == 'emoticons') ? 'code' : 'icons_url'; $field_sql = ($mode == 'emoticons') ? 'code' : 'icons_url';
$result = $db->sql_query('SELECT ' . $field_sql . ' $result = $db->sql_query("SELECT $field_sql FROM $table");
FROM ' . $table);
if ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
do ++$order;
{ $cur_img[$row[$field_sql]] = 1;
++$order;
$cur_img[$row[$field_sql]] = 1;
}
while ($row = $db->sql_fetchrow($result));
} }
$db->sql_freeresult($result); $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) foreach ($pak_ary as $pak_entry)
@ -421,7 +440,7 @@ function update_image_dimensions()
$data = array(); $data = array();
if (preg_match_all("#'(.*?)', #", $pak_entry, $data)) 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')) (sizeof($data[1]) != 5 && $mode == 'emoticons'))
{ {
trigger_error($user->lang['WRONG_PAK_TYPE']); trigger_error($user->lang['WRONG_PAK_TYPE']);
@ -436,15 +455,15 @@ function update_image_dimensions()
$code = htmlentities(stripslashes($data[1][4])); $code = htmlentities(stripslashes($data[1][4]));
} }
if ($_POST['current'] == 'replace' && if ($current == 'replace' &&
(($mode == 'emoticons' && !empty($cur_img[$code])) || (($mode == 'emoticons' && !empty($cur_img[$code])) ||
($mode == 'icons' && !empty($cur_img[$img])))) ($mode == 'icons' && !empty($cur_img[$img]))))
{ {
$replace_sql = ($mode == 'emoticons') ? $code : $img; $replace_sql = ($mode == 'emoticons') ? $code : $img;
$sql = array( $sql = array(
$fields . '_url' => $img, $fields . '_url' => $img,
$fields . '_height' => intval($height), $fields . '_height' => (int) $height,
$fields . '_width' => intval($width), $fields . '_width' => (int) $width,
); );
if ($mode == 'emoticons') if ($mode == 'emoticons')
{ {
@ -462,10 +481,11 @@ function update_image_dimensions()
$sql = array( $sql = array(
$fields . '_url' => $img, $fields . '_url' => $img,
$fields . '_height' => intval($height), $fields . '_height' => (int) $height,
$fields . '_width' => intval($width), $fields . '_width' => (int) $width,
$fields . '_order' => intval($order), $fields . '_order' => (int) $order,
); );
if ($mode == 'emoticons') if ($mode == 'emoticons')
{ {
$sql = array_merge($sql, array( $sql = array_merge($sql, array(
@ -480,22 +500,15 @@ function update_image_dimensions()
} }
$cache->destroy('icons'); $cache->destroy('icons');
trigger_error($user->lang[$lang . '_IMPORT_SUCCESS']); trigger_error($user->lang[$lang . '_IMPORT_SUCCESS']);
} }
else else
{ {
$paklist = filelist($phpbb_root_path . $img_path, '', 'pak');
$pak_options = ''; $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]); adm_page_header($user->lang[$lang]);
@ -505,19 +518,20 @@ function update_image_dimensions()
<p><?php echo $user->lang[$lang .'_EXPLAIN'] ?></p> <p><?php echo $user->lang[$lang .'_EXPLAIN'] ?></p>
<form method="post" action="admin_icons.<?php echo $phpEx . $SID . '&amp;mode=' . $mode . '&amp;action=import'; ?>"><table class="bg" cellspacing="1" cellpadding="4" border="0" align="center"> <form method="post" action="admin_icons.<?php echo $phpEx . $SID . '&amp;mode=' . $mode . '&amp;action=import'; ?>">
<tr> <table class="bg" cellspacing="1" cellpadding="4" border="0" align="center">
<th colspan="2"><?php echo $user->lang[$lang . '_IMPORT'] ?></th> <tr>
</tr> <th colspan="2"><?php echo $user->lang[$lang . '_IMPORT'] ?></th>
</tr>
<?php <?php
if ($pak_options == '') if ($pak_options == '')
{ {
?> ?>
<tr> <tr>
<td class="row1" colspan="2"><?php echo $user->lang['NO_' . $lang . '_PAK']; ?></td> <td class="row1" colspan="2"><?php echo $user->lang['NO_' . $lang . '_PAK']; ?></td>
</tr> </tr>
<?php <?php
} }
@ -525,17 +539,17 @@ function update_image_dimensions()
{ {
?> ?>
<tr> <tr>
<td class="row2"><?php echo $user->lang['SELECT_PACKAGE'] ?></td> <td class="row2"><?php echo $user->lang['SELECT_PACKAGE'] ?></td>
<td class="row1"><select name="pak"><?php echo $pak_options ?></select></td> <td class="row1"><select name="pak"><?php echo $pak_options ?></select></td>
</tr> </tr>
<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="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'] ?>&nbsp; &nbsp;<input type="radio" name="current" value="replace" /> <?php echo $user->lang['REPLACE_MATCHES'] ?>&nbsp; &nbsp;<input type="radio" name="current" value="delete" /> <?php echo $user->lang['DELETE_ALL'] ?>&nbsp;</td> <td class="row1"><input type="radio" name="current" value="keep" checked="checked" /> <?php echo $user->lang['KEEP_ALL'] ?>&nbsp; &nbsp;<input type="radio" name="current" value="replace" /> <?php echo $user->lang['REPLACE_MATCHES'] ?>&nbsp; &nbsp;<input type="radio" name="current" value="delete" /> <?php echo $user->lang['DELETE_ALL'] ?>&nbsp;</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> </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 <?php
} }
@ -556,24 +570,23 @@ function update_image_dimensions()
case 'send': case 'send':
$result = $db->sql_query('SELECT * $sql = "SELECT *
FROM ' . $table . " FROM $table
ORDER BY {$fields}_order"); ORDER BY {$fields}_order";
if ($row = $db->sql_fetchrow($result)) $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['emoticon']) . "', ";
$pak .= "'" . addslashes($row[$fields . '_height']) . "', "; $pak .= "'" . addslashes($row['code']) . "', ";
$pak .= "'" . addslashes($row[$fields . '_width']) . "', ";
if ($mode == 'emoticons')
{
$pak .= "'" . addslashes($row['emoticon']) . "', ";
$pak .= "'" . addslashes($row['code']) . "', ";
}
$pak .= "\n";
} }
while ($row = $db->sql_fetchrow($result)); $pak .= "\n";
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -592,35 +605,66 @@ function update_image_dimensions()
} }
break; 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_up':
case 'move_down': case 'move_down':
$image_order = intval($_GET['order']);
$order_total = $image_order * 2 + (($action == 'move_up') ? -1 : 1);
$sql = 'UPDATE ' . $table . ' if ($action != 'delete')
SET ' . $fields . "_order = $order_total - " . $fields . '_order {
WHERE ' . $fields . "_order IN ($image_order, " . (($action == 'move_up') ? $image_order - 1 : $image_order + 1) . ')'; $image_order = intval($_GET['order']);
$db->sql_query($sql); $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 // No break; here, display the smilies admin back
default: default:
// By default, check that image_order is valid and fix it if necessary // 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)) if ($row = $db->sql_fetchrow($result))
{ {
$order = 0; $order = 0;
do do
{ {
++$order; ++$order;
if ($row[$fields . '_order'] != $order) if ($row['fields_order'] != $order)
{ {
$db->sql_query('UPDATE ' . $table . ' $db->sql_query("UPDATE $table
SET ' . $fields . '_order = ' . $order . ' SET {$fields}_order = $order
WHERE ' . $fields . '_id = ' . $row[$fields . '_id']); WHERE {$fields}_id = " . $row['order_id']);
} }
} }
while ($row = $db->sql_fetchrow($result)); while ($row = $db->sql_fetchrow($result));
@ -636,37 +680,47 @@ function update_image_dimensions()
<p><?php echo $user->lang[$lang .'_EXPLAIN']; ?></p> <p><?php echo $user->lang[$lang .'_EXPLAIN']; ?></p>
<form method="post" action="admin_icons.<?php echo $phpEx . $SID . '&amp;mode=' . $mode ?>"><table cellspacing="1" cellpadding="0" border="0" align="center">
<tr>
<td align="right"> &nbsp;&nbsp; <a href="admin_icons.<?php echo $phpEx . $SID . '&amp;mode=' . $mode . '&amp;action=import'; ?>"><?php echo $user->lang['IMPORT_' . $lang]; ?></a> | <a href="admin_icons.<?php echo $phpEx . $SID . '&amp;mode=' . $mode . '&amp;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 <?php
if ($mode == 'emoticons') if ($notice != '')
{ {
?>
<b style="color:green"><?php echo $notice; ?></b>
<?php
}
?>
<form method="post" action="admin_icons.<?php echo $phpEx . $SID . '&amp;mode=' . $mode ?>">
<table cellspacing="1" cellpadding="0" border="0" align="center">
<tr>
<td align="right"> &nbsp;&nbsp; <a href="admin_icons.<?php echo $phpEx . $SID . '&amp;mode=' . $mode . '&amp;action=import'; ?>"><?php echo $user->lang['IMPORT_' . $lang]; ?></a> | <a href="admin_icons.<?php echo $phpEx . $SID . '&amp;mode=' . $mode . '&amp;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['CODE']; ?></th>
<th><?php echo $user->lang['EMOTION']; ?></th> <th><?php echo $user->lang['EMOTION']; ?></th>
<?php <?php
}
}
?> ?>
<th><?php echo $user->lang['ACTION']; ?></th> <th><?php echo $user->lang['ACTION']; ?></th>
<th><?php echo $user->lang['REORDER']; ?></th> <th><?php echo $user->lang['REORDER']; ?></th>
</tr> </tr>
<?php <?php
$spacer = FALSE; $spacer = FALSE;
$sql = 'SELECT * $sql = "SELECT *
FROM ' . $table . ' FROM $table
ORDER BY display_on_posting DESC, ' . $fields . '_order ASC'; ORDER BY display_on_posting DESC, {$fields}_order ASC";
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
@ -675,50 +729,46 @@ function update_image_dimensions()
{ {
$spacer = TRUE; $spacer = TRUE;
?> ?>
<tr> <tr>
<td class="row3" colspan="<?php echo ($mode == 'emoticons') ? 5 : 3; ?>" align="center"><?php echo $user->lang[$lang . '_NOT_DISPLAYED'] ?></td> <td class="row3" colspan="<?php echo ($mode == 'emoticons') ? 5 : 3; ?>" align="center"><?php echo $user->lang[$lang . '_NOT_DISPLAYED'] ?></td>
</tr> </tr>
<?php <?php
} }
$row_class = ($row_class != 'row1') ? 'row1' : 'row2'; $row_class = ($row_class != 'row1') ? 'row1' : 'row2';
$alt_text = ($mode == 'emoticon') ? htmlspecialchars($row['code']) : ''; $alt_text = ($mode == 'emoticon') ? htmlspecialchars($row['code']) : '';
?> ?>
<tr> <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> <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 <?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 htmlspecialchars($row['code']); ?></td>
<td class="<?php echo $row_class; ?>" align="center"><?php echo $row['emoticon']; ?></td> <td class="<?php echo $row_class; ?>" align="center"><?php echo $row['emoticon']; ?></td>
<?php <?php
}
}
?> ?>
<td class="<?php echo $row_class; ?>" align="center"><a href="<?php echo "admin_icons.$phpEx$SID&amp;mode=$mode&amp;action=edit&amp;id=" . $row[$fields . '_id']; ?>"><?php echo $user->lang['EDIT']; ?></a> | <a href="<?php echo "admin_icons.$phpEx$SID&amp;mode=$mode&amp;action=delete&amp;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&amp;mode=$mode&amp;action=edit&amp;id=" . $row[$fields . '_id']; ?>"><?php echo $user->lang['EDIT']; ?></a> | <a href="<?php echo "admin_icons.$phpEx$SID&amp;mode=$mode&amp;action=delete&amp;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&amp;mode=$mode&amp;action=move_up&amp;order=" . $row[$fields . '_order']; ?>"><?php echo $user->lang['MOVE_UP']; ?></a> <br /> <a href="<?php echo "admin_icons.$phpEx$SID&amp;mode=$mode&amp;action=move_down&amp;order=" . $row[$fields . '_order']; ?>"><?php echo $user->lang['MOVE_DOWN']; ?></a></td> <td class="<?php echo $row_class; ?>" align="center"><a href="<?php echo "admin_icons.$phpEx$SID&amp;mode=$mode&amp;action=move_up&amp;order=" . $row[$fields . '_order']; ?>"><?php echo $user->lang['MOVE_UP']; ?></a> <br /> <a href="<?php echo "admin_icons.$phpEx$SID&amp;mode=$mode&amp;action=move_down&amp;order=" . $row[$fields . '_order']; ?>"><?php echo $user->lang['MOVE_DOWN']; ?></a></td>
</tr> </tr>
<?php <?php
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
?> ?>
<tr> <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> <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" />&nbsp;<input type="submit" name="edit" value="<?php echo $user->lang['EDIT_' . $lang]; ?>" class="btnmain" /></td>
</tr> </tr>
</table></td> </table>
</tr> </td>
</table></form> </tr>
</table>
</form>
<?php <?php
adm_page_footer(); adm_page_footer();
break; break;