From 11a92936e370ce4bb35398a0f373f113ae72bd98 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sun, 04 Nov 2012 17:29:29 +0000
Subject: [PATCH] Poprawka błędu typu "Undefined property: PDOStatement::$rowCount" w pliku ./class/BotSession.php

---
 modules/70_kino/handler.php |   51 +++++++++++++++++++++++++++------------------------
 1 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/modules/70_kino/handler.php b/modules/70_kino/handler.php
index 93b5304..b22ddf9 100644
--- a/modules/70_kino/handler.php
+++ b/modules/70_kino/handler.php
@@ -1,33 +1,19 @@
 <?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;
 	}
@@ -59,7 +45,7 @@
 		
 		foreach($dane as $kino) {
 			$name = trim($kino->textContent);
-			$return[$name] = $kino->getAttribute('name');
+			$return[$name] = $kino->getAttribute('href');
 		}
 		
 		return $return;
@@ -70,19 +56,34 @@
 		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(
@@ -97,6 +98,7 @@
 	
 	function ustaw($msg, $params) {
 		$arg = funcs::utfToAscii($msg->args);
+		$msg->session->setClass('kino');
 		
 		if(empty($arg)) {
 			unset($msg->session->kino);
@@ -112,6 +114,7 @@
 	
 	function handle($msg, $params) {
 		$arg = funcs::utfToAscii($msg->args);
+		$msg->session->setClass('kino');
 		
 		if(empty($arg)) {
 			$arg = $msg->session->kino;

--
Gitblit v1.9.1