forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 plugins => Topic started by: macmiller on March 19, 2011, 05:23:55 am

Title: Delete Control for V 1.5.x
Post by: macmiller on March 19, 2011, 05:23:55 am
Is there a plugin similar to Delete Control on Users Galleries & Public Albums available for 1.5.x? 

The following plugin does what I want but I can only locate the 1.4.x version:

http://forum.coppermine-gallery.net/index.php/topic,29116.html (http://forum.coppermine-gallery.net/index.php/topic,29116.html)

Title: Re: Delete Control for V 1.5.x
Post by: Αndré on March 19, 2011, 07:37:47 pm
Afaik such a plugin doesn't exist, but I think it's quite easy to port that plugin to cpg1.5.x.
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on March 20, 2011, 03:43:45 am
I've been testing the plugin to see if it will work. 

The two things that don't seem to work with the plugin 'as is' (in 1.5.12):

The user can no longer create albums.  This was a noted problem in 1.4.x and fixed with this notation:
* fixed error where user could not create album (function is in delete.php)
(the problem re appears in 1.5.x)

The Delete button appears on the page where albums are listed.  Noted and fixed in 1.4.x with this notation:
* remove delete button from albmgr.php - processing is already disabled in delete.php
(the problem re appears in 1.5.x)

Any hints on what to change appreciated. 

Title: Re: Delete Control for V 1.5.x
Post by: Αndré on March 20, 2011, 10:53:46 am
I'll have a look at that plugin asap.
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on March 27, 2011, 07:22:22 am
Any insight?  Not quite sure why this plug interferes with the album creation feature.  Any help greatly appreciated.  Also, just as a note I have tested this version posted of this plug in in CPG 1.4.x and it does not have any of the noted problems (everything works with the plugin in v 1.4.x).
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on April 11, 2011, 03:09:52 pm
I just had a look at this again in my test area.  When I comment out the following code in the plugin the album creation works as normal, with this code active (no commented out) the album creation does not work.  Again, this was a problem at one time for the 1.4.x version which was later fixed.  The fixed and latest version is broken again with CPG 1.5.x (I already verified that this version does in fact work in 1.4.x in my test area).

Here is the code which causes the problem (now commented out):
Code: [Select]
//  if (defined('DELETE_PHP') && !GALLERY_ADMIN_MODE) {
//  $try_to_delete = false;
// $what = isset($_GET['what']) ? $_GET['what'] : $_POST['what'];
//  if (($what != 'albmgr') || (($what == 'albmgr') && $_POST['delete_album'])) {
//  $try_to_delete = true;
//  }
//  if ($try_to_delete) {
//  load_template();
//  pageheader($lang_error);
//  cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
//  }
//  }

How this causes the album creation to fail in CPG 1.5.x is a mystery to me.  Any clues greatly appreciated as I need to get this operational soon, and I am totally stumped!

Title: Re: Delete Control for V 1.5.x
Post by: Αndré on April 11, 2011, 03:34:46 pm
Sorry that I hadn't found time to look at the code myself. It's quite easy to explain why that code breaks the album creation. New albums will be created with the file delete.php in the back-end. That's why there's the following check, which distinguish the different actions contained in that file:
Code: [Select]
// $what = isset($_GET['what']) ? $_GET['what'] : $_POST['what'];
//  if (($what != 'albmgr') || (($what == 'albmgr') && $_POST['delete_album'])) {
//  $try_to_delete = true;
//  }

You have to replace the superglobals as described here (http://documentation.coppermine-gallery.net/en/dev_superglobals.htm), otherwise $what is always empty and the check doesn't work.

Try to replace
Code: [Select]
$what = isset($_GET['what']) ? $_GET['what'] : $_POST['what'];with
Code: [Select]
$superCage = Inspekt::makeSuperCage();
if ($superCage->get->keyExists('what')) {
    $what = $superCage->get->getAlpha('what');
} elseif ($superCage->post->keyExists('what')) {
    $what = $superCage->post->getAlpha('what');
} else {
    cpg_die(CRITICAL_ERROR, $lang_errors['param_missing'], __FILE__, __LINE__);
}
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on April 11, 2011, 05:15:46 pm
Much thanks Andre.  I just tried your suggested code and was able to create an album in my test area.  I will do more testing on this later, but for now seems to be working.

Before closing this out there is one remaining issue, that is the Delete button.  In the 1.4.x environment the button was labeled 'DELETE'.  This plug-in in the 1.4.x environment correctly hides the button, that is it is not displayed.  In the 1.5.x environment the button is labeled 'Delete'.  The plug-in does not hide the button, that is it is still displayed (which is not good, it should not be displayed).

I know it is something simple, but any quick suggestions on code and I will test it and then this plug-in will be ready to go for 1.5.x. 

Thanks in advance.
Title: Re: Delete Control for V 1.5.x
Post by: Αndré on April 12, 2011, 10:32:21 am
Please attach your cpg1.5.x version of the plugin as zip file to your next reply.
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on April 12, 2011, 12:36:03 pm
The zip of version 1.04 is attached.  Remember it isn't finished yet.  The Delete button still shows up when it shouldn't.  I need help to fix this. 


Thanks for the continuing help.
Title: Re: Delete Control for V 1.5.x
Post by: Αndré on April 12, 2011, 04:45:57 pm
As you can see in the function delcon_filterpage the plugin removes delete buttons at 4 different places:
1. displayimage.php
2. index.php
3. editpics.php
4. albmgr.php

Which delete button do you mean that won't be hidden?


Additionally, you have to replace 3 more $_POST[ superglobals.
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on April 12, 2011, 05:18:50 pm
Quote
Which delete button do you mean that won't be hidden?
index.php:  The Delete button still shows.  (in error)
displayimage.php:  There is no Delete button showing.  (working correctly) 
albmgr.php:  There is an 'X' button to delete the selected album showing.   (in error)
editpics.php:  There is an 'X' button showing to delete the selected pics.  (in error)

 
Quote
Additionally, you have to replace 3 more $_POST[ superglobals.
I'm reading the documentation, still a bit foggy on it.  Can you give me an example of how to access the $_POST and change this line
        
Code: [Select]
if (($what != 'albmgr') || (($what == 'albmgr') && $_POST['delete_album'])) which is the next instance of $_POST?

Thanks in advance....
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on May 23, 2011, 09:17:38 am
This was marked as 'solved' although it isn't yet as the plug in as is causes other things not to work.   I'm wondering if you could let me know how to change the following line to work in 1.5? 

Code: [Select]
if (($what != 'albmgr') || (($what == 'albmgr') && $_POST['delete_album']))
I think I will understand how to upgrade a plug in after this, sorry about being so dense! ???
Title: Re: Delete Control for V 1.5.x
Post by: Αndré on May 23, 2011, 09:55:32 am
I haven't looked at the code, but in any case you have to replace
Code: [Select]
$_POST['delete_album']with
Code: [Select]
$superCage->post->keyExists('delete_album')
For more information, read http://documentation.coppermine-gallery.net/en/dev_superglobals.htm
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on May 24, 2011, 03:53:39 am
There is one last $_POST which is:

Code: [Select]
  if (isset($_POST['delete'.$pid])) $try_to_delete = true;
Can you let me know what the modified code would be?
Title: Re: Delete Control for V 1.5.x
Post by: Αndré on May 24, 2011, 09:07:13 am
Replace
Code: [Select]
isset($_POST['delete'.$pid])with
Code: [Select]
$superCage->post->keyExists('delete'.$pid)
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on May 26, 2011, 10:12:55 am
I tried to change another _post command but it is not working (the way I changed it).

Can you tell me how this line should be changed?

Code: [Select]
          $pid_array = $_POST['pid'];

Thanks and I believe this is the last one!!!
Title: Re: Delete Control for V 1.5.x
Post by: Αndré on May 26, 2011, 12:25:03 pm
it is not working (the way I changed it).
Please post your solution.
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on May 27, 2011, 10:46:11 am
Code: [Select]
        $pid_array = $superCage->post->keyExists('pid');
Title: Re: Delete Control for V 1.5.x
Post by: Αndré on May 27, 2011, 11:00:40 am
Of course it won't work if you use keyExists. The name should be self-explanatory: it only checks if a value has been submitted. If you want to get that value, use getInt:
Code: [Select]
        $pid_array = $superCage->post->getInt('pid');
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on May 28, 2011, 01:22:59 pm
For some reason it blows up under the Editpics section when it hits the $superCage line $superCage->post->getInt('pid');  (this happens when the Edit Files button is pressed off of the index.php).  It produces no error message that I can find.  I had a log file set up and it logs right before the $supercage and then doesn't execute the following line.

Code: [Select]
if (defined('EDITPICS_PHP') && !GALLERY_ADMIN_MODE) {

$try_to_delete = false;
//V1.051 Mod following Line
//         $pid_array = $_POST['pid'];

  $pid_array = $superCage->post->getInt('pid');
        foreach($pid_array as $pid){
                $pid = (int)$pid;
//V1.051 Mod following line
// if (isset($_POST['delete'.$pid])) $try_to_delete = true;
  if ($superCage->post->keyExists('delete'.$pid)) $try_to_delete = true;

}
if ($try_to_delete) {

load_template();
pageheader($lang_error);

cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
}
}

Likewise this code to check the boolean condition also causes it to blow up for some reason (placed before the first $superCage). 
Code: [Select]
              if ($superCage->post->keyExists('pid')) {
                 fwrite($newfile,"keyexists");
             } else {
                 fwrite($newfile,"keydoesntexist");
              }
write($newfile, "\n");

When I comment out the $superCage section and initialize the $pid_array ($pid_array = array()), everything executes and looks normal, but I am unclear on what the purpose of this section is.

 
Title: Re: Delete Control for V 1.5.x
Post by: Αndré on May 31, 2011, 10:52:57 am
Please attach your modified plugin so I can perform some tests.
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on May 31, 2011, 03:37:49 pm
thanks for taking a look.  There are two things still not working, one is the noted code that seems to blow up and also the delete options are still available under the editpics option. 
Title: Re: Delete Control for V 1.5.x
Post by: Αndré on June 01, 2011, 12:23:22 pm
For some reason it blows up under the Editpics section when it hits the $superCage line $superCage->post->getInt('pid');  (this happens when the Edit Files button is pressed off of the index.php).  It produces no error message that I can find.
The error message
Quote
Fatal error: Call to a member function getInt() on a non-object in C:\xampplite\htdocs\svn_cpg15x_trunk\plugins\delete_control1.042\codebase.php on line 95
says, that you have to add
Code: [Select]
$superCage = Inspekt::makeSuperCage();just before
Code: [Select]
$pid_array = $superCage->post->getInt('pid');


the delete options are still available under the editpics option
Try the following code:
Code: [Select]
$html = preg_replace('/<td class="(tableh2|tableb|tableb tableb_alternate)" width="40" valign="top">.*name="delete.*".*<\/td>/Us','',$html);
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on June 01, 2011, 03:22:52 pm
That works in my test environment (both items). 

In testing I just noticed that the delete option is still showing under the albmgr (hopefully the last item)

The existing preg_replace statement is this:
Code: [Select]
$html = preg_replace('/(?U)<td.*\s*(?s)javascript:Album_Delete().*<\/td>/','<td width="80">&nbsp;</td>',$html);
The html generated looks like this:
Code: [Select]
<button type="button" id="delete_album" name="delete_album" class="button" value="Delete album" disabled="disabled" title="Delete album"><img src="images/icons/delete.png" border="0" alt="" width="16" height="16" class="icon" /></button>
I tried these:
Code: [Select]
   $html = preg_replace('/(?U)<button.*name=\"delete_album\".*<\/button>/','',$html);
   $html = preg_replace('/(?U)<button.*\s*(?s)name=\"delete_album\".*<\/button>/','',$html);
They both did the same thing, they removed the desired button but also removed the downdown_click button which is on the same line immeaditely preceding the delete button.  The entire line is as follows:
Code: [Select]
<button type="button" id="downdown_click" name="downdown_click" class="button" value="Move to bottom" disabled="disabled" title="Move to bottom"><img src="images/icons/downdown.png" border="0" alt="" width="16" height="16" class="icon" /></button>                        <button type="button" id="delete_album" name="delete_album" class="button" value="Delete album" disabled="disabled" title="Delete album"><img src="images/icons/delete.png" border="0" alt="" width="16" height="16" class="icon" /></button>
   If you can suggest one that removes only the one segment it would be appreciated.


Title: Re: Delete Control for V 1.5.x
Post by: Αndré on June 01, 2011, 03:46:40 pm
Use
Code: [Select]
$html = preg_replace('/<button type="button" id="delete_album".*<\/button>/U','',$html);
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on June 02, 2011, 10:01:04 am
Thanks for all the help Andre!

Here is the latest plugin (attached).  I have tested it and it seems to work fine in 1.5.12. 
Title: Re: Delete Control for V 1.5.x
Post by: Αndré on June 07, 2011, 03:26:00 pm
Do you want to use this thread as plugin announcement thread (i.e. should I move it to the plugin contributions board) or do you want to start a separate thread?
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on June 07, 2011, 04:05:25 pm
Good point, this is the announcement thread for the Delete Control for CPG V1.5.x (http://forum.coppermine-gallery.net/index.php/topic,72695.0.html) .
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on June 12, 2011, 06:12:32 am
There is another problem with this plug in.  Basically once the plug in is installed the users can not longer sort their pictures.

How the problem occurs:
1. User Logon
2. User selects 'sort my pictures'.
3. User modifies sort order
4. User clicks on 'apply these changes'.
A message is returned indicating the user does not have permission to make the modifications.

This problem existed on the 1.4.x version of the plugin (http://forum.coppermine-gallery.net/index.php/topic,29116.0.html).  I have tested the previous (1.4.x) version of the plug in in both a bridged and non-bridged test environment (v 1.4.25), and the problem (as described above) occurs in both environments.  The problem also occurs in the 1.5.12 version of coppermine and the new plug in.
   
Title: Re: Delete Control for V 1.5.x
Post by: Αndré on June 14, 2011, 11:56:28 am
In codebase.php, find
Code: [Select]
if (($what != 'albmgr') || (($what == 'albmgr') && $superCage->post->keyExists('delete_album'))) {and replace with
Code: [Select]
if (($what != 'albmgr' && $what != 'picmgr' ) || (($what == 'albmgr') && $superCage->post->keyExists('delete_album'))) {
Title: Re: Delete Control for V 1.5.x
Post by: macmiller on June 14, 2011, 01:58:48 pm
Great!  That seemed to fix it.   :)

I'll post the revised plug in v 1.043 here and in the announcement thread (http://forum.coppermine-gallery.net/index.php/topic,72695.0.html) .