reformattings
no redirect on tagclick on homepage no multiple add of same tag possible
This commit is contained in:
		@@ -212,6 +212,28 @@ class VideoParser {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * get all videoinfos of a video file
 | 
			
		||||
     *
 | 
			
		||||
     * @param $video string name including extension
 | 
			
		||||
     * @return object all infos as object
 | 
			
		||||
     */
 | 
			
		||||
    private function _get_video_attributes(string $video) {
 | 
			
		||||
        $command = "mediainfo \"../$this->videopath$video\" --Output=JSON";
 | 
			
		||||
        $output = shell_exec($command);
 | 
			
		||||
        return json_decode($output);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * write a line to the output log file
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $message message to write
 | 
			
		||||
     */
 | 
			
		||||
    public function writeLog(string $message) {
 | 
			
		||||
        file_put_contents("/tmp/output.log", $message, FILE_APPEND);
 | 
			
		||||
        flush();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * insert the corresponding videosize tag to a specific videoid
 | 
			
		||||
     * @param $width int video width
 | 
			
		||||
@@ -246,28 +268,6 @@ class VideoParser {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * get all videoinfos of a video file
 | 
			
		||||
     *
 | 
			
		||||
     * @param $video string name including extension
 | 
			
		||||
     * @return object all infos as object
 | 
			
		||||
     */
 | 
			
		||||
    private function _get_video_attributes(string $video) {
 | 
			
		||||
        $command = "mediainfo \"../$this->videopath$video\" --Output=JSON";
 | 
			
		||||
        $output = shell_exec($command);
 | 
			
		||||
        return json_decode($output);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * write a line to the output log file
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $message message to write
 | 
			
		||||
     */
 | 
			
		||||
    public function writeLog(string $message) {
 | 
			
		||||
        file_put_contents("/tmp/output.log", $message, FILE_APPEND);
 | 
			
		||||
        flush();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * ckecks if tag exists -- if not creates it
 | 
			
		||||
     * @param string $tagname the name of the tag
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
<?php
 | 
			
		||||
require_once __DIR__.'/../Database.php';
 | 
			
		||||
require_once __DIR__ . '/../Database.php';
 | 
			
		||||
 | 
			
		||||
abstract class RequestBase {
 | 
			
		||||
    protected $conn;
 | 
			
		||||
@@ -34,17 +34,17 @@ abstract class RequestBase {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send response message and exit script
 | 
			
		||||
     * @param $message string the response message
 | 
			
		||||
     */
 | 
			
		||||
    function commitMessage($message){
 | 
			
		||||
        echo $message;
 | 
			
		||||
        exit(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * add the action handlers in this abstract method
 | 
			
		||||
     */
 | 
			
		||||
    abstract function initHandlers();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send response message and exit script
 | 
			
		||||
     * @param $message string the response message
 | 
			
		||||
     */
 | 
			
		||||
    function commitMessage($message) {
 | 
			
		||||
        echo $message;
 | 
			
		||||
        exit(0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -11,30 +11,15 @@ class Tags extends RequestBase {
 | 
			
		||||
        $this->getFromDB();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function getFromDB(){
 | 
			
		||||
        /**
 | 
			
		||||
         * returns all available tags from database
 | 
			
		||||
         */
 | 
			
		||||
        $this->addActionHandler("getAllTags", function () {
 | 
			
		||||
            $query = "SELECT tag_name,tag_id from tags";
 | 
			
		||||
            $result = $this->conn->query($query);
 | 
			
		||||
 | 
			
		||||
            $rows = array();
 | 
			
		||||
            while ($r = mysqli_fetch_assoc($result)) {
 | 
			
		||||
                array_push($rows, $r);
 | 
			
		||||
            }
 | 
			
		||||
            $this->commitMessage(json_encode($rows));
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function addToDB(){
 | 
			
		||||
    private function addToDB() {
 | 
			
		||||
        /**
 | 
			
		||||
         * creates a new tag
 | 
			
		||||
         * query requirements:
 | 
			
		||||
         * * tagname -- name of the new tag
 | 
			
		||||
         */
 | 
			
		||||
        $this->addActionHandler("createTag", function () {
 | 
			
		||||
            $query = "INSERT INTO tags (tag_name) VALUES ('" . $_POST['tagname'] . "')";
 | 
			
		||||
            // skip tag create if already existing
 | 
			
		||||
            $query = "INSERT IGNORE INTO tags (tag_name) VALUES ('" . $_POST['tagname'] . "')";
 | 
			
		||||
 | 
			
		||||
            if ($this->conn->query($query) === TRUE) {
 | 
			
		||||
                $this->commitMessage('{"result":"success"}');
 | 
			
		||||
@@ -54,7 +39,8 @@ class Tags extends RequestBase {
 | 
			
		||||
            $movieid = $_POST['movieid'];
 | 
			
		||||
            $tagid = $_POST['id'];
 | 
			
		||||
 | 
			
		||||
            $query = "INSERT INTO video_tags(tag_id, video_id) VALUES ('$tagid','$movieid')";
 | 
			
		||||
            // skip tag add if already assigned
 | 
			
		||||
            $query = "INSERT IGNORE INTO video_tags(tag_id, video_id) VALUES ('$tagid','$movieid')";
 | 
			
		||||
 | 
			
		||||
            if ($this->conn->query($query) === TRUE) {
 | 
			
		||||
                $this->commitMessage('{"result":"success"}');
 | 
			
		||||
@@ -63,4 +49,20 @@ class Tags extends RequestBase {
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function getFromDB() {
 | 
			
		||||
        /**
 | 
			
		||||
         * returns all available tags from database
 | 
			
		||||
         */
 | 
			
		||||
        $this->addActionHandler("getAllTags", function () {
 | 
			
		||||
            $query = "SELECT tag_name,tag_id from tags";
 | 
			
		||||
            $result = $this->conn->query($query);
 | 
			
		||||
 | 
			
		||||
            $rows = array();
 | 
			
		||||
            while ($r = mysqli_fetch_assoc($result)) {
 | 
			
		||||
                array_push($rows, $r);
 | 
			
		||||
            }
 | 
			
		||||
            $this->commitMessage(json_encode($rows));
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
<?php
 | 
			
		||||
require_once __DIR__.'/../SSettings.php';
 | 
			
		||||
require_once __DIR__ . '/../SSettings.php';
 | 
			
		||||
require_once 'RequestBase.php';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -29,7 +29,8 @@ class Video extends RequestBase {
 | 
			
		||||
            $query = "SELECT movie_id,movie_name FROM videos ORDER BY create_date DESC, movie_name";
 | 
			
		||||
            if (isset($_POST['tag'])) {
 | 
			
		||||
                $tag = $_POST['tag'];
 | 
			
		||||
                if ($_POST['tag'] != "all") {
 | 
			
		||||
                // if not all tags allowed filter for specific one
 | 
			
		||||
                if (strtolower($_POST['tag']) != "all") {
 | 
			
		||||
                    $query = "SELECT movie_id,movie_name FROM videos 
 | 
			
		||||
                            INNER JOIN video_tags vt on videos.movie_id = vt.video_id
 | 
			
		||||
                            INNER JOIN tags t on vt.tag_id = t.tag_id
 | 
			
		||||
@@ -115,7 +116,7 @@ class Video extends RequestBase {
 | 
			
		||||
            // todo drop video url from db -- maybe one with and one without extension
 | 
			
		||||
            // extension hardcoded here!!!
 | 
			
		||||
            $arr["movie_url"] = str_replace("?", "%3F", $this->videopath . $row["movie_name"] . ".mp4");
 | 
			
		||||
            $arr["likes"] = (int) $row["likes"];
 | 
			
		||||
            $arr["likes"] = (int)$row["likes"];
 | 
			
		||||
            $arr["quality"] = $row["quality"];
 | 
			
		||||
            $arr["length"] = $row["length"];
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user