Файл: mob-site/mods/pages/classes/validate.class.php
Строк: 35
<?php
class validate{
    
    private $db;
    
   public function __construct(){
       $this->db = Simple::openDB();
       $this->db->query("SET NAMES utf8");
   }
     
   public function addFriends($name,$http,$secret){
       try{
           if($secret!=$_SESSION['secret'])
               throw new Exception("Введён неверный проверочный код!");
           
           $http = 'http://'.$http;
           if(!preg_match('/^(http://|https://)?([^./]+.)*([a-zA-Z0-9])([a-zA-Z0-9-]*).([a-zA-Z]{2,4})(/.*)?$/i',$http))
                   throw new Exception("Неверный адрес сайта!");
           
           if(Simple::strlen($name)<3 || Simple::strlen($name)>50)
               throw new Exception("Название сайта не может быть менее 3 и не более 50 символов!");
           
           $name = Simple::ClearDataDB($name);
           $http = Simple::ClearDataDB($http);
           
           $sql_2 = "SELECT * FROM `friends` WHERE `http` = '".$http."'";
           $res = $this->db->query($sql_2);
           $num = $res->num_rows;
           
           if($num>0)
               throw new Exception("Такой сайт уже есть у нас!");
           
           
           $sql = "INSERT INTO `friends` SET
               `name` = '".$name."',
                   `http` = '".$http."'";
           
           if(!$this->db->query($sql))
               throw new Exception("Не удалось добавить сайт! Обратитесь к администратору!");
           
   }catch(Exception $e){
       Simple::redirect("index.php?mod=pages&a=friends", $e->getMessage());
   }
   }
   
   
}
?>