Skip to content

Commit 0b3068d

Browse files
committed
Option Max File Size
1 parent 69a5dd2 commit 0b3068d

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

mathilda.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function mathilda_activate () {
9494
add_option('mathilda_import_finish', "0");
9595
add_option('mathilda_import_subprocess_running', "0");
9696
add_option('mathilda_load_process_running',"0");
97+
add_option('mathilda_import_filesize_max',"409600");
9798

9899
/* Create Mathilda Tables */
99100

@@ -206,6 +207,7 @@ function mathilda_delete () {
206207
delete_option('mathilda_import_finish');
207208
delete_option('mathilda_import_subprocess_running');
208209
delete_option('mathilda_load_process_running');
210+
delete_option('mathilda_import_filesize_max');
209211

210212
/* Delete Tables */
211213

mathilda_import.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ function mathilda_import_tool() {
4646
$twitter_import_path = mathilda_get_import_directory();
4747

4848
/*
49-
Arrays
49+
Variables & Arrays
5050
*/
5151

5252
$list_import_files_draft=array();
5353
$number_of_files_draft=0;
5454
$list_import_files=array();
5555
$number_of_files=0;
56+
$max_file_size=0;
57+
$filesize_max_threshold=get_option('mathilda_import_filesize_max');
58+
$filesize_max_string=$filesize_max_threshold;
59+
$filesize_max_string=$filesize_max_string/1024;
5660

5761
/*
5862
Read Files @ Import Directory
@@ -105,6 +109,22 @@ function mathilda_import_tool() {
105109

106110
array_multisort($list_import_files);
107111

112+
/*
113+
Get Max File Size
114+
*/
115+
116+
for($i=0; $i<$number_of_files; $i++)
117+
{
118+
119+
$filename_with_path=$twitter_import_path . '/' . $list_import_files[$i][0];
120+
$filesize_this=filesize($filename_with_path);
121+
122+
if($filesize_this>$max_file_size) {
123+
$max_file_size=$filesize_this;
124+
}
125+
126+
}
127+
108128
/*
109129
Check Number of Files
110130
*/
@@ -116,10 +136,24 @@ function mathilda_import_tool() {
116136
echo 'Please follow the instructions below.</p>';
117137
echo '<p><strong>Required Steps</strong></p>';
118138
echo '<p>1. Download your tweet archive from Twitter (Profile/Settings).<br/>';
119-
echo '2. Upload all files from /data/js/tweets to /wp-content/uploads/mathilda-import.<br/>';
120-
echo '3. Run this import script again.</p>';
139+
echo '2. Split the file data/tweets.js into smaller files (<'.$filesize_max_string.' KB) with a local app.<br/>';
140+
echo '3. Upload all files to the folder wp-content/uploads/mathilda-import.</br>';
141+
echo '4. Run this import script again.</p>';
142+
echo '<p>&nbsp;<br/><a class="button" href="'.admin_url().'tools.php?page=mathilda-tools-menu">Close</a></p>';
143+
return;
144+
145+
}
146+
147+
if ($max_file_size>$filesize_max_threshold) {
148+
149+
echo '<p><strong>Error</strong></p>';
150+
echo '<p>One or more files in the import folder are larger as '.$filesize_max_string.' KB.<br/>';
151+
echo 'Unfortunately the import process is limited to files not larger as 400 KB.<br/>';
152+
echo 'You must split the affected files in smaller files with a local app.<br/>';
153+
echo 'After that run this import script again.</p>';
121154
echo '<p>&nbsp;<br/><a class="button" href="'.admin_url().'tools.php?page=mathilda-tools-menu">Close</a></p>';
122155
return;
156+
123157
}
124158

125159
if ($number_of_files>0) {

mathilda_tools.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ function mathilda_tools_close() {
435435
*/
436436

437437
function mathilda_handbook() {
438+
439+
$filesize_max_threshold=get_option('mathilda_import_filesize_max');
440+
$filesize_max_string=$filesize_max_threshold;
441+
$filesize_max_string=$filesize_max_string/1024;
438442

439443
echo '<h1 class="mathilda_tools_headline">Mathilda Handbook</h1>';
440444
echo '<p class="mathilda_tools_description">Get it working!<br/>&nbsp;</p>';
@@ -454,7 +458,7 @@ function mathilda_handbook() {
454458

455459
echo '<h2>How to import your complete twitter history?</h2>
456460
1. Download your tweet archive from Twitter (Profile/Settings/Your Data).<br/>
457-
2. Split the file data/tweets.js into smaller files (<400 KB) with a local app.<br/>
461+
2. Split the file data/tweets.js into smaller files (<'.$filesize_max_string.' KB) with a local app.<br/>
458462
3. Upload all files to the folder wp-content/uploads/mathilda-import.</br>
459463
4. Run the import.</p>';
460464

mathilda_update.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ function mathilda_update () {
188188
update_option('mathilda_plugin_version', "13");
189189
}
190190

191+
/* Update Process Version 0.11 */
192+
if($mathilda_previous_version==13) {
193+
update_option('mathilda_plugin_version', "14");
194+
add_option('mathilda_import_filesize_max',"409600");
195+
}
196+
191197
}
192198
add_action( 'plugins_loaded', 'mathilda_update' );
193199

0 commit comments

Comments
 (0)