Пример #1
0
 /**
  * @depends test_is_json_exists
  */
 public function test_is_json_dislikes_serialized()
 {
     $input = 'a:3:{s:13:"twentyfifteen";s:7:"/themes";s:14:"twentyfourteen";s:7:"/themes";s:14:"twentythirteen";s:7:"/themes";}';
     $result = Options_Pixie_Data_Format::is_json($input);
     $this->assertFalse($result);
 }
 /**
  * Returns an array of the high level types of the data other than general text or number.
  *
  * Types: S (serialized), O (object), J (JSON), b64 (base64), !!! (broken serialized).
  *
  * @since 1.0
  *
  * @param mixed $data
  *
  * @return array
  */
 public static function get_data_types($data)
 {
     $types = array();
     if (Options_Pixie_Data_Format::is_base64($data)) {
         $types[] = 'b64';
         $data = base64_decode($data, true);
     }
     if (is_serialized($data)) {
         $types[] = 'S';
         if (Options_Pixie_Data_Format::is_broken_serialized($data)) {
             $types[] = '!!!';
         } else {
             $data = unserialize($data);
         }
     }
     if (is_object($data)) {
         $types[] = 'O';
     }
     if (Options_Pixie_Data_Format::is_json($data)) {
         $types[] = 'J';
     }
     return $types;
 }
 /**
  * Formats the option_value column for display.
  *
  * @since 1.0
  *
  * @param string $value
  * @param object $item
  * @param array  $options
  *
  * @return string|void
  */
 public function column_option_value($value, $item, $options)
 {
     global $mode;
     $chars = 100;
     if ('list' == $mode && strlen(trim($value)) > $chars) {
         if (!isset($options['collapsed']) || true === $options['collapsed']) {
             if (is_serialized($value)) {
                 $boundary = ';';
             } elseif (Options_Pixie_Data_Format::is_json($value)) {
                 $boundary = ',';
             } else {
                 $boundary = ' ';
             }
             $truncated = $this->truncate_chars($value, $chars, $boundary);
             if ($truncated !== $value) {
                 $value = $truncated . ' …';
             }
         }
     } elseif ('excerpt' === $mode) {
         $value = Options_Pixie_Data_Format::to_html($value, 'options-pixie-rich-view');
     }
     // Whether truncated or not, in list mode we're handling raw data that must be escaped.
     if ('list' == $mode) {
         $value = esc_html($value);
     }
     return $value;
 }