[icinga-checkins] icinga.org: icingaweb2/master: PluginOutput: fix links only if there is any HTML
git at icinga.org
git at icinga.org
Thu Jun 2 17:58:35 CEST 2016
Module: icingaweb2
Branch: master
Commit: 7cfdbfccdb2349ceaa70cfe2d523745396afd87d
URL: https://git.icinga.org/?p=icingaweb2.git;a=commit;h=7cfdbfccdb2349ceaa70cfe2d523745396afd87d
Author: Alexander A. Klimov <alexander.klimov at netways.de>
Date: Fri May 20 13:11:09 2016 +0200
PluginOutput: fix links only if there is any HTML
refs #11796
---
.../application/views/helpers/PluginOutput.php | 41 ++++++++++++++++----
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/modules/monitoring/application/views/helpers/PluginOutput.php b/modules/monitoring/application/views/helpers/PluginOutput.php
index 7bb1cc4..b1b9a46 100644
--- a/modules/monitoring/application/views/helpers/PluginOutput.php
+++ b/modules/monitoring/application/views/helpers/PluginOutput.php
@@ -53,13 +53,20 @@ class Zend_View_Helper_PluginOutput extends Zend_View_Helper_Abstract
protected $zeroWidthSpace;
/**
+ * The encoded character
+ *
+ * @var string
+ */
+ protected $zeroWidthSpaceEnt = '';
+
+ /**
* Create a new Zend_View_Helper_PluginOutput
*/
public function __construct()
{
// This is actually not required as the value is constant,
// but as its (visual) length is 0, it's likely to be mixed up with the empty string.
- $this->zeroWidthSpace = html_entity_decode('', ENT_NOQUOTES, 'UTF-8');
+ $this->zeroWidthSpace = html_entity_decode($this->zeroWidthSpaceEnt, ENT_NOQUOTES, 'UTF-8');
}
/**
@@ -84,16 +91,23 @@ class Zend_View_Helper_PluginOutput extends Zend_View_Helper_Abstract
$this->getPurifier()->purify($output)
);
$isHtml = true;
+ $useDom = true;
} else {
// Plaintext
+ $count = 0;
$output = preg_replace(
self::$txtPatterns,
self::$txtReplacements,
- $this->view->escape($output)
+ $this->view->escape($output),
+ -1,
+ $count
);
$isHtml = false;
+ $useDom = (bool) $count;
}
- $output = $this->fixLinksAndWrapping($output);
+
+ $output = $useDom ? $this->fixLinksAndWrapping($output) : $this->fixWrapping($output, $this->zeroWidthSpaceEnt);
+
// Help browsers to break words in plugin output
$output = trim($output);
// Add space after comma where missing
@@ -184,14 +198,27 @@ class Zend_View_Helper_PluginOutput extends Zend_View_Helper_Abstract
protected function fixWrappingRecursive(DOMNode $node)
{
if ($node instanceof DOMText) {
- // Add zero width space after ')', ']', ':', '.', '_' and '-' if not surrounded by whitespaces
- $data = preg_replace('/([^\s])([\\)\\]:._-])([^\s])/', '$1$2' . $this->zeroWidthSpace . '$3', $node->data);
- // Add zero width space before '(' and '[' if not surrounded by whitespaces
- $node->data = preg_replace('/([^\s])([([])([^\s])/', '$1' . $this->zeroWidthSpace . '$2$3', $data);
+ $node->data = $this->fixWrapping($node->data, $this->zeroWidthSpace);
} elseif ($node->childNodes !== null) {
foreach ($node->childNodes as $childNode) {
$this->fixWrappingRecursive($childNode);
}
}
}
+
+ /**
+ * Add zero width space to make wrapping easier for the user agent
+ *
+ * @param string $output
+ * @param string $zeroWidthSpace
+ *
+ * @return string
+ */
+ protected function fixWrapping($output, $zeroWidthSpace)
+ {
+ // Add zero width space after ')', ']', ':', '.', '_' and '-' if not surrounded by whitespaces
+ $output = preg_replace('/([^\s])([\\)\\]:._-])([^\s])/', '$1$2' . $zeroWidthSpace . '$3', $output);
+ // Add zero width space before '(' and '[' if not surrounded by whitespaces
+ return preg_replace('/([^\s])([([])([^\s])/', '$1' . $zeroWidthSpace . '$2$3', $output);
+ }
}
More information about the icinga-checkins
mailing list