Guest User

WBB 1.2 _functions.php

a guest
Apr 11th, 2017
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 66.65 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5.  
  6. /**
  7. * @return result bool
  8. * @param varname string
  9. * @desc Registriert die Variable ${$varname} in einer Session.
  10. * Dank einem Bug in php4 sind wir gezwungen, je nach Konfiguration session_register()
  11. * oder $HTTP_SESSION_VARS/$_SESSION zu verwenden.
  12. */
  13. function wbb_session_register($varname)
  14. {
  15.     global $register_globals, $HTTP_SESSION_VARS, ${$varname};
  16.     $done = false;
  17.     if($register_globals)
  18.     {
  19.         $done = session_register("$varname");
  20.     }
  21.     else
  22.     {
  23.         if($HTTP_SESSION_VARS[$varname] = ${$varname}) $done=true;
  24.         if($_SESSION[$varname] =${$varname}) $done=true;
  25.     }
  26.     return $done;
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. /**
  36. * @return result bool
  37. * @param varname string
  38. * @desc Löscht die Variable ${$varname} aus einer Session.
  39. * Dank einem Bug in php4 sind wir gezwungen, je nach Konfiguration session_unregister()
  40. * oder $HTTP_SESSION_VARS/$_SESSION zu verwenden.
  41. */
  42. function wbb_session_unregister($varname)
  43. {
  44.     global $register_globals, $HTTP_SESSION_VARS, ${$varname};
  45.     $done = false;
  46.     if($register_globals)
  47.     {
  48.         $done = session_unregister("$varname");
  49.     }
  50.     else
  51.     {
  52.         unset($HTTP_SESSION_VARS[$varname]);
  53.         unset($_SESSION[$varname]);
  54.         $done=true;
  55.     }
  56.     return $done;
  57. }
  58.  
  59.  
  60.  
  61.  
  62. /**
  63. * @return out string
  64. * @param boardid int
  65. * @param depth=1 int
  66. * @desc Diese Funktion erstellt eine <option> Liste aller Boards.
  67. * Die Struktur wird dabei rekursiv erstellt..
  68. */
  69. function makeboardjumpbit2($bid,$depth=1) {
  70.     global $boardcache, $boardid, $permissioncache;
  71.  
  72.     if(!isset($boardcache[$bid])) {
  73.         return;
  74.     }
  75.     $out = "";
  76.     while (list($key1,$val1) = each($boardcache[$bid])) {
  77.             while(list($key2,$boards) = each($val1)) {
  78.             if($boards['invisible'] && !$permissioncache[$boards['boardid']]) continue;
  79.             $out .= "<OPTION value=\"".$boards['boardid']."\"";
  80.             if($boardid == $boards['boardid']) $out .= " selected";
  81.             if($depth>1) $out .= ">".str_repeat("--",$depth-1)." ".$boards['boardname']."</option>";
  82.             else $out .= ">".$boards['boardname']."</option>";
  83.             $out.=makeboardjumpbit2($boards['boardid'],$depth+1);
  84.             }
  85.     }
  86.     unset($boardcache[$bid]);
  87.     return $out;
  88. }
  89.  
  90.  
  91. /**
  92. * @return out string
  93. * @param boardid int
  94. * @param depth=1 int
  95. * @desc Diese Funktion erstellt eine <option> Liste speziell für die Forenauswahl in der Suche.
  96. * Die Stuktur wird auch hier rekursiv erstellt.
  97. */
  98. function makeboardsearchbit($bid,$depth=1) {
  99.     global $boardcache, $permissioncache;
  100.  
  101.     if ( !isset($boardcache[$bid]) ) {
  102.         return;
  103.     }
  104.  
  105.     if(!isset($out)) $out="";
  106.     while ( list($key1,$val1)=each($boardcache[$bid]) ) {
  107.         while ( list($key2,$boards)=each($val1) ) {
  108.             if($boards['invisible'] && !$permissioncache[$boards['boardid']]) continue;
  109.             $out .= "<OPTION value=\"+".$boards['boardid']."\"";
  110.             if($depth>1) $out .= ">".str_repeat("--",$depth-1)." ".$boards['boardname']."</option>";
  111.             else $out .= ">".$boards['boardname']."</option>";
  112.             $out.=makeboardsearchbit($boards['boardid'],$depth+1);
  113.         }
  114.     }
  115.     unset($boardcache[$bid]);
  116.     return $out;
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123. /**
  124.  * @return void
  125.  * @desc Diese Funktion füllt die Arrays $_REQUEST $_POST $_GET $_COOKIE usw.
  126.  * mit den Daten aus dem equivalenten Arrays aus PHP Versionen vor 4.10
  127.  */
  128. function get_vars_old()
  129. {
  130.     global $HTTP_COOKIE_VARS, $HTTP_POST_FILES, $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_SERVER_VARS,$HTTP_ENV_VARS, $HTTP_SESSION_VARS, $_REQUEST, $_COOKIE, $_POST, $_GET, $_SERVER, $_FILES,$_ENV,$_SESSION;
  131.    
  132.     if(is_array($HTTP_COOKIE_VARS))
  133.     {
  134.         while(list($key,$val)=each($HTTP_COOKIE_VARS))
  135.         {
  136.             $_REQUEST[$key]=$val;
  137.             $_COOKIE[$key]=$val;
  138.         }
  139.     }
  140.  
  141.     if(is_array($HTTP_POST_VARS))
  142.     {
  143.         while(list($key,$val)=each($HTTP_POST_VARS))
  144.         {
  145.             $_REQUEST[$key]=$val;
  146.             $_POST[$key]=$val;
  147.         }
  148.     }
  149.  
  150.     if(is_array($HTTP_GET_VARS))
  151.     {
  152.         while(list($key,$val)=each($HTTP_GET_VARS))
  153.         {
  154.             $_REQUEST[$key]=$val;
  155.             $_GET[$key]=$val;
  156.         }
  157.     }
  158.    
  159.     if(is_array($HTTP_POST_FILES))
  160.     {
  161.         while(list($key,$val)=each($HTTP_POST_FILES)){
  162.             $_FILES[$key]=$val;
  163.         }
  164.     }
  165.    
  166.     if(is_array($HTTP_SERVER_VARS))
  167.     {
  168.         while(list($key,$val)=each($HTTP_SERVER_VARS))
  169.         {
  170.             $_SERVER[$key]=$val;
  171.         }
  172.     }
  173.    
  174.     if(is_array($HTTP_ENV_VARS))
  175.     {
  176.         while(list($key,$val)=each($HTTP_ENV_VARS))
  177.         {
  178.             $_ENV[$key]=$val;
  179.         }
  180.     }
  181.    
  182.     if(is_array($HTTP_SESSION_VARS))
  183.     {
  184.         while(list($key,$val)=each($HTTP_SESSION_VARS))
  185.         {
  186.             $_SESSION[$key]=$val;
  187.         }
  188.     }
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. /**
  199.  * @return array array
  200.  * @param array array
  201.  * @desc Diese Funktion wendet die Funktion stripslashes()
  202.  * auf alle Elemente eines Arrays (auch mehrdimensional) an.
  203.  */
  204. function stripslashes_array(&$array)
  205. {
  206.     reset($array);
  207.     while(list($key,$val)=each($array))
  208.     {
  209.         if(is_string($val))
  210.         {
  211.             $array[$key]=stripslashes($val);
  212.         }
  213.         elseif(is_array($val))
  214.         {
  215.             /* rekursiver Aufruf bei mehrdimensionalem Array */
  216.             $array[$key]=stripslashes_array($val);
  217.         }
  218.     }
  219.     return $array;
  220. }
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227. /**
  228. * @return array array
  229. * @param array array
  230. * @desc Diese Funktion wendet die Funktion htmlspecialchars()
  231. * auf alle Elemente eines Arrays (auch mehrdimensional) an.
  232. */
  233. function htmlspecialchars_array(&$array)
  234. {
  235.     reset($array);
  236.     while(list($key,$val)=each($array))
  237.     {
  238.         if(is_string($val))
  239.         {
  240.             $array[$key]=htmlspecialchars($val);
  241.         }
  242.         elseif(is_array($val))
  243.         {
  244.             /* rekursiver Aufruf bei mehrdimensionalem Array */
  245.             $array[$key]=htmlspecialchars_array($val);
  246.         }
  247.     }
  248.     return $array;
  249. }
  250.  
  251.  
  252.  
  253.  
  254. /**
  255. * @return text string
  256. * @param text string
  257. * @desc rehtmlspecialchars() macht die Funktin htmlspecialchars() rückgängig.
  258. */
  259. function rehtmlspecialchars($text) {
  260.  $text = str_replace("&lt;","<",$text);
  261.  $text = str_replace("&gt;",">",$text);
  262.  $text = str_replace("&quot;","\"",$text);
  263.  $text = str_replace("&amp;","&",$text);
  264.  return $text;
  265. }
  266.  
  267.  
  268. # -------- user funktionen
  269.  
  270. /**
  271. * @return username string
  272. * @param userid int
  273. * @desc getUserid() ermittelt die Userid anhand des Benutzernamen
  274. */
  275. function getUserid($usernick) {
  276.         global $n,$db_zugriff;
  277.         $result = $db_zugriff->query_first("SELECT userid FROM bb".$n."_user_table WHERE username='".addslashes($usernick)."'");
  278.         return $result['userid'];
  279. }
  280.  
  281.  
  282.  
  283.  
  284. /**
  285. * @return userid int
  286. * @param username string
  287. * @desc getUsername() ermittelt den usernamen anhand der userid
  288. */
  289. function getUsername($userid) {
  290.         global $n,$db_zugriff;
  291.         $result = $db_zugriff->query_first("SELECT username FROM bb".$n."_user_table WHERE userid='$userid'");
  292.         return ($result['username']);
  293. }
  294.  
  295.  
  296.  
  297. /**
  298. * @return userid int
  299. * @param email string
  300. * @desc getUserEmail() ermittelt die eMail Adresse anhand der userid
  301. */
  302. function getUserEmail($userid) {
  303.         global $n,$db_zugriff;
  304.         $result = $db_zugriff->query_first("SELECT useremail FROM bb".$n."_user_table WHERE userid='$userid'");
  305.         return $result['useremail'];
  306. }
  307.  
  308.  
  309.  
  310. /**
  311. * @return count int
  312. * @param userid int
  313. * @param password string
  314. * @desc check_userdata() prüft, ob userid und passwort richtig sind.
  315. * Der Rückgabewert ist 0, wenn das passwort nicht stimmt und größer 0,
  316. * wenn die Daten korrekt sind.
  317. */
  318. function check_userdata($userid,$password) {
  319.     global $n, $db_zugriff;
  320.         $result = $db_zugriff->query_first("SELECT COUNT(userid) FROM bb".$n."_user_table WHERE userid='$userid' AND userpassword = '".addslashes($password)."' AND activation = 1");
  321.     return $result[0];        
  322. }
  323.  
  324.  
  325.  
  326. /**
  327. * @return check string
  328. * @param username string
  329. * @param password string
  330. * @desc checkUser() prüft die kombination von benutzername und passwort.
  331. * der Rückgabewert ist 0, wenn der Benutzer nicht existiert und 2, wenn
  332. * die Daten korrekt sind und 1, wenn das Passwort falsch ist.
  333. */
  334. function checkUser($username,$password) {
  335.         global $n,$db_zugriff;
  336.         $result = $db_zugriff->query_first("SELECT userpassword FROM bb".$n."_user_table WHERE username='".addslashes($username)."' && activation='1'");
  337.         if(!$result['userpassword']) return 0;
  338.         elseif($result['userpassword']==$password) return 2;
  339.         else return 1;
  340. }
  341.  
  342.  
  343. /**
  344. * @return password string
  345. * @param userid int
  346. * @desc getUserPW() gibt das verschlüsselte Passwort des Benutzers zurück.
  347. */
  348. function getUserPW($userid) {
  349.         global $n,$db_zugriff;
  350.         $result = $db_zugriff->query_first("SELECT userpassword FROM bb".$n."_user_table WHERE userid='$userid'");
  351.         return $result['userpassword'];
  352. }
  353.  
  354.  
  355. /**
  356. * @return rank string
  357. * @param posts int
  358. * @param groupid int
  359. * @desc Diese Funktion ermittelt den Benutzerrang anhand der Beitragszahl und der Benutzergruppe.
  360. */
  361. function getUserrang($posts,$groupid) {
  362.         global $n,$db_zugriff;
  363.         $rank = $db_zugriff->query_first("SELECT rank FROM bb".$n."_ranks WHERE groupid = $groupid AND posts<='$posts' ORDER by posts DESC");
  364.         return $rank['rank'];
  365. }
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374. # -------- beitrags erstellung
  375.  
  376. /**
  377. * @return valid int
  378. * @param text string
  379. * @desc Diese Funktion überprüft die IMG Tags in einem Beitrag.
  380. * Wird die maximale Zahl an Bildern überschritten oder taucht eine
  381. * unerlaubte Dateiendung auf oder kommt javascript:, vbscript: oder about:
  382. * vor, so wird 1 (ungültig) zurückgegeben. Andernfalls 0 (gültig).
  383. */
  384. function check_posts($text)
  385. {
  386.     global $image, $image_ext, $maximage;
  387.     $extension_array = @explode("\r\n",trim(strtolower($image_ext)));
  388.     $count=0;
  389.     if(preg_match("/\[img].*(javascript:|vbscript:|about:).*\[\/img\]/siU",$text))
  390.     {
  391.         return 1;
  392.     }
  393.     else
  394.     {
  395.         do
  396.         {
  397.             $extension="";
  398.             preg_match("/\[img]([^\"]*)\[\/img\]/siU",$text,$exp);
  399.             if(!isset($exp[0])) $exp[0]="";
  400.             if(!$exp[0]) break;
  401.             $text = str_replace($exp[0],"",$text);
  402.             $extension = strtolower(substr(strrchr($exp[1],"."),1));
  403.             if(!in_array($extension, $extension_array))
  404.             {
  405.                 return 1;
  406.                 break;
  407.             }
  408.             $count++;
  409.         } while($exp[0]!="" && $count<=$maximage);
  410.  
  411.         if($count>$maximage) return 1; 
  412.     }
  413. }
  414.  
  415. /**
  416. * @return valid int
  417. * @param text string
  418. * @desc Diese Funktion überprüft die IMG Tags in einem Beitrag.
  419. * Wird die maximale Zahl an Bildern überschritten oder taucht eine
  420. * unerlaubte Dateiendung auf oder kommt javascript:, vbscript: oder about:
  421. * vor, so wird 1 (ungültig) zurückgegeben. Andernfalls 0 (gültig).
  422. */
  423. function check_signature($text)
  424. {
  425.     global $image, $image_ext, $maximage;
  426.     $extension_array = @explode("\r\n",trim(strtolower($image_ext)));
  427.     $count=0;
  428.     if(preg_match("/\[img].*(javascript:|vbscript:|about:).*\[\/img\]/siU",$text))
  429.     {
  430.         return 1;
  431.     }
  432.     else
  433.     {
  434.         do
  435.         {
  436.             $extension="";
  437.             preg_match("/\[img]([^\"]*)\[\/img\]/siU",$text,$exp);
  438.             if(!isset($exp[0])) $exp[0]="";
  439.             if(!$exp[0]) break;
  440.             $text = str_replace($exp[0],"",$text);
  441.             $extension = strtolower(substr(strrchr($exp[1],"."),1));
  442.             if(!in_array($extension, $extension_array))
  443.             {
  444.                 return 1;
  445.                 break;
  446.             }
  447.             $count++;
  448.         } while($exp[0]!="" && $count<=$maximage);
  449.  
  450.         if($count>$maximage) return 1; 
  451.     }
  452. }
  453.  
  454.  
  455. // Kopie von check_signature //
  456. function check_signature2($text) {
  457.  global $sigimage, $sigimage_ext, $sigmaximage;
  458.  $image_ext = explode("\r\n",trim($sigimage_ext));
  459.  $count=0;
  460.  
  461.  if(preg_match("/\[img].*javascript.*\[\/img\]/siU",$text)) {
  462.     return 1;
  463.   }
  464.  else {
  465.   do { 
  466.   $exp=array();
  467.   preg_match("/\[img]([^\"]*)\[\/img\]/siU",$text,$exp);
  468.   if(!isset($exp[0])) $exp[0]="";
  469.   if(!$exp[0]) break;
  470.   $text = str_replace($exp[0],"",$text);
  471.   $extension = trim(strtolower(substr(strrchr($exp[1],"."),1)));
  472.   if(!in_array($extension, $image_ext)) {
  473.    return 1;
  474.    break;
  475.   }
  476.   $count++;
  477.  } while($exp[0]!="" && $count<=$sigmaximage);
  478.  if($count>$sigmaximage) return 1;  }
  479. }
  480.  
  481. /* wird nicht mehr benötig
  482. * (durch das Auskommentieren finden wir auch  Fehler,
  483. * wo diese Funktion noch benutzt wird.
  484. */
  485. /*function editPostdata($data) {
  486.  $data = str_replace("'","&acute;", $data);
  487.  $data = str_replace("\"","&quot;", $data);
  488.  return $data;
  489. }*/
  490.  
  491.  
  492.  
  493.  
  494.  
  495. /**
  496. * @return text string
  497. * @param text string
  498. * @desc Diese Funktion ersetzt Urls und email Adressen ohne BBCode durch die Adresse MIT bbcode.
  499. * http://link wird zu [URL]http://link[/URL].. falls der URL Tag schon vorhanden ist, wird nichts ersetzt.
  500. */
  501. function parseURL($out) {
  502.  $urlsearch[]="/([^]_a-z0-9-=\"'\/])((https?|ftp):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si";
  503.  $urlsearch[]="/^((https?|ftp):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si";
  504.  $urlreplace[]="\\1[URL]\\2\\4[/URL]";
  505.  $urlreplace[]="[URL]\\1\\3[/URL]";
  506.  $emailsearch[]="/([\s])([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si";
  507.  $emailsearch[]="/^([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si";
  508.  $emailreplace[]="\\1[EMAIL]\\2[/EMAIL]";
  509.  $emailreplace[]="[EMAIL]\\0[/EMAIL]";
  510.  $out = preg_replace($urlsearch, $urlreplace, $out);
  511.  if (strpos($out, "@")) $out = preg_replace($emailsearch, $emailreplace, $out);
  512.  return $out;
  513. }
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522. # -------- beitrags anzeige
  523.  
  524. /* wird nicht mehr benötig
  525. * (durch das Auskommentieren finden wir auch  Fehler,
  526. * wo diese Funktion noch benutzt wird.
  527. */
  528. /*function editDBdata($data) {
  529.  $data = str_replace("&acute;","'", $data);
  530.  $data = str_replace("&quot;","\"", $data);
  531.  return $data;
  532. }*/
  533.  
  534.  
  535.  
  536. /**
  537. * @return expression string
  538. * @param expression string
  539. * @desc escaped einen String für die Benutzung in einem regulären Ausdruck.
  540. */
  541. function wbb_preg_quote($expression) {
  542.  $expression=preg_quote($expression);
  543.  $expression = str_replace("/","\/",$expression);
  544.  return $expression;
  545. }
  546.  
  547.  
  548. /**
  549. * @return text string
  550. * @param text string
  551. * @desc Diese Funktion zensiert einen Beitrag.
  552. */
  553. function censor($out) {
  554.  global $cover,$badwords;
  555.  reset($badwords);
  556.  if(count($badwords)) {
  557.   while (list($key, $val) = each($badwords)) {
  558.    $val = trim($val);
  559.    if(!$val) continue;
  560.    if(preg_match("/\{(.+)\}/si", $val, $exp)) {
  561.     $val = $exp[1];
  562.     $position = strpos($val, "=");
  563.     if($position===false) {
  564.      $searcharray[] = "/([\s]{1})".wbb_preg_quote($val)."([\s]{1})/si";                            
  565.      $replacearray[] = "\\1".str_repeat($cover, strlen($val))."\\2";
  566.      $searcharray[] = "/^".wbb_preg_quote($val)."([\s]{1})/si";                            
  567.      $replacearray[] = str_repeat($cover, strlen($val))."\\1";
  568.      $searcharray[] = "/([\s]{1})".wbb_preg_quote($val)."$/si";                            
  569.      $replacearray[] = "\\1".str_repeat($cover, strlen($val));
  570.     }
  571.     else {
  572.      $pcover = substr($val, $position+1);
  573.      $val = substr($val, 0, $position);
  574.      $searcharray[] = "/([\s]{1})".wbb_preg_quote($val)."([\s]{1})/si";                            
  575.      $replacearray[] = "\\1".$pcover."\\2";
  576.      $searcharray[] = "/^".wbb_preg_quote($val)."([\s]{1})/si";                            
  577.      $replacearray[] = $pcover."\\1";
  578.      $searcharray[] = "/([\s]{1})".wbb_preg_quote($val)."$/si";                            
  579.      $replacearray[] = "\\1".$pcover;
  580.     }
  581.    }
  582.    else {
  583.     $position = strpos($val, "=");
  584.     if($position===false) {
  585.      $out = eregi_replace("$val","".str_repeat($cover, strlen($val))."", $out);                        
  586.      $searcharray[] = "/".wbb_preg_quote($val)."/si";                          
  587.      $replacearray[] = str_repeat($cover, strlen($val));
  588.     }
  589.     else {
  590.      $pcover = substr($val, $position+1);
  591.      $val = substr($val, 0, $position);
  592.      $searcharray[] = "/".wbb_preg_quote($val)."/si";                          
  593.      $replacearray[] = $pcover;
  594.     }
  595.    }
  596.   }
  597.  }
  598.  // Bug: "Empty regular Expression" bei fehlender Zensurfunktion...
  599.  if(!isset($searcharray)) $searcharray=array();
  600.  if(!isset($replacearray)) $replacearray=array();
  601.  return ifelse(count($searcharray) && count($replacearray),preg_replace($searcharray, $replacearray, $out),$out);
  602. }
  603.  
  604.  
  605.  
  606.  
  607. /**
  608. * @return text string
  609. * @param text string
  610. * @desc Diese Funktion ersetzt Smiliecodes in einem Text durch die Smiliebilder.
  611. */
  612. function smilies($out) {
  613.     global $smiliecache;
  614.     if(!count($smiliecache)) $smiliecache = getsmilies();
  615.     for($i = 0; $i < count($smiliecache); $i++) $out=str_replace ($smiliecache[$i]['text'], "<img src=".$smiliecache[$i]['path']." border=0>", $out);
  616.         return $out;
  617. }
  618.  
  619.  
  620.  
  621.  
  622.  
  623. /**
  624. * @return smiliecache array
  625. * @desc Diese Funktion lädt alle Smiliecodes und Pfade in einen Array (cache).
  626. */
  627. function getsmilies() {
  628.     global $db_zugriff, $n;
  629.     $result = $db_zugriff->query("SELECT smiliespath as path, smiliestext as text FROM bb".$n."_smilies");
  630.     $count = 0;
  631.     while($row = $db_zugriff->fetch_array($result)) {
  632.         $smiliecache[$count] = $row;
  633.         $count++;
  634.     }
  635.     return $smiliecache;
  636. }
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644. /**
  645. * @return text string
  646. * @param text string
  647. * @param disablesmilies=0 int
  648. * @desc Diese Funktion ersetzt bearbeitet einen Beitrag zur Anzeige in einem Thema.
  649. * HTML wird (wenn eingestellt) zensiert. Smilies werden (wenn eingestellt) ersetzt.
  650. * Ferner wird die Zensur (wenn eingestellt) angewendet und BBCode (wenn eingestellt) wird ersetzt.
  651. */
  652. function editPost($out,$disable_smilies=0) {
  653.     global $bbcode,$html,$smilies,$badwords;
  654.     $nlreplace=substr(md5(uniqid(microtime())),0,6);
  655.     if(!$html)
  656.     {
  657.         #$out = str_replace("&lt;","&amp;lt;",$out);
  658.         #$out = str_replace("&gt;","&amp;gt;",$out);
  659.         #$out = str_replace("<","&lt;",$out);
  660.         #$out = str_replace(">","&gt;",$out);
  661.         $out = htmlspecialchars($out);
  662.     }
  663.     // <script> ist generell verboten...
  664.     else $out = preg_replace("/<script[^>]*>/i","&lt;script\\1&gt;",$out);
  665.     #$out = str_replace("\r\n",$nlreplace,$out);
  666.     #$out = str_replace($nlreplace,"\r\n",$out);
  667.     if($smilies && !$disable_smilies) $out = smilies($out);
  668.     if($bbcode) $out = prepare_code($out);
  669.     #$out = nl2br($out);
  670.     $out = str_replace("\n","<br />",$out);
  671.     $out = censor($out);
  672.     $out = nt_wordwrap($out);
  673.     return $out;
  674. }
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682. /**
  683. * @return text string
  684. * @param text string
  685. * @param disablesmilies=0 int
  686. * @desc Diese Funktion bearbeitet eine Signatur für die Anzeige in einem Thema.
  687. * HTML wird ersetzt, Smilies und BBCode werden ersetzt und die Zensur angewendet.
  688. */
  689. function editSignatur($out,$disable_smilies=0) {
  690.         global $sigbbcode,$sightml,$sigsmilies,$badwords;
  691.         #$out = editDBdata($out);
  692.         $nlreplace=substr(md5(uniqid(microtime())),0,6);
  693.         if(!$sightml)
  694.         {
  695.             #$out = str_replace("&lt;","&amp;lt;",$out);
  696.             #$out = str_replace("&gt;","&amp;gt;",$out);
  697.             #$out = str_replace("<","&lt;",$out);
  698.             #$out = str_replace(">","&gt;",$out);
  699.             $out = htmlspecialchars($out);
  700.         }
  701.         else $out = preg_replace("/<script[^>]*>/i","&lt;script\\1&gt;",$out);
  702.         $out = str_replace("\r\n",$nlreplace,$out);
  703.         $out = str_replace($nlreplace,"\n",$out);
  704.         if($sigsmilies && !$disable_smilies) $out = smilies($out);
  705.         if($sigbbcode) $out = prepare_code($out);
  706.         #$out = nl2br($out);
  707.         $out = str_replace("\n","<br />",$out);
  708.         /*$out = nl2br($out);
  709.         if($sigsmilies && !$disable_smilies) $out = smilies($out);
  710.         if($sigbbcode) $out = prepare_code($out); */
  711.         $out = censor($out);
  712.         $out = nt_wordwrap($out);
  713.         return $out;
  714. }
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721. /**
  722. * @return return mixed
  723. * @param expression boolean
  724. * @param returntrue mixed
  725. * @param returnfalse=null mixed
  726. * @desc Diese Funktion gibt returntrue zurück, wenn expression true ergibt. Andernfalls wird returnfalse zurückgegeben.
  727. */
  728. function ifelse($expression,$returntrue,$returnfalse="") {
  729.     #if (!$expression) return $returnfalse;
  730.     #else return $returntrue;
  731.     return ($expression ? $returntrue : $returnfalse);
  732. }
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739. /**
  740. * @return code string
  741. * @param code string
  742. * @desc Diese Funktion formatiert Code mit dem <pre> Tag
  743. */
  744. function formatcodetag($code) {
  745.     #$code = str_replace("<br>","",$code);
  746.     #$code = str_replace("<br />","",$code);
  747.     $code = str_replace("\\\"","\"",$code);
  748.     return "<blockquote><pre><font size=1>code:</font><hr><p>".$code."</p><hr></pre></blockquote>";
  749. }
  750.  
  751.  
  752.  
  753.  
  754.  
  755. /**
  756. * @return link string
  757. * @param url string
  758. * @param title=null string
  759. * @param maxwidth=60 int
  760. * @param width1=40 int
  761. * @param width2=-15 int
  762. * @desc Diese Funktion gibt einen Link zu url mit dem Titel title zurück.
  763. * Ist der Titel länger als maxwidth und kommt kein IMG Tag darin vor, wird er "abgeschnitten".
  764. */
  765. function formaturl($url, $title="", $maxwidth=60, $width1=40, $width2=-15) {
  766.  if(!trim($title)) $title=$url;
  767.  if(!preg_match("/[a-z]:\/\//si", $url)) $url = "http://$url";
  768.  if(strlen($title)>$maxwidth && !stristr($title,"[img]")) $title = substr($title,0,$width1)."...".substr($title,$width2);
  769.  return "<a href=\"$url\" target=\"_blank\">".str_replace("\\\"", "\"", $title)."</a>";
  770. }
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777. /**
  778. * @return list string
  779. * @param list string
  780. * @param listtype=null string
  781. * @desc Diese Funktion formatiert eine Liste...
  782. */
  783. function formatlist($list, $listtype="") {
  784.  $listtype = ifelse(!trim($listtype), "",  " type=\"$listtype\"");
  785.  $list = str_replace("\\\"","\"",$list);
  786.  if ($listtype) return "<ol$listtype>".str_replace("[*]","<li>", $list)."</ol>";
  787.  else return "<ul>".str_replace("[*]","<li>", $list)."</ul>";
  788. }
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. /**
  797. * @return highlighted_code string
  798. * @param code string
  799. * @desc Diese Funktion formatiert einen Code innerhalb eines PHP Tags mit highlight_string()
  800. */
  801. function phphighlite($code) {
  802.  
  803.  #$code = str_replace("\\\"","\"",$code);
  804. $code = rehtmlspecialchars($code);
  805.  #$code = str_replace("&gt;", ">", $code);
  806. #$code = str_replace("&lt;", "<", $code);
  807. #$code = str_replace("&amp;", "&", $code);
  808. #$code = str_replace('$', '\$', $code);
  809. #$code = str_replace('\n', '\\\\n', $code);
  810. #$code = str_replace('\r', '\\\\r', $code);
  811. #$code = str_replace('\t', '\\\\t', $code);
  812. #$code = str_replace("<br>", "", $code);
  813. #$code = str_replace("<br />", "", $code);
  814. $code = stripslashes($code);
  815.  if(!strpos($code,"<?") && substr($code,0,2)!="<?") $code="<?php\n".trim($code)."\n?>";
  816.  $code = trim($code);
  817.  ob_start();
  818.  $oldlevel=error_reporting(0);
  819.  highlight_string($code);
  820.  error_reporting($oldlevel);
  821.  $buffer = ob_get_contents();
  822.  ob_end_clean();
  823.  #$buffer = str_replace("<br />", "",$buffer);
  824.  
  825.  #$buffer = str_replace("&quot;", "\"", $buffer);
  826. #echo nl2br(htmlspecialchars($buffer))."<hr>";
  827. return "<blockquote><pre><font size=1>php:</font><hr><p>$buffer</p><hr></pre></blockquote>";
  828. }
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836. /**
  837. * @return out string
  838. * @param out string
  839. * @desc ..
  840. */
  841. function prepare_quote($out) {
  842.         global $zensur;
  843.         #$out = editDBdata($out);
  844.        if($zensur == 1) $out = censor($out);
  845.         return $out;
  846. }
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855. /**
  856. * @return topic string
  857. * @param topic string
  858. * @desc Diese Funktion zensiert HTML in einem String..
  859. */
  860. function prepare_topic($out) {
  861.     #return htmlspecialchars(nt_wordwrap(editDBdata($out),40));
  862.     return htmlspecialchars(nt_wordwrap($out,45));
  863. }
  864. // Kopie von prepare_topic() //
  865. function prepare_topic2($out) {
  866.     #return htmlspecialchars(nt_wordwrap(editDBdata($out),40));
  867.     return htmlspecialchars(stripslashes(nt_wordwrap($out,40)));
  868. }
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882. # -------- sonstige
  883.  
  884. /**
  885. * @return mods string
  886. * @param boardid int
  887. * @desc Gibt eine Liste mit den Moderatoren eines Forums zurück.
  888. */
  889. function getMod($id) {
  890.         global $boardid,$styleid,$session,$db_zugriff,$n;
  891.         $result = $db_zugriff->query("SELECT objectid,username FROM bb".$n."_object2board LEFT JOIN bb".$n."_user_table ON bb".$n."_user_table.userid=bb".$n."_object2board.objectid WHERE boardid = '$id' AND `mod` = 1");
  892.         $mods = "";
  893.         while($row = $db_zugriff->fetch_array($result)) {
  894.             if($mods) $mods .= ", ";
  895.             $mods .= "<a href=\"members.php?mode=profile&userid=".$row['objectid']."&boardid=".$boardid."&styleid=".$styleid.$session."\">".($row['username'])."</a>";
  896.         }
  897.         return $mods;
  898. }
  899. /*function getMod($id) {
  900.         global $boardid,$styleid,$session,$db_zugriff,$n;
  901.         $result = $db_zugriff->query("SELECT objectid FROM bb".$n."_object2board WHERE boardid = '$id' AND `mod` = 1");
  902.         $mods = "";
  903.         while($row = $db_zugriff->fetch_array($result)) {
  904.             if($mods) $mods .= ", ";
  905.             $mods .= "<a href=\"members.php?mode=profile&userid=".$row['objectid']."&boardid=".$boardid."&styleid=".$styleid.$session."\">".getUsername($row['objectid'])."</a>";
  906.         }
  907.         return $mods;
  908. }*/
  909.  
  910.  
  911.  
  912. /**
  913. * @return lastauthor string
  914. * @param threadid int
  915. * @desc Gibt den letzten Autor in einem Thema zurück... (mit Link zum profil).
  916. */
  917. function getLastAuthor($threadid) {
  918.         global $boardid,$n,$db_zugriff,$session;
  919.         $result = $db_zugriff->query_first("SELECT userid FROM bb".$n."_posts WHERE threadparentid='$threadid' ORDER by posttime DESC LIMIT 1");
  920.         return "<a href=\"members.php?mode=profile&userid=$result[userid]&boardid=$boardid$session\">".getUsername($result['userid'])."</a>";
  921. }
  922.  
  923.  
  924.  
  925. /**
  926. * @return flag int
  927. * @param threadid int
  928. * @desc Gibt den/die/das (*gg*) Flag eines thread zurück. 1 entspricht geschlossen, 0 entspricht offen.
  929. * Damit überprüft man also, ob ein Thread geschlossen ist oder nicht.
  930. */
  931. function getThreadflag($threadid) {
  932.         global $n,$db_zugriff;
  933.         $result = $db_zugriff->query_first("SELECT flags FROM bb".$n."_threads WHERE threadid='$threadid'");
  934.         return $result['flags'];
  935. }
  936.  
  937.  
  938.  
  939. /**
  940. * @return highlighted_code string
  941. * @param code string
  942. * @desc Diese Funktion formatiert einen Code innerhalb eines PHP Tags mit highlight_string()
  943. */
  944. function getBoardname($boardid) {
  945.         global $n,$db_zugriff;
  946.         $result = $db_zugriff->query_first("SELECT boardname FROM bb".$n."_boards WHERE boardid='$boardid'");
  947.         return prepare_topic($result['boardname']);
  948. }
  949.  
  950.  
  951.  
  952.  
  953. /**
  954. * @return threadname string
  955. * @param threadid int
  956. * @desc Ermittelt den Namen eines Themas anhand der ID und gibt ihn zurück..
  957. */
  958. function getThreadname($threadid) {
  959.         global $n,$db_zugriff;
  960.         $result = $db_zugriff->query_first("SELECT threadname FROM bb".$n."_threads WHERE threadid='$threadid'");
  961.         return prepare_topic($result['threadname']);
  962. }
  963.  
  964.  
  965. /**
  966. * @return url string
  967. * @param id int
  968. * @param nr int
  969. * @desc Ermittelt die URL zum letzten Beitrag 1) eines Themas 2) eines Forums 3) eines Benutzers
  970. */
  971. function getLastPost($id,$nr) {
  972.         global $eproseite, $n, $db_zugriff, $session, $longdateformat, $postorder, $sid, $styleid;
  973.         if($nr==1) {
  974.                 $result = $db_zugriff->query_first("SELECT threadid,replies FROM bb".$n."_threads WHERE boardparentid='$id' ORDER by timelastreply DESC LIMIT 1");
  975.                 $threadid = $result['threadid'];
  976.                 if($postorder) return "thread.php?threadid=".$threadid."&boardid=".$id."$session&page=1#1";
  977.                 else {
  978.                     $posts = $result['replies']+1;
  979.             $pages=(int)($posts/$eproseite);
  980.                     if(($posts/$eproseite)-$pages>0) $pages++;
  981.                     return "thread.php?threadid=".$threadid."&boardid=".$id."$session&page=".$pages."#".$posts;
  982.             }
  983.         }
  984.         if($nr==2) {
  985.                 $result = $db_zugriff->query_first("SELECT boardparentid,replies FROM bb".$n."_threads WHERE threadid='$id' LIMIT 1");
  986.                 $boardid = $result['boardparentid'];
  987.                 if($postorder) return "thread.php?threadid=".$id."&boardid=".$boardid."$session&page=1#1";
  988.                 else {
  989.                     $posts = $result['replies']+1;
  990.             $pages=(int)($posts/$eproseite);
  991.                     if(($posts/$eproseite)-$pages>0) $pages++;
  992.             return "thread.php?threadid=".$id."&boardid=".$boardid."$session&page=".$pages."#".$posts;
  993.         }
  994.         }
  995.         if($nr==4) {
  996.                 $result = $db_zugriff->query_first("SELECT threadparentid, boardparentid FROM bb".$n."_posts WHERE userid='$id' ORDER by posttime DESC LIMIT 1");
  997.                 $threadid = $result['threadparentid'];
  998.                 if($postorder) return "thread.php?threadid=".$threadid."&boardid=".$result['boardparentid']."$session&page=1#1";
  999.             else {
  1000.                     $result = $db_zugriff->query_first("SELECT boardparentid,replies FROM bb".$n."_threads WHERE threadid='$threadid'");
  1001.                     $posts = $result['replies']+1;
  1002.                     $pages=(int)($posts/$eproseite);
  1003.                     if(($posts/$eproseite)-$pages>0) $pages++;
  1004.                     return "thread.php?threadid=".$threadid."&boardid=".$result['boardparentid']."&styleid=$styleid$session&page=".$pages."#".$posts;
  1005.             }
  1006.         }
  1007.         if($nr==5) {
  1008.                 $result = $db_zugriff->query_first("SELECT threadparentid, boardparentid FROM bb".$n."_posts WHERE userid='$id' ORDER by posttime DESC LIMIT 1");
  1009.                 $threadid = $result['threadparentid'];
  1010.                 if($postorder) return "thread.php?threadid=".$threadid."&boardid=".$result['boardparentid']."$session&page=1#1";
  1011.             else {
  1012.                     $result = $db_zugriff->query_first("SELECT boardparentid,replies FROM bb".$n."_threads WHERE threadid='$threadid'");
  1013.                     $posts = $result['replies']+1;
  1014.                     $pages=(int)($posts/$eproseite);
  1015.                     if(($posts/$eproseite)-$pages>0) $pages++;
  1016.                     return "thread.php?threadid=".$threadid."&boardid=".$result['boardparentid']."&styleid=$styleid$session&page=".$pages."#".$posts;
  1017.             }
  1018.         }
  1019. }
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025. /**
  1026. * @return url string
  1027. * @param threadid int
  1028. * @param time int
  1029. * @desc Ermittelt die URL des ersten neuen Beitrags in einem Themas.
  1030. */
  1031. function firstnewPost($threadid,$time) {
  1032.         global $eproseite,$n,$db_zugriff,$styleid,$session, $postorder;
  1033.         $sthreadname = "sthread_".$threadid;
  1034.     global $$sthreadname;
  1035.     if($$sthreadname > $time) $time = $$sthreadname+1;
  1036.        
  1037.         $thread = $db_zugriff->query_first("SELECT boardparentid, replies FROM bb".$n."_threads WHERE threadid='$threadid' ORDER by timelastreply DESC");
  1038.         $posts = $thread['replies']+1;
  1039.  
  1040.         $result = $db_zugriff->query("SELECT posttime FROM bb".$n."_posts WHERE threadparentid='$threadid' ORDER by posttime ".ifelse($postorder,"DESC","ASC"));
  1041.         $i=1;
  1042.         while($row = $db_zugriff->fetch_array($result)) {
  1043.                 if($time<=$row['posttime']) break;
  1044.                 $i++;
  1045.         }
  1046.         $db_zugriff->free_result($result);
  1047.         $j=(int)($i/$eproseite);
  1048.         if(($i/$eproseite)-$j>0) $j++;
  1049.  
  1050.         return "thread.php?threadid=".$threadid."&boardid=".$thread[boardparentid]."&styleid=$styleid$session&page=".$j."#".$i;
  1051. }
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058. /**
  1059. * @return isonline int
  1060. * @param userid int
  1061. * @desc Überprüft, ob ein Benutzer online ist. Gibt 1 zurück, wenn er online ist, andernfalls 0.
  1062. */
  1063. function checkuseronline($userid) {
  1064.         global $n,$db_zugriff, $timeout;
  1065.         $user = $db_zugriff->query_first("SELECT COUNT(userid) as anzahl FROM bb".$n."_user_table WHERE userid='$userid' AND invisible='0'");
  1066.         if($user['anzahl']) $anzahl = $db_zugriff->query_first("SELECT COUNT(zeit)as anzahl FROM bb".$n."_useronline WHERE userid='$userid' AND zeit>='".(time()-60*$timeout)."'");
  1067.         return $anzahl['anzahl'];
  1068. }
  1069.  
  1070.  
  1071.  
  1072. /**
  1073. * @return result int
  1074. * @param postid int
  1075. * @param threadid int
  1076. * @param boardid int
  1077. * @desc Löscht einen Beitrag in einem Thema. Sind keine Antworten mehr in einem Thema, wird auch das Thema gelöscht.
  1078. * Wird nur ein Beitrag gelöscht, wird 1 zurückgegeben. Wenn auch das Thema gelöscht wird, wird 2 zurückgegeben.
  1079. */
  1080. function delPost($postid,$threadid,$boardid) {
  1081.         global $n,$db_zugriff;
  1082.         $threadinfo = $db_zugriff->query_first("SELECT replies FROM bb".$n."_threads WHERE threadid = '$threadid'");
  1083.         if(!$threadinfo['replies']) { // keine Antworten mehr => Thema auch löschen.
  1084.                 $author = $db_zugriff->query_first("SELECT userid FROM bb".$n."_posts WHERE postid = '$postid'");
  1085.                 delUserposts($author[0]);
  1086.                 $db_zugriff->query("DELETE FROM bb".$n."_threads WHERE threadid='$threadid'");
  1087.                 $db_zugriff->query("DELETE FROM bb".$n."_posts WHERE postid='$postid'");
  1088.                
  1089.                 $pinfo = $db_zugriff->query_first("SELECT postid, posttime, userid FROM bb".$n."_posts WHERE boardparentid = '$boardid' ORDER BY posttime DESC LIMIT 1");
  1090.                 $db_zugriff->query("UPDATE bb".$n."_boards SET threads=threads-1, posts=posts-1, lastposttime = '$pinfo[posttime]', lastpostid = '$pinfo[postid]' WHERE boardid = '$boardid'");
  1091.                
  1092.                 $db_zugriff->query("DELETE FROM bb".$n."_notify WHERE threadid='$threadid'");
  1093.                 $db_zugriff->query("DELETE FROM bb".$n."_poll WHERE threadid='$threadid'");
  1094.                 $db_zugriff->query("DELETE FROM bb".$n."_vote WHERE threadid='$threadid'");
  1095.                 $db_zugriff->query("DELETE FROM bb".$n."_object2user WHERE objectid='$threadid' AND favthreads = 1");
  1096.                
  1097.                 return 2;
  1098.         }
  1099.         else { // nur beitrag löschen..
  1100.                 $author = $db_zugriff->query_first("SELECT userid FROM bb".$n."_posts WHERE postid = '$postid'");
  1101.                 delUserposts($author[0]);
  1102.                 $db_zugriff->query("DELETE FROM bb".$n."_posts WHERE postid='$postid'");
  1103.                 $tinfo=$db_zugriff->query_first("SELECT userid, posttime FROM bb".$n."_posts WHERE threadparentid='$threadid' ORDER BY posttime DESC");
  1104.                 $db_zugriff->query("UPDATE bb".$n."_threads SET replies=replies-1, timelastreply='$tinfo[posttime]', lastposterid='$tinfo[userid]' WHERE threadid = '$threadid'");
  1105.                
  1106.                 $pinfo = $db_zugriff->query_first("SELECT postid, posttime FROM bb".$n."_posts WHERE boardparentid = '$boardid' ORDER BY posttime DESC LIMIT 1");
  1107.                 $db_zugriff->query("UPDATE bb".$n."_boards SET posts=posts-1, lastposttime = '$pinfo[posttime]', lastpostid = '$pinfo[postid]' WHERE boardid = '$boardid'");
  1108.                
  1109.                 return 1;
  1110.         }
  1111. }
  1112.  
  1113.  
  1114.  
  1115. /**
  1116. * @return void
  1117. * @param userid int
  1118. * @desc Verringert die Beitragszahl des Benutzers um 1. (wenn ein Beitrag gelöscht wird).
  1119. */
  1120. function delUserposts($userid) {
  1121.         global $n,$db_zugriff;
  1122.         $db_zugriff->query("UPDATE bb".$n."_user_table SET userposts=userposts-1 WHERE userid='$userid'");
  1123. }
  1124.  
  1125.  
  1126.  
  1127. /**
  1128. * @return date string
  1129. * @param time int
  1130. * @param format string
  1131. * @param replacetoday=0 int
  1132. * @desc Gibt die Zeit time formatiert nach format zurück.
  1133. * Ist replacetoday=1, wird das heutige Datum durch "heute" ersetzt.
  1134. */
  1135. function formatdate($time,$format,$replacetoday=0) {
  1136.     global $db_zugriff, $n, $timetype, $timeoffset, $today;
  1137.     $time = $time+(3600*$timeoffset);
  1138.     if(date("dmY", time()+(3600*$timeoffset))==date("dmY", $time) && $replacetoday) { // heute ersetzen.
  1139.         $position = strpos($today, "=");
  1140.                 if($position!==false) {                        
  1141.                     $pcover = substr($today, $position+1);
  1142.                     $val = substr($today, 0, $position);
  1143.                     $format = str_replace($val,$pcover, $format);
  1144.                 }
  1145.     }
  1146.     $out = str_replace("DD",date("d", $time), $format);
  1147.     $out = str_replace("MM",date("m", $time), $out);
  1148.     $out = str_replace("YYYY",date("Y", $time), $out);
  1149.     $out = str_replace("YY",date("y", $time), $out);
  1150.     $out = str_replace("MN",get_month_name(date("n", $time)), $out);
  1151.     if($timetype) { #12 Stunden
  1152.         $out = str_replace("II","II ".date("A", $time), $out); 
  1153.         $out = str_replace("HH",date("h", $time), $out);
  1154.     }
  1155.     else $out = str_replace("HH",date("H", $time), $out);
  1156.     $out = str_replace("II",date("i", $time), $out);
  1157.     return $out;
  1158. }
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164. /**
  1165. * @return template string
  1166. * @param templatename string
  1167. * @param extension='htm' string
  1168. * @desc gibt den Inhalt der Template template zurück. Benutzt einen Cache..
  1169. */
  1170. function gettemplate($template,$endung="htm") {
  1171.         global $templatefolder,$templatecache;
  1172.         // noch nicht im Cache
  1173.         if(!isset($templatecache[$template]))
  1174.         {
  1175.             if(!$templatefolder) $templatefolder = "templates";
  1176.             $templatecache[$template] = implode("",file($templatefolder."/".$template.".".$endung));
  1177.         }
  1178.         return str_replace("\"","\\\"",$templatecache[$template]);
  1179. }
  1180.  
  1181.  
  1182.  
  1183.  
  1184. /**
  1185. * @return void
  1186. * @param template string
  1187. * @desc Ersetzt in template einige Codewörter zur Formatierung und gibt template dann auf dem Bildschirm aus.
  1188. */
  1189. function dooutput($template) {
  1190.         global $_SESSION, $_COOKIE, $db_zugriff,$bgcolor, $tablebg, $tableb, $tablec, $tabled, $tablea, $font, $fontcolor, $fontcolorsec, $fontcolorthi, $fontcolorfour, $bgfixed, $bgimage, $imagefolder;
  1191.        
  1192.         $template = str_replace("{pagebgcolor}","$bgcolor",$template);
  1193.         $template = str_replace("{tablebordercolor}","$tablebg",$template);
  1194.         $template = str_replace("{tablea}","$tablea",$template);
  1195.         $template = str_replace("{tableb}","$tableb",$template);
  1196.         $template = str_replace("{tablec}","$tablec",$template);
  1197.         $template = str_replace("{tabled}","$tabled",$template);
  1198.         $template = str_replace("{font}","$font",$template);
  1199.         $template = str_replace("{fontcolorfirst}","$fontcolor",$template);
  1200.         $template = str_replace("{fontcolorsecond}","$fontcolorsec",$template);
  1201.         $template = str_replace("{fontcolorthird}","$fontcolorthi",$template);
  1202.         $template = str_replace("{fontcolorfourth}","$fontcolorfour",$template);
  1203.         $template = str_replace("{imagefolder}","$imagefolder",$template);
  1204.        
  1205.  
  1206.         if($bgimage) $hgpicture = " background=\"$bgimage\"";
  1207.         if(isset($hgpicture)) $template = str_replace("{hgpicture}","$hgpicture",$template);
  1208.         if($bgfixed) $template = str_replace("{bgproperties}"," bgproperties=fixed",$template);
  1209.         else $template = str_replace("{bgproperties}","",$template);
  1210.         echo $template;
  1211.  
  1212. }
  1213.  
  1214.  
  1215.  
  1216.  
  1217. // ##########################  Neuen Post einfügen * ########################################################
  1218.  
  1219. /**
  1220. * @return result int
  1221. * @param boardid int
  1222. * @param threadid int
  1223. * @param userid int
  1224. * @param subject string
  1225. * @param message string
  1226. * @param posticon int
  1227. * @param parseurl int
  1228. * @param email int
  1229. * @param disablesmilies int
  1230. * @param signature int
  1231. * @param close int
  1232. * @desc erstellt einen neuen Beitrag im Thema mit der id threadid und dem board mit der id boardid
  1233. * mit dem Inhalt subject und message. Ausserdem gibt es einige Parameter.
  1234. * Gibt 4 zurück, wenn der Beitrag erstellt wurde. Wenn der Beitrag nicht erstellt werden konnte, weil das Thema
  1235. * schon geschlossen ist, wird 2 zurückgegben.
  1236. */
  1237. function newPost($boardid,$threadid,$userid,$subject,$message,$posticon,$parseurl,$email,$disablesmilies,$signature,$close)
  1238. {
  1239.     global $n,$db_zugriff,$REMOTE_ADDR;
  1240.     $thread_info = $db_zugriff->query_first("SELECT boardparentid,flags FROM bb".$n."_threads WHERE threadid='$threadid'");
  1241.     if($thread_info['flags']==1) return 2; // Thema schon geschlossen..
  1242.     else // Beitrag speichern.
  1243.     {
  1244.         $time = time();
  1245.         if($parseurl) $message = parseURL($message);
  1246.  
  1247.         if($disablesmilies!=1) $disablesmilies=0;
  1248.         if($signature!=1) $signature=0;
  1249.  
  1250.         $db_zugriff->query("UPDATE bb".$n."_user_table SET userposts=userposts+1 WHERE userid='$userid'");
  1251.         $db_zugriff->query("UPDATE bb".$n."_threads SET replies=replies+1, lastposterid='$userid', timelastreply='$time' WHERE threadid='$threadid'");
  1252.         $db_zugriff->query("INSERT INTO bb".$n."_posts (boardparentid,threadparentid,userid,posttime,posttopic,message,posticon,disable_smilies,signature,ip) VALUES ('$boardid','$threadid','$userid','$time','$subject','$message','$posticon','$disablesmilies','$signature','$REMOTE_ADDR')");
  1253.  
  1254.         $postid = $db_zugriff->insert_id();
  1255.         $db_zugriff->query("UPDATE bb".$n."_boards SET posts=posts+1, lastposttime = '$time', lastpostid = '$postid' WHERE boardid = '$boardid'"); 
  1256.  
  1257.         sendEmail($userid,getLastPost($userid,5),$threadid,$boardid);
  1258.         if($email && $userid) // eMail Benachrichtigung einfügen.
  1259.         {
  1260.             $check = $db_zugriff->query_first("SELECT COUNT(*) FROM bb".$n."_notify WHERE threadid = '$threadid' AND userid = '$userid'");
  1261.             if(!$check[0]) $db_zugriff->query("INSERT INTO bb".$n."_notify (threadid,userid) VALUES ($threadid,$userid)");
  1262.         }
  1263.         // Thema auch gleich schliessen
  1264.         if($close) $db_zugriff->query("UPDATE bb".$n."_threads SET flags = 1 WHERE threadid = '$threadid'");
  1265.         return 4;
  1266.     }
  1267. }
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274. // ##########################  Useronline * ########################################################
  1275.  
  1276. /**
  1277. * @return void
  1278. * @param user_id int
  1279. * @desc diese Funktion wird bei jedem Seitenaufruf aufgerufen und trägt den Benutzer
  1280. * in die useronlineliste ein bzw. aktualisiert seinen Eintrag.
  1281. */
  1282. function useronline($user_id)
  1283. {
  1284.     global $useronlinelastemptied,$timeout,$n,$db_zugriff,$rekord,$sid,$REMOTE_ADDR;
  1285.     $deltime = time()-($timeout*60);
  1286.  
  1287.  
  1288.     // Registrierter Benutzer .. keine ip
  1289.     if($user_id)
  1290.     {
  1291.         $db_zugriff->query("REPLACE INTO bb".$n."_useronline (sid,zeit,ip,userid) VALUES ('$sid','".time()."','','$user_id')");
  1292.         $db_zugriff->query("DELETE FROM bb".$n."_useronline WHERE userid=$user_id AND sid<>'$sid'");
  1293.     }
  1294.    
  1295.     // Gast, identifizierung anhand der ip..
  1296.     else
  1297.     {
  1298.         $db_zugriff->query("REPLACE INTO bb".$n."_useronline (sid,zeit,ip,userid) VALUES ('$sid','".time()."','$REMOTE_ADDR','')");
  1299.     }
  1300.    
  1301.    
  1302.     // Wenn die letzte "Löschung" mehr als timeout Minuten zurückliegt,
  1303.     // ist es Zeit für die nächste ;)
  1304.     if((time()-$timeout*60)>$useronlinelastemptied)
  1305.     {
  1306.         $db_zugriff->query("DELETE FROM bb".$n."_useronline WHERE zeit<'$deltime'");
  1307.         $db_zugriff->query("UPDATE bb".$n."_config SET useronlinelastemptied='".time()."'");
  1308.     }
  1309.    
  1310.     // Useronline Rekord aktualisieren..
  1311.     $user = $db_zugriff->query_first("SELECT COUNT(zeit) as anzahl FROM bb".$n."_useronline");
  1312.     if($user['anzahl']>$rekord) $db_zugriff->query("UPDATE bb".$n."_config set rekord='".$user['anzahl']."', rekordtime='".time()."'");
  1313. }
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323. /**
  1324. * @return void
  1325. * @param userid int
  1326. * @param link string
  1327. * @param threadid int
  1328. * @param boardid int
  1329. * @desc Wenn jemand die Email Benachrichtigung zum Thema mit der id threadid aktiviert hat,
  1330. * wird eine Benachrichtigung per email gesendet, dass der benutzer (mit der id userid) einen neuen
  1331. * Beitrag im Thema (mit der Id threadid - im Board mit der id boardid) geschrieben hat.
  1332. * link ist die direkte URL zu diesem Beitrag.
  1333. */
  1334. function sendEmail($userid,$link,$threadid,$boardid) {
  1335.         global $boardid, $master_email, $php_path, $db_zugriff, $n;
  1336.         $result = $db_zugriff->query("SELECT * FROM bb".$n."_notify WHERE threadid = '$threadid'");
  1337.         if($db_zugriff->num_rows($result)) {
  1338.             $boardname = getBoardname($boardid);
  1339.                 $threadname = getThreadname($threadid);
  1340.                 if($userid) $authorname = getUsername($userid);
  1341.                 else eval ("\$authorname = \"".gettemplate("lg_anonymous")."\";");
  1342.                 eval ("\$inhalt = \"".gettemplate("notify_inhalt")."\";");
  1343.                 eval ("\$betreff = \"".gettemplate("notify_betreff")."\";");
  1344.                 while($row = $db_zugriff->fetch_array($result)) {
  1345.                         if($row['userid']==$userid) continue;
  1346.                         $email = getUserEmail($row['userid']);
  1347.                         mail($email,$betreff,$inhalt.$row['userid'],"From: ".$master_email);
  1348.                 }
  1349.         }
  1350. }
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356. // ##########################  activation * ########################################################
  1357. /**
  1358. * @return result int
  1359. * @param userid int
  1360. * @param code int
  1361. * @desc Aktiviert den Benutzeraccount mit der id userid,
  1362. * wenn der code mit dem in der Datenbank übereinstimmt (der bei der Registrierung versendet wurde).
  1363. * Gibt bei Erfolg 0 zurück; wenn der Benutzeraccount nicht exisiert, wird 1 zurückgegen.
  1364. * Ist der Benutzeraccount schon aktiviert, wird 2 zurückgegeben. Wenn der Code falsch ist, wird 3 zurückgegeben.
  1365. */
  1366. function activat($userid,$code)
  1367. {
  1368.         global $n,$db_zugriff;
  1369.         $anzahluser = $db_zugriff->query_first("SELECT COUNT(userid)as anzahl FROM bb".$n."_user_table WHERE userid='$userid'");
  1370.         if($anzahluser['anzahl']==0) return 1; // kein Benutzer gefunden.
  1371.         else {
  1372.                 $result = $db_zugriff->query("SELECT activation FROM bb".$n."_user_table WHERE userid='$userid' && activation!='1'");
  1373.                 $anzahluser = $db_zugriff->num_rows($result);
  1374.                 if($anzahluser==0) return 2; // Benutzeraccount ist schon aktiviert.
  1375.                 else {
  1376.                         $result = $db_zugriff->fetch_array($result);
  1377.                         if($code==$result['activation']) $db_zugriff->query("UPDATE bb".$n."_user_table SET activation='1' WHERE userid='$userid'");
  1378.                         else return 3; // falscher Code
  1379.                 }
  1380.         }
  1381. }
  1382.  
  1383.  
  1384.  
  1385. /**
  1386. * @return output string
  1387. * @param userid int
  1388. * @param id int
  1389. * @param b_or_t string
  1390. * @desc Fügt ein Board/Thema zu den Favoriten des Benutzers userid hinzu.
  1391. */
  1392. function subscripe($userid,$id,$b_or_t) {
  1393.         global $n,$db_zugriff,$favboards,$favthreads;
  1394.         $output="";
  1395.         if($b_or_t == "b") $max = $favboards;
  1396.         else $max = $favthreads;
  1397.         $field = "fav".$b_or_t;
  1398.         if(!check_userobject($userid,$id,$field)) {
  1399.         $count = $db_zugriff->query_first("SELECT COUNT(*) FROM bb".$n."_object2user WHERE userid = '$userid' AND $field = 1");
  1400.         if($count[0] >= $max) eval ("\$output = \"".gettemplate("error24")."\";");
  1401.         else $db_zugriff->query("INSERT INTO bb".$n."_object2user (userid,objectid,$field) VALUES ('$userid','$id','1')");
  1402.     }
  1403.         return $output;
  1404. }
  1405.  
  1406.  
  1407.  
  1408. /**
  1409. * @return color string
  1410. * @param zeilennr int
  1411. * @desc Gibt abwechselnd 'tableb'/'tablec' zurück.
  1412. */
  1413. function rowcolor($zeile) {
  1414.         if (($zeile/2) != floor($zeile/2)) $color="tableb";
  1415.         else $color="tablec";
  1416.         return $color;
  1417. }
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423. /**
  1424. * @return boardid int
  1425. * @param threadid int
  1426. * @desc gibt die id des Forums zurück.
  1427. */
  1428. function getBoardparent($threadid) {
  1429.         global $n,$db_zugriff;
  1430.         $result = $db_zugriff->query_first("SELECT boardparentid FROM bb".$n."_threads WHERE threadid='$threadid'");
  1431.         return $result['boardparentid'];
  1432. }
  1433.  
  1434.  
  1435.  
  1436.  
  1437. /**
  1438. * @return void
  1439. * @param id int
  1440. * @param userid int
  1441. * @param b_or_t string
  1442. * @desc Entfernt ein Board/Thema aus den Favoriten des Benutzers userid
  1443. */
  1444. function unsubscripe($id,$userid,$b_or_t) {
  1445.         global $n,$db_zugriff;
  1446.         $field = "fav".$b_or_t;
  1447.         $db_zugriff->query("DELETE FROM bb".$n."_object2user WHERE userid = '$userid' AND objectid = '$id' AND $field = 1");
  1448. }
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455. /**
  1456. * @return userstars string
  1457. * @param posts int
  1458. * @param groupid int
  1459. * @desc gibt einen String mit den Bildern des Ranges zurück, der mit posts und groupid ermittelt wird.
  1460. */
  1461. function getUserStars($posts,$groupid) {
  1462.         global $n,$db_zugriff;
  1463.         $result = $db_zugriff->query_first("SELECT id, rank, grafik, mal FROM bb".$n."_ranks WHERE groupid = $groupid AND posts<='$posts' ORDER by posts DESC");
  1464.              
  1465.        # for($i = 0; $i<$result[mal]; $i++) {
  1466.        #        $out .= "<img src=\"".$result['grafik']."\" border=\"0\">";
  1467.        #}
  1468.         $out = str_repeat("<img src=\"".$result['grafik']."\" border=\"0\">",$result['mal']);
  1469.         return "<a href=\"javascript:rank($result[id])\" title=\"Informationen zum Rang $result[rank]\">".$out."</a>";
  1470. }
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476. /**
  1477. * @return void
  1478. * @param absender string
  1479. * @param message string
  1480. * @param betreff string
  1481. * @useremail string
  1482. * @desc Schickt über das Board eine email an useremail mit dem Absender absender und dem Inhalt betreff und message
  1483. */
  1484. function formmail($absender,$message,$betreff,$useremail) {
  1485.         global $master_board_name, $php_path;
  1486.         $useremail = trim($useremail);
  1487.         #$message .= "\n\n_________________________________________________________________\nPowered by: ".$master_board_name." - ".$php_path;
  1488.         eval ("\$message = \"".gettemplate("formmail_message2")."\";");
  1489.         $absender = "From: ".$absender;
  1490.         mail($useremail,$betreff,$message,$absender);
  1491. }
  1492.  
  1493.  
  1494.  
  1495.  
  1496. /**
  1497. * @return void
  1498. * @param userid int
  1499. * @param postid int
  1500. * @param boardid int
  1501. * @param threadid int
  1502. * @desc Schickt eine eMail an den moderator des Forums boardid und meldet den Beitrag mit der id postid.
  1503. */
  1504. function report($userid,$postid,$boardid,$threadid) {
  1505.         global $master_board_name, $php_path, $master_email, $db_zugriff, $n, $eproseite;
  1506.         $mod = $db_zugriff->query_first("SELECT bb".$n."_object2board.objectid, useremail FROM bb".$n."_object2board LEFT JOIN bb".$n."_user_table ON (bb".$n."_object2board.objectid=bb".$n."_user_table.userid) WHERE boardid='$boardid' AND `mod`=1");
  1507.         if(!$mod['useremail']) $mod = $db_zugriff->query_first("SELECT bb".$n."_object2board.objectid, useremail FROM bb".$n."_object2board LEFT JOIN bb".$n."_user_table ON (bb".$n."_object2board.objectid=bb".$n."_user_table.userid) WHERE `mod`=1");
  1508.         if(!$mod['useremail']) $mod = $db_zugriff->query_first("SELECT bb".$n."_groups.id, useremail FROM bb".$n."_groups LEFT JOIN bb".$n."_user_table ON (bb".$n."_groups.id=bb".$n."_user_table.groupid) WHERE ismod=1 OR issupermod=1 ORDER BY ismod DESC");      
  1509.         $posts = $db_zugriff->query("SELECT postid,userid FROM bb".$n."_posts WHERE threadparentid='".$threadid."' ORDER BY posttime ASC");
  1510.         $i=0;
  1511.         while($post=$db_zugriff->fetch_array($posts))
  1512.         {
  1513.             $i++;
  1514.             if($post['postid']==$postid) break;
  1515.         }
  1516.         $page=ceil($i/$eproseite);
  1517.         $authorname = getUsername($post['userid']);
  1518.         $username = getUsername($userid);
  1519.         eval ("\$betreff = \"".gettemplate("report_betreff")."\";");
  1520.         eval ("\$message = \"".gettemplate("report_mail")."\";");
  1521.         mail(trim($mod['useremail']),$betreff,$message,"From: ".$master_email);
  1522. }
  1523.  
  1524.  
  1525.  
  1526.  
  1527. // ###################### Get Code Buttons #######################
  1528. /**
  1529. * @return bbcode_buttons string
  1530. * @desc lädt die Templates für die bbcode buttons und gibt den inhalt zurück.
  1531. */
  1532. function getcodebuttons() {
  1533.         $modechecked[0] = "CHECKED";
  1534.         $modechecked[1] = "";
  1535.  
  1536.         eval ("\$bbcode_sizebits = \"".gettemplate("bbcode_sizebits")."\";");
  1537.         eval ("\$bbcode_fontbits = \"".gettemplate("bbcode_fontbits")."\";");
  1538.         eval ("\$bbcode_colorbits = \"".gettemplate("bbcode_colorbits")."\";");
  1539.         eval ("\$bbcode_alignbits = \"".gettemplate("bbcode_alignbits")."\";");
  1540.         eval ("\$bbcode_buttons = \"".gettemplate("bbcode_buttons")."\";");
  1541.         return $bbcode_buttons;
  1542. }
  1543.  
  1544. // ###################### Get Clicky Smilies #######################
  1545. /**
  1546. * @return bbcodesmilies string
  1547. * @param tableColumns=3 int
  1548. * @param maxSmilies=-1 int
  1549. * @desc generiert eine HTML Tabelle mit allen Smilies (die man anklicken kann - zum einfügen in beiträge).
  1550. * tableColumns Smilies pro Reihe.
  1551. */
  1552. function getclickysmilies ($tableColumns=3,$maxSmilies=-1) {
  1553.         global $session,$boardid,$styleid, $db_zugriff, $n, $sid;
  1554.  
  1555.         $result = $db_zugriff->query("SELECT * FROM bb".$n."_smilies");
  1556.     $totalSmilies = $db_zugriff->num_rows($result);
  1557.  
  1558.         if (($maxSmilies == -1) || ($maxSmilies >= $totalSmilies)) $maxSmilies = $totalSmilies;
  1559.         elseif ($maxSmilies < $totalSmilies) eval ("\$bbcode_smilies_getmore = \"".gettemplate("bbcode_smilies_getmore")."\";");
  1560.  
  1561.     $i=0;
  1562.         while($row = $db_zugriff->fetch_array($result)) {
  1563.             eval ("\$smilieArray[\"".$i."\"] = \"".gettemplate("bbcode_smiliebit")."\";");
  1564.             $i++;
  1565.         }
  1566.         $tableRows = ceil($maxSmilies/$tableColumns);
  1567.         $count = 0;
  1568.         $smiliebits = "";
  1569.         for ($i=0; $i<$tableRows; $i++) {
  1570.                 $smiliebits .= "\t<tr bgcolor=\"{tableb}\">\n";
  1571.                 for ($j=0; $j<$tableColumns; $j++) {
  1572.                         $smiliebits .= "\t<td align=\"center\">".$smilieArray[$count]."&nbsp;</td>\n";
  1573.                         $count++;
  1574.                 }
  1575.                 $smiliebits .= "\t</tr>\n";
  1576.         }
  1577.  
  1578.         eval ("\$bbcode_smilies = \"".gettemplate("bbcode_smilies")."\";");
  1579.         return $bbcode_smilies;
  1580. }
  1581.  
  1582.  
  1583.  
  1584. /**
  1585. * @return userposts int
  1586. * @param username string
  1587. * @desc ermittelt die Beitragszahl des Benutzers username und gibt sie zurück.
  1588. */
  1589. function getUserposts($name) {
  1590.     global $db_zugriff, $n;
  1591.     // Ich bin nicht sicher, wie die Funktion aufgerufen wird (habs net gefunden).
  1592.     // also ob addslashes() und htmlspecialchars() schon auf den Benutzername angewendet wurden oder nicht.
  1593.     $result = $db_zugriff->query_first("SELECT userposts FROM bb".$n."_user_table WHERE username='".addslashes(htmlspecialchars($name))."'");
  1594.     #$result = $db_zugriff->query_first("SELECT userposts FROM bb".$n."_user_table WHERE username='".$name."'");
  1595.     return $result['userposts'];
  1596. }
  1597.  
  1598.  
  1599.  
  1600. /**
  1601. * @return result int
  1602. * @param boardid int
  1603. * @param objectid int
  1604. * @param field string
  1605. * @desc Überprüft, ob man Zugriff auf ein Forum hat, ob man moderator ist etc.
  1606. * Rückgabewert: bei Erfolg 1, ansonsten 0.
  1607. */
  1608. function check_boardobject($boardid,$objectid,$field) {
  1609.         global $n,$db_zugriff;
  1610.         $result = $db_zugriff->query_first("SELECT COUNT(*) FROM bb".$n."_object2board WHERE boardid = '$boardid' AND objectid = '$objectid' AND bb".$n."_object2board.$field = 1");
  1611.         return $result[0];
  1612. }
  1613.  
  1614. /**
  1615. * @return result int
  1616. * @param userid int
  1617. * @param objectid in
  1618. * @param field string
  1619. * @desc überprüft, ob man jemanden in der buddy- oder ignoreliste hat oder ob man ein board oder thread in den favoriten hat.
  1620. * Rückgabewert: bei Erfolg 1, ansonsten 0.
  1621. */
  1622. function check_userobject($userid,$objectid,$field) {
  1623.     global $n,$db_zugriff;
  1624.     $result = $db_zugriff->query_first("SELECT COUNT(*) FROM bb".$n."_object2user WHERE userid = '$userid' AND objectid = '$objectid' AND $field = 1");
  1625.     return $result[0];
  1626. }
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632. /**
  1633. * @return result int
  1634. * @param email string
  1635. * @param db=0 int
  1636. * @desc Überprüft, ob eine eMail Adresse gültig ist.
  1637. * Rückgabewert: 1 wenn die Email Adresse ungültig ist. Wenn sie gültig ist, dann kein Rückgabewert.
  1638. * Der Parameter db gibt an, ob überprüft werden soll, ob die eMail Adresse schon in der Datenbank eingetragen ist.
  1639. */
  1640. function checkemail($email, $db=0) {
  1641.     global $db_zugriff, $n, $multi_email, $banemail;
  1642.     if(!substr_count($email,"@") || substr_count($email,"@")>1) return 1;
  1643.     $position1 = strrpos($email,"@");
  1644.     if(!$position1) return 1;
  1645.     $position2 = strrpos($email,".");
  1646.     if(!$position2) return 1;
  1647.     if(strlen(substr($email, $position2)) < 3)return 1;
  1648.     if(strlen(substr($email, $position1,$position2-$position1-1))<2) return 1;
  1649.     if(!$multi_email && !$db) {
  1650.         $check = $db_zugriff->query_first("SELECT COUNT(userid) FROM bb".$n."_user_table WHERE useremail = '$email'");
  1651.         if($check[0]) return 1;
  1652.     }
  1653.     $banemail = @explode("\n",$banemail);
  1654.     for($i = 0; $i < count($banemail); $i++) {
  1655.         if(!trim($banemail[$i])) continue;
  1656.         if(ereg("\*", $banemail[$i])) {
  1657.             $banemail[$i] = str_replace("*",".*", trim($banemail[$i]));
  1658.             if(eregi("$banemail[$i]", $email)) return 1;
  1659.             break;
  1660.         }
  1661.         elseif(strtolower($email)==strtolower(trim($banemail[$i]))) {
  1662.             return 1;
  1663.             break;
  1664.         }  
  1665.     }
  1666. }
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675. /**
  1676. * @return result int
  1677. * @param name string
  1678. * @desc Überprüft einen Benutzernamen auf seine Gültigkeit.
  1679. * Wenn der Benutzername verboten ist oder schon in Benutzun ist, wird 1 zurückgegeben.
  1680. * Ansonsten ist der Rückgabewert 0
  1681. */
  1682. function checkname($name) {
  1683.    
  1684.     global $db_zugriff, $n, $banname;
  1685.     $bannames = explode("\r\n", trim($banname));
  1686.     for($i=0;$i<count($bannames);$i++) {
  1687.      $bannames[$i] = trim($bannames[$i]);
  1688.      if(!$bannames[$i]) continue;
  1689.      if($name==$bannames[$i]) return 1;
  1690.     }
  1691.     $check = $db_zugriff->query_first("SELECT COUNT(userid) FROM bb".$n."_user_table WHERE username = '".addslashes(htmlspecialchars($name))."'");
  1692.     return $check[0];
  1693. }
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701. /**
  1702. * @return result int
  1703. * @param userid int
  1704. * @param password string
  1705. * @desc Überprüft die gültigkeit einer userid-passwort kombination.
  1706. * Wenn die Daten korrekt sind, wird 1 zurückgegeben, ansonsten 0
  1707. */
  1708. function checkpw($userid,$password) {
  1709.  
  1710.     global $db_zugriff, $n;
  1711.     $check = $db_zugriff->query_first("SELECT COUNT(userid) FROM bb".$n."_user_table WHERE userid = '$userid' AND userpassword = '$password'");
  1712.     return $check[0];
  1713. }
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719. /**
  1720. * @return avatar string
  1721. * @param avatarid int
  1722. * @desc Gibt den Pfad zu dem Avatar mit der Id id zurück.
  1723. */
  1724. function getAvatar($id) {
  1725.     global $db_zugriff, $n;
  1726.     $result = $db_zugriff->query_first("SELECT extension FROM bb".$n."_avatars WHERE id = '$id'");
  1727.     return "images/avatars/avatar-".$id.".".$result['extension'];
  1728. }
  1729.  
  1730.  
  1731.  
  1732.  
  1733. /**
  1734. * @return text string
  1735. * @param text string
  1736. * @param width=75 int
  1737. * @desc fügt nach width Zeichen einen Zeilenumbruch in text ein.
  1738. */
  1739. function nt_wordwrap($text, $width = 75) {
  1740.          if($text) return preg_replace("/([^\n\r ?&\.\/<>\"\\-]{".$width."})/i"," \\1\n",$text);
  1741. }
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748. /**
  1749. * @return page_link string
  1750. * @param link string
  1751. * @param page int
  1752. * @param pages int
  1753. * @desc Generiert Links zu weiteren Seiten eines Themas.
  1754. */
  1755. function makepagelink($link, $page, $pages) {
  1756.     $page_link = "<b>[";
  1757.     if($page!=1) $page_link .= "&nbsp;&nbsp;<a href=\"$link&page=1\">&laquo;</a>&nbsp;&nbsp;<a href=\"$link&page=".($page-1)."\">‹</a>";
  1758.     if($page>=6) $page_link .= "&nbsp;&nbsp;<a href=\"$link&page=".($page-5)."\">...</a>";
  1759.     if($page+4>=$pages) $pagex=$pages;
  1760.     else $pagex=$page+4;
  1761.     for($i=$page-4 ; $i<=$pagex ; $i++) {  
  1762.         if($i<=0) $i=1;
  1763.         if($i==$page) $page_link .= "&nbsp;&nbsp;$i";
  1764.         else $page_link .= "&nbsp;&nbsp;<a href=\"$link&page=$i\">$i</a>";
  1765.     }
  1766.     if(($pages-$page)>=5) $page_link .= "&nbsp;&nbsp;<a href=\"$link&page=".($page+5)."\">...</a>";
  1767.     if($page!=$pages) $page_link .= "&nbsp;&nbsp;<a href=\"$link&page=".($page+1)."\">›</a>&nbsp;&nbsp;<a href=\"$link&page=".$pages."\">&raquo;</a>";
  1768.     $page_link .= "&nbsp;&nbsp;]</b>";
  1769.  
  1770.     return $page_link;
  1771. }
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777. /**
  1778. * @return result int
  1779. * @param user_id int
  1780. * @desc Überprüft, ob ein Benutzer innerhalb der Floodcontrol Zeit schon einen Beitrag erstellt hat.
  1781. * Wenn ja ist der Rückgabewert größer 0. Ansonsten 0.
  1782. */
  1783. function floodcontrol($user_id) {
  1784.     global $fctime, $db_zugriff, $n;
  1785.     $check_time = time()-$fctime;
  1786.     $result = $db_zugriff->query_first("SELECT COUNT(postid) FROM bb".$n."_posts WHERE userid = '$user_id' AND posttime > '$check_time'");
  1787.     return $result[0];
  1788. }
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795. /**
  1796. * @return out string
  1797. * @param boardid int
  1798. * @param depth=1 int
  1799. * @param subscripe=0 int
  1800. * @desc Generiert für die Startseite bzw. die unterforen in der board.php die Boardzeilen.
  1801. * ziemlich kompliziert das ganze ;)
  1802. */
  1803. function makeforumbit($boardid,$depth=1,$subscripe=0) {
  1804.   global $db_zugriff, $n, $show_subboards, $boardcache, $permissioncache, $modcache, $forumhomedepth, $session, $old_time, $user_group, $longdateformat;
  1805.  
  1806.   if ( !isset($boardcache[$boardid]) ) {
  1807.     return;
  1808.   }
  1809.     $out = "";
  1810.   while ( list($key1,$val1)=each($boardcache[$boardid]) ) {
  1811.     while ( list($key2,$boards)=each($val1) ) {
  1812.     $delboard = "";
  1813.     if($subscripe) eval ("\$delboard = \"".gettemplate("profile_subscripe_delboard")."\";");
  1814.     if($boards['invisible'] && !$permissioncache[$boards['boardid']]) continue;
  1815.     if($boards['isboard']) { //board
  1816.         if($depth==2 && $show_subboards==1) {
  1817.             $subboards=getSubboards($boards['boardid']);
  1818.             if($subboards) $subboards=ifelse($boards['descriptiontext'],"<br>","")."Inklusive: ".substr($subboards, 0, -2);
  1819.         }
  1820.         #$boards['descriptiontext'] = editDBdata($boards['descriptiontext']);
  1821.         #$boards[boardname] = editDBdata($boards[boardname]);
  1822.         if($old_time <= $boards['lastposttime']) eval ("\$on_or_off = \"".gettemplate("main_newposts")."\";");
  1823.         else eval ("\$on_or_off = \"".gettemplate("main_nonewposts")."\";");
  1824.    
  1825.         if($boards['lastpostid']) {
  1826.             $lastposttime = formatdate($boards['posttime'],$longdateformat,1);
  1827.             if($boards['userid']) $lastauthor = "<a href=\"members.php?mode=profile&userid=".$boards['userid'].$session."\">".($boards['username'])."</a>";
  1828.             else eval ("\$lastauthor = \"".gettemplate("lg_anonymous")."\";");
  1829.             $boards['threadname'] = prepare_topic($boards['threadname']);
  1830.             if (!$boards['topicicon']) $ViewPosticon = "<img src=\"images/icons/noicon.gif\">";
  1831.             else $ViewPosticon = "<img src=\"$boards[topicicon]\">";
  1832.             if (isset($permissioncache[$boards['boardid']]) && $permissioncache[$boards['boardid']]) $template="main_lastpost";
  1833.             else $template="main_lastpost2";
  1834.             if (strlen($boards['threadname']) > '30') $ViewThreadname = substr($boards['threadname'], 0, 27)."...";
  1835.                 else $ViewThreadname = $boards['threadname'];
  1836.                 eval ("\$last_post = \"".gettemplate("$template")."\";");
  1837.         }
  1838.         else $last_post = "&nbsp;";
  1839.        
  1840.         $moderators = "";
  1841.         if(isset($modcache[$boards['boardid']])) {
  1842.             while (list($mkey,$moderator)=each($modcache[$boards['boardid']])) {
  1843.                         if ($moderators) $moderators .= ", ";
  1844.                         $moderators .= "<a href=\"members.php?mode=profile&userid=".$moderator['userid'].$session."\">".($moderator['username'])."</a>";
  1845.             }
  1846.         }
  1847.         eval ("\$out .= \"".gettemplate("main_boardbit$depth")."\";");
  1848.         unset($moderators);
  1849.        
  1850.     }
  1851.     else { //cat
  1852.         if($depth==2 && $show_subboards==1) {
  1853.             $subboards=getSubboards($boards['boardid']);
  1854.             if($subboards) $subboards=ifelse($boards['descriptiontext'],"<br>","")."Inklusive: ".substr($subboards, 0, -2);
  1855.         }
  1856.         #$boards['descriptiontext'] = editDBdata($boards['descriptiontext']);
  1857.         #$boards['boardname'] = editDBdata($boards['boardname']);
  1858.         eval ("\$out .= \"".gettemplate("main_catbit$depth")."\";");
  1859.     }
  1860.         if ($depth<2) {
  1861.           $out.=makeforumbit($boards['boardid'],$depth+1,$subscripe);
  1862.         }
  1863.     }
  1864.   }
  1865.   unset($boardcache[$boardid]);
  1866.   return $out;
  1867. }
  1868.  
  1869.  
  1870.  
  1871. /**
  1872. * @return navichain string
  1873. * @param template string
  1874. * @param boardid int
  1875. * @param threadid=0 int
  1876. * @desc Generiert die sog. "Navichain"...
  1877. */
  1878. function makenavichain($template, $boardid, $threadid=0) {
  1879.     global $db_zugriff, $n, $session;
  1880.     if($template == "board") {
  1881.         $binfo = $db_zugriff->query_first("SELECT boardparentid, boardname FROM bb".$n."_boards WHERE boardid = '$boardid'");
  1882.         $result['boardparentid'] = $binfo['boardparentid'];
  1883.     }
  1884.     else $result['boardparentid'] = $boardid;
  1885.     eval ("\$split = \"".gettemplate("navi_split")."\";");
  1886.     $out = "";
  1887.     do {
  1888.         $result = $db_zugriff->query_first("SELECT boardid, boardparentid, boardname FROM bb".$n."_boards WHERE boardid = '$result[boardparentid]'");  
  1889.         if(!$result['boardid']) break;
  1890.         $out = $split."<a href=\"board.php?boardid=$result[boardid]$session\">".$result['boardname']."</a>".$out;  
  1891.     }
  1892.     while($result['boardparentid']!=0);
  1893.    
  1894.     if($threadid) {
  1895.         $tinfo = $db_zugriff->query_first("SELECT threadname FROM bb".$n."_threads WHERE threadid = '$threadid'");
  1896.         $tinfo['threadname'] = prepare_topic($tinfo['threadname']);
  1897.     }
  1898.     eval ("\$ende = \"".gettemplate("navi_".$template)."\";");
  1899.     return $out.$ende;
  1900. }
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906. /**
  1907. * @return month_name string
  1908. * @param month_number int
  1909. * @desc Gibt den Monatsnamen zu einer Monatszahl zurück.
  1910. */
  1911. function get_month_name($month_number) {
  1912.     $name_monat[1]    =  "Januar";  
  1913.     $name_monat[2]    =  "Februar";  
  1914.     $name_monat[3]    =  "M&auml;rz";  
  1915.     $name_monat[4]    =  "April";  
  1916.     $name_monat[5]    =  "Mai";  
  1917.     $name_monat[6]    =  "Juni";  
  1918.     $name_monat[7]    =  "Juli";  
  1919.     $name_monat[8]    =  "August";  
  1920.     $name_monat[9]    =  "September";  
  1921.     $name_monat[10]  =  "Oktober";  
  1922.     $name_monat[11]  =  "November";  
  1923.     $name_monat[12]  =  "Dezember";
  1924.    
  1925.     return $name_monat[$month_number];
  1926. }
  1927.  
  1928.  
  1929.  
  1930.  
  1931.  
  1932. /**
  1933. * @return url string
  1934. * @param url string
  1935. * @desc Hängt http:// vor eine Url, wenn es noch nicht vorhanden ist.
  1936. */
  1937. function editURL($url) {
  1938.         if(strtolower(substr($url,0,7))!="http://") $url="http://".$url;
  1939.         return $url;
  1940. }
  1941.  
  1942.  
  1943.  
  1944.  
  1945.  
  1946. /**
  1947. * @return out string
  1948. * @param out string
  1949. * @desc Ersetzt in out alle bbcodes..
  1950. */
  1951. function prepare_code($out) {
  1952.  global $db_zugriff,$n,$searcharray,$replacearray;
  1953.  $phpversionnum = phpversion();
  1954.  
  1955.  if(!isset($searcharray) && !isset($replacearray)) {
  1956.   $searcharray[]="/\[list=(['\"]?)([^\"']*)\\1](.*)\[\/list((=\\1[^\"']*\\1])|(\]))/esiU";
  1957.   $replacearray[]="formatlist('\\3', '\\2')";
  1958.   $searcharray[]="/\[list](.*)\[\/list\]/esiU";
  1959.   $replacearray[]="formatlist('\\1')";
  1960.   $searcharray[]="/\[url=(['\"]?)([^\"']*)\\1](.*)\[\/url\]/esiU";
  1961.   $replacearray[]="formaturl('\\2','\\3')";
  1962.   $searcharray[]="/\[url]([^\"]*)\[\/url\]/esiU";  
  1963.   $replacearray[]="formaturl('\\1')";
  1964.   $searcharray[]="/\[code](.*)\[\/code\]/esiU";
  1965.   $replacearray[]="formatcodetag('\\1')";
  1966.   $searcharray[]="/\[php](.*)\[\/php\]/esiU";  
  1967.   $replacearray[]="phphighlite('\\1')";
  1968.   $searcharray[]="/\[img]([^\"]*)\[\/img\]/siU";   
  1969.   $replacearray[]="<img src=\"\\1\" border=0>";
  1970.  
  1971.   $threeparams = "/\[%s=(['\"]?)([^\"']*),([^\"']*)\\1](.*)\[\/%s\]/siU";
  1972.   $twoparams = "/\[%s=(['\"]?)([^\"']*)\\1](.*)\[\/%s\]/siU";
  1973.   $oneparam = "/\[%s](.*)\[\/%s\]/siU";
  1974.  
  1975.   $result = $db_zugriff->query("SELECT bbcodetag,bbcodereplace,params FROM bb".$n."_bbcode");
  1976.  
  1977.   while($row = $db_zugriff->fetch_array($result)) {
  1978.    if($row['params']==0) continue;
  1979.    if($row['params']==1) $search = sprintf($oneparam, $row['bbcodetag'], $row['bbcodetag']);
  1980.    if($row['params']==2) $search = sprintf($twoparams, $row['bbcodetag'], $row['bbcodetag']);
  1981.    if($row['params']==3) $search = sprintf($threeparams, $row['bbcodetag'], $row['bbcodetag']);
  1982.  
  1983.     for($i=0;$i<7;$i++) { // Verschachtelungstiefe
  1984.    $searcharray[] = $search;
  1985.    $replacearray[] = $row['bbcodereplace']; }
  1986.   }
  1987.  }
  1988.  
  1989.  if ($phpversionnum<"4.0.5") $bbcode=str_replace("'", "\'", $out);
  1990.  $out = preg_replace($searcharray, $replacearray, $out);
  1991.  $out = str_replace("\\'", "'", $out);
  1992.  return $out;
  1993. }
  1994.  
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001. /**
  2002. * @return links string
  2003. * @param boardid int
  2004. * @desc Gibt Links (per , getrennt) zu den Unterforen eines Boards zurück.
  2005. */
  2006. function getSubboards($boardid) {
  2007.     global $boardcache,$session;
  2008.  
  2009.     if (!isset($boardcache[$boardid])) return;
  2010.     if(!isset($subboards)) $subboards = "";
  2011.  
  2012.     while(list($key1,$val1)=each($boardcache[$boardid])) {
  2013.         while(list($key2,$boards)=each($val1)) {
  2014.             $subboards.="<a href=\"board.php?boardid=$boards[boardid]$session\">".($boards['boardname'])."</a>, ".getSubboards($boards['boardid'],$boards);
  2015.         }
  2016.     }
  2017.    
  2018.     return $subboards;
  2019. }
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026. /**
  2027. * @return rank string
  2028. * @param posts int
  2029. * @param groupid int
  2030. * @desc Ermittelt aus dem rankcache den Rang anhand von posts und groupid.
  2031. */
  2032. function getRank($posts,$groupid)
  2033. {
  2034.     global $rankcache;
  2035.     if(isset($rankcache[$groupid]) && count($rankcache[$groupid]))
  2036.     {
  2037.         for($i=0;$i<count($rankcache[$groupid]);$i++)
  2038.         {
  2039.             if($rankcache[$groupid][$i]['posts']==0)
  2040.             {
  2041.                 return $rankcache[$groupid][$i];
  2042.                 break;
  2043.             }
  2044.             elseif($posts/$rankcache[$groupid][$i]['posts']>=1)
  2045.             {
  2046.                 return $rankcache[$groupid][$i];
  2047.                 break;
  2048.             }
  2049.         }
  2050.     }
  2051. }
  2052.  
  2053.  
  2054.  
  2055.  
  2056. /**
  2057. * @return ipaddress string
  2058. * @desc Ermittelt die IP des Clienten und gibt sie zurück.
  2059. */
  2060. function getIpAddress() {
  2061.  $REMOTE_ADDR=getenv("REMOTE_ADDR");
  2062.  $HTTP_X_FORWARDED_FOR=getenv("HTTP_X_FORWARDED_FOR");
  2063.    
  2064.  if($HTTP_X_FORWARDED_FOR!="") {
  2065.   if(preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $HTTP_X_FORWARDED_FOR, $ip_match)) {
  2066.    $private_ip_list = array("/^0\./", "/^127\.0\.0\.1/", "/^192\.168\..*/", "/^172\.16\..*/", "/^10..*/", "/^224..*/", "/^240..*/");   
  2067.    $REMOTE_ADDR = preg_replace($private_ip_list, $REMOTE_ADDR, $ip_match[1]);  
  2068.   }
  2069.  }
  2070.  
  2071.  if(strlen($REMOTE_ADDR)>16) $REMOTE_ADDR=substr($REMOTE_ADDR, 0, 16);
  2072.  return $REMOTE_ADDR;
  2073. }
  2074. ?>
Advertisement
Add Comment
Please, Sign In to add comment