Current time: 18-11-2017, 02:31:13 Hello There, Guest! (LoginRegister)
Advertisement

CF Image Host 1.6.5

Download link Fixed 1.6.5 is out and can be found here-> http://forum.codefuture.co.uk/showthread.php?tid=73141

CF Image Host Pro 0.4.5

Download CF Image Host Pro 0.4.5 can be found here-> http://forum.codefuture.co.uk/showthread.php?tid=73481

display total bandwidth used on homepage
Author Message
Post: #1
display total bandwidth used on homepage
How would I add the total bandwidth used on the homepage?
Quote
Advertisement
Post: #2
RE: display total bandwidth used on homepage
I got it to work by pasting all of this in the first php tag on the footer.php page, like this
PHP Code:
<?php    if(!defined('cfih') or !cfih) exit("Direct access not permitted.");
/**************************************************************************************************************
 *
 *   CF Image Hosting Script
 *   ---------------------------------
 *
 *   Author:    codefuture.co.uk
 *   Version:   1.6
 *
 *   You can download the latest version from: http://codefuture.co.uk/projects/imagehost/
 *
 *   Copyright (c) 2010-2012 CodeFuture.co.uk
 *   This file is part of the CF Image Hosting Script.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 *   COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 *   OR  IN  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *
 *   You may not modify and/or remove any copyright notices or labels on the software on each
 *   page (unless full license is purchase) and in the header of each script source file.
 *
 *   You should have received a full copy of the LICENSE AGREEMENT along with
 *   Codefuture Image Hosting Script. If not, see http://codefuture.co.uk/projects/imagehost/license/.
 *
 *
 *   ABOUT THIS PAGE -----
 *   Used For:     Web site Footer
 *   Last edited:  30/05/2012
 *
 *************************************************************************************************************/
    //var for totals
        
$total_bw 0//bandwidth
        
$lr_total_bw 0;
        
$total_is 0//image size
        
$mostBwImage = array('id' => null,'alt' => '''bandwidth' => 0,'hotlink' =>0'ext' => '','lr_bandwidth' => 0,'lr_hotlink' =>0,);
        
$mostViewImage $mostBwImage;
        
$lr_mostBwImage $mostBwImage;
        
$lr_mostViewImage $mostBwImage;
 
       
// workout the last reset date for home page and image list
        
if ($settings['SET_BANDWIDTH_RESET'] == 'm'){
                 
$resetdate strtotime('01 '.date('M Y'));
                 
$n_resetdate mktime(0,0,0,date('m')+1,1,date('Y'));
        }else{
                 
$resetdate strtotime('last monday'strtotime('tomorrow'));
                 
$n_resetdate strtotime("next Monday");
        }
 
 
// Check for images in database
        
if(imageList(0,1)){
 
        
// get image index
                
$db_img imageList(0,'all');
        
// Add bandwidth & counter to image index
                
foreach ($db_img as $k => $v){
                
// get image bandwidth & counter index
                        
if(!$hc db_imageCounterList(null,$v['id'])){
                                
$hc = array('image'=>0,'thumb_mid'=>0,'thumb'=>0,'bandwidth'=>0,
                                                                        
'lr_image'=>0,'lr_thumb_mid'=>0,'lr_thumb'=>0,'lr_bandwidth'=>0);
                        }
                
// add bandwidth & counter index to image index
                        
$db_img[$k]['lr_bandwidth']= $hc['lr_bandwidth'];
                        
$db_img[$k]['bandwidth']        = $hc['bandwidth'];
                        
$db_img[$k]['lr_hotlink']       = 0+$hc['lr_image']+$hc['lr_thumb_mid']+$hc['lr_thumb'];
                        
$db_img[$k]['hotlink']          = 0+$hc['image']+$hc['thumb_mid']+$hc['thumb'];
 
                
// Totals
                        
$total_bw += $db_img[$k]['bandwidth'];
                        
$lr_total_bw += $db_img[$k]['lr_bandwidth'];
                        
$total_is += $v['size'] + $v['thumbsize'] + $v['sthumbsize'];
 
                
// Top images
                        
if(!isset($mostBwImage) || $mostBwImage['bandwidth'] < $db_img[$k]['bandwidth']){
                                
$mostBwImage $db_img[$k];
                        }
                        if(!isset(
$mostViewImage) || $mostViewImage['hotlink'] < $db_img[$k]['hotlink']){
                                
$mostViewImage $db_img[$k];
                        }
                        if(!isset(
$lr_mostBwImage) || $lr_mostBwImage['lr_bandwidth'] < $db_img[$k]['lr_bandwidth']){
                                
$lr_mostBwImage $db_img[$k];
                        }
                        if(!isset(
$lr_mostViewImage) || $lr_mostViewImage['lr_hotlink'] < $db_img[$k]['lr_hotlink']){
                                
$lr_mostViewImage $db_img[$k];
                        }
 
                }
        
// empty memory
                
unset($hc);
                unset(
$db_img);
        }
?>

and I added this
PHP Code:
<div class="sp"></div>
        <
p><?php
$db 
loadDBGlobal();
$images $db->db_count();
echo 
'We are currently hosting '.$images.($images>1?' images':' image');
?> and have used <?php echo format_size($total_bw);?> of bandwidth.</p>
    </div> 
Where I wanted it to go. Only the <?php echo format_size($total_bw);?> is needed, but I like the total images hosted to.

If you have a more efficient way to do this, I would appreciate it!
Quote
Post: #3
RE: display total bandwidth used on homepage
for the pro version

PHP Code:
<!-- footerstats -->
    <?
php
        
//var for totals
            
$mostBwImage    db_topImg($resetdate,'bandwidth');
             
$mostViewImage    db_topImg($resetdate,'hotlink');
            
$ADM_VARS        db_getTotals();
          
?>
      <?=$lang["admin_home_total_images"];?>: 1<span class="number"><?=$ADM_VARS['totalImages'];/*db_totalimages();*/?></span>
      <?=$lang["admin_home_filespace_used"];?>: 4<span class="number"><?=format_size($ADM_VARS['totalspace']/*db_spaceused()*/);?></span>
      <?=$lang["admin_home_total_bandwidth"];?>: 12<span class="number"><?=format_size(db_totalBanwidth(($settings['SET_BANDWIDTH_RESET'] == 'm'?'start of month':'last Monday')));?></span>
<!-- /footerstats --> 
sorry for my bad English.

I used the google translator Confused
Quote
Post: #4
RE: display total bandwidth used on homepage
Your code for the pro version no longer works I'm afraid, but I've gotten it working fine for me Smile

On the footer.php page I have
PHP Code:
<p><?php

$images 
apc_fetch('jf-totalimages'); // comes from generate-cache.php

echo 'We are currently hosting '.$images.($images>1?' images':' image');

?> and have used <?php echo format_size(apc_fetch('jf-totalbandwidth')); ?> of bandwidth.</p> 

This references another file you must make called generate-cache.php
In this file, you'll have this. NOTE: You must change the key to your own key of choice to avoid possible abuse.
PHP Code:
<?php

if (empty($_GET['key']) || $_GET['key'] != 'secret-key-123') {
        exit(
"Invalid token");
}

error_reporting(-1);
ini_set('display_errors''On');

define('cfih''generate-cache');
include_once(
'./inc/cfih.php');

///var for totals
        
$mostBwImage    db_top_image('bandwidth');
        
$mostViewImage          db_top_image('hotlink');
        
$db_totals      db_get_totals();

// Store the total number of images

if (!apc_store('jf-totalimages'$db_totals->totalImages)) {
        echo 
"Error storing images";
}

// Store the bandwidth used

if (!apc_store('jf-totalbandwidth'$db_totals->bandwidth)) {
        echo 
"Error storing bandwidth";


To make the cache, you must call this php script. I set up a cron job to do it for me.
Code:
*/30 * * * * wget -O /dev/null -o /dev/null http://localhost/generate-cache.php?key=secret-key-123
This will call the file up every 30 minutes to update the cache.
This decreases load time dramatically! Enjoy!

It will similar to as "We are currently hosting 28735 images and have used 3.86 GB of bandwidth."
(This post was last modified: 14-02-2015, 10:13:42 by utopiated420x.)
Quote
Post: #5
RE: display total bandwidth used on homepage
(14-02-2015, 10:12:57)utopiated420x Wrote: Your code for the pro version no longer works I'm afraid, but I've gotten it working fine for me Smile

On the footer.php page I have
PHP Code:
<p><?php

$images 
apc_fetch('jf-totalimages'); // comes from generate-cache.php

echo 'We are currently hosting '.$images.($images>1?' images':' image');

?> and have used <?php echo format_size(apc_fetch('jf-totalbandwidth')); ?> of bandwidth.</p> 

This references another file you must make called generate-cache.php
In this file, you'll have this. NOTE: You must change the key to your own key of choice to avoid possible abuse.
PHP Code:
<?php

if (empty($_GET['key']) || $_GET['key'] != 'secret-key-123') {
        exit(
"Invalid token");
}

error_reporting(-1);
ini_set('display_errors''On');

define('cfih''generate-cache');
include_once(
'./inc/cfih.php');

///var for totals
        
$mostBwImage    db_top_image('bandwidth');
        
$mostViewImage          db_top_image('hotlink');
        
$db_totals      db_get_totals();

// Store the total number of images

if (!apc_store('jf-totalimages'$db_totals->totalImages)) {
        echo 
"Error storing images";
}

// Store the bandwidth used

if (!apc_store('jf-totalbandwidth'$db_totals->bandwidth)) {
        echo 
"Error storing bandwidth";


To make the cache, you must call this php script. I set up a cron job to do it for me.
Code:
*/30 * * * * wget -O /dev/null -o /dev/null http://localhost/generate-cache.php?key=secret-key-123
This will call the file up every 30 minutes to update the cache.
This decreases load time dramatically! Enjoy!

It will similar to as "We are currently hosting 28735 images and have used 3.86 GB of bandwidth."
Fatal error: Call to undefined function apc_store() in /data/web/virtuals/116346/virtual/www/domains/postimg.cz/generate-cache.php on line 20
Quote
Post: #6
RE: display total bandwidth used on homepage
apc is outdated and this needs to be replaced.
Quote


Forum Jump: