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;
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;
--- /dev/null
+<?php
+
+use app\core\Application;
+
+class m_1652080803_favoriteVtuber
+{
+ public function up()
+ {
+ $db = Application::$app->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);
+ }
+}
+?>
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();
+ }
}
<?php
+if (isset($_GET["aggiungi"])) {
+ $model->addToFav();
+ exit;
+}
+
if (!isset($_GET["id"])) {
echo "<h1>Live page</h1>";
- $form = app\core\forms\Form::begin("", "post");
- echo $form->field($model, "Link");
- echo '<button type="submit" class="btn btn-primary">Submit</button>';
- app\core\forms\Form::end();
+?>
+
+ <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">Add vtuber to the list</button>
+
+ <!-- Modal -->
+ <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <h5 class="modal-title" id="exampleModalLabel">Add vtuber to the list</h5>
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
+ </div>
+ <div class="modal-body">
+ <?php
+ $form = app\core\forms\Form::begin("", "post");
+ echo $form->field($model, "Link");
+ ?>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
+ <button type="submit" class="btn btn-primary">Submit</button>
+ <?php app\core\forms\Form::end(); ?>
+ </div>
+ </div>
+ </div>
+ </div>
+ <?php
echo "<h2>Currently live</h2>";
echo "<ul>";
foreach ($params[0] as $idol) {
<div>
<nav class=\"navbar bg-dark text-white\">
<div class=\"container-fluid\">
- <h1>" . ucfirst($vtuber[0]["username"]) . "</h1><img class=\"idolLogo\" src=\"" . $vtuber[0]["img"] . "\"/>
+ <h1>" . ucfirst($vtuber[0]["username"]) . "</h1>";
+
+ # TODO: controllo con session se l'utente รจ loggato
+ // echo "<button id='add' class='btn btn-primary' name='add'>Add to favorites</button>";
+ echo "<button id='add'>Add to favorites</button>";
+ # -------------------------------------------------
+
+ echo "<img class=\"idolLogo\" src=\"" . $vtuber[0]["img"] . "\"/>
</div>
</nav>
<div id=\"child\">";
if (str_contains($vtuber[0]["link"], "twitch.tv")) {
- echo "<iframe src=\"https://player.twitch.tv/?channel=".$vtuber[0]["login"]."&parent=localhost\" frameborder=\"0\" allowfullscreen=\"true\" scrolling=\"no\"></iframe>";
+ echo "<iframe src=\"https://player.twitch.tv/?channel=" . $vtuber[0]["login"] . "&parent=localhost\" frameborder=\"0\" allowfullscreen=\"true\" scrolling=\"no\"></iframe>";
} else {
- echo "<iframe src=\"https://www.youtube.com/embed/".$vtuber[1][0]."\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>";
+ echo "<iframe src=\"https://www.youtube.com/embed/" . $vtuber[1][0] . "\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>";
}
+ ?>
+ </div>
+ </div>
+ <script>
+ document.getElementById('add').onclick = function() {
+ let req = new XMLHttpRequest();
- echo "</div></div>";
+ req.open("get", "/live?aggiungi=1&id="+ <?php echo $_GET["id"] ?>, true);
+ req.send();
+ };
+ </script>
+<?php
}
}
}
+?>