Plugin Directory

Changeset 1934587


Ignore:
Timestamp:
09/02/2018 02:03:27 PM (8 years ago)
Author:
chaoxifer
Message:

Fix some bugs and add new feature within metabox widget.

Location:
tistorywriter/trunk
Files:
7 added
9 edited

Legend:

Unmodified
Added
Removed
  • tistorywriter/trunk/assets/pages/metabox_main.php

    r1934352 r1934587  
    77use const tistory_writer\FEATURE_KEY\OPTION;
    88use const tistory_writer\FEATURE_KEY\TISTORY_API;
     9use const tistory_writer\OPTION_KEY\ACCESS_TOKEN;
     10use const tistory_writer\OPTION_KEY\CLIENT_ID;
    911use const tistory_writer\OPTION_KEY\REDIRECT_URI;
    1012use const tistory_writer\OPTION_KEY\SELECTED_BLOG;
     
    1315
    1416$api_mgr = TistoryWriter::getManager(TISTORY_API);
    15 $option_mgr = TistoryWriter::getManager(OPTION);
    16 
    17 echo "<div class=\"service-container\" data-redirecturi=\"" . $option_mgr->getOption(REDIRECT_URI) . "\"></div>";
    1817
    1918// 액세스 토큰 유효성 검사
     
    2322
    2423if (!$isAccessTokenAvailable) {
    25     echo "<div id=\"div_require_token\" style='padding: 10px; vertical-align:center;'>";
    26     echo "<span style='padding: 5px; vertical-align: center; height: 50px;'>액세스 토큰이 설정되지 않았습니다. 계정 설정을 먼저 해주세요.</span></div>";
    27 }
    28 else {
    2924?>
    30 
     25<div id="div_require_token" style="padding: 10px; vertical-align:center;">
     26    <span style="padding: 5px; vertical-align: center; height: 50px;">
     27        액세스 토큰이 설정되지 않았습니다. 계정 설정을 먼저 해주세요.</span>
     28    <div style="padding: 5px; margin-top: 5px;">
     29        <input type="button" value="액세스 토큰 갱신" id="refresh_access_code" class="button" />
     30    </div>
     31</div>
     32
     33<?php
     34} else {
     35?>
    3136<div id="tw_metabox">
    3237    <style>
     
    4146    </style>
    4247    <div id="tw-table">
    43 
    4448        <div class="tw-row">
    4549            <div class="tw-cell tw-entryname">
    4650                <span class="cell-content" style="margin-left: 3px;">연동 계정</span></div>
    4751            <div class="tw-cell">
    48                 <span id="span_access_code">
     52                <span id="blogAccount" class="blogAccount">
    4953                <?php
    5054                if ($isAccessTokenAvailable) {
     
    214218
    215219</div>
    216 
    217220<?php
    218221}
  • tistorywriter/trunk/assets/pages/panel_changelog.php

    r1934352 r1934587  
    55                <h4>업데이트 내역</h4>
    66                <div class="mdl-cell mdl-cell--8-col mdl-card__supporting-text no-padding">
     7                    <h6>1.0.5</h6>
     8                    <ul>
     9                        <li>글 작성 시 Access Code 만료된 경우 코드 갱신할 수 있도록 버튼 추가</li>
     10                        <li>Access Code 만료 시 포스팅 창 내 오류 메시지 출력 제거</li>
     11                    </ul>
     12
    713                    <h6>1.0.4</h6>
    814                    <ul>
  • tistorywriter/trunk/assets/scripts/tw_jquery.js

    r1934309 r1934587  
    11jQuery(document).ready(function($) {
    2 
    32    document.getElementById('footer-thankyou').style.display = 'none';
    43    document.getElementById('footer-upgrade').style.display = 'none';
     
    5857            if (opener != null) {
    5958                var access_code_span = opener.document.getElementById('span_access_code');
    60                 access_code_span.innerText = access_token;
    6159
    62                 var json_data = JSON.parse(data);
     60                if (typeof(access_code_span) != "undefined" && access_code_span != null) {
     61                    access_code_span.innerText = access_token;
    6362
    64                 if (json_data != null) {
    65                     // 블로그 정보 갱신
    66                     for (var i in json_data) {
    67                         var blogurl_span = opener.document.getElementById('blog_url_' + json_data[i].name);
    68                         if (blogurl_span != null) {
    69                             blogurl_span.innerHTML = "<a href=\"" + json_data[i].url + "\">" + json_data[i].title + "(" + json_data[i].url + ")</a>";
     63                    var json_data = JSON.parse(data);
     64
     65                    if (json_data != null) {
     66                        // 블로그 정보 갱신
     67                        for (var i in json_data) {
     68                            var blogurl_span = opener.document.getElementById('blog_url_' + json_data[i].name);
     69                            if (blogurl_span != null) {
     70                                blogurl_span.innerHTML = "<a href=\"" + json_data[i].url + "\">" + json_data[i].title + "(" + json_data[i].url + ")</a>";
     71                            }
    7072                        }
    7173                    }
     
    7981
    8082jQuery(document).ready(function($) {
    81 
    82     /*
    83      * 설정 저장 이벤트 처리
    84      */
    8583    $(".tw-save-setting").click(function () {             //event
    8684
  • tistorywriter/trunk/assets/scripts/tw_metabox_jquery.js

    r1934352 r1934587  
     1// global variables
     2var timer, subwin;
     3
    14$(document).ready(function() {
    25
    3     var client_id;
    4     var redirect_uri;
     6    $("#refresh_access_code").click(function () {
    57
    6     $('.service-container').each(function() {
    7         var container = $(this);
    8 
    9         //client_id = container.data('clientid');
    10         redirect_uri = container.data('redirecturi');
    11     });
    12 
    13     $('.refresh_access_code').click(function() {
    148        $.post(tw_ajax.ajax_url, {
    159            _ajax_nonce: tw_ajax.nonce,
    16             action: "refreshAccessCode",
    17         }, function (data) {
    18 
    19         });
     10            action: "getUrlForAccessToken"
     11        }, function(url) {
     12            subwin = window.open(url);
     13            timer = setInterval(checkChild, 500);
     14        })
    2015    });
    2116
     
    5348    });
    5449});
     50
     51function checkChild() {
     52    if (subwin.closed) {
     53        clearInterval(timer);
     54        location.reload();
     55    }
     56}
    5557
    5658function GetMetaboxData() {
     
    120122        }
    121123        else  {
    122             $("#acceptComment").prop('checked', false);
     124            $("#checkAllowComment").prop('checked', false);
    123125        }
    124126    }
  • tistorywriter/trunk/features/api_manager.php

    r1934352 r1934587  
    130130
    131131        for ($i = 0; $i < TRY_NUM; $i++ ) {
    132             $result = file_get_contents($requestUrl);
    133             if ($result != false) {
     132            $result = @file_get_contents($requestUrl);
     133            if (empty($result)) {
    134134                return $result;
    135135            }
     
    152152
    153153        for ($i = 0; $i < TRY_NUM; $i++ ) {
    154             $result = file_get_contents( $url, false, $context );
     154            $result = @file_get_contents( $url, false, $context );
    155155            if ($result != false) {
    156156                return $result;
  • tistorywriter/trunk/features/handler_manager.php

    r1846025 r1934587  
    11<?php
    22namespace tistory_writer;
     3
     4use const tistory_writer\REQUEST_KEY\REQUEST_SAVE_SETTINGS;
     5use const tistory_writer\REQUEST_KEY\HANDLER_SUFFIX;
    36
    47/**
     
    1114    public function __construct()
    1215    {
    13         $this->handlers = array (
    14             REDIRECT_EVENT\SETTINGINFO => array($this, 'handlerSettingInfo'),
    15             REDIRECT_EVENT\SETTINGINFO_RESET => array($this, 'handlerSettingInfoReset'),
    16             REDIRECT_EVENT\SETTING_ACCESSCODE => array($this, 'handlerAccessCode'),
     16        // Initiailize request handlers
     17        $this->handlers = array(
     18            REQUEST_SAVE_SETTINGS => REQUEST_SAVE_SETTINGS . HANDLER_SUFFIX,
    1719        );
    1820    }
    1921
    20     public function handle($redirectDef)
     22    public function handleRequest($requestName)
    2123    {
    2224        // Validate $redirectDef value
    23         if (array_key_exists($redirectDef, $this->handlers)) {
    24             $this->handlers[$redirectDef]();
     25        if (array_key_exists($requestName, $this->handlers)) {
     26            $this->handlers[$requestName]();
    2527        }
    2628    }
    2729
    28     /**
    29      * 사용자가 설정창에서 #2 설정단계를 SUbmit했을 경우에 호출되는 핸들러
    30      */
    31     public function handlerSettingInfo()
    32     {
    33         $optionMgr = TistoryWriter::getManager(FEATURE_KEY\OPTION);
     30    public static function REQUEST_SAVE_SETTINGS_HANDLER()
     31    {
     32        check_ajax_referer( 'tistory_writer' );
    3433
    35         $callback_uri_temp = get_admin_url() . 'options-general.php?page=tistory_writer';
     34        $optionMgr = self::getManager(FEATURE_KEY\OPTION);
    3635
    37         /* 옵션 설정 */
    38         $optionMgr->setOption(OPTION_KEY\CLIENT_ID, wp_kses_post($_POST['client_id']));
    39         $optionMgr->setOption(OPTION_KEY\SECRET_KEY, wp_kses_post($_POST['secret_key']));
    40         $optionMgr->setOption(OPTION_KEY\BLOG_NAME, wp_kses_post($_POST['blogname']));
    41         $optionMgr->setOption(OPTION_KEY\CALLBACK_URL, wp_kses_post($callback_uri_temp));
     36        $optionMgr->setOption(CLIENT_ID, $_POST['client_id']);
     37        $optionMgr->setOption(SECRET_KEY, $_POST['secret_key']);
     38        $optionMgr->setOption(BLOG_NAME, $_POST['blog_name']);
    4239
    43         wp_safe_redirect(get_admin_url() . "/options-general.php?page=tistory_writer");
    44     }
     40        $apiMgr = self::getManager(TISTORY_API);
     41        $blogInfo = $apiMgr->getBlogInformation();
    4542
    46     /**
    47      * 사용자가 Access Token을 얻어왔을 때 처리 핸들러
    48      */
    49     public function handlerAccessCode()
    50     {
    51         $optionMgr = TistoryWriter::getManager(FEATURE_KEY\OPTION);
    52         $optionMgr->setOption(OPTION_KEY\ACCESS_TOKEN, wp_kses_post($_POST['access_code']));
    53 
    54         wp_safe_redirect(get_admin_url() . "/options-general.php?page=tistory_writer");
    55     }
    56 
    57     public function handlerSettingInfoReset()
    58     {
    59         $optionMgr = TistoryWriter::getManager(FEATURE_KEY\OPTION);
    60         $optionMgr->setOption(OPTION_KEY\ACCESS_TOKEN, '');
    61 
    62         wp_safe_redirect(get_admin_url() . "/options-general.php?page=tistory_writer");
    63     }
     43        wp_die(json_encode($blogInfo));
     44    }
    6445}
  • tistorywriter/trunk/features/tistory_writer.php

    r1934352 r1934587  
    33namespace tistory_writer;
    44
     5use const tistory_writer\FEATURE_KEY\HANDLER;
    56use const tistory_writer\FEATURE_KEY\OPTION;
    67use const tistory_writer\FEATURE_KEY\TISTORY_API;
     
    1920 * @author   Sukbeom Kim <sukbeom.kim@gmail.com>
    2021 * @license  GPL v2
    21  * @version  Release: 1.0.4
     22 * @version  Release: 1.0.5
    2223 * @link     https://github.com/seokbeomKim/TistoryWriter
    2324 */
     
    6162    }
    6263
     64    public static function handleRequest() {
     65        $handlerMgr = self::getManager(HANDLER);
     66        $handlerMgr->handleRequest($_POST['action']);
     67    }
     68
    6369    public static function checkAuthCode($code)
    6470    {
     
    184190    {
    185191        $apiMgr   = self::getManager(FEATURE_KEY\TISTORY_API);
    186         $postId = "";
    187192        $title = $_POST['title'];
    188193
    189194        $categories = $apiMgr->getCategoryList();
    190 
    191         $postInfo = $apiMgr->getPostInfoWithTitle($title, $postId);
     195        $postInfo = $apiMgr->getPostInfoWithTitle($title);
    192196
    193197        if (!is_null($postInfo)) {
     
    293297
    294298        wp_die(json_encode($blogInfo));
     299    }
     300
     301    public static function getUrlForAccessToken()
     302    {
     303        $optionMgr = self::getManager(FEATURE_KEY\OPTION);
     304
     305        $rvalue = "https://www.tistory.com/oauth/authorize?client_id=" . $optionMgr->getOption(CLIENT_ID) .
     306        "&redirect_uri=" . $optionMgr->getOption(REDIRECT_URI) . "&response_type=token";
     307
     308        wp_die($rvalue);
    295309    }
    296310
     
    348362        $flag   = isset($_POST['turnIntegratationOff']);
    349363
    350         if (!$flag && isset($_POST['postId'])) {
     364        $post_info = $apiMgr->getPostInfoWithTitle($post->post_title);
     365
     366        if (!$flag) {
    351367            if (strpos($post->name, 'autosave') != true) {
    352                 $ti = (int)wp_kses_post($_POST['postId']);
     368                $ti = (int)wp_kses_post($post_info['id']);
    353369                if ($ti <= 0) {
    354370                    self::postUpdate();
  • tistorywriter/trunk/readme.txt

    r1934352 r1934587  
    55Requires at least: 1.5
    66Tested up to: 4.9.5
    7 Stable tag: 1.0.4
     7Stable tag: 1.0.5
    88License: MIT License
    99License URI: https://mit-license.org/
     
    4242
    4343== Changelog ==
     44= 1.0.5 =
     45* 글 작성 시 Access Code 만료된 경우 코드 갱신할 수 있도록 버튼 추가
     46* Access Code 만료 시 포스팅 창 내 오류 메시지 출력 제거
     47
    4448= 1.0.4 =
    4549* 버그 수정
  • tistorywriter/trunk/tistorywriter.php

    r1934352 r1934587  
    77 * Author URI: https://chaoxifer.tistory.com
    88 * Contributors:None
    9  * Version: 1.0.4
     9 * Version: 1.0.5
    1010 * Text Domain: TistoryWriter
    1111
     
    3838defined('ABSPATH') or die('No script kiddies please!');
    3939
    40 define(__NAMESPACE__ . '\VERSION', '1.0.4');
     40define(__NAMESPACE__ . '\VERSION', '1.0.5');
    4141define(__NAMESPACE__ . '\MAIN_URL', $_SERVER['HTTP_HOST'] . '/wp-admin/options-general.php?page=tistory_writer');
    4242define(__NAMESPACE__ . '\PLUGIN_DIR', plugin_dir_path(__FILE__));
     
    5151require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'def' . DIRECTORY_SEPARATOR . 'fs_require.php');
    5252require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'def' . DIRECTORY_SEPARATOR . 'errors.php');
     53require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'def' . DIRECTORY_SEPARATOR . 'requests.php');
    5354
    5455add_action('admin_menu', array('tistory_writer\TistoryWriter', 'addAdminOptionMenu'));
     
    6364
    6465add_action( 'wp_ajax_saveSettings', array('tistory_writer\TistoryWriter', 'saveSettings') );
     66//add_action( 'wp_ajax_saveSettings', array('tistory_writer\TistoryWriter', 'handleRequest') );
    6567add_action( 'wp_ajax_requestAccessCode', array('tistory_writer\TistoryWriter', 'requestAccessCode') );
    6668add_action( 'wp_ajax_requestAccessCodeWithAuth', array('tistory_writer\TistoryWriter', 'requestAccessCodeWithAuth') );
     
    6870add_action( 'wp_ajax_getMetaboxData', array('tistory_writer\TistoryWriter', 'getMetaboxData') );
    6971add_action( 'wp_ajax_requestBlogUrl', array('tistory_writer\TistoryWriter', 'requestBlogUrl') );
     72add_action( 'wp_ajax_getUrlForAccessToken', array('tistory_writer\TistoryWriter', 'getUrlForAccessToken') );
    7073
    7174register_activation_hook(__FILE__, array('tistory_writer\TistoryWriter', 'activatePlugin'));
Note: See TracChangeset for help on using the changeset viewer.