Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
GaziYucel committed Nov 28, 2024
1 parent 32ae2b4 commit a709c66
Show file tree
Hide file tree
Showing 22 changed files with 1,363 additions and 377 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions classes/citation/.project/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://tug.ctan.org/info/biblatex-cheatsheet/biblatex-cheatsheet.pdf
93 changes: 41 additions & 52 deletions classes/citation/Citation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/**
* @file classes/citation/Citation.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2000-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class Citation
Expand All @@ -20,97 +20,86 @@

namespace PKP\citation;

class Citation extends \PKP\core\DataObject
use PKP\core\DataObject;

class Citation extends DataObject
{
/**
* Constructor.
*
* @param string $rawCitation an unparsed citation string
* @param string|null $rawCitation an unparsed citation string
*/
public function __construct($rawCitation = null)
public function __construct(string $rawCitation = null)
{
parent::__construct();
$this->setRawCitation($rawCitation);
}

//
// Getters and Setters
//

/**
* Replace URLs through HTML links, if the citation does not already contain HTML links
*
* @return string
* Get publication id.
*/
public function getCitationWithLinks()
public function getPublicationId()
{
$citation = $this->getRawCitation();
if (stripos($citation, '<a href=') === false) {
$citation = preg_replace_callback(
'#(http|https|ftp)://[\d\w\.-]+\.[\w\.]{2,6}[^\s\]\[\<\>]*/?#',
function ($matches) {
$trailingDot = in_array($char = substr($matches[0], -1), ['.', ',']);
$url = rtrim($matches[0], '.,');
return "<a href=\"{$url}\">{$url}</a>" . ($trailingDot ? $char : '');
},
$citation
);
}
return $citation;
return $this->getData('publicationId');
}

/**
* Get the rawCitation
*
* @return string
* Get the rawCitation.
*/
public function getRawCitation()
public function getRawCitation(): string
{
return $this->getData('rawCitation');
}

/**
* Set the rawCitation
*
* @param string $rawCitation
* Set the rawCitation.
*/
public function setRawCitation($rawCitation)
public function setRawCitation(string $rawCitation = null): void
{
$rawCitation = $this->_cleanCitationString($rawCitation);
$rawCitation = $this->cleanCitationString($rawCitation);
$this->setData('rawCitation', $rawCitation);
}

/**
* Get the sequence number
*
* @return int
* Get the sequence number.
*/
public function getSequence()
public function getSequence(): int
{
return $this->getData('seq');
}

/**
* Set the sequence number
*
* @param int $seq
* Set the sequence number.
*/
public function setSequence($seq)
public function setSequence(int $seq): void
{
$this->setData('seq', $seq);
}

//
// Private methods
//
/**
* Take a citation string and clean/normalize it
*
* @param string $citationString
*
* @return string
* Replace URLs through HTML links, if the citation does not already contain HTML links.
*/
public function getCitationWithLinks(): string
{
$citation = $this->getRawCitation();
if (stripos($citation, '<a href=') === false) {
$citation = preg_replace_callback(
'#(http|https|ftp)://[\d\w\.-]+\.[\w\.]{2,6}[^\s\]\[\<\>]*/?#',
function ($matches) {
$trailingDot = in_array($char = substr($matches[0], -1), ['.', ',']);
$url = rtrim($matches[0], '.,');
return "<a href=\"{$url}\">{$url}</a>" . ($trailingDot ? $char : '');
},
$citation
);
}
return $citation;
}

/**
* Take a citation string and clean/normalize it.
*/
public function _cleanCitationString($citationString)
public function cleanCitationString(string $citationString = null): string
{
// 1) Strip slashes and whitespace
$citationString = trim(stripslashes($citationString));
Expand Down
Loading

0 comments on commit a709c66

Please sign in to comment.