helloworld, we added some features to make than the werobot website is ready to prod

This commit is contained in:
GZod01 2024-05-18 21:22:51 +02:00
parent a8d427f230
commit 5d47788f18
6 changed files with 35 additions and 4 deletions

4
content/photos.en.md Normal file
View file

@ -0,0 +1,4 @@
---
title: "Photos"
---
{{<photos>}}

4
content/photos.md Normal file
View file

@ -0,0 +1,4 @@
---
title: "Photos"
---
{{<photos>}}

View file

@ -1,4 +1,6 @@
<?php <?php
$medias = [];
if(!isset($_SESSION["medias"])){
$opts = [ $opts = [
"http" => [ "http" => [
"method" => "GET", "method" => "GET",
@ -6,7 +8,7 @@ $opts = [
] ]
]; ];
$context = stream_context_create($opts); $context = stream_context_create($opts);
$u = "https://www.instagram.com/graphql/query/?query_hash=e769aa130647d2354c40ea6a439bfc08&variables=%7B%22id%22%3A%225408546825%22,%20%22first%22%3A%2250%22,%20%22after%22%3A%20%22%22%7D"; $u = "test.json";//"https://www.instagram.com/graphql/query/?query_hash=e769aa130647d2354c40ea6a439bfc08&variables=%7B%22id%22%3A%225408546825%22,%20%22first%22%3A%2250%22,%20%22after%22%3A%20%22%22%7D";
$json = file_get_contents($u, false, $context); $json = file_get_contents($u, false, $context);
$data = json_decode($json, true); $data = json_decode($json, true);
$raw = $data['data']['user']['edge_owner_to_timeline_media']['edges']; $raw = $data['data']['user']['edge_owner_to_timeline_media']['edges'];
@ -28,6 +30,24 @@ foreach ($raw as $rawMedia) {
'taken_at' => $rawMedia['taken_at_timestamp'] 'taken_at' => $rawMedia['taken_at_timestamp']
]; ];
} }
$_SESSION["medias"]=json_encode($medias);
}
$medias = json_decode($_SESSION["medias"],true);
if(isset($_GET["id"])){
$newarr = [];
foreach($medias as $k => $v){
$newarr[$v['id']] = $v;
}
if(!isset($newarr[$_GET["id"]]) and !in_array($_GET["id"],$newarr)){
die(print_r($newarr,true));
}
header('Content-Type: image/png');
die( file_get_contents($newarr[$_GET["id"]]["thumbnail"]));
}
if(isset($_GET["limit"])){
$limit = intval($_GET["limit"]);
$medias = array_slice($medias, 0, $limit);
}
?> ?>
<div <div
class="photos-list-photos"> class="photos-list-photos">
@ -35,7 +55,7 @@ class="photos-list-photos">
foreach($medias as $m){ foreach($medias as $m){
?> ?>
<a <a
style="background-image:url(<?=$m["thumbnail"]?>);" style="background-image:url(/getallphotos?id=<?=$m["id"]?>);"
title="<?=$m["caption"]?>" title="<?=$m["caption"]?>"
class="photos-list-item" class="photos-list-item"
href="<?=$m["link"]?>" href="<?=$m["link"]?>"

View file

@ -8,10 +8,10 @@
</div> </div>
</div> </div>
</div> </div>
<script> <script defer>
function loadimages(){ function loadimages(){
var http = new XMLHttpRequest(); var http = new XMLHttpRequest();
var url = '/getallphotos'; var url = '/getallphotos{{ if .limit }}?limit={{ .limit }}{{ end }}';
http.open('GET', url, false); http.open('GET', url, false);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {//Call a function when the state changes. http.onreadystatechange = function() {//Call a function when the state changes.
@ -23,4 +23,5 @@
} }
http.send(); http.send();
} }
loadimages();
</script> </script>

View file

@ -0,0 +1 @@
{{ partial "photos.html" }}

1
test.json Normal file

File diff suppressed because one or more lines are too long