mirror of
https://github.com/ivuorinen/BassoFeed.git
synced 2026-02-20 20:50:36 +00:00
Working on multiple show feed, still mostly broken
This commit is contained in:
112
bassofeed.php
112
bassofeed.php
@@ -49,13 +49,49 @@ class BassoFeed {
|
|||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
var $from_cache = 0;
|
var $from_cache = 0;
|
||||||
|
/**
|
||||||
|
* Dealing with multiple shows?
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
var $multiple_shows = false;
|
||||||
|
|
||||||
function __construct($show) {
|
function __construct($show) {
|
||||||
$this->show = $show;
|
|
||||||
$this->cachefile = "./cache/{$this->show}.txt";
|
|
||||||
$this->cachetime = 900;
|
|
||||||
|
|
||||||
$this->generate();
|
if( is_array($show) ) {
|
||||||
|
$this->multiple_shows = true;
|
||||||
|
$this->multiple($show);
|
||||||
|
$this->get_ical();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->multiple_shows = false;
|
||||||
|
$this->show = $show;
|
||||||
|
$this->cachefile = "./cache/{$this->show}.txt";
|
||||||
|
$this->cachetime = 900;
|
||||||
|
|
||||||
|
$this->generate();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function multiple($array = array()) {
|
||||||
|
|
||||||
|
if( !empty($array) ) {
|
||||||
|
$this->cachetime = 900;
|
||||||
|
$alltimes = array();
|
||||||
|
|
||||||
|
foreach ($array as $show) {
|
||||||
|
|
||||||
|
$this->show = $show;
|
||||||
|
$this->cachefile = "./cache/{$this->show}.txt";
|
||||||
|
$data = $this->cache();
|
||||||
|
|
||||||
|
$this->showtimes[$show] = $this->get_showtimes($data);
|
||||||
|
$this->showinfo[$show] = $this->get_showinfo($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,13 +136,13 @@ class BassoFeed {
|
|||||||
$fetch = file_get_html(
|
$fetch = file_get_html(
|
||||||
"http://www.basso.fi/radio/" . $this->show
|
"http://www.basso.fi/radio/" . $this->show
|
||||||
);
|
);
|
||||||
|
|
||||||
// Service is being updated
|
// Service is being updated
|
||||||
if( preg_match( '/Palvelua/i', $fetch) ) {
|
if( preg_match( '/Palvelua/i', $fetch) ) {
|
||||||
$this->from_cache = true;
|
$this->from_cache = true;
|
||||||
return file_get_html($this->cachefile);
|
return file_get_html($this->cachefile);
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents($this->cachefile, $fetch);
|
file_put_contents($this->cachefile, $fetch);
|
||||||
$this->from_cache = false;
|
$this->from_cache = false;
|
||||||
return $fetch;
|
return $fetch;
|
||||||
@@ -216,6 +252,7 @@ class BassoFeed {
|
|||||||
$data = array(
|
$data = array(
|
||||||
"title" => str_replace(";", "\;", $title),
|
"title" => str_replace(";", "\;", $title),
|
||||||
"desc" => str_replace(";", "\;", $desc),
|
"desc" => str_replace(";", "\;", $desc),
|
||||||
|
"desc" => str_replace(",", "\,", $desc),
|
||||||
"url" => "http://www.basso.fi/radio/" . $this->show
|
"url" => "http://www.basso.fi/radio/" . $this->show
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -231,31 +268,58 @@ class BassoFeed {
|
|||||||
* @author Ismo Vuorinen
|
* @author Ismo Vuorinen
|
||||||
* */
|
* */
|
||||||
function get_ical() {
|
function get_ical() {
|
||||||
|
|
||||||
$cal = "BEGIN:VCALENDAR\n"
|
$cal = "BEGIN:VCALENDAR\n"
|
||||||
. "X-WR-CALNAME:{$this->showinfo["title"]}\n"
|
|
||||||
. "PRODID:-//BASSOFEED/FEED/EN\n"
|
|
||||||
. "VERSION:2.0\n"
|
. "VERSION:2.0\n"
|
||||||
|
. "X-WR-CALNAME:BassoRadioFeed\n"
|
||||||
|
. "PRODID:-//BASSOFEED/FEED/EN\n"
|
||||||
. "CALSCALE:GREGORIAN\n"
|
. "CALSCALE:GREGORIAN\n"
|
||||||
. "X-WR-TIMEZONE:Europe/Helsinki\n"
|
. "X-WR-TIMEZONE:Europe/Helsinki\n"
|
||||||
. "METHOD:PUBLISH\n";
|
. "METHOD:PUBLISH\n";
|
||||||
|
|
||||||
foreach ($this->showtimes as $i) {
|
if( $this->multiple_shows ) {
|
||||||
|
foreach ($this->showinfo as $show => $info) {
|
||||||
|
|
||||||
|
foreach ($this->showtimes[$show] as $i) {
|
||||||
|
$cal .= "BEGIN:VEVENT\n"
|
||||||
|
. "SUMMARY:{$this->showinfo[$show]["title"]}\n"
|
||||||
|
. "DESCRIPTION:{$this->showinfo[$show]["desc"]}\n"
|
||||||
|
. "LOCATION:Basso Radio 102.8 FM\n"
|
||||||
|
. "UID:{$this->show}-{$i["date_f"]}/basso.fi\n"
|
||||||
|
. "URL:http://basso.fi/radio/{$this->show}\n"
|
||||||
|
. "DTSTART;VALUE=DATE-TIME;TZID=GMT:{$i["date_f"]}\n"
|
||||||
|
. "DTEND;VALUE=DATE-TIME;TZID=GMT:{$i["date_t"]}\n"
|
||||||
|
. "DTSTAMP:{$i["date_f"]}\n"
|
||||||
|
. "BEGIN:VALARM\n"
|
||||||
|
. "TRIGGER:-PT15M\n"
|
||||||
|
. "ACTION:DISPLAY\n"
|
||||||
|
. "DESCRIPTION:{$this->showinfo[$show]["title"]}\n"
|
||||||
|
. "END:VALARM\n"
|
||||||
|
. "END:VEVENT\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// One show info gets looped
|
||||||
|
foreach ($this->showtimes as $i) {
|
||||||
|
|
||||||
|
$cal .= "BEGIN:VEVENT\n"
|
||||||
|
. "SUMMARY:{$this->showinfo["title"]}\n"
|
||||||
|
. "DESCRIPTION:{$this->showinfo["desc"]}\n"
|
||||||
|
. "LOCATION:Basso Radio 102.8 FM\n"
|
||||||
|
. "UID:{$this->show}-{$i["date_f"]}/basso.fi\n"
|
||||||
|
. "URL:http://basso.fi/radio/{$this->show}\n"
|
||||||
|
. "DTSTART;VALUE=DATE-TIME;TZID=GMT:{$i["date_f"]}\n"
|
||||||
|
. "DTEND;VALUE=DATE-TIME;TZID=GMT:{$i["date_t"]}\n"
|
||||||
|
. "DTSTAMP:{$i["date_f"]}\n"
|
||||||
|
. "BEGIN:VALARM\n"
|
||||||
|
. "TRIGGER:-PT15M\n"
|
||||||
|
. "ACTION:DISPLAY\n"
|
||||||
|
. "DESCRIPTION:{$this->showinfo["title"]}\n"
|
||||||
|
. "END:VALARM\n"
|
||||||
|
. "END:VEVENT\n";
|
||||||
|
}
|
||||||
|
|
||||||
$cal .= "BEGIN:VEVENT\n"
|
|
||||||
. "SUMMARY:{$this->showinfo["title"]}\n"
|
|
||||||
. "DESCRIPTION:{$this->showinfo["desc"]}\n"
|
|
||||||
. "LOCATION:Basso Radio 102.8 FM\n"
|
|
||||||
. "UID:{$this->show}-{$i["date_f"]}/basso.fi\n"
|
|
||||||
. "URL:http://basso.fi/radio/{$this->show}\n"
|
|
||||||
. "DTSTART;VALUE=DATE-TIME;TZID=GMT:{$i["date_f"]}\n"
|
|
||||||
. "DTEND;VALUE=DATE-TIME;TZID=GMT:{$i["date_t"]}\n"
|
|
||||||
. "DTSTAMP:{$i["date_f"]}\n"
|
|
||||||
. "BEGIN:VALARM\n"
|
|
||||||
. "TRIGGER:-PT15M\n"
|
|
||||||
. "ACTION:DISPLAY\n"
|
|
||||||
. "DESCRIPTION:{$this->showinfo["title"]}\n"
|
|
||||||
. "END:VALARM\n"
|
|
||||||
. "END:VEVENT\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$cal .= "END:VCALENDAR\n";
|
$cal .= "END:VCALENDAR\n";
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
header('Content-Type: text/calendar; charset=utf-8');
|
#header('Content-Type: text/calendar; charset=utf-8');
|
||||||
|
error_reporting(E_ALL ^ E_NOTICE);
|
||||||
date_default_timezone_set('Europe/Helsinki');
|
date_default_timezone_set('Europe/Helsinki');
|
||||||
|
|
||||||
require_once("simple_html_dom.php");
|
require_once("simple_html_dom.php");
|
||||||
@@ -8,3 +9,8 @@ require_once("bassofeed.php");
|
|||||||
#echo "<pre>";
|
#echo "<pre>";
|
||||||
$basso_alas = new BassoFeed('alas');
|
$basso_alas = new BassoFeed('alas');
|
||||||
echo $basso_alas->get_ical();
|
echo $basso_alas->get_ical();
|
||||||
|
|
||||||
|
echo "\n----------------------------\n\n\n\n";
|
||||||
|
|
||||||
|
$basso_multiple = new BassoFeed(array('alas', 'darkdays'));
|
||||||
|
echo $basso_multiple->get_ical();
|
||||||
Reference in New Issue
Block a user