last update: Sat, 15 Mar 2014 12:07:52 +0000
  1. <?
  2. /*
  3. CREATE TABLE `languages` (
  4. `id` INT NOT NULL ,
  5. `name` VARCHAR( 200 ) NOT NULL ,
  6. `owner` INT DEFAULT '0' NOT NULL ,
  7. `data` LONGTEXT NOT NULL
  8. ) TYPE = innodb;
  9. CREATE TABLE `styles` (
  10. `id` INT NOT NULL ,
  11. `name` VARCHAR( 200 ) NOT NULL ,
  12. `owner` INT NOT NULL ,
  13. `data` LONGTEXT NOT NULL ,
  14. `hidden` BOOL DEFAULT '1' NOT NULL ,
  15. `public` BOOL DEFAULT '0' NOT NULL ,
  16. PRIMARY KEY ( `id` )
  17. ) TYPE = innodb;
  18. */
  19. /*require_once('enable_gzip.php');*/
  20. require( './common.php' );
  21. require_once('code_css.php');
  22. require_once('codetitles.php');
  23. //main template
  24. $smarty->assign('main_template', 'code.tpl');
  25. //title
  26. $pageTitle = "Code";
  27. //set default = nothing
  28. $smarty->assign('html_code', false);
  29. $smarty->assign('id', false);
  30. $additional_headers = array();
  31. $editor_languages = array
  32. (
  33. "jass" => "jass",
  34. "pascal" => "pas",
  35. "delphi" => "pas",
  36. "java" => "js"
  37. );
  38. $editor_start_lang = "jass";
  39. if ((isset($_GET['l'])) && (isset($editor_languages[$_GET['l']])))
  40. {
  41. $pageTitle = htmlspecialchars($_GET['l']).'-Code posten';
  42. $editor_start_lang = $editor_languages[$_GET['l']];
  43. }
  44. $editor_lang_change_script = '';
  45. foreach ($editor_languages as $key => $val)
  46. {
  47. if ($editor_lang_change_script != '')
  48. $editor_lang_change_script.="\nelse";
  49. $editor_lang_change_script.='
  50. if (o.value == "'.$key.'")
  51. {
  52. editAreaLoader.execCommand("code", "change_syntax", "'.$val.'");
  53. }
  54. ';
  55. }
  56. function checkKey($key) {
  57. if (!preg_match("/^[a-zA-Z0-9\._]*$/", $key)) {
  58. die('invalid key');
  59. }
  60. }
  61. function escape_string($s)
  62. {
  63. return str_replace('"', '\"', $s);
  64. }
  65. function unescape_string($s)
  66. {
  67. //return $s;
  68. return stripslashes($s);
  69. //return str_replace('\"', '"', $s);
  70. }
  71. function fill_line_array($s)
  72. {
  73. return explode("\n",$s);
  74. }
  75. function strip_markup($s)
  76. {
  77. return str_replace('##', '', str_replace('', '', $s));
  78. }
  79. require_once("codehighlighter.php");
  80. require_once('SmartTextProcessor.class.php');
  81. if (isset($_POST['code']))
  82. {
  83. $query = 'SELECT `id` as x FROM `mapping_nopaste_jass` ORDER BY `id` DESC;';
  84. $count = mysql_fetch_array(mysql_query($query, $mysqlconnection));
  85. $id = $count['x'] + 1;
  86. $code_type = mysql_real_escape_string($_POST['lang']);
  87. //remember to check this value later
  88. //check value
  89. $query = 'SELECT name FROM languages WHERE `name` = "'.$code_type.'";';
  90. $row = mysql_fetch_array(mysql_query($query));
  91. if (isset($row['name']) && ($row['name'] != $code_type))
  92. {
  93. die('unbekannte Sprache.');
  94. }
  95. $code = unescape_string($_POST['code']);
  96. $code = str_replace("<", "<", $code);
  97. $code = str_replace(">", ">", $code);
  98. //check if code is empty:
  99. if (strlen(trim($code)) < 5) {
  100. die('Spam verdacht: Code muss mindestends 5 Zeichen lang sein.');
  101. }
  102. //check if code contains url:
  103. if (strpos($code, "http://") !== false) {
  104. if (session_get_userid_secure() <= 0) {
  105. die('Um Spam zu vermeiden dürfen Posts, die Internet-Addressen enthalten nur von angemeldeten Benutzern erstellt werden.');
  106. }
  107. }
  108. /*
  109. include('language_data_jass.php');
  110. $ld = new languagedata();
  111. $ld->load_array($language_data);
  112. include('style_data_html.php');
  113. $hs = new highlightstyle();
  114. $hs->load_array($style_data);
  115. $code_lines = fill_line_array($code);
  116. $ch = new codehighlighter($code_lines);
  117. $output = $ch->parse_code($ld, $hs);
  118. */
  119. $key = "";
  120. if ($_POST['hidden']) {
  121. $key = uniqid("", true);
  122. }
  123. $query = 'INSERT INTO
  124. `mapping_nopaste_jass` (`id`, `jass_code`, `datum`, `userid`, `codetype`, `key` )
  125. VALUES ("'.$id.'", "'.mysql_real_escape_string($code).'", NOW(), "'.session_get_userid_secure().'", "'.$code_type.'", "'.$key.'")
  126. ';
  127. $temp = mysql_query($query, $mysqlconnection);
  128. echo mysql_error();
  129. /*
  130. $smarty->assign('output', $output);
  131. $smarty->assign('jass_code', strip_markup($code));
  132. */
  133. $keystring= $key ? "&key=".$key :"";
  134. if ($id == 1000)
  135. {
  136. $additional_headers[] ='<script>document.location="code.php?id='.$id.'&showpic=1";</script>';
  137. }
  138. else
  139. {
  140. $additional_headers[] ='<script>document.location="code.php?id='.$id.$keystring.'";</script>';
  141. }
  142. $smarty->assign('id', $id);
  143. }
  144. elseif (isset($_GET['id']))
  145. {
  146. $additional_headers[] = '<script type="text/javascript" src="codehandling.js"></script>';
  147. $id = intval($_GET['id']);
  148. $language_id = (isset($_GET['language'])) ? intval($_GET['language']) : 0;
  149. $style_id = (isset($_GET['style'])) ? intval($_GET['style']) : 0;
  150. $format_output = (isset($_GET['f'])) ? intval($_GET['f']) : false;
  151. $key = (isset($_GET['key'])) ? $_GET['key'] : "";
  152. checkKey($key);
  153. $query = 'SELECT * FROM `mapping_nopaste_jass` WHERE `id` LIKE "'.$id.'";';
  154. $data = mysql_query($query, $mysqlconnection);
  155. echo mysql_error();
  156. $row = mysql_fetch_array($data);
  157. if ($key != $row['key']) {
  158. die('Dieser Code ist durch ein Passwort geschützt. Bitte prüfe deinen Link.');
  159. }
  160. $code = $row['jass_code'] ;
  161. $default_lang = $row['codetype'];
  162. $ech = null; //new easycodehighlighter($code, $default_lang, $language_id, $style_id, $format_output);
  163. if ($language_id == 11 || $language_id == 0 && $default_lang == 'Markdown') {
  164. $ech = new SmartTextProcessor($code);
  165. } else {
  166. $ech = new easycodehighlighter($code, $default_lang, $language_id, $style_id, $format_output);
  167. }
  168. if ($ech->format_script == null)
  169. {
  170. $smarty->assign('format_script', 0);
  171. }
  172. else
  173. {
  174. $smarty->assign('format_script', (($format_output) ? 2 : 1));
  175. }
  176. $smarty->assign('language_id', $ech->language_id);
  177. $smarty->assign('style_id', $ech->style_id);
  178. $smarty->assign('output', $ech->output);
  179. $smarty->assign('jass_code', strip_markup($ech->code));
  180. $additional_headers[] = $ech->code_css;
  181. $smarty->assign('id', $id);
  182. /*
  183. $output_lines = '';
  184. $language = false;
  185. if (isset($_GET['language']))
  186. {
  187. $language_id = intval($_GET['language']);
  188. $query = 'SELECT data, defaultstyle, `id`, `name` FROM languages WHERE `id` = "'.$language_id.'";';
  189. $language = mysql_fetch_array(mysql_query($query));
  190. }
  191. if (!$language)
  192. {
  193. $query = 'SELECT data, defaultstyle, `id`, `name` FROM languages WHERE `name` = "'.$row['codetype'].'";';
  194. $language = mysql_fetch_array(mysql_query($query));
  195. }
  196. if ($language)
  197. {
  198. $format_script = 'format_'.$language['name'].'.php';
  199. if (file_exists($format_script) != '')
  200. {
  201. if (isset($_GET['f']))
  202. {
  203. require_once('format_'.$language['name'].'.php');
  204. //$my_jass_formater = new jass_formater();
  205. eval('$my_formater = new '.$language['name'].'_formater();');
  206. $code = $my_formater->format(strip_markup($code),true,true);
  207. $smarty->assign('format_script', 2);
  208. }
  209. else
  210. {
  211. $smarty->assign('format_script', 1);
  212. }
  213. }
  214. else
  215. {
  216. $smarty->assign('format_script', 0);
  217. }
  218. $code_lines = fill_line_array($code);
  219. $smarty->assign('language_id', $language['id']);
  220. eval('$language_data = array('.$language['data'].');');
  221. $ld = new languagedata();
  222. $ld->load_array($language_data);
  223. //$ld->debug_print();
  224. $style_id = 0;
  225. $cssdata = null;
  226. if (isset($_GET['style']))
  227. {
  228. $style_id = intval($_GET['style']);
  229. $query = 'SELECT data, cssdata FROM styles WHERE `id` = "'.$style_id.'";';
  230. $style = mysql_fetch_array(mysql_query($query));
  231. if (!$style)
  232. {
  233. $style_id = 0;
  234. }
  235. $cssdata = $style['cssdata'];
  236. $style = $style['data'];
  237. }
  238. if ($style_id == 0)
  239. {
  240. //load default value of language
  241. $style_id = $language['defaultstyle'];
  242. $query = 'SELECT data, cssdata FROM styles WHERE `id` = "'.$style_id.'";';
  243. $style = mysql_fetch_array(mysql_query($query));
  244. $cssdata = $style['cssdata'];
  245. $style = $style['data'];
  246. }
  247. //echo "<pre>".code_css($cssdata)."</pre>";
  248. $additional_headers[] = code_css($cssdata);
  249. $smarty->assign('style_id', $style_id);
  250. eval('$style_data = array('.$style.');');
  251. $hs = new highlightstyle();
  252. $hs->load_array($style_data);
  253. $ch = new codehighlighter($code_lines);
  254. $output = $ch->parse_code($ld, $hs);
  255. }
  256. else
  257. { //no language definend
  258. $code_lines = fill_line_array($code);
  259. $output='<textarea>';
  260. for($i=0;$i<sizeof($code_lines);$i++)
  261. {
  262. $output_lines[$i] = "".$code_lines[$i]."\n";
  263. }
  264. $output='</textarea>';
  265. }
  266. */
  267. $language_name = "X";
  268. //load languages
  269. $query = 'SELECT `id`, name FROM languages;';
  270. $data = mysql_query($query);
  271. $languages = array();
  272. while ($row = mysql_fetch_array($data))
  273. {
  274. $languages[] = array("id" => $row['id'],"name" => $row['name']);
  275. if ($row['id'] == $ech->language_id)
  276. $language_name = $row['name'];
  277. }
  278. $smarty->assign('languages', $languages);
  279. $smarty->assign('language_name', $language_name);
  280. //load styles
  281. $query = 'SELECT `id`, name FROM styles;';
  282. $data = mysql_query($query);
  283. $styles = array();
  284. while ($row = mysql_fetch_array($data))
  285. {
  286. $styles[] = array("id" => $row['id'],"name" => $row['name']);
  287. }
  288. $smarty->assign('styles', $styles);
  289. if ($key) {
  290. $smarty->assign('keyString', "&key=$key");
  291. }
  292. $pageTitle = $language_name.'-Code #'.$id.' '.getCodeTitle($code);
  293. }
  294. else
  295. {
  296. if (isset($_GET['copy'])) {
  297. $copyId = intval($_GET['copy']);
  298. $query = 'SELECT * FROM `mapping_nopaste_jass` WHERE `id` LIKE "'.$copyId.'";';
  299. $data = mysql_query($query, $mysqlconnection);
  300. echo mysql_error();
  301. $row = mysql_fetch_array($data);
  302. $key = (isset($_GET['key'])) ? $_GET['key'] : "";
  303. if ($key != $row['key']) {
  304. die('Dieser Code ist durch ein Passwort geschützt. Bitte prüfe deinen Link.');
  305. }
  306. $smarty->assign('code', strip_markup($row['jass_code']));
  307. }
  308. //load editor
  309. $additional_headers[] =
  310. '<script language="Javascript" type="text/javascript">
  311. //<!--
  312. function init_editarea()
  313. {
  314. //initialisation
  315. editAreaLoader.init({
  316. id: "code" // id of the textarea to transform
  317. ,start_highlight: "true" // if start with highlight
  318. ,allow_resize: "both"
  319. ,allow_toggle: true
  320. ,language: "de"
  321. ,syntax: "'.$editor_start_lang.'"
  322. ,display: "later"
  323. ,replace_tab_by_spaces: "false"
  324. ,toolbar: "search, go_to_line, |, undo, redo, |, select_font, |, change_smooth_selection, highlight, reset_highlight, |, help"
  325. ,syntax_selection_allow: "jass,css,html,js,php,python,vb,xml,c,cpp,basic,pas,brainfuck"
  326. });
  327. //alert("done");
  328. }
  329. function onSyntaxChange(o)
  330. {
  331. '.$editor_lang_change_script.
  332. /*if (o.value == "jass")
  333. {
  334. //alert(o.value);
  335. editAreaLoader.execCommand("code", "change_syntax", "jass");
  336. //alert("done");
  337. }
  338. else if (o.value == "pascal")
  339. {
  340. editAreaLoader.execCommand("code", "change_syntax", "pas");
  341. }
  342. else if (o.value == "delphi")
  343. {
  344. editAreaLoader.execCommand("code", "change_syntax", "pas");
  345. }
  346. else if (o.value == "java")
  347. {
  348. editAreaLoader.execCommand("code", "change_syntax", "js");
  349. }*/
  350. '
  351. }
  352. //Drop-Down lists:
  353. startList = function()
  354. {
  355. if (document.all && document.getElementById)
  356. {
  357. cssdropdownRoot = document.getElementById("cssdropdown");
  358. for (x=0; x<cssdropdownRoot.childNodes.length; x++)
  359. {
  360. node = cssdropdownRoot.childNodes[x];
  361. if (node.nodeName=="LI")
  362. {
  363. node.onmouseover=function()
  364. {
  365. this.className+=" over";
  366. }
  367. node.onmouseout=function()
  368. {
  369. this.className=this.className.replace(" over", "");
  370. }
  371. }
  372. }
  373. }
  374. }
  375. if (window.attachEvent)
  376. window.attachEvent("onload", startList)
  377. else
  378. window.onload=startList;
  379. //-->
  380. </script>';
  381. $additional_headers[] = '<script language="Javascript" type="text/javascript" src="./editarea/edit_area/edit_area_full.js"></script>';
  382. $smarty->assign('addtional_onloads', array("init_editarea()"));
  383. $query = 'SELECT name FROM languages;';
  384. $data = mysql_query($query);
  385. $languages = array();
  386. while ($row = mysql_fetch_array($data))
  387. {
  388. $languages[] = $row['name'];
  389. }
  390. $smarty->assign('languages', $languages);
  391. }
  392. $smarty->assign('additional_headers', $additional_headers);
  393. $smarty->assign("compileTime",sprintf("%.4f",(microtime(true) - $sript_start_time)));
  394. $GLOBALS['USE_PEEEQ_STYLE'] = true;
  395. $GLOBALS['NO_HEADER_IMAGE'] = true;
  396. $GLOBALS['additional_headers'] = $additional_headers;
  397. finish($smarty, "code.tpl", $additional_headers);

goto line:
Compare with:
text copy window edit this code post new code