From de53ffabb410f7db9eb807a2965b02d19e314cc0 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 19 Oct 2003 15:26:14 +0000 Subject: [PATCH] mass add/edit smilies and icons git-svn-id: file:///svn/phpbb/trunk@4613 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/adm/admin_icons.php | 716 ++++++++++++++++++++------------------ 1 file changed, 383 insertions(+), 333 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 @@ 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 = '' . $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"; - - 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 .= ''; - } - } + $data = $_images; } - 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]); ?> @@ -199,78 +168,97 @@ switch ($action)

lang[$lang .'_EXPLAIN']; ?>

- - -
"> - - - - - - - +?> + + + + + + + + + + + $img_row) + { + $row_class = (($row % 2) == 0) ? 'row1' : 'row2'; +?> + + + - - - - - - - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + + @@ -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']); + // 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(); - if ($image_width == 0 || $image_height == 0) + foreach ($images as $image) { - $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') - { - $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; + 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]; + } + + $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 - { - $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); - } + + $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 .= ''; - } + foreach ($_paks as $pak) + { + $pak_options .= ''; } adm_page_header($user->lang[$lang]); @@ -505,19 +518,20 @@ function update_image_dimensions()

lang[$lang .'_EXPLAIN'] ?>

-
lang[$lang . '_CONFIG'] ?>
lang[$lang . '_URL'] ?>    
lang[$lang . '_WIDTH'] ?>lang[$lang . '_HEIGHT'] ?>lang['DISPLAY_ON_POSTING'] ?>lang[$lang . '_ORDER'] ?>lang['ADD'] ?>
[]
lang[$lang . '_CODE'] ?>
lang[$lang . '_EMOTION'] ?>
lang[$lang . '_WIDTH'] ?>
lang[$lang . '_HEIGHT'] ?>
lang['DISPLAY_ON_POSTING'] ?>/>
lang[$lang . '_ORDER'] ?>
"> /> +
- - - + +
lang[$lang . '_IMPORT'] ?>
+ + + - - - + + + - - - - - - - - - - + + + + + + + + + +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()

lang[$lang .'_EXPLAIN']; ?>

-
lang[$lang . '_IMPORT'] ?>
lang['NO_' . $lang . '_PAK']; ?>
lang['NO_' . $lang . '_PAK']; ?>
lang['SELECT_PACKAGE'] ?>
lang['CURRENT_' . $lang] ?>
lang['CURRENT_' . $lang . '_EXPLAIN'] ?>
lang['KEEP_ALL'] ?>    lang['REPLACE_MATCHES'] ?>    lang['DELETE_ALL'] ?> 
lang['SELECT_PACKAGE'] ?>
lang['CURRENT_' . $lang] ?>
lang['CURRENT_' . $lang . '_EXPLAIN'] ?>
lang['KEEP_ALL'] ?>    lang['REPLACE_MATCHES'] ?>    lang['DELETE_ALL'] ?> 
- - - - - + + +
   lang['IMPORT_' . $lang]; ?> | lang['EXPORT_' . $lang]; ?>
- - + + + + +
lang[$lang]; ?>
+ + + + + - -
   lang['IMPORT_' . $lang]; ?> | lang['EXPORT_' . $lang]; ?>
+ + + + - - - + + + sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -675,50 +729,46 @@ function update_image_dimensions() { $spacer = TRUE; ?> - - - + + + - - + + - - - + + + sql_freeresult($result); ?> - - - -
lang[$lang]; ?> lang['CODE']; ?> lang['EMOTION']; ?> lang['ACTION']; ?>lang['REORDER']; ?>
lang['ACTION']; ?>lang['REORDER']; ?>
lang[$lang . '_NOT_DISPLAYED'] ?>
lang[$lang . '_NOT_DISPLAYED'] ?>
<?php echo $alt_text; ?>
<?php echo $alt_text; ?> ">lang['EDIT']; ?> | ">lang['DELETE']; ?>">lang['MOVE_UP']; ?>
">lang['MOVE_DOWN']; ?>
">lang['EDIT']; ?> | ">lang['DELETE']; ?>">lang['MOVE_UP']; ?>
">lang['MOVE_DOWN']; ?>
+
 
+ + + +