Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get JSON data containing URL #86

Merged
merged 9 commits into from
Oct 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
require_once("includes/sanitycheck.php"); # check everything before we proceed
require_once("settings.php"); # load settings
require_once("includes/functions.php"); # load functions
require_once('html/header.php'); # display header

# display secret code in json format if requested
if (isset($_POST['json']) && isset($_POST['submit']) && !empty($_POST['secret'])) {
header("Content-Type: application/json");
die(display_secret_code(true));
}

require_once('html/header.php'); # display header

if (!empty($_GET['k'])) {
try {
Expand All @@ -18,7 +24,7 @@

} elseif (isset($_POST['submit']) && !empty($_POST['secret'])) {
try {
display_secret_code(); # secret submitted. display url/code
display_secret_code($json); # secret submitted. display url/code
} catch (Exception $e) { display_error($e); }

} else {
Expand Down Expand Up @@ -63,7 +69,7 @@ function display_secret() {
require_once('html/view_secret.php');
}

function display_secret_code() {
function display_secret_code($return_only_json = false) {
global $settings;

# verify secret length isnt too long
Expand All @@ -77,6 +83,11 @@ function display_secret_code() {
if ($settings['return_full_url'] == true) {
$message = build_url($message);
}

if ($return_only_json) {
return json_encode(array("url" => $message), JSON_UNESCAPED_SLASHES);
}

require_once('html/view_code.php');
}

Expand Down