Skip to content

Commit a709c66

Browse files
committed
Initial commit
1 parent 32ae2b4 commit a709c66

22 files changed

+1363
-377
lines changed
Binary file not shown.

classes/citation/.project/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://tug.ctan.org/info/biblatex-cheatsheet/biblatex-cheatsheet.pdf

classes/citation/Citation.php

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
/**
88
* @file classes/citation/Citation.php
99
*
10-
* Copyright (c) 2014-2021 Simon Fraser University
11-
* Copyright (c) 2000-2021 John Willinsky
10+
* Copyright (c) 2014-2024 Simon Fraser University
11+
* Copyright (c) 2000-2024 John Willinsky
1212
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
1313
*
1414
* @class Citation
@@ -20,97 +20,86 @@
2020

2121
namespace PKP\citation;
2222

23-
class Citation extends \PKP\core\DataObject
23+
use PKP\core\DataObject;
24+
25+
class Citation extends DataObject
2426
{
2527
/**
2628
* Constructor.
2729
*
28-
* @param string $rawCitation an unparsed citation string
30+
* @param string|null $rawCitation an unparsed citation string
2931
*/
30-
public function __construct($rawCitation = null)
32+
public function __construct(string $rawCitation = null)
3133
{
3234
parent::__construct();
3335
$this->setRawCitation($rawCitation);
3436
}
3537

36-
//
37-
// Getters and Setters
38-
//
39-
4038
/**
41-
* Replace URLs through HTML links, if the citation does not already contain HTML links
42-
*
43-
* @return string
39+
* Get publication id.
4440
*/
45-
public function getCitationWithLinks()
41+
public function getPublicationId()
4642
{
47-
$citation = $this->getRawCitation();
48-
if (stripos($citation, '<a href=') === false) {
49-
$citation = preg_replace_callback(
50-
'#(http|https|ftp)://[\d\w\.-]+\.[\w\.]{2,6}[^\s\]\[\<\>]*/?#',
51-
function ($matches) {
52-
$trailingDot = in_array($char = substr($matches[0], -1), ['.', ',']);
53-
$url = rtrim($matches[0], '.,');
54-
return "<a href=\"{$url}\">{$url}</a>" . ($trailingDot ? $char : '');
55-
},
56-
$citation
57-
);
58-
}
59-
return $citation;
43+
return $this->getData('publicationId');
6044
}
6145

6246
/**
63-
* Get the rawCitation
64-
*
65-
* @return string
47+
* Get the rawCitation.
6648
*/
67-
public function getRawCitation()
49+
public function getRawCitation(): string
6850
{
6951
return $this->getData('rawCitation');
7052
}
7153

7254
/**
73-
* Set the rawCitation
74-
*
75-
* @param string $rawCitation
55+
* Set the rawCitation.
7656
*/
77-
public function setRawCitation($rawCitation)
57+
public function setRawCitation(string $rawCitation = null): void
7858
{
79-
$rawCitation = $this->_cleanCitationString($rawCitation);
59+
$rawCitation = $this->cleanCitationString($rawCitation);
8060
$this->setData('rawCitation', $rawCitation);
8161
}
8262

8363
/**
84-
* Get the sequence number
85-
*
86-
* @return int
64+
* Get the sequence number.
8765
*/
88-
public function getSequence()
66+
public function getSequence(): int
8967
{
9068
return $this->getData('seq');
9169
}
9270

9371
/**
94-
* Set the sequence number
95-
*
96-
* @param int $seq
72+
* Set the sequence number.
9773
*/
98-
public function setSequence($seq)
74+
public function setSequence(int $seq): void
9975
{
10076
$this->setData('seq', $seq);
10177
}
10278

103-
//
104-
// Private methods
105-
//
10679
/**
107-
* Take a citation string and clean/normalize it
108-
*
109-
* @param string $citationString
110-
*
111-
* @return string
80+
* Replace URLs through HTML links, if the citation does not already contain HTML links.
81+
*/
82+
public function getCitationWithLinks(): string
83+
{
84+
$citation = $this->getRawCitation();
85+
if (stripos($citation, '<a href=') === false) {
86+
$citation = preg_replace_callback(
87+
'#(http|https|ftp)://[\d\w\.-]+\.[\w\.]{2,6}[^\s\]\[\<\>]*/?#',
88+
function ($matches) {
89+
$trailingDot = in_array($char = substr($matches[0], -1), ['.', ',']);
90+
$url = rtrim($matches[0], '.,');
91+
return "<a href=\"{$url}\">{$url}</a>" . ($trailingDot ? $char : '');
92+
},
93+
$citation
94+
);
95+
}
96+
return $citation;
97+
}
98+
99+
/**
100+
* Take a citation string and clean/normalize it.
112101
*/
113-
public function _cleanCitationString($citationString)
102+
public function cleanCitationString(string $citationString = null): string
114103
{
115104
// 1) Strip slashes and whitespace
116105
$citationString = trim(stripslashes($citationString));

0 commit comments

Comments
 (0)