summaryrefslogtreecommitdiff
path: root/_darcs/pristine/actions/facebooksettings.php
blob: d28b1aa5ca95b7027be03d16b15bcce04b9ac6a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/*
 * Laconica - a distributed open-source microblogging tool
 * Copyright (C) 2008, Controlez-Vous, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.     If not, see <http://www.gnu.org/licenses/>.
 */

if (!defined('LACONICA')) { exit(1); }

require_once(INSTALLDIR.'/lib/facebookaction.php');

class FacebooksettingsAction extends FacebookAction
{

    function handle($args)
    {
        parent::handle($args);

        if ($this->arg('save')) {
            $this->save_settings();
        } else {
            $this->show_form();
        }
    }


    function save_settings() {

        $noticesync = $this->arg('noticesync');
        $replysync = $this->arg('replysync');

        $facebook = get_facebook();
        $fbuid = $facebook->require_login();

        $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook

        $original = clone($flink);
        $flink->set_flags($noticesync, $replysync, false);
        $result = $flink->update($original);

        if ($result) {
            echo '<fb:success message="Sync preferences saved." />';
        }

        $this->show_form();

    }

    function show_form() {

        $facebook = get_facebook();
        $fbuid = $facebook->require_login();

        $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook

        $this->show_header('Settings');

        $fbml = '<fb:if-section-not-added section="profile">'
            .'<h2>Add an Identi.ca box to my profile</h2>'
            .'<p><fb:add-section-button section="profile"/></p>'
            .'</fb:if-section-not-added>';

        $fbml .= '<p><fb:prompt-permission perms="status_update"><h2>Allow Identi.ca to update my Facebook status</h2></fb:prompt-permission></p>';

        if ($facebook->api_client->users_hasAppPermission('status_update')) {

        $fbml .= '<form method="post" id="facebook_settings">'
        .'<h2>Sync preferences</h2>'
        .'<p>';

        if ($flink->noticesync & FOREIGN_NOTICE_SEND) {
            $fbml .= '<input name="noticesync" type="checkbox" class="checkbox" id="noticesync" checked="checked"/>';
        } else {
            $fbml .= '<input name="noticesync" type="checkbox" class="checkbox" id="noticesync">';
        }

        $fbml .= '<label class="checkbox_label" for="noticesync">Automatically update my Facebook status with my notices.</label>'
        .'</p>'
        .'<p>';

        if ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) {
            $fbml .= '<input name="replysync" type="checkbox" class="checkbox" id="replysync" checked="checked"/>';
        } else {
            $fbml .= '<input name="replysync" type="checkbox" class="checkbox" id="replysync"/>';
        }

        $fbml .= '<label class="checkbox_label" for="replysync">Send &quot;@&quot; replies to Facebook.</label>'
        .'</p>'
        .'<p>'
        .'<input type="submit" id="save" name="save" class="submit" value="Save"/>'
        .'</p>'
        .'</form>';

    }

        echo $fbml;

        $this->show_footer();
    }

}