aboutsummaryrefslogtreecommitdiff
path: root/lib/BridgeCard.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/BridgeCard.php')
-rw-r--r--lib/BridgeCard.php177
1 files changed, 85 insertions, 92 deletions
diff --git a/lib/BridgeCard.php b/lib/BridgeCard.php
index dbb2a23d..900671ca 100644
--- a/lib/BridgeCard.php
+++ b/lib/BridgeCard.php
@@ -23,6 +23,90 @@
final class BridgeCard
{
/**
+ * Gets a single bridge card
+ *
+ * @param class-string<BridgeInterface> $bridgeClassName The bridge name
+ * @param array $formats A list of formats
+ * @param bool $isActive Indicates if the bridge is active or not
+ * @return string The bridge card
+ */
+ public static function displayBridgeCard($bridgeClassName, $formats, $isActive = true)
+ {
+ $bridgeFactory = new BridgeFactory();
+
+ $bridge = $bridgeFactory->create($bridgeClassName);
+
+ $isHttps = strpos($bridge->getURI(), 'https') === 0;
+
+ $uri = $bridge->getURI();
+ $name = $bridge->getName();
+ $icon = $bridge->getIcon();
+ $description = $bridge->getDescription();
+ $parameters = $bridge->getParameters();
+ if (Configuration::getConfig('proxy', 'url') && Configuration::getConfig('proxy', 'by_bridge')) {
+ $parameters['global']['_noproxy'] = [
+ 'name' => 'Disable proxy (' . (Configuration::getConfig('proxy', 'name') ?: Configuration::getConfig('proxy', 'url')) . ')',
+ 'type' => 'checkbox'
+ ];
+ }
+
+ if (CUSTOM_CACHE_TIMEOUT) {
+ $parameters['global']['_cache_timeout'] = [
+ 'name' => 'Cache timeout in seconds',
+ 'type' => 'number',
+ 'defaultValue' => $bridge->getCacheTimeout()
+ ];
+ }
+
+ $card = <<<CARD
+ <section id="bridge-{$bridgeClassName}" data-ref="{$name}">
+ <h2><a href="{$uri}">{$name}</a></h2>
+ <p class="description">{$description}</p>
+ <input type="checkbox" class="showmore-box" id="showmore-{$bridgeClassName}" />
+ <label class="showmore" for="showmore-{$bridgeClassName}">Show more</label>
+CARD;
+
+ // If we don't have any parameter for the bridge, we print a generic form to load it.
+ if (count($parameters) === 0) {
+ $card .= self::getForm($bridgeClassName, $formats, $isActive, $isHttps);
+
+ // Display form with cache timeout and/or noproxy options (if enabled) when bridge has no parameters
+ } elseif (count($parameters) === 1 && array_key_exists('global', $parameters)) {
+ $card .= self::getForm($bridgeClassName, $formats, $isActive, $isHttps, '', $parameters['global']);
+ } else {
+ foreach ($parameters as $parameterName => $parameter) {
+ if (!is_numeric($parameterName) && $parameterName === 'global') {
+ continue;
+ }
+
+ if (array_key_exists('global', $parameters)) {
+ $parameter = array_merge($parameter, $parameters['global']);
+ }
+
+ if (!is_numeric($parameterName)) {
+ $card .= '<h5>' . $parameterName . '</h5>' . PHP_EOL;
+ }
+
+ $card .= self::getForm($bridgeClassName, $formats, $isActive, $isHttps, $parameterName, $parameter);
+ }
+ }
+
+ $card .= sprintf('<label class="showless" for="showmore-%s">Show less</label>', $bridgeClassName);
+ if ($bridge->getDonationURI() !== '' && Configuration::getConfig('admin', 'donations')) {
+ $card .= sprintf(
+ '<p class="maintainer">%s ~ <a href="%s">Donate</a></p>',
+ $bridge->getMaintainer(),
+ $bridge->getDonationURI()
+ );
+ } else {
+ $card .= sprintf('<p class="maintainer">%s</p>', $bridge->getMaintainer());
+ }
+ $card .= '</section>';
+
+ return $card;
+ }
+
+ /**
* Get the form header for a bridge card
*
* @param class-string<BridgeInterface> $bridgeClassName The bridge name
@@ -38,9 +122,7 @@ final class BridgeCard
EOD;
if (!empty($parameterName)) {
- $form .= <<<EOD
- <input type="hidden" name="context" value="{$parameterName}" />
-EOD;
+ $form .= sprintf('<input type="hidden" name="context" value="%s" />', $parameterName);
}
if (!$isHttps) {
@@ -293,93 +375,4 @@ This bridge is not fetching its content through a secure connection</div>';
. ' />'
. PHP_EOL;
}
-
- /**
- * Gets a single bridge card
- *
- * @param class-string<BridgeInterface> $bridgeClassName The bridge name
- * @param array $formats A list of formats
- * @param bool $isActive Indicates if the bridge is active or not
- * @return string The bridge card
- */
- public static function displayBridgeCard($bridgeClassName, $formats, $isActive = true)
- {
- $bridgeFactory = new \BridgeFactory();
-
- $bridge = $bridgeFactory->create($bridgeClassName);
-
- if ($bridge == false) {
- return '';
- }
-
- $isHttps = strpos($bridge->getURI(), 'https') === 0;
-
- $uri = $bridge->getURI();
- $name = $bridge->getName();
- $icon = $bridge->getIcon();
- $description = $bridge->getDescription();
- $parameters = $bridge->getParameters();
- $donationUri = $bridge->getDonationURI();
- $maintainer = $bridge->getMaintainer();
-
- $donationsAllowed = Configuration::getConfig('admin', 'donations');
-
- if (Configuration::getConfig('proxy', 'url') && Configuration::getConfig('proxy', 'by_bridge')) {
- $parameters['global']['_noproxy'] = [
- 'name' => 'Disable proxy (' . (Configuration::getConfig('proxy', 'name') ?: Configuration::getConfig('proxy', 'url')) . ')',
- 'type' => 'checkbox'
- ];
- }
-
- if (CUSTOM_CACHE_TIMEOUT) {
- $parameters['global']['_cache_timeout'] = [
- 'name' => 'Cache timeout in seconds',
- 'type' => 'number',
- 'defaultValue' => $bridge->getCacheTimeout()
- ];
- }
-
- $card = <<<CARD
- <section id="bridge-{$bridgeClassName}" data-ref="{$name}">
- <h2><a href="{$uri}">{$name}</a></h2>
- <p class="description">{$description}</p>
- <input type="checkbox" class="showmore-box" id="showmore-{$bridgeClassName}" />
- <label class="showmore" for="showmore-{$bridgeClassName}">Show more</label>
-CARD;
-
- // If we don't have any parameter for the bridge, we print a generic form to load it.
- if (count($parameters) === 0) {
- $card .= self::getForm($bridgeClassName, $formats, $isActive, $isHttps);
-
- // Display form with cache timeout and/or noproxy options (if enabled) when bridge has no parameters
- } elseif (count($parameters) === 1 && array_key_exists('global', $parameters)) {
- $card .= self::getForm($bridgeClassName, $formats, $isActive, $isHttps, '', $parameters['global']);
- } else {
- foreach ($parameters as $parameterName => $parameter) {
- if (!is_numeric($parameterName) && $parameterName === 'global') {
- continue;
- }
-
- if (array_key_exists('global', $parameters)) {
- $parameter = array_merge($parameter, $parameters['global']);
- }
-
- if (!is_numeric($parameterName)) {
- $card .= '<h5>' . $parameterName . '</h5>' . PHP_EOL;
- }
-
- $card .= self::getForm($bridgeClassName, $formats, $isActive, $isHttps, $parameterName, $parameter);
- }
- }
-
- $card .= '<label class="showless" for="showmore-' . $bridgeClassName . '">Show less</label>';
- if ($donationUri !== '' && $donationsAllowed) {
- $card .= '<p class="maintainer">' . $maintainer . ' ~ <a href="' . $donationUri . '">Donate</a></p>';
- } else {
- $card .= '<p class="maintainer">' . $maintainer . '</p>';
- }
- $card .= '</section>';
-
- return $card;
- }
}