Plugin Directory

Changeset 2427198


Ignore:
Timestamp:
11/27/2020 10:55:57 AM (5 years ago)
Author:
svgator
Message:

v1.0.2

Location:
svgator
Files:
57 added
8 edited

Legend:

Unmodified
Added
Removed
  • svgator/trunk/includes/class/WP_SVGator.php

    r2422334 r2427198  
    1111        require $sdkAutoload;
    1212
    13         // Let's not make this public yet.. We still have issues w/ it
    14         //(new \WP_SVGator_Block\WP_SVGator_Block())->run();
     13        (new \WP_SVGator_Block\WP_SVGator_Block())->run();
    1514        (new \WP_SVGator_Svg_Support())->run();
    1615        add_action('admin_menu', [$this, 'wp_adminMenu']);
     
    166165                'success'  => true,
    167166                'response' => [
     167                    'id' => intval($resp['attachment']),
    168168                    'html' => wp_get_attachment_image($resp['attachment']),
    169169                    'url' => $resp['url'],
  • svgator/trunk/includes/class/WP_SVGator_Block/WP_SVGator_Block.php

    r2422334 r2427198  
    66    public function run() {
    77        add_action('init', [$this, 'registerBlock']);
    8         add_action('enqueue_block_editor_assets', [$this, 'addGutenbergScripts']);
    98    }
    109
    1110    function registerBlock() {
     11        $userId = get_current_user_id();
     12
     13        if (!$userId) {
     14            return;
     15        }
     16
     17        $userTokens = get_user_option('svgator_api', $userId);
     18
     19        $loggedOut = empty($userTokens)
     20                     || empty($userTokens['app_id'])
     21                     || empty($userTokens['secret_key'])
     22                     || empty($userTokens['customer_id'])
     23                     || empty($userTokens['access_token']);
     24
     25        if ($loggedOut) {
     26            return;
     27        }
     28
     29        add_action('enqueue_block_editor_assets', [$this, 'addGutenbergScripts']);
     30
    1231        register_block_type('wp-svgator/insert-svg');
    1332    }
  • svgator/trunk/includes/class/WP_SVGator_Svg_Support.php

    r2422387 r2427198  
    2626
    2727        $content = preg_replace_callback(
    28             '/(<img.*?>)/',
     28            '/(<img[^>]*?>)/',
    2929            [$this, 'getImageReplacement'],
    3030            $content
     
    114114
    115115    function fixScript($svgContent) {
     116        //Remove CDATA, since Wordpress does not allow it inside the content
     117        $svgContent = str_replace('<![CDATA[', '', $svgContent);
     118        $svgContent = str_replace(']]>', '', $svgContent);
     119
    116120        $startOfScript = strpos($svgContent, '<script>');
    117121        if ($startOfScript === false) {
    118122            return $svgContent;
    119123        }
    120 
    121         //Remove CDATA, since Wordpress does not allow it inside the content
    122         $svgContent = str_replace('<![CDATA[', '', $svgContent);
    123         $svgContent = str_replace(']]>', '', $svgContent);
    124124
    125125        //add a space after the < char if it is followed by a letter
  • svgator/trunk/readme.txt

    r2425456 r2427198  
    1 === SVGator - Add Animated SVG Easily ===
     1=== SVGator ===
    22
    33Contributors: alucaci, dzsamper
     
    66Requires at least: 5.0
    77Tested up to: 5.5.3
    8 Stable tag: 1.0.1
     8Stable tag: 1.0.2
    99
    10 Connect your SVGator account to easily import your animated SVG projects to your blog
     10The easiest way to add SVG animations to your website right from your SVGator account.
    1111
    1212== Description ==
     
    7575== Changelog ==
    7676
     77= 1.0.2 =
     78* Ability to add a project directly to a post via block editor
     79
    7780= 1.0.1 =
    7881* Bugs reported by users fixed
     
    8891== Upgrade Notice ==
    8992
    90 For full functionality update to version 1.0.1
     93For full functionality update to version 1.0.2
    9194
    9295== Disclosure ==
  • svgator/trunk/svgator.php

    r2425456 r2427198  
    11<?php
    22/**
    3  * Plugin Name: SVGator - Add Animated SVG Easily
     3 * Plugin Name: SVGator
    44 * Plugin URI: https://www.svgator.com/help/getting-started/how-to-add-svg-to-wordpress
    55 * Description: Import your animated SVGs from SVGator.com
    6  * Version: 1.0.1
     6 * Version: 1.0.2
    77 * Author: SVGator
    88 * Author URI: https://www.svgator.com
     
    3434}
    3535
    36 define('WP_SVGATOR_VERSION', '1.0.1');
     36define('WP_SVGATOR_VERSION', '1.0.2');
    3737
    3838require plugin_dir_path(__FILE__) . 'includes/autoload.php';
  • svgator/trunk/wp-svgator-block/css/style.css

    r2422334 r2427198  
    2828}
    2929
     30.svgator-popup-projects .svgator-popup-inner.svgator-hidden {
     31    display: none;
     32}
     33
    3034.svgator-popup-projects .svgator-popup-inner.svgator-loading {
    3135    background-color: rgba(0, 0, 0, .1);
     
    3539}
    3640
     41
     42.svgator-popup-projects .svgator-popup-inner .svgator-no-project {
     43    color: #4c4c4c;
     44    font-size: 24px;
     45    font-weight: 300;
     46    line-height: normal;
     47    text-align: center;
     48    padding-top: 230px;
     49}
     50
     51/**
     52    Header of projects
     53 */
     54#svgator-header {
     55    align-items: center;
     56    display: flex;
     57    line-height: 36px;
     58    padding: 0 8px;
     59}
     60
     61#svgator-header > h1 {
     62    margin-right: 20px;
     63    padding: 0;
     64}
     65
     66#svgator-header > form input {
     67    background-image: url("../imgs/magnifier.svg");
     68    background-repeat: no-repeat;
     69    background-position: 10px center;
     70    border-color: #d3d6d9;
     71    border-radius: 4px;
     72    height: 36px;
     73    line-height: 36px;
     74    padding-left: 37px;
     75    width: 416px;
     76}
     77
     78/**
     79    Header of projects
     80 */
    3781.svgator-popup-projects .svgator-popup-inner > ul > li {
    3882    background-color: #fff;
    3983    border: 1px solid rgba(0, 0, 0, .12);
    4084    border-radius: 4px;
    41     display: inline-block;
     85    display: none;
    4286    margin: 8px;
    4387    overflow: hidden;
    4488    position: relative;
    4589    vertical-align: top;
    46     width: 256px;
     90    width: calc(16.66% - 16px);
     91}
     92
     93.svgator-popup-projects .svgator-popup-inner > ul > li.svgator-on-page.svgator-on-filter {
     94    display: inline-block;
    4795}
    4896
     
    77125    word-break: break-all;
    78126}
     127
     128/**
     129    Pagination
     130 */
     131#svgator-projects-pagination ul {
     132    display: inline-flex;
     133    justify-content: center;
     134    width: 100%;
     135}
     136
     137#svgator-projects-pagination li {
     138    background-color: #fff;
     139    border-radius: 4px;
     140    box-shadow: 0 3px 1px -2px rgba(0, 0, 0, .2),
     141    0 2px 2px 0 rgba(0, 0, 0, .14),
     142    0 1px 5px 0 rgba(0, 0, 0, .12);
     143    color: rgba(0, 0, 0, .87);
     144    cursor: pointer;
     145    font-size: 16px;
     146    height: 34px;
     147    line-height: 34px;
     148    margin: 5px;
     149    min-width: 34px;
     150    padding: 0 5px;
     151    text-align: center;
     152    transition: .3s cubic-bezier(0, 0, .2, 1);
     153}
     154
     155#svgator-projects-pagination li.active {
     156    background-color: #1976d2;
     157    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, .2),
     158    0 4px 5px 0 rgba(0, 0, 0, .14),
     159    0 1px 10px 0 rgba(0, 0, 0, .12);
     160    color: #fff;
     161}
  • svgator/trunk/wp-svgator-block/js/SVGator_BlockProjects.js

    r2422334 r2427198  
    3333                        type: 'string',
    3434                        source: 'html',
    35                         selector: 'figcaption',
     35                        selector: 'div.wp-block-wp-svgator-insert-svg',
    3636                    }
    3737                },
    3838                edit: function(props) {
    39                     let placeholder = slf.createPlaceholder(props);
     39                    let placeholder = slf.createPlaceholder(props, 'Please select a SVG.');
    4040                    if (props.isSelected) {
    41                         slf.popup.showPopup(placeholder, props);
     41                        if (!props.attributes.htmlContent) {
     42                            slf.popup.showPopup(placeholder, props);
     43                        }
    4244                    }
    4345                    return placeholder;
     
    5052    }
    5153
    52     createPlaceholder(props) {
     54    createPlaceholder(props, placeholderText = false) {
    5355        if (props.attributes.htmlContent) {
    54             //this.$('.svgator-placeholder').remove();
    5556            return this.wp.element.createElement(
    5657                'div',
    5758                {
     59                    className: 'wp-svgator-image',
    5860                    dangerouslySetInnerHTML: {
    5961                        __html: props.attributes.htmlContent,
     
    6668            'div',
    6769            {
    68                 className: 'svgator-placeholder',
     70                className: 'wp-svgator-image',
    6971            },
    70             'Please select a SVG.'
     72            placeholderText
    7173        );
     74
    7275    }
    7376
     
    121124    }
    122125
    123     edit(params) {
    124         let pr = svgator_bp.loadProjects();
    125         if (!pr) {
    126             return false;
    127         }
    128 
    129         pr.then(function(data){
    130             if (!data || !data.success) {
    131                 return false;
    132             }
    133         }).catch(function(err){
    134             console.log(err);
    135         });
    136 
    137         return this.createPlaceholder();
    138     }
    139 
    140     save() {
    141         return null;
    142     }
    143 
    144126    loadProjects() {
    145127        return this.makeRequest({
  • svgator/trunk/wp-svgator-block/js/SVGator_BlockProjects_Popup.js

    r2422334 r2427198  
    11export default class SVGator_BlockProjects_Popup {
     2    projectsPerPage = 18;
     3
    24    constructor(wp, $) {
    35        this.wp = wp;
     
    1517        let $innerDiv = this.$('<div>')
    1618            .addClass('svgator-popup-inner')
     19            .addClass('svgator-hidden')
    1720            .addClass('svgator-loading');
     21
     22        let $header = this.getPopupHeader();
     23
     24        let $paginator = this.$('<div>')
     25            .attr('id', 'svgator-projects-pagination');
    1826
    1927        let $ul = this.$('<ul>');
     
    3240            data.response.forEach(function(project){
    3341                $ul.append(slf.buildProjectLi(project));
    34                 $innerDiv.removeClass('svgator-loading');
    3542            });
     43
     44            $innerDiv.removeClass('svgator-loading');
     45            $innerDiv.removeClass('svgator-hidden');
     46
     47            slf.filterProjects(slf.$('#svgator-header [type="search"]').val());
    3648        }).catch(function(err){
    3749            console.log(err);
     
    3951        });
    4052
     53        $innerDiv.append($header);
    4154        $innerDiv.append($ul);
     55        $innerDiv.append($paginator);
    4256        $outerDiv.append($innerDiv);
    4357        this.$('body').append($outerDiv);
    4458
    4559        this.setupPopupClose($outerDiv);
     60    }
     61
     62    getPopupHeader() {
     63        let slf = this;
     64
     65        let $header = this.$('<div>')
     66            .attr('id', 'svgator-header');
     67
     68        let $h1 = this.$('<h1>')
     69            .text('SVGator');
     70
     71        let $filter = this.$('<form>');
     72        let $input = this.$('<input>')
     73            .attr('type', 'search')
     74            .attr('placeholder', 'Search project...')
     75            .on('keyup search', function(e) {
     76                slf.filterProjects(e.target.value);
     77            });
     78
     79        $filter.append($input);
     80
     81        $header.append($h1);
     82        $header.append($filter);
     83        return $header;
     84    }
     85
     86    filterProjects(search) {
     87        let slf = this;
     88        search = slf.$.trim(search).toLowerCase();
     89        slf.$('.svgator-popup-inner .svgator-no-project').remove();
     90
     91        let $lis = slf.$('.svgator-popup-inner > ul li');
     92        if (!search) {
     93            $lis.addClass('svgator-on-filter');
     94            slf.paginateProjects();
     95            return;
     96        }
     97
     98        $lis.removeClass('svgator-on-filter');
     99
     100        $lis.each(function(idx, li) {
     101            let $li = slf.$(li);
     102            let liText = $li.find('.svgator-title-container').text().toLowerCase();
     103
     104            if (liText.indexOf(search) >= 0) {
     105                $li.addClass('svgator-on-filter');
     106            }
     107        });
     108
     109        if ($lis.filter('.svgator-on-filter').length === 0) {
     110            let $noProjects = slf.$('<div>')
     111                .addClass('svgator-no-project')
     112                .text('No project found');
     113
     114            slf.$('.svgator-popup-inner').append($noProjects);
     115        }
     116
     117        slf.paginateProjects();
    46118    }
    47119
     
    72144    updatePlaceholder(project) {
    73145        let slf = this;
    74         this.$('.svgator-popup-inner > ul').remove();
     146        this.$('.svgator-popup-inner > *').remove();
    75147        this.$('.svgator-popup-inner').addClass('svgator-loading');
    76148
     
    136208
    137209        return $li;
     210    }
     211
     212    paginateProjects() {
     213        let $projects = this.$('.svgator-popup-inner li');
     214        $projects.removeClass('svgator-on-page');
     215
     216        $projects = $projects.filter('.svgator-on-filter');
     217
     218        let $paginationContainer = this.$('#svgator-projects-pagination');
     219        $paginationContainer.empty();
     220
     221        let $ul = this.$('<ul>');
     222
     223        for (let i = 0; i < $projects.length; i++) {
     224            let page = parseInt(i / this.projectsPerPage) + 1;
     225            this.$($projects[i]).attr('data-page', page);
     226
     227            if (!$ul.find('[data-page="' + page + '"]').length) {
     228                let $li = this.$('<li>')
     229                    .attr('data-page', page)
     230                    .text(page);
     231
     232                $li.on('click', function() {
     233                    $projects.removeClass('svgator-on-page');
     234                    $projects.filter('[data-page="' + page + '"]').addClass('svgator-on-page');
     235                    $li.siblings().removeClass('active');
     236                    $li.addClass('active');
     237                });
     238
     239                $ul.append($li);
     240            }
     241        }
     242
     243        $paginationContainer.append($ul);
     244
     245        $ul.find('> li').first().click();
    138246    }
    139247
Note: See TracChangeset for help on using the changeset viewer.