Skip to content

Commit

Permalink
Merge pull request #10 from ebartz/develop
Browse files Browse the repository at this point in the history
prepared the first steps for solving #4
  • Loading branch information
ebartz committed Aug 20, 2015
2 parents c4ad9d7 + 2c1dc9e commit b2e954c
Showing 1 changed file with 40 additions and 17 deletions.
57 changes: 40 additions & 17 deletions lib/garbage-collection.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

error_reporting(0);

function garbage_get_dates(){

//function will return the dates for the actual and the next month

//create empty result variable
$result_dates;
#load configuration
require_once("../conf/global.conf.php");

Expand All @@ -18,8 +21,17 @@ function garbage_get_dates(){
$data = preg_match_all('#(<td valign=\'top\'>).*(<\/td>)#eisU', $data, $result);


//get actual monthfor german
//get actual month for german
$months_german = array(
"1" => "Januar",
"2" => "Februar",
"3" => "März",
"4" => "April",
"5" => "Mai",
"6" => "Juni",
"7" => "Juli",
"8" => "August",
"9" => "September",
"01" => "Januar",
"02" => "Februar",
"03" => "März",
Expand All @@ -35,28 +47,36 @@ function garbage_get_dates(){

//search for actual month
foreach($result[0] as $key){
//ensure the encoding is good
$key = utf8_encode($key);
//get the results for the actual year
if(strpos(" ".$key, date('Y'))){
if(strpos(" ".$key, $months_german[date('m')])){
//replace everything which is not needed
$key = str_replace("<b>", "", $key);
$key = str_replace("</b>", "", $key);
$key = str_replace("<br>", "", $key);
$key = str_replace("<nobr>", "", $key);
$key = str_replace("</td>", "", $key);
$key = str_replace("<td valign='top'>", "", $key);
$key = str_replace("\t", "", $key);
$key = str_replace("&nbsp;", " ", $key);
$key = str_replace(" ", "", $key);
$key = str_replace($months_german[date('m')]." ".date('Y'), "", $key);
$key = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $key);
return trim($key);
//filter the dates for the actual and the next month
if(strpos(" ".$key, $months_german[date('m')]) || strpos(" ".$key, $months_german[(date('m') +1)]) ){

$result_dates = $key;
}
}
}
//replace everything which is not needed
$result_dates = str_replace("<b>", "", $result_dates);
$result_dates = str_replace("</b>", "", $result_dates);
$result_dates = str_replace("<br>", "", $result_dates);
$result_dates = str_replace("<nobr>", "", $result_dates);
$result_dates = str_replace("</td>", "", $result_dates);
$result_dates = str_replace("<td valign='top'>", "", $result_dates);
$result_dates = str_replace("\t", "", $result_dates);
$result_dates = str_replace("&nbsp;", " ", $result_dates);
$result_dates = str_replace(" ", "", $result_dates);
$result_dates = str_replace($months_german[date('m')]." ".date('Y'), "", $result_dates);
$result_dates = str_replace($months_german[(date('m') +1)]." ".date('Y'), "", $result_dates);
$result_dates = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $result_dates);
//return the usable result
return trim($result_dates);
}

function garbage_get_next_date(){
// Function will return the next date of the garage collection according to the actual date of the server
$dates = garbage_get_dates();
$actual_date = date('d');

Expand All @@ -71,4 +91,7 @@ function garbage_get_next_date(){
}


echo garbage_get_dates();


?>

0 comments on commit b2e954c

Please sign in to comment.