last update: Wed, 30 Dec 2009 15:40:52 +0000
  1. <?
  2. require_once("add_smarty.php");
  3. require_once("session.php");
  4. require_once("mysql_cfg.php");
  5. //title
  6. $smarty->assign('title', 'Startseite');
  7. //main template
  8. $smarty->assign('main_template', 'index.tpl');
  9. function strip_markup($s)
  10. {
  11. return str_replace('##', '', str_replace('', '', $s));
  12. }
  13. function get_firtst_line ($_text)
  14. {
  15. $text = $_text;
  16. $regexps = array(
  17. "library" => '/library\s+(\w*)/',
  18. "scope" => '/scope\s+(\w*)/',
  19. "class" => '/class\s+(\w*)/',
  20. "struct" => '/struct\s+(\w*)/',
  21. "function" => '/function\s+(\w*)/',
  22. "method" => '/method\s+(\w*)/'
  23. );
  24. foreach ($regexps as $key => $regexp) {
  25. preg_match($regexp, $text, $treffer);
  26. if ($treffer != null) {
  27. return "$key ".$treffer[1];
  28. }
  29. }
  30. $text = nl2br(trim($_text));
  31. $pos = strpos($text,"<br />");
  32. if ($pos)
  33. {
  34. return strip_markup(substr($text,0, $pos));
  35. }
  36. else
  37. {
  38. return strip_markup($text);
  39. }
  40. }
  41. function make_ago_timer ($_seconds)
  42. {
  43. $seconds =intval($_seconds);
  44. if ($seconds >= (60*60*24) )
  45. {
  46. $i = intval($seconds / (60*60*24));
  47. return ($i > 1) ? "$i Tagen" : "einem Tag";
  48. }
  49. elseif ($seconds >= (60*60) )
  50. {
  51. $i = intval($seconds / (60*60));
  52. return ($i > 1) ? "$i Stunden" : "einer Stunde";
  53. }
  54. elseif ($seconds >= (60) )
  55. {
  56. $i = intval($seconds / (60));
  57. return ($i > 1) ? "$i Minuten" : "einer Minute";
  58. }
  59. else
  60. {
  61. $i = intval($seconds);
  62. return ($i > 1) ? "$i Sekunden" : "einer Sekunde";
  63. }
  64. }
  65. //load latest code
  66. $query = 'SELECT *, UNIX_TIMESTAMP(NOW())- UNIX_TIMESTAMP(datum) as diff_datum FROM mapping_nopaste_jass ORDER BY `id` DESC LIMIT 5;';
  67. $data = mysql_query($query);
  68. echo mysql_error();
  69. $latest_code = array();
  70. $i = 0;
  71. while ($row = mysql_fetch_array($data))
  72. {
  73. $i++;
  74. $latest_code[$i] = array_merge($row, array("short" => htmlspecialchars(get_firtst_line($row['jass_code'])), "ago_time" => make_ago_timer($row['diff_datum'])));
  75. $latest_code[$i]['codetype']= str_replace("+","p",$latest_code[$i]['codetype']);
  76. }
  77. $smarty->assign('latest_code', $latest_code);
  78. //load latest gui
  79. $query = 'SELECT *, UNIX_TIMESTAMP(NOW())- UNIX_TIMESTAMP(datum) as diff_datum FROM mapping_nopaste_gui ORDER BY `id` DESC LIMIT 5;';
  80. $data = mysql_query($query);
  81. echo mysql_error();
  82. $latest_gui = array();
  83. while ($row = mysql_fetch_array($data))
  84. {
  85. $latest_gui[] = array_merge($row, array("short" => htmlspecialchars(get_firtst_line($row['gui_code'])), "ago_time" => make_ago_timer($row['diff_datum'])));
  86. }
  87. $smarty->assign('latest_gui', $latest_gui);
  88. //load comments
  89. require_once("comments.php");
  90. $from = (isset($_GET['from'])) ? intval($_GET['from']) : 0;
  91. $count = (isset($_GET['count'])) ? intval($_GET['count']) : 10;
  92. add_comments(0,$from,$count);
  93. $smarty->assign('draw_comments_form', true);
  94. //we need additional headers to do ajax:
  95. $footer_scripts[] = '<script src="jquery/jquery.js" type="text/javascript"></script>';
  96. //$smarty->assign('additional_headers', $additional_headers);
  97. //we also need additional headers for tinymce editor:
  98. $footer_scripts[] ='<script type="text/javascript" src="tinymce/tiny_mce/tiny_mce_gzip.js"></script>';
  99. $footer_scripts[] ='<script src="comments001.js" type="text/javascript"></script>';
  100. //aus frame raus springen:
  101. $additional_headers[]='<script type="text/javascript">
  102. if (top != self)
  103. top.location = self.location;
  104. </script>';
  105. $smarty->assign('additional_headers', $additional_headers);
  106. $smarty->assign('footer_scripts', $footer_scripts);
  107. //display everything
  108. $smarty->assign("compileTime",sprintf("%.4f",(microtime(true) - $sript_start_time)));
  109. $smarty->display('site.tpl');
  110. ?>

goto:
Vergleichen mit :

Neuen Code Posten


Text-Kopier-Fenster