1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Install, update and uninstall functions for CDM_DataPortal install profile.
|
5
|
*
|
6
|
* This profile performs the same actions as the standard profile, but with
|
7
|
* some customizations for CDM portals.
|
8
|
*/
|
9
|
|
10
|
/**
|
11
|
* Implements hook_install().
|
12
|
*
|
13
|
* Perform actions to set up the site for this profile.
|
14
|
*
|
15
|
* @see system_install()
|
16
|
*/
|
17
|
function CDM_Portal_install() {
|
18
|
|
19
|
|
20
|
/****************************************
|
21
|
* First of all configure the default theme
|
22
|
****************************************/
|
23
|
|
24
|
// >>> admin/appearance
|
25
|
// set the default theme
|
26
|
// This must be done first, otherwise blocks are not
|
27
|
// configured correctly for the default theme
|
28
|
$default_theme = 'bartik';
|
29
|
if( drupal_get_path('theme', 'zen_dataportal') ){
|
30
|
$default_theme = 'zen_dataportal';
|
31
|
}
|
32
|
variable_set('theme_default', $default_theme);
|
33
|
|
34
|
// enable default theme
|
35
|
db_update('system')
|
36
|
->fields(array('status' => 1))
|
37
|
->condition(
|
38
|
db_and()
|
39
|
->condition('type', 'theme')
|
40
|
->condition('name', $default_theme))
|
41
|
->execute();
|
42
|
|
43
|
// Run drupal standard install after the theme has been chosen
|
44
|
// standard_install() will configure blocks, filters, etc.
|
45
|
// After the standard_install() the dataportal
|
46
|
// customization can be applied
|
47
|
|
48
|
require_once DRUPAL_ROOT . '/profiles/standard/standard.install';
|
49
|
standard_install();
|
50
|
|
51
|
// >>> admin/appearance/settings
|
52
|
// Toggle display of various page details
|
53
|
// some of the below keys are specific to the
|
54
|
// zen theme
|
55
|
variable_set('theme_settings', array(
|
56
|
'toggle_logo' => 1,
|
57
|
'toggle_name' => 1,
|
58
|
'toggle_slogan' => 0,
|
59
|
'toggle_node_user_picture' => 0,
|
60
|
'toggle_comment_user_picture' => 0,
|
61
|
'toggle_comment_user_verification' => 0,
|
62
|
'toggle_favicon' => 1,
|
63
|
'toggle_main_menu' => 1,
|
64
|
'toggle_secondary_menu' => 0,
|
65
|
'default_logo' => 1,
|
66
|
'logo_path' => NULL,
|
67
|
'logo_upload' => NULL,
|
68
|
'default_favicon' => 1,
|
69
|
'favicon_path' => NULL,
|
70
|
'favicon_upload' => NULL,
|
71
|
// >>> admin/appearance/settings/zen_dataportal
|
72
|
// Display breadcrumbs only in the admin section
|
73
|
'zen_breadcrumb' => 'admin',
|
74
|
'zen_rebuild_registry' => 0,
|
75
|
));
|
76
|
|
77
|
/****************************************
|
78
|
* Reconfigure Drupal core modules
|
79
|
****************************************/
|
80
|
|
81
|
// >>> admin/config/media/file-system
|
82
|
// Temporary directory
|
83
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
84
|
variable_set('file_temporary_path', 'c:\\windows\\temp');
|
85
|
}
|
86
|
else {
|
87
|
variable_set('file_temporary_path', '/tmp');
|
88
|
}
|
89
|
|
90
|
// >>> admin/config/content/formats
|
91
|
// Do not use the line-break filter for the full_html input format.
|
92
|
$full_html_format = array(
|
93
|
'format' => 'full_html',
|
94
|
'name' => 'Full HTML',
|
95
|
'weight' => 1,
|
96
|
'filters' => array(
|
97
|
// URL filter.
|
98
|
'filter_url' => array(
|
99
|
'weight' => 0,
|
100
|
'status' => 1,
|
101
|
),
|
102
|
// HTML corrector filter.
|
103
|
'filter_htmlcorrector' => array(
|
104
|
'weight' => 10,
|
105
|
'status' => 1,
|
106
|
),
|
107
|
),
|
108
|
);
|
109
|
$full_html_format = (object) $full_html_format;
|
110
|
filter_format_save($full_html_format);
|
111
|
|
112
|
// variable_set('filter_html_1', 1);
|
113
|
// variable_set('menu_primary_menu', 2);
|
114
|
// variable_set('menu_secondary_menu', 2);
|
115
|
|
116
|
|
117
|
variable_set('node_options_forum', array (0 => 'status'));
|
118
|
variable_set('node_options_page', array (0 => 'status'));
|
119
|
// variable_set('site_footer', '');
|
120
|
|
121
|
// >>> admin/config/system/site-information
|
122
|
//
|
123
|
variable_set('site_frontpage', 'node/1');
|
124
|
variable_set('site_mail', '');
|
125
|
// variable_set('site_mission', '');
|
126
|
variable_set('site_name', 'CDM Dataportal');
|
127
|
variable_set('site_slogan', '');
|
128
|
variable_set('cdm_dataportal_geoservice_display_width', '600');
|
129
|
|
130
|
// >>> admin/config/development/logging
|
131
|
// Error messages to display: Errors and warnings
|
132
|
variable_set('error_level', '1');
|
133
|
|
134
|
// >>> admin/structure/types/manage/*
|
135
|
// Display author and date information: [off]
|
136
|
variable_set('node_submitted_page', 0);
|
137
|
variable_set('node_submitted_article', 0);
|
138
|
variable_set('node_submitted_cdm_media', 0);
|
139
|
variable_set('node_submitted_cdm_name', 0);
|
140
|
variable_set('node_submitted_cdm_taxon', 0);
|
141
|
variable_set('node_submitted_cdm_reference', 0);
|
142
|
// turn comments off for all content types (disabling the comment module would lead to an error)
|
143
|
variable_set('comment_page', 0);
|
144
|
variable_set('comment_article', 0);
|
145
|
variable_set('comment_cdm_media', 0);
|
146
|
variable_set('comment_cdm_name', 0);
|
147
|
variable_set('comment_cdm_taxon', 0);
|
148
|
variable_set('comment_cdm_reference', 0);
|
149
|
|
150
|
|
151
|
/****************************************
|
152
|
* CDM DataPortal - specific
|
153
|
*
|
154
|
* TODO consider moving these into
|
155
|
* the module
|
156
|
****************************************/
|
157
|
|
158
|
variable_set('cdm_webservice_cache', 0);
|
159
|
|
160
|
/****************************************
|
161
|
* User management
|
162
|
****************************************/
|
163
|
// USER_REGISTER_ADMINISTRATORS_ONLY = 0
|
164
|
// USER_REGISTER_VISITORS = 1
|
165
|
// USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL = 2
|
166
|
variable_set('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
|
167
|
|
168
|
// Create a role for CDM administrator.
|
169
|
$admin_role = new stdClass();
|
170
|
$admin_role->name = 'CDM admin';
|
171
|
$admin_role->weight = 3;
|
172
|
user_role_save($admin_role);
|
173
|
|
174
|
// Make sure these permissions are present, e.g. that the modules defining these permissions are installed.
|
175
|
// This because user_role_grant_permissions() will create the permission in the role_permission table if it does not
|
176
|
// exist, and for that it needs to find a module that defines the permission (there is a module column in this table).
|
177
|
$permissions = array(
|
178
|
'access administration menu',
|
179
|
'access administration pages',
|
180
|
'access content',
|
181
|
'access cdm content',
|
182
|
'access content overview',
|
183
|
'access site in maintenance mode',
|
184
|
'administer blocks',
|
185
|
'administer cdm_dataportal',
|
186
|
'administer content types',
|
187
|
'administer menu',
|
188
|
'administer nodes',
|
189
|
'administer site configuration',
|
190
|
'administer themes',
|
191
|
'administer users',
|
192
|
'bypass node access',
|
193
|
'create article content',
|
194
|
'create page content',
|
195
|
'create url aliases',
|
196
|
'delete any article content',
|
197
|
'delete any page content',
|
198
|
'delete own article content',
|
199
|
'delete own page content',
|
200
|
'delete revisions',
|
201
|
'edit any article content',
|
202
|
'edit any page content',
|
203
|
'edit own article content',
|
204
|
'edit own page content',
|
205
|
'flush caches',
|
206
|
'revert revisions',
|
207
|
'use text format full_html',
|
208
|
'view own unpublished content',
|
209
|
'view revisions',
|
210
|
'view the administration theme'
|
211
|
// Devel and IMCE modules are not yet required modules in this profile.
|
212
|
// 'access devel information',
|
213
|
// 'access imce',
|
214
|
// 'administer imce',
|
215
|
);
|
216
|
user_role_grant_permissions($admin_role->rid, $permissions);
|
217
|
|
218
|
// Assign user 1 the "CDM admin" role.
|
219
|
db_insert('users_roles')
|
220
|
->fields(array('uid' => 1, 'rid' => $admin_role->rid))
|
221
|
->execute();
|
222
|
|
223
|
// additional permission for the anonymous user authenticated user roles
|
224
|
$additional_default_permissions = array(
|
225
|
'access cdm content'
|
226
|
);
|
227
|
user_role_grant_permissions(1, $additional_default_permissions); // anonymous user
|
228
|
user_role_grant_permissions(2, $additional_default_permissions); // authenticated user
|
229
|
|
230
|
|
231
|
/****************************************
|
232
|
* Blocks
|
233
|
****************************************/
|
234
|
|
235
|
// >>> admin/structure/block
|
236
|
// Disable the blocks that were enabled for the dashboard in the standard install.
|
237
|
// In the CDM dataportals we use the admin_menu module instead of taskbar and dashboard.
|
238
|
$query = db_update('block')->fields(array('status' => '0'))
|
239
|
->condition('region', 'dashboard_main', '=')
|
240
|
->execute();
|
241
|
$query = db_update('block')->fields(array('status' => '0'))
|
242
|
->condition('region', 'dashboard_sidebar', '=')
|
243
|
->execute();
|
244
|
|
245
|
// disable "Search form" block for all themes
|
246
|
$query = db_update('block')->fields(array('status' => '0'))
|
247
|
->condition(
|
248
|
db_and()
|
249
|
->condition('module', 'search', '=')
|
250
|
->condition('delta', 'form', '=')
|
251
|
)
|
252
|
->execute();
|
253
|
|
254
|
// disable the "Powered by Drupal" block for all themes
|
255
|
$query = db_update('block')->fields(array('status' => '0'))
|
256
|
->condition(
|
257
|
db_and()
|
258
|
->condition('module', 'system', '=')
|
259
|
->condition('delta', 'powered-by', '=')
|
260
|
)
|
261
|
->execute();
|
262
|
|
263
|
$new_blocks = array();
|
264
|
|
265
|
;
|
266
|
// enable "CDM Search Taxa" block for all themes
|
267
|
$block_search_taxa = cdm_dataportal_block_info()["2"];
|
268
|
$block_search_taxa= array_merge($block_search_taxa, array(
|
269
|
'module' => 'cdm_dataportal',
|
270
|
'delta' => '2',
|
271
|
'theme' => $default_theme,
|
272
|
'status' => 1,
|
273
|
'weight' => -11,
|
274
|
'region' => 'sidebar_first',
|
275
|
'pages' => '',
|
276
|
));
|
277
|
$new_blocks[] = array(
|
278
|
'block' => $block_search_taxa
|
279
|
);
|
280
|
|
281
|
$block_back_to_search_results = cdm_dataportal_block_info()["back_to_search_results"];
|
282
|
$block_back_to_search_results= array_merge($block_back_to_search_results, array(
|
283
|
'module' => 'cdm_dataportal',
|
284
|
'delta' => 'back_to_search_results',
|
285
|
'theme' => $default_theme,
|
286
|
'status' => 1,
|
287
|
'weight' => 10,
|
288
|
'region' => 'navigation'
|
289
|
));
|
290
|
$new_blocks[] = array(
|
291
|
'block' => $block_back_to_search_results
|
292
|
);
|
293
|
|
294
|
// CDM web service debug block
|
295
|
$block_cdm_ws_debug = cdm_api_block_info()['cdm_ws_debug'];
|
296
|
$block_cdm_ws_debug= array_merge($block_cdm_ws_debug, array(
|
297
|
'module' => 'cdm_api',
|
298
|
'delta' => 'cdm_ws_debug',
|
299
|
'theme' => $default_theme,
|
300
|
'status' => 1,
|
301
|
'weight' => -50,
|
302
|
'region' => 'sidebar_first',
|
303
|
'pages' => '',
|
304
|
));
|
305
|
|
306
|
$new_blocks[] = array(
|
307
|
'block' => $block_cdm_ws_debug,
|
308
|
'block_role' => array(
|
309
|
'module' => 'cdm_api',
|
310
|
'delta' => 'cdm_ws_debug',
|
311
|
'rid' => $admin_role->rid
|
312
|
)
|
313
|
);
|
314
|
|
315
|
// TODO consider using block_flush_caches() to initially populate the block table with blocks from contributed
|
316
|
// modules, and only update the blocks afterwards with block_save()?
|
317
|
$block_insert = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
|
318
|
$block_role_insert = db_insert('block_role')->fields(array('module', 'delta', 'rid'));
|
319
|
foreach ($new_blocks as $block) {
|
320
|
$block_insert->values($block['block']);
|
321
|
if(isset($block['block_role'])){
|
322
|
$block_role_insert->values($block['block_role']);
|
323
|
}
|
324
|
}
|
325
|
$block_insert->execute();
|
326
|
$block_role_insert->execute();
|
327
|
|
328
|
/****************************************
|
329
|
* Create the front page
|
330
|
****************************************/
|
331
|
$node = new stdClass();
|
332
|
$node->uid = 1;
|
333
|
$node->type = 'page';
|
334
|
|
335
|
// Sets some defaults.
|
336
|
node_object_prepare($node);
|
337
|
|
338
|
$node->status = 1;
|
339
|
$node->language = LANGUAGE_NONE;
|
340
|
|
341
|
// Promoted to front page.
|
342
|
$node->promote = 0;
|
343
|
|
344
|
// Comments on.
|
345
|
// $node->comment = 1;
|
346
|
$node->title = 'CDM DataPortal';
|
347
|
// Format to use = full html.
|
348
|
$node->body[$node->language][0]['format'] = 'full_html';
|
349
|
$node->body[$node->language][0]['value'] = sprintf(
|
350
|
'<h3>Welcome to your CDM DataPortal. </h3>
|
351
|
This data portal makes full use of the Common Data Model (CDM),
|
352
|
a central component of the Internet Platform for Cybertaxonomy being
|
353
|
developed by EDIT workpackage 5. All taxon pages are created as dynamic
|
354
|
web pages from the underlying database.
|
355
|
In order to finish the setup of your DataPortal please visit the %s.
|
356
|
The CDM Dataportal provides several Drupal Blocks (<i>taxon search</i>,
|
357
|
<i>classification browser</i>, <i>external links</i>,
|
358
|
<i>print this page</i>) which you may want to activate in the
|
359
|
%s.',
|
360
|
l('CDM Dataportal settings','admin/config/cdm_dataportal/settings'),
|
361
|
l('Blocks Settings', 'admin/structure/block')
|
362
|
);
|
363
|
node_save($node);
|
364
|
|
365
|
}
|