diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66f6d1d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.buildpath +/.project +/.settings diff --git a/db.json b/db.json new file mode 100644 index 0000000..3732acf --- /dev/null +++ b/db.json @@ -0,0 +1 @@ +{"Ghost in the Shell":{"title":"Ghost in the Shell","dates":"13 - 19 April"}} \ No newline at end of file diff --git a/inc/eventcinema.php b/inc/eventcinema.php new file mode 100644 index 0000000..fc53bda --- /dev/null +++ b/inc/eventcinema.php @@ -0,0 +1,132 @@ +loadMoviesFromDb(); + $this->addMovieOfTheWeek(); + } + + private function loadMoviesFromDb() + { + if(!file_exists(self::DB)) $this->asMovies = array(); + else + { + $sContent = file_get_contents(self::DB); + $this->asMovies = json_decode($sContent==''?'{}':$sContent, true); + } + } + + private function saveMovieToDb() + { + $sContent= json_encode($this->asMovies); + file_put_contents(self::DB, $sContent); + } + + private function getCurl($sUrl, $bHeader=false, $asPostData=array()) + { + $oCurl = curl_init(); + + curl_setopt($oCurl, CURLOPT_URL, $sUrl); + curl_setopt($oCurl, CURLOPT_HEADER, $bHeader); + if(!empty($asPostData)) + { + curl_setopt($oCurl, CURLOPT_POST, count($asPostData)); + curl_setopt($oCurl, CURLOPT_POSTFIELDS, $asPostData); + } + + curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true); + + //Fake browser + curl_setopt($oCurl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); + //if($this->sReferer!='') curl_setopt($oCurl, CURLOPT_REFERER, $this->sReferer); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); + //if($bHeader) curl_setopt($oCurl, CURLOPT_FOLLOWLOCATION, true); + + //Cookies + //$sCookies = $this->getCookies(); + //if($sCookies!='') curl_setopt($oCurl, CURLOPT_COOKIE, $sCookies); + $fCookieJar = tempnam('/tmp','cookie'); + curl_setopt($oCurl, CURLOPT_COOKIESESSION, true); + curl_setopt($oCurl, CURLOPT_COOKIEJAR, $fCookieJar); + curl_setopt($oCurl, CURLOPT_COOKIEFILE, $fCookieJar); + + $sContent = curl_exec($oCurl); + + curl_close($oCurl); + //$this->sReferer = $sUrl; + return $sContent; + } + + private function addMovieOfTheWeek() + { + $asNewMovie = $this->getMovieOfTheWeek(); + $sTitle = $asNewMovie['title']; + + //Merge with DB + if(!array_key_exists($sTitle, $this->asMovies)) + { + $this->asMovies = array($sTitle=>$asNewMovie) + $this->asMovies; + } + else $this->asMovies[$sTitle] = $asNewMovie; + + $this->saveMovieToDb(); + } + + private function getMovieOfTheWeek() + { + //Get Event Cinema Page + $sContent = $this->getCurl(self::PROM_LINK); + + //Build DOM + $oDom = new DOMDocument(); + @$oDom->loadHTML($sContent); + $oXPath = new DOMXPath($oDom); + + //Get header object + $oHeader = $oXPath->query('//*[@class="header-title"]//*[@class="featured-name arrow-top small"]')->item(0)->childNodes; + $sTitle = $oHeader->item(3)->nodeValue; + $aoDetails = $oHeader->item(5)->childNodes; + $sDates = mb_substr($aoDetails->item(1)->nodeValue, 6); + + return array('title'=>$sTitle, 'dates'=>$sDates); + } + + public function getRss() + { + $asDesc = array + ( + 'title'=>'Rarbg RSS Feed', + 'link'=>'', + 'copyright'=>'Powered by Franzz. RSS Feed Generator under GPLv3 License', + 'description'=>'Rarbg RSS Feed', + 'language'=>'en', + 'webmaster_mail'=>'franzz@gmail.com' + ); + $oFeed = new Feed($asDesc); + + foreach($this->asMovies as $asMovie) + { + $asItem = array(); + $asItem['title'] = $asMovie['title']; + $asItem['link'] = self::PROM_LINK; + $asItem['guid'] = $asMovie['title']; + $asItem['category'] = 'Movies'; + $asItem['pub_date'] = date('r'); + $asItem['author'] = 'Event Cinema - Queen Street'; + $asItem['description'] = $asMovie['dates'].' '.date('Y'); + + $oFeed->addItem($asItem); + } + + return $oFeed->getFeed(); + } +} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..e8adc70 --- /dev/null +++ b/index.php @@ -0,0 +1,10 @@ +incClass('rss'); + +$oEventCinema = new EventCinema(); + +echo $oEventCinema->getRss(); \ No newline at end of file diff --git a/settings.php b/settings.php new file mode 100644 index 0000000..c142e55 --- /dev/null +++ b/settings.php @@ -0,0 +1,7 @@ +