[core] Support for bridge maintainers' donation URLs (#2102)

This commit is contained in:
Bockiii 2021-06-25 21:45:25 +02:00 committed by GitHub
parent 5598fef3cf
commit ecaae735d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 3 deletions

View file

@ -40,6 +40,13 @@ abstract class BridgeAbstract implements BridgeInterface {
*/
const URI = '';
/**
* Donation URI to the site the bridge is intended to be used for.
*
* Use {@see BridgeAbstract::getDonationURI()} to read this parameter
*/
const DONATION_URI = '';
/**
* A brief description of what the bridge can do
*
@ -341,6 +348,11 @@ abstract class BridgeAbstract implements BridgeInterface {
return static::URI;
}
/** {@inheritdoc} */
public function getDonationURI(){
return static::DONATION_URI;
}
/** {@inheritdoc} */
public function getCacheTimeout(){
return static::CACHE_TIMEOUT;

View file

@ -301,6 +301,10 @@ This bridge is not fetching its content through a secure connection</div>';
$icon = $bridge->getIcon();
$description = $bridge->getDescription();
$parameters = $bridge->getParameters();
$donationUri = $bridge->getDonationURI();
$maintainer = $bridge->getMaintainer();
$donationsAllowed = Configuration::getConfig('admin', 'donations');
if(defined('PROXY_URL') && PROXY_BYBRIDGE) {
$parameters['global']['_noproxy'] = array(
@ -332,7 +336,6 @@ CARD;
// Display form with cache timeout and/or noproxy options (if enabled) when bridge has no parameters
} else if (count($parameters) === 1 && array_key_exists('global', $parameters)) {
$card .= self::getForm($bridgeName, $formats, $isActive, $isHttps, '', $parameters['global']);
} else {
foreach($parameters as $parameterName => $parameter) {
@ -351,7 +354,11 @@ CARD;
}
$card .= '<label class="showless" for="showmore-' . $bridgeName . '">Show less</label>';
$card .= '<p class="maintainer">' . $bridge->getMaintainer() . '</p>';
if($donationUri !== '' && $donationsAllowed) {
$card .= '<p class="maintainer">' . $maintainer . ' ~ <a href="' . $donationUri . '">Donate</a></p>';
} else {
$card .= '<p class="maintainer">' . $maintainer . '</p>';
}
$card .= '</section>';
return $card;

View file

@ -120,6 +120,13 @@ interface BridgeInterface {
*/
public function getURI();
/**
* Returns the bridge Donation URI
*
* @return string Bridge Donation URI
*/
public function getDonationURI();
/**
* Returns the cache timeout
*

View file

@ -198,6 +198,9 @@ final class Configuration {
&& !filter_var(self::getConfig('admin', 'email'), FILTER_VALIDATE_EMAIL))
self::reportConfigurationError('admin', 'email', 'Is not a valid email address');
if(!is_bool(self::getConfig('admin', 'donations')))
self::reportConfigurationError('admin', 'donations', 'Is not a valid Boolean');
if(!is_string(self::getConfig('error', 'output')))
self::reportConfigurationError('error', 'output', 'Is not a valid String');

View file

@ -140,7 +140,7 @@ abstract class FormatAbstract implements FormatInterface {
* @param array $extraInfos {@inheritdoc}
*/
public function setExtraInfos(array $extraInfos = array()){
foreach(array('name', 'uri', 'icon') as $infoName) {
foreach(array('name', 'uri', 'icon', 'donationUri') as $infoName) {
if(!isset($extraInfos[$infoName])) {
$extraInfos[$infoName] = '';
}