Replace array() notation with PHP preferred square bracktes []

This commit is contained in:
bergware
2016-10-24 09:50:08 +02:00
parent 3847e44624
commit 69c2507390
3 changed files with 59 additions and 58 deletions
+10 -10
View File
@@ -40,8 +40,8 @@ if ($action) {
'Error: '.$lv->get_last_error();
}
elseif ($subaction == 'disk-resize') {
$capacity = str_replace(array("KB","MB","GB","TB","PB", " ", ","), array("K","M","G","T","P", "", ""), strtoupper($_POST['cap']));
$oldcap = str_replace(array("KB","MB","GB","TB","PB", " ", ","), array("K","M","G","T","P", "", ""), strtoupper($_GET['oldcap']));
$capacity = str_replace(["KB","MB","GB","TB","PB", " ", ","], ["K","M","G","T","P", "", ""], strtoupper($_POST['cap']));
$oldcap = str_replace(["KB","MB","GB","TB","PB", " ", ","], ["K","M","G","T","P", "", ""], strtoupper($_GET['oldcap']));
if (substr($oldcap,0,-1) < substr($capacity,0,-1)){
shell_exec("qemu-img resize -q " . escapeshellarg($_GET['disk']) . " $capacity");
$msg = $domName." disk capacity has been changed to $capacity";
@@ -124,7 +124,7 @@ if ($action) {
}
} else {
sort($doms);
$contextMenus = array();
$contextMenus = [];
for ($i = 0; $i < sizeof($doms); $i++) {
$name = $doms[$i];
@@ -196,8 +196,8 @@ if ($action) {
if (!empty($vmtemplateicon)) {
if (file_exists($vmtemplateicon)) {
$vmicon = $vmtemplateicon;
} else if (file_exists('/usr/local/emhttp/plugins/dynamix.vm.manager/templates/images/' . $vmtemplateicon)) {
$vmicon = '/plugins/dynamix.vm.manager/templates/images/' . $vmtemplateicon;
} else if (file_exists("$docroot/plugins/dynamix.vm.manager/templates/images/".$vmtemplateicon)) {
$vmicon = "/plugins/dynamix.vm.manager/templates/images/".$vmtemplateicon;
}
}
@@ -243,7 +243,7 @@ if ($action) {
if($bootdev == 'cdrom')
echo "selected ";
echo "value='?subaction=bootdev-change&amp;uuid=$uuid&amp;bootdev=cdrom'>cd</option>
</select><font size='-6'>(boot)</font>
</select><span class='small'>(boot)</span>
</th>
<th class='header'>Driver type</th>
<th class='header'>Dev Name</th>
@@ -465,10 +465,10 @@ if ($action) {
unset($name, $val);
if($msg){
if(strpos($msg, "rror:"))
$color = 'red';
$color = 'red-text';
else
$color = 'green';
echo "<script type='text/javascript'>$(function() { $('#countdown').html('<font class=\"".$color."\">".$msg."</font>');}); </script>";
$color = 'green-text';
echo "<script type='text/javascript'>$(function() { $('#countdown').html('<span class=\"".$color."\">".$msg."</span>');}); </script>";
}
?>
@@ -478,7 +478,7 @@ if($msg){
<script>
function vncOpen() {
$.post('/plugins/dynamix.vm.manager/classes/vnc.php',{cmd:'open',root:'<?=$docroot?>',file:'/usr/local/emhttp/plugins/dynamix.vm.manager/vncconnect.vnc'},function(data) {
$.post('/plugins/dynamix.vm.manager/classes/vnc.php',{cmd:'open',root:'<?=$docroot?>',file:'<?=$docroot?>/plugins/dynamix.vm.manager/vncconnect.vnc'},function(data) {
window.location.href = data;
});
}
+34 -34
View File
@@ -15,7 +15,7 @@
private $conn;
private $last_error;
private $allow_cached = true;
private $dominfos = array();
private $dominfos = [];
private $enabled = false;
function Libvirt($uri = false, $login = false, $pwd = false, $debug=false) {
@@ -80,7 +80,7 @@
$arrReturn = [];
if (!empty($disk['size'])) {
$disk['size'] = str_replace(array("KB","MB","GB","TB","PB"), array("K","M","G","T","P"), strtoupper($disk['size']));
$disk['size'] = str_replace(["KB","MB","GB","TB","PB"], ["K","M","G","T","P"], strtoupper($disk['size']));
}
if (empty($disk['driver'])) {
$disk['driver'] = 'raw';
@@ -845,7 +845,7 @@
function connect($uri = 'null', $login = false, $password = false) {
if ($login !== false && $password !== false) {
$this->conn=libvirt_connect($uri, false, array(VIR_CRED_AUTHNAME => $login, VIR_CRED_PASSPHRASE => $password));
$this->conn=libvirt_connect($uri, false, [VIR_CRED_AUTHNAME => $login, VIR_CRED_PASSPHRASE => $password]);
} else {
$this->conn=libvirt_connect($uri, false);
}
@@ -960,7 +960,7 @@
$disks = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/target/@dev', false);
$files = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/source/@file', false);
$ret = array();
$ret = [];
for ($i = 0; $i < $disks['num']; $i++) {
$tmp = libvirt_domain_get_block_info($dom, $disks[$i]);
if ($tmp) {
@@ -970,7 +970,7 @@
else {
$this->_set_last_error();
$ret[] = array(
$ret[] = [
'device' => $disks[$i],
'file' => $files[$i],
'type' => '-',
@@ -978,7 +978,7 @@
'allocation' => '-',
'physical' => '-',
'bus' => $buses[$i]
);
];
}
}
@@ -1008,7 +1008,7 @@
$disks = $this->get_xpath($dom, '//domain/devices/disk[@device="disk"]/target/@dev', false);
$files = $this->get_xpath($dom, '//domain/devices/disk[@device="disk"]/source/@*', false);
$ret = array();
$ret = [];
for ($i = 0; $i < $disks['num']; $i++) {
$tmp = libvirt_domain_get_block_info($dom, $disks[$i]);
if ($tmp) {
@@ -1031,7 +1031,7 @@
else {
$this->_set_last_error();
$ret[] = array(
$ret[] = [
'device' => $disks[$i],
'file' => $files[$i],
'type' => '-',
@@ -1039,7 +1039,7 @@
'allocation' => '-',
'physical' => '-',
'bus' => $buses[$i]
);
];
}
}
@@ -1300,7 +1300,7 @@
function get_node_device_cap_options() {
$all = $this->get_node_devices();
$ret = array();
$ret = [];
for ($i = 0; $i < sizeof($all); $i++) {
$tmp = $this->get_node_device_caps($all[$i]);
@@ -1331,7 +1331,7 @@
}
function domain_get_info_call($name = false, $name_override = false) {
$ret = array();
$ret = [];
if ($name != false) {
$dom = $this->get_domain_object($name);
@@ -1522,7 +1522,7 @@
$seed = time();
srand($seed);
$ret = array();
$ret = [];
for ($i = 0; $i < 16; $i++)
$ret[] = $this->macbyte(rand() % 256);
@@ -1764,7 +1764,7 @@
if (!$tmp)
return false;
$devs = array();
$devs = [];
for ($i = 0; $i < $tmp['num']; $i++)
$devs[] = $tmp[$i];
@@ -1800,7 +1800,7 @@
if (!$tmp)
return false;
$devs = array();
$devs = [];
for ($i = 0; $i < $tmp['num']; $i++)
$devs[] = $tmp[$i];
@@ -1813,13 +1813,13 @@
$sources = $this->get_xpath($domain, $xpath.'/source/@dir', false);
$targets = $this->get_xpath($domain, $xpath.'/target/@dir', false);
$ret = array();
$ret = [];
if (!empty($sources)) {
for ($i = 0; $i < $sources['num']; $i++) {
$ret[] = array(
$ret[] = [
'source' => $sources[$i],
'target' => $targets[$i]
);
];
}
}
@@ -1852,7 +1852,7 @@
if ($display)
return $type.' ('.$targetType.' on port '.$targetPort.')';
else
return array('type' => $type, 'targetType' => $targetType, 'targetPort' => $targetPort);
return ['type' => $type, 'targetType' => $targetType, 'targetPort' => $targetPort];
}
else
if ($type == 'input') {
@@ -1862,7 +1862,7 @@
if ($display)
return $type.' on '.$bus;
else
return array('type' => $type, 'bus' => $bus);
return ['type' => $type, 'bus' => $bus];
}
else
if ($type == 'graphics') {
@@ -1873,7 +1873,7 @@
if ($display)
return $type.' on port '.$port.' with'.($autoport ? '' : 'out').' autoport enabled';
else
return array('type' => $type, 'port' => $port, 'autoport' => $autoport);
return ['type' => $type, 'port' => $port, 'autoport' => $autoport];
}
else
if ($type == 'video') {
@@ -1884,7 +1884,7 @@
if ($display)
return $type.' with '.($vram / 1024).' MB VRAM, '.$heads.' head(s)';
else
return array('type' => $type, 'vram' => $vram, 'heads' => $heads);
return ['type' => $type, 'vram' => $vram, 'heads' => $heads];
}
else
return false;
@@ -1898,11 +1898,11 @@
$slot = $this->get_xpath($domain, $xpath.'slot', false);
$func = $this->get_xpath($domain, $xpath.'function', false);
$devs = array();
$devs = [];
for ($i = 0; $i < $bus['num']; $i++) {
$devid = str_replace('0x', '', 'pci_'.$dom[$i].'_'.$bus[$i].'_'.$slot[$i].'_'.$func[$i]);
$tmp2 = $this->get_node_device_information($devid);
$devs[] = array(
$devs[] = [
'domain' => $dom[$i],
'bus' => $bus[$i],
'slot' => $slot[$i],
@@ -1912,7 +1912,7 @@
'vendor_id' => $tmp2['vendor_id'],
'product' => $tmp2['product_name'],
'product_id' => $tmp2['product_id']
);
];
}
// Get any pci devices contained in the qemu args
@@ -1929,10 +1929,10 @@
$keypair = explode('=', $arg);
if ($keypair[0] == 'host' && !empty($keypair[1])) {
$devid = 'pci_0000_' . str_replace(array(':', '.'), '_', $keypair[1]);
$devid = 'pci_0000_' . str_replace([':', '.'], '_', $keypair[1]);
$tmp2 = $this->get_node_device_information($devid);
list($bus, $slot, $func) = explode(":", str_replace('.', ':', $keypair[1]));
$devs[] = array(
$devs[] = [
'domain' => '0x0000',
'bus' => '0x' . $bus,
'slot' => '0x' . $slot,
@@ -1942,7 +1942,7 @@
'vendor_id' => $tmp2['vendor_id'],
'product' => $tmp2['product_name'],
'product_id' => $tmp2['product_id']
);
];
break;
}
}
@@ -1971,16 +1971,16 @@
$vid = $this->get_xpath($domain, $xpath.'vendor/@id', false);
$pid = $this->get_xpath($domain, $xpath.'product/@id', false);
$devs = array();
$devs = [];
for ($i = 0; $i < $vid['num']; $i++) {
$dev = $this->_lookup_device_usb($vid[$i], $pid[$i]);
$devs[] = array(
$devs[] = [
'id' => str_replace('0x', '', $vid[$i] . ':' . $pid[$i]),
'vendor_id' => $vid[$i],
'product_id' => $pid[$i],
'product' => $dev['product_name'],
'vendor' => $dev['vendor_name']
);
];
}
return $devs;
@@ -1992,7 +1992,7 @@
$devs_pci = $this->domain_get_host_devices_pci($domain);
$devs_usb = $this->domain_get_host_devices_usb($domain);
return array('pci' => $devs_pci, 'usb' => $devs_usb);
return ['pci' => $devs_pci, 'usb' => $devs_usb];
}
function get_nic_info($domain) {
@@ -2001,7 +2001,7 @@
$bridge = $this->get_xpath($domain, "//domain/devices/interface/source/@bridge", false);
if (!$macs)
return $this->_set_last_error();
$ret = array();
$ret = [];
for ($i = 0; $i < $macs['num']; $i++) {
if ($net[$i] != 'bridge')
$tmp = libvirt_domain_get_network_info($domain, $macs[$i]);
@@ -2009,11 +2009,11 @@
$ret[] = $tmp;
else {
$this->_set_last_error();
$ret[] = array(
$ret[] = [
'mac' => $macs[$i],
'network' => $bridge[$i],
'nic_type' => 'virtio'
);
];
}
}
@@ -11,16 +11,17 @@
*/
?>
<?
$docroot = $docroot ?: @$_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
// Load emhttp variables if needed.
if (! isset($var)){
if (! is_file("/usr/local/emhttp/state/var.ini")) shell_exec("wget -qO /dev/null localhost:$(lsof -nPc emhttp | grep -Po 'TCP[^\d]*\K\d+')");
$var = @parse_ini_file("/usr/local/emhttp/state/var.ini");
$disks = @parse_ini_file("/usr/local/emhttp/state/disks.ini", true);
if (!is_file("$docroot/state/var.ini")) shell_exec("wget -qO /dev/null localhost:$(lsof -nPc emhttp | grep -Po 'TCP[^\d]*\K\d+')");
$var = @parse_ini_file("$docroot/state/var.ini");
$disks = @parse_ini_file("$docroot/state/disks.ini", true);
extract(parse_plugin_cfg("dynamix",true));
}
if (!isset($eth0) && is_file("/usr/local/emhttp/state/network.ini")) {
extract(parse_ini_file('/usr/local/emhttp/state/network.ini',true));
if (!isset($eth0) && is_file("$docroot/state/network.ini")) {
extract(parse_ini_file("$docroot/state/network.ini",true));
}
// Check if program is running and
@@ -494,7 +495,7 @@
}
function appendOrdinalSuffix($number) {
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
$ends = ['th','st','nd','rd','th','th','th','th','th','th'];
if (($number % 100) >= 11 && ($number % 100) <= 13) {
$abbreviation = $number . 'th';
@@ -606,7 +607,7 @@
$arrMatch['vendorname'] = sanitizeVendor($arrMatch['vendorname']);
$arrMatch['productname'] = sanitizeProduct($arrMatch['productname']);
$arrValidPCIDevices[] = array(
$arrValidPCIDevices[] = [
'id' => $arrMatch['id'],
'type' => $arrMatch['type'],
'typeid' => $arrMatch['typeid'],
@@ -618,7 +619,7 @@
'driver' => $strDriver,
'name' => $arrMatch['vendorname'] . ' ' . $arrMatch['productname'],
'blacklisted' => $boolBlacklisted
);
];
}
}
@@ -680,7 +681,7 @@
return $cacheValidUSBDevices;
}
$arrValidUSBDevices = array();
$arrValidUSBDevices = [];
// Get a list of all usb hubs so we can blacklist them
exec("cat /sys/bus/usb/drivers/hub/*/modalias | grep -Po 'usb:v\K\w{9}' | tr 'p' ':'", $arrAllUSBHubs);
@@ -715,10 +716,10 @@
// Clean up the name
$arrMatch['name'] = sanitizeVendor($arrMatch['name']);
$arrValidUSBDevices[] = array(
$arrValidUSBDevices[] = [
'id' => $arrMatch['id'],
'name' => $arrMatch['name'],
);
];
}
}
@@ -868,7 +869,7 @@
function getHostCPUModel() {
$cpu = explode('#', exec("dmidecode -q -t 4|awk -F: '{if(/Version:/) v=$2; else if(/Current Speed:/) s=$2} END{print v\"#\"s}'"));
list($strCPUModel) = explode('@', str_replace(array("Processor","CPU","(C)","(R)","(TM)"), array("","","&#169;","&#174;","&#8482;"), $cpu[0]) . '@');
list($strCPUModel) = explode('@', str_replace(["Processor","CPU","(C)","(R)","(TM)"], ["","","&#169;","&#174;","&#8482;"], $cpu[0]) . '@');
return trim($strCPUModel);
}
@@ -967,10 +968,10 @@
// Add claimed USB devices by this VM to the available USB devices
/*
foreach($arrUSBDevs as $arrUSB) {
$arrValidUSBDevices[] = array(
$arrValidUSBDevices[] = [
'id' => $arrUSB['id'],
'name' => $arrUSB['product'],
);
];
}
*/