Make word references link to hash unless individual

This commit is contained in:
Robbie Antenesse 2020-05-07 23:20:47 -06:00
parent a30bdf5d63
commit 8f6dad8a84
1 changed files with 7 additions and 5 deletions

View File

@ -86,7 +86,7 @@ class PublicDictionary {
'pronunciation' => $row['pronunciation'], 'pronunciation' => $row['pronunciation'],
'partOfSpeech' => $row['part_of_speech'], 'partOfSpeech' => $row['part_of_speech'],
'definition' => $row['definition'], 'definition' => $row['definition'],
'details' => $this->parseReferences(strip_tags($row['details']), $dictionary), 'details' => $this->parseReferences(strip_tags($row['details']), $dictionary, false),
'lastUpdated' => is_null($row['last_updated']) ? intval($row['created_on']) : intval($row['last_updated']), 'lastUpdated' => is_null($row['last_updated']) ? intval($row['created_on']) : intval($row['last_updated']),
'createdOn' => intval($row['created_on']), 'createdOn' => intval($row['created_on']),
'wordId' => intval($row['word_id']), 'wordId' => intval($row['word_id']),
@ -95,7 +95,7 @@ class PublicDictionary {
if (!is_null($row['etymology'])) { if (!is_null($row['etymology'])) {
if (strlen($row['etymology']) > 0) { if (strlen($row['etymology']) > 0) {
$word['etymology'] = array_map(function ($root) use($dictionary) { $word['etymology'] = array_map(function ($root) use($dictionary) {
return $this->getWordReferenceHTML(strip_tags($root), $dictionary); return $this->getWordReferenceHTML(strip_tags($root), $dictionary, false);
}, explode(',', $row['etymology'])); }, explode(',', $row['etymology']));
} }
} }
@ -103,7 +103,7 @@ class PublicDictionary {
if (!is_null($row['related'])) { if (!is_null($row['related'])) {
if (strlen($row['related']) > 0) { if (strlen($row['related']) > 0) {
$word['related'] = array_map(function ($root) use($dictionary) { $word['related'] = array_map(function ($root) use($dictionary) {
return $this->getWordReferenceHTML(strip_tags($root), $dictionary); return $this->getWordReferenceHTML(strip_tags($root), $dictionary, false);
}, explode(',', $row['related'])); }, explode(',', $row['related']));
} }
} }
@ -235,7 +235,7 @@ WHERE words.dictionary=? AND is_public=1";
return $details; return $details;
} }
private function getWordReferenceHTML($reference, $dictionary_id) { private function getWordReferenceHTML($reference, $dictionary_id, $direct_link = true) {
$word_to_find = preg_replace('/\{\{|\}\}/', '', $reference); $word_to_find = preg_replace('/\{\{|\}\}/', '', $reference);
$homonymn = 0; $homonymn = 0;
@ -268,7 +268,9 @@ WHERE words.dictionary=? AND is_public=1";
} }
$homonymn_sub_html = count($reference_ids) > 1 && $homonymn - 1 >= 0 ? '<sub>' . $homonymn . '</sub>' : ''; $homonymn_sub_html = count($reference_ids) > 1 && $homonymn - 1 >= 0 ? '<sub>' . $homonymn . '</sub>' : '';
$site_root = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], $dictionary_id)); $site_root = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], $dictionary_id));
return '<span class="word-reference"><a href="' . $site_root . $dictionary_id . '/' . $target_id .'" target="_blank" title="Link to Reference">' return '<span class="word-reference"><a href="'
. ($direct_link ? $site_root . $dictionary_id . '/' : '#') . $target_id .'" '
. ($direct_link ? 'target="_blank" ' : '') . 'title="Link to Reference">'
. '<span class="orthographic-translation">' . $this->translateOrthography($word_to_find, $dictionary_id) . '</span>' . $homonymn_sub_html . '<span class="orthographic-translation">' . $this->translateOrthography($word_to_find, $dictionary_id) . '</span>' . $homonymn_sub_html
. '</a></span>'; . '</a></span>';
} }