bridges = array(); $list->total = 0; foreach(Bridge::listBridges() as $bridgeName) { $bridge = Bridge::create($bridgeName); if($bridge === false) { // Broken bridge, show as inactive $list->bridges[$bridgeName] = array( 'status' => 'inactive' ); continue; } $status = Bridge::isWhitelisted($whitelist_selection, strtolower($bridgeName)) ? 'active' : 'inactive'; $list->bridges[$bridgeName] = array( 'status' => $status, 'uri' => $bridge->getURI(), 'name' => $bridge->getName(), 'parameters' => $bridge->getParameters(), 'maintainer' => $bridge->getMaintainer(), 'description' => $bridge->getDescription() ); } $list->total = count($list->bridges); header('Content-Type: application/json'); echo json_encode($list, JSON_PRETTY_PRINT); } elseif($action === 'display' && !empty($bridge)) { // DEPRECATED: 'nameBridge' scheme is replaced by 'name' in bridge parameter values // this is to keep compatibility until futher complete removal if(($pos = strpos($bridge, 'Bridge')) === (strlen($bridge) - strlen('Bridge'))) { $bridge = substr($bridge, 0, $pos); } $format = $params['format'] or returnClientError('You must specify a format!'); // DEPRECATED: 'nameFormat' scheme is replaced by 'name' in format parameter values // this is to keep compatibility until futher complete removal if(($pos = strpos($format, 'Format')) === (strlen($format) - strlen('Format'))) { $format = substr($format, 0, $pos); } // whitelist control if(!Bridge::isWhitelisted($whitelist_selection, strtolower($bridge))) { throw new \HttpException('This bridge is not whitelisted', 401); die; } // Data retrieval $bridge = Bridge::create($bridge); $noproxy = array_key_exists('_noproxy', $params) && filter_var($params['_noproxy'], FILTER_VALIDATE_BOOLEAN); if(defined('PROXY_URL') && PROXY_BYBRIDGE && $noproxy) { define('NOPROXY', true); } // Custom cache timeout $cache_timeout = -1; if(array_key_exists('_cache_timeout', $params)) { if(!CUSTOM_CACHE_TIMEOUT) { throw new \HttpException('This server doesn\'t support "_cache_timeout"!'); } $cache_timeout = filter_var($params['_cache_timeout'], FILTER_VALIDATE_INT); } // Initialize cache $cache = Cache::create('FileCache'); $cache->setPath(CACHE_DIR); $cache->purgeCache(86400); // 24 hours $cache->setParameters($params); unset($params['action']); unset($params['bridge']); unset($params['format']); unset($params['_noproxy']); unset($params['_cache_timeout']); // Load cache & data try { $bridge->setCache($cache); $bridge->setCacheTimeout($cache_timeout); $bridge->setDatas($params); } catch(Error $e) { http_response_code($e->getCode()); header('Content-Type: text/html'); die(buildBridgeException($e, $bridge)); } catch(Exception $e) { http_response_code($e->getCode()); header('Content-Type: text/html'); die(buildBridgeException($e, $bridge)); } // Data transformation try { $format = Format::create($format); $format->setItems($bridge->getItems()); $format->setExtraInfos($bridge->getExtraInfos()); $format->display(); } catch(Error $e) { http_response_code($e->getCode()); header('Content-Type: text/html'); die(buildTransformException($e, $bridge)); } catch(Exception $e) { http_response_code($e->getCode()); header('Content-Type: text/html'); die(buildBridgeException($e, $bridge)); } } else { echo BridgeList::create($whitelist_selection, $showInactive); } } catch(HttpException $e) { http_response_code($e->getCode()); header('Content-Type: text/plain'); die($e->getMessage()); } catch(\Exception $e) { die($e->getMessage()); }