Plugin Directory

Changeset 2176027


Ignore:
Timestamp:
10/19/2019 08:52:32 AM (6 years ago)
Author:
Somonator
Message:

update to 1.3

Location:
last-comments-vk-widget/trunk
Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • last-comments-vk-widget/trunk/Readme.txt

    r2149034 r2176027  
    22Contributors: Somonator
    33Tags: vk, comments, widget
    4 Requires at least: 1.0
    5 Tested up to: 4.9.9
    6 Stable tag: 1.0
     4Tested up to: 5.2.3
    75
    86Widget last comments VK
     
    27251.1 Completely rewritten code
    28261.2 Minification of the layout code, processing the required fields
     271.3 Add universal code for widgets and ect
  • last-comments-vk-widget/trunk/last-comments-vk-widget.php

    r2149034 r2176027  
    11<?php
    22/*
    3     Plugin Name: Last comments VK widget
    4     Plugin URI:
     3    Plugin Name: Last comments VK Widget
    54    Description: Widget last comments VK
    6     Version: 1.2
     5    Version: 1.3
    76    Author: Somonator
    8     Author URI:
     7    Author URI: mailto:somonator@gmail.com
     8    Text Domain: lcw
     9    Domain Path: /lang
    910*/
    1011
     
    2728*/
    2829
    29 class lcv_widget extends WP_Widget {
     30class lcw_widget extends WP_Widget {
    3031    function __construct() {
    31         parent::__construct('', __('Last comments VK', 'lcv'), array(
    32             'description' => __('Widget last comments VK', 'lcv')
    33         ) );
     32        parent::__construct('', __('Last comments VK', 'lcw'), array(
     33            'description' => __('Widget last comments VK', 'lcw')
     34        ));
    3435    }
    3536   
     
    3738        $title = apply_filters('widget_title', $instance['title']);
    3839        $appid = @ $instance['appid']; 
    39         $limit = @ $instance['limit']; 
    40 
     40        $limit = @ $instance['limit'];
     41       
    4142        echo $args['before_widget'];
    4243       
     
    4546        }
    4647       
    47         echo '<div id="last-comments-vk"></div>';
    48         echo '<script>var lcv = {"appid": "' . $appid . '", "limit": "' . $limit . '"};</script>';
    49            
     48        if (!empty($appid)) {
     49            echo '<div id="container-' . $this->id . '"></div>';
     50            echo '<script>window.onload = function () {VK.init({apiId: ' . $appid . ', onlyWidgets: false}); VK.Widgets.CommentsBrowse("container-' . $this->id . '", {limit: ' . $limit . ', mini: 0});}</script>';
     51        } else {
     52            echo '<p>' . __('Please enter vk app id for work widget.', 'lcw') . '</p>';
     53        }
     54       
    5055        echo $args['after_widget'];
    5156    }
    5257
    5358    public function form($instance) {
    54         $title = @ $instance['title']?:'';
    55         $appid = @ $instance['appid']?:'';
    56         $limit = @ $instance['limit']?:'5';
     59        $title = @ $instance['title'] ? : null;
     60        $appid = @ $instance['appid'] ? : null;
     61        $limit = @ $instance['limit'] ? : '5';
    5762
    58         echo $this->get_field_html('title', $title, __('Title:','lcv'));
    59         echo $this->get_field_html('appid', $appid, __('App id VK:*','lcv'), true);
    60         echo $this->get_field_html('limit', $limit, __('Number comments:','lcv'));
     63        echo $this->get_field_html('title', $title, __('Title:', 'lcw'));
     64        echo $this->get_field_html('appid', $appid, __('App id VK:*', 'lcw'), true);
     65        echo $this->get_field_html('limit', $limit, __('Number comments:', 'lcw'));
    6166    }
    6267
    63     public function get_field_html($name, $val, $translate, $required='') {
    64         ?>
    65         <p>
    66             <label><?php echo $translate; ?>
    67                 <input type="text" name="<?php echo $this->get_field_name($name); ?>" value="<?php echo esc_attr($val); ?>" class="widefat" <?php echo !empty($required)?'required':null; ?>>
    68             </label>
    69         </p>
    70         <?php
     68    public function get_field_html($name, $val, $translate, $required = '') {
     69        $name = $this->get_field_name($name);
     70        $val =  esc_attr($val);
     71        $req = $required ? 'required' : null;
     72       
     73        echo '<p>';
     74            echo '<label>' . $translate;
     75            echo '<input type="text" name="' . $name . '" value="' . $val . '" class="widefat" ' . $req  . '>';
     76        echo '</p>';
    7177    }
    7278
    7379    public function update($new_instance, $old_instance) {
    74         $instance['title'] = !empty($new_instance['title'])?strip_tags($new_instance['title']):null;
    75         $instance['appid'] = !empty($new_instance['appid'])?strip_tags($new_instance['appid']):null;
    76         $instance['limit'] = !empty($new_instance['limit'])?strip_tags($new_instance['limit']):null;
     80        $instance['title'] = !empty($new_instance['title']) ? strip_tags($new_instance['title']) : null;
     81        $instance['appid'] = !empty($new_instance['appid']) ? strip_tags($new_instance['appid']) : null;
     82        $instance['limit'] = !empty($new_instance['limit']) ? strip_tags($new_instance['limit']) : null;
    7783
    7884        return $instance;
     
    8187}
    8288
    83 class lcv_includes {
     89class lcw_includes {
    8490    function __construct() {
    85         if (is_active_widget(false, false, 'lcv_widget') || is_customize_preview()) {
     91        if (is_active_widget(false, false, 'lcw_widget') || is_customize_preview()) {
    8692            add_action('wp_enqueue_scripts', array($this, 'vk_api'), 11);
    87             add_action('wp_footer', array($this, 'inner_scripts'));
     93            add_action('wp_footer', array($this, 'add_scripts'));
    8894        }
     95
    8996        add_action('admin_footer', array($this, 'add_scripts_to_admin'));
    9097        add_action('plugins_loaded', array($this, 'lang_load'));       
     
    95102            wp_enqueue_script('vk-api', '//vk.com/js/api/openapi.js');
    96103        }
    97         wp_add_inline_script('vk-api', 'window.onload = function () {VK.init({apiId: lcv.appid, onlyWidgets: false}); VK.Widgets.CommentsBrowse("last-comments-vk", {limit: lcv.limit, mini: 0});}');
    98104    }
    99105   
    100     public function inner_scripts() {
    101         ?>
    102         <style>#last-comments-vk,#last-comments-vk iframe{width:100%!important;max-width:100%!important;display:table;}</style>
    103         <?php
     106    public function add_scripts() {
     107        echo '<style>[id*="container-lcw_widget"],[id*="container-lcw_widget"] iframe{width:100%!important;max-width:100%!important;display:table;}</style>';
    104108    }
    105109   
    106110    public function add_scripts_to_admin() {
    107111        if (get_current_screen()->base == 'widgets') {
    108             ?>
    109             <script>jQuery(function($){$(document).delegate('[id*="lcv_widget"] input[name="savewidget"]', 'click', function() {var $form = $(this).parents().closest('form');$form.find('input[required]').each(function() {if (!$(this)[0].checkValidity()) {$(this)[0].reportValidity();}});});});</script>
    110             <?php
     112            echo '<script>jQuery(function($){$(document).delegate(\'[id*="lcw_widget"] input[name="savewidget"]\', \'click\', function() {var $form = $(this).parents().closest(\'form\');$form.find(\'input[required]\').each(function() {if (!$(this)[0].checkValidity()) {$(this)[0].reportValidity();}});});});</script>';
    111113        }
    112114    }
    113115   
    114116    public function lang_load() {
    115         load_plugin_textdomain('simple-soc-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/');
     117        load_plugin_textdomain('lcw', false, dirname(plugin_basename( __FILE__ )) . '/lang/');
    116118    }
    117119}
    118120
    119 function register_lcv_widget() {
    120     new lcv_includes();
    121     register_widget('lcv_widget');
     121
     122/**
     123* Init widget.
     124*/
     125function register_lcw_widget() {
     126    register_widget('lcw_widget');
    122127}
    123128
    124 add_action('widgets_init', 'register_lcv_widget');
     129add_action('widgets_init', 'register_lcw_widget');
     130
     131/**
     132* Stylea, scripts and lang.
     133*/
     134new lcw_includes();
Note: See TracChangeset for help on using the changeset viewer.