Started working on making a single word display page, but there's still a lot of work that needs to be done (maybe just load full dictionary with 1 word to simplify?).

Made references to files look in root instead of local directory.
This commit is contained in:
Robbie Antenesse 2016-06-19 22:58:27 -06:00
parent 3512d55d97
commit fca5fb2704
3 changed files with 181 additions and 114 deletions

163
index.php
View File

@ -8,12 +8,13 @@ $dictionary_to_load = (isset($_GET['dict'])) ? intval($_GET['dict']) : 0;
$the_public_dictionary = '"That dictionary doesn\'t exist."'; $the_public_dictionary = '"That dictionary doesn\'t exist."';
$dictionary_name = 'ERROR'; $dictionary_name = 'ERROR';
$dictionary_creator = 'nobody'; $dictionary_creator = 'nobody';
$is_viewing = $dictionary_to_load > 0;
$word_to_load = (isset($_GET['word'])) ? intval($_GET['word']) : 0; $word_to_load = (isset($_GET['word'])) ? intval($_GET['word']) : 0;
$the_public_word = '"That word doesn\'t exist."'; $the_public_word = '"That word doesn\'t exist."';
$word_name = 'ERROR'; $word_name = 'ERROR';
$display_mode = ($dictionary_to_load > 0) ? (($word_to_load > 0) ? "word" : "view") : "build";
$announcement = get_include_contents(SITE_LOCATION . '/announcement.php'); $announcement = get_include_contents(SITE_LOCATION . '/announcement.php');
$notificationMessage = ""; $notificationMessage = "";
@ -27,35 +28,66 @@ if ($current_user > 0 || !isset($_SESSION['loginfailures']) || (isset($_SESSION[
require_once(SITE_LOCATION . '/php/notificationconditiontree.php'); require_once(SITE_LOCATION . '/php/notificationconditiontree.php');
if ($is_viewing) { if ($display_mode != "build") {
$query = "SELECT `d`.`id`, `d`.`name`, `d`.`description`, `u`.`public_name`, `d`.`words`, `d`.`parts_of_speech`, `d`.`is_complete` ";
$query .= "FROM `dictionaries` AS `d` LEFT JOIN `users` AS `u` ON `d`.`user`=`u`.`id` WHERE `d`.`is_public`=1 AND `d`.`id`=" . $dictionary_to_load . ";";
$dbconnection = new PDO('mysql:host=' . DATABASE_SERVERNAME . ';dbname=' . DATABASE_NAME . ';charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD); $dbconnection = new PDO('mysql:host=' . DATABASE_SERVERNAME . ';dbname=' . DATABASE_NAME . ';charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD);
$dbconnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbconnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbconnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $dbconnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$dbconnection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $dbconnection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
try {
$queryResults = $dbconnection->prepare($query); if ($display_mode == "word") {
$queryResults->execute(); // only query for specific word.
if ($queryResults) { $query = "SELECT `d`.`name` AS `dname`, `u`.`public_name`, `w`.`word_id`, `w`.`name`, `w`.`pronunciation`, `w`.`part_of_speech`, `w`.`simple_definition`, `w`.`long_definition` ";
if (num_rows($queryResults) === 1) { $query .= "FROM `words` AS `w` LEFT JOIN `dictionaries` AS `d` ON `w`.`dictionary`=`d`.`id` ";
while ($dict = fetch($queryResults)) { $query .= "LEFT JOIN `users` AS `u` ON `d`.`user`=`u`.`id` ";
$dictionary_name = $dict['name']; $query .= "WHERE `d`.`is_public`=1 AND `w`.`dictionary`=" . $dictionary_to_load . " AND `w`.`word_id`=" . $dictionary_to_load . ";";
$dictionary_creator = $dict['public_name'];
$the_public_dictionary = '{"name":"' . $dict['name'] . '",'; try {
$the_public_dictionary .= '"description":"' . $dict['description'] . '",'; $queryResults = $dbconnection->prepare($query);
$the_public_dictionary .= '"createdBy":"' . $dict['public_name'] . '",'; $queryResults->execute();
$the_public_dictionary .= '"words":' . $dict['words'] . ','; if ($queryResults) {
$the_public_dictionary .= '"settings":{'; if (num_rows($queryResults) === 1) {
$the_public_dictionary .= '"partsOfSpeech":"' . $dict['parts_of_speech'] . '",'; while ($word = fetch($queryResults)) {
$the_public_dictionary .= '"isComplete":' . (($dict['is_complete'] == 1) ? 'true' : 'false') . '},'; $dictionary_name = $word['dname'];
$the_public_dictionary .= '}'; $dictionary_creator = $word['public_name'];
$the_public_word = '{"name":"' . $word['name'] . '",';
$the_public_word .= '"pronunciation":"' . $word['pronunciation'] . '",';
$the_public_word .= '"partOfSpeech":"' . $word['part_of_speech'] . '",';
$the_public_word .= '"simpleDefinition":"' . $word['simple_definition'] . '",';
$the_public_word .= '"longDefinition":"' . $word['long_definition'] . '",';
$the_public_word .= '"wordId":"' . $word['word_id'] . '"';
$the_public_word .= '}';
}
} }
} }
} }
catch (PDOException $ex) {}
} else {
// Otherwise, grab everything.
$query = "SELECT `d`.`id`, `d`.`name`, `d`.`description`, `u`.`public_name`, `d`.`parts_of_speech`, `d`.`is_complete` ";
$query .= "FROM `dictionaries` AS `d` LEFT JOIN `users` AS `u` ON `d`.`user`=`u`.`id` WHERE `d`.`is_public`=1 AND `d`.`id`=" . $dictionary_to_load . ";";
try {
$queryResults = $dbconnection->prepare($query);
$queryResults->execute();
if ($queryResults) {
if (num_rows($queryResults) === 1) {
while ($dict = fetch($queryResults)) {
$dictionary_name = $dict['name'];
$dictionary_creator = $dict['public_name'];
$the_public_dictionary = '{"name":"' . $dict['name'] . '",';
$the_public_dictionary .= '"description":"' . $dict['description'] . '",';
$the_public_dictionary .= '"createdBy":"' . $dict['public_name'] . '",';
$the_public_dictionary .= '"words":' . Get_Dictionary_Words($dictionary_to_load) . ',';
$the_public_dictionary .= '"settings":{';
$the_public_dictionary .= '"partsOfSpeech":"' . $dict['parts_of_speech'] . '",';
$the_public_dictionary .= '"isComplete":' . (($dict['is_complete'] == 1) ? 'true' : 'false') . '},';
$the_public_dictionary .= '}';
}
}
}
}
catch (PDOException $ex) {}
} }
catch (PDOException $ex) {}
} }
?> ?>
@ -65,20 +97,29 @@ if ($is_viewing) {
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<?php if ($is_viewing) { ?> <?php if ($display_mode != "build") { ?>
<title><?php echo $dictionary_name; ?> Dictionary on Lexiconga</title> <title><?php echo (($display_mode == "word") ? ($word_name . " | ") : "") . $dictionary_name; ?> Dictionary on Lexiconga</title>
<meta property="og:url" content="http://lexicon.ga/view/?dict=<?php echo $dictionary_to_load; ?>" /> <meta property="og:url" content="http://lexicon.ga/<?php echo $dictionary_to_load . (($display_mode == "word") ? ("/" . $word_to_load) : ""); ?>" />
<meta property="og:type" content="article" /> <meta property="og:type" content="article" />
<meta property="og:title" content="<?php echo $dictionary_name; ?> Dictionary" /> <meta property="og:title" content="<?php echo (($display_mode == "word") ? ("\"" . $word_name . "\" in the ") : "") . $dictionary_name; ?> Dictionary" />
<meta property="og:description" content="A Lexiconga dictionary by <?php echo $dictionary_creator; ?>" /> <meta property="og:description" content="A Lexiconga dictionary by <?php echo $dictionary_creator; ?>" />
<meta property="og:image" content="http://lexicon.ga/images/logo.svg" /> <meta property="og:image" content="http://lexicon.ga/images/logo.svg" />
<script>var publicDictionary = <?php echo $the_public_dictionary; ?></script> <?php if (isset($the_public_word)) { ?>
<?php } else { ?> <script>var publicWord = <?php echo $the_public_word; ?></script>
<?php } else { ?>
<script>var publicDictionary = <?php echo $the_public_dictionary; ?></script>
<?php }
} else { ?>
<title>Lexiconga Dictionary Builder</title> <title>Lexiconga Dictionary Builder</title>
<meta property="og:url" content="http://lexicon.ga" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Lexiconga Dictionary Builder" />
<meta property="og:description" content="Build lexicons for contructed languages or anything that you can think of!" />
<meta property="og:image" content="http://lexicon.ga/images/logo.svg" />
<?php } ?> <?php } ?>
<link href="css/styles.css" rel="stylesheet" /> <link href="/css/styles.css" rel="stylesheet" />
<link href="css/lexiconga.css" rel="stylesheet" /> <link href="/css/lexiconga.css" rel="stylesheet" />
</head> </head>
<body> <body>
<header> <header>
@ -99,7 +140,7 @@ if ($is_viewing) {
</div> </div>
</header> </header>
<contents> <contents>
<?php if (!$is_viewing) { ?> <?php if ($display_mode == "build") { ?>
<div id="announcementArea" style="display:<?php echo (($announcement) ? "block" : "none"); ?>;margin-bottom:10px;"> <div id="announcementArea" style="display:<?php echo (($announcement) ? "block" : "none"); ?>;margin-bottom:10px;">
<span id="announcementCloseButton" class="clickable" onclick="document.getElementById('announcementArea').style.display='none';">Close</span> <span id="announcementCloseButton" class="clickable" onclick="document.getElementById('announcementArea').style.display='none';">Close</span>
<div id="announcement"><?php echo $announcement; ?></div> <div id="announcement"><?php echo $announcement; ?></div>
@ -142,35 +183,36 @@ if ($is_viewing) {
<?php } ?> <?php } ?>
<div id="dictionaryContainer"> <div id="dictionaryContainer">
<?php if (!$is_viewing) { ?> <?php if ($display_mode == "build") { ?>
<span id="settingsButton" class="clickable" onclick="ShowSettings()">Settings</span> <span id="settingsButton" class="clickable" onclick="ShowSettings()">Settings</span>
<?php } ?> <?php } ?>
<h1 id="dictionaryName"></h1> <h1 id="dictionaryName"></h1>
<?php if ($is_viewing) { ?> <?php if ($display_mode == "view") { ?>
<h4 id="dictionaryBy"></h4> <h4 id="dictionaryBy"></h4>
<div id="incompleteNotice"></div> <div id="incompleteNotice"></div>
<?php } ?> <?php } ?>
<span id="descriptionToggle" class="clickable" onclick="ToggleDescription();"><?php if ($is_viewing) { ?>Hide<?php } else { ?>Show<?php } ?> Description</span> <span id="descriptionToggle" class="clickable" onclick="ToggleDescription();"><?php if ($display_mode == "view") { ?>Hide<?php } else { ?>Show<?php } ?> Description</span>
<div id="dictionaryDescription" style="display:<?php if ($is_viewing) { ?>block<?php } else { ?>none<?php } ?>;"></div> <div id="dictionaryDescription" style="display:<?php if ($display_mode == "view") { ?>block<?php } else { ?>none<?php } ?>;"></div>
<span id="searchFilterToggle" class="clickable" onclick="ToggleSearchFilter();"><?php if ($is_viewing) { ?>Hide <?php } ?>Search/Filter Options</span> <?php if ($display_mode != "word") { ?>
<div id="searchFilterArea" style="display:<?php if ($is_viewing) { ?>block<?php } else { ?>none<?php } ?>;"> <span id="searchFilterToggle" class="clickable" onclick="ToggleSearchFilter();"><?php if ($display_mode == "view") { ?>Hide <?php } ?>Search/Filter Options</span>
<div id="searchFilterArea" style="display:<?php if ($display_mode == "view") { ?>block<?php } else { ?>none<?php } ?>;">
<div id="searchArea" style="display:block;"> <div id="searchArea" style="display:block;">
<label style="margin-top:10px;"> <label style="margin-top:10px;">
<span>Search</span> <span>Search</span>
<div style="display:block;"> <div style="display:block;">
<input type="text" id="searchBox" onclick="this.select();" onchange="<?php Show_Dictionary_Function($is_viewing) ?>" style="display:inline;" />&nbsp; <input type="text" id="searchBox" onclick="this.select();" onchange="<?php Show_Dictionary_Function($display_mode == "view") ?>" style="display:inline;" />&nbsp;
<span class="clickable inline-button" onclick="document.getElementById('searchBox').value='';<?php Show_Dictionary_Function($is_viewing) ?>;">Clear Search</span> <span class="clickable inline-button" onclick="document.getElementById('searchBox').value='';<?php Show_Dictionary_Function($display_mode == "view") ?>;">Clear Search</span>
</div> </div>
<div id="searchOptions"> <div id="searchOptions">
<label class="searchOption">Word <input type="checkbox" id="searchOptionWord" checked="checked" onchange="<?php Show_Dictionary_Function($is_viewing) ?>" /></label> <label class="searchOption">Word <input type="checkbox" id="searchOptionWord" checked="checked" onchange="<?php Show_Dictionary_Function($display_mode == "view") ?>" /></label>
<label class="searchOption">Equivalent <input type="checkbox" id="searchOptionSimple" checked="checked" onchange="<?php Show_Dictionary_Function($is_viewing) ?>" /></label> <label class="searchOption">Equivalent <input type="checkbox" id="searchOptionSimple" checked="checked" onchange="<?php Show_Dictionary_Function($display_mode == "view") ?>" /></label>
<label class="searchOption">Explanation <input type="checkbox" id="searchOptionLong" checked="checked" onchange="<?php Show_Dictionary_Function($is_viewing) ?>" /></label> <label class="searchOption">Explanation <input type="checkbox" id="searchOptionLong" checked="checked" onchange="<?php Show_Dictionary_Function($display_mode == "view") ?>" /></label>
<br /> <br />
<label class="searchOption">Search Case-Sensitive <input type="checkbox" id="searchCaseSensitive" onchange="<?php Show_Dictionary_Function($is_viewing) ?>" /></label> <label class="searchOption">Search Case-Sensitive <input type="checkbox" id="searchCaseSensitive" onchange="<?php Show_Dictionary_Function($display_mode == "view") ?>" /></label>
<label class="searchOption" title="Note: Matching diacritics will appear but may not highlight.">Ignore Diacritics/Accents <input type="checkbox" id="searchIgnoreDiacritics" onchange="<?php Show_Dictionary_Function($is_viewing) ?>" /></label> <label class="searchOption" title="Note: Matching diacritics will appear but may not highlight.">Ignore Diacritics/Accents <input type="checkbox" id="searchIgnoreDiacritics" onchange="<?php Show_Dictionary_Function($display_mode == "view") ?>" /></label>
</div> </div>
</label> </label>
</div> </div>
@ -178,25 +220,28 @@ if ($is_viewing) {
<label style="display:block;margin-bottom:0;"><b>Filter Words</b></label> <label style="display:block;margin-bottom:0;"><b>Filter Words</b></label>
<div id="filterOptions" style="display:block"></div> <div id="filterOptions" style="display:block"></div>
<div style="display:block;"> <div style="display:block;">
<span class="clickable inline-button" onclick="ToggleAllFilters(true);<?php Show_Dictionary_Function($is_viewing) ?>;"> <span class="clickable inline-button" onclick="ToggleAllFilters(true);<?php Show_Dictionary_Function($display_mode == "view") ?>;">
Check All Check All
</span> </span>
&nbsp; &nbsp;
<span class="clickable inline-button" onclick="ToggleAllFilters(false);<?php Show_Dictionary_Function($is_viewing) ?>;"> <span class="clickable inline-button" onclick="ToggleAllFilters(false);<?php Show_Dictionary_Function($display_mode == "view") ?>;">
Uncheck All Uncheck All
</span> </span>
</div> </div>
</div> </div>
<div id="filterWordCount"></div> <div id="filterWordCount"></div>
<?php } ?>
<div id="theDictionary"></div> <div id="theDictionary">
<?php if ($display_mode == "word") { echo "<script>document.write(DictionaryEntryTemplate(" . $the_public_word . "));</script>"; } ?>
</div>
</div> </div>
<div id="rightColumn" class="googleads" style="float:right;width:20%;max-width:300px;min-width:200px;overflow:hidden;"> <div id="rightColumn" class="googleads" style="float:right;width:20%;max-width:300px;min-width:200px;overflow:hidden;">
<?php if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/adsense.php"); } ?> <?php if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/adsense.php"); } ?>
</div> </div>
<?php if (!$is_viewing) { ?> <?php if ($display_mode == "build") { ?>
<div id="settingsScreen" style="display:none;"> <div id="settingsScreen" style="display:none;">
<div id="settingsBackgroundFade" onclick="HideSettings()"></div> <div id="settingsBackgroundFade" onclick="HideSettings()"></div>
@ -326,7 +371,7 @@ if ($is_viewing) {
} }
?> ?>
<?php if (!$is_viewing) { ?> <?php if ($display_mode == "build") { ?>
<div id="loadAfterDeleteScreen" style="display:none;"> <div id="loadAfterDeleteScreen" style="display:none;">
<div id="loadAfterDeleteFade"></div> <div id="loadAfterDeleteFade"></div>
<div id="loadAfterDeletePage"> <div id="loadAfterDeletePage">
@ -348,27 +393,27 @@ if ($is_viewing) {
</footer> </footer>
<!-- Markdown Parser --> <!-- Markdown Parser -->
<script src="js/marked.js"></script> <script src="/js/marked.js"></script>
<!-- CSV Parser --> <!-- CSV Parser -->
<script src="js/papaparse.js"></script> <script src="/js/papaparse.js"></script>
<!-- JSON Search --> <!-- JSON Search -->
<script src="js/defiant.js"></script> <script src="/js/defiant.js"></script>
<!-- Diacritics Removal for Exports --> <!-- Diacritics Removal for Exports -->
<script src="js/removeDiacritics.js"></script> <script src="/js/removeDiacritics.js"></script>
<!-- Helper Functions --> <!-- Helper Functions -->
<script src="js/helpers.js"></script> <script src="/js/helpers.js"></script>
<!-- Main Functions --> <!-- Main Functions -->
<script src="js/dictionaryBuilder.js"></script> <script src="/js/dictionaryBuilder.js"></script>
<!-- UI Functions --> <!-- UI Functions -->
<script src="js/ui.js"></script> <script src="/js/ui.js"></script>
<?php if ($is_viewing) { ?> <?php if ($display_mode == "view") { ?>
<!-- Public View Functions --> <!-- Public View Functions -->
<script src="js/publicView.js"></script> <script src="/js/publicView.js"></script>
<?php } ?> <?php } ?>
<?php if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/analytics.php"); } ?> <?php if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/analytics.php"); } ?>
<script> <script>
var aboutText = termsText = privacyText = loginForm = forgotForm = importForm = "Loading..."; var aboutText = termsText = privacyText = loginForm = forgotForm = importForm = "Loading...";
<?php if ($is_viewing) { ?> <?php if ($display_mode == "view") { ?>
window.onload = function () { window.onload = function () {
ShowPublicDictionary(); ShowPublicDictionary();
SetPublicPartsOfSpeech(); SetPublicPartsOfSpeech();

View File

@ -176,7 +176,7 @@ function UpdateWord(wordIndex, word, pronunciation, partOfSpeech, simpleDefiniti
function DeleteWord(index) { function DeleteWord(index) {
var deleteWord = new XMLHttpRequest(); var deleteWord = new XMLHttpRequest();
deleteWord.open('POST', "php/ajax_dictionarymanagement.php?action=worddelete"); deleteWord.open('POST', "/php/ajax_dictionarymanagement.php?action=worddelete");
deleteWord.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); deleteWord.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
deleteWord.onreadystatechange = function() { deleteWord.onreadystatechange = function() {
if (deleteWord.readyState == 4 && deleteWord.status == 200) { if (deleteWord.readyState == 4 && deleteWord.status == 200) {
@ -265,9 +265,6 @@ function ShowDictionary() {
} }
function DictionaryEntry(itemIndex) { function DictionaryEntry(itemIndex) {
displayPublic = (typeof displayPublic !== 'undefined' && displayPublic != null) ? displayPublic : false;
var entryText = "<entry id='entry" + itemIndex.toString() + "'><a name='" + currentDictionary.words[itemIndex].wordId + "'></a><a href='#" + currentDictionary.words[itemIndex].wordId + "' class='wordLink clickable'>&#x1f517;</a>";
var searchTerm = regexParseForSearch(document.getElementById("searchBox").value); var searchTerm = regexParseForSearch(document.getElementById("searchBox").value);
var searchByWord = document.getElementById("searchOptionWord").checked; var searchByWord = document.getElementById("searchOptionWord").checked;
var searchBySimple = document.getElementById("searchOptionSimple").checked; var searchBySimple = document.getElementById("searchOptionSimple").checked;
@ -277,61 +274,46 @@ function DictionaryEntry(itemIndex) {
var searchRegEx = new RegExp("(" + ((searchIgnoreDiacritics) ? removeDiacritics(searchTerm) + "|" + searchTerm : searchTerm) + ")", "g" + ((searchIgnoreCase) ? "i" : "")); var searchRegEx = new RegExp("(" + ((searchIgnoreDiacritics) ? removeDiacritics(searchTerm) + "|" + searchTerm : searchTerm) + ")", "g" + ((searchIgnoreCase) ? "i" : ""));
entryText += "<word>"; var wordName = wordPronunciation = wordPartOfSpeech = wordSimpleDefinition = wordLongDefinition = "";
if (searchTerm != "" && searchByWord) { if (searchTerm != "" && searchByWord) {
entryText += htmlEntitiesParse(currentDictionary.words[itemIndex].name).replace(searchRegEx, "<searchTerm>$1</searchterm>"); wordName += htmlEntitiesParse(currentDictionary.words[itemIndex].name).replace(searchRegEx, "<searchTerm>$1</searchterm>");
} else { } else {
entryText += currentDictionary.words[itemIndex].name; wordName += currentDictionary.words[itemIndex].name.toString(); // Use toString() to prevent using a reference instead of the value.
} }
entryText += "</word>";
if (currentDictionary.words[itemIndex].pronunciation != "") { if (currentDictionary.words[itemIndex].pronunciation != "") {
entryText += "<pronunciation>"; wordPronunciation += marked(htmlEntitiesParse(currentDictionary.words[itemIndex].pronunciation)).replace("<p>","").replace("</p>","");
entryText += marked(htmlEntitiesParse(currentDictionary.words[itemIndex].pronunciation)).replace("<p>","").replace("</p>","");
entryText += "</pronunciation>";
} }
if (currentDictionary.words[itemIndex].partOfSpeech != "") { if (currentDictionary.words[itemIndex].partOfSpeech != "") {
entryText += "<partofspeech>"; wordPartOfSpeech += currentDictionary.words[itemIndex].partOfSpeech.toString();
entryText += currentDictionary.words[itemIndex].partOfSpeech;
entryText += "</partofspeech>";
} }
entryText += "<br>";
if (currentDictionary.words[itemIndex].simpleDefinition != "") { if (currentDictionary.words[itemIndex].simpleDefinition != "") {
entryText += "<simpledefinition>";
if (searchTerm != "" && searchBySimple) { if (searchTerm != "" && searchBySimple) {
entryText += htmlEntitiesParse(currentDictionary.words[itemIndex].simpleDefinition).replace(searchRegEx, "<searchTerm>$1</searchterm>"); wordSimpleDefinition += htmlEntitiesParse(currentDictionary.words[itemIndex].simpleDefinition).replace(searchRegEx, "<searchTerm>$1</searchterm>");
} else { } else {
entryText += currentDictionary.words[itemIndex].simpleDefinition; wordSimpleDefinition += currentDictionary.words[itemIndex].simpleDefinition.toString();
} }
entryText += "</simpledefinition>";
} }
if (currentDictionary.words[itemIndex].longDefinition != "") { if (currentDictionary.words[itemIndex].longDefinition != "") {
entryText += "<longdefinition>";
if (searchTerm != "" && searchByLong) { if (searchTerm != "" && searchByLong) {
entryText += marked(htmlEntitiesParse(currentDictionary.words[itemIndex].longDefinition).replace(searchRegEx, "<searchTerm>$1</searchterm>")); wordLongDefinition += marked(htmlEntitiesParse(currentDictionary.words[itemIndex].longDefinition).replace(searchRegEx, "<searchTerm>$1</searchterm>"));
} else { } else {
entryText += marked(htmlEntitiesParse(currentDictionary.words[itemIndex].longDefinition)); wordLongDefinition += marked(htmlEntitiesParse(currentDictionary.words[itemIndex].longDefinition));
} }
entryText += "</longdefinition>";
} }
if (!currentDictionary.settings.isComplete) { return DictionaryEntryTemplate({
entryText += ManagementArea(itemIndex); name : wordName,
} pronunciation : wordPronunciation,
partOfSpeech : wordPartOfSpeech,
entryText += "</entry>"; simpleDefinition : wordSimpleDefinition,
longDefinition : wordLongDefinition,
return entryText; wordId : currentDictionary.words[itemIndex].wordId.toString()
}, (!currentDictionary.settings.isComplete) ? itemIndex : false);
} }
function ManagementArea(itemIndex) { function ManagementArea(itemIndex) {
@ -350,6 +332,44 @@ function ManagementArea(itemIndex) {
return managementHTML; return managementHTML;
} }
function DictionaryEntryTemplate(wordObject, managementIndex) {
managementIndex = (typeof managementIndex !== 'undefined') ? managementIndex : false;
var entryText = "<entry id='entry";
if (managementIndex !== false) {
// If there's a managementIndex, append index number to the element id.
entryText += managementIndex.toString();
}
entryText += "'><a href='#" + wordObject.wordId + "' class='wordLink clickable'>&#x1f517;</a>";
entryText += "<word>" + wordObject.name + "</word>";
if (wordObject.pronunciation != "") {
entryText += "<pronunciation>" + wordObject.pronunciation + "</pronunciation>";
}
if (wordObject.partOfSpeech != "") {
entryText += "<partofspeech>" + wordObject.partOfSpeech + "</partofspeech>";
}
entryText += "<br>";
if (wordObject.simpleDefinition != "") {
entryText += "<simpledefinition>" + wordObject.simpleDefinition + "</simpledefinition>";
}
if (wordObject.longDefinition != "") {
entryText += "<longdefinition>" + wordObject.longDefinition + "</longdefinition>";
}
if (managementIndex !== false) {
entryText += ManagementArea(managementIndex);
}
entryText += "</entry>";
return entryText;
}
function SaveSettings() { function SaveSettings() {
if (htmlEntities(document.getElementById("dictionaryNameEdit").value) != "") { if (htmlEntities(document.getElementById("dictionaryNameEdit").value) != "") {
currentDictionary.name = htmlEntities(document.getElementById("dictionaryNameEdit").value); currentDictionary.name = htmlEntities(document.getElementById("dictionaryNameEdit").value);
@ -395,7 +415,7 @@ function DeleteCurrentDictionary() {
ResetDictionaryToDefault(); ResetDictionaryToDefault();
var deleteDictionary = new XMLHttpRequest(); var deleteDictionary = new XMLHttpRequest();
deleteDictionary.open('POST', "php/ajax_dictionarymanagement.php?action=delete"); deleteDictionary.open('POST', "/php/ajax_dictionarymanagement.php?action=delete");
deleteDictionary.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); deleteDictionary.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
deleteDictionary.onreadystatechange = function() { deleteDictionary.onreadystatechange = function() {
if (deleteDictionary.readyState == 4 && deleteDictionary.status == 200) { if (deleteDictionary.readyState == 4 && deleteDictionary.status == 200) {
@ -439,7 +459,7 @@ function SaveAndUpdateWords(action, wordIndex) {
} }
var sendWords = new XMLHttpRequest(); var sendWords = new XMLHttpRequest();
sendWords.open('POST', "php/ajax_dictionarymanagement.php?action=word" + action + "&nextwordid=" + currentDictionary.nextWordId.toString()); sendWords.open('POST', "/php/ajax_dictionarymanagement.php?action=word" + action + "&nextwordid=" + currentDictionary.nextWordId.toString());
sendWords.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); sendWords.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
sendWords.onreadystatechange = function() { sendWords.onreadystatechange = function() {
if (sendWords.readyState == 4 && sendWords.status == 200) { if (sendWords.readyState == 4 && sendWords.status == 200) {
@ -501,7 +521,7 @@ function SendDictionary() {
} }
var sendDictionary = new XMLHttpRequest(); var sendDictionary = new XMLHttpRequest();
sendDictionary.open('POST', "php/ajax_dictionarymanagement.php?action=" + action); sendDictionary.open('POST', "/php/ajax_dictionarymanagement.php?action=" + action);
sendDictionary.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); sendDictionary.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
sendDictionary.onreadystatechange = function() { sendDictionary.onreadystatechange = function() {
if (sendDictionary.readyState == 4 && sendDictionary.status == 200) { if (sendDictionary.readyState == 4 && sendDictionary.status == 200) {
@ -570,7 +590,7 @@ function DataToSend(sendAll) {
function LoadDictionary() { function LoadDictionary() {
LoadLocalDictionary(); LoadLocalDictionary();
var loadDictionary = new XMLHttpRequest(); var loadDictionary = new XMLHttpRequest();
loadDictionary.open('GET', "php/ajax_dictionarymanagement.php?action=load"); loadDictionary.open('GET', "/php/ajax_dictionarymanagement.php?action=load");
loadDictionary.onreadystatechange = function() { loadDictionary.onreadystatechange = function() {
if (loadDictionary.readyState == 4 && loadDictionary.status == 200) { if (loadDictionary.readyState == 4 && loadDictionary.status == 200) {
if (loadDictionary.responseText == "no dictionaries") { if (loadDictionary.responseText == "no dictionaries") {
@ -594,7 +614,7 @@ function ChangeDictionary(userDictionariesSelect) {
userDictionariesSelect = (typeof userDictionariesSelect !== 'undefined' && userDictionariesSelect != null) ? userDictionariesSelect : document.getElementById("userDictionaries"); userDictionariesSelect = (typeof userDictionariesSelect !== 'undefined' && userDictionariesSelect != null) ? userDictionariesSelect : document.getElementById("userDictionaries");
if (currentDictionary.externalID != userDictionariesSelect.value && userDictionariesSelect.options.length > 0) { if (currentDictionary.externalID != userDictionariesSelect.value && userDictionariesSelect.options.length > 0) {
var changeDictionaryRequest = new XMLHttpRequest(); var changeDictionaryRequest = new XMLHttpRequest();
changeDictionaryRequest.open('POST', "php/ajax_dictionarymanagement.php?action=switch"); changeDictionaryRequest.open('POST', "/php/ajax_dictionarymanagement.php?action=switch");
changeDictionaryRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); changeDictionaryRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var postString = "newdictionaryid=" + userDictionariesSelect.value.toString(); var postString = "newdictionaryid=" + userDictionariesSelect.value.toString();
changeDictionaryRequest.onreadystatechange = function() { changeDictionaryRequest.onreadystatechange = function() {
@ -775,11 +795,13 @@ function ImportWords() {
} }
} }
function WordIndex(word) { function WordIndex(word, byId) {
// Use byId = true to enter word id number instead of string.
for (var i = 0; i < currentDictionary.words.length; i++) for (var i = 0; i < currentDictionary.words.length; i++)
{ {
if ((!currentDictionary.settings.caseSensitive && currentDictionary.words[i].name.toLowerCase() == word.toLowerCase()) || if ((!byId && (!currentDictionary.settings.caseSensitive && currentDictionary.words[i].name.toLowerCase() == word.toLowerCase()) ||
(currentDictionary.settings.caseSensitive && currentDictionary.words[i].name == word)) { (currentDictionary.settings.caseSensitive && currentDictionary.words[i].name == word)) ||
(byId && currentDictionary.words[i].wordId == word)) {
return i; return i;
} }
} }

View File

@ -3,12 +3,12 @@ function Initialize() {
ClearForm(); ClearForm();
LoadUserDictionaries(); LoadUserDictionaries();
GetTextFile("README.md", "aboutText", true); GetTextFile("/README.md", "aboutText", true);
GetTextFile("TERMS.md", "termsText", true); GetTextFile("/TERMS.md", "termsText", true);
GetTextFile("PRIVACY.md", "privacyText", true); GetTextFile("/PRIVACY.md", "privacyText", true);
GetTextFile("LOGIN.form", "loginForm", false); GetTextFile("/LOGIN.form", "loginForm", false);
GetTextFile("FORGOT.form", "forgotForm", false); GetTextFile("/FORGOT.form", "forgotForm", false);
GetTextFile("IMPORT.form", "importForm", false); GetTextFile("/IMPORT.form", "importForm", false);
SetKeyboardShortcuts(); SetKeyboardShortcuts();
} }
@ -133,7 +133,7 @@ function LoadUserDictionaries() {
var getDictionariesRequest = new XMLHttpRequest(); var getDictionariesRequest = new XMLHttpRequest();
var userDictionariesSelect = document.getElementById("userDictionaries"); var userDictionariesSelect = document.getElementById("userDictionaries");
if (userDictionariesSelect != null) { if (userDictionariesSelect != null) {
getDictionariesRequest.open('GET', "php/ajax_dictionarymanagement.php?action=getall"); getDictionariesRequest.open('GET', "/php/ajax_dictionarymanagement.php?action=getall");
getDictionariesRequest.onreadystatechange = function() { getDictionariesRequest.onreadystatechange = function() {
if (getDictionariesRequest.readyState == 4 && getDictionariesRequest.status == 200) { if (getDictionariesRequest.readyState == 4 && getDictionariesRequest.status == 200) {
ParseUserDictionariesIntoSelect(userDictionariesSelect, getDictionariesRequest.responseText); ParseUserDictionariesIntoSelect(userDictionariesSelect, getDictionariesRequest.responseText);
@ -216,7 +216,7 @@ function ValidateCreateAccount() {
return false; return false;
} else { } else {
var emailCheck = new XMLHttpRequest(); var emailCheck = new XMLHttpRequest();
emailCheck.open('GET', "php/ajax_createaccountemailcheck.php?email=" + emailValue); emailCheck.open('GET', "/php/ajax_createaccountemailcheck.php?email=" + emailValue);
emailCheck.onreadystatechange = function() { emailCheck.onreadystatechange = function() {
if (emailCheck.readyState == 4 && emailCheck.status == 200) { if (emailCheck.readyState == 4 && emailCheck.status == 200) {
if (emailCheck.responseText != "ok") { if (emailCheck.responseText != "ok") {
@ -262,7 +262,7 @@ function ValidateForgotPassword() {
return false; return false;
} else { } else {
var emailCheck = new XMLHttpRequest(); var emailCheck = new XMLHttpRequest();
emailCheck.open('GET', "php/ajax_passwordresetemailcheck.php?email=" + emailValue); emailCheck.open('GET', "/php/ajax_passwordresetemailcheck.php?email=" + emailValue);
emailCheck.onreadystatechange = function() { emailCheck.onreadystatechange = function() {
if (emailCheck.readyState == 4 && emailCheck.status == 200) { if (emailCheck.readyState == 4 && emailCheck.status == 200) {
if (emailCheck.responseText != "email exists") { if (emailCheck.responseText != "email exists") {
@ -307,7 +307,7 @@ function WarnEmailChange() {
function LoggedInResetPassword() { function LoggedInResetPassword() {
var resetPasswordRequest = new XMLHttpRequest(); var resetPasswordRequest = new XMLHttpRequest();
resetPasswordRequest.open('GET', "php/ajax_setnewpassword.php"); resetPasswordRequest.open('GET', "/php/ajax_setnewpassword.php");
resetPasswordRequest.onreadystatechange = function() { resetPasswordRequest.onreadystatechange = function() {
if (resetPasswordRequest.readyState == 4 && resetPasswordRequest.status == 200) { if (resetPasswordRequest.readyState == 4 && resetPasswordRequest.status == 200) {
if (resetPasswordRequest.responseText != "done") { if (resetPasswordRequest.responseText != "done") {