1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Content\Tag; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Html; |
5
|
|
|
use function str_replace; |
6
|
|
|
use function strpos; |
7
|
|
|
use function substr; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* children class to parse content for more tags |
11
|
|
|
* |
12
|
|
|
* @since 3.0.0 |
13
|
|
|
* |
14
|
|
|
* @package Redaxscript |
15
|
|
|
* @category Content |
16
|
|
|
* @author Henry Ruhs |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
class More extends TagAbstract |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* options of the more tag |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
protected $_optionArray = |
28
|
|
|
[ |
29
|
|
|
'prefix' => 'more-', |
30
|
|
|
'className' => |
31
|
|
|
[ |
32
|
|
|
'link' => 'rs-link-more', |
33
|
|
|
'break' => 'rs-break-more' |
34
|
|
|
], |
35
|
|
|
'search' => |
36
|
|
|
[ |
37
|
|
|
'<rs-more>' |
38
|
|
|
] |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* process the class |
43
|
|
|
* |
44
|
|
|
* @since 3.0.0 |
45
|
|
|
* |
46
|
|
|
* @param string $content content to be parsed |
47
|
|
|
* @param string $route route of the content |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
15 |
|
*/ |
51
|
|
|
|
52
|
15 |
|
public function process(string $content = null, string $route = null) : string |
53
|
15 |
|
{ |
54
|
|
|
$output = str_replace($this->_optionArray['search'], null, $content); |
55
|
|
|
$position = strpos($content, $this->_optionArray['search'][0]); |
56
|
|
|
$id = $this->_optionArray['prefix'] . $position; |
57
|
15 |
|
|
58
|
15 |
|
/* html element */ |
59
|
|
|
|
60
|
15 |
|
$element = new Html\Element(); |
61
|
|
|
$linkElement = $element |
62
|
|
|
->copy() |
63
|
|
|
->init('a', |
64
|
|
|
[ |
65
|
15 |
|
'class' => $this->_optionArray['className']['link'] |
66
|
|
|
]); |
67
|
1 |
|
$breakElement = $element |
68
|
1 |
|
->copy() |
69
|
|
|
->init('hr', |
70
|
|
|
[ |
71
|
1 |
|
'id' => $id, |
72
|
1 |
|
'class' => $this->_optionArray['className']['break'] |
73
|
1 |
|
]); |
74
|
|
|
|
75
|
|
|
/* collect output */ |
76
|
15 |
|
|
77
|
|
|
if ($position > -1 && $this->_registry->get('lastTable') === 'categories') |
78
|
|
|
{ |
79
|
|
|
$output = substr($output, 0, $position); |
80
|
|
|
if ($route) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$output .= $linkElement |
83
|
|
|
->attr('href', $this->_registry->get('parameterRoute') . $route . '#' . $id) |
84
|
|
|
->text($this->_language->get('read_more')); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
else if ($position > -1) |
88
|
|
|
{ |
89
|
|
|
$output = substr($output, 0, $position) . $breakElement . substr($output, $position); |
90
|
|
|
} |
91
|
|
|
return $output; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: