-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwelcome.install
More file actions
293 lines (266 loc) · 9.2 KB
/
welcome.install
File metadata and controls
293 lines (266 loc) · 9.2 KB
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
<?php
function welcome_install() {
global $user;
$current_uid = $user->uid;
// Checking to see if "About" node still exists
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->propertyCondition('type', 'page')
->propertyCondition('title', 'About')
->propertyCondition('status', 1)
->range(0,1)
->execute();
if (!empty($entities['node'])) {
$nids = array_keys($entities['node']);
$about = node_load(array_shift($nids));
}
// If About page exists, unpublish it.
if (!empty($about)) {
$page = node_load($about->nid);
$page->status = '0';
node_save($page);
}
// Checking to see if "Your first post" node still exists
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->propertyCondition('type', 'post')
->propertyCondition('title', 'Your first post!')
->propertyCondition('status', 1)
->range(0,1)
->execute();
if (!empty($entities['node'])) {
$nids = array_keys($entities['node']);
$about = node_load(array_shift($nids));
}
// If default post still exists, unpublish it.
if (!empty($about)) {
$post = node_load($about->nid);
$post->status = '0';
node_save($post);
}
$pages = array(
'500' => array(
'title' => st('What are posts?'),
'body' => '500',
'type' => 'post',
'promote' => '1',
'tags' => array('Promoted Content','Posts'),
),
'501' => array(
'title' => st('Promoted Content'),
'body' => '501',
'type' => 'post',
'promote' => '1',
'tags' => array('Promoted Content','Help'),
),
'502' => array(
'title' => st('Post that was not promoted'),
'body' => '502',
'type' => 'post',
'promote' => '0',
'tags' => array('Promoted Content'),
),
'503' => array(
'title' => st('Backdrop LIVE'),
'body' => '503',
'type' => 'post',
'promote' => '1',
'tags' => array('Community'),
),
'504' => array(
'title' => st('Community Support'),
'body' => '504',
'type' => 'post',
'promote' => '0',
'tags' => array('Community', 'Support'),
),
'505' => array(
'title' => st('The Dashboard'),
'body' => '505',
'type' => 'post',
'promote' => '1',
'tags' => array('Tools', 'Support'),
),
'506' => array(
'title' => st('Why Use Backdrop (The Video)'),
'body' => '506',
'type' => 'post',
'promote' => '0',
'tags' => array(''),
),
'600' => array(
'title' => st('About'),
'body' => '600',
'type' => 'page',
'promote' => '0',
'tags' => array(''),
),
'601' => array(
'title' => st('Site Details'),
'body' => '601',
'type' => 'page',
'promote' => '0',
'tags' => array(''),
'menu_parent' => 'about',
),
'602' => array(
'title' => st("What's Next"),
'body' => '602',
'type' => 'page',
'promote' => '0',
'tags' => array(''),
'menu_parent' => 'about',
),
);
// Setting some values we'll be using a little later.
// 'created' is to help adjust creation time on nodes, to make the sample content
// behave more realistic than if it is all created at the same moment.
// I just do some math to change the created time of each node we create.
$module_path = backdrop_get_path('module', 'welcome');
$created = time() - '1036800';
// Creates an array of all new taxonony terms
$new_terms = array();
foreach ($pages as $page) {
$page = $page['tags'];
foreach ($page as $tag) {
if (!empty($tag) && !in_array($tag, $new_terms)) {
array_push($new_terms, $tag);
}
}
}
// Adds all new terms to 'tags' vocabulary
foreach ($new_terms as $new_term) {
$term = entity_create('taxonomy_term', array(
'name' => $new_term,
'description' => '',
'format' => 1,
'vocabulary' => 'tags',
));
taxonomy_term_save($term);
}
// Create new nodes
foreach ($pages as $info) {
$content = file_get_contents($module_path . '/content/' . $info['body'] . '.txt');
$page = new Node(
array(
'title' => $info['title'],
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => $content,
'format' => 'filtered_html',
),
),
),
'uid' => $current_uid,
'promote' => $info['promote'],
'status' => 1,
'type' => $info['type'],
'created' => $created,
'changed' => $created,
)
);
// Find tid for each new term and add term to node
$term_key = '0';
foreach ($info['tags'] as $page_tag) {
if (empty($page_tag)) { continue; }
$temp_tag = taxonomy_term_load_multiple_by_name($page_tag, 'tags');
$term_tid = array_keys($temp_tag);
$page->field_tags['und'][$term_key++]['tid'] = $term_tid[0];
}
$page->save();
// Help make an arbitrary adjustment to node creation date
$created = $created - '1003121';
// Create an "About" link in the main menu.
if ($page->title == 'About') {
$item = array(
'link_path' => 'node/' . $page->nid,
'link_title' => 'About',
'weight' => 1,
);
menu_link_save($item);
$about_mlid = $item['mlid'];
// While here, fix the about alias
$about = node_load($page->nid);
$about->path['auto'] = FALSE;
$about->path['alias'] = 'new-about';
$about->save();
}
// Create menu items for children of About
if (isset($info['menu_parent']) && $info['menu_parent'] == 'about') {
$item = array(
'link_path' => 'node/' . $page->nid,
'link_title' => $page->title,
'weight' => 2,
'plid' => $about_mlid,
);
menu_link_save($item);
}
// Update the menu router information.
menu_rebuild();
}
// END new nodes section
$format = filter_format_load('filtered_html');
$format->filters['video_filter'] = (object) array();
filter_format_save($format);
// Make sure filters are in the correct order
config_set('filter.format.filtered_html', 'filters.video_filter.status', '1');
config_set('filter.format.filtered_html', 'filters.filter_html.settings.allowed_html', '<a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <h1> <h2> <h3> <h4> <h5> <p> <img> <figure> <figcaption> <table> <thead> <tbody> <tr> <th> <td>');
config_set('filter.format.filtered_html', 'filters.filter_html.weight', '-3');
config_set('filter.format.filtered_html', 'filters.video_filter.weight', '-2');
config_set('filter.format.filtered_html', 'filters.filter_url.weight', '-1');
// Prepping new image to use in hero block of front page.
$field_image_dir = 'public://hero';
file_prepare_directory($field_image_dir, FILE_CREATE_DIRECTORY);
$image_url = BACKDROP_ROOT . '/' . $module_path . '/images/mountain-shadows.jpg';
$moved_file = file_unmanaged_copy($image_url, $field_image_dir);
$file = entity_create('file', array(
'filename' => 'mountain-shadows.jpg',
'uri' => $moved_file,
'uid' => $current_uid,
));
$file->save();
// Add default content to the current user's profile page.
$user_account = user_load($current_uid);
$content = file_get_contents($module_path . '/content/user.txt');
$user_account->field_profile[LANGUAGE_NONE][0]['value'] = $content;
$user_account->field_profile[LANGUAGE_NONE][0]['format'] = 'filtered_html';
user_save($user_account);
// Adding mini-block that we use for footer
$uuid1 = '57deb90a-f136-49af-af00-c5e14ec6b8c5';
$block1 = array(
'content.' . $uuid1 => array(
'plugin' => 'mini_layouts:footer',
'data' => array(
'module' => 'mini_layouts',
'delta' => 'footer',
'settings' => array(
'title_display' => 'default',
'title' => '',
'style' => 'default',
'block_settings' => [],
'contexts' => [],
),
'uuid' => $uuid1,
'style' => array(
'plugin' => 'default',
'data' => array(
'settings' => array(
'classes' => '',
),
),
),
),
),
);
// Adds block to layouts
config_set_multiple('layout.layout.home', $block1 );
config_set_multiple('layout.layout.default', $block1 );
// Puts block into footer of each layout
config_set('layout.layout.home','positions.footer', array($uuid1));
config_set('layout.layout.default','positions.footer', array($uuid1));
// Changing image and title in hero block on front page
config_set('layout.layout.home', 'content.094cbc03-d088-4b3c-8361-977733540ae8.data.settings.image_path', '/files/hero/mountain-shadows.jpg');
config_set('layout.layout.home', 'content.094cbc03-d088-4b3c-8361-977733540ae8.data.settings.title', 'Getting Started with Backdrop');
backdrop_set_message('The Welcome module has installed some content on your site and enabled some contributed modules to help you better evaluate and test Backdrop CMS. You will need to manually delete any content that you do not wish to keep.', 'info');
}