View Single Post
Hmm well I see others doing it so I will post mine
Old
  (#2 (permalink))
Eck
Junior Member
 
Status: Offline
Posts: 3
Join Date: Apr 2005
Hmm well I see others doing it so I will post mine - 04-09-2005, 03:14 PM

This is the code I am using. I just changed the file name to block-lastimage.php and threw it in my blocks folder.

Quote:
global $GALLERY_NO_SESSIONS;
global $GALLERY_BASEDIR;
global $GALLERY_EMBEDDED_INSIDE;
global $GALLERY_MODULENAME;
global $gallery;
$GALLERY_MODULENAME = "Gallery"; //Change this to your module Name
$GALLERY_NO_SESSIONS = true;
$GALLERY_EMBEDDED_INSIDE = "nuke"; //these next two vars were changed by lincles so that
$GALLERY_EMBEDDED_INSIDE_TYPE = "phpnuke"; //this script would work with the gallery init file correctly
//change from postnuke if using other nuke

// Control variables (multiple page display mooted).
$photocount = 8;
$maxphotos = 10;
// You can also comment out the $photocount line above, and add a variable to
// your URL: include.php?type=date&photocount=10 - but if you do this, you need
// to specify the photocount variable when include.php is called, or you'll get
// a divisible by zero error.

$photosperrow = 4;
//this variable and all the table tags below were added by lincles so that the
//block could be a center block and have multiple per row, and have multiple rows.

// 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;
}

if (!isset($GALLERY_BASEDIR)) {
$GALLERY_BASEDIR = "/home/yoursitename/public_html/html/modules/gallery/"; //if you are using a url include to include this script,
//change this to ""
}
require_once($GALLERY_BASEDIR . 'init.php');

$borderColor = $gallery->app->default["bordercolor"];
// I set this to a static number for small, 72-pixel thumbnails.
// To use the Gallery default, change this line to the following:
// $thumbSize = $gallery->app->default["thumb_size"];
$thumbSize = 100;
?>

<?php
$navigator["fullWidth"] = 100;
$navigator["widthUnits"] = "%";
$albumDB = new AlbumDB();
$list = $albumDB->albumList;
$numAlbums = count($list);
$skip = array();
for ($i = 0; $i<$numAlbums; $i++) {
$statsAlbum = $list[$i];
if ($statsAlbum->versionOutOfDate()) {
$skip[] = $statsAlbum;
continue;
}
$uid = $gallery->user->getUid();
if ($statsAlbum->canRead($uid) || $gallery->user->isAdmin()) {
$numPhotos = $statsAlbum->numPhotos(1);
for ($j = 1; $j <= $numPhotos; $j++) {
if ( !$statsAlbum->getalbumname($j) )
{
$views = $statsAlbum->getItemClicks($j);
$uploaddate = $statsAlbum->getUploadDate($j);
$arrPhotos[] = array("albumName" => $statsAlbum->fields['name'],
"photoIndex" => $j,
"votes" => $votes,
"views" => $views,
"uploaddate" => $uploaddate);
}
}
}
}
if ( $type == "votes" )
{
usort($arrPhotos, "votesort");
}
else if ( $type == "views" )
{
usort($arrPhotos, "viewsort");
}
else if ( $type == "date" )
{
usort($arrPhotos, "datesort");
}
function votesort($a, $b) {
if ($a['votes'] == $b['votes']) {
return 0;
}
return ($a['votes'] > $b['votes']) ? -1 : 1;
}
function viewsort($a, $b) {
if ($a['views'] == $b['views']) {
return 0;
}
return ($a['views'] > $b['views']) ? -1 : 1;
}
function datesort($a, $b) {
if ($a['uploaddate'] == $b['uploaddate']) {
return 0;
}
return ($a['uploaddate'] > $b['uploaddate']) ? -1 : 1;
}
$uid = $gallery->user->getUid();

if ( !isset($page) )
{
$page = 1;
}
if ( $maxphotos < 0 || $maxphotos > sizeof($arrPhotos))
{
$maxphotos = sizeof($arrPhotos);
}
$startPhoto = ($page - 1) * $photocount;
// Use fuz factor to avoid rounding up when result is 0.5
$lastpage = round( ($maxphotos / $photocount) - 0.500001) + 1;
?>
<table width="100%" cellspacing="0" cellpadding="5"><tr>
<?php
for ($j = $startPhoto; $j < $maxphotos && $j < $startPhoto + $photocount; $j+=1)
{

$photoInfo = $arrPhotos[$j];
for ( $i = 0; $i < $numAlbums; ++$i )
{
if ( !strcmp($photoInfo['albumName'], $list[$i]->fields['name']) )
{
$statsAlbum = $list[$i];
break;
}
}

if (isset($statsAlbum))
{
$photoIndex = $photoInfo['photoIndex'];
$photoId = $statsAlbum->getPhotoId($photoIndex);
if ($statsAlbum->canRead($uid) || $gallery->user->isAdmin())
{
if (!$statsAlbum->isHidden($photoIndex) ||
$statsAlbum->isOwner($uid) ||
$gallery->user->isAdmin())
{
$statsCaption = $statsAlbum->getCaption($photoIndex);
// $statsCaption .= $statsAlbum->getCaptionName($photoIndex);
$statsUrl = makeAlbumUrl($statsAlbum->fields['name'], $photoId);

if (0 == $j%$photosperrow && $startPhoto != $j)
echo '</tr><tr>';
?>
<td align="center">
<?php

$gallery->html_wrap['imageTag'] = $statsAlbum->getThumbnailTag($photoIndex, $thumbSize);
$gallery->html_wrap['imageHref'] = $statsUrl;
$gallery->html_wrap['frame'] = "none";
includeHtmlWrap('inline_gallerythumb.frame');

?>

<?php
$output = "";
if ($statsCaption) {
$output = "
$statsCaption";
}
echo $output;
$output = "
Album: "
."<a href=" .makeAlbumUrl($statsAlbum->fields["name"]) .">"
.$statsAlbum->fields["title"]
."</a></td>";
echo $output;
?>

<?php
}
}
}
}

?>
</tr></table>
<?php
/*
* To call these images from another page on your site, you can use either
* PHP or SSI include calls. In a PHP page, use the command:
*
* <?
* include "http://www.yourdomain.com/gallery/include.php?type=xxxx";
* ?>
*
* In a SHTML page, use the command:
*
*
*
* Change 'xxxx' to your preferred sort type. And remember, you can specify
* for each include the number of images shown by commenting out the $photocount
* variable above and adding it to your include URL. For example:
*
*
*
* ----- The following was added by lincles on 4/8/2004---------
* The following information is using versions:
* postnuke 7.2.6
* gallery 1.4.2
*
* I had troubles with permissions on the photos. When I included this script in the way
* prescribed above, gallery always thought that I was not logged in and would only show
* me pictures viewable by everybody. I found out that this was because all of the
* pnUser functions that postnuke uses to to get user info was not transfered in the
* include. When i changed the include to a file path and set the $type var before the
* include, it fixed this problem. A few other changes were needed was now that it is a
* file include instead of a url, the $GALLERY_BASEDIR had to be set to the dir relitive
* to postnuke, instead of the lastimage.php file. Also the $GALLERY_EMBEDDED_INSIDE value
* was changed to "nuke" and i added $GALLERY_EMBEDDED_INSIDE_TYPE and set it to "postnuke"
* since these are the values that gallery has when running as a module in postnuke. This
* should make it so you only see pictures that you have rights to see and if you have rights
* to see private photos, you see them.
*
* The script in my php block looked like the following
*
* $type = date;
* include('modules/gallery/lastimage.php');
*
* change $type to how you want the pictures sorted - votes,views, or date.
*/
   
Reply With Quote