From ba8b71316d838a0d6e217677f43629df591c2135 Mon Sep 17 00:00:00 2001
From: MichaelDaum \
\
+
"._dump(@followers)."" if Foswiki::Func::isTrue($params->{raw}); - return "" unless @followers; - - my $format = $params->{format}; - my $header = $params->{header} || ''; - my $footer = $params->{footer} || ''; - my $sep = $params->{separator}; - - $format = '$screen_name' unless defined $format; - $sep = ', ' unless defined $sep; - - my @result = (); - - my $index = 0; - foreach my $item (@followers) { - my $line = $format; - - foreach my $key (qw(created_at description favorites_count followers_count - friends_count id lang listed_count location name profile_background_color - profile_background_image_url profile_background_image_url_https - profile_background_tile profile_image_url profile_image_url_https - profile_link_color profile_location profile_sidebar_border_color - profile_sidebar_fill_color profile_text_color profile_use_background_image - protected screen_name status statuses_count time_zone url utc_offset verified)) { - my $val; + return "" unless @users; + return $this->renderUsers(\@users, $params); - if ($key eq 'status') { - $val = defined($item->{$key}) ? $item->{$key}->text : ''; - } else { - $val = $item->{$key}; - } - $line =~ s/\$$key/$val/g; - } - - $line =~ s/\$index/$index/g; - push @result, $line; - - $index++; - } - - return "" unless @result; - - my $result = $header.join($sep, @result).$footer; - $result =~ s/\$count/$index/g; - - return Foswiki::Func::decodeFormatTokens($result); } sub handle_favorites { @@ -309,6 +282,35 @@ sub handle_get_lists { return Foswiki::Func::decodeFormatTokens($header.join($sep, @result).$footer); } +sub handle_account_settings { + my ($this, $params) = @_; + + my $settings = $this->agent->account_settings(_params2args($params)); + return "
"._dump($settings)."" if Foswiki::Func::isTrue($params->{raw}); + + my $format = $params->{format} || '$screen_name'; + foreach my $key (qw(allow_contributor_request allow_dm_groups_from allow_dms_from discoverable_by_email discoverable_by_mobile_phone + display_sensitive_media geo_enabled language protected screen_name smart_mute use_cookie_personalization)) { + $format =~ s/\$$key/$settings->{$key}/g; + } + + return $format; +} + +sub handle_friends { + my ($this, $params) = @_; + + my @users = (); + my $args = _params2args($params); + for (my $cursor = -1, my $result; $cursor; $cursor = $result->{next_cursor} ) { + $args->{cursor} = $cursor; + $result = $this->agent->friends($args); + push @users, @{$result->users}; + } + + return $this->renderUsers(\@users, $params); +} + sub handle_list_statuses { my ($this, $params) = @_; @@ -325,6 +327,14 @@ sub handle_user_timeline { return $this->renderTimeline($timeline, $params); } +sub handle_following_timeline { + my ($this, $params) = @_; + + my $timeline = $this->agent->following_timeline(_params2args($params)); + + return $this->renderTimeline($timeline, $params); +} + sub handle_home_timeline { my ($this, $params) = @_; @@ -341,6 +351,14 @@ sub handle_mentions_timeline { return $this->renderTimeline($timeline, $params); } +sub handle_retweets_of_me { + my ($this, $params) = @_; + + my $timeline = $this->agent->retweets_of_me(_params2args($params)); + + return $this->renderTimeline($timeline, $params); +} + sub handle_search { my ($this, $params) = @_; @@ -349,6 +367,56 @@ sub handle_search { return $this->renderTimeline($result->statuses, $params); } +sub renderUsers { + my ($this, $users, $params) = @_; + + return "
"._dump($users)."" if Foswiki::Func::isTrue($params->{raw}); + + my $format = $params->{format}; + my $header = $params->{header} || ''; + my $footer = $params->{footer} || ''; + my $sep = $params->{separator}; + + $format = '$screen_name' unless defined $format; + $sep = ', ' unless defined $sep; + + my @result = (); + + my $index = 0; + foreach my $item (@$users) { + my $line = $format; + + foreach my $key (qw(created_at description favorites_count followers_count + friends_count id lang listed_count location name profile_background_color + profile_background_image_url profile_background_image_url_https + profile_background_tile profile_image_url profile_image_url_https + profile_link_color profile_location profile_sidebar_border_color + profile_sidebar_fill_color profile_text_color profile_use_background_image + protected screen_name status statuses_count time_zone url utc_offset verified)) { + my $val; + + if ($key eq 'status') { + $val = defined($item->{$key}) ? $item->{$key}->text : ''; + } else { + $val = $item->{$key}; + } + $line =~ s/\$$key/$val/g; + } + + $line =~ s/\$index/$index/g; + push @result, $line; + + $index++; + } + + return "" unless @result; + + my $result = $header.join($sep, @result).$footer; + $result =~ s/\$count/$index/g; + + return Foswiki::Func::decodeFormatTokens($result); +} + sub renderTimeline { my ($this, $timeline, $params) = @_; @@ -429,7 +497,7 @@ sub renderTimeline { $line =~ s/\$orig_name/$origUser->name/ge; $line =~ s/\$id/$item->{id}/g; - $line = Encode::encode($Foswiki::cfg{Site}{CharSet}, $line); + $line = Encode::encode($Foswiki::cfg{Site}{CharSet}, $line) unless $Foswiki::UNICODE; push @results, $line; } return '' unless @results; diff --git a/lib/Foswiki/Plugins/TwitterPlugin/UserAgent.pm b/lib/Foswiki/Plugins/TwitterPlugin/UserAgent.pm index c63c9e9..0d9c36b 100644 --- a/lib/Foswiki/Plugins/TwitterPlugin/UserAgent.pm +++ b/lib/Foswiki/Plugins/TwitterPlugin/UserAgent.pm @@ -1,6 +1,6 @@ # Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ # -# TwitterPlugin is Copyright (C) 2014 Michael Daum http://michaeldaumconsulting.com +# TwitterPlugin is Copyright (C) 2014-2016 Michael Daum http://michaeldaumconsulting.com # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -31,16 +31,24 @@ sub new { $this->{cacheExpire} = $Foswiki::cfg{TwitterPlugin}{CacheExpire}; $this->{cacheExpire} = 3600 unless defined $this->{cacheExpire}; - $this->{cache} = Cache::FileCache->new({ - 'cache_root' => Foswiki::Func::getWorkArea('TwitterPlugin') . '/cache', - 'default_expires_in' => $this->{cacheExpire}, - 'directory_umask' => 077, - } - ); - return $this; } +sub cache { + my $this = shift; + + unless ($this->{cache}) { + $this->{cache} = Cache::FileCache->new({ + 'cache_root' => Foswiki::Func::getWorkArea('TwitterPlugin') . '/cache', + 'default_expires_in' => $this->{cacheExpire}, + 'directory_umask' => 077, + } + ); + } + + return $this->{cache}; +} + sub expires { my ($this, $val) = @_; @@ -71,7 +79,7 @@ sub request { my $cacheKey = $Foswiki::cfg{TwitterPlugin}{APIKey} . $uri; - $obj = $this->{cache}->get($cacheKey) unless $refresh; + $obj = $this->cache->get($cacheKey) unless $refresh; if (defined $obj) { #print STDERR "... found in cache $uri\n"; @@ -84,7 +92,7 @@ sub request { ## cache only "200 OK" content if ($res->code eq HTTP::Status::RC_OK) { - $this->{cache}->set($cacheKey, $res->as_string, $this->{cacheExpire}); + $this->cache->set($cacheKey, $res->as_string, $this->{cacheExpire}); } return $res; diff --git a/lib/Foswiki/Plugins/TwitterPlugin/build.pl b/lib/Foswiki/Plugins/TwitterPlugin/build.pl index a51760e..3e2df4d 100755 --- a/lib/Foswiki/Plugins/TwitterPlugin/build.pl +++ b/lib/Foswiki/Plugins/TwitterPlugin/build.pl @@ -12,20 +12,6 @@ BEGIN # Create the build object my $build = new Foswiki::Contrib::Build('TwitterPlugin'); -# (Optional) Set the details of the repository for uploads. -# This can be any web on any accessible Foswiki installation. -# These defaults will be used when expanding tokens in .txt -# files, but be warned, they can be overridden at upload time! - -# name of web to upload to -$build->{UPLOADTARGETWEB} = 'Extensions'; -# Full URL of pub directory -$build->{UPLOADTARGETPUB} = 'http://foswiki.org/pub'; -# Full URL of bin directory -$build->{UPLOADTARGETSCRIPT} = 'http://foswiki.org/bin'; -# Script extension -$build->{UPLOADTARGETSUFFIX} = ''; - # Build the target on the command line, or the default target $build->build($build->{target});