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(); } }