18 require_once SQ_SYSTEM_ROOT.
'/core/assets/system/tool/tool.inc';
19 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
20 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
21 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
22 require_once SQ_DATA_PATH.
'/private/conf/import_tools_manager.inc';
50 $this->
Tool($assetid);
66 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
67 $itm = $am->getSystemAsset(
'import_tools_manager');
69 $import_dir = STRUCTURED_FILE_IMPORT_DIR;
70 if (empty($import_dir)) {
72 $o->openSection(
'Warning');
73 $o->openField(translate(
'import_tools_not_ready'));
74 echo translate(
'import_tools_not_ready_msg');
81 $tool_info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type_code);
82 $o->openSection($tool_info[
'name']);
84 $compatible_types = $itm->attr(
'valid_file_types');
85 $o->openField(translate(
'import_tools_import_dir'));
88 $o->openField(translate(
'import_tools_files'));
90 $files_array = list_files($import_dir, TRUE);
92 foreach ($files_array as $id => $file_name) {
93 $file_type = get_file_type($file_name);
94 if (!in_array($file_type, $compatible_types)) {
95 unset($files_array[$id]);
99 <script
type=
"text/javascript">
101 $tmp =
'var file_list =[';
102 for (reset($files_array); $key = key($files_array); next($files_array)) {
103 $strrpos_files_array = strrpos($files_array[$key],
'/') + 1;
104 $stripped_fname = substr($files_array[$key], $strrpos_files_array);
105 $tmp .=
'"'.str_replace(Array(
'.',
' '),
'_', $stripped_fname).
'",';
107 echo substr($tmp, 0, -1).
'];';
109 function uncheck_import_file() {
110 var form = document.getElementById(
"main_form");
111 for (counter = 0; counter < form.structured_file_import_filename.length; counter++) {
112 if (form.structured_file_import_filename[counter].value ==
'') {
113 form.structured_file_import_filename[counter].checked =
true;
115 form.structured_file_import_filename[counter].checked =
false;
119 function can_select() {
120 for (counter = 0; counter < file_list.length; counter++ ) {
121 var delete_chkbox = document.getElementById(
"structured_file_remove_" + file_list[counter]);
122 if (delete_chkbox.checked ==
true) {
123 uncheck_import_file();
124 alert(
"<?php echo translate("import_tools_javascript_warning
"); ?>");
130 <table
class=
"sq-backend-table" style=
"width: 440px;">
132 <th
class=
"sq-backend-table-header" style=
"width: 240px;"><?php echo translate(
'import_tools_select_file'); ?></th>
133 <th
class=
"sq-backend-table-header" style=
"width: 100px;"><?php echo translate(
'import_tools_select_for_import'); ?></th>
134 <th
class=
"sq-backend-table-header" style=
"width: 100px; text-align: center;"><?php echo translate(
'import_tools_select_for_removal'); ?></th>
137 <td
class=
"sq-backend-table-cell"><?php echo translate(
'none'); ?></td>
138 <td
class=
"sq-backend-table-cell" style=
"text-align: center;"><?php radio_button(
'structured_file_import_filename',
'', TRUE); ?></td>
139 <td
class=
"sq-backend-table-cell" style=
"text-align: center;"></td>
142 foreach ($files_array as $file_name) {
143 $strrpos_file_name = strrpos($file_name,
'/') + 1;
144 $stripped_fname = substr($file_name, $strrpos_file_name);
145 $replaced_fname = str_replace(Array(
'.',
' '),
'_', $stripped_fname);
148 <td
class=
"sq-backend-table-cell"><?php echo $stripped_fname; ?></td>
149 <td
class=
"sq-backend-table-cell" style=
"text-align: center;"><?php radio_button(
'structured_file_import_filename', $file_name, FALSE,
'can_select();'); ?></td>
150 <td
class=
"sq-backend-table-cell" style=
"text-align: center;"><?php check_box(
'structured_file_remove_'.$replaced_fname,
'1', FALSE,
'uncheck_import_file();'); ?></td>
157 $o->note(translate(
'import_tools_select_file'));
160 $o->openField(translate(
'import_tools_asset_to_import'));
161 asset_finder($type_code.
'_root_assetid',
'');
163 $o->openField(translate(
'import_tools_new_site'));
165 <table
class=
"sq-backend-table" style=
"width: 300px;">
168 <?php echo translate(
'import_tools_create_new_site'); ?>
172 check_box($type_code.
'_create_new_site',
'1');
178 <?php echo translate(
'import_tools_create_new_site_name'); ?>
182 text_box($type_code.
'_new_site_name',
'',
'30',
'255');
188 <?php echo
'Create Site Map for New Site:'; ?>
192 check_box($type_code.
'_create_new_map',
'1');
198 $o->note(translate(
'import_tools_create_new_site_note'));
200 $o->openField(
'Headings to Split On');
201 check_box($type_code.
'_no_headings',
'1', FALSE,
'document.getElementById(\''.$type_code.
'_headings_table\').style.visibility = (this.checked == true) ? \'hidden\' : \'\';');
202 label(
'Import as a Single Page (Headings will be ignored)', $type_code.
'_no_headings');
203 $heading_defaults = $itm->attr(
'heading_defaults');
205 <table
id=
"<?php echo $type_code.'_headings_table'; ?>" class=
"sq-backend-table" style=
"width: 300px;">
207 <th
class=
"sq-backend-table-header"><?php echo translate(
'import_tools_heading_style'); ?></th>
208 <th
class=
"sq-backend-table-header" style=
"width: 120px;"><?php echo translate(
'import_tools_use_for_structure'); ?></th>
212 for ($i = 1; $i <= 6; $i++) {
213 $h_string =
'h'.strval($i);
216 <td
class=
"sq-backend-table-cell"><?php echo strtoupper($h_string); ?></td>
217 <td
class=
"sq-backend-table-cell" style=
"text-align: center;">
219 check_box(
'structured_file_import_headings['.$h_string.
']',
'1', in_array($h_string, $heading_defaults));
229 $o->openField(translate(
'import_tools_create_css'));
230 check_box($type_code.
'_create_css',
'1', $itm->attr(
'create_css_file'));
231 $o->note(translate(
'import_tools_create_css_note'));
233 $o->openField(translate(
'import_tools_leading_text'));
234 check_box($type_code.
'_leading_text',
'1');
235 $o->note(translate(
'import_tools_leading_text_note'));
237 $o->openField(translate(
'import_tools_leading_page_name'));
238 text_box($type_code.
'_leading_name',
'Preface');
239 $o->note(translate(
'import_tools_leading_page_name_note'));
243 $o->openSection(translate(
'import_tools_tidying_options'));
244 $o->openField(translate(
'import_tools_word_tags'));
245 check_box($type_code.
'_remove_word',
'1');
247 $o->openField(translate(
'import_tools_html_tidy'));
248 check_box($type_code.
'_run_tidy');
249 $o->note(translate(
'import_tools_tidy_note'));
251 $o->openField(translate(
'import_tools_footnotes'));
252 check_box($type_code.
'_footnotes');
273 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
274 $itm = $am->getSystemAsset(
'import_tools_manager');
276 $vars[
'import_file'] = array_get_index($_POST,
'structured_file_import_filename',
'');
277 $vars[
'remove_file'] = array_get_index($_POST,
'structured_file_remove_filename',
'');
278 $vars[
'create_new_site'] = FALSE;
279 if (isset($_POST[$type_code.
'_create_new_site'])) {
281 $vars[
'create_new_site'] = TRUE;
282 $vars[
'new_site_name'] = $_POST[$type_code.
'_new_site_name'];
284 $vars[
'root_assetid'] = $_POST[$type_code.
'_root_assetid'][
'assetid'];
285 $vars[
'use_headings'] = isset($_POST[$type_code.
'_no_headings']) ? FALSE : TRUE;
286 $vars[
'headings'] = array_keys($_POST[
'structured_file_import_headings']);
287 $vars[
'import_dir'] = STRUCTURED_FILE_IMPORT_DIR;
288 $vars[
'create_css'] = isset($_POST[$type_code.
'_create_css_file']);
289 $vars[
'create_site_map'] = isset($_POST[$type_code.
'_create_new_map']);
290 $vars[
'leading_create'] = isset($_POST[$type_code.
'_leading_text']);
291 $vars[
'leading_text'] = $_POST[$type_code.
'_leading_name'];
293 $vars[
'remove_word'] = isset($_POST[$type_code.
'_remove_word']);
294 $vars[
'run_tidy'] = isset($_POST[$type_code.
'_run_tidy']);
295 $vars[
'fix_anchors'] = isset($_POST[$type_code.
'_footnotes']);
297 if ($vars[
'run_tidy']) {
298 $vars[
'tidy_path'] = SQ_TOOL_HTML_TIDY_PATH;
302 $import_dir = STRUCTURED_FILE_IMPORT_DIR;
303 $files_array = list_files($import_dir, TRUE);
304 $remove_list = Array();
305 foreach ($files_array as $id => $file_name) {
306 $strrpos_files_name = strrpos($file_name,
'/') + 1;
307 $stripped_fname = substr($file_name, $strrpos_files_name);
308 $replaced_fname = str_replace(Array(
'.',
' '),
'_', $stripped_fname);
309 if (isset($_POST[
'structured_file_remove_'.$replaced_fname])) {
310 $remove_list[] = $stripped_fname;
313 if (empty($remove_list)) {
315 if (($vars[
'import_file'] ==
'') || (empty($vars[
'headings']) && ($vars[
'use_headings'])) || ($vars[
'root_assetid'] ==
'' && $vars[
'create_new_site'] == FALSE)) {
320 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
321 $hh->queueHipo(
'hipo_job_structured_file_import', $vars,
'', SQ_PACKAGES_PATH.
'/import_tools/hipo_jobs/');
322 $url = $hh->runQueuedJobs();
323 if (!empty($url)) $o->setRedirect($url);
328 foreach ($remove_list as $file_name) {
329 $tmp = explode(
'.', $file_name);
330 $fname_no_ext = $tmp[0];
331 if (file_exists($import_dir.
'/'.$file_name)) {
332 $success = unlink($import_dir.
'/'.$file_name);
334 if ($success && file_exists($import_dir.
'/'.$fname_no_ext.
'.doc')) {
335 $success = unlink($import_dir.
'/'.$fname_no_ext.
'.doc');
337 if ($success && file_exists($import_dir.
'/'.$fname_no_ext.
'.dot')) {
338 $success = unlink($import_dir.
'/'.$fname_no_ext.
'.dot');
340 if ($success && file_exists($import_dir.
'/'.$fname_no_ext.
'_files')) {
341 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
342 $success = delete_directory($import_dir.
'/'.$fname_no_ext.
'_files');
346 trigger_error(
'Failed to delete the imported files.');