Download & Extend

* warning: mb_eregi_replace() expects parameter 3 to be string, array given in...

Project:File (Field) Paths
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

I get the following error when using filefield paths in conjunction with pathauto:

    * warning: mb_eregi_replace() expects parameter 3 to be string, array given in /sites/all/modules/pathauto/pathauto.inc on line 184.
    * warning: mb_eregi_replace() expects parameter 3 to be string, array given in /sites/all/modules/pathauto/pathauto.inc on line 184.

Comments

#1

Status:active» postponed (maintainer needs more info)

Hi,

I just ran a couple quick tests and was unable to reproduce the issue.

What versions of the modules are you using?
If possible, get the latest versions of the modules and check if the error persists.

#2

The error occurs when uploading a photo using filefield/imagefield.

I upgraded to the OCT22 dev release, but the bug persists.

When trying to reproduce, did you enable pathauto within filefield_paths to rewrite the filename.

#3

Yes, I enabled pathauto cleanup for both the filename and filepath, and I also tested with an Imagefield.

What version of Pathauto are you using?

#4

Here is a list of all my modules from the updates page:

Content Construction Kit (CCK) 6.x-2.0-rc10

FileField 6.x-3.0-alpha5

FileField Paths 6.x-1.x-dev (2008-Oct-22)

ImageAPI 6.x-1.0

ImageCache 6.x-2.0-beta1

ImageField 6.x-3.0-alpha2

Lightbox2 6.x-1.x-dev (2008-Sep-05)

Node Map 6.x-1.0

Pathauto 6.x-1.1

Token 6.x-1.11

Views 6.x-2.1

All are up to date according to drupal.

#5

Hmm, the modules seem good, running the same versions as I am for all the modules. Only difference is I don't have Node Map or Lightbox2, and I don't have ImageCache enabled, but I very much doubt they should be related to this issue.

What are the patterns you are using and the data for the tokens?

#6

I disabled nodemap and lightbox2 but that had no effect.

I have only two fields in my content type, an imagefield, and a text field "name".

pattern:
[field_name-formatted].[filefield_paths-ext]

As for pathauto, I changed nothing from its original settings.

#7

Just a quick update... I also disabled imagecache and views but the error persists.

#8

I ran a test with that configuration and it worked fine.

Is it possible for you to setup another fresh install with just the required modules and see if the issue remains? I know it's a pain to do so, but without being able to reproduce the issue it's impossible for me to determine the cause.

#9

Another thing, what did you put in the 'name' field or does the error occur no matter what you use?

#10

Ok, very weird. I set up filefield paths on an established site with a similar module setup and it works error free. I should have done this from the beginning instead of wasting your time.

I'll completely reinstall the problem site (tommorrow) and post the results here.

Thanks for replying so quickly.

#11

Same error here. I'm curious to see your results!

#12

I did a full reinstall and now filefield paths renames like a jiffy with no errors. I can't wait until alt tags support!

#13

An observation after more testing:

When the node has one image uploaded, it saves normally.

If there are 2 or more images, it saves VERY slow - around 10 seconds or longer.

This only happens when "cleanup with pathauto" is enabled. I absolutely need that feature, so that file name spaces are turned from %20 into hyphens. Unfortunately its very slow, so I'm stuck between a rock and hard place.

Sometimes I get this error:

Fatal error: Maximum execution time of 30 seconds exceeded in /home/public_html/mysite/includes/common.inc on line 767

or this error:

Fatal error: Maximum execution time of 30 seconds exceeded in /home/public_html/mysite/sites/all/modules/pathauto/pathauto.inc on line 184

Please advise.

#14

I gave up on pathauto for removing filename spaces by adding this line to the module:

$value = str_replace(" ", "-" , $value);

AFTER

// Convert string to lower case
    $value = drupal_strtolower($value);

#15

I was looking to use the pathauto cleanup for space removal as well. Thanks for your solution!!

#16

You're welcome my friend.

When you tried to cleanup with pathauto, was it very slow when saving?

#17

Yes, it was a little slow. I suspect because of all the errors. I would receive around 4 mb_eregi_replace() errors per uploaded file.

Thanks again!

#18

@B.P.B.

I'm glad you got a workaround, however I would still like to work out the exact issue. I will continue to reproduce the issue, and if I ever manage to do so then I will attempt to fix it.

As for the workaround, it might be a useful feature. Can you create a feature request with any ideas of what you think are the primary things needed for replacements and I will look into it ASAP.

#19

I have the same error

    * warning: mb_eregi_replace() expects parameter 3 to be string, array given in /sites/all/modules/pathauto/pathauto.inc on line 184.
    * warning: mb_eregi_replace() expects parameter 3 to be string, array given in /sites/all/modules/pathauto/pathauto.inc on line 184.

I don t want to reinstall my website, too much work. Is there an other solution ?

To do that, will it fix my problem ?

gave up on pathauto for removing filename spaces by adding this line to the module:

$value = str_replace(" ", "-" , $value);
AFTER

// Convert string to lower case
    $value = drupal_strtolower($value);

#20

If all you want to do is convert spaces to hyphens, then yes.

Uncheck pathauto and add my fix.

#21

I think that the problem is data dependent. It seems that the pathauto_cleanstring() function (the one giving the warnings) is called over all possible tokens whether they are used in the particular filename or not.

The warnings occur when the value passed in as the string parameter is an array.

It is interesting that the problem only occurs when 'Cleanup using Pathauto' is enabled for 'File name cleanup settings and not for 'File path cleanup settings' (in my case anyway).

BTW. My comments are true for 6.x-1.0, I haven't had a look at dev yet.

#22

Getting this too.

#23

The reason for these warnings is that several modules implement the hook_token_values() function and return tokens when $type=='field'. Unfortunately some of them return tokens with the same keys.

For example:

  • The Numbers and Text modules that come as part of the CCK both return tokens with the keys raw and formatted.
  • The Link module returns a token with the key url as does the Nodereference module that comes with the CCK.

Thus getting these warnings is dependent upon which CCK related modules you have enabled. Each one on its own behaves well but when module_invoke_all is called to retrieve the token lists from these modules it bangs them together using array_merge_recursive. When Array_merge_recursive finds identical keys in arrays it is merging it merges their values together into an array for the one instance of the key in the final array. This array of values is then passed into a pathauto function that is expecting a string.

This problem is not related to FileField Paths. It is one of the modules that prefixes its keys with its module name, so its keys don't conflict with other modules.

#24

@pauline_perren

Thanks for the detailed response, that means I may be able to finaly replicate the issue and rule it out if what you say is true. :)

#25

@pauline_perren, just realized I'm not using filefield paths, so thank you for the explaination.

#26

Version:6.x-1.x-dev» 6.x-1.0
Status:postponed (maintainer needs more info)» needs review

One possible fix would be to patch pathauto so it doesn't warn on multiple values per key name. For example:

<?php
--- pathauto/pathauto.inc.orig  2008-12-22 14:40:26.000000000 -0500
+++ pathauto/pathauto.inc       2008-12-22 14:39:47.000000000 -0500
@@ -453,7 +453,16 @@
      
$full->values[$key] = pathauto_cleanstring($value, FALSE);
     }
     else {
-     
$full->values[$key] = pathauto_cleanstring($value);
+      if (
is_array($value)) {
+      
// certain modules (which luckily aren't path/url friendly)
+       // return duplicate keys (see <a href="http://drupal.org/node/324736" title="http://drupal.org/node/324736" rel="nofollow">http://drupal.org/node/324736</a>)
+       // which get merged into an array; process these specially
+       foreach ($value as $sub_key => $sub_value) {
+        
$full->values[$key][$sub_key] = pathauto_cleanstring($sub_value);
+       }
+      } else {
+      
$full->values[$key] = pathauto_cleanstring($value);
+      }
     }
   }
   return
$full->values;
?>

This doesn't get to the root problem (either token-providing modules should have unique token names, or token itself should better handle non-unique names). Also, not sure if this bug should be reassigned to either pathauto (where the above patch would go), token, or CCK?

I'm seeing this when I have CCK text and number modules enabled, and using PHP with mbstring module installed.

#27

Status:needs review» fixed

Implemented temporary fix to prevent issue and committed to DRUPAL-6--1 and HEAD.

#28

Where can I get this version from?
Meanwhile, is it ok if I get this warning?
Does it break functionality anywhere?

#29

Version:6.x-1.0» 6.x-1.x-dev
Status:fixed» closed (fixed)

The fix is in 6.x-1.x-dev and 5.x-1.x-dev..

The warning should not have broken any functionality, but I can not say that with 100% certainty.

#30

What does the File Alias option do?

#31

Just thought I would let you know that the error still persists with the latest of all the required modules.

Strange behaviour though...
My filepath settings are as such: [type-name]/[nid]/logo and filename: [nid]-[filefield-fid]-[filefield-filesize].[filefield_paths-ext]
Directories have been created as: [type-name]/[nid]/logo into which the old filename the image is stored.
Additionally, the tokens were also replaced and directories were created: group/153/logo with my new filename too: 153-55-36595.png. Stranger still, my generic files display links to the original, unfiltered, unpathautoed settings.

#32

@mckeen_greg,

This particular issue is closed. While you have said you are still seeing this issue, I will need more information to confirm that it is still a problem. A screenshot, module versions, reproduction steps would be great,

You're other issue needs to be re-posted as a separate issue. And some more information about it would be great as I have attempted to reproduce the issue with no luck so far.

#33

We get this on our site (Redmami - a site for Spanish parents), when users create content, but NOT when admins or editors create content. Is this a permissions issue?
warning: mb_eregi_replace() expects parameter 3 to be string, array given in /########/htdocs/sites/all/modules/pathauto/pathauto.inc on line 184.

#34

@redmani This issue is closed.

There are many different causes to this issue, FileField Paths was one, but that is now fixed so if you have the latest version of FileField Paths it is not the issue.

As the error you are receiving mentions Pathauto, it would probably be the best place to start, so maybe create a new issue in the Pathauto issue queue.

Cheers,
Deciphered.

nobody click here