Actualización

This commit is contained in:
Xes
2025-04-10 12:36:07 +02:00
parent 1da7c3f3b9
commit 4aff98e77b
3147 changed files with 320647 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
CleanDeleted Files Maintenance plugin
===
This plugin allows the administrator to permanently delete files marked as deleted.
Enable the plugin, then add it to the menu_administrator region and check back the
'Plugins' box on the administration page to access it.

View File

@@ -0,0 +1,192 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Plugin.
*
* @author Jose Angel Ruiz
*/
$cidReset = true;
require_once __DIR__.'/config.php';
api_protect_admin_script();
/** @var \CleanDeletedFilesPlugin $plugin */
$plugin = CleanDeletedFilesPlugin::create();
$plugin_info = $plugin->get_info();
$isPlatformAdmin = api_is_platform_admin();
if ($plugin->isEnabled() && $isPlatformAdmin) {
$htmlHeadXtra[] = '<script>
$(function() {
$(".delete-file").click(function(e) {
e.preventDefault();
var path = $(this).prop("href").substr(7);
if (confirm("'.$plugin->get_lang("ConfirmDelete").'")) {
$.post(
"src/ajax.php",
{a:"delete-file", path:path},
function(data){
if (data.status == "false") {
alert(data.message);
} else {
location.reload();
}
},
"json"
);
}
});
$(".select_all").click(function(e) {
var id = $(this).prop("id").substr(7);
if( $(this).prop("checked") ) {
$(".checkbox-"+id).prop( "checked", true);
} else {
$(".checkbox-"+id).prop( "checked", false);
}
});
$("#delete-selected-files").click(function(e) {
if (confirm("'.$plugin->get_lang("ConfirmDeleteFiles").'")) {
var list = [];
$.each($(".checkbox-item:checked"), function() {
list.push($(this).prop("id"));
});
$.post(
"src/ajax.php",
{a:"delete-files-list", list:list},
function(data){
if (data.status == "false") {
alert(data.message);
} else {
location.reload();
}
},
"json"
);
}
});
});
</script>';
$nameTools = $plugin->get_lang("FileList");
Display::display_header($nameTools);
echo Display::page_header($nameTools);
$pathList = [
"app/courses",
"app/upload",
];
function findDeletedFiles($pathRelative)
{
global $sizePath;
$pathAbsolute = api_get_path(SYS_PATH).$pathRelative;
$result = [];
if (is_dir($pathAbsolute)) {
$dir = dir($pathAbsolute);
while ($file = $dir->read()) {
if (is_file($pathAbsolute.'/'.$file)) {
$filesize = round(filesize($pathAbsolute.'/'.$file) / 1024, 1);
$pos = strpos($file, "DELETED");
if ($pos !== false) {
$result[] = [
'path_complete' => $pathAbsolute.'/'.$file,
'path_relative' => $pathRelative.'/'.$file,
'size' => $filesize,
];
$sizePath += $filesize;
}
} else {
if ($file != '..' && $file != '.') {
$result = array_merge($result, findDeletedFiles($pathRelative.'/'.$file));
}
}
}
}
return $result;
}
$sizeTotal = 0;
$i = 0;
foreach ($pathList as $pathItem) {
$sizePath = 0;
$filesDeletedList = findDeletedFiles($pathItem);
echo Display::page_subheader($plugin->get_lang("path_dir").": ".$pathItem);
if (count($filesDeletedList) > 0) {
echo "<ul>";
echo "<li>".$plugin->get_lang('FilesDeletedMark').": <strong>".count($filesDeletedList)."</strong>";
echo "<li>".$plugin->get_lang('FileDirSize').": ";
if ($sizePath >= 1024) {
echo "<strong>".round($sizePath / 1024, 1)." Mb</strong>";
} else {
echo "<strong>".$sizePath." Kb</strong>";
}
echo "</ul>";
$header = [
[
'<input type="checkbox" id="select_'.$i.'" class="select_all" />',
false,
null,
['style' => 'text-align:center'],
],
[$plugin->get_lang('path_dir'), true],
[$plugin->get_lang('size'), true, null, ['style' => 'min-width:85px']],
[get_lang('Actions'), false],
];
$data = [];
$deleteIcon = Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
foreach ($filesDeletedList as $value) {
$tools = Display::url(
$deleteIcon,
'file://'.$value['path_complete'],
['class' => 'delete-file']
);
$row = [
'<input type="checkbox"
class="checkbox-'.$i.' checkbox-item"
id="file://'.$value['path_complete'].'" />',
$value['path_relative'],
$value['size'].' '.($value['size'] >= 1024 ? 'Mb' : 'Kb'),
$tools,
];
$data[] = $row;
}
echo Display::return_sortable_table(
$header,
$data,
[],
['per_page' => 100],
[]
);
} else {
$message = $plugin->get_lang('NoFilesDeleted');
echo Display::return_message($message, 'warning', false);
}
$sizeTotal += $sizePath;
echo '<hr>';
$i++;
}
if ($sizeTotal >= 1024) {
echo $plugin->get_lang('SizeTotalAllDir').": <strong>".round($sizeTotal / 1024, 1).' Mb</strong>';
} else {
echo $plugin->get_lang('SizeTotalAllDir').": <strong>".$sizeTotal.' Kb</strong>';
}
echo '<hr>';
echo '<a href="#" id="delete-selected-files" class="btn btn-primary">'.
$plugin->get_lang("DeleteSelectedFiles").
'</a>';
Display::display_footer();
}

View File

@@ -0,0 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Config the plugin.
*
* @author Jose Angel Ruiz
*/
require_once __DIR__.'/../../main/inc/global.inc.php';

View File

@@ -0,0 +1,5 @@
<?php
/* For license terms, see /license.txt */
require_once 'config.php';

View File

@@ -0,0 +1 @@
<?php

View File

@@ -0,0 +1,17 @@
<?php
$strings['plugin_title'] = "Clean deleted files";
$strings['plugin_comment'] = "Permanently delete files marked as deleted. Enable it in the menu_administrator region then access it from main admin page.";
$strings['tool_enable'] = "Enable plugin";
$strings['FileList'] = "List of files marked as deleted";
$strings['SizeTotalAllDir'] = "Total size (all directories)";
$strings['NoFilesDeleted'] = "There are no files marked as deleted";
$strings['FilesDeletedMark'] = "Files marked as deleted";
$strings['FileDirSize'] = "Directory files size";
$strings['ConfirmDelete'] = "Are you sure you want to delete the file?";
$strings['ErrorDeleteFile'] = "An error occurred while deleting the file";
$strings['ErrorEmptyPath'] = "There was a problem deleting the file, the path cannot be empty";
$strings['DeleteSelectedFiles'] = "Delete selected files";
$strings['ConfirmDeleteFiles'] = "Are you sure you want to delete all the selected files?";
$strings['DeletedSuccess'] = "The file deletion was successful";
$strings['path_dir'] = "Directory";
$strings['size'] = "Size";

View File

@@ -0,0 +1,17 @@
<?php
$strings['plugin_title'] = "Nettoyer les fichiers supprimés";
$strings['plugin_comment'] = "Élimine de manière définitive les fichiers marqués comme éliminés. Activer le plugin dans la région 'menu_administrator' puis y accéder depuis la page d'administration.";
$strings['tool_enable'] = "Activer plugin";
$strings['FileList'] = "Liste des fichiers marqués comme éliminés";
$strings['SizeTotalAllDir'] = "Taille totale (tous les répertoires)";
$strings['NoFilesDeleted'] = "Il n'y a pas de fichiers marqués comme supprimés";
$strings['FilesDeletedMark'] = "Fichiers marqués comme supprimés";
$strings['FileDirSize'] = "Taille des fichiers du répertoire";
$strings['ConfirmDelete'] = "Êtes-vous certain de vouloir supprimer le fichier?";
$strings['ErrorDeleteFile'] = "Une erreur a empêché la suppression du fichier";
$strings['ErrorEmptyPath'] = "Il y a eu un problème au moment de supprimer le fichier. Le chemin ne peut être vide.";
$strings['DeleteSelectedFiles'] = "Supprimer les fichiers sélectionnés";
$strings['ConfirmDeleteFiles'] = "Êtes-vous certain de vouloir supprimer tous les fichiers sélectionnés?";
$strings['DeletedSuccess'] = "La suppression des fichiers s'est bien déroulée.";
$strings['path_dir'] = "Répertoire";
$strings['size'] = "Taille";

View File

@@ -0,0 +1,17 @@
<?php
$strings['plugin_title'] = "Limpiar ficheros borrados";
$strings['plugin_comment'] = "Elimina de forma definitiva los ficheros marcados como eliminados. Active el plugin en la región 'menu_administrator' y acceda desde la página principal de administración.";
$strings['tool_enable'] = "Activar plugin";
$strings['FileList'] = "Lista de archivos marcados como eliminados";
$strings['SizeTotalAllDir'] = "Tamaño total (todos los directorios)";
$strings['NoFilesDeleted'] = "No hay ficheros marcados como eliminados";
$strings['FilesDeletedMark'] = "Ficheros marcados como eliminados";
$strings['FileDirSize'] = "Tamaño de los ficheros del directorio";
$strings['ConfirmDelete'] = "¿Está seguro que desea borrar el fichero?";
$strings['ErrorDeleteFile'] = "Se ha producido un error al borrar el fichero";
$strings['ErrorEmptyPath'] = "Ha habido un problema al borrar el fichero, la ruta no puede ser vacía";
$strings['DeleteSelectedFiles'] = "Borrar archivos seleccionados";
$strings['ConfirmDeleteFiles'] = "¿Esta seguro que desea borrar todos los ficheros seleccionados?";
$strings['DeletedSuccess'] = "El borrado de archivos ha sido correcto";
$strings['path_dir'] = "Directorio";
$strings['size'] = "Tamaño";

View File

@@ -0,0 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Plugin.
*
* @author Jose Angel Ruiz
*/
require_once __DIR__.'/config.php';
$plugin_info = CleanDeletedFilesPlugin::create()->get_info();

View File

@@ -0,0 +1,34 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Clean deleted files plugin.
*
* @author Jose Angel Ruiz
*/
class CleanDeletedFilesPlugin extends Plugin
{
public $isAdminPlugin = true;
/**
* Class constructor.
*/
protected function __construct()
{
$version = '1.0';
$author = 'José Angel Ruiz (NOSOLORED)';
parent::__construct($version, $author, ['enabled' => 'boolean']);
$this->isAdminPlugin = true;
}
/**
* @return RedirectionPlugin
*/
public static function create()
{
static $result = null;
return $result ? $result : $result = new self();
}
}

View File

@@ -0,0 +1,47 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Responses to AJAX calls.
*/
require_once '../config.php';
api_protect_admin_script();
$plugin = CleanDeletedFilesPlugin::create();
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
switch ($action) {
case 'delete-file':
$path = isset($_REQUEST['path']) ? $_REQUEST['path'] : null;
if (empty($path)) {
echo json_encode(["status" => "false", "message" => $plugin->get_lang('ErrorEmptyPath')]);
exit;
}
if (unlink($path)) {
Display::addFlash($plugin->get_lang("DeletedSuccess"), 'success');
echo json_encode(["status" => "true"]);
} else {
echo json_encode(["status" => "false", "message" => $plugin->get_lang('ErrorDeleteFile')]);
}
break;
case 'delete-files-list':
$list = isset($_REQUEST['list']) ? $_REQUEST['list'] : [];
if (empty($list)) {
echo json_encode(["status" => "false", "message" => $plugin->get_lang('ErrorEmptyPath')]);
exit;
}
foreach ($list as $value) {
if (empty($value)) {
continue;
}
unlink($value);
}
Display::addFlash($plugin->get_lang("DeletedSuccess"), 'success');
echo json_encode(["status" => "true"]);
break;
}