1
0

functions.common.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /* $Id: functions.common.php 2835 2007-04-08 13:20:05Z b4rt $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /*
  16. * auth
  17. */
  18. require_once("inc/functions/functions.common.auth.php");
  19. /*
  20. * cookie
  21. */
  22. require_once("inc/functions/functions.common.cookie.php");
  23. /*
  24. * language
  25. */
  26. require_once("inc/functions/functions.common.language.php");
  27. /*
  28. * message
  29. */
  30. require_once("inc/functions/functions.common.message.php");
  31. /*
  32. * settings
  33. */
  34. require_once("inc/functions/functions.common.settings.php");
  35. /*
  36. * theme
  37. */
  38. require_once("inc/functions/functions.common.theme.php");
  39. /*
  40. * tmpl
  41. */
  42. require_once("inc/functions/functions.common.tmpl.php");
  43. /*
  44. * transfer
  45. */
  46. require_once("inc/functions/functions.common.transfer.php");
  47. /*
  48. * trprofile
  49. */
  50. require_once("inc/functions/functions.common.trprofile.php");
  51. /*
  52. * user
  53. */
  54. require_once("inc/functions/functions.common.user.php");
  55. /**
  56. * GetActivityCount
  57. *
  58. * @param $user
  59. * @return int
  60. */
  61. function GetActivityCount($user="") {
  62. global $cfg, $db;
  63. $count = 0;
  64. $for_user = ($user != "") ? "user_id=".$db->qstr($user)." AND " : "";
  65. $sql = "SELECT count(*) FROM tf_log WHERE ".$for_user."(action=".$db->qstr($cfg["constants"]["file_upload"])." OR action=".$db->qstr($cfg["constants"]["url_upload"]).")";
  66. $count = $db->GetOne($sql);
  67. return $count;
  68. }
  69. /**
  70. * get File
  71. *
  72. * @param $var
  73. * @return boolean
  74. */
  75. function getFile($var) {
  76. return ($var < 65535);
  77. }
  78. /**
  79. * checks main-directories.
  80. *
  81. * @return boolean
  82. */
  83. function checkMainDirectories() {
  84. global $cfg;
  85. // main-path
  86. if (!checkDirectory($cfg["path"]))
  87. @error("Main-Path does not exist and cannot be created or is not writable", "admin.php?op=serverSettings", "Server-Settings", array("path : ".$cfg["path"]));
  88. // transfer-path
  89. if (!checkDirectory($cfg["transfer_file_path"]))
  90. @error("Transfer-File-Path does not exist and cannot be created or is not writable", "admin.php?op=serverSettings", "Server-Settings", array("transfer_file_path : ".$cfg["transfer_file_path"]));
  91. }
  92. /**
  93. * Removes HTML from Messages
  94. *
  95. * @param $str
  96. * @param $strip
  97. * @return string
  98. */
  99. function check_html ($str, $strip="") {
  100. /* The core of this code has been lifted from phpslash */
  101. /* which is licenced under the GPL. */
  102. if ($strip == "nohtml")
  103. $AllowableHTML = array('');
  104. $str = stripslashes($str);
  105. $str = preg_replace("/<[[:space:]]*([^>]*)[[:space:]]*>/i",'<\\1>', $str);
  106. // Delete all spaces from html tags .
  107. $str = preg_replace("/<a[^>]*href[[:space:]]*=[[:space:]]*\"?[[:space:]]*([^\" >]*)[[:space:]]*\"?[^>]*>/i",'<a href="\\1">', $str);
  108. // Delete all attribs from Anchor, except an href, double quoted.
  109. $str = preg_replace("/<[[:space:]]* img[[:space:]]*([^>]*)[[:space:]]*>/i", '', $str);
  110. // Delete all img tags
  111. $str = preg_replace("/<a[^>]*href[[:space:]]*=[[:space:]]*\"?javascript[[:punct:]]*\"?[^>]*>/i", '', $str);
  112. // Delete javascript code from a href tags -- Zhen-Xjell @ http://nukecops.com
  113. $tmp = "";
  114. while (preg_match("/<(/?[[:alpha:]]*)[[:space:]]*([^>]*)>/",$str,$reg)) {
  115. $i = strpos($str,$reg[0]);
  116. $l = strlen($reg[0]);
  117. $tag = ($reg[1][0] == "/") ? strtolower(substr($reg[1],1)) : strtolower($reg[1]);
  118. if ($a = $AllowableHTML[$tag]) {
  119. if ($reg[1][0] == "/") {
  120. $tag = "</$tag>";
  121. } elseif (($a == 1) || ($reg[2] == "")) {
  122. $tag = "<$tag>";
  123. } else {
  124. # Place here the double quote fix function.
  125. $attrb_list=delQuotes($reg[2]);
  126. // A VER
  127. $attrb_list = preg_replace("/&/","&amp;",$attrb_list);
  128. $tag = "<$tag" . $attrb_list . ">";
  129. } # Attribs in tag allowed
  130. } else {
  131. $tag = "";
  132. }
  133. $tmp .= substr($str,0,$i) . $tag;
  134. $str = substr($str,$i+$l);
  135. }
  136. $str = $tmp . $str;
  137. // parse for strings starting with http:// and subst em with hyperlinks.
  138. if ($strip != "nohtml") {
  139. global $cfg;
  140. $str = ($cfg["enable_dereferrer"] != 0)
  141. ? preg_replace('/(http:\/\/)(.*)([[:space:]]*)/i', '<a href="index.php?iid=dereferrer&u=${1}${2}" target="_blank">${1}${2}</a>${3}', $str)
  142. : preg_replace('/(http:\/\/)(.*)([[:space:]]*)/i', '<a href="${1}${2}" target="_blank">${1}${2}</a>${3}', $str);
  143. }
  144. return $str;
  145. }
  146. /**
  147. * sendLine - sends a line to the browser
  148. */
  149. function sendLine($line = "") {
  150. echo $line;
  151. echo str_pad('',4096)."\n";
  152. @ob_flush();
  153. @flush();
  154. }
  155. ?>