Code: › <?php
/****************************************************************************/
/* PHP-NUKE: Web Portal System */
/* =========================== */
/* */
/* Copyright (c) 2002 by Francisco Burzi (fbc@mandrakesoft.com) */
/* http://phpnuke.org */
/* */
/* 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. */
/* */
/* Block to show users albums in their Gallery which have been updated */
/* since their last visit. */
/* */
/* Dariush Molavi - http://www.nukedgallery.net */
/* email:
dari@nukedgallery.net */
/* version: 1.0 */
/* 4 November 2003 */
/* */
/****************************************************************************/
if (eregi("block-NG-NewestPhoto.php",$PHP_SELF)) {
Header("Location: index.html");
die();
}
global $gallery,$GALLERY_MODULENAME,$GALLERY_EMBEDDED_INSIDE,$GALLERY_EMBEDDED_INSIDE_TYPE;
/*******************************************************************/
/* Full path to your Gallery, don't forget the trailing / */
/*******************************************************************/
$GALLERY_BASEDIR = "/home/pikchaz/public_html/home/modules/Gallery/";
/*******************************************************************/
/* Time, in seconds, to refresh random photo cache. Default is */
/* 86400 (check it daily) */
/*******************************************************************/
define(EXPIRE_TIME, 3600);
/*******************************************************************/
/* The module name of your Gallery, default is "gallery" */
/*******************************************************************/
$GALLERY_MODULENAME="Gallery";
/*******************************************************************/
/* Size of thumbnail. Leave at 0 to use Gallery default */
/*******************************************************************/
define(scaleThumb, 0);
// DON"T CHANGE ANYTHING BELOW HERE
require_once($GALLERY_BASEDIR."init.php");
define(NEW_PHOTO_CACHE,$gallery->app->albumDir."/newestphoto.cache");
$content = "";
$GALLERY_EMBEDDED_INSIDE="nuke";
$GALLERY_EMBEDDED_INSIDE_TYPE = "phpnuke";
function getNewestPhoto($albumName, $depth=0) {
global $gallery, $dateArray, $imageArray, $albumNameArray,$GALLERY_EMBEDDED_INSIDE,$GALLERY_EMBEDDED_INSIDE_TYPE, $GALLERY_MODULENAME;
$tempDates = array();
$tempImages = array();
$myAlbum = new Album();
$myAlbum->load($albumName);
$numPhotos = $myAlbum->numPhotos(1);
for ($i=1; $i <= $numPhotos; $i++) {
if(!$myAlbum->getAlbumName($i)) {
$id = $myAlbum->getPhotoId($i);
$index = $myAlbum->getPhotoIndex($id);
array_push($tempDates, $myAlbum->getUploadDate($index));
array_push($tempImages, $id);
}
}
arsort($tempDates);
$keys = array_keys($tempDates);
array_push($dateArray, $tempDates[$keys[0]]);
array_push($imageArray, $tempImages[$keys[0]]);
array_push($albumNameArray, $albumName);
}
function scanNewestPhoto() {
global $gallery, $dateArray, $imageArray, $albumNameArray;
$dateArray = array();
$imageArray = array();
$albumNameArray = array();
$everybody = new EverybodyUser();
$albumDB = new AlbumDB(FALSE);
foreach ($albumDB->albumList as $tmpAlbum) {
if($everybody->canReadAlbum($tmpAlbum)) {
$name = $tmpAlbum->fields["name"];
$title = $tmpAlbum->fields["title"];
getNewestPhoto($name);
}
}
}
function saveNewestPhoto() {
global $gallery, $dateArray, $imageArray, $albumNameArray;
arsort($dateArray);
$dateKeys = array_keys($dateArray);
$new_image_file = fopen(NEW_PHOTO_CACHE,"w");
fwrite($new_image_file, $dateArray[$dateKeys[0]]."/".$albumNameArray[$dateKeys[0]]."/".$imageArray[$dateKeys[0]]);
fclose($new_image_file);
}
function readNewestPhoto() {
global $gallery, $GALLERY_EMBEDDED_INSIDE, $GALLERY_EMBEDDED_INSIDE_TYPE, $GALLERY_MODULENAME;
$GALLERY_EMBEDDED_INSIDE="nuke";
$GALLERY_EMBEDDED_INSIDE_TYPE="phpnuke";
$file =fopen(NEW_PHOTO_CACHE,"r");
for($i=0;$i<3;$i++) {
$line =fgets($file, 4096);
$fileArray = explode("/",$line);
$newestPhotoAlbum = new Album();
$newestPhotoAlbum->load($fileArray[1]);
$id = $fileArray[2];
$index = $newestPhotoAlbum->getPhotoIndex($id);
$PHOTO_URL = makeAlbumUrl($newestPhotoAlbum->fields['name'], $id);
$ALBUM_URL = makeAlbumUrl($newestPhotoAlbum->fields['name']);
$IMG = "<center><a href=\"$PHOTO_URL\">" . $newestPhotoAlbum->getThumbnailTag($index, scaleThumb) . $
$CAPTION = "<br>".$newestPhotoAlbum->getCaption($index);
$FROM = "<br>From: <a href=\"$ALBUM_URL\">" . $newestPhotoAlbum->fields['title'] . '</a><br>';
$content = $IMG;
$content .= $CAPTION;
$content .= $FROM;
}
return $content;
}
$rebuild = 0;
if (fs_file_exists(NEW_PHOTO_CACHE)) {
$stat = fs_stat(NEW_PHOTO_CACHE);
$mtime = $stat[9];
if (time() - $mtime > EXPIRE_TIME) {
$rebuild = 1;
}
}
else {
scanNewestPhoto();
saveNewestPhoto();
$content = readNewestPhoto();
}
if($rebuild) {
scanNewestPhoto();
saveNewestPhoto();
$content = readNewestPhoto();
}
else {
$content = readNewestPhoto();
}
?>