-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e57dbc6
commit fc7a20e
Showing
5 changed files
with
155 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,68 @@ | ||
<?php if ($_SERVER['REQUEST_METHOD'] === 'POST') { | ||
// get the comment from the POST | ||
$description = $_POST["description"]; | ||
$links = $_POST["links"]; | ||
// Create theme object | ||
if (!empty($_POST["theme"])) { | ||
$theme = json_decode($_POST["theme"], true); | ||
} else { | ||
$theme = array(); | ||
} | ||
} else { | ||
<?php | ||
|
||
// If the request method is not POST, return a 405 Method Not Allowed response | ||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { | ||
http_response_code(405); | ||
header('allow: POST'); | ||
print "You can only access this page by submission of a form."; | ||
exit(); | ||
die(); | ||
} | ||
|
||
if (is_uploaded_file($_FILES["photo"]["tmp_name"])) { | ||
// process image | ||
$imagesize = getimagesize($_FILES["photo"]["tmp_name"]); | ||
if ($imagesize !== false) { | ||
// client uploaded a bona fide image! | ||
$photo_data = base64_encode(file_get_contents($_FILES["photo"]["tmp_name"])); | ||
$user_photo = "data:" . $imagesize["mime"] . ";base64," . $photo_data; | ||
if (!isset($_POST["getzip"])) { | ||
// If the "getzip" box is not checked, set the template to be downloaded as "index.html" | ||
|
||
// If the "ispreview" box is not checked, set the template to be downloaded as "index.html" | ||
if (!isset($_POST["ispreview"])) { | ||
header('Content-Disposition: attachment; filename="index.html"'); | ||
} | ||
} | ||
|
||
if (!isset($_POST["ispreview"])) { | ||
header('Content-Disposition: attachment; filename="index.html"'); | ||
// Include the template.php file | ||
include "template.php"; | ||
|
||
// Exit the script | ||
die(); | ||
} else { | ||
// If the "getzip" box is checked, capture the output of template.php and create a zip file | ||
|
||
// Start output buffering | ||
ob_start(); | ||
|
||
// Include the template.php file | ||
include "template.php"; | ||
|
||
// Get the contents of the output buffer | ||
$buffer = ob_get_clean(); | ||
|
||
try { | ||
// Create a temporary zip file | ||
$tmpfile = tempnam(sys_get_temp_dir(), "linkfree"); | ||
|
||
// Register a shutdown function to delete the temporary file | ||
register_shutdown_function('unlink', $tmpfile); | ||
|
||
// Create a new ZipArchive object | ||
$zip = new ZipArchive(); | ||
$zip->open($tmpfile, ZipArchive::CREATE | ZipArchive::OVERWRITE); | ||
|
||
// Add the index.html file to the zip | ||
$zip->addFromString("index.html", $buffer); | ||
|
||
$zip->close(); | ||
} catch (Exception $e) { | ||
// If an exception is thrown, return a 500 Server Error response | ||
http_response_code(500); | ||
print "An error occurred while creating the zip file."; | ||
die(); | ||
} | ||
|
||
// Set the headers to download the zip file | ||
header('Content-Type: application/zip'); | ||
header('Content-Length: ' . filesize($tmpfile)); | ||
header('Content-Disposition: attachment; filename="linkfree.zip"'); | ||
|
||
// Output the contents of the zip file | ||
readfile($tmpfile); | ||
|
||
// Exit the script | ||
die(); | ||
} | ||
?> | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta charset="UTF-8"> | ||
<title><?= $_POST["name"] ?></title> | ||
<?php if (!empty($theme["css"])) { ?> | ||
<link rel="stylesheet" href="<?= "{$_POST["themes-source"]}/{$theme["css"]}" ?>"> | ||
<?php } else { ?> | ||
<style> | ||
<?php include "default.css"; ?> | ||
</style> | ||
<?php } ?> | ||
</head> | ||
|
||
<body> | ||
<?php if (!empty($user_photo)) { ?> | ||
<img id="userPhoto" src="<?= $user_photo ?>" alt="User Photo"> | ||
<?php } ?> | ||
|
||
<a href="<?= (!empty($_POST["url"]) ? $_POST["url"] : ".") ?>"> | ||
<h1 id="userName"><?= $_POST["name"] ?></h1> | ||
</a> | ||
|
||
<?php if (!empty($_POST["description"])) { ?> | ||
<p id="description"><?= $_POST["description"] ?></p> | ||
<?php } ?> | ||
|
||
<div id="links"> | ||
<?php foreach ($links as $link) { | ||
if (!empty($link["url"])) { ?> | ||
<a class="link" href="<?= $link["url"] ?>" target="_blank"> | ||
<?php if (!empty($link["icon"])) { ?> | ||
<ion-icon name="<?= $link["icon"] ?>"></ion-icon> | ||
<?php } ?> | ||
<?= $link["name"] ?> | ||
</a> | ||
<?php } | ||
} ?> | ||
<?php if (!empty($_POST["email"])) { ?> | ||
<!--email_off--> | ||
<a class="link" href="mailto:<?= $_POST["email"] ?>" target="_blank"><ion-icon name="mail"></ion-icon> Email</a> | ||
<!--/email_off--> | ||
<?php } ?> | ||
</div> | ||
<?php if (!empty($theme["js"])) { ?> | ||
<script src="<?= "{$_POST["themes-source"]}/{$theme["js"]}" ?>"></script> | ||
<?php } ?> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ionicons/ionicons.esm.js"></script> | ||
<script nomodule src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ionicons/ionicons.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
// get the comment from the POST | ||
$description = $_POST["description"]; | ||
$links = $_POST["links"]; | ||
|
||
// Create theme object | ||
if (!empty($_POST["theme"])) { | ||
$theme = json_decode($_POST["theme"], true); | ||
} else { | ||
$theme = array(); | ||
} | ||
|
||
// Convert uploaded photo to data URI | ||
if (is_uploaded_file($_FILES["photo"]["tmp_name"])) { | ||
// process image | ||
$imagesize = getimagesize($_FILES["photo"]["tmp_name"]); | ||
if ($imagesize !== false) { | ||
// client uploaded a bona fide image! | ||
$photo_data = base64_encode(file_get_contents($_FILES["photo"]["tmp_name"])); | ||
$user_photo = "data:" . $imagesize["mime"] . ";base64," . $photo_data; | ||
} | ||
} | ||
?> | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta charset="UTF-8"> | ||
<title><?= $_POST["name"] ?></title> | ||
<?php if (!empty($theme["css"])) { ?> | ||
<link rel="stylesheet" href="<?= "{$_POST["themes-source"]}/{$theme["css"]}" ?>"> | ||
<?php } else { ?> | ||
<style> | ||
<?php include "default.css"; ?> | ||
</style> | ||
<?php } ?> | ||
</head> | ||
|
||
<body> | ||
<?php if (!empty($user_photo)) { ?> | ||
<img id="userPhoto" src="<?= $user_photo ?>" alt="User Photo"> | ||
<?php } ?> | ||
|
||
<a href="<?= (!empty($_POST["url"]) ? $_POST["url"] : ".") ?>"> | ||
<h1 id="userName"><?= $_POST["name"] ?></h1> | ||
</a> | ||
|
||
<?php if (!empty($_POST["description"])) { ?> | ||
<p id="description"><?= $_POST["description"] ?></p> | ||
<?php } ?> | ||
|
||
<div id="links"> | ||
<?php foreach ($links as $link) { | ||
if (!empty($link["url"])) { ?> | ||
<a class="link" href="<?= $link["url"] ?>" target="_blank"> | ||
<?php if (!empty($link["icon"])) { ?> | ||
<ion-icon name="<?= $link["icon"] ?>"></ion-icon> | ||
<?php } ?> | ||
<?= $link["name"] ?> | ||
</a> | ||
<?php } | ||
} ?> | ||
<?php if (!empty($_POST["email"])) { ?> | ||
<!--email_off--> | ||
<a class="link" href="mailto:<?= $_POST["email"] ?>" target="_blank"><ion-icon name="mail"></ion-icon> Email</a> | ||
<!--/email_off--> | ||
<?php } ?> | ||
</div> | ||
<?php if (!empty($theme["js"])) { ?> | ||
<script src="<?= "{$_POST["themes-source"]}/{$theme["js"]}" ?>"></script> | ||
<?php } ?> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ionicons/ionicons.esm.js"></script> | ||
<script nomodule src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ionicons/ionicons.js"></script> | ||
</body> | ||
|
||
</html> |