]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/facebookutil.php
Add a menuItem method to Action
[quix0rs-gnu-social.git] / lib / facebookutil.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 require_once(INSTALLDIR.'/extlib/facebook/facebook.php');
21 require_once(INSTALLDIR.'/lib/noticelist.php');
22
23 define("FACEBOOK_SERVICE", 2); // Facebook is foreign_service ID 2
24
25 // Gets all the notices from users with a Facebook link since a given ID
26 function get_facebook_notices($since)
27 {
28     $qry = 'SELECT notice.* ' .
29         'FROM notice ' .
30         'JOIN foreign_link ' .
31         'WHERE notice.profile_id = foreign_link.user_id ' .
32         'AND foreign_link.service = 2';
33
34     // XXX: What should the limit be?
35     return Notice::getStreamDirect($qry, 0, 100, 0, 0, null, $since);
36 }
37
38 function get_facebook()
39 {
40     $apikey = common_config('facebook', 'apikey');
41     $secret = common_config('facebook', 'secret');
42     return new Facebook($apikey, $secret);
43 }
44
45 function start_fbml($indent = true)
46 {
47     global $xw;
48     $xw = new XMLWriter();
49     $xw->openURI('php://output');
50     $xw->setIndent($indent);
51 }
52
53 function update_profile_box($facebook, $fbuid, $user, $notice)
54 {
55
56     // Need to include inline CSS for styling the Profile box
57
58     $style = '<style>
59      #notices {
60          clear: both;
61          margin: 0 auto;
62          padding: 0;
63          list-style-type: none;
64          width: 600px;
65          border-top: 1px solid #dec5b5;
66      }
67      #notices a:hover {
68          text-decoration: underline;
69      }
70      .notice_single {
71          clear: both;
72          display: block;
73          margin: 0;
74          padding: 5px 5px 5px 0;
75          min-height: 48px;
76          font-family: Georgia, "Times New Roman", Times, serif;
77          font-size: 13px;
78          line-height: 16px;
79          border-bottom: 1px solid #dec5b5;
80          background-color:#FCFFF5;
81          opacity:1;
82      }
83      .notice_single:hover {
84          background-color: #f7ebcc;
85      }
86      .notice_single p {
87          display: inline;
88          margin: 0;
89          padding: 0;
90      }
91      </style>';
92
93     global $xw;
94     $xw = new XMLWriter();
95     $xw->openMemory();
96
97     $item = new NoticeListItem($notice);
98     $item->show();
99
100     $fbml = "<fb:wide>$style " . $xw->outputMemory(false) . "</fb:wide>";
101     $fbml .= "<fb:narrow>$style " . $xw->outputMemory(false) . "</fb:narrow>";
102
103     $fbml_main = "<fb:narrow>$style " . $xw->outputMemory(false) . "</fb:narrow>";
104
105     $facebook->api_client->profile_setFBML(null, $fbuid, $fbml, null, null, $fbml_main);
106 }