Ejemplo n.º 1
0
 /**
  * Display binary columns as hex string if requested
  * otherwise escape the contents using the best possible way
  *
  * @param string $content        String to parse
  * @param string $binary_or_blob binary' or 'blob'
  * @param int    $hexlength      optional, get substring
  *
  * @return String Displayable version of the binary string
  *
  * @access private
  *
  * @see    _getDataCellForGeometryColumns
  *         _getDataCellForNonNumericAndNonBlobColumns
  *         _handleNonPrintableContents
  */
 private function _displayBinaryAsPrintable($content, $binary_or_blob, $hexlength = null)
 {
     if ($binary_or_blob === 'binary' && $_SESSION['tmpval']['display_binary_as_hex']) {
         $content = bin2hex($content);
         if ($hexlength !== null) {
             $content = $GLOBALS['PMA_String']->substr($content, $hexlength);
         }
     } elseif (PMA_Util::containsNonPrintableAscii($content)) {
         if (PMA_PHP_INT_VERSION < 50400) {
             $content = htmlspecialchars(PMA_Util::replaceBinaryContents($content));
         } else {
             // The ENT_SUBSTITUTE option is available for PHP >= 5.4.0
             $content = htmlspecialchars(PMA_Util::replaceBinaryContents($content), ENT_SUBSTITUTE);
         }
     }
     return $content;
 }
 /**
  * Test for containsNonPrintableAscii
  *
  * @param string $str Value
  * @param bool   $res Expected value
  *
  * @return void
  *
  * @dataProvider dataProvider
  */
 public function testContainsNonPrintableAscii($str, $res)
 {
     $this->assertEquals($res, PMA_Util::containsNonPrintableAscii($str));
 }
 /**
  * Display binary fields as hex string for PHP <5.4, 
  * otherwise escape the contents if it may be displayed as hex
  *
  * @param string $content         String to parse
  * @param string $binary_or_blob  'binary' or 'blob'
  * @param int    $hexlength       optional, get substring
  *
  * @return Displayable version of the binary string
  *
  * @access private
  *
  * @see    _getDataCellForGeometryColumns
  *         _getDataCellForNonNumericAndNonBlobColumns
  *         _handleNonPrintableContents
  */
 private function _displayBinaryAsPrintable($content, $binary_or_blob, $hexlength = null)
 {
     if (PMA_PHP_INT_VERSION < 50400 || $binary_or_blob === 'binary' && $_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_Util::containsNonPrintableAscii($content)) {
         $content = bin2hex($content);
         if ($hexlength !== null) {
             $content = PMA_substr($content, $hexlength);
         }
     } else {
         $content = htmlspecialchars(PMA_Util::replaceBinaryContents($content), ENT_SUBSTITUTE);
     }
     return $content;
 }
Ejemplo n.º 4
0
 /**
  * Get data cell for non numeric and non blob type fields
  *
  * @param string  $column                the relavent column in data row
  * @param string  $class                 the html class for column
  * @param object  $meta                  the meta-information about the field
  * @param array   $map                   the list of relations
  * @param array   $_url_params           the parameters for generate url
  * @param boolean $condition_field       the column should highlighted
  *                                       or not
  * @param string  $transformation_plugin the name of transformation function
  * @param string  $default_function      the default transformation function
  * @param string  $transform_options     the transformation parameters
  * @param boolean $is_field_truncated    the condition for blob data
  *                                       replacements
  * @param array   $analyzed_sql          the analyzed query
  * @param integer &$dt_result            the link id associated to the query
  *                                        which results have to be displayed
  * @param integer $col_index             the column index
  *
  * @return  string  $cell               the prepared data cell, html content
  *
  * @access  private
  *
  * @see     _getTableBody()
  */
 private function _getDataCellForNonNumericAndNonBlobColumns($column, $class, $meta, $map, $_url_params, $condition_field, $transformation_plugin, $default_function, $transform_options, $is_field_truncated, $analyzed_sql, &$dt_result, $col_index)
 {
     $is_analyse = $this->__get('_is_analyse');
     $field_flags = PMA_DBI_field_flags($dt_result, $col_index);
     if (stristr($field_flags, self::BINARY_FIELD) && ($GLOBALS['cfg']['ProtectBinary'] == 'all' || $GLOBALS['cfg']['ProtectBinary'] == 'noblob')) {
         $class = str_replace('grid_edit', '', $class);
     }
     if (!isset($column) || is_null($column)) {
         $cell = $this->_buildNullDisplay($class, $condition_field, $meta);
     } elseif ($column != '') {
         // Cut all fields to $GLOBALS['cfg']['LimitChars']
         // (unless it's a link-type transformation)
         if (PMA_strlen($column) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == self::DISPLAY_PARTIAL_TEXT && gettype($transformation_plugin) == "object" && !strpos($transformation_plugin::getName(), 'Link') === true) {
             $column = PMA_substr($column, 0, $GLOBALS['cfg']['LimitChars']) . '...';
             $is_field_truncated = true;
         }
         $formatted = false;
         if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
             $column = PMA_Util::printableBitValue($column, $meta->length);
             // some results of PROCEDURE ANALYSE() are reported as
             // being BINARY but they are quite readable,
             // so don't treat them as BINARY
         } elseif (stristr($field_flags, self::BINARY_FIELD) && $meta->type == self::STRING_FIELD && !(isset($is_analyse) && $is_analyse)) {
             if ($_SESSION['tmp_user_values']['display_binary']) {
                 // user asked to see the real contents of BINARY
                 // fields
                 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_Util::containsNonPrintableAscii($column)) {
                     $column = bin2hex($column);
                 } else {
                     $column = htmlspecialchars(PMA_Util::replaceBinaryContents($column));
                 }
             } else {
                 // we show the BINARY message and field's size
                 // (or maybe use a transformation)
                 $column = $this->_handleNonPrintableContents(self::BINARY_FIELD, $column, $transformation_plugin, $transform_options, $default_function, $meta, $_url_params);
                 $formatted = true;
             }
         }
         if ($formatted) {
             $cell = $this->_buildValueDisplay($class, $condition_field, $column);
         } else {
             // transform functions may enable no-wrapping:
             $function_nowrap = 'applyTransformationNoWrap';
             $bool_nowrap = $default_function != $transformation_plugin && function_exists($transformation_plugin->{$function_nowrap}()) ? $transformation_plugin->{$function_nowrap}($transform_options) : false;
             // do not wrap if date field type
             $nowrap = preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap ? ' nowrap' : '';
             $where_comparison = ' = \'' . PMA_Util::sqlAddSlashes($column) . '\'';
             $cell = $this->_getRowData($class, $condition_field, $analyzed_sql, $meta, $map, $column, $transformation_plugin, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated);
         }
     } else {
         $cell = $this->_buildEmptyDisplay($class, $condition_field, $meta);
     }
     return $cell;
 }