tiki-importer.php 3.32 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
6
//
changi67's avatar
changi67 committed
7 8 9
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
10 11

require_once('tiki-setup.php');
12 13
require_once('lib/importer/tikiimporter.php');
require_once('lib/importer/tikiimporter_wiki.php');
14

15
$access->check_permission('tiki_p_admin_importer');
16

rjsmelo's avatar
rjsmelo committed
17 18
if (! empty($_POST['importerClassName'])) {
	$importerClassName = filter_input(INPUT_POST, 'importerClassName', FILTER_SANITIZE_STRING);
19

rjsmelo's avatar
rjsmelo committed
20 21 22
	switch ($importerClassName) {
		case 'TikiImporter_Wiki_Mediawiki':
			require_once('lib/importer/tikiimporter_wiki_mediawiki.php');
23
			break;
rjsmelo's avatar
rjsmelo committed
24 25
		case 'TikiImporter_Blog_Wordpress':
			require_once('lib/importer/tikiimporter_blog_wordpress.php');
26
			break;
rjsmelo's avatar
rjsmelo committed
27
		case 'default':
28
			break;
rjsmelo's avatar
rjsmelo committed
29
	}
30

rjsmelo's avatar
rjsmelo committed
31 32
	$importer = new $importerClassName();
	$smarty->assign('softwareName', $importer->softwareName);
33

rjsmelo's avatar
rjsmelo committed
34
	TikiImporter::changePhpSettings();
35
}
36

37
if (isset($_SESSION['tiki_importer_feedback'])) {
rjsmelo's avatar
rjsmelo committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
	$smarty->assign('importFeedback', $_SESSION['tiki_importer_feedback']);
	$smarty->assign('importLog', $_SESSION['tiki_importer_log']);
	$smarty->assign('importErrors', $_SESSION['tiki_importer_errors']);
	$smarty->assign('safe_mode', ini_get('safe_mode'));
	unset($_SESSION['tiki_importer_feedback']);
	unset($_SESSION['tiki_importer_log']);
	unset($_SESSION['tiki_importer_errors']);

	// wordpress specific
	if (isset($_SESSION['tiki_importer_wordpress_urls'])) {
		$smarty->assign('wordpressUrls', $_SESSION['tiki_importer_wordpress_urls']);
		unset($_SESSION['tiki_importer_wordpress_urls']);
	}
} elseif (! empty($_FILES['importFile'])) {
	// third step: start the importing process

	if ($_FILES['importFile']['error'] === UPLOAD_ERR_OK) {
		try {
			$importer->import($_FILES['importFile']['tmp_name']);
		} catch (Exception $e) {
			$smarty->assign('msg', $e->getMessage());
			$smarty->display('error.tpl');
			die;
		}
	} else {
		$msg = TikiImporter::displayPhpUploadError($_FILES['importFile']['error']);
		$smarty->assign('msg', $msg);
		$smarty->display('error.tpl');
		die;
	}

	die;
} elseif (! empty($_POST['importerClassName'])) {
	// second step: display import options for the software previously chosen
	if (! class_exists($importerClassName)) {
		$smarty->assign('msg', tra("Invalid software name"));
		$smarty->display("error.tpl");
		die;
	}
77 78 79 80 81 82 83 84 85

	try {
		$importer->checkRequirements();
	} catch (Exception $e) {
		$smarty->assign('msg', $e->getMessage());
		$smarty->display('error.tpl');
		die;
	}

rjsmelo's avatar
rjsmelo committed
86
	$importerOptions = $importer->getOptions();
87

rjsmelo's avatar
rjsmelo committed
88 89 90
	$smarty->assign('importerOptions', $importerOptions);
	$smarty->assign('softwareSpecificOptions', true);
	$smarty->assign('importerClassName', $importerClassName);
91
} else {
rjsmelo's avatar
rjsmelo committed
92
	// first step: display the list of available software importers
93

94 95
	// $availableSoftwares is an array that control the list of available software importers.
	// The array key is the name of the importer class and the value is the name of the software
rjsmelo's avatar
rjsmelo committed
96
	$availableSoftwares = [
97 98
		'TikiImporter_Wiki_Mediawiki' => 'Mediawiki',
		'TikiImporter_Blog_Wordpress' => 'Wordpress',
rjsmelo's avatar
rjsmelo committed
99
	];
100

rjsmelo's avatar
rjsmelo committed
101 102
	$smarty->assign('availableSoftwares', $availableSoftwares);
	$smarty->assign('chooseSoftware', true);
103 104 105 106
}

$smarty->assign('mid', 'tiki-importer.tpl');
$smarty->display('tiki.tpl');