Skip to content

Commit

Permalink
Apply some code optimalizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick committed Dec 28, 2014
1 parent f92c49c commit 1c7e311
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions backstage/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
if (isset($_POST['add_item'])) {
confirm_referrer('backstage/menu.php');

$item_name = luna_trim($_POST['name']);
$item_url = luna_trim($_POST['url']);
$item_name = luna_trim($_POST['name']);
$item_url = luna_trim($_POST['url']);

$db->query('INSERT INTO '.$db->prefix.'menu (url, name, disp_position, visible, sys_entry) VALUES(\''.$item_url.'\', \''.$item_name.'\', 0, 1, 0)') or error('Unable to add new menu item', __FILE__, __LINE__, $db->error());

Expand All @@ -34,16 +34,7 @@
$db->query('DELETE FROM '.$db->prefix.'menu WHERE id='.$item_id) or error('Unable to delete menu item', __FILE__, __LINE__, $db->error());

redirect('backstage/menu.php');
}

// Generate an array with all menu items
$result = $db->query('SELECT id, url, name, disp_position, visible, sys_entry FROM '.$db->prefix.'menu ORDER BY disp_position') or error('Unable to fetch menu items list', __FILE__, __LINE__, $db->error());
$num_items = $db->num_rows($result);

for ($i = 0; $i < $num_items; ++$i)
$item_list[] = $db->fetch_assoc($result);

if (isset($_POST['update'])) {
} else if (isset($_POST['update'])) {
confirm_referrer('backstage/menu.php');

$menu_items = $_POST['item'];
Expand All @@ -55,13 +46,13 @@
$cur_item['name'] = luna_trim($cur_item['name']);
$cur_item['order'] = luna_trim($cur_item['order']);

if ($cur_item['name'] == '')
if (empty($cur_item['name']))
message_backstage($lang['Must enter name message']);

if ($cur_item['url'] == '')
if (empty($cur_item['url']))
message_backstage($lang['Must enter name message']);

if ($cur_item['order'] == '' || preg_match('%[^0-9]%', $cur_item['order']))
if (is_int($cur_item['order']))
message_backstage($lang['Must enter integer message']);

$db->query('UPDATE '.$db->prefix.'menu SET url=\''.$db->escape($cur_item['url']).'\', name=\''.$cur_item['name'].'\', disp_position='.$cur_item['order'].', visible=\''.$cur_item['visible'].'\' WHERE id='.intval($item_id)) or error('Unable to update menu', __FILE__, __LINE__, $db->error());
Expand All @@ -70,7 +61,7 @@
redirect('backstage/menu.php');
}

$result = $db->query('SELECT id, url, name, disp_position, visible, sys_entry FROM '.$db->prefix.'menu ORDER BY disp_position') or error('Unable to fetch menu items', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT * FROM '.$db->prefix.'menu ORDER BY disp_position') or error('Unable to fetch menu items', __FILE__, __LINE__, $db->error());

require 'header.php';
load_admin_nav('settings', 'menu');
Expand Down

0 comments on commit 1c7e311

Please sign in to comment.