-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathixi.admin.inc
153 lines (140 loc) · 4.82 KB
/
ixi.admin.inc
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
<?php
/**
* @file
* IXI: XML Importer file.
*
* Administration page callbacks for IXI: XML Importer.
*/
/**
* Form constructor for configuring the XML importer.
*/
function _ixi_config_form($form, &$form_state) {
$form['ixi_group_content_type'] = array(
'#type' => 'select',
'#title' => t('Group content type'),
'#options' => _ixi_get_content_types(),
'#description' => t('What content type should be created when uploading new files?'),
'#default_value' => variable_get('ixi_group_content_type'),
'#required' => TRUE,
'#ajax' => array(
'event' => 'change',
'callback' => '_ixi_ajax_group_fields',
'wrapper' => 'group-fields-wrapper',
),
);
// This allows us to update the list of group fields with ajax when the
// group node is changed. This is the wrapper div that actually gets updated.
$form['wrapper'] = array(
'#prefix' => '<div id="group-fields-wrapper">',
'#suffix' => '</div>',
);
// Here we want to check if the form state has a value, and update the fields
// based on that. If not, then we check to see if there is already a saved
// value and use the fields from that.
$options = array();
if (isset($form_state['values']['ixi_group_content_type'])) {
$options = _ixi_get_content_type_fields($form_state['values']['ixi_group_content_type']);
}
elseif (!is_null(variable_get('ixi_group_content_type'))) {
$options = _ixi_get_content_type_fields(variable_get('ixi_group_content_type'));
}
// This include the actual form item on the page; this concludes the ajax
// stuff.
$form['wrapper']['ixi_group_fields'] = array(
'#type' => 'select',
'#title' => t('Group fields'),
'#options' => $options,
'#default_value' => variable_get('ixi_group_fields'),
'#multiple' => TRUE,
);
$form['ixi_image_extensions'] = array(
'#type' => 'select',
'#title' => t('Image Extesions'),
'#description' => t('Image extensions to automatically process and extract to public folder.'),
'#options' => array(
'bmp' => 'bmp',
'gif' => 'gif',
'jpg' => 'jpg',
'jpeg' => 'jpeg',
'png' => 'png',
),
'#default_value' => variable_get('ixi_image_extensions'),
'#multiple' => TRUE,
);
$form['ixi_extra_extensions'] = array(
'#type' => 'textfield',
'#title' => t('Restrict File Extensions'),
'#description' => t("Enter file extensions that you would like to restrict in the extra files array, separated by a ';'. Or you can leave it blank to get everything."),
'#default_value' => variable_get('ixi_extra_extensions'),
'#required' => FALSE,
);
$form['ixi_garbage_collect'] = array(
'#type' => 'checkbox',
'#title' => t('Garbage Collect'),
'#description' => t("If checked we'll delete old uploaded archives and clean old tracking records from the database."),
'#default_value' => variable_get('ixi_garbage_collect'),
);
return system_settings_form($form);
}
/**
* Return an array of available content types.
*
* The array is keyed by machine name and the values are the human readable
* names.
*/
function _ixi_get_content_types() {
$content_types = array();
foreach (node_type_get_types() as $key => $content_type) {
$content_types[$key] = $content_type->name;
}
return $content_types;
}
/**
* Return the associated fields of a given content type.
*/
function _ixi_get_content_type_fields($content_type) {
if (is_null($content_type)) {
return array();
}
else {
$fields = array();
foreach (field_info_instances('node', $content_type) as $key => $field) {
$fields[$key] = $field['label'];
}
return $fields;
}
}
/**
* Ajax callback for the group node fields configuration.
*/
function _ixi_ajax_group_fields($form, &$form_state) {
return $form['wrapper'];
}
/**
* Form constructor for manually recreating the archive directory.
*/
function _ixi_recreate_archive_directory_form() {
return confirm_form(
array(),
t('Do you want to attempt to recreate the archives upload directory?'),
'admin/reports/status',
t('This will attempt to recreate and make writable the upload archives directory: <em>%directory</em>.', array('%directory' => 'private://ixi_archives')), t('Recreate archive directory'),
t('Cancel')
);
}
/**
* Form submission handler for manually recreating the archive directory.
*/
function _ixi_recreate_archive_directory_form_submit($form, &$form_state) {
_ixi_recreate_archive_directory();
$form_state['redirect'] = 'admin/reports/status';
}
/**
* Attempt to manually recreate the archive directory.
*/
function _ixi_recreate_archive_directory() {
$directory = 'private://ixi_archives';
if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
drupal_set_message(t('Could not create the directory %directory.', array('%directory' => $directory)), 'error');
}
}