forked from shaarli/Shaarli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relates to shaarli#250 Modifications - add PHP 5.3 to Travis environments - rewrite array declarations: explicitely use array() instead of [] - move checkPHPVersion to application/Utils.php - move timezone functions to application/TimeZone.php - improve test coverage - bump required version from 5.1.0 to 5.3.x Signed-off-by: VirtualTam <virtualtam@flibidi.net>
- Loading branch information
1 parent
1b73f35
commit e3b48b3
Showing
9 changed files
with
230 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ php: | |
- 5.6 | ||
- 5.5 | ||
- 5.4 | ||
- 5.3 | ||
install: | ||
- composer self-update | ||
- composer install | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/** | ||
* Generates the timezone selection form and JavaScript. | ||
* | ||
* Note: 'UTC/UTC' is mapped to 'UTC' | ||
* | ||
* Example: preselect Europe/Paris | ||
* list($htmlform, $js) = templateTZform('Europe/Paris'); | ||
* | ||
* @param $preselected_timezone preselected timezone (can be 'UTC/UTC') (optional) | ||
* @return array(html, js) | ||
**/ | ||
function generateTimeZoneForm($preseleced_timezone=false) | ||
{ | ||
// Try to split the provided timezone. | ||
if ($preseleced_timezone == false) { | ||
$l = timezone_identifiers_list(); | ||
$preseleced_timezone = $l[0]; | ||
} | ||
$spos = strpos($preseleced_timezone, '/'); | ||
$pcontinent = substr($preseleced_timezone, 0, $spos); | ||
$pcity = substr($preseleced_timezone, $spos+1); | ||
|
||
// Display config form: | ||
$timezone_form = ''; | ||
$timezone_js = ''; | ||
|
||
// The list is in the form "Europe/Paris", "America/Argentina/Buenos_Aires"... | ||
// We split the list in continents/cities. | ||
$continents = array(); | ||
$cities = array(); | ||
|
||
foreach (timezone_identifiers_list() as $tz) { | ||
if ($tz == 'UTC') { | ||
$tz = 'UTC/UTC'; | ||
} | ||
$spos = strpos($tz, '/'); | ||
if ($spos !== false) { | ||
$continent = substr($tz, 0, $spos); | ||
$city = substr($tz, $spos+1); | ||
$continents[$continent] = 1; | ||
|
||
if (!isset($cities[$continent])) { | ||
$cities[$continent] = ''; | ||
} | ||
$cities[$continent].='<option value="'.$city.'"'.($pcity==$city?' selected':'').'>'.$city.'</option>'; | ||
} | ||
} | ||
|
||
$continents_html = ''; | ||
$continents = array_keys($continents); | ||
|
||
// TODO: use a template to generate the HTML/Javascript form | ||
|
||
foreach ($continents as $continent) { | ||
$continents_html.='<option value="'.$continent.'"'.($pcontinent==$continent?' selected':'').'>'.$continent.'</option>'; | ||
} | ||
|
||
$cities_html = $cities[$pcontinent]; | ||
|
||
$timezone_form = "Continent: <select name=\"continent\" id=\"continent\" onChange=\"onChangecontinent();\">${continents_html}</select>"; | ||
$timezone_form .= " City: <select name=\"city\" id=\"city\">${cities[$pcontinent]}</select><br />"; | ||
$timezone_js = "<script>"; | ||
$timezone_js .= "function onChangecontinent(){document.getElementById(\"city\").innerHTML = citiescontinent[document.getElementById(\"continent\").value];}"; | ||
$timezone_js .= "var citiescontinent = ".json_encode($cities).";"; | ||
$timezone_js .= "</script>"; | ||
return array($timezone_form, $timezone_js); | ||
} | ||
|
||
/** | ||
* Tells if a continent/city pair form a valid timezone | ||
* | ||
* Note: 'UTC/UTC' is mapped to 'UTC' | ||
* | ||
* @param $continent the timezone continent | ||
* @param $city the timezone city | ||
* @return whether continent/city is a valid timezone | ||
*/ | ||
function isTimeZoneValid($continent, $city) | ||
{ | ||
if ($continent == 'UTC' && $city == 'UTC') { | ||
return true; | ||
} | ||
|
||
$tz = $continent.'/'.$city; | ||
if (in_array($tz, timezone_identifiers_list())) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.