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) ✨ ### 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/) [![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/) [![PRs](https://img.shields.io/badge/PRs-welcome-blue.svg?style=flat)](https://github.com/xeorl/xeorl-portfolio/)
<br></br> <br></br>

View File

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

View File

@@ -3,6 +3,31 @@ const form = document.querySelector(".shorten-form"),
shortenBtn = document.querySelector("#shorten-btn"), shortenBtn = document.querySelector("#shorten-btn"),
linksList = document.querySelector("#links-list"); 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 = () => { shortenBtn.onclick = () => {
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.open("POST", "core/url-controll.php", true); xhr.open("POST", "core/url-controll.php", true);
@@ -13,6 +38,13 @@ shortenBtn.onclick = () => {
let domain = "xeorl.buzz/"; let domain = "xeorl.buzz/";
let shortenURL = domain + data; 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 = ` let newRow = `
<li> <li>
<div class="link-icon"><img src="assets/images/url.png" class="logo-img"></div> <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> <button class="delete-btn"><img src="assets/images/delete.png"></button>
</li> </li>
`; `;
// Append the new link to the list and update session storage
linksList.insertAdjacentHTML('afterbegin', newRow); linksList.insertAdjacentHTML('afterbegin', newRow);
urlInput.value = ""; // Clear the input field sessionStorage.setItem("shortenedLinks", linksList.innerHTML);
location.reload(); // Reload the page after shortening
// Clear the input field
urlInput.value = "";
} else { } else {
alert(data); 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 // Handle delete button clicks
/* /*
document.addEventListener('click', function(e) { 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 <?php
include "config.php"; session_start();
$full_url = mysqli_real_escape_string($conn, $_POST['full_url']); include "config.php";
if(!empty($full_url) && filter_var($full_url, FILTER_VALIDATE_URL)){ $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); $ran_url = substr(md5(microtime()), rand(0, 26), 5);
$sql = mysqli_query($conn, "SELECT * FROM url WHERE shorten_url = '{$ran_url}'"); $sql = mysqli_query($conn, "SELECT * FROM url WHERE shorten_url = '{$ran_url}'");
if(mysqli_num_rows($sql) > 0){
if (mysqli_num_rows($sql) > 0) {
echo "Something went wrong. Please generate again!"; echo "Something went wrong. Please generate again!";
}else{ } else {
$sql2 = mysqli_query($conn, "INSERT INTO url (full_url, shorten_url, clicks) $sql2 = mysqli_query($conn, "INSERT INTO url (full_url, shorten_url, clicks)
VALUES ('{$full_url}', '{$ran_url}', '0')"); VALUES ('{$full_url}', '{$ran_url}', '0')");
if($sql2){ if ($sql2) {
$sql3 = mysqli_query($conn, "SELECT shorten_url FROM url WHERE shorten_url = '{$ran_url}'"); $link_id = mysqli_insert_id($conn); // Get the ID of the newly inserted row
if(mysqli_num_rows($sql3) > 0){ if (!isset($_SESSION['shortened_links'])) {
$shorten_url = mysqli_fetch_assoc($sql3); $_SESSION['shortened_links'] = array();
echo $shorten_url['shorten_url']; }
$_SESSION['shortened_links'][] = $link_id; // Store the link ID in session
$shorten_url = $ran_url;
echo $shorten_url;
} }
} }
} } else {
}else{
echo "$full_url - This is not a valid URL!"; echo "$full_url - This is not a valid URL!";
} }
?> ?>