Skocz do zawartości

Problem ze skryptem - PHP galeria


r0wl3n

Recommended Posts

Witam, zacząłem przerabiać skrypt galerii w php i przypasowywać go sobie pod swoje wymagania i natrafiłem na problem, a mianowicie. Skrypt miał taka opcje, ze po naciśnięciu w miniaturkę, powiększanie zdjęcia polegało na przeniesieniu do nowej zakładki i tam wyświetleniu dużego zdjęcia. Postanowiłem to zmienić i spróbować wgrać lightbox'a, żeby powiększane zdjęcia pokazywały się w okienku ładnie. Problem jest teraz następujący, ze lightbox tak jakby nie łapie przekierowania i po naciśnięciu na miniaturkę nie pokazuje powiększonego zdjęcia... Ponizej daje kod tej galerii:

<?php
//----------------------------------------------------------------------------//
//------------------------Configuration---------------------------------------//
//----------------------------------------------------------------------------//
$thumbs_prfx        = "_thumbs_"; // thumbnails prefix
$msg                = 5;        // comments per page
$thumb_size         = 160;      // thumbnail size
$pix_size           = 640;      // big picture size
$copyright          = "";// text on the picture leave blank if no text
$picsperpage        = 4;       // how many pictures per page
$picsperrow         = 2;        // how many pictures in row
$converter          = "gd2";     //use "im" or "gd" or "gd2"
                                //if "im"  then sript is using Imgage Magick library for convert
                                //if 'gd1' then using GD Library version 1.x
                                //if "gd2" then using GD Library version 2.x
//----------------------------------------------------------------------------//
//------------------------Language--------------------------------------------//
//----------------------------------------------------------------------------//
$lang['next']           ="Następna strona";
$lang['previous']       ="Poprzednia strona";
$lang["back_to_pixs"]   ="Back to thumbnails";
$lang["title"]          = "Simple Gallery PHP v1.1";
$lang["comments"]       ="comments";
$lang["name"]           ="Name";
$lang["email"]          ="Email";
$lang["message"]        ="Message";
$lang["submit"]         ="Submit";
$lang["reset"]          ="Clear";
$lang["eror_perm"]      ="can't write, chek folder permisions must be: 777";
$lang["eror_nopics"]    ="can't find pictures, upload pictures to directory";
$lang["admin_name"]     ="Administrator answer";
$lang["show"]           ="show";
//----------------------------------------------------------------------------//
//------------------------------Html------------------------------------------//
//----------------------------------------------------------------------------//
$body='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>'.$lang["title"].'-'.$koks_nors.'</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<meta name="Description" content="Simple Gallery">
<meta name="keywords" content="Simle Gallery, Images, Images Gallery, PHP, PHP Scripts and Programs, PHP Images Gallery, Images Gallery, Images Gallery Script, PHP converting images, PHP convert with GD, PHP convert with Image magick, convert with GD, Image magick converting pictures,">
<meta NAME="Author" CONTENT="Vytautas Stanaitis">
<meta name="Copyright" content="2003 © Vytautas Stanaitis">
<meta http-equiv="imagetoolbar" content="no">
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen">
<style TYPE="text/css">

    A:link { font-family:verdana, arial, sans-serif; font-size:7pt; COLOR: #000000; TEXT-DECORATION: none;   }
    A:visited {font-family:verdana, arial, sans-serif; font-size:7pt; color: #000000; TEXT-DECORATION: none; }
    A:active {font-family:verdana, arial, sans-serif; font-size:7pt; COLOR: #089ACB; TEXT-DECORATION: none; }
    A:hover {font-family:verdana, arial, sans-serif; font-size:7pt; COLOR: #969F79; TEXT-DECORATION: none; }
    td
        {
            font-family:Verdana,arial, sans-serif; font-size:7pt;
            border-width:0px;
            border-color: #FFFFFF;
        }

    IMG {
          border-style: solid;
          border-width:0;
          border-color: #000000;
        }
    .table_border
            {
                margin: 10px;
                padding: 5px;
                border: 0px solid #595959;
            }
    .input_border
            {
               color : #000000;
               background-color : #FFFFFF;
               BORDER-STYLE : groove;
               border-left-width: 0px;
               border-right-width: 0px;
               border-top-width: 0px;
               border-bottom-width: 0px;
               BORDER-color :#595959;
               overflow: auto;
            }
    .button
            {
                background-color:#969F79;
                border: 0px;
                border-color:#595959;
                BORDER-STYLE :groove;
                color : #000000;
                FONT-FAMILY: Verdana, Arial, Sans-serif;
                FONT-SIZE:9px;
            }
</style>
</head>
<body>';
//------------------------------------------------------------------------------
$header.='
<table class="table_border" border="0" cellpadding="0" cellspacing="0" >
  <tr>
    <td>
<!-- End header -->
';
//------------------------------------------------------------------------------
$footer.='
<!-- Start footer -->
    </td>
  </tr>
</table>
<table cellspacing="0" cellpadding="0" style="border: 0px #595959 solid; margin: 0px;">
</table>
</body>
</html>';
//----------------------------------------------------------------------------//
//---------------------------Functions----------------------------------------//
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
//              NO USER EDITABLE SECTIONS BELOW THIS LINE                     //
//----------------------------------------------------------------------------//

function test_silly_safe_mode(){
   $file = "dummy.txt";
   @mkdir(dirname($file), 0777);
   $fd = @fopen($file, 'w');
   if (!$fd) {@rmdir(dirname($file));return true;}
   fclose($fd);
   @unlink($file);
   @rmdir(dirname($file));
}//end test_silly_safe_mode

function convert ($pixas){
   global $thumbs_prfx,$thumb_size,$pix_size,$copyright,$converter;
    $pixas = trim($pixas);
    $size = getimagesize($pixas);
    $pavWidth = $size[0];
    $pavHeight = $size[1];
   $didesnis = max($pavWidth, $pavHeight);
    $dalyba = $didesnis / $thumb_size;
    $gdydis = max($dalyba, 1.0);
   $maz_width = (int)($pavWidth / $gdydis);
   $maz_height = (int)($pavHeight / $gdydis);
    if ($didesnis > $pix_size){
        $aaa= $didesnis/$pix_size;
        $dpixo_aukstis = (int)($pavHeight/$aaa);
        $dpixo_ilgis = (int)($pavWidth/$aaa);
    }
    else {$dpixo_ilgis = $pavWidth; $dpixo_aukstis = $pavHeight; }

    if ($converter=="gd1" || $converter=="gd2" || $converter=="gd"){//if gd
        if ($converter=="gd2"){
            $spix = imagecreatetruecolor ($maz_width,$maz_height) or die ("Cannot Initialize new GD image stream");
        }
        else{
           $spix = imagecreate ($maz_width,$maz_height) or die ("Cannot Initialize new GD image stream");//this is for gd 1.*
        }
       $image = ImageCreateFromJpeg($pixas);
       imagecopyresized ($spix, $image, 0, 0, 0, 0, $maz_width, $maz_height, $size[0], $size[1]);
      imagejpeg ($spix,$thumbs_prfx.$pixas,90);
       @imagedestroy($spix);
       @imagedestroy($image);
       if ($converter=="gd2"){
         $bpix = imagecreatetruecolor ($dpixo_ilgis,$dpixo_aukstis) or die ("Cannot Initialize new GD image stream");
       }
       else{
           $bpix = imagecreate ($dpixo_ilgis,$dpixo_aukstis) or die ("Cannot Initialize new GD image stream");//this is for gd 1.*
       }
       $image = ImageCreateFromJpeg($pixas);
       imagecopyresized ($bpix, $image, 0, 0, 0, 0, $dpixo_ilgis, $dpixo_aukstis, $size[0], $size[1]);
       $text_color = imagecolorallocate ($bpix, 255,255,255);//white text
       imagestring ($bpix, 1, 5, 3,  $copyright, $text_color);
       imagejpeg ($bpix,$pixas,90);
       @imagedestroy($bpix);
       @imagedestroy($image);
       ob_end_clean();
       $imginfo = getimagesize($thumbs_prfx.$pixas);
       if ($imginfo == null){return false;}
       else {return true;}
    }// end if gd,gd1,gd2

    else{// if image magick
        exec (" convert -quality 50 -antialias -geometry {$maz_width}x{$maz_height} '$pixas' '$thumbs_prfx"."$pixas'");
        exec (" convert -quality 70 -antialias -geometry {$dpixo_ilgis}x{$dpixo_aukstis} -font Verdana -fill white  -draw 'text 5,10 $copyright' '$pixas' '$pixas'");//
        $imginfo = getimagesize($thumbs_prfx.$pixas);
        if ($imginfo == null){return false;}
        else {return true;}
    }

}//end function convert
function replace($kint){
   $kint = stripslashes($kint);
    $kint = str_replace("<","<",$kint);
    $kint = str_replace(">",">",$kint);
    $kint = str_replace("|","¦",$kint);
    $kint = str_replace("\n","<br>",$kint);
    return $kint;
}

//----------------------------------------------------------------------------//
//---------------------------Script-------------------------------------------//
//----------------------------------------------------------------------------//
//cheks dir permisions if not wirtible exits
if (test_silly_safe_mode()){echo $body.$header.'<center>'.$lang["eror_perm"].'</center>'.$footer;exit;}
if (isset($_GET['con']) && $_GET['con']!==''){ //for converting
    if (convert($_GET['con'])){
        $file_name = $thumbs_prfx.$_GET['con'];
        header('Content-type: image/jpeg');
        echo fread(fopen($file_name, 'rb'), filesize($file_name));
    }
    else {
       header ("Content-type: image/png");
      $im = @imagecreate (25, 25) or die ("Cannot Initialize new GD image stream");
      $background_color = imagecolorallocate ($im, 255, 255, 255);
      $text_color = imagecolorallocate ($im, 233, 14, 91);
      imagestring ($im, 1, 1, 5,  "Found", $text_color);
      imagepng ($im);
      // echo $body.$header."Problems".$footer; exit;
   }
exit;
}//end $_GET['con']

//------------------------------------------------------------------------------
//ERROR_REPORTING(E_ALL);
$opdir=opendir(".");//file list
$i=0;
while ($file = readdir($opdir)){
if (!is_dir($file)) {
    ereg( ".*\.([a-zA-z0-9]{0,5})$", $file, $ext );
    preg_match("/\b".$thumbs_prfx."/", $file,$qq);
    if (!$qq && $file != "." && $file != ".." && ($ext[1]== "jpg" || $ext[1]== "JPG" || $ext[1]== "Jpg" || $ext[1] == "jpeg" || $ext[1] == "png"))
    $filelist[$i++] = $file;
}
}
if (!$filelist) {  $html=$body.$header.$lang["eror_nopics"].$footer; echo $html; exit;}
@sort ($filelist);
closedir($opdir);

//------------------------------------------------------------------------------

if ($_POST['submit']){ // if posting comment
    if (!$_POST['vardas'] || !$_POST['txt'] || !$_POST['pixas']){// if something is missing do nothing
      header("Location: $PHP_SELF?p=".$_POST['pixas']."&pg=".$_POST['page']."");
      exit;
    }
    //else write to file
    else{
        $txt = stripslashes($_POST['txt']);
        if (getenv("HTTP_X_FORWARDED_FOR")){$tavo_ip = getenv("HTTP_X_FORWARDED_FOR");}
        else { $tavo_ip = getenv("REMOTE_ADDR");}
        $ex = substr(strrchr($_POST['pixas'],"."),0);
        $pix_txt = substr($_POST['pixas'], 0, strlen($_POST['pixas']) - strlen(strstr($_POST['pixas'],$ex)));//commens will be stored in txt file named like picture name
        $byla=fopen("".$pix_txt.".txt", "a");
        fputs($byla, "".date("YmdHis",time())."|".replace($_POST['vardas'])."|".replace($_POST['meilas'])."|".replace($txt)."|$tavo_ip|".date("Y-m-d-H:i:s")."||\n");
        fclose($byla);
        header("Location: $PHP_SELF?p=".$_POST['pixas']."&pg=".$_POST['page']."");
    }
}//end $_POST['submit']

//------------------------------------------------------------------------------
// for converting first time
if (isset($_GET['setup'])&& $_GET['setup']=='' ){
   $html=$body.$header.'
<table border="0" cellpadding="0" cellspacing="0" >
  <tr>';
   $pixpsl=0;
   //open all pictures to convert.
   while (list ($key, $pixas) = each ($filelist)){
        if (!file_exists($thumbs_prfx.$pixas)){
           $html.= '<td align="" valign="middle" ><A HREF="'.$PHP_SELF.'?p='.$pixas.'&pg='.$pixpsl.'"><img src="'.$PHP_SELF.'?con='.$pixas.'&r='.uniqid('').'" <img border="0" alt="'.$lang["show"].'"><br /></a>';
       }
        else{
           $html.= '<td align="" valign="middle" ><A HREF="'.$PHP_SELF."?p=".$pixas.'&pg='.$pixpsl.'">';
           $html.=  '<IMG SRC="'.$thumbs_prfx.$pixas.'" border="0" alt="'.$lang["show"].'"></A>';
        }
        $html.='            </td>';
        $counter++;
        $countpixs++;
        if ($countpixs == $picsperpage) {$countpixs = 0; $pixpsl++;}
        if ($counter == $picsperrow) {$counter = 0; $html.='    </tr><tr>';}
   }
   $html.='
  </tr>
</table>
';
   $html.=$footer;
   echo $html;
   exit;
}//end $_GET['setup']

//------------------------------------------------------------------------------
// for big picture viewing
if (isset($_GET['p']) && $_GET['p']!=='' && isset($_GET['pg'])){
   $html=$body.$header;
   foreach ( $filelist as $key => $value ) {if ($value==$p){$sek=$key+1;$atg=$key-1;}  } //navigation
   $html.='
<table  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="middle">
                <a href="'.$PHP_SELF.'?psl='.$_GET['pg'].'"><img src="'.$_GET['p'].'" border="0" alt="'.$_GET['p'].'"></a><br>
                <a href="'.$PHP_SELF.'?psl='.$_GET['pg'].'">'.$lang["back_to_pixs"].'</A><br>
    </td>
  </tr>
</table>';
    $p=trim($_GET['p']);
    $ex = substr(strrchr($p,"."),0);
    $pixas = substr($p, 0, strlen($p) - strlen(strstr($p,$ex)));
    $filename = "".$pixas.".txt";
    if (!file_exists($filename) && file_exists($p)){//cheking if exists comments file
        touch($filename);
        chmod($filename,0666);
    }
    $byla=file($filename);
    $max = count($byla);
   $html.= '
<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" >
  <tr>
    <td>';
    rsort ($byla);
    if(!$_GET['psl']){$_GET['psl']=0;}//navigation}
    $tmp = $psl * $msg + $msg;
    $startas = $psl * $msg;
    $endaz = $psl * $msg + $msg;;
    if ($endaz > $max){$endaz=$max;}
   $html.='   </td>
  </tr>
</table>';
   // show comments
    for ($u=$startas; $u<$endaz; $u++){
        $infa = explode("|",$byla[$u]);
        $infa[3] = wordwrap( $infa[3], 95, "\n", 1);
        $html.='
    </td>
  </tr>';
        $html.='
  <tr>
    <td colspan="2">'.$infa[3].'<br><div align="right">'.$infa[5].'</div>';
if ($infa[6]){
$html.='    <div align="left">'.$lang["admin_name"].' :<br />'.$infa[6].'</div>';
}

    $html.='
    </td>
  </tr>
</table>';
    }//end for
   $html.=$footer;
   echo $html;
   exit;
}//end $_GET['p']  viewing big picture

//------------------------------------------------------------------------------
// show all pictures per page
$max = count ($filelist);
if(!$psl){$psl=0;}
if($psl==0){$navig = $lang["previous"];}
else{$tmp = $psl -1; $navig = '<a href="'.$PHP_SELF.'?psl='.$tmp.'"> '.$lang["previous"].'</a>';}
$tmp = $psl * $picsperpage + $picsperpage;
$navig .= '';
$puslapiu=(int)($max/$picsperpage);
$kp=0;
for ($i=0; $i<=$puslapiu;$i++){
   $kp++;
     $navig .='';
}
$navig .= ' | ';
if ($max > $tmp){$tmp = $psl +1; $navig .= '<a href="'.$PHP_SELF.'?psl='.$tmp.'">'.$lang["next"].' </a>';}
else {$navig .= $lang["next"];}
$startas = $psl * $picsperpage;
$endaz = $psl * $picsperpage + $picsperpage;;
if ($endaz > $max){$endaz=$max;}
$html=$body.$header;
$html.='
<table>
    <tr>';
for ($u=$startas; $u<$endaz;){
    $pixas = $filelist[$u];
    if (!file_exists($thumbs_prfx.$pixas)){
        $html.='<td><A HREF="'.$PHP_SELF.'?p='.$pixas.'&pg='.$psl.'" rel="lightbox"><img src="'.$PHP_SELF.'?con='.$pixas.'&r='.uniqid('').'" border="0" alt="'.$lang["show"].'"><br /></a>';
   }
    else{
       $html.= '<td><A HREF="'.$PHP_SELF."?p=".$pixas.'&pg='.$psl.'" rel="lightbox">';
        $html.=  '<IMG SRC="'.$thumbs_prfx.$pixas.'" border="0" alt="'.$lang["show"].'"></A>';
    }
    $ex = substr(strrchr($pixas,"."),0);
    $tvard = substr($pixas, 0, strlen($pixas) - strlen(strstr($pixas,$ex)));
    if (file_exists("".$tvard.".txt")){
        $byla=file("".$tvard.".txt");
        $max = count($byla);
        if($max==0)  $html.='';
        else $html.='<br>'.$lang["comments"].': '.$max.'';
    }
    $html.='</td>';
    $counter++;
   $u++;
   if ($u == $endaz) {$counter = 0;
   $html.= '
    </tr>';}
       if ($counter == $picsperrow) {$counter = 0; $html.= '
    </tr>
    <tr>';}
}//end for
$html.='
    <tr>
        <td  height="10" style="border-top: 0px #595959 solid;" colspan="5" align="center" valign="bottom">'.$navig.'</td>
    </tr>
</table>';
$html.= $footer;
echo $html;
?>

Jak to wszystko sie zachowuje mozna zobaczyc na:

http://zstudio.ggear.pl/galeria44/index.php?psl=0

Co jest źle? i gdzie co trzeba poprawić?

Link do komentarza
Udostępnij na innych stronach

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gość
Odpowiedz...

×   Wkleiłeś treść z formatowaniem.   Usuń formatowanie

  Only 75 emoji are allowed.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Wczytywanie...
×
×
  • Utwórz nowe...