1
Roby73
XOOPS 2.5.7 Final: PM issues
  • 2014/6/19 23:55

  • Roby73

  • Friend of XOOPS

  • Posts: 262

  • Since: 2011/6/15


In PM module i have this error when i delete one or many messages:
array_map(): Argument #2 should be an array nel file /modules/pm/viewpmsg.php alla linea 47

2
Mamba
Re: XOOPS 2.5.7 Final: PM issues
  • 2014/6/27 9:21

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


@ Roby73
Quote:
In PM module i have this error when i delete one or many messages:
array_map(): Argument #2 should be an array nel file /modules/pm/viewpmsg.php alla linea 47

in the file /modules/pm/viewpmsg.php in line 47 add "(array) ", so it changes from this:

$clean_msg_id array_map("intval"$clean_msg_id);

to this:

$clean_msg_id array_map("intval", (array) $clean_msg_id);


And let me know if it works.

It was tricky, because I've tested the issue of not being able to delete PM messages and I couldn't replicate it on 3 different installations, till finally on the fourth installation I could replicate the problem. I hope, it fixes the issue now.
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

3
Roby73
Re: XOOPS 2.5.7 Final: PM issues
  • 2014/6/27 22:19

  • Roby73

  • Friend of XOOPS

  • Posts: 262

  • Since: 2011/6/15


Quote:

Mamba wrote:
@ Roby73
Quote:
In PM module i have this error when i delete one or many messages:
array_map(): Argument #2 should be an array nel file /modules/pm/viewpmsg.php alla linea 47

in the file /modules/pm/viewpmsg.php in line 47 add "(array) ", so it changes from this:

$clean_msg_id array_map("intval"$clean_msg_id);

to this:

$clean_msg_id array_map("intval", (array) $clean_msg_id);


And let me know if it works.

It was tricky, because I've tested the issue of not being able to delete PM messages and I couldn't replicate it on 3 different installations, till finally on the fourth installation I could replicate the problem. I hope, it fixes the issue now.

Thank you very much Mamba!. Your job for xoops is fantastic

Sorry i try now new code.
Now i have white page after confirm delete.

4
Mamba
Re: XOOPS 2.5.7 Final: PM issues
  • 2014/6/28 1:42

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


Quote:
Sorry i try now new code.
Now i have white page after confirm delete.

Ouch!

What PHP version do you have? What theme do you use?
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

5
Roby73
Re: XOOPS 2.5.7 Final: PM issues
  • 2014/6/28 21:39

  • Roby73

  • Friend of XOOPS

  • Posts: 262

  • Since: 2011/6/15


Php on server is 5.4.28 and theme in use is BabyGelbDesign.
I try with default theme.

Thank you!!!

6
Mamba
Re: XOOPS 2.5.7 Final: PM issues
  • 2014/6/29 19:52

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


@ Roby73
Quote:
Sorry i try now new code.
Now i have white page after confirm delete.

OK, I see the issue now. The solution I've provided, works fine for single deletes, but it causes an error when you select multiple messages to delete, and unfortunately, I didn't test for it
My bad! Sorry for that!

Let me go back to the drawing board and find a fix for you.
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

7
Mamba
Re: XOOPS 2.5.7 Final: PM issues
  • 2014/7/8 12:01

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


Quote:
OK, I see the issue now. The solution I've provided, works fine for single deletes, but it causes an error when you select multiple messages to delete,

This is a little bit more complex that I thought. First, it was a whole adventure to get remote debugging working on this site with my editor, as it was the only site where I could replicate the error.

I have finally found what it is, but I don't have yet a solution.

What is happening is that when you select the messages to delete, XOOPS puts them into an array, which is then placed in $_POST. When XOOPS asks you to confirm to delete these messages, it encodes the array with JSON, and after you confirm the deletion, it should decode it again.
Unfortunately, somehow in this particular installation, it is being converted to a string, before XOOPS has a chance to decode it.

Can you take a look at your mainfile.php and tell me what values do you have for these constants:

define('XOOPS_GROUP_ADMIN''1');
define('XOOPS_GROUP_USERS''2');
define('XOOPS_GROUP_ANONYMOUS''3');
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

8
Roby73
Re: XOOPS 2.5.7 Final: PM issues
  • 2014/7/8 23:12

  • Roby73

  • Friend of XOOPS

  • Posts: 262

  • Since: 2011/6/15


Thank you!.
In mainfile.php i have:

define('XOOPS_GROUP_ADMIN''1');     
define('XOOPS_GROUP_USERS''2');     
define('XOOPS_GROUP_ANONYMOUS''3');

9
Mamba
Re: XOOPS 2.5.7 Final: PM issues
  • 2014/7/8 23:29

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


Quote:
What is happening is that when you select the messages to delete, XOOPS puts them into an array, which is then placed in $_POST. When XOOPS asks you to confirm to delete these messages, it encodes the array with JSON, and after you confirm the deletion, it should decode it again.
Unfortunately, somehow in this particular installation, it is being converted to a string, before XOOPS has a chance to decode it.

Good teamwork always leads to quicker results!

I was further investigating it and found out that the change was being done by the Protector in \xoops_lib\modules\protector\class\protector.php in line 636:

foreach ($_POST as $key => $val) {
    if ( 
substr$key , -) == 'id' && ! is_array$_POST$key] ) ) {
        
$newval preg_replace'/[^0-9a-zA-Z_-]/' '' $val ) ;
        
$_POST$key ] = $HTTP_POST_VARS$key ] = $newval ;
        if (
$_REQUEST$key ] == $_POST$key ]) {
            
$_REQUEST$key ] = $newval ;
        }
    }
}

So value that was stored in $_POST['msg_id'] like this: "[123,456]" would be converted to "123456", and JSON could not decode it again into an array.

Resized Image

Once this value has been changed, then the $pm_handler on line 52 in /pm/viewpmsg.php could never find the message, so $pm is null, and creates a Fatal Error in line 53:

Resized Image


This was the file trace:

Resized Image


and by going back step by step, we could see that the change was triggered by this code on line 66 in /xoops_lib/modules/protector/include/precheck_functions.php

// force intval variables whose name is *id
if( ! empty( $conf['id_forceintval'] ) ) $protector->intval_allrequestsendid() ;


because in the "msg_id" we have the "id".

I had to leave to a meeting, but Richard was kind enough to take a look at this, and he found the issue:

Quote:
I am able to turn the problem on and off with a protector preference, Force intval. The default value for this option is off, but when on it looks for request field names ending with 'id' and force them to be integers. Since the pm code uses 'msg_id' for the list of messages to delete in the confirmation, protector manges the value.

I ran a test on a clean system. Created 3 pm's, turned on "Force intval to variables like id" in protector preferences. Attempting to delete the pm's generates error:
"Warning: array_map(): Argument #2 should be an array in file /modules/pm/viewpmsg.php line 47"


Turn off the same preference everything works again.

Since protector is looking for fields ending with 'id', the solution is to end the problem name with something else. This problem effects both the pm module, and the simpler core pm functionality.

I've got patches for both ready to check in that solve this problem.

If anyone can find an additional circumstance that triggers this error, please let us know.

Thanks to Richard, another mystery has been solved, and we'll have a fix for it going forward.

Thanks to Roby73 for reporting the issues, and to Richard for fixing it.

And thanks to PhpStorm for being such a good tool that helped to debug the code here.

Resized Image
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

10
Mamba
Re: XOOPS 2.5.7 Final: PM issues
  • 2014/7/8 23:43

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


Richard has just committed the fix to XOOPS SVN, and I have tested it, and it works perfectly!

Thanks, Richard!!!
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

Login

Who's Online

418 user(s) are online (260 user(s) are browsing Support Forums)


Members: 0


Guests: 418


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits