Zend - The PHP Company




Miscellaneous

Add Code


Best Before check on links  

Type: code fragment
Added by: Tiberg
Entered: 25/08/2000
Last modified: 08/12/1999
Rating: - (fewer than 3 votes)
Views: 5052
A function that check best before dates on links to local files. Add new's flash or mark the link red on new files. Send a mail to the creator if the file are old. Check updates on your webcam and display a messgage if you are out of office.


<?PHP
    
// DOCTYPE PHP3 PUBLIC "-//www.php.org// PHP vers. 3 //EN">
    // TITLE        =" Best_Before_link "
    // Generator    =" EditPlus "
    // Author        =" Sven-Erik Tiberg <set@dc.luth.se> "
    // Keywords        =""
    // Description    =""
    // Version        =" 0.2 " 
    // Rev. Date    =" 3 sept. 2000 "
    // Rev. sign.    =" set "
    // Included/required files =""

    
Function Best_Before$label$file $nf_days=60 $new_mode="NEW" $show_old=$mailto_adr="" $alt_txt=""$nf_hour=){
    
###############################################
    # Def of parrameters
    # $label        label of link %s
    # $file            linked file or page %s
    # $nf_days        News flash time in days %i
    # $nf_hours        News flash time in hours %i
    # $new_mode        Mode of annoncing age of file. %s
    #        "NEW"    New image after link
    #        "FLASH"    Flashing New image
    #        "RED"   Red text on link while new.
    #        "IMG"    Display image
    # $show_old        Dipsplay link after expired time �b
    # $mailto_adr    mail to adress %s
    # $alt_txt        alternative text %s
    ###############################################
    # Rev. history
    # 1.2 
    #    added timestamp dd month yyyy to new files 
        
    # check for relative files
    # if $file != http://... then continue with best before procedure
    #        else link direct to $file

    
$new_mode=strtoupper$new_mode );
    if ( !
strstr$file"http://" ) ) {
        
setlocale ("LC_TIME","se");
        
# get date of file
        
$basedir="..\webroot\"; 
        
$handle=opendir($basedir);  
        
$file_mod_time=filemtime($file);
        closedir(
$handle); 

        # add 
$nf_days to modification date of $file
        
$time_base = 12*60*60;
        
$file_new_time$file_mod_time + $nf_days * $time_base + $nf_hours * 60*60;
 
        # if calculated best before date are older than todays date if not 
$new_mode="";
        if ( 
$file_new_time <= time() ) { 
            # send mail to 
$mailto_adr 
            if (  
$mailto_adr!="" ) {
                
$update = " Please Update webpage:".$file."n" ;
                
$from = "Fromwebmaster@dc.luth.sen";
                
$reply = "Reply-Towebmaster@dc.luth.sen";
                
$x_Mailer = "X-MailerPHP ".phpversion()."n";
                Mail
$mailto_adr , $update$update."It's out of date" , $from . $reply . $x_Mailer );
            }
            if ( $show_old ) { $new_mode=""; } else { $new_mode="HIDE"; }
        }
        else {}
    }
    else  {  $new_mode=""; }
 
    switch(  $new_mode ) {
        case "NEW":
             echo ("<A href="". $file."" >".$label."</A>");
            echo ("<A img src="file:/images/new.gif" width="22" height="22" alt="".$alt_txt."></A>");
            echo (" Updated ".strftime("%d %b %Y",$file_mod_time) );
             break;
        case "FLASH":
             echo ("<A href=". $file." >".$label."</A>");
            echo ("<A img src="file:/images/flash.gif" width="22" height="22" alt="".$alt_txt."></A>");
            echo (" Updated ".strftime("%d %b %Y",$file_mod_time) );
             break;
        case "RED":
             echo ("<A href=". $file." ><font color="#FF0033">".$label." </font></A>");
             break;
        case "IMG":
             echo ("<img src="file:".$file."">");
             break;
        case "HIDE":
             echo ("Link to". $label." inactive or out of date. Last updated ".strftime("%d %b %Y",$file_mod_time));
             break;
        default:
             echo ("<A href=". $file.">".$label."</A>");
    }
}
?>



Usage Example


<?php  include "Best_Before.php3"
?> 
<HTML>
<!-- example.php3 -->
   <BODY>
      <H1>Best before test page</H1>    
      
    <A href="test.html"> linked test page 1 </A>
    <!-- susbstitue above line with -->
    <?php  Best_Before"linked test page","test.html",30,"NEW",1,"me@test.org","This link will expire",0); ?>
    <!-- to add a NEW-image after the link for 30 days, 
    after this period the NEW-image will be disabled and a mail will be sent to "me@test.org" every time someone access this file -->
    <p>

    <A href="test.html"> linked test page 2</A>
    <!-- susbstitue above line with -->
    <?php  Best_Before"linked test page","test.html",30,"NEW",0,"me@test.org","This link will expire",0); ?>
    <!-- to add a NEW-image after the link for 30 days, 
    after this period the link will be disabled and a mail will be sent to "me@test.org" every time someone access this file -->
    <p>

    <A href="test.html"> linked test page 3</A>
    <!-- susbstitue above line with -->
    <?php  Best_Before"linked test page","test.html",30,"NEW",0,"","This link will expire",0); ?>
    <!-- to add a NEW-image after the link for 30 days, 
    after this period the link will be disabled and no mail will be sent -->
    <p>

    <A href="test.html"> linked test page 4</A>
    <!-- susbstitue above line with -->
    <?php  Best_Before"linked test page","test.html",30,"RED",0,"","This link will expire",0); ?>
    <!-- Label to the link will be red for 30 days, 
    after this period the link will be disabled and no mail will be sent -->
    <p>

    <img src="file:///D%7C/Inetpub/iissamples/ISSamples/rankbtn5.gif" width="90" height="20"> 
    <!-- susbstitue above line with -->
    <?php  Best_Before"","test.jpg",0,"IMG",0,"","",1); ?>
    <!-- display an image from a webcam if it's active once every 1 hour, 
    if it's not active the image will be disabled and no mail will be sent -->
    <p>

   </BODY>

</HTML>



Rate This Script





Search



This Category All Categories