From 92d9f3116eaca3d3e981e4c75235db93497813ae Mon Sep 17 00:00:00 2001 From: LeonardoBizzoni Date: Mon, 9 May 2022 10:24:11 +0200 Subject: [PATCH] Can add fav vtuber on click --- dockerfiles/web/nginx.conf | 12 ++-- .../m_1652080803_favoriteVtuber.php | 28 ++++++++ www/models/Vtubers.php | 70 ++++++++++--------- www/pub/js/index.js | 0 www/views/live.php | 62 +++++++++++++--- 5 files changed, 126 insertions(+), 46 deletions(-) create mode 100644 www/Migrations/m_1652080803_favoriteVtuber.php create mode 100644 www/pub/js/index.js diff --git a/dockerfiles/web/nginx.conf b/dockerfiles/web/nginx.conf index 4723ea5..9a37f12 100644 --- a/dockerfiles/web/nginx.conf +++ b/dockerfiles/web/nginx.conf @@ -9,8 +9,8 @@ events { http { -fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MY_CACHE:100m inactive=60m; -fastcgi_cache_key "$scheme$request_method$host$request_uri"; +# fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MY_CACHE:100m inactive=60m; +# fastcgi_cache_key "$scheme$request_method$host$request_uri"; server { listen 80 default_server; @@ -26,10 +26,10 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; location ~ \.php$ { -fastcgi_ignore_headers Expires Cache-Control; -fastcgi_cache MY_CACHE; - fastcgi_cache_valid 200 60m; - add_header X-Cache $upstream_cache_status; +# fastcgi_ignore_headers Expires Cache-Control; +# fastcgi_cache MY_CACHE; +# fastcgi_cache_valid 200 60m; +# add_header X-Cache $upstream_cache_status; fastcgi_read_timeout 300; fastcgi_pass app:9000; diff --git a/www/Migrations/m_1652080803_favoriteVtuber.php b/www/Migrations/m_1652080803_favoriteVtuber.php new file mode 100644 index 0000000..7f80447 --- /dev/null +++ b/www/Migrations/m_1652080803_favoriteVtuber.php @@ -0,0 +1,28 @@ +db; + $sql = "CREATE TABLE favoriteVtuber ( + id INT AUTO_INCREMENT PRIMARY KEY, + _vtuberID INT NOT NULL, + _userID INT NOT NULL, + + FOREIGN KEY(_vtuberID) references `vtubers`(`id`), + FOREIGN KEY(_userID) references `users`(`id`) + ) ENGINE=INNODB;"; + $db->pdo->exec($sql); + } + + public function down() + { + $db = Application::$app->db; + $sql = "DROP TABLE favoriteVtuber;"; + $db->pdo->exec($sql); + } +} +?> diff --git a/www/models/Vtubers.php b/www/models/Vtubers.php index cf1f680..95f2d86 100644 --- a/www/models/Vtubers.php +++ b/www/models/Vtubers.php @@ -93,50 +93,56 @@ class Vtubers extends DbModel public function isLive(string $login, string $link) { - if (str_contains($link, "twitch.tv")) { - $clientID = Application::$app->config["twitch"]["clientid"] ?? ""; - $token = Application::$app->config["twitch"]["token"] ?? ""; + // if (str_contains($link, "twitch.tv")) { + // $clientID = Application::$app->config["twitch"]["clientid"] ?? ""; + // $token = Application::$app->config["twitch"]["token"] ?? ""; - $url = "https://api.twitch.tv/helix/streams?user_login=$login"; + // $url = "https://api.twitch.tv/helix/streams?user_login=$login"; - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_HTTPHEADER, array("Client-ID: $clientID", "Authorization: Bearer $token")); + // $ch = curl_init($url); + // curl_setopt($ch, CURLOPT_URL, $url); + // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + // curl_setopt($ch, CURLOPT_HTTPHEADER, array("Client-ID: $clientID", "Authorization: Bearer $token")); - $result = get_object_vars(json_decode(curl_exec($ch))); - curl_close($ch); + // $result = get_object_vars(json_decode(curl_exec($ch))); + // curl_close($ch); - return count($result["data"]) ? $result["data"] : []; - } + // return count($result["data"]) ? $result["data"] : []; + // } - if (str_contains($link, "youtube.com")) { - $url = "https://www.youtube.com/channel/$login/live"; + // if (str_contains($link, "youtube.com")) { + // $url = "https://www.youtube.com/channel/$login/live"; - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + // $ch = curl_init($url); + // curl_setopt($ch, CURLOPT_URL, $url); + // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - $result = curl_exec($ch); - curl_close($ch); + // $result = curl_exec($ch); + // curl_close($ch); - $doc = new DOMDocument(); - libxml_use_internal_errors(true); - $doc->loadHTML($result); + // $doc = new DOMDocument(); + // libxml_use_internal_errors(true); + // $doc->loadHTML($result); - $result = $doc->getElementsByTagName("link"); - $length = $result->length; + // $result = $doc->getElementsByTagName("link"); + // $length = $result->length; - for ($i = 0; $i < $length; $i++) { - $tag = $result->item($i)->getAttribute("href"); - if (str_contains($tag, "https://www.youtube.com/watch?v=")) { - return [str_replace("https://www.youtube.com/watch?v=", "", $tag)]; - } - } + // for ($i = 0; $i < $length; $i++) { + // $tag = $result->item($i)->getAttribute("href"); + // if (str_contains($tag, "https://www.youtube.com/watch?v=")) { + // return [str_replace("https://www.youtube.com/watch?v=", "", $tag)]; + // } + // } - unset($doc); - } + // unset($doc); + // } return []; } + + public function addToFav() + { + $stmt = parent::prepare("INSERT INTO favoriteVtuber(_vtuberID, _userID) values (".$_GET["id"].", ".Application::$app->user->id.")"); + $stmt->execute(); + } } diff --git a/www/pub/js/index.js b/www/pub/js/index.js new file mode 100644 index 0000000..e69de29 diff --git a/www/views/live.php b/www/views/live.php index 8a13a2c..09a4e54 100644 --- a/www/views/live.php +++ b/www/views/live.php @@ -1,12 +1,40 @@ addToFav(); + exit; +} + if (!isset($_GET["id"])) { echo "

Live page

"; - $form = app\core\forms\Form::begin("", "post"); - echo $form->field($model, "Link"); - echo ''; - app\core\forms\Form::end(); +?> + + + + + + Currently live"; echo "