Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/includes/TextTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,14 @@ function tidy_date_inside(string $string): string {
}
// Google sends ranges
if (preg_match('~^(\d{4})(\-\d{2}\-\d{2})\s+\-\s+(\d{4})(\-\d{2}\-\d{2})$~', $string, $matches)) { // Date range
if ($matches[1] === $matches[3]) {
return date('j F', strtotime($matches[1] . $matches[2])) . ' – ' . date('j F Y', strtotime($matches[3] . $matches[4]));
} else {
return date('j F Y', strtotime($matches[1] . $matches[2])) . ' – ' . date('j F Y', strtotime($matches[3] . $matches[4]));
$start_ts = strtotime($matches[1] . $matches[2]);
$end_ts = strtotime($matches[3] . $matches[4]);
if ($start_ts !== false && $end_ts !== false) {
if ($matches[1] === $matches[3]) {
return date('j F', $start_ts) . ' – ' . date('j F Y', $end_ts);
} else {
return date('j F Y', $start_ts) . ' – ' . date('j F Y', $end_ts);
}
}
}
// Huge amount of character cleaning
Expand Down
10 changes: 7 additions & 3 deletions src/includes/URLtools.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,11 @@ function url_simplify(string $url): string {
$url = str_replace(['/abstract/', '/full/', '/full+pdf/', '/pdf/', '/document/', '/html/', '/html+pdf/', '/abs/', '/epdf/', '/doi/', '/xprint/', '/print/', '.short', '.long', '.abstract', '.full', '///', '//'],
['/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/'], $url);
$url = mb_substr($url, 0, -1); // Remove the ending slash we added
$url = (string) preg_split("~[\?\#]~", $url, 2)[0];
$url_parts = preg_split("~[\?\#]~", $url, 2);
if ($url_parts === false) {
return $url; // @codeCoverageIgnore
}
$url = $url_parts[0];
return str_ireplace('https', 'http', $url);
}

Expand Down Expand Up @@ -1694,9 +1698,9 @@ function find_identifiers_in_urls_INSIDE(Template $template, string $url, string
if ($template->blank('pmc')) {
report_modification("Converting URL to PMC parameter");
}
$new_pmc = (string) @$match[1] . @$match[2] . @$match[3];
$new_pmc = $match[1] . ($match[2] ?? '') . ($match[3] ?? '');
// php stan does not understand that this could because of the insanity of regex and 8-bit characters and PHP bugs end up being empty
if ($new_pmc === '') { // @phpstan-ignore-line
if ($new_pmc === '') {
bot_debug_log("PMC oops");
return false;
}
Expand Down
Loading