forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
2258 lines (1923 loc) · 62 KB
/
functions.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
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Define the common functions that can be accessed from anywhere.
*/
use enshrined\svgSanitize\Sanitizer;
function try_queries($queries = [])
{
global $dbh;
$total = count($queries);
$success = 0;
$failed = 0;
foreach ($queries as $i => $value) {
try {
$statement = $dbh->prepare($queries[$i]['query']);
if (!empty($queries[$i]['params'])) {
foreach ($queries[$i]['params'] as $name => $value) {
$statement->bindValue($name, $value);
}
}
$statement->execute($queries[$i]['params']);
$success++;
} catch (Exception $e) {
$failed++;
}
}
return $failed == 0;
}
function get_server_requirements_errors()
{
$errors_found = [];
// Check for PDO extensions
$pdo_available_drivers = PDO::getAvailableDrivers();
if (empty($pdo_available_drivers)) {
$errors_found[] = sprintf(__('Missing required extension: %s', 'cftp_admin'), 'pdo');
} else {
if ((DB_DRIVER == 'mysql') && !defined('PDO::MYSQL_ATTR_INIT_COMMAND')) {
$errors_found[] = sprintf(__('Missing required extension: %s', 'cftp_admin'), 'pdo');
}
if ((DB_DRIVER == 'mssql') && !in_array('dblib', $pdo_available_drivers)) {
$errors_found[] = sprintf(__('Missing required extension: %s', 'cftp_admin'), 'pdo');
}
}
// Version requirements
$version_not_met = __('%s minimum version not met. Please upgrade to at least version %s', 'cftp_admin');
// php
if (version_compare(phpversion(), REQUIRED_VERSION_PHP, "<")) {
$errors_found[] = sprintf($version_not_met, 'php', REQUIRED_VERSION_PHP);
}
// mysql
global $dbh;
if (!empty($dbh)) {
$version_mysql = $dbh->query('SELECT version()')->fetchColumn();
if (version_compare($version_mysql, REQUIRED_VERSION_MYSQL, "<")) {
$errors_found[] = sprintf($version_not_met, 'MySQL', REQUIRED_VERSION_MYSQL);
}
}
return $errors_found;
}
function check_server_requirements()
{
$errors = get_server_requirements_errors();
if (!empty($errors)) {
ps_redirect(PAGE_STATUS_CODE_REQUIREMENTS);
}
}
/**
* Check if ProjectSend is installed by trying to find the main users table.
* If it is missing, the installation is invalid.
*/
function is_projectsend_installed()
{
$tables_need = array(
TABLE_USERS
);
$tables_missing = 0;
/**
* This table list is defined on app.php
*/
foreach ($tables_need as $table) {
if (!table_exists($table)) {
$tables_missing++;
}
}
if ($tables_missing > 0) {
return false;
} else {
return true;
}
}
function is_unique_username($string)
{
global $dbh;
$statement = $dbh->prepare("SELECT * FROM " . TABLE_USERS . " WHERE user = :user");
$statement->execute(array(':user' => $string));
if ($statement->rowCount() > 0) {
return false;
}
return true;
}
/** Prevents an infinite loop */
function force_logout()
{
$auth = new \ProjectSend\Classes\Auth();
$auth->logout();
ps_redirect(BASE_URI);
}
/**
* Check if curl is enabled
*/
function curl_is_enabled()
{
return function_exists('curl_version');
}
/** Gets a Json file from and url and caches the result */
function get_json($url, $cache_time)
{
$cache_dir = JSON_CACHE_DIR;
$cacheFile = $cache_dir . DS . md5($url);
if (file_exists($cacheFile)) {
$fh = fopen($cacheFile, 'r');
$cacheTime = trim(fgets($fh));
// if data was cached recently, return cached data
if ($cacheTime > strtotime($cache_time)) {
return fread($fh, filesize($cacheFile));
}
// else delete cache file
fclose($fh);
unlink($cacheFile);
}
if (curl_is_enabled()) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, CURL_TIMEOUT_SECONDS);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, CURL_TIMEOUT_SECONDS);
$json = curl_exec($ch);
curl_close($ch);
$fh = fopen($cacheFile, 'w');
fwrite($fh, time() . "\n");
fwrite($fh, $json);
fclose($fh);
} else {
$json = file_get_contents($url);
}
return $json;
}
/**
* To successfully add the orderby and order parameters to a query,
* check if the column exists on the table and validate that order
* is either ASC or DESC.
* Defaults to ORDER BY: id, ORDER: DESC
*/
function sql_add_order($table, $column = 'id', $initial_order = 'ASC')
{
global $dbh;
$allowed_custom_sort_columns = array('download_count');
$columns_query = $dbh->query('SELECT * FROM ' . $table . ' LIMIT 1');
if ($columns_query->rowCount() > 0) {
$columns_keys = array_keys($columns_query->fetch(PDO::FETCH_ASSOC));
$columns_keys = array_merge($columns_keys, $allowed_custom_sort_columns);
$orderby = (isset($_GET['orderby']) && in_array($_GET['orderby'], $columns_keys)) ? $_GET['orderby'] : $column;
$order = (isset($_GET['order'])) ? strtoupper($_GET['order']) : $initial_order;
$order = (preg_match("/^(DESC|ASC)$/", $order)) ? $order : $initial_order;
return " ORDER BY $orderby $order";
} else {
return false;
}
}
function generate_password($length = 12)
{
$error_unexpected = __('An unexpected error has occurred', 'cftp_admin');
$error_os_fail = __('Could not generate a random password', 'cftp_admin');
try {
$password = random_bytes($length);
} catch (TypeError $e) {
die($error_unexpected);
} catch (Error $e) {
die($error_unexpected);
} catch (Exception $e) {
die($error_os_fail);
}
return bin2hex($password);
}
/**
* Reads the lang folder and scans for .mo files.
* Returns an array of available languages.
*/
function get_available_languages()
{
/** Load the language and locales names list */
require ROOT_DIR . '/includes/language.locales.names.php';
$langs = [];
$mo_files = glob(ROOT_DIR . '/lang/*.mo');
foreach ($mo_files as $file) {
$lang_file = pathinfo($file, PATHINFO_FILENAME);
$extension = pathinfo($file, PATHINFO_EXTENSION);
if (array_key_exists($lang_file, $locales_names)) {
$lang_name = $locales_names[$lang_file];
} else {
$lang_name = $lang_file;
}
$langs[$lang_file] = $lang_name;
}
/** Sort alphabetically */
asort($langs, SORT_STRING);
return $langs;
}
/**
* Get the total count of downloads grouped by file
* Data returned:
* - Count anonymous downloads (Public downloads)
* - Unique logged in clients downloads
* - Total count
*/
function get_downloads_information($id = null)
{
global $dbh;
$data = [];
$sql = "SELECT file_id, COUNT(*) as downloads, SUM( ISNULL(user_id) ) AS anonymous_users, COUNT(DISTINCT user_id) as unique_clients FROM " . TABLE_DOWNLOADS;
if (!empty($id)) {
$sql .= ' WHERE file_id = :id';
}
$sql .= " GROUP BY file_id";
$statement = $dbh->prepare($sql);
if (!empty($id)) {
$statement->bindValue(':id', $id, PDO::PARAM_INT);
}
$statement->execute();
$statement->setFetchMode(PDO::FETCH_ASSOC);
if (!empty($id)) {
$data[$id] = array(
'file_id' => $id,
'total' => 0,
'unique_clients' => 0,
'anonymous_users' => 0,
);
}
while ($row = $statement->fetch()) {
$data[$row['file_id']] = array(
'file_id' => html_output($row['file_id']),
'total' => html_output($row['downloads']),
'unique_clients' => html_output($row['unique_clients']),
'anonymous_users' => html_output($row['anonymous_users']),
);
}
return $data;
}
/**
* Check if a table exists in the current database.
*
* @param string $table Table to search for.
* @return bool TRUE if table exists, FALSE if no table found.
* by esbite on http://stackoverflow.com/questions/1717495/check-if-a-database-table-exists-using-php-pdo
*/
function table_exists($table)
{
global $dbh;
$result = false;
if (!empty($dbh)) {
try {
$statement = $dbh->prepare("SELECT 1 FROM $table LIMIT 1");
$result = $statement->execute();
} catch (Exception $e) {
return false;
}
}
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
return $result !== false;
}
/**
* Check if a file id exists on the database.
* Used on the download information page.
*
* @return bool
*/
function download_information_exists($id)
{
global $dbh;
$statement = $dbh->prepare("SELECT id FROM " . TABLE_DOWNLOADS . " WHERE file_id = :id");
$statement->bindParam(':id', $id, PDO::PARAM_INT);
$statement->execute();
if ($statement->rowCount() > 0) {
return true;
} else {
return false;
}
}
/**
* Check if a client id exists on the database.
* Used on the Edit client page.
*
* @return bool
*/
function client_exists_id($id)
{
global $dbh;
$statement = $dbh->prepare("SELECT * FROM " . TABLE_USERS . " WHERE id=:id");
$statement->bindParam(':id', $id, PDO::PARAM_INT);
$statement->execute();
if ($statement->rowCount() > 0) {
return true;
} else {
return false;
}
}
/**
* Check if a user id exists on the database.
* Used on the Edit user page.
*
* @return bool
*/
function user_exists_id($id)
{
global $dbh;
$statement = $dbh->prepare("SELECT * FROM " . TABLE_USERS . " WHERE id=:id");
$statement->bindParam(':id', $id, PDO::PARAM_INT);
$statement->execute();
if ($statement->rowCount() > 0) {
return true;
} else {
return false;
}
}
/**
* Get all the client information knowing only the id
* Used on the Manage files page.
*
* @return array
*/
function get_client_by_id($client)
{
global $dbh;
$statement = $dbh->prepare("SELECT * FROM " . TABLE_USERS . " WHERE id=:id");
$statement->bindParam(':id', $client, PDO::PARAM_INT);
$statement->execute();
$statement->setFetchMode(PDO::FETCH_ASSOC);
if ($statement->rowCount() > 0) {
while ($row = $statement->fetch()) {
$information = array(
'id' => html_output($row['id']),
'username' => html_output($row['user']),
'name' => html_output($row['name']),
'address' => html_output($row['address']),
'phone' => html_output($row['phone']),
'email' => html_output($row['email']),
'notify_upload' => html_output($row['notify']),
'level' => html_output($row['level']),
'active' => html_output($row['active']),
'max_file_size' => html_output($row['max_file_size']),
'can_upload_public' => html_output($row['can_upload_public']),
'contact' => html_output($row['contact']),
'created_date' => html_output($row['timestamp']),
'created_by' => html_output($row['created_by'])
);
if (!empty($information)) {
return $information;
} else {
return false;
}
}
} else {
return false;
}
}
function username_exists($username)
{
global $dbh;
$statement = $dbh->prepare("SELECT * FROM " . TABLE_USERS . " WHERE user = :user");
$statement->execute([
':user' => $username,
]);
if ($statement->rowCount() > 0) {
return true;
}
return false;
}
function generate_random_password()
{
return bin2hex(openssl_random_pseudo_bytes(5));
}
function generate_username($from)
{
$cut = substr($from, 0, MAX_USER_CHARS);
if (!username_exists($cut)) {
return $cut;
}
$rand = substr(uniqid(), 0, MAX_USER_CHARS);
return $rand;
}
/**
* Get all the client information knowing only the log in username
*
* @return array
*/
function get_client_by_username($client)
{
global $dbh;
$statement = $dbh->prepare("SELECT id FROM " . TABLE_USERS . " WHERE user=:username");
$statement->bindParam(':username', $client);
$statement->execute();
$statement->setFetchMode(PDO::FETCH_ASSOC);
while ($row = $statement->fetch()) {
$found_id = html_output($row['id']);
if (!empty($found_id)) {
$information = get_client_by_id($found_id);
return $information;
} else {
return false;
}
}
}
/**
* Get a user using any of the accepted field names
*
* @uses get_user_by_id
* @return array
*/
function get_user_by($user_type, $field, $value)
{
global $dbh;
$field = (string)$field;
$field = trim(strip_Tags(htmlentities(strtolower($field))));
$acceptable_fields = [
'username',
'name',
'email',
];
if (in_array($field, $acceptable_fields)) {
$statement = $dbh->prepare("SELECT id FROM " . TABLE_USERS . " WHERE `$field`=:value");
$statement->bindParam(':value', $value);
$statement->execute();
$result = $statement->fetchColumn();
if ($result) {
switch ($user_type) {
case 'user':
$user_data = get_user_by_id($result);
break;
case 'client':
$user_data = get_client_by_id($result);
}
return $user_data;
} else {
return false;
}
} else {
return false;
}
}
/**
* Get all the user information knowing only the id
*
* @return array
*/
function get_user_by_id($id)
{
global $dbh;
$statement = $dbh->prepare("SELECT * FROM " . TABLE_USERS . " WHERE id=:id");
$statement->bindParam(':id', $id, PDO::PARAM_INT);
$statement->execute();
$statement->setFetchMode(PDO::FETCH_ASSOC);
while ($row = $statement->fetch()) {
$information = array(
'id' => html_output($row['id']),
'username' => html_output($row['user']),
'name' => html_output($row['name']),
'email' => html_output($row['email']),
'level' => html_output($row['level']),
'active' => html_output($row['active']),
'max_file_size' => html_output($row['max_file_size']),
'created_date' => html_output($row['timestamp']),
);
if (!empty($information)) {
return $information;
} else {
return false;
}
}
}
/**
* Get all the user information knowing only the log in username
*
* @return array
* @uses get_user_by_id
*/
function get_user_by_username($user)
{
global $dbh;
$statement = $dbh->prepare("SELECT * FROM " . TABLE_USERS . " WHERE user=:user");
$statement->execute(
array(
':user' => $user
)
);
$statement->setFetchMode(PDO::FETCH_ASSOC);
if ($statement->rowCount() > 0) {
while ($row = $statement->fetch()) {
$found_id = html_output($row['id']);
if (!empty($found_id)) {
$information = get_user_by_id($found_id);
return $information;
} else {
return false;
}
}
} else {
return false;
}
}
function current_user_can($permission, $params = [])
{
global $permissions;
return $permissions->can($permission);
}
function client_can_upload_public($client_id)
{
switch (get_option('clients_can_set_public')) {
case 'all':
return true;
break;
case 'allowed':
$client = get_client_by_id($client_id);
return (bool)$client['can_upload_public'];
break;
}
return false;
}
function client_can_assign_to_public_folder($client_id)
{
if (!client_can_upload_public($client_id)) {
return false;
}
if (get_option('clients_can_upload_to_public_folders') == '1') {
return true;
}
return false;
}
function current_user_can_upload()
{
switch (CURRENT_USER_LEVEL) {
case 9:
case 8:
case 7:
return true;
break;
case 0:
return (get_option('clients_can_upload') == '1');
break;
default:
break;
}
return false;
}
function current_user_can_upload_public()
{
switch (CURRENT_USER_LEVEL) {
case 9:
case 8:
case 7:
return true;
break;
case 0:
return client_can_upload_public(CURRENT_USER_ID);
break;
default:
break;
}
return false;
}
/**
* Get all the file information knowing only the id
* Used on the Download information page.
*
* @return array
*/
function get_file_by_id($id)
{
global $dbh;
$statement = $dbh->prepare("SELECT * FROM " . TABLE_FILES . " WHERE id=:id");
$statement->bindParam(':id', $id, PDO::PARAM_INT);
$statement->execute();
$statement->setFetchMode(PDO::FETCH_ASSOC);
while ($row = $statement->fetch()) {
$information = array(
'id' => html_output($row['id']),
'user_id' => html_output($row['user_id']),
'title' => html_output($row['filename']),
'original_url' => html_output($row['original_url']),
'url' => html_output($row['url']),
'description' => html_output($row['description']),
'uploaded_date' => html_output($row['timestamp']),
'uploaded_by' => html_output($row['uploader']),
'expires' => html_output($row['expires']),
'expiry_date' => html_output($row['expiry_date']),
'public' => html_output($row['public_allow']),
'public_token' => html_output($row['public_token']),
);
if (!empty($information)) {
return $information;
} else {
return false;
}
}
}
/**
* Get all the file information knowing only the id
* Used on the Download information page.
*
* @return array
*/
function get_file_by_filename($filename)
{
global $dbh;
$statement = $dbh->prepare("SELECT * FROM " . TABLE_FILES . " WHERE url=:filename");
$statement->execute(
array(
':filename' => $filename
)
);
if ($statement->rowCount() > 0) {
while ($row = $statement->fetch()) {
$found_id = $row['id'];
if (!empty($found_id)) {
$information = get_file_by_id($found_id);
return $information;
} else {
return false;
}
}
}
return false;
}
function get_file_assignations($file_id)
{
if (empty($file_id)) {
return false;
}
if (!is_numeric($file_id)) {
return false;
}
global $dbh;
$statement = $dbh->prepare("SELECT * FROM " . TABLE_FILES_RELATIONS . " WHERE file_id = :file_id");
$statement->bindParam(':file_id', $file_id, PDO::PARAM_INT);
$statement->execute();
$statement->setFetchMode(PDO::FETCH_ASSOC);
$count = $statement->rowCount();
$return = [
'clients' => [],
'groups' => [],
];
if ($count > 0) {
while ($row = $statement->fetch()) {
if (!empty($row['client_id'])) {
$return['clients'][$row['client_id']] = [
'hidden' => $row['hidden'],
];
}
if (!empty($row['group_id'])) {
$return['groups'][$row['group_id']] = [
'hidden' => $row['hidden'],
];
}
}
return $return;
}
return false;
}
/**
* Standard footer mark up and information generated on this function to
* prevent code repetition.
* Used on the default template, log in page, install page and the back-end
* footer file.
*/
function render_footer_text()
{
?>
<footer>
<div id="footer">
<?php
if (is_projectsend_installed() && get_option('footer_custom_enable') == '1') {
echo strip_tags(get_option('footer_custom_content'), '<br><span><a><strong><em><b><i><u><s>');
} else {
// $link = '<a href="'.SYSTEM_URI.'" target="_blank">'.SYSTEM_NAME.'</a>';
// echo sprintf(__('Provided by %s', 'cftp_admin'), $link);
_e('Provided by', 'cftp_admin'); ?> <a href="<?php echo SYSTEM_URI; ?>" target="_blank"><?php echo SYSTEM_NAME; ?></a> <?php if (user_is_logged_in() == true) {
_e('version', 'cftp_admin');
echo ' ' . CURRENT_VERSION;
} ?> - <?php _e('Free software', 'cftp_admin');
}
?>
</div>
</footer>
<?php
}
/**
* function render_json_variables
*
* Adds a CDATA block with variables that are used on the main JS file
* URLs. text strings, etc.
*/
function render_json_variables()
{
global $json_strings;
$output = json_encode($json_strings);
?>
<script type="text/javascript">
/*<![CDATA[*/
var json_strings = <?php echo $output; ?>;
/*]]>*/
</script>
<?php
}
/**
* Standard "There are no clients" message mark up and information
* generated on this function to prevent code repetition.
*
* Used on the upload pages and the clients list.
*/
function message_no_clients()
{
global $dbh;
// Count the clients to show a warning message or the form
$statement = $dbh->query("SELECT id FROM " . TABLE_USERS . " WHERE level = '0'");
$count_clients = $statement->rowCount();
$statement = $dbh->query("SELECT id FROM " . TABLE_GROUPS);
$count_groups = $statement->rowCount();
if ((!$count_clients or $count_clients < 1) && (!$count_groups or $count_groups < 1)) {
global $flash;
$msg = '<strong>' . __('Important:', 'cftp_admin') . '</strong> ' . __('There are no clients or groups at the moment. You can still upload files and assign them later.', 'cftp_admin');
$flash->warning($msg);
}
}
/**
* Generate a system text message.
*
* Current CSS available message classes:
* - message_ok
* - message_error
* - message_info
*
*/
/**
* Generate a system text message using Bootstrap's alert box.
*/
function system_message($type, $message, $div_id = '')
{
if (empty($type)) {
$type = 'success';
}
switch ($type) {
case 'success':
break;
case 'danger':
break;
case 'info':
break;
case 'warning':
break;
}
$return = '<div class="alert alert-' . $type . '"';
if (isset($div_id) && $div_id != '') {
$return .= ' id="' . $div_id . '"';
}
$return .= '>';
if (isset($close) && $close == true) {
$return .= '<a href="#" class="close" data-dismiss="alert">×</a>';
}
$return .= $message;
$return .= '</div>';
return $return;
}
/**
* Function used across the system to determine if the current logged in
* account has permission to do something.
*
*/
function current_role_in($levels)
{
if (!is_array($levels)) {
$levels = array($levels);
}
if (isset($_SESSION['role']) && (in_array($_SESSION['role'], $levels))) {
return true;
} else {
return false;
}
}
/**
* Returns the current logged in account level either from the active
* session or the cookies.
*
* @todo Validate the returned value against the one stored on the database
*/
function get_current_user_level()
{
$level = 0;
if (isset($_SESSION['role'])) {
$level = $_SESSION['role'];
}
return $level;
}
/**
* Wrap print_r with pre tags
*/
function print_array($array)
{
echo '<pre>';
print_r($array);
echo '</pre>';
}
/**
* Alias for previous function
*/
function pa($array)
{
print_array($array);
}
/**
* Prints array and ends execution
*/
function pax($array)
{
print_array($array);
exit;
}
function va($array)
{
echo '<pre>';
var_dump($array);
echo '</pre>';
}
function vax($array)
{
va($array);
exit;
}
/**
* Wrapper for htmlentities with default options
*
*/
function html_output($str, $flags = ENT_QUOTES, $encoding = CHARSET, $double_encode = false)
{
if ($str == null) { return; }
return htmlentities($str, $flags, $encoding, $double_encode);
}
/**
* Allow some html tags for file and group descriptions on htmlentities
*
*/
function htmlentities_allowed($str, $quoteStyle = ENT_COMPAT, $charset = CHARSET, $doubleEncode = false)
{
//$description = htmlspecialchars($str, $quoteStyle, $charset, $doubleEncode);
$string = htmlspecialchars_decode($str, $quoteStyle);
return strip_tags($string, '<i><b><strong><em><p><br><ul><ol><li><u><sup><sub><s>');
/*
$allowed_tags = array('i','b','strong','em','p','br','ul','ol','li','u','sup','sub','s');
$find = [];
$replace = [];
foreach ( $allowed_tags as $tag ) {
// Opening tags
$find[] = '<' . $tag . '>';