|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of PHP-Typography. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright 2017 Peter Putzer. |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software; you can redistribute it and/or modify modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License along |
|
18
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
|
19
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20
|
|
|
* |
|
21
|
|
|
* *** |
|
22
|
|
|
* |
|
23
|
|
|
* @package mundschenk-at/php-typography |
|
24
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace PHP_Typography\Fixes\Node_Fixes; |
|
28
|
|
|
|
|
29
|
|
|
use PHP_Typography\Settings; |
|
30
|
|
|
use PHP_Typography\DOM; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* All fixes that depend on certain HTML classes not being present should extend this baseclass. |
|
34
|
|
|
* |
|
35
|
|
|
* @author Peter Putzer <[email protected]> |
|
36
|
|
|
* |
|
37
|
|
|
* @since 5.0.0 |
|
38
|
|
|
*/ |
|
39
|
|
|
abstract class Classes_Dependent_Fix extends Abstract_Node_Fix { |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* An array of HTML classes to avoid applying the fix. |
|
43
|
|
|
* |
|
44
|
|
|
* @var array |
|
45
|
|
|
*/ |
|
46
|
|
|
private $classes_to_avoid; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Creates a new classes dependent fix. |
|
50
|
|
|
* |
|
51
|
|
|
* @param array|string $classes HTML class(es). |
|
52
|
|
|
* @param bool $feed_compatible Optional. Default false. |
|
53
|
|
|
*/ |
|
54
|
2 |
|
public function __construct( $classes, $feed_compatible = false ) { |
|
55
|
2 |
|
parent::__construct( $feed_compatible ); |
|
56
|
|
|
|
|
57
|
2 |
|
if ( ! is_array( $classes ) ) { |
|
58
|
1 |
|
$classes = [ $classes ]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
2 |
|
$this->classes_to_avoid = $classes; |
|
62
|
2 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Apply the fix to a given textnode if the nodes class(es) allow it. |
|
66
|
|
|
* |
|
67
|
|
|
* @param \DOMText $textnode Required. |
|
68
|
|
|
* @param Settings $settings Required. |
|
69
|
|
|
* @param bool $is_title Optional. Default false. |
|
70
|
|
|
* |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
26 |
|
public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
74
|
26 |
|
if ( ! DOM::has_class( $textnode, $this->classes_to_avoid ) ) { |
|
75
|
26 |
|
$this->apply_internal( $textnode, $settings, $is_title ); |
|
76
|
|
|
} |
|
77
|
26 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Apply the fix to a given textnode. |
|
81
|
|
|
* |
|
82
|
|
|
* @since 6.0.0 The method was accidentally made public and is now protected. |
|
83
|
|
|
* |
|
84
|
|
|
* @param \DOMText $textnode Required. |
|
85
|
|
|
* @param Settings $settings Required. |
|
86
|
|
|
* @param bool $is_title Optional. Default false. |
|
87
|
|
|
* |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
|
|
abstract protected function apply_internal( \DOMText $textnode, Settings $settings, $is_title = false ); |
|
91
|
|
|
} |
|
92
|
|
|
|