<commit_before><?php

namespace common\components;

use common\models\_base\CameraBase;
use common\models\Recorder;
use frontend\models\Camera;

class Common
{
    public static function validatePhone($phone) {
        $phone = trim($phone);
        if(strpos($phone,"84")===0){
            $phone = "0".substr($phone,"2");
        }else if(strpos($phone,"0")!==0){
            $phone = "0".$phone;
        }
        $pattern = "/^(089|086|088|090|091|092|093|094|095|096|097|098|099|0121|0122|0123|0124|0125|0126|0127|0128|0129|0121|0120||0161|0162|0163|0164|0165|0166|0167|0168|0169)([0-9]{7})$/";
        return preg_match($pattern,$phone);
    }

    public static function validateEmail($email){
        $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";

        if (eregi($pattern, $email)){
            return true;
        }
        else {
            return false;
        }
    }

    public static function getLinkStream($camera_id){
        $camera_model = CameraBase::findOne($camera_id);
        $recorder_model = Recorder::findOne($camera_model->recorder_id);
        if($recorder_model->protocol == 'http')
            return $camera_model->ip_address;
        elseif ($recorder_model->protocol == 'rtsp'){
            if(strtoupper($recorder_model->model) == 'DAHUA'){
                return 'rtsp://' . $recorder_model->username . ':' . $recorder_model->password . '@' . $recorder_model->ip. ':' . $recorder_model->media_port . '/cam/realmonitor?channel='.$camera_model->channel.'&subtype='.  $camera_model->quality;
            }
            return 'rtsp://' .$recorder_model->ip. ':' . $recorder_model->media_port . '/user=' . $recorder_model->username . '&password='. $recorder_model->password . '&channel=' . $camera_model->channel . '&stream='. $camera_model->quality .'.sdp';
        }
    }

    public static function getLinkStreamByQuality($camera_id, $quality){
        $camera_model = CameraBase::findOne($camera_id);
        if($camera_model->protocol == 'http')
            return $camera_model->ip_address;
        elseif ($camera_model->protocol == 'rtsp'){
            if(strtoupper($camera_model->encoder_model) == 'DAHUA'){<commit_msg>quan ly theo dau ghi<commit_after><?php

namespace common\components;

use common\models\_base\CameraBase;
use common\models\Recorder;
use frontend\models\Camera;

class Common
{
    public static function validatePhone($phone) {
        $phone = trim($phone);
        if(strpos($phone,"84")===0){
            $phone = "0".substr($phone,"2");
        }else if(strpos($phone,"0")!==0){
            $phone = "0".$phone;
        }
        $pattern = "/^(089|086|088|090|091|092|093|094|095|096|097|098|099|0121|0122|0123|0124|0125|0126|0127|0128|0129|0121|0120||0161|0162|0163|0164|0165|0166|0167|0168|0169)([0-9]{7})$/";
        return preg_match($pattern,$phone);
    }

    public static function validateEmail($email){
        $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";

        if (eregi($pattern, $email)){
            return true;
        }
        else {
            return false;
        }
    }

    public static function getLinkStream($camera_id){
        $camera_model = CameraBase::findOne($camera_id);
        $recorder_model = Recorder::findOne($camera_model->recorder_id);
        if($recorder_model->protocol == 'http')
            return $camera_model->streaming_url;
        elseif ($recorder_model->protocol == 'rtsp'){
            if(strtoupper($recorder_model->model) == 'DAHUA'){
                return 'rtsp://' . $recorder_model->username . ':' . $recorder_model->password . '@' . $recorder_model->ip. ':' . $recorder_model->media_port . '/cam/realmonitor?channel='.$camera_model->channel.'&subtype='.  $camera_model->quality;
            }
            return 'rtsp://' .$recorder_model->ip. ':' . $recorder_model->media_port . '/user=' . $recorder_model->username . '&password='. $recorder_model->password . '&channel=' . $camera_model->channel . '&stream='. $camera_model->quality .'.sdp';
        }
    }

    public static function getLinkStreamByQuality($camera_id, $quality){
        $camera_model = CameraBase::findOne($camera_id);
        if($camera_model->protocol == 'http')
            return $camera_model->ip_address;
        elseif ($camera_model->protocol == 'rtsp'){
            if(strtoupper($camera_model->encoder_model) == 'DAHUA'){
{'fraction_non_alphanumeric': 0.19095022624434388, 'fraction_numerical': 0.06334841628959276, 'mean_word_length': 3.0300820419325434, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1852804', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1495, 'n_words': 195}