We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10529
    • 73 Posts
    Currently looking at migrating an exsiting site to MODx - one of the key elements is a Live Weather Feed that is uploaded via FTP to the server (see existing site http://www.seaspritesports.com/weather-cams.php ) and stored in a directory. This is an example of the HTML doc that is FTp’d http://www.anotherharddayattheoffice.co.uk/weather/270410.htm

    <html>
    <head>
    <title>Live Weather Data for Windsurfers and Kitesurfers from Worthing West Sussex</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body bgcolor="#FFFFFF" text="#000000">
    <p><b><span class="windsurfboards">Current Weather at : <u> 
      16:28
      </u></span></b><span class="windsurfboards"><b><br>
      Date </b> 
      07/02/11
      <br>
    
      <b>Wind </b> 
      W
      at 
      13.0
      mph
      <br>
      <b>10 min average wind speed: 
      15.0
      </b> <br>
      <b>Highest Gust</b>: 
      41.0
      at 
      13:31
      <br>
      <b>Wind Chill</b>: 
      7.7
      °C
      <br>
    
      <b>Pressure:</b> 
      1013.2
      Rising Slowly
      <br>
      <strong>Temperature:</strong></span> 
      10.6
      °C
      <br>
      <b>Sunrise:</b> 
       7:29
      <br>
      <b>Sunset:</b> 
      17:04<br>
    
    <strong>Weather Data Copyright:</strong> <A href="http://www.gavinbaylis.com" target=_parent>GavinBaylis.com</A>
    </p>
    <B><A href="http://seaspritesports.com/weather.php" target=_parent>Charts 0 - 132hrs & Inshore / Offshore forecasts</A>
    
    <p> <B><A href="http://www.seaspritesports.com/archive/archive.htm" target=_blank>Archive 
      Weather Data</A> </b> 
    <p><span class="windsurfboards"><a href="http://www.channelcoast.org/data_management/wave_charts/?table=envdata_Rustington" target="_parent" class="windsurfboards">
    <b>Rustington Buoy Wave Height</b></a> </span> </p>
    
    <p><span class="windsurfboards"><a href="http://www.seaspritesports.com/weathercamframe.htm" target="_parent" class="windsurfboards">
    <b>Live Streaming VideoCam click here</b></a> </span> </p>
    
    <p>
    </b>
    <p> 
    <p> 
      <!--WEBBOT bot="HTMLMarkup" startspan ALT="Site Meter" -->
      <script type="text/javascript" language="JavaScript">var site="sm2weathercam"</script>
      <script type="text/javascript" language="JavaScript1.2" src="http://sm2.sitemeter.com/js/counter.js?site=sm2weathercam">
    </script>
    
      <noscript> <a href="http://sm2.sitemeter.com/stats.asp?site=sm2weathercam" target="_top"> 
      <img src="http://sm2.sitemeter.com/meter.asp?site=sm2weathercam" alt="Site Meter" border="0"/></a> 
      </noscript> 
      <!-- Copyright (c)2002 Site Meter -->
      <!--WEBBOT bot="HTMLMarkup" Endspan -->
    </body>
    </html>



    The current setup of the site calls the weather data in an include this is the code bninc/270210.php - now I’m not good with anything PHP I tried copying and pasting the code of the bninc file below into a snippet changing the relevant directory / file settings but just get parse errors - I can do it with an IFrame but that does not fulfill various criteria such as keeping the allowedreferrers as a lot of people like to use the data on their own weather sites!!

    <?php //PHP ADODB document - made with PHAkt 2.8.2
    $section = "weather";
    $allow = false;
    $allowedReferrers = array('tiedtothewind.interoptix.co.uk','seaspritesports.com');
    if(strlen($_SERVER['HTTP_REFERER'])>1) {
    	foreach ($allowedReferrers as $referer) {
    		if(stristr($_SERVER['HTTP_REFERER'],$referer))
    		{
    			$allow = true;			
    		}
    	}
    } 
    if($allow) { ?>
    <html>
    <head>
    <title>current weather</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="robots" content="noindex">
    <link href="/objs/seasprite2005.css" rel="stylesheet" type="text/css">
    </head>
    
    <body>
    <table width="100%" height="420" border="0" cellpadding="2" cellspacing="0">
      <tr>
        <td width="50%" align="center" class="navTabCurrent">Weather </td>
        <td width="50%" align="center" class="navTab"><a href="/weather-cams-stream.php" target="_parent">Stream</a></td>
      </tr>
      <tr valign="top">
        <td colspan="2" class="tblTextCompressed"> 
          <p> </p>
          <?php include("../weatherfiles/270410.htm"); ?></td>
      </tr>
    </table>
    </body>
    </html>
    <?php } else { ?>
    <img src="http://www.seaspritesports.com/images/header2007.jpg" onLoad="window.location='http://www.seaspritesports.com/'"></img>
    <?php } ?>


    So essentially how is it best to embed the weather file giving some form of protection as in the above inc file in Modx

    Hope that makes sense - and like I said, not that good on PHP - so if any of you PHP rock starts like the look of the www.anotherharddayattheoffice.co.uk template and can help me out then I’ll share the template code with you - though you can probably suss it out yourselves !!
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      You could create unpublished resources for the weather files, and on your weather page use a snippet to fetch the content from the unpublished resources.

      Then the only way to access that data is through your weather page.


      I’m not sure if I fully understand why you are protecting the weather info though - if it is publicly viewable one way or another, it can be retrieved and parsed... I’d be happy if people would use an API or image to display todays weather forecast with a link back. That helps your brand and in the end the more publicity the better I guess.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 18913
        • 654 Posts
        Try creating a snippet with this sort of code :
        <?php
        $section = "weather";
        $allow = false;
        $allowedReferrers = array('localhost');
        if(strlen($_SERVER['HTTP_REFERER'])>1) {
        	foreach ($allowedReferrers as $referer) {
        		if(stristr($_SERVER['HTTP_REFERER'],$referer))
        		{
        			$allow = true;			
        		}
        	}
        } 
        $output = '';
        if($allow) { 
        
        ob_start();
        include_once('270410.htm');
        $output = ob_get_contents();
        ob_end_clean();
        
         } else { 
        $output = '<img src="http://www.seaspritesports.com/images/header2007.jpg" onLoad="window.location=\'http://www.seaspritesports.com/\'"></img>';
         }
        return "blahblah".$output."blahblahblah";
        ?>
        

        and then call it from a document. Season to taste...
        Matt
          • 10529
          • 73 Posts
          Great guys - thanks for those - I will see how I get on - though might well have some issues with the snippet(s) so will probably be asking for more help rolleyes
            • 10529
            • 73 Posts
            mconsidine thanks for the snippet - had some frustrating fun n’games with caching, at least that’s what I think was happening - seems as soon as I changed anything it affected the referrers - for the time being I have taken the referrers element out of the snippet and I’m just using

            <?php
            $section = "weather";
            ob_start();
            include_once('280410.htm');
            $output = ob_get_contents();
            ob_end_clean();
            
             
            return "blahblah".$output."blahblahblah";
            ?>


            I’ll experiment more later with css etc http://www.anotherharddayattheoffice.co.uk/index.php?id=58
              • 10529
              • 73 Posts
              Don’t know what I’m doing wrong all seems to work when I’m logged into manager & previewing - I see the correct page - as soon as I logout and then attempt to view the page it does not allow me to view the file and does not allow me as a referrer

              This is the code I’ve put on the resource [!Weather!] http://www.anotherharddayattheoffice.co.uk/index.php?id=58


              This is the snippet code

              <?php
              $section = "weather";
              $allow = false;
              $allowedReferrers = array('anotherharddayattheoffice.co.uk','anotherharddayattheoffice.com');
              if(strlen($_SERVER['HTTP_REFERER'])>1) {
              	foreach ($allowedReferrers as $referer) {
              		if(stristr($_SERVER['HTTP_REFERER'],$referer))
              		{
              			$allow = true;			
              		}
              	}
              } 
              if($allow) { ?>
              
              ob_start();
              <html>
              <head>
              <title>current weather</title>
              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
              <meta name="robots" content="noindex">
              <link href="/objs/seasprite2005.css" rel="stylesheet" type="text/css">
              </head>
              
              <body>
              <table width="100%" height="420" border="0" cellpadding="2" cellspacing="0">
                <tr>
                  <td width="50%" align="center" class="navTabCurrent">Weather </td>
                  <td width="50%" align="center" class="navTab"><a href="/weather-cams-stream.php" target="_parent">Stream</a></td>
                </tr>
                <tr valign="top">
                  <td colspan="2" class="tblTextCompressed"> 
                  include_once('280410.htm');</td>
                </tr>
              </table>
              </body>
              </html>
              ob_end_clean();
               } else { 
              $output = '<img src="http://www.seaspritesports.com/images/header2007.jpg" onLoad="window.location=\'http://www.seaspritesports.com/\'"></img>';
               }
              return "blahblah".$output."blahblahblah";
              ?>
                • 22840
                • 1,572 Posts
                Is the page published ??
                  • 18913
                  • 654 Posts
                  Here’s what I did.
                  - Created a template that the page would use. This was it’s content :
                  <html>
                  <head>
                  <title>current weather</title>
                  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
                  <meta name="robots" content="noindex">
                  <link href="/objs/seasprite2005.css" rel="stylesheet" type="text/css">
                  </head>
                  
                  <body>
                  <table width="100%" height="420" border="0" cellpadding="2" cellspacing="0">
                    <tr>
                      <td width="50%" align="center" class="navTabCurrent">Weather </td>
                      <td width="50%" align="center" class="navTab"><a href="/weather-cams-stream.php" target="_parent">Stream</a></td>
                    </tr>
                    <tr valign="top">
                      <td colspan="2" class="tblTextCompressed"> 
                  [*content*]
                  </td>
                    </tr>
                  </table>
                  </body>
                  </html> 
                  


                  - Created a document and assigned this template to it.
                  - The content of the document was a call to the snippet I posted above, with referres changed to "localhost" for testing.

                  The snippet only returns a) the included file if the referrers test is passed or b) the "alternative" output you want someone to see. That is then all wrapped up in the html code in the template.

                  Is that what you’re trying to accomplish? I can tell you why your above code isn’t returning anything, but I’m really not sure that that is the way you want to go about putting the html together wink

                  Matt
                    • 18913
                    • 654 Posts
                    PS If you really want to take the approach you laid out, try this version of what you posted :
                    <?php
                    $section = "weather";
                    $allow = false;
                    $allowedReferrers = array('anotherharddayattheoffice.co.uk','anotherharddayattheoffice.com');
                    if(strlen($_SERVER['HTTP_REFERER'])>1) {
                    	foreach ($allowedReferrers as $referer) {
                    		if(stristr($_SERVER['HTTP_REFERER'],$referer))
                    		{
                    			$allow = true;			
                    		}
                    	}
                    } 
                    $output = '';
                    if($allow) { 
                    $output = '
                    <html>
                    <head>
                    <title>current weather</title>
                    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
                    <meta name="robots" content="noindex">
                    <link href="/objs/seasprite2005.css" rel="stylesheet" type="text/css">
                    </head>
                    
                    <body>
                    <table width="100%" height="420" border="0" cellpadding="2" cellspacing="0">
                      <tr>
                        <td width="50%" align="center" class="navTabCurrent">Weather </td>
                        <td width="50%" align="center" class="navTab"><a href="/weather-cams-stream.php" target="_parent">Stream</a></td>
                      </tr>
                      <tr valign="top">
                        <td colspan="2" class="tblTextCompressed"> ';
                    ob_start();
                    include_once('280410.htm');
                    $output .= ob_get_contents();
                    ob_end_clean();
                    $output .=	'</td>
                      </tr>
                    </table>
                    </body>
                    </html>';
                     } else { 
                    $output = '<img src="http://www.seaspritesports.com/images/header2007.jpg" onLoad="window.location=\'http://www.seaspritesports.com/\'"></img>';
                     }
                    return "blahblah".$output."blahblahblah";
                    ?>
                    


                    I haven’t tested it, but it should be close.
                    Matt
                      • 10529
                      • 73 Posts
                      Thanks for you efforts / help guys - and yes page was published and I don’t have it cacheable.

                      Maybe I was not clear in my earlier post(s)

                      Everything works when I view / preview the page http://www.anotherharddayattheoffice.co.uk/index.php?id=58 when I am logged into Manager - when on the same pc I attempt to view the same page in a different browser I am bounced away from the content that I can see in manager (280410.htm) and end up being redirected to Seasprite Page.

                      It would seem that the function $allowedReferrers = array(’anotherharddayattheoffice.co.uk’); is not enabled once I log out of Manager

                      I have stripped everything out to test and I have tried the snippet code in a blank template
                      [!Weather!]
                      and using the earlier stripped down snippet code
                      <?php
                      $section = "weather";
                      $allow = false;
                      $allowedReferrers = array('anotherharddayattheoffice.co.uk');
                      if(strlen($_SERVER['HTTP_REFERER'])>1) {
                      	foreach ($allowedReferrers as $referer) {
                      		if(stristr($_SERVER['HTTP_REFERER'],$referer))
                      		{
                      			$allow = true;			
                      		}
                      	}
                      } 
                      $output = '';
                      if($allow) { 
                      
                      ob_start();
                      include_once('280410.htm');
                      $output = ob_get_contents();
                      ob_end_clean();
                      
                       } else { 
                      $output = '<img src="http://www.seaspritesports.com/images/header2007.jpg" onLoad="window.location=\'http://www.seaspritesports.com/\'"></img>';
                       }
                      return "blahblah".$output."blahblahblah";
                      ?>


                      But as soon as I log out of Manager it does not work - the only time it does work is when I change the $allow = false; to true; which I presume sort of defeats the logic?