Plugin Directory

Changeset 2015675


Ignore:
Timestamp:
01/20/2019 09:24:10 AM (7 years ago)
Author:
Somonator
Message:

update plugin to version 1.1

Location:
last-comments-vk-widget
Files:
2 added
3 edited

Legend:

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

    r1484582 r2015675  
    33Tags: vk, comments, widget
    44Requires at least: 1.0
    5 Tested up to: 4.6
     5Tested up to: 4.9.9
    66Stable tag: 1.0
    77
     
    1212
    1313== Installation ==
    14 1) Install Vk comments in your site.
    15 
    16 2) Install the plugin and add widget.
     141. Install Vk comments in your site.
     152. Install this plugin.
     163. Add widget.
     174. Use.
    1718
    1819== Frequently Asked Questions ==
    19 In setting up the widget has a few options:
    20 ? App ID: Get the ID of the page on VKontakte editing application.
    21 ? Width: for mobile \"auto\".
    22 ? Limit: The amount administered commentsþ
     20● Get the ID of the page on VKontakte editing application.
     21● The output cannot be adapted for media less than 300 pixels.
    2322
    2423== Screenshots ==
    25 1. Add widget
     241. The widget
    2625
    2726== Changelog ==
    28271.0 Release
     281.1 Completely rewritten code
  • last-comments-vk-widget/trunk/last-comments-vk-widget.php

    r1742619 r2015675  
    11<?php
    22/*
    3 Plugin Name: Last comments VK widget
    4 Plugin URI: none
    5 Description: Widget last comments VK
    6 Version: 1.0
    7 Author: Somonator
    8 Author URI: none
     3    Plugin Name: Last comments VK widget
     4    Plugin URI:
     5    Description: Widget last comments VK
     6    Version: 1.1
     7    Author: Somonator
     8    Author URI:
    99*/
    1010
    11 /*  Copyright 2016  Alexsandr (email: somonator@gmail.com)
     11/* 
     12    Copyright 2016  Alexsandr (email: somonator@gmail.com)
    1213
    1314    This program is free software; you can redistribute it and/or modify
     
    2627*/
    2728
     29class lcv_widget extends WP_Widget {
     30    function __construct() {
     31        parent::__construct('', __('Last comments VK', 'lcv'), array(
     32            'description' => __('Widget last comments VK', 'lcv')
     33        ) );
     34    }
     35   
     36    public function widget( $args, $instance ) {
     37        $title = apply_filters('widget_title', $instance['title']);
     38        $appid = @ $instance['appid']; 
     39        $limit = @ $instance['limit'];
    2840
    29 class Lcv_Widget extends WP_Widget {
    30     function __construct() {
    31         parent::__construct(
    32             'lcv_widget',
    33             'Last comments VK',
    34             array( 'description' => 'Widget last comments VK', /*'classname' => 'my_widget',*/ )
    35         );
     41        echo $args['before_widget'];
     42       
     43        if (!empty($title)) {
     44          echo $args['before_title'] . $title . $args['after_title'];
     45        }
     46       
     47        echo '<div id="last-comments-vk"></div>';
     48        echo '<script>var lcv = {"appid": "' . $appid . '", "limit": "' . $limit . '"};</script>';
     49           
     50        echo $args['after_widget'];
    3651    }
    37     function widget( $args, $instance ) {
    38     $title = apply_filters( 'widget_title', $instance['title'] );
    39     $appid =@ $instance['appid'];
    40     $limit =@ $instance['limit'];
    41     $width =@ $instance['width'];
    4252
    43     echo $args['before_widget'];
    44     if ( ! empty( $title ) ) {
    45       echo $args['before_title'] . $title . $args['after_title'];
    46     }
    47     echo '<div id="vk_comments1"></div>
    48 <script type="text/javascript">
    49 window.onload = function () {
    50  VK.init({apiId: '.$appid.', onlyWidgets: false});
    51  VK.Widgets.CommentsBrowse("vk_comments1", {width: "'.$width.'", limit: '.$limit.', mini: 0});
    52 }
    53 </script>' ;
    54     echo $args['after_widget'];
    55   }
     53    public function form($instance) {
     54        $title = @ $instance['title']?:'';
     55        $appid = @ $instance['appid']?:'';
     56        $limit = @ $instance['limit']?:'5';
    5657
    57     function form( $instance ) {
    58         $title = @ $instance['title'] ?: '';
    59         $appid = @ $instance['appid'] ?: '111';
    60         $width = @ $instance['width'] ?: 'auto';
    61         $limit = @ $instance['limit'] ?: '5';
     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'));
     61    }
    6262
     63    public function get_field_html($name, $val, $translate, $required='') {
    6364        ?>
    6465        <p>
    65             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    66             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
     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; ?>>
    6768        </p>
    68         <p>
    69             <label for="<?php echo $this->get_field_id( 'appid' ); ?>"><?php _e( 'App id VK:' ); ?></label>
    70             <input class="widefat" id="<?php echo $this->get_field_id( 'appid' ); ?>" name="<?php echo $this->get_field_name( 'appid' ); ?>" type="text" value="<?php echo esc_attr( $appid ); ?>">
    71         </p>
    72         <p>
    73             <label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php _e( 'Width:' ); ?></label>
    74             <input class="widefat" id="<?php echo $this->get_field_id( 'width' ); ?>" name="<?php echo $this->get_field_name( 'width' ); ?>" type="text" value="<?php echo esc_attr( $width ); ?>">
    75         </p>
    76         <p>
    77             <label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e( 'Limit:' ); ?></label>
    78             <input class="widefat" id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>">
    79         </p>
    80         <?php
     69        <?php
    8170    }
    8271
    83 
    84     function update( $new_instance, $old_instance ) {
    85         $instance = array();
    86         $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
    87         $instance['appid'] = ( ! empty( $new_instance['appid'] ) ) ? strip_tags( $new_instance['appid'] ) : '';
    88         $instance['width'] = ( ! empty( $new_instance['width'] ) ) ? strip_tags( $new_instance['width'] ) : '';
    89         $instance['limit'] = ( ! empty( $new_instance['limit'] ) ) ? strip_tags( $new_instance['limit'] ) : '';
     72    public function update($new_instance, $old_instance) {
     73        $instance['title'] = !empty($new_instance['title'])?strip_tags($new_instance['title']):null;
     74        $instance['appid'] = !empty($new_instance['appid'])?strip_tags($new_instance['appid']):null;
     75        $instance['limit'] = !empty($new_instance['limit'])?strip_tags($new_instance['limit']):null;
    9076
    9177        return $instance;
     
    9480}
    9581
     82class lcv_includes {
     83    function __construct() {
     84        if (is_active_widget(false, false, 'lcv_widget') || is_customize_preview()) {
     85            add_action('wp_enqueue_scripts', array($this, 'vk_api'), 11);
     86            add_action('wp_footer', array($this, 'inner_scripts'));
     87        }
     88        add_action('plugins_loaded', array($this, 'lang_load'));       
     89    }
     90   
     91    public function vk_api() {
     92        if (!wp_script_is('vk-api', 'enqueued')) {
     93            wp_enqueue_script('vk-api', '//vk.com/js/api/openapi.js');
     94        }
     95        wp_add_inline_script('vk-api', '
     96            window.onload = function () {
     97                VK.init({apiId: lcv.appid, onlyWidgets: false});
     98                VK.Widgets.CommentsBrowse("last-comments-vk", {limit: lcv.limit, mini: 0});
     99            }
     100        ');
     101    }
     102   
     103    public function inner_scripts() {
     104        ?>
     105        <style>
     106            #last-comments-vk,
     107            #last-comments-vk iframe {
     108                width: 100% !important;
     109                max-width: 100% !important;         
     110                display: table;
     111            }
     112        </style>
     113        <?php
     114    }
     115   
     116    public function lang_load() {
     117        load_plugin_textdomain('simple-soc-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/');
     118    }
     119}
     120
    96121function register_lcv_widget() {
    97     register_widget( 'Lcv_Widget' );
     122    new lcv_includes();
     123    register_widget('lcv_widget');
    98124}
    99 add_action( 'widgets_init', 'register_lcv_widget' );
     125
     126add_action('widgets_init', 'register_lcv_widget');
Note: See TracChangeset for help on using the changeset viewer.