| | |
| | | <?php |
| | | class bot_kino_module implements BotModule { |
| | | function cache($url) { |
| | | $time = '+2 hour'; |
| | | $dir = './data/kino/cache/'; |
| | | |
| | | if(file_exists($dir.md5($url))) { |
| | | $mtime = @filemtime($dir.md5($url)); |
| | | } |
| | | |
| | | if($mtime && $mtime > strtotime('today '.$time) && $mtime < strtotime('tomorrow '.$time)) { |
| | | $dane = file_get_contents($dir.md5($url)); |
| | | } |
| | | else |
| | | { |
| | | $dane = @file_get_contents($url); |
| | | if(!$dane) { |
| | | return FALSE; |
| | | } |
| | | |
| | | file_put_contents($dir.md5($url), $dane); |
| | | } |
| | | $down = new DownloadHelper($url); |
| | | $dane = $down->exec(); |
| | | |
| | | libxml_use_internal_errors(TRUE); |
| | | |
| | | $dom = new DOMDocument(); |
| | | if(!$dom->loadHTML($dane)) { |
| | | libxml_use_internal_errors(FALSE); |
| | | $down->cacheFor(1800); |
| | | return FALSE; |
| | | } |
| | | |
| | | $down->cacheUntil(strtotime('tomorrow midnight')); |
| | | |
| | | return $dom; |
| | | } |
| | |
| | | |
| | | foreach($dane as $kino) { |
| | | $name = trim($kino->textContent); |
| | | $return[$name] = $kino->getAttribute('name'); |
| | | $return[$name] = $kino->getAttribute('href'); |
| | | } |
| | | |
| | | return $return; |
| | |
| | | if(!$xml) return FALSE; |
| | | |
| | | $xpath = new DOMXPath($xml); |
| | | $dane = $xpath->query('//div[@id=\'mainContent\']/table//a[@name=\''.$kino.'\']/../../following-sibling::tr'); |
| | | $dane = $xpath->query('//div[@id=\'mainContent\']/table//a[@href=\''.$kino.'\']/../../following-sibling::tr'); |
| | | $return = array(); |
| | | |
| | | foreach($dane as $film) { |
| | | if($film->firstChild && $film->firstChild->nodeName == 'th') break; |
| | | if(!$film->firstChild) { |
| | | break; |
| | | } |
| | | if($film->firstChild->nodeName == 'th') { |
| | | break; |
| | | } |
| | | if($film->firstChild->nodeName != 'td') { |
| | | break; |
| | | } |
| | | |
| | | $tds = $xpath->query('td', $film); |
| | | $name = $xpath->query('a[1]', $tds->item(0)); |
| | | |
| | | $more = array(); |
| | | $more_xml = $xpath->query('span[@class=\'reper\']/span', $tds->item(0)); |
| | | $more_desc = array( |
| | | 's3d-movie' => '3D', |
| | | 'dubbing-movie' => 'dubbing', |
| | | ); |
| | | $more_xml = $xpath->query('span[@class=\'reper\']/div', $tds->item(0)); |
| | | foreach($more_xml as $more_x) { |
| | | $more[] = $more_x->textContent; |
| | | $more_x = $more_x->getAttribute('class'); |
| | | if(isset($more_desc[$more_x])) { |
| | | $more[] = $more_desc[$more_x]; |
| | | } |
| | | } |
| | | |
| | | $return[] = array( |
| | |
| | | |
| | | function ustaw($msg, $params) { |
| | | $arg = funcs::utfToAscii($msg->args); |
| | | $msg->session->setClass('kino'); |
| | | |
| | | if(empty($arg)) { |
| | | unset($msg->session->kino); |
| | |
| | | |
| | | function handle($msg, $params) { |
| | | $arg = funcs::utfToAscii($msg->args); |
| | | $msg->session->setClass('kino'); |
| | | |
| | | if(empty($arg)) { |
| | | $arg = $msg->session->kino; |
| | |
| | | MIASTO |
| | | */ |
| | | $miasta = self::getMiasta(); |
| | | $found = FALSE; |
| | | $miasto_num = $miasto_nazw = ''; |
| | | |
| | | if(!$miasta) { |
| | |
| | | foreach($miasta as $miasto => $numer) { |
| | | $szukaj = funcs::utfToAscii($miasto); |
| | | if(($pos = strpos($arg, $szukaj)) !== FALSE) { |
| | | $found = TRUE; |
| | | $miasto_nazw = htmlspecialchars($miasto); |
| | | $miasto_num = $numer; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | if($found===FALSE && !empty($arg2)) { |
| | | if($miasto_num === '' && !empty($arg2)) { |
| | | foreach($miasta as $miasto => $numer) { |
| | | $szukaj = funcs::utfToAscii($miasto); |
| | | if(($pos = strpos($arg2, $szukaj)) !== FALSE) { |
| | | $found = TRUE; |
| | | $miasto_nazw = htmlspecialchars($miasto); |
| | | $miasto_num = $numer; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | if($found === FALSE) { |
| | | if($miasto_num === '') { |
| | | $txt = 'Wybrane miasto nie został odnalezione. Obsługiwane miejscowości:'; |
| | | $miasto = 'Warszawa'; |
| | | foreach($miasta as $miasto => $num) { |
| | | $txt .= '<br />'."\n".htmlspecialchars($miasto); |
| | | } |
| | |
| | | KINO |
| | | */ |
| | | $kina = self::getKina($miasto_num, $czas); |
| | | $found = FALSE; |
| | | $kino_num = $kino_nazw = ''; |
| | | |
| | | if(!$kina) { |
| | |
| | | if(!empty($arg)) { |
| | | foreach($kina as $kino => $kino_id) { |
| | | if(levenshtein(funcs::utfToAscii($kino), $arg, 1, 1, 0) < 2) { |
| | | $found = TRUE; |
| | | $kino_num = $kino_id; |
| | | $kino_nazw = htmlspecialchars($kino); |
| | | break; |
| | |
| | | } |
| | | } |
| | | |
| | | if($found===FALSE && !empty($arg2)) { |
| | | if($kino_num === '' && !empty($arg2)) { |
| | | foreach($kina as $kino => $kino_id) { |
| | | if(levenshtein(funcs::utfToAscii($kino), $arg2, 1, 1, 0) < 2) { |
| | | $found = TRUE; |
| | | $kino_num = $kino_id; |
| | | $kino_nazw = htmlspecialchars($kino); |
| | | break; |
| | |
| | | } |
| | | } |
| | | |
| | | if($found === FALSE) { |
| | | if($kino_num === '') { |
| | | $txt = (!empty($arg) ? 'Podany obiekt nie został znaleziony. ' : '').'Dostępne kina w pasujących miastach:'; |
| | | $kino = ''; |
| | | foreach($kina as $kino => $num) { |
| | | $txt .= '<br />'."\n".$miasto_nazw.' '.htmlspecialchars($kino); |
| | | } |
| | |
| | | /* |
| | | REPERTUAR |
| | | */ |
| | | $filmy = self::getKino($miasto_num, $kino_id, $czas); |
| | | $filmy = self::getKino($miasto_num, $kino_num, $czas); |
| | | |
| | | if(!$filmy) { |
| | | return new BotMsg('Przepraszamy, wystąpił bład przy pobieraniu listy wyświelanych filmów.'); |