Favorites: automatically clean non-existing pages

This commit is contained in:
bergware
2024-01-03 12:43:08 +01:00
parent 25340cc3be
commit 08ecf1d9d2
2 changed files with 13 additions and 2 deletions

View File

@@ -14,6 +14,6 @@ $(function(){
$(this).find('span').append('<i class="fa fa-heartbeat favo" title="_(Remove from favorites)_" onclick="delPage(&quot;'+page+'&quot;);return false"></i>');
$(this).hover(function(){$(this).find('i.favo').show();},function(){$(this).find('i.favo').hide();});
});
if ($('div.Panel').length==0) $('#nofavs').show();
$.post('/webGui/include/MyFavorites.php',{action:'clear'},function(){if ($('div.Panel').length==0) $('#nofavs').show();});
});
</script>

View File

@@ -14,10 +14,21 @@
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
$permit = ['del','add'];
$action = $_POST['action']??'';
$page = glob("$docroot/plugins/*/{$_POST['page']}.page",GLOB_NOSORT)[0];
$cfg = '/boot/config/favorites.cfg';
// remove non-existing pages
if ($action=='clear') {
if (file_exists($cfg)) foreach (file($cfg,FILE_IGNORE_NEW_LINES) as $page) {
if (!file_exists($page)) {
$page = str_replace('/','\/',$page);
exec("sed -i '/$page/d' $cfg 2>/dev/null");
}
}
exit;
}
// validate input
$page = glob("$docroot/plugins/*/{$_POST['page']}.page",GLOB_NOSORT)[0];
if (!$page || !in_array($action,$permit)) exit;
$file = fopen($page,'r');