-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbs.admin.inc
104 lines (91 loc) · 3.56 KB
/
fbs.admin.inc
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
<?php
// $Id: fb_social.admin.inc,v 1.2.2.8 2010/11/21 03:22:23 ferdi Exp $
/**
* Settings form for global fbs custimazation
*/
function fbs_admin_settings_form(){
$languages = language_list();
$form = array();
$form['fbs_appid'] = array(
'#title' => t('Facebook application id'),
'#type' => 'textfield',
'#description' => t('<p> Register your application on Facebook to get a Facebook App Id: !url.</p>
<p>Go on your facebook app page (Applications > Developer > My Applications)
click "Edit Settings". Then click "Connect". Make sure that the "Connect
URL" matches your domain exactly.</p>', array(
'!url' => l('register here', 'http://developers.facebook.com/setup/')
)),
'#default_value' => variable_get('fbs_appid', '')
);
/*
$form['fbs_secret'] = array(
'#title' => t('Facebook application secret ky'),
'#type' => 'textfield',
'#description' => t('Facebook application secret key'),
'#default_value' => variable_get('fbs_secret', '')
);
*/
$form['fbs_locale'] = array(
'#title' => t('Default facebook application locale'),
'#type' => 'select',
'#default_value' => variable_get('fbs_locale', 'en_US'),
'#description' => t('Your facebook application locale'),
'#options' => _get_facebook_locale()
);
$form['fbs_urls'] = array(
'#type' => 'fieldset',
'#title' => t('Submitted urls mode'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['fbs_urls']['fbs_urls_mode'] = array(
'#type' => 'radios',
'#title' => t('urls mode'),
'#default_value' => variable_get('fbs_urls_mode', 0),
'#options' => array(t('aliased'), t('Unaliased')),
'#description' => t('The url version of your post you want to be shown in fb. Aliased - http://example.com/mypage, Unaliased - http://example.com/node/34')
);
$form['fbs_languages'] = array(
'#type' => 'fieldset',
'#title' => t('Languages mapping'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['fbs_languages']['fbs_locale_auto'] = array(
'#title' => t('Auto translate plugin'),
'#type' => 'checkbox',
'#default_value' => variable_get('fbs_locale_auto', 0),
'#description' => t('Check to automatically detect current node\'s language based on the settings below. Uncheck this if you want to force the node to use the default facebook locale set earlier'),
);
foreach ($languages as $language) {
$form['fbs_languages']['fbs_language_'. $language->language] = array(
'#type' => 'select',
'#title' => 'Mapping for ' . $language->name . ' (' . $language->language . ')',
'#description' => t('Select the equivalent language code in the facebook locale'),
'#default_value' => variable_get('fbs_language_' . $language->language, 'en_US'),
'#options' => _get_facebook_locale(),
);
}
$form = system_settings_form($form);
return $form;
}
function _get_facebook_locale(){
$fb_locale = array();
$cache = cache_get('fbs');
if (empty($cache->data)) {
$result = drupal_http_request("http://www.facebook.com/translations/FacebookLocales.xml");
$xml = simplexml_load_string($result->data);
foreach ( $xml->locale as $line ) {
$representation = ( array ) $line->codes->code->standard->representation;
$name = ( array ) $line->englishName;
$key = $representation[0];
$value = $name[0];
$fb_locale[$key] = $value;
}
cache_set('fbs', serialize($fb_locale), 'cache');
}
else {
$fb_locale = unserialize($cache->data);
}
return $fb_locale;
}