Support Forums | Demo Gallery [1.x] [2.x] | Downloads | News | Site Map ]
Nuked Gallery
  Create a FREE account or Login   As a guest, you don't have access to our FULL navigation system.
 Forum FAQForum FAQ   StatisticsStatistics   SearchSearch   UsergroupsUsergroups   FavoritesFavorites  

[RELEASE] Random Photo V2
Goto page Previous  1, 2, 3, 4, 5, 6
 
Post new topic   Reply to topic    NukedGallery.net Forum Index » PHP-Nuke Integration » Blocks View previous topicPrinter friendly versionView next topic
Author Message
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6318
Location: Washington Township, NJ, USA

PostPosted: Fri Jul 08, 2005 6:27 am    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

hmm...can you post the config lines from your block?
Back to top
Offline View user's profile Send private message Visit poster's website
AdBot
   Post subject: Re: [RELEASE] Random Photo V2  

Back to top
artificialhero

Beginner
Beginner


Joined: Jul 07, 2005
Posts: 3

PostPosted: Sat Jul 09, 2005 12:29 pm    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

block-NG-RandomPhoto.php:

Code: › <?php

/*
 * 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, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Developed by Dariush Molavi at NukedGallery.net
 * Version 2.0
 * 11 December 2003
 */

 if (eregi("block-NG-RandomPhoto.php",$_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

global $gallery, $Version_Num;

require_once("NG-RandomPhoto_functions.php");

/*******************************************************************/
/* Valid values for $selector: "DAILY", "HOURLY", "RANDOM", "AUTO" */
/* DAILY, HOURLY show a new photo each day/hour                    */
/* RANDOM shows a new photo with each reload of the page           */
/* AUTO refreshes just the block with a new random photo      */
/*******************************************************************/
$selector = "RANDOM";

/*******************************************************************/
/* Number of seconds between autorefresh of block, valid only for  */
/* $selector = AUTO                                                */
/*******************************************************************/
$auto_rate = 5;

/*******************************************************************/
/* Number of photos to display, valid only for $selector = RANDOM  */
/*******************************************************************/
$number_of_pix = 3;

/*******************************************************************/
/* Show photos horozontally(1) or vertically(0). Valid only for    */
/* $selector = RANDOM                                              */
/*******************************************************************/
$horozontal = 0;

/*******************************************************************/
/* Size of thumbnail. Leave at 0 to use Gallery default            */
/*******************************************************************/
$scaleTo = 0;

/*******************************************************************/
/* Scrolling photos, valid only for $selector = RANDOM             */
/*******************************************************************/
$scroll = 1;


NG-RandomPhoto_functions.php:

Code: › <?php

/*
 * 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, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Developed by Dariush Molavi at NukedGallery.net
 * Version 2.0
 * 13 December 2003
 */

 if (eregi("block-NG-RandomPhoto_functions.php",$_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

global $gallery, $GALLERY_EMBEDDED_INSIDE, $GALLERY_EMBEDDED_INSIDE_TYPE, $GALLERY_MODULENAME, $Version_Num;

/*******************************************************************/
/* Full path to your Gallery, don't forget the trailing /          */
/*******************************************************************/
$GALLERY_BASEDIR = "/home/public_html/NEW/modules/gallery/";

/*******************************************************************/
/* The module name of your Gallery, default is "gallery"           */
/*******************************************************************/
$GALLERY_MODULENAME = "gallery";

/*******************************************************************/
/* Time, in seconds, to refresh random photo cache. Default is     */
/* 86400 (check it daily)                                          */
/*******************************************************************/
define(CACHE_EXPIRED, 10);

/*******************************************************************/
/* Full path to your albums directory, don't forget the trailing / */
/*******************************************************************/
define(ALBUM_DIRECTORY,"/home/public_html/images/");



/*******************************************************************/
/*          STOP!! DO NOT EDIT ANYTHING BELOW THIS POINT           */
/*******************************************************************/
define(CACHE_FILE, ALBUM_DIRECTORY."block-random.cache");

$GALLERY_EMBEDDED_INSIDE = "nuke";
$GALLERY_EMBEDDED_INSIDE_TYPE = "phpnuke";

require_once($GALLERY_BASEDIR . "init.php");

function createBlockContent($album,$index,$scale,$auto=0) {
   global $gallery, $GALLERY_EMBEDDED_INSIDE, $GALLERY_EMBEDDED_INSIDE_TYPE, $GALLERY_MODULENAME;

   $id = $album->getPhotoId($index);
   $caption = $album->getCaption($index);
   $photo = $album->getPhoto($index);
   $dir = $album->getAlbumDirURL("full");
   $image = $photo->image;
   $PHOTO_URL = makeAlbumUrl($album->fields['name'], $id);
   $ALBUM_URL = makeAlbumUrl($album->fields['name']);
   if($scale == 0) {
                        if($auto == 0) {
                                $IMG = "<center><a href=\"$PHOTO_URL\">".$album->getThumbnailTag($index)."</a><br>";
                        }
                        else {
                                $IMG = "<center><a href=\"$PHOTO_URL\" target=\"_top\">".$album->getThumbnailTag($index)."</a><br>";
                        }
   } else {
                        if($auto == 0) {
                                $IMG = "<center><a href=\"$PHOTO_URL\">".$album->getThumbnailTag($index,$scale)."</a><br>";
                        }
                        else {
                                $IMG = "<center><a href=\"$PHOTO_URL\" target=\"_top\">".$album->getThumbnailTag($index,$scale)."</a><br>";
                        }
   }
   $FROM = "From: <a href=\"$ALBUM_URL\">" . $album->fields['title'] . '</a>';
   $blockContent .=  "\t$IMG\n";
   $blockContent .= "\t$caption<br />\n";
   $blockContent .= "\t$FROM\n</center>";
   return $blockContent;
}

function get_photo($interval, $scale,$auto=0) {
   global $gallery, $GALLERY_EMBEDDED_INSIDE, $GALLERY_EMBEDDED_INSIDE_TYPE, $GALLERY_MODULENAME;

   switch ($interval) {
      case 0:
         list($album,$index) = get_random_photo_id();
         while($album->getAlbumName($index)) {
            list($album,$index) = get_random_photo_id();
         }
         $blockContent = createBlockContent($album,$index,$scale,$auto);
         return $blockContent;
         break;
      case 1:
         if (file_exists($gallery->app->albumDir."/hourly.txt")) {
            $stat=stat($gallery->app->albumDir."/hourly.txt");
            $modtime = $stat['mtime'];
            if(date("G", $modtime) != date("G", time())) {            
               list($album,$index) = get_random_photo_id();
                              while($album->getAlbumName($index)) {
                                      list($album,$index) = get_random_photo_id();
                              }
               $blockContent = createBlockContent($album,$index,$scale);
               $fp = fopen($gallery->app->albumDir."/hourly.txt","w");
               fwrite($fp,$album->fields['name']."/".$index);
               fclose($fp);
               return $blockContent;
            }
            else {
               $fp = fopen($gallery->app->albumDir."/hourly.txt","r");
               $line = explode("/",fgets($fp));
               $albumName = $line[0];
               $album = new Album();
               $album->load($albumName);
               $index = $line[1];
               $blockContent = createBlockContent($album,$index,$scale);
               return $blockContent;
            }
         }
         else {
            list($album,$index) = get_random_photo_id();
                           while($album->getAlbumName($index)) {
                                   list($album,$index) = get_random_photo_id();
                           }
            $blockContent = createBlockContent($album,$index,$scale);
            $fp = fopen($gallery->app->albumDir."/hourly.txt","w");
            fwrite($fp,$album->fields['name']."/".$index);
            fclose($fp);
            return $blockContent;
         }
         break;
      case 24:
         if (file_exists($gallery->app->albumDir."/daily.txt")) {
            $stat=stat($gallery->app->albumDir."/daily.txt");
            $modtime = $stat['mtime'];
            if(date("d", $modtime) != date("d", time())) {            
               list($album,$index) = get_random_photo_id();
                              while($album->getAlbumName($index)) {
                                      list($album,$index) = get_random_photo_id();
                              }
               $blockContent = createBlockContent($album,$index,$scale);
               $fp = fopen($gallery->app->albumDir."/daily.txt","w");
               fwrite($fp,$album->fields['name']."/".$index);
               fclose($fp);
               return $blockContent;
            }
            else {
               $fp = fopen($gallery->app->albumDir."/daily.txt","r");
               $line = explode("/",fgets($fp));
               $albumName = $line[0];
               $album = new Album();
               $album->load($albumName);
               $index = $line[1];
               $blockContent = createBlockContent($album,$index,$scale);
               return $blockContent;
            }
         }
         else {
            list($album,$index) = get_random_photo_id();
                           while($album->getAlbumName($index)) {
                                   list($album,$index) = get_random_photo_id();
                           }
            $blockContent = createBlockContent($album,$index,$scale);
            $fp = fopen($gallery->app->albumDir."/daily.txt","w");
            fwrite($fp,$album->fields['name']."/".$index);
            fclose($fp);
            return $blockContent;
         }
         break;
   }
}

function get_random_photo_id(){
      /* Initializing the seed */
      srand ((double) microtime() * 1000000);

      // Check the cache file to see if it's up to date
      $rebuild = 0;
      if (fs_file_exists(CACHE_FILE)) {
         $stat = fs_stat(CACHE_FILE);
         $mtime = $stat[9];
         if ((time() - $mtime) > CACHE_EXPIRED) {
            $rebuild = 1;
         }
      }
      else {
         $rebuild = 1;
      }

      if ($rebuild) {
         scanalbums();
         savecache();
      }
      else {
         readcache();
      }

      $album = choosealbum();

      if ($album) {
         $index = choosephoto($album);
      }
      return array($album,$index);
}

function savecache() {
    global $cache;
    $fd = fopen(CACHE_FILE, "w");
    foreach ($cache as $key => $val) {
   fwrite($fd, "$key/$val\n");
    }
    fclose($fd);
}

function readcache() {
    global $cache;
    if ($fd = fs_fopen(CACHE_FILE, "r")) {
      while ($line = fgets($fd, 4096)) {
         list($key, $val) = explode("/", $line);
         $cache[$key] = $val;
      }
      fclose($fd);
    }
}

function choosephoto($album) {
    global $cache, $gallery;

    $count = $cache[$album->fields["name"]];

    if ($count == 0) {
      // Shouldn't happen
      return null;
    } else if ($count == 1) {
      $choose = 1;
    } else {
      $count = floatval($count);
      $choose = rand(1, $count);
      $wrap = 0;
      if ($album->isHidden($choose)) {
         $choose++;
         if ($choose > $album->numPhotos(1)) {
            $choose = 1;
            $wrap++;
            if ($wrap = 2) {
               return null;
            }
         }
      }
    }
    return $choose;
}

function choosealbum() {
    global $cache;

    /*
     * The odds that an album will be selected is proportional
     * to the number of (visible) items in the album.
     */

    $total = 0;
    foreach ($cache as $name => $count) {
      if (!$choose) {
         $choose = $name;
      }

      $total += $count;
      if ($total != 0 && ($total == 1 || rand(1, $total) <= $count)) {
         $choose = $name;
      }
    }

    if ($choose) {
      $album = new Album();
      $album->load($choose);
      return $album;
    } else {
      return null;
    }
}

function scanalbums() {
    global $cache;
    global $gallery;

    $cache = array();
    $everybody = $gallery->userDB->getEverybody();
    $albumDB = new AlbumDB();
    foreach ($albumDB->albumList as $tmpAlbum) {
      if ($everybody->canReadAlbum($tmpAlbum)) {
         $seeHidden = $everybody->canWriteToAlbum($tmpAlbum);
         $numPhotos = $tmpAlbum->numPhotos($seeHidden);
         $name = $tmpAlbum->fields["name"];
         if ($numPhotos > 0) {
            $cache[$name] = $numPhotos;
         }
      }
    }
}

?>


Thanks in advance,

ArtificialHero
Back to top
Offline View user's profile Send private message
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6318
Location: Washington Township, NJ, USA

PostPosted: Mon Jul 11, 2005 8:09 am    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

perhaps you need the "NEW" in your album path?

also, if you're on a virtual server (ie, from a hosting company), sometimes they "mask" the true paths to the files. create a phpinfo file and see what the path is that it reveals as the "script path".
Back to top
Offline View user's profile Send private message Visit poster's website
artificialhero

Beginner
Beginner


Joined: Jul 07, 2005
Posts: 3

PostPosted: Mon Jul 11, 2005 3:04 pm    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

That was it! Finding the script path and using that sorted it! thanks very much

artificialhero
Back to top
Offline View user's profile Send private message
mykroft

Beginner
Beginner


Joined: Sep 18, 2005
Posts: 4

PostPosted: Sun Sep 18, 2005 2:01 am    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

Ok, I am not new to gallery or php-nuke but.....

Am trying to get the block working correctly. Have made a test block as the last block on the right side.

Everything displays until I get to that block. No error msgs, and no page footer. It just stops. There is nothing even in display source .. last line is a <br> and then the next block should start.

Any ideas where to start. I have tripple checks the paths in the function file...

Thanks
Myk
Back to top
Offline View user's profile Send private message
mykroft

Beginner
Beginner


Joined: Sep 18, 2005
Posts: 4

PostPosted: Sun Sep 18, 2005 2:07 am    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

Ok, I should have checked the paths a 4th time Sad

Got that part correct but now....

The block shows up but is a black square where the pic should be.

Here is what is showing in the view source:

Code: ›
</head>
<TABLE WIDTH="181" BORDER="0" CELLPADDING="0" CELLSPACING="0">
  <TR>
    <TD width="181" height="26" class="right1">test</TD>
  </TR>
  <TR>
    <TD width="181" valign="top" class="right2"><center><iframe name="randomblock" scrolling="no" allowtransparency="true" width="140" src="block-NG-AutoPhoto.php?rate=5" frameborder="0" marginheight="0" marginwidth="0" hspace="0" vspace="0"></iframe></center></TD>
  </TR>
  <TR>
    <TD><IMG SRC="themes/alliancefull/images/alliancefull_33.jpg" WIDTH=181 HEIGHT=3 ALT=""></TD>
  </TR>
</TABLE>
<br></head>
<TABLE WIDTH="181" BORDER="0" CELLPADDING="0" CELLSPACING="0">
  <TR>
    <TD width="181" height="26" class="right1">Old Articles</TD>
  </TR>
  <TR>
    <TD width="181" valign="top" class="right2"><center>There isn't content right now for this block.</center></TD>
  </TR>
  <TR>
    <TD><IMG SRC="themes/alliancefull/images/alliancefull_33.jpg" WIDTH=181 HEIGHT=3 ALT=""></TD>
  </TR>
</TABLE>


I do not know where that first </head> is comming from....

Suggestions?

Thanks
Myk
Back to top
Offline View user's profile Send private message
mykroft

Beginner
Beginner


Joined: Sep 18, 2005
Posts: 4

PostPosted: Sun Sep 18, 2005 2:25 am    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

Found it and got it working.

Sorry - need to use search better....

FYI - would cause alot less greef for everyone if the dist files where updated with the isAlbumName > getaAlbumName fix.....

Myk
Back to top
Offline View user's profile Send private message
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6318
Location: Washington Township, NJ, USA

PostPosted: Tue Sep 20, 2005 6:40 am    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

mykroft -
agreed, will do as soon as i'm done my forum run this AM.
Back to top
Offline View user's profile Send private message Visit poster's website
kachukuma

Beginner
Beginner


Joined: Sep 03, 2005
Posts: 1

PostPosted: Fri Nov 18, 2005 7:25 pm    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

trying to use it as a center block. screws up the right side blocks (they vanish)... and doesnt work itself either (does not show up). Only the left hand side blocks shop up, the center content and blocks show up except for this one... Sad

php v4.3.3 using phpnuke 7.8 with chatserv patched 3.1, gallery 1.5 ... Gallery's working like a charm otherwise.

PLEASE HELP!!!
Back to top
Offline View user's profile Send private message
BumontheRun

Beginner
Beginner


Joined: Nov 24, 2005
Posts: 1

PostPosted: Mon Nov 28, 2005 11:44 pm    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

kachukuma wrote: › trying to use it as a center block. screws up the right side blocks (they vanish)... and doesnt work itself either (does not show up). Only the left hand side blocks shop up, the center content and blocks show up except for this one... Sad

php v4.3.3 using phpnuke 7.8 with chatserv patched 3.1, gallery 1.5 ... Gallery's working like a charm otherwise.

PLEASE HELP!!!


I've got the same problem but with nuke 7.9 at PHP 4.3.11
Back to top
Offline View user's profile Send private message
DannD

Beginner
Beginner


Joined: Nov 10, 2005
Posts: 2

PostPosted: Tue Jan 24, 2006 12:29 pm    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

BumontheRun wrote: ›
kachukuma wrote: › trying to use it as a center block. screws up the right side blocks (they vanish)... and doesnt work itself either (does not show up). Only the left hand side blocks shop up, the center content and blocks show up except for this one... Sad

php v4.3.3 using phpnuke 7.8 with chatserv patched 3.1, gallery 1.5 ... Gallery's working like a charm otherwise.

PLEASE HELP!!!


I've got the same problem but with nuke 7.9 at PHP 4.3.11


got the same problem, everything after where the block should be is missing aswell as the block.
Back to top
Offline View user's profile Send private message
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6318
Location: Washington Township, NJ, USA

PostPosted: Wed Jan 25, 2006 9:21 am    Post subject: Re: [RELEASE] Random Photo V2 Reply with quote

did you double check to make sure that the isalbumname / getalbumname switch is in your code?
Back to top
Offline View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    NukedGallery.net Forum Index » PHP-Nuke Integration » Blocks View previous topicPrinter friendly versionView next topic
Goto page Previous  1, 2, 3, 4, 5, 6

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours

Powered by phpBB © phpBB Group



Sponsors: Dedicated ServersDomain NamesWeb HostingDomain Name RegistrationDedicated Web HostingWeb Design New YorkCompare VoIPSEO IndiaWeb Design MelbournePhoenix SEOPhoenix Web MarketingSEOflorida web design companyScottsdale Interior Designweb marketing servicesScottsdale SEOAsked Last NightSEO ServicesSEO IndiaWeb Development IndiaPHP Web Development IndiaWeb DirectoryNew York Yellow Pages

7th year online! 2003-2010
Legal • Use of this site consitutes agreement to the Acceptable Use Policy
Hosted by Implosion WorksSourceForge.net Logo • Theme by TonicMedia