From c4550be812c238319c98c2de554cf69a01f3f355 Mon Sep 17 00:00:00 2001
From: logmanoriginal
Date: Fri, 16 Nov 2018 21:48:59 +0100
Subject: [PATCH] lib: Add API documentation
---
lib/Authentication.php | 49 +++++++++++
lib/BridgeAbstract.php | 131 ++++++++++++++++++++++++----
lib/BridgeCard.php | 91 +++++++++++++++++++
lib/BridgeInterface.php | 53 +++++++++++
lib/BridgeList.php | 61 +++++++++++++
lib/CacheInterface.php | 44 ++++++++++
lib/Configuration.php | 112 ++++++++++++++++++++++++
lib/Exceptions.php | 78 ++++++++++++++---
lib/FeedExpander.php | 174 ++++++++++++++++++++++++++++++++++++-
lib/FormatAbstract.php | 113 +++++++++++++++++++-----
lib/FormatInterface.php | 73 ++++++++++++++++
lib/ParameterValidator.php | 72 +++++++++++++--
lib/contents.php | 104 ++++++++++++++++++++--
lib/error.php | 31 +++++++
lib/html.php | 117 +++++++++++++++++++++----
15 files changed, 1212 insertions(+), 91 deletions(-)
diff --git a/lib/Authentication.php b/lib/Authentication.php
index da247630..f9683940 100644
--- a/lib/Authentication.php
+++ b/lib/Authentication.php
@@ -1,6 +1,48 @@
items;
}
/**
- * Sets the input values for a given context. Existing values are
- * overwritten.
+ * Sets the input values for a given context.
*
* @param array $inputs Associative array of inputs
- * @param string $context The context name
+ * @param string $queriedContext The context name
+ * @return void
*/
protected function setInputs(array $inputs, $queriedContext){
// Import and assign all inputs to their context
@@ -103,9 +183,15 @@ abstract class BridgeAbstract implements BridgeInterface {
}
/**
- * Defined datas with parameters depending choose bridge
- * @param array array with expected bridge paramters
- */
+ * Set inputs for the bridge
+ *
+ * Returns errors and aborts execution if the provided input parameters are
+ * invalid.
+ *
+ * @param array List of input parameters. Each element in this list must
+ * relate to an item in {@see BridgeAbstract::PARAMETERS}
+ * @return void
+ */
public function setDatas(array $inputs){
if(empty(static::PARAMETERS)) {
@@ -148,7 +234,7 @@ abstract class BridgeAbstract implements BridgeInterface {
* Returns the value for the provided input
*
* @param string $input The input name
- * @return mixed Returns the input value or null if the input is not defined
+ * @return mixed|null The input value or null if the input is not defined
*/
protected function getInput($input){
if(!isset($this->inputs[$this->queriedContext][$input]['value'])) {
@@ -157,30 +243,37 @@ abstract class BridgeAbstract implements BridgeInterface {
return $this->inputs[$this->queriedContext][$input]['value'];
}
+ /** {@inheritdoc} */
public function getDescription(){
return static::DESCRIPTION;
}
+ /** {@inheritdoc} */
public function getMaintainer(){
return static::MAINTAINER;
}
+ /** {@inheritdoc} */
public function getName(){
return static::NAME;
}
+ /** {@inheritdoc} */
public function getIcon(){
return '';
}
+ /** {@inheritdoc} */
public function getParameters(){
return static::PARAMETERS;
}
+ /** {@inheritdoc} */
public function getURI(){
return static::URI;
}
+ /** {@inheritdoc} */
public function getCacheTimeout(){
return static::CACHE_TIMEOUT;
}
diff --git a/lib/BridgeCard.php b/lib/BridgeCard.php
index 28e74fe6..cb7e607b 100644
--- a/lib/BridgeCard.php
+++ b/lib/BridgeCard.php
@@ -1,6 +1,33 @@
@@ -31,6 +65,17 @@ This bridge is not fetching its content through a secure connection';
return $form;
}
+ /**
+ * Get the form body for a bridge
+ *
+ * @param string $bridgeName The bridge name
+ * @param array $formats A list of supported formats
+ * @param bool $isActive Indicates if a bridge is enabled or not
+ * @param bool $isHttps Indicates if a bridge uses HTTPS or not
+ * @param string $parameterName Sets the bridge context for the current form
+ * @param array $parameters The bridge parameters
+ * @return string The form body
+ */
private static function getForm($bridgeName,
$formats,
$isActive = false,
@@ -88,6 +133,12 @@ This bridge is not fetching its content through a secure connection';
return $form . '' . PHP_EOL;
}
+ /**
+ * Get input field attributes
+ *
+ * @param array $entry The current entry
+ * @return string The input field attributes
+ */
private static function getInputAttributes($entry) {
$retVal = '';
@@ -103,6 +154,14 @@ This bridge is not fetching its content through a secure connection';
return $retVal;
}
+ /**
+ * Get text input
+ *
+ * @param array $entry The current entry
+ * @param string $id The field ID
+ * @param string $name The field name
+ * @return string The text input field
+ */
private static function getTextInput($entry, $id, $name) {
return '';
. PHP_EOL;
}
+ /**
+ * Get number input
+ *
+ * @param array $entry The current entry
+ * @param string $id The field ID
+ * @param string $name The field name
+ * @return string The number input field
+ */
private static function getNumberInput($entry, $id, $name) {
return '';
. PHP_EOL;
}
+ /**
+ * Get list input
+ *
+ * @param array $entry The current entry
+ * @param string $id The field ID
+ * @param string $name The field name
+ * @return string The list input field
+ */
private static function getListInput($entry, $id, $name) {
$list = '
` becomes `Hello World!`).
+ * @return object A simplehtmldom object of the remaining contents.
+ *
+ * @todo Check if this implementation is still necessary, because simplehtmldom
+ * already removes some of the tags (search for `remove_noise` in simple_html_dom.php).
+ * @todo Rename parameters to make more sense. `$textToSanitize` must be HTML,
+ * `$removedTags`, `$keptAttributes` and `$keptText` are past tense.
+ * @todo Clarify the meaning of `*[!b38fd2b1fe7f4747d6b1c1254ccd055e]`, which
+ * looks like a SHA1 hash (does simplehtmldom not support `find('*')`?).
+ */
function sanitize($textToSanitize,
$removedTags = array('script', 'iframe', 'input', 'form'),
$keptAttributes = array('title', 'href', 'src'),
@@ -21,6 +51,35 @@ $keptText = array()){
return $htmlContent;
}
+/**
+ * Replace background by image
+ *
+ * Replaces tags with styles of `backgroud-image` by `` tags.
+ *
+ * For example:
+ *
+ * ```HTML
+ *
+ *
+ *
Hello world!
+ *
+ *
+ * ```
+ *
+ * results in this output:
+ *
+ * ```HTML
+ *
+ *
+ *
+ * ```
+ *
+ * @param string $htmlContent The HTML content
+ * @return string The HTML content with all ocurrences replaced
+ *
+ * @todo Clarify the meaning of `*[!b38fd2b1fe7f4747d6b1c1254ccd055e]`, which
+ * looks like a SHA1 hash (does simplehtmldom not support `find('*')`?).
+ */
function backgroundToImg($htmlContent) {
$regex = '/background-image[ ]{0,}:[ ]{0,}url\([\'"]{0,}(.*?)[\'"]{0,}\)/';
@@ -42,9 +101,17 @@ function backgroundToImg($htmlContent) {
/**
* Convert relative links in HTML into absolute links
- * @param $content HTML content to fix. Supports HTML objects or string objects
- * @param $server full URL to the page containing relative links
- * @return content with fixed URLs, as HTML object or string depending on input type
+ *
+ * This function is based on `php-urljoin`.
+ *
+ * @link https://github.com/plaidfluff/php-urljoin php-urljoin
+ *
+ * @param string|object $content The HTML content. Supports HTML objects or string objects
+ * @param string $server Fully qualified URL to the page containing relative links
+ * @return object Content with fixed URLs.
+ *
+ * @todo If the input type was a string, this function should return a string as
+ * well. This is currently done implicitly by how the simplehtmldom object works.
*/
function defaultLinkTo($content, $server){
$string_convert = false;
@@ -70,10 +137,14 @@ function defaultLinkTo($content, $server){
/**
* Extract the first part of a string matching the specified start and end delimiters
- * @param $string input string, e.g. '
Post author: John Doe
'
- * @param $start start delimiter, e.g. 'author: '
- * @param $end end delimiter, e.g. '<'
- * @return extracted string, e.g. 'John Doe', or false if the delimiters were not found.
+ *
+ * @param string $string Input string, e.g. `
Post author: John Doe
`
+ * @param string $start Start delimiter, e.g. `author: `
+ * @param string $end End delimiter, e.g. `<`
+ * @return string|bool Extracted string, e.g. `John Doe`, or false if the
+ * delimiters were not found.
+ *
+ * @todo This function can possibly be simplified to use a single `substr` command.
*/
function extractFromDelimiters($string, $start, $end) {
if (strpos($string, $start) !== false) {
@@ -85,10 +156,13 @@ function extractFromDelimiters($string, $start, $end) {
/**
* Remove one or more part(s) of a string using a start and end delmiters
- * @param $string input string, e.g. 'foobar'
- * @param $start start delimiter, e.g. 'bar`
+ * @param string $start Start delimiter, e.g. `