/
qa-profile-sharer-widget.php
121 lines (106 loc) · 3.77 KB
/
qa-profile-sharer-widget.php
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
114
115
116
117
118
119
120
121
<?php
require(__DIR__ . '/lib/src/Facebook/autoload.php');
class qa_profile_sharer_widget {
function allow_template($template)
{
return ($template=='user');
}
function allow_region($region)
{
return ($region=='main');
}
function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
require_once QA_INCLUDE_DIR.'qa-app-users.php';
$allowEdit=!qa_user_permit_error('fb_share_permit_edit');
$parts=explode('/', qa_self_html());
if($allowEdit && $parts[2] == qa_get_logged_in_handle()) {
$appid = qa_opt('fb_app_id');
$secret = qa_opt('fb_app_secret');
$fb = new Facebook\Facebook([
'app_id' => $appid,
'app_secret' => $secret,
'default_graph_version' => 'v2.4',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email', 'publish_actions'];
$callback = 'http://nathorr.com/qeta/fb-share/' . qa_get_logged_in_handle() . '/';
$loginUrl = $helper->getLoginUrl($callback, $permissions);
echo '<a href="' . $loginUrl . '"><img src="http://oi57.tinypic.com/f1xlbt.jpg"></a>';
}
}
function option_default($option)
{
if ($option=='fb_shared_message_title')
return 'My profile - Q&A';
if ($option=='fb_shared_message_picture')
return 'http://oi61.tinypic.com/2j1otpg.jpg';
if ($option=='fb_shared_message_description')
return 'Q&A helps your online community to share knowledge.';
if ($option=='fb_share_permit_edit') {
require_once QA_INCLUDE_DIR.'qa-app-options.php';
return QA_PERMIT_USERS;
}
return null;
}
function admin_form() {
require_once QA_INCLUDE_DIR.'qa-app-admin.php';
require_once QA_INCLUDE_DIR.'qa-app-options.php';
$permitoptions=qa_admin_permit_options(QA_PERMIT_USERS, QA_PERMIT_SUPERS, false, false);
$saved=false;
if (qa_clicked('fb_save_button')) {
qa_opt('fb_app_id', qa_post_text('fb_app_id_field'));
qa_opt('fb_app_secret', qa_post_text('fb_app_secret_field'));
qa_opt('fb_shared_message_title', qa_post_text('fb_shared_message_title_field'));
qa_opt('fb_shared_message_picture', qa_post_text('fb_shared_message_picture_field'));
qa_opt('fb_shared_message_description', qa_post_text('fb_shared_message_description_field'));
qa_opt('fb_share_permit_edit', (int)qa_post_text('fb_share_pe_field'));
$saved=true;
}
$ready=strlen(qa_opt('fb_app_id')) && strlen(qa_opt('fb_app_secret'));
return array(
'ok' => $saved ? 'Facebook application details saved' : null,
'fields' => array(
array(
'label' => 'Facebook App ID:',
'value' => qa_html(qa_opt('fb_app_id')),
'tags' => 'name="fb_app_id_field"',
),
array(
'label' => 'Facebook App Secret:',
'value' => qa_html(qa_opt('fb_app_secret')),
'tags' => 'name="fb_app_secret_field"',
'error' => $ready ? null : 'To use Facebook Login, please <a href="http://developers.facebook.com/setup/" target="_blank">set up a Facebook application</a>.',
),
array(
'label' => 'Title of the shared message:',
'value' => qa_html(qa_opt('fb_shared_message_title')),
'tags' => 'name="fb_shared_message_title_field"',
),
array(
'label' => 'Link to the picture of shared message:',
'value' => qa_html(qa_opt('fb_shared_message_picture')),
'tags' => 'name="fb_shared_message_picture_field"',
),
array(
'label' => 'Description of the shared message:',
'value' => qa_html(qa_opt('fb_shared_message_description')),
'tags' => 'name="fb_shared_message_description_field"',
),
array(
'label' => 'Allow using:',
'type' => 'select',
'value' => @$permitoptions[qa_opt('fb_share_permit_edit')],
'options' => $permitoptions,
'tags' => 'name="fb_share_pe_field"',
),
),
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'name="fb_save_button"',
),
),
);
}
}