2015-11-05 21:26:48 +01:00
|
|
|
<?php
|
|
|
|
class HTMLUtils {
|
|
|
|
|
|
|
|
public static function getHelperButtonFormat($value, $name){
|
|
|
|
return '<button type="submit" name="format" value="' . $value . '">' . $name . '</button>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getHelperButtonsFormat($formats){
|
|
|
|
$buttons = '';
|
|
|
|
foreach( $formats as $name => $infos )
|
|
|
|
{
|
|
|
|
if ( isset($infos['name']) )
|
|
|
|
{
|
|
|
|
$buttons .= HTMLUtils::getHelperButtonFormat($name, $infos['name']) . PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $buttons;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function displayBridgeCard($bridgeName, $formats, $isActive = true)
|
|
|
|
{
|
|
|
|
|
|
|
|
$bridgeElement = Bridge::create($bridgeName);
|
|
|
|
if($bridgeElement == false) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
$bridgeElement->loadMetadatas();
|
|
|
|
|
|
|
|
$name = '<a href="'.$bridgeElement->uri.'">'.$bridgeElement->name.'</a>';
|
|
|
|
$description = $bridgeElement->description;
|
|
|
|
|
|
|
|
$card = <<<CARD
|
|
|
|
<section id="bridge-{$bridgeName}" data-ref="{$bridgeName}">
|
|
|
|
<h2>{$name}</h2>
|
|
|
|
<p class="description">
|
|
|
|
{$description}
|
|
|
|
</p>
|
|
|
|
CARD;
|
|
|
|
|
|
|
|
// If we don't have any parameter for the bridge, we print a generic form to load it.
|
|
|
|
if(count($bridgeElement->parameters) == 0) {
|
|
|
|
|
2015-11-11 22:45:24 +01:00
|
|
|
$card .= '<form method="GET" action="?">
|
2015-11-05 21:26:48 +01:00
|
|
|
<input type="hidden" name="action" value="display" />
|
|
|
|
<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
|
|
|
|
|
|
|
|
if ($isActive)
|
|
|
|
{
|
|
|
|
$card .= HTMLUtils::getHelperButtonsFormat($formats);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$card .= '<span style="font-weight: bold;">Inactive</span>';
|
|
|
|
}
|
|
|
|
$card .= '</form>' . PHP_EOL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($bridgeElement->parameters as $parameterName => $parameter)
|
|
|
|
{
|
|
|
|
if(!is_numeric($parameterName)) {
|
|
|
|
$card .= '<h5>'.$parameterName.'</h5>' . PHP_EOL;
|
|
|
|
}
|
2015-11-11 22:45:24 +01:00
|
|
|
$card .= '<form method="GET" action="?">
|
2015-11-05 21:26:48 +01:00
|
|
|
<input type="hidden" name="action" value="display" />
|
|
|
|
<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
|
|
|
|
|
|
|
|
$parameter = json_decode($parameter, true);
|
|
|
|
|
|
|
|
foreach($parameter as $inputEntry) {
|
|
|
|
|
2015-11-11 22:45:24 +01:00
|
|
|
$additionalInfoString = "";
|
|
|
|
if(isset($inputEntry['required'])) {
|
|
|
|
|
|
|
|
$additionalInfoString .= " required=\"required\"";
|
|
|
|
|
|
|
|
}
|
|
|
|
if(isset($inputEntry['pattern'])) {
|
|
|
|
|
|
|
|
$additionalInfoString .= " pattern=\"".$inputEntry['pattern']."\"";
|
|
|
|
|
|
|
|
}
|
2016-01-19 21:57:24 +01:00
|
|
|
if(isset($inputEntry['title'])) {
|
|
|
|
|
|
|
|
$additionalInfoString .= " title=\"" .$inputEntry['title']."\"";
|
|
|
|
|
|
|
|
}
|
2015-11-05 21:26:48 +01:00
|
|
|
if(!isset($inputEntry['exampleValue'])) $inputEntry['exampleValue'] = "";
|
|
|
|
|
2015-11-11 22:45:24 +01:00
|
|
|
$idArg = 'arg-' . urlencode($bridgeName) . '-' . urlencode($parameterName) . '-' . urlencode($inputEntry['identifier']);
|
2015-11-05 21:26:48 +01:00
|
|
|
|
|
|
|
$card .= '<label for="' .$idArg. '">' .$inputEntry['name']. ' : </label>' . PHP_EOL;
|
|
|
|
|
|
|
|
if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text') {
|
2015-11-11 22:45:24 +01:00
|
|
|
$card .= '<input '.$additionalInfoString.' id="' . $idArg . '" type="text" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
2015-11-05 21:26:48 +01:00
|
|
|
} else if($inputEntry['type'] == 'number') {
|
2015-11-11 22:45:24 +01:00
|
|
|
$card .= '<input '.$additionalInfoString.' id="' . $idArg . '" type="number" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
2015-11-05 21:26:48 +01:00
|
|
|
} else if($inputEntry['type'] == 'list') {
|
2015-11-27 15:20:33 +01:00
|
|
|
$card .= '<select '.$additionalInfoString.' id="' . $idArg . '" name="' . $inputEntry['identifier'] . '" >';
|
2015-11-05 21:26:48 +01:00
|
|
|
foreach($inputEntry['values'] as $listValues) {
|
|
|
|
|
2015-11-11 22:45:24 +01:00
|
|
|
$card .= "<option $additionalInfoString value='" . $listValues['value'] . "'>" . $listValues['name'] . "</option>";
|
2015-11-05 21:26:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
$card .= '</select><br >';
|
|
|
|
} else if($inputEntry['type'] == 'checkbox') {
|
|
|
|
|
|
|
|
$card .= '<input id="' . $idArg . '" type="checkbox" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($isActive)
|
|
|
|
{
|
|
|
|
$card .= HTMLUtils::getHelperButtonsFormat($formats);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$card .= '<span style="font-weight: bold;">Inactive</span>';
|
|
|
|
}
|
|
|
|
$card .= '</form>' . PHP_EOL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$card .= '<span class="maintainer">'.$bridgeElement->maintainer.'</span>';
|
|
|
|
$card .= '</section>';
|
|
|
|
|
|
|
|
return $card;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-11 22:45:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class HTMLSanitizer {
|
|
|
|
|
|
|
|
|
|
|
|
var $tagsToRemove;
|
|
|
|
var $keptAttributes;
|
|
|
|
var $onlyKeepText;
|
|
|
|
|
2015-12-06 18:49:41 +01:00
|
|
|
|
2015-12-06 18:47:20 +01:00
|
|
|
public static $DEFAULT_CLEAR_TAGS = ["script", "iframe"];
|
|
|
|
public static $KEPT_ATTRIBUTES = ["title", "href", "src"];
|
2015-11-11 22:45:24 +01:00
|
|
|
|
|
|
|
const ONLY_TEXT = null;
|
|
|
|
|
|
|
|
function __construct($tags_to_remove = HTMLSanitizer::DEFAULT_CLEAR_TAGS, $kept_attributes = HTMLSanitizer::KEPT_ATTRIBUTES, $only_keep_text = HTMLSanitizer::ONLY_TEXT) {
|
|
|
|
|
|
|
|
$this->tagsToRemove = $tags_to_remove;
|
|
|
|
$this->keptAttributes = $kept_attributes;
|
|
|
|
$this->onlyKeepText = $only_keep_text;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function sanitize($textToSanitize) {
|
|
|
|
|
|
|
|
$htmlContent = str_get_html($textToSanitize);
|
|
|
|
|
|
|
|
foreach($htmlContent->find('*[!j_ai_pas_trouve_comment_tout_demander]') as $element) {
|
|
|
|
if(in_array($element->tag, $this->onlyKeepText)) {
|
|
|
|
$element->outertext = $element->plaintext;
|
|
|
|
} else if(in_array($element->tag, $this->tagsToRemove)) {
|
|
|
|
$element->outertext = '';
|
|
|
|
} else {
|
|
|
|
foreach($element->getAllAttributes() as $attributeName => $attribute) {
|
|
|
|
if(!in_array($attributeName, $this->keptAttributes)) $element->removeAttribute($attributeName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $htmlContent;
|
|
|
|
|
|
|
|
}
|
2015-11-27 15:20:33 +01:00
|
|
|
public static function defaultImageSrcTo($content, $server) {
|
|
|
|
foreach($content->find('img') as $image) {
|
|
|
|
if(strpos($image->src, '/')==0) {
|
|
|
|
$image->src = $server.$image->src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-11 22:45:24 +01:00
|
|
|
|
2015-11-05 21:26:48 +01:00
|
|
|
}
|
|
|
|
?>
|