/[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 3 by dpavlin, Fri Jun 26 21:14:01 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  my $facebook = WWW::Facebook::API->new(  my $facebook = WWW::Facebook::API->new(
24          api_key  => $api_key,          api_key  => $api_key,
25          secret   => $secret,          secret   => $secret,
26          app_path => "ffzg-koha",          app_path => $app_path,
27          parse    => 1,          parse    => 1,
28  );  );
29    
30    warn dump($facebook);
31    
32    sub dashboard {
33            print qq|
34                    <fb:dashboard>
35                    <fb:action href=/$app_path/>Search</fb:action>
36                    </fb:dashboard>
37            |;
38            '';
39    }
40    
41    sub form {
42            my $q = shift;
43            my $v = $q->param('search');
44            $v = qq| value="$v"| if defined $v;
45    
46            print qq|
47    <form method="post" action="search">
48    <input name="search" $v>
49    <input type="submit">
50    </form>
51            |;
52            '';
53    }
54    
55    # dispatcher
56    
57  our %action_map = (  our %action_map = (
58          ''   => \&index_page,          ''   => \&index_page,
59          info => \&info_page,          info => \&info_page,
60          search => \&search_page,          search => \&search_page,
61            debug => \&debug_page,
62  );  );
63    
64  sub main {  sub main {
# Line 53  sub main { Line 84  sub main {
84      }      }
85    
86      my ( $action, $param ) = ( $q->path_info =~ m!^/(\w+)/?(.*)! );      my ( $action, $param ) = ( $q->path_info =~ m!^/(\w+)/?(.*)! );
87    
88            print dashboard;
89    
90      if ( my $s = $action_map{$action} ) {      if ( my $s = $action_map{$action} ) {
91            print qq|<div style='padding-left: 2em'>|;
92          $s->( $q, $params );          $s->( $q, $params );
93            print qq|</div>|;
94      }      }
95      else {      else {
96          div_error("Action unknown");          print "Action <tt>$action</tt> unknown";
97            warn "unknown action $action";
98      }      }
99    
100      # Clear session_key (for if running under FastCGI).      # Clear session_key (for if running under FastCGI).
# Line 65  sub main { Line 102  sub main {
102  }  }
103    
104  sub index_page {  sub index_page {
105      my ( $q, $params ) = @_;          my ( $q, $params ) = @_;
106    
107    warn dump($params);
108    
109      print "<fb:header/><div style='padding: 20px'>";          form($q);
110    
111    =for later
112    
113  # 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.
114      my $name = "You";      my $name = "You";
# Line 79  sub index_page { Line 120  sub index_page {
120      }      }
121      print "$name ", ( $params ? "have" : "have't" ),      print "$name ", ( $params ? "have" : "have't" ),
122          " added this application. Some <a href='info'>info</a>.";          " added this application. Some <a href='info'>info</a>.";
123    =cut
124    
125      if ( !$params ) {      if ( !$params ) {
126          print "<a href='", $facebook->get_add_url,          print "<a href='", $facebook->get_add_url,
127              "'>Add this application</a>.";              "'>Add this application</a>.";
128      }      }
     print "</div>";  
   
         print qq{  
   
 <form method="post" action="search">  
 <input name="search">  
 <input type="submit">  
 </form>  
129    
         };  
130    
131    
132  }  }
133    
134  sub info_page {  sub info_page {
135      my ( $q, $params ) = @_;          open( my $fh, '<', 'info.html' );
136            print <$fh>;
137            close($fh);
138    }
139    
140      print "<fb:header/><div style='padding: 20px'><pre>";  sub debug_page {
141            my ( $q, $params ) = @_;
142        print "<pre>";
143      print dump($params);      print dump($params);
144      print "</pre></div>";      print "</pre>";
145  }  }
146    
147  sub search_page {  sub search_page {
148          my ( $q, $params ) = @_;          my ( $q, $params ) = @_;
149        
150          my $search = $q->param('search');          my $search = $q->param('search');
151    
152            my $t = time();
153    
154            my $feed = XML::FeedPP->new( $rss_url . $search );
155    
156            my $t = time() - $t;
157    
158          print qq|          print form($q), qq|
                 <fb:header/>  
                 <div style='padding: 20px'>  
                 Search results for <em>$search</em>  
159                  <ol>                  <ol>
160          |;          |;
161    
         my $feed = XML::FeedPP->new( $rss_url . $search );  
   
162          foreach my $item ( $feed->get_item ) {          foreach my $item ( $feed->get_item ) {
163                  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;
164          }          }
165    
166          print qq|          print qq|
167                  </ol>                  </ol>
168                  </div>  
169                    <div style="color: #ccc;">search took $t sec</div>
170          |;          |;
171    
172  }  }
173    
174  sub redirect {  sub redirect {
175      div_error("Please go <a href='"      print("Please go <a href='"
176              . $facebook->get_app_url              . $facebook->get_app_url
177              . "'>to facebook</a>" );              . "'>to facebook</a>" );
178      exit;      exit;
179  }  }
180    
 sub div_error {  
     print "<div style='padding: 20px'>", join( "", @_ ), "</div>";  
 }  
   
181  main();  main();

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

  ViewVC Help
Powered by ViewVC 1.1.26