implement en/disabling feeds

master
Benjamin 'blindCoder' Schieder 2017-04-22 21:28:21 +02:00
parent 564c0f52b5
commit 44ecb7e512
8 changed files with 88 additions and 8 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
tweetodon.conf.json
*.swp

17
Tweetodon/Entry.pm 100644
View File

@ -0,0 +1,17 @@
# vim: set foldmarker={,}:
use strict;
use Tweetodon::Base;
package Tweetodon::Entry;
@Tweetodon::Entry::ISA = qw(Tweetodon::Base);
use JSON;
use Data::Dumper;
sub dbTable :lvalue { "entries"; }
sub orderBy :lvalue { "posted_at ASC"; }
# Class functions
# Object methods
1;

View File

@ -7,6 +7,9 @@ package Tweetodon::Feed;
use JSON;
use Data::Dumper;
use Tweetodon::Filter;
use Tweetodon::Entry;
use XML::Feed;
use URI;
sub dbTable :lvalue { "feeds"; }
sub orderBy :lvalue { "url ASC"; }
@ -26,6 +29,19 @@ sub get_by_user_instance {
return @retVal;
}
sub create_and_fetch {
my $class = shift;
my %data = @_;
my $self = $class->create(%data);
my $feeddata = $self->fetch_entries();
foreach my $entry ($feeddata->items){
my %ne;
$ne{feed_id} = $self->{data}->{ID};
$ne{entry_link} = $entry->link();
Tweetodon::Entry->create(%ne);
}
}
# Object methods
sub filters {
@ -39,4 +55,11 @@ sub filters {
return @retVal;
}
sub fetch_entries {
my $self = shift;
$XML::Feed::MULTIPLE_ENCLOSURES = 1;
return XML::Feed->parse(URI->new($self->{data}->{url}));
}
1;

View File

@ -18,8 +18,17 @@ sub requires_authentication {
sub fill_content {
my $class = shift;
my $output = shift;
my @feeds = Tweetodon::Feed->get_by_user_instance($main::CURRENTUSER->{data}->{acct}, $main::FORM{instance});
if ($main::FORM{inputURL}){
my %nf;
$nf{url} = $main::FORM{inputURL};
$nf{username} = $main::CURRENTUSER->{data}->{acct};
$nf{instance} = $main::FORM{instance};
$nf{enabled} = "n";
my $feed = Tweetodon::Feed->create_and_fetch(%nf);
}
my @feeds = Tweetodon::Feed->get_by_user_instance($main::CURRENTUSER->{data}->{acct}, $main::FORM{instance});
my @param_feeds;
my $count = 0;
FEED: foreach my $feed (@feeds){
@ -30,6 +39,14 @@ sub fill_content {
my %r;
$count++;
$r{"count"} = $count;
if ($main::FORM{enable} and "x".$main::FORM{enable} eq "x".$feed->{data}->{ID}){
$feed->{data}->{enabled} = "1";
$feed->save();
}
if ($main::FORM{disable} and "x".$main::FORM{disable} eq "x".$feed->{data}->{ID}){
$feed->{data}->{enabled} = "0";
$feed->save();
}
foreach my $key (keys %{$feed->{data}}){
$r{$key} = $feed->{data}->{$key};
}

View File

@ -10,8 +10,6 @@ use Tweetodon::Website;
package Tweetodon::Website::EditFeed;
use Data::Dumper;
use XML::Feed;
use URI;
@Tweetodon::Website::EditFeed::ISA = qw(Tweetodon::Website);
sub requires_authentication {
@ -60,10 +58,9 @@ sub fill_content {
}
}
$XML::Feed::MULTIPLE_ENCLOSURES = 1;
my $feeddata = XML::Feed->parse(URI->new($feed->{data}->{url}));
my @param_entries;
my @filters = $feed->filters();
my $feeddata = $feed->fetch_entries();
foreach my $entry ($feeddata->items){
my %entry;
$entry{title} = $entry->title();
@ -75,7 +72,7 @@ sub fill_content {
$entry{id} = $entry->id();
$entry{tags} = join(", ", $entry->tags());
$entry{class} = "green";
$entry{class} = "red";
foreach my $filter (@filters){
if ($filter->apply($entry)){
if ($filter->{data}->{type} eq "white"){

View File

@ -1,4 +1,5 @@
function TweetodonOnReady(){
$("form#addFeed").hide();
$("a.deleteFeed").on("click", function(){
var btn = $(this);
if (confirm("Really delete this feed?")){
@ -6,4 +7,21 @@ function TweetodonOnReady(){
document.location.href=l;
}
});
$("a.addFeed").on("click", function(){
var btn=$(this);
$("form#addFeed").show();
btn.hide();
});
$("a.enable").on("click", function(){
var btn = $(this);
var l = "index.pl?mode=Dashboard&enable="+btn.data("id");
document.location.href=l;
});
$("a.disable").on("click", function(){
var btn = $(this);
var l = "index.pl?mode=Dashboard&disable="+btn.data("id");
document.location.href=l;
});
}

View File

@ -48,13 +48,20 @@
<tr>
<td><TMPL_VAR NAME="count"></td>
<td><TMPL_VAR NAME="url"></td>
<td><TMPL_IF NAME="enabled"><a class="btn btn-danger disable" data-id="<TMPL_VAR NAME="ID">" href="#">Disable</a><TMPL_ELSE><a class="btn btn-default enable" data-id="<TMPL_VAR NAME="ID">" href="#">Enable</a></TMPL_IF></td>
<td><a class="btn btn-default" href="index.pl?mode=EditFeed&id=<TMPL_VAR NAME="ID">">Edit</a></td>
<td><a class="btn btn-danger deleteFeed" href="#" data-id="<TMPL_VAR NAME="ID">">Delete</a></td>
</tr>
</TMPL_LOOP>
</tbody>
</table>
<a class="btn btn-primary">Add new feed</a>
<a class="btn btn-primary addFeed" href="#">Add new feed</a>
<form class="form" id="addFeed" method="POST">
<input type="hidden" name="mode" value="<TMPL_VAR NAME="currentmode">">
<label for="inputURL">RSS Feed URL</label>
<input type="url" id="inputURL" name="inputURL" class="form-control" placeholder="https://www.example.com/rss.xml">
<button class="btn btn-lg btn-primary btn-block" type="submit">Add Feed</button>
</form>
</div>
</div>
</div>

View File

@ -4,7 +4,7 @@
<form class="form-signin" method="POST" action="index.pl">
<h2 class="form-signin-heading">Please enter your Mastodon instance URL</h2>
<label for="inputUsername" class="sr-only">Mastodon instance URL</label>
<input type="url" id="inputInstance" name="inputInstance" class="form-control" placeholder="mastodon.social" required autofocus>
<input type="url" id="inputInstance" name="inputInstance" class="form-control" placeholder="https://mastodon.social" required autofocus>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
<input type="hidden" id="mode" name="mode" value="OAuthLogin">