Refactor pastes to use repository

This commit is contained in:
Pijus Kamandulis 2023-09-14 23:33:31 +03:00
parent 6617d03a17
commit d3970c3116
14 changed files with 495 additions and 337 deletions

View File

@ -1,18 +1,11 @@
<?php <?php
include_once "includes/config.php"; include_once "includes/config.php";
function RemoveExpiredPastes()
{
$conn = GetConnectionToDB();
$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 (isset($_GET["key"])) { if (isset($_GET["key"])) {
if ($_GET["key"] == $CRON_ExpireKey) { //Delete expired pastes if ($_GET["key"] == $CRON_ExpireKey) { //Delete expired pastes
RemoveExpiredPastes(); include_once "repositories/paste-repository.php";
$pasteRepo = new PasteRepository();
echo $pasteRepo->removeExpiredPastes();
} }
} }
//Cron job example: */5 * * * * curl --silent http://127.0.0.1/paste/cronjob.php?key=fgd45fb5fb15gb > /dev/null //Cron job example: */5 * * * * curl --silent http://127.0.0.1/paste/cronjob.php?key=fgd45fb5fb15gb > /dev/null

View File

@ -6,35 +6,19 @@
include_once "includes/user.php"; include_once "includes/user.php";
$uid = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]); $uid = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]);
$paste = $_GET['id']; $paste = $_GET['id'];
//connect to db and get paste info
$conn = GetConnectionToDB(); include_once "repositories/paste-repository.php";
$stmt = $conn->prepare('SELECT * FROM pastes WHERE uid=:uid'); $pasteRepo = new PasteRepository();
$stmt->bindParam(':uid', $paste); $result = $pasteRepo->deletePasteByUID($paste, $uid);
$stmt->execute(); if ($result === 'OK! 200') {
if ($stmt->rowCount() > 0) { echo '<center><h4>Paste ' . $paste . ' has been deleted!</h4></center>';
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo '<meta http-equiv="refresh" content="2;url=../index.php">';
if ($row['owner'] === $uid) { die();
$stmt2 = $conn->prepare("DELETE FROM pastes WHERE id=:id");
$stmt2->bindParam(':id', $row['id']);
$stmt2->execute();
$conn = null;
echo '<center><h4>Paste ' . $row["uid"] . ' has been deleted!</h4></center>';
echo '<meta http-equiv="refresh" content="2;url=../index.php">';
die();
} else {
$conn = null;
echo '<center><h4>You are not the owner of the paste ' . $row["uid"] . '</h4></center>';
echo '<meta http-equiv="refresh" content="2;url=../index.php">';
die();
}
}
} else { } else {
$conn = null; echo '<center><h4>' . $result . '</h4></center>';
echo '<center><h4>The paste ' . $row["uid"] . ' does not exist</h4></center>';
echo '<meta http-equiv="refresh" content="2;url=../index.php">'; echo '<meta http-equiv="refresh" content="2;url=../index.php">';
die(); die();
} }
$conn = null;
} }
?> ?>
</div> </div>

View File

@ -11,3 +11,5 @@ function GetConnectionToDB() {
} }
//========CRON_JOBS=========// //========CRON_JOBS=========//
$CRON_ExpireKey = getenv('CRON_EXPIREKEY') ?: "b1g51bf6g"; $CRON_ExpireKey = getenv('CRON_EXPIREKEY') ?: "b1g51bf6g";
//=========GENERAL==========//
$BASE_DIR = "/";

View File

@ -1,49 +1,51 @@
<?php <?php
$_HL = "plain"; include_once "includes/config.php";
if (isset($_GET["page"])){
if($_GET["page"] == "create" || $_GET["page"] == "mypastes" || $_GET["page"] == "login" || $_GET["page"] == "logout" || $_GET["page"] == "signup"); $_HL = "plain";
else { if (isset($_GET["page"])) {
$uid = $_GET["page"]; if ($_GET["page"] == "create" || $_GET["page"] == "mypastes" || $_GET["page"] == "login" || $_GET["page"] == "logout" || $_GET["page"] == "signup");
echo '<script type="text/javascript" src="public/js/SyntaxHighlighter/shCore.js"></script>'; else {
//
include_once "includes/config.php"; $uid = $_GET["page"];
$conn = GetConnectionToDB(); echo '<script type="text/javascript" src="' . $BASE_DIR . 'public/js/SyntaxHighlighter/shCore.js"></script>';
$stmt = $conn->query('SELECT highlight FROM pastes WHERE uid="'.$uid.'"');
if($result = $stmt->fetch(PDO::FETCH_ASSOC)){ include_once "repositories/paste-repository.php";
$conn = null; $pasteRepo = new PasteRepository();
$_HL = $result["highlight"]; $_HL = $pasteRepo->getSyntaxHighlightByUID($uid);
if($_HL == "")$_HL = "plain";
echo '<script type="text/javascript" src="public/js/SyntaxHighlighter/'; if ($_HL === "") {
if($result["highlight"]=="cpp")echo 'shBrushCpp.js'; $_HL = "plain";
else if($result["highlight"]=="python")echo 'shBrushPython.js';
else if($result["highlight"]=="applescript")echo 'shBrushAppleScript.js';
else if($result["highlight"]=="as3")echo 'shBrushAS3.js';
else if($result["highlight"]=="bash")echo 'shBrushBash.js';
else if($result["highlight"]=="cf")echo 'shBrushColdFusion.js';
else if($result["highlight"]=="csharp")echo 'shBrushCSharp.js';
else if($result["highlight"]=="css")echo 'shBrushCss.js';
else if($result["highlight"]=="delphi")echo 'shBrushDelphi.js';
else if($result["highlight"]=="diff")echo 'shBrushDiff.js';
else if($result["highlight"]=="erlang")echo 'shBrushErlang.js';
else if($result["highlight"]=="groovy")echo 'shBrushGroovy.js';
else if($result["highlight"]=="java")echo 'shBrushJava.js';
else if($result["highlight"]=="javafx")echo 'shBrushJavaFX.js';
else if($result["highlight"]=="jscript")echo 'shBrushJScript.js';
else if($result["highlight"]=="perl")echo 'shBrushPerl.js';
else if($result["highlight"]=="php")echo 'shBrushPhp.js';
else if($result["highlight"]=="powershell")echo 'shBrushPowerShell.js';
else if($result["highlight"]=="ruby")echo 'shBrushRuby.js';
else if($result["highlight"]=="sass")echo 'shBrushSass.js';
else if($result["highlight"]=="scala")echo 'shBrushScala.js';
else if($result["highlight"]=="sql")echo 'shBrushSql.js';
else if($result["highlight"]=="vb")echo 'shBrushVb.js';
else if($result["highlight"]=="xml")echo 'shBrushXml.js';
else echo 'shBrushPlain.js';
echo '"></script>';
}
$conn = null;
//
echo '<link href="public/css/SyntaxHighlighter/shCore.css" rel="stylesheet" type="text/css">
<link href="public/css/SyntaxHighlighter/shThemeDefault.css" rel="stylesheet" type="text/css" />';
} }
$highlightToBrushFileMap = [
"python" => 'shBrushPython.js',
"applescript" => 'shBrushAppleScript.js',
"as3" => 'shBrushAS3.js',
"bash" => 'shBrushBash.js',
"cf" => 'shBrushColdFusion.js',
"csharp" => 'shBrushCSharp.js',
"css" => 'shBrushCss.js',
"delphi" => 'shBrushDelphi.js',
"diff" => 'shBrushDiff.js',
"erlang" => 'shBrushErlang.js',
"groovy" => 'shBrushGroovy.js',
"java" => 'shBrushJava.js',
"javafx" => 'shBrushJavaFX.js',
"jscript" => 'shBrushJScript.js',
"perl" => 'shBrushPerl.js',
"php" => 'shBrushPhp.js',
"powershell" => 'shBrushPowerShell.js',
"ruby" => 'shBrushRuby.js',
"sass" => 'shBrushSass.js',
"scala" => 'shBrushScala.js',
"sql" => 'shBrushSql.js',
"vb" => 'shBrushVb.js',
"xml" => 'shBrushXml.js',
];
$brushFile = $highlightToBrushFileMap[$_HL] ?? 'shBrushPlain.js';
echo '<script type="text/javascript" src="public/js/SyntaxHighlighter/' . $brushFile . '"></script>';
echo '<link href="' . $BASE_DIR . 'public/css/SyntaxHighlighter/shCore.css" rel="stylesheet" type="text/css">
<link href="' . $BASE_DIR . 'public/css/SyntaxHighlighter/shThemeDefault.css" rel="stylesheet" type="text/css" />';
} }
}

View File

@ -1,126 +1,51 @@
<?php <?php
include_once "includes/config.php"; include_once "includes/config.php";
function generate_uid () { include_once "repositories/paste-repository.php";
$conn = GetConnectionToDB(); $pasteRepo = new PasteRepository();
$name = '';
// We start at N retries, and --N until we give up
$tries = 500;
do {
// Iterate until we reach the maximum number of retries
if ($tries-- == 0) throw new Exception('Gave up trying to find an unused name', 500);
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$name = '';
for ($i = 0; $i < 8; $i++) {
$name .= $chars[mt_rand(0, 61)];
// $chars string length is hardcoded, should use a variable to store it?
}
// Check if a paste with the same uid does already exist in the database
$q = $conn->prepare('SELECT COUNT(uid) FROM pastes WHERE uid = (:name)');
$q->bindValue(':name', $name, PDO::PARAM_STR);
$q->execute();
$result = $q->fetchColumn();
// If it does, generate a new uid
} while($result > 0);
$conn = null;
return $name;
}
if(isset($_POST["type"])){ if (isset($_POST["type"]) && isset($_POST["text"])) {
//===New_Paste===// // Set paste details
if($_POST["type"]=="paste" && isset($_POST["text"])){ $title = isset($_POST["title"]) && !empty($_POST["title"]) ? $_POST["title"] : "Untitled";
/* Set paste details */ $text = $_POST["text"];
$title = "Untitled"; $exposure = isset($_POST["exposure"]) && is_numeric($_POST["exposure"]) ? $_POST["exposure"] : 0;
$text = $_POST["text"];
$exposure = 0; // Common details for both create and edit
if(isset($_POST["title"]) && $_POST["title"]!="") $uid = isset($_POST["uid"]) ? $_POST["uid"] : $pasteRepo->generateUniqueUID();
$title = $_POST["title"]; $created = time();
if(isset($_POST["exposure"]) && is_numeric($_POST["exposure"])) $expire = isset($_POST["expire"]) && is_numeric($_POST["expire"]) ? ($created + $_POST["expire"]) : 0;
$exposure = $_POST["exposure"];
$uid = generate_uid(); $owner = 0;
$created = time(); $syntax = isset($_POST["syntax"]) ? $_POST["syntax"] : "plain";
$expire = 0;
if(isset($_POST["expire"]) && is_numeric($_POST["expire"])) if (isset($_POST["asguest"]) && $_POST["asguest"] == "on") {
$expire = $created + $_POST["expire"];
$owner = 0; $owner = 0;
$syntax = "plain"; } elseif (isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"])) {
if(isset($_POST["syntax"])) include "includes/user.php";
$syntax=$_POST["syntax"]; $owner = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]);
if(isset($_POST["asguest"]) && $_POST["asguest"]=="on") }
$owner = 0;
else if(isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"])){ if ($_POST["type"] == "paste") {
include "includes/user.php"; // Add paste to the database using the repository
$owner = GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"]); $result = $pasteRepo->create($uid, $title, $text, $created, $expire, $exposure, $owner, $syntax);
} } elseif ($_POST["type"] == "edit_paste" && isset($_POST["uid"])) {
/* Add paste to database */ // Get the owner of the paste from the database
$conn = GetConnectionToDB(); $existingPaste = $pasteRepo->readByUid($uid);
$QuerySTR = "INSERT INTO pastes (uid,title,text,created,expire,exposure,owner,highlight)
VALUES (:uid, :tit, :txt, :cre, :exp, :exposure, :own, :hl)"; // Edit paste in the database using the repository
$stmt = $conn->prepare($QuerySTR); if ($owner === $existingPaste["owner"] && $owner !== 0) {
$stmt->bindParam(':exp', $expire); $result = $pasteRepo->update($existingPaste["id"], $uid, $title, $text, $created, $expire, $exposure, $owner, $syntax);
$stmt->bindParam(':uid', $uid);
$stmt->bindParam(':tit', $title);
$stmt->bindParam(':txt', $text);
$stmt->bindParam(':cre', $created);
$stmt->bindParam(':exposure', $exposure);
$stmt->bindParam(':own', $owner);
$stmt->bindParam(':hl', $syntax);
$stmt->execute();
$conn = null; //close connection to database
header("Location: ".$uid);
die();
} else if($_POST["type"]=="edit_paste" && isset($_POST["text"])){
/* Set paste details */
$title = "Untitled";
$text = $_POST["text"];
$exposure = 0;
if(isset($_POST["title"]))
$title = $_POST["title"];
if(isset($_POST["exposure"]) && is_numeric($_POST["exposure"]))
$exposure = $_POST["exposure"];
$uid = $_POST["uid"];
$created = time();
$expire = 0;
if(isset($_POST["expire"]) && is_numeric($_POST["expire"]))
$expire = $created + $_POST["expire"];
$owner = 0;
$syntax = "plain";
if(isset($_POST["syntax"]))
$syntax=$_POST["syntax"];
if(isset($_POST["asguest"]) && $_POST["asguest"]=="on")
$owner = 0;
else if(isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"])){
include "includes/user.php";
$owner = GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"]);
}
/* Get the owner of the paste */
$paste_owner = 0;
$conn = GetConnectionToDB();
$stmt = $conn->query('SELECT owner FROM pastes WHERE uid="'.$uid.'"');
if($result = $stmt->fetch(PDO::FETCH_ASSOC)){
$paste_owner = $result['owner'];
}
/* Edit paste in database */
if($owner === $paste_owner && $owner !== 0){
$QuerySTR = " UPDATE pastes SET title=:tit,text=:txt,created=:cre,expire=:exp,exposure=:exposure,owner=:own,highlight=:hl
WHERE uid=:uid";
$stmt = $conn->prepare($QuerySTR);
$stmt->bindParam(':exp', $expire);
$stmt->bindParam(':uid', $uid);
$stmt->bindParam(':tit', $title);
$stmt->bindParam(':txt', $text);
$stmt->bindParam(':cre', $created);
$stmt->bindParam(':exposure', $exposure);
$stmt->bindParam(':own', $owner);
$stmt->bindParam(':hl', $syntax);
$stmt->execute();
$conn = null; //close connection to database
header("Location: ".$uid);
die();
} else { } else {
$conn = null; //close connection to database
echo "<h1>This paste does not belong to you!</h1>"; echo "<h1>This paste does not belong to you!</h1>";
die(); die();
} }
} }
if ($result) {
header("Location: " . $uid);
die();
} else {
echo "<h1>Error processing the paste!</h1>";
die();
}
} }

View File

@ -0,0 +1,228 @@
<?php
include_once "includes/config.php";
class PasteRepository
{
private $conn;
private $table_name = "pastes";
public function __construct()
{
$this->conn = GetConnectionToDB();
}
function __destruct()
{
$this->conn = null;
}
// Create a new paste
public function create($uid, $title, $text, $created, $expire, $exposure, $owner, $highlight)
{
$query = "INSERT INTO " . $this->table_name . "
(uid, title, text, created, expire, exposure, owner, highlight)
VALUES (:uid, :title, :text, :created, :expire, :exposure, :owner, :highlight)";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(":uid", $uid);
$stmt->bindParam(":title", $title);
$stmt->bindParam(":text", $text);
$stmt->bindParam(":created", $created);
$stmt->bindParam(":expire", $expire);
$stmt->bindParam(":exposure", $exposure);
$stmt->bindParam(":owner", $owner);
$stmt->bindParam(":highlight", $highlight);
if ($stmt->execute()) {
return true;
} else {
return false;
}
}
// Read a paste by ID
public function read($id)
{
$query = "SELECT * FROM " . $this->table_name . " WHERE id = :id";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(":id", $id);
$stmt->execute();
return $stmt->fetch(PDO::FETCH_ASSOC);
}
// Read a paste by UID
public function readByUid($uid)
{
$query = "SELECT * FROM " . $this->table_name . " WHERE uid = :uid";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(":uid", $uid);
$stmt->execute();
return $stmt->fetch(PDO::FETCH_ASSOC);
}
// Update a paste
public function update($id, $uid, $title, $text, $created, $expire, $exposure, $owner, $highlight)
{
$query = "UPDATE " . $this->table_name . " SET
uid = :uid,
title = :title,
text = :text,
created = :created,
expire = :expire,
exposure = :exposure,
owner = :owner,
highlight = :highlight
WHERE id = :id";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(":id", $id);
$stmt->bindParam(":uid", $uid);
$stmt->bindParam(":title", $title);
$stmt->bindParam(":text", $text);
$stmt->bindParam(":created", $created);
$stmt->bindParam(":expire", $expire);
$stmt->bindParam(":exposure", $exposure);
$stmt->bindParam(":owner", $owner);
$stmt->bindParam(":highlight", $highlight);
if ($stmt->execute()) {
return true;
} else {
return false;
}
}
// Delete a paste by ID
public function delete($id)
{
$query = "DELETE FROM " . $this->table_name . " WHERE id = :id";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(":id", $id);
if ($stmt->execute()) {
return true;
} else {
return false;
}
}
// Get pastes with a specific exposure value and limit
public function getPastesWithExposure($exposureValue, $limit)
{
$query = "SELECT * FROM " . $this->table_name . " WHERE exposure = :exposureValue ORDER BY id DESC LIMIT :limit";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(":exposureValue", $exposureValue, PDO::PARAM_INT);
$stmt->bindParam(":limit", $limit, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
// Remove expired pastes
public function removeExpiredPastes()
{
$time = time();
$query = "DELETE FROM " . $this->table_name . " WHERE `expire` < :time AND `expire` > 0";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(':time', $time, PDO::PARAM_INT);
if ($stmt->execute()) {
return 'OK! 200';
} else {
return 'Error!';
}
}
// Delete a paste by UID and owner
public function deletePasteByUID($uid, $owner)
{
$query = "SELECT * FROM " . $this->table_name . " WHERE uid = :uid";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(':uid', $uid);
$stmt->execute();
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row['owner'] === $owner) {
$deleteQuery = "DELETE FROM " . $this->table_name . " WHERE id = :id";
$deleteStmt = $this->conn->prepare($deleteQuery);
$deleteStmt->bindParam(':id', $row['id']);
$deleteStmt->execute();
return 'OK! 200';
} else {
return 'You are not the owner of the paste ' . $row['uid'];
}
}
} else {
return 'The paste ' . $uid . ' does not exist';
}
}
// Generate a random unique UID for a new paste
public function generateUniqueUID()
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$uid = '';
// Maximum number of retries to find an unused name
$maxRetries = 500;
$tries = $maxRetries;
do {
if ($tries-- === 0) {
throw new Exception('Gave up trying to find an unused name', 500);
}
for ($i = 0; $i < 8; $i++) {
$uid .= $chars[mt_rand(0, 61)];
}
$query = "SELECT COUNT(uid) FROM " . $this->table_name . " WHERE uid = :uid";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(':uid', $uid, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchColumn();
} while ($result > 0);
return $uid;
}
// Get syntax highlight for a paste by UID
public function getSyntaxHighlightByUID($uid)
{
$query = "SELECT highlight FROM " . $this->table_name . " WHERE uid = :uid";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(':uid', $uid);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result['highlight'];
} else {
return "";
}
}
// Get pastes by owner ID and exposure condition
public function getPastesByOwner($ownerID, $includePrivate = false)
{
$query = "SELECT * FROM " . $this->table_name . " WHERE owner = :ownerID";
if (!$includePrivate) {
$query .= " AND exposure = 0";
}
$query .= " ORDER BY id DESC";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(":ownerID", $ownerID);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}

View File

@ -1,4 +1,6 @@
<?php <?php
include_once "includes/config.php";
if (!isset($content)) { if (!isset($content)) {
$content = '<p>no content</p>'; $content = '<p>no content</p>';
} }
@ -12,19 +14,17 @@ if (!isset($content)) {
<meta charset="utf-8"> <meta charset="utf-8">
<?php <?php
echo '<meta name="viewport" content="width=device-width, initial-scale=1">'; echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
$dir = "";
if (isset($_GET["user"]) || isset($_GET["page"]) && $_GET["page"] == "edit") $dir = "../";
echo '<link rel="stylesheet" href="' . $dir . 'public/css/bootstrap.min.css">'; echo '<link rel="stylesheet" href="' . $BASE_DIR . 'public/css/bootstrap.min.css">';
echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>'; echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>';
echo '<script src="' . $dir . 'public/js/bootstrap.min.js"></script>'; echo '<script src="' . $BASE_DIR . 'public/js/bootstrap.min.js"></script>';
echo '<script type="text/javascript" src="' . $dir . 'public/js/jquery.dynatable.js"></script>'; echo '<script type="text/javascript" src="' . $BASE_DIR . 'public/js/jquery.dynatable.js"></script>';
echo '<link href="' . $dir . 'public/css/jquery.dynatable.css" rel="stylesheet">'; echo '<link href="' . $BASE_DIR . 'public/css/jquery.dynatable.css" rel="stylesheet">';
echo '<link href="' . $dir . 'public/css/chosen.css" rel="stylesheet">'; echo '<link href="' . $BASE_DIR . 'public/css/chosen.css" rel="stylesheet">';
echo '<script src="' . $dir . 'public/js/chosen.jquery.js" type="text/javascript"></script>'; echo '<script src="' . $BASE_DIR . 'public/js/chosen.jquery.js" type="text/javascript"></script>';
echo '<script src="' . $dir . 'public/js/chosen.proto.js" type="text/javascript"></script>'; echo '<script src="' . $BASE_DIR . 'public/js/chosen.proto.js" type="text/javascript"></script>';
echo "<script>$(document).ready(function(){ echo "<script>$(document).ready(function(){
$('#tablepastes').dynatable(); $('#tablepastes').dynatable();

View File

@ -1,10 +1,10 @@
<?php include_once "includes/config.php"; ?>
<nav class="navbar navbar-inverse"> <nav class="navbar navbar-inverse">
<div class="container"> <div class="container">
<div class="navbar-header"> <div class="navbar-header">
<?php <?php
$dir = ""; echo '<a class="navbar-brand" href="' . $BASE_DIR . '.">Palm-Paste</a>';
if (isset($_GET["user"]) || isset($_GET["page"]) && $_GET["page"] == "edit") $dir = "../";
echo '<a class="navbar-brand" href="' . $dir . '.">Palm-Paste</a>';
?> ?>
</div> </div>
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
@ -15,13 +15,11 @@
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<?php <?php
include_once "includes/user.php"; include_once "includes/user.php";
$dir = "";
if (isset($_GET["user"]) || isset($_GET["page"]) && $_GET["page"] == "edit") $dir = "../";
$userID = -1; $userID = -1;
if (isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"])) if (isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]))
$userID = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]); $userID = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]);
if ($userID == -1) { if ($userID == -1) {
echo "<li><a href=\"" . $dir . "signup\"><span class=\"glyphicon glyphicon-user\"></span> Sign Up</a></li>"; echo "<li><a href=\"" . $BASE_DIR . "signup\"><span class=\"glyphicon glyphicon-user\"></span> Sign Up</a></li>";
echo "<li><a data-toggle=\"modal\" data-target=\"#LoginPopup\" href=\"#\"><span class=\"glyphicon glyphicon-log-in\"></span> Login</a></li>"; echo "<li><a data-toggle=\"modal\" data-target=\"#LoginPopup\" href=\"#\"><span class=\"glyphicon glyphicon-log-in\"></span> Login</a></li>";
} else { } else {
$user = GetUserByID($userID); $user = GetUserByID($userID);
@ -29,8 +27,8 @@
<li class="dropdown"> <li class="dropdown">
<a class="dropdown-toggle glyphicon glyphicon-user" data-toggle="dropdown" href="#"> ' . htmlspecialchars($user[1], ENT_QUOTES, 'UTF-8') . '<span class="caret"></span></a> <a class="dropdown-toggle glyphicon glyphicon-user" data-toggle="dropdown" href="#"> ' . htmlspecialchars($user[1], ENT_QUOTES, 'UTF-8') . '<span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="' . $dir . 'mypastes">My pastes</a></li> <li><a href="' . $BASE_DIR . 'mypastes">My pastes</a></li>
<li><a href="' . $dir . 'logout">Logout</a></li> <li><a href="' . $BASE_DIR . 'logout">Logout</a></li>
</ul> </ul>
</li> </li>
'; ';
@ -52,7 +50,7 @@
<div class="modal-body"> <div class="modal-body">
<!-- Login form --> <!-- Login form -->
<?php <?php
echo '<form role="form" method="POST" action="' . $dir . 'login">'; echo '<form role="form" method="POST" action="' . $BASE_DIR . 'login">';
?> ?>
<div class="form-group"> <div class="form-group">
<label for="user">Username:</label> <label for="user">Username:</label>

View File

@ -12,7 +12,7 @@
<label for="title">Paste title:</label> <label for="title">Paste title:</label>
<?php <?php
if ($edit_mode == true) { if ($edit_mode == true) {
printf('<input type="title" class="form-control" value="' . $row['title'] . '" id="title" name="title">'); printf('<input type="title" class="form-control" value="' . $pasteInfo['title'] . '" id="title" name="title">');
} else printf('<input type="title" class="form-control" id="title" name="title">'); } else printf('<input type="title" class="form-control" id="title" name="title">');
?> ?>
</div> </div>
@ -20,14 +20,14 @@
<label for="text">New paste:</label> <label for="text">New paste:</label>
<?php <?php
if ($edit_mode == true) { if ($edit_mode == true) {
echo '<textarea class="form-control" rows="5" id="text" name="text">' . $row['text'] . '</textarea>'; echo '<textarea class="form-control" rows="5" id="text" name="text">' . $pasteInfo['text'] . '</textarea>';
} else printf('<textarea class="form-control" rows="5" id="text" name="text"></textarea>'); } else printf('<textarea class="form-control" rows="5" id="text" name="text"></textarea>');
?> ?>
</div> </div>
<?php <?php
if ($edit_mode == true) { if ($edit_mode == true) {
printf("<input type='hidden' name='type' value='edit_paste'></input>"); printf("<input type='hidden' name='type' value='edit_paste'></input>");
printf("<input type='hidden' name='uid' value='" . $row['uid'] . "'></input>"); printf("<input type='hidden' name='uid' value='" . $pasteInfo['uid'] . "'></input>");
} else printf("<input type='hidden' name='type' value='paste'></input>"); } else printf("<input type='hidden' name='type' value='paste'></input>");
?> ?>
<div class="container-fluid"> <div class="container-fluid">
@ -58,7 +58,7 @@
<select data-placeholder="None" class="form-control chosen-select" id="syntax" name="syntax"> <select data-placeholder="None" class="form-control chosen-select" id="syntax" name="syntax">
<?php <?php
if ($edit_mode == true) if ($edit_mode == true)
print '<option value="' . $row['highlight'] . '">Current (' . $row['highlight'] . ')</option>'; print '<option value="' . $pasteInfo['highlight'] . '">Current (' . $pasteInfo['highlight'] . ')</option>';
?> ?>
<option value="plain">Plain</option> <option value="plain">Plain</option>
<option value="applescript">AppleScript</option> <option value="applescript">AppleScript</option>
@ -93,7 +93,7 @@
<select class="form-control" id="exposure" name="exposure"> <select class="form-control" id="exposure" name="exposure">
<?php <?php
print '<option value="0">Public</option>'; print '<option value="0">Public</option>';
if ($edit_mode == true && $row['exposure'] == 1) if ($edit_mode == true && $pasteInfo['exposure'] == 1)
print '<option selected="selected" value="1">Unlisted</option>'; print '<option selected="selected" value="1">Unlisted</option>';
else print '<option value="1">Unlisted</option>'; else print '<option value="1">Unlisted</option>';
include_once "includes/user.php"; include_once "includes/user.php";
@ -103,7 +103,7 @@
if ($userID == -1) if ($userID == -1)
print '<option value="2" disabled>Private (Members only)</option>'; print '<option value="2" disabled>Private (Members only)</option>';
else { else {
if ($edit_mode === true && $row['exposure'] === 2) if ($edit_mode === true && $pasteInfo['exposure'] === 2)
print '<option selected="selected" value="2" >Private</option>'; print '<option selected="selected" value="2" >Private</option>';
else print '<option value="2" >Private</option>'; else print '<option value="2" >Private</option>';
} }

View File

@ -3,15 +3,15 @@
<h4>Newest pastes:</h4> <h4>Newest pastes:</h4>
<div class="list-group"> <div class="list-group">
<?php <?php
include_once "includes/config.php"; include_once "repositories/paste-repository.php";
$conn = GetConnectionToDB(); $pasteRepo = new PasteRepository();
$stmt = $conn->query('SELECT * FROM pastes WHERE exposure=0 ORDER BY id DESC LIMIT 5'); $pastes = $pasteRepo->getPastesWithExposure(0, 5);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$title = htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8'); foreach ($pastes as $paste) {
$title = htmlspecialchars($paste['title'], ENT_QUOTES, 'UTF-8');
if (strlen($title) > 25) $title = substr($title, 0, 25) . "..."; if (strlen($title) > 25) $title = substr($title, 0, 25) . "...";
echo "<a href=\"" . htmlspecialchars($row['uid'], ENT_QUOTES, 'UTF-8') . "\" class=\"list-group-item\">" . $title . "</a>"; echo "<a href=\"" . htmlspecialchars($paste['uid'], ENT_QUOTES, 'UTF-8') . "\" class=\"list-group-item\">" . $title . "</a>";
} }
$conn = null;
?> ?>
</div> </div>
</div> </div>

View File

@ -6,28 +6,25 @@
include_once "includes/user.php"; include_once "includes/user.php";
$uid = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]); $uid = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]);
$paste = $_GET['id']; $paste = $_GET['id'];
//connect to db and get paste info
$conn = GetConnectionToDB(); include_once "repositories/paste-repository.php";
$stmt = $conn->prepare('SELECT * FROM pastes WHERE uid=:uid'); $pasteRepo = new PasteRepository();
$stmt->bindParam(':uid', $paste);
$stmt->execute(); // Get paste info
if ($stmt->rowCount() > 0) { $pasteInfo = $pasteRepo->readByUid($paste);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row['owner'] === $uid) { if ($pasteInfo) {
include "views/_new-paste.php"; if ($pasteInfo['owner'] === $uid) {
} else { include "views/_new-paste.php";
$conn = null; } else {
echo '<center><h4>You are not the owner of the paste ' . $row["uid"] . '</h4></center>'; echo '<center><h4>You are not the owner of the paste ' . $pasteInfo["uid"] . '</h4></center>';
echo '<meta http-equiv="refresh" content="2;url=../index.php">'; echo '<meta http-equiv="refresh" content="2;url=../index.php">';
die(); die();
}
} }
} else { } else {
$conn = null; echo '<center><h4>The paste ' . $paste . ' does not exist</h4></center>';
echo '<center><h4>The paste ' . $row["uid"] . ' does not exist</h4></center>';
echo '<meta http-equiv="refresh" content="2;url=../index.php">'; echo '<meta http-equiv="refresh" content="2;url=../index.php">';
} }
$conn = null;
} }
?> ?>
</div> </div>

View File

@ -4,56 +4,60 @@
<?php <?php
include_once "includes/config.php"; include_once "includes/config.php";
include_once "includes/user.php"; include_once "includes/user.php";
$conn = GetConnectionToDB();
include_once "repositories/paste-repository.php";
$pasteRepo = new PasteRepository();
if (GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]) == -1) { if (GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]) == -1) {
printf('<h2>You must be loged in to see your pastes!</h2>'); echo '<h2>You must be logged in to see your pastes!</h2>';
$conn = null;
echo '</div></div></div>'; echo '</div></div></div>';
die(); die();
} }
$stmt = $conn->prepare('SELECT * FROM pastes WHERE owner=:own');
$own = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]); $own = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]);
$stmt->bindParam(':own', $own); $pastes = $pasteRepo->getPastesByOwner($own, true);
$stmt->execute();
if ($stmt->rowCount() > 0) { if (!empty($pastes)) {
echo "<table id=\"tablepastes\" class=\"table table-striped\" style=\"width:100%\">"; echo '<table id="tablepastes" class="table table-striped" style="width:100%">';
printf('<thead><th data-dynatable-column="name" style="text-align: left;">Title</th> echo '<thead><th data-dynatable-column="name" style="text-align: left;">Title</th>
<th style="text-align: left;">Added</th> <th style="text-align: left;">Added</th>
<th style="text-align: left;">Expires</th> <th style="text-align: left;">Expires</th>
<th style="text-align: left;">ID</th> <th style="text-align: left;">ID</th>
<th style="text-align: left;">Actions</th></thead>'); <th style="text-align: left;">Actions</th></thead>';
printf('<tbody>'); echo '<tbody>';
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$title = $row['title']; foreach ($pastes as $row) {
//Paste title $title = htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8');
printf('<tr><td style="text-align: left;">' . htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8') . '</td>'); $created = date('Y-m-d', $row["created"]);
//Creation date
printf('<td style="text-align: left;">' . date('Y-m-d', $row["created"]) . '</td>'); if ($row["expire"] == 0) {
//Expire date $expire = 'Never';
if ($row["expire"] == 0) printf('<td style="text-align: left;">Never</td>'); } else {
else { $expireInSeconds = $row["expire"] - time();
$expire = ($row["expire"] - time()) / 3600; if ($expireInSeconds > 24 * 3600) {
if ($expire > 24) { $expire = round($expireInSeconds / (24 * 3600)) . ' days from now';
printf('<td style="text-align: left;">' . round($expire / 24) . ' days from now</td>'); } elseif ($expireInSeconds >= 3600) {
} else if ($expire >= 1) $expire = round($expireInSeconds / 3600) . ' hours from now';
printf('<td style="text-align: left;">' . round($expire) . ' hours from now</td>'); } else {
else printf('<td style="text-align: left;">' . round($expire * 60) . ' minutes from now</td>'); $expire = round($expireInSeconds / 60) . ' minutes from now';
}
} }
//Paste url
printf('<td style="text-align: right;"><a href="' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '">' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '</a></td>'); echo '<tr>';
//Actions echo '<td style="text-align: left;">' . $title . '</td>';
printf('<td style="text-align: right;">'); echo '<td style="text-align: left;">' . $created . '</td>';
//delete paste echo '<td style="text-align: left;">' . $expire . '</td>';
printf('<a href="delete/' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '"><span class="glyphicon glyphicon-trash" title="Delete paste" aria-hidden="true"></span>'); echo '<td style="text-align: right;"><a href="' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '">' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '</a></td>';
//edit paste echo '<td style="text-align: right;">';
printf('<a href="edit/' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '"><span class="glyphicon glyphicon-edit" title="Edit paste" aria-hidden="true"></span>'); echo '<a href="delete/' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '"><span class="glyphicon glyphicon-trash" title="Delete paste" aria-hidden="true"></span></a>';
printf('</td></tr>'); echo '<a href="edit/' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '"><span class="glyphicon glyphicon-edit" title="Edit paste" aria-hidden="true"></span></a>';
echo '</td></tr>';
} }
printf('</tbody></talbe>');
echo '</tbody></table>';
} else { } else {
printf('<h2>You havent made any pastes yet!</h2>'); echo '<h2>You haven\'t made any pastes yet!</h2>';
} }
$conn = null;
?> ?>
</div> </div>
</div> </div>

View File

@ -4,48 +4,57 @@
<?php <?php
include_once "includes/config.php"; include_once "includes/config.php";
include_once "includes/user.php"; include_once "includes/user.php";
$conn = GetConnectionToDB();
$ownerID = GetUserIDByName($_GET["user"]); include_once "repositories/paste-repository.php";
$pasteRepo = new PasteRepository();
$ownerName = $_GET["user"];
$ownerID = GetUserIDByName($ownerName);
if ($ownerID != -1) { if ($ownerID != -1) {
//== Print user info ==//
$owner = GetUserByID($ownerID); $owner = GetUserByID($ownerID);
printf('<h2>' . $owner["user"] . '\'s profile</h2>'); printf('<h2>' . $owner["user"] . '\'s profile</h2>');
//== Print pastes ==//
$query = "SELECT * FROM pastes WHERE owner=:own AND exposure=0";
if (GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]) == $ownerID) $query = "SELECT * FROM pastes WHERE owner=:own";
$stmt = $conn->prepare($query);
$stmt->bindParam(':own', $ownerID);
$stmt->execute();
if ($stmt->rowCount() > 0) { $pastes = $pasteRepo->getPastesByOwner($ownerID, isset($_COOKIE["pp_sid"]) ? true : false);
if (!empty($pastes)) {
echo "<table id=\"tablepastes\" class=\"table table-striped\" style=\"width:100%\">"; echo "<table id=\"tablepastes\" class=\"table table-striped\" style=\"width:100%\">";
printf('<thead><th data-dynatable-column="name" style="text-align: left;">Title</th> printf('<thead><th data-dynatable-column="name" style="text-align: left;">Title</th>
<th style="text-align: left;">Added</th> <th style="text-align: left;">Added</th>
<th style="text-align: left;">Expires</th> <th style="text-align: left;">Expires</th>
<th style="text-align: left;">ID</th></thead>'); <th style="text-align: left;">ID</th></thead>');
printf('<tbody>'); printf('<tbody>');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$title = $row['title']; foreach ($pastes as $paste) {
printf('<tr><td style="text-align: left;">' . htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8') . '</td>'); $title = $paste['title'];
printf('<td style="text-align: left;">' . date('Y-m-d', $row["created"]) . '</td>'); printf('<tr><td style="text-align: left;">' . htmlspecialchars($paste["title"], ENT_QUOTES, 'UTF-8') . '</td>');
if ($row["expire"] == 0) printf('<td style="text-align: left;">Never</td>'); printf('<td style="text-align: left;">' . date('Y-m-d', $paste["created"]) . '</td>');
else {
$expire = ($row["expire"] - time()) / 3600; if ($paste["expire"] == 0) {
printf('<td style="text-align: left;">Never</td>');
} else {
$expire = ($paste["expire"] - time()) / 3600;
if ($expire > 24) { if ($expire > 24) {
printf('<td style="text-align: left;">' . round($expire / 24) . ' days from now</td>'); printf('<td style="text-align: left;">' . round($expire / 24) . ' days from now</td>');
} else if ($expire >= 1) } else if ($expire >= 1) {
printf('<td style="text-align: left;">' . round($expire) . ' hours from now</td>'); printf('<td style="text-align: left;">' . round($expire) . ' hours from now</td>');
else printf('<td style="text-align: left;">' . round($expire * 60) . ' minutes from now</td>'); } else {
printf('<td style="text-align: left;">' . round($expire * 60) . ' minutes from now</td>');
}
} }
printf('<td style="text-align: right;"><a href="../' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '">' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '</a></td></tr>');
printf('<td style="text-align: right;"><a href="../' . htmlspecialchars($paste["uid"], ENT_QUOTES, 'UTF-8') . '">' . htmlspecialchars($paste["uid"], ENT_QUOTES, 'UTF-8') . '</a></td></tr>');
} }
printf('</tbody></talbe>');
printf('</tbody></table>');
} else { } else {
printf('<h2>This user has no public pastes!</h2>'); printf('<h2>This user has no public pastes!</h2>');
} }
} else printf('<h2>User does not exist!</h2>'); } else {
$conn = null; printf('<h2>User does not exist!</h2>');
}
?> ?>
</div> </div>
</div> </div>

View File

@ -5,47 +5,63 @@
if (isset($uid)) { if (isset($uid)) {
include_once "includes/config.php"; include_once "includes/config.php";
include_once "includes/user.php"; include_once "includes/user.php";
$conn = GetConnectionToDB(); include_once "repositories/paste-repository.php";
$stmt = $conn->query('SELECT * FROM pastes WHERE uid="' . $uid . '"'); $pasteRepo = new PasteRepository();
if ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
$conn = null; $paste = $pasteRepo->readByUid($uid);
if ($result["expire"] != 0 && $result["expire"] < time()) { if ($paste) {
//This paste is expired but not removed if ($paste["expire"] != 0 && $paste["expire"] < time()) {
// This paste is expired but not removed
echo "<h1>This paste just expired</h1>"; echo "<h1>This paste just expired</h1>";
include_once "cronjob.php"; $result = $pasteRepo->removeExpiredPastes();
RemoveExpiredPastes(); if ($result === 'OK! 200') {
echo 'Expired pastes have been removed';
} else {
echo 'Error removing expired pastes';
}
die(); die();
} }
if ($result["exposure"] == 2 && $result["owner"] != 0 && isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]) && $result["owner"] != GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"])) {
if ($paste["exposure"] == 2 && $paste["owner"] != 0 && isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]) && $paste["owner"] != GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"])) {
echo "<h1>This paste is private</h1>"; echo "<h1>This paste is private</h1>";
die(); die();
} }
echo "<h1>" . htmlspecialchars($result["title"], ENT_QUOTES, 'UTF-8') . "</h1>";
// echo "<h1>" . htmlspecialchars($paste["title"], ENT_QUOTES, 'UTF-8') . "</h1>";
$owner = GetUserByID($result["owner"]);
$owner = GetUserByID($paste["owner"]);
echo "<h5>"; echo "<h5>";
if ($owner[1] == -1) if ($owner[1] == -1)
echo "Posted by: <b>Guest</b>"; echo "Posted by: <b>Guest</b>";
else echo "Posted by: <b><a href=\"u/" . htmlspecialchars($owner[1]) . "\">" . htmlspecialchars($owner[1]) . "</a></b>"; else
echo ", at " . date('Y-m-d', $result["created"]) . ", it will expire <b>"; echo "Posted by: <b><a href=\"u/" . htmlspecialchars($owner[1]) . "\">" . htmlspecialchars($owner[1]) . "</a></b>";
if ($result["expire"] == 0) printf('Never'); echo ", at " . date('Y-m-d', $paste["created"]) . ", it will expire <b>";
else { if ($paste["expire"] == 0) {
$expire = ($result["expire"] - time()) / 3600; printf('Never');
} else {
$expire = ($paste["expire"] - time()) / 3600;
if ($expire > 24) { if ($expire > 24) {
printf(round($expire / 24) . ' days from now'); printf(round($expire / 24) . ' days from now');
} else if ($expire >= 1) } elseif ($expire >= 1) {
printf(round($expire) . ' hours from now'); printf(round($expire) . ' hours from now');
else printf(round($expire * 60) . ' minutes from now'); } else {
printf(round($expire * 60) . ' minutes from now');
}
} }
echo "</b></h5>"; echo "</b></h5>";
//
echo "<pre class=\"brush: " . $_HL . "\">"; echo "<pre class=\"brush: " . $_HL . "\">";
echo htmlspecialchars($result["text"], ENT_QUOTES, 'UTF-8') . "</pre><pb>"; echo htmlspecialchars($paste["text"], ENT_QUOTES, 'UTF-8') . "</pre><pb>";
echo "<label for=\"rawtext\">Raw text:</label>"; echo "<label for=\"rawtext\">Raw text:</label>";
echo "<textarea id=\"rawtext\" class=\"form-control\" rows=\"10\">" . htmlspecialchars($result["text"], ENT_QUOTES, 'UTF-8') . "</textarea>"; echo "<textarea id=\"rawtext\" class=\"form-control\" rows=\"10\">" . htmlspecialchars($paste["text"], ENT_QUOTES, 'UTF-8') . "</textarea>";
} else echo "Paste does not exist"; } else {
echo "Paste does not exist";
}
$conn = null; $conn = null;
} else echo "Error: id not set"; } else {
echo "Error: id not set";
}
?> ?>
<script type="text/javascript"> <script type="text/javascript">
SyntaxHighlighter.all() SyntaxHighlighter.all()