Plugin Directory

Changeset 2328652


Ignore:
Timestamp:
06/22/2020 02:18:15 PM (6 years ago)
Author:
thronspa
Message:

1.0.1 RC

Location:
thron/trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • thron/trunk/README.txt

    r2305030 r2328652  
    22Contributors: thronspa, websolutedev
    33Tags: DAM
    4 Stable tag: 1.0
     4Stable tag: 1.0.1
    55Requires at least: 5.2
    66Tested up to: 5.4
     
    6868= Setting up =
    6969* Once the plugin is activated, go to the `THRON` settings.
    70 * Youll be prompted to your THRON clientId, AppId and AppKey that you can find on the Wordpress Connector page in THRON.
     70* You’ll be prompted to your THRON clientId, AppId and AppKey that you can find on the Wordpress Connector page in THRON.
    7171* After saving, the plugin is active and connected to the THRON platform.
    7272
  • thron/trunk/admin/class-thron-admin.php

    r2304750 r2328652  
    232232        wp_enqueue_script( 'thron-js', 'https://' . $thron_options['thron_clientId'] . '-cdn.thron.com/shared/lib/common/sdk/0.5.2/thron.js', array(), $this->version, true );
    233233
    234         /*
     234
    235235        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/thron-admin.js', array(
    236236            'jquery',
    237237            'media-views'
    238238        ), null, false );
    239         */
     239
    240240
    241241        /**
     
    350350    }
    351351
     352    function thron_wp_ajax_query_attachments_upload( $query ) {
     353
     354        $request      = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
     355        $thron_source = sanitize_text_field( $request['thron_source'] );
     356
     357        if ( 'local' == $thron_source ) {
     358            $query['meta_query'] = array(
     359                array(
     360                    'key'     => 'thron_id',
     361                    'compare' => 'NOT EXISTS'
     362                )
     363            );
     364        } else {
     365            $query['meta_query'] = array(
     366                array(
     367                    'key'     => 'thron_id',
     368                    'compare' => 'EXISTS'
     369                )
     370            );
     371        }
     372
     373        return $query;
     374    }
     375
    352376    /**
    353377     * Carica i risultati nella finestra dei media
     
    359383        }
    360384
    361 
    362385        /**
    363          * Essco se non mi trovo nella pagina upload.php
     386         * Esco se il post__in fa riferimento ad un post in particolare
    364387         */
    365388        if ( count( $_REQUEST['query']['post__in'] ) > 0 ) {
     
    367390        }
    368391
    369         /**
    370          * Mostra due risultati differenti se si apre la sezione Media o se si
    371          * apre il frame dei media
    372          */
    373         if ( $this->thron_is_media_library() ) {
    374             return;
    375         }
    376 
    377392        $query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
    378393
    379394        $source = sanitize_text_field( $query['thron_source'] );
     395
    380396        if ( 'local' == $source ) {
    381             return $response;
     397
     398            $query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
     399            $keys  = array(
     400                's',
     401                'order',
     402                'orderby',
     403                'posts_per_page',
     404                'paged',
     405                'post_mime_type',
     406                'post_parent',
     407                'author',
     408                'post__in',
     409                'post__not_in',
     410                'year',
     411                'monthnum',
     412                'meta_query'
     413            );
     414
     415
     416            foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) {
     417                if ( $t->query_var && isset( $query[ $t->query_var ] ) ) {
     418                    $keys[] = $t->query_var;
     419                }
     420            }
     421
     422            $query              = array_intersect_key( $query, array_flip( $keys ) );
     423            $query['post_type'] = 'attachment';
     424
     425            if (
     426                MEDIA_TRASH &&
     427                ! empty( $_REQUEST['query']['post_status'] ) &&
     428                'trash' === $_REQUEST['query']['post_status']
     429            ) {
     430                $query['post_status'] = 'trash';
     431            } else {
     432                $query['post_status'] = 'inherit';
     433            }
     434
     435            if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) {
     436                $query['post_status'] .= ',private';
     437            }
     438
     439            // Filter query clauses to include filenames.
     440            if ( isset( $query['s'] ) ) {
     441                add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     442            }
     443
     444            $query['meta_query'] = array(
     445                array(
     446                    'key'     => 'thron_id',
     447                    'compare' => 'NOT EXISTS'
     448                )
     449            );
     450
     451            /**
     452             * Filters the arguments passed to WP_Query during an Ajax
     453             * call for querying attachments.
     454             *
     455             * @param array $query An array of query variables.
     456             *
     457             * @see WP_Query::parse_query()
     458             *
     459             * @since 3.7.0
     460             *
     461             */
     462            $query = apply_filters( 'ajax_query_attachments_args', $query );
     463
     464            $query = new WP_Query( $query );
     465
     466            $posts = array_map( 'wp_prepare_attachment_for_js', $query->posts );
     467            $posts = array_filter( $posts );
     468
     469            wp_send_json_success( $posts );
     470            die;
    382471        }
    383472
     
    409498        wp_send_json_success( $posts );
    410499        die;
     500    }
     501
     502    /**
     503     * Filter attachments to correct thumbnail URLs
     504     */
     505    public function wp_prepare_attachment_for_js( $attachment ) {
     506        if ( ! is_array( $attachment ) ) {
     507            return $attachment;
     508        }
     509
     510        $thron_id = get_post_meta( $attachment['id'], 'thron_id', true );
     511
     512        if ( ! $thron_id ) {
     513            return $attachment;
     514        }
     515
     516        if ( strpos( $attachment['mime'], 'image' ) === false ) {
     517            return $attachment;
     518        }
     519
     520        $url      = get_post_meta( $attachment['id'], '_wp_attached_file', true );
     521        $filename = basename( $url );
     522        $path     = str_replace( $filename, '', $url );
     523
     524        foreach ( $attachment['sizes'] as $size => $item ) {
     525            if ( 'full' != $size ) {
     526                $width  = $attachment['sizes'][ $size ]['width'];
     527                $height = $attachment['sizes'][ $size ]['height'];
     528
     529                $attachment['sizes'][ $size ]['url'] = $path . $width . 'x' . $height . '/' . $filename;
     530            }
     531        }
     532
     533        return $attachment;
    411534    }
    412535
     
    528651                    case 'IMAGE':
    529652
    530                         $file_url = 'https://' . $clientId . '-cdn.thron.com/delivery/public/image/' . $clientId . '/' . $file->id . '/' . $pkey . '/std/0x0/' . $file->details->source->fileName;
     653                        $thron_options = get_option( 'thron_option_api_page' );
     654                        $width_default = ( array_key_exists( 'thron_maxImageWidth', $thron_options ) ) ? $thron_options['thron_maxImageWidth'] : '0';
     655
     656                        $file_url = 'https://' . $clientId . '-cdn.thron.com/delivery/public/image/' . $clientId . '/' . $file->id . '/' . $pkey . '/std/' . strval( $width_default ) . 'x0/' . $file->details->source->fileName;
    531657
    532658                        $attachment_metadata          = array();
     
    534660                            'width'     => null,
    535661                            'height'    => null,
    536                             'url'       => $thumbs,
     662                            'url'       => $file_url,
    537663                            'crop'      => false,
    538664                            'mime-type' => $mime
     
    641767    }
    642768
    643     /**
    644      * Returns true if current page is "upload.php". False otherwise.
    645      *
    646      * @return bool
    647      */
    648     private function thron_is_media_library() {
    649         $page = basename( $_SERVER["SCRIPT_FILENAME"], '.php' );
    650 
    651         if ( 'upload' == $page ) {
    652             return true;
    653         }
    654 
    655         return false;
    656     }
    657 
    658769    function custom_media_string( $strings, $post ) {
    659770        $strings['THRONMenuTitle']    = __( 'THRON Universal Player', 'thron' );
     
    803914            case 'IMAGE':
    804915
     916                $thron_options = get_option( 'thron_option_api_page' );
     917                $width_default = ( array_key_exists( 'thron_maxImageWidth', $thron_options ) ) ? $thron_options['thron_maxImageWidth'] : '0';
     918
    805919                $thumbs = 'https://' . str_replace( '//', '', strtok( $detail->thumbUrls[0], '?' ) );
    806920                /**
     
    808922                 */
    809923                $attached_file      = 'https://' . $clientId . '-cdn.thron.com/delivery/public/image/' . $clientId . '/' . $thron_id . '/' . $pkey . '/std/' . $file_name;
    810                 $attached_file_full = 'https://' . $clientId . '-cdn.thron.com/delivery/public/image/' . $clientId . '/' . $thron_id . '/' . $pkey . '/std/0x0/' . $file_name;
     924                $attached_file_full = 'https://' . $clientId . '-cdn.thron.com/delivery/public/image/' . $clientId . '/' . $thron_id . '/' . $pkey . '/std/' . strval( $width_default ) . 'x0/' . $file_name;
    811925
    812926                $size = getimagesize( $attached_file_full );
     927
    813928
    814929                list ( $type, $submime ) = explode( '/', $mime );
     
    823938                    'width'     => $size[0],
    824939                    'height'    => $size[1],
    825                     'file'      => '0x0/' . $file_name,
     940                    'file'      => strval( $width_default ) . 'x0/' . $file_name,
    826941                    'crop'      => false,
    827942                    'mime-type' => $mime
     
    840955                    $height = intval( get_option( "{$image_size}_size_h" ) );
    841956
    842                     if ( 'post-thumbnail' == $image_size ) {
    843                         $width  = $size[0];
    844                         $height = $size[1];
     957                    if ( $width or $height ) {
     958                        if ( 'post-thumbnail' == $image_size ) {
     959                            $width  = $size[0];
     960                            $height = $size[1];
     961                        }
     962
     963                        $file = '' . $width . 'x' . $height . '/' . $file_name;
     964
     965                        $attachment_metadata['sizes'][ $image_size ] = array(
     966                            'width'     => $width,
     967                            'height'    => $height,
     968                            'file'      => $file,
     969                            'crop'      => get_option( "{$image_size}_crop" ) ? get_option( "{$image_size}_crop" ) : false,
     970                            'mime-type' => $mime
     971                        );
    845972                    }
    846 
    847                     $file = '' . $width . 'x' . $height . '/' . $file_name;
    848 
    849                     $attachment_metadata['sizes'][ $image_size ] = array(
    850                         'width'     => $width,
    851                         'height'    => $height,
    852                         'file'      => $file,
    853                         'crop'      => get_option( "{$image_size}_crop" ) ? get_option( "{$image_size}_crop" ) : false,
    854                         'mime-type' => $mime
    855                     );
    856973                }
    857974
     
    9691086     */
    9701087    function filter_wp_calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
    971         // make filter magic happen here...
    9721088
    9731089        $thron_id = get_post_meta( $attachment_id, 'thron_id', true );
    974         // $thron_div_area = get_post_meta( $attachment_id, 'thron_div_area', true );
    9751090
    9761091        if ( ! $thron_id ) {
     
    9881103
    9891104        return $result;
    990     }
    991 
    992     function wp_get_attachment_url( $url, $attachment_id ) {
    993 
    994         $post = get_post( $attachment_id );
    995 
    996         $thron_id = get_post_meta( $attachment_id, 'thron_id', true );
    997 
    998         if ( ! $thron_id ) {
    999             return $url;
    1000         }
    1001 
    1002         if ( false !== strpos( $post->post_mime_type, 'image' ) ) {
    1003             $url = get_post_meta( $attachment_id, '_wp_attached_file', true );
    1004 
    1005         }
    1006 
    1007         return get_post_meta( $attachment_id, '_wp_attached_file', true );
    1008     }
    1009 
    1010     function wp_get_attachment_image_src( $image, $attachment_id, $size, $icon ) {
    1011 
    1012         if ( $image ) {
    1013             $path = pathinfo( $image[0] );
    1014 
    1015 
    1016             $sub = explode( "/", $path['dirname'] );
    1017 
    1018             if ( end( $sub ) == 'std' ) {
    1019                 $image[0] = $path['dirname'] . '/' . $size[0] . 'x' . $size[1] . '/' . $path['basename'];
    1020             }
    1021         }
    1022 
    1023         return $image;
    10241105    }
    10251106
     
    10591140    }
    10601141
     1142    function thron_add_tci_tracking_image_block( $attributes, $content ) {
     1143
     1144        $content = str_replace('wp-image-', 'tci wp-image-', $content);
     1145
     1146        return $content;
     1147    }
     1148
     1149    function thron_add_tci_tracking_video_block( $attributes, $content ) {
     1150
     1151        $content = preg_replace_callback( '/(<video) (.*video>)/i', array(
     1152            $this,
     1153            'process_video_audio_class'
     1154        ), $content );
     1155
     1156        return $content;
     1157    }
     1158
     1159    function thron_add_tci_tracking_audio_block( $attributes, $content ) {
     1160
     1161        $content = preg_replace_callback( '/(<audio) (.*audio>)/i', array(
     1162            $this,
     1163            'process_video_audio_class'
     1164        ), $content );
     1165
     1166        return $content;
     1167    }
     1168
     1169
    10611170    function register_block_embed() {
     1171
     1172        register_block_type( 'core/gallery', array(
     1173            'render_callback' => array( $this, 'thron_add_tci_tracking_image_block' ),
     1174        ) );
     1175
     1176        register_block_type( 'core/media-text', array(
     1177            'render_callback' => array( $this, 'thron_add_tci_tracking_image_block' ),
     1178        ) );
     1179
     1180        register_block_type( 'core/audio', array(
     1181            'render_callback' => array( $this, 'thron_add_tci_tracking_audio_block' ),
     1182        ) );
     1183
     1184        register_block_type( 'core/image', array(
     1185            'render_callback' => array( $this, 'thron_add_tci_tracking_image_block' ),
     1186        ) );
     1187
     1188        register_block_type( 'core/video', array(
     1189            'render_callback' => array( $this, 'thron_add_tci_tracking_video_block' ),
     1190        ) );
     1191
     1192
    10621193        register_block_type(
    10631194            'thron/embed',
     
    10781209    }
    10791210
     1211    function image_send_to_editor( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
     1212        $thron_id = get_post_meta( $id, 'thron_id', true );
     1213
     1214        if ( ! $thron_id ) {
     1215            return $html;
     1216        }
     1217
     1218        $html = preg_replace_callback( '/(<img.*class="([^"]+)"[^>]*>)/i', [ $this, 'process_image_class' ], $html );
     1219
     1220        $dom = new DOMDocument();
     1221        $dom->loadHTML( $html );
     1222        $imgs = $dom->getElementsByTagName( "img" );
     1223
     1224        foreach ( $imgs as $img ) {
     1225
     1226            $thron_options = get_option( 'thron_option_api_page' );
     1227            $width_default = ( array_key_exists( 'thron_maxImageWidth', $thron_options ) ) ? $thron_options['thron_maxImageWidth'] : '0';
     1228
     1229            if ( is_array( $size ) ) {
     1230                $width  = $size[0];
     1231                $height = $size[1];
     1232            } else {
     1233                $width  = intval( get_option( "{$size}_size_w" ) );
     1234                $height = intval( get_option( "{$size}_size_h" ) );
     1235            }
     1236
     1237            $width = $width == 0 ? $width_default : $width;
     1238
     1239            $file     = get_post_meta( $id, '_wp_attached_file', true );
     1240            $basename = basename( $file );
     1241            $path     = str_replace( $basename, '', $file );
     1242            $src      = $path . $width . 'x' . $height . '/' . $basename;
     1243
     1244            $img->setAttribute( 'src', $src );
     1245
     1246            $html = $dom->saveHTML( $img );
     1247        }
     1248
     1249        return $html;
     1250    }
     1251
     1252    private function process_image_class( $matches ) {
     1253
     1254        $matches[1] = str_replace( $matches[2], $matches[2] . " tci", $matches[1] );
     1255
     1256        return $matches[1];
     1257    }
     1258
     1259    private function process_video_audio_class( $matches ) {
     1260
     1261        return  $matches[1] .  ' class="tci" ' . $matches[2] ;
     1262    }
     1263
    10801264    function render_block_embed( $attr ) {
    1081 
    10821265        return do_shortcode( '[thron contentID="' . $attr['contentID'] . '" embedCodeId= "' . $attr['embedCode'] . '"]' );
    10831266    }
  • thron/trunk/admin/class-thron-cron.php

    r2304750 r2328652  
    145145                                case 'IMAGE':
    146146
     147                                    $thron_options = get_option( 'thron_option_api_page' );
     148                                    $width_default = (array_key_exists('thron_maxImageWidth', $thron_options)) ? $thron_options['thron_maxImageWidth'] : '0';
     149
    147150                                    $thumbs = 'https://' . str_replace( '//', '', strtok( $detail->thumbUrl, '?' ) );
    148151                                    /**
     
    150153                                     */
    151154                                    $attached_file      = 'https://' . $clientId . '-cdn.thron.com/delivery/public/image/' . $clientId . '/' . $detail->content->id . '/' . $pkey . '/std/' . $file_name;
    152                                     $attached_file_full = 'https://' . $clientId . '-cdn.thron.com/delivery/public/image/' . $clientId . '/' . $detail->content->id . '/' . $pkey . '/std/0x0/' . $file_name;
     155                                    $attached_file_full = 'https://' . $clientId . '-cdn.thron.com/delivery/public/image/' . $clientId . '/' . $detail->content->id . '/' . $pkey . '/std/' . strval($width_default) . 'x0/' . $file_name;
    153156
    154157                                    $file_name = sanitize_title( $language->name ) . '.' . thron_mime2ext( $mime );
     
    167170                                        'width'     => $size[0],
    168171                                        'height'    => $size[1],
    169                                         'file'      => '0x0/' . $file_name,
     172                                        'file'      => strval($width_default) . 'x0/' . $file_name,
    170173                                        'crop'      => false,
    171174                                        'mime-type' => $mime
  • thron/trunk/admin/class-thron-setting.php

    r2304750 r2328652  
    6767        ) );
    6868
     69        $main_options->add_field( array(
     70            'name' => __( 'Image settings', 'thron' ),
     71            'desc' => '',
     72            'type' => 'title',
     73            'id'   => 'image_title'
     74        ) );
     75
     76        $main_options->add_field( array(
     77            'name' => __( 'Default maximum width (px)', 'thron' ),
     78            'description' => __( 'Maximum default size for images imported from THRON', 'thron' ),
     79            'id'   => 'thron_maxImageWidth',
     80            'default' => 1920,
     81            'type' => 'text',
     82        ) );
     83
    6984        $pkey = get_option( 'thron_pkey' );
    7085
     
    150165            $thron_options = get_option( 'thron_option_api_page' );
    151166
     167
    152168            $clientId = $thron_options['thron_clientId'];
    153169            $appId    = $thron_options['thron_appId'];
     
    161177
    162178    function thron_admin_notices() {
     179
     180        $thron_options = get_option( 'thron_option_api_page' );
     181
     182        if (! array_key_exists('thron_maxImageWidth', $thron_options ) or $thron_options['thron_maxImageWidth'] == '' ) {
     183            $thron_options['thron_maxImageWidth'] = 1920;
     184
     185            update_option( 'thron_option_api_page', $thron_options );
     186        }
    163187
    164188        $thron_options = get_option( 'thron_option_api_page' );
  • thron/trunk/admin/js/collection-filter.js

    r2304750 r2328652  
    88     * Create a new MediaLibraryTaxonomyFilter we later will instantiate
    99     */
     10    var MediaLibrarySourceFilter = wp.media.view.AttachmentFilters.extend({
     11        id: 'media-attachment-thron-source-filter',
     12
     13        createFilters: function () {
     14
     15            var filters = {};
     16
     17            var props = {};
     18            props['thron_source'] = 'thron';
     19
     20            filters.all = {
     21                text: 'THRON',
     22                props: props,
     23                priority: 10
     24            };
     25
     26            var props = {};
     27            props['thron_source'] = 'local';
     28            filters['local'] = {
     29                text: 'Local files',
     30                props: props
     31            };
     32
     33
     34            this.filters = filters;
     35        }
     36    });
     37
     38
     39    /**
     40     * Create a new MediaLibraryTaxonomyFilter we later will instantiate
     41     */
    1042    var MediaLibraryTaxonomyFilter = wp.media.view.AttachmentFilters.extend({
    11         id: 'media-attachment-thron-tags-filter' ,
     43        id: 'media-attachment-thron-tags-filter',
     44        className : 'attachment-filters attachment-filters-tag',
    1245
    1346        createFilters: function () {
     
    2962            props['thron_tags_' + dataStore.tags.id] = '';
    3063
    31             console.log(ThronTagsList);;
    32 
    3364            filters.all = {
    3465                text: ThronTagsList.lang.all + ' ' + dataStore.tags.name,
     
    4576     */
    4677    var MediaLibraryFoldersFilter = wp.media.view.AttachmentFilters.extend({
    47         id: 'media-attachment-thron-folders-filter' ,
     78        id: 'media-attachment-thron-folders-filter',
    4879
    4980        createFilters: function () {
     
    88119
    89120            /**
     121             * Viene creato il filtro per la sorgente
     122             */
     123            t.toolbar.set('MediaLibrarySourceFilter', new MediaLibrarySourceFilter({
     124                controller: t.controller,
     125                model: t.collection.props,
     126                priority: -150
     127            }).render());
     128
     129            /**
    90130             * Viene creato il filtro per le cartelle
    91131             */
    92             t.toolbar.set('MediaLibraryFoldersFilter' , new MediaLibraryFoldersFilter({
     132            t.toolbar.set('MediaLibraryFoldersFilter', new MediaLibraryFoldersFilter({
    93133                controller: t.controller,
    94134                model: t.collection.props,
  • thron/trunk/admin/js/thron-admin.js

    r2304750 r2328652  
    11jQuery(document).ready(function ($) {
    22
     3    $(document).on("change", '#media-attachment-thron-source-filter', function(event) {
     4        if (this.value == 'local') {
     5            $('#media-attachment-thron-folders-filter').prop('disabled', 'disabled');
     6            $('.attachment-filters-tag').prop('disabled', 'disabled');
     7
     8        } else {
     9            $('#media-attachment-thron-folders-filter').prop('disabled', false);
     10            $('.attachment-filters-tag').prop('disabled', false);
     11
     12        }
     13    });
     14
    315});
     16
     17
     18const setExtraPropsToBlockType = (props, blockType, attributes) => {
     19    const notDefined = (typeof props.className === 'undefined' || !props.className) ? true : false
     20
     21    if (blockType.name === 'core/cover') {
     22        return Object.assign(props, {
     23            className: notDefined ? ' tci' : 'tci ' +  props.className,
     24        });
     25    }
     26
     27    return props;
     28};
     29
     30wp.hooks.addFilter(
     31    'blocks.getSaveContent.extraProps',
     32    'your-namespace/block-filters',
     33    setExtraPropsToBlockType
     34);
  • thron/trunk/admin/js/wp.media.library.js

    r2304750 r2328652  
    9595                        var element = collection.get(attachment.id);
    9696
    97                         console.log (element);
    9897
    9998                        $.ajax({
     
    101100                            dataType: "json",
    102101                            url: myAjax.ajaxurl,
    103                             data: {action: "thron_file_upload", 'thron_id': attachment.id},
     102                            data: {
     103                                action: "thron_file_upload",
     104                                'thron_id': attachment.id
     105                            },
    104106                            async: false,
    105107                            success: function (response) {
    106108                                if (response.success == true) {
    107 
    108                                     console.log(response.data);
    109                                     console.log(response.data.url);
    110109
    111110                                    element.set({id: response.data.ID});
     
    154153            console.log('Fine del salvataggio...');
    155154
    156             /*
    157             var controller = wp.media.frame.state().get('gallery-library');
    158             var library = controller.get('library');
    159             get the shortcode and update the input field
    160             var new_shortcode = wp.media.gallery.shortcode(library).string();
    161             console.log(new_shortcode)
    162              */
    163155        });
    164156
  • thron/trunk/includes/class-thron.php

    r2304750 r2328652  
    7171            $this->version = THRON_VERSION;
    7272        } else {
    73             $this->version = '1.0.0';
     73            $this->version = '1.0.1';
    7474        }
    7575        $this->plugin_name = 'thron';
     
    198198
    199199        /**
     200         * Adds the class for image tracking
     201         */
     202        $this->loader->add_filter( 'image_send_to_editor', $plugin_admin, 'image_send_to_editor', 10, 8 );
     203
     204
     205        /**
    200206         * Perform AJAX search in the media library
    201207         */
    202208        if ( isset($_SERVER["HTTP_REFERER"]) && strpos($_SERVER["HTTP_REFERER"], 'upload.php') === false) {
    203209            $this->loader->add_action( 'wp_ajax_query-attachments', $plugin_admin, 'thron_wp_ajax_query_attachments', 1  );
     210        } else {
     211            $this->loader->add_filter( 'ajax_query_attachments_args', $plugin_admin, 'thron_wp_ajax_query_attachments_upload', 1  );
    204212        }
     213
     214
     215        /**
     216         * Filter attachments to correct thumbnail URLs
     217         */
     218        $this->loader->add_action( 'wp_prepare_attachment_for_js', $plugin_admin, 'wp_prepare_attachment_for_js', 1  );
    205219
    206220        /**
     
    231245         */
    232246        $this->loader->add_filter( 'wp_calculate_image_srcset', $plugin_admin, 'filter_wp_calculate_image_srcset', 10, 5 );
    233         $this->loader->add_filter( 'wp_get_attachment_url', $plugin_admin, 'wp_get_attachment_url', 10, 2 );
    234         $this->loader->add_filter( 'wp_get_attachment_image_src', $plugin_admin, 'wp_get_attachment_image_src', 10, 4 );
    235247
    236248        /**
     
    261273
    262274        /**
    263          * Adds the class for image tracking
    264          */
    265         $this->loader->add_filter( 'image_send_to_editor', $plugin_public, 'image_send_to_editor', 10, 8 );
    266 
    267         /**
    268275         * Adds the shortcode to embed the player
    269276         */
    270277        add_shortcode('thron', array($plugin_public, 'thron_shortcode'));
     278
     279        $this->loader->add_filter( 'wp_get_attachment_image_src', $plugin_public, 'wp_get_attachment_image_src', 10, 4 );
     280        $this->loader->add_filter( 'wp_get_attachment_url', $plugin_public, 'wp_get_attachment_url', 10, 2 );
     281
     282        $this->loader->add_filter( 'wp_get_attachment_image_attributes', $plugin_public, 'filter_wp_get_attachment_image_attributes', 10, 3 );
     283
     284        /**
     285         * Add class tci to image
     286         */
     287        $this->loader->add_filter( 'get_image_tag_class', $plugin_public, 'get_image_tag_class', 10, 3 );
     288        $this->loader->add_filter( 'wp_get_attachment_image_attributes', $plugin_public, 'wp_get_attachment_image_attributes', 10, 3 );
     289
    271290    }
    272291
  • thron/trunk/languages/thron-it_IT.po

    r2304750 r2328652  
    22msgstr ""
    33"Language: it_IT\n"
    4 "POT-Creation-Date: 2020-04-16 12:08+0000\n"
     4"POT-Creation-Date: 2020-05-26 16:27+0000\n"
    55"Plural-Forms: nplurals=2; plural=n != 1;\n"
    6 "PO-Revision-Date: 2020-04-16 12:10+0000\n"
     6"PO-Revision-Date: 2020-05-26 16:29+0000\n"
    77"X-Generator: Loco https://localise.biz/\n"
    88"Project-Id-Version: THRON\n"
    99"Report-Msgid-Bugs-To: \n"
    10 "Last-Translator: admin <dev-email@flywheel.local>\n"
     10"Last-Translator: \n"
    1111"Language-Team: Italiano\n"
    1212"MIME-Version: 1.0\n"
    1313"Content-Type: text/plain; charset=UTF-8\n"
    1414"Content-Transfer-Encoding: 8bit\n"
    15 "X-Loco-Version: 2.3.1; wp-5.4"
     15"X-Loco-Version: 2.3.4; wp-5.4.1"
    1616
    17 #: admin/class-thron-admin.php:278
     17#: admin/class-thron-admin.php:276
    1818msgid "All"
    1919msgstr "Tutti"
    2020
    21 #: admin/class-thron-admin.php:279 admin/class-thron-admin.php:305
     21#: admin/class-thron-admin.php:277 admin/class-thron-admin.php:303
    2222msgid "All folders"
    2323msgstr "Tutte le cartelle"
    2424
    25 #: admin/class-thron-admin.php:306
     25#: admin/class-thron-admin.php:304
    2626msgid "All content"
    2727msgstr "Tutti i contenuti"
    2828
    29 #: admin/class-thron-admin.php:307
     29#: admin/class-thron-admin.php:305
    3030msgid "Content details"
    3131msgstr "Dettagli del contenuto"
    3232
    33 #: admin/class-thron-admin.php:308
     33#: admin/class-thron-admin.php:306
    3434msgid "Player template"
    3535msgstr "Template per il player"
    3636
    37 #: admin/class-thron-admin.php:309
     37#: admin/class-thron-admin.php:307
    3838msgid "--Please select a template--"
    3939msgstr "--Seleziona un template--"
    4040
    41 #: admin/class-thron-admin.php:310
     41#: admin/class-thron-admin.php:308
    4242msgid "Embed type"
    4343msgstr "Tipo di embed"
    4444
    45 #: admin/class-thron-admin.php:311
     45#: admin/class-thron-admin.php:309
    4646msgid "Fixed size"
    4747msgstr "Dimensione fissa"
    4848
    49 #: admin/class-thron-admin.php:312
     49#: admin/class-thron-admin.php:310
    5050msgid "Width (px)"
    5151msgstr "Larghezza (px)"
    5252
    53 #: admin/class-thron-admin.php:313
     53#: admin/class-thron-admin.php:311
    5454msgid "Height (px)"
    5555msgstr "Altezza (px)"
    5656
    57 #: admin/class-thron-admin.php:655
     57#: admin/class-thron-admin.php:736
    5858msgid "THRON Universal Player"
    5959msgstr "THRON Universal Player"
    6060
    61 #: admin/class-thron-admin.php:656
     61#: admin/class-thron-admin.php:737
    6262msgid "Insert"
    6363msgstr "Inserisci"
     
    100100msgstr "Inserisci la chiave di autenticazione del connettore"
    101101
    102 #: admin/class-thron-setting.php:108
     102#: admin/class-thron-setting.php:70
     103msgid "Image settings"
     104msgstr "Opzioni immagini"
     105
     106#: admin/class-thron-setting.php:77
     107msgid "Default maximum width (px)"
     108msgstr "Larghezza massima di default (px)"
     109
     110#: admin/class-thron-setting.php:78
     111msgid "Maximum default size for images imported from THRON"
     112msgstr "Dimensione massima di default per le immagini importate da THRON"
     113
     114#: admin/class-thron-setting.php:123
    103115msgid "Search option"
    104116msgstr "Opzioni di ricerca"
    105117
    106 #: admin/class-thron-setting.php:109
     118#: admin/class-thron-setting.php:124
    107119msgid ""
    108120"Choose whether to use tags as search filters and set the root folder of "
     
    112124"principale dei contenuti WordPress"
    113125
    114 #: admin/class-thron-setting.php:115
     126#: admin/class-thron-setting.php:130
    115127msgid "Enable filtering"
    116128msgstr "Abilita il filtraggio"
    117129
    118 #: admin/class-thron-setting.php:121
     130#: admin/class-thron-setting.php:136
    119131msgid "Enable tag filtering"
    120132msgstr "Abilita il filtraggio per tag"
    121133
    122 #: admin/class-thron-setting.php:122
     134#: admin/class-thron-setting.php:137
    123135msgid "Select the tags to be used for filtering"
    124136msgstr "Seleziona le tag da utilizzare per i filtraggi"
    125137
    126 #: admin/class-thron-setting.php:134
     138#: admin/class-thron-setting.php:149
    127139msgid "Select starting folder"
    128140msgstr "Cartella di partenza"
    129141
    130 #: admin/class-thron-setting.php:135
     142#: admin/class-thron-setting.php:150
    131143msgid ""
    132144"Select the starting folder for content selection (subfolders will be "
     
    136148"incluse anche le sottocartelle)"
    137149
    138 #: admin/class-thron-setting.php:169
     150#: admin/class-thron-setting.php:197
    139151msgid "The connector has not been successfully configured!!"
    140152msgstr "Il connettore non è stato configurato correttamente!"
    141153
    142 #: admin/class-thron-setting.php:191
     154#: admin/class-thron-setting.php:219
    143155msgid "THRON has not been configured!"
    144156msgstr "THRON non è stato configurato!"
    145157
    146 #: admin/class-thron-setting.php:197
     158#: admin/class-thron-setting.php:225
    147159msgid "THRON login failed!"
    148160msgstr "Login fallito su THRON!"
    149161
    150 #: admin/class-thron-setting.php:203
     162#: admin/class-thron-setting.php:231
    151163msgid ""
    152164"The application has not been configured correctly. Please contact technical "
  • thron/trunk/languages/thron.pot

    r2304750 r2328652  
    33msgstr ""
    44"Language: \n"
    5 "POT-Creation-Date: 2020-04-16 12:08+0000\n"
     5"POT-Creation-Date: 2020-05-26 16:27+0000\n"
    66"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
    77"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    88"X-Generator: Loco https://localise.biz/"
    99
    10 #: admin/class-thron-admin.php:278
     10#: admin/class-thron-admin.php:276
    1111msgid "All"
    1212msgstr ""
    1313
    14 #: admin/class-thron-admin.php:279 admin/class-thron-admin.php:305
     14#: admin/class-thron-admin.php:277 admin/class-thron-admin.php:303
    1515msgid "All folders"
    1616msgstr ""
    1717
    18 #: admin/class-thron-admin.php:306
     18#: admin/class-thron-admin.php:304
    1919msgid "All content"
    2020msgstr ""
    2121
    22 #: admin/class-thron-admin.php:307
     22#: admin/class-thron-admin.php:305
    2323msgid "Content details"
    2424msgstr ""
    2525
    26 #: admin/class-thron-admin.php:308
     26#: admin/class-thron-admin.php:306
    2727msgid "Player template"
    2828msgstr ""
    2929
    30 #: admin/class-thron-admin.php:309
     30#: admin/class-thron-admin.php:307
    3131msgid "--Please select a template--"
    3232msgstr ""
    3333
    34 #: admin/class-thron-admin.php:310
     34#: admin/class-thron-admin.php:308
    3535msgid "Embed type"
    3636msgstr ""
    3737
    38 #: admin/class-thron-admin.php:311
     38#: admin/class-thron-admin.php:309
    3939msgid "Fixed size"
    4040msgstr ""
    4141
    42 #: admin/class-thron-admin.php:312
     42#: admin/class-thron-admin.php:310
    4343msgid "Width (px)"
    4444msgstr ""
    4545
    46 #: admin/class-thron-admin.php:313
     46#: admin/class-thron-admin.php:311
    4747msgid "Height (px)"
    4848msgstr ""
    4949
    50 #: admin/class-thron-admin.php:655
     50#: admin/class-thron-admin.php:736
    5151msgid "THRON Universal Player"
    5252msgstr ""
    5353
    54 #: admin/class-thron-admin.php:656
     54#: admin/class-thron-admin.php:737
    5555msgid "Insert"
    5656msgstr ""
     
    9393msgstr ""
    9494
    95 #: admin/class-thron-setting.php:108
     95#: admin/class-thron-setting.php:70
     96msgid "Image settings"
     97msgstr ""
     98
     99#: admin/class-thron-setting.php:77
     100msgid "Default maximum width (px)"
     101msgstr ""
     102
     103#: admin/class-thron-setting.php:78
     104msgid "Maximum default size for images imported from THRON"
     105msgstr ""
     106
     107#: admin/class-thron-setting.php:123
    96108msgid "Search option"
    97109msgstr ""
    98110
    99 #: admin/class-thron-setting.php:109
     111#: admin/class-thron-setting.php:124
    100112msgid ""
    101113"Choose whether to use tags as search filters and set the root folder of "
     
    103115msgstr ""
    104116
    105 #: admin/class-thron-setting.php:115
     117#: admin/class-thron-setting.php:130
    106118msgid "Enable filtering"
    107119msgstr ""
    108120
    109 #: admin/class-thron-setting.php:121
     121#: admin/class-thron-setting.php:136
    110122msgid "Enable tag filtering"
    111123msgstr ""
    112124
    113 #: admin/class-thron-setting.php:122
     125#: admin/class-thron-setting.php:137
    114126msgid "Select the tags to be used for filtering"
    115127msgstr ""
    116128
    117 #: admin/class-thron-setting.php:134
     129#: admin/class-thron-setting.php:149
    118130msgid "Select starting folder"
    119131msgstr ""
    120132
    121 #: admin/class-thron-setting.php:135
     133#: admin/class-thron-setting.php:150
    122134msgid ""
    123135"Select the starting folder for content selection (subfolders will be "
     
    125137msgstr ""
    126138
    127 #: admin/class-thron-setting.php:169
     139#: admin/class-thron-setting.php:197
    128140msgid "The connector has not been successfully configured!!"
    129141msgstr ""
    130142
    131 #: admin/class-thron-setting.php:191
     143#: admin/class-thron-setting.php:219
    132144msgid "THRON has not been configured!"
    133145msgstr ""
    134146
    135 #: admin/class-thron-setting.php:197
     147#: admin/class-thron-setting.php:225
    136148msgid "THRON login failed!"
    137149msgstr ""
    138150
    139 #: admin/class-thron-setting.php:203
     151#: admin/class-thron-setting.php:231
    140152msgid ""
    141153"The application has not been configured correctly. Please contact technical "
  • thron/trunk/public/class-thron-public.php

    r2304750 r2328652  
    9898        $tracking_context = get_option( 'thron_tracking_context' );
    9999
    100         $width =  (('responsive' == $embedType) and ($atts['width'] == '')) ? 100 : $atts['width'] ;
     100        $width = ( ( 'responsive' == $embedType ) and ( $atts['width'] == '' ) ) ? 100 : $atts['width'];
    101101
    102102        $uniqID = uniqid();
     
    107107
    108108        return $string;
    109     }
    110 
    111     /**
    112      * Aggiunge il la classe alle immagini
    113      */
    114     public function thron_alter_att_attributes_image( $attr, $attachment ) {
    115         $attr['class'] = 'thron';
    116 
    117         return $attr;
    118109    }
    119110
     
    132123    }
    133124
    134     function image_send_to_editor( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
    135         $pattern = '/(<img.*class="([^"]+)"[^>]*>)/i';
    136 
    137         $html = preg_replace_callback( $pattern, [ $this, 'process' ], $html );
    138 
    139         return $html;
    140     }
    141 
    142     private function process( $matches ) {
    143 
    144         $matches[1] = str_replace( $matches[2], $matches[2] . " tci", $matches[1] );
    145 
    146         return $matches[1];
    147 
     125    function wp_get_attachment_image_src( $image, $attachment_id, $size, $icon ) {
     126
     127        $thron_id = get_post_meta( $attachment_id, 'thron_id', true );
     128
     129        if ( ! $thron_id ) {
     130            return $image;
     131        }
     132
     133        $thron_options = get_option( 'thron_option_api_page' );
     134        $width_default = ( array_key_exists( 'thron_maxImageWidth', $thron_options ) ) ? $thron_options['thron_maxImageWidth'] : '0';
     135
     136        if ( $image ) {
     137            // $path = pathinfo( $image[0] );
     138            $path = pathinfo( get_post_meta( $attachment_id, '_wp_attached_file', true ) );
     139
     140            $sub = explode( "/", $path['dirname'] );
     141
     142            if ( end( $sub ) == 'std' ) {
     143                $width  = 0;
     144                $height = 0;
     145
     146                if ( is_array( $size ) ) {
     147                    $width  = $size[0];
     148                    $height = $size[1];
     149                } else {
     150                    $width  = intval( get_option( "{$size}_size_w" ) );
     151                    $height = intval( get_option( "{$size}_size_h" ) );
     152                }
     153
     154                $width    = $width == 0 ? $width_default : $width;
     155                $image[0] = $path['dirname'] . '/' . $width . 'x' . $height . '/' . $path['basename'];
     156            }
     157
     158        }
     159
     160        return $image;
     161    }
     162
     163    function wp_get_attachment_url( $url, $attachment_id ) {
     164
     165        $thron_options = get_option( 'thron_option_api_page' );
     166        $width_default = ( array_key_exists( 'thron_maxImageWidth', $thron_options ) ) ? $thron_options['thron_maxImageWidth'] : '0';
     167
     168
     169        $post = get_post( $attachment_id );
     170
     171        $thron_id = get_post_meta( $attachment_id, 'thron_id', true );
     172
     173        if ( ! $thron_id ) {
     174            return $url;
     175        }
     176
     177        $url = get_post_meta( $attachment_id, '_wp_attached_file', true );
     178
     179        if ( strpos($post->post_mime_type, 'image') === false ) {
     180            return $url;
     181        }
     182
     183        $filename = basename( $url );
     184
     185        $path = str_replace( $filename, '', $url );
     186
     187        return $path . $width_default . 'x0/' . $filename;;
     188    }
     189
     190    public function filter_wp_get_attachment_image_attributes( $attr, $attachment, $size ) {
     191
     192        $thron_id = get_post_meta( $attachment->ID, 'thron_id', true );
     193
     194        if ( ! $thron_id ) {
     195            return $attr;
     196        }
     197
     198
     199        $attachment_metadata = wp_get_attachment_metadata( $attachment->ID );
     200        $attached_file       = dirname( get_post_meta( $attachment->ID, '_wp_attached_file', true ) );
     201
     202        if ( !is_array($attachment_metadata) or ! array_key_exists( 'sizes', $attachment_metadata ) ) {
     203            return $attr;
     204        }
     205
     206        $size_array             = $attachment_metadata['sizes'];
     207        $max_srcset_image_width = apply_filters( 'max_srcset_image_width', 2048, $size_array );
     208
     209        $srcset = '';
     210
     211        foreach ( $size_array as $size ) {
     212            if ( $size['width'] and $size['width'] < $max_srcset_image_width ) {
     213                $srcset .= str_replace( ' ', '%20', $attached_file . '/' . $size['file'] ) . ' ' . $size['width'] . 'w, ';
     214            }
     215        }
     216
     217        $attr['srcset'] = rtrim( $srcset, ', ' );
     218
     219        return $attr;
     220    }
     221
     222    /**
     223     * Add class tci to image
     224     */
     225
     226    public function wp_get_attachment_image_attributes( $attr, $attachment ) {
     227        $attr['class'] .= ' tci';
     228
     229        return $attr;
     230    }
     231
     232    public function get_image_tag_class($class) {
     233        return strpos($class, 'tci') !== false ? $class . ' tci' : $class;
    148234    }
    149235
  • thron/trunk/public/partials/player.php

    r2304750 r2328652  
    1 <?php if ('responsive' == $embedType ) : ?>
    2 <div style="padding-top:<?= $aspectRatio; ?>%; width: 100%; position: relative">
    3     <div id="elementId_<?= $uniqID;  ?>" style="width: 100%; height: 100%; position: absolute; top: 0"></div>
    4 </div>
     1<?php if ( 'responsive' == $embedType ) : ?>
     2    <div>
     3        <div style="padding-top:<?= $aspectRatio; ?>%; width: 100%; position: relative">
     4            <div id="elementId_<?= $uniqID; ?>" style="width: 100%; height: 100%; position: absolute; top: 0"></div>
     5        </div>
     6    </div>
    57<?php else : ?>
    6     <div id="elementId_<?= $uniqID; ?>" style="width: <?= $width; ?>px; height: <?= $height; ?>px;"></div>
     8    <div id="elementId_<?= $uniqID; ?>" style="width: <?= $width; ?>px; height: <?= $height; ?>px;"></div>
    79<?php endif; ?>
    810
     
    1012
    1113    var options = {
    12         <?= $tracking_context ?  '"contextId": "' . $tracking_context .'",' : ''; ?>
     14        <?= $tracking_context ? '"contextId": "' . $tracking_context . '",' : ''; ?>
    1315        "clientId": "<?= $clientId; ?>",
    1416        "xcontentId": "<?= $contentID; ?>",
  • thron/trunk/thron.php

    r2304750 r2328652  
    1717 * Plugin URI:
    1818 * Description:       Select the assets to insert within your pages directly from the DAM library
    19  * Version:           1.0.0
     19 * Version:           1.0.1
    2020 * Author:            THRON
    2121 * Author URI:        https://www.thron.com
Note: See TracChangeset for help on using the changeset viewer.