mirror of
https://github.com/unraid/webgui.git
synced 2026-05-12 15:20:29 -05:00
Plugins page loading improvements
This commit is contained in:
@@ -29,17 +29,44 @@ $updates = 0;
|
||||
$builtin = ['unRAIDServer'];
|
||||
$plugins = "/var/log/plugins/*.plg";
|
||||
$ncsi = null; // network connection status indicator
|
||||
$default = "<tr><td colspan='6' style='text-align:center;padding-top:12px'><i class='fa fa-check-square-o icon'></i> "._('No plugins installed')."</td><tr>";
|
||||
|
||||
if ($init) {
|
||||
foreach (glob($plugins,GLOB_NOSORT) as $plugin_link) {
|
||||
//only consider symlinks
|
||||
$plugin_file = @readlink($plugin_link);
|
||||
if ($plugin_file===false) continue;
|
||||
//plugin name
|
||||
$name = plugin('name',$plugin_file) ?: basename($plugin_file,".plg");
|
||||
//skip system plugin
|
||||
if (in_array($name,$builtin)) continue;
|
||||
if ($audit) {
|
||||
[$plg,$action] = explode(':',$audit);
|
||||
switch ($action) {
|
||||
case 'return' : $check = true; break;
|
||||
case 'remove' : return;
|
||||
case 'install': $install = true;
|
||||
case 'update' : $plugins = "/var/log/plugins/$plg.plg"; break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (glob($plugins,GLOB_NOSORT) as $plugin_link) {
|
||||
//only consider symlinks
|
||||
$plugin_file = @readlink($plugin_link);
|
||||
if ($plugin_file === false) continue;
|
||||
//plugin name
|
||||
$name = plugin('name',$plugin_file) ?: basename($plugin_file,".plg");
|
||||
$user = in_array($name,$builtin);
|
||||
//switch between system and user plugins
|
||||
if (($system && !$user) || (!$system && $user)) continue;
|
||||
if ($init || $install) {
|
||||
//OS update?
|
||||
$os = $system && $name==$builtin[0];
|
||||
$past = false;
|
||||
//toggle stable/next release?
|
||||
if ($os && $branch) {
|
||||
$past = plugin('version',$plugin_file);
|
||||
$tmp_plg = "$name-.plg";
|
||||
$tmp_file = "/var/tmp/$name.plg";
|
||||
copy($plugin_file,$tmp_file);
|
||||
exec("sed -ri 's|^(<!ENTITY category).*|\\1 \"{$branch}\">|' $tmp_file");
|
||||
symlink($tmp_file,"/var/log/plugins/$tmp_plg");
|
||||
$next = end(explode("\n",check_plugin($tmp_plg,$ncsi)));
|
||||
if (version_compare($next,$past,'>')) {
|
||||
copy("/tmp/plugins/$tmp_plg",$tmp_file);
|
||||
$plugin_file = $tmp_file;
|
||||
}
|
||||
}
|
||||
//icon + link
|
||||
$launch = plugin('launch',$plugin_file);
|
||||
if ($icon = plugin('icon',$plugin_file)) {
|
||||
@@ -69,6 +96,8 @@ if ($init) {
|
||||
//support
|
||||
$support = plugin('support',$plugin_file) ?: "";
|
||||
$support = $support ? "<a href='$support' target='_blank'>"._('Support Thread')."</a>" : "";
|
||||
//category
|
||||
$category = plugin('category',$plugin_file) ?: (strpos($version,'-')!==false ? 'next' : 'stable');
|
||||
//author
|
||||
$author = plugin('author',$plugin_file) ?: _('anonymous');
|
||||
//version
|
||||
@@ -84,134 +113,6 @@ if ($init) {
|
||||
echo "<td>$author</td>";
|
||||
echo "<td id='vid-$id' data='$date'>$version <span class='fa fa-info-circle fa-fw big blue-text'></span></td>";
|
||||
echo "<td id='sid-$id' data='0'><span class='fa fa-spin fa-refresh'></span> $status</td>";
|
||||
echo "<td>".make_link('remove',basename($plugin_file))."</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
if ($empty) echo $default;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($audit) {
|
||||
[$plg,$action] = explode(':',$audit);
|
||||
switch ($action) {
|
||||
case 'return' : $check = true; break;
|
||||
case 'remove' : return;
|
||||
case 'install': $install = true;
|
||||
case 'update' : $plugins = "/var/log/plugins/$plg.plg"; break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (glob($plugins,GLOB_NOSORT) as $plugin_link) {
|
||||
//only consider symlinks
|
||||
$plugin_file = @readlink($plugin_link);
|
||||
if ($plugin_file === false) continue;
|
||||
//plugin name
|
||||
$name = plugin('name',$plugin_file) ?: basename($plugin_file,".plg");
|
||||
$custom = in_array($name,$builtin);
|
||||
//switch between system and custom plugins
|
||||
if (($system && !$custom) || (!$system && $custom)) continue;
|
||||
//forced plugin check?
|
||||
$checked = (!$audit && !$check) ? check_plugin(basename($plugin_file),$ncsi) : true;
|
||||
//OS update?
|
||||
$os = $system && $name==$builtin[0];
|
||||
$past = false;
|
||||
//toggle stable/next release?
|
||||
if ($os && $branch) {
|
||||
$past = plugin('version',$plugin_file);
|
||||
$tmp_plg = "$name-.plg";
|
||||
$tmp_file = "/var/tmp/$name.plg";
|
||||
copy($plugin_file,$tmp_file);
|
||||
exec("sed -ri 's|^(<!ENTITY category).*|\\1 \"{$branch}\">|' $tmp_file");
|
||||
symlink($tmp_file,"/var/log/plugins/$tmp_plg");
|
||||
$next = end(explode("\n",check_plugin($tmp_plg,$ncsi)));
|
||||
if (version_compare($next,$past,'>')) {
|
||||
copy("/tmp/plugins/$tmp_plg",$tmp_file);
|
||||
$plugin_file = $tmp_file;
|
||||
}
|
||||
}
|
||||
if ($system || $install) {
|
||||
//link/icon
|
||||
$launch = plugin('launch',$plugin_file);
|
||||
if ($icon = plugin('icon',$plugin_file)) {
|
||||
if (substr($icon,-4)=='.png') {
|
||||
if (file_exists("plugins/$name/images/$icon")) {
|
||||
$icon = "plugins/$name/images/$icon";
|
||||
} elseif (file_exists("plugins/$name/$icon")) {
|
||||
$icon = "plugins/$name/$icon";
|
||||
} else {
|
||||
$icon = "plugins/dynamix.plugin.manager/images/dynamix.plugin.manager.png";
|
||||
}
|
||||
$icon = "<img src='/$icon' class='list'>";
|
||||
} elseif (substr($icon,0,5)=='icon-') {
|
||||
$icon = "<i class='$icon list'></i>";
|
||||
} else {
|
||||
if (substr($icon,0,3)!='fa-') $icon = "fa-$icon";
|
||||
$icon = "<i class='fa $icon list'></i>";
|
||||
}
|
||||
$link = $launch ? "<a href='/$launch' class='list'>$icon</a>" : $icon;
|
||||
} else {
|
||||
$icon = icon($name);
|
||||
$link = $launch ? "<a href='/$launch' class='list'><img src='/$icon' class='list'></a>" : "<img src='/$icon' class='list'>";
|
||||
}
|
||||
//description
|
||||
$readme = "plugins/{$name}/README.md";
|
||||
$desc = file_exists($readme) ? Markdown(file_get_contents($readme)) : Markdown("**{$name}**");
|
||||
//author
|
||||
$author = plugin('author',$plugin_file) ?: _('anonymous');
|
||||
//support
|
||||
$support = plugin('support',$plugin_file) ?: "";
|
||||
$support = $support ? "<a href='$support' target='_blank'>"._('Support Thread')."</a>" : "";
|
||||
//category
|
||||
$category = plugin('category',$plugin_file) ?: (strpos($version,'-')!==false ? 'next' : 'stable');
|
||||
}
|
||||
//version
|
||||
$version = plugin('version',$plugin_file) ?: _('unknown');
|
||||
$date = str_replace('.','',$version);
|
||||
//status
|
||||
$status = _('unknown');
|
||||
$changes_file = $plugin_file;
|
||||
$url = plugin('pluginURL',$plugin_file);
|
||||
if ($url !== false) {
|
||||
$filename = "/tmp/plugins/".(($os && $branch) ? $tmp_plg : basename($url));
|
||||
if ($checked && file_exists($filename)) {
|
||||
if ($past && $past != $version) {
|
||||
$status = make_link('install',$plugin_file,'forced');
|
||||
} else {
|
||||
$latest = plugin('version',$filename);
|
||||
if ($os ? version_compare($latest,$version,'>') : strcmp($latest,$version) > 0) {
|
||||
$version .= "<br><span class='red-text'>$latest</span>";
|
||||
$status = make_link("update",basename($plugin_file));
|
||||
$changes_file = $filename;
|
||||
if (!$os) $updates++;
|
||||
} else {
|
||||
//status is considered outdated when older than 1 day
|
||||
$status = filectime($filename) > (time()-86400) ? _('up-to-date') : _('need check');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strpos($status,'update')!==false) $rank = '0';
|
||||
elseif (strpos($status,'install')!==false) $rank = '1';
|
||||
elseif ($status=='need check') $rank = '2';
|
||||
elseif ($status=='up-to-date') $rank = '3';
|
||||
else $rank = '4';
|
||||
$changes = plugin('changes',$changes_file);
|
||||
if ($changes !== false) {
|
||||
$txtfile = "/tmp/plugins/".basename($plugin_file,'.plg').".txt";
|
||||
file_put_contents($txtfile,$changes);
|
||||
$version .= " <a href='#' title=\""._('View Release Notes')."\" onclick=\"openBox('/plugins/dynamix.plugin.manager/include/ShowChanges.php?file=".urlencode($txtfile)."','"._('Release Notes')."',600,900); return false\"><span class='fa fa-info-circle fa-fw big blue-text'></span></a>";
|
||||
}
|
||||
//write plugin information
|
||||
$empty = false;
|
||||
$id = str_replace('.','-',$name);
|
||||
if ($system || $install) {
|
||||
// regular table construct for system plugin or manual install
|
||||
echo "<tr id=\"".str_replace(['.',' ','_'],'',basename($plugin_file,'.plg'))."\">";
|
||||
echo "<td>$link</td>";
|
||||
echo "<td><span class='desc_readmore' style='display:block'>$desc</span> $support</td>";
|
||||
echo "<td>$author</td>";
|
||||
echo "<td id='vid-$id' data='$date'>$version</td>";
|
||||
echo "<td id='sid-$id' data='$rank'>$status</td>";
|
||||
echo "<td>";
|
||||
if ($os) {
|
||||
$regular = ['stable','next'];
|
||||
@@ -225,12 +126,53 @@ foreach (glob($plugins,GLOB_NOSORT) as $plugin_link) {
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
} else {
|
||||
// selective updates for user plugins
|
||||
//forced plugin check?
|
||||
$checked = (!$audit && !$check) ? check_plugin(basename($plugin_file),$ncsi) : true;
|
||||
//version
|
||||
$version = plugin('version',$plugin_file) ?: _('unknown');
|
||||
$date = str_replace('.','',$version);
|
||||
//status
|
||||
$status = _('unknown');
|
||||
$changes_file = $plugin_file;
|
||||
$url = plugin('pluginURL',$plugin_file);
|
||||
if ($url !== false) {
|
||||
$filename = "/tmp/plugins/".(($os && $branch) ? $tmp_plg : basename($url));
|
||||
if ($checked && file_exists($filename)) {
|
||||
if ($past && $past != $version) {
|
||||
$status = make_link('install',$plugin_file,'forced');
|
||||
} else {
|
||||
$latest = plugin('version',$filename);
|
||||
if ($os ? version_compare($latest,$version,'>') : strcmp($latest,$version) > 0) {
|
||||
$version .= "<br><span class='red-text'>$latest</span>";
|
||||
$status = make_link("update",basename($plugin_file));
|
||||
$changes_file = $filename;
|
||||
if (!$os) $updates++;
|
||||
} else {
|
||||
//status is considered outdated when older than 1 day
|
||||
$status = filectime($filename) > (time()-86400) ? _('up-to-date') : _('need check');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strpos($status,'update')!==false) $rank = '0';
|
||||
elseif (strpos($status,'install')!==false) $rank = '1';
|
||||
elseif ($status=='need check') $rank = '2';
|
||||
elseif ($status=='up-to-date') $rank = '3';
|
||||
else $rank = '4';
|
||||
$changes = plugin('changes',$changes_file);
|
||||
if ($changes !== false) {
|
||||
$txtfile = "/tmp/plugins/".basename($plugin_file,'.plg').".txt";
|
||||
file_put_contents($txtfile,$changes);
|
||||
$version .= " <a href='#' title=\""._('View Release Notes')."\" onclick=\"openBox('/plugins/dynamix.plugin.manager/include/ShowChanges.php?file=".urlencode($txtfile)."','"._('Release Notes')."',600,900); return false\"><span class='fa fa-info-circle fa-fw big blue-text'></span></a>";
|
||||
}
|
||||
//write plugin information
|
||||
$empty = false;
|
||||
$id = str_replace('.','-',$name);
|
||||
echo "vid-$id::$date::$version\rsid-$id::$rank::$status\n";
|
||||
//remove temporary symlink
|
||||
@unlink("/var/log/plugins/$tmp_plg");
|
||||
}
|
||||
//remove temporary symlink
|
||||
@unlink("/var/log/plugins/$tmp_plg");
|
||||
}
|
||||
if ($empty) echo $default;
|
||||
echo "\0".$updates;
|
||||
if ($empty) echo "<tr><td colspan='6' style='text-align:center;padding-top:12px'><i class='fa fa-check-square-o icon'></i> "._('No plugins installed')."</td><tr>";
|
||||
if (!$init && !$os) echo "\0".$updates;
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user