Active
Project:
Calendar Block
Version:
5.x-2.1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
28 Jan 2009 at 15:31 UTC
Updated:
28 Jan 2009 at 15:31 UTC
Hi, just got the block up and running -- thanks for your help earlier!
Though once the block was working, I discovered that the first day of the month was always getting set to the first day of the week, and realized that it was because the json_decode function was leaving the quotes on the keys in the $calendar->weekdays array.
I tweaked it as follows, and it looks like it's working now (though there may be a more elegant way to do it):
/**
* json_decode for < PHP 5
*/
if (!function_exists('json_decode')) {
function json_decode($v) {
if ($v{0} == '"') {
$v = drupal_substr($v, 1, -1);
}
elseif ($v{0} == '{') {
$var = explode(",", drupal_substr($v, 1, -1)); # changed from drupal_substr($v, 1, -2), since it was chopping off the final quote
$v = array();
foreach ($var as $value) {
$va = explode(":", $value);
# added the following condition to remove quotes from the key
if($va[0]{0} == '"') {
$va[0] = drupal_substr($va[0], 1, -1);
}
$v[$va[0]] = json_decode($va[1]);
}
}
elseif ($v{0} == '[') {
$var = explode(",", drupal_substr($v, 1, -2));
$v = array();
foreach ($var as $value) {
$v[] = json_decode($va[0]);
}
}
return $v;
}
}