/[drupal]/contributions/sandbox/jamesandres/facebook_api/facebook_api_admin.inc
ViewVC logotype

Contents of /contributions/sandbox/jamesandres/facebook_api/facebook_api_admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sun Sep 9 19:10:07 2007 UTC (2 years, 2 months ago) by jamesandres
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 /**
3 * The admin form for creating and editing Facebook Apps
4 **/
5 function facebook_admin_settings_form() {
6 $test = _is_facebook_client_available();
7 $form['client'] = array(
8 '#type' => 'fieldset',
9 '#title' => t('Facebook Client Settings'),
10 '#description' => t('Enter your API key and secret here. If the client status is anything but OK you need to copy the Facebook API client into the client folder of this module (see INSTALL.txt for more details). The Facebook client can be downloaded ') . l('here', 'http://developers.facebook.com/resources.php', array(), NULL, NULL, TRUE) . '.',
11 '#collapsible' => TRUE,
12 '#collapsed' => FALSE,
13 );
14 $form['client']['test'] = array(
15 '#value' =>
16 '<div style="color: black; background-color: ' . ($test === TRUE ? '#9F3' : '#F33') . '; width: 80%; padding: 5px; border: solid black 1px; margin: 10px; text-align: center;">Facebook client status: <strong>'
17 . ($test === TRUE ? 'OK!' : $test) .
18 '</strong></div>',
19 );
20
21 $form['client']['api_key'] = array(
22 '#type' => 'textfield',
23 '#title' => t('Facebook API Key'),
24 '#size' => 30,
25 '#default_value' => variable_get('facebook_api_key', ''),
26 '#maxlength' => 255,
27 '#required' => TRUE,
28 );
29 $form['client']['api_secret'] = array(
30 '#type' => 'textfield',
31 '#title' => t('Facebook API Secret'),
32 '#size' => 30,
33 '#default_value' => variable_get('facebook_api_secret', ''),
34 '#maxlength' => 255,
35 '#required' => TRUE,
36 );
37
38 $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
39
40 return $form;
41 }
42
43 function facebook_admin_settings_form_submit($form_id, $form_values) {
44 variable_set('facebook_api_key', $form_values['api_key']);
45 variable_set('facebook_api_secret', $form_values['api_secret']);
46
47 drupal_set_message('Settings saved!');
48 }
49
50 function _is_facebook_client_available() {
51 $files_to_test = array(
52 'facebook.php',
53 // 'facebook_desktop.php',
54 'facebookapi_php5_restlib.php'
55 );
56
57 $path = drupal_get_path('module', 'facebook_api') . '/client/';
58 foreach ($files_to_test as $file) {
59 if (!file_exists($path . $file)) {
60 return t("'%file' does not exist!", array('%file' => $path . $file));
61 } else if (!is_readable($path . $file)) {
62 return t("'%file' is not readable (check permissions!)!", array('%file' => $path . $file));
63 }
64 }
65
66 if (!variable_get('facebook_api_key', FALSE) || !variable_get('facebook_api_secret', FALSE)) {
67 return t('API key and Secret must both be set.');
68 }
69
70 return TRUE;
71 }
72
73 /**
74 * Get the conf settings set by the GUI admin panel.
75 *
76 * see http://developers.facebook.com/step_by_step.php
77 **/
78 function facebook_get_conf() {
79 return array(
80 'facebook_api_key' => variable_get('facebook_api_key', ''),
81 'facebook_api_secret' => variable_get('facebook_api_secret', ''),
82 'facebook_app_homepage' => variable_get('facebook_app_homepage', ''),
83 'facebook_infinite_session_key' => variable_get('facebook_infinite_session_key', ''),
84 );
85 }

  ViewVC Help
Powered by ViewVC 1.1.2