1.4 now as date format was changed to use slashes - Cache file can now be refreshed by admin without getting screwed up with edit links 02/28/03 ppmnt v2.0 - Created a customizations section to make it easy to customize (duh) - Added option to display list with numbers - Renamed all functions to avoid conflicts if called from same page as other scripts with same function names */ global $numX; global $show_ranks; /*------------------------------- BEGIN CUSTOMIZATION SECTION -------------------------------*/ /* Number of albums to be displayed */ $numX = 4; /* Cache file expiration date. You might want to change this for testing. * This number is in seconds, so 43200 is 12 hours * If you set this to 0 you will force the cache to be refreshed every time. * This will slow the page down significantly! Only use this for testing! */ $cache_expire = 21600; //$cache_expire = 0; // refresh every time. /* Cache file name, there should be no reason to change this */ $cachefile = "lastXupdates.cache"; /*------------------------------- END CUSTOMIZATION SECTION -------------------------------*/ // Please don't make any changes below //------------------------------------------------------------------------------ // Hack prevention. if (!empty($HTTP_GET_VARS["GALLERY_BASEDIR"]) || !empty($HTTP_POST_VARS["GALLERY_BASEDIR"]) || !empty($HTTP_COOKIE_VARS["GALLERY_BASEDIR"])) { print "Security violation\n"; exit; } // read in required files require($GALLERY_BASEDIR . "init.php"); if ($profile) { $timer = time(); } /* Initializing the seed */ srand ((double) microtime() * 1000000); // set the cache file name define(CACHE_FILE_LXU, $gallery->app->albumDir . "/last-updated.cache"); // here we rebuild the cache file every 12 hours (43200 seconds) define(CACHE_EXPIRED_LXU, $cache_expire); // Check the cache file to see if it's up to date $rebuild = 1; if (fs_file_exists(CACHE_FILE_LXU)) { $stat = fs_stat(CACHE_FILE_LXU); $mtime = $stat[9]; if (time() - $mtime < CACHE_EXPIRED_LXU) { $rebuild = 0; } } // if the cache is not upto date rebuild the cache file if ($rebuild) { scanAlbumsLXU(); saveCacheLXU(); readCacheLXU(); } // else just read the cache file into arrays else { readCacheLXU(); } // show last X updated albums lastUpdatedLXU(); /* * -------------------------------------------------- * Support functions * -------------------------------------------------- */ function saveCacheLXU() { /* * saves X recent albums updates */ global $dateArray; global $nameArray; global $albumDate; global $albumName; reset($dateArray); reset($nameArray); reset($albumDate); reset($albumName); if ($fd = fs_fopen(CACHE_FILE_LXU, "w")) { $currentKey = key($dateArray); fwrite($fd, "$nameArray[$currentKey]|$albumName[$currentKey]|$albumDate[$currentKey]\n"); for ($i = 0; $i <= 8; $i++) { $current = next($dateArray); $currentKey = key($dateArray); fwrite($fd, "$nameArray[$currentKey]|$albumName[$currentKey]|$albumDate[$currentKey]\n"); } fclose($fd); } } function readCacheLXU() { /* * reads info from cache file and populates arrays */ global $cacheName; global $cacheDate; global $cacheRealName; $cacheName = array(); $cacheDate = array(); $cacheRealName = array(); $i = 0; if ($fd = fs_fopen(CACHE_FILE_LXU, "r")) { while ($line = fgets($fd, 4096)) { list($cacheName[$i], $cacheRealName[$i], $cacheDate[$i]) = explode("|", $line); $i++; } fclose($fd); } } function scanAlbumsLXU() { /* * scans through albums to find the recent updates */ global $dateArray; global $nameArray; global $albumDate; global $albumName; global $gallery; $dateArray = array(); $nameArray = array(); $albumDate = array(); $albumName = array(); /* Read the album list */ $albumDB = new AlbumDB(); $gallery->session->albumName = ""; /* If there are albums in our list, display them in the table */ $numAllAlbums = $albumDB->numAllAlbums($gallery->user); if (!$gallery->session->albumListPage) { $gallery->session->albumListPage = 1; } $start = ($gallery->session->albumListPage - 1) * 3 + 1; $end = $numAllAlbums; for ($i = $start; $i <= $end; $i++) { $gallery->album = $albumDB->getAllAlbum($gallery->user, $i); $tmpAlbumName = $gallery->album->fields["name"]; $modDate = $gallery->album->getLastModificationDate(); // here we use unix timestamps for date storage - seems the easiest way to sort later $modDate = strtotime ($modDate); $nameArray[$i] = $tmpAlbumName; $dateArray[$i] = $modDate; $albumDate[$i] = $gallery->album->getLastModificationDate(); $albumName[$i] = editField($gallery->album, "title", $edit); $albumName[$i] = strip_tags(editField($gallery->album, "title", $edit)); $albumName[$i] = str_replace("[edit title]", "", $albumName[$i]); // sort the date array so that we can use it for reference later arsort ($dateArray); } // for () end } function lastUpdatedLXU() { /* * display last X updates based on cache file */ global $cacheName; global $cacheDate; global $cacheRealName; global $albumName; global $gallery; global $numX; $albumDB = new AlbumDB(); $gallery->session->albumName = ""; $numAllAlbums = $albumDB->numAllAlbums($gallery->user); $numPhotos = $albumDB->numPhotos($gallery->user); ?> photos in albums:

" . $cacheRealName[$i] . "
\n" ."  updated: " . $cacheDate[$i] . "
\n"; } } ?>