fix ported from 6.x branch.
[project/fb.git] / fb.install
CommitLineData
186f033e 1<?php
440edc95 2
456be90c
DC
3/**
4 * @file
5 * Install file to support fb.module.
19092d2f 6 *
456be90c 7 */
186f033e 8
49c58876
DC
9// Normally fb_settings.inc is included in settings.php or by fb.module, but that is not available during update.php.
10if (!function_exists('fb_settings')) {
11 module_load_include('inc', 'fb', 'fb_settings');
12}
13
e8485da9
DC
14/**
15 * Implementation of hook_requirements().
16 */
17function fb_requirements($phase) {
18 $t = get_t();
19 $items = array();
19092d2f 20
b389f367
DC
21 // fb.module and Facebook's PHP libs require JSON extensions.
22 if (!function_exists('json_encode')) {
23 $items[] = array(
24 'value' => $t('Not found'),
25 'severity' => REQUIREMENT_ERROR,
26 'description' => $t('JSON extension for PHP'),
27 );
28 }
29
f54b3a2b 30 // Disable these checks at install time, because failure then causes more
3cf45120 31 // problems due to module dependencies and Drupal's poor handling of
f54b3a2b 32 // requirement errors.
d6db04b7
DC
33 if ($phase != 'runtime') {
34 return $items;
35 }
19092d2f 36
e8485da9 37 $status = array('title' => $t('Drupal for Facebook Settings'));
a0e2c9a5 38 if (function_exists('fb_settings')) {
e8485da9
DC
39 if ($phase == 'runtime') {
40 $status['value'] = $t('Included');
41 }
42 $status['severity'] = REQUIREMENT_OK;
43 }
44 else {
45 if ($phase == 'runtime') {
46 $status['value'] = $t('Not included');
47 }
48 $status['severity'] = REQUIREMENT_ERROR;
c989c091
DC
49 $path = drupal_get_path('module', 'fb');
50 if (!$path)
51 // Not set during install.php
52 $path = 'modules/fb';
19092d2f 53
c989c091 54 $status['description'] = $t('Add something like <strong>include "%path";</strong> to your settings.php.', array('%path' => $path . '/fb_settings.inc'));
e8485da9
DC
55 }
56 $items[] = $status;
19092d2f 57
6c017586 58 $status = array('title' => $t('Facebook PHP SDK'));
49c58876
DC
59
60 // Find Facebook's PHP SDK. Use libraries API if enabled.
61 $fb_lib_path = function_exists('libraries_get_path') ? libraries_get_path('facebook-php-sdk') : 'sites/all/libraries/facebook-php-sdk';
62 $fb_platform = variable_get(FB_VAR_API_FILE, $fb_lib_path . '/src/facebook.php');
01ec8435 63
79bfec16
DC
64 if (!class_exists('Facebook') && $fb_platform) {
65 // Attempt to load, if not loaded already.
66 include($fb_platform);
67 }
68
67fffb73 69 if (class_exists('Facebook')) {
db804874 70 $status['value'] = Facebook::VERSION;
79bfec16
DC
71 if (Facebook::VERSION < "3" || Facebook::VERSION > "4") {
72 $status['description'] = $t('Expected version 3.x.y of Facebook PHP SDK.');
db804874
DC
73 $status['severity'] = REQUIREMENT_ERROR;
74 }
75 else {
79bfec16 76 $status['description'] = $fb_platform;
db804874
DC
77 $status['severity'] = REQUIREMENT_OK;
78 }
67fffb73 79 }
e8485da9 80 else {
79bfec16
DC
81 $status['description'] = $t('Facebook client API not found at %path. See modules/fb/README.txt', array(
82 '%path' => $fb_platform,
83 ));
e8485da9
DC
84 $status['severity'] = REQUIREMENT_ERROR;
85 if ($phase == 'runtime') {
86 $status['value'] = $t('Not found');
87 }
88 }
89 $items[] = $status;
19092d2f 90
e8485da9
DC
91 return $items;
92}
93
f54b3a2b
DC
94function fb_install() {
95 _fb_install_set_weight();
96
97 drupal_set_message(st('Drupal for Facebook modules enabled. Be sure to install facebook\'s client libraries and modify your settings.php! Read modules/fb/README.txt and <a href="!doc_url" target="_blank">the online documentation for Drupal for Facebook</a> for details.',
98 array('!doc_url' => 'http://drupal.org/node/195035')
19092d2f 99 ));
f54b3a2b
DC
100}
101
102function fb_uninstall() {
b24ac6ad
DC
103 foreach (array(
104 FB_VAR_LANGUAGE_OVERRIDE,
105 FB_VAR_JS_SDK,
106 FB_VAR_API_FILE,
107 FB_VAR_JS_CHANNEL,
108 FB_VAR_VERBOSE,
109 FB_VAR_APIKEY,
110 ) as $var) {
111 variable_del($var);
112 }
3cf45120
DC
113 $num_deleted = db_delete("variable")
114 ->condition('name', 'fb_language_%', 'like')
115 ->execute();
f54b3a2b
DC
116}
117
186f033e 118function _fb_install_set_weight() {
3cf45120
DC
119 db_update('system')
120 ->fields(array(
121 'weight' => -2
122 ))
123 ->condition('name', 'fb')
124 ->execute();
440edc95 125}
612558ed 126
3cf45120 127// TODO AVA doesn't appear to be called by anything
612558ed 128/**
425f16e3 129 * Convenience function to display messages like the one from fb_app_update_6003.
612558ed
DC
130 */
131function fb_install_property_message(&$ret, $reason) {
132 $result = db_query("SELECT * FROM {fb_app}");
133 $items = array();
3cf45120 134 foreach ($result as $data) {
612558ed
DC
135 $items[] = l($data->title, 'admin/build/fb/app/' . $data->label . '/fb/set_props', array('attributes' => array('target' => '_blank')));
136 }
137 if (count($items)) {
138 $message = 'Manual action required!. !reason Click below to update the settings, on facebook, for each of your applications. !list';
139 $args = array(
140 '!reason' => $reason,
141 '!list' => theme('item_list', $items),
142 );
143 drupal_set_message(t($message, $args), 'warning', FALSE);
144 watchdog('fb', $message, $args, WATCHDOG_WARNING);
145 }
146
147 $ret[] = array('success' => FALSE, 'query' => t('Manual action required. Go to !link and set properties for each facebook application.', array('!link' => l('Facebook Applications', 'admin/build/fb'))));
148
149}