Event cinema RSS v1
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/.buildpath
|
||||
/.project
|
||||
/.settings
|
||||
1
db.json
Normal file
1
db.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Ghost in the Shell":{"title":"Ghost in the Shell","dates":"13 - 19 April"}}
|
||||
132
inc/eventcinema.php
Normal file
132
inc/eventcinema.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
class EventCinema extends PhpObject
|
||||
{
|
||||
//DB
|
||||
const DB = 'db.json';
|
||||
private $asMovies;
|
||||
|
||||
//Remote
|
||||
const PROM_LINK = 'https://www.eventcinemas.co.nz/Promotions/MembersMovieOfTheWeek#cinemas=502';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
10
index.php
Normal file
10
index.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
require_once '../objects/class_management.php';
|
||||
|
||||
$oClassManagement = new ClassManagement('eventcinema');
|
||||
$oClassManagement->incClass('rss');
|
||||
|
||||
$oEventCinema = new EventCinema();
|
||||
|
||||
echo $oEventCinema->getRss();
|
||||
7
settings.php
Normal file
7
settings.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
class Settings
|
||||
{
|
||||
const DEBUG = true;
|
||||
const TEXT_ENC = 'UTF-8';
|
||||
}
|
||||
Reference in New Issue
Block a user