5*1024*1024)||$magic!==($ext==='woff2'?'wOF2':'wOFF')){$file['error']='Upload a valid WOFF/WOFF2 font, up to 5 MB, using an administrator account.';}return $file; } public static function font(int $id): array { if(!$id||get_post_type($id)!=='attachment'||!in_array(get_post_mime_type($id),['font/woff','font/woff2','application/font-woff','application/font-woff2'],true)){return [];} $url=wp_get_attachment_url($id);$file=get_attached_file($id);if(!$url||!$file||!is_file($file)||!in_array(strtolower(pathinfo($file,PATHINFO_EXTENSION)),['woff','woff2'],true)){return [];} return ['family'=>'DigiterFont'.$id,'url'=>Document::url($url),'format'=>strtolower(pathinfo($file,PATHINFO_EXTENSION))]; } public static function styles(array $s): array { $css='';$class='';$inline=''; foreach(['bodyFont','titleFont'] as $key){$font=self::font((int)($s[$key]??0));if(!$font){continue;}$url=strtr($font['url'],['"'=>'%22',"'"=>'%27','('=>'%28',')'=>'%29',chr(92)=>'%5C','<'=>'%3C','>'=>'%3E']); $css.='@font-face{font-family:'.$font['family'].';src:url("'.$url.'") format("'.$font['format'].'");font-display:swap}'; if($key==='bodyFont'){$inline.='font-family:'.$font['family'].',sans-serif;';}else{$inline.='--dbs-heading-font:'.$font['family'].',sans-serif;';$class.=' dbs-custom-headings';} } $mobile=(int)($s['mobileBreakpoint']??600);$tablet=(int)($s['tabletBreakpoint']??900); if($mobile!==600||$tablet!==900){ $name='dbs-responsive-'.$mobile.'-'.$tablet;$class.=' dbs-custom-responsive '.$name; $template=file_get_contents(DIGIBL_PATH.'assets/responsive-template.css');$template=strtr($template,['max-width:600px'=>'max-width:'.$mobile.'px','min-width:601px'=>'min-width:'.($mobile+1).'px','max-width:900px'=>'max-width:'.$tablet.'px','min-width:901px'=>'min-width:'.($tablet+1).'px']); $css.=preg_replace_callback('/(?<=\{|\})([^{}]+)\{/',static function($match)use($name){$selectors=[];foreach(explode(',',$match[1]) as $selector){$selector=trim($selector);if(str_starts_with($selector,'@')){return $match[0];}$selectors[]=str_contains($selector,'.dbs-document')?str_replace('.dbs-document','.dbs-document.'.$name,$selector):'.dbs-document.'.$name.' '.$selector;}return implode(',',$selectors).'{';},$template); } return ['css'=>Assets::inline_style($css,'design'),'class'=>$class,'inline'=>$inline]; } }