/[Grep]/lib/Grep/Model/Feed.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/Grep/Model/Feed.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 196 - (hide annotations)
Wed May 28 17:52:06 2008 UTC (16 years ago) by dpavlin
File size: 2320 byte(s)
added login and passwd to feed model in preparation
to handle 401 Authorization Required
1 dpavlin 2 use strict;
2     use warnings;
3    
4     package Grep::Model::Feed;
5     use Jifty::DBI::Schema;
6    
7 dpavlin 19 use Feed::Find;
8 dpavlin 58 use Scalar::Defer;
9     use Grep::Model::User;
10 dpavlin 19
11 dpavlin 2 use Grep::Record schema {
12    
13     column uri =>
14     type is 'text',
15     label is 'URI',
16 dpavlin 19 hints is 'Replace search string in URI with %s (grep will be replaced automatically)',
17 dpavlin 65 is mandatory;
18 dpavlin 2
19 dpavlin 3 column title =>
20     type is 'text',
21 dpavlin 19 label is 'Title',
22 dpavlin 12 hints is 'Use something descriptive to you',
23 dpavlin 3 since '0.0.2';
24    
25 dpavlin 19 column cookie =>
26     type is 'text',
27     label is 'Cookie',
28     render as 'textarea',
29 dpavlin 73 hints is 'If you leave Cookie data Grep will impersonate you to feed provider!',
30 dpavlin 19 since '0.0.3';
31    
32 dpavlin 58 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 dpavlin 73 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 dpavlin 196 column login =>
53     type is 'text',
54     label is 'Login',
55     since '0.0.8';
56    
57     column passwd =>
58     type is 'text',
59     label is 'Login',
60     since '0.0.8';
61    
62 dpavlin 2 };
63    
64 dpavlin 3 sub since { '0.0.1' }
65    
66 dpavlin 2 # Your model-specific methods go here.
67    
68 dpavlin 19 =head2 search_uri
69    
70     print $feed->search_uri('search string');
71    
72     This function will decode field delimiters C<|!|> into normal C<;>
73     (which are protected to make AJAX validation work)
74    
75     =cut
76    
77     sub search_uri {
78     my $self = shift;
79     my $search = shift;
80    
81     my $uri = $self->uri or die "no uri?";
82 dpavlin 124 $uri =~ s/^https:/http:/;
83 dpavlin 19 $uri =~ s/\Q|!|\E/;/g;
84 dpavlin 81 $uri =~ s/{x!(26|3b)}/chr(hex($1))/gei;
85 dpavlin 19 return sprintf( $uri, $search );
86     }
87    
88 dpavlin 166 =head2 home_page_uri
89 dpavlin 19
90 dpavlin 166 print $feed->home_page_uri
91    
92     Try to strip search arguments from C<uri> and construct home page URI
93    
94     =cut
95    
96     sub home_page_uri {
97     my $self = shift;
98     my $uri = $self->search_uri('foo');
99     $uri =~ s/\?.*$//g;
100     return $uri;
101     }
102    
103    
104 dpavlin 37 sub current_user_can {
105     my $self = shift;
106     my $what = shift;
107    
108 dpavlin 58 my $uid = Jifty->web->current_user->id;
109 dpavlin 37
110 dpavlin 143 # superuser
111     return 1 if ( defined $uid && $uid == 0 );
112 dpavlin 58
113 dpavlin 143 return 1 if ( $uid && $what eq 'create' );
114    
115 dpavlin 58 return 1 if ( $uid && ! $self->id );
116    
117 dpavlin 120 return 1 if ( $uid && $uid == $self->owner->id );
118 dpavlin 58
119 dpavlin 167 #warn "$uid can't $what";
120 dpavlin 37 }
121    
122 dpavlin 2 1;
123    

  ViewVC Help
Powered by ViewVC 1.1.26