1 | <?php
|
---|
2 | /**
|
---|
3 | * @author: Javier Reyes Gomez (http://www.sociable.es)
|
---|
4 | * @date: 05/10/2008
|
---|
5 | * @license: GPLv2
|
---|
6 | */
|
---|
7 |
|
---|
8 | function fb_get_loggedin_user() {
|
---|
9 | $fbclient = & facebook_client();
|
---|
10 | if ($fbclient)
|
---|
11 | return $fbclient->get_loggedin_user();
|
---|
12 | return null;
|
---|
13 | }
|
---|
14 |
|
---|
15 | function fb_user_getInfo($fb_user) {
|
---|
16 | $fbclient = & facebook_client();
|
---|
17 | if ($fbclient){
|
---|
18 | $fbapi_client = & $fbclient->api_client;
|
---|
19 | $userinfo = $fbapi_client->users_getInfo($fb_user, "about_me,profile_url,first_name,last_name,birthday,current_location,sex,pic,pic_small,pic_big,pic_square");
|
---|
20 | //print_r($userinfo);
|
---|
21 | if (isset($userinfo["users_getInfo_response"]) && isset($userinfo["users_getInfo_response"]["user"]))
|
---|
22 | return $userinfo["users_getInfo_response"]["user"];
|
---|
23 | else
|
---|
24 | return $userinfo;
|
---|
25 | }
|
---|
26 | return null;
|
---|
27 | }
|
---|
28 |
|
---|
29 | function fb_feed_getRegisteredTemplateBundles() {
|
---|
30 | $fbclient = & facebook_client();
|
---|
31 | if ($fbclient){
|
---|
32 | $fbapi_client = & $fbclient->api_client;
|
---|
33 | $templates = $fbapi_client->feed_getRegisteredTemplateBundles();
|
---|
34 |
|
---|
35 | if (isset($templates) && isset($templates["feed_getRegisteredTemplateBundles_response"]) && isset($templates["feed_getRegisteredTemplateBundles_response"]["template_bundle"])){
|
---|
36 | $templates = $templates["feed_getRegisteredTemplateBundles_response"]["template_bundle"];
|
---|
37 | if (!isset($templates[0])){
|
---|
38 | $newtemplates = array();
|
---|
39 | $newtemplates[] = $templates;
|
---|
40 | $templates = $newtemplates;
|
---|
41 | }
|
---|
42 | foreach ($templates as $key=>$template){ //PHP5 structure
|
---|
43 | if (isset($template["one_line_story_templates"]) && isset($template["one_line_story_templates"]["one_line_story_template"])){
|
---|
44 | $templates[$key]["one_line_story_templates"][]=$template["one_line_story_templates"]["one_line_story_template"];
|
---|
45 | }
|
---|
46 | if(isset($template["short_story_templates"]) && isset($template["short_story_templates"]["short_story_template"])){
|
---|
47 | $templates[$key]["short_story_templates"][]=$template["short_story_templates"]["short_story_template"];
|
---|
48 | }
|
---|
49 | }
|
---|
50 | return $templates;
|
---|
51 | }else{
|
---|
52 | return array();
|
---|
53 | }
|
---|
54 | }
|
---|
55 | return null;
|
---|
56 | }
|
---|
57 |
|
---|
58 | function fb_feed_registerTemplateBundle($one_line_stories,$short_stories,$full_stories){
|
---|
59 | $fbclient = & facebook_client();
|
---|
60 | if ($fbclient){
|
---|
61 | $fbapi_client = & $fbclient->api_client;
|
---|
62 | $response = $fbapi_client->feed_registerTemplateBundle($one_line_stories,$short_stories,$full_stories);
|
---|
63 | if (isset($response["feed_registerTemplateBundle_response"]))
|
---|
64 | return $response["feed_registerTemplateBundle_response"];
|
---|
65 | else
|
---|
66 | return $response;
|
---|
67 | }
|
---|
68 | return null;
|
---|
69 | }
|
---|
70 |
|
---|
71 | function fb_feed_deactivateTemplateBundleByID($templateID){
|
---|
72 | $fbclient = & facebook_client();
|
---|
73 | if ($fbclient){
|
---|
74 | $fbapi_client = & $fbclient->api_client;
|
---|
75 | $fbapi_client->feed_deactivateTemplateBundleByID($templateID);
|
---|
76 | }
|
---|
77 | return null;
|
---|
78 | }
|
---|
79 |
|
---|
80 | function fb_feed_getRegisteredTemplateBundleByID($templateID){
|
---|
81 | $fbclient = & facebook_client();
|
---|
82 | if ($fbclient){
|
---|
83 | $fbapi_client = & $fbclient->api_client;
|
---|
84 | return $fbapi_client->feed_getRegisteredTemplateBundleByID($templateID);
|
---|
85 | }
|
---|
86 | return null;
|
---|
87 | }
|
---|
88 |
|
---|
89 | function fb_fql_query($query){
|
---|
90 | $fbclient = & facebook_client();
|
---|
91 | if ($fbclient){
|
---|
92 | $fbapi_client = & $fbclient->api_client;
|
---|
93 | $response = $fbapi_client->fql_query($query);
|
---|
94 | if (isset($response["fql_query_response"]) && isset($response["fql_query_response"]["user"])){
|
---|
95 | if (isset($response["fql_query_response"]["user"][0])){
|
---|
96 | return $response["fql_query_response"]["user"];
|
---|
97 | }else{
|
---|
98 | $newresp = array();
|
---|
99 | $newresp[] = $response["fql_query_response"]["user"];
|
---|
100 | }
|
---|
101 | }
|
---|
102 | return $response;
|
---|
103 | }
|
---|
104 | return null;
|
---|
105 | }
|
---|
106 | function fb_expire_session(){
|
---|
107 | $fbclient = & facebook_client();
|
---|
108 | if ($fbclient && $fbclient->get_loggedin_user()!="") {
|
---|
109 | $fbclient->expire_session();
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | function fb_feed_publishUserAction($template_data){
|
---|
114 | $fbclient = & facebook_client();
|
---|
115 | if ($fbclient){
|
---|
116 | $fbapi_client = & $fbclient->api_client;
|
---|
117 | $feed_bundle_id = get_option('fb_templates_id');
|
---|
118 | $fbapi_client->feed_publishUserAction( $feed_bundle_id,
|
---|
119 | $template_data ,
|
---|
120 | null,
|
---|
121 | null,2);
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | function fb_showFeedDialog(){
|
---|
126 | $template_data = $_SESSION["template_data"];
|
---|
127 | if (isset($template_data) && $template_data!=""){
|
---|
128 | echo "<script type='text/javascript'>\n";
|
---|
129 | //echo "jQuery(window).ready(function() {\n"; NO FUNCIONA COMO EL ONLOAD
|
---|
130 | echo "window.onload = function() {\n";
|
---|
131 | echo "FB.ensureInit(function(){\n";
|
---|
132 | echo " FB.Connect.showFeedDialog(".get_option('fb_templates_id').", ".json_encode($template_data).", null, null, FB.FeedStorySize.full , FB.RequireConnect.promptConnect);";
|
---|
133 | echo "});\n";
|
---|
134 | echo " };\n";
|
---|
135 | //echo " });\n";
|
---|
136 | echo " </script>";
|
---|
137 | $_SESSION["template_data"] = "";
|
---|
138 | }
|
---|
139 |
|
---|
140 | }
|
---|
141 |
|
---|
142 | //REYES
|
---|
143 | function json_encode($data){
|
---|
144 | require_once 'facebook-client4/classes/JSON.php';
|
---|
145 | $json = new Services_JSON();
|
---|
146 | return $json->encode($data);
|
---|
147 | }
|
---|