Skip to content

Commit d5f407c

Browse files
committed
Changes for edoc provider
1 parent fe1258c commit d5f407c

File tree

2 files changed

+60
-52
lines changed

2 files changed

+60
-52
lines changed

os2web_edoc_esdh.module

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
include_once('os2web_edoc_esdh.features.inc');
99

10-
define('MM_IMPORT_DIR', 'public://sbsys');
10+
define('MM_IMPORT_DIR', 'public://edoc');
1111
define('MM_DEFAULT_APPROVED', '62,59,64,53,54,56,57,63,58,51,55,61,68,69,42');
12+
define('MM_DEFAULT_BANNED_CHAR', '');
1213

1314
/**
1415
* Implements hook_ctools_plugin_directory().
@@ -37,7 +38,7 @@ function os2web_edoc_esdh_form_os2web_settings_settings_form_alter(&$form, &$for
3738
);
3839
$form['meetings']['os2web_edoc_esdh_mm_path'] = array(
3940
'#type' => 'textfield',
40-
'#title' => 'Sti til sbsys publish folder.',
41+
'#title' => 'Sti til edoc publish folder.',
4142
'#description' => 'Dette er stien hvor ESDH publisere .XML filer til.',
4243
'#default_value' => variable_get('os2web_edoc_esdh_mm_path', MM_IMPORT_DIR),
4344
);
@@ -48,6 +49,13 @@ function os2web_edoc_esdh_form_os2web_settings_settings_form_alter(&$form, &$for
4849
'#description' => 'Komma sepereret liste over udvalgs-id der er godkendt til publisering.',
4950
'#default_value' => variable_get('os2web_edoc_esdh_approved_committees', MM_DEFAULT_APPROVED),
5051
);
52+
$form['meetings']['os2web_edoc_esdh_banned_special_char'] = array(
53+
'#type' => 'textfield',
54+
'#title' => 'Ikke standard XML tegn der skal fjernes ved import',
55+
'#maxlength' => 200,
56+
'#description' => 'Komma sepereret liste over ikke standard tegn der skal fjernes ved import.',
57+
'#default_value' => variable_get('os2web_edoc_esdh_banned_special_char', MM_DEFAULT_BANNED_CHAR),
58+
);
5159
}
5260

5361
/**
@@ -56,7 +64,7 @@ function os2web_edoc_esdh_form_os2web_settings_settings_form_alter(&$form, &$for
5664
function os2web_edoc_esdh_os2web_help($sections) {
5765

5866
// Content types.
59-
$sections['configuration'] = t('<p><a href="@url" target="_blank">See the advanced documentation for sbsys</a></p>', array('@url' => url('admin/help/os2web_edoc_esdh')));
67+
$sections['configuration'] = t('<p><a href="@url" target="_blank">See the advanced documentation for edoc</a></p>', array('@url' => url('admin/help/os2web_edoc_esdh')));
6068
return $sections;
6169
}
6270

@@ -67,6 +75,6 @@ function os2web_edoc_esdh_help($path, $arg) {
6775
switch ($path) {
6876
case 'admin/help#os2web_edoc_esdh':
6977
// TODO.
70-
return t('Missing documentation.');
78+
return t('Se the OS2web documentation under "help" for details.');
7179
}
7280
}

plugins/mm/os2web_edoc_esdh_mm.inc

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,29 @@ function os2web_edoc_esdh_mm_get_import_list() {
4040
foreach (file_scan_directory(variable_get('os2web_edoc_esdh_mm_path', MM_IMPORT_DIR), '/\.xml$/i', array('recurse' => TRUE)) as $xml_file) {
4141
$uris[] = array('id' => dirname($xml_file->uri), 'uri' => $xml_file->uri);
4242
}
43-
error_log(print_r($xml_file, 1 ));
43+
#error_log(print_r($xml_file, 1 ));
4444
return $uris;
4545
}
4646

47+
48+
/**
49+
* Strip illegal characters from the XML.
50+
* Ex &#xC = ASCII new line feed
51+
*
52+
* @param object $string
53+
* string to sanitise
54+
*
55+
* $return array
56+
* The string sanitised
57+
*/
58+
function utf8_for_xml($string)
59+
{
60+
#$replace_me = "&#xC;";
61+
$replace_me = variable_get('os2web_edoc_esdh_banned_special_char');
62+
$str_new = str_replace($replace_me, "", $string);
63+
return $str_new;
64+
}
65+
4766
/**
4867
* Imports a meeting, and return the import as a structured array.
4968
*
@@ -60,16 +79,28 @@ function os2web_edoc_esdh_mm_import_meeting($meeting) {
6079
}
6180
$meetings = array();
6281
if (is_file(drupal_realpath($file))) {
63-
$manifest = simplexml_load_file(drupal_realpath($file));
82+
83+
libxml_use_internal_errors(true);
84+
$manifest = simplexml_load_string(utf8_for_xml(file_get_contents(drupal_realpath($file))), 'SimpleXMLElement', LIBXML_NOWARNING);
85+
86+
libxml_clear_errors();
87+
libxml_use_internal_errors(false);
88+
89+
if ($manifest === false) {
90+
error_log("Failed loading XML");
91+
foreach(libxml_get_errors() as $error) {
92+
error_log ($error->message);
93+
}
94+
}
95+
6496
if (is_object($manifest)) {
6597
$committee = (string) array_shift($manifest->xpath("/Meeting/Committee"));
6698
$meeting_date = (string) array_shift($manifest->xpath("/Meeting/MeetingDate"));
6799
$directory_name = dirname(drupal_realpath($file));
68-
69100
// Check if the committee is allowed to publish.
70-
$publish_committee = array_map('trim', explode(',', variable_get('os2web_meetings_approved_committee', MM_DEFAULT_APPROVED)));
101+
$publish_committee = array_map('trim', explode(',', variable_get('os2web_edoc_esdh_approved_committees', MM_DEFAULT_APPROVED)));
71102
if ($committee == '' || !in_array($committee, $publish_committee)) {
72-
watchdog('eDoc MM', 'Ignored agenda from %committee .', array('%committee' => $committee));
103+
watchdog('eDoc MM', 'Ignored agenda from "%committee" .', array('%committee' => $committee));
73104
return FALSE;
74105
}
75106

@@ -78,49 +109,31 @@ function os2web_edoc_esdh_mm_import_meeting($meeting) {
78109
date_timezone_set($date_obj, timezone_open('UTC'));
79110
$meeting_date = date_format($date_obj, 'Y-m-d H:i');
80111

81-
// Handle type of meeting.
82-
// Type:
83-
// switch ($info['type']) {
84-
// case 1:
85-
// $meeting['type'] = 'Dagsorden';
86-
// break;
87-
88-
// case 2:
89-
// $meeting['type'] = 'Referat';
90-
// break;
91-
92-
// default:
93-
// $meeting['type'] = 'Anden';
94-
// watchdog('eDoc MM', 'Unknown meeting type value: %type', array('%type' => $meeting['type']), WATCHDOG_WARNING);
95-
// }
96-
97112
$meeting = array(
98113
'sys_id' => $directory_name,
99114
'committee' => $committee,
100115
'title' => $committee,
116+
'uri' => strstr($file , 'eDocAgendaPublishing.xml', TRUE),
101117
'meeting_date' => $meeting_date,
102118
);
103-
error_log(print_r(array('committee' => $committee, 'date' => $meeting_date), 1));
104-
$meeting_agendas = $manifest->xpath("/Meeting/MeetingAgendaTypes");
119+
$meeting_agendas = $manifest->xpath("/Meeting/MeetingAgendaTypes/MeetingAgendaType/MeetingAgendaItems");
120+
$meeting_state = $manifest->xpath('/Meeting/MeetingState');
121+
$meeting['state'] = (string) $meeting_state[0];
122+
$meeting_type = $manifest->xpath('/Meeting/MeetingAgendaTypes/MeetingAgendaType/AgendaType');
123+
$meeting['type'] = (string) $meeting_type[0];
124+
$meeting_pdf = $manifest->xpath('/Meeting/MeetingAgendaTypes/MeetingAgendaType/PDFDocument');
125+
$meeting['pdf'] = (string) $meeting_pdf[0];
105126
if (empty($meeting_agendas)) {
106127
watchdog('eDoc MM', 'Empty list of import items in %file.', array('%file' => $file), WATCHDOG_WARNING);
107128
}
108129

109130
foreach ($meeting_agendas as $meeting_agenda) {
110-
111131
$imported = _os2web_edoc_esdh_mm_import_meeting_agenda($meeting, $meeting_agenda);
112-
132+
error_log("du er her");
113133
if (is_array($imported)) {
114134
$imported['publish'] = TRUE;
115135
$meetings[] = $imported;
116136
}
117-
// else {
118-
// // Publication not published or public.
119-
// $meetings[] = array(
120-
// 'system_id' => $agendainfo['sysid'],
121-
// 'publish' => FALSE,
122-
// ) + os2web_esdh_provider_default_meeting();
123-
// }
124137
}
125138
}
126139
else {
@@ -143,29 +156,16 @@ error_log(print_r(array('committee' => $committee, 'date' => $meeting_date), 1))
143156
* Meeting_struct array for an accepted import, else FALSE
144157
*/
145158
function _os2web_edoc_esdh_mm_import_meeting_agenda(&$meeting, $agenda_xml) {
146-
$xml_item_pdf = (string) array_shift($agenda_xml->xpath('/PDFDocument'));
147-
$xml_item_type = (string) array_shift($agenda_xml->xpath('/AgendaType'));
148-
149159
$meeting['items'] = array();
150-
$meeting['type'] = $xml_item_type;
151-
152-
153-
$pdf_uri = implode('/', array(
154-
variable_get('os2web_edoc_esdh_mm_path', MM_IMPORT_DIR),
155-
$meeting['sys_id'],
156-
$xml_item_pdf,
157-
));
158-
159-
error_log(print_r($agendainfo, 1));
160160

161161
// Only add the agenda if its PDF exists.
162-
if (file_exists(drupal_realpath($pdf_uri))) {
162+
if (file_exists(drupal_realpath($meeting['uri'] . $meeting['pdf']))) {
163163
$agenda['full_doc'] = array(
164-
'uri' => $pdf_uri,
164+
'uri' => $meeting['uri'] . $meeting['pdf'],
165165
'title' => $meeting['committee'],
166166
);
167167
// Import all agenda items.
168-
foreach ($agenda_xml->xpath("/MeetingAgendaItems") as $agenda_item) {
168+
foreach ($agenda_xml->xpath("/MeetingAgendaItems/MeetingAgendaItem") as $agenda_item) {
169169
if (($item = _os2web_edoc_esdh_mm_import_meeting_agenda_item($meeting, $agenda_item)) !== FALSE) {
170170
$agenda['items'][] = $item;
171171
}

0 commit comments

Comments
 (0)