'array', 'trans' => 'array', ]; protected $fillable = [ 'user_id', 'name', 'active', 'active_date', ]; use SoftDeletes; protected $dates = ['deleted_at']; use Sluggable; public function sluggable() : array { return [ 'slug' => [ 'source' => 'name' ] ]; } public function user() { return $this->belongsTo('App\User', 'user_id'); } public function on_sites(){ return $this->hasMany('App\Models\UserShopOnSite', 'user_shop_id', 'id'); } public function getActiveDateFormat(){ if(!$this->attributes['active_date']){ return ""; } return Carbon::parse($this->attributes['active_date'])->format(\Util::formatDateTimeDB()); } public function getActiveDateFormatSmall(){ if(!$this->attributes['active_date']){ return ""; } return Carbon::parse($this->attributes['active_date'])->format("d.m.Y"); } public function getLang($key, $default = true) { $lang = \App::getLocale(); if ($lang == 'de') { return $this->{$key}; } return $this->getTrans($key, $lang, $default); } public function getTrans($key, $lang, $default = true) { if ($lang == 'de') { return $this->{$key}; } if(!empty($this->trans[$lang][$key])){ return $this->trans[$lang][$key]; } if($default){ return !empty($this->{$key}) ? $this->{$key} : ''; } return ""; } public function getSubdomain($session=true) { if($session && \Session::has('user_shop_domain')){ return \Session::get('user_shop_domain'); } return config('app.protocol').$this->attributes['slug'].".".config('app.domain').config('app.tld_care'); } public function getSubdomainStatus() { if($this->is_online !== NULL){ return $this->is_online; } $kas = new KasController(); $domain = 'mivita.care'; $pra = array( 'subdomain_name' => $this->attributes['slug'].".".$domain, 'domain_name' => $domain, ); //check if exisist $subdomain = $kas->action('get_subdomains', $pra); if(is_soap_fault($subdomain)){ return false; } if(!empty($subdomain[0]['is_active']) && $subdomain[0]['is_active'] == 'Y'){ $this->is_online = true; }else{ $this->is_online = false; } if(!empty($subdomain[0]['ssl_certificate_sni']) && $subdomain[0]['ssl_certificate_sni'] == 'Y'){ $this->ssl_certificate_sni = true; }else{ $this->ssl_certificate_sni = false; $this->userShopAddSSL($subdomain[0]['subdomain_name']); } if(!empty($subdomain[0]['ssl_certificate_sni_is_active']) && $subdomain[0]['ssl_certificate_sni_is_active'] == 'j'){ $this->ssl_certificate_sni_is_active = true; }else{ $this->ssl_certificate_sni_is_active = false; } return $this->is_online; } public function userShopAddSSL($full_subdomain_name) { $kas = new KasController(); $ssl = KasSLLController::getApiSSLParameter(); $pra = array( 'hostname' => $full_subdomain_name ); $pra = array_merge($pra, $ssl); $value = $kas->action('update_ssl', $pra); return $value; } public function getSubdomainSslSin () { return $this->ssl_certificate_sni; } public function getSubdomainSslSinActive () { return $this->ssl_certificate_sni_is_active; } public function getSubdomainAvailable () { $rCurlHandle = curl_init ( $this->attributes['slug'].".mivita.care" ); curl_setopt ( $rCurlHandle, CURLOPT_CONNECTTIMEOUT, 10 ); curl_setopt ( $rCurlHandle, CURLOPT_HEADER, TRUE ); curl_setopt ( $rCurlHandle, CURLOPT_NOBODY, TRUE ); curl_setopt ( $rCurlHandle, CURLOPT_RETURNTRANSFER, TRUE ); $strResponse = curl_exec ( $rCurlHandle ); curl_close ( $rCurlHandle ); if ( !$strResponse ) { return FALSE; } $url = "http://".$this->attributes['slug'].".mivita.care/domain/check"; if(@file_get_contents($url) != 'checked'){ return FALSE; } return TRUE; } public function isImage(){ if(empty($this->attributes['filename']) || @$this->attributes['filename'] == null || @$this->attributes['filename'] == ""){ return false; } if(!\Storage::disk('public')->has('images/shop/'.$this->filename)){ return false; } return true; } public function getImage(){ if($this->isImage()){ $link = 'images/shop/'.$this->filename; return '/storage/'.$link.'?=lm='.\Storage::disk('public')->lastModified($link); } return false; } }