Passed
Push — 1.10.x ( 5654d2...115d5a )
by Yannick
263:14 queued 212:07
created
main/inc/lib/tracking.lib.php 1 patch
Indentation   +862 added lines, -862 removed lines patch added patch discarded remove patch
@@ -311,8 +311,8 @@  discard block
 block discarded – undo
311 311
                     $extend_link = '';
312 312
                     if (!empty($inter_num)) {
313 313
                         $extend_link = Display::url(
314
-                              Display::return_icon('visible.gif', get_lang('HideAttemptView')),
315
-                              api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix
314
+                                Display::return_icon('visible.gif', get_lang('HideAttemptView')),
315
+                                api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix
316 316
                         );
317 317
                     }
318 318
                     $title = $row['mytitle'];
@@ -1319,7 +1319,7 @@  discard block
 block discarded – undo
1319 1319
             case 'last_30_days':
1320 1320
                 $new_date = date('Y-m-d H:i:s', strtotime('-30 day'));
1321 1321
                 $condition_time = ' AND (login_date >= "'.$new_date.'" AND logout_date <= "'.$today.'") ';
1322
-               break;
1322
+                break;
1323 1323
             case 'custom':
1324 1324
                 if (!empty($start_date) && !empty($end_date)) {
1325 1325
                     $start_date = Database::escape_string($start_date);
@@ -1329,10 +1329,10 @@  discard block
 block discarded – undo
1329 1329
                 break;
1330 1330
         }
1331 1331
 
1332
-    	$sql = 'SELECT SUM(TIMESTAMPDIFF(SECOND, login_date, logout_date)) diff
1332
+        $sql = 'SELECT SUM(TIMESTAMPDIFF(SECOND, login_date, logout_date)) diff
1333 1333
     	        FROM '.$tbl_track_login.'
1334 1334
                 WHERE '.$userCondition.$condition_time;
1335
-    	$rs = Database::query($sql);
1335
+        $rs = Database::query($sql);
1336 1336
         $row = Database::fetch_array($rs, 'ASSOC');
1337 1337
         $diff = $row['diff'];
1338 1338
 
@@ -1354,18 +1354,18 @@  discard block
 block discarded – undo
1354 1354
     public static function get_time_spent_on_the_course($user_id, $courseId, $session_id = 0)
1355 1355
     {
1356 1356
         $courseId = intval($courseId);
1357
-    	$session_id  = intval($session_id);
1358
-
1359
-    	$tbl_track_course = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
1360
-    	if (is_array($user_id)) {
1361
-    	    $user_id = array_map('intval', $user_id);
1362
-    		$condition_user = " AND user_id IN (".implode(',',$user_id).") ";
1363
-    	} else {
1364
-    		$user_id = intval($user_id);
1365
-    		$condition_user = " AND user_id = $user_id ";
1366
-    	}
1367
-
1368
-    	$sql = "SELECT
1357
+        $session_id  = intval($session_id);
1358
+
1359
+        $tbl_track_course = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
1360
+        if (is_array($user_id)) {
1361
+            $user_id = array_map('intval', $user_id);
1362
+            $condition_user = " AND user_id IN (".implode(',',$user_id).") ";
1363
+        } else {
1364
+            $user_id = intval($user_id);
1365
+            $condition_user = " AND user_id = $user_id ";
1366
+        }
1367
+
1368
+        $sql = "SELECT
1369 1369
     	        SUM(UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date)) as nb_seconds
1370 1370
                 FROM $tbl_track_course
1371 1371
                 WHERE UNIX_TIMESTAMP(logout_course_date) > UNIX_TIMESTAMP(login_course_date) ";
@@ -1381,9 +1381,9 @@  discard block
 block discarded – undo
1381 1381
         $sql .= $condition_user;
1382 1382
 
1383 1383
         $rs = Database::query($sql);
1384
-    	$row = Database::fetch_array($rs);
1384
+        $row = Database::fetch_array($rs);
1385 1385
 
1386
-    	return $row['nb_seconds'];
1386
+        return $row['nb_seconds'];
1387 1387
     }
1388 1388
 
1389 1389
     /**
@@ -1394,25 +1394,25 @@  discard block
 block discarded – undo
1394 1394
      */
1395 1395
     public static function get_first_connection_date($student_id)
1396 1396
     {
1397
-    	$tbl_track_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
1398
-    	$sql = 'SELECT login_date
1397
+        $tbl_track_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
1398
+        $sql = 'SELECT login_date
1399 1399
     	        FROM ' . $tbl_track_login . '
1400 1400
                 WHERE login_user_id = ' . intval($student_id) . '
1401 1401
                 ORDER BY login_date ASC
1402 1402
                 LIMIT 0,1';
1403 1403
 
1404
-    	$rs = Database::query($sql);
1405
-    	if (Database::num_rows($rs)>0) {
1406
-    		if ($first_login_date = Database::result($rs, 0, 0)) {
1404
+        $rs = Database::query($sql);
1405
+        if (Database::num_rows($rs)>0) {
1406
+            if ($first_login_date = Database::result($rs, 0, 0)) {
1407 1407
                 return api_convert_and_format_date(
1408 1408
                     $first_login_date,
1409 1409
                     DATE_FORMAT_SHORT,
1410 1410
                     date_default_timezone_get()
1411 1411
                 );
1412
-    		}
1413
-    	}
1412
+            }
1413
+        }
1414 1414
 
1415
-    	return false;
1415
+        return false;
1416 1416
     }
1417 1417
 
1418 1418
     /**
@@ -1425,38 +1425,38 @@  discard block
 block discarded – undo
1425 1425
      */
1426 1426
     public static function get_last_connection_date($student_id, $warning_message = false, $return_timestamp = false)
1427 1427
     {
1428
-    	$table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
1429
-    	$sql = 'SELECT login_date
1428
+        $table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
1429
+        $sql = 'SELECT login_date
1430 1430
     	        FROM ' . $table . '
1431 1431
                 WHERE login_user_id = ' . intval($student_id) . '
1432 1432
                 ORDER BY login_date
1433 1433
                 DESC LIMIT 0,1';
1434 1434
 
1435
-    	$rs = Database::query($sql);
1436
-    	if (Database::num_rows($rs) > 0) {
1437
-    		if ($last_login_date = Database::result($rs, 0, 0)) {
1438
-    			$last_login_date = api_get_local_time($last_login_date);
1439
-    			if ($return_timestamp) {
1440
-    				return api_strtotime($last_login_date,'UTC');
1441
-    			} else {
1442
-    				if (!$warning_message) {
1443
-    					return api_format_date($last_login_date, DATE_FORMAT_SHORT);
1444
-    				} else {
1445
-    					$timestamp = api_strtotime($last_login_date,'UTC');
1446
-    					$currentTimestamp = time();
1447
-
1448
-    					//If the last connection is > than 7 days, the text is red
1449
-    					//345600 = 7 days in seconds
1450
-    					if ($currentTimestamp - $timestamp > 604800) {
1451
-    						return '<span style="color: #F00;">' . api_format_date($last_login_date, DATE_FORMAT_SHORT) . '</span>';
1452
-    					} else {
1453
-    						return api_format_date($last_login_date, DATE_FORMAT_SHORT);
1454
-    					}
1455
-    				}
1456
-    			}
1457
-    		}
1458
-    	}
1459
-    	return false;
1435
+        $rs = Database::query($sql);
1436
+        if (Database::num_rows($rs) > 0) {
1437
+            if ($last_login_date = Database::result($rs, 0, 0)) {
1438
+                $last_login_date = api_get_local_time($last_login_date);
1439
+                if ($return_timestamp) {
1440
+                    return api_strtotime($last_login_date,'UTC');
1441
+                } else {
1442
+                    if (!$warning_message) {
1443
+                        return api_format_date($last_login_date, DATE_FORMAT_SHORT);
1444
+                    } else {
1445
+                        $timestamp = api_strtotime($last_login_date,'UTC');
1446
+                        $currentTimestamp = time();
1447
+
1448
+                        //If the last connection is > than 7 days, the text is red
1449
+                        //345600 = 7 days in seconds
1450
+                        if ($currentTimestamp - $timestamp > 604800) {
1451
+                            return '<span style="color: #F00;">' . api_format_date($last_login_date, DATE_FORMAT_SHORT) . '</span>';
1452
+                        } else {
1453
+                            return api_format_date($last_login_date, DATE_FORMAT_SHORT);
1454
+                        }
1455
+                    }
1456
+                }
1457
+            }
1458
+        }
1459
+        return false;
1460 1460
     }
1461 1461
 
1462 1462
     /**
@@ -1510,30 +1510,30 @@  discard block
 block discarded – undo
1510 1510
         $session_id = 0,
1511 1511
         $convert_date = true
1512 1512
     ) {
1513
-    	$student_id  = intval($student_id);
1513
+        $student_id  = intval($student_id);
1514 1514
         $courseId = intval($courseId);
1515
-    	$session_id  = intval($session_id);
1515
+        $session_id  = intval($session_id);
1516 1516
 
1517
-    	$tbl_track_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
1518
-    	$sql = 'SELECT login_course_date
1517
+        $tbl_track_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
1518
+        $sql = 'SELECT login_course_date
1519 1519
     	        FROM '.$tbl_track_login.'
1520 1520
                 WHERE
1521 1521
                     user_id = '.$student_id.' AND
1522 1522
                     c_id = '.$courseId.' AND
1523 1523
                     session_id = '.$session_id.'
1524 1524
                 ORDER BY login_course_date ASC LIMIT 0,1';
1525
-    	$rs = Database::query($sql);
1526
-    	if (Database::num_rows($rs) > 0) {
1527
-    		if ($first_login_date = Database::result($rs, 0, 0)) {
1528
-    			if ($convert_date) {
1529
-    				return api_convert_and_format_date($first_login_date, DATE_FORMAT_SHORT);
1530
-    			} else {
1531
-    				return $first_login_date;
1532
-    			}
1533
-    		}
1534
-    	}
1535
-
1536
-    	return false;
1525
+        $rs = Database::query($sql);
1526
+        if (Database::num_rows($rs) > 0) {
1527
+            if ($first_login_date = Database::result($rs, 0, 0)) {
1528
+                if ($convert_date) {
1529
+                    return api_convert_and_format_date($first_login_date, DATE_FORMAT_SHORT);
1530
+                } else {
1531
+                    return $first_login_date;
1532
+                }
1533
+            }
1534
+        }
1535
+
1536
+        return false;
1537 1537
     }
1538 1538
 
1539 1539
     /**
@@ -1549,13 +1549,13 @@  discard block
 block discarded – undo
1549 1549
         $session_id = 0,
1550 1550
         $convert_date = true
1551 1551
     ) {
1552
-    	// protect data
1553
-    	$student_id  = intval($student_id);
1552
+        // protect data
1553
+        $student_id  = intval($student_id);
1554 1554
         $courseId = $courseInfo['real_id'];
1555
-    	$session_id  = intval($session_id);
1555
+        $session_id  = intval($session_id);
1556 1556
 
1557
-    	$tbl_track_e_access = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
1558
-    	$sql = 'SELECT access_date
1557
+        $tbl_track_e_access = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
1558
+        $sql = 'SELECT access_date
1559 1559
                 FROM '.$tbl_track_e_access.'
1560 1560
                 WHERE   access_user_id = '.$student_id.' AND
1561 1561
                         c_id = "'.$courseId.'" AND
@@ -1563,38 +1563,38 @@  discard block
 block discarded – undo
1563 1563
                 ORDER BY access_date DESC
1564 1564
                 LIMIT 0,1';
1565 1565
 
1566
-    	$rs = Database::query($sql);
1567
-    	if (Database::num_rows($rs) > 0) {
1568
-    		if ($last_login_date = Database::result($rs, 0, 0)) {
1566
+        $rs = Database::query($sql);
1567
+        if (Database::num_rows($rs) > 0) {
1568
+            if ($last_login_date = Database::result($rs, 0, 0)) {
1569 1569
                 if (empty($last_login_date) || $last_login_date == '0000-00-00 00:00:00') {
1570 1570
                     return false;
1571 1571
                 }
1572 1572
                 //see #5736
1573 1573
                 $last_login_date_timestamp = api_strtotime($last_login_date);
1574
-    			$now = time();
1575
-    			//If the last connection is > than 7 days, the text is red
1576
-    			//345600 = 7 days in seconds
1577
-    			if ($now - $last_login_date_timestamp > 604800) {
1578
-    				if ($convert_date) {
1574
+                $now = time();
1575
+                //If the last connection is > than 7 days, the text is red
1576
+                //345600 = 7 days in seconds
1577
+                if ($now - $last_login_date_timestamp > 604800) {
1578
+                    if ($convert_date) {
1579 1579
                         $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
1580 1580
                         $icon = api_is_allowed_to_edit() ?
1581 1581
                             '<a href="'.api_get_path(REL_CODE_PATH).'announcements/announcements.php?action=add&remind_inactive='.$student_id.'&cidReq='.$courseInfo['code'].'" title="'.get_lang('RemindInactiveUser').'">
1582 1582
                              <img src="'.api_get_path(WEB_IMG_PATH).'messagebox_warning.gif" /> </a>'
1583 1583
                             : null;
1584
-    					return $icon. Display::label($last_login_date, 'warning');
1585
-    				} else {
1586
-    					return $last_login_date;
1587
-    				}
1588
-    			} else {
1589
-    				if ($convert_date) {
1590
-    					return api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
1591
-    				} else {
1592
-    					return $last_login_date;
1593
-    				}
1594
-    			}
1595
-    		}
1596
-    	}
1597
-    	return false;
1584
+                        return $icon. Display::label($last_login_date, 'warning');
1585
+                    } else {
1586
+                        return $last_login_date;
1587
+                    }
1588
+                } else {
1589
+                    if ($convert_date) {
1590
+                        return api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
1591
+                    } else {
1592
+                        return $last_login_date;
1593
+                    }
1594
+                }
1595
+            }
1596
+        }
1597
+        return false;
1598 1598
     }
1599 1599
 
1600 1600
     /**
@@ -1607,36 +1607,36 @@  discard block
 block discarded – undo
1607 1607
      */
1608 1608
     public static function get_course_connections_count($courseId, $session_id = 0, $start = 0, $stop = null)
1609 1609
     {
1610
-    	if ($start < 0) {
1611
-    		$start = 0;
1612
-    	}
1613
-    	if (!isset($stop) or ($stop < 0)) {
1614
-    		$stop = api_get_utc_datetime();
1615
-    	}
1610
+        if ($start < 0) {
1611
+            $start = 0;
1612
+        }
1613
+        if (!isset($stop) or ($stop < 0)) {
1614
+            $stop = api_get_utc_datetime();
1615
+        }
1616 1616
 
1617 1617
         $start = Database::escape_string($start);
1618 1618
         $stop = Database::escape_string($stop);
1619 1619
 
1620
-    	$month_filter = " AND login_course_date > '$start' AND login_course_date < '$stop' ";
1620
+        $month_filter = " AND login_course_date > '$start' AND login_course_date < '$stop' ";
1621 1621
 
1622 1622
         $courseId = intval($courseId);
1623
-    	$session_id  = intval($session_id);
1624
-    	$count = 0;
1623
+        $session_id  = intval($session_id);
1624
+        $count = 0;
1625 1625
 
1626
-    	$tbl_track_e_course_access = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
1627
-    	$sql = "SELECT count(*) as count_connections
1626
+        $tbl_track_e_course_access = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
1627
+        $sql = "SELECT count(*) as count_connections
1628 1628
                 FROM $tbl_track_e_course_access
1629 1629
                 WHERE
1630 1630
                     c_id = $courseId AND
1631 1631
                     session_id = $session_id
1632 1632
                     $month_filter";
1633
-    	$rs = Database::query($sql);
1634
-    	if (Database::num_rows($rs)>0) {
1635
-    		$row = Database::fetch_object($rs);
1636
-    		$count = $row->count_connections;
1637
-    	}
1633
+        $rs = Database::query($sql);
1634
+        if (Database::num_rows($rs)>0) {
1635
+            $row = Database::fetch_object($rs);
1636
+            $count = $row->count_connections;
1637
+        }
1638 1638
 
1639
-    	return $count;
1639
+        return $count;
1640 1640
     }
1641 1641
 
1642 1642
     /**
@@ -1647,25 +1647,25 @@  discard block
 block discarded – undo
1647 1647
      */
1648 1648
     public static function count_course_per_student($user_id, $include_sessions = true)
1649 1649
     {
1650
-    	$user_id = intval($user_id);
1651
-    	$tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
1652
-    	$tbl_session_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
1650
+        $user_id = intval($user_id);
1651
+        $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
1652
+        $tbl_session_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
1653 1653
 
1654
-    	$sql = 'SELECT DISTINCT c_id
1654
+        $sql = 'SELECT DISTINCT c_id
1655 1655
                 FROM ' . $tbl_course_rel_user . '
1656 1656
                 WHERE user_id = ' . $user_id.' AND relation_type<>'.COURSE_RELATION_TYPE_RRHH;
1657
-    	$rs = Database::query($sql);
1658
-    	$nb_courses = Database::num_rows($rs);
1657
+        $rs = Database::query($sql);
1658
+        $nb_courses = Database::num_rows($rs);
1659 1659
 
1660
-    	if ($include_sessions) {
1661
-    		$sql = 'SELECT DISTINCT c_id
1660
+        if ($include_sessions) {
1661
+            $sql = 'SELECT DISTINCT c_id
1662 1662
                     FROM ' . $tbl_session_course_rel_user . '
1663 1663
                     WHERE user_id = ' . $user_id;
1664
-    		$rs = Database::query($sql);
1665
-    		$nb_courses += Database::num_rows($rs);
1666
-    	}
1664
+            $rs = Database::query($sql);
1665
+            $nb_courses += Database::num_rows($rs);
1666
+        }
1667 1667
 
1668
-    	return $nb_courses;
1668
+        return $nb_courses;
1669 1669
     }
1670 1670
 
1671 1671
     /**
@@ -1696,25 +1696,25 @@  discard block
 block discarded – undo
1696 1696
         $into_lp = 0
1697 1697
     ) {
1698 1698
         $course_code = Database::escape_string($course_code);
1699
-    	$course_info = api_get_course_info($course_code);
1700
-    	if (!empty($course_info)) {
1701
-    		// table definition
1702
-    		$tbl_course_quiz     = Database::get_course_table(TABLE_QUIZ_TEST);
1703
-    		$tbl_stats_exercise  = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
1704
-
1705
-    		// Compose a filter based on optional exercise given
1706
-    		$condition_quiz = "";
1707
-    		if (!empty($exercise_id)) {
1708
-    			$exercise_id = intval($exercise_id);
1709
-    			$condition_quiz =" AND id = $exercise_id ";
1710
-    		}
1711
-
1712
-    		// Compose a filter based on optional session id given
1713
-    		$condition_session = "";
1714
-    		if (isset($session_id)) {
1715
-    			$session_id = intval($session_id);
1716
-    			$condition_session = " AND session_id = $session_id ";
1717
-    		}
1699
+        $course_info = api_get_course_info($course_code);
1700
+        if (!empty($course_info)) {
1701
+            // table definition
1702
+            $tbl_course_quiz     = Database::get_course_table(TABLE_QUIZ_TEST);
1703
+            $tbl_stats_exercise  = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
1704
+
1705
+            // Compose a filter based on optional exercise given
1706
+            $condition_quiz = "";
1707
+            if (!empty($exercise_id)) {
1708
+                $exercise_id = intval($exercise_id);
1709
+                $condition_quiz =" AND id = $exercise_id ";
1710
+            }
1711
+
1712
+            // Compose a filter based on optional session id given
1713
+            $condition_session = "";
1714
+            if (isset($session_id)) {
1715
+                $session_id = intval($session_id);
1716
+                $condition_session = " AND session_id = $session_id ";
1717
+            }
1718 1718
             if ($active_filter == 1) {
1719 1719
                 $condition_active = 'AND active <> -1';
1720 1720
             } elseif ($active_filter == 0) {
@@ -1730,25 +1730,25 @@  discard block
 block discarded – undo
1730 1730
                 $select_lp_id = ', orig_lp_id as lp_id ';
1731 1731
             }
1732 1732
 
1733
-    		$sql = "SELECT count(id) FROM $tbl_course_quiz
1733
+            $sql = "SELECT count(id) FROM $tbl_course_quiz
1734 1734
     				WHERE c_id = {$course_info['real_id']} $condition_active $condition_quiz ";
1735
-    		$count_quiz = Database::fetch_row(Database::query($sql));
1735
+            $count_quiz = Database::fetch_row(Database::query($sql));
1736 1736
 
1737
-    		if (!empty($count_quiz[0]) && !empty($student_id)) {
1738
-    			if (is_array($student_id)) {
1737
+            if (!empty($count_quiz[0]) && !empty($student_id)) {
1738
+                if (is_array($student_id)) {
1739 1739
                     $student_id = array_map('intval', $student_id);
1740
-    				$condition_user = " AND exe_user_id IN (".implode(',', $student_id).") ";
1741
-    			} else {
1740
+                    $condition_user = " AND exe_user_id IN (".implode(',', $student_id).") ";
1741
+                } else {
1742 1742
                     $student_id = intval($student_id);
1743
-    				$condition_user = " AND exe_user_id = '$student_id' ";
1744
-    			}
1743
+                    $condition_user = " AND exe_user_id = '$student_id' ";
1744
+                }
1745 1745
 
1746
-    			if (empty($exercise_id)) {
1747
-    				$sql = "SELECT id FROM $tbl_course_quiz
1746
+                if (empty($exercise_id)) {
1747
+                    $sql = "SELECT id FROM $tbl_course_quiz
1748 1748
     						WHERE c_id = {$course_info['real_id']} $condition_active $condition_quiz";
1749 1749
                     $result = Database::query($sql);
1750 1750
                     $exercise_list = array();
1751
-    				$exercise_id = null;
1751
+                    $exercise_id = null;
1752 1752
                     if (Database::num_rows($result)) {
1753 1753
                         while ($row = Database::fetch_array($result)) {
1754 1754
                             $exercise_list[] = $row['id'];
@@ -1757,11 +1757,11 @@  discard block
 block discarded – undo
1757 1757
                     if (!empty($exercise_list)) {
1758 1758
                         $exercise_id = implode("','",$exercise_list);
1759 1759
                     }
1760
-    			}
1760
+                }
1761 1761
 
1762
-    			$count_quiz = Database::fetch_row(Database::query($sql));
1762
+                $count_quiz = Database::fetch_row(Database::query($sql));
1763 1763
 
1764
-    			$sql = "SELECT
1764
+                $sql = "SELECT
1765 1765
     			        SUM(exe_result/exe_weighting*100) as avg_score,
1766 1766
     			        COUNT(*) as num_attempts
1767 1767
     			        $select_lp_id
@@ -1775,20 +1775,20 @@  discard block
 block discarded – undo
1775 1775
                             $condition_into_lp
1776 1776
                         ORDER BY exe_date DESC";
1777 1777
 
1778
-    			$res = Database::query($sql);
1779
-    			$row = Database::fetch_array($res);
1780
-    			$quiz_avg_score = null;
1778
+                $res = Database::query($sql);
1779
+                $row = Database::fetch_array($res);
1780
+                $quiz_avg_score = null;
1781 1781
 
1782
-    			if (!empty($row['avg_score'])) {
1783
-    				$quiz_avg_score = round($row['avg_score'],2);
1784
-    			}
1782
+                if (!empty($row['avg_score'])) {
1783
+                    $quiz_avg_score = round($row['avg_score'],2);
1784
+                }
1785 1785
 
1786
-    			if(!empty($row['num_attempts'])) {
1787
-    				$quiz_avg_score = round($quiz_avg_score / $row['num_attempts'], 2);
1788
-    			}
1789
-    			if (is_array($student_id)) {
1790
-    				$quiz_avg_score = round($quiz_avg_score / count($student_id), 2);
1791
-    			}
1786
+                if(!empty($row['num_attempts'])) {
1787
+                    $quiz_avg_score = round($quiz_avg_score / $row['num_attempts'], 2);
1788
+                }
1789
+                if (is_array($student_id)) {
1790
+                    $quiz_avg_score = round($quiz_avg_score / count($student_id), 2);
1791
+                }
1792 1792
                 if ($into_lp == 0) {
1793 1793
                     return $quiz_avg_score;
1794 1794
                 } else {
@@ -1811,9 +1811,9 @@  discard block
 block discarded – undo
1811 1811
                         return array($quiz_avg_score, null);
1812 1812
                     }
1813 1813
                 }
1814
-    		}
1815
-    	}
1816
-    	return null;
1814
+            }
1815
+        }
1816
+        return null;
1817 1817
     }
1818 1818
 
1819 1819
     /**
@@ -1846,15 +1846,15 @@  discard block
 block discarded – undo
1846 1846
         $find_all_lp = 0
1847 1847
     ) {
1848 1848
         $courseId = intval($courseId);
1849
-    	$student_id  = intval($student_id);
1850
-    	$exercise_id = intval($exercise_id);
1851
-    	$session_id  = intval($session_id);
1849
+        $student_id  = intval($student_id);
1850
+        $exercise_id = intval($exercise_id);
1851
+        $session_id  = intval($session_id);
1852 1852
 
1853
-    	$lp_id = intval($lp_id);
1853
+        $lp_id = intval($lp_id);
1854 1854
         $lp_item_id = intval($lp_item_id);
1855
-    	$tbl_stats_exercises = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
1855
+        $tbl_stats_exercises = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
1856 1856
 
1857
-    	$sql = "SELECT COUNT(ex.exe_id) as essais FROM $tbl_stats_exercises AS ex
1857
+        $sql = "SELECT COUNT(ex.exe_id) as essais FROM $tbl_stats_exercises AS ex
1858 1858
                 WHERE  ex.c_id = $courseId
1859 1859
                 AND ex.exe_exo_id = $exercise_id
1860 1860
                 AND status = ''
@@ -1869,11 +1869,11 @@  discard block
 block discarded – undo
1869 1869
                 AND orig_lp_item_id = $lp_item_id";
1870 1870
         }
1871 1871
 
1872
-    	$rs = Database::query($sql);
1873
-    	$row = Database::fetch_row($rs);
1874
-    	$count_attempts = $row[0];
1872
+        $rs = Database::query($sql);
1873
+        $row = Database::fetch_row($rs);
1874
+        $count_attempts = $row[0];
1875 1875
 
1876
-    	return $count_attempts;
1876
+        return $count_attempts;
1877 1877
     }
1878 1878
 
1879 1879
     /**
@@ -1883,7 +1883,7 @@  discard block
 block discarded – undo
1883 1883
      * @param int    $user_id
1884 1884
      * @param int    $courseId
1885 1885
      * @param int    $session_id
1886
-    */
1886
+     */
1887 1887
     public static function get_exercise_student_progress($exercise_list, $user_id, $courseId, $session_id)
1888 1888
     {
1889 1889
         $courseId = intval($courseId);
@@ -3499,8 +3499,8 @@  discard block
 block discarded – undo
3499 3499
 
3500 3500
         $condition_session = '';
3501 3501
         if (isset($session_id)) {
3502
-             $session_id = intval($session_id);
3503
-             $condition_session = ' AND f.session_id = '. $session_id;
3502
+                $session_id = intval($session_id);
3503
+                $condition_session = ' AND f.session_id = '. $session_id;
3504 3504
         }
3505 3505
 
3506 3506
         $groupId = intval($groupId);
@@ -5399,9 +5399,9 @@  discard block
 block discarded – undo
5399 5399
     }
5400 5400
 
5401 5401
     /**
5402
-    * @param FormValidator $form
5403
-    * @return mixed
5404
-    */
5402
+     * @param FormValidator $form
5403
+     * @return mixed
5404
+     */
5405 5405
     public static function setUserSearchForm($form)
5406 5406
     {
5407 5407
         global $_configuration;
@@ -5680,26 +5680,26 @@  discard block
 block discarded – undo
5680 5680
         $session_id = api_get_session_id();
5681 5681
         $course_id = api_get_course_int_id();
5682 5682
 
5683
-    	$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
5684
-    	$table_user = Database :: get_main_table(TABLE_MAIN_USER);
5683
+        $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
5684
+        $table_user = Database :: get_main_table(TABLE_MAIN_USER);
5685 5685
 
5686
-    	$sql = "SELECT count(tool) AS total_number_of_items
5686
+        $sql = "SELECT count(tool) AS total_number_of_items
5687 5687
     	        FROM $table_item_property track_resource, $table_user user
5688 5688
     	        WHERE
5689 5689
                     track_resource.c_id = $course_id AND
5690 5690
                     track_resource.insert_user_id = user.user_id AND
5691 5691
                     session_id " .(empty($session_id) ? ' IS NULL ' : " = $session_id ");
5692 5692
 
5693
-    	if (isset($_GET['keyword'])) {
5694
-    		$keyword = Database::escape_string(trim($_GET['keyword']));
5695
-    		$sql .= " AND (
5693
+        if (isset($_GET['keyword'])) {
5694
+            $keyword = Database::escape_string(trim($_GET['keyword']));
5695
+            $sql .= " AND (
5696 5696
     		            user.username LIKE '%".$keyword."%' OR
5697 5697
     		            lastedit_type LIKE '%".$keyword."%' OR
5698 5698
     		            tool LIKE '%".$keyword."%'
5699 5699
                     )";
5700
-    	}
5700
+        }
5701 5701
 
5702
-    	$sql .= " AND tool IN (
5702
+        $sql .= " AND tool IN (
5703 5703
     	            'document',
5704 5704
     	            'learnpath',
5705 5705
     	            'quiz',
@@ -5711,10 +5711,10 @@  discard block
 block discarded – undo
5711 5711
     	            'thematic_advance',
5712 5712
     	            'thematic_plan'
5713 5713
                 )";
5714
-    	$res = Database::query($sql);
5715
-    	$obj = Database::fetch_object($res);
5714
+        $res = Database::query($sql);
5715
+        $obj = Database::fetch_object($res);
5716 5716
 
5717
-    	return $obj->total_number_of_items;
5717
+        return $obj->total_number_of_items;
5718 5718
     }
5719 5719
 
5720 5720
     /**
@@ -5729,12 +5729,12 @@  discard block
 block discarded – undo
5729 5729
         $session_id = api_get_session_id();
5730 5730
         $course_id = api_get_course_int_id();
5731 5731
 
5732
-    	$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
5733
-    	$table_user = Database :: get_main_table(TABLE_MAIN_USER);
5734
-    	$table_session = Database :: get_main_table(TABLE_MAIN_SESSION);
5735
-    	$session_id = intval($session_id);
5732
+        $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
5733
+        $table_user = Database :: get_main_table(TABLE_MAIN_USER);
5734
+        $table_session = Database :: get_main_table(TABLE_MAIN_SESSION);
5735
+        $session_id = intval($session_id);
5736 5736
 
5737
-    	$sql = "SELECT
5737
+        $sql = "SELECT
5738 5738
                     tool as col0,
5739 5739
                     lastedit_type as col1,
5740 5740
                     ref as ref,
@@ -5748,16 +5748,16 @@  discard block
 block discarded – undo
5748 5748
                   track_resource.insert_user_id = user.user_id AND
5749 5749
                   session_id " .(empty($session_id) ? ' IS NULL ' : " = $session_id ");
5750 5750
 
5751
-    	if (isset($_GET['keyword'])) {
5752
-    		$keyword = Database::escape_string(trim($_GET['keyword']));
5753
-    		$sql .= " AND (
5751
+        if (isset($_GET['keyword'])) {
5752
+            $keyword = Database::escape_string(trim($_GET['keyword']));
5753
+            $sql .= " AND (
5754 5754
     		            user.username LIKE '%".$keyword."%' OR
5755 5755
     		            lastedit_type LIKE '%".$keyword."%' OR
5756 5756
     		            tool LIKE '%".$keyword."%'
5757 5757
                      ) ";
5758
-    	}
5758
+        }
5759 5759
 
5760
-    	$sql .= " AND tool IN (
5760
+        $sql .= " AND tool IN (
5761 5761
     	            'document',
5762 5762
     	            'learnpath',
5763 5763
     	            'quiz',
@@ -5770,41 +5770,41 @@  discard block
 block discarded – undo
5770 5770
     	            'thematic_plan'
5771 5771
                 )";
5772 5772
 
5773
-    	if ($column == 0) {
5774
-    		$column = '0';
5775
-    	}
5776
-    	if ($column != '' && $direction != '') {
5777
-    		if ($column != 2 && $column != 4) {
5778
-    			$sql .= " ORDER BY col$column $direction";
5779
-    		}
5780
-    	} else {
5781
-    		$sql .= " ORDER BY col5 DESC ";
5782
-    	}
5773
+        if ($column == 0) {
5774
+            $column = '0';
5775
+        }
5776
+        if ($column != '' && $direction != '') {
5777
+            if ($column != 2 && $column != 4) {
5778
+                $sql .= " ORDER BY col$column $direction";
5779
+            }
5780
+        } else {
5781
+            $sql .= " ORDER BY col5 DESC ";
5782
+        }
5783 5783
 
5784 5784
         $from = intval($from);
5785 5785
         $number_of_items = intval($number_of_items);
5786 5786
 
5787
-    	$sql .= " LIMIT $from, $number_of_items ";
5788
-
5789
-    	$res = Database::query($sql);
5790
-    	$resources = array();
5791
-    	$thematic_tools = array('thematic', 'thematic_advance', 'thematic_plan');
5792
-    	while ($row = Database::fetch_array($res)) {
5793
-    		$ref = $row['ref'];
5794
-    		$table_name = TrackingCourseLog::get_tool_name_table($row['col0']);
5795
-    		$table_tool = Database :: get_course_table($table_name['table_name']);
5796
-
5797
-    		$id = $table_name['id_tool'];
5798
-    		$recorset = false;
5787
+        $sql .= " LIMIT $from, $number_of_items ";
5799 5788
 
5800
-    		if (in_array($row['col0'], array('thematic_plan', 'thematic_advance'))) {
5801
-    			$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
5802
-    			$sql = "SELECT thematic_id FROM $table_tool
5789
+        $res = Database::query($sql);
5790
+        $resources = array();
5791
+        $thematic_tools = array('thematic', 'thematic_advance', 'thematic_plan');
5792
+        while ($row = Database::fetch_array($res)) {
5793
+            $ref = $row['ref'];
5794
+            $table_name = TrackingCourseLog::get_tool_name_table($row['col0']);
5795
+            $table_tool = Database :: get_course_table($table_name['table_name']);
5796
+
5797
+            $id = $table_name['id_tool'];
5798
+            $recorset = false;
5799
+
5800
+            if (in_array($row['col0'], array('thematic_plan', 'thematic_advance'))) {
5801
+                $tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
5802
+                $sql = "SELECT thematic_id FROM $table_tool
5803 5803
     			        WHERE c_id = $course_id AND id = $ref";
5804
-    			$rs_thematic  = Database::query($sql);
5805
-    			if (Database::num_rows($rs_thematic)) {
5806
-    				$row_thematic = Database::fetch_array($rs_thematic);
5807
-    				$thematic_id = $row_thematic['thematic_id'];
5804
+                $rs_thematic  = Database::query($sql);
5805
+                if (Database::num_rows($rs_thematic)) {
5806
+                    $row_thematic = Database::fetch_array($rs_thematic);
5807
+                    $thematic_id = $row_thematic['thematic_id'];
5808 5808
 
5809 5809
                     $sql = "SELECT session.id, session.name, user.username
5810 5810
                             FROM $tbl_thematic t, $table_session session, $table_user user
@@ -5813,9 +5813,9 @@  discard block
 block discarded – undo
5813 5813
                               t.session_id = session.id AND
5814 5814
                               session.id_coach = user.user_id AND
5815 5815
                               t.id = $thematic_id";
5816
-    				$recorset = Database::query($sql);
5817
-    			}
5818
-    		} else {
5816
+                    $recorset = Database::query($sql);
5817
+                }
5818
+            } else {
5819 5819
                 $sql = "SELECT session.id, session.name, user.username
5820 5820
                           FROM $table_tool tool, $table_session session, $table_user user
5821 5821
     			          WHERE
@@ -5823,127 +5823,127 @@  discard block
 block discarded – undo
5823 5823
     			              tool.session_id = session.id AND
5824 5824
     			              session.id_coach = user.user_id AND
5825 5825
     			              tool.$id = $ref";
5826
-    			$recorset = Database::query($sql);
5827
-    		}
5828
-
5829
-    		if (!empty($recorset)) {
5830
-    			$obj = Database::fetch_object($recorset);
5831
-
5832
-    			$name_session = '';
5833
-    			$coach_name = '';
5834
-    			if (!empty($obj)) {
5835
-    				$name_session = $obj->name;
5836
-    				$coach_name   = $obj->username;
5837
-    			}
5838
-
5839
-    			$url_tool = api_get_path(WEB_CODE_PATH).$table_name['link_tool'];
5840
-    			$row[0] = '';
5841
-    			if ($row['col6'] != 2) {
5842
-    				if (in_array($row['col0'], $thematic_tools)) {
5843
-
5844
-    					$exp_thematic_tool = explode('_', $row['col0']);
5845
-    					$thematic_tool_title = '';
5846
-    					if (is_array($exp_thematic_tool)) {
5847
-    						foreach ($exp_thematic_tool as $exp) {
5848
-    							$thematic_tool_title .= api_ucfirst($exp);
5849
-    						}
5850
-    					} else {
5851
-    						$thematic_tool_title = api_ucfirst($row['col0']);
5852
-    					}
5853
-
5854
-    					$row[0] = '<a href="'.$url_tool.'?'.api_get_cidreq().'&action=thematic_details">'.get_lang($thematic_tool_title).'</a>';
5855
-    				} else {
5856
-    					$row[0] = '<a href="'.$url_tool.'?'.api_get_cidreq().'">'.get_lang('Tool'.api_ucfirst($row['col0'])).'</a>';
5857
-    				}
5858
-    			} else {
5859
-    				$row[0] = api_ucfirst($row['col0']);
5860
-    			}
5861
-    			$row[1] = get_lang($row[1]);
5862
-    			$row[6] = api_convert_and_format_date($row['col5'], null, date_default_timezone_get());
5863
-    			$row[5] = '';
5864
-    			//@todo Improve this code please
5865
-    			switch ($table_name['table_name']) {
5866
-    				case 'document' :
5867
-    					$sql = "SELECT tool.title as title FROM $table_tool tool
5826
+                $recorset = Database::query($sql);
5827
+            }
5828
+
5829
+            if (!empty($recorset)) {
5830
+                $obj = Database::fetch_object($recorset);
5831
+
5832
+                $name_session = '';
5833
+                $coach_name = '';
5834
+                if (!empty($obj)) {
5835
+                    $name_session = $obj->name;
5836
+                    $coach_name   = $obj->username;
5837
+                }
5838
+
5839
+                $url_tool = api_get_path(WEB_CODE_PATH).$table_name['link_tool'];
5840
+                $row[0] = '';
5841
+                if ($row['col6'] != 2) {
5842
+                    if (in_array($row['col0'], $thematic_tools)) {
5843
+
5844
+                        $exp_thematic_tool = explode('_', $row['col0']);
5845
+                        $thematic_tool_title = '';
5846
+                        if (is_array($exp_thematic_tool)) {
5847
+                            foreach ($exp_thematic_tool as $exp) {
5848
+                                $thematic_tool_title .= api_ucfirst($exp);
5849
+                            }
5850
+                        } else {
5851
+                            $thematic_tool_title = api_ucfirst($row['col0']);
5852
+                        }
5853
+
5854
+                        $row[0] = '<a href="'.$url_tool.'?'.api_get_cidreq().'&action=thematic_details">'.get_lang($thematic_tool_title).'</a>';
5855
+                    } else {
5856
+                        $row[0] = '<a href="'.$url_tool.'?'.api_get_cidreq().'">'.get_lang('Tool'.api_ucfirst($row['col0'])).'</a>';
5857
+                    }
5858
+                } else {
5859
+                    $row[0] = api_ucfirst($row['col0']);
5860
+                }
5861
+                $row[1] = get_lang($row[1]);
5862
+                $row[6] = api_convert_and_format_date($row['col5'], null, date_default_timezone_get());
5863
+                $row[5] = '';
5864
+                //@todo Improve this code please
5865
+                switch ($table_name['table_name']) {
5866
+                    case 'document' :
5867
+                        $sql = "SELECT tool.title as title FROM $table_tool tool
5868 5868
                                 WHERE c_id = $course_id AND id = $ref";
5869
-    					$rs_document = Database::query($sql);
5870
-    					$obj_document = Database::fetch_object($rs_document);
5871
-    					$row[5] = $obj_document->title;
5869
+                        $rs_document = Database::query($sql);
5870
+                        $obj_document = Database::fetch_object($rs_document);
5871
+                        $row[5] = $obj_document->title;
5872 5872
 
5873
-    					break;
5874
-    				case 'announcement':
5873
+                        break;
5874
+                    case 'announcement':
5875 5875
                         $sql = "SELECT title FROM $table_tool
5876 5876
                                 WHERE c_id = $course_id AND id = $ref";
5877
-    					$rs_document = Database::query($sql);
5878
-    					$obj_document = Database::fetch_object($rs_document);
5877
+                        $rs_document = Database::query($sql);
5878
+                        $obj_document = Database::fetch_object($rs_document);
5879 5879
                         if ($obj_document) {
5880 5880
                             $row[5] = $obj_document->title;
5881 5881
                         }
5882
-    					break;
5883
-    				case 'glossary':
5882
+                        break;
5883
+                    case 'glossary':
5884 5884
                         $sql = "SELECT name FROM $table_tool
5885 5885
     					        WHERE c_id = $course_id AND glossary_id = $ref";
5886
-    					$rs_document = Database::query($sql);
5887
-    					$obj_document = Database::fetch_object($rs_document);
5886
+                        $rs_document = Database::query($sql);
5887
+                        $obj_document = Database::fetch_object($rs_document);
5888 5888
                         if ($obj_document) {
5889 5889
                             $row[5] = $obj_document->name;
5890 5890
                         }
5891
-    					break;
5892
-    				case 'lp':
5891
+                        break;
5892
+                    case 'lp':
5893 5893
                         $sql = "SELECT name
5894 5894
                                 FROM $table_tool WHERE c_id = $course_id AND id = $ref";
5895
-    					$rs_document = Database::query($sql);
5896
-    					$obj_document = Database::fetch_object($rs_document);
5897
-    					$row[5] = $obj_document->name;
5898
-    					break;
5899
-    				case 'quiz':
5895
+                        $rs_document = Database::query($sql);
5896
+                        $obj_document = Database::fetch_object($rs_document);
5897
+                        $row[5] = $obj_document->name;
5898
+                        break;
5899
+                    case 'quiz':
5900 5900
                         $sql = "SELECT title FROM $table_tool
5901 5901
                                 WHERE c_id = $course_id AND id = $ref";
5902
-    					$rs_document = Database::query($sql);
5903
-    					$obj_document = Database::fetch_object($rs_document);
5902
+                        $rs_document = Database::query($sql);
5903
+                        $obj_document = Database::fetch_object($rs_document);
5904 5904
                         if ($obj_document) {
5905 5905
                             $row[5] = $obj_document->title;
5906 5906
                         }
5907
-    					break;
5908
-    				case 'course_description':
5907
+                        break;
5908
+                    case 'course_description':
5909 5909
                         $sql = "SELECT title FROM $table_tool
5910 5910
                                 WHERE c_id = $course_id AND id = $ref";
5911
-    					$rs_document = Database::query($sql);
5912
-    					$obj_document = Database::fetch_object($rs_document);
5911
+                        $rs_document = Database::query($sql);
5912
+                        $obj_document = Database::fetch_object($rs_document);
5913 5913
                         if ($obj_document) {
5914 5914
                             $row[5] = $obj_document->title;
5915 5915
                         }
5916
-    					break;
5917
-    				case 'thematic':
5918
-    					$rs = Database::query("SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref");
5919
-    					if (Database::num_rows($rs) > 0) {
5920
-    						$obj = Database::fetch_object($rs);
5921
-    						$row[5] = $obj->title;
5922
-    					}
5923
-    					break;
5924
-    				case 'thematic_advance':
5925
-    					$rs = Database::query("SELECT content FROM $table_tool WHERE c_id = $course_id AND id = $ref");
5926
-    					if (Database::num_rows($rs) > 0) {
5927
-    						$obj = Database::fetch_object($rs);
5928
-    						$row[5] = $obj->content;
5929
-    					}
5930
-    					break;
5931
-    				case 'thematic_plan':
5932
-    					$rs = Database::query("SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref");
5933
-    					if (Database::num_rows($rs) > 0) {
5934
-    						$obj = Database::fetch_object($rs);
5935
-    						$row[5] = $obj->title;
5936
-    					}
5937
-    					break;
5938
-    				default:
5939
-    					break;
5940
-    			}
5941
-
5942
-    			$row2 = $name_session;
5943
-    			if (!empty($coach_name)) {
5944
-    				$row2 .= '<br />'.get_lang('Coach').': '.$coach_name;
5945
-    			}
5946
-    			$row[2] = $row2;
5916
+                        break;
5917
+                    case 'thematic':
5918
+                        $rs = Database::query("SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref");
5919
+                        if (Database::num_rows($rs) > 0) {
5920
+                            $obj = Database::fetch_object($rs);
5921
+                            $row[5] = $obj->title;
5922
+                        }
5923
+                        break;
5924
+                    case 'thematic_advance':
5925
+                        $rs = Database::query("SELECT content FROM $table_tool WHERE c_id = $course_id AND id = $ref");
5926
+                        if (Database::num_rows($rs) > 0) {
5927
+                            $obj = Database::fetch_object($rs);
5928
+                            $row[5] = $obj->content;
5929
+                        }
5930
+                        break;
5931
+                    case 'thematic_plan':
5932
+                        $rs = Database::query("SELECT title FROM $table_tool WHERE c_id = $course_id AND id = $ref");
5933
+                        if (Database::num_rows($rs) > 0) {
5934
+                            $obj = Database::fetch_object($rs);
5935
+                            $row[5] = $obj->title;
5936
+                        }
5937
+                        break;
5938
+                    default:
5939
+                        break;
5940
+                }
5941
+
5942
+                $row2 = $name_session;
5943
+                if (!empty($coach_name)) {
5944
+                    $row2 .= '<br />'.get_lang('Coach').': '.$coach_name;
5945
+                }
5946
+                $row[2] = $row2;
5947 5947
                 if (!empty($row['col3'])) {
5948 5948
                     $userInfo = api_get_user_info($row['user_id']);
5949 5949
 
@@ -5960,11 +5960,11 @@  discard block
 block discarded – undo
5960 5960
                     $row[4] = $ip;
5961 5961
                 }
5962 5962
 
5963
-    			$resources[] = $row;
5964
-    		}
5965
-    	}
5963
+                $resources[] = $row;
5964
+            }
5965
+        }
5966 5966
 
5967
-    	return $resources;
5967
+        return $resources;
5968 5968
     }
5969 5969
 
5970 5970
     /**
@@ -5974,63 +5974,63 @@  discard block
 block discarded – undo
5974 5974
      */
5975 5975
     public static function get_tool_name_table($tool)
5976 5976
     {
5977
-    	switch ($tool) {
5978
-    		case 'document':
5979
-    			$table_name = TABLE_DOCUMENT;
5980
-    			$link_tool = 'document/document.php';
5981
-    			$id_tool = 'id';
5982
-    			break;
5983
-    		case 'learnpath':
5984
-    			$table_name = TABLE_LP_MAIN;
5985
-    			$link_tool = 'newscorm/lp_controller.php';
5986
-    			$id_tool = 'id';
5987
-    			break;
5988
-    		case 'quiz':
5989
-    			$table_name = TABLE_QUIZ_TEST;
5990
-    			$link_tool = 'exercice/exercice.php';
5991
-    			$id_tool = 'id';
5992
-    			break;
5993
-    		case 'glossary':
5994
-    			$table_name = TABLE_GLOSSARY;
5995
-    			$link_tool = 'glossary/index.php';
5996
-    			$id_tool = 'glossary_id';
5997
-    			break;
5998
-    		case 'link':
5999
-    			$table_name = TABLE_LINK;
6000
-    			$link_tool = 'link/link.php';
6001
-    			$id_tool = 'id';
6002
-    			break;
6003
-    		case 'course_description':
6004
-    			$table_name = TABLE_COURSE_DESCRIPTION;
6005
-    			$link_tool = 'course_description/';
6006
-    			$id_tool = 'id';
6007
-    			break;
6008
-    		case 'announcement':
6009
-    			$table_name = TABLE_ANNOUNCEMENT;
6010
-    			$link_tool = 'announcements/announcements.php';
6011
-    			$id_tool = 'id';
6012
-    			break;
6013
-    		case 'thematic':
6014
-    			$table_name = TABLE_THEMATIC;
6015
-    			$link_tool = 'course_progress/index.php';
6016
-    			$id_tool = 'id';
6017
-    			break;
6018
-    		case 'thematic_advance':
6019
-    			$table_name = TABLE_THEMATIC_ADVANCE;
6020
-    			$link_tool = 'course_progress/index.php';
6021
-    			$id_tool = 'id';
6022
-    			break;
6023
-    		case 'thematic_plan':
6024
-    			$table_name = TABLE_THEMATIC_PLAN;
6025
-    			$link_tool = 'course_progress/index.php';
6026
-    			$id_tool = 'id';
6027
-    			break;
6028
-    		default:
6029
-    			$table_name = $tool;
6030
-    		break;
6031
-    	}
6032
-
6033
-    	return array(
5977
+        switch ($tool) {
5978
+            case 'document':
5979
+                $table_name = TABLE_DOCUMENT;
5980
+                $link_tool = 'document/document.php';
5981
+                $id_tool = 'id';
5982
+                break;
5983
+            case 'learnpath':
5984
+                $table_name = TABLE_LP_MAIN;
5985
+                $link_tool = 'newscorm/lp_controller.php';
5986
+                $id_tool = 'id';
5987
+                break;
5988
+            case 'quiz':
5989
+                $table_name = TABLE_QUIZ_TEST;
5990
+                $link_tool = 'exercice/exercice.php';
5991
+                $id_tool = 'id';
5992
+                break;
5993
+            case 'glossary':
5994
+                $table_name = TABLE_GLOSSARY;
5995
+                $link_tool = 'glossary/index.php';
5996
+                $id_tool = 'glossary_id';
5997
+                break;
5998
+            case 'link':
5999
+                $table_name = TABLE_LINK;
6000
+                $link_tool = 'link/link.php';
6001
+                $id_tool = 'id';
6002
+                break;
6003
+            case 'course_description':
6004
+                $table_name = TABLE_COURSE_DESCRIPTION;
6005
+                $link_tool = 'course_description/';
6006
+                $id_tool = 'id';
6007
+                break;
6008
+            case 'announcement':
6009
+                $table_name = TABLE_ANNOUNCEMENT;
6010
+                $link_tool = 'announcements/announcements.php';
6011
+                $id_tool = 'id';
6012
+                break;
6013
+            case 'thematic':
6014
+                $table_name = TABLE_THEMATIC;
6015
+                $link_tool = 'course_progress/index.php';
6016
+                $id_tool = 'id';
6017
+                break;
6018
+            case 'thematic_advance':
6019
+                $table_name = TABLE_THEMATIC_ADVANCE;
6020
+                $link_tool = 'course_progress/index.php';
6021
+                $id_tool = 'id';
6022
+                break;
6023
+            case 'thematic_plan':
6024
+                $table_name = TABLE_THEMATIC_PLAN;
6025
+                $link_tool = 'course_progress/index.php';
6026
+                $id_tool = 'id';
6027
+                break;
6028
+            default:
6029
+                $table_name = $tool;
6030
+            break;
6031
+        }
6032
+
6033
+        return array(
6034 6034
             'table_name' => $table_name,
6035 6035
             'link_tool' => $link_tool,
6036 6036
             'id_tool' => $id_tool
@@ -6039,45 +6039,45 @@  discard block
 block discarded – undo
6039 6039
 
6040 6040
     public static function display_additional_profile_fields()
6041 6041
     {
6042
-    	// getting all the extra profile fields that are defined by the platform administrator
6043
-    	$extra_fields = UserManager :: get_extra_fields(0,50,5,'ASC');
6044
-
6045
-    	// creating the form
6046
-    	$return = '<form action="courseLog.php" method="get" name="additional_profile_field_form" id="additional_profile_field_form">';
6047
-
6048
-    	// the select field with the additional user profile fields (= this is where we select the field of which we want to see
6049
-    	// the information the users have entered or selected.
6050
-    	$return .= '<select name="additional_profile_field">';
6051
-    	$return .= '<option value="-">'.get_lang('SelectFieldToAdd').'</option>';
6052
-    	$extra_fields_to_show = 0;
6053
-    	foreach ($extra_fields as $key=>$field) {
6054
-    		// show only extra fields that are visible + and can be filtered, added by J.Montoya
6055
-    		if ($field[6]==1 && $field[8] == 1) {
6056
-    			if (isset($_GET['additional_profile_field']) && $field[0] == $_GET['additional_profile_field'] ) {
6057
-    				$selected = 'selected="selected"';
6058
-    			} else {
6059
-    				$selected = '';
6060
-    			}
6061
-    			$extra_fields_to_show++;
6062
-    			$return .= '<option value="'.$field[0].'" '.$selected.'>'.$field[3].'</option>';
6063
-    		}
6064
-    	}
6065
-    	$return .= '</select>';
6066
-
6067
-    	// the form elements for the $_GET parameters (because the form is passed through GET
6068
-    	foreach ($_GET as $key=>$value){
6069
-    		if ($key <> 'additional_profile_field')    {
6070
-    			$return .= '<input type="hidden" name="'.Security::remove_XSS($key).'" value="'.Security::remove_XSS($value).'" />';
6071
-    		}
6072
-    	}
6073
-    	// the submit button
6074
-    	$return .= '<button class="save" type="submit">'.get_lang('AddAdditionalProfileField').'</button>';
6075
-    	$return .= '</form>';
6076
-    	if ($extra_fields_to_show > 0) {
6077
-    		return $return;
6078
-    	} else {
6079
-    		return '';
6080
-    	}
6042
+        // getting all the extra profile fields that are defined by the platform administrator
6043
+        $extra_fields = UserManager :: get_extra_fields(0,50,5,'ASC');
6044
+
6045
+        // creating the form
6046
+        $return = '<form action="courseLog.php" method="get" name="additional_profile_field_form" id="additional_profile_field_form">';
6047
+
6048
+        // the select field with the additional user profile fields (= this is where we select the field of which we want to see
6049
+        // the information the users have entered or selected.
6050
+        $return .= '<select name="additional_profile_field">';
6051
+        $return .= '<option value="-">'.get_lang('SelectFieldToAdd').'</option>';
6052
+        $extra_fields_to_show = 0;
6053
+        foreach ($extra_fields as $key=>$field) {
6054
+            // show only extra fields that are visible + and can be filtered, added by J.Montoya
6055
+            if ($field[6]==1 && $field[8] == 1) {
6056
+                if (isset($_GET['additional_profile_field']) && $field[0] == $_GET['additional_profile_field'] ) {
6057
+                    $selected = 'selected="selected"';
6058
+                } else {
6059
+                    $selected = '';
6060
+                }
6061
+                $extra_fields_to_show++;
6062
+                $return .= '<option value="'.$field[0].'" '.$selected.'>'.$field[3].'</option>';
6063
+            }
6064
+        }
6065
+        $return .= '</select>';
6066
+
6067
+        // the form elements for the $_GET parameters (because the form is passed through GET
6068
+        foreach ($_GET as $key=>$value){
6069
+            if ($key <> 'additional_profile_field')    {
6070
+                $return .= '<input type="hidden" name="'.Security::remove_XSS($key).'" value="'.Security::remove_XSS($value).'" />';
6071
+            }
6072
+        }
6073
+        // the submit button
6074
+        $return .= '<button class="save" type="submit">'.get_lang('AddAdditionalProfileField').'</button>';
6075
+        $return .= '</form>';
6076
+        if ($extra_fields_to_show > 0) {
6077
+            return $return;
6078
+        } else {
6079
+            return '';
6080
+        }
6081 6081
     }
6082 6082
 
6083 6083
     /**
@@ -6096,31 +6096,31 @@  discard block
 block discarded – undo
6096 6096
      */
6097 6097
     public static function get_addtional_profile_information_of_field_by_user($field_id, $users)
6098 6098
     {
6099
-    	// Database table definition
6100
-    	$table_user = Database::get_main_table(TABLE_MAIN_USER);
6101
-    	$table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
6099
+        // Database table definition
6100
+        $table_user = Database::get_main_table(TABLE_MAIN_USER);
6101
+        $table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
6102 6102
         $extraField = Database::get_main_table(TABLE_EXTRA_FIELD);
6103
-    	$result_extra_field = UserManager::get_extra_field_information($field_id);
6104
-
6105
-    	if (!empty($users)) {
6106
-    		if ($result_extra_field['field_type'] == UserManager::USER_FIELD_TYPE_TAG ) {
6107
-    			foreach($users as $user_id) {
6108
-    				$user_result = UserManager::get_user_tags($user_id, $field_id);
6109
-    				$tag_list = array();
6110
-    				foreach($user_result as $item) {
6111
-    					$tag_list[] = $item['tag'];
6112
-    				}
6113
-    				$return[$user_id][] = implode(', ',$tag_list);
6114
-    			}
6115
-    		} else {
6116
-    			$new_user_array = array();
6117
-    			foreach ($users as $user_id) {
6118
-    				$new_user_array[]= "'".$user_id."'";
6119
-    			}
6120
-    			$users = implode(',',$new_user_array);
6103
+        $result_extra_field = UserManager::get_extra_field_information($field_id);
6104
+
6105
+        if (!empty($users)) {
6106
+            if ($result_extra_field['field_type'] == UserManager::USER_FIELD_TYPE_TAG ) {
6107
+                foreach($users as $user_id) {
6108
+                    $user_result = UserManager::get_user_tags($user_id, $field_id);
6109
+                    $tag_list = array();
6110
+                    foreach($user_result as $item) {
6111
+                        $tag_list[] = $item['tag'];
6112
+                    }
6113
+                    $return[$user_id][] = implode(', ',$tag_list);
6114
+                }
6115
+            } else {
6116
+                $new_user_array = array();
6117
+                foreach ($users as $user_id) {
6118
+                    $new_user_array[]= "'".$user_id."'";
6119
+                }
6120
+                $users = implode(',',$new_user_array);
6121 6121
                 $extraFieldType = EntityExtraField::USER_FIELD_TYPE;
6122
-    			// Selecting only the necessary information NOT ALL the user list
6123
-    			$sql = "SELECT user.user_id, v.value
6122
+                // Selecting only the necessary information NOT ALL the user list
6123
+                $sql = "SELECT user.user_id, v.value
6124 6124
     			        FROM $table_user user
6125 6125
     			        INNER JOIN $table_user_field_values v
6126 6126
                         ON (user.user_id = v.item_id)
@@ -6131,27 +6131,27 @@  discard block
 block discarded – undo
6131 6131
                             v.field_id=".intval($field_id)." AND
6132 6132
                             user.user_id IN ($users)";
6133 6133
 
6134
-    			$result = Database::query($sql);
6135
-    			while($row = Database::fetch_array($result)) {
6136
-    				// get option value for field type double select by id
6137
-    				if (!empty($row['value'])) {
6138
-    					if ($result_extra_field['field_type'] ==
6134
+                $result = Database::query($sql);
6135
+                while($row = Database::fetch_array($result)) {
6136
+                    // get option value for field type double select by id
6137
+                    if (!empty($row['value'])) {
6138
+                        if ($result_extra_field['field_type'] ==
6139 6139
                             ExtraField::FIELD_TYPE_DOUBLE_SELECT
6140 6140
                         ) {
6141
-    						$id_double_select = explode(';', $row['value']);
6142
-    						if (is_array($id_double_select)) {
6143
-    							$value1 = $result_extra_field['options'][$id_double_select[0]]['option_value'];
6144
-    							$value2 = $result_extra_field['options'][$id_double_select[1]]['option_value'];
6145
-    							$row['value'] = ($value1.';'.$value2);
6146
-    						}
6147
-    					}
6148
-    				}
6149
-    				// get other value from extra field
6150
-    				$return[$row['user_id']][] = $row['value'];
6151
-    			}
6152
-    		}
6153
-    	}
6154
-    	return $return;
6141
+                            $id_double_select = explode(';', $row['value']);
6142
+                            if (is_array($id_double_select)) {
6143
+                                $value1 = $result_extra_field['options'][$id_double_select[0]]['option_value'];
6144
+                                $value2 = $result_extra_field['options'][$id_double_select[1]]['option_value'];
6145
+                                $row['value'] = ($value1.';'.$value2);
6146
+                            }
6147
+                        }
6148
+                    }
6149
+                    // get other value from extra field
6150
+                    $return[$row['user_id']][] = $row['value'];
6151
+                }
6152
+            }
6153
+        }
6154
+        return $return;
6155 6155
     }
6156 6156
 
6157 6157
     /**
@@ -6160,18 +6160,18 @@  discard block
 block discarded – undo
6160 6160
      */
6161 6161
     public function count_student_in_course()
6162 6162
     {
6163
-    	global $nbStudents;
6164
-    	return $nbStudents;
6163
+        global $nbStudents;
6164
+        return $nbStudents;
6165 6165
     }
6166 6166
 
6167 6167
     public function sort_users($a, $b)
6168 6168
     {
6169
-    	return strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
6169
+        return strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
6170 6170
     }
6171 6171
 
6172 6172
     public function sort_users_desc($a, $b)
6173 6173
     {
6174
-    	return strcmp( trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
6174
+        return strcmp( trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
6175 6175
     }
6176 6176
 
6177 6177
     /**
@@ -6180,8 +6180,8 @@  discard block
 block discarded – undo
6180 6180
      */
6181 6181
     public static function get_number_of_users()
6182 6182
     {
6183
-    	global $user_ids;
6184
-    	return count($user_ids);
6183
+        global $user_ids;
6184
+        return count($user_ids);
6185 6185
     }
6186 6186
 
6187 6187
     /**
@@ -6197,37 +6197,37 @@  discard block
 block discarded – undo
6197 6197
     {
6198 6198
         global $user_ids, $course_code, $additional_user_profile_info, $export_csv, $is_western_name_order, $csv_content, $session_id;
6199 6199
 
6200
-    	$course_code = Database::escape_string($course_code);
6201
-    	$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
6202
-    	$tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
6200
+        $course_code = Database::escape_string($course_code);
6201
+        $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
6202
+        $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
6203 6203
 
6204
-    	$access_url_id = api_get_current_access_url_id();
6204
+        $access_url_id = api_get_current_access_url_id();
6205 6205
 
6206
-    	// get all users data from a course for sortable with limit
6207
-    	if (is_array($user_ids)) {
6208
-    		$user_ids = array_map('intval', $user_ids);
6209
-    		$condition_user = " WHERE user.user_id IN (".implode(',',$user_ids).") ";
6210
-    	} else {
6211
-    		$user_ids = intval($user_ids);
6212
-    		$condition_user = " WHERE user.user_id = $user_ids ";
6213
-    	}
6206
+        // get all users data from a course for sortable with limit
6207
+        if (is_array($user_ids)) {
6208
+            $user_ids = array_map('intval', $user_ids);
6209
+            $condition_user = " WHERE user.user_id IN (".implode(',',$user_ids).") ";
6210
+        } else {
6211
+            $user_ids = intval($user_ids);
6212
+            $condition_user = " WHERE user.user_id = $user_ids ";
6213
+        }
6214 6214
 
6215
-    	if (!empty($_GET['user_keyword'])) {
6216
-    		$keyword = trim(Database::escape_string($_GET['user_keyword']));
6217
-    		$condition_user .=  " AND (
6215
+        if (!empty($_GET['user_keyword'])) {
6216
+            $keyword = trim(Database::escape_string($_GET['user_keyword']));
6217
+            $condition_user .=  " AND (
6218 6218
                 user.firstname LIKE '%".$keyword."%' OR
6219 6219
                 user.lastname LIKE '%".$keyword."%'  OR
6220 6220
                 user.username LIKE '%".$keyword."%'  OR
6221 6221
                 user.email LIKE '%".$keyword."%'
6222 6222
              ) ";
6223
-    	}
6223
+        }
6224 6224
 
6225 6225
         $url_table = null;
6226 6226
         $url_condition = null;
6227
-    	if (api_is_multiple_url_enabled()) {
6228
-    		$url_table = ", ".$tbl_url_rel_user." as url_users";
6229
-    		$url_condition = " AND user.user_id = url_users.user_id AND access_url_id='$access_url_id'";
6230
-    	}
6227
+        if (api_is_multiple_url_enabled()) {
6228
+            $url_table = ", ".$tbl_url_rel_user." as url_users";
6229
+            $url_condition = " AND user.user_id = url_users.user_id AND access_url_id='$access_url_id'";
6230
+        }
6231 6231
 
6232 6232
         $invitedUsersCondition = '';
6233 6233
 
@@ -6235,7 +6235,7 @@  discard block
 block discarded – undo
6235 6235
             $invitedUsersCondition = " AND user.status != " . INVITEE;
6236 6236
         }
6237 6237
 
6238
-    	$sql = "SELECT  user.user_id as user_id,
6238
+        $sql = "SELECT  user.user_id as user_id,
6239 6239
                     user.official_code  as col0,
6240 6240
                     user.lastname       as col1,
6241 6241
                     user.firstname      as col2,
@@ -6243,17 +6243,17 @@  discard block
 block discarded – undo
6243 6243
                 FROM $tbl_user as user $url_table
6244 6244
     	        $condition_user $url_condition $invitedUsersCondition";
6245 6245
 
6246
-    	if (!in_array($direction, array('ASC','DESC'))) {
6247
-    		$direction = 'ASC';
6248
-    	}
6246
+        if (!in_array($direction, array('ASC','DESC'))) {
6247
+            $direction = 'ASC';
6248
+        }
6249 6249
 
6250
-    	$column = intval($column);
6250
+        $column = intval($column);
6251 6251
 
6252
-    	$from = intval($from);
6253
-    	$number_of_items = intval($number_of_items);
6252
+        $from = intval($from);
6253
+        $number_of_items = intval($number_of_items);
6254 6254
 
6255
-    	$sql .= " ORDER BY col$column $direction ";
6256
-    	$sql .= " LIMIT $from,$number_of_items";
6255
+        $sql .= " ORDER BY col$column $direction ";
6256
+        $sql .= " LIMIT $from,$number_of_items";
6257 6257
 
6258 6258
         $res = Database::query($sql);
6259 6259
         $users = array();
@@ -6287,7 +6287,7 @@  discard block
 block discarded – undo
6287 6287
             }
6288 6288
         }
6289 6289
 
6290
-    	while ($user = Database::fetch_array($res, 'ASSOC')) {
6290
+        while ($user = Database::fetch_array($res, 'ASSOC')) {
6291 6291
             $courseInfo = api_get_course_info($course_code);
6292 6292
             $courseId = $courseInfo['real_id'];
6293 6293
 
@@ -6318,10 +6318,10 @@  discard block
 block discarded – undo
6318 6318
                 $session_id
6319 6319
             );
6320 6320
 
6321
-    		if (empty($avg_student_progress)) {
6321
+            if (empty($avg_student_progress)) {
6322 6322
                 $avg_student_progress = 0;
6323
-    		}
6324
-    		$user['average_progress'] = $avg_student_progress.'%';
6323
+            }
6324
+            $user['average_progress'] = $avg_student_progress.'%';
6325 6325
 
6326 6326
             $total_user_exercise = Tracking::get_exercise_student_progress(
6327 6327
                 $total_exercises,
@@ -6341,11 +6341,11 @@  discard block
 block discarded – undo
6341 6341
 
6342 6342
             $user['exercise_average_best_attempt'] = $total_user_exercise;
6343 6343
 
6344
-    		if (is_numeric($avg_student_score)) {
6345
-    			$user['student_score']  = $avg_student_score.'%';
6346
-    		} else {
6347
-    			$user['student_score']  = $avg_student_score;
6348
-    		}
6344
+            if (is_numeric($avg_student_score)) {
6345
+                $user['student_score']  = $avg_student_score.'%';
6346
+            } else {
6347
+                $user['student_score']  = $avg_student_score;
6348
+            }
6349 6349
 
6350 6350
             $user['count_assignments'] = Tracking::count_student_assignments(
6351 6351
                 $user['user_id'],
@@ -6368,26 +6368,26 @@  discard block
 block discarded – undo
6368 6368
                 $session_id
6369 6369
             );
6370 6370
 
6371
-    		// we need to display an additional profile field
6372
-    		$user['additional'] = '';
6371
+            // we need to display an additional profile field
6372
+            $user['additional'] = '';
6373 6373
 
6374
-    		if (isset($_GET['additional_profile_field']) && is_numeric($_GET['additional_profile_field'])) {
6375
-    			if (isset($additional_user_profile_info[$user['user_id']]) &&
6374
+            if (isset($_GET['additional_profile_field']) && is_numeric($_GET['additional_profile_field'])) {
6375
+                if (isset($additional_user_profile_info[$user['user_id']]) &&
6376 6376
                     is_array($additional_user_profile_info[$user['user_id']])
6377 6377
                 ) {
6378
-    				$user['additional'] = implode(', ', $additional_user_profile_info[$user['user_id']]);
6379
-    			}
6380
-    		}
6378
+                    $user['additional'] = implode(', ', $additional_user_profile_info[$user['user_id']]);
6379
+                }
6380
+            }
6381 6381
 
6382 6382
             if (empty($session_id)) {
6383 6383
                 $user['survey'] = (isset($survey_user_list[$user['user_id']]) ? $survey_user_list[$user['user_id']] : 0) .' / '.$total_surveys;
6384 6384
             }
6385 6385
 
6386
-    		$user['link'] = '<center><a href="../mySpace/myStudents.php?student='.$user['user_id'].'&details=true&course='.$course_code.'&origin=tracking_course&id_session='.$session_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'icons/22/2rightarrow.png" border="0" /></a></center>';
6386
+            $user['link'] = '<center><a href="../mySpace/myStudents.php?student='.$user['user_id'].'&details=true&course='.$course_code.'&origin=tracking_course&id_session='.$session_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'icons/22/2rightarrow.png" border="0" /></a></center>';
6387 6387
 
6388
-    		// store columns in array $users
6388
+            // store columns in array $users
6389 6389
 
6390
-    		$is_western_name_order = api_is_western_name_order();
6390
+            $is_western_name_order = api_is_western_name_order();
6391 6391
             $user_row = array();
6392 6392
 
6393 6393
             $user_row[]= $user['official_code']; //0
@@ -6422,21 +6422,21 @@  discard block
 block discarded – undo
6422 6422
 
6423 6423
             $users[] = $user_row;
6424 6424
 
6425
-    		if ($export_csv) {
6426
-    		    if (empty($session_id)) {
6425
+            if ($export_csv) {
6426
+                if (empty($session_id)) {
6427 6427
                     $user_row = array_map('strip_tags', $user_row);
6428
-    			    unset($user_row[14]);
6429
-    			    unset($user_row[15]);
6428
+                    unset($user_row[14]);
6429
+                    unset($user_row[15]);
6430 6430
                 } else {
6431 6431
                     $user_row = array_map('strip_tags', $user_row);
6432 6432
                     unset($user_row[13]);
6433 6433
                     unset($user_row[14]);
6434 6434
                 }
6435 6435
 
6436
-    			$csv_content[] = $user_row;
6437
-    		}
6438
-    	}
6439
-    	return $users;
6436
+                $csv_content[] = $user_row;
6437
+            }
6438
+        }
6439
+        return $users;
6440 6440
     }
6441 6441
 }
6442 6442
 
@@ -6454,18 +6454,18 @@  discard block
 block discarded – undo
6454 6454
      */
6455 6455
     public function display_login_tracking_info($view, $user_id, $course_id, $session_id = 0)
6456 6456
     {
6457
-    	$MonthsLong = $GLOBALS['MonthsLong'];
6458
-
6459
-    	// protected data
6460
-    	$user_id = intval($user_id);
6461
-    	$session_id = intval($session_id);
6462
-    	$course_id = Database::escape_string($course_id);
6463
-
6464
-    	$track_access_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
6465
-    	$tempView = $view;
6466
-    	if(substr($view,0,1) == '1') {
6467
-    		$new_view = substr_replace($view,'0',0,1);
6468
-    		echo "
6457
+        $MonthsLong = $GLOBALS['MonthsLong'];
6458
+
6459
+        // protected data
6460
+        $user_id = intval($user_id);
6461
+        $session_id = intval($session_id);
6462
+        $course_id = Database::escape_string($course_id);
6463
+
6464
+        $track_access_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
6465
+        $tempView = $view;
6466
+        if(substr($view,0,1) == '1') {
6467
+            $new_view = substr_replace($view,'0',0,1);
6468
+            echo "
6469 6469
                 <tr>
6470 6470
                     <td valign='top'>
6471 6471
                     <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font>" .
@@ -6473,9 +6473,9 @@  discard block
 block discarded – undo
6473 6473
                     </td>
6474 6474
                 </tr>
6475 6475
                 ";
6476
-    		echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('LoginsDetails')."<br>";
6476
+            echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('LoginsDetails')."<br>";
6477 6477
 
6478
-    		$sql = "SELECT UNIX_TIMESTAMP(access_date), count(access_date)
6478
+            $sql = "SELECT UNIX_TIMESTAMP(access_date), count(access_date)
6479 6479
                         FROM $track_access_table
6480 6480
                         WHERE access_user_id = $user_id
6481 6481
                         AND c_id = $course_id
@@ -6483,11 +6483,11 @@  discard block
 block discarded – undo
6483 6483
                         GROUP BY YEAR(access_date),MONTH(access_date)
6484 6484
                         ORDER BY YEAR(access_date),MONTH(access_date) ASC";
6485 6485
 
6486
-    		echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
6487
-    		$results = getManyResults3Col($sql);
6486
+            echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
6487
+            $results = getManyResults3Col($sql);
6488 6488
 
6489
-    		echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
6490
-    		echo "<tr>
6489
+            echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
6490
+            echo "<tr>
6491 6491
                     <td class='secLine'>
6492 6492
                     ".get_lang('LoginsTitleMonthColumn')."
6493 6493
                     </td>
@@ -6495,36 +6495,36 @@  discard block
 block discarded – undo
6495 6495
                     ".get_lang('LoginsTitleCountColumn')."
6496 6496
                     </td>
6497 6497
                 </tr>";
6498
-    		$total = 0;
6499
-    		if (is_array($results)) {
6500
-    			for($j = 0 ; $j < count($results) ; $j++) {
6501
-    				echo "<tr>";
6502
-    				echo "<td class='content'><a href='logins_details.php?uInfo=".$user_id."&reqdate=".$results[$j][0]."&view=".Security::remove_XSS($view)."'>".$MonthsLong[date('n', $results[$j][0])-1].' '.date('Y', $results[$j][0])."</a></td>";
6503
-    				echo "<td valign='top' align='right' class='content'>".$results[$j][1]."</td>";
6504
-    				echo"</tr>";
6505
-    				$total = $total + $results[$j][1];
6506
-    			}
6507
-    			echo "<tr>";
6508
-    			echo "<td>".get_lang('Total')."</td>";
6509
-    			echo "<td align='right' class='content'>".$total."</td>";
6510
-    			echo"</tr>";
6511
-    		} else {
6512
-    			echo "<tr>";
6513
-    			echo "<td colspan='2'><center>".get_lang('NoResult')."</center></td>";
6514
-    			echo"</tr>";
6515
-    		}
6516
-    		echo "</table>";
6517
-    		echo "</td></tr>";
6518
-    	} else {
6519
-    		$new_view = substr_replace($view,'1',0,1);
6520
-    		echo "
6498
+            $total = 0;
6499
+            if (is_array($results)) {
6500
+                for($j = 0 ; $j < count($results) ; $j++) {
6501
+                    echo "<tr>";
6502
+                    echo "<td class='content'><a href='logins_details.php?uInfo=".$user_id."&reqdate=".$results[$j][0]."&view=".Security::remove_XSS($view)."'>".$MonthsLong[date('n', $results[$j][0])-1].' '.date('Y', $results[$j][0])."</a></td>";
6503
+                    echo "<td valign='top' align='right' class='content'>".$results[$j][1]."</td>";
6504
+                    echo"</tr>";
6505
+                    $total = $total + $results[$j][1];
6506
+                }
6507
+                echo "<tr>";
6508
+                echo "<td>".get_lang('Total')."</td>";
6509
+                echo "<td align='right' class='content'>".$total."</td>";
6510
+                echo"</tr>";
6511
+            } else {
6512
+                echo "<tr>";
6513
+                echo "<td colspan='2'><center>".get_lang('NoResult')."</center></td>";
6514
+                echo"</tr>";
6515
+            }
6516
+            echo "</table>";
6517
+            echo "</td></tr>";
6518
+        } else {
6519
+            $new_view = substr_replace($view,'1',0,1);
6520
+            echo "
6521 6521
                 <tr>
6522 6522
                     <td valign='top'>
6523 6523
                     +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".$user_id."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('LoginsAndAccessTools')."</a>
6524 6524
                     </td>
6525 6525
                 </tr>
6526 6526
             ";
6527
-    	}
6527
+        }
6528 6528
     }
6529 6529
 
6530 6530
     /**
@@ -6537,38 +6537,38 @@  discard block
 block discarded – undo
6537 6537
      */
6538 6538
     public function display_exercise_tracking_info($view, $user_id, $courseCode)
6539 6539
     {
6540
-    	global $TBL_TRACK_HOTPOTATOES, $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $dateTimeFormatLong;
6540
+        global $TBL_TRACK_HOTPOTATOES, $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $dateTimeFormatLong;
6541 6541
         $courseId = api_get_course_int_id($courseCode);
6542
-    	if(substr($view,1,1) == '1') {
6543
-    		$new_view = substr_replace($view,'0',1,1);
6544
-    		echo "<tr>
6542
+        if(substr($view,1,1) == '1') {
6543
+            $new_view = substr_replace($view,'0',1,1);
6544
+            echo "<tr>
6545 6545
                     <td valign='top'>
6546 6546
                         <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('ExercicesResults')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=01000'>".get_lang('ExportAsCSV')."</a>]
6547 6547
                     </td>
6548 6548
                 </tr>";
6549
-    		echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('ExercicesDetails')."<br />";
6549
+            echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('ExercicesDetails')."<br />";
6550 6550
 
6551
-    		$sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
6551
+            $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
6552 6552
                     FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te
6553 6553
                     WHERE te.c_id = $courseId
6554 6554
                         AND te.exe_user_id = ".intval($user_id)."
6555 6555
                         AND te.exe_exo_id = ce.id
6556 6556
                     ORDER BY ce.title ASC, te.exe_date ASC";
6557 6557
 
6558
-    		$hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
6558
+            $hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
6559 6559
                         FROM $TBL_TRACK_HOTPOTATOES AS te
6560 6560
                         WHERE te.exe_user_id = '".intval($user_id)."' AND te.c_id = $courseId
6561 6561
                         ORDER BY te.c_id ASC, te.exe_date ASC";
6562 6562
 
6563
-    		$hpresults = StatsUtils::getManyResultsXCol($hpsql, 4);
6563
+            $hpresults = StatsUtils::getManyResultsXCol($hpsql, 4);
6564 6564
 
6565
-    		$NoTestRes = 0;
6566
-    		$NoHPTestRes = 0;
6565
+            $NoTestRes = 0;
6566
+            $NoHPTestRes = 0;
6567 6567
 
6568
-    		echo "<tr>\n<td style='padding-left : 40px;padding-right : 40px;'>\n";
6569
-    		$results = StatsUtils::getManyResultsXCol($sql, 4);
6570
-    		echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>\n";
6571
-    		echo "
6568
+            echo "<tr>\n<td style='padding-left : 40px;padding-right : 40px;'>\n";
6569
+            $results = StatsUtils::getManyResultsXCol($sql, 4);
6570
+            echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>\n";
6571
+            echo "
6572 6572
                 <tr bgcolor='#E6E6E6'>
6573 6573
                     <td>
6574 6574
                     ".get_lang('ExercicesTitleExerciceColumn')."
@@ -6581,28 +6581,28 @@  discard block
 block discarded – undo
6581 6581
                     </td>
6582 6582
                 </tr>";
6583 6583
 
6584
-    		if (is_array($results)) {
6585
-    			for($i = 0; $i < sizeof($results); $i++) {
6586
-    				$display_date = api_convert_and_format_date($results[$i][3], null, date_default_timezone_get());
6587
-    				echo "<tr>\n";
6588
-    				echo "<td class='content'>".$results[$i][0]."</td>\n";
6589
-    				echo "<td class='content'>".$display_date."</td>\n";
6590
-    				echo "<td valign='top' align='right' class='content'>".$results[$i][1]." / ".$results[$i][2]."</td>\n";
6591
-    				echo "</tr>\n";
6592
-    			}
6593
-    		} else {
6594
-    			// istvan begin
6595
-    			$NoTestRes = 1;
6596
-    		}
6597
-
6598
-    		// The Result of Tests
6599
-    		if (is_array($hpresults)) {
6600
-    			for($i = 0; $i < sizeof($hpresults); $i++) {
6601
-    				$title = GetQuizName($hpresults[$i][0],'');
6602
-    				if ($title == '')
6603
-    				$title = basename($hpresults[$i][0]);
6604
-    				$display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get());
6605
-    				?>
6584
+            if (is_array($results)) {
6585
+                for($i = 0; $i < sizeof($results); $i++) {
6586
+                    $display_date = api_convert_and_format_date($results[$i][3], null, date_default_timezone_get());
6587
+                    echo "<tr>\n";
6588
+                    echo "<td class='content'>".$results[$i][0]."</td>\n";
6589
+                    echo "<td class='content'>".$display_date."</td>\n";
6590
+                    echo "<td valign='top' align='right' class='content'>".$results[$i][1]." / ".$results[$i][2]."</td>\n";
6591
+                    echo "</tr>\n";
6592
+                }
6593
+            } else {
6594
+                // istvan begin
6595
+                $NoTestRes = 1;
6596
+            }
6597
+
6598
+            // The Result of Tests
6599
+            if (is_array($hpresults)) {
6600
+                for($i = 0; $i < sizeof($hpresults); $i++) {
6601
+                    $title = GetQuizName($hpresults[$i][0],'');
6602
+                    if ($title == '')
6603
+                    $title = basename($hpresults[$i][0]);
6604
+                    $display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get());
6605
+                    ?>
6606 6606
                     <tr>
6607 6607
                         <td class="content"><?php echo $title; ?></td>
6608 6608
                         <td class="content" align="center"><?php echo $display_date; ?></td>
@@ -6612,26 +6612,26 @@  discard block
 block discarded – undo
6612 6612
 
6613 6613
                     <?php
6614 6614
                 }
6615
-    		} else {
6616
-    			$NoHPTestRes = 1;
6617
-    		}
6618
-
6619
-    		if ($NoTestRes == 1 && $NoHPTestRes == 1) {
6620
-    			echo "<tr>\n";
6621
-    			echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>\n";
6622
-    			echo "</tr>\n";
6623
-    		}
6624
-    		echo "</table>";
6625
-    		echo "</td>\n</tr>\n";
6626
-    	} else {
6627
-    		$new_view = substr_replace($view,'1',1,1);
6628
-    		echo "
6615
+            } else {
6616
+                $NoHPTestRes = 1;
6617
+            }
6618
+
6619
+            if ($NoTestRes == 1 && $NoHPTestRes == 1) {
6620
+                echo "<tr>\n";
6621
+                echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>\n";
6622
+                echo "</tr>\n";
6623
+            }
6624
+            echo "</table>";
6625
+            echo "</td>\n</tr>\n";
6626
+        } else {
6627
+            $new_view = substr_replace($view,'1',1,1);
6628
+            echo "
6629 6629
                 <tr>
6630 6630
                     <td valign='top'>
6631 6631
                         +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=$user_id&view=".$new_view."' class='specialLink'>".get_lang('ExercicesResults')."</a>
6632 6632
                     </td>
6633 6633
                 </tr>";
6634
-    	}
6634
+        }
6635 6635
     }
6636 6636
 
6637 6637
     /**
@@ -6640,27 +6640,27 @@  discard block
 block discarded – undo
6640 6640
      */
6641 6641
     public function display_student_publications_tracking_info($view, $user_id, $course_id)
6642 6642
     {
6643
-    	global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK;
6643
+        global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK;
6644 6644
         $_course = api_get_course_info_by_id($course_id);
6645 6645
 
6646
-    	if (substr($view,2,1) == '1') {
6647
-    		$new_view = substr_replace($view,'0',2,1);
6648
-    		echo "<tr>
6646
+        if (substr($view,2,1) == '1') {
6647
+            $new_view = substr_replace($view,'0',2,1);
6648
+            echo "<tr>
6649 6649
                     <td valign='top'>
6650 6650
                     <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('WorkUploads')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=00100'>".get_lang('ExportAsCSV')."</a>]
6651 6651
                     </td>
6652 6652
                 </tr>";
6653
-    		echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('WorksDetails')."<br>";
6654
-    		$sql = "SELECT u.upload_date, w.title, w.author,w.url
6653
+            echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('WorksDetails')."<br>";
6654
+            $sql = "SELECT u.upload_date, w.title, w.author,w.url
6655 6655
                     FROM $TABLETRACK_UPLOADS u , $TABLECOURSE_WORK w
6656 6656
                     WHERE u.upload_work_id = w.id
6657 6657
                         AND u.upload_user_id = '".intval($user_id)."'
6658 6658
                         AND u.c_id = '".intval($course_id)."'
6659 6659
                     ORDER BY u.upload_date DESC";
6660
-    		echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
6661
-    		$results = StatsUtils::getManyResultsXCol($sql,4);
6662
-    		echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
6663
-    		echo "<tr>
6660
+            echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
6661
+            $results = StatsUtils::getManyResultsXCol($sql,4);
6662
+            echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
6663
+            echo "<tr>
6664 6664
                     <td class='secLine' width='40%'>
6665 6665
                     ".get_lang('WorkTitle')."
6666 6666
                     </td>
@@ -6671,35 +6671,35 @@  discard block
 block discarded – undo
6671 6671
                     ".get_lang('Date')."
6672 6672
                     </td>
6673 6673
                 </tr>";
6674
-    		if (is_array($results)) {
6675
-    			for($j = 0 ; $j < count($results) ; $j++) {
6676
-    				$pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
6677
-    				$beautifulDate = api_convert_and_format_date($results[$j][0], null, date_default_timezone_get());
6678
-    				echo "<tr>";
6679
-    				echo "<td class='content'>"
6680
-    				."<a href ='".$pathToFile."'>".$results[$j][1]."</a>"
6681
-    				."</td>";
6682
-    				echo "<td class='content'>".$results[$j][2]."</td>";
6683
-    				echo "<td class='content'>".$beautifulDate."</td>";
6684
-    				echo"</tr>";
6685
-    			}
6686
-    		} else {
6687
-    			echo "<tr>";
6688
-    			echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>";
6689
-    			echo"</tr>";
6690
-    		}
6691
-    		echo "</table>";
6692
-    		echo "</td></tr>";
6693
-    	} else {
6694
-    		$new_view = substr_replace($view,'1',2,1);
6695
-    		echo "
6674
+            if (is_array($results)) {
6675
+                for($j = 0 ; $j < count($results) ; $j++) {
6676
+                    $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
6677
+                    $beautifulDate = api_convert_and_format_date($results[$j][0], null, date_default_timezone_get());
6678
+                    echo "<tr>";
6679
+                    echo "<td class='content'>"
6680
+                    ."<a href ='".$pathToFile."'>".$results[$j][1]."</a>"
6681
+                    ."</td>";
6682
+                    echo "<td class='content'>".$results[$j][2]."</td>";
6683
+                    echo "<td class='content'>".$beautifulDate."</td>";
6684
+                    echo"</tr>";
6685
+                }
6686
+            } else {
6687
+                echo "<tr>";
6688
+                echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>";
6689
+                echo"</tr>";
6690
+            }
6691
+            echo "</table>";
6692
+            echo "</td></tr>";
6693
+        } else {
6694
+            $new_view = substr_replace($view,'1',2,1);
6695
+            echo "
6696 6696
                 <tr>
6697 6697
                     <td valign='top'>
6698 6698
                     +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('WorkUploads')."</a>
6699 6699
                     </td>
6700 6700
                 </tr>
6701 6701
             ";
6702
-    	}
6702
+        }
6703 6703
     }
6704 6704
 
6705 6705
     /**
@@ -6708,55 +6708,55 @@  discard block
 block discarded – undo
6708 6708
      */
6709 6709
     public function display_links_tracking_info($view, $user_id, $courseCode)
6710 6710
     {
6711
-    	global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
6711
+        global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
6712 6712
         $courseId = api_get_course_int_id($courseCode);
6713
-    	if (substr($view,3,1) == '1') {
6714
-    		$new_view = substr_replace($view,'0',3,1);
6715
-    		echo "
6713
+        if (substr($view,3,1) == '1') {
6714
+            $new_view = substr_replace($view,'0',3,1);
6715
+            echo "
6716 6716
                 <tr>
6717 6717
                         <td valign='top'>
6718 6718
                         <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('LinksAccess')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=00010'>".get_lang('ExportAsCSV')."</a>]
6719 6719
                         </td>
6720 6720
                 </tr>
6721 6721
             ";
6722
-    		echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('LinksDetails')."<br>";
6723
-    		$sql = "SELECT cl.title, cl.url
6722
+            echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('LinksDetails')."<br>";
6723
+            $sql = "SELECT cl.title, cl.url
6724 6724
                     FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
6725 6725
                     WHERE sl.links_link_id = cl.id
6726 6726
                         AND sl.c_id = $courseId
6727 6727
                         AND sl.links_user_id = ".intval($user_id)."
6728 6728
                     GROUP BY cl.title, cl.url";
6729
-    		echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
6730
-    		$results = StatsUtils::getManyResults2Col($sql);
6731
-    		echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
6732
-    		echo "<tr>
6729
+            echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
6730
+            $results = StatsUtils::getManyResults2Col($sql);
6731
+            echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
6732
+            echo "<tr>
6733 6733
                     <td class='secLine'>
6734 6734
                     ".get_lang('LinksTitleLinkColumn')."
6735 6735
                     </td>
6736 6736
                 </tr>";
6737
-    		if (is_array($results)) {
6738
-    			for($j = 0 ; $j < count($results) ; $j++) {
6739
-    				echo "<tr>";
6740
-    				echo "<td class='content'><a href='".$results[$j][1]."'>".$results[$j][0]."</a></td>";
6741
-    				echo"</tr>";
6742
-    			}
6743
-    		} else {
6744
-    			echo "<tr>";
6745
-    			echo "<td ><center>".get_lang('NoResult')."</center></td>";
6746
-    			echo"</tr>";
6747
-    		}
6748
-    		echo "</table>";
6749
-    		echo "</td></tr>";
6750
-    	} else {
6751
-    		$new_view = substr_replace($view,'1',3,1);
6752
-    		echo "
6737
+            if (is_array($results)) {
6738
+                for($j = 0 ; $j < count($results) ; $j++) {
6739
+                    echo "<tr>";
6740
+                    echo "<td class='content'><a href='".$results[$j][1]."'>".$results[$j][0]."</a></td>";
6741
+                    echo"</tr>";
6742
+                }
6743
+            } else {
6744
+                echo "<tr>";
6745
+                echo "<td ><center>".get_lang('NoResult')."</center></td>";
6746
+                echo"</tr>";
6747
+            }
6748
+            echo "</table>";
6749
+            echo "</td></tr>";
6750
+        } else {
6751
+            $new_view = substr_replace($view,'1',3,1);
6752
+            echo "
6753 6753
                 <tr>
6754 6754
                     <td valign='top'>
6755 6755
                     +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('LinksAccess')."</a>
6756 6756
                     </td>
6757 6757
                 </tr>
6758 6758
             ";
6759
-    	}
6759
+        }
6760 6760
     }
6761 6761
 
6762 6762
     /**
@@ -6769,61 +6769,61 @@  discard block
 block discarded – undo
6769 6769
      */
6770 6770
     public static function display_document_tracking_info($view, $user_id, $course_code, $session_id = 0)
6771 6771
     {
6772
-    	// protect data
6772
+        // protect data
6773 6773
         $user_id = intval($user_id);
6774 6774
         $courseId = api_get_course_int_id($course_code);
6775
-    	$session_id = intval($session_id);
6775
+        $session_id = intval($session_id);
6776 6776
 
6777
-    	$downloads_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
6778
-    	if(substr($view,4,1) == '1') {
6779
-    		$new_view = substr_replace($view,'0',4,1);
6780
-    		echo "
6777
+        $downloads_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
6778
+        if(substr($view,4,1) == '1') {
6779
+            $new_view = substr_replace($view,'0',4,1);
6780
+            echo "
6781 6781
                 <tr>
6782 6782
                     <td valign='top'>
6783 6783
                     <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('DocumentsAccess')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=00001'>".get_lang('ExportAsCSV')."</a>]
6784 6784
                     </td>
6785 6785
                 </tr>
6786 6786
             ";
6787
-    		echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('DocumentsDetails')."<br>";
6787
+            echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('DocumentsDetails')."<br>";
6788 6788
 
6789
-    		$sql = "SELECT down_doc_path
6789
+            $sql = "SELECT down_doc_path
6790 6790
                     FROM $downloads_table
6791 6791
                     WHERE c_id = $courseId
6792 6792
                         AND down_user_id = $user_id
6793 6793
                         AND down_session_id = $session_id
6794 6794
                     GROUP BY down_doc_path";
6795 6795
 
6796
-    		echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
6797
-    		$results = StatsUtils::getManyResults1Col($sql);
6798
-    		echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>";
6799
-    		echo "<tr>
6796
+            echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
6797
+            $results = StatsUtils::getManyResults1Col($sql);
6798
+            echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>";
6799
+            echo "<tr>
6800 6800
                     <td class='secLine'>
6801 6801
                     ".get_lang('DocumentsTitleDocumentColumn')."
6802 6802
                     </td>
6803 6803
                 </tr>";
6804
-    		if (is_array($results)) {
6805
-    			for($j = 0 ; $j < count($results) ; $j++) {
6806
-    				echo "<tr>";
6807
-    				echo "<td class='content'>".$results[$j]."</td>";
6808
-    				echo"</tr>";
6809
-    			}
6810
-    		} else {
6811
-    			echo "<tr>";
6812
-    			echo "<td><center>".get_lang('NoResult')."</center></td>";
6813
-    			echo"</tr>";
6814
-    		}
6815
-    		echo "</table>";
6816
-    		echo "</td></tr>";
6817
-    	} else {
6818
-    		$new_view = substr_replace($view,'1',4,1);
6819
-    		echo "
6804
+            if (is_array($results)) {
6805
+                for($j = 0 ; $j < count($results) ; $j++) {
6806
+                    echo "<tr>";
6807
+                    echo "<td class='content'>".$results[$j]."</td>";
6808
+                    echo"</tr>";
6809
+                }
6810
+            } else {
6811
+                echo "<tr>";
6812
+                echo "<td><center>".get_lang('NoResult')."</center></td>";
6813
+                echo"</tr>";
6814
+            }
6815
+            echo "</table>";
6816
+            echo "</td></tr>";
6817
+        } else {
6818
+            $new_view = substr_replace($view,'1',4,1);
6819
+            echo "
6820 6820
                 <tr>
6821 6821
                     <td valign='top'>
6822 6822
                     +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('DocumentsAccess')."</a>
6823 6823
                     </td>
6824 6824
                 </tr>
6825 6825
             ";
6826
-    	}
6826
+        }
6827 6827
     }
6828 6828
 
6829 6829
     /**
@@ -6880,43 +6880,43 @@  discard block
 block discarded – undo
6880 6880
      */
6881 6881
     public function display_login_tracking_info($view, $user_id, $course_id, $session_id = 0)
6882 6882
     {
6883
-    	$MonthsLong = $GLOBALS['MonthsLong'];
6884
-    	$track_access_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
6885
-
6886
-    	// protected data
6887
-    	$user_id    = intval($user_id);
6888
-    	$session_id = intval($session_id);
6889
-    	$course_id  = intval($course_id);
6890
-
6891
-    	$tempView = $view;
6892
-    	if (substr($view,0,1) == '1') {
6893
-    		$new_view = substr_replace($view,'0',0,1);
6894
-    		$title[1]= get_lang('LoginsAndAccessTools').get_lang('LoginsDetails');
6895
-    		$sql = "SELECT UNIX_TIMESTAMP(access_date), count(access_date)
6883
+        $MonthsLong = $GLOBALS['MonthsLong'];
6884
+        $track_access_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
6885
+
6886
+        // protected data
6887
+        $user_id    = intval($user_id);
6888
+        $session_id = intval($session_id);
6889
+        $course_id  = intval($course_id);
6890
+
6891
+        $tempView = $view;
6892
+        if (substr($view,0,1) == '1') {
6893
+            $new_view = substr_replace($view,'0',0,1);
6894
+            $title[1]= get_lang('LoginsAndAccessTools').get_lang('LoginsDetails');
6895
+            $sql = "SELECT UNIX_TIMESTAMP(access_date), count(access_date)
6896 6896
                     FROM $track_access_table
6897 6897
                     WHERE access_user_id = $user_id
6898 6898
                     AND c_id = $course_id
6899 6899
                     AND access_session_id = $session_id
6900 6900
                     GROUP BY YEAR(access_date),MONTH(access_date)
6901 6901
                     ORDER BY YEAR(access_date),MONTH(access_date) ASC";
6902
-    		//$results = getManyResults2Col($sql);
6903
-    		$results = getManyResults3Col($sql);
6904
-    		$title_line= get_lang('LoginsTitleMonthColumn').';'.get_lang('LoginsTitleCountColumn')."\n";
6905
-    		$line='';
6906
-    		$total = 0;
6907
-    		if (is_array($results)) {
6908
-    			for($j = 0 ; $j < count($results) ; $j++) {
6909
-    				$line .= $results[$j][0].';'.$results[$j][1]."\n";
6910
-    				$total = $total + $results[$j][1];
6911
-    			}
6912
-    			$line .= get_lang('Total').";".$total."\n";
6913
-    		} else {
6914
-    			$line= get_lang('NoResult')."</center></td>";
6915
-    		}
6916
-    	} else {
6917
-    		$new_view = substr_replace($view,'1',0,1);
6918
-    	}
6919
-    	return array($title_line, $line);
6902
+            //$results = getManyResults2Col($sql);
6903
+            $results = getManyResults3Col($sql);
6904
+            $title_line= get_lang('LoginsTitleMonthColumn').';'.get_lang('LoginsTitleCountColumn')."\n";
6905
+            $line='';
6906
+            $total = 0;
6907
+            if (is_array($results)) {
6908
+                for($j = 0 ; $j < count($results) ; $j++) {
6909
+                    $line .= $results[$j][0].';'.$results[$j][1]."\n";
6910
+                    $total = $total + $results[$j][1];
6911
+                }
6912
+                $line .= get_lang('Total').";".$total."\n";
6913
+            } else {
6914
+                $line= get_lang('NoResult')."</center></td>";
6915
+            }
6916
+        } else {
6917
+            $new_view = substr_replace($view,'1',0,1);
6918
+        }
6919
+        return array($title_line, $line);
6920 6920
     }
6921 6921
 
6922 6922
     /**
@@ -6929,67 +6929,67 @@  discard block
 block discarded – undo
6929 6929
      */
6930 6930
     public function display_exercise_tracking_info($view, $userId, $courseCode)
6931 6931
     {
6932
-    	global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES, $dateTimeFormatLong;
6932
+        global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES, $dateTimeFormatLong;
6933 6933
         $courseId = api_get_course_int_id($courseCode);
6934 6934
         $userId = intval($userId);
6935
-    	if (substr($view,1,1) == '1') {
6936
-    		$new_view = substr_replace($view,'0',1,1);
6937
-    		$title[1] = get_lang('ExercicesDetails');
6938
-    		$line = '';
6939
-    		$sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
6935
+        if (substr($view,1,1) == '1') {
6936
+            $new_view = substr_replace($view,'0',1,1);
6937
+            $title[1] = get_lang('ExercicesDetails');
6938
+            $line = '';
6939
+            $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
6940 6940
                     FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te
6941 6941
                     WHERE te.c_id = $courseId
6942 6942
                         AND te.exe_user_id = $userId
6943 6943
                         AND te.exe_exo_id = ce.id
6944 6944
                     ORDER BY ce.title ASC, te.exe_date ASC";
6945 6945
 
6946
-    		$hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
6946
+            $hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
6947 6947
                         FROM $TABLETRACK_HOTPOTATOES AS te
6948 6948
                         WHERE te.exe_user_id = '$userId' AND te.c_id = $courseId
6949 6949
                         ORDER BY te.c_id ASC, te.exe_date ASC";
6950 6950
 
6951
-    		$hpresults = StatsUtils::getManyResultsXCol($hpsql, 4);
6951
+            $hpresults = StatsUtils::getManyResultsXCol($hpsql, 4);
6952 6952
 
6953
-    		$NoTestRes = 0;
6954
-    		$NoHPTestRes = 0;
6953
+            $NoTestRes = 0;
6954
+            $NoHPTestRes = 0;
6955 6955
 
6956
-    		$results = StatsUtils::getManyResultsXCol($sql, 4);
6957
-    		$title_line = get_lang('ExercicesTitleExerciceColumn').";".get_lang('Date').';'.get_lang('ExercicesTitleScoreColumn')."\n";
6956
+            $results = StatsUtils::getManyResultsXCol($sql, 4);
6957
+            $title_line = get_lang('ExercicesTitleExerciceColumn').";".get_lang('Date').';'.get_lang('ExercicesTitleScoreColumn')."\n";
6958 6958
 
6959
-    		if (is_array($results)) {
6960
-    			for($i = 0; $i < sizeof($results); $i++)
6961
-    			{
6962
-    				$display_date = api_convert_and_format_date($results[$i][3], null, date_default_timezone_get());
6963
-    				$line .= $results[$i][0].";".$display_date.";".$results[$i][1]." / ".$results[$i][2]."\n";
6964
-    			}
6965
-    		} else {
6959
+            if (is_array($results)) {
6960
+                for($i = 0; $i < sizeof($results); $i++)
6961
+                {
6962
+                    $display_date = api_convert_and_format_date($results[$i][3], null, date_default_timezone_get());
6963
+                    $line .= $results[$i][0].";".$display_date.";".$results[$i][1]." / ".$results[$i][2]."\n";
6964
+                }
6965
+            } else {
6966 6966
                 // istvan begin
6967
-    			$NoTestRes = 1;
6968
-    		}
6969
-
6970
-    		// The Result of Tests
6971
-    		if (is_array($hpresults)) {
6972
-    			for($i = 0; $i < sizeof($hpresults); $i++) {
6973
-    				$title = GetQuizName($hpresults[$i][0],'');
6974
-
6975
-    				if ($title == '')
6976
-    				$title = basename($hpresults[$i][0]);
6977
-
6978
-    				$display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get());
6979
-
6980
-    				$line .= $title.';'.$display_date.';'.$hpresults[$i][1].'/'.$hpresults[$i][2]."\n";
6981
-    			}
6982
-    		} else {
6983
-    			$NoHPTestRes = 1;
6984
-    		}
6985
-
6986
-    		if ($NoTestRes == 1 && $NoHPTestRes == 1) {
6987
-    			$line=get_lang('NoResult');
6988
-    		}
6989
-    	} else {
6990
-    		$new_view = substr_replace($view,'1',1,1);
6991
-    	}
6992
-    	return array($title_line, $line);
6967
+                $NoTestRes = 1;
6968
+            }
6969
+
6970
+            // The Result of Tests
6971
+            if (is_array($hpresults)) {
6972
+                for($i = 0; $i < sizeof($hpresults); $i++) {
6973
+                    $title = GetQuizName($hpresults[$i][0],'');
6974
+
6975
+                    if ($title == '')
6976
+                    $title = basename($hpresults[$i][0]);
6977
+
6978
+                    $display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get());
6979
+
6980
+                    $line .= $title.';'.$display_date.';'.$hpresults[$i][1].'/'.$hpresults[$i][2]."\n";
6981
+                }
6982
+            } else {
6983
+                $NoHPTestRes = 1;
6984
+            }
6985
+
6986
+            if ($NoTestRes == 1 && $NoHPTestRes == 1) {
6987
+                $line=get_lang('NoResult');
6988
+            }
6989
+        } else {
6990
+            $new_view = substr_replace($view,'1',1,1);
6991
+        }
6992
+        return array($title_line, $line);
6993 6993
     }
6994 6994
 
6995 6995
     /**
@@ -6998,37 +6998,37 @@  discard block
 block discarded – undo
6998 6998
      */
6999 6999
     public function display_student_publications_tracking_info($view, $user_id, $course_id)
7000 7000
     {
7001
-    	global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK;
7001
+        global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK;
7002 7002
         $_course = api_get_course_info();
7003 7003
         $user_id = intval($user_id);
7004 7004
         $course_id = intval($course_id);
7005 7005
 
7006
-    	if (substr($view,2,1) == '1') {
7007
-    		$sql = "SELECT u.upload_date, w.title, w.author, w.url
7006
+        if (substr($view,2,1) == '1') {
7007
+            $sql = "SELECT u.upload_date, w.title, w.author, w.url
7008 7008
                     FROM $TABLETRACK_UPLOADS u , $TABLECOURSE_WORK w
7009 7009
                     WHERE
7010 7010
                         u.upload_work_id = w.id AND
7011 7011
                         u.upload_user_id = '$user_id' AND
7012 7012
                         u.c_id = '$course_id'
7013 7013
                     ORDER BY u.upload_date DESC";
7014
-    		$results = StatsUtils::getManyResultsXCol($sql,4);
7015
-
7016
-    		$title[1]=get_lang('WorksDetails');
7017
-    		$line='';
7018
-    		$title_line=get_lang('WorkTitle').";".get_lang('WorkAuthors').";".get_lang('Date')."\n";
7019
-
7020
-    		if (is_array($results)) {
7021
-    			for($j = 0 ; $j < count($results) ; $j++) {
7022
-    				$pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
7023
-    				$beautifulDate = api_convert_and_format_date($results[$j][0], null, date_default_timezone_get());
7024
-    				$line .= $results[$j][1].";".$results[$j][2].";".$beautifulDate."\n";
7025
-    			}
7026
-
7027
-    		} else {
7028
-    			$line= get_lang('NoResult');
7029
-    		}
7030
-    	}
7031
-    	return array($title_line, $line);
7014
+            $results = StatsUtils::getManyResultsXCol($sql,4);
7015
+
7016
+            $title[1]=get_lang('WorksDetails');
7017
+            $line='';
7018
+            $title_line=get_lang('WorkTitle').";".get_lang('WorkAuthors').";".get_lang('Date')."\n";
7019
+
7020
+            if (is_array($results)) {
7021
+                for($j = 0 ; $j < count($results) ; $j++) {
7022
+                    $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
7023
+                    $beautifulDate = api_convert_and_format_date($results[$j][0], null, date_default_timezone_get());
7024
+                    $line .= $results[$j][1].";".$results[$j][2].";".$beautifulDate."\n";
7025
+                }
7026
+
7027
+            } else {
7028
+                $line= get_lang('NoResult');
7029
+            }
7030
+        }
7031
+        return array($title_line, $line);
7032 7032
     }
7033 7033
 
7034 7034
     /**
@@ -7037,32 +7037,32 @@  discard block
 block discarded – undo
7037 7037
      */
7038 7038
     public function display_links_tracking_info($view, $userId, $courseCode)
7039 7039
     {
7040
-    	global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
7040
+        global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
7041 7041
         $courseId = api_get_course_int_id($courseCode);
7042 7042
         $userId = intval($userId);
7043 7043
         $line = null;
7044
-    	if (substr($view,3,1) == '1') {
7045
-    		$new_view = substr_replace($view,'0',3,1);
7046
-    		$title[1]=get_lang('LinksDetails');
7047
-    		$sql = "SELECT cl.title, cl.url
7044
+        if (substr($view,3,1) == '1') {
7045
+            $new_view = substr_replace($view,'0',3,1);
7046
+            $title[1]=get_lang('LinksDetails');
7047
+            $sql = "SELECT cl.title, cl.url
7048 7048
                         FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
7049 7049
                         WHERE sl.links_link_id = cl.id
7050 7050
                             AND sl.c_id = $courseId
7051 7051
                             AND sl.links_user_id = $userId
7052 7052
                         GROUP BY cl.title, cl.url";
7053
-    		$results = StatsUtils::getManyResults2Col($sql);
7054
-    		$title_line= get_lang('LinksTitleLinkColumn')."\n";
7055
-    		if (is_array($results)) {
7056
-    			for ($j = 0 ; $j < count($results) ; $j++) {
7057
-    				$line .= $results[$j][0]."\n";
7058
-    			}
7059
-    		} else {
7060
-    			$line=get_lang('NoResult');
7061
-    		}
7062
-    	} else {
7063
-    		$new_view = substr_replace($view,'1',3,1);
7064
-    	}
7065
-    	return array($title_line, $line);
7053
+            $results = StatsUtils::getManyResults2Col($sql);
7054
+            $title_line= get_lang('LinksTitleLinkColumn')."\n";
7055
+            if (is_array($results)) {
7056
+                for ($j = 0 ; $j < count($results) ; $j++) {
7057
+                    $line .= $results[$j][0]."\n";
7058
+                }
7059
+            } else {
7060
+                $line=get_lang('NoResult');
7061
+            }
7062
+        } else {
7063
+            $new_view = substr_replace($view,'1',3,1);
7064
+        }
7065
+        return array($title_line, $line);
7066 7066
     }
7067 7067
 
7068 7068
     /**
@@ -7075,38 +7075,38 @@  discard block
 block discarded – undo
7075 7075
      */
7076 7076
     public function display_document_tracking_info($view, $user_id, $courseCode, $session_id = 0)
7077 7077
     {
7078
-    	// protect data
7079
-    	$user_id     = intval($user_id);
7078
+        // protect data
7079
+        $user_id     = intval($user_id);
7080 7080
         $courseId = api_get_course_int_id($courseCode);
7081
-    	$session_id = intval($session_id);
7081
+        $session_id = intval($session_id);
7082 7082
 
7083
-    	$downloads_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
7083
+        $downloads_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
7084 7084
 
7085
-    	if (substr($view,4,1) == '1') {
7086
-    		$new_view = substr_replace($view,'0',4,1);
7087
-    		$title[1]= get_lang('DocumentsDetails');
7085
+        if (substr($view,4,1) == '1') {
7086
+            $new_view = substr_replace($view,'0',4,1);
7087
+            $title[1]= get_lang('DocumentsDetails');
7088 7088
 
7089
-    		$sql = "SELECT down_doc_path
7089
+            $sql = "SELECT down_doc_path
7090 7090
                         FROM $downloads_table
7091 7091
                         WHERE c_id = $courseId
7092 7092
                             AND down_user_id = $user_id
7093 7093
                             AND down_session_id = $session_id
7094 7094
                         GROUP BY down_doc_path";
7095 7095
 
7096
-    		$results = StatsUtils::getManyResults1Col($sql);
7097
-    		$title_line = get_lang('DocumentsTitleDocumentColumn')."\n";
7096
+            $results = StatsUtils::getManyResults1Col($sql);
7097
+            $title_line = get_lang('DocumentsTitleDocumentColumn')."\n";
7098 7098
             $line = null;
7099
-    		if (is_array($results)) {
7100
-    			for ($j = 0 ; $j < count($results) ; $j++) {
7101
-    				$line .= $results[$j]."\n";
7102
-    			}
7103
-    		} else {
7104
-    			$line = get_lang('NoResult');
7105
-    		}
7106
-    	} else {
7107
-    		$new_view = substr_replace($view,'1',4,1);
7108
-    	}
7109
-    	return array($title_line, $line);
7099
+            if (is_array($results)) {
7100
+                for ($j = 0 ; $j < count($results) ; $j++) {
7101
+                    $line .= $results[$j]."\n";
7102
+                }
7103
+            } else {
7104
+                $line = get_lang('NoResult');
7105
+            }
7106
+        } else {
7107
+            $new_view = substr_replace($view,'1',4,1);
7108
+        }
7109
+        return array($title_line, $line);
7110 7110
     }
7111 7111
 
7112 7112
     /**
Please login to merge, or discard this patch.
main/inc/lib/add_courses_to_session_functions.lib.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -6,47 +6,47 @@  discard block
 block discarded – undo
6 6
  */
7 7
 class AddCourseToSession
8 8
 {
9
-	/**
10
-	 * Searches a course, given a search string and a type of search box
11
-	 * @param string $needle Search string
12
-	 * @param string $type Type of search box ('single' or anything else)
13
-	 * @return string XajaxResponse
14
-	 * @assert ('abc', 'single') !== null
15
-	 * @assert ('abc', 'multiple') !== null
16
-	 */
17
-	public static function search_courses($needle, $type)
18
-	{
19
-		global $tbl_session_rel_course, $id_session;
9
+    /**
10
+     * Searches a course, given a search string and a type of search box
11
+     * @param string $needle Search string
12
+     * @param string $type Type of search box ('single' or anything else)
13
+     * @return string XajaxResponse
14
+     * @assert ('abc', 'single') !== null
15
+     * @assert ('abc', 'multiple') !== null
16
+     */
17
+    public static function search_courses($needle, $type)
18
+    {
19
+        global $tbl_session_rel_course, $id_session;
20 20
         $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
21
-		$course_title = null;
22
-		$xajax_response = new xajaxResponse();
23
-		$return = '';
24
-		if(!empty($needle) && !empty($type)) {
25
-			// xajax send utf8 datas... datas in db can be non-utf8 datas
26
-			$charset = api_get_system_encoding();
27
-			$needle = api_convert_encoding($needle, $charset, 'utf-8');
21
+        $course_title = null;
22
+        $xajax_response = new xajaxResponse();
23
+        $return = '';
24
+        if(!empty($needle) && !empty($type)) {
25
+            // xajax send utf8 datas... datas in db can be non-utf8 datas
26
+            $charset = api_get_system_encoding();
27
+            $needle = api_convert_encoding($needle, $charset, 'utf-8');
28 28
 
29
-			$cond_course_code = '';
30
-			if (!empty($id_session)) {
31
-				$id_session = intval($id_session);
32
-				// check course_code from session_rel_course table
33
-				$sql = 'SELECT c_id FROM '.$tbl_session_rel_course.'
29
+            $cond_course_code = '';
30
+            if (!empty($id_session)) {
31
+                $id_session = intval($id_session);
32
+                // check course_code from session_rel_course table
33
+                $sql = 'SELECT c_id FROM '.$tbl_session_rel_course.'
34 34
 						WHERE session_id = '.$id_session;
35
-				$res = Database::query($sql);
36
-				$course_codes = '';
37
-				if (Database::num_rows($res) > 0) {
38
-					while ($row = Database::fetch_row($res)) {
39
-						$course_codes .= '\''.$row[0].'\',';
40
-					}
41
-					$course_codes = substr($course_codes,0,(strlen($course_codes)-1));
35
+                $res = Database::query($sql);
36
+                $course_codes = '';
37
+                if (Database::num_rows($res) > 0) {
38
+                    while ($row = Database::fetch_row($res)) {
39
+                        $course_codes .= '\''.$row[0].'\',';
40
+                    }
41
+                    $course_codes = substr($course_codes,0,(strlen($course_codes)-1));
42 42
 
43
-					$cond_course_code = ' AND course.id NOT IN('.$course_codes.') ';
44
-				}
45
-			}
43
+                    $cond_course_code = ' AND course.id NOT IN('.$course_codes.') ';
44
+                }
45
+            }
46 46
 
47
-			if ($type=='single') {
48
-				// search users where username or firstname or lastname begins likes $needle
49
-				$sql = 'SELECT
47
+            if ($type=='single') {
48
+                // search users where username or firstname or lastname begins likes $needle
49
+                $sql = 'SELECT
50 50
 							course.code,
51 51
 						 	course.visual_code,
52 52
 						 	course.title,
@@ -58,21 +58,21 @@  discard block
 block discarded – undo
58 58
 						WHERE
59 59
 							course.visual_code LIKE "'.$needle.'%" OR
60 60
 							course.title LIKE "'.$needle.'%"';
61
-			} else {
62
-				$sql = 'SELECT course.code, course.visual_code, course.title
61
+            } else {
62
+                $sql = 'SELECT course.code, course.visual_code, course.title
63 63
 						FROM '.$tbl_course.' course
64 64
 						WHERE
65 65
 							course.visual_code LIKE "'.$needle.'%" '.$cond_course_code.'
66 66
 						ORDER BY course.code ';
67
-			}
67
+            }
68 68
 
69
-			if (api_is_multiple_url_enabled()) {
70
-				$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
71
-				$access_url_id = api_get_current_access_url_id();
72
-				if ($access_url_id != -1){
69
+            if (api_is_multiple_url_enabled()) {
70
+                $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
71
+                $access_url_id = api_get_current_access_url_id();
72
+                if ($access_url_id != -1){
73 73
 
74
-					if ($type=='single') {
75
-						$sql = 'SELECT
74
+                    if ($type=='single') {
75
+                        $sql = 'SELECT
76 76
 						            course.code,
77 77
 						            course.visual_code,
78 78
 						            course.title,
@@ -87,42 +87,42 @@  discard block
 block discarded – undo
87 87
 									access_url_id = '.$access_url_id.' AND
88 88
 									(course.visual_code LIKE "'.$needle.'%" OR
89 89
 									course.title LIKE "'.$needle.'%" )';
90
-					} else {
91
-						$sql = 'SELECT course.code, course.visual_code, course.title
90
+                    } else {
91
+                        $sql = 'SELECT course.code, course.visual_code, course.title
92 92
 								FROM '.$tbl_course.' course, '.$tbl_course_rel_access_url.' url_course
93 93
 								WHERE
94 94
 									url_course.c_id = course.id AND
95 95
 									access_url_id = '.$access_url_id.' AND
96 96
 									course.visual_code LIKE "'.$needle.'%" '.$cond_course_code.'
97 97
 								ORDER BY course.code ';
98
-					}
99
-				}
100
-			}
98
+                    }
99
+                }
100
+            }
101 101
 
102
-			$rs = Database::query($sql);
103
-			$course_list = array();
104
-			if ($type=='single') {
102
+            $rs = Database::query($sql);
103
+            $course_list = array();
104
+            if ($type=='single') {
105 105
 
106
-				while($course = Database :: fetch_array($rs)) {
107
-					$course_list[] = $course['code'];
108
-					$course_title=str_replace("'","\'",$course_title);
109
-					$return .= '<a href="javascript: void(0);" onclick="javascript: add_course_to_session(\''.$course['code'].'\',\''.$course_title.' ('.$course['visual_code'].')'.'\')">'.$course['title'].' ('.$course['visual_code'].')</a><br />';
110
-				}
111
-				$xajax_response -> addAssign('ajax_list_courses_single','innerHTML',api_utf8_encode($return));
112
-			} else {
113
-				$return .= '<select id="origin" name="NoSessionCoursesList[]" multiple="multiple" size="20" style="width:340px;">';
114
-				while($course = Database :: fetch_array($rs)) {
115
-					$course_list[] = $course['code'];
116
-					$course_title=str_replace("'","\'",$course_title);
117
-					$return .= '<option value="'.$course['code'].'" title="'.htmlspecialchars($course['title'].' ('.$course['visual_code'].')',ENT_QUOTES).'">'.$course['title'].' ('.$course['visual_code'].')</option>';
118
-				}
119
-				$return .= '</select>';
106
+                while($course = Database :: fetch_array($rs)) {
107
+                    $course_list[] = $course['code'];
108
+                    $course_title=str_replace("'","\'",$course_title);
109
+                    $return .= '<a href="javascript: void(0);" onclick="javascript: add_course_to_session(\''.$course['code'].'\',\''.$course_title.' ('.$course['visual_code'].')'.'\')">'.$course['title'].' ('.$course['visual_code'].')</a><br />';
110
+                }
111
+                $xajax_response -> addAssign('ajax_list_courses_single','innerHTML',api_utf8_encode($return));
112
+            } else {
113
+                $return .= '<select id="origin" name="NoSessionCoursesList[]" multiple="multiple" size="20" style="width:340px;">';
114
+                while($course = Database :: fetch_array($rs)) {
115
+                    $course_list[] = $course['code'];
116
+                    $course_title=str_replace("'","\'",$course_title);
117
+                    $return .= '<option value="'.$course['code'].'" title="'.htmlspecialchars($course['title'].' ('.$course['visual_code'].')',ENT_QUOTES).'">'.$course['title'].' ('.$course['visual_code'].')</option>';
118
+                }
119
+                $return .= '</select>';
120 120
 
121
-				$xajax_response -> addAssign('ajax_list_courses_multiple','innerHTML',api_utf8_encode($return));
122
-			}
123
-		}
124
-		$_SESSION['course_list'] = $course_list;
121
+                $xajax_response -> addAssign('ajax_list_courses_multiple','innerHTML',api_utf8_encode($return));
122
+            }
123
+        }
124
+        $_SESSION['course_list'] = $course_list;
125 125
 
126
-		return $xajax_response;
127
-	}
126
+        return $xajax_response;
127
+    }
128 128
 }
Please login to merge, or discard this patch.
main/inc/lib/kses-0.2.2/kses_original.php 1 patch
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 
32 32
 
33 33
 function kses($string, $allowed_html, $allowed_protocols =
34
-               array('http', 'https', 'ftp', 'news', 'nntp', 'telnet',
35
-                     'gopher', 'mailto'))
34
+                array('http', 'https', 'ftp', 'news', 'nntp', 'telnet',
35
+                        'gopher', 'mailto'))
36 36
 ###############################################################################
37 37
 # This function makes sure that only the allowed HTML element names, attribute
38 38
 # names and attribute values plus only sane HTML entities will occur in
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
 # call this function.
41 41
 ###############################################################################
42 42
 {
43
-  $string = kses_no_null($string);
44
-  $string = kses_js_entities($string);
45
-  $string = kses_normalize_entities($string);
46
-  $string = kses_hook($string);
47
-  $allowed_html_fixed = kses_array_lc($allowed_html);
48
-  return kses_split($string, $allowed_html_fixed, $allowed_protocols);
43
+    $string = kses_no_null($string);
44
+    $string = kses_js_entities($string);
45
+    $string = kses_normalize_entities($string);
46
+    $string = kses_hook($string);
47
+    $allowed_html_fixed = kses_array_lc($allowed_html);
48
+    return kses_split($string, $allowed_html_fixed, $allowed_protocols);
49 49
 } # function kses
50 50
 
51 51
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 # You add any kses hooks here.
55 55
 ###############################################################################
56 56
 {
57
-  return $string;
57
+    return $string;
58 58
 } # function kses_hook
59 59
 
60 60
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 # This function returns kses' version number.
64 64
 ###############################################################################
65 65
 {
66
-  return '0.2.2';
66
+    return '0.2.2';
67 67
 } # function kses_version
68 68
 
69 69
 
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
 # matches stray ">" characters.
74 74
 ###############################################################################
75 75
 {
76
-  return preg_replace('%(<'.   # EITHER: <
77
-                      '[^>]*'. # things that aren't >
78
-                      '(>|$)'. # > or end of string
79
-                      '|>)%e', # OR: just a >
80
-                      "kses_split2('\\1', \$allowed_html, ".
81
-                      '$allowed_protocols)',
82
-                      $string);
76
+    return preg_replace('%(<'.   # EITHER: <
77
+                        '[^>]*'. # things that aren't >
78
+                        '(>|$)'. # > or end of string
79
+                        '|>)%e', # OR: just a >
80
+                        "kses_split2('\\1', \$allowed_html, ".
81
+                        '$allowed_protocols)',
82
+                        $string);
83 83
 } # function kses_split
84 84
 
85 85
 
@@ -91,30 +91,30 @@  discard block
 block discarded – undo
91 91
 # attribute list.
92 92
 ###############################################################################
93 93
 {
94
-  $string = kses_stripslashes($string);
94
+    $string = kses_stripslashes($string);
95 95
 
96
-  if (substr($string, 0, 1) != '<')
96
+    if (substr($string, 0, 1) != '<')
97 97
     return '&gt;';
98 98
     # It matched a ">" character
99 99
 
100
-  if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
100
+    if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
101 101
     return '';
102 102
     # It's seriously malformed
103 103
 
104
-  $slash = trim($matches[1]);
105
-  $elem = $matches[2];
106
-  $attrlist = $matches[3];
104
+    $slash = trim($matches[1]);
105
+    $elem = $matches[2];
106
+    $attrlist = $matches[3];
107 107
 
108
-  if (!@isset($allowed_html[strtolower($elem)]))
108
+    if (!@isset($allowed_html[strtolower($elem)]))
109 109
     return '';
110 110
     # They are using a not allowed HTML element
111 111
 
112
-  if ($slash != '')
112
+    if ($slash != '')
113 113
     return "<$slash$elem>";
114
-  # No attributes are allowed for closing elements
114
+    # No attributes are allowed for closing elements
115 115
 
116
-  return kses_attr("$slash$elem", $attrlist, $allowed_html,
117
-                   $allowed_protocols);
116
+    return kses_attr("$slash$elem", $attrlist, $allowed_html,
117
+                    $allowed_protocols);
118 118
 } # function kses_split2
119 119
 
120 120
 
@@ -130,56 +130,56 @@  discard block
 block discarded – undo
130 130
 {
131 131
 # Is there a closing XHTML slash at the end of the attributes?
132 132
 
133
-  $xhtml_slash = '';
134
-  if (preg_match('%\s/\s*$%', $attr))
133
+    $xhtml_slash = '';
134
+    if (preg_match('%\s/\s*$%', $attr))
135 135
     $xhtml_slash = ' /';
136 136
 
137 137
 # Are any attributes allowed at all for this element?
138 138
 
139
-  if (@count($allowed_html[strtolower($element)]) == 0)
139
+    if (@count($allowed_html[strtolower($element)]) == 0)
140 140
     return "<$element$xhtml_slash>";
141 141
 
142 142
 # Split it
143 143
 
144
-  $attrarr = kses_hair($attr, $allowed_protocols);
144
+    $attrarr = kses_hair($attr, $allowed_protocols);
145 145
 
146 146
 # Go through $attrarr, and save the allowed attributes for this element
147 147
 # in $attr2
148 148
 
149
-  $attr2 = '';
149
+    $attr2 = '';
150 150
 
151
-  foreach ($attrarr as $arreach)
152
-  {
151
+    foreach ($attrarr as $arreach)
152
+    {
153 153
     if (!@isset($allowed_html[strtolower($element)]
154 154
                             [strtolower($arreach['name'])]))
155
-      continue; # the attribute is not allowed
155
+        continue; # the attribute is not allowed
156 156
 
157 157
     $current = $allowed_html[strtolower($element)]
158 158
                             [strtolower($arreach['name'])];
159 159
 
160 160
     if (!is_array($current))
161
-      $attr2 .= ' '.$arreach['whole'];
161
+        $attr2 .= ' '.$arreach['whole'];
162 162
     # there are no checks
163 163
 
164 164
     else
165 165
     {
166 166
     # there are some checks
167
-      $ok = true;
168
-      foreach ($current as $currkey => $currval)
167
+        $ok = true;
168
+        foreach ($current as $currkey => $currval)
169 169
         if (!kses_check_attr_val($arreach['value'], $arreach['vless'],
170
-                                 $currkey, $currval))
170
+                                    $currkey, $currval))
171 171
         { $ok = false; break; }
172 172
 
173
-      if ($ok)
173
+        if ($ok)
174 174
         $attr2 .= ' '.$arreach['whole']; # it passed them
175 175
     } # if !is_array($current)
176
-  } # foreach
176
+    } # foreach
177 177
 
178 178
 # Remove any "<" or ">" characters
179 179
 
180
-  $attr2 = preg_replace('/[<>]/', '', $attr2);
180
+    $attr2 = preg_replace('/[<>]/', '', $attr2);
181 181
 
182
-  return "<$element$attr2$xhtml_slash>";
182
+    return "<$element$attr2$xhtml_slash>";
183 183
 } # function kses_attr
184 184
 
185 185
 
@@ -193,96 +193,96 @@  discard block
 block discarded – undo
193 193
 # from attribute values.
194 194
 ###############################################################################
195 195
 {
196
-  $attrarr = array();
197
-  $mode = 0;
198
-  $attrname = '';
196
+    $attrarr = array();
197
+    $mode = 0;
198
+    $attrname = '';
199 199
 
200 200
 # Loop through the whole attribute list
201 201
 
202
-  while (strlen($attr) != 0)
203
-  {
202
+    while (strlen($attr) != 0)
203
+    {
204 204
     $working = 0; # Was the last operation successful?
205 205
 
206 206
     switch ($mode)
207 207
     {
208
-      case 0: # attribute name, href for instance
208
+        case 0: # attribute name, href for instance
209 209
 
210 210
         if (preg_match('/^([-a-zA-Z]+)/', $attr, $match))
211 211
         {
212
-          $attrname = $match[1];
213
-          $working = $mode = 1;
214
-          $attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
212
+            $attrname = $match[1];
213
+            $working = $mode = 1;
214
+            $attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
215 215
         }
216 216
 
217 217
         break;
218 218
 
219
-      case 1: # equals sign or valueless ("selected")
219
+        case 1: # equals sign or valueless ("selected")
220 220
 
221 221
         if (preg_match('/^\s*=\s*/', $attr)) # equals sign
222 222
         {
223
-          $working = 1; $mode = 2;
224
-          $attr = preg_replace('/^\s*=\s*/', '', $attr);
225
-          break;
223
+            $working = 1; $mode = 2;
224
+            $attr = preg_replace('/^\s*=\s*/', '', $attr);
225
+            break;
226 226
         }
227 227
 
228 228
         if (preg_match('/^\s+/', $attr)) # valueless
229 229
         {
230
-          $working = 1; $mode = 0;
231
-          $attrarr[] = array
230
+            $working = 1; $mode = 0;
231
+            $attrarr[] = array
232 232
                         ('name'  => $attrname,
233
-                         'value' => '',
234
-                         'whole' => $attrname,
235
-                         'vless' => 'y');
236
-          $attr = preg_replace('/^\s+/', '', $attr);
233
+                            'value' => '',
234
+                            'whole' => $attrname,
235
+                            'vless' => 'y');
236
+            $attr = preg_replace('/^\s+/', '', $attr);
237 237
         }
238 238
 
239 239
         break;
240 240
 
241
-      case 2: # attribute value, a URL after href= for instance
241
+        case 2: # attribute value, a URL after href= for instance
242 242
 
243 243
         if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match))
244
-         # "value"
244
+            # "value"
245 245
         {
246
-          $thisval = kses_bad_protocol($match[1], $allowed_protocols);
246
+            $thisval = kses_bad_protocol($match[1], $allowed_protocols);
247 247
 
248
-          $attrarr[] = array
248
+            $attrarr[] = array
249 249
                         ('name'  => $attrname,
250
-                         'value' => $thisval,
251
-                         'whole' => "$attrname=\"$thisval\"",
252
-                         'vless' => 'n');
253
-          $working = 1; $mode = 0;
254
-          $attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
255
-          break;
250
+                            'value' => $thisval,
251
+                            'whole' => "$attrname=\"$thisval\"",
252
+                            'vless' => 'n');
253
+            $working = 1; $mode = 0;
254
+            $attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
255
+            break;
256 256
         }
257 257
 
258 258
         if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match))
259
-         # 'value'
259
+            # 'value'
260 260
         {
261
-          $thisval = kses_bad_protocol($match[1], $allowed_protocols);
261
+            $thisval = kses_bad_protocol($match[1], $allowed_protocols);
262 262
 
263
-          $attrarr[] = array
263
+            $attrarr[] = array
264 264
                         ('name'  => $attrname,
265
-                         'value' => $thisval,
266
-                         'whole' => "$attrname='$thisval'",
267
-                         'vless' => 'n');
268
-          $working = 1; $mode = 0;
269
-          $attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
270
-          break;
265
+                            'value' => $thisval,
266
+                            'whole' => "$attrname='$thisval'",
267
+                            'vless' => 'n');
268
+            $working = 1; $mode = 0;
269
+            $attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
270
+            break;
271 271
         }
272 272
 
273 273
         if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match))
274
-         # value
274
+            # value
275 275
         {
276
-          $thisval = kses_bad_protocol($match[1], $allowed_protocols);
276
+            $thisval = kses_bad_protocol($match[1], $allowed_protocols);
277 277
 
278
-          $attrarr[] = array
278
+            $attrarr[] = array
279 279
                         ('name'  => $attrname,
280
-                         'value' => $thisval,
281
-                         'whole' => "$attrname=\"$thisval\"",
282
-                         'vless' => 'n');
283
-                         # We add quotes to conform to W3C's HTML spec.
284
-          $working = 1; $mode = 0;
285
-          $attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
280
+                            'value' => $thisval,
281
+                            'whole' => "$attrname=\"$thisval\"",
282
+                            'vless' => 'n');
283
+                            # We add quotes to conform to W3C's HTML spec.
284
+            $working = 1; $mode = 0;
285
+            $attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
286 286
         }
287 287
 
288 288
         break;
@@ -290,21 +290,21 @@  discard block
 block discarded – undo
290 290
 
291 291
     if ($working == 0) # not well formed, remove and try again
292 292
     {
293
-      $attr = kses_html_error($attr);
294
-      $mode = 0;
293
+        $attr = kses_html_error($attr);
294
+        $mode = 0;
295 295
     }
296
-  } # while
296
+    } # while
297 297
 
298
-  if ($mode == 1)
299
-  # special case, for when the attribute list ends with a valueless
300
-  # attribute like "selected"
298
+    if ($mode == 1)
299
+    # special case, for when the attribute list ends with a valueless
300
+    # attribute like "selected"
301 301
     $attrarr[] = array
302
-                  ('name'  => $attrname,
303
-                   'value' => '',
304
-                   'whole' => $attrname,
305
-                   'vless' => 'y');
302
+                    ('name'  => $attrname,
303
+                    'value' => '',
304
+                    'whole' => $attrname,
305
+                    'vless' => 'y');
306 306
 
307
-  return $attrarr;
307
+    return $attrarr;
308 308
 } # function kses_hair
309 309
 
310 310
 
@@ -315,10 +315,10 @@  discard block
 block discarded – undo
315 315
 # with even more checks to come soon.
316 316
 ###############################################################################
317 317
 {
318
-  $ok = true;
318
+    $ok = true;
319 319
 
320
-  switch (strtolower($checkname))
321
-  {
320
+    switch (strtolower($checkname))
321
+    {
322 322
     case 'maxlen':
323 323
     # The maxlen check makes sure that the attribute value has a length not
324 324
     # greater than the given value. This can be used to avoid Buffer Overflows
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 
327 327
       if (strlen($value) > $checkvalue)
328 328
         $ok = false;
329
-      break;
329
+        break;
330 330
 
331 331
     case 'minlen':
332 332
     # The minlen check makes sure that the attribute value has a length not
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 
335 335
       if (strlen($value) < $checkvalue)
336 336
         $ok = false;
337
-      break;
337
+        break;
338 338
 
339 339
     case 'maxval':
340 340
     # The maxval check does two things: it checks that the attribute value is
@@ -345,9 +345,9 @@  discard block
 block discarded – undo
345 345
 
346 346
       if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
347 347
         $ok = false;
348
-      if ($value > $checkvalue)
348
+        if ($value > $checkvalue)
349 349
         $ok = false;
350
-      break;
350
+        break;
351 351
 
352 352
     case 'minval':
353 353
     # The minval check checks that the attribute value is a positive integer,
@@ -355,9 +355,9 @@  discard block
 block discarded – undo
355 355
 
356 356
       if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
357 357
         $ok = false;
358
-      if ($value < $checkvalue)
358
+        if ($value < $checkvalue)
359 359
         $ok = false;
360
-      break;
360
+        break;
361 361
 
362 362
     case 'valueless':
363 363
     # The valueless check checks if the attribute has a value
@@ -367,10 +367,10 @@  discard block
 block discarded – undo
367 367
 
368 368
       if (strtolower($checkvalue) != $vless)
369 369
         $ok = false;
370
-      break;
371
-  } # switch
370
+        break;
371
+    } # switch
372 372
 
373
-  return $ok;
373
+    return $ok;
374 374
 } # function kses_check_attr_val
375 375
 
376 376
 
@@ -382,17 +382,17 @@  discard block
 block discarded – undo
382 382
 # fooled by a string like "javascript:javascript:alert(57)".
383 383
 ###############################################################################
384 384
 {
385
-  $string = kses_no_null($string);
386
-  $string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature"
387
-  $string2 = $string.'a';
385
+    $string = kses_no_null($string);
386
+    $string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature"
387
+    $string2 = $string.'a';
388 388
 
389
-  while ($string != $string2)
390
-  {
389
+    while ($string != $string2)
390
+    {
391 391
     $string2 = $string;
392 392
     $string = kses_bad_protocol_once($string, $allowed_protocols);
393
-  } # while
393
+    } # while
394 394
 
395
-  return $string;
395
+    return $string;
396 396
 } # function kses_bad_protocol
397 397
 
398 398
 
@@ -401,10 +401,10 @@  discard block
 block discarded – undo
401 401
 # This function removes any NULL characters in $string.
402 402
 ###############################################################################
403 403
 {
404
-  $string = preg_replace('/\0+/', '', $string);
405
-  $string = preg_replace('/(\\\\0)+/', '', $string);
404
+    $string = preg_replace('/\0+/', '', $string);
405
+    $string = preg_replace('/(\\\\0)+/', '', $string);
406 406
 
407
-  return $string;
407
+    return $string;
408 408
 } # function kses_no_null
409 409
 
410 410
 
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 # preg_replace(//e) seems to require this.
416 416
 ###############################################################################
417 417
 {
418
-  return preg_replace('%\\\\"%', '"', $string);
418
+    return preg_replace('%\\\\"%', '"', $string);
419 419
 } # function kses_stripslashes
420 420
 
421 421
 
@@ -424,21 +424,21 @@  discard block
 block discarded – undo
424 424
 # This function goes through an array, and changes the keys to all lower case.
425 425
 ###############################################################################
426 426
 {
427
-  $outarray = array();
427
+    $outarray = array();
428 428
 
429
-  foreach ($inarray as $inkey => $inval)
430
-  {
429
+    foreach ($inarray as $inkey => $inval)
430
+    {
431 431
     $outkey = strtolower($inkey);
432 432
     $outarray[$outkey] = array();
433 433
 
434 434
     foreach ($inval as $inkey2 => $inval2)
435 435
     {
436
-      $outkey2 = strtolower($inkey2);
437
-      $outarray[$outkey][$outkey2] = $inval2;
436
+        $outkey2 = strtolower($inkey2);
437
+        $outarray[$outkey][$outkey2] = $inval2;
438 438
     } # foreach $inval
439
-  } # foreach $inarray
439
+    } # foreach $inarray
440 440
 
441
-  return $outarray;
441
+    return $outarray;
442 442
 } # function kses_array_lc
443 443
 
444 444
 
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 # Netscape 4.
449 449
 ###############################################################################
450 450
 {
451
-  return preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);
451
+    return preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);
452 452
 } # function kses_js_entities
453 453
 
454 454
 
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 # quotes and apostrophes as well.
460 460
 ###############################################################################
461 461
 {
462
-  return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string);
462
+    return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string);
463 463
 } # function kses_html_error
464 464
 
465 465
 
@@ -469,12 +469,12 @@  discard block
 block discarded – undo
469 469
 # handling whitespace and HTML entities.
470 470
 ###############################################################################
471 471
 {
472
-	$string2 = preg_split('/:|&#58;|&#x3a;/i', $string, 2);
473
-	if(isset($string2[1]) && !preg_match('%/\?%',$string2[0]))
474
-	{
475
-		$string = kses_bad_protocol_once2($string2[0],$allowed_protocols).trim($string2[1]);
476
-	}
477
-	return $string;
472
+    $string2 = preg_split('/:|&#58;|&#x3a;/i', $string, 2);
473
+    if(isset($string2[1]) && !preg_match('%/\?%',$string2[0]))
474
+    {
475
+        $string = kses_bad_protocol_once2($string2[0],$allowed_protocols).trim($string2[1]);
476
+    }
477
+    return $string;
478 478
 } # function kses_bad_protocol_once
479 479
 
480 480
 
@@ -484,24 +484,24 @@  discard block
 block discarded – undo
484 484
 # list or not, and returns different data depending on the answer.
485 485
 ###############################################################################
486 486
 {
487
-  $string2 = kses_decode_entities($string);
488
-  $string2 = preg_replace('/\s/', '', $string2);
489
-  $string2 = kses_no_null($string2);
490
-  $string2 = preg_replace('/\xad+/', '', $string2);
491
-   # deals with Opera "feature"
492
-  $string2 = strtolower($string2);
493
-
494
-  $allowed = false;
495
-  foreach ($allowed_protocols as $one_protocol)
487
+    $string2 = kses_decode_entities($string);
488
+    $string2 = preg_replace('/\s/', '', $string2);
489
+    $string2 = kses_no_null($string2);
490
+    $string2 = preg_replace('/\xad+/', '', $string2);
491
+    # deals with Opera "feature"
492
+    $string2 = strtolower($string2);
493
+
494
+    $allowed = false;
495
+    foreach ($allowed_protocols as $one_protocol)
496 496
     if (strtolower($one_protocol) == $string2)
497 497
     {
498
-      $allowed = true;
499
-      break;
498
+        $allowed = true;
499
+        break;
500 500
     }
501 501
 
502
-  if ($allowed)
502
+    if ($allowed)
503 503
     return "$string2:";
504
-  else
504
+    else
505 505
     return '';
506 506
 } # function kses_bad_protocol_once2
507 507
 
@@ -514,18 +514,18 @@  discard block
 block discarded – undo
514 514
 {
515 515
 # Disarm all entities by converting & to &amp;
516 516
 
517
-  $string = str_replace('&', '&amp;', $string);
517
+    $string = str_replace('&', '&amp;', $string);
518 518
 
519 519
 # Change back the allowed entities in our entity whitelist
520 520
 
521
-  $string = preg_replace('/&amp;([A-Za-z][A-Za-z0-9]{0,19});/',
522
-                         '&\\1;', $string);
523
-  $string = preg_replace('/&amp;#0*([0-9]{1,5});/e',
524
-                         'kses_normalize_entities2("\\1")', $string);
525
-  $string = preg_replace('/&amp;#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/',
526
-                         '&#\\1\\2;', $string);
521
+    $string = preg_replace('/&amp;([A-Za-z][A-Za-z0-9]{0,19});/',
522
+                            '&\\1;', $string);
523
+    $string = preg_replace('/&amp;#0*([0-9]{1,5});/e',
524
+                            'kses_normalize_entities2("\\1")', $string);
525
+    $string = preg_replace('/&amp;#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/',
526
+                            '&#\\1\\2;', $string);
527 527
 
528
-  return $string;
528
+    return $string;
529 529
 } # function kses_normalize_entities
530 530
 
531 531
 
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
 # and nothing more for &#number; entities.
536 536
 ###############################################################################
537 537
 {
538
-  return (($i > 65535) ? "&amp;#$i;" : "&#$i;");
538
+    return (($i > 65535) ? "&amp;#$i;" : "&#$i;");
539 539
 } # function kses_normalize_entities2
540 540
 
541 541
 
@@ -546,11 +546,11 @@  discard block
 block discarded – undo
546 546
 # URL protocol whitelisting system anyway.
547 547
 ###############################################################################
548 548
 {
549
-  $string = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $string);
550
-  $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', 'chr(hexdec("\\1"))',
551
-                         $string);
549
+    $string = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $string);
550
+    $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', 'chr(hexdec("\\1"))',
551
+                            $string);
552 552
 
553
-  return $string;
553
+    return $string;
554 554
 } # function kses_decode_entities
555 555
 
556 556
 ?>
Please login to merge, or discard this patch.
main/inc/lib/kses-0.2.2/kses.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
  * @return string
98 98
  */
99 99
 function kses($string, $allowed_html, $allowed_protocols =
100
-               array('http', 'https', 'ftp', 'news', 'nntp', 'telnet',
101
-                     'gopher', 'mailto'))
100
+                array('http', 'https', 'ftp', 'news', 'nntp', 'telnet',
101
+                        'gopher', 'mailto'))
102 102
 {
103 103
     $string = kses_no_null($string);
104 104
     $string = kses_js_entities($string);
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
     // No attributes are allowed for closing elements
219 219
 
220 220
     return kses_attr("$slash$elem", $attrlist, $allowed_html,
221
-                   $allowed_protocols);
221
+                    $allowed_protocols);
222 222
 }
223 223
 
224 224
 /**
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
     foreach ($attrarr as $arreach)
262 262
     {
263 263
         if (!@isset($allowed_html[strtolower($element)]
264
-                              [strtolower($arreach['name'])]))
264
+                                [strtolower($arreach['name'])]))
265 265
             continue; // the attribute is not allowed
266 266
 
267 267
         $current = $allowed_html[strtolower($element)]
268
-                              [strtolower($arreach['name'])];
268
+                                [strtolower($arreach['name'])];
269 269
         if ($current == '')
270 270
             continue; // the attribute is not allowed
271 271
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
             $ok = true;
280 280
             foreach ($current as $currkey => $currval)
281 281
                 if (!kses_check_attr_val($arreach['value'], $arreach['vless'],
282
-                                 $currkey, $currval))
282
+                                    $currkey, $currval))
283 283
                 { $ok = false; break; }
284 284
 
285 285
             if ( strtolower($arreach['name']) == 'style' ) {
Please login to merge, or discard this patch.
main/inc/lib/kses-0.2.2/oop/php5.class.kses.php 1 patch
Indentation   +1140 added lines, -1140 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	/*
3
+    /*
4 4
 	 * ==========================================================================================
5 5
 	 *
6 6
 	 * This program is free software and open source software; you can redistribute
@@ -21,1146 +21,1146 @@  discard block
 block discarded – undo
21 21
 	 * ==========================================================================================
22 22
 	 */
23 23
 
24
-	/**
25
-	*	Class file for PHP5 OOP version of kses
26
-	*
27
-	*	This is an updated version of kses to work with PHP5 that works under E_STRICT.
28
-	*
29
-	*	This version is a bit of a rewrite to match my own coding style and use some of the
30
-	*	capabilities allowed in PHP5.  Since this was a significant rewrite, but it still
31
-	*	maintains backward compatibility syntax-wise, the version number is now 1.0.0.  Any
32
-	*	minor changes that do not break compatibility will be indicated in the second or third
33
-	*	digits.  Anything that breaks compatibility will change the major version number.
34
-	*
35
-	*	PHP5 specific changes:
36
-	*	+ Private methods are now in place
37
-	*	+ __construct() is now used rather then the standard class name 'kses()'
38
-	*	+ Kses will not load in any version less that PHP5
39
-	*	Other modifications:
40
-	*	+ PHPdoc style documentation has been added to the class.  See http://www.phpdoc.org/ for more info.
41
-	*	+ Method names have been changed to reflect status as verbs
42
-	*	+ One line methods have been folded into the code
43
-	*	+ Some methods are now deprecated due to nomenclature style change.  See method documentation for specifics.
44
-	*	+ Kses5 now works in E_STRICT
45
-	*	+ Version number is 1.0.0 to reflect serious code changes
46
-	*	+ Addition of methods AddProtocols(), filterKsestextHook(), RemoveProtocol(), RemoveProtocols() and SetProtocols()
47
-	*	+ Deprecated _hook(), Protocols()
48
-	*
49
-	*	@package    kses
50
-	*	@subpackage kses5
51
-	*/
52
-
53
-	if(substr(phpversion(), 0, 1) < 5)
54
-	{
55
-		die("Class kses requires PHP 5 or higher.");
56
-	}
57
-
58
-	/**
59
-	*	Only install KSES5 once
60
-	*/
61
-	if(!defined('KSES_CLASS_PHP5'))
62
-	{
63
-		define('KSES_CLASS_PHP5', true);
64
-
65
-	/**
66
-	*	Kses strips evil scripts!
67
-	*
68
-	*	This class provides the capability for removing unwanted HTML/XHTML, attributes from
69
-	*	tags, and protocols contained in links.  The net result is a much more powerful tool
70
-	*	than the PHP internal strip_tags()
71
-	*
72
-	*	This is a fork of a slick piece of procedural code called 'kses' written by Ulf Harnhammar.
73
-	*
74
-	*	The original class for PHP4 was basically a wrapper around all of the functions in
75
-	*	the procedural code written by Ulf, and was released 7/25/2003.
76
-	*
77
-	*	This version is a bit of a rewrite to match my own coding style and use some of the
78
-	*	capabilities allowed in PHP5.  Since this was a significant rewrite, but it still
79
-	*	maintains backward compatibility syntax-wise, the version number is now 1.0.0.  Any
80
-	*	minor changes that do not break compatibility will be indicated in the second or third
81
-	*	digits.  Anything that breaks compatibility will change the major version number.
82
-	*
83
-	*	PHP5 specific changes:
84
-	*	+ Private methods are now in place
85
-	*	+ __construct() is now used rather then the standard class name 'kses()'
86
-	*	+ Kses5 will not load in any version less that PHP5
87
-	*	Other modifications:
88
-	*	+ PHPdoc style documentation has been added to the class.  See http://www.phpdoc.org/ for more info.
89
-	*	+ Method names have been changed to reflect status as verbs
90
-	*	+ One line methods have been folded into the code
91
-	*	+ Some methods are now deprecated due to nomenclature style change.  See method documentation for specifics.
92
-	*	+ Kses now works in E_STRICT
93
-	*	+ Initial Version number set to 1.0.0 to reflect serious code changes
94
-	*	+ Addition of methods AddProtocols(), filterKsestextHook(), RemoveProtocol(), RemoveProtocols() and SetProtocols()
95
-	*	+ Deprecated _hook(), Protocols()
96
-	*	+ Integrated code from kses 0.2.2 into class.
97
-	*	+ Added methods DumpProtocols(), DumpMethods()
98
-	*
99
-	*	@author     Richard R. V�squez, Jr. (Original procedural code by Ulf H�rnhammar)
100
-	*	@link       http://sourceforge.net/projects/kses/ Home Page for Kses
101
-	*	@link       http://chaos.org/contact/ Contact page with current email address for Richard Vasquez
102
-	*	@copyright  Richard R. V�squez, Jr. 2005
103
-	*	@version    PHP5 OOP 1.0.2
104
-	*	@license    http://www.gnu.org/licenses/gpl.html GNU Public License
105
-	*	@package    kses
106
-	*/
107
-		class kses5
108
-		{
109
-			/**#@+
24
+    /**
25
+     *	Class file for PHP5 OOP version of kses
26
+     *
27
+     *	This is an updated version of kses to work with PHP5 that works under E_STRICT.
28
+     *
29
+     *	This version is a bit of a rewrite to match my own coding style and use some of the
30
+     *	capabilities allowed in PHP5.  Since this was a significant rewrite, but it still
31
+     *	maintains backward compatibility syntax-wise, the version number is now 1.0.0.  Any
32
+     *	minor changes that do not break compatibility will be indicated in the second or third
33
+     *	digits.  Anything that breaks compatibility will change the major version number.
34
+     *
35
+     *	PHP5 specific changes:
36
+     *	+ Private methods are now in place
37
+     *	+ __construct() is now used rather then the standard class name 'kses()'
38
+     *	+ Kses will not load in any version less that PHP5
39
+     *	Other modifications:
40
+     *	+ PHPdoc style documentation has been added to the class.  See http://www.phpdoc.org/ for more info.
41
+     *	+ Method names have been changed to reflect status as verbs
42
+     *	+ One line methods have been folded into the code
43
+     *	+ Some methods are now deprecated due to nomenclature style change.  See method documentation for specifics.
44
+     *	+ Kses5 now works in E_STRICT
45
+     *	+ Version number is 1.0.0 to reflect serious code changes
46
+     *	+ Addition of methods AddProtocols(), filterKsestextHook(), RemoveProtocol(), RemoveProtocols() and SetProtocols()
47
+     *	+ Deprecated _hook(), Protocols()
48
+     *
49
+     *	@package    kses
50
+     *	@subpackage kses5
51
+     */
52
+
53
+    if(substr(phpversion(), 0, 1) < 5)
54
+    {
55
+        die("Class kses requires PHP 5 or higher.");
56
+    }
57
+
58
+    /**
59
+     *	Only install KSES5 once
60
+     */
61
+    if(!defined('KSES_CLASS_PHP5'))
62
+    {
63
+        define('KSES_CLASS_PHP5', true);
64
+
65
+    /**
66
+     *	Kses strips evil scripts!
67
+     *
68
+     *	This class provides the capability for removing unwanted HTML/XHTML, attributes from
69
+     *	tags, and protocols contained in links.  The net result is a much more powerful tool
70
+     *	than the PHP internal strip_tags()
71
+     *
72
+     *	This is a fork of a slick piece of procedural code called 'kses' written by Ulf Harnhammar.
73
+     *
74
+     *	The original class for PHP4 was basically a wrapper around all of the functions in
75
+     *	the procedural code written by Ulf, and was released 7/25/2003.
76
+     *
77
+     *	This version is a bit of a rewrite to match my own coding style and use some of the
78
+     *	capabilities allowed in PHP5.  Since this was a significant rewrite, but it still
79
+     *	maintains backward compatibility syntax-wise, the version number is now 1.0.0.  Any
80
+     *	minor changes that do not break compatibility will be indicated in the second or third
81
+     *	digits.  Anything that breaks compatibility will change the major version number.
82
+     *
83
+     *	PHP5 specific changes:
84
+     *	+ Private methods are now in place
85
+     *	+ __construct() is now used rather then the standard class name 'kses()'
86
+     *	+ Kses5 will not load in any version less that PHP5
87
+     *	Other modifications:
88
+     *	+ PHPdoc style documentation has been added to the class.  See http://www.phpdoc.org/ for more info.
89
+     *	+ Method names have been changed to reflect status as verbs
90
+     *	+ One line methods have been folded into the code
91
+     *	+ Some methods are now deprecated due to nomenclature style change.  See method documentation for specifics.
92
+     *	+ Kses now works in E_STRICT
93
+     *	+ Initial Version number set to 1.0.0 to reflect serious code changes
94
+     *	+ Addition of methods AddProtocols(), filterKsestextHook(), RemoveProtocol(), RemoveProtocols() and SetProtocols()
95
+     *	+ Deprecated _hook(), Protocols()
96
+     *	+ Integrated code from kses 0.2.2 into class.
97
+     *	+ Added methods DumpProtocols(), DumpMethods()
98
+     *
99
+     *	@author     Richard R. V�squez, Jr. (Original procedural code by Ulf H�rnhammar)
100
+     *	@link       http://sourceforge.net/projects/kses/ Home Page for Kses
101
+     *	@link       http://chaos.org/contact/ Contact page with current email address for Richard Vasquez
102
+     *	@copyright  Richard R. V�squez, Jr. 2005
103
+     *	@version    PHP5 OOP 1.0.2
104
+     *	@license    http://www.gnu.org/licenses/gpl.html GNU Public License
105
+     *	@package    kses
106
+     */
107
+        class kses5
108
+        {
109
+            /**#@+
110 110
 			 *	@access private
111 111
 			 *	@var array
112 112
 			 */
113
-			private $allowed_protocols;
114
-			private $allowed_html;
115
-			/**#@-*/
116
-
117
-			/**
118
-			 *	Constructor for kses.
119
-			 *
120
-			 *	This sets a default collection of protocols allowed in links, and creates an
121
-			 *	empty set of allowed HTML tags.
122
-			 *	@since PHP5 OOP 1.0.0
123
-			 */
124
-			public function __construct()
125
-			{
126
-				/**
127
-				 *	You could add protocols such as ftp, new, gopher, mailto, irc, etc.
128
-				 *
129
-				 *	The base values the original kses provided were:
130
-				 *		'http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto'
131
-				 */
132
-				$this->allowed_protocols = array('http', 'ftp', 'mailto');
133
-				$this->allowed_html      = array();
134
-			}
135
-
136
-			/**
137
-			 *	Basic task of kses - parses $string and strips it as required.
138
-			 *
139
-			 *	This method strips all the disallowed (X)HTML tags, attributes
140
-			 *	and protocols from the input $string.
141
-			 *
142
-			 *	@access public
143
-			 *	@param string $string String to be stripped of 'evil scripts'
144
-			 *	@return string The stripped string
145
-			 *	@since PHP4 OOP 0.0.1
146
-			 */
147
-			public function Parse($string = "")
148
-			{
149
-				if (get_magic_quotes_gpc())
150
-				{
151
-					$string = stripslashes($string);
152
-				}
153
-				$string = $this->removeNulls($string);
154
-				//	Remove JavaScript entities from early Netscape 4 versions
155
-				$string = preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);
156
-				$string = $this->normalizeEntities($string);
157
-				$string = $this->filterKsesTextHook($string);
158
-				$string = preg_replace('%(<' . '[^>]*' . '(>|$)' . '|>)%e', "\$this->stripTags('\\1')", $string);
159
-				return $string;
160
-			}
161
-
162
-			/**
163
-			 *	Allows for single/batch addition of protocols
164
-			 *
165
-			 *	This method accepts one argument that can be either a string
166
-			 *	or an array of strings.  Invalid data will be ignored.
167
-			 *
168
-			 *	The argument will be processed, and each string will be added
169
-			 *	via AddProtocol().
170
-			 *
171
-			 *	@access public
172
-			 *	@param mixed , A string or array of protocols that will be added to the internal list of allowed protocols.
173
-			 *	@return bool Status of adding valid protocols.
174
-			 *	@see AddProtocol()
175
-			 *	@since PHP5 OOP 1.0.0
176
-			 */
177
-			public function AddProtocols()
178
-			{
179
-				$c_args = func_num_args();
180
-				if($c_args != 1)
181
-				{
182
-					trigger_error("kses5::AddProtocols() did not receive an argument.", E_USER_WARNING);
183
-					return false;
184
-				}
185
-
186
-				$protocol_data = func_get_arg(0);
187
-
188
-				if(is_array($protocol_data) && count($protocol_data) > 0)
189
-				{
190
-					foreach($protocol_data as $protocol)
191
-					{
192
-						$this->AddProtocol($protocol);
193
-					}
194
-					return true;
195
-				}
196
-				elseif(is_string($protocol_data))
197
-				{
198
-					$this->AddProtocol($protocol_data);
199
-					return true;
200
-				}
201
-				else
202
-				{
203
-					trigger_error("kses5::AddProtocols() did not receive a string or an array.", E_USER_WARNING);
204
-					return false;
205
-				}
206
-			}
207
-
208
-			/**
209
-			 *	Allows for single/batch addition of protocols
210
-			 *
211
-			 *	@deprecated Use AddProtocols()
212
-			 *	@see AddProtocols()
213
-			 *	@return bool
214
-			 *	@since PHP4 OOP 0.0.1
215
-			 */
216
-			public function Protocols()
217
-			{
218
-				$c_args = func_num_args();
219
-				if($c_args != 1)
220
-				{
221
-					trigger_error("kses5::Protocols() did not receive an argument.", E_USER_WARNING);
222
-					return false;
223
-				}
224
-
225
-				return $this->AddProtocols(func_get_arg(0));
226
-			}
227
-
228
-			/**
229
-			 *	Adds a single protocol to $this->allowed_protocols.
230
-			 *
231
-			 *	This method accepts a string argument and adds it to
232
-			 *	the list of allowed protocols to keep when performing
233
-			 *	Parse().
234
-			 *
235
-			 *	@access public
236
-			 *	@param string $protocol The name of the protocol to be added.
237
-			 *	@return bool Status of adding valid protocol.
238
-			 *	@since PHP4 OOP 0.0.1
239
-			 */
240
-			public function AddProtocol($protocol = "")
241
-			{
242
-				if(!is_string($protocol))
243
-				{
244
-					trigger_error("kses5::AddProtocol() requires a string.", E_USER_WARNING);
245
-					return false;
246
-				}
247
-
248
-				// Remove any inadvertent ':' at the end of the protocol.
249
-				if(substr($protocol, strlen($protocol) - 1, 1) == ":")
250
-				{
251
-					$protocol = substr($protocol, 0, strlen($protocol) - 1);
252
-				}
253
-
254
-				$protocol = strtolower(trim($protocol));
255
-				if($protocol == "")
256
-				{
257
-					trigger_error("kses5::AddProtocol() tried to add an empty/NULL protocol.", E_USER_WARNING);
258
-					return false;
259
-				}
260
-
261
-				//	prevent duplicate protocols from being added.
262
-				if(!in_array($protocol, $this->allowed_protocols))
263
-				{
264
-					array_push($this->allowed_protocols, $protocol);
265
-					sort($this->allowed_protocols);
266
-				}
267
-				return true;
268
-			}
269
-
270
-			/**
271
-			 *	Removes a single protocol from $this->allowed_protocols.
272
-			 *
273
-			 *	This method accepts a string argument and removes it from
274
-			 *	the list of allowed protocols to keep when performing
275
-			 *	Parse().
276
-			 *
277
-			 *	@access public
278
-			 *	@param string $protocol The name of the protocol to be removed.
279
-			 *	@return bool Status of removing valid protocol.
280
-			 *	@since PHP5 OOP 1.0.0
281
-			 */
282
-			public function RemoveProtocol($protocol = "")
283
-			{
284
-				if(!is_string($protocol))
285
-				{
286
-					trigger_error("kses5::RemoveProtocol() requires a string.", E_USER_WARNING);
287
-					return false;
288
-				}
289
-
290
-				// Remove any inadvertent ':' at the end of the protocol.
291
-				if(substr($protocol, strlen($protocol) - 1, 1) == ":")
292
-				{
293
-					$protocol = substr($protocol, 0, strlen($protocol) - 1);
294
-				}
295
-
296
-				$protocol = strtolower(trim($protocol));
297
-				if($protocol == "")
298
-				{
299
-					trigger_error("kses5::RemoveProtocol() tried to remove an empty/NULL protocol.", E_USER_WARNING);
300
-					return false;
301
-				}
302
-
303
-				//	Ensures that the protocol exists before removing it.
304
-				if(in_array($protocol, $this->allowed_protocols))
305
-				{
306
-					$this->allowed_protocols = array_diff($this->allowed_protocols, array($protocol));
307
-					sort($this->allowed_protocols);
308
-				}
309
-
310
-				return true;
311
-			}
312
-
313
-			/**
314
-			 *	Allows for single/batch removal of protocols
315
-			 *
316
-			 *	This method accepts one argument that can be either a string
317
-			 *	or an array of strings.  Invalid data will be ignored.
318
-			 *
319
-			 *	The argument will be processed, and each string will be removed
320
-			 *	via RemoveProtocol().
321
-			 *
322
-			 *	@access public
323
-			 *	@param mixed , A string or array of protocols that will be removed from the internal list of allowed protocols.
324
-			 *	@return bool Status of removing valid protocols.
325
-			 *	@see RemoveProtocol()
326
-			 *	@since PHP5 OOP 1.0.0
327
-			 */
328
-			public function RemoveProtocols()
329
-			{
330
-				$c_args = func_num_args();
331
-				if($c_args != 1)
332
-				{
333
-					return false;
334
-				}
335
-
336
-				$protocol_data = func_get_arg(0);
337
-
338
-				if(is_array($protocol_data) && count($protocol_data) > 0)
339
-				{
340
-					foreach($protocol_data as $protocol)
341
-					{
342
-						$this->RemoveProtocol($protocol);
343
-					}
344
-				}
345
-				elseif(is_string($protocol_data))
346
-				{
347
-					$this->RemoveProtocol($protocol_data);
348
-					return true;
349
-				}
350
-				else
351
-				{
352
-					trigger_error("kses5::RemoveProtocols() did not receive a string or an array.", E_USER_WARNING);
353
-					return false;
354
-				}
355
-			}
356
-
357
-			/**
358
-			 *	Allows for single/batch replacement of protocols
359
-			 *
360
-			 *	This method accepts one argument that can be either a string
361
-			 *	or an array of strings.  Invalid data will be ignored.
362
-			 *
363
-			 *	Existing protocols will be removed, then the argument will be
364
-			 *	processed, and each string will be added via AddProtocol().
365
-			 *
366
-			 *	@access public
367
-			 *	@param mixed , A string or array of protocols that will be the new internal list of allowed protocols.
368
-			 *	@return bool Status of replacing valid protocols.
369
-			 *	@since PHP5 OOP 1.0.1
370
-			 *	@see AddProtocol()
371
-			 */
372
-			public function SetProtocols()
373
-			{
374
-				$c_args = func_num_args();
375
-				if($c_args != 1)
376
-				{
377
-					trigger_error("kses5::SetProtocols() did not receive an argument.", E_USER_WARNING);
378
-					return false;
379
-				}
380
-
381
-				$protocol_data = func_get_arg(0);
382
-
383
-				if(is_array($protocol_data) && count($protocol_data) > 0)
384
-				{
385
-					$this->allowed_protocols = array();
386
-					foreach($protocol_data as $protocol)
387
-					{
388
-						$this->AddProtocol($protocol);
389
-					}
390
-					return true;
391
-				}
392
-				elseif(is_string($protocol_data))
393
-				{
394
-					$this->allowed_protocols = array();
395
-					$this->AddProtocol($protocol_data);
396
-					return true;
397
-				}
398
-				else
399
-				{
400
-					trigger_error("kses5::SetProtocols() did not receive a string or an array.", E_USER_WARNING);
401
-					return false;
402
-				}
403
-			}
404
-
405
-			/**
406
-			 *	Raw dump of allowed protocols
407
-			 *
408
-			 *	This returns an indexed array of allowed protocols for a particular KSES
409
-			 *	instantiation.
410
-			 *
411
-			 *	@access public
412
-			 *	@return array The list of allowed protocols.
413
-			 *	@since PHP5 OOP 1.0.2
414
-			 */
415
-			public function DumpProtocols()
416
-			{
417
-				return $this->allowed_protocols;
418
-			}
419
-
420
-			/**
421
-			 *	Raw dump of allowed (X)HTML elements
422
-			 *
423
-			 *	This returns an indexed array of allowed (X)HTML elements and attributes
424
-			 *	for a particular KSES instantiation.
425
-			 *
426
-			 *	@access public
427
-			 *	@return array The list of allowed elements.
428
-			 *	@since PHP5 OOP 1.0.2
429
-			 */
430
-			public function DumpElements()
431
-			{
432
-				return $this->allowed_html;
433
-			}
434
-
435
-
436
-			/**
437
-			 *	Adds valid (X)HTML with corresponding attributes that will be kept when stripping 'evil scripts'.
438
-			 *
439
-			 *	This method accepts one argument that can be either a string
440
-			 *	or an array of strings.  Invalid data will be ignored.
441
-			 *
442
-			 *	@access public
443
-			 *	@param string $tag (X)HTML tag that will be allowed after stripping text.
444
-			 *	@param array $attribs Associative array of allowed attributes - key => attribute name - value => attribute parameter
445
-			 *	@return bool Status of Adding (X)HTML and attributes.
446
-			 *	@since PHP4 OOP 0.0.1
447
-			 */
448
-			public function AddHTML($tag = "", $attribs = array())
449
-			{
450
-				if(!is_string($tag))
451
-				{
452
-					trigger_error("kses5::AddHTML() requires the tag to be a string", E_USER_WARNING);
453
-					return false;
454
-				}
455
-
456
-				$tag = strtolower(trim($tag));
457
-				if($tag == "")
458
-				{
459
-					trigger_error("kses5::AddHTML() tried to add an empty/NULL tag", E_USER_WARNING);
460
-					return false;
461
-				}
462
-
463
-				if(!is_array($attribs))
464
-				{
465
-					trigger_error("kses5::AddHTML() requires an array (even an empty one) of attributes for '$tag'", E_USER_WARNING);
466
-					return false;
467
-				}
468
-
469
-				$new_attribs = array();
470
-				if(is_array($attribs) && count($attribs) > 0)
471
-				{
472
-					foreach($attribs as $idx1 => $val1)
473
-					{
474
-						$new_idx1 = strtolower($idx1);
475
-						$new_val1 = $attribs[$idx1];
476
-
477
-						if(is_array($new_val1) && count($attribs) > 0)
478
-						{
479
-							$tmp_val = array();
480
-							foreach($new_val1 as $idx2 => $val2)
481
-							{
482
-								$new_idx2 = strtolower($idx2);
483
-								$tmp_val[$new_idx2] = $val2;
484
-							}
485
-							$new_val1 = $tmp_val;
486
-						}
487
-
488
-						$new_attribs[$new_idx1] = $new_val1;
489
-					}
490
-				}
491
-
492
-				$this->allowed_html[$tag] = $new_attribs;
493
-				return true;
494
-			}
495
-
496
-			/**
497
-			 *	This method removes any NULL characters in $string.
498
-			 *
499
-			 *	@access private
500
-			 *	@param string $string
501
-			 *	@return string String without any NULL/chr(173)
502
-			 *	@since PHP4 OOP 0.0.1
503
-			 */
504
-			private function removeNulls($string)
505
-			{
506
-				$string = preg_replace('/\0+/', '', $string);
507
-				$string = preg_replace('/(\\\\0)+/', '', $string);
508
-				return $string;
509
-			}
510
-
511
-			/**
512
-			 *	Normalizes HTML entities
513
-			 *
514
-			 *	This function normalizes HTML entities. It will convert "AT&T" to the correct
515
-			 *	"AT&amp;T", "&#00058;" to "&#58;", "&#XYZZY;" to "&amp;#XYZZY;" and so on.
516
-			 *
517
-			 *	@access private
518
-			 *	@param string $string
519
-			 *	@return string String with normalized entities
520
-			 *	@since PHP4 OOP 0.0.1
521
-			 */
522
-			private function normalizeEntities($string)
523
-			{
524
-				# Disarm all entities by converting & to &amp;
525
-				$string = str_replace('&', '&amp;', $string);
526
-
527
-				#	TODO: Change back (Keep?) the allowed entities in our entity white list
528
-
529
-				#	Keeps entities that start with [A-Za-z]
530
-				$string = preg_replace(
531
-					'/&amp;([A-Za-z][A-Za-z0-9]{0,19});/',
532
-					'&\\1;',
533
-					$string
534
-				);
535
-
536
-				#	Change numeric entities to valid 16 bit values
537
-
538
-				$string = preg_replace(
539
-					'/&amp;#0*([0-9]{1,5});/e',
540
-					'\$this->normalizeEntities16bit("\\1")',
541
-					$string
542
-				);
543
-
544
-				#	Change &XHHHHHHH (Hex digits) to 16 bit hex values
545
-				$string = preg_replace(
546
-					'/&amp;#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/',
547
-					'&#\\1\\2;',
548
-					$string
549
-				);
550
-
551
-				return $string;
552
-			}
553
-
554
-			/**
555
-			 *	Helper method used by normalizeEntites()
556
-			 *
557
-			 *	This method helps normalizeEntities() to only accept 16 bit values
558
-			 *	and nothing more for &#number; entities.
559
-			 *
560
-			 *	This method helps normalize_entities() during a preg_replace()
561
-			 *	where a &#(0)*XXXXX; occurs.  The '(0)*XXXXXX' value is converted to
562
-			 *	a number and the result is returned as a numeric entity if the number
563
-			 *	is less than 65536.  Otherwise, the value is returned 'as is'.
564
-			 *
565
-			 *	@access private
566
-			 *	@param string $i
567
-			 *	@return string Normalized numeric entity
568
-			 *	@see normalizeEntities()
569
-			 *	@since PHP4 OOP 0.0.1
570
-			 */
571
-			private function normalizeEntities16bit($i)
572
-			{
573
-			  return (($i > 65535) ? "&amp;#$i;" : "&#$i;");
574
-			}
575
-
576
-			/**
577
-			 *	Allows for additional user defined modifications to text.
578
-			 *
579
-			 *	This method allows for additional modifications to be performed on
580
-			 *	a string that's being run through Parse().  Currently, it returns the
581
-			 *	input string 'as is'.
582
-			 *
583
-			 *	This method is provided for users to extend the kses class for their own
584
-			 *	requirements.
585
-			 *
586
-			 *	@access public
587
-			 *	@param string $string String to perfrom additional modifications on.
588
-			 *	@return string User modified string.
589
-			 *	@see Parse()
590
-			 *	@since PHP5 OOP 1.0.0
591
-			 */
592
-			private function filterKsesTextHook($string)
593
-			{
594
-			  return $string;
595
-			}
596
-
597
-			/**
598
-			 *	Allows for additional user defined modifications to text.
599
-			 *
600
-			 *	@deprecated use filterKsesTextHook()
601
-			 *	@param string $string
602
-			 *	@return string
603
-			 *	@see filterKsesTextHook()
604
-			 *	@since PHP4 OOP 0.0.1
605
-			 */
606
-			private function _hook($string)
607
-			{
608
-				return $this->filterKsesTextHook($string);
609
-			}
610
-
611
-			/**
612
-			 *	This method goes through an array, and changes the keys to all lower case.
613
-			 *
614
-			 *	@access private
615
-			 *	@param array $in_array Associative array
616
-			 *	@return array Modified array
617
-			 *	@since PHP4 OOP 0.0.1
618
-			 */
619
-			private function makeArrayKeysLowerCase($in_array)
620
-			{
621
-				$out_array = array();
622
-
623
-				if(is_array($in_array) && count($in_array) > 0)
624
-				{
625
-					foreach ($in_array as $in_key => $in_val)
626
-					{
627
-						$out_key = strtolower($in_key);
628
-						$out_array[$out_key] = array();
629
-
630
-						if(is_array($in_val) && count($in_val) > 0)
631
-						{
632
-							foreach ($in_val as $in_key2 => $in_val2)
633
-							{
634
-								$out_key2 = strtolower($in_key2);
635
-								$out_array[$out_key][$out_key2] = $in_val2;
636
-							}
637
-						}
638
-					}
639
-				}
640
-
641
-				return $out_array;
642
-			}
643
-
644
-			/**
645
-			 *	This method strips out disallowed and/or mangled (X)HTML tags along with assigned attributes.
646
-			 *
647
-			 *	This method does a lot of work. It rejects some very malformed things
648
-			 *	like <:::>. It returns an empty string if the element isn't allowed (look
649
-			 *	ma, no strip_tags()!). Otherwise it splits the tag into an element and an
650
-			 *	allowed attribute list.
651
-			 *
652
-			 *	@access private
653
-			 *	@param string $string
654
-			 *	@return string Modified string minus disallowed/mangled (X)HTML and attributes
655
-			 *	@since PHP4 OOP 0.0.1
656
-			 */
657
-			private function stripTags($string)
658
-			{
659
-				$string = preg_replace('%\\\\"%', '"', $string);
660
-
661
-				if (substr($string, 0, 1) != '<')
662
-				{
663
-					# It matched a ">" character
664
-					return '&gt;';
665
-				}
666
-
667
-				if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
668
-				{
669
-					# It's seriously malformed
670
-					return '';
671
-				}
672
-
673
-				$slash    = trim($matches[1]);
674
-				$elem     = $matches[2];
675
-				$attrlist = $matches[3];
676
-
677
-				if (
678
-					!isset($this->allowed_html[strtolower($elem)]) ||
679
-					!is_array($this->allowed_html[strtolower($elem)]))
680
-				{
681
-					#	Found an HTML element not in the white list
682
-					return '';
683
-				}
684
-
685
-				if ($slash != '')
686
-				{
687
-					return "<$slash$elem>";
688
-				}
689
-				# No attributes are allowed for closing elements
690
-
691
-				return $this->stripAttributes("$slash$elem", $attrlist);
692
-			}
693
-
694
-			/**
695
-			 *	This method strips out disallowed attributes for (X)HTML tags.
696
-			 *
697
-			 *	This method removes all attributes if none are allowed for this element.
698
-			 *	If some are allowed it calls combAttributes() to split them further, and then it
699
-			 *	builds up new HTML code from the data that combAttributes() returns. It also
700
-			 *	removes "<" and ">" characters, if there are any left. One more thing it
701
-			 *	does is to check if the tag has a closing XHTML slash, and if it does,
702
-			 *	it puts one in the returned code as well.
703
-			 *
704
-			 *	@access private
705
-			 *	@param string $element (X)HTML tag to check
706
-			 *	@param string $attr Text containing attributes to check for validity.
707
-			 *	@return string Resulting valid (X)HTML or ''
708
-			 *	@see combAttributes()
709
-			 *	@since PHP4 OOP 0.0.1
710
-			 */
711
-			private function stripAttributes($element, $attr)
712
-			{
713
-				# Is there a closing XHTML slash at the end of the attributes?
714
-				$xhtml_slash = '';
715
-				if (preg_match('%\s/\s*$%', $attr))
716
-				{
717
-					$xhtml_slash = ' /';
718
-				}
719
-
720
-				# Are any attributes allowed at all for this element?
721
-				if (
722
-					!isset($this->allowed_html[strtolower($element)]) ||
723
-					count($this->allowed_html[strtolower($element)]) == 0
724
-				)
725
-				{
726
-					return "<$element$xhtml_slash>";
727
-				}
728
-
729
-				# Split it
730
-				$attrarr = $this->combAttributes($attr);
731
-
732
-				# Go through $attrarr, and save the allowed attributes for this element
733
-				# in $attr2
734
-				$attr2 = '';
735
-				if(is_array($attrarr) && count($attrarr) > 0)
736
-				{
737
-					foreach ($attrarr as $arreach)
738
-					{
739
-						if(!isset($this->allowed_html[strtolower($element)][strtolower($arreach['name'])]))
740
-						{
741
-							continue;
742
-						}
743
-
744
-						$current = $this->allowed_html[strtolower($element)][strtolower($arreach['name'])];
745
-
746
-						if (!is_array($current))
747
-						{
748
-							# there are no checks
749
-							$attr2 .= ' '.$arreach['whole'];
750
-						}
751
-						else
752
-						{
753
-							# there are some checks
754
-							$ok = true;
755
-							if(is_array($current) && count($current) > 0)
756
-							{
757
-								foreach ($current as $currkey => $currval)
758
-								{
759
-									if (!$this->checkAttributeValue($arreach['value'], $arreach['vless'], $currkey, $currval))
760
-									{
761
-										$ok = false;
762
-										break;
763
-									}
764
-								}
765
-							}
766
-
767
-							if ($ok)
768
-							{
769
-								# it passed them
770
-								$attr2 .= ' '.$arreach['whole'];
771
-							}
772
-						}
773
-					}
774
-				}
775
-
776
-				# Remove any "<" or ">" characters
777
-				$attr2 = preg_replace('/[<>]/', '', $attr2);
778
-				return "<$element$attr2$xhtml_slash>";
779
-			}
780
-
781
-			/**
782
-			 *	This method combs through an attribute list string and returns an associative array of attributes and values.
783
-			 *
784
-			 *	This method does a lot of work. It parses an attribute list into an array
785
-			 *	with attribute data, and tries to do the right thing even if it gets weird
786
-			 *	input. It will add quotes around attribute values that don't have any quotes
787
-			 *	or apostrophes around them, to make it easier to produce HTML code that will
788
-			 *	conform to W3C's HTML specification. It will also remove bad URL protocols
789
-			 *	from attribute values.
790
-			 *
791
-			 *	@access private
792
-			 *	@param string $attr Text containing tag attributes for parsing
793
-			 *	@return array Associative array containing data on attribute and value
794
-			 *	@since PHP4 OOP 0.0.1
795
-			 */
796
-			private function combAttributes($attr)
797
-			{
798
-				$attrarr  = array();
799
-				$mode     = 0;
800
-				$attrname = '';
801
-
802
-				# Loop through the whole attribute list
803
-
804
-				while (strlen($attr) != 0)
805
-				{
806
-					# Was the last operation successful?
807
-					$working = 0;
808
-
809
-					switch ($mode)
810
-					{
811
-						case 0:	# attribute name, href for instance
812
-							if (preg_match('/^([-a-zA-Z]+)/', $attr, $match))
813
-							{
814
-								$attrname = $match[1];
815
-								$working = $mode = 1;
816
-								$attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
817
-							}
818
-							break;
819
-						case 1:	# equals sign or valueless ("selected")
820
-							if (preg_match('/^\s*=\s*/', $attr)) # equals sign
821
-							{
822
-								$working = 1;
823
-								$mode    = 2;
824
-								$attr    = preg_replace('/^\s*=\s*/', '', $attr);
825
-								break;
826
-							}
827
-							if (preg_match('/^\s+/', $attr)) # valueless
828
-							{
829
-								$working   = 1;
830
-								$mode      = 0;
831
-								$attrarr[] = array(
832
-									'name'  => $attrname,
833
-									'value' => '',
834
-									'whole' => $attrname,
835
-									'vless' => 'y'
836
-								);
837
-								$attr      = preg_replace('/^\s+/', '', $attr);
838
-							}
839
-							break;
840
-						case 2: # attribute value, a URL after href= for instance
841
-							if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match)) # "value"
842
-							{
843
-								$thisval   = $this->removeBadProtocols($match[1]);
844
-								$attrarr[] = array(
845
-									'name'  => $attrname,
846
-									'value' => $thisval,
847
-									'whole' => $attrname . '="' . $thisval . '"',
848
-									'vless' => 'n'
849
-								);
850
-								$working   = 1;
851
-								$mode      = 0;
852
-								$attr      = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
853
-								break;
854
-							}
855
-							if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match)) # 'value'
856
-							{
857
-								$thisval   = $this->removeBadProtocols($match[1]);
858
-								$attrarr[] = array(
859
-									'name'  => $attrname,
860
-									'value' => $thisval,
861
-									'whole' => "$attrname='$thisval'",
862
-									'vless' => 'n'
863
-								);
864
-								$working   = 1;
865
-								$mode      = 0;
866
-								$attr      = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
867
-								break;
868
-							}
869
-							if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match)) # value
870
-							{
871
-								$thisval   = $this->removeBadProtocols($match[1]);
872
-								$attrarr[] = array(
873
-									'name'  => $attrname,
874
-									'value' => $thisval,
875
-									'whole' => $attrname . '="' . $thisval . '"',
876
-									'vless' => 'n'
877
-								);
878
-								# We add quotes to conform to W3C's HTML spec.
879
-								$working   = 1;
880
-								$mode      = 0;
881
-								$attr      = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
882
-							}
883
-							break;
884
-					}
885
-
886
-					if ($working == 0) # not well formed, remove and try again
887
-					{
888
-						$attr = preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $attr);
889
-						$mode = 0;
890
-					}
891
-				}
892
-
893
-				# special case, for when the attribute list ends with a valueless
894
-				# attribute like "selected"
895
-				if ($mode == 1)
896
-				{
897
-					$attrarr[] = array(
898
-						'name'  => $attrname,
899
-						'value' => '',
900
-						'whole' => $attrname,
901
-						'vless' => 'y'
902
-					);
903
-				}
904
-
905
-				return $attrarr;
906
-			}
907
-
908
-			/**
909
-			 *	This method removes disallowed protocols.
910
-			 *
911
-			 *	This method removes all non-allowed protocols from the beginning of
912
-			 *	$string. It ignores whitespace and the case of the letters, and it does
913
-			 *	understand HTML entities. It does its work in a while loop, so it won't be
914
-			 *	fooled by a string like "javascript:javascript:alert(57)".
915
-			 *
916
-			 *	@access private
917
-			 *	@param string $string String to check for protocols
918
-			 *	@return string String with removed protocols
919
-			 *	@since PHP4 OOP 0.0.1
920
-			 */
921
-			private function removeBadProtocols($string)
922
-			{
923
-				$string  = $this->RemoveNulls($string);
924
-				$string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature"
925
-				$string2 = $string . 'a';
926
-
927
-				$string2 = preg_split('/:|&#58;|&#x3a;/i', $string, 2);
928
-				if(isset($string2[1]) && !preg_match('%/\?%',$string2[0]))
929
-				{
930
-					$string = $this->filterProtocols($string2[0]).trim($string2[1]);
931
-				}
932
-				return $string;
933
-			}
934
-
935
-			/**
936
-			 *	Helper method used by removeBadProtocols()
937
-			 *
938
-			 *	This function processes URL protocols, checks to see if they're in the white-
939
-			 *	list or not, and returns different data depending on the answer.
940
-			 *
941
-			 *	@access private
942
-			 *	@param string $string String to check for protocols
943
-			 *	@return string String with removed protocols
944
-			 *	@see removeBadProtocols()
945
-			 *	@since PHP4 OOP 0.0.1
946
-			 */
947
-			private function filterProtocols($string)
948
-			{
949
-				$string = $this->decodeEntities($string);
950
-				$string = preg_replace('/\s/', '', $string);
951
-				$string = $this->removeNulls($string);
952
-				$string = preg_replace('/\xad+/', '', $string2); # deals with Opera "feature"
953
-				$string = strtolower($string);
954
-
955
-				if(is_array($this->allowed_protocols) && count($this->allowed_protocols) > 0)
956
-				{
957
-					foreach ($this->allowed_protocols as $one_protocol)
958
-					{
959
-						if (strtolower($one_protocol) == $string)
960
-						{
961
-							return "$string:";
962
-						}
963
-					}
964
-				}
965
-
966
-				return '';
967
-			}
968
-
969
-			/**
970
-			 *	Controller method for performing checks on attribute values.
971
-			 *
972
-			 *	This method calls the appropriate method as specified by $checkname with
973
-			 *	the parameters $value, $vless, and $checkvalue, and returns the result
974
-			 *	of the call.
975
-			 *
976
-			 *	This method's functionality can be expanded by creating new methods
977
-			 *	that would match checkAttributeValue[$checkname].
978
-			 *
979
-			 *	Current checks implemented are: "maxlen", "minlen", "maxval", "minval" and "valueless"
980
-			 *
981
-			 *	@access private
982
-			 *	@param string $value The value of the attribute to be checked.
983
-			 *	@param string $vless Indicates whether the the value is supposed to be valueless
984
-			 *	@param string $checkname The check to be performed
985
-			 *	@param string $checkvalue The value that is to be checked against
986
-			 *	@return bool Indicates whether the check passed or not
987
-			 *	@since PHP5 OOP 1.0.0
988
-			 */
989
-			private function checkAttributeValue($value, $vless, $checkname, $checkvalue)
990
-			{
991
-				$ok = true;
992
-				$check_attribute_method_name  = 'checkAttributeValue' . ucfirst(strtolower($checkname));
993
-				if(method_exists($this, $check_attribute_method_name))
994
-				{
995
-					$ok = $this->$check_attribute_method_name($value, $checkvalue, $vless);
996
-				}
997
-
998
-				return $ok;
999
-			}
1000
-
1001
-			/**
1002
-			 *	Helper method invoked by checkAttributeValue().
1003
-			 *
1004
-			 *	The maxlen check makes sure that the attribute value has a length not
1005
-			 *	greater than the given value. This can be used to avoid Buffer Overflows
1006
-			 *	in WWW clients and various Internet servers.
1007
-			 *
1008
-			 *	@access private
1009
-			 *	@param string $value The value of the attribute to be checked.
1010
-			 *	@param int $checkvalue The maximum value allowed
1011
-			 *	@return bool Indicates whether the check passed or not
1012
-			 *	@see checkAttributeValue()
1013
-			 *	@since PHP5 OOP 1.0.0
1014
-			 */
1015
-			private function checkAttributeValueMaxlen($value, $checkvalue)
1016
-			{
1017
-				if (strlen($value) > intval($checkvalue))
1018
-				{
1019
-					return false;
1020
-				}
1021
-				return true;
1022
-			}
1023
-
1024
-			/**
1025
-			 *	Helper method invoked by checkAttributeValue().
1026
-			 *
1027
-			 *	The minlen check makes sure that the attribute value has a length not
1028
-			 *	smaller than the given value.
1029
-			 *
1030
-			 *	@access private
1031
-			 *	@param string $value The value of the attribute to be checked.
1032
-			 *	@param int $checkvalue The minimum value allowed
1033
-			 *	@return bool Indicates whether the check passed or not
1034
-			 *	@see checkAttributeValue()
1035
-			 *	@since PHP5 OOP 1.0.0
1036
-			 */
1037
-			private function checkAttributeValueMinlen($value, $checkvalue)
1038
-			{
1039
-				if (strlen($value) < intval($checkvalue))
1040
-				{
1041
-					return false;
1042
-				}
1043
-				return true;
1044
-			}
1045
-
1046
-			/**
1047
-			 *	Helper method invoked by checkAttributeValue().
1048
-			 *
1049
-			 *	The maxval check does two things: it checks that the attribute value is
1050
-			 *	an integer from 0 and up, without an excessive amount of zeroes or
1051
-			 *	whitespace (to avoid Buffer Overflows). It also checks that the attribute
1052
-			 *	value is not greater than the given value.
1053
-			 *
1054
-			 *	This check can be used to avoid Denial of Service attacks.
1055
-			 *
1056
-			 *	@access private
1057
-			 *	@param int $value The value of the attribute to be checked.
1058
-			 *	@param int $checkvalue The maximum numeric value allowed
1059
-			 *	@return bool Indicates whether the check passed or not
1060
-			 *	@see checkAttributeValue()
1061
-			 *	@since PHP5 OOP 1.0.0
1062
-			 */
1063
-			private function checkAttributeValueMaxval($value, $checkvalue)
1064
-			{
1065
-				if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
1066
-				{
1067
-					return false;
1068
-				}
1069
-				if (intval($value) > intval($checkvalue))
1070
-				{
1071
-					return false;
1072
-				}
1073
-				return true;
1074
-			}
1075
-
1076
-			/**
1077
-			 *	Helper method invoked by checkAttributeValue().
1078
-			 *
1079
-			 *	The minval check checks that the attribute value is a positive integer,
1080
-			 *	and that it is not smaller than the given value.
1081
-			 *
1082
-			 *	@access private
1083
-			 *	@param int $value The value of the attribute to be checked.
1084
-			 *	@param int $checkvalue The minimum numeric value allowed
1085
-			 *	@return bool Indicates whether the check passed or not
1086
-			 *	@see checkAttributeValue()
1087
-			 *	@since PHP5 OOP 1.0.0
1088
-			 */
1089
-			private function checkAttributeValueMinval($value, $checkvalue)
1090
-			{
1091
-				if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
1092
-				{
1093
-					return false;
1094
-				}
1095
-				if (intval($value) < ($checkvalue))
1096
-				{
1097
-					return false;
1098
-				}
1099
-				return true;
1100
-			}
1101
-
1102
-			/**
1103
-			 *	Helper method invoked by checkAttributeValue().
1104
-			 *
1105
-			 *	The valueless check checks if the attribute has a value
1106
-			 *	(like <a href="blah">) or not (<option selected>). If the given value
1107
-			 *	is a "y" or a "Y", the attribute must not have a value.
1108
-			 *
1109
-			 *	If the given value is an "n" or an "N", the attribute must have one.
1110
-			 *
1111
-			 *	@access private
1112
-			 *	@param int $value The value of the attribute to be checked.
1113
-			 *	@param mixed $checkvalue This variable is ignored for this test
1114
-			 *	@param string $vless Flag indicating if this attribute is not supposed to have an attribute
1115
-			 *	@return bool Indicates whether the check passed or not
1116
-			 *	@see checkAttributeValue()
1117
-			 *	@since PHP5 OOP 1.0.0
1118
-			 */
1119
-			private function checkAttributeValueValueless($value, $checkvalue, $vless)
1120
-			{
1121
-				if (strtolower($checkvalue) != $vless)
1122
-				{
1123
-					return false;
1124
-				}
1125
-				return true;
1126
-			}
1127
-
1128
-			/**
1129
-			 *	Decodes numeric HTML entities
1130
-			 *
1131
-			 *	This method decodes numeric HTML entities (&#65; and &#x41;). It doesn't
1132
-			 *	do anything with other entities like &auml;, but we don't need them in the
1133
-			 *	URL protocol white listing system anyway.
1134
-			 *
1135
-			 *	@access private
1136
-			 *	@param string $value The entitiy to be decoded.
1137
-			 *	@return string Decoded entity
1138
-			 *	@since PHP4 OOP 0.0.1
1139
-			 */
1140
-			private function decodeEntities($string)
1141
-			{
1142
-				$string = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $string);
1143
-				$string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', 'chr(hexdec("\\1"))', $string);
1144
-				return $string;
1145
-			}
1146
-
1147
-			/**
1148
-			 *	Returns PHP5 OOP version # of kses.
1149
-			 *
1150
-			 *	Since this class has been refactored and documented and proven to work,
1151
-			 *	I'm fixing the version number at 1.0.0.
1152
-			 *
1153
-			 *	This version is syntax compatible with the PHP4 OOP version 0.0.2.  Future
1154
-			 *	versions may not be syntax compatible.
1155
-			 *
1156
-			 *	@access public
1157
-			 *	@return string Version number
1158
-			 *	@since PHP4 OOP 0.0.1
1159
-			 */
1160
-			public function Version()
1161
-			{
1162
-				return 'PHP5 OOP 1.0.2';
1163
-			}
1164
-		}
1165
-	}
113
+            private $allowed_protocols;
114
+            private $allowed_html;
115
+            /**#@-*/
116
+
117
+            /**
118
+             *	Constructor for kses.
119
+             *
120
+             *	This sets a default collection of protocols allowed in links, and creates an
121
+             *	empty set of allowed HTML tags.
122
+             *	@since PHP5 OOP 1.0.0
123
+             */
124
+            public function __construct()
125
+            {
126
+                /**
127
+                 *	You could add protocols such as ftp, new, gopher, mailto, irc, etc.
128
+                 *
129
+                 *	The base values the original kses provided were:
130
+                 *		'http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto'
131
+                 */
132
+                $this->allowed_protocols = array('http', 'ftp', 'mailto');
133
+                $this->allowed_html      = array();
134
+            }
135
+
136
+            /**
137
+             *	Basic task of kses - parses $string and strips it as required.
138
+             *
139
+             *	This method strips all the disallowed (X)HTML tags, attributes
140
+             *	and protocols from the input $string.
141
+             *
142
+             *	@access public
143
+             *	@param string $string String to be stripped of 'evil scripts'
144
+             *	@return string The stripped string
145
+             *	@since PHP4 OOP 0.0.1
146
+             */
147
+            public function Parse($string = "")
148
+            {
149
+                if (get_magic_quotes_gpc())
150
+                {
151
+                    $string = stripslashes($string);
152
+                }
153
+                $string = $this->removeNulls($string);
154
+                //	Remove JavaScript entities from early Netscape 4 versions
155
+                $string = preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);
156
+                $string = $this->normalizeEntities($string);
157
+                $string = $this->filterKsesTextHook($string);
158
+                $string = preg_replace('%(<' . '[^>]*' . '(>|$)' . '|>)%e', "\$this->stripTags('\\1')", $string);
159
+                return $string;
160
+            }
161
+
162
+            /**
163
+             *	Allows for single/batch addition of protocols
164
+             *
165
+             *	This method accepts one argument that can be either a string
166
+             *	or an array of strings.  Invalid data will be ignored.
167
+             *
168
+             *	The argument will be processed, and each string will be added
169
+             *	via AddProtocol().
170
+             *
171
+             *	@access public
172
+             *	@param mixed , A string or array of protocols that will be added to the internal list of allowed protocols.
173
+             *	@return bool Status of adding valid protocols.
174
+             *	@see AddProtocol()
175
+             *	@since PHP5 OOP 1.0.0
176
+             */
177
+            public function AddProtocols()
178
+            {
179
+                $c_args = func_num_args();
180
+                if($c_args != 1)
181
+                {
182
+                    trigger_error("kses5::AddProtocols() did not receive an argument.", E_USER_WARNING);
183
+                    return false;
184
+                }
185
+
186
+                $protocol_data = func_get_arg(0);
187
+
188
+                if(is_array($protocol_data) && count($protocol_data) > 0)
189
+                {
190
+                    foreach($protocol_data as $protocol)
191
+                    {
192
+                        $this->AddProtocol($protocol);
193
+                    }
194
+                    return true;
195
+                }
196
+                elseif(is_string($protocol_data))
197
+                {
198
+                    $this->AddProtocol($protocol_data);
199
+                    return true;
200
+                }
201
+                else
202
+                {
203
+                    trigger_error("kses5::AddProtocols() did not receive a string or an array.", E_USER_WARNING);
204
+                    return false;
205
+                }
206
+            }
207
+
208
+            /**
209
+             *	Allows for single/batch addition of protocols
210
+             *
211
+             *	@deprecated Use AddProtocols()
212
+             *	@see AddProtocols()
213
+             *	@return bool
214
+             *	@since PHP4 OOP 0.0.1
215
+             */
216
+            public function Protocols()
217
+            {
218
+                $c_args = func_num_args();
219
+                if($c_args != 1)
220
+                {
221
+                    trigger_error("kses5::Protocols() did not receive an argument.", E_USER_WARNING);
222
+                    return false;
223
+                }
224
+
225
+                return $this->AddProtocols(func_get_arg(0));
226
+            }
227
+
228
+            /**
229
+             *	Adds a single protocol to $this->allowed_protocols.
230
+             *
231
+             *	This method accepts a string argument and adds it to
232
+             *	the list of allowed protocols to keep when performing
233
+             *	Parse().
234
+             *
235
+             *	@access public
236
+             *	@param string $protocol The name of the protocol to be added.
237
+             *	@return bool Status of adding valid protocol.
238
+             *	@since PHP4 OOP 0.0.1
239
+             */
240
+            public function AddProtocol($protocol = "")
241
+            {
242
+                if(!is_string($protocol))
243
+                {
244
+                    trigger_error("kses5::AddProtocol() requires a string.", E_USER_WARNING);
245
+                    return false;
246
+                }
247
+
248
+                // Remove any inadvertent ':' at the end of the protocol.
249
+                if(substr($protocol, strlen($protocol) - 1, 1) == ":")
250
+                {
251
+                    $protocol = substr($protocol, 0, strlen($protocol) - 1);
252
+                }
253
+
254
+                $protocol = strtolower(trim($protocol));
255
+                if($protocol == "")
256
+                {
257
+                    trigger_error("kses5::AddProtocol() tried to add an empty/NULL protocol.", E_USER_WARNING);
258
+                    return false;
259
+                }
260
+
261
+                //	prevent duplicate protocols from being added.
262
+                if(!in_array($protocol, $this->allowed_protocols))
263
+                {
264
+                    array_push($this->allowed_protocols, $protocol);
265
+                    sort($this->allowed_protocols);
266
+                }
267
+                return true;
268
+            }
269
+
270
+            /**
271
+             *	Removes a single protocol from $this->allowed_protocols.
272
+             *
273
+             *	This method accepts a string argument and removes it from
274
+             *	the list of allowed protocols to keep when performing
275
+             *	Parse().
276
+             *
277
+             *	@access public
278
+             *	@param string $protocol The name of the protocol to be removed.
279
+             *	@return bool Status of removing valid protocol.
280
+             *	@since PHP5 OOP 1.0.0
281
+             */
282
+            public function RemoveProtocol($protocol = "")
283
+            {
284
+                if(!is_string($protocol))
285
+                {
286
+                    trigger_error("kses5::RemoveProtocol() requires a string.", E_USER_WARNING);
287
+                    return false;
288
+                }
289
+
290
+                // Remove any inadvertent ':' at the end of the protocol.
291
+                if(substr($protocol, strlen($protocol) - 1, 1) == ":")
292
+                {
293
+                    $protocol = substr($protocol, 0, strlen($protocol) - 1);
294
+                }
295
+
296
+                $protocol = strtolower(trim($protocol));
297
+                if($protocol == "")
298
+                {
299
+                    trigger_error("kses5::RemoveProtocol() tried to remove an empty/NULL protocol.", E_USER_WARNING);
300
+                    return false;
301
+                }
302
+
303
+                //	Ensures that the protocol exists before removing it.
304
+                if(in_array($protocol, $this->allowed_protocols))
305
+                {
306
+                    $this->allowed_protocols = array_diff($this->allowed_protocols, array($protocol));
307
+                    sort($this->allowed_protocols);
308
+                }
309
+
310
+                return true;
311
+            }
312
+
313
+            /**
314
+             *	Allows for single/batch removal of protocols
315
+             *
316
+             *	This method accepts one argument that can be either a string
317
+             *	or an array of strings.  Invalid data will be ignored.
318
+             *
319
+             *	The argument will be processed, and each string will be removed
320
+             *	via RemoveProtocol().
321
+             *
322
+             *	@access public
323
+             *	@param mixed , A string or array of protocols that will be removed from the internal list of allowed protocols.
324
+             *	@return bool Status of removing valid protocols.
325
+             *	@see RemoveProtocol()
326
+             *	@since PHP5 OOP 1.0.0
327
+             */
328
+            public function RemoveProtocols()
329
+            {
330
+                $c_args = func_num_args();
331
+                if($c_args != 1)
332
+                {
333
+                    return false;
334
+                }
335
+
336
+                $protocol_data = func_get_arg(0);
337
+
338
+                if(is_array($protocol_data) && count($protocol_data) > 0)
339
+                {
340
+                    foreach($protocol_data as $protocol)
341
+                    {
342
+                        $this->RemoveProtocol($protocol);
343
+                    }
344
+                }
345
+                elseif(is_string($protocol_data))
346
+                {
347
+                    $this->RemoveProtocol($protocol_data);
348
+                    return true;
349
+                }
350
+                else
351
+                {
352
+                    trigger_error("kses5::RemoveProtocols() did not receive a string or an array.", E_USER_WARNING);
353
+                    return false;
354
+                }
355
+            }
356
+
357
+            /**
358
+             *	Allows for single/batch replacement of protocols
359
+             *
360
+             *	This method accepts one argument that can be either a string
361
+             *	or an array of strings.  Invalid data will be ignored.
362
+             *
363
+             *	Existing protocols will be removed, then the argument will be
364
+             *	processed, and each string will be added via AddProtocol().
365
+             *
366
+             *	@access public
367
+             *	@param mixed , A string or array of protocols that will be the new internal list of allowed protocols.
368
+             *	@return bool Status of replacing valid protocols.
369
+             *	@since PHP5 OOP 1.0.1
370
+             *	@see AddProtocol()
371
+             */
372
+            public function SetProtocols()
373
+            {
374
+                $c_args = func_num_args();
375
+                if($c_args != 1)
376
+                {
377
+                    trigger_error("kses5::SetProtocols() did not receive an argument.", E_USER_WARNING);
378
+                    return false;
379
+                }
380
+
381
+                $protocol_data = func_get_arg(0);
382
+
383
+                if(is_array($protocol_data) && count($protocol_data) > 0)
384
+                {
385
+                    $this->allowed_protocols = array();
386
+                    foreach($protocol_data as $protocol)
387
+                    {
388
+                        $this->AddProtocol($protocol);
389
+                    }
390
+                    return true;
391
+                }
392
+                elseif(is_string($protocol_data))
393
+                {
394
+                    $this->allowed_protocols = array();
395
+                    $this->AddProtocol($protocol_data);
396
+                    return true;
397
+                }
398
+                else
399
+                {
400
+                    trigger_error("kses5::SetProtocols() did not receive a string or an array.", E_USER_WARNING);
401
+                    return false;
402
+                }
403
+            }
404
+
405
+            /**
406
+             *	Raw dump of allowed protocols
407
+             *
408
+             *	This returns an indexed array of allowed protocols for a particular KSES
409
+             *	instantiation.
410
+             *
411
+             *	@access public
412
+             *	@return array The list of allowed protocols.
413
+             *	@since PHP5 OOP 1.0.2
414
+             */
415
+            public function DumpProtocols()
416
+            {
417
+                return $this->allowed_protocols;
418
+            }
419
+
420
+            /**
421
+             *	Raw dump of allowed (X)HTML elements
422
+             *
423
+             *	This returns an indexed array of allowed (X)HTML elements and attributes
424
+             *	for a particular KSES instantiation.
425
+             *
426
+             *	@access public
427
+             *	@return array The list of allowed elements.
428
+             *	@since PHP5 OOP 1.0.2
429
+             */
430
+            public function DumpElements()
431
+            {
432
+                return $this->allowed_html;
433
+            }
434
+
435
+
436
+            /**
437
+             *	Adds valid (X)HTML with corresponding attributes that will be kept when stripping 'evil scripts'.
438
+             *
439
+             *	This method accepts one argument that can be either a string
440
+             *	or an array of strings.  Invalid data will be ignored.
441
+             *
442
+             *	@access public
443
+             *	@param string $tag (X)HTML tag that will be allowed after stripping text.
444
+             *	@param array $attribs Associative array of allowed attributes - key => attribute name - value => attribute parameter
445
+             *	@return bool Status of Adding (X)HTML and attributes.
446
+             *	@since PHP4 OOP 0.0.1
447
+             */
448
+            public function AddHTML($tag = "", $attribs = array())
449
+            {
450
+                if(!is_string($tag))
451
+                {
452
+                    trigger_error("kses5::AddHTML() requires the tag to be a string", E_USER_WARNING);
453
+                    return false;
454
+                }
455
+
456
+                $tag = strtolower(trim($tag));
457
+                if($tag == "")
458
+                {
459
+                    trigger_error("kses5::AddHTML() tried to add an empty/NULL tag", E_USER_WARNING);
460
+                    return false;
461
+                }
462
+
463
+                if(!is_array($attribs))
464
+                {
465
+                    trigger_error("kses5::AddHTML() requires an array (even an empty one) of attributes for '$tag'", E_USER_WARNING);
466
+                    return false;
467
+                }
468
+
469
+                $new_attribs = array();
470
+                if(is_array($attribs) && count($attribs) > 0)
471
+                {
472
+                    foreach($attribs as $idx1 => $val1)
473
+                    {
474
+                        $new_idx1 = strtolower($idx1);
475
+                        $new_val1 = $attribs[$idx1];
476
+
477
+                        if(is_array($new_val1) && count($attribs) > 0)
478
+                        {
479
+                            $tmp_val = array();
480
+                            foreach($new_val1 as $idx2 => $val2)
481
+                            {
482
+                                $new_idx2 = strtolower($idx2);
483
+                                $tmp_val[$new_idx2] = $val2;
484
+                            }
485
+                            $new_val1 = $tmp_val;
486
+                        }
487
+
488
+                        $new_attribs[$new_idx1] = $new_val1;
489
+                    }
490
+                }
491
+
492
+                $this->allowed_html[$tag] = $new_attribs;
493
+                return true;
494
+            }
495
+
496
+            /**
497
+             *	This method removes any NULL characters in $string.
498
+             *
499
+             *	@access private
500
+             *	@param string $string
501
+             *	@return string String without any NULL/chr(173)
502
+             *	@since PHP4 OOP 0.0.1
503
+             */
504
+            private function removeNulls($string)
505
+            {
506
+                $string = preg_replace('/\0+/', '', $string);
507
+                $string = preg_replace('/(\\\\0)+/', '', $string);
508
+                return $string;
509
+            }
510
+
511
+            /**
512
+             *	Normalizes HTML entities
513
+             *
514
+             *	This function normalizes HTML entities. It will convert "AT&T" to the correct
515
+             *	"AT&amp;T", "&#00058;" to "&#58;", "&#XYZZY;" to "&amp;#XYZZY;" and so on.
516
+             *
517
+             *	@access private
518
+             *	@param string $string
519
+             *	@return string String with normalized entities
520
+             *	@since PHP4 OOP 0.0.1
521
+             */
522
+            private function normalizeEntities($string)
523
+            {
524
+                # Disarm all entities by converting & to &amp;
525
+                $string = str_replace('&', '&amp;', $string);
526
+
527
+                #	TODO: Change back (Keep?) the allowed entities in our entity white list
528
+
529
+                #	Keeps entities that start with [A-Za-z]
530
+                $string = preg_replace(
531
+                    '/&amp;([A-Za-z][A-Za-z0-9]{0,19});/',
532
+                    '&\\1;',
533
+                    $string
534
+                );
535
+
536
+                #	Change numeric entities to valid 16 bit values
537
+
538
+                $string = preg_replace(
539
+                    '/&amp;#0*([0-9]{1,5});/e',
540
+                    '\$this->normalizeEntities16bit("\\1")',
541
+                    $string
542
+                );
543
+
544
+                #	Change &XHHHHHHH (Hex digits) to 16 bit hex values
545
+                $string = preg_replace(
546
+                    '/&amp;#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/',
547
+                    '&#\\1\\2;',
548
+                    $string
549
+                );
550
+
551
+                return $string;
552
+            }
553
+
554
+            /**
555
+             *	Helper method used by normalizeEntites()
556
+             *
557
+             *	This method helps normalizeEntities() to only accept 16 bit values
558
+             *	and nothing more for &#number; entities.
559
+             *
560
+             *	This method helps normalize_entities() during a preg_replace()
561
+             *	where a &#(0)*XXXXX; occurs.  The '(0)*XXXXXX' value is converted to
562
+             *	a number and the result is returned as a numeric entity if the number
563
+             *	is less than 65536.  Otherwise, the value is returned 'as is'.
564
+             *
565
+             *	@access private
566
+             *	@param string $i
567
+             *	@return string Normalized numeric entity
568
+             *	@see normalizeEntities()
569
+             *	@since PHP4 OOP 0.0.1
570
+             */
571
+            private function normalizeEntities16bit($i)
572
+            {
573
+                return (($i > 65535) ? "&amp;#$i;" : "&#$i;");
574
+            }
575
+
576
+            /**
577
+             *	Allows for additional user defined modifications to text.
578
+             *
579
+             *	This method allows for additional modifications to be performed on
580
+             *	a string that's being run through Parse().  Currently, it returns the
581
+             *	input string 'as is'.
582
+             *
583
+             *	This method is provided for users to extend the kses class for their own
584
+             *	requirements.
585
+             *
586
+             *	@access public
587
+             *	@param string $string String to perfrom additional modifications on.
588
+             *	@return string User modified string.
589
+             *	@see Parse()
590
+             *	@since PHP5 OOP 1.0.0
591
+             */
592
+            private function filterKsesTextHook($string)
593
+            {
594
+                return $string;
595
+            }
596
+
597
+            /**
598
+             *	Allows for additional user defined modifications to text.
599
+             *
600
+             *	@deprecated use filterKsesTextHook()
601
+             *	@param string $string
602
+             *	@return string
603
+             *	@see filterKsesTextHook()
604
+             *	@since PHP4 OOP 0.0.1
605
+             */
606
+            private function _hook($string)
607
+            {
608
+                return $this->filterKsesTextHook($string);
609
+            }
610
+
611
+            /**
612
+             *	This method goes through an array, and changes the keys to all lower case.
613
+             *
614
+             *	@access private
615
+             *	@param array $in_array Associative array
616
+             *	@return array Modified array
617
+             *	@since PHP4 OOP 0.0.1
618
+             */
619
+            private function makeArrayKeysLowerCase($in_array)
620
+            {
621
+                $out_array = array();
622
+
623
+                if(is_array($in_array) && count($in_array) > 0)
624
+                {
625
+                    foreach ($in_array as $in_key => $in_val)
626
+                    {
627
+                        $out_key = strtolower($in_key);
628
+                        $out_array[$out_key] = array();
629
+
630
+                        if(is_array($in_val) && count($in_val) > 0)
631
+                        {
632
+                            foreach ($in_val as $in_key2 => $in_val2)
633
+                            {
634
+                                $out_key2 = strtolower($in_key2);
635
+                                $out_array[$out_key][$out_key2] = $in_val2;
636
+                            }
637
+                        }
638
+                    }
639
+                }
640
+
641
+                return $out_array;
642
+            }
643
+
644
+            /**
645
+             *	This method strips out disallowed and/or mangled (X)HTML tags along with assigned attributes.
646
+             *
647
+             *	This method does a lot of work. It rejects some very malformed things
648
+             *	like <:::>. It returns an empty string if the element isn't allowed (look
649
+             *	ma, no strip_tags()!). Otherwise it splits the tag into an element and an
650
+             *	allowed attribute list.
651
+             *
652
+             *	@access private
653
+             *	@param string $string
654
+             *	@return string Modified string minus disallowed/mangled (X)HTML and attributes
655
+             *	@since PHP4 OOP 0.0.1
656
+             */
657
+            private function stripTags($string)
658
+            {
659
+                $string = preg_replace('%\\\\"%', '"', $string);
660
+
661
+                if (substr($string, 0, 1) != '<')
662
+                {
663
+                    # It matched a ">" character
664
+                    return '&gt;';
665
+                }
666
+
667
+                if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
668
+                {
669
+                    # It's seriously malformed
670
+                    return '';
671
+                }
672
+
673
+                $slash    = trim($matches[1]);
674
+                $elem     = $matches[2];
675
+                $attrlist = $matches[3];
676
+
677
+                if (
678
+                    !isset($this->allowed_html[strtolower($elem)]) ||
679
+                    !is_array($this->allowed_html[strtolower($elem)]))
680
+                {
681
+                    #	Found an HTML element not in the white list
682
+                    return '';
683
+                }
684
+
685
+                if ($slash != '')
686
+                {
687
+                    return "<$slash$elem>";
688
+                }
689
+                # No attributes are allowed for closing elements
690
+
691
+                return $this->stripAttributes("$slash$elem", $attrlist);
692
+            }
693
+
694
+            /**
695
+             *	This method strips out disallowed attributes for (X)HTML tags.
696
+             *
697
+             *	This method removes all attributes if none are allowed for this element.
698
+             *	If some are allowed it calls combAttributes() to split them further, and then it
699
+             *	builds up new HTML code from the data that combAttributes() returns. It also
700
+             *	removes "<" and ">" characters, if there are any left. One more thing it
701
+             *	does is to check if the tag has a closing XHTML slash, and if it does,
702
+             *	it puts one in the returned code as well.
703
+             *
704
+             *	@access private
705
+             *	@param string $element (X)HTML tag to check
706
+             *	@param string $attr Text containing attributes to check for validity.
707
+             *	@return string Resulting valid (X)HTML or ''
708
+             *	@see combAttributes()
709
+             *	@since PHP4 OOP 0.0.1
710
+             */
711
+            private function stripAttributes($element, $attr)
712
+            {
713
+                # Is there a closing XHTML slash at the end of the attributes?
714
+                $xhtml_slash = '';
715
+                if (preg_match('%\s/\s*$%', $attr))
716
+                {
717
+                    $xhtml_slash = ' /';
718
+                }
719
+
720
+                # Are any attributes allowed at all for this element?
721
+                if (
722
+                    !isset($this->allowed_html[strtolower($element)]) ||
723
+                    count($this->allowed_html[strtolower($element)]) == 0
724
+                )
725
+                {
726
+                    return "<$element$xhtml_slash>";
727
+                }
728
+
729
+                # Split it
730
+                $attrarr = $this->combAttributes($attr);
731
+
732
+                # Go through $attrarr, and save the allowed attributes for this element
733
+                # in $attr2
734
+                $attr2 = '';
735
+                if(is_array($attrarr) && count($attrarr) > 0)
736
+                {
737
+                    foreach ($attrarr as $arreach)
738
+                    {
739
+                        if(!isset($this->allowed_html[strtolower($element)][strtolower($arreach['name'])]))
740
+                        {
741
+                            continue;
742
+                        }
743
+
744
+                        $current = $this->allowed_html[strtolower($element)][strtolower($arreach['name'])];
745
+
746
+                        if (!is_array($current))
747
+                        {
748
+                            # there are no checks
749
+                            $attr2 .= ' '.$arreach['whole'];
750
+                        }
751
+                        else
752
+                        {
753
+                            # there are some checks
754
+                            $ok = true;
755
+                            if(is_array($current) && count($current) > 0)
756
+                            {
757
+                                foreach ($current as $currkey => $currval)
758
+                                {
759
+                                    if (!$this->checkAttributeValue($arreach['value'], $arreach['vless'], $currkey, $currval))
760
+                                    {
761
+                                        $ok = false;
762
+                                        break;
763
+                                    }
764
+                                }
765
+                            }
766
+
767
+                            if ($ok)
768
+                            {
769
+                                # it passed them
770
+                                $attr2 .= ' '.$arreach['whole'];
771
+                            }
772
+                        }
773
+                    }
774
+                }
775
+
776
+                # Remove any "<" or ">" characters
777
+                $attr2 = preg_replace('/[<>]/', '', $attr2);
778
+                return "<$element$attr2$xhtml_slash>";
779
+            }
780
+
781
+            /**
782
+             *	This method combs through an attribute list string and returns an associative array of attributes and values.
783
+             *
784
+             *	This method does a lot of work. It parses an attribute list into an array
785
+             *	with attribute data, and tries to do the right thing even if it gets weird
786
+             *	input. It will add quotes around attribute values that don't have any quotes
787
+             *	or apostrophes around them, to make it easier to produce HTML code that will
788
+             *	conform to W3C's HTML specification. It will also remove bad URL protocols
789
+             *	from attribute values.
790
+             *
791
+             *	@access private
792
+             *	@param string $attr Text containing tag attributes for parsing
793
+             *	@return array Associative array containing data on attribute and value
794
+             *	@since PHP4 OOP 0.0.1
795
+             */
796
+            private function combAttributes($attr)
797
+            {
798
+                $attrarr  = array();
799
+                $mode     = 0;
800
+                $attrname = '';
801
+
802
+                # Loop through the whole attribute list
803
+
804
+                while (strlen($attr) != 0)
805
+                {
806
+                    # Was the last operation successful?
807
+                    $working = 0;
808
+
809
+                    switch ($mode)
810
+                    {
811
+                        case 0:	# attribute name, href for instance
812
+                            if (preg_match('/^([-a-zA-Z]+)/', $attr, $match))
813
+                            {
814
+                                $attrname = $match[1];
815
+                                $working = $mode = 1;
816
+                                $attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
817
+                            }
818
+                            break;
819
+                        case 1:	# equals sign or valueless ("selected")
820
+                            if (preg_match('/^\s*=\s*/', $attr)) # equals sign
821
+                            {
822
+                                $working = 1;
823
+                                $mode    = 2;
824
+                                $attr    = preg_replace('/^\s*=\s*/', '', $attr);
825
+                                break;
826
+                            }
827
+                            if (preg_match('/^\s+/', $attr)) # valueless
828
+                            {
829
+                                $working   = 1;
830
+                                $mode      = 0;
831
+                                $attrarr[] = array(
832
+                                    'name'  => $attrname,
833
+                                    'value' => '',
834
+                                    'whole' => $attrname,
835
+                                    'vless' => 'y'
836
+                                );
837
+                                $attr      = preg_replace('/^\s+/', '', $attr);
838
+                            }
839
+                            break;
840
+                        case 2: # attribute value, a URL after href= for instance
841
+                            if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match)) # "value"
842
+                            {
843
+                                $thisval   = $this->removeBadProtocols($match[1]);
844
+                                $attrarr[] = array(
845
+                                    'name'  => $attrname,
846
+                                    'value' => $thisval,
847
+                                    'whole' => $attrname . '="' . $thisval . '"',
848
+                                    'vless' => 'n'
849
+                                );
850
+                                $working   = 1;
851
+                                $mode      = 0;
852
+                                $attr      = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
853
+                                break;
854
+                            }
855
+                            if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match)) # 'value'
856
+                            {
857
+                                $thisval   = $this->removeBadProtocols($match[1]);
858
+                                $attrarr[] = array(
859
+                                    'name'  => $attrname,
860
+                                    'value' => $thisval,
861
+                                    'whole' => "$attrname='$thisval'",
862
+                                    'vless' => 'n'
863
+                                );
864
+                                $working   = 1;
865
+                                $mode      = 0;
866
+                                $attr      = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
867
+                                break;
868
+                            }
869
+                            if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match)) # value
870
+                            {
871
+                                $thisval   = $this->removeBadProtocols($match[1]);
872
+                                $attrarr[] = array(
873
+                                    'name'  => $attrname,
874
+                                    'value' => $thisval,
875
+                                    'whole' => $attrname . '="' . $thisval . '"',
876
+                                    'vless' => 'n'
877
+                                );
878
+                                # We add quotes to conform to W3C's HTML spec.
879
+                                $working   = 1;
880
+                                $mode      = 0;
881
+                                $attr      = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
882
+                            }
883
+                            break;
884
+                    }
885
+
886
+                    if ($working == 0) # not well formed, remove and try again
887
+                    {
888
+                        $attr = preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $attr);
889
+                        $mode = 0;
890
+                    }
891
+                }
892
+
893
+                # special case, for when the attribute list ends with a valueless
894
+                # attribute like "selected"
895
+                if ($mode == 1)
896
+                {
897
+                    $attrarr[] = array(
898
+                        'name'  => $attrname,
899
+                        'value' => '',
900
+                        'whole' => $attrname,
901
+                        'vless' => 'y'
902
+                    );
903
+                }
904
+
905
+                return $attrarr;
906
+            }
907
+
908
+            /**
909
+             *	This method removes disallowed protocols.
910
+             *
911
+             *	This method removes all non-allowed protocols from the beginning of
912
+             *	$string. It ignores whitespace and the case of the letters, and it does
913
+             *	understand HTML entities. It does its work in a while loop, so it won't be
914
+             *	fooled by a string like "javascript:javascript:alert(57)".
915
+             *
916
+             *	@access private
917
+             *	@param string $string String to check for protocols
918
+             *	@return string String with removed protocols
919
+             *	@since PHP4 OOP 0.0.1
920
+             */
921
+            private function removeBadProtocols($string)
922
+            {
923
+                $string  = $this->RemoveNulls($string);
924
+                $string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature"
925
+                $string2 = $string . 'a';
926
+
927
+                $string2 = preg_split('/:|&#58;|&#x3a;/i', $string, 2);
928
+                if(isset($string2[1]) && !preg_match('%/\?%',$string2[0]))
929
+                {
930
+                    $string = $this->filterProtocols($string2[0]).trim($string2[1]);
931
+                }
932
+                return $string;
933
+            }
934
+
935
+            /**
936
+             *	Helper method used by removeBadProtocols()
937
+             *
938
+             *	This function processes URL protocols, checks to see if they're in the white-
939
+             *	list or not, and returns different data depending on the answer.
940
+             *
941
+             *	@access private
942
+             *	@param string $string String to check for protocols
943
+             *	@return string String with removed protocols
944
+             *	@see removeBadProtocols()
945
+             *	@since PHP4 OOP 0.0.1
946
+             */
947
+            private function filterProtocols($string)
948
+            {
949
+                $string = $this->decodeEntities($string);
950
+                $string = preg_replace('/\s/', '', $string);
951
+                $string = $this->removeNulls($string);
952
+                $string = preg_replace('/\xad+/', '', $string2); # deals with Opera "feature"
953
+                $string = strtolower($string);
954
+
955
+                if(is_array($this->allowed_protocols) && count($this->allowed_protocols) > 0)
956
+                {
957
+                    foreach ($this->allowed_protocols as $one_protocol)
958
+                    {
959
+                        if (strtolower($one_protocol) == $string)
960
+                        {
961
+                            return "$string:";
962
+                        }
963
+                    }
964
+                }
965
+
966
+                return '';
967
+            }
968
+
969
+            /**
970
+             *	Controller method for performing checks on attribute values.
971
+             *
972
+             *	This method calls the appropriate method as specified by $checkname with
973
+             *	the parameters $value, $vless, and $checkvalue, and returns the result
974
+             *	of the call.
975
+             *
976
+             *	This method's functionality can be expanded by creating new methods
977
+             *	that would match checkAttributeValue[$checkname].
978
+             *
979
+             *	Current checks implemented are: "maxlen", "minlen", "maxval", "minval" and "valueless"
980
+             *
981
+             *	@access private
982
+             *	@param string $value The value of the attribute to be checked.
983
+             *	@param string $vless Indicates whether the the value is supposed to be valueless
984
+             *	@param string $checkname The check to be performed
985
+             *	@param string $checkvalue The value that is to be checked against
986
+             *	@return bool Indicates whether the check passed or not
987
+             *	@since PHP5 OOP 1.0.0
988
+             */
989
+            private function checkAttributeValue($value, $vless, $checkname, $checkvalue)
990
+            {
991
+                $ok = true;
992
+                $check_attribute_method_name  = 'checkAttributeValue' . ucfirst(strtolower($checkname));
993
+                if(method_exists($this, $check_attribute_method_name))
994
+                {
995
+                    $ok = $this->$check_attribute_method_name($value, $checkvalue, $vless);
996
+                }
997
+
998
+                return $ok;
999
+            }
1000
+
1001
+            /**
1002
+             *	Helper method invoked by checkAttributeValue().
1003
+             *
1004
+             *	The maxlen check makes sure that the attribute value has a length not
1005
+             *	greater than the given value. This can be used to avoid Buffer Overflows
1006
+             *	in WWW clients and various Internet servers.
1007
+             *
1008
+             *	@access private
1009
+             *	@param string $value The value of the attribute to be checked.
1010
+             *	@param int $checkvalue The maximum value allowed
1011
+             *	@return bool Indicates whether the check passed or not
1012
+             *	@see checkAttributeValue()
1013
+             *	@since PHP5 OOP 1.0.0
1014
+             */
1015
+            private function checkAttributeValueMaxlen($value, $checkvalue)
1016
+            {
1017
+                if (strlen($value) > intval($checkvalue))
1018
+                {
1019
+                    return false;
1020
+                }
1021
+                return true;
1022
+            }
1023
+
1024
+            /**
1025
+             *	Helper method invoked by checkAttributeValue().
1026
+             *
1027
+             *	The minlen check makes sure that the attribute value has a length not
1028
+             *	smaller than the given value.
1029
+             *
1030
+             *	@access private
1031
+             *	@param string $value The value of the attribute to be checked.
1032
+             *	@param int $checkvalue The minimum value allowed
1033
+             *	@return bool Indicates whether the check passed or not
1034
+             *	@see checkAttributeValue()
1035
+             *	@since PHP5 OOP 1.0.0
1036
+             */
1037
+            private function checkAttributeValueMinlen($value, $checkvalue)
1038
+            {
1039
+                if (strlen($value) < intval($checkvalue))
1040
+                {
1041
+                    return false;
1042
+                }
1043
+                return true;
1044
+            }
1045
+
1046
+            /**
1047
+             *	Helper method invoked by checkAttributeValue().
1048
+             *
1049
+             *	The maxval check does two things: it checks that the attribute value is
1050
+             *	an integer from 0 and up, without an excessive amount of zeroes or
1051
+             *	whitespace (to avoid Buffer Overflows). It also checks that the attribute
1052
+             *	value is not greater than the given value.
1053
+             *
1054
+             *	This check can be used to avoid Denial of Service attacks.
1055
+             *
1056
+             *	@access private
1057
+             *	@param int $value The value of the attribute to be checked.
1058
+             *	@param int $checkvalue The maximum numeric value allowed
1059
+             *	@return bool Indicates whether the check passed or not
1060
+             *	@see checkAttributeValue()
1061
+             *	@since PHP5 OOP 1.0.0
1062
+             */
1063
+            private function checkAttributeValueMaxval($value, $checkvalue)
1064
+            {
1065
+                if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
1066
+                {
1067
+                    return false;
1068
+                }
1069
+                if (intval($value) > intval($checkvalue))
1070
+                {
1071
+                    return false;
1072
+                }
1073
+                return true;
1074
+            }
1075
+
1076
+            /**
1077
+             *	Helper method invoked by checkAttributeValue().
1078
+             *
1079
+             *	The minval check checks that the attribute value is a positive integer,
1080
+             *	and that it is not smaller than the given value.
1081
+             *
1082
+             *	@access private
1083
+             *	@param int $value The value of the attribute to be checked.
1084
+             *	@param int $checkvalue The minimum numeric value allowed
1085
+             *	@return bool Indicates whether the check passed or not
1086
+             *	@see checkAttributeValue()
1087
+             *	@since PHP5 OOP 1.0.0
1088
+             */
1089
+            private function checkAttributeValueMinval($value, $checkvalue)
1090
+            {
1091
+                if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
1092
+                {
1093
+                    return false;
1094
+                }
1095
+                if (intval($value) < ($checkvalue))
1096
+                {
1097
+                    return false;
1098
+                }
1099
+                return true;
1100
+            }
1101
+
1102
+            /**
1103
+             *	Helper method invoked by checkAttributeValue().
1104
+             *
1105
+             *	The valueless check checks if the attribute has a value
1106
+             *	(like <a href="blah">) or not (<option selected>). If the given value
1107
+             *	is a "y" or a "Y", the attribute must not have a value.
1108
+             *
1109
+             *	If the given value is an "n" or an "N", the attribute must have one.
1110
+             *
1111
+             *	@access private
1112
+             *	@param int $value The value of the attribute to be checked.
1113
+             *	@param mixed $checkvalue This variable is ignored for this test
1114
+             *	@param string $vless Flag indicating if this attribute is not supposed to have an attribute
1115
+             *	@return bool Indicates whether the check passed or not
1116
+             *	@see checkAttributeValue()
1117
+             *	@since PHP5 OOP 1.0.0
1118
+             */
1119
+            private function checkAttributeValueValueless($value, $checkvalue, $vless)
1120
+            {
1121
+                if (strtolower($checkvalue) != $vless)
1122
+                {
1123
+                    return false;
1124
+                }
1125
+                return true;
1126
+            }
1127
+
1128
+            /**
1129
+             *	Decodes numeric HTML entities
1130
+             *
1131
+             *	This method decodes numeric HTML entities (&#65; and &#x41;). It doesn't
1132
+             *	do anything with other entities like &auml;, but we don't need them in the
1133
+             *	URL protocol white listing system anyway.
1134
+             *
1135
+             *	@access private
1136
+             *	@param string $value The entitiy to be decoded.
1137
+             *	@return string Decoded entity
1138
+             *	@since PHP4 OOP 0.0.1
1139
+             */
1140
+            private function decodeEntities($string)
1141
+            {
1142
+                $string = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $string);
1143
+                $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', 'chr(hexdec("\\1"))', $string);
1144
+                return $string;
1145
+            }
1146
+
1147
+            /**
1148
+             *	Returns PHP5 OOP version # of kses.
1149
+             *
1150
+             *	Since this class has been refactored and documented and proven to work,
1151
+             *	I'm fixing the version number at 1.0.0.
1152
+             *
1153
+             *	This version is syntax compatible with the PHP4 OOP version 0.0.2.  Future
1154
+             *	versions may not be syntax compatible.
1155
+             *
1156
+             *	@access public
1157
+             *	@return string Version number
1158
+             *	@since PHP4 OOP 0.0.1
1159
+             */
1160
+            public function Version()
1161
+            {
1162
+                return 'PHP5 OOP 1.0.2';
1163
+            }
1164
+        }
1165
+    }
1166 1166
 ?>
1167 1167
\ No newline at end of file
Please login to merge, or discard this patch.
main/inc/lib/kses-0.2.2/oop/test.oop.kses.php 1 patch
Indentation   +503 added lines, -503 removed lines patch added patch discarded remove patch
@@ -1,507 +1,507 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	//	This is a q&d program that shows some of the results of
4
-	//	running KSES.  If you have further questions, check the
5
-	//	current valid email address at http://chaos.org/contact/
6
-
7
-	//	Make sure we're in a usable PHP environment
8
-	if(substr(phpversion(), 0, 1) < 4)
9
-	{
10
-		define('KSESTEST_VER', 0);
11
-	}
12
-	elseif(substr(phpversion(), 0, 1) >= 5)
13
-	{
14
-		define('KSESTEST_VER', 5);
15
-	}
16
-	else
17
-	{
18
-		define('KSESTEST_VER', 4);
19
-	}
20
-
21
-	//	See if we're in command line or web
22
-	if($_SERVER["DOCUMENT_ROOT"] == "")
23
-	{
24
-		define('KSESTEST_ENV', 'CLI');
25
-	}
26
-	else
27
-	{
28
-		define('KSESTEST_ENV', 'WEB');
29
-	}
30
-
31
-	if(KSESTEST_VER == 0)
32
-	{
33
-		$message = array(
34
-			"Error: Not using a current version of PHP!",
35
-			"You are using PHP version " . phpversion() . ".",
36
-			"KSES Class version requires PHP4 or better.",
37
-			"KSES test program ending."
38
-			);
39
-
40
-		displayPage(
41
-			array("title" => "Error running KSES test", "message" => $message)
42
-		);
43
-
44
-		exit();
45
-	}
46
-
47
-	$include_file = "php" . KSESTEST_VER . ".class.kses.php";
48
-	if(file_exists($include_file) && is_readable($include_file))
49
-	{
50
-		include_once($include_file);
51
-	}
52
-	else
53
-	{
54
-		$message = array(
55
-			"Error:  Unable to find '" . $include_file . "'.",
56
-			"Please check your include path and make sure the file is available.",
57
-			"Path: " . ini_get('include_path')
58
-		);
59
-
60
-		displayPage(
61
-			array('title' => 'Unable to include ' . $include_file, 'message' => $message)
62
-		);
63
-
64
-		exit();
65
-	}
66
-
67
-	$kses_type = "kses" . KSESTEST_VER;
68
-	$myKses = new $kses_type;
69
-
70
-	$test_text = array();
71
-	$test_text = test1_protocols($myKses);
72
-	$test_text = array_merge($test_text, test1_html($myKses));
73
-	$test_text = array_merge($test_text, test1_kses($myKses));
74
-
75
-	displayPage(
76
-		array('title' => 'New Test', 'message' => $test_text)
77
-	);
78
-
79
-	function test1_kses(&$myKses)
80
-	{
81
-		$out = array(output_hr(), "Testing current configuration");
82
-
83
-		$test_tags = array(
84
-			'<a href="http://www.chaos.org/">www.chaos.org</a>',
85
-			'<a name="X">Short \'a name\' tag</a>',
86
-			'<td colspan="3" rowspan="5">Foo</td>',
87
-			'<td rowspan="2" class="mugwump" style="background-color: rgb(255, 204 204);">Bar</td>',
88
-			'<td nowrap>Very Long String running to 1000 characters...</td>',
89
-			'<td bgcolor="#00ff00" nowrap>Very Long String with a blue background</td>',
90
-			'<a href="proto1://www.foo.com">New protocol test</a>',
91
-			'<img src="proto2://www.foo.com" />',
92
-			'<a href="javascript:javascript:javascript:javascript:javascript:alert(\'Boo!\');">bleep</a>',
93
-			'<a href="proto4://abc.xyz.foo.com">Another new protocol</a>',
94
-			'<a href="proto9://foo.foo.foo.foo.foo.org/">Test of "proto9"</a>',
95
-			'<td width="75">Bar!</td>',
96
-			'<td width="200">Long Cell</td>'
97
-		);
98
-
99
-		$out_li = array();
100
-		// Keep only allowed HTML from the presumed 'form'.
101
-		foreach($test_tags as $tag)
102
-		{
103
-			$temp  = $myKses->Parse($tag);
104
-			$check = ($temp == $tag) ? true : false;
105
-			$text  = ($temp == $tag) ? 'pass' : 'fail';
106
-
107
-			$li_text  = output_testresult($check, $text) . output_newline();
108
-			$li_text .= "Input: &nbsp;" . output_translate($tag) . output_newline();
109
-			$li_text .= "Output: " . output_translate($temp);
110
-			if(KSESTEST_ENV == 'CLI')
111
-			{
112
-				$li_text .= output_newline();
113
-			}
114
-
115
-			array_push($out_li, output_code_wrap($li_text));
116
-		}
117
-
118
-		$out = array_merge($out, array(output_ul($out_li)));
119
-		array_push($out, output_hr());
120
-		array_push($out, "Testing is now finished.");
121
-		return $out;
122
-	}
123
-
124
-	function output_code_wrap($text)
125
-	{
126
-		if(KSESTEST_ENV == 'CLI')
127
-		{
128
-			return $text;
129
-		}
130
-		else
131
-		{
132
-			return "<code>\n$text<code>\n";
133
-		}
134
-	}
135
-
136
-	function output_translate($text)
137
-	{
138
-		if(KSESTEST_ENV == 'CLI')
139
-		{
140
-			return $text;
141
-		}
142
-		else
143
-		{
144
-			return htmlentities($text);
145
-		}
146
-	}
147
-
148
-	function output_testresult($pass = false, $text = "")
149
-	{
150
-		if(KSESTEST_ENV == 'CLI')
151
-		{
152
-			return '[' . $text . ']';
153
-		}
154
-		else
155
-		{
156
-			if($pass == true)
157
-			{
158
-				return '<span style="color: green;">[' . $text . ']</span>';
159
-			}
160
-			else
161
-			{
162
-				return '<span style="color: red;">[' . $text . ']</span>';
163
-			}
164
-		}
165
-	}
166
-
167
-	function output_spaces()
168
-	{
169
-		if(KSESTEST_ENV == 'WEB')
170
-		{
171
-			$out = "&nbsp;&nbsp;&nbsp;";
172
-		}
173
-		else
174
-		{
175
-			$out = "   ";
176
-		}
177
-
178
-		return $out;
179
-	}
180
-
181
-	function output_newline()
182
-	{
183
-		if(KSESTEST_ENV == 'WEB')
184
-		{
185
-			$out = "<br />\n";
186
-		}
187
-		else
188
-		{
189
-			$out = "\n";
190
-		}
191
-
192
-		return $out;
193
-	}
194
-
195
-	function displayPage($data = array())
196
-	{
197
-		$title   = ($data['title'] == '') ? 'No title' : $data['title'];
198
-		$message = ($data['message'] == '') ? array('No message') : $data['message'];
199
-
200
-		$out = "";
201
-
202
-		foreach($message as $text)
203
-		{
204
-			if(KSESTEST_ENV == 'WEB')
205
-			{
206
-				$header = "\t\t<h1>$title</h1>\n\t\t<hr />\n";
207
-				$out .= "\t\t<p>\n";
208
-				$out .= "\t\t\t$text\n";
209
-				$out .= "\t\t</p>\n";
210
-			}
211
-			else
212
-			{
213
-				$header = "$title\n" . str_repeat('-', 60) . "\n\n";
214
-				$out .= "\t$text\n\n";
215
-			}
216
-		}
217
-
218
-		if(KSESTEST_ENV == 'WEB')
219
-		{
220
-			echo "<html>\n";
221
-			echo "\t<head>\n";
222
-			echo "\t\t<title>$title</title>\n";
223
-			echo "\t</head>\n";
224
-			echo "\t<body>\n";
225
-			echo $header;
226
-			echo $out;
227
-			echo "\t</body>\n";
228
-			echo "</html>\n";
229
-		}
230
-		else
231
-		{
232
-			echo $header;
233
-			echo $out;
234
-		}
235
-	}
236
-
237
-	function output_hr()
238
-	{
239
-		if(KSESTEST_ENV == 'WEB')
240
-		{
241
-			return "\t\t\t<hr />\n";
242
-		}
243
-		else
244
-		{
245
-			return str_repeat(60, '-') . "\n";
246
-		}
247
-	}
248
-
249
-	function output_ul($data = array(), $padding = "")
250
-	{
251
-		if(!is_array($data) || count($data) < 1)
252
-		{
253
-			return "";
254
-		}
255
-
256
-		$text = "";
257
-		if(KSESTEST_ENV == 'WEB')
258
-		{
259
-			$text = "\t\t\t<ul>\n";
260
-			foreach($data as $li)
261
-			{
262
-				$text .= "\t\t\t\t<li>$li</li>\n";
263
-			}
264
-			$text .= "\t\t\t</ul>\n";
265
-		}
266
-		else
267
-		{
268
-			foreach($data as $li)
269
-			{
270
-				$text .= $padding . "   * $li\n";
271
-			}
272
-		}
273
-
274
-		return $text;
275
-	}
276
-
277
-	function test1_protocols(&$myKses)
278
-	{
279
-		$default_prots = $myKses->dumpProtocols();
280
-		$out_text = array();
281
-		if(count($default_prots) > 0)
282
-		{
283
-			array_push($out_text, "Initial protocols from KSES" . KSESTEST_VER . ":");
284
-			array_push($out_text, output_ul($default_prots));
285
-			array_push($out_text, output_hr());
286
-		}
287
-
288
-		$myKses->AddProtocols(array("proto1", "proto2:", "proto3"));   // Add a list of protocols
289
-		$myKses->AddProtocols("proto4:");  // Add a single protocol (Note ':' is optional at end)
290
-		$myKses->AddProtocol("proto9", "mystery:", "anarchy");
291
-		$myKses->AddProtocol("alpha", "beta", "gamma:");
292
-
293
-		$add_protocol  = "\t\t\t<ol>\n";
294
-		$add_protocol .= "\t\t\t\t" . '<li>$myKses->AddProtocols(array("proto1", "proto2:", "proto3"));</li>' . "\n";
295
-		$add_protocol .= "\t\t\t\t" . '<li>$myKses->AddProtocols("proto4:");</li>' . "\n";
296
-		$add_protocol .= "\t\t\t\t" . '<li>$myKses->AddProtocols("proto4:");</li>' . "\n";
297
-		$add_protocol .= "\t\t\t\t" . '<li>$myKses->AddProtocol("proto9", "mystery:", "anarchy");</li>' . "\n";
298
-		$add_protocol .= "\t\t\t\t" . '<li>$myKses->AddProtocol("alpha", "beta", "gamma:");</li>' . "\n";
299
-		$add_protocol .= "\t\t\t</ol>\n";
300
-
301
-		array_push($out_text, $add_protocol);
302
-
303
-		$new_prots = $myKses->dumpProtocols();
304
-		if(count($new_prots) > 0)
305
-		{
306
-			array_push($out_text, "New protocols from KSES" . KSESTEST_VER . " after using AddProtocol(s):");
307
-			array_push($out_text, output_ul($new_prots));
308
-			array_push($out_text, output_hr());
309
-		}
310
-
311
-		$myKses->RemoveProtocols(array("mystery", "anarchy:"));
312
-		$myKses->RemoveProtocols("alpha:");
313
-		$myKses->RemoveProtocol("beta:");
314
-		$myKses->RemoveProtocol("gamma");
315
-
316
-		$remove_protocol  = "\t\t\t<ol>\n";
317
-		$remove_protocol .= "\t\t\t\t" . '<li>$myKses->RemoveProtocols(array("mystery", "anarchy:"));</li>' . "\n";
318
-		$remove_protocol .= "\t\t\t\t" . '<li>$myKses->RemoveProtocols("alpha:");</li>' . "\n";
319
-		$remove_protocol .= "\t\t\t\t" . '<li>$myKses->RemoveProtocol("beta:");</li>' . "\n";
320
-		$remove_protocol .= "\t\t\t\t" . '<li>$myKses->RemoveProtocol("gamma");</li>' . "\n";
321
-		$remove_protocol .= "\t\t\t</ol>\n";
322
-		array_push($out_text, $remove_protocol);
323
-
324
-		$new_prots = $myKses->dumpProtocols();
325
-		if(count($new_prots) > 0)
326
-		{
327
-			array_push($out_text, "Resulting protocols from KSES" . KSESTEST_VER . " after using RemoveProtocol(s):");
328
-			array_push($out_text, output_ul($new_prots));
329
-			array_push($out_text, output_hr());
330
-		}
331
-
332
-		$myKses->SetProtocols(array("https", "gopher", "news"));
333
-		$set_protocol  = "\t\t\t<ol>\n";
334
-		$set_protocol .= "\t\t\t\t" . '<li>$myKses->SetProtocols(array("https", "gopher", "news"));</li>' . "\n";
335
-		$set_protocol .= "\t\t\t</ol>\n";
336
-		array_push($out_text, $set_protocol);
337
-
338
-		$new_prots = $myKses->dumpProtocols();
339
-		if(count($new_prots) > 0)
340
-		{
341
-			array_push($out_text, "Resulting protocols from KSES" . KSESTEST_VER . " after using SetProtocols:");
342
-			array_push($out_text, output_ul($new_prots));
343
-			array_push($out_text, output_hr());
344
-		}
345
-
346
-		//	Invisible reset
347
-		$myKses->SetProtocols(array("http", "proto1", "proto2", "proto9"));
348
-
349
-		return $out_text;
350
-	}
351
-
352
-	function test1_html(&$myKses)
353
-	{
354
-		$out = array();
355
-
356
-		//	Allows <p>|</p> tag
357
-		$myKses->AddHTML("p");
358
-
359
-		//	Allows 'a' tag with href|name attributes,
360
-		//	href has minlen of 10 chars, and maxlen of 25 chars
361
-		//	name has minlen of  2 chars
362
-		$myKses->AddHTML(
363
-			"a",
364
-			array(
365
-				"href" => array('maxlen' => 25, 'minlen' => 10),
366
-				"name" => array('minlen' => 2)
367
-			)
368
-		);
369
-
370
-		//	Allows 'td' tag with colspan|rowspan|class|style|width|nowrap attributes,
371
-		//		colspan has minval of   2       and maxval of 5
372
-		//		rowspan has minval of   3       and maxval of 6
373
-		//		class   has minlen of   1 char  and maxlen of   10 chars
374
-		//		style   has minlen of  10 chars and maxlen of 100 chars
375
-		//		width   has maxval of 100
376
-		//		nowrap  is valueless
377
-		$myKses->AddHTML(
378
-			"td",
379
-			array(
380
-				"colspan" => array('minval' =>   2, 'maxval' =>   5),
381
-				"rowspan" => array('minval' =>   3, 'maxval' =>   6),
382
-				"class"   => array("minlen" =>   1, 'maxlen' =>  10),
383
-				"width"   => array("maxval" => 100),
384
-				"style"   => array('minlen' =>  10, 'maxlen' => 100),
385
-				"nowrap"  => array('valueless' => 'y')
386
-			)
387
-		);
388
-
389
-		array_push($out, "Modifying HTML Tests:");
390
-		$code_text  = "<pre>\n";
391
-		$code_text .= "      //   Allows &lt;p&gt;|&lt;/p&gt; tag\n";
392
-		$code_text .= "      \$myKses-&gt;AddHTML(\"p\");\n";
393
-		$code_text .= "\n";
394
-		$code_text .= "      //   Allows 'a' tag with href|name attributes,\n";
395
-		$code_text .= "      //   href has minlen of 10 chars, and maxlen of 25 chars\n";
396
-		$code_text .= "      //   name has minlen of  2 chars\n";
397
-		$code_text .= "      \$myKses-&gt;AddHTML(\n";
398
-		$code_text .= "         \"a\",\n";
399
-		$code_text .= "         array(\n";
400
-		$code_text .= "            \"href\" =&gt; array('maxlen' =&gt; 25, 'minlen' =&gt; 10),\n";
401
-		$code_text .= "            \"name\" =&gt; array('minlen' =&gt; 2)\n";
402
-		$code_text .= "         )\n";
403
-		$code_text .= "      );\n";
404
-		$code_text .= "\n";
405
-		$code_text .= "      //   Allows 'td' tag with colspan|rowspan|class|style|width|nowrap attributes,\n";
406
-		$code_text .= "      //      colspan has minval of   2       and maxval of 5\n";
407
-		$code_text .= "      //      rowspan has minval of   3       and maxval of 6\n";
408
-		$code_text .= "      //      class   has minlen of   1 char  and maxlen of   10 chars\n";
409
-		$code_text .= "      //      style   has minlen of  10 chars and maxlen of 100 chars\n";
410
-		$code_text .= "      //      width   has maxval of 100\n";
411
-		$code_text .= "      //      nowrap  is valueless\n";
412
-		$code_text .= "      \$myKses-&gt;AddHTML(\n";
413
-		$code_text .= "         \"td\",\n";
414
-		$code_text .= "         array(\n";
415
-		$code_text .= "            \"colspan\" =&gt; array('minval' =&gt;   2, 'maxval' =&gt;   5),\n";
416
-		$code_text .= "            \"rowspan\" =&gt; array('minval' =&gt;   3, 'maxval' =&gt;   6),\n";
417
-		$code_text .= "            \"class\"   =&gt; array(\"minlen\" =&gt;   1, 'maxlen' =&gt;  10),\n";
418
-		$code_text .= "            \"width\"   =&gt; array(\"maxval\" =&gt; 100),\n";
419
-		$code_text .= "            \"style\"   =&gt; array('minlen' =&gt;  10, 'maxlen' =&gt; 100),\n";
420
-		$code_text .= "            \"nowrap\"  =&gt; array('valueless' =&gt; 'y')\n";
421
-		$code_text .= "         )\n";
422
-		$code_text .= "      );\n";
423
-		$code_text .= "</pre>\n";
424
-
425
-		array_push($out, $code_text);
426
-		array_push($out, output_hr());
427
-		array_push($out, "Net results:");
428
-
429
-		$out_elems = $myKses->DumpElements();
430
-		if(count($out_elems) > 0)
431
-		{
432
-			//array_push($out, "\t\t\t<ul>\n");
433
-			foreach($out_elems as $tag => $attr_data)
434
-			{
435
-				$out_li_elems = array();
436
-				$elem_text = "(X)HTML element $tag";
437
-				$allow = "";
438
-				if(isset($attr_data) && is_array($attr_data) && count($attr_data) > 0)
439
-				{
440
-					$allow = " allows attribute";
441
-					if(count($attr_data) > 1)
442
-					{
443
-						$allow .= "s";
444
-					}
445
-					$allow .= ":\n";
446
-				}
447
-
448
-				array_push($out_li_elems, "$elem_text$allow");
449
-
450
-				$attr_test_li = array();
451
-				if(isset($attr_data) && is_array($attr_data) && count($attr_data) > 0)
452
-				{
453
-					foreach($attr_data as $attr_name => $attr_tests)
454
-					{
455
-						$li_text = $attr_name;
456
-						if(isset($attr_tests) && count($attr_tests) > 0)
457
-						{
458
-							foreach($attr_tests as $test_name => $test_val)
459
-							{
460
-								switch($test_name)
461
-								{
462
-									case "maxlen":
463
-										$li_text .= " - maximum length of '" . $test_val . "' characters";
464
-										break;
465
-									case "minlen":
466
-										$li_text .= " - minimum length of '" . $test_val . "' characters";
467
-										break;
468
-									case "minval":
469
-										$li_text .= " - minimum value of '" . $test_val . "'";
470
-										break;
471
-									case "maxval":
472
-										$li_text .= " - maximum value of '" . $test_val . "'";
473
-										break;
474
-									case "valueless":
475
-										switch(strtolower($test_val))
476
-										{
477
-											case 'n':
478
-												$li_text .= " - must not be valueless";
479
-												break;
480
-											case 'y':
481
-												$li_text .= " - must be valueless";
482
-												break;
483
-											default:
484
-												break;
485
-										}
486
-										break;
487
-									default:
488
-										break;
489
-								}
490
-							}
491
-						}
492
-						array_push($attr_test_li, $li_text);
493
-					}
494
-					if(count($attr_test_li) > 0)
495
-					{
496
-						$attr_test_li = output_ul($attr_test_li, "   ");
497
-						$out_li_elems = array("$elem_text$allow$attr_test_li");
498
-					}
499
-				}
500
-				$out = array_merge($out, $out_li_elems);
501
-			}
502
-		}
503
-
504
-		return $out;
505
-	}
3
+    //	This is a q&d program that shows some of the results of
4
+    //	running KSES.  If you have further questions, check the
5
+    //	current valid email address at http://chaos.org/contact/
6
+
7
+    //	Make sure we're in a usable PHP environment
8
+    if(substr(phpversion(), 0, 1) < 4)
9
+    {
10
+        define('KSESTEST_VER', 0);
11
+    }
12
+    elseif(substr(phpversion(), 0, 1) >= 5)
13
+    {
14
+        define('KSESTEST_VER', 5);
15
+    }
16
+    else
17
+    {
18
+        define('KSESTEST_VER', 4);
19
+    }
20
+
21
+    //	See if we're in command line or web
22
+    if($_SERVER["DOCUMENT_ROOT"] == "")
23
+    {
24
+        define('KSESTEST_ENV', 'CLI');
25
+    }
26
+    else
27
+    {
28
+        define('KSESTEST_ENV', 'WEB');
29
+    }
30
+
31
+    if(KSESTEST_VER == 0)
32
+    {
33
+        $message = array(
34
+            "Error: Not using a current version of PHP!",
35
+            "You are using PHP version " . phpversion() . ".",
36
+            "KSES Class version requires PHP4 or better.",
37
+            "KSES test program ending."
38
+            );
39
+
40
+        displayPage(
41
+            array("title" => "Error running KSES test", "message" => $message)
42
+        );
43
+
44
+        exit();
45
+    }
46
+
47
+    $include_file = "php" . KSESTEST_VER . ".class.kses.php";
48
+    if(file_exists($include_file) && is_readable($include_file))
49
+    {
50
+        include_once($include_file);
51
+    }
52
+    else
53
+    {
54
+        $message = array(
55
+            "Error:  Unable to find '" . $include_file . "'.",
56
+            "Please check your include path and make sure the file is available.",
57
+            "Path: " . ini_get('include_path')
58
+        );
59
+
60
+        displayPage(
61
+            array('title' => 'Unable to include ' . $include_file, 'message' => $message)
62
+        );
63
+
64
+        exit();
65
+    }
66
+
67
+    $kses_type = "kses" . KSESTEST_VER;
68
+    $myKses = new $kses_type;
69
+
70
+    $test_text = array();
71
+    $test_text = test1_protocols($myKses);
72
+    $test_text = array_merge($test_text, test1_html($myKses));
73
+    $test_text = array_merge($test_text, test1_kses($myKses));
74
+
75
+    displayPage(
76
+        array('title' => 'New Test', 'message' => $test_text)
77
+    );
78
+
79
+    function test1_kses(&$myKses)
80
+    {
81
+        $out = array(output_hr(), "Testing current configuration");
82
+
83
+        $test_tags = array(
84
+            '<a href="http://www.chaos.org/">www.chaos.org</a>',
85
+            '<a name="X">Short \'a name\' tag</a>',
86
+            '<td colspan="3" rowspan="5">Foo</td>',
87
+            '<td rowspan="2" class="mugwump" style="background-color: rgb(255, 204 204);">Bar</td>',
88
+            '<td nowrap>Very Long String running to 1000 characters...</td>',
89
+            '<td bgcolor="#00ff00" nowrap>Very Long String with a blue background</td>',
90
+            '<a href="proto1://www.foo.com">New protocol test</a>',
91
+            '<img src="proto2://www.foo.com" />',
92
+            '<a href="javascript:javascript:javascript:javascript:javascript:alert(\'Boo!\');">bleep</a>',
93
+            '<a href="proto4://abc.xyz.foo.com">Another new protocol</a>',
94
+            '<a href="proto9://foo.foo.foo.foo.foo.org/">Test of "proto9"</a>',
95
+            '<td width="75">Bar!</td>',
96
+            '<td width="200">Long Cell</td>'
97
+        );
98
+
99
+        $out_li = array();
100
+        // Keep only allowed HTML from the presumed 'form'.
101
+        foreach($test_tags as $tag)
102
+        {
103
+            $temp  = $myKses->Parse($tag);
104
+            $check = ($temp == $tag) ? true : false;
105
+            $text  = ($temp == $tag) ? 'pass' : 'fail';
106
+
107
+            $li_text  = output_testresult($check, $text) . output_newline();
108
+            $li_text .= "Input: &nbsp;" . output_translate($tag) . output_newline();
109
+            $li_text .= "Output: " . output_translate($temp);
110
+            if(KSESTEST_ENV == 'CLI')
111
+            {
112
+                $li_text .= output_newline();
113
+            }
114
+
115
+            array_push($out_li, output_code_wrap($li_text));
116
+        }
117
+
118
+        $out = array_merge($out, array(output_ul($out_li)));
119
+        array_push($out, output_hr());
120
+        array_push($out, "Testing is now finished.");
121
+        return $out;
122
+    }
123
+
124
+    function output_code_wrap($text)
125
+    {
126
+        if(KSESTEST_ENV == 'CLI')
127
+        {
128
+            return $text;
129
+        }
130
+        else
131
+        {
132
+            return "<code>\n$text<code>\n";
133
+        }
134
+    }
135
+
136
+    function output_translate($text)
137
+    {
138
+        if(KSESTEST_ENV == 'CLI')
139
+        {
140
+            return $text;
141
+        }
142
+        else
143
+        {
144
+            return htmlentities($text);
145
+        }
146
+    }
147
+
148
+    function output_testresult($pass = false, $text = "")
149
+    {
150
+        if(KSESTEST_ENV == 'CLI')
151
+        {
152
+            return '[' . $text . ']';
153
+        }
154
+        else
155
+        {
156
+            if($pass == true)
157
+            {
158
+                return '<span style="color: green;">[' . $text . ']</span>';
159
+            }
160
+            else
161
+            {
162
+                return '<span style="color: red;">[' . $text . ']</span>';
163
+            }
164
+        }
165
+    }
166
+
167
+    function output_spaces()
168
+    {
169
+        if(KSESTEST_ENV == 'WEB')
170
+        {
171
+            $out = "&nbsp;&nbsp;&nbsp;";
172
+        }
173
+        else
174
+        {
175
+            $out = "   ";
176
+        }
177
+
178
+        return $out;
179
+    }
180
+
181
+    function output_newline()
182
+    {
183
+        if(KSESTEST_ENV == 'WEB')
184
+        {
185
+            $out = "<br />\n";
186
+        }
187
+        else
188
+        {
189
+            $out = "\n";
190
+        }
191
+
192
+        return $out;
193
+    }
194
+
195
+    function displayPage($data = array())
196
+    {
197
+        $title   = ($data['title'] == '') ? 'No title' : $data['title'];
198
+        $message = ($data['message'] == '') ? array('No message') : $data['message'];
199
+
200
+        $out = "";
201
+
202
+        foreach($message as $text)
203
+        {
204
+            if(KSESTEST_ENV == 'WEB')
205
+            {
206
+                $header = "\t\t<h1>$title</h1>\n\t\t<hr />\n";
207
+                $out .= "\t\t<p>\n";
208
+                $out .= "\t\t\t$text\n";
209
+                $out .= "\t\t</p>\n";
210
+            }
211
+            else
212
+            {
213
+                $header = "$title\n" . str_repeat('-', 60) . "\n\n";
214
+                $out .= "\t$text\n\n";
215
+            }
216
+        }
217
+
218
+        if(KSESTEST_ENV == 'WEB')
219
+        {
220
+            echo "<html>\n";
221
+            echo "\t<head>\n";
222
+            echo "\t\t<title>$title</title>\n";
223
+            echo "\t</head>\n";
224
+            echo "\t<body>\n";
225
+            echo $header;
226
+            echo $out;
227
+            echo "\t</body>\n";
228
+            echo "</html>\n";
229
+        }
230
+        else
231
+        {
232
+            echo $header;
233
+            echo $out;
234
+        }
235
+    }
236
+
237
+    function output_hr()
238
+    {
239
+        if(KSESTEST_ENV == 'WEB')
240
+        {
241
+            return "\t\t\t<hr />\n";
242
+        }
243
+        else
244
+        {
245
+            return str_repeat(60, '-') . "\n";
246
+        }
247
+    }
248
+
249
+    function output_ul($data = array(), $padding = "")
250
+    {
251
+        if(!is_array($data) || count($data) < 1)
252
+        {
253
+            return "";
254
+        }
255
+
256
+        $text = "";
257
+        if(KSESTEST_ENV == 'WEB')
258
+        {
259
+            $text = "\t\t\t<ul>\n";
260
+            foreach($data as $li)
261
+            {
262
+                $text .= "\t\t\t\t<li>$li</li>\n";
263
+            }
264
+            $text .= "\t\t\t</ul>\n";
265
+        }
266
+        else
267
+        {
268
+            foreach($data as $li)
269
+            {
270
+                $text .= $padding . "   * $li\n";
271
+            }
272
+        }
273
+
274
+        return $text;
275
+    }
276
+
277
+    function test1_protocols(&$myKses)
278
+    {
279
+        $default_prots = $myKses->dumpProtocols();
280
+        $out_text = array();
281
+        if(count($default_prots) > 0)
282
+        {
283
+            array_push($out_text, "Initial protocols from KSES" . KSESTEST_VER . ":");
284
+            array_push($out_text, output_ul($default_prots));
285
+            array_push($out_text, output_hr());
286
+        }
287
+
288
+        $myKses->AddProtocols(array("proto1", "proto2:", "proto3"));   // Add a list of protocols
289
+        $myKses->AddProtocols("proto4:");  // Add a single protocol (Note ':' is optional at end)
290
+        $myKses->AddProtocol("proto9", "mystery:", "anarchy");
291
+        $myKses->AddProtocol("alpha", "beta", "gamma:");
292
+
293
+        $add_protocol  = "\t\t\t<ol>\n";
294
+        $add_protocol .= "\t\t\t\t" . '<li>$myKses->AddProtocols(array("proto1", "proto2:", "proto3"));</li>' . "\n";
295
+        $add_protocol .= "\t\t\t\t" . '<li>$myKses->AddProtocols("proto4:");</li>' . "\n";
296
+        $add_protocol .= "\t\t\t\t" . '<li>$myKses->AddProtocols("proto4:");</li>' . "\n";
297
+        $add_protocol .= "\t\t\t\t" . '<li>$myKses->AddProtocol("proto9", "mystery:", "anarchy");</li>' . "\n";
298
+        $add_protocol .= "\t\t\t\t" . '<li>$myKses->AddProtocol("alpha", "beta", "gamma:");</li>' . "\n";
299
+        $add_protocol .= "\t\t\t</ol>\n";
300
+
301
+        array_push($out_text, $add_protocol);
302
+
303
+        $new_prots = $myKses->dumpProtocols();
304
+        if(count($new_prots) > 0)
305
+        {
306
+            array_push($out_text, "New protocols from KSES" . KSESTEST_VER . " after using AddProtocol(s):");
307
+            array_push($out_text, output_ul($new_prots));
308
+            array_push($out_text, output_hr());
309
+        }
310
+
311
+        $myKses->RemoveProtocols(array("mystery", "anarchy:"));
312
+        $myKses->RemoveProtocols("alpha:");
313
+        $myKses->RemoveProtocol("beta:");
314
+        $myKses->RemoveProtocol("gamma");
315
+
316
+        $remove_protocol  = "\t\t\t<ol>\n";
317
+        $remove_protocol .= "\t\t\t\t" . '<li>$myKses->RemoveProtocols(array("mystery", "anarchy:"));</li>' . "\n";
318
+        $remove_protocol .= "\t\t\t\t" . '<li>$myKses->RemoveProtocols("alpha:");</li>' . "\n";
319
+        $remove_protocol .= "\t\t\t\t" . '<li>$myKses->RemoveProtocol("beta:");</li>' . "\n";
320
+        $remove_protocol .= "\t\t\t\t" . '<li>$myKses->RemoveProtocol("gamma");</li>' . "\n";
321
+        $remove_protocol .= "\t\t\t</ol>\n";
322
+        array_push($out_text, $remove_protocol);
323
+
324
+        $new_prots = $myKses->dumpProtocols();
325
+        if(count($new_prots) > 0)
326
+        {
327
+            array_push($out_text, "Resulting protocols from KSES" . KSESTEST_VER . " after using RemoveProtocol(s):");
328
+            array_push($out_text, output_ul($new_prots));
329
+            array_push($out_text, output_hr());
330
+        }
331
+
332
+        $myKses->SetProtocols(array("https", "gopher", "news"));
333
+        $set_protocol  = "\t\t\t<ol>\n";
334
+        $set_protocol .= "\t\t\t\t" . '<li>$myKses->SetProtocols(array("https", "gopher", "news"));</li>' . "\n";
335
+        $set_protocol .= "\t\t\t</ol>\n";
336
+        array_push($out_text, $set_protocol);
337
+
338
+        $new_prots = $myKses->dumpProtocols();
339
+        if(count($new_prots) > 0)
340
+        {
341
+            array_push($out_text, "Resulting protocols from KSES" . KSESTEST_VER . " after using SetProtocols:");
342
+            array_push($out_text, output_ul($new_prots));
343
+            array_push($out_text, output_hr());
344
+        }
345
+
346
+        //	Invisible reset
347
+        $myKses->SetProtocols(array("http", "proto1", "proto2", "proto9"));
348
+
349
+        return $out_text;
350
+    }
351
+
352
+    function test1_html(&$myKses)
353
+    {
354
+        $out = array();
355
+
356
+        //	Allows <p>|</p> tag
357
+        $myKses->AddHTML("p");
358
+
359
+        //	Allows 'a' tag with href|name attributes,
360
+        //	href has minlen of 10 chars, and maxlen of 25 chars
361
+        //	name has minlen of  2 chars
362
+        $myKses->AddHTML(
363
+            "a",
364
+            array(
365
+                "href" => array('maxlen' => 25, 'minlen' => 10),
366
+                "name" => array('minlen' => 2)
367
+            )
368
+        );
369
+
370
+        //	Allows 'td' tag with colspan|rowspan|class|style|width|nowrap attributes,
371
+        //		colspan has minval of   2       and maxval of 5
372
+        //		rowspan has minval of   3       and maxval of 6
373
+        //		class   has minlen of   1 char  and maxlen of   10 chars
374
+        //		style   has minlen of  10 chars and maxlen of 100 chars
375
+        //		width   has maxval of 100
376
+        //		nowrap  is valueless
377
+        $myKses->AddHTML(
378
+            "td",
379
+            array(
380
+                "colspan" => array('minval' =>   2, 'maxval' =>   5),
381
+                "rowspan" => array('minval' =>   3, 'maxval' =>   6),
382
+                "class"   => array("minlen" =>   1, 'maxlen' =>  10),
383
+                "width"   => array("maxval" => 100),
384
+                "style"   => array('minlen' =>  10, 'maxlen' => 100),
385
+                "nowrap"  => array('valueless' => 'y')
386
+            )
387
+        );
388
+
389
+        array_push($out, "Modifying HTML Tests:");
390
+        $code_text  = "<pre>\n";
391
+        $code_text .= "      //   Allows &lt;p&gt;|&lt;/p&gt; tag\n";
392
+        $code_text .= "      \$myKses-&gt;AddHTML(\"p\");\n";
393
+        $code_text .= "\n";
394
+        $code_text .= "      //   Allows 'a' tag with href|name attributes,\n";
395
+        $code_text .= "      //   href has minlen of 10 chars, and maxlen of 25 chars\n";
396
+        $code_text .= "      //   name has minlen of  2 chars\n";
397
+        $code_text .= "      \$myKses-&gt;AddHTML(\n";
398
+        $code_text .= "         \"a\",\n";
399
+        $code_text .= "         array(\n";
400
+        $code_text .= "            \"href\" =&gt; array('maxlen' =&gt; 25, 'minlen' =&gt; 10),\n";
401
+        $code_text .= "            \"name\" =&gt; array('minlen' =&gt; 2)\n";
402
+        $code_text .= "         )\n";
403
+        $code_text .= "      );\n";
404
+        $code_text .= "\n";
405
+        $code_text .= "      //   Allows 'td' tag with colspan|rowspan|class|style|width|nowrap attributes,\n";
406
+        $code_text .= "      //      colspan has minval of   2       and maxval of 5\n";
407
+        $code_text .= "      //      rowspan has minval of   3       and maxval of 6\n";
408
+        $code_text .= "      //      class   has minlen of   1 char  and maxlen of   10 chars\n";
409
+        $code_text .= "      //      style   has minlen of  10 chars and maxlen of 100 chars\n";
410
+        $code_text .= "      //      width   has maxval of 100\n";
411
+        $code_text .= "      //      nowrap  is valueless\n";
412
+        $code_text .= "      \$myKses-&gt;AddHTML(\n";
413
+        $code_text .= "         \"td\",\n";
414
+        $code_text .= "         array(\n";
415
+        $code_text .= "            \"colspan\" =&gt; array('minval' =&gt;   2, 'maxval' =&gt;   5),\n";
416
+        $code_text .= "            \"rowspan\" =&gt; array('minval' =&gt;   3, 'maxval' =&gt;   6),\n";
417
+        $code_text .= "            \"class\"   =&gt; array(\"minlen\" =&gt;   1, 'maxlen' =&gt;  10),\n";
418
+        $code_text .= "            \"width\"   =&gt; array(\"maxval\" =&gt; 100),\n";
419
+        $code_text .= "            \"style\"   =&gt; array('minlen' =&gt;  10, 'maxlen' =&gt; 100),\n";
420
+        $code_text .= "            \"nowrap\"  =&gt; array('valueless' =&gt; 'y')\n";
421
+        $code_text .= "         )\n";
422
+        $code_text .= "      );\n";
423
+        $code_text .= "</pre>\n";
424
+
425
+        array_push($out, $code_text);
426
+        array_push($out, output_hr());
427
+        array_push($out, "Net results:");
428
+
429
+        $out_elems = $myKses->DumpElements();
430
+        if(count($out_elems) > 0)
431
+        {
432
+            //array_push($out, "\t\t\t<ul>\n");
433
+            foreach($out_elems as $tag => $attr_data)
434
+            {
435
+                $out_li_elems = array();
436
+                $elem_text = "(X)HTML element $tag";
437
+                $allow = "";
438
+                if(isset($attr_data) && is_array($attr_data) && count($attr_data) > 0)
439
+                {
440
+                    $allow = " allows attribute";
441
+                    if(count($attr_data) > 1)
442
+                    {
443
+                        $allow .= "s";
444
+                    }
445
+                    $allow .= ":\n";
446
+                }
447
+
448
+                array_push($out_li_elems, "$elem_text$allow");
449
+
450
+                $attr_test_li = array();
451
+                if(isset($attr_data) && is_array($attr_data) && count($attr_data) > 0)
452
+                {
453
+                    foreach($attr_data as $attr_name => $attr_tests)
454
+                    {
455
+                        $li_text = $attr_name;
456
+                        if(isset($attr_tests) && count($attr_tests) > 0)
457
+                        {
458
+                            foreach($attr_tests as $test_name => $test_val)
459
+                            {
460
+                                switch($test_name)
461
+                                {
462
+                                    case "maxlen":
463
+                                        $li_text .= " - maximum length of '" . $test_val . "' characters";
464
+                                        break;
465
+                                    case "minlen":
466
+                                        $li_text .= " - minimum length of '" . $test_val . "' characters";
467
+                                        break;
468
+                                    case "minval":
469
+                                        $li_text .= " - minimum value of '" . $test_val . "'";
470
+                                        break;
471
+                                    case "maxval":
472
+                                        $li_text .= " - maximum value of '" . $test_val . "'";
473
+                                        break;
474
+                                    case "valueless":
475
+                                        switch(strtolower($test_val))
476
+                                        {
477
+                                            case 'n':
478
+                                                $li_text .= " - must not be valueless";
479
+                                                break;
480
+                                            case 'y':
481
+                                                $li_text .= " - must be valueless";
482
+                                                break;
483
+                                            default:
484
+                                                break;
485
+                                        }
486
+                                        break;
487
+                                    default:
488
+                                        break;
489
+                                }
490
+                            }
491
+                        }
492
+                        array_push($attr_test_li, $li_text);
493
+                    }
494
+                    if(count($attr_test_li) > 0)
495
+                    {
496
+                        $attr_test_li = output_ul($attr_test_li, "   ");
497
+                        $out_li_elems = array("$elem_text$allow$attr_test_li");
498
+                    }
499
+                }
500
+                $out = array_merge($out, $out_li_elems);
501
+            }
502
+        }
503
+
504
+        return $out;
505
+    }
506 506
 
507 507
 ?>
508 508
\ No newline at end of file
Please login to merge, or discard this patch.
main/inc/lib/kses-0.2.2/oop/php4.class.kses.php 1 patch
Indentation   +1137 added lines, -1137 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	/*
2
+    /*
3 3
 	 * ==========================================================================================
4 4
 	 *
5 5
 	 * This program is free software and open source software; you can redistribute
@@ -20,1143 +20,1143 @@  discard block
 block discarded – undo
20 20
 	 * ==========================================================================================
21 21
 	 */
22 22
 
23
-	/**
24
-	*	Class file for PHP4 OOP version of kses
25
-	*
26
-	*	This is an updated version of kses to work with PHP4 that works under E_STRICT.
27
-	*
28
-	*	This upgrade provides the following:
29
-	*	+ Version number synced to procedural version number
30
-	*	+ PHPdoc style documentation has been added to the class.  See http://www.phpdoc.org/ for more info.
31
-	*	+ Some methods are now deprecated due to nomenclature style change.  See method documentation for specifics.
32
-	*	+ Kses4 now works in E_STRICT
33
-	*	+ Addition of methods AddProtocols(), filterKsestextHook(), RemoveProtocol() and RemoveProtocols()
34
-	*	+ Deprecated _hook(), Protocols()
35
-	*	+ Integrated code from kses 0.2.2 into class.
36
-	*	+ Added methods DumpProtocols(), DumpMethods()
37
-	*
38
-	*	@package    kses
39
-	*	@subpackage kses4
40
-	*/
41
-
42
-	if(substr(phpversion(), 0, 1) < 4)
43
-	{
44
-		die("Class kses requires PHP 4 or higher.");
45
-	}
46
-
47
-	/**
48
-	*	Only install KSES4 once
49
-	*/
50
-	if(!defined('KSES_CLASS_PHP4'))
51
-	{
52
-		define('KSES_CLASS_PHP4', true);
53
-
54
-	/**
55
-	*	Kses strips evil scripts!
56
-	*
57
-	*	This class provides the capability for removing unwanted HTML/XHTML, attributes from
58
-	*	tags, and protocols contained in links.  The net result is a much more powerful tool
59
-	*	than the PHP internal strip_tags()
60
-	*
61
-	*	This is a fork of a slick piece of procedural code called 'kses' written by Ulf Harnhammar
62
-	*	The entire set of functions was wrapped in a PHP object with some internal modifications
63
-	*	by Richard Vasquez (http://www.chaos.org/) 7/25/2003
64
-	*
65
-	*	This upgrade provides the following:
66
-	*	+ Version number synced to procedural version number
67
-	*	+ PHPdoc style documentation has been added to the class.  See http://www.phpdoc.org/ for more info.
68
-	*	+ Some methods are now deprecated due to nomenclature style change.  See method documentation for specifics.
69
-	*	+ Kses4 now works in E_STRICT
70
-	*	+ Addition of methods AddProtocols(), filterKsestextHook(), RemoveProtocol(), RemoveProtocols() and SetProtocols()
71
-	*	+ Deprecated _hook(), Protocols()
72
-	*	+ Integrated code from kses 0.2.2 into class.
73
-	*
74
-	*	@author     Richard R. V�squez, Jr. (Original procedural code by Ulf H�rnhammar)
75
-	*	@link       http://sourceforge.net/projects/kses/ Home Page for Kses
76
-	*	@link       http://chaos.org/contact/ Contact page with current email address for Richard Vasquez
77
-	*	@copyright  Richard R. V�squez, Jr. 2003-2005
78
-	*	@version    PHP4 OOP 0.2.2
79
-	*	@license    http://www.gnu.org/licenses/gpl.html GNU Public License
80
-	*	@package    kses
81
-	*/
82
-		class kses4
83
-		{
84
-			/**#@+
23
+    /**
24
+     *	Class file for PHP4 OOP version of kses
25
+     *
26
+     *	This is an updated version of kses to work with PHP4 that works under E_STRICT.
27
+     *
28
+     *	This upgrade provides the following:
29
+     *	+ Version number synced to procedural version number
30
+     *	+ PHPdoc style documentation has been added to the class.  See http://www.phpdoc.org/ for more info.
31
+     *	+ Some methods are now deprecated due to nomenclature style change.  See method documentation for specifics.
32
+     *	+ Kses4 now works in E_STRICT
33
+     *	+ Addition of methods AddProtocols(), filterKsestextHook(), RemoveProtocol() and RemoveProtocols()
34
+     *	+ Deprecated _hook(), Protocols()
35
+     *	+ Integrated code from kses 0.2.2 into class.
36
+     *	+ Added methods DumpProtocols(), DumpMethods()
37
+     *
38
+     *	@package    kses
39
+     *	@subpackage kses4
40
+     */
41
+
42
+    if(substr(phpversion(), 0, 1) < 4)
43
+    {
44
+        die("Class kses requires PHP 4 or higher.");
45
+    }
46
+
47
+    /**
48
+     *	Only install KSES4 once
49
+     */
50
+    if(!defined('KSES_CLASS_PHP4'))
51
+    {
52
+        define('KSES_CLASS_PHP4', true);
53
+
54
+    /**
55
+     *	Kses strips evil scripts!
56
+     *
57
+     *	This class provides the capability for removing unwanted HTML/XHTML, attributes from
58
+     *	tags, and protocols contained in links.  The net result is a much more powerful tool
59
+     *	than the PHP internal strip_tags()
60
+     *
61
+     *	This is a fork of a slick piece of procedural code called 'kses' written by Ulf Harnhammar
62
+     *	The entire set of functions was wrapped in a PHP object with some internal modifications
63
+     *	by Richard Vasquez (http://www.chaos.org/) 7/25/2003
64
+     *
65
+     *	This upgrade provides the following:
66
+     *	+ Version number synced to procedural version number
67
+     *	+ PHPdoc style documentation has been added to the class.  See http://www.phpdoc.org/ for more info.
68
+     *	+ Some methods are now deprecated due to nomenclature style change.  See method documentation for specifics.
69
+     *	+ Kses4 now works in E_STRICT
70
+     *	+ Addition of methods AddProtocols(), filterKsestextHook(), RemoveProtocol(), RemoveProtocols() and SetProtocols()
71
+     *	+ Deprecated _hook(), Protocols()
72
+     *	+ Integrated code from kses 0.2.2 into class.
73
+     *
74
+     *	@author     Richard R. V�squez, Jr. (Original procedural code by Ulf H�rnhammar)
75
+     *	@link       http://sourceforge.net/projects/kses/ Home Page for Kses
76
+     *	@link       http://chaos.org/contact/ Contact page with current email address for Richard Vasquez
77
+     *	@copyright  Richard R. V�squez, Jr. 2003-2005
78
+     *	@version    PHP4 OOP 0.2.2
79
+     *	@license    http://www.gnu.org/licenses/gpl.html GNU Public License
80
+     *	@package    kses
81
+     */
82
+        class kses4
83
+        {
84
+            /**#@+
85 85
 			 *	@access private
86 86
 			 *	@var array
87 87
 			 */
88
-			var $allowed_protocols = array();
89
-			var $allowed_html      = array();
90
-			/**#@-*/
91
-
92
-			/**
93
-			 *	Constructor for kses.
94
-			 *
95
-			 *	This sets a default collection of protocols allowed in links, and creates an
96
-			 *	empty set of allowed HTML tags.
97
-			 *	@since PHP4 OOP 0.0.1
98
-			 */
99
-			function kses4()
100
-			{
101
-				/**
102
-				 *	You could add protocols such as ftp, new, gopher, mailto, irc, etc.
103
-				 *
104
-				 *	The base values the original kses provided were:
105
-				 *		'http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto'
106
-				 */
107
-				$this->allowed_protocols = array('http', 'ftp', 'mailto');
108
-				$this->allowed_html      = array();
109
-			}
110
-
111
-			/**
112
-			 *	Basic task of kses - parses $string and strips it as required.
113
-			 *
114
-			 *	This method strips all the disallowed (X)HTML tags, attributes
115
-			 *	and protocols from the input $string.
116
-			 *
117
-			 *	@access public
118
-			 *	@param string $string String to be stripped of 'evil scripts'
119
-			 *	@return string The stripped string
120
-			 *	@since PHP4 OOP 0.2.1
121
-			 */
122
-			function Parse($string = "")
123
-			{
124
-				if (get_magic_quotes_gpc())
125
-				{
126
-					$string = stripslashes($string);
127
-				}
128
-				$string = $this->_no_null($string);
129
-				$string = $this->_js_entities($string);
130
-				$string = $this->_normalize_entities($string);
131
-				$string = $this->filterKsesTextHook($string);
132
-				return    $this->_split($string);
133
-			}
134
-
135
-			/**
136
-			 *	Allows for single/batch addition of protocols
137
-			 *
138
-			 *	This method accepts one argument that can be either a string
139
-			 *	or an array of strings.  Invalid data will be ignored.
140
-			 *
141
-			 *	The argument will be processed, and each string will be added
142
-			 *	via AddProtocol().
143
-			 *
144
-			 *	@access public
145
-			 *	@param mixed , A string or array of protocols that will be added to the internal list of allowed protocols.
146
-			 *	@return bool Status of adding valid protocols.
147
-			 *	@see AddProtocol()
148
-			 *	@since PHP4 OOP 0.2.1
149
-			 */
150
-			function AddProtocols()
151
-			{
152
-				$c_args = func_num_args();
153
-				if($c_args != 1)
154
-				{
155
-					trigger_error("kses4::AddProtocols() did not receive an argument.", E_USER_WARNING);
156
-					return false;
157
-				}
158
-
159
-				$protocol_data = func_get_arg(0);
160
-
161
-				if(is_array($protocol_data) && count($protocol_data) > 0)
162
-				{
163
-					foreach($protocol_data as $protocol)
164
-					{
165
-						$this->AddProtocol($protocol);
166
-					}
167
-					return true;
168
-				}
169
-				elseif(is_string($protocol_data))
170
-				{
171
-					$this->AddProtocol($protocol_data);
172
-					return true;
173
-				}
174
-				else
175
-				{
176
-					trigger_error("kses4::AddProtocols() did not receive a string or an array.", E_USER_WARNING);
177
-					return false;
178
-				}
179
-			}
180
-
181
-			/**
182
-			 *	Allows for single/batch addition of protocols
183
-			 *
184
-			 *	@deprecated Use AddProtocols()
185
-			 *	@see AddProtocols()
186
-			 *	@return bool
187
-			 *	@since PHP4 OOP 0.0.1
188
-			 */
189
-			function Protocols()
190
-			{
191
-				$c_args = func_num_args();
192
-				if($c_args != 1)
193
-				{
194
-					trigger_error("kses4::Protocols() did not receive an argument.", E_USER_WARNING);
195
-					return false;
196
-				}
197
-
198
-				return $this->AddProtocols(func_get_arg(0));
199
-			}
200
-
201
-			/**
202
-			 *	Adds a single protocol to $this->allowed_protocols.
203
-			 *
204
-			 *	This method accepts a string argument and adds it to
205
-			 *	the list of allowed protocols to keep when performing
206
-			 *	Parse().
207
-			 *
208
-			 *	@access public
209
-			 *	@param string $protocol The name of the protocol to be added.
210
-			 *	@return bool Status of adding valid protocol.
211
-			 *	@since PHP4 OOP 0.0.1
212
-			 */
213
-			function AddProtocol($protocol = "")
214
-			{
215
-				if(!is_string($protocol))
216
-				{
217
-					trigger_error("kses4::AddProtocol() requires a string.", E_USER_WARNING);
218
-					return false;
219
-				}
220
-
221
-				$protocol = strtolower(trim($protocol));
222
-				if($protocol == "")
223
-				{
224
-					trigger_error("kses4::AddProtocol() tried to add an empty/NULL protocol.", E_USER_WARNING);
225
-					return false;
226
-				}
227
-
228
-				// Remove any inadvertent ':' at the end of the protocol.
229
-				if(substr($protocol, strlen($protocol) - 1, 1) == ":")
230
-				{
231
-					$protocol = substr($protocol, 0, strlen($protocol) - 1);
232
-				}
233
-
234
-				if(!in_array($protocol, $this->allowed_protocols))
235
-				{
236
-					array_push($this->allowed_protocols, $protocol);
237
-					sort($this->allowed_protocols);
238
-				}
239
-				return true;
240
-			}
241
-
242
-			/**
243
-			 *	Allows for single/batch replacement of protocols
244
-			 *
245
-			 *	This method accepts one argument that can be either a string
246
-			 *	or an array of strings.  Invalid data will be ignored.
247
-			 *
248
-			 *	Existing protocols will be removed, then the argument will be
249
-			 *	processed, and each string will be added via AddProtocol().
250
-			 *
251
-			 *	@access public
252
-			 *	@param mixed , A string or array of protocols that will be the new internal list of allowed protocols.
253
-			 *	@return bool Status of replacing valid protocols.
254
-			 *	@since PHP4 OOP 0.2.2
255
-			 *	@see AddProtocol()
256
-			 */
257
-			function SetProtocols()
258
-			{
259
-				$c_args = func_num_args();
260
-				if($c_args != 1)
261
-				{
262
-					trigger_error("kses4::SetProtocols() did not receive an argument.", E_USER_WARNING);
263
-					return false;
264
-				}
265
-
266
-				$protocol_data = func_get_arg(0);
267
-
268
-				if(is_array($protocol_data) && count($protocol_data) > 0)
269
-				{
270
-					$this->allowed_protocols = array();
271
-					foreach($protocol_data as $protocol)
272
-					{
273
-						$this->AddProtocol($protocol);
274
-					}
275
-					return true;
276
-				}
277
-				elseif(is_string($protocol_data))
278
-				{
279
-					$this->allowed_protocols = array();
280
-					$this->AddProtocol($protocol_data);
281
-					return true;
282
-				}
283
-				else
284
-				{
285
-					trigger_error("kses4::SetProtocols() did not receive a string or an array.", E_USER_WARNING);
286
-					return false;
287
-				}
288
-			}
289
-
290
-			/**
291
-			 *	Raw dump of allowed protocols
292
-			 *
293
-			 *	This returns an indexed array of allowed protocols for a particular KSES
294
-			 *	instantiation.
295
-			 *
296
-			 *	@access public
297
-			 *	@return array The list of allowed protocols.
298
-			 *	@since PHP4 OOP 0.2.2
299
-			 */
300
-			function DumpProtocols()
301
-			{
302
-				return $this->allowed_protocols;
303
-			}
304
-
305
-			/**
306
-			 *	Raw dump of allowed (X)HTML elements
307
-			 *
308
-			 *	This returns an indexed array of allowed (X)HTML elements and attributes
309
-			 *	for a particular KSES instantiation.
310
-			 *
311
-			 *	@access public
312
-			 *	@return array The list of allowed elements.
313
-			 *	@since PHP4 OOP 0.2.2
314
-			 */
315
-			function DumpElements()
316
-			{
317
-				return $this->allowed_html;
318
-			}
319
-
320
-			/**
321
-			 *	Adds valid (X)HTML with corresponding attributes that will be kept when stripping 'evil scripts'.
322
-			 *
323
-			 *	This method accepts one argument that can be either a string
324
-			 *	or an array of strings.  Invalid data will be ignored.
325
-			 *
326
-			 *	@access public
327
-			 *	@param string $tag (X)HTML tag that will be allowed after stripping text.
328
-			 *	@param array $attribs Associative array of allowed attributes - key => attribute name - value => attribute parameter
329
-			 *	@return bool Status of Adding (X)HTML and attributes.
330
-			 *	@since PHP4 OOP 0.0.1
331
-			 */
332
-			function AddHTML($tag = "", $attribs = array())
333
-			{
334
-				if(!is_string($tag))
335
-				{
336
-					trigger_error("kses4::AddHTML() requires the tag to be a string", E_USER_WARNING);
337
-					return false;
338
-				}
339
-
340
-				$tag = strtolower(trim($tag));
341
-				if($tag == "")
342
-				{
343
-					trigger_error("kses4::AddHTML() tried to add an empty/NULL tag", E_USER_WARNING);
344
-					return false;
345
-				}
346
-
347
-				if(!is_array($attribs))
348
-				{
349
-					trigger_error("kses4::AddHTML() requires an array (even an empty one) of attributes for '$tag'", E_USER_WARNING);
350
-					return false;
351
-				}
352
-
353
-				$new_attribs = array();
354
-				if(is_array($attribs) && count($attribs) > 0)
355
-				{
356
-					foreach($attribs as $idx1 => $val1)
357
-					{
358
-						$new_idx1 = strtolower($idx1);
359
-						$new_val1 = $attribs[$idx1];
360
-
361
-						if(is_array($new_val1) && count($new_val1) > 0)
362
-						{
363
-							$tmp_val = array();
364
-							foreach($new_val1 as $idx2 => $val2)
365
-							{
366
-								$new_idx2 = strtolower($idx2);
367
-								$tmp_val[$new_idx2] = $val2;
368
-							}
369
-							$new_val1 = $tmp_val;
370
-						}
371
-
372
-						$new_attribs[$new_idx1] = $new_val1;
373
-					}
374
-				}
375
-
376
-				$this->allowed_html[$tag] = $new_attribs;
377
-				return true;
378
-			}
379
-
380
-			/**
381
-			 *	Removes a single protocol from $this->allowed_protocols.
382
-			 *
383
-			 *	This method accepts a string argument and removes it from
384
-			 *	the list of allowed protocols to keep when performing
385
-			 *	Parse().
386
-			 *
387
-			 *	@access public
388
-			 *	@param string $protocol The name of the protocol to be removed.
389
-			 *	@return bool Status of removing valid protocol.
390
-			 *	@since PHP4 OOP 0.2.1
391
-			 */
392
-			function RemoveProtocol($protocol = "")
393
-			{
394
-				if(!is_string($protocol))
395
-				{
396
-					trigger_error("kses4::RemoveProtocol() requires a string.", E_USER_WARNING);
397
-					return false;
398
-				}
399
-
400
-				// Remove any inadvertent ':' at the end of the protocol.
401
-				if(substr($protocol, strlen($protocol) - 1, 1) == ":")
402
-				{
403
-					$protocol = substr($protocol, 0, strlen($protocol) - 1);
404
-				}
405
-
406
-				$protocol = strtolower(trim($protocol));
407
-				if($protocol == "")
408
-				{
409
-					trigger_error("kses4::RemoveProtocol() tried to remove an empty/NULL protocol.", E_USER_WARNING);
410
-					return false;
411
-				}
412
-
413
-				//	Ensures that the protocol exists before removing it.
414
-				if(in_array($protocol, $this->allowed_protocols))
415
-				{
416
-					$this->allowed_protocols = array_diff($this->allowed_protocols, array($protocol));
417
-					sort($this->allowed_protocols);
418
-				}
419
-
420
-				return true;
421
-			}
422
-
423
-			/**
424
-			 *	Allows for single/batch removal of protocols
425
-			 *
426
-			 *	This method accepts one argument that can be either a string
427
-			 *	or an array of strings.  Invalid data will be ignored.
428
-			 *
429
-			 *	The argument will be processed, and each string will be removed
430
-			 *	via RemoveProtocol().
431
-			 *
432
-			 *	@access public
433
-			 *	@param mixed , A string or array of protocols that will be removed from the internal list of allowed protocols.
434
-			 *	@return bool Status of removing valid protocols.
435
-			 *	@see RemoveProtocol()
436
-			 *	@since PHP5 OOP 0.2.1
437
-			 */
438
-			function RemoveProtocols()
439
-			{
440
-				$c_args = func_num_args();
441
-				if($c_args != 1)
442
-				{
443
-					return false;
444
-				}
445
-
446
-				$protocol_data = func_get_arg(0);
447
-
448
-				if(is_array($protocol_data) && count($protocol_data) > 0)
449
-				{
450
-					foreach($protocol_data as $protocol)
451
-					{
452
-						$this->RemoveProtocol($protocol);
453
-					}
454
-				}
455
-				elseif(is_string($protocol_data))
456
-				{
457
-					$this->RemoveProtocol($protocol_data);
458
-					return true;
459
-				}
460
-				else
461
-				{
462
-					trigger_error("kses4::RemoveProtocols() did not receive a string or an array.", E_USER_WARNING);
463
-					return false;
464
-				}
465
-			}
466
-
467
-			/**
468
-			 *	This method removes any NULL or characters in $string.
469
-			 *
470
-			 *	@access private
471
-			 *	@param string $string
472
-			 *	@return string String without any NULL/chr(173)
473
-			 *	@since PHP4 OOP 0.0.1
474
-			 */
475
-			function _no_null($string)
476
-			{
477
-				$string = preg_replace('/\0+/', '', $string);
478
-				$string = preg_replace('/(\\\\0)+/', '', $string);
479
-				return $string;
480
-			}
481
-
482
-			/**
483
-			 *	This function removes the HTML JavaScript entities found in early versions of
484
-			 *	Netscape 4.
485
-			 *
486
-			 *	@access private
487
-			 *	@param string $string
488
-			 *	@return string String without any NULL/chr(173)
489
-			 *	@since PHP4 OOP 0.0.1
490
-			 */
491
-			function _js_entities($string)
492
-			{
493
-			  return preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);
494
-			}
495
-
496
-			/**
497
-			 *	Normalizes HTML entities
498
-			 *
499
-			 *	This function normalizes HTML entities. It will convert "AT&T" to the correct
500
-			 *	"AT&amp;T", "&#00058;" to "&#58;", "&#XYZZY;" to "&amp;#XYZZY;" and so on.
501
-			 *
502
-			 *	@access private
503
-			 *	@param string $string
504
-			 *	@return string String with normalized entities
505
-			 *	@since PHP4 OOP 0.0.1
506
-			 */
507
-			function _normalize_entities($string)
508
-			{
509
-				# Disarm all entities by converting & to &amp;
510
-			  $string = str_replace('&', '&amp;', $string);
511
-
512
-				# Change back the allowed entities in our entity white list
513
-
514
-			  $string = preg_replace('/&amp;([A-Za-z][A-Za-z0-9]{0,19});/', '&\\1;', $string);
515
-			  $string = preg_replace('/&amp;#0*([0-9]{1,5});/e', '\$this->_normalize_entities2("\\1")', $string);
516
-			  $string = preg_replace('/&amp;#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', '&#\\1\\2;', $string);
517
-
518
-			  return $string;
519
-			}
520
-
521
-			/**
522
-			 *	Helper method used by normalizeEntites()
523
-			 *
524
-			 *	This method helps normalizeEntities() to only accept 16 bit values
525
-			 *	and nothing more for &#number; entities.
526
-			 *
527
-			 *	This method helps normalize_entities() during a preg_replace()
528
-			 *	where a &#(0)*XXXXX; occurs.  The '(0)*XXXXXX' value is converted to
529
-			 *	a number and the result is returned as a numeric entity if the number
530
-			 *	is less than 65536.  Otherwise, the value is returned 'as is'.
531
-			 *
532
-			 *	@access private
533
-			 *	@param string $i
534
-			 *	@return string Normalized numeric entity
535
-			 *	@see _normalize_entities()
536
-			 *	@since PHP4 OOP 0.0.1
537
-			 */
538
-			function _normalize_entities2($i)
539
-			{
540
-			  return (($i > 65535) ? "&amp;#$i;" : "&#$i;");
541
-			}
542
-
543
-			/**
544
-			 *	Allows for additional user defined modifications to text.
545
-			 *
546
-			 *	@deprecated use filterKsesTextHook()
547
-			 *	@param string $string
548
-			 *	@see filterKsesTextHook()
549
-			 *	@return string
550
-			 *	@since PHP4 OOP 0.0.1
551
-			 */
552
-			function _hook($string)
553
-			{
554
-			  return $this->filterKsesTextHook($string);
555
-			}
556
-
557
-			/**
558
-			 *	Allows for additional user defined modifications to text.
559
-			 *
560
-			 *	This method allows for additional modifications to be performed on
561
-			 *	a string that's being run through Parse().  Currently, it returns the
562
-			 *	input string 'as is'.
563
-			 *
564
-			 *	This method is provided for users to extend the kses class for their own
565
-			 *	requirements.
566
-			 *
567
-			 *	@access public
568
-			 *	@param string $string String to perfrom additional modifications on.
569
-			 *	@return string User modified string.
570
-			 *	@see Parse()
571
-			 *	@since PHP5 OOP 1.0.0
572
-			 */
573
-			function filterKsesTextHook($string)
574
-			{
575
-			  return $string;
576
-			}
577
-
578
-			/**
579
-			 *	This method goes through an array, and changes the keys to all lower case.
580
-			 *
581
-			 *	@access private
582
-			 *	@param array $in_array Associative array
583
-			 *	@return array Modified array
584
-			 *	@since PHP4 OOP 0.0.1
585
-			 */
586
-			function _array_lc($inarray)
587
-			{
588
-			  $outarray = array();
589
-
590
-				if(is_array($inarray) && count($inarray) > 0)
591
-				{
592
-					foreach ($inarray as $inkey => $inval)
593
-					{
594
-						$outkey = strtolower($inkey);
595
-						$outarray[$outkey] = array();
596
-
597
-						if(is_array($inval) && count($inval) > 0)
598
-						{
599
-							foreach ($inval as $inkey2 => $inval2)
600
-							{
601
-								$outkey2 = strtolower($inkey2);
602
-								$outarray[$outkey][$outkey2] = $inval2;
603
-							}
604
-						}
605
-					}
606
-				}
607
-
608
-			  return $outarray;
609
-			}
610
-
611
-			/**
612
-			 *	This method searched for HTML tags, no matter how malformed.  It also
613
-			 *	matches stray ">" characters.
614
-			 *
615
-			 *	@access private
616
-			 *	@param string $string
617
-			 *	@return string HTML tags
618
-			 *	@since PHP4 OOP 0.0.1
619
-			 */
620
-			function _split($string)
621
-			{
622
-				return preg_replace(
623
-					'%(<'.   # EITHER: <
624
-					'[^>]*'. # things that aren't >
625
-					'(>|$)'. # > or end of string
626
-					'|>)%e', # OR: just a >
627
-					"\$this->_split2('\\1')",
628
-					$string);
629
-			}
630
-
631
-			/**
632
-			 *	This method strips out disallowed and/or mangled (X)HTML tags along with assigned attributes.
633
-			 *
634
-			 *	This method does a lot of work. It rejects some very malformed things
635
-			 *	like <:::>. It returns an empty string if the element isn't allowed (look
636
-			 *	ma, no strip_tags()!). Otherwise it splits the tag into an element and an
637
-			 *	allowed attribute list.
638
-			 *
639
-			 *	@access private
640
-			 *	@param string $string
641
-			 *	@return string Modified string minus disallowed/mangled (X)HTML and attributes
642
-			 *	@since PHP4 OOP 0.0.1
643
-			 */
644
-			function _split2($string)
645
-			{
646
-				$string = $this->_stripslashes($string);
647
-
648
-				if (substr($string, 0, 1) != '<')
649
-				{
650
-					# It matched a ">" character
651
-					return '&gt;';
652
-				}
653
-
654
-				if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
655
-				{
656
-					# It's seriously malformed
657
-					return '';
658
-				}
659
-
660
-				$slash    = trim($matches[1]);
661
-				$elem     = $matches[2];
662
-				$attrlist = $matches[3];
663
-
664
-				if (
665
-					!isset($this->allowed_html[strtolower($elem)]) ||
666
-					!is_array($this->allowed_html[strtolower($elem)])
667
-				)
668
-				{
669
-					# They are using a not allowed HTML element
670
-					return '';
671
-				}
672
-
673
-				if ($slash != '')
674
-				{
675
-					return "<$slash$elem>";
676
-				}
677
-				# No attributes are allowed for closing elements
678
-
679
-				return $this->_attr("$slash$elem", $attrlist);
680
-			}
681
-
682
-			/**
683
-			 *	This method strips out disallowed attributes for (X)HTML tags.
684
-			 *
685
-			 *	This method removes all attributes if none are allowed for this element.
686
-			 *	If some are allowed it calls $this->_hair() to split them further, and then it
687
-			 *	builds up new HTML code from the data that $this->_hair() returns. It also
688
-			 *	removes "<" and ">" characters, if there are any left. One more thing it
689
-			 *	does is to check if the tag has a closing XHTML slash, and if it does,
690
-			 *	it puts one in the returned code as well.
691
-			 *
692
-			 *	@access private
693
-			 *	@param string $element (X)HTML tag to check
694
-			 *	@param string $attr Text containing attributes to check for validity.
695
-			 *	@return string Resulting valid (X)HTML or ''
696
-			 *	@see _hair()
697
-			 *	@since PHP4 OOP 0.0.1
698
-			 */
699
-			function _attr($element, $attr)
700
-			{
701
-				# Is there a closing XHTML slash at the end of the attributes?
702
-				$xhtml_slash = '';
703
-				if (preg_match('%\s/\s*$%', $attr))
704
-				{
705
-					$xhtml_slash = ' /';
706
-				}
707
-
708
-				# Are any attributes allowed at all for this element?
709
-				if (
710
-					!isset($this->allowed_html[strtolower($element)]) ||
711
-					count($this->allowed_html[strtolower($element)]) == 0
712
-				)
713
-				{
714
-					return "<$element$xhtml_slash>";
715
-				}
716
-
717
-				# Split it
718
-				$attrarr = $this->_hair($attr);
719
-
720
-				# Go through $attrarr, and save the allowed attributes for this element
721
-				# in $attr2
722
-				$attr2 = '';
723
-				if(is_array($attrarr) && count($attrarr) > 0)
724
-				{
725
-					foreach ($attrarr as $arreach)
726
-					{
727
-						if(!isset($this->allowed_html[strtolower($element)][strtolower($arreach['name'])]))
728
-						{
729
-							continue;
730
-						}
731
-
732
-						$current = $this->allowed_html[strtolower($element)][strtolower($arreach['name'])];
733
-						if ($current == '')
734
-						{
735
-							# the attribute is not allowed
736
-							continue;
737
-						}
738
-
739
-						if (!is_array($current))
740
-						{
741
-							# there are no checks
742
-							$attr2 .= ' '.$arreach['whole'];
743
-						}
744
-						else
745
-						{
746
-							# there are some checks
747
-							$ok = true;
748
-							if(is_array($current) && count($current) > 0)
749
-							{
750
-								foreach ($current as $currkey => $currval)
751
-								{
752
-									if (!$this->_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval))
753
-									{
754
-										$ok = false;
755
-										break;
756
-									}
757
-								}
758
-
759
-								if ($ok)
760
-								{
761
-									# it passed them
762
-									$attr2 .= ' '.$arreach['whole'];
763
-								}
764
-							}
765
-						}
766
-					}
767
-				}
768
-
769
-				# Remove any "<" or ">" characters
770
-				$attr2 = preg_replace('/[<>]/', '', $attr2);
771
-				return "<$element$attr2$xhtml_slash>";
772
-			}
773
-
774
-			/**
775
-			 *	This method combs through an attribute list string and returns an associative array of attributes and values.
776
-			 *
777
-			 *	This method does a lot of work. It parses an attribute list into an array
778
-			 *	with attribute data, and tries to do the right thing even if it gets weird
779
-			 *	input. It will add quotes around attribute values that don't have any quotes
780
-			 *	or apostrophes around them, to make it easier to produce HTML code that will
781
-			 *	conform to W3C's HTML specification. It will also remove bad URL protocols
782
-			 *	from attribute values.
783
-			 *
784
-			 *	@access private
785
-			 *	@param string $attr Text containing tag attributes for parsing
786
-			 *	@return array Associative array containing data on attribute and value
787
-			 *	@since PHP4 OOP 0.0.1
788
-			 */
789
-			function _hair($attr)
790
-			{
791
-				$attrarr  = array();
792
-				$mode     = 0;
793
-				$attrname = '';
794
-
795
-				# Loop through the whole attribute list
796
-
797
-				while (strlen($attr) != 0)
798
-				{
799
-					# Was the last operation successful?
800
-					$working = 0;
801
-
802
-					switch ($mode)
803
-					{
804
-						case 0:	# attribute name, href for instance
805
-							if (preg_match('/^([-a-zA-Z]+)/', $attr, $match))
806
-							{
807
-								$attrname = $match[1];
808
-								$working = $mode = 1;
809
-								$attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
810
-							}
811
-							break;
812
-						case 1:	# equals sign or valueless ("selected")
813
-							if (preg_match('/^\s*=\s*/', $attr)) # equals sign
814
-							{
815
-								$working = 1;
816
-								$mode    = 2;
817
-								$attr    = preg_replace('/^\s*=\s*/', '', $attr);
818
-								break;
819
-							}
820
-							if (preg_match('/^\s+/', $attr)) # valueless
821
-							{
822
-								$working   = 1;
823
-								$mode      = 0;
824
-								$attrarr[] = array(
825
-									'name'  => $attrname,
826
-									'value' => '',
827
-									'whole' => $attrname,
828
-									'vless' => 'y'
829
-								);
830
-								$attr      = preg_replace('/^\s+/', '', $attr);
831
-							}
832
-							break;
833
-						case 2: # attribute value, a URL after href= for instance
834
-							if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match)) # "value"
835
-							{
836
-								$thisval   = $this->_bad_protocol($match[1]);
837
-								$attrarr[] = array(
838
-									'name'  => $attrname,
839
-									'value' => $thisval,
840
-									'whole' => "$attrname=\"$thisval\"",
841
-									'vless' => 'n'
842
-								);
843
-								$working   = 1;
844
-								$mode      = 0;
845
-								$attr      = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
846
-								break;
847
-							}
848
-							if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match)) # 'value'
849
-							{
850
-								$thisval   = $this->_bad_protocol($match[1]);
851
-								$attrarr[] = array(
852
-									'name'  => $attrname,
853
-									'value' => $thisval,
854
-									'whole' => "$attrname='$thisval'",
855
-									'vless' => 'n'
856
-								);
857
-								$working   = 1;
858
-								$mode      = 0;
859
-								$attr      = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
860
-								break;
861
-							}
862
-							if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match)) # value
863
-							{
864
-								$thisval   = $this->_bad_protocol($match[1]);
865
-								$attrarr[] = array(
866
-									'name'  => $attrname,
867
-									'value' => $thisval,
868
-									'whole' => "$attrname=\"$thisval\"",
869
-									'vless' => 'n'
870
-								);
871
-								# We add quotes to conform to W3C's HTML spec.
872
-								$working   = 1;
873
-								$mode      = 0;
874
-								$attr      = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
875
-							}
876
-							break;
877
-					}
878
-
879
-					if ($working == 0) # not well formed, remove and try again
880
-					{
881
-						$attr = $this->_html_error($attr);
882
-						$mode = 0;
883
-					}
884
-				}
885
-
886
-				# special case, for when the attribute list ends with a valueless
887
-				# attribute like "selected"
888
-				if ($mode == 1)
889
-				{
890
-					$attrarr[] = array(
891
-						'name'  => $attrname,
892
-						'value' => '',
893
-						'whole' => $attrname,
894
-						'vless' => 'y'
895
-					);
896
-				}
897
-
898
-				return $attrarr;
899
-			}
900
-
901
-			/**
902
-			 *	This method removes disallowed protocols.
903
-			 *
904
-			 *	This method removes all non-allowed protocols from the beginning of
905
-			 *	$string. It ignores whitespace and the case of the letters, and it does
906
-			 *	understand HTML entities. It does its work in a while loop, so it won't be
907
-			 *	fooled by a string like "javascript:javascript:alert(57)".
908
-			 *
909
-			 *	@access private
910
-			 *	@param string $string String to check for protocols
911
-			 *	@return string String with removed protocols
912
-			 *	@since PHP4 OOP 0.0.1
913
-			 */
914
-			function _bad_protocol($string)
915
-			{
916
-				$string  = $this->_no_null($string);
917
-				$string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature"
918
-				$string2 = $string.'a';
919
-
920
-				while ($string != $string2)
921
-				{
922
-					$string2 = $string;
923
-					$string  = $this->_bad_protocol_once($string);
924
-				} # while
925
-
926
-				return $string;
927
-			}
928
-
929
-			/**
930
-			 *	Helper method used by _bad_protocol()
931
-			 *
932
-			 *	This function searches for URL protocols at the beginning of $string, while
933
-			 *	handling whitespace and HTML entities.
934
-			 *  Function updated to fix security vulnerability (see http://projects.dokeos.com/index.php?do=details&task_id=2312)
935
-			 *
936
-			 *	@access private
937
-			 *	@param string $string String to check for protocols
938
-			 *	@return string String with removed protocols
939
-			 *	@see _bad_protocol()
940
-			 *	@since PHP4 OOP 0.0.1
941
-			 */
942
-			function _bad_protocol_once($string)
943
-			{
944
-				$string2 = preg_split('/:|&#58;|&#x3a;/i', $string, 2);
945
-				if(isset($string2[1]) && !preg_match('%/\?%',$string2[0]))
946
-				{
947
-					$string = $this->_bad_protocol_once2($string2[0]).trim($string2[1]);
948
-				}
949
-				return $string;
950
-			}
951
-			/**
952
-			 *	Helper method used by _bad_protocol_once() regex
953
-			 *
954
-			 *	This function processes URL protocols, checks to see if they're in the white-
955
-			 *	list or not, and returns different data depending on the answer.
956
-			 *
957
-			 *	@access private
958
-			 *	@param string $string String to check for protocols
959
-			 *	@return string String with removed protocols
960
-			 *	@see _bad_protocol()
961
-			 *	@see _bad_protocol_once()
962
-			 *	@since PHP4 OOP 0.0.1
963
-			 */
964
-			function _bad_protocol_once2($string)
965
-			{
966
-				$string = $this->_decode_entities($string);
967
-				$string = preg_replace('/\s/', '', $string);
968
-				$string = $this->_no_null($string);
969
-				$string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature"
970
-				$string = strtolower($string);
971
-
972
-				$allowed = false;
973
-				if(is_array($this->allowed_protocols) && count($this->allowed_protocols) > 0)
974
-				{
975
-					foreach ($this->allowed_protocols as $one_protocol)
976
-					{
977
-						if (strtolower($one_protocol) == $string)
978
-						{
979
-							$allowed = true;
980
-							break;
981
-						}
982
-					}
983
-				}
984
-
985
-				if ($allowed)
986
-				{
987
-					return "$string:";
988
-				}
989
-				else
990
-				{
991
-					return '';
992
-				}
993
-			}
994
-
995
-			/**
996
-			 *	This function performs different checks for attribute values.
997
-			 *
998
-			 *	The currently implemented checks are "maxlen", "minlen", "maxval",
999
-			 *	"minval" and "valueless" with even more checks to come soon.
1000
-			 *
1001
-			 *	@access private
1002
-			 *	@param string $value The value of the attribute to be checked.
1003
-			 *	@param string $vless Indicates whether the the value is supposed to be valueless
1004
-			 *	@param string $checkname The check to be performed
1005
-			 *	@param string $checkvalue The value that is to be checked against
1006
-			 *	@return bool Indicates whether the check passed or not
1007
-			 *	@since PHP4 OOP 0.0.1
1008
-			 */
1009
-			function _check_attr_val($value, $vless, $checkname, $checkvalue)
1010
-			{
1011
-				$ok = true;
1012
-
1013
-				switch (strtolower($checkname))
1014
-				{
1015
-					/**
1016
-					*	The maxlen check makes sure that the attribute value has a length not
1017
-					*	greater than the given value. This can be used to avoid Buffer Overflows
1018
-					*	in WWW clients and various Internet servers.
1019
-					*/
1020
-					case 'maxlen':
1021
-						if (strlen($value) > $checkvalue)
1022
-						{
1023
-							$ok = false;
1024
-						}
1025
-						break;
1026
-
1027
-					/**
1028
-					*	The minlen check makes sure that the attribute value has a length not
1029
-					*	smaller than the given value.
1030
-					*/
1031
-					case 'minlen':
1032
-						if (strlen($value) < $checkvalue)
1033
-						{
1034
-							$ok = false;
1035
-						}
1036
-						break;
1037
-
1038
-					/**
1039
-					*	The maxval check does two things: it checks that the attribute value is
1040
-					*	an integer from 0 and up, without an excessive amount of zeroes or
1041
-					*	whitespace (to avoid Buffer Overflows). It also checks that the attribute
1042
-					*	value is not greater than the given value.
1043
-					*	This check can be used to avoid Denial of Service attacks.
1044
-					*/
1045
-					case 'maxval':
1046
-						if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
1047
-						{
1048
-							$ok = false;
1049
-						}
1050
-						if ($value > $checkvalue)
1051
-						{
1052
-							$ok = false;
1053
-						}
1054
-						break;
1055
-
1056
-					/**
1057
-					*	The minval check checks that the attribute value is a positive integer,
1058
-					*	and that it is not smaller than the given value.
1059
-					*/
1060
-					case 'minval':
1061
-						if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
1062
-						{
1063
-							$ok = false;
1064
-						}
1065
-						if ($value < $checkvalue)
1066
-						{
1067
-							$ok = false;
1068
-						}
1069
-						break;
1070
-
1071
-					/**
1072
-					*	The valueless check checks if the attribute has a value
1073
-					*	(like <a href="blah">) or not (<option selected>). If the given value
1074
-					*	is a "y" or a "Y", the attribute must not have a value.
1075
-					*	If the given value is an "n" or an "N", the attribute must have one.
1076
-					*/
1077
-					case 'valueless':
1078
-					if (strtolower($checkvalue) != $vless)
1079
-					{
1080
-						$ok = false;
1081
-					}
1082
-					break;
1083
-
1084
-				}
1085
-
1086
-				return $ok;
1087
-			}
1088
-
1089
-			/**
1090
-			 *	Changes \" to "
1091
-			 *
1092
-			 *	This function changes the character sequence  \"  to just  "
1093
-			 *	It leaves all other slashes alone. It's really weird, but the quoting from
1094
-			 *	preg_replace(//e) seems to require this.
1095
-			 *
1096
-			 *	@access private
1097
-			 *	@param string $string The string to be stripped.
1098
-			 *	@return string string stripped of \"
1099
-			 *	@since PHP4 OOP 0.0.1
1100
-			 */
1101
-			function _stripslashes($string)
1102
-			{
1103
-				return preg_replace('%\\\\"%', '"', $string);
1104
-			}
1105
-
1106
-			/**
1107
-			 *	helper method for _hair()
1108
-			 *
1109
-			 *	This function deals with parsing errors in _hair(). The general plan is
1110
-			 *	to remove everything to and including some whitespace, but it deals with
1111
-			 *	quotes and apostrophes as well.
1112
-			 *
1113
-			 *	@access private
1114
-			 *	@param string $string The string to be stripped.
1115
-			 *	@return string string stripped of whitespace
1116
-			 *	@see _hair()
1117
-			 *	@since PHP4 OOP 0.0.1
1118
-			 */
1119
-			function _html_error($string)
1120
-			{
1121
-				return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string);
1122
-			}
1123
-
1124
-			/**
1125
-			 *	Decodes numeric HTML entities
1126
-			 *
1127
-			 *	This method decodes numeric HTML entities (&#65; and &#x41;). It doesn't
1128
-			 *	do anything with other entities like &auml;, but we don't need them in the
1129
-			 *	URL protocol white listing system anyway.
1130
-			 *
1131
-			 *	@access private
1132
-			 *	@param string $value The entitiy to be decoded.
1133
-			 *	@return string Decoded entity
1134
-			 *	@since PHP4 OOP 0.0.1
1135
-			 */
1136
-			function _decode_entities($string)
1137
-			{
1138
-				$string = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $string);
1139
-				$string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', 'chr(hexdec("\\1"))', $string);
1140
-				return $string;
1141
-			}
1142
-
1143
-			/**
1144
-			 *	Returns PHP4 OOP version # of kses.
1145
-			 *
1146
-			 *	Since this class has been refactored and documented and proven to work,
1147
-			 *	I'm syncing the version number to procedural kses.
1148
-			 *
1149
-			 *	@access public
1150
-			 *	@return string Version number
1151
-			 *	@since PHP4 OOP 0.0.1
1152
-			 */
1153
-			function _version()
1154
-			{
1155
-				return 'PHP4 0.2.2 (OOP fork of procedural kses 0.2.2)';
1156
-			}
1157
-		}
1158
-
1159
-
1160
-
1161
-	}
88
+            var $allowed_protocols = array();
89
+            var $allowed_html      = array();
90
+            /**#@-*/
91
+
92
+            /**
93
+             *	Constructor for kses.
94
+             *
95
+             *	This sets a default collection of protocols allowed in links, and creates an
96
+             *	empty set of allowed HTML tags.
97
+             *	@since PHP4 OOP 0.0.1
98
+             */
99
+            function kses4()
100
+            {
101
+                /**
102
+                 *	You could add protocols such as ftp, new, gopher, mailto, irc, etc.
103
+                 *
104
+                 *	The base values the original kses provided were:
105
+                 *		'http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto'
106
+                 */
107
+                $this->allowed_protocols = array('http', 'ftp', 'mailto');
108
+                $this->allowed_html      = array();
109
+            }
110
+
111
+            /**
112
+             *	Basic task of kses - parses $string and strips it as required.
113
+             *
114
+             *	This method strips all the disallowed (X)HTML tags, attributes
115
+             *	and protocols from the input $string.
116
+             *
117
+             *	@access public
118
+             *	@param string $string String to be stripped of 'evil scripts'
119
+             *	@return string The stripped string
120
+             *	@since PHP4 OOP 0.2.1
121
+             */
122
+            function Parse($string = "")
123
+            {
124
+                if (get_magic_quotes_gpc())
125
+                {
126
+                    $string = stripslashes($string);
127
+                }
128
+                $string = $this->_no_null($string);
129
+                $string = $this->_js_entities($string);
130
+                $string = $this->_normalize_entities($string);
131
+                $string = $this->filterKsesTextHook($string);
132
+                return    $this->_split($string);
133
+            }
134
+
135
+            /**
136
+             *	Allows for single/batch addition of protocols
137
+             *
138
+             *	This method accepts one argument that can be either a string
139
+             *	or an array of strings.  Invalid data will be ignored.
140
+             *
141
+             *	The argument will be processed, and each string will be added
142
+             *	via AddProtocol().
143
+             *
144
+             *	@access public
145
+             *	@param mixed , A string or array of protocols that will be added to the internal list of allowed protocols.
146
+             *	@return bool Status of adding valid protocols.
147
+             *	@see AddProtocol()
148
+             *	@since PHP4 OOP 0.2.1
149
+             */
150
+            function AddProtocols()
151
+            {
152
+                $c_args = func_num_args();
153
+                if($c_args != 1)
154
+                {
155
+                    trigger_error("kses4::AddProtocols() did not receive an argument.", E_USER_WARNING);
156
+                    return false;
157
+                }
158
+
159
+                $protocol_data = func_get_arg(0);
160
+
161
+                if(is_array($protocol_data) && count($protocol_data) > 0)
162
+                {
163
+                    foreach($protocol_data as $protocol)
164
+                    {
165
+                        $this->AddProtocol($protocol);
166
+                    }
167
+                    return true;
168
+                }
169
+                elseif(is_string($protocol_data))
170
+                {
171
+                    $this->AddProtocol($protocol_data);
172
+                    return true;
173
+                }
174
+                else
175
+                {
176
+                    trigger_error("kses4::AddProtocols() did not receive a string or an array.", E_USER_WARNING);
177
+                    return false;
178
+                }
179
+            }
180
+
181
+            /**
182
+             *	Allows for single/batch addition of protocols
183
+             *
184
+             *	@deprecated Use AddProtocols()
185
+             *	@see AddProtocols()
186
+             *	@return bool
187
+             *	@since PHP4 OOP 0.0.1
188
+             */
189
+            function Protocols()
190
+            {
191
+                $c_args = func_num_args();
192
+                if($c_args != 1)
193
+                {
194
+                    trigger_error("kses4::Protocols() did not receive an argument.", E_USER_WARNING);
195
+                    return false;
196
+                }
197
+
198
+                return $this->AddProtocols(func_get_arg(0));
199
+            }
200
+
201
+            /**
202
+             *	Adds a single protocol to $this->allowed_protocols.
203
+             *
204
+             *	This method accepts a string argument and adds it to
205
+             *	the list of allowed protocols to keep when performing
206
+             *	Parse().
207
+             *
208
+             *	@access public
209
+             *	@param string $protocol The name of the protocol to be added.
210
+             *	@return bool Status of adding valid protocol.
211
+             *	@since PHP4 OOP 0.0.1
212
+             */
213
+            function AddProtocol($protocol = "")
214
+            {
215
+                if(!is_string($protocol))
216
+                {
217
+                    trigger_error("kses4::AddProtocol() requires a string.", E_USER_WARNING);
218
+                    return false;
219
+                }
220
+
221
+                $protocol = strtolower(trim($protocol));
222
+                if($protocol == "")
223
+                {
224
+                    trigger_error("kses4::AddProtocol() tried to add an empty/NULL protocol.", E_USER_WARNING);
225
+                    return false;
226
+                }
227
+
228
+                // Remove any inadvertent ':' at the end of the protocol.
229
+                if(substr($protocol, strlen($protocol) - 1, 1) == ":")
230
+                {
231
+                    $protocol = substr($protocol, 0, strlen($protocol) - 1);
232
+                }
233
+
234
+                if(!in_array($protocol, $this->allowed_protocols))
235
+                {
236
+                    array_push($this->allowed_protocols, $protocol);
237
+                    sort($this->allowed_protocols);
238
+                }
239
+                return true;
240
+            }
241
+
242
+            /**
243
+             *	Allows for single/batch replacement of protocols
244
+             *
245
+             *	This method accepts one argument that can be either a string
246
+             *	or an array of strings.  Invalid data will be ignored.
247
+             *
248
+             *	Existing protocols will be removed, then the argument will be
249
+             *	processed, and each string will be added via AddProtocol().
250
+             *
251
+             *	@access public
252
+             *	@param mixed , A string or array of protocols that will be the new internal list of allowed protocols.
253
+             *	@return bool Status of replacing valid protocols.
254
+             *	@since PHP4 OOP 0.2.2
255
+             *	@see AddProtocol()
256
+             */
257
+            function SetProtocols()
258
+            {
259
+                $c_args = func_num_args();
260
+                if($c_args != 1)
261
+                {
262
+                    trigger_error("kses4::SetProtocols() did not receive an argument.", E_USER_WARNING);
263
+                    return false;
264
+                }
265
+
266
+                $protocol_data = func_get_arg(0);
267
+
268
+                if(is_array($protocol_data) && count($protocol_data) > 0)
269
+                {
270
+                    $this->allowed_protocols = array();
271
+                    foreach($protocol_data as $protocol)
272
+                    {
273
+                        $this->AddProtocol($protocol);
274
+                    }
275
+                    return true;
276
+                }
277
+                elseif(is_string($protocol_data))
278
+                {
279
+                    $this->allowed_protocols = array();
280
+                    $this->AddProtocol($protocol_data);
281
+                    return true;
282
+                }
283
+                else
284
+                {
285
+                    trigger_error("kses4::SetProtocols() did not receive a string or an array.", E_USER_WARNING);
286
+                    return false;
287
+                }
288
+            }
289
+
290
+            /**
291
+             *	Raw dump of allowed protocols
292
+             *
293
+             *	This returns an indexed array of allowed protocols for a particular KSES
294
+             *	instantiation.
295
+             *
296
+             *	@access public
297
+             *	@return array The list of allowed protocols.
298
+             *	@since PHP4 OOP 0.2.2
299
+             */
300
+            function DumpProtocols()
301
+            {
302
+                return $this->allowed_protocols;
303
+            }
304
+
305
+            /**
306
+             *	Raw dump of allowed (X)HTML elements
307
+             *
308
+             *	This returns an indexed array of allowed (X)HTML elements and attributes
309
+             *	for a particular KSES instantiation.
310
+             *
311
+             *	@access public
312
+             *	@return array The list of allowed elements.
313
+             *	@since PHP4 OOP 0.2.2
314
+             */
315
+            function DumpElements()
316
+            {
317
+                return $this->allowed_html;
318
+            }
319
+
320
+            /**
321
+             *	Adds valid (X)HTML with corresponding attributes that will be kept when stripping 'evil scripts'.
322
+             *
323
+             *	This method accepts one argument that can be either a string
324
+             *	or an array of strings.  Invalid data will be ignored.
325
+             *
326
+             *	@access public
327
+             *	@param string $tag (X)HTML tag that will be allowed after stripping text.
328
+             *	@param array $attribs Associative array of allowed attributes - key => attribute name - value => attribute parameter
329
+             *	@return bool Status of Adding (X)HTML and attributes.
330
+             *	@since PHP4 OOP 0.0.1
331
+             */
332
+            function AddHTML($tag = "", $attribs = array())
333
+            {
334
+                if(!is_string($tag))
335
+                {
336
+                    trigger_error("kses4::AddHTML() requires the tag to be a string", E_USER_WARNING);
337
+                    return false;
338
+                }
339
+
340
+                $tag = strtolower(trim($tag));
341
+                if($tag == "")
342
+                {
343
+                    trigger_error("kses4::AddHTML() tried to add an empty/NULL tag", E_USER_WARNING);
344
+                    return false;
345
+                }
346
+
347
+                if(!is_array($attribs))
348
+                {
349
+                    trigger_error("kses4::AddHTML() requires an array (even an empty one) of attributes for '$tag'", E_USER_WARNING);
350
+                    return false;
351
+                }
352
+
353
+                $new_attribs = array();
354
+                if(is_array($attribs) && count($attribs) > 0)
355
+                {
356
+                    foreach($attribs as $idx1 => $val1)
357
+                    {
358
+                        $new_idx1 = strtolower($idx1);
359
+                        $new_val1 = $attribs[$idx1];
360
+
361
+                        if(is_array($new_val1) && count($new_val1) > 0)
362
+                        {
363
+                            $tmp_val = array();
364
+                            foreach($new_val1 as $idx2 => $val2)
365
+                            {
366
+                                $new_idx2 = strtolower($idx2);
367
+                                $tmp_val[$new_idx2] = $val2;
368
+                            }
369
+                            $new_val1 = $tmp_val;
370
+                        }
371
+
372
+                        $new_attribs[$new_idx1] = $new_val1;
373
+                    }
374
+                }
375
+
376
+                $this->allowed_html[$tag] = $new_attribs;
377
+                return true;
378
+            }
379
+
380
+            /**
381
+             *	Removes a single protocol from $this->allowed_protocols.
382
+             *
383
+             *	This method accepts a string argument and removes it from
384
+             *	the list of allowed protocols to keep when performing
385
+             *	Parse().
386
+             *
387
+             *	@access public
388
+             *	@param string $protocol The name of the protocol to be removed.
389
+             *	@return bool Status of removing valid protocol.
390
+             *	@since PHP4 OOP 0.2.1
391
+             */
392
+            function RemoveProtocol($protocol = "")
393
+            {
394
+                if(!is_string($protocol))
395
+                {
396
+                    trigger_error("kses4::RemoveProtocol() requires a string.", E_USER_WARNING);
397
+                    return false;
398
+                }
399
+
400
+                // Remove any inadvertent ':' at the end of the protocol.
401
+                if(substr($protocol, strlen($protocol) - 1, 1) == ":")
402
+                {
403
+                    $protocol = substr($protocol, 0, strlen($protocol) - 1);
404
+                }
405
+
406
+                $protocol = strtolower(trim($protocol));
407
+                if($protocol == "")
408
+                {
409
+                    trigger_error("kses4::RemoveProtocol() tried to remove an empty/NULL protocol.", E_USER_WARNING);
410
+                    return false;
411
+                }
412
+
413
+                //	Ensures that the protocol exists before removing it.
414
+                if(in_array($protocol, $this->allowed_protocols))
415
+                {
416
+                    $this->allowed_protocols = array_diff($this->allowed_protocols, array($protocol));
417
+                    sort($this->allowed_protocols);
418
+                }
419
+
420
+                return true;
421
+            }
422
+
423
+            /**
424
+             *	Allows for single/batch removal of protocols
425
+             *
426
+             *	This method accepts one argument that can be either a string
427
+             *	or an array of strings.  Invalid data will be ignored.
428
+             *
429
+             *	The argument will be processed, and each string will be removed
430
+             *	via RemoveProtocol().
431
+             *
432
+             *	@access public
433
+             *	@param mixed , A string or array of protocols that will be removed from the internal list of allowed protocols.
434
+             *	@return bool Status of removing valid protocols.
435
+             *	@see RemoveProtocol()
436
+             *	@since PHP5 OOP 0.2.1
437
+             */
438
+            function RemoveProtocols()
439
+            {
440
+                $c_args = func_num_args();
441
+                if($c_args != 1)
442
+                {
443
+                    return false;
444
+                }
445
+
446
+                $protocol_data = func_get_arg(0);
447
+
448
+                if(is_array($protocol_data) && count($protocol_data) > 0)
449
+                {
450
+                    foreach($protocol_data as $protocol)
451
+                    {
452
+                        $this->RemoveProtocol($protocol);
453
+                    }
454
+                }
455
+                elseif(is_string($protocol_data))
456
+                {
457
+                    $this->RemoveProtocol($protocol_data);
458
+                    return true;
459
+                }
460
+                else
461
+                {
462
+                    trigger_error("kses4::RemoveProtocols() did not receive a string or an array.", E_USER_WARNING);
463
+                    return false;
464
+                }
465
+            }
466
+
467
+            /**
468
+             *	This method removes any NULL or characters in $string.
469
+             *
470
+             *	@access private
471
+             *	@param string $string
472
+             *	@return string String without any NULL/chr(173)
473
+             *	@since PHP4 OOP 0.0.1
474
+             */
475
+            function _no_null($string)
476
+            {
477
+                $string = preg_replace('/\0+/', '', $string);
478
+                $string = preg_replace('/(\\\\0)+/', '', $string);
479
+                return $string;
480
+            }
481
+
482
+            /**
483
+             *	This function removes the HTML JavaScript entities found in early versions of
484
+             *	Netscape 4.
485
+             *
486
+             *	@access private
487
+             *	@param string $string
488
+             *	@return string String without any NULL/chr(173)
489
+             *	@since PHP4 OOP 0.0.1
490
+             */
491
+            function _js_entities($string)
492
+            {
493
+                return preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);
494
+            }
495
+
496
+            /**
497
+             *	Normalizes HTML entities
498
+             *
499
+             *	This function normalizes HTML entities. It will convert "AT&T" to the correct
500
+             *	"AT&amp;T", "&#00058;" to "&#58;", "&#XYZZY;" to "&amp;#XYZZY;" and so on.
501
+             *
502
+             *	@access private
503
+             *	@param string $string
504
+             *	@return string String with normalized entities
505
+             *	@since PHP4 OOP 0.0.1
506
+             */
507
+            function _normalize_entities($string)
508
+            {
509
+                # Disarm all entities by converting & to &amp;
510
+                $string = str_replace('&', '&amp;', $string);
511
+
512
+                # Change back the allowed entities in our entity white list
513
+
514
+                $string = preg_replace('/&amp;([A-Za-z][A-Za-z0-9]{0,19});/', '&\\1;', $string);
515
+                $string = preg_replace('/&amp;#0*([0-9]{1,5});/e', '\$this->_normalize_entities2("\\1")', $string);
516
+                $string = preg_replace('/&amp;#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', '&#\\1\\2;', $string);
517
+
518
+                return $string;
519
+            }
520
+
521
+            /**
522
+             *	Helper method used by normalizeEntites()
523
+             *
524
+             *	This method helps normalizeEntities() to only accept 16 bit values
525
+             *	and nothing more for &#number; entities.
526
+             *
527
+             *	This method helps normalize_entities() during a preg_replace()
528
+             *	where a &#(0)*XXXXX; occurs.  The '(0)*XXXXXX' value is converted to
529
+             *	a number and the result is returned as a numeric entity if the number
530
+             *	is less than 65536.  Otherwise, the value is returned 'as is'.
531
+             *
532
+             *	@access private
533
+             *	@param string $i
534
+             *	@return string Normalized numeric entity
535
+             *	@see _normalize_entities()
536
+             *	@since PHP4 OOP 0.0.1
537
+             */
538
+            function _normalize_entities2($i)
539
+            {
540
+                return (($i > 65535) ? "&amp;#$i;" : "&#$i;");
541
+            }
542
+
543
+            /**
544
+             *	Allows for additional user defined modifications to text.
545
+             *
546
+             *	@deprecated use filterKsesTextHook()
547
+             *	@param string $string
548
+             *	@see filterKsesTextHook()
549
+             *	@return string
550
+             *	@since PHP4 OOP 0.0.1
551
+             */
552
+            function _hook($string)
553
+            {
554
+                return $this->filterKsesTextHook($string);
555
+            }
556
+
557
+            /**
558
+             *	Allows for additional user defined modifications to text.
559
+             *
560
+             *	This method allows for additional modifications to be performed on
561
+             *	a string that's being run through Parse().  Currently, it returns the
562
+             *	input string 'as is'.
563
+             *
564
+             *	This method is provided for users to extend the kses class for their own
565
+             *	requirements.
566
+             *
567
+             *	@access public
568
+             *	@param string $string String to perfrom additional modifications on.
569
+             *	@return string User modified string.
570
+             *	@see Parse()
571
+             *	@since PHP5 OOP 1.0.0
572
+             */
573
+            function filterKsesTextHook($string)
574
+            {
575
+                return $string;
576
+            }
577
+
578
+            /**
579
+             *	This method goes through an array, and changes the keys to all lower case.
580
+             *
581
+             *	@access private
582
+             *	@param array $in_array Associative array
583
+             *	@return array Modified array
584
+             *	@since PHP4 OOP 0.0.1
585
+             */
586
+            function _array_lc($inarray)
587
+            {
588
+                $outarray = array();
589
+
590
+                if(is_array($inarray) && count($inarray) > 0)
591
+                {
592
+                    foreach ($inarray as $inkey => $inval)
593
+                    {
594
+                        $outkey = strtolower($inkey);
595
+                        $outarray[$outkey] = array();
596
+
597
+                        if(is_array($inval) && count($inval) > 0)
598
+                        {
599
+                            foreach ($inval as $inkey2 => $inval2)
600
+                            {
601
+                                $outkey2 = strtolower($inkey2);
602
+                                $outarray[$outkey][$outkey2] = $inval2;
603
+                            }
604
+                        }
605
+                    }
606
+                }
607
+
608
+                return $outarray;
609
+            }
610
+
611
+            /**
612
+             *	This method searched for HTML tags, no matter how malformed.  It also
613
+             *	matches stray ">" characters.
614
+             *
615
+             *	@access private
616
+             *	@param string $string
617
+             *	@return string HTML tags
618
+             *	@since PHP4 OOP 0.0.1
619
+             */
620
+            function _split($string)
621
+            {
622
+                return preg_replace(
623
+                    '%(<'.   # EITHER: <
624
+                    '[^>]*'. # things that aren't >
625
+                    '(>|$)'. # > or end of string
626
+                    '|>)%e', # OR: just a >
627
+                    "\$this->_split2('\\1')",
628
+                    $string);
629
+            }
630
+
631
+            /**
632
+             *	This method strips out disallowed and/or mangled (X)HTML tags along with assigned attributes.
633
+             *
634
+             *	This method does a lot of work. It rejects some very malformed things
635
+             *	like <:::>. It returns an empty string if the element isn't allowed (look
636
+             *	ma, no strip_tags()!). Otherwise it splits the tag into an element and an
637
+             *	allowed attribute list.
638
+             *
639
+             *	@access private
640
+             *	@param string $string
641
+             *	@return string Modified string minus disallowed/mangled (X)HTML and attributes
642
+             *	@since PHP4 OOP 0.0.1
643
+             */
644
+            function _split2($string)
645
+            {
646
+                $string = $this->_stripslashes($string);
647
+
648
+                if (substr($string, 0, 1) != '<')
649
+                {
650
+                    # It matched a ">" character
651
+                    return '&gt;';
652
+                }
653
+
654
+                if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
655
+                {
656
+                    # It's seriously malformed
657
+                    return '';
658
+                }
659
+
660
+                $slash    = trim($matches[1]);
661
+                $elem     = $matches[2];
662
+                $attrlist = $matches[3];
663
+
664
+                if (
665
+                    !isset($this->allowed_html[strtolower($elem)]) ||
666
+                    !is_array($this->allowed_html[strtolower($elem)])
667
+                )
668
+                {
669
+                    # They are using a not allowed HTML element
670
+                    return '';
671
+                }
672
+
673
+                if ($slash != '')
674
+                {
675
+                    return "<$slash$elem>";
676
+                }
677
+                # No attributes are allowed for closing elements
678
+
679
+                return $this->_attr("$slash$elem", $attrlist);
680
+            }
681
+
682
+            /**
683
+             *	This method strips out disallowed attributes for (X)HTML tags.
684
+             *
685
+             *	This method removes all attributes if none are allowed for this element.
686
+             *	If some are allowed it calls $this->_hair() to split them further, and then it
687
+             *	builds up new HTML code from the data that $this->_hair() returns. It also
688
+             *	removes "<" and ">" characters, if there are any left. One more thing it
689
+             *	does is to check if the tag has a closing XHTML slash, and if it does,
690
+             *	it puts one in the returned code as well.
691
+             *
692
+             *	@access private
693
+             *	@param string $element (X)HTML tag to check
694
+             *	@param string $attr Text containing attributes to check for validity.
695
+             *	@return string Resulting valid (X)HTML or ''
696
+             *	@see _hair()
697
+             *	@since PHP4 OOP 0.0.1
698
+             */
699
+            function _attr($element, $attr)
700
+            {
701
+                # Is there a closing XHTML slash at the end of the attributes?
702
+                $xhtml_slash = '';
703
+                if (preg_match('%\s/\s*$%', $attr))
704
+                {
705
+                    $xhtml_slash = ' /';
706
+                }
707
+
708
+                # Are any attributes allowed at all for this element?
709
+                if (
710
+                    !isset($this->allowed_html[strtolower($element)]) ||
711
+                    count($this->allowed_html[strtolower($element)]) == 0
712
+                )
713
+                {
714
+                    return "<$element$xhtml_slash>";
715
+                }
716
+
717
+                # Split it
718
+                $attrarr = $this->_hair($attr);
719
+
720
+                # Go through $attrarr, and save the allowed attributes for this element
721
+                # in $attr2
722
+                $attr2 = '';
723
+                if(is_array($attrarr) && count($attrarr) > 0)
724
+                {
725
+                    foreach ($attrarr as $arreach)
726
+                    {
727
+                        if(!isset($this->allowed_html[strtolower($element)][strtolower($arreach['name'])]))
728
+                        {
729
+                            continue;
730
+                        }
731
+
732
+                        $current = $this->allowed_html[strtolower($element)][strtolower($arreach['name'])];
733
+                        if ($current == '')
734
+                        {
735
+                            # the attribute is not allowed
736
+                            continue;
737
+                        }
738
+
739
+                        if (!is_array($current))
740
+                        {
741
+                            # there are no checks
742
+                            $attr2 .= ' '.$arreach['whole'];
743
+                        }
744
+                        else
745
+                        {
746
+                            # there are some checks
747
+                            $ok = true;
748
+                            if(is_array($current) && count($current) > 0)
749
+                            {
750
+                                foreach ($current as $currkey => $currval)
751
+                                {
752
+                                    if (!$this->_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval))
753
+                                    {
754
+                                        $ok = false;
755
+                                        break;
756
+                                    }
757
+                                }
758
+
759
+                                if ($ok)
760
+                                {
761
+                                    # it passed them
762
+                                    $attr2 .= ' '.$arreach['whole'];
763
+                                }
764
+                            }
765
+                        }
766
+                    }
767
+                }
768
+
769
+                # Remove any "<" or ">" characters
770
+                $attr2 = preg_replace('/[<>]/', '', $attr2);
771
+                return "<$element$attr2$xhtml_slash>";
772
+            }
773
+
774
+            /**
775
+             *	This method combs through an attribute list string and returns an associative array of attributes and values.
776
+             *
777
+             *	This method does a lot of work. It parses an attribute list into an array
778
+             *	with attribute data, and tries to do the right thing even if it gets weird
779
+             *	input. It will add quotes around attribute values that don't have any quotes
780
+             *	or apostrophes around them, to make it easier to produce HTML code that will
781
+             *	conform to W3C's HTML specification. It will also remove bad URL protocols
782
+             *	from attribute values.
783
+             *
784
+             *	@access private
785
+             *	@param string $attr Text containing tag attributes for parsing
786
+             *	@return array Associative array containing data on attribute and value
787
+             *	@since PHP4 OOP 0.0.1
788
+             */
789
+            function _hair($attr)
790
+            {
791
+                $attrarr  = array();
792
+                $mode     = 0;
793
+                $attrname = '';
794
+
795
+                # Loop through the whole attribute list
796
+
797
+                while (strlen($attr) != 0)
798
+                {
799
+                    # Was the last operation successful?
800
+                    $working = 0;
801
+
802
+                    switch ($mode)
803
+                    {
804
+                        case 0:	# attribute name, href for instance
805
+                            if (preg_match('/^([-a-zA-Z]+)/', $attr, $match))
806
+                            {
807
+                                $attrname = $match[1];
808
+                                $working = $mode = 1;
809
+                                $attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
810
+                            }
811
+                            break;
812
+                        case 1:	# equals sign or valueless ("selected")
813
+                            if (preg_match('/^\s*=\s*/', $attr)) # equals sign
814
+                            {
815
+                                $working = 1;
816
+                                $mode    = 2;
817
+                                $attr    = preg_replace('/^\s*=\s*/', '', $attr);
818
+                                break;
819
+                            }
820
+                            if (preg_match('/^\s+/', $attr)) # valueless
821
+                            {
822
+                                $working   = 1;
823
+                                $mode      = 0;
824
+                                $attrarr[] = array(
825
+                                    'name'  => $attrname,
826
+                                    'value' => '',
827
+                                    'whole' => $attrname,
828
+                                    'vless' => 'y'
829
+                                );
830
+                                $attr      = preg_replace('/^\s+/', '', $attr);
831
+                            }
832
+                            break;
833
+                        case 2: # attribute value, a URL after href= for instance
834
+                            if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match)) # "value"
835
+                            {
836
+                                $thisval   = $this->_bad_protocol($match[1]);
837
+                                $attrarr[] = array(
838
+                                    'name'  => $attrname,
839
+                                    'value' => $thisval,
840
+                                    'whole' => "$attrname=\"$thisval\"",
841
+                                    'vless' => 'n'
842
+                                );
843
+                                $working   = 1;
844
+                                $mode      = 0;
845
+                                $attr      = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
846
+                                break;
847
+                            }
848
+                            if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match)) # 'value'
849
+                            {
850
+                                $thisval   = $this->_bad_protocol($match[1]);
851
+                                $attrarr[] = array(
852
+                                    'name'  => $attrname,
853
+                                    'value' => $thisval,
854
+                                    'whole' => "$attrname='$thisval'",
855
+                                    'vless' => 'n'
856
+                                );
857
+                                $working   = 1;
858
+                                $mode      = 0;
859
+                                $attr      = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
860
+                                break;
861
+                            }
862
+                            if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match)) # value
863
+                            {
864
+                                $thisval   = $this->_bad_protocol($match[1]);
865
+                                $attrarr[] = array(
866
+                                    'name'  => $attrname,
867
+                                    'value' => $thisval,
868
+                                    'whole' => "$attrname=\"$thisval\"",
869
+                                    'vless' => 'n'
870
+                                );
871
+                                # We add quotes to conform to W3C's HTML spec.
872
+                                $working   = 1;
873
+                                $mode      = 0;
874
+                                $attr      = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
875
+                            }
876
+                            break;
877
+                    }
878
+
879
+                    if ($working == 0) # not well formed, remove and try again
880
+                    {
881
+                        $attr = $this->_html_error($attr);
882
+                        $mode = 0;
883
+                    }
884
+                }
885
+
886
+                # special case, for when the attribute list ends with a valueless
887
+                # attribute like "selected"
888
+                if ($mode == 1)
889
+                {
890
+                    $attrarr[] = array(
891
+                        'name'  => $attrname,
892
+                        'value' => '',
893
+                        'whole' => $attrname,
894
+                        'vless' => 'y'
895
+                    );
896
+                }
897
+
898
+                return $attrarr;
899
+            }
900
+
901
+            /**
902
+             *	This method removes disallowed protocols.
903
+             *
904
+             *	This method removes all non-allowed protocols from the beginning of
905
+             *	$string. It ignores whitespace and the case of the letters, and it does
906
+             *	understand HTML entities. It does its work in a while loop, so it won't be
907
+             *	fooled by a string like "javascript:javascript:alert(57)".
908
+             *
909
+             *	@access private
910
+             *	@param string $string String to check for protocols
911
+             *	@return string String with removed protocols
912
+             *	@since PHP4 OOP 0.0.1
913
+             */
914
+            function _bad_protocol($string)
915
+            {
916
+                $string  = $this->_no_null($string);
917
+                $string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature"
918
+                $string2 = $string.'a';
919
+
920
+                while ($string != $string2)
921
+                {
922
+                    $string2 = $string;
923
+                    $string  = $this->_bad_protocol_once($string);
924
+                } # while
925
+
926
+                return $string;
927
+            }
928
+
929
+            /**
930
+             *	Helper method used by _bad_protocol()
931
+             *
932
+             *	This function searches for URL protocols at the beginning of $string, while
933
+             *	handling whitespace and HTML entities.
934
+             *  Function updated to fix security vulnerability (see http://projects.dokeos.com/index.php?do=details&task_id=2312)
935
+             *
936
+             *	@access private
937
+             *	@param string $string String to check for protocols
938
+             *	@return string String with removed protocols
939
+             *	@see _bad_protocol()
940
+             *	@since PHP4 OOP 0.0.1
941
+             */
942
+            function _bad_protocol_once($string)
943
+            {
944
+                $string2 = preg_split('/:|&#58;|&#x3a;/i', $string, 2);
945
+                if(isset($string2[1]) && !preg_match('%/\?%',$string2[0]))
946
+                {
947
+                    $string = $this->_bad_protocol_once2($string2[0]).trim($string2[1]);
948
+                }
949
+                return $string;
950
+            }
951
+            /**
952
+             *	Helper method used by _bad_protocol_once() regex
953
+             *
954
+             *	This function processes URL protocols, checks to see if they're in the white-
955
+             *	list or not, and returns different data depending on the answer.
956
+             *
957
+             *	@access private
958
+             *	@param string $string String to check for protocols
959
+             *	@return string String with removed protocols
960
+             *	@see _bad_protocol()
961
+             *	@see _bad_protocol_once()
962
+             *	@since PHP4 OOP 0.0.1
963
+             */
964
+            function _bad_protocol_once2($string)
965
+            {
966
+                $string = $this->_decode_entities($string);
967
+                $string = preg_replace('/\s/', '', $string);
968
+                $string = $this->_no_null($string);
969
+                $string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature"
970
+                $string = strtolower($string);
971
+
972
+                $allowed = false;
973
+                if(is_array($this->allowed_protocols) && count($this->allowed_protocols) > 0)
974
+                {
975
+                    foreach ($this->allowed_protocols as $one_protocol)
976
+                    {
977
+                        if (strtolower($one_protocol) == $string)
978
+                        {
979
+                            $allowed = true;
980
+                            break;
981
+                        }
982
+                    }
983
+                }
984
+
985
+                if ($allowed)
986
+                {
987
+                    return "$string:";
988
+                }
989
+                else
990
+                {
991
+                    return '';
992
+                }
993
+            }
994
+
995
+            /**
996
+             *	This function performs different checks for attribute values.
997
+             *
998
+             *	The currently implemented checks are "maxlen", "minlen", "maxval",
999
+             *	"minval" and "valueless" with even more checks to come soon.
1000
+             *
1001
+             *	@access private
1002
+             *	@param string $value The value of the attribute to be checked.
1003
+             *	@param string $vless Indicates whether the the value is supposed to be valueless
1004
+             *	@param string $checkname The check to be performed
1005
+             *	@param string $checkvalue The value that is to be checked against
1006
+             *	@return bool Indicates whether the check passed or not
1007
+             *	@since PHP4 OOP 0.0.1
1008
+             */
1009
+            function _check_attr_val($value, $vless, $checkname, $checkvalue)
1010
+            {
1011
+                $ok = true;
1012
+
1013
+                switch (strtolower($checkname))
1014
+                {
1015
+                    /**
1016
+                     *	The maxlen check makes sure that the attribute value has a length not
1017
+                     *	greater than the given value. This can be used to avoid Buffer Overflows
1018
+                     *	in WWW clients and various Internet servers.
1019
+                     */
1020
+                    case 'maxlen':
1021
+                        if (strlen($value) > $checkvalue)
1022
+                        {
1023
+                            $ok = false;
1024
+                        }
1025
+                        break;
1026
+
1027
+                    /**
1028
+                     *	The minlen check makes sure that the attribute value has a length not
1029
+                     *	smaller than the given value.
1030
+                     */
1031
+                    case 'minlen':
1032
+                        if (strlen($value) < $checkvalue)
1033
+                        {
1034
+                            $ok = false;
1035
+                        }
1036
+                        break;
1037
+
1038
+                    /**
1039
+                     *	The maxval check does two things: it checks that the attribute value is
1040
+                     *	an integer from 0 and up, without an excessive amount of zeroes or
1041
+                     *	whitespace (to avoid Buffer Overflows). It also checks that the attribute
1042
+                     *	value is not greater than the given value.
1043
+                     *	This check can be used to avoid Denial of Service attacks.
1044
+                     */
1045
+                    case 'maxval':
1046
+                        if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
1047
+                        {
1048
+                            $ok = false;
1049
+                        }
1050
+                        if ($value > $checkvalue)
1051
+                        {
1052
+                            $ok = false;
1053
+                        }
1054
+                        break;
1055
+
1056
+                    /**
1057
+                     *	The minval check checks that the attribute value is a positive integer,
1058
+                     *	and that it is not smaller than the given value.
1059
+                     */
1060
+                    case 'minval':
1061
+                        if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
1062
+                        {
1063
+                            $ok = false;
1064
+                        }
1065
+                        if ($value < $checkvalue)
1066
+                        {
1067
+                            $ok = false;
1068
+                        }
1069
+                        break;
1070
+
1071
+                    /**
1072
+                     *	The valueless check checks if the attribute has a value
1073
+                     *	(like <a href="blah">) or not (<option selected>). If the given value
1074
+                     *	is a "y" or a "Y", the attribute must not have a value.
1075
+                     *	If the given value is an "n" or an "N", the attribute must have one.
1076
+                     */
1077
+                    case 'valueless':
1078
+                    if (strtolower($checkvalue) != $vless)
1079
+                    {
1080
+                        $ok = false;
1081
+                    }
1082
+                    break;
1083
+
1084
+                }
1085
+
1086
+                return $ok;
1087
+            }
1088
+
1089
+            /**
1090
+             *	Changes \" to "
1091
+             *
1092
+             *	This function changes the character sequence  \"  to just  "
1093
+             *	It leaves all other slashes alone. It's really weird, but the quoting from
1094
+             *	preg_replace(//e) seems to require this.
1095
+             *
1096
+             *	@access private
1097
+             *	@param string $string The string to be stripped.
1098
+             *	@return string string stripped of \"
1099
+             *	@since PHP4 OOP 0.0.1
1100
+             */
1101
+            function _stripslashes($string)
1102
+            {
1103
+                return preg_replace('%\\\\"%', '"', $string);
1104
+            }
1105
+
1106
+            /**
1107
+             *	helper method for _hair()
1108
+             *
1109
+             *	This function deals with parsing errors in _hair(). The general plan is
1110
+             *	to remove everything to and including some whitespace, but it deals with
1111
+             *	quotes and apostrophes as well.
1112
+             *
1113
+             *	@access private
1114
+             *	@param string $string The string to be stripped.
1115
+             *	@return string string stripped of whitespace
1116
+             *	@see _hair()
1117
+             *	@since PHP4 OOP 0.0.1
1118
+             */
1119
+            function _html_error($string)
1120
+            {
1121
+                return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string);
1122
+            }
1123
+
1124
+            /**
1125
+             *	Decodes numeric HTML entities
1126
+             *
1127
+             *	This method decodes numeric HTML entities (&#65; and &#x41;). It doesn't
1128
+             *	do anything with other entities like &auml;, but we don't need them in the
1129
+             *	URL protocol white listing system anyway.
1130
+             *
1131
+             *	@access private
1132
+             *	@param string $value The entitiy to be decoded.
1133
+             *	@return string Decoded entity
1134
+             *	@since PHP4 OOP 0.0.1
1135
+             */
1136
+            function _decode_entities($string)
1137
+            {
1138
+                $string = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $string);
1139
+                $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', 'chr(hexdec("\\1"))', $string);
1140
+                return $string;
1141
+            }
1142
+
1143
+            /**
1144
+             *	Returns PHP4 OOP version # of kses.
1145
+             *
1146
+             *	Since this class has been refactored and documented and proven to work,
1147
+             *	I'm syncing the version number to procedural kses.
1148
+             *
1149
+             *	@access public
1150
+             *	@return string Version number
1151
+             *	@since PHP4 OOP 0.0.1
1152
+             */
1153
+            function _version()
1154
+            {
1155
+                return 'PHP4 0.2.2 (OOP fork of procedural kses 0.2.2)';
1156
+            }
1157
+        }
1158
+
1159
+
1160
+
1161
+    }
1162 1162
 ?>
1163 1163
\ No newline at end of file
Please login to merge, or discard this patch.
main/inc/lib/xajax/xajaxResponse.inc.php 1 patch
Indentation   +512 added lines, -512 removed lines patch added patch discarded remove patch
@@ -67,521 +67,521 @@
 block discarded – undo
67 67
  */
68 68
 class xajaxResponse
69 69
 {
70
-	/**#@+
70
+    /**#@+
71 71
 	 * @access protected
72 72
 	 */
73
-	/**
74
-	 * @var string internal XML storage
75
-	 */
76
-	var $xml;
77
-	/**
78
-	 * @var string the encoding type to use
79
-	 */
80
-	var $sEncoding;
81
-	/**
82
-	 * @var boolean if special characters in the XML should be converted to
83
-	 *              entities
84
-	 */
85
-	var $bOutputEntities;
86
-
87
-	/**#@-*/
88
-
89
-	/**
90
-	 * The constructor's main job is to set the character encoding for the
91
-	 * response.
92
-	 *
93
-	 * <i>Note:</i> to change the character encoding for all of the
94
-	 * responses, set the XAJAX_DEFAULT_ENCODING constant before you
95
-	 * instantiate xajax.
96
-	 *
97
-	 * @param string  contains the character encoding string to use
98
-	 * @param boolean lets you set if you want special characters in the output
99
-	 *                converted to HTML entities
100
-	 *
101
-	 */
102
-	function xajaxResponse($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities=false)
103
-	{
104
-		$this->setCharEncoding($sEncoding);
105
-		$this->bOutputEntities = $bOutputEntities;
106
-	}
107
-
108
-	/**
109
-	 * Sets the character encoding for the response based on $sEncoding, which
110
-	 * is a string containing the character encoding to use. You don't need to
111
-	 * use this method normally, since the character encoding for the response
112
-	 * gets set automatically based on the XAJAX_DEFAULT_CHAR_ENCODING
113
-	 * constant.
114
-	 *
115
-	 * @param string
116
-	 */
117
-	function setCharEncoding($sEncoding)
118
-	{
119
-		$this->sEncoding = $sEncoding;
120
-	}
121
-
122
-	/**
123
-	 * Tells the response object to convert special characters to HTML entities
124
-	 * automatically (only works if the mb_string extension is available).
125
-	 */
126
-	function outputEntitiesOn()
127
-	{
128
-		$this->bOutputEntities = true;
129
-	}
130
-
131
-	/**
132
-	 * Tells the response object to output special characters intact. (default
133
-	 * behavior)
134
-	 */
135
-	function outputEntitiesOff()
136
-	{
137
-		$this->bOutputEntities = false;
138
-	}
139
-
140
-	/**
141
-	 * Adds a confirm commands command message to the XML response.
142
-	 *
143
-	 * <i>Usage:</i> <kbd>$objResponse->addConfirmCommands(1, "Do you want to preview the new data?");</kbd>
144
-	 *
145
-	 * @param integer the number of commands to skip if the user presses
146
-	 *                Cancel in the browsers's confirm dialog
147
-	 * @param string  the message to show in the browser's confirm dialog
148
-	 */
149
-	function addConfirmCommands($iCmdNumber, $sMessage)
150
-	{
151
-		$this->xml .= $this->_cmdXML(array("n"=>"cc","t"=>$iCmdNumber),$sMessage);
152
-	}
153
-
154
-	/**
155
-	 * Adds an assign command message to the XML response.
156
-	 *
157
-	 * <i>Usage:</i> <kbd>$objResponse->addAssign("contentDiv", "innerHTML", "Some Text");</kbd>
158
-	 *
159
-	 * @param string contains the id of an HTML element
160
-	 * @param string the part of the element you wish to modify ("innerHTML",
161
-	 *               "value", etc.)
162
-	 * @param string the data you want to set the attribute to
163
-	 */
164
-	function addAssign($sTarget,$sAttribute,$sData)
165
-	{
166
-		$this->xml .= $this->_cmdXML(array("n"=>"as","t"=>$sTarget,"p"=>$sAttribute),$sData);
167
-	}
168
-
169
-	/**
170
-	 * Adds an append command message to the XML response.
171
-	 *
172
-	 * <i>Usage:</i> <kbd>$objResponse->addAppend("contentDiv", "innerHTML", "Some New Text");</kbd>
173
-	 *
174
-	 * @param string contains the id of an HTML element
175
-	 * @param string the part of the element you wish to modify ("innerHTML",
176
-	 *               "value", etc.)
177
-	 * @param string the data you want to append to the end of the attribute
178
-	 */
179
-	function addAppend($sTarget,$sAttribute,$sData)
180
-	{
181
-		$this->xml .= $this->_cmdXML(array("n"=>"ap","t"=>$sTarget,"p"=>$sAttribute),$sData);
182
-	}
183
-
184
-	/**
185
-	 * Adds an prepend command message to the XML response.
186
-	 *
187
-	 * <i>Usage:</i> <kbd>$objResponse->addPrepend("contentDiv", "innerHTML", "Some Starting Text");</kbd>
188
-	 *
189
-	 * @param string contains the id of an HTML element
190
-	 * @param string the part of the element you wish to modify ("innerHTML",
191
-	 *               "value", etc.)
192
-	 * @param string the data you want to prepend to the beginning of the
193
-	 *               attribute
194
-	 */
195
-	function addPrepend($sTarget,$sAttribute,$sData)
196
-	{
197
-		$this->xml .= $this->_cmdXML(array("n"=>"pp","t"=>$sTarget,"p"=>$sAttribute),$sData);
198
-	}
199
-
200
-	/**
201
-	 * Adds a replace command message to the XML response.
202
-	 *
203
-	 * <i>Usage:</i> <kbd>$objResponse->addReplace("contentDiv", "innerHTML", "text", "<b>text</b>");</kbd>
204
-	 *
205
-	 * @param string contains the id of an HTML element
206
-	 * @param string the part of the element you wish to modify ("innerHTML",
207
-	 *               "value", etc.)
208
-	 * @param string the string to search for
209
-	 * @param string the string to replace the search string when found in the
210
-	 *               attribute
211
-	 */
212
-	function addReplace($sTarget,$sAttribute,$sSearch,$sData)
213
-	{
214
-		$sDta = "<s><![CDATA[$sSearch]]></s><r><![CDATA[$sData]]></r>";
215
-		$this->xml .= $this->_cmdXML(array("n"=>"rp","t"=>$sTarget,"p"=>$sAttribute),$sDta);
216
-	}
217
-
218
-	/**
219
-	 * Adds a clear command message to the XML response.
220
-	 *
221
-	 * <i>Usage:</i> <kbd>$objResponse->addClear("contentDiv", "innerHTML");</kbd>
222
-	 *
223
-	 * @param string contains the id of an HTML element
224
-	 * @param string the part of the element you wish to clear ("innerHTML",
225
-	 *               "value", etc.)
226
-	 */
227
-	function addClear($sTarget,$sAttribute)
228
-	{
229
-		$this->addAssign($sTarget,$sAttribute,'');
230
-	}
231
-
232
-	/**
233
-	 * Adds an alert command message to the XML response.
234
-	 *
235
-	 * <i>Usage:</i> <kbd>$objResponse->addAlert("This is important information");</kbd>
236
-	 *
237
-	 * @param string the text to be displayed in the Javascript alert box
238
-	 */
239
-	function addAlert($sMsg)
240
-	{
241
-		$this->xml .= $this->_cmdXML(array("n"=>"al"),$sMsg);
242
-	}
243
-
244
-	/**
245
-	 * Uses the addScript() method to add a Javascript redirect to another URL.
246
-	 *
247
-	 * <i>Usage:</i> <kbd>$objResponse->addRedirect("http://www.xajaxproject.org");</kbd>
248
-	 *
249
-	 * @param string the URL to redirect the client browser to
250
-	 */
251
-	function addRedirect($sURL)
252
-	{
253
-		//we need to parse the query part so that the values are rawurlencode()'ed
254
-		//can't just use parse_url() cos we could be dealing with a relative URL which
255
-		//  parse_url() can't deal with.
256
-		$queryStart = strpos($sURL, '?', strrpos($sURL, '/'));
257
-		if ($queryStart !== FALSE)
258
-		{
259
-			$queryStart++;
260
-			$queryEnd = strpos($sURL, '#', $queryStart);
261
-			if ($queryEnd === FALSE)
262
-				$queryEnd = strlen($sURL);
263
-			$queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart);
73
+    /**
74
+     * @var string internal XML storage
75
+     */
76
+    var $xml;
77
+    /**
78
+     * @var string the encoding type to use
79
+     */
80
+    var $sEncoding;
81
+    /**
82
+     * @var boolean if special characters in the XML should be converted to
83
+     *              entities
84
+     */
85
+    var $bOutputEntities;
86
+
87
+    /**#@-*/
88
+
89
+    /**
90
+     * The constructor's main job is to set the character encoding for the
91
+     * response.
92
+     *
93
+     * <i>Note:</i> to change the character encoding for all of the
94
+     * responses, set the XAJAX_DEFAULT_ENCODING constant before you
95
+     * instantiate xajax.
96
+     *
97
+     * @param string  contains the character encoding string to use
98
+     * @param boolean lets you set if you want special characters in the output
99
+     *                converted to HTML entities
100
+     *
101
+     */
102
+    function xajaxResponse($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities=false)
103
+    {
104
+        $this->setCharEncoding($sEncoding);
105
+        $this->bOutputEntities = $bOutputEntities;
106
+    }
107
+
108
+    /**
109
+     * Sets the character encoding for the response based on $sEncoding, which
110
+     * is a string containing the character encoding to use. You don't need to
111
+     * use this method normally, since the character encoding for the response
112
+     * gets set automatically based on the XAJAX_DEFAULT_CHAR_ENCODING
113
+     * constant.
114
+     *
115
+     * @param string
116
+     */
117
+    function setCharEncoding($sEncoding)
118
+    {
119
+        $this->sEncoding = $sEncoding;
120
+    }
121
+
122
+    /**
123
+     * Tells the response object to convert special characters to HTML entities
124
+     * automatically (only works if the mb_string extension is available).
125
+     */
126
+    function outputEntitiesOn()
127
+    {
128
+        $this->bOutputEntities = true;
129
+    }
130
+
131
+    /**
132
+     * Tells the response object to output special characters intact. (default
133
+     * behavior)
134
+     */
135
+    function outputEntitiesOff()
136
+    {
137
+        $this->bOutputEntities = false;
138
+    }
139
+
140
+    /**
141
+     * Adds a confirm commands command message to the XML response.
142
+     *
143
+     * <i>Usage:</i> <kbd>$objResponse->addConfirmCommands(1, "Do you want to preview the new data?");</kbd>
144
+     *
145
+     * @param integer the number of commands to skip if the user presses
146
+     *                Cancel in the browsers's confirm dialog
147
+     * @param string  the message to show in the browser's confirm dialog
148
+     */
149
+    function addConfirmCommands($iCmdNumber, $sMessage)
150
+    {
151
+        $this->xml .= $this->_cmdXML(array("n"=>"cc","t"=>$iCmdNumber),$sMessage);
152
+    }
153
+
154
+    /**
155
+     * Adds an assign command message to the XML response.
156
+     *
157
+     * <i>Usage:</i> <kbd>$objResponse->addAssign("contentDiv", "innerHTML", "Some Text");</kbd>
158
+     *
159
+     * @param string contains the id of an HTML element
160
+     * @param string the part of the element you wish to modify ("innerHTML",
161
+     *               "value", etc.)
162
+     * @param string the data you want to set the attribute to
163
+     */
164
+    function addAssign($sTarget,$sAttribute,$sData)
165
+    {
166
+        $this->xml .= $this->_cmdXML(array("n"=>"as","t"=>$sTarget,"p"=>$sAttribute),$sData);
167
+    }
168
+
169
+    /**
170
+     * Adds an append command message to the XML response.
171
+     *
172
+     * <i>Usage:</i> <kbd>$objResponse->addAppend("contentDiv", "innerHTML", "Some New Text");</kbd>
173
+     *
174
+     * @param string contains the id of an HTML element
175
+     * @param string the part of the element you wish to modify ("innerHTML",
176
+     *               "value", etc.)
177
+     * @param string the data you want to append to the end of the attribute
178
+     */
179
+    function addAppend($sTarget,$sAttribute,$sData)
180
+    {
181
+        $this->xml .= $this->_cmdXML(array("n"=>"ap","t"=>$sTarget,"p"=>$sAttribute),$sData);
182
+    }
183
+
184
+    /**
185
+     * Adds an prepend command message to the XML response.
186
+     *
187
+     * <i>Usage:</i> <kbd>$objResponse->addPrepend("contentDiv", "innerHTML", "Some Starting Text");</kbd>
188
+     *
189
+     * @param string contains the id of an HTML element
190
+     * @param string the part of the element you wish to modify ("innerHTML",
191
+     *               "value", etc.)
192
+     * @param string the data you want to prepend to the beginning of the
193
+     *               attribute
194
+     */
195
+    function addPrepend($sTarget,$sAttribute,$sData)
196
+    {
197
+        $this->xml .= $this->_cmdXML(array("n"=>"pp","t"=>$sTarget,"p"=>$sAttribute),$sData);
198
+    }
199
+
200
+    /**
201
+     * Adds a replace command message to the XML response.
202
+     *
203
+     * <i>Usage:</i> <kbd>$objResponse->addReplace("contentDiv", "innerHTML", "text", "<b>text</b>");</kbd>
204
+     *
205
+     * @param string contains the id of an HTML element
206
+     * @param string the part of the element you wish to modify ("innerHTML",
207
+     *               "value", etc.)
208
+     * @param string the string to search for
209
+     * @param string the string to replace the search string when found in the
210
+     *               attribute
211
+     */
212
+    function addReplace($sTarget,$sAttribute,$sSearch,$sData)
213
+    {
214
+        $sDta = "<s><![CDATA[$sSearch]]></s><r><![CDATA[$sData]]></r>";
215
+        $this->xml .= $this->_cmdXML(array("n"=>"rp","t"=>$sTarget,"p"=>$sAttribute),$sDta);
216
+    }
217
+
218
+    /**
219
+     * Adds a clear command message to the XML response.
220
+     *
221
+     * <i>Usage:</i> <kbd>$objResponse->addClear("contentDiv", "innerHTML");</kbd>
222
+     *
223
+     * @param string contains the id of an HTML element
224
+     * @param string the part of the element you wish to clear ("innerHTML",
225
+     *               "value", etc.)
226
+     */
227
+    function addClear($sTarget,$sAttribute)
228
+    {
229
+        $this->addAssign($sTarget,$sAttribute,'');
230
+    }
231
+
232
+    /**
233
+     * Adds an alert command message to the XML response.
234
+     *
235
+     * <i>Usage:</i> <kbd>$objResponse->addAlert("This is important information");</kbd>
236
+     *
237
+     * @param string the text to be displayed in the Javascript alert box
238
+     */
239
+    function addAlert($sMsg)
240
+    {
241
+        $this->xml .= $this->_cmdXML(array("n"=>"al"),$sMsg);
242
+    }
243
+
244
+    /**
245
+     * Uses the addScript() method to add a Javascript redirect to another URL.
246
+     *
247
+     * <i>Usage:</i> <kbd>$objResponse->addRedirect("http://www.xajaxproject.org");</kbd>
248
+     *
249
+     * @param string the URL to redirect the client browser to
250
+     */
251
+    function addRedirect($sURL)
252
+    {
253
+        //we need to parse the query part so that the values are rawurlencode()'ed
254
+        //can't just use parse_url() cos we could be dealing with a relative URL which
255
+        //  parse_url() can't deal with.
256
+        $queryStart = strpos($sURL, '?', strrpos($sURL, '/'));
257
+        if ($queryStart !== FALSE)
258
+        {
259
+            $queryStart++;
260
+            $queryEnd = strpos($sURL, '#', $queryStart);
261
+            if ($queryEnd === FALSE)
262
+                $queryEnd = strlen($sURL);
263
+            $queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart);
264 264
             $queryParts = array();
265
-			parse_str($queryPart, $queryParts);
266
-			$newQueryPart = "";
267
-			foreach($queryParts as $key => $value)
268
-			{
269
-				$newQueryPart .= rawurlencode($key).'='.rawurlencode($value).ini_get('arg_separator.output');
270
-			}
271
-			$sURL = str_replace($queryPart, $newQueryPart, $sURL);
272
-		}
273
-		$this->addScript('window.location = "'.$sURL.'";');
274
-	}
275
-
276
-	/**
277
-	 * Adds a Javascript command message to the XML response.
278
-	 *
279
-	 * <i>Usage:</i> <kbd>$objResponse->addScript("var x = prompt('get some text');");</kbd>
280
-	 *
281
-	 * @param string contains Javascript code to be executed
282
-	 */
283
-	function addScript($sJS)
284
-	{
285
-		$this->xml .= $this->_cmdXML(array("n"=>"js"),$sJS);
286
-	}
287
-
288
-	/**
289
-	 * Adds a Javascript function call command message to the XML response.
290
-	 *
291
-	 * <i>Usage:</i> <kbd>$objResponse->addScriptCall("myJSFunction", "arg 1", "arg 2", 12345);</kbd>
292
-	 *
293
-	 * @param string $sFunc the name of a Javascript function
294
-	 * @param mixed $args,... optional arguments to pass to the Javascript function
295
-	 */
296
-	function addScriptCall() {
297
-		$arguments = func_get_args();
298
-		$sFunc = array_shift($arguments);
299
-		$sData = $this->_buildObjXml($arguments);
300
-		$this->xml .= $this->_cmdXML(array("n"=>"jc","t"=>$sFunc),$sData);
301
-	}
302
-
303
-	/**
304
-	 * Adds a remove element command message to the XML response.
305
-	 *
306
-	 * <i>Usage:</i> <kbd>$objResponse->addRemove("Div2");</kbd>
307
-	 *
308
-	 * @param string contains the id of an HTML element to be removed
309
-	 */
310
-	function addRemove($sTarget)
311
-	{
312
-		$this->xml .= $this->_cmdXML(array("n"=>"rm","t"=>$sTarget),'');
313
-	}
314
-
315
-	/**
316
-	 * Adds a create element command message to the XML response.
317
-	 *
318
-	 * <i>Usage:</i> <kbd>$objResponse->addCreate("parentDiv", "h3", "myid");</kbd>
319
-	 *
320
-	 * @param string contains the id of an HTML element to to which the new
321
-	 *               element will be appended.
322
-	 * @param string the tag to be added
323
-	 * @param string the id to be assigned to the new element
324
-	 * @param string deprecated, use the addCreateInput() method instead
325
-	 */
326
-	function addCreate($sParent, $sTag, $sId, $sType="")
327
-	{
328
-		if ($sType)
329
-		{
330
-			trigger_error("The \$sType parameter of addCreate has been deprecated.  Use the addCreateInput() method instead.", E_USER_WARNING);
331
-			return;
332
-		}
333
-		$this->xml .= $this->_cmdXML(array("n"=>"ce","t"=>$sParent,"p"=>$sId),$sTag);
334
-	}
335
-
336
-	/**
337
-	 * Adds a insert element command message to the XML response.
338
-	 *
339
-	 * <i>Usage:</i> <kbd>$objResponse->addInsert("childDiv", "h3", "myid");</kbd>
340
-	 *
341
-	 * @param string contains the id of the child before which the new element
342
-	 *               will be inserted
343
-	 * @param string the tag to be added
344
-	 * @param string the id to be assigned to the new element
345
-	 */
346
-	function addInsert($sBefore, $sTag, $sId)
347
-	{
348
-		$this->xml .= $this->_cmdXML(array("n"=>"ie","t"=>$sBefore,"p"=>$sId),$sTag);
349
-	}
350
-
351
-	/**
352
-	 * Adds a insert element command message to the XML response.
353
-	 *
354
-	 * <i>Usage:</i> <kbd>$objResponse->addInsertAfter("childDiv", "h3", "myid");</kbd>
355
-	 *
356
-	 * @param string contains the id of the child after which the new element
357
-	 *               will be inserted
358
-	 * @param string the tag to be added
359
-	 * @param string the id to be assigned to the new element
360
-	 */
361
-	function addInsertAfter($sAfter, $sTag, $sId)
362
-	{
363
-		$this->xml .= $this->_cmdXML(array("n"=>"ia","t"=>$sAfter,"p"=>$sId),$sTag);
364
-	}
365
-
366
-	/**
367
-	 * Adds a create input command message to the XML response.
368
-	 *
369
-	 * <i>Usage:</i> <kbd>$objResponse->addCreateInput("form1", "text", "username", "input1");</kbd>
370
-	 *
371
-	 * @param string contains the id of an HTML element to which the new input
372
-	 *               will be appended
373
-	 * @param string the type of input to be created (text, radio, checkbox,
374
-	 *               etc.)
375
-	 * @param string the name to be assigned to the new input and the variable
376
-	 *               name when it is submitted
377
-	 * @param string the id to be assigned to the new input
378
-	 */
379
-	function addCreateInput($sParent, $sType, $sName, $sId)
380
-	{
381
-		$this->xml .= $this->_cmdXML(array("n"=>"ci","t"=>$sParent,"p"=>$sId,"c"=>$sType),$sName);
382
-	}
383
-
384
-	/**
385
-	 * Adds an insert input command message to the XML response.
386
-	 *
387
-	 * <i>Usage:</i> <kbd>$objResponse->addInsertInput("input5", "text", "username", "input1");</kbd>
388
-	 *
389
-	 * @param string contains the id of the child before which the new element
390
-	 *               will be inserted
391
-	 * @param string the type of input to be created (text, radio, checkbox,
392
-	 *               etc.)
393
-	 * @param string the name to be assigned to the new input and the variable
394
-	 *               name when it is submitted
395
-	 * @param string the id to be assigned to the new input
396
-	 */
397
-	function addInsertInput($sBefore, $sType, $sName, $sId)
398
-	{
399
-		$this->xml .= $this->_cmdXML(array("n"=>"ii","t"=>$sBefore,"p"=>$sId,"c"=>$sType),$sName);
400
-	}
401
-
402
-	/**
403
-	 * Adds an insert input command message to the XML response.
404
-	 *
405
-	 * <i>Usage:</i> <kbd>$objResponse->addInsertInputAfter("input7", "text", "email", "input2");</kbd>
406
-	 *
407
-	 * @param string contains the id of the child after which the new element
408
-	 *               will be inserted
409
-	 * @param string the type of input to be created (text, radio, checkbox,
410
-	 *               etc.)
411
-	 * @param string the name to be assigned to the new input and the variable
412
-	 *               name when it is submitted
413
-	 * @param string the id to be assigned to the new input
414
-	 */
415
-	function addInsertInputAfter($sAfter, $sType, $sName, $sId)
416
-	{
417
-		$this->xml .= $this->_cmdXML(array("n"=>"iia","t"=>$sAfter,"p"=>$sId,"c"=>$sType),$sName);
418
-	}
419
-
420
-	/**
421
-	 * Adds an event command message to the XML response.
422
-	 *
423
-	 * <i>Usage:</i> <kbd>$objResponse->addEvent("contentDiv", "onclick", "alert(\'Hello World\');");</kbd>
424
-	 *
425
-	 * @param string contains the id of an HTML element
426
-	 * @param string the event you wish to set ("onclick", "onmouseover", etc.)
427
-	 * @param string the Javascript string you want the event to invoke
428
-	 */
429
-	function addEvent($sTarget,$sEvent,$sScript)
430
-	{
431
-		$this->xml .= $this->_cmdXML(array("n"=>"ev","t"=>$sTarget,"p"=>$sEvent),$sScript);
432
-	}
433
-
434
-	/**
435
-	 * Adds a handler command message to the XML response.
436
-	 *
437
-	 * <i>Usage:</i> <kbd>$objResponse->addHandler("contentDiv", "onclick", "content_click");</kbd>
438
-	 *
439
-	 * @param string contains the id of an HTML element
440
-	 * @param string the event you wish to set ("onclick", "onmouseover", etc.)
441
-	 * @param string the name of a Javascript function that will handle the
442
-	 *               event. Multiple handlers can be added for the same event
443
-	 */
444
-	function addHandler($sTarget,$sEvent,$sHandler)
445
-	{
446
-		$this->xml .= $this->_cmdXML(array("n"=>"ah","t"=>$sTarget,"p"=>$sEvent),$sHandler);
447
-	}
448
-
449
-	/**
450
-	 * Adds a remove handler command message to the XML response.
451
-	 *
452
-	 * <i>Usage:</i> <kbd>$objResponse->addRemoveHandler("contentDiv", "onclick", "content_click");</kbd>
453
-	 *
454
-	 * @param string contains the id of an HTML element
455
-	 * @param string the event you wish to remove ("onclick", "onmouseover",
456
-	 *               etc.)
457
-	 * @param string the name of a Javascript handler function that you want to
458
-	 *               remove
459
-	 */
460
-	function addRemoveHandler($sTarget,$sEvent,$sHandler)
461
-	{
462
-		$this->xml .= $this->_cmdXML(array("n"=>"rh","t"=>$sTarget,"p"=>$sEvent),$sHandler);
463
-	}
464
-
465
-	/**
466
-	 * Adds an include script command message to the XML response.
467
-	 *
468
-	 * <i>Usage:</i> <kbd>$objResponse->addIncludeScript("functions.js");</kbd>
469
-	 *
470
-	 * @param string URL of the Javascript file to include
471
-	 */
472
-	function addIncludeScript($sFileName)
473
-	{
474
-		$this->xml .= $this->_cmdXML(array("n"=>"in"),$sFileName);
475
-	}
476
-
477
-	/**
478
-	 * Returns the XML to be returned from your function to the xajax processor
479
-	 * on your page. Since xajax 0.2, you can also return an xajaxResponse
480
-	 * object from your function directly, and xajax will automatically request
481
-	 * the XML using this method call.
482
-	 *
483
-	 * <i>Usage:</i> <kbd>return $objResponse->getXML();</kbd>
484
-	 *
485
-	 * @return string response XML data
486
-	 */
487
-	function getXML()
488
-	{
489
-		$sXML = "<?xml version=\"1.0\"";
490
-		if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0)
491
-			$sXML .= " encoding=\"".$this->sEncoding."\"";
492
-		$sXML .= " ?"."><xjx>" . $this->xml . "</xjx>";
493
-
494
-		return $sXML;
495
-	}
496
-
497
-	/**
498
-	 * Adds the commands of the provided response XML output to this response
499
-	 * object
500
-	 *
501
-	 * <i>Usage:</i>
502
-	 * <code>$r1 = $objResponse1->getXML();
503
-	 * $objResponse2->loadXML($r1);
504
-	 * return $objResponse2->getXML();</code>
505
-	 *
506
-	 * @param string the response XML (returned from a getXML() method) to add
507
-	 *               to the end of this response object
508
-	 */
509
-	function loadXML($mXML)
510
-	{
511
-		if (is_a($mXML, "xajaxResponse")) {
512
-			$mXML = $mXML->getXML();
513
-		}
514
-		$sNewXML = "";
515
-		$iStartPos = strpos($mXML, "<xjx>") + 5;
516
-		$sNewXML = substr($mXML, $iStartPos);
517
-		$iEndPos = strpos($sNewXML, "</xjx>");
518
-		$sNewXML = substr($sNewXML, 0, $iEndPos);
519
-		$this->xml .= $sNewXML;
520
-	}
521
-
522
-	/**
523
-	 * Generates XML from command data
524
-	 *
525
-	 * @access private
526
-	 * @param array associative array of attributes
527
-	 * @param string data
528
-	 * @return string XML command
529
-	 */
530
-	function _cmdXML($aAttributes, $sData)
531
-	{
532
-		if ($this->bOutputEntities) {
533
-			// An adaptation for the Dokeos LMS, 22-AUG-2009.
534
-			if (function_exists('api_convert_encoding')) {
535
-				$sData = call_user_func_array('api_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding));
536
-			}
537
-			//if (function_exists('mb_convert_encoding')) {
538
-			elseif (function_exists('mb_convert_encoding')) {
539
-			//
540
-				$sData = call_user_func_array('mb_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding));
541
-			}
542
-			else {
543
-				trigger_error("The xajax XML response output could not be converted to HTML entities because the mb_convert_encoding function is not available", E_USER_NOTICE);
544
-			}
545
-		}
546
-		$xml = "<cmd";
547
-		foreach($aAttributes as $sAttribute => $sValue)
548
-			$xml .= " $sAttribute=\"$sValue\"";
549
-		if ($sData !== null && !stristr($sData,'<![CDATA['))
550
-			$xml .= "><![CDATA[$sData]]></cmd>";
551
-		else if ($sData !== null)
552
-			$xml .= ">$sData</cmd>";
553
-		else
554
-			$xml .= "></cmd>";
555
-
556
-		return $xml;
557
-	}
558
-
559
-	/**
560
-	 * Recursively serializes a data structure in XML so it can be sent to
561
-	 * the client. It could be thought of as the opposite of
562
-	 * {@link xajax::_parseObjXml()}.
563
-	 *
564
-	 * @access private
565
-	 * @param mixed data structure to serialize to XML
566
-	 * @return string serialized XML
567
-	 */
568
-	function _buildObjXml($var) {
569
-		if (gettype($var) == "object") $var = get_object_vars($var);
570
-		if (!is_array($var)) {
571
-			return "<![CDATA[$var]]>";
572
-		}
573
-		else {
574
-			$data = "<xjxobj>";
575
-			foreach ($var as $key => $value) {
576
-				$data .= "<e>";
577
-				$data .= "<k>" . htmlspecialchars($key) . "</k>";
578
-				$data .= "<v>" . $this->_buildObjXml($value) . "</v>";
579
-				$data .= "</e>";
580
-			}
581
-			$data .= "</xjxobj>";
582
-			return $data;
583
-		}
584
-	}
265
+            parse_str($queryPart, $queryParts);
266
+            $newQueryPart = "";
267
+            foreach($queryParts as $key => $value)
268
+            {
269
+                $newQueryPart .= rawurlencode($key).'='.rawurlencode($value).ini_get('arg_separator.output');
270
+            }
271
+            $sURL = str_replace($queryPart, $newQueryPart, $sURL);
272
+        }
273
+        $this->addScript('window.location = "'.$sURL.'";');
274
+    }
275
+
276
+    /**
277
+     * Adds a Javascript command message to the XML response.
278
+     *
279
+     * <i>Usage:</i> <kbd>$objResponse->addScript("var x = prompt('get some text');");</kbd>
280
+     *
281
+     * @param string contains Javascript code to be executed
282
+     */
283
+    function addScript($sJS)
284
+    {
285
+        $this->xml .= $this->_cmdXML(array("n"=>"js"),$sJS);
286
+    }
287
+
288
+    /**
289
+     * Adds a Javascript function call command message to the XML response.
290
+     *
291
+     * <i>Usage:</i> <kbd>$objResponse->addScriptCall("myJSFunction", "arg 1", "arg 2", 12345);</kbd>
292
+     *
293
+     * @param string $sFunc the name of a Javascript function
294
+     * @param mixed $args,... optional arguments to pass to the Javascript function
295
+     */
296
+    function addScriptCall() {
297
+        $arguments = func_get_args();
298
+        $sFunc = array_shift($arguments);
299
+        $sData = $this->_buildObjXml($arguments);
300
+        $this->xml .= $this->_cmdXML(array("n"=>"jc","t"=>$sFunc),$sData);
301
+    }
302
+
303
+    /**
304
+     * Adds a remove element command message to the XML response.
305
+     *
306
+     * <i>Usage:</i> <kbd>$objResponse->addRemove("Div2");</kbd>
307
+     *
308
+     * @param string contains the id of an HTML element to be removed
309
+     */
310
+    function addRemove($sTarget)
311
+    {
312
+        $this->xml .= $this->_cmdXML(array("n"=>"rm","t"=>$sTarget),'');
313
+    }
314
+
315
+    /**
316
+     * Adds a create element command message to the XML response.
317
+     *
318
+     * <i>Usage:</i> <kbd>$objResponse->addCreate("parentDiv", "h3", "myid");</kbd>
319
+     *
320
+     * @param string contains the id of an HTML element to to which the new
321
+     *               element will be appended.
322
+     * @param string the tag to be added
323
+     * @param string the id to be assigned to the new element
324
+     * @param string deprecated, use the addCreateInput() method instead
325
+     */
326
+    function addCreate($sParent, $sTag, $sId, $sType="")
327
+    {
328
+        if ($sType)
329
+        {
330
+            trigger_error("The \$sType parameter of addCreate has been deprecated.  Use the addCreateInput() method instead.", E_USER_WARNING);
331
+            return;
332
+        }
333
+        $this->xml .= $this->_cmdXML(array("n"=>"ce","t"=>$sParent,"p"=>$sId),$sTag);
334
+    }
335
+
336
+    /**
337
+     * Adds a insert element command message to the XML response.
338
+     *
339
+     * <i>Usage:</i> <kbd>$objResponse->addInsert("childDiv", "h3", "myid");</kbd>
340
+     *
341
+     * @param string contains the id of the child before which the new element
342
+     *               will be inserted
343
+     * @param string the tag to be added
344
+     * @param string the id to be assigned to the new element
345
+     */
346
+    function addInsert($sBefore, $sTag, $sId)
347
+    {
348
+        $this->xml .= $this->_cmdXML(array("n"=>"ie","t"=>$sBefore,"p"=>$sId),$sTag);
349
+    }
350
+
351
+    /**
352
+     * Adds a insert element command message to the XML response.
353
+     *
354
+     * <i>Usage:</i> <kbd>$objResponse->addInsertAfter("childDiv", "h3", "myid");</kbd>
355
+     *
356
+     * @param string contains the id of the child after which the new element
357
+     *               will be inserted
358
+     * @param string the tag to be added
359
+     * @param string the id to be assigned to the new element
360
+     */
361
+    function addInsertAfter($sAfter, $sTag, $sId)
362
+    {
363
+        $this->xml .= $this->_cmdXML(array("n"=>"ia","t"=>$sAfter,"p"=>$sId),$sTag);
364
+    }
365
+
366
+    /**
367
+     * Adds a create input command message to the XML response.
368
+     *
369
+     * <i>Usage:</i> <kbd>$objResponse->addCreateInput("form1", "text", "username", "input1");</kbd>
370
+     *
371
+     * @param string contains the id of an HTML element to which the new input
372
+     *               will be appended
373
+     * @param string the type of input to be created (text, radio, checkbox,
374
+     *               etc.)
375
+     * @param string the name to be assigned to the new input and the variable
376
+     *               name when it is submitted
377
+     * @param string the id to be assigned to the new input
378
+     */
379
+    function addCreateInput($sParent, $sType, $sName, $sId)
380
+    {
381
+        $this->xml .= $this->_cmdXML(array("n"=>"ci","t"=>$sParent,"p"=>$sId,"c"=>$sType),$sName);
382
+    }
383
+
384
+    /**
385
+     * Adds an insert input command message to the XML response.
386
+     *
387
+     * <i>Usage:</i> <kbd>$objResponse->addInsertInput("input5", "text", "username", "input1");</kbd>
388
+     *
389
+     * @param string contains the id of the child before which the new element
390
+     *               will be inserted
391
+     * @param string the type of input to be created (text, radio, checkbox,
392
+     *               etc.)
393
+     * @param string the name to be assigned to the new input and the variable
394
+     *               name when it is submitted
395
+     * @param string the id to be assigned to the new input
396
+     */
397
+    function addInsertInput($sBefore, $sType, $sName, $sId)
398
+    {
399
+        $this->xml .= $this->_cmdXML(array("n"=>"ii","t"=>$sBefore,"p"=>$sId,"c"=>$sType),$sName);
400
+    }
401
+
402
+    /**
403
+     * Adds an insert input command message to the XML response.
404
+     *
405
+     * <i>Usage:</i> <kbd>$objResponse->addInsertInputAfter("input7", "text", "email", "input2");</kbd>
406
+     *
407
+     * @param string contains the id of the child after which the new element
408
+     *               will be inserted
409
+     * @param string the type of input to be created (text, radio, checkbox,
410
+     *               etc.)
411
+     * @param string the name to be assigned to the new input and the variable
412
+     *               name when it is submitted
413
+     * @param string the id to be assigned to the new input
414
+     */
415
+    function addInsertInputAfter($sAfter, $sType, $sName, $sId)
416
+    {
417
+        $this->xml .= $this->_cmdXML(array("n"=>"iia","t"=>$sAfter,"p"=>$sId,"c"=>$sType),$sName);
418
+    }
419
+
420
+    /**
421
+     * Adds an event command message to the XML response.
422
+     *
423
+     * <i>Usage:</i> <kbd>$objResponse->addEvent("contentDiv", "onclick", "alert(\'Hello World\');");</kbd>
424
+     *
425
+     * @param string contains the id of an HTML element
426
+     * @param string the event you wish to set ("onclick", "onmouseover", etc.)
427
+     * @param string the Javascript string you want the event to invoke
428
+     */
429
+    function addEvent($sTarget,$sEvent,$sScript)
430
+    {
431
+        $this->xml .= $this->_cmdXML(array("n"=>"ev","t"=>$sTarget,"p"=>$sEvent),$sScript);
432
+    }
433
+
434
+    /**
435
+     * Adds a handler command message to the XML response.
436
+     *
437
+     * <i>Usage:</i> <kbd>$objResponse->addHandler("contentDiv", "onclick", "content_click");</kbd>
438
+     *
439
+     * @param string contains the id of an HTML element
440
+     * @param string the event you wish to set ("onclick", "onmouseover", etc.)
441
+     * @param string the name of a Javascript function that will handle the
442
+     *               event. Multiple handlers can be added for the same event
443
+     */
444
+    function addHandler($sTarget,$sEvent,$sHandler)
445
+    {
446
+        $this->xml .= $this->_cmdXML(array("n"=>"ah","t"=>$sTarget,"p"=>$sEvent),$sHandler);
447
+    }
448
+
449
+    /**
450
+     * Adds a remove handler command message to the XML response.
451
+     *
452
+     * <i>Usage:</i> <kbd>$objResponse->addRemoveHandler("contentDiv", "onclick", "content_click");</kbd>
453
+     *
454
+     * @param string contains the id of an HTML element
455
+     * @param string the event you wish to remove ("onclick", "onmouseover",
456
+     *               etc.)
457
+     * @param string the name of a Javascript handler function that you want to
458
+     *               remove
459
+     */
460
+    function addRemoveHandler($sTarget,$sEvent,$sHandler)
461
+    {
462
+        $this->xml .= $this->_cmdXML(array("n"=>"rh","t"=>$sTarget,"p"=>$sEvent),$sHandler);
463
+    }
464
+
465
+    /**
466
+     * Adds an include script command message to the XML response.
467
+     *
468
+     * <i>Usage:</i> <kbd>$objResponse->addIncludeScript("functions.js");</kbd>
469
+     *
470
+     * @param string URL of the Javascript file to include
471
+     */
472
+    function addIncludeScript($sFileName)
473
+    {
474
+        $this->xml .= $this->_cmdXML(array("n"=>"in"),$sFileName);
475
+    }
476
+
477
+    /**
478
+     * Returns the XML to be returned from your function to the xajax processor
479
+     * on your page. Since xajax 0.2, you can also return an xajaxResponse
480
+     * object from your function directly, and xajax will automatically request
481
+     * the XML using this method call.
482
+     *
483
+     * <i>Usage:</i> <kbd>return $objResponse->getXML();</kbd>
484
+     *
485
+     * @return string response XML data
486
+     */
487
+    function getXML()
488
+    {
489
+        $sXML = "<?xml version=\"1.0\"";
490
+        if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0)
491
+            $sXML .= " encoding=\"".$this->sEncoding."\"";
492
+        $sXML .= " ?"."><xjx>" . $this->xml . "</xjx>";
493
+
494
+        return $sXML;
495
+    }
496
+
497
+    /**
498
+     * Adds the commands of the provided response XML output to this response
499
+     * object
500
+     *
501
+     * <i>Usage:</i>
502
+     * <code>$r1 = $objResponse1->getXML();
503
+     * $objResponse2->loadXML($r1);
504
+     * return $objResponse2->getXML();</code>
505
+     *
506
+     * @param string the response XML (returned from a getXML() method) to add
507
+     *               to the end of this response object
508
+     */
509
+    function loadXML($mXML)
510
+    {
511
+        if (is_a($mXML, "xajaxResponse")) {
512
+            $mXML = $mXML->getXML();
513
+        }
514
+        $sNewXML = "";
515
+        $iStartPos = strpos($mXML, "<xjx>") + 5;
516
+        $sNewXML = substr($mXML, $iStartPos);
517
+        $iEndPos = strpos($sNewXML, "</xjx>");
518
+        $sNewXML = substr($sNewXML, 0, $iEndPos);
519
+        $this->xml .= $sNewXML;
520
+    }
521
+
522
+    /**
523
+     * Generates XML from command data
524
+     *
525
+     * @access private
526
+     * @param array associative array of attributes
527
+     * @param string data
528
+     * @return string XML command
529
+     */
530
+    function _cmdXML($aAttributes, $sData)
531
+    {
532
+        if ($this->bOutputEntities) {
533
+            // An adaptation for the Dokeos LMS, 22-AUG-2009.
534
+            if (function_exists('api_convert_encoding')) {
535
+                $sData = call_user_func_array('api_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding));
536
+            }
537
+            //if (function_exists('mb_convert_encoding')) {
538
+            elseif (function_exists('mb_convert_encoding')) {
539
+            //
540
+                $sData = call_user_func_array('mb_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding));
541
+            }
542
+            else {
543
+                trigger_error("The xajax XML response output could not be converted to HTML entities because the mb_convert_encoding function is not available", E_USER_NOTICE);
544
+            }
545
+        }
546
+        $xml = "<cmd";
547
+        foreach($aAttributes as $sAttribute => $sValue)
548
+            $xml .= " $sAttribute=\"$sValue\"";
549
+        if ($sData !== null && !stristr($sData,'<![CDATA['))
550
+            $xml .= "><![CDATA[$sData]]></cmd>";
551
+        else if ($sData !== null)
552
+            $xml .= ">$sData</cmd>";
553
+        else
554
+            $xml .= "></cmd>";
555
+
556
+        return $xml;
557
+    }
558
+
559
+    /**
560
+     * Recursively serializes a data structure in XML so it can be sent to
561
+     * the client. It could be thought of as the opposite of
562
+     * {@link xajax::_parseObjXml()}.
563
+     *
564
+     * @access private
565
+     * @param mixed data structure to serialize to XML
566
+     * @return string serialized XML
567
+     */
568
+    function _buildObjXml($var) {
569
+        if (gettype($var) == "object") $var = get_object_vars($var);
570
+        if (!is_array($var)) {
571
+            return "<![CDATA[$var]]>";
572
+        }
573
+        else {
574
+            $data = "<xjxobj>";
575
+            foreach ($var as $key => $value) {
576
+                $data .= "<e>";
577
+                $data .= "<k>" . htmlspecialchars($key) . "</k>";
578
+                $data .= "<v>" . $this->_buildObjXml($value) . "</v>";
579
+                $data .= "</e>";
580
+            }
581
+            $data .= "</xjxobj>";
582
+            return $data;
583
+        }
584
+    }
585 585
 
586 586
 }// end class xajaxResponse
587 587
 ?>
Please login to merge, or discard this patch.
main/inc/lib/xajax/xajaxCompress.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -42,141 +42,141 @@
 block discarded – undo
42 42
  */
43 43
 function xajaxCompressJavascript($sJS)
44 44
 {
45
-	//remove windows cariage returns
46
-	$sJS = str_replace("\r","",$sJS);
47
-
48
-	//array to store replaced literal strings
49
-	$literal_strings = array();
50
-
51
-	//explode the string into lines
52
-	$lines = explode("\n",$sJS);
53
-	//loop through all the lines, building a new string at the same time as removing literal strings
54
-	$clean = "";
55
-	$inComment = false;
56
-	$literal = "";
57
-	$inQuote = false;
58
-	$escaped = false;
59
-	$quoteChar = "";
60
-
61
-	for($i=0;$i<count($lines);$i++)
62
-	{
63
-		$line = $lines[$i];
64
-		$inNormalComment = false;
65
-
66
-		//loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
67
-		for($j=0;$j<strlen($line);$j++)
68
-		{
69
-			$c = substr($line,$j,1);
70
-			$d = substr($line,$j,2);
71
-
72
-			//look for start of quote
73
-			if(!$inQuote && !$inComment)
74
-			{
75
-				//is this character a quote or a comment
76
-				if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
77
-				{
78
-					$inQuote = true;
79
-					$inComment = false;
80
-					$escaped = false;
81
-					$quoteChar = $c;
82
-					$literal = $c;
83
-				}
84
-				else if($d=="/*" && !$inNormalComment)
85
-				{
86
-					$inQuote = false;
87
-					$inComment = true;
88
-					$escaped = false;
89
-					$quoteChar = $d;
90
-					$literal = $d;
91
-					$j++;
92
-				}
93
-				else if($d=="//") //ignore string markers that are found inside comments
94
-				{
95
-					$inNormalComment = true;
96
-					$clean .= $c;
97
-				}
98
-				else
99
-				{
100
-					$clean .= $c;
101
-				}
102
-			}
103
-			else //allready in a string so find end quote
104
-			{
105
-				if($c == $quoteChar && !$escaped && !$inComment)
106
-				{
107
-					$inQuote = false;
108
-					$literal .= $c;
109
-
110
-					//subsitute in a marker for the string
111
-					$clean .= "___" . count($literal_strings) . "___";
112
-
113
-					//push the string onto our array
114
-					array_push($literal_strings,$literal);
115
-
116
-				}
117
-				else if($inComment && $d=="*/")
118
-				{
119
-					$inComment = false;
120
-					$literal .= $d;
121
-
122
-					//subsitute in a marker for the string
123
-					$clean .= "___" . count($literal_strings) . "___";
124
-
125
-					//push the string onto our array
126
-					array_push($literal_strings,$literal);
127
-
128
-					$j++;
129
-				}
130
-				else if($c == "\\" && !$escaped)
131
-					$escaped = true;
132
-				else
133
-					$escaped = false;
134
-
135
-				$literal .= $c;
136
-			}
137
-		}
138
-		if($inComment) $literal .= "\n";
139
-		$clean .= "\n";
140
-	}
141
-	//explode the clean string into lines again
142
-	$lines = explode("\n",$clean);
143
-
144
-	//now process each line at a time
145
-	for($i=0;$i<count($lines);$i++)
146
-	{
147
-		$line = $lines[$i];
148
-
149
-		//remove comments
150
-		$line = preg_replace("/\/\/(.*)/","",$line);
151
-
152
-		//strip leading and trailing whitespace
153
-		$line = trim($line);
154
-
155
-		//remove all whitespace with a single space
156
-		$line = preg_replace("/\s+/"," ",$line);
157
-
158
-		//remove any whitespace that occurs after/before an operator
159
-		$line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
160
-
161
-		$lines[$i] = $line;
162
-	}
163
-
164
-	//implode the lines
165
-	$sJS = implode("\n",$lines);
166
-
167
-	//make sure there is a max of 1 \n after each line
168
-	$sJS = preg_replace("/[\n]+/","\n",$sJS);
169
-
170
-	//strip out line breaks that immediately follow a semi-colon
171
-	$sJS = preg_replace("/;\n/",";",$sJS);
172
-
173
-	//curly brackets aren't on their own
174
-	$sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
175
-
176
-	//finally loop through and replace all the literal strings:
177
-	for($i=0;$i<count($literal_strings);$i++)
178
-		$sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
179
-
180
-	return $sJS;
45
+    //remove windows cariage returns
46
+    $sJS = str_replace("\r","",$sJS);
47
+
48
+    //array to store replaced literal strings
49
+    $literal_strings = array();
50
+
51
+    //explode the string into lines
52
+    $lines = explode("\n",$sJS);
53
+    //loop through all the lines, building a new string at the same time as removing literal strings
54
+    $clean = "";
55
+    $inComment = false;
56
+    $literal = "";
57
+    $inQuote = false;
58
+    $escaped = false;
59
+    $quoteChar = "";
60
+
61
+    for($i=0;$i<count($lines);$i++)
62
+    {
63
+        $line = $lines[$i];
64
+        $inNormalComment = false;
65
+
66
+        //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
67
+        for($j=0;$j<strlen($line);$j++)
68
+        {
69
+            $c = substr($line,$j,1);
70
+            $d = substr($line,$j,2);
71
+
72
+            //look for start of quote
73
+            if(!$inQuote && !$inComment)
74
+            {
75
+                //is this character a quote or a comment
76
+                if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
77
+                {
78
+                    $inQuote = true;
79
+                    $inComment = false;
80
+                    $escaped = false;
81
+                    $quoteChar = $c;
82
+                    $literal = $c;
83
+                }
84
+                else if($d=="/*" && !$inNormalComment)
85
+                {
86
+                    $inQuote = false;
87
+                    $inComment = true;
88
+                    $escaped = false;
89
+                    $quoteChar = $d;
90
+                    $literal = $d;
91
+                    $j++;
92
+                }
93
+                else if($d=="//") //ignore string markers that are found inside comments
94
+                {
95
+                    $inNormalComment = true;
96
+                    $clean .= $c;
97
+                }
98
+                else
99
+                {
100
+                    $clean .= $c;
101
+                }
102
+            }
103
+            else //allready in a string so find end quote
104
+            {
105
+                if($c == $quoteChar && !$escaped && !$inComment)
106
+                {
107
+                    $inQuote = false;
108
+                    $literal .= $c;
109
+
110
+                    //subsitute in a marker for the string
111
+                    $clean .= "___" . count($literal_strings) . "___";
112
+
113
+                    //push the string onto our array
114
+                    array_push($literal_strings,$literal);
115
+
116
+                }
117
+                else if($inComment && $d=="*/")
118
+                {
119
+                    $inComment = false;
120
+                    $literal .= $d;
121
+
122
+                    //subsitute in a marker for the string
123
+                    $clean .= "___" . count($literal_strings) . "___";
124
+
125
+                    //push the string onto our array
126
+                    array_push($literal_strings,$literal);
127
+
128
+                    $j++;
129
+                }
130
+                else if($c == "\\" && !$escaped)
131
+                    $escaped = true;
132
+                else
133
+                    $escaped = false;
134
+
135
+                $literal .= $c;
136
+            }
137
+        }
138
+        if($inComment) $literal .= "\n";
139
+        $clean .= "\n";
140
+    }
141
+    //explode the clean string into lines again
142
+    $lines = explode("\n",$clean);
143
+
144
+    //now process each line at a time
145
+    for($i=0;$i<count($lines);$i++)
146
+    {
147
+        $line = $lines[$i];
148
+
149
+        //remove comments
150
+        $line = preg_replace("/\/\/(.*)/","",$line);
151
+
152
+        //strip leading and trailing whitespace
153
+        $line = trim($line);
154
+
155
+        //remove all whitespace with a single space
156
+        $line = preg_replace("/\s+/"," ",$line);
157
+
158
+        //remove any whitespace that occurs after/before an operator
159
+        $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
160
+
161
+        $lines[$i] = $line;
162
+    }
163
+
164
+    //implode the lines
165
+    $sJS = implode("\n",$lines);
166
+
167
+    //make sure there is a max of 1 \n after each line
168
+    $sJS = preg_replace("/[\n]+/","\n",$sJS);
169
+
170
+    //strip out line breaks that immediately follow a semi-colon
171
+    $sJS = preg_replace("/;\n/",";",$sJS);
172
+
173
+    //curly brackets aren't on their own
174
+    $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
175
+
176
+    //finally loop through and replace all the literal strings:
177
+    for($i=0;$i<count($literal_strings);$i++)
178
+        $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
179
+
180
+    return $sJS;
181 181
 }
182 182
 ?>
Please login to merge, or discard this patch.