-
Notifications
You must be signed in to change notification settings - Fork 2
/
the_curtain.admin.inc
executable file
·232 lines (194 loc) · 5.95 KB
/
the_curtain.admin.inc
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
<?php
/**
* @file administrative page building functions
*/
/**
* Page callback
*/
function _the_curtain_admin_page() {
return t('All shall be revealed.');
}
function _the_curtain_admin_display_table($table) {
$data = _the_curtain_admin_entable_table($table);
return _the_curtain_admin_theme_table($data['header'], $data['rows']);
}
function _the_curtain_admin_hooks() {
// use `module_implements()`
return "Under Construction";
}
function _the_curtain_watchdog_stats() {
$results = db_query('select type, message, variables, COUNT(*) AS count FROM watchdog w
GROUP BY type, message, variables HAVING count > 4 ORDER BY count DESC');
$header = array('Type', 'Count', 'Message');
$rows = array();
foreach ( $results as $result ) {
// t() message and variables
$result = (array)$result;
$result['message'] = t($result['message'], unserialize($result['variables']));
unset($result['variables']);
$rows[] = array(
$result['type'],
$result['count'],
$result['message'],
);
}
return theme('table', array('header'=>$header,'rows'=>$rows));
}
function _the_curtain_admin_entable_table($table, array $orderBy = NULL, $limit = 100) {
$query = db_select($table, 't')->fields('t')
->addTag(__FUNCTION__);
foreach ( $orderBy as $field ) {
$query->orderBy($field);
}
// Query options
// limit & offset
if ( isset($_GET['limit']) && is_numeric($_GET['limit']) ) {
$limit = $_GET['limit'];
}
$offset = 0;
if ( isset($_GET['offset']) && is_numeric($_GET['offset']) ) {
$offset = $_GET['offset'];
}
$query->range($offset,$limit);
// order by
if ( isset($_GET['order_by']) ) {
foreach ( explode($_GET['order_by']) as $sort_field ) {
$query->orderby($sort_field);
}
}
$results = $query->execute()->fetchAll();
foreach ( $results as $result ) {
// create the column headers from the field names
if ( ! isset($header) ) {
$header = array();
foreach ( (array)$result as $field => $value ) {
if ( ! isset($header[$field]) ) {
$header[$field] = ucwords($field);
}
}
}
// turn the row into an array for easy drupal formatting.
$result = (array)$result;
foreach ( $result as &$value) {
if ( strpos($value, ':') === 1 ) {
$value = _the_curtain_test_serialization($value);
}
elseif ( $value == 'N;' ) {
// NULL
$value = '(literal) NULL';
}
}
$rows[] = (array)$result;
}
return array('header'=>$header,'rows'=>$rows);
}
function _the_curtain_admin_theme_table($header, $rows) {
return theme('table', array('header'=>$header,'rows'=>$rows));
}
function _the_curtain_test_serialization($value) {
// unserialize serialized values
if ( $value == 'a:0:{}' ) {
$value = "(serialized empty array)" . theme('table', array('rows'=>array(array(" "))));
}
elseif ( $value == 'b:0;' ) {
$value = "(serialized boolean) FALSE";
}
elseif ( $value == 'b:1;' ) {
$value = "(serialized boolean) TRUE";
}
elseif ( $value == 's:0:"";' ) {
$value = '(serialized empty string) ""';
}
elseif ( strpos($value, 's:O:') === 0 ) {
// object
$value = '(serialized object)' . (array)unserialize($value);
}
/*
// this is acting problematic
elseif ( strpos($value, 'a:') === 0 ) {
$vals = array();
foreach ( @unserialize($value) as $key => $val ) {
if ( is_object($val) ) {
$val = (array)$val;
}
$vals[] = array($key, $val);
}
$value = '(serialized array)' . theme('table', array('rows'=>$vals));
}
*/
elseif (
strpos($value, 'i:') === 0
|| strpos($value, 's:') === 0
|| strpos($value, 'd:') === 0
) {
$value = @unserialize($value);
if ( is_string($value) && is_numeric($value) ) {
$value = '(serialized string numeral) "' . $value . '"';
}
}
return $value;
}
function _the_curtain_admin_table($table) {
$data = _the_curtain_admin_entable_table($table);
return _the_curtain_admin_theme_table($data['header'], $data['rows']);
}
function _the_curtain_admin_tables_form($form, &$form_state) {
$tables = db_query('SHOW TABLES');
while ( $table = $tables->fetchAssoc() ) {
foreach ( $table as $key => $value ) {
$options[$value] = $value;
}
}
$form['table'] = array(
'#type' => 'select',
'#title' => t('Tables'),
'#options' => $options,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#submit' => array('_the_curtain_admin_show_tables_submit'),
);
return $form;
}
function _the_curtain_admin_show_tables_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/config/development/the_curtain/tables/'
. check_plain($form_state['values']['table']);
}
function _the_curtain_admin_unveilings_form($form, &$form_state) {
$unveilings = array(
'the_curtain_show_sql' => t('Show SQL'),
'the_curtain_show_form_id' => t('Show Form IDs (names)'),
'the_curtain_show_forms' => t('Show Form Arrays'),
'the_curtain_show_form_states' => t('Show Form State Arrays'),
'the_curtain_show_efq' => t('Show Entity Field Queries SQL'),
);
foreach ( $unveilings as $unveiling => $description) {
$form[$unveiling] = array(
'#title' => $description,
'#type' => 'checkbox',
'#default_value' => variable_get($unveiling),
);
}
return system_settings_form($form);
}
function _the_curtain_admin_fields() {
$field_map = field_info_field_map();
foreach ( $field_map as $field => $info ) {
foreach( $info['bundles'] as $bundle => $appearances ) {
$bundle_rows = array();
foreach ( $appearances as $appearance ) {
$bundle_rows[] = array($appearance);
}
$bundle_info = theme('table', array(
'header' => array($bundle),
'rows' => $bundle_rows,
));
}
$rows[] = array($field, $info['type'],$bundle_info );
}
return theme('table',array(
'header' => array(t('Name'),t('Type'),t('Bundles')),
'rows'=> $rows,
));
}