/[koha-facebook]/koha-facebook.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /koha-facebook.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Fri Jun 26 17:20:04 2009 UTC revision 2 by dpavlin, Fri Jun 26 18:45:33 2009 UTC
# Line 13  use CGI; Line 13  use CGI;
13  use WWW::Facebook::API;  use WWW::Facebook::API;
14  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
15  use XML::FeedPP;  use XML::FeedPP;
16    use Time::HiRes qw/time/;
17    
18  our ($api_key,$secret,$rss_url); # XXX configure this in config.pl  our ($api_key,$secret,$rss_url,$app_path); # XXX configure this in config.pl
19  require 'config.pl';  require 'config.pl';
20    
21    # UI elements
22    
23    sub dashboard {
24            print qq|
25                    <fb:dashboard>
26                    <fb:action href=/$app_path/>Search</fb:action>
27                    <fb:action href=/$app_path/info>info</fb:action>
28                    </fb:dashboard>
29            |;
30            '';
31    }
32    
33    sub form {
34            my $q = shift;
35            my $v = $q->param('search');
36            $v = qq| value="$v"| if defined $v;
37    
38            print qq|
39    <form method="post" action="search">
40    <input name="search" $v>
41    <input type="submit">
42    </form>
43            |;
44            '';
45    }
46    
47    
48  my $facebook = WWW::Facebook::API->new(  my $facebook = WWW::Facebook::API->new(
49          api_key  => $api_key,          api_key  => $api_key,
50          secret   => $secret,          secret   => $secret,
51          app_path => "ffzg-koha",          app_path => $app_path,
52          parse    => 1,          parse    => 1,
53  );  );
54    
# Line 28  our %action_map = ( Line 56  our %action_map = (
56          ''   => \&index_page,          ''   => \&index_page,
57          info => \&info_page,          info => \&info_page,
58          search => \&search_page,          search => \&search_page,
59            debug => \&debug_page,
60  );  );
61    
62  sub main {  sub main {
# Line 53  sub main { Line 82  sub main {
82      }      }
83    
84      my ( $action, $param ) = ( $q->path_info =~ m!^/(\w+)/?(.*)! );      my ( $action, $param ) = ( $q->path_info =~ m!^/(\w+)/?(.*)! );
85    
86      if ( my $s = $action_map{$action} ) {      if ( my $s = $action_map{$action} ) {
87            print dashboard;
88            print qq|<div style='padding-left: 2em'>|;
89          $s->( $q, $params );          $s->( $q, $params );
90            print qq|</div>|;
91      }      }
92      else {      else {
93          div_error("Action unknown");          div_error("Action unknown");
# Line 65  sub main { Line 98  sub main {
98  }  }
99    
100  sub index_page {  sub index_page {
101      my ( $q, $params ) = @_;          my ( $q, $params ) = @_;
102    
103            form($q);
104    
105      print "<fb:header/><div style='padding: 20px'>";  =for later
106    
107  # You could do this easier by using <fb:name>, just showing some API stuff here.  # You could do this easier by using <fb:name>, just showing some API stuff here.
108      my $name = "You";      my $name = "You";
# Line 83  sub index_page { Line 118  sub index_page {
118          print "<a href='", $facebook->get_add_url,          print "<a href='", $facebook->get_add_url,
119              "'>Add this application</a>.";              "'>Add this application</a>.";
120      }      }
     print "</div>";  
121    
122          print qq{  =cut
   
 <form method="post" action="search">  
 <input name="search">  
 <input type="submit">  
 </form>  
   
         };  
123    
124    
125  }  }
126    
127  sub info_page {  sub info_page {
128      my ( $q, $params ) = @_;          open( my $fh, '<', 'info.html' );
129            print <$fh>;
130            close($fh);
131    }
132    
133      print "<fb:header/><div style='padding: 20px'><pre>";  sub debug_page {
134            my ( $q, $params ) = @_;
135        print "<pre>";
136      print dump($params);      print dump($params);
137      print "</pre></div>";      print "</pre>";
138  }  }
139    
140  sub search_page {  sub search_page {
141          my ( $q, $params ) = @_;          my ( $q, $params ) = @_;
142        
143          my $search = $q->param('search');          my $search = $q->param('search');
144    
145            my $t = time();
146    
147            my $feed = XML::FeedPP->new( $rss_url . $search );
148    
149            my $t = time() - $t;
150    
151          print qq|          print form($q), qq|
                 <fb:header/>  
                 <div style='padding: 20px'>  
                 Search results for <em>$search</em>  
152                  <ol>                  <ol>
153          |;          |;
154    
         my $feed = XML::FeedPP->new( $rss_url . $search );  
   
155          foreach my $item ( $feed->get_item ) {          foreach my $item ( $feed->get_item ) {
156                  print qq|<li><a href="|, $item->link, qq|">|, $item->title, qq|</a><br>|, $item->description;                  print qq|<li><a href="|, $item->link, qq|">|, $item->title, qq|</a><br>|, $item->description;
157          }          }
158    
159          print qq|          print qq|
160                  </ol>                  </ol>
161                  </div>  
162                    <div style="color: #ccc;">search took $t sec</div>
163          |;          |;
164    
165  }  }
166    
167  sub redirect {  sub redirect {
168      div_error("Please go <a href='"      print("Please go <a href='"
169              . $facebook->get_app_url              . $facebook->get_app_url
170              . "'>to facebook</a>" );              . "'>to facebook</a>" );
171      exit;      exit;
172  }  }
173    
 sub div_error {  
     print "<div style='padding: 20px'>", join( "", @_ ), "</div>";  
 }  
   
174  main();  main();

Legend:
Removed from v.1  
changed lines
  Added in v.2

  ViewVC Help
Powered by ViewVC 1.1.26