-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevel_tables.module
60 lines (55 loc) · 1.59 KB
/
devel_tables.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* @file
* A Drupal front-end for mondrake.
*
* More soon...
*/
function _DTTextTrim($dontdoit, $text)
{
if ($dontdoit) {
return $text;
}
// @todo a default setting if variable not defined
$config = \Drupal::config('devel_tables.settings');
$text = strip_tags($text);
if (is_null($config->get('list_records.limit_text_to_chars'))) {
return $text;
}
if (strlen($text) > $config->get('list_records.limit_text_to_chars')) {
return substr($text, 0, $config->get('list_records.limit_text_to_chars') - 3) . '...';
}
return $text;
}
/**
* jsonpp - Pretty print JSON data
*
* In versions of PHP < 5.4.x, the json_encode() function does not yet provide a
* pretty-print option. In lieu of forgoing the feature, an additional call can
* be made to this function, passing in JSON text, and (optionally) a string to
* be used for indentation.
*
* @param string $json The JSON data, pre-encoded
* @param string $istr The indentation string
*
* @return string
*/
function jsonpp($json, $istr=' ')
{
$result = '';
for($p=$q=$i=0; isset($json[$p]); $p++)
{
$json[$p] == '"' && ($p>0?$json[$p-1]:'') != '\\' && $q=!$q;
if(strchr('}]', $json[$p]) && !$q && $i--)
{
strchr('{[', $json[$p-1]) || $result .= "\n".str_repeat($istr, $i);
}
$result .= $json[$p];
if(strchr(',{[', $json[$p]) && !$q)
{
$i += strchr('{[', $json[$p])===FALSE?0:1;
strchr('}]', $json[$p+1]) || $result .= "\n".str_repeat($istr, $i);
}
}
return $result;
}