Changeset 2176027
- Timestamp:
- 10/19/2019 08:52:32 AM (6 years ago)
- Location:
- last-comments-vk-widget/trunk
- Files:
-
- 1 added
- 1 deleted
- 2 edited
-
Readme.txt (modified) (2 diffs)
-
lang/last-comments-vk-widget.pot (deleted)
-
lang/lcw.pot (added)
-
last-comments-vk-widget.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
last-comments-vk-widget/trunk/Readme.txt
r2149034 r2176027 2 2 Contributors: Somonator 3 3 Tags: vk, comments, widget 4 Requires at least: 1.0 5 Tested up to: 4.9.9 6 Stable tag: 1.0 4 Tested up to: 5.2.3 7 5 8 6 Widget last comments VK … … 27 25 1.1 Completely rewritten code 28 26 1.2 Minification of the layout code, processing the required fields 27 1.3 Add universal code for widgets and ect -
last-comments-vk-widget/trunk/last-comments-vk-widget.php
r2149034 r2176027 1 1 <?php 2 2 /* 3 Plugin Name: Last comments VK widget 4 Plugin URI: 3 Plugin Name: Last comments VK Widget 5 4 Description: Widget last comments VK 6 Version: 1. 25 Version: 1.3 7 6 Author: Somonator 8 Author URI: 7 Author URI: mailto:somonator@gmail.com 8 Text Domain: lcw 9 Domain Path: /lang 9 10 */ 10 11 … … 27 28 */ 28 29 29 class lc v_widget extends WP_Widget {30 class lcw_widget extends WP_Widget { 30 31 function __construct() { 31 parent::__construct('', __('Last comments VK', 'lc v'), array(32 'description' => __('Widget last comments VK', 'lc v')33 ) );32 parent::__construct('', __('Last comments VK', 'lcw'), array( 33 'description' => __('Widget last comments VK', 'lcw') 34 )); 34 35 } 35 36 … … 37 38 $title = apply_filters('widget_title', $instance['title']); 38 39 $appid = @ $instance['appid']; 39 $limit = @ $instance['limit']; 40 40 $limit = @ $instance['limit']; 41 41 42 echo $args['before_widget']; 42 43 … … 45 46 } 46 47 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 50 55 echo $args['after_widget']; 51 56 } 52 57 53 58 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'; 57 62 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')); 61 66 } 62 67 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>'; 71 77 } 72 78 73 79 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; 77 83 78 84 return $instance; … … 81 87 } 82 88 83 class lc v_includes {89 class lcw_includes { 84 90 function __construct() { 85 if (is_active_widget(false, false, 'lc v_widget') || is_customize_preview()) {91 if (is_active_widget(false, false, 'lcw_widget') || is_customize_preview()) { 86 92 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')); 88 94 } 95 89 96 add_action('admin_footer', array($this, 'add_scripts_to_admin')); 90 97 add_action('plugins_loaded', array($this, 'lang_load')); … … 95 102 wp_enqueue_script('vk-api', '//vk.com/js/api/openapi.js'); 96 103 } 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});}');98 104 } 99 105 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>'; 104 108 } 105 109 106 110 public function add_scripts_to_admin() { 107 111 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>'; 111 113 } 112 114 } 113 115 114 116 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/'); 116 118 } 117 119 } 118 120 119 function register_lcv_widget() { 120 new lcv_includes(); 121 register_widget('lcv_widget'); 121 122 /** 123 * Init widget. 124 */ 125 function register_lcw_widget() { 126 register_widget('lcw_widget'); 122 127 } 123 128 124 add_action('widgets_init', 'register_lcv_widget'); 129 add_action('widgets_init', 'register_lcw_widget'); 130 131 /** 132 * Stylea, scripts and lang. 133 */ 134 new lcw_includes();
Note: See TracChangeset
for help on using the changeset viewer.