PMA\libraries\DisplayResults::_handleNonPrintableContents PHP Method

_handleNonPrintableContents() private method

Verifies what to do with non-printable contents (binary or BLOB) in Browse mode.
private _handleNonPrintableContents ( string $category, string $content, mixed $transformation_plugin, string $transform_options, string $default_function, object $meta, array $url_params = [], &$is_truncated = null ) : mixed
$category string BLOB|BINARY|GEOMETRY
$content string the binary content
$transformation_plugin mixed transformation plugin. Can also be the default function: PMA_mimeDefaultFunction
$transform_options string transformation parameters
$default_function string default transformation function
$meta object the meta-information about the field
$url_params array parameters that should go to the download link
return mixed string or float
    private function _handleNonPrintableContents($category, $content, $transformation_plugin, $transform_options, $default_function, $meta, $url_params = array(), &$is_truncated = null)
    {
        $is_truncated = false;
        $result = '[' . $category;
        if (isset($content)) {
            $size = strlen($content);
            $display_size = Util::formatByteDown($size, 3, 1);
            $result .= ' - ' . $display_size[0] . ' ' . $display_size[1];
        } else {
            $result .= ' - NULL';
            $size = 0;
        }
        $result .= ']';
        // if we want to use a text transformation on a BLOB column
        if (gettype($transformation_plugin) === "object") {
            $posMimeOctetstream = strpos($transformation_plugin->getMIMESubtype(), 'Octetstream');
            $posMimeText = strpos($transformation_plugin->getMIMEtype(), 'Text');
            if ($posMimeOctetstream || $posMimeText !== false) {
                // Applying Transformations on hex string of binary data
                // seems more appropriate
                $result = pack("H*", bin2hex($content));
            }
        }
        if ($size <= 0) {
            return $result;
        }
        if ($default_function != $transformation_plugin) {
            $result = $transformation_plugin->applyTransformation($result, $transform_options, $meta);
            return $result;
        }
        $result = $default_function($result, array(), $meta);
        if ($_SESSION['tmpval']['display_binary'] && $meta->type === self::STRING_FIELD || $_SESSION['tmpval']['display_blob'] && stristr($meta->type, self::BLOB_FIELD)) {
            // in this case, restart from the original $content
            if (mb_check_encoding($content, 'utf-8') && !preg_match('/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x80-\\x9F]/u', $content)) {
                // show as text if it's valid utf-8
                $result = htmlspecialchars($content);
            } else {
                $result = '0x' . bin2hex($content);
            }
            list($is_truncated, $result, ) = $this->_getPartialText($result);
        }
        /* Create link to download */
        // in PHP < 5.5, empty() only checks variables
        $tmpdb = $this->__get('db');
        if (count($url_params) > 0 && (!empty($tmpdb) && !empty($meta->orgtable))) {
            $result = '<a href="tbl_get_field.php' . URL::getCommon($url_params) . '" class="disableAjax">' . $result . '</a>';
        }
        return $result;
    }
DisplayResults