orderly and working
This commit is contained in:
parent
e4230379d0
commit
80eafc06bc
41
xExtension-Readability/configure.phtml
Normal file
41
xExtension-Readability/configure.phtml
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<form action="<?php echo _url('extension', 'configure', 'e', urlencode($this->getName())); ?>" method="post">
|
||||||
|
<input type="hidden" name="_csrf" value="<?php echo FreshRSS_Auth::csrfToken(); ?>" />
|
||||||
|
<div class="form-group">
|
||||||
|
|
||||||
|
<label class="group-name" for="read_readability_host">Readbility Host</label>
|
||||||
|
<div class="group-controls">
|
||||||
|
<input type="text" id="read_readability_host" name="read_readability_host" value="<?php echo $this->getReadHost(); ?>" min="50" data-leave-validation="1">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label class="group-name" for="read_mercury_host">Mercury Host</label>
|
||||||
|
<div class="group-controls">
|
||||||
|
<input type="text" id="read_mercury_host" name="read_mercury_host" value="<?php echo $this->getMercHost(); ?>" min="100" data-leave-validation="1">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p> Shown below are the feeds, on which this addon will apply either Mercury or Readability Parsing </p>
|
||||||
|
<table>
|
||||||
|
<tr> <td>Mercury</td><td>Readability</td><td>Feed</td></tr>
|
||||||
|
<?php
|
||||||
|
foreach ($this->getFeeds() as $f) {
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td> <input type="checkbox" id="merc_<?php echo $f->id() ?>" name="merc_<?php echo $f->id() ?>" value="1" <?php echo $this->getConfStore('m', $f->id()) ? 'checked' : ''; ?>> </td>
|
||||||
|
<td> <input type="checkbox" id="read_<?php echo $f->id() ?>" name="read_<?php echo $f->id() ?>" value="1" <?php echo $this->getConfStore('r', $f->id()) ? 'checked' : ''; ?>> </td>
|
||||||
|
<td><?php echo $f->name() ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-actions">
|
||||||
|
<div class="group-controls">
|
||||||
|
<button type="submit" class="btn btn-important"><?php echo _t('gen.action.submit'); ?></button>
|
||||||
|
<button type="reset" class="btn"><?php echo _t('gen.action.cancel'); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
|
@ -1,24 +1,31 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ReadabilityExtension extends Minz_Extension {
|
class ReadabilityExtension extends Minz_Extension {
|
||||||
|
|
||||||
|
private $readHost;
|
||||||
|
private $mercHost;
|
||||||
|
private $feeds;
|
||||||
|
private $mStore;
|
||||||
|
private $rStore;
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
#$this->registerTranslates();
|
#$this->registerTranslates();
|
||||||
|
|
||||||
#$current_user = Minz_Session::param('currentUser');
|
#$current_user = Minz_Session::param('currentUser');
|
||||||
|
Minz_View::appendScript($this->getFileUrl('read_ext.js', 'js'));
|
||||||
|
|
||||||
$this->registerHook('entry_before_insert', array($this, 'fetchStuff'));
|
$this->registerHook('entry_before_insert', array($this, 'fetchStuff'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchStuff($entry) {
|
public function fetchStuff($entry) {
|
||||||
|
|
||||||
|
$this->loadConfigValues();
|
||||||
|
/*
|
||||||
$read = false;
|
$read = false;
|
||||||
|
|
||||||
$regex = [
|
$regex = [
|
||||||
'washingtonpost.com',
|
'nytimes.com',
|
||||||
'heise.de',
|
'ncsjdnfsd.de'
|
||||||
'nytimes.com'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ( $regex as $ex ) {
|
foreach ( $regex as $ex ) {
|
||||||
|
@ -26,30 +33,121 @@ class ReadabilityExtension extends Minz_Extension {
|
||||||
$read = true;
|
$read = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
$host = '';
|
||||||
|
|
||||||
if (! $read){
|
if ( array_key_exists($entry->feed(false), $this->mStore) )
|
||||||
|
$host = $this->mercHost;
|
||||||
|
|
||||||
|
if ( array_key_exists($entry->feed(false), $this->rStore) )
|
||||||
|
$host = $this->readHost;
|
||||||
|
|
||||||
|
if ($host === '')
|
||||||
return $entry;
|
return $entry;
|
||||||
}
|
|
||||||
|
|
||||||
|
/*if (! $read){
|
||||||
|
return $entry;
|
||||||
|
}*/
|
||||||
$data = "{\"url\": \"" . $entry->link() ."\"}";
|
$data = "{\"url\": \"" . $entry->link() ."\"}";
|
||||||
$headers[] = 'Content-Type: application/json';
|
$headers[] = 'Content-Type: application/json';
|
||||||
|
|
||||||
$c = curl_init("http://read:3000/");
|
$c = curl_init($host);
|
||||||
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
|
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
|
||||||
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
|
||||||
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
|
||||||
$result = curl_exec($c);
|
$result = curl_exec($c);
|
||||||
$c_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
|
$c_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
|
||||||
|
//$c_error = curl_error($c);
|
||||||
curl_close($c);
|
curl_close($c);
|
||||||
|
|
||||||
if ($c_status !== 200) {
|
if ($c_status !== 200) {
|
||||||
return $entry;
|
return $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
$val = json_decode($result, true);
|
$val = json_decode($result, true);
|
||||||
$entry->_content($val["content"]);
|
$entry->_content($val["content"]);
|
||||||
|
|
||||||
return $entry;
|
return $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getReadHost() {
|
||||||
|
return $this->readHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMercHost() {
|
||||||
|
return $this->mercHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFeeds() {
|
||||||
|
return $this->feeds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadConfigValues()
|
||||||
|
{
|
||||||
|
if (!class_exists('FreshRSS_Context', false) || null === FreshRSS_Context::$user_conf) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FreshRSS_Context::$user_conf->read_ext_read_host != '') {
|
||||||
|
$this->readHost = FreshRSS_Context::$user_conf->read_ext_read_host;
|
||||||
|
}
|
||||||
|
if (FreshRSS_Context::$user_conf->read_ext_merc_host != '') {
|
||||||
|
$this->mercHost = FreshRSS_Context::$user_conf->read_ext_merc_host;
|
||||||
|
}
|
||||||
|
if (FreshRSS_Context::$user_conf->read_ext_mercury != '') {
|
||||||
|
$this->mStore = json_decode(FreshRSS_Context::$user_conf->read_ext_mercury, true);
|
||||||
|
} else {
|
||||||
|
$this->mStore = [];
|
||||||
|
}
|
||||||
|
if (FreshRSS_Context::$user_conf->read_ext_readability != '') {
|
||||||
|
$this->rStore = json_decode(FreshRSS_Context::$user_conf->read_ext_readability, true);
|
||||||
|
} else {
|
||||||
|
$this->rStore = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConfStore( $list, $id ) {
|
||||||
|
if ($list === 'm' ) {
|
||||||
|
return array_key_exists($id, $this->mStore);
|
||||||
|
} else {
|
||||||
|
return array_key_exists($id, $this->rStore);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handleConfigureAction()
|
||||||
|
{
|
||||||
|
//$this->registerTranslates();
|
||||||
|
|
||||||
|
$feedDAO = FreshRSS_Factory::createFeedDao();
|
||||||
|
$this->feeds = $feedDAO->listFeeds();
|
||||||
|
|
||||||
|
if (Minz_Request::isPost()) {
|
||||||
|
//FreshRSS_Context::$user_conf->yt_nocookie = (int)Minz_Request::param('yt_nocookie', 0);
|
||||||
|
$mstore = [];
|
||||||
|
$rstore = [];
|
||||||
|
foreach ( $this->feeds as $f ) {
|
||||||
|
if ((bool)Minz_Request::param("read_".$f->id(), 0)){
|
||||||
|
$rstore[$f->id()] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( (bool)Minz_Request::param("merc_".$f->id(), 0) ) {
|
||||||
|
$mstore[$f->id()] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FreshRSS_Context::$user_conf->read_ext_mercury = (string)json_encode($mstore);
|
||||||
|
FreshRSS_Context::$user_conf->read_ext_readability = (string)json_encode($rstore);
|
||||||
|
|
||||||
|
|
||||||
|
FreshRSS_Context::$user_conf->read_ext_merc_host = (string)Minz_Request::param('read_mercury_host');
|
||||||
|
FreshRSS_Context::$user_conf->read_ext_read_host = (string)Minz_Request::param('read_readability_host');
|
||||||
|
|
||||||
|
FreshRSS_Context::$user_conf->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->loadConfigValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
"description": "fetch article content for every feed with readability",
|
"description": "fetch article content for every feed with readability",
|
||||||
"version": "0.7.1",
|
"version": "0.7.1",
|
||||||
"entrypoint": "Readability",
|
"entrypoint": "Readability",
|
||||||
"type": "system"
|
"type": "user"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue