Completed
Push — develop ( 5613ed...d17f77 )
by Maxim
11:03 queued 05:33
created
manager/actions/import_site.static.php 1 patch
Indentation   +333 added lines, -333 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) {
3
-	die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
3
+    die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
4 4
 }
5 5
 if(!$modx->hasPermission('import_static')) {
6
-	$modx->webAlertAndQuit($_lang["error_no_privileges"]);
6
+    $modx->webAlertAndQuit($_lang["error_no_privileges"]);
7 7
 }
8 8
 
9 9
 // Files to upload
10 10
 $allowedfiles = array(
11
-	'html',
12
-	'htm',
13
-	'shtml',
14
-	'xml'
11
+    'html',
12
+    'htm',
13
+    'shtml',
14
+    'xml'
15 15
 );
16 16
 ?>
17 17
 	<script language="javascript">
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	<div class="tab-page">
44 44
 		<div class="container container-body">
45 45
 			<?php
46
-			if(!isset($_POST['import'])) {
47
-				echo "<div class=\"element-edit-message\">" . $_lang['import_site_message'] . "</div>";
48
-				?>
46
+            if(!isset($_POST['import'])) {
47
+                echo "<div class=\"element-edit-message\">" . $_lang['import_site_message'] . "</div>";
48
+                ?>
49 49
 				<form action="index.php" method="post" name="importFrm">
50 50
 					<input type="hidden" name="import" value="import" />
51 51
 					<input type="hidden" name="a" value="95" />
@@ -85,18 +85,18 @@  discard block
 block discarded – undo
85 85
 					<a href="javascript:;" class="btn btn-primary" onclick="window.importFrm.submit();"><i class="<?= $_style["actions_save"] ?>"></i> <?= $_lang["import_site_start"] ?></a>
86 86
 				</form>
87 87
 			<?php
88
-			} else {
89
-			run();
90
-			$modx->clearCache('full');
91
-			?>
88
+            } else {
89
+            run();
90
+            $modx->clearCache('full');
91
+            ?>
92 92
 				<a href="javascript:;" class="btn btn-primary" onclick="window.location.href='index.php?a=2';"><i class="<?= $_style["actions_close"] ?>"></i> <?= $_lang["close"] ?></a>
93 93
 				<script type="text/javascript">
94 94
 					top.mainMenu.reloadtree();
95 95
 					parent.tree.ca = 'open';
96 96
 				</script>
97 97
 				<?php
98
-			}
99
-			?>
98
+            }
99
+            ?>
100 100
 		</div>
101 101
 	</div>
102 102
 
@@ -105,64 +105,64 @@  discard block
 block discarded – undo
105 105
  * @return string
106 106
  */
107 107
 function run() {
108
-	global $modx, $_lang;
108
+    global $modx, $_lang;
109 109
 
110
-	$tbl_site_content = $modx->getFullTableName('site_content');
111
-	$output = '';
112
-	$maxtime = $_POST['maxtime'];
110
+    $tbl_site_content = $modx->getFullTableName('site_content');
111
+    $output = '';
112
+    $maxtime = $_POST['maxtime'];
113 113
 
114
-	if(!is_numeric($maxtime)) {
115
-		$maxtime = 30;
116
-	}
114
+    if(!is_numeric($maxtime)) {
115
+        $maxtime = 30;
116
+    }
117 117
 
118
-	@set_time_limit($maxtime);
118
+    @set_time_limit($maxtime);
119 119
 
120
-	$mtime = microtime();
121
-	$mtime = explode(' ', $mtime);
122
-	$mtime = $mtime[1] + $mtime[0];
123
-	$importstart = $mtime;
120
+    $mtime = microtime();
121
+    $mtime = explode(' ', $mtime);
122
+    $mtime = $mtime[1] + $mtime[0];
123
+    $importstart = $mtime;
124 124
 
125
-	if($_POST['reset'] == 'on') {
126
-		$modx->db->truncate($tbl_site_content);
127
-		$modx->db->query("ALTER TABLE {$tbl_site_content} AUTO_INCREMENT = 1");
128
-	}
125
+    if($_POST['reset'] == 'on') {
126
+        $modx->db->truncate($tbl_site_content);
127
+        $modx->db->query("ALTER TABLE {$tbl_site_content} AUTO_INCREMENT = 1");
128
+    }
129 129
 
130
-	$parent = (int)$_POST['parent'];
130
+    $parent = (int)$_POST['parent'];
131 131
 
132
-	if(is_dir(MODX_BASE_PATH . 'temp/import')) {
133
-		$filedir = MODX_BASE_PATH . 'temp/import/';
134
-	} elseif(is_dir(MODX_BASE_PATH . 'assets/import')) {
135
-		$filedir = MODX_BASE_PATH . 'assets/import/';
136
-	} else {
132
+    if(is_dir(MODX_BASE_PATH . 'temp/import')) {
133
+        $filedir = MODX_BASE_PATH . 'temp/import/';
134
+    } elseif(is_dir(MODX_BASE_PATH . 'assets/import')) {
135
+        $filedir = MODX_BASE_PATH . 'assets/import/';
136
+    } else {
137 137
         $filedir = '';
138 138
     }
139 139
 
140
-	$filesfound = 0;
140
+    $filesfound = 0;
141 141
 
142
-	$files = getFiles($filedir);
143
-	$files = pop_index($files);
142
+    $files = getFiles($filedir);
143
+    $files = pop_index($files);
144 144
 
145
-	// no. of files to import
146
-	$output .= sprintf('<p>' . $_lang['import_files_found'] . '</p>', $filesfound);
145
+    // no. of files to import
146
+    $output .= sprintf('<p>' . $_lang['import_files_found'] . '</p>', $filesfound);
147 147
 
148
-	// import files
149
-	if(0 < count($files)) {
150
-		$modx->db->update(array('isfolder' => 1), $tbl_site_content, "id='{$parent}'");
151
-		importFiles($parent, $filedir, $files, 'root');
152
-	}
148
+    // import files
149
+    if(0 < count($files)) {
150
+        $modx->db->update(array('isfolder' => 1), $tbl_site_content, "id='{$parent}'");
151
+        importFiles($parent, $filedir, $files, 'root');
152
+    }
153 153
 
154
-	$mtime = microtime();
155
-	$mtime = explode(' ', $mtime);
156
-	$mtime = $mtime[1] + $mtime[0];
157
-	$importend = $mtime;
158
-	$totaltime = ($importend - $importstart);
159
-	$output .= sprintf('<p>' . $_lang['import_site_time'] . '</p>', round($totaltime, 3));
154
+    $mtime = microtime();
155
+    $mtime = explode(' ', $mtime);
156
+    $mtime = $mtime[1] + $mtime[0];
157
+    $importend = $mtime;
158
+    $totaltime = ($importend - $importstart);
159
+    $output .= sprintf('<p>' . $_lang['import_site_time'] . '</p>', round($totaltime, 3));
160 160
 
161
-	if($_POST['convert_link'] == 'on') {
162
-		convertLink();
163
-	}
161
+    if($_POST['convert_link'] == 'on') {
162
+        convertLink();
163
+    }
164 164
 
165
-	return $output;
165
+    return $output;
166 166
 }
167 167
 
168 168
 /**
@@ -172,144 +172,144 @@  discard block
 block discarded – undo
172 172
  * @param string $mode
173 173
  */
174 174
 function importFiles($parent, $filedir, $files, $mode) {
175
-	global $modx;
176
-	global $_lang, $allowedfiles;
177
-	global $search_default, $cache_default, $publish_default;
178
-
179
-	$tbl_site_content = $modx->getFullTableName('site_content');
180
-	$tbl_system_settings = $modx->getFullTableName('system_settings');
181
-
182
-	$createdby = $modx->getLoginUserID();
183
-	if(!is_array($files)) {
184
-		return;
185
-	}
186
-	if($_POST['object'] === 'all') {
187
-		$modx->config['default_template'] = '0';
188
-		$richtext = '0';
189
-	} else {
190
-		$richtext = '1';
191
-	}
192
-
193
-	foreach($files as $id => $value) {
194
-		if(is_array($value)) {
195
-			// create folder
196
-			$alias = $id;
197
-			printf('<span>' . $_lang['import_site_importing_document'] . '</span>', $alias);
198
-			$field = array();
199
-			$field['type'] = 'document';
200
-			$field['contentType'] = 'text/html';
201
-			$field['published'] = $publish_default;
202
-			$field['parent'] = $parent;
203
-			$field['alias'] = $modx->stripAlias($alias);
204
-			$field['richtext'] = $richtext;
205
-			$field['template'] = $modx->config['default_template'];
206
-			$field['searchable'] = $search_default;
207
-			$field['cacheable'] = $cache_default;
208
-			$field['createdby'] = $createdby;
209
-			$field['isfolder'] = 1;
210
-			$field['menuindex'] = 1;
211
-			$find = false;
212
-			foreach(array(
213
-						'index.html',
214
-						'index.htm'
215
-					) as $filename) {
216
-				$filepath = $filedir . $alias . '/' . $filename;
217
-				if($find === false && file_exists($filepath)) {
218
-					$file = getFileContent($filepath);
219
-					list($pagetitle, $content, $description) = treatContent($file, $filename, $alias);
220
-
221
-					$date = filemtime($filepath);
222
-					$field['pagetitle'] = $pagetitle;
223
-					$field['longtitle'] = $pagetitle;
224
-					$field['description'] = $description;
225
-					$field['content'] = $modx->db->escape($content);
226
-					$field['createdon'] = $date;
227
-					$field['editedon'] = $date;
228
-					$newid = $modx->db->insert($field, $tbl_site_content);
229
-					if($newid) {
230
-						$find = true;
231
-						echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
232
-						importFiles($newid, $filedir . $alias . '/', $value, 'sub');
233
-					} else {
234
-						echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
235
-						exit;
236
-					}
237
-				}
238
-			}
239
-			if($find === false) {
240
-				$date = time();
241
-				$field['pagetitle'] = '---';
242
-				$field['content'] = '';
243
-				$field['createdon'] = $date;
244
-				$field['editedon'] = $date;
245
-				$field['hidemenu'] = '1';
246
-				$newid = $modx->db->insert($field, $tbl_site_content);
247
-				if($newid) {
248
-					$find = true;
249
-					echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
250
-					importFiles($newid, $filedir . $alias . '/', $value, 'sub');
251
-				} else {
252
-					echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
253
-					exit;
254
-				}
255
-			}
256
-		} else {
257
-			// create document
258
-			if($mode == 'sub' && $value == 'index.html') {
259
-				continue;
260
-			}
261
-			$filename = $value;
262
-			$fparts = explode('.', $value);
263
-			$alias = $fparts[0];
264
-			$ext = (count($fparts) > 1) ? $fparts[count($fparts) - 1] : "";
265
-			printf("<span>" . $_lang['import_site_importing_document'] . "</span>", $filename);
266
-
267
-			if(!in_array($ext, $allowedfiles)) {
268
-				echo ' - <span class="fail">' . $_lang["import_site_skip"] . '</span><br />' . "\n";
269
-			} else {
270
-				$filepath = $filedir . $filename;
271
-				$file = getFileContent($filepath);
272
-				list($pagetitle, $content, $description) = treatContent($file, $filename, $alias);
273
-
274
-				$date = filemtime($filepath);
275
-				$field = array();
276
-				$field['type'] = 'document';
277
-				$field['contentType'] = 'text/html';
278
-				$field['pagetitle'] = $pagetitle;
279
-				$field['longtitle'] = $pagetitle;
280
-				$field['description'] = $description;
281
-				$field['alias'] = $modx->stripAlias($alias);
282
-				$field['published'] = $publish_default;
283
-				$field['parent'] = $parent;
284
-				$field['content'] = $modx->db->escape($content);
285
-				$field['richtext'] = $richtext;
286
-				$field['template'] = $modx->config['default_template'];
287
-				$field['searchable'] = $search_default;
288
-				$field['cacheable'] = $cache_default;
289
-				$field['createdby'] = $createdby;
290
-				$field['createdon'] = $date;
291
-				$field['editedon'] = $date;
292
-				$field['isfolder'] = 0;
293
-				$field['menuindex'] = ($alias == 'index') ? 0 : 2;
294
-				$newid = $modx->db->insert($field, $tbl_site_content);
295
-				if($newid) {
296
-					echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
297
-				} else {
298
-					echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
299
-					exit;
300
-				}
301
-
302
-				$is_site_start = false;
303
-				if($filename == 'index.html') {
304
-					$is_site_start = true;
305
-				}
306
-				if($is_site_start == true && $_POST['reset'] == 'on') {
307
-					$modx->db->update(array('setting_value' => $newid), $tbl_system_settings, "setting_name='site_start'");
308
-					$modx->db->update(array('menuindex' => 0), $tbl_site_content, "id='{$newid}'");
309
-				}
310
-			}
311
-		}
312
-	}
175
+    global $modx;
176
+    global $_lang, $allowedfiles;
177
+    global $search_default, $cache_default, $publish_default;
178
+
179
+    $tbl_site_content = $modx->getFullTableName('site_content');
180
+    $tbl_system_settings = $modx->getFullTableName('system_settings');
181
+
182
+    $createdby = $modx->getLoginUserID();
183
+    if(!is_array($files)) {
184
+        return;
185
+    }
186
+    if($_POST['object'] === 'all') {
187
+        $modx->config['default_template'] = '0';
188
+        $richtext = '0';
189
+    } else {
190
+        $richtext = '1';
191
+    }
192
+
193
+    foreach($files as $id => $value) {
194
+        if(is_array($value)) {
195
+            // create folder
196
+            $alias = $id;
197
+            printf('<span>' . $_lang['import_site_importing_document'] . '</span>', $alias);
198
+            $field = array();
199
+            $field['type'] = 'document';
200
+            $field['contentType'] = 'text/html';
201
+            $field['published'] = $publish_default;
202
+            $field['parent'] = $parent;
203
+            $field['alias'] = $modx->stripAlias($alias);
204
+            $field['richtext'] = $richtext;
205
+            $field['template'] = $modx->config['default_template'];
206
+            $field['searchable'] = $search_default;
207
+            $field['cacheable'] = $cache_default;
208
+            $field['createdby'] = $createdby;
209
+            $field['isfolder'] = 1;
210
+            $field['menuindex'] = 1;
211
+            $find = false;
212
+            foreach(array(
213
+                        'index.html',
214
+                        'index.htm'
215
+                    ) as $filename) {
216
+                $filepath = $filedir . $alias . '/' . $filename;
217
+                if($find === false && file_exists($filepath)) {
218
+                    $file = getFileContent($filepath);
219
+                    list($pagetitle, $content, $description) = treatContent($file, $filename, $alias);
220
+
221
+                    $date = filemtime($filepath);
222
+                    $field['pagetitle'] = $pagetitle;
223
+                    $field['longtitle'] = $pagetitle;
224
+                    $field['description'] = $description;
225
+                    $field['content'] = $modx->db->escape($content);
226
+                    $field['createdon'] = $date;
227
+                    $field['editedon'] = $date;
228
+                    $newid = $modx->db->insert($field, $tbl_site_content);
229
+                    if($newid) {
230
+                        $find = true;
231
+                        echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
232
+                        importFiles($newid, $filedir . $alias . '/', $value, 'sub');
233
+                    } else {
234
+                        echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
235
+                        exit;
236
+                    }
237
+                }
238
+            }
239
+            if($find === false) {
240
+                $date = time();
241
+                $field['pagetitle'] = '---';
242
+                $field['content'] = '';
243
+                $field['createdon'] = $date;
244
+                $field['editedon'] = $date;
245
+                $field['hidemenu'] = '1';
246
+                $newid = $modx->db->insert($field, $tbl_site_content);
247
+                if($newid) {
248
+                    $find = true;
249
+                    echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
250
+                    importFiles($newid, $filedir . $alias . '/', $value, 'sub');
251
+                } else {
252
+                    echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
253
+                    exit;
254
+                }
255
+            }
256
+        } else {
257
+            // create document
258
+            if($mode == 'sub' && $value == 'index.html') {
259
+                continue;
260
+            }
261
+            $filename = $value;
262
+            $fparts = explode('.', $value);
263
+            $alias = $fparts[0];
264
+            $ext = (count($fparts) > 1) ? $fparts[count($fparts) - 1] : "";
265
+            printf("<span>" . $_lang['import_site_importing_document'] . "</span>", $filename);
266
+
267
+            if(!in_array($ext, $allowedfiles)) {
268
+                echo ' - <span class="fail">' . $_lang["import_site_skip"] . '</span><br />' . "\n";
269
+            } else {
270
+                $filepath = $filedir . $filename;
271
+                $file = getFileContent($filepath);
272
+                list($pagetitle, $content, $description) = treatContent($file, $filename, $alias);
273
+
274
+                $date = filemtime($filepath);
275
+                $field = array();
276
+                $field['type'] = 'document';
277
+                $field['contentType'] = 'text/html';
278
+                $field['pagetitle'] = $pagetitle;
279
+                $field['longtitle'] = $pagetitle;
280
+                $field['description'] = $description;
281
+                $field['alias'] = $modx->stripAlias($alias);
282
+                $field['published'] = $publish_default;
283
+                $field['parent'] = $parent;
284
+                $field['content'] = $modx->db->escape($content);
285
+                $field['richtext'] = $richtext;
286
+                $field['template'] = $modx->config['default_template'];
287
+                $field['searchable'] = $search_default;
288
+                $field['cacheable'] = $cache_default;
289
+                $field['createdby'] = $createdby;
290
+                $field['createdon'] = $date;
291
+                $field['editedon'] = $date;
292
+                $field['isfolder'] = 0;
293
+                $field['menuindex'] = ($alias == 'index') ? 0 : 2;
294
+                $newid = $modx->db->insert($field, $tbl_site_content);
295
+                if($newid) {
296
+                    echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
297
+                } else {
298
+                    echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
299
+                    exit;
300
+                }
301
+
302
+                $is_site_start = false;
303
+                if($filename == 'index.html') {
304
+                    $is_site_start = true;
305
+                }
306
+                if($is_site_start == true && $_POST['reset'] == 'on') {
307
+                    $modx->db->update(array('setting_value' => $newid), $tbl_system_settings, "setting_name='site_start'");
308
+                    $modx->db->update(array('menuindex' => 0), $tbl_site_content, "id='{$newid}'");
309
+                }
310
+            }
311
+        }
312
+    }
313 313
 }
314 314
 
315 315
 /**
@@ -319,27 +319,27 @@  discard block
 block discarded – undo
319 319
  * @return array
320 320
  */
321 321
 function getFiles($directory, $listing = array(), $count = 0) {
322
-	global $_lang;
323
-	global $filesfound;
324
-	$dummy = $count;
325
-	if( ! empty($directory) && $files = scandir($directory)) {
326
-		foreach($files as $file) {
327
-			if($file == '.' || $file == '..') {
328
-				continue;
329
-			} elseif($h = @opendir($directory . $file . "/")) {
330
-				closedir($h);
331
-				$count = -1;
332
-				$listing[$file] = getFiles($directory . $file . "/", array(), $count + 1);
333
-			} elseif(strpos($file, '.htm') !== false) {
334
-				$listing[$dummy] = $file;
335
-				$dummy = $dummy + 1;
336
-				$filesfound++;
337
-			}
338
-		}
339
-	} else {
340
-		echo '<p><span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_no_open_dir"] . $directory . ".</p>";
341
-	}
342
-	return ($listing);
322
+    global $_lang;
323
+    global $filesfound;
324
+    $dummy = $count;
325
+    if( ! empty($directory) && $files = scandir($directory)) {
326
+        foreach($files as $file) {
327
+            if($file == '.' || $file == '..') {
328
+                continue;
329
+            } elseif($h = @opendir($directory . $file . "/")) {
330
+                closedir($h);
331
+                $count = -1;
332
+                $listing[$file] = getFiles($directory . $file . "/", array(), $count + 1);
333
+            } elseif(strpos($file, '.htm') !== false) {
334
+                $listing[$dummy] = $file;
335
+                $dummy = $dummy + 1;
336
+                $filesfound++;
337
+            }
338
+        }
339
+    } else {
340
+        echo '<p><span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_no_open_dir"] . $directory . ".</p>";
341
+    }
342
+    return ($listing);
343 343
 }
344 344
 
345 345
 /**
@@ -347,13 +347,13 @@  discard block
 block discarded – undo
347 347
  * @return bool|string
348 348
  */
349 349
 function getFileContent($filepath) {
350
-	global $_lang;
351
-	// get the file
352
-	if(!$buffer = file_get_contents($filepath)) {
353
-		echo '<p><span class="fail">' . $_lang['import_site_failed'] . "</span> " . $_lang["import_site_failed_no_retrieve_file"] . $filepath . ".</p>";
354
-	} else {
355
-		return $buffer;
356
-	}
350
+    global $_lang;
351
+    // get the file
352
+    if(!$buffer = file_get_contents($filepath)) {
353
+        echo '<p><span class="fail">' . $_lang['import_site_failed'] . "</span> " . $_lang["import_site_failed_no_retrieve_file"] . $filepath . ".</p>";
354
+    } else {
355
+        return $buffer;
356
+    }
357 357
 }
358 358
 
359 359
 /**
@@ -361,20 +361,20 @@  discard block
 block discarded – undo
361 361
  * @return array
362 362
  */
363 363
 function pop_index($array) {
364
-	$new_array = array();
365
-	foreach($array as $k => $v) {
366
-		if($v !== 'index.html' && $v !== 'index.htm') {
367
-			$new_array[$k] = $v;
368
-		} else {
369
-			array_unshift($new_array, $v);
370
-		}
371
-	}
372
-	foreach($array as $k => $v) {
373
-		if(is_array($v)) {
374
-			$new_array[$k] = $v;
375
-		}
376
-	}
377
-	return $new_array;
364
+    $new_array = array();
365
+    foreach($array as $k => $v) {
366
+        if($v !== 'index.html' && $v !== 'index.htm') {
367
+            $new_array[$k] = $v;
368
+        } else {
369
+            array_unshift($new_array, $v);
370
+        }
371
+    }
372
+    foreach($array as $k => $v) {
373
+        if(is_array($v)) {
374
+            $new_array[$k] = $v;
375
+        }
376
+    }
377
+    return $new_array;
378 378
 }
379 379
 
380 380
 /**
@@ -384,108 +384,108 @@  discard block
 block discarded – undo
384 384
  * @return array
385 385
  */
386 386
 function treatContent($src, $filename, $alias) {
387
-	global $modx;
388
-
389
-	$src = mb_convert_encoding($src, $modx->config['modx_charset'], 'UTF-8,SJIS-win,eucJP-win,SJIS,EUC-JP,ASCII');
390
-
391
-	if(preg_match("@<title>(.*)</title>@i", $src, $matches)) {
392
-		$pagetitle = ($matches[1] !== '') ? $matches[1] : $filename;
393
-		$pagetitle = str_replace('[*pagetitle*]', '', $pagetitle);
394
-	} else {
395
-		$pagetitle = $alias;
396
-	}
397
-	if(!$pagetitle) {
398
-		$pagetitle = $alias;
399
-	}
400
-
401
-	if(preg_match('@<meta[^>]+"description"[^>]+content=[\'"](.*)[\'"].+>@i', $src, $matches)) {
402
-		$description = ($matches[1] !== '') ? $matches[1] : $filename;
403
-		$description = str_replace('[*description*]', '', $description);
404
-	} else {
405
-		$description = '';
406
-	}
407
-
408
-	if((preg_match("@<body[^>]*>(.*)[^<]+</body>@is", $src, $matches)) && $_POST['object'] == 'body') {
409
-		$content = $matches[1];
410
-	} else {
411
-		$content = $src;
412
-		$s = '/(<meta[^>]+charset\s*=)[^>"\'=]+(.+>)/i';
413
-		$r = '$1' . $modx->config['modx_charset'] . '$2';
414
-		$content = preg_replace($s, $r, $content);
415
-		$content = preg_replace('@<title>.*</title>@i', "<title>[*pagetitle*]</title>", $content);
416
-	}
417
-	$content = str_replace('[*content*]', '[ *content* ]', $content);
418
-	$content = trim($content);
419
-	$pagetitle = $modx->db->escape($pagetitle);
420
-	return array(
421
-		$pagetitle,
422
-		$content,
423
-		$description
424
-	);
387
+    global $modx;
388
+
389
+    $src = mb_convert_encoding($src, $modx->config['modx_charset'], 'UTF-8,SJIS-win,eucJP-win,SJIS,EUC-JP,ASCII');
390
+
391
+    if(preg_match("@<title>(.*)</title>@i", $src, $matches)) {
392
+        $pagetitle = ($matches[1] !== '') ? $matches[1] : $filename;
393
+        $pagetitle = str_replace('[*pagetitle*]', '', $pagetitle);
394
+    } else {
395
+        $pagetitle = $alias;
396
+    }
397
+    if(!$pagetitle) {
398
+        $pagetitle = $alias;
399
+    }
400
+
401
+    if(preg_match('@<meta[^>]+"description"[^>]+content=[\'"](.*)[\'"].+>@i', $src, $matches)) {
402
+        $description = ($matches[1] !== '') ? $matches[1] : $filename;
403
+        $description = str_replace('[*description*]', '', $description);
404
+    } else {
405
+        $description = '';
406
+    }
407
+
408
+    if((preg_match("@<body[^>]*>(.*)[^<]+</body>@is", $src, $matches)) && $_POST['object'] == 'body') {
409
+        $content = $matches[1];
410
+    } else {
411
+        $content = $src;
412
+        $s = '/(<meta[^>]+charset\s*=)[^>"\'=]+(.+>)/i';
413
+        $r = '$1' . $modx->config['modx_charset'] . '$2';
414
+        $content = preg_replace($s, $r, $content);
415
+        $content = preg_replace('@<title>.*</title>@i', "<title>[*pagetitle*]</title>", $content);
416
+    }
417
+    $content = str_replace('[*content*]', '[ *content* ]', $content);
418
+    $content = trim($content);
419
+    $pagetitle = $modx->db->escape($pagetitle);
420
+    return array(
421
+        $pagetitle,
422
+        $content,
423
+        $description
424
+    );
425 425
 }
426 426
 
427 427
 /**
428 428
  * @return void
429 429
  */
430 430
 function convertLink() {
431
-	global $modx;
432
-	$tbl_site_content = $modx->getFullTableName('site_content');
431
+    global $modx;
432
+    $tbl_site_content = $modx->getFullTableName('site_content');
433 433
 
434
-	$rs = $modx->db->select('id,content', $tbl_site_content);
435
-	$p = array();
434
+    $rs = $modx->db->select('id,content', $tbl_site_content);
435
+    $p = array();
436 436
     $target = array();
437
-	$dir = '';
438
-	while($row = $modx->db->getRow($rs)) {
439
-		$id = $row['id'];
440
-		$array = explode('<a href=', $row['content']);
441
-		$c = 0;
442
-		foreach($array as $v) {
443
-			if($v[0] === '"') {
444
-				$v = substr($v, 1);
445
-				list($href, $v) = explode('"', $v, 2);
446
-				$_ = $href;
447
-				if(strpos($_, $modx->config['site_url']) !== false) {
448
-					$_ = $modx->config['base_url'] . str_replace($modx->config['site_url'], '', $_);
449
-				}
450
-				if($_[0] === '/') {
451
-					$_ = substr($_, 1);
452
-				}
453
-				$_ = str_replace('/index.html', '.html', $_);
454
-				$level = substr_count($_, '../');
455
-				if(1 < $level) {
456
-					if(!isset($p[$id])) {
457
-						$p[$id] = $modx->getParentIds($id);
458
-					}
459
-					$k = array_keys($p[$id]);
460
-					while(0 < $level) {
461
-						$dir = array_shift($k);
462
-						$level--;
463
-					}
464
-					if($dir != '') {
465
-						$dir .= '/';
466
-					}
467
-				} else {
468
-					$dir = '';
469
-				}
470
-
471
-				$_ = trim($_, './');
472
-				if(strpos($_, '/') !== false) {
473
-					$_ = substr($_, strrpos($_, '/'));
474
-				}
475
-				$_ = $dir . str_replace('.html', '', $_);
476
-				if(!isset($target[$_])) {
477
-					$target[$_] = $modx->getIdFromAlias($_);
478
-				}
479
-				$target[$_] = trim($target[$_]);
480
-				if(!empty($target[$_])) {
481
-					$href = '[~' . $target[$_] . '~]';
482
-				}
483
-				$array[$c] = '<a href="' . $href . '"' . $v;
484
-			}
485
-			$c++;
486
-		}
487
-		$content = implode('', $array);
488
-		$f['content'] = $modx->db->escape($content);
489
-		$modx->db->update($f, $tbl_site_content, "id='{$id}'");
490
-	}
437
+    $dir = '';
438
+    while($row = $modx->db->getRow($rs)) {
439
+        $id = $row['id'];
440
+        $array = explode('<a href=', $row['content']);
441
+        $c = 0;
442
+        foreach($array as $v) {
443
+            if($v[0] === '"') {
444
+                $v = substr($v, 1);
445
+                list($href, $v) = explode('"', $v, 2);
446
+                $_ = $href;
447
+                if(strpos($_, $modx->config['site_url']) !== false) {
448
+                    $_ = $modx->config['base_url'] . str_replace($modx->config['site_url'], '', $_);
449
+                }
450
+                if($_[0] === '/') {
451
+                    $_ = substr($_, 1);
452
+                }
453
+                $_ = str_replace('/index.html', '.html', $_);
454
+                $level = substr_count($_, '../');
455
+                if(1 < $level) {
456
+                    if(!isset($p[$id])) {
457
+                        $p[$id] = $modx->getParentIds($id);
458
+                    }
459
+                    $k = array_keys($p[$id]);
460
+                    while(0 < $level) {
461
+                        $dir = array_shift($k);
462
+                        $level--;
463
+                    }
464
+                    if($dir != '') {
465
+                        $dir .= '/';
466
+                    }
467
+                } else {
468
+                    $dir = '';
469
+                }
470
+
471
+                $_ = trim($_, './');
472
+                if(strpos($_, '/') !== false) {
473
+                    $_ = substr($_, strrpos($_, '/'));
474
+                }
475
+                $_ = $dir . str_replace('.html', '', $_);
476
+                if(!isset($target[$_])) {
477
+                    $target[$_] = $modx->getIdFromAlias($_);
478
+                }
479
+                $target[$_] = trim($target[$_]);
480
+                if(!empty($target[$_])) {
481
+                    $href = '[~' . $target[$_] . '~]';
482
+                }
483
+                $array[$c] = '<a href="' . $href . '"' . $v;
484
+            }
485
+            $c++;
486
+        }
487
+        $content = implode('', $array);
488
+        $f['content'] = $modx->db->escape($content);
489
+        $modx->db->update($f, $tbl_site_content, "id='{$id}'");
490
+    }
491 491
 }
Please login to merge, or discard this patch.
manager/actions/mutate_role.dynamic.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) {
3
-	die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
3
+    die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
4 4
 }
5 5
 
6 6
 switch((int) $modx->manager->action) {
7
-	case 35:
8
-		if(!$modx->hasPermission('edit_role')) {
9
-			$modx->webAlertAndQuit($_lang["error_no_privileges"]);
10
-		}
11
-		break;
12
-	case 38:
13
-		if(!$modx->hasPermission('new_role')) {
14
-			$modx->webAlertAndQuit($_lang["error_no_privileges"]);
15
-		}
16
-		break;
17
-	default:
18
-		$modx->webAlertAndQuit($_lang["error_no_privileges"]);
7
+    case 35:
8
+        if(!$modx->hasPermission('edit_role')) {
9
+            $modx->webAlertAndQuit($_lang["error_no_privileges"]);
10
+        }
11
+        break;
12
+    case 38:
13
+        if(!$modx->hasPermission('new_role')) {
14
+            $modx->webAlertAndQuit($_lang["error_no_privileges"]);
15
+        }
16
+        break;
17
+    default:
18
+        $modx->webAlertAndQuit($_lang["error_no_privileges"]);
19 19
 }
20 20
 
21 21
 $role = isset($_REQUEST['id']) ? (int)$_REQUEST['id'] : 0;
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 
25 25
 // check to see the snippet editor isn't locked
26 26
 if($lockedEl = $modx->elementIsLocked(8, $role)) {
27
-	$modx->webAlertAndQuit(sprintf($_lang['lock_msg'], $lockedEl['username'], $_lang['role']));
27
+    $modx->webAlertAndQuit(sprintf($_lang['lock_msg'], $lockedEl['username'], $_lang['role']));
28 28
 }
29 29
 // end check for lock
30 30
 
@@ -32,15 +32,15 @@  discard block
 block discarded – undo
32 32
 $modx->lockElement(8, $role);
33 33
 
34 34
 if($modx->manager->action == '35') {
35
-	$rs = $modx->db->select('*', $tbl_user_roles, "id='{$role}'");
36
-	$roledata = $modx->db->getRow($rs);
37
-	if(!$roledata) {
38
-		$modx->webAlertAndQuit("No role returned!");
39
-	}
40
-	$_SESSION['itemname'] = $roledata['name'];
35
+    $rs = $modx->db->select('*', $tbl_user_roles, "id='{$role}'");
36
+    $roledata = $modx->db->getRow($rs);
37
+    if(!$roledata) {
38
+        $modx->webAlertAndQuit("No role returned!");
39
+    }
40
+    $_SESSION['itemname'] = $roledata['name'];
41 41
 } else {
42
-	$roledata = 0;
43
-	$_SESSION['itemname'] = $_lang["new_role"];
42
+    $roledata = 0;
43
+    $_SESSION['itemname'] = $_lang["new_role"];
44 44
 }
45 45
 
46 46
 // Add lock-element JS-Script
@@ -107,63 +107,63 @@  discard block
 block discarded – undo
107 107
 							<div class="form-group">
108 108
 								<h3><?= $_lang['page_data_general'] ?></h3>
109 109
 								<?php
110
-								echo render_form('frames', $_lang['role_frames'], 'disabled');
111
-								echo render_form('home', $_lang['role_home'], 'disabled');
112
-								echo render_form('messages', $_lang['role_messages']);
113
-								echo render_form('logout', $_lang['role_logout'], 'disabled');
114
-								echo render_form('help', $_lang['role_help']);
115
-								echo render_form('action_ok', $_lang['role_actionok'], 'disabled');
116
-								echo render_form('error_dialog', $_lang['role_errors'], 'disabled');
117
-								echo render_form('about', $_lang['role_about'], 'disabled');
118
-								echo render_form('credits', $_lang['role_credits'], 'disabled');
119
-								echo render_form('change_password', $_lang['role_change_password']);
120
-								echo render_form('save_password', $_lang['role_save_password']);
121
-								?>
110
+                                echo render_form('frames', $_lang['role_frames'], 'disabled');
111
+                                echo render_form('home', $_lang['role_home'], 'disabled');
112
+                                echo render_form('messages', $_lang['role_messages']);
113
+                                echo render_form('logout', $_lang['role_logout'], 'disabled');
114
+                                echo render_form('help', $_lang['role_help']);
115
+                                echo render_form('action_ok', $_lang['role_actionok'], 'disabled');
116
+                                echo render_form('error_dialog', $_lang['role_errors'], 'disabled');
117
+                                echo render_form('about', $_lang['role_about'], 'disabled');
118
+                                echo render_form('credits', $_lang['role_credits'], 'disabled');
119
+                                echo render_form('change_password', $_lang['role_change_password']);
120
+                                echo render_form('save_password', $_lang['role_save_password']);
121
+                                ?>
122 122
 							</div>
123 123
 						</div>
124 124
 						<div class="col-sm-6 col-lg-3">
125 125
 							<div class="form-group">
126 126
 								<h3><?= $_lang['role_content_management'] ?></h3>
127 127
 								<?php
128
-								echo render_form('view_document', $_lang['role_view_docdata'], 'disabled');
129
-								echo render_form('new_document', $_lang['role_create_doc']);
130
-								echo render_form('edit_document', $_lang['role_edit_doc']);
131
-								echo render_form('change_resourcetype', $_lang['role_change_resourcetype']);
132
-								echo render_form('save_document', $_lang['role_save_doc']);
133
-								echo render_form('publish_document', $_lang['role_publish_doc']);
134
-								echo render_form('delete_document', $_lang['role_delete_doc']);
135
-								echo render_form('empty_trash', $_lang['role_empty_trash']);
136
-								echo render_form('empty_cache', $_lang['role_cache_refresh']);
137
-								echo render_form('view_unpublished', $_lang['role_view_unpublished']);
138
-								?>
128
+                                echo render_form('view_document', $_lang['role_view_docdata'], 'disabled');
129
+                                echo render_form('new_document', $_lang['role_create_doc']);
130
+                                echo render_form('edit_document', $_lang['role_edit_doc']);
131
+                                echo render_form('change_resourcetype', $_lang['role_change_resourcetype']);
132
+                                echo render_form('save_document', $_lang['role_save_doc']);
133
+                                echo render_form('publish_document', $_lang['role_publish_doc']);
134
+                                echo render_form('delete_document', $_lang['role_delete_doc']);
135
+                                echo render_form('empty_trash', $_lang['role_empty_trash']);
136
+                                echo render_form('empty_cache', $_lang['role_cache_refresh']);
137
+                                echo render_form('view_unpublished', $_lang['role_view_unpublished']);
138
+                                ?>
139 139
 							</div>
140 140
 						</div>
141 141
 						<div class="col-sm-6 col-lg-3 form-group">
142 142
 							<div class="form-group">
143 143
 								<h3><?= $_lang['role_file_management'] ?></h3>
144 144
 								<?php
145
-								echo render_form('file_manager', $_lang['role_file_manager']);
146
-								echo render_form('assets_files', $_lang['role_assets_files']);
147
-								echo render_form('assets_images', $_lang['role_assets_images']);
148
-								?>
145
+                                echo render_form('file_manager', $_lang['role_file_manager']);
146
+                                echo render_form('assets_files', $_lang['role_assets_files']);
147
+                                echo render_form('assets_images', $_lang['role_assets_images']);
148
+                                ?>
149 149
 							</div>
150 150
 							<div class="form-group">
151 151
 								<h3><?= $_lang['category_management'] ?></h3>
152 152
 								<?php
153
-								echo render_form('category_manager', $_lang['role_category_manager']);
154
-								?>
153
+                                echo render_form('category_manager', $_lang['role_category_manager']);
154
+                                ?>
155 155
 							</div>
156 156
 						</div>
157 157
 						<div class="col-sm-6 col-lg-3">
158 158
 							<div class="form-group">
159 159
 								<h3><?= $_lang['role_module_management'] ?></h3>
160 160
 								<?php
161
-								echo render_form('new_module', $_lang['role_new_module']);
162
-								echo render_form('edit_module', $_lang['role_edit_module']);
163
-								echo render_form('save_module', $_lang['role_save_module']);
164
-								echo render_form('delete_module', $_lang['role_delete_module']);
165
-								echo render_form('exec_module', $_lang['role_run_module']);
166
-								?>
161
+                                echo render_form('new_module', $_lang['role_new_module']);
162
+                                echo render_form('edit_module', $_lang['role_edit_module']);
163
+                                echo render_form('save_module', $_lang['role_save_module']);
164
+                                echo render_form('delete_module', $_lang['role_delete_module']);
165
+                                echo render_form('exec_module', $_lang['role_run_module']);
166
+                                ?>
167 167
 							</div>
168 168
 						</div>
169 169
 					</div>
@@ -173,44 +173,44 @@  discard block
 block discarded – undo
173 173
 							<div class="form-group">
174 174
 								<h3><?= $_lang['role_template_management'] ?></h3>
175 175
 								<?php
176
-								echo render_form('new_template', $_lang['role_create_template']);
177
-								echo render_form('edit_template', $_lang['role_edit_template']);
178
-								echo render_form('save_template', $_lang['role_save_template']);
179
-								echo render_form('delete_template', $_lang['role_delete_template']);
180
-								?>
176
+                                echo render_form('new_template', $_lang['role_create_template']);
177
+                                echo render_form('edit_template', $_lang['role_edit_template']);
178
+                                echo render_form('save_template', $_lang['role_save_template']);
179
+                                echo render_form('delete_template', $_lang['role_delete_template']);
180
+                                ?>
181 181
 							</div>
182 182
 						</div>
183 183
 						<div class="col-sm-6 col-lg-3">
184 184
 							<div class="form-group">
185 185
 								<h3><?= $_lang['role_snippet_management'] ?></h3>
186 186
 								<?php
187
-								echo render_form('new_snippet', $_lang['role_create_snippet']);
188
-								echo render_form('edit_snippet', $_lang['role_edit_snippet']);
189
-								echo render_form('save_snippet', $_lang['role_save_snippet']);
190
-								echo render_form('delete_snippet', $_lang['role_delete_snippet']);
191
-								?>
187
+                                echo render_form('new_snippet', $_lang['role_create_snippet']);
188
+                                echo render_form('edit_snippet', $_lang['role_edit_snippet']);
189
+                                echo render_form('save_snippet', $_lang['role_save_snippet']);
190
+                                echo render_form('delete_snippet', $_lang['role_delete_snippet']);
191
+                                ?>
192 192
 							</div>
193 193
 						</div>
194 194
 						<div class="col-sm-6 col-lg-3">
195 195
 							<div class="form-group">
196 196
 								<h3><?= $_lang['role_chunk_management'] ?></h3>
197 197
 								<?php
198
-								echo render_form('new_chunk', $_lang['role_create_chunk']);
199
-								echo render_form('edit_chunk', $_lang['role_edit_chunk']);
200
-								echo render_form('save_chunk', $_lang['role_save_chunk']);
201
-								echo render_form('delete_chunk', $_lang['role_delete_chunk']);
202
-								?>
198
+                                echo render_form('new_chunk', $_lang['role_create_chunk']);
199
+                                echo render_form('edit_chunk', $_lang['role_edit_chunk']);
200
+                                echo render_form('save_chunk', $_lang['role_save_chunk']);
201
+                                echo render_form('delete_chunk', $_lang['role_delete_chunk']);
202
+                                ?>
203 203
 							</div>
204 204
 						</div>
205 205
 						<div class="col-sm-6 col-lg-3">
206 206
 							<div class="form-group">
207 207
 								<h3><?= $_lang['role_plugin_management'] ?></h3>
208 208
 								<?php
209
-								echo render_form('new_plugin', $_lang['role_create_plugin']);
210
-								echo render_form('edit_plugin', $_lang['role_edit_plugin']);
211
-								echo render_form('save_plugin', $_lang['role_save_plugin']);
212
-								echo render_form('delete_plugin', $_lang['role_delete_plugin']);
213
-								?>
209
+                                echo render_form('new_plugin', $_lang['role_create_plugin']);
210
+                                echo render_form('edit_plugin', $_lang['role_edit_plugin']);
211
+                                echo render_form('save_plugin', $_lang['role_save_plugin']);
212
+                                echo render_form('delete_plugin', $_lang['role_delete_plugin']);
213
+                                ?>
214 214
 							</div>
215 215
 						</div>
216 216
 					</div>
@@ -220,42 +220,42 @@  discard block
 block discarded – undo
220 220
 							<div class="form-group">
221 221
 								<h3><?= $_lang['role_user_management'] ?></h3>
222 222
 								<?php
223
-								echo render_form('new_user', $_lang['role_new_user']);
224
-								echo render_form('edit_user', $_lang['role_edit_user']);
225
-								echo render_form('save_user', $_lang['role_save_user']);
226
-								echo render_form('delete_user', $_lang['role_delete_user']);
227
-								?>
223
+                                echo render_form('new_user', $_lang['role_new_user']);
224
+                                echo render_form('edit_user', $_lang['role_edit_user']);
225
+                                echo render_form('save_user', $_lang['role_save_user']);
226
+                                echo render_form('delete_user', $_lang['role_delete_user']);
227
+                                ?>
228 228
 							</div>
229 229
 						</div>
230 230
 						<div class="col-sm-6 col-lg-3">
231 231
 							<div class="form-group">
232 232
 								<h3><?= $_lang['role_web_user_management'] ?></h3>
233 233
 								<?php
234
-								echo render_form('new_web_user', $_lang['role_new_web_user']);
235
-								echo render_form('edit_web_user', $_lang['role_edit_web_user']);
236
-								echo render_form('save_web_user', $_lang['role_save_web_user']);
237
-								echo render_form('delete_web_user', $_lang['role_delete_web_user']);
238
-								?>
234
+                                echo render_form('new_web_user', $_lang['role_new_web_user']);
235
+                                echo render_form('edit_web_user', $_lang['role_edit_web_user']);
236
+                                echo render_form('save_web_user', $_lang['role_save_web_user']);
237
+                                echo render_form('delete_web_user', $_lang['role_delete_web_user']);
238
+                                ?>
239 239
 							</div>
240 240
 						</div>
241 241
 						<div class="col-sm-6 col-lg-3">
242 242
 							<div class="form-group">
243 243
 								<h3><?= $_lang['role_udperms'] ?></h3>
244 244
 								<?php
245
-								echo render_form('access_permissions', $_lang['role_access_persmissions']);
246
-								echo render_form('web_access_permissions', $_lang['role_web_access_persmissions']);
247
-								?>
245
+                                echo render_form('access_permissions', $_lang['role_access_persmissions']);
246
+                                echo render_form('web_access_permissions', $_lang['role_web_access_persmissions']);
247
+                                ?>
248 248
 							</div>
249 249
 						</div>
250 250
 						<div class="col-sm-6 col-lg-3">
251 251
 							<div class="form-group">
252 252
 								<h3><?= $_lang['role_role_management'] ?></h3>
253 253
 								<?php
254
-								echo render_form('new_role', $_lang['role_new_role']);
255
-								echo render_form('edit_role', $_lang['role_edit_role']);
256
-								echo render_form('save_role', $_lang['role_save_role']);
257
-								echo render_form('delete_role', $_lang['role_delete_role']);
258
-								?>
254
+                                echo render_form('new_role', $_lang['role_new_role']);
255
+                                echo render_form('edit_role', $_lang['role_edit_role']);
256
+                                echo render_form('save_role', $_lang['role_save_role']);
257
+                                echo render_form('delete_role', $_lang['role_delete_role']);
258
+                                ?>
259 259
 							</div>
260 260
 						</div>
261 261
 					</div>
@@ -265,23 +265,23 @@  discard block
 block discarded – undo
265 265
 							<div class="form-group">
266 266
 								<h3><?= $_lang['role_eventlog_management'] ?></h3>
267 267
 								<?php
268
-								echo render_form('view_eventlog', $_lang['role_view_eventlog']);
269
-								echo render_form('delete_eventlog', $_lang['role_delete_eventlog']);
270
-								?>
268
+                                echo render_form('view_eventlog', $_lang['role_view_eventlog']);
269
+                                echo render_form('delete_eventlog', $_lang['role_delete_eventlog']);
270
+                                ?>
271 271
 							</div>
272 272
 						</div>
273 273
 						<div class="col-sm-6 col-lg-3">
274 274
 							<div class="form-group">
275 275
 								<h3><?= $_lang['role_config_management'] ?></h3>
276 276
 								<?php
277
-								echo render_form('logs', $_lang['role_view_logs']);
278
-								echo render_form('settings', $_lang['role_edit_settings']);
279
-								echo render_form('bk_manager', $_lang['role_bk_manager']);
280
-								echo render_form('import_static', $_lang['role_import_static']);
281
-								echo render_form('export_static', $_lang['role_export_static']);
282
-								echo render_form('remove_locks', $_lang['role_remove_locks']);
283
-								echo render_form('display_locks', $_lang['role_display_locks']);
284
-								?>
277
+                                echo render_form('logs', $_lang['role_view_logs']);
278
+                                echo render_form('settings', $_lang['role_edit_settings']);
279
+                                echo render_form('bk_manager', $_lang['role_bk_manager']);
280
+                                echo render_form('import_static', $_lang['role_import_static']);
281
+                                echo render_form('export_static', $_lang['role_export_static']);
282
+                                echo render_form('remove_locks', $_lang['role_remove_locks']);
283
+                                echo render_form('display_locks', $_lang['role_display_locks']);
284
+                                ?>
285 285
 							</div>
286 286
 						</div>
287 287
 					</div>
@@ -300,32 +300,32 @@  discard block
 block discarded – undo
300 300
  * @return string
301 301
  */
302 302
 function render_form($name, $label, $status = '') {
303
-	global $modx, $roledata;
303
+    global $modx, $roledata;
304 304
 
305
-	$tpl = '<label class="d-block" for="[+name+]check">
305
+    $tpl = '<label class="d-block" for="[+name+]check">
306 306
 		<input name="[+name+]check" id="[+name+]check" class="click" type="checkbox" onchange="changestate(document.userform.[+name+])" [+checked+] [+status+]>
307 307
 		<input type="hidden" class="[+set+]" name="[+name+]" value="[+value+]">
308 308
 		[+label+]
309 309
 	</label>';
310 310
 
311
-	$checked = ($roledata[$name] == 1) ? 'checked' : '';
312
-	$value = ($roledata[$name] == 1) ? 1 : 0;
313
-	if($status == 'disabled') {
314
-		$checked = 'checked';
315
-		$value = 1;
316
-		$set = 'fix';
317
-	} else {
318
-		$set = 'set';
319
-	}
311
+    $checked = ($roledata[$name] == 1) ? 'checked' : '';
312
+    $value = ($roledata[$name] == 1) ? 1 : 0;
313
+    if($status == 'disabled') {
314
+        $checked = 'checked';
315
+        $value = 1;
316
+        $set = 'fix';
317
+    } else {
318
+        $set = 'set';
319
+    }
320 320
 
321
-	$ph = array(
322
-		'name' => $name,
323
-		'checked' => $checked,
324
-		'status' => $status,
325
-		'value' => $value,
326
-		'label' => $label,
327
-		'set' => $set
328
-	);
321
+    $ph = array(
322
+        'name' => $name,
323
+        'checked' => $checked,
324
+        'status' => $status,
325
+        'value' => $value,
326
+        'label' => $label,
327
+        'set' => $set
328
+    );
329 329
 
330
-	return $modx->parseText($tpl, $ph);
330
+    return $modx->parseText($tpl, $ph);
331 331
 }
Please login to merge, or discard this patch.
manager/includes/tmplvars.inc.php 1 patch
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -13,159 +13,159 @@  discard block
 block discarded – undo
13 13
  * @return string
14 14
  */
15 15
 function renderFormElement($field_type, $field_id, $default_text = '', $field_elements = '', $field_value = '', $field_style = '', $row = array(), $tvsArray = array()) {
16
-	global $modx;
17
-	global $_style;
18
-	global $_lang;
19
-	global $content;
20
-	global $which_browser;
16
+    global $modx;
17
+    global $_style;
18
+    global $_lang;
19
+    global $content;
20
+    global $which_browser;
21 21
 
22
-	if(substr($default_text, 0, 6) === '@@EVAL' && $field_value === $default_text) {
23
-		$eval_str = trim(substr($default_text, 7));
24
-		$default_text = eval($eval_str);
25
-		$field_value = $default_text;
26
-	}
22
+    if(substr($default_text, 0, 6) === '@@EVAL' && $field_value === $default_text) {
23
+        $eval_str = trim(substr($default_text, 7));
24
+        $default_text = eval($eval_str);
25
+        $field_value = $default_text;
26
+    }
27 27
 
28
-	$field_html = '';
29
-	$cimode = strpos($field_type, ':');
30
-	if($cimode === false) {
31
-		switch($field_type) {
28
+    $field_html = '';
29
+    $cimode = strpos($field_type, ':');
30
+    if($cimode === false) {
31
+        switch($field_type) {
32 32
 
33
-			case "text": // handler for regular text boxes
34
-			case "rawtext"; // non-htmlentity converted text boxes
35
-				$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%" />';
36
-				break;
37
-			case "email": // handles email input fields
38
-				$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%"/>';
39
-				break;
40
-			case "number": // handles the input of numbers
41
-				$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-,.+]/,\'\')"/>';
42
-				break;
43
-			case "textareamini": // handler for textarea mini boxes
44
-				$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>';
45
-				break;
46
-			case "textarea": // handler for textarea boxes
47
-			case "rawtextarea": // non-htmlentity convertex textarea boxes
48
-			case "htmlarea": // handler for textarea boxes (deprecated)
49
-			case "richtext": // handler for textarea boxes
50
-				$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>';
51
-				break;
52
-			case "date":
53
-				$field_id = str_replace(array(
54
-					'-',
55
-					'.'
56
-				), '_', urldecode($field_id));
57
-				if($field_value == '') {
58
-					$field_value = 0;
59
-				}
60
-				$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;" />';
61
-				$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>';
33
+            case "text": // handler for regular text boxes
34
+            case "rawtext"; // non-htmlentity converted text boxes
35
+                $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%" />';
36
+                break;
37
+            case "email": // handles email input fields
38
+                $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%"/>';
39
+                break;
40
+            case "number": // handles the input of numbers
41
+                $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-,.+]/,\'\')"/>';
42
+                break;
43
+            case "textareamini": // handler for textarea mini boxes
44
+                $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>';
45
+                break;
46
+            case "textarea": // handler for textarea boxes
47
+            case "rawtextarea": // non-htmlentity convertex textarea boxes
48
+            case "htmlarea": // handler for textarea boxes (deprecated)
49
+            case "richtext": // handler for textarea boxes
50
+                $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>';
51
+                break;
52
+            case "date":
53
+                $field_id = str_replace(array(
54
+                    '-',
55
+                    '.'
56
+                ), '_', urldecode($field_id));
57
+                if($field_value == '') {
58
+                    $field_value = 0;
59
+                }
60
+                $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;" />';
61
+                $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>';
62 62
 
63
-				break;
64
-			case "dropdown": // handler for select boxes
65
-				$field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" size="1" onchange="documentDirty=true;">';
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": // handler for select boxes
77
-				$field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" onchange="documentDirty=true;" size="8">';
78
-				$index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
79
-				while(list($item, $itemvalue) = each($index_list)) {
80
-					list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
81
-					if(strlen($itemvalue) == 0) {
82
-						$itemvalue = $item;
83
-					}
84
-					$field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
85
-				}
86
-				$field_html .= "</select>";
87
-				break;
88
-			case "listbox-multiple": // handler for select boxes where you can choose multiple items
89
-				$field_value = explode("||", $field_value);
90
-				$field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '[]" multiple="multiple" onchange="documentDirty=true;" size="8">';
91
-				$index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
92
-				while(list($item, $itemvalue) = each($index_list)) {
93
-					list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
94
-					if(strlen($itemvalue) == 0) {
95
-						$itemvalue = $item;
96
-					}
97
-					$field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . (in_array($itemvalue, $field_value) ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
98
-				}
99
-				$field_html .= "</select>";
100
-				break;
101
-			case "url": // handles url input fields
102
-				$urls = array(
103
-					'' => '--',
104
-					'http://' => 'http://',
105
-					'https://' => 'https://',
106
-					'ftp://' => 'ftp://',
107
-					'mailto:' => 'mailto:'
108
-				);
109
-				$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;">';
110
-				foreach($urls as $k => $v) {
111
-					if(strpos($field_value, $v) === false) {
112
-						$field_html .= '<option value="' . $v . '">' . $k . '</option>';
113
-					} else {
114
-						$field_value = str_replace($v, '', $field_value);
115
-						$field_html .= '<option value="' . $v . '" selected="selected">' . $k . '</option>';
116
-					}
117
-				}
118
-				$field_html .= '</select></td><td>';
119
-				$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>';
120
-				break;
121
-			case 'checkbox': // handles check boxes
122
-				$values = !is_array($field_value) ? explode('||', $field_value) : $field_value;
123
-				$index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
124
-				$tpl = '<label class="checkbox"><input type="checkbox" value="%s" id="tv_%s" name="tv%s[]" %s onchange="documentDirty=true;" />%s</label><br />';
125
-				static $i = 0;
126
-				$_ = array();
127
-				foreach($index_list as $c => $item) {
128
-					if(is_array($item)) {
129
-						$name = trim($item[0]);
130
-						$value = isset($item[1]) ? $item[1] : $name;
131
-					} else {
132
-						$item = trim($item);
133
-						list($name, $value) = (strpos($item, '==') !== false) ? explode('==', $item, 2) : array(
134
-							$item,
135
-							$item
136
-						);
137
-					}
138
-					$checked = in_array($value, $values) ? ' checked="checked"' : '';
139
-					$param = array(
140
-						$modx->htmlspecialchars($value),
141
-						$i,
142
-						$field_id,
143
-						$checked,
144
-						$modx->htmlspecialchars($name)
145
-					);
146
-					$_[] = vsprintf($tpl, $param);
147
-					$i++;
148
-				}
149
-				$field_html = implode("\n", $_);
150
-				break;
151
-			case "option": // handles radio buttons
152
-				$index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
153
-				static $i = 0;
154
-				while(list($item, $itemvalue) = each($index_list)) {
155
-					list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
156
-					if(strlen($itemvalue) == 0) {
157
-						$itemvalue = $item;
158
-					}
159
-					$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 />';
160
-					$i++;
161
-				}
162
-				break;
163
-			case "image": // handles image fields using htmlarea image manager
164
-				global $_lang;
165
-				global $ResourceManagerLoaded;
166
-				global $content, $use_editor, $which_editor;
167
-				if(!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $modx->manager->action == 4) && $use_editor == 1 && $which_editor == 3)) {
168
-					$field_html .= "
63
+                break;
64
+            case "dropdown": // handler for select boxes
65
+                $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" size="1" onchange="documentDirty=true;">';
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": // handler for select boxes
77
+                $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" onchange="documentDirty=true;" size="8">';
78
+                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
79
+                while(list($item, $itemvalue) = each($index_list)) {
80
+                    list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
81
+                    if(strlen($itemvalue) == 0) {
82
+                        $itemvalue = $item;
83
+                    }
84
+                    $field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
85
+                }
86
+                $field_html .= "</select>";
87
+                break;
88
+            case "listbox-multiple": // handler for select boxes where you can choose multiple items
89
+                $field_value = explode("||", $field_value);
90
+                $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '[]" multiple="multiple" onchange="documentDirty=true;" size="8">';
91
+                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
92
+                while(list($item, $itemvalue) = each($index_list)) {
93
+                    list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
94
+                    if(strlen($itemvalue) == 0) {
95
+                        $itemvalue = $item;
96
+                    }
97
+                    $field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . (in_array($itemvalue, $field_value) ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
98
+                }
99
+                $field_html .= "</select>";
100
+                break;
101
+            case "url": // handles url input fields
102
+                $urls = array(
103
+                    '' => '--',
104
+                    'http://' => 'http://',
105
+                    'https://' => 'https://',
106
+                    'ftp://' => 'ftp://',
107
+                    'mailto:' => 'mailto:'
108
+                );
109
+                $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;">';
110
+                foreach($urls as $k => $v) {
111
+                    if(strpos($field_value, $v) === false) {
112
+                        $field_html .= '<option value="' . $v . '">' . $k . '</option>';
113
+                    } else {
114
+                        $field_value = str_replace($v, '', $field_value);
115
+                        $field_html .= '<option value="' . $v . '" selected="selected">' . $k . '</option>';
116
+                    }
117
+                }
118
+                $field_html .= '</select></td><td>';
119
+                $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>';
120
+                break;
121
+            case 'checkbox': // handles check boxes
122
+                $values = !is_array($field_value) ? explode('||', $field_value) : $field_value;
123
+                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
124
+                $tpl = '<label class="checkbox"><input type="checkbox" value="%s" id="tv_%s" name="tv%s[]" %s onchange="documentDirty=true;" />%s</label><br />';
125
+                static $i = 0;
126
+                $_ = array();
127
+                foreach($index_list as $c => $item) {
128
+                    if(is_array($item)) {
129
+                        $name = trim($item[0]);
130
+                        $value = isset($item[1]) ? $item[1] : $name;
131
+                    } else {
132
+                        $item = trim($item);
133
+                        list($name, $value) = (strpos($item, '==') !== false) ? explode('==', $item, 2) : array(
134
+                            $item,
135
+                            $item
136
+                        );
137
+                    }
138
+                    $checked = in_array($value, $values) ? ' checked="checked"' : '';
139
+                    $param = array(
140
+                        $modx->htmlspecialchars($value),
141
+                        $i,
142
+                        $field_id,
143
+                        $checked,
144
+                        $modx->htmlspecialchars($name)
145
+                    );
146
+                    $_[] = vsprintf($tpl, $param);
147
+                    $i++;
148
+                }
149
+                $field_html = implode("\n", $_);
150
+                break;
151
+            case "option": // handles radio buttons
152
+                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform', $tvsArray));
153
+                static $i = 0;
154
+                while(list($item, $itemvalue) = each($index_list)) {
155
+                    list($item, $itemvalue) = (is_array($itemvalue)) ? $itemvalue : explode("==", $itemvalue);
156
+                    if(strlen($itemvalue) == 0) {
157
+                        $itemvalue = $item;
158
+                    }
159
+                    $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 />';
160
+                    $i++;
161
+                }
162
+                break;
163
+            case "image": // handles image fields using htmlarea image manager
164
+                global $_lang;
165
+                global $ResourceManagerLoaded;
166
+                global $content, $use_editor, $which_editor;
167
+                if(!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $modx->manager->action == 4) && $use_editor == 1 && $which_editor == 3)) {
168
+                    $field_html .= "
169 169
 						<script type=\"text/javascript\">
170 170
 							/* <![CDATA[ */
171 171
 								var lastImageCtrl;
@@ -224,18 +224,18 @@  discard block
 block discarded – undo
224 224
 								}
225 225
 							/* ]]> */
226 226
 						</script>";
227
-					$ResourceManagerLoaded = true;
228
-				}
229
-				$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 . '\')" />';
230
-				break;
231
-			case "file": // handles the input of file uploads
232
-				/* Modified by Timon for use with resource browser */
233
-				global $_lang;
234
-				global $ResourceManagerLoaded;
235
-				global $content, $use_editor, $which_editor;
236
-				if(!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $modx->manager->action == 4) && $use_editor == 1 && $which_editor == 3)) {
237
-					/* I didn't understand the meaning of the condition above, so I left it untouched ;-) */
238
-					$field_html .= "
227
+                    $ResourceManagerLoaded = true;
228
+                }
229
+                $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 . '\')" />';
230
+                break;
231
+            case "file": // handles the input of file uploads
232
+                /* Modified by Timon for use with resource browser */
233
+                global $_lang;
234
+                global $ResourceManagerLoaded;
235
+                global $content, $use_editor, $which_editor;
236
+                if(!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $modx->manager->action == 4) && $use_editor == 1 && $which_editor == 3)) {
237
+                    /* I didn't understand the meaning of the condition above, so I left it untouched ;-) */
238
+                    $field_html .= "
239 239
 						<script type=\"text/javascript\">
240 240
 							/* <![CDATA[ */
241 241
 								var lastImageCtrl;
@@ -294,90 +294,90 @@  discard block
 block discarded – undo
294 294
 								}
295 295
 							/* ]]> */
296 296
 						</script>";
297
-					$ResourceManagerLoaded = true;
298
-				}
299
-				$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 . '\')" />';
297
+                    $ResourceManagerLoaded = true;
298
+                }
299
+                $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 . '\')" />';
300 300
 
301
-				break;
301
+                break;
302 302
 
303
-			case 'custom_tv':
304
-				$custom_output = '';
305
-				/* If we are loading a file */
306
-				if(substr($field_elements, 0, 5) == "@FILE") {
307
-					$file_name = MODX_BASE_PATH . trim(substr($field_elements, 6));
308
-					if(!file_exists($file_name)) {
309
-						$custom_output = $file_name . ' does not exist';
310
-					} else {
311
-						$custom_output = file_get_contents($file_name);
312
-					}
313
-				} elseif(substr($field_elements, 0, 8) == '@INCLUDE') {
314
-					$file_name = MODX_BASE_PATH . trim(substr($field_elements, 9));
315
-					if(!file_exists($file_name)) {
316
-						$custom_output = $file_name . ' does not exist';
317
-					} else {
318
-						ob_start();
319
-						include $file_name;
320
-						$custom_output = ob_get_contents();
321
-						ob_end_clean();
322
-					}
323
-				} elseif(substr($field_elements, 0, 6) == "@CHUNK") {
324
-					$chunk_name = trim(substr($field_elements, 7));
325
-					$chunk_body = $modx->getChunk($chunk_name);
326
-					if($chunk_body == false) {
327
-						$custom_output = $_lang['chunk_no_exist'] . '(' . $_lang['htmlsnippet_name'] . ':' . $chunk_name . ')';
328
-					} else {
329
-						$custom_output = $chunk_body;
330
-					}
331
-				} elseif(substr($field_elements, 0, 5) == "@EVAL") {
332
-					$eval_str = trim(substr($field_elements, 6));
333
-					$custom_output = eval($eval_str);
334
-				} else {
335
-					$custom_output = $field_elements;
336
-				}
337
-				$replacements = array(
338
-					'[+field_type+]' => $field_type,
339
-					'[+field_id+]' => $field_id,
340
-					'[+default_text+]' => $default_text,
341
-					'[+field_value+]' => $modx->htmlspecialchars($field_value),
342
-					'[+field_style+]' => $field_style,
343
-				);
344
-				$custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
345
-				$modx->documentObject = $content;
346
-				$modx->documentIdentifier = $content['id'];
347
-				$custom_output = $modx->parseDocumentSource($custom_output);
348
-				$field_html .= $custom_output;
349
-				break;
303
+            case 'custom_tv':
304
+                $custom_output = '';
305
+                /* If we are loading a file */
306
+                if(substr($field_elements, 0, 5) == "@FILE") {
307
+                    $file_name = MODX_BASE_PATH . trim(substr($field_elements, 6));
308
+                    if(!file_exists($file_name)) {
309
+                        $custom_output = $file_name . ' does not exist';
310
+                    } else {
311
+                        $custom_output = file_get_contents($file_name);
312
+                    }
313
+                } elseif(substr($field_elements, 0, 8) == '@INCLUDE') {
314
+                    $file_name = MODX_BASE_PATH . trim(substr($field_elements, 9));
315
+                    if(!file_exists($file_name)) {
316
+                        $custom_output = $file_name . ' does not exist';
317
+                    } else {
318
+                        ob_start();
319
+                        include $file_name;
320
+                        $custom_output = ob_get_contents();
321
+                        ob_end_clean();
322
+                    }
323
+                } elseif(substr($field_elements, 0, 6) == "@CHUNK") {
324
+                    $chunk_name = trim(substr($field_elements, 7));
325
+                    $chunk_body = $modx->getChunk($chunk_name);
326
+                    if($chunk_body == false) {
327
+                        $custom_output = $_lang['chunk_no_exist'] . '(' . $_lang['htmlsnippet_name'] . ':' . $chunk_name . ')';
328
+                    } else {
329
+                        $custom_output = $chunk_body;
330
+                    }
331
+                } elseif(substr($field_elements, 0, 5) == "@EVAL") {
332
+                    $eval_str = trim(substr($field_elements, 6));
333
+                    $custom_output = eval($eval_str);
334
+                } else {
335
+                    $custom_output = $field_elements;
336
+                }
337
+                $replacements = array(
338
+                    '[+field_type+]' => $field_type,
339
+                    '[+field_id+]' => $field_id,
340
+                    '[+default_text+]' => $default_text,
341
+                    '[+field_value+]' => $modx->htmlspecialchars($field_value),
342
+                    '[+field_style+]' => $field_style,
343
+                );
344
+                $custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
345
+                $modx->documentObject = $content;
346
+                $modx->documentIdentifier = $content['id'];
347
+                $custom_output = $modx->parseDocumentSource($custom_output);
348
+                $field_html .= $custom_output;
349
+                break;
350 350
 
351
-			default: // the default handler -- for errors, mostly
352
-				$field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' onchange="documentDirty=true;" />';
351
+            default: // the default handler -- for errors, mostly
352
+                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' onchange="documentDirty=true;" />';
353 353
 
354
-		} // end switch statement
355
-	} else {
356
-		$custom = explode(":", $field_type);
357
-		$custom_output = '';
358
-		$file_name = MODX_BASE_PATH . 'assets/tvs/' . $custom['1'] . '/' . $custom['1'] . '.customtv.php';
359
-		if(!file_exists($file_name)) {
360
-			$custom_output = $file_name . ' does not exist';
361
-		} else {
362
-			ob_start();
363
-			include $file_name;
364
-			$custom_output = ob_get_contents();
365
-			ob_end_clean();
366
-		}
367
-		$replacements = array(
368
-			'[+field_type+]' => $field_type,
369
-			'[+field_id+]' => $field_id,
370
-			'[+default_text+]' => $default_text,
371
-			'[+field_value+]' => $modx->htmlspecialchars($field_value),
372
-			'[+field_style+]' => $field_style,
373
-		);
374
-		$custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
375
-		$modx->documentObject = $content;
376
-		$custom_output = $modx->parseDocumentSource($custom_output);
377
-		$field_html .= $custom_output;
378
-	}
354
+        } // end switch statement
355
+    } else {
356
+        $custom = explode(":", $field_type);
357
+        $custom_output = '';
358
+        $file_name = MODX_BASE_PATH . 'assets/tvs/' . $custom['1'] . '/' . $custom['1'] . '.customtv.php';
359
+        if(!file_exists($file_name)) {
360
+            $custom_output = $file_name . ' does not exist';
361
+        } else {
362
+            ob_start();
363
+            include $file_name;
364
+            $custom_output = ob_get_contents();
365
+            ob_end_clean();
366
+        }
367
+        $replacements = array(
368
+            '[+field_type+]' => $field_type,
369
+            '[+field_id+]' => $field_id,
370
+            '[+default_text+]' => $default_text,
371
+            '[+field_value+]' => $modx->htmlspecialchars($field_value),
372
+            '[+field_style+]' => $field_style,
373
+        );
374
+        $custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
375
+        $modx->documentObject = $content;
376
+        $custom_output = $modx->parseDocumentSource($custom_output);
377
+        $field_html .= $custom_output;
378
+    }
379 379
 
380
-	return $field_html;
380
+    return $field_html;
381 381
 } // end renderFormElement function
382 382
 
383 383
 /**
@@ -385,14 +385,14 @@  discard block
 block discarded – undo
385 385
  * @return array
386 386
  */
387 387
 function ParseIntputOptions($v) {
388
-	global $modx;
389
-	$a = array();
390
-	if(is_array($v)) {
391
-		return $v;
392
-	} else if($modx->db->isResult($v)) {
393
-		while($cols = $modx->db->getRow($v, 'num')) $a[] = $cols;
394
-	} else {
395
-		$a = explode("||", $v);
396
-	}
397
-	return $a;
388
+    global $modx;
389
+    $a = array();
390
+    if(is_array($v)) {
391
+        return $v;
392
+    } else if($modx->db->isResult($v)) {
393
+        while($cols = $modx->db->getRow($v, 'num')) $a[] = $cols;
394
+    } else {
395
+        $a = explode("||", $v);
396
+    }
397
+    return $a;
398 398
 }
Please login to merge, or discard this patch.
manager/includes/template.parser.class.inc.php 1 patch
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -10,178 +10,178 @@
 block discarded – undo
10 10
 Class TemplateParser {
11 11
 
12 12
     /**
13
-	 * @param array $config [action, tabs, toArray]
14
-	 * @param array $data
15
-	 * @return string
16
-	 */
17
-	public function output($config = array(), $data = array()) {
18
-		global $modx;
19
-
20
-		$output = '';
21
-		$action = !empty($config['action']) ? $config['action'] : (!empty($_REQUEST['a']) ? $_REQUEST['a'] : '');
22
-		$tab = isset($config['tab']) ? ' AND tab IN(' . $config['tab'] . ')' : '';
23
-
24
-		if($action) {
25
-			$sql = $modx->db->query('SELECT t1.*, IF(t1.alias=\'\',t1.name,t1.alias) AS alias, t2.category AS category_name
13
+     * @param array $config [action, tabs, toArray]
14
+     * @param array $data
15
+     * @return string
16
+     */
17
+    public function output($config = array(), $data = array()) {
18
+        global $modx;
19
+
20
+        $output = '';
21
+        $action = !empty($config['action']) ? $config['action'] : (!empty($_REQUEST['a']) ? $_REQUEST['a'] : '');
22
+        $tab = isset($config['tab']) ? ' AND tab IN(' . $config['tab'] . ')' : '';
23
+
24
+        if($action) {
25
+            $sql = $modx->db->query('SELECT t1.*, IF(t1.alias=\'\',t1.name,t1.alias) AS alias, t2.category AS category_name
26 26
 			FROM ' . $modx->getFullTableName('system_templates') . ' AS t1
27 27
 			INNER JOIN ' . $modx->getFullTableName('categories') . ' AS t2 ON t2.id=t1.category
28 28
 			WHERE t1.action IN(' . $action . ') ' . $tab . '
29 29
 			ORDER BY t1.tab ASC, t1.rank ASC');
30 30
 
31
-			if($modx->db->getRecordCount($sql)) {
32
-				$tabs = array();
33
-				while($row = $modx->db->getRow($sql)) {
34
-					if(!$row['value'] && !empty($data[$row['name']])) {
35
-						$row['value'] = $data[$row['name']];
36
-					}
37
-					$tabs[$row['tab']]['category_name'] = $row['category_name'];
38
-					$tabs[$row['tab']][$row['name']] = TemplateParser::render($row);
39
-				}
40
-
41
-				if(!empty($config['toArray'])) {
42
-					$output = $tabs;
43
-				} else {
44
-					$output .= '<div class="tab-pane" id="pane_' . $action . '">';
45
-					$output .= '
31
+            if($modx->db->getRecordCount($sql)) {
32
+                $tabs = array();
33
+                while($row = $modx->db->getRow($sql)) {
34
+                    if(!$row['value'] && !empty($data[$row['name']])) {
35
+                        $row['value'] = $data[$row['name']];
36
+                    }
37
+                    $tabs[$row['tab']]['category_name'] = $row['category_name'];
38
+                    $tabs[$row['tab']][$row['name']] = TemplateParser::render($row);
39
+                }
40
+
41
+                if(!empty($config['toArray'])) {
42
+                    $output = $tabs;
43
+                } else {
44
+                    $output .= '<div class="tab-pane" id="pane_' . $action . '">';
45
+                    $output .= '
46 46
 					<script type="text/javascript">
47 47
 						var pane_' . $action . ' = new WebFXTabPane(document.getElementById("pane_' . $action . '"), ' . ($modx->config['remember_last_tab'] == 1 ? 'true' : 'false') . ');
48 48
 					</script>';
49 49
 
50
-					foreach($tabs as $idTab => $tab) {
51
-						$output .= '<div class="tab-page" id="tab_' . $action . '_' . $idTab . '">';
52
-						$output .= '
50
+                    foreach($tabs as $idTab => $tab) {
51
+                        $output .= '<div class="tab-page" id="tab_' . $action . '_' . $idTab . '">';
52
+                        $output .= '
53 53
 						<h2 class="tab">' . (!empty($config['tabs'][$idTab]) ? $config['tabs'][$idTab] : $tab['category_name']) . '</h2>
54 54
 						<script type="text/javascript">pane_' . $action . '.addTabPage(document.getElementById("tab_' . $action . '_' . $idTab . '"));</script>';
55
-						unset($tab['category_name']);
56
-						foreach($tab as $item) {
57
-							$output .= $item;
58
-						}
59
-						$output .= '</div>';
60
-					}
61
-					$output .= '</div>';
62
-				}
63
-			}
64
-		}
65
-
66
-		return $output;
67
-	}
55
+                        unset($tab['category_name']);
56
+                        foreach($tab as $item) {
57
+                            $output .= $item;
58
+                        }
59
+                        $output .= '</div>';
60
+                    }
61
+                    $output .= '</div>';
62
+                }
63
+            }
64
+        }
65
+
66
+        return $output;
67
+    }
68 68
 
69 69
     /**
70 70
      * @param array $data
71 71
      * @return string
72 72
      */
73
-	private function render($data) {
74
-		global $modx, $_lang, $_country_lang;
73
+    private function render($data) {
74
+        global $modx, $_lang, $_country_lang;
75 75
 
76
-		$data['lang.name'] = (isset($_lang[$data['alias']]) ? $_lang[$data['alias']] : $data['alias']);
77
-		$data['value'] = (isset($_POST[$data['name']][$data['value']]) ? $_POST[$data['name']][$data['value']] : (isset($data['value']) ? $modx->htmlspecialchars($data['value']) : ''));
78
-		$data['readonly'] = ($data['readonly'] ? ' readonly' : '');
76
+        $data['lang.name'] = (isset($_lang[$data['alias']]) ? $_lang[$data['alias']] : $data['alias']);
77
+        $data['value'] = (isset($_POST[$data['name']][$data['value']]) ? $_POST[$data['name']][$data['value']] : (isset($data['value']) ? $modx->htmlspecialchars($data['value']) : ''));
78
+        $data['readonly'] = ($data['readonly'] ? ' readonly' : '');
79 79
 
80
-		$output = '';
81
-		$output .= '<div class="form-group row">';
80
+        $output = '';
81
+        $output .= '<div class="form-group row">';
82 82
 
83
-		switch($data['type']) {
83
+        switch($data['type']) {
84 84
 
85
-			case 'text':
86
-				$output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>
85
+            case 'text':
86
+                $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>
87 87
 					<div class="col-sm-7">
88 88
 					<input type="text" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />';
89
-				$output .= $data['content'];
90
-				$output .= '</div>';
89
+                $output .= $data['content'];
90
+                $output .= '</div>';
91 91
 
92
-				break;
92
+                break;
93 93
 
94
-			case 'textarea':
95
-				$output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>
94
+            case 'textarea':
95
+                $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>
96 96
 					<div class="col-sm-7">
97 97
 					<textarea name="[+name+]" class="form-control" id="[+name+]" onChange="documentDirty=true;"[+readonly+]>[+value+]</textarea>';
98
-				$output .= $data['content'];
99
-				$output .= '</div>';
98
+                $output .= $data['content'];
99
+                $output .= '</div>';
100 100
 
101
-				break;
101
+                break;
102 102
 
103
-			case 'date':
104
-				$data['value'] = (isset($_POST[$data['name']][$data['value']]) ? $modx->toDateFormat($_POST[$data['name']][$data['value']]) : (isset($data['value']) ? $modx->toDateFormat($data['value']) : ''));
105
-				$output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>
103
+            case 'date':
104
+                $data['value'] = (isset($_POST[$data['name']][$data['value']]) ? $modx->toDateFormat($_POST[$data['name']][$data['value']]) : (isset($data['value']) ? $modx->toDateFormat($data['value']) : ''));
105
+                $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>
106 106
 					<div class="col-sm-7">
107 107
 					<input type="text" name="[+name+]" class="form-control DatePicker" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />';
108
-				$output .= $data['content'];
109
-				$output .= '</div>';
110
-
111
-				break;
112
-
113
-			case 'select':
114
-				$output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>';
115
-				$output .= '<div class="col-sm-7">';
116
-				$output .= '<select name="[+name+]" class="form-control" id="[+name+]" onChange="documentDirty=true;">';
117
-				if($data['name'] == 'country' && isset($_country_lang)) {
118
-					$chosenCountry = isset($_POST['country']) ? $_POST['country'] : $data['country'];
119
-					$output .= '<option value=""' . (!isset($chosenCountry) ? ' selected' : '') . '>&nbsp;</option>';
120
-					foreach($_country_lang as $key => $value) {
121
-						$output .= '<option value="' . $key . '"' . (isset($chosenCountry) && $chosenCountry == $key ? ' selected' : '') . '>' . $value . '</option>';
122
-					}
123
-				} else {
124
-					if($data['elements']) {
125
-						$elements = explode('||', $data['elements']);
126
-						foreach($elements as $key => $value) {
127
-							$value = explode('==', $value);
128
-							$output .= '<option value="' . $value[1] . '">' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]) . '</option>';
129
-						}
130
-					}
131
-				}
132
-				$output .= '</select>';
133
-				$output .= $data['content'];
134
-				$output .= '</div>';
135
-
136
-				break;
137
-
138
-			case 'checkbox':
139
-				$output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>';
140
-				$output .= '<div class="col-sm-7">';
141
-				$output .= '<input type="checkbox" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />';
142
-				if($data['elements']) {
143
-					$elements = explode('||', $data['elements']);
144
-					foreach($elements as $key => $value) {
145
-						$value = explode('==', $value);
146
-						$output .= '<br /><input type="checkbox" name="' . $value[0] . '" class="form-control" id="' . $value[0] . '" value="' . $value[1] . '" onChange="documentDirty=true;"[+readonly+] /> ' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]);
147
-					}
148
-				}
149
-				$output .= $data['content'];
150
-				$output .= '</div>';
151
-
152
-				break;
153
-
154
-			case 'radio':
155
-				$output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>';
156
-				$output .= '<div class="col-sm-7">';
157
-				$output .= '<input type="radio" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />';
158
-				if($data['elements']) {
159
-					$elements = explode('||', $data['elements']);
160
-					foreach($elements as $key => $value) {
161
-						$value = explode('==', $value);
162
-						$output .= '<br /><input type="radio" name="[+name+]" class="form-control" id="[+name+]_' . $key . '" value="' . $value[1] . '" onChange="documentDirty=true;"[+readonly+] /> ' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]);
163
-					}
164
-				}
165
-				$output .= $data['content'];
166
-				$output .= '</div>';
167
-
168
-				break;
169
-
170
-			case 'custom':
171
-				$output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>';
172
-				$output .= '<div class="col-sm-7">';
173
-				$output .= $data['content'];
174
-				$output .= '</div>';
175
-
176
-				break;
177
-		}
178
-
179
-		$output .= '</div>';
180
-
181
-		$output = $modx->parseText($output, $data);
182
-
183
-		return $output;
184
-	}
108
+                $output .= $data['content'];
109
+                $output .= '</div>';
110
+
111
+                break;
112
+
113
+            case 'select':
114
+                $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>';
115
+                $output .= '<div class="col-sm-7">';
116
+                $output .= '<select name="[+name+]" class="form-control" id="[+name+]" onChange="documentDirty=true;">';
117
+                if($data['name'] == 'country' && isset($_country_lang)) {
118
+                    $chosenCountry = isset($_POST['country']) ? $_POST['country'] : $data['country'];
119
+                    $output .= '<option value=""' . (!isset($chosenCountry) ? ' selected' : '') . '>&nbsp;</option>';
120
+                    foreach($_country_lang as $key => $value) {
121
+                        $output .= '<option value="' . $key . '"' . (isset($chosenCountry) && $chosenCountry == $key ? ' selected' : '') . '>' . $value . '</option>';
122
+                    }
123
+                } else {
124
+                    if($data['elements']) {
125
+                        $elements = explode('||', $data['elements']);
126
+                        foreach($elements as $key => $value) {
127
+                            $value = explode('==', $value);
128
+                            $output .= '<option value="' . $value[1] . '">' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]) . '</option>';
129
+                        }
130
+                    }
131
+                }
132
+                $output .= '</select>';
133
+                $output .= $data['content'];
134
+                $output .= '</div>';
135
+
136
+                break;
137
+
138
+            case 'checkbox':
139
+                $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>';
140
+                $output .= '<div class="col-sm-7">';
141
+                $output .= '<input type="checkbox" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />';
142
+                if($data['elements']) {
143
+                    $elements = explode('||', $data['elements']);
144
+                    foreach($elements as $key => $value) {
145
+                        $value = explode('==', $value);
146
+                        $output .= '<br /><input type="checkbox" name="' . $value[0] . '" class="form-control" id="' . $value[0] . '" value="' . $value[1] . '" onChange="documentDirty=true;"[+readonly+] /> ' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]);
147
+                    }
148
+                }
149
+                $output .= $data['content'];
150
+                $output .= '</div>';
151
+
152
+                break;
153
+
154
+            case 'radio':
155
+                $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>';
156
+                $output .= '<div class="col-sm-7">';
157
+                $output .= '<input type="radio" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />';
158
+                if($data['elements']) {
159
+                    $elements = explode('||', $data['elements']);
160
+                    foreach($elements as $key => $value) {
161
+                        $value = explode('==', $value);
162
+                        $output .= '<br /><input type="radio" name="[+name+]" class="form-control" id="[+name+]_' . $key . '" value="' . $value[1] . '" onChange="documentDirty=true;"[+readonly+] /> ' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]);
163
+                    }
164
+                }
165
+                $output .= $data['content'];
166
+                $output .= '</div>';
167
+
168
+                break;
169
+
170
+            case 'custom':
171
+                $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>';
172
+                $output .= '<div class="col-sm-7">';
173
+                $output .= $data['content'];
174
+                $output .= '</div>';
175
+
176
+                break;
177
+        }
178
+
179
+        $output .= '</div>';
180
+
181
+        $output = $modx->parseText($output, $data);
182
+
183
+        return $output;
184
+    }
185 185
 
186 186
 }
187 187
 
Please login to merge, or discard this patch.
manager/includes/tmplvars.format.inc.php 1 patch
Indentation   +322 added lines, -322 removed lines patch added patch discarded remove patch
@@ -17,324 +17,324 @@  discard block
 block discarded – undo
17 17
  */
18 18
 function getTVDisplayFormat($name, $value, $format, $paramstring = "", $tvtype = "", $docid = "", $sep = '') {
19 19
 
20
-	global $modx;
20
+    global $modx;
21 21
     $o = '';
22 22
 
23 23
     // process any TV commands in value
24
-	$docid = (int)$docid > 0 ? (int)$docid : $modx->documentIdentifier;
25
-	$value = ProcessTVCommand($value, $name, $docid);
24
+    $docid = (int)$docid > 0 ? (int)$docid : $modx->documentIdentifier;
25
+    $value = ProcessTVCommand($value, $name, $docid);
26 26
 
27
-	$params = array();
28
-	if($paramstring) {
29
-		$cp = explode("&", $paramstring);
30
-		foreach($cp as $p => $v) {
31
-			$v = trim($v); // trim
32
-			$ar = explode("=", $v);
33
-			if(is_array($ar) && count($ar) == 2) {
34
-				$params[$ar[0]] = decodeParamValue($ar[1]);
35
-			}
36
-		}
37
-	}
27
+    $params = array();
28
+    if($paramstring) {
29
+        $cp = explode("&", $paramstring);
30
+        foreach($cp as $p => $v) {
31
+            $v = trim($v); // trim
32
+            $ar = explode("=", $v);
33
+            if(is_array($ar) && count($ar) == 2) {
34
+                $params[$ar[0]] = decodeParamValue($ar[1]);
35
+            }
36
+        }
37
+    }
38 38
 
39
-	$id = "tv$name";
40
-	switch($format) {
41
-		case 'image':
42
-			$images = parseInput($value, '||', 'array');
43
-			foreach($images as $image) {
44
-				if(!is_array($image)) {
45
-					$image = explode('==', $image);
46
-				}
47
-				$src = $image[0];
39
+    $id = "tv$name";
40
+    switch($format) {
41
+        case 'image':
42
+            $images = parseInput($value, '||', 'array');
43
+            foreach($images as $image) {
44
+                if(!is_array($image)) {
45
+                    $image = explode('==', $image);
46
+                }
47
+                $src = $image[0];
48 48
 
49
-				if($src) {
50
-					// We have a valid source
51
-					$attributes = '';
52
-					$attr = array(
53
-						'class' => $params['class'],
54
-						'src' => $src,
55
-						'id' => ($params['id'] ? $params['id'] : ''),
56
-						'alt' => $modx->htmlspecialchars($params['alttext']),
57
-						'style' => $params['style']
58
-					);
59
-					if(isset($params['align']) && $params['align'] != 'none') {
60
-						$attr['align'] = $params['align'];
61
-					}
62
-					foreach($attr as $k => $v) $attributes .= ($v ? ' ' . $k . '="' . $v . '"' : '');
63
-					$attributes .= ' ' . $params['attrib'];
49
+                if($src) {
50
+                    // We have a valid source
51
+                    $attributes = '';
52
+                    $attr = array(
53
+                        'class' => $params['class'],
54
+                        'src' => $src,
55
+                        'id' => ($params['id'] ? $params['id'] : ''),
56
+                        'alt' => $modx->htmlspecialchars($params['alttext']),
57
+                        'style' => $params['style']
58
+                    );
59
+                    if(isset($params['align']) && $params['align'] != 'none') {
60
+                        $attr['align'] = $params['align'];
61
+                    }
62
+                    foreach($attr as $k => $v) $attributes .= ($v ? ' ' . $k . '="' . $v . '"' : '');
63
+                    $attributes .= ' ' . $params['attrib'];
64 64
 
65
-					// Output the image with attributes
66
-					$o .= '<img' . rtrim($attributes) . ' />';
67
-				}
68
-			}
69
-			break;
65
+                    // Output the image with attributes
66
+                    $o .= '<img' . rtrim($attributes) . ' />';
67
+                }
68
+            }
69
+            break;
70 70
 
71
-		case "delim":    // display as delimitted list
72
-			$value = parseInput($value, "||");
73
-			$p = $params['format'] ? $params['format'] : " ";
74
-			if($p == "\\n") {
75
-				$p = "\n";
76
-			}
77
-			$o = str_replace("||", $p, $value);
78
-			break;
71
+        case "delim":    // display as delimitted list
72
+            $value = parseInput($value, "||");
73
+            $p = $params['format'] ? $params['format'] : " ";
74
+            if($p == "\\n") {
75
+                $p = "\n";
76
+            }
77
+            $o = str_replace("||", $p, $value);
78
+            break;
79 79
 
80
-		case "string":
81
-			$value = parseInput($value);
82
-			$format = strtolower($params['format']);
83
-			if($format == 'upper case') {
84
-				$o = strtoupper($value);
85
-			} else if($format == 'lower case') {
86
-				$o = strtolower($value);
87
-			} else if($format == 'sentence case') {
88
-				$o = ucfirst($value);
89
-			} else if($format == 'capitalize') {
90
-				$o = ucwords($value);
91
-			} else {
92
-				$o = $value;
93
-			}
94
-			break;
80
+        case "string":
81
+            $value = parseInput($value);
82
+            $format = strtolower($params['format']);
83
+            if($format == 'upper case') {
84
+                $o = strtoupper($value);
85
+            } else if($format == 'lower case') {
86
+                $o = strtolower($value);
87
+            } else if($format == 'sentence case') {
88
+                $o = ucfirst($value);
89
+            } else if($format == 'capitalize') {
90
+                $o = ucwords($value);
91
+            } else {
92
+                $o = $value;
93
+            }
94
+            break;
95 95
 
96
-		case "date":
97
-			if($value != '' || $params['default'] == 'Yes') {
98
-				if(empty($value)) {
99
-					$value = 'now';
100
-				}
101
-				$timestamp = getUnixtimeFromDateString($value);
102
-				$p = $params['format'] ? $params['format'] : "%A %d, %B %Y";
103
-				$o = strftime($p, $timestamp);
104
-			} else {
105
-				$value = '';
106
-			}
107
-			break;
96
+        case "date":
97
+            if($value != '' || $params['default'] == 'Yes') {
98
+                if(empty($value)) {
99
+                    $value = 'now';
100
+                }
101
+                $timestamp = getUnixtimeFromDateString($value);
102
+                $p = $params['format'] ? $params['format'] : "%A %d, %B %Y";
103
+                $o = strftime($p, $timestamp);
104
+            } else {
105
+                $value = '';
106
+            }
107
+            break;
108 108
 
109
-		case "hyperlink":
110
-			$value = parseInput($value, "||", "array");
111
-			$o = '';
112
-			$countValue = count($value);
113
-			for($i = 0; $i < $countValue; $i++) {
114
-				list($name, $url) = is_array($value[$i]) ? $value[$i] : explode("==", $value[$i]);
115
-				if(!$url) {
116
-					$url = $name;
117
-				}
118
-				if($url) {
119
-					if($o) {
120
-						$o .= '<br />';
121
-					}
122
-					$attributes = '';
123
-					// setup the link attributes
124
-					$attr = array(
125
-						'href' => $url,
126
-						'title' => $params['title'] ? $modx->htmlspecialchars($params['title']) : $name,
127
-						'class' => $params['class'],
128
-						'style' => $params['style'],
129
-						'target' => $params['target'],
130
-					);
131
-					foreach($attr as $k => $v) $attributes .= ($v ? ' ' . $k . '="' . $v . '"' : '');
132
-					$attributes .= ' ' . $params['attrib']; // add extra
109
+        case "hyperlink":
110
+            $value = parseInput($value, "||", "array");
111
+            $o = '';
112
+            $countValue = count($value);
113
+            for($i = 0; $i < $countValue; $i++) {
114
+                list($name, $url) = is_array($value[$i]) ? $value[$i] : explode("==", $value[$i]);
115
+                if(!$url) {
116
+                    $url = $name;
117
+                }
118
+                if($url) {
119
+                    if($o) {
120
+                        $o .= '<br />';
121
+                    }
122
+                    $attributes = '';
123
+                    // setup the link attributes
124
+                    $attr = array(
125
+                        'href' => $url,
126
+                        'title' => $params['title'] ? $modx->htmlspecialchars($params['title']) : $name,
127
+                        'class' => $params['class'],
128
+                        'style' => $params['style'],
129
+                        'target' => $params['target'],
130
+                    );
131
+                    foreach($attr as $k => $v) $attributes .= ($v ? ' ' . $k . '="' . $v . '"' : '');
132
+                    $attributes .= ' ' . $params['attrib']; // add extra
133 133
 
134
-					// Output the link
135
-					$o .= '<a' . rtrim($attributes) . '>' . ($params['text'] ? $modx->htmlspecialchars($params['text']) : $name) . '</a>';
136
-				}
137
-			}
138
-			break;
134
+                    // Output the link
135
+                    $o .= '<a' . rtrim($attributes) . '>' . ($params['text'] ? $modx->htmlspecialchars($params['text']) : $name) . '</a>';
136
+                }
137
+            }
138
+            break;
139 139
 
140
-		case "htmltag":
141
-			$value = parseInput($value, "||", "array");
142
-			$tagid = $params['tagid'];
143
-			$tagname = ($params['tagname']) ? $params['tagname'] : 'div';
144
-			$o = '';
145
-			// Loop through a list of tags
140
+        case "htmltag":
141
+            $value = parseInput($value, "||", "array");
142
+            $tagid = $params['tagid'];
143
+            $tagname = ($params['tagname']) ? $params['tagname'] : 'div';
144
+            $o = '';
145
+            // Loop through a list of tags
146 146
             $countValue = count($value);
147
-			for($i = 0; $i < $countValue; $i++) {
148
-				$tagvalue = is_array($value[$i]) ? implode(' ', $value[$i]) : $value[$i];
149
-				if(!$tagvalue) {
150
-					continue;
151
-				}
147
+            for($i = 0; $i < $countValue; $i++) {
148
+                $tagvalue = is_array($value[$i]) ? implode(' ', $value[$i]) : $value[$i];
149
+                if(!$tagvalue) {
150
+                    continue;
151
+                }
152 152
 
153
-				$attributes = '';
154
-				$attr = array(
155
-					'id' => ($tagid ? $tagid : $id),
156
-					// 'tv' already added to id
157
-					'class' => $params['class'],
158
-					'style' => $params['style'],
159
-				);
160
-				foreach($attr as $k => $v) $attributes .= ($v ? ' ' . $k . '="' . $v . '"' : '');
161
-				$attributes .= ' ' . $params['attrib']; // add extra
153
+                $attributes = '';
154
+                $attr = array(
155
+                    'id' => ($tagid ? $tagid : $id),
156
+                    // 'tv' already added to id
157
+                    'class' => $params['class'],
158
+                    'style' => $params['style'],
159
+                );
160
+                foreach($attr as $k => $v) $attributes .= ($v ? ' ' . $k . '="' . $v . '"' : '');
161
+                $attributes .= ' ' . $params['attrib']; // add extra
162 162
 
163
-				// Output the HTML Tag
164
-				$o .= '<' . $tagname . rtrim($attributes) . '>' . $tagvalue . '</' . $tagname . '>';
165
-			}
166
-			break;
163
+                // Output the HTML Tag
164
+                $o .= '<' . $tagname . rtrim($attributes) . '>' . $tagvalue . '</' . $tagname . '>';
165
+            }
166
+            break;
167 167
 
168
-		case "richtext":
169
-			$value = parseInput($value);
170
-			$w = $params['w'] ? $params['w'] : '100%';
171
-			$h = $params['h'] ? $params['h'] : '400px';
172
-			$richtexteditor = $params['edt'] ? $params['edt'] : "";
173
-			$o = '<div class="MODX_RichTextWidget"><textarea id="' . $id . '" name="' . $id . '" style="width:' . $w . '; height:' . $h . ';">';
174
-			$o .= $modx->htmlspecialchars($value);
175
-			$o .= '</textarea></div>';
176
-			$replace_richtext = array($id);
177
-			// setup editors
178
-			if(!empty($replace_richtext) && !empty($richtexteditor)) {
179
-				// invoke OnRichTextEditorInit event
180
-				$evtOut = $modx->invokeEvent("OnRichTextEditorInit", array(
181
-					'editor' => $richtexteditor,
182
-					'elements' => $replace_richtext,
183
-					'forfrontend' => 1,
184
-					'width' => $w,
185
-					'height' => $h
186
-				));
187
-				if(is_array($evtOut)) {
188
-					$o .= implode("", $evtOut);
189
-				}
190
-			}
191
-			break;
168
+        case "richtext":
169
+            $value = parseInput($value);
170
+            $w = $params['w'] ? $params['w'] : '100%';
171
+            $h = $params['h'] ? $params['h'] : '400px';
172
+            $richtexteditor = $params['edt'] ? $params['edt'] : "";
173
+            $o = '<div class="MODX_RichTextWidget"><textarea id="' . $id . '" name="' . $id . '" style="width:' . $w . '; height:' . $h . ';">';
174
+            $o .= $modx->htmlspecialchars($value);
175
+            $o .= '</textarea></div>';
176
+            $replace_richtext = array($id);
177
+            // setup editors
178
+            if(!empty($replace_richtext) && !empty($richtexteditor)) {
179
+                // invoke OnRichTextEditorInit event
180
+                $evtOut = $modx->invokeEvent("OnRichTextEditorInit", array(
181
+                    'editor' => $richtexteditor,
182
+                    'elements' => $replace_richtext,
183
+                    'forfrontend' => 1,
184
+                    'width' => $w,
185
+                    'height' => $h
186
+                ));
187
+                if(is_array($evtOut)) {
188
+                    $o .= implode("", $evtOut);
189
+                }
190
+            }
191
+            break;
192 192
 
193
-		case "unixtime":
194
-			$value = parseInput($value);
195
-			$o = getUnixtimeFromDateString($value);
196
-			break;
193
+        case "unixtime":
194
+            $value = parseInput($value);
195
+            $o = getUnixtimeFromDateString($value);
196
+            break;
197 197
 
198
-		case "viewport":
199
-			$value = parseInput($value);
200
-			$id = '_' . time();
201
-			if(!$params['vpid']) {
202
-				$params['vpid'] = $id;
203
-			}
204
-			$sTag = "<iframe";
205
-			$eTag = "</iframe>";
206
-			$autoMode = "0";
207
-			$w = $params['width'];
208
-			$h = $params['height'];
209
-			if($params['stretch'] == 'Yes') {
210
-				$w = "100%";
211
-				$h = "100%";
212
-			}
213
-			if($params['asize'] == 'Yes' || ($params['awidth'] == 'Yes' && $params['aheight'] == 'Yes')) {
214
-				$autoMode = "3";  //both
215
-			} else if($params['awidth'] == 'Yes') {
216
-				$autoMode = "1"; //width only
217
-			} else if($params['aheight'] == 'Yes') {
218
-				$autoMode = "2";    //height only
219
-			}
198
+        case "viewport":
199
+            $value = parseInput($value);
200
+            $id = '_' . time();
201
+            if(!$params['vpid']) {
202
+                $params['vpid'] = $id;
203
+            }
204
+            $sTag = "<iframe";
205
+            $eTag = "</iframe>";
206
+            $autoMode = "0";
207
+            $w = $params['width'];
208
+            $h = $params['height'];
209
+            if($params['stretch'] == 'Yes') {
210
+                $w = "100%";
211
+                $h = "100%";
212
+            }
213
+            if($params['asize'] == 'Yes' || ($params['awidth'] == 'Yes' && $params['aheight'] == 'Yes')) {
214
+                $autoMode = "3";  //both
215
+            } else if($params['awidth'] == 'Yes') {
216
+                $autoMode = "1"; //width only
217
+            } else if($params['aheight'] == 'Yes') {
218
+                $autoMode = "2";    //height only
219
+            }
220 220
 
221
-			$modx->regClientStartupScript(MODX_MANAGER_URL . "media/script/bin/viewport.js", array(
222
-				'name' => 'viewport',
223
-				'version' => '0',
224
-				'plaintext' => false
225
-			));
226
-			$o = $sTag . " id='" . $params['vpid'] . "' name='" . $params['vpid'] . "' ";
227
-			if($params['class']) {
228
-				$o .= " class='" . $params['class'] . "' ";
229
-			}
230
-			if($params['style']) {
231
-				$o .= " style='" . $params['style'] . "' ";
232
-			}
233
-			if($params['attrib']) {
234
-				$o .= $params['attrib'] . " ";
235
-			}
236
-			$o .= "scrolling='" . ($params['sbar'] == 'No' ? "no" : ($params['sbar'] == 'Yes' ? "yes" : "auto")) . "' ";
237
-			$o .= "src='" . $value . "' frameborder='" . $params['borsize'] . "' ";
238
-			$o .= "onload=\"window.setTimeout('ResizeViewPort(\\'" . $params['vpid'] . "\\'," . $autoMode . ")',100);\" width='" . $w . "' height='" . $h . "' ";
239
-			$o .= ">";
240
-			$o .= $eTag;
241
-			break;
221
+            $modx->regClientStartupScript(MODX_MANAGER_URL . "media/script/bin/viewport.js", array(
222
+                'name' => 'viewport',
223
+                'version' => '0',
224
+                'plaintext' => false
225
+            ));
226
+            $o = $sTag . " id='" . $params['vpid'] . "' name='" . $params['vpid'] . "' ";
227
+            if($params['class']) {
228
+                $o .= " class='" . $params['class'] . "' ";
229
+            }
230
+            if($params['style']) {
231
+                $o .= " style='" . $params['style'] . "' ";
232
+            }
233
+            if($params['attrib']) {
234
+                $o .= $params['attrib'] . " ";
235
+            }
236
+            $o .= "scrolling='" . ($params['sbar'] == 'No' ? "no" : ($params['sbar'] == 'Yes' ? "yes" : "auto")) . "' ";
237
+            $o .= "src='" . $value . "' frameborder='" . $params['borsize'] . "' ";
238
+            $o .= "onload=\"window.setTimeout('ResizeViewPort(\\'" . $params['vpid'] . "\\'," . $autoMode . ")',100);\" width='" . $w . "' height='" . $h . "' ";
239
+            $o .= ">";
240
+            $o .= $eTag;
241
+            break;
242 242
 
243
-		case "datagrid":
244
-			include_once MODX_MANAGER_PATH . "includes/controls/datagrid.class.php";
245
-			$grd = new DataGrid('', $value);
243
+        case "datagrid":
244
+            include_once MODX_MANAGER_PATH . "includes/controls/datagrid.class.php";
245
+            $grd = new DataGrid('', $value);
246 246
 
247
-			$grd->noRecordMsg = $params['egmsg'];
247
+            $grd->noRecordMsg = $params['egmsg'];
248 248
 
249
-			$grd->columnHeaderClass = $params['chdrc'];
250
-			$grd->cssClass = $params['tblc'];
251
-			$grd->itemClass = $params['itmc'];
252
-			$grd->altItemClass = $params['aitmc'];
249
+            $grd->columnHeaderClass = $params['chdrc'];
250
+            $grd->cssClass = $params['tblc'];
251
+            $grd->itemClass = $params['itmc'];
252
+            $grd->altItemClass = $params['aitmc'];
253 253
 
254
-			$grd->columnHeaderStyle = $params['chdrs'];
255
-			$grd->cssStyle = $params['tbls'];
256
-			$grd->itemStyle = $params['itms'];
257
-			$grd->altItemStyle = $params['aitms'];
254
+            $grd->columnHeaderStyle = $params['chdrs'];
255
+            $grd->cssStyle = $params['tbls'];
256
+            $grd->itemStyle = $params['itms'];
257
+            $grd->altItemStyle = $params['aitms'];
258 258
 
259
-			$grd->columns = $params['cols'];
260
-			$grd->fields = $params['flds'];
261
-			$grd->colWidths = $params['cwidth'];
262
-			$grd->colAligns = $params['calign'];
263
-			$grd->colColors = $params['ccolor'];
264
-			$grd->colTypes = $params['ctype'];
259
+            $grd->columns = $params['cols'];
260
+            $grd->fields = $params['flds'];
261
+            $grd->colWidths = $params['cwidth'];
262
+            $grd->colAligns = $params['calign'];
263
+            $grd->colColors = $params['ccolor'];
264
+            $grd->colTypes = $params['ctype'];
265 265
 
266
-			$grd->cellPadding = $params['cpad'];
267
-			$grd->cellSpacing = $params['cspace'];
268
-			$grd->header = $params['head'];
269
-			$grd->footer = $params['foot'];
270
-			$grd->pageSize = $params['psize'];
271
-			$grd->pagerLocation = $params['ploc'];
272
-			$grd->pagerClass = $params['pclass'];
273
-			$grd->pagerStyle = $params['pstyle'];
274
-			$o = $grd->render();
275
-			break;
266
+            $grd->cellPadding = $params['cpad'];
267
+            $grd->cellSpacing = $params['cspace'];
268
+            $grd->header = $params['head'];
269
+            $grd->footer = $params['foot'];
270
+            $grd->pageSize = $params['psize'];
271
+            $grd->pagerLocation = $params['ploc'];
272
+            $grd->pagerClass = $params['pclass'];
273
+            $grd->pagerStyle = $params['pstyle'];
274
+            $o = $grd->render();
275
+            break;
276 276
 
277
-		case 'htmlentities':
278
-			$value = parseInput($value);
279
-			if($tvtype == 'checkbox' || $tvtype == 'listbox-multiple') {
280
-				// remove delimiter from checkbox and listbox-multiple TVs
281
-				$value = str_replace('||', '', $value);
282
-			}
283
-			$o = htmlentities($value, ENT_NOQUOTES, $modx->config['modx_charset']);
284
-			break;
277
+        case 'htmlentities':
278
+            $value = parseInput($value);
279
+            if($tvtype == 'checkbox' || $tvtype == 'listbox-multiple') {
280
+                // remove delimiter from checkbox and listbox-multiple TVs
281
+                $value = str_replace('||', '', $value);
282
+            }
283
+            $o = htmlentities($value, ENT_NOQUOTES, $modx->config['modx_charset']);
284
+            break;
285 285
 
286
-		case 'custom_widget':
287
-			$widget_output = '';
288
-			$o = '';
289
-			/* If we are loading a file */
290
-			if(substr($params['output'], 0, 5) == "@FILE") {
291
-				$file_name = MODX_BASE_PATH . trim(substr($params['output'], 6));
292
-				if(!file_exists($file_name)) {
293
-					$widget_output = $file_name . ' does not exist';
294
-				} else {
295
-					$widget_output = file_get_contents($file_name);
296
-				}
297
-			} elseif(substr($params['output'], 0, 8) == '@INCLUDE') {
298
-				$file_name = MODX_BASE_PATH . trim(substr($params['output'], 9));
299
-				if(!file_exists($file_name)) {
300
-					$widget_output = $file_name . ' does not exist';
301
-				} else {
302
-					/* The included file needs to set $widget_output. Can be string, array, object */
303
-					include $file_name;
304
-				}
305
-			} elseif(substr($params['output'], 0, 6) == '@CHUNK' && $value !== '') {
306
-				$chunk_name = trim(substr($params['output'], 7));
307
-				$widget_output = $modx->getChunk($chunk_name);
308
-			} elseif(substr($params['output'], 0, 5) == '@EVAL' && $value !== '') {
309
-				$eval_str = trim(substr($params['output'], 6));
310
-				$widget_output = eval($eval_str);
311
-			} elseif($value !== '') {
312
-				$widget_output = $params['output'];
313
-			} else {
314
-				$widget_output = '';
315
-			}
316
-			if(is_string($widget_output)) {
317
-				$_ = $modx->config['enable_filter'];
318
-				$modx->config['enable_filter'] = 1;
319
-				$widget_output = $modx->parseText($widget_output, array('value' => $value));
320
-				$modx->config['enable_filter'] = $_;
321
-				$o = $modx->parseDocumentSource($widget_output);
322
-			} else {
323
-				$o = $widget_output;
324
-			}
325
-			break;
286
+        case 'custom_widget':
287
+            $widget_output = '';
288
+            $o = '';
289
+            /* If we are loading a file */
290
+            if(substr($params['output'], 0, 5) == "@FILE") {
291
+                $file_name = MODX_BASE_PATH . trim(substr($params['output'], 6));
292
+                if(!file_exists($file_name)) {
293
+                    $widget_output = $file_name . ' does not exist';
294
+                } else {
295
+                    $widget_output = file_get_contents($file_name);
296
+                }
297
+            } elseif(substr($params['output'], 0, 8) == '@INCLUDE') {
298
+                $file_name = MODX_BASE_PATH . trim(substr($params['output'], 9));
299
+                if(!file_exists($file_name)) {
300
+                    $widget_output = $file_name . ' does not exist';
301
+                } else {
302
+                    /* The included file needs to set $widget_output. Can be string, array, object */
303
+                    include $file_name;
304
+                }
305
+            } elseif(substr($params['output'], 0, 6) == '@CHUNK' && $value !== '') {
306
+                $chunk_name = trim(substr($params['output'], 7));
307
+                $widget_output = $modx->getChunk($chunk_name);
308
+            } elseif(substr($params['output'], 0, 5) == '@EVAL' && $value !== '') {
309
+                $eval_str = trim(substr($params['output'], 6));
310
+                $widget_output = eval($eval_str);
311
+            } elseif($value !== '') {
312
+                $widget_output = $params['output'];
313
+            } else {
314
+                $widget_output = '';
315
+            }
316
+            if(is_string($widget_output)) {
317
+                $_ = $modx->config['enable_filter'];
318
+                $modx->config['enable_filter'] = 1;
319
+                $widget_output = $modx->parseText($widget_output, array('value' => $value));
320
+                $modx->config['enable_filter'] = $_;
321
+                $o = $modx->parseDocumentSource($widget_output);
322
+            } else {
323
+                $o = $widget_output;
324
+            }
325
+            break;
326 326
 
327
-		default:
328
-			$value = parseInput($value);
329
-			if($tvtype == 'checkbox' || $tvtype == 'listbox-multiple') {
330
-				// add separator
331
-				$value = explode('||', $value);
332
-				$value = implode($sep, $value);
333
-			}
334
-			$o = $value;
335
-			break;
336
-	}
337
-	return $o;
327
+        default:
328
+            $value = parseInput($value);
329
+            if($tvtype == 'checkbox' || $tvtype == 'listbox-multiple') {
330
+                // add separator
331
+                $value = explode('||', $value);
332
+                $value = implode($sep, $value);
333
+            }
334
+            $o = $value;
335
+            break;
336
+    }
337
+    return $o;
338 338
 }
339 339
 
340 340
 /**
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
  * @return string
343 343
  */
344 344
 function decodeParamValue($s) {
345
-	$s = str_replace("%3D", '=', $s); // =
346
-	return str_replace("%26", '&', $s); // &
345
+    $s = str_replace("%3D", '=', $s); // =
346
+    return str_replace("%26", '&', $s); // &
347 347
 }
348 348
 
349 349
 /**
@@ -356,20 +356,20 @@  discard block
 block discarded – undo
356 356
  * @return array|string
357 357
  */
358 358
 function parseInput($src, $delim = "||", $type = "string", $columns = true) { // type can be: string, array
359
-	global $modx;
360
-	if($modx->db->isResult($src)) {
361
-		// must be a recordset
362
-		$rows = array();
363
-		while($cols = $modx->db->getRow($src, 'num')) $rows[] = ($columns) ? $cols : implode(" ", $cols);
364
-		return ($type == "array") ? $rows : implode($delim, $rows);
365
-	} else {
366
-		// must be a text
367
-		if($type == "array") {
368
-			return explode($delim, $src);
369
-		} else {
370
-			return $src;
371
-		}
372
-	}
359
+    global $modx;
360
+    if($modx->db->isResult($src)) {
361
+        // must be a recordset
362
+        $rows = array();
363
+        while($cols = $modx->db->getRow($src, 'num')) $rows[] = ($columns) ? $cols : implode(" ", $cols);
364
+        return ($type == "array") ? $rows : implode($delim, $rows);
365
+    } else {
366
+        // must be a text
367
+        if($type == "array") {
368
+            return explode($delim, $src);
369
+        } else {
370
+            return $src;
371
+        }
372
+    }
373 373
 }
374 374
 
375 375
 /**
@@ -377,21 +377,21 @@  discard block
 block discarded – undo
377 377
  * @return bool|false|int
378 378
  */
379 379
 function getUnixtimeFromDateString($value) {
380
-	$timestamp = false;
381
-	// Check for MySQL or legacy style date
382
-	$date_match_1 = '/^([0-9]{2})-([0-9]{2})-([0-9]{4})\ ([0-9]{2}):([0-9]{2}):([0-9]{2})$/';
383
-	$date_match_2 = '/^([0-9]{4})-([0-9]{2})-([0-9]{2})\ ([0-9]{2}):([0-9]{2}):([0-9]{2})$/';
384
-	$matches = array();
385
-	if(strpos($value, '-') !== false) {
386
-		if(preg_match($date_match_1, $value, $matches)) {
387
-			$timestamp = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]);
388
-		} elseif(preg_match($date_match_2, $value, $matches)) {
389
-			$timestamp = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
390
-		}
391
-	}
392
-	// If those didn't work, use strtotime to figure out the date
393
-	if($timestamp === false || $timestamp === -1) {
394
-		$timestamp = strtotime($value);
395
-	}
396
-	return $timestamp;
380
+    $timestamp = false;
381
+    // Check for MySQL or legacy style date
382
+    $date_match_1 = '/^([0-9]{2})-([0-9]{2})-([0-9]{4})\ ([0-9]{2}):([0-9]{2}):([0-9]{2})$/';
383
+    $date_match_2 = '/^([0-9]{4})-([0-9]{2})-([0-9]{2})\ ([0-9]{2}):([0-9]{2}):([0-9]{2})$/';
384
+    $matches = array();
385
+    if(strpos($value, '-') !== false) {
386
+        if(preg_match($date_match_1, $value, $matches)) {
387
+            $timestamp = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]);
388
+        } elseif(preg_match($date_match_2, $value, $matches)) {
389
+            $timestamp = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
390
+        }
391
+    }
392
+    // If those didn't work, use strtotime to figure out the date
393
+    if($timestamp === false || $timestamp === -1) {
394
+        $timestamp = strtotime($value);
395
+    }
396
+    return $timestamp;
397 397
 }
Please login to merge, or discard this patch.
manager/includes/tmplvars.commands.inc.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
  */
132 132
 function ProcessFile($file) {
133 133
     // get the file
134
-	$buffer = @file_get_contents($file);
135
-	if ($buffer === false) $buffer = " Could not retrieve document '$file'.";
134
+    $buffer = @file_get_contents($file);
135
+    if ($buffer === false) $buffer = " Could not retrieve document '$file'.";
136 136
     return $buffer;
137 137
 }
138 138
 
@@ -167,21 +167,21 @@  discard block
 block discarded – undo
167 167
  */
168 168
 function parseTvValues($param, $tvsArray)
169 169
 {
170
-	global $modx;
171
-	$tvsArray = is_array($modx->documentObject) ? array_merge($tvsArray, $modx->documentObject) : $tvsArray;
172
-	if (strpos($param, '[*') !== false) {
173
-		$matches = $modx->getTagsFromContent($param, '[*', '*]');
174
-		foreach ($matches[0] as $i=>$match) {
175
-			if(isset($tvsArray[ $matches[1][$i] ])) {
176
-				if(is_array($tvsArray[ $matches[1][$i] ])) {
177
-					$value = $tvsArray[$matches[1][$i]]['value'];
178
-					$value = $value === '' ? $tvsArray[$matches[1][$i]]['default_text'] : $value;
179
-				} else {
180
-					$value = $tvsArray[ $matches[1][$i] ];
181
-				}
182
-				$param = str_replace($match, $value, $param);
183
-			}
184
-		}
185
-	}
186
-	return $param;
170
+    global $modx;
171
+    $tvsArray = is_array($modx->documentObject) ? array_merge($tvsArray, $modx->documentObject) : $tvsArray;
172
+    if (strpos($param, '[*') !== false) {
173
+        $matches = $modx->getTagsFromContent($param, '[*', '*]');
174
+        foreach ($matches[0] as $i=>$match) {
175
+            if(isset($tvsArray[ $matches[1][$i] ])) {
176
+                if(is_array($tvsArray[ $matches[1][$i] ])) {
177
+                    $value = $tvsArray[$matches[1][$i]]['value'];
178
+                    $value = $value === '' ? $tvsArray[$matches[1][$i]]['default_text'] : $value;
179
+                } else {
180
+                    $value = $tvsArray[ $matches[1][$i] ];
181
+                }
182
+                $param = str_replace($match, $value, $param);
183
+            }
184
+        }
185
+    }
186
+    return $param;
187 187
 }
Please login to merge, or discard this patch.
manager/processors/save_user.processor.php 1 patch
Indentation   +368 added lines, -368 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) {
3
-	die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
3
+    die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
4 4
 }
5 5
 if(!$modx->hasPermission('save_user')) {
6
-	$modx->webAlertAndQuit($_lang["error_no_privileges"]);
6
+    $modx->webAlertAndQuit($_lang["error_no_privileges"]);
7 7
 }
8 8
 
9 9
 $modx->loadExtension('phpass');
@@ -45,134 +45,134 @@  discard block
 block discarded – undo
45 45
 
46 46
 // verify password
47 47
 if($passwordgenmethod == "spec" && $input['specifiedpassword'] != $input['confirmpassword']) {
48
-	webAlertAndQuit("Password typed is mismatched");
48
+    webAlertAndQuit("Password typed is mismatched");
49 49
 }
50 50
 
51 51
 // verify email
52 52
 if($email == '' || !preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,24}$/i", $email)) {
53
-	webAlertAndQuit("E-mail address doesn't seem to be valid!");
53
+    webAlertAndQuit("E-mail address doesn't seem to be valid!");
54 54
 }
55 55
 
56 56
 // verify admin security
57 57
 if($_SESSION['mgrRole'] != 1) {
58
-	// Check to see if user tried to spoof a "1" (admin) role
59
-	if(!$modx->hasPermission('save_role')) {
60
-		webAlertAndQuit("Illegal attempt to create/modify administrator by non-administrator!");
61
-	}
62
-	// Verify that the user being edited wasn't an admin and the user ID got spoofed
63
-	$rs = $modx->db->select('count(internalKey)', $tbl_user_attributes, "internalKey='{$id}' AND role=1");
64
-	$limit = $modx->db->getValue($rs);
65
-	if($limit > 0) {
66
-		webAlertAndQuit("You cannot alter an administrative user.");
67
-	}
58
+    // Check to see if user tried to spoof a "1" (admin) role
59
+    if(!$modx->hasPermission('save_role')) {
60
+        webAlertAndQuit("Illegal attempt to create/modify administrator by non-administrator!");
61
+    }
62
+    // Verify that the user being edited wasn't an admin and the user ID got spoofed
63
+    $rs = $modx->db->select('count(internalKey)', $tbl_user_attributes, "internalKey='{$id}' AND role=1");
64
+    $limit = $modx->db->getValue($rs);
65
+    if($limit > 0) {
66
+        webAlertAndQuit("You cannot alter an administrative user.");
67
+    }
68 68
 
69 69
 }
70 70
 
71 71
 switch($input['mode']) {
72
-	case '11' : // new user
73
-		// check if this user name already exist
74
-		$rs = $modx->db->select('count(id)', $tbl_manager_users, sprintf("username='%s'", $modx->db->escape($newusername)));
75
-		$limit = $modx->db->getValue($rs);
76
-		if($limit > 0) {
77
-			webAlertAndQuit("User name is already in use!");
78
-		}
79
-
80
-		// check if the email address already exist
81
-		$rs = $modx->db->select('count(internalKey)', $tbl_user_attributes, sprintf("email='%s' AND id!='%s'", $modx->db->escape($email), $id));
82
-		$limit = $modx->db->getValue($rs);
83
-		if($limit > 0) {
84
-			webAlertAndQuit("Email is already in use!");
85
-		}
86
-
87
-		// generate a new password for this user
88
-		if($specifiedpassword != "" && $passwordgenmethod == "spec") {
89
-			if(strlen($specifiedpassword) < 6) {
90
-				webAlertAndQuit("Password is too short!");
91
-			} else {
92
-				$newpassword = $specifiedpassword;
93
-			}
94
-		} elseif($specifiedpassword == "" && $passwordgenmethod == "spec") {
95
-			webAlertAndQuit("You didn't specify a password for this user!");
96
-		} elseif($passwordgenmethod == 'g') {
97
-			$newpassword = generate_password(8);
98
-		} else {
99
-			webAlertAndQuit("No password generation method specified!");
100
-		}
101
-
102
-		// invoke OnBeforeUserFormSave event
103
-		$modx->invokeEvent("OnBeforeUserFormSave", array(
104
-			"mode" => "new",
105
-		));
106
-
107
-		// create the user account
108
-		$internalKey = $modx->db->insert(array('username' => $modx->db->escape($newusername)), $tbl_manager_users);
109
-
110
-		$field = array();
111
-		$field['password'] = $modx->phpass->HashPassword($newpassword);
112
-		$modx->db->update($field, $tbl_manager_users, "id='{$internalKey}'");
113
-
114
-		$field = compact('internalKey', 'fullname', 'role', 'email', 'phone', 'mobilephone', 'fax', 'zip', 'street', 'city', 'state', 'country', 'gender', 'dob', 'photo', 'comment', 'blocked', 'blockeduntil', 'blockedafter');
115
-		$field = $modx->db->escape($field);
116
-		$modx->db->insert($field, $tbl_user_attributes);
117
-
118
-		// Save user settings
119
-		saveUserSettings($internalKey);
120
-
121
-		// invoke OnManagerSaveUser event
122
-		$modx->invokeEvent("OnManagerSaveUser", array(
123
-			"mode" => "new",
124
-			"userid" => $internalKey,
125
-			"username" => $newusername,
126
-			"userpassword" => $newpassword,
127
-			"useremail" => $email,
128
-			"userfullname" => $fullname,
129
-			"userroleid" => $role
130
-		));
131
-
132
-		// invoke OnUserFormSave event
133
-		$modx->invokeEvent("OnUserFormSave", array(
134
-			"mode" => "new",
135
-			"id" => $internalKey
136
-		));
137
-
138
-		// Set the item name for logger
139
-		$_SESSION['itemname'] = $newusername;
140
-
141
-		/*******************************************************************************/
142
-		// put the user in the user_groups he/ she should be in
143
-		// first, check that up_perms are switched on!
144
-		if($use_udperms == 1) {
145
-			if(!empty($user_groups)) {
146
-				for($i = 0; $i < count($user_groups); $i++) {
147
-					$f = array();
148
-					$f['user_group'] = (int)$user_groups[$i];
149
-					$f['member'] = $internalKey;
150
-					$modx->db->insert($f, $tbl_member_groups);
151
-				}
152
-			}
153
-		}
154
-		// end of user_groups stuff!
155
-
156
-		if($passwordnotifymethod == 'e') {
157
-			sendMailMessage($email, $newusername, $newpassword, $fullname);
158
-			if($input['stay'] != '') {
159
-				$a = ($input['stay'] == '2') ? "12&id={$internalKey}" : "11";
160
-				$header = "Location: index.php?a={$a}&r=2&stay=" . $input['stay'];
161
-				header($header);
162
-			} else {
163
-				$header = "Location: index.php?a=75&r=2";
164
-				header($header);
165
-			}
166
-		} else {
167
-			if($input['stay'] != '') {
168
-				$a = ($input['stay'] == '2') ? "12&id={$internalKey}" : "11";
169
-				$stayUrl = "index.php?a={$a}&r=2&stay=" . $input['stay'];
170
-			} else {
171
-				$stayUrl = "index.php?a=75&r=2";
172
-			}
173
-
174
-			include_once "header.inc.php";
175
-			?>
72
+    case '11' : // new user
73
+        // check if this user name already exist
74
+        $rs = $modx->db->select('count(id)', $tbl_manager_users, sprintf("username='%s'", $modx->db->escape($newusername)));
75
+        $limit = $modx->db->getValue($rs);
76
+        if($limit > 0) {
77
+            webAlertAndQuit("User name is already in use!");
78
+        }
79
+
80
+        // check if the email address already exist
81
+        $rs = $modx->db->select('count(internalKey)', $tbl_user_attributes, sprintf("email='%s' AND id!='%s'", $modx->db->escape($email), $id));
82
+        $limit = $modx->db->getValue($rs);
83
+        if($limit > 0) {
84
+            webAlertAndQuit("Email is already in use!");
85
+        }
86
+
87
+        // generate a new password for this user
88
+        if($specifiedpassword != "" && $passwordgenmethod == "spec") {
89
+            if(strlen($specifiedpassword) < 6) {
90
+                webAlertAndQuit("Password is too short!");
91
+            } else {
92
+                $newpassword = $specifiedpassword;
93
+            }
94
+        } elseif($specifiedpassword == "" && $passwordgenmethod == "spec") {
95
+            webAlertAndQuit("You didn't specify a password for this user!");
96
+        } elseif($passwordgenmethod == 'g') {
97
+            $newpassword = generate_password(8);
98
+        } else {
99
+            webAlertAndQuit("No password generation method specified!");
100
+        }
101
+
102
+        // invoke OnBeforeUserFormSave event
103
+        $modx->invokeEvent("OnBeforeUserFormSave", array(
104
+            "mode" => "new",
105
+        ));
106
+
107
+        // create the user account
108
+        $internalKey = $modx->db->insert(array('username' => $modx->db->escape($newusername)), $tbl_manager_users);
109
+
110
+        $field = array();
111
+        $field['password'] = $modx->phpass->HashPassword($newpassword);
112
+        $modx->db->update($field, $tbl_manager_users, "id='{$internalKey}'");
113
+
114
+        $field = compact('internalKey', 'fullname', 'role', 'email', 'phone', 'mobilephone', 'fax', 'zip', 'street', 'city', 'state', 'country', 'gender', 'dob', 'photo', 'comment', 'blocked', 'blockeduntil', 'blockedafter');
115
+        $field = $modx->db->escape($field);
116
+        $modx->db->insert($field, $tbl_user_attributes);
117
+
118
+        // Save user settings
119
+        saveUserSettings($internalKey);
120
+
121
+        // invoke OnManagerSaveUser event
122
+        $modx->invokeEvent("OnManagerSaveUser", array(
123
+            "mode" => "new",
124
+            "userid" => $internalKey,
125
+            "username" => $newusername,
126
+            "userpassword" => $newpassword,
127
+            "useremail" => $email,
128
+            "userfullname" => $fullname,
129
+            "userroleid" => $role
130
+        ));
131
+
132
+        // invoke OnUserFormSave event
133
+        $modx->invokeEvent("OnUserFormSave", array(
134
+            "mode" => "new",
135
+            "id" => $internalKey
136
+        ));
137
+
138
+        // Set the item name for logger
139
+        $_SESSION['itemname'] = $newusername;
140
+
141
+        /*******************************************************************************/
142
+        // put the user in the user_groups he/ she should be in
143
+        // first, check that up_perms are switched on!
144
+        if($use_udperms == 1) {
145
+            if(!empty($user_groups)) {
146
+                for($i = 0; $i < count($user_groups); $i++) {
147
+                    $f = array();
148
+                    $f['user_group'] = (int)$user_groups[$i];
149
+                    $f['member'] = $internalKey;
150
+                    $modx->db->insert($f, $tbl_member_groups);
151
+                }
152
+            }
153
+        }
154
+        // end of user_groups stuff!
155
+
156
+        if($passwordnotifymethod == 'e') {
157
+            sendMailMessage($email, $newusername, $newpassword, $fullname);
158
+            if($input['stay'] != '') {
159
+                $a = ($input['stay'] == '2') ? "12&id={$internalKey}" : "11";
160
+                $header = "Location: index.php?a={$a}&r=2&stay=" . $input['stay'];
161
+                header($header);
162
+            } else {
163
+                $header = "Location: index.php?a=75&r=2";
164
+                header($header);
165
+            }
166
+        } else {
167
+            if($input['stay'] != '') {
168
+                $a = ($input['stay'] == '2') ? "12&id={$internalKey}" : "11";
169
+                $stayUrl = "index.php?a={$a}&r=2&stay=" . $input['stay'];
170
+            } else {
171
+                $stayUrl = "index.php?a=75&r=2";
172
+            }
173
+
174
+            include_once "header.inc.php";
175
+            ?>
176 176
 
177 177
 			<h1><?php echo $_lang['user_title']; ?></h1>
178 178
 
@@ -194,125 +194,125 @@  discard block
 block discarded – undo
194 194
 			</div>
195 195
 			<?php
196 196
 
197
-			include_once "footer.inc.php";
198
-		}
199
-		break;
200
-	case '12' : // edit user
201
-		// generate a new password for this user
202
-		if($genpassword == 1) {
203
-			if($specifiedpassword != "" && $passwordgenmethod == "spec") {
204
-				if(strlen($specifiedpassword) < 6) {
205
-					webAlertAndQuit("Password is too short!");
206
-				} else {
207
-					$newpassword = $specifiedpassword;
208
-				}
209
-			} elseif($specifiedpassword == "" && $passwordgenmethod == "spec") {
210
-				webAlertAndQuit("You didn't specify a password for this user!");
211
-			} elseif($passwordgenmethod == 'g') {
212
-				$newpassword = generate_password(8);
213
-			} else {
214
-				webAlertAndQuit("No password generation method specified!");
215
-			}
216
-		}
217
-		if($passwordnotifymethod == 'e') {
218
-			sendMailMessage($email, $newusername, $newpassword, $fullname);
219
-		}
220
-
221
-		// check if the username already exist
222
-		$rs = $modx->db->select('count(id)', $tbl_manager_users, sprintf("username='%s' AND id!='%s'", $modx->db->escape($newusername), $id));
223
-		$limit = $modx->db->getValue($rs);
224
-		if($limit > 0) {
225
-			webAlertAndQuit("User name is already in use!");
226
-		}
227
-
228
-		// check if the email address already exists
229
-		$rs = $modx->db->select('count(internalKey)', $tbl_user_attributes, sprintf("email='%s' AND internalKey!='%s'", $modx->db->escape($email), $id));
230
-		$limit = $modx->db->getValue($rs);
231
-		if($limit > 0) {
232
-			webAlertAndQuit("Email is already in use!");
233
-		}
234
-
235
-		// invoke OnBeforeUserFormSave event
236
-		$modx->invokeEvent("OnBeforeUserFormSave", array(
237
-			"mode" => "upd",
238
-			"id" => $id
239
-		));
240
-
241
-		// update user name and password
242
-		$field = array();
243
-		$field['username'] = $modx->db->escape($newusername);
244
-		if($genpassword == 1) {
245
-			$field['password'] = $modx->phpass->HashPassword($newpassword);
246
-		}
247
-		$modx->db->update($field, $tbl_manager_users, "id='{$id}'");
248
-		$field = compact('fullname', 'role', 'email', 'phone', 'mobilephone', 'fax', 'zip', 'street', 'city', 'state', 'country', 'gender', 'dob', 'photo', 'comment', 'failedlogincount', 'blocked', 'blockeduntil', 'blockedafter');
249
-		$field = $modx->db->escape($field);
250
-		$modx->db->update($field, $tbl_user_attributes, "internalKey='{$id}'");
251
-
252
-		// Save user settings
253
-		saveUserSettings($id);
254
-
255
-		// Set the item name for logger
256
-		$_SESSION['itemname'] = $newusername;
257
-
258
-		// invoke OnManagerSaveUser event
259
-		$modx->invokeEvent("OnManagerSaveUser", array(
260
-			"mode" => "upd",
261
-			"userid" => $id,
262
-			"username" => $newusername,
263
-			"userpassword" => $newpassword,
264
-			"useremail" => $email,
265
-			"userfullname" => $fullname,
266
-			"userroleid" => $role,
267
-			"oldusername" => (($oldusername != $newusername) ? $oldusername : ""),
268
-			"olduseremail" => (($oldemail != $email) ? $oldemail : "")
269
-		));
270
-
271
-		// invoke OnManagerChangePassword event
272
-		if($genpassword == 1) {
273
-			$modx->invokeEvent("OnManagerChangePassword", array(
274
-				"userid" => $id,
275
-				"username" => $newusername,
276
-				"userpassword" => $newpassword
277
-			));
278
-		}
279
-
280
-		// invoke OnUserFormSave event
281
-		$modx->invokeEvent("OnUserFormSave", array(
282
-			"mode" => "upd",
283
-			"id" => $id
284
-		));
285
-
286
-		/*******************************************************************************/
287
-		// put the user in the user_groups he/ she should be in
288
-		// first, check that up_perms are switched on!
289
-		if($use_udperms == 1) {
290
-			// as this is an existing user, delete his/ her entries in the groups before saving the new groups
291
-			$modx->db->delete($tbl_member_groups, "member='{$id}'");
292
-			if(!empty($user_groups)) {
293
-				for($i = 0; $i < count($user_groups); $i++) {
294
-					$field = array();
295
-					$field['user_group'] = (int)$user_groups[$i];
296
-					$field['member'] = $id;
297
-					$modx->db->insert($field, $tbl_member_groups);
298
-				}
299
-			}
300
-		}
301
-		// end of user_groups stuff!
302
-		/*******************************************************************************/
303
-		if($id == $modx->getLoginUserID() && ($genpassword !== 1 && $passwordnotifymethod != 's')) {
304
-			$modx->webAlertAndQuit($_lang["user_changeddata"], 'javascript:top.location.href="index.php?a=8";');
305
-		}
306
-		if($genpassword == 1 && $passwordnotifymethod == 's') {
307
-			if($input['stay'] != '') {
308
-				$a = ($input['stay'] == '2') ? "12&id={$id}" : "11";
309
-				$stayUrl = "index.php?a={$a}&r=2&stay=" . $input['stay'];
310
-			} else {
311
-				$stayUrl = "index.php?a=75&r=2";
312
-			}
313
-
314
-			include_once "header.inc.php";
315
-			?>
197
+            include_once "footer.inc.php";
198
+        }
199
+        break;
200
+    case '12' : // edit user
201
+        // generate a new password for this user
202
+        if($genpassword == 1) {
203
+            if($specifiedpassword != "" && $passwordgenmethod == "spec") {
204
+                if(strlen($specifiedpassword) < 6) {
205
+                    webAlertAndQuit("Password is too short!");
206
+                } else {
207
+                    $newpassword = $specifiedpassword;
208
+                }
209
+            } elseif($specifiedpassword == "" && $passwordgenmethod == "spec") {
210
+                webAlertAndQuit("You didn't specify a password for this user!");
211
+            } elseif($passwordgenmethod == 'g') {
212
+                $newpassword = generate_password(8);
213
+            } else {
214
+                webAlertAndQuit("No password generation method specified!");
215
+            }
216
+        }
217
+        if($passwordnotifymethod == 'e') {
218
+            sendMailMessage($email, $newusername, $newpassword, $fullname);
219
+        }
220
+
221
+        // check if the username already exist
222
+        $rs = $modx->db->select('count(id)', $tbl_manager_users, sprintf("username='%s' AND id!='%s'", $modx->db->escape($newusername), $id));
223
+        $limit = $modx->db->getValue($rs);
224
+        if($limit > 0) {
225
+            webAlertAndQuit("User name is already in use!");
226
+        }
227
+
228
+        // check if the email address already exists
229
+        $rs = $modx->db->select('count(internalKey)', $tbl_user_attributes, sprintf("email='%s' AND internalKey!='%s'", $modx->db->escape($email), $id));
230
+        $limit = $modx->db->getValue($rs);
231
+        if($limit > 0) {
232
+            webAlertAndQuit("Email is already in use!");
233
+        }
234
+
235
+        // invoke OnBeforeUserFormSave event
236
+        $modx->invokeEvent("OnBeforeUserFormSave", array(
237
+            "mode" => "upd",
238
+            "id" => $id
239
+        ));
240
+
241
+        // update user name and password
242
+        $field = array();
243
+        $field['username'] = $modx->db->escape($newusername);
244
+        if($genpassword == 1) {
245
+            $field['password'] = $modx->phpass->HashPassword($newpassword);
246
+        }
247
+        $modx->db->update($field, $tbl_manager_users, "id='{$id}'");
248
+        $field = compact('fullname', 'role', 'email', 'phone', 'mobilephone', 'fax', 'zip', 'street', 'city', 'state', 'country', 'gender', 'dob', 'photo', 'comment', 'failedlogincount', 'blocked', 'blockeduntil', 'blockedafter');
249
+        $field = $modx->db->escape($field);
250
+        $modx->db->update($field, $tbl_user_attributes, "internalKey='{$id}'");
251
+
252
+        // Save user settings
253
+        saveUserSettings($id);
254
+
255
+        // Set the item name for logger
256
+        $_SESSION['itemname'] = $newusername;
257
+
258
+        // invoke OnManagerSaveUser event
259
+        $modx->invokeEvent("OnManagerSaveUser", array(
260
+            "mode" => "upd",
261
+            "userid" => $id,
262
+            "username" => $newusername,
263
+            "userpassword" => $newpassword,
264
+            "useremail" => $email,
265
+            "userfullname" => $fullname,
266
+            "userroleid" => $role,
267
+            "oldusername" => (($oldusername != $newusername) ? $oldusername : ""),
268
+            "olduseremail" => (($oldemail != $email) ? $oldemail : "")
269
+        ));
270
+
271
+        // invoke OnManagerChangePassword event
272
+        if($genpassword == 1) {
273
+            $modx->invokeEvent("OnManagerChangePassword", array(
274
+                "userid" => $id,
275
+                "username" => $newusername,
276
+                "userpassword" => $newpassword
277
+            ));
278
+        }
279
+
280
+        // invoke OnUserFormSave event
281
+        $modx->invokeEvent("OnUserFormSave", array(
282
+            "mode" => "upd",
283
+            "id" => $id
284
+        ));
285
+
286
+        /*******************************************************************************/
287
+        // put the user in the user_groups he/ she should be in
288
+        // first, check that up_perms are switched on!
289
+        if($use_udperms == 1) {
290
+            // as this is an existing user, delete his/ her entries in the groups before saving the new groups
291
+            $modx->db->delete($tbl_member_groups, "member='{$id}'");
292
+            if(!empty($user_groups)) {
293
+                for($i = 0; $i < count($user_groups); $i++) {
294
+                    $field = array();
295
+                    $field['user_group'] = (int)$user_groups[$i];
296
+                    $field['member'] = $id;
297
+                    $modx->db->insert($field, $tbl_member_groups);
298
+                }
299
+            }
300
+        }
301
+        // end of user_groups stuff!
302
+        /*******************************************************************************/
303
+        if($id == $modx->getLoginUserID() && ($genpassword !== 1 && $passwordnotifymethod != 's')) {
304
+            $modx->webAlertAndQuit($_lang["user_changeddata"], 'javascript:top.location.href="index.php?a=8";');
305
+        }
306
+        if($genpassword == 1 && $passwordnotifymethod == 's') {
307
+            if($input['stay'] != '') {
308
+                $a = ($input['stay'] == '2') ? "12&id={$id}" : "11";
309
+                $stayUrl = "index.php?a={$a}&r=2&stay=" . $input['stay'];
310
+            } else {
311
+                $stayUrl = "index.php?a=75&r=2";
312
+            }
313
+
314
+            include_once "header.inc.php";
315
+            ?>
316 316
 
317 317
 			<h1><?php echo $_lang['user_title']; ?></h1>
318 318
 
@@ -332,20 +332,20 @@  discard block
 block discarded – undo
332 332
 			</div>
333 333
 			<?php
334 334
 
335
-			include_once "footer.inc.php";
336
-		} else {
337
-			if($input['stay'] != '') {
338
-				$a = ($input['stay'] == '2') ? "12&id={$id}" : "11";
339
-				$header = "Location: index.php?a={$a}&r=2&stay=" . $input['stay'];
340
-				header($header);
341
-			} else {
342
-				$header = "Location: index.php?a=75&r=2";
343
-				header($header);
344
-			}
345
-		}
346
-		break;
347
-	default:
348
-		webAlertAndQuit("No operation set in request.");
335
+            include_once "footer.inc.php";
336
+        } else {
337
+            if($input['stay'] != '') {
338
+                $a = ($input['stay'] == '2') ? "12&id={$id}" : "11";
339
+                $header = "Location: index.php?a={$a}&r=2&stay=" . $input['stay'];
340
+                header($header);
341
+            } else {
342
+                $header = "Location: index.php?a=75&r=2";
343
+                header($header);
344
+            }
345
+        }
346
+        break;
347
+    default:
348
+        webAlertAndQuit("No operation set in request.");
349 349
 }
350 350
 
351 351
 /**
@@ -357,31 +357,31 @@  discard block
 block discarded – undo
357 357
  * @param string $ufn
358 358
  */
359 359
 function sendMailMessage($email, $uid, $pwd, $ufn) {
360
-	global $modx, $_lang, $signupemail_message;
361
-	global $emailsubject, $emailsender;
362
-	global $site_name;
363
-	$manager_url = MODX_MANAGER_URL;
364
-	$message = sprintf($signupemail_message, $uid, $pwd); // use old method
365
-	// replace placeholders
366
-	$message = str_replace("[+uid+]", $uid, $message);
367
-	$message = str_replace("[+pwd+]", $pwd, $message);
368
-	$message = str_replace("[+ufn+]", $ufn, $message);
369
-	$message = str_replace("[+sname+]", $site_name, $message);
370
-	$message = str_replace("[+saddr+]", $emailsender, $message);
371
-	$message = str_replace("[+semail+]", $emailsender, $message);
372
-	$message = str_replace("[+surl+]", $manager_url, $message);
373
-
374
-	$param = array();
375
-	$param['from'] = "{$site_name}<{$emailsender}>";
376
-	$param['subject'] = $emailsubject;
377
-	$param['body'] = $message;
378
-	$param['to'] = $email;
379
-	$param['type'] = 'text';
380
-	$rs = $modx->sendmail($param);
381
-	if(!$rs) {
382
-		$modx->manager->saveFormValues();
383
-		$modx->messageQuit("{$email} - {$_lang['error_sending_email']}");
384
-	}
360
+    global $modx, $_lang, $signupemail_message;
361
+    global $emailsubject, $emailsender;
362
+    global $site_name;
363
+    $manager_url = MODX_MANAGER_URL;
364
+    $message = sprintf($signupemail_message, $uid, $pwd); // use old method
365
+    // replace placeholders
366
+    $message = str_replace("[+uid+]", $uid, $message);
367
+    $message = str_replace("[+pwd+]", $pwd, $message);
368
+    $message = str_replace("[+ufn+]", $ufn, $message);
369
+    $message = str_replace("[+sname+]", $site_name, $message);
370
+    $message = str_replace("[+saddr+]", $emailsender, $message);
371
+    $message = str_replace("[+semail+]", $emailsender, $message);
372
+    $message = str_replace("[+surl+]", $manager_url, $message);
373
+
374
+    $param = array();
375
+    $param['from'] = "{$site_name}<{$emailsender}>";
376
+    $param['subject'] = $emailsubject;
377
+    $param['body'] = $message;
378
+    $param['to'] = $email;
379
+    $param['type'] = 'text';
380
+    $rs = $modx->sendmail($param);
381
+    if(!$rs) {
382
+        $modx->manager->saveFormValues();
383
+        $modx->messageQuit("{$email} - {$_lang['error_sending_email']}");
384
+    }
385 385
 }
386 386
 
387 387
 /**
@@ -390,86 +390,86 @@  discard block
 block discarded – undo
390 390
  * @param int $id
391 391
  */
392 392
 function saveUserSettings($id) {
393
-	global $modx;
394
-	$tbl_user_settings = $modx->getFullTableName('user_settings');
395
-
396
-	$ignore = array(
397
-		'id',
398
-		'oldusername',
399
-		'oldemail',
400
-		'newusername',
401
-		'fullname',
402
-		'newpassword',
403
-		'newpasswordcheck',
404
-		'passwordgenmethod',
405
-		'passwordnotifymethod',
406
-		'specifiedpassword',
407
-		'confirmpassword',
408
-		'email',
409
-		'phone',
410
-		'mobilephone',
411
-		'fax',
412
-		'dob',
413
-		'country',
414
-		'street',
415
-		'city',
416
-		'state',
417
-		'zip',
418
-		'gender',
419
-		'photo',
420
-		'comment',
421
-		'role',
422
-		'failedlogincount',
423
-		'blocked',
424
-		'blockeduntil',
425
-		'blockedafter',
426
-		'user_groups',
427
-		'mode',
428
-		'blockedmode',
429
-		'stay',
430
-		'save',
431
-		'theme_refresher'
432
-	);
433
-
434
-	// determine which settings can be saved blank (based on 'default_{settingname}' POST checkbox values)
435
-	$defaults = array(
436
-		'upload_images',
437
-		'upload_media',
438
-		'upload_flash',
439
-		'upload_files'
440
-	);
441
-
442
-	// get user setting field names
443
-	$settings = array();
444
-	foreach($_POST as $n => $v) {
445
-		if(in_array($n, $ignore) || (!in_array($n, $defaults) && is_scalar($v) && trim($v) == '') || (!in_array($n, $defaults) && is_array($v) && empty($v))) {
446
-			continue;
447
-		} // ignore blacklist and empties
448
-		$settings[$n] = $v; // this value should be saved
449
-	}
450
-
451
-	foreach($defaults as $k) {
452
-		if(isset($settings['default_' . $k]) && $settings['default_' . $k] == '1') {
453
-			unset($settings[$k]);
454
-		}
455
-		unset($settings['default_' . $k]);
456
-	}
457
-
458
-	$modx->db->delete($tbl_user_settings, "user='{$id}'");
459
-
460
-	foreach($settings as $n => $vl) {
461
-		if(is_array($vl)) {
462
-			$vl = implode(",", $vl);
463
-		}
464
-		if($vl != '') {
465
-			$f = array();
466
-			$f['user'] = $id;
467
-			$f['setting_name'] = $n;
468
-			$f['setting_value'] = $vl;
469
-			$f = $modx->db->escape($f);
470
-			$modx->db->insert($f, $tbl_user_settings);
471
-		}
472
-	}
393
+    global $modx;
394
+    $tbl_user_settings = $modx->getFullTableName('user_settings');
395
+
396
+    $ignore = array(
397
+        'id',
398
+        'oldusername',
399
+        'oldemail',
400
+        'newusername',
401
+        'fullname',
402
+        'newpassword',
403
+        'newpasswordcheck',
404
+        'passwordgenmethod',
405
+        'passwordnotifymethod',
406
+        'specifiedpassword',
407
+        'confirmpassword',
408
+        'email',
409
+        'phone',
410
+        'mobilephone',
411
+        'fax',
412
+        'dob',
413
+        'country',
414
+        'street',
415
+        'city',
416
+        'state',
417
+        'zip',
418
+        'gender',
419
+        'photo',
420
+        'comment',
421
+        'role',
422
+        'failedlogincount',
423
+        'blocked',
424
+        'blockeduntil',
425
+        'blockedafter',
426
+        'user_groups',
427
+        'mode',
428
+        'blockedmode',
429
+        'stay',
430
+        'save',
431
+        'theme_refresher'
432
+    );
433
+
434
+    // determine which settings can be saved blank (based on 'default_{settingname}' POST checkbox values)
435
+    $defaults = array(
436
+        'upload_images',
437
+        'upload_media',
438
+        'upload_flash',
439
+        'upload_files'
440
+    );
441
+
442
+    // get user setting field names
443
+    $settings = array();
444
+    foreach($_POST as $n => $v) {
445
+        if(in_array($n, $ignore) || (!in_array($n, $defaults) && is_scalar($v) && trim($v) == '') || (!in_array($n, $defaults) && is_array($v) && empty($v))) {
446
+            continue;
447
+        } // ignore blacklist and empties
448
+        $settings[$n] = $v; // this value should be saved
449
+    }
450
+
451
+    foreach($defaults as $k) {
452
+        if(isset($settings['default_' . $k]) && $settings['default_' . $k] == '1') {
453
+            unset($settings[$k]);
454
+        }
455
+        unset($settings['default_' . $k]);
456
+    }
457
+
458
+    $modx->db->delete($tbl_user_settings, "user='{$id}'");
459
+
460
+    foreach($settings as $n => $vl) {
461
+        if(is_array($vl)) {
462
+            $vl = implode(",", $vl);
463
+        }
464
+        if($vl != '') {
465
+            $f = array();
466
+            $f['user'] = $id;
467
+            $f['setting_name'] = $n;
468
+            $f['setting_value'] = $vl;
469
+            $f = $modx->db->escape($f);
470
+            $modx->db->insert($f, $tbl_user_settings);
471
+        }
472
+    }
473 473
 }
474 474
 
475 475
 /**
@@ -478,10 +478,10 @@  discard block
 block discarded – undo
478 478
  * @param $msg
479 479
  */
480 480
 function webAlertAndQuit($msg) {
481
-	global $id, $modx;
482
-	$mode = $_POST['mode'];
483
-	$modx->manager->saveFormValues($mode);
484
-	$modx->webAlertAndQuit($msg, "index.php?a={$mode}" . ($mode == '12' ? "&id={$id}" : ''));
481
+    global $id, $modx;
482
+    $mode = $_POST['mode'];
483
+    $modx->manager->saveFormValues($mode);
484
+    $modx->webAlertAndQuit($msg, "index.php?a={$mode}" . ($mode == '12' ? "&id={$id}" : ''));
485 485
 }
486 486
 
487 487
 /**
@@ -491,12 +491,12 @@  discard block
 block discarded – undo
491 491
  * @return string
492 492
  */
493 493
 function generate_password($length = 10) {
494
-	$allowable_characters = "abcdefghjkmnpqrstuvxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
495
-	$ps_len = strlen($allowable_characters);
496
-	mt_srand((double) microtime() * 1000000);
497
-	$pass = "";
498
-	for($i = 0; $i < $length; $i++) {
499
-		$pass .= $allowable_characters[mt_rand(0, $ps_len - 1)];
500
-	}
501
-	return $pass;
494
+    $allowable_characters = "abcdefghjkmnpqrstuvxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
495
+    $ps_len = strlen($allowable_characters);
496
+    mt_srand((double) microtime() * 1000000);
497
+    $pass = "";
498
+    for($i = 0; $i < $length; $i++) {
499
+        $pass .= $allowable_characters[mt_rand(0, $ps_len - 1)];
500
+    }
501
+    return $pass;
502 502
 }
Please login to merge, or discard this patch.
manager/processors/login.processor.php 1 patch
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
3
-	header('HTTP/1.0 404 Not Found');
4
-	exit('error');
3
+    header('HTTP/1.0 404 Not Found');
4
+    exit('error');
5 5
 }
6 6
 define('IN_MANAGER_MODE', true);  // we use this to make sure files are accessed through
7 7
 define('MODX_API_MODE', true);
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 include_once("{$core_path}lang/english.inc.php");
19 19
 
20 20
 if($manager_language !== 'english' && is_file("{$core_path}lang/{$manager_language}.inc.php")) {
21
-	include_once("{$core_path}lang/{$manager_language}.inc.php");
21
+    include_once("{$core_path}lang/{$manager_language}.inc.php");
22 22
 }
23 23
 
24 24
 // include the logger
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 // Initialize System Alert Message Queque
28 28
 if(!isset($_SESSION['SystemAlertMsgQueque'])) {
29
-	$_SESSION['SystemAlertMsgQueque'] = array();
29
+    $_SESSION['SystemAlertMsgQueque'] = array();
30 30
 }
31 31
 $SystemAlertMsgQueque = &$_SESSION['SystemAlertMsgQueque'];
32 32
 
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
 
42 42
 // invoke OnBeforeManagerLogin event
43 43
 $modx->invokeEvent('OnBeforeManagerLogin', array(
44
-		'username' => $username,
45
-		'userpassword' => $givenPassword,
46
-		'rememberme' => $rememberme
47
-	));
44
+        'username' => $username,
45
+        'userpassword' => $givenPassword,
46
+        'rememberme' => $rememberme
47
+    ));
48 48
 $fields = 'mu.*, ua.*';
49 49
 $from = '[+prefix+]manager_users AS mu, [+prefix+]user_attributes AS ua';
50 50
 $where = "BINARY mu.username='{$username}' and ua.internalKey=mu.id";
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 $limit = $modx->db->getRecordCount($rs);
53 53
 
54 54
 if($limit == 0 || $limit > 1) {
55
-	jsAlert($_lang['login_processor_unknown_user']);
56
-	return;
55
+    jsAlert($_lang['login_processor_unknown_user']);
56
+    return;
57 57
 }
58 58
 
59 59
 $row = $modx->db->getRow($rs);
@@ -74,127 +74,127 @@  discard block
 block discarded – undo
74 74
 // get the user settings from the database
75 75
 $rs = $modx->db->select('setting_name, setting_value', '[+prefix+]user_settings', "user='{$internalKey}' AND setting_value!=''");
76 76
 while($row = $modx->db->getRow($rs)) {
77
-	extract($row);
78
-	${$setting_name} = $setting_value;
77
+    extract($row);
78
+    ${$setting_name} = $setting_value;
79 79
 }
80 80
 
81 81
 // blocked due to number of login errors.
82 82
 if($failedlogins >= $failed_allowed && $blockeduntildate > time()) {
83
-	@session_destroy();
84
-	session_unset();
85
-	if($cip = getenv("HTTP_CLIENT_IP")) {
86
-		$ip = $cip;
87
-	} elseif($cip = getenv("HTTP_X_FORWARDED_FOR")) {
88
-		$ip = $cip;
89
-	} elseif($cip = getenv("REMOTE_ADDR")) {
90
-		$ip = $cip;
91
-	} else {
92
-		$ip = "UNKNOWN";
93
-	}
94
-	$log = new logHandler;
95
-	$log->initAndWriteLog("Login Fail (Temporary Block)", $internalKey, $username, "119", $internalKey, "IP: " . $ip);
96
-	jsAlert($_lang['login_processor_many_failed_logins']);
97
-	return;
83
+    @session_destroy();
84
+    session_unset();
85
+    if($cip = getenv("HTTP_CLIENT_IP")) {
86
+        $ip = $cip;
87
+    } elseif($cip = getenv("HTTP_X_FORWARDED_FOR")) {
88
+        $ip = $cip;
89
+    } elseif($cip = getenv("REMOTE_ADDR")) {
90
+        $ip = $cip;
91
+    } else {
92
+        $ip = "UNKNOWN";
93
+    }
94
+    $log = new logHandler;
95
+    $log->initAndWriteLog("Login Fail (Temporary Block)", $internalKey, $username, "119", $internalKey, "IP: " . $ip);
96
+    jsAlert($_lang['login_processor_many_failed_logins']);
97
+    return;
98 98
 }
99 99
 
100 100
 // blocked due to number of login errors, but get to try again
101 101
 if($failedlogins >= $failed_allowed && $blockeduntildate < time()) {
102
-	$fields = array();
103
-	$fields['failedlogincount'] = '0';
104
-	$fields['blockeduntil'] = time() - 1;
105
-	$modx->db->update($fields, '[+prefix+]user_attributes', "internalKey='{$internalKey}'");
102
+    $fields = array();
103
+    $fields['failedlogincount'] = '0';
104
+    $fields['blockeduntil'] = time() - 1;
105
+    $modx->db->update($fields, '[+prefix+]user_attributes', "internalKey='{$internalKey}'");
106 106
 }
107 107
 
108 108
 // this user has been blocked by an admin, so no way he's loggin in!
109 109
 if($blocked == '1') {
110
-	@session_destroy();
111
-	session_unset();
112
-	jsAlert($_lang['login_processor_blocked1']);
113
-	return;
110
+    @session_destroy();
111
+    session_unset();
112
+    jsAlert($_lang['login_processor_blocked1']);
113
+    return;
114 114
 }
115 115
 
116 116
 // blockuntil: this user has a block until date
117 117
 if($blockeduntildate > time()) {
118
-	@session_destroy();
119
-	session_unset();
120
-	jsAlert($_lang['login_processor_blocked2']);
121
-	return;
118
+    @session_destroy();
119
+    session_unset();
120
+    jsAlert($_lang['login_processor_blocked2']);
121
+    return;
122 122
 }
123 123
 
124 124
 // blockafter: this user has a block after date
125 125
 if($blockedafterdate > 0 && $blockedafterdate < time()) {
126
-	@session_destroy();
127
-	session_unset();
128
-	jsAlert($_lang['login_processor_blocked3']);
129
-	return;
126
+    @session_destroy();
127
+    session_unset();
128
+    jsAlert($_lang['login_processor_blocked3']);
129
+    return;
130 130
 }
131 131
 
132 132
 // allowed ip
133 133
 if($allowed_ip) {
134
-	if(($hostname = gethostbyaddr($_SERVER['REMOTE_ADDR'])) && ($hostname != $_SERVER['REMOTE_ADDR'])) {
135
-		if(gethostbyname($hostname) != $_SERVER['REMOTE_ADDR']) {
136
-			jsAlert($_lang['login_processor_remotehost_ip']);
137
-			return;
138
-		}
139
-	}
140
-	if(!in_array($_SERVER['REMOTE_ADDR'], array_filter(array_map('trim', explode(',', $allowed_ip))))) {
141
-		jsAlert($_lang['login_processor_remote_ip']);
142
-		return;
143
-	}
134
+    if(($hostname = gethostbyaddr($_SERVER['REMOTE_ADDR'])) && ($hostname != $_SERVER['REMOTE_ADDR'])) {
135
+        if(gethostbyname($hostname) != $_SERVER['REMOTE_ADDR']) {
136
+            jsAlert($_lang['login_processor_remotehost_ip']);
137
+            return;
138
+        }
139
+    }
140
+    if(!in_array($_SERVER['REMOTE_ADDR'], array_filter(array_map('trim', explode(',', $allowed_ip))))) {
141
+        jsAlert($_lang['login_processor_remote_ip']);
142
+        return;
143
+    }
144 144
 }
145 145
 
146 146
 // allowed days
147 147
 if($allowed_days) {
148
-	$date = getdate();
149
-	$day = $date['wday'] + 1;
150
-	if(strpos($allowed_days, $day) === false) {
151
-		jsAlert($_lang['login_processor_date']);
152
-		return;
153
-	}
148
+    $date = getdate();
149
+    $day = $date['wday'] + 1;
150
+    if(strpos($allowed_days, $day) === false) {
151
+        jsAlert($_lang['login_processor_date']);
152
+        return;
153
+    }
154 154
 }
155 155
 
156 156
 // invoke OnManagerAuthentication event
157 157
 $rt = $modx->invokeEvent('OnManagerAuthentication', array(
158
-		'userid' => $internalKey,
159
-		'username' => $username,
160
-		'userpassword' => $givenPassword,
161
-		'savedpassword' => $dbasePassword,
162
-		'rememberme' => $rememberme
163
-	));
158
+        'userid' => $internalKey,
159
+        'username' => $username,
160
+        'userpassword' => $givenPassword,
161
+        'savedpassword' => $dbasePassword,
162
+        'rememberme' => $rememberme
163
+    ));
164 164
 
165 165
 // check if plugin authenticated the user
166 166
 $matchPassword = false;
167 167
 if(!isset($rt) || !$rt || (is_array($rt) && !in_array(true, $rt))) {
168
-	// check user password - local authentication
169
-	$hashType = $modx->manager->getHashType($dbasePassword);
170
-	if($hashType == 'phpass') {
171
-		$matchPassword = login($username, $_REQUEST['password'], $dbasePassword);
172
-	} elseif($hashType == 'md5') {
173
-		$matchPassword = loginMD5($internalKey, $_REQUEST['password'], $dbasePassword, $username);
174
-	} elseif($hashType == 'v1') {
175
-		$matchPassword = loginV1($internalKey, $_REQUEST['password'], $dbasePassword, $username);
176
-	} else {
177
-		$matchPassword = false;
178
-	}
168
+    // check user password - local authentication
169
+    $hashType = $modx->manager->getHashType($dbasePassword);
170
+    if($hashType == 'phpass') {
171
+        $matchPassword = login($username, $_REQUEST['password'], $dbasePassword);
172
+    } elseif($hashType == 'md5') {
173
+        $matchPassword = loginMD5($internalKey, $_REQUEST['password'], $dbasePassword, $username);
174
+    } elseif($hashType == 'v1') {
175
+        $matchPassword = loginV1($internalKey, $_REQUEST['password'], $dbasePassword, $username);
176
+    } else {
177
+        $matchPassword = false;
178
+    }
179 179
 } else if($rt === true || (is_array($rt) && in_array(true, $rt))) {
180
-	$matchPassword = true;
180
+    $matchPassword = true;
181 181
 }
182 182
 
183 183
 if(!$matchPassword) {
184
-	jsAlert($_lang['login_processor_wrong_password']);
185
-	incrementFailedLoginCount($internalKey, $failedlogins, $failed_allowed, $blocked_minutes);
186
-	return;
184
+    jsAlert($_lang['login_processor_wrong_password']);
185
+    incrementFailedLoginCount($internalKey, $failedlogins, $failed_allowed, $blocked_minutes);
186
+    return;
187 187
 }
188 188
 
189 189
 if($modx->config['use_captcha'] == 1) {
190
-	if(!isset ($_SESSION['veriword'])) {
191
-		jsAlert($_lang['login_processor_captcha_config']);
192
-		return;
193
-	} elseif($_SESSION['veriword'] != $captcha_code) {
194
-		jsAlert($_lang['login_processor_bad_code']);
195
-		incrementFailedLoginCount($internalKey, $failedlogins, $failed_allowed, $blocked_minutes);
196
-		return;
197
-	}
190
+    if(!isset ($_SESSION['veriword'])) {
191
+        jsAlert($_lang['login_processor_captcha_config']);
192
+        return;
193
+    } elseif($_SESSION['veriword'] != $captcha_code) {
194
+        jsAlert($_lang['login_processor_bad_code']);
195
+        incrementFailedLoginCount($internalKey, $failedlogins, $failed_allowed, $blocked_minutes);
196
+        return;
197
+    }
198 198
 }
199 199
 
200 200
 $modx->cleanupExpiredLocks();
@@ -229,36 +229,36 @@  discard block
 block discarded – undo
229 229
 $_SESSION['mgrToken'] = md5($currentsessionid);
230 230
 
231 231
 if($rememberme == '1') {
232
-	$_SESSION['modx.mgr.session.cookie.lifetime'] = (int)$modx->config['session.cookie.lifetime'];
233
-
234
-	// Set a cookie separate from the session cookie with the username in it.
235
-	// Are we using secure connection? If so, make sure the cookie is secure
236
-	global $https_port;
237
-
238
-	$secure = ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port);
239
-	if(version_compare(PHP_VERSION, '5.2', '<')) {
240
-		setcookie('modx_remember_manager', $_SESSION['mgrShortname'], time() + 60 * 60 * 24 * 365, MODX_BASE_URL, '; HttpOnly', $secure);
241
-	} else {
242
-		setcookie('modx_remember_manager', $_SESSION['mgrShortname'], time() + 60 * 60 * 24 * 365, MODX_BASE_URL, NULL, $secure, true);
243
-	}
232
+    $_SESSION['modx.mgr.session.cookie.lifetime'] = (int)$modx->config['session.cookie.lifetime'];
233
+
234
+    // Set a cookie separate from the session cookie with the username in it.
235
+    // Are we using secure connection? If so, make sure the cookie is secure
236
+    global $https_port;
237
+
238
+    $secure = ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port);
239
+    if(version_compare(PHP_VERSION, '5.2', '<')) {
240
+        setcookie('modx_remember_manager', $_SESSION['mgrShortname'], time() + 60 * 60 * 24 * 365, MODX_BASE_URL, '; HttpOnly', $secure);
241
+    } else {
242
+        setcookie('modx_remember_manager', $_SESSION['mgrShortname'], time() + 60 * 60 * 24 * 365, MODX_BASE_URL, NULL, $secure, true);
243
+    }
244 244
 } else {
245
-	$_SESSION['modx.mgr.session.cookie.lifetime'] = 0;
245
+    $_SESSION['modx.mgr.session.cookie.lifetime'] = 0;
246 246
 
247
-	// Remove the Remember Me cookie
248
-	setcookie('modx_remember_manager', '', time() - 3600, MODX_BASE_URL);
247
+    // Remove the Remember Me cookie
248
+    setcookie('modx_remember_manager', '', time() - 3600, MODX_BASE_URL);
249 249
 }
250 250
 
251 251
 // Check if user already has an active session, if not check if user pressed logout end of last session
252 252
 $rs = $modx->db->select('lasthit', $modx->getFullTableName('active_user_sessions'), "internalKey='{$internalKey}'");
253 253
 $activeSession = $modx->db->getValue($rs);
254 254
 if(!$activeSession) {
255
-	$rs = $modx->db->select('lasthit', $modx->getFullTableName('active_users'), "internalKey='{$internalKey}' AND action != 8");
256
-	if($lastHit = $modx->db->getValue($rs)) {
257
-		$_SESSION['show_logout_reminder'] = array(
258
-			'type' => 'logout_reminder',
259
-			'lastHit' => $lastHit
260
-		);
261
-	}
255
+    $rs = $modx->db->select('lasthit', $modx->getFullTableName('active_users'), "internalKey='{$internalKey}' AND action != 8");
256
+    if($lastHit = $modx->db->getValue($rs)) {
257
+        $_SESSION['show_logout_reminder'] = array(
258
+            'type' => 'logout_reminder',
259
+            'lastHit' => $lastHit
260
+        );
261
+    }
262 262
 }
263 263
 
264 264
 $log = new logHandler;
@@ -266,29 +266,29 @@  discard block
 block discarded – undo
266 266
 
267 267
 // invoke OnManagerLogin event
268 268
 $modx->invokeEvent('OnManagerLogin', array(
269
-		'userid' => $internalKey,
270
-		'username' => $username,
271
-		'userpassword' => $givenPassword,
272
-		'rememberme' => $rememberme
273
-	));
269
+        'userid' => $internalKey,
270
+        'username' => $username,
271
+        'userpassword' => $givenPassword,
272
+        'rememberme' => $rememberme
273
+    ));
274 274
 
275 275
 // check if we should redirect user to a web page
276 276
 $rs = $modx->db->select('setting_value', '[+prefix+]user_settings', "user='{$internalKey}' AND setting_name='manager_login_startup'");
277 277
 $id = (int)$modx->db->getValue($rs);
278 278
 if($id > 0) {
279
-	$header = 'Location: ' . $modx->makeUrl($id, '', '', 'full');
280
-	if($_POST['ajax'] == 1) {
281
-		echo $header;
282
-	} else {
283
-		header($header);
284
-	}
279
+    $header = 'Location: ' . $modx->makeUrl($id, '', '', 'full');
280
+    if($_POST['ajax'] == 1) {
281
+        echo $header;
282
+    } else {
283
+        header($header);
284
+    }
285 285
 } else {
286
-	$header = 'Location: ' . MODX_MANAGER_URL;
287
-	if($_POST['ajax'] == 1) {
288
-		echo $header;
289
-	} else {
290
-		header($header);
291
-	}
286
+    $header = 'Location: ' . MODX_MANAGER_URL;
287
+    if($_POST['ajax'] == 1) {
288
+        echo $header;
289
+    } else {
290
+        header($header);
291
+    }
292 292
 }
293 293
 
294 294
 /**
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
  * @param string $msg
298 298
  */
299 299
 function jsAlert($msg) {
300
-	global $modx;
301
-	if($_POST['ajax'] != 1) {
302
-		echo "<script>window.setTimeout(\"alert('" . addslashes($modx->db->escape($msg)) . "')\",10);history.go(-1)</script>";
303
-	} else {
304
-		echo $msg . "\n";
305
-	}
300
+    global $modx;
301
+    if($_POST['ajax'] != 1) {
302
+        echo "<script>window.setTimeout(\"alert('" . addslashes($modx->db->escape($msg)) . "')\",10);history.go(-1)</script>";
303
+    } else {
304
+        echo $msg . "\n";
305
+    }
306 306
 }
307 307
 
308 308
 /**
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
  * @return bool
313 313
  */
314 314
 function login($username, $givenPassword, $dbasePassword) {
315
-	global $modx;
316
-	return $modx->phpass->CheckPassword($givenPassword, $dbasePassword);
315
+    global $modx;
316
+    return $modx->phpass->CheckPassword($givenPassword, $dbasePassword);
317 317
 }
318 318
 
319 319
 /**
@@ -324,26 +324,26 @@  discard block
 block discarded – undo
324 324
  * @return bool
325 325
  */
326 326
 function loginV1($internalKey, $givenPassword, $dbasePassword, $username) {
327
-	global $modx;
327
+    global $modx;
328 328
 
329
-	$user_algo = $modx->manager->getV1UserHashAlgorithm($internalKey);
329
+    $user_algo = $modx->manager->getV1UserHashAlgorithm($internalKey);
330 330
 
331
-	if(!isset($modx->config['pwd_hash_algo']) || empty($modx->config['pwd_hash_algo'])) {
332
-		$modx->config['pwd_hash_algo'] = 'UNCRYPT';
333
-	}
331
+    if(!isset($modx->config['pwd_hash_algo']) || empty($modx->config['pwd_hash_algo'])) {
332
+        $modx->config['pwd_hash_algo'] = 'UNCRYPT';
333
+    }
334 334
 
335
-	if($user_algo !== $modx->config['pwd_hash_algo']) {
336
-		$bk_pwd_hash_algo = $modx->config['pwd_hash_algo'];
337
-		$modx->config['pwd_hash_algo'] = $user_algo;
338
-	}
335
+    if($user_algo !== $modx->config['pwd_hash_algo']) {
336
+        $bk_pwd_hash_algo = $modx->config['pwd_hash_algo'];
337
+        $modx->config['pwd_hash_algo'] = $user_algo;
338
+    }
339 339
 
340
-	if($dbasePassword != $modx->manager->genV1Hash($givenPassword, $internalKey)) {
341
-		return false;
342
-	}
340
+    if($dbasePassword != $modx->manager->genV1Hash($givenPassword, $internalKey)) {
341
+        return false;
342
+    }
343 343
 
344
-	updateNewHash($username, $givenPassword);
344
+    updateNewHash($username, $givenPassword);
345 345
 
346
-	return true;
346
+    return true;
347 347
 }
348 348
 
349 349
 /**
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
  * @return bool
355 355
  */
356 356
 function loginMD5($internalKey, $givenPassword, $dbasePassword, $username) {
357
-	global $modx;
357
+    global $modx;
358 358
 
359
-	if($dbasePassword != md5($givenPassword)) {
360
-		return false;
361
-	}
362
-	updateNewHash($username, $givenPassword);
363
-	return true;
359
+    if($dbasePassword != md5($givenPassword)) {
360
+        return false;
361
+    }
362
+    updateNewHash($username, $givenPassword);
363
+    return true;
364 364
 }
365 365
 
366 366
 /**
@@ -368,11 +368,11 @@  discard block
 block discarded – undo
368 368
  * @param string $password
369 369
  */
370 370
 function updateNewHash($username, $password) {
371
-	global $modx;
371
+    global $modx;
372 372
 
373
-	$field = array();
374
-	$field['password'] = $modx->phpass->HashPassword($password);
375
-	$modx->db->update($field, '[+prefix+]manager_users', "username='{$username}'");
373
+    $field = array();
374
+    $field['password'] = $modx->phpass->HashPassword($password);
375
+    $modx->db->update($field, '[+prefix+]manager_users', "username='{$username}'");
376 376
 }
377 377
 
378 378
 /**
@@ -382,27 +382,27 @@  discard block
 block discarded – undo
382 382
  * @param int $blocked_minutes
383 383
  */
384 384
 function incrementFailedLoginCount($internalKey, $failedlogins, $failed_allowed, $blocked_minutes) {
385
-	global $modx;
386
-
387
-	$failedlogins += 1;
388
-
389
-	$fields = array('failedlogincount' => $failedlogins);
390
-	if($failedlogins >= $failed_allowed) //block user for too many fail attempts
391
-	{
392
-		$fields['blockeduntil'] = time() + ($blocked_minutes * 60);
393
-	}
394
-
395
-	$modx->db->update($fields, '[+prefix+]user_attributes', "internalKey='{$internalKey}'");
396
-
397
-	if($failedlogins < $failed_allowed) {
398
-		//sleep to help prevent brute force attacks
399
-		$sleep = (int) $failedlogins / 2;
400
-		if($sleep > 5) {
401
-			$sleep = 5;
402
-		}
403
-		sleep($sleep);
404
-	}
405
-	@session_destroy();
406
-	session_unset();
407
-	return;
385
+    global $modx;
386
+
387
+    $failedlogins += 1;
388
+
389
+    $fields = array('failedlogincount' => $failedlogins);
390
+    if($failedlogins >= $failed_allowed) //block user for too many fail attempts
391
+    {
392
+        $fields['blockeduntil'] = time() + ($blocked_minutes * 60);
393
+    }
394
+
395
+    $modx->db->update($fields, '[+prefix+]user_attributes', "internalKey='{$internalKey}'");
396
+
397
+    if($failedlogins < $failed_allowed) {
398
+        //sleep to help prevent brute force attacks
399
+        $sleep = (int) $failedlogins / 2;
400
+        if($sleep > 5) {
401
+            $sleep = 5;
402
+        }
403
+        sleep($sleep);
404
+    }
405
+    @session_destroy();
406
+    session_unset();
407
+    return;
408 408
 }
Please login to merge, or discard this patch.
manager/processors/undelete_content.processor.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@  discard block
 block discarded – undo
3 3
     die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
4 4
 }
5 5
 if(!$modx->hasPermission('delete_document')) {
6
-	$modx->webAlertAndQuit($_lang["error_no_privileges"]);
6
+    $modx->webAlertAndQuit($_lang["error_no_privileges"]);
7 7
 }
8 8
 
9 9
 $id = isset($_REQUEST['id'])? (int)$_REQUEST['id'] : 0;
10 10
 if($id==0) {
11
-	$modx->webAlertAndQuit($_lang["error_no_id"]);
11
+    $modx->webAlertAndQuit($_lang["error_no_id"]);
12 12
 }
13 13
 
14 14
 /************ webber ********/
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
 $udperms->role = $_SESSION['mgrRole'];
33 33
 
34 34
 if(!$udperms->checkPermissions()) {
35
-	$modx->webAlertAndQuit($_lang["access_permission_denied"]);
35
+    $modx->webAlertAndQuit($_lang["access_permission_denied"]);
36 36
 }
37 37
 
38 38
 // get the timestamp on which the document was deleted.
39 39
 $rs = $modx->db->select('deletedon', $modx->getFullTableName('site_content'), "id='{$id}' AND deleted=1");
40 40
 $deltime = $modx->db->getValue($rs);
41 41
 if(!$deltime) {
42
-	$modx->webAlertAndQuit("Couldn't find document to determine it's date of deletion!");
42
+    $modx->webAlertAndQuit("Couldn't find document to determine it's date of deletion!");
43 43
 }
44 44
 
45 45
 $children = array();
@@ -49,36 +49,36 @@  discard block
 block discarded – undo
49 49
  */
50 50
 function getChildren($parent) {
51 51
 
52
-	global $modx;
53
-	global $children;
54
-	global $deltime;
55
-
56
-	$rs = $modx->db->select('id', $modx->getFullTableName('site_content'), "parent='".(int)$parent."' AND deleted=1 AND deletedon='".(int)$deltime."'");
57
-		// the document has children documents, we'll need to delete those too
58
-		while ($row=$modx->db->getRow($rs)) {
59
-			$children[] = $row['id'];
60
-			getChildren($row['id']);
61
-			//echo "Found childNode of parentNode $parent: ".$row['id']."<br />";
62
-		}
52
+    global $modx;
53
+    global $children;
54
+    global $deltime;
55
+
56
+    $rs = $modx->db->select('id', $modx->getFullTableName('site_content'), "parent='".(int)$parent."' AND deleted=1 AND deletedon='".(int)$deltime."'");
57
+        // the document has children documents, we'll need to delete those too
58
+        while ($row=$modx->db->getRow($rs)) {
59
+            $children[] = $row['id'];
60
+            getChildren($row['id']);
61
+            //echo "Found childNode of parentNode $parent: ".$row['id']."<br />";
62
+        }
63 63
 }
64 64
 
65 65
 getChildren($id);
66 66
 
67 67
 if(count($children)>0) {
68
-	$modx->db->update(
69
-		array(
70
-			'deleted'   => 0,
71
-			'deletedby' => 0,
72
-			'deletedon' => 0,
73
-		), $modx->getFullTableName('site_content'), "id IN(".implode(", ", $children).")");
68
+    $modx->db->update(
69
+        array(
70
+            'deleted'   => 0,
71
+            'deletedby' => 0,
72
+            'deletedon' => 0,
73
+        ), $modx->getFullTableName('site_content'), "id IN(".implode(", ", $children).")");
74 74
 }
75 75
 //'undelete' the document.
76 76
 $modx->db->update(
77
-	array(
78
-		'deleted'   => 0,
79
-		'deletedby' => 0,
80
-		'deletedon' => 0,
81
-	), $modx->getFullTableName('site_content'), "id='{$id}'");
77
+    array(
78
+        'deleted'   => 0,
79
+        'deletedby' => 0,
80
+        'deletedon' => 0,
81
+    ), $modx->getFullTableName('site_content'), "id='{$id}'");
82 82
 
83 83
 $modx->invokeEvent("OnDocFormUnDelete",
84 84
     array(
Please login to merge, or discard this patch.