|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace sokolnikov911\YandexTurboPages\helpers; |
|
4
|
|
|
|
|
5
|
|
|
class Content |
|
6
|
|
|
{ |
|
7
|
|
|
const SHARE_TYPE_FACEBOOK = 'facebook'; |
|
8
|
|
|
const SHARE_TYPE_GOOGLE = 'google'; |
|
9
|
|
|
const SHARE_TYPE_ODNOKLASSNIKI = 'odnoklassniki'; |
|
10
|
|
|
const SHARE_TYPE_TELEGRAM = 'telegram'; |
|
11
|
|
|
const SHARE_TYPE_TWITTER = 'twitter'; |
|
12
|
|
|
const SHARE_TYPE_VKONTAKTE = 'vkontakte'; |
|
13
|
|
|
|
|
14
|
|
|
const SLIDER_DATA_VIEW_SQUARE = 'square'; |
|
15
|
|
|
const SLIDER_DATA_VIEW_PORTRAIT = 'portrait'; |
|
16
|
|
|
const SLIDER_DATA_VIEW_LANDSCAPE = 'landscape'; |
|
17
|
|
|
|
|
18
|
|
|
const SLIDER_DATA_ITEM_VIEW_COVER = 'cover'; |
|
19
|
|
|
const SLIDER_DATA_ITEM_VIEW_CONTAIN = 'contain'; |
|
20
|
|
|
|
|
21
|
|
|
const OWN_VIDEO_TYPE_MP4 = 'video/mp4'; |
|
22
|
|
|
|
|
23
|
|
|
const ADDITIONAL_CONTENT_ORIENTATION_VERTICAL = 'vertical'; |
|
24
|
|
|
const ADDITIONAL_CONTENT_ORIENTATION_HORIZONTAL = 'horizontal'; |
|
25
|
|
|
|
|
26
|
|
|
const ADDITIONAL_CONTENT_THUMB_POSITION_LEFT = 'left'; |
|
27
|
|
|
const ADDITIONAL_CONTENT_THUMB_POSITION_RIGHT = 'right'; |
|
28
|
|
|
const ADDITIONAL_CONTENT_THUMB_POSITION_TOP = 'top'; |
|
29
|
|
|
|
|
30
|
|
|
const ADDITIONAL_CONTENT_THUMB_RATIO_1_1 = '1x1'; |
|
31
|
|
|
const ADDITIONAL_CONTENT_THUMB_RATIO_2_3 = '2x3'; |
|
32
|
|
|
const ADDITIONAL_CONTENT_THUMB_RATIO_3_2 = '3x2'; |
|
33
|
|
|
const ADDITIONAL_CONTENT_THUMB_RATIO_3_4 = '3x4'; |
|
34
|
|
|
const ADDITIONAL_CONTENT_THUMB_RATIO_4_3 = '4x3'; |
|
35
|
|
|
const ADDITIONAL_CONTENT_THUMB_RATIO_16_9 = '16x9'; |
|
36
|
|
|
const ADDITIONAL_CONTENT_THUMB_RATIO_16_10 = '16x10'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Generate header element |
|
40
|
|
|
* @param string $h1 |
|
41
|
|
|
* @param string|null $h2 |
|
42
|
|
|
* @param string|null $imgUrl |
|
43
|
|
|
* @param string|null $imgCaption |
|
44
|
|
|
* @param array|null $menuArray array of arrays with pairs of url and content |
|
45
|
|
|
* [ |
|
46
|
|
|
* ['url' => 'http://example/page1.html', 'title' => 'Page title 1'], |
|
47
|
|
|
* ['url' => 'http://example/page2.html', 'title' => 'Page title 2'], |
|
48
|
|
|
* ] |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
18 |
|
public static function header($h1, $h2 = null, $imgUrl = null, |
|
52
|
|
|
$imgCaption = null, array $menuArray = null) |
|
53
|
|
|
{ |
|
54
|
18 |
|
$header = '<h1>' . $h1 . '</h1>'; |
|
55
|
18 |
|
$header .= $h2 ? '<h2>' . $h2 . '</h2>' : ''; |
|
56
|
18 |
|
$header .= $menuArray ? self::generateMenu($menuArray) : ''; |
|
57
|
18 |
|
$header .= $imgUrl ? self::img($imgUrl, $imgCaption) : ''; |
|
58
|
|
|
|
|
59
|
18 |
|
return '<header>' . $header . '</header>'; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Generate image element |
|
64
|
|
|
* @param string $imgUrl |
|
65
|
|
|
* @param string|null $imgCaption |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
18 |
|
public static function img($imgUrl, $imgCaption = null) |
|
69
|
|
|
{ |
|
70
|
18 |
|
$imageString = '<img src="' . $imgUrl . '" />'; |
|
71
|
|
|
|
|
72
|
18 |
|
$imageString .= $imgCaption ? '<figcaption>' . $imgCaption . '</figcaption>' : ''; |
|
73
|
|
|
|
|
74
|
18 |
|
return '<figure>' . $imageString . '</figure>'; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Generate video element |
|
79
|
|
|
* @param string $videoUrl |
|
80
|
|
|
* @param string|null $videoCaption |
|
81
|
|
|
* @param string $imgUrl |
|
82
|
|
|
* @param string $type |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
12 |
|
public static function ownVideo($videoUrl, $videoCaption = null, $type = self::OWN_VIDEO_TYPE_MP4, $imgUrl = null) |
|
86
|
|
|
{ |
|
87
|
12 |
|
$videoString = '<video><source src="' . $videoUrl . '" type="' . $type . '" /></video>'; |
|
88
|
12 |
|
$videoString .= $imgUrl ? '<img src="' . $imgUrl . '" />' : ''; |
|
89
|
12 |
|
$videoString .= $videoCaption ? '<figcaption>' . $videoCaption . '</figcaption>' : ''; |
|
90
|
|
|
|
|
91
|
12 |
|
return '<figure>' . $videoString . '</figure>'; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Generate video element for external video |
|
96
|
|
|
* @param string $videoUrl |
|
97
|
|
|
* @param array $options Options Array with next variables: width, height, frameborder, allowfullscreen, |
|
98
|
|
|
* referrerpolicy, sandbox, hd. Options example: |
|
99
|
|
|
* [ |
|
100
|
|
|
* 'width' => 640, |
|
101
|
|
|
* 'height' => 480, |
|
102
|
|
|
* 'frameborder' => 1, |
|
103
|
|
|
* 'allowfullscreen' => 'true', |
|
104
|
|
|
* 'referrerpolicy' => 'unsafe-url', |
|
105
|
|
|
* 'sandbox' => 'allow-forms allow-modals', |
|
106
|
|
|
* 'hd' => 3 |
|
107
|
|
|
* ] |
|
108
|
|
|
* @return string |
|
109
|
|
|
*/ |
|
110
|
12 |
|
public static function externalVideo($videoUrl, array $options = []) |
|
111
|
|
|
{ |
|
112
|
12 |
|
$videoString = '<iframe src="' . $videoUrl . '"'; |
|
113
|
|
|
|
|
114
|
12 |
|
foreach ($options as $key => $value) { |
|
115
|
6 |
|
$videoString .= ' ' . $key . '="' . $value . '"'; |
|
116
|
6 |
|
} |
|
117
|
|
|
|
|
118
|
12 |
|
$videoString .= '></iframe>'; |
|
119
|
|
|
|
|
120
|
12 |
|
return $videoString; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Generate images gallery |
|
125
|
|
|
* @param array $imagesArray Array of images urls |
|
126
|
|
|
* ['http://example.com/image1.jpg', 'http://example.com/image2.jpg'] |
|
127
|
|
|
* @param string|null $header |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
12 |
|
public static function gallery(array $imagesArray, $header = null) |
|
131
|
|
|
{ |
|
132
|
12 |
|
$galleryString = $header ? '<header>' . $header . '</header>' : ''; |
|
133
|
|
|
|
|
134
|
12 |
|
foreach ($imagesArray as $image) { |
|
135
|
12 |
|
$galleryString .= '<img src="' . $image . '" />'; |
|
136
|
6 |
|
} |
|
137
|
|
|
|
|
138
|
12 |
|
return '<div data-block="gallery">' . $galleryString . '</div>'; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Generate share block |
|
143
|
|
|
* @param array|null $networks Array of network names |
|
144
|
|
|
* [Content::SHARE_TYPE_GOOGLE, Content::SHARE_TYPE_TWITTER] |
|
145
|
|
|
* Can be empty, in this way all possible network types will be showed. |
|
146
|
|
|
* @return string |
|
147
|
|
|
*/ |
|
148
|
12 |
|
public static function share(array $networks = null) |
|
149
|
|
|
{ |
|
150
|
6 |
|
$networksString = $networks |
|
151
|
9 |
|
? 'data-network="' . implode(',', $networks) . '"' |
|
152
|
12 |
|
: ''; |
|
153
|
|
|
|
|
154
|
12 |
|
return '<div data-block="share" ' . $networksString . '></div>'; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Generate rating block |
|
159
|
|
|
* @param float $currentRating |
|
160
|
|
|
* @param float $maxRating |
|
161
|
|
|
* @return string |
|
162
|
|
|
* @throws \UnexpectedValueException |
|
163
|
|
|
*/ |
|
164
|
24 |
|
public static function rating($currentRating, $maxRating) |
|
165
|
|
|
{ |
|
166
|
24 |
|
if (($currentRating > $maxRating) || ($maxRating <= 0) || ($currentRating < 0)) { |
|
167
|
18 |
|
throw new \UnexpectedValueException("Current rating can't be bigger than max value. And max value must be bigger than 0."); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
return '<div itemscope="" itemtype="http://schema.org/Rating"> |
|
171
|
6 |
|
<meta itemprop="ratingValue" content="' . $currentRating . '" /> |
|
172
|
6 |
|
<meta itemprop="bestRating" content="' . $maxRating . '" /> |
|
173
|
3 |
|
</div>'; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Generate button |
|
178
|
|
|
* @param string $text |
|
179
|
|
|
* @param string $url |
|
180
|
|
|
* @param string $phone Phone number in RFC-3966 format |
|
181
|
|
|
* @param string|null $buttonColor Can be Text or HEX |
|
182
|
|
|
* @param string|null $textColor Can be Text or HEX |
|
183
|
|
|
* @param bool $isBoldText |
|
184
|
|
|
* @param bool $isDisabled |
|
185
|
|
|
* @return string |
|
186
|
|
|
* @throws \UnexpectedValueException |
|
187
|
|
|
*/ |
|
188
|
24 |
|
public static function button($text, $url = '', $phone = '', |
|
189
|
|
|
$buttonColor = null, $textColor = null, |
|
190
|
|
|
$isBoldText = false, $isDisabled = false) |
|
191
|
|
|
{ |
|
192
|
24 |
|
if (!$url && !$phone) { |
|
193
|
6 |
|
throw new \UnexpectedValueException('Please set url or phone number for button'); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
18 |
|
$formAction = $url ? $url : 'tel:' . $phone; |
|
197
|
18 |
|
$buttonColorString = $buttonColor ? 'data-background-color="' . $buttonColor . '"' : ''; |
|
198
|
18 |
|
$textColorString = $textColor ? 'data-color="' . $textColor . '"' : ''; |
|
199
|
18 |
|
$isBoldTextString = $isBoldText ? 'data-primary="true"' : ''; |
|
200
|
18 |
|
$isDisabledString = $isDisabled ? 'disabled="true"' : ''; |
|
201
|
|
|
|
|
202
|
|
|
return "<button |
|
203
|
18 |
|
formaction=\"" . $formAction . "\" |
|
204
|
18 |
|
" . $buttonColorString . " |
|
205
|
18 |
|
" . $textColorString . " |
|
206
|
18 |
|
" . $isBoldTextString . " |
|
207
|
18 |
|
" . $isDisabledString . ">" . $text . "</button>"; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Generate comment block |
|
212
|
|
|
* @param string $url URL to comments page |
|
213
|
|
|
* @param array $commentsArray multidimensional or one-dimensional array of comments, |
|
214
|
|
|
* can has unlimited includes, example: |
|
215
|
|
|
* [ |
|
216
|
|
|
* [ |
|
217
|
|
|
* 'author' => 'First Author Name', |
|
218
|
|
|
* 'avatar' => 'http://example.com/user1.jpg', |
|
219
|
|
|
* 'title' => 'Comment Title', |
|
220
|
|
|
* 'subtitle' => '2017-12-10', |
|
221
|
|
|
* 'content' => 'Somme comment text', |
|
222
|
|
|
* 'comments' => [ |
|
223
|
|
|
* [ |
|
224
|
|
|
* 'author' => 'Third Author Name', |
|
225
|
|
|
* 'avatar' => 'http://example.com/user3.jpg', |
|
226
|
|
|
* 'title' => 'Comment Title', |
|
227
|
|
|
* 'subtitle' => '2017-12-12', |
|
228
|
|
|
* 'content' => 'Some answer text' |
|
229
|
|
|
* ], |
|
230
|
|
|
* [ |
|
231
|
|
|
* 'author' => 'Another Author Name', |
|
232
|
|
|
* 'avatar' => 'http://example.com/user4.jpg', |
|
233
|
|
|
* 'title' => 'Comment Title', |
|
234
|
|
|
* 'subtitle' => '2017-12-13', |
|
235
|
|
|
* 'content' => 'Another answer text' |
|
236
|
|
|
* ], |
|
237
|
|
|
* ] |
|
238
|
|
|
* ], |
|
239
|
|
|
* [ |
|
240
|
|
|
* 'author' => 'Second Author Name', |
|
241
|
|
|
* 'avatar' => 'http://example.com/user2.jpg', |
|
242
|
|
|
* 'title' => 'Comment Title', |
|
243
|
|
|
* 'subtitle' => '2017-12-11', |
|
244
|
|
|
* 'content' => 'Some comment text' |
|
245
|
|
|
* ], |
|
246
|
|
|
* ] |
|
247
|
|
|
* @return string |
|
248
|
|
|
*/ |
|
249
|
6 |
|
public static function comment($url, array $commentsArray) |
|
250
|
|
|
{ |
|
251
|
6 |
|
$commentBlock = self::generateCommentBlock($commentsArray); |
|
252
|
|
|
|
|
253
|
6 |
|
return '<div data-block="comments" data-url="' . $url . '">' . $commentBlock . '</div>'; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Generate accordion |
|
258
|
|
|
* @param array $accordionArray array accordion elements |
|
259
|
|
|
* [ |
|
260
|
|
|
* ['title' => 'Page title 1', 'text' => 'Text 1'], |
|
261
|
|
|
* ['title' => 'Page title 2', 'text' => 'Text 2', 'expanded' => true], |
|
262
|
|
|
* ] |
|
263
|
|
|
* @return string |
|
264
|
|
|
*/ |
|
265
|
6 |
|
public static function accordion(array $accordionArray) |
|
266
|
|
|
{ |
|
267
|
6 |
|
$accordionString = '<div data-block="accordion">'; |
|
268
|
|
|
|
|
269
|
6 |
|
foreach ($accordionArray as $item) { |
|
270
|
6 |
|
$expanded = isset($item['expanded']) && $item['expanded'] ? ' data-expanded="true"' : ''; |
|
271
|
6 |
|
$accordionString .= '<div data-block="item" data-title="' . $item['title'] . '"' . $expanded . '>' . $item['text'] . '</div>'; |
|
272
|
3 |
|
} |
|
273
|
|
|
|
|
274
|
6 |
|
$accordionString .= '</div>'; |
|
275
|
|
|
|
|
276
|
6 |
|
return $accordionString; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Generate block with additional content |
|
281
|
|
|
* @param array $itemsArray Array of items with data |
|
282
|
|
|
* [ |
|
283
|
|
|
* [ |
|
284
|
|
|
* 'href' => 'http://example.com/page1.html', |
|
285
|
|
|
* 'title' => 'Item title 1', |
|
286
|
|
|
* 'description' => 'Item description', |
|
287
|
|
|
* 'thumb' => 'http://example/image1.jpg', |
|
288
|
|
|
* 'thumb_position' => Content::ADDITIONAL_CONTENT_THUMB_POSITION_LEFT, |
|
289
|
|
|
* 'thumb_ratio' => Content::ADDITIONAL_CONTENT_THUMB_RATIO_1_1 |
|
290
|
|
|
* ], |
|
291
|
|
|
* [ |
|
292
|
|
|
* 'href' => 'http://example.com/page2.html', |
|
293
|
|
|
* 'title' => 'Item title 2' |
|
294
|
|
|
* ], |
|
295
|
|
|
* ] |
|
296
|
|
|
* @param string|null $title |
|
297
|
|
|
* @param string|null $orientation |
|
298
|
|
|
* @return string |
|
299
|
|
|
* @throws \Exception |
|
300
|
|
|
*/ |
|
301
|
24 |
|
public static function additionalContent(array $itemsArray, $title = null, $orientation = null) |
|
302
|
|
|
{ |
|
303
|
24 |
|
$contentString = '<div data-block="feed"'; |
|
304
|
|
|
|
|
305
|
24 |
|
$contentString .= $orientation ? ' data-layout="' . $orientation . '"' : ''; |
|
306
|
24 |
|
$contentString .= $title ? ' data-title="' . $title . '"' : ''; |
|
307
|
|
|
|
|
308
|
24 |
|
$contentString .= '>'; |
|
309
|
|
|
|
|
310
|
24 |
|
return $contentString . self::generateAdditionalContentItemsList($itemsArray) . '</div>'; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* Generate media slider |
|
315
|
|
|
* @param array $itemsArray Array of items with data |
|
316
|
|
|
* [ |
|
317
|
|
|
* ['url' => 'http://example.com/image1.jpg', 'title' => 'Image title 1', 'link' => ''], |
|
318
|
|
|
* ['url' => 'http://example.com/image2.jpg', 'title' => 'Image title 2', 'link' => ''], |
|
319
|
|
|
* ['url' => 'http://example.com/image3.jpg'], |
|
320
|
|
|
* ['href' => 'http://example.com/page1.html', 'title' => 'Link title 1', 'text' => 'Link text 1'] |
|
321
|
|
|
* ] |
|
322
|
|
|
* @param string|null $header |
|
323
|
|
|
* @param string $dataView |
|
324
|
|
|
* @param string $dataItemView |
|
325
|
|
|
* @return string |
|
326
|
|
|
*/ |
|
327
|
12 |
|
public static function slider(array $itemsArray, $header = null, |
|
328
|
|
|
$dataView = self::SLIDER_DATA_VIEW_SQUARE, |
|
329
|
|
|
$dataItemView = self::SLIDER_DATA_ITEM_VIEW_COVER) |
|
330
|
|
|
{ |
|
331
|
12 |
|
$sliderString = $header ? '<header>' . $header . '</header>' : ''; |
|
332
|
|
|
|
|
333
|
12 |
|
$sliderString .= self::generateSliderItemsBlock($itemsArray); |
|
334
|
|
|
|
|
335
|
12 |
|
return '<div data-block="slider" data-view="' . $dataView . '" data-item-view="' |
|
336
|
12 |
|
. $dataItemView . '">' . $sliderString . '</div>'; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* Generate Ad block position element |
|
341
|
|
|
* @param string $turboAdId value of $turboAdId used in Channel() class |
|
342
|
|
|
* @return string |
|
343
|
|
|
* |
|
344
|
|
|
* @see Channel::$adTurboAdId |
|
345
|
|
|
*/ |
|
346
|
6 |
|
public static function adBlockPosition($turboAdId) |
|
347
|
|
|
{ |
|
348
|
6 |
|
return '<figure data-turbo-ad-id="' . $turboAdId . '"></figure>'; |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* Generate content block for media slider |
|
353
|
|
|
* @param array $itemsArray Array of items with data |
|
354
|
|
|
* [ |
|
355
|
|
|
* ['url' => 'http://example.com/image1.jpg', 'title' => 'Image title 1', 'link' => ''], |
|
356
|
|
|
* ['url' => 'http://example.com/image2.jpg', 'title' => 'Image title 2', 'link' => ''], |
|
357
|
|
|
* ['url' => 'http://example.com/image3.jpg'], |
|
358
|
|
|
* ['href' => 'http://example.com/page1.html', 'title' => 'Link title 1', 'text' => 'Link text 1'] |
|
359
|
|
|
* ] |
|
360
|
|
|
* @return string |
|
361
|
|
|
*/ |
|
362
|
12 |
|
private static function generateSliderItemsBlock(array $itemsArray) |
|
363
|
|
|
{ |
|
364
|
12 |
|
$sliderString = ''; |
|
365
|
|
|
|
|
366
|
12 |
|
foreach ($itemsArray as $item) { |
|
367
|
12 |
|
$sliderString .= '<figure>'; |
|
368
|
|
|
|
|
369
|
12 |
|
if (isset($item['title'])) { |
|
370
|
12 |
|
$sliderString .= '<figcaption>' . $item['title'] . '</figcaption>'; |
|
371
|
6 |
|
} |
|
372
|
|
|
|
|
373
|
12 |
|
if (isset($item['url'])) { |
|
374
|
12 |
|
$sliderString .= '<img src="' . $item['url'] . '" />'; |
|
375
|
12 |
|
} elseif (isset($item['href'])) { |
|
376
|
12 |
|
$sliderString .= '<a href="' . $item['href'] . '">' . $item['text'] . '</a>'; |
|
377
|
6 |
|
} |
|
378
|
|
|
|
|
379
|
12 |
|
$sliderString .= '</figure>'; |
|
380
|
6 |
|
} |
|
381
|
|
|
|
|
382
|
12 |
|
return $sliderString; |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
6 |
|
private static function generateCommentBlock(array $commentsArray) |
|
386
|
|
|
{ |
|
387
|
6 |
|
$commentBlock = ''; |
|
388
|
|
|
|
|
389
|
6 |
|
foreach ($commentsArray as $commentArray) { |
|
390
|
6 |
|
$author = isset($commentArray['author']) ? 'data-author="' . $commentArray['author'] . '"' : ''; |
|
391
|
6 |
|
$avatar = isset($commentArray['avatar']) ? 'data-avatar-url="' . $commentArray['avatar'] . '"' : ''; |
|
392
|
6 |
|
$subtitle = isset($commentArray['subtitle']) ? 'data-subtitle="' . $commentArray['subtitle'] . '"' : ''; |
|
393
|
|
|
|
|
394
|
|
|
$commentBlock .= '<div |
|
395
|
|
|
data-block="comment" |
|
396
|
6 |
|
' . $author . ' |
|
397
|
6 |
|
' . $avatar . ' |
|
398
|
6 |
|
' . $subtitle . ' |
|
399
|
3 |
|
><div data-block="content">'; |
|
400
|
|
|
|
|
401
|
6 |
|
$commentBlock .= isset($commentArray['title']) ? '<header>' . $commentArray['title'] . '</header>' : ''; |
|
402
|
6 |
|
$commentBlock .= isset($commentArray['content']) ? '<p>' . $commentArray['content'] . '</p></div>' : ''; |
|
403
|
|
|
|
|
404
|
6 |
|
if (isset($commentArray['comments'])) { |
|
405
|
6 |
|
$commentBlock .= '<div data-block="comments">'; |
|
406
|
6 |
|
$commentBlock .= self::generateCommentBlock($commentArray['comments']); |
|
407
|
6 |
|
$commentBlock .= '</div>'; |
|
408
|
3 |
|
} |
|
409
|
|
|
|
|
410
|
6 |
|
$commentBlock .= '</div>'; |
|
411
|
3 |
|
} |
|
412
|
|
|
|
|
413
|
6 |
|
return $commentBlock; |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
/** |
|
417
|
|
|
* Generate header menu |
|
418
|
|
|
* @param array $menuArray array of arrays with pairs of url and title |
|
419
|
|
|
* [ |
|
420
|
|
|
* ['url' => 'http://example/page1.html', 'title' => 'Page title 1'], |
|
421
|
|
|
* ['url' => 'http://example/page2.html', 'title' => 'Page title 2'], |
|
422
|
|
|
* ] |
|
423
|
|
|
* @return string |
|
424
|
|
|
*/ |
|
425
|
6 |
|
private static function generateMenu(array $menuArray) |
|
426
|
|
|
{ |
|
427
|
6 |
|
$menuString = ''; |
|
428
|
|
|
|
|
429
|
6 |
|
foreach ($menuArray as $menuItem) { |
|
430
|
6 |
|
$menuString .= '<a href="' . $menuItem['url'] . '">' . $menuItem['title'] . '</a>'; |
|
431
|
3 |
|
} |
|
432
|
|
|
|
|
433
|
6 |
|
return '<menu>' . $menuString . '</menu>'; |
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
/** |
|
437
|
|
|
* Generate additional content items list |
|
438
|
|
|
* @param array $itemsArray array of arrays with data of additional content items |
|
439
|
|
|
* [ |
|
440
|
|
|
* [ |
|
441
|
|
|
* 'href' => 'http://example.com/page1.html', |
|
442
|
|
|
* 'title' => 'Item title 1', |
|
443
|
|
|
* 'description' => 'Item description', |
|
444
|
|
|
* 'thumb' => 'http://example/image1.jpg', |
|
445
|
|
|
* 'thumb_position' => Content::ADDITIONAL_CONTENT_THUMB_POSITION_LEFT, |
|
446
|
|
|
* 'thumb_ratio' => Content::ADDITIONAL_CONTENT_THUMB_RATIO_1_1 |
|
447
|
|
|
* ], |
|
448
|
|
|
* [ |
|
449
|
|
|
* 'href' => 'http://example.com/page2.html', |
|
450
|
|
|
* 'title' => 'Item title 2' |
|
451
|
|
|
* ], |
|
452
|
|
|
* ] |
|
453
|
|
|
* @return string |
|
454
|
|
|
* @throws \Exception |
|
455
|
|
|
*/ |
|
456
|
24 |
|
private static function generateAdditionalContentItemsList(array $itemsArray) |
|
457
|
|
|
{ |
|
458
|
24 |
|
$itemsString = ''; |
|
459
|
|
|
|
|
460
|
24 |
|
foreach ($itemsArray as $item) { |
|
461
|
|
|
|
|
462
|
24 |
|
if (!isset($item['href']) || !isset($item['title'])) { |
|
463
|
12 |
|
throw new \Exception("Title and Url attributes are required"); |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
$itemsString .= '<div data-block="feed-item" |
|
467
|
12 |
|
data-href="' . $item['href'] . '" |
|
468
|
12 |
|
data-title="' . $item['title'] . '"'; |
|
469
|
|
|
|
|
470
|
12 |
|
$itemsString .= isset($item['description']) ? ' data-description="' . $item['description'] . '"' : ''; |
|
471
|
12 |
|
$itemsString .= isset($item['thumb']) ? ' data-thumb="' . $item['thumb'] . '"' : ''; |
|
472
|
12 |
|
$itemsString .= isset($item['thumb_position']) ? ' data-thumb-position="' . $item['thumb_position'] . '"' : ''; |
|
473
|
12 |
|
$itemsString .= isset($item['thumb_ratio']) ? ' data-thumb-ratio="' . $item['thumb_ratio'] . '"' : ''; |
|
474
|
|
|
|
|
475
|
12 |
|
$itemsString .= '/>'; |
|
476
|
6 |
|
} |
|
477
|
|
|
|
|
478
|
12 |
|
return $itemsString; |
|
479
|
|
|
} |
|
480
|
|
|
} |