Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions actions/DisplayAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public function execute() {
$infos = array(
'name' => $bridge->getName(),
'uri' => $bridge->getURI(),
'donationUri' => $bridge->getDonationURI(),
'icon' => $bridge->getIcon()
);
} catch(Error $e) {
Expand Down
1 change: 1 addition & 0 deletions actions/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function execute() {
$list->bridges[$bridgeName] = array(
'status' => $status,
'uri' => $bridge->getURI(),
'donationUri' => $bridge->getDonationURI(),
'name' => $bridge->getName(),
'icon' => $bridge->getIcon(),
'parameters' => $bridge->getParameters(),
Expand Down
7 changes: 7 additions & 0 deletions config.default.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
; "" = Disabled (default)
email = ""

; Show Donation information for bridges if available.
; This will display a 'Donate' link on the bridge view
; and a "Donate" button in the HTML view of the bridges feed.
; true = enabled (default)
; false = disabled
donations = true

[proxy]

; Sets the proxy url (i.e. "tcp://192.168.0.0:32")
Expand Down
13 changes: 13 additions & 0 deletions formats/HtmlFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public function stringify(){
$extraInfos = $this->getExtraInfos();
$title = htmlspecialchars($extraInfos['name']);
$uri = htmlspecialchars($extraInfos['uri']);
$donationUri = htmlspecialchars($extraInfos['donationUri']);
$donationsAllowed = Configuration::getConfig('admin', 'donations');

// Dynamically build buttons for all formats (except HTML)
$formatFac = new FormatFactory();
Expand All @@ -26,6 +28,17 @@ public function stringify(){
$links .= $this->buildLink($format, $query, $mime) . PHP_EOL;
}

if($donationUri !== '' && $donationsAllowed) {
$buttons .= '<a href="'
. $donationUri
. '" target="_blank"><button class="highlight">Donate to maintainer</button></a>'
. PHP_EOL;
$links .= '<link href="'
. $donationUri
. ' target="_blank"" title="Donate to Maintainer" rel="alternate">'
. PHP_EOL;
}

$entries = '';
foreach($this->getItems() as $item) {
$entryAuthor = $item->getAuthor() ? '<br /><p class="author">by: ' . $item->getAuthor() . '</p>' : '';
Expand Down
12 changes: 12 additions & 0 deletions lib/BridgeAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -336,6 +343,11 @@ public function getURI(){
return static::URI;
}

/** {@inheritdoc} */
public function getDonationURI(){
return static::DONATION_URI;
}

/** {@inheritdoc} */
public function getCacheTimeout(){
return static::CACHE_TIMEOUT;
Expand Down
11 changes: 9 additions & 2 deletions lib/BridgeCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ static function displayBridgeCard($bridgeName, $formats, $isActive = true){
$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(
Expand Down Expand Up @@ -353,7 +357,6 @@ static function displayBridgeCard($bridgeName, $formats, $isActive = true){
// 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) {
Expand All @@ -372,7 +375,11 @@ static function displayBridgeCard($bridgeName, $formats, $isActive = true){
}

$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;
Expand Down
7 changes: 7 additions & 0 deletions lib/BridgeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ public function getParameters();
*/
public function getURI();

/**
* Returns the bridge Donation URI
*
* @return string Bridge Donation URI
*/
public function getDonationURI();

/**
* Returns the cache timeout
*
Expand Down
7 changes: 6 additions & 1 deletion lib/BridgeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ private static function getSearchbar() {
private static function getFooter($totalBridges, $totalActiveBridges, $showInactive) {
$version = Configuration::getVersion();

$donationsAllowed = Configuration::getConfig('admin', 'donations');
$email = Configuration::getConfig('admin', 'email');
$admininfo = '';
if (!empty($email)) {
Expand All @@ -178,10 +179,14 @@ private static function getFooter($totalBridges, $totalActiveBridges, $showInact

}

if($donationsAllowed) {
$donation = ' ~ <a href="http://www.google.com">Donate</a>';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wnat is expected here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thats right. Thats the rss-bridge-general-donation-url, so not bridge specific but for rss-bridge itself. You need to define that link

}

return <<<EOD
<section class="footer">
<a href="https://github.com/rss-bridge/rss-bridge">RSS-Bridge ~ Public Domain</a><br>
<p class="version">{$version}</p>
<p class="version">{$version}{$donation}</p>
{$totalActiveBridges}/{$totalBridges} active bridges.<br>
{$inactive}
{$admininfo}
Expand Down
3 changes: 3 additions & 0 deletions lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ public static function loadConfiguration() {
&& !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');

Expand Down
2 changes: 1 addition & 1 deletion lib/FormatAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function getItems(){
* @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] = '';
}
Expand Down
7 changes: 7 additions & 0 deletions static/HtmlFormat.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockq
button:hover {
background: #49afff;
}
button.highlight {
background: #ff6600;
}
button.highlight:hover {
background: #ff8a3b;
}


@media screen and (max-width: 767px) {

Expand Down