| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
function presslearn_is_plugin_active_for_social_share() { |
| 7 |
return get_option('presslearn_social_share_enabled', 'no') === 'yes'; |
| 8 |
} |
| 9 |
|
| 10 |
/** |
| 11 |
* Social Share admin styles |
| 12 |
*/ |
| 13 |
function presslearn_social_share_admin_styles() { |
| 14 |
if (!is_admin()) { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
$screen = get_current_screen(); |
| 19 |
if (!$screen || strpos($screen->id, 'presslearn-social-share') === false) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
wp_register_style( |
| 24 |
'presslearn-social-share-admin-css', |
| 25 |
false, |
| 26 |
array(), |
| 27 |
PRESSLEARN_PLUGIN_VERSION |
| 28 |
); |
| 29 |
wp_enqueue_style('presslearn-social-share-admin-css'); |
| 30 |
|
| 31 |
$social_share_admin_css = " |
| 32 |
.social-share-options { |
| 33 |
display: flex; |
| 34 |
flex-wrap: wrap; |
| 35 |
} |
| 36 |
|
| 37 |
.social-share-button { |
| 38 |
display: inline-block; |
| 39 |
margin: 0; |
| 40 |
} |
| 41 |
|
| 42 |
.social-share-button input[type='checkbox'] { |
| 43 |
display: none; |
| 44 |
} |
| 45 |
|
| 46 |
.social-btn { |
| 47 |
display: inline-block; |
| 48 |
padding: 8px 16px; |
| 49 |
background-color: #f8f9fa; |
| 50 |
border: 1px solid #b5bfc9; |
| 51 |
border-radius: 5px; |
| 52 |
color: #333; |
| 53 |
font-size: 14px; |
| 54 |
cursor: pointer; |
| 55 |
transition: all 0.3s ease; |
| 56 |
} |
| 57 |
|
| 58 |
.social-share-button input[type='checkbox']:checked + .social-btn { |
| 59 |
background-color: #2196F3; |
| 60 |
color: white; |
| 61 |
border-color: #2196F3; |
| 62 |
} |
| 63 |
|
| 64 |
.social-share-button input[type='checkbox']:disabled + .social-btn { |
| 65 |
opacity: 0.3; |
| 66 |
cursor: not-allowed; |
| 67 |
} |
| 68 |
|
| 69 |
#social-share-shortcode { |
| 70 |
resize: none; |
| 71 |
font-family: monospace; |
| 72 |
background-color: #f9f9f9; |
| 73 |
} |
| 74 |
"; |
| 75 |
|
| 76 |
wp_add_inline_style('presslearn-social-share-admin-css', $social_share_admin_css); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Social Share admin scripts |
| 81 |
*/ |
| 82 |
function presslearn_social_share_admin_scripts() { |
| 83 |
if (!is_admin()) { |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
$screen = get_current_screen(); |
| 88 |
if (!$screen || strpos($screen->id, 'presslearn-social-share') === false) { |
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
wp_register_script( |
| 93 |
'presslearn-social-share-kakao-js', |
| 94 |
false, |
| 95 |
array('jquery'), |
| 96 |
PRESSLEARN_PLUGIN_VERSION, |
| 97 |
true |
| 98 |
); |
| 99 |
wp_enqueue_script('presslearn-social-share-kakao-js'); |
| 100 |
|
| 101 |
$kakao_js = " |
| 102 |
document.addEventListener('DOMContentLoaded', function() { |
| 103 |
const kakaoApiKeyInput = document.getElementById('kakao-api-key'); |
| 104 |
const kakaoCheckbox = document.getElementById('kakaotalk-option'); |
| 105 |
const kakaoLabel = document.getElementById('kakaotalk-option-label'); |
| 106 |
|
| 107 |
if (kakaoApiKeyInput && kakaoCheckbox && kakaoLabel) { |
| 108 |
function updateKakaoOption() { |
| 109 |
const apiKey = kakaoApiKeyInput.value.trim(); |
| 110 |
|
| 111 |
if (apiKey === '') { |
| 112 |
kakaoCheckbox.disabled = true; |
| 113 |
kakaoCheckbox.checked = false; |
| 114 |
kakaoLabel.style.opacity = '0.3'; |
| 115 |
kakaoLabel.style.cursor = 'not-allowed'; |
| 116 |
} else { |
| 117 |
kakaoCheckbox.disabled = false; |
| 118 |
kakaoLabel.style.opacity = '1'; |
| 119 |
kakaoLabel.style.cursor = 'pointer'; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
updateKakaoOption(); |
| 124 |
|
| 125 |
kakaoApiKeyInput.addEventListener('input', updateKakaoOption); |
| 126 |
} |
| 127 |
}); |
| 128 |
"; |
| 129 |
|
| 130 |
wp_add_inline_script('presslearn-social-share-kakao-js', $kakao_js); |
| 131 |
|
| 132 |
wp_register_script( |
| 133 |
'presslearn-social-share-style-js', |
| 134 |
false, |
| 135 |
array('jquery'), |
| 136 |
PRESSLEARN_PLUGIN_VERSION, |
| 137 |
true |
| 138 |
); |
| 139 |
wp_enqueue_script('presslearn-social-share-style-js'); |
| 140 |
|
| 141 |
$style_js = " |
| 142 |
document.addEventListener('DOMContentLoaded', function() { |
| 143 |
const styleSelect = document.getElementById('social-share-style'); |
| 144 |
const alignmentSelect = document.getElementById('social-share-alignment'); |
| 145 |
|
| 146 |
if (styleSelect && alignmentSelect) { |
| 147 |
function toggleFullWidthOption() { |
| 148 |
const style = styleSelect.value; |
| 149 |
const fullOption = alignmentSelect.querySelector('option[value=\"full\"]'); |
| 150 |
|
| 151 |
if (style === 'default') { |
| 152 |
fullOption.disabled = true; |
| 153 |
fullOption.style.display = 'none'; |
| 154 |
|
| 155 |
if (alignmentSelect.value === 'full') { |
| 156 |
alignmentSelect.value = 'left'; |
| 157 |
} |
| 158 |
} else { |
| 159 |
fullOption.disabled = false; |
| 160 |
fullOption.style.display = 'block'; |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
toggleFullWidthOption(); |
| 165 |
styleSelect.addEventListener('change', toggleFullWidthOption); |
| 166 |
} |
| 167 |
}); |
| 168 |
"; |
| 169 |
|
| 170 |
wp_add_inline_script('presslearn-social-share-style-js', $style_js); |
| 171 |
|
| 172 |
wp_register_script( |
| 173 |
'presslearn-social-share-clipboard-js', |
| 174 |
false, |
| 175 |
array(), |
| 176 |
PRESSLEARN_PLUGIN_VERSION, |
| 177 |
true |
| 178 |
); |
| 179 |
wp_enqueue_script('presslearn-social-share-clipboard-js'); |
| 180 |
|
| 181 |
$clipboard_js = " |
| 182 |
document.addEventListener('DOMContentLoaded', function() { |
| 183 |
const copyButton = document.getElementById('copy-social-share-shortcode'); |
| 184 |
if (copyButton) { |
| 185 |
copyButton.addEventListener('click', function() { |
| 186 |
copyToClipboard('#social-share-shortcode'); |
| 187 |
}); |
| 188 |
} |
| 189 |
}); |
| 190 |
|
| 191 |
function copyToClipboard(element) { |
| 192 |
const targetElement = document.querySelector(element); |
| 193 |
if (targetElement) { |
| 194 |
const tempInput = document.createElement('input'); |
| 195 |
document.body.appendChild(tempInput); |
| 196 |
tempInput.value = targetElement.value; |
| 197 |
tempInput.select(); |
| 198 |
document.execCommand('copy'); |
| 199 |
document.body.removeChild(tempInput); |
| 200 |
alert('숏코드가 클립보드에 복사되었습니다!'); |
| 201 |
} |
| 202 |
} |
| 203 |
"; |
| 204 |
|
| 205 |
wp_add_inline_script('presslearn-social-share-clipboard-js', $clipboard_js); |
| 206 |
} |
| 207 |
|
| 208 |
/** |
| 209 |
* Frontend Social Share styles and scripts |
| 210 |
*/ |
| 211 |
function presslearn_social_share_frontend_assets() { |
| 212 |
if (is_admin() || !presslearn_is_plugin_active_for_social_share()) { |
| 213 |
return; |
| 214 |
} |
| 215 |
|
| 216 |
wp_register_style('presslearn-social-share-style', false); |
| 217 |
wp_enqueue_style('presslearn-social-share-style'); |
| 218 |
|
| 219 |
$custom_css = " |
| 220 |
.presslearn-social-share { |
| 221 |
display: flex; |
| 222 |
flex-wrap: wrap; |
| 223 |
gap: 8px; |
| 224 |
margin: 30px 0; |
| 225 |
} |
| 226 |
|
| 227 |
.presslearn-social-share.full-width { |
| 228 |
justify-content: space-between; |
| 229 |
width: 100%; |
| 230 |
} |
| 231 |
|
| 232 |
.presslearn-social-share.full-width .presslearn-social-share-button { |
| 233 |
flex: 1; |
| 234 |
width: 100%; |
| 235 |
text-align: center; |
| 236 |
justify-content: center; |
| 237 |
} |
| 238 |
|
| 239 |
.presslearn-social-share.inline { |
| 240 |
display: inline-flex; |
| 241 |
margin: 0 10px; |
| 242 |
vertical-align: middle; |
| 243 |
} |
| 244 |
|
| 245 |
.presslearn-social-share-button { |
| 246 |
display: inline-flex; |
| 247 |
align-items: center; |
| 248 |
justify-content: center; |
| 249 |
padding: 8px 16px; |
| 250 |
background-color: #f8f9fa; |
| 251 |
border: 1px solid #b5bfc9; |
| 252 |
border-radius: 10px; |
| 253 |
color: #333; |
| 254 |
font-size: 16px; |
| 255 |
font-weight: 500; |
| 256 |
text-decoration: none; |
| 257 |
cursor: pointer; |
| 258 |
transition: all 0.3s ease; |
| 259 |
gap: 6px; |
| 260 |
} |
| 261 |
|
| 262 |
.presslearn-social-share-button:hover { |
| 263 |
background-color: #e9e9e9; |
| 264 |
color: #FFF; |
| 265 |
} |
| 266 |
|
| 267 |
.presslearn-facebook { |
| 268 |
background-color: #1877f2; |
| 269 |
color: white !important; |
| 270 |
border-color: #1877f2; |
| 271 |
} |
| 272 |
|
| 273 |
.presslearn-facebook:hover { |
| 274 |
background-color: #166fe5; |
| 275 |
border-color: #166fe5; |
| 276 |
} |
| 277 |
|
| 278 |
.presslearn-twitter { |
| 279 |
background-color: #000000; |
| 280 |
color: white !important; |
| 281 |
border-color: #000000; |
| 282 |
} |
| 283 |
|
| 284 |
.presslearn-twitter:hover { |
| 285 |
background-color: #333333; |
| 286 |
border-color: #333333; |
| 287 |
} |
| 288 |
|
| 289 |
.presslearn-kakaotalk { |
| 290 |
background-color: #fee500; |
| 291 |
color: #000 !important; |
| 292 |
border-color: #fee500; |
| 293 |
} |
| 294 |
|
| 295 |
.presslearn-kakaotalk:hover { |
| 296 |
background-color: #f4dc00; |
| 297 |
border-color: #f4dc00; |
| 298 |
} |
| 299 |
|
| 300 |
.presslearn-kakaotalk:hover span { |
| 301 |
color: #000 !important; |
| 302 |
} |
| 303 |
|
| 304 |
.presslearn-naver { |
| 305 |
background-color: #03c75a; |
| 306 |
color: white !important; |
| 307 |
border-color: #03c75a; |
| 308 |
} |
| 309 |
|
| 310 |
.presslearn-naver:hover { |
| 311 |
background-color: #02b350; |
| 312 |
border-color: #02b350; |
| 313 |
} |
| 314 |
|
| 315 |
.presslearn-band { |
| 316 |
background-color: #00c73c; |
| 317 |
color: white !important; |
| 318 |
border-color: #00c73c; |
| 319 |
} |
| 320 |
|
| 321 |
.presslearn-band:hover { |
| 322 |
background-color: #00b636; |
| 323 |
border-color: #00b636; |
| 324 |
} |
| 325 |
|
| 326 |
.presslearn-line { |
| 327 |
background-color: #06c755; |
| 328 |
color: white !important; |
| 329 |
border-color: #06c755; |
| 330 |
} |
| 331 |
|
| 332 |
.presslearn-line:hover { |
| 333 |
background-color: #05b64c; |
| 334 |
border-color: #05b64c; |
| 335 |
} |
| 336 |
|
| 337 |
.presslearn-social-share-icon { |
| 338 |
width: 16px; |
| 339 |
height: 16px; |
| 340 |
display: inline-block; |
| 341 |
} |
| 342 |
|
| 343 |
.presslearn-social-share-icon img { |
| 344 |
width: 100%; |
| 345 |
} |
| 346 |
|
| 347 |
.presslearn-share-popup-trigger { |
| 348 |
display: inline-flex; |
| 349 |
align-items: center; |
| 350 |
justify-content: center; |
| 351 |
padding: 8px 16px; |
| 352 |
background-color: #f8f9fa; |
| 353 |
border: 1px solid #b5bfc9; |
| 354 |
border-radius: 10px; |
| 355 |
color: #333; |
| 356 |
font-size: 16px; |
| 357 |
font-weight: 500; |
| 358 |
text-decoration: none; |
| 359 |
cursor: pointer; |
| 360 |
transition: all 0.3s ease; |
| 361 |
gap: 10px; |
| 362 |
} |
| 363 |
|
| 364 |
.presslearn-share-popup-trigger:hover { |
| 365 |
background-color: #e9e9e9; |
| 366 |
} |
| 367 |
|
| 368 |
.presslearn-share-popup { |
| 369 |
display: none; |
| 370 |
position: fixed; |
| 371 |
top: 0; |
| 372 |
left: 0; |
| 373 |
right: 0; |
| 374 |
bottom: 0; |
| 375 |
background-color: rgba(0, 0, 0, 0.5); |
| 376 |
z-index: 9999; |
| 377 |
justify-content: center; |
| 378 |
align-items: center; |
| 379 |
} |
| 380 |
|
| 381 |
.presslearn-share-popup-content { |
| 382 |
background-color: #fff; |
| 383 |
border-radius: 10px; |
| 384 |
padding: 20px; |
| 385 |
width: 100%; |
| 386 |
max-width: 400px; |
| 387 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); |
| 388 |
} |
| 389 |
|
| 390 |
.presslearn-share-popup-header { |
| 391 |
display: flex; |
| 392 |
justify-content: space-between; |
| 393 |
align-items: center; |
| 394 |
margin-bottom: 15px; |
| 395 |
padding-bottom: 10px; |
| 396 |
border-bottom: 1px solid #eee; |
| 397 |
} |
| 398 |
|
| 399 |
.presslearn-share-popup-title { |
| 400 |
font-size: 16px; |
| 401 |
font-weight: bold; |
| 402 |
margin: 0; |
| 403 |
} |
| 404 |
|
| 405 |
.presslearn-share-popup-close { |
| 406 |
background: none !important; |
| 407 |
border: none !important; |
| 408 |
font-size: 20px !important; |
| 409 |
cursor: pointer !important; |
| 410 |
padding: 0 !important; |
| 411 |
color: #666 !important; |
| 412 |
} |
| 413 |
|
| 414 |
.presslearn-share-popup-buttons { |
| 415 |
display: grid; |
| 416 |
grid-template-columns: repeat(3, 1fr); |
| 417 |
gap: 10px; |
| 418 |
} |
| 419 |
|
| 420 |
.presslearn-share-popup .presslearn-social-share-button { |
| 421 |
display: flex; |
| 422 |
flex-direction: column; |
| 423 |
height: auto; |
| 424 |
padding: 10px; |
| 425 |
border-radius: 8px; |
| 426 |
text-align: center; |
| 427 |
} |
| 428 |
|
| 429 |
.presslearn-share-popup .presslearn-social-share-icon { |
| 430 |
width: 24px; |
| 431 |
height: 24px; |
| 432 |
} |
| 433 |
.full-width a { |
| 434 |
width: 100%; |
| 435 |
} |
| 436 |
|
| 437 |
@media screen and (max-width: 782px) { |
| 438 |
.presslearn-share-popup-content { |
| 439 |
width: 100%; |
| 440 |
max-width: 90%; |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
a.presslearn-social-share-button { |
| 445 |
text-decoration: none !important; |
| 446 |
} |
| 447 |
"; |
| 448 |
|
| 449 |
wp_add_inline_style('presslearn-social-share-style', $custom_css); |
| 450 |
|
| 451 |
wp_register_script('presslearn-social-share-script', false, array(), PRESSLEARN_PLUGIN_VERSION, true); |
| 452 |
wp_enqueue_script('presslearn-social-share-script'); |
| 453 |
|
| 454 |
$script = " |
| 455 |
document.addEventListener('DOMContentLoaded', function() { |
| 456 |
const shareButtons = document.querySelectorAll('.presslearn-social-share-button'); |
| 457 |
|
| 458 |
shareButtons.forEach(button => { |
| 459 |
button.addEventListener('click', function(e) { |
| 460 |
const social = this.getAttribute('data-social'); |
| 461 |
const url = this.getAttribute('data-url'); |
| 462 |
const title = this.getAttribute('data-title'); |
| 463 |
|
| 464 |
if (social === 'copy') { |
| 465 |
e.preventDefault(); |
| 466 |
navigator.clipboard.writeText(url).then(function() { |
| 467 |
alert('링크가 복사되었습니다.'); |
| 468 |
}).catch(function(err) { |
| 469 |
console.error('복사 실패:', err); |
| 470 |
}); |
| 471 |
return; |
| 472 |
} |
| 473 |
|
| 474 |
if (social === 'kakaotalk') { |
| 475 |
e.preventDefault(); |
| 476 |
return; |
| 477 |
} |
| 478 |
|
| 479 |
const width = 570; |
| 480 |
const height = 450; |
| 481 |
const left = (screen.width - width) / 2; |
| 482 |
const top = (screen.height - height) / 2; |
| 483 |
const options = 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left; |
| 484 |
|
| 485 |
window.open(this.getAttribute('href'), social, options); |
| 486 |
|
| 487 |
e.preventDefault(); |
| 488 |
}); |
| 489 |
}); |
| 490 |
|
| 491 |
const popupTriggers = document.querySelectorAll('.presslearn-share-popup-trigger'); |
| 492 |
popupTriggers.forEach(trigger => { |
| 493 |
trigger.addEventListener('click', function(e) { |
| 494 |
e.preventDefault(); |
| 495 |
const popup = document.querySelector('.presslearn-share-popup'); |
| 496 |
if (popup) { |
| 497 |
popup.style.display = 'flex'; |
| 498 |
popup.style.opacity = '0'; |
| 499 |
popup.style.transition = 'opacity 0.2s'; |
| 500 |
setTimeout(() => { |
| 501 |
popup.style.opacity = '1'; |
| 502 |
}, 10); |
| 503 |
} |
| 504 |
}); |
| 505 |
}); |
| 506 |
|
| 507 |
const closeButtons = document.querySelectorAll('.presslearn-share-popup-close'); |
| 508 |
closeButtons.forEach(button => { |
| 509 |
button.addEventListener('click', function() { |
| 510 |
const popup = document.querySelector('.presslearn-share-popup'); |
| 511 |
if (popup) { |
| 512 |
popup.style.opacity = '0'; |
| 513 |
setTimeout(() => { |
| 514 |
popup.style.display = 'none'; |
| 515 |
}, 200); |
| 516 |
} |
| 517 |
}); |
| 518 |
}); |
| 519 |
|
| 520 |
document.addEventListener('click', function(e) { |
| 521 |
const popup = document.querySelector('.presslearn-share-popup'); |
| 522 |
if (popup && popup.style.display === 'flex') { |
| 523 |
if (!e.target.closest('.presslearn-share-popup-content') && |
| 524 |
!e.target.closest('.presslearn-share-popup-trigger')) { |
| 525 |
popup.style.opacity = '0'; |
| 526 |
setTimeout(() => { |
| 527 |
popup.style.display = 'none'; |
| 528 |
}, 200); |
| 529 |
} |
| 530 |
} |
| 531 |
}); |
| 532 |
}); |
| 533 |
"; |
| 534 |
|
| 535 |
wp_add_inline_script('presslearn-social-share-script', $script); |
| 536 |
} |
| 537 |
|
| 538 |
function presslearn_init_social_share() { |
| 539 |
$social_share_enabled = get_option('presslearn_social_share_enabled', 'no'); |
| 540 |
|
| 541 |
if ($social_share_enabled !== 'yes') { |
| 542 |
return; |
| 543 |
} |
| 544 |
|
| 545 |
add_shortcode('presslearn_social_share', 'presslearn_social_share_shortcode'); |
| 546 |
|
| 547 |
add_action('wp_enqueue_scripts', 'presslearn_social_share_frontend_assets'); |
| 548 |
} |
| 549 |
add_action('init', 'presslearn_init_social_share'); |
| 550 |
|
| 551 |
function presslearn_social_share_shortcode($atts) { |
| 552 |
$social_share_enabled = get_option('presslearn_social_share_enabled', 'no'); |
| 553 |
|
| 554 |
if ($social_share_enabled !== 'yes') { |
| 555 |
return ''; |
| 556 |
} |
| 557 |
|
| 558 |
$atts = shortcode_atts(array( |
| 559 |
'title' => '', |
| 560 |
), $atts, 'presslearn_social_share'); |
| 561 |
|
| 562 |
$title = !empty($atts['title']) ? $atts['title'] : get_the_title(); |
| 563 |
$url = get_permalink(); |
| 564 |
$align = get_option('presslearn_social_share_alignment', 'left'); |
| 565 |
|
| 566 |
$social_share_options = get_option('presslearn_social_share_options', array('facebook', 'twitter', 'kakaotalk', 'naver', 'band', 'line')); |
| 567 |
$social_share_style = get_option('presslearn_social_share_style', 'default'); |
| 568 |
|
| 569 |
if (empty($social_share_options)) { |
| 570 |
return ''; |
| 571 |
} |
| 572 |
|
| 573 |
$alignment_data = presslearn_get_share_alignment($align, $social_share_style); |
| 574 |
$alignment_style = $alignment_data['style']; |
| 575 |
$alignment_class = $alignment_data['class']; |
| 576 |
|
| 577 |
if ($social_share_style === 'popup') { |
| 578 |
$html = '<div class="presslearn-social-share ' . esc_attr($alignment_class) . '" style="' . esc_attr($alignment_style) . '">'; |
| 579 |
$html .= '<a href="javascript:void(0)" class="presslearn-share-popup-trigger"> |
| 580 |
<span class="presslearn-social-share-icon"> |
| 581 |
<img src="' . esc_url(plugins_url('/assets/images/share.png', dirname(__FILE__))) . '" alt="Share" width="16" height="16"> |
| 582 |
</span> |
| 583 |
<span>공유하기</span> |
| 584 |
</a>'; |
| 585 |
|
| 586 |
$html .= '<div class="presslearn-share-popup"> |
| 587 |
<div class="presslearn-share-popup-content"> |
| 588 |
<div class="presslearn-share-popup-header"> |
| 589 |
<h4 class="presslearn-share-popup-title">공유하기</h4> |
| 590 |
<button type="button" class="presslearn-share-popup-close">×</button> |
| 591 |
</div> |
| 592 |
<div class="presslearn-share-popup-buttons">'; |
| 593 |
|
| 594 |
foreach ($social_share_options as $social) { |
| 595 |
switch ($social) { |
| 596 |
case 'facebook': |
| 597 |
$html .= presslearn_facebook_share_button($url, $title); |
| 598 |
break; |
| 599 |
|
| 600 |
case 'twitter': |
| 601 |
$html .= presslearn_twitter_share_button($url, $title); |
| 602 |
break; |
| 603 |
|
| 604 |
case 'kakaotalk': |
| 605 |
$html .= presslearn_kakaotalk_share_button($url, $title); |
| 606 |
break; |
| 607 |
|
| 608 |
case 'naver': |
| 609 |
$html .= presslearn_naver_share_button($url, $title); |
| 610 |
break; |
| 611 |
|
| 612 |
case 'band': |
| 613 |
$html .= presslearn_band_share_button($url, $title); |
| 614 |
break; |
| 615 |
|
| 616 |
case 'line': |
| 617 |
$html .= presslearn_line_share_button($url, $title); |
| 618 |
break; |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
$html .= '<a href="javascript:void(0)" class="presslearn-social-share-button" data-social="copy" data-url="' . esc_url($url) . '" data-title="' . esc_attr($title) . '"> |
| 623 |
<span class="presslearn-social-share-icon"> |
| 624 |
<img src="' . esc_url(plugins_url('/assets/images/copy.png', dirname(__FILE__))) . '" alt="Copy link" width="16" height="16"> |
| 625 |
</span> |
| 626 |
<span style="color: #000 !important;">링크 복사</span> |
| 627 |
</a>'; |
| 628 |
|
| 629 |
$html .= '</div></div></div></div>'; |
| 630 |
|
| 631 |
return $html; |
| 632 |
} |
| 633 |
|
| 634 |
$html = '<div class="presslearn-social-share ' . esc_attr($alignment_class) . '" style="' . esc_attr($alignment_style) . '">'; |
| 635 |
|
| 636 |
foreach ($social_share_options as $social) { |
| 637 |
switch ($social) { |
| 638 |
case 'facebook': |
| 639 |
$html .= presslearn_facebook_share_button($url, $title); |
| 640 |
break; |
| 641 |
|
| 642 |
case 'twitter': |
| 643 |
$html .= presslearn_twitter_share_button($url, $title); |
| 644 |
break; |
| 645 |
|
| 646 |
case 'kakaotalk': |
| 647 |
$html .= presslearn_kakaotalk_share_button($url, $title); |
| 648 |
break; |
| 649 |
|
| 650 |
case 'naver': |
| 651 |
$html .= presslearn_naver_share_button($url, $title); |
| 652 |
break; |
| 653 |
|
| 654 |
case 'band': |
| 655 |
$html .= presslearn_band_share_button($url, $title); |
| 656 |
break; |
| 657 |
|
| 658 |
case 'line': |
| 659 |
$html .= presslearn_line_share_button($url, $title); |
| 660 |
break; |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
$html .= '<a href="javascript:void(0)" class="presslearn-social-share-button" data-social="copy" data-url="' . esc_url($url) . '" data-title="' . esc_attr($title) . '"> |
| 665 |
<span class="presslearn-social-share-icon"> |
| 666 |
<img src="' . esc_url(plugins_url('/assets/images/copy.png', dirname(__FILE__))) . '" alt="Copy link" width="16" height="16"> |
| 667 |
</span> |
| 668 |
<span style="color: #000 !important;">링크 복사</span> |
| 669 |
</a>'; |
| 670 |
|
| 671 |
$html .= '</div>'; |
| 672 |
|
| 673 |
return $html; |
| 674 |
} |
| 675 |
|
| 676 |
function presslearn_get_share_alignment($align, $style = 'default') { |
| 677 |
$style_attr = ''; |
| 678 |
$class = ''; |
| 679 |
|
| 680 |
if ($align === 'full' && $style !== 'popup') { |
| 681 |
$align = 'left'; |
| 682 |
} |
| 683 |
|
| 684 |
switch ($align) { |
| 685 |
case 'center': |
| 686 |
$style_attr = 'justify-content: center;'; |
| 687 |
break; |
| 688 |
case 'right': |
| 689 |
$style_attr = 'justify-content: flex-end;'; |
| 690 |
break; |
| 691 |
case 'full': |
| 692 |
$class = 'full-width'; |
| 693 |
break; |
| 694 |
case 'inline': |
| 695 |
$class = 'inline'; |
| 696 |
break; |
| 697 |
case 'left': |
| 698 |
default: |
| 699 |
$style_attr = 'justify-content: flex-start;'; |
| 700 |
break; |
| 701 |
} |
| 702 |
|
| 703 |
return array( |
| 704 |
'style' => $style_attr, |
| 705 |
'class' => $class |
| 706 |
); |
| 707 |
} |
| 708 |
|
| 709 |
function presslearn_facebook_share_button($url, $title) { |
| 710 |
$share_url = 'https://www.facebook.com/sharer/sharer.php?u=' . urlencode($url); |
| 711 |
$icon_url = plugins_url('/assets/images/facebook.png', dirname(__FILE__)); |
| 712 |
|
| 713 |
return '<a href="' . esc_url($share_url) . '" class="presslearn-social-share-button presslearn-facebook" data-social="facebook" data-url="' . esc_url($url) . '" data-title="' . esc_attr($title) . '" target="_blank" rel="noopener noreferrer"> |
| 714 |
<span class="presslearn-social-share-icon"> |
| 715 |
<img src="' . esc_url($icon_url) . '" alt="Facebook" width="16" height="16"> |
| 716 |
</span> |
| 717 |
<span>페이스북</span> |
| 718 |
</a>'; |
| 719 |
} |
| 720 |
|
| 721 |
function presslearn_twitter_share_button($url, $title) { |
| 722 |
$share_url = 'https://twitter.com/intent/tweet?url=' . urlencode($url) . '&text=' . urlencode($title); |
| 723 |
$icon_url = plugins_url('/assets/images/twitter.png', dirname(__FILE__)); |
| 724 |
|
| 725 |
return '<a href="' . esc_url($share_url) . '" class="presslearn-social-share-button presslearn-twitter" data-social="twitter" data-url="' . esc_url($url) . '" data-title="' . esc_attr($title) . '" target="_blank" rel="noopener noreferrer"> |
| 726 |
<span class="presslearn-social-share-icon"> |
| 727 |
<img src="' . esc_url($icon_url) . '" alt="Twitter" width="16" height="16"> |
| 728 |
</span> |
| 729 |
<span>X</span> |
| 730 |
</a>'; |
| 731 |
} |
| 732 |
|
| 733 |
function presslearn_kakaotalk_share_button($url, $title) { |
| 734 |
if (!wp_script_is('kakao-sdk', 'registered')) { |
| 735 |
wp_register_script('kakao-sdk', PRESSLEARN_PLUGIN_URL . 'assets/js/kakao.min.js', array(), null, true); |
| 736 |
wp_enqueue_script('kakao-sdk'); |
| 737 |
|
| 738 |
$kakao_api_key = get_option('presslearn_kakao_api_key', ''); |
| 739 |
wp_add_inline_script('kakao-sdk', " |
| 740 |
if (typeof Kakao !== 'undefined') { |
| 741 |
Kakao.init('" . esc_js($kakao_api_key) . "'); |
| 742 |
} |
| 743 |
"); |
| 744 |
} |
| 745 |
|
| 746 |
$thumbnail = ''; |
| 747 |
if (is_single() || is_page()) { |
| 748 |
$post_id = get_the_ID(); |
| 749 |
if (has_post_thumbnail($post_id)) { |
| 750 |
$thumbnail = get_the_post_thumbnail_url($post_id, 'large'); |
| 751 |
} |
| 752 |
} |
| 753 |
|
| 754 |
$description = ''; |
| 755 |
if (is_single() || is_page()) { |
| 756 |
$post = get_post(); |
| 757 |
if ($post) { |
| 758 |
$excerpt = $post->post_excerpt; |
| 759 |
if (empty($excerpt)) { |
| 760 |
$excerpt = wp_strip_all_tags(get_the_content()); |
| 761 |
} |
| 762 |
$description = wp_html_excerpt($excerpt, 100, '...'); |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
wp_add_inline_script('presslearn-social-share-script', " |
| 767 |
document.addEventListener('DOMContentLoaded', function() { |
| 768 |
const kakaoButtons = document.querySelectorAll('.presslearn-kakaotalk'); |
| 769 |
kakaoButtons.forEach(button => { |
| 770 |
button.addEventListener('click', function(e) { |
| 771 |
e.preventDefault(); |
| 772 |
|
| 773 |
if (typeof Kakao === 'undefined') { |
| 774 |
alert('카카오톡 공유 기능을 사용할 수 없습니다.'); |
| 775 |
return; |
| 776 |
} |
| 777 |
|
| 778 |
const shareUrl = this.getAttribute('data-url'); |
| 779 |
const shareTitle = this.getAttribute('data-title'); |
| 780 |
const shareImage = '" . esc_js($thumbnail) . "'; |
| 781 |
const shareDesc = '" . esc_js($description) . "'; |
| 782 |
|
| 783 |
Kakao.Share.sendDefault({ |
| 784 |
objectType: 'feed', |
| 785 |
content: { |
| 786 |
title: shareTitle, |
| 787 |
description: shareDesc, |
| 788 |
imageUrl: shareImage || '', |
| 789 |
link: { |
| 790 |
mobileWebUrl: shareUrl, |
| 791 |
webUrl: shareUrl |
| 792 |
} |
| 793 |
}, |
| 794 |
buttons: [ |
| 795 |
{ |
| 796 |
title: '웹으로 보기', |
| 797 |
link: { |
| 798 |
mobileWebUrl: shareUrl, |
| 799 |
webUrl: shareUrl |
| 800 |
} |
| 801 |
} |
| 802 |
] |
| 803 |
}); |
| 804 |
}); |
| 805 |
}); |
| 806 |
}); |
| 807 |
"); |
| 808 |
|
| 809 |
$icon_url = plugins_url('/assets/images/kakao.png', dirname(__FILE__)); |
| 810 |
|
| 811 |
return '<a href="javascript:void(0)" class="presslearn-social-share-button presslearn-kakaotalk" data-social="kakaotalk" data-url="' . esc_url($url) . '" data-title="' . esc_attr($title) . '"> |
| 812 |
<span class="presslearn-social-share-icon"> |
| 813 |
<img src="' . esc_url($icon_url) . '" alt="KakaoTalk" width="16" height="16"> |
| 814 |
</span> |
| 815 |
<span>카카오톡</span> |
| 816 |
</a>'; |
| 817 |
} |
| 818 |
|
| 819 |
function presslearn_naver_share_button($url, $title) { |
| 820 |
$share_url = 'https://share.naver.com/web/shareView?url=' . urlencode($url) . '&title=' . urlencode($title); |
| 821 |
$icon_url = plugins_url('/assets/images/naver.png', dirname(__FILE__)); |
| 822 |
|
| 823 |
return '<a href="' . esc_url($share_url) . '" class="presslearn-social-share-button presslearn-naver" data-social="naver" data-url="' . esc_url($url) . '" data-title="' . esc_attr($title) . '" target="_blank" rel="noopener noreferrer"> |
| 824 |
<span class="presslearn-social-share-icon"> |
| 825 |
<img src="' . esc_url($icon_url) . '" alt="Naver" width="16" height="16"> |
| 826 |
</span> |
| 827 |
<span>네이버</span> |
| 828 |
</a>'; |
| 829 |
} |
| 830 |
|
| 831 |
function presslearn_band_share_button($url, $title) { |
| 832 |
$share_url = 'https://band.us/plugin/share?body=' . urlencode($title) . '%0A' . urlencode($url) . '&route=' . urlencode($url); |
| 833 |
$icon_url = plugins_url('/assets/images/band.png', dirname(__FILE__)); |
| 834 |
|
| 835 |
return '<a href="' . esc_url($share_url) . '" class="presslearn-social-share-button presslearn-band" data-social="band" data-url="' . esc_url($url) . '" data-title="' . esc_attr($title) . '" target="_blank" rel="noopener noreferrer"> |
| 836 |
<span class="presslearn-social-share-icon"> |
| 837 |
<img src="' . esc_url($icon_url) . '" alt="Band" width="16" height="16"> |
| 838 |
</span> |
| 839 |
<span>밴드</span> |
| 840 |
</a>'; |
| 841 |
} |
| 842 |
|
| 843 |
function presslearn_line_share_button($url, $title) { |
| 844 |
$share_url = 'https://social-plugins.line.me/lineit/share?url=' . urlencode($url); |
| 845 |
$icon_url = plugins_url('/assets/images/line.png', dirname(__FILE__)); |
| 846 |
|
| 847 |
return '<a href="' . esc_url($share_url) . '" class="presslearn-social-share-button presslearn-line" data-social="line" data-url="' . esc_url($url) . '" data-title="' . esc_attr($title) . '" target="_blank" rel="noopener noreferrer"> |
| 848 |
<span class="presslearn-social-share-icon"> |
| 849 |
<img src="' . esc_url($icon_url) . '" alt="Line" width="16" height="16"> |
| 850 |
</span> |
| 851 |
<span>라인</span> |
| 852 |
</a>'; |
| 853 |
} |
| 854 |
|
| 855 |
function presslearn_get_social_share_shortcode() { |
| 856 |
return '[presslearn_social_share]'; |
| 857 |
} |
| 858 |
|
| 859 |
add_action('admin_enqueue_scripts', 'presslearn_social_share_admin_styles'); |
| 860 |
add_action('admin_enqueue_scripts', 'presslearn_social_share_admin_scripts'); |