source: trunk/Modules/Meet/Import/Amblar.php

Last change on this file was 64, checked in by chronos, 3 years ago
  • Added: MG Dance import.
File size: 4.1 KB
Line 
1<?php
2
3$HeightTags = array(
4 '150-160cm' => '155',
5 '160-170cm' => '165',
6 '170-180cm' => '175',
7 '180-190cm' => '185',
8 '&gt; 190cm' => '195',
9);
10$AgeTags = array(
11 'věk 19-24' => '22',
12 'věk 25-30' => '27',
13 'věk 31-39' => '35',
14 'věk 40-49' => '45',
15 'věk 50+' => '55',
16);
17$LevelTags = array(
18 'Začátečník' => 'Začátečník',
19 'Mírně pokročilý' => 'Mírně pokročilý',
20 'Pokročilý' => 'Pokročilý',
21 'Více pokročilý' => 'Více pokročilý',
22 'Profi' => 'Profi',
23 'Master' => 'Master',
24);
25
26class MeetSourceAmblar extends MeetSource
27{
28 function Import(): string
29 {
30 $Output = parent::Import();
31 $this->AddTimeInterval = 24 * 60 * 60;
32 $Content = file_get_contents($this->URL);
33
34 //echo($Content);
35 $BlockStart = '<div id="archive-question"';
36 $BlockEnd = '<div class="social-bookmark">';
37 $Content = GetTextBetween($Content, $BlockStart, $BlockEnd);
38 if ($Content == '')
39 {
40 $Output .= 'Main block not isolated.</br>';
41 return $Output;
42 }
43
44 $ItemStart = '<article id="question';
45 $ItemEnd = '</article>';
46 while (strpos($Content, $ItemStart) !== false)
47 {
48 $Item = GetTextBetween($Content, $ItemStart, $ItemEnd);
49 $MeetItem = new MeetItem();
50 $MeetItem->Link = trim(GetTextBetween($Item, '<a class="dwqa-title" href="', '"'));
51 $MeetItem->Title = trim(GetTextBetween($Item, 'rel="bookmark">', '</a>'));
52 $MeetItem->Gender = trim(GetTextBetween($Item, 'class="dwqa-status status-search-dancer">', '</span>'));
53 if ($MeetItem->Gender == 'Inzerent hledá tanečníka') $MeetItem->Gender = Gender::Female;
54 else $MeetItem->Gender = Gender::Male;
55 $MeetItem->Name = trim(GetTextBetween($Item, '<span class="dwqa-author">', '</span>'));
56 $Type = trim(GetTextBetween($Item, ' ', ' '));
57 if ($Type == 'odpovězeno') continue;
58 $MeetItem->Time = trim(GetTextBetween($Item, '<span class="dwqa-date">', '</span>'));
59 if (mb_substr($MeetItem->Time, 0, 4) == 'před')
60 {
61 $Parts = explode(' ', $MeetItem->Time);
62 if ($Parts[2] == 'hours') $MeetItem->Time = strtotime("-".$Parts[1]." hours");
63 else if ($Parts[2] == 'dní') $MeetItem->Time = strtotime("-".$Parts[1]." days");
64 else if ($Parts[2] == 'dny') $MeetItem->Time = strtotime("-".$Parts[1]." days");
65 } else $MeetItem->Time = HumanDateToTime($MeetItem->Time);
66 $MeetItem->Email = '';
67 $MeetItem->Message = '';
68 $MeetItem->Phone = '';
69 $MeetItem->Height = '';
70 $MeetItem->Weight = '';
71 $MeetItem->Age = '';
72 $MeetItem->Location = '';
73 $MeetItem->Database = $this->Database;
74 $MeetItem->Source = $this->Id;
75 $Output .= $this->ImportItem($MeetItem);
76 $this->MeetItems[] = $MeetItem;
77 }
78 return $Output;
79 }
80
81 function ImportItem(MeetItem &$MeetItem): string
82 {
83 global $HeightTags, $AgeTags, $LevelTags;
84
85 $Output = '';
86 $Content = file_get_contents($MeetItem->Link);
87
88 $BlockStart = '<div class="dwqa-container" >';
89 $BlockEnd = '<div class="social-bookmark">';
90 $Content = GetTextBetween($Content, $BlockStart, $BlockEnd);
91 if ($Content == '')
92 {
93 $Output .= 'Main block not isolated.</br>';
94 return $Output;
95 }
96
97 $MeetItem->Message = trim(strip_tags(GetTextBetween($Content, '<div class="dwqa-content">', '</div>')));
98 $MeetItem->Age = GetAgeFromText($MeetItem->Message);
99 $MeetItem->Height = GetHeightFromText($MeetItem->Message);
100 $MeetItem->Weight = GetWeightFromText($MeetItem->Message);
101 $MeetItem->Email = GetEmailFromText($MeetItem->Message);
102 $Tags = trim(GetTextBetween($Content, '<div class="dwqa-tags">', '</div>'));
103 while (strpos($Tags, 'rel="tag">') !== false)
104 {
105 $Tag = trim(strip_tags(GetTextBetween($Tags, 'rel="tag">', '</a>')));
106 if (array_key_exists($Tag, $HeightTags) and ($MeetItem->Height == '')) $MeetItem->Height = $HeightTags[$Tag];
107 if (array_key_exists($Tag, $AgeTags) and ($MeetItem->Age == '')) $MeetItem->Age = $AgeTags[$Tag];
108 if (array_key_exists($Tag, $LevelTags) and ($MeetItem->Level == '')) $MeetItem->Level = $LevelTags[$Tag];
109 if ($Tag == 'Praha') $MeetItem->Location = 'Praha';
110 }
111 return $Output;
112 }
113}
Note: See TracBrowser for help on using the repository browser.