jimsite/site/assets/php/query_handler.php

24 lines
1.6 KiB
PHP

<?php
//__DIR__ points to scripts folder.
$pages = json_decode(file_get_contents(__DIR__ ."/../data/pages.json"));
//Load dictionary of site pages from pages.json file.
$query_page = (isset($_REQUEST['page']) && !empty($_REQUEST['page'])) ? $_GET['page'] : "home";
//Get value of "page" query key; default is "home".
$page = (isset($pages->$query_page)) ? $pages->$query_page : $pages->{404};
//If the query value ($query_page) is not in the dictionary ($pages), then load the 404 page instead.
echo "<var id='query-page'>".$query_page."</var>";
//Store the page id in a var tag in case we need to access it with JavaScript.
$list = (isset($_REQUEST['list']) && !empty($_REQUEST['list'])) ? $_GET['list'] : "master";
//Get the value of "list" from the query key; default is "master" (the master list).
echo "<var id='query-list'>".$list."</var>";
//Store the list id in a var tag so that we can easily figure out what list to generate with list.js.
if($query_page=="lists"){
$lists_json = json_decode(file_get_contents(__DIR__ ."/../data/lists.json"));
echo "<script id='lists-json'>var lists=".json_encode($lists_json)."</script>";
//Copy the data from lists.json and paste it into a script tag, saving it as a variable called `list` to be accessed by later JavaScript code (i.e. lists.js).
//I would have stored it in a var tag, but there was a weird bug with some of the <u> tags leaking out and making my title underlined, and this seemed to avoid that (and it's probably more efficient too).
}
?>