-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmathilda_utilities.php
More file actions
335 lines (261 loc) · 9.33 KB
/
mathilda_utilities.php
File metadata and controls
335 lines (261 loc) · 9.33 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?php
/*
Security
*/
if (!defined('ABSPATH')) { exit; }
/*
Mathilda Helper Functions
*/
/*
Mathilda YouTube Check
*/
// The function checks if an URL is linking to YouTube
// Input: URL
// Output: true or false
function mathilda_is_youtube($url) {
$mathilda_youtube_url_long="youtube";
$mathilda_youtube_url_short="youtu.be";
$mathilda_is_youtube_url;
if(stripos($url, $mathilda_youtube_url_long)!==false) {
$mathilda_is_youtube_url=TRUE;
}
elseif(stripos($url, $mathilda_youtube_url_short)!==false) {
$mathilda_is_youtube_url=TRUE;
}
else {
$mathilda_is_youtube_url=FALSE;
}
return $mathilda_is_youtube_url;
}
/*
Mathilda Permalink Check
*/
function mathilda_is_tweet_page() {
$is_mathilda_page=false;
$mathilda_slug=get_option('mathilda_slug');
if(! mathilda_is_pretty_permalink_enabled() ) {
$is_mathilda_slug_equal_page_title= strcasecmp ( $mathilda_slug , get_the_title() );
if( $is_mathilda_slug_equal_page_title == 0 ) { $is_mathilda_page=true; }
}
if ( is_page( get_option('mathilda_slug') ) ) { $is_mathilda_page=true; }
return $is_mathilda_page;
}
/*
Mathilda Permalink Check
*/
function mathilda_is_pretty_permalink_enabled() {
if ( get_option('permalink_structure') ) {
return true;
}
else {
return false;
}
}
/*
Mathilda Import Directory
* Function runs the path of the import directory
* Input: none
* Output: String
*/
function mathilda_get_import_directory() {
$upload_dir = wp_upload_dir();
$twitter_import_directory="mathilda-import";
$twitter_import_path = $upload_dir['basedir'].'/'.$twitter_import_directory;
return $twitter_import_path;
}
/*
Mathilda Image Directory
* Function returns the path of the image directory
* Input: none
* Output: String
*/
function mathilda_get_image_directory() {
$upload_dir = wp_upload_dir();
$mathilda_images_directory="mathilda-images";
$mathilda_images_path = $upload_dir['basedir'].'/'.$mathilda_images_directory .'/';
return $mathilda_images_path;
}
/*
Mathilda API Data Directory
* Function return the path of the API Data directory
* Input: none
* Output: String
*/
function mathilda_get_apidata_directory() {
$upload_dir = wp_upload_dir();
$mathilda_apidata_directory="mathilda-twitterapidata";
$mathilda_apidata_path = $upload_dir['basedir'].'/'.$mathilda_apidata_directory .'/';
return $mathilda_apidata_path;
}
/*
Mathilda Import Status
* Function returns the Import Status in Dezimal
* Input: none
* Output: Number
*/
function mathilda_get_import_status() {
$mathilda_import_running=get_option('mathilda_import_running');
if ($mathilda_import_running==1) {
$mathilda_import_numberoffiles=get_option('mathilda_import_numberoffiles');
$mathilda_import_open=get_option('mathilda_import_open');
$mathilda_import_done=$mathilda_import_numberoffiles-$mathilda_import_open;
$mathilda_import_status=(100/$mathilda_import_numberoffiles)*$mathilda_import_done;
$mathilda_import_status=round($mathilda_import_status);
return $mathilda_import_status;
}
else {
return 'na';
}
}
/*
Mathilda Import Done files
* Function returns the amount of done files
* Input: none
* Output: Number
*/
function mathilda_get_import_files_done() {
$mathilda_import_numberoffiles=get_option('mathilda_import_numberoffiles');
$mathilda_import_open=get_option('mathilda_import_open');
$mathilda_import_done=$mathilda_import_numberoffiles-$mathilda_import_open;
return $mathilda_import_done;
}
/*
Mathilda Healthy Check
* Function runs several consistency checks
* Input: none
* Output: Result as HTML Markup
*/
function mathilda_healthy_check() {
$upload_dir = wp_upload_dir();
$upload_dir_url=$upload_dir['basedir'];
$healthy_check_result=array(7);
$output='<p><strong>Checkpoints</strong></p>';
$output.='<p>';
// 1. Check
if (is_writable($upload_dir_url.'/mathilda-export')) {
$output.='Directory mathilda-export is writable.';
$healthy_check_result[0]=1;
} else {
$output.='<span class="mathilda-healtycheck-error"> Error: </span> Directory mathilda-export is not writable.';
$healthy_check_result[0]=0;
}
$output.='<br/>';
// 2. Check
if (is_writable($upload_dir_url.'/mathilda-images')) {
$output.='Directory mathilda-images is writable.';
$healthy_check_result[1]=1;
} else {
$output.='<span class="mathilda-healtycheck-error"> Error: </span> Directory mathilda-images is not writable.';
$healthy_check_result[1]=0;
}
$output.='<br/>';
// 3. Check
if (is_writable($upload_dir_url.'/mathilda-twitterapidata')) {
$output.='Directory mathilda-twitterapidata is writable.';
$healthy_check_result[2]=1;
} else {
$output.='<span class="mathilda-healtycheck-error"> Error: </span> Directory mathilda-twitterapidata is not writable.';
$healthy_check_result[2]=0;
}
$output.='<br/>';
// 4. Check
if (is_writable($upload_dir_url.'/mathilda-import')) {
$output.='Directory mathilda-import is writable.';
$healthy_check_result[3]=1;
} else {
$output.='<span class="mathilda-healtycheck-error"> Error: </span> Directory mathilda-import is not writable.';
$healthy_check_result[3]=0;
}
$output.='<br/>';
// 5. Check
if (mathilda_update_seven_aftercheck()==true) {
$output.='Data are consistent.';
$healthy_check_result[4]=1;
} else {
$output.='<span class="mathilda-healtycheck-error"> Error: </span> Data are inconsistent. Please reset Mathilda and reload the data again.';
$healthy_check_result[4]=0;
}
$output.='<br/>';
// 6. Check
if (ini_get('allow_url_fopen')) {
$output.='PHP option allow_url_fopen is set to TRUE.';
$healthy_check_result[5]=1;
} else {
$output.='<span class="mathilda-healtycheck-error"> Error: </span> PHP option allow_url_fopen is set to FALSE (0) on the webhosting environment. Please change to TRUE (1).';
$healthy_check_result[5]=0;
}
$output.='<br/>';
// 7. Check
if (mathilda_update_eight_aftercheck()==true) {
$output.='None tweets are truncated.';
$healthy_check_result[6]=1;
} else {
$output.='<span class="mathilda-healtycheck-warning"> Warning: </span> Some tweets are truncated. Please reset Mathilda and reload the data again.';
$healthy_check_result[6]=0;
}
$output.='</p>';
$output.='<p><strong>Additional Information</strong></p>';
$output.='<p>';
// 1. Info
$this_environment_php_execution_time=ini_get('max_execution_time');
if($this_environment_php_execution_time==0) {
$this_environment_php_execution_time='Not limited';
}
else {
$this_environment_php_execution_time=$this_environment_php_execution_time .' seconds';
}
$output.='Max PHP script execution time: '.$this_environment_php_execution_time.'.';
$output.='<br/>';
// 2. Info
$initial_load_done=get_option('mathilda_initial_load');
if($initial_load_done==0) {
$output.='Initial Load is pending.';
} else {
$output.='Initial Load was executed.';
}
$output.='<br/>';
// 3. Info
$import_done=get_option('mathilda_import');
$import_running=get_option('mathilda_import_running');
if($import_done==0) {
$output.='Import was not executed.';
} elseif ($import_running==1) {
$output.='Import is running.';
}
else {
$output.='Import was executed.';
}
$output.='<br/>';
// 4. Info
$cron_status=get_option('mathilda_cron_status');
if($cron_status==0) {
$output.='Auto Load is deactive.';
}
else {
$output.='Auto Load is active.';
}
$output.='<br/>';
// 5. Info
$tweets_loaded=mathilda_tweets_count();
if($tweets_loaded==0) {
$output.='No Tweets are loaded.';
} else {
$output.='Tweets are loaded.';
}
$output.='</p>';
$output.='<p><strong>Result</strong></p>';
$output.='<p>';
// Result
$result = array_search(0, $healthy_check_result);
if($result) {
$output.='Mathilda is not doing well! :-(<br/>Please investigate the issues above.';
} else {
$output.='Mathilda is doing well! :-)';
}
$output.='</p>';
// Helpful Links
$output.='<p><strong>Helpful Resources</strong></p>';
$output.=mathilda_helpful_resources();
return $output;
}
?>