forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.inc
91 lines (85 loc) · 2.5 KB
/
output.inc
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
use Drupal\Core\Render\Markup;
use Drush\Utils\StringUtils;
/**
* @defgroup outputfunctions Process output text.
* @{
*/
/**
* Prints a message with optional indentation. In general,
* $this->>logger()->$method($message) is often a better choice than this function.
* That gets your confirmation message (for example) into the logs for this
* drush request. Consider that Drush requests may be executed remotely and
* non interactively.
*
* @param $message
* The message to print.
* @param $indent
* The indentation (space chars)
* @param $handle
* File handle to write to. NULL will write
* to standard output, STDERR will write to the standard
* error. See http://php.net/manual/en/features.commandline.io-streams.php
* @param $newline
* Add a "\n" to the end of the output. Defaults to TRUE.
*
* @deprecated
* Use $this->output()->writeln() in a command method.
*/
function drush_print($message = '', $indent = 0, $handle = NULL, $newline = TRUE) {
$msg = str_repeat(' ', $indent) . (string)$message;
if ($newline) {
$msg .= "\n";
}
if (($charset = drush_get_option('output_charset')) && function_exists('iconv')) {
$msg = iconv('UTF-8', $charset, $msg);
}
if (!$handle) {
$handle = STDOUT;
}
fwrite($handle, $msg);
}
/**
* Rudimentary translation system, akin to Drupal's t() function.
*
* @param string
* String to process, possibly with replacement item.
* @param array
* An associative array of replacement items.
*
* @return
* The processed string.
*/
function dt($string, $args = []) {
return StringUtils::interpolate($string, $args);
}
/**
* Convert html to readable text. Compatible API to
* drupal_html_to_text, but less functional. Caller
* might prefer to call drupal_html_to_text if there
* is a bootstrapped Drupal site available.
*
* @param string $html
* The html text to convert.
*
* @return string
* The plain-text representation of the input.
*/
function drush_html_to_text($html, $allowed_tags = NULL) {
$replacements = [
'<hr>' => '------------------------------------------------------------------------------',
'<li>' => ' * ',
'<h1>' => '===== ',
'</h1>' => ' =====',
'<h2>' => '---- ',
'</h2>' => ' ----',
'<h3>' => '::: ',
'</h3>' => ' :::',
'<br/>' => "\n",
];
$text = str_replace(array_keys($replacements), array_values($replacements), $html);
return html_entity_decode(preg_replace('/ *<[^>]*> */', ' ', $text));
}
/**
* @} End of "defgroup outputfunctions".
*/