Ejemplo n.º 1
0
function wolk_api_read($user_id, $origin_id, array $namespaces = null, $since = null)
{
    $pairs = wolk_list_pairs($user_id, $origin_id, $namespaces, json_parse_date($since));
    $response = array();
    foreach ($pairs as $pair) {
        $response[] = array('k' => $pair->key, 'v' => $pair->value, 'm' => json_stringify_date($pair->last_modified_on));
    }
    return $response;
}
Ejemplo n.º 2
0
function index_data()
{
    global $self;
    $selected_origin = isset($_GET['origin']) ? (int) $_GET['origin'] : null;
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        switch ($_POST['action']) {
            case 'delete':
                wolk_delete_pairs($_SESSION['user_id'], $_POST['keys'], $selected_origin);
                break;
        }
    }
    echo '
	<ol>
	';
    foreach (wolk_list_origins($_SESSION['user_id']) as $origin) {
        echo '
		<li class="' . ($origin->id == $selected_origin ? 'selected' : '') . '">
			<a href="' . $self . '?page=data&origin=' . urlencode($origin->id) . '">' . htmlspecialchars($origin->origin, ENT_COMPAT, 'utf-8') . '</a>
			<span class="last_updated timestamp">Last updated on <time datetime="' . json_stringify_date($origin->last_updated_on) . '">' . $origin->last_updated_on->format('d-m-Y H:i:s') . '</time></span>
		</li>
		';
    }
    echo '
	</ol>
	';
    if ($selected_origin) {
        echo '
		<form method="post">
			<table>
				<thead>
					<tr>
						<th><input type="checkbox"></th>
						<th>Key</th>
						<th>Value</th>
						<th>Last Updated</th>
					</tr>
				</thead>
				<tbody>
			';
        foreach (wolk_list_pairs($_SESSION['user_id'], $selected_origin) as $pair) {
            echo '
					<tr>
						<td><input type="checkbox" name="keys[]" value="' . htmlspecialchars($pair->key, ENT_QUOTES, 'utf-8') . '"></td>
						<td>' . htmlspecialchars($pair->key, ENT_COMPAT, 'utf-8') . '</td>
						<td>' . (is_null($pair->value) ? '<span class="deleted">deleted</span>' : htmlspecialchars($pair->value, ENT_COMPAT, 'utf-8')) . '</td>
						<td><time timestamp="' . json_stringify_date($pair->last_modified_on) . '">' . $pair->last_modified_on->format('d-m-Y H:i:s') . '</time></td>
					</tr>
			';
        }
        echo '
				</tbody>
			</table>
			<button type="submit" name="action" value="delete">Delete</button>
		</form>
		';
    }
}