|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
|
|
|
|
|
3
|
|
|
* citeproc-php |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
|
6
|
|
|
* @copyright Copyright (c) 2017 Sebastian Böttger. |
|
7
|
|
|
* @license https://opensource.org/licenses/MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Seboettg\CiteProc\Styles; |
|
11
|
|
|
use Seboettg\CiteProc\CiteProc; |
|
12
|
|
|
use Seboettg\CiteProc\Util\StringHelper; |
|
13
|
|
|
use SimpleXMLElement; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Trait QuotesTrait |
|
17
|
|
|
* |
|
18
|
|
|
* The quotes attribute may set on cs:text. When set to “true” (“false” is default), the rendered text is wrapped in |
|
19
|
|
|
* quotes (the quotation marks used are terms). The localized punctuation-in-quote option controls whether an adjoining |
|
20
|
|
|
* comma or period appears outside (default) or inside the closing quotation mark. |
|
21
|
|
|
* |
|
22
|
|
|
* @package Seboettg\CiteProc\Styles |
|
23
|
|
|
* @author Sebastian Böttger <[email protected]> |
|
|
|
|
|
|
24
|
|
|
*/ |
|
|
|
|
|
|
25
|
|
|
trait QuotesTrait |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
|
|
|
|
|
29
|
|
|
* @var bool |
|
30
|
|
|
*/ |
|
31
|
|
|
private $quotes = false; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
85 |
|
public function initQuotesAttributes(SimpleXMLElement $node) |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
85 |
|
if (isset($node['quotes']) && "true" === (string) $node['quotes']) { |
|
36
|
24 |
|
$this->quotes = true; |
|
37
|
|
|
} |
|
38
|
85 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
|
|
|
|
|
41
|
|
|
* @param string $text |
|
|
|
|
|
|
42
|
|
|
* @return string |
|
|
|
|
|
|
43
|
|
|
*/ |
|
44
|
69 |
|
public function addSurroundingQuotes($text) |
|
45
|
|
|
{ |
|
46
|
69 |
|
if ($this->quotes) { |
|
47
|
4 |
|
$openQuote = CiteProc::getContext()->getLocale()->filter("terms", "open-quote")->single; |
|
48
|
4 |
|
$closeQuote = CiteProc::getContext()->getLocale()->filter("terms", "close-quote")->single; |
|
49
|
4 |
|
$text = $this->replaceOuterQuotes($text, $openQuote, $closeQuote); |
|
50
|
4 |
|
return $openQuote . $text . $closeQuote; |
|
51
|
|
|
} |
|
52
|
69 |
|
return $text; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
|
|
|
|
|
56
|
|
|
* @param $text |
|
|
|
|
|
|
57
|
|
|
* @param $outerOpenQuote |
|
|
|
|
|
|
58
|
|
|
* @param $outerCloseQuote |
|
|
|
|
|
|
59
|
|
|
* @return string |
|
|
|
|
|
|
60
|
|
|
*/ |
|
61
|
4 |
|
private function replaceOuterQuotes($text, $outerOpenQuote, $outerCloseQuote) |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
|
|
64
|
4 |
|
$innerOpenQuote = CiteProc::getContext()->getLocale()->filter("terms", "open-inner-quote")->single; |
|
65
|
4 |
|
$innerCloseQuote = CiteProc::getContext()->getLocale()->filter("terms", "close-inner-quote")->single; |
|
66
|
|
|
|
|
67
|
4 |
|
$text = StringHelper::replaceOuterQuotes($text, "\"", "\"", $innerOpenQuote, $innerCloseQuote); |
|
68
|
4 |
|
$text = StringHelper::replaceOuterQuotes($text, $outerOpenQuote, $outerCloseQuote, $innerOpenQuote, $innerCloseQuote); |
|
69
|
4 |
|
return $text; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|