Welcome to Geeklog Friday, October 20 2017 @ 03:09 am EDT


Status: offline

smOke

Forum User
Newbie
Registered: 14/02/2003
Posts: 6
Ok its a simple old gallery page tha uses GD2+ Library to Generate images thumbs from a Jpg Images Directory on your host... here is the code needs many changes but is simple to do...
PHP Formatted Code

<?php

// +---------------------------------------------------------------------------+
// | Gallery Import 1.13 for Geeklog - The Ultimate Weblog                     |
// +---------------------------------------------------------------------------+
// | gallery.php                                                               |
// |                                                                           |
// | This file is a galley utility for Geeklog.  Drop it into your path_html   |
// | directory -- edit the configs -- make sure your                           |
// | webserver has write access to that directory and upload.                  |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2003 by the following authors:                              |
// |                                                                           |
// | Authors: John Simeonidis    - admin@mazanet.gr                            |
// +---------------------------------------------------------------------------+
// |                                                                           |
// | This program a 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.           |
// |                                                                           |
// +---------------------------------------------------------------------------+
//

//
// you will need to edit the path to lib-common.php if you put this file anywhere other than
// the toolbox directory in a standard install
//
require_once('../lib-common.php');

// Default path to this file
// $path = $_CONF['path_html']; // use this to place it in root directory
$path = $_CONF['path_html'] . '/gallery';   // default location of gallery.php.

// Only let Registed users access this page
if (!SEC_inGroup('Logged-in Users')) {
    // Someone is trying to illegally access this page
    COM_errorLog("Someone has tried to illegally access the Gallery page.  User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: $REMOTE_ADDR",1);
    $display = COM_siteHeader();
    $display .= COM_startBlock("Access Denied!!!");
    $display .= "You are illegally trying to access the Gallery page.  You Must Register first it's FREE!";
    $display .= COM_endBlock();
    $display .= COM_siteFooter(true);
    echo $display;
    exit;
}
/*
* Main configs
*/

$parent = "gallery.php"; // name of this file
$per_row = 3; // pictures per row to be displayed
$quality = 100; // 100 best quality, 0 worst
$max_size = 150; // thumbnail maximum size in pixels
$pikkies = 15; // pictures to be shown per page

// what file type do we proces? supported: jpg, png, gif
$ft = "jpg";
// picture dir; contains source files
$pdir = "vimages";
// thumbs dir; destination dir assumed to be within the picture dir
$tdir = "mini";
// display properties; 0 is off, 1 is on
$show_time = 1; // show file time&date
$show_props = 1; // show file size and resolution
// rename the files?
$rename = "no";
$file_prefix = "maza_"; // add prefix to renamed files
$version = "1.07";
$new_gd = 1; // 1 for GD 2.0+, 0 for all lower GD libraries

/*
* Main Functions
*/

echo COM_siteHeader();
echo COM_startBlock("Gallery v1.13");
// check server support---------------------------------------------
$err1 = '<center><font face=arial size=2><font color=red>';
$err2 = ' </font> Filetype not supported by server. Aborting script.<br><br><a href="http://www.mazanet.gr">Created by J.Simeonidis '.$version.'</a></font></center></body></html>';

if ( $ft == "jpg" && !(ImageTypes() & IMG_JPG) ) {
        echo $err1.'JPEG'.$err2;
        exit;
}
elseif ( $ft == "gif" && !(ImageTypes() & IMG_GIF) ) {
        echo $err1.'GIF'.$err2;
        exit;
}
elseif ( $ft == "png" && !(ImageTypes() & IMG_PNG) ) {
        echo $err1.'PNG'.$err2;
        exit;
}
// ---------------------------------------------------------------------
echo "<table border=1 align=center bordercolor=gray>n";
$data = $pdir."/nailer.txt";
// get current dir listing -----------------------
$reader = dir($pdir);
while ($test = $reader->read()){
        $extensie = substr($test, -5,5);
        if (!preg_match("/.$ft/", $extensie)) {
                continue;
        }
        $names[] = $test;
} // end while
$reader->close();
$ai = count($names);
//-----------------------------------------------
if ($ai == 0) {
        echo "<tr><td align=center> No <font color=red><b>$ft</b></font> files found in: <br>/$pdir</td></tr>".$footer;
        exit;
}

natcasesort($names);
reset($names);

if (!file_exists($data)) {
        $fp = fopen($data,"a");

        if ($rename == "yes") {
                for ($h = 0; $h < count($names) ; $h++) {
                        $new_name = $file_prefix.$h.".".$ft;
                        rename($pdir."/".$names[$h], $pdir."/".$new_name);
                        $fp = fwrite($fp, $new_name."n");
                }
        }
        else {
                for ($h = 0; $h < count($names) ; $h++) {
                        $fp = fwrite($fp, $names[$h]."n");
                }
        }

} // end if

else {
        $fp = fopen($data,"r");

        while ($content = fscanf ($fp, "%sn")) {
                if (strlen(trim($content[0])) < 5) {
                        continue;
                }
                $files[] = trim($content[0]);
        } // end while
        natcasesort($files);
        reset($files);
        fclose($fp);

        $nr_names = count($names);
        $nr_files = count($files);

        if ( $nr_names > $nr_files) { //assuming only files will be added

        $diff =array_diff($names, $files); // returns the difference
        $keys = array_keys($diff); // returns the keys in the new array as array
        $yep = 0; //because we have to start somewhere... :-)

                if ($rename == "yes") {
                        for ($j = $nr_files; $j < ($nr_files + count($diff)) ; $j++) {
                                $new_name = $file_prefix.$j.".".$ft;

                                $pointer = $keys[$yep];
                                $yep++;

                                if (!in_array($names[$pointer], $files)) {
                                        if (file_exists($pdir."/".$new_name)) {
                                                echo $new_name." Something went wrong here! Please mail willem@vddh.com if you're unsure what went wrong!";
                                                break;
                                        }
                                        rename($pdir."/".$names[$pointer], $pdir."/".$new_name);
                                        $fp = fopen($data,"a");
                                        $fp = fwrite($fp, $new_name."n");
                                }
                        } // end for

                }
                else {
                        for ($j = 0; $j < count($names) ; $j++) {
                                if (!in_array($names[$j], $files)) {
                                        $fp = fopen($data,"a");
                                        $fp = fwrite($fp, $names[$j]."n");
                                }
                        } // end for
                }

        }

} // end else
//-----------------------------------------------

// get new file listing -----------
unset($names);
$fi = fopen($data,"r");
while ($cont = fscanf ($fi, "%sn")) {
        $names[] = $cont[0];
}
fclose($fi);

natcasesort($names);
reset($names);
$rows = ceil($i/$per_row);
$i = count($names);

// determine colspan
if ($show_props != 0 || $show_time != 0) {
        $cols = $per_row*2;
}
else {
        $cols = $per_row;
}

if (!$id) {
        echo "<tr>n <td colspan=".$cols." align=center><b><font color=green>$i</font></b> pictures is now in our database</td>n</tr>n";
}

if (!$id) {

$aantal = 0;

        if (!$page || $page == 1) {
                $pag = 0;
                $page = 1;
        }
        else {
                $pag = ($page - 1) * $pikkies;
        }

        for ($k = $pag; $k < count($names); $k++ ){

                if ($k > ($page*$pikkies - 1)) {
                        break;
                }

                $file = $pdir."/".$names[$k];
                $thumb = $pdir."/".$tdir."/".$names[$k];

                if ($show_time == 1) {
                        $filetime = date( 'H:i:s d/m/y', filemtime($file));
                }
                else {
                        $filetime = '';
                }

                if ($show_props == 1) {
                        $size = getimagesize($file);
                        $kb = round((filesize($file)/1024), 1);
                        $size = '<br><font size="1" color="gray">'.$size[0].'x'.$size[1].'<br>('.$kb.' Kb)</font>';
                }
                else {
                        $size = '';
                        $kb = '';
                }

                if ($show_props != 0 || $show_time != 0) {
                        $cell = '<td align=center width=50>'.$filetime.$size.'</td>';
                }

                if (!file_exists($thumb)) {
                        create_tn($names[$k]);
                }

                if ($teller == 0 || is_int($teller/$per_row) ) {
                        echo "n<tr height=".($max_size + 2).">n";
                }

                echo ' <td align=center width='.($max_size + 2).'><a href="'.$parent.'?id='.base64_encode($names[$k]).'&page='.$page.'"><img src="'.$pdir.'/'.$tdir.'/'.$names[$k].'" border=1 alt="" style="border-color: black"></a></td>'.$cell;
                echo "n";

                $teller++;

                if (is_int($teller/$per_row) ) {
                        echo "</tr>n";
                }
                elseif ($i == $k) {
                        $colspan = ($per_row*$rows - $i)*2;
                        echo "<td colspan=".$colspan."> </td></tr>!!n";
                }

        }

        // navigational area -------------------------------------------------
        $paginas = ceil(count($names)/$pikkies);

        if (!$page || $page == 1) {
                echo "n<tr>n <td colspan=".$cols." align=center><font color=gray size=3><b><<</b></font>  ";
        }
        else {
                echo "n<tr>n <td colspan=".$cols." align=center><font size=3><a href="".$parent."?page=".($page - 1)."" title="Previous Page"><b><<</b></a>  </font>";
        }

        for ($g = 0;$g < $paginas;$g++) {
                $count = $g +1;
                if ($page == $count) {
                        echo '<a href="'.$parent.'?page='.$count.'"><font color=green size=3><b>'.$count.'</b></font></a> ';
                }
                else {
                        echo '<a href="'.$parent.'?page='.$count.'">'.$count.'</a> ';
                }
        }

        if ($page > ($paginas - 1)) {
                echo " <font color=gray size=3><b>>></b></font></td>n</tr>n";
        }
        else {
                echo " <a href="".$parent."?page=".($page + 1)."" title="Next Page"><font size=3><b>>></b></a></font></td>n</tr>n";
        }
        //----------------------------------------------------------------------

} // end if

else{
        $id = base64_decode($id);
        if ($show_time == 1) {
                $filetime = "<br>".(date( 'H:i:s d/m/y', filemtime($pdir."/".$id)));
        }
        else {
                $filetime = '';
        }
        echo '<tr><td align=center><a href="'.$parent.'?page='.$page.'" style="text-decoration: none"><font size=3><b><< Back</b> <br><img src="'.$pdir.'/'.$id.'" border=1 alt="Back 2 Overview" style="border-color: black"></a>'.$filetime.'</font></td></tr>';
} // end else


function create_tn($plaat) {
global $pdir, $tdir, $quality, $max_size, $ft, $new_gd;

        $image = $pdir."/".$plaat;
        $size = GetImageSize ($image);
        $ratio = $size[0]/$size[1];
        if ($ratio > 1) {
                $width = $max_size;
                $height = ($max_size/$size[0]) * $size[1];
        }
        else {
                $width = ($max_size/$size[1]) * $size[0];
                $height = $max_size;
        }
        if ($new_gd == 1) {
                $thumb = ImageCreateTrueColor($width, $height);
        }
        else {
                $thumb = ImageCreate($width, $height);
        }
        if ($ft == "jpg") { $source = ImageCreateFromJPEG($image); }
        if ($ft == "gif") { $source = ImageCreateFromGIF($image); }
        if ($ft == "png") { $source = ImageCreateFromPNG($image); }
        if ($new_gd == 1) {
                ImageCopyResampled($thumb, $source, 0, 0, 0, 0, $width, $height, ImageSX($source), ImageSY($source));
        }
        else {
                ImageCopyResized($thumb, $source, 0, 0, 0, 0, $width, $height, ImageSX($source), ImageSY($source));
        }
        if ($ft == "jpg") { ImageJPEG($thumb, "$pdir/$tdir/$plaat", $quality); }
        if ($ft == "gif") { ImageGIF($thumb, "$pdir/$tdir/$plaat", $quality); }
        if ($ft == "png") { ImagePNG($thumb, "$pdir/$tdir/$plaat", $quality); }
        ImageDestroy($thumb);
}
$footer = "</table>";
echo $footer;

/*
* Upload Functions
*/

$updir = "/raid/http/smoke/public_html/gallery/vimages"; //absolute path to where files are uploaded, no trailing slash
$sizelim = "yes"; //do you want size limitations yes or no
$size = "400000"; //if you want size limited how many bytes
$certtype = "yes"; //do you want certain type of file, no recommended
$type = "image/pjpeg"; //what type of file would you like
$msg = "";

if ($import == 'Upload File') {
$buffer='';
$str = strtolower($_FILES['userfile']['name']);
//error if no file is selected
if ($_FILES['userfile']['name'] == "") {
$msg = "<b>ERROR:</b> No file selected to upload";
}
else if ($pass != "incert pass here!") {
$msg = "<b>ERROR:</b> The password is wrong you can NOT Upload here!";
}
//error if file exists
else if (file_exists("$updir/$str")) {
$msg = "<b>ERROR:</b> The file already exists, rename and upload...";
}
//error if file is to big
else if ($_FILES['userfile']['size'] > $size) {
$msg = "<b>ERROR:</b> The file you are trying to upload is too big.";
}
//error if file isn't certain type
else if ($type != $_FILES['userfile']['type']) {
$msg = "<b>ERROR:</b> The file you are trying to upload is wrong type";
}
else if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $updir."/".$str)) {
$msg = "<b>ERROR:</b> Error: Could not Copy file";
} else {
$msg = "Upload Successful for File -- " . $str;
         }      }
$display ="<br><br>";
$display .="<center>";
$display .="<p>$msg</p>";
$display .="<form method="post" action="http://www.mazanet.gr/gallery/gallery.php" enctype="multipart/form-data">";
$display .="<p>File to upload:<br>";
$display .="<input type=file name=userfile size=30><br>";
$display .="<input type=text name=pass value="give the password!"><br>";
$display .="<button name=import type=submit>Upload File</button><br>";
$display .="<small>the upload accepts only .jpg(JPEG} files!</small>";
$display .="</form>";
$display .="php code & import for gl by <a href="http://www.mazanet.gr/users.php?mode=profile&uid=2">smOke</a></center>";
echo $display;
echo COM_endBlock();
echo COM_siteFooter(false);
?>
</code>
<br>Ok that was the code of the "gallery.php" tha you may place on your "root/gallery/"
<br><br>
ok this is the time for the phpblock code:<br>
<code>
function phpblock_potm()
{
  $randompic = "";
  $file = file("/raid/http/smoke/public_html/gallery/vimages/nailer.txt");
  while ($randompic == "")
  {
    $ind = rand(0,count($file));
    $randompic = ereg_replace("n","",$file[$ind]);
  }
$retval  = "<center><a href="http://www.mazanet.gr/gallery/gallery.php"><img src="http://www.mazanet.gr/gallery/vimages/mini/$randompic"></a><br>";
$retval .= "view our <a href="http://www.mazanet.gr/gallery/gallery.php">gallery</a> for full images listing & fullsize pictures ;)";
return $retval;
}
 
and now you may edit your "lib-custom.php" file to include the above function and make the php_block!

Note: You need to edit all paths and url's for the script to works on your site ...
Note2: I Use this simple script on my site http://www.mazanet.gr you can visit to see for your self how it works...

take the script and modify it if you like to make it better ...
ThanX,
The MAZA Team
www.mazanet.gr
email: admin@mazanet.gr

Status: offline

Dirk

Site Admin
Admin
Registered: 12/01/2002
Posts: 13073
Location:Stuttgart, Germany
It would probably make more sense to make this script available for download somewhere (e.g. here on geeklog.net) instead of posting in it a story ... bye, Dirk

Status: offline

smOke

Forum User
Newbie
Registered: 14/02/2003
Posts: 6
Ok dirk you are right!!! I made this post in a hurry sorry Smile i Will make more detailed post soon ... but it really works also the php_block is a simple picture of the moment! (images taked from the gallery... stay tuned for a better post Smile

All times are EDT. The time is now 03:09 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content