Просмотр файла includes/functions_validate.php

Размер файла: 4.31Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. function validate_username($username)
  7. {
  8. global $db, $lang, $userdata;
  9.  
  10. $username = preg_replace('#\s+#', ' ', trim($username));
  11. $username = phpbb_clean_username($username);
  12.  
  13. $sql = "SELECT username
  14. FROM " . USERS_TABLE . "
  15. WHERE LOWER(username) = '" . strtolower($username) . "'";
  16. if ($result = $db->sql_query($sql))
  17. {
  18. while ($row = $db->sql_fetchrow($result))
  19. {
  20. if (($userdata['session_logged_in'] && $row['username'] != $userdata['username']) || !$userdata['session_logged_in'])
  21. {
  22. $db->sql_freeresult($result);
  23. return array('error' => true, 'error_msg' => $lang['Username_taken']);
  24. }
  25. }
  26. }
  27. $db->sql_freeresult($result);
  28.  
  29. $sql = "SELECT group_name
  30. FROM " . GROUPS_TABLE . "
  31. WHERE LOWER(group_name) = '" . strtolower($username) . "'";
  32. if ($result = $db->sql_query($sql))
  33. {
  34. if ($row = $db->sql_fetchrow($result))
  35. {
  36. $db->sql_freeresult($result);
  37. return array('error' => true, 'error_msg' => $lang['Username_taken']);
  38. }
  39. }
  40. $db->sql_freeresult($result);
  41.  
  42. $sql = "SELECT disallow_username
  43. FROM " . DISALLOW_TABLE;
  44. if ($result = $db->sql_query($sql))
  45. {
  46. if ($row = $db->sql_fetchrow($result))
  47. {
  48. do
  49. {
  50. if (preg_match("#\b(" . str_replace("\*", ".*?", preg_quote($row['disallow_username'], '#')) . ")\b#i", $username))
  51. {
  52. $db->sql_freeresult($result);
  53. return array('error' => true, 'error_msg' => $lang['Username_disallowed']);
  54. }
  55. }
  56. while($row = $db->sql_fetchrow($result));
  57. }
  58. }
  59. $db->sql_freeresult($result);
  60.  
  61. $sql = "SELECT word
  62. FROM " . WORDS_TABLE;
  63. if ($result = $db->sql_query($sql))
  64. {
  65. if ($row = $db->sql_fetchrow($result))
  66. {
  67. do
  68. {
  69. if (preg_match("#\b(" . str_replace("\*", ".*?", preg_quote($row['word'], '#')) . ")\b#i", $username))
  70. {
  71. $db->sql_freeresult($result);
  72. return array('error' => true, 'error_msg' => $lang['Username_disallowed']);
  73. }
  74. }
  75. while ($row = $db->sql_fetchrow($result));
  76. }
  77. }
  78. $db->sql_freeresult($result);
  79.  
  80. if (strstr($username, '"') || strstr($username, '&quot;') || strstr($username, chr(160)) || strstr($username, chr(173)))
  81. {
  82. return array('error' => true, 'error_msg' => $lang['Username_invalid']);
  83. }
  84.  
  85. return array('error' => false, 'error_msg' => '');
  86. }
  87.  
  88.  
  89. function validate_email($email)
  90. {
  91. global $db, $lang;
  92.  
  93. if ($email != '')
  94. {
  95. if (preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*?[a-z]+$/is', $email))
  96. {
  97. $sql = "SELECT ban_email
  98. FROM " . BANLIST_TABLE;
  99. if ($result = $db->sql_query($sql))
  100. {
  101. if ($row = $db->sql_fetchrow($result))
  102. {
  103. do
  104. {
  105. $match_email = str_replace('*', '.*?', $row['ban_email']);
  106. if (preg_match('/^' . $match_email . '$/is', $email))
  107. {
  108. $db->sql_freeresult($result);
  109. return array('error' => true, 'error_msg' => $lang['Email_banned']);
  110. }
  111. }
  112. while($row = $db->sql_fetchrow($result));
  113. }
  114. }
  115. $db->sql_freeresult($result);
  116.  
  117. $sql = "SELECT user_email
  118. FROM " . USERS_TABLE . "
  119. WHERE user_email = '" . str_replace("\'", "''", $email) . "'";
  120. if (!($result = $db->sql_query($sql)))
  121. {
  122. message_die(GENERAL_ERROR, "Couldn't obtain user email information.", "", __LINE__, __FILE__, $sql);
  123. }
  124. if ($row = $db->sql_fetchrow($result))
  125. {
  126. return array('error' => true, 'error_msg' => $lang['Email_taken']);
  127. }
  128. $db->sql_freeresult($result);
  129.  
  130. return array('error' => false, 'error_msg' => '');
  131. }
  132. }
  133.  
  134. return array('error' => true, 'error_msg' => $lang['Email_invalid']);
  135. }
  136.  
  137.  
  138. function validate_optional_fields(&$icq, &$aim, &$msnm, &$yim, &$website, &$location, &$occupation, &$interests)
  139. {
  140. $check_var_length = array('aim', 'msnm', 'yim', 'location', 'occupation', 'interests');
  141.  
  142. for($i = 0; $i < count($check_var_length); $i++)
  143. {
  144. if (strlen($$check_var_length[$i]) < 2)
  145. {
  146. $$check_var_length[$i] = '';
  147. }
  148. }
  149.  
  150. if (!preg_match('/^[0-9]+$/', $icq))
  151. {
  152. $icq = '';
  153. }
  154.  
  155. if ($website != "")
  156. {
  157. if (!preg_match('#^http[s]?:\/\/#i', $website))
  158. {
  159. $website = 'http://' . $website;
  160. }
  161.  
  162. if (!preg_match('#^http[s]?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $website))
  163. {
  164. $website = '';
  165. }
  166. }
  167.  
  168. return;
  169. }
  170.  
  171. ?>