This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | class BrowseCitiesPage extends BrowseAbstractPage |
||
0 ignored issues
–
show
|
|||
4 | { |
||
5 | |||
6 | /** |
||
7 | * Standard SS static |
||
8 | **/ |
||
9 | public static $icon = "geobrowser/images/treeicons/BrowseCitiesPage"; |
||
10 | |||
11 | /** |
||
12 | * Standard SS static |
||
13 | **/ |
||
14 | public static $default_parent = "BrowseRegionsPage"; |
||
15 | |||
16 | /** |
||
17 | * Standard SS static |
||
18 | **/ |
||
19 | public static $can_be_root = false; |
||
20 | |||
21 | /** |
||
22 | * Standard SS static |
||
23 | **/ |
||
24 | public static $db = array( |
||
25 | "Latitude" => "Double", |
||
26 | "Longitude" => "Double", |
||
27 | "TimeZone"=> "Varchar(10)", |
||
28 | "County" => "Varchar(25)", |
||
29 | "Code" => "Varchar(4)", |
||
30 | ); |
||
31 | |||
32 | /** |
||
33 | * Standard SS Static |
||
34 | **/ |
||
35 | public static $defaults = array( |
||
36 | "ShowInMenus" => false |
||
37 | ); |
||
38 | |||
39 | /** |
||
40 | * @param Array - $googleMapAddressArray: an array of geographic data provided by google maps |
||
41 | * @param Int - $maxRadius: maximum number of kilometers (as the bird flies) between search point defined in $googleMapAddressArray and city found. |
||
42 | * @return Object | false : returns a BrowseCitiesPage or false if nothing was found |
||
43 | **/ |
||
44 | public static function get_clostest_city_page($googleMapAddressArray, $maxRadius = 500) |
||
45 | { |
||
46 | $cityPage = null; |
||
47 | $suburbPage = null; |
||
48 | $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
||
49 | $existingDistance = $maxRadius+1; |
||
50 | $newDistance = $maxRadius+1; |
||
51 | $existingPage = null; |
||
52 | $newPage = null; |
||
53 | $radiusSelectionSQL = self::radiusDefinitionOtherTable($googleMapAddressArray[0], $googleMapAddressArray[1], "BrowseCitiesPage", "Latitude", "Longitude"); |
||
54 | $sqlQuery = new SQLQuery(); |
||
0 ignored issues
–
show
The class
SQLQuery has been deprecated with message: since version 4.0
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead. ![]() |
|||
55 | $sqlQuery->select = array("{$bt}BrowseCitiesPage{$bt}.{$bt}ID{$bt}, ". $radiusSelectionSQL." as distance"); |
||
56 | $sqlQuery->from[] = "{$bt}BrowseCitiesPage{$bt}"; |
||
57 | $sqlQuery->where[] = $radiusSelectionSQL . " < ".$maxRadius; |
||
58 | $sqlQuery->orderby = " distance "; |
||
59 | $sqlQuery->limit = "1"; |
||
60 | $result = $sqlQuery->execute(); |
||
61 | $page = null; |
||
62 | foreach ($result as $row) { |
||
63 | $existingDistance = $row["distance"]; |
||
64 | $existingPage = DataObject::get_by_id("BrowseCitiesPage", $row["ID"]); |
||
65 | } |
||
66 | $radiusSelectionSQL = self::radiusDefinitionOtherTable($googleMapAddressArray[0], $googleMapAddressArray[1], "cities", "Latitude", "Longitude"); |
||
67 | $sqlQuery = new SQLQuery(); |
||
0 ignored issues
–
show
The class
SQLQuery has been deprecated with message: since version 4.0
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead. ![]() |
|||
68 | $sqlQuery->select = array("cities.CityID", $radiusSelectionSQL." as distance"); |
||
69 | $sqlQuery->from[] = "{$bt}cities{$bt}"; |
||
70 | $sqlQuery->where[] = $radiusSelectionSQL . " < ".$maxRadius; |
||
71 | $sqlQuery->orderby = " distance "; |
||
72 | $sqlQuery->limit = "1"; |
||
73 | $result = $sqlQuery->execute(); |
||
74 | foreach ($result as $row) { |
||
75 | $sameOne = false; |
||
76 | if ($existingPage) { |
||
77 | if ($row["CityID"] == $existingPage->HiddenDataID) { |
||
78 | $sameOne = true; |
||
79 | } |
||
80 | } |
||
81 | if (!$sameOne) { |
||
82 | $newPage = self::create_city_and_parents($row["CityID"]); |
||
83 | $newDistance = $row["distance"]; |
||
84 | } |
||
85 | } |
||
86 | if (($newPage) && ($newDistance < $existingDistance) && ($newDistance < $maxRadius)) { |
||
87 | $cityPage = $newPage; |
||
88 | } elseif ($existingPage && $existingDistance < $maxRadius) { |
||
89 | $cityPage = $existingPage; |
||
90 | } |
||
91 | if ($cityPage) { |
||
92 | if ($cityPage->allowBrowseChildren()) { |
||
93 | $suburbPage = BrowseSuburbPage::create_suburb($googleMapAddressArray, $cityPage); |
||
94 | } |
||
95 | } |
||
96 | if ($suburbPage) { |
||
97 | return $suburbPage; |
||
98 | } |
||
99 | return $cityPage; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * formulae for working out distance |
||
104 | **/ |
||
105 | protected static function radiusDefinitionOtherTable($lon, $lat, $table, $latitudeField, $longitudeField) |
||
106 | { |
||
107 | $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
||
108 | return "(6378.137 * ACOS( ( SIN( PI( ) * ".$lat." /180 ) * SIN( PI( ) * {$bt}".$table."{$bt}.{$bt}".$latitudeField."{$bt} /180 ) ) + ( COS( PI( ) * ".$lat." /180 ) * cos( PI( ) * {$bt}".$table."{$bt}.{$bt}".$latitudeField."{$bt} /180 ) * COS( (PI( ) * {$bt}".$table."{$bt}.{$bt}".$longitudeField."{$bt} /180 ) - ( PI( ) *".$lon." /180 ) ) ) ) ) "; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * name for page level. |
||
113 | **/ |
||
114 | public function GeoLevelName() |
||
115 | { |
||
116 | return "Cities"; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * number for page level. |
||
121 | **/ |
||
122 | public function GeoLevelNumber() |
||
123 | { |
||
124 | return 3; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * This static method creates a city page and all the required parent pages... |
||
129 | *@param Int - $CityID: the ID for the city to create |
||
130 | **/ |
||
131 | public static function create_city_and_parents($CityID) |
||
132 | { |
||
133 | $cityPage = null; |
||
134 | //check if the city exists at all |
||
135 | $sql = ' |
||
136 | SELECT cities.RegionID, regions.CountryID, countries.ContinentID From cities, regions, countries, continents |
||
137 | WHERE |
||
138 | cities.RegionID = regions.RegionID AND |
||
139 | regions.CountryID = countries.CountryID AND |
||
140 | countries.ContinentID = continents.ContinentID AND |
||
141 | cities.CityID = '.$CityID.' |
||
142 | LIMIT 1;'; |
||
143 | $result = DB::query($sql); |
||
144 | |||
145 | foreach ($result as $row) { |
||
146 | break; |
||
147 | } |
||
148 | $abstractHelpPage = new BrowseAbstractPage(); |
||
149 | if ($row) { |
||
0 ignored issues
–
show
The expression
$row of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
150 | //1 check if world exists |
||
151 | if ($worldPage = DataObject::get_one("BrowseWorldPage")) { |
||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
152 | //do nothing |
||
153 | } else { |
||
154 | $worldPage = new BrowseWorldPage(); |
||
155 | $name = "Find"; |
||
156 | $worldPage->Title = $name; |
||
157 | $worldPage->MetaTitle = $name; |
||
158 | $worldPage->MenuTitle = $name; |
||
159 | $worldPage->writeToStage('Stage'); |
||
160 | $worldPage->publish('Stage', 'Live'); |
||
161 | $worldPage->flushCache(); |
||
162 | } |
||
163 | |||
164 | //2 check if continent exists |
||
165 | $ContinentID = $row["ContinentID"]; |
||
166 | View Code Duplication | if ($continentPage = DataObject::get_one("BrowseContinentsPage", 'HiddenDataID = '.$ContinentID)) { |
|
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
167 | //debug::show("continent exists"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
168 | } else { |
||
169 | //create continent |
||
170 | $continents = $abstractHelpPage->getDataFromTable("continents", "ContinentID = ".$ContinentID, null); |
||
171 | foreach ($continents as $continentData) { |
||
172 | $continentPage = new BrowseContinentsPage(); |
||
173 | $continentPage->CreateContinent($continentData, $worldPage); |
||
174 | } |
||
175 | } |
||
176 | |||
177 | //3 check if country exists |
||
178 | $CountryID = $row["CountryID"]; |
||
179 | View Code Duplication | if ($countryPage = DataObject::get_one("BrowseCountriesPage", 'HiddenDataID = '.$CountryID)) { |
|
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
180 | //debug::show("country exists"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
181 | } else { |
||
182 | //create Country |
||
183 | $countries = $abstractHelpPage->getDataFromTable("countries", "CountryID = ".$CountryID, null); |
||
184 | foreach ($countries as $countryData) { |
||
185 | $countryPage = new BrowseCountriesPage(); |
||
186 | $countryPage->CreateCountry($countryData, $continentPage); |
||
187 | } |
||
188 | } |
||
189 | |||
190 | //4 check if region exists |
||
191 | $RegionID = $row["RegionID"]; |
||
192 | View Code Duplication | if ($regionPage = DataObject::get_one("BrowseRegionsPage", 'HiddenDataID = '.$RegionID)) { |
|
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
193 | //debug::show("region exists"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
194 | } else { |
||
195 | //create region |
||
196 | $regions = $abstractHelpPage->getDataFromTable("regions", "RegionID = ".$RegionID, null); |
||
197 | foreach ($regions as $regionData) { |
||
198 | $regionPage = new BrowseRegionsPage(); |
||
199 | $regionPage->CreateRegion($regionData, $countryPage); |
||
200 | } |
||
201 | } |
||
202 | View Code Duplication | if ($cityPage = DataObject::get_one("BrowseCitiesPage", 'HiddenDataID = '.$CityID)) { |
|
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
203 | //debug::show("city exists"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
204 | } else { |
||
205 | //create region |
||
206 | $cities = $abstractHelpPage->getDataFromTable("cities", "CityID = ".$CityID, null); |
||
207 | foreach ($cities as $city) { |
||
208 | $cityPage = new BrowseCitiesPage(); |
||
209 | $cityPage->CreateCity($city, $regionPage); |
||
210 | } |
||
211 | } |
||
212 | } |
||
213 | return $cityPage; |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * fix URLS |
||
218 | * NOTE: you must set get variables: urls, from and to.... |
||
219 | **/ |
||
220 | public function requireDefaultRecords() |
||
0 ignored issues
–
show
requireDefaultRecords uses the super-global variable $_GET which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
221 | { |
||
222 | parent::requireDefaultRecords(); |
||
223 | if (isset($_GET["urls"]) && isset($_GET["from"]) && isset($_GET["to"])) { |
||
224 | $dos = DataObject::get("SiteTree", null, null, null, $_GET["from"].','.$_GET["to"]); |
||
225 | foreach ($dos as $page) { |
||
226 | if (isset($page)) { |
||
227 | echo "<li>fixing ".$page->Title."</li>"; |
||
228 | $page->URLSegment = $this->generateURLSegment($page->Title); |
||
229 | $page->writeToStage('Stage'); |
||
230 | $page->publish('Stage', 'Live'); |
||
231 | $page->flushCache(); |
||
232 | $page->detroy(); |
||
233 | } |
||
234 | } |
||
235 | } |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Create a page |
||
240 | * @param Array - $city: the data for the city |
||
241 | * @param Object $parent: BrowseRegionsPage |
||
0 ignored issues
–
show
There is no parameter named
$parent: . Did you maybe mean $parent ?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit. Consider the following example. The parameter /**
* @param array $germany
* @param array $ireland
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was changed, but the annotation was not. ![]() |
|||
242 | **/ |
||
243 | public function CreateCity(array $city, BrowseRegionsPage $parent) |
||
0 ignored issues
–
show
CreateCity uses the super-global variable $_GET which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
244 | { |
||
245 | if ($parent && isset($city["City"])) { |
||
246 | $name = htmlentities($city["City"]); |
||
247 | if (isset($name)) { |
||
248 | if (isset($_GET["geobuild"])) { |
||
249 | echo "<li>creating ".$name."</li>"; |
||
250 | } |
||
251 | $this->ParentID = $parent->ID; |
||
252 | $this->Title = $name; |
||
253 | $this->MetaTitle = $name; |
||
254 | $this->MenuTitle = $name; |
||
255 | $this->HiddenDataID = $city["CityID"]; |
||
256 | |||
257 | $this->Code = $city["Code"]; |
||
258 | $this->Latitude = $city["Latitude"]; |
||
259 | $this->Longitude = $city["Longitude"]; |
||
260 | $this->TimeZone = $city["TimeZone"]; |
||
261 | $this->County = htmlentities($city["County"]); |
||
262 | $this->Code = $city["Code"]; |
||
263 | |||
264 | $this->CreateChildren = $parent->CreateAllChildren; |
||
265 | $this->CreateAllChildren = $parent->CreateAllChildren; |
||
266 | |||
267 | $this->URLSegment = $this->generateURLSegment($this->Title); |
||
268 | |||
269 | $this->writeToStage('Stage'); |
||
270 | $this->publish('Stage', 'Live'); |
||
271 | $this->flushCache(); |
||
272 | } else { |
||
273 | if (isset($_GET["geobuild"])) { |
||
274 | debug::show("No name can be found"); |
||
275 | } |
||
276 | } |
||
277 | } else { |
||
278 | if (isset($_GET["geobuild"])) { |
||
279 | debug::show("Parent does not exist"); |
||
280 | } |
||
281 | } |
||
282 | } |
||
283 | } |
||
284 | |||
285 | class BrowseCitiesPage_Controller extends BrowseAbstractPage_Controller |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
286 | { |
||
287 | } |
||
288 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.