From 4f75591060d95208a301bc6bf460d875631b29cc Mon Sep 17 00:00:00 2001 From: Dag Date: Fri, 1 Jul 2022 15:10:30 +0200 Subject: Reformat codebase v4 (#2872) Reformat code base to PSR12 Co-authored-by: rssbridge --- lib/BridgeCard.php | 682 +++++++++++++++++++++++++++-------------------------- 1 file changed, 350 insertions(+), 332 deletions(-) (limited to 'lib/BridgeCard.php') diff --git a/lib/BridgeCard.php b/lib/BridgeCard.php index 22520170..78132776 100644 --- a/lib/BridgeCard.php +++ b/lib/BridgeCard.php @@ -1,4 +1,5 @@ EOD; - if(!empty($parameterName)) { - $form .= << EOD; - } + } - if(!$isHttps) { - $form .= '
Warning : + if (!$isHttps) { + $form .= '
Warning : This bridge is not fetching its content through a secure connection
'; - } - - return $form; - } - - /** - * Get the form body for a bridge - * - * @param string $bridgeName The bridge name - * @param array $formats A list of supported formats - * @param bool $isActive Indicates if a bridge is enabled or not - * @param bool $isHttps Indicates if a bridge uses HTTPS or not - * @param string $parameterName Sets the bridge context for the current form - * @param array $parameters The bridge parameters - * @return string The form body - */ - private static function getForm($bridgeName, - $formats, - $isActive = false, - $isHttps = false, - $parameterName = '', - $parameters = array()) { - $form = self::getFormHeader($bridgeName, $isHttps, $parameterName); - - if(count($parameters) > 0) { - - $form .= '
'; - - foreach($parameters as $id => $inputEntry) { - if(!isset($inputEntry['exampleValue'])) - $inputEntry['exampleValue'] = ''; - - if(!isset($inputEntry['defaultValue'])) - $inputEntry['defaultValue'] = ''; - - $idArg = 'arg-' - . urlencode($bridgeName) - . '-' - . urlencode($parameterName) - . '-' - . urlencode($id); - - $form .= '' - . PHP_EOL; - - if(!isset($inputEntry['type']) || $inputEntry['type'] === 'text') { - $form .= self::getTextInput($inputEntry, $idArg, $id); - } elseif($inputEntry['type'] === 'number') { - $form .= self::getNumberInput($inputEntry, $idArg, $id); - } else if($inputEntry['type'] === 'list') { - $form .= self::getListInput($inputEntry, $idArg, $id); - } elseif($inputEntry['type'] === 'checkbox') { - $form .= self::getCheckboxInput($inputEntry, $idArg, $id); - } - - if(isset($inputEntry['title'])) { - $title_filtered = filter_var($inputEntry['title'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); - $form .= 'i'; - } else { - $form .= ''; - } - } - - $form .= '
'; - - } - - if($isActive) { - $form .= ''; - } else { - $form .= 'Inactive'; - } - - return $form . '' . PHP_EOL; - } - - /** - * Get input field attributes - * - * @param array $entry The current entry - * @return string The input field attributes - */ - private static function getInputAttributes($entry) { - $retVal = ''; - - if(isset($entry['required']) && $entry['required'] === true) - $retVal .= ' required'; - - if(isset($entry['pattern'])) - $retVal .= ' pattern="' . $entry['pattern'] . '"'; - - return $retVal; - } - - /** - * Get text input - * - * @param array $entry The current entry - * @param string $id The field ID - * @param string $name The field name - * @return string The text input field - */ - private static function getTextInput($entry, $id, $name) { - return '' - . PHP_EOL; - } - - /** - * Get number input - * - * @param array $entry The current entry - * @param string $id The field ID - * @param string $name The field name - * @return string The number input field - */ - private static function getNumberInput($entry, $id, $name) { - return '' - . PHP_EOL; - } - - /** - * Get list input - * - * @param array $entry The current entry - * @param string $id The field ID - * @param string $name The field name - * @return string The list input field - */ - private static function getListInput($entry, $id, $name) { - if(isset($entry['required']) && $entry['required'] === true) { - Debug::log('The "required" attribute is not supported for lists.'); - unset($entry['required']); - } - - $list = ''; - - return $list; - } - - /** - * Get checkbox input - * - * @param array $entry The current entry - * @param string $id The field ID - * @param string $name The field name - * @return string The checkbox input field - */ - private static function getCheckboxInput($entry, $id, $name) { - if(isset($entry['required']) && $entry['required'] === true) { - Debug::log('The "required" attribute is not supported for checkboxes.'); - unset($entry['required']); - } - - return '' - . PHP_EOL; - } - - /** - * Gets a single bridge card - * - * @param string $bridgeName 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($bridgeName, $formats, $isActive = true){ - - $bridgeFac = new \BridgeFactory(); - - $bridge = $bridgeFac->create($bridgeName); - - 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(defined('PROXY_URL') && PROXY_BYBRIDGE) { - $parameters['global']['_noproxy'] = array( - 'name' => 'Disable proxy (' . ((defined('PROXY_NAME') && PROXY_NAME) ? PROXY_NAME : PROXY_URL) . ')', - 'type' => 'checkbox' - ); - } - - if(CUSTOM_CACHE_TIMEOUT) { - $parameters['global']['_cache_timeout'] = array( - 'name' => 'Cache timeout in seconds', - 'type' => 'number', - 'defaultValue' => $bridge->getCacheTimeout() - ); - } - - $card = << 0) { + $form .= '
'; + + foreach ($parameters as $id => $inputEntry) { + if (!isset($inputEntry['exampleValue'])) { + $inputEntry['exampleValue'] = ''; + } + + if (!isset($inputEntry['defaultValue'])) { + $inputEntry['defaultValue'] = ''; + } + + $idArg = 'arg-' + . urlencode($bridgeName) + . '-' + . urlencode($parameterName) + . '-' + . urlencode($id); + + $form .= '' + . PHP_EOL; + + if (!isset($inputEntry['type']) || $inputEntry['type'] === 'text') { + $form .= self::getTextInput($inputEntry, $idArg, $id); + } elseif ($inputEntry['type'] === 'number') { + $form .= self::getNumberInput($inputEntry, $idArg, $id); + } elseif ($inputEntry['type'] === 'list') { + $form .= self::getListInput($inputEntry, $idArg, $id); + } elseif ($inputEntry['type'] === 'checkbox') { + $form .= self::getCheckboxInput($inputEntry, $idArg, $id); + } + + if (isset($inputEntry['title'])) { + $title_filtered = filter_var($inputEntry['title'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); + $form .= 'i'; + } else { + $form .= ''; + } + } + + $form .= '
'; + } + + if ($isActive) { + $form .= ''; + } else { + $form .= 'Inactive'; + } + + return $form . '' . PHP_EOL; + } + + /** + * Get input field attributes + * + * @param array $entry The current entry + * @return string The input field attributes + */ + private static function getInputAttributes($entry) + { + $retVal = ''; + + if (isset($entry['required']) && $entry['required'] === true) { + $retVal .= ' required'; + } + + if (isset($entry['pattern'])) { + $retVal .= ' pattern="' . $entry['pattern'] . '"'; + } + + return $retVal; + } + + /** + * Get text input + * + * @param array $entry The current entry + * @param string $id The field ID + * @param string $name The field name + * @return string The text input field + */ + private static function getTextInput($entry, $id, $name) + { + return '' + . PHP_EOL; + } + + /** + * Get number input + * + * @param array $entry The current entry + * @param string $id The field ID + * @param string $name The field name + * @return string The number input field + */ + private static function getNumberInput($entry, $id, $name) + { + return '' + . PHP_EOL; + } + + /** + * Get list input + * + * @param array $entry The current entry + * @param string $id The field ID + * @param string $name The field name + * @return string The list input field + */ + private static function getListInput($entry, $id, $name) + { + if (isset($entry['required']) && $entry['required'] === true) { + Debug::log('The "required" attribute is not supported for lists.'); + unset($entry['required']); + } + + $list = ''; + + return $list; + } + + /** + * Get checkbox input + * + * @param array $entry The current entry + * @param string $id The field ID + * @param string $name The field name + * @return string The checkbox input field + */ + private static function getCheckboxInput($entry, $id, $name) + { + if (isset($entry['required']) && $entry['required'] === true) { + Debug::log('The "required" attribute is not supported for checkboxes.'); + unset($entry['required']); + } + + return '' + . PHP_EOL; + } + + /** + * Gets a single bridge card + * + * @param string $bridgeName 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($bridgeName, $formats, $isActive = true) + { + $bridgeFac = new \BridgeFactory(); + + $bridge = $bridgeFac->create($bridgeName); + + 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 (defined('PROXY_URL') && PROXY_BYBRIDGE) { + $parameters['global']['_noproxy'] = [ + 'name' => 'Disable proxy (' . ((defined('PROXY_NAME') && PROXY_NAME) ? PROXY_NAME : PROXY_URL) . ')', + 'type' => 'checkbox' + ]; + } + + if (CUSTOM_CACHE_TIMEOUT) { + $parameters['global']['_cache_timeout'] = [ + 'name' => 'Cache timeout in seconds', + 'type' => 'number', + 'defaultValue' => $bridge->getCacheTimeout() + ]; + } + + $card = <<

{$name}

{$description}

@@ -330,38 +347,39 @@ This bridge is not fetching its content through a secure connection
'; 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($bridgeName, $formats, $isActive, $isHttps); - - // Display form with cache timeout and/or noproxy options (if enabled) when bridge has no parameters - } else if (count($parameters) === 1 && array_key_exists('global', $parameters)) { - $card .= self::getForm($bridgeName, $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 .= '
' . $parameterName . '
' . PHP_EOL; - - $card .= self::getForm($bridgeName, $formats, $isActive, $isHttps, $parameterName, $parameter); - } - - } - - $card .= ''; - if($donationUri !== '' && $donationsAllowed) { - $card .= '

' . $maintainer . ' ~ Donate

'; - } else { - $card .= '

' . $maintainer . '

'; - } - $card .= ''; - - return $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($bridgeName, $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($bridgeName, $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 .= '
' . $parameterName . '
' . PHP_EOL; + } + + $card .= self::getForm($bridgeName, $formats, $isActive, $isHttps, $parameterName, $parameter); + } + } + + $card .= ''; + if ($donationUri !== '' && $donationsAllowed) { + $card .= '

' . $maintainer . ' ~ Donate

'; + } else { + $card .= '

' . $maintainer . '

'; + } + $card .= ''; + + return $card; + } } -- cgit v1.2.3