function api_output_xml($v, $k=null) {
	global $api_xml_arr;
	$verbose = get_http_var('verbose') ? "\n" : '';
	if (is_array($v)) {
		if (count($v) && array_keys($v) === range(0, count($v)-1)) {
			$elt = 'match';
			$api_xml_arr++;
			$out = "<$elt>";
			$out .= join("</$elt>$verbose<$elt>", array_map('api_output_xml', $v));
			$out .= "</$elt>$verbose";
			return $out;
		}
		$out = '';
		foreach ($v as $k => $vv) {
			$out .= (is_numeric($k) || strpos($k, ' ')) ? '<match><id>' . htmlspecialchars($k) . '</id>' : "<$k>";
			$out .= api_output_xml($vv, $k);
			$out .= (is_numeric($k) || strpos($k, ' ')) ? '</match>' : "</$k>";
			$out .= $verbose;
		}
		return $out;
	} else {
		return htmlspecialchars($v);
	}
}
Esempio n. 2
0
function api_output_xml($v, $k = null)
{
    global $api_xml_arr;
    $verbose = get_http_var('verbose') ? "\n" : '';
    if (is_array($v)) {
        if (count($v) && array_keys($v) === range(0, count($v) - 1)) {
            $elt = 'match';
            $api_xml_arr++;
            $out = "<{$elt}>";
            $out .= join("</{$elt}>{$verbose}<{$elt}>", array_map('api_output_xml', $v));
            $out .= "</{$elt}>{$verbose}";
            return $out;
        }
        $out = '';
        foreach ($v as $k => $vv) {
            $out .= "<{$k}>";
            $out .= api_output_xml($vv, $k);
            $out .= "</{$k}>{$verbose}";
        }
        return $out;
    } else {
        return htmlspecialchars($v);
    }
}
Esempio n. 3
0
File: dat.php Progetto: palfrey/twfy
}
$pw = '<ul>';
$pw .= display_dream_comparison(996, "a <strong>transparent Parliament</strong>");
$pw .= display_dream_comparison(811, "introducing a <strong>smoking ban</strong>");
$pw .= display_dream_comparison(230, "introducing <strong>ID cards</strong>", true);
$pw .= display_dream_comparison(363, "introducing <strong>foundation hospitals</strong>");
$pw .= display_dream_comparison(367, "introducing <strong>student top-up fees</strong>", true);
$pw .= display_dream_comparison(258, "Labour's <strong>anti-terrorism laws</strong>", true);
$pw .= display_dream_comparison(219, "the <strong>Iraq war</strong>", true);
$pw .= display_dream_comparison(975, "investigating the <strong>Iraq war</strong>");
$pw .= display_dream_comparison(984, "replacing <strong>Trident</strong>");
$pw .= display_dream_comparison(358, "the <strong>hunting ban</strong>", true);
$pw .= display_dream_comparison(826, "equal <strong>gay rights</strong>");
$pw .= '</ul>';
$row['pw_data'] = $pw;
print '<twfy>' . api_output_xml($row) . '</twfy>';
# ---
function display_dream_comparison($id, $text, $inverse = false)
{
    global $output;
    if (!array_key_exists($id, $output)) {
        return;
    }
    $pw = '';
    $score = $output[$id];
    if ($score == -1) {
        $pw .= '<li>Has never voted on';
    } else {
        if ($inverse) {
            $score = 1 - $score;
        }
Esempio n. 4
0
File: dat.php Progetto: leowmjw/twfy
        if ($inverse) {
            $score = 1 - $score;
        }
        $pw .= '<li>Voted <strong>' . score_to_strongly($score) . '</strong>';
    }
    $pw .= ' ' . $text . '</li>';
}
$pw .= '</ul>';
$output = $row;
$output['pw_data'] = $pw;
$q = $db->query("select * from memberinfo where member_id = " . $row['member_id'] . " and data_key in ('swing_to_lose_seat_today', 'majority_in_seat')");
for ($i = 0; $i < $q->rows(); $i++) {
    $key = $q->field($i, 'data_key');
    $output[$key] = number_format($q->field($i, 'data_value'));
}
print '<twfy>' . api_output_xml($output) . '</twfy>';
function score_to_strongly($dmpscore)
{
    $dmpdesc = "unknown about";
    if ($dmpscore > 0.95 && $dmpscore <= 1.0) {
        $dmpdesc = "very strongly against";
    } elseif ($dmpscore > 0.85) {
        $dmpdesc = "strongly against";
    } elseif ($dmpscore > 0.6) {
        $dmpdesc = "moderately against";
    } elseif ($dmpscore > 0.4) {
        $dmpdesc = "a mixture of for and against";
    } elseif ($dmpscore > 0.15) {
        $dmpdesc = "moderately for";
    } elseif ($dmpscore > 0.05) {
        $dmpdesc = "strongly for";
Esempio n. 5
0
function api_output_xml($v, $k = null)
{
    global $api_xml_arr;
    $verbose = get_http_var('verbose') ? "\n" : '';
    if (is_array($v)) {
        if (count($v) && array_keys($v) === range(0, count($v) - 1)) {
            $elt = 'item';
            /* generic name for anonymous elements */
            /* TODO: could derive $elt by depluralising $k, eg "image" from "images" */
            $api_xml_arr++;
            $out = "<{$elt}>";
            $out .= join("</{$elt}>{$verbose}<{$elt}>", array_map('api_output_xml', $v));
            $out .= "</{$elt}>{$verbose}";
            return $out;
        }
        $out = '';
        foreach ($v as $k => $vv) {
            $out .= "<{$k}>";
            $out .= api_output_xml($vv, $k);
            $out .= "</{$k}>{$verbose}";
        }
        return $out;
    } else {
        return htmlspecialchars($v);
    }
}