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  

Fatal error: Call to undefined function: floatval()

 
Post new topic   Reply to topic    NukedGallery.net Forum Index » PHP-Nuke Issues » Blocks View previous topicPrinter friendly versionView next topic
Author Message
hue

Beginner
Beginner


Joined: Oct 04, 2003
Posts: 3

PostPosted: Wed Dec 03, 2003 12:49 pm    Post subject: Fatal error: Call to undefined function: floatval() Reply with quote

<your message here>Hello, I have nuke 6.8
Gallery 1.4-pl1
Readhat server
The gallery works great only when i try and add the random block i get this error
Fatal error: Call to undefined function: floatval() in /home/httpd/vhosts/1stmarinedivision.com/httpdocs/modules/gallery/random_support.php on line 199
The image will show up until you refresh your page , then its gone! Also, the link dont work once you click on the photo, just page can not be displayed! Any help would be greatly apprciated
----
Give us your Gallery/webserver information to get a faster answer.
Get this information from the PHP diagnostic (in the configuration wizard).
Gallery URL (optional but very useful):
Gallery version:
Apache version:
PHP version (don't just say PHP 4, please):
Graphics Toolkit:
Operating system:
Web browser/version (if applicable):
The CONFIG lines from the top of your block file(s):[/code]
Back to top
Offline View user's profile Send private message
AdBot
   Post subject: Fatal error: Call to undefined function: floatval()  

Back to top
hue

Beginner
Beginner


Joined: Oct 04, 2003
Posts: 3

PostPosted: Wed Dec 03, 2003 1:11 pm    Post subject: Re: Fatal error: Call to undefined function: floatval() Reply with quote

Isnt This function is only in CVS. ?
Back to top
Offline View user's profile Send private message
slackbladder

Moderator
Moderator


Joined: Mar 29, 2003
Posts: 1038
Location: Cambs,UK

PostPosted: Wed Dec 03, 2003 1:52 pm    Post subject: Reply with quote

Plz post your random_support.php here and the CONFIG lines from the top of your block-NG-random.php
_________________
"The only difference between me and a madman is that I'm not mad."
Back to top
Offline View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
dari

Site Admin
Site Admin


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

PostPosted: Wed Dec 03, 2003 1:54 pm    Post subject: Reply with quote

floatval is a standard PHP function:
http://www.php.net/floatval
what version of PHP are you running? if it's older than 4.2.0, that's why you're getting this error.
_________________
Back to top
Offline View user's profile Send private message Visit poster's website
hue

Beginner
Beginner


Joined: Oct 04, 2003
Posts: 3

PostPosted: Wed Dec 03, 2003 3:47 pm    Post subject: Re: Fatal error: Call to undefined function: floatval() Reply with quote

My php version is 4.1.2 as for the random_support.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.
 */
/*
 * Original random block code from gallery.menalto.com
 * This updated version (c) 2003 Dariush Molavi
 * dari.molavi@nukedgallery.net
 * Version 1.0
 * 8 August 2003
 */
global $gallery, $GALLERY_BASEDIR;

$GALLERY_BASEDIR = "/home/httpd/vhosts/1stmarinedivision.com/httpdocs/modules/gallery/";
require_once($GALLERY_BASEDIR . "init.php");
define(ALBUM_BASEADDR, "http://1stmarinedivision.com/albums/");
define(CACHE_FILE, $gallery->app->albumDir . "/block-random.cache");   
define(SERVER_ADDR, "1stmarinedivision.com/");
define(CACHE_EXPIRED, 86400);

function daily_photo(){
        global $gallery;
        if((fs_file_exists($gallery->app->albumDir."/daily.jpg"))){
                $stat=stat($gallery->app->albumDir."/daily.jpg");
                $modtime = $stat['mtime'];
                if(date("d", $modtime) != date("d", time())) {
                        list($album,$index) = get_random_photo_id();
                        list($url, $albumURL) = random_photo($album,$index,24);
            $content = "<center><a href=\"".$url."\"><img src=\"".ALBUM_BASEADDR."daily.jpg\" border=\"0\"></a></center>";
                        $content .= "<br><center>From: <a href=\"".$albumURL."\">".$album->fields["title"]."</a></center>";
                }
                else{
            $fp = fs_fopen($gallery->app->albumDir."/daily.txt", "r");
            $line = explode("      ",fgets($fp, 4096));
            fclose($fp);
            $content = "<center><a href=\"".$line[0]."\"><img src=\"".ALBUM_BASEADDR."daily.jpg\" border=\"0\"></a></center>";
                        $content .= "<br><center>From: <a href=\"".$line[1]."\">".$line[2]."</a></center>";
                }
      }
      else {
            list($album,$index) = get_random_photo_id();
                   list ($url, $albumURL) = random_photo($album,$index,24);
                        $content = "<center><a href=\"".$url."\"><img src=\"".ALBUM_BASEADDR."daily.jpg\" border=\"0\"></a></center>";
                        $content .= "<br><center>From: <a href=\"".$albumURL."\">".$album->fields["title"]."</a></center>";
      }
      return $content;
}
 
  function hourly_photo(){
        global $gallery;
        if((fs_file_exists($gallery->app->albumDir."/hourly.jpg"))){
                $stat=stat($gallery->app->albumDir."/hourly.jpg");
                $modtime = $stat['mtime'];
                if(date("G", $modtime) != date("G", time())) {
                        list($album,$index) = get_random_photo_id();
                        list($url, $albumURL) = random_photo($album,$index,1);
            $content = "<center><a href=\"".$url."\"><img src=\"".ALBUM_BASEADDR."hourly.jpg\" border=\"0\"></a></center>";
                        $content .= "<br><center>From: <a href=\"".$albumURL."\">".$album->fields["title"]."</a></center>";
                }
                else{
            $fp = fs_fopen($gallery->app->albumDir."/hourly.txt", "r");
            $line = explode("      ",fgets($fp, 4096));
            fclose($fp);
            $content = "<center><a href=\"".$line[0]."\"><img src=\"".ALBUM_BASEADDR."hourly.jpg\" border=\"0\"></a></center>";
                        $content .= "<br><center>From: <a href=\"".$line[1]."\">".$line[2]."</a></center>";
                }
      }
      else {
            list($album,$index) = get_random_photo_id();
                   list ($url, $albumURL) = random_photo($album,$index,1);
                        $content = "<center><a href=\"".$url."\"><img src=\"".ALBUM_BASEADDR."hourly.jpg\" border=\"0\"></a></center>";
                        $content .= "<br><center>From: <a href=\"".$albumURL."\">".$album->fields["title"]."</a></center>";
      }
      return $content;
  }
 
  function random_photo($album, $index,$filetype){
        global $gallery;
                if (isset($index)) {
                        $id = $album->getPhotoId($index);
                        $url = SERVER_ADDR;
                        $url .= "modules.php?set_albumName=".$album->fields["name"];
                        $url .= "&id=" .$id;
                        $url .= "&op=modload&name=gallery&file=index&include=view_photo.php";

                        $albumURL = SERVER_ADDR;
                        $albumURL .= "modules.php?set_albumName=".$album->fields["name"];
                        $albumURL .= "&op=modload&name=gallery&file=index&include=view_album.php";
                        $content = "<center><a href=\"$url\">".$album->getThumbnailTag($index)."</a></center>";
                        $caption = $album->getCaption($index);
                        if ($caption) {
                                $content.="<br><center>".$caption."</center>";
                        }
                        $content .= "<br><center>From: <a href=\"".$albumURL."\">".$album->fields["title"]."</a></center>";

                } else {
                        $content = "No photo chosen.";
                }
                if($filetype == 24) {
               
fs_copy($gallery->app->albumDir."/".$album->fields["name"]."/".$id.".thumb.jpg",$gallery->app->albumDir."/daily.jpg");
               $fp = fs_fopen($gallery->app->albumDir."/daily.txt","w");
               fwrite($fp,$url."      ".$albumURL."      ".$album->fields["title"]);
               fclose($fp);
               return array($url, $albumURL);
              }
                else if($filetype == 1) {
               
fs_copy($gallery->app->albumDir."/".$album->fields["name"]."/".$id.".thumb.jpg",$gallery->app->albumDir."/hourly.jpg");
               $fp = fs_fopen($gallery->app->albumDir."/hourly.txt","w");
               fwrite($fp,$url."      ".$albumURL."      ".$album->fields["title"]);
               fclose($fp);
               return array($url, $albumURL);
              }

        return $content;
  }

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

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

                $album = choosealbum();

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

   /*
 * --------------------------------------------------
 * Support functions
 * --------------------------------------------------
 */

function savecache() {
    global $cache;
    if ($fd = fs_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;

    $count = $cache[$album->fields["name"]];
       
    if ($count == 0) {
        // Shouldn't happen
        return null;
    } else if ($count == 1) {
        $choose = 1;
    } else {
                $count = (float)$foo;($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;
                        }
                }
    }
}
?>


and for the config lines (which mine is called block-RandomPhoto.php )
Code: › $GALLERY_BASEDIR = "/home/httpd/vhosts/1stmarinedivision.com/httpdocs/modules/gallery/";
require_once($GALLERY_BASEDIR . "random_support.php");


define(CACHE_FILE, $gallery->app->albumDir."/block-random.cache");
define(ALBUM_BASEADDR, "http://1stmarinedivision.com/albums/");
define(SERVER_ADDR, "1stmarinedivision.com/");
require_once($GALLERY_BASEDIR . "init.php");
Back to top
Offline View user's profile Send private message
dari

Site Admin
Site Admin


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

PostPosted: Wed Dec 03, 2003 3:49 pm    Post subject: Reply with quote

your version of PHP does not support the floatval command.
either upgrade (good idea, since it's also very buggy), or use:
(float)<var> instead of floatval(<var>)
_________________
Back to top
Offline View user's profile Send private message Visit poster's website
gijza

Beginner
Beginner


Joined: Apr 14, 2003
Posts: 7

PostPosted: Thu Apr 29, 2004 5:11 am    Post subject: Re: Fatal error: Call to undefined function: floatval() Reply with quote

i had the same problem (php 4.1.2) , but the function float doesn't work, so i copied this function from www.php.net/floatval
Code: › function floatval($strValue) {
   $floatValue = ereg_replace("(^[0-9]*)(\\.|,)([0-9]*)(.*)", "\\1.\\3", $strValue);
   if (!is_numeric($floatValue)) $floatValue = ereg_replace("(^[0-9]*)(.*)", "\\1", $strValue);
   if (!is_numeric($floatValue)) $floatValue = 0;
   return $floatValue;
  }

put it above the other function and everything works perfect!
Back to top
Offline View user's profile Send private message
gijza

Beginner
Beginner


Joined: Apr 14, 2003
Posts: 7

PostPosted: Thu Apr 29, 2004 5:13 am    Post subject: Re: Fatal error: Call to undefined function: floatval() Reply with quote

btw: both seems to work!
i misread dari's post Embarassed
_________________
Gallery: 1.4.2
Apache: 1.3.23
PHP ver: 4.1.2
PHPNuke: 6.5
Grap. Toolkit: ImageMagick
OS: Redhat
phpinfo [gijza.net]
Back to top
Offline View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    NukedGallery.net Forum Index » PHP-Nuke Issues » Blocks View previous topicPrinter friendly versionView next topic

 
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: Web HostingDedicated ServersDomain NamesDomain Name RegistrationDedicated Web HostingSearch Engine OptimisationSEOWeb Design New YorkSEO Web DesignWeb hosting AustraliaSEO

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