Compare commits

...

6 Commits

Author SHA1 Message Date
Robbie Antenesse 4ad86e31fa Fix updateCurrentChangeDictionaryOption() selector 2019-05-28 00:17:23 -06:00
Robbie Antenesse 6154510af6 Load and render public dictionary correctly 2019-05-28 00:12:17 -06:00
Robbie Antenesse 373414d5c0 Fix dictionary not returning alphabeticalOrder;
Needs fix to include in db!
2019-05-28 00:11:38 -06:00
Robbie Antenesse e806f53076 Add original .htaccess file from Lexiconga 2019-05-27 23:51:28 -06:00
Robbie Antenesse bed665f448 Remove hashing dictionary id
Randomizing id should be enough security, plus it makes .htaccess easier
2019-05-27 23:50:26 -06:00
Robbie Antenesse 1bc75f2256 Make view.html a template for router.php to use
Also add public_name to Dictionary->getPublicDictionaryDetails()
2019-05-27 22:52:50 -06:00
10 changed files with 105 additions and 28 deletions

View File

@ -9,8 +9,8 @@
"scripts": {
"start": "concurrently \"npm run watch-js\" \"npm run watch-php\"",
"watch-js": "parcel watch index.html view.html --public-url ./",
"watch-php": "cpx \"src/php/**/*\" dist -v -w",
"bundle": "parcel build index.html && cpx src/php/**/* dist",
"watch-php": "cpx \"src/php/**/{*,.*}\" dist -v -w",
"bundle": "parcel build index.html && cpx \"src/php/**/{*,.*}\" dist",
"serve-frontend-only": "parcel index.html",
"clear": "npm run clear-dist && npm run clear-cache",
"clear-dist": "rimraf dist/*",

View File

@ -35,7 +35,7 @@ export function changeDictionary(dictionary) {
export function updateCurrentChangeDictionaryOption() {
const label = window.currentDictionary.name + ' ' + window.currentDictionary.specification;
document.getElementById('accountSettingsChangeDictionary')
.querySelector(`option[value=${window.currentDictionary.externalID}]`).innerText = label;
.querySelector(`option[value="${window.currentDictionary.externalID}"]`).innerText = label;
}
export function deleteDictionary(deletedId) {

View File

@ -0,0 +1,36 @@
import { renderDescription, renderDetails, renderStats } from './render';
export function showSection(sectionName) {
switch (sectionName) {
case 'description': showDescription(); break;
case 'details': showDetails(); break;
case 'stats': showStats(); break;
}
}
export function hideDetailsPanel() {
document.getElementById('detailsPanel').style.display = 'none';
}
export function getIsDetailsPanelDisplayed() {
return document.getElementById('detailsPanel').style.display !== 'none';
}
function showDescription() {
const detailsPanel = document.getElementById('detailsPanel');
detailsPanel.style.display = 'block';
renderDescription();
}
function showDetails() {
const detailsPanel = document.getElementById('detailsPanel');
detailsPanel.style.display = 'block';
renderDetails();
}
function showStats() {
const detailsPanel = document.getElementById('detailsPanel');
detailsPanel.style.display = 'block';
renderStats();
}

View File

@ -1,5 +1,6 @@
import '../../main.scss';
import { getDictionary } from './dictionaryManagement';
import { renderAll } from './render';
import setupListeners from './setupListeners';
// import setupListeners, { setupSearchFilters } from './js/setupListeners';
// import { renderAll } from './js/render';
@ -8,8 +9,8 @@ import { getDictionary } from './dictionaryManagement';
// import { loadSettings } from './js/settings';
function initialize() {
getDictionary();
// setupSearchFilters();
renderAll();
setupListeners();
}
window.onload = (function (oldLoad) {

View File

@ -1,4 +1,4 @@
import {showSection, hideDetailsPanel} from '../displayToggles';
import {showSection, hideDetailsPanel} from './displayToggles';
import { showSearchModal, clearSearchText, checkAllPartsOfSpeechFilters, uncheckAllPartsOfSpeechFilters } from '../search';
import { renderWords, renderInfoModal } from './render';
@ -23,9 +23,6 @@ function setupDetailsTabs() {
}
});
});
setupEditFormTabs();
setupEditFormInteractions();
setupEditFormButtons();
}
function setupSearchBar() {
@ -82,17 +79,17 @@ export function setupSearchFilters() {
export function setupInfoButtons() {
document.getElementById('helpInfoButton').addEventListener('click', () => {
import('../markdown/help.md').then(html => {
import('../../markdown/help.md').then(html => {
renderInfoModal(html);
});
});
document.getElementById('termsInfoButton').addEventListener('click', () => {
import('../markdown/terms.md').then(html => {
import('../../markdown/terms.md').then(html => {
renderInfoModal(html);
});
});
document.getElementById('privacyInfoButton').addEventListener('click', () => {
import('../markdown/privacy.md').then(html => {
import('../../markdown/privacy.md').then(html => {
renderInfoModal(html);
});
});

13
src/php/.htaccess Normal file
View File

@ -0,0 +1,13 @@
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^view/([0-9]+)/([0-9]+)/?$ api/router.php?view=publicview&dict=$1&word=$2 [NC,L] # Handle word ids.
RewriteRule ^([0-9]+)/([0-9]+)/?$ api/router.php?view=publicview&dict=$1&word=$2 [NC,L] # Handle word ids.
RewriteRule ^view/([0-9]+)/?$ api/router.php?view=publicview&dict=$1 [NC,L] # Handle dictionary ids.
RewriteRule ^([0-9]+)/?$ api/router.php?view=publicview&dict=$1 [NC,L] # Handle dictionary ids.
#RewriteRule ^issues/?$ https://github.com/Alamantus/Lexiconga/issues [R=301,L] # Shorten issues url.
#RewriteRule ^updates/?$ https://github.com/Alamantus/Lexiconga/releases [R=301,L] # Shorten updates url.

View File

@ -80,7 +80,7 @@ VALUES ($new_id, ?, ?, ?, ?)";
if ($results) {
return array_map(function($result) {
return array(
'id' => $this->token->hash($result['id']),
'id' => $result['id'],
'name' => $result['name'] . ' ' . $result['specification'],
);
}, $results);
@ -88,21 +88,22 @@ VALUES ($new_id, ?, ?, ?, ?)";
return array();
}
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";
public function getPublicDictionaryDetails ($dictionary) {
if (is_numeric($dictionary)) {
$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
$partsOfSpeech = $result['parts_of_speech'] !== '' ? $result['parts_of_speech'] : $this->defaults['partsOfSpeech'];
return array(
'externalID' => $this->token->hash($result['id']),
'externalID' => $result['id'],
'name' => $result['name'],
'specification' => $result['specification'],
'description' => $result['description'],
'createdBy' => $result['public_name'],
'partsOfSpeech' => explode(',', $partsOfSpeech),
'alphabeticalOrder' => array(),
'details' => array(
'phonology' => array(
'consonants' => $result['consonants'] !== '' ? explode(' ', $result['consonants']) : array(),
@ -137,9 +138,8 @@ VALUES ($new_id, ?, ?, ?, ?)";
return false;
}
public function getPublicDictionaryWords ($dictionary_hash) {
$dictionary = $this->token->unhash($dictionary_hash);
if ($dictionary !== false) {
public function getPublicDictionaryWords ($dictionary) {
if (is_numeric($dictionary)) {
$query = "SELECT words.* FROM words JOIN dictionaries ON id = dictionary WHERE dictionary=? AND is_public=1";
$results = $this->db->query($query, array($dictionary))->fetchAll();
if ($results) {
@ -168,11 +168,12 @@ VALUES ($new_id, ?, ?, ?, ?)";
$partsOfSpeech = $result['parts_of_speech'] !== '' ? $result['parts_of_speech'] : $this->defaults['partsOfSpeech'];
return array(
'externalID' => $this->token->hash($result['id']),
'externalID' => $result['id'],
'name' => $result['name'],
'specification' => $result['specification'],
'description' => $result['description'],
'partsOfSpeech' => explode(',', $partsOfSpeech),
'alphabeticalOrder' => array(),
'details' => array(
'phonology' => array(
'consonants' => $result['consonants'] !== '' ? explode(' ', $result['consonants']) : array(),

View File

@ -146,12 +146,11 @@ VALUES (?, ?, ?, ?, ?)';
);
}
public function changeCurrentDictionary ($token, $dictionary_hash) {
public function changeCurrentDictionary ($token, $dictionary_id) {
$user_data = $this->token->decode($token);
if ($user_data !== false) {
$id = $user_data->id;
$dictionary_id = $this->token->unhash($dictionary_hash);
if ($dictionary_id !== false) {
if (is_numeric($dictionary_id)) {
$changed_dictionary = $this->dictionary->changeCurrent($id, $dictionary_id);
if ($changed_dictionary !== false) {
$new_token = $this->generateUserToken($id, $changed_dictionary);
@ -196,7 +195,7 @@ VALUES (?, ?, ?, ?, ?)';
$details_updated = $this->dictionary->setDetails($user, $dictionary, $dictionary_data['details']);
$words_updated = $this->dictionary->setWords($user, $dictionary, $dictionary_data['words']);
if ($details_updated === true && $words_updated === true) {
return $this->token->hash($dictionary);
return $dictionary;
}
return array(
'error' => ($details_updated !== true ? $details_updated . ' ' : '') . ($words_updated !== true ? $words_updated : ''),

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

@ -0,0 +1,24 @@
<?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);
$dictionary_json = json_encode($dictionary_data);
$html = str_replace('{{dict_json}}', addslashes($dictionary_json), $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>