From b59f2f0596f6979fe9c98b736d69c53824a599a8 Mon Sep 17 00:00:00 2001 From: pikami Date: Thu, 16 Jun 2016 14:34:00 +0000 Subject: [PATCH] Changes to paste expiry --- MyPastes.php | 10 ++++++++++ NewPastePanel.php | 1 + ViewPaste.php | 18 +++++++++++++++++- config/config.php | 10 ++++++---- cronjob.php | 21 ++++++++++++--------- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/MyPastes.php b/MyPastes.php index 8f5c92c..050b2ff 100644 --- a/MyPastes.php +++ b/MyPastes.php @@ -17,12 +17,22 @@ if($stmt->rowCount()>0){ echo ""; printf(' + '); printf(''); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $title = $row['title']; printf(''); printf(''); + if($row["expire"]==0) printf(''); + else{ + $expire = ($row["expire"]-time())/3600; + if($expire>24){ + printf(''); + } else if($expire>=1) + printf(''); + else printf(''); + } printf(''); } printf(''); diff --git a/NewPastePanel.php b/NewPastePanel.php index 8e9ce69..01d7c22 100644 --- a/NewPastePanel.php +++ b/NewPastePanel.php @@ -29,6 +29,7 @@ + diff --git a/ViewPaste.php b/ViewPaste.php index d199074..55cb9ab 100644 --- a/ViewPaste.php +++ b/ViewPaste.php @@ -8,6 +8,12 @@ if(isset($uid)){ $stmt = $conn->query('SELECT * FROM pastes WHERE uid="'.$uid.'"'); if($result = $stmt->fetch(PDO::FETCH_ASSOC)){ $conn = null; + if($result["expire"]This paste is private"; die(); @@ -19,7 +25,17 @@ if(isset($uid)){ if($owner[1] == -1) echo "Posted by: Guest"; else echo "Posted by: ".htmlspecialchars($owner[1]).""; - echo ", at ".date('Y-m-d',$result["created"]).""; + echo ", at ".date('Y-m-d',$result["created"]).", it will expire "; + if($result["expire"]==0) printf('Never'); + else{ + $expire = ($result["expire"]-time())/3600; + if($expire>24){ + printf(round($expire/24).' days from now'); + } else if($expire>=1) + printf(round($expire).' hours from now'); + else printf(round($expire*60).' minutes from now'); + } + echo ""; // echo "
";
 		echo htmlspecialchars($result["text"], ENT_QUOTES, 'UTF-8')."
"; diff --git a/config/config.php b/config/config.php index aa3c0cc..9e21d75 100644 --- a/config/config.php +++ b/config/config.php @@ -1,9 +1,11 @@ diff --git a/cronjob.php b/cronjob.php index 702f136..183dcba 100644 --- a/cronjob.php +++ b/cronjob.php @@ -1,15 +1,18 @@ prepare("DELETE from `pastes` where `expire`<:time and `expire`>0"); + $stmt->bindValue(':time', $time); + $stmt->execute(); + $conn = null; //close connection to database + echo 'OK! 200'; +} if (isset($_GET["key"])){ - if($_GET["key"]=="b1g51bf6g"){ //Kill sessions - include "config/config.php"; - $time = time(); - $stmt = $conn->prepare("DELETE from `pastes` where `expire`<:time and `expire`>0"); - $stmt->bindValue(':time', $time); - $stmt->execute(); - $conn = null; //close connection to database - echo 'OK! 200'; + if($_GET["key"]==$CRON_ExpireKey){ //Delete expired pastes + RemoveExpiredPastes(); } } -//Cron job example: */5 * * * * curl --silent http://127.0.0.1/paste/cronjob.php?key=b1g51bf6g > /dev/null +//Cron job example: */5 * * * * curl --silent http://127.0.0.1/paste/cronjob.php?key=fgd45fb5fb15gb > /dev/null //More about cron jobs: http://www.shellhacks.com/en/Adding-Cron-Jobs-in-Linux-Crontab-Usage-and-Examples ?> \ No newline at end of file
Title AddedExpires ID
'.htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8').''.date('Y-m-d',$row["created"]).'Never'.round($expire/24).' days from now'.round($expire).' hours from now'.round($expire*60).' minutes from now'.htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8').'