diff --git a/CREATE_BRIDGE.md b/CREATE_BRIDGE.md new file mode 100644 index 00000000..215ae282 --- /dev/null +++ b/CREATE_BRIDGE.md @@ -0,0 +1,23 @@ +# Howto create a bridge + +A bridge is an interface that allows rss-bridge to create a RSS feed from a website. +The bridge is a PHP file, located in the `bridges/` folder. + +##Specifications + +A rss bridge must extend the `BridgeAbstract` class, and implement the following functions : + +* The `loadMetadatas` function, described below, +* The `getCacheDuration` function, describing the time during which rss-bridge will output cached values instead of re-generating a RSS feed. +* The `collectData` function, also described below. + +##The `collectData` function + +This function takes as a parameter an array called `$param`, that is automatically filled with values from the user, according to the values setted in `loadMetadatas`. +This function is the place where all the website scrapping and the RSS feed generation process will go. + +The RSS elements are stored in the class variable `items[]`. + +Every RSS element is an instance of the `Item` class. + + diff --git a/bridges/AcrimedBridge.php b/bridges/AcrimedBridge.php index 97a2e4a7..d50a0d66 100644 --- a/bridges/AcrimedBridge.php +++ b/bridges/AcrimedBridge.php @@ -1,6 +1,6 @@ maintainer = "qwertygc"; + $this->name = "Acrimed Bridge"; + $this->uri = "http://www.acrimed.org/"; + $this->description = "Returns the newest articles."; + $this->update = "2014-05-25"; + + } + public function collectData(array $param){ function StripCDATA($string) { $string = str_replace('maintainer = "mitsukarenai"; + $this->name = "Arte +7"; + $this->uri = "http://www.arte.tv/"; + $this->description = "Returns newest videos from ARTE +7"; + $this->update = "2015-10-31"; + $this->parameters["Catégorie (Français)"] = + '[ + { + "type" : "list", + "identifier" : "catfr", + "name" : "Catégorie", + "values" : [ + { + "name" : "Toutes les vidéos (français)", + "value" : "toutes-les-videos" + }, + { + "name" : "Actu & société", + "value" : "actu-société" + }, + { + "name" : "Séries & fiction", + "value" : "séries-fiction" + }, + { + "name" : "Cinéma", + "value" : "cinéma" + } + + ] + + + } + + ]'; + } + + public function collectData(array $param){ function extractVideoset($category='toutes-les-videos', $lang='fr') diff --git a/bridges/DemoBridge.php b/bridges/DemoBridge.php new file mode 100644 index 00000000..df38be6b --- /dev/null +++ b/bridges/DemoBridge.php @@ -0,0 +1,72 @@ +maintainer = "teromene"; + $this->name = "DemoBridge"; + $this->uri = "http://github.com/sebsauvage/rss-bridge"; + $this->description = "Bridge used for demos"; + $this->update = "2015-11-03"; + + $this->parameters['testCheckbox'] = + '[ + { + "type" : "checkbox", + "identifier" : "testCheckbox", + "name" : "test des checkbox" + } + + ]'; + + $this->parameters['testList'] = + '[ + { + "type" : "list", + "identifier" : "testList", + "name" : "test des listes", + "values" : [ + { + "name" : "Test", + "value" : "test" + }, + { + "name" : "Test 2", + "value" : "test2" + } + ] + } + ]'; + $this->parameters['testNumber'] = + '[ + { + "type" : "number", + "identifier" : "testNumber", + "name" : "test des numéros", + "exampleValue" : "1515632" + + } + + ]'; + + } + + public function collectData(array $param){ + + } + + public function getCacheDuration(){ + return 3600; // 1 hour + } +} diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index 15f648ca..dc37d5ec 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -9,7 +9,7 @@ */ class FacebookBridge extends BridgeAbstract{ - private $name; + public function collectData(array $param){ diff --git a/index.php b/index.php index 72ee5851..bb062599 100644 --- a/index.php +++ b/index.php @@ -114,14 +114,14 @@ try{ $bridge->setCache($cache); // just add disable cache to your query to disable caching } $bridge->setDatas($_REQUEST); - + $bridge->loadMetadatas(); // Data transformation $format = Format::create($format); $format ->setDatas($bridge->getDatas()) ->setExtraInfos(array( - 'name' => $bridge->getName(), - 'uri' => $bridge->getURI(), + 'name' => $bridge->name, + 'uri' => $bridge->uri, )) ->display(); die; @@ -161,7 +161,7 @@ function displayBridgeCard($bridgeName, $formats, $isActive = true) $bridgeElement = Bridge::create($bridgeName); $bridgeElement->loadMetadatas(); - $name = ''.$bridgeElement->name.''; + $name = ''.$bridgeElement->name.''; $description = $bridgeElement->description; $card = <<parameters) == 0) { - $card .= '
+ $card .= ' ' . PHP_EOL; @@ -195,7 +195,7 @@ CARD; { $card .= '
    ' . PHP_EOL; $card .= '
    '.$parameterName.'
    ' . PHP_EOL; - $card .= ' + $card .= ' ' . PHP_EOL; @@ -211,6 +211,18 @@ CARD; $card .= '
    ' . PHP_EOL; } else if($inputEntry['type'] == 'number') { $card .= '
    ' . PHP_EOL; + } else if($inputEntry['type'] == 'list') { + $card .= '
    '; + } else if($inputEntry['type'] == 'checkbox') { + + $card .= '
    ' . PHP_EOL; + } } @@ -258,7 +270,7 @@ $formats = Format::searchInformation(); $activeFoundBridgeCount = 0; $showInactive = isset($_REQUEST['show_inactive']) && $_REQUEST['show_inactive'] == 1; $inactiveBridges = ''; - foreach($whitelist_selection as $bridgeName) + foreach(Bridge::listBridges() as $bridgeName) { if(BridgeWhitelist($whitelist_selection, $bridgeName)) { diff --git a/lib/Bridge.php b/lib/Bridge.php index e0632778..29ac6d2a 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -6,8 +6,6 @@ interface BridgeInterface{ public function collectData(array $param); - public function getName(); - public function getURI(); public function getCacheDuration(); public function loadMetadatas(); } @@ -18,7 +16,7 @@ abstract class BridgeAbstract implements BridgeInterface{ protected $items = array(); public $name = "Bridge sans nom"; - public $homepage = ""; + public $uri = ""; public $description = 'No description provided'; public $maintainer = 'No maintainer'; public $parameters = array(); @@ -257,74 +255,25 @@ class Bridge{ } /** - * Read bridge dir and catch informations about each bridge depending annotation - * @return array Informations about each bridge + * Lists the available bridges. + * @return array List of the bridges */ - static public function searchInformation(){ + static public function listBridges() { + $pathDirBridge = self::getDir(); - $listBridge = array(); + $dirFiles = scandir($pathDirBridge); - $searchCommonPattern = array('maintainer', 'description', 'homepage', 'name'); - - $dirFiles = scandir($pathDirBridge); if( $dirFiles !== false ){ foreach( $dirFiles as $fileName ){ - if( preg_match('@([^.]+)\.php@U', $fileName, $out) ){ // Is PHP file ? - $infos = array(); // Information about the bridge - $resParse = token_get_all(file_get_contents($pathDirBridge . $fileName)); // Parse PHP file - foreach($resParse as $v){ - if( is_array($v) && $v[0] == T_DOC_COMMENT ){ // Lexer node is COMMENT ? - $commentary = $v[1]; - foreach( $searchCommonPattern as $name){ // Catch information with common pattern - preg_match('#@' . preg_quote($name, '#') . '\s+(.+)#', $commentary, $outComment); - if( isset($outComment[1]) ){ - $infos[$name] = $outComment[1]; - } - } + if( preg_match('@([^.]+)\.php@U', $fileName, $out) ){ + $listBridge[] = $out[1]; + } + } + } - preg_match_all('#@use(?[1-9][0-9]*)\s?\((?.+)\)(?:\r|\n)#', $commentary, $outComment); // Catch specific information about "use". + return $listBridge; + } - if( isset($outComment['args']) && is_array($outComment['args']) ){ - $infos['use'] = array(); - - foreach($outComment['args'] as $num => $args){ // Each use - - preg_match_all('#(?[a-z]+)\|(?[a-z]+)="(?.*)"(?:,|$)#U', $args, $outArg); // Catch arguments for current use - - if(!isset($outArg['name']) || count($outArg['name']) == 0) { - preg_match_all('#(?[a-z]+)="(?.*)"(?:,|$)#U', $args, $outArg); // Catch arguments - } - - - if( isset($outArg['name'])){ - $usePos = $outComment['num'][$num]; // Current use name - if( !isset($infos['use'][$usePos]) ){ // Not information actually for this "use" ? - $infos['use'][$usePos] = array(); - } - - foreach($outArg['name'] as $numArg => $name){ // Each arguments - $infos['use'][$usePos][$name] = array(); - - $infos['use'][$usePos][$name]['query-name'] = $name; - $infos['use'][$usePos][$name]['value'] = $outArg['value'][$numArg]; - $infos['use'][$usePos][$name]['type'] = $outArg['type'][$numArg]; - - } - } - } - } - } - } - - if( isset($infos['name']) ){ // If informations containt at least a name - $listBridge[$out[1]] = $infos; - } - } - } - } - - return $listBridge; - } }