forked from vanilla/porter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·129 lines (109 loc) · 3.42 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* Vanilla 2 Exporter Plus is a modified version or fork of Vanilla 2 Exporter to provide various parsing options.
* Which carries the following GPL:
*
* This script exports other forum databases to the Vanilla 2 import format.
* To use this script, copy it to your web server and open it in your browser.
* If you have a large database, make the directory writable so that the export file can be saved locally and zipped.
*
* @copyright 2010 Vanilla Forums Inc.
* @license GNU GPLv2
* @package VanillaPorter
*/
define('APPLICATION', 'Vanilla 2 Exporter Plus');
define('APPLICATION_VERSION', 'b0.2');
if(TRUE || defined('DEBUG'))
error_reporting(E_ALL);
else
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR);
ini_set('display_errors', 'on');
ini_set('track_errors', 1);
/** @var array Supported forum packages: classname => array(name, prefix) */
global $Supported;
// Support Files
include_once 'class.exportmodel.php';
include_once 'views.php';
include_once 'class.exportcontroller.php';
include_once 'functions.php';
// Set Vanilla to appear first in the list.
$Supported = array(
'vanilla1' => array('name'=> 'Vanilla 1.*', 'prefix'=>'LUM_'),
'vanilla2' => array('name'=> 'Vanilla 2.*', 'prefix'=>'GDN_')
);
// Include individual software porters.
// MAKESKIPSTART
$Paths = glob(dirname(__FILE__).'/class.*.php');
foreach ($Paths as $Path) {
include_once $Path;
}
// MAKESKIPEND
include_once 'functions.commandline.php';
// Make sure a default time zone is set
if (ini_get('date.timezone') == '')
date_default_timezone_set('America/Montreal');
if (PHP_SAPI == 'cli')
define('CONSOLE', TRUE);
if (defined('CONSOLE')) {
ParseCommandLine();
}
if (isset($_GET['type'])) {
$CustomType = $_GET['type'];
if (!isset($Supported[$CustomType])) {
$Path = 'class.'.strtolower($CustomType).'.php';
if (file_exists($Path)) {
$Supported[$CustomType] = array('name' => $CustomType.' (custom)', 'prefix' => '');
include_once($Path);
}
}
}
$Method = 'DoExport';
//if (isset($_POST['doavatars']) && $_POST['doavatars'])
//$Method = 'DoAvatars';
// Instantiate the appropriate controller or display the input page.
if(isset($_POST['type']) && array_key_exists($_POST['type'], $Supported)) {
// Mini-Factory
$class = ucwords($_POST['type']);
$Controller = new $class();
if (!method_exists($Controller, $Method)) {
echo "This datasource type does not support {$Method}.\n";
exit();
}
$Controller->$Method();
}
else {
$CanWrite = TestWrite();
ViewForm(array('Supported' => $Supported, 'CanWrite' => $CanWrite));
}
if (defined('CONSOLE'))
echo "\n";
function ErrorHandler($errno, $errstr) {
echo "Error: ({$errno}) {$errstr}\n";
die();
}
set_error_handler("ErrorHandler");
/**
* Write out a value passed as bytes to its most readable format.
*/
function FormatMemorySize($Bytes, $Precision = 1) {
$Units = array('B', 'K', 'M', 'G', 'T');
$Bytes = max((int)$Bytes, 0);
$Pow = floor(($Bytes ? log($Bytes) : 0) / log(1024));
$Pow = min($Pow, count($Units) - 1);
$Bytes /= pow(1024, $Pow);
$Result = round($Bytes, $Precision).$Units[$Pow];
return $Result;
}
/**
* Test filesystem permissions
*/
function TestWrite() {
// Create file
$file = 'vanilla2test.txt';
@touch($file);
if(is_writable($file)) {
@unlink($file);
return true;
}
else return false;
}