/** * git_dump() - save all data to the git repository * parameter: $changeset - see class Changeset */ function git_dump($changeset) { global $git; global $system; $message = $changeset->message; if (!isset($git)) { return; } $cwd = getcwd(); $git_path = $git['path']; if (!file_exists($git['path'])) { mkdir($git['path']); } if (chdir($git['path']) === false) { messages_add("Git: cannot chdir to git directory", MSG_ERROR); return; } if (!is_dir(".git")) { adv_exec("git init"); } foreach ($changeset->objects as $ob) { $ob_path = get_class($ob) . "/" . $ob->id() . '.json'; @mkdir("{$git_path}/" . get_class($ob)); if ($ob->orig_id !== null) { $orig_ob_path = get_class($ob) . "/" . $ob->orig_id . '.json'; if ($orig_ob_path != $ob_path) { adv_exec("git mv " . shell_escape("{$git_path}/{$orig_ob_path}") . " " . shell_escape("{$git_path}/{$ob_path}")); } } file_put_contents($ob_path, json_readable_encode($ob->view()) . "\n"); adv_exec("git add " . shell_escape("{$git_path}/{$ob_path}")); } foreach ($changeset->removed_objects as $ob) { $ob_path = get_class($ob) . "/" . $ob->id() . '.json'; adv_exec("git rm " . shell_escape("{$git_path}/{$ob_path}")); } global $auth; if ($auth && $auth->current_user()) { $user = $auth->current_user()->name(); $email = $auth->current_user()->email(); } else { $user = "******"; $email = "unknown@unknown"; } if (!$email) { $email = "unknown@unknown"; } $result = adv_exec("git " . "-c user.name=" . shell_escape($user) . " " . "-c user.email=" . shell_escape($email) . " " . "commit " . "-a -m " . shell_escape($message) . " " . "--allow-empty-message " . "--author=" . shell_escape("{$user} <{$email}>")); if (!in_array($result[0], array(0, 1))) { messages_add("<pre>Git commit failed:\n" . htmlspecialchars($result[1]) . "</pre>\n", MSG_ERROR); } chdir($cwd); }
function right_content() { global $riak, $bucket, $key, $_GET, $_POST; $ret = ''; // if i have a bucket selected, but no KEY, I'll display all keys from it if (isset($bucket) && !isset($_GET['key'])) { // $keys = $bucket->getKeys(); $stream = $bucket->getContentStream(); if ($stream) { require_once dirname(__FILE__) . '/lib/ArrayMaker.php'; require_once dirname(__FILE__) . '/lib/jsonstreamingparser/RiakParser.php'; $listener = new ArrayMaker(); $listener->setLimit(DISPLAY_KEYS); try { $parser = new RiakParser($stream, $listener); $parser->parse(); } catch (Exception $e) { fclose($stream); throw $e; } fclose($stream); } else { echo "No stream"; exit; } // exit; $arr_keys = $listener->get_result(); // print_R($arr_keys); $keys = array_map("urldecode", $arr_keys); // pagination ??? $ret .= ' <div class="content"> <h3>Selected BUCKET: "' . $_GET['bucketName'] . '"</h3>'; // add a new key in this bucket if ($_GET['cmd'] == 'addKey') { $ret .= ' <form method="GET" name="addKey" action="?"> <input type="hidden" name="cmd" value="saveKey"> <input type="hidden" name="bucketName" value="' . $_GET['bucketName'] . '"> <div class=content> <div class="td_left">Key name:<div class="msgSmall">Leave empty for random value.</div></div> <div class="td_right"><textarea name="key_name" rows=3 cols="30"></textarea></div> </div> <div id="fieldList"> <div class="content"> <div class=td_left><input type=text name=key[]></div> <div class=td_right><textarea name=value[] rows=3 cols=30></textarea></div> </div> </div> <div style="text-align:center"> <input type="submit" name="ok" value="Save"> <a href="#" onClick="document.getElementById(\'fieldList\').innerHTML=document.getElementById(\'fieldList\').innerHTML + \'<div class=content><div class=td_left><input type=text name=key[]></div><div class=td_right><textarea name=value[] rows=3 cols=30></textarea></div></div>\'">Add another key => value!</a> </div> </form>'; return $ret; } elseif ($_GET['cmd'] == 'findKey') { $ret .= ' <form method="GET" name="searchKey" action="?"> <input type="hidden" name="cmd" value="searchKey"> <input type="hidden" name="bucketName" value="' . $_GET['bucketName'] . '"> <div class="content"> <div class="td_left">Search for:</div> <div class="td_right"><input type="text" name="q" value=""> <input type="submit" name="ok" value="Search"></div> </div> </form>'; return $ret; } elseif ($_GET['cmd'] == 'searchKey') { // display the search results } $ret .= ' <div class="td_left" align="center"><b>KEY NAME</b></div> <div class="td_right" align="center"><b>ACTIONS</b></div> </div>'; $total = 0; $count = count($keys); for ($i = 0; $i < min($count, DISPLAY_KEYS); $i++) { $total++; $ret .= ' <div class="content"> <div class="td_left"><b>' . $keys[$i] . '</b></div> <div class="td_right"> <a href="?cmd=useBucket&bucketName=' . $_GET['bucketName'] . '&key=' . $keys[$i] . '">View/Modify</a> | <a href="?cmd=deleteKey&bucketName=' . $_GET['bucketName'] . '&key=' . $keys[$i] . '">Delete</a> </div> </div>'; } if ($total == 0) { $ret = ' <div class="msg">No keys found in this bucket.</div>'; } $ret .= '</table>'; } elseif (isset($bucket) && isset($_GET['key'])) { $ret .= ' <form name="updateKey" method="POST" action="?cmd=updateKey&bucketName=' . $_GET['bucketName'] . '&key=' . $_GET['key'] . '"> <div class="content"> <h3>Selected KEY: "' . $_GET['key'] . '"</h3> </div>'; $arr_key = $key->reload()->getData(); if (!empty($arr_key)) { $key = json_readable_encode($arr_key); $ret .= '<div class="content">' . '<textarea id="documentdata" name="value[]" style="width:778px; height:375px;">' . $key . "</textarea>" . "<script>document.getElementById('documentdata').value=document.getElementById('documentdata').value.replace(/\\*\\/[^\\/]+\$/, '').replace(/\t/g, ' ');</script>" . "</div>" . '<input type="submit" name="ok" value="Save">'; } else { $ret = '<div class="msg">For some reasons, this key could not be read.</div>'; } $ret .= ' <div id = "fieldList"></div> </form>'; } elseif ($_GET['cmd'] == 'setCookies') { $ret .= '<div="content">' . '<div style="float:left"><img src="' . $_SERVER['SCRIPT_NAME'] . '/../images/iLoading.gif" style="width:90px;"/></div>' . '<div style="float:left; margin-top:30px;">Loading...</div>' . '</div>'; if (isset($_POST)) { $arr = $_POST; $buckets = array(); if (is_array($arr)) { foreach ($arr as $key => $value) { $buckets[] = $key; } } $buckets = json_encode($buckets); setcookie('buckets', $buckets); } $page = $_SERVER['PHP_SELF']; header("Refresh: 0; url={$page}/../"); } elseif ($_GET['cmd'] == 'manageBuckets') { ?> <form name="manageBuckets" action="?cmd=setCookies" method="POST"> <div class="content"> <div id="beforeLoad">Listing all known buckets (ones that have keys stored in them) from Riak...<br/> Please wait while this is fetched from all your nodes... <a href="http://docs.basho.com/riak/1.3.0/references/apis/http/HTTP-List-Buckets/" target="_blank">(i)</a> </div> <div class="clear"></div> <div id="afterLoad" style='display:none'><h3>Manage Favorite Buckets:</h3>(select the buckets you want to be displayed on left, as we cannot read each time from Riak, <a href="http://docs.basho.com/riak/1.3.0/references/apis/http/HTTP-List-Buckets/" target="_blank">find out why</a>.)<br/><br/></div> <?php $buckets = $riak->buckets(); $b = json_decode($_COOKIE['buckets'], true); if (is_array($buckets)) { foreach ($buckets as $bucket) { if (is_array($b) && in_array($bucket->name, $b)) { $checked = true; } else { $checked = false; } $ret .= '<input type="checkbox" id="' . $bucket->name . '"' . ($checked ? 'checked="checked"' : '') . ' name="' . $bucket->name . '"> <label for="' . $bucket->name . '">' . $bucket->name . '</label><br/><br/>'; } } $ret .= '<input type="submit" value="Save favorites"></form><br/><br/>'; $ret .= '* favorites are kept in cookies</div>'; ?> <script> document.getElementById('afterLoad').style.display = document.getElementById('beforeLoad').style.display; document.getElementById('beforeLoad').style.display = 'none'; </script> <?php } else { $ret = ' <div class = "msg">Chose a bucket from the left panel, or create a new one...</div>'; } $ret .= '</div>'; return $ret; }
<?php include "conf.php"; /* load a local configuration */ include "modulekit/loader.php"; /* loads all php-includes */ $content = ajax_load($_REQUEST); if (!$content) { print "An error occured downloading map"; exit(1); } Header("Content-Type: application/json"); Header("Content-Disposition: attachment; filename=" . urlencode($_REQUEST['id']) . ".json"); print json_readable_encode($content);
private function saveConfig() { file_put_contents(RESOURCES_DIR . 'config/config.json', json_readable_encode($this->getAllConfig())); }
function PrintAsciiPacketPayload($encoded_payload, $output_type, $json = false) { $ret_text = Util::htmlentities(wordwrap($encoded_payload, 144)); if ($json) { $decoded_data = @json_decode($encoded_payload, TRUE); if (json_last_error() == JSON_ERROR_NONE) { $ret_text = Util::htmlentities(json_readable_encode($decoded_data)); } else { $ret_text = Util::htmlentities($encoded_payload); } } $ret_text = str_replace("&quot;", "\"", $ret_text); $ret_text = str_replace("&#039;", "'", $ret_text); $ret_text = str_replace("&gt;", ">", $ret_text); $ret_text = str_replace("&lt;", "<", $ret_text); $ret_text = str_replace("'", "'", $ret_text); //$ret_text = str_replace(">", ">", $ret_text); //$ret_text = str_replace("<", "<", $ret_text); $ret_text = preg_replace("/\\&(.)tilde;/", "\\1", $ret_text); return $ret_text; }
function ajax_save_feature($param, $postdata) { global $data_path; if (!check_param($param)) { return array('saved' => false, 'error' => 'Invalid ID'); } git_init(); if (array_key_exists('rev', $param)) { git_checkout($param['rev']); } // create directory for map data $path = "{$data_path}/{$param['id']}"; if (!is_dir($path)) { mkdir($path); } $feature = json_decode($postdata, true); if (!check_param($feature)) { $feature['id'] = md5(uniqid()); } file_put_contents("{$path}/_{$feature['id']}.json", json_readable_encode($feature)); git_exec("add " . shell_escape($param['id'])); git_commit("save feature"); $rev = git_rev(); if (!git_merge()) { return array('saved' => false, 'rev' => $rev, 'feature_id' => $feature['id'], 'error' => "Conflict when merging changes. Please reload and re-do changes."); } return array('saved' => true, 'rev' => $rev, 'feature_id' => $feature['id']); }