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

New extension event + Tumblr GDPR #1924

Merged
merged 3 commits into from
Jun 9, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions app/Controllers/extensionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function enableAction() {

if ($res === true) {
$ext_list = $conf->extensions_enabled;
array_push_unique($ext_list, $ext_name);
$ext_list[$ext_name] = true;
$conf->extensions_enabled = $ext_list;
$conf->save();

Expand Down Expand Up @@ -196,7 +196,11 @@ public function disableAction() {

if ($res === true) {
$ext_list = $conf->extensions_enabled;
array_remove($ext_list, $ext_name);
$legacyKey = array_search($ext_name, $ext_list, true);
if ($legacyKey !== false) { //Legacy format FreshRSS < 1.11.1
unset($ext_list[$legacyKey]);
}
$ext_list[$ext_name] = false;
$conf->extensions_enabled = $ext_list;
$conf->save();

Expand Down
1 change: 1 addition & 0 deletions app/Models/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public function load($loadDetails = false, $noCache = false) {
if (!$loadDetails) { //Only activates auto-discovery when adding a new feed
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
}
Minz_ExtensionManager::callHook('simplepie_before_init', $feed, $this);
$mtime = $feed->init();

if ((!$mtime) || $feed->error()) {
Expand Down
4 changes: 3 additions & 1 deletion config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@
),

# List of enabled FreshRSS extensions.
'extensions_enabled' => array(),
'extensions_enabled' => array(
'Tumblr-GDPR' => true,
),

# Disable self-update,
'disable_update' => false,
Expand Down
1 change: 1 addition & 0 deletions docs/en/developers/03_Backend/05_Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ The following events are available:
- `entry_before_insert` (`function($entry) -> Entry | null`) : will be executed when a feed is refreshed and new entries will be imported into the database. The new entry (instance of FreshRSS_Entry) will be passed as parameter.
- `feed_before_insert` (`function($feed) -> Feed | null`) : will be executed when a new feed is imported into the database. The new feed (instance of FreshRSS_Feed) will be passed as parameter.
- `post_update` (`function(none) -> none`) : **TODO** add documentation
- `simplepie_before_init` (`function($simplePie, $feed) -> none`) : **TODO** add documentation

### Writing your own configure.phtml

Expand Down
2 changes: 1 addition & 1 deletion docs/en/users/06_Fever_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Following features are implemented:
- setting starred marker for item(s)
- setting read marker for feed
- setting read marker for category
- supports FreshRSS extensions, which use th `entry_before_display` hook
- supports FreshRSS extensions, which use the `entry_before_display` hook

Following features are not supported:
- **Hot Links** aka **hot** as there is nothing in FreshRSS yet that is similar or could be used to simulate it
Expand Down
1 change: 1 addition & 0 deletions docs/fr/developers/03_Backend/05_Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ TODO :
- `entry_before_insert` (`function($entry) -> Entry | null`)
- `feed_before_insert` (`function($feed) -> Feed | null`)
- `post_update` (`function(none) -> none`)
- `simplepie_before_init` (`function($simplePie, $feed) -> none`)

### Écrire le fichier configure.phtml

Expand Down
4 changes: 4 additions & 0 deletions extensions/Tumblr-GDPR/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Tumblr-GDPR

Needed for accessing [Tumblr](https://www.tumblr.com/) RSS feeds from the European Union:
bypass the [GPDR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation) check, implying consent.
13 changes: 13 additions & 0 deletions extensions/Tumblr-GDPR/extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

class TumblrGdprExtension extends Minz_Extension {
public function init() {
$this->registerHook('simplepie_before_init', array('TumblrGdprExtension', 'curlHook'));
}

public static function curlHook($simplePie, $feed) {
if (preg_match('#^https?://[a-zA-Z_0-9-]+.tumblr.com/#i', $feed->url())) {
$simplePie->set_useragent(FRESHRSS_USERAGENT . ' like Googlebot');
}
}
}
8 changes: 8 additions & 0 deletions extensions/Tumblr-GDPR/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Tumblr-GDPR",
"author": "Alkarex",
"description": "Bypass Tumblr’ GPDR check (implying consent) for the European Union",
"version": 1.0,
"entrypoint": "TumblrGdpr",
"type": "system"
}
14 changes: 7 additions & 7 deletions lib/Minz/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ public static function get($namespace) {
private $configuration_setter = null;

public function removeExtension($ext_name) {
self::$extensions_enabled = array_diff(
self::$extensions_enabled,
array($ext_name)
);
unset(self::$extensions_enabled[$ext_name]);
$legacyKey = array_search($ext_name, self::$extensions_enabled, true);
if ($legacyKey !== false) { //Legacy format FreshRSS < 1.11.1
unset(self::$extensions_enabled[$legacyKey]);
}
}
public function addExtension($ext_name) {
$found = array_search($ext_name, self::$extensions_enabled) !== false;
if (!$found) {
self::$extensions_enabled[] = $ext_name;
if (!isset(self::$extensions_enabled[$ext_name])) {
self::$extensions_enabled[$ext_name] = true;
}
}

Expand Down
26 changes: 20 additions & 6 deletions lib/Minz/ExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class Minz_ExtensionManager {
'list' => array(),
'signature' => 'OneToOne',
),
'simplepie_before_init' => array( // function($simplePie, $feed) -> none
'list' => array(),
'signature' => 'PassArguments',
),
);
private static $ext_to_hooks = array();

Expand Down Expand Up @@ -160,7 +164,8 @@ public static function register($ext) {
self::$ext_list[$name] = $ext;

if ($ext->getType() === 'system' &&
in_array($name, self::$ext_auto_enabled)) {
(!empty(self::$ext_auto_enabled[$name]) ||
in_array($name, self::$ext_auto_enabled, true))) { //Legacy format < FreshRSS 1.11.1
self::enable($ext->getName());
}

Expand Down Expand Up @@ -189,8 +194,12 @@ public static function enable($ext_name) {
* @param string[] $ext_list the names of extensions we want to load.
*/
public static function enableByList($ext_list) {
foreach ($ext_list as $ext_name) {
self::enable($ext_name);
foreach ($ext_list as $ext_name => $ext_status) {
if (is_int($ext_name)) { //Legacy format int=>name
self::enable($ext_status);
} elseif ($ext_status) { //New format name=>Boolean
self::enable($ext_name);
}
}
}

Expand Down Expand Up @@ -255,10 +264,15 @@ public static function callHook($hook_name) {
}

$signature = self::$hook_list[$hook_name]['signature'];
$signature = 'self::call' . $signature;
$args = func_get_args();

return call_user_func_array($signature, $args);
if ($signature === 'PassArguments') {
array_shift($args);
foreach (self::$hook_list[$hook_name]['list'] as $function) {
call_user_func_array($function, $args);
}
} else {
return call_user_func_array('self::call' . $signature, $args);
}
}

/**
Expand Down
24 changes: 0 additions & 24 deletions lib/lib_rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ function recursive_unlink($dir) {
return rmdir($dir);
}


/**
* Remove queries where $get is appearing.
* @param $get the get attribute which should be removed.
Expand All @@ -497,29 +496,6 @@ function remove_query_by_get($get, $queries) {
return $final_queries;
}


/**
* Add a value in an array and take care it is unique.
* @param $array the array in which we add the value.
* @param $value the value to add.
*/
function array_push_unique(&$array, $value) {
$found = array_search($value, $array) !== false;
if (!$found) {
$array[] = $value;
}
}


/**
* Remove a value from an array.
* @param $array the array from wich value is removed.
* @param $value the value to remove.
*/
function array_remove(&$array, $value) {
$array = array_diff($array, array($value));
}

//RFC 4648
function base64url_encode($data) {
return strtr(rtrim(base64_encode($data), '='), '+/', '-_');
Expand Down