/** * This function checks and prepares the text to be logged * * @access private */ function _toLog($func, $text, $requestedLogLevel = LOG_NOTICE) { pwurple_log($func, $text, $requestedLogLevel); }
function pwurple_start_element($parser, $name, $attr) { global $wurfl, $curr_event, $curr_device, $curr_group, $fp_cache, $check_patch_params, $checkpatch_result; if ($check_patch_params) { // if the patch file checks fail I don't merge info retrived if (!checkpatch($name, $attr)) { pwurple_log('pwurple_start_element', "error on {$name}, " . $attr['id']); $curr_device = 'dump_anything'; return; } else { if ($curr_device == 'dump_anything' && $name != 'device') { // this capability is referred to a device that was erroneously defined for some reason, skip it pwurple_log('pwurple_start_element', $name . " cannot be merged, the device was skipped because of an error"); return; } } } switch ($name) { case "ver": case "last_updated": case "official_url": case "statement": //cdata will take care of these, I'm just defining the array $wurfl[$name] = ""; //$curr_event=$wurfl[$name]; break; case "maintainers": case "maintainer": case "authors": case "author": case "contributors": case "contributor": if (sizeof($attr) > 0) { // dirty trick: author is child of authors, contributor is child of contributors while ($t = each($attr)) { // example: $wurfl["authors"]["author"]["name"]="Andrea Trasatti"; $wurfl[$name . "s"][$name][$attr["name"]][$t[0]] = $t[1]; } } break; case "device": if (($attr["user_agent"] == "" || !$attr["user_agent"]) && $attr["id"] != "generic") { die("No user agent and I am not generic!! id=" . $attr["id"] . " HELP"); } if (sizeof($attr) > 0) { $patch_values = ''; if (!isset($wurfl["devices"][$attr["id"]])) { $new_device = true; } while ($t = each($attr)) { if ($check_patch_params && defined('WURFL_PATCH_DEBUG') && WURFL_PATCH_DEBUG === true) { if (!isset($wurfl["devices"][$attr["id"]][$t[0]])) { if ($new_device !== true) { $patch_values .= 'adding '; } $patch_values .= $t[0] . '=' . $t[1] . ', '; } else { if ($wurfl["devices"][$attr["id"]][$t[0]] != $t[1]) { $patch_values .= $t[0] . ', ' . $wurfl["devices"][$attr["id"]][$t[0]] . '=>' . $t[1] . ', '; } } } // example: $wurfl["devices"]["ericsson_generic"]["fall_back"]="generic"; $wurfl["devices"][$attr["id"]][$t[0]] = $t[1]; } } if ($check_patch_params && defined('WURFL_PATCH_DEBUG') && WURFL_PATCH_DEBUG === true) { if ($new_device === true) { $log_string = 'Adding device ' . $attr["id"] . ' '; $new_device = false; } else { $log_string = 'Updating device ' . $attr["id"] . ' '; } if (strlen($patch_values) > 0) { $log_string .= ': ' . $patch_values; } pwurple_log('parse', $log_string); } $curr_device = $attr["id"]; break; case "group": // this HAS NOT to be executed or we will define the id as string and then reuse it as array: ERROR //$wurfl["devices"][$curr_device][$attr["id"]]=$attr["id"]; $curr_group = $attr["id"]; break; case "capability": if ($attr["value"] == 'true') { $value = true; } else { if ($attr["value"] == 'false') { $value = false; } else { $value = $attr["value"]; $intval = intval($value); if (strcmp($value, $intval) == 0) { $value = $intval; } } } if ($curr_device != 'generic' && !isset($wurfl["devices"]['generic'][$curr_group][$attr["name"]])) { pwurple_log('parse', 'Capability ' . $attr["name"] . ' in group ' . $curr_group . ' is not defined in the generic device, can\'t set it for ' . $curr_device . '.'); } else { if ($check_patch_params && defined('WURFL_PATCH_DEBUG') && WURFL_PATCH_DEBUG === true) { if (isset($wurfl["devices"][$curr_device][$curr_group][$attr["name"]])) { pwurple_log('parse', $curr_device . ': updating ' . $attr["name"] . ', ' . $wurfl["devices"][$curr_device][$curr_group][$attr["name"]] . '=>' . $value); } else { pwurple_log('parse', $curr_device . ': setting ' . $attr["name"] . '=' . $value); } } $wurfl["devices"][$curr_device][$curr_group][$attr["name"]] = $value; } break; case "devices": // This might look useless but it's good when you want to parse only the devices and skip the rest if (!isset($wurfl["devices"])) { $wurfl["devices"] = array(); } break; case "pwurple_patch": // opening tag of the patch file // opening tag of the patch file case "wurfl": // opening tag of the WURFL, nothing to do break; case "default": // unknown events are not welcome die($name . " is an unknown event<br>"); break; } }