1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-05 08:07:33 +02:00

[BridgeAbstract] Update constant definition

LogMANOriginal
2016-09-09 13:09:21 +02:00
parent ecd21a22c6
commit 8d7e8fbbd6

@@ -1,8 +1,7 @@
`BridgeAbstract` is a base class intended for standard Bridges that need to filter HTML pages for content.
To create a new Bridge extending `BridgeAbstract` you must implement following functions:
To create a new Bridge extending `BridgeAbstract` you must specify some [basic metadata](#basic-metadata) implement following functions:
- [`loadMetadatas`](#the-loadmetadatas-function) (**required**)
- [`collectData`](#the-collectdata-function) (**required**)
- [`getName`](#the-getname-function)
- [`getURI`](#the-geturi-function)
@@ -10,59 +9,54 @@ To create a new Bridge extending `BridgeAbstract` you must implement following f
Find a [template](#template) at the end of this file.
## The `loadMetadatas` function
This function is used by **RSS-Bridge** to determine the name, maintainer name, website, last updated date... of the bridge, and the user parameters.
### Basic metadata
## Basic metadata
The basic metadata are :
```PHP
$this->maintainer // Name of the maintainer
$this->name // Name of the bridge
$this->uri // URI to the target website of the bridge ("http://....")
$this->description // A brief description of the bridge
$this->parameters // (optional) Definition of additional parameters
const NAME // Name of the Bridge
const URI // URI to the target website of the bridge ("http://....")
const DESCRIPTION // A brief description of the Bridge
const MAINTAINER // Name of the maintainer
const PARAMETERS // (optional) Definition of additional parameters
```
Find a description of `$this->parameters` [below](#parameters)
Find a description of `const PARAMETERS` [below](#parameters)
The default values are :
```PHP
$this->maintainer = 'No maintainer';
$this->name = "Unnamed bridge";
$this->uri = "";
$this->description = 'No description provided';
$this->parameters = array();
const NAME = "Unnamed bridge";
const URI = "";
const DESCRIPTION = 'No description provided';
const MAINTAINER = 'No maintainer';
const PARAMETERS = array();
```
### Parameters
Parameters are defined in an array, which is used to generate an HTML `<form>` by **RSS-Bridge**.
The `$this->parameters` array is not mandatory if your bridge doesn't take any parameter.
The `const PARAMETERS` array is not mandatory if your bridge doesn't take any parameter.
The first level of this array describes every possible usage of a bridge.
The array can be a key-based array, but it is not necessary. The following syntaxes are hereby correct :
```PHP
$this->parameters[] = ...
$this->parameters['First usage of my bridge'] = ...
const PARAMETERS = array(array(...), array(...));
const PARAMETERS = array('First usage' => array(...), 'Second usage' => array(...));
```
It is worth mentioning that you can also define a set of parameters that will be applied to every possible utilization of your bridge.
To do this, just create a parameter array with the `global` key :
It is worth mentioning that you can also define a set of parameters that will be applied to every possible utilization of your bridge. To do this, just create a parameter array with the `global` key :
```PHP
$this->parameters['global'] = ...
const PARAMETERS = array('global' => array(...));
```
### Format specifications
`$this->parameters[]` element is an associative array whose key is the input field identifier, and the value is another array containing all input fields names and values.
`const PARAMETERS` element is an associative array whose key is the input field identifier, and the value is another array containing all input fields names and values.
Following elements are supported :
@@ -81,9 +75,9 @@ Hence, the most basic parameter definition is the following :
```PHP
...
$this->parameters[] = array(
const PARAMETERS = array(
'u' => array('name' => 'Username')
)
);
...
```
@@ -132,7 +126,6 @@ If a more complex organization is required to display the values, the above key/
## 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 defined in the parameters array in `loadMetadatas`.
This function is the place where all the website scrapping and the RSS feed generation process must be implemented.
RSS elements collected by this function must be stored in the class variable `items[]`.
@@ -172,7 +165,7 @@ Parameter | ATOM | HTML | (M)RSS
This function returns the name of the bridge as it will be displayed on the main page of **RSS-Bridge** or on top of the feed output (HTML, ATOM, etc...).
**Notice:** **RSS-Bridge** will by default return `$this->name` which is defined in the [`loadMetadatas`](#the-loadmetadatas-function) function, so you only have to implement this function if you require different behavior!
**Notice:** **RSS-Bridge** will by default return `const NAME` which is defined in the [`loadMetadatas`](#the-loadmetadatas-function) function, so you only have to implement this function if you require different behavior!
```PHP
public function getName(){
@@ -184,7 +177,7 @@ This function returns the name of the bridge as it will be displayed on the main
This function returns the URI to the destination site of the bridge. It will be used on the main page of rss-bridge when clicking your bridge name.
**Notice:** **RSS-Bridge** will by default return `$this->uri` which is defined in the [`loadMetadatas`](#the-loadmetadatas-function) function, so you only have to implement this function if you require different behavior!
**Notice:** **RSS-Bridge** will by default return `const URI` which is defined in the [`loadMetadatas`](#the-loadmetadatas-function) function, so you only have to implement this function if you require different behavior!
```PHP
public function getURI(){
@@ -262,15 +255,13 @@ This is the minimum template for a new bridge:
```PHP
<?php
class MySiteBridge extends BridgeAbstract {
public function loadMetadatas(){
$this->maintainer = 'No maintainer';
$this->name = 'Unnamed bridge';
$this->uri = '';
$this->description = 'No description provided';
$this->parameters = array();
}
const NAME = 'Unnamed bridge';
const URI = '';
const DESCRIPTION = 'No description provided';
const MAINTAINER = 'No maintainer';
const PARAMETERS = array();
public function collectData(array $params){
public function collectData(){
// Implement your bridge here!
}
}