Skip to content

Commit 22734e8

Browse files
authored
Merge pull request #11 from circuscode/develop
Preparation Release 0.11
2 parents 1594bd4 + cf834f5 commit 22734e8

File tree

8 files changed

+137
-68
lines changed

8 files changed

+137
-68
lines changed

mathilda.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/*
44
Plugin Name: Mathilda
55
Plugin URI: https://www.unmus.de/wordpress-plugin-mathilda/
6-
Description: Mathilda copies your tweets from Twitter continuously, stores them in the WordPress database and displays them in the blog.
7-
Version: 0.10
6+
Description: Mathilda copies your tweets from Twitter to WordPress.
7+
Version: 0.11
88
Author: Marco Hitschler
99
Author URI: https://www.unmus.de/
1010
License: GPL3
@@ -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: 66 additions & 45 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. <a href="https://www.unmus.de/wp-content/uploads/Mathilda-JSON-File-Split-EN.pdf" target="_blank">Split the file</a> 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>';
121142
echo '<p>&nbsp;<br/><a class="button" href="'.admin_url().'tools.php?page=mathilda-tools-menu">Close</a></p>';
122143
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>';
154+
echo '<p>&nbsp;<br/><a class="button" href="'.admin_url().'tools.php?page=mathilda-tools-menu">Close</a></p>';
155+
return;
156+
123157
}
124158

125159
if ($number_of_files>0) {
@@ -327,15 +361,15 @@ function mathilda_import_file( $file ) {
327361
$hashtag_index_e=false;
328362
$hashtags_yes_or_no="FALSE";
329363

330-
if(array_key_exists('0', $items['entities']['hashtags']))
364+
if(array_key_exists('0', $items['tweet']['entities']['hashtags']))
331365
{
332-
foreach($items['entities']['hashtags'] as $hashtags)
366+
foreach($items['tweet']['entities']['hashtags'] as $hashtags)
333367
{
334368
$hashtag_text=$hashtags['text'];
335369
$hashtag_index_s=$hashtags['indices'][0];
336370
$hashtag_index_e=$hashtags['indices'][1];
337371
$hashtags_yes_or_no="TRUE";
338-
$hashtag_cache[]=array($hashtag_text,$hashtag_index_s,$hashtag_index_e,$items['id_str']);
372+
$hashtag_cache[]=array($hashtag_text,$hashtag_index_s,$hashtag_index_e,$items['tweet']['id_str']);
339373
$num_hashtags=$num_hashtags+1;
340374
}
341375
}
@@ -349,17 +383,17 @@ function mathilda_import_file( $file ) {
349383
$mention_index_end=false;
350384
$mentions_yes_or_no="FALSE";
351385

352-
if(array_key_exists('0', $items['entities']['user_mentions']))
386+
if(array_key_exists('0', $items['tweet']['entities']['user_mentions']))
353387
{
354-
foreach($items['entities']['user_mentions'] as $mentions)
388+
foreach($items['tweet']['entities']['user_mentions'] as $mentions)
355389
{
356390
$mention_useridstr=$mentions['id_str'];
357391
$mention_screenname=$mentions['screen_name'];
358392
$mention_fullname=$mentions['name'];
359393
$mention_index_start=$mentions['indices'][0];
360394
$mention_index_end=$mentions['indices'][1];
361395
$mentions_yes_or_no="TRUE";
362-
$mention_cache[]=array($mention_useridstr,$mention_screenname,$mention_fullname,$mention_index_start,$mention_index_end,$items['id_str']);
396+
$mention_cache[]=array($mention_useridstr,$mention_screenname,$mention_fullname,$mention_index_start,$mention_index_end,$items['tweet']['id_str']);
363397
$num_mentions=$num_mentions+1;
364398
}
365399
}
@@ -373,17 +407,17 @@ function mathilda_import_file( $file ) {
373407
$url_index_end=false;
374408
$urls_yes_or_no="FALSE";
375409

376-
if(array_key_exists('0', $items['entities']['urls']))
410+
if(array_key_exists('0', $items['tweet']['entities']['urls']))
377411
{
378-
foreach($items['entities']['urls'] as $urls)
412+
foreach($items['tweet']['entities']['urls'] as $urls)
379413
{
380414
$url_tco=$urls['url'];
381415
$url_extended=$urls['expanded_url'];
382416
$url_display=$urls['display_url'];
383417
$url_index_start=$urls['indices'][0];
384418
$url_index_end=$urls['indices'][1];
385419
$urls_yes_or_no="TRUE";
386-
$url_cache[]=array($url_tco,$url_extended,$url_display,$url_index_start,$url_index_end,$items['id_str']);
420+
$url_cache[]=array($url_tco,$url_extended,$url_display,$url_index_start,$url_index_end,$items['tweet']['id_str']);
387421
$num_urls=$num_urls+1;
388422
}
389423
}
@@ -404,9 +438,9 @@ function mathilda_import_file( $file ) {
404438
$index_end=false;
405439
$media_yes_or_no="FALSE";
406440

407-
if(isset($items['entities']['media']))
441+
if(isset($items['tweet']['entities']['media']))
408442
{
409-
foreach($items['entities']['media'] as $images)
443+
foreach($items['tweet']['entities']['media'] as $images)
410444
{
411445

412446
$media_idstr=$images['id_str'];
@@ -416,23 +450,9 @@ function mathilda_import_file( $file ) {
416450
$media_displayurl=$images['display_url'];
417451
$media_extendedurl=$images['expanded_url'];
418452

419-
/*
420-
Twitter Export JSON does not contain the size-array (small, medium, large, xxx)
421-
Search Largest Value Pair
422-
*/
423-
424-
$select_size=0;
425-
for ($x=0; $x<4; $x++)
426-
{
427-
if($images['sizes'][$select_size]['w']<$images['sizes'][($x+1)]['w'])
428-
{
429-
$select_size=($x+1);
430-
}
431-
}
432-
433-
$media_size_w=$images['sizes'][$select_size]['w'];
434-
$media_size_h=$images['sizes'][$select_size]['h'];
435-
$media_size_resize=$images['sizes'][$select_size]['resize'];
453+
$media_size_w=$images['sizes']['large']['w'];
454+
$media_size_h=$images['sizes']['large']['h'];
455+
$media_size_resize=$images['sizes']['large']['resize'];
436456
$media_type='photo';
437457
$index_start=$images['indices'][0];
438458
$index_end=$images['indices'][1];
@@ -457,7 +477,7 @@ function mathilda_import_file( $file ) {
457477

458478
// Update Media Array
459479

460-
$media_cache[]=array($media_idstr,$media_mediaurl,$media_mediaurlhttps,$media_url,$media_displayurl,$media_extendedurl, $media_size_w, $media_size_h, $media_size_resize,$media_type, $index_start, $index_end,$items['id_str'],$filename,$loaded);
480+
$media_cache[]=array($media_idstr,$media_mediaurl,$media_mediaurlhttps,$media_url,$media_displayurl,$media_extendedurl, $media_size_w, $media_size_h, $media_size_resize,$media_type, $index_start, $index_end,$items['tweet']['id_str'],$filename,$loaded);
461481
$media_yes_or_no="TRUE";
462482
$num_media=$num_media+1;
463483
}
@@ -470,16 +490,19 @@ function mathilda_import_file( $file ) {
470490
$tweet_retweet="FALSE";
471491
$tweet_quote="FALSE";
472492

473-
if(isset($items['retweeted_status'])) {
474-
$tweet_retweet="TRUE";
493+
// Identify Retweets
494+
$is_retweet = strpos($items['tweet']['full_text'], 'RT ');
495+
if($is_retweet===0) {
496+
$tweet_retweet="TRUE";
475497
}
476-
if(isset($items['truncated'])) {
477-
if($items['truncated']=='true') {
498+
499+
if(isset($items['tweet']['truncated'])) {
500+
if($items['tweet']['truncated']=='true') {
478501
$tweet_truncate="TRUE";
479502
}
480503
}
481-
if(isset($items['in_reply_to_status_id'])) {
482-
if($items['in_reply_to_status_id']!=null) {
504+
if(isset($items['tweet']['in_reply_to_user_id'])) {
505+
if($items['tweet']['in_reply_to_user_id']!=null) {
483506
$tweet_reply="TRUE";
484507
}
485508
}
@@ -490,9 +513,9 @@ function mathilda_import_file( $file ) {
490513
}
491514

492515
$tweet_cache[]=array($num_tweets,
493-
$items['id_str'],
494-
$items['text'],
495-
$items['created_at'],
516+
$items['tweet']['id_str'],
517+
$items['tweet']['full_text'],
518+
$items['tweet']['created_at'],
496519
$hashtags_yes_or_no,
497520
$mentions_yes_or_no,
498521
$media_yes_or_no,
@@ -518,10 +541,8 @@ function mathilda_import_file( $file ) {
518541

519542
// Convert Date
520543

521-
$tweet_cache[$i][3]=str_replace ( '-' , '' , $tweet_cache[$i][3] );
522-
$tweet_cache[$i][3]=str_replace ( ' ' , '' , $tweet_cache[$i][3] );
523-
$tweet_cache[$i][3]=str_replace ( ':' , '' , $tweet_cache[$i][3] );
524-
$tweet_cache[$i][3]=str_replace ( '+0000' , '' , $tweet_cache[$i][3] );
544+
$tweet_date=strtotime($tweet_cache[$i][3]);
545+
$tweet_cache[$i][3]=date('YmdHis', $tweet_date);
525546

526547
// Update Tweets
527548

mathilda_painting.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@ function mathilda_tweet_paint($date,$tweet,$id,$me,$image,$mention,$url,$hashtag
466466
$num_hashtags=count($tweet_hashtags);
467467
for($i=0; $i<$num_hashtags; $i++)
468468
{
469-
$hashtag_html='<a href="https://twitter.com/search?q=%23'.$tweet_hashtags[$i][1].'" class="mathilda-hashtag" rel="nofollow" target="_blank">#'.$tweet_hashtags[$i][1].'</a>';
470-
$hashtag_search='#'.$tweet_hashtags[$i][1];
471-
$tweet=str_replace ( $hashtag_search, $hashtag_html , $tweet ) ;
469+
$hashtag_html='<a href="https://twitter.com/search?q=%23'.$tweet_hashtags[$i][1].'" class="mathilda-hashtag" rel="nofollow" target="_blank">#'.$tweet_hashtags[$i][1].'</a> ';
470+
$hashtag_search='#'.$tweet_hashtags[$i][1].' ';
471+
$tweet=str_replace ( $hashtag_search, $hashtag_html , $tweet ) ;
472472
}
473473

474474
}
@@ -601,7 +601,17 @@ function mathilda_tweet_paint($date,$tweet,$id,$me,$image,$mention,$url,$hashtag
601601
$upload_dir = wp_upload_dir();
602602
$mathilda_images_dirname="mathilda-images";
603603
$mathilda_images_dirwithpath = $upload_dir['baseurl'].'/'.$mathilda_images_dirname .'/';
604-
$mathilda_content.='<img src="'.$mathilda_images_dirwithpath.$mathilda_tweet_image.'" alt="Tweet Image" class="mathilda-tweet-image"/>';
604+
$mathilda_content.='<img src="'.$mathilda_images_dirwithpath.$mathilda_tweet_image.'" alt="Tweet Image" class="mathilda-tweet-image"/>';
605+
606+
// Identify Video Tweet
607+
$video_extendedurl=$tweet_image[6];
608+
$is_video_url = strpos($video_extendedurl, 'video');
609+
if($is_video_url!==false) {
610+
$mathilda_content.='<div class="mathilda-tweet-video-link">';
611+
$mathilda_content.='Video: <a href="'.$tweet_image[6].'">'.$tweet_image[6].'</a>';
612+
$mathilda_content.="</div>";
613+
$mathilda_content.="&nbsp;<br/>";
614+
}
605615

606616
// Line Break for Tweet Galerys
607617
if($number_of_images>1) {

mathilda_tools.php

Lines changed: 8 additions & 3 deletions
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,8 +458,9 @@ 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. Upload all files from the folder data/js/tweets to the folder wp-content/uploads/mathilda-import.</br>
458-
3. Run the import.</p>';
461+
2. <a href="https://www.unmus.de/wp-content/uploads/Mathilda-JSON-File-Split-EN.pdf" target="_blank">Split the file</a> data/tweets.js into smaller files (<'.$filesize_max_string.' KB) with a local app.<br/>
462+
3. Upload all files to the folder wp-content/uploads/mathilda-import.</br>
463+
4. Run the import.</p>';
459464

460465
echo '<h2>Helpful Resources</h2>';
461466
echo mathilda_helpful_resources();
@@ -472,7 +477,7 @@ function mathilda_helpful_resources() {
472477

473478
$output='<p>';
474479
$output.='<a href="https://wordpress.org/plugins/mathilda/faq/" target="_blank">Mathilda FAQ</a><br/>';
475-
$output.='<a href="https://wordpress.org/support/plugin/mathilda" target="_blank">Mathilda Support Forum</a><br/>';
480+
$output.='<a href="https://wordpress.org/support/plugin/mathilda" target="_blank">Mathilda Support</a><br/>';
476481
$output.='<a href="https://github.com/circuscode/mathilda" target="_blank">Mathilda @ GitHub</a><br/>';
477482
$output.='<a href="https://www.unmus.de/mathilda/" target="_blank">Official Plugin Page</a>';
478483
$output.='</p>';

mathilda_tweets.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
.mathilda-tweet-image
2222
{padding-left:50px;}
2323

24+
.mathilda-tweet-video-link
25+
{position:relative;top:7px;padding-left:50px;}
26+
2427
.mathilda-url-follows
2528
{margin-bottom:0px;}
2629

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)