5 |
use Jifty::DBI::Schema; |
use Jifty::DBI::Schema; |
6 |
|
|
7 |
use Feed::Find; |
use Feed::Find; |
8 |
|
use Scalar::Defer; |
9 |
|
use Grep::Model::User; |
10 |
|
|
11 |
use Grep::Record schema { |
use Grep::Record schema { |
12 |
|
|
14 |
type is 'text', |
type is 'text', |
15 |
label is 'URI', |
label is 'URI', |
16 |
hints is 'Replace search string in URI with %s (grep will be replaced automatically)', |
hints is 'Replace search string in URI with %s (grep will be replaced automatically)', |
17 |
is mandatory, |
is mandatory; |
|
distinct; |
|
18 |
|
|
19 |
column title => |
column title => |
20 |
type is 'text', |
type is 'text', |
26 |
type is 'text', |
type is 'text', |
27 |
label is 'Cookie', |
label is 'Cookie', |
28 |
render as 'textarea', |
render as 'textarea', |
29 |
hints are 'If you leave Cookie data Grep will impersonate you to feed provider!', |
hints is 'If you leave Cookie data Grep will impersonate you to feed provider!', |
30 |
since '0.0.3'; |
since '0.0.3'; |
31 |
|
|
32 |
|
column owner => |
33 |
|
refers_to Grep::Model::User by 'id', |
34 |
|
label is 'Feed owner', |
35 |
|
default is defer { Jifty->web->current_user->id }, |
36 |
|
since '0.0.5'; |
37 |
|
|
38 |
|
column created_on => |
39 |
|
type is 'timestamp', |
40 |
|
label is 'Created On', |
41 |
|
default is defer { DateTime->now }, |
42 |
|
filters are 'Jifty::DBI::Filter::DateTime', |
43 |
|
since '0.0.5'; |
44 |
|
|
45 |
|
column source => |
46 |
|
type is 'text', |
47 |
|
label is 'Source', |
48 |
|
default is 'Grep::Source::Feed', |
49 |
|
# available are defer { Grep::Source::Feed->sources }, |
50 |
|
since '0.0.6'; |
51 |
|
|
52 |
}; |
}; |
53 |
|
|
54 |
sub since { '0.0.1' } |
sub since { '0.0.1' } |
55 |
|
|
56 |
# Your model-specific methods go here. |
# Your model-specific methods go here. |
57 |
|
|
|
=head2 canonicalize_uri |
|
|
|
|
|
Replace C<grep>' with C<%s> in URI arguments |
|
|
|
|
|
=cut |
|
|
|
|
|
sub canonicalize_uri { |
|
|
my $self = shift; |
|
|
my $value = shift; |
|
|
warn "uri: $value"; |
|
|
$value =~ s/=grep/=%s/; |
|
|
return $value; |
|
|
} |
|
|
|
|
58 |
=head2 search_uri |
=head2 search_uri |
59 |
|
|
60 |
print $feed->search_uri('search string'); |
print $feed->search_uri('search string'); |
69 |
my $search = shift; |
my $search = shift; |
70 |
|
|
71 |
my $uri = $self->uri or die "no uri?"; |
my $uri = $self->uri or die "no uri?"; |
72 |
|
$uri =~ s/^https:/http:/; |
73 |
$uri =~ s/\Q|!|\E/;/g; |
$uri =~ s/\Q|!|\E/;/g; |
74 |
|
$uri =~ s/{x!(26|3b)}/chr(hex($1))/gei; |
75 |
return sprintf( $uri, $search ); |
return sprintf( $uri, $search ); |
76 |
} |
} |
77 |
|
|
78 |
|
|
79 |
|
sub current_user_can { |
80 |
|
my $self = shift; |
81 |
|
my $what = shift; |
82 |
|
|
83 |
|
my $uid = Jifty->web->current_user->id; |
84 |
|
|
85 |
|
return 1 if ( defined $uid && $what eq 'create' ); |
86 |
|
|
87 |
|
return 1 if ( $uid && ! $self->id ); |
88 |
|
|
89 |
|
return 1 if ( $uid && $uid == $self->owner->id ); |
90 |
|
|
91 |
|
warn "$uid can't $what"; |
92 |
|
} |
93 |
|
|
94 |
1; |
1; |
95 |
|
|