Completed
Pull Request — develop (#522)
by Agel_Nash
07:16
created
manager/includes/tmplvars.inc.php 1 patch
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -1,159 +1,159 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // DISPLAY FORM ELEMENTS
3 3
 function renderFormElement($field_type, $field_id, $default_text = '', $field_elements = '', $field_value = '', $field_style = '', $row = array(), $tvsArray = array()) {
4
-	global $modx;
5
-	global $_style;
6
-	global $_lang;
7
-	global $content;
8
-	global $which_browser;
4
+    global $modx;
5
+    global $_style;
6
+    global $_lang;
7
+    global $content;
8
+    global $which_browser;
9 9
 
10
-	if(substr($default_text, 0, 6) === '@@EVAL' && $field_value === $default_text) {
11
-		$eval_str = trim(substr($default_text, 7));
12
-		$default_text = eval($eval_str);
13
-		$field_value = $default_text;
14
-	}
10
+    if(substr($default_text, 0, 6) === '@@EVAL' && $field_value === $default_text) {
11
+        $eval_str = trim(substr($default_text, 7));
12
+        $default_text = eval($eval_str);
13
+        $field_value = $default_text;
14
+    }
15 15
 
16
-	$field_html = '';
17
-	$cimode = strpos($field_type, ':');
18
-	if($cimode === false) {
19
-		switch($field_type) {
16
+    $field_html = '';
17
+    $cimode = strpos($field_type, ':');
18
+    if($cimode === false) {
19
+        switch($field_type) {
20 20
 
21
-			case "text": // handler for regular text boxes
22
-			case "rawtext"; // non-htmlentity converted text boxes
23
-				$field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%" />';
24
-				break;
25
-			case "email": // handles email input fields
26
-				$field_html .= '<input type="email" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%"/>';
27
-				break;
28
-			case "number": // handles the input of numbers
29
-				$field_html .= '<input type="number" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%" onkeyup="this.value=this.value.replace(/[^\d-,.+]/,\'\')"/>';
30
-				break;
31
-			case "textareamini": // handler for textarea mini boxes
32
-				$field_html .= '<textarea id="tv' . $field_id . '" name="tv' . $field_id . '" cols="40" rows="5" onchange="documentDirty=true;" style="width:100%">' . $modx->htmlspecialchars($field_value) . '</textarea>';
33
-				break;
34
-			case "textarea": // handler for textarea boxes
35
-			case "rawtextarea": // non-htmlentity convertex textarea boxes
36
-			case "htmlarea": // handler for textarea boxes (deprecated)
37
-			case "richtext": // handler for textarea boxes
38
-				$field_html .= '<textarea id="tv' . $field_id . '" name="tv' . $field_id . '" cols="40" rows="15" onchange="documentDirty=true;" style="width:100%">' . $modx->htmlspecialchars($field_value) . '</textarea>';
39
-				break;
40
-			case "date":
41
-				$field_id = str_replace(array(
42
-					'-',
43
-					'.'
44
-				), '_', urldecode($field_id));
45
-				if($field_value == '') {
46
-					$field_value = 0;
47
-				}
48
-				$field_html .= '<input id="tv' . $field_id . '" name="tv' . $field_id . '" class="DatePicker" type="text" value="' . ($field_value == 0 || !isset($field_value) ? "" : $field_value) . '" onblur="documentDirty=true;" />';
49
-				$field_html .= ' <a onclick="document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].value=\'\';document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].onblur(); return true;" onmouseover="window.status=\'clear the date\'; return true;" onmouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><i class="' . $_style["actions_calendar_delete"] . '"></i></a>';
21
+            case "text": // handler for regular text boxes
22
+            case "rawtext"; // non-htmlentity converted text boxes
23
+                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%" />';
24
+                break;
25
+            case "email": // handles email input fields
26
+                $field_html .= '<input type="email" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%"/>';
27
+                break;
28
+            case "number": // handles the input of numbers
29
+                $field_html .= '<input type="number" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%" onkeyup="this.value=this.value.replace(/[^\d-,.+]/,\'\')"/>';
30
+                break;
31
+            case "textareamini": // handler for textarea mini boxes
32
+                $field_html .= '<textarea id="tv' . $field_id . '" name="tv' . $field_id . '" cols="40" rows="5" onchange="documentDirty=true;" style="width:100%">' . $modx->htmlspecialchars($field_value) . '</textarea>';
33
+                break;
34
+            case "textarea": // handler for textarea boxes
35
+            case "rawtextarea": // non-htmlentity convertex textarea boxes
36
+            case "htmlarea": // handler for textarea boxes (deprecated)
37
+            case "richtext": // handler for textarea boxes
38
+                $field_html .= '<textarea id="tv' . $field_id . '" name="tv' . $field_id . '" cols="40" rows="15" onchange="documentDirty=true;" style="width:100%">' . $modx->htmlspecialchars($field_value) . '</textarea>';
39
+                break;
40
+            case "date":
41
+                $field_id = str_replace(array(
42
+                    '-',
43
+                    '.'
44
+                ), '_', urldecode($field_id));
45
+                if($field_value == '') {
46
+                    $field_value = 0;
47
+                }
48
+                $field_html .= '<input id="tv' . $field_id . '" name="tv' . $field_id . '" class="DatePicker" type="text" value="' . ($field_value == 0 || !isset($field_value) ? "" : $field_value) . '" onblur="documentDirty=true;" />';
49
+                $field_html .= ' <a onclick="document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].value=\'\';document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].onblur(); return true;" onmouseover="window.status=\'clear the date\'; return true;" onmouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><i class="' . $_style["actions_calendar_delete"] . '"></i></a>';
50 50
 
51
-				break;
52
-			case "dropdown": // handler for select boxes
53
-				$field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" size="1" onchange="documentDirty=true;">';
54
-				$index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
55
-				while(list($item, $itemvalue) = each($index_list)) {
56
-					list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
57
-					if(strlen($itemvalue) == 0) {
58
-						$itemvalue = $item;
59
-					}
60
-					$field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
61
-				}
62
-				$field_html .= "</select>";
63
-				break;
64
-			case "listbox": // handler for select boxes
65
-				$field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" onchange="documentDirty=true;" size="8">';
66
-				$index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
67
-				while(list($item, $itemvalue) = each($index_list)) {
68
-					list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
69
-					if(strlen($itemvalue) == 0) {
70
-						$itemvalue = $item;
71
-					}
72
-					$field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
73
-				}
74
-				$field_html .= "</select>";
75
-				break;
76
-			case "listbox-multiple": // handler for select boxes where you can choose multiple items
77
-				$field_value = explode("||", $field_value);
78
-				$field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '[]" multiple="multiple" onchange="documentDirty=true;" size="8">';
79
-				$index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
80
-				while(list($item, $itemvalue) = each($index_list)) {
81
-					list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
82
-					if(strlen($itemvalue) == 0) {
83
-						$itemvalue = $item;
84
-					}
85
-					$field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . (in_array($itemvalue, $field_value) ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
86
-				}
87
-				$field_html .= "</select>";
88
-				break;
89
-			case "url": // handles url input fields
90
-				$urls = array(
91
-					'' => '--',
92
-					'http://' => 'http://',
93
-					'https://' => 'https://',
94
-					'ftp://' => 'ftp://',
95
-					'mailto:' => 'mailto:'
96
-				);
97
-				$field_html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><select id="tv' . $field_id . '_prefix" name="tv' . $field_id . '_prefix" onchange="documentDirty=true;">';
98
-				foreach($urls as $k => $v) {
99
-					if(strpos($field_value, $v) === false) {
100
-						$field_html .= '<option value="' . $v . '">' . $k . '</option>';
101
-					} else {
102
-						$field_value = str_replace($v, '', $field_value);
103
-						$field_html .= '<option value="' . $v . '" selected="selected">' . $k . '</option>';
104
-					}
105
-				}
106
-				$field_html .= '</select></td><td>';
107
-				$field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" width="100" ' . $field_style . ' onchange="documentDirty=true;" /></td></tr></table>';
108
-				break;
109
-			case 'checkbox': // handles check boxes
110
-				$values = !is_array($field_value) ? explode('||', $field_value) : $field_value;
111
-				$index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
112
-				$tpl = '<label class="checkbox"><input type="checkbox" value="%s" id="tv_%s" name="tv%s[]" %s onchange="documentDirty=true;" />%s</label><br />';
113
-				static $i = 0;
114
-				$_ = array();
115
-				foreach($index_list as $c => $item) {
116
-					if(is_array($item)) {
117
-						$name = trim($item[0]);
118
-						$value = isset($item[1]) ? $item[1] : $name;
119
-					} else {
120
-						$item = trim($item);
121
-						list($name, $value) = (strpos($item, '==') !== false) ? explode('==', $item, 2) : array(
122
-							$item,
123
-							$item
124
-						);
125
-					}
126
-					$checked = in_array($value, $values) ? ' checked="checked"' : '';
127
-					$param = array(
128
-						$modx->htmlspecialchars($value),
129
-						$i,
130
-						$field_id,
131
-						$checked,
132
-						$modx->htmlspecialchars($name)
133
-					);
134
-					$_[] = vsprintf($tpl, $param);
135
-					$i++;
136
-				}
137
-				$field_html = join("\n", $_);
138
-				break;
139
-			case "option": // handles radio buttons
140
-				$index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
141
-				static $i = 0;
142
-				while(list($item, $itemvalue) = each($index_list)) {
143
-					list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
144
-					if(strlen($itemvalue) == 0) {
145
-						$itemvalue = $item;
146
-					}
147
-					$field_html .= '<input type="radio" value="' . $modx->htmlspecialchars($itemvalue) . '" id="tv_' . $i . '" name="tv' . $field_id . '" ' . ($itemvalue == $field_value ? 'checked="checked"' : '') . ' onchange="documentDirty=true;" /><label for="tv_' . $i . '" class="radio">' . $item . '</label><br />';
148
-					$i++;
149
-				}
150
-				break;
151
-			case "image": // handles image fields using htmlarea image manager
152
-				global $_lang;
153
-				global $ResourceManagerLoaded;
154
-				global $content, $use_editor, $which_editor;
155
-				if(!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $modx->manager->action == 4) && $use_editor == 1 && $which_editor == 3)) {
156
-					$field_html .= "
51
+                break;
52
+            case "dropdown": // handler for select boxes
53
+                $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" size="1" onchange="documentDirty=true;">';
54
+                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
55
+                while(list($item, $itemvalue) = each($index_list)) {
56
+                    list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
57
+                    if(strlen($itemvalue) == 0) {
58
+                        $itemvalue = $item;
59
+                    }
60
+                    $field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
61
+                }
62
+                $field_html .= "</select>";
63
+                break;
64
+            case "listbox": // handler for select boxes
65
+                $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" onchange="documentDirty=true;" size="8">';
66
+                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
67
+                while(list($item, $itemvalue) = each($index_list)) {
68
+                    list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
69
+                    if(strlen($itemvalue) == 0) {
70
+                        $itemvalue = $item;
71
+                    }
72
+                    $field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
73
+                }
74
+                $field_html .= "</select>";
75
+                break;
76
+            case "listbox-multiple": // handler for select boxes where you can choose multiple items
77
+                $field_value = explode("||", $field_value);
78
+                $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '[]" multiple="multiple" onchange="documentDirty=true;" size="8">';
79
+                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
80
+                while(list($item, $itemvalue) = each($index_list)) {
81
+                    list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
82
+                    if(strlen($itemvalue) == 0) {
83
+                        $itemvalue = $item;
84
+                    }
85
+                    $field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . (in_array($itemvalue, $field_value) ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
86
+                }
87
+                $field_html .= "</select>";
88
+                break;
89
+            case "url": // handles url input fields
90
+                $urls = array(
91
+                    '' => '--',
92
+                    'http://' => 'http://',
93
+                    'https://' => 'https://',
94
+                    'ftp://' => 'ftp://',
95
+                    'mailto:' => 'mailto:'
96
+                );
97
+                $field_html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><select id="tv' . $field_id . '_prefix" name="tv' . $field_id . '_prefix" onchange="documentDirty=true;">';
98
+                foreach($urls as $k => $v) {
99
+                    if(strpos($field_value, $v) === false) {
100
+                        $field_html .= '<option value="' . $v . '">' . $k . '</option>';
101
+                    } else {
102
+                        $field_value = str_replace($v, '', $field_value);
103
+                        $field_html .= '<option value="' . $v . '" selected="selected">' . $k . '</option>';
104
+                    }
105
+                }
106
+                $field_html .= '</select></td><td>';
107
+                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" width="100" ' . $field_style . ' onchange="documentDirty=true;" /></td></tr></table>';
108
+                break;
109
+            case 'checkbox': // handles check boxes
110
+                $values = !is_array($field_value) ? explode('||', $field_value) : $field_value;
111
+                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
112
+                $tpl = '<label class="checkbox"><input type="checkbox" value="%s" id="tv_%s" name="tv%s[]" %s onchange="documentDirty=true;" />%s</label><br />';
113
+                static $i = 0;
114
+                $_ = array();
115
+                foreach($index_list as $c => $item) {
116
+                    if(is_array($item)) {
117
+                        $name = trim($item[0]);
118
+                        $value = isset($item[1]) ? $item[1] : $name;
119
+                    } else {
120
+                        $item = trim($item);
121
+                        list($name, $value) = (strpos($item, '==') !== false) ? explode('==', $item, 2) : array(
122
+                            $item,
123
+                            $item
124
+                        );
125
+                    }
126
+                    $checked = in_array($value, $values) ? ' checked="checked"' : '';
127
+                    $param = array(
128
+                        $modx->htmlspecialchars($value),
129
+                        $i,
130
+                        $field_id,
131
+                        $checked,
132
+                        $modx->htmlspecialchars($name)
133
+                    );
134
+                    $_[] = vsprintf($tpl, $param);
135
+                    $i++;
136
+                }
137
+                $field_html = join("\n", $_);
138
+                break;
139
+            case "option": // handles radio buttons
140
+                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
141
+                static $i = 0;
142
+                while(list($item, $itemvalue) = each($index_list)) {
143
+                    list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
144
+                    if(strlen($itemvalue) == 0) {
145
+                        $itemvalue = $item;
146
+                    }
147
+                    $field_html .= '<input type="radio" value="' . $modx->htmlspecialchars($itemvalue) . '" id="tv_' . $i . '" name="tv' . $field_id . '" ' . ($itemvalue == $field_value ? 'checked="checked"' : '') . ' onchange="documentDirty=true;" /><label for="tv_' . $i . '" class="radio">' . $item . '</label><br />';
148
+                    $i++;
149
+                }
150
+                break;
151
+            case "image": // handles image fields using htmlarea image manager
152
+                global $_lang;
153
+                global $ResourceManagerLoaded;
154
+                global $content, $use_editor, $which_editor;
155
+                if(!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $modx->manager->action == 4) && $use_editor == 1 && $which_editor == 3)) {
156
+                    $field_html .= "
157 157
 						<script type=\"text/javascript\">
158 158
 							/* <![CDATA[ */
159 159
 								var lastImageCtrl;
@@ -212,18 +212,18 @@  discard block
 block discarded – undo
212 212
 								}
213 213
 							/* ]]> */
214 214
 						</script>";
215
-					$ResourceManagerLoaded = true;
216
-				}
217
-				$field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '"  value="' . $field_value . '" ' . $field_style . ' onchange="documentDirty=true;" /><input type="button" value="' . $_lang['insert'] . '" onclick="BrowseServer(\'tv' . $field_id . '\')" />';
218
-				break;
219
-			case "file": // handles the input of file uploads
220
-				/* Modified by Timon for use with resource browser */
221
-				global $_lang;
222
-				global $ResourceManagerLoaded;
223
-				global $content, $use_editor, $which_editor;
224
-				if(!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $modx->manager->action == 4) && $use_editor == 1 && $which_editor == 3)) {
225
-					/* I didn't understand the meaning of the condition above, so I left it untouched ;-) */
226
-					$field_html .= "
215
+                    $ResourceManagerLoaded = true;
216
+                }
217
+                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '"  value="' . $field_value . '" ' . $field_style . ' onchange="documentDirty=true;" /><input type="button" value="' . $_lang['insert'] . '" onclick="BrowseServer(\'tv' . $field_id . '\')" />';
218
+                break;
219
+            case "file": // handles the input of file uploads
220
+                /* Modified by Timon for use with resource browser */
221
+                global $_lang;
222
+                global $ResourceManagerLoaded;
223
+                global $content, $use_editor, $which_editor;
224
+                if(!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $modx->manager->action == 4) && $use_editor == 1 && $which_editor == 3)) {
225
+                    /* I didn't understand the meaning of the condition above, so I left it untouched ;-) */
226
+                    $field_html .= "
227 227
 						<script type=\"text/javascript\">
228 228
 							/* <![CDATA[ */
229 229
 								var lastImageCtrl;
@@ -282,101 +282,101 @@  discard block
 block discarded – undo
282 282
 								}
283 283
 							/* ]]> */
284 284
 						</script>";
285
-					$ResourceManagerLoaded = true;
286
-				}
287
-				$field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '"  value="' . $field_value . '" ' . $field_style . ' onchange="documentDirty=true;" /><input type="button" value="' . $_lang['insert'] . '" onclick="BrowseFileServer(\'tv' . $field_id . '\')" />';
285
+                    $ResourceManagerLoaded = true;
286
+                }
287
+                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '"  value="' . $field_value . '" ' . $field_style . ' onchange="documentDirty=true;" /><input type="button" value="' . $_lang['insert'] . '" onclick="BrowseFileServer(\'tv' . $field_id . '\')" />';
288 288
 
289
-				break;
289
+                break;
290 290
 
291
-			case 'custom_tv':
292
-				$custom_output = '';
293
-				/* If we are loading a file */
294
-				if(substr($field_elements, 0, 5) == "@FILE") {
295
-					$file_name = MODX_BASE_PATH . trim(substr($field_elements, 6));
296
-					if(!file_exists($file_name)) {
297
-						$custom_output = $file_name . ' does not exist';
298
-					} else {
299
-						$custom_output = file_get_contents($file_name);
300
-					}
301
-				} elseif(substr($field_elements, 0, 8) == '@INCLUDE') {
302
-					$file_name = MODX_BASE_PATH . trim(substr($field_elements, 9));
303
-					if(!file_exists($file_name)) {
304
-						$custom_output = $file_name . ' does not exist';
305
-					} else {
306
-						ob_start();
307
-						include $file_name;
308
-						$custom_output = ob_get_contents();
309
-						ob_end_clean();
310
-					}
311
-				} elseif(substr($field_elements, 0, 6) == "@CHUNK") {
312
-					$chunk_name = trim(substr($field_elements, 7));
313
-					$chunk_body = $modx->getChunk($chunk_name);
314
-					if($chunk_body == false) {
315
-						$custom_output = $_lang['chunk_no_exist'] . '(' . $_lang['htmlsnippet_name'] . ':' . $chunk_name . ')';
316
-					} else {
317
-						$custom_output = $chunk_body;
318
-					}
319
-				} elseif(substr($field_elements, 0, 5) == "@EVAL") {
320
-					$eval_str = trim(substr($field_elements, 6));
321
-					$custom_output = eval($eval_str);
322
-				} else {
323
-					$custom_output = $field_elements;
324
-				}
325
-				$replacements = array(
326
-					'[+field_type+]' => $field_type,
327
-					'[+field_id+]' => $field_id,
328
-					'[+default_text+]' => $default_text,
329
-					'[+field_value+]' => $modx->htmlspecialchars($field_value),
330
-					'[+field_style+]' => $field_style,
331
-				);
332
-				$custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
333
-				$modx->documentObject = $content;
334
-				$modx->documentIdentifier = $content['id'];
335
-				$custom_output = $modx->parseDocumentSource($custom_output);
336
-				$field_html .= $custom_output;
337
-				break;
291
+            case 'custom_tv':
292
+                $custom_output = '';
293
+                /* If we are loading a file */
294
+                if(substr($field_elements, 0, 5) == "@FILE") {
295
+                    $file_name = MODX_BASE_PATH . trim(substr($field_elements, 6));
296
+                    if(!file_exists($file_name)) {
297
+                        $custom_output = $file_name . ' does not exist';
298
+                    } else {
299
+                        $custom_output = file_get_contents($file_name);
300
+                    }
301
+                } elseif(substr($field_elements, 0, 8) == '@INCLUDE') {
302
+                    $file_name = MODX_BASE_PATH . trim(substr($field_elements, 9));
303
+                    if(!file_exists($file_name)) {
304
+                        $custom_output = $file_name . ' does not exist';
305
+                    } else {
306
+                        ob_start();
307
+                        include $file_name;
308
+                        $custom_output = ob_get_contents();
309
+                        ob_end_clean();
310
+                    }
311
+                } elseif(substr($field_elements, 0, 6) == "@CHUNK") {
312
+                    $chunk_name = trim(substr($field_elements, 7));
313
+                    $chunk_body = $modx->getChunk($chunk_name);
314
+                    if($chunk_body == false) {
315
+                        $custom_output = $_lang['chunk_no_exist'] . '(' . $_lang['htmlsnippet_name'] . ':' . $chunk_name . ')';
316
+                    } else {
317
+                        $custom_output = $chunk_body;
318
+                    }
319
+                } elseif(substr($field_elements, 0, 5) == "@EVAL") {
320
+                    $eval_str = trim(substr($field_elements, 6));
321
+                    $custom_output = eval($eval_str);
322
+                } else {
323
+                    $custom_output = $field_elements;
324
+                }
325
+                $replacements = array(
326
+                    '[+field_type+]' => $field_type,
327
+                    '[+field_id+]' => $field_id,
328
+                    '[+default_text+]' => $default_text,
329
+                    '[+field_value+]' => $modx->htmlspecialchars($field_value),
330
+                    '[+field_style+]' => $field_style,
331
+                );
332
+                $custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
333
+                $modx->documentObject = $content;
334
+                $modx->documentIdentifier = $content['id'];
335
+                $custom_output = $modx->parseDocumentSource($custom_output);
336
+                $field_html .= $custom_output;
337
+                break;
338 338
 
339
-			default: // the default handler -- for errors, mostly
340
-				$field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' onchange="documentDirty=true;" />';
339
+            default: // the default handler -- for errors, mostly
340
+                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' onchange="documentDirty=true;" />';
341 341
 
342
-		} // end switch statement
343
-	} else {
344
-		$custom = explode(":", $field_type);
345
-		$custom_output = '';
346
-		$file_name = MODX_BASE_PATH . 'assets/tvs/' . $custom['1'] . '/' . $custom['1'] . '.customtv.php';
347
-		if(!file_exists($file_name)) {
348
-			$custom_output = $file_name . ' does not exist';
349
-		} else {
350
-			ob_start();
351
-			include $file_name;
352
-			$custom_output = ob_get_contents();
353
-			ob_end_clean();
354
-		}
355
-		$replacements = array(
356
-			'[+field_type+]' => $field_type,
357
-			'[+field_id+]' => $field_id,
358
-			'[+default_text+]' => $default_text,
359
-			'[+field_value+]' => $modx->htmlspecialchars($field_value),
360
-			'[+field_style+]' => $field_style,
361
-		);
362
-		$custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
363
-		$modx->documentObject = $content;
364
-		$custom_output = $modx->parseDocumentSource($custom_output);
365
-		$field_html .= $custom_output;
366
-	}
342
+        } // end switch statement
343
+    } else {
344
+        $custom = explode(":", $field_type);
345
+        $custom_output = '';
346
+        $file_name = MODX_BASE_PATH . 'assets/tvs/' . $custom['1'] . '/' . $custom['1'] . '.customtv.php';
347
+        if(!file_exists($file_name)) {
348
+            $custom_output = $file_name . ' does not exist';
349
+        } else {
350
+            ob_start();
351
+            include $file_name;
352
+            $custom_output = ob_get_contents();
353
+            ob_end_clean();
354
+        }
355
+        $replacements = array(
356
+            '[+field_type+]' => $field_type,
357
+            '[+field_id+]' => $field_id,
358
+            '[+default_text+]' => $default_text,
359
+            '[+field_value+]' => $modx->htmlspecialchars($field_value),
360
+            '[+field_style+]' => $field_style,
361
+        );
362
+        $custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
363
+        $modx->documentObject = $content;
364
+        $custom_output = $modx->parseDocumentSource($custom_output);
365
+        $field_html .= $custom_output;
366
+    }
367 367
 
368
-	return $field_html;
368
+    return $field_html;
369 369
 } // end renderFormElement function
370 370
 
371 371
 function ParseIntputOptions($v) {
372
-	global $modx;
373
-	$a = array();
374
-	if(is_array($v)) {
375
-		return $v;
376
-	} else if($modx->db->isResult($v)) {
377
-		while($cols = $modx->db->getRow($v, 'num')) $a[] = $cols;
378
-	} else {
379
-		$a = explode("||", $v);
380
-	}
381
-	return $a;
372
+    global $modx;
373
+    $a = array();
374
+    if(is_array($v)) {
375
+        return $v;
376
+    } else if($modx->db->isResult($v)) {
377
+        while($cols = $modx->db->getRow($v, 'num')) $a[] = $cols;
378
+    } else {
379
+        $a = explode("||", $v);
380
+    }
381
+    return $a;
382 382
 }
Please login to merge, or discard this patch.
manager/includes/extenders/message.quit.inc.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -19,60 +19,60 @@
 block discarded – undo
19 19
 </head><body>
20 20
 ";
21 21
 if($is_error) {
22
-	$parsedMessageString .= "<h3 style='color:red;background:#e0e0e0;padding:2px;'>&nbsp;MODX Parse Error </h3>
22
+    $parsedMessageString .= "<h3 style='color:red;background:#e0e0e0;padding:2px;'>&nbsp;MODX Parse Error </h3>
23 23
 	<table border='0' cellpadding='1' cellspacing='0'>
24 24
 	<tr><td colspan='3'>MODX encountered the following error while attempting to parse the requested resource:</td></tr>
25 25
 	<tr><td colspan='3'><b style='color:red;'>&laquo; $msg &raquo;</b></td></tr>";
26 26
 } else {
27
-	$parsedMessageString .= "<h3 style='color:#003399; background:#eeeeee;padding:2px;'>&nbsp;MODX Debug/ stop message </h3>
27
+    $parsedMessageString .= "<h3 style='color:#003399; background:#eeeeee;padding:2px;'>&nbsp;MODX Debug/ stop message </h3>
28 28
 	<table border='0' cellpadding='1' cellspacing='0'>
29 29
 	<tr><td colspan='3'>The MODX parser recieved the following debug/ stop message:</td></tr>
30 30
 	<tr><td colspan='3'><b style='color:#003399;'>&laquo; $msg &raquo;</b></td></tr>";
31 31
 }
32 32
 
33 33
 if(!empty($query)) {
34
-	$parsedMessageString .= "<tr><td colspan='3'><hr size='1' width='98%' style='color:#e0e0e0'/><b style='color:#999;font-size: 9px;border-left:1px solid #c0c0c0; margin-left:10px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQL:&nbsp;<span id='sqlHolder'>$query</span></b><hr size='1' width='98%' style='color:#e0e0e0'/>
34
+    $parsedMessageString .= "<tr><td colspan='3'><hr size='1' width='98%' style='color:#e0e0e0'/><b style='color:#999;font-size: 9px;border-left:1px solid #c0c0c0; margin-left:10px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQL:&nbsp;<span id='sqlHolder'>$query</span></b><hr size='1' width='98%' style='color:#e0e0e0'/>
35 35
 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:copyToClip();' style='color:#821517;font-size: 9px; text-decoration: none'>[Copy SQL to ClipBoard]</a><textarea id='holdtext' style='display:none;'></textarea></td></tr>";
36 36
 }
37 37
 
38 38
 if($text!='') {
39 39
 
40
-	$errortype = array (
41
-		E_ERROR          => "Error",
42
-		E_WARNING        => "Warning",
43
-		E_PARSE          => "Parsing Error",
44
-		E_NOTICE          => "Notice",
45
-		E_CORE_ERROR      => "Core Error",
46
-		E_CORE_WARNING    => "Core Warning",
47
-		E_COMPILE_ERROR  => "Compile Error",
48
-		E_COMPILE_WARNING => "Compile Warning",
49
-		E_USER_ERROR      => "User Error",
50
-		E_USER_WARNING    => "User Warning",
51
-		E_USER_NOTICE    => "User Notice",
52
-	);
40
+    $errortype = array (
41
+        E_ERROR          => "Error",
42
+        E_WARNING        => "Warning",
43
+        E_PARSE          => "Parsing Error",
44
+        E_NOTICE          => "Notice",
45
+        E_CORE_ERROR      => "Core Error",
46
+        E_CORE_WARNING    => "Core Warning",
47
+        E_COMPILE_ERROR  => "Compile Error",
48
+        E_COMPILE_WARNING => "Compile Warning",
49
+        E_USER_ERROR      => "User Error",
50
+        E_USER_WARNING    => "User Warning",
51
+        E_USER_NOTICE    => "User Notice",
52
+    );
53 53
 
54
-	$parsedMessageString .= "<tr><td>&nbsp;</td></tr><tr><td colspan='3'><b>PHP error debug</b></td></tr>";
54
+    $parsedMessageString .= "<tr><td>&nbsp;</td></tr><tr><td colspan='3'><b>PHP error debug</b></td></tr>";
55 55
 
56
-	$parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Error: </td>";
57
-	$parsedMessageString .= "<td colspan='2'>$text</td><td>&nbsp;</td>";
58
-	$parsedMessageString .= "</tr>";
56
+    $parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Error: </td>";
57
+    $parsedMessageString .= "<td colspan='2'>$text</td><td>&nbsp;</td>";
58
+    $parsedMessageString .= "</tr>";
59 59
 
60
-	$parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Error type/ Nr.: </td>";
61
-	$parsedMessageString .= "<td colspan='2'>".$errortype[$nr]." - $nr</b></td><td>&nbsp;</td>";
62
-	$parsedMessageString .= "</tr>";
60
+    $parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Error type/ Nr.: </td>";
61
+    $parsedMessageString .= "<td colspan='2'>".$errortype[$nr]." - $nr</b></td><td>&nbsp;</td>";
62
+    $parsedMessageString .= "</tr>";
63 63
 
64
-	$parsedMessageString .= "<tr><td>&nbsp;&nbsp;File: </td>";
65
-	$parsedMessageString .= "<td colspan='2'>$file</td><td>&nbsp;</td>";
66
-	$parsedMessageString .= "</tr>";
64
+    $parsedMessageString .= "<tr><td>&nbsp;&nbsp;File: </td>";
65
+    $parsedMessageString .= "<td colspan='2'>$file</td><td>&nbsp;</td>";
66
+    $parsedMessageString .= "</tr>";
67 67
 
68
-	$parsedMessageString .= "<tr><td>&nbsp;&nbsp;Line: </td>";
69
-	$parsedMessageString .= "<td colspan='2'>$line</td><td>&nbsp;</td>";
70
-	$parsedMessageString .= "</tr>";
71
-	if($source!='') {
72
-		$parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Line $line source: </td>";
73
-		$parsedMessageString .= "<td colspan='2'>$source</td><td>&nbsp;</td>";
74
-		$parsedMessageString .= "</tr>";
75
-	}
68
+    $parsedMessageString .= "<tr><td>&nbsp;&nbsp;Line: </td>";
69
+    $parsedMessageString .= "<td colspan='2'>$line</td><td>&nbsp;</td>";
70
+    $parsedMessageString .= "</tr>";
71
+    if($source!='') {
72
+        $parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Line $line source: </td>";
73
+        $parsedMessageString .= "<td colspan='2'>$source</td><td>&nbsp;</td>";
74
+        $parsedMessageString .= "</tr>";
75
+    }
76 76
 }
77 77
 
78 78
 $parsedMessageString .= "<tr><td>&nbsp;</td></tr><tr><td colspan='3'><b>Parser timing</b></td></tr>";
Please login to merge, or discard this patch.
manager/includes/extenders/deprecated.functions.inc.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     function getUserData() {
41 41
         $client['ip'] = $_SERVER['REMOTE_ADDR'];
42 42
         $client['ua'] = $_SERVER['HTTP_USER_AGENT'];
43
-    	return $client;
43
+        return $client;
44 44
     }
45 45
     
46 46
     # Returns true, install or interact when inside manager
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
 
61 61
     // deprecated
62 62
     function putChunk($chunkName) { // alias name >.<
63
-    	global $modx;
63
+        global $modx;
64 64
         return $modx->getChunk($chunkName);
65 65
     }
66 66
 
67 67
     function getDocGroups() {
68
-    	global $modx;
68
+        global $modx;
69 69
         return $modx->getUserDocGroups();
70 70
     } // deprecated
71 71
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     } // deprecated
75 75
     
76 76
     function userLoggedIn() {
77
-    	global $modx;
77
+        global $modx;
78 78
         $userdetails= array ();
79 79
         if ($modx->isFrontend() && isset ($_SESSION['webValidated'])) {
80 80
             // web user
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     
99 99
     function getFormVars($method= "", $prefix= "", $trim= "", $REQUEST_METHOD) {
100 100
         //  function to retrieve form results into an associative array
101
-    	global $modx;
101
+        global $modx;
102 102
         $results= array ();
103 103
         $method= strtoupper($method);
104 104
         if ($method == "")
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      * @param string $url URL to redirect to
131 131
      */
132 132
     function webAlert($msg, $url= "") {
133
-    	global $modx;
133
+        global $modx;
134 134
         $msg= addslashes($modx->db->escape($msg));
135 135
         if (substr(strtolower($url), 0, 11) == "javascript:") {
136 136
             $act= "__WebAlert();";
Please login to merge, or discard this patch.
manager/includes/extenders/dbapi.mysqli.class.inc.php 1 patch
Indentation   +349 added lines, -349 removed lines patch added patch discarded remove patch
@@ -1,104 +1,104 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class DBAPI {
3
-	var $conn;
4
-	var $config;
5
-	var $lastQuery;
6
-	var $isConnected;
3
+    var $conn;
4
+    var $config;
5
+    var $lastQuery;
6
+    var $isConnected;
7 7
 
8
-	function __construct($host='', $dbase='', $uid='', $pwd='', $pre=NULL, $charset='', $connection_method='SET CHARACTER SET') {
9
-		$this->config['host'] = $host ? $host : $GLOBALS['database_server'];
10
-		$this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase'];
11
-		$this->config['user'] = $uid ? $uid : $GLOBALS['database_user'];
12
-		$this->config['pass'] = $pwd ? $pwd : $GLOBALS['database_password'];
13
-		$this->config['charset'] = $charset ? $charset : $GLOBALS['database_connection_charset'];
14
-		$this->config['connection_method'] =  $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method);
15
-		$this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix'];
16
-	}
8
+    function __construct($host='', $dbase='', $uid='', $pwd='', $pre=NULL, $charset='', $connection_method='SET CHARACTER SET') {
9
+        $this->config['host'] = $host ? $host : $GLOBALS['database_server'];
10
+        $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase'];
11
+        $this->config['user'] = $uid ? $uid : $GLOBALS['database_user'];
12
+        $this->config['pass'] = $pwd ? $pwd : $GLOBALS['database_password'];
13
+        $this->config['charset'] = $charset ? $charset : $GLOBALS['database_connection_charset'];
14
+        $this->config['connection_method'] =  $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method);
15
+        $this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix'];
16
+    }
17 17
 
18
-	function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0) {
19
-		global $modx;
20
-		$uid     = $uid   ? $uid   : $this->config['user'];
21
-		$pwd     = $pwd   ? $pwd   : $this->config['pass'];
22
-		$host    = $host  ? $host  : $this->config['host'];
23
-		$dbase   = $dbase ? $dbase : $this->config['dbase'];
24
-		$dbase   = trim($dbase, '`'); // remove the `` chars
25
-		$charset = $this->config['charset'];
26
-		$connection_method = $this->config['connection_method'];
27
-		$tstart = $modx->getMicroTime();
28
-		$safe_count = 0;
29
-		do {
30
-			$this->conn = new mysqli($host, $uid, $pwd, $dbase);
31
-			if ($this->conn->connect_error) {
32
-				$this->conn = null;
33
-				if (isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0') {
34
-					if ($modx->config['send_errormail'] <= 2) {
35
-						$logtitle    = 'Failed to create the database connection!';
36
-						$request_uri = $modx->htmlspecialchars($_SERVER['REQUEST_URI']);
37
-						$ua          = $modx->htmlspecialchars($_SERVER['HTTP_USER_AGENT']);
38
-						$referer     = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']);
39
-						$modx->sendmail(array(
40
-							'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'],
41
-							'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}",
42
-							'type' => 'text'
43
-						));
44
-					}
45
-				}
46
-				sleep(1);
47
-				$safe_count++;
48
-			}
49
-		} while (!$this->conn && $safe_count<3);
50
-		if (!$this->conn) {
51
-			$modx->messageQuit("Failed to create the database connection!");
52
-			exit;
53
-		} else {
54
-			$this->conn->query("{$connection_method} {$charset}");
55
-			$tend = $modx->getMicroTime();
56
-			$totaltime = $tend - $tstart;
57
-			if ($modx->dumpSQL) {
58
-				$modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>" . sprintf("Database connection was created in %2.4f s", $totaltime) . "</fieldset><br />";
59
-			}
60
-			$this->conn->set_charset($this->config['charset']);
61
-			$this->isConnected = true;
62
-			$modx->queryTime += $totaltime;
63
-		}
64
-	}
18
+    function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0) {
19
+        global $modx;
20
+        $uid     = $uid   ? $uid   : $this->config['user'];
21
+        $pwd     = $pwd   ? $pwd   : $this->config['pass'];
22
+        $host    = $host  ? $host  : $this->config['host'];
23
+        $dbase   = $dbase ? $dbase : $this->config['dbase'];
24
+        $dbase   = trim($dbase, '`'); // remove the `` chars
25
+        $charset = $this->config['charset'];
26
+        $connection_method = $this->config['connection_method'];
27
+        $tstart = $modx->getMicroTime();
28
+        $safe_count = 0;
29
+        do {
30
+            $this->conn = new mysqli($host, $uid, $pwd, $dbase);
31
+            if ($this->conn->connect_error) {
32
+                $this->conn = null;
33
+                if (isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0') {
34
+                    if ($modx->config['send_errormail'] <= 2) {
35
+                        $logtitle    = 'Failed to create the database connection!';
36
+                        $request_uri = $modx->htmlspecialchars($_SERVER['REQUEST_URI']);
37
+                        $ua          = $modx->htmlspecialchars($_SERVER['HTTP_USER_AGENT']);
38
+                        $referer     = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']);
39
+                        $modx->sendmail(array(
40
+                            'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'],
41
+                            'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}",
42
+                            'type' => 'text'
43
+                        ));
44
+                    }
45
+                }
46
+                sleep(1);
47
+                $safe_count++;
48
+            }
49
+        } while (!$this->conn && $safe_count<3);
50
+        if (!$this->conn) {
51
+            $modx->messageQuit("Failed to create the database connection!");
52
+            exit;
53
+        } else {
54
+            $this->conn->query("{$connection_method} {$charset}");
55
+            $tend = $modx->getMicroTime();
56
+            $totaltime = $tend - $tstart;
57
+            if ($modx->dumpSQL) {
58
+                $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>" . sprintf("Database connection was created in %2.4f s", $totaltime) . "</fieldset><br />";
59
+            }
60
+            $this->conn->set_charset($this->config['charset']);
61
+            $this->isConnected = true;
62
+            $modx->queryTime += $totaltime;
63
+        }
64
+    }
65 65
 
66
-	function disconnect() {
67
-		$this->conn->close();
68
-		$this->conn = null;
69
-		$this->isConnected = false;
70
-	}
66
+    function disconnect() {
67
+        $this->conn->close();
68
+        $this->conn = null;
69
+        $this->isConnected = false;
70
+    }
71 71
 
72
-	function escape($s, $safecount=0) {
73
-		$safecount++;
74
-		if (1000<$safecount) exit("Too many loops '{$safecount}'");
75
-		if (empty ($this->conn) || !is_object($this->conn)) {
76
-			$this->connect();
77
-		}
78
-		if (is_array($s)) {
79
-			if (count($s) === 0) {
80
-				$s = '';
81
-			} else {
82
-				foreach ($s as $i=>$v) {
83
-					$s[$i] = $this->escape($v, $safecount);
84
-				}
85
-			}
86
-		} else {
87
-			$s = $this->conn->escape_string($s);
88
-		}
89
-		return $s;
90
-	}
72
+    function escape($s, $safecount=0) {
73
+        $safecount++;
74
+        if (1000<$safecount) exit("Too many loops '{$safecount}'");
75
+        if (empty ($this->conn) || !is_object($this->conn)) {
76
+            $this->connect();
77
+        }
78
+        if (is_array($s)) {
79
+            if (count($s) === 0) {
80
+                $s = '';
81
+            } else {
82
+                foreach ($s as $i=>$v) {
83
+                    $s[$i] = $this->escape($v, $safecount);
84
+                }
85
+            }
86
+        } else {
87
+            $s = $this->conn->escape_string($s);
88
+        }
89
+        return $s;
90
+    }
91 91
 
92
-	function query($sql,$watchError=true) {
93
-		global $modx;
94
-		if (empty ($this->conn) || !is_object($this->conn)) {
95
-			$this->connect();
96
-		}
97
-		$tstart = $modx->getMicroTime();
98
-		if(is_array($sql)) $sql = join("\n", $sql);
99
-		$this->lastQuery = $sql;
100
-		if (!($result = $this->conn->query($sql))) {
101
-			if(!$watchError) return;
92
+    function query($sql,$watchError=true) {
93
+        global $modx;
94
+        if (empty ($this->conn) || !is_object($this->conn)) {
95
+            $this->connect();
96
+        }
97
+        $tstart = $modx->getMicroTime();
98
+        if(is_array($sql)) $sql = join("\n", $sql);
99
+        $this->lastQuery = $sql;
100
+        if (!($result = $this->conn->query($sql))) {
101
+            if(!$watchError) return;
102 102
             switch(mysqli_errno($this->conn)) {
103 103
                 case 1054:
104 104
                 case 1060:
@@ -109,119 +109,119 @@  discard block
 block discarded – undo
109 109
                 default:
110 110
                     $modx->messageQuit('Execution of a query to the database failed - ' . $this->getLastError(), $sql);
111 111
             }
112
-		} else {
113
-			$tend = $modx->getMicroTime();
114
-			$totaltime = $tend - $tstart;
115
-			$modx->queryTime = $modx->queryTime + $totaltime;
116
-			if ($modx->dumpSQL) {
117
-				$debug = debug_backtrace();
118
-				array_shift($debug);
119
-				$debug_path = array();
120
-				foreach ($debug as $line) $debug_path[] = $line['function'];
121
-				$debug_path = implode(' > ', array_reverse($debug_path));
122
-				$modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", $totaltime*1000) . "</legend>";
123
-				$modx->queryCode .= $sql . '<br><br>';
124
-				if ($modx->event->name) $modx->queryCode .= 'Current Event  => ' . $modx->event->name . '<br>';
125
-				if ($modx->event->activePlugin) $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>';
126
-				if ($modx->currentSnippet) $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>';
127
-				if (stripos($sql, 'select')===0) $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>';
128
-				else $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>';
129
-				$modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>';
130
-				$modx->queryCode .= "</fieldset><br />";
131
-			}
132
-			$modx->executedQueries = $modx->executedQueries + 1;
133
-			return $result;
134
-		}
135
-	}
112
+        } else {
113
+            $tend = $modx->getMicroTime();
114
+            $totaltime = $tend - $tstart;
115
+            $modx->queryTime = $modx->queryTime + $totaltime;
116
+            if ($modx->dumpSQL) {
117
+                $debug = debug_backtrace();
118
+                array_shift($debug);
119
+                $debug_path = array();
120
+                foreach ($debug as $line) $debug_path[] = $line['function'];
121
+                $debug_path = implode(' > ', array_reverse($debug_path));
122
+                $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", $totaltime*1000) . "</legend>";
123
+                $modx->queryCode .= $sql . '<br><br>';
124
+                if ($modx->event->name) $modx->queryCode .= 'Current Event  => ' . $modx->event->name . '<br>';
125
+                if ($modx->event->activePlugin) $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>';
126
+                if ($modx->currentSnippet) $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>';
127
+                if (stripos($sql, 'select')===0) $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>';
128
+                else $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>';
129
+                $modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>';
130
+                $modx->queryCode .= "</fieldset><br />";
131
+            }
132
+            $modx->executedQueries = $modx->executedQueries + 1;
133
+            return $result;
134
+        }
135
+    }
136 136
 
137
-	function delete($from, $where='', $orderby='', $limit = '') {
138
-		global $modx;
139
-		if (!$from) {
140
-			$modx->messageQuit("Empty \$from parameters in DBAPI::delete().");
141
-		} else {
142
-			$from = $this->replaceFullTableName($from);
143
-			$where   = trim($where);
144
-			$orderby = trim($orderby);
145
-			$limit   = trim($limit);
146
-			if($where!==''    && stripos($where,  'WHERE')!==0)    $where   = "WHERE {$where}";
147
-			if($orderby!== '' && stripos($orderby,'ORDER BY')!==0) $orderby = "ORDER BY {$orderby}";
148
-			if($limit!== ''   && stripos($limit,  'LIMIT')!==0)    $limit   = "LIMIT {$limit}";
149
-			return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}");
150
-		}
151
-	}
137
+    function delete($from, $where='', $orderby='', $limit = '') {
138
+        global $modx;
139
+        if (!$from) {
140
+            $modx->messageQuit("Empty \$from parameters in DBAPI::delete().");
141
+        } else {
142
+            $from = $this->replaceFullTableName($from);
143
+            $where   = trim($where);
144
+            $orderby = trim($orderby);
145
+            $limit   = trim($limit);
146
+            if($where!==''    && stripos($where,  'WHERE')!==0)    $where   = "WHERE {$where}";
147
+            if($orderby!== '' && stripos($orderby,'ORDER BY')!==0) $orderby = "ORDER BY {$orderby}";
148
+            if($limit!== ''   && stripos($limit,  'LIMIT')!==0)    $limit   = "LIMIT {$limit}";
149
+            return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}");
150
+        }
151
+    }
152 152
 
153
-	function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") {
154
-		global $modx;
153
+    function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") {
154
+        global $modx;
155 155
 		
156
-		if(is_array($fields)) $fields = $this->_getFieldsStringFromArray($fields);
157
-		if(is_array($from))   $from   = $this->_getFromStringFromArray($from);
158
-		if(is_array($where))  $where  = join(' ', $where);
156
+        if(is_array($fields)) $fields = $this->_getFieldsStringFromArray($fields);
157
+        if(is_array($from))   $from   = $this->_getFromStringFromArray($from);
158
+        if(is_array($where))  $where  = join(' ', $where);
159 159
 		
160
-		if (!$from) {
161
-			$modx->messageQuit("Empty \$from parameters in DBAPI::select().");
162
-			exit;
163
-		}
160
+        if (!$from) {
161
+            $modx->messageQuit("Empty \$from parameters in DBAPI::select().");
162
+            exit;
163
+        }
164 164
 		
165
-		$fields = $this->replaceFullTableName($fields);
166
-		$from = $this->replaceFullTableName($from);
165
+        $fields = $this->replaceFullTableName($fields);
166
+        $from = $this->replaceFullTableName($from);
167 167
         $where   = trim($where);
168 168
         $orderby = trim($orderby);
169 169
         $limit   = trim($limit);
170 170
         if($where!==''   && stripos($where,'WHERE')!==0)   $where   = "WHERE {$where}";
171 171
         if($orderby!=='' && stripos($orderby,'ORDER')!==0) $orderby = "ORDER BY {$orderby}";
172 172
         if($limit!==''   && stripos($limit,'LIMIT')!==0)   $limit   = "LIMIT {$limit}";
173
-		return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}");
174
-	}
173
+        return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}");
174
+    }
175 175
 
176
-	function update($fields, $table, $where = "") {
177
-		global $modx;
178
-		if (!$table) {
179
-			$modx->messageQuit("Empty \$table parameter in DBAPI::update().");
180
-		} else {
181
-			$table = $this->replaceFullTableName($table);
182
-			if (is_array($fields)) {
183
-				foreach ($fields as $key => $value) {
184
-					if(is_null($value) || strtolower($value) === 'null'){
185
-						$flds = 'NULL';
186
-					}else{
187
-						$flds = "'" . $value . "'";
188
-					}
189
-					$fields[$key] = "`{$key}` = ".$flds;
190
-				}
191
-				$fields = implode(",", $fields);
192
-			}
193
-			$where = trim($where);
194
-			if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
195
-			return $this->query("UPDATE {$table} SET {$fields} {$where}");
196
-		}
197
-	}
176
+    function update($fields, $table, $where = "") {
177
+        global $modx;
178
+        if (!$table) {
179
+            $modx->messageQuit("Empty \$table parameter in DBAPI::update().");
180
+        } else {
181
+            $table = $this->replaceFullTableName($table);
182
+            if (is_array($fields)) {
183
+                foreach ($fields as $key => $value) {
184
+                    if(is_null($value) || strtolower($value) === 'null'){
185
+                        $flds = 'NULL';
186
+                    }else{
187
+                        $flds = "'" . $value . "'";
188
+                    }
189
+                    $fields[$key] = "`{$key}` = ".$flds;
190
+                }
191
+                $fields = implode(",", $fields);
192
+            }
193
+            $where = trim($where);
194
+            if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
195
+            return $this->query("UPDATE {$table} SET {$fields} {$where}");
196
+        }
197
+    }
198 198
 
199
-	function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") {
200
-		global $modx;
201
-		if (!$intotable) {
202
-			$modx->messageQuit("Empty \$intotable parameters in DBAPI::insert().");
203
-		} else {
204
-			$intotable = $this->replaceFullTableName($intotable);
205
-			if (!is_array($fields)) {
206
-				$this->query("INSERT INTO {$intotable} {$fields}");
207
-			} else {
208
-				if (empty($fromtable)) {
209
-					$fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", array_values($fields))."')";
210
-					$rt = $this->query("INSERT INTO {$intotable} {$fields}");
211
-				} else {
212
-					$fromtable = $this->replaceFullTableName($fromtable);
213
-					$fields = "(".implode(",", array_keys($fields)).")";
214
-					$where = trim($where);
215
-					$limit = trim($limit);
216
-					if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
217
-					if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}";
218
-					$rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}");
219
-				}
220
-			}
221
-			if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!");
222
-			return $lid;
223
-		}
224
-	}
199
+    function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") {
200
+        global $modx;
201
+        if (!$intotable) {
202
+            $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert().");
203
+        } else {
204
+            $intotable = $this->replaceFullTableName($intotable);
205
+            if (!is_array($fields)) {
206
+                $this->query("INSERT INTO {$intotable} {$fields}");
207
+            } else {
208
+                if (empty($fromtable)) {
209
+                    $fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", array_values($fields))."')";
210
+                    $rt = $this->query("INSERT INTO {$intotable} {$fields}");
211
+                } else {
212
+                    $fromtable = $this->replaceFullTableName($fromtable);
213
+                    $fields = "(".implode(",", array_keys($fields)).")";
214
+                    $where = trim($where);
215
+                    $limit = trim($limit);
216
+                    if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
217
+                    if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}";
218
+                    $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}");
219
+                }
220
+            }
221
+            if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!");
222
+            return $lid;
223
+        }
224
+    }
225 225
 
226 226
     function save($fields, $table, $where='') { // This is similar to "replace into table".
227 227
         
@@ -233,182 +233,182 @@  discard block
 block discarded – undo
233 233
         else                 return $this->update($fields, $table, $where);
234 234
     }
235 235
     
236
-	function isResult($rs) {
237
-		return is_object($rs);
238
-	}
236
+    function isResult($rs) {
237
+        return is_object($rs);
238
+    }
239 239
 
240
-	function freeResult($rs) {
241
-		$rs->free_result();
242
-	}
240
+    function freeResult($rs) {
241
+        $rs->free_result();
242
+    }
243 243
 
244
-	function numFields($rs) {
245
-		return $rs->field_count;
246
-	}
244
+    function numFields($rs) {
245
+        return $rs->field_count;
246
+    }
247 247
 
248
-	function fieldName($rs,$col=0) {
249
-		$field = $rs->fetch_field_direct($col);
250
-		return $field->name;
251
-	}
248
+    function fieldName($rs,$col=0) {
249
+        $field = $rs->fetch_field_direct($col);
250
+        return $field->name;
251
+    }
252 252
 
253
-	function selectDb($name) {
254
-		$this->conn->select_db($name);
255
-	}
253
+    function selectDb($name) {
254
+        $this->conn->select_db($name);
255
+    }
256 256
 
257 257
 
258
-	function getInsertId($conn=NULL) {
259
-		if (!is_object($conn)) $conn =& $this->conn;
260
-		return $conn->insert_id;
261
-	}
258
+    function getInsertId($conn=NULL) {
259
+        if (!is_object($conn)) $conn =& $this->conn;
260
+        return $conn->insert_id;
261
+    }
262 262
 
263
-	function getAffectedRows($conn=NULL) {
264
-		if (!is_object($conn)) $conn =& $this->conn;
265
-		return $conn->affected_rows;
266
-	}
263
+    function getAffectedRows($conn=NULL) {
264
+        if (!is_object($conn)) $conn =& $this->conn;
265
+        return $conn->affected_rows;
266
+    }
267 267
 
268
-	function getLastError($conn=NULL) {
269
-		if (!is_object($conn)) $conn =& $this->conn;
270
-		return $conn->error;
271
-	}
268
+    function getLastError($conn=NULL) {
269
+        if (!is_object($conn)) $conn =& $this->conn;
270
+        return $conn->error;
271
+    }
272 272
 
273
-	function getRecordCount($ds) {
274
-		return (is_object($ds)) ? $ds->num_rows : 0;
275
-	}
273
+    function getRecordCount($ds) {
274
+        return (is_object($ds)) ? $ds->num_rows : 0;
275
+    }
276 276
 
277
-	function getRow($ds, $mode = 'assoc') {
278
-		if (is_object($ds)) {
279
-			if ($mode == 'assoc') {
280
-				return $ds->fetch_assoc();
281
-			} elseif ($mode == 'num') {
282
-				return $ds->fetch_row();
283
-			} elseif ($mode == 'object') {
284
-				return $ds->fetch_object();
285
-			} elseif ($mode == 'both') {
286
-				return $ds->fetch_array(MYSQLI_BOTH);
287
-			} else {
288
-				global $modx;
289
-				$modx->messageQuit("Unknown get type ($mode) specified for fetchRow - must be empty, 'assoc', 'num' or 'both'.");
290
-			}
291
-		}
292
-	}
277
+    function getRow($ds, $mode = 'assoc') {
278
+        if (is_object($ds)) {
279
+            if ($mode == 'assoc') {
280
+                return $ds->fetch_assoc();
281
+            } elseif ($mode == 'num') {
282
+                return $ds->fetch_row();
283
+            } elseif ($mode == 'object') {
284
+                return $ds->fetch_object();
285
+            } elseif ($mode == 'both') {
286
+                return $ds->fetch_array(MYSQLI_BOTH);
287
+            } else {
288
+                global $modx;
289
+                $modx->messageQuit("Unknown get type ($mode) specified for fetchRow - must be empty, 'assoc', 'num' or 'both'.");
290
+            }
291
+        }
292
+    }
293 293
 
294
-	function getColumn($name, $dsq) {
295
-		if (!is_object($dsq)) {
296
-			$dsq = $this->query($dsq);
297
-		}
298
-		if ($dsq) {
299
-			$col = array ();
300
-			while ($row = $this->getRow($dsq)) {
301
-				$col[] = $row[$name];
302
-			}
303
-			return $col;
304
-		}
305
-	}
294
+    function getColumn($name, $dsq) {
295
+        if (!is_object($dsq)) {
296
+            $dsq = $this->query($dsq);
297
+        }
298
+        if ($dsq) {
299
+            $col = array ();
300
+            while ($row = $this->getRow($dsq)) {
301
+                $col[] = $row[$name];
302
+            }
303
+            return $col;
304
+        }
305
+    }
306 306
 
307
-	function getColumnNames($dsq) {
308
-		if (!is_object($dsq)) {
309
-			$dsq = $this->query($dsq);
310
-		}
311
-		if ($dsq) {
312
-			$names = array ();
313
-			$limit = $this->numFields($dsq);
314
-			for ($i = 0; $i < $limit; $i++) {
315
-				$names[] = $this->fieldName($dsq, $i);
316
-			}
317
-			return $names;
318
-		}
319
-	}
307
+    function getColumnNames($dsq) {
308
+        if (!is_object($dsq)) {
309
+            $dsq = $this->query($dsq);
310
+        }
311
+        if ($dsq) {
312
+            $names = array ();
313
+            $limit = $this->numFields($dsq);
314
+            for ($i = 0; $i < $limit; $i++) {
315
+                $names[] = $this->fieldName($dsq, $i);
316
+            }
317
+            return $names;
318
+        }
319
+    }
320 320
 
321
-	function getValue($dsq) {
322
-		if (!is_object($dsq)) {
323
-			$dsq = $this->query($dsq);
324
-		}
325
-		if ($dsq) {
326
-			$r = $this->getRow($dsq, "num");
327
-			return $r[0];
328
-		}
329
-	}
321
+    function getValue($dsq) {
322
+        if (!is_object($dsq)) {
323
+            $dsq = $this->query($dsq);
324
+        }
325
+        if ($dsq) {
326
+            $r = $this->getRow($dsq, "num");
327
+            return $r[0];
328
+        }
329
+    }
330 330
 
331
-	function getTableMetaData($table) {
332
-		$metadata = false;
333
-		if (!empty ($table)) {
334
-			$sql = "SHOW FIELDS FROM $table";
335
-			if ($ds = $this->query($sql)) {
336
-				while ($row = $this->getRow($ds)) {
337
-					$fieldName = $row['Field'];
338
-					$metadata[$fieldName] = $row;
339
-				}
340
-			}
341
-		}
342
-		return $metadata;
343
-	}
331
+    function getTableMetaData($table) {
332
+        $metadata = false;
333
+        if (!empty ($table)) {
334
+            $sql = "SHOW FIELDS FROM $table";
335
+            if ($ds = $this->query($sql)) {
336
+                while ($row = $this->getRow($ds)) {
337
+                    $fieldName = $row['Field'];
338
+                    $metadata[$fieldName] = $row;
339
+                }
340
+            }
341
+        }
342
+        return $metadata;
343
+    }
344 344
 
345
-	function prepareDate($timestamp, $fieldType = 'DATETIME') {
346
-		$date = '';
347
-		if (!$timestamp === false && $timestamp > 0) {
348
-			switch ($fieldType) {
349
-				case 'DATE' :
350
-					$date = date('Y-m-d', $timestamp);
351
-					break;
352
-				case 'TIME' :
353
-					$date = date('H:i:s', $timestamp);
354
-					break;
355
-				case 'YEAR' :
356
-					$date = date('Y', $timestamp);
357
-					break;
358
-				default :
359
-					$date = date('Y-m-d H:i:s', $timestamp);
360
-					break;
361
-			}
362
-		}
363
-		return $date;
364
-	}
345
+    function prepareDate($timestamp, $fieldType = 'DATETIME') {
346
+        $date = '';
347
+        if (!$timestamp === false && $timestamp > 0) {
348
+            switch ($fieldType) {
349
+                case 'DATE' :
350
+                    $date = date('Y-m-d', $timestamp);
351
+                    break;
352
+                case 'TIME' :
353
+                    $date = date('H:i:s', $timestamp);
354
+                    break;
355
+                case 'YEAR' :
356
+                    $date = date('Y', $timestamp);
357
+                    break;
358
+                default :
359
+                    $date = date('Y-m-d H:i:s', $timestamp);
360
+                    break;
361
+            }
362
+        }
363
+        return $date;
364
+    }
365 365
 
366
-	function makeArray($rs='',$index=false){
367
-		if (!$rs) return false;
368
-		$rsArray = array();
369
-		$iterator = 0;
370
-		while ($row = $this->getRow($rs)) {
371
-			$returnIndex = $index !== false && isset($row[$index]) ? $row[$index] : $iterator; 
372
-			$rsArray[$returnIndex] = $row;
373
-			$iterator++;
374
-		}
375
-		return $rsArray;
376
-	}
366
+    function makeArray($rs='',$index=false){
367
+        if (!$rs) return false;
368
+        $rsArray = array();
369
+        $iterator = 0;
370
+        while ($row = $this->getRow($rs)) {
371
+            $returnIndex = $index !== false && isset($row[$index]) ? $row[$index] : $iterator; 
372
+            $rsArray[$returnIndex] = $row;
373
+            $iterator++;
374
+        }
375
+        return $rsArray;
376
+    }
377 377
 
378
-	function getVersion() {
379
-		return $this->conn->server_info;
380
-	}
378
+    function getVersion() {
379
+        return $this->conn->server_info;
380
+    }
381 381
 
382
-	function replaceFullTableName($str,$force=null) {
383
-		$str = trim($str);
384
-		$dbase  = trim($this->config['dbase'],'`');
385
-		$prefix = $this->config['table_prefix'];
386
-		if (!empty($force)) {
387
-			$result = "`{$dbase}`.`{$prefix}{$str}`";
388
-		} elseif (strpos($str,'[+prefix+]')!==false) {
389
-			$result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $str);
390
-		} else {
391
-			$result = $str;
392
-		}
393
-		return $result;
394
-	}
382
+    function replaceFullTableName($str,$force=null) {
383
+        $str = trim($str);
384
+        $dbase  = trim($this->config['dbase'],'`');
385
+        $prefix = $this->config['table_prefix'];
386
+        if (!empty($force)) {
387
+            $result = "`{$dbase}`.`{$prefix}{$str}`";
388
+        } elseif (strpos($str,'[+prefix+]')!==false) {
389
+            $result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $str);
390
+        } else {
391
+            $result = $str;
392
+        }
393
+        return $result;
394
+    }
395 395
 
396
-	function optimize($table_name) {
397
-		$rs = $this->query("OPTIMIZE TABLE {$table_name}");
398
-		if ($rs) {
399
-			$rs = $this->query("ALTER TABLE {$table_name}");
400
-		}
401
-		return $rs;
402
-	}
396
+    function optimize($table_name) {
397
+        $rs = $this->query("OPTIMIZE TABLE {$table_name}");
398
+        if ($rs) {
399
+            $rs = $this->query("ALTER TABLE {$table_name}");
400
+        }
401
+        return $rs;
402
+    }
403 403
 
404
-	function truncate($table_name) {
405
-		$rs = $this->query("TRUNCATE {$table_name}");
406
-		return $rs;
407
-	}
404
+    function truncate($table_name) {
405
+        $rs = $this->query("TRUNCATE {$table_name}");
406
+        return $rs;
407
+    }
408 408
 
409
-	function dataSeek($result, $row_number) {
410
-		return $result->data_seek($row_number);
411
-	}
409
+    function dataSeek($result, $row_number) {
410
+        return $result->data_seek($row_number);
411
+    }
412 412
 	
413 413
     function _getFieldsStringFromArray($fields=array()) {
414 414
         
Please login to merge, or discard this patch.
manager/includes/extenders/dbapi.mysql.class.inc.php 1 patch
Indentation   +496 added lines, -496 removed lines patch added patch discarded remove patch
@@ -7,187 +7,187 @@  discard block
 block discarded – undo
7 7
 
8 8
 class DBAPI {
9 9
 
10
-   var $conn;
11
-   var $config;
12
-   var $lastQuery;
13
-   var $isConnected;
10
+    var $conn;
11
+    var $config;
12
+    var $lastQuery;
13
+    var $isConnected;
14 14
 
15
-   /**
16
-    * @name:  DBAPI
17
-    *
18
-    */
19
-   function __construct($host='',$dbase='', $uid='',$pwd='',$pre=NULL,$charset='',$connection_method='SET CHARACTER SET') {
20
-      $this->config['host'] = $host ? $host : $GLOBALS['database_server'];
21
-      $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase'];
22
-      $this->config['user'] = $uid ? $uid : $GLOBALS['database_user'];
23
-      $this->config['pass'] = $pwd ? $pwd : $GLOBALS['database_password'];
24
-      $this->config['charset'] = $charset ? $charset : $GLOBALS['database_connection_charset'];
25
-      $this->config['connection_method'] =  $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method);
26
-      $this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix'];
27
-      $this->initDataTypes();
28
-   }
15
+    /**
16
+     * @name:  DBAPI
17
+     *
18
+     */
19
+    function __construct($host='',$dbase='', $uid='',$pwd='',$pre=NULL,$charset='',$connection_method='SET CHARACTER SET') {
20
+        $this->config['host'] = $host ? $host : $GLOBALS['database_server'];
21
+        $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase'];
22
+        $this->config['user'] = $uid ? $uid : $GLOBALS['database_user'];
23
+        $this->config['pass'] = $pwd ? $pwd : $GLOBALS['database_password'];
24
+        $this->config['charset'] = $charset ? $charset : $GLOBALS['database_connection_charset'];
25
+        $this->config['connection_method'] =  $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method);
26
+        $this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix'];
27
+        $this->initDataTypes();
28
+    }
29 29
 
30
-   /**
31
-    * @name:  initDataTypes
32
-    * @desc:  called in the constructor to set up arrays containing the types
33
-    *         of database fields that can be used with specific PHP types
34
-    */
35
-   function initDataTypes() {
36
-      $this->dataTypes['numeric'] = array (
37
-         'INT',
38
-         'INTEGER',
39
-         'TINYINT',
40
-         'BOOLEAN',
41
-         'DECIMAL',
42
-         'DEC',
43
-         'NUMERIC',
44
-         'FLOAT',
45
-         'DOUBLE PRECISION',
46
-         'REAL',
47
-         'SMALLINT',
48
-         'MEDIUMINT',
49
-         'BIGINT',
50
-         'BIT'
51
-      );
52
-      $this->dataTypes['string'] = array (
53
-         'CHAR',
54
-         'VARCHAR',
55
-         'BINARY',
56
-         'VARBINARY',
57
-         'TINYBLOB',
58
-         'BLOB',
59
-         'MEDIUMBLOB',
60
-         'LONGBLOB',
61
-         'TINYTEXT',
62
-         'TEXT',
63
-         'MEDIUMTEXT',
64
-         'LONGTEXT',
65
-         'ENUM',
66
-         'SET'
67
-      );
68
-      $this->dataTypes['date'] = array (
69
-         'DATE',
70
-         'DATETIME',
71
-         'TIMESTAMP',
72
-         'TIME',
73
-         'YEAR'
74
-      );
75
-   }
30
+    /**
31
+     * @name:  initDataTypes
32
+     * @desc:  called in the constructor to set up arrays containing the types
33
+     *         of database fields that can be used with specific PHP types
34
+     */
35
+    function initDataTypes() {
36
+        $this->dataTypes['numeric'] = array (
37
+            'INT',
38
+            'INTEGER',
39
+            'TINYINT',
40
+            'BOOLEAN',
41
+            'DECIMAL',
42
+            'DEC',
43
+            'NUMERIC',
44
+            'FLOAT',
45
+            'DOUBLE PRECISION',
46
+            'REAL',
47
+            'SMALLINT',
48
+            'MEDIUMINT',
49
+            'BIGINT',
50
+            'BIT'
51
+        );
52
+        $this->dataTypes['string'] = array (
53
+            'CHAR',
54
+            'VARCHAR',
55
+            'BINARY',
56
+            'VARBINARY',
57
+            'TINYBLOB',
58
+            'BLOB',
59
+            'MEDIUMBLOB',
60
+            'LONGBLOB',
61
+            'TINYTEXT',
62
+            'TEXT',
63
+            'MEDIUMTEXT',
64
+            'LONGTEXT',
65
+            'ENUM',
66
+            'SET'
67
+        );
68
+        $this->dataTypes['date'] = array (
69
+            'DATE',
70
+            'DATETIME',
71
+            'TIMESTAMP',
72
+            'TIME',
73
+            'YEAR'
74
+        );
75
+    }
76 76
 
77
-   /**
78
-    * @name:  connect
79
-    *
80
-    */
81
-   function connect($host = '', $dbase = '', $uid = '', $pwd = '', $persist = 0) {
82
-      global $modx;
83
-      $uid = $uid ? $uid : $this->config['user'];
84
-      $pwd = $pwd ? $pwd : $this->config['pass'];
85
-      $host = $host ? $host : $this->config['host'];
86
-      $dbase = $dbase ? $dbase : $this->config['dbase'];
87
-      $charset = $this->config['charset'];
88
-      $connection_method = $this->config['connection_method'];
89
-      $tstart = $modx->getMicroTime();
90
-      $safe_count = 0;
91
-      while(!$this->conn && $safe_count<3)
92
-      {
93
-          if($persist!=0) $this->conn = mysql_pconnect($host, $uid, $pwd);
94
-          else            $this->conn = mysql_connect($host, $uid, $pwd, true);
77
+    /**
78
+     * @name:  connect
79
+     *
80
+     */
81
+    function connect($host = '', $dbase = '', $uid = '', $pwd = '', $persist = 0) {
82
+        global $modx;
83
+        $uid = $uid ? $uid : $this->config['user'];
84
+        $pwd = $pwd ? $pwd : $this->config['pass'];
85
+        $host = $host ? $host : $this->config['host'];
86
+        $dbase = $dbase ? $dbase : $this->config['dbase'];
87
+        $charset = $this->config['charset'];
88
+        $connection_method = $this->config['connection_method'];
89
+        $tstart = $modx->getMicroTime();
90
+        $safe_count = 0;
91
+        while(!$this->conn && $safe_count<3)
92
+        {
93
+            if($persist!=0) $this->conn = mysql_pconnect($host, $uid, $pwd);
94
+            else            $this->conn = mysql_connect($host, $uid, $pwd, true);
95 95
           
96
-          if(!$this->conn)
97
-          {
96
+            if(!$this->conn)
97
+            {
98 98
             if(isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0')
99 99
             {
100
-               if($modx->config['send_errormail'] <= 2)
101
-               {
102
-                  $logtitle    = 'Failed to create the database connection!';
103
-                  $request_uri = $modx->htmlspecialchars($_SERVER['REQUEST_URI']);
104
-                  $ua          = $modx->htmlspecialchars($_SERVER['HTTP_USER_AGENT']);
105
-                  $referer     = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']);
100
+                if($modx->config['send_errormail'] <= 2)
101
+                {
102
+                    $logtitle    = 'Failed to create the database connection!';
103
+                    $request_uri = $modx->htmlspecialchars($_SERVER['REQUEST_URI']);
104
+                    $ua          = $modx->htmlspecialchars($_SERVER['HTTP_USER_AGENT']);
105
+                    $referer     = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']);
106 106
 
107
-                  $modx->sendmail(array(
108
-					  'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'],
109
-					  'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}",
110
-					  'type' => 'text')
111
-				  );
112
-               }
107
+                    $modx->sendmail(array(
108
+                        'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'],
109
+                        'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}",
110
+                        'type' => 'text')
111
+                    );
112
+                }
113 113
             }
114 114
             sleep(1);
115 115
             $safe_count++;
116
-          }
117
-      }
118
-      if (!$this->conn) {
119
-         $modx->messageQuit("Failed to create the database connection!");
120
-         exit;
121
-      } else {
122
-         $dbase = trim($dbase,'`'); // remove the `` chars
123
-         if (!@ mysql_select_db($dbase, $this->conn)) {
116
+            }
117
+        }
118
+        if (!$this->conn) {
119
+            $modx->messageQuit("Failed to create the database connection!");
120
+            exit;
121
+        } else {
122
+            $dbase = trim($dbase,'`'); // remove the `` chars
123
+            if (!@ mysql_select_db($dbase, $this->conn)) {
124 124
             $modx->messageQuit("Failed to select the database '" . $dbase . "'!");
125 125
             exit;
126
-         }
127
-         @mysql_query("{$connection_method} {$charset}", $this->conn);
128
-         $tend = $modx->getMicroTime();
129
-         $totaltime = $tend - $tstart;
130
-         if ($modx->dumpSQL) {
126
+            }
127
+            @mysql_query("{$connection_method} {$charset}", $this->conn);
128
+            $tend = $modx->getMicroTime();
129
+            $totaltime = $tend - $tstart;
130
+            if ($modx->dumpSQL) {
131 131
             $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>" . sprintf("Database connection was created in %2.4f s", $totaltime) . "</fieldset><br />";
132
-         }
132
+            }
133 133
             if (function_exists('mysql_set_charset')) {
134 134
                 mysql_set_charset($this->config['charset']);
135 135
             } else {
136 136
                 @mysql_query("SET NAMES {$this->config['charset']}", $this->conn);
137 137
             }
138
-         $this->isConnected = true;
139
-         // FIXME (Fixed by line below):
140
-         // this->queryTime = this->queryTime + $totaltime;
141
-         $modx->queryTime += $totaltime;
142
-      }
143
-   }
138
+            $this->isConnected = true;
139
+            // FIXME (Fixed by line below):
140
+            // this->queryTime = this->queryTime + $totaltime;
141
+            $modx->queryTime += $totaltime;
142
+        }
143
+    }
144 144
 
145
-   /**
146
-    * @name:  disconnect
147
-    *
148
-    */
149
-   function disconnect() {
150
-      @ mysql_close($this->conn);
151
-      $this->conn = null;
152
-      $this->isConnected = false;
153
-   }
145
+    /**
146
+     * @name:  disconnect
147
+     *
148
+     */
149
+    function disconnect() {
150
+        @ mysql_close($this->conn);
151
+        $this->conn = null;
152
+        $this->isConnected = false;
153
+    }
154 154
 
155
-   function escape($s, $safecount=0) {
155
+    function escape($s, $safecount=0) {
156 156
       
157
-      $safecount++;
158
-      if(1000<$safecount) exit("Too many loops '{$safecount}'");
157
+        $safecount++;
158
+        if(1000<$safecount) exit("Too many loops '{$safecount}'");
159 159
       
160
-      if (empty ($this->conn) || !is_resource($this->conn)) {
161
-         $this->connect();
162
-       }
160
+        if (empty ($this->conn) || !is_resource($this->conn)) {
161
+            $this->connect();
162
+        }
163 163
        
164
-      if(is_array($s)) {
165
-          if(count($s) === 0) $s = '';
166
-          else {
167
-              foreach($s as $i=>$v) {
168
-                  $s[$i] = $this->escape($v,$safecount);
169
-              }
170
-          }
171
-      }
172
-      else $s = mysql_real_escape_string($s, $this->conn);
173
-          return $s;
174
-   }
164
+        if(is_array($s)) {
165
+            if(count($s) === 0) $s = '';
166
+            else {
167
+                foreach($s as $i=>$v) {
168
+                    $s[$i] = $this->escape($v,$safecount);
169
+                }
170
+            }
171
+        }
172
+        else $s = mysql_real_escape_string($s, $this->conn);
173
+            return $s;
174
+    }
175 175
 
176
-   /**
177
-    * @name:  query
178
-    * @desc:  Mainly for internal use.
179
-    * Developers should use select, update, insert, delete where possible
180
-    */
181
-   function query($sql,$watchError=true) {
182
-      global $modx;
183
-      if (empty ($this->conn) || !is_resource($this->conn)) {
184
-         $this->connect();
185
-      }
186
-      $tstart = $modx->getMicroTime();
187
-      if(is_array($sql)) $sql = join("\n", $sql);
188
-      $this->lastQuery = $sql;
189
-      if (!$result = @ mysql_query($sql, $this->conn)) {
190
-         if(!$watchError) return;
176
+    /**
177
+     * @name:  query
178
+     * @desc:  Mainly for internal use.
179
+     * Developers should use select, update, insert, delete where possible
180
+     */
181
+    function query($sql,$watchError=true) {
182
+        global $modx;
183
+        if (empty ($this->conn) || !is_resource($this->conn)) {
184
+            $this->connect();
185
+        }
186
+        $tstart = $modx->getMicroTime();
187
+        if(is_array($sql)) $sql = join("\n", $sql);
188
+        $this->lastQuery = $sql;
189
+        if (!$result = @ mysql_query($sql, $this->conn)) {
190
+            if(!$watchError) return;
191 191
             switch(mysql_errno()) {
192 192
                 case 1054:
193 193
                 case 1060:
@@ -198,11 +198,11 @@  discard block
 block discarded – undo
198 198
                 default:
199 199
                     $modx->messageQuit('Execution of a query to the database failed - ' . $this->getLastError(), $sql);
200 200
             }
201
-      } else {
202
-         $tend = $modx->getMicroTime();
203
-         $totaltime = $tend - $tstart;
204
-         $modx->queryTime = $modx->queryTime + $totaltime;
205
-         if ($modx->dumpSQL) {
201
+        } else {
202
+            $tend = $modx->getMicroTime();
203
+            $totaltime = $tend - $tstart;
204
+            $modx->queryTime = $modx->queryTime + $totaltime;
205
+            if ($modx->dumpSQL) {
206 206
             $debug = debug_backtrace();
207 207
             array_shift($debug);	
208 208
             $debug_path = array();
@@ -217,124 +217,124 @@  discard block
 block discarded – undo
217 217
             else $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>';
218 218
             $modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>';
219 219
             $modx->queryCode .= "</fieldset><br />";
220
-         }
221
-         $modx->executedQueries = $modx->executedQueries + 1;
222
-         return $result;
223
-      }
224
-   }
220
+            }
221
+            $modx->executedQueries = $modx->executedQueries + 1;
222
+            return $result;
223
+        }
224
+    }
225 225
 
226
-   /**
227
-    * @name:  delete
228
-    *
229
-    */
230
-   function delete($from, $where='', $orderby='', $limit = '') {
231
-      global $modx;
232
-      if (!$from)
233
-         $modx->messageQuit("Empty \$from parameters in DBAPI::delete().");
234
-      else {
235
-         $from = $this->replaceFullTableName($from);
236
-         $where   = trim($where);
237
-         $orderby = trim($orderby);
238
-         $limit   = trim($limit);
239
-         if($where!==''   && stripos($where,   'WHERE')!==0)    $where   = "WHERE {$where}";
240
-         if($orderby!=='' && stripos($orderby, 'ORDER BY')!==0) $orderby = "ORDER BY {$orderby}";
241
-         if($limit!==''   && stripos($limit,   'LIMIT')!==0)    $limit   = "LIMIT {$limit}";
242
-         return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}");
243
-      }
244
-   }
226
+    /**
227
+     * @name:  delete
228
+     *
229
+     */
230
+    function delete($from, $where='', $orderby='', $limit = '') {
231
+        global $modx;
232
+        if (!$from)
233
+            $modx->messageQuit("Empty \$from parameters in DBAPI::delete().");
234
+        else {
235
+            $from = $this->replaceFullTableName($from);
236
+            $where   = trim($where);
237
+            $orderby = trim($orderby);
238
+            $limit   = trim($limit);
239
+            if($where!==''   && stripos($where,   'WHERE')!==0)    $where   = "WHERE {$where}";
240
+            if($orderby!=='' && stripos($orderby, 'ORDER BY')!==0) $orderby = "ORDER BY {$orderby}";
241
+            if($limit!==''   && stripos($limit,   'LIMIT')!==0)    $limit   = "LIMIT {$limit}";
242
+            return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}");
243
+        }
244
+    }
245 245
 
246
-   /**
247
-    * @name:  select
248
-    *
249
-    */
250
-   function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") {
251
-      global $modx;
246
+    /**
247
+     * @name:  select
248
+     *
249
+     */
250
+    function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") {
251
+        global $modx;
252 252
       
253
-      if(is_array($fields)) $fields = $this->_getFieldsStringFromArray($fields);
254
-      if(is_array($from))   $from   = $this->_getFromStringFromArray($from);
255
-      if(is_array($where))  $where  = join(' ', $where);
253
+        if(is_array($fields)) $fields = $this->_getFieldsStringFromArray($fields);
254
+        if(is_array($from))   $from   = $this->_getFromStringFromArray($from);
255
+        if(is_array($where))  $where  = join(' ', $where);
256 256
       
257
-      if (!$from) {
258
-         $modx->messageQuit("Empty \$from parameters in DBAPI::select().");
259
-         exit;
260
-      }
257
+        if (!$from) {
258
+            $modx->messageQuit("Empty \$from parameters in DBAPI::select().");
259
+            exit;
260
+        }
261 261
       
262
-      $fields = $this->replaceFullTableName($fields);
263
-      $from = $this->replaceFullTableName($from);
264
-      $where   = trim($where);
265
-      $orderby = trim($orderby);
266
-      $limit   = trim($limit);
267
-      if($where!==''   && stripos($where,'WHERE')!==0)   $where   = "WHERE {$where}";
268
-      if($orderby!=='' && stripos($orderby,'ORDER')!==0) $orderby = "ORDER BY {$orderby}";
269
-      if($limit!==''   && stripos($limit,'LIMIT')!==0)   $limit   = "LIMIT {$limit}";
270
-      return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}");
271
-   }
262
+        $fields = $this->replaceFullTableName($fields);
263
+        $from = $this->replaceFullTableName($from);
264
+        $where   = trim($where);
265
+        $orderby = trim($orderby);
266
+        $limit   = trim($limit);
267
+        if($where!==''   && stripos($where,'WHERE')!==0)   $where   = "WHERE {$where}";
268
+        if($orderby!=='' && stripos($orderby,'ORDER')!==0) $orderby = "ORDER BY {$orderby}";
269
+        if($limit!==''   && stripos($limit,'LIMIT')!==0)   $limit   = "LIMIT {$limit}";
270
+        return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}");
271
+    }
272 272
 
273
-   /**
274
-    * @name:  update
275
-    *
276
-    */
277
-   function update($fields, $table, $where = "") {
278
-      global $modx;
279
-      if (!$table)
280
-         $modx->messageQuit("Empty \$table parameter in DBAPI::update().");
281
-      else {
282
-         $table = $this->replaceFullTableName($table);
283
-         if (is_array($fields)) {
284
-			 foreach ($fields as $key => $value) {
285
-				 if(is_null($value) || strtolower($value) === 'null'){
286
-					 $flds = 'NULL';
287
-				 }else{
288
-					 $flds = "'" . $value . "'";
289
-				 }
290
-				 $fields[$key] = "`{$key}` = ".$flds;
291
-			 }
273
+    /**
274
+     * @name:  update
275
+     *
276
+     */
277
+    function update($fields, $table, $where = "") {
278
+        global $modx;
279
+        if (!$table)
280
+            $modx->messageQuit("Empty \$table parameter in DBAPI::update().");
281
+        else {
282
+            $table = $this->replaceFullTableName($table);
283
+            if (is_array($fields)) {
284
+                foreach ($fields as $key => $value) {
285
+                    if(is_null($value) || strtolower($value) === 'null'){
286
+                        $flds = 'NULL';
287
+                    }else{
288
+                        $flds = "'" . $value . "'";
289
+                    }
290
+                    $fields[$key] = "`{$key}` = ".$flds;
291
+                }
292 292
             $fields = implode(",", $fields);
293
-         }
294
-         $where = trim($where);
295
-         if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
296
-         return $this->query("UPDATE {$table} SET {$fields} {$where}");
297
-      }
298
-   }
293
+            }
294
+            $where = trim($where);
295
+            if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
296
+            return $this->query("UPDATE {$table} SET {$fields} {$where}");
297
+        }
298
+    }
299 299
 
300
-   /**
301
-    * @name:  insert
302
-    * @desc:  returns either last id inserted or the result from the query
303
-    */
304
-   function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") {
305
-      global $modx;
306
-      if (!$intotable)
307
-         $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert().");
308
-      else {
309
-         $intotable = $this->replaceFullTableName($intotable);
310
-         if (!is_array($fields)) {
300
+    /**
301
+     * @name:  insert
302
+     * @desc:  returns either last id inserted or the result from the query
303
+     */
304
+    function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") {
305
+        global $modx;
306
+        if (!$intotable)
307
+            $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert().");
308
+        else {
309
+            $intotable = $this->replaceFullTableName($intotable);
310
+            if (!is_array($fields)) {
311 311
             $this->query("INSERT INTO {$intotable} {$fields}");
312
-         } else {
312
+            } else {
313 313
             if (empty($fromtable)) {
314
-               $fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", array_values($fields))."')";
315
-               $rt = $this->query("INSERT INTO {$intotable} {$fields}");
314
+                $fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", array_values($fields))."')";
315
+                $rt = $this->query("INSERT INTO {$intotable} {$fields}");
316 316
             } else {
317
-               if (version_compare($this->getVersion(),"4.0.14")>=0) {
318
-                  $fromtable = $this->replaceFullTableName($fromtable);
319
-                  $fields = "(".implode(",", array_keys($fields)).")";
320
-                  $where = trim($where);
321
-                  $limit = trim($limit);
322
-                  if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
323
-                  if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}";
324
-                  $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}");
325
-               } else {
326
-                  $ds = $this->select($fromfields, $fromtable, $where, '', $limit);
327
-                  while ($row = $this->getRow($ds)) {
328
-                     $fields = "(".implode(",", array_keys($fields)).") VALUES('".implode("', '", $row)."')";
329
-                     $rt = $this->query("INSERT INTO {$intotable} {$fields}");
330
-                  }
331
-               }
317
+                if (version_compare($this->getVersion(),"4.0.14")>=0) {
318
+                    $fromtable = $this->replaceFullTableName($fromtable);
319
+                    $fields = "(".implode(",", array_keys($fields)).")";
320
+                    $where = trim($where);
321
+                    $limit = trim($limit);
322
+                    if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
323
+                    if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}";
324
+                    $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}");
325
+                } else {
326
+                    $ds = $this->select($fromfields, $fromtable, $where, '', $limit);
327
+                    while ($row = $this->getRow($ds)) {
328
+                        $fields = "(".implode(",", array_keys($fields)).") VALUES('".implode("', '", $row)."')";
329
+                        $rt = $this->query("INSERT INTO {$intotable} {$fields}");
330
+                    }
331
+                }
332
+            }
332 333
             }
333
-         }
334
-         if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!");
335
-         return $lid;
336
-      }
337
-   }
334
+            if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!");
335
+            return $lid;
336
+        }
337
+    }
338 338
    
339 339
     function save($fields, $table, $where='') {
340 340
         
@@ -346,277 +346,277 @@  discard block
 block discarded – undo
346 346
         else                 return $this->update($fields, $table, $where);
347 347
     }
348 348
     
349
-   /**
350
-    * @name:  isResult
351
-    *
352
-    */
353
-   function isResult($rs) {
354
-      return is_resource($rs);
355
-   }
349
+    /**
350
+     * @name:  isResult
351
+     *
352
+     */
353
+    function isResult($rs) {
354
+        return is_resource($rs);
355
+    }
356 356
 
357
-   /**
358
-    * @name:  freeResult
359
-    *
360
-    */
361
-   function freeResult($rs) {
362
-      mysql_free_result($rs);
363
-   }
357
+    /**
358
+     * @name:  freeResult
359
+     *
360
+     */
361
+    function freeResult($rs) {
362
+        mysql_free_result($rs);
363
+    }
364 364
    
365
-   /**
366
-    * @name:  numFields
367
-    *
368
-    */
369
-   function numFields($rs) {
370
-      return mysql_num_fields($rs);
371
-   }
365
+    /**
366
+     * @name:  numFields
367
+     *
368
+     */
369
+    function numFields($rs) {
370
+        return mysql_num_fields($rs);
371
+    }
372 372
    
373
-   /**
374
-    * @name:  fieldName
375
-    *
376
-    */
377
-   function fieldName($rs,$col=0) {
378
-      return mysql_field_name($rs,$col);
379
-   }
373
+    /**
374
+     * @name:  fieldName
375
+     *
376
+     */
377
+    function fieldName($rs,$col=0) {
378
+        return mysql_field_name($rs,$col);
379
+    }
380 380
    
381 381
     /**
382
-    * @name:  selectDb
383
-    *
384
-    */
385
-   function selectDb($name) {
386
-      mysql_select_db($name);
387
-   }
382
+     * @name:  selectDb
383
+     *
384
+     */
385
+    function selectDb($name) {
386
+        mysql_select_db($name);
387
+    }
388 388
    
389 389
 
390
-   /**
391
-    * @name:  getInsertId
392
-    *
393
-    */
394
-   function getInsertId($conn=NULL) {
395
-      if( !is_resource($conn)) $conn =& $this->conn;
396
-      return mysql_insert_id($conn);
397
-   }
390
+    /**
391
+     * @name:  getInsertId
392
+     *
393
+     */
394
+    function getInsertId($conn=NULL) {
395
+        if( !is_resource($conn)) $conn =& $this->conn;
396
+        return mysql_insert_id($conn);
397
+    }
398 398
 
399
-   /**
400
-    * @name:  getAffectedRows
401
-    *
402
-    */
403
-   function getAffectedRows($conn=NULL) {
404
-      if (!is_resource($conn)) $conn =& $this->conn;
405
-      return mysql_affected_rows($conn);
406
-   }
399
+    /**
400
+     * @name:  getAffectedRows
401
+     *
402
+     */
403
+    function getAffectedRows($conn=NULL) {
404
+        if (!is_resource($conn)) $conn =& $this->conn;
405
+        return mysql_affected_rows($conn);
406
+    }
407 407
 
408
-   /**
409
-    * @name:  getLastError
410
-    *
411
-    */
412
-   function getLastError($conn=NULL) {
413
-      if (!is_resource($conn)) $conn =& $this->conn;
414
-      return mysql_error($conn);
415
-   }
408
+    /**
409
+     * @name:  getLastError
410
+     *
411
+     */
412
+    function getLastError($conn=NULL) {
413
+        if (!is_resource($conn)) $conn =& $this->conn;
414
+        return mysql_error($conn);
415
+    }
416 416
 
417
-   /**
418
-    * @name:  getRecordCount
419
-    *
420
-    */
421
-   function getRecordCount($ds) {
422
-      return (is_resource($ds)) ? mysql_num_rows($ds) : 0;
423
-   }
417
+    /**
418
+     * @name:  getRecordCount
419
+     *
420
+     */
421
+    function getRecordCount($ds) {
422
+        return (is_resource($ds)) ? mysql_num_rows($ds) : 0;
423
+    }
424 424
 
425
-   /**
426
-    * @name:  getRow
427
-    * @desc:  returns an array of column values
428
-    * @param: $dsq - dataset
429
-    *
430
-    */
431
-   function getRow($ds, $mode = 'assoc') {
432
-      if (is_resource($ds)) {
433
-         if ($mode == 'assoc') {
425
+    /**
426
+     * @name:  getRow
427
+     * @desc:  returns an array of column values
428
+     * @param: $dsq - dataset
429
+     *
430
+     */
431
+    function getRow($ds, $mode = 'assoc') {
432
+        if (is_resource($ds)) {
433
+            if ($mode == 'assoc') {
434 434
             return mysql_fetch_assoc($ds);
435
-         }
436
-         elseif ($mode == 'num') {
435
+            }
436
+            elseif ($mode == 'num') {
437 437
             return mysql_fetch_row($ds);
438
-         }
439
-		 elseif ($mode == 'object') {
438
+            }
439
+            elseif ($mode == 'object') {
440 440
             return mysql_fetch_object($ds);
441
-         }
442
-         elseif ($mode == 'both') {
441
+            }
442
+            elseif ($mode == 'both') {
443 443
             return mysql_fetch_array($ds, MYSQL_BOTH);
444
-         } else {
444
+            } else {
445 445
             global $modx;
446 446
             $modx->messageQuit("Unknown get type ($mode) specified for fetchRow - must be empty, 'assoc', 'num' or 'both'.");
447
-         }
448
-      }
449
-   }
447
+            }
448
+        }
449
+    }
450 450
 
451
-   /**
452
-    * @name:  getColumn
453
-    * @desc:  returns an array of the values found on colun $name
454
-    * @param: $dsq - dataset or query string
455
-    */
456
-   function getColumn($name, $dsq) {
457
-      if (!is_resource($dsq))
458
-         $dsq = $this->query($dsq);
459
-      if ($dsq) {
460
-         $col = array ();
461
-         while ($row = $this->getRow($dsq)) {
451
+    /**
452
+     * @name:  getColumn
453
+     * @desc:  returns an array of the values found on colun $name
454
+     * @param: $dsq - dataset or query string
455
+     */
456
+    function getColumn($name, $dsq) {
457
+        if (!is_resource($dsq))
458
+            $dsq = $this->query($dsq);
459
+        if ($dsq) {
460
+            $col = array ();
461
+            while ($row = $this->getRow($dsq)) {
462 462
             $col[] = $row[$name];
463
-         }
464
-         return $col;
465
-      }
466
-   }
463
+            }
464
+            return $col;
465
+        }
466
+    }
467 467
 
468
-   /**
469
-    * @name:  getColumnNames
470
-    * @desc:  returns an array containing the column $name
471
-    * @param: $dsq - dataset or query string
472
-    */
473
-   function getColumnNames($dsq) {
474
-      if (!is_resource($dsq))
475
-         $dsq = $this->query($dsq);
476
-      if ($dsq) {
477
-         $names = array ();
478
-         $limit = mysql_num_fields($dsq);
479
-         for ($i = 0; $i < $limit; $i++) {
468
+    /**
469
+     * @name:  getColumnNames
470
+     * @desc:  returns an array containing the column $name
471
+     * @param: $dsq - dataset or query string
472
+     */
473
+    function getColumnNames($dsq) {
474
+        if (!is_resource($dsq))
475
+            $dsq = $this->query($dsq);
476
+        if ($dsq) {
477
+            $names = array ();
478
+            $limit = mysql_num_fields($dsq);
479
+            for ($i = 0; $i < $limit; $i++) {
480 480
             $names[] = mysql_field_name($dsq, $i);
481
-         }
482
-         return $names;
483
-      }
484
-   }
481
+            }
482
+            return $names;
483
+        }
484
+    }
485 485
 
486
-   /**
487
-    * @name:  getValue
488
-    * @desc:  returns the value from the first column in the set
489
-    * @param: $dsq - dataset or query string
490
-    */
491
-   function getValue($dsq) {
492
-      if (!is_resource($dsq))
493
-         $dsq = $this->query($dsq);
494
-      if ($dsq) {
495
-         $r = $this->getRow($dsq, "num");
496
-         return $r[0];
497
-      }
498
-   }
486
+    /**
487
+     * @name:  getValue
488
+     * @desc:  returns the value from the first column in the set
489
+     * @param: $dsq - dataset or query string
490
+     */
491
+    function getValue($dsq) {
492
+        if (!is_resource($dsq))
493
+            $dsq = $this->query($dsq);
494
+        if ($dsq) {
495
+            $r = $this->getRow($dsq, "num");
496
+            return $r[0];
497
+        }
498
+    }
499 499
 
500
-   /**
501
-    * @name:  getTableMetaData
502
-    * @desc:  returns an array of MySQL structure detail for each column of a
503
-    *         table
504
-    * @param: $table: the full name of the database table
505
-    */
506
-   function getTableMetaData($table) {
507
-      $metadata = false;
508
-      if (!empty ($table)) {
509
-         $sql = "SHOW FIELDS FROM $table";
510
-         if ($ds = $this->query($sql)) {
500
+    /**
501
+     * @name:  getTableMetaData
502
+     * @desc:  returns an array of MySQL structure detail for each column of a
503
+     *         table
504
+     * @param: $table: the full name of the database table
505
+     */
506
+    function getTableMetaData($table) {
507
+        $metadata = false;
508
+        if (!empty ($table)) {
509
+            $sql = "SHOW FIELDS FROM $table";
510
+            if ($ds = $this->query($sql)) {
511 511
             while ($row = $this->getRow($ds)) {
512
-               $fieldName = $row['Field'];
513
-               $metadata[$fieldName] = $row;
512
+                $fieldName = $row['Field'];
513
+                $metadata[$fieldName] = $row;
514
+            }
514 515
             }
515
-         }
516
-      }
517
-      return $metadata;
518
-   }
516
+        }
517
+        return $metadata;
518
+    }
519 519
 
520
-   /**
521
-    * @name:  prepareDate
522
-    * @desc:  prepares a date in the proper format for specific database types
523
-    *         given a UNIX timestamp
524
-    * @param: $timestamp: a UNIX timestamp
525
-    * @param: $fieldType: the type of field to format the date for
526
-    *         (in MySQL, you have DATE, TIME, YEAR, and DATETIME)
527
-    */
528
-   function prepareDate($timestamp, $fieldType = 'DATETIME') {
529
-      $date = '';
530
-      if (!$timestamp === false && $timestamp > 0) {
531
-         switch ($fieldType) {
520
+    /**
521
+     * @name:  prepareDate
522
+     * @desc:  prepares a date in the proper format for specific database types
523
+     *         given a UNIX timestamp
524
+     * @param: $timestamp: a UNIX timestamp
525
+     * @param: $fieldType: the type of field to format the date for
526
+     *         (in MySQL, you have DATE, TIME, YEAR, and DATETIME)
527
+     */
528
+    function prepareDate($timestamp, $fieldType = 'DATETIME') {
529
+        $date = '';
530
+        if (!$timestamp === false && $timestamp > 0) {
531
+            switch ($fieldType) {
532 532
             case 'DATE' :
533 533
                $date = date('Y-m-d', $timestamp);
534
-               break;
534
+                break;
535 535
             case 'TIME' :
536 536
                $date = date('H:i:s', $timestamp);
537
-               break;
537
+                break;
538 538
             case 'YEAR' :
539 539
                $date = date('Y', $timestamp);
540
-               break;
540
+                break;
541 541
             default :
542 542
                $date = date('Y-m-d H:i:s', $timestamp);
543
-               break;
544
-         }
545
-      }
546
-      return $date;
547
-   }
543
+                break;
544
+            }
545
+        }
546
+        return $date;
547
+    }
548 548
 
549
-   /**
550
-   * @name:  makeArray
551
-   * @desc:  turns a recordset into a multidimensional array
552
-   * @return: an array of row arrays from recordset, or empty array
553
-   *          if the recordset was empty, returns false if no recordset
554
-   *          was passed
555
-   * @param: $rs Recordset to be packaged into an array
556
-   */
557
-	function makeArray($rs='',$index=false){
558
-		if (!$rs) return false;
559
-		$rsArray = array();
560
-		$iterator = 0;
561
-		while ($row = $this->getRow($rs)) {
562
-			$returnIndex = $index !== false && isset($row[$index]) ? $row[$index] : $iterator;
563
-			$rsArray[$returnIndex] = $row;
564
-			$iterator++;
565
-		}
566
-		return $rsArray;
567
-	}
549
+    /**
550
+     * @name:  makeArray
551
+     * @desc:  turns a recordset into a multidimensional array
552
+     * @return: an array of row arrays from recordset, or empty array
553
+     *          if the recordset was empty, returns false if no recordset
554
+     *          was passed
555
+     * @param: $rs Recordset to be packaged into an array
556
+     */
557
+    function makeArray($rs='',$index=false){
558
+        if (!$rs) return false;
559
+        $rsArray = array();
560
+        $iterator = 0;
561
+        while ($row = $this->getRow($rs)) {
562
+            $returnIndex = $index !== false && isset($row[$index]) ? $row[$index] : $iterator;
563
+            $rsArray[$returnIndex] = $row;
564
+            $iterator++;
565
+        }
566
+        return $rsArray;
567
+    }
568 568
    
569
-   /**
570
-    * @name	getVersion
571
-    * @desc	returns a string containing the database server version
572
-    *
573
-    * @return string
574
-    */
575
-   function getVersion() {
576
-       return mysql_get_server_info();
577
-   }
569
+    /**
570
+     * @name	getVersion
571
+     * @desc	returns a string containing the database server version
572
+     *
573
+     * @return string
574
+     */
575
+    function getVersion() {
576
+        return mysql_get_server_info();
577
+    }
578 578
    
579
-   /**
580
-    * @name replaceFullTableName
581
-    * @desc  Get full table name. Append table name and table prefix.
582
-    * 
583
-    * @param string $str
584
-    * @return string 
585
-    */
586
-   function replaceFullTableName($str,$force=null) {
579
+    /**
580
+     * @name replaceFullTableName
581
+     * @desc  Get full table name. Append table name and table prefix.
582
+     * 
583
+     * @param string $str
584
+     * @return string 
585
+     */
586
+    function replaceFullTableName($str,$force=null) {
587 587
        
588
-       $str = trim($str);
589
-       $dbase  = trim($this->config['dbase'],'`');
590
-       $prefix = $this->config['table_prefix'];
591
-       if(!empty($force))
592
-       {
593
-           $result = "`{$dbase}`.`{$prefix}{$str}`";
594
-       }
595
-       elseif(strpos($str,'[+prefix+]')!==false)
596
-       {
597
-           $result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $str);
598
-       }
599
-       else $result = $str;
588
+        $str = trim($str);
589
+        $dbase  = trim($this->config['dbase'],'`');
590
+        $prefix = $this->config['table_prefix'];
591
+        if(!empty($force))
592
+        {
593
+            $result = "`{$dbase}`.`{$prefix}{$str}`";
594
+        }
595
+        elseif(strpos($str,'[+prefix+]')!==false)
596
+        {
597
+            $result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $str);
598
+        }
599
+        else $result = $str;
600 600
        
601
-       return $result;
602
-   }
601
+        return $result;
602
+    }
603 603
    
604
-   function optimize($table_name)
605
-   {
606
-       $rs = $this->query("OPTIMIZE TABLE {$table_name}");
607
-       if($rs) $rs = $this->query("ALTER TABLE {$table_name}");
608
-       return $rs;
609
-   }
604
+    function optimize($table_name)
605
+    {
606
+        $rs = $this->query("OPTIMIZE TABLE {$table_name}");
607
+        if($rs) $rs = $this->query("ALTER TABLE {$table_name}");
608
+        return $rs;
609
+    }
610 610
    
611
-   function truncate($table_name)
612
-   {
613
-       $rs = $this->query("TRUNCATE {$table_name}");
614
-       return $rs;
615
-   }
611
+    function truncate($table_name)
612
+    {
613
+        $rs = $this->query("TRUNCATE {$table_name}");
614
+        return $rs;
615
+    }
616 616
 
617
-  function dataSeek($result, $row_number) {
617
+    function dataSeek($result, $row_number) {
618 618
     return mysql_data_seek($result, $row_number);
619
-  }
619
+    }
620 620
   
621 621
     function _getFieldsStringFromArray($fields=array()) {
622 622
         
Please login to merge, or discard this patch.
manager/includes/extenders/export.class.inc.php 1 patch
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -1,258 +1,258 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class EXPORT_SITE
3 3
 {
4
-	var $targetDir;
5
-	var $generate_mode;
6
-	var $total;
7
-	var $count;
8
-	var $ignore_ids;
9
-	var $exportstart;
10
-	var $repl_before;
11
-	var $repl_after;
12
-	var $output = array();
4
+    var $targetDir;
5
+    var $generate_mode;
6
+    var $total;
7
+    var $count;
8
+    var $ignore_ids;
9
+    var $exportstart;
10
+    var $repl_before;
11
+    var $repl_after;
12
+    var $output = array();
13 13
 	
14
-	function __construct()
15
-	{
16
-		global $modx;
14
+    function __construct()
15
+    {
16
+        global $modx;
17 17
 		
18
-		if(!defined('MODX_BASE_PATH'))  return false;
19
-		$this->exportstart = $this->get_mtime();
20
-		$this->count = 0;
21
-		$this->setUrlMode();
22
-		$this->dirCheckCount = 0;
23
-		$this->generate_mode = 'crawl';
24
-		$this->targetDir = $modx->config['base_path'] . 'temp/export';
25
-		if(!isset($this->total)) $this->getTotal();
26
-	}
18
+        if(!defined('MODX_BASE_PATH'))  return false;
19
+        $this->exportstart = $this->get_mtime();
20
+        $this->count = 0;
21
+        $this->setUrlMode();
22
+        $this->dirCheckCount = 0;
23
+        $this->generate_mode = 'crawl';
24
+        $this->targetDir = $modx->config['base_path'] . 'temp/export';
25
+        if(!isset($this->total)) $this->getTotal();
26
+    }
27 27
 	
28
-	function setExportDir($dir)
29
-	{
30
-		$dir = str_replace('\\','/',$dir);
31
-		$dir = rtrim($dir, '/');
32
-		$this->targetDir = $dir;
33
-	}
28
+    function setExportDir($dir)
29
+    {
30
+        $dir = str_replace('\\','/',$dir);
31
+        $dir = rtrim($dir, '/');
32
+        $this->targetDir = $dir;
33
+    }
34 34
 	
35
-	function get_mtime()
36
-	{
37
-		$mtime = microtime();
38
-		$mtime = explode(' ', $mtime);
39
-		$mtime = $mtime[1] + $mtime[0];
40
-		return $mtime;
41
-	}
35
+    function get_mtime()
36
+    {
37
+        $mtime = microtime();
38
+        $mtime = explode(' ', $mtime);
39
+        $mtime = $mtime[1] + $mtime[0];
40
+        return $mtime;
41
+    }
42 42
 	
43
-	function setUrlMode()
44
-	{
45
-		global $modx;
43
+    function setUrlMode()
44
+    {
45
+        global $modx;
46 46
 		
47
-		if($modx->config['friendly_urls']==0)
48
-		{
49
-			$modx->config['friendly_urls']  = 1;
50
-			$modx->config['use_alias_path'] = 1;
51
-			$modx->clearCache('full');
52
-		}
53
-		$modx->config['make_folders'] = '1';
54
-	}
47
+        if($modx->config['friendly_urls']==0)
48
+        {
49
+            $modx->config['friendly_urls']  = 1;
50
+            $modx->config['use_alias_path'] = 1;
51
+            $modx->clearCache('full');
52
+        }
53
+        $modx->config['make_folders'] = '1';
54
+    }
55 55
 	
56
-	function getTotal($ignore_ids='', $noncache='0')
57
-	{
58
-		global $modx;
59
-		$tbl_site_content = $modx->getFullTableName('site_content');
56
+    function getTotal($ignore_ids='', $noncache='0')
57
+    {
58
+        global $modx;
59
+        $tbl_site_content = $modx->getFullTableName('site_content');
60 60
 		
61
-		$ignore_ids = array_filter(array_map('intval', explode(',', $ignore_ids)));
62
-		if(count($ignore_ids)>0)
63
-		{
64
-			$ignore_ids = "AND NOT id IN ('".implode("','", $ignore_ids)."')";
65
-		} else {
66
-			$ignore_ids = '';
67
-		}
61
+        $ignore_ids = array_filter(array_map('intval', explode(',', $ignore_ids)));
62
+        if(count($ignore_ids)>0)
63
+        {
64
+            $ignore_ids = "AND NOT id IN ('".implode("','", $ignore_ids)."')";
65
+        } else {
66
+            $ignore_ids = '';
67
+        }
68 68
 		
69
-		$this->ignore_ids = $ignore_ids;
69
+        $this->ignore_ids = $ignore_ids;
70 70
 		
71
-		$noncache = ($noncache == 1) ? '' : 'AND cacheable=1';
72
-		$where = "deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}";
73
-		$rs  = $modx->db->select('count(id)',$tbl_site_content,$where);
74
-		$this->total = $modx->db->getValue($rs);
75
-		return $this->total;
76
-	}
71
+        $noncache = ($noncache == 1) ? '' : 'AND cacheable=1';
72
+        $where = "deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}";
73
+        $rs  = $modx->db->select('count(id)',$tbl_site_content,$where);
74
+        $this->total = $modx->db->getValue($rs);
75
+        return $this->total;
76
+    }
77 77
 	
78
-	function removeDirectoryAll($directory='')
79
-	{
80
-		if(empty($directory)) $directory = $this->targetDir;
81
-		$directory = rtrim($directory,'/');
82
-		// if the path is not valid or is not a directory ...
83
-		if(empty($directory)) return false;
84
-		if(strpos($directory,MODX_BASE_PATH)===false) return FALSE;
78
+    function removeDirectoryAll($directory='')
79
+    {
80
+        if(empty($directory)) $directory = $this->targetDir;
81
+        $directory = rtrim($directory,'/');
82
+        // if the path is not valid or is not a directory ...
83
+        if(empty($directory)) return false;
84
+        if(strpos($directory,MODX_BASE_PATH)===false) return FALSE;
85 85
 		
86
-		if(!is_dir($directory))          return FALSE;
87
-		elseif(!is_readable($directory)) return FALSE;
88
-		else
89
-		{
90
-			$files = glob($directory . '/*');
91
-			if(!empty($files))
92
-			{
93
-    			foreach($files as $path)
94
-    			{
95
-    				if(is_dir($path)) $this->removeDirectoryAll($path);
96
-    				else              $rs = unlink($path);
97
-    			}
98
-			}
99
-		}
100
-		if($directory !== $this->targetDir) $rs = rmdir($directory);
86
+        if(!is_dir($directory))          return FALSE;
87
+        elseif(!is_readable($directory)) return FALSE;
88
+        else
89
+        {
90
+            $files = glob($directory . '/*');
91
+            if(!empty($files))
92
+            {
93
+                foreach($files as $path)
94
+                {
95
+                    if(is_dir($path)) $this->removeDirectoryAll($path);
96
+                    else              $rs = unlink($path);
97
+                }
98
+            }
99
+        }
100
+        if($directory !== $this->targetDir) $rs = rmdir($directory);
101 101
 		
102
-		return $rs;
103
-	}
102
+        return $rs;
103
+    }
104 104
 
105
-	function makeFile($docid, $filepath)
106
-	{
107
-		global  $modx,$_lang;
108
-		$file_permission = octdec($modx->config['new_file_permissions']);
109
-		if($this->generate_mode==='direct')
110
-		{
111
-			$back_lang = $_lang;
112
-			$src = $modx->executeParser($docid);
105
+    function makeFile($docid, $filepath)
106
+    {
107
+        global  $modx,$_lang;
108
+        $file_permission = octdec($modx->config['new_file_permissions']);
109
+        if($this->generate_mode==='direct')
110
+        {
111
+            $back_lang = $_lang;
112
+            $src = $modx->executeParser($docid);
113 113
 			
114
-			$_lang = $back_lang;
115
-		}
116
-		else $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}");
114
+            $_lang = $back_lang;
115
+        }
116
+        else $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}");
117 117
 		
118 118
 		
119
-		if($src !== false)
120
-		{
121
-			if($this->repl_before!==$this->repl_after) $src = str_replace($this->repl_before,$this->repl_after,$src);
122
-			$result = file_put_contents($filepath,$src);
123
-			if($result!==false) @chmod($filepath, $file_permission);
119
+        if($src !== false)
120
+        {
121
+            if($this->repl_before!==$this->repl_after) $src = str_replace($this->repl_before,$this->repl_after,$src);
122
+            $result = file_put_contents($filepath,$src);
123
+            if($result!==false) @chmod($filepath, $file_permission);
124 124
 			
125
-			if($result !== false) return 'success';
126
-			else                  return 'failed_no_write';
127
-		}
128
-		else                      return 'failed_no_retrieve';
129
-	}
125
+            if($result !== false) return 'success';
126
+            else                  return 'failed_no_write';
127
+        }
128
+        else                      return 'failed_no_retrieve';
129
+    }
130 130
 
131
-	function getFileName($docid, $alias='', $prefix, $suffix)
132
-	{
133
-		global $modx;
131
+    function getFileName($docid, $alias='', $prefix, $suffix)
132
+    {
133
+        global $modx;
134 134
 		
135
-		if($alias==='') $filename = $prefix.$docid.$suffix;
136
-		else
137
-		{
138
-			if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false)
139
-			{
140
-				$suffix = '';
141
-			}
142
-			$filename = $prefix.$alias.$suffix;
143
-		}
144
-		return $filename;
145
-	}
135
+        if($alias==='') $filename = $prefix.$docid.$suffix;
136
+        else
137
+        {
138
+            if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false)
139
+            {
140
+                $suffix = '';
141
+            }
142
+            $filename = $prefix.$alias.$suffix;
143
+        }
144
+        return $filename;
145
+    }
146 146
 
147
-	function run($parent=0)
148
-	{
149
-		global $_lang;
150
-		global $modx;
147
+    function run($parent=0)
148
+    {
149
+        global $_lang;
150
+        global $modx;
151 151
 		
152
-		$tbl_site_content = $modx->getFullTableName('site_content');
152
+        $tbl_site_content = $modx->getFullTableName('site_content');
153 153
 		
154
-		$ignore_ids = $this->ignore_ids;
155
-		$dirpath = $this->targetDir . '/';
154
+        $ignore_ids = $this->ignore_ids;
155
+        $dirpath = $this->targetDir . '/';
156 156
 		
157
-		$prefix = $modx->config['friendly_url_prefix'];
158
-		$suffix = $modx->config['friendly_url_suffix'];
157
+        $prefix = $modx->config['friendly_url_prefix'];
158
+        $suffix = $modx->config['friendly_url_suffix'];
159 159
 		
160
-		$tpl = ' <span class="[+status+]">[+msg1+]</span> [+msg2+]</span>';
161
-		$ph = array();
160
+        $tpl = ' <span class="[+status+]">[+msg1+]</span> [+msg2+]</span>';
161
+        $ph = array();
162 162
 		
163
-		$ph['status'] = 'fail';
164
-		$ph['msg1']   = $_lang['export_site_failed'];
165
-		$ph['msg2']   = $_lang["export_site_failed_no_write"] . ' - ' . $dirpath;
166
-		$msg_failed_no_write    = $this->parsePlaceholder($tpl,$ph);
163
+        $ph['status'] = 'fail';
164
+        $ph['msg1']   = $_lang['export_site_failed'];
165
+        $ph['msg2']   = $_lang["export_site_failed_no_write"] . ' - ' . $dirpath;
166
+        $msg_failed_no_write    = $this->parsePlaceholder($tpl,$ph);
167 167
 		
168
-		$ph['msg2']   = $_lang["export_site_failed_no_retrieve"];
169
-		$msg_failed_no_retrieve = $this->parsePlaceholder($tpl,$ph);
168
+        $ph['msg2']   = $_lang["export_site_failed_no_retrieve"];
169
+        $msg_failed_no_retrieve = $this->parsePlaceholder($tpl,$ph);
170 170
 		
171
-		$ph['status'] = 'success';
172
-		$ph['msg1']   = $_lang['export_site_success'];
173
-		$ph['msg2']   = '';
174
-		$msg_success            = $this->parsePlaceholder($tpl,$ph);
171
+        $ph['status'] = 'success';
172
+        $ph['msg1']   = $_lang['export_site_success'];
173
+        $ph['msg2']   = '';
174
+        $msg_success            = $this->parsePlaceholder($tpl,$ph);
175 175
 		
176
-		$ph['msg2']   = $_lang['export_site_success_skip_doc'];
177
-		$msg_success_skip_doc = $this->parsePlaceholder($tpl,$ph);
176
+        $ph['msg2']   = $_lang['export_site_success_skip_doc'];
177
+        $msg_success_skip_doc = $this->parsePlaceholder($tpl,$ph);
178 178
 		
179
-		$ph['msg2']   = $_lang['export_site_success_skip_dir'];
180
-		$msg_success_skip_dir = $this->parsePlaceholder($tpl,$ph);
179
+        $ph['msg2']   = $_lang['export_site_success_skip_dir'];
180
+        $msg_success_skip_dir = $this->parsePlaceholder($tpl,$ph);
181 181
 		
182
-		$fields = "id, alias, pagetitle, isfolder, (content = '' AND template = 0) AS wasNull, published";
183
-		$noncache = $_POST['includenoncache']==1 ? '' : 'AND cacheable=1';
184
-		$where = "parent = '{$parent}' AND deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}";
185
-		$rs = $modx->db->select($fields,$tbl_site_content,$where);
182
+        $fields = "id, alias, pagetitle, isfolder, (content = '' AND template = 0) AS wasNull, published";
183
+        $noncache = $_POST['includenoncache']==1 ? '' : 'AND cacheable=1';
184
+        $where = "parent = '{$parent}' AND deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}";
185
+        $rs = $modx->db->select($fields,$tbl_site_content,$where);
186 186
 		
187
-		$ph = array();
188
-		$ph['total']     = $this->total;
189
-		$folder_permission = octdec($modx->config['new_folder_permissions']);
190
-		while($row = $modx->db->getRow($rs))
191
-		{
192
-			$this->count++;
187
+        $ph = array();
188
+        $ph['total']     = $this->total;
189
+        $folder_permission = octdec($modx->config['new_folder_permissions']);
190
+        while($row = $modx->db->getRow($rs))
191
+        {
192
+            $this->count++;
193 193
 			
194
-			$row['count']     = $this->count;
195
-			$row['url'] = $modx->makeUrl($row['id']);
194
+            $row['count']     = $this->count;
195
+            $row['url'] = $modx->makeUrl($row['id']);
196 196
 			
197
-			if (!$row['wasNull'])
198
-			{ // needs writing a document
199
-				$docname = $this->getFileName($row['id'], $row['alias'], $prefix, $suffix);
200
-				$filename = $dirpath.$docname;
201
-				if (!is_file($filename))
202
-				{
203
-					if($row['published']==='1')
204
-					{
205
-						$status = $this->makeFile($row['id'], $filename);
206
-						switch($status)
207
-						{
208
-							case 'failed_no_write'   :
197
+            if (!$row['wasNull'])
198
+            { // needs writing a document
199
+                $docname = $this->getFileName($row['id'], $row['alias'], $prefix, $suffix);
200
+                $filename = $dirpath.$docname;
201
+                if (!is_file($filename))
202
+                {
203
+                    if($row['published']==='1')
204
+                    {
205
+                        $status = $this->makeFile($row['id'], $filename);
206
+                        switch($status)
207
+                        {
208
+                            case 'failed_no_write'   :
209 209
                                                             $row['status'] = $msg_failed_no_write;
210 210
                                                             break;
211
-							case 'failed_no_retrieve':
211
+                            case 'failed_no_retrieve':
212 212
                                                             $row['status'] = $msg_failed_no_retrieve;
213 213
                                                             break;
214
-							default:
214
+                            default:
215 215
                                                             $row['status'] = $msg_success;
216
-						}
217
-					}
218
-					else $row['status'] = $msg_failed_no_retrieve;
219
-				}
220
-				else     $row['status'] = $msg_success_skip_doc;
221
-				$this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row);
222
-			}
223
-			else
224
-			{
225
-				$row['status'] = $msg_success_skip_dir;
226
-				$this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row);
227
-			}
228
-			if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false))
229
-			{ // needs making a folder
230
-				$end_dir = ($row['alias']!=='') ? $row['alias'] : $row['id'];
231
-				$dir_path = $dirpath . $end_dir;
232
-				if(strpos($dir_path,MODX_BASE_PATH)===false) return FALSE;
233
-				if (!is_dir($dir_path))
234
-				{
235
-					if (is_file($dir_path)) @unlink($dir_path);
236
-					mkdir($dir_path);
237
-					@chmod($dir_path, $folder_permission);
216
+                        }
217
+                    }
218
+                    else $row['status'] = $msg_failed_no_retrieve;
219
+                }
220
+                else     $row['status'] = $msg_success_skip_doc;
221
+                $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row);
222
+            }
223
+            else
224
+            {
225
+                $row['status'] = $msg_success_skip_dir;
226
+                $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row);
227
+            }
228
+            if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false))
229
+            { // needs making a folder
230
+                $end_dir = ($row['alias']!=='') ? $row['alias'] : $row['id'];
231
+                $dir_path = $dirpath . $end_dir;
232
+                if(strpos($dir_path,MODX_BASE_PATH)===false) return FALSE;
233
+                if (!is_dir($dir_path))
234
+                {
235
+                    if (is_file($dir_path)) @unlink($dir_path);
236
+                    mkdir($dir_path);
237
+                    @chmod($dir_path, $folder_permission);
238 238
 					
239
-				}
239
+                }
240 240
 				
241 241
 				
242
-				if($modx->config['make_folders']==='1' && $row['published']==='1')
243
-				{
244
-					if(is_file($filename)) rename($filename,$dir_path . '/index.html');
245
-				}
246
-				$this->targetDir = $dir_path;
247
-				$this->run($row['id']);
248
-			}
249
-		}
250
-		return implode("\n", $this->output);
251
-	}
242
+                if($modx->config['make_folders']==='1' && $row['published']==='1')
243
+                {
244
+                    if(is_file($filename)) rename($filename,$dir_path . '/index.html');
245
+                }
246
+                $this->targetDir = $dir_path;
247
+                $this->run($row['id']);
248
+            }
249
+        }
250
+        return implode("\n", $this->output);
251
+    }
252 252
 	
253 253
     function curl_get_contents($url, $timeout = 30 )
254 254
     {
255
-    	if(!function_exists('curl_init')) return @file_get_contents($url);
255
+        if(!function_exists('curl_init')) return @file_get_contents($url);
256 256
 
257 257
         $ch = curl_init();
258 258
         curl_setopt($ch, CURLOPT_URL, $url);
@@ -269,12 +269,12 @@  discard block
 block discarded – undo
269 269
 
270 270
     function parsePlaceholder($tpl,$ph=array())
271 271
     {
272
-    	foreach($ph as $k=>$v)
273
-    	{
274
-    		$k = "[+{$k}+]";
275
-    		$tpl = str_replace($k,$v,$tpl);
276
-    	}
277
-    	return $tpl;
272
+        foreach($ph as $k=>$v)
273
+        {
274
+            $k = "[+{$k}+]";
275
+            $tpl = str_replace($k,$v,$tpl);
276
+        }
277
+        return $tpl;
278 278
     }
279 279
 
280 280
 }
Please login to merge, or discard this patch.
manager/includes/extenders/manager.api.class.inc.php 1 patch
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -10,215 +10,215 @@
 block discarded – undo
10 10
 // Content manager wrapper class
11 11
 class ManagerAPI {
12 12
 	
13
-	var $action; // action directive
13
+    var $action; // action directive
14 14
 
15
-	function __construct(){
16
-		global $action;
17
-		$this->action = $action; // set action directive
18
-	}
15
+    function __construct(){
16
+        global $action;
17
+        $this->action = $action; // set action directive
18
+    }
19 19
 	
20
-	function initPageViewState($id=0){
21
-		global $_PAGE;
22
-		$vsid = isset($_SESSION["mgrPageViewSID"]) ? $_SESSION["mgrPageViewSID"] : '';
23
-		if($vsid!=$this->action) {
24
-			$_SESSION["mgrPageViewSDATA"] = array(); // new view state
25
-			$_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action; // set id
26
-		}
27
-		$_PAGE['vs'] = &$_SESSION["mgrPageViewSDATA"]; // restore viewstate
28
-	}
20
+    function initPageViewState($id=0){
21
+        global $_PAGE;
22
+        $vsid = isset($_SESSION["mgrPageViewSID"]) ? $_SESSION["mgrPageViewSID"] : '';
23
+        if($vsid!=$this->action) {
24
+            $_SESSION["mgrPageViewSDATA"] = array(); // new view state
25
+            $_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action; // set id
26
+        }
27
+        $_PAGE['vs'] = &$_SESSION["mgrPageViewSDATA"]; // restore viewstate
28
+    }
29 29
 
30
-	// save page view state - not really necessary,
31
-	function savePageViewState($id=0){
32
-		global $_PAGE;
33
-		$_SESSION["mgrPageViewSDATA"] = $_PAGE['vs'];
34
-		$_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action;
35
-	}
30
+    // save page view state - not really necessary,
31
+    function savePageViewState($id=0){
32
+        global $_PAGE;
33
+        $_SESSION["mgrPageViewSDATA"] = $_PAGE['vs'];
34
+        $_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action;
35
+    }
36 36
 	
37
-	// check for saved form
38
-	function hasFormValues() {
39
-		if(isset($_SESSION["mgrFormValueId"])) {		
40
-			if($this->action==$_SESSION["mgrFormValueId"]) {
41
-				return true;
42
-			}
43
-			else {
44
-				$this->clearSavedFormValues();
45
-			}
46
-		}
47
-		return false;
48
-	}	
49
-	// saved form post from $_POST
50
-	function saveFormValues($id=0){
51
-		$_SESSION["mgrFormValues"] = $_POST;
52
-		$_SESSION["mgrFormValueId"] = $id>0 ? $id:$this->action;
53
-	}		
54
-	// load saved form values into $_POST
55
-	function loadFormValues(){
37
+    // check for saved form
38
+    function hasFormValues() {
39
+        if(isset($_SESSION["mgrFormValueId"])) {		
40
+            if($this->action==$_SESSION["mgrFormValueId"]) {
41
+                return true;
42
+            }
43
+            else {
44
+                $this->clearSavedFormValues();
45
+            }
46
+        }
47
+        return false;
48
+    }	
49
+    // saved form post from $_POST
50
+    function saveFormValues($id=0){
51
+        $_SESSION["mgrFormValues"] = $_POST;
52
+        $_SESSION["mgrFormValueId"] = $id>0 ? $id:$this->action;
53
+    }		
54
+    // load saved form values into $_POST
55
+    function loadFormValues(){
56 56
 		
57
-		if(!$this->hasFormValues()) return false;
57
+        if(!$this->hasFormValues()) return false;
58 58
 		
59
-		$p = $_SESSION["mgrFormValues"];
60
-		$this->clearSavedFormValues();
61
-		foreach($p as $k=>$v) {
62
-			$_POST[$k]=$v;
63
-		}
64
-		return true;
65
-	}
66
-	// clear form post
67
-	function clearSavedFormValues(){
68
-		unset($_SESSION["mgrFormValues"]);
69
-		unset($_SESSION["mgrFormValueId"]);	
70
-	}
59
+        $p = $_SESSION["mgrFormValues"];
60
+        $this->clearSavedFormValues();
61
+        foreach($p as $k=>$v) {
62
+            $_POST[$k]=$v;
63
+        }
64
+        return true;
65
+    }
66
+    // clear form post
67
+    function clearSavedFormValues(){
68
+        unset($_SESSION["mgrFormValues"]);
69
+        unset($_SESSION["mgrFormValueId"]);	
70
+    }
71 71
 	
72
-	function getHashType($db_value='') { // md5 | v1 | phpass
73
-		$c = substr($db_value,0,1);
74
-		if($c==='$')                                      return 'phpass';
75
-		elseif(strlen($db_value)===32)                    return 'md5';
76
-		elseif($c!=='$' && strpos($db_value,'>')!==false) return 'v1';
77
-		else                                              return 'unknown';
78
-	}
72
+    function getHashType($db_value='') { // md5 | v1 | phpass
73
+        $c = substr($db_value,0,1);
74
+        if($c==='$')                                      return 'phpass';
75
+        elseif(strlen($db_value)===32)                    return 'md5';
76
+        elseif($c!=='$' && strpos($db_value,'>')!==false) return 'v1';
77
+        else                                              return 'unknown';
78
+    }
79 79
 	
80
-	function genV1Hash($password, $seed='1')
81
-	{ // $seed is user_id basically
82
-		global $modx;
80
+    function genV1Hash($password, $seed='1')
81
+    { // $seed is user_id basically
82
+        global $modx;
83 83
 		
84
-		if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo']))
85
-			$algorithm = $modx->config['pwd_hash_algo'];
86
-		else $algorithm = 'UNCRYPT';
84
+        if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo']))
85
+            $algorithm = $modx->config['pwd_hash_algo'];
86
+        else $algorithm = 'UNCRYPT';
87 87
 		
88
-		$salt = md5($password . $seed);
88
+        $salt = md5($password . $seed);
89 89
 		
90
-		switch($algorithm)
91
-		{
92
-			case 'BLOWFISH_Y':
93
-				$salt = '$2y$07$' . substr($salt,0,22);
94
-				break;
95
-			case 'BLOWFISH_A':
96
-				$salt = '$2a$07$' . substr($salt,0,22);
97
-				break;
98
-			case 'SHA512':
99
-				$salt = '$6$' . substr($salt,0,16);
100
-				break;
101
-			case 'SHA256':
102
-				$salt = '$5$' . substr($salt,0,16);
103
-				break;
104
-			case 'MD5':
105
-				$salt = '$1$' . substr($salt,0,8);
106
-				break;
107
-		}
90
+        switch($algorithm)
91
+        {
92
+            case 'BLOWFISH_Y':
93
+                $salt = '$2y$07$' . substr($salt,0,22);
94
+                break;
95
+            case 'BLOWFISH_A':
96
+                $salt = '$2a$07$' . substr($salt,0,22);
97
+                break;
98
+            case 'SHA512':
99
+                $salt = '$6$' . substr($salt,0,16);
100
+                break;
101
+            case 'SHA256':
102
+                $salt = '$5$' . substr($salt,0,16);
103
+                break;
104
+            case 'MD5':
105
+                $salt = '$1$' . substr($salt,0,8);
106
+                break;
107
+        }
108 108
 		
109
-		if($algorithm!=='UNCRYPT')
110
-		{
111
-			$password = sha1($password) . crypt($password,$salt);
112
-		}
113
-		else $password = sha1($salt.$password);
109
+        if($algorithm!=='UNCRYPT')
110
+        {
111
+            $password = sha1($password) . crypt($password,$salt);
112
+        }
113
+        else $password = sha1($salt.$password);
114 114
 		
115
-		$result = strtolower($algorithm) . '>' . md5($salt.$password) . substr(md5($salt),0,8);
115
+        $result = strtolower($algorithm) . '>' . md5($salt.$password) . substr(md5($salt),0,8);
116 116
 		
117
-		return $result;
118
-	}
117
+        return $result;
118
+    }
119 119
 	
120
-	function getV1UserHashAlgorithm($uid)
121
-	{
122
-		global $modx;
123
-		$tbl_manager_users = $modx->getFullTableName('manager_users');
124
-		$rs = $modx->db->select('password',$tbl_manager_users,"id='{$uid}'");
125
-		$password = $modx->db->getValue($rs);
120
+    function getV1UserHashAlgorithm($uid)
121
+    {
122
+        global $modx;
123
+        $tbl_manager_users = $modx->getFullTableName('manager_users');
124
+        $rs = $modx->db->select('password',$tbl_manager_users,"id='{$uid}'");
125
+        $password = $modx->db->getValue($rs);
126 126
 		
127
-		if(strpos($password,'>')===false) $algo = 'NOSALT';
128
-		else
129
-		{
130
-			$algo = substr($password,0,strpos($password,'>'));
131
-		}
132
-		return strtoupper($algo);
133
-	}
127
+        if(strpos($password,'>')===false) $algo = 'NOSALT';
128
+        else
129
+        {
130
+            $algo = substr($password,0,strpos($password,'>'));
131
+        }
132
+        return strtoupper($algo);
133
+    }
134 134
 	
135
-	function checkHashAlgorithm($algorithm='')
136
-	{
137
-		$result = false;
138
-		if (!empty($algorithm))
139
-		{
140
-			switch ($algorithm)
141
-			{
142
-				case 'BLOWFISH_Y':
143
-					if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1)
144
-					{
145
-						if (version_compare('5.3.7', PHP_VERSION) <= 0) $result = true;
146
-					}
147
-					break;
148
-				case 'BLOWFISH_A':
149
-					if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) $result = true;
150
-					break;
151
-				case 'SHA512':
152
-					if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) $result = true;
153
-					break;
154
-				case 'SHA256':
155
-					if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) $result = true;
156
-					break;
157
-				case 'MD5':
158
-					if (defined('CRYPT_MD5') && CRYPT_MD5 == 1 && PHP_VERSION != '5.3.7') $result = true;
159
-					break;
160
-				case 'UNCRYPT':
161
-					$result = true;
162
-					break;
163
-			}
164
-		}
165
-		return $result;
166
-	}
135
+    function checkHashAlgorithm($algorithm='')
136
+    {
137
+        $result = false;
138
+        if (!empty($algorithm))
139
+        {
140
+            switch ($algorithm)
141
+            {
142
+                case 'BLOWFISH_Y':
143
+                    if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1)
144
+                    {
145
+                        if (version_compare('5.3.7', PHP_VERSION) <= 0) $result = true;
146
+                    }
147
+                    break;
148
+                case 'BLOWFISH_A':
149
+                    if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) $result = true;
150
+                    break;
151
+                case 'SHA512':
152
+                    if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) $result = true;
153
+                    break;
154
+                case 'SHA256':
155
+                    if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) $result = true;
156
+                    break;
157
+                case 'MD5':
158
+                    if (defined('CRYPT_MD5') && CRYPT_MD5 == 1 && PHP_VERSION != '5.3.7') $result = true;
159
+                    break;
160
+                case 'UNCRYPT':
161
+                    $result = true;
162
+                    break;
163
+            }
164
+        }
165
+        return $result;
166
+    }
167 167
 
168
-	function getSystemChecksum($check_files) {
169
-		$_ = array();
170
-		$check_files = trim($check_files);
171
-		$check_files = explode("\n", $check_files);
172
-		foreach($check_files as $file) {
173
-			$file = trim($file);
174
-			$file = MODX_BASE_PATH . $file;
175
-			if(!is_file($file)) continue;
176
-			$_[$file]= md5_file($file);
177
-		}
178
-		return serialize($_);
179
-	}
168
+    function getSystemChecksum($check_files) {
169
+        $_ = array();
170
+        $check_files = trim($check_files);
171
+        $check_files = explode("\n", $check_files);
172
+        foreach($check_files as $file) {
173
+            $file = trim($file);
174
+            $file = MODX_BASE_PATH . $file;
175
+            if(!is_file($file)) continue;
176
+            $_[$file]= md5_file($file);
177
+        }
178
+        return serialize($_);
179
+    }
180 180
 
181
-	function getModifiedSystemFilesList($check_files, $checksum) {
182
-		$_ = array();
183
-		$check_files = trim($check_files);
184
-		$check_files = explode("\n", $check_files);
185
-		$checksum = unserialize($checksum);
186
-		foreach($check_files as $file) {
187
-			$file = trim($file);
188
-			$filePath = MODX_BASE_PATH . $file;
189
-			if(!is_file($filePath)) continue;
190
-			if(md5_file($filePath) != $checksum[$filePath]) $_[] = $file;
191
-		}
192
-		return $_;
193
-	}
181
+    function getModifiedSystemFilesList($check_files, $checksum) {
182
+        $_ = array();
183
+        $check_files = trim($check_files);
184
+        $check_files = explode("\n", $check_files);
185
+        $checksum = unserialize($checksum);
186
+        foreach($check_files as $file) {
187
+            $file = trim($file);
188
+            $filePath = MODX_BASE_PATH . $file;
189
+            if(!is_file($filePath)) continue;
190
+            if(md5_file($filePath) != $checksum[$filePath]) $_[] = $file;
191
+        }
192
+        return $_;
193
+    }
194 194
 
195
-	function setSystemChecksum($checksum) {
196
-		global $modx;
197
-		$tbl_system_settings = $modx->getFullTableName('system_settings');
198
-		$sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','" . $modx->db->escape($checksum) . "')";
195
+    function setSystemChecksum($checksum) {
196
+        global $modx;
197
+        $tbl_system_settings = $modx->getFullTableName('system_settings');
198
+        $sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','" . $modx->db->escape($checksum) . "')";
199 199
         $modx->db->query($sql);
200
-	}
200
+    }
201 201
 	
202
-	function checkSystemChecksum() {
203
-		global $modx;
202
+    function checkSystemChecksum() {
203
+        global $modx;
204 204
 
205
-		if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0';
205
+        if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0';
206 206
 		
207
-		$current = $this->getSystemChecksum($modx->config['check_files_onlogin']);
208
-		if(empty($current)) return '0';
207
+        $current = $this->getSystemChecksum($modx->config['check_files_onlogin']);
208
+        if(empty($current)) return '0';
209 209
 		
210
-		if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum']))
211
-		{
212
-			$this->setSystemChecksum($current);
213
-			return '0';
214
-		}
215
-		if($current===$modx->config['sys_files_checksum']) $result = '0';
216
-		else {
217
-			$result = $this->getModifiedSystemFilesList($modx->config['check_files_onlogin'], $modx->config['sys_files_checksum']);
218
-		} 
210
+        if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum']))
211
+        {
212
+            $this->setSystemChecksum($current);
213
+            return '0';
214
+        }
215
+        if($current===$modx->config['sys_files_checksum']) $result = '0';
216
+        else {
217
+            $result = $this->getModifiedSystemFilesList($modx->config['check_files_onlogin'], $modx->config['sys_files_checksum']);
218
+        } 
219 219
 
220
-		return $result;
221
-	}
220
+        return $result;
221
+    }
222 222
 
223 223
     function getLastUserSetting($key=false) {
224 224
         global $modx;
Please login to merge, or discard this patch.
manager/includes/extenders/phpcompat.class.inc.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -2,26 +2,26 @@
 block discarded – undo
2 2
 // todo file_put_contents(), strftime(), mb_*()
3 3
 class PHPCOMPAT
4 4
 {
5
-	function __construct()
6
-	{
7
-	}
5
+    function __construct()
6
+    {
7
+    }
8 8
 	
9
-	function htmlspecialchars($str='', $flags = ENT_COMPAT, $encode='')
10
-	{
11
-		global $modx;
9
+    function htmlspecialchars($str='', $flags = ENT_COMPAT, $encode='')
10
+    {
11
+        global $modx;
12 12
 		
13
-		if($str=='') return '';
13
+        if($str=='') return '';
14 14
 		
15
-		if($encode=='') $encode = $modx->config['modx_charset'];
15
+        if($encode=='') $encode = $modx->config['modx_charset'];
16 16
 		
17
-		$ent_str = htmlspecialchars($str, $flags, $encode);
17
+        $ent_str = htmlspecialchars($str, $flags, $encode);
18 18
 		
19
-		if(!empty($str) && empty($ent_str))
20
-		{
21
-			$detect_order = implode(',', mb_detect_order());
22
-			$ent_str = mb_convert_encoding($str, $encode, $detect_order); 
23
-		}
19
+        if(!empty($str) && empty($ent_str))
20
+        {
21
+            $detect_order = implode(',', mb_detect_order());
22
+            $ent_str = mb_convert_encoding($str, $encode, $detect_order); 
23
+        }
24 24
 		
25
-		return $ent_str;
26
-	}
25
+        return $ent_str;
26
+    }
27 27
 }
Please login to merge, or discard this patch.
manager/includes/extenders/modifiers.class.inc.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
                     else               $opt = true;
599 599
                 }
600 600
                 elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html')
601
-                                       $opt = false;
601
+                                        $opt = false;
602 602
                 else                   $opt = true;
603 603
                 return nl2br($value,$opt);
604 604
             case 'ltrim':
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
         {
1023 1023
             $bt = $content;
1024 1024
             if(strpos($content,'[*')!==false && $modx->documentIdentifier)
1025
-                                              $content = $modx->mergeDocumentContent($content);
1025
+                                                $content = $modx->mergeDocumentContent($content);
1026 1026
             if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content);
1027 1027
             if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content);
1028 1028
             if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content);
Please login to merge, or discard this patch.