`BridgeAbstract` is a base class for standard bridges.
It implements the most common functions to simplify the process of adding new bridges.
***
# Creating a new bridge
You need four basic steps in order to create a new bridge:
[**Step 1**](#step-1---create-a-new-file) - Create a new file
[**Step 2**](#step-2---add-a-class-extending-bridgeabstract) - Add a class, extending `BridgeAbstract`
[**Step 3**](#step-3---add-general-constants-to-the-class) - Add general constants to the class
[**Step 4**](#step-4---implement-a-function-to-collect-feed-data) - Implement a function to collect feed data
These steps are described in more detail below.
At the end of this document you'll find a complete [template](#template) based on these instructions.
The pictures below show an example based on these instructions:
Show pictures
Make sure to read these instructions carefully.
Please don't hesitate to open an
[Issue](https://github.com/RSS-Bridge/rss-bridge/issues)
if you have further questions (or suggestions).
Once your bridge is finished, please open a [Pull Request](https://github.com/RSS-Bridge/rss-bridge/pulls),
in order to get your bridge merge into RSS-Bridge.
***
## Step 1 - Create a new file
Please read [these instructions](./01_How_to_create_a_new_bridge.md) on how to create a new file for RSS-Bridge.
## Step 2 - Add a class, extending `BridgeAbstract`
Your bridge needs to be a class, which extends `BridgeAbstract`.
The class name must **exactly** match the name of the file, without the file extension.
For example: `MyBridge.php` => `MyBridge`
Show example
```PHP
## Step 3 - Add general constants to the class
In order to present your bridge on the front page, RSS-Bridge requires a few constants:
```PHP
const NAME // Name of the Bridge (default: "Unnamed Bridge")
const URI // URI to the target website of the bridge (default: empty)
const DESCRIPTION // A brief description of the Bridge (default: "No description provided")
const MAINTAINER // Name of the maintainer, i.e. your name on GitHub (default: "No maintainer")
const PARAMETERS // (optional) Definition of additional parameters (default: empty)
const CACHE_TIMEOUT // (optional) Defines the maximum duration for the cache in seconds (default: 3600)
```
Show example
```PHP
**Notice**: `const PARAMETERS` can be used to request information from the user.
Refer to [these instructions](#parameters) for more information.
## Step 4 - Implement a function to collect feed data
In order for RSS-Bridge to collect data, you must implement the **public** function `collectData`.
This function takes no arguments and returns nothing.
It generates a list of feed elements, which must be placed into the variable `$this->items`.
Show example
```PHP
items[] = $item;
}
}
```
For more details on the `collectData` function refer to [these instructions](#collectdata).
***
# Template
Use this template to create your own bridge.
Please remove any unnecessary comments and parameters.
```php
items[] = $item; // Add item to the list
}
}
```
# PARAMETERS
You can specify additional parameters in order to customize the bridge (i.e. to specify how many items to return).
This document explains how to specify those parameters and which options are available to you.
For information on how to read parameter values during execution, please refer to the [getInput](../06_Helper_functions/index.md#getinput) function.
***
## Adding parameters to a bridge
Parameters are specified as part of the bridge class.
An empty list of parameters is defined as `const PARAMETERS = [];`
Show example
```PHP
Parameters are organized in two levels:
[**Level 1**](##level-1---context) - Context
[**Level 2**](##level-2---parameter) - Parameter
## Level 1 - Context
A context is defined as a associative array of parameters.
The name of a context is displayed by RSS-Bridge.
Show example
_Notice_: The name of a context can be left empty if only one context is needed!
Show example
```PHP
const PARAMETERS = [
[]
];
```
You can also define a set of parameters that will be applied to every possible context of your bridge.
To do this, specify a context named `global`.
Show example
```PHP
const PARAMETERS = [
'global' => [] // Applies to all contexts!
];
```
## Level 2 - Parameter
Parameters are placed inside a context.
They are defined as associative array of parameter specifications.
Each parameter is defined by it's internal input name, a definition in the form `'n' => [];`,
where `n` is the name with which the bridge can access the parameter during execution.
Show example
***
Parameter Name | Required | Type | Supported values | Description
---------------|----------|------|------------------| -----------
`name` | **yes** | Text | | Input name as displayed to the user
`type` | no | Text | `text`, `number`, `list`, `checkbox` | Type of the input (default: `text`)
`required` | no | Boolean | `true`, `false` | Specifies if the parameter is required or not (default: `false`). Not supported for lists and checkboxes.
[`values`](#list-values) | no | associative array | | name/value pairs used by the HTML option tag, required for type '`list`'
`title` | no | Text | | Used as tool-tip when mouse-hovering over the input box
`pattern` | no | Text | | Defines a pattern for an element of type `text`. The pattern should be mentioned in the `title` attribute!
`exampleValue` | no | Text | | Defines an example value displayed for elements of type `text` and `number` when no data has been entered yet
[`defaultValue`](#defaultvalue) | no | | | Defines the default value if left blank by the user
#### List values
List values are defined in an associative array where keys are the string displayed in the combo list of the **RSS-Bridge** web interface, and values are the content of the \