function checkday(bool $force = true) : bool
{
    global $session, $revertsession, $REQUEST_URI;
    output_notl('<!--checkday()-->', true);
    if (is_new_day()) {
        if ($force && $session['user']['loggedin']) {
            $session = $revertsession;
            $session['user']['restorepage'] = $REQUEST_URI;
            $session['allowednavs'] = [];
            addnav('', 'newday.php');
            redirect('newday.php');
        }
        return true;
    } else {
        return false;
    }
}
Exemple #2
0
/**
 * Display or Retrieve the date the current post was written (once per date)
 *
 * Will only output the date if the current post's date is different from the
 * previous one output.
 *
 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
 * function is called several times for each post.
 *
 * HTML output can be filtered with 'the_date'.
 * Date string output can be filtered with 'get_the_date'.
 *
 * @since 0.71
 *
 * @global string|int|bool $currentday
 * @global string|int|bool $previousday
 *
 * @param string $d      Optional. PHP date format defaults to the date_format option if not specified.
 * @param string $before Optional. Output before the date.
 * @param string $after  Optional. Output after the date.
 * @param bool   $echo   Optional, default is display. Whether to echo the date or return it.
 * @return string|void String if retrieving.
 */
function the_date($d = '', $before = '', $after = '', $echo = true)
{
    global $currentday, $previousday;
    if (is_new_day()) {
        $the_date = $before . get_the_date($d) . $after;
        $previousday = $currentday;
        /**
         * Filter the date a post was published for display.
         *
         * @since 0.71
         *
         * @param string $the_date The formatted date string.
         * @param string $d        PHP date format. Defaults to 'date_format' option
         *                         if not specified.
         * @param string $before   HTML output before the date.
         * @param string $after    HTML output after the date.
         */
        $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
        if ($echo) {
            echo $the_date;
        } else {
            return $the_date;
        }
    }
}
function checkday()
{
    global $session, $revertsession, $REQUEST_URI;
    //output("`#`iChecking to see if you're due for a new day: ".$session['user']['laston'].", ".date("Y-m-d H:i:s")."`i`n`0");
    if ($session['user']['loggedin']) {
        output("<!--CheckNewDay()-->", true);
        if (is_new_day()) {
            $session = $revertsession;
            $session['user']['restorepage'] = $REQUEST_URI;
            $session['allowednavs'] = array();
            addnav("", "newday.php");
            redirect("newday.php");
        }
    }
}
Exemple #4
0
<?php

/**
 * Template part for displaying the post meta inside The Loop.
 *
 * @package Rock
 * @since   1.0.0
 */
?>

<div class="entry-meta">

	<?php 
if (is_new_day()) {
    ?>

		<span class="posted-date"><?php 
    the_date();
    ?>
</span>

	<?php 
}
?>

	<span class="posted-author"><?php 
the_author_posts_link();
?>
</span>

	<?php 
function checkday()
{
    global $session, $revertsession, $REQUEST_URI;
    if ($session['user']['loggedin']) {
        output_notl("<!--CheckNewDay()-->", true);
        if (is_new_day()) {
            $session = $revertsession;
            $session['user']['restorepage'] = $REQUEST_URI;
            $session['allowednavs'] = array();
            addnav("", "newday.php");
            $trace = debug_backtrace();
            redirect("newday.php", "New Day, checkday called from " . $trace[0]['file'] . ", line " . $trace[0]['line']);
        }
    }
}
 /**
  * parses an record string
  * 
  * @param $data string
  * @param $status string
  * @return array
  */
 private function Parse($data, $status)
 {
     /**
      * @par Status
      * @code
      * #----Status (te923con -s -i '')
      * 0x29 :0x17 :0x14 :0x10 :0x26 :1   :1   :1   :1   :1   :1   :1   :1
      * SYSSW:BARSW:EXTSW:RCCSW:WINSW:BATR:BATU:BATW:BAT5:BAT4:BAT5:BAT2:BAT1
      * @endcode
      * - SYSSW  - software version of system controller
      * - BARSW  - software version of barometer
      * - EXTSW  - software version of UV and channel controller
      * - RCCSW  - software version of rain controller
      * - WINSW  - software version of wind controller
      * - BATR   - battery of rain sensor (1-good (not present), 0-low)
      * - BATU   - battery of UV sensor (1-good (not present), 0-low)
      * - BATW   - battery of wind sensor (1-good (not present), 0-low)
      * - BAT5   - battery of sensor 5 (1-good (not present), 0-low)
      * - BAT4   - battery of sensor 4 (1-good (not present), 0-low)
      * - BAT3   - battery of sensor 3 (1-good (not present), 0-low)
      * - BAT2   - battery of sensor 2 (1-good (not present), 0-low)
      * - BAT1   - battery of sensor 1 (1-good (not present), 0-low)
      *
      * @par Data
      * @code
      * #------Data (te923con -i 'i')
      *
      * 1356207784:22.95:41:7.70:91:8.00:83:i :i :i :i :i :i :1001.9:i :3 :0    :9 :0.1:0.0:7.2:356
      * T0   :H0:T1  :H1:T2  :H2:T3:H3:T4:H4:T5:H5:PRESS :UV:FC:STORM:WD:WS :WG :WC :RC
      * @endcode
      * -  T0    - temperature from internal sensor in °C
      * -  H0    - humidity from internal sensor in % rel
      * -  T1..5 - temperature from external sensor 1..4 in °C
      * -  H1..5 - humidity from external sensor 1...4 in % rel
      * -  PRESS - air pressure in mBar
      * -  UV    - UV index from UV sensor
      * -  FC    - station forecast, see below for more details
      * -  STORM - stormwarning; 0 - no warning, 1 - fix your dog
      * -  WD    - wind direction in n x 22.5°; 0 -> north
      * -  WS    - wind speed in m/s
      * -  WG    - wind gust speed in m/s
      * -  WC    - windchill temperature in °C
      * -  RC    - rain counter (maybe since station starts measurement) as value
      *
      *
      * weather forecast means (as precisely as possible)
      * - 0 - heavy snow
      * - 1 - little snow
      * - 2 - heavy rain
      * - 3 - little rain
      * - 4 - cloudy
      * - 5 - some clouds
      * - 6 - sunny
      */
     $te_data = array();
     $status = explode(":", $status);
     $data = explode(":", $data);
     $cdata = count($data);
     $cstatus = count($status);
     $this->debug(__FUNCTION__, "Entered: Data:{$cdata},Status: {$cstatus}");
     //if (($cdata == 22) && ($cstatus == 13)) {
     $date = $data[0];
     $tsid = @$this->GetIDForIdent('TimeStamp');
     if ($tsid > 0) {
         SetValueInteger($tsid, $date);
     }
     $te_data['date'] = $date;
     //Indoor and Sensor1-5 T/H
     for ($s = 0; $s < self::MAXSENSORS; $s++) {
         $f = $s * 2 + 1;
         if (trim($data[$f]) == 'i') {
             continue;
         }
         $te_data[$s]['Id'] = "{$s}";
         $te_data[$s]['Temp'] = (double) $data[$f];
         if ($s > 0) {
             $batf = 13 - $s;
             if (isset($status[$batf])) {
                 $stat = $status[$batf] == '0' ? 'LOW' : 'OK';
                 $te_data[$s]['Battery'] = $stat;
             }
         }
         if (trim($data[$f + 1]) != 'i') {
             $te_data[$s]['Hum'] = (int) $data[$f + 1];
         }
         //todo
         $te_data[$s]['Typ'] = 'T/F';
         if ($s == 0) {
             $te_data[$s]['Typ'] = 'Indoor';
         } else {
             if (!isset($te_data[$s]['Hum'])) {
                 $te_data[$s]['Typ'] = 'T';
             }
         }
     }
     //indoor specioa
     if (trim($data[13]) != 'i') {
         $te_data[0]['Press'] = (int) $data[13];
     }
     if (trim($data[15]) != 'i') {
         $te_data[0]['Forecast'] = (int) $data[15];
     }
     //uv
     if (trim($data[14]) != 'i') {
         $te_data['UV']['UV'] = $data[14];
         $te_data['UV']['Bat'] = $status[6];
     }
     //wind
     if (trim($data[18]) != 'i') {
         $te_data['Wind']['Wind'] = $data[18] * self::ms_to_kmh;
         $te_data['Wind']['Storm'] = $data[16] != 0 ? 'YES' : 'No';
         $te_data['Wind']['WindDir'] = $data[17] * 22.5;
         $te_data['Wind']['WindGust'] = $data[19] * self::ms_to_kmh;
         $te_data['Wind']['WindChill'] = (double) $data[20];
         $te_data['Wind']['Bat'] = $status[7];
     }
     //rain
     if (trim($data[21]) != 'i') {
         $new = (int) $data[21];
         $factor = $this->GetRainPerCount() / 1000;
         $rcid = @$this->GetIDForIdent('LastRainCounter');
         $dailyid = @$this->GetIDForIdent('NewDayRainCounter');
         $old = GetValueInteger($rcid);
         $daily = GetValueInteger($dailyid);
         $diff = $new - $old;
         $dailydiff = $new - $daily;
         $rain = $diff * $factor;
         $raindaily = $dailydiff * $factor;
         $te_data['Rain']['RainLastDay'] = '';
         $dailyvar = IPS_GetVariable($dailyid);
         $dailyupdated = $dailyvar['VariableUpdated'];
         if (is_new_day($dailyupdated)) {
             //set last day sum
             SetValueInteger($dailyid, $old);
             //calculate rain last day
             $lastday = ($old - $daily) * $factor;
             if ($lastday < 0 or $lastday > 500) {
                 $lastday = 0;
             }
             $te_data['Rain']['RainLastDay'] = $lastday;
             $this->debug(__FUNCTION__, "::NewDay, Store old Counter({$old}) and Daily({$lastday})");
         }
         if ($new > $old) {
             SetValueInteger($rcid, $new);
         }
         if ($rain < 0 or $rain > 100) {
             $rain = 0;
         }
         $te_data['Rain']['Rain'] = $rain;
         if ($raindaily < 0 or $raindaily > 500) {
             $raindaily = 0;
         }
         $te_data['Rain']['RainDaily'] = $raindaily;
         $te_data['Rain']['Bat'] = $status[5];
     }
     //fill standard fields
     foreach (array('Wind', 'Rain', 'UV', 'Indoor') as $dev) {
         if (isset($te_data[$dev])) {
             $te_data[$dev]['Typ'] = $dev . "Sensor";
             $te_data[$dev]['Id'] = $dev;
             if (isset($te_data[$dev]['Bat'])) {
                 $stat = trim($te_data[$dev]['Bat']) == '0' ? 'LOW' : 'OK';
                 $te_data[$dev]['Battery'] = $stat;
                 unset($te_data[$dev]['Bat']);
             }
         }
     }
     $this->debug(__FUNCTION__, 'OK');
     /*
     } else {
         $this->debug(__FUNCTION__, "Field Error (22 data and 14 status fields expected");
     }
     */
     $this->debug(__FUNCTION__, " Parsed Data:" . print_r($te_data, true));
     if (count($te_data) == 0) {
         IPS_LogMessage(__CLASS__, __FUNCTION__ . " Error: Parsing returned no data");
     }
     return $te_data;
 }
 /**
  * parses an record string
  * 
  * @param $txt string Output from ws2500 program
  * @return array
  */
 private function Parse($txt)
 {
     /*
      # Sensorname[-number] (drop outs): values of sensor
      ## Blocknumber: Block(1)
      ## Date: Cal(date), time(sec)
      ## Station: Id(1)
      ## THS(Temp/humidity): Temperatur(�C), Humidity(%), New(1)
      ## PS(Pressure): Pressure-relativ(hPa), New
      ## RS(Rain): Counter(1), OneCount(mm/1000), Rain(mm/1000), Tol(1), New(1)
      ## WS(Wind): Speed(Km/h), Direction(�), Variance(�), New(1)
      ## LS(Light): Light(lux), Factor(1), Flag(1), Duration(h), DeltaDuration(min), New(1)
      ## PYS(Pyranometer): Energy(W/m), Factor(1)
      #
      Blocknumber: 348
      Date: Sun May  8 06:56:17 2016, 1462690577
      Station: 1
      THS-1 (0): 24.9, 20, h
      THS-2 (1): 20.4, 44, 1
      THS-3 (0): 23.7, 21, 1
      THS-4 (0): 23.0, 31, 1
      THS-5 (0): 22.1, 32, 1
      THS-6 (0): 24.5, 28, 1
      THS-7 (1): 17.3, 45, 1
      THS-8 (1): 17.0, 51, 1
      THS-17 (0): 23.2, 32, 1
      PS     (0): 1009, 1
      LS    (0): 479, 100, 0, 52.27, -1, 1
     */
     $lines = explode("\n", $txt);
     if (count($lines) < 4) {
         $this->debug(__FUNCTION__, 'Not enough data');
         return;
     }
     foreach ($lines as $line) {
         if (!isset($line[0])) {
             continue;
         }
         if ($line[0] == '#') {
             continue;
         }
         if ($line[0] == '+') {
             continue;
         }
         $result = array();
         $datum = date('Y-m-d H:i:s');
         if (preg_match_all("/^([\\w-]+).*?:\\s+(.*)\$/", $line, $result)) {
             $dev = $result[1][0];
             $typ = $dev;
             $id = 0;
             $p = strpos($dev, '-');
             if ($p > 0) {
                 $typ = substr($dev, 0, $p);
                 $id = substr($dev, $p + 1);
             }
             $values = $result[2][0];
             //$values=str_replace(" ",'',$values);
             $data = array();
             $data['Id'] = $dev;
             $caps = '';
             switch ($typ) {
                 case 'Date':
                     list($d, $ts) = explode(',', $values);
                     $tsid = @$this->GetIDForIdent('TimeStamp');
                     if ($tsid > 0) {
                         $old = GetValueInteger($tsid);
                         if ($ts > $old) {
                             SetValueInteger($tsid, $ts);
                         }
                     }
                     $datum = date('Y-m-d H:i:s', $ts);
                     $this->debug(__FUNCTION__, "Date: {$d}, TS {$ts}, Datum {$datum}");
                     break;
                 case 'Blocknumber':
                     $block = $values;
                     $blid = @$this->GetIDForIdent('Block');
                     if ($blid > 0) {
                         $old = GetValueInteger($blid);
                         if ($block != $old) {
                             SetValueInteger($blid, $block);
                         } else {
                             $this->debug(__FUNCTION__, "BlockNumber ({$block}) is the same, skipping");
                             return;
                         }
                     }
                     $this->debug(__FUNCTION__, "Blocknumber: {$block}");
                     break;
                 case 'Station':
                     break;
                 case 'THS':
                     $values = str_replace(" ", "", $values);
                     list($temp, $hum, $new) = explode(',', $values);
                     $new = trim($new);
                     if ($new != '0') {
                         $data['Date'] = $datum;
                         $data['Typ'] = 'T/F';
                         $caps .= 'Temp;Hum;';
                         if ($id == 17) {
                             $data['Typ'] = 'Indoor';
                             $data['Id'] = 'Indoor';
                             $caps .= 'Press;';
                         }
                         $data['Temp'] = $temp;
                         $data['Hum'] = $hum;
                         $this->debug(__FUNCTION__, "{$dev}: Temp:{$temp}, Hum:{$hum}");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 case 'RS':
                     $values = str_replace(" ", "", $values);
                     list($rc, $cf, $rain, $tol, $new) = explode(',', $values);
                     if ($new == 1) {
                         $rcid = @$this->GetIDForIdent('LastRainCounter');
                         $dailyid = @$this->GetIDForIdent('NewDayRainCounter');
                         //build diffs
                         $old = GetValueInteger($rcid);
                         $daily = GetValueInteger($dailyid);
                         $diff = $new - $old;
                         //counter overflow 4096
                         if ($diff < 0) {
                             $diff += 4096;
                         }
                         $dailydiff = $new - $daily;
                         if ($dailydiff < 0) {
                             $dailydiff += 4096;
                         }
                         $crain = $diff * $this->GetRainPerCount() / 1000;
                         if ($crain != $rain) {
                             $this->debug(__FUNCTION__, "Rain different c:{$crain},d:{$rain} ");
                         }
                         $raindaily = $dailydiff * $this->GetRainPerCount() / 1000;
                         $dailyvar = IPS_GetVariable($dailyid);
                         $dailyupdated = $dailyvar['VariableUpdated'];
                         if (is_new_day($dailyupdated)) {
                             //new day routine,set
                             //$rcvar=IPS_GetVariable($rcid);
                             //$updated=$rcvar['VariableUpdated'];
                             //if($updated<$date) {
                             //set last day sum
                             $this->debug(__FUNCTION__, 'NewDay, Store old Counter');
                             SetValueInteger($dailyid, $old);
                             //}
                         }
                         if ($new > $old) {
                             SetValueInteger($rcid, $new);
                         }
                         if ($rain < 0 or $rain > 100) {
                             $rain = 0;
                         }
                         if ($raindaily < 0 or $raindaily > 500) {
                             $raindaily = 0;
                         }
                         $data['Date'] = $datum;
                         $data['Typ'] = 'Rain';
                         $data['Rain'] = $rain;
                         $data['RainCounter'] = $rc;
                         $data['RainDaily'] = $raindaily;
                         $data['CounterFactor'] = $cf;
                         $caps .= 'RainCounter;Rain;RainDaily;';
                         $this->debug(__FUNCTION__, "Rain Counter:{$rc}, Rain:{$rain}, cf: {$cf}, daily: {$raindaily} ,TOL:{$tol}");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 case 'WS':
                     $values = str_replace(" ", "", $values);
                     list($speed, $dir, $var, $new) = explode(',', $values);
                     if ($new == 1) {
                         $data['Date'] = $datum;
                         $data['Typ'] = 'Wind';
                         $data['WindSpeed'] = $speed;
                         $data['WindDir'] = $dir;
                         $data['WindVar'] = $var;
                         $caps .= 'WindSpeed;WindDir;WindVar';
                         $this->debug(__FUNCTION__, "Wind Speed:{$speed}, Dir:{$dir}, Var: {$var}");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 case 'LS':
                     $values = str_replace(" ", "", $values);
                     list($light, $factor, $flag, $dur, $deltadur, $new) = explode(',', $values);
                     if ($new == 1) {
                         $data['Date'] = $datum;
                         $data['Typ'] = 'Light';
                         $data['Light'] = $light * $factor;
                         $caps .= 'Light;';
                         $this->debug(__FUNCTION__, "Light {$light} factor: {$factor}, Flag:{$flag}, Dur:{$dur}, Deltadur:{$deltadur}");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 case 'PYS':
                     $values = str_replace(" ", "", $values);
                     list($light, $factor, $new) = explode(',', $values);
                     if ($new == 1) {
                         $data['Date'] = $datum;
                         $data['Typ'] = 'Pyrano';
                         $data['UV'] = $light * $factor;
                         $caps .= 'UV;';
                         $this->debug(__FUNCTION__, "PYR {$light} factor: {$factor} ");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 case 'PS':
                     $values = str_replace(" ", "", $values);
                     list($press, $new) = explode(',', $values);
                     if ($new == 1) {
                         $data['Date'] = $datum;
                         $data['Typ'] = 'Indoor';
                         $data['Id'] = 'Indoor';
                         $data['Press'] = $press;
                         $caps .= 'Press;';
                         $this->debug(__FUNCTION__, "Press {$press}");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 default:
                     $this->debug(__FUNCTION__, "Unknown type '{$typ}'");
                     break;
             }
             //switch
         }
         //match  line
     }
     //for lines
 }