fedi-tumblr/include/init.php

67 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2020-04-01 00:46:27 +00:00
<?php
/* this file initializes some stuff when the user loads a page */
/* fetch the user token from the cookie */
$token = (isset($_COOKIE['token']) ? $_COOKIE['token'] : false);
/* fetch the FE user setings from the cookie or set them if the cookie does not exists */
if (isset($_COOKIE['user_settings'])){
$user_settings = json_decode(base64_decode($_COOKIE['user_settings']),true);
} else {
$user_settings['replies'] = "off";
$user_settings['attach'] = "on";
2021-09-08 00:07:04 +00:00
$user_settings['instance'] = "fedi.absturztau.be";
2020-04-01 00:46:27 +00:00
$user_settings['text'] = "off";
$user_settings['reblog'] = "off";
$user_settings['videoloop'] = "off";
$user_settings['theme'] = "default";
$user_settings['nsfw'] = array();
if (isset($_COOKIE['token'])) {
$user_settings['explicit'] = "blur";
} else {
$user_settings['explicit'] = "hide";
}
setrawcookie("user_settings",base64_encode(json_encode($user_settings)),time()+60*60*24*30,'/');
}
if (isset($_COOKIE['theme'])){
$theme = json_decode(base64_decode($_COOKIE['theme']),true);
} else {
$theme = array();
}
/* a lazy way to check if we are logded in, to fix */
$logedin = (isset($_COOKIE['token']) ? true : false);
/* by default the timeline to fetch will be the federated one
but we will infer the timeline to load from the presence of
some common url variables.
*/
$tl['mode'] = "federated";
if(isset($_GET['mode'])){
$tl['mode'] = $_GET['mode'];
} else {
foreach ($_GET as $key => $value){
if(in_array($key,array("user","thread","local","tag","list","federated","search"))){
2020-04-01 00:46:27 +00:00
$tl['mode'] = $key;
$tl[$key] = $value;
}
}
}
/* same as above but these are mostly used for AJAX requests */
$tl['next'] = (isset($_GET['next']) ? htmlentities($_GET['next']) : false);
$tl['since'] = (isset($_GET['since']) ? htmlentities($_GET['since']) : false);
$tl['sincen'] = (isset($_GET['sincen']) ? htmlentities($_GET['sincen']) : false);
$srv = $user_settings['instance'];
/* no longer used */
$nocookies = (isset($_COOKIE['user_settings']) ? false : true);
/* these variables will hold the data of the page that will be generated */
$replies = "";
$notes = "";
?>