@@ -73,6 +73,9 @@ function os2web_gf_service_handler($file_id) {
73
73
'application/vnd.ms-outlook',
74
74
);
75
75
76
+ $disallowed_mimes = array_merge($disallowed_mimes, explode(',', variable_get('os2web_cp_service_disallow_mimes', '')));
77
+ $case_exceptions = explode(',', variable_get('os2web_cp_service_disallow_mimes_exceptions', ''));
78
+
76
79
if ($url = variable_get('os2web_cp_service_cp_document_fileurl')) {
77
80
78
81
$username = variable_get('os2web_cp_service_endpoint_user');
@@ -87,7 +90,22 @@ function os2web_gf_service_handler($file_id) {
87
90
$header = curl_getinfo($ch);
88
91
curl_close($ch);
89
92
if ($header['http_code'] === 200) {
90
- if (!in_array($header['content_type'], $disallowed_mimes)) {
93
+ // Load the title to use it as the filename, and for conditions.
94
+ $query = new EntityFieldQuery();
95
+ $result = $query
96
+ ->entityCondition('entity_type', 'node')
97
+ ->propertyCondition('type', 'os2web_cp_service_cp_document')
98
+ ->propertyCondition('status', 1)
99
+ ->fieldCondition('field_os2web_cp_service_file_id', 'value', $file_id, '=')
100
+ ->execute();
101
+ $nids = (isset($result['node']))?array_keys($result['node']) : NULL;
102
+
103
+ $node = node_load(array_pop($nids));
104
+ $case_id = NULL;
105
+ if ($node) {
106
+ $case_id = $node->field_os2web_cp_service_case_id[LANGUAGE_NONE][0]['value'];
107
+ }
108
+ if (!in_array($header['content_type'], $disallowed_mimes) || ($case_id && in_array($case_id, $case_exceptions))) {
91
109
drupal_add_http_header('Content-Type', $header['content_type']);
92
110
drupal_add_http_header('Content-Length', $header['download_content_length']);
93
111
drupal_add_http_header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
@@ -103,22 +121,12 @@ function os2web_gf_service_handler($file_id) {
103
121
drupal_add_http_header('Pragma', 'no-cache');
104
122
}
105
123
106
- // Load the title to use it as the filename.
107
- $query = new EntityFieldQuery();
108
- $result = $query
109
- ->entityCondition('entity_type', 'node')
110
- ->propertyCondition('type', 'os2web_cp_service_cp_document')
111
- ->propertyCondition('status', 1)
112
- ->fieldCondition('field_os2web_cp_service_file_id', 'value', $file_id, '=')
113
- ->execute();
114
- $nids = (isset($result['node']))?array_keys($result['node']) : NULL;
115
-
116
- $node = node_load(array_pop($nids));
117
-
124
+ $filename = str_replace('/', '_', $file_id . '.' . os2web_cp_service_get_extension_from_mime($header['content_type']));
118
125
if ($node) {
126
+ // If we can find the doc in DB, give it a real name.
119
127
$filename = str_replace('/', '_', $node->field_os2web_cp_service_doc_id[LANGUAGE_NONE][0]['value'] . '.' . os2web_cp_service_get_extension_from_mime($header['content_type']));
120
- drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $filename);
121
128
}
129
+ drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $filename);
122
130
echo $data;
123
131
drupal_exit();
124
132
}
@@ -319,13 +327,6 @@ function os2web_cp_service_create_case(array $data) {
319
327
node_submit($node);
320
328
node_save($node);
321
329
322
- // Trigger a cache reload by calling the URL for the node.
323
- $cache_trigger = curl_init(url('sag/' . $node->field_os2web_cp_service_case_id[LANGUAGE_NONE][0]['value'], array('absolute' => TRUE)));
324
- // Stop the call after 1 sec. Dont care about the response.
325
- curl_setopt($cache_trigger, CURLOPT_TIMEOUT, 1);
326
- curl_exec($cache_trigger);
327
- curl_close($cache_trigger);
328
-
329
330
return TRUE;
330
331
}
331
332
catch (Exception $e) {
@@ -643,7 +644,6 @@ function os2web_cp_service_delete($guid) {
643
644
$query = new EntityFieldQuery();
644
645
$result = $query
645
646
->entityCondition('entity_type', 'node')
646
- ->propertyCondition('status', 1)
647
647
->fieldCondition('field_os2web_cp_service_key', 'value', $guid, '=')
648
648
->execute();
649
649
$nids = (isset($result['node']))?array_keys($result['node']) : array();
@@ -674,20 +674,21 @@ function os2web_cp_service_node_delete($node) {
674
674
$result = $query
675
675
->entityCondition('entity_type', 'node')
676
676
->propertyCondition('type', 'os2web_cp_service_cp_case')
677
- ->propertyCondition('status', 1)
678
677
->fieldCondition('field_os2web_cp_service_doc_ref', 'target_id', $node->nid, '=')
679
678
->execute();
680
- $nids = array_keys($result['node']);
681
- $new_nids = array();
682
- foreach ($nids as $nid) {
683
- $cnode = node_load($nid);
684
- foreach ($cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE] as $value) {
685
- if ($value['target_id'] != $node->nid) {
686
- $new_nids[] = $value;
679
+ if (!empty($result['node'])) {
680
+ $nids = array_keys($result['node']);
681
+ $new_nids = array();
682
+ foreach ($nids as $nid) {
683
+ $cnode = node_load($nid);
684
+ foreach ($cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE] as $value) {
685
+ if ($value['target_id'] != $node->nid) {
686
+ $new_nids[] = $value;
687
+ }
687
688
}
689
+ $cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE] = $new_nids;
690
+ node_save($cnode);
688
691
}
689
- $cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE] = $new_nids;
690
- node_save($cnode);
691
692
}
692
693
}
693
694
}
@@ -879,6 +880,18 @@ function os2web_cp_service_form_os2web_settings_settings_form_alter(&$form, &$fo
879
880
'#description' => 'Vises når den modtagede filtype ikke er godkendt til Download.',
880
881
'#default_value' => variable_get('os2web_cp_service_access_denied_message'),
881
882
);
883
+ $form['os2web_cp_service_config_group']['os2web_cp_service_disallow_mimes'] = array(
884
+ '#type' => 'textfield',
885
+ '#title' => 'Filers MIME type, som ikke må downloades af brugere.',
886
+ '#description' => 'Tillad kun filer som ikke har disse mimes. Seperer mimes med komma. Standard:.msg',
887
+ '#default_value' => variable_get('os2web_cp_service_disallow_mimes'),
888
+ );
889
+ $form['os2web_cp_service_config_group']['os2web_cp_service_disallow_mimes_exceptions'] = array(
890
+ '#type' => 'textfield',
891
+ '#title' => 'Sager hvor ALLE mimes er tilladt.',
892
+ '#description' => 'Tillad brugere at hente ALLE mime typer på angivende sager. Seperer sager med komma.',
893
+ '#default_value' => variable_get('os2web_cp_service_disallow_mimes_exceptions'),
894
+ );
882
895
}
883
896
884
897
/**
0 commit comments