Changeset 2015675
- Timestamp:
- 01/20/2019 09:24:10 AM (7 years ago)
- Location:
- last-comments-vk-widget
- Files:
-
- 2 added
- 3 edited
-
assets/screenshot-1.png (modified) (previous)
-
trunk/Readme.txt (modified) (2 diffs)
-
trunk/lang (added)
-
trunk/lang/last-comments-vk-widget.pot (added)
-
trunk/last-comments-vk-widget.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
last-comments-vk-widget/trunk/Readme.txt
r1484582 r2015675 3 3 Tags: vk, comments, widget 4 4 Requires at least: 1.0 5 Tested up to: 4. 65 Tested up to: 4.9.9 6 6 Stable tag: 1.0 7 7 … … 12 12 13 13 == Installation == 14 1) Install Vk comments in your site. 15 16 2) Install the plugin and add widget. 14 1. Install Vk comments in your site. 15 2. Install this plugin. 16 3. Add widget. 17 4. Use. 17 18 18 19 == 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. 23 22 24 23 == Screenshots == 25 1. Addwidget24 1. The widget 26 25 27 26 == Changelog == 28 27 1.0 Release 28 1.1 Completely rewritten code -
last-comments-vk-widget/trunk/last-comments-vk-widget.php
r1742619 r2015675 1 1 <?php 2 2 /* 3 Plugin Name: Last comments VK widget4 Plugin URI: none 5 Description: Widget last comments VK6 Version: 1.0 7 Author: Somonator8 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: 9 9 */ 10 10 11 /* Copyright 2016 Alexsandr (email: somonator@gmail.com) 11 /* 12 Copyright 2016 Alexsandr (email: somonator@gmail.com) 12 13 13 14 This program is free software; you can redistribute it and/or modify … … 26 27 */ 27 28 29 class 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']; 28 40 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']; 36 51 } 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'];42 52 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'; 56 57 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 } 62 62 63 public function get_field_html($name, $val, $translate, $required='') { 63 64 ?> 64 65 <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; ?>> 67 68 </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 81 70 } 82 71 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; 90 76 91 77 return $instance; … … 94 80 } 95 81 82 class 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 96 121 function register_lcv_widget() { 97 register_widget( 'Lcv_Widget' ); 122 new lcv_includes(); 123 register_widget('lcv_widget'); 98 124 } 99 add_action( 'widgets_init', 'register_lcv_widget' ); 125 126 add_action('widgets_init', 'register_lcv_widget');
Note: See TracChangeset
for help on using the changeset viewer.