Skip to content

Commit

Permalink
fix: Prevent abbreviation from displaying if replace fails
Browse files Browse the repository at this point in the history
Placeholder replacements failed if placeholders in text were altered during text
manipulation.
  • Loading branch information
AlexanderBlanchardAC committed Dec 2, 2024
1 parent e0bfc4d commit 772ec43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions code/web/interface/themes/responsive/Citation/harvard.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{if !empty($citeDetails.authors)}{$citeDetails.authors|escape} {/if}
{if !empty($citeDetails.year)}({$citeDetails.year|escape}). {/if}
<span style="font-style:italic;">{$citeDetails.title|escape}</span>
{if !empty($citeDetails.edition)} {$citeDetails.edition|escape} {/if}
{if !empty($citeDetails.publisher)}{$citeDetails.publisher|escape}. {/if}
{if !empty($harvardDetails.authors)}{$harvardDetails.authors|escape} {/if}
{if !empty($harvardDetails.year)}({$harvardDetails.year|escape}). {/if}
<span style="font-style:italic;">{$harvardDetails.title|escape}</span>
{if !empty($harvardDetails.edition)} {$harvardDetails.edition|escape} {/if}
{if !empty($harvardDetails.publisher)}{$harvardDetails.publisher|escape}. {/if}
6 changes: 3 additions & 3 deletions code/web/sys/CitationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function getHarvard() {
'year' => $this->getHarvardYear(),
'edition' => $this->getHarvardEdition(),
];
$interface->assign('citeDetails', $harvard);
$interface->assign('harvardDetails', $harvard);
return 'Citation/harvard.tpl';
}

Expand Down Expand Up @@ -390,13 +390,14 @@ private function capitalizeTitle($str) {
* @return string
*/
private function convertToSentenceCase($text) {

$abbreviations = [];

//Regex pattern to match common exceptions e.g. "R&B" and "USA"
$pattern = '/\b[A-Z&]+\b/';
//Generate placeholders for abbreviations that match the pattern
$text = preg_replace_callback($pattern, function($matches) use (&$abbreviations) {
$placeholder = uniqid('abbr_', true);
$placeholder = '[[abbr_' . count($abbreviations) . ']]';
$abbreviations[$placeholder] = $matches[0];
//Replace abbreviation with placeholder
return $placeholder;
Expand Down Expand Up @@ -428,7 +429,6 @@ private function getAPATitle() {
/*if (!((substr($title, -1) == '?') || (substr($title, -1) == '!'))) {
$title .= '.';
}*/

return $title;
}

Expand Down

0 comments on commit 772ec43

Please sign in to comment.