60 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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";
 | 
						|
			$user_settings['instance'] = "mastodon.social";
 | 
						|
			$user_settings['text'] = "off";
 | 
						|
			$user_settings['reblog'] = "off";	
 | 
						|
			$user_settings['videoloop'] = "off";			
 | 
						|
			$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,'/');
 | 
						|
	}
 | 
						|
	
 | 
						|
	/* 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"))){
 | 
						|
				$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 = "";
 | 
						|
?>
 |