1 | <?php
|
---|
2 |
|
---|
3 | include_once('Import/Seznamka.php');
|
---|
4 | include_once('Import/TanecniSkola.php');
|
---|
5 | include_once('Import/AstraPraha.php');
|
---|
6 | include_once('Import/Vavruska.php');
|
---|
7 | include_once('Import/SalsaDance.php');
|
---|
8 | include_once('Import/Amblar.php');
|
---|
9 | include_once('Import/MajkluvSvet.php');
|
---|
10 | include_once('Import/Csts.php');
|
---|
11 |
|
---|
12 | abstract class Gender
|
---|
13 | {
|
---|
14 | const Undefined = 0;
|
---|
15 | const Male = 1;
|
---|
16 | const Female = 2;
|
---|
17 | }
|
---|
18 |
|
---|
19 | function GetTextBetween(&$Text, $Start, $End)
|
---|
20 | {
|
---|
21 | $Result = '';
|
---|
22 | if ((strpos($Text, $Start) !== false) and (strpos($Text, $End) !== false))
|
---|
23 | {
|
---|
24 | $Text = substr($Text, strpos($Text, $Start) + strlen($Start));
|
---|
25 | $Result = substr($Text, 0, strpos($Text, $End));
|
---|
26 | $Text = substr($Text, strpos($Text, $End) + strlen($End));
|
---|
27 | }
|
---|
28 | return $Result;
|
---|
29 | }
|
---|
30 |
|
---|
31 | function HumanDateTimeToTime($DateTime)
|
---|
32 | {
|
---|
33 | if($DateTime == '') return(NULL);
|
---|
34 | $Parts = explode(' ', $DateTime);
|
---|
35 | $DateParts = explode('.', $Parts[0]);
|
---|
36 | $TimeParts = explode(':', $Parts[1]);
|
---|
37 | $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[0], $DateParts[2]);
|
---|
38 | return($Result);
|
---|
39 | }
|
---|
40 |
|
---|
41 | function HumanDateToTime($Date)
|
---|
42 | {
|
---|
43 | if($Date == '') return(NULL);
|
---|
44 | return(HumanDateTimeToTime($Date.' 0:0:0'));
|
---|
45 | }
|
---|
46 |
|
---|
47 | function DecodeHtmlEnt($str)
|
---|
48 | {
|
---|
49 | $prefix = '&#';
|
---|
50 | $suffix = ';';
|
---|
51 | $hexchar = 'x';
|
---|
52 | $ret = html_entity_decode($str, ENT_COMPAT, 'UTF-8');
|
---|
53 | $p2 = 0;
|
---|
54 | for(;;)
|
---|
55 | {
|
---|
56 | $p = strpos($ret, $prefix, $p2);
|
---|
57 | if ($p === FALSE)
|
---|
58 | break;
|
---|
59 | $p2 = strpos($ret, $suffix, $p);
|
---|
60 | if ($p2 === FALSE)
|
---|
61 | {
|
---|
62 | $p2 = $p + strlen($prefix);
|
---|
63 | while (($p2 < strlen($ret)) and is_numeric($ret[$p2]))
|
---|
64 | $p2++;
|
---|
65 | if ($p2 <= ($p + strlen($prefix))) break;
|
---|
66 | $add = 0;
|
---|
67 | } else $add = 1;
|
---|
68 |
|
---|
69 | if (substr($ret, $p + strlen($prefix), strlen($hexchar)) == $hexchar)
|
---|
70 | $char = hexdec(substr($ret, $p + strlen($prefix) + strlen($hexchar), $p2 - $p - strlen($prefix) - strlen($hexchar)));
|
---|
71 | else
|
---|
72 | $char = intval(substr($ret, $p + strlen($prefix), $p2 - $p - strlen($prefix)));
|
---|
73 |
|
---|
74 | $newchar = iconv(
|
---|
75 | 'UCS-4', 'UTF-8',
|
---|
76 | chr(($char >> 24) & 0xFF).chr(($char >> 16) & 0xFF).chr(($char >> 8) & 0xFF).chr($char & 0xFF)
|
---|
77 | );
|
---|
78 | $ret = substr_replace($ret, $newchar, $p, $add + $p2 - $p);
|
---|
79 | $p2 = $p + strlen($newchar) + $add;
|
---|
80 | }
|
---|
81 | return $ret;
|
---|
82 | }
|
---|
83 |
|
---|
84 | function RemoveHtmlComments($Content)
|
---|
85 | {
|
---|
86 | $Result = '';
|
---|
87 | while (strpos($Content, '<!--') !== false)
|
---|
88 | {
|
---|
89 | $Result .= substr($Content, 0, strpos($Content, '<!--'));
|
---|
90 | $Content = substr($Content, strpos($Content, '<!--') + 4);
|
---|
91 | $Content = substr($Content, strpos($Content, '-->') + 3);
|
---|
92 | }
|
---|
93 | return $Result;
|
---|
94 | //return preg_replace('/<!--(.|\s)*?-->/', '', $Content);
|
---|
95 | }
|
---|
96 |
|
---|
97 | function is_alpha($Char)
|
---|
98 | {
|
---|
99 | return ((($Char >= 'a') and ($Char <= 'z')) or (($Char >= 'A') and ($Char <= 'Z')));
|
---|
100 | }
|
---|
101 |
|
---|
102 | function GetNumberBeforeText($Text, $Needle)
|
---|
103 | {
|
---|
104 | $Result = '';
|
---|
105 | for(;;)
|
---|
106 | {
|
---|
107 | $Pos = strpos($Text, $Needle);
|
---|
108 | if ($Pos !== false)
|
---|
109 | {
|
---|
110 | if ((($Pos + strlen($Needle)) < strlen($Text)) and (is_alpha($Text[$Pos + strlen($Needle)])))
|
---|
111 | {
|
---|
112 | $Text = substr($Text, $Pos + 1);
|
---|
113 | continue;
|
---|
114 | }
|
---|
115 | $Result = substr($Text, 0, $Pos);
|
---|
116 | $Text = substr($Text, $Pos + 1);
|
---|
117 | $Start = $Pos - 1;
|
---|
118 | while (($Start >= 0) and (is_numeric($Result[$Start]) or ($Result[$Start] == ' ')))
|
---|
119 | $Start--;
|
---|
120 | $Start++;
|
---|
121 | $Result = trim(substr($Result, $Start, $Pos - $Start));
|
---|
122 | break;
|
---|
123 | } else break;
|
---|
124 | }
|
---|
125 | return $Result;
|
---|
126 | }
|
---|
127 |
|
---|
128 | function GetNumberAfterText($Text, $Needle)
|
---|
129 | {
|
---|
130 | $Result = '';
|
---|
131 | for(;;)
|
---|
132 | {
|
---|
133 | $Pos = strpos($Text, $Needle);
|
---|
134 | if ($Pos !== false)
|
---|
135 | {
|
---|
136 | if ((($Pos - 1) >= 0) and (is_alpha($Text[$Pos - 1])))
|
---|
137 | {
|
---|
138 | $Text = substr($Text, $Pos + 1);
|
---|
139 | continue;
|
---|
140 | }
|
---|
141 | $Result = substr($Text, $Pos + strlen($Needle));
|
---|
142 | $Text = substr($Text, $Pos + 1);
|
---|
143 | $End = 0;
|
---|
144 | while (($End < strlen($Result)) and (is_numeric($Result[$End]) or ($Result[$End] == ' ')))
|
---|
145 | $End++;
|
---|
146 | $End--;
|
---|
147 |
|
---|
148 | $Result = trim(substr($Result, 0, $End + 1));
|
---|
149 | if (is_numeric($Result)) break;
|
---|
150 | } else break;
|
---|
151 | }
|
---|
152 | return $Result;
|
---|
153 | }
|
---|
154 |
|
---|
155 | function GetAgeFromText($Text)
|
---|
156 | {
|
---|
157 | $Text = strtolower($Text);
|
---|
158 | $Result = GetNumberBeforeText($Text, 'let');
|
---|
159 | if ($Result == '') $Result = GetNumberBeforeText($Text, 'rokov');
|
---|
160 | if ($Result == '') $Result = GetNumberBeforeText($Text, 'letou');
|
---|
161 | if ($Result == '') $Result = GetNumberAfterText($Text, 'je mi');
|
---|
162 | if ($Result == '') $Result = GetNumberAfterText($Text, 'jsem');
|
---|
163 | if ($Result == '') $Result = GetNumberAfterText($Text, 'čerstvých');
|
---|
164 | if ($Result == '') $Result = GetAgeHeightWeightFromText($Text)[0];
|
---|
165 | if ($Result == '') $Result = date('Y', time()) - GetNumberAfterText($Text, 'ročník');
|
---|
166 | return $Result;
|
---|
167 | }
|
---|
168 |
|
---|
169 | function GetHeightFromText($Text)
|
---|
170 | {
|
---|
171 | $Text = strtolower($Text);
|
---|
172 | $Result = GetNumberBeforeText($Text, 'cm');
|
---|
173 | if ($Result == '') $Result = GetNumberAfterText($Text, 'měřím');
|
---|
174 | if ($Result == '') $Result = GetNumberAfterText($Text, 'merim');
|
---|
175 | if ($Result == '') $Result = GetNumberBeforeText($Text, 'bez podpatků');
|
---|
176 | if ($Result == '') $Result = GetAgeHeightWeightFromText($Text)[1];
|
---|
177 | return $Result;
|
---|
178 | }
|
---|
179 |
|
---|
180 | function GetWeightFromText($Text)
|
---|
181 | {
|
---|
182 | $Text = strtolower($Text);
|
---|
183 | $Result = GetNumberBeforeText($Text, 'kg');
|
---|
184 | if ($Result == '') $Result = GetAgeHeightWeightFromText($Text)[2];
|
---|
185 | return $Result;
|
---|
186 | }
|
---|
187 |
|
---|
188 | function GetAgeHeightWeightFromText($Text)
|
---|
189 | {
|
---|
190 | $Result = array('', '', '');
|
---|
191 | $Pattern = '/[0-9]+\/[0-9]+\/[0-9]+/i';
|
---|
192 | if (preg_match_all($Pattern, $Text, $Matches))
|
---|
193 | {
|
---|
194 | $Result = explode('/', $Matches[0][0]);
|
---|
195 | // Avoid dates in a form day/month/year
|
---|
196 | if ($Result[2] > 150) $Result = array('', '', '');
|
---|
197 | } else
|
---|
198 | {
|
---|
199 | $Pattern = '/[0-9]+\/[0-9]+/i';
|
---|
200 | if (preg_match_all($Pattern, $Text, $Matches))
|
---|
201 | {
|
---|
202 | $Result = explode('/', $Matches[0][0]);
|
---|
203 | $Result[] = '';
|
---|
204 | }
|
---|
205 | }
|
---|
206 | return $Result;
|
---|
207 | }
|
---|
208 |
|
---|
209 | function GetEmailFromText($Text)
|
---|
210 | {
|
---|
211 | $Result = '';
|
---|
212 | if (strpos($Text, '@') !== false)
|
---|
213 | {
|
---|
214 | $Pattern = '/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
|
---|
215 | preg_match_all($Pattern, $Text, $Matches);
|
---|
216 | if (count($Matches) > 0)
|
---|
217 | $Result = $Matches[0][0];
|
---|
218 | }
|
---|
219 | return $Result;
|
---|
220 | }
|
---|
221 |
|
---|
222 | $Locations = array(
|
---|
223 | 'praha' => 'Praha',
|
---|
224 | 'prahy' => 'Praha',
|
---|
225 | 'praze' => 'Praha',
|
---|
226 | 'brno' => 'Brno',
|
---|
227 | 'brně' => 'Brno',
|
---|
228 | 'ostrava' => 'Ostrava',
|
---|
229 | 'ostravě' => 'Ostrava',
|
---|
230 | 'ostravy' => 'Ostrava',
|
---|
231 | 'olomouc' => 'Olomouc',
|
---|
232 | 'liberec' => 'Liberec',
|
---|
233 | 'opava' => 'Opava',
|
---|
234 | 'opave' => 'Opava',
|
---|
235 | 'plzeň' => 'Plzeň',
|
---|
236 | 'plzni' => 'Plzeň',
|
---|
237 | 'vyškov' => 'Vyškov',
|
---|
238 | 'mladá boleslav' => 'Mladá Boleslav',
|
---|
239 | 'mladé boleslavi' => 'Mladá Boleslav',
|
---|
240 | 'litoměřice' => 'Litoměřice',
|
---|
241 | 'sokolov' => 'Sokolov',
|
---|
242 | 'mikulov' => 'Mikulov',
|
---|
243 | );
|
---|
244 |
|
---|
245 | function GetLocationFromText($Text)
|
---|
246 | {
|
---|
247 | global $Locations;
|
---|
248 |
|
---|
249 | $Text = strtolower($Text);
|
---|
250 |
|
---|
251 | foreach ($Locations as $Index => $Location)
|
---|
252 | {
|
---|
253 | if (strpos($Text, $Index) !== false) return $Location;
|
---|
254 | }
|
---|
255 | return '';
|
---|
256 | }
|
---|
257 |
|
---|
258 | class MeetSources
|
---|
259 | {
|
---|
260 | public $Database;
|
---|
261 |
|
---|
262 | function Parse($Id = null)
|
---|
263 | {
|
---|
264 | if (($Id != null) and is_numeric($Id)) $Where = 'Id='.$Id;
|
---|
265 | else $Where = '1';
|
---|
266 | $DbResult = $this->Database->select('MeetSource', '*', $Where);
|
---|
267 | while ($DbRow = $DbResult->fetch_assoc())
|
---|
268 | {
|
---|
269 | $Method = $DbRow['Method'];
|
---|
270 | if ($Method == 'hes') $Source = new MeetSourceTanecniSkola();
|
---|
271 | else if ($Method == 'vavruska') $Source = new MeetSourceVavruska();
|
---|
272 | else if ($Method == 'salsadance') $Source = new MeetSourceSalsaDance();
|
---|
273 | else if ($Method == 'astra') $Source = new MeetSourceAstraPraha();
|
---|
274 | else if ($Method == 'seznamka') $Source = new MeetSourceSeznamka();
|
---|
275 | else if ($Method == 'amblar') $Source = new MeetSourceAmblar();
|
---|
276 | else if ($Method == 'majkluvsvet') $Source = new MeetSourceMajkluvSvet();
|
---|
277 | else if ($Method == 'csts') $Source = new MeetSourceCsts();
|
---|
278 | else {
|
---|
279 | echo('Unsupported parse method: '.$Method.'<br/>');
|
---|
280 | continue;
|
---|
281 | }
|
---|
282 | $Source->Database = $this->Database;
|
---|
283 | $Source->Id = $DbRow['Id'];
|
---|
284 | $Source->URL = $DbRow['URL'];
|
---|
285 | $Source->Method = $Method;
|
---|
286 | $Source->Name = $DbRow['Name'];
|
---|
287 | $this->Items[] = $Source;
|
---|
288 | $Source->Import();
|
---|
289 | }
|
---|
290 | }
|
---|
291 | }
|
---|
292 |
|
---|
293 | class MeetSource
|
---|
294 | {
|
---|
295 | public $Name;
|
---|
296 | public $URL;
|
---|
297 | public $Method;
|
---|
298 | public $Id;
|
---|
299 | public $Database;
|
---|
300 |
|
---|
301 | function Import()
|
---|
302 | {
|
---|
303 | $this->AddedCount = 0;
|
---|
304 | echo('Parsing '.$this->Name.' ('.$this->Id.')...</br>');
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | class MeetItem
|
---|
309 | {
|
---|
310 | var $Database;
|
---|
311 | var $Name = '';
|
---|
312 | var $Message = '';
|
---|
313 | var $Date = '';
|
---|
314 | var $Gender = Gender::Undefined;
|
---|
315 | var $Phone = '';
|
---|
316 | var $Email = '';
|
---|
317 | var $Age = '';
|
---|
318 | var $Height = '';
|
---|
319 | var $Source = 0;
|
---|
320 | var $Weight = '';
|
---|
321 | var $Location = '';
|
---|
322 | var $Image = '';
|
---|
323 | var $Link = '';
|
---|
324 | var $Title = '';
|
---|
325 | var $Level = '';
|
---|
326 |
|
---|
327 | function AddIfNotExist()
|
---|
328 | {
|
---|
329 | $DbResult = $this->Database->select('MeetItem', '*',
|
---|
330 | '(`Message` = "'.$this->Database->real_escape_string($this->Message).'") AND '.
|
---|
331 | '(`Email` = "'.$this->Database->real_escape_string($this->Email).'") AND '.
|
---|
332 | '(`Date` = "'.$this->Database->real_escape_string(TimeToMysqlDate($this->Date)).'")');
|
---|
333 | if ($DbResult->num_rows == 0)
|
---|
334 | {
|
---|
335 | $this->Database->insert('MeetItem', array(
|
---|
336 | 'Message' => $this->Message,
|
---|
337 | 'Date' => TimeToMysqlDate($this->Date),
|
---|
338 | 'Gender' => $this->Gender,
|
---|
339 | 'Age' => $this->Age,
|
---|
340 | 'Email' => $this->Email,
|
---|
341 | 'Phone' => $this->Phone,
|
---|
342 | 'Name' => $this->Name,
|
---|
343 | 'Height' => $this->Height,
|
---|
344 | 'Weight' => $this->Weight,
|
---|
345 | 'Location' => $this->Location,
|
---|
346 | 'Source' => $this->Source,
|
---|
347 | 'Link' => $this->Link,
|
---|
348 | ));
|
---|
349 | $Result = 1;
|
---|
350 | } else $Result = 0;
|
---|
351 | return($Result);
|
---|
352 | }
|
---|
353 | }
|
---|