geodesicsolutions-community / geocore-community

GeoCore Community, open source classifieds and auctions software
MIT License
9 stars 6 forks source link

multiple type errors in classes #234

Open iBeleave opened 5 months ago

iBeleave commented 5 months ago

Just a bunch of misc errors that show up, not going to make a new issue for each.
Errors noted, with suggested fixes (what worked for me) using '-' for remove and '+' for add.

manage watchlist/favorites (need quotes around 's') \classes\user_management_favorites.php ~line 133 - $seconds = $this->DateDifference(s, (geoUtil::time() + $remaining_minutes), $show_classified->ENDS); + $seconds = $this->DateDifference('s', (geoUtil::time() + $remaining_minutes), $show_classified->ENDS);

/ /
delete filter (saved search) produces site error
explanation from adodb: Because the method returns 0 for zero results and false for an unsupported statement, it is recommended to use === if testing for zero or false. in this case, already tested if query failed, so this really is just testing for rows affected \classes\user_management_ad_filters.php ~ line 90

/ / Unsupported operand types: int + string \classes\user_management_expired_ads.php:311 this just seems like an error, since should not add a string to int, and $extraCosts is added to $price later on, so should not be a string - $extraCosts += $show_closed->$fieldName_uc;

/ / //archive listings records wrong category information in expired listings table
\classes\cron\archive_listings.php

~147 - $category_string .= $cat[$i]["category_name"]; + $category_string .= $cat["category_name"];

// category is now stored in it's own table since 2016, so category field in classifieds table may be null // use geoListing object to get category id instead
~212 - $show['category'] = $this->get_category_string($show['category']); + $show['category'] = $this->get_category_string(geoListing::getListing($show['id'])->category);

/ / // $this->category_tree_array will not be an array if listing was archived
\classes\user_management_expired_ads.php ~465 (note: move this line lower, inside if statement a few lines down) remove: - reset($this->category_tree_array); add here:

if (is_array($this->category_tree_array)) {
    reset($this->category_tree_array);

/ / if viewing expired / archived listings from admin, the getListing() function may return null, and cause an error, so added check if $listing exists first (in about 16 places). there may be better solution, but this seems to work \classes\php5_classes\Listing.class.php (replace in multiple places, where ever found in this file) - if ($saveCache) { + if ($listing && $saveCache) {

/ /
TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in

\classes\browse_notify_friend.php :68

`- if (count($this->error_message['send_a_friend']) > 0) {`
`+ if (is_countable($this->error_message['send_a_friend']) && count($this->error_message['send_a_friend']) > 0) {`

/ /
TypeError: Unsupported operand types: string & int in \classes\php5_classes\products.php: 798

`- if ($key === null) {`
`+ if ($key === null || $key == '') {`

explanation: $key was set here: $key = $this->db->get_site_setting('password_key'); $key is not found, but returning empty string, instead of null, so causing type error could possibly use empty() to check, but would match on "0" so not sure if that is intended?

/ /

TypeError: trim(): Argument #1 ($string) must be of type string, array given \classes\order_items\listing_edit.php:131
remove:

if (trim($old_vars[$key]) === trim($value)) {
        //don't show if no change
        //continue;
    }
    if ($key == 'description' || strlen($old_vars[$key]) > 100 || strlen($value) > 100) {
        $old_vars[$key] = '<textarea disabled="disabled" style="overflow: auto; height: 200px; width: 450px;">' . $old_vars[$key] . '</textarea>';
        $value = '<textarea disabled="disabled" style="overflow: auto; height: 200px; width: 450px;">' . $value . '</textarea>';
    }
    if (is_array($old_vars[$key])) {
        $old_vars[$key] = '<pre>' . print_r($old_vars[$key], 1) . '</pre>';
    }
    if (is_array($value)) {
        $value = '<pre>' . print_r($value, 1) . '</pre>';
    }

replace with:

    if (is_array($old_vars[$key])) {
      $old_vars[$key] = '<pre>' . print_r($old_vars[$key], 1) . '</pre>';
     }

    if (is_array($value)) {
      $value = '<pre>' . print_r($value, 1) . '</pre>';
     }

    if ($key == 'description' || strlen($old_vars[$key]) > 100 || strlen($value) > 100) {
      $old_vars[$key] = '<textarea disabled="disabled" style="overflow: auto; height: 200px; width: 450px;">' . $old_vars[$key] . '</textarea>';
      $value = '<textarea disabled="disabled" style="overflow: auto; height: 200px; width: 450px;">' . $value . '</textarea>';
    }