|
7 | 7 | /**
|
8 | 8 | * @file classes/citation/Citation.php
|
9 | 9 | *
|
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 |
12 | 12 | * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
13 | 13 | *
|
14 | 14 | * @class Citation
|
|
20 | 20 |
|
21 | 21 | namespace PKP\citation;
|
22 | 22 |
|
23 |
| -class Citation extends \PKP\core\DataObject |
| 23 | +use PKP\core\DataObject; |
| 24 | + |
| 25 | +class Citation extends DataObject |
24 | 26 | {
|
25 | 27 | /**
|
26 | 28 | * Constructor.
|
27 | 29 | *
|
28 |
| - * @param string $rawCitation an unparsed citation string |
| 30 | + * @param string|null $rawCitation an unparsed citation string |
29 | 31 | */
|
30 |
| - public function __construct($rawCitation = null) |
| 32 | + public function __construct(string $rawCitation = null) |
31 | 33 | {
|
32 | 34 | parent::__construct();
|
33 | 35 | $this->setRawCitation($rawCitation);
|
34 | 36 | }
|
35 | 37 |
|
36 |
| - // |
37 |
| - // Getters and Setters |
38 |
| - // |
39 |
| - |
40 | 38 | /**
|
41 |
| - * Replace URLs through HTML links, if the citation does not already contain HTML links |
42 |
| - * |
43 |
| - * @return string |
| 39 | + * Get publication id. |
44 | 40 | */
|
45 |
| - public function getCitationWithLinks() |
| 41 | + public function getPublicationId() |
46 | 42 | {
|
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'); |
60 | 44 | }
|
61 | 45 |
|
62 | 46 | /**
|
63 |
| - * Get the rawCitation |
64 |
| - * |
65 |
| - * @return string |
| 47 | + * Get the rawCitation. |
66 | 48 | */
|
67 |
| - public function getRawCitation() |
| 49 | + public function getRawCitation(): string |
68 | 50 | {
|
69 | 51 | return $this->getData('rawCitation');
|
70 | 52 | }
|
71 | 53 |
|
72 | 54 | /**
|
73 |
| - * Set the rawCitation |
74 |
| - * |
75 |
| - * @param string $rawCitation |
| 55 | + * Set the rawCitation. |
76 | 56 | */
|
77 |
| - public function setRawCitation($rawCitation) |
| 57 | + public function setRawCitation(string $rawCitation = null): void |
78 | 58 | {
|
79 |
| - $rawCitation = $this->_cleanCitationString($rawCitation); |
| 59 | + $rawCitation = $this->cleanCitationString($rawCitation); |
80 | 60 | $this->setData('rawCitation', $rawCitation);
|
81 | 61 | }
|
82 | 62 |
|
83 | 63 | /**
|
84 |
| - * Get the sequence number |
85 |
| - * |
86 |
| - * @return int |
| 64 | + * Get the sequence number. |
87 | 65 | */
|
88 |
| - public function getSequence() |
| 66 | + public function getSequence(): int |
89 | 67 | {
|
90 | 68 | return $this->getData('seq');
|
91 | 69 | }
|
92 | 70 |
|
93 | 71 | /**
|
94 |
| - * Set the sequence number |
95 |
| - * |
96 |
| - * @param int $seq |
| 72 | + * Set the sequence number. |
97 | 73 | */
|
98 |
| - public function setSequence($seq) |
| 74 | + public function setSequence(int $seq): void |
99 | 75 | {
|
100 | 76 | $this->setData('seq', $seq);
|
101 | 77 | }
|
102 | 78 |
|
103 |
| - // |
104 |
| - // Private methods |
105 |
| - // |
106 | 79 | /**
|
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. |
112 | 101 | */
|
113 |
| - public function _cleanCitationString($citationString) |
| 102 | + public function cleanCitationString(string $citationString = null): string |
114 | 103 | {
|
115 | 104 | // 1) Strip slashes and whitespace
|
116 | 105 | $citationString = trim(stripslashes($citationString));
|
|
0 commit comments