home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / comics / index.php
PHP Script  |  2004-03-08  |  3KB  |  99 lines

  1. <?php
  2. /*
  3.  * Displays the daily garfield strip from ucomics.com
  4.  *
  5.  * Author: Markus Schabel <markus.schabel@tgm.ac.at>
  6.  *
  7.  * TODO add support for multiple comics
  8.  * TODO add multiple language code
  9.  */
  10.  
  11. // Require main configuration file
  12. require( "../../Group-Office.php" );
  13.  
  14. // Check if a user is logged in. If not try to login via cookies. If that
  15. // also fails then show the login-screen.
  16. $GO_SECURITY->authenticate();
  17.  
  18. // Check if the user is allowed to access this module.
  19. $GO_MODULES->authenticate( 'comics' );
  20.  
  21. // This is the title of this page. Needed in header.inc for displaying the
  22. // correct title in the titlebar of the browser.
  23. $page_title = "comics - garfield";
  24.  
  25. // Require theme-header, most times this will be the navigation with some
  26. // design issues.
  27. require( $GO_THEME->theme_path."header.inc" );
  28.  
  29. // Find out if we got a date (a unix timestamp to be exact) as parameter, and
  30. // if not find out the current time.
  31. $date = isset( $_REQUEST['date'] ) ? $_REQUEST['date'] : time();
  32.  
  33. // Try to open the garfield from this date. The URL will be something like
  34. // this: http://images.ucomics.com/comics/ga/2003/ga031203.gif
  35. $file = @fopen(
  36.               "http://images.ucomics.com/comics/ga/".date( 'Y', $date ).
  37.           "/ga".date( 'ymd', $date ).".gif",
  38.           "r"
  39.           );
  40.  
  41. // Test if we were able to open this file. If not decrement date until we can
  42. // fetch a file or tested 30 files.
  43. if ( !$file ) {
  44.   // We were not able to fetch the file. So we initialies our test-counter.
  45.   $tries = 0;
  46.   // Try to read some url's.
  47.   do {
  48.     // Decrement date, so that we fetch the comic of $date-one day.
  49.     $date -= 60*60*24;
  50.     // Increment tries, so that we can give an error if we weren't able to
  51.     // fetch 30 days in the past, this prevents an infinite loop if e.g. the
  52.     // ucomics server is down.
  53.     $tries++;
  54.     // Fetch the comic that was released at $date.
  55.     $file = @fopen(
  56.                   "http://images.ucomics.com/comics/ga/".date( 'Y', $date ).
  57.                   "/ga".date( 'ymd', $date ).".gif",
  58.                   "r"
  59.                   );
  60.     // Do this till you find a file or tried 30 times.
  61.   } while ( !$file && $tries < 30 );
  62. }
  63.  
  64. // If we found a file (either in the beginning or in the loop) then we should
  65. // close this again, but set a variable to mark that we found the file.
  66. if ( $file ) {
  67.   // Close the file.
  68.   fclose( $file );
  69.   // We found a file.
  70.   $file = 1;
  71. } else {
  72.   // We found no file.
  73.   $file = 0;
  74. }
  75.  
  76. // All output should be aligned in a table to have correct distances
  77. // between the window-borders and our output.
  78. echo "<table border='0' cellpadding='10'><tr><td align='center'>";
  79.  
  80. // If we found a file, then we display it.
  81. if ( $file ) {
  82.   echo "<img src='http://images.ucomics.com/comics/ga/".date('Y',$date).
  83.        "/ga".date('ymd',$date).".gif'><br>";
  84.   // Display links for last, next and todays strip.
  85.   echo "<a href='".$PHP_SELF."?date=".($date-60*60*24)."'>gestern</a> ";
  86.   echo "<a href='".$PHP_SELF."?date=".time()."'>heute</a> ";
  87.   echo "<a href='".$PHP_SELF."?date=".($date+60*60*24)."'>morgen</a>";
  88. }
  89.  
  90. // Since all our output goes into a table we have to close the following tags
  91. echo "</td></tr></table>";
  92.  
  93. // Load theme-footer, this is probably some kind of "Group-Office Version..."
  94. require( $GO_THEME->theme_path."footer.inc" );
  95.  
  96. // That's it, we've printed what the user wanted to do and can now exit.
  97. // Maybe that would be the correct place to close database connections...
  98. ?>
  99.