-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagile_iit.install
302 lines (269 loc) · 9.9 KB
/
agile_iit.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
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
<?php
/**
* @file
* The Agile IIT module install hooks.
*/
/**
* Implements hook_enable().
*
* We create the agile_iit flag on enable, so hook implementations in flag
* module will fire correctly, as the APIs are not available on install.
*/
function agile_iit_enable() {
// Load the flag API in case we want to use it when enabling.
include_once drupal_get_path('module', 'flag') . '/flag.module';
$existing_flags = flag_get_flags();
if (!isset($existing_flags['selected_images'])) {
// Only install the flag if it doesn't exist already.
$flag = flag_flag::factory_by_entity_type('node');
$configuration = array(
'name' => 'selected_images',
'global' => 0,
'show_in_links' => array(
'full' => 1,
'teaser' => 1,
),
'show_on_form' => 1,
// The following UI labels aren't wrapped in t() because they are written
// to the DB in English. They are passed to t() later, thus allowing for
// multilingual sites.
'title' => 'Selected Images',
'flag_short' => 'Select this',
'flag_long' => 'Add this node to your selected',
'flag_message' => 'This node has been added to your selected',
'unflag_short' => 'Unselect this',
'unflag_long' => 'Remove this post from your selected',
'unflag_message' => 'This post has been removed from your selected',
'types' => _agile_iit_install_get_suggested_node_types(),
);
$flag->form_input($configuration);
$flag->save();
// Clear the flag cache so the new permission is seen by core.
drupal_static_reset('flag_get_flags');
// Grant permissions.
$permissions = array('flag selected_images', 'unflag selected_images');
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $permissions);
}
if (!isset($existing_flags['saved_comparisons'])) {
// Only install the flag if it doesn't exist already.
$flag = flag_flag::factory_by_entity_type('node');
$configuration = array(
'name' => 'saved_comparisons',
'global' => 0,
'show_in_links' => array(
'full' => 1,
'teaser' => 1,
),
'show_on_form' => 1,
// The following UI labels aren't wrapped in t() because they are written
// to the DB in English. They are passed to t() later, thus allowing for
// multilingual sites.
'title' => 'Saved Comparisons',
'flag_short' => 'Save this comparison',
'flag_long' => 'Add this comparison to your personal list',
'flag_message' => 'This comparison has been added to your list',
'unflag_short' => 'Remove this',
'unflag_long' => 'Remove this comparison from your personal list',
'unflag_message' => 'This comparison has been removed from your list',
'types' => array('iit_detail_comparison'),
);
$flag->form_input($configuration);
$flag->save();
// Clear the flag cache so the new permission is seen by core.
drupal_static_reset('flag_get_flags');
// Grant permissions.
$permissions = array('flag saved_comparisons', 'unflag saved_comparisons');
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $permissions);
}
}
/**
* Returns some node types to which the demonstration 'selected' flag will
* apply.
*/
function _agile_iit_install_get_suggested_node_types() {
$preferred = array('article', 'story', 'forum', 'blog', 'image');
$existing = array_intersect($preferred, array_keys(node_type_get_types()));
if (!$existing) {
// As a last resort, take the first preference.
return array($preferred[0]);
}
return $existing;
}
/**
* Implements hook_uninstall().
*/
function agile_iit_uninstall() {
$ournewtype = 'iit_detail_comparison';
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
$result = db_query($sql, array(':type' => $ournewtype));
$nodeids = array();
foreach ($result as $row) {
$nodeids[] = $row->nid;
}
node_delete_multiple($nodeids);
agile_iit_delete_custom_fields();
node_type_delete($ournewtype);
field_purge_batch(500);
}
/**
* Implements hook_install().
*/
function agile_iit_install() {
node_types_rebuild();
$types = node_type_get_types();
$types = node_type_get_names();
if ( !in_array('iit_detail_comparison', $types )) {
$new_type = array(
'name' => t('IIT Detail Comparison'),
'base' => 'iit_detail_comparison',
'description' => t('A detail comparison.'),
'has_title' => TRUE,
'title_label' => t('Title'),
'type' => 'iit_detail_comparison',
);
$new_type = node_type_set_defaults($new_type);
node_type_save( $new_type );
}
iit_add_custom_fields();
$help_id = agile_iit_create_page_node();
variable_set('agile_iit_help_node_id', $help_id);
}
function _agile_iit_installed_fields() {
$t = get_t();
return array(
'iit_comments' => array(
'field_name' => 'iit_comments',
'label' => 'Comments (IIT Detail)',
'type' => 'text_long',
),
'iit_detail_1' => array(
'field_name' => 'iit_detail_1',
'label' => $t('Image Detail 1'),
'type' => 'image',
),
'iit_detail_2' => array(
'field_name' => 'iit_detail_2',
'label' => $t('Image Detail 2'),
'type' => 'image',
),
'iit_nid_1' => array(
'field_name' => 'iit_nid_1',
'label' => $t('Node of Image 1'),
'type' => 'entityreference',
),
'iit_nid_2' => array(
'field_name' => 'iit_nid_2',
'label' => $t('Node of Image 2'),
'type' => 'entityreference',
),
'iit_crop_data_1' => array(
'field_name' => 'iit_crop_data_1',
'label' => $t('Crop data from section 1'),
'type' => 'text_long',
),
'iit_crop_data_2' => array(
'field_name' => 'iit_crop_data_2',
'label' => $t('Crop data from section 2'),
'type' => 'text_long',
),
);
}
function _agile_iit_installed_instances() {
$t = get_t();
return array(
'iit_comments' => array(
'field_name' => 'iit_comments',
'label' => $t('Detail Comments'),
'widget' => array(
'type' => 'textarea',
),
),
'iit_detail_1' => array(
'field_name' => 'iit_detail_1',
'label' => $t('Image Detail 1'),
'settings' => array('file_extensions' => 'jpg, jpeg, gif'),
),
'iit_detail_2' => array(
'field_name' => 'iit_detail_2',
'label' => $t('Image Detail 2'),
'settings' => array('file_extensions' => 'jpg, jpeg, gif'),
),
'iit_nid_1' => array(
'field_name' => 'iit_nid_1',
'label' => $t('Node of Image 1'),
),
'iit_nid_2' => array(
'field_name' => 'iit_nid_2',
'label' => $t('Node of Image 2'),
),
'iit_crop_data_1' => array(
'field_name' => 'iit_crop_data_1',
'label' => $t('Crop data from section 1'),
),
'iit_crop_data_2' => array(
'field_name' => 'iit_crop_data_2',
'label' => $t('Crop data from section 2'),
),
);
}
function iit_add_custom_fields() {
foreach (_agile_iit_installed_fields() as $field) {
field_create_field($field);
}
foreach (_agile_iit_installed_instances() as $fieldinstance) {
$fieldinstance['entity_type'] = 'node';
$fieldinstance['bundle'] = 'iit_detail_comparison';
field_create_instance($fieldinstance);
}
}
function agile_iit_delete_custom_fields() {
foreach (array_keys(_agile_iit_installed_fields()) as $field) {
field_delete_field($field);
}
$instances = field_info_instances('node', 'iit_detail_comparison');
foreach ($instances as $instance_name => $fieldinstance) {
field_delete_instance($fieldinstance);
}
}
/**
* Add the custom node type and fields for Detail Comparisons.
*/
function agile_iit_update_7000() {
node_types_rebuild();
$types = node_type_get_types();
iit_add_custom_fields();
}
function agile_iit_update_7001() {
$help_id = agile_iit_create_page_node();
variable_set('agile_iit_help_node_id', $help_id);
}
function agile_iit_update_7002() {
agile_iit_enable();
}
function agile_iit_create_page_node() {
$values = array(
'type' => 'page',
'uid' => $GLOBALS['user']->uid,
'status' => 0,
'comment' => 1,
'promote' => 0,
);
$entity = entity_create('node', $values);
$wrapper = entity_metadata_wrapper('node', $entity);
$wrapper->title->set('Agile IIT Help Page');
$wrapper->body->set(array('value' => <<<EOF
<h1 id="comparison">Comparison Viewer</h1>
<p>Move the mouse over either image to see a closeup of the area under the cursor. The close-up image will be at 100% resolution, meaning the natural resolution of the original image. For this reason, the images will not entirely 'overlap' unless they are of comparable original size. </p>
<h2>Set origin</h2>
<p>By default, the top-left corners of each image are mapped to each other. Double-click anywhere on each image to set the "origin" to that point. For instance, double-clicking on corresponding points of interest will allow them both to be seen in the close-up windows simultaneously. Move the mouse slightly to align the zoomed sections.</p>
<p>To reset the origin, click the buttons at the top of the page displaying the coordinates of the origins.</p>
<h1 id="crop">Crop Tool</h1>
<p>The crop tool allows you to extract corresponding areas of interest. Drag on the left-hand image to isolate a section of interest, then click "Extract Detail" to create a section containing the selected area. It will appear below both images. Drag it onto the right-hand image to a corresponding section of interest. Resize, rotate, or horizontally flip the section using the icons around the bottom edge. When alignment is complete, click the 'i' icon at the top left of the section. A pop-up window will appear containing both sections. Make sure that your browser allows pop-ups from this site.</p>
<h2>Saving comparisons </h2>
<p>If this detail comparison is one you would like to save, fill out the "title" and "description" at the bottom of the pop-up window and click "Save sections". </p>
EOF
));
$wrapper->save(true);
entity_save('node', $entity);
return $wrapper->getIdentifier();
}