PluginProbe
LIQUID SPEECH BALLOON / trunk
LIQUID SPEECH BALLOON vtrunk
1.2.7 1.2.6 trunk 1.0 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.4 1.1.5 1.1.6 1.1.7 1.1.9 1.2.1 1.2.5
liquid-speech-balloon / liquid-speech-balloon.php

liquid-speech-balloon.php in LIQUID SPEECH BALLOON trunk, at liquid-speech-balloon.php

377 lines 17.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: LIQUID SPEECH BALLOON
4 Plugin URI: https://lqd.jp/wp/plugin.html
5 Description: Create a talk style design with a visual editor Gutenberg.
6 Author: LIQUID DESIGN Ltd.
7 Author URI: https://lqd.jp/wp/
8 License: GPLv2
9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 Text Domain: liquid-speech-balloon
11 Version: 1.2.7
12 */
13 /* Copyright 2019 LIQUID DESIGN Ltd. (email : info@lqd.jp)
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License, version 2, as
17 published by the Free Software Foundation.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 */
27
28 // ------------------------------------
29 // Plugin
30 // ------------------------------------
31 function liquid_speech_balloon_init() {
32 load_plugin_textdomain( 'liquid-speech-balloon', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
33 }
34 add_action( 'init', 'liquid_speech_balloon_init' );
35
36 // api
37 if ( is_admin() ) {
38 $liquid_speech_balloon_api = require_once 'inc/api.php';
39 $liquid_speech_balloon_json = $liquid_speech_balloon_api('https://lqd.jp/wp/data/p/liquid-speech-balloon.json', 'liquid_speech_balloon_json');
40 }
41
42 // plugin_action_links_
43 function liquid_speech_balloon_plugin_action_links( $links ) {
44 $mylinks = '<a href="'.admin_url( 'options-general.php?page=liquid-speech-balloon' ).'">'.__( 'Settings', 'liquid-speech-balloon' ).'</a>';
45 array_unshift( $links, $mylinks);
46 return $links;
47 }
48 add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'liquid_speech_balloon_plugin_action_links' );
49
50 // get_option
51 $liquid_speech_balloon = get_option( 'liquid_speech_balloon' );
52 $liquid_speech_balloon_img = get_option( 'liquid_speech_balloon_img' );
53 $liquid_speech_balloon_name = get_option( 'liquid_speech_balloon_name' );
54 $liquid_speech_balloon_note = get_option( 'liquid_speech_balloon_note' );
55
56 // enqueue
57 if( empty( $liquid_speech_balloon ) ){
58 add_action( 'enqueue_block_editor_assets', 'liquid_speech_balloon_editor_assets' );
59 add_action( 'enqueue_block_assets', function () {
60 wp_enqueue_style( 'liquid-block-speech', plugins_url( 'css/block.css' , __FILE__ ), array() );
61 // エディター(iframe キャンバス�
62 を含む)にもアバター画像等のインライン CSS を届かせる。
63 // enqueue_block_editor_assets は親ドキュメント専用で iframe �
64 に反映されないため、ここで追加する
65 if ( is_admin() ) {
66 wp_add_inline_style( 'liquid-block-speech', liquid_speech_balloon_style_data() );
67 }
68 });
69 add_action( 'wp_head', 'liquid_speech_balloon_style' );
70 }
71
72 function liquid_speech_balloon_editor_assets() {
73 global $liquid_speech_balloon_name, $liquid_speech_balloon_note;
74 // enqueue(wp-editor 依存は新ウィジェットエディターで Notice が出るため wp-block-editor を使う)
75 wp_enqueue_script( 'liquid-block-speech', plugins_url( 'lib/block.js', __FILE__ ), array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor' ));
76 wp_enqueue_style( 'liquid-block-speech', plugins_url( 'css/block.css', __FILE__ ), array() );
77 // inline CSS は enqueue_block_assets 側で追加する(iframe �
78 対応・二重追加防止)
79 // translations
80 if ( function_exists( 'wp_set_script_translations' ) ) {
81 wp_set_script_translations( 'liquid-block-speech', 'liquid-speech-balloon', plugin_dir_path( __FILE__ ) . 'languages' );
82 }
83 // localize
84 if( empty( $liquid_speech_balloon_name ) ){
85 $liquid_speech_balloon_name = [];
86 }
87 if( empty( $liquid_speech_balloon_note ) ){
88 $liquid_speech_balloon_note = [];
89 }
90 wp_localize_script( 'liquid-block-speech', 'liquid_speech_balloon_name', $liquid_speech_balloon_name );
91 wp_localize_script( 'liquid-block-speech', 'liquid_speech_balloon_note', $liquid_speech_balloon_note );
92 }
93
94 // output style
95 function liquid_speech_balloon_style() {
96 $data = liquid_speech_balloon_style_data();
97 if( !empty( $data ) ){
98 echo '<style type="text/css">'.$data."</style>\n";
99 }
100 }
101
102 function liquid_speech_balloon_style_data() {
103 global $liquid_speech_balloon_img, $liquid_speech_balloon_name;
104 $data = '';
105 if( !empty( $liquid_speech_balloon_img ) ){
106 $i=0;
107 foreach ( $liquid_speech_balloon_img as $key => $value ) {
108 if( !empty( $value ) ){
109 $data.= '.liquid-speech-balloon-'.$key.' .liquid-speech-balloon-avatar { background-image: url("'.esc_url($value).'"); } ';
110 }
111 $i++;
112 }
113 }
114 if( !empty( $liquid_speech_balloon_name ) ){
115 $i=0;
116 foreach ( $liquid_speech_balloon_name as $key => $value ) {
117 if( !empty( $value ) ){
118 $data.= '.liquid-speech-balloon-'.$key.' .liquid-speech-balloon-avatar::after { content: "'.esc_html($value).'"; } ';
119 }
120 $i++;
121 }
122 }
123 return $data;
124 }
125
126 // ------------------------------------
127 // Admin
128 // ------------------------------------
129 function liquid_speech_balloon_admin() {
130 add_options_page(
131 'LIQUID SPEECH BALLOON',
132 'LIQUID SPEECH BALLOON',
133 'edit_posts',
134 'liquid-speech-balloon',
135 'liquid_speech_balloon_admin_page'
136 );
137 register_setting(
138 'liquid_speech_balloon_group',
139 'liquid_speech_balloon'
140 );
141 register_setting(
142 'liquid_speech_balloon_group',
143 'liquid_speech_balloon_img'
144 );
145 register_setting(
146 'liquid_speech_balloon_group',
147 'liquid_speech_balloon_name'
148 );
149 register_setting(
150 'liquid_speech_balloon_group',
151 'liquid_speech_balloon_note'
152 );
153 }
154 add_action( 'admin_menu', 'liquid_speech_balloon_admin' );
155
156 // 設定ページでメディアライブラリ(wp.media)を使えるようにする
157 function liquid_speech_balloon_admin_media( $hook ) {
158 if ( 'settings_page_liquid-speech-balloon' === $hook ) {
159 wp_enqueue_media();
160 }
161 }
162 add_action( 'admin_enqueue_scripts', 'liquid_speech_balloon_admin_media' );
163
164 // admin_page
165 function liquid_speech_balloon_admin_page() {
166 global $liquid_speech_balloon_json, $liquid_speech_balloon, $liquid_speech_balloon_img, $liquid_speech_balloon_name, $liquid_speech_balloon_note;
167
168 // POST
169 if( $_POST && check_admin_referer( 'liquid_speech_balloon_nonce_action', 'liquid_speech_balloon_nonce_field' ) ){
170 if( isset( $_POST['liquid_speech_balloon'] ) ) {
171 update_option( 'liquid_speech_balloon', htmlspecialchars( $_POST['liquid_speech_balloon'] ) );
172 $liquid_speech_balloon = htmlspecialchars( $_POST['liquid_speech_balloon'] );
173 $update_flag = 1;
174 }
175 if( isset( $_POST['liquid_speech_balloon_img'] ) ) {
176 if( is_array( $_POST['liquid_speech_balloon_img'] ) ){
177 $liquid_speech_balloon_img_post = array_map( 'htmlspecialchars', $_POST['liquid_speech_balloon_img'] );
178 }else{
179 $liquid_speech_balloon_img_post = htmlspecialchars( $_POST['liquid_speech_balloon_img'] );
180 }
181 update_option( 'liquid_speech_balloon_img', $liquid_speech_balloon_img_post );
182 $liquid_speech_balloon_img = $liquid_speech_balloon_img_post;
183 $update_flag = 1;
184 }
185 if( isset( $_POST['liquid_speech_balloon_name'] ) ) {
186 if( is_array( $_POST['liquid_speech_balloon_name'] ) ){
187 $liquid_speech_balloon_name_post = array_map( 'htmlspecialchars', $_POST['liquid_speech_balloon_name'] );
188 }else{
189 $liquid_speech_balloon_name_post = htmlspecialchars( $_POST['liquid_speech_balloon_name'] );
190 }
191 update_option( 'liquid_speech_balloon_name', $liquid_speech_balloon_name_post );
192 $liquid_speech_balloon_name = $liquid_speech_balloon_name_post;
193 $update_flag = 1;
194 }
195 if( isset( $_POST['liquid_speech_balloon_note'] ) ) {
196 if( is_array( $_POST['liquid_speech_balloon_note'] ) ){
197 $liquid_speech_balloon_note_post = array_map( 'htmlspecialchars', $_POST['liquid_speech_balloon_note'] );
198 }else{
199 $liquid_speech_balloon_note_post = htmlspecialchars( $_POST['liquid_speech_balloon_note'] );
200 }
201 update_option( 'liquid_speech_balloon_note', $liquid_speech_balloon_note_post );
202 $liquid_speech_balloon_note = $liquid_speech_balloon_note_post;
203 $update_flag = 1;
204 }
205 }
206 if( empty( $liquid_speech_balloon ) ){
207 $checked_on = 'checked="checked"';
208 $checked_off = '';
209 } else {
210 $checked_on = '';
211 $checked_off = 'checked="checked"';
212 }
213 ?>
214 <div class="wrap">
215 <h1>LIQUID SPEECH BALLOON</h1>
216
217 <?php if( !empty( $update_flag ) ) { ?>
218 <div class="notice notice-success is-dismissible"><p><strong><?php _e( 'Settings saved.', 'liquid-speech-balloon' ); ?></strong></p></div>
219 <?php } ?>
220
221 <div id="poststuff">
222
223 <!-- Recommend -->
224 <?php if( !empty($liquid_speech_balloon_json) && !empty($liquid_speech_balloon_json['recommend']) ){ ?>
225 <div class="postbox">
226 <h2 style="border-bottom: 1px solid #eee;"><?php _e( 'Recommend', 'liquid-speech-balloon' ); ?></h2>
227 <div class="inside"><?php echo wp_kses_post( $liquid_speech_balloon_json['recommend'] ); ?></div>
228 </div>
229 <?php } ?>
230
231 <!-- Settings -->
232 <div class="postbox">
233 <h2 style="border-bottom: 1px solid #eee;"><?php _e( 'Settings', 'liquid-speech-balloon' ); ?></h2>
234 <div class="inside">
235 <form method="post" name="liquid_speech_balloon_group" action="">
236 <?php
237 settings_fields( 'liquid_speech_balloon_group' );
238 do_settings_sections( 'default' );
239 wp_nonce_field( 'liquid_speech_balloon_nonce_action', 'liquid_speech_balloon_nonce_field' );
240 ?>
241 <table class="form-table">
242 <tbody>
243 <tr>
244 <th style="width:5em"><?php _e( 'Enable', 'liquid-speech-balloon' ); ?></th>
245 <td scope="row" colspan="3">
246 <label for="liquid_speech_balloon_on"><input type="radio" id="liquid_speech_balloon_on" name="liquid_speech_balloon" value="0" <?php echo $checked_on; ?>>On</label>
247 <label for="liquid_speech_balloon_off"><input type="radio" id="liquid_speech_balloon_off" name="liquid_speech_balloon" value="1" <?php echo $checked_off; ?>>Off</label>
248 </td>
249 </tr>
250 <tr>
251 <th scope="row" colspan="4"><?php _e( 'Avatar', 'liquid-speech-balloon' ); ?> [<a href="https://lqd.jp/wp/plugin/speech-balloon.html?utm_source=admin&utm_medium=plugin&utm_campaign=balloon" target="_blank"><?php _e( 'How to use', 'liquid-speech-balloon' ); ?></a>]</th>
252 </tr>
253 <tr>
254 <td style="padding:2px; width:5em">
255 <strong><label><?php _e( 'No.', 'liquid-speech-balloon' ); ?></label></strong>
256 </td>
257 <td style="padding:2px">
258 <strong><label><?php _e( 'Name', 'liquid-speech-balloon' ); ?></label></strong>
259 </td>
260 <td style="padding:2px">
261 <strong><label><a href="<?php echo admin_url('upload.php'); ?>" target="_blank"><?php _e( 'Image URL', 'liquid-speech-balloon' ); ?></a></label></strong>
262 </td>
263 <td style="padding:2px">
264 <strong><label><?php _e( 'Note (For admin screen)', 'liquid-speech-balloon' ); ?></label></strong>
265 </td>
266 </tr>
267 <?php
268 $count = !empty($liquid_speech_balloon_name) ? count($liquid_speech_balloon_name) : 11;
269 $count = 10<$count ? $count : 11;
270 for ($i=0; $i<$count; $i++) {
271 $j = sprintf('%02d', $i);
272 $name = !empty($liquid_speech_balloon_name[$j]) ? $liquid_speech_balloon_name[$j] : "";
273 $img = !empty($liquid_speech_balloon_img[$j]) ? $liquid_speech_balloon_img[$j] : "";
274 $note = !empty($liquid_speech_balloon_note[$j]) ? $liquid_speech_balloon_note[$j] : "";
275 if( $i!=0 ) {
276 echo '<tr><td style="padding:2px"><p>'.$j.'</p></td>';
277 } else {
278 echo '<tr><td style="padding:2px"><p>'.__( 'Default', 'liquid-speech-balloon' ).'</p></td>';
279 }
280 echo '<td style="padding:2px"><p><input class="widefat" type="text" name="liquid_speech_balloon_name['.$j.']" value="'.esc_attr($name).'"></p></td>';
281 echo '<td style="padding:2px"><p><input class="widefat" style="width:70%" type="url" name="liquid_speech_balloon_img['.$j.']" value="'.esc_url($img).'"> <button type="button" class="button lsb-media-btn" style="line-height:1">'.esc_html__( 'Select', 'liquid-speech-balloon' ).'</button> <img src="'.esc_url($img).'" alt="" style="width:22px; vertical-align:sub;"></p></td>';
282 if( $i!=0 ) {
283 echo '<td style="padding:2px"><p><input class="widefat" type="text" name="liquid_speech_balloon_note['.$j.']" value="'.esc_attr($note).'"></p></td>';
284 } else {
285 echo '<td style="padding:2px"><p><input class="widefat" type="text" name="liquid_speech_balloon_note['.$j.']" value="'.esc_attr($note).'"></p></td>';
286 }
287 echo '</tr>';
288 }
289 $j++;
290 echo '<tr><td style="padding:2px"><p id="btn_add" class="button">'.__( 'Add', 'liquid-speech-balloon' ).'</p></td>';
291 echo '<td style="padding:2px;visibility:hidden;" class="hides"><p><input class="widefat dises" type="text" name="liquid_speech_balloon_name['.$j.']" value="" disabled></p></td>';
292 echo '<td style="padding:2px;visibility:hidden;" class="hides"><p><input class="widefat dises" style="width:70%" type="url" name="liquid_speech_balloon_img['.$j.']" value="" disabled> <button type="button" class="button lsb-media-btn" style="line-height:1">'.esc_html__( 'Select', 'liquid-speech-balloon' ).'</button></p></td>';
293 echo '<td style="padding:2px;visibility:hidden;" class="hides"><p><input class="widefat dises" type="text" name="liquid_speech_balloon_note['.$j.']" value="" disabled></p></td>';
294 echo '</tr>';
295 ?>
296 </tbody>
297 </table>
298 <input type="hidden" name="liquid_speech_balloon_name" value="" disabled class="deletions">
299 <input type="hidden" name="liquid_speech_balloon_img" value="" disabled class="deletions">
300 <input type="hidden" name="liquid_speech_balloon_note" value="" disabled class="deletions">
301 <p id="btn_del"><input type="checkbox" name="delete" value="" id="btn_del_check" onclick="btn_del();"> <?php _e( 'Delete All', 'liquid-speech-balloon' ); ?></p>
302 <?php submit_button(); ?>
303 <script>
304 // media select
305 document.addEventListener('click', function (e) {
306 var btn = e.target.closest('.lsb-media-btn');
307 if (!btn || typeof wp === 'undefined' || !wp.media) {
308 return;
309 }
310 e.preventDefault();
311 var input = btn.parentNode.querySelector('input[type="url"]');
312 var frame = wp.media({
313 title: '<?php echo esc_js( __( 'Select Image', 'liquid-speech-balloon' ) ); ?>',
314 library: { type: 'image' },
315 multiple: false
316 });
317 frame.on('select', function () {
318 var att = frame.state().get('selection').first().toJSON();
319 var url = (att.sizes && att.sizes.thumbnail) ? att.sizes.thumbnail.url : att.url;
320 input.value = url;
321 var img = btn.parentNode.querySelector('img');
322 if (img) {
323 img.src = url;
324 }
325 });
326 frame.open();
327 });
328 // add
329 document.getElementById("btn_add").onclick = function onclick(event) {
330 this.classList.remove("button");
331 document.querySelectorAll('.dises').forEach(item => item.disabled = false);
332 document.querySelectorAll('.hides').forEach(item => item.style.visibility ="visible");
333 }
334 // del
335 function btn_del(){
336 check = document.getElementById("btn_del_check").checked;
337 if (check == true) {
338 document.getElementById("btn_del").style.color = "red";
339 document.querySelectorAll('.deletions').forEach(item => item.disabled = false);
340 window.alert("<?php esc_html_e( 'Delete All', 'liquid-speech-balloon' ); ?>");
341 } else {
342 document.getElementById("btn_del").style.color = "";
343 document.querySelectorAll('.deletions').forEach(item => item.disabled = true);
344 }
345 }
346 </script>
347 </form>
348
349 </div>
350 </div>
351
352 </div><!-- /poststuff -->
353 <hr><a href="https://lqd.jp/wp/" target="_blank">LIQUID PRESS</a>
354 </div><!-- /wrap -->
355 <?php }
356
357 // notices
358 function liquid_speech_balloon_admin_notices() {
359 global $liquid_speech_balloon_json;
360 if( !empty($liquid_speech_balloon_json) ) {
361 if ( isset( $_GET['liquid_admin_notices_dismissed'] ) ) {
362 set_transient( 'liquid_admin_notices', 'dismissed', 60*60*24*180 );
363 }
364 if ( isset( $_GET['liquid_admin_offer_dismissed'] ) ) {
365 set_transient( 'liquid_admin_offer', 'dismissed', 60*60*24*180 );
366 }
367 if( !empty($liquid_speech_balloon_json['news']) && get_transient( 'liquid_admin_notices' ) != 'dismissed' ){
368 echo '<div class="notice notice-info" style="position: relative;"><p>'.wp_kses_post($liquid_speech_balloon_json['news']).'</p><a href="?liquid_admin_notices_dismissed" style="position: absolute; right: 10px; top: 10px;">&times;</a></div>';
369 }
370 if( !empty($liquid_speech_balloon_json['offer']) && get_transient( 'liquid_admin_offer' ) != 'dismissed' ){
371 echo '<div class="notice notice-info" style="position: relative;"><p>'.wp_kses_post($liquid_speech_balloon_json['offer']).'</p><a href="?liquid_admin_offer_dismissed" style="position: absolute; right: 10px; top: 10px;">&times;</a></div>';
372 }
373 }
374 }
375 add_action( 'admin_notices', 'liquid_speech_balloon_admin_notices' );
376
377 ?>