singapore: the smallest big galery
home » forum » Mods » Moving images via admin

You are not logged in.

#16 2007-08-21 14:34:38

jdvb
Member

Re: Moving images via admin

Hi,

I was just trying something on this function...
I got it all completed except for saving the old image data to the new location...

have not dug into how that works yet...

Code:

function moveMultipleImages()
  {
    $galleryId = isset($_REQUEST["gallery"]) ? $_REQUEST["gallery"] : ".";
    $totalImagesMoved = 0;
    foreach($_REQUEST["sgImages"] as $imageId) {
      $source = $this->config->base_path.$this->config->pathto_galleries.$galleryId.'/'.$imageId;
      $target = $this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/'.basename($imageId);
      if(file_exists($target)) {
        $this->pushError($this->translator->_g("Unable to copy/move image '%s' because the target image already exists.", $imageId));
      } elseif($this->isSubPath($source, $target, false)) {
        $this->pushError($this->translator->_g("Unable to copy/move gallery '%s' because the target is a child of the source.", $imageId));
      //} elseif(!is_writable($target)) {
      //  $this->pushError($this->translator->_g("Unable to copy/move image '%s': the target is not writable", $galleryId));
      } else {
        if($_REQUEST["sgMoveType"] == 'move') { //Move

          $current = rename($source, $target);
        foreach($this->gallery->images as $i => $img)
          if($img->id == $imageId) {
            array_splice($this->gallery->images,$i,1);
            //image removed from array so save metadata
            if($this->io->putGallery($this->gallery)) {
              //nulling image reference will select parent gallery
          $temp = $this->image;
              $this->image = null;
        
\\ save $temp to new location here


              $this->pushMessage($this->translator->_g("Image '%s' moved", htmlspecialchars($image)));
            } else {
              $this->pushError($this->translator->_g("Unable to save metadata."));
            }
          }
        } else { //Copy
          $current = copy($source, $target);
        }


        if($current === false) $this->pushError($this->translator->_g("Unable to copy/move image '%s' because the operation failed.", $imageId));
        else $totalImagesMoved++;
      }
    }
    
    //load target image
    if($totalImagesMoved)
      $this->selectGallery($_REQUEST['sgMoveTarget']);

    
    return $totalImagesMoved;
  }

feel free to improve this code...
it is already functional when you reindex the target album after moving the images.
Just want to save already posted data in the new location as well.

Offline

 

#17 2007-08-22 19:04:41

DC
Administrator

Re: Moving images via admin

Fantastic I modified it a tad so that when you move or copy it will now say MOVE or COPY...
so example err will say Unable to copy/move image '%s'

My mod will say if it was moved or copied I felt that was better Unable to MOVE image 'cool.jpg' or Unable to COPY image 'cool.jpg'

I also changed som other code ... as well check it out let me know what you think.

The one thing i did note and cant seem to fix is the followning err if we click the copy buton i get a foreach err when realy it should just show the err from the script thus bypassing our php based err, that would say somthing like please make a selection it does that fine with the standard gal move, but if you have no image checked you get that err I always test for ers like that, but somthings a miss with getting that to work on this as well?  any ides on that?

Did you hit that err as well?

from what I see in the orig this block prevents the php err on post and shows that text message please select, but will not seem to work correctly with the new code or even some mode code ...

if(!isset($_REQUEST["sgGalleries"]) && !isset($_REQUEST["sgImages"])) {
          $this->pushMessage($this->translator->_g("Please select one or more items."));
          $this->includeFile = "view";
}



Anyone who may have the above err try this mod that works great in my tests

//EDIT Made ...
//This was added to provide & error return if no box is ticked ...
        $my_image = $_REQUEST["sgImages"];
        if(!isset($my_image[0])) {
        $this->pushMessage($this->translator->_g("Please select one or more images."));
        $this->includeFile = "view";


Main MOD

Code:

 
//Mod allows you to move or copy images to new location.
  function moveMultipleImages(){
  
  $my_move = strtoupper($_REQUEST["sgMoveType"]);
  $galleryId = isset($_REQUEST["gallery"]) ? $_REQUEST["gallery"] : ".";
    $totalImagesMoved = 0;
    foreach($_REQUEST["sgImages"] as $imageId) {
      $source = $this->config->base_path.$this->config->pathto_galleries.$galleryId.'/'.$imageId;
      $target = $this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/'.basename($imageId);
      if(file_exists($target)) {
      $this->pushError($this->translator->_g("Unable to $my_move image '%s' image already exists.", $imageId));
        }elseif($this->isSubPath($source, $target, false)) {
        $this->pushError($this->translator->_g("Unable to $my_move gallery '%s' because the target is a child of the source.", $imageId));
      //} elseif(!is_writable($target)) {
      //  $this->pushError($this->translator->_g("Unable to copy/move image '%s': the target is not writable", $galleryId));
        }else{
        if($_REQUEST["sgMoveType"] == 'move') { //Move
        $current = @rename($source, $target);
        foreach($this->gallery->images as $i => $img)
        if($img->id == $imageId) {
            array_splice($this->gallery->images,$i,1);
            //image removed from array so save metadata
            if($this->io->putGallery($this->gallery)) {
            //nulling image reference will select parent gallery
            $temp = $this->image;
            $this->image = null;
        
            //Save $temp to new location here not yet implimented ...

            $this->pushMessage($this->translator->_g("Image '$imageId' moved", htmlspecialchars($image)));
            }else{
            $this->pushError($this->translator->_g("Unable to save metadata."));
            }
          }
        }else{ //Copy
        $current = @copy($source, $target);
        if ($current) $this->pushMessage($this->translator->_g("Image '$imageId' copied", htmlspecialchars($image)));
        }
        
        if($current === false) $this->pushError($this->translator->_g("Unable to $my_move image '$imageId' operation failed.", $imageId));
        else $totalImagesMoved++;
      }
    }
//load target image
if($totalImagesMoved)
  $this->selectGallery($_REQUEST['sgMoveTarget']);
  return $totalImagesMoved;
}

DC

Last edited by DC (2007-09-20 19:13:39)


To code or not to code that is the question?

Did my response help you out? Consider donating by buying me a slice, Whats this? Read More!
http://www.clickcraft.net/slice.php

Offline

 

#18 2007-08-24 21:38:13

jdvb
Member

Re: Moving images via admin

that function should work properly I would think

Code:

if(!isset($_REQUEST["sgImages"])) {
          $this->pushMessage($this->translator->_g("Please select one or more items."));
          $this->includeFile = "view";
} else {

// function contents

}

you should use the else to prevent the foreach from executing.

now that I take a closer look I also see that the $temp I set is incorrect, should be something with $this->gallery->images instead of $this->images

might dive into how that works exactly in order to build an absolute ordering system...

but then, I just do this for some holyday pictures... that I want to be maintained by others from this group holyday so that I won't have to do all...
Just don't have too much time to spend coding this...

Last edited by jdvb (2007-08-24 21:57:39)

Offline

 

#19 2007-08-24 21:51:02

DC
Administrator

Re: Moving images via admin

Nope that does not seem to work does it work for you?

it still alows you to get to the next step even thogh i did not select a check box and it should not ...

$test = $_REQUEST["sgImages"];
echo $test;

A test of what our request is outputing shows me its the dir info then on click with a check box ticked we see it shows only this, the words Array so thats why the func does not seem to, be working as it should in my opin ...

Any ideas on this based on what I am saying?

DC

Last edited by DC (2007-08-24 22:04:45)


To code or not to code that is the question?

Did my response help you out? Consider donating by buying me a slice, Whats this? Read More!
http://www.clickcraft.net/slice.php

Offline

 

#20 2007-08-24 22:00:12

jdvb
Member

Re: Moving images via admin

I will check it out in my test environment now, the site is now live, and people are active moving images... so will have to set up a test environment for that...

edit: In my code it does seam to work just fine, now that I am bussy, I am also getting the moving comments to work...
at least, diving into that a bit

Last edited by jdvb (2007-08-24 22:17:08)

Offline

 

#21 2007-08-24 22:08:01

DC
Administrator

Re: Moving images via admin

Thanks, thats fine please let me know?

Also check out the mods I did if you would, I think they make it a little better let me know what you think when you set it up on a test server.

DC


To code or not to code that is the question?

Did my response help you out? Consider donating by buying me a slice, Whats this? Read More!
http://www.clickcraft.net/slice.php

Offline

 

#22 2007-08-24 22:37:32

jdvb
Member

Re: Moving images via admin

Code:

  function moveMultipleImages(){
  
  $my_move = strtoupper($_REQUEST["sgMoveType"]);
  $galleryId = isset($_REQUEST["gallery"]) ? $_REQUEST["gallery"] : ".";
    $totalImagesMoved = 0;
if(!isset($_REQUEST["sgImages"])) {
          $this->pushMessage($this->translator->_g("Please select one or more items."));
          $this->includeFile = "view";
} else {
    foreach($_REQUEST["sgImages"] as $imageId) {
      $source = $this->config->base_path.$this->config->pathto_galleries.$galleryId.'/'.$imageId;
      $target = $this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/'.basename($imageId);
      if(file_exists($target)) {
      $this->pushError($this->translator->_g("Unable to $my_move image '%s' image already exists.", $imageId));
        }elseif($this->isSubPath($source, $target, false)) {
        $this->pushError($this->translator->_g("Unable to $my_move gallery '%s' because the target is a child of the source.", $imageId));
      //} elseif(!is_writable($target)) {
      //  $this->pushError($this->translator->_g("Unable to copy/move image '%s': the target is not writable", $galleryId));
        }else{
        if($_REQUEST["sgMoveType"] == 'move') { //Move
        $current = @rename($source, $target);
        foreach($this->gallery->images as $i => $img)
        if($img->id == $imageId) {
            array_splice($this->gallery->images,$i,1);
            //image removed from array so save metadata
            if($this->io->putGallery($this->gallery)) {
            //nulling image reference will select parent gallery
            $this->image = null;
        
            $this->pushMessage($this->translator->_g("Image '$imageId' moved", htmlspecialchars($imageId)));
            }else{
            $this->pushError($this->translator->_g("Unable to save metadata."));
            }
          }
        }else{ //Copy
        $current = @copy($source, $target);
        if ($current) $this->pushMessage($this->translator->_g("Image '$imageId' copied", htmlspecialchars($imageId)));
        }
        
        if($current === false) $this->pushError($this->translator->_g("Unable to $my_move image '$imageId' operation failed.", $imageId));
        else $totalImagesMoved++;
      }
    }
//load target image
if($totalImagesMoved)
  $this->selectGallery($_REQUEST['sgMoveTarget']);
        if($_REQUEST["sgMoveType"] == 'move') { //Move
$this->pushMessage($this->translator->_g("$totalImagesMoved image(s) moved", htmlspecialchars($imageId)));
} else {
$this->pushMessage($this->translator->_g("$totalImagesMoved image(s) copied", htmlspecialchars($imageId)));
}

  return $totalImagesMoved;
}}

no problems there on both test and livesite now

Last edited by jdvb (2007-08-24 22:38:52)

Offline

 

#23 2007-08-24 23:19:13

DC
Administrator

Re: Moving images via admin

Thats really strange my admin is pretty modified but whats odd is on yours it works and on mine the original move gall function works with no err if its unticked and I try and make it err, yet on mine your new mod still goes to the next step with the drop and the text on the page saying

Select the gallery to which you wish to move or copy the selected items. I need it to never get to that step if no checkbox is ticked.

therefor becouse it makes it to the next page its causing the err if nothing is selected

its fine if I select or tick a check box but if I tick nothing i still get err ...

they only way I seem to be able to prevent it from geting to the next step in my test are to do this in the doAction func

if(isset($_REQUEST["sgImages"])) {
$this->pushMessage($this->translator->_g("Please select one or more items."));
         $this->includeFile = "view";
         }else

just before this

if(!isset($_REQUEST["sgGalleries"]) && !isset($_REQUEST["sgImages"])) {
          $this->pushMessage($this->translator->_g("Please select one or more items."));
          $this->includeFile = "view";


Now this is incorrect as its not dynamic and you can never get to the next step ticked or not, but I did this in my test just to see if I could stop the err and prevent the next step from being executed ...

So if yours works with no err even when unticked then mine is to modified to compair the two acuratly.

So based on this info any idea how i can get the code added into the section were it will do what i need and yet work...

DC

Last edited by DC (2007-08-24 23:22:10)


To code or not to code that is the question?

Did my response help you out? Consider donating by buying me a slice, Whats this? Read More!
http://www.clickcraft.net/slice.php

Offline

 

#24 2007-08-25 00:39:35

jdvb
Member

Re: Moving images via admin

I have completed the function to include any given coments to also be copied and or moved:

ps. this function requires PHP 5.

Code:

    function moveMultipleImages(){
  
  $my_move = strtoupper($_REQUEST["sgMoveType"]);
  $galleryId = isset($_REQUEST["gallery"]) ? $_REQUEST["gallery"] : ".";
    $totalImagesMoved = 0;
if(!isset($_REQUEST["sgImages"])) {
          $this->pushMessage($this->translator->_g("Please select one or more items."));
          $this->includeFile = "view";
} else {
// getting all metadata into an array
    unset($temp, $temp2);
    $fcsv = fopen($this->config->base_path.$this->config->pathto_galleries.$galleryId.'/metadata.csv', r);
    while($tempo = fgetcsv($fcsv, 5000000, ",", '"')){
    $temp[] = $tempo;
    }    
    fclose($fcsv);
    if(!file_exists($this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/hits.csv')){
    $temp2[0] = Array ('"./'.$_REQUEST['sgMoveTarget'].'"', 0, 0);
    }
    $fcsv2 = fopen($this->config->base_path.$this->config->pathto_galleries.$galleryId.'/hits.csv', r);
    while($tempo = fgetcsv($fcsv2, 5000000, ",", '"')){
    $temp2[] = $tempo;
    }    
    fclose($fcsv2);
    foreach($_REQUEST["sgImages"] as $imageId) {
      $source = $this->config->base_path.$this->config->pathto_galleries.$galleryId.'/'.$imageId;
      $target = $this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/'.basename($imageId);
      if(file_exists($target)) {
      $this->pushError($this->translator->_g("Unable to $my_move image '%s' image already exists.", $imageId));
        }elseif($this->isSubPath($source, $target, false)) {
        $this->pushError($this->translator->_g("Unable to $my_move gallery '%s' because the target is a child of the source.", $imageId));
      //} elseif(!is_writable($target)) {
      //  $this->pushError($this->translator->_g("Unable to copy/move image '%s': the target is not writable", $galleryId));
        }else{
        if($_REQUEST["sgMoveType"] == 'move') { //Move
        $current = @rename($source, $target);
    
        foreach($this->gallery->images as $i => $img)
        if($img->id == $imageId) {
        array_splice($this->gallery->images,$i,1);
            //image removed from array so save metadata
            if($this->io->putGallery($this->gallery)) {
            //nulling image reference will select parent gallery
            $this->image = null;
               foreach($temp2 as $meta){
        if ($meta[0] == $imageId){

$csv = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+');
fputcsv($csv, $meta, ",", '"');
rewind($csv);
$meta = substr(stream_get_contents($csv), o, -1);

            $writemeta = fopen($this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/hits.csv', 'a');
            fwrite($writemeta, "\r\n" . $meta);
            fclose($writemeta);
        }
    }

            $this->pushMessage($this->translator->_g("Image '$imageId' moved", htmlspecialchars($imageId)));
            }else{
            $this->pushError($this->translator->_g("Unable to save metadata."));
            }
          }
        }else{ //Copy
        $current = @copy($source, $target);
        if ($current) $this->pushMessage($this->translator->_g("Image '$imageId' copied", htmlspecialchars($imageId)));
        }
    // getting the specific metadata out of the metadata array $temp and storing it into the new location metadata
    foreach($temp as $meta){
        if ($meta[0] == $imageId){

$csv = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+');
fputcsv($csv, $meta, ",", '"');
rewind($csv);
$meta = substr(stream_get_contents($csv), o, -1);

            $writemeta = fopen($this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/metadata.csv', 'a');
            fwrite($writemeta, "\r\n" . $meta);
            fclose($writemeta);
        }
    }
        
        if($current === false) $this->pushError($this->translator->_g("Unable to $my_move image '$imageId' operation failed.", $imageId));
        else $totalImagesMoved++;
      }
    }
//load target image
if($totalImagesMoved)
  $this->selectGallery($_REQUEST['sgMoveTarget']);
        if($_REQUEST["sgMoveType"] == 'move') { //Move
$this->pushMessage($this->translator->_g("$totalImagesMoved image(s) moved", htmlspecialchars($imageId)));
} else {
$this->pushMessage($this->translator->_g("$totalImagesMoved image(s) copied", htmlspecialchars($imageId)));
}

  return $totalImagesMoved;
}}

if you want to make this code work on any earlier version of PHP you should replace the fputcsv funcion with one compatible with an older PHP version.

The code is written kinda ugly, I simply read the source csv file again to avoid having to dig into how the CSV file is handled withing sgal. It works, but the file is read twice now, the target CSV is kinda strange a bit, the normal fputcsv function puts the line break at the en of each line, while sgal starts with it, hence I wrote the csv to memory and then striped the trailing "\r\n" from it, and wrote it to file starting with it.

feel free to improve this code in general (although it now is fully functional)




regarding the not working function when nothing is selected:

If it does not work for you then you must have implemented the code incorrectly:

Code:

if(!isset($_REQUEST["sgImages"])) {
          $this->pushMessage($this->translator->_g("Please select one or more items."));
          $this->includeFile = "view";
} else {
...
    foreach($_REQUEST["sgImages"] as $imageId) {
...

in words that code states:
if no images are selected then return your currentpage with the message no images selected,
else do the folowing for each selected image...

you should not use any categories selection requirements in this code, for then, when a categorie is selected, you will pass that requirement, wich is incorrect for the images function to be executed.

a suggestion might be to use the code exactly as I have provided, it does require PHP version 5 now though.


edit: Updated the code to also move the number of hits, hits will not be copied though

Last edited by jdvb (2007-08-25 01:12:12)

Offline

 

#25 2007-08-25 01:02:06

DC
Administrator

Re: Moving images via admin

Yes I know what it means, but thats the problem
$_REQUEST["sgImages"] only gives me the directory data so its never returning what I need so am not getting img array data in this case my crazy work around that now works for my page is the following.  Far from perfect but it does now work.

admin.class.php

I am updating this a bit, for the final mod as I now have it working I also made a new action block within the doAction func called multi_img

In my new action block I have
//This was added to provide & error return if no box is ticked ...
        $my_image = $_REQUEST["sgImages"];
        if(!isset($my_image[0])) {
        $this->pushMessage($this->translator->_g("Please select one or more images."));
        $this->includeFile = "view";
}else

/////

Mod code here ...

/////

and in viewalbum.tpl.php

I added
<input type="hidden" name="sgImages" value="<?php echo $sg->image->id; ?>"/>
and changed the orig multi hidden field to.
<input type="hidden" name="action" value="multi_img" />


and now that I can call my action block seperatly it all now works correctly as it should, again my version is very modified I am just presenting this here in case somone would like to try it that may have simular probs.


jdvb I thank you for your suggestions and nice mod by the way, but i need it to also be back compat so il use your old version with my mods inplace and work with that for now and then maybe re-mod it later.

DC

Last edited by DC (2007-08-25 04:17:08)


To code or not to code that is the question?

Did my response help you out? Consider donating by buying me a slice, Whats this? Read More!
http://www.clickcraft.net/slice.php

Offline

 

#26 2007-08-25 01:32:21

jdvb
Member

Re: Moving images via admin

to modify it for older verions you would only need to replace:

Code:

$csv = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+');
fputcsv($csv, $meta, ",", '"');
rewind($csv);
$meta = substr(stream_get_contents($csv), o, -1);

with something like:

Code:

$newmeta = "";
for($a=0, $b=sizeof($meta); $a<$b; $a++){
$newmeta .= '"'. preg_replace('#"#s','""', $meta[$a]) . '"';
if (($a+1)!=$b) $newmeta .= ',';
}
$meta = $newmeta;
unset($newmeta);

that code should work on all PHP versions

edit: replaced escapeshellarg($meta[$a]) with '"'. preg_replace('#"#s','""', $meta[$a]) . '"' in order for this function to also return double quotes on non windows servers

note: the above code is used twice, so should also be replaced twice in case you are using older PHP versions

to be complete the complete code for older PHP versions should now be (did test this on PHP4):

Code:

  function moveMultipleImages(){
  
  $my_move = strtoupper($_REQUEST["sgMoveType"]);
  $galleryId = isset($_REQUEST["gallery"]) ? $_REQUEST["gallery"] : ".";
    $totalImagesMoved = 0;
if(!isset($_REQUEST["sgImages"])) {
          $this->pushMessage($this->translator->_g("Please select one or more items."));
          $this->includeFile = "view";
} else {
// getting all metadata into an array
    unset($temp, $temp2);
    $fcsv = fopen($this->config->base_path.$this->config->pathto_galleries.$galleryId.'/metadata.csv', r);
    while($tempo = fgetcsv($fcsv, 5000000, ",", '"')){
    $temp[] = $tempo;
    }    
    fclose($fcsv);
    if(!file_exists($this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/hits.csv')){
    $temp2[0] = Array ('"./'.$_REQUEST['sgMoveTarget'].'"', 0, 0);
    }
    $fcsv2 = fopen($this->config->base_path.$this->config->pathto_galleries.$galleryId.'/hits.csv', r);
    while($tempo = fgetcsv($fcsv2, 5000000, ",", '"')){
    $temp2[] = $tempo;
    }    
    fclose($fcsv2);
    foreach($_REQUEST["sgImages"] as $imageId) {
      $source = $this->config->base_path.$this->config->pathto_galleries.$galleryId.'/'.$imageId;
      $target = $this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/'.basename($imageId);
      if(file_exists($target)) {
      $this->pushError($this->translator->_g("Unable to $my_move image '%s' image already exists.", $imageId));
        }elseif($this->isSubPath($source, $target, false)) {
        $this->pushError($this->translator->_g("Unable to $my_move gallery '%s' because the target is a child of the source.", $imageId));
      //} elseif(!is_writable($target)) {
      //  $this->pushError($this->translator->_g("Unable to copy/move image '%s': the target is not writable", $galleryId));
        }else{
        if($_REQUEST["sgMoveType"] == 'move') { //Move
        $current = @rename($source, $target);
    
        foreach($this->gallery->images as $i => $img)
        if($img->id == $imageId) {
        array_splice($this->gallery->images,$i,1);
            //image removed from array so save metadata
            if($this->io->putGallery($this->gallery)) {
            //nulling image reference will select parent gallery
            $this->image = null;
               foreach($temp2 as $meta){
        if ($meta[0] == $imageId){

$newmeta = "";
for($a=0, $b=sizeof($meta); $a<$b; $a++){
$newmeta .= '"'. preg_replace('#"#s','""', $meta[$a]) . '"';
if (($a+1)!=$b) $newmeta .= ',';
}
$meta = $newmeta;
unset($newmeta);

            $writemeta = fopen($this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/hits.csv', 'a');
            fwrite($writemeta, "\r\n" . $meta);
            fclose($writemeta);
        }
    }

            $this->pushMessage($this->translator->_g("Image '$imageId' moved", htmlspecialchars($imageId)));
            }else{
            $this->pushError($this->translator->_g("Unable to save metadata."));
            }
          }
        }else{ //Copy
        $current = @copy($source, $target);
        if ($current) $this->pushMessage($this->translator->_g("Image '$imageId' copied", htmlspecialchars($imageId)));
        }
    // getting the specific metadata out of the metadata array $temp and storing it into the new location metadata
    foreach($temp as $meta){
        if ($meta[0] == $imageId){

$newmeta = "";
for($a=0, $b=sizeof($meta); $a<$b; $a++){
$newmeta .= '"'. preg_replace('#"#s','""', $meta[$a]) . '"';
if (($a+1)!=$b) $newmeta .= ',';
}
$meta = $newmeta;
unset($newmeta);


            $writemeta = fopen($this->config->base_path.$this->config->pathto_galleries.$_REQUEST['sgMoveTarget'].'/metadata.csv', 'a');
            fwrite($writemeta, "\r\n" . $meta);
            fclose($writemeta);
        }
    }
        
        if($current === false) $this->pushError($this->translator->_g("Unable to $my_move image '$imageId' operation failed.", $imageId));
        else $totalImagesMoved++;
      }
    }
//load target image
if($totalImagesMoved)
  $this->selectGallery($_REQUEST['sgMoveTarget']);
        if($_REQUEST["sgMoveType"] == 'move') { //Move
$this->pushMessage($this->translator->_g("$totalImagesMoved image(s) moved", htmlspecialchars($imageId)));
} else {
$this->pushMessage($this->translator->_g("$totalImagesMoved image(s) copied", htmlspecialchars($imageId)));
}

  return $totalImagesMoved;
}}

Last edited by jdvb (2007-08-25 11:18:08)

Offline

 

#27 2007-09-20 17:36:35

joshq3i
Member

Re: Moving images via admin

There is an issue with moving an image that is also used for the gallery's thumbnail, it moves two lines of metadata, the thumbnail line and image line, instead of just the image line.

To correct this behavior find this code:

Code:

// getting all metadata into an array
    unset($temp, $temp2);
    $fcsv = fopen($this->config->base_path.$this->config->pathto_galleries.$galleryId.'/metadata.csv', r);
    while($tempo = fgetcsv($fcsv, 5000000, ",", '"')){
    $temp[] = $tempo;
    }    
    fclose($fcsv);

and add the line:

array_splice($temp,0,2);

immediately afterwards.

Final code will be:

Code:

// getting all metadata into an array
    unset($temp, $temp2);
    $fcsv = fopen($this->config->base_path.$this->config->pathto_galleries.$galleryId.'/metadata.csv', r);
    while($tempo = fgetcsv($fcsv, 5000000, ",", '"')){
    $temp[] = $tempo;
    }    
    fclose($fcsv);
    array_splice($temp,0,2);

This will remove the common header and thumbnail lines from the array so it doesn't get read when searching for image metadata.

The thumbnail is still lost though and will display the "Sample image from gallery" message.

____
Josh

Offline

 

#28 2007-09-20 19:06:56

DC
Administrator

Re: Moving images via admin

This mod works fine on my test server it combines code from jdvb and myself. ...

http://www.sgal.org/forum/viewtopic.php?pid=9334#p9334

The other that you speak of must have the bug try the other mod
at my link you should not have a problem with that version the one you tested looks like the other version jdvb wrote that works a little dif.

They both require additional mods to sections of the script.
But the one at my link works no prob moving images same or nt from gal to gal no problem that I can see ...

Might be best to use this version over the other mod if you cant get it to work correctly.

DC

Last edited by DC (2007-09-20 23:06:06)


To code or not to code that is the question?

Did my response help you out? Consider donating by buying me a slice, Whats this? Read More!
http://www.clickcraft.net/slice.php

Offline

 

#29 2007-10-11 00:26:27

forty two
Member

Re: Moving images via admin

You guys are the bomb.  Which file does this go into?  I'm assuming it's singapore.class.php

And probably at the bottom of the file?

+dk

Offline

 

#30 2007-10-11 00:59:02

DC
Administrator

Re: Moving images via admin

Thanks,

If your using the version I modified It works great it does not go in singaclass. I have it tested on a few servers and installs ...

The main mod goes in admin.class.php not singaclass

there is also  some other code you  will need to add as well
Please look at a few of my posts to see what I did to get it all working ...


http://www.sgal.org/forum/viewtopic.php?pid=9334#p9334

DC


To code or not to code that is the question?

Did my response help you out? Consider donating by buying me a slice, Whats this? Read More!
http://www.clickcraft.net/slice.php

Offline