Skip to content

Commit

Permalink
Merge pull request #563 from GlazerMann/patch-41
Browse files Browse the repository at this point in the history
uppercase for constants
  • Loading branch information
Martin R. Smith committed Aug 16, 2018
2 parents 973e3df + ae9054e commit 282ecef
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Template {
$citation_template, $mod_dashes;

public function parse_text($text) {
$this->initial_author_params = null; // Will be populated later if there are any
$this->initial_author_params = NULL; // Will be populated later if there are any
if ($this->rawtext) {
warning("Template already initialized; call new Template() before calling Template::parse_text()");
}
Expand Down Expand Up @@ -98,7 +98,7 @@ public function process() {
$this->process();
} elseif ($this->has('arxiv')) {
$this->name = 'Cite arxiv';
$this->rename('arxiv','eprint');
$this->rename('arxiv', 'eprint');
$this->process();
} elseif ($this->has('eprint')) {
$this->name = 'Cite arxiv';
Expand Down Expand Up @@ -337,7 +337,7 @@ public function add_if_new($param_name, $value) {
$this->add('last' . (substr($param_name, -1) == '1' ? '1' : ''), sanitize_string(format_Surname($au[0])));
return $this->add_if_new('first' . (substr($param_name, -1) == '1' ? '1' : ''), sanitize_string(format_forename(trim($au[1]))));
} else {
return $this->add($param_name,sanitize_string($value));
return $this->add($param_name, sanitize_string($value));
}
}
return FALSE;
Expand All @@ -351,7 +351,7 @@ public function add_if_new($param_name, $value) {
$value = str_replace(array(",;", " and;", " and ", " ;", " ", "+", "*"), array(";", ";", " ", ";", " ", "", ""), $value);

if ($this->blank("last2") && $this->blank("coauthor") && $this->blank("coauthors") && $this->blank("author"))
return $this->add($param_name,sanitize_string($value));
return $this->add($param_name, sanitize_string($value));
// Note; we shouldn't be using this parameter ever....
return FALSE;
case "last2": case "last3": case "last4": case "last5": case "last6": case "last7": case "last8": case "last9":
Expand Down Expand Up @@ -390,7 +390,7 @@ public function add_if_new($param_name, $value) {
$this->add('last' . $auNo, format_surname($au[0]));
return $this->add_if_new('first' . $auNo, format_forename(trim($au[1])));
} else {
return $this->add($param_name,sanitize_string($value));
return $this->add($param_name, sanitize_string($value));
}
}
return FALSE;
Expand All @@ -409,7 +409,7 @@ public function add_if_new($param_name, $value) {
if ($this->blank($param_name)
&& under_two_authors($this->get('author')) && $this->blank("author" . $auNo)
&& $this->blank("coauthor") && $this->blank("coauthors")) {
return $this->add($param_name,sanitize_string($value));
return $this->add($param_name, sanitize_string($value));
}
return FALSE;

Expand Down Expand Up @@ -506,8 +506,8 @@ public function add_if_new($param_name, $value) {
case 'volume':
if ($this->blank($param_name)) {
$temp_string = strtolower($this->get('journal')) ;
if(substr($temp_string,0,2) === "[[" && substr($temp_string,-2) === "]]") { // Wikilinked journal title
$temp_string = substr(substr($temp_string,2),0,-2); // Remove [[ and ]]
if(substr($temp_string, 0, 2) === "[[" && substr($temp_string, -2) === "]]") { // Wikilinked journal title
$temp_string = substr(substr($temp_string, 2), 0, -2); // Remove [[ and ]]
}
if (in_array($temp_string, HAS_NO_VOLUME) === TRUE ) {
// This journal has no volume. This is really the issue number
Expand Down Expand Up @@ -1230,9 +1230,9 @@ protected function expand_by_adsabs() {
}
if (isset($record->identifier)) { // Sometimes arXiv is in journal (see above), sometimes here in identifier
foreach ($record->identifier as $recid) {
if(strtolower(substr($recid,0,6)) === 'arxiv:') {
if(strtolower(substr($recid, 0, 6)) === 'arxiv:') {
if (isset($record->arxivclass)) $this->add_if_new("class", $record->arxivclass);
if ($this->add_if_new("arxiv", substr($recid,6))) $this->expand_by_arxiv();
if ($this->add_if_new("arxiv", substr($recid, 6))) $this->expand_by_arxiv();
}
}
}
Expand Down Expand Up @@ -1414,7 +1414,7 @@ protected function expand_by_jstor() {
echo "\n JSTOR API returned nothing for JSTOR ". $jstor . "\n";
return FALSE;
}
if (stripos($dat, 'No RIS data found for') !== false) {
if (stripos($dat, 'No RIS data found for') !== FALSE) {
echo "\n JSTOR API found nothing for JSTOR ". $jstor . "\n";
return FALSE;
}
Expand Down Expand Up @@ -1538,7 +1538,7 @@ protected function expand_by_jstor_citoid() {
echo "\n Citoid API returned nothing for JSTOR ". $jstor . "\n";
return FALSE;
}
$data = @json_decode($json,false);
$data = @json_decode($json, FALSE);
if (!isset($data) || !isset($data[0]) || !isset($data[0]->{'title'})) {
echo "\n Citoid API returned invalid json for JSTOR ". $jstor . "\n";
return FALSE;
Expand All @@ -1548,7 +1548,7 @@ protected function expand_by_jstor_citoid() {
return FALSE;
}
// Verify that Citoid did not think that this was a website and not a journal
if (strtolower(substr(trim($data[0]->{'title'}),-9)) === ' on jstor') {
if (strtolower(substr(trim($data[0]->{'title'}), -9)) === ' on jstor') {
$this->add_if_new('title', substr(trim($data[0]->{'title'}), 0, -9)); // Add the title without " on jstor"
return FALSE; // Not really "expanded"
}
Expand Down Expand Up @@ -1594,7 +1594,7 @@ protected function expand_by_pubmed($force = FALSE) {
$this->add_if_new('doi', $match[0]);
}
switch ($item["Name"]) {
case "Title": $this->add_if_new('title', str_replace(array("[", "]"), "",(string) $item)); // add_if_new will format the title
case "Title": $this->add_if_new('title', str_replace(array("[", "]"), "", (string) $item)); // add_if_new will format the title
break; case "PubDate": preg_match("~(\d+)\s*(\w*)~", $item, $match);
$this->add_if_new('year', (string) $match[1]);
break; case "FullJournalName": $this->add_if_new('journal', ucwords((string) $item)); // add_if_new will format the title
Expand Down Expand Up @@ -1782,12 +1782,12 @@ protected function expand_by_google_books() {
$lccn= $this->get('lccn');
$oclc= $this->get('oclc');
if ($isbn) {
$isbn = str_replace(array(" ","-"), "", $isbn);
$isbn = str_replace(array(" ", "-"), "", $isbn);
if (preg_match("~[^0-9Xx]~", $isbn) === 1) $isbn='' ;
if (strlen($isbn) !== 13 && strlen($isbn) !== 10) $isbn='' ;
}
if ($lccn) {
$lccn = str_replace(array(" ","-"), "", $lccn);
$lccn = str_replace(array(" ", "-"), "", $lccn);
if (preg_match("~[^0-9]~", $lccn) === 1) $lccn='' ;
}
if ($oclc) {
Expand All @@ -1802,7 +1802,7 @@ protected function expand_by_google_books() {
$google_results = array_unique($google_results);
if (count($google_results) === 1) {
$google_results = $google_results[0];
$gid = substr($google_results,26,-4);
$gid = substr($google_results, 26, -4);
$url = 'https://books.google.com/books?id=' . $gid;
// if ($this->blank('url')) $this->add('url', $url); // This pissed off a lot of people. And blank url does not mean not linked in title, etc.
$google_books_worked = TRUE;
Expand All @@ -1824,7 +1824,7 @@ protected function expand_by_google_books() {
echo "\n Google APIs search failed for $url_token \n";
return FALSE;
}
$result = @json_decode($string, false);
$result = @json_decode($string, FALSE);
if (isset($result) && isset($result->totalItems) && $result->totalItems === 1 && isset($result->items[0]) && isset($result->items[0]->id) ) {
$gid=$result->items[0]->id;
$url = 'https://books.google.com/books?id=' . $gid;
Expand Down Expand Up @@ -1903,8 +1903,8 @@ protected function google_book_details ($gid) {
if( in_array(strtolower($author), BAD_AUTHORS) === FALSE) {
$author_parts = explode(" ", $author);
$author_ending = end($author_parts);
if( in_array(strtolower($author), AUTHORS_ARE_PUBLISHERS ) === TRUE ||
in_array(strtolower($author_ending),AUTHORS_ARE_PUBLISHERS_ENDINGS) === TRUE) {
if( in_array(strtolower($author), AUTHORS_ARE_PUBLISHERS ) === TRUE ||
in_array(strtolower($author_ending), AUTHORS_ARE_PUBLISHERS_ENDINGS) === TRUE) {
$this->add_if_new("publisher" , (str_replace("___", ":", $author)));
} else {
$this->add_if_new("author" . ++$i, format_author(str_replace("___", ":", $author)));
Expand All @@ -1916,7 +1916,7 @@ protected function google_book_details ($gid) {
if (substr_count($google_date, "-") === 1) {
$date=@date_create($google_date);
if ($date !== FALSE) {
$date = @date_format($date,"F Y");
$date = @date_format($date, "F Y");
if ($date !== FALSE) {
$google_date = $date; // only now change data
}
Expand Down Expand Up @@ -2175,7 +2175,7 @@ protected function use_unnamed_params() {
$this->param[$param_key]->val = implode(" ", $pAll);
$param_recycled = TRUE;
} else {
$this->add($p1,implode(" ", $pAll));
$this->add($p1, implode(" ", $pAll));
}
}
break;
Expand All @@ -2187,7 +2187,7 @@ protected function use_unnamed_params() {
$this->param[$param_key]->val = implode(" ", $pAll);
$param_recycled = TRUE;
} else {
$this->add('issue',implode(" ", $pAll));
$this->add('issue', implode(" ", $pAll));
}
}
break;
Expand All @@ -2199,7 +2199,7 @@ protected function use_unnamed_params() {
$this->param[$param_key]->val = implode(" ", $pAll);
$param_recycled = TRUE;
} else {
$this->add('accessdate',implode(" ", $pAll));
$this->add('accessdate', implode(" ", $pAll));
}
}
break;
Expand Down Expand Up @@ -2502,8 +2502,8 @@ function($matches) {return $matches[4];},
break;
} elseif(mb_substr($p->val, 0, 2) !== "[[" ||
mb_substr($p->val, -2) !== "]]" ||
mb_substr_count($p->val,'[[') !== 1 ||
mb_substr_count($p->val,']]') !== 1) { // Only remove partial wikilinks
mb_substr_count($p->val, '[[') !== 1 ||
mb_substr_count($p->val, ']]') !== 1) { // Only remove partial wikilinks
$p->val = preg_replace_callback( // Convert [[X]] wikilinks into X
"~(\[\[)([^|]+?)(\]\])~",
function($matches) {return $matches[2];},
Expand Down Expand Up @@ -2930,7 +2930,7 @@ protected function forget ($par) {
}
$pos = $this->get_param_key($par);
if ($pos !== NULL) {
if ($this->has($par) && strpos($par,'CITATION_BOT_PLACEHOLDER') === FALSE) echo "\n - Dropping parameter " . echoable($par) . tag(); // Do not mention forgetting empty parameters
if ($this->has($par) && strpos($par, 'CITATION_BOT_PLACEHOLDER') === FALSE) echo "\n - Dropping parameter " . echoable($par) . tag(); // Do not mention forgetting empty parameters
unset($this->param[$pos]);
}
}
Expand Down Expand Up @@ -2986,19 +2986,19 @@ public function is_modified () {

protected function isbn10Toisbn13 ($isbn10) {
$isbn10 = trim($isbn10); // Remove leading and trailing spaces
$isbn10 = str_replace(array('—','?','–','-','?'),'-', $isbn10); // Standardize dahses : en dash, horizontal bar, em dash, minus sign, figure dash, to hyphen.
$isbn10 = str_replace(array('—', '?', '–', '-', '?'), '-', $isbn10); // Standardize dahses : en dash, horizontal bar, em dash, minus sign, figure dash, to hyphen.
if (preg_match("~[^0-9Xx\-]~", $isbn10) === 1) return $isbn10; // Contains invalid characters
if (substr($isbn10, -1) === "-" || substr($isbn10,0,1) === "-") return $isbn10; // Ends or starts with a dash
if (substr($isbn10, -1) === "-" || substr($isbn10, 0, 1) === "-") return $isbn10; // Ends or starts with a dash
$isbn13 = str_replace('-', '', $isbn10); // Remove dashes to do math
if (strlen($isbn13) !== 10) return $isbn10; // Might be an ISBN 13 already, or rubbish
$isbn13 = '978' . substr($isbn13,0,-1); // Convert without check digit - do not need and might be X
$isbn13 = '978' . substr($isbn13, 0, -1); // Convert without check digit - do not need and might be X
if (preg_match("~[^0123456789]~", $isbn13) === 1) return $isbn10; // Not just numbers
$sum = 0;
for ($count=0; $count<12; $count++ ) {
$sum = $sum + $isbn13[$count]*($count%2?3:1); // Depending upon even or odd, we multiply by 3 or 1 (strange but true)
}
$sum = ((10-$sum%10)%10) ;
$isbn13 = '978' . '-' . substr($isbn10,0,-1) . (string) $sum; // Assume existing dashes (if any) are right
$isbn13 = '978' . '-' . substr($isbn10, 0, -1) . (string) $sum; // Assume existing dashes (if any) are right
return $isbn13;
}
}

0 comments on commit 282ecef

Please sign in to comment.