@@ -40,10 +40,29 @@ function os2web_edoc_esdh_mm_get_import_list() {
40
40
foreach (file_scan_directory (variable_get ('os2web_edoc_esdh_mm_path ' , MM_IMPORT_DIR ), '/\.xml$/i ' , array ('recurse ' => TRUE )) as $ xml_file ) {
41
41
$ uris [] = array ('id ' => dirname ($ xml_file ->uri ), 'uri ' => $ xml_file ->uri );
42
42
}
43
- error_log (print_r ($ xml_file , 1 ));
43
+ # error_log(print_r($xml_file, 1 ));
44
44
return $ uris ;
45
45
}
46
46
47
+
48
+ /**
49
+ * Strip illegal characters from the XML.
50
+ * Ex  = 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 = "";
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
+
47
66
/**
48
67
* Imports a meeting, and return the import as a structured array.
49
68
*
@@ -60,16 +79,28 @@ function os2web_edoc_esdh_mm_import_meeting($meeting) {
60
79
}
61
80
$ meetings = array ();
62
81
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
+
64
96
if (is_object ($ manifest )) {
65
97
$ committee = (string ) array_shift ($ manifest ->xpath ("/Meeting/Committee " ));
66
98
$ meeting_date = (string ) array_shift ($ manifest ->xpath ("/Meeting/MeetingDate " ));
67
99
$ directory_name = dirname (drupal_realpath ($ file ));
68
-
69
100
// 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 )));
71
102
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 ));
73
104
return FALSE ;
74
105
}
75
106
@@ -78,49 +109,31 @@ function os2web_edoc_esdh_mm_import_meeting($meeting) {
78
109
date_timezone_set ($ date_obj , timezone_open ('UTC ' ));
79
110
$ meeting_date = date_format ($ date_obj , 'Y-m-d H:i ' );
80
111
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
-
97
112
$ meeting = array (
98
113
'sys_id ' => $ directory_name ,
99
114
'committee ' => $ committee ,
100
115
'title ' => $ committee ,
116
+ 'uri ' => strstr ($ file , 'eDocAgendaPublishing.xml ' , TRUE ),
101
117
'meeting_date ' => $ meeting_date ,
102
118
);
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 ];
105
126
if (empty ($ meeting_agendas )) {
106
127
watchdog ('eDoc MM ' , 'Empty list of import items in %file. ' , array ('%file ' => $ file ), WATCHDOG_WARNING );
107
128
}
108
129
109
130
foreach ($ meeting_agendas as $ meeting_agenda ) {
110
-
111
131
$ imported = _os2web_edoc_esdh_mm_import_meeting_agenda ($ meeting , $ meeting_agenda );
112
-
132
+ error_log ( " du er her " );
113
133
if (is_array ($ imported )) {
114
134
$ imported ['publish ' ] = TRUE ;
115
135
$ meetings [] = $ imported ;
116
136
}
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
- // }
124
137
}
125
138
}
126
139
else {
@@ -143,29 +156,16 @@ error_log(print_r(array('committee' => $committee, 'date' => $meeting_date), 1))
143
156
* Meeting_struct array for an accepted import, else FALSE
144
157
*/
145
158
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
-
149
159
$ 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 ));
160
160
161
161
// 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 ' ] ))) {
163
163
$ agenda ['full_doc ' ] = array (
164
- 'uri ' => $ pdf_uri ,
164
+ 'uri ' => $ meeting [ ' uri ' ] . $ meeting [ ' pdf ' ] ,
165
165
'title ' => $ meeting ['committee ' ],
166
166
);
167
167
// Import all agenda items.
168
- foreach ($ agenda_xml ->xpath ("/MeetingAgendaItems " ) as $ agenda_item ) {
168
+ foreach ($ agenda_xml ->xpath ("/MeetingAgendaItems/MeetingAgendaItem " ) as $ agenda_item ) {
169
169
if (($ item = _os2web_edoc_esdh_mm_import_meeting_agenda_item ($ meeting , $ agenda_item )) !== FALSE ) {
170
170
$ agenda ['items ' ][] = $ item ;
171
171
}
0 commit comments