function displayFiles($path) { echo "<table class='table table-hover file-list'>\n <thead><th>Nome</th><th>Dimensione</th><th>Ultima modifica</th></thead>"; $file_array = array_diff(scandir("../" . $path), array('..', '.', '.DS_Store')); foreach ($file_array as $file) { $url = "../" . $path . "/" . $file; if (is_dir($url)) { $name = $file; $folder_path = $path . "/" . $file; $size = formatBytes(getFolderSize($url), 1); $date = date("d/m/Y", stat($url)['mtime']); echo "<tr><td><span class='fa-stack fa-2x'><i class='fa fa-folder'></i></span> <a href='#' data-path=\"{$folder_path}\" class='file-list-folder'>{$name}</a>"; echo "<button type='button' class='btn btn-link pull-right lmb remove-folder tooltipped' data-toggle='tooltip' title='Elimina' data-path=\"{$folder_path}\"><i class='fa fa-remove'></i></button>"; echo "<button type='button' class='btn btn-link pull-right lmb edit-folder tooltipped' data-toggle='tooltip' title='Rinomina' data-path=\"{$folder_path}\"><i class='fa fa-edit'></i></button>"; echo "</td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>"; } else { $finfo = finfo_open(FILEINFO_MIME_TYPE); $content_type = finfo_file($finfo, $url); $file_icon = getFileTypeIcon($content_type, $file); $size = formatBytes(filesize($url), 1); $date = date("d/m/Y", filemtime($url)); $preview = canPreview($content_type); if ($preview == "no") { echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href=\"{$url}\" class='file-list' target='_blank'>{$file}</a>"; } else { echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href='#' data-path=\"{$url}\" data-preview_mode='{$preview}' class='file-list-previewable'>{$file}</a>"; } echo "<button type='button' class='btn btn-link pull-right lmb remove-file tooltipped' data-toggle='tooltip' title='Elimina' data-path=\"{$url}\"><i class='fa fa-remove'></i></button>"; echo "</td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>"; } } echo "</table>"; }
function AJAXSpecialFileListerPreview($path) { function getFileTypeIcon($content_type, $file_name) { if (strpos($file_name, ".docx") !== false) { return "fa-file-word-o"; } elseif (strpos($file_name, ".xlsx") !== false) { return "fa-file-excel-o"; } elseif (strpos($file_name, ".pptx") !== false) { return "fa-file-powerpoint-o"; } if (strpos($content_type, "application") !== false) { switch ($content_type) { case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": case "application/msword": case "application/vnd.oasis.opendocument.text": return "fa-file-word-o"; break; case "application/vnd.oasis.opendocument.presentation": case "application/vnd.openxmlformats-officedocument.presentationml.presentation": case "application/vnd.ms-powerpoint": return "fa-file-powerpoint-o"; break; case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": case "application/vnd.ms-excel": case "application/vnd.oasis.opendocument.spreadsheet": return "fa-file-excel-o"; break; case "application/pdf": return "fa-file-pdf-o"; break; case "application/ogg": return "fa-file-audio-o"; break; case "application/zip": return "fa-file-archive-o"; break; default: return "fa-file-o"; break; } } elseif (strpos($content_type, "audio") !== false) { return "fa-file-audio-o"; } elseif (strpos($content_type, "video") !== false) { return "fa-file-video-o"; } elseif (strpos($content_type, "image") !== false) { return "fa-file-image-o"; } elseif (strpos($content_type, "text") !== false) { return "fa-file-text-o"; } else { return "fa-file-o"; } } function formatBytes($size, $precision = 2) { //TODO: Scegliere se visualizzare in base binaria o decimale. $base = log($size) / log(1024); $suffixes = array(' B', ' KiB', ' MiB', ' GiB', ' TiB'); return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)]; } if (file_exists("../" . $path)) { echo "<table class='table table-hover'>\n <thead><th>Nome</th><th>Dimensione</th><th>Ultima modifica</th></thead>"; $file_array = array_diff(scandir("../" . $path), array('..', '.', '.DS_Store')); foreach ($file_array as $file) { $url = "../" . $path . "/" . $file; if (!is_dir($url)) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $content_type = finfo_file($finfo, $url); $file_icon = getFileTypeIcon($content_type, $file); $size = formatBytes(filesize($url), 1); $date = date("d/m/Y", filemtime($url)); echo "<tr><td><i class='fa {$file_icon}'></i> <a href=\"{$url}\" target='_blank'>{$file}</a>"; echo "</td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>"; } } echo "</table>"; } else { echo "<div class='alert alert-danger' role='alert'>\n <i class='fa fa-exclamation-circle'></i> <strong>Errore!</strong> Il percorso specificato non esiste. Verificare il percorso o l'URL e verificare che i permessi siano corretti.\n </div>"; } }
?> '> </div> <p> Le sottocartelle non sono visualizzate. I files sono solitamente archiviati in <code>files/</code>. Il percorso va specificato relativamente alla cartella base del cms (<code>files/x</code>)</p> </div> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">File nella cartella selezionata <a class='update-preview lmb pull-right tooltipped' data-toggle='tooltip' title='Aggiorna'><i class='text-primary fa fa-refresh'></i></a></h3> </div> <div class="panel-body"> <?php if (file_exists("../" . $path)) { echo "<table class='table table-hover'>\n <thead><th>Nome</th><th>Dimensione</th><th>Ultima modifica</th></thead>"; $file_array = array_diff(scandir("../" . $path), array('..', '.', '.DS_Store')); foreach ($file_array as $file) { $url = "../" . $path . "/" . $file; if (!is_dir($url)) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $content_type = finfo_file($finfo, $url); $file_icon = getFileTypeIcon($content_type, $file); $size = formatBytes(filesize($url), 1); $date = date("d/m/Y", filemtime($url)); echo "<tr><td><i class='fa {$file_icon}'></i> <a href=\"{$url}\" target='_blank'>{$file}</a>"; echo "</td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>"; } } echo "</table>"; } else { echo "<div class='alert alert-danger' role='alert'>\n <i class='fa fa-exclamation-circle'></i> <strong>Errore!</strong> Il percorso specificato non esiste. Verificare il percorso o l'URL e verificare che i permessi siano corretti.\n </div>"; } echo "</div></div>";
function displayFiles($path) { global $connection, $config; //calculate permissions $permissions = validatePermissions(validateUser()); //Switch mode based on path echo "<table class='table table-hover file-list'>"; if ($path == "/") { //Root: list containers echo "<thead><tr><th>Nome</th></tr></thead>"; $request = "SELECT * FROM teachers_users"; $result = $connection->query($request); while ($line = $result->fetch_assoc()) { $name = $line["user"]; $title = ucfirst($name); if (file_exists($config->plugin_notes_engine_fpath . "/" . $name)) { echo "<tr><td><span class='fa-stack fa-3x'><i class='fa fa-folder'></i></span> <a href='#' id='{$name}' class='file-list-folder'>{$title}</a></td></tr>"; } } } else { //check if it is a VFS folder then if it is not check if it is a container if (strpos($path, "/") !== false) { $folders = explode("/", $path); $folder = end($folders); } else { $folder = $path; } echo "<thead><tr><th>Nome</th><th>Insegnante</th><th>Dimensione</th><th>Ultima modifica</th></tr></thead>"; $request = "SELECT * FROM notes_vfs WHERE id = '{$folder}'"; $result = $connection->query($request); $line = $result->fetch_assoc(); if (isset($line["name"])) { //it is a VFS folder, check for folders with parent=$folder, then download blob list and get items in that folder, save name for later use $folder_container = $line["container"]; $request = "SELECT * FROM notes_vfs WHERE parent = '{$folder}'"; $result = $connection->query($request); } else { //it is a container: $name = str_replace("/", "", $path); $request = "SELECT * FROM teachers_users WHERE user='******'"; $result = $connection->query($request); $line = $result->fetch_assoc(); $folder_container = $line["user"]; if (file_exists($config->plugin_notes_engine_fpath . "/" . $folder_container)) { $request = "SELECT * FROM notes_vfs WHERE parent = '/' AND container='{$folder_container}'"; $result = $connection->query($request); } else { echo "Error fetching container: name does not exists"; return; } } $dir_array = []; while ($line = $result->fetch_assoc()) { $name = $line["name"]; $id = $line["id"]; $container = ucfirst($line["container"]); $dir_array[] = $id; echo "<tr><td><span class='fa-stack fa-2x'><i class='fa fa-folder'></i></span> <a href='#' id='{$id}' class='file-list-folder'>{$name}</a>"; if ($permissions == $line["container"] or $permissions == "all") { echo "<button type='button' class='btn btn-link pull-right lmb remove-folder tooltipped' data-toggle='tooltip' title='Elimina' id='{$id}'><i class='fa fa-remove'></i></button>"; echo "<button type='button' class='btn btn-link pull-right lmb edit-folder tooltipped' data-toggle='tooltip' title='Rinomina' id='{$id}'><i class='fa fa-edit'></i></button>"; } echo "</td><td><span class='text-muted container-value'>{$container}</span></td><td></td><td></td></tr>"; } //get file list $file_array = array_diff(array_diff(scandir($config->plugin_notes_engine_fpath . "/" . $path), array('..', '.', '.DS_Store')), $dir_array); foreach ($file_array as $file) { $url = $config->plugin_notes_engine_fpath . "/" . $path . "/" . $file; if (!is_dir($url)) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $container = ucfirst($folder_container); $content_type = finfo_file($finfo, $url); $file_icon = getFileTypeIcon($content_type, $file); $size = formatBytes(filesize($url), 1); $date = date("d/m/Y", filemtime($url)); $preview = canPreview($content_type); if ($preview == "no") { echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href=\"{$url}\" class='file-list' target='_blank'>{$file}</a>"; } else { echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href='#' data-path=\"{$url}\" data-preview_mode='{$preview}' class='file-list-previewable'>{$file}</a>"; } if ($permissions == $folder_container or $permissions == "all") { echo "<button type='button' class='btn btn-link pull-right lmb remove-file tooltipped' data-toggle='tooltip' title='Elimina' data-path=\"{$url}\"><i class='fa fa-remove'></i></button>"; if (isEditable($content_type)) { if ($content_type == "text/html") { $mode = "html"; } else { $mode = "code"; } echo "<button type='button' class='btn btn-link pull-right lmb edit-file tooltipped' data-toggle='tooltip' title='Modifica' data-edit-mode='{$mode}' data-path='{$url}'><i class='fa fa-edit'></i></button>"; } } echo "</td><td><span class='text-muted container-value'>{$container}</span></td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>"; } } } echo "</table>"; }