1 | <?php |
||
9 | trait TTextUtilities |
||
10 | { |
||
11 | /** |
||
12 | * Get text until <!--stop--> or all text. |
||
13 | * |
||
14 | * @param string $text with content |
||
15 | * |
||
16 | * @return string with text |
||
17 | */ |
||
18 | 8 | public function getUntilStop($text) |
|
26 | |||
27 | |||
28 | |||
29 | /** |
||
30 | * Get text until <!--more--> or all text. |
||
31 | * |
||
32 | * @param string $text with content |
||
33 | * |
||
34 | * @return array with text and boolean if more was detected. |
||
35 | */ |
||
36 | 8 | public function getUntilMore($text) |
|
45 | |||
46 | |||
47 | |||
48 | /** |
||
49 | * Wrap HTML element with with start and end. |
||
50 | * |
||
51 | * @param string $text with content |
||
52 | * @param string $tag HTML tag to search for |
||
53 | * @param string $start wrap start part |
||
54 | * @param string $end wrap end part |
||
55 | * @param number $count hits to search for |
||
56 | * |
||
57 | * @return array with text and boolean if more was detected. |
||
58 | */ |
||
59 | public function wrapElementWithStartEnd($text, $tag, $start, $end, $count) |
||
68 | |||
69 | |||
70 | |||
71 | /** |
||
72 | * Wrap content of a HTML element with start and end. |
||
73 | * |
||
74 | * @param string $text with content |
||
75 | * @param string $tag HTML tag to search for |
||
76 | * @param string $start wrap start part |
||
77 | * @param string $end wrap end part |
||
78 | * @param number $count hits to search for |
||
79 | * |
||
80 | * @return array with text and boolean if more was detected. |
||
81 | */ |
||
82 | public function wrapElementContentWithStartEnd($text, $tag, $start, $end, $count) |
||
91 | |||
92 | |||
93 | |||
94 | |||
95 | /** |
||
96 | * Returns the excerpt of the text with at most the specified amount of characters. |
||
97 | * |
||
98 | * @param int $chars the number of characters to return. |
||
99 | * @param boolean $hard do a hard break at exactly $chars characters or find closest space. |
||
100 | * @return string as the excerpt. |
||
101 | */ |
||
102 | /* public function GetExcerpt($chars=139, $hard=false) { |
||
103 | if(!isset($this->data['data_filtered'])) { |
||
104 | return null; |
||
105 | } |
||
106 | $excerpt = strip_tags($this->data['data_filtered']); |
||
107 | |||
108 | if(strlen($excerpt) > $chars) { |
||
109 | $excerpt = substr($excerpt, 0, $chars-1); |
||
110 | } |
||
111 | |||
112 | if(!$hard) { |
||
113 | $lastSpace = strrpos($excerpt, ' '); |
||
114 | $excerpt = substr($excerpt, 0, $lastSpace); |
||
115 | } |
||
116 | |||
117 | return $excerpt; |
||
118 | } |
||
119 | |||
120 | |||
121 | /** |
||
122 | * Returns the first paragraph ot the text. |
||
123 | * |
||
124 | * @return string as the first paragraph. |
||
125 | */ |
||
126 | /* public function GetFirstParagraph() { |
||
127 | if(!isset($this->data['data_filtered'])) { |
||
128 | return null; |
||
129 | } |
||
130 | $excerpt = $this->data['data_filtered']; |
||
131 | |||
132 | $firstPara = strpos($excerpt, '</p>'); |
||
133 | $excerpt = substr($excerpt, 0, $firstPara + 4); |
||
134 | |||
135 | return $excerpt; |
||
136 | } |
||
137 | */ |
||
138 | } |
||
139 |