diff --git a/bassofeed.php b/bassofeed.php
index 87c81e2..bff14df 100644
--- a/bassofeed.php
+++ b/bassofeed.php
@@ -1,4 +1,5 @@
show = $show;
- $this->cachefile = "./cache/{$this->show}.txt";
- $this->cachetime = 900;
-
+
+ function __construct($show) {
+ $this->show = $show;
+ $this->cachefile = "./cache/{$this->show}.txt";
+ $this->cachetime = 900;
+
$this->generate();
}
-
+
/**
* generate
- *
+ *
* The action sequence of the script.
* Used to run the process:
* * cache verification
* * scraping
- * * gets
+ * * gets
*
* @return void
* @author Ismo Vuorinen
- **/
- function generate()
- {
+ * */
+ function generate() {
// Load the data
- $data = $this->cache();
-
+ $data = $this->cache();
+
// Process the data
- $this->showinfo = $this->get_showinfo($data);
- $this->showtimes = $this->get_showtimes($data);
-
+ $this->showinfo = $this->get_showinfo($data);
+ $this->showtimes = $this->get_showtimes($data);
+
// Echo the iCal
$this->get_ical();
}
-
+
/**
* cache
* Fetches the page to a cachefile and returns it
*
* @return mixed
* @author Ismo Vuorinen
- **/
- function cache()
- {
+ * */
+ function cache() {
$filemtime = 0;
- if( is_readable($this->cachefile) ) {
- $filemtime = filemtime($this->cachefile);
+ if (is_readable($this->cachefile)) {
+ $filemtime = filemtime($this->cachefile);
}
- if(
- !$filemtime || (time() - $filemtime >= $this->cachetime)
+ if (
+ !$filemtime || (time() - $filemtime >= $this->cachetime)
) {
$fetch = file_get_html(
- "http://www.basso.fi/radio/".$this->show
+ "http://www.basso.fi/radio/" . $this->show
);
file_put_contents($this->cachefile, $fetch);
$this->from_cache = false;
@@ -115,71 +108,67 @@ class BassoFeed
return file_get_html($this->cachefile);
}
}
-
+
/**
* get_showtimes
* Process loaded showpage and find our showtimes
* @param mixed $fetch
* @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
- foreach($fetch->find('div.column_entry') as $m) {
+ foreach ($fetch->find('div.column_entry') as $m) {
$div = $m->innertext;
$items[] = $div;
}
-
+
// List of finnish daynames for elimination from the strings
$finnish_dates = array(
"Maanantai", "Tiistai", "Keskiviikko",
"Torstai", "Perjantai", "Lauantai", "Sunnuntai"
);
-
+
// Take the found broadcast times, strip tags and explode it
$items = $items[1];
$items = str_replace("
", "|", $items);
$items = str_replace("Tulevia lähetysaikoja", "", $items);
$items = explode("|", strip_tags($items));
-
+
// Take the processed showtimes and mangle to right format
- foreach ($items as $n => $item)
- {
+ foreach ($items as $n => $item) {
$item = trim($item);
- if( !empty($item) && strlen($item) > 2 )
- {
+ if (!empty($item) && strlen($item) > 2) {
// Remove finnish daynames
$item = str_replace($finnish_dates, "", $item);
// Split into 2 vars; start and end times
$dates = explode("-", trim($item));
$dates2 = explode(" ", $dates[0]);
-
- $dates_from = $dates[0];
- $dates_to = $dates2[0]." ".$dates[1];
-
+
+ $dates_from = $dates[0];
+ $dates_to = $dates2[0] . " " . $dates[1];
+
$date = $dates2[0];
list($day, $month, $year) = explode(".", $date);
$date = "20{$year}-$month-$day"; // We are on the 21st cent.
-
// Unix timestamps
- $time_f = strtotime($date." ".$dates2[1]);
- $time_t = strtotime($date." ".$dates[1]);
-
+ $time_f = strtotime($date . " " . $dates2[1]);
+ $time_t = strtotime($date . " " . $dates[1]);
+
// We take -2 as timezone info 'coz the times are in +2
- $date_f = $this->unixToiCal( $time_f, -2 );
- $date_t = $this->unixToiCal( $time_t, -2 );
-
- $stuff[$n]["time_f"] = $time_f;
- $stuff[$n]["time_t"] = $time_t;
- $stuff[$n]["date_f"] = $date_f;
- $stuff[$n]["date_t"] = $date_t;
+ $date_f = $this->unixToiCal($time_f, -2);
+ $date_t = $this->unixToiCal($time_t, -2);
+
+ $stuff[$n]["time_f"] = $time_f;
+ $stuff[$n]["time_t"] = $time_t;
+ $stuff[$n]["date_f"] = $date_f;
+ $stuff[$n]["date_t"] = $date_t;
}
}
return $stuff;
}
-
+
/**
* get_showinfo
* Parses the show info from fetched data
@@ -187,44 +176,42 @@ class BassoFeed
* @return array
* @todo Document me
* @author Ismo Vuorinen
- **/
- function get_showinfo($fetch)
- {
- foreach($fetch->find('div#main_column_1') as $m) {
+ * */
+ function get_showinfo($fetch) {
+ foreach ($fetch->find('div#main_column_1') as $m) {
$div = $m->innertext;
-
+
$items[] = $div;
}
-
+
$title = $fetch->find("h1", 0);
$title = $title->plaintext;
-
+
$cleaned = $items[0];
$cleaned = str_replace(" ", " ", $cleaned);
$cleaned = strip_tags($cleaned, "