Browse Source

Added website pastebin code

tags/14.04.2
falkTX 11 years ago
parent
commit
62219132a7
6 changed files with 414 additions and 0 deletions
  1. +30
    -0
      pastebin/README
  2. +38
    -0
      pastebin/download.php
  3. +6
    -0
      pastebin/htaccess
  4. +230
    -0
      pastebin/index.php
  5. +109
    -0
      pastebin/kxstudio.css
  6. +1
    -0
      pastebin/repo/_error

+ 30
- 0
pastebin/README View File

@@ -0,0 +1,30 @@
This folder contains the code for KXStudio's Pastebin.

It's shared under the Public Domain.
The full license is available at:
http://creativecommons.org/licenses/publicdomain/


To use it, download GeSHi first, and unpack the geshi folder in here.

The file structure must be like this:
+ geshi/<some-php-files>
- repo/
+ repo/_error
- .htaccess
- download.php
- geshi.php
- index.php
- kxstudio.css

NOTE:
-> htaccess has been renamed as usual
-> repo directory must have r+w permissions (we'll use it to store the files)


To make this work, you'll need to:

edit index/download.php and set $base_dir and $server_dir properly.
edit index.php and set the server root path if needed (ie, href="/paste/kxstudio.css" -> href="/home/http/public_html/paste/kxstudio.css")
^ change everything that starts with '/paste'.


+ 38
- 0
pastebin/download.php View File

@@ -0,0 +1,38 @@
<?php

$base_dir = "/home/groups/k/kx/kxstudio/htdocs/paste/";

function downloadFile($fullPath) {
// Must be fresh start
if(headers_sent())
die('Headers Sent');

// Required for some browsers
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');

$fsize = filesize($fullPath);

header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"".basename($fullPath)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$fsize);
ob_clean();
flush();
readfile($fullPath);
}

if (!empty($_GET["id"])) {
$paste_id = htmlspecialchars($_GET["id"]);
$paste_file = $base_dir . "repo/" . $paste_id;

if (!file_exists($paste_file)) die("File does not exist");

downloadFile($paste_file);
}

?>

+ 6
- 0
pastebin/htaccess View File

@@ -0,0 +1,6 @@
Options -Indexes

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /paste/index.php?id=$1 [L,QSA]

+ 230
- 0
pastebin/index.php View File

@@ -0,0 +1,230 @@
<?php

include_once 'geshi.php';

$server_dir = "/Paste/";
$base_dir = "/home/groups/k/kx/kxstudio/htdocs/paste/";
$show_paste = FALSE;
$is_error = FALSE;

if (!empty($_GET["id"])) {

$paste_id = htmlspecialchars($_GET["id"]);
$show_paste = TRUE;

$paste_file = $base_dir . "repo/" . $paste_id;

if (!file_exists($paste_file)) {
$is_error = TRUE;
}

$paste_info = $base_dir . "repo/" . $paste_id . ".inc";

if (file_exists($paste_info)) {
include_once $paste_info;
} else {
$paste_name = "";
$paste_format = "";
}

} else if (!empty($_POST["paste_text"])) {

$paste_code = $_POST["paste_text"];
$paste_format = $_POST["paste_format"];
$paste_name = $_POST["paste_title"];

$paste_id = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',5)),0,5);
$paste_file = $base_dir . "repo/" . $paste_id;

while (file_exists($paste_file)) {
$paste_id = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',5)),0,5);
$paste_file = $base_dir . "repo/" . $paste_id;
}

$fp = fopen($paste_file, 'w');

if ($fp) {
fwrite($fp, $paste_code);
fclose($fp);
} else {
$paste_file = "_error";
$is_error = TRUE;
}

$paste_info = $base_dir . "repo/" . $paste_id . ".inc";

$paste_info_content = "<?php\n\n";
$paste_info_content .= "\$paste_name = \"$paste_name\";\n";
$paste_info_content .= "\$paste_format = \"$paste_format\";\n";
$paste_info_content .= "?>";

$fp = fopen($paste_info, 'w');

if ($fp) {
fwrite($fp, $paste_info_content);
fclose($fp);
}

$show_paste = TRUE;

header ("Location: " . $server_dir . $paste_id);

}

?>
<html>
<head>
<?php if (!empty($paste_name)) { ?>
<title>KXStudio Paste - <?php echo $paste_name; ?></title>
<?php } else { ?>
<title>KXStudio Paste</title>
<?php } ?>

<link rel="stylesheet" href="/paste/kxstudio.css" type="text/css" media="screen" />

<style type="text/css">
html, body {
color: white;
}
.paste_textarea_border {
width: 100% - 1px;
height: 300px;
border: 1px solid gray;
}
textarea {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border-width: 0;
resize: none;
}
</style>
</head>

<body>
<div class="header-tabs">
<ul>
<li><a href="/paste" title="Create new paste">New Paste</a></li>
<?php if ($show_paste && !$is_error) { ?>
<li><a href="/paste/repo/<?php echo $paste_id; ?>" target="blank" title="View RAW">View RAW</a></li>
<li><a href="/paste/download.php?id=<?php echo $paste_id; ?>" title="Download">Download</a></li>
<?php } ?>
</ul>
</div>

<div class="content">
<!-- Begin Content Area -->
<?php if ($show_paste) {
$file_path = $base_dir . "repo/" . $paste_id;
if (file_exists($file_path)) {
if ($is_error) {
$paste_data = file_get_contents($file_path);
} else {
$geshi = new GeSHi(file_get_contents($file_path), $paste_format);
$geshi->enable_classes();
$geshi->set_header_type(GESHI_HEADER_NONE);
$paste_data = $geshi->parse_code();
}
?>
<p><?php echo $paste_data; ?></p>
<?php } else { ?>
<p style="color: #CF2525; font-size: 20px;">Invalid Paste ID</p><br/>
<?php } ?>
<?php } else { ?>
<form enctype="multipart/form-data" method="post" action="" onsubmit="document.getElementById('paste_submit').disabled=true;document.getElementById('paste_submit').value='Please wait...';">
<div class="paste_textarea_border">
<textarea name="paste_text" id="paste_text"></textarea>
</div>

<br/>

<table>
<tr><td align="right">Syntax Highlighting:</td><td>
<select name="paste_format" id="paste_format">
<option value="none" selected="selected">None</option>
<option value="6502acme">6502 ACME Cross Assembler</option>
<option value="6502kickass">6502 Kick Assembler</option>
<option value="6502tasm">6502 TASM/64TASS</option>
<option value="abap">ABAP</option>
<option value="actionscript">ActionScript</option>
<option value="ada">Ada</option>
<option value="apache">Apache Log</option>
<option value="asm">ASM (NASM)</option>
<option value="asp">ASP</option>
<option value="bash">Bash</option>
<option value="bf">BrainFuck</option>
<option value="c">C</option>
<option value="c_mac">C for Macs</option>
<option value="csharp">C#</option>
<option value="cpp">C++</option>
<option value="caddcl">CAD DCL</option>
<option value="cadlisp">CAD Lisp</option>
<option value="cfdg">CFDG</option>
<option value="klonec">Clone C</option>
<option value="klonecpp">Clone C++</option>
<option value="css">CSS</option>
<option value="d">D</option>
<option value="delphi">Delphi</option>
<option value="diff">Diff</option>
<option value="gdb">GDB</option>
<option value="genero">Genero</option>
<option value="gettext">GetText</option>
<option value="groovy">Groovy</option>
<option value="haskell">Haskell</option>
<option value="html4strict">HTML</option>
<option value="java">Java</option>
<option value="javascript">JavaScript</option>
<option value="jquery">jQuery</option>
<option value="latex">Latex</option>
<option value="lisp">Lisp</option>
<option value="lua">Lua</option>
<option value="matlab">MatLab</option>
<option value="mpasm">MPASM</option>
<option value="mysql">MySQL</option>
<option value="nsis">NullSoft Installer</option>
<option value="objc">Objective C</option>
<option value="oobas">Openoffice BASIC</option>
<option value="oracle8">Oracle 8</option>
<option value="oracle10">Oracle 10</option>
<option value="pascal">Pascal</option>
<option value="perl">Perl</option>
<option value="php">PHP</option>
<option value="povray">POV-Ray</option>
<option value="prolog">Prolog</option>
<option value="providex">ProvideX</option>
<option value="python">Python</option>
<option value="qbasic">QBasic</option>
<option value="reg">REG</option>
<option value="ruby">Ruby</option>
<option value="sas">SAS</option>
<option value="scala">Scala</option>
<option value="scheme">Scheme</option>
<option value="scilab">Scilab</option>
<option value="sdlbasic">SdlBasic</option>
<option value="smalltalk">Smalltalk</option>
<option value="smarty">Smarty</option>
<option value="tcl">TCL</option>n>
<option value="vbnet">VB.NET</option>
<option value="vb">VisualBasic</option>
<option value="whitespace">WhiteSpace</option>
<option value="xml">XML</option>
<option value="z80">Z80 Assembler</option>
</select>
</td></tr>

<tr><td align="right">Paste Name / Title:</td><td>
<input type="text" name="paste_title" id="paste_title">
</td></tr>

<tr><td></td><td>
<input type="submit" name="paste_submit" id="paste_submit" value="Submit">
</td></tr>

</table>
</form>
<?php } ?>
<!-- End Content Area -->
</div>
</body>
</html>

+ 109
- 0
pastebin/kxstudio.css View File

@@ -0,0 +1,109 @@
/*
* GeSHi CSS Inspired by TextMate
* Theme KXStudio
*
* Copyright 2008 Mark Story
* Copyright 2011 Filipe Coelho
*
* This work is licensed under the Creative Commons Attribution-Share Alike 2.5 Canada License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.5/ca/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA
*
* @filesource
* @copyright Copyright 2008, Mark Story.
* @link http://mark-story.com
* @license http://creativecommons.org/licenses/by-sa/2.5/ca/
*
* This file has been modified by Filipe Coelho (aka 'falkTX'), to match KXStudio's theme
*/

/*
* Global geshi styles
**********************/
#main pre {
line-height: 1.5em;
font-size: 10px;
white-space: normal;
padding: 0;
border: 1px solid;
}
pre ol {
list-style: decimal;
list-style-position: outside;
padding: 0;
margin: 0;
}
#main pre ol li {
margin: 0 0 0 35px;
padding: 0;
color: rgb(240,240,240);
clear: none;
}
pre ol li div {
color: rgb(240,240,240);
}

/* comments */
.co0, .co1,
.coMULTI {
color: rgb(100,100,100);
}

/* brackets */
.br0 {
color: rgb(230,230,230);
}

/* strings */
.st0, .st_h {
color: rgb(230,100,100);
}

/* keywords */
.kw1 {
color: rgb(240,240,240);
font-weight: 700;
}
.kw2 {
color: rgb(100,230,100);
}

.kw3 {
color: rgb(100,100,230);
}

/* numbers */
.nu0 {
color: rgb(230,230,100);
}

/* vars */
.re0, .re1, .re2 {
color: rgb(100,230,100);
}

/*
* CSS selectors
*****************/
/* classnames */
[lang=css] .kw2,
.css .kw2 {
color: rgb(240,240,240);
font-weight: 700;
}
.re1 {
color: rgb(240,240,240);
font-weight: 700;
}
/* css px */
.re3 {
color: rgb(230,230,100);
}

/*
* Javascript
****************/
[lang=javascript] .me1,
.javascript .me1 {
color: rgb(100,100,230);
}

+ 1
- 0
pastebin/repo/_error View File

@@ -0,0 +1 @@
<p style="color: #CF2525; font-size: 20px;">Failed to create new Paste</p>

Loading…
Cancel
Save