|
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\Css; |
|
11
|
|
|
|
|
12
|
|
|
use Seboettg\CiteProc\Style\Options\BibliographyOptions; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class CssStyle |
|
16
|
|
|
* @package Seboettg\CiteProc\Styles |
|
17
|
|
|
* @author Sebastian Böttger <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class CssStyle |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
private $bibliographyOptions; |
|
23
|
|
|
|
|
24
|
|
|
private $cssRules = null; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(BibliographyOptions $bibliographyOptions) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->bibliographyOptions = $bibliographyOptions; |
|
29
|
|
|
$this->cssRules = new CssRules(); |
|
30
|
|
|
$this->init(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function render() |
|
34
|
|
|
{ |
|
35
|
|
|
return implode("\n", $this->cssRules->toArray()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
private function init() |
|
39
|
|
|
{ |
|
40
|
|
|
//'hanging-indent', 'line-spacing', 'entry-spacing', 'second-field-align' |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
$lineSpacing = $this->bibliographyOptions->getLineSpacing(); |
|
43
|
|
|
$entrySpacing = $this->bibliographyOptions->getEntrySpacing(); |
|
44
|
|
|
$hangingIndent = $this->bibliographyOptions->getHangingIndent(); |
|
45
|
|
|
|
|
46
|
|
|
if ($lineSpacing || $entrySpacing || $hangingIndent) { |
|
47
|
|
|
$rule = $this->cssRules->getRule(".csl-entry"); |
|
48
|
|
|
if (!empty($lineSpacing)) { |
|
49
|
|
|
$rule->addDirective("line-height", intval($lineSpacing)."em"); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if (!empty($entrySpacing)) { |
|
53
|
|
|
$rule->addDirective("margin-bottom", intval($entrySpacing)."em"); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if (!empty($hangingIndent)) { |
|
57
|
|
|
$rule->addDirective("text-indent", "45px"); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if ("flush" === $this->bibliographyOptions->getSecondFieldAlign()) { |
|
62
|
|
|
$rule = $this->cssRules->getRule(".csl-left-margin"); |
|
63
|
|
|
$rule->addDirective("display", "block"); |
|
64
|
|
|
$rule->addDirective("float", "left"); |
|
65
|
|
|
|
|
66
|
|
|
$rule = $this->cssRules->getRule(".csl-right-inline"); |
|
67
|
|
|
$rule->addDirective("margin-left", "35px"); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.