// set headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=\"tokens.csv\""); header("Content-Transfer-Encoding: binary"); print get_tokens_as_csv($_SESSION['tokens']); exit; break; case 'tokenlist': $file = $_GET['file']; if (isset($_POST['submit'])) { if (is_numeric($_POST['howmany'])) { $_SESSION['tokens'] = create_tokens($file, $_POST['howmany'], $_POST['uses'], $_POST['expires']); $_SESSION['message'] = "Created " . count($_SESSION['tokens']) . " tokens. <a href=\"admin.php?p=csv\">Download as CSV</a>?"; } else { $_SESSION['message'] = "'How many?' should be a number"; } header("Location: admin.php?p=tokenlist&file=" . $file); exit; } $tokens = query("SELECT * FROM tokens WHERE file = %d ORDER BY created", $file); ?> <h2>Generate new tokens</h2> <form method="POST"> <label for="howmany">How many?</label><input id="howmany" name="howmany"><br> <label for="uses">Uses</label><input id="uses" name="uses" value="1"><br> <label for="expires">Expires</label><input id="expires" name="expires" value="2029-12-31 00:00:00"><br> <input name="submit" id="submit" type="submit" value="Generate!">
$data = simplexml_load_file($file_to_prepare); foreach ($data->object as $obj) { echo $singularized_name = Inflect::singularize((string) $obj->attributes()->name); $tokens = create_tokens($singularized_name); // notseparated lowercase $obj->addAttribute('name_ns_lc', build_name($tokens, 'ns_lc')); // underline_separated lowercase $obj->addAttribute('name_us_lc', build_name($tokens, 'us_lc')); // UNDERLINE_SEPARATED uppercase $obj->addAttribute('name_us_uc', build_name($tokens, 'us_uc')); // camelCase lower-first $obj->addAttribute('name_cc_lf', build_name($tokens, 'cc_lf')); // CamelCase upper-first $obj->addAttribute('name_cc_uf', build_name($tokens, 'cc_uf')); foreach ($obj as $field) { $tokens = create_tokens((string) $field->attributes()->name); $field->addAttribute('name_us_lc', build_name($tokens, 'us_lc')); $field->addAttribute('name_cc_lf', build_name($tokens, 'cc_lf')); } } file_put_contents($file_to_prepare, $data->asXML()); function create_tokens($str) { $tokens = array(); $token = ""; for ($i = strlen($str) - 1; $i >= 0; $i--) { $char = $str[$i]; $token = $char . $token; if (preg_match('/^[A-Z|_]/', $token) || $i == 0) { array_push($tokens, strtolower(trim($token, '_'))); $token = "";