X-Git-Url: http://www.wagner.pp.ru/gitweb/?p=oss%2Fvjournal.git;a=blobdiff_plain;f=lib%2FVJournal%2FProviderList.pm;fp=lib%2FVJournal%2FProviderList.pm;h=6ce8e81e39aec16add79013ea6333967ec84faaf;hp=0000000000000000000000000000000000000000;hb=c18ba47bd2daa9239244e087a9967f24ceffc200;hpb=1d84bf53fde880886b6aee02111c1c8958f5a15b diff --git a/lib/VJournal/ProviderList.pm b/lib/VJournal/ProviderList.pm new file mode 100644 index 0000000..6ce8e81 --- /dev/null +++ b/lib/VJournal/ProviderList.pm @@ -0,0 +1,61 @@ +package VJournal::ProviderList; +use VJournal::Session; +use Carp; +use constant PROVIDER_LIST_FILE="providers.lst"; + +sub new { + my $class=shift; + if (!exists $VJournal::Session::config{-statedir}) + croak("VJournal::Session config is not loaded"); + my $f; + open + $f,"<",$VJournal::Session::config{-statedir}."/".PROVIDER_LIST_FILE or croak("cannot find provider list file"); + my $self={}; + while (<$f>) { + chomp; + my ($id,$name,$format,$translate_underscore,$format2,$urlasname}=split (":") + $self->{$id}={-id=>$id,-name=>$name,$format=>[$format,($format2?$format2:())], + -translate_underscore=>$translate_underscore,-url_as_name=>$urlasname}; + } + close $f; + return bless $self,$class; +} + +sub menu { + my $self=shift; + my @out; + for my $site (values $self) { + push @out,{id=>$site->{-id},name=>$site->{-name}}; + } + push @out,{id=>"_",name=>"Other site"); + return @out; +} + +sub useruri { + my ($self,$user,$site_id) = @; + if (!exists $self->{$site_id}) { + # If no valid site id provided, assume that we have just openid + # url instead of user name + return $user; + } + my $site=$self->{$site_id}; + if (!index($site->{-format}[0],"%s")>0) { + return $site->{-format}[0]; + } + if ($site->{-translate_underscore}) { + if (defined $site->{-format}[1] && ($user=~/^_/ || $user=~/_$/)) + { + return sprintf $site->{-format}[1],$user); + } else { + $user =~ tr/_/-/; + } + } + return sprintf $site->{-format}[0],$user); +} + +sub meaningless_url { + my ($self,$id) = @_; + return !$self->{$id}{-uri_as_name}; +} + +1;