Got public word pages working! Added link to public words from editing dictionary.

Separated some templating functions so styling will be easier moving forward.
This commit is contained in:
Robbie Antenesse 2016-06-20 17:13:51 -06:00
parent fca5fb2704
commit 3902ba96ba
3 changed files with 186 additions and 132 deletions

151
index.php
View File

@ -13,6 +13,8 @@ $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';
$is_owner = false;
$display_mode = ($dictionary_to_load > 0) ? (($word_to_load > 0) ? "word" : "view") : "build"; $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');
@ -34,60 +36,62 @@ if ($display_mode != "build") {
$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);
if ($display_mode == "word") { $dictionary_query = "SELECT `d`.`id`, `d`.`user`, `d`.`name`, `d`.`description`, `u`.`public_name`, `d`.`parts_of_speech`, `d`.`is_complete` ";
// only query for specific word. $dictionary_query .= "FROM `dictionaries` AS `d` LEFT JOIN `users` AS `u` ON `d`.`user`=`u`.`id`";
$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` "; $dictionary_query .= "WHERE `d`.`is_public`=1 AND `d`.`id`=" . $dictionary_to_load . ";";
$query .= "FROM `words` AS `w` LEFT JOIN `dictionaries` AS `d` ON `w`.`dictionary`=`d`.`id` ";
$query .= "LEFT JOIN `users` AS `u` ON `d`.`user`=`u`.`id` ";
$query .= "WHERE `d`.`is_public`=1 AND `w`.`dictionary`=" . $dictionary_to_load . " AND `w`.`word_id`=" . $dictionary_to_load . ";";
try {
$queryResults = $dbconnection->prepare($query);
$queryResults->execute();
if ($queryResults) {
if (num_rows($queryResults) === 1) {
while ($word = fetch($queryResults)) {
$dictionary_name = $word['dname'];
$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 { $word_query = "SELECT `w`.`word_id`, `w`.`name`, `w`.`pronunciation`, `w`.`part_of_speech`, `w`.`simple_definition`, `w`.`long_definition` ";
$queryResults = $dbconnection->prepare($query); $word_query .= "FROM `words` AS `w` LEFT JOIN `dictionaries` AS `d` ON `w`.`dictionary`=`d`.`id` ";
$queryResults->execute(); $word_query .= "WHERE `d`.`is_public`=1 AND `w`.`dictionary`=" . $dictionary_to_load . (($display_mode == "word") ? " AND `w`.`word_id`=" . $word_to_load : "") . " ";
if ($queryResults) { $word_query .= "ORDER BY IF(`d`.`sort_by_equivalent`, `w`.`simple_definition`, `w`.`name`) COLLATE utf8_unicode_ci;";
if (num_rows($queryResults) === 1) {
while ($dict = fetch($queryResults)) { try {
$dictionary_name = $dict['name']; $dictionary_results = $dbconnection->prepare($dictionary_query);
$dictionary_creator = $dict['public_name']; $dictionary_results->execute();
$the_public_dictionary = '{"name":"' . $dict['name'] . '",'; if ($dictionary_results) {
$the_public_dictionary .= '"description":"' . $dict['description'] . '",'; $word_results = $dbconnection->prepare($word_query);
$the_public_dictionary .= '"createdBy":"' . $dict['public_name'] . '",'; $word_results->execute();
$the_public_dictionary .= '"words":' . Get_Dictionary_Words($dictionary_to_load) . ','; $dictionary_words = "[";
$the_public_dictionary .= '"settings":{'; if ($word_results) {
$the_public_dictionary .= '"partsOfSpeech":"' . $dict['parts_of_speech'] . '",'; $words_counted = 0;
$the_public_dictionary .= '"isComplete":' . (($dict['is_complete'] == 1) ? 'true' : 'false') . '},'; $words_total = num_rows($word_results);
$the_public_dictionary .= '}'; while ($word = fetch($word_results)) {
$words_counted++;
$word_name = $word['name'];
$dictionary_words .= '{"name":"' . $word['name'] . '",';
$dictionary_words .= '"pronunciation":"' . $word['pronunciation'] . '",';
$dictionary_words .= '"partOfSpeech":"' . $word['part_of_speech'] . '",';
$dictionary_words .= '"simpleDefinition":"' . $word['simple_definition'] . '",';
$dictionary_words .= '"longDefinition":"' . $word['long_definition'] . '",';
$dictionary_words .= '"wordId":"' . $word['word_id'] . '"';
$dictionary_words .= '}';
if ($words_counted < $words_total) {
$dictionary_words .= ',';
} }
} }
} }
$dictionary_words .= "]";
if (num_rows($dictionary_results) === 1) {
while ($dict = fetch($dictionary_results)) {
$dictionary_name = $dict['name'];
$dictionary_creator = $dict['public_name'];
$is_owner = $current_user == $dict['user'];
$the_public_dictionary = '{"name":"' . $dict['name'] . '",';
$the_public_dictionary .= '"description":"' . $dict['description'] . '",';
$the_public_dictionary .= '"createdBy":"' . $dict['public_name'] . '",';
$the_public_dictionary .= '"words":' . $dictionary_words . ',';
$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 .= '"id":"' . $dictionary_to_load . '"';
$the_public_dictionary .= '}';
}
}
} }
catch (PDOException $ex) {}
} }
catch (PDOException $ex) {}
} }
?> ?>
@ -104,12 +108,8 @@ if ($display_mode != "build") {
<meta property="og:title" content="<?php echo (($display_mode == "word") ? ("\"" . $word_name . "\" in the ") : "") . $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" />
<?php if (isset($the_public_word)) { ?> <script>var publicDictionary = <?php echo $the_public_dictionary; ?></script>
<script>var publicWord = <?php echo $the_public_word; ?></script> <?php } else { ?>
<?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:url" content="http://lexicon.ga" />
<meta property="og:type" content="website" /> <meta property="og:type" content="website" />
@ -129,13 +129,22 @@ if ($display_mode != "build") {
<span id="aboutButton" class="clickable" onclick="ShowInfo('aboutText')">About Lexiconga</span> <span id="aboutButton" class="clickable" onclick="ShowInfo('aboutText')">About Lexiconga</span>
</div> </div>
<div id="loginoutArea" style="font-size:12px;"> <div id="loginoutArea" style="font-size:12px;">
<?php if ($display_mode == "build") { ?>
<?php if ($current_user > 0) { //If logged in, show the log out button. ?> <?php if ($current_user > 0) { //If logged in, show the log out button. ?>
<span id="accountSettings" class="clickable" onclick="ShowAccountSettings()">Account Settings</span> <a href="?logout" id="logoutLink" class="clickable">Log Out</a> <span id="accountSettings" class="clickable" onclick="ShowAccountSettings()">Account Settings</span> <a href="?logout" id="logoutLink" class="clickable">Log Out</a>
<?php } elseif (!isset($_SESSION['loginfailures']) || (isset($_SESSION['loginfailures']) && $_SESSION['loginfailures'] < 10)) { ?> <?php } elseif (!isset($_SESSION['loginfailures']) || (isset($_SESSION['loginfailures']) && $_SESSION['loginfailures'] < 10)) { ?>
<span id="loginLink" class="clickable" onclick="ShowInfo('loginForm')">Log In/Create Account</span> <span id="loginLink" class="clickable" onclick="ShowInfo('loginForm')">Log In/Create Account</span>
<?php } else { ?> <?php } else { ?>
<span id="loginLink" class="clickable" title="<?php echo $hoverlockoutmessage; ?>" onclick="alert('<?php echo $alertlockoutmessage; ?>');">Can't Login</span> <span id="loginLink" class="clickable" title="<?php echo $hoverlockoutmessage; ?>" onclick="alert('<?php echo $alertlockoutmessage; ?>');">Can't Login</span>
<?php } ?> <?php }
} else { ?>
<h3 style="display:inline; margin:0 5px;">Viewing</h3>
<?php if ($is_owner) { ?>
<span class="clickable" onclick="ChangeDictionaryToId(<?php echo $dictionary_to_load; ?>, function(response) {if (response.length >= 60) window.location.href = '/';});">&laquo; Edit Dictionary</span>
<?php } else { ?>
<a class="clickable" href="/">&laquo; Go Home to Lexiconga</a>
<?php }?>
<?php } ?>
</div> </div>
</div> </div>
</header> </header>
@ -188,11 +197,14 @@ if ($display_mode != "build") {
<?php } ?> <?php } ?>
<h1 id="dictionaryName"></h1> <h1 id="dictionaryName"></h1>
<?php if ($display_mode == "view") { ?> <?php if ($display_mode != "build") { ?>
<h4 id="dictionaryBy"></h4> <h4 id="dictionaryBy"></h4>
<div id="incompleteNotice"></div> <div id="incompleteNotice"></div>
<?php } ?> <?php } ?>
<?php if ($display_mode == "word") { ?>
<a class="clickable" href="/<?php echo $dictionary_to_load; ?>">View Full Dictionary</a>
<?php } ?>
<span id="descriptionToggle" class="clickable" onclick="ToggleDescription();"><?php if ($display_mode == "view") { ?>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 ($display_mode == "view") { ?>block<?php } else { ?>none<?php } ?>;"></div> <div id="dictionaryDescription" style="display:<?php if ($display_mode == "view") { ?>block<?php } else { ?>none<?php } ?>;"></div>
@ -232,9 +244,7 @@ if ($display_mode != "build") {
<div id="filterWordCount"></div> <div id="filterWordCount"></div>
<?php } ?> <?php } ?>
<div id="theDictionary"> <div id="theDictionary"></div>
<?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;">
@ -406,24 +416,27 @@ if ($display_mode != "build") {
<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 ($display_mode == "view") { ?> <?php if ($display_mode != "build") { ?>
<!-- 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 ($display_mode == "view") { ?> <?php if ($display_mode != "build") { ?>
window.onload = function () { window.onload = function () {
ShowPublicDictionary(); ShowPublicDictionary(<?php if ($display_mode == "word") echo "true"; ?>);
SetPublicPartsOfSpeech(); <?php
if ($display_mode != "word") { // don't try to set the filters
echo "SetPublicPartsOfSpeech()";
} ?>
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);
} }
<?php } else { ?> <?php } else { ?>
ready(function() { ready(function() {

View File

@ -339,7 +339,13 @@ function DictionaryEntryTemplate(wordObject, managementIndex) {
// If there's a managementIndex, append index number to the element id. // If there's a managementIndex, append index number to the element id.
entryText += managementIndex.toString(); entryText += managementIndex.toString();
} }
entryText += "'><a href='#" + wordObject.wordId + "' class='wordLink clickable'>&#x1f517;</a>"; entryText += "'><a name='" + wordObject.wordId + "'></a>";
if (currentDictionary.settings.isPublic) {
entryText += "<a href='/" + currentDictionary.externalID + "/" + wordObject.wordId + "' class='wordLink clickable' title='Share Word' style='margin-left:5px;'>&#10150;</a>";
}
entryText += "<a href='#" + wordObject.wordId + "' class='wordLink clickable' title='Link Within Page'>&#x1f517;</a>";
entryText += "<word>" + wordObject.name + "</word>"; entryText += "<word>" + wordObject.name + "</word>";
@ -613,28 +619,34 @@ function LoadDictionary() {
function ChangeDictionary(userDictionariesSelect) { 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(); ChangeDictionaryToId(userDictionariesSelect.value, function(response) {
changeDictionaryRequest.open('POST', "/php/ajax_dictionarymanagement.php?action=switch"); if (response == "no dictionaries") {
changeDictionaryRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); console.log(response);
var postString = "newdictionaryid=" + userDictionariesSelect.value.toString();
changeDictionaryRequest.onreadystatechange = function() {
if (changeDictionaryRequest.readyState == 4 && changeDictionaryRequest.status == 200) {
if (changeDictionaryRequest.responseText == "no dictionaries") {
console.log(changeDictionaryRequest.responseText);
SendDictionary(false); SendDictionary(false);
} else if (changeDictionaryRequest.responseText.length < 60) { } else if (response.length < 60) {
console.log(changeDictionaryRequest.responseText); console.log(response);
} else { } else {
currentDictionary = JSON.parse(changeDictionaryRequest.responseText); currentDictionary = JSON.parse(response);
SaveDictionary(false); SaveDictionary(false);
ProcessLoad(); ProcessLoad();
LoadUserDictionaries(); LoadUserDictionaries();
HideSettings(); HideSettings();
} }
});
}
}
function ChangeDictionaryToId(dictionaryId, callbackFunction) {
var changeDictionaryRequest = new XMLHttpRequest();
changeDictionaryRequest.open('POST', "/php/ajax_dictionarymanagement.php?action=switch");
changeDictionaryRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var postString = "newdictionaryid=" + dictionaryId.toString();
changeDictionaryRequest.onreadystatechange = function() {
if (changeDictionaryRequest.readyState == 4 && changeDictionaryRequest.status == 200) {
callbackFunction(changeDictionaryRequest.responseText);
} }
} }
changeDictionaryRequest.send(postString); changeDictionaryRequest.send(postString);
}
} }
function LoadLocalDictionary() { function LoadLocalDictionary() {

View File

@ -2,18 +2,20 @@ function IsValidPublicDicitonary() {
return typeof publicDictionary !== 'string'; return typeof publicDictionary !== 'string';
} }
function ShowPublicDictionary() { function ShowPublicDictionary(ignoreFilters) {
ignoreFilters = (typeof ignoreFilters !== 'undefined') ? ignoreFilters : false;
if (IsValidPublicDicitonary()) { if (IsValidPublicDicitonary()) {
var filters = GetSelectedFilters(); var filters = (ignoreFilters) ? [] : GetSelectedFilters();
var searchResults = []; var searchResults = [];
var search = htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value); var search = (ignoreFilters) ? "" : htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value);
var searchByWord = document.getElementById("searchOptionWord").checked; var searchByWord = (ignoreFilters) ? null : document.getElementById("searchOptionWord").checked;
var searchBySimple = document.getElementById("searchOptionSimple").checked; var searchBySimple = (ignoreFilters) ? null : document.getElementById("searchOptionSimple").checked;
var searchByLong = document.getElementById("searchOptionLong").checked; var searchByLong = (ignoreFilters) ? null : document.getElementById("searchOptionLong").checked;
var searchIgnoreCase = !document.getElementById("searchCaseSensitive").checked; //It's easier to negate case here instead of negating it every use since ignore case is default. var searchIgnoreCase = (ignoreFilters) ? null : !document.getElementById("searchCaseSensitive").checked; //It's easier to negate case here instead of negating it every use since ignore case is default.
var searchIgnoreDiacritics = document.getElementById("searchIgnoreDiacritics").checked; var searchIgnoreDiacritics = (ignoreFilters) ? null : document.getElementById("searchIgnoreDiacritics").checked;
if (search != "" && (searchByWord || searchBySimple || searchByLong)) { if (!ignoreFilters && search != "" && (searchByWord || searchBySimple || searchByLong)) {
var xpath = []; var xpath = [];
var searchDictionaryJSON = htmlEntitiesParseForSearch(JSON.stringify(publicDictionary)); var searchDictionaryJSON = htmlEntitiesParseForSearch(JSON.stringify(publicDictionary));
if (searchIgnoreCase) { if (searchIgnoreCase) {
@ -65,7 +67,7 @@ function ShowPublicDictionary() {
if (!publicDictionary.words[i].hasOwnProperty("wordId")) { if (!publicDictionary.words[i].hasOwnProperty("wordId")) {
publicDictionary.words[i].wordId = i + 1; //Account for new property publicDictionary.words[i].wordId = i + 1; //Account for new property
} }
dictionaryText += PublicDictionaryEntry(i); dictionaryText += PublicDictionaryEntry(i, ignoreFilters);
numberOfWordsDisplayed++; numberOfWordsDisplayed++;
} }
} }
@ -74,70 +76,97 @@ function ShowPublicDictionary() {
dictionaryText = "There are no entries in the dictionary." dictionaryText = "There are no entries in the dictionary."
} }
dictionaryArea.innerHTML = dictionaryText; dictionaryArea.innerHTML = dictionaryText;
ShowFilterWordCount(numberOfWordsDisplayed); if (!ignoreFilters) {
ShowFilterWordCount(numberOfWordsDisplayed);
}
} else { } else {
document.getElementById("dictionaryContainer").innerHTML = publicDictionary; document.getElementById("dictionaryContainer").innerHTML = publicDictionary;
} }
} }
function PublicDictionaryEntry(itemIndex) { function PublicDictionaryEntry(itemIndex, ignoreFilters) {
var entryText = "<entry><a name='" + publicDictionary.words[itemIndex].wordId + "'></a><a href='#" + publicDictionary.words[itemIndex].wordId + "' class='wordLink clickable'>&#x1f517;</a>"; var searchTerm = (ignoreFilters) ? "" : regexParseForSearch(document.getElementById("searchBox").value);
var searchByWord = (ignoreFilters) ? false : document.getElementById("searchOptionWord").checked;
var searchTerm = regexParseForSearch(document.getElementById("searchBox").value); var searchBySimple = (ignoreFilters) ? false : document.getElementById("searchOptionSimple").checked;
var searchByWord = document.getElementById("searchOptionWord").checked; var searchByLong = (ignoreFilters) ? false : document.getElementById("searchOptionLong").checked;
var searchBySimple = document.getElementById("searchOptionSimple").checked; var searchIgnoreCase = (ignoreFilters) ? false : !document.getElementById("searchCaseSensitive").checked; //It's easier to negate case here instead of negating it every use since ignore case is default.
var searchByLong = document.getElementById("searchOptionLong").checked; var searchIgnoreDiacritics = (ignoreFilters) ? false : document.getElementById("searchIgnoreDiacritics").checked;
var searchIgnoreCase = !document.getElementById("searchCaseSensitive").checked; //It's easier to negate case here instead of negating it every use since ignore case is default.
var searchIgnoreDiacritics = document.getElementById("searchIgnoreDiacritics").checked;
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(publicDictionary.words[itemIndex].name).replace(searchRegEx, "<searchTerm>$1</searchterm>"); wordName += htmlEntitiesParse(publicDictionary.words[itemIndex].name).replace(searchRegEx, "<searchTerm>$1</searchterm>");
} else { } else {
entryText += publicDictionary.words[itemIndex].name; wordName += publicDictionary.words[itemIndex].name.toString(); // Use toString() to prevent using a reference instead of the value.
} }
entryText += "</word>";
if (publicDictionary.words[itemIndex].pronunciation != "") { if (publicDictionary.words[itemIndex].pronunciation != "") {
entryText += "<pronunciation>"; wordPronunciation += marked(htmlEntitiesParse(publicDictionary.words[itemIndex].pronunciation)).replace("<p>","").replace("</p>","");
entryText += marked(htmlEntitiesParse(publicDictionary.words[itemIndex].pronunciation)).replace("<p>","").replace("</p>","");
entryText += "</pronunciation>";
} }
if (publicDictionary.words[itemIndex].partOfSpeech != "") { if (publicDictionary.words[itemIndex].partOfSpeech != "") {
entryText += "<partofspeech>"; wordPartOfSpeech += publicDictionary.words[itemIndex].partOfSpeech.toString();
entryText += publicDictionary.words[itemIndex].partOfSpeech; }
entryText += "</partofspeech>";
if (publicDictionary.words[itemIndex].simpleDefinition != "") {
if (searchTerm != "" && searchBySimple) {
wordSimpleDefinition += htmlEntitiesParse(publicDictionary.words[itemIndex].simpleDefinition).replace(searchRegEx, "<searchTerm>$1</searchterm>");
} else {
wordSimpleDefinition += publicDictionary.words[itemIndex].simpleDefinition.toString();
}
}
if (publicDictionary.words[itemIndex].longDefinition != "") {
if (searchTerm != "" && searchByLong) {
wordLongDefinition += marked(htmlEntitiesParse(publicDictionary.words[itemIndex].longDefinition).replace(searchRegEx, "<searchTerm>$1</searchterm>"));
} else {
wordLongDefinition += marked(htmlEntitiesParse(publicDictionary.words[itemIndex].longDefinition));
}
}
return PublicDictionaryEntryTemplate({
name : wordName,
pronunciation : wordPronunciation,
partOfSpeech : wordPartOfSpeech,
simpleDefinition : wordSimpleDefinition,
longDefinition : wordLongDefinition,
wordId : publicDictionary.words[itemIndex].wordId.toString()
}, false);
}
function PublicDictionaryEntryTemplate(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='/" + publicDictionary.id + "/" + wordObject.wordId + "' class='wordLink clickable' title='Share Word'>&#10150;</a>";
entryText += "<word>" + wordObject.name + "</word>";
if (wordObject.pronunciation != "") {
entryText += "<pronunciation>" + wordObject.pronunciation + "</pronunciation>";
}
if (wordObject.partOfSpeech != "") {
entryText += "<partofspeech>" + wordObject.partOfSpeech + "</partofspeech>";
} }
entryText += "<br>"; entryText += "<br>";
if (publicDictionary.words[itemIndex].simpleDefinition != "") { if (wordObject.simpleDefinition != "") {
entryText += "<simpledefinition>"; entryText += "<simpledefinition>" + wordObject.simpleDefinition + "</simpledefinition>";
if (searchTerm != "" && searchBySimple) {
entryText += htmlEntitiesParse(publicDictionary.words[itemIndex].simpleDefinition).replace(searchRegEx, "<searchTerm>$1</searchterm>");
} else {
entryText += publicDictionary.words[itemIndex].simpleDefinition;
}
entryText += "</simpledefinition>";
} }
if (publicDictionary.words[itemIndex].longDefinition != "") { if (wordObject.longDefinition != "") {
entryText += "<longdefinition>"; entryText += "<longdefinition>" + wordObject.longDefinition + "</longdefinition>";
}
if (searchTerm != "" && searchByLong) { if (managementIndex !== false) {
entryText += marked(htmlEntitiesParse(publicDictionary.words[itemIndex].longDefinition).replace(searchRegEx, "<searchTerm>$1</searchterm>")); entryText += ManagementArea(managementIndex);
} else {
entryText += marked(htmlEntitiesParse(publicDictionary.words[itemIndex].longDefinition));
}
entryText += "</longdefinition>";
} }
entryText += "</entry>"; entryText += "</entry>";