Skip to content

Commit

Permalink
Implement escapeComment helper
Browse files Browse the repository at this point in the history
refs #10654
  • Loading branch information
Al2Klimov committed Feb 15, 2016
1 parent c78a791 commit b0932d2
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions modules/monitoring/application/views/helpers/EscapeComment.php
@@ -0,0 +1,38 @@
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */

/**
* Helper for escaping comments, but preserving links
*/
class Zend_View_Helper_EscapeComment extends Zend_View_Helper_Abstract
{
/**
* The purifier to use for escaping
*
* @var HTMLPurifier
*/
protected static $purifier;

/**
* Escape any comment for being placed inside HTML, but preserve simple links (<a href="...">).
*
* @param string $comment
*
* @return string
*/
public function escapeComment($comment)
{
if (self::$purifier === null) {
require_once 'HTMLPurifier/Bootstrap.php';
require_once 'HTMLPurifier.php';
require_once 'HTMLPurifier.autoload.php';

$config = HTMLPurifier_Config::createDefault();
$config->set('Core.EscapeNonASCIICharacters', true);
$config->set('HTML.Allowed', 'a[href]');
$config->set('Cache.DefinitionImpl', null);
self::$purifier = new HTMLPurifier($config);
}
return self::$purifier->purify($comment);
}
}

0 comments on commit b0932d2

Please sign in to comment.