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:
parent
fca5fb2704
commit
3902ba96ba
151
index.php
151
index.php
|
@ -13,6 +13,8 @@ $word_to_load = (isset($_GET['word'])) ? intval($_GET['word']) : 0;
|
|||
$the_public_word = '"That word doesn\'t exist."';
|
||||
$word_name = 'ERROR';
|
||||
|
||||
$is_owner = false;
|
||||
|
||||
$display_mode = ($dictionary_to_load > 0) ? (($word_to_load > 0) ? "word" : "view") : "build";
|
||||
|
||||
$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_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
|
||||
if ($display_mode == "word") {
|
||||
// only query for specific word.
|
||||
$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` ";
|
||||
$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 . ";";
|
||||
$dictionary_query = "SELECT `d`.`id`, `d`.`user`, `d`.`name`, `d`.`description`, `u`.`public_name`, `d`.`parts_of_speech`, `d`.`is_complete` ";
|
||||
$dictionary_query .= "FROM `dictionaries` AS `d` LEFT JOIN `users` AS `u` ON `d`.`user`=`u`.`id`";
|
||||
$dictionary_query .= "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 .= '}';
|
||||
$word_query = "SELECT `w`.`word_id`, `w`.`name`, `w`.`pronunciation`, `w`.`part_of_speech`, `w`.`simple_definition`, `w`.`long_definition` ";
|
||||
$word_query .= "FROM `words` AS `w` LEFT JOIN `dictionaries` AS `d` ON `w`.`dictionary`=`d`.`id` ";
|
||||
$word_query .= "WHERE `d`.`is_public`=1 AND `w`.`dictionary`=" . $dictionary_to_load . (($display_mode == "word") ? " AND `w`.`word_id`=" . $word_to_load : "") . " ";
|
||||
$word_query .= "ORDER BY IF(`d`.`sort_by_equivalent`, `w`.`simple_definition`, `w`.`name`) COLLATE utf8_unicode_ci;";
|
||||
|
||||
try {
|
||||
$dictionary_results = $dbconnection->prepare($dictionary_query);
|
||||
$dictionary_results->execute();
|
||||
if ($dictionary_results) {
|
||||
$word_results = $dbconnection->prepare($word_query);
|
||||
$word_results->execute();
|
||||
$dictionary_words = "[";
|
||||
if ($word_results) {
|
||||
$words_counted = 0;
|
||||
$words_total = num_rows($word_results);
|
||||
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:description" content="A Lexiconga dictionary by <?php echo $dictionary_creator; ?>" />
|
||||
<meta property="og:image" content="http://lexicon.ga/images/logo.svg" />
|
||||
<?php if (isset($the_public_word)) { ?>
|
||||
<script>var publicWord = <?php echo $the_public_word; ?></script>
|
||||
<?php } else { ?>
|
||||
<script>var publicDictionary = <?php echo $the_public_dictionary; ?></script>
|
||||
<?php }
|
||||
} else { ?>
|
||||
<script>var publicDictionary = <?php echo $the_public_dictionary; ?></script>
|
||||
<?php } else { ?>
|
||||
<title>Lexiconga Dictionary Builder</title>
|
||||
<meta property="og:url" content="http://lexicon.ga" />
|
||||
<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>
|
||||
</div>
|
||||
<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. ?>
|
||||
<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)) { ?>
|
||||
<span id="loginLink" class="clickable" onclick="ShowInfo('loginForm')">Log In/Create Account</span>
|
||||
<?php } else { ?>
|
||||
<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 = '/';});">« Edit Dictionary</span>
|
||||
<?php } else { ?>
|
||||
<a class="clickable" href="/">« Go Home to Lexiconga</a>
|
||||
<?php }?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
@ -188,11 +197,14 @@ if ($display_mode != "build") {
|
|||
<?php } ?>
|
||||
<h1 id="dictionaryName"></h1>
|
||||
|
||||
<?php if ($display_mode == "view") { ?>
|
||||
<?php if ($display_mode != "build") { ?>
|
||||
<h4 id="dictionaryBy"></h4>
|
||||
<div id="incompleteNotice"></div>
|
||||
<?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>
|
||||
<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>
|
||||
<?php } ?>
|
||||
|
||||
<div id="theDictionary">
|
||||
<?php if ($display_mode == "word") { echo "<script>document.write(DictionaryEntryTemplate(" . $the_public_word . "));</script>"; } ?>
|
||||
</div>
|
||||
<div id="theDictionary"></div>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<!-- UI Functions -->
|
||||
<script src="/js/ui.js"></script>
|
||||
<?php if ($display_mode == "view") { ?>
|
||||
<?php if ($display_mode != "build") { ?>
|
||||
<!-- Public View Functions -->
|
||||
<script src="/js/publicView.js"></script>
|
||||
<?php } ?>
|
||||
<?php if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/analytics.php"); } ?>
|
||||
<script>
|
||||
var aboutText = termsText = privacyText = loginForm = forgotForm = importForm = "Loading...";
|
||||
<?php if ($display_mode == "view") { ?>
|
||||
<?php if ($display_mode != "build") { ?>
|
||||
window.onload = function () {
|
||||
ShowPublicDictionary();
|
||||
SetPublicPartsOfSpeech();
|
||||
ShowPublicDictionary(<?php if ($display_mode == "word") echo "true"; ?>);
|
||||
<?php
|
||||
if ($display_mode != "word") { // don't try to set the filters
|
||||
echo "SetPublicPartsOfSpeech()";
|
||||
} ?>
|
||||
|
||||
GetTextFile("README.md", "aboutText", true);
|
||||
GetTextFile("TERMS.md", "termsText", true);
|
||||
GetTextFile("PRIVACY.md", "privacyText", true);
|
||||
GetTextFile("LOGIN.form", "loginForm", false);
|
||||
GetTextFile("FORGOT.form", "forgotForm", false);
|
||||
GetTextFile("IMPORT.form", "importForm", false);
|
||||
GetTextFile("/README.md", "aboutText", true);
|
||||
GetTextFile("/TERMS.md", "termsText", true);
|
||||
GetTextFile("/PRIVACY.md", "privacyText", true);
|
||||
GetTextFile("/LOGIN.form", "loginForm", false);
|
||||
GetTextFile("/FORGOT.form", "forgotForm", false);
|
||||
GetTextFile("/IMPORT.form", "importForm", false);
|
||||
}
|
||||
<?php } else { ?>
|
||||
ready(function() {
|
||||
|
|
|
@ -339,7 +339,13 @@ function DictionaryEntryTemplate(wordObject, managementIndex) {
|
|||
// If there's a managementIndex, append index number to the element id.
|
||||
entryText += managementIndex.toString();
|
||||
}
|
||||
entryText += "'><a href='#" + wordObject.wordId + "' class='wordLink clickable'>🔗</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;'>➦</a>";
|
||||
}
|
||||
|
||||
entryText += "<a href='#" + wordObject.wordId + "' class='wordLink clickable' title='Link Within Page'>🔗</a>";
|
||||
|
||||
entryText += "<word>" + wordObject.name + "</word>";
|
||||
|
||||
|
@ -613,28 +619,34 @@ function LoadDictionary() {
|
|||
function ChangeDictionary(userDictionariesSelect) {
|
||||
userDictionariesSelect = (typeof userDictionariesSelect !== 'undefined' && userDictionariesSelect != null) ? userDictionariesSelect : document.getElementById("userDictionaries");
|
||||
if (currentDictionary.externalID != userDictionariesSelect.value && userDictionariesSelect.options.length > 0) {
|
||||
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=" + userDictionariesSelect.value.toString();
|
||||
changeDictionaryRequest.onreadystatechange = function() {
|
||||
if (changeDictionaryRequest.readyState == 4 && changeDictionaryRequest.status == 200) {
|
||||
if (changeDictionaryRequest.responseText == "no dictionaries") {
|
||||
console.log(changeDictionaryRequest.responseText);
|
||||
ChangeDictionaryToId(userDictionariesSelect.value, function(response) {
|
||||
if (response == "no dictionaries") {
|
||||
console.log(response);
|
||||
SendDictionary(false);
|
||||
} else if (changeDictionaryRequest.responseText.length < 60) {
|
||||
console.log(changeDictionaryRequest.responseText);
|
||||
} else if (response.length < 60) {
|
||||
console.log(response);
|
||||
} else {
|
||||
currentDictionary = JSON.parse(changeDictionaryRequest.responseText);
|
||||
currentDictionary = JSON.parse(response);
|
||||
SaveDictionary(false);
|
||||
ProcessLoad();
|
||||
LoadUserDictionaries();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
function LoadLocalDictionary() {
|
||||
|
|
129
js/publicView.js
129
js/publicView.js
|
@ -2,18 +2,20 @@ function IsValidPublicDicitonary() {
|
|||
return typeof publicDictionary !== 'string';
|
||||
}
|
||||
|
||||
function ShowPublicDictionary() {
|
||||
function ShowPublicDictionary(ignoreFilters) {
|
||||
ignoreFilters = (typeof ignoreFilters !== 'undefined') ? ignoreFilters : false;
|
||||
|
||||
if (IsValidPublicDicitonary()) {
|
||||
var filters = GetSelectedFilters();
|
||||
var filters = (ignoreFilters) ? [] : GetSelectedFilters();
|
||||
|
||||
var searchResults = [];
|
||||
var search = htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value);
|
||||
var searchByWord = document.getElementById("searchOptionWord").checked;
|
||||
var searchBySimple = document.getElementById("searchOptionSimple").checked;
|
||||
var searchByLong = 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 searchIgnoreDiacritics = document.getElementById("searchIgnoreDiacritics").checked;
|
||||
if (search != "" && (searchByWord || searchBySimple || searchByLong)) {
|
||||
var search = (ignoreFilters) ? "" : htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value);
|
||||
var searchByWord = (ignoreFilters) ? null : document.getElementById("searchOptionWord").checked;
|
||||
var searchBySimple = (ignoreFilters) ? null : document.getElementById("searchOptionSimple").checked;
|
||||
var searchByLong = (ignoreFilters) ? null : document.getElementById("searchOptionLong").checked;
|
||||
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 = (ignoreFilters) ? null : document.getElementById("searchIgnoreDiacritics").checked;
|
||||
if (!ignoreFilters && search != "" && (searchByWord || searchBySimple || searchByLong)) {
|
||||
var xpath = [];
|
||||
var searchDictionaryJSON = htmlEntitiesParseForSearch(JSON.stringify(publicDictionary));
|
||||
if (searchIgnoreCase) {
|
||||
|
@ -65,7 +67,7 @@ function ShowPublicDictionary() {
|
|||
if (!publicDictionary.words[i].hasOwnProperty("wordId")) {
|
||||
publicDictionary.words[i].wordId = i + 1; //Account for new property
|
||||
}
|
||||
dictionaryText += PublicDictionaryEntry(i);
|
||||
dictionaryText += PublicDictionaryEntry(i, ignoreFilters);
|
||||
numberOfWordsDisplayed++;
|
||||
}
|
||||
}
|
||||
|
@ -74,70 +76,97 @@ function ShowPublicDictionary() {
|
|||
dictionaryText = "There are no entries in the dictionary."
|
||||
}
|
||||
dictionaryArea.innerHTML = dictionaryText;
|
||||
ShowFilterWordCount(numberOfWordsDisplayed);
|
||||
if (!ignoreFilters) {
|
||||
ShowFilterWordCount(numberOfWordsDisplayed);
|
||||
}
|
||||
} else {
|
||||
document.getElementById("dictionaryContainer").innerHTML = publicDictionary;
|
||||
}
|
||||
}
|
||||
|
||||
function PublicDictionaryEntry(itemIndex) {
|
||||
var entryText = "<entry><a name='" + publicDictionary.words[itemIndex].wordId + "'></a><a href='#" + publicDictionary.words[itemIndex].wordId + "' class='wordLink clickable'>🔗</a>";
|
||||
|
||||
var searchTerm = regexParseForSearch(document.getElementById("searchBox").value);
|
||||
var searchByWord = document.getElementById("searchOptionWord").checked;
|
||||
var searchBySimple = document.getElementById("searchOptionSimple").checked;
|
||||
var searchByLong = 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 searchIgnoreDiacritics = document.getElementById("searchIgnoreDiacritics").checked;
|
||||
function PublicDictionaryEntry(itemIndex, ignoreFilters) {
|
||||
var searchTerm = (ignoreFilters) ? "" : regexParseForSearch(document.getElementById("searchBox").value);
|
||||
var searchByWord = (ignoreFilters) ? false : document.getElementById("searchOptionWord").checked;
|
||||
var searchBySimple = (ignoreFilters) ? false : document.getElementById("searchOptionSimple").checked;
|
||||
var searchByLong = (ignoreFilters) ? false : document.getElementById("searchOptionLong").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 searchIgnoreDiacritics = (ignoreFilters) ? false : document.getElementById("searchIgnoreDiacritics").checked;
|
||||
|
||||
var searchRegEx = new RegExp("(" + ((searchIgnoreDiacritics) ? removeDiacritics(searchTerm) + "|" + searchTerm : searchTerm) + ")", "g" + ((searchIgnoreCase) ? "i" : ""));
|
||||
|
||||
entryText += "<word>";
|
||||
var wordName = wordPronunciation = wordPartOfSpeech = wordSimpleDefinition = wordLongDefinition = "";
|
||||
|
||||
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 {
|
||||
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 != "") {
|
||||
entryText += "<pronunciation>";
|
||||
entryText += marked(htmlEntitiesParse(publicDictionary.words[itemIndex].pronunciation)).replace("<p>","").replace("</p>","");
|
||||
entryText += "</pronunciation>";
|
||||
wordPronunciation += marked(htmlEntitiesParse(publicDictionary.words[itemIndex].pronunciation)).replace("<p>","").replace("</p>","");
|
||||
}
|
||||
|
||||
if (publicDictionary.words[itemIndex].partOfSpeech != "") {
|
||||
entryText += "<partofspeech>";
|
||||
entryText += publicDictionary.words[itemIndex].partOfSpeech;
|
||||
entryText += "</partofspeech>";
|
||||
wordPartOfSpeech += publicDictionary.words[itemIndex].partOfSpeech.toString();
|
||||
}
|
||||
|
||||
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'>➦</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 (publicDictionary.words[itemIndex].simpleDefinition != "") {
|
||||
entryText += "<simpledefinition>";
|
||||
|
||||
if (searchTerm != "" && searchBySimple) {
|
||||
entryText += htmlEntitiesParse(publicDictionary.words[itemIndex].simpleDefinition).replace(searchRegEx, "<searchTerm>$1</searchterm>");
|
||||
} else {
|
||||
entryText += publicDictionary.words[itemIndex].simpleDefinition;
|
||||
}
|
||||
|
||||
entryText += "</simpledefinition>";
|
||||
if (wordObject.simpleDefinition != "") {
|
||||
entryText += "<simpledefinition>" + wordObject.simpleDefinition + "</simpledefinition>";
|
||||
}
|
||||
|
||||
if (publicDictionary.words[itemIndex].longDefinition != "") {
|
||||
entryText += "<longdefinition>";
|
||||
if (wordObject.longDefinition != "") {
|
||||
entryText += "<longdefinition>" + wordObject.longDefinition + "</longdefinition>";
|
||||
}
|
||||
|
||||
if (searchTerm != "" && searchByLong) {
|
||||
entryText += marked(htmlEntitiesParse(publicDictionary.words[itemIndex].longDefinition).replace(searchRegEx, "<searchTerm>$1</searchterm>"));
|
||||
} else {
|
||||
entryText += marked(htmlEntitiesParse(publicDictionary.words[itemIndex].longDefinition));
|
||||
}
|
||||
|
||||
entryText += "</longdefinition>";
|
||||
if (managementIndex !== false) {
|
||||
entryText += ManagementArea(managementIndex);
|
||||
}
|
||||
|
||||
entryText += "</entry>";
|
||||
|
|
Loading…
Reference in New Issue