now supporting page tab similar to canvas front page.
[project/fb.git] / fb_tab.admin.inc
1 <?php
2
3 /**
4 * @file
5 * Drupal administration of fb_tab.module.
6 */
7
8 /**
9 * Implementation of hook_fb_admin().
10 *
11 */
12 function fb_tab_fb_admin($op, $data, &$return) {
13 $fb = isset($data['fb']) ? $data['fb'] : NULL;
14 $fb_app = isset($data['fb_app']) ? $data['fb_app'] : NULL;
15 $config = _fb_tab_get_config($fb_app);
16 if ($op == FB_ADMIN_OP_SET_PROPERTIES) {
17 $return['tab_default_name'] = $config['tab_default_name'];
18
19 if ($config['tab_default_name']) {
20 if (function_exists('fb_url_inbound_alter')) {
21 $callback_url = url('', array('absolute' => TRUE)) . FB_SETTINGS_CB . '/' . $fb_app->id . '/';
22 }
23 else {
24 // Paving the way to make URL alters optional.
25 $callback_url = url('', array('absolute' => TRUE));
26 }
27 $return['profile_tab_url'] = $callback_url . FB_TAB_PATH_VIEW;
28
29 if (variable_get(FB_VAR_SECURE_URLS, FB_SECURE_URLS_SOMETIMES) >= FB_SECURE_URLS_SOMETIMES) {
30 $return['secure_page_tab_url'] = str_replace('http://', 'https://', $return['profile_tab_url']) . '/'; // Must end with '/' ???
31 }
32 if (variable_get(FB_VAR_SECURE_URLS, FB_SECURE_URLS_SOMETIMES) <= FB_SECURE_URLS_SOMETIMES) {
33 $return['profile_tab_url'] = str_replace('https://', 'http://', $return['profile_tab_url']);
34 }
35 }
36 else {
37 $return['profile_tab_url'] = '';
38 }
39
40 if ($config['edit_url']) {
41 // http://forum.developers.facebook.net/viewtopic.php?id=88920
42 $return['edit_url'] = url($config['edit_url'], array(
43 'absolute' => TRUE,
44 'fb_canvas' => $fb_app->label, // @TODO make canvas optional
45 ));;
46 }
47 else {
48 $return['edit_url'] = '';
49 }
50 }
51 elseif ($op == FB_ADMIN_OP_LIST_PROPERTIES) {
52 $return[t('Profile Tab Name')] = 'tab_default_name';
53 $return[t('Profile Tab URL')] = 'profile_tab_url';
54 $return[t('Secure Page Tab URL')] = 'secure_page_tab_url';
55 $return[t('Profile Tab Edit URL')] = 'edit_url';
56 $return[t('Installable')] = 'installable';
57 }
58 }
59
60
61 /**
62 * Form builder; Configure settings for this site.
63 *
64 * @ingroup forms
65 * @see system_settings_form()
66 */
67 function fb_tab_admin_settings() {
68
69 $form['process_settings'] = array(
70 '#type' => 'fieldset',
71 '#title' => t('Tab URL processing'),
72 '#description' => t('This option alters links, so that instead of changing the iframe\'s URL, they change the top frame. This adds some overhead to each tab served. Still, most sites will want this enabled.'),
73 );
74 $form['process_settings'][FB_TAB_VAR_PROCESS_IFRAME] = array(
75 '#type' => 'checkbox',
76 '#title' => t('Enable processing on iframe tabs.'),
77 '#default_value' => variable_get(FB_TAB_VAR_PROCESS_IFRAME, TRUE),
78 '#description' => t('Uncheck if you want the user to stay on the tab, instead of linking to canvas page or website. <br/>If unchecked, settings below have no effect.'),
79 );
80 $form['process_settings'][FB_TAB_VAR_PROCESS_TO_CANVAS] = array(
81 '#type' => 'checkbox',
82 '#title' => t('Links send user to canvas pages.'),
83 '#default_value' => variable_get(FB_TAB_VAR_PROCESS_TO_CANVAS, TRUE),
84 '#description' => t('If unchecked, links send user to normal website.'),
85 );
86 $form['process_settings'][FB_TAB_VAR_PROCESS_ABSOLUTE] = array(
87 '#type' => 'checkbox',
88 '#title' => t('Replace absolute hrefs, not just relative links.'),
89 '#default_value' => variable_get(FB_TAB_VAR_PROCESS_ABSOLUTE, TRUE),
90 );
91
92 return system_settings_form($form);
93 }
94
95
96 /**
97 * See fb_tab_form_alter.
98 */
99 function fb_tab_admin_form_alter(&$form, &$form_state, $form_id) {
100 // Add our settings to the fb_app edit form.
101 if (isset($form['fb_app_data']) && is_array($form['fb_app_data'])) {
102 $fb_app = $form['#fb_app'];
103 $config = _fb_tab_get_config($fb_app);
104
105 $form['fb_app_data']['fb_tab'] = array(
106 '#type' => 'fieldset',
107 '#collapsible' => TRUE,
108 '#collapsed' => isset($fb_app->label),
109 '#title' => t('Facebook profile tabs'),
110 '#description' => t('Settings which apply to <a href=!url target=_blank>profile tabs</a>.',
111 array('!url' => 'http://developers.facebook.com/docs/guides/canvas/#tabs')),
112 );
113
114 // Override themes
115 $themes = system_theme_data();
116 ksort($themes);
117 $theme_options[0] = t('System default');
118 foreach ($themes as $theme) {
119 if ($theme->status) { // Only enabled themes.
120 $theme_options[$theme->name] = $theme->name;
121 }
122 }
123 $form['fb_app_data']['fb_tab']['custom_theme'] = array(
124 '#type' => 'select',
125 '#title' => t('Theme for profile tabs'),
126 '#description' => t('Choose a theme designed to return FBML specifically for the 520 pixel wide space allocated to tabs. <br/>Note that if your tab path is a menu callback which returns FBML, this setting is ignored.'),
127 '#options' => $theme_options,
128 '#required' => TRUE,
129 '#default_value' => $config['custom_theme'],
130 );
131
132 // Properties: http://developers.facebook.com/docs/appproperties
133 $form['fb_app_data']['fb_tab']['tab_default_name'] = array(
134 '#type' => 'textfield',
135 '#title' => 'Tab name',
136 '#default_value' => $config['tab_default_name'],
137 '#description' => t('A very short title.'),
138 );
139
140 $form['fb_app_data']['fb_tab']['profile_tab_url'] = array(
141 '#type' => 'textfield',
142 '#title' => 'View path',
143 '#default_value' => $config['profile_tab_url'],
144 '#description' => t('Specify a Drupal page (i.e. "node/123") to render specific content in your page tab. Or leave blank and implement <em>hook_fb_tab()</em> in your custom module.'),
145 );
146
147 $form['fb_app_data']['fb_tab']['profile_tab_url_liked'] = array(
148 '#type' => 'textfield',
149 '#title' => 'View path when page is liked',
150 '#default_value' => $config['profile_tab_url_liked'],
151 '#description' => t('Optionally specify another path when the user has liked the page where the tab is shown. Leave blank to use <em>view path</em>.'),
152 );
153
154 $form['fb_app_data']['fb_tab']['edit_url'] = array(
155 '#type' => 'textfield',
156 '#title' => 'Edit path',
157 '#default_value' => $config['edit_url'],
158 '#description' => t('Recommended value is %edit_url. Implement <em>hook_fb_tab()</em> to customize the configuration form.', array(
159 '%edit_url' => FB_TAB_PATH_FORM,
160 )),
161 );
162 }
163 }