KXStudio scripts and misc stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
9.2KB

  1. <?php
  2. include_once 'geshi.php';
  3. $server_dir = "/Paste/";
  4. $base_dir = "/home/groups/k/kx/kxstudio/htdocs/paste/";
  5. $show_paste = FALSE;
  6. $is_error = FALSE;
  7. if (!empty($_GET["id"])) {
  8. $paste_id = htmlspecialchars($_GET["id"]);
  9. $show_paste = TRUE;
  10. $paste_file = $base_dir . "repo/" . $paste_id;
  11. if (!file_exists($paste_file)) {
  12. $is_error = TRUE;
  13. }
  14. $paste_info = $base_dir . "repo/" . $paste_id . ".inc";
  15. if (file_exists($paste_info)) {
  16. include_once $paste_info;
  17. } else {
  18. $paste_name = "";
  19. $paste_format = "";
  20. }
  21. } else if (!empty($_POST["paste_text"])) {
  22. $paste_code = $_POST["paste_text"];
  23. $paste_format = $_POST["paste_format"];
  24. $paste_name = $_POST["paste_title"];
  25. $paste_id = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',5)),0,5);
  26. $paste_file = $base_dir . "repo/" . $paste_id;
  27. while (file_exists($paste_file)) {
  28. $paste_id = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',5)),0,5);
  29. $paste_file = $base_dir . "repo/" . $paste_id;
  30. }
  31. $fp = fopen($paste_file, 'w');
  32. if ($fp) {
  33. fwrite($fp, $paste_code);
  34. fclose($fp);
  35. } else {
  36. $paste_file = "_error";
  37. $is_error = TRUE;
  38. }
  39. $paste_info = $base_dir . "repo/" . $paste_id . ".inc";
  40. $paste_info_content = "<?php\n\n";
  41. $paste_info_content .= "\$paste_name = \"$paste_name\";\n";
  42. $paste_info_content .= "\$paste_format = \"$paste_format\";\n";
  43. $paste_info_content .= "?>";
  44. $fp = fopen($paste_info, 'w');
  45. if ($fp) {
  46. fwrite($fp, $paste_info_content);
  47. fclose($fp);
  48. }
  49. $show_paste = TRUE;
  50. header ("Location: " . $server_dir . $paste_id);
  51. }
  52. ?>
  53. <html>
  54. <head>
  55. <?php if (!empty($paste_name)) { ?>
  56. <title>KXStudio Paste - <?php echo $paste_name; ?></title>
  57. <?php } else { ?>
  58. <title>KXStudio Paste</title>
  59. <?php } ?>
  60. <link rel="stylesheet" href="/paste/kxstudio.css" type="text/css" media="screen" />
  61. <style type="text/css">
  62. html, body {
  63. color: white;
  64. }
  65. .paste_textarea_border {
  66. width: 100% - 1px;
  67. height: 300px;
  68. border: 1px solid gray;
  69. }
  70. textarea {
  71. width: 100%;
  72. height: 100%;
  73. margin: 0;
  74. padding: 0;
  75. border-width: 0;
  76. resize: none;
  77. }
  78. </style>
  79. </head>
  80. <body>
  81. <div class="header-tabs">
  82. <ul>
  83. <li><a href="/paste" title="Create new paste">New Paste</a></li>
  84. <?php if ($show_paste && !$is_error) { ?>
  85. <li><a href="/paste/repo/<?php echo $paste_id; ?>" target="blank" title="View RAW">View RAW</a></li>
  86. <li><a href="/paste/download.php?id=<?php echo $paste_id; ?>" title="Download">Download</a></li>
  87. <?php } ?>
  88. </ul>
  89. </div>
  90. <div class="content">
  91. <!-- Begin Content Area -->
  92. <?php if ($show_paste) {
  93. $file_path = $base_dir . "repo/" . $paste_id;
  94. if (file_exists($file_path)) {
  95. if ($is_error) {
  96. $paste_data = file_get_contents($file_path);
  97. } else {
  98. $geshi = new GeSHi(file_get_contents($file_path), $paste_format);
  99. $geshi->enable_classes();
  100. $geshi->set_header_type(GESHI_HEADER_NONE);
  101. $paste_data = $geshi->parse_code();
  102. }
  103. ?>
  104. <p><?php echo $paste_data; ?></p>
  105. <?php } else { ?>
  106. <p style="color: #CF2525; font-size: 20px;">Invalid Paste ID</p><br/>
  107. <?php } ?>
  108. <?php } else { ?>
  109. <form enctype="multipart/form-data" method="post" action="" onsubmit="document.getElementById('paste_submit').disabled=true;document.getElementById('paste_submit').value='Please wait...';">
  110. <div class="paste_textarea_border">
  111. <textarea name="paste_text" id="paste_text"></textarea>
  112. </div>
  113. <br/>
  114. <table>
  115. <tr><td align="right">Syntax Highlighting:</td><td>
  116. <select name="paste_format" id="paste_format">
  117. <option value="none" selected="selected">None</option>
  118. <option value="6502acme">6502 ACME Cross Assembler</option>
  119. <option value="6502kickass">6502 Kick Assembler</option>
  120. <option value="6502tasm">6502 TASM/64TASS</option>
  121. <option value="abap">ABAP</option>
  122. <option value="actionscript">ActionScript</option>
  123. <option value="ada">Ada</option>
  124. <option value="apache">Apache Log</option>
  125. <option value="asm">ASM (NASM)</option>
  126. <option value="asp">ASP</option>
  127. <option value="bash">Bash</option>
  128. <option value="bf">BrainFuck</option>
  129. <option value="c">C</option>
  130. <option value="c_mac">C for Macs</option>
  131. <option value="csharp">C#</option>
  132. <option value="cpp">C++</option>
  133. <option value="caddcl">CAD DCL</option>
  134. <option value="cadlisp">CAD Lisp</option>
  135. <option value="cfdg">CFDG</option>
  136. <option value="klonec">Clone C</option>
  137. <option value="klonecpp">Clone C++</option>
  138. <option value="css">CSS</option>
  139. <option value="d">D</option>
  140. <option value="delphi">Delphi</option>
  141. <option value="diff">Diff</option>
  142. <option value="gdb">GDB</option>
  143. <option value="genero">Genero</option>
  144. <option value="gettext">GetText</option>
  145. <option value="groovy">Groovy</option>
  146. <option value="haskell">Haskell</option>
  147. <option value="html4strict">HTML</option>
  148. <option value="java">Java</option>
  149. <option value="javascript">JavaScript</option>
  150. <option value="jquery">jQuery</option>
  151. <option value="latex">Latex</option>
  152. <option value="lisp">Lisp</option>
  153. <option value="lua">Lua</option>
  154. <option value="matlab">MatLab</option>
  155. <option value="mpasm">MPASM</option>
  156. <option value="mysql">MySQL</option>
  157. <option value="nsis">NullSoft Installer</option>
  158. <option value="objc">Objective C</option>
  159. <option value="oobas">Openoffice BASIC</option>
  160. <option value="oracle8">Oracle 8</option>
  161. <option value="oracle10">Oracle 10</option>
  162. <option value="pascal">Pascal</option>
  163. <option value="perl">Perl</option>
  164. <option value="php">PHP</option>
  165. <option value="povray">POV-Ray</option>
  166. <option value="prolog">Prolog</option>
  167. <option value="providex">ProvideX</option>
  168. <option value="python">Python</option>
  169. <option value="qbasic">QBasic</option>
  170. <option value="reg">REG</option>
  171. <option value="ruby">Ruby</option>
  172. <option value="sas">SAS</option>
  173. <option value="scala">Scala</option>
  174. <option value="scheme">Scheme</option>
  175. <option value="scilab">Scilab</option>
  176. <option value="sdlbasic">SdlBasic</option>
  177. <option value="smalltalk">Smalltalk</option>
  178. <option value="smarty">Smarty</option>
  179. <option value="tcl">TCL</option>
  180. <option value="vbnet">VB.NET</option>
  181. <option value="vb">VisualBasic</option>
  182. <option value="whitespace">WhiteSpace</option>
  183. <option value="xml">XML</option>
  184. <option value="z80">Z80 Assembler</option>
  185. </select>
  186. </td></tr>
  187. <tr><td align="right">Paste Name / Title:</td><td>
  188. <input type="text" name="paste_title" id="paste_title" />
  189. </td></tr>
  190. <tr><td></td><td>
  191. <input type="submit" name="paste_submit" id="paste_submit" value="Submit" />
  192. </td></tr>
  193. </table>
  194. </form>
  195. <?php } ?>
  196. <!-- End Content Area -->
  197. </div>
  198. </body>
  199. </html>