Post by JEfromCanada » Fri Aug 24, 2018 8:27 pm

Hello,

I have seen this topic discussed in the OpenCart 2.0 General Support forum and have tried several free extensions which attempt to address this issue. It was after installing OpenCart 3.0.2 and experiencing the issue first hand that I took notice. It was my frustration with the situation that caused me to spend some time trying to track down the cause.

As mentioned, I am running OpenCart 3.0.2 with the Journal 2 theme, and I believe I have tracked down the cause, and have fixed the issue once and for all.

Since I am a relative newbie in this forum (but have been a programmer for over 45 years) I may not have any "street cred" in the OpenCart community. I don't know how to build a proper .ocmod.zip file to distribute the fix, but I was able to build a vqMod (thanks to UK Site Builder's excellent vqMod editor).

This vqMod (crafted specifically for OC 3.0.2) fixes the image manager search issue and implements case-insensitive search. I just purchased a wonderful image manager extension from "sonfil", and it was his attempt to fix these issues with his Free extensions that motivated me to find the actual solution. I have already sent him my vqMod solution in hopes that he will update his Free extensions.

For those who wish to receive my vqMod (absolutely free), send an email to info [at] jem-software.com. If any of you can direct me on how to submit this into the OpenCart github, I'd be more than willing to do that.

The first part of the fix (allowing the search to work as expected) was simple to solve. Line 48 of the /admin/controller/common/filemanager.php file is:

$files = glob($directory . '/' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE);

Note the wildcard character just before the file extension list. This tells the search program to search for anything that BEGINS WITH $filter_name. HOWEVER, it does not handle the situation where $filter_name appears INSIDE the file name (not the beginning).

To solve this, a second wildcard needs to be added BEFORE the $filter_name. Here is the revised line 48, with one additional astererisk (can you spot it)?

$files = glob($directory . '/*' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE);

That's it! Add the asterisk, and image search works as expected - almost.

Unfortunately, it still requires that $filter_name be entered in the CORRECT CASE (who knows how users will enter their information). To fix this, $filter_name needs to be case insensitive. However, the sql_regcase command, suggested by "sonfil" in his free extension, was removed in PHP 7.0. A user-defined function that implements this functionality needs to be substituted instead. My solution includes a user-defined function, which should be added as a file in the /system/helper folder, as well as the modifications to /system/startup.php file to reference the new helper module.

Now that I've thoroughly described the solution, perhaps someone could arrange to have it added to the code base. In the meantime, feel free to contact me about the .zip file that contains the vqMod and helper files.

If it is not breaking the rules of the forum, I can be reached at info [at] jem-software.com.
Last edited by JEfromCanada on Sat Aug 25, 2018 10:17 am, edited 2 times in total.

New member

Posts

Joined
Thu May 23, 2013 1:49 am

Post by straightlight » Sat Aug 25, 2018 5:40 am

You might be using a Solaris server. See this solution: viewtopic.php?f=202&t=204862&p=731937#p725577

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by JEfromCanada » Sat Aug 25, 2018 10:01 am

@straightlight

Thanks for responding to my post. I had no problems with the "glob" command or its parameters. I posted a solution for a long-standing problem using the search feature of the image manager, which involved simply adding a '*' before the $filter_name.

Instead of OpenCart doing a match on '$filter_name*.jpg', with my solution, it will do a match on '*$filter_name*.jpg'. The match will not work using the original version of filemanager.php unless the user-specified filter happened to match the beginning of the filename. For example, if the name of an image is DSC01234.jpg, a user entering "1234" as the search string would *NOT* be successful using the stock version of filemanager.php. However, by making the described change to line 48, a user entering "1234" as the search string *WILL* locate a file named DSC01234.jpg.

The second part of my post, which discusses adding a user-defined function in the /system/help folder, would allow users to match on the term: "dsc". Right now, even after implementing the "*" fix, a search for "dsc" would fail because it doesn't exactly match the CASE of the filename, which begins with "DSC". An image named "Horses.jpg" would not match a search for "horse" (because of the capitalized "H"). Implementing the second part of the solution will allow for a case-insensitive search by emulating the function of the sql_regcase function (which is not supported in PHP 7.0).

New member

Posts

Joined
Thu May 23, 2013 1:49 am
Who is online

Users browsing this forum: No registered users and 2 guests