Esempio n. 1
0
        switch ($_REQUEST['action']) {
            case 'display':
                if (isset($_REQUEST['bridge'])) {
                    unset($_REQUEST['action']);
                    $bridge = $_REQUEST['bridge'];
                    unset($_REQUEST['bridge']);
                    $format = $_REQUEST['format'];
                    unset($_REQUEST['format']);
                    // whitelist control
                    if (!BridgeWhitelist($whitelist_selection, $bridge)) {
                        throw new \HttpException('This bridge is not whitelisted', 401);
                        die;
                    }
                    $cache = Cache::create('FileCache');
                    // Data retrieval
                    $bridge = Bridge::create($bridge);
                    if (isset($_REQUEST["disable_cache"])) {
                    } else {
                        $bridge->setCache($cache);
                        // just add disable cache to your query to disable caching
                    }
                    $bridge->setDatas($_REQUEST);
                    // Data transformation
                    $format = Format::create($format);
                    $format->setDatas($bridge->getDatas())->setExtraInfos(array('name' => $bridge->getName(), 'uri' => $bridge->getURI()))->display();
                    die;
                }
                break;
        }
    }
} catch (HttpException $e) {
Esempio n. 2
0
    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
\t\t<section id="bridge-{$bridgeName}" data-ref="{$bridgeName}">
\t\t\t<h2>{$name}</h2>
\t\t\t<p class="description">
\t\t\t\t{$description}
\t\t\t</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) {
            $card .= '<form method="GET" action="?">
					<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;
        }
        $hasGlobalParameter = array_key_exists("global", $bridgeElement->parameters);
        if ($hasGlobalParameter) {
            $globalParameters = json_decode($bridgeElement->parameters['global'], true);
        }
        foreach ($bridgeElement->parameters as $parameterName => $parameter) {
            $parameter = json_decode($parameter, true);
            if (!is_numeric($parameterName) && $parameterName == "global") {
                continue;
            }
            if ($hasGlobalParameter) {
                $parameter = array_merge($parameter, $globalParameters);
            }
            if (!is_numeric($parameterName)) {
                $card .= '<h5>' . $parameterName . '</h5>' . PHP_EOL;
            }
            $card .= '<form method="GET" action="?">
						<input type="hidden" name="action" value="display" />
						<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
            foreach ($parameter as $inputEntry) {
                $additionalInfoString = "";
                if (isset($inputEntry['required'])) {
                    $additionalInfoString .= " required=\"required\"";
                }
                if (isset($inputEntry['pattern'])) {
                    $additionalInfoString .= " pattern=\"" . $inputEntry['pattern'] . "\"";
                }
                if (isset($inputEntry['title'])) {
                    $additionalInfoString .= " title=\"" . $inputEntry['title'] . "\"";
                }
                if (!isset($inputEntry['exampleValue'])) {
                    $inputEntry['exampleValue'] = "";
                }
                $idArg = 'arg-' . urlencode($bridgeName) . '-' . urlencode($parameterName) . '-' . urlencode($inputEntry['identifier']);
                $card .= '<label for="' . $idArg . '">' . $inputEntry['name'] . ' : </label>' . PHP_EOL;
                if (!isset($inputEntry['type']) || $inputEntry['type'] == 'text') {
                    $card .= '<input ' . $additionalInfoString . ' id="' . $idArg . '" type="text" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
                } else {
                    if ($inputEntry['type'] == 'number') {
                        $card .= '<input ' . $additionalInfoString . ' id="' . $idArg . '" type="number" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
                    } else {
                        if ($inputEntry['type'] == 'list') {
                            $card .= '<select ' . $additionalInfoString . ' id="' . $idArg . '" name="' . $inputEntry['identifier'] . '" >';
                            foreach ($inputEntry['values'] as $listValues) {
                                $card .= "<option {$additionalInfoString} value='" . $listValues['value'] . "'>" . $listValues['name'] . "</option>";
                            }
                            $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;
    }