Author Topic: Error, Daily / Monthly Weather History From This Station  (Read 1345 times)

0 Members and 1 Guest are viewing this topic.

Offline yamiacaveman

  • Forecaster
  • *****
  • Posts: 439
    • Penn Lake Weather
Error, Daily / Monthly Weather History From This Station
« on: July 18, 2017, 08:29:03 AM »
I have not checked this tab in a while and I just noticed in my History tab this error, Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /home/pennla7/public_html/include-wxhistory.php on line 362

I searched the site but I am not finding anything.

I haven't changed anything for a while but I'm thinking it has to do with upgrading to PHP 7 a few months back.

Thanks for any help or direction,

yamiacaveman


http://www.pennlake.us/wxhistory.php

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 947
    • LexMAWeather
Re: Error, Daily / Monthly Weather History From This Station
« Reply #1 on: July 18, 2017, 12:54:38 PM »
See http://php.net/manual/en/function.preg-replace.php

The /e modifier was deprecated in PHP v.5.5 and removed completely in 7.

If your provider allows you to use an earlier PHP version you can do that as a quick fix, but you should find an ultimate solution that is compatible with current and future versions.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline yamiacaveman

  • Forecaster
  • *****
  • Posts: 439
    • Penn Lake Weather
Re: Error, Daily / Monthly Weather History From This Station
« Reply #2 on: July 18, 2017, 01:15:13 PM »
Thanks Jasiu,

For me I guess the easiest thing to do, is to remove the History tab all together. :-(

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Error, Daily / Monthly Weather History From This Station
« Reply #3 on: July 18, 2017, 01:20:07 PM »
Can you post the script where you have the problem? It is not hard to fix

Offline yamiacaveman

  • Forecaster
  • *****
  • Posts: 439
    • Penn Lake Weather
Re: Error, Daily / Monthly Weather History From This Station
« Reply #4 on: July 18, 2017, 03:55:09 PM »
Hi Jachym,

?php

// This is a custom version by Mike Challis
// http://www.642weather.com/weather/scripts.php
// AvgExtract.php has been modified into this include-wxhistory.php - Mulitlingual Version

# mchallis Version 1.01 04/04/08 Fixed some display issues caused by new WD 10.37j-01 version
# mchallis Version 1.02 04/06/08 Fixed some display issues caused by new WD 10.37j-01 version
# mchallis Version 1.03 04/08/08 Added support for rain totals in mm
# mchallis Version 1.04 04/21/08 added 'Frost days' support
# ktrue    Version 1.05 30-Jun-2008 -- adapted for WD-World-ML template multilanguage use
# mchallis Version 1.06 10/27/09 added $wxh_graphs_path setting to enable custom graphs image directory
#            - fixed one issue on PHP 5.3
# ktrue    Version 1.07 11/24/10 added WD10.37Q support+ avg daily min/max monthly display
# mconnaroe Version 1.08 12/19/10 added support for Special Weather report in output
# ktrue     Version 1.09 11-Jul-2011 - fixed Notice error when no UV sensor

# mchallis modified for style compatibility with my css theme switcher and to be used
# inside of a wxhistory.php page in a Weather Display/PHP/AJAX Website Template set
# http://saratoga-weather.org/template/
# mchallis added if is_file check and toggle image feature for 24 hour chart images
# also added other minor formatting changes

############################################################################
# A Project of TNET Services, Inc. - TNET Weather
############################################################################
#
#   Project:    Sample code to extract Daily Ave/Ext WD HTML Page
#   Module:     AvgExtract.php
#   Authors:    Kevin W. Reed <kreed@tnet.com>
#               TNET Services, Inc.
#
#   Copyright:  (c) 1992-2007 Copyright TNET Services, Inc.
############################################################################
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
############################################################################
// allow viewing of generated source

if ( isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) {
//--self downloader --
   $filenameReal = __FILE__;
   $download_size = filesize($filenameReal);
   header('Pragma: public');
   header('Cache-Control: private');
   header('Cache-Control: no-cache, must-revalidate');
   header('Content-type: text/plain');
   header('Accept-Ranges: bytes');
   header("Content-Length: $download_size");
   header('Connection: close');
   
   readfile($filenameReal);
   exit;
}


//# mchallis override $website setting to use setting from $webdir setting in wxhistory.php
$website = $webdir;

if ( !isset($wxh_graphs_path) ) {
   $wxh_graphs_path = $webdir;
}

# Unless you are going to change the language, you most likely won't need
# to change anything below this section
############################################################################

$parts = array();
$extracts = array();
$LEVEL = 0;
$DAY = 0;

$month = '';
$monthnum = 0;
$yearnum = 0;

// Arrays to Format Things with
$level1 = array(
            array('Average temperature',3),
            array('Average humidity',3),
            array('Average dewpoint',3),
            array('Average barometer',3),
            array('Average windspeed',3),
            array('Average gustspeed',3),
            array('Average direction',3),
            array('Rainfall for month',4),
            array('Rainfall for year',4),
            array('Maximum rain per minute',5),
            array('Maximum temperature',4), # mchallis 04/04/08 (WD 10.37j-01 fix) changed 3 to 4
            array('Minimum temperature',4), # mchallis 04/04/08 (WD 10.37j-01 fix) changed 3 to 4
            array('Minimum pressure',3),
            array('Maximum pressure',3),
            array('Maximum windspeed',3),
            array('Maximum gust speed',4),
            array('Maximum humidity',4), # mchallis 04/06/08 (WD 10.37j-01 fix) changed 3 to 4
            array('Minimum humidity',3),
            array('Maximum heat index',4),
            array('Growing degrees days',5),
         array('Avg daily min temp',5), # ktrue added 'Avg daily min temp' support 24-Nov-2010
         array('Avg daily max temp',5), # ktrue added 'Avg daily max temp' support 24-Nov-2010
            array('Frost days',3), # mchallis added 'Frost days' support 04/21/08
            );

$level2 = array(
            array(',ET', 2),
            array('Sunshine hours month to date',6),
            array('Sunshine hours year to date',6),
            array('in. on day',0),
            array('in.  on day',0), # mchallis added 04/04/08 (WD 10.37j-01 fix)
            array('mm on day',0),  # mchallis added 04/08/08 support for rain in mm
            array('mm  on day',0), # mchallis added 04/08/08 support for rain in mm (WD 10.37j + fix)
            );

function display_data($date_to_process){
    global $website, $wxh_graphs_path, $SITE;
    global $level1, $level2, $LEVEL, $DAY, $month, $monthnum, $yearnum;

    $mnthname = array('January', 'February', 'March', 'April', 'May', 'June',
    'July', 'August', 'September', 'October', 'November', 'December');

    # mchallis added
    $mnthnameshort = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
/*   if (isset($SITE['langMonths'])) {
      print "<!-- loaded short month names -->\n";
       $mnthname = $SITE['langMonths'];  // load array for current language
      foreach ($mnthname as $i => $name) {
        $mnthname[$i] = substr($mnthname[$i],0,3);
      }

    } */
    if ( strlen($date_to_process) == 0 ) {
        # defaults to this year month
        $date_to_process = date('Y') . date('m');
    }
    $monthnum = substr($date_to_process,4,2);
    $yearnum = substr($date_to_process,0,4);

    $datafile = $website . $mnthname[$monthnum -1 ] . $yearnum . ".htm";

    $fd = fopen($datafile,'r');

    $LEVEL = 0;
    $DAY = 0;
    $RAIN = 0;
    $even_odd = 0;
    $ignore = 0;
    $special_msg = '';

    if ($fd ) {
        while ( !feof($fd) ){
            $gotraw = fgets($fd,8192);
            $value = trim($gotraw);

            if ( preg_match("|Any Special weather conditions for the day:|i",$gotraw)) {  // Ignore special weather conditions
                $ignore = 1;                                                              // entered by users 
                $value = $gotraw = $special_msg = '';
            } else {
                if (($ignore == 1) AND preg_match("|<FONT COLOR|i",$gotraw)){
                    $ignore = 0;
                    $special_class = array('class="column-light"','class="column-dark"');
                    $special_class = $special_class[$DAY % 2];
                    echo '<tr><td colspan="2" ',$special_class,'>'.$special_msg.'</td></tr>';
                } else {
                    if ($ignore == 1){
                        if (!preg_match("|<img |i",$gotraw)){
                        $special_msg = $special_msg.$gotraw;
                        }
                    $value = $gotraw = '';
                    }
                }
            }

            if ($LEVEL == 0 ) {

                if ( preg_match("|Daily report for |i",$value)) {

                    # mchallis page title consistancy fix ....
                    # January2007.htm page title was "Daily Report for the month of January 2007"
                    # and January2008.htm page title was "Daily Report for the month of 01 2007"
#                     preg_match("/Daily report for (.*)\</U",$value,$found);
                      #$month = $found[1];
                      $month = $mnthname[$monthnum -1 ] . " $yearnum";
                      echo "<h1>".langtransstr('Daily Report for the month of') ." " .
                   langtransstr($mnthname[$monthnum-1]) . " $yearnum</h1>\n";
                      $LEVEL = 1;
                }
            }

            if ($LEVEL == 1 ) {

                // Check for Day String
                if ( strpos ($value,"Extremes for day :") !== false ) {

                    // Must already have been processing a day so close table
                    if ( $DAY != 0 ) {
                        echo "</table>\n";

                          $this_img = $yearnum . $monthnum . $DAY;
                        # mchallis added if is_file check and image toggle feature
                        if (is_file("$wxh_graphs_path$this_img.jpg")){
                         echo '
<p onclick="toggleDisplay(\'img_\' + '.$this_img.');">
'. langtransstr('Click here to toggle the 24 Hour Graph of this day') . '</p>
<img src="'. $wxh_graphs_path . $this_img .'.jpg" id="img_'.$this_img .'" style="display: none" onclick="toggleDisplay(\'img_\' + '.$this_img.');" alt="24 Hour Graph for Day '.$DAY.'" title="24 Hour Graph for Day '.$DAY.'" />' . "\n";
                        } else {
                            echo langtransstr("24 Hour Graph of this day is not available") . " ($this_img.jpg)<br/> <br/>" . "\n";
                        }

                    }
                    preg_match("/Extremes for day :(\d{1,2})\</",$value,$found);
                    $DAY = $found[1];

                  echo '<br /><br />
                    <table width="600" cellpadding="3" cellspacing="0" border="0">
                    <tr class="table-top">
                    <td colspan="2">'. intval($DAY). ' ' . langtransstr($mnthname[$monthnum -1 ]).' '.  langtransstr('Average and Extremes') . '</td>
                    </tr>
                    ';

                }

                // Check for Month Recap

                if ( strpos ($value, "Extremes for the month of ") !== false ) {
                    echo "</table>\n";

                        $this_img = $yearnum . $monthnum . $DAY;
                        # mchallis added if is_file check
                        if (is_file("$wxh_graphs_path$this_img.jpg")){
                         echo '
<p onclick="toggleDisplay(\'img_\' + '.$this_img.');">
'. langtransstr('Click here to toggle the 24 Hour Graph of this day') . '</p>
<img src="'. $wxh_graphs_path . $this_img .'.jpg" id="img_'.$this_img .'" style="display: none" onclick="toggleDisplay(\'img_\' + '.$this_img.');" alt="24 Hour Graph for Day '.$DAY.'" title="24 Hour Graph for Day '.$DAY.'" />' . "\n";

                        } else {
                            echo langtransstr("24 Hour Graph of this day is not available") . " ($this_img.jpg)<br/> <br/>" . "\n";
                        }


                    echo '<br /><br />
                    <table width="600" cellpadding="3" cellspacing="0" border="0">
                    <tr class="table-top">
                    <td colspan="2">' . langtransstr('Average and Extremes for Month of') . ' ' .
               langtransstr($mnthname[$monthnum -1 ]) . " $yearnum " . langtransstr('up to day') . ' ' . intval($DAY) . '</td>
                    </tr>
                    ';
                }

                // Check for Sunshine Hours

                #if ( strpos ($value, "Sunshine hours " ) !== false ) {
                if ( strpos ($value, "Sunshine" ) !== false ) { # mchallis 04/04/08 (WD 10.37j-01 fix)
                    echo "</table>\n";
                    # mchallis added 04/04/08 (WD 10.37j-01 fix) modified Day, Sunshine Hours title
                    echo '<br /><br />
                    <table width="600" cellpadding="3" cellspacing="0" border="0">
                    <tr class="table-top">
                    <td colspan="4">' . langtransstr('Day, Sunshine Hours, ET, Max Solar, UV') .'</td>
                    </tr>
                    ';
                    $LEVEL = 2;
                }

                // Check for Daily Rain Totals (in case there was no Sunshine)

                if ( strpos ($value, "Daily rain totals" ) !== false ) {
                    echo "</table>\n";

                    echo '<br /><br />
                    <table width="600" cellpadding="3" cellspacing="0" border="0">
                    <tr class="table-top">
                    <td colspan="2">'. langtransstr('Daily Rain Totals') . '</td>
                    </tr>
                    ';
                    $LEVEL = 2;
                    $RAIN = 1;
                }

                // Check for data lines
            # ktrue added 'Avg daily min/max temp' support 24-Nov-2010
            if(preg_match('|Avg daily \S+ temp :|is',$value)) {
               $value = preg_replace('|\:|','  =',$value);
            }
                output_data($value, $LEVEL);

            }

            if ($LEVEL == 2 ) {
                // Check for Daily Rain Totals (in case there was no Sunshine)

                if ( strpos ($value, "Daily rain totals" ) !== false  && ! $RAIN ) {
                    echo "</table>\n";

                    echo '<br /><br />
                    <table width="600" cellpadding="3" cellspacing="0" border="0">
                    <tr class="table-top">
                    <td colspan="2">' . langtransstr('Daily Rain Totals') . '</td>
                    </tr>
                    ';
                }

                if ( strpos (strtolower($value), "</body>" ) !== false ) {
                    echo "</table>\n";
                    $LEVEL = 3;
                }

                // Check for data lines
                output_data($value, $LEVEL);
            }

        }
    }
}

function output_data($invalue, $LEVEL ) {
    global $website, $even_odd;
    global $level1, $level2, $LEVEL, $DAY, $month, $monthnum, $yearnum;

    $row_class = '';
    $even_class = 'class="column-light"';
    $odd_class = 'class="column-dark"';

    // Remove ALL html tag info...
        $newval = preg_replace("'<[/!]*?[^<>]*?>'si","",$invalue);

    if ($LEVEL == 1 ) {

        foreach ($level1 as $key => $kvalue ) {
            if ( strpos ( strtolower($newval), strtolower($kvalue[0]) ) !== false ) {
                list ($left, $right ) = getparts($newval,$kvalue[1]);
                $left = preg_replace('/=/','',$left); # mchallis added 04/21/08
                $right = preg_replace('/=/','',$right); # mchallis added 04/04/08 (WD 10.37j-01 fix)
                # mjc added for testing
#                  if (preg_match("/Maximum gust speed/i",$left)){
#                      $left = "<b>$left</b>";
#                      $right = "<b>$right</b>";
#                  }
                 # eof

               if ($even_odd % 2){
                     $row_class = $odd_class;
               }
               else {
                     $row_class = $even_class;
               }
             $right = preg_replace('/°/Uis','&deg;',$right);
            $right = preg_replace('/from/is',langtransstr('from'),$right);
            $right = preg_replace('/on day/is',langtransstr('on'),$right);
            $right = preg_replace('/at time/is',langtransstr('at'),$right);
            $right = preg_replace('/\((.+)\)/e',"'('.langtransstr(trim('\\1')).')'",$right);

               echo '<tr '.$row_class.'>
                <td>'. langtransstr($left) .'</td><td>' .$right ."</td>
                </tr>\n";
//                echo "<!-- right='$right' -->\n";
                $even_odd++;
            }

        }
    }

    if ($LEVEL == 2 ) {

            // Strip out = sign from line
            if (strpos($newval,'Sunshine hours ') !== false) {
                    $newval = preg_replace('/=/','',$newval);
            }

        foreach ($level2 as $key => $kvalue ) {
            if ( strpos ( strtolower($newval), strtolower($kvalue[0]) ) !== false ) {

               if ($even_odd % 2){
                     $row_class = $odd_class;
               }
               else {
                     $row_class = $even_class;
               }
               if (strpos($newval,',ET') !== false) {
                $sunshine_vals = explode(',', $newval.',,,,');
                echo '<tr '.$row_class.'>
                <td>'.$sunshine_vals[0] .'</td>
                <td>'.$sunshine_vals[1] .'</td>
                <td>'.$sunshine_vals[2] .'</td>
                <td>'.$sunshine_vals[3] ."</td>
                </tr>\n";
               }else if(strpos($newval,'Sunshine hours ') !== false){
             preg_match('/(.*) ([\d|\.]+) (\S+)/is',$newval,$matches); // split up so we can do langtransstr()
            // print "<!-- matches \n" . print_r($matches,true) . " -->\n";
                echo '<tr '.$row_class.'>
                <td colspan="4">'.langtransstr($matches[1]) . ' ' . $matches[2] . ' ' . langtransstr($matches[3])  ."</td>
                </tr>\n";
               }
               else{
             $newval = preg_replace('/on day/is',langtransstr('on'),$newval);
                echo '<tr '.$row_class.'>
                <td>'.langtransstr($newval) ."</td>
                </tr>\n";
               }
                $even_odd++;
            }
        }
    }
}

function getparts($val, $number) {
    $retval = array();
    $collect = '';

    $splits = explode(" ", $val, $number);

    for ($i = 0 ; $i < ($number -1) ; $i++ ) {
        $collect .= $splits[$i] . ' ';
    }
    $retval[0] = trim($collect);
    $retval[1] = ltrim($splits[$i]);
    return($retval);
}
?>

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Error, Daily / Monthly Weather History From This Station
« Reply #5 on: July 18, 2017, 04:15:12 PM »
Ummm... there is a Version 1.10 12-Aug-2015 - fixed Deprecated preg_replace /e issue available for that

http://www.pennlake.us/check-fetch-times.php?show=versions shows you all the scripts included in the template that need update :)
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Error, Daily / Monthly Weather History From This Station
« Reply #6 on: July 18, 2017, 05:22:20 PM »
Hi,
ok I guess there is no point in fixing it then :-) Make sure you stay up-to-date with the scripts :-)
Thanks Ken

Offline yamiacaveman

  • Forecaster
  • *****
  • Posts: 439
    • Penn Lake Weather
Re: Error, Daily / Monthly Weather History From This Station
« Reply #7 on: July 18, 2017, 06:19:38 PM »
Thanks Ken and Jachym!!!!!

Boy I didn't know that tool was available to check versions,

and I think I only went back to 2016 sometime looking for an updated script -- again thanks.

 

anything