Make view.html a template for router.php to use

Also add public_name to Dictionary->getPublicDictionaryDetails()
This commit is contained in:
Robbie Antenesse 2019-05-27 22:52:50 -06:00
parent d1b123317f
commit 1bc75f2256
3 changed files with 32 additions and 2 deletions

View File

@ -91,7 +91,7 @@ VALUES ($new_id, ?, ?, ?, ?)";
public function getPublicDictionaryDetails ($dictionary_hash) {
$dictionary = $this->token->unhash($dictionary_hash);
if ($dictionary !== false) {
$query = "SELECT * FROM dictionaries JOIN dictionary_linguistics ON dictionary = id WHERE id=? AND is_public=1";
$query = "SELECT d.*, dl.*, u.public_name FROM dictionaries d JOIN dictionary_linguistics dl ON dl.dictionary = d.id JOIN users u ON u.id = d.user WHERE d.id=? AND d.is_public=1";
$result = $this->db->query($query, array($dictionary))->fetch();
if ($result) {
// Default json values in case they are somehow not created by front end first
@ -102,6 +102,7 @@ VALUES ($new_id, ?, ?, ?, ?)";
'name' => $result['name'],
'specification' => $result['specification'],
'description' => $result['description'],
'createdBy' => $result['public_name'],
'partsOfSpeech' => explode(',', $partsOfSpeech),
'details' => array(
'phonology' => array(

23
src/php/api/router.php Normal file
View File

@ -0,0 +1,23 @@
<?php
$view = isset($_GET['view']) ? $_GET['view'] : false;
$dict = isset($_GET['dict']) ? $_GET['dict'] : false;
switch ($view) {
case 'publicview': {
$html = file_get_contents('../view.html');
if ($dict !== false) {
require_once('./Dictionary.php');
$dictionary = new Dictionary();
$dictionary_data = $dictionary->getPublicDictionaryDetails($dict);
if ($dictionary_data !== false) {
$dictionary_data['words'] = $dictionary->getPublicDictionaryWords($dict);
$html = str_replace('{{dict}}', $dict, $html);
$html = str_replace('{{dict_name}}', $dictionary_data['name'] . ' ' . $dictionary_data['specification'], $html);
$html = str_replace('{{public_name}}', $dictionary_data['createdBy'], $html);
$html = str_replace('{{dict_json}}', json_encode($dictionary_data), $html);
}
echo $html;
}
break;
}
}

View File

@ -4,7 +4,13 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lexiconga</title>
<title>{{dict_name}} | Lexiconga</title>
<meta property="og:url" content="http://lexicon.ga/{{dict}}" />
<meta property="og:type" content="article" />
<meta property="og:title" content="{{dict_name}}" />
<meta property="og:description" content="A Lexiconga dictionary by {{public_name}}" />
<!--meta property="og:image" content="http://lexicon.ga/images/logo.svg" /-->
<script>window.currentDictionary = JSON.parse('{{dict_json}}');</script>
<script src="src/js/view/index.js"></script>
</head>
<body>