PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Helpers / global / query.php

query.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.1.0, at back/Helpers/global/query.php

67 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || die('Restricted Access');
3
4 function acym_getTables(bool $reload = false): array
5 {
6 static $tables = null;
7 if (empty($tables) || $reload) {
8 $tables = acym_loadResultArray('SHOW TABLES');
9 }
10
11 return $tables;
12 }
13
14 function acym_getColumns(string $table, bool $acyTable = true, bool $addPrefix = true): array
15 {
16 if ($addPrefix) {
17 $prefix = $acyTable ? '#__acym_' : '#__';
18 $table = $prefix.$table;
19 }
20
21 static $columns = [];
22 if (empty($columns[$table])) {
23 $columns[$table] = acym_loadResultArray('SHOW COLUMNS FROM '.acym_secureDBColumn($table));
24 }
25
26 return $columns[$table] ?? [];
27 }
28
29 function acym_secureDBColumn(string $fieldName): string
30 {
31 if (preg_match('|[^a-z0-9#_.-]|i', $fieldName) !== 0) {
32 die('field, table or database "'.esc_html($fieldName).'" not secured');
33 }
34
35 return $fieldName;
36 }
37
38 function acym_getDatabases(): array
39 {
40 try {
41 $allDatabases = acym_loadResultArray('SHOW DATABASES');
42 } catch (Exception $exception) {
43 $allDatabases = [];
44 $allDatabases[] = acym_loadResult('SELECT DATABASE();');
45 }
46
47 $databases = [];
48 foreach ($allDatabases as $database) {
49 $databases[$database] = $database;
50 }
51
52 return $databases;
53 }
54
55 function acym_addLimit(string &$query, int $limit = 1, ?int $offset = null): void
56 {
57 if (strpos($query, 'LIMIT ') !== false) {
58 return;
59 }
60
61 $query .= ' LIMIT ';
62 if (!empty($offset)) {
63 $query .= intval($offset).',';
64 }
65 $query .= intval($limit);
66 }
67