1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
2 |
|
# |
3 |
|
# Facebook appliaction which use Koha's RSS search results |
4 |
|
# 2009-06-27 Dobrica Pavlinusic <dpavlin@rot13.org> |
5 |
|
# |
6 |
|
# Based on WWW::Facebook::API example |
7 |
# Copyright David Leadbeater 2007 <http://dgl.cx>. |
# Copyright David Leadbeater 2007 <http://dgl.cx>. |
8 |
# Licensed under the same terms as Perl itself. |
# Licensed under the same terms as Perl itself. |
9 |
|
|
|
# A simple example of using WWW::Facebook::API within a facebook canvas. |
|
|
# You will need to change the api_key, secret and app_path below to match your |
|
|
# account. To get an api_key and secret, go to |
|
|
# http://www.facebook.com/developers/editapp.php?new, choose "Use FBML" and |
|
|
# enter a unique name for the canvas which you should put into app_path. |
|
|
|
|
10 |
use strict; |
use strict; |
11 |
use CGI; |
use CGI; |
12 |
use WWW::Facebook::API; |
use WWW::Facebook::API; |
19 |
|
|
20 |
# UI elements |
# UI elements |
21 |
|
|
22 |
|
my $facebook = WWW::Facebook::API->new( |
23 |
|
api_key => $api_key, |
24 |
|
secret => $secret, |
25 |
|
app_path => $app_path, |
26 |
|
parse => 1, |
27 |
|
); |
28 |
|
|
29 |
|
warn dump($facebook); |
30 |
|
|
31 |
sub dashboard { |
sub dashboard { |
32 |
print qq| |
print qq| |
33 |
<fb:dashboard> |
<fb:dashboard> |
34 |
<fb:action href=/$app_path/>Search</fb:action> |
<fb:action href=/$app_path/>Search</fb:action> |
|
<fb:action href=/$app_path/info>info</fb:action> |
|
35 |
</fb:dashboard> |
</fb:dashboard> |
36 |
|; |
|; |
37 |
''; |
''; |
51 |
''; |
''; |
52 |
} |
} |
53 |
|
|
54 |
|
# dispatcher |
|
my $facebook = WWW::Facebook::API->new( |
|
|
api_key => $api_key, |
|
|
secret => $secret, |
|
|
app_path => $app_path, |
|
|
parse => 1, |
|
|
); |
|
55 |
|
|
56 |
our %action_map = ( |
our %action_map = ( |
57 |
'' => \&index_page, |
'' => \&index_page, |
84 |
|
|
85 |
my ( $action, $param ) = ( $q->path_info =~ m!^/(\w+)/?(.*)! ); |
my ( $action, $param ) = ( $q->path_info =~ m!^/(\w+)/?(.*)! ); |
86 |
|
|
|
if ( my $s = $action_map{$action} ) { |
|
87 |
print dashboard; |
print dashboard; |
88 |
|
|
89 |
|
if ( my $s = $action_map{$action} ) { |
90 |
print qq|<div style='padding-left: 2em'>|; |
print qq|<div style='padding-left: 2em'>|; |
91 |
$s->( $q, $params ); |
$s->( $q, $params ); |
92 |
print qq|</div>|; |
print qq|</div>|; |
93 |
} |
} |
94 |
else { |
else { |
95 |
div_error("Action unknown"); |
print "Action <tt>$action</tt> unknown"; |
96 |
|
warn "unknown action $action"; |
97 |
} |
} |
98 |
|
|
99 |
# Clear session_key (for if running under FastCGI). |
# Clear session_key (for if running under FastCGI). |
103 |
sub index_page { |
sub index_page { |
104 |
my ( $q, $params ) = @_; |
my ( $q, $params ) = @_; |
105 |
|
|
106 |
form($q); |
warn dump($params); |
107 |
|
|
108 |
=for later |
form($q); |
109 |
|
|
110 |
# 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. |
111 |
|
# http://wiki.developers.facebook.com/index.php/User_(FQL) |
112 |
my $name = "You"; |
my $name = "You"; |
113 |
if ($params) { |
if ( my $uid = $params->{user} ) { |
114 |
my $res = |
my $res = $facebook->fql->query( query => qq| |
115 |
$facebook->fql->query( query => |
select |
116 |
"SELECT first_name FROM user WHERE uid=$params->{canvas_user}" ); |
first_name, last_name, |
117 |
$name = "Hi $res->[0]->{first_name}, you"; |
is_app_user, |
118 |
|
books, |
119 |
|
locale |
120 |
|
from user |
121 |
|
where uid=$uid |
122 |
|
| ); |
123 |
|
warn "# $uid res = ",dump(@{$res}); |
124 |
|
$name = "Hello $res->[0]->{first_name}, you"; |
125 |
} |
} |
126 |
print "$name ", ( $params ? "have" : "have't" ), |
print "$name ", ( $params ? "have" : "have't" ), |
127 |
" added this application. Some <a href='info'>info</a>."; |
" added this application."; |
128 |
|
|
129 |
if ( !$params ) { |
if ( !$params ) { |
130 |
print "<a href='", $facebook->get_add_url, |
print "<a href='", $facebook->get_add_url, |
131 |
"'>Add this application</a>."; |
"'>Add this application</a>."; |
132 |
} |
} |
133 |
|
|
|
=cut |
|
134 |
|
|
135 |
|
|
136 |
} |
} |