Completed
Push — master ( 73f088...7f17b6 )
by Yannick
07:13
created
require/libs/simple_html_dom.php 1 patch
Braces   +193 added lines, -101 removed lines patch added patch discarded remove patch
@@ -159,8 +159,9 @@  discard block
 block discarded – undo
159 159
 		if ($show_attr && count($this->attr)>0)
160 160
 		{
161 161
 			echo '(';
162
-			foreach ($this->attr as $k=>$v)
163
-				echo "[$k]=>\"".$this->$k.'", ';
162
+			foreach ($this->attr as $k=>$v) {
163
+							echo "[$k]=>\"".$this->$k.'", ';
164
+			}
164 165
 			echo ')';
165 166
 		}
166 167
 		echo "\n";
@@ -218,8 +219,7 @@  discard block
 block discarded – undo
218 219
 		if (isset($node->_[HDOM_INFO_INNER]))
219 220
 		{
220 221
 			$string .= $node->_[HDOM_INFO_INNER] . "'";
221
-		}
222
-		else
222
+		} else
223 223
 		{
224 224
 			$string .= ' NULL ';
225 225
 		}
@@ -233,8 +233,7 @@  discard block
 block discarded – undo
233 233
 		{
234 234
 			echo $string;
235 235
 			return;
236
-		}
237
-		else
236
+		} else
238 237
 		{
239 238
 			return $string;
240 239
 		}
@@ -320,12 +319,17 @@  discard block
 block discarded – undo
320 319
 	// returns the previous sibling of node
321 320
 	function prev_sibling()
322 321
 	{
323
-		if ($this->parent===null) return null;
322
+		if ($this->parent===null) {
323
+			return null;
324
+		}
324 325
 		$idx = 0;
325 326
 		$count = count($this->parent->children);
326
-		while ($idx<$count && $this!==$this->parent->children[$idx])
327
-			++$idx;
328
-		if (--$idx<0) return null;
327
+		while ($idx<$count && $this!==$this->parent->children[$idx]) {
328
+					++$idx;
329
+		}
330
+		if (--$idx<0) {
331
+			return null;
332
+		}
329 333
 		return $this->parent->children[$idx];
330 334
 	}
331 335
 
@@ -354,12 +358,17 @@  discard block
 block discarded – undo
354 358
 	// get dom node's inner html
355 359
 	function innertext()
356 360
 	{
357
-		if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];
358
-		if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
361
+		if (isset($this->_[HDOM_INFO_INNER])) {
362
+			return $this->_[HDOM_INFO_INNER];
363
+		}
364
+		if (isset($this->_[HDOM_INFO_TEXT])) {
365
+			return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
366
+		}
359 367
 
360 368
 		$ret = '';
361
-		foreach ($this->nodes as $n)
362
-			$ret .= $n->outertext();
369
+		foreach ($this->nodes as $n) {
370
+					$ret .= $n->outertext();
371
+		}
363 372
 		return $ret;
364 373
 	}
365 374
 
@@ -380,7 +389,9 @@  discard block
 block discarded – undo
380 389
 			$debug_object->debug_log(1, 'Innertext of tag: ' . $this->tag . $text);
381 390
 		}
382 391
 
383
-		if ($this->tag==='root') return $this->innertext();
392
+		if ($this->tag==='root') {
393
+			return $this->innertext();
394
+		}
384 395
 
385 396
 		// trigger callback
386 397
 		if ($this->dom && $this->dom->callback!==null)
@@ -388,8 +399,12 @@  discard block
 block discarded – undo
388 399
 			call_user_func_array($this->dom->callback, array($this));
389 400
 		}
390 401
 
391
-		if (isset($this->_[HDOM_INFO_OUTER])) return $this->_[HDOM_INFO_OUTER];
392
-		if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
402
+		if (isset($this->_[HDOM_INFO_OUTER])) {
403
+			return $this->_[HDOM_INFO_OUTER];
404
+		}
405
+		if (isset($this->_[HDOM_INFO_TEXT])) {
406
+			return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
407
+		}
393 408
 
394 409
 		// render begin tag
395 410
 		if ($this->dom && $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]])
@@ -418,23 +433,30 @@  discard block
 block discarded – undo
418 433
 		}
419 434
 
420 435
 		// render end tag
421
-		if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0)
422
-			$ret .= '</'.$this->tag.'>';
436
+		if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0) {
437
+					$ret .= '</'.$this->tag.'>';
438
+		}
423 439
 		return $ret;
424 440
 	}
425 441
 
426 442
 	// get dom node's plain text
427 443
 	function text()
428 444
 	{
429
-		if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];
445
+		if (isset($this->_[HDOM_INFO_INNER])) {
446
+			return $this->_[HDOM_INFO_INNER];
447
+		}
430 448
 		switch ($this->nodetype)
431 449
 		{
432 450
 			case HDOM_TYPE_TEXT: return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
433 451
 			case HDOM_TYPE_COMMENT: return '';
434 452
 			case HDOM_TYPE_UNKNOWN: return '';
435 453
 		}
436
-		if (strcasecmp($this->tag, 'script')===0) return '';
437
-		if (strcasecmp($this->tag, 'style')===0) return '';
454
+		if (strcasecmp($this->tag, 'script')===0) {
455
+			return '';
456
+		}
457
+		if (strcasecmp($this->tag, 'style')===0) {
458
+			return '';
459
+		}
438 460
 
439 461
 		$ret = '';
440 462
 		// In rare cases, (always node type 1 or HDOM_TYPE_ELEMENT - observed for some span tags, and some p tags) $this->nodes is set to NULL.
@@ -470,7 +492,9 @@  discard block
 block discarded – undo
470 492
 	function makeup()
471 493
 	{
472 494
 		// text, comment, unknown
473
-		if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
495
+		if (isset($this->_[HDOM_INFO_TEXT])) {
496
+			return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
497
+		}
474 498
 
475 499
 		$ret = '<'.$this->tag;
476 500
 		$i = -1;
@@ -480,14 +504,15 @@  discard block
 block discarded – undo
480 504
 			++$i;
481 505
 
482 506
 			// skip removed attribute
483
-			if ($val===null || $val===false)
484
-				continue;
507
+			if ($val===null || $val===false) {
508
+							continue;
509
+			}
485 510
 
486 511
 			$ret .= $this->_[HDOM_INFO_SPACE][$i][0];
487 512
 			//no value attr: nowrap, checked selected...
488
-			if ($val===true)
489
-				$ret .= $key;
490
-			else {
513
+			if ($val===true) {
514
+							$ret .= $key;
515
+			} else {
491 516
 				switch ($this->_[HDOM_INFO_QUOTE][$i])
492 517
 				{
493 518
 					case HDOM_QUOTE_DOUBLE: $quote = '"'; break;
@@ -506,7 +531,9 @@  discard block
 block discarded – undo
506 531
 	function find($selector, $idx=null, $lowercase=false)
507 532
 	{
508 533
 		$selectors = $this->parse_selector($selector);
509
-		if (($count=count($selectors))===0) return array();
534
+		if (($count=count($selectors))===0) {
535
+			return array();
536
+		}
510 537
 		$found_keys = array();
511 538
 
512 539
 		// find each selector
@@ -514,8 +541,12 @@  discard block
 block discarded – undo
514 541
 		{
515 542
 			// The change on the below line was documented on the sourceforge code tracker id 2788009
516 543
 			// used to be: if (($levle=count($selectors[0]))===0) return array();
517
-			if (($levle=count($selectors[$c]))===0) return array();
518
-			if (!isset($this->_[HDOM_INFO_BEGIN])) return array();
544
+			if (($levle=count($selectors[$c]))===0) {
545
+				return array();
546
+			}
547
+			if (!isset($this->_[HDOM_INFO_BEGIN])) {
548
+				return array();
549
+			}
519 550
 
520 551
 			$head = array($this->_[HDOM_INFO_BEGIN]=>1);
521 552
 
@@ -545,12 +576,16 @@  discard block
 block discarded – undo
545 576
 		ksort($found_keys);
546 577
 
547 578
 		$found = array();
548
-		foreach ($found_keys as $k=>$v)
549
-			$found[] = $this->dom->nodes[$k];
579
+		foreach ($found_keys as $k=>$v) {
580
+					$found[] = $this->dom->nodes[$k];
581
+		}
550 582
 
551 583
 		// return nth-element or array
552
-		if (is_null($idx)) return $found;
553
-		else if ($idx<0) $idx = count($found) + $idx;
584
+		if (is_null($idx)) {
585
+			return $found;
586
+		} else if ($idx<0) {
587
+			$idx = count($found) + $idx;
588
+		}
554 589
 		return (isset($found[$idx])) ? $found[$idx] : null;
555 590
 	}
556 591
 
@@ -595,8 +630,9 @@  discard block
 block discarded – undo
595 630
 			$pass = true;
596 631
 
597 632
 			if ($tag==='*' && !$key) {
598
-				if (in_array($node, $this->children, true))
599
-					$ret[$i] = 1;
633
+				if (in_array($node, $this->children, true)) {
634
+									$ret[$i] = 1;
635
+				}
600 636
 				continue;
601 637
 			}
602 638
 
@@ -605,9 +641,13 @@  discard block
 block discarded – undo
605 641
 			// compare key
606 642
 			if ($pass && $key) {
607 643
 				if ($no_key) {
608
-					if (isset($node->attr[$key])) $pass=false;
644
+					if (isset($node->attr[$key])) {
645
+						$pass=false;
646
+					}
609 647
 				} else {
610
-					if (($key != "plaintext") && !isset($node->attr[$key])) $pass=false;
648
+					if (($key != "plaintext") && !isset($node->attr[$key])) {
649
+						$pass=false;
650
+					}
611 651
 				}
612 652
 			}
613 653
 			// compare value
@@ -640,13 +680,19 @@  discard block
 block discarded – undo
640 680
 							} else {
641 681
 								$check = $this->match($exp, $val, $k);
642 682
 							}
643
-							if ($check) break;
683
+							if ($check) {
684
+								break;
685
+							}
644 686
 						}
645 687
 					}
646 688
 				}
647
-				if (!$check) $pass = false;
689
+				if (!$check) {
690
+					$pass = false;
691
+				}
692
+			}
693
+			if ($pass) {
694
+				$ret[$i] = 1;
648 695
 			}
649
-			if ($pass) $ret[$i] = 1;
650 696
 			unset($node);
651 697
 		}
652 698
 		// It's passed by reference so this is actually what this function returns.
@@ -696,9 +742,13 @@  discard block
 block discarded – undo
696 742
 
697 743
 		foreach ($matches as $m) {
698 744
 			$m[0] = trim($m[0]);
699
-			if ($m[0]==='' || $m[0]==='/' || $m[0]==='//') continue;
745
+			if ($m[0]==='' || $m[0]==='/' || $m[0]==='//') {
746
+				continue;
747
+			}
700 748
 			// for browser generated xpath
701
-			if ($m[1]==='tbody') continue;
749
+			if ($m[1]==='tbody') {
750
+				continue;
751
+			}
702 752
 
703 753
 			list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false);
704 754
 			if (!empty($m[2])) {$key='id'; $val=$m[2];}
@@ -718,8 +768,9 @@  discard block
 block discarded – undo
718 768
 				$result = array();
719 769
 			}
720 770
 		}
721
-		if (count($result)>0)
722
-			$selectors[] = $result;
771
+		if (count($result)>0) {
772
+					$selectors[] = $result;
773
+		}
723 774
 		return $selectors;
724 775
 	}
725 776
 
@@ -748,7 +799,9 @@  discard block
 block discarded – undo
748 799
 		{
749 800
 			case 'outertext': return $this->_[HDOM_INFO_OUTER] = $value;
750 801
 			case 'innertext':
751
-				if (isset($this->_[HDOM_INFO_TEXT])) return $this->_[HDOM_INFO_TEXT] = $value;
802
+				if (isset($this->_[HDOM_INFO_TEXT])) {
803
+					return $this->_[HDOM_INFO_TEXT] = $value;
804
+				}
752 805
 				return $this->_[HDOM_INFO_INNER] = $value;
753 806
 		}
754 807
 		if (!isset($this->attr[$name]))
@@ -772,8 +825,9 @@  discard block
 block discarded – undo
772 825
 	}
773 826
 
774 827
 	function __unset($name) {
775
-		if (isset($this->attr[$name]))
776
-			unset($this->attr[$name]);
828
+		if (isset($this->attr[$name])) {
829
+					unset($this->attr[$name]);
830
+		}
777 831
 	}
778 832
 
779 833
 	// PaperG - Function to convert the text from one character set to another if the two sets are not the same.
@@ -800,8 +854,7 @@  discard block
 block discarded – undo
800 854
 			if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text)))
801 855
 			{
802 856
 				$converted_text = $text;
803
-			}
804
-			else
857
+			} else
805 858
 			{
806 859
 				$converted_text = iconv($sourceCharset, $targetCharset, $text);
807 860
 			}
@@ -839,19 +892,31 @@  discard block
 block discarded – undo
839 892
 			$c=ord($str[$i]);
840 893
 			if($c > 128)
841 894
 			{
842
-				if(($c >= 254)) return false;
843
-				elseif($c >= 252) $bits=6;
844
-				elseif($c >= 248) $bits=5;
845
-				elseif($c >= 240) $bits=4;
846
-				elseif($c >= 224) $bits=3;
847
-				elseif($c >= 192) $bits=2;
848
-				else return false;
849
-				if(($i+$bits) > $len) return false;
895
+				if(($c >= 254)) {
896
+					return false;
897
+				} elseif($c >= 252) {
898
+					$bits=6;
899
+				} elseif($c >= 248) {
900
+					$bits=5;
901
+				} elseif($c >= 240) {
902
+					$bits=4;
903
+				} elseif($c >= 224) {
904
+					$bits=3;
905
+				} elseif($c >= 192) {
906
+					$bits=2;
907
+				} else {
908
+					return false;
909
+				}
910
+				if(($i+$bits) > $len) {
911
+					return false;
912
+				}
850 913
 				while($bits > 1)
851 914
 				{
852 915
 					$i++;
853 916
 					$b=ord($str[$i]);
854
-					if($b < 128 || $b > 191) return false;
917
+					if($b < 128 || $b > 191) {
918
+						return false;
919
+					}
855 920
 					$bits--;
856 921
 				}
857 922
 			}
@@ -1035,8 +1100,7 @@  discard block
 block discarded – undo
1035 1100
 			if (preg_match("/^http:\/\//i",$str) || is_file($str))
1036 1101
 			{
1037 1102
 				$this->load_file($str);
1038
-			}
1039
-			else
1103
+			} else
1040 1104
 			{
1041 1105
 				$this->load($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText);
1042 1106
 			}
@@ -1118,7 +1182,9 @@  discard block
 block discarded – undo
1118 1182
 	function save($filepath='')
1119 1183
 	{
1120 1184
 		$ret = $this->root->innertext();
1121
-		if ($filepath!=='') file_put_contents($filepath, $ret, LOCK_EX);
1185
+		if ($filepath!=='') {
1186
+			file_put_contents($filepath, $ret, LOCK_EX);
1187
+		}
1122 1188
 		return $ret;
1123 1189
 	}
1124 1190
 
@@ -1134,7 +1200,10 @@  discard block
 block discarded – undo
1134 1200
 	{
1135 1201
 		foreach ($this->nodes as $n) {$n->clear(); $n = null;}
1136 1202
 		// This add next line is documented in the sourceforge repository. 2977248 as a fix for ongoing memory leaks that occur even with the use of clear.
1137
-		if (isset($this->children)) foreach ($this->children as $n) {$n->clear(); $n = null;}
1203
+		if (isset($this->children)) {
1204
+			foreach ($this->children as $n) {$n->clear();
1205
+		}
1206
+		$n = null;}
1138 1207
 		if (isset($this->parent)) {$this->parent->clear(); unset($this->parent);}
1139 1208
 		if (isset($this->root)) {$this->root->clear(); unset($this->root);}
1140 1209
 		unset($this->doc);
@@ -1178,7 +1247,9 @@  discard block
 block discarded – undo
1178 1247
 		$this->root->_[HDOM_INFO_BEGIN] = -1;
1179 1248
 		$this->root->nodetype = HDOM_TYPE_ROOT;
1180 1249
 		$this->parent = $this->root;
1181
-		if ($this->size>0) $this->char = $this->doc[0];
1250
+		if ($this->size>0) {
1251
+			$this->char = $this->doc[0];
1252
+		}
1182 1253
 	}
1183 1254
 
1184 1255
 	// parse html content
@@ -1232,8 +1303,7 @@  discard block
 block discarded – undo
1232 1303
 					if ($success)
1233 1304
 					{
1234 1305
 						$charset = $matches[1];
1235
-					}
1236
-					else
1306
+					} else
1237 1307
 					{
1238 1308
 						// If there is a meta tag, and they don't specify the character set, research says that it's typically ISO-8859-1
1239 1309
 						if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag couldn\'t be parsed. using iso-8859 default.');}
@@ -1296,8 +1366,9 @@  discard block
 block discarded – undo
1296 1366
 			$tag = $this->copy_until_char('>');
1297 1367
 
1298 1368
 			// skip attributes in end tag
1299
-			if (($pos = strpos($tag, ' '))!==false)
1300
-				$tag = substr($tag, 0, $pos);
1369
+			if (($pos = strpos($tag, ' '))!==false) {
1370
+							$tag = substr($tag, 0, $pos);
1371
+			}
1301 1372
 
1302 1373
 			$parent_lower = strtolower($this->parent->tag);
1303 1374
 			$tag_lower = strtolower($tag);
@@ -1309,23 +1380,26 @@  discard block
 block discarded – undo
1309 1380
 					$this->parent->_[HDOM_INFO_END] = 0;
1310 1381
 					$org_parent = $this->parent;
1311 1382
 
1312
-					while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower)
1313
-						$this->parent = $this->parent->parent;
1383
+					while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower) {
1384
+											$this->parent = $this->parent->parent;
1385
+					}
1314 1386
 
1315 1387
 					if (strtolower($this->parent->tag)!==$tag_lower) {
1316 1388
 						$this->parent = $org_parent; // restore origonal parent
1317
-						if ($this->parent->parent) $this->parent = $this->parent->parent;
1389
+						if ($this->parent->parent) {
1390
+							$this->parent = $this->parent->parent;
1391
+						}
1318 1392
 						$this->parent->_[HDOM_INFO_END] = $this->cursor;
1319 1393
 						return $this->as_text_node($tag);
1320 1394
 					}
1321
-				}
1322
-				else if (($this->parent->parent) && isset($this->block_tags[$tag_lower]))
1395
+				} else if (($this->parent->parent) && isset($this->block_tags[$tag_lower]))
1323 1396
 				{
1324 1397
 					$this->parent->_[HDOM_INFO_END] = 0;
1325 1398
 					$org_parent = $this->parent;
1326 1399
 
1327
-					while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower)
1328
-						$this->parent = $this->parent->parent;
1400
+					while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower) {
1401
+											$this->parent = $this->parent->parent;
1402
+					}
1329 1403
 
1330 1404
 					if (strtolower($this->parent->tag)!==$tag_lower)
1331 1405
 					{
@@ -1333,18 +1407,19 @@  discard block
 block discarded – undo
1333 1407
 						$this->parent->_[HDOM_INFO_END] = $this->cursor;
1334 1408
 						return $this->as_text_node($tag);
1335 1409
 					}
1336
-				}
1337
-				else if (($this->parent->parent) && strtolower($this->parent->parent->tag)===$tag_lower)
1410
+				} else if (($this->parent->parent) && strtolower($this->parent->parent->tag)===$tag_lower)
1338 1411
 				{
1339 1412
 					$this->parent->_[HDOM_INFO_END] = 0;
1340 1413
 					$this->parent = $this->parent->parent;
1414
+				} else {
1415
+									return $this->as_text_node($tag);
1341 1416
 				}
1342
-				else
1343
-					return $this->as_text_node($tag);
1344 1417
 			}
1345 1418
 
1346 1419
 			$this->parent->_[HDOM_INFO_END] = $this->cursor;
1347
-			if ($this->parent->parent) $this->parent = $this->parent->parent;
1420
+			if ($this->parent->parent) {
1421
+				$this->parent = $this->parent->parent;
1422
+			}
1348 1423
 
1349 1424
 			$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1350 1425
 			return true;
@@ -1367,7 +1442,9 @@  discard block
 block discarded – undo
1367 1442
 				$node->nodetype = HDOM_TYPE_UNKNOWN;
1368 1443
 				$node->tag = 'unknown';
1369 1444
 			}
1370
-			if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>';
1445
+			if ($this->char==='>') {
1446
+				$node->_[HDOM_INFO_TEXT].='>';
1447
+			}
1371 1448
 			$this->link_nodes($node, true);
1372 1449
 			$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1373 1450
 			return true;
@@ -1389,7 +1466,9 @@  discard block
 block discarded – undo
1389 1466
 				return true;
1390 1467
 			}
1391 1468
 
1392
-			if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>';
1469
+			if ($this->char==='>') {
1470
+				$node->_[HDOM_INFO_TEXT].='>';
1471
+			}
1393 1472
 			$this->link_nodes($node, false);
1394 1473
 			$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1395 1474
 			return true;
@@ -1455,22 +1534,26 @@  discard block
 block discarded – undo
1455 1534
 			if ($name!=='/' && $name!=='') {
1456 1535
 				$space[1] = $this->copy_skip($this->token_blank);
1457 1536
 				$name = $this->restore_noise($name);
1458
-				if ($this->lowercase) $name = strtolower($name);
1537
+				if ($this->lowercase) {
1538
+					$name = strtolower($name);
1539
+				}
1459 1540
 				if ($this->char==='=') {
1460 1541
 					$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1461 1542
 					$this->parse_attr($node, $name, $space);
1462
-				}
1463
-				else {
1543
+				} else {
1464 1544
 					//no value attr: nowrap, checked selected...
1465 1545
 					$node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO;
1466 1546
 					$node->attr[$name] = true;
1467
-					if ($this->char!='>') $this->char = $this->doc[--$this->pos]; // prev
1547
+					if ($this->char!='>') {
1548
+						$this->char = $this->doc[--$this->pos];
1549
+					}
1550
+					// prev
1468 1551
 				}
1469 1552
 				$node->_[HDOM_INFO_SPACE][] = $space;
1470 1553
 				$space = array($this->copy_skip($this->token_blank), '', '');
1554
+			} else {
1555
+							break;
1471 1556
 			}
1472
-			else
1473
-				break;
1474 1557
 		} while ($this->char!=='>' && $this->char!=='/');
1475 1558
 
1476 1559
 		$this->link_nodes($node, true);
@@ -1481,11 +1564,12 @@  discard block
 block discarded – undo
1481 1564
 		{
1482 1565
 			$node->_[HDOM_INFO_ENDSPACE] .= '/';
1483 1566
 			$node->_[HDOM_INFO_END] = 0;
1484
-		}
1485
-		else
1567
+		} else
1486 1568
 		{
1487 1569
 			// reset parent
1488
-			if (!isset($this->self_closing_tags[strtolower($node->tag)])) $this->parent = $node;
1570
+			if (!isset($this->self_closing_tags[strtolower($node->tag)])) {
1571
+				$this->parent = $node;
1572
+			}
1489 1573
 		}
1490 1574
 		$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1491 1575
 
@@ -1571,7 +1655,9 @@  discard block
 block discarded – undo
1571 1655
 		$len = strspn($this->doc, $chars, $pos);
1572 1656
 		$this->pos += $len;
1573 1657
 		$this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1574
-		if ($len===0) return '';
1658
+		if ($len===0) {
1659
+			return '';
1660
+		}
1575 1661
 		return substr($this->doc, $pos, $len);
1576 1662
 	}
1577 1663
 
@@ -1586,7 +1672,9 @@  discard block
 block discarded – undo
1586 1672
 
1587 1673
 	protected function copy_until_char($char)
1588 1674
 	{
1589
-		if ($this->char===null) return '';
1675
+		if ($this->char===null) {
1676
+			return '';
1677
+		}
1590 1678
 
1591 1679
 		if (($pos = strpos($this->doc, $char, $this->pos))===false) {
1592 1680
 			$ret = substr($this->doc, $this->pos, $this->size-$this->pos);
@@ -1595,7 +1683,9 @@  discard block
 block discarded – undo
1595 1683
 			return $ret;
1596 1684
 		}
1597 1685
 
1598
-		if ($pos===$this->pos) return '';
1686
+		if ($pos===$this->pos) {
1687
+			return '';
1688
+		}
1599 1689
 		$pos_old = $this->pos;
1600 1690
 		$this->char = $this->doc[$pos];
1601 1691
 		$this->pos = $pos;
@@ -1604,7 +1694,9 @@  discard block
 block discarded – undo
1604 1694
 
1605 1695
 	protected function copy_until_char_escape($char)
1606 1696
 	{
1607
-		if ($this->char===null) return '';
1697
+		if ($this->char===null) {
1698
+			return '';
1699
+		}
1608 1700
 
1609 1701
 		$start = $this->pos;
1610 1702
 		while (1)
@@ -1617,7 +1709,9 @@  discard block
 block discarded – undo
1617 1709
 				return $ret;
1618 1710
 			}
1619 1711
 
1620
-			if ($pos===$this->pos) return '';
1712
+			if ($pos===$this->pos) {
1713
+				return '';
1714
+			}
1621 1715
 
1622 1716
 			if ($this->doc[$pos-1]==='\\') {
1623 1717
 				$start = $pos+1;
@@ -1674,14 +1768,12 @@  discard block
 block discarded – undo
1674 1768
 				if (isset($this->noise[$key]))
1675 1769
 				{
1676 1770
 					$text = substr($text, 0, $pos).$this->noise[$key].substr($text, $pos+16);
1677
-				}
1678
-				else
1771
+				} else
1679 1772
 				{
1680 1773
 					// do this to prevent an infinite loop.
1681 1774
 					$text = substr($text, 0, $pos).'UNDEFINED NOISE FOR KEY: '.$key . substr($text, $pos+16);
1682 1775
 				}
1683
-			}
1684
-			else
1776
+			} else
1685 1777
 			{
1686 1778
 				// There is no valid key being given back to us... We must get rid of the ___noise___ or we will have a problem.
1687 1779
 				$text = substr($text, 0, $pos).'NO NUMERIC NOISE KEY' . substr($text, $pos+11);
Please login to merge, or discard this patch.
require/libs/uagent/uagent.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -183,8 +183,7 @@
 block discarded – undo
183 183
         if ( mt_rand( 0, 1 ) == 0 )
184 184
         {
185 185
             $ver = mt_rand( 4, 5 ) . '.' . mt_rand( 0, 1 );
186
-        }
187
-        else
186
+        } else
188 187
         {
189 188
             $ver = mt_rand( 4, 5 ) . '.0.' . mt_rand( 1, 5 );
190 189
         }
Please login to merge, or discard this patch.
require/libs/geoPHP/tests/tests/methodsTest.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -290,7 +290,9 @@
 block discarded – undo
290 290
 
291 291
   function _methods_tester_with_geos($geometry) {
292 292
     // Cannot test methods if GEOS is not intstalled
293
-    if (!geoPHP::geosInstalled()) return;
293
+    if (!geoPHP::geosInstalled()) {
294
+    	return;
295
+    }
294 296
 
295 297
     $methods = array(
296 298
       //'boundary', //@@TODO: Uncomment this and fix errors
Please login to merge, or discard this patch.
require/libs/geoPHP/tests/tests/adaptersTest.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,9 @@
 block discarded – undo
32 32
 
33 33
         // Test to make sure adapter work the same wether GEOS is ON or OFF
34 34
         // Cannot test methods if GEOS is not intstalled
35
-        if (!geoPHP::geosInstalled()) return;
35
+        if (!geoPHP::geosInstalled()) {
36
+        	return;
37
+        }
36 38
 
37 39
         foreach (geoPHP::getAdapterMap() as $adapter_key => $adapter_class) {
38 40
           if ($adapter_key != 'google_geocode') { //Don't test google geocoder regularily. Uncomment to test
Please login to merge, or discard this patch.
require/libs/geoPHP/tests/test.php 1 patch
Braces   +13 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
   if (geoPHP::geosInstalled()) {
14 14
     print "GEOS is installed.\n";
15
-  }
16
-  else {
15
+  } else {
17 16
     print "GEOS is not installed.\n";
18 17
   }
19 18
 
@@ -125,8 +124,7 @@  discard block
 block discarded – undo
125 124
         if ($test_geom_1->out('wkt') != $test_geom_2->out('wkt')) {
126 125
           print "Mismatched adapter output in ".$adapter_class."\n";
127 126
         }
128
-      }
129
-      else {
127
+      } else {
130 128
         print "Empty output on "  . $adapter_key . "\n";
131 129
       }
132 130
     }
@@ -134,7 +132,9 @@  discard block
 block discarded – undo
134 132
 
135 133
   // Test to make sure adapter work the same wether GEOS is ON or OFF
136 134
   // Cannot test methods if GEOS is not intstalled
137
-  if (!geoPHP::geosInstalled()) return;
135
+  if (!geoPHP::geosInstalled()) {
136
+  	return;
137
+  }
138 138
 
139 139
   foreach (geoPHP::getAdapterMap() as $adapter_key => $adapter_class) {
140 140
     if ($adapter_key != 'google_geocode') { //Don't test google geocoder regularily. Uncomment to test
@@ -167,7 +167,9 @@  discard block
 block discarded – undo
167 167
 
168 168
 function test_methods($geometry) {
169 169
   // Cannot test methods if GEOS is not intstalled
170
-  if (!geoPHP::geosInstalled()) return;
170
+  if (!geoPHP::geosInstalled()) {
171
+  	return;
172
+  }
171 173
 
172 174
   $methods = array(
173 175
     //'boundary', //@@TODO: Uncomment this and fix errors
@@ -237,8 +239,11 @@  discard block
 block discarded – undo
237 239
 function test_detection($value, $format, $file) {
238 240
   $detected = geoPHP::detectFormat($value);
239 241
   if ($detected != $format) {
240
-    if ($detected) print 'detected as ' . $detected . "\n";
241
-    else print "not detected\n";
242
+    if ($detected) {
243
+    	print 'detected as ' . $detected . "\n";
244
+    } else {
245
+    	print "not detected\n";
246
+    }
242 247
   }
243 248
   // Make sure it loads using auto-detect
244 249
   geoPHP::load($value);
Please login to merge, or discard this patch.
require/libs/geoPHP/lib/adapters/EWKT.class.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,7 @@
 block discarded – undo
19 19
       $wkt = 'SRID=' . $srid . ';';
20 20
       $wkt .= $geometry->out('wkt');
21 21
       return $wkt;
22
-    }
23
-    else {
22
+    } else {
24 23
       return $geometry->out('wkt');
25 24
     }
26 25
   }
Please login to merge, or discard this patch.
require/libs/geoPHP/lib/adapters/GeoRSS.class.php 1 patch
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -87,8 +87,7 @@  discard block
 block discarded – undo
87 87
       if (!($key % 2)) {
88 88
         // It's a latitude
89 89
         $lat = $item;
90
-      }
91
-      else {
90
+      } else {
92 91
         // It's a longitude
93 92
         $lon = $item;
94 93
         $coords[] = new Point($lon, $lat);
@@ -125,8 +124,7 @@  discard block
 block discarded – undo
125 124
         $points = $this->getPointsFromCoords(trim($poly->firstChild->nodeValue));
126 125
         $exterior_ring = new LineString($points);
127 126
         $polygons[] = new Polygon(array($exterior_ring));
128
-      }
129
-      else {
127
+      } else {
130 128
         // It's an EMPTY polygon
131 129
         $polygons[] = new Polygon(); 
132 130
       }
@@ -196,7 +194,9 @@  discard block
 block discarded – undo
196 194
     $output = '<'.$this->nss.'line>';
197 195
     foreach ($geom->getComponents() as $k => $point) {
198 196
       $output .= $point->getY().' '.$point->getX();
199
-      if ($k < ($geom->numGeometries() -1)) $output .= ' ';
197
+      if ($k < ($geom->numGeometries() -1)) {
198
+      	$output .= ' ';
199
+      }
200 200
     }
201 201
     $output .= '</'.$this->nss.'line>';
202 202
     return $output;
@@ -207,7 +207,9 @@  discard block
 block discarded – undo
207 207
     $exterior_ring = $geom->exteriorRing();
208 208
     foreach ($exterior_ring->getComponents() as $k => $point) {
209 209
       $output .= $point->getY().' '.$point->getX();
210
-      if ($k < ($exterior_ring->numGeometries() -1)) $output .= ' ';
210
+      if ($k < ($exterior_ring->numGeometries() -1)) {
211
+      	$output .= ' ';
212
+      }
211 213
     }
212 214
     $output .= '</'.$this->nss.'polygon>';
213 215
     return $output;
Please login to merge, or discard this patch.
require/libs/geoPHP/lib/adapters/WKT.class.php 1 patch
Braces   +52 added lines, -25 removed lines patch added patch discarded remove patch
@@ -21,8 +21,7 @@  discard block
 block discarded – undo
21 21
       $wkt = $parts[1];
22 22
       $eparts = explode('=',$parts[0]);
23 23
       $srid = $eparts[1];
24
-    }
25
-    else {
24
+    } else {
26 25
       $srid = NULL;
27 26
     }
28 27
     
@@ -33,8 +32,7 @@  discard block
 block discarded – undo
33 32
         $geom = geoPHP::geosToGeometry($reader->read($wkt));
34 33
         $geom->setSRID($srid);
35 34
         return $geom;
36
-      }
37
-      else { 
35
+      } else { 
38 36
         return geoPHP::geosToGeometry($reader->read($wkt));
39 37
       }
40 38
     }
@@ -52,8 +50,7 @@  discard block
 block discarded – undo
52 50
           $geom = $this->$method($data_string);
53 51
           $geom->setSRID($srid);
54 52
           return $geom;
55
-        }
56
-        else { 
53
+        } else { 
57 54
           return $this->$method($data_string);
58 55
         }
59 56
         
@@ -71,7 +68,9 @@  discard block
 block discarded – undo
71 68
     $data_string = $this->trimParens($data_string);
72 69
 
73 70
     // If it's marked as empty, then return an empty line
74
-    if ($data_string == 'EMPTY') return new LineString();
71
+    if ($data_string == 'EMPTY') {
72
+    	return new LineString();
73
+    }
75 74
     
76 75
     $parts = explode(',',$data_string);
77 76
     $points = array();
@@ -85,13 +84,19 @@  discard block
 block discarded – undo
85 84
     $data_string = $this->trimParens($data_string);
86 85
     
87 86
     // If it's marked as empty, then return an empty polygon
88
-    if ($data_string == 'EMPTY') return new Polygon();
87
+    if ($data_string == 'EMPTY') {
88
+    	return new Polygon();
89
+    }
89 90
     
90 91
     $parts = explode('),(',$data_string);
91 92
     $lines = array();
92 93
     foreach ($parts as $part) {
93
-      if (!$this->beginsWith($part,'(')) $part = '(' . $part;
94
-      if (!$this->endsWith($part,')'))   $part = $part . ')';
94
+      if (!$this->beginsWith($part,'(')) {
95
+      	$part = '(' . $part;
96
+      }
97
+      if (!$this->endsWith($part,')')) {
98
+      	$part = $part . ')';
99
+      }
95 100
       $lines[] = $this->parseLineString($part);
96 101
     }
97 102
     return new Polygon($lines);
@@ -101,7 +106,9 @@  discard block
 block discarded – undo
101 106
     $data_string = $this->trimParens($data_string);
102 107
     
103 108
     // If it's marked as empty, then return an empty MutiPoint
104
-    if ($data_string == 'EMPTY') return new MultiPoint();
109
+    if ($data_string == 'EMPTY') {
110
+    	return new MultiPoint();
111
+    }
105 112
     
106 113
     $parts = explode(',',$data_string);
107 114
     $points = array();
@@ -115,14 +122,20 @@  discard block
 block discarded – undo
115 122
     $data_string = $this->trimParens($data_string);
116 123
 
117 124
     // If it's marked as empty, then return an empty multi-linestring
118
-    if ($data_string == 'EMPTY') return new MultiLineString();
125
+    if ($data_string == 'EMPTY') {
126
+    	return new MultiLineString();
127
+    }
119 128
     
120 129
     $parts = explode('),(',$data_string);
121 130
     $lines = array();
122 131
     foreach ($parts as $part) {
123 132
       // Repair the string if the explode broke it
124
-      if (!$this->beginsWith($part,'(')) $part = '(' . $part;
125
-      if (!$this->endsWith($part,')'))   $part = $part . ')';
133
+      if (!$this->beginsWith($part,'(')) {
134
+      	$part = '(' . $part;
135
+      }
136
+      if (!$this->endsWith($part,')')) {
137
+      	$part = $part . ')';
138
+      }
126 139
       $lines[] = $this->parseLineString($part);
127 140
     }
128 141
     return new MultiLineString($lines);
@@ -132,14 +145,20 @@  discard block
 block discarded – undo
132 145
     $data_string = $this->trimParens($data_string);
133 146
 
134 147
     // If it's marked as empty, then return an empty multi-polygon
135
-    if ($data_string == 'EMPTY') return new MultiPolygon();
148
+    if ($data_string == 'EMPTY') {
149
+    	return new MultiPolygon();
150
+    }
136 151
     
137 152
     $parts = explode(')),((',$data_string);
138 153
     $polys = array();
139 154
     foreach ($parts as $part) {
140 155
       // Repair the string if the explode broke it
141
-      if (!$this->beginsWith($part,'((')) $part = '((' . $part;
142
-      if (!$this->endsWith($part,'))'))   $part = $part . '))';
156
+      if (!$this->beginsWith($part,'((')) {
157
+      	$part = '((' . $part;
158
+      }
159
+      if (!$this->endsWith($part,'))')) {
160
+      	$part = $part . '))';
161
+      }
143 162
       $polys[] = $this->parsePolygon($part);
144 163
     }
145 164
     return new MultiPolygon($polys);
@@ -149,7 +168,9 @@  discard block
 block discarded – undo
149 168
     $data_string = $this->trimParens($data_string);
150 169
 
151 170
     // If it's marked as empty, then return an empty geom-collection
152
-    if ($data_string == 'EMPTY') return new GeometryCollection();
171
+    if ($data_string == 'EMPTY') {
172
+    	return new GeometryCollection();
173
+    }
153 174
     
154 175
     $geometries = array();
155 176
     $matches = array();
@@ -180,18 +201,25 @@  discard block
 block discarded – undo
180 201
     // We want to only strip off one set of parenthesis
181 202
     if ($this->beginsWith($str, '(')) {
182 203
       return substr($str,1,-1);
204
+    } else {
205
+    	return $str;
183 206
     }
184
-    else return $str;
185 207
   }
186 208
   
187 209
   protected function beginsWith($str, $char) {
188
-    if (substr($str,0,strlen($char)) == $char) return TRUE;
189
-    else return FALSE;
210
+    if (substr($str,0,strlen($char)) == $char) {
211
+    	return TRUE;
212
+    } else {
213
+    	return FALSE;
214
+    }
190 215
   }
191 216
 
192 217
   protected function endsWith($str, $char) {
193
-    if (substr($str,(0 - strlen($char))) == $char) return TRUE;
194
-    else return FALSE;
218
+    if (substr($str,(0 - strlen($char))) == $char) {
219
+    	return TRUE;
220
+    } else {
221
+    	return FALSE;
222
+    }
195 223
   }
196 224
     
197 225
   /**
@@ -211,8 +239,7 @@  discard block
 block discarded – undo
211 239
     
212 240
     if ($geometry->isEmpty()) {
213 241
       return strtoupper($geometry->geometryType()).' EMPTY';
214
-    }
215
-    else if ($data = $this->extractData($geometry)) {
242
+    } else if ($data = $this->extractData($geometry)) {
216 243
       return strtoupper($geometry->geometryType()).' ('.$data.')';
217 244
     }
218 245
   }
Please login to merge, or discard this patch.
require/libs/geoPHP/lib/adapters/GoogleGeocode.class.php 1 patch
Braces   +16 added lines, -11 removed lines patch added patch discarded remove patch
@@ -30,15 +30,16 @@  discard block
 block discarded – undo
30 30
    * @return Geometry|GeometryCollection
31 31
    */
32 32
   public function read($address, $return_type = 'point', $bounds = FALSE, $return_multiple = FALSE) {
33
-    if (is_array($address)) $address = join(',', $address);
33
+    if (is_array($address)) {
34
+    	$address = join(',', $address);
35
+    }
34 36
     
35 37
     if (gettype($bounds) == 'object') {
36 38
       $bounds = $bounds->getBBox();
37 39
     }
38 40
     if (gettype($bounds) == 'array') {
39 41
       $bounds_string = '&bounds='.$bounds['miny'].','.$bounds['minx'].'|'.$bounds['maxy'].','.$bounds['maxx'];
40
-    }
41
-    else {
42
+    } else {
42 43
       $bounds_string = '';
43 44
     }
44 45
     
@@ -73,10 +74,12 @@  discard block
 block discarded – undo
73 74
           return new MultiPolygon($polygons);
74 75
         }
75 76
       }
76
-    }
77
-    else {
78
-      if ($this->result->status) throw new Exception('Error in Google Geocoder: '.$this->result->status);
79
-      else throw new Exception('Unknown error in Google Geocoder');
77
+    } else {
78
+      if ($this->result->status) {
79
+      	throw new Exception('Error in Google Geocoder: '.$this->result->status);
80
+      } else {
81
+      	throw new Exception('Unknown error in Google Geocoder');
82
+      }
80 83
       return FALSE;
81 84
     }
82 85
   }
@@ -106,10 +109,12 @@  discard block
 block discarded – undo
106 109
       if ($return_type == 'array') {
107 110
         return $this->result->results[0]->address_components;
108 111
       }
109
-    }
110
-    else {
111
-      if ($this->result->status) throw new Exception('Error in Google Reverse Geocoder: '.$this->result->status);
112
-      else throw new Exception('Unknown error in Google Reverse Geocoder');
112
+    } else {
113
+      if ($this->result->status) {
114
+      	throw new Exception('Error in Google Reverse Geocoder: '.$this->result->status);
115
+      } else {
116
+      	throw new Exception('Unknown error in Google Reverse Geocoder');
117
+      }
113 118
       return FALSE;
114 119
     }
115 120
   }
Please login to merge, or discard this patch.