Просмотр файла functions.php

Размер файла: 7.64Kb
  1. <?php
  2. include_once("connect.php");
  3. include_once("config.php");
  4.  
  5. function ban($username, $ua, $ip)
  6. {
  7. global $modername, $banmess;
  8. $query = mysql_query("SELECT * FROM `ban`
  9. WHERE `user`='".$ua."'
  10. OR `ip`='".$ip."'
  11. OR `username`='".$username."'
  12. AND `time` > UNIX_TIMESTAMP()");
  13. if(mysql_num_rows($query))
  14. {
  15. $rows = mysql_fetch_array($query);
  16. $modername = $rows['moder'];
  17. $banmess = $rows['mess'];
  18. return( true );
  19. }
  20. else
  21. {
  22. return ( false );
  23. }
  24. }
  25.  
  26. function translate($mess)
  27. {
  28. $array = array(
  29. "Jo" => "Ё",
  30. "jo" => "ё",
  31. "Yo" => "Ё",
  32. "yo" => "ё",
  33. "Zh" => "Ж",
  34. "zh" => "ж",
  35. "*" => "ж",
  36. "Ch" => "Ч",
  37. "ch" => "ч",
  38. "Sh" => "Ш",
  39. "sh" => "ш",
  40. "Shc" => "Щ",
  41. "shc" => "щ",
  42. "''" => 'ъ',
  43. "'" => "ь",
  44. "Ye" => "Э",
  45. "ye" => "э",
  46. "Yu" => "Ю",
  47. "yu" => "ю",
  48. "Ya" => "Я",
  49. "ya" => "я",
  50. "X" => "Ы",
  51. "x" => "ы",
  52. "A" => "А",
  53. "a" => "а",
  54. "B" => "Б",
  55. "b" => "б",
  56. "C" => "Ц",
  57. "c" => "ц",
  58. "D" => "Д",
  59. "d" => "д",
  60. "E" => "Е",
  61. "e" => "е",
  62. "F" => "Ф",
  63. "f" => "ф",
  64. "G" => "Г",
  65. "g" => "г",
  66. "H" => "Х",
  67. "h" => "х",
  68. "I" => "И",
  69. "i" => "и",
  70. "K" => "К",
  71. "k" => "к",
  72. "L" => "Л",
  73. "l" => "л",
  74. "M" => "М",
  75. "m" => "м",
  76. "N" => "Н",
  77. "n" => "н",
  78. "O" => "О",
  79. "o" => "о",
  80. "P" => "П",
  81. "p" => "п",
  82. "Q" => "Ь",
  83. "q" => "ь",
  84. "R" => "Р",
  85. "r" => "р",
  86. "S" => "С",
  87. "s" => "с",
  88. "T" => "Т",
  89. "t" => "т",
  90. "U" => "У",
  91. "u" => "у",
  92. "V" => "В",
  93. "v" => "в",
  94. "W" => "Ш",
  95. "w" => "ш",
  96. "Y" => "Й",
  97. "y" => "й",
  98. "Z" => "З",
  99. "z" => "з"
  100. );
  101. return (strtr($mess, $array));
  102. }
  103.  
  104. function smile($matches)
  105. {
  106. static $c;
  107. $arr = array('&lt;1&gt;',
  108. '&lt;2&gt;',
  109. '&lt;3&gt;',
  110. '&lt;4&gt;',
  111. '&lt;5&gt;',
  112. '&lt;6&gt;',
  113. '&lt;7&gt;',
  114. '&lt;8&gt;',
  115. '&lt;9&gt;',
  116. '&lt;10&gt;',
  117. '&lt;11&gt;',
  118. '&lt;12&gt;',
  119. '&lt;13&gt;',
  120. '&lt;14&gt;',
  121. '&lt;15&gt;',
  122. '&lt;16&gt;',
  123. '&lt;17&gt;',
  124. '&lt;18&gt;',
  125. '&lt;19&gt;',
  126. '&lt;20&gt;',
  127. '&lt;21&gt;',
  128. '&lt;22&gt;',
  129. '&lt;23&gt;',
  130. '&lt;24&gt;',
  131. '&lt;25&gt;',
  132. '&lt;26&gt;',
  133. '&lt;27&gt;',
  134. '&lt;28&gt;',
  135. '&lt;29&gt;',
  136. '&lt;30&gt;',
  137. '&lt;31&gt;',
  138. '&lt;32&gt;',
  139. '&lt;33&gt;',
  140. '&lt;34&gt;',
  141. '&lt;35&gt;',
  142. '&lt;36&gt;',
  143. '&lt;37&gt;',
  144. '&lt;38&gt;'
  145. );
  146. if($c == 1) return $matches[0];
  147. if(!in_array($matches[0], $arr)) return $matches[0];
  148.  
  149. $c++;
  150.  
  151. $smiles = array(
  152. '<img src="smiles/1.gif" alt=":-)" />',
  153. '<img src="smiles/2.gif" alt=":-(" />',
  154. '<img src="smiles/3.gif" alt=":-[" />',
  155. '<img src="smiles/4.gif" alt="8-)" />',
  156. '<img src="smiles/5.gif" alt=":-E)" />',
  157. '<img src="smiles/6.gif" alt=":-P" />',
  158. '<img src="smiles/7.gif" alt="{beer}" />',
  159. '<img src="smiles/8.gif" alt="{tee}" />',
  160. '<img src="smiles/9.gif" alt="{smoke}" />',
  161. '<img src="smiles/10.gif" alt="{vine}" />',
  162. '<img src="smiles/11.gif" alt="{kiss}" />',
  163. '<img src="smiles/12.gif" alt="{heard}" />',
  164. '<img src="smiles/13.gif" alt="" />',
  165. '<img src="smiles/14.gif" alt="{ok}" />',
  166. '<img src="smiles/15.gif" alt="{no}" />',
  167. '<img src="smiles/16.gif" alt="{cool}" />',
  168. '<img src="smiles/17.gif" alt="{flower}" />',
  169. '<img src="smiles/18.gif" alt="{cherry}" />',
  170. '<img src="smiles/19.gif" alt="{ball}" />',
  171. '<img src="smiles/20.gif" alt="{surprise}" />',
  172. '<img src="smiles/21.gif" alt="{cake}" />',
  173. '<img src="smiles/22.gif" alt="{phone}" />',
  174. '<img src="smiles/23.gif" alt="{mobile}" />',
  175. '<img src="smiles/24.gif" alt="{wall}" />',
  176. '<img src="smiles/25.gif" alt="{camel}" />',
  177. '<img src="smiles/26.gif" alt="{cat}" />',
  178. '<img src="smiles/27.gif" alt="{pig}" />',
  179. '<img src="smiles/28.gif" alt="{hammer}" />',
  180. '<img src="smiles/29.gif" alt="{gun}" />',
  181. '<img src="smiles/30.gif" alt="{skull}" />',
  182. '<img src="smiles/31.gif" alt="{rip}" />',
  183. '<img src="smiles/32.gif" alt="{sun}" />',
  184. '<img src="smiles/33.gif" alt="{moon}" />',
  185. '<img src="smiles/34.gif" alt="{lock}" />',
  186. '<img src="smiles/35.gif" alt="{dollar}" />',
  187. '<img src="smiles/36.gif" alt="{fig}" />',
  188. '<img src="smiles/37.gif" alt="{drug}" />',
  189. '<img src="smiles/38.gif" alt="{fuck}" />'
  190. );
  191.  
  192. return str_replace($arr, $smiles, $matches[0]);
  193. }
  194.  
  195. function username2id($username)
  196. {
  197. $id = mysql_fetch_array(mysql_query("SELECT id FROM users WHERE username='".$username."'"));
  198. return( $id['id'] );
  199. }
  200.  
  201. function ClearOnline()
  202. {
  203. mysql_query("DELETE FROM session WHERE time < ".(time() - (24 * 60 * 60)));
  204. }
  205.  
  206. function RefreshLastTime($username, $fid, $lastMsgTime)
  207. {
  208. mysql_query("UPDATE `counter` SET `time`=".($lastMsgTime)." WHERE `fid`=".$fid." AND `username`='".$username."'");
  209. }
  210.  
  211. function mRefreshLastTime($username, $fid, $lastMsgTime)
  212. {
  213. mysql_query("UPDATE `mcounter` SET `time`=".($lastMsgTime)." WHERE `fid`=".$fid." AND `username`='".$username."'");
  214. }
  215.  
  216.  
  217. function RefreshSid($username)
  218. {
  219. mysql_query("UPDATE `session` SET `time`=".time()." WHERE `nickname`='".$username."'");
  220. mysql_query("UPDATE `users` SET `last_time`=".time()." WHERE `username`='".$username."'");
  221. }
  222.  
  223. function topic2post($id_topic)
  224. {
  225. return(mysql_result(mysql_query("SELECT MIN(`id`) FROM `posts` WHERE `id_theme`=".$id_topic), 0));
  226. }
  227. function topic2postm($id_topic)
  228. {
  229. return(mysql_result(mysql_query("SELECT MIN(`id`) FROM `mposts` WHERE `id_theme`=".$id_topic), 0));
  230. }
  231. function is_author($id, $user)
  232. {
  233. if(mysql_result(mysql_query("SELECT COUNT(*) FROM `themes` WHERE `id`=".$id." AND `name`='".$user."'"), 0))
  234. {
  235. return(true);
  236. }
  237. else
  238. {
  239. return(false);
  240. }
  241. }
  242.  
  243. function sql($str)
  244. {
  245. if(get_magic_quotes_gpc())
  246. {
  247. $str = stripslashes($str);
  248. }
  249. return(str_replace("$", "&#36;", mysql_escape_string($str)));
  250. }
  251. function cutString($string, $len)
  252. {
  253. if (strlen($string) <= $len)
  254. {
  255. return $string;
  256. }
  257. return substr($string, 0, $len) . "....";
  258. }
  259. function translatenick($username)
  260. {
  261. $array = array(
  262. "Е" => "E",
  263. "е" => "e",
  264. "А" => "A",
  265. "а" => "a",
  266. "В" => "B",
  267. "С" => "C",
  268. "с" => "c",
  269. "Н" => "H",
  270. "Х" => "X",
  271. "К" => "K",
  272. "М" => "M",
  273. "О" => "O",
  274. "о" => "o",
  275. "Р" => "P",
  276. "р" => "p",
  277. "Т" => "T",
  278. "у" => "y"
  279. );
  280. return (strtr($username, $array));
  281. }
  282. $ua=$_SERVER['HTTP_USER_AGENT'];
  283. $ip=$_SERVER['REMOTE_ADDR'];
  284. $uniq=serialize(array($ip,$ua))."\n";
  285. $store='./count/count.dat';
  286. $offset=3600;
  287. $date_now=date('d',time()+$offset);
  288. $date_access=date('d',filemtime($store)+$offset);
  289. if ($date_now!=$date_access && file_exists($store))
  290. {
  291. unlink($store);
  292. }
  293. if (!file_exists($store))
  294. {
  295. $hit=1;
  296. $host=1;
  297. }
  298. else
  299. {
  300. $data=file($store);
  301. $data[]=$uniq;
  302. $hit=count($data);
  303. $ip_ua=array();
  304. $ip_ua[]=$uniq;
  305. foreach ($data as $v)
  306. {
  307. if (!in_array($v,$ip_ua))
  308. $ip_ua[]=$v;
  309. }
  310.  
  311. $host=count($ip_ua);
  312. }
  313. $f=fopen($store,'a+');
  314. flock($f,2);
  315. fwrite($f,$uniq);
  316. fclose($f);
  317. $_GET['p']=intval($_GET['p']);
  318. /// "//" replase "/"
  319. /*function e ($e){
  320. $e = str_replace("//", "/", $e);
  321. return $e;
  322. }
  323. ob_start ("e");*/
  324. ?>