Update of /cvsroot/php-blog/serendipity/include/admin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27345/include/admin
Added Files:
Tag: branch-smarty
export.inc.php import.inc.php
Removed Files:
Tag: branch-smarty
interop.inc.php rss_exchange.inc.php
Log Message:
- Draft for new import framework. It's working, but might need some changes to make it a little more pretty
Note: Please review your importer methods, like validateData() etc.
- Split importer and exporter up into two menuitems
- Don't let serendipity_guessInput() parse data, it should just act on the data given
- Add 'file' type to serendipity_guessInput(), implementing <input type="file">
--- interop.inc.php DELETED ---
--- NEW FILE: import.inc.php ---
<?php # $Id: import.inc.php,v 1.1.2.1 2004/11/15 21:06:49 tomsommer Exp $
if (IN_serendipity !== true) {
die ("Don't hack!");
}
if ( $serendipity['serendipityUserlevel'] != USERLEVEL_ADMIN ) {
return;
}
/* For later use */
class Serendipity_Import {
}
if ( isset($serendipity['GET']['importFrom']) ) {
/* Include the importer
HIGH PRIORITY TODO: Must validate $serendipity['GET']['importFrom']
*/
$class = @require_once(S9Y_INCLUDE_PATH . 'include/admin/importers/'. $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 . '<br />';
/* import() MUST return (bool)true, otherwise we assume it failed */
if ( ($result = $importer->import()) !== true ) {
echo IMPORT_FAILED .': '. $result . '<br />';
} else {
echo IMPORT_DONE . '<br />';
}
/* Apprently we do not have valid data, ask for some */
} else {
?>
<?php echo IMPORT_PLEASE_ENTER ?>:<br />
<br />
<form action="" method="POST">
<table cellpadding="3" cellspacing="2">
<?php foreach ( $importer->getInputFields() as $field ) { ?>
<tr>
<td><?php echo $field['text'] ?></td>
<td><?php serendipity_guessInput($field['type'], 'serendipity[import]['. $field['name'] .']', $serendipity['POST']['import'][$field['name']], $field['default']) ?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2" align="right"><input type="submit" value="<?php echo IMPORT_NOW ?>"></td>
</tr>
</table>
</form>
<?php
}
} else {
$importpath = S9Y_INCLUDE_PATH . 'include/admin/importers/';
$dir = opendir($importpath);
$list = array();
while (($file = readdir($dir)) !== false ) {
if (!is_file($importpath . $file)) {
continue;
}
$class = include_once($importpath . $file);
if ( class_exists($class) ) {
$tmpClass = new $class(array());
$list[substr($file, 0, strpos($file, '.'))] = $tmpClass->info['software'];
unset($tmpClass);
}
}
closedir($dir);
natsort($list);
?>
<?php echo IMPORT_WELCOME ?>.<br />
<?php echo IMPORT_WHAT_CAN ?>. <br />
<br />
<?php echo IMPORT_SELECT ?>:<br />
<br />
<form action="" method="GET">
<input type="hidden" name="serendipity[adminModule]" value="import">
<strong><?php echo IMPORT_WEBLOG_APP ?>: </strong>
<select name="serendipity[importFrom]">
<?php foreach ($list as $v=>$k) { ?>
<option value="<?php echo $v ?>"><?php echo $k ?></option>
<?php } ?>
</select>
<input type="submit" value="<?php echo GO ?>">
</form>
<?php
}
/* vim: set sts=4 ts=4 expandtab : */
?>
--- rss_exchange.inc.php DELETED ---
--- NEW FILE: export.inc.php ---
<?php # $Id: export.inc.php,v 1.1.2.1 2004/11/15 21:06:49 tomsommer Exp $
if (IN_serendipity !== true) {
die ("Don't hack!");
}
?>
<div>
<input type="submit" name="serendipity[export]" value="<?php echo EXPORT_FEED; ?>" onclick="location.href='<?php echo $serendipity['baseURL'] ?>rss.php?version=2.0&all=1'" />
</div>
<?php
/* vim: set sts=4 ts=4 expandtab : */
?>
|