Bladeren bron

Refactor les chemins de fichiers pour utiliser ROOT_DIR et mise à jour du .gitignore pour inclure le dossier vidéo

stany.ferer 2 maanden geleden
bovenliggende
commit
76a4941af8

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 env.inc.php
+video/*

+ 42 - 42
core/class/core.class.php

@@ -2,17 +2,18 @@
 
 class core
 {
-    public static function switch(){
-        if($_SERVER['REQUEST_METHOD'] === 'POST'){
-            if(isset($_POST["from"])){
-                if($_POST["from"] == "cse.invent" AND isset($_POST["token"])){
-                    include_once "../core/submit/record.jwt.php";
-                } elseif($_POST["from"] == "video.form.add") {
-                    include_once "../core/submit/video.add.php";
-                } elseif($_POST["from"] == "video.form") {
-                    include_once "../core/submit/video.edit.php";
-                } elseif($_POST["from"] == "video.cut") {
-                    include_once "../core/submit/video.cut.php";
+    public static function switch()
+    {
+        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+            if (isset($_POST["from"])) {
+                if ($_POST["from"] == "cse.invent" and isset($_POST["token"])) {
+                    include_once ROOT_DIR . "/core/submit/record.jwt.php";
+                } elseif ($_POST["from"] == "video.form.add") {
+                    include_once ROOT_DIR . "/core/submit/video.add.php";
+                } elseif ($_POST["from"] == "video.form") {
+                    include_once ROOT_DIR . "/core/submit/video.edit.php";
+                } elseif ($_POST["from"] == "video.cut") {
+                    include_once ROOT_DIR . "/core/submit/video.cut.php";
                 } else {
                     echo "Error : switch :. from else post";
                     var_dump($_POST);
@@ -22,44 +23,43 @@ class core
                 echo "Error : switch :. from post";
                 exit();
             }
-            
-        } elseif($_SERVER['REQUEST_METHOD'] === 'GET') { 
-        
-            if(isset($_GET["video"])){
-                include_once "../core/page/video.show.php";
-            } elseif(isset($_GET["preview"])){
-                include_once "../core/page/video.preview.php";
-            } elseif(isset($_GET["delete"])){
-                include_once "../core/submit/video.delete.php";
+        } elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
+
+            if (isset($_GET["video"])) {
+                include_once ROOT_DIR . "/core/page/video.show.php";
+            } elseif (isset($_GET["preview"])) {
+                include_once ROOT_DIR . "/core/page/video.preview.php";
+            } elseif (isset($_GET["delete"])) {
+                include_once ROOT_DIR . "/core/submit/video.delete.php";
             } else {
-                require_once "../core/controllers/session.php";
-                include_once "../core/page/_header.php";
-                if(empty($_GET["video"]) AND empty($_GET["preview"]) AND empty($_GET["edit"]) AND empty($_GET["cut"])){
-                    include_once "../core/page/videos.all.php";
-                } elseif(isset($_GET["edit"]) AND $_GET["edit"] == "add"){
-                    include_once "../core/page/video.form.add.php";
-                } elseif(isset($_GET["edit"]) AND $_GET["edit"] != "add"){
-                    include_once "../core/page/video.form.php";
-                } elseif(isset($_GET["cut"])){
-                    include_once "../core/page/video.cut.php";
+                require_once ROOT_DIR . "/core/controllers/session.php";
+                include_once ROOT_DIR . "/core/page/_header.php";
+                if (empty($_GET["video"]) and empty($_GET["preview"]) and empty($_GET["edit"]) and empty($_GET["cut"])) {
+                    include_once ROOT_DIR . "/core/page/videos.all.php";
+                } elseif (isset($_GET["edit"]) and $_GET["edit"] == "add") {
+                    include_once ROOT_DIR . "/core/page/video.form.add.php";
+                } elseif (isset($_GET["edit"]) and $_GET["edit"] != "add") {
+                    include_once ROOT_DIR . "/core/page/video.form.php";
+                } elseif (isset($_GET["cut"])) {
+                    include_once ROOT_DIR . "/core/page/video.cut.php";
                 } else {
                     echo "Error : switch :. from get";
                     exit();
                 }
-                include_once "../core/page/_footer.php";
+                include_once ROOT_DIR . "/core/page/_footer.php";
             }
         } else {
             echo "Error : switch";
             exit();
         }
     }
-    
+
     public static function print_r($_debug, int $_exit = NULL)
     {
         echo "<pre>";
-        if(is_array($_debug)) {
+        if (is_array($_debug)) {
             print_r($_debug);
-        } elseif(is_object($_debug)){
+        } elseif (is_object($_debug)) {
             var_dump($_debug);
         } else {
             echo $_debug;
@@ -68,27 +68,27 @@ class core
         ($_exit != NULL) ? exit() : NULL;
     }
 
-    public static function formatDuration(float $seconds = NULL, string $type = NULL) {
+    public static function formatDuration(float $seconds = NULL, string $type = NULL)
+    {
 
-        if($seconds == NULL){
+        if ($seconds == NULL) {
             return NULL;
         }
 
         // Calculer les heures
         $hours = floor($seconds / 3600);
-        
+
         // Calculer les minutes restantes après avoir soustrait les heures
         $minutes = floor(($seconds % 3600) / 60);
-        
+
         // Calculer les secondes restantes après avoir soustrait les minutes
         $remainingSeconds = $seconds % 60;
-        
+
         // Retourner la durée formatée en "H:i:s"
-        if($type == ":"){
+        if ($type == ":") {
             return sprintf("%02d:%02d:%02d", $hours, $minutes, $remainingSeconds);
         } else {
             return sprintf("%02dh %02dm %02ds", $hours, $minutes, $remainingSeconds);
         }
-        
     }
-}
+}

+ 7 - 7
core/class/fichier.class.php

@@ -9,7 +9,7 @@ class fichier
             $hash = self::generateHash($file['name']);
             $durationInSeconds = fichier::getVideoDuration($file["tmp_name"]);
 
-            if (copy($file["tmp_name"], "../video/" . $md5 . ".mp4")) {
+            if (copy($file["tmp_name"], ROOT_DIR . "/video/" . $md5 . ".mp4")) {
                 db::query("INSERT INTO videos (title, titleTmp, type, size, duration, md5, hash, active, dateEvent, user) VALUES (:title, :titleTmp, :type, :size, :duration, :md5, :hash, :active, :dateEvent, :user)");
                 db::bind(':title', htmlspecialchars($form['videoName']));
                 db::bind(':titleTmp', htmlspecialchars($file['name']));
@@ -63,7 +63,7 @@ class fichier
         db::execute();
     }
 
-    public static function delete(string $_md5, string $_folderFiles = "../video/")
+    public static function delete(string $_md5, string $_folderFiles = ROOT_DIR . "/video/")
     {
         if (isset($_md5) and $_md5 != NULL and file_exists($_folderFiles . $_md5)) {
             if (unlink($_folderFiles . $_md5 . ".mp4")) {
@@ -156,13 +156,13 @@ class fichier
 
     static public function generatePreview($_md5)
     {
-        $videoPreview = "../video/" . $_md5 . ".jpg";
+        $videoPreview = ROOT_DIR . "/video/" . $_md5 . ".jpg";
         if (file_exists($videoPreview)) {
             return ['success' => TRUE, 'file' => 'Le fichier existe déjà'];
         }
 
         $time = "00:00:00";
-        $videoFile = "../video/" . $_md5 . ".mp4";
+        $videoFile = ROOT_DIR . "/video/" . $_md5 . ".mp4";
 
         if (!file_exists($videoFile)) {
             return ['success' => FALSE, 'error' => 'Le fichier vidéo n\'existe pas.'];
@@ -180,7 +180,7 @@ class fichier
 
         // Vérifier si la commande a réussi
         if ($return_var === 0) {
-            $destinationFile = "../video/" . $_md5 . ".jpg";
+            $destinationFile = ROOT_DIR . "/video/" . $_md5 . ".jpg";
             if (copy($outputFile, $destinationFile)) {
                 unlink($outputFile);  // Supprimer le fichier temporaire
                 return ['success' => TRUE, 'file' => $destinationFile];
@@ -209,7 +209,7 @@ class fichier
             }
 
             // Chemin sécurisé du fichier vidéo
-            $videoFile = "../video/" . basename($_POST['md5']) . ".mp4";
+            $videoFile = ROOT_DIR . "/video/" . basename($_POST['md5']) . ".mp4";
 
             if (!file_exists($videoFile)) {
                 alert::addAlert('error', 'Le fichier vidéo n\'existe pas.');
@@ -231,7 +231,7 @@ class fichier
 
             // Vérifier si la commande a réussi
             if ($return_var === 0) {
-                $destinationFile = "../video/_" . basename($_POST['md5'] . ".mp4");
+                $destinationFile = ROOT_DIR . "/video/_" . basename($_POST['md5'] . ".mp4");
                 if (copy($outputFile, $destinationFile)) {
                     unlink($outputFile);  // Supprimer le fichier temporaire
                     alert::addAlert('success', 'Vidéo découpée avec succès.');

+ 2 - 2
core/controllers/header.php

@@ -4,6 +4,6 @@ setlocale(LC_TIME, 'fr_FR');
 date_default_timezone_set("Europe/Paris");
 
 spl_autoload_register(function ($class_name) {
-    (file_exists('../core/class/'.$class_name.'.class.php'))?	
-    require_once '../core/class/'.$class_name.'.class.php' : '';
+    (file_exists(__DIR__ . '/../class/' . $class_name . '.class.php')) ?
+        require_once __DIR__ . '/../class/' . $class_name . '.class.php' : '';
 });

+ 8 - 8
core/submit/video.cut.php

@@ -1,19 +1,19 @@
-<?php 
+<?php
 
-if(isset($_POST["from"]) AND $_POST["from"] == "video.cut"){
-    require_once "../core/controllers/session.php";
+if (isset($_POST["from"]) and $_POST["from"] == "video.cut") {
+    require_once ROOT_DIR . "/core/controllers/session.php";
     $execute = fichier::cut();
 
-    if($execute["success"] == TRUE){
-        unlink("../video/" . $_POST['md5']. ".mp4");
-        rename("../video/_" . $_POST['md5']. ".mp4", "../video/" . $_POST['md5']. ".mp4");
-        $durationInSeconds = fichier::getVideoDuration("../video/" . $_POST["md5"]. ".mp4");
+    if ($execute["success"] == TRUE) {
+        unlink(ROOT_DIR . "/video/" . $_POST['md5'] . ".mp4");
+        rename(ROOT_DIR . "/video/_" . $_POST['md5'] . ".mp4", ROOT_DIR . "/video/" . $_POST['md5'] . ".mp4");
+        $durationInSeconds = fichier::getVideoDuration(ROOT_DIR . "/video/" . $_POST["md5"] . ".mp4");
         fichier::updateTime($_POST["id"], $durationInSeconds);
     } else {
         core::print_r($execute);
         exit();
     }
-    header("Location: /edit/".$_POST["hash"]);
+    header("Location: /edit/" . $_POST["hash"]);
     exit();
 } else {
     header("Location: /");

+ 1 - 1
core/submit/video.delete.php

@@ -1,7 +1,7 @@
 <?php
 
 if (isset($_GET["delete"])) {
-    require_once "../core/controllers/session.php";
+    require_once ROOT_DIR . "/core/controllers/session.php";
     fichier::delete($_GET["delete"]);
     header("Location: /");
     exit();

+ 4 - 4
public/index.php

@@ -1,5 +1,7 @@
 <?php
 
+define('ROOT_DIR', realpath(__DIR__ . '/../'));
+
 session_start();
 
 /*
@@ -7,8 +9,6 @@ error_reporting(E_ALL);
 ini_set("display_errors", 1);
 */
 
-require_once "../env.inc.php";
-require_once "../core/controllers/header.php";
+require_once ROOT_DIR . "/env.inc.php";
+require_once ROOT_DIR . "/core/controllers/header.php";
 core::switch();
-
-?>