osclass / Osclass

With Osclass, get your own classifieds site for free. Build your own Osclass installation and start advertising real estate, jobs or whatever you want- in minutes!
http://osclass.org/
648 stars 343 forks source link

Search params array #2247

Closed maddrid closed 6 years ago

maddrid commented 6 years ago

http://mysite.com/osclass374/index.php?page=search&sOrder=dt_pub_date&iOrderType=desc&sCategory=1,2,33,44,8,17,12,13

works fine but throws warning message when hitting apply on search sidebar

PHP Warning: urldecode() expects parameter 1 to be string, array given in /osclass374/oc-includes/osclass/classes/Rewrite.php on line 194

also

this does not work anymore http://mysite.com/index.php?page=search&sCategory[]=1&sCategory[]=2

from bender theme (sCategory not passed to params )

        $aCategories = osc_search_category();
        foreach($aCategories as $cat_id) { ?>
            <input type="hidden" name="sCategory[]" value="<?php echo osc_esc_html($cat_id); ?>"/>
<?php } 

this works

<input   type="hidden" name="sCategory" value="<?php echo implode(",", osc_search_category()); ?>"/>
juliolopez78 commented 6 years ago

@web-media ran into this today too. It appears that the Rewrite class has only been written to expect strings, not arrays. :(

My workaround was to add a function and hook call in my theme's functions file and also to give my checkboxes unique names, but all prefixed with the same identifier, for example cat1, cat2, etc. To keep things extra simple, I actually used the category's ID as the numeric part of the name.

The function looks like this:

if (!function_exists('customPrepareCategories')) {
    function customPrepareCategories()
    {
        // grab the original GET array
        $getParams = Params::getParamsAsArray('get');
        // filter it down to our prefixed checkboxes
        $categories = array_filter(
            $getParams,
            function ($key) {
                // regex assumes that we will have up to a 5-digit category id,
                // but really your regex should work for your checkbox name style
                return preg_match('/^cat[0-9]{1,5}$/', $key) === 1;
            },
            ARRAY_FILTER_USE_KEY
        );
        // join all the category ids with a comma
        $sCategory = implode(',', $categories);
        // reset the sCategory param
        Params::setParam('sCategory', $categories);
    }
}
osc_add_hook('before_search', 'customPrepareCategories');
garciademarina commented 6 years ago

same issue #2259