PluginProbe
AL Pack / 1.0.0
AL Pack v1.0.0
1.3.13 trunk 1.0.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.11 1.3.12
alpack / includes / buttons.php

buttons.php in AL Pack 1.0.0, at includes/buttons.php

734 lines 29.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 exit;
4 }
5
6 function presslearn_is_plugin_active_for_buttons() {
7 $is_activated = false;
8 if (function_exists('presslearn_plugin')) {
9 $is_activated = presslearn_plugin()->is_plugin_activated();
10 }
11 return $is_activated;
12 }
13
14 function presslearn_register_quick_button_block() {
15 if (!presslearn_is_plugin_active_for_buttons()) {
16 return;
17 }
18
19 $quick_button_enabled = get_option('presslearn_quick_button_enabled', 'no');
20 if ($quick_button_enabled !== 'yes') {
21 return;
22 }
23
24 wp_register_script(
25 'presslearn-quick-button-block',
26 false,
27 array('wp-blocks', 'wp-element', 'wp-editor', 'wp-components'),
28 time(),
29 true
30 );
31
32 $button_transition_enabled = get_option('presslearn_button_transition_enabled', 'no');
33
34 wp_add_inline_script('presslearn-quick-button-block', '
35 (function(blocks, element, components, editor) {
36 var el = element.createElement;
37 var RichText = editor.RichText;
38 var ColorPalette = components.ColorPalette;
39 var InspectorControls = editor.InspectorControls;
40 var TextControl = components.TextControl;
41 var SelectControl = components.SelectControl;
42 var PanelBody = components.PanelBody;
43 var PanelRow = components.PanelRow;
44
45 var buttonIcon = el("svg", { width: 24, height: 24, viewBox: "0 0 24 24" },
46 el("path", {
47 d: "M19 6H5c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 10H5V8h14v8z",
48 fill: "#2196F3"
49 })
50 );
51
52 var infiniteAnimationEnabled = "' . esc_js($button_transition_enabled === 'yes' ? 'yes' : 'no') . '";
53
54 blocks.registerBlockType("presslearn/quick-button", {
55 title: "PL 빠른 버튼",
56 icon: buttonIcon,
57 category: "presslearn",
58 keywords: ["버튼", "button", "link", "presslearn"],
59 description: "클릭 가능한 버튼을 추가합니다. �
60 �스트, URL, 색상 및 정렬을 사용자 정의할 수 있습니다.",
61 attributes: {
62 buttonText: {
63 type: "string",
64 default: "버튼 �
65 �스트"
66 },
67 buttonUrl: {
68 type: "string",
69 default: "#"
70 },
71 buttonColor: {
72 type: "string",
73 default: "#2196F3"
74 },
75 buttonTextColor: {
76 type: "string",
77 default: "#ffffff"
78 },
79 buttonHoverColor: {
80 type: "string",
81 default: ""
82 },
83 buttonPosition: {
84 type: "string",
85 default: "center"
86 },
87 buttonSize: {
88 type: "string",
89 default: "medium"
90 },
91 buttonWidth: {
92 type: "string",
93 default: "default"
94 },
95 openInNewTab: {
96 type: "boolean",
97 default: false
98 },
99 buttonAnimation: {
100 type: "string",
101 default: "none"
102 },
103 infiniteAnimation: {
104 type: "string",
105 default: infiniteAnimationEnabled
106 }
107 },
108 example: {
109 attributes: {
110 buttonText: "버튼 미리보기",
111 buttonColor: "#2196F3",
112 buttonPosition: "center"
113 }
114 },
115 edit: function(props) {
116 var attributes = props.attributes;
117
118 function onChangeText(newText) {
119 props.setAttributes({ buttonText: newText });
120 }
121
122 function onChangeUrl(newUrl) {
123 props.setAttributes({ buttonUrl: newUrl });
124 }
125
126 function onChangeColor(newColor) {
127 props.setAttributes({ buttonColor: newColor });
128 }
129
130 function onChangeTextColor(newColor) {
131 props.setAttributes({ buttonTextColor: newColor });
132 }
133
134 function onChangeHoverColor(newColor) {
135 props.setAttributes({ buttonHoverColor: newColor });
136 }
137
138 function onChangePosition(newPosition) {
139 props.setAttributes({ buttonPosition: newPosition });
140 }
141
142 function onChangeSize(newSize) {
143 props.setAttributes({ buttonSize: newSize });
144 }
145
146 function onChangeWidth(newWidth) {
147 props.setAttributes({ buttonWidth: newWidth });
148 }
149
150 function onChangeOpenInNewTab(newValue) {
151 props.setAttributes({ openInNewTab: newValue });
152 }
153
154 function onChangeAnimation(newAnimation) {
155 props.setAttributes({ buttonAnimation: newAnimation });
156 }
157
158 var buttonPadding;
159 switch(attributes.buttonSize) {
160 case "small":
161 buttonPadding = "8px 16px";
162 break;
163 case "large":
164 buttonPadding = "16px 32px";
165 break;
166 case "xlarge":
167 buttonPadding = "20px 40px";
168 break;
169 default: // medium
170 buttonPadding = "12px 24px";
171 }
172
173 var fontSize;
174 switch(attributes.buttonSize) {
175 case "small":
176 fontSize = "13px";
177 break;
178 case "large":
179 fontSize = "18px";
180 break;
181 case "xlarge":
182 fontSize = "22px";
183 break;
184 default: // medium
185 fontSize = "15px";
186 }
187
188 var buttonWidth = "auto";
189 var textAlign = "inherit";
190 if (attributes.buttonWidth === "half") {
191 buttonWidth = "50%";
192 textAlign = "center";
193 } else if (attributes.buttonWidth === "full") {
194 buttonWidth = "100%";
195 textAlign = "center";
196 }
197
198 var positionControl = null;
199 if (attributes.buttonWidth !== "full") {
200 positionControl = el(PanelRow, {},
201 el(SelectControl, {
202 label: "버튼 위치",
203 value: attributes.buttonPosition,
204 options: [
205 { label: "왼쪽", value: "left" },
206 { label: "가운데", value: "center" },
207 { label: "오른쪽", value: "right" }
208 ],
209 onChange: onChangePosition
210 })
211 );
212 }
213
214 var containerAlignment = attributes.buttonPosition;
215
216 if (attributes.buttonWidth === "full") {
217 containerAlignment = "center";
218 }
219
220 var animationClass = "presslearn-button presslearn-button-animation-" + attributes.buttonAnimation;
221 if (infiniteAnimationEnabled === "yes" && attributes.buttonAnimation !== "none") {
222 animationClass += " presslearn-button-animation-infinite";
223 }
224
225 return [
226 el(InspectorControls, { key: "controls" },
227 el(PanelBody, { title: "버튼 설정", initialOpen: true },
228 el(PanelRow, {},
229 el(TextControl, {
230 label: "버튼 �
231 �스트",
232 value: attributes.buttonText,
233 onChange: onChangeText
234 })
235 ),
236 el(PanelRow, {},
237 el(TextControl, {
238 label: "버튼 URL",
239 value: attributes.buttonUrl,
240 onChange: onChangeUrl
241 })
242 ),
243 el(PanelRow, {},
244 el(components.ToggleControl, {
245 label: "새 탭에서 열기",
246 checked: attributes.openInNewTab,
247 onChange: onChangeOpenInNewTab
248 })
249 ),
250 el(PanelRow, {},
251 el("div", { className: "components-base-control" },
252 el("label", { className: "components-base-control__label" }, "버튼 배경 색상"),
253 el(ColorPalette, {
254 value: attributes.buttonColor,
255 onChange: onChangeColor,
256 clearable: false
257 })
258 )
259 ),
260 el(PanelRow, {},
261 el("div", { className: "components-base-control" },
262 el("label", { className: "components-base-control__label" }, "버튼 글씨 색상"),
263 el(ColorPalette, {
264 value: attributes.buttonTextColor,
265 onChange: onChangeTextColor,
266 clearable: false
267 })
268 )
269 ),
270 el(PanelRow, {},
271 el("div", { className: "components-base-control" },
272 el("label", { className: "components-base-control__label" }, "마우스 오버시 배경 색상"),
273 el(ColorPalette, {
274 value: attributes.buttonHoverColor,
275 onChange: onChangeHoverColor,
276 clearable: true
277 })
278 )
279 ),
280 el(PanelRow, {},
281 el(SelectControl, {
282 label: "버튼 가로 크기",
283 value: attributes.buttonWidth,
284 options: [
285 { label: "기본", value: "default" },
286 { label: "절반", value: "half" },
287 { label: "꽉찬", value: "full" }
288 ],
289 onChange: onChangeWidth
290 })
291 ),
292 positionControl,
293 el(PanelRow, {},
294 el(SelectControl, {
295 label: "버튼 크기",
296 value: attributes.buttonSize,
297 options: [
298 { label: "작게", value: "small" },
299 { label: "중간", value: "medium" },
300 { label: "크게", value: "large" },
301 { label: "매우 크게", value: "xlarge" }
302 ],
303 onChange: onChangeSize
304 })
305 ),
306 el(PanelRow, {},
307 el(SelectControl, {
308 label: "애니메이�
309 � 효과",
310 value: attributes.buttonAnimation,
311 options: [
312 { label: "없음", value: "none" },
313 { label: "펄스", value: "pulse" },
314 { label: "줌", value: "zoom" },
315 { label: "페이드", value: "fade" },
316 { label: "떨림", value: "shake" }
317 ],
318 onChange: onChangeAnimation
319 })
320 )
321 )
322 ),
323 el("div", { className: "presslearn-button-block-editor" },
324 el("div", {
325 className: "presslearn-button-container",
326 style: { textAlign: containerAlignment }
327 },
328 el("a", {
329 className: animationClass,
330 href: "#",
331 style: {
332 display: "inline-block",
333 padding: buttonPadding,
334 backgroundColor: attributes.buttonColor,
335 color: attributes.buttonTextColor,
336 textDecoration: "none",
337 borderRadius: "4px",
338 fontWeight: "bold",
339 fontSize: fontSize,
340 width: buttonWidth,
341 textAlign: textAlign,
342 boxSizing: "border-box",
343 transition: "all 0.3s ease-in-out"
344 },
345 "data-hover-color": attributes.buttonHoverColor || attributes.buttonColor
346 }, attributes.buttonText || "버튼 �
347 �스트")
348 )
349 )
350 ];
351 },
352 save: function(props) {
353 var attributes = props.attributes;
354
355 var buttonPadding;
356 switch(attributes.buttonSize) {
357 case "small":
358 buttonPadding = "8px 16px";
359 break;
360 case "large":
361 buttonPadding = "16px 32px";
362 break;
363 case "xlarge":
364 buttonPadding = "20px 40px";
365 break;
366 default: // medium
367 buttonPadding = "12px 24px";
368 }
369
370 var fontSize;
371 switch(attributes.buttonSize) {
372 case "small":
373 fontSize = "13px";
374 break;
375 case "large":
376 fontSize = "18px";
377 break;
378 case "xlarge":
379 fontSize = "22px";
380 break;
381 default: // medium
382 fontSize = "15px";
383 }
384
385 var buttonWidth = "auto";
386 var textAlign = "inherit";
387 if (attributes.buttonWidth === "half") {
388 buttonWidth = "50%";
389 textAlign = "center";
390 } else if (attributes.buttonWidth === "full") {
391 buttonWidth = "100%";
392 textAlign = "center";
393 }
394
395 var containerAlignment = attributes.buttonPosition;
396
397 if (attributes.buttonWidth === "full") {
398 containerAlignment = "center";
399 }
400
401 var animationClass = "presslearn-button presslearn-button-animation-" + attributes.buttonAnimation;
402 if (infiniteAnimationEnabled === "yes" && attributes.buttonAnimation !== "none") {
403 animationClass += " presslearn-button-animation-infinite";
404 }
405
406 return el("div", {
407 className: "presslearn-button-container",
408 style: { textAlign: containerAlignment, margin: "20px 0" }
409 },
410 el("a", {
411 className: animationClass,
412 href: attributes.buttonUrl || "#",
413 ...(attributes.openInNewTab ? { target: "_blank", rel: "noopener noreferrer" } : {}),
414 style: {
415 display: "inline-block",
416 padding: buttonPadding,
417 backgroundColor: attributes.buttonColor,
418 color: attributes.buttonTextColor,
419 textDecoration: "none",
420 borderRadius: "4px",
421 fontWeight: "bold",
422 fontSize: fontSize,
423 width: buttonWidth,
424 textAlign: textAlign,
425 boxSizing: "border-box",
426 transition: "all 0.3s ease-in-out"
427 },
428 "data-hover-color": attributes.buttonHoverColor || attributes.buttonColor
429 }, attributes.buttonText || "버튼 �
430 �스트")
431 );
432 }
433 });
434 })(
435 window.wp.blocks,
436 window.wp.element,
437 window.wp.components,
438 window.wp.blockEditor
439 );
440 ');
441
442 register_block_type('presslearn/quick-button', array(
443 'editor_script' => 'presslearn-quick-button-block',
444 'render_callback' => 'presslearn_render_quick_button',
445 'attributes' => array(
446 'buttonText' => array(
447 'type' => 'string',
448 'default' => '버튼 �
449 �스트'
450 ),
451 'buttonUrl' => array(
452 'type' => 'string',
453 'default' => '#'
454 ),
455 'buttonColor' => array(
456 'type' => 'string',
457 'default' => '#2196F3'
458 ),
459 'buttonTextColor' => array(
460 'type' => 'string',
461 'default' => '#ffffff'
462 ),
463 'buttonHoverColor' => array(
464 'type' => 'string',
465 'default' => ''
466 ),
467 'buttonPosition' => array(
468 'type' => 'string',
469 'default' => 'center'
470 ),
471 'buttonSize' => array(
472 'type' => 'string',
473 'default' => 'medium'
474 ),
475 'buttonWidth' => array(
476 'type' => 'string',
477 'default' => 'default'
478 ),
479 'openInNewTab' => array(
480 'type' => 'boolean',
481 'default' => false
482 ),
483 'buttonAnimation' => array(
484 'type' => 'string',
485 'default' => 'none'
486 ),
487 'infiniteAnimation' => array(
488 'type' => 'string',
489 'default' => 'yes'
490 )
491 )
492 ));
493
494 add_filter('block_categories_all', function($categories) {
495 return array_merge(
496 $categories,
497 array(
498 array(
499 'slug' => 'presslearn',
500 'title' => 'PressLearn',
501 'icon' => null,
502 ),
503 )
504 );
505 });
506 }
507 add_action('init', 'presslearn_register_quick_button_block');
508
509 function presslearn_render_quick_button($attributes, $content) {
510 $attributes = wp_parse_args($attributes, array(
511 'buttonText' => '버튼 �
512 �스트',
513 'buttonUrl' => '#',
514 'buttonColor' => '#2196F3',
515 'buttonTextColor' => '#ffffff',
516 'buttonHoverColor' => '',
517 'buttonPosition' => 'center',
518 'buttonSize' => 'medium',
519 'buttonWidth' => 'default',
520 'openInNewTab' => false,
521 'buttonAnimation' => 'none',
522 'infiniteAnimation' => 'yes'
523 ));
524
525 $button_padding = '12px 24px';
526 switch ($attributes['buttonSize']) {
527 case 'small':
528 $button_padding = '8px 16px';
529 break;
530 case 'large':
531 $button_padding = '16px 32px';
532 break;
533 case 'xlarge':
534 $button_padding = '20px 40px';
535 break;
536 }
537
538 $font_size = '15px';
539 switch ($attributes['buttonSize']) {
540 case 'small':
541 $font_size = '13px';
542 break;
543 case 'large':
544 $font_size = '18px';
545 break;
546 case 'xlarge':
547 $font_size = '22px';
548 break;
549 }
550
551 $button_width = 'auto';
552 $text_align = 'inherit';
553 if ($attributes['buttonWidth'] === 'half') {
554 $button_width = '50%';
555 $text_align = 'center';
556 } else if ($attributes['buttonWidth'] === 'full') {
557 $button_width = '100%';
558 $text_align = 'center';
559 }
560
561 $container_alignment = $attributes['buttonPosition'];
562 if ($attributes['buttonWidth'] === 'full') {
563 $container_alignment = 'center';
564 }
565
566 $animation_class = 'presslearn-button presslearn-button-animation-' . $attributes['buttonAnimation'];
567 $button_transition_enabled = get_option('presslearn_button_transition_enabled', 'no');
568 if ($button_transition_enabled === 'yes' && $attributes['buttonAnimation'] !== 'none') {
569 $animation_class .= ' presslearn-button-animation-infinite';
570 }
571
572 $target_attr = $attributes['openInNewTab'] ? ' target="_blank"' : '';
573 $rel_attr = $attributes['openInNewTab'] ? ' rel="noopener noreferrer"' : '';
574
575 $output = '<div class="presslearn-button-container" style="text-align:' . esc_attr($container_alignment) . ';margin:20px 0">';
576 $output .= '<a class="' . esc_attr($animation_class) . '" href="' . esc_url($attributes['buttonUrl']) . '"' . $target_attr . $rel_attr;
577 $output .= ' style="display:inline-block;padding:' . esc_attr($button_padding) . ';background-color:' . esc_attr($attributes['buttonColor']) . ';';
578 $output .= 'color:' . esc_attr($attributes['buttonTextColor']) . ';text-decoration:none;border-radius:4px;font-weight:bold;';
579 $output .= 'font-size:' . esc_attr($font_size) . ';width:' . esc_attr($button_width) . ';text-align:' . esc_attr($text_align) . ';';
580 $output .= 'box-sizing:border-box;transition:all 0.3s ease-in-out" data-hover-color="' . esc_attr($attributes['buttonHoverColor'] ?: $attributes['buttonColor']) . '">';
581 $output .= esc_html($attributes['buttonText'] ?: '버튼 �
582 �스트') . '</a>';
583 $output .= '</div>';
584
585 return $output;
586 }
587
588 function presslearn_quick_button_admin_styles() {
589 if (!presslearn_is_plugin_active_for_buttons()) {
590 return;
591 }
592
593 $quick_button_enabled = get_option('presslearn_quick_button_enabled', 'no');
594 if ($quick_button_enabled !== 'yes') {
595 return;
596 }
597
598 wp_register_style('presslearn-button-admin-styles', false);
599 wp_enqueue_style('presslearn-button-admin-styles');
600
601 $admin_styles = '
602 .presslearn-button-block-editor {
603 padding: 20px;
604 background: #f5f5f5;
605 border-radius: 4px;
606 margin-bottom: 10px;
607 }
608
609 .editor-styles-wrapper .presslearn-button:focus,
610 .editor-styles-wrapper .presslearn-button:hover {
611 color: #fff !important;
612 opacity: 0.9;
613 }
614
615 .block-editor-block-inspector .components-base-control .components-text-control__input,
616 .block-editor-block-inspector .components-base-control .components-select-control__input {
617 width: 100% !important;
618 box-sizing: border-box !important;
619 }
620
621 .components-panel__body .components-base-control {
622 width: 100%;
623 }
624
625 .presslearn-button-animation-pulse {
626 animation: plButtonPulse 2s ease-in-out;
627 }
628 .presslearn-button-animation-zoom {
629 animation: plButtonZoom 2s ease-in-out;
630 }
631 .presslearn-button-animation-fade {
632 animation: plButtonFade 2s ease-in-out;
633 }
634 .presslearn-button-animation-shake {
635 animation: plButtonShake 2s ease-in-out;
636 }
637
638 .presslearn-button-animation-infinite {
639 animation-iteration-count: infinite !important;
640 }
641
642 @keyframes plButtonPulse {
643 0% { transform: scale(1); }
644 50% { transform: scale(1.05); }
645 100% { transform: scale(1); }
646 }
647
648 @keyframes plButtonZoom {
649 0% { transform: scale(1); }
650 50% { transform: scale(1.1); }
651 100% { transform: scale(1); }
652 }
653
654 @keyframes plButtonFade {
655 0% { opacity: 1; }
656 50% { opacity: 0.7; }
657 100% { opacity: 1; }
658 }
659
660 @keyframes plButtonShake {
661 0%, 100% { transform: translateX(0); }
662 10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
663 20%, 40%, 60%, 80% { transform: translateX(5px); }
664 }
665 ';
666
667 wp_add_inline_style('presslearn-button-admin-styles', $admin_styles);
668 }
669 add_action('admin_enqueue_scripts', 'presslearn_quick_button_admin_styles');
670
671 function presslearn_quick_button_frontend_styles() {
672 if (!presslearn_is_plugin_active_for_buttons()) {
673 return;
674 }
675
676 $quick_button_enabled = get_option('presslearn_quick_button_enabled', 'no');
677 if ($quick_button_enabled !== 'yes') {
678 return;
679 }
680
681 wp_register_style('presslearn-button-frontend-styles', false);
682 wp_enqueue_style('presslearn-button-frontend-styles');
683
684 $frontend_styles = '
685 .presslearn-button-animation-pulse {
686 animation: plButtonPulse 2s ease-in-out;
687 }
688 .presslearn-button-animation-zoom {
689 animation: plButtonZoom 2s ease-in-out;
690 }
691 .presslearn-button-animation-fade {
692 animation: plButtonFade 2s ease-in-out;
693 }
694 .presslearn-button-animation-shake {
695 animation: plButtonShake 2s ease-in-out;
696 }
697
698 .presslearn-button-animation-infinite {
699 animation-iteration-count: infinite !important;
700 }
701
702 @keyframes plButtonPulse {
703 0% { transform: scale(1); }
704 50% { transform: scale(1.05); }
705 100% { transform: scale(1); }
706 }
707
708 @keyframes plButtonZoom {
709 0% { transform: scale(1); }
710 50% { transform: scale(1.1); }
711 100% { transform: scale(1); }
712 }
713
714 @keyframes plButtonFade {
715 0% { opacity: 1; }
716 50% { opacity: 0.7; }
717 100% { opacity: 1; }
718 }
719
720 @keyframes plButtonShake {
721 0%, 100% { transform: translateX(0); }
722 10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
723 20%, 40%, 60%, 80% { transform: translateX(5px); }
724 }
725
726 .presslearn-button:hover {
727 opacity: 0.9;
728 }
729 ';
730
731 wp_add_inline_style('presslearn-button-frontend-styles', $frontend_styles);
732 }
733 add_action('wp_enqueue_scripts', 'presslearn_quick_button_frontend_styles');
734