diff options
Diffstat (limited to 'lib/BridgeList.php')
-rw-r--r-- | lib/BridgeList.php | 275 |
1 files changed, 136 insertions, 139 deletions
diff --git a/lib/BridgeList.php b/lib/BridgeList.php index c5082e57..921dfe50 100644 --- a/lib/BridgeList.php +++ b/lib/BridgeList.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of RSS-Bridge, a PHP project capable of generating RSS and * Atom feeds for websites that don't have one. @@ -6,9 +7,9 @@ * For the full license information, please view the UNLICENSE file distributed * with this source code. * - * @package Core - * @license http://unlicense.org/ UNLICENSE - * @link https://github.com/rss-bridge/rss-bridge + * @package Core + * @license http://unlicense.org/ UNLICENSE + * @link https://github.com/rss-bridge/rss-bridge */ /** @@ -19,14 +20,16 @@ * * @todo Return error if a caller creates an object of this class. */ -final class BridgeList { - /** - * Get the document head - * - * @return string The document head - */ - private static function getHead() { - return <<<EOD +final class BridgeList +{ + /** + * Get the document head + * + * @return string The document head + */ + private static function getHead() + { + return <<<EOD <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> @@ -45,91 +48,87 @@ final class BridgeList { </noscript> </head> EOD; - } - - /** - * Get the document body for all bridge cards - * - * @param bool $showInactive Inactive bridges are visible on the home page if - * enabled. - * @param int $totalBridges (ref) Returns the total number of bridges. - * @param int $totalActiveBridges (ref) Returns the number of active bridges. - * @return string The document body for all bridge cards. - */ - private static function getBridges($showInactive, &$totalBridges, &$totalActiveBridges) { - - $body = ''; - $totalActiveBridges = 0; - $inactiveBridges = ''; - - $bridgeFac = new \BridgeFactory(); - $bridgeList = $bridgeFac->getBridgeNames(); - - $formatFac = new FormatFactory(); - $formats = $formatFac->getFormatNames(); - - $totalBridges = count($bridgeList); - - foreach($bridgeList as $bridgeName) { - - if($bridgeFac->isWhitelisted($bridgeName)) { - - $body .= BridgeCard::displayBridgeCard($bridgeName, $formats); - $totalActiveBridges++; - - } elseif($showInactive) { - - // inactive bridges - $inactiveBridges .= BridgeCard::displayBridgeCard($bridgeName, $formats, false) . PHP_EOL; - - } - - } - - $body .= $inactiveBridges; - - return $body; - } - - /** - * Get the document header - * - * @return string The document header - */ - private static function getHeader() { - $warning = ''; - - if(Debug::isEnabled()) { - if(!Debug::isSecure()) { - $warning .= <<<EOD + } + + /** + * Get the document body for all bridge cards + * + * @param bool $showInactive Inactive bridges are visible on the home page if + * enabled. + * @param int $totalBridges (ref) Returns the total number of bridges. + * @param int $totalActiveBridges (ref) Returns the number of active bridges. + * @return string The document body for all bridge cards. + */ + private static function getBridges($showInactive, &$totalBridges, &$totalActiveBridges) + { + $body = ''; + $totalActiveBridges = 0; + $inactiveBridges = ''; + + $bridgeFac = new \BridgeFactory(); + $bridgeList = $bridgeFac->getBridgeNames(); + + $formatFac = new FormatFactory(); + $formats = $formatFac->getFormatNames(); + + $totalBridges = count($bridgeList); + + foreach ($bridgeList as $bridgeName) { + if ($bridgeFac->isWhitelisted($bridgeName)) { + $body .= BridgeCard::displayBridgeCard($bridgeName, $formats); + $totalActiveBridges++; + } elseif ($showInactive) { + // inactive bridges + $inactiveBridges .= BridgeCard::displayBridgeCard($bridgeName, $formats, false) . PHP_EOL; + } + } + + $body .= $inactiveBridges; + + return $body; + } + + /** + * Get the document header + * + * @return string The document header + */ + private static function getHeader() + { + $warning = ''; + + if (Debug::isEnabled()) { + if (!Debug::isSecure()) { + $warning .= <<<EOD <section class="critical-warning">Warning : Debug mode is active from any location, make sure only you can access RSS-Bridge.</section> EOD; - } else { - $warning .= <<<EOD + } else { + $warning .= <<<EOD <section class="warning">Warning : Debug mode is active from your IP address, your requests will bypass the cache.</section> EOD; - } - } + } + } - return <<<EOD + return <<<EOD <header> <div class="logo"></div> {$warning} </header> EOD; - } - - /** - * Get the searchbar - * - * @return string The searchbar - */ - private static function getSearchbar() { - $query = filter_input(INPUT_GET, 'q', FILTER_SANITIZE_SPECIAL_CHARS); - - return <<<EOD + } + + /** + * Get the searchbar + * + * @return string The searchbar + */ + private static function getSearchbar() + { + $query = filter_input(INPUT_GET, 'q', FILTER_SANITIZE_SPECIAL_CHARS); + + return <<<EOD <section class="searchbar"> <h3>Search</h3> <input type="text" name="searchfield" @@ -137,46 +136,45 @@ EOD; onchange="search()" onkeyup="search()" value="{$query}"> </section> EOD; - } - - /** - * Get the document footer - * - * @param int $totalBridges The total number of bridges, shown in the footer - * @param int $totalActiveBridges The total number of active bridges, shown - * in the footer. - * @param bool $showInactive Sets the 'Show active'/'Show inactive' text in - * the footer. - * @return string The document footer - */ - private static function getFooter($totalBridges, $totalActiveBridges, $showInactive) { - $version = Configuration::getVersion(); - - $email = Configuration::getConfig('admin', 'email'); - $admininfo = ''; - if (!empty($email)) { - $admininfo = <<<EOD + } + + /** + * Get the document footer + * + * @param int $totalBridges The total number of bridges, shown in the footer + * @param int $totalActiveBridges The total number of active bridges, shown + * in the footer. + * @param bool $showInactive Sets the 'Show active'/'Show inactive' text in + * the footer. + * @return string The document footer + */ + private static function getFooter($totalBridges, $totalActiveBridges, $showInactive) + { + $version = Configuration::getVersion(); + + $email = Configuration::getConfig('admin', 'email'); + $admininfo = ''; + if (!empty($email)) { + $admininfo = <<<EOD <br /> <span> You may email the administrator of this RSS-Bridge instance at <a href="mailto:{$email}">{$email}</a> </span> EOD; - } + } - $inactive = ''; - - if($totalActiveBridges !== $totalBridges) { - - if(!$showInactive) { - $inactive = '<a href="?show_inactive=1"><button class="small">Show inactive bridges</button></a><br>'; - } else { - $inactive = '<a href="?show_inactive=0"><button class="small">Hide inactive bridges</button></a><br>'; - } + $inactive = ''; - } + if ($totalActiveBridges !== $totalBridges) { + if (!$showInactive) { + $inactive = '<a href="?show_inactive=1"><button class="small">Show inactive bridges</button></a><br>'; + } else { + $inactive = '<a href="?show_inactive=0"><button class="small">Hide inactive bridges</button></a><br>'; + } + } - return <<<EOD + return <<<EOD <section class="footer"> <a href="https://github.com/rss-bridge/rss-bridge">RSS-Bridge ~ Public Domain</a><br> <p class="version">{$version}</p> @@ -185,28 +183,27 @@ EOD; {$admininfo} </section> EOD; - } - - /** - * Create the entire home page - * - * @param bool $showInactive Inactive bridges are displayed on the home page, - * if enabled. - * @return string The home page - */ - public static function create($showInactive = true) { - - $totalBridges = 0; - $totalActiveBridges = 0; - - return '<!DOCTYPE html><html lang="en">' - . BridgeList::getHead() - . '<body onload="search()">' - . BridgeList::getHeader() - . BridgeList::getSearchbar() - . BridgeList::getBridges($showInactive, $totalBridges, $totalActiveBridges) - . BridgeList::getFooter($totalBridges, $totalActiveBridges, $showInactive) - . '</body></html>'; - - } + } + + /** + * Create the entire home page + * + * @param bool $showInactive Inactive bridges are displayed on the home page, + * if enabled. + * @return string The home page + */ + public static function create($showInactive = true) + { + $totalBridges = 0; + $totalActiveBridges = 0; + + return '<!DOCTYPE html><html lang="en">' + . BridgeList::getHead() + . '<body onload="search()">' + . BridgeList::getHeader() + . BridgeList::getSearchbar() + . BridgeList::getBridges($showInactive, $totalBridges, $totalActiveBridges) + . BridgeList::getFooter($totalBridges, $totalActiveBridges, $showInactive) + . '</body></html>'; + } } |