1
0
Fork 0
forked from blallo/rss-bridge

Merge pull request #174 from teromene/new-attribute-system

Le travail continue...
This commit is contained in:
Mitsu 2015-11-12 00:19:28 +01:00
commit 4c120cd831
7 changed files with 81 additions and 26 deletions

View file

@ -13,7 +13,8 @@ class FacebookBridge extends BridgeAbstract{
'[ '[
{ {
"name" : "Username", "name" : "Username",
"identifier" : "u" "identifier" : "u",
"required" : "required"
} }
]'; ]';
} }

View file

@ -31,7 +31,8 @@ class PickyWallpapersBridge extends BridgeAbstract {
{ {
"name" : "resolution", "name" : "resolution",
"identifier" : "r", "identifier" : "r",
"exampleValue" : "1920x1200, 1680x1050, ..." "exampleValue" : "1920x1200, 1680x1050, ...",
"pattern" : "[0-9]{3,4}x[0-9]{3,4}"
} }
]'; ]';

View file

@ -23,7 +23,8 @@ class YoutubeBridge extends BridgeAbstract {
"type" : "text", "type" : "text",
"identifier" : "u", "identifier" : "u",
"name" : "username", "name" : "username",
"exampleValue" : "test" "exampleValue" : "test",
"required" : "required"
} }
]'; ]';
@ -33,7 +34,8 @@ class YoutubeBridge extends BridgeAbstract {
"type" : "number", "type" : "number",
"identifier" : "c", "identifier" : "c",
"name" : "channel id", "name" : "channel id",
"exampleValue" : "15" "exampleValue" : "15",
"required" : "required"
} }
]'; ]';

View file

@ -131,9 +131,6 @@ $formats = Format::searchInformation();
<meta name="description" content="Rss-bridge" /> <meta name="description" content="Rss-bridge" />
<title>RSS-Bridge</title> <title>RSS-Bridge</title>
<link href="css/style.css" rel="stylesheet"> <link href="css/style.css" rel="stylesheet">
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head> </head>
<body> <body>
@ -152,7 +149,7 @@ $formats = Format::searchInformation();
if(Bridge::isWhitelisted($whitelist_selection, $bridgeName)) if(Bridge::isWhitelisted($whitelist_selection, $bridgeName))
{ {
echo HTMLUtils::displayBridgeCard($bridgeName, $formats); echo HTMLUtils::displayBridgeCard($bridgeName, $formats);
$activeFoundBridgeCount++; $activeFoundBridgeCount++;
} }
elseif ($showInactive) elseif ($showInactive)
{ {

View file

@ -279,15 +279,16 @@ class Bridge{
*/ */
static public function listBridges() { static public function listBridges() {
$pathDirBridge = self::getDir(); $pathDirBridge = self::getDir();
$listBridge = array(); $listBridge = array();
$dirFiles = scandir($pathDirBridge); $dirFiles = scandir($pathDirBridge);
if( $dirFiles !== false ){ if( $dirFiles !== false ){
foreach( $dirFiles as $fileName ){
if( preg_match('@([^.]+)\.php@U', $fileName, $out) ){ foreach( $dirFiles as $fileName ) {
$listBridge[] = $out[1]; if( preg_match('@([^.]+)\.php$@U', $fileName, $out) ){
} $listBridge[] = $out[1];
}
} }
} }

View file

@ -20,7 +20,6 @@ class HTMLUtils {
public static function displayBridgeCard($bridgeName, $formats, $isActive = true) public static function displayBridgeCard($bridgeName, $formats, $isActive = true)
{ {
$bridgeElement = Bridge::create($bridgeName); $bridgeElement = Bridge::create($bridgeName);
if($bridgeElement == false) { if($bridgeElement == false) {
return ""; return "";
@ -41,7 +40,7 @@ CARD;
// If we don't have any parameter for the bridge, we print a generic form to load it. // If we don't have any parameter for the bridge, we print a generic form to load it.
if(count($bridgeElement->parameters) == 0) { if(count($bridgeElement->parameters) == 0) {
$card .= '<form method="POST" action="?"> $card .= '<form method="GET" action="?">
<input type="hidden" name="action" value="display" /> <input type="hidden" name="action" value="display" />
<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL; <input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
@ -59,11 +58,10 @@ CARD;
foreach($bridgeElement->parameters as $parameterName => $parameter) foreach($bridgeElement->parameters as $parameterName => $parameter)
{ {
$card .= '<ol class="list-use">' . PHP_EOL;
if(!is_numeric($parameterName)) { if(!is_numeric($parameterName)) {
$card .= '<h5>'.$parameterName.'</h5>' . PHP_EOL; $card .= '<h5>'.$parameterName.'</h5>' . PHP_EOL;
} }
$card .= '<form method="POST" action="?"> $card .= '<form method="GET" action="?">
<input type="hidden" name="action" value="display" /> <input type="hidden" name="action" value="display" />
<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL; <input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
@ -71,21 +69,32 @@ CARD;
foreach($parameter as $inputEntry) { foreach($parameter as $inputEntry) {
$additionalInfoString = "";
if(isset($inputEntry['required'])) {
$additionalInfoString .= " required=\"required\"";
}
if(isset($inputEntry['pattern'])) {
$additionalInfoString .= " pattern=\"".$inputEntry['pattern']."\"";
}
if(!isset($inputEntry['exampleValue'])) $inputEntry['exampleValue'] = ""; if(!isset($inputEntry['exampleValue'])) $inputEntry['exampleValue'] = "";
$idArg = 'arg-' . $bridgeName . '-' . $parameterName . '-' . $inputEntry['identifier']; $idArg = 'arg-' . urlencode($bridgeName) . '-' . urlencode($parameterName) . '-' . urlencode($inputEntry['identifier']);
$card .= '<label for="' .$idArg. '">' .$inputEntry['name']. ' : </label>' . PHP_EOL; $card .= '<label for="' .$idArg. '">' .$inputEntry['name']. ' : </label>' . PHP_EOL;
if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text') { if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text') {
$card .= '<input id="' . $idArg . '" type="text" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL; $card .= '<input '.$additionalInfoString.' id="' . $idArg . '" type="text" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
} else if($inputEntry['type'] == 'number') { } else if($inputEntry['type'] == 'number') {
$card .= '<input id="' . $idArg . '" type="number" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL; $card .= '<input '.$additionalInfoString.' id="' . $idArg . '" type="number" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
} else if($inputEntry['type'] == 'list') { } else if($inputEntry['type'] == 'list') {
$card .= '<select id="' . $idArg . '" name="' . $inputEntry['name'] . '" >'; $card .= '<select '.$additionalInfoString.' id="' . $idArg . '" name="' . $inputEntry['name'] . '" >';
foreach($inputEntry['values'] as $listValues) { foreach($inputEntry['values'] as $listValues) {
$card .= "<option value='" . $listValues['value'] . "'>" . $listValues['name'] . "</option>"; $card .= "<option $additionalInfoString value='" . $listValues['value'] . "'>" . $listValues['name'] . "</option>";
} }
$card .= '</select><br >'; $card .= '</select><br >';
@ -115,5 +124,49 @@ CARD;
} }
}
class HTMLSanitizer {
var $tagsToRemove;
var $keptAttributes;
var $onlyKeepText;
const DEFAULT_CLEAR_TAGS = ["script", "iframe"];
const KEPT_ATTRIBUTES = ["title", "href", "src"];
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;
}
} }
?> ?>