From 12aad7b9d1b92328f480b2a79b539523fdbb7e4c Mon Sep 17 00:00:00 2001 From: onli Date: Wed, 29 Feb 2012 14:33:23 +0100 Subject: [PATCH] smartified import.inc.php --- include/admin/import.inc.php | 107 ++++++++++++------------------- include/admin/tpl/import.inc.tpl | 58 +++++++++++++++++ 2 files changed, 99 insertions(+), 66 deletions(-) create mode 100644 include/admin/tpl/import.inc.tpl diff --git a/include/admin/import.inc.php b/include/admin/import.inc.php index f0b4333a..8267d554 100644 --- a/include/admin/import.inc.php +++ b/include/admin/import.inc.php @@ -6,6 +6,8 @@ if (IN_serendipity !== true) { die ("Don't hack!"); } +$data = array(); + if (!serendipity_checkPermission('adminImport')) { return; } @@ -196,62 +198,41 @@ class Serendipity_Import { } } -if (isset($serendipity['GET']['importFrom']) && serendipity_checkFormToken()) { +if (isset($serendipity['GET']['importFrom']) && serendipity_checkFormToken()) { + $data['importForm'] = true; /* Include the importer */ $class = @require_once(S9Y_INCLUDE_PATH . 'include/admin/importers/'. basename($serendipity['GET']['importFrom']) .'.inc.php'); if ( !class_exists($class) ) { - die('FAILURE: Unable to require import module, possible syntax error?'); - } - - /* Init the importer with form data */ - $importer = new $class($serendipity['POST']['import']); - - /* Yes sir, we are importing if we have valid data */ - if ( $importer->validateData() ) { - echo IMPORT_STARTING . '
'; - - /* import() MUST return (bool)true, otherwise we assume it failed */ - if ( ($result = $importer->import()) !== true ) { - echo IMPORT_FAILED .': '. $result . '
'; - } else { - echo IMPORT_DONE . '
'; - } - - - /* Apprently we do not have valid data, ask for some */ + $data['die'] = true; } else { -?> -:
-
-
- - - getInputFields() as $field ) { ?> - - - - - - getImportNotes()){ ?> - - - - - - - -
-
- -
-
-validateData() ) { + $data['validateData'] = true; + + /* import() MUST return (bool)true, otherwise we assume it failed */ + if ( ($result = $importer->import()) !== true ) { + $data['result'] = $result; + } + /* Apprently we do not have valid data, ask for some */ + } else { + $data['formToken'] = serendipity_setFormToken(); + $fields = $importer->getInputFields(); + foreach ($fields as &$field ) { + ob_start(); + serendipity_guessInput($field['type'], 'serendipity[import]['. $field['name'] .']', (isset($serendipity['POST']['import'][$field['name']]) ? $serendipity['POST']['import'][$field['name']] : $field['default']), $field['default']); + $field['guessedInput'] = ob_get_contents(); + ob_end_clean(); + } + $data['fields'] = $fields; + $data['notes'] = $importer->getImportNotes(); + } } - } else { - $importpath = S9Y_INCLUDE_PATH . 'include/admin/importers/'; $dir = opendir($importpath); $list = array(); @@ -269,24 +250,18 @@ if (isset($serendipity['GET']['importFrom']) && serendipity_checkFormToken()) { } closedir($dir); ksort($list); -?> -.
-.
-
-:
-
-
- - - : - - -
-assign($data); +$tfile = dirname(__FILE__) . "/tpl/import.inc.tpl"; +$content = $serendipity['smarty']->fetch('file:'. $tfile); +echo $content; + + /* vim: set sts=4 ts=4 expandtab : */ diff --git a/include/admin/tpl/import.inc.tpl b/include/admin/tpl/import.inc.tpl new file mode 100644 index 00000000..8ab07c03 --- /dev/null +++ b/include/admin/tpl/import.inc.tpl @@ -0,0 +1,58 @@ +{if $importForm} + {if $die} + FAILURE: Unable to require import module, possible syntax error? + {else} + {if $validateData} + {$CONST.IMPORT_STARTING}
+ {if $result != true} + {$CONST.IMPORT_FAILED}: {$result}
+ {else} + {$CONST.IMPORT_DONE}
+ {/if} + {else} + {$CONST.IMPORT_PLEASE_ENTER} +
+
+ {$formToken} + + {foreach $fields as $field} + + + + + {/foreach} + {if $notes} + + + + {/if} + + + +
{$field.text}{$field.guessedInput}
+ {$CONST.IMPORT_NOTES}
+ {$notes} +
+
+ {/if} + {/if} +{else} + {$CONST.IMPORT_WELCOME}.
+ {$CONST.IMPORT_WHAT_CAN}.
+
+ {$CONST.IMPORT_SELECT}:
+
+
+ + {$formToken} + {$CONST.IMPORT_WEBLOG_APP}: + + +
+{/if} + + \ No newline at end of file