This repository has been archived by the owner on Aug 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cos.profile
724 lines (687 loc) · 20.3 KB
/
cos.profile
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
<?php
/**
* @file
* COS Profile, Profile file.
*/
if (!function_exists("system_form_install_configure_form_alter")) {
/**
* Implements hook_form_FORM_ID_alter().
*
* Allows the profile to alter the site configuration form.
*/
function system_form_install_configure_form_alter(&$form, $form_state) {
$form['site_information']['site_name']['#default_value'] = 'Drupal COS';
$form['site_information']['site_mail']['#default_value'] = '[email protected]';
$form['admin_account']['account']['name']['#default_value'] = 'cosine';
$form['admin_account']['account']['mail']['#default_value'] = '[email protected]';
$form['server_settings']['site_default_country']['#default_value'] = 'US';
$form['server_settings']['date_default_timezone']['#default_value'] = 'America/Los_Angeles';
}
}
if (!function_exists("system_form_install_select_profile_form_alter")) {
/**
* Implements hook_form_FORM_ID_alter().
*
* Select the current install profile by default.
*/
function cos_system_form_install_select_profile_form_alter(&$form, $form_state) {
foreach ($form['profile'] as $key => $element) {
$form['profile'][$key]['#value'] = 'cos';
}
}
}
/**
* Implements hook_install_tasks().
*/
function cos_install_tasks($install_state) {
$tasks = array(
'cos_path_auto' => array(
'display_name' => st("Configure Path auto for Content Types"),
'function' => 'cos_path_auto',
),
'cos_doug_fir' => array(
'display_name' => st('Configure Doug Fir Theme'),
'function' => 'cos_doug_fir',
),
'cos_permissions' => array(
'display_name' => st('Configure Site Permissions'),
'function' => 'cos_perms',
),
'cos_front_page_custom' => array(
'display_name' => st('Add default home page'),
'function' => 'cos_front_page_custom',
),
'cos_add_extra_content' => array(
'display_name' => st('Extra Content to add'),
'type' => 'form',
),
'cos_add_onid' => array(
'display_name' => st('Add ONID Users'),
'type' => 'form',
),
);
return $tasks;
}
/**
* Configure Permissions and roles for a site.
*/
function cos_perms() {
// Add User Roles.
// Site Admin Permissions.
$site_admin_perms = array(
'access administration menu',
'access administration pages',
'access all views',
'access all webform results',
'access broken links report',
'access content overview',
'access contextual links',
'access own broken links report',
'access own webform results',
'access own webform submissions',
'access protected node overview page',
'access protected node password form',
'access site in maintenance mode',
'access site reports',
'access user profiles',
'add media from remote sources',
'administer biblio',
'administer blocks',
'administer cas redirect',
'administer code per node',
'administer content types',
'administer image styles',
'administer linkchecker',
'administer media',
'administer menu',
'administer nodeaccess',
'administer nodes',
'administer pathauto',
'administer permissions',
'administer rules',
'administer site configuration',
'administer taxonomy',
'administer url aliases',
'administer users',
'administer views',
'administer workbench',
'bypass node access',
'configure top hat',
'create article content',
'create biblio content',
'create feature_story content',
'create feed',
'create feed content',
'create people_osu content',
'create page content',
'create url aliases',
'create video content',
'create webform content',
'customize shortcut links',
'delete all webform submissions',
'delete any article content',
'delete any biblio content',
'delete any feature_story content',
'delete any feed content',
'delete any page content',
'delete any people_osu content',
'delete any video content',
'delete any webform content',
'delete own article content',
'delete own biblio content',
'delete own feed content',
'delete own feature_story content',
'delete own page content',
'delete own people_osu content',
'delete own video content',
'delete own webform content',
'delete own webform submissions',
'delete revisions',
'delete terms in 1',
'edit all webform submissions',
'edit any article content',
'edit any biblio content',
'edit any feature_story content',
'edit any feed content',
'edit any page content',
'edit any people_osu content',
'edit any protected node password',
'edit any video content',
'edit any webform content',
'edit biblio authors',
'edit by all biblio authors',
'edit css per block',
'edit css per node',
'edit feed',
'edit javascript per block',
'edit javascript per node',
'edit link settings',
'edit media',
'edit own article content',
'edit own biblio content',
'edit own comments',
'edit own feed content',
'edit own feature_story content',
'edit own page content',
'edit own people_osu content',
'edit own video content',
'edit own webform content',
'edit own webform submissions',
'edit page password',
'edit protected content',
'edit terms in 1',
'edit webform components',
'export taxonomy by csv',
'flush caches',
'grant deletable node permissions',
'grant editable node permissions',
'grant node permissions',
'grant own node permissions',
'import from file',
'import taxonomy by csv',
'revert revisions',
'switch shortcut sets',
'use text format ckeditor',
'use text format full_html',
'view advanced help index',
'view advanced help popup',
'view advanced help topic',
'view date repeats',
'view own unpublished content',
'view protected content',
'view revisions',
'view the administration theme',
);
// Site Admin Role.
$site_admin = new stdClass();
$site_admin->name = 'Site Admin';
$site_admin->weight = 9;
user_role_save($site_admin);
user_role_grant_permissions($site_admin->rid, $site_admin_perms);
// Graduate Student Permissions.
$grad_stu_perms = array(
'access administration menu',
'access administration pages',
'access contextual links',
'access own broken links report',
'access own webform results',
'access own webform submissions',
'access site in maintenance mode',
'access site reports',
'access user profiles',
'add media from remote sources',
'administer biblio',
'administer image styles',
'administer menu',
'administer taxonomy',
'create article content',
'create biblio content',
'create feature_story content',
'create feed',
'create feed content',
'create page content',
'create people_osu content',
'create url aliases',
'create video content',
'create webform content',
'customize shortcut links',
'delete own article content',
'delete own biblio content',
'delete own feature_story content',
'delete own feed content',
'delete own page content',
'delete own people_osu content',
'delete own video content',
'delete own webform content',
'delete own webform submissions',
'edit css per block',
'edit css per node',
'edit feed',
'edit javascript per block',
'edit javascript per node',
'edit media',
'edit own article content',
'edit own biblio content',
'edit own comments',
'edit own feature_story content',
'edit own feed content',
'edit own page content',
'edit own people_osu content',
'edit own video content',
'edit own webform content',
'edit own webform submissions',
'edit protected content',
'edit terms in 1',
'edit webform components',
'flush caches',
'import from file',
'revert revisions',
'switch shortcut sets',
'use text format ckeditor',
'use text format full_html',
'view advanced help index',
'view advanced help popup',
'view advanced help topic',
'view date repeats',
'view own unpublished content',
'view protected content',
'view revisions',
'view the administration theme',
);
// Graduate Student Role.
$grad_stu = new stdClass();
$grad_stu->name = 'Grad Student';
$grad_stu->weight = 8;
user_role_save($grad_stu);
user_role_grant_permissions($grad_stu->rid, $grad_stu_perms);
// Authenticated Users Permissions.
$auth_user_perm = array(
'access biblio content',
'access comments',
'access content',
'access own webform submissions',
'access protected node password form',
'access workbench',
'post comments',
'search content',
'show download links',
'show export links',
'show filter tab',
'show own download links',
'show sort links',
'skip comment approval',
'use advanced search',
'use text format filtered_html',
'view date repeats',
'view full text',
'view media',
'view protected content',
);
// Update Auth user perms.
user_role_grant_permissions('2', $auth_user_perm);
// Anonymous Permissions.
$anon_perms = array(
'access biblio content',
'access comments',
'access content',
'access protected node password form',
'search content',
'use text format filtered_html',
'view date repeats',
'view media',
);
// Update annon perms.
user_role_grant_permissions('1', $anon_perms);
}
/**
* Setup Doug Fir Theme.
*/
function cos_doug_fir() {
// Doug Fir Theme settings.
$doug_fir_settings = array(
"theme_settings" => '',
"toggle_logo" => 0,
"toggle_name" => 1,
"toggle_favicon" => 1,
"toggle_main_menu" => 0,
"toggle_secondary_menu" => 0,
"default_favicon" => 1,
"logo" => '',
"default_logo" => 0,
"logo_path" => '',
"logo_upload" => '',
"favicon" => '',
"favicon_path" => '',
"favicon_upload" => '',
"variant" => "science",
"responsive" => 1,
"hide_breadcrumbs" => 0,
"hide_book_nav" => 0,
"hide_terms" => 0,
"custom_ga_code" => '',
"parent_site_name" => 'College of Science',
"parent_site_url" => 'www.science.oregonstate.edu',
"facebook" => '',
"youtube-play" => '',
"flickr" => '',
"linkedin" => '',
"twitter" => '',
"google-plus" => '',
"instagram" => '',
"nice_menus_custom_css" => '',
);
variable_set('theme_doug_fir_settings', $doug_fir_settings);
}
/**
* Setup Path Auto aliases.
*/
function cos_path_auto() {
// URL Patterns.
variable_set('pathauto_node_article_pattern', 'articles/[node:title]');
variable_set('pathauto_node_feature_story_pattern', 'stories/[node:title]');
variable_set('pathauto_node_feed_pattern', 'feeds/[node:title]');
variable_set('pathauto_node_video_pattern', 'videos/[node:title]');
variable_set('pathauto_node_webform_pattern', 'forms/[node:title]');
variable_set('pathauto_node_biblio_pattern', '');
variable_set('pathauto_node_page_pattern', '');
variable_set('pathauto_node_people_osu_pattern', 'people/[node:title]');
}
/**
*
*/
function cos_front_page_custom() {
// Home.
$body = '<h3>Welcome to your new Drupal site</h3>';
$body .= '<p>This is your front page, <strong>do not</strong> delete it.';
$body .= 'You can edit this page, remove this content, and add your own.';
$body .= '<p>To learn more about building your site, visit our <a href="http://oregonstate.edu/cws/training/view/training-materials">Drupal Training Materials</a>.</p>';
$node = new stdClass();
// Main Node Fields.
$node->name = 'Home';
$node->title = $node->name;
// This can be any node type.
$node->type = 'page';
$node->created = strtotime('now');
$node->changed = $node->created;
// Display on front page ? 1 : 0.
$node->promote = 0;
// Display top of page ? 1 : 0.
$node->sticky = 0;
// Published ? 1 : 0.
$node->status = 1;
$node->language = 'en';
$node->uid = 1;
$node->body['und'][0]['format'] = 'ckeditor';
$node->body['und'][0]['value'] = $body;
// $node->og_group_ref['und'][0]['target_id'] = $gid;.
node_save($node);
// Set this has the front page.
variable_set('site_frontpage', 'node/' . $node->nid);
/*
// Drupal7 creates the alias to this new node as content/home
// We want to change it to just home
$res = db_update('url_alias')
->fields(array('alias' => 'home'))
->condition('alias', 'content/home')
->execute();
*/
drupal_set_message(t('The default pages have been created.'));
}
/**
*
*/
function cos_add_extra_content() {
$form = array();
$form['into'] = array(
'#markup' => '<p>' . st('Check the box if you wish to add extra default content') . '</p>',
);
$my_content_options = array(
'lab' => st('The Lab'),
'feat_story' => st('Feature Story'),
'contact' => st('Contact us'),
'bib' => st('Biblio Link'),
);
$form['profile_extra'] = array(
'#type' => 'checkboxes',
'#title' => st('What extra content to you want to create?'),
'#description' => st(''),
'#options' => $my_content_options,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => st('Continue'),
);
return $form;
}
/**
* Implements hook_submit().
*
* @param $form
* @param $form_state
*/
function cos_add_extra_content_submit($form, &$form_state) {
$boxes_checked = $form_state['values']['profile_extra'];
foreach ($boxes_checked as $content_options) {
switch ($content_options) {
case 'video':
// cos_content_video();
break;
case 'lab':
cos_content_lab();
break;
case 'feat_story':
break;
case 'contact':
cos_content_contact();
break;
case 'bib':
$my_menu = array(
'link_path' => 'biblio',
'link_title' => st('Publications'),
'menu_name' => 'main-menu',
'weight' => 19,
'language' => 'en',
'plid' => 0,
'module' => 'menu',
);
menu_link_save($my_menu);
unset($my_menu);
break;
default:
break;
}
}
}
/**
* Create The Lab node page.
*/
function cos_content_lab() {
// The Body of the Node.
$body = '<p>Here I will post photos and descriptions of our experimental tool and capabilities. </p>';
$node = new stdClass();
// The Lab Page.
$node->name = 'The Lab';
$node->title = $node->name;
// This can be any node type.
$node->type = 'page';
$node->created = strtotime('now');
$node->changed = $node->created;
// Display on front page ? 1 : 0.
$node->promote = 0;
// Display top of page ? 1 : 0.
$node->sticky = 0;
// Published ? 1 : 0.
$node->status = 1;
$node->language = 'en';
$node->uid = 0;
$node->body['und'][0]['format'] = 'ckeditor';
$node->body['und'][0]['value'] = $body;
// $node->og_group_ref['und'][0]['target_id'] = $gid;.
node_save($node);
// Create menu link for the node.
$my_menu = array(
'link_path' => 'node/' . $node->nid,
'link_title' => st('The Lab'),
'menu_name' => 'main-menu',
'weight' => 19,
'language' => $node->language,
'plid' => 0,
'module' => 'menu',
);
menu_link_save($my_menu);
unset($body, $node, $my_menu);
}
/**
* Create the Contact us webform.
*/
function cos_content_contact() {
$body = '<p>Please contanct us with any questions.</p>';
$node = new stdClass();
$node->type = 'webform';
node_object_prepare($node);
$node->title = 'Contact Us';
$node->language = 'en';
$node->body[LANGUAGE_NONE][0]['value'] = $body;
$node->body[LANGUAGE_NONE][0]['format'] = 'ckeditor';
$node->uid = 1;
$node->promote = 0;
$node->comment = 0;
// Create the webform components.
$components = array(
array(
'name' => 'Full Name',
'form_key' => 'name',
'type' => 'textfield',
'required' => TRUE,
'weight' => 5,
'pid' => 0,
'extra' => array(
'title_display' => 'above',
'private' => 0,
),
),
array(
'name' => 'Email address',
'form_key' => 'email_address',
'type' => 'email',
'required' => TRUE,
'weight' => 6,
'pid' => 0,
'extra' => array(
'title_display' => 'above',
'private' => 0,
),
),
array(
'name' => 'Comments/Questions',
'form_key' => 'comment_question',
'type' => 'textarea',
'required' => TRUE,
'weight' => 7,
'pid' => 0,
'extra' => array(
'title_display' => 'above',
'private' => 0,
),
),
);
// Attach the webform to the node.
$node->webform = array(
'confirmation' => '',
'confirmation_format' => NULL,
'redirect_url' => '',
'status' => '1',
'block' => '0',
'teaser' => '0',
'allow_draft' => '0',
'auto_save' => '0',
'submit_notice' => '1',
'submit_text' => '',
// User can submit more than once.
'submit_limit' => '-1',
'submit_interval' => '-1',
'total_submit_limit' => '-1',
'total_submit_interval' => '-1',
'record_exists' => TRUE,
'roles' => array(
// Anonymous user can submit this webform.
0 => '1',
),
'emails' => '',
'components' => $components,
);
// Save the node.
node_save($node);
// Create menu link for the node.
$my_menu = array(
'link_path' => 'node/' . $node->nid,
'link_title' => st('Contact Us'),
'menu_name' => 'main-menu',
'weight' => 20,
'language' => $node->language,
'plid' => 0,
'module' => 'menu',
);
menu_link_save($my_menu);
unset($body, $node, $my_menu);
}
/**
* This adds more videos than it should.
*/
function cos_content_video() {
$body = '<p>Chris Marshall, curator of OSU\'s arthropod collection, takes us on an early morning journey to find an elusive scarab, a northwestern rain beetle.</p>';
$node = new stdClass();
$node->type = 'video';
// node_object_prepare($node);
$node->title = 'Chris Marshall, Beetles ';
$node->language = 'en';
$node->body[LANGUAGE_NONE][0]['value'] = $body;
$node->body[LANGUAGE_NONE][0]['format'] = 'ckeditor';
$node->uid = 1;
$node->promote = 0;
$node->comment = 0;
$node->field_video[LANGUAGE_NONE][0]['fid'] = NULL;
$node->field_video[LANGUAGE_NONE][0]['uid'] = 3;
$node->field_video[LANGUAGE_NONE][0]['filename'] = 'Searching for Rain Beetles with Chris Marshall';
$node->field_video[LANGUAGE_NONE][0]['uri'] = 'youtube://v/eclWC1knmU0';
$node->field_video[LANGUAGE_NONE][0]['filemime'] = 'video/youtube';
$node->field_video[LANGUAGE_NONE][0]['type'] = 'video';
$node->field_video[LANGUAGE_NONE][0]['display'] = 1;
node_save($node);
unset($node);
}
/**
* Implements hook_form().
*/
function cos_add_onid() {
$form = array();
$form['into'] = array(
'#markup' => '<p>' . st('Enter ONID names to add to the site') . '</p>',
);
$cosine_defaults = array('brabhamm', 'dinsmorc', 'haagensa');
$form['onid_admin'] = array(
'#type' => 'textarea',
'#title' => st('Full Site Admins'),
'#required' => TRUE,
'#default_value' => implode("\r\n", $cosine_defaults),
);
$form['onid_site_admin'] = array(
'#type' => 'textarea',
'#title' => st('Site Admins'),
'#required' => FALSE,
'#description' => st('Enter the ONID Usernames, enter delemeted to add'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => st('Continue'),
);
return $form;
}
/**
* Implements hook_form_submit().
* Takes name from the form and creates Drupal Accounts for each.
* Adds roles to newly created accounts.
*/
function cos_add_onid_submit($form, &$form_state) {
require_once drupal_get_path('module', 'cas') . '/cas.module';
$cas_oid = preg_split('/[\n\r|\r|\n]+/', $form_state['values']['onid_admin']);
$cos_admin = user_role_load_by_name('administrator');
$options = array(
'invoke_cas_user_presave' => TRUE,
);
foreach ($cas_oid as $oid) {
// Returns the Object of the user created, don't need to load by name.
$user = cas_user_register($oid, $options);
// $user = user_load_by_name($oid);
user_multiple_role_edit(array($user->uid), 'add_role', $cos_admin->rid);
}
unset($user, $oid, $cos_admin);
$cas_oid_site = preg_split('/[\n\r|\r|\n]+/', $form_state['values']['onid_site_admin']);
$cos_site_admin = user_role_load_by_name('Site Admin');
foreach ($cas_oid_site as $oid) {
$user = cas_user_register($oid, array());
user_multiple_role_edit(array($user->uid), 'add_role', $cos_site_admin->rid);
}
unset($user, $oid, $cas_oid_site);
drupal_set_message(st('Added OIND Users to the site'));
}