mirror of
https://github.com/ivuorinen/BassoFeed.git
synced 2026-03-21 00:01:51 +00:00
Trying new ical style, could this work?
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basso Radio Showtimes
|
* Basso Radio Showtimes
|
||||||
*
|
*
|
||||||
@@ -16,46 +17,40 @@
|
|||||||
* @todo Documentation
|
* @todo Documentation
|
||||||
* @todo More testing
|
* @todo More testing
|
||||||
* */
|
* */
|
||||||
class BassoFeed
|
class BassoFeed {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Show you listen to
|
* Show you listen to
|
||||||
* @var string
|
* @var string
|
||||||
* */
|
* */
|
||||||
var $show;
|
var $show;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of showtimes
|
* List of showtimes
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $showtimes;
|
var $showtimes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show title, desc, etc.
|
* Show title, desc, etc.
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $showinfo;
|
var $showinfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File (and possibly folder) you use as cache
|
* File (and possibly folder) you use as cache
|
||||||
* @var string Default: "./cache/[show].txt"
|
* @var string Default: "./cache/[show].txt"
|
||||||
*/
|
*/
|
||||||
var $cachefile;
|
var $cachefile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How long the programpage should be cached in seconds
|
* How long the programpage should be cached in seconds
|
||||||
* @var int Default: 900
|
* @var int Default: 900
|
||||||
*/
|
*/
|
||||||
var $cachetime;
|
var $cachetime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the data coming from cache or not
|
* Is the data coming from cache or not
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
var $from_cache = 0;
|
var $from_cache = 0;
|
||||||
|
|
||||||
function __construct($show)
|
function __construct($show) {
|
||||||
{
|
|
||||||
$this->show = $show;
|
$this->show = $show;
|
||||||
$this->cachefile = "./cache/{$this->show}.txt";
|
$this->cachefile = "./cache/{$this->show}.txt";
|
||||||
$this->cachetime = 900;
|
$this->cachetime = 900;
|
||||||
@@ -75,8 +70,7 @@ class BassoFeed
|
|||||||
* @return void
|
* @return void
|
||||||
* @author Ismo Vuorinen
|
* @author Ismo Vuorinen
|
||||||
* */
|
* */
|
||||||
function generate()
|
function generate() {
|
||||||
{
|
|
||||||
// Load the data
|
// Load the data
|
||||||
$data = $this->cache();
|
$data = $this->cache();
|
||||||
|
|
||||||
@@ -95,8 +89,7 @@ class BassoFeed
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @author Ismo Vuorinen
|
* @author Ismo Vuorinen
|
||||||
* */
|
* */
|
||||||
function cache()
|
function cache() {
|
||||||
{
|
|
||||||
$filemtime = 0;
|
$filemtime = 0;
|
||||||
if (is_readable($this->cachefile)) {
|
if (is_readable($this->cachefile)) {
|
||||||
$filemtime = filemtime($this->cachefile);
|
$filemtime = filemtime($this->cachefile);
|
||||||
@@ -122,8 +115,7 @@ class BassoFeed
|
|||||||
* @param mixed $fetch
|
* @param mixed $fetch
|
||||||
* @uses simple_html_dom::find|simple_html_dom::innertext
|
* @uses simple_html_dom::find|simple_html_dom::innertext
|
||||||
*/
|
*/
|
||||||
function get_showtimes($fetch)
|
function get_showtimes($fetch) {
|
||||||
{
|
|
||||||
// Find our sidebar columns and get the insides
|
// Find our sidebar columns and get the insides
|
||||||
foreach ($fetch->find('div.column_entry') as $m) {
|
foreach ($fetch->find('div.column_entry') as $m) {
|
||||||
$div = $m->innertext;
|
$div = $m->innertext;
|
||||||
@@ -143,12 +135,10 @@ class BassoFeed
|
|||||||
$items = explode("|", strip_tags($items));
|
$items = explode("|", strip_tags($items));
|
||||||
|
|
||||||
// Take the processed showtimes and mangle to right format
|
// Take the processed showtimes and mangle to right format
|
||||||
foreach ($items as $n => $item)
|
foreach ($items as $n => $item) {
|
||||||
{
|
|
||||||
$item = trim($item);
|
$item = trim($item);
|
||||||
|
|
||||||
if( !empty($item) && strlen($item) > 2 )
|
if (!empty($item) && strlen($item) > 2) {
|
||||||
{
|
|
||||||
// Remove finnish daynames
|
// Remove finnish daynames
|
||||||
$item = str_replace($finnish_dates, "", $item);
|
$item = str_replace($finnish_dates, "", $item);
|
||||||
|
|
||||||
@@ -162,7 +152,6 @@ class BassoFeed
|
|||||||
$date = $dates2[0];
|
$date = $dates2[0];
|
||||||
list($day, $month, $year) = explode(".", $date);
|
list($day, $month, $year) = explode(".", $date);
|
||||||
$date = "20{$year}-$month-$day"; // We are on the 21st cent.
|
$date = "20{$year}-$month-$day"; // We are on the 21st cent.
|
||||||
|
|
||||||
// Unix timestamps
|
// Unix timestamps
|
||||||
$time_f = strtotime($date . " " . $dates2[1]);
|
$time_f = strtotime($date . " " . $dates2[1]);
|
||||||
$time_t = strtotime($date . " " . $dates[1]);
|
$time_t = strtotime($date . " " . $dates[1]);
|
||||||
@@ -188,8 +177,7 @@ class BassoFeed
|
|||||||
* @todo Document me
|
* @todo Document me
|
||||||
* @author Ismo Vuorinen
|
* @author Ismo Vuorinen
|
||||||
* */
|
* */
|
||||||
function get_showinfo($fetch)
|
function get_showinfo($fetch) {
|
||||||
{
|
|
||||||
foreach ($fetch->find('div#main_column_1') as $m) {
|
foreach ($fetch->find('div#main_column_1') as $m) {
|
||||||
$div = $m->innertext;
|
$div = $m->innertext;
|
||||||
|
|
||||||
@@ -208,8 +196,7 @@ class BassoFeed
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
strlen($clean) > 10 &&
|
strlen($clean) > 10 &&
|
||||||
!preg_match('/\<h1\>/i', $clean) )
|
!preg_match('/\<h1\>/i', $clean)) {
|
||||||
{
|
|
||||||
$c[] = $clean;
|
$c[] = $clean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,27 +223,39 @@ class BassoFeed
|
|||||||
* @todo Document me
|
* @todo Document me
|
||||||
* @author Ismo Vuorinen
|
* @author Ismo Vuorinen
|
||||||
* */
|
* */
|
||||||
function get_ical()
|
function get_ical() {
|
||||||
{
|
|
||||||
$cal = "BEGIN:VCALENDAR\n"
|
$cal = "BEGIN:VCALENDAR\n"
|
||||||
. "VERSION:2.0\n"
|
. "VERSION:2.0\n"
|
||||||
."PRODID:-//basso/feed//NONSGML v1.0//EN\n";
|
. "PRODID:BASSOFEED\n"
|
||||||
|
. "CALSCALE:GREGORIAN\n"
|
||||||
|
. "X-WR-TIMEZONE:Etc/GMT\n"
|
||||||
|
. "METHOD:PUBLISH\n"
|
||||||
|
. "BEGIN:VTIMEZONE\n"
|
||||||
|
. "TZID:GMT\n"
|
||||||
|
. "BEGIN:STANDARD\n"
|
||||||
|
. "DTSTART:20100101T010000\n"
|
||||||
|
. "TZOFFSETTO:+0000\n"
|
||||||
|
. "TZOFFSETFROM:+0000\n"
|
||||||
|
. "END:STANDARD\n"
|
||||||
|
. "END:VTIMEZONE\n";
|
||||||
|
|
||||||
|
foreach ($this->showtimes as $i) {
|
||||||
|
|
||||||
foreach( $this->showtimes as $i )
|
|
||||||
{
|
|
||||||
$cal .= "BEGIN:VEVENT\n"
|
$cal .= "BEGIN:VEVENT\n"
|
||||||
."UID:".md5($this->show . $i["date_f"])."@basso.fi\n"
|
|
||||||
."DTSTAMP:{$i["date_f"]}\n"
|
|
||||||
."DTSTART:{$i["date_f"]}\n"
|
|
||||||
."DTEND:{$i["date_t"]}\n"
|
|
||||||
. "SUMMARY:{$this->showinfo["title"]}\n"
|
. "SUMMARY:{$this->showinfo["title"]}\n"
|
||||||
. "DESCRIPTION:{$this->showinfo["desc"]}\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"
|
||||||
. "END:VEVENT\n";
|
. "END:VEVENT\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$cal .= "END:VCALENDAR\n";
|
$cal .= "END:VCALENDAR\n";
|
||||||
|
|
||||||
return $cal;
|
return str_replace("\n", "\r\n", $cal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user