1 | <?php
|
---|
2 |
|
---|
3 | class EventSourceJoeClub extends EventSource
|
---|
4 | {
|
---|
5 | function ImportInternal(): string
|
---|
6 | {
|
---|
7 | $Output = '';
|
---|
8 | $Content = file_get_contents($this->URL);
|
---|
9 |
|
---|
10 | $BlockStart = '<div class="ai1ec-date-events">';
|
---|
11 | $BlockEnd = '<div class="ai1ec-pull-left"><div class="ai1ec-pagination ai1ec-btn-group">';
|
---|
12 | $Content = GetTextBetween($Content, $BlockStart, $BlockEnd);
|
---|
13 | if ($Content == '')
|
---|
14 | {
|
---|
15 | $Output .= 'Main block not isolated.</br>';
|
---|
16 | return $Output;
|
---|
17 | }
|
---|
18 |
|
---|
19 | $ItemStart = '<div class="ai1ec-event-header">';
|
---|
20 | $ItemEnd = 'Číst více <i class="';
|
---|
21 | while (strpos($Content, $ItemStart) !== false)
|
---|
22 | {
|
---|
23 | $Item = GetTextBetween($Content, $ItemStart, $ItemEnd);
|
---|
24 | $Event = new Event();
|
---|
25 |
|
---|
26 | $Event->Title = trim(html_entity_decode(strip_tags(GetTextBetween($Item, '<span class="ai1ec-event-title">', '<div class="ai1ec-sas-actions'))));
|
---|
27 | $Event->Title = ReduceSpaces(RemoveTabs(RemoveLines($Event->Title)));
|
---|
28 | if (($Event->Title == 'MÁME ZAVŘENO') or ($Event->Title == 'PRIVATE PARTY v Klub Joe')) continue;
|
---|
29 | //$Event->TimeFrom = $this->ParseTime(trim(html_entity_decode(strip_tags(GetTextBetween($Item, '<div class="ai1ec-event-time">', '</div>')))));
|
---|
30 | $Event->Description = GetTextBetween($Item, '<div class="ai1ec-event-description">', '<div class="ai1ec-event-summary-footer">');
|
---|
31 | $Event->Description = str_replace('>Uložit<', '><', $Event->Description);
|
---|
32 | $Event->Description = trim(html_entity_decode(strip_tags($Event->Description)));
|
---|
33 | $Event->Link = trim(html_entity_decode(GetTextBetween($Item, 'href="', '"')));
|
---|
34 | $Event->Location = 'Praha';
|
---|
35 |
|
---|
36 | $Event->Database = $this->Database;
|
---|
37 | $Event->Source = $this->Id;
|
---|
38 | $Output .= $this->ImportItem($Event);
|
---|
39 | $this->AddedCount += $Event->AddIfNotExist();
|
---|
40 | }
|
---|
41 | return $Output;
|
---|
42 | }
|
---|
43 |
|
---|
44 | function ImportItem(&$Event)
|
---|
45 | {
|
---|
46 | $Output = '';
|
---|
47 | if ($Event->Link == '') return $Output;
|
---|
48 | $Content = file_get_contents($Event->Link);
|
---|
49 |
|
---|
50 | $BlockStart = '<header class="entry-header">';
|
---|
51 | $BlockEnd = '<footer class="entry-footer">';
|
---|
52 | $Content = GetTextBetween($Content, $BlockStart, $BlockEnd);
|
---|
53 | if ($Content == '')
|
---|
54 | {
|
---|
55 | $Output .= 'Main block not isolated.</br>';
|
---|
56 | return;
|
---|
57 | }
|
---|
58 |
|
---|
59 | $Event->TimeFrom = strtotime(trim(GetTextBetween($Content, 'ai1ec-hidden dt-start">', '</div>')));
|
---|
60 | $Event->TimeTo = strtotime(trim(GetTextBetween($Content, 'ai1ec-hidden dt-end">', '</div>')));
|
---|
61 | $Event->Price = trim(strip_tags(GetTextBetween($Content, 'Náklady:</div>', '</div')));
|
---|
62 | $Event->Price = trim(str_replace('Kč', '', $Event->Price));
|
---|
63 | if ($Event->Price == 'Zdarma') $Event->Price = 0;
|
---|
64 | if ($Event->Price == '') $Event->Price = 0;
|
---|
65 | return $Output;
|
---|
66 | }
|
---|
67 |
|
---|
68 | function ParseTime($Time)
|
---|
69 | {
|
---|
70 | // Strip out time range
|
---|
71 | if (strpos($Time, '–') !== false)
|
---|
72 | $Time = substr($Time, 0, strpos($Time, '–'));
|
---|
73 |
|
---|
74 | if ($Time == '') return NULL;
|
---|
75 | $Time = str_replace('@', '', $Time);
|
---|
76 |
|
---|
77 | $Parts = explode(' ', $Time);
|
---|
78 | $Month = $Parts[0];
|
---|
79 | $Day = $Parts[1];
|
---|
80 | $Year =
|
---|
81 |
|
---|
82 | $DateParts = explode('.', $Parts[0]);
|
---|
83 | if (count($Parts) > 1) {
|
---|
84 | $TimeParts = explode(':', $Parts[1]);
|
---|
85 | if (count($TimeParts) == 1) $TimeParts[1] = '0';
|
---|
86 | if (count($TimeParts) == 2) $TimeParts[2] = '0';
|
---|
87 | } else $TimeParts = array(0, 0, 0);
|
---|
88 | $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[0], $DateParts[2]);
|
---|
89 | return $Time;
|
---|
90 | }
|
---|
91 | }
|
---|