@@ -84,6 +84,9 @@ |
||
84 | 84 | $this->members->SelectedValues = $members; |
85 | 85 | } |
86 | 86 | |
87 | + /** |
|
88 | + * @param string $role |
|
89 | + */ |
|
87 | 90 | protected function getUsersWithRole($role) |
88 | 91 | { |
89 | 92 | if(is_null($this->allUsers)) |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | |
9 | 9 | protected function getCurrentProject() |
10 | 10 | { |
11 | - if(!$this->currentProject) |
|
11 | + if (!$this->currentProject) |
|
12 | 12 | { |
13 | 13 | $id = intval($this->Request['ProjectID']); |
14 | - if($id > 0) |
|
14 | + if ($id > 0) |
|
15 | 15 | $this->currentProject = $this->getProjectDao()->getProjectByID($id); |
16 | 16 | } |
17 | 17 | return $this->currentProject; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | public function onLoad($param) |
31 | 31 | { |
32 | - if(!$this->IsPostBack) |
|
32 | + if (!$this->IsPostBack) |
|
33 | 33 | { |
34 | 34 | $this->manager->DataSource = $this->getUsersWithRole('manager'); |
35 | 35 | $this->manager->dataBind(); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | $project = $this->getCurrentProject(); |
40 | 40 | |
41 | - if($project !== null) |
|
41 | + if ($project !== null) |
|
42 | 42 | { |
43 | 43 | $this->projectName->Text = $project->Name; |
44 | 44 | $this->completionDate->TimeStamp = $project->CompletionDate; |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | protected function getProjects() |
71 | 71 | { |
72 | 72 | $projects = array(); |
73 | - foreach($this->getProjectDao()->getAllProjects() as $project) |
|
73 | + foreach ($this->getProjectDao()->getAllProjects() as $project) |
|
74 | 74 | { |
75 | - if($project->Name != $this->currentProject->Name) |
|
75 | + if ($project->Name != $this->currentProject->Name) |
|
76 | 76 | $projects[$project->ID] = $project->Name; |
77 | 77 | } |
78 | 78 | return $projects; |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | |
87 | 87 | protected function getUsersWithRole($role) |
88 | 88 | { |
89 | - if(is_null($this->allUsers)) |
|
89 | + if (is_null($this->allUsers)) |
|
90 | 90 | { |
91 | 91 | $dao = $this->Application->Modules['daos']->getDao('UserDao'); |
92 | 92 | $this->allUsers = $dao->getAllUsers(); |
93 | 93 | } |
94 | 94 | $users = array(); |
95 | - foreach($this->allUsers as $user) |
|
95 | + foreach ($this->allUsers as $user) |
|
96 | 96 | { |
97 | - if($user->isInRole($role)) |
|
97 | + if ($user->isInRole($role)) |
|
98 | 98 | $users[$user->Name] = $user->Name; |
99 | 99 | } |
100 | 100 | return $users; |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | public function onPreRender($param) |
104 | 104 | { |
105 | 105 | $ids = array(); |
106 | - foreach($this->members->Items as $item) |
|
106 | + foreach ($this->members->Items as $item) |
|
107 | 107 | { |
108 | - if($item->Selected) |
|
108 | + if ($item->Selected) |
|
109 | 109 | $ids[] = $item->Value; |
110 | 110 | } |
111 | 111 | $this->setViewState('ActiveConsultants', $ids); |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | |
114 | 114 | public function saveButton_clicked($sender, $param) |
115 | 115 | { |
116 | - if(!$this->Page->IsValid) |
|
116 | + if (!$this->Page->IsValid) |
|
117 | 117 | return; |
118 | 118 | |
119 | 119 | $newProject = new ProjectRecord; |
120 | 120 | |
121 | 121 | $projectDao = $this->getProjectDao(); |
122 | 122 | |
123 | - if($project = $this->getCurrentProject()) |
|
123 | + if ($project = $this->getCurrentProject()) |
|
124 | 124 | $newProject = $projectDao->getProjectByID($project->ID); |
125 | 125 | else |
126 | 126 | $newProject->CreatorUserName = $this->User->Name; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $newProject->EstimateDuration = floatval($this->estimateHours->Text); |
132 | 132 | $newProject->ManagerUserName = $this->manager->SelectedValue; |
133 | 133 | |
134 | - if($this->currentProject) |
|
134 | + if ($this->currentProject) |
|
135 | 135 | $projectDao->updateProject($newProject); |
136 | 136 | else |
137 | 137 | $projectDao->addNewProject($newProject); |
@@ -148,16 +148,16 @@ discard block |
||
148 | 148 | { |
149 | 149 | $active = $this->getViewState('ActiveConsultants'); |
150 | 150 | $projectDao = $this->getProjectDao(); |
151 | - foreach($this->members->Items as $item) |
|
151 | + foreach ($this->members->Items as $item) |
|
152 | 152 | { |
153 | - if($item->Selected) |
|
153 | + if ($item->Selected) |
|
154 | 154 | { |
155 | - if(!in_array($item->Value, $active)) |
|
155 | + if (!in_array($item->Value, $active)) |
|
156 | 156 | $projectDao->addUserToProject($projectID, $item->Value); |
157 | 157 | } |
158 | 158 | else |
159 | 159 | { |
160 | - if(in_array($item->Value, $active)) |
|
160 | + if (in_array($item->Value, $active)) |
|
161 | 161 | $projectDao->removeUserFromProject($projectID, $item->Value); |
162 | 162 | } |
163 | 163 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | public function deleteButton_clicked($sender, $param) |
167 | 167 | { |
168 | - if($project = $this->getCurrentProject()) |
|
168 | + if ($project = $this->getCurrentProject()) |
|
169 | 169 | { |
170 | 170 | $this->getProjectDao()->deleteProject($project->ID); |
171 | 171 | $url = $this->Service->constructUrl('TimeTracker.ProjectList'); |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | $categoryDao = $this->getCategoryDao(); |
180 | 180 | $categories = $categoryDao->getCategoriesByProjectID($project); |
181 | 181 | $currentProject = $this->getCurrentProject(); |
182 | - foreach($categories as $cat) |
|
182 | + foreach ($categories as $cat) |
|
183 | 183 | { |
184 | 184 | $cat->ProjectID = $currentProject->ID; |
185 | 185 | $categoryDao->addNewCategory($cat); |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | if(!$this->currentProject) |
12 | 12 | { |
13 | 13 | $id = intval($this->Request['ProjectID']); |
14 | - if($id > 0) |
|
15 | - $this->currentProject = $this->getProjectDao()->getProjectByID($id); |
|
14 | + if($id > 0) { |
|
15 | + $this->currentProject = $this->getProjectDao()->getProjectByID($id); |
|
16 | + } |
|
16 | 17 | } |
17 | 18 | return $this->currentProject; |
18 | 19 | } |
@@ -57,8 +58,7 @@ discard block |
||
57 | 58 | $this->projectList->DataSource = $this->getProjects(); |
58 | 59 | $this->projectList->dataBind(); |
59 | 60 | |
60 | - } |
|
61 | - else |
|
61 | + } else |
|
62 | 62 | { |
63 | 63 | $this->projectCategoryColumn->Visible = false; |
64 | 64 | $this->deleteButton->Visible = false; |
@@ -72,8 +72,9 @@ discard block |
||
72 | 72 | $projects = array(); |
73 | 73 | foreach($this->getProjectDao()->getAllProjects() as $project) |
74 | 74 | { |
75 | - if($project->Name != $this->currentProject->Name) |
|
76 | - $projects[$project->ID] = $project->Name; |
|
75 | + if($project->Name != $this->currentProject->Name) { |
|
76 | + $projects[$project->ID] = $project->Name; |
|
77 | + } |
|
77 | 78 | } |
78 | 79 | return $projects; |
79 | 80 | } |
@@ -94,8 +95,9 @@ discard block |
||
94 | 95 | $users = array(); |
95 | 96 | foreach($this->allUsers as $user) |
96 | 97 | { |
97 | - if($user->isInRole($role)) |
|
98 | - $users[$user->Name] = $user->Name; |
|
98 | + if($user->isInRole($role)) { |
|
99 | + $users[$user->Name] = $user->Name; |
|
100 | + } |
|
99 | 101 | } |
100 | 102 | return $users; |
101 | 103 | } |
@@ -105,25 +107,28 @@ discard block |
||
105 | 107 | $ids = array(); |
106 | 108 | foreach($this->members->Items as $item) |
107 | 109 | { |
108 | - if($item->Selected) |
|
109 | - $ids[] = $item->Value; |
|
110 | + if($item->Selected) { |
|
111 | + $ids[] = $item->Value; |
|
112 | + } |
|
110 | 113 | } |
111 | 114 | $this->setViewState('ActiveConsultants', $ids); |
112 | 115 | } |
113 | 116 | |
114 | 117 | public function saveButton_clicked($sender, $param) |
115 | 118 | { |
116 | - if(!$this->Page->IsValid) |
|
117 | - return; |
|
119 | + if(!$this->Page->IsValid) { |
|
120 | + return; |
|
121 | + } |
|
118 | 122 | |
119 | 123 | $newProject = new ProjectRecord; |
120 | 124 | |
121 | 125 | $projectDao = $this->getProjectDao(); |
122 | 126 | |
123 | - if($project = $this->getCurrentProject()) |
|
124 | - $newProject = $projectDao->getProjectByID($project->ID); |
|
125 | - else |
|
126 | - $newProject->CreatorUserName = $this->User->Name; |
|
127 | + if($project = $this->getCurrentProject()) { |
|
128 | + $newProject = $projectDao->getProjectByID($project->ID); |
|
129 | + } else { |
|
130 | + $newProject->CreatorUserName = $this->User->Name; |
|
131 | + } |
|
127 | 132 | |
128 | 133 | $newProject->Name = $this->projectName->Text; |
129 | 134 | $newProject->CompletionDate = $this->completionDate->TimeStamp; |
@@ -131,10 +136,11 @@ discard block |
||
131 | 136 | $newProject->EstimateDuration = floatval($this->estimateHours->Text); |
132 | 137 | $newProject->ManagerUserName = $this->manager->SelectedValue; |
133 | 138 | |
134 | - if($this->currentProject) |
|
135 | - $projectDao->updateProject($newProject); |
|
136 | - else |
|
137 | - $projectDao->addNewProject($newProject); |
|
139 | + if($this->currentProject) { |
|
140 | + $projectDao->updateProject($newProject); |
|
141 | + } else { |
|
142 | + $projectDao->addNewProject($newProject); |
|
143 | + } |
|
138 | 144 | |
139 | 145 | $this->updateProjectMembers($newProject->ID); |
140 | 146 | |
@@ -152,13 +158,14 @@ discard block |
||
152 | 158 | { |
153 | 159 | if($item->Selected) |
154 | 160 | { |
155 | - if(!in_array($item->Value, $active)) |
|
156 | - $projectDao->addUserToProject($projectID, $item->Value); |
|
157 | - } |
|
158 | - else |
|
161 | + if(!in_array($item->Value, $active)) { |
|
162 | + $projectDao->addUserToProject($projectID, $item->Value); |
|
163 | + } |
|
164 | + } else |
|
159 | 165 | { |
160 | - if(in_array($item->Value, $active)) |
|
161 | - $projectDao->removeUserFromProject($projectID, $item->Value); |
|
166 | + if(in_array($item->Value, $active)) { |
|
167 | + $projectDao->removeUserFromProject($projectID, $item->Value); |
|
168 | + } |
|
162 | 169 | } |
163 | 170 | } |
164 | 171 | } |
@@ -49,6 +49,9 @@ |
||
49 | 49 | throw new Exception('unable to find script file '.$file); |
50 | 50 | } |
51 | 51 | |
52 | + /** |
|
53 | + * @param string $script |
|
54 | + */ |
|
52 | 55 | protected function runScript($connection, $script) |
53 | 56 | { |
54 | 57 | $sql = file_get_contents($script); |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | { |
19 | 19 | $conn = $this->sqlmap->getDbConnection(); |
20 | 20 | $find = 'sqlite:protected'; |
21 | - if(is_int(strpos($conn->getConnectionString(),$find))) |
|
21 | + if (is_int(strpos($conn->getConnectionString(), $find))) |
|
22 | 22 | $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString); |
23 | 23 | $conn->setActive(false); |
24 | 24 | $conn->setActive(true); |
25 | - switch(strtolower($conn->getDriverName())) |
|
25 | + switch (strtolower($conn->getDriverName())) |
|
26 | 26 | { |
27 | 27 | case 'mysql': |
28 | 28 | return $this->flushMySQLDatabase(); |
@@ -34,29 +34,29 @@ discard block |
||
34 | 34 | function flushSQLiteDatabase() |
35 | 35 | { |
36 | 36 | $conn = $this->sqlmap->getDbConnection(); |
37 | - $file = str_replace('sqlite:','',$conn->getConnectionString()); |
|
38 | - $backup = $file.'.bak'; |
|
37 | + $file = str_replace('sqlite:', '', $conn->getConnectionString()); |
|
38 | + $backup = $file . '.bak'; |
|
39 | 39 | copy($backup, $file); |
40 | 40 | } |
41 | 41 | |
42 | 42 | function flushMySQLDatabase() |
43 | 43 | { |
44 | 44 | $conn = $this->sqlmap->getDbConnection(); |
45 | - $file = Prado::getPathOfNamespace('Application.App_Data.MySQL4.mysql-reset','.sql'); |
|
46 | - if(is_file($file)) |
|
45 | + $file = Prado::getPathOfNamespace('Application.App_Data.MySQL4.mysql-reset', '.sql'); |
|
46 | + if (is_file($file)) |
|
47 | 47 | $this->runScript($conn, $file); |
48 | 48 | else |
49 | - throw new Exception('unable to find script file '.$file); |
|
49 | + throw new Exception('unable to find script file ' . $file); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | protected function runScript($connection, $script) |
53 | 53 | { |
54 | 54 | $sql = file_get_contents($script); |
55 | 55 | $lines = explode(';', $sql); |
56 | - foreach($lines as $line) |
|
56 | + foreach ($lines as $line) |
|
57 | 57 | { |
58 | 58 | $line = trim($line); |
59 | - if(strlen($line) > 0) |
|
59 | + if (strlen($line) > 0) |
|
60 | 60 | $connection->createCommand($line)->execute(); |
61 | 61 | } |
62 | 62 | } |
@@ -18,8 +18,9 @@ discard block |
||
18 | 18 | { |
19 | 19 | $conn = $this->sqlmap->getDbConnection(); |
20 | 20 | $find = 'sqlite:protected'; |
21 | - if(is_int(strpos($conn->getConnectionString(),$find))) |
|
22 | - $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString); |
|
21 | + if(is_int(strpos($conn->getConnectionString(),$find))) { |
|
22 | + $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString); |
|
23 | + } |
|
23 | 24 | $conn->setActive(false); |
24 | 25 | $conn->setActive(true); |
25 | 26 | switch(strtolower($conn->getDriverName())) |
@@ -43,10 +44,11 @@ discard block |
||
43 | 44 | { |
44 | 45 | $conn = $this->sqlmap->getDbConnection(); |
45 | 46 | $file = Prado::getPathOfNamespace('Application.App_Data.MySQL4.mysql-reset','.sql'); |
46 | - if(is_file($file)) |
|
47 | - $this->runScript($conn, $file); |
|
48 | - else |
|
49 | - throw new Exception('unable to find script file '.$file); |
|
47 | + if(is_file($file)) { |
|
48 | + $this->runScript($conn, $file); |
|
49 | + } else { |
|
50 | + throw new Exception('unable to find script file '.$file); |
|
51 | + } |
|
50 | 52 | } |
51 | 53 | |
52 | 54 | protected function runScript($connection, $script) |
@@ -56,8 +58,9 @@ discard block |
||
56 | 58 | foreach($lines as $line) |
57 | 59 | { |
58 | 60 | $line = trim($line); |
59 | - if(strlen($line) > 0) |
|
60 | - $connection->createCommand($line)->execute(); |
|
61 | + if(strlen($line) > 0) { |
|
62 | + $connection->createCommand($line)->execute(); |
|
63 | + } |
|
61 | 64 | } |
62 | 65 | } |
63 | 66 | } |
@@ -22,6 +22,9 @@ |
||
22 | 22 | $this->assertEqual($user->getEmailAddress(), '[email protected]'); |
23 | 23 | } |
24 | 24 | |
25 | + /** |
|
26 | + * @param TimeTrackerUser $user2 |
|
27 | + */ |
|
25 | 28 | function assertSameUser($user1, $user2) |
26 | 29 | { |
27 | 30 | if(is_null($user1) || is_null($user2)) |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once(dirname(__FILE__).'/BaseTestCase.php'); |
|
3 | +require_once(dirname(__FILE__) . '/BaseTestCase.php'); |
|
4 | 4 | |
5 | 5 | class UserDaoTestCase extends BaseTestCase |
6 | 6 | { |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | function assertIsAdmin($user) |
18 | 18 | { |
19 | - if(!$user) |
|
19 | + if (!$user) |
|
20 | 20 | return $this->fail(); |
21 | 21 | $this->assertEqual($user->getName(), 'admin'); |
22 | 22 | $this->assertEqual($user->getEmailAddress(), '[email protected]'); |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | function assertSameUser($user1, $user2) |
26 | 26 | { |
27 | - if(is_null($user1) || is_null($user2)) |
|
27 | + if (is_null($user1) || is_null($user2)) |
|
28 | 28 | return $this->fail(); |
29 | 29 | |
30 | 30 | $this->assertEqual($user1->getName(), $user2->getName()); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | function assertIsAdminRole($user) |
35 | 35 | { |
36 | - if(is_null($user)) |
|
36 | + if (is_null($user)) |
|
37 | 37 | return $this->fail(); |
38 | 38 | |
39 | 39 | $this->assertTrue($user->isInRole('admin')); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | function assertIsManagerRole($user) |
43 | 43 | { |
44 | - if(is_null($user)) |
|
44 | + if (is_null($user)) |
|
45 | 45 | return $this->fail(); |
46 | 46 | |
47 | 47 | $this->assertTrue($user->isInRole('manager')); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | function assertIsConsultantRole($user) |
51 | 51 | { |
52 | - if(is_null($user)) |
|
52 | + if (is_null($user)) |
|
53 | 53 | return $this->fail(); |
54 | 54 | |
55 | 55 | $this->assertTrue($user->isInRole('consultant')); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | |
58 | 58 | function assertNotConsultantRole($user) |
59 | 59 | { |
60 | - if(is_null($user)) |
|
60 | + if (is_null($user)) |
|
61 | 61 | return $this->fail(); |
62 | 62 | |
63 | 63 | $this->assertFalse($user->isInRole('consultant')); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $this->userDao->updateUserRoles($user); |
178 | 178 | $this->fail(); |
179 | 179 | } |
180 | - catch(TDbException $e) |
|
180 | + catch (TDbException $e) |
|
181 | 181 | { |
182 | 182 | $this->pass(); |
183 | 183 | } |
@@ -16,16 +16,18 @@ discard block |
||
16 | 16 | |
17 | 17 | function assertIsAdmin($user) |
18 | 18 | { |
19 | - if(!$user) |
|
20 | - return $this->fail(); |
|
19 | + if(!$user) { |
|
20 | + return $this->fail(); |
|
21 | + } |
|
21 | 22 | $this->assertEqual($user->getName(), 'admin'); |
22 | 23 | $this->assertEqual($user->getEmailAddress(), '[email protected]'); |
23 | 24 | } |
24 | 25 | |
25 | 26 | function assertSameUser($user1, $user2) |
26 | 27 | { |
27 | - if(is_null($user1) || is_null($user2)) |
|
28 | - return $this->fail(); |
|
28 | + if(is_null($user1) || is_null($user2)) { |
|
29 | + return $this->fail(); |
|
30 | + } |
|
29 | 31 | |
30 | 32 | $this->assertEqual($user1->getName(), $user2->getName()); |
31 | 33 | $this->assertEqual($user1->getEmailAddress(), $user2->getEmailAddress()); |
@@ -33,32 +35,36 @@ discard block |
||
33 | 35 | |
34 | 36 | function assertIsAdminRole($user) |
35 | 37 | { |
36 | - if(is_null($user)) |
|
37 | - return $this->fail(); |
|
38 | + if(is_null($user)) { |
|
39 | + return $this->fail(); |
|
40 | + } |
|
38 | 41 | |
39 | 42 | $this->assertTrue($user->isInRole('admin')); |
40 | 43 | } |
41 | 44 | |
42 | 45 | function assertIsManagerRole($user) |
43 | 46 | { |
44 | - if(is_null($user)) |
|
45 | - return $this->fail(); |
|
47 | + if(is_null($user)) { |
|
48 | + return $this->fail(); |
|
49 | + } |
|
46 | 50 | |
47 | 51 | $this->assertTrue($user->isInRole('manager')); |
48 | 52 | } |
49 | 53 | |
50 | 54 | function assertIsConsultantRole($user) |
51 | 55 | { |
52 | - if(is_null($user)) |
|
53 | - return $this->fail(); |
|
56 | + if(is_null($user)) { |
|
57 | + return $this->fail(); |
|
58 | + } |
|
54 | 59 | |
55 | 60 | $this->assertTrue($user->isInRole('consultant')); |
56 | 61 | } |
57 | 62 | |
58 | 63 | function assertNotConsultantRole($user) |
59 | 64 | { |
60 | - if(is_null($user)) |
|
61 | - return $this->fail(); |
|
65 | + if(is_null($user)) { |
|
66 | + return $this->fail(); |
|
67 | + } |
|
62 | 68 | |
63 | 69 | $this->assertFalse($user->isInRole('consultant')); |
64 | 70 | } |
@@ -176,8 +182,7 @@ discard block |
||
176 | 182 | { |
177 | 183 | $this->userDao->updateUserRoles($user); |
178 | 184 | $this->fail(); |
179 | - } |
|
180 | - catch(TDbException $e) |
|
185 | + } catch(TDbException $e) |
|
181 | 186 | { |
182 | 187 | $this->pass(); |
183 | 188 | } |
@@ -50,7 +50,6 @@ discard block |
||
50 | 50 | * "Server" request tab. |
51 | 51 | * |
52 | 52 | * @see http://www.firephp.org/Wiki/Reference/Fb |
53 | - * @param mixed $Object |
|
54 | 53 | * @return true |
55 | 54 | * @throws Exception |
56 | 55 | */ |
@@ -130,7 +129,6 @@ discard block |
||
130 | 129 | * Log object to firebug |
131 | 130 | * |
132 | 131 | * @see http://www.firephp.org/Wiki/Reference/Fb |
133 | - * @param mixed $Object |
|
134 | 132 | * @return true |
135 | 133 | * @throws Exception |
136 | 134 | */ |
@@ -150,7 +148,7 @@ discard block |
||
150 | 148 | * |
151 | 149 | * @param string $Name |
152 | 150 | * @param array $Options OPTIONAL Instructions on how to log the group |
153 | - * @return true |
|
151 | + * @return boolean |
|
154 | 152 | */ |
155 | 153 | public static function group($Name, $Options=null) { |
156 | 154 | $instance = FirePHP::getInstance(true); |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * @return void |
74 | 74 | */ |
75 | 75 | public static function setEnabled($Enabled) { |
76 | - $instance = FirePHP::getInstance(true); |
|
77 | - $instance->setEnabled($Enabled); |
|
76 | + $instance = FirePHP::getInstance(true); |
|
77 | + $instance->setEnabled($Enabled); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * @return boolean TRUE if enabled |
85 | 85 | */ |
86 | 86 | public static function getEnabled() { |
87 | - $instance = FirePHP::getInstance(true); |
|
88 | - return $instance->getEnabled(); |
|
87 | + $instance = FirePHP::getInstance(true); |
|
88 | + return $instance->getEnabled(); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | * @return void |
100 | 100 | */ |
101 | 101 | public static function setObjectFilter($Class, $Filter) { |
102 | - $instance = FirePHP::getInstance(true); |
|
103 | - $instance->setObjectFilter($Class, $Filter); |
|
102 | + $instance = FirePHP::getInstance(true); |
|
103 | + $instance->setObjectFilter($Class, $Filter); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | * @return void |
112 | 112 | */ |
113 | 113 | public static function setOptions($Options) { |
114 | - $instance = FirePHP::getInstance(true); |
|
115 | - $instance->setOptions($Options); |
|
114 | + $instance = FirePHP::getInstance(true); |
|
115 | + $instance->setOptions($Options); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @return array The options |
123 | 123 | */ |
124 | 124 | public static function getOptions() { |
125 | - $instance = FirePHP::getInstance(true); |
|
126 | - return $instance->getOptions(); |
|
125 | + $instance = FirePHP::getInstance(true); |
|
126 | + return $instance->getOptions(); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -136,9 +136,9 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public static function send() |
138 | 138 | { |
139 | - $instance = FirePHP::getInstance(true); |
|
140 | - $args = func_get_args(); |
|
141 | - return call_user_func_array(array($instance,'fb'),$args); |
|
139 | + $instance = FirePHP::getInstance(true); |
|
140 | + $args = func_get_args(); |
|
141 | + return call_user_func_array(array($instance,'fb'),$args); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | * @return true |
154 | 154 | */ |
155 | 155 | public static function group($Name, $Options=null) { |
156 | - $instance = FirePHP::getInstance(true); |
|
157 | - return $instance->group($Name, $Options); |
|
156 | + $instance = FirePHP::getInstance(true); |
|
157 | + return $instance->group($Name, $Options); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @throws Exception |
165 | 165 | */ |
166 | 166 | public static function groupEnd() { |
167 | - return self::send(null, null, FirePHP::GROUP_END); |
|
167 | + return self::send(null, null, FirePHP::GROUP_END); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @throws Exception |
178 | 178 | */ |
179 | 179 | public static function log($Object, $Label=null) { |
180 | - return self::send($Object, $Label, FirePHP::LOG); |
|
180 | + return self::send($Object, $Label, FirePHP::LOG); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @throws Exception |
191 | 191 | */ |
192 | 192 | public static function info($Object, $Label=null) { |
193 | - return self::send($Object, $Label, FirePHP::INFO); |
|
193 | + return self::send($Object, $Label, FirePHP::INFO); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @throws Exception |
204 | 204 | */ |
205 | 205 | public static function warn($Object, $Label=null) { |
206 | - return self::send($Object, $Label, FirePHP::WARN); |
|
206 | + return self::send($Object, $Label, FirePHP::WARN); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @throws Exception |
217 | 217 | */ |
218 | 218 | public static function error($Object, $Label=null) { |
219 | - return self::send($Object, $Label, FirePHP::ERROR); |
|
219 | + return self::send($Object, $Label, FirePHP::ERROR); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @throws Exception |
230 | 230 | */ |
231 | 231 | public static function dump($Key, $Variable) { |
232 | - return self::send($Variable, $Key, FirePHP::DUMP); |
|
232 | + return self::send($Variable, $Key, FirePHP::DUMP); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @throws Exception |
242 | 242 | */ |
243 | 243 | public static function trace($Label) { |
244 | - return self::send($Label, FirePHP::TRACE); |
|
244 | + return self::send($Label, FirePHP::TRACE); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * @throws Exception |
255 | 255 | */ |
256 | 256 | public static function table($Label, $Table) { |
257 | - return self::send($Table, $Label, FirePHP::TABLE); |
|
257 | + return self::send($Table, $Label, FirePHP::TABLE); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @package FirePHP |
43 | 43 | */ |
44 | 44 | |
45 | -require_once dirname(__FILE__).'/FirePHP.class.php'; |
|
45 | +require_once dirname(__FILE__) . '/FirePHP.class.php'; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Sends the given data to the FirePHP Firefox Extension. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $instance = FirePHP::getInstance(true); |
60 | 60 | |
61 | 61 | $args = func_get_args(); |
62 | - return call_user_func_array(array($instance,'fb'),$args); |
|
62 | + return call_user_func_array(array($instance, 'fb'), $args); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | { |
139 | 139 | $instance = FirePHP::getInstance(true); |
140 | 140 | $args = func_get_args(); |
141 | - return call_user_func_array(array($instance,'fb'),$args); |
|
141 | + return call_user_func_array(array($instance, 'fb'), $args); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @param array $Options OPTIONAL Instructions on how to log the group |
153 | 153 | * @return true |
154 | 154 | */ |
155 | - public static function group($Name, $Options=null) { |
|
155 | + public static function group($Name, $Options = null) { |
|
156 | 156 | $instance = FirePHP::getInstance(true); |
157 | 157 | return $instance->group($Name, $Options); |
158 | 158 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @return true |
177 | 177 | * @throws Exception |
178 | 178 | */ |
179 | - public static function log($Object, $Label=null) { |
|
179 | + public static function log($Object, $Label = null) { |
|
180 | 180 | return self::send($Object, $Label, FirePHP::LOG); |
181 | 181 | } |
182 | 182 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @return true |
190 | 190 | * @throws Exception |
191 | 191 | */ |
192 | - public static function info($Object, $Label=null) { |
|
192 | + public static function info($Object, $Label = null) { |
|
193 | 193 | return self::send($Object, $Label, FirePHP::INFO); |
194 | 194 | } |
195 | 195 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return true |
203 | 203 | * @throws Exception |
204 | 204 | */ |
205 | - public static function warn($Object, $Label=null) { |
|
205 | + public static function warn($Object, $Label = null) { |
|
206 | 206 | return self::send($Object, $Label, FirePHP::WARN); |
207 | 207 | } |
208 | 208 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @return true |
216 | 216 | * @throws Exception |
217 | 217 | */ |
218 | - public static function error($Object, $Label=null) { |
|
218 | + public static function error($Object, $Label = null) { |
|
219 | 219 | return self::send($Object, $Label, FirePHP::ERROR); |
220 | 220 | } |
221 | 221 |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | /** |
227 | 227 | * When the object gets serialized only include specific object members. |
228 | 228 | * |
229 | - * @return array |
|
229 | + * @return string[] |
|
230 | 230 | */ |
231 | 231 | public function __sleep() { |
232 | 232 | return array('options','objectFilters','enabled'); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * |
317 | 317 | * Will throw exceptions for each php error. |
318 | 318 | * |
319 | - * @return mixed Returns a string containing the previously defined error handler (if any) |
|
319 | + * @return null|callable Returns a string containing the previously defined error handler (if any) |
|
320 | 320 | */ |
321 | 321 | public function registerErrorHandler($throwErrorExceptions=true) |
322 | 322 | { |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | /** |
363 | 363 | * Register FirePHP as your exception handler |
364 | 364 | * |
365 | - * @return mixed Returns the name of the previously defined exception handler, |
|
365 | + * @return callable Returns the name of the previously defined exception handler, |
|
366 | 366 | * or NULL on error. |
367 | 367 | * If no previous handler was defined, NULL is also returned. |
368 | 368 | */ |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | * |
468 | 468 | * @param string $Name |
469 | 469 | * @param array $Options OPTIONAL Instructions on how to log the group |
470 | - * @return true |
|
470 | + * @return boolean |
|
471 | 471 | * @throws Exception |
472 | 472 | */ |
473 | 473 | public function group($Name, $Options=null) { |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | /** |
492 | 492 | * Ends a group you have started before |
493 | 493 | * |
494 | - * @return true |
|
494 | + * @return boolean |
|
495 | 495 | * @throws Exception |
496 | 496 | */ |
497 | 497 | public function groupEnd() { |
@@ -502,9 +502,9 @@ discard block |
||
502 | 502 | * Log object with label to firebug console |
503 | 503 | * |
504 | 504 | * @see FirePHP::LOG |
505 | - * @param mixes $Object |
|
505 | + * @param string $Object |
|
506 | 506 | * @param string $Label |
507 | - * @return true |
|
507 | + * @return boolean |
|
508 | 508 | * @throws Exception |
509 | 509 | */ |
510 | 510 | public function log($Object, $Label=null) { |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | * @see FirePHP::INFO |
518 | 518 | * @param mixes $Object |
519 | 519 | * @param string $Label |
520 | - * @return true |
|
520 | + * @return boolean |
|
521 | 521 | * @throws Exception |
522 | 522 | */ |
523 | 523 | public function info($Object, $Label=null) { |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | * @see FirePHP::WARN |
531 | 531 | * @param mixes $Object |
532 | 532 | * @param string $Label |
533 | - * @return true |
|
533 | + * @return boolean |
|
534 | 534 | * @throws Exception |
535 | 535 | */ |
536 | 536 | public function warn($Object, $Label=null) { |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | * @see FirePHP::ERROR |
544 | 544 | * @param mixes $Object |
545 | 545 | * @param string $Label |
546 | - * @return true |
|
546 | + * @return boolean |
|
547 | 547 | * @throws Exception |
548 | 548 | */ |
549 | 549 | public function error($Object, $Label=null) { |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | * @see FirePHP::DUMP |
557 | 557 | * @param string $Key |
558 | 558 | * @param mixed $Variable |
559 | - * @return true |
|
559 | + * @return boolean |
|
560 | 560 | * @throws Exception |
561 | 561 | */ |
562 | 562 | public function dump($Key, $Variable) { |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | * |
569 | 569 | * @see FirePHP::TRACE |
570 | 570 | * @param string $Label |
571 | - * @return true |
|
571 | + * @return boolean |
|
572 | 572 | * @throws Exception |
573 | 573 | */ |
574 | 574 | public function trace($Label) { |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | * @see FirePHP::TABLE |
582 | 582 | * @param string $Label |
583 | 583 | * @param string $Table |
584 | - * @return true |
|
584 | + * @return boolean |
|
585 | 585 | * @throws Exception |
586 | 586 | */ |
587 | 587 | public function table($Label, $Table) { |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | * |
608 | 608 | * @see http://www.firephp.org/Wiki/Reference/Fb |
609 | 609 | * @param mixed $Object The variable to be logged |
610 | - * @return true Return TRUE if message was added to headers, FALSE otherwise |
|
610 | + * @return boolean Return TRUE if message was added to headers, FALSE otherwise |
|
611 | 611 | * @throws Exception |
612 | 612 | */ |
613 | 613 | public function fb($Object) { |
@@ -1005,7 +1005,6 @@ discard block |
||
1005 | 1005 | * protected and private visibility |
1006 | 1006 | * |
1007 | 1007 | * @param Object $Object The object to be encoded |
1008 | - * @param int $Depth The current traversal depth |
|
1009 | 1008 | * @return array All members of the object |
1010 | 1009 | */ |
1011 | 1010 | protected function encodeObject($Object, $ObjectDepth = 1, $ArrayDepth = 1) |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @return array |
230 | 230 | */ |
231 | 231 | public function __sleep() { |
232 | - return array('options','objectFilters','enabled'); |
|
232 | + return array('options', 'objectFilters', 'enabled'); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | * @param boolean $AutoCreate |
239 | 239 | * @return FirePHP |
240 | 240 | */ |
241 | - public static function getInstance($AutoCreate=false) { |
|
242 | - if($AutoCreate===true && !self::$instance) { |
|
241 | + public static function getInstance($AutoCreate = false) { |
|
242 | + if ($AutoCreate === true && !self::$instance) { |
|
243 | 243 | self::init(); |
244 | 244 | } |
245 | 245 | return self::$instance; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return void |
300 | 300 | */ |
301 | 301 | public function setOptions($Options) { |
302 | - $this->options = array_merge($this->options,$Options); |
|
302 | + $this->options = array_merge($this->options, $Options); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | * |
319 | 319 | * @return mixed Returns a string containing the previously defined error handler (if any) |
320 | 320 | */ |
321 | - public function registerErrorHandler($throwErrorExceptions=true) |
|
321 | + public function registerErrorHandler($throwErrorExceptions = true) |
|
322 | 322 | { |
323 | 323 | //NOTE: The following errors will not be caught by this error handler: |
324 | 324 | // E_ERROR, E_PARSE, E_CORE_ERROR, |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | $this->throwErrorExceptions = $throwErrorExceptions; |
329 | 329 | |
330 | - return set_error_handler(array($this,'errorHandler')); |
|
330 | + return set_error_handler(array($this, 'errorHandler')); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | if (error_reporting() & $errno) { |
352 | 352 | |
353 | 353 | $exception = new ErrorException($errstr, 0, $errno, $errfile, $errline); |
354 | - if($this->throwErrorExceptions) { |
|
354 | + if ($this->throwErrorExceptions) { |
|
355 | 355 | throw $exception; |
356 | 356 | } else { |
357 | 357 | $this->fb($exception); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function registerExceptionHandler() |
370 | 370 | { |
371 | - return set_exception_handler(array($this,'exceptionHandler')); |
|
371 | + return set_exception_handler(array($this, 'exceptionHandler')); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -397,12 +397,12 @@ discard block |
||
397 | 397 | * @param boolean $throwAssertionExceptions |
398 | 398 | * @return mixed Returns the original setting or FALSE on errors |
399 | 399 | */ |
400 | - public function registerAssertionHandler($convertAssertionErrorsToExceptions=true, $throwAssertionExceptions=false) |
|
400 | + public function registerAssertionHandler($convertAssertionErrorsToExceptions = true, $throwAssertionExceptions = false) |
|
401 | 401 | { |
402 | 402 | $this->convertAssertionErrorsToExceptions = $convertAssertionErrorsToExceptions; |
403 | 403 | $this->throwAssertionExceptions = $throwAssertionExceptions; |
404 | 404 | |
405 | - if($throwAssertionExceptions && !$convertAssertionErrorsToExceptions) { |
|
405 | + if ($throwAssertionExceptions && !$convertAssertionErrorsToExceptions) { |
|
406 | 406 | throw $this->newException('Cannot throw assertion exceptions as assertion errors are not being converted to exceptions!'); |
407 | 407 | } |
408 | 408 | |
@@ -421,11 +421,11 @@ discard block |
||
421 | 421 | public function assertionHandler($file, $line, $code) |
422 | 422 | { |
423 | 423 | |
424 | - if($this->convertAssertionErrorsToExceptions) { |
|
424 | + if ($this->convertAssertionErrorsToExceptions) { |
|
425 | 425 | |
426 | - $exception = new ErrorException('Assertion Failed - Code[ '.$code.' ]', 0, null, $file, $line); |
|
426 | + $exception = new ErrorException('Assertion Failed - Code[ ' . $code . ' ]', 0, null, $file, $line); |
|
427 | 427 | |
428 | - if($this->throwAssertionExceptions) { |
|
428 | + if ($this->throwAssertionExceptions) { |
|
429 | 429 | throw $exception; |
430 | 430 | } else { |
431 | 431 | $this->fb($exception); |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | |
434 | 434 | } else { |
435 | 435 | |
436 | - $this->fb($code, 'Assertion Failed', FirePHP::ERROR, array('File'=>$file,'Line'=>$line)); |
|
436 | + $this->fb($code, 'Assertion Failed', FirePHP::ERROR, array('File'=>$file, 'Line'=>$line)); |
|
437 | 437 | |
438 | 438 | } |
439 | 439 | } |
@@ -470,18 +470,18 @@ discard block |
||
470 | 470 | * @return true |
471 | 471 | * @throws Exception |
472 | 472 | */ |
473 | - public function group($Name, $Options=null) { |
|
473 | + public function group($Name, $Options = null) { |
|
474 | 474 | |
475 | - if(!$Name) { |
|
475 | + if (!$Name) { |
|
476 | 476 | throw $this->newException('You must specify a label for the group!'); |
477 | 477 | } |
478 | 478 | |
479 | - if($Options) { |
|
480 | - if(!is_array($Options)) { |
|
479 | + if ($Options) { |
|
480 | + if (!is_array($Options)) { |
|
481 | 481 | throw $this->newException('Options must be defined as an array!'); |
482 | 482 | } |
483 | - if(array_key_exists('Collapsed', $Options)) { |
|
484 | - $Options['Collapsed'] = ($Options['Collapsed'])?'true':'false'; |
|
483 | + if (array_key_exists('Collapsed', $Options)) { |
|
484 | + $Options['Collapsed'] = ($Options['Collapsed']) ? 'true' : 'false'; |
|
485 | 485 | } |
486 | 486 | } |
487 | 487 | |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @return true |
508 | 508 | * @throws Exception |
509 | 509 | */ |
510 | - public function log($Object, $Label=null) { |
|
510 | + public function log($Object, $Label = null) { |
|
511 | 511 | return $this->fb($Object, $Label, FirePHP::LOG); |
512 | 512 | } |
513 | 513 | |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | * @return true |
521 | 521 | * @throws Exception |
522 | 522 | */ |
523 | - public function info($Object, $Label=null) { |
|
523 | + public function info($Object, $Label = null) { |
|
524 | 524 | return $this->fb($Object, $Label, FirePHP::INFO); |
525 | 525 | } |
526 | 526 | |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | * @return true |
534 | 534 | * @throws Exception |
535 | 535 | */ |
536 | - public function warn($Object, $Label=null) { |
|
536 | + public function warn($Object, $Label = null) { |
|
537 | 537 | return $this->fb($Object, $Label, FirePHP::WARN); |
538 | 538 | } |
539 | 539 | |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | * @return true |
547 | 547 | * @throws Exception |
548 | 548 | */ |
549 | - public function error($Object, $Label=null) { |
|
549 | + public function error($Object, $Label = null) { |
|
550 | 550 | return $this->fb($Object, $Label, FirePHP::ERROR); |
551 | 551 | } |
552 | 552 | |
@@ -595,8 +595,8 @@ discard block |
||
595 | 595 | */ |
596 | 596 | public function detectClientExtension() { |
597 | 597 | /* Check if FirePHP is installed on client */ |
598 | - if(!@preg_match_all('/\sFirePHP\/([\.|\d]*)\s?/si',$this->getUserAgent(),$m) || |
|
599 | - !version_compare($m[1][0],'0.0.6','>=')) { |
|
598 | + if (!@preg_match_all('/\sFirePHP\/([\.|\d]*)\s?/si', $this->getUserAgent(), $m) || |
|
599 | + !version_compare($m[1][0], '0.0.6', '>=')) { |
|
600 | 600 | return false; |
601 | 601 | } |
602 | 602 | return true; |
@@ -612,17 +612,17 @@ discard block |
||
612 | 612 | */ |
613 | 613 | public function fb($Object) { |
614 | 614 | |
615 | - if(!$this->enabled) { |
|
615 | + if (!$this->enabled) { |
|
616 | 616 | return false; |
617 | 617 | } |
618 | 618 | |
619 | 619 | if (headers_sent($filename, $linenum)) { |
620 | 620 | // If we are logging from within the exception handler we cannot throw another exception |
621 | - if($this->inExceptionHandler) { |
|
621 | + if ($this->inExceptionHandler) { |
|
622 | 622 | // Simply echo the error out to the page |
623 | - echo '<div style="border: 2px solid red; font-family: Arial; font-size: 12px; background-color: lightgray; padding: 5px;"><span style="color: red; font-weight: bold;">FirePHP ERROR:</span> Headers already sent in <b>'.$filename.'</b> on line <b>'.$linenum.'</b>. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.</div>'; |
|
623 | + echo '<div style="border: 2px solid red; font-family: Arial; font-size: 12px; background-color: lightgray; padding: 5px;"><span style="color: red; font-weight: bold;">FirePHP ERROR:</span> Headers already sent in <b>' . $filename . '</b> on line <b>' . $linenum . '</b>. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.</div>'; |
|
624 | 624 | } else { |
625 | - throw $this->newException('Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.'); |
|
625 | + throw $this->newException('Headers already sent in ' . $filename . ' on line ' . $linenum . '. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.'); |
|
626 | 626 | } |
627 | 627 | } |
628 | 628 | |
@@ -630,10 +630,10 @@ discard block |
||
630 | 630 | $Label = null; |
631 | 631 | $Options = array(); |
632 | 632 | |
633 | - if(func_num_args()==1) { |
|
633 | + if (func_num_args() == 1) { |
|
634 | 634 | } else |
635 | - if(func_num_args()==2) { |
|
636 | - switch(func_get_arg(1)) { |
|
635 | + if (func_num_args() == 2) { |
|
636 | + switch (func_get_arg(1)) { |
|
637 | 637 | case self::LOG: |
638 | 638 | case self::INFO: |
639 | 639 | case self::WARN: |
@@ -651,11 +651,11 @@ discard block |
||
651 | 651 | break; |
652 | 652 | } |
653 | 653 | } else |
654 | - if(func_num_args()==3) { |
|
654 | + if (func_num_args() == 3) { |
|
655 | 655 | $Type = func_get_arg(2); |
656 | 656 | $Label = func_get_arg(1); |
657 | 657 | } else |
658 | - if(func_num_args()==4) { |
|
658 | + if (func_num_args() == 4) { |
|
659 | 659 | $Type = func_get_arg(2); |
660 | 660 | $Label = func_get_arg(1); |
661 | 661 | $Options = func_get_arg(3); |
@@ -664,27 +664,27 @@ discard block |
||
664 | 664 | } |
665 | 665 | |
666 | 666 | |
667 | - if(!$this->detectClientExtension()) { |
|
667 | + if (!$this->detectClientExtension()) { |
|
668 | 668 | return false; |
669 | 669 | } |
670 | 670 | |
671 | 671 | $meta = array(); |
672 | 672 | $skipFinalObjectEncode = false; |
673 | 673 | |
674 | - if($Object instanceof Exception) { |
|
674 | + if ($Object instanceof Exception) { |
|
675 | 675 | |
676 | 676 | $meta['file'] = $this->_escapeTraceFile($Object->getFile()); |
677 | 677 | $meta['line'] = $Object->getLine(); |
678 | 678 | |
679 | 679 | $trace = $Object->getTrace(); |
680 | - if($Object instanceof ErrorException |
|
680 | + if ($Object instanceof ErrorException |
|
681 | 681 | && isset($trace[0]['function']) |
682 | - && $trace[0]['function']=='errorHandler' |
|
682 | + && $trace[0]['function'] == 'errorHandler' |
|
683 | 683 | && isset($trace[0]['class']) |
684 | - && $trace[0]['class']=='FirePHP') { |
|
684 | + && $trace[0]['class'] == 'FirePHP') { |
|
685 | 685 | |
686 | 686 | $severity = false; |
687 | - switch($Object->getSeverity()) { |
|
687 | + switch ($Object->getSeverity()) { |
|
688 | 688 | case E_WARNING: $severity = 'E_WARNING'; break; |
689 | 689 | case E_NOTICE: $severity = 'E_NOTICE'; break; |
690 | 690 | case E_USER_ERROR: $severity = 'E_USER_ERROR'; break; |
@@ -697,11 +697,11 @@ discard block |
||
697 | 697 | } |
698 | 698 | |
699 | 699 | $Object = array('Class'=>get_class($Object), |
700 | - 'Message'=>$severity.': '.$Object->getMessage(), |
|
700 | + 'Message'=>$severity . ': ' . $Object->getMessage(), |
|
701 | 701 | 'File'=>$this->_escapeTraceFile($Object->getFile()), |
702 | 702 | 'Line'=>$Object->getLine(), |
703 | 703 | 'Type'=>'trigger', |
704 | - 'Trace'=>$this->_escapeTrace(array_splice($trace,2))); |
|
704 | + 'Trace'=>$this->_escapeTrace(array_splice($trace, 2))); |
|
705 | 705 | $skipFinalObjectEncode = true; |
706 | 706 | } else { |
707 | 707 | $Object = array('Class'=>get_class($Object), |
@@ -715,49 +715,49 @@ discard block |
||
715 | 715 | $Type = self::EXCEPTION; |
716 | 716 | |
717 | 717 | } else |
718 | - if($Type==self::TRACE) { |
|
718 | + if ($Type == self::TRACE) { |
|
719 | 719 | |
720 | 720 | $trace = debug_backtrace(); |
721 | - if(!$trace) return false; |
|
722 | - for( $i=0 ; $i<sizeof($trace) ; $i++ ) { |
|
721 | + if (!$trace) return false; |
|
722 | + for ($i = 0; $i < sizeof($trace); $i++) { |
|
723 | 723 | |
724 | - if(isset($trace[$i]['class']) |
|
724 | + if (isset($trace[$i]['class']) |
|
725 | 725 | && isset($trace[$i]['file']) |
726 | - && ($trace[$i]['class']=='FirePHP' |
|
727 | - || $trace[$i]['class']=='FB') |
|
728 | - && (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' |
|
729 | - || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { |
|
726 | + && ($trace[$i]['class'] == 'FirePHP' |
|
727 | + || $trace[$i]['class'] == 'FB') |
|
728 | + && (substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php' |
|
729 | + || substr($this->_standardizePath($trace[$i]['file']), -29, 29) == 'FirePHPCore/FirePHP.class.php')) { |
|
730 | 730 | /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ |
731 | 731 | } else |
732 | - if(isset($trace[$i]['class']) |
|
733 | - && isset($trace[$i+1]['file']) |
|
734 | - && $trace[$i]['class']=='FirePHP' |
|
735 | - && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') { |
|
732 | + if (isset($trace[$i]['class']) |
|
733 | + && isset($trace[$i + 1]['file']) |
|
734 | + && $trace[$i]['class'] == 'FirePHP' |
|
735 | + && substr($this->_standardizePath($trace[$i + 1]['file']), -18, 18) == 'FirePHPCore/fb.php') { |
|
736 | 736 | /* Skip fb() */ |
737 | 737 | } else |
738 | - if($trace[$i]['function']=='fb' |
|
739 | - || $trace[$i]['function']=='trace' |
|
740 | - || $trace[$i]['function']=='send') { |
|
741 | - $Object = array('Class'=>isset($trace[$i]['class'])?$trace[$i]['class']:'', |
|
742 | - 'Type'=>isset($trace[$i]['type'])?$trace[$i]['type']:'', |
|
743 | - 'Function'=>isset($trace[$i]['function'])?$trace[$i]['function']:'', |
|
738 | + if ($trace[$i]['function'] == 'fb' |
|
739 | + || $trace[$i]['function'] == 'trace' |
|
740 | + || $trace[$i]['function'] == 'send') { |
|
741 | + $Object = array('Class'=>isset($trace[$i]['class']) ? $trace[$i]['class'] : '', |
|
742 | + 'Type'=>isset($trace[$i]['type']) ? $trace[$i]['type'] : '', |
|
743 | + 'Function'=>isset($trace[$i]['function']) ? $trace[$i]['function'] : '', |
|
744 | 744 | 'Message'=>$trace[$i]['args'][0], |
745 | - 'File'=>isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'', |
|
746 | - 'Line'=>isset($trace[$i]['line'])?$trace[$i]['line']:'', |
|
747 | - 'Args'=>isset($trace[$i]['args'])?$this->encodeObject($trace[$i]['args']):'', |
|
748 | - 'Trace'=>$this->_escapeTrace(array_splice($trace,$i+1))); |
|
745 | + 'File'=>isset($trace[$i]['file']) ? $this->_escapeTraceFile($trace[$i]['file']) : '', |
|
746 | + 'Line'=>isset($trace[$i]['line']) ? $trace[$i]['line'] : '', |
|
747 | + 'Args'=>isset($trace[$i]['args']) ? $this->encodeObject($trace[$i]['args']) : '', |
|
748 | + 'Trace'=>$this->_escapeTrace(array_splice($trace, $i + 1))); |
|
749 | 749 | |
750 | 750 | $skipFinalObjectEncode = true; |
751 | - $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):''; |
|
752 | - $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:''; |
|
751 | + $meta['file'] = isset($trace[$i]['file']) ? $this->_escapeTraceFile($trace[$i]['file']) : ''; |
|
752 | + $meta['line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : ''; |
|
753 | 753 | break; |
754 | 754 | } |
755 | 755 | } |
756 | 756 | |
757 | 757 | } else |
758 | - if($Type==self::TABLE) { |
|
758 | + if ($Type == self::TABLE) { |
|
759 | 759 | |
760 | - if(isset($Object[0]) && is_string($Object[0])) { |
|
760 | + if (isset($Object[0]) && is_string($Object[0])) { |
|
761 | 761 | $Object[1] = $this->encodeTable($Object[1]); |
762 | 762 | } else { |
763 | 763 | $Object = $this->encodeTable($Object); |
@@ -766,44 +766,44 @@ discard block |
||
766 | 766 | $skipFinalObjectEncode = true; |
767 | 767 | |
768 | 768 | } else |
769 | - if($Type==self::GROUP_START) { |
|
769 | + if ($Type == self::GROUP_START) { |
|
770 | 770 | |
771 | - if(!$Label) { |
|
771 | + if (!$Label) { |
|
772 | 772 | throw $this->newException('You must specify a label for the group!'); |
773 | 773 | } |
774 | 774 | |
775 | 775 | } else { |
776 | - if($Type===null) { |
|
776 | + if ($Type === null) { |
|
777 | 777 | $Type = self::LOG; |
778 | 778 | } |
779 | 779 | } |
780 | 780 | |
781 | - if($this->options['includeLineNumbers']) { |
|
782 | - if(!isset($meta['file']) || !isset($meta['line'])) { |
|
781 | + if ($this->options['includeLineNumbers']) { |
|
782 | + if (!isset($meta['file']) || !isset($meta['line'])) { |
|
783 | 783 | |
784 | 784 | $trace = debug_backtrace(); |
785 | - for( $i=0 ; $trace && $i<sizeof($trace) ; $i++ ) { |
|
785 | + for ($i = 0; $trace && $i < sizeof($trace); $i++) { |
|
786 | 786 | |
787 | - if(isset($trace[$i]['class']) |
|
787 | + if (isset($trace[$i]['class']) |
|
788 | 788 | && isset($trace[$i]['file']) |
789 | - && ($trace[$i]['class']=='FirePHP' |
|
790 | - || $trace[$i]['class']=='FB') |
|
791 | - && (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' |
|
792 | - || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { |
|
789 | + && ($trace[$i]['class'] == 'FirePHP' |
|
790 | + || $trace[$i]['class'] == 'FB') |
|
791 | + && (substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php' |
|
792 | + || substr($this->_standardizePath($trace[$i]['file']), -29, 29) == 'FirePHPCore/FirePHP.class.php')) { |
|
793 | 793 | /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ |
794 | 794 | } else |
795 | - if(isset($trace[$i]['class']) |
|
796 | - && isset($trace[$i+1]['file']) |
|
797 | - && $trace[$i]['class']=='FirePHP' |
|
798 | - && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') { |
|
795 | + if (isset($trace[$i]['class']) |
|
796 | + && isset($trace[$i + 1]['file']) |
|
797 | + && $trace[$i]['class'] == 'FirePHP' |
|
798 | + && substr($this->_standardizePath($trace[$i + 1]['file']), -18, 18) == 'FirePHPCore/fb.php') { |
|
799 | 799 | /* Skip fb() */ |
800 | 800 | } else |
801 | - if(isset($trace[$i]['file']) |
|
802 | - && substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php') { |
|
801 | + if (isset($trace[$i]['file']) |
|
802 | + && substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php') { |
|
803 | 803 | /* Skip FB::fb() */ |
804 | 804 | } else { |
805 | - $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):''; |
|
806 | - $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:''; |
|
805 | + $meta['file'] = isset($trace[$i]['file']) ? $this->_escapeTraceFile($trace[$i]['file']) : ''; |
|
806 | + $meta['line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : ''; |
|
807 | 807 | break; |
808 | 808 | } |
809 | 809 | } |
@@ -814,49 +814,49 @@ discard block |
||
814 | 814 | unset($meta['line']); |
815 | 815 | } |
816 | 816 | |
817 | - $this->setHeader('X-Wf-Protocol-1','http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); |
|
818 | - $this->setHeader('X-Wf-1-Plugin-1','http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'.self::VERSION); |
|
817 | + $this->setHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); |
|
818 | + $this->setHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/' . self::VERSION); |
|
819 | 819 | |
820 | 820 | $structure_index = 1; |
821 | - if($Type==self::DUMP) { |
|
821 | + if ($Type == self::DUMP) { |
|
822 | 822 | $structure_index = 2; |
823 | - $this->setHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1'); |
|
823 | + $this->setHeader('X-Wf-1-Structure-2', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1'); |
|
824 | 824 | } else { |
825 | - $this->setHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); |
|
825 | + $this->setHeader('X-Wf-1-Structure-1', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); |
|
826 | 826 | } |
827 | 827 | |
828 | - if($Type==self::DUMP) { |
|
829 | - $msg = '{"'.$Label.'":'.$this->jsonEncode($Object, $skipFinalObjectEncode).'}'; |
|
828 | + if ($Type == self::DUMP) { |
|
829 | + $msg = '{"' . $Label . '":' . $this->jsonEncode($Object, $skipFinalObjectEncode) . '}'; |
|
830 | 830 | } else { |
831 | 831 | $msg_meta = $Options; |
832 | 832 | $msg_meta['Type'] = $Type; |
833 | - if($Label!==null) { |
|
833 | + if ($Label !== null) { |
|
834 | 834 | $msg_meta['Label'] = $Label; |
835 | 835 | } |
836 | - if(isset($meta['file']) && !isset($msg_meta['File'])) { |
|
836 | + if (isset($meta['file']) && !isset($msg_meta['File'])) { |
|
837 | 837 | $msg_meta['File'] = $meta['file']; |
838 | 838 | } |
839 | - if(isset($meta['line']) && !isset($msg_meta['Line'])) { |
|
839 | + if (isset($meta['line']) && !isset($msg_meta['Line'])) { |
|
840 | 840 | $msg_meta['Line'] = $meta['line']; |
841 | 841 | } |
842 | - $msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']'; |
|
842 | + $msg = '[' . $this->jsonEncode($msg_meta) . ',' . $this->jsonEncode($Object, $skipFinalObjectEncode) . ']'; |
|
843 | 843 | } |
844 | 844 | |
845 | - $parts = explode("\n",chunk_split($msg, 5000, "\n")); |
|
845 | + $parts = explode("\n", chunk_split($msg, 5000, "\n")); |
|
846 | 846 | |
847 | - for( $i=0 ; $i<count($parts) ; $i++) { |
|
847 | + for ($i = 0; $i < count($parts); $i++) { |
|
848 | 848 | |
849 | 849 | $part = $parts[$i]; |
850 | 850 | if ($part) { |
851 | 851 | |
852 | - if(count($parts)>2) { |
|
852 | + if (count($parts) > 2) { |
|
853 | 853 | // Message needs to be split into multiple parts |
854 | - $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex, |
|
855 | - (($i==0)?strlen($msg):'') |
|
854 | + $this->setHeader('X-Wf-1-' . $structure_index . '-' . '1-' . $this->messageIndex, |
|
855 | + (($i == 0) ? strlen($msg) : '') |
|
856 | 856 | . '|' . $part . '|' |
857 | - . (($i<count($parts)-2)?'\\':'')); |
|
857 | + . (($i < count($parts) - 2) ? '\\' : '')); |
|
858 | 858 | } else { |
859 | - $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex, |
|
859 | + $this->setHeader('X-Wf-1-' . $structure_index . '-' . '1-' . $this->messageIndex, |
|
860 | 860 | strlen($part) . '|' . $part . '|'); |
861 | 861 | } |
862 | 862 | |
@@ -868,7 +868,7 @@ discard block |
||
868 | 868 | } |
869 | 869 | } |
870 | 870 | |
871 | - $this->setHeader('X-Wf-1-Index',$this->messageIndex-1); |
|
871 | + $this->setHeader('X-Wf-1-Index', $this->messageIndex - 1); |
|
872 | 872 | |
873 | 873 | return true; |
874 | 874 | } |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | * @return string |
881 | 881 | */ |
882 | 882 | protected function _standardizePath($Path) { |
883 | - return preg_replace('/\\\\+/','/',$Path); |
|
883 | + return preg_replace('/\\\\+/', '/', $Path); |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
@@ -890,12 +890,12 @@ discard block |
||
890 | 890 | * @return array |
891 | 891 | */ |
892 | 892 | protected function _escapeTrace($Trace) { |
893 | - if(!$Trace) return $Trace; |
|
894 | - for( $i=0 ; $i<sizeof($Trace) ; $i++ ) { |
|
895 | - if(isset($Trace[$i]['file'])) { |
|
893 | + if (!$Trace) return $Trace; |
|
894 | + for ($i = 0; $i < sizeof($Trace); $i++) { |
|
895 | + if (isset($Trace[$i]['file'])) { |
|
896 | 896 | $Trace[$i]['file'] = $this->_escapeTraceFile($Trace[$i]['file']); |
897 | 897 | } |
898 | - if(isset($Trace[$i]['args'])) { |
|
898 | + if (isset($Trace[$i]['args'])) { |
|
899 | 899 | $Trace[$i]['args'] = $this->encodeObject($Trace[$i]['args']); |
900 | 900 | } |
901 | 901 | } |
@@ -910,10 +910,10 @@ discard block |
||
910 | 910 | */ |
911 | 911 | protected function _escapeTraceFile($File) { |
912 | 912 | /* Check if we have a windows filepath */ |
913 | - if(strpos($File,'\\')) { |
|
913 | + if (strpos($File, '\\')) { |
|
914 | 914 | /* First strip down to single \ */ |
915 | 915 | |
916 | - $file = preg_replace('/\\\\+/','\\',$File); |
|
916 | + $file = preg_replace('/\\\\+/', '\\', $File); |
|
917 | 917 | |
918 | 918 | return $file; |
919 | 919 | } |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | * @param string_type $Value |
928 | 928 | */ |
929 | 929 | protected function setHeader($Name, $Value) { |
930 | - return header($Name.': '.$Value); |
|
930 | + return header($Name . ': ' . $Value); |
|
931 | 931 | } |
932 | 932 | |
933 | 933 | /** |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | * @return string|false |
937 | 937 | */ |
938 | 938 | protected function getUserAgent() { |
939 | - if(!isset($_SERVER['HTTP_USER_AGENT'])) return false; |
|
939 | + if (!isset($_SERVER['HTTP_USER_AGENT'])) return false; |
|
940 | 940 | return $_SERVER['HTTP_USER_AGENT']; |
941 | 941 | } |
942 | 942 | |
@@ -958,14 +958,14 @@ discard block |
||
958 | 958 | * @param object $Object The object to be encoded |
959 | 959 | * @return string The JSON string |
960 | 960 | */ |
961 | - public function jsonEncode($Object, $skipObjectEncode=false) |
|
961 | + public function jsonEncode($Object, $skipObjectEncode = false) |
|
962 | 962 | { |
963 | - if(!$skipObjectEncode) { |
|
963 | + if (!$skipObjectEncode) { |
|
964 | 964 | $Object = $this->encodeObject($Object); |
965 | 965 | } |
966 | 966 | |
967 | - if(function_exists('json_encode') |
|
968 | - && $this->options['useNativeJsonEncode']!=false) { |
|
967 | + if (function_exists('json_encode') |
|
968 | + && $this->options['useNativeJsonEncode'] != false) { |
|
969 | 969 | |
970 | 970 | return json_encode($Object); |
971 | 971 | } else { |
@@ -981,15 +981,15 @@ discard block |
||
981 | 981 | */ |
982 | 982 | protected function encodeTable($Table) { |
983 | 983 | |
984 | - if(!$Table) return $Table; |
|
984 | + if (!$Table) return $Table; |
|
985 | 985 | |
986 | 986 | $new_table = array(); |
987 | - foreach($Table as $row) { |
|
987 | + foreach ($Table as $row) { |
|
988 | 988 | |
989 | - if(is_array($row)) { |
|
989 | + if (is_array($row)) { |
|
990 | 990 | $new_row = array(); |
991 | 991 | |
992 | - foreach($row as $item) { |
|
992 | + foreach ($row as $item) { |
|
993 | 993 | $new_row[] = $this->encodeObject($item); |
994 | 994 | } |
995 | 995 | |
@@ -1014,18 +1014,18 @@ discard block |
||
1014 | 1014 | |
1015 | 1015 | if (is_resource($Object)) { |
1016 | 1016 | |
1017 | - return '** '.(string)$Object.' **'; |
|
1017 | + return '** ' . (string) $Object . ' **'; |
|
1018 | 1018 | |
1019 | 1019 | } else |
1020 | 1020 | if (is_object($Object)) { |
1021 | 1021 | |
1022 | 1022 | if ($ObjectDepth > $this->options['maxObjectDepth']) { |
1023 | - return '** Max Object Depth ('.$this->options['maxObjectDepth'].') **'; |
|
1023 | + return '** Max Object Depth (' . $this->options['maxObjectDepth'] . ') **'; |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | foreach ($this->objectStack as $refVal) { |
1027 | 1027 | if ($refVal === $Object) { |
1028 | - return '** Recursion ('.get_class($Object).') **'; |
|
1028 | + return '** Recursion (' . get_class($Object) . ') **'; |
|
1029 | 1029 | } |
1030 | 1030 | } |
1031 | 1031 | array_push($this->objectStack, $Object); |
@@ -1034,45 +1034,45 @@ discard block |
||
1034 | 1034 | |
1035 | 1035 | $reflectionClass = new ReflectionClass($class); |
1036 | 1036 | $properties = array(); |
1037 | - foreach( $reflectionClass->getProperties() as $property) { |
|
1037 | + foreach ($reflectionClass->getProperties() as $property) { |
|
1038 | 1038 | $properties[$property->getName()] = $property; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | - $members = (array)$Object; |
|
1041 | + $members = (array) $Object; |
|
1042 | 1042 | |
1043 | - foreach( $properties as $raw_name => $property ) { |
|
1043 | + foreach ($properties as $raw_name => $property) { |
|
1044 | 1044 | |
1045 | 1045 | $name = $raw_name; |
1046 | - if($property->isStatic()) { |
|
1047 | - $name = 'static:'.$name; |
|
1046 | + if ($property->isStatic()) { |
|
1047 | + $name = 'static:' . $name; |
|
1048 | 1048 | } |
1049 | - if($property->isPublic()) { |
|
1050 | - $name = 'public:'.$name; |
|
1049 | + if ($property->isPublic()) { |
|
1050 | + $name = 'public:' . $name; |
|
1051 | 1051 | } else |
1052 | - if($property->isPrivate()) { |
|
1053 | - $name = 'private:'.$name; |
|
1054 | - $raw_name = "\0".$class."\0".$raw_name; |
|
1052 | + if ($property->isPrivate()) { |
|
1053 | + $name = 'private:' . $name; |
|
1054 | + $raw_name = "\0" . $class . "\0" . $raw_name; |
|
1055 | 1055 | } else |
1056 | - if($property->isProtected()) { |
|
1057 | - $name = 'protected:'.$name; |
|
1058 | - $raw_name = "\0".'*'."\0".$raw_name; |
|
1056 | + if ($property->isProtected()) { |
|
1057 | + $name = 'protected:' . $name; |
|
1058 | + $raw_name = "\0" . '*' . "\0" . $raw_name; |
|
1059 | 1059 | } |
1060 | 1060 | |
1061 | - if(!(isset($this->objectFilters[$class]) |
|
1061 | + if (!(isset($this->objectFilters[$class]) |
|
1062 | 1062 | && is_array($this->objectFilters[$class]) |
1063 | - && in_array($raw_name,$this->objectFilters[$class]))) { |
|
1063 | + && in_array($raw_name, $this->objectFilters[$class]))) { |
|
1064 | 1064 | |
1065 | - if(array_key_exists($raw_name,$members) |
|
1065 | + if (array_key_exists($raw_name, $members) |
|
1066 | 1066 | && !$property->isStatic()) { |
1067 | 1067 | |
1068 | 1068 | $return[$name] = $this->encodeObject($members[$raw_name], $ObjectDepth + 1, 1); |
1069 | 1069 | |
1070 | 1070 | } else { |
1071 | - if(method_exists($property,'setAccessible')) { |
|
1071 | + if (method_exists($property, 'setAccessible')) { |
|
1072 | 1072 | $property->setAccessible(true); |
1073 | 1073 | $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1); |
1074 | 1074 | } else |
1075 | - if($property->isPublic()) { |
|
1075 | + if ($property->isPublic()) { |
|
1076 | 1076 | $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1); |
1077 | 1077 | } else { |
1078 | 1078 | $return[$name] = '** Need PHP 5.3 to get value **'; |
@@ -1085,7 +1085,7 @@ discard block |
||
1085 | 1085 | |
1086 | 1086 | // Include all members that are not defined in the class |
1087 | 1087 | // but exist in the object |
1088 | - foreach( $members as $raw_name => $value ) { |
|
1088 | + foreach ($members as $raw_name => $value) { |
|
1089 | 1089 | |
1090 | 1090 | $name = $raw_name; |
1091 | 1091 | |
@@ -1094,12 +1094,12 @@ discard block |
||
1094 | 1094 | $name = $parts[2]; |
1095 | 1095 | } |
1096 | 1096 | |
1097 | - if(!isset($properties[$name])) { |
|
1098 | - $name = 'undeclared:'.$name; |
|
1097 | + if (!isset($properties[$name])) { |
|
1098 | + $name = 'undeclared:' . $name; |
|
1099 | 1099 | |
1100 | - if(!(isset($this->objectFilters[$class]) |
|
1100 | + if (!(isset($this->objectFilters[$class]) |
|
1101 | 1101 | && is_array($this->objectFilters[$class]) |
1102 | - && in_array($raw_name,$this->objectFilters[$class]))) { |
|
1102 | + && in_array($raw_name, $this->objectFilters[$class]))) { |
|
1103 | 1103 | |
1104 | 1104 | $return[$name] = $this->encodeObject($value, $ObjectDepth + 1, 1); |
1105 | 1105 | } else { |
@@ -1113,7 +1113,7 @@ discard block |
||
1113 | 1113 | } elseif (is_array($Object)) { |
1114 | 1114 | |
1115 | 1115 | if ($ArrayDepth > $this->options['maxArrayDepth']) { |
1116 | - return '** Max Array Depth ('.$this->options['maxArrayDepth'].') **'; |
|
1116 | + return '** Max Array Depth (' . $this->options['maxArrayDepth'] . ') **'; |
|
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | foreach ($Object as $key => $val) { |
@@ -1122,16 +1122,16 @@ discard block |
||
1122 | 1122 | // if the recursion is not reset here as it contains |
1123 | 1123 | // a reference to itself. This is the only way I have come up |
1124 | 1124 | // with to stop infinite recursion in this case. |
1125 | - if($key=='GLOBALS' |
|
1125 | + if ($key == 'GLOBALS' |
|
1126 | 1126 | && is_array($val) |
1127 | - && array_key_exists('GLOBALS',$val)) { |
|
1127 | + && array_key_exists('GLOBALS', $val)) { |
|
1128 | 1128 | $val['GLOBALS'] = '** Recursion (GLOBALS) **'; |
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | $return[$key] = $this->encodeObject($val, 1, $ArrayDepth + 1); |
1132 | 1132 | } |
1133 | 1133 | } else { |
1134 | - if(self::is_utf8($Object)) { |
|
1134 | + if (self::is_utf8($Object)) { |
|
1135 | 1135 | return $Object; |
1136 | 1136 | } else { |
1137 | 1137 | return utf8_encode($Object); |
@@ -1147,24 +1147,24 @@ discard block |
||
1147 | 1147 | * @return boolean |
1148 | 1148 | */ |
1149 | 1149 | protected static function is_utf8($str) { |
1150 | - $c=0; $b=0; |
|
1151 | - $bits=0; |
|
1152 | - $len=strlen($str); |
|
1153 | - for($i=0; $i<$len; $i++){ |
|
1154 | - $c=ord($str[$i]); |
|
1155 | - if($c > 128){ |
|
1156 | - if(($c >= 254)) return false; |
|
1157 | - elseif($c >= 252) $bits=6; |
|
1158 | - elseif($c >= 248) $bits=5; |
|
1159 | - elseif($c >= 240) $bits=4; |
|
1160 | - elseif($c >= 224) $bits=3; |
|
1161 | - elseif($c >= 192) $bits=2; |
|
1150 | + $c = 0; $b = 0; |
|
1151 | + $bits = 0; |
|
1152 | + $len = strlen($str); |
|
1153 | + for ($i = 0; $i < $len; $i++) { |
|
1154 | + $c = ord($str[$i]); |
|
1155 | + if ($c > 128) { |
|
1156 | + if (($c >= 254)) return false; |
|
1157 | + elseif ($c >= 252) $bits = 6; |
|
1158 | + elseif ($c >= 248) $bits = 5; |
|
1159 | + elseif ($c >= 240) $bits = 4; |
|
1160 | + elseif ($c >= 224) $bits = 3; |
|
1161 | + elseif ($c >= 192) $bits = 2; |
|
1162 | 1162 | else return false; |
1163 | - if(($i+$bits) > $len) return false; |
|
1164 | - while($bits > 1){ |
|
1163 | + if (($i + $bits) > $len) return false; |
|
1164 | + while ($bits > 1) { |
|
1165 | 1165 | $i++; |
1166 | - $b=ord($str[$i]); |
|
1167 | - if($b < 128 || $b > 191) return false; |
|
1166 | + $b = ord($str[$i]); |
|
1167 | + if ($b < 128 || $b > 191) return false; |
|
1168 | 1168 | $bits--; |
1169 | 1169 | } |
1170 | 1170 | } |
@@ -1249,11 +1249,11 @@ discard block |
||
1249 | 1249 | private function json_utf82utf16($utf8) |
1250 | 1250 | { |
1251 | 1251 | // oh please oh please oh please oh please oh please |
1252 | - if(function_exists('mb_convert_encoding')) { |
|
1252 | + if (function_exists('mb_convert_encoding')) { |
|
1253 | 1253 | return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
1254 | 1254 | } |
1255 | 1255 | |
1256 | - switch(strlen($utf8)) { |
|
1256 | + switch (strlen($utf8)) { |
|
1257 | 1257 | case 1: |
1258 | 1258 | // this case should never be reached, because we are in ASCII range |
1259 | 1259 | // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
@@ -1293,8 +1293,8 @@ discard block |
||
1293 | 1293 | private function json_encode($var) |
1294 | 1294 | { |
1295 | 1295 | |
1296 | - if(is_object($var)) { |
|
1297 | - if(in_array($var,$this->json_objectStack)) { |
|
1296 | + if (is_object($var)) { |
|
1297 | + if (in_array($var, $this->json_objectStack)) { |
|
1298 | 1298 | return '"** Recursion **"'; |
1299 | 1299 | } |
1300 | 1300 | } |
@@ -1347,7 +1347,7 @@ discard block |
||
1347 | 1347 | case $ord_var_c == 0x2F: |
1348 | 1348 | case $ord_var_c == 0x5C: |
1349 | 1349 | // double quote, slash, slosh |
1350 | - $ascii .= '\\'.$var{$c}; |
|
1350 | + $ascii .= '\\' . $var{$c}; |
|
1351 | 1351 | break; |
1352 | 1352 | |
1353 | 1353 | case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
@@ -1416,7 +1416,7 @@ discard block |
||
1416 | 1416 | } |
1417 | 1417 | } |
1418 | 1418 | |
1419 | - return '"'.$ascii.'"'; |
|
1419 | + return '"' . $ascii . '"'; |
|
1420 | 1420 | |
1421 | 1421 | case 'array': |
1422 | 1422 | /* |
@@ -1448,8 +1448,8 @@ discard block |
||
1448 | 1448 | |
1449 | 1449 | array_pop($this->json_objectStack); |
1450 | 1450 | |
1451 | - foreach($properties as $property) { |
|
1452 | - if($property instanceof Exception) { |
|
1451 | + foreach ($properties as $property) { |
|
1452 | + if ($property instanceof Exception) { |
|
1453 | 1453 | return $property; |
1454 | 1454 | } |
1455 | 1455 | } |
@@ -1464,8 +1464,8 @@ discard block |
||
1464 | 1464 | |
1465 | 1465 | array_pop($this->json_objectStack); |
1466 | 1466 | |
1467 | - foreach($elements as $element) { |
|
1468 | - if($element instanceof Exception) { |
|
1467 | + foreach ($elements as $element) { |
|
1468 | + if ($element instanceof Exception) { |
|
1469 | 1469 | return $element; |
1470 | 1470 | } |
1471 | 1471 | } |
@@ -1483,8 +1483,8 @@ discard block |
||
1483 | 1483 | |
1484 | 1484 | array_pop($this->json_objectStack); |
1485 | 1485 | |
1486 | - foreach($properties as $property) { |
|
1487 | - if($property instanceof Exception) { |
|
1486 | + foreach ($properties as $property) { |
|
1487 | + if ($property instanceof Exception) { |
|
1488 | 1488 | return $property; |
1489 | 1489 | } |
1490 | 1490 | } |
@@ -1511,15 +1511,15 @@ discard block |
||
1511 | 1511 | // if the recursion is not reset here as it contains |
1512 | 1512 | // a reference to itself. This is the only way I have come up |
1513 | 1513 | // with to stop infinite recursion in this case. |
1514 | - if($name=='GLOBALS' |
|
1514 | + if ($name == 'GLOBALS' |
|
1515 | 1515 | && is_array($value) |
1516 | - && array_key_exists('GLOBALS',$value)) { |
|
1516 | + && array_key_exists('GLOBALS', $value)) { |
|
1517 | 1517 | $value['GLOBALS'] = '** Recursion **'; |
1518 | 1518 | } |
1519 | 1519 | |
1520 | 1520 | $encoded_value = $this->json_encode($value); |
1521 | 1521 | |
1522 | - if($encoded_value instanceof Exception) { |
|
1522 | + if ($encoded_value instanceof Exception) { |
|
1523 | 1523 | return $encoded_value; |
1524 | 1524 | } |
1525 | 1525 |
@@ -718,7 +718,9 @@ discard block |
||
718 | 718 | if($Type==self::TRACE) { |
719 | 719 | |
720 | 720 | $trace = debug_backtrace(); |
721 | - if(!$trace) return false; |
|
721 | + if(!$trace) { |
|
722 | + return false; |
|
723 | + } |
|
722 | 724 | for( $i=0 ; $i<sizeof($trace) ; $i++ ) { |
723 | 725 | |
724 | 726 | if(isset($trace[$i]['class']) |
@@ -890,7 +892,9 @@ discard block |
||
890 | 892 | * @return array |
891 | 893 | */ |
892 | 894 | protected function _escapeTrace($Trace) { |
893 | - if(!$Trace) return $Trace; |
|
895 | + if(!$Trace) { |
|
896 | + return $Trace; |
|
897 | + } |
|
894 | 898 | for( $i=0 ; $i<sizeof($Trace) ; $i++ ) { |
895 | 899 | if(isset($Trace[$i]['file'])) { |
896 | 900 | $Trace[$i]['file'] = $this->_escapeTraceFile($Trace[$i]['file']); |
@@ -936,7 +940,9 @@ discard block |
||
936 | 940 | * @return string|false |
937 | 941 | */ |
938 | 942 | protected function getUserAgent() { |
939 | - if(!isset($_SERVER['HTTP_USER_AGENT'])) return false; |
|
943 | + if(!isset($_SERVER['HTTP_USER_AGENT'])) { |
|
944 | + return false; |
|
945 | + } |
|
940 | 946 | return $_SERVER['HTTP_USER_AGENT']; |
941 | 947 | } |
942 | 948 | |
@@ -981,7 +987,9 @@ discard block |
||
981 | 987 | */ |
982 | 988 | protected function encodeTable($Table) { |
983 | 989 | |
984 | - if(!$Table) return $Table; |
|
990 | + if(!$Table) { |
|
991 | + return $Table; |
|
992 | + } |
|
985 | 993 | |
986 | 994 | $new_table = array(); |
987 | 995 | foreach($Table as $row) { |
@@ -1153,18 +1161,30 @@ discard block |
||
1153 | 1161 | for($i=0; $i<$len; $i++){ |
1154 | 1162 | $c=ord($str[$i]); |
1155 | 1163 | if($c > 128){ |
1156 | - if(($c >= 254)) return false; |
|
1157 | - elseif($c >= 252) $bits=6; |
|
1158 | - elseif($c >= 248) $bits=5; |
|
1159 | - elseif($c >= 240) $bits=4; |
|
1160 | - elseif($c >= 224) $bits=3; |
|
1161 | - elseif($c >= 192) $bits=2; |
|
1162 | - else return false; |
|
1163 | - if(($i+$bits) > $len) return false; |
|
1164 | + if(($c >= 254)) { |
|
1165 | + return false; |
|
1166 | + } elseif($c >= 252) { |
|
1167 | + $bits=6; |
|
1168 | + } elseif($c >= 248) { |
|
1169 | + $bits=5; |
|
1170 | + } elseif($c >= 240) { |
|
1171 | + $bits=4; |
|
1172 | + } elseif($c >= 224) { |
|
1173 | + $bits=3; |
|
1174 | + } elseif($c >= 192) { |
|
1175 | + $bits=2; |
|
1176 | + } else { |
|
1177 | + return false; |
|
1178 | + } |
|
1179 | + if(($i+$bits) > $len) { |
|
1180 | + return false; |
|
1181 | + } |
|
1164 | 1182 | while($bits > 1){ |
1165 | 1183 | $i++; |
1166 | 1184 | $b=ord($str[$i]); |
1167 | - if($b < 128 || $b > 191) return false; |
|
1185 | + if($b < 128 || $b > 191) { |
|
1186 | + return false; |
|
1187 | + } |
|
1168 | 1188 | $bits--; |
1169 | 1189 | } |
1170 | 1190 | } |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | * @var array |
193 | 193 | */ |
194 | 194 | protected $options = array('maxObjectDepth' => 10, |
195 | - 'maxArrayDepth' => 20, |
|
196 | - 'useNativeJsonEncode' => true, |
|
197 | - 'includeLineNumbers' => true); |
|
195 | + 'maxArrayDepth' => 20, |
|
196 | + 'useNativeJsonEncode' => true, |
|
197 | + 'includeLineNumbers' => true); |
|
198 | 198 | |
199 | 199 | /** |
200 | 200 | * Filters used to exclude object members when encoding |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @return array |
230 | 230 | */ |
231 | 231 | public function __sleep() { |
232 | - return array('options','objectFilters','enabled'); |
|
232 | + return array('options','objectFilters','enabled'); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -239,10 +239,10 @@ discard block |
||
239 | 239 | * @return FirePHP |
240 | 240 | */ |
241 | 241 | public static function getInstance($AutoCreate=false) { |
242 | - if($AutoCreate===true && !self::$instance) { |
|
243 | - self::init(); |
|
244 | - } |
|
245 | - return self::$instance; |
|
242 | + if($AutoCreate===true && !self::$instance) { |
|
243 | + self::init(); |
|
244 | + } |
|
245 | + return self::$instance; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @return FirePHP |
252 | 252 | */ |
253 | 253 | public static function init() { |
254 | - return self::$instance = new self(); |
|
254 | + return self::$instance = new self(); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * @return void |
262 | 262 | */ |
263 | 263 | public function setEnabled($Enabled) { |
264 | - $this->enabled = $Enabled; |
|
264 | + $this->enabled = $Enabled; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @return boolean TRUE if enabled |
271 | 271 | */ |
272 | 272 | public function getEnabled() { |
273 | - return $this->enabled; |
|
273 | + return $this->enabled; |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @return void |
284 | 284 | */ |
285 | 285 | public function setObjectFilter($Class, $Filter) { |
286 | - $this->objectFilters[$Class] = $Filter; |
|
286 | + $this->objectFilters[$Class] = $Filter; |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return void |
300 | 300 | */ |
301 | 301 | public function setOptions($Options) { |
302 | - $this->options = array_merge($this->options,$Options); |
|
302 | + $this->options = array_merge($this->options,$Options); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @return array The currently set options |
309 | 309 | */ |
310 | 310 | public function getOptions() { |
311 | - return $this->options; |
|
311 | + return $this->options; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | */ |
321 | 321 | public function registerErrorHandler($throwErrorExceptions=true) |
322 | 322 | { |
323 | - //NOTE: The following errors will not be caught by this error handler: |
|
324 | - // E_ERROR, E_PARSE, E_CORE_ERROR, |
|
325 | - // E_CORE_WARNING, E_COMPILE_ERROR, |
|
326 | - // E_COMPILE_WARNING, E_STRICT |
|
323 | + //NOTE: The following errors will not be caught by this error handler: |
|
324 | + // E_ERROR, E_PARSE, E_CORE_ERROR, |
|
325 | + // E_CORE_WARNING, E_COMPILE_ERROR, |
|
326 | + // E_COMPILE_WARNING, E_STRICT |
|
327 | 327 | |
328 | - $this->throwErrorExceptions = $throwErrorExceptions; |
|
328 | + $this->throwErrorExceptions = $throwErrorExceptions; |
|
329 | 329 | |
330 | - return set_error_handler(array($this,'errorHandler')); |
|
330 | + return set_error_handler(array($this,'errorHandler')); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -343,20 +343,20 @@ discard block |
||
343 | 343 | */ |
344 | 344 | public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) |
345 | 345 | { |
346 | - // Don't throw exception if error reporting is switched off |
|
347 | - if (error_reporting() == 0) { |
|
348 | - return; |
|
349 | - } |
|
350 | - // Only throw exceptions for errors we are asking for |
|
351 | - if (error_reporting() & $errno) { |
|
352 | - |
|
353 | - $exception = new ErrorException($errstr, 0, $errno, $errfile, $errline); |
|
354 | - if($this->throwErrorExceptions) { |
|
355 | - throw $exception; |
|
356 | - } else { |
|
357 | - $this->fb($exception); |
|
358 | - } |
|
359 | - } |
|
346 | + // Don't throw exception if error reporting is switched off |
|
347 | + if (error_reporting() == 0) { |
|
348 | + return; |
|
349 | + } |
|
350 | + // Only throw exceptions for errors we are asking for |
|
351 | + if (error_reporting() & $errno) { |
|
352 | + |
|
353 | + $exception = new ErrorException($errstr, 0, $errno, $errfile, $errline); |
|
354 | + if($this->throwErrorExceptions) { |
|
355 | + throw $exception; |
|
356 | + } else { |
|
357 | + $this->fb($exception); |
|
358 | + } |
|
359 | + } |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function registerExceptionHandler() |
370 | 370 | { |
371 | - return set_exception_handler(array($this,'exceptionHandler')); |
|
371 | + return set_exception_handler(array($this,'exceptionHandler')); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -381,13 +381,13 @@ discard block |
||
381 | 381 | */ |
382 | 382 | function exceptionHandler($Exception) { |
383 | 383 | |
384 | - $this->inExceptionHandler = true; |
|
384 | + $this->inExceptionHandler = true; |
|
385 | 385 | |
386 | - header('HTTP/1.1 500 Internal Server Error'); |
|
386 | + header('HTTP/1.1 500 Internal Server Error'); |
|
387 | 387 | |
388 | - $this->fb($Exception); |
|
388 | + $this->fb($Exception); |
|
389 | 389 | |
390 | - $this->inExceptionHandler = false; |
|
390 | + $this->inExceptionHandler = false; |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -399,14 +399,14 @@ discard block |
||
399 | 399 | */ |
400 | 400 | public function registerAssertionHandler($convertAssertionErrorsToExceptions=true, $throwAssertionExceptions=false) |
401 | 401 | { |
402 | - $this->convertAssertionErrorsToExceptions = $convertAssertionErrorsToExceptions; |
|
403 | - $this->throwAssertionExceptions = $throwAssertionExceptions; |
|
402 | + $this->convertAssertionErrorsToExceptions = $convertAssertionErrorsToExceptions; |
|
403 | + $this->throwAssertionExceptions = $throwAssertionExceptions; |
|
404 | 404 | |
405 | - if($throwAssertionExceptions && !$convertAssertionErrorsToExceptions) { |
|
406 | - throw $this->newException('Cannot throw assertion exceptions as assertion errors are not being converted to exceptions!'); |
|
407 | - } |
|
405 | + if($throwAssertionExceptions && !$convertAssertionErrorsToExceptions) { |
|
406 | + throw $this->newException('Cannot throw assertion exceptions as assertion errors are not being converted to exceptions!'); |
|
407 | + } |
|
408 | 408 | |
409 | - return assert_options(ASSERT_CALLBACK, array($this, 'assertionHandler')); |
|
409 | + return assert_options(ASSERT_CALLBACK, array($this, 'assertionHandler')); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** |
@@ -421,21 +421,21 @@ discard block |
||
421 | 421 | public function assertionHandler($file, $line, $code) |
422 | 422 | { |
423 | 423 | |
424 | - if($this->convertAssertionErrorsToExceptions) { |
|
424 | + if($this->convertAssertionErrorsToExceptions) { |
|
425 | 425 | |
426 | - $exception = new ErrorException('Assertion Failed - Code[ '.$code.' ]', 0, null, $file, $line); |
|
426 | + $exception = new ErrorException('Assertion Failed - Code[ '.$code.' ]', 0, null, $file, $line); |
|
427 | 427 | |
428 | - if($this->throwAssertionExceptions) { |
|
429 | - throw $exception; |
|
430 | - } else { |
|
431 | - $this->fb($exception); |
|
432 | - } |
|
428 | + if($this->throwAssertionExceptions) { |
|
429 | + throw $exception; |
|
430 | + } else { |
|
431 | + $this->fb($exception); |
|
432 | + } |
|
433 | 433 | |
434 | - } else { |
|
434 | + } else { |
|
435 | 435 | |
436 | - $this->fb($code, 'Assertion Failed', FirePHP::ERROR, array('File'=>$file,'Line'=>$line)); |
|
436 | + $this->fb($code, 'Assertion Failed', FirePHP::ERROR, array('File'=>$file,'Line'=>$line)); |
|
437 | 437 | |
438 | - } |
|
438 | + } |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | */ |
446 | 446 | public function setProcessorUrl($URL) |
447 | 447 | { |
448 | - $this->setHeader('X-FirePHP-ProcessorURL', $URL); |
|
448 | + $this->setHeader('X-FirePHP-ProcessorURL', $URL); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | */ |
456 | 456 | public function setRendererUrl($URL) |
457 | 457 | { |
458 | - $this->setHeader('X-FirePHP-RendererURL', $URL); |
|
458 | + $this->setHeader('X-FirePHP-RendererURL', $URL); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /** |
@@ -472,20 +472,20 @@ discard block |
||
472 | 472 | */ |
473 | 473 | public function group($Name, $Options=null) { |
474 | 474 | |
475 | - if(!$Name) { |
|
476 | - throw $this->newException('You must specify a label for the group!'); |
|
477 | - } |
|
475 | + if(!$Name) { |
|
476 | + throw $this->newException('You must specify a label for the group!'); |
|
477 | + } |
|
478 | 478 | |
479 | - if($Options) { |
|
480 | - if(!is_array($Options)) { |
|
481 | - throw $this->newException('Options must be defined as an array!'); |
|
482 | - } |
|
483 | - if(array_key_exists('Collapsed', $Options)) { |
|
484 | - $Options['Collapsed'] = ($Options['Collapsed'])?'true':'false'; |
|
485 | - } |
|
486 | - } |
|
479 | + if($Options) { |
|
480 | + if(!is_array($Options)) { |
|
481 | + throw $this->newException('Options must be defined as an array!'); |
|
482 | + } |
|
483 | + if(array_key_exists('Collapsed', $Options)) { |
|
484 | + $Options['Collapsed'] = ($Options['Collapsed'])?'true':'false'; |
|
485 | + } |
|
486 | + } |
|
487 | 487 | |
488 | - return $this->fb(null, $Name, FirePHP::GROUP_START, $Options); |
|
488 | + return $this->fb(null, $Name, FirePHP::GROUP_START, $Options); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | /** |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | * @throws Exception |
496 | 496 | */ |
497 | 497 | public function groupEnd() { |
498 | - return $this->fb(null, null, FirePHP::GROUP_END); |
|
498 | + return $this->fb(null, null, FirePHP::GROUP_END); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | * @throws Exception |
509 | 509 | */ |
510 | 510 | public function log($Object, $Label=null) { |
511 | - return $this->fb($Object, $Label, FirePHP::LOG); |
|
511 | + return $this->fb($Object, $Label, FirePHP::LOG); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | /** |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | * @throws Exception |
522 | 522 | */ |
523 | 523 | public function info($Object, $Label=null) { |
524 | - return $this->fb($Object, $Label, FirePHP::INFO); |
|
524 | + return $this->fb($Object, $Label, FirePHP::INFO); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | * @throws Exception |
535 | 535 | */ |
536 | 536 | public function warn($Object, $Label=null) { |
537 | - return $this->fb($Object, $Label, FirePHP::WARN); |
|
537 | + return $this->fb($Object, $Label, FirePHP::WARN); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | * @throws Exception |
548 | 548 | */ |
549 | 549 | public function error($Object, $Label=null) { |
550 | - return $this->fb($Object, $Label, FirePHP::ERROR); |
|
550 | + return $this->fb($Object, $Label, FirePHP::ERROR); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * @throws Exception |
561 | 561 | */ |
562 | 562 | public function dump($Key, $Variable) { |
563 | - return $this->fb($Variable, $Key, FirePHP::DUMP); |
|
563 | + return $this->fb($Variable, $Key, FirePHP::DUMP); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | * @throws Exception |
573 | 573 | */ |
574 | 574 | public function trace($Label) { |
575 | - return $this->fb($Label, FirePHP::TRACE); |
|
575 | + return $this->fb($Label, FirePHP::TRACE); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | /** |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | * @throws Exception |
586 | 586 | */ |
587 | 587 | public function table($Label, $Table) { |
588 | - return $this->fb($Table, $Label, FirePHP::TABLE); |
|
588 | + return $this->fb($Table, $Label, FirePHP::TABLE); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | /** |
@@ -594,12 +594,12 @@ discard block |
||
594 | 594 | * @return boolean |
595 | 595 | */ |
596 | 596 | public function detectClientExtension() { |
597 | - /* Check if FirePHP is installed on client */ |
|
598 | - if(!@preg_match_all('/\sFirePHP\/([\.|\d]*)\s?/si',$this->getUserAgent(),$m) || |
|
599 | - !version_compare($m[1][0],'0.0.6','>=')) { |
|
600 | - return false; |
|
601 | - } |
|
602 | - return true; |
|
597 | + /* Check if FirePHP is installed on client */ |
|
598 | + if(!@preg_match_all('/\sFirePHP\/([\.|\d]*)\s?/si',$this->getUserAgent(),$m) || |
|
599 | + !version_compare($m[1][0],'0.0.6','>=')) { |
|
600 | + return false; |
|
601 | + } |
|
602 | + return true; |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
@@ -612,265 +612,265 @@ discard block |
||
612 | 612 | */ |
613 | 613 | public function fb($Object) { |
614 | 614 | |
615 | - if(!$this->enabled) { |
|
616 | - return false; |
|
617 | - } |
|
615 | + if(!$this->enabled) { |
|
616 | + return false; |
|
617 | + } |
|
618 | 618 | |
619 | - if (headers_sent($filename, $linenum)) { |
|
620 | - // If we are logging from within the exception handler we cannot throw another exception |
|
621 | - if($this->inExceptionHandler) { |
|
622 | - // Simply echo the error out to the page |
|
623 | - echo '<div style="border: 2px solid red; font-family: Arial; font-size: 12px; background-color: lightgray; padding: 5px;"><span style="color: red; font-weight: bold;">FirePHP ERROR:</span> Headers already sent in <b>'.$filename.'</b> on line <b>'.$linenum.'</b>. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.</div>'; |
|
624 | - } else { |
|
625 | - throw $this->newException('Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.'); |
|
626 | - } |
|
627 | - } |
|
619 | + if (headers_sent($filename, $linenum)) { |
|
620 | + // If we are logging from within the exception handler we cannot throw another exception |
|
621 | + if($this->inExceptionHandler) { |
|
622 | + // Simply echo the error out to the page |
|
623 | + echo '<div style="border: 2px solid red; font-family: Arial; font-size: 12px; background-color: lightgray; padding: 5px;"><span style="color: red; font-weight: bold;">FirePHP ERROR:</span> Headers already sent in <b>'.$filename.'</b> on line <b>'.$linenum.'</b>. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.</div>'; |
|
624 | + } else { |
|
625 | + throw $this->newException('Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.'); |
|
626 | + } |
|
627 | + } |
|
628 | 628 | |
629 | - $Type = null; |
|
630 | - $Label = null; |
|
631 | - $Options = array(); |
|
629 | + $Type = null; |
|
630 | + $Label = null; |
|
631 | + $Options = array(); |
|
632 | 632 | |
633 | - if(func_num_args()==1) { |
|
634 | - } else |
|
635 | - if(func_num_args()==2) { |
|
636 | - switch(func_get_arg(1)) { |
|
637 | - case self::LOG: |
|
638 | - case self::INFO: |
|
639 | - case self::WARN: |
|
640 | - case self::ERROR: |
|
641 | - case self::DUMP: |
|
642 | - case self::TRACE: |
|
643 | - case self::EXCEPTION: |
|
644 | - case self::TABLE: |
|
645 | - case self::GROUP_START: |
|
646 | - case self::GROUP_END: |
|
647 | - $Type = func_get_arg(1); |
|
648 | - break; |
|
649 | - default: |
|
650 | - $Label = func_get_arg(1); |
|
651 | - break; |
|
652 | - } |
|
653 | - } else |
|
654 | - if(func_num_args()==3) { |
|
655 | - $Type = func_get_arg(2); |
|
656 | - $Label = func_get_arg(1); |
|
657 | - } else |
|
658 | - if(func_num_args()==4) { |
|
659 | - $Type = func_get_arg(2); |
|
660 | - $Label = func_get_arg(1); |
|
661 | - $Options = func_get_arg(3); |
|
662 | - } else { |
|
663 | - throw $this->newException('Wrong number of arguments to fb() function!'); |
|
664 | - } |
|
633 | + if(func_num_args()==1) { |
|
634 | + } else |
|
635 | + if(func_num_args()==2) { |
|
636 | + switch(func_get_arg(1)) { |
|
637 | + case self::LOG: |
|
638 | + case self::INFO: |
|
639 | + case self::WARN: |
|
640 | + case self::ERROR: |
|
641 | + case self::DUMP: |
|
642 | + case self::TRACE: |
|
643 | + case self::EXCEPTION: |
|
644 | + case self::TABLE: |
|
645 | + case self::GROUP_START: |
|
646 | + case self::GROUP_END: |
|
647 | + $Type = func_get_arg(1); |
|
648 | + break; |
|
649 | + default: |
|
650 | + $Label = func_get_arg(1); |
|
651 | + break; |
|
652 | + } |
|
653 | + } else |
|
654 | + if(func_num_args()==3) { |
|
655 | + $Type = func_get_arg(2); |
|
656 | + $Label = func_get_arg(1); |
|
657 | + } else |
|
658 | + if(func_num_args()==4) { |
|
659 | + $Type = func_get_arg(2); |
|
660 | + $Label = func_get_arg(1); |
|
661 | + $Options = func_get_arg(3); |
|
662 | + } else { |
|
663 | + throw $this->newException('Wrong number of arguments to fb() function!'); |
|
664 | + } |
|
665 | 665 | |
666 | 666 | |
667 | - if(!$this->detectClientExtension()) { |
|
668 | - return false; |
|
669 | - } |
|
667 | + if(!$this->detectClientExtension()) { |
|
668 | + return false; |
|
669 | + } |
|
670 | 670 | |
671 | - $meta = array(); |
|
672 | - $skipFinalObjectEncode = false; |
|
671 | + $meta = array(); |
|
672 | + $skipFinalObjectEncode = false; |
|
673 | 673 | |
674 | - if($Object instanceof Exception) { |
|
674 | + if($Object instanceof Exception) { |
|
675 | 675 | |
676 | - $meta['file'] = $this->_escapeTraceFile($Object->getFile()); |
|
677 | - $meta['line'] = $Object->getLine(); |
|
676 | + $meta['file'] = $this->_escapeTraceFile($Object->getFile()); |
|
677 | + $meta['line'] = $Object->getLine(); |
|
678 | 678 | |
679 | - $trace = $Object->getTrace(); |
|
680 | - if($Object instanceof ErrorException |
|
681 | - && isset($trace[0]['function']) |
|
682 | - && $trace[0]['function']=='errorHandler' |
|
683 | - && isset($trace[0]['class']) |
|
684 | - && $trace[0]['class']=='FirePHP') { |
|
679 | + $trace = $Object->getTrace(); |
|
680 | + if($Object instanceof ErrorException |
|
681 | + && isset($trace[0]['function']) |
|
682 | + && $trace[0]['function']=='errorHandler' |
|
683 | + && isset($trace[0]['class']) |
|
684 | + && $trace[0]['class']=='FirePHP') { |
|
685 | 685 | |
686 | - $severity = false; |
|
687 | - switch($Object->getSeverity()) { |
|
688 | - case E_WARNING: $severity = 'E_WARNING'; break; |
|
689 | - case E_NOTICE: $severity = 'E_NOTICE'; break; |
|
690 | - case E_USER_ERROR: $severity = 'E_USER_ERROR'; break; |
|
691 | - case E_USER_WARNING: $severity = 'E_USER_WARNING'; break; |
|
692 | - case E_USER_NOTICE: $severity = 'E_USER_NOTICE'; break; |
|
693 | - case E_STRICT: $severity = 'E_STRICT'; break; |
|
694 | - case E_RECOVERABLE_ERROR: $severity = 'E_RECOVERABLE_ERROR'; break; |
|
695 | - case E_DEPRECATED: $severity = 'E_DEPRECATED'; break; |
|
696 | - case E_USER_DEPRECATED: $severity = 'E_USER_DEPRECATED'; break; |
|
697 | - } |
|
686 | + $severity = false; |
|
687 | + switch($Object->getSeverity()) { |
|
688 | + case E_WARNING: $severity = 'E_WARNING'; break; |
|
689 | + case E_NOTICE: $severity = 'E_NOTICE'; break; |
|
690 | + case E_USER_ERROR: $severity = 'E_USER_ERROR'; break; |
|
691 | + case E_USER_WARNING: $severity = 'E_USER_WARNING'; break; |
|
692 | + case E_USER_NOTICE: $severity = 'E_USER_NOTICE'; break; |
|
693 | + case E_STRICT: $severity = 'E_STRICT'; break; |
|
694 | + case E_RECOVERABLE_ERROR: $severity = 'E_RECOVERABLE_ERROR'; break; |
|
695 | + case E_DEPRECATED: $severity = 'E_DEPRECATED'; break; |
|
696 | + case E_USER_DEPRECATED: $severity = 'E_USER_DEPRECATED'; break; |
|
697 | + } |
|
698 | 698 | |
699 | - $Object = array('Class'=>get_class($Object), |
|
700 | - 'Message'=>$severity.': '.$Object->getMessage(), |
|
701 | - 'File'=>$this->_escapeTraceFile($Object->getFile()), |
|
702 | - 'Line'=>$Object->getLine(), |
|
703 | - 'Type'=>'trigger', |
|
704 | - 'Trace'=>$this->_escapeTrace(array_splice($trace,2))); |
|
705 | - $skipFinalObjectEncode = true; |
|
706 | - } else { |
|
707 | - $Object = array('Class'=>get_class($Object), |
|
708 | - 'Message'=>$Object->getMessage(), |
|
709 | - 'File'=>$this->_escapeTraceFile($Object->getFile()), |
|
710 | - 'Line'=>$Object->getLine(), |
|
711 | - 'Type'=>'throw', |
|
712 | - 'Trace'=>$this->_escapeTrace($trace)); |
|
713 | - $skipFinalObjectEncode = true; |
|
714 | - } |
|
715 | - $Type = self::EXCEPTION; |
|
699 | + $Object = array('Class'=>get_class($Object), |
|
700 | + 'Message'=>$severity.': '.$Object->getMessage(), |
|
701 | + 'File'=>$this->_escapeTraceFile($Object->getFile()), |
|
702 | + 'Line'=>$Object->getLine(), |
|
703 | + 'Type'=>'trigger', |
|
704 | + 'Trace'=>$this->_escapeTrace(array_splice($trace,2))); |
|
705 | + $skipFinalObjectEncode = true; |
|
706 | + } else { |
|
707 | + $Object = array('Class'=>get_class($Object), |
|
708 | + 'Message'=>$Object->getMessage(), |
|
709 | + 'File'=>$this->_escapeTraceFile($Object->getFile()), |
|
710 | + 'Line'=>$Object->getLine(), |
|
711 | + 'Type'=>'throw', |
|
712 | + 'Trace'=>$this->_escapeTrace($trace)); |
|
713 | + $skipFinalObjectEncode = true; |
|
714 | + } |
|
715 | + $Type = self::EXCEPTION; |
|
716 | 716 | |
717 | - } else |
|
718 | - if($Type==self::TRACE) { |
|
717 | + } else |
|
718 | + if($Type==self::TRACE) { |
|
719 | 719 | |
720 | - $trace = debug_backtrace(); |
|
721 | - if(!$trace) return false; |
|
722 | - for( $i=0 ; $i<sizeof($trace) ; $i++ ) { |
|
723 | - |
|
724 | - if(isset($trace[$i]['class']) |
|
725 | - && isset($trace[$i]['file']) |
|
726 | - && ($trace[$i]['class']=='FirePHP' |
|
727 | - || $trace[$i]['class']=='FB') |
|
728 | - && (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' |
|
729 | - || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { |
|
730 | - /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ |
|
731 | - } else |
|
732 | - if(isset($trace[$i]['class']) |
|
733 | - && isset($trace[$i+1]['file']) |
|
734 | - && $trace[$i]['class']=='FirePHP' |
|
735 | - && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') { |
|
736 | - /* Skip fb() */ |
|
737 | - } else |
|
738 | - if($trace[$i]['function']=='fb' |
|
739 | - || $trace[$i]['function']=='trace' |
|
740 | - || $trace[$i]['function']=='send') { |
|
741 | - $Object = array('Class'=>isset($trace[$i]['class'])?$trace[$i]['class']:'', |
|
742 | - 'Type'=>isset($trace[$i]['type'])?$trace[$i]['type']:'', |
|
743 | - 'Function'=>isset($trace[$i]['function'])?$trace[$i]['function']:'', |
|
744 | - 'Message'=>$trace[$i]['args'][0], |
|
745 | - 'File'=>isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'', |
|
746 | - 'Line'=>isset($trace[$i]['line'])?$trace[$i]['line']:'', |
|
747 | - 'Args'=>isset($trace[$i]['args'])?$this->encodeObject($trace[$i]['args']):'', |
|
748 | - 'Trace'=>$this->_escapeTrace(array_splice($trace,$i+1))); |
|
749 | - |
|
750 | - $skipFinalObjectEncode = true; |
|
751 | - $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):''; |
|
752 | - $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:''; |
|
753 | - break; |
|
754 | - } |
|
755 | - } |
|
756 | - |
|
757 | - } else |
|
758 | - if($Type==self::TABLE) { |
|
720 | + $trace = debug_backtrace(); |
|
721 | + if(!$trace) return false; |
|
722 | + for( $i=0 ; $i<sizeof($trace) ; $i++ ) { |
|
723 | + |
|
724 | + if(isset($trace[$i]['class']) |
|
725 | + && isset($trace[$i]['file']) |
|
726 | + && ($trace[$i]['class']=='FirePHP' |
|
727 | + || $trace[$i]['class']=='FB') |
|
728 | + && (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' |
|
729 | + || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { |
|
730 | + /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ |
|
731 | + } else |
|
732 | + if(isset($trace[$i]['class']) |
|
733 | + && isset($trace[$i+1]['file']) |
|
734 | + && $trace[$i]['class']=='FirePHP' |
|
735 | + && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') { |
|
736 | + /* Skip fb() */ |
|
737 | + } else |
|
738 | + if($trace[$i]['function']=='fb' |
|
739 | + || $trace[$i]['function']=='trace' |
|
740 | + || $trace[$i]['function']=='send') { |
|
741 | + $Object = array('Class'=>isset($trace[$i]['class'])?$trace[$i]['class']:'', |
|
742 | + 'Type'=>isset($trace[$i]['type'])?$trace[$i]['type']:'', |
|
743 | + 'Function'=>isset($trace[$i]['function'])?$trace[$i]['function']:'', |
|
744 | + 'Message'=>$trace[$i]['args'][0], |
|
745 | + 'File'=>isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'', |
|
746 | + 'Line'=>isset($trace[$i]['line'])?$trace[$i]['line']:'', |
|
747 | + 'Args'=>isset($trace[$i]['args'])?$this->encodeObject($trace[$i]['args']):'', |
|
748 | + 'Trace'=>$this->_escapeTrace(array_splice($trace,$i+1))); |
|
749 | + |
|
750 | + $skipFinalObjectEncode = true; |
|
751 | + $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):''; |
|
752 | + $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:''; |
|
753 | + break; |
|
754 | + } |
|
755 | + } |
|
756 | + |
|
757 | + } else |
|
758 | + if($Type==self::TABLE) { |
|
759 | 759 | |
760 | - if(isset($Object[0]) && is_string($Object[0])) { |
|
761 | - $Object[1] = $this->encodeTable($Object[1]); |
|
762 | - } else { |
|
763 | - $Object = $this->encodeTable($Object); |
|
764 | - } |
|
760 | + if(isset($Object[0]) && is_string($Object[0])) { |
|
761 | + $Object[1] = $this->encodeTable($Object[1]); |
|
762 | + } else { |
|
763 | + $Object = $this->encodeTable($Object); |
|
764 | + } |
|
765 | 765 | |
766 | - $skipFinalObjectEncode = true; |
|
766 | + $skipFinalObjectEncode = true; |
|
767 | 767 | |
768 | - } else |
|
769 | - if($Type==self::GROUP_START) { |
|
768 | + } else |
|
769 | + if($Type==self::GROUP_START) { |
|
770 | 770 | |
771 | - if(!$Label) { |
|
772 | - throw $this->newException('You must specify a label for the group!'); |
|
773 | - } |
|
771 | + if(!$Label) { |
|
772 | + throw $this->newException('You must specify a label for the group!'); |
|
773 | + } |
|
774 | 774 | |
775 | - } else { |
|
776 | - if($Type===null) { |
|
777 | - $Type = self::LOG; |
|
778 | - } |
|
779 | - } |
|
775 | + } else { |
|
776 | + if($Type===null) { |
|
777 | + $Type = self::LOG; |
|
778 | + } |
|
779 | + } |
|
780 | 780 | |
781 | - if($this->options['includeLineNumbers']) { |
|
782 | - if(!isset($meta['file']) || !isset($meta['line'])) { |
|
781 | + if($this->options['includeLineNumbers']) { |
|
782 | + if(!isset($meta['file']) || !isset($meta['line'])) { |
|
783 | 783 | |
784 | - $trace = debug_backtrace(); |
|
785 | - for( $i=0 ; $trace && $i<sizeof($trace) ; $i++ ) { |
|
784 | + $trace = debug_backtrace(); |
|
785 | + for( $i=0 ; $trace && $i<sizeof($trace) ; $i++ ) { |
|
786 | 786 | |
787 | - if(isset($trace[$i]['class']) |
|
788 | - && isset($trace[$i]['file']) |
|
789 | - && ($trace[$i]['class']=='FirePHP' |
|
790 | - || $trace[$i]['class']=='FB') |
|
791 | - && (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' |
|
792 | - || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { |
|
793 | - /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ |
|
794 | - } else |
|
795 | - if(isset($trace[$i]['class']) |
|
796 | - && isset($trace[$i+1]['file']) |
|
797 | - && $trace[$i]['class']=='FirePHP' |
|
798 | - && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') { |
|
799 | - /* Skip fb() */ |
|
800 | - } else |
|
801 | - if(isset($trace[$i]['file']) |
|
802 | - && substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php') { |
|
803 | - /* Skip FB::fb() */ |
|
804 | - } else { |
|
805 | - $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):''; |
|
806 | - $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:''; |
|
807 | - break; |
|
808 | - } |
|
809 | - } |
|
787 | + if(isset($trace[$i]['class']) |
|
788 | + && isset($trace[$i]['file']) |
|
789 | + && ($trace[$i]['class']=='FirePHP' |
|
790 | + || $trace[$i]['class']=='FB') |
|
791 | + && (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' |
|
792 | + || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { |
|
793 | + /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ |
|
794 | + } else |
|
795 | + if(isset($trace[$i]['class']) |
|
796 | + && isset($trace[$i+1]['file']) |
|
797 | + && $trace[$i]['class']=='FirePHP' |
|
798 | + && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') { |
|
799 | + /* Skip fb() */ |
|
800 | + } else |
|
801 | + if(isset($trace[$i]['file']) |
|
802 | + && substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php') { |
|
803 | + /* Skip FB::fb() */ |
|
804 | + } else { |
|
805 | + $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):''; |
|
806 | + $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:''; |
|
807 | + break; |
|
808 | + } |
|
809 | + } |
|
810 | 810 | |
811 | - } |
|
812 | - } else { |
|
813 | - unset($meta['file']); |
|
814 | - unset($meta['line']); |
|
815 | - } |
|
811 | + } |
|
812 | + } else { |
|
813 | + unset($meta['file']); |
|
814 | + unset($meta['line']); |
|
815 | + } |
|
816 | 816 | |
817 | 817 | $this->setHeader('X-Wf-Protocol-1','http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); |
818 | 818 | $this->setHeader('X-Wf-1-Plugin-1','http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'.self::VERSION); |
819 | 819 | |
820 | - $structure_index = 1; |
|
821 | - if($Type==self::DUMP) { |
|
822 | - $structure_index = 2; |
|
823 | - $this->setHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1'); |
|
824 | - } else { |
|
825 | - $this->setHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); |
|
826 | - } |
|
820 | + $structure_index = 1; |
|
821 | + if($Type==self::DUMP) { |
|
822 | + $structure_index = 2; |
|
823 | + $this->setHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1'); |
|
824 | + } else { |
|
825 | + $this->setHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); |
|
826 | + } |
|
827 | 827 | |
828 | - if($Type==self::DUMP) { |
|
829 | - $msg = '{"'.$Label.'":'.$this->jsonEncode($Object, $skipFinalObjectEncode).'}'; |
|
830 | - } else { |
|
831 | - $msg_meta = $Options; |
|
832 | - $msg_meta['Type'] = $Type; |
|
833 | - if($Label!==null) { |
|
834 | - $msg_meta['Label'] = $Label; |
|
835 | - } |
|
836 | - if(isset($meta['file']) && !isset($msg_meta['File'])) { |
|
837 | - $msg_meta['File'] = $meta['file']; |
|
838 | - } |
|
839 | - if(isset($meta['line']) && !isset($msg_meta['Line'])) { |
|
840 | - $msg_meta['Line'] = $meta['line']; |
|
841 | - } |
|
842 | - $msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']'; |
|
843 | - } |
|
828 | + if($Type==self::DUMP) { |
|
829 | + $msg = '{"'.$Label.'":'.$this->jsonEncode($Object, $skipFinalObjectEncode).'}'; |
|
830 | + } else { |
|
831 | + $msg_meta = $Options; |
|
832 | + $msg_meta['Type'] = $Type; |
|
833 | + if($Label!==null) { |
|
834 | + $msg_meta['Label'] = $Label; |
|
835 | + } |
|
836 | + if(isset($meta['file']) && !isset($msg_meta['File'])) { |
|
837 | + $msg_meta['File'] = $meta['file']; |
|
838 | + } |
|
839 | + if(isset($meta['line']) && !isset($msg_meta['Line'])) { |
|
840 | + $msg_meta['Line'] = $meta['line']; |
|
841 | + } |
|
842 | + $msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']'; |
|
843 | + } |
|
844 | 844 | |
845 | - $parts = explode("\n",chunk_split($msg, 5000, "\n")); |
|
845 | + $parts = explode("\n",chunk_split($msg, 5000, "\n")); |
|
846 | 846 | |
847 | - for( $i=0 ; $i<count($parts) ; $i++) { |
|
847 | + for( $i=0 ; $i<count($parts) ; $i++) { |
|
848 | 848 | |
849 | - $part = $parts[$i]; |
|
850 | - if ($part) { |
|
849 | + $part = $parts[$i]; |
|
850 | + if ($part) { |
|
851 | 851 | |
852 | - if(count($parts)>2) { |
|
853 | - // Message needs to be split into multiple parts |
|
854 | - $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex, |
|
855 | - (($i==0)?strlen($msg):'') |
|
856 | - . '|' . $part . '|' |
|
857 | - . (($i<count($parts)-2)?'\\':'')); |
|
858 | - } else { |
|
859 | - $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex, |
|
860 | - strlen($part) . '|' . $part . '|'); |
|
861 | - } |
|
852 | + if(count($parts)>2) { |
|
853 | + // Message needs to be split into multiple parts |
|
854 | + $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex, |
|
855 | + (($i==0)?strlen($msg):'') |
|
856 | + . '|' . $part . '|' |
|
857 | + . (($i<count($parts)-2)?'\\':'')); |
|
858 | + } else { |
|
859 | + $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex, |
|
860 | + strlen($part) . '|' . $part . '|'); |
|
861 | + } |
|
862 | 862 | |
863 | - $this->messageIndex++; |
|
863 | + $this->messageIndex++; |
|
864 | 864 | |
865 | - if ($this->messageIndex > 99999) { |
|
866 | - throw $this->newException('Maximum number (99,999) of messages reached!'); |
|
867 | - } |
|
868 | - } |
|
869 | - } |
|
865 | + if ($this->messageIndex > 99999) { |
|
866 | + throw $this->newException('Maximum number (99,999) of messages reached!'); |
|
867 | + } |
|
868 | + } |
|
869 | + } |
|
870 | 870 | |
871 | 871 | $this->setHeader('X-Wf-1-Index',$this->messageIndex-1); |
872 | 872 | |
873 | - return true; |
|
873 | + return true; |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | * @return string |
881 | 881 | */ |
882 | 882 | protected function _standardizePath($Path) { |
883 | - return preg_replace('/\\\\+/','/',$Path); |
|
883 | + return preg_replace('/\\\\+/','/',$Path); |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
@@ -890,16 +890,16 @@ discard block |
||
890 | 890 | * @return array |
891 | 891 | */ |
892 | 892 | protected function _escapeTrace($Trace) { |
893 | - if(!$Trace) return $Trace; |
|
894 | - for( $i=0 ; $i<sizeof($Trace) ; $i++ ) { |
|
895 | - if(isset($Trace[$i]['file'])) { |
|
896 | - $Trace[$i]['file'] = $this->_escapeTraceFile($Trace[$i]['file']); |
|
897 | - } |
|
898 | - if(isset($Trace[$i]['args'])) { |
|
899 | - $Trace[$i]['args'] = $this->encodeObject($Trace[$i]['args']); |
|
900 | - } |
|
901 | - } |
|
902 | - return $Trace; |
|
893 | + if(!$Trace) return $Trace; |
|
894 | + for( $i=0 ; $i<sizeof($Trace) ; $i++ ) { |
|
895 | + if(isset($Trace[$i]['file'])) { |
|
896 | + $Trace[$i]['file'] = $this->_escapeTraceFile($Trace[$i]['file']); |
|
897 | + } |
|
898 | + if(isset($Trace[$i]['args'])) { |
|
899 | + $Trace[$i]['args'] = $this->encodeObject($Trace[$i]['args']); |
|
900 | + } |
|
901 | + } |
|
902 | + return $Trace; |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | /** |
@@ -909,15 +909,15 @@ discard block |
||
909 | 909 | * @return string |
910 | 910 | */ |
911 | 911 | protected function _escapeTraceFile($File) { |
912 | - /* Check if we have a windows filepath */ |
|
913 | - if(strpos($File,'\\')) { |
|
914 | - /* First strip down to single \ */ |
|
912 | + /* Check if we have a windows filepath */ |
|
913 | + if(strpos($File,'\\')) { |
|
914 | + /* First strip down to single \ */ |
|
915 | 915 | |
916 | - $file = preg_replace('/\\\\+/','\\',$File); |
|
916 | + $file = preg_replace('/\\\\+/','\\',$File); |
|
917 | 917 | |
918 | - return $file; |
|
919 | - } |
|
920 | - return $File; |
|
918 | + return $file; |
|
919 | + } |
|
920 | + return $File; |
|
921 | 921 | } |
922 | 922 | |
923 | 923 | /** |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | * @param string_type $Value |
928 | 928 | */ |
929 | 929 | protected function setHeader($Name, $Value) { |
930 | - return header($Name.': '.$Value); |
|
930 | + return header($Name.': '.$Value); |
|
931 | 931 | } |
932 | 932 | |
933 | 933 | /** |
@@ -936,8 +936,8 @@ discard block |
||
936 | 936 | * @return string|false |
937 | 937 | */ |
938 | 938 | protected function getUserAgent() { |
939 | - if(!isset($_SERVER['HTTP_USER_AGENT'])) return false; |
|
940 | - return $_SERVER['HTTP_USER_AGENT']; |
|
939 | + if(!isset($_SERVER['HTTP_USER_AGENT'])) return false; |
|
940 | + return $_SERVER['HTTP_USER_AGENT']; |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | /** |
@@ -947,7 +947,7 @@ discard block |
||
947 | 947 | * @return Exception |
948 | 948 | */ |
949 | 949 | protected function newException($Message) { |
950 | - return new Exception($Message); |
|
950 | + return new Exception($Message); |
|
951 | 951 | } |
952 | 952 | |
953 | 953 | /** |
@@ -960,17 +960,17 @@ discard block |
||
960 | 960 | */ |
961 | 961 | public function jsonEncode($Object, $skipObjectEncode=false) |
962 | 962 | { |
963 | - if(!$skipObjectEncode) { |
|
964 | - $Object = $this->encodeObject($Object); |
|
965 | - } |
|
963 | + if(!$skipObjectEncode) { |
|
964 | + $Object = $this->encodeObject($Object); |
|
965 | + } |
|
966 | 966 | |
967 | - if(function_exists('json_encode') |
|
968 | - && $this->options['useNativeJsonEncode']!=false) { |
|
967 | + if(function_exists('json_encode') |
|
968 | + && $this->options['useNativeJsonEncode']!=false) { |
|
969 | 969 | |
970 | - return json_encode($Object); |
|
971 | - } else { |
|
972 | - return $this->json_encode($Object); |
|
973 | - } |
|
970 | + return json_encode($Object); |
|
971 | + } else { |
|
972 | + return $this->json_encode($Object); |
|
973 | + } |
|
974 | 974 | } |
975 | 975 | |
976 | 976 | /** |
@@ -981,23 +981,23 @@ discard block |
||
981 | 981 | */ |
982 | 982 | protected function encodeTable($Table) { |
983 | 983 | |
984 | - if(!$Table) return $Table; |
|
984 | + if(!$Table) return $Table; |
|
985 | 985 | |
986 | - $new_table = array(); |
|
987 | - foreach($Table as $row) { |
|
986 | + $new_table = array(); |
|
987 | + foreach($Table as $row) { |
|
988 | 988 | |
989 | - if(is_array($row)) { |
|
990 | - $new_row = array(); |
|
989 | + if(is_array($row)) { |
|
990 | + $new_row = array(); |
|
991 | 991 | |
992 | - foreach($row as $item) { |
|
993 | - $new_row[] = $this->encodeObject($item); |
|
994 | - } |
|
992 | + foreach($row as $item) { |
|
993 | + $new_row[] = $this->encodeObject($item); |
|
994 | + } |
|
995 | 995 | |
996 | - $new_table[] = $new_row; |
|
997 | - } |
|
998 | - } |
|
996 | + $new_table[] = $new_row; |
|
997 | + } |
|
998 | + } |
|
999 | 999 | |
1000 | - return $new_table; |
|
1000 | + return $new_table; |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | /** |
@@ -1010,134 +1010,134 @@ discard block |
||
1010 | 1010 | */ |
1011 | 1011 | protected function encodeObject($Object, $ObjectDepth = 1, $ArrayDepth = 1) |
1012 | 1012 | { |
1013 | - $return = array(); |
|
1013 | + $return = array(); |
|
1014 | 1014 | |
1015 | - if (is_resource($Object)) { |
|
1015 | + if (is_resource($Object)) { |
|
1016 | 1016 | |
1017 | - return '** '.(string)$Object.' **'; |
|
1017 | + return '** '.(string)$Object.' **'; |
|
1018 | 1018 | |
1019 | - } else |
|
1020 | - if (is_object($Object)) { |
|
1019 | + } else |
|
1020 | + if (is_object($Object)) { |
|
1021 | 1021 | |
1022 | - if ($ObjectDepth > $this->options['maxObjectDepth']) { |
|
1023 | - return '** Max Object Depth ('.$this->options['maxObjectDepth'].') **'; |
|
1024 | - } |
|
1022 | + if ($ObjectDepth > $this->options['maxObjectDepth']) { |
|
1023 | + return '** Max Object Depth ('.$this->options['maxObjectDepth'].') **'; |
|
1024 | + } |
|
1025 | 1025 | |
1026 | - foreach ($this->objectStack as $refVal) { |
|
1027 | - if ($refVal === $Object) { |
|
1028 | - return '** Recursion ('.get_class($Object).') **'; |
|
1029 | - } |
|
1030 | - } |
|
1031 | - array_push($this->objectStack, $Object); |
|
1026 | + foreach ($this->objectStack as $refVal) { |
|
1027 | + if ($refVal === $Object) { |
|
1028 | + return '** Recursion ('.get_class($Object).') **'; |
|
1029 | + } |
|
1030 | + } |
|
1031 | + array_push($this->objectStack, $Object); |
|
1032 | 1032 | |
1033 | - $return['__className'] = $class = get_class($Object); |
|
1033 | + $return['__className'] = $class = get_class($Object); |
|
1034 | 1034 | |
1035 | - $reflectionClass = new ReflectionClass($class); |
|
1036 | - $properties = array(); |
|
1037 | - foreach( $reflectionClass->getProperties() as $property) { |
|
1038 | - $properties[$property->getName()] = $property; |
|
1039 | - } |
|
1035 | + $reflectionClass = new ReflectionClass($class); |
|
1036 | + $properties = array(); |
|
1037 | + foreach( $reflectionClass->getProperties() as $property) { |
|
1038 | + $properties[$property->getName()] = $property; |
|
1039 | + } |
|
1040 | 1040 | |
1041 | - $members = (array)$Object; |
|
1041 | + $members = (array)$Object; |
|
1042 | 1042 | |
1043 | - foreach( $properties as $raw_name => $property ) { |
|
1043 | + foreach( $properties as $raw_name => $property ) { |
|
1044 | 1044 | |
1045 | - $name = $raw_name; |
|
1046 | - if($property->isStatic()) { |
|
1047 | - $name = 'static:'.$name; |
|
1048 | - } |
|
1049 | - if($property->isPublic()) { |
|
1050 | - $name = 'public:'.$name; |
|
1051 | - } else |
|
1052 | - if($property->isPrivate()) { |
|
1053 | - $name = 'private:'.$name; |
|
1054 | - $raw_name = "\0".$class."\0".$raw_name; |
|
1055 | - } else |
|
1056 | - if($property->isProtected()) { |
|
1057 | - $name = 'protected:'.$name; |
|
1058 | - $raw_name = "\0".'*'."\0".$raw_name; |
|
1059 | - } |
|
1045 | + $name = $raw_name; |
|
1046 | + if($property->isStatic()) { |
|
1047 | + $name = 'static:'.$name; |
|
1048 | + } |
|
1049 | + if($property->isPublic()) { |
|
1050 | + $name = 'public:'.$name; |
|
1051 | + } else |
|
1052 | + if($property->isPrivate()) { |
|
1053 | + $name = 'private:'.$name; |
|
1054 | + $raw_name = "\0".$class."\0".$raw_name; |
|
1055 | + } else |
|
1056 | + if($property->isProtected()) { |
|
1057 | + $name = 'protected:'.$name; |
|
1058 | + $raw_name = "\0".'*'."\0".$raw_name; |
|
1059 | + } |
|
1060 | 1060 | |
1061 | - if(!(isset($this->objectFilters[$class]) |
|
1062 | - && is_array($this->objectFilters[$class]) |
|
1063 | - && in_array($raw_name,$this->objectFilters[$class]))) { |
|
1061 | + if(!(isset($this->objectFilters[$class]) |
|
1062 | + && is_array($this->objectFilters[$class]) |
|
1063 | + && in_array($raw_name,$this->objectFilters[$class]))) { |
|
1064 | 1064 | |
1065 | - if(array_key_exists($raw_name,$members) |
|
1066 | - && !$property->isStatic()) { |
|
1065 | + if(array_key_exists($raw_name,$members) |
|
1066 | + && !$property->isStatic()) { |
|
1067 | 1067 | |
1068 | - $return[$name] = $this->encodeObject($members[$raw_name], $ObjectDepth + 1, 1); |
|
1068 | + $return[$name] = $this->encodeObject($members[$raw_name], $ObjectDepth + 1, 1); |
|
1069 | 1069 | |
1070 | - } else { |
|
1071 | - if(method_exists($property,'setAccessible')) { |
|
1072 | - $property->setAccessible(true); |
|
1073 | - $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1); |
|
1074 | - } else |
|
1075 | - if($property->isPublic()) { |
|
1076 | - $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1); |
|
1077 | - } else { |
|
1078 | - $return[$name] = '** Need PHP 5.3 to get value **'; |
|
1079 | - } |
|
1080 | - } |
|
1081 | - } else { |
|
1082 | - $return[$name] = '** Excluded by Filter **'; |
|
1083 | - } |
|
1084 | - } |
|
1070 | + } else { |
|
1071 | + if(method_exists($property,'setAccessible')) { |
|
1072 | + $property->setAccessible(true); |
|
1073 | + $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1); |
|
1074 | + } else |
|
1075 | + if($property->isPublic()) { |
|
1076 | + $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1); |
|
1077 | + } else { |
|
1078 | + $return[$name] = '** Need PHP 5.3 to get value **'; |
|
1079 | + } |
|
1080 | + } |
|
1081 | + } else { |
|
1082 | + $return[$name] = '** Excluded by Filter **'; |
|
1083 | + } |
|
1084 | + } |
|
1085 | 1085 | |
1086 | - // Include all members that are not defined in the class |
|
1087 | - // but exist in the object |
|
1088 | - foreach( $members as $raw_name => $value ) { |
|
1086 | + // Include all members that are not defined in the class |
|
1087 | + // but exist in the object |
|
1088 | + foreach( $members as $raw_name => $value ) { |
|
1089 | 1089 | |
1090 | - $name = $raw_name; |
|
1090 | + $name = $raw_name; |
|
1091 | 1091 | |
1092 | - if ($name{0} == "\0") { |
|
1093 | - $parts = explode("\0", $name); |
|
1094 | - $name = $parts[2]; |
|
1095 | - } |
|
1092 | + if ($name{0} == "\0") { |
|
1093 | + $parts = explode("\0", $name); |
|
1094 | + $name = $parts[2]; |
|
1095 | + } |
|
1096 | 1096 | |
1097 | - if(!isset($properties[$name])) { |
|
1098 | - $name = 'undeclared:'.$name; |
|
1097 | + if(!isset($properties[$name])) { |
|
1098 | + $name = 'undeclared:'.$name; |
|
1099 | 1099 | |
1100 | - if(!(isset($this->objectFilters[$class]) |
|
1101 | - && is_array($this->objectFilters[$class]) |
|
1102 | - && in_array($raw_name,$this->objectFilters[$class]))) { |
|
1100 | + if(!(isset($this->objectFilters[$class]) |
|
1101 | + && is_array($this->objectFilters[$class]) |
|
1102 | + && in_array($raw_name,$this->objectFilters[$class]))) { |
|
1103 | 1103 | |
1104 | - $return[$name] = $this->encodeObject($value, $ObjectDepth + 1, 1); |
|
1105 | - } else { |
|
1106 | - $return[$name] = '** Excluded by Filter **'; |
|
1107 | - } |
|
1108 | - } |
|
1109 | - } |
|
1104 | + $return[$name] = $this->encodeObject($value, $ObjectDepth + 1, 1); |
|
1105 | + } else { |
|
1106 | + $return[$name] = '** Excluded by Filter **'; |
|
1107 | + } |
|
1108 | + } |
|
1109 | + } |
|
1110 | 1110 | |
1111 | - array_pop($this->objectStack); |
|
1111 | + array_pop($this->objectStack); |
|
1112 | 1112 | |
1113 | - } elseif (is_array($Object)) { |
|
1113 | + } elseif (is_array($Object)) { |
|
1114 | 1114 | |
1115 | - if ($ArrayDepth > $this->options['maxArrayDepth']) { |
|
1116 | - return '** Max Array Depth ('.$this->options['maxArrayDepth'].') **'; |
|
1117 | - } |
|
1115 | + if ($ArrayDepth > $this->options['maxArrayDepth']) { |
|
1116 | + return '** Max Array Depth ('.$this->options['maxArrayDepth'].') **'; |
|
1117 | + } |
|
1118 | 1118 | |
1119 | - foreach ($Object as $key => $val) { |
|
1119 | + foreach ($Object as $key => $val) { |
|
1120 | 1120 | |
1121 | - // Encoding the $GLOBALS PHP array causes an infinite loop |
|
1122 | - // if the recursion is not reset here as it contains |
|
1123 | - // a reference to itself. This is the only way I have come up |
|
1124 | - // with to stop infinite recursion in this case. |
|
1125 | - if($key=='GLOBALS' |
|
1126 | - && is_array($val) |
|
1127 | - && array_key_exists('GLOBALS',$val)) { |
|
1128 | - $val['GLOBALS'] = '** Recursion (GLOBALS) **'; |
|
1129 | - } |
|
1121 | + // Encoding the $GLOBALS PHP array causes an infinite loop |
|
1122 | + // if the recursion is not reset here as it contains |
|
1123 | + // a reference to itself. This is the only way I have come up |
|
1124 | + // with to stop infinite recursion in this case. |
|
1125 | + if($key=='GLOBALS' |
|
1126 | + && is_array($val) |
|
1127 | + && array_key_exists('GLOBALS',$val)) { |
|
1128 | + $val['GLOBALS'] = '** Recursion (GLOBALS) **'; |
|
1129 | + } |
|
1130 | 1130 | |
1131 | - $return[$key] = $this->encodeObject($val, 1, $ArrayDepth + 1); |
|
1132 | - } |
|
1133 | - } else { |
|
1134 | - if(self::is_utf8($Object)) { |
|
1135 | - return $Object; |
|
1136 | - } else { |
|
1137 | - return utf8_encode($Object); |
|
1138 | - } |
|
1139 | - } |
|
1140 | - return $return; |
|
1131 | + $return[$key] = $this->encodeObject($val, 1, $ArrayDepth + 1); |
|
1132 | + } |
|
1133 | + } else { |
|
1134 | + if(self::is_utf8($Object)) { |
|
1135 | + return $Object; |
|
1136 | + } else { |
|
1137 | + return utf8_encode($Object); |
|
1138 | + } |
|
1139 | + } |
|
1140 | + return $return; |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | /** |
@@ -1147,29 +1147,29 @@ discard block |
||
1147 | 1147 | * @return boolean |
1148 | 1148 | */ |
1149 | 1149 | protected static function is_utf8($str) { |
1150 | - $c=0; $b=0; |
|
1151 | - $bits=0; |
|
1152 | - $len=strlen($str); |
|
1153 | - for($i=0; $i<$len; $i++){ |
|
1154 | - $c=ord($str[$i]); |
|
1155 | - if($c > 128){ |
|
1156 | - if(($c >= 254)) return false; |
|
1157 | - elseif($c >= 252) $bits=6; |
|
1158 | - elseif($c >= 248) $bits=5; |
|
1159 | - elseif($c >= 240) $bits=4; |
|
1160 | - elseif($c >= 224) $bits=3; |
|
1161 | - elseif($c >= 192) $bits=2; |
|
1162 | - else return false; |
|
1163 | - if(($i+$bits) > $len) return false; |
|
1164 | - while($bits > 1){ |
|
1165 | - $i++; |
|
1166 | - $b=ord($str[$i]); |
|
1167 | - if($b < 128 || $b > 191) return false; |
|
1168 | - $bits--; |
|
1169 | - } |
|
1170 | - } |
|
1171 | - } |
|
1172 | - return true; |
|
1150 | + $c=0; $b=0; |
|
1151 | + $bits=0; |
|
1152 | + $len=strlen($str); |
|
1153 | + for($i=0; $i<$len; $i++){ |
|
1154 | + $c=ord($str[$i]); |
|
1155 | + if($c > 128){ |
|
1156 | + if(($c >= 254)) return false; |
|
1157 | + elseif($c >= 252) $bits=6; |
|
1158 | + elseif($c >= 248) $bits=5; |
|
1159 | + elseif($c >= 240) $bits=4; |
|
1160 | + elseif($c >= 224) $bits=3; |
|
1161 | + elseif($c >= 192) $bits=2; |
|
1162 | + else return false; |
|
1163 | + if(($i+$bits) > $len) return false; |
|
1164 | + while($bits > 1){ |
|
1165 | + $i++; |
|
1166 | + $b=ord($str[$i]); |
|
1167 | + if($b < 128 || $b > 191) return false; |
|
1168 | + $bits--; |
|
1169 | + } |
|
1170 | + } |
|
1171 | + } |
|
1172 | + return true; |
|
1173 | 1173 | } |
1174 | 1174 | |
1175 | 1175 | /** |
@@ -1248,35 +1248,35 @@ discard block |
||
1248 | 1248 | */ |
1249 | 1249 | private function json_utf82utf16($utf8) |
1250 | 1250 | { |
1251 | - // oh please oh please oh please oh please oh please |
|
1252 | - if(function_exists('mb_convert_encoding')) { |
|
1253 | - return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
|
1254 | - } |
|
1255 | - |
|
1256 | - switch(strlen($utf8)) { |
|
1257 | - case 1: |
|
1258 | - // this case should never be reached, because we are in ASCII range |
|
1259 | - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1260 | - return $utf8; |
|
1261 | - |
|
1262 | - case 2: |
|
1263 | - // return a UTF-16 character from a 2-byte UTF-8 char |
|
1264 | - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1265 | - return chr(0x07 & (ord($utf8{0}) >> 2)) |
|
1266 | - . chr((0xC0 & (ord($utf8{0}) << 6)) |
|
1267 | - | (0x3F & ord($utf8{1}))); |
|
1268 | - |
|
1269 | - case 3: |
|
1270 | - // return a UTF-16 character from a 3-byte UTF-8 char |
|
1271 | - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1272 | - return chr((0xF0 & (ord($utf8{0}) << 4)) |
|
1273 | - | (0x0F & (ord($utf8{1}) >> 2))) |
|
1274 | - . chr((0xC0 & (ord($utf8{1}) << 6)) |
|
1275 | - | (0x7F & ord($utf8{2}))); |
|
1276 | - } |
|
1277 | - |
|
1278 | - // ignoring UTF-32 for now, sorry |
|
1279 | - return ''; |
|
1251 | + // oh please oh please oh please oh please oh please |
|
1252 | + if(function_exists('mb_convert_encoding')) { |
|
1253 | + return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
|
1254 | + } |
|
1255 | + |
|
1256 | + switch(strlen($utf8)) { |
|
1257 | + case 1: |
|
1258 | + // this case should never be reached, because we are in ASCII range |
|
1259 | + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1260 | + return $utf8; |
|
1261 | + |
|
1262 | + case 2: |
|
1263 | + // return a UTF-16 character from a 2-byte UTF-8 char |
|
1264 | + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1265 | + return chr(0x07 & (ord($utf8{0}) >> 2)) |
|
1266 | + . chr((0xC0 & (ord($utf8{0}) << 6)) |
|
1267 | + | (0x3F & ord($utf8{1}))); |
|
1268 | + |
|
1269 | + case 3: |
|
1270 | + // return a UTF-16 character from a 3-byte UTF-8 char |
|
1271 | + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1272 | + return chr((0xF0 & (ord($utf8{0}) << 4)) |
|
1273 | + | (0x0F & (ord($utf8{1}) >> 2))) |
|
1274 | + . chr((0xC0 & (ord($utf8{1}) << 6)) |
|
1275 | + | (0x7F & ord($utf8{2}))); |
|
1276 | + } |
|
1277 | + |
|
1278 | + // ignoring UTF-32 for now, sorry |
|
1279 | + return ''; |
|
1280 | 1280 | } |
1281 | 1281 | |
1282 | 1282 | /** |
@@ -1293,133 +1293,133 @@ discard block |
||
1293 | 1293 | private function json_encode($var) |
1294 | 1294 | { |
1295 | 1295 | |
1296 | - if(is_object($var)) { |
|
1297 | - if(in_array($var,$this->json_objectStack)) { |
|
1298 | - return '"** Recursion **"'; |
|
1299 | - } |
|
1300 | - } |
|
1296 | + if(is_object($var)) { |
|
1297 | + if(in_array($var,$this->json_objectStack)) { |
|
1298 | + return '"** Recursion **"'; |
|
1299 | + } |
|
1300 | + } |
|
1301 | 1301 | |
1302 | - switch (gettype($var)) { |
|
1303 | - case 'boolean': |
|
1304 | - return $var ? 'true' : 'false'; |
|
1302 | + switch (gettype($var)) { |
|
1303 | + case 'boolean': |
|
1304 | + return $var ? 'true' : 'false'; |
|
1305 | 1305 | |
1306 | - case 'NULL': |
|
1307 | - return 'null'; |
|
1306 | + case 'NULL': |
|
1307 | + return 'null'; |
|
1308 | 1308 | |
1309 | - case 'integer': |
|
1310 | - return (int) $var; |
|
1309 | + case 'integer': |
|
1310 | + return (int) $var; |
|
1311 | 1311 | |
1312 | - case 'double': |
|
1313 | - case 'float': |
|
1314 | - return (float) $var; |
|
1312 | + case 'double': |
|
1313 | + case 'float': |
|
1314 | + return (float) $var; |
|
1315 | 1315 | |
1316 | - case 'string': |
|
1317 | - // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
|
1318 | - $ascii = ''; |
|
1319 | - $strlen_var = strlen($var); |
|
1316 | + case 'string': |
|
1317 | + // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
|
1318 | + $ascii = ''; |
|
1319 | + $strlen_var = strlen($var); |
|
1320 | 1320 | |
1321 | - /* |
|
1321 | + /* |
|
1322 | 1322 | * Iterate over every character in the string, |
1323 | 1323 | * escaping with a slash or encoding to UTF-8 where necessary |
1324 | 1324 | */ |
1325 | - for ($c = 0; $c < $strlen_var; ++$c) { |
|
1326 | - |
|
1327 | - $ord_var_c = ord($var{$c}); |
|
1328 | - |
|
1329 | - switch (true) { |
|
1330 | - case $ord_var_c == 0x08: |
|
1331 | - $ascii .= '\b'; |
|
1332 | - break; |
|
1333 | - case $ord_var_c == 0x09: |
|
1334 | - $ascii .= '\t'; |
|
1335 | - break; |
|
1336 | - case $ord_var_c == 0x0A: |
|
1337 | - $ascii .= '\n'; |
|
1338 | - break; |
|
1339 | - case $ord_var_c == 0x0C: |
|
1340 | - $ascii .= '\f'; |
|
1341 | - break; |
|
1342 | - case $ord_var_c == 0x0D: |
|
1343 | - $ascii .= '\r'; |
|
1344 | - break; |
|
1345 | - |
|
1346 | - case $ord_var_c == 0x22: |
|
1347 | - case $ord_var_c == 0x2F: |
|
1348 | - case $ord_var_c == 0x5C: |
|
1349 | - // double quote, slash, slosh |
|
1350 | - $ascii .= '\\'.$var{$c}; |
|
1351 | - break; |
|
1352 | - |
|
1353 | - case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
|
1354 | - // characters U-00000000 - U-0000007F (same as ASCII) |
|
1355 | - $ascii .= $var{$c}; |
|
1356 | - break; |
|
1357 | - |
|
1358 | - case (($ord_var_c & 0xE0) == 0xC0): |
|
1359 | - // characters U-00000080 - U-000007FF, mask 110XXXXX |
|
1360 | - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1361 | - $char = pack('C*', $ord_var_c, ord($var{$c + 1})); |
|
1362 | - $c += 1; |
|
1363 | - $utf16 = $this->json_utf82utf16($char); |
|
1364 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
1365 | - break; |
|
1366 | - |
|
1367 | - case (($ord_var_c & 0xF0) == 0xE0): |
|
1368 | - // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
1369 | - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1370 | - $char = pack('C*', $ord_var_c, |
|
1371 | - ord($var{$c + 1}), |
|
1372 | - ord($var{$c + 2})); |
|
1373 | - $c += 2; |
|
1374 | - $utf16 = $this->json_utf82utf16($char); |
|
1375 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
1376 | - break; |
|
1377 | - |
|
1378 | - case (($ord_var_c & 0xF8) == 0xF0): |
|
1379 | - // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
1380 | - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1381 | - $char = pack('C*', $ord_var_c, |
|
1382 | - ord($var{$c + 1}), |
|
1383 | - ord($var{$c + 2}), |
|
1384 | - ord($var{$c + 3})); |
|
1385 | - $c += 3; |
|
1386 | - $utf16 = $this->json_utf82utf16($char); |
|
1387 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
1388 | - break; |
|
1389 | - |
|
1390 | - case (($ord_var_c & 0xFC) == 0xF8): |
|
1391 | - // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
1392 | - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1393 | - $char = pack('C*', $ord_var_c, |
|
1394 | - ord($var{$c + 1}), |
|
1395 | - ord($var{$c + 2}), |
|
1396 | - ord($var{$c + 3}), |
|
1397 | - ord($var{$c + 4})); |
|
1398 | - $c += 4; |
|
1399 | - $utf16 = $this->json_utf82utf16($char); |
|
1400 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
1401 | - break; |
|
1402 | - |
|
1403 | - case (($ord_var_c & 0xFE) == 0xFC): |
|
1404 | - // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
1405 | - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1406 | - $char = pack('C*', $ord_var_c, |
|
1407 | - ord($var{$c + 1}), |
|
1408 | - ord($var{$c + 2}), |
|
1409 | - ord($var{$c + 3}), |
|
1410 | - ord($var{$c + 4}), |
|
1411 | - ord($var{$c + 5})); |
|
1412 | - $c += 5; |
|
1413 | - $utf16 = $this->json_utf82utf16($char); |
|
1414 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
1415 | - break; |
|
1416 | - } |
|
1417 | - } |
|
1418 | - |
|
1419 | - return '"'.$ascii.'"'; |
|
1420 | - |
|
1421 | - case 'array': |
|
1422 | - /* |
|
1325 | + for ($c = 0; $c < $strlen_var; ++$c) { |
|
1326 | + |
|
1327 | + $ord_var_c = ord($var{$c}); |
|
1328 | + |
|
1329 | + switch (true) { |
|
1330 | + case $ord_var_c == 0x08: |
|
1331 | + $ascii .= '\b'; |
|
1332 | + break; |
|
1333 | + case $ord_var_c == 0x09: |
|
1334 | + $ascii .= '\t'; |
|
1335 | + break; |
|
1336 | + case $ord_var_c == 0x0A: |
|
1337 | + $ascii .= '\n'; |
|
1338 | + break; |
|
1339 | + case $ord_var_c == 0x0C: |
|
1340 | + $ascii .= '\f'; |
|
1341 | + break; |
|
1342 | + case $ord_var_c == 0x0D: |
|
1343 | + $ascii .= '\r'; |
|
1344 | + break; |
|
1345 | + |
|
1346 | + case $ord_var_c == 0x22: |
|
1347 | + case $ord_var_c == 0x2F: |
|
1348 | + case $ord_var_c == 0x5C: |
|
1349 | + // double quote, slash, slosh |
|
1350 | + $ascii .= '\\'.$var{$c}; |
|
1351 | + break; |
|
1352 | + |
|
1353 | + case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
|
1354 | + // characters U-00000000 - U-0000007F (same as ASCII) |
|
1355 | + $ascii .= $var{$c}; |
|
1356 | + break; |
|
1357 | + |
|
1358 | + case (($ord_var_c & 0xE0) == 0xC0): |
|
1359 | + // characters U-00000080 - U-000007FF, mask 110XXXXX |
|
1360 | + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1361 | + $char = pack('C*', $ord_var_c, ord($var{$c + 1})); |
|
1362 | + $c += 1; |
|
1363 | + $utf16 = $this->json_utf82utf16($char); |
|
1364 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
1365 | + break; |
|
1366 | + |
|
1367 | + case (($ord_var_c & 0xF0) == 0xE0): |
|
1368 | + // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
1369 | + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1370 | + $char = pack('C*', $ord_var_c, |
|
1371 | + ord($var{$c + 1}), |
|
1372 | + ord($var{$c + 2})); |
|
1373 | + $c += 2; |
|
1374 | + $utf16 = $this->json_utf82utf16($char); |
|
1375 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
1376 | + break; |
|
1377 | + |
|
1378 | + case (($ord_var_c & 0xF8) == 0xF0): |
|
1379 | + // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
1380 | + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1381 | + $char = pack('C*', $ord_var_c, |
|
1382 | + ord($var{$c + 1}), |
|
1383 | + ord($var{$c + 2}), |
|
1384 | + ord($var{$c + 3})); |
|
1385 | + $c += 3; |
|
1386 | + $utf16 = $this->json_utf82utf16($char); |
|
1387 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
1388 | + break; |
|
1389 | + |
|
1390 | + case (($ord_var_c & 0xFC) == 0xF8): |
|
1391 | + // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
1392 | + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1393 | + $char = pack('C*', $ord_var_c, |
|
1394 | + ord($var{$c + 1}), |
|
1395 | + ord($var{$c + 2}), |
|
1396 | + ord($var{$c + 3}), |
|
1397 | + ord($var{$c + 4})); |
|
1398 | + $c += 4; |
|
1399 | + $utf16 = $this->json_utf82utf16($char); |
|
1400 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
1401 | + break; |
|
1402 | + |
|
1403 | + case (($ord_var_c & 0xFE) == 0xFC): |
|
1404 | + // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
1405 | + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
1406 | + $char = pack('C*', $ord_var_c, |
|
1407 | + ord($var{$c + 1}), |
|
1408 | + ord($var{$c + 2}), |
|
1409 | + ord($var{$c + 3}), |
|
1410 | + ord($var{$c + 4}), |
|
1411 | + ord($var{$c + 5})); |
|
1412 | + $c += 5; |
|
1413 | + $utf16 = $this->json_utf82utf16($char); |
|
1414 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
1415 | + break; |
|
1416 | + } |
|
1417 | + } |
|
1418 | + |
|
1419 | + return '"'.$ascii.'"'; |
|
1420 | + |
|
1421 | + case 'array': |
|
1422 | + /* |
|
1423 | 1423 | * As per JSON spec if any array key is not an integer |
1424 | 1424 | * we must treat the the whole array as an object. We |
1425 | 1425 | * also try to catch a sparsely populated associative |
@@ -1437,63 +1437,63 @@ discard block |
||
1437 | 1437 | * bracket notation. |
1438 | 1438 | */ |
1439 | 1439 | |
1440 | - // treat as a JSON object |
|
1441 | - if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { |
|
1440 | + // treat as a JSON object |
|
1441 | + if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { |
|
1442 | 1442 | |
1443 | - $this->json_objectStack[] = $var; |
|
1443 | + $this->json_objectStack[] = $var; |
|
1444 | 1444 | |
1445 | - $properties = array_map(array($this, 'json_name_value'), |
|
1446 | - array_keys($var), |
|
1447 | - array_values($var)); |
|
1445 | + $properties = array_map(array($this, 'json_name_value'), |
|
1446 | + array_keys($var), |
|
1447 | + array_values($var)); |
|
1448 | 1448 | |
1449 | - array_pop($this->json_objectStack); |
|
1449 | + array_pop($this->json_objectStack); |
|
1450 | 1450 | |
1451 | - foreach($properties as $property) { |
|
1452 | - if($property instanceof Exception) { |
|
1453 | - return $property; |
|
1454 | - } |
|
1455 | - } |
|
1451 | + foreach($properties as $property) { |
|
1452 | + if($property instanceof Exception) { |
|
1453 | + return $property; |
|
1454 | + } |
|
1455 | + } |
|
1456 | 1456 | |
1457 | - return '{' . join(',', $properties) . '}'; |
|
1458 | - } |
|
1457 | + return '{' . join(',', $properties) . '}'; |
|
1458 | + } |
|
1459 | 1459 | |
1460 | - $this->json_objectStack[] = $var; |
|
1460 | + $this->json_objectStack[] = $var; |
|
1461 | 1461 | |
1462 | - // treat it like a regular array |
|
1463 | - $elements = array_map(array($this, 'json_encode'), $var); |
|
1462 | + // treat it like a regular array |
|
1463 | + $elements = array_map(array($this, 'json_encode'), $var); |
|
1464 | 1464 | |
1465 | - array_pop($this->json_objectStack); |
|
1465 | + array_pop($this->json_objectStack); |
|
1466 | 1466 | |
1467 | - foreach($elements as $element) { |
|
1468 | - if($element instanceof Exception) { |
|
1469 | - return $element; |
|
1470 | - } |
|
1471 | - } |
|
1467 | + foreach($elements as $element) { |
|
1468 | + if($element instanceof Exception) { |
|
1469 | + return $element; |
|
1470 | + } |
|
1471 | + } |
|
1472 | 1472 | |
1473 | - return '[' . join(',', $elements) . ']'; |
|
1473 | + return '[' . join(',', $elements) . ']'; |
|
1474 | 1474 | |
1475 | - case 'object': |
|
1476 | - $vars = self::encodeObject($var); |
|
1475 | + case 'object': |
|
1476 | + $vars = self::encodeObject($var); |
|
1477 | 1477 | |
1478 | - $this->json_objectStack[] = $var; |
|
1478 | + $this->json_objectStack[] = $var; |
|
1479 | 1479 | |
1480 | - $properties = array_map(array($this, 'json_name_value'), |
|
1481 | - array_keys($vars), |
|
1482 | - array_values($vars)); |
|
1480 | + $properties = array_map(array($this, 'json_name_value'), |
|
1481 | + array_keys($vars), |
|
1482 | + array_values($vars)); |
|
1483 | 1483 | |
1484 | - array_pop($this->json_objectStack); |
|
1484 | + array_pop($this->json_objectStack); |
|
1485 | 1485 | |
1486 | - foreach($properties as $property) { |
|
1487 | - if($property instanceof Exception) { |
|
1488 | - return $property; |
|
1489 | - } |
|
1490 | - } |
|
1486 | + foreach($properties as $property) { |
|
1487 | + if($property instanceof Exception) { |
|
1488 | + return $property; |
|
1489 | + } |
|
1490 | + } |
|
1491 | 1491 | |
1492 | - return '{' . join(',', $properties) . '}'; |
|
1492 | + return '{' . join(',', $properties) . '}'; |
|
1493 | 1493 | |
1494 | - default: |
|
1495 | - return null; |
|
1496 | - } |
|
1494 | + default: |
|
1495 | + return null; |
|
1496 | + } |
|
1497 | 1497 | } |
1498 | 1498 | |
1499 | 1499 | /** |
@@ -1507,22 +1507,22 @@ discard block |
||
1507 | 1507 | */ |
1508 | 1508 | private function json_name_value($name, $value) |
1509 | 1509 | { |
1510 | - // Encoding the $GLOBALS PHP array causes an infinite loop |
|
1511 | - // if the recursion is not reset here as it contains |
|
1512 | - // a reference to itself. This is the only way I have come up |
|
1513 | - // with to stop infinite recursion in this case. |
|
1514 | - if($name=='GLOBALS' |
|
1515 | - && is_array($value) |
|
1516 | - && array_key_exists('GLOBALS',$value)) { |
|
1517 | - $value['GLOBALS'] = '** Recursion **'; |
|
1518 | - } |
|
1510 | + // Encoding the $GLOBALS PHP array causes an infinite loop |
|
1511 | + // if the recursion is not reset here as it contains |
|
1512 | + // a reference to itself. This is the only way I have come up |
|
1513 | + // with to stop infinite recursion in this case. |
|
1514 | + if($name=='GLOBALS' |
|
1515 | + && is_array($value) |
|
1516 | + && array_key_exists('GLOBALS',$value)) { |
|
1517 | + $value['GLOBALS'] = '** Recursion **'; |
|
1518 | + } |
|
1519 | 1519 | |
1520 | - $encoded_value = $this->json_encode($value); |
|
1520 | + $encoded_value = $this->json_encode($value); |
|
1521 | 1521 | |
1522 | - if($encoded_value instanceof Exception) { |
|
1523 | - return $encoded_value; |
|
1524 | - } |
|
1522 | + if($encoded_value instanceof Exception) { |
|
1523 | + return $encoded_value; |
|
1524 | + } |
|
1525 | 1525 | |
1526 | - return $this->json_encode(strval($name)) . ':' . $encoded_value; |
|
1526 | + return $this->json_encode(strval($name)) . ':' . $encoded_value; |
|
1527 | 1527 | } |
1528 | 1528 | } |
@@ -13,6 +13,10 @@ |
||
13 | 13 | * |
14 | 14 | */ |
15 | 15 | interface PHP_Shell_Extension { |
16 | + |
|
17 | + /** |
|
18 | + * @return void |
|
19 | + */ |
|
16 | 20 | public function register(); |
17 | 21 | } |
18 | 22 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * |
14 | 14 | */ |
15 | 15 | interface PHP_Shell_Extension { |
16 | - public function register(); |
|
16 | + public function register(); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -22,65 +22,65 @@ discard block |
||
22 | 22 | * |
23 | 23 | */ |
24 | 24 | class PHP_Shell_Extensions { |
25 | - /** |
|
26 | - * @var PHP_Shell_Extensions |
|
27 | - */ |
|
28 | - static protected $instance; |
|
25 | + /** |
|
26 | + * @var PHP_Shell_Extensions |
|
27 | + */ |
|
28 | + static protected $instance; |
|
29 | 29 | |
30 | - /** |
|
31 | - * storage for the extension |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $exts = array(); |
|
30 | + /** |
|
31 | + * storage for the extension |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $exts = array(); |
|
36 | 36 | |
37 | - /** |
|
38 | - * the extension object gives access to the register objects |
|
39 | - * through the a simple $exts->name->... |
|
40 | - * |
|
41 | - * @param string registered name of the extension |
|
42 | - * @return PHP_Shell_Extension object handle |
|
43 | - */ |
|
44 | - public function __get($key) { |
|
45 | - if (!isset($this->exts[$key])) { |
|
46 | - throw new Exception("Extension $s is not known."); |
|
47 | - } |
|
48 | - return $this->exts[$key]; |
|
49 | - } |
|
37 | + /** |
|
38 | + * the extension object gives access to the register objects |
|
39 | + * through the a simple $exts->name->... |
|
40 | + * |
|
41 | + * @param string registered name of the extension |
|
42 | + * @return PHP_Shell_Extension object handle |
|
43 | + */ |
|
44 | + public function __get($key) { |
|
45 | + if (!isset($this->exts[$key])) { |
|
46 | + throw new Exception("Extension $s is not known."); |
|
47 | + } |
|
48 | + return $this->exts[$key]; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * register set of extensions |
|
53 | - * |
|
54 | - * @param array set of (name, class-name) pairs |
|
55 | - */ |
|
56 | - public function registerExtensions($exts) { |
|
57 | - foreach ($exts as $k => $v) { |
|
58 | - $this->registerExtension($k, $v); |
|
59 | - } |
|
60 | - } |
|
51 | + /** |
|
52 | + * register set of extensions |
|
53 | + * |
|
54 | + * @param array set of (name, class-name) pairs |
|
55 | + */ |
|
56 | + public function registerExtensions($exts) { |
|
57 | + foreach ($exts as $k => $v) { |
|
58 | + $this->registerExtension($k, $v); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * register a single extension |
|
64 | - * |
|
65 | - * @param string name of the registered extension |
|
66 | - * @param PHP_Shell_Extension the extension object |
|
67 | - */ |
|
68 | - public function registerExtension($k, PHP_Shell_Extension $obj) { |
|
69 | - $obj->register(); |
|
62 | + /** |
|
63 | + * register a single extension |
|
64 | + * |
|
65 | + * @param string name of the registered extension |
|
66 | + * @param PHP_Shell_Extension the extension object |
|
67 | + */ |
|
68 | + public function registerExtension($k, PHP_Shell_Extension $obj) { |
|
69 | + $obj->register(); |
|
70 | 70 | |
71 | - $this->exts[$k] = $obj; |
|
72 | - } |
|
71 | + $this->exts[$k] = $obj; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return object a singleton of the class |
|
76 | - */ |
|
77 | - static function getInstance() { |
|
78 | - if (is_null(self::$instance)) { |
|
79 | - $class = __CLASS__; |
|
80 | - self::$instance = new $class(); |
|
81 | - } |
|
82 | - return self::$instance; |
|
83 | - } |
|
74 | + /** |
|
75 | + * @return object a singleton of the class |
|
76 | + */ |
|
77 | + static function getInstance() { |
|
78 | + if (is_null(self::$instance)) { |
|
79 | + $class = __CLASS__; |
|
80 | + self::$instance = new $class(); |
|
81 | + } |
|
82 | + return self::$instance; |
|
83 | + } |
|
84 | 84 | } |
85 | 85 | |
86 | 86 |
@@ -97,6 +97,8 @@ |
||
97 | 97 | * calls the setor for the :set <option> |
98 | 98 | * |
99 | 99 | * |
100 | + * @param string $key |
|
101 | + * @param string|null $value |
|
100 | 102 | */ |
101 | 103 | private function execute($key, $value) { |
102 | 104 | /* did we hit a alias (bg for backgroud) ? */ |
@@ -6,127 +6,127 @@ |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | class PHP_Shell_Options implements PHP_Shell_Extension { |
9 | - /* |
|
9 | + /* |
|
10 | 10 | * instance of the current class |
11 | 11 | * |
12 | 12 | * @var PHP_Shell_Options |
13 | 13 | */ |
14 | - static protected $instance; |
|
15 | - |
|
16 | - /** |
|
17 | - * known options and their setors |
|
18 | - * |
|
19 | - * @var array |
|
20 | - * @see registerOption |
|
21 | - */ |
|
22 | - protected $options = array(); |
|
23 | - |
|
24 | - /** |
|
25 | - * known options and their setors |
|
26 | - * |
|
27 | - * @var array |
|
28 | - * @see registerOptionAlias |
|
29 | - */ |
|
30 | - protected $option_aliases = array(); |
|
31 | - |
|
32 | - public function register() { |
|
14 | + static protected $instance; |
|
15 | + |
|
16 | + /** |
|
17 | + * known options and their setors |
|
18 | + * |
|
19 | + * @var array |
|
20 | + * @see registerOption |
|
21 | + */ |
|
22 | + protected $options = array(); |
|
23 | + |
|
24 | + /** |
|
25 | + * known options and their setors |
|
26 | + * |
|
27 | + * @var array |
|
28 | + * @see registerOptionAlias |
|
29 | + */ |
|
30 | + protected $option_aliases = array(); |
|
31 | + |
|
32 | + public function register() { |
|
33 | 33 | // $cmd = PHP_Shell_Commands::getInstance(); |
34 | 34 | // $cmd->registerCommand('#^:set #', $this, 'cmdSet', ':set <var>', 'set a shell variable'); |
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * register a option |
|
39 | - * |
|
40 | - * @param string name of the option |
|
41 | - * @param object a object handle |
|
42 | - * @param string method-name of the setor in the object |
|
43 | - * @param string (unused) |
|
44 | - */ |
|
45 | - public function registerOption($option, $obj, $setor, $getor = null) { |
|
46 | - if (!method_exists($obj, $setor)) { |
|
47 | - throw new Exception(sprintf("setor %s doesn't exist on class %s", $setor, get_class($obj))); |
|
48 | - } |
|
49 | - |
|
50 | - $this->options[trim($option)] = array("obj" => $obj, "setor" => $setor); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * set a shell-var |
|
55 | - * |
|
56 | - * :set al to enable autoload |
|
57 | - * :set bg=dark to enable highlighting with a dark backgroud |
|
58 | - */ |
|
59 | - public function cmdSet($l) { |
|
60 | - if (!preg_match('#:set\s+([a-z]+)\s*(?:=\s*([a-z0-9]+)\s*)?$#i', $l, $a)) { |
|
61 | - print(':set failed: either :set <option> or :set <option> = <value>'); |
|
62 | - return; |
|
63 | - } |
|
64 | - |
|
65 | - $this->execute($a[1], isset($a[2]) ? $a[2] : null); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * get all the option names |
|
70 | - * |
|
71 | - * @return array names of all options |
|
72 | - */ |
|
73 | - public function getOptions() { |
|
74 | - return array_keys($this->options); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * map a option to another option |
|
79 | - * |
|
80 | - * e.g.: bg maps to background |
|
81 | - * |
|
82 | - * @param string alias |
|
83 | - * @param string option |
|
84 | - */ |
|
85 | - public function registerOptionAlias($alias, $option) { |
|
86 | - if (!isset($this->options[$option])) { |
|
87 | - throw new Exception(sprintf("Option %s is not known", $option)); |
|
88 | - } |
|
89 | - |
|
90 | - $this->option_aliases[trim($alias)] = trim($option); |
|
91 | - |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * execute a :set command |
|
96 | - * |
|
97 | - * calls the setor for the :set <option> |
|
98 | - * |
|
99 | - * |
|
100 | - */ |
|
101 | - private function execute($key, $value) { |
|
102 | - /* did we hit a alias (bg for backgroud) ? */ |
|
103 | - if (isset($this->option_aliases[$key])) { |
|
104 | - $opt_key = $this->option_aliases[$key]; |
|
105 | - } else { |
|
106 | - $opt_key = $key; |
|
107 | - } |
|
108 | - |
|
109 | - if (!isset($this->options[$opt_key])) { |
|
110 | - print (':set '.$key.' failed: unknown key'); |
|
111 | - return; |
|
112 | - } |
|
113 | - |
|
114 | - if (!isset($this->options[$opt_key]["setor"])) { |
|
115 | - return; |
|
116 | - } |
|
117 | - |
|
118 | - $setor = $this->options[$opt_key]["setor"]; |
|
119 | - $obj = $this->options[$opt_key]["obj"]; |
|
120 | - $obj->$setor($key, $value); |
|
121 | - } |
|
122 | - |
|
123 | - static function getInstance() { |
|
124 | - if (is_null(self::$instance)) { |
|
125 | - $class = __CLASS__; |
|
126 | - self::$instance = new $class(); |
|
127 | - } |
|
128 | - return self::$instance; |
|
129 | - } |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * register a option |
|
39 | + * |
|
40 | + * @param string name of the option |
|
41 | + * @param object a object handle |
|
42 | + * @param string method-name of the setor in the object |
|
43 | + * @param string (unused) |
|
44 | + */ |
|
45 | + public function registerOption($option, $obj, $setor, $getor = null) { |
|
46 | + if (!method_exists($obj, $setor)) { |
|
47 | + throw new Exception(sprintf("setor %s doesn't exist on class %s", $setor, get_class($obj))); |
|
48 | + } |
|
49 | + |
|
50 | + $this->options[trim($option)] = array("obj" => $obj, "setor" => $setor); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * set a shell-var |
|
55 | + * |
|
56 | + * :set al to enable autoload |
|
57 | + * :set bg=dark to enable highlighting with a dark backgroud |
|
58 | + */ |
|
59 | + public function cmdSet($l) { |
|
60 | + if (!preg_match('#:set\s+([a-z]+)\s*(?:=\s*([a-z0-9]+)\s*)?$#i', $l, $a)) { |
|
61 | + print(':set failed: either :set <option> or :set <option> = <value>'); |
|
62 | + return; |
|
63 | + } |
|
64 | + |
|
65 | + $this->execute($a[1], isset($a[2]) ? $a[2] : null); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * get all the option names |
|
70 | + * |
|
71 | + * @return array names of all options |
|
72 | + */ |
|
73 | + public function getOptions() { |
|
74 | + return array_keys($this->options); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * map a option to another option |
|
79 | + * |
|
80 | + * e.g.: bg maps to background |
|
81 | + * |
|
82 | + * @param string alias |
|
83 | + * @param string option |
|
84 | + */ |
|
85 | + public function registerOptionAlias($alias, $option) { |
|
86 | + if (!isset($this->options[$option])) { |
|
87 | + throw new Exception(sprintf("Option %s is not known", $option)); |
|
88 | + } |
|
89 | + |
|
90 | + $this->option_aliases[trim($alias)] = trim($option); |
|
91 | + |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * execute a :set command |
|
96 | + * |
|
97 | + * calls the setor for the :set <option> |
|
98 | + * |
|
99 | + * |
|
100 | + */ |
|
101 | + private function execute($key, $value) { |
|
102 | + /* did we hit a alias (bg for backgroud) ? */ |
|
103 | + if (isset($this->option_aliases[$key])) { |
|
104 | + $opt_key = $this->option_aliases[$key]; |
|
105 | + } else { |
|
106 | + $opt_key = $key; |
|
107 | + } |
|
108 | + |
|
109 | + if (!isset($this->options[$opt_key])) { |
|
110 | + print (':set '.$key.' failed: unknown key'); |
|
111 | + return; |
|
112 | + } |
|
113 | + |
|
114 | + if (!isset($this->options[$opt_key]["setor"])) { |
|
115 | + return; |
|
116 | + } |
|
117 | + |
|
118 | + $setor = $this->options[$opt_key]["setor"]; |
|
119 | + $obj = $this->options[$opt_key]["obj"]; |
|
120 | + $obj->$setor($key, $value); |
|
121 | + } |
|
122 | + |
|
123 | + static function getInstance() { |
|
124 | + if (is_null(self::$instance)) { |
|
125 | + $class = __CLASS__; |
|
126 | + self::$instance = new $class(); |
|
127 | + } |
|
128 | + return self::$instance; |
|
129 | + } |
|
130 | 130 | } |
131 | 131 | |
132 | 132 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once(dirname(__FILE__)."/Extensions.php"); /* for the PHP_Shell_Interface */ |
|
3 | +require_once(dirname(__FILE__) . "/Extensions.php"); /* for the PHP_Shell_Interface */ |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | if (!isset($this->options[$opt_key])) { |
110 | - print (':set '.$key.' failed: unknown key'); |
|
110 | + print (':set ' . $key . ' failed: unknown key'); |
|
111 | 111 | return; |
112 | 112 | } |
113 | 113 |
@@ -211,6 +211,9 @@ discard block |
||
211 | 211 | |
212 | 212 | /* Mailhide related code */ |
213 | 213 | |
214 | +/** |
|
215 | + * @param string $ky |
|
216 | + */ |
|
214 | 217 | function _recaptcha_aes_encrypt($val,$ky) { |
215 | 218 | if (! function_exists ("mcrypt_encrypt")) { |
216 | 219 | die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); |
@@ -222,6 +225,9 @@ discard block |
||
222 | 225 | } |
223 | 226 | |
224 | 227 | |
228 | +/** |
|
229 | + * @param null|string $x |
|
230 | + */ |
|
225 | 231 | function _recaptcha_mailhide_urlbase64 ($x) { |
226 | 232 | return strtr(base64_encode ($x), '+/', '-_'); |
227 | 233 | } |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | * @return string - encoded request |
46 | 46 | */ |
47 | 47 | function _recaptcha_qsencode ($data) { |
48 | - $req = ""; |
|
49 | - foreach ( $data as $key => $value ) |
|
50 | - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
48 | + $req = ""; |
|
49 | + foreach ( $data as $key => $value ) |
|
50 | + $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
51 | 51 | |
52 | - // Cut the last '&' |
|
53 | - $req=substr($req,0,strlen($req)-1); |
|
54 | - return $req; |
|
52 | + // Cut the last '&' |
|
53 | + $req=substr($req,0,strlen($req)-1); |
|
54 | + return $req; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -66,29 +66,29 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function _recaptcha_http_post($host, $path, $data, $port = 80) { |
68 | 68 | |
69 | - $req = _recaptcha_qsencode ($data); |
|
69 | + $req = _recaptcha_qsencode ($data); |
|
70 | 70 | |
71 | - $http_request = "POST $path HTTP/1.0\r\n"; |
|
72 | - $http_request .= "Host: $host\r\n"; |
|
73 | - $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; |
|
74 | - $http_request .= "Content-Length: " . strlen($req) . "\r\n"; |
|
75 | - $http_request .= "User-Agent: reCAPTCHA/PHP\r\n"; |
|
76 | - $http_request .= "\r\n"; |
|
77 | - $http_request .= $req; |
|
71 | + $http_request = "POST $path HTTP/1.0\r\n"; |
|
72 | + $http_request .= "Host: $host\r\n"; |
|
73 | + $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; |
|
74 | + $http_request .= "Content-Length: " . strlen($req) . "\r\n"; |
|
75 | + $http_request .= "User-Agent: reCAPTCHA/PHP\r\n"; |
|
76 | + $http_request .= "\r\n"; |
|
77 | + $http_request .= $req; |
|
78 | 78 | |
79 | - $response = ''; |
|
80 | - if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { |
|
81 | - die ('Could not open socket'); |
|
82 | - } |
|
79 | + $response = ''; |
|
80 | + if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { |
|
81 | + die ('Could not open socket'); |
|
82 | + } |
|
83 | 83 | |
84 | - fwrite($fs, $http_request); |
|
84 | + fwrite($fs, $http_request); |
|
85 | 85 | |
86 | - while ( !feof($fs) ) |
|
87 | - $response .= fgets($fs, 1160); // One TCP-IP packet |
|
88 | - fclose($fs); |
|
89 | - $response = explode("\r\n\r\n", $response, 2); |
|
86 | + while ( !feof($fs) ) |
|
87 | + $response .= fgets($fs, 1160); // One TCP-IP packet |
|
88 | + fclose($fs); |
|
89 | + $response = explode("\r\n\r\n", $response, 2); |
|
90 | 90 | |
91 | - return $response; |
|
91 | + return $response; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | |
@@ -100,7 +100,6 @@ discard block |
||
100 | 100 | * @param string $pubkey A public key for reCAPTCHA |
101 | 101 | * @param string $error The error given by reCAPTCHA (optional, default is null) |
102 | 102 | * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false) |
103 | - |
|
104 | 103 | * @return string - The HTML to be embedded in the user's form. |
105 | 104 | */ |
106 | 105 | function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false) |
@@ -110,16 +109,16 @@ discard block |
||
110 | 109 | } |
111 | 110 | |
112 | 111 | if ($use_ssl) { |
113 | - $server = RECAPTCHA_API_SECURE_SERVER; |
|
114 | - } else { |
|
115 | - $server = RECAPTCHA_API_SERVER; |
|
116 | - } |
|
112 | + $server = RECAPTCHA_API_SECURE_SERVER; |
|
113 | + } else { |
|
114 | + $server = RECAPTCHA_API_SERVER; |
|
115 | + } |
|
117 | 116 | |
118 | - $errorpart = ""; |
|
119 | - if ($error) { |
|
120 | - $errorpart = "&error=" . $error; |
|
121 | - } |
|
122 | - return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> |
|
117 | + $errorpart = ""; |
|
118 | + if ($error) { |
|
119 | + $errorpart = "&error=" . $error; |
|
120 | + } |
|
121 | + return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> |
|
123 | 122 | |
124 | 123 | <noscript> |
125 | 124 | <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/> |
@@ -135,20 +134,20 @@ discard block |
||
135 | 134 | * A ReCaptchaResponse is returned from recaptcha_check_answer() |
136 | 135 | */ |
137 | 136 | class ReCaptchaResponse { |
138 | - var $is_valid; |
|
139 | - var $error; |
|
137 | + var $is_valid; |
|
138 | + var $error; |
|
140 | 139 | } |
141 | 140 | |
142 | 141 | |
143 | 142 | /** |
144 | - * Calls an HTTP POST function to verify if the user's guess was correct |
|
145 | - * @param string $privkey |
|
146 | - * @param string $remoteip |
|
147 | - * @param string $challenge |
|
148 | - * @param string $response |
|
149 | - * @param array $extra_params an array of extra variables to post to the server |
|
150 | - * @return ReCaptchaResponse |
|
151 | - */ |
|
143 | + * Calls an HTTP POST function to verify if the user's guess was correct |
|
144 | + * @param string $privkey |
|
145 | + * @param string $remoteip |
|
146 | + * @param string $challenge |
|
147 | + * @param string $response |
|
148 | + * @param array $extra_params an array of extra variables to post to the server |
|
149 | + * @return ReCaptchaResponse |
|
150 | + */ |
|
152 | 151 | function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) |
153 | 152 | { |
154 | 153 | if ($privkey == null || $privkey == '') { |
@@ -161,34 +160,34 @@ discard block |
||
161 | 160 | |
162 | 161 | |
163 | 162 | |
164 | - //discard spam submissions |
|
165 | - if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) { |
|
166 | - $recaptcha_response = new ReCaptchaResponse(); |
|
167 | - $recaptcha_response->is_valid = false; |
|
168 | - $recaptcha_response->error = 'incorrect-captcha-sol'; |
|
169 | - return $recaptcha_response; |
|
170 | - } |
|
171 | - |
|
172 | - $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
|
173 | - array ( |
|
174 | - 'privatekey' => $privkey, |
|
175 | - 'remoteip' => $remoteip, |
|
176 | - 'challenge' => $challenge, |
|
177 | - 'response' => $response |
|
178 | - ) + $extra_params |
|
179 | - ); |
|
180 | - |
|
181 | - $answers = explode ("\n", $response [1]); |
|
182 | - $recaptcha_response = new ReCaptchaResponse(); |
|
183 | - |
|
184 | - if (trim ($answers [0]) == 'true') { |
|
185 | - $recaptcha_response->is_valid = true; |
|
186 | - } |
|
187 | - else { |
|
188 | - $recaptcha_response->is_valid = false; |
|
189 | - $recaptcha_response->error = $answers [1]; |
|
190 | - } |
|
191 | - return $recaptcha_response; |
|
163 | + //discard spam submissions |
|
164 | + if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) { |
|
165 | + $recaptcha_response = new ReCaptchaResponse(); |
|
166 | + $recaptcha_response->is_valid = false; |
|
167 | + $recaptcha_response->error = 'incorrect-captcha-sol'; |
|
168 | + return $recaptcha_response; |
|
169 | + } |
|
170 | + |
|
171 | + $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
|
172 | + array ( |
|
173 | + 'privatekey' => $privkey, |
|
174 | + 'remoteip' => $remoteip, |
|
175 | + 'challenge' => $challenge, |
|
176 | + 'response' => $response |
|
177 | + ) + $extra_params |
|
178 | + ); |
|
179 | + |
|
180 | + $answers = explode ("\n", $response [1]); |
|
181 | + $recaptcha_response = new ReCaptchaResponse(); |
|
182 | + |
|
183 | + if (trim ($answers [0]) == 'true') { |
|
184 | + $recaptcha_response->is_valid = true; |
|
185 | + } |
|
186 | + else { |
|
187 | + $recaptcha_response->is_valid = false; |
|
188 | + $recaptcha_response->error = $answers [1]; |
|
189 | + } |
|
190 | + return $recaptcha_response; |
|
192 | 191 | |
193 | 192 | } |
194 | 193 | |
@@ -230,7 +229,7 @@ discard block |
||
230 | 229 | function recaptcha_mailhide_url($pubkey, $privkey, $email) { |
231 | 230 | if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) { |
232 | 231 | die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " . |
233 | - "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>"); |
|
232 | + "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>"); |
|
234 | 233 | } |
235 | 234 | |
236 | 235 |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @param $data - array of string elements to be encoded |
45 | 45 | * @return string - encoded request |
46 | 46 | */ |
47 | -function _recaptcha_qsencode ($data) { |
|
47 | +function _recaptcha_qsencode($data) { |
|
48 | 48 | $req = ""; |
49 | - foreach ( $data as $key => $value ) |
|
50 | - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
49 | + foreach ($data as $key => $value) |
|
50 | + $req .= $key . '=' . urlencode(stripslashes($value)) . '&'; |
|
51 | 51 | |
52 | 52 | // Cut the last '&' |
53 | - $req=substr($req,0,strlen($req)-1); |
|
53 | + $req = substr($req, 0, strlen($req) - 1); |
|
54 | 54 | return $req; |
55 | 55 | } |
56 | 56 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function _recaptcha_http_post($host, $path, $data, $port = 80) { |
68 | 68 | |
69 | - $req = _recaptcha_qsencode ($data); |
|
69 | + $req = _recaptcha_qsencode($data); |
|
70 | 70 | |
71 | 71 | $http_request = "POST $path HTTP/1.0\r\n"; |
72 | 72 | $http_request .= "Host: $host\r\n"; |
@@ -77,13 +77,13 @@ discard block |
||
77 | 77 | $http_request .= $req; |
78 | 78 | |
79 | 79 | $response = ''; |
80 | - if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { |
|
80 | + if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10))) { |
|
81 | 81 | die ('Could not open socket'); |
82 | 82 | } |
83 | 83 | |
84 | 84 | fwrite($fs, $http_request); |
85 | 85 | |
86 | - while ( !feof($fs) ) |
|
86 | + while (!feof($fs)) |
|
87 | 87 | $response .= fgets($fs, 1160); // One TCP-IP packet |
88 | 88 | fclose($fs); |
89 | 89 | $response = explode("\r\n\r\n", $response, 2); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | * @return string - The HTML to be embedded in the user's form. |
105 | 105 | */ |
106 | -function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false) |
|
106 | +function recaptcha_get_html($pubkey, $error = null, $use_ssl = false) |
|
107 | 107 | { |
108 | 108 | if ($pubkey == null || $pubkey == '') { |
109 | 109 | die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | if ($error) { |
120 | 120 | $errorpart = "&error=" . $error; |
121 | 121 | } |
122 | - return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> |
|
122 | + return '<script type="text/javascript" src="' . $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> |
|
123 | 123 | |
124 | 124 | <noscript> |
125 | 125 | <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/> |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param array $extra_params an array of extra variables to post to the server |
150 | 150 | * @return ReCaptchaResponse |
151 | 151 | */ |
152 | -function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) |
|
152 | +function recaptcha_check_answer($privkey, $remoteip, $challenge, $response, $extra_params = array()) |
|
153 | 153 | { |
154 | 154 | if ($privkey == null || $privkey == '') { |
155 | 155 | die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | return $recaptcha_response; |
170 | 170 | } |
171 | 171 | |
172 | - $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
|
173 | - array ( |
|
172 | + $response = _recaptcha_http_post(RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
|
173 | + array( |
|
174 | 174 | 'privatekey' => $privkey, |
175 | 175 | 'remoteip' => $remoteip, |
176 | 176 | 'challenge' => $challenge, |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | ) + $extra_params |
179 | 179 | ); |
180 | 180 | |
181 | - $answers = explode ("\n", $response [1]); |
|
181 | + $answers = explode("\n", $response [1]); |
|
182 | 182 | $recaptcha_response = new ReCaptchaResponse(); |
183 | 183 | |
184 | - if (trim ($answers [0]) == 'true') { |
|
184 | + if (trim($answers [0]) == 'true') { |
|
185 | 185 | $recaptcha_response->is_valid = true; |
186 | 186 | } |
187 | 187 | else { |
@@ -199,31 +199,31 @@ discard block |
||
199 | 199 | * @param string $domain The domain where the page is hosted |
200 | 200 | * @param string $appname The name of your application |
201 | 201 | */ |
202 | -function recaptcha_get_signup_url ($domain = null, $appname = null) { |
|
203 | - return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname)); |
|
202 | +function recaptcha_get_signup_url($domain = null, $appname = null) { |
|
203 | + return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode(array('domains' => $domain, 'app' => $appname)); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | function _recaptcha_aes_pad($val) { |
207 | 207 | $block_size = 16; |
208 | - $numpad = $block_size - (strlen ($val) % $block_size); |
|
209 | - return str_pad($val, strlen ($val) + $numpad, chr($numpad)); |
|
208 | + $numpad = $block_size - (strlen($val) % $block_size); |
|
209 | + return str_pad($val, strlen($val) + $numpad, chr($numpad)); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /* Mailhide related code */ |
213 | 213 | |
214 | -function _recaptcha_aes_encrypt($val,$ky) { |
|
215 | - if (! function_exists ("mcrypt_encrypt")) { |
|
214 | +function _recaptcha_aes_encrypt($val, $ky) { |
|
215 | + if (!function_exists("mcrypt_encrypt")) { |
|
216 | 216 | die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); |
217 | 217 | } |
218 | - $mode=MCRYPT_MODE_CBC; |
|
219 | - $enc=MCRYPT_RIJNDAEL_128; |
|
220 | - $val=_recaptcha_aes_pad($val); |
|
218 | + $mode = MCRYPT_MODE_CBC; |
|
219 | + $enc = MCRYPT_RIJNDAEL_128; |
|
220 | + $val = _recaptcha_aes_pad($val); |
|
221 | 221 | return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); |
222 | 222 | } |
223 | 223 | |
224 | 224 | |
225 | -function _recaptcha_mailhide_urlbase64 ($x) { |
|
226 | - return strtr(base64_encode ($x), '+/', '-_'); |
|
225 | +function _recaptcha_mailhide_urlbase64($x) { |
|
226 | + return strtr(base64_encode($x), '+/', '-_'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */ |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | |
236 | 236 | |
237 | 237 | $ky = pack('H*', $privkey); |
238 | - $cryptmail = _recaptcha_aes_encrypt ($email, $ky); |
|
238 | + $cryptmail = _recaptcha_aes_encrypt($email, $ky); |
|
239 | 239 | |
240 | - return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail); |
|
240 | + return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64($cryptmail); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -245,15 +245,15 @@ discard block |
||
245 | 245 | * eg, given johndoe@example,com return ["john", "example.com"]. |
246 | 246 | * the email is then displayed as [email protected] |
247 | 247 | */ |
248 | -function _recaptcha_mailhide_email_parts ($email) { |
|
249 | - $arr = preg_split("/@/", $email ); |
|
248 | +function _recaptcha_mailhide_email_parts($email) { |
|
249 | + $arr = preg_split("/@/", $email); |
|
250 | 250 | |
251 | - if (strlen ($arr[0]) <= 4) { |
|
252 | - $arr[0] = substr ($arr[0], 0, 1); |
|
253 | - } else if (strlen ($arr[0]) <= 6) { |
|
254 | - $arr[0] = substr ($arr[0], 0, 3); |
|
251 | + if (strlen($arr[0]) <= 4) { |
|
252 | + $arr[0] = substr($arr[0], 0, 1); |
|
253 | + } else if (strlen($arr[0]) <= 6) { |
|
254 | + $arr[0] = substr($arr[0], 0, 3); |
|
255 | 255 | } else { |
256 | - $arr[0] = substr ($arr[0], 0, 4); |
|
256 | + $arr[0] = substr($arr[0], 0, 4); |
|
257 | 257 | } |
258 | 258 | return $arr; |
259 | 259 | } |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | * http://www.google.com/recaptcha/mailhide/apikey |
266 | 266 | */ |
267 | 267 | function recaptcha_mailhide_html($pubkey, $privkey, $email) { |
268 | - $emailparts = _recaptcha_mailhide_email_parts ($email); |
|
269 | - $url = recaptcha_mailhide_url ($pubkey, $privkey, $email); |
|
268 | + $emailparts = _recaptcha_mailhide_email_parts($email); |
|
269 | + $url = recaptcha_mailhide_url($pubkey, $privkey, $email); |
|
270 | 270 | |
271 | - return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) . |
|
272 | - "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]); |
|
271 | + return htmlentities($emailparts[0]) . "<a href='" . htmlentities($url) . |
|
272 | + "' onclick=\"window.open('" . htmlentities($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities($emailparts [1]); |
|
273 | 273 | |
274 | 274 | } |
275 | 275 |
@@ -46,8 +46,9 @@ discard block |
||
46 | 46 | */ |
47 | 47 | function _recaptcha_qsencode ($data) { |
48 | 48 | $req = ""; |
49 | - foreach ( $data as $key => $value ) |
|
50 | - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
49 | + foreach ( $data as $key => $value ) { |
|
50 | + $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
51 | + } |
|
51 | 52 | |
52 | 53 | // Cut the last '&' |
53 | 54 | $req=substr($req,0,strlen($req)-1); |
@@ -83,8 +84,10 @@ discard block |
||
83 | 84 | |
84 | 85 | fwrite($fs, $http_request); |
85 | 86 | |
86 | - while ( !feof($fs) ) |
|
87 | - $response .= fgets($fs, 1160); // One TCP-IP packet |
|
87 | + while ( !feof($fs) ) { |
|
88 | + $response .= fgets($fs, 1160); |
|
89 | + } |
|
90 | + // One TCP-IP packet |
|
88 | 91 | fclose($fs); |
89 | 92 | $response = explode("\r\n\r\n", $response, 2); |
90 | 93 | |
@@ -183,8 +186,7 @@ discard block |
||
183 | 186 | |
184 | 187 | if (trim ($answers [0]) == 'true') { |
185 | 188 | $recaptcha_response->is_valid = true; |
186 | - } |
|
187 | - else { |
|
189 | + } else { |
|
188 | 190 | $recaptcha_response->is_valid = false; |
189 | 191 | $recaptcha_response->error = $answers [1]; |
190 | 192 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | /** |
197 | 197 | * Returns the next character from the XML document or void if at end |
198 | 198 | * @access protected |
199 | - * @return mixed |
|
199 | + * @return string|null |
|
200 | 200 | */ |
201 | 201 | function scanCharacter() { |
202 | 202 | if ($this->position < $this->length) { |
@@ -332,6 +332,7 @@ discard block |
||
332 | 332 | * parser options |
333 | 333 | * @var TSax3 instance of user front end class |
334 | 334 | * @access protected |
335 | + * @param TSax3 $htmlsax |
|
335 | 336 | */ |
336 | 337 | function __construct(& $htmlsax) { |
337 | 338 | parent::__construct($htmlsax); |
@@ -397,6 +398,7 @@ discard block |
||
397 | 398 | * parser options |
398 | 399 | * @var TSax3 instance of user front end class |
399 | 400 | * @access protected |
401 | + * @param TSax3 $htmlsax |
|
400 | 402 | */ |
401 | 403 | function __construct(& $htmlsax) { |
402 | 404 | parent::__construct($htmlsax); |
@@ -508,7 +510,7 @@ discard block |
||
508 | 510 | * if supplied argument is not an object. |
509 | 511 | * @param object handler object containing SAX callback methods |
510 | 512 | * @access public |
511 | - * @return mixed |
|
513 | + * @return boolean|null |
|
512 | 514 | */ |
513 | 515 | function set_object(&$object) { |
514 | 516 | if ( is_object($object) ) { |
@@ -546,7 +548,7 @@ discard block |
||
546 | 548 | * @param string name of parser option |
547 | 549 | * @param int (optional) 1 to switch on, 0 for off |
548 | 550 | * @access public |
549 | - * @return boolean |
|
551 | + * @return boolean|null |
|
550 | 552 | */ |
551 | 553 | function set_option($name, $value=1) { |
552 | 554 | if ( array_key_exists($name,$this->state_parser->parser_options) ) { |
@@ -568,6 +570,7 @@ discard block |
||
568 | 570 | * function myDataHander(& $parser,$data){} |
569 | 571 | * </pre> |
570 | 572 | * @param string name of method |
573 | + * @param string $data_method |
|
571 | 574 | * @access public |
572 | 575 | * @return void |
573 | 576 | * @see set_object |
@@ -591,6 +594,8 @@ discard block |
||
591 | 594 | * </pre> |
592 | 595 | * @param string name of open method |
593 | 596 | * @param string name of close method |
597 | + * @param string $opening_method |
|
598 | + * @param string $closing_method |
|
594 | 599 | * @access public |
595 | 600 | * @return void |
596 | 601 | * @see set_object |
@@ -610,6 +615,7 @@ discard block |
||
610 | 615 | * function myPIHander(& $parser,$target, $data){} |
611 | 616 | * </pre> |
612 | 617 | * @param string name of method |
618 | + * @param string $pi_method |
|
613 | 619 | * @access public |
614 | 620 | * @return void |
615 | 621 | * @see set_object |
@@ -628,6 +634,7 @@ discard block |
||
628 | 634 | * function myEscapeHander(& $parser, $data){} |
629 | 635 | * </pre> |
630 | 636 | * @param string name of method |
637 | + * @param string $escape_method |
|
631 | 638 | * @access public |
632 | 639 | * @return void |
633 | 640 | * @see set_object |
@@ -645,6 +652,7 @@ discard block |
||
645 | 652 | * function myJaspHander(& $parser, $data){} |
646 | 653 | * </pre> |
647 | 654 | * @param string name of method |
655 | + * @param string $jasp_method |
|
648 | 656 | * @access public |
649 | 657 | * @return void |
650 | 658 | * @see set_object |
@@ -684,6 +692,7 @@ discard block |
||
684 | 692 | /** |
685 | 693 | * Start parsing some XML |
686 | 694 | * @param string XML document |
695 | + * @param string $data |
|
687 | 696 | * @access public |
688 | 697 | * @return void |
689 | 698 | */ |
@@ -39,114 +39,114 @@ discard block |
||
39 | 39 | * @abstract |
40 | 40 | */ |
41 | 41 | class TSax3_StateParser { |
42 | - /** |
|
43 | - * Instance of user front end class to be passed to callbacks |
|
44 | - * @var TSax3 |
|
45 | - * @access private |
|
46 | - */ |
|
47 | - public $htmlsax; |
|
48 | - /** |
|
49 | - * User defined object for handling elements |
|
50 | - * @var object |
|
51 | - * @access private |
|
52 | - */ |
|
53 | - public $handler_object_element; |
|
54 | - /** |
|
55 | - * User defined open tag handler method |
|
56 | - * @var string |
|
57 | - * @access private |
|
58 | - */ |
|
59 | - public $handler_method_opening; |
|
60 | - /** |
|
61 | - * User defined close tag handler method |
|
62 | - * @var string |
|
63 | - * @access private |
|
64 | - */ |
|
65 | - public $handler_method_closing; |
|
66 | - /** |
|
67 | - * User defined object for handling data in elements |
|
68 | - * @var object |
|
69 | - * @access private |
|
70 | - */ |
|
71 | - public $handler_object_data; |
|
72 | - /** |
|
73 | - * User defined data handler method |
|
74 | - * @var string |
|
75 | - * @access private |
|
76 | - */ |
|
77 | - public $handler_method_data; |
|
78 | - /** |
|
79 | - * User defined object for handling processing instructions |
|
80 | - * @var object |
|
81 | - * @access private |
|
82 | - */ |
|
83 | - public $handler_object_pi; |
|
84 | - /** |
|
85 | - * User defined processing instruction handler method |
|
86 | - * @var string |
|
87 | - * @access private |
|
88 | - */ |
|
89 | - public $handler_method_pi; |
|
90 | - /** |
|
91 | - * User defined object for handling JSP/ASP tags |
|
92 | - * @var object |
|
93 | - * @access private |
|
94 | - */ |
|
95 | - public $handler_object_jasp; |
|
96 | - /** |
|
97 | - * User defined JSP/ASP handler method |
|
98 | - * @var string |
|
99 | - * @access private |
|
100 | - */ |
|
101 | - public $handler_method_jasp; |
|
102 | - /** |
|
103 | - * User defined object for handling XML escapes |
|
104 | - * @var object |
|
105 | - * @access private |
|
106 | - */ |
|
107 | - public $handler_object_escape; |
|
108 | - /** |
|
109 | - * User defined XML escape handler method |
|
110 | - * @var string |
|
111 | - * @access private |
|
112 | - */ |
|
113 | - public $handler_method_escape; |
|
114 | - /** |
|
115 | - * User defined handler object or NullHandler |
|
116 | - * @var object |
|
117 | - * @access private |
|
118 | - */ |
|
119 | - public $handler_default; |
|
120 | - /** |
|
121 | - * Parser options determining parsing behavior |
|
122 | - * @var array |
|
123 | - * @access private |
|
124 | - */ |
|
125 | - protected $parser_options = array(); |
|
126 | - /** |
|
127 | - * XML document being parsed |
|
128 | - * @var string |
|
129 | - * @access private |
|
130 | - */ |
|
131 | - protected $rawtext; |
|
132 | - /** |
|
133 | - * Position in XML document relative to start (0) |
|
134 | - * @var int |
|
135 | - * @access private |
|
136 | - */ |
|
137 | - protected $position; |
|
138 | - /** |
|
139 | - * Length of the XML document in characters |
|
140 | - * @var int |
|
141 | - * @access private |
|
142 | - */ |
|
143 | - protected $length; |
|
144 | - /** |
|
145 | - * Array of state objects |
|
146 | - * @var array |
|
147 | - * @access private |
|
148 | - */ |
|
149 | - protected $State = array(); |
|
42 | + /** |
|
43 | + * Instance of user front end class to be passed to callbacks |
|
44 | + * @var TSax3 |
|
45 | + * @access private |
|
46 | + */ |
|
47 | + public $htmlsax; |
|
48 | + /** |
|
49 | + * User defined object for handling elements |
|
50 | + * @var object |
|
51 | + * @access private |
|
52 | + */ |
|
53 | + public $handler_object_element; |
|
54 | + /** |
|
55 | + * User defined open tag handler method |
|
56 | + * @var string |
|
57 | + * @access private |
|
58 | + */ |
|
59 | + public $handler_method_opening; |
|
60 | + /** |
|
61 | + * User defined close tag handler method |
|
62 | + * @var string |
|
63 | + * @access private |
|
64 | + */ |
|
65 | + public $handler_method_closing; |
|
66 | + /** |
|
67 | + * User defined object for handling data in elements |
|
68 | + * @var object |
|
69 | + * @access private |
|
70 | + */ |
|
71 | + public $handler_object_data; |
|
72 | + /** |
|
73 | + * User defined data handler method |
|
74 | + * @var string |
|
75 | + * @access private |
|
76 | + */ |
|
77 | + public $handler_method_data; |
|
78 | + /** |
|
79 | + * User defined object for handling processing instructions |
|
80 | + * @var object |
|
81 | + * @access private |
|
82 | + */ |
|
83 | + public $handler_object_pi; |
|
84 | + /** |
|
85 | + * User defined processing instruction handler method |
|
86 | + * @var string |
|
87 | + * @access private |
|
88 | + */ |
|
89 | + public $handler_method_pi; |
|
90 | + /** |
|
91 | + * User defined object for handling JSP/ASP tags |
|
92 | + * @var object |
|
93 | + * @access private |
|
94 | + */ |
|
95 | + public $handler_object_jasp; |
|
96 | + /** |
|
97 | + * User defined JSP/ASP handler method |
|
98 | + * @var string |
|
99 | + * @access private |
|
100 | + */ |
|
101 | + public $handler_method_jasp; |
|
102 | + /** |
|
103 | + * User defined object for handling XML escapes |
|
104 | + * @var object |
|
105 | + * @access private |
|
106 | + */ |
|
107 | + public $handler_object_escape; |
|
108 | + /** |
|
109 | + * User defined XML escape handler method |
|
110 | + * @var string |
|
111 | + * @access private |
|
112 | + */ |
|
113 | + public $handler_method_escape; |
|
114 | + /** |
|
115 | + * User defined handler object or NullHandler |
|
116 | + * @var object |
|
117 | + * @access private |
|
118 | + */ |
|
119 | + public $handler_default; |
|
120 | + /** |
|
121 | + * Parser options determining parsing behavior |
|
122 | + * @var array |
|
123 | + * @access private |
|
124 | + */ |
|
125 | + protected $parser_options = array(); |
|
126 | + /** |
|
127 | + * XML document being parsed |
|
128 | + * @var string |
|
129 | + * @access private |
|
130 | + */ |
|
131 | + protected $rawtext; |
|
132 | + /** |
|
133 | + * Position in XML document relative to start (0) |
|
134 | + * @var int |
|
135 | + * @access private |
|
136 | + */ |
|
137 | + protected $position; |
|
138 | + /** |
|
139 | + * Length of the XML document in characters |
|
140 | + * @var int |
|
141 | + * @access private |
|
142 | + */ |
|
143 | + protected $length; |
|
144 | + /** |
|
145 | + * Array of state objects |
|
146 | + * @var array |
|
147 | + * @access private |
|
148 | + */ |
|
149 | + protected $State = array(); |
|
150 | 150 | |
151 | 151 | const TSAX3_STATE_STOP = 0; |
152 | 152 | const TSAX3_STATE_START = 1; |
@@ -157,166 +157,166 @@ discard block |
||
157 | 157 | const TSAX3_STATE_JASP = 7; |
158 | 158 | const TSAX3_STATE_PI = 8; |
159 | 159 | |
160 | - /** |
|
161 | - * Constructs TSax3_StateParser setting up states |
|
162 | - * @var TSax3 instance of user front end class |
|
163 | - * @access protected |
|
164 | - */ |
|
165 | - protected function __construct($htmlsax) { |
|
166 | - $this->htmlsax = $htmlsax; |
|
167 | - $this->State[self::TSAX3_STATE_START] = new TSax3_StartingState(); |
|
168 | - |
|
169 | - $this->State[self::TSAX3_STATE_CLOSING_TAG] = new TSax3_ClosingTagState(); |
|
170 | - $this->State[self::TSAX3_STATE_TAG] = new TSax3_TagState(); |
|
171 | - $this->State[self::TSAX3_STATE_OPENING_TAG] = new TSax3_OpeningTagState(); |
|
172 | - |
|
173 | - $this->State[self::TSAX3_STATE_PI] = new TSax3_PiState(); |
|
174 | - $this->State[self::TSAX3_STATE_JASP] = new TSax3_JaspState(); |
|
175 | - $this->State[self::TSAX3_STATE_ESCAPE] = new TSax3_EscapeState(); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Moves the position back one character |
|
180 | - * @access protected |
|
181 | - * @return void |
|
182 | - */ |
|
183 | - function unscanCharacter() { |
|
184 | - $this->position -= 1; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Moves the position forward one character |
|
189 | - * @access protected |
|
190 | - * @return void |
|
191 | - */ |
|
192 | - function ignoreCharacter() { |
|
193 | - $this->position += 1; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Returns the next character from the XML document or void if at end |
|
198 | - * @access protected |
|
199 | - * @return mixed |
|
200 | - */ |
|
201 | - function scanCharacter() { |
|
202 | - if ($this->position < $this->length) { |
|
203 | - return $this->rawtext{$this->position++}; |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Returns a string from the current position to the next occurance |
|
209 | - * of the supplied string |
|
210 | - * @param string string to search until |
|
211 | - * @access protected |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - function scanUntilString($string) { |
|
215 | - $start = $this->position; |
|
216 | - $this->position = strpos($this->rawtext, $string, $start); |
|
217 | - if ($this->position === FALSE) { |
|
218 | - $this->position = $this->length; |
|
219 | - } |
|
220 | - return substr($this->rawtext, $start, $this->position - $start); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Returns a string from the current position until the first instance of |
|
225 | - * one of the characters in the supplied string argument |
|
226 | - * @param string string to search until |
|
227 | - * @access protected |
|
228 | - * @return string |
|
229 | - * @abstract |
|
230 | - */ |
|
231 | - function scanUntilCharacters($string) {} |
|
232 | - |
|
233 | - /** |
|
234 | - * Moves the position forward past any whitespace characters |
|
235 | - * @access protected |
|
236 | - * @return void |
|
237 | - * @abstract |
|
238 | - */ |
|
239 | - function ignoreWhitespace() {} |
|
240 | - |
|
241 | - /** |
|
242 | - * Begins the parsing operation, setting up any decorators, depending on |
|
243 | - * parse options invoking _parse() to execute parsing |
|
244 | - * @param string XML document to parse |
|
245 | - * @access protected |
|
246 | - * @return void |
|
247 | - */ |
|
248 | - function parse($data) { |
|
249 | - if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES']==1) { |
|
250 | - $decorator = new TSax3_Trim( |
|
251 | - $this->handler_object_data, |
|
252 | - $this->handler_method_data); |
|
253 | - $this->handler_object_data =& $decorator; |
|
254 | - $this->handler_method_data = 'trimData'; |
|
255 | - } |
|
256 | - if ($this->parser_options['XML_OPTION_CASE_FOLDING']==1) { |
|
257 | - $open_decor = new TSax3_CaseFolding( |
|
258 | - $this->handler_object_element, |
|
259 | - $this->handler_method_opening, |
|
260 | - $this->handler_method_closing); |
|
261 | - $this->handler_object_element =& $open_decor; |
|
262 | - $this->handler_method_opening ='foldOpen'; |
|
263 | - $this->handler_method_closing ='foldClose'; |
|
264 | - } |
|
265 | - if ($this->parser_options['XML_OPTION_LINEFEED_BREAK']==1) { |
|
266 | - $decorator = new TSax3_Linefeed( |
|
267 | - $this->handler_object_data, |
|
268 | - $this->handler_method_data); |
|
269 | - $this->handler_object_data =& $decorator; |
|
270 | - $this->handler_method_data = 'breakData'; |
|
271 | - } |
|
272 | - if ($this->parser_options['XML_OPTION_TAB_BREAK']==1) { |
|
273 | - $decorator = new TSax3_Tab( |
|
274 | - $this->handler_object_data, |
|
275 | - $this->handler_method_data); |
|
276 | - $this->handler_object_data =& $decorator; |
|
277 | - $this->handler_method_data = 'breakData'; |
|
278 | - } |
|
279 | - if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED']==1) { |
|
280 | - $decorator = new TSax3_Entities_Unparsed( |
|
281 | - $this->handler_object_data, |
|
282 | - $this->handler_method_data); |
|
283 | - $this->handler_object_data =& $decorator; |
|
284 | - $this->handler_method_data = 'breakData'; |
|
285 | - } |
|
286 | - if ($this->parser_options['XML_OPTION_ENTITIES_PARSED']==1) { |
|
287 | - $decorator = new TSax3_Entities_Parsed( |
|
288 | - $this->handler_object_data, |
|
289 | - $this->handler_method_data); |
|
290 | - $this->handler_object_data =& $decorator; |
|
291 | - $this->handler_method_data = 'breakData'; |
|
292 | - } |
|
293 | - // Note switched on by default |
|
294 | - if ($this->parser_options['XML_OPTION_STRIP_ESCAPES']==1) { |
|
295 | - $decorator = new TSax3_Escape_Stripper( |
|
296 | - $this->handler_object_escape, |
|
297 | - $this->handler_method_escape); |
|
298 | - $this->handler_object_escape =& $decorator; |
|
299 | - $this->handler_method_escape = 'strip'; |
|
300 | - } |
|
301 | - $this->rawtext = $data; |
|
302 | - $this->length = strlen($data); |
|
303 | - $this->position = 0; |
|
304 | - $this->_parse(); |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Performs the parsing itself, delegating calls to a specific parser |
|
309 | - * state |
|
310 | - * @param constant state object to parse with |
|
311 | - * @access protected |
|
312 | - * @return void |
|
313 | - */ |
|
314 | - function _parse($state = self::TSAX3_STATE_START) { |
|
315 | - do { |
|
316 | - $state = $this->State[$state]->parse($this); |
|
317 | - } while ($state != self::TSAX3_STATE_STOP && |
|
318 | - $this->position < $this->length); |
|
319 | - } |
|
160 | + /** |
|
161 | + * Constructs TSax3_StateParser setting up states |
|
162 | + * @var TSax3 instance of user front end class |
|
163 | + * @access protected |
|
164 | + */ |
|
165 | + protected function __construct($htmlsax) { |
|
166 | + $this->htmlsax = $htmlsax; |
|
167 | + $this->State[self::TSAX3_STATE_START] = new TSax3_StartingState(); |
|
168 | + |
|
169 | + $this->State[self::TSAX3_STATE_CLOSING_TAG] = new TSax3_ClosingTagState(); |
|
170 | + $this->State[self::TSAX3_STATE_TAG] = new TSax3_TagState(); |
|
171 | + $this->State[self::TSAX3_STATE_OPENING_TAG] = new TSax3_OpeningTagState(); |
|
172 | + |
|
173 | + $this->State[self::TSAX3_STATE_PI] = new TSax3_PiState(); |
|
174 | + $this->State[self::TSAX3_STATE_JASP] = new TSax3_JaspState(); |
|
175 | + $this->State[self::TSAX3_STATE_ESCAPE] = new TSax3_EscapeState(); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Moves the position back one character |
|
180 | + * @access protected |
|
181 | + * @return void |
|
182 | + */ |
|
183 | + function unscanCharacter() { |
|
184 | + $this->position -= 1; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Moves the position forward one character |
|
189 | + * @access protected |
|
190 | + * @return void |
|
191 | + */ |
|
192 | + function ignoreCharacter() { |
|
193 | + $this->position += 1; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Returns the next character from the XML document or void if at end |
|
198 | + * @access protected |
|
199 | + * @return mixed |
|
200 | + */ |
|
201 | + function scanCharacter() { |
|
202 | + if ($this->position < $this->length) { |
|
203 | + return $this->rawtext{$this->position++}; |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Returns a string from the current position to the next occurance |
|
209 | + * of the supplied string |
|
210 | + * @param string string to search until |
|
211 | + * @access protected |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + function scanUntilString($string) { |
|
215 | + $start = $this->position; |
|
216 | + $this->position = strpos($this->rawtext, $string, $start); |
|
217 | + if ($this->position === FALSE) { |
|
218 | + $this->position = $this->length; |
|
219 | + } |
|
220 | + return substr($this->rawtext, $start, $this->position - $start); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Returns a string from the current position until the first instance of |
|
225 | + * one of the characters in the supplied string argument |
|
226 | + * @param string string to search until |
|
227 | + * @access protected |
|
228 | + * @return string |
|
229 | + * @abstract |
|
230 | + */ |
|
231 | + function scanUntilCharacters($string) {} |
|
232 | + |
|
233 | + /** |
|
234 | + * Moves the position forward past any whitespace characters |
|
235 | + * @access protected |
|
236 | + * @return void |
|
237 | + * @abstract |
|
238 | + */ |
|
239 | + function ignoreWhitespace() {} |
|
240 | + |
|
241 | + /** |
|
242 | + * Begins the parsing operation, setting up any decorators, depending on |
|
243 | + * parse options invoking _parse() to execute parsing |
|
244 | + * @param string XML document to parse |
|
245 | + * @access protected |
|
246 | + * @return void |
|
247 | + */ |
|
248 | + function parse($data) { |
|
249 | + if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES']==1) { |
|
250 | + $decorator = new TSax3_Trim( |
|
251 | + $this->handler_object_data, |
|
252 | + $this->handler_method_data); |
|
253 | + $this->handler_object_data =& $decorator; |
|
254 | + $this->handler_method_data = 'trimData'; |
|
255 | + } |
|
256 | + if ($this->parser_options['XML_OPTION_CASE_FOLDING']==1) { |
|
257 | + $open_decor = new TSax3_CaseFolding( |
|
258 | + $this->handler_object_element, |
|
259 | + $this->handler_method_opening, |
|
260 | + $this->handler_method_closing); |
|
261 | + $this->handler_object_element =& $open_decor; |
|
262 | + $this->handler_method_opening ='foldOpen'; |
|
263 | + $this->handler_method_closing ='foldClose'; |
|
264 | + } |
|
265 | + if ($this->parser_options['XML_OPTION_LINEFEED_BREAK']==1) { |
|
266 | + $decorator = new TSax3_Linefeed( |
|
267 | + $this->handler_object_data, |
|
268 | + $this->handler_method_data); |
|
269 | + $this->handler_object_data =& $decorator; |
|
270 | + $this->handler_method_data = 'breakData'; |
|
271 | + } |
|
272 | + if ($this->parser_options['XML_OPTION_TAB_BREAK']==1) { |
|
273 | + $decorator = new TSax3_Tab( |
|
274 | + $this->handler_object_data, |
|
275 | + $this->handler_method_data); |
|
276 | + $this->handler_object_data =& $decorator; |
|
277 | + $this->handler_method_data = 'breakData'; |
|
278 | + } |
|
279 | + if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED']==1) { |
|
280 | + $decorator = new TSax3_Entities_Unparsed( |
|
281 | + $this->handler_object_data, |
|
282 | + $this->handler_method_data); |
|
283 | + $this->handler_object_data =& $decorator; |
|
284 | + $this->handler_method_data = 'breakData'; |
|
285 | + } |
|
286 | + if ($this->parser_options['XML_OPTION_ENTITIES_PARSED']==1) { |
|
287 | + $decorator = new TSax3_Entities_Parsed( |
|
288 | + $this->handler_object_data, |
|
289 | + $this->handler_method_data); |
|
290 | + $this->handler_object_data =& $decorator; |
|
291 | + $this->handler_method_data = 'breakData'; |
|
292 | + } |
|
293 | + // Note switched on by default |
|
294 | + if ($this->parser_options['XML_OPTION_STRIP_ESCAPES']==1) { |
|
295 | + $decorator = new TSax3_Escape_Stripper( |
|
296 | + $this->handler_object_escape, |
|
297 | + $this->handler_method_escape); |
|
298 | + $this->handler_object_escape =& $decorator; |
|
299 | + $this->handler_method_escape = 'strip'; |
|
300 | + } |
|
301 | + $this->rawtext = $data; |
|
302 | + $this->length = strlen($data); |
|
303 | + $this->position = 0; |
|
304 | + $this->_parse(); |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Performs the parsing itself, delegating calls to a specific parser |
|
309 | + * state |
|
310 | + * @param constant state object to parse with |
|
311 | + * @access protected |
|
312 | + * @return void |
|
313 | + */ |
|
314 | + function _parse($state = self::TSAX3_STATE_START) { |
|
315 | + do { |
|
316 | + $state = $this->State[$state]->parse($this); |
|
317 | + } while ($state != self::TSAX3_STATE_STOP && |
|
318 | + $this->position < $this->length); |
|
319 | + } |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -327,61 +327,61 @@ discard block |
||
327 | 327 | * @see TSax3_StateParser_Gtet430 |
328 | 328 | */ |
329 | 329 | class TSax3_StateParser_Lt430 extends TSax3_StateParser { |
330 | - /** |
|
331 | - * Constructs TSax3_StateParser_Lt430 defining available |
|
332 | - * parser options |
|
333 | - * @var TSax3 instance of user front end class |
|
334 | - * @access protected |
|
335 | - */ |
|
336 | - function __construct(& $htmlsax) { |
|
337 | - parent::__construct($htmlsax); |
|
338 | - $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0; |
|
339 | - $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0; |
|
340 | - $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0; |
|
341 | - $this->parser_options['XML_OPTION_TAB_BREAK'] = 0; |
|
342 | - $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0; |
|
343 | - $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0; |
|
344 | - $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0; |
|
330 | + /** |
|
331 | + * Constructs TSax3_StateParser_Lt430 defining available |
|
332 | + * parser options |
|
333 | + * @var TSax3 instance of user front end class |
|
334 | + * @access protected |
|
335 | + */ |
|
336 | + function __construct(& $htmlsax) { |
|
337 | + parent::__construct($htmlsax); |
|
338 | + $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0; |
|
339 | + $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0; |
|
340 | + $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0; |
|
341 | + $this->parser_options['XML_OPTION_TAB_BREAK'] = 0; |
|
342 | + $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0; |
|
343 | + $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0; |
|
344 | + $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0; |
|
345 | 345 | //var_dump($this->parser_options); |
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Returns a string from the current position until the first instance of |
|
350 | - * one of the characters in the supplied string argument |
|
351 | - * @param string string to search until |
|
352 | - * @access protected |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - function scanUntilCharacters($string) { |
|
356 | - $startpos = $this->position; |
|
357 | - while ($this->position < $this->length && strpos($string, $this->rawtext{$this->position}) === FALSE) { |
|
358 | - $this->position++; |
|
359 | - } |
|
360 | - return substr($this->rawtext, $startpos, $this->position - $startpos); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Moves the position forward past any whitespace characters |
|
365 | - * @access protected |
|
366 | - * @return void |
|
367 | - */ |
|
368 | - function ignoreWhitespace() { |
|
369 | - while ($this->position < $this->length && |
|
370 | - strpos(" \n\r\t", $this->rawtext{$this->position}) !== FALSE) { |
|
371 | - $this->position++; |
|
372 | - } |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Begins the parsing operation, setting up the unparsed XML entities |
|
377 | - * decorator if necessary then delegating further work to parent |
|
378 | - * @param string XML document to parse |
|
379 | - * @access protected |
|
380 | - * @return void |
|
381 | - */ |
|
382 | - function parse($data) { |
|
383 | - parent::parse($data); |
|
384 | - } |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Returns a string from the current position until the first instance of |
|
350 | + * one of the characters in the supplied string argument |
|
351 | + * @param string string to search until |
|
352 | + * @access protected |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + function scanUntilCharacters($string) { |
|
356 | + $startpos = $this->position; |
|
357 | + while ($this->position < $this->length && strpos($string, $this->rawtext{$this->position}) === FALSE) { |
|
358 | + $this->position++; |
|
359 | + } |
|
360 | + return substr($this->rawtext, $startpos, $this->position - $startpos); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Moves the position forward past any whitespace characters |
|
365 | + * @access protected |
|
366 | + * @return void |
|
367 | + */ |
|
368 | + function ignoreWhitespace() { |
|
369 | + while ($this->position < $this->length && |
|
370 | + strpos(" \n\r\t", $this->rawtext{$this->position}) !== FALSE) { |
|
371 | + $this->position++; |
|
372 | + } |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Begins the parsing operation, setting up the unparsed XML entities |
|
377 | + * decorator if necessary then delegating further work to parent |
|
378 | + * @param string XML document to parse |
|
379 | + * @access protected |
|
380 | + * @return void |
|
381 | + */ |
|
382 | + function parse($data) { |
|
383 | + parent::parse($data); |
|
384 | + } |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -392,56 +392,56 @@ discard block |
||
392 | 392 | * @see TSax3_StateParser_Lt430 |
393 | 393 | */ |
394 | 394 | class TSax3_StateParser_Gtet430 extends TSax3_StateParser { |
395 | - /** |
|
396 | - * Constructs TSax3_StateParser_Gtet430 defining available |
|
397 | - * parser options |
|
398 | - * @var TSax3 instance of user front end class |
|
399 | - * @access protected |
|
400 | - */ |
|
401 | - function __construct(& $htmlsax) { |
|
402 | - parent::__construct($htmlsax); |
|
403 | - $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0; |
|
404 | - $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0; |
|
405 | - $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0; |
|
406 | - $this->parser_options['XML_OPTION_TAB_BREAK'] = 0; |
|
407 | - $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0; |
|
408 | - $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0; |
|
409 | - $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0; |
|
410 | - } |
|
411 | - /** |
|
412 | - * Returns a string from the current position until the first instance of |
|
413 | - * one of the characters in the supplied string argument. |
|
414 | - * @param string string to search until |
|
415 | - * @access protected |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - function scanUntilCharacters($string) { |
|
419 | - $startpos = $this->position; |
|
420 | - $length = strcspn($this->rawtext, $string, $startpos); |
|
421 | - $this->position += $length; |
|
422 | - return substr($this->rawtext, $startpos, $length); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Moves the position forward past any whitespace characters |
|
427 | - * @access protected |
|
428 | - * @return void |
|
429 | - */ |
|
430 | - function ignoreWhitespace() { |
|
431 | - $this->position += strspn($this->rawtext, " \n\r\t", $this->position); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Begins the parsing operation, setting up the parsed and unparsed |
|
436 | - * XML entity decorators if necessary then delegating further work |
|
437 | - * to parent |
|
438 | - * @param string XML document to parse |
|
439 | - * @access protected |
|
440 | - * @return void |
|
441 | - */ |
|
442 | - function parse($data) { |
|
443 | - parent::parse($data); |
|
444 | - } |
|
395 | + /** |
|
396 | + * Constructs TSax3_StateParser_Gtet430 defining available |
|
397 | + * parser options |
|
398 | + * @var TSax3 instance of user front end class |
|
399 | + * @access protected |
|
400 | + */ |
|
401 | + function __construct(& $htmlsax) { |
|
402 | + parent::__construct($htmlsax); |
|
403 | + $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0; |
|
404 | + $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0; |
|
405 | + $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0; |
|
406 | + $this->parser_options['XML_OPTION_TAB_BREAK'] = 0; |
|
407 | + $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0; |
|
408 | + $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0; |
|
409 | + $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0; |
|
410 | + } |
|
411 | + /** |
|
412 | + * Returns a string from the current position until the first instance of |
|
413 | + * one of the characters in the supplied string argument. |
|
414 | + * @param string string to search until |
|
415 | + * @access protected |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + function scanUntilCharacters($string) { |
|
419 | + $startpos = $this->position; |
|
420 | + $length = strcspn($this->rawtext, $string, $startpos); |
|
421 | + $this->position += $length; |
|
422 | + return substr($this->rawtext, $startpos, $length); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Moves the position forward past any whitespace characters |
|
427 | + * @access protected |
|
428 | + * @return void |
|
429 | + */ |
|
430 | + function ignoreWhitespace() { |
|
431 | + $this->position += strspn($this->rawtext, " \n\r\t", $this->position); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Begins the parsing operation, setting up the parsed and unparsed |
|
436 | + * XML entity decorators if necessary then delegating further work |
|
437 | + * to parent |
|
438 | + * @param string XML document to parse |
|
439 | + * @access protected |
|
440 | + * @return void |
|
441 | + */ |
|
442 | + function parse($data) { |
|
443 | + parent::parse($data); |
|
444 | + } |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -450,13 +450,13 @@ discard block |
||
450 | 450 | * @access protected |
451 | 451 | */ |
452 | 452 | class TSax3_NullHandler { |
453 | - /** |
|
454 | - * Generic handler method which does nothing |
|
455 | - * @access protected |
|
456 | - * @return void |
|
457 | - */ |
|
458 | - function DoNothing() { |
|
459 | - } |
|
453 | + /** |
|
454 | + * Generic handler method which does nothing |
|
455 | + * @access protected |
|
456 | + * @return void |
|
457 | + */ |
|
458 | + function DoNothing() { |
|
459 | + } |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | /** |
@@ -465,229 +465,229 @@ discard block |
||
465 | 465 | * @access public |
466 | 466 | */ |
467 | 467 | class TSax3 { |
468 | - /** |
|
469 | - * Instance of concrete subclass of TSax3_StateParser |
|
470 | - * @var TSax3_StateParser |
|
471 | - * @access private |
|
472 | - */ |
|
473 | - private $state_parser; |
|
474 | - |
|
475 | - /** |
|
476 | - * Constructs TSax3 selecting concrete StateParser subclass |
|
477 | - * depending on PHP version being used as well as setting the default |
|
478 | - * NullHandler for all callbacks<br /> |
|
479 | - * <b>Example:</b> |
|
480 | - * <pre> |
|
481 | - * $myHandler = & new MyHandler(); |
|
482 | - * $parser = new TSax3(); |
|
483 | - * $parser->set_object($myHandler); |
|
484 | - * $parser->set_option('XML_OPTION_CASE_FOLDING'); |
|
485 | - * $parser->set_element_handler('myOpenHandler','myCloseHandler'); |
|
486 | - * $parser->set_data_handler('myDataHandler'); |
|
487 | - * $parser->parser($xml); |
|
488 | - * </pre> |
|
489 | - * @access public |
|
490 | - */ |
|
491 | - function __construct() { |
|
492 | - if (version_compare(phpversion(), '4.3', 'ge')) { |
|
493 | - $this->state_parser = new TSax3_StateParser_Gtet430($this); |
|
494 | - } else { |
|
495 | - $this->state_parser = new TSax3_StateParser_Lt430($this); |
|
496 | - } |
|
497 | - $nullhandler = new TSax3_NullHandler(); |
|
498 | - $this->set_object($nullhandler); |
|
499 | - $this->set_element_handler('DoNothing', 'DoNothing'); |
|
500 | - $this->set_data_handler('DoNothing'); |
|
501 | - $this->set_pi_handler('DoNothing'); |
|
502 | - $this->set_jasp_handler('DoNothing'); |
|
503 | - $this->set_escape_handler('DoNothing'); |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Sets the user defined handler object. Returns a PEAR Error |
|
508 | - * if supplied argument is not an object. |
|
509 | - * @param object handler object containing SAX callback methods |
|
510 | - * @access public |
|
511 | - * @return mixed |
|
512 | - */ |
|
513 | - function set_object(&$object) { |
|
514 | - if ( is_object($object) ) { |
|
515 | - $this->state_parser->handler_default =& $object; |
|
516 | - return true; |
|
517 | - } else { |
|
518 | - require_once('PEAR.php'); |
|
519 | - PEAR::raiseError('TSax3::set_object requires '. |
|
520 | - 'an object instance'); |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Sets a parser option. By default all options are switched off. |
|
526 | - * Returns a PEAR Error if option is invalid<br /> |
|
527 | - * <b>Available options:</b> |
|
528 | - * <ul> |
|
529 | - * <li>XML_OPTION_TRIM_DATA_NODES: trim whitespace off the beginning |
|
530 | - * and end of data passed to the data handler</li> |
|
531 | - * <li>XML_OPTION_LINEFEED_BREAK: linefeeds result in additional data |
|
532 | - * handler calls</li> |
|
533 | - * <li>XML_OPTION_TAB_BREAK: tabs result in additional data handler |
|
534 | - * calls</li> |
|
535 | - * <li>XML_OPTION_ENTITIES_UNPARSED: XML entities are returned as |
|
536 | - * seperate data handler calls in unparsed form</li> |
|
537 | - * <li>XML_OPTION_ENTITIES_PARSED: (PHP 4.3.0+ only) XML entities are |
|
538 | - * returned as seperate data handler calls and are parsed with |
|
539 | - * PHP's html_entity_decode() function</li> |
|
540 | - * <li>XML_OPTION_STRIP_ESCAPES: strips out the -- -- comment markers |
|
541 | - * or CDATA markup inside an XML escape, if found.</li> |
|
542 | - * </ul> |
|
543 | - * To get HTMLSax to behave in the same way as the native PHP SAX parser, |
|
544 | - * using it's default state, you need to switch on XML_OPTION_LINEFEED_BREAK, |
|
545 | - * XML_OPTION_ENTITIES_PARSED and XML_OPTION_CASE_FOLDING |
|
546 | - * @param string name of parser option |
|
547 | - * @param int (optional) 1 to switch on, 0 for off |
|
548 | - * @access public |
|
549 | - * @return boolean |
|
550 | - */ |
|
551 | - function set_option($name, $value=1) { |
|
552 | - if ( array_key_exists($name,$this->state_parser->parser_options) ) { |
|
553 | - $this->state_parser->parser_options[$name] = $value; |
|
554 | - return true; |
|
555 | - } else { |
|
556 | - require_once('PEAR.php'); |
|
557 | - PEAR::raiseError('TSax3::set_option('.$name.') illegal'); |
|
558 | - } |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * Sets the data handler method which deals with the contents of XML |
|
563 | - * elements.<br /> |
|
564 | - * The handler method must accept two arguments, the first being an |
|
565 | - * instance of TSax3 and the second being the contents of an |
|
566 | - * XML element e.g. |
|
567 | - * <pre> |
|
568 | - * function myDataHander(& $parser,$data){} |
|
569 | - * </pre> |
|
570 | - * @param string name of method |
|
571 | - * @access public |
|
572 | - * @return void |
|
573 | - * @see set_object |
|
574 | - */ |
|
575 | - function set_data_handler($data_method) { |
|
576 | - $this->state_parser->handler_object_data =& $this->state_parser->handler_default; |
|
577 | - $this->state_parser->handler_method_data = $data_method; |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * Sets the open and close tag handlers |
|
582 | - * <br />The open handler method must accept three arguments; the parser, |
|
583 | - * the tag name and an array of attributes e.g. |
|
584 | - * <pre> |
|
585 | - * function myOpenHander(& $parser,$tagname,$attrs=array()){} |
|
586 | - * </pre> |
|
587 | - * The close handler method must accept two arguments; the parser and |
|
588 | - * the tag name e.g. |
|
589 | - * <pre> |
|
590 | - * function myCloseHander(& $parser,$tagname){} |
|
591 | - * </pre> |
|
592 | - * @param string name of open method |
|
593 | - * @param string name of close method |
|
594 | - * @access public |
|
595 | - * @return void |
|
596 | - * @see set_object |
|
597 | - */ |
|
598 | - function set_element_handler($opening_method, $closing_method) { |
|
599 | - $this->state_parser->handler_object_element =& $this->state_parser->handler_default; |
|
600 | - $this->state_parser->handler_method_opening = $opening_method; |
|
601 | - $this->state_parser->handler_method_closing = $closing_method; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Sets the processing instruction handler method e.g. for PHP open |
|
606 | - * and close tags<br /> |
|
607 | - * The handler method must accept three arguments; the parser, the |
|
608 | - * PI target and data inside the PI |
|
609 | - * <pre> |
|
610 | - * function myPIHander(& $parser,$target, $data){} |
|
611 | - * </pre> |
|
612 | - * @param string name of method |
|
613 | - * @access public |
|
614 | - * @return void |
|
615 | - * @see set_object |
|
616 | - */ |
|
617 | - function set_pi_handler($pi_method) { |
|
618 | - $this->state_parser->handler_object_pi =& $this->state_parser->handler_default; |
|
619 | - $this->state_parser->handler_method_pi = $pi_method; |
|
620 | - } |
|
621 | - |
|
622 | - /** |
|
623 | - * Sets the XML escape handler method e.g. for comments and doctype |
|
624 | - * declarations<br /> |
|
625 | - * The handler method must accept two arguments; the parser and the |
|
626 | - * contents of the escaped section |
|
627 | - * <pre> |
|
628 | - * function myEscapeHander(& $parser, $data){} |
|
629 | - * </pre> |
|
630 | - * @param string name of method |
|
631 | - * @access public |
|
632 | - * @return void |
|
633 | - * @see set_object |
|
634 | - */ |
|
635 | - function set_escape_handler($escape_method) { |
|
636 | - $this->state_parser->handler_object_escape =& $this->state_parser->handler_default; |
|
637 | - $this->state_parser->handler_method_escape = $escape_method; |
|
638 | - } |
|
639 | - |
|
640 | - /** |
|
641 | - * Sets the JSP/ASP markup handler<br /> |
|
642 | - * The handler method must accept two arguments; the parser and |
|
643 | - * body of the JASP tag |
|
644 | - * <pre> |
|
645 | - * function myJaspHander(& $parser, $data){} |
|
646 | - * </pre> |
|
647 | - * @param string name of method |
|
648 | - * @access public |
|
649 | - * @return void |
|
650 | - * @see set_object |
|
651 | - */ |
|
652 | - function set_jasp_handler ($jasp_method) { |
|
653 | - $this->state_parser->handler_object_jasp =& $this->state_parser->handler_default; |
|
654 | - $this->state_parser->handler_method_jasp = $jasp_method; |
|
655 | - } |
|
656 | - |
|
657 | - /** |
|
658 | - * Returns the current string position of the "cursor" inside the XML |
|
659 | - * document |
|
660 | - * <br />Intended for use from within a user defined handler called |
|
661 | - * via the $parser reference e.g. |
|
662 | - * <pre> |
|
663 | - * function myDataHandler(& $parser,$data) { |
|
664 | - * echo( 'Current position: '.$parser->get_current_position() ); |
|
665 | - * } |
|
666 | - * </pre> |
|
667 | - * @access public |
|
668 | - * @return int |
|
669 | - * @see get_length |
|
670 | - */ |
|
671 | - function get_current_position() { |
|
672 | - return $this->state_parser->position; |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Returns the string length of the XML document being parsed |
|
677 | - * @access public |
|
678 | - * @return int |
|
679 | - */ |
|
680 | - function get_length() { |
|
681 | - return $this->state_parser->length; |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Start parsing some XML |
|
686 | - * @param string XML document |
|
687 | - * @access public |
|
688 | - * @return void |
|
689 | - */ |
|
690 | - function parse($data) { |
|
691 | - $this->state_parser->parse($data); |
|
692 | - } |
|
468 | + /** |
|
469 | + * Instance of concrete subclass of TSax3_StateParser |
|
470 | + * @var TSax3_StateParser |
|
471 | + * @access private |
|
472 | + */ |
|
473 | + private $state_parser; |
|
474 | + |
|
475 | + /** |
|
476 | + * Constructs TSax3 selecting concrete StateParser subclass |
|
477 | + * depending on PHP version being used as well as setting the default |
|
478 | + * NullHandler for all callbacks<br /> |
|
479 | + * <b>Example:</b> |
|
480 | + * <pre> |
|
481 | + * $myHandler = & new MyHandler(); |
|
482 | + * $parser = new TSax3(); |
|
483 | + * $parser->set_object($myHandler); |
|
484 | + * $parser->set_option('XML_OPTION_CASE_FOLDING'); |
|
485 | + * $parser->set_element_handler('myOpenHandler','myCloseHandler'); |
|
486 | + * $parser->set_data_handler('myDataHandler'); |
|
487 | + * $parser->parser($xml); |
|
488 | + * </pre> |
|
489 | + * @access public |
|
490 | + */ |
|
491 | + function __construct() { |
|
492 | + if (version_compare(phpversion(), '4.3', 'ge')) { |
|
493 | + $this->state_parser = new TSax3_StateParser_Gtet430($this); |
|
494 | + } else { |
|
495 | + $this->state_parser = new TSax3_StateParser_Lt430($this); |
|
496 | + } |
|
497 | + $nullhandler = new TSax3_NullHandler(); |
|
498 | + $this->set_object($nullhandler); |
|
499 | + $this->set_element_handler('DoNothing', 'DoNothing'); |
|
500 | + $this->set_data_handler('DoNothing'); |
|
501 | + $this->set_pi_handler('DoNothing'); |
|
502 | + $this->set_jasp_handler('DoNothing'); |
|
503 | + $this->set_escape_handler('DoNothing'); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Sets the user defined handler object. Returns a PEAR Error |
|
508 | + * if supplied argument is not an object. |
|
509 | + * @param object handler object containing SAX callback methods |
|
510 | + * @access public |
|
511 | + * @return mixed |
|
512 | + */ |
|
513 | + function set_object(&$object) { |
|
514 | + if ( is_object($object) ) { |
|
515 | + $this->state_parser->handler_default =& $object; |
|
516 | + return true; |
|
517 | + } else { |
|
518 | + require_once('PEAR.php'); |
|
519 | + PEAR::raiseError('TSax3::set_object requires '. |
|
520 | + 'an object instance'); |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Sets a parser option. By default all options are switched off. |
|
526 | + * Returns a PEAR Error if option is invalid<br /> |
|
527 | + * <b>Available options:</b> |
|
528 | + * <ul> |
|
529 | + * <li>XML_OPTION_TRIM_DATA_NODES: trim whitespace off the beginning |
|
530 | + * and end of data passed to the data handler</li> |
|
531 | + * <li>XML_OPTION_LINEFEED_BREAK: linefeeds result in additional data |
|
532 | + * handler calls</li> |
|
533 | + * <li>XML_OPTION_TAB_BREAK: tabs result in additional data handler |
|
534 | + * calls</li> |
|
535 | + * <li>XML_OPTION_ENTITIES_UNPARSED: XML entities are returned as |
|
536 | + * seperate data handler calls in unparsed form</li> |
|
537 | + * <li>XML_OPTION_ENTITIES_PARSED: (PHP 4.3.0+ only) XML entities are |
|
538 | + * returned as seperate data handler calls and are parsed with |
|
539 | + * PHP's html_entity_decode() function</li> |
|
540 | + * <li>XML_OPTION_STRIP_ESCAPES: strips out the -- -- comment markers |
|
541 | + * or CDATA markup inside an XML escape, if found.</li> |
|
542 | + * </ul> |
|
543 | + * To get HTMLSax to behave in the same way as the native PHP SAX parser, |
|
544 | + * using it's default state, you need to switch on XML_OPTION_LINEFEED_BREAK, |
|
545 | + * XML_OPTION_ENTITIES_PARSED and XML_OPTION_CASE_FOLDING |
|
546 | + * @param string name of parser option |
|
547 | + * @param int (optional) 1 to switch on, 0 for off |
|
548 | + * @access public |
|
549 | + * @return boolean |
|
550 | + */ |
|
551 | + function set_option($name, $value=1) { |
|
552 | + if ( array_key_exists($name,$this->state_parser->parser_options) ) { |
|
553 | + $this->state_parser->parser_options[$name] = $value; |
|
554 | + return true; |
|
555 | + } else { |
|
556 | + require_once('PEAR.php'); |
|
557 | + PEAR::raiseError('TSax3::set_option('.$name.') illegal'); |
|
558 | + } |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * Sets the data handler method which deals with the contents of XML |
|
563 | + * elements.<br /> |
|
564 | + * The handler method must accept two arguments, the first being an |
|
565 | + * instance of TSax3 and the second being the contents of an |
|
566 | + * XML element e.g. |
|
567 | + * <pre> |
|
568 | + * function myDataHander(& $parser,$data){} |
|
569 | + * </pre> |
|
570 | + * @param string name of method |
|
571 | + * @access public |
|
572 | + * @return void |
|
573 | + * @see set_object |
|
574 | + */ |
|
575 | + function set_data_handler($data_method) { |
|
576 | + $this->state_parser->handler_object_data =& $this->state_parser->handler_default; |
|
577 | + $this->state_parser->handler_method_data = $data_method; |
|
578 | + } |
|
579 | + |
|
580 | + /** |
|
581 | + * Sets the open and close tag handlers |
|
582 | + * <br />The open handler method must accept three arguments; the parser, |
|
583 | + * the tag name and an array of attributes e.g. |
|
584 | + * <pre> |
|
585 | + * function myOpenHander(& $parser,$tagname,$attrs=array()){} |
|
586 | + * </pre> |
|
587 | + * The close handler method must accept two arguments; the parser and |
|
588 | + * the tag name e.g. |
|
589 | + * <pre> |
|
590 | + * function myCloseHander(& $parser,$tagname){} |
|
591 | + * </pre> |
|
592 | + * @param string name of open method |
|
593 | + * @param string name of close method |
|
594 | + * @access public |
|
595 | + * @return void |
|
596 | + * @see set_object |
|
597 | + */ |
|
598 | + function set_element_handler($opening_method, $closing_method) { |
|
599 | + $this->state_parser->handler_object_element =& $this->state_parser->handler_default; |
|
600 | + $this->state_parser->handler_method_opening = $opening_method; |
|
601 | + $this->state_parser->handler_method_closing = $closing_method; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Sets the processing instruction handler method e.g. for PHP open |
|
606 | + * and close tags<br /> |
|
607 | + * The handler method must accept three arguments; the parser, the |
|
608 | + * PI target and data inside the PI |
|
609 | + * <pre> |
|
610 | + * function myPIHander(& $parser,$target, $data){} |
|
611 | + * </pre> |
|
612 | + * @param string name of method |
|
613 | + * @access public |
|
614 | + * @return void |
|
615 | + * @see set_object |
|
616 | + */ |
|
617 | + function set_pi_handler($pi_method) { |
|
618 | + $this->state_parser->handler_object_pi =& $this->state_parser->handler_default; |
|
619 | + $this->state_parser->handler_method_pi = $pi_method; |
|
620 | + } |
|
621 | + |
|
622 | + /** |
|
623 | + * Sets the XML escape handler method e.g. for comments and doctype |
|
624 | + * declarations<br /> |
|
625 | + * The handler method must accept two arguments; the parser and the |
|
626 | + * contents of the escaped section |
|
627 | + * <pre> |
|
628 | + * function myEscapeHander(& $parser, $data){} |
|
629 | + * </pre> |
|
630 | + * @param string name of method |
|
631 | + * @access public |
|
632 | + * @return void |
|
633 | + * @see set_object |
|
634 | + */ |
|
635 | + function set_escape_handler($escape_method) { |
|
636 | + $this->state_parser->handler_object_escape =& $this->state_parser->handler_default; |
|
637 | + $this->state_parser->handler_method_escape = $escape_method; |
|
638 | + } |
|
639 | + |
|
640 | + /** |
|
641 | + * Sets the JSP/ASP markup handler<br /> |
|
642 | + * The handler method must accept two arguments; the parser and |
|
643 | + * body of the JASP tag |
|
644 | + * <pre> |
|
645 | + * function myJaspHander(& $parser, $data){} |
|
646 | + * </pre> |
|
647 | + * @param string name of method |
|
648 | + * @access public |
|
649 | + * @return void |
|
650 | + * @see set_object |
|
651 | + */ |
|
652 | + function set_jasp_handler ($jasp_method) { |
|
653 | + $this->state_parser->handler_object_jasp =& $this->state_parser->handler_default; |
|
654 | + $this->state_parser->handler_method_jasp = $jasp_method; |
|
655 | + } |
|
656 | + |
|
657 | + /** |
|
658 | + * Returns the current string position of the "cursor" inside the XML |
|
659 | + * document |
|
660 | + * <br />Intended for use from within a user defined handler called |
|
661 | + * via the $parser reference e.g. |
|
662 | + * <pre> |
|
663 | + * function myDataHandler(& $parser,$data) { |
|
664 | + * echo( 'Current position: '.$parser->get_current_position() ); |
|
665 | + * } |
|
666 | + * </pre> |
|
667 | + * @access public |
|
668 | + * @return int |
|
669 | + * @see get_length |
|
670 | + */ |
|
671 | + function get_current_position() { |
|
672 | + return $this->state_parser->position; |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Returns the string length of the XML document being parsed |
|
677 | + * @access public |
|
678 | + * @return int |
|
679 | + */ |
|
680 | + function get_length() { |
|
681 | + return $this->state_parser->length; |
|
682 | + } |
|
683 | + |
|
684 | + /** |
|
685 | + * Start parsing some XML |
|
686 | + * @param string XML document |
|
687 | + * @access public |
|
688 | + * @return void |
|
689 | + */ |
|
690 | + function parse($data) { |
|
691 | + $this->state_parser->parse($data); |
|
692 | + } |
|
693 | 693 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | * Required classes |
30 | 30 | */ |
31 | 31 | |
32 | -require_once(dirname(__FILE__).'/HTMLSax3/States.php'); |
|
33 | -require_once(dirname(__FILE__).'/HTMLSax3/Decorators.php'); |
|
32 | +require_once(dirname(__FILE__) . '/HTMLSax3/States.php'); |
|
33 | +require_once(dirname(__FILE__) . '/HTMLSax3/Decorators.php'); |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Base State Parser |
@@ -246,56 +246,56 @@ discard block |
||
246 | 246 | * @return void |
247 | 247 | */ |
248 | 248 | function parse($data) { |
249 | - if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES']==1) { |
|
249 | + if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES'] == 1) { |
|
250 | 250 | $decorator = new TSax3_Trim( |
251 | 251 | $this->handler_object_data, |
252 | 252 | $this->handler_method_data); |
253 | - $this->handler_object_data =& $decorator; |
|
253 | + $this->handler_object_data = & $decorator; |
|
254 | 254 | $this->handler_method_data = 'trimData'; |
255 | 255 | } |
256 | - if ($this->parser_options['XML_OPTION_CASE_FOLDING']==1) { |
|
256 | + if ($this->parser_options['XML_OPTION_CASE_FOLDING'] == 1) { |
|
257 | 257 | $open_decor = new TSax3_CaseFolding( |
258 | 258 | $this->handler_object_element, |
259 | 259 | $this->handler_method_opening, |
260 | 260 | $this->handler_method_closing); |
261 | - $this->handler_object_element =& $open_decor; |
|
262 | - $this->handler_method_opening ='foldOpen'; |
|
263 | - $this->handler_method_closing ='foldClose'; |
|
261 | + $this->handler_object_element = & $open_decor; |
|
262 | + $this->handler_method_opening = 'foldOpen'; |
|
263 | + $this->handler_method_closing = 'foldClose'; |
|
264 | 264 | } |
265 | - if ($this->parser_options['XML_OPTION_LINEFEED_BREAK']==1) { |
|
265 | + if ($this->parser_options['XML_OPTION_LINEFEED_BREAK'] == 1) { |
|
266 | 266 | $decorator = new TSax3_Linefeed( |
267 | 267 | $this->handler_object_data, |
268 | 268 | $this->handler_method_data); |
269 | - $this->handler_object_data =& $decorator; |
|
269 | + $this->handler_object_data = & $decorator; |
|
270 | 270 | $this->handler_method_data = 'breakData'; |
271 | 271 | } |
272 | - if ($this->parser_options['XML_OPTION_TAB_BREAK']==1) { |
|
272 | + if ($this->parser_options['XML_OPTION_TAB_BREAK'] == 1) { |
|
273 | 273 | $decorator = new TSax3_Tab( |
274 | 274 | $this->handler_object_data, |
275 | 275 | $this->handler_method_data); |
276 | - $this->handler_object_data =& $decorator; |
|
276 | + $this->handler_object_data = & $decorator; |
|
277 | 277 | $this->handler_method_data = 'breakData'; |
278 | 278 | } |
279 | - if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED']==1) { |
|
279 | + if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] == 1) { |
|
280 | 280 | $decorator = new TSax3_Entities_Unparsed( |
281 | 281 | $this->handler_object_data, |
282 | 282 | $this->handler_method_data); |
283 | - $this->handler_object_data =& $decorator; |
|
283 | + $this->handler_object_data = & $decorator; |
|
284 | 284 | $this->handler_method_data = 'breakData'; |
285 | 285 | } |
286 | - if ($this->parser_options['XML_OPTION_ENTITIES_PARSED']==1) { |
|
286 | + if ($this->parser_options['XML_OPTION_ENTITIES_PARSED'] == 1) { |
|
287 | 287 | $decorator = new TSax3_Entities_Parsed( |
288 | 288 | $this->handler_object_data, |
289 | 289 | $this->handler_method_data); |
290 | - $this->handler_object_data =& $decorator; |
|
290 | + $this->handler_object_data = & $decorator; |
|
291 | 291 | $this->handler_method_data = 'breakData'; |
292 | 292 | } |
293 | 293 | // Note switched on by default |
294 | - if ($this->parser_options['XML_OPTION_STRIP_ESCAPES']==1) { |
|
294 | + if ($this->parser_options['XML_OPTION_STRIP_ESCAPES'] == 1) { |
|
295 | 295 | $decorator = new TSax3_Escape_Stripper( |
296 | 296 | $this->handler_object_escape, |
297 | 297 | $this->handler_method_escape); |
298 | - $this->handler_object_escape =& $decorator; |
|
298 | + $this->handler_object_escape = & $decorator; |
|
299 | 299 | $this->handler_method_escape = 'strip'; |
300 | 300 | } |
301 | 301 | $this->rawtext = $data; |
@@ -511,12 +511,12 @@ discard block |
||
511 | 511 | * @return mixed |
512 | 512 | */ |
513 | 513 | function set_object(&$object) { |
514 | - if ( is_object($object) ) { |
|
515 | - $this->state_parser->handler_default =& $object; |
|
514 | + if (is_object($object)) { |
|
515 | + $this->state_parser->handler_default = & $object; |
|
516 | 516 | return true; |
517 | 517 | } else { |
518 | 518 | require_once('PEAR.php'); |
519 | - PEAR::raiseError('TSax3::set_object requires '. |
|
519 | + PEAR::raiseError('TSax3::set_object requires ' . |
|
520 | 520 | 'an object instance'); |
521 | 521 | } |
522 | 522 | } |
@@ -548,13 +548,13 @@ discard block |
||
548 | 548 | * @access public |
549 | 549 | * @return boolean |
550 | 550 | */ |
551 | - function set_option($name, $value=1) { |
|
552 | - if ( array_key_exists($name,$this->state_parser->parser_options) ) { |
|
551 | + function set_option($name, $value = 1) { |
|
552 | + if (array_key_exists($name, $this->state_parser->parser_options)) { |
|
553 | 553 | $this->state_parser->parser_options[$name] = $value; |
554 | 554 | return true; |
555 | 555 | } else { |
556 | 556 | require_once('PEAR.php'); |
557 | - PEAR::raiseError('TSax3::set_option('.$name.') illegal'); |
|
557 | + PEAR::raiseError('TSax3::set_option(' . $name . ') illegal'); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @see set_object |
574 | 574 | */ |
575 | 575 | function set_data_handler($data_method) { |
576 | - $this->state_parser->handler_object_data =& $this->state_parser->handler_default; |
|
576 | + $this->state_parser->handler_object_data = & $this->state_parser->handler_default; |
|
577 | 577 | $this->state_parser->handler_method_data = $data_method; |
578 | 578 | } |
579 | 579 | |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * @see set_object |
597 | 597 | */ |
598 | 598 | function set_element_handler($opening_method, $closing_method) { |
599 | - $this->state_parser->handler_object_element =& $this->state_parser->handler_default; |
|
599 | + $this->state_parser->handler_object_element = & $this->state_parser->handler_default; |
|
600 | 600 | $this->state_parser->handler_method_opening = $opening_method; |
601 | 601 | $this->state_parser->handler_method_closing = $closing_method; |
602 | 602 | } |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | * @see set_object |
616 | 616 | */ |
617 | 617 | function set_pi_handler($pi_method) { |
618 | - $this->state_parser->handler_object_pi =& $this->state_parser->handler_default; |
|
618 | + $this->state_parser->handler_object_pi = & $this->state_parser->handler_default; |
|
619 | 619 | $this->state_parser->handler_method_pi = $pi_method; |
620 | 620 | } |
621 | 621 | |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | * @see set_object |
634 | 634 | */ |
635 | 635 | function set_escape_handler($escape_method) { |
636 | - $this->state_parser->handler_object_escape =& $this->state_parser->handler_default; |
|
636 | + $this->state_parser->handler_object_escape = & $this->state_parser->handler_default; |
|
637 | 637 | $this->state_parser->handler_method_escape = $escape_method; |
638 | 638 | } |
639 | 639 | |
@@ -649,8 +649,8 @@ discard block |
||
649 | 649 | * @return void |
650 | 650 | * @see set_object |
651 | 651 | */ |
652 | - function set_jasp_handler ($jasp_method) { |
|
653 | - $this->state_parser->handler_object_jasp =& $this->state_parser->handler_default; |
|
652 | + function set_jasp_handler($jasp_method) { |
|
653 | + $this->state_parser->handler_object_jasp = & $this->state_parser->handler_default; |
|
654 | 654 | $this->state_parser->handler_method_jasp = $jasp_method; |
655 | 655 | } |
656 | 656 |