'#f4f7f2','textColor'=>'#13201a','buttonColor'=>'#13935a','buttonText'=>'#ffffff','controlsBackground'=>'#ffffff','controlsText'=>'#13201a','accentColor'=>'#13935a','borderColor'=>'#e2e8de','radius'=>'16','buttonRadius'=>'100','padding'=>'24','fontSize'=>'16','titleSize'=>'22','width'=>'100','alignment'=>'left','showTitle'=>'0','showVolume'=>'1','showSpeed'=>'1','showFullscreen'=>'1','showDownload'=>'0','showTime'=>'1','poster'=>'','loop'=>'0'];} static function attributes(){return array_map(static fn($v)=>['type'=>'string','default'=>$v],self::defaults());} static function color($v,$transparent=false){if(is_string($v)&&preg_match('/^#[a-fA-F0-9]{6}(?:[a-fA-F0-9]{2})?$/D',$v))return true;if($transparent&&$v==='transparent')return true;if(is_string($v)&&preg_match('/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*([0-9]*\.?[0-9]+))?\s*\)$/D',$v,$m))return (int)$m[1]<=255&&(int)$m[2]<=255&&(int)$m[3]<=255&&(!isset($m[4])||(float)$m[4]<=1);return false;} static function styles($a){$map=['background'=>'bg','textColor'=>'text','buttonColor'=>'button','buttonText'=>'button-text','controlsBackground'=>'controls-bg','controlsText'=>'controls-text','accentColor'=>'accent','borderColor'=>'border'];$s=[];foreach($map as $key=>$var){$v=$a[$key];if(!self::color($v,$key==='background'))$v=self::defaults()[$key];$s[]='--lfdrive-'.$var.':'.$v;} foreach(['radius'=>[0,80],'buttonRadius'=>[0,100],'padding'=>[0,80],'fontSize'=>[10,36],'titleSize'=>[12,60]] as $key=>$range){$v=max($range[0],min($range[1],(int)$a[$key]));$s[]='--lfdrive-'.strtolower(preg_replace('/([A-Z])/','-$1',$key)).':'.$v.'px';} $s[]='--lfdrive-width:'.max(20,min(100,(int)$a['width'])).'%';$s[]='text-align:'.(in_array($a['alignment'],['left','center','right'],true)?$a['alignment']:'left');return implode(';',$s);} static function register_assets(){ if(!wp_style_is('lfdrive-front','registered'))wp_register_style('lfdrive-front',plugins_url('assets/front.css',__FILE__),[],'1.2.4'); if(!wp_script_is('lfdrive-front','registered'))wp_register_script('lfdrive-front',plugins_url('assets/front.js',__FILE__),[],'1.2.4',true); } static function assets(){ self::register_assets();wp_enqueue_style('lfdrive-front');wp_enqueue_script('lfdrive-front'); if(!self::$configured){ self::$configured=true;$base=plugins_url('assets/pdfjs/',__FILE__); wp_add_inline_script('lfdrive-front','window.LFDriveFrontConfig='.wp_json_encode(['pdf'=>$base.'pdf.min.mjs','worker'=>$base.'pdf.worker.min.mjs','cmaps'=>$base.'cmaps/','fonts'=>$base.'standard_fonts/','wasm'=>$base.'wasm/']).';','before'); } } static function frontend_assets(){ if(is_admin())return; $post=get_post();if(!$post)return; $content=(string)$post->post_content;$needed=strpos($content,'wp:lfdrive/')!==false; foreach(['file','image','pdf','video','audio','sale','uploader'] as $type){if(has_shortcode($content,'lfdrive_'.$type)){$needed=true;break;}} if(!$needed){$elementor=get_post_meta($post->ID,'_elementor_data',true);$needed=is_string($elementor)&&preg_match('/"widgetType"\s*:\s*"lfdrive"/',$elementor)===1;} if($needed)self::assets(); } static function control($action,$label,$text){return '';} static function render($type,$attrs){$a=shortcode_atts(array_merge(['url'=>'','title'=>'','label'=>'','description'=>'','price'=>'','alt'=>'','height'=>'600'],self::defaults()),$attrs);if(!LFDrive_Plugin::safe_url($a['url']))return '';self::assets();$url=esc_url($a['url']);$open='
'.esc_html($a['description']).'
'.esc_html($a['price']).' ₽':'').''.esc_html($a['label']?:($type==='sale'?'Купить файл':'Скачать файл')).'';} if($type==='video'||$type==='audio'){ $poster=$type==='video'&&LFDrive_Plugin::safe_url($a['poster'])?' poster="'.esc_url($a['poster']).'"':'';$media='<'.$type.' class="lfdrive-media" controls src="'.$url.'" preload="metadata"'.($type==='video'?' playsinline':'').($a['loop']==='1'?' loop':'').$poster.'>'.$type.'>'; $controls=self::control('play','Воспроизвести','▶').''.($a['showTime']==='1'?'0:00 / 0:00':''); if($a['showVolume']==='1')$controls.=self::control('mute','Выключить звук','♫').''; if($a['showSpeed']==='1')$controls.=self::control('speed','Изменить скорость воспроизведения','1×');if($type==='video'&&$a['showFullscreen']==='1')$controls.=self::control('fullscreen','На весь экран','⛶');if($a['showDownload']==='1')$controls.='↓'; return $open.'Загружаем документ…
Открыть PDF отдельно ↗