Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Call to undefined function dbdecode

Hi all,

I am struck with an error when I tried to access JS Connect settings page

[24-Aug-2017 19:08:00 UTC] PHP Fatal error: Call to undefined function dbdecode() in /home/public_html/members/forum/plugins/jsconnect/class.jsconnect.plugin.php on line 234

Any idea on how to resolve this issue?

Thank you very much!

Comments

  • Any one please?

  • hgtonighthgtonight ∞ · New Moderator

    The function dbdecode was added to 2.4b1 via commit be55d0399e9e3a80fad4b6499023ffcc2302bc45 and jsConnect was updated later to use it. Vanilla 2.3.1 does not have this method defined. You could add it and the dbencode function definition to your custom /conf/bootstrap.before.php file.

    Snipped here for convenience:

    if (!function_exists('dbdecode')) {
        /**
         * Decode a value retrieved from database storage.
         *
         * @param string $value An encoded string representation of a value to be decoded.
         * @return mixed Null if the $value was empty, a decoded value on success or false on failure.
         */
        function dbdecode($value) {
            // Mirror dbencode behaviour.
            if ($value === null || $value === '') {
                return null;
            } elseif (is_array($value)) {
                // This handles a common double decoding scenario.
                return $value;
            }
            $decodedValue = json_decode($value, true);
            // Backward compatibility.
            if ($decodedValue === null) {
                // Suppress errors https://github.com/vanilla/vanilla/pull/3734#issuecomment-210664113
                $decodedValue = @unserialize($value);
            }
            if (is_array($value) || is_object($value)) {
                // IP addresses are binary packed now. Let's convert them from text to binary
                $decodedValue = ipEncodeRecursive($decodedValue);
            }
            return $decodedValue;
        }
    }
    if (!function_exists('dbencode')) {
        /**
         * Encode a value in preparation for database storage.
         *
         * @param mixed $value A value to be encoded.
         * @return mixed An encoded string representation of the provided value, null if the value was empty or false on failure.
         */
        function dbencode($value) {
            // Treat an empty value as null so that we insert "nothing" in the database instead of an empty string.
            if ($value === null || $value === '') {
                return null;
            }
            if (is_array($value) || is_object($value)) {
                // IP addresses are binary packed now.
                // Let's convert them to text so that they can be safely inserted into the text column
                $value = ipDecodeRecursive($value);
            }
            $encodedValue = false;
            try {
                $encodedValue = jsonEncodeChecked($value, JSON_UNESCAPED_SLASHES);
            } catch (Exception $ex) {
                $msg = 'Failed to encode a value in dbencode()';
                $context = ['value' => $value];
                trace(array_merge(['Error' => $msg], $context), TRACE_ERROR);
                Logger::log(Logger::ERROR, 'Failed to encode a value in dbencode()', $context);
            }
            return $encodedValue;
        }
    }
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.