Skip to content

Commit

Permalink
Version bumped to 0.2.0
Browse files Browse the repository at this point in the history
Please read CHANGELOG for details.
  • Loading branch information
chwnam committed Nov 13, 2021
1 parent 63a27e4 commit 1d825c0
Show file tree
Hide file tree
Showing 14 changed files with 532 additions and 46 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
0.2.0
-----
2021-11-13

- Add clipboard share feature.
- Add 'nss' custom javascript event.
- Add korean localization.
- Concat option, and priority option added.
- JavaScript global variable renamed from 'naranSocialShare' to 'nss'.
- Some template code update.


0.1.0
-----
2021-11-09
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# 나란 소셜 공유 플러그인

워드프레스 포스트를 손쉽게 공유해 주는 플러그인입니다.


## 사용법
여타 플러그인처럼 설치 후 활성화시키면 됩니다.

관리자 > 소셜 공유 메뉴로 이동하여 적절히 설정하면 됩니다.


## 템플릿 변경
플러그인의 `includes/templates/buttons.php`는 플러그인의 기본 소셜 공유 링크(버튼)의
출력을 위한 템플릿입니다. 주석에 쓰여진대로 기본으로 주어지는 PHP 변수를 활용하여
원하는대로 HTML 구조를 찍어내면 됩니다.

이 때 플러그인의 템플릿을 수정하기보다, 템플릿을 오버라이드하세요.

테마 디렉토리에 'nss'라는 디렉토리를 만들고 'buttons.php' 파일을 복사합니다.
즉, `{테마 루트}/nss/buttons.php` 파일을 원하는대로 수정하시면 플러그인보다 테마의 파일을
우선하여 읽어들일 것입니다.
16 changes: 14 additions & 2 deletions assets/js/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
share(type) {
if ('function' === typeof this[type]) {
this[type].call(this, opts.shareParams);
document.dispatchEvent(new CustomEvent('nss', {detail: {type: type, params: opts.shareParams}}));
}
},
facebook(s) {
Expand Down Expand Up @@ -50,6 +51,18 @@
naverBlog(s) {
this.openPopup('https://blog.naver.com/LinkShare.nhn?url=' + encodeURIComponent(s.permalink) + '&title=' + encodeURIComponent(s.title));
},
clipboard(s) {
if (s.permalink && s.permalink.length) {
let input = document.createElement('input');
input.type = 'text';
input.value = s.permalink;
document.body.appendChild(input);
input.select();
input.setSelectionRange(0, s.permalink.length);
document.execCommand('copy');
input.remove();
}
},
openPopup(href) {
const top = (screen.availHeight - opts.height) * 0.5,
left = (screen.availWidth - opts.width) * 0.5,
Expand Down Expand Up @@ -88,6 +101,5 @@
});
});


window.naranSocialShare = sharer;
window.nss = sharer;
})();
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"includes"
]
},
"version": "0.1.0",
"version": "0.2.0",
"require-dev": {
"phpunit/phpunit": "^7"
},
Expand Down
8 changes: 7 additions & 1 deletion core/abstracts/abstract-nss-main-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public function set( string $key, $value ) {
public function init_conditional_modules() {
}

public function load_textdomain() {
load_plugin_textdomain( 'nss', false, wp_basename( dirname( $this->get_main_file() ) ) . '/languages' );
}

/**
* Return root modules
*
Expand All @@ -176,7 +180,9 @@ abstract protected function get_modules(): array;
protected function initialize() {
$this->assign_modules( $this->get_modules() );

$this->add_action( 'wp', 'init_conditional_modules' );
$this
->add_action( 'plugins_loaded', 'load_textdomain' )
->add_action( 'wp', 'init_conditional_modules' );

do_action( 'nss_initialized' );
}
Expand Down
1 change: 1 addition & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function nss_get_available_services(): array {
'telegram' => __( 'Telegram', 'nss' ),
'kakaoTalk' => __( 'KakaoTalk', 'nss' ),
'naverBlog' => __( 'Naver Blog', 'nss' ),
'clipboard' => __( 'Clipboard', 'nss' ),
] );
}
}
Expand Down
145 changes: 112 additions & 33 deletions includes/modules/class-nss-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,41 @@ private function prepre_settings() {
]
);

add_settings_field(
'nss-priority',
__( 'Priority', 'nss' ),
[ $this, 'render_input' ],
'nss',
'nss-general',
[
'id' => "$option_name-priority",
'label_for' => "$option_name-priority",
'name' => "{$option_name}[priority]",
'type' => 'number',
'value' => $setup->get_priority(),
'description' => __( '\'the_content\' filter priority.', 'nss' ),
]
);

add_settings_field(
'nss-concat',
__( 'Concatenation', 'nss' ),
[ $this, 'render_select' ],
'nss',
'nss-general',
[
'id' => "$option_name-concat",
'label_for' => "$option_name-concat",
'name' => "{$option_name}[concat]",
'value' => $setup->get_concat(),
'options' => [
'prepend' => __( 'Prepend', 'nss' ),
'append' => __( 'Append', 'nss' ),
],
'attrs' => [],
]
);

add_settings_section(
'nss-kakao',
__( 'Kakao API', 'nss' ),
Expand Down Expand Up @@ -168,12 +203,46 @@ public function render_checkbox( array $args ) {
esc_html( $args['instruction'] )
);

if ( $args['description'] ) {
$kses = [
'a' => [ 'href' => true, 'target' => true ]
];
echo '<p class="description">' . wp_kses( $args['instruction'], $kses ) . '</p>';
self::render_description( $args['description'] );
}

/**
* Render select widget
*
* @param array $args
*/
public function render_select( array $args ) {
$args = wp_parse_args(
$args,
[
'id' => '',
'name' => '',
'value' => '',
'options' => [],
'attrs' => [],
'description' => '',
]
);

$options = [];
foreach ( $args['options'] as $val => $label ) {
$options[] = sprintf(
'<option value="%s" %s>%s</option>',
esc_attr( $val ),
selected( $val, $args['value'], false ),
esc_html( $label )
);
}

printf(
'<select id="%s" name="%s" %s>%s</select>',
esc_attr( $args['id'] ),
esc_attr( $args['name'] ),
self::format_attrs( (array) $args['attrs'] ),
implode( ' ', $options ),
);

self::render_description( $args['description'] );
}

/**
Expand All @@ -193,23 +262,11 @@ public function render_input( array $args ) {
'class' => 'text',
'value' => '',
'placeholder' => '',
'attrs' => '',
'attrs' => [],
'description' => '',
]
);

if ( ! empty( $args['attrs'] ) ) {
$buffer = [];
foreach ( (array) $args['attrs'] as $key => $value ) {
$key = sanitize_key( $key );
$value = esc_attr( $value );
if ( $key ) {
$buffer[] = "$key=\"$value\"";
}
}
$args['attrs'] = implode( ' ', $buffer );
}

printf(
'<input id="%s" name="%s" type="%s" class="%s" value="%s" placeholder="%s" %s> ',
esc_attr( $args['id'] ),
Expand All @@ -218,15 +275,10 @@ public function render_input( array $args ) {
esc_attr( $args['class'] ),
esc_attr( $args['value'] ),
esc_attr( $args['placeholder'] ),
$args['attrs']
self::format_attrs( (array) $args['attrs'] )
);

if ( $args['description'] ) {
$kses = [
'a' => [ 'href' => true, 'target' => true ]
];
echo '<p class="description">' . wp_kses( $args['instruction'], $kses ) . '</p>';
}
self::render_description( $args['description'] );
}

/**
Expand All @@ -243,15 +295,42 @@ public function render_available_widget( array $args ) {
);

$this
->enqueue_style('nss-admin-settings')
->enqueue_style( 'nss-admin-settings' )
->render(
'admin/available-widget',
[
'option_name' => $args['option_name'],
'available' => $args['available'],
'value' => $args['value'],
]
);
'admin/available-widget',
[
'option_name' => $args['option_name'],
'available' => $args['available'],
'value' => $args['value'],
]
)
;
}

private static function format_attrs( array $attrs ): string {
$buffer = [];

foreach ( $attrs as $key => $value ) {
$key = sanitize_key( $key );
$value = esc_attr( $value );
if ( $key ) {
$buffer[] = "$key=\"$value\"";
}
}

return implode( ' ', $buffer );
}

private static function render_description( string $description ) {
if ( $description ) {
$kses = [
'a' => [
'href' => true,
'target' => true
],
];
echo '<p class="description">' . wp_kses( $description, $kses ) . '</p>';
}
}
}
}
11 changes: 9 additions & 2 deletions includes/modules/class-nss-front.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function initialize() {
)
;

$this->add_filter( 'the_content', 'content' );
$this->add_filter( 'the_content', 'content', nss_setup()->get_priority() );
}
}

Expand All @@ -66,7 +66,14 @@ public function content( string $content ): string {

$buttons = preg_replace( '/>\s+</', '><', $buttons );

return $content . $buttons;
$concat = nss_setup()->get_concat();
if ( 'prepend' === $concat ) {
$content = $buttons . $content;
} elseif ( 'append' === $concat ) {
$content = $content . $buttons;
}

return $content;
}

/**
Expand Down
22 changes: 22 additions & 0 deletions includes/modules/class-nss-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public function get_height(): int {
return (int) $this->get_value( 'height' );
}

public function get_priority(): int {
return (int) $this->get_value( 'priority' );
}

public function get_concat(): string {
return $this->get_value( 'concat' );
}

public function get_kakao_api_key(): string {
return (string) $this->get_value( 'kakao_api_key' );
}
Expand Down Expand Up @@ -67,6 +75,12 @@ public static function get_default_value(): array {
// Popup window height (px).
'height' => 320,

// the_content filter priority.
'priority' => 10,

// concat: prepend, append.
'concat' => 'append',

// Kakao API Key
'kakao_api_key' => '',
];
Expand Down Expand Up @@ -101,6 +115,14 @@ function ( string $item ) {
$_POST[ $option_name ]['height'] ?? $default['height']
);

$output['priority'] = intval(
$_POST[ $option_name ]['priority'] ?? $default['priority']
);

$output['concat'] = sanitize_key(
$_POST[ $option_name ]['concat'] ?? $default['concat']
);

$output['kakao_api_key'] = sanitize_text_field(
$_POST[ $option_name ]['kakao_api_key'] ?? $default['kakao_api_key']
);
Expand Down
Loading

0 comments on commit 1d825c0

Please sign in to comment.