# HG changeset patch # User Guillermo Bonvehi # Date 1331914908 10800 # Node ID 155999d879aac1e32299b9d0d6abe9542fa21786 # Parent 9aaaff136ecb2ed9b1f98d3b144fb4714c41fd78 Made it work without warnings diff -r 9aaaff136ecb -r 155999d879aa system_gallery.php --- a/system_gallery.php Fri Mar 16 12:57:42 2012 -0300 +++ b/system_gallery.php Fri Mar 16 13:21:48 2012 -0300 @@ -71,7 +71,6 @@ $content.= "in-page-blade(gallery-".$_POST['gal'].")"; } $galleries = getGallery(); - echo $aaa[1]; $extraInfo.= '¦ '.galList( 'gal',$galleries); $extraInfo.= ' ¦'; } @@ -107,14 +106,14 @@ -$fh=fopen($text, "r"); - -while(!feof($fh)) -{ - $temp = explode(",", $line); - $description[$temp[0]] = $temp[1]; - $line=fgets($fh); - unset($temp); +$fh=@fopen($text, "r"); +if ($fh) { + while(($line=fgets($fh)) !== false) { + $temp = explode(",", $line); + $description[$temp[0]] = $temp[1]; + unset($temp); + } + fclose($fh); } if ($handle = opendir($images)) { @@ -148,7 +147,7 @@ function subMenuGallery(&$menuOutput) { if($_SESSION['adminLogIn']) { - if ($_GET['action'] == 'Gallery') { + if (isset($_GET['action']) && $_GET['action'] == 'Gallery') { $menuOutput.= '
  • Gallery
  • '; } else { $menuOutput.= '
  • Gallery
  • '; @@ -253,7 +252,7 @@ function outputSettings(){ if($_SESSION['adminLogIn']) { - $gallerySettings = gallery_readSettings(admin); + $gallerySettings = gallery_readSettings('admin'); echo ""; echo "

    Layout Settings

    "; @@ -350,34 +349,32 @@ include('../blade_packs/system_gallery/gallery_func.php'); - $command = $_GET['cmd']; - $file = $_GET['id']; - if (isset($_GET['cmd'])) { - if ($_GET['cmd']== "create"){ - unset ($_GET['cmd']); + $getcmd = $_GET['cmd']; + if ($getcmd == "create"){ + $getcmd = ''; thumber($_GET['id']); } - if ($_GET['cmd'] == "recreate") { - unset ($_GET['cmd']); + if ($getcmd == "recreate") { + $getcmd = ''; reThumber($_GET['id']); } - if ($_GET['cmd'] == "edit") { - unset ($_GET['cmd']); + if ($getcmd == "edit") { + $getcmd = ''; edit_gallery($_GET['id']); } - if ($_GET['cmd'] == "save") { - unset ($_GET['cmd']); + if ($getcmd == "save") { + $getcmd = ''; $ret = save_gallery($_GET['id']); if ($ret) { MsgBox( lt('Descriptions for '.$_GET['id'].' succesfully saved!') ); } } - if ($_GET['cmd'] == "saveSettings") { - unset ($_GET['cmd']); + if ($getcmd == "saveSettings") { + $getcmd = ''; $ret = gallery_saveSettings(); if ($ret == "true") { @@ -389,11 +386,13 @@ } } - if ($_GET['cmd'] == "delete") + if ($getcmd == "delete") { - unset ($_GET['cmd']); + $getcmd = ''; galleryDelete($_GET['id']); } + if (empty($getcmd)) + unset ($_GET['cmd']); } echo '

    Add Gallery

    '; diff -r 9aaaff136ecb -r 155999d879aa system_gallery/gallery_func.php --- a/system_gallery/gallery_func.php Fri Mar 16 12:57:42 2012 -0300 +++ b/system_gallery/gallery_func.php Fri Mar 16 13:21:48 2012 -0300 @@ -21,10 +21,10 @@ // loop through it, looking for any/all JPG files: while (false !== ($fname = readdir( $dir ))) { - // parse path for the extension - $info = pathinfo($pathToImages . $fname); + $ext = explode('.',$fname); + $extc = count($ext); // continue only if this is a JPEG image - if ( strtolower($info['extension']) == 'jpg' or strtolower($info['extension']) == 'jpeg') + if ( $extc > 1 && (!empty($ext[$extc-1]) && strtolower($ext[$extc-1]) == 'jpg' || strtolower($ext[$extc-1]) == 'jpeg')) { echo "Creating thumb for: {$fname}
    "; @@ -97,10 +97,10 @@ // loop through it, looking for any/all JPG files: while (false !== ($fname = readdir( $dir ))) { - // parse path for the extension - $info = pathinfo($pathToImages . $fname); + $ext = explode('.',$fname); + $extc = count($ext); // continue only if this is a JPEG image - if ( strtolower($info['extension']) == 'jpg' or strtolower($info['extension']) == 'jpeg') + if ( $extc > 1 && (!empty($ext[$extc-1]) && strtolower($ext[$extc-1]) == 'jpg' || strtolower($ext[$extc-1]) == 'jpeg')) { echo "Creating thumb for: {$fname}
    "; @@ -132,18 +132,15 @@ #-------------------------------------------------------------------------------------------------------------- function redescr( $pathToImages, $pathToredescr) { - - - // open the directory $dir = opendir( $pathToImages ); // loop through it, looking for any/all JPG files: while (false !== ($fname = readdir( $dir ))) { - // parse path for the extension - $info = pathinfo($pathToImages . $fname); + $ext = explode('.',$fname); + $extc = count($ext); // continue only if this is a JPEG image - if ( strtolower($info['extension']) == 'jpg' or strtolower($info['extension']) == 'jpeg') + if ( $extc > 1 && (!empty($ext[$extc-1]) && strtolower($ext[$extc-1]) == 'jpg' || strtolower($ext[$extc-1]) == 'jpeg')) { echo "Adding {$fname} to List.
    "; if( file_exists($pathToredescr)) @@ -174,8 +171,8 @@ $galleryFile = "../datastore/system_gallery/".$_GET['id'] . "/images/normal/exists.gal"; $redescrFile = "../datastore/system_gallery/".$_GET['id'] . "/descr.txt"; - unlink ($redescrFile); - unlink ($galleryFile); + @unlink ($redescrFile); + @unlink ($galleryFile); while ($file = readdir ($handle)) { @@ -215,16 +212,17 @@ //$text = "a.txt"; # Location of small versions - $fh = fopen($text,"r"); - - - while(!feof($fh)) - { - $temp = explode(",", $line); - $description[$temp[0]] = $temp[1]; - $line=fgets($fh); - unset($temp); - } + $description = array(); + $fh = @fopen($text,"r"); + if ($fh) { + while(($line=fgets($fh)) !== false) { + $temp = explode(",", $line); + if (count($temp) > 1) + $description[$temp[0]] = $temp[1]; + unset($temp); + } + fclose($fh); + } if ($handle = opendir($images)) { @@ -248,10 +246,11 @@ { foreach($files as $file) { - $allfiles .= $file . ',
    '; + $p = ''; + if (isset($description[$file])) $p=strip_tags($description[$file]); echo ""; - echo ''; + echo ''; echo ''; echo ""; @@ -270,19 +269,24 @@ } #-------Function for saving the description of a gallery---------- function save_gallery($fgenre){ + // Do not act if no POST is sent + if (!isset($_POST['Descr'])) return 'true'; + $images = "../datastore/system_gallery/".$fgenre."/images/"; $big = "normal/"; $text = "../datastore/system_gallery/".$fgenre."/descr.txt"; $colCtr = 0; - $fh=fopen($text, "r"); + $fh=@fopen($text, "r"); - while(!feof($fh)) - { - $temp = explode(",", $line); - $description[$temp[0]] = $temp[1]; - $line=fgets($fh); - unset($temp); - } + if ($fh) { + while(($line=fgets($fh)) !== false) { + $temp = explode(",", $line); + if (count($temp)>1) + $description[$temp[0]] = $temp[1]; + unset($temp); + } + fclose($fh); + } if ($handle = opendir($images)) { @@ -293,7 +297,7 @@ } closedir($handle); } - unlink($text); + @unlink($text); $i = 0; foreach($files as $file) { @@ -307,10 +311,7 @@ fclose($saveFile); $i = $i + 1; } - - return "true"; - - + return "true"; } // read in settings data // @@ -335,15 +336,14 @@ } else { - $fhandle=fopen($gallerySettings, "r"); - while(!feof($fhandle)) - { - $temp = explode(",", $line); - $settings[$temp[0]] = $temp[1]; - $line=fgets($fhandle); - unset($temp); + $fhandle=@fopen($gallerySettings, "r"); + if ($fhandle) { + while(($line=fgets($fhandle)) !== false) { + $temp = explode(",", $line); + $settings[$temp[0]] = $temp[1]; + unset($temp); + } } - fclose($fhandle); return $settings; } } @@ -404,14 +404,14 @@ function galleryDelete($gallery) { // first delete /gallery/images/normal - $mydir = '../datastore/system_gallery/'.$gallery.'/images/normal/'; + $mydir = '../datastore/system_gallery/'.$gallery.'/images/normal'; emptyDir($mydir); // seond delete /gallery/images/ - $mydir = '../datastore/system_gallery/'.$gallery.'/images/'; + $mydir = '../datastore/system_gallery/'.$gallery.'/images'; emptyDir($mydir); // third delete /gallery/ - $mydir = '../datastore/system_gallery/'.$gallery.'/'; + $mydir = '../datastore/system_gallery/'.$gallery; emptyDir($mydir); //remove dir @@ -427,48 +427,25 @@ $debugStr .= "Deleting Contents Of: $path

    "; // PARSE THE FOLDER - if ($handle = opendir($path)) { - + if ($handle = opendir($path.DIRECTORY_SEPARATOR)) { while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != "..") { - // IF IT"S A FILE THEN DELETE IT - if(is_file($path."/".$file)) { - - if(unlink($path."/".$file)) { - $debugStr .= "Deleted File: ".$file."
    "; + if(is_file($path.DIRECTORY_SEPARATOR.$file)) { + if(unlink($path.DIRECTORY_SEPARATOR.$file)) { + $debugStr .= "Deleted File: ".$file."
    "; } - } else { - // IT IS A DIRECTORY // CRAWL THROUGH THE DIRECTORY AND DELETE IT'S CONTENTS - - if($handle2 = opendir($path."/".$file)) { - - while (false !== ($file2 = readdir($handle2))) { - - if ($file2 != "." && $file2 != "..") { - if(unlink($path."/".$file."/".$file2)) { - $debugStr .= "Deleted File: $file/$file2
    "; - } - } - - } - + emptyDir($path.DIRECTORY_SEPARATOR.$file); + if(rmdir($path.DIRECTORY_SEPARATOR.$file)) { + $debugStr .= "Directory: ".$file."
    "; } - - if(rmdir($path."/".$file)) { - $debugStr .= "Directory: ".$file."
    "; - } - } - } - } - + closedir($handle); } return $debugStr; }
    ' . strip_tags($description[$file]) . '' . $p . '