Plugin Directory

Changeset 3815470


Ignore:
Timestamp:
11/21/2026 04:34:42 PM (less than one hour ago)
Author:
j03rul4nd
Message:

Release 1.2.0

Location:
bimo-ifc-viewer
Files:
6 added
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • bimo-ifc-viewer/tags/1.2.0/bimo-ifc-viewer.php

    r3815325 r3815470  
    44 * Plugin URI:        https://github.com/j03rul4nd/ifc-viewer-online/tree/main/integrations/wordpress
    55 * Description:       Embed interactive 3D IFC (BIM) models in posts and pages: Health Score, federated models, point clouds, the model on the map, sun studies, plan cuts and digital twin scenes. Block and [ifc_viewer] shortcode.
    6  * Version:           1.1.0
     6 * Version:           1.2.0
    77 * Requires at least: 6.1
    88 * Requires PHP:      7.4
    … …  
    2222}
    2323
    24 define( 'IFCVO_VERSION', '1.1.0' );
     24define( 'IFCVO_VERSION', '1.2.0' );
    2525define( 'IFCVO_APP_URL', 'https://www.ifcvieweronline.eu/' );
    2626define( 'IFCVO_APP_ORIGIN', 'https://www.ifcvieweronline.eu' );
    … …  
    4949                'drawings'  => array( 'plan' ),
    5050                'explore'   => array( '1', '0' ),
     51                'toolbar'   => array( '1', '0' ),
     52                // "none" is the shortcode's way to say `tools=` (no tools at all).
     53                'tools'     => '/^(none|(validate|measure)(,(validate|measure))?)$/',
     54                'panels'    => '/^(none|(properties|scene|measurement|section|plans|map|solar|flood|devices|pointcloud|mesh)(,(properties|scene|measurement|section|plans|map|solar|flood|devices|pointcloud|mesh)){0,10})$/',
     55                'autoframe' => array( '1', '0' ),
     56                'fill'      => '/^(0?\.\d{1,3}|[2-9]\d)$/',
     57                'rule'      => '/^RULE_[A-Z0-9_]{2,60}$/',
     58                'flood'     => '/^(shower|storm|intense|extreme)(,(1m|2m|5m|free|closed|sealed|compacted|loam|sandy)){0,3}$/',
    5159        );
    5260}
    … …  
    5967                'name'       => '',
    6068                'height'     => 600,
    61                 'ui'         => 'article',
     69                'ui'         => '',
    6270                'view'       => 'iso',
    6371                'wheel'      => 'ctrl',
    … …  
    7886                'drawings'   => '',
    7987                'explore'    => '',
    80         );
     88                // 1.2.0
     89                'toolbar'    => '',
     90                'tools'      => '',
     91                'panels'     => '',
     92                'autoframe'  => '',
     93                'fill'       => '',
     94                'layers'     => '',
     95                'rule'       => '',
     96                'flood'      => '',
     97                'fullscreen' => '',
     98                'load'       => '',
     99                'poster'     => '',
     100                'poster_title' => '',
     101                'poster_text'  => '',
     102                'launch_label' => '',
     103                'form_field'   => '',
     104        );
     105}
     106
     107/** Site-wide settings (Settings → Bimo IFC Viewer), with their defaults. */
     108function ifcvo_settings() {
     109        $saved = get_option( 'ifcvo_settings', array() );
     110        return wp_parse_args(
     111                is_array( $saved ) ? $saved : array(),
     112                array(
     113                        'accent'     => '',
     114                        'lang'       => '',
     115                        'ui'         => '',
     116                        'bg'         => '',
     117                        'load'       => 'auto',
     118                        'poster'     => '',
     119                        'consent'    => '',
     120                        'form_field' => '0',
     121                        'datalayer'  => '0',
     122                )
     123        );
     124}
     125
     126/** Empty attributes take the site-wide default; 1.1.0 embeds stay as they were. */
     127function ifcvo_apply_settings( $atts ) {
     128        $settings = ifcvo_settings();
     129        foreach ( array( 'accent', 'lang', 'bg' ) as $key ) {
     130                if ( '' === trim( (string) $atts[ $key ] ) && '' !== $settings[ $key ] ) {
     131                        $atts[ $key ] = $settings[ $key ];
     132                }
     133        }
     134        if ( '' === trim( (string) $atts['ui'] ) ) {
     135                $atts['ui'] = '' !== $settings['ui'] ? $settings['ui'] : 'article';
     136        }
     137        if ( ! in_array( $atts['load'], array( 'auto', 'click' ), true ) ) {
     138                $atts['load'] = 'click' === $settings['load'] ? 'click' : 'auto';
     139        }
     140        if ( '' === trim( (string) $atts['poster'] ) ) {
     141                $atts['poster'] = $settings['poster'];
     142        }
     143        return $atts;
    81144}
    82145
    … …  
    164227                $query['scan'] = implode( ',', $scan );
    165228        }
     229        $layers = ifcvo_https_list( $atts['layers'], 1 );
     230        if ( $layers ) {
     231                $query['layers'] = $layers[0];
     232        }
    166233        foreach ( ifcvo_param_rules() as $key => $rule ) {
    167234                $value = trim( (string) $atts[ $key ] );
    … …  
    175242                if ( 'accent' === $key ) {
    176243                        $value = ltrim( $value, '#' );
     244                }
     245                if ( ( 'tools' === $key || 'panels' === $key ) && 'none' === $value ) {
     246                        $value = '';
    177247                }
    178248                // The viewer's defaults need no parameter.
    … …  
    190260}
    191261
     262/** The poster image URL: a Media Library ID or an https URL. */
     263function ifcvo_poster_url( $poster ) {
     264        $poster = trim( (string) $poster );
     265        if ( '' === $poster ) {
     266                return '';
     267        }
     268        if ( ctype_digit( $poster ) ) {
     269                $url = wp_get_attachment_image_url( absint( $poster ), 'large' );
     270                return $url ? $url : '';
     271        }
     272        return esc_url_raw( $poster, array( 'https' ) );
     273}
     274
     275/** Loads the bundled front-end script, only on pages that render a viewer or a step. */
     276function ifcvo_enqueue_frontend() {
     277        wp_enqueue_script( 'ifcvo-frontend', plugins_url( 'frontend.js', __FILE__ ), array(), IFCVO_VERSION, true );
     278}
     279
     280/** The data-* attributes the front-end script reads, already escaped. */
     281function ifcvo_data_attributes( $atts, $settings ) {
     282        $data = array();
     283        if ( '1' === (string) $atts['fullscreen'] ) {
     284                $data['fullscreen'] = '1';
     285        }
     286        $field = trim( (string) $atts['form_field'] );
     287        // Opt-in: filling form fields stays off until the site owner turns it on.
     288        if ( '' !== $field && '1' === $settings['form_field'] && preg_match( '/^[A-Za-z0-9_\-#.\[\]="\' :]{1,120}$/', $field ) ) {
     289                $data['form-field'] = $field;
     290        }
     291        if ( '1' === $settings['datalayer'] ) {
     292                $data['datalayer'] = '1';
     293        }
     294        $out = '';
     295        foreach ( $data as $key => $value ) {
     296                $out .= ' data-ifcvo-' . $key . '="' . esc_attr( $value ) . '"';
     297        }
     298        return $out;
     299}
     300
    192301/** The iframe markup shared by the shortcode and the block. */
    193302function ifcvo_render( $atts, $wrapper = 'class="ifcvo-embed"' ) {
    194         $atts = shortcode_atts( ifcvo_default_atts(), (array) $atts, 'ifc_viewer' );
     303        $atts = ifcvo_apply_settings( shortcode_atts( ifcvo_default_atts(), (array) $atts, 'ifc_viewer' ) );
    195304        $src  = ifcvo_build_embed_url( $atts );
    196305        if ( '' === $src ) {
    … …  
    200309                return '';
    201310        }
    202         $height = max( 200, min( 2000, absint( $atts['height'] ) ) );
    203         $title  = '' !== trim( (string) $atts['title'] ) ? $atts['title'] : __( 'Interactive 3D IFC model', 'bimo-ifc-viewer' );
    204         return sprintf(
    205                 '<div %4$s><iframe src="%1$s" width="100%%" height="%2$d" style="border:0;border-radius:12px;max-width:100%%;display:block" loading="lazy" allow="fullscreen" title="%3$s"></iframe></div>',
    206                 esc_url( $src ),
    207                 $height,
    208                 esc_attr( $title ),
    209                 $wrapper
    210         );
     311        ifcvo_enqueue_frontend();
     312        $settings = ifcvo_settings();
     313        $height   = max( 200, min( 2000, absint( $atts['height'] ) ) );
     314        $title    = '' !== trim( (string) $atts['title'] ) ? $atts['title'] : __( 'Interactive 3D IFC model', 'bimo-ifc-viewer' );
     315        $wrapper .= ifcvo_data_attributes( $atts, $settings );
     316        if ( 'click' !== $atts['load'] ) {
     317                return sprintf(
     318                        '<div %4$s><iframe src="%1$s" width="100%%" height="%2$d" style="border:0;border-radius:12px;max-width:100%%;display:block" loading="lazy" allow="fullscreen" title="%3$s"></iframe></div>',
     319                        esc_url( $src ),
     320                        $height,
     321                        esc_attr( $title ),
     322                        $wrapper
     323                );
     324        }
     325
     326        // Click to load: nothing is requested from ifcvieweronline.eu until the visitor asks.
     327        $poster  = ifcvo_poster_url( $atts['poster'] );
     328        $heading = '' !== trim( (string) $atts['poster_title'] ) ? $atts['poster_title'] : $title;
     329        $text    = trim( (string) $atts['poster_text'] );
     330        $label   = '' !== trim( (string) $atts['launch_label'] ) ? $atts['launch_label'] : __( 'Load the 3D model', 'bimo-ifc-viewer' );
     331        $consent = '' !== trim( (string) $settings['consent'] ) ? $settings['consent'] : __( 'The 3D viewer loads from www.ifcvieweronline.eu when you click. Your browser then downloads the model from this site.', 'bimo-ifc-viewer' );
     332        // The poster takes the iframe's height, so loading the model shifts nothing.
     333        $style = 'position:relative;height:' . $height . 'px;border-radius:12px;overflow:hidden;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:24px;box-sizing:border-box;text-align:center;color:#fff;background:#1d2430';
     334        $html  = '<div ' . $wrapper . ' data-ifcvo-load="click" data-ifcvo-src="' . esc_url( $src ) . '" data-ifcvo-height="' . esc_attr( (string) $height ) . '" data-ifcvo-title="' . esc_attr( $title ) . '">';
     335        $html .= '<div class="ifcvo-poster" style="' . esc_attr( $style ) . '">';
     336        if ( $poster ) {
     337                $html .= '<img src="' . esc_url( $poster ) . '" alt="" loading="lazy" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover;opacity:.45;margin:0;max-width:none">';
     338        }
     339        $html .= '<p class="ifcvo-poster-title" style="position:relative;margin:0;font-size:1.25em;font-weight:600">' . esc_html( $heading ) . '</p>';
     340        if ( '' !== $text ) {
     341                $html .= '<p class="ifcvo-poster-text" style="position:relative;margin:0;max-width:40em">' . esc_html( $text ) . '</p>';
     342        }
     343        $html .= '<button type="button" class="ifcvo-launch" style="position:relative;cursor:pointer;padding:10px 18px;border-radius:8px;border:0;font:inherit;font-weight:600;background:#fff;color:#1d2430">' . esc_html( $label ) . '</button>';
     344        $html .= '<p class="ifcvo-consent" style="position:relative;margin:0;font-size:.8em;opacity:.85;max-width:40em">' . esc_html( $consent ) . '</p>';
     345        // Without JavaScript the button does nothing: offer a plain link instead.
     346        $html .= '<noscript><a href="' . esc_url( remove_query_arg( 'embed', $src ) ) . '" target="_blank" rel="noopener" style="position:relative;color:#fff">' . esc_html__( 'Open the model on ifcvieweronline.eu', 'bimo-ifc-viewer' ) . '</a></noscript>';
     347        $html .= '</div></div>';
     348        return $html;
     349}
     350
     351/**
     352 * [ifc_step view="front" select="GUID" isolate="IfcWall"]Text[/ifc_step]
     353 *
     354 * A paragraph of a guided story: while it crosses the middle of the screen the
     355 * nearest viewer above it (or the first one below) shows what the step says.
     356 * Without JavaScript it is plain text.
     357 */
     358function ifcvo_step_attributes( $atts ) {
     359        $atts  = shortcode_atts(
     360                array(
     361                        'view'      => '',
     362                        'select'    => '',
     363                        'isolate'   => '',
     364                        'azimuth'   => '',
     365                        'elevation' => '',
     366                        'fill'      => '',
     367                ),
     368                (array) $atts,
     369                'ifc_step'
     370        );
     371        $rules = array(
     372                'view'      => '/^(iso|top|front|back|left|right|bottom)$/',
     373                'select'    => '/^[0-9A-Za-z_$]{22}$/',
     374                'isolate'   => '/^(none|[A-Za-z]{3,60})$/',
     375                'azimuth'   => '/^-?\d{1,3}(\.\d+)?$/',
     376                'elevation' => '/^-?\d{1,2}(\.\d+)?$/',
     377                'fill'      => '/^0?\.\d{1,3}$/',
     378        );
     379        $out   = '';
     380        foreach ( $rules as $key => $rule ) {
     381                $value = trim( (string) $atts[ $key ] );
     382                if ( '' !== $value && preg_match( $rule, $value ) ) {
     383                        $out .= ' data-' . $key . '="' . esc_attr( $value ) . '"';
     384                }
     385        }
     386        return $out;
     387}
     388
     389function ifcvo_render_step( $atts, $content = '' ) {
     390        ifcvo_enqueue_frontend();
     391        return '<div class="ifcvo-step"' . ifcvo_step_attributes( $atts ) . '>' . do_shortcode( (string) $content ) . '</div>';
     392}
     393add_shortcode( 'ifc_step', 'ifcvo_render_step' );
     394
     395/** The step block keeps its inner blocks (the text) as saved content. */
     396function ifcvo_render_step_block( $atts, $content ) {
     397        ifcvo_enqueue_frontend();
     398        return '<div ' . get_block_wrapper_attributes( array( 'class' => 'ifcvo-step' ) ) . ifcvo_step_attributes( $atts ) . '>' . $content . '</div>';
    211399}
    212400
    … …  
    216404}
    217405
    218 add_shortcode( 'ifc_viewer', 'ifcvo_render' );
     406/** Shortcode callback: WordPress passes the content as the second argument, which is not a wrapper. */
     407function ifcvo_shortcode( $atts ) {
     408        return ifcvo_render( $atts );
     409}
     410add_shortcode( 'ifc_viewer', 'ifcvo_shortcode' );
    219411
    220412/** Gutenberg block (no build step: the editor script uses the wp.* globals). */
    … …  
    230422                __DIR__ . '/block.json',
    231423                array( 'render_callback' => 'ifcvo_render_block' )
     424        );
     425        register_block_type(
     426                __DIR__ . '/step/block.json',
     427                array( 'render_callback' => 'ifcvo_render_step_block' )
    232428        );
    233429}
    … …  
    330526        exit;
    331527}
     528
     529/*
     530 * Settings → Bimo IFC Viewer: site-wide defaults. Every embed can override them.
     531 */
     532function ifcvo_sanitize_settings( $input ) {
     533        $input = is_array( $input ) ? $input : array();
     534        $rules = ifcvo_param_rules();
     535        $out   = array();
     536        foreach ( array( 'accent', 'lang', 'ui', 'bg' ) as $key ) {
     537                $value       = isset( $input[ $key ] ) ? sanitize_text_field( wp_unslash( $input[ $key ] ) ) : '';
     538                $rule        = $rules[ $key ];
     539                $ok          = is_array( $rule ) ? in_array( $value, $rule, true ) : (bool) preg_match( $rule, $value );
     540                $out[ $key ] = $ok ? $value : '';
     541        }
     542        $out['load']       = isset( $input['load'] ) && 'click' === $input['load'] ? 'click' : 'auto';
     543        $poster            = isset( $input['poster'] ) ? trim( sanitize_text_field( wp_unslash( $input['poster'] ) ) ) : '';
     544        $out['poster']     = ctype_digit( $poster ) ? (string) absint( $poster ) : esc_url_raw( $poster, array( 'https' ) );
     545        $out['consent']    = isset( $input['consent'] ) ? sanitize_textarea_field( wp_unslash( $input['consent'] ) ) : '';
     546        $out['form_field'] = empty( $input['form_field'] ) ? '0' : '1';
     547        $out['datalayer']  = empty( $input['datalayer'] ) ? '0' : '1';
     548        return $out;
     549}
     550
     551function ifcvo_register_settings() {
     552        register_setting(
     553                'ifcvo_settings_group',
     554                'ifcvo_settings',
     555                array(
     556                        'type'              => 'array',
     557                        'sanitize_callback' => 'ifcvo_sanitize_settings',
     558                        'default'           => array(),
     559                )
     560        );
     561}
     562add_action( 'admin_init', 'ifcvo_register_settings' );
     563
     564function ifcvo_settings_menu() {
     565        add_options_page(
     566                __( 'Bimo IFC Viewer', 'bimo-ifc-viewer' ),
     567                __( 'Bimo IFC Viewer', 'bimo-ifc-viewer' ),
     568                'manage_options',
     569                'bimo-ifc-viewer',
     570                'ifcvo_settings_page'
     571        );
     572}
     573add_action( 'admin_menu', 'ifcvo_settings_menu' );
     574
     575function ifcvo_settings_link( $links ) {
     576        $links[] = '<a href="' . esc_url( admin_url( 'options-general.php?page=bimo-ifc-viewer' ) ) . '">' . esc_html__( 'Settings', 'bimo-ifc-viewer' ) . '</a>';
     577        return $links;
     578}
     579add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'ifcvo_settings_link' );
     580
     581/** One select box of the settings page. */
     582function ifcvo_settings_select( $key, $value, $options ) {
     583        echo '<select id="ifcvo-' . esc_attr( $key ) . '" name="ifcvo_settings[' . esc_attr( $key ) . ']">';
     584        foreach ( $options as $option => $label ) {
     585                echo '<option value="' . esc_attr( $option ) . '"' . selected( $value, $option, false ) . '>' . esc_html( $label ) . '</option>';
     586        }
     587        echo '</select>';
     588}
     589
     590function ifcvo_settings_page() {
     591        if ( ! current_user_can( 'manage_options' ) ) {
     592                return;
     593        }
     594        $s     = ifcvo_settings();
     595        $rules = ifcvo_param_rules();
     596        $langs = array( '' => __( 'Visitor language', 'bimo-ifc-viewer' ) );
     597        foreach ( $rules['lang'] as $lang ) {
     598                $langs[ $lang ] = $lang;
     599        }
     600        ?>
     601        <div class="wrap">
     602                <h1><?php esc_html_e( 'Bimo IFC Viewer', 'bimo-ifc-viewer' ); ?></h1>
     603                <p><?php esc_html_e( 'Defaults for every IFC Viewer block and [ifc_viewer] shortcode of this site. A setting given on a block or shortcode wins.', 'bimo-ifc-viewer' ); ?></p>
     604                <form method="post" action="options.php">
     605                        <?php settings_fields( 'ifcvo_settings_group' ); ?>
     606                        <table class="form-table" role="presentation">
     607                                <tr>
     608                                        <th scope="row"><label for="ifcvo-ui"><?php esc_html_e( 'Interface', 'bimo-ifc-viewer' ); ?></label></th>
     609                                        <td>
     610                                        <?php
     611                                        ifcvo_settings_select(
     612                                                'ui',
     613                                                $s['ui'],
     614                                                array(
     615                                                        ''        => __( 'Article (default)', 'bimo-ifc-viewer' ),
     616                                                        'minimal' => __( 'Minimal', 'bimo-ifc-viewer' ),
     617                                                        'full'    => __( 'Full app', 'bimo-ifc-viewer' ),
     618                                                        'kiosk'   => __( 'Kiosk', 'bimo-ifc-viewer' ),
     619                                                        'client'  => __( 'Client presentation', 'bimo-ifc-viewer' ),
     620                                                )
     621                                        );
     622                                        ?>
     623                                        </td>
     624                                </tr>
     625                                <tr>
     626                                        <th scope="row"><label for="ifcvo-lang"><?php esc_html_e( 'Language', 'bimo-ifc-viewer' ); ?></label></th>
     627                                        <td><?php ifcvo_settings_select( 'lang', $s['lang'], $langs ); ?></td>
     628                                </tr>
     629                                <tr>
     630                                        <th scope="row"><label for="ifcvo-accent"><?php esc_html_e( 'Accent colour (hex)', 'bimo-ifc-viewer' ); ?></label></th>
     631                                        <td><input type="text" id="ifcvo-accent" name="ifcvo_settings[accent]" value="<?php echo esc_attr( $s['accent'] ); ?>" placeholder="#3366ff" class="regular-text"></td>
     632                                </tr>
     633                                <tr>
     634                                        <th scope="row"><label for="ifcvo-bg"><?php esc_html_e( 'Background', 'bimo-ifc-viewer' ); ?></label></th>
     635                                        <td><input type="text" id="ifcvo-bg" name="ifcvo_settings[bg]" value="<?php echo esc_attr( $s['bg'] ); ?>" placeholder="paper" class="regular-text">
     636                                        <p class="description"><?php esc_html_e( 'white, paper, blueprint, sky, studio, or one or two hex colours without # (top,bottom).', 'bimo-ifc-viewer' ); ?></p></td>
     637                                </tr>
     638                                <tr>
     639                                        <th scope="row"><label for="ifcvo-load"><?php esc_html_e( 'Loading', 'bimo-ifc-viewer' ); ?></label></th>
     640                                        <td>
     641                                        <?php
     642                                        ifcvo_settings_select(
     643                                                'load',
     644                                                $s['load'],
     645                                                array(
     646                                                        'auto'  => __( 'Load the viewer with the page', 'bimo-ifc-viewer' ),
     647                                                        'click' => __( 'Show a poster; load the viewer when the visitor clicks', 'bimo-ifc-viewer' ),
     648                                                )
     649                                        );
     650                                        ?>
     651                                        <p class="description"><?php esc_html_e( 'With click to load, nothing is requested from ifcvieweronline.eu until the visitor asks for the model.', 'bimo-ifc-viewer' ); ?></p></td>
     652                                </tr>
     653                                <tr>
     654                                        <th scope="row"><label for="ifcvo-poster"><?php esc_html_e( 'Default poster image', 'bimo-ifc-viewer' ); ?></label></th>
     655                                        <td><input type="text" id="ifcvo-poster" name="ifcvo_settings[poster]" value="<?php echo esc_attr( $s['poster'] ); ?>" class="regular-text">
     656                                        <p class="description"><?php esc_html_e( 'A Media Library ID or an https image URL.', 'bimo-ifc-viewer' ); ?></p></td>
     657                                </tr>
     658                                <tr>
     659                                        <th scope="row"><label for="ifcvo-consent"><?php esc_html_e( 'Consent text on the poster', 'bimo-ifc-viewer' ); ?></label></th>
     660                                        <td><textarea id="ifcvo-consent" name="ifcvo_settings[consent]" rows="3" class="large-text"><?php echo esc_textarea( $s['consent'] ); ?></textarea>
     661                                        <p class="description"><?php esc_html_e( 'Leave empty for the default note that the viewer loads from www.ifcvieweronline.eu.', 'bimo-ifc-viewer' ); ?></p></td>
     662                                </tr>
     663                                <tr>
     664                                        <th scope="row"><?php esc_html_e( 'Form fields', 'bimo-ifc-viewer' ); ?></th>
     665                                        <td><label><input type="checkbox" name="ifcvo_settings[form_field]" value="1" <?php checked( '1', $s['form_field'] ); ?>> <?php esc_html_e( 'Fill a form field with the selected element (form_field="#css-selector" on the embed)', 'bimo-ifc-viewer' ); ?></label></td>
     666                                </tr>
     667                                <tr>
     668                                        <th scope="row"><?php esc_html_e( 'Analytics', 'bimo-ifc-viewer' ); ?></th>
     669                                        <td><label><input type="checkbox" name="ifcvo_settings[datalayer]" value="1" <?php checked( '1', $s['datalayer'] ); ?>> <?php esc_html_e( 'Push viewer events to window.dataLayer (Google Tag Manager), if the page has one', 'bimo-ifc-viewer' ); ?></label></td>
     670                                </tr>
     671                        </table>
     672                        <?php submit_button(); ?>
     673                </form>
     674        </div>
     675        <?php
     676}
  • bimo-ifc-viewer/tags/1.2.0/block-editor.js

    r3815325 r3815470  
    5555                                el( c.PanelBody, { title: __( 'Display', 'bimo-ifc-viewer' ), initialOpen: false },
    5656                                        el( c.SelectControl, { label: __( 'Interface', 'bimo-ifc-viewer' ), value: a.ui, onChange: function ( v ) { set( { ui: v } ); },
    57                                                 options: [ option( 'article', __( 'Article (clean, for posts)', 'bimo-ifc-viewer' ) ), option( 'minimal', __( 'Minimal', 'bimo-ifc-viewer' ) ), option( 'full', __( 'Full app', 'bimo-ifc-viewer' ) ), option( 'kiosk', __( 'Kiosk', 'bimo-ifc-viewer' ) ), option( 'client', __( 'Client presentation', 'bimo-ifc-viewer' ) ) ] } ),
     57                                                options: [ option( '', __( 'Site default', 'bimo-ifc-viewer' ) ), option( 'article', __( 'Article (clean, for posts)', 'bimo-ifc-viewer' ) ), option( 'minimal', __( 'Minimal', 'bimo-ifc-viewer' ) ), option( 'full', __( 'Full app', 'bimo-ifc-viewer' ) ), option( 'kiosk', __( 'Kiosk', 'bimo-ifc-viewer' ) ), option( 'client', __( 'Client presentation', 'bimo-ifc-viewer' ) ) ] } ),
    5858                                        el( c.SelectControl, { label: __( 'Starting view', 'bimo-ifc-viewer' ), value: a.view, onChange: function ( v ) { set( { view: v } ); },
    5959                                                options: [ 'iso', 'top', 'front', 'back', 'left', 'right' ].map( function ( v ) { return option( v, v ); } ) } ),
    … …  
    6262                                        el( c.ToggleControl, { label: __( 'Mouse wheel scrolls the page (zoom with Ctrl)', 'bimo-ifc-viewer' ), checked: a.wheel === 'ctrl', onChange: function ( v ) { set( { wheel: v ? 'ctrl' : 'always' } ); } } ),
    6363                                        el( c.TextControl, { label: __( 'Accent colour (hex)', 'bimo-ifc-viewer' ), value: a.accent, onChange: function ( v ) { set( { accent: v } ); } } ),
     64                                        select( 'lang', __( 'Language', 'bimo-ifc-viewer' ), [ '', 'en', 'es', 'ca', 'de', 'fr', 'it', 'pt', 'ja', 'zh', 'th' ].map( function ( v ) { return option( v, v || __( 'Site default', 'bimo-ifc-viewer' ) ); } ) ),
     65                                        text( 'bg', __( 'Background', 'bimo-ifc-viewer' ), __( 'white, paper, blueprint, sky, studio, or hex colours without # (top,bottom).', 'bimo-ifc-viewer' ) ),
     66                                        text( 'name', __( 'Model names (comma-separated)', 'bimo-ifc-viewer' ), __( 'Shown instead of the file names, in the same order as the models.', 'bimo-ifc-viewer' ) ),
    6467                                        el( c.TextControl, { label: __( 'Accessible title', 'bimo-ifc-viewer' ), value: a.title, onChange: function ( v ) { set( { title: v } ); } } )
    6568                                ),
    … …  
    8083                                        ] ),
    8184                                        text( 'site', __( 'Study the sun at another place (lat,lon)', 'bimo-ifc-viewer' ) ),
     85                                        el( c.ToggleControl, { label: __( 'Show the moon', 'bimo-ifc-viewer' ), checked: a.moon === '1', onChange: function ( v ) { set( { moon: v ? '1' : '' } ); } } ),
    8286                                        el( c.ToggleControl, { label: __( 'Open with a plan cut of the model', 'bimo-ifc-viewer' ), checked: a.drawings === 'plan', onChange: function ( v ) { set( { drawings: v ? 'plan' : '' } ); } } )
    8387                                ),
    … …  
    8892                                                option( '1', __( 'On', 'bimo-ifc-viewer' ) ),
    8993                                                option( '0', __( 'Off', 'bimo-ifc-viewer' ) ),
    90                                         ] )
     94                                        ] ),
     95                                        text( 'layers', __( 'Data layers (https URL)', 'bimo-ifc-viewer' ), __( 'A layers document (GeoJSON, sensors) shown with the model.', 'bimo-ifc-viewer' ) ),
     96                                        text( 'flood', __( 'Flood simulation', 'bimo-ifc-viewer' ), __( 'shower, storm, intense or extreme, then optional 1m/2m/5m, free/closed and sealed/compacted/loam/sandy, comma-separated.', 'bimo-ifc-viewer' ) )
     97                                ),
     98                                el( c.PanelBody, { title: __( 'Viewer tools', 'bimo-ifc-viewer' ), initialOpen: false },
     99                                        select( 'toolbar', __( 'Toolbar', 'bimo-ifc-viewer' ), [ option( '', __( 'Automatic', 'bimo-ifc-viewer' ) ), option( '1', __( 'Show', 'bimo-ifc-viewer' ) ), option( '0', __( 'Hide', 'bimo-ifc-viewer' ) ) ] ),
     100                                        text( 'tools', __( 'Toolbar tools', 'bimo-ifc-viewer' ), __( 'validate, measure (comma-separated), or none.', 'bimo-ifc-viewer' ) ),
     101                                        text( 'panels', __( 'Side panels', 'bimo-ifc-viewer' ), __( 'properties, scene, measurement, section, plans, map, solar, flood, devices, pointcloud, mesh (comma-separated), or none.', 'bimo-ifc-viewer' ) ),
     102                                        el( c.ToggleControl, { label: __( 'Frame the model when it loads', 'bimo-ifc-viewer' ), checked: a.autoframe !== '0', onChange: function ( v ) { set( { autoframe: v ? '' : '0' } ); } } ),
     103                                        text( 'fill', __( 'Share of the frame the model fills', 'bimo-ifc-viewer' ), __( 'From 0.2 to 0.98, for example 0.85.', 'bimo-ifc-viewer' ) ),
     104                                        text( 'rule', __( 'Open on a validation rule', 'bimo-ifc-viewer' ), __( 'A rule id such as RULE_MISSING_NAME.', 'bimo-ifc-viewer' ) ),
     105                                        el( c.ToggleControl, { label: __( 'Full-screen button', 'bimo-ifc-viewer' ), checked: a.fullscreen === '1', onChange: function ( v ) { set( { fullscreen: v ? '1' : '' } ); } } )
     106                                ),
     107                                el( c.PanelBody, { title: __( 'Click to load', 'bimo-ifc-viewer' ), initialOpen: false },
     108                                        select( 'load', __( 'Loading', 'bimo-ifc-viewer' ), [
     109                                                option( '', __( 'Site default', 'bimo-ifc-viewer' ) ),
     110                                                option( 'auto', __( 'With the page', 'bimo-ifc-viewer' ) ),
     111                                                option( 'click', __( 'Poster; load when the visitor clicks', 'bimo-ifc-viewer' ) ),
     112                                        ] ),
     113                                        el( be.MediaUploadCheck, null,
     114                                                el( be.MediaUpload, {
     115                                                        allowedTypes: [ 'image' ],
     116                                                        value: Number( a.poster ) || undefined,
     117                                                        onSelect: function ( m ) { set( { poster: String( m.id ) } ); },
     118                                                        render: function ( o ) {
     119                                                                return el( c.Button, { variant: 'secondary', onClick: o.open }, a.poster ? __( 'Replace poster image', 'bimo-ifc-viewer' ) : __( 'Choose a poster image', 'bimo-ifc-viewer' ) );
     120                                                        },
     121                                                } )
     122                                        ),
     123                                        a.poster ? el( c.Button, { variant: 'link', isDestructive: true, onClick: function () { set( { poster: '' } ); } }, __( 'Remove poster image', 'bimo-ifc-viewer' ) ) : null,
     124                                        text( 'poster_title', __( 'Poster title', 'bimo-ifc-viewer' ) ),
     125                                        text( 'poster_text', __( 'Poster text', 'bimo-ifc-viewer' ) ),
     126                                        text( 'launch_label', __( 'Button label', 'bimo-ifc-viewer' ) )
     127                                ),
     128                                el( c.PanelBody, { title: __( 'Events and forms', 'bimo-ifc-viewer' ), initialOpen: false },
     129                                        text( 'form_field', __( 'Fill this form field with the selected element', 'bimo-ifc-viewer' ), __( 'A CSS selector such as #your-element. Turn it on in Settings → Bimo IFC Viewer.', 'bimo-ifc-viewer' ) )
    91130                                )
    92131                        );
    … …  
    100139                save: function () { return null; },
    101140        } );
     141
     142        // A guided step: its inner blocks are the text; the settings drive the nearest viewer.
     143        wp.blocks.registerBlockType( 'bimo-ifc-viewer/step', {
     144                edit: function ( props ) {
     145                        var a = props.attributes;
     146                        var set = props.setAttributes;
     147                        function text( key, label, help ) {
     148                                return el( c.TextControl, { label: label, help: help, value: a[ key ], onChange: function ( v ) { var o = {}; o[ key ] = v; set( o ); } } );
     149                        }
     150                        var inspector = el( be.InspectorControls, null,
     151                                el( c.PanelBody, { title: __( 'What the viewer shows', 'bimo-ifc-viewer' ), initialOpen: true },
     152                                        el( c.SelectControl, { label: __( 'View', 'bimo-ifc-viewer' ), value: a.view, onChange: function ( v ) { set( { view: v } ); },
     153                                                options: [ '', 'iso', 'top', 'front', 'back', 'left', 'right', 'bottom' ].map( function ( v ) { return option( v, v || __( 'Keep the camera', 'bimo-ifc-viewer' ) ); } ) } ),
     154                                        text( 'select', __( 'Select an element (GlobalId)', 'bimo-ifc-viewer' ), __( 'The 22-character IFC GlobalId.', 'bimo-ifc-viewer' ) ),
     155                                        text( 'isolate', __( 'Isolate an IFC class', 'bimo-ifc-viewer' ), __( 'For example IfcWall, or none to show everything again.', 'bimo-ifc-viewer' ) ),
     156                                        text( 'azimuth', __( 'Azimuth (degrees)', 'bimo-ifc-viewer' ) ),
     157                                        text( 'elevation', __( 'Elevation (degrees)', 'bimo-ifc-viewer' ) ),
     158                                        text( 'fill', __( 'Share of the frame (0.2–0.98)', 'bimo-ifc-viewer' ) )
     159                                )
     160                        );
     161                        return el( 'div', be.useBlockProps( { className: 'ifcvo-step' } ), inspector,
     162                                el( be.InnerBlocks, { template: [ [ 'core/paragraph', { placeholder: __( 'Text of this step…', 'bimo-ifc-viewer' ) } ] ] } ) );
     163                },
     164                save: function () { return el( be.InnerBlocks.Content ); },
     165        } );
    102166} )( window.wp );
  • bimo-ifc-viewer/tags/1.2.0/block.json

    r3815325 r3815470  
    1515                "name": { "type": "string", "default": "" },
    1616                "height": { "type": "number", "default": 600 },
    17                 "ui": { "type": "string", "default": "article" },
     17                "ui": { "type": "string", "default": "" },
    1818                "view": { "type": "string", "default": "iso" },
    1919                "wheel": { "type": "string", "default": "ctrl" },
    … …  
    3434                "site": { "type": "string", "default": "" },
    3535                "drawings": { "type": "string", "default": "" },
    36                 "explore": { "type": "string", "default": "" }
     36                "explore": { "type": "string", "default": "" },
     37                "toolbar": { "type": "string", "default": "" },
     38                "tools": { "type": "string", "default": "" },
     39                "panels": { "type": "string", "default": "" },
     40                "autoframe": { "type": "string", "default": "" },
     41                "fill": { "type": "string", "default": "" },
     42                "layers": { "type": "string", "default": "" },
     43                "rule": { "type": "string", "default": "" },
     44                "flood": { "type": "string", "default": "" },
     45                "fullscreen": { "type": "string", "default": "" },
     46                "load": { "type": "string", "default": "" },
     47                "poster": { "type": [ "number", "string" ], "default": "" },
     48                "poster_title": { "type": "string", "default": "" },
     49                "poster_text": { "type": "string", "default": "" },
     50                "launch_label": { "type": "string", "default": "" },
     51                "form_field": { "type": "string", "default": "" }
    3752        },
    3853        "editorScript": "ifcvo-block-editor"
  • bimo-ifc-viewer/tags/1.2.0/readme.txt

    r3815325 r3815470  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.1.0
     7Stable tag: 1.2.0
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
    … …  
    2929* 10 interface languages.
    3030
    31 The plugin holds no copy of the viewer and adds nothing to your pages except the embed: no scripts on the front end, no settings, no database tables.
     31The plugin holds no copy of the viewer. On pages with a viewer it adds one small bundled script (frontend.js, no remote code) for click-to-load, events and guided steps. It stores one option (its settings) and no database tables.
    3232
    3333== External services ==
    … …  
    3636
    3737* **What is sent and when:** when a visitor opens a page with an IFC Viewer block or `[ifc_viewer]` shortcode, their browser loads the viewer in an iframe from www.ifcvieweronline.eu. The iframe address carries the block settings and the address of the model (and of any point cloud or scene). The visitor's browser then downloads the model straight from your site, or from the URL you gave: the file is not uploaded to or stored by IFC Viewer Online.
     38* **Click to load:** with `load="click"` (or the site-wide setting) nothing is requested from www.ifcvieweronline.eu until the visitor clicks the poster's button; the poster says where the viewer comes from.
     39* **No tracking:** the bundled front-end script sends nothing anywhere. Pushing events to your own `window.dataLayer` is off unless you turn it on.
    3840* **Map:** only when you turn on the map, the viewer loads map tiles, terrain and building data from third-party map providers listed in the viewer's privacy policy.
    3941* Terms of use: https://www.ifcvieweronline.eu/terms
    … …  
    8890* `solar` (`MM-DDTHH:MM` or `YYYY-MM-DDTHH:MM`, site time), `moon` (1), `analysis` (for example `year`, `year:passive`, `summer:sun`), `site` (`lat,lon`).
    8991* `drawings` (`plan`), `explore` (1, 0).
     92* `toolbar` (1, 0), `tools` (`validate`, `measure`, both comma-separated, or `none`), `panels` (properties, scene, measurement, section, plans, map, solar, flood, devices, pointcloud, mesh, comma-separated, or `none`), `autoframe` (1, 0), `fill` (0.2–0.98, or a percentage 20–98), `layers` (https URL to a layers document), `rule` (a validation rule id such as `RULE_MISSING_NAME`), `flood` (`shower`, `storm`, `intense` or `extreme`, then optional `1m`/`2m`/`5m`, `free`/`closed`, `sealed`/`compacted`/`loam`/`sandy`), `fullscreen` (1: a full-screen button).
     93
     94Click to load (no request to ifcvieweronline.eu until the visitor clicks):
     95
     96`[ifc_viewer attachment="123" load="click" poster="456" poster_title="Duplex" poster_text="Two-family house, IFC 2x3" launch_label="Open the 3D model"]`
     97
     98* `load` (`auto`, `click`), `poster` (Media Library ID or https image URL), `poster_title`, `poster_text`, `launch_label`. The poster takes the viewer's height, so nothing moves when the model loads. It carries a note that the viewer loads from www.ifcvieweronline.eu (change it in the settings).
     99
     100Guided steps: each `[ifc_step]` drives the nearest viewer above it (or the first below) while it crosses the middle of the screen. Without JavaScript it is plain text. The **IFC Viewer Step** block does the same in the block editor.
     101
     102`[ifc_step view="front" isolate="IfcWall"]The walls carry the roof.[/ifc_step]`
     103`[ifc_step select="2O2Fr$t4X7Zf8NOew3FLOH"]This is the main door.[/ifc_step]`
     104
     105* `view` (iso, top, front, back, left, right, bottom), `select` (an IFC GlobalId), `isolate` (an IFC class, or `none`), `azimuth`, `elevation` (degrees), `fill` (0.2–0.98).
     106
     107== Settings ==
     108
     109Settings → Bimo IFC Viewer sets site-wide defaults: accent colour, language, interface, background, loading mode (with the page or click to load), default poster and the consent text. A block or shortcode setting always wins. Two opt-in switches, both off by default:
     110
     111* **Fill a form field with the selected element:** with `form_field="#css-selector"` on an embed, clicking an element writes "Name (GlobalId)" into that input and fires `input` and `change`, so it works with Contact Form 7, WPForms, Gravity Forms or any plain form.
     112* **Push viewer events to window.dataLayer** (only if the page already has one): `bimo_ifc_model_loaded`, `bimo_ifc_validation_completed` (with `score`), `bimo_ifc_element_selected` (with `ifc_type`, never names or IDs), `bimo_ifc_tour_started`, `bimo_ifc_tour_ended`.
     113
     114== Events and JavaScript API ==
     115
     116Each viewer event is dispatched on the viewer's wrapper (`.ifcvo-embed`) as a DOM CustomEvent named `bimo-ifc:<event>`, which bubbles; the payload is in `event.detail`. Events include `ready`, `model-loaded`, `model-error`, `validation-completed`, `element-selected` (`name`, `globalId`, `ifcType`, `expressId`, `modelId`), `measurements-changed`, `tour-started`, `tour-step` and `tour-ended`. Only messages from https://www.ifcvieweronline.eu are accepted.
     117
     118`document.addEventListener( 'bimo-ifc:element-selected', function ( e ) { console.log( e.detail.name, e.detail.globalId ); } );`
     119
     120`window.BimoIFC.get( elementOrSelector )` returns the commands of one viewer (commands wait until the model has loaded):
     121
     122* `select( globalId )`, `isolate( 'IfcWall' )` (nothing to show all), `setView( 'top' )`, `frame( { view, fill, azimuth, elevation } )`, `startTour( 'client-walkthrough' )`, `load()` (behind a poster), `on( event, callback )` (returns an unsubscribe function), `whenReady()`.
    90123
    91124== Screenshots ==
    … …  
    97130
    98131== Changelog ==
     132
     133= 1.2.0 =
     134* Click to load: a poster with title, text, button and consent note; the viewer loads from ifcvieweronline.eu only when the visitor clicks.
     135* Settings page (Settings → Bimo IFC Viewer) with site-wide defaults.
     136* Viewer events as DOM events (`bimo-ifc:<event>`), the `window.BimoIFC` API, opt-in form field filling and opt-in dataLayer push.
     137* Guided steps: `[ifc_step]` shortcode and IFC Viewer Step block.
     138* New parameters: toolbar, tools, panels, autoframe, fill, layers, rule, flood, fullscreen; the block now has controls for language, background, moon and model names too.
    99139
    100140= 1.1.0 =
    … …  
    108148== Upgrade Notice ==
    109149
     150= 1.2.0 =
     151Click to load with a consent note, site-wide settings, events for your forms and scripts, and guided scroll steps. Existing embeds render as before.
     152
    110153= 1.1.0 =
    111154Federated models, point clouds, map, sun studies, plan cut and digital twin scenes.
  • bimo-ifc-viewer/trunk/bimo-ifc-viewer.php

    r3815325 r3815470  
    44 * Plugin URI:        https://github.com/j03rul4nd/ifc-viewer-online/tree/main/integrations/wordpress
    55 * Description:       Embed interactive 3D IFC (BIM) models in posts and pages: Health Score, federated models, point clouds, the model on the map, sun studies, plan cuts and digital twin scenes. Block and [ifc_viewer] shortcode.
    6  * Version:           1.1.0
     6 * Version:           1.2.0
    77 * Requires at least: 6.1
    88 * Requires PHP:      7.4
    … …  
    2222}
    2323
    24 define( 'IFCVO_VERSION', '1.1.0' );
     24define( 'IFCVO_VERSION', '1.2.0' );
    2525define( 'IFCVO_APP_URL', 'https://www.ifcvieweronline.eu/' );
    2626define( 'IFCVO_APP_ORIGIN', 'https://www.ifcvieweronline.eu' );
    … …  
    4949                'drawings'  => array( 'plan' ),
    5050                'explore'   => array( '1', '0' ),
     51                'toolbar'   => array( '1', '0' ),
     52                // "none" is the shortcode's way to say `tools=` (no tools at all).
     53                'tools'     => '/^(none|(validate|measure)(,(validate|measure))?)$/',
     54                'panels'    => '/^(none|(properties|scene|measurement|section|plans|map|solar|flood|devices|pointcloud|mesh)(,(properties|scene|measurement|section|plans|map|solar|flood|devices|pointcloud|mesh)){0,10})$/',
     55                'autoframe' => array( '1', '0' ),
     56                'fill'      => '/^(0?\.\d{1,3}|[2-9]\d)$/',
     57                'rule'      => '/^RULE_[A-Z0-9_]{2,60}$/',
     58                'flood'     => '/^(shower|storm|intense|extreme)(,(1m|2m|5m|free|closed|sealed|compacted|loam|sandy)){0,3}$/',
    5159        );
    5260}
    … …  
    5967                'name'       => '',
    6068                'height'     => 600,
    61                 'ui'         => 'article',
     69                'ui'         => '',
    6270                'view'       => 'iso',
    6371                'wheel'      => 'ctrl',
    … …  
    7886                'drawings'   => '',
    7987                'explore'    => '',
    80         );
     88                // 1.2.0
     89                'toolbar'    => '',
     90                'tools'      => '',
     91                'panels'     => '',
     92                'autoframe'  => '',
     93                'fill'       => '',
     94                'layers'     => '',
     95                'rule'       => '',
     96                'flood'      => '',
     97                'fullscreen' => '',
     98                'load'       => '',
     99                'poster'     => '',
     100                'poster_title' => '',
     101                'poster_text'  => '',
     102                'launch_label' => '',
     103                'form_field'   => '',
     104        );
     105}
     106
     107/** Site-wide settings (Settings → Bimo IFC Viewer), with their defaults. */
     108function ifcvo_settings() {
     109        $saved = get_option( 'ifcvo_settings', array() );
     110        return wp_parse_args(
     111                is_array( $saved ) ? $saved : array(),
     112                array(
     113                        'accent'     => '',
     114                        'lang'       => '',
     115                        'ui'         => '',
     116                        'bg'         => '',
     117                        'load'       => 'auto',
     118                        'poster'     => '',
     119                        'consent'    => '',
     120                        'form_field' => '0',
     121                        'datalayer'  => '0',
     122                )
     123        );
     124}
     125
     126/** Empty attributes take the site-wide default; 1.1.0 embeds stay as they were. */
     127function ifcvo_apply_settings( $atts ) {
     128        $settings = ifcvo_settings();
     129        foreach ( array( 'accent', 'lang', 'bg' ) as $key ) {
     130                if ( '' === trim( (string) $atts[ $key ] ) && '' !== $settings[ $key ] ) {
     131                        $atts[ $key ] = $settings[ $key ];
     132                }
     133        }
     134        if ( '' === trim( (string) $atts['ui'] ) ) {
     135                $atts['ui'] = '' !== $settings['ui'] ? $settings['ui'] : 'article';
     136        }
     137        if ( ! in_array( $atts['load'], array( 'auto', 'click' ), true ) ) {
     138                $atts['load'] = 'click' === $settings['load'] ? 'click' : 'auto';
     139        }
     140        if ( '' === trim( (string) $atts['poster'] ) ) {
     141                $atts['poster'] = $settings['poster'];
     142        }
     143        return $atts;
    81144}
    82145
    … …  
    164227                $query['scan'] = implode( ',', $scan );
    165228        }
     229        $layers = ifcvo_https_list( $atts['layers'], 1 );
     230        if ( $layers ) {
     231                $query['layers'] = $layers[0];
     232        }
    166233        foreach ( ifcvo_param_rules() as $key => $rule ) {
    167234                $value = trim( (string) $atts[ $key ] );
    … …  
    175242                if ( 'accent' === $key ) {
    176243                        $value = ltrim( $value, '#' );
     244                }
     245                if ( ( 'tools' === $key || 'panels' === $key ) && 'none' === $value ) {
     246                        $value = '';
    177247                }
    178248                // The viewer's defaults need no parameter.
    … …  
    190260}
    191261
     262/** The poster image URL: a Media Library ID or an https URL. */
     263function ifcvo_poster_url( $poster ) {
     264        $poster = trim( (string) $poster );
     265        if ( '' === $poster ) {
     266                return '';
     267        }
     268        if ( ctype_digit( $poster ) ) {
     269                $url = wp_get_attachment_image_url( absint( $poster ), 'large' );
     270                return $url ? $url : '';
     271        }
     272        return esc_url_raw( $poster, array( 'https' ) );
     273}
     274
     275/** Loads the bundled front-end script, only on pages that render a viewer or a step. */
     276function ifcvo_enqueue_frontend() {
     277        wp_enqueue_script( 'ifcvo-frontend', plugins_url( 'frontend.js', __FILE__ ), array(), IFCVO_VERSION, true );
     278}
     279
     280/** The data-* attributes the front-end script reads, already escaped. */
     281function ifcvo_data_attributes( $atts, $settings ) {
     282        $data = array();
     283        if ( '1' === (string) $atts['fullscreen'] ) {
     284                $data['fullscreen'] = '1';
     285        }
     286        $field = trim( (string) $atts['form_field'] );
     287        // Opt-in: filling form fields stays off until the site owner turns it on.
     288        if ( '' !== $field && '1' === $settings['form_field'] && preg_match( '/^[A-Za-z0-9_\-#.\[\]="\' :]{1,120}$/', $field ) ) {
     289                $data['form-field'] = $field;
     290        }
     291        if ( '1' === $settings['datalayer'] ) {
     292                $data['datalayer'] = '1';
     293        }
     294        $out = '';
     295        foreach ( $data as $key => $value ) {
     296                $out .= ' data-ifcvo-' . $key . '="' . esc_attr( $value ) . '"';
     297        }
     298        return $out;
     299}
     300
    192301/** The iframe markup shared by the shortcode and the block. */
    193302function ifcvo_render( $atts, $wrapper = 'class="ifcvo-embed"' ) {
    194         $atts = shortcode_atts( ifcvo_default_atts(), (array) $atts, 'ifc_viewer' );
     303        $atts = ifcvo_apply_settings( shortcode_atts( ifcvo_default_atts(), (array) $atts, 'ifc_viewer' ) );
    195304        $src  = ifcvo_build_embed_url( $atts );
    196305        if ( '' === $src ) {
    … …  
    200309                return '';
    201310        }
    202         $height = max( 200, min( 2000, absint( $atts['height'] ) ) );
    203         $title  = '' !== trim( (string) $atts['title'] ) ? $atts['title'] : __( 'Interactive 3D IFC model', 'bimo-ifc-viewer' );
    204         return sprintf(
    205                 '<div %4$s><iframe src="%1$s" width="100%%" height="%2$d" style="border:0;border-radius:12px;max-width:100%%;display:block" loading="lazy" allow="fullscreen" title="%3$s"></iframe></div>',
    206                 esc_url( $src ),
    207                 $height,
    208                 esc_attr( $title ),
    209                 $wrapper
    210         );
     311        ifcvo_enqueue_frontend();
     312        $settings = ifcvo_settings();
     313        $height   = max( 200, min( 2000, absint( $atts['height'] ) ) );
     314        $title    = '' !== trim( (string) $atts['title'] ) ? $atts['title'] : __( 'Interactive 3D IFC model', 'bimo-ifc-viewer' );
     315        $wrapper .= ifcvo_data_attributes( $atts, $settings );
     316        if ( 'click' !== $atts['load'] ) {
     317                return sprintf(
     318                        '<div %4$s><iframe src="%1$s" width="100%%" height="%2$d" style="border:0;border-radius:12px;max-width:100%%;display:block" loading="lazy" allow="fullscreen" title="%3$s"></iframe></div>',
     319                        esc_url( $src ),
     320                        $height,
     321                        esc_attr( $title ),
     322                        $wrapper
     323                );
     324        }
     325
     326        // Click to load: nothing is requested from ifcvieweronline.eu until the visitor asks.
     327        $poster  = ifcvo_poster_url( $atts['poster'] );
     328        $heading = '' !== trim( (string) $atts['poster_title'] ) ? $atts['poster_title'] : $title;
     329        $text    = trim( (string) $atts['poster_text'] );
     330        $label   = '' !== trim( (string) $atts['launch_label'] ) ? $atts['launch_label'] : __( 'Load the 3D model', 'bimo-ifc-viewer' );
     331        $consent = '' !== trim( (string) $settings['consent'] ) ? $settings['consent'] : __( 'The 3D viewer loads from www.ifcvieweronline.eu when you click. Your browser then downloads the model from this site.', 'bimo-ifc-viewer' );
     332        // The poster takes the iframe's height, so loading the model shifts nothing.
     333        $style = 'position:relative;height:' . $height . 'px;border-radius:12px;overflow:hidden;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:24px;box-sizing:border-box;text-align:center;color:#fff;background:#1d2430';
     334        $html  = '<div ' . $wrapper . ' data-ifcvo-load="click" data-ifcvo-src="' . esc_url( $src ) . '" data-ifcvo-height="' . esc_attr( (string) $height ) . '" data-ifcvo-title="' . esc_attr( $title ) . '">';
     335        $html .= '<div class="ifcvo-poster" style="' . esc_attr( $style ) . '">';
     336        if ( $poster ) {
     337                $html .= '<img src="' . esc_url( $poster ) . '" alt="" loading="lazy" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover;opacity:.45;margin:0;max-width:none">';
     338        }
     339        $html .= '<p class="ifcvo-poster-title" style="position:relative;margin:0;font-size:1.25em;font-weight:600">' . esc_html( $heading ) . '</p>';
     340        if ( '' !== $text ) {
     341                $html .= '<p class="ifcvo-poster-text" style="position:relative;margin:0;max-width:40em">' . esc_html( $text ) . '</p>';
     342        }
     343        $html .= '<button type="button" class="ifcvo-launch" style="position:relative;cursor:pointer;padding:10px 18px;border-radius:8px;border:0;font:inherit;font-weight:600;background:#fff;color:#1d2430">' . esc_html( $label ) . '</button>';
     344        $html .= '<p class="ifcvo-consent" style="position:relative;margin:0;font-size:.8em;opacity:.85;max-width:40em">' . esc_html( $consent ) . '</p>';
     345        // Without JavaScript the button does nothing: offer a plain link instead.
     346        $html .= '<noscript><a href="' . esc_url( remove_query_arg( 'embed', $src ) ) . '" target="_blank" rel="noopener" style="position:relative;color:#fff">' . esc_html__( 'Open the model on ifcvieweronline.eu', 'bimo-ifc-viewer' ) . '</a></noscript>';
     347        $html .= '</div></div>';
     348        return $html;
     349}
     350
     351/**
     352 * [ifc_step view="front" select="GUID" isolate="IfcWall"]Text[/ifc_step]
     353 *
     354 * A paragraph of a guided story: while it crosses the middle of the screen the
     355 * nearest viewer above it (or the first one below) shows what the step says.
     356 * Without JavaScript it is plain text.
     357 */
     358function ifcvo_step_attributes( $atts ) {
     359        $atts  = shortcode_atts(
     360                array(
     361                        'view'      => '',
     362                        'select'    => '',
     363                        'isolate'   => '',
     364                        'azimuth'   => '',
     365                        'elevation' => '',
     366                        'fill'      => '',
     367                ),
     368                (array) $atts,
     369                'ifc_step'
     370        );
     371        $rules = array(
     372                'view'      => '/^(iso|top|front|back|left|right|bottom)$/',
     373                'select'    => '/^[0-9A-Za-z_$]{22}$/',
     374                'isolate'   => '/^(none|[A-Za-z]{3,60})$/',
     375                'azimuth'   => '/^-?\d{1,3}(\.\d+)?$/',
     376                'elevation' => '/^-?\d{1,2}(\.\d+)?$/',
     377                'fill'      => '/^0?\.\d{1,3}$/',
     378        );
     379        $out   = '';
     380        foreach ( $rules as $key => $rule ) {
     381                $value = trim( (string) $atts[ $key ] );
     382                if ( '' !== $value && preg_match( $rule, $value ) ) {
     383                        $out .= ' data-' . $key . '="' . esc_attr( $value ) . '"';
     384                }
     385        }
     386        return $out;
     387}
     388
     389function ifcvo_render_step( $atts, $content = '' ) {
     390        ifcvo_enqueue_frontend();
     391        return '<div class="ifcvo-step"' . ifcvo_step_attributes( $atts ) . '>' . do_shortcode( (string) $content ) . '</div>';
     392}
     393add_shortcode( 'ifc_step', 'ifcvo_render_step' );
     394
     395/** The step block keeps its inner blocks (the text) as saved content. */
     396function ifcvo_render_step_block( $atts, $content ) {
     397        ifcvo_enqueue_frontend();
     398        return '<div ' . get_block_wrapper_attributes( array( 'class' => 'ifcvo-step' ) ) . ifcvo_step_attributes( $atts ) . '>' . $content . '</div>';
    211399}
    212400
    … …  
    216404}
    217405
    218 add_shortcode( 'ifc_viewer', 'ifcvo_render' );
     406/** Shortcode callback: WordPress passes the content as the second argument, which is not a wrapper. */
     407function ifcvo_shortcode( $atts ) {
     408        return ifcvo_render( $atts );
     409}
     410add_shortcode( 'ifc_viewer', 'ifcvo_shortcode' );
    219411
    220412/** Gutenberg block (no build step: the editor script uses the wp.* globals). */
    … …  
    230422                __DIR__ . '/block.json',
    231423                array( 'render_callback' => 'ifcvo_render_block' )
     424        );
     425        register_block_type(
     426                __DIR__ . '/step/block.json',
     427                array( 'render_callback' => 'ifcvo_render_step_block' )
    232428        );
    233429}
    … …  
    330526        exit;
    331527}
     528
     529/*
     530 * Settings → Bimo IFC Viewer: site-wide defaults. Every embed can override them.
     531 */
     532function ifcvo_sanitize_settings( $input ) {
     533        $input = is_array( $input ) ? $input : array();
     534        $rules = ifcvo_param_rules();
     535        $out   = array();
     536        foreach ( array( 'accent', 'lang', 'ui', 'bg' ) as $key ) {
     537                $value       = isset( $input[ $key ] ) ? sanitize_text_field( wp_unslash( $input[ $key ] ) ) : '';
     538                $rule        = $rules[ $key ];
     539                $ok          = is_array( $rule ) ? in_array( $value, $rule, true ) : (bool) preg_match( $rule, $value );
     540                $out[ $key ] = $ok ? $value : '';
     541        }
     542        $out['load']       = isset( $input['load'] ) && 'click' === $input['load'] ? 'click' : 'auto';
     543        $poster            = isset( $input['poster'] ) ? trim( sanitize_text_field( wp_unslash( $input['poster'] ) ) ) : '';
     544        $out['poster']     = ctype_digit( $poster ) ? (string) absint( $poster ) : esc_url_raw( $poster, array( 'https' ) );
     545        $out['consent']    = isset( $input['consent'] ) ? sanitize_textarea_field( wp_unslash( $input['consent'] ) ) : '';
     546        $out['form_field'] = empty( $input['form_field'] ) ? '0' : '1';
     547        $out['datalayer']  = empty( $input['datalayer'] ) ? '0' : '1';
     548        return $out;
     549}
     550
     551function ifcvo_register_settings() {
     552        register_setting(
     553                'ifcvo_settings_group',
     554                'ifcvo_settings',
     555                array(
     556                        'type'              => 'array',
     557                        'sanitize_callback' => 'ifcvo_sanitize_settings',
     558                        'default'           => array(),
     559                )
     560        );
     561}
     562add_action( 'admin_init', 'ifcvo_register_settings' );
     563
     564function ifcvo_settings_menu() {
     565        add_options_page(
     566                __( 'Bimo IFC Viewer', 'bimo-ifc-viewer' ),
     567                __( 'Bimo IFC Viewer', 'bimo-ifc-viewer' ),
     568                'manage_options',
     569                'bimo-ifc-viewer',
     570                'ifcvo_settings_page'
     571        );
     572}
     573add_action( 'admin_menu', 'ifcvo_settings_menu' );
     574
     575function ifcvo_settings_link( $links ) {
     576        $links[] = '<a href="' . esc_url( admin_url( 'options-general.php?page=bimo-ifc-viewer' ) ) . '">' . esc_html__( 'Settings', 'bimo-ifc-viewer' ) . '</a>';
     577        return $links;
     578}
     579add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'ifcvo_settings_link' );
     580
     581/** One select box of the settings page. */
     582function ifcvo_settings_select( $key, $value, $options ) {
     583        echo '<select id="ifcvo-' . esc_attr( $key ) . '" name="ifcvo_settings[' . esc_attr( $key ) . ']">';
     584        foreach ( $options as $option => $label ) {
     585                echo '<option value="' . esc_attr( $option ) . '"' . selected( $value, $option, false ) . '>' . esc_html( $label ) . '</option>';
     586        }
     587        echo '</select>';
     588}
     589
     590function ifcvo_settings_page() {
     591        if ( ! current_user_can( 'manage_options' ) ) {
     592                return;
     593        }
     594        $s     = ifcvo_settings();
     595        $rules = ifcvo_param_rules();
     596        $langs = array( '' => __( 'Visitor language', 'bimo-ifc-viewer' ) );
     597        foreach ( $rules['lang'] as $lang ) {
     598                $langs[ $lang ] = $lang;
     599        }
     600        ?>
     601        <div class="wrap">
     602                <h1><?php esc_html_e( 'Bimo IFC Viewer', 'bimo-ifc-viewer' ); ?></h1>
     603                <p><?php esc_html_e( 'Defaults for every IFC Viewer block and [ifc_viewer] shortcode of this site. A setting given on a block or shortcode wins.', 'bimo-ifc-viewer' ); ?></p>
     604                <form method="post" action="options.php">
     605                        <?php settings_fields( 'ifcvo_settings_group' ); ?>
     606                        <table class="form-table" role="presentation">
     607                                <tr>
     608                                        <th scope="row"><label for="ifcvo-ui"><?php esc_html_e( 'Interface', 'bimo-ifc-viewer' ); ?></label></th>
     609                                        <td>
     610                                        <?php
     611                                        ifcvo_settings_select(
     612                                                'ui',
     613                                                $s['ui'],
     614                                                array(
     615                                                        ''        => __( 'Article (default)', 'bimo-ifc-viewer' ),
     616                                                        'minimal' => __( 'Minimal', 'bimo-ifc-viewer' ),
     617                                                        'full'    => __( 'Full app', 'bimo-ifc-viewer' ),
     618                                                        'kiosk'   => __( 'Kiosk', 'bimo-ifc-viewer' ),
     619                                                        'client'  => __( 'Client presentation', 'bimo-ifc-viewer' ),
     620                                                )
     621                                        );
     622                                        ?>
     623                                        </td>
     624                                </tr>
     625                                <tr>
     626                                        <th scope="row"><label for="ifcvo-lang"><?php esc_html_e( 'Language', 'bimo-ifc-viewer' ); ?></label></th>
     627                                        <td><?php ifcvo_settings_select( 'lang', $s['lang'], $langs ); ?></td>
     628                                </tr>
     629                                <tr>
     630                                        <th scope="row"><label for="ifcvo-accent"><?php esc_html_e( 'Accent colour (hex)', 'bimo-ifc-viewer' ); ?></label></th>
     631                                        <td><input type="text" id="ifcvo-accent" name="ifcvo_settings[accent]" value="<?php echo esc_attr( $s['accent'] ); ?>" placeholder="#3366ff" class="regular-text"></td>
     632                                </tr>
     633                                <tr>
     634                                        <th scope="row"><label for="ifcvo-bg"><?php esc_html_e( 'Background', 'bimo-ifc-viewer' ); ?></label></th>
     635                                        <td><input type="text" id="ifcvo-bg" name="ifcvo_settings[bg]" value="<?php echo esc_attr( $s['bg'] ); ?>" placeholder="paper" class="regular-text">
     636                                        <p class="description"><?php esc_html_e( 'white, paper, blueprint, sky, studio, or one or two hex colours without # (top,bottom).', 'bimo-ifc-viewer' ); ?></p></td>
     637                                </tr>
     638                                <tr>
     639                                        <th scope="row"><label for="ifcvo-load"><?php esc_html_e( 'Loading', 'bimo-ifc-viewer' ); ?></label></th>
     640                                        <td>
     641                                        <?php
     642                                        ifcvo_settings_select(
     643                                                'load',
     644                                                $s['load'],
     645                                                array(
     646                                                        'auto'  => __( 'Load the viewer with the page', 'bimo-ifc-viewer' ),
     647                                                        'click' => __( 'Show a poster; load the viewer when the visitor clicks', 'bimo-ifc-viewer' ),
     648                                                )
     649                                        );
     650                                        ?>
     651                                        <p class="description"><?php esc_html_e( 'With click to load, nothing is requested from ifcvieweronline.eu until the visitor asks for the model.', 'bimo-ifc-viewer' ); ?></p></td>
     652                                </tr>
     653                                <tr>
     654                                        <th scope="row"><label for="ifcvo-poster"><?php esc_html_e( 'Default poster image', 'bimo-ifc-viewer' ); ?></label></th>
     655                                        <td><input type="text" id="ifcvo-poster" name="ifcvo_settings[poster]" value="<?php echo esc_attr( $s['poster'] ); ?>" class="regular-text">
     656                                        <p class="description"><?php esc_html_e( 'A Media Library ID or an https image URL.', 'bimo-ifc-viewer' ); ?></p></td>
     657                                </tr>
     658                                <tr>
     659                                        <th scope="row"><label for="ifcvo-consent"><?php esc_html_e( 'Consent text on the poster', 'bimo-ifc-viewer' ); ?></label></th>
     660                                        <td><textarea id="ifcvo-consent" name="ifcvo_settings[consent]" rows="3" class="large-text"><?php echo esc_textarea( $s['consent'] ); ?></textarea>
     661                                        <p class="description"><?php esc_html_e( 'Leave empty for the default note that the viewer loads from www.ifcvieweronline.eu.', 'bimo-ifc-viewer' ); ?></p></td>
     662                                </tr>
     663                                <tr>
     664                                        <th scope="row"><?php esc_html_e( 'Form fields', 'bimo-ifc-viewer' ); ?></th>
     665                                        <td><label><input type="checkbox" name="ifcvo_settings[form_field]" value="1" <?php checked( '1', $s['form_field'] ); ?>> <?php esc_html_e( 'Fill a form field with the selected element (form_field="#css-selector" on the embed)', 'bimo-ifc-viewer' ); ?></label></td>
     666                                </tr>
     667                                <tr>
     668                                        <th scope="row"><?php esc_html_e( 'Analytics', 'bimo-ifc-viewer' ); ?></th>
     669                                        <td><label><input type="checkbox" name="ifcvo_settings[datalayer]" value="1" <?php checked( '1', $s['datalayer'] ); ?>> <?php esc_html_e( 'Push viewer events to window.dataLayer (Google Tag Manager), if the page has one', 'bimo-ifc-viewer' ); ?></label></td>
     670                                </tr>
     671                        </table>
     672                        <?php submit_button(); ?>
     673                </form>
     674        </div>
     675        <?php
     676}
  • bimo-ifc-viewer/trunk/block-editor.js

    r3815325 r3815470  
    5555                                el( c.PanelBody, { title: __( 'Display', 'bimo-ifc-viewer' ), initialOpen: false },
    5656                                        el( c.SelectControl, { label: __( 'Interface', 'bimo-ifc-viewer' ), value: a.ui, onChange: function ( v ) { set( { ui: v } ); },
    57                                                 options: [ option( 'article', __( 'Article (clean, for posts)', 'bimo-ifc-viewer' ) ), option( 'minimal', __( 'Minimal', 'bimo-ifc-viewer' ) ), option( 'full', __( 'Full app', 'bimo-ifc-viewer' ) ), option( 'kiosk', __( 'Kiosk', 'bimo-ifc-viewer' ) ), option( 'client', __( 'Client presentation', 'bimo-ifc-viewer' ) ) ] } ),
     57                                                options: [ option( '', __( 'Site default', 'bimo-ifc-viewer' ) ), option( 'article', __( 'Article (clean, for posts)', 'bimo-ifc-viewer' ) ), option( 'minimal', __( 'Minimal', 'bimo-ifc-viewer' ) ), option( 'full', __( 'Full app', 'bimo-ifc-viewer' ) ), option( 'kiosk', __( 'Kiosk', 'bimo-ifc-viewer' ) ), option( 'client', __( 'Client presentation', 'bimo-ifc-viewer' ) ) ] } ),
    5858                                        el( c.SelectControl, { label: __( 'Starting view', 'bimo-ifc-viewer' ), value: a.view, onChange: function ( v ) { set( { view: v } ); },
    5959                                                options: [ 'iso', 'top', 'front', 'back', 'left', 'right' ].map( function ( v ) { return option( v, v ); } ) } ),
    … …  
    6262                                        el( c.ToggleControl, { label: __( 'Mouse wheel scrolls the page (zoom with Ctrl)', 'bimo-ifc-viewer' ), checked: a.wheel === 'ctrl', onChange: function ( v ) { set( { wheel: v ? 'ctrl' : 'always' } ); } } ),
    6363                                        el( c.TextControl, { label: __( 'Accent colour (hex)', 'bimo-ifc-viewer' ), value: a.accent, onChange: function ( v ) { set( { accent: v } ); } } ),
     64                                        select( 'lang', __( 'Language', 'bimo-ifc-viewer' ), [ '', 'en', 'es', 'ca', 'de', 'fr', 'it', 'pt', 'ja', 'zh', 'th' ].map( function ( v ) { return option( v, v || __( 'Site default', 'bimo-ifc-viewer' ) ); } ) ),
     65                                        text( 'bg', __( 'Background', 'bimo-ifc-viewer' ), __( 'white, paper, blueprint, sky, studio, or hex colours without # (top,bottom).', 'bimo-ifc-viewer' ) ),
     66                                        text( 'name', __( 'Model names (comma-separated)', 'bimo-ifc-viewer' ), __( 'Shown instead of the file names, in the same order as the models.', 'bimo-ifc-viewer' ) ),
    6467                                        el( c.TextControl, { label: __( 'Accessible title', 'bimo-ifc-viewer' ), value: a.title, onChange: function ( v ) { set( { title: v } ); } } )
    6568                                ),
    … …  
    8083                                        ] ),
    8184                                        text( 'site', __( 'Study the sun at another place (lat,lon)', 'bimo-ifc-viewer' ) ),
     85                                        el( c.ToggleControl, { label: __( 'Show the moon', 'bimo-ifc-viewer' ), checked: a.moon === '1', onChange: function ( v ) { set( { moon: v ? '1' : '' } ); } } ),
    8286                                        el( c.ToggleControl, { label: __( 'Open with a plan cut of the model', 'bimo-ifc-viewer' ), checked: a.drawings === 'plan', onChange: function ( v ) { set( { drawings: v ? 'plan' : '' } ); } } )
    8387                                ),
    … …  
    8892                                                option( '1', __( 'On', 'bimo-ifc-viewer' ) ),
    8993                                                option( '0', __( 'Off', 'bimo-ifc-viewer' ) ),
    90                                         ] )
     94                                        ] ),
     95                                        text( 'layers', __( 'Data layers (https URL)', 'bimo-ifc-viewer' ), __( 'A layers document (GeoJSON, sensors) shown with the model.', 'bimo-ifc-viewer' ) ),
     96                                        text( 'flood', __( 'Flood simulation', 'bimo-ifc-viewer' ), __( 'shower, storm, intense or extreme, then optional 1m/2m/5m, free/closed and sealed/compacted/loam/sandy, comma-separated.', 'bimo-ifc-viewer' ) )
     97                                ),
     98                                el( c.PanelBody, { title: __( 'Viewer tools', 'bimo-ifc-viewer' ), initialOpen: false },
     99                                        select( 'toolbar', __( 'Toolbar', 'bimo-ifc-viewer' ), [ option( '', __( 'Automatic', 'bimo-ifc-viewer' ) ), option( '1', __( 'Show', 'bimo-ifc-viewer' ) ), option( '0', __( 'Hide', 'bimo-ifc-viewer' ) ) ] ),
     100                                        text( 'tools', __( 'Toolbar tools', 'bimo-ifc-viewer' ), __( 'validate, measure (comma-separated), or none.', 'bimo-ifc-viewer' ) ),
     101                                        text( 'panels', __( 'Side panels', 'bimo-ifc-viewer' ), __( 'properties, scene, measurement, section, plans, map, solar, flood, devices, pointcloud, mesh (comma-separated), or none.', 'bimo-ifc-viewer' ) ),
     102                                        el( c.ToggleControl, { label: __( 'Frame the model when it loads', 'bimo-ifc-viewer' ), checked: a.autoframe !== '0', onChange: function ( v ) { set( { autoframe: v ? '' : '0' } ); } } ),
     103                                        text( 'fill', __( 'Share of the frame the model fills', 'bimo-ifc-viewer' ), __( 'From 0.2 to 0.98, for example 0.85.', 'bimo-ifc-viewer' ) ),
     104                                        text( 'rule', __( 'Open on a validation rule', 'bimo-ifc-viewer' ), __( 'A rule id such as RULE_MISSING_NAME.', 'bimo-ifc-viewer' ) ),
     105                                        el( c.ToggleControl, { label: __( 'Full-screen button', 'bimo-ifc-viewer' ), checked: a.fullscreen === '1', onChange: function ( v ) { set( { fullscreen: v ? '1' : '' } ); } } )
     106                                ),
     107                                el( c.PanelBody, { title: __( 'Click to load', 'bimo-ifc-viewer' ), initialOpen: false },
     108                                        select( 'load', __( 'Loading', 'bimo-ifc-viewer' ), [
     109                                                option( '', __( 'Site default', 'bimo-ifc-viewer' ) ),
     110                                                option( 'auto', __( 'With the page', 'bimo-ifc-viewer' ) ),
     111                                                option( 'click', __( 'Poster; load when the visitor clicks', 'bimo-ifc-viewer' ) ),
     112                                        ] ),
     113                                        el( be.MediaUploadCheck, null,
     114                                                el( be.MediaUpload, {
     115                                                        allowedTypes: [ 'image' ],
     116                                                        value: Number( a.poster ) || undefined,
     117                                                        onSelect: function ( m ) { set( { poster: String( m.id ) } ); },
     118                                                        render: function ( o ) {
     119                                                                return el( c.Button, { variant: 'secondary', onClick: o.open }, a.poster ? __( 'Replace poster image', 'bimo-ifc-viewer' ) : __( 'Choose a poster image', 'bimo-ifc-viewer' ) );
     120                                                        },
     121                                                } )
     122                                        ),
     123                                        a.poster ? el( c.Button, { variant: 'link', isDestructive: true, onClick: function () { set( { poster: '' } ); } }, __( 'Remove poster image', 'bimo-ifc-viewer' ) ) : null,
     124                                        text( 'poster_title', __( 'Poster title', 'bimo-ifc-viewer' ) ),
     125                                        text( 'poster_text', __( 'Poster text', 'bimo-ifc-viewer' ) ),
     126                                        text( 'launch_label', __( 'Button label', 'bimo-ifc-viewer' ) )
     127                                ),
     128                                el( c.PanelBody, { title: __( 'Events and forms', 'bimo-ifc-viewer' ), initialOpen: false },
     129                                        text( 'form_field', __( 'Fill this form field with the selected element', 'bimo-ifc-viewer' ), __( 'A CSS selector such as #your-element. Turn it on in Settings → Bimo IFC Viewer.', 'bimo-ifc-viewer' ) )
    91130                                )
    92131                        );
    … …  
    100139                save: function () { return null; },
    101140        } );
     141
     142        // A guided step: its inner blocks are the text; the settings drive the nearest viewer.
     143        wp.blocks.registerBlockType( 'bimo-ifc-viewer/step', {
     144                edit: function ( props ) {
     145                        var a = props.attributes;
     146                        var set = props.setAttributes;
     147                        function text( key, label, help ) {
     148                                return el( c.TextControl, { label: label, help: help, value: a[ key ], onChange: function ( v ) { var o = {}; o[ key ] = v; set( o ); } } );
     149                        }
     150                        var inspector = el( be.InspectorControls, null,
     151                                el( c.PanelBody, { title: __( 'What the viewer shows', 'bimo-ifc-viewer' ), initialOpen: true },
     152                                        el( c.SelectControl, { label: __( 'View', 'bimo-ifc-viewer' ), value: a.view, onChange: function ( v ) { set( { view: v } ); },
     153                                                options: [ '', 'iso', 'top', 'front', 'back', 'left', 'right', 'bottom' ].map( function ( v ) { return option( v, v || __( 'Keep the camera', 'bimo-ifc-viewer' ) ); } ) } ),
     154                                        text( 'select', __( 'Select an element (GlobalId)', 'bimo-ifc-viewer' ), __( 'The 22-character IFC GlobalId.', 'bimo-ifc-viewer' ) ),
     155                                        text( 'isolate', __( 'Isolate an IFC class', 'bimo-ifc-viewer' ), __( 'For example IfcWall, or none to show everything again.', 'bimo-ifc-viewer' ) ),
     156                                        text( 'azimuth', __( 'Azimuth (degrees)', 'bimo-ifc-viewer' ) ),
     157                                        text( 'elevation', __( 'Elevation (degrees)', 'bimo-ifc-viewer' ) ),
     158                                        text( 'fill', __( 'Share of the frame (0.2–0.98)', 'bimo-ifc-viewer' ) )
     159                                )
     160                        );
     161                        return el( 'div', be.useBlockProps( { className: 'ifcvo-step' } ), inspector,
     162                                el( be.InnerBlocks, { template: [ [ 'core/paragraph', { placeholder: __( 'Text of this step…', 'bimo-ifc-viewer' ) } ] ] } ) );
     163                },
     164                save: function () { return el( be.InnerBlocks.Content ); },
     165        } );
    102166} )( window.wp );
  • bimo-ifc-viewer/trunk/block.json

    r3815325 r3815470  
    1515                "name": { "type": "string", "default": "" },
    1616                "height": { "type": "number", "default": 600 },
    17                 "ui": { "type": "string", "default": "article" },
     17                "ui": { "type": "string", "default": "" },
    1818                "view": { "type": "string", "default": "iso" },
    1919                "wheel": { "type": "string", "default": "ctrl" },
    … …  
    3434                "site": { "type": "string", "default": "" },
    3535                "drawings": { "type": "string", "default": "" },
    36                 "explore": { "type": "string", "default": "" }
     36                "explore": { "type": "string", "default": "" },
     37                "toolbar": { "type": "string", "default": "" },
     38                "tools": { "type": "string", "default": "" },
     39                "panels": { "type": "string", "default": "" },
     40                "autoframe": { "type": "string", "default": "" },
     41                "fill": { "type": "string", "default": "" },
     42                "layers": { "type": "string", "default": "" },
     43                "rule": { "type": "string", "default": "" },
     44                "flood": { "type": "string", "default": "" },
     45                "fullscreen": { "type": "string", "default": "" },
     46                "load": { "type": "string", "default": "" },
     47                "poster": { "type": [ "number", "string" ], "default": "" },
     48                "poster_title": { "type": "string", "default": "" },
     49                "poster_text": { "type": "string", "default": "" },
     50                "launch_label": { "type": "string", "default": "" },
     51                "form_field": { "type": "string", "default": "" }
    3752        },
    3853        "editorScript": "ifcvo-block-editor"
  • bimo-ifc-viewer/trunk/readme.txt

    r3815325 r3815470  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.1.0
     7Stable tag: 1.2.0
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
    … …  
    2929* 10 interface languages.
    3030
    31 The plugin holds no copy of the viewer and adds nothing to your pages except the embed: no scripts on the front end, no settings, no database tables.
     31The plugin holds no copy of the viewer. On pages with a viewer it adds one small bundled script (frontend.js, no remote code) for click-to-load, events and guided steps. It stores one option (its settings) and no database tables.
    3232
    3333== External services ==
    … …  
    3636
    3737* **What is sent and when:** when a visitor opens a page with an IFC Viewer block or `[ifc_viewer]` shortcode, their browser loads the viewer in an iframe from www.ifcvieweronline.eu. The iframe address carries the block settings and the address of the model (and of any point cloud or scene). The visitor's browser then downloads the model straight from your site, or from the URL you gave: the file is not uploaded to or stored by IFC Viewer Online.
     38* **Click to load:** with `load="click"` (or the site-wide setting) nothing is requested from www.ifcvieweronline.eu until the visitor clicks the poster's button; the poster says where the viewer comes from.
     39* **No tracking:** the bundled front-end script sends nothing anywhere. Pushing events to your own `window.dataLayer` is off unless you turn it on.
    3840* **Map:** only when you turn on the map, the viewer loads map tiles, terrain and building data from third-party map providers listed in the viewer's privacy policy.
    3941* Terms of use: https://www.ifcvieweronline.eu/terms
    … …  
    8890* `solar` (`MM-DDTHH:MM` or `YYYY-MM-DDTHH:MM`, site time), `moon` (1), `analysis` (for example `year`, `year:passive`, `summer:sun`), `site` (`lat,lon`).
    8991* `drawings` (`plan`), `explore` (1, 0).
     92* `toolbar` (1, 0), `tools` (`validate`, `measure`, both comma-separated, or `none`), `panels` (properties, scene, measurement, section, plans, map, solar, flood, devices, pointcloud, mesh, comma-separated, or `none`), `autoframe` (1, 0), `fill` (0.2–0.98, or a percentage 20–98), `layers` (https URL to a layers document), `rule` (a validation rule id such as `RULE_MISSING_NAME`), `flood` (`shower`, `storm`, `intense` or `extreme`, then optional `1m`/`2m`/`5m`, `free`/`closed`, `sealed`/`compacted`/`loam`/`sandy`), `fullscreen` (1: a full-screen button).
     93
     94Click to load (no request to ifcvieweronline.eu until the visitor clicks):
     95
     96`[ifc_viewer attachment="123" load="click" poster="456" poster_title="Duplex" poster_text="Two-family house, IFC 2x3" launch_label="Open the 3D model"]`
     97
     98* `load` (`auto`, `click`), `poster` (Media Library ID or https image URL), `poster_title`, `poster_text`, `launch_label`. The poster takes the viewer's height, so nothing moves when the model loads. It carries a note that the viewer loads from www.ifcvieweronline.eu (change it in the settings).
     99
     100Guided steps: each `[ifc_step]` drives the nearest viewer above it (or the first below) while it crosses the middle of the screen. Without JavaScript it is plain text. The **IFC Viewer Step** block does the same in the block editor.
     101
     102`[ifc_step view="front" isolate="IfcWall"]The walls carry the roof.[/ifc_step]`
     103`[ifc_step select="2O2Fr$t4X7Zf8NOew3FLOH"]This is the main door.[/ifc_step]`
     104
     105* `view` (iso, top, front, back, left, right, bottom), `select` (an IFC GlobalId), `isolate` (an IFC class, or `none`), `azimuth`, `elevation` (degrees), `fill` (0.2–0.98).
     106
     107== Settings ==
     108
     109Settings → Bimo IFC Viewer sets site-wide defaults: accent colour, language, interface, background, loading mode (with the page or click to load), default poster and the consent text. A block or shortcode setting always wins. Two opt-in switches, both off by default:
     110
     111* **Fill a form field with the selected element:** with `form_field="#css-selector"` on an embed, clicking an element writes "Name (GlobalId)" into that input and fires `input` and `change`, so it works with Contact Form 7, WPForms, Gravity Forms or any plain form.
     112* **Push viewer events to window.dataLayer** (only if the page already has one): `bimo_ifc_model_loaded`, `bimo_ifc_validation_completed` (with `score`), `bimo_ifc_element_selected` (with `ifc_type`, never names or IDs), `bimo_ifc_tour_started`, `bimo_ifc_tour_ended`.
     113
     114== Events and JavaScript API ==
     115
     116Each viewer event is dispatched on the viewer's wrapper (`.ifcvo-embed`) as a DOM CustomEvent named `bimo-ifc:<event>`, which bubbles; the payload is in `event.detail`. Events include `ready`, `model-loaded`, `model-error`, `validation-completed`, `element-selected` (`name`, `globalId`, `ifcType`, `expressId`, `modelId`), `measurements-changed`, `tour-started`, `tour-step` and `tour-ended`. Only messages from https://www.ifcvieweronline.eu are accepted.
     117
     118`document.addEventListener( 'bimo-ifc:element-selected', function ( e ) { console.log( e.detail.name, e.detail.globalId ); } );`
     119
     120`window.BimoIFC.get( elementOrSelector )` returns the commands of one viewer (commands wait until the model has loaded):
     121
     122* `select( globalId )`, `isolate( 'IfcWall' )` (nothing to show all), `setView( 'top' )`, `frame( { view, fill, azimuth, elevation } )`, `startTour( 'client-walkthrough' )`, `load()` (behind a poster), `on( event, callback )` (returns an unsubscribe function), `whenReady()`.
    90123
    91124== Screenshots ==
    … …  
    97130
    98131== Changelog ==
     132
     133= 1.2.0 =
     134* Click to load: a poster with title, text, button and consent note; the viewer loads from ifcvieweronline.eu only when the visitor clicks.
     135* Settings page (Settings → Bimo IFC Viewer) with site-wide defaults.
     136* Viewer events as DOM events (`bimo-ifc:<event>`), the `window.BimoIFC` API, opt-in form field filling and opt-in dataLayer push.
     137* Guided steps: `[ifc_step]` shortcode and IFC Viewer Step block.
     138* New parameters: toolbar, tools, panels, autoframe, fill, layers, rule, flood, fullscreen; the block now has controls for language, background, moon and model names too.
    99139
    100140= 1.1.0 =
    … …  
    108148== Upgrade Notice ==
    109149
     150= 1.2.0 =
     151Click to load with a consent note, site-wide settings, events for your forms and scripts, and guided scroll steps. Existing embeds render as before.
     152
    110153= 1.1.0 =
    111154Federated models, point clouds, map, sun studies, plan cut and digital twin scenes.
Note: See TracChangeset for help on using the changeset viewer.