This commit is contained in:
2024-09-04 14:05:30 +05:30
parent 55592d3214
commit 8aaea4bd32
5 changed files with 97 additions and 32 deletions

View File

@@ -2,7 +2,7 @@
### Xeorl - The All-In-One, Fully Free to Use Advanced Link Shortener and Management Tool - Powered by [@xodivorce](https://instagram.com/xodivorce) ✨
[![status](https://img.shields.io/badge/status-active-brightgreen.svg?style=flat)](https://github.com/xeorl/xeorl-portfolio/)
[![version](https://img.shields.io/badge/version-v3.1.4-yellow.svg?style=flat)](https://github.com/xeorl/xeorl-portfolio/)
[![version](https://img.shields.io/badge/version-v3.2.0-yellow.svg?style=flat)](https://github.com/xeorl/xeorl-portfolio/)
[![PRs](https://img.shields.io/badge/PRs-welcome-blue.svg?style=flat)](https://github.com/xeorl/xeorl-portfolio/)
<br></br>

View File

@@ -4,7 +4,7 @@
<div class="logo">
<img src="assets/images/url.png" alt="Xeorl Logo" class="logo-img">
<span>Xeorl</span>
<span class="version-number">3.1.4</span>
<span class="version-number">3.2.0</span>
</div>
<label class="burger" for="burger">
<input type="checkbox" id="burger">

View File

@@ -3,6 +3,31 @@ const form = document.querySelector(".shorten-form"),
shortenBtn = document.querySelector("#shorten-btn"),
linksList = document.querySelector("#links-list");
// Clear the list and show the "You don't have any shortened links" message
function resetLinksList() {
linksList.innerHTML = `
<li id="default-message">
<div class="link-icon"><img src="assets/images/url.png" class="url-img"></div>
<div class="link-info">
<span class="short-link">xeorl.buzz/*****</span>
<span class="long-link">You don't have any shortened links</span>
</div>
<button class="copy-btn"><img src="assets/images/copy.png"></button>
<button class="delete-btn"><img src="assets/images/delete.png"></button>
</li>
`;
}
// Check session storage for existing links on page load
document.addEventListener("DOMContentLoaded", () => {
const savedLinks = sessionStorage.getItem("shortenedLinks");
if (savedLinks) {
linksList.innerHTML = savedLinks;
} else {
resetLinksList();
}
});
shortenBtn.onclick = () => {
let xhr = new XMLHttpRequest();
xhr.open("POST", "core/url-controll.php", true);
@@ -13,6 +38,13 @@ shortenBtn.onclick = () => {
let domain = "xeorl.buzz/";
let shortenURL = domain + data;
// Remove the default message if it exists
const defaultMessage = document.getElementById("default-message");
if (defaultMessage) {
defaultMessage.remove();
}
// Add the new link to the list
let newRow = `
<li>
<div class="link-icon"><img src="assets/images/url.png" class="logo-img"></div>
@@ -24,9 +56,13 @@ shortenBtn.onclick = () => {
<button class="delete-btn"><img src="assets/images/delete.png"></button>
</li>
`;
// Append the new link to the list and update session storage
linksList.insertAdjacentHTML('afterbegin', newRow);
urlInput.value = ""; // Clear the input field
location.reload(); // Reload the page after shortening
sessionStorage.setItem("shortenedLinks", linksList.innerHTML);
// Clear the input field
urlInput.value = "";
} else {
alert(data);
}
@@ -47,6 +83,14 @@ document.addEventListener('click', function(e) {
}
});
// Handle members only delete button clicks!!
document.addEventListener('click', function(e) {
if (e.target.closest('.delete-btn')) {
alert("This feature is available for members only.");
}
});
// Handle delete button clicks
/*
document.addEventListener('click', function(e) {
@@ -74,12 +118,3 @@ document.addEventListener('click', function(e) {
}
});*/
// Handle members only delete button clicks!!
document.querySelectorAll(".delete-btn").forEach((deleteBtn) => {
deleteBtn.addEventListener("click", function () {
// Alert instead of delete functionality
alert("This feature is available for members only.");
});
});

View File

@@ -0,0 +1,24 @@
<?php
session_start();
include "config.php";
// Check if the session variable for storing shortened links exists
if (!isset($_SESSION['shortened_links'])) {
$_SESSION['shortened_links'] = array();
}
// Retrieve and return the list of shortened links for the current session
$links = array();
foreach ($_SESSION['shortened_links'] as $link_id) {
$sql = mysqli_query($conn, "SELECT * FROM url WHERE id = '{$link_id}'");
if (mysqli_num_rows($sql) > 0) {
$row = mysqli_fetch_assoc($sql);
$links[] = array(
'short_url' => $row['shorten_url'],
'full_url' => $row['full_url']
);
}
}
echo json_encode($links);
?>

View File

@@ -1,23 +1,29 @@
<?php
include "config.php";
$full_url = mysqli_real_escape_string($conn, $_POST['full_url']);
if(!empty($full_url) && filter_var($full_url, FILTER_VALIDATE_URL)){
$ran_url = substr(md5(microtime()), rand(0, 26), 5);
$sql = mysqli_query($conn, "SELECT * FROM url WHERE shorten_url = '{$ran_url}'");
if(mysqli_num_rows($sql) > 0){
echo "Something went wrong. Please generate again!";
}else{
$sql2 = mysqli_query($conn, "INSERT INTO url (full_url, shorten_url, clicks)
VALUES ('{$full_url}', '{$ran_url}', '0')");
if($sql2){
$sql3 = mysqli_query($conn, "SELECT shorten_url FROM url WHERE shorten_url = '{$ran_url}'");
if(mysqli_num_rows($sql3) > 0){
$shorten_url = mysqli_fetch_assoc($sql3);
echo $shorten_url['shorten_url'];
}
session_start();
include "config.php";
$full_url = mysqli_real_escape_string($conn, $_POST['full_url']);
if (!empty($full_url) && filter_var($full_url, FILTER_VALIDATE_URL)) {
$ran_url = substr(md5(microtime()), rand(0, 26), 5);
$sql = mysqli_query($conn, "SELECT * FROM url WHERE shorten_url = '{$ran_url}'");
if (mysqli_num_rows($sql) > 0) {
echo "Something went wrong. Please generate again!";
} else {
$sql2 = mysqli_query($conn, "INSERT INTO url (full_url, shorten_url, clicks)
VALUES ('{$full_url}', '{$ran_url}', '0')");
if ($sql2) {
$link_id = mysqli_insert_id($conn); // Get the ID of the newly inserted row
if (!isset($_SESSION['shortened_links'])) {
$_SESSION['shortened_links'] = array();
}
$_SESSION['shortened_links'][] = $link_id; // Store the link ID in session
$shorten_url = $ran_url;
echo $shorten_url;
}
}else{
echo "$full_url - This is not a valid URL!";
}
?>
} else {
echo "$full_url - This is not a valid URL!";
}
?>