root/lang/perl/Jipotter/trunk/lib/Jipotter/Model/Status.pm @ 3660

Revision 3660, 1.6 kB (checked in by charsbar, 7 years ago)

lang/perl/Jipotter: switched from WWW::Shorten::TinyURL to WWW::Lengthen

  • Property svn:eol-style set to native
Line 
1package Jipotter::Model::Status;
2
3use strict;
4use warnings;
5use Time::Piece;
6use URI;
7use HTML::Entities;
8use WWW::Lengthen;
9
10my $lengthener = WWW::Lengthen->new;
11
12use Jifty::DBI::Schema;
13use Jifty::Record schema {
14  column text            => type is 'varchar', max_length is 255;
15  column html            => type is 'varchar', max_length is 255;
16  column link            => type is 'varchar', max_length is 255;
17  column user_nick       => type is 'varchar', max_length is 255;
18  column user_login_id   => type is 'varchar', max_length is 255;
19  column package_name    => type is 'varchar', max_length is 255;
20  column user_url        => type is 'varchar', max_length is 255;
21  column profile_img_url => type is 'varchar', max_length is 255;
22  column epoch           => type is 'integer', is mandatory;
23};
24
25sub ymd { localtime( shift->epoch )->ymd }
26sub hms { localtime( shift->epoch )->hms }
27
28sub linked_text {
29  my $self = shift;
30  my $text = $self->text;
31
32  $text =~ s{(http://[!-~]+)}{_convert_uri($1)}ge;
33
34  if ( $self->package_name eq 'Twitter' ) {
35    $text =~ s{\@([a-zA-Z0-9_]+)}{_convert_id('twitter.com',$1)}ge;
36  }
37  if ( $self->package_name eq 'Wassr' ) {
38    $text =~ s{\@([a-zA-Z0-9_]+)}{_convert_id('wassr.jp/user',$1)}ge;
39  }
40
41  $text;
42}
43
44sub _convert_uri {
45  my $uri = URI->new( $lengthener->try( decode_entities( shift ) ) );
46
47  return q{<a href="}."$uri".q{">}.
48         encode_entities("$uri", "\000-\377").q{</a>};
49}
50
51sub _convert_id {
52  my ($base, $id) = @_;
53  my $uri = URI->new( "http://$base/$id" );
54  return q{@<a href="}."$uri".q{">}.$id.q{</a>};
55}
56
57sub current_user_can { 1 }
58
591;
60
Note: See TracBrowser for help on using the browser.