-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnextnode.install
195 lines (184 loc) · 5.72 KB
/
nextnode.install
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
* @file
* Install, update and uninstall functions for the NextNode module.
*/
/**
* Implements hook_schema().
*/
function nextnode_schema() {
$schema['nextnode_profiles'] = array(
'description' => 'Stores NextNode profile definitions.',
'fields' => array(
'pid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'no export' => TRUE,
'description' => 'Serial id for this profile.',
),
'name' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'description' => 'Machine-readable name for this profile.',
),
'title' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'description' => 'Administrative title for this profile.',
),
'active' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 1,
'description' => 'Profile status.',
),
'config' => array(
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'description' => 'Serialized data containing profile settings.',
),
),
'primary key' => array('pid'),
'unique keys' => array(
'name' => array('name'),
),
'indexes' => array(
'pid' => array('pid'),
'active' => array('active'),
),
);
$schema['nextnode_index'] = array(
'description' => 'Stores relationship between nodes and NextNode profiles.',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The {node}.nid of the node.',
),
'profile' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'description' => 'Machine name of a NextNode profile.',
),
),
'primary key' => array('nid'),
'indexes' => array(
'profile' => array('profile'),
),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function nextnode_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
// Ensure translations don't break at install time.
$t = get_t();
// Waypoints library.
$waypoints = libraries_detect('waypoints');
$waypoints_version = isset($waypoints['version']) ? $waypoints['version'] : NULL;
if (empty($waypoints['installed'])) {
$error_type = isset($waypoints['error']) ? drupal_ucfirst($waypoints['error']) : '';
$error_message = isset($waypoints['error message']) ? $waypoints['error message'] : '';
$requirements['waypoints_library'] = array(
'title' => $t('Waypoints library'),
'value' => $t('@e: Need at least @a', array('@e' => $error_type, '@a' => NEXTNODE_WAYPOINTS_MIN_VERSION)),
'severity' => REQUIREMENT_ERROR,
'description' => $t('!error Please download the !link and see README.txt for installation instructions.',
array(
'!error' => $error_message,
'!link' => l($t('Waypoints'), $waypoints['download url']),
)
),
);
}
elseif (version_compare($waypoints_version, NEXTNODE_WAYPOINTS_MIN_VERSION, '>=')) {
$requirements['waypoints_library'] = array(
'title' => $t('Waypoints library'),
'severity' => REQUIREMENT_OK,
'value' => $waypoints_version,
);
}
else {
$requirements['waypoints_library'] = array(
'title' => $t('Waypoints library'),
'value' => $t('Outdated version. Need at least @a', array('@a' => NEXTNODE_WAYPOINTS_MIN_VERSION)),
'severity' => REQUIREMENT_ERROR,
'description' => $t('You need to download at least version @ver of the !link and replace the old version located in the %path directory on your server.',
array(
'!link' => l($t('Waypoints'), $waypoints['download url']),
'@ver' => NEXTNODE_WAYPOINTS_MIN_VERSION,
'%path' => $waypoints['library path'],
)
),
);
}
}
return $requirements;
}
/**
* Implements hook_install().
*/
function nextnode_install() {
$t = get_t();
// Create global variables.
foreach (_nextnode_variables() as $name => $value) {
variable_set($name, $value);
}
// Create the default profile.
module_load_include('inc', 'nextnode', 'nextnode.profile');
$profile = nextnode_default_profile(array(
'name' => 'default',
'title' => $t('Default'),
));
nextnode_profile_save($profile, FALSE);
}
/**
* Implements hook_uninstall().
*/
function nextnode_uninstall() {
// Start with global variables.
$variables = array_keys(_nextnode_variables());
// Add variables created by content type.
foreach (node_type_get_types() as $type) {
$variables[] = 'nextnode_enable_' . $type->type;
$variables[] = 'nextnode_profile_' . $type->type;
$variables[] = 'nextnode_override_' . $type->type;
}
foreach ($variables as $variable) {
variable_del($variable);
}
// Delete the profiles cache.
cache_clear_all('nextnode_profiles', 'cache');
}
/**
* Helper function, define the set of global variables used by NextNode.
*
* @return array
* Associative array with default values keyed by name.
*/
function _nextnode_variables() {
return array(
'nextnode_change_url' => 1,
'nextnode_load_css' => 1,
'nextnode_minified_code' => 1,
'nextnode_load_offset' => 200,
'nextnode_scroll_offset' => 100,
'nextnode_sticky_title' => 1,
'nextnode_sticky_title_zindex' => 99,
'nextnode_sticky_title_top' => 0,
'nextnode_sticky_title_offset' => -100,
'nextnode_hook_selector' => 'nextnode-wrapper',
'nextnode_next_selector' => 'nextnode-next',
'nextnode_content_selector' => 'nextnode-node',
);
}