From 218e5a3afc4ef0c11c69f50ca7aeb955719ad8be Mon Sep 17 00:00:00 2001 From: Maxim Stewart Date: Mon, 23 Apr 2018 01:46:19 -0500 Subject: [PATCH] Have recursion option or season folders. --- index.html | 3 ++ resources/js/ajax.js | 7 +-- resources/js/filesystemActions.js | 8 +-- resources/php/getDirList.php | 87 +++++++++++++++++++------------ 4 files changed, 65 insertions(+), 40 deletions(-) diff --git a/index.html b/index.html index 256570d..63eaec9 100644 --- a/index.html +++ b/index.html @@ -24,6 +24,9 @@
+ + +     Path:   diff --git a/resources/js/ajax.js b/resources/js/ajax.js index 4a3d1a6..da70738 100644 --- a/resources/js/ajax.js +++ b/resources/js/ajax.js @@ -57,6 +57,7 @@ function getDir(query) { // Get dir info... function process(path) { + var mergeType = document.getElementById("MergeType"); var xhttp = new XMLHttpRequest(); // Create the xhttp object // This is actually run after open and send are done @@ -72,10 +73,10 @@ function process(path) { } } }; - xhttp.open("POST", "resources/php/getDirList.php", true); // Open the connection + xhttp.open("POST", "resources/php/getDirList.php", true); // Open the connection xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.overrideMimeType('application/xml'); // Force return to be XML - xhttp.send(path); // Start the process + xhttp.overrideMimeType('application/xml'); // Force return to be XML + xhttp.send(path + "&mergeType=" + mergeType.checked + "Here"); // Start the process // Use a cookie for persistence during browser session.... document.cookie = path + "; expires=Sun, 31 Dec 2034 12:00:00 UTC"; diff --git a/resources/js/filesystemActions.js b/resources/js/filesystemActions.js index 62f4e64..30f3d24 100644 --- a/resources/js/filesystemActions.js +++ b/resources/js/filesystemActions.js @@ -8,7 +8,7 @@ function renameItem(obj) { console.log("Old name: " + oldName); console.log("New name: " + newName); - xhttp.open("POST", "resources/php/filesystemActions.php", false); + xhttp.open("POST", "resources/php/filesystemActions.php", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send(formData); } @@ -20,9 +20,9 @@ function createItem(type) { var xhttp = new XMLHttpRequest(); newItem.value = ""; - xhttp.open("POST", "resources/php/filesystemActions.php", false); + xhttp.open("POST", "resources/php/filesystemActions.php", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.send("createItem=true&item=" + fullPth + "&type=" + type + ""); + xhttp.send("createItem=true&item=" + fullPth + "&type=" + type); } function startDeleteItem(item) { @@ -40,7 +40,7 @@ function deleteItem(item) { if (answer == true) { var xhttp = new XMLHttpRequest(); - xhttp.open("POST", "resources/php/filesystemActions.php", false); + xhttp.open("POST", "resources/php/filesystemActions.php", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send("deleteItem=true&item=" + fullPth); diff --git a/resources/php/getDirList.php b/resources/php/getDirList.php index 9f6b554..a7ee461 100644 --- a/resources/php/getDirList.php +++ b/resources/php/getDirList.php @@ -2,51 +2,72 @@ session_start(); -// Retrieve data -function dirListing($NEWPATH) { +// Start of retrieving dir data +function startListing($NEWPATH, $MERGESEASSONS) { if (is_dir($NEWPATH)) { $GeneratedXML = "" . "" . $NEWPATH . ""; + $subPath = ""; // This is used for season scanning as a means of properly getting + // the video src.... It's left blank when not in a sub dir + listDir($GeneratedXML, $NEWPATH, $MERGESEASSONS, $subPath); - $dirContents = scandir($NEWPATH); - foreach ($dirContents as $fileName) { - $fullPath = $NEWPATH . $fileName; - - if (is_dir($NEWPATH . $fileName)) { - $GeneratedXML .= "" . $fileName . "/"; - } elseif (preg_match('/^.*\.(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg|mp4|webm)$/i', strtolower($fileName))) { - $NAMEHASH = hash('sha256', $fileName); - if (!file_exists('resources/images/thumbnails/' . $NAMEHASH . '.jpg')) { - shell_exec('resources/ffmpegthumbnailer -t 65% -s 320 -c jpg -i "' - . $fullPath . '" -o resources/images/thumbnails/' - . $NAMEHASH . '.jpg'); - } - $GeneratedXML .= - "" - . "/resources/images/thumbnails/" . $NAMEHASH . ".jpg" - . "" . $fileName . "" . - ""; - } elseif (preg_match('/^.*\.(png|jpg|gif|jpeg)$/i', strtolower($fileName))) { - $GeneratedXML .= - "" - . "" . $fileName . "" - . ""; - } else { - $GeneratedXML .= - "" - . "" . $fileName . "" - . ""; - } - } $GeneratedXML .= ""; echo $GeneratedXML; } } +// Used for recursion +function listDir(&$GeneratedXML, &$NEWPATH, &$MERGESEASSONS, &$subPath) { + $dirContents = scandir($NEWPATH); + foreach ($dirContents as $fileName) { + // Filter for . and .. items We have controls for these actions + if ($fileName !== "." && $fileName !== "..") { + $fullPath = $NEWPATH . $fileName; + if ($MERGESEASSONS == "trueHere" && is_dir($fullPath) && + strpos(strtolower($fileName), 'season') !== false) { + $fileName .= "/"; + listDir($GeneratedXML, $fullPath, $MERGESEASSONS, $fileName); + } else { + processItem($GeneratedXML, $fullPath, $fileName, $subPath); + } + } + } +} + +// Assign XML Markup based on file type +function processItem(&$GeneratedXML, &$fullPath, &$fileName, $subPath) { + if (is_dir($fullPath)) { + $GeneratedXML .= "" . $fileName . "/"; + } elseif (preg_match('/^.*\.(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg|mp4|webm)$/i', strtolower($fileName))) { + $NAMEHASH = hash('sha256', $fileName); + if (!file_exists('resources/images/thumbnails/' . $NAMEHASH . '.jpg')) { + shell_exec('resources/ffmpegthumbnailer -t 65% -s 320 -c jpg -i "' + . $subPath . $fullPath . '" -o resources/images/thumbnails/' + . $NAMEHASH . '.jpg'); + } + $GeneratedXML .= + "" + . "/resources/images/thumbnails/" . $NAMEHASH . ".jpg" + . "" . $subPath . $fileName . "" . + ""; + } elseif (preg_match('/^.*\.(png|jpg|gif|jpeg)$/i', strtolower($fileName))) { + $GeneratedXML .= + "" + . "" . $subPath . $fileName . "" + . ""; + } else { + $GeneratedXML .= + "" + . "" . $subPath . $fileName . "" + . ""; + } +} + + // Determin action chdir("../../"); if (isset($_POST['dirQuery'])) { - dirListing(trim($_POST['dirQuery'])); + startListing(trim($_POST['dirQuery']), $_POST['mergeType']); } else { echo "

Error! Illegal Access Method!

"; }