Plugin Directory

Changeset 1033049


Ignore:
Timestamp:
11/26/2014 09:27:09 AM (11 years ago)
Author:
jquerybloger
Message:

version up & bug fix

Location:
write-time/trunk
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • write-time/trunk/languages/write-time-ja.po

    r1022353 r1033049  
    44msgstr ""
    55"Project-Id-Version: write time\n"
    6 "POT-Creation-Date: 2014-11-09 00:57+0900\n"
    7 "PO-Revision-Date: 2014-11-09 00:58+0900\n"
     6"POT-Creation-Date: 2014-11-26 18:15+0900\n"
     7"PO-Revision-Date: 2014-11-26 18:17+0900\n"
    88"Last-Translator: yonetsu <[email protected]>\n"
    99"Language-Team: shinji yonetsu\n"
     
    1919"X-Poedit-SearchPath-0: ..\n"
    2020
    21 #: ../write-time.php:111 ../write-time.php:121
     21#: ../write-time.php:159
    2222msgid "This article"
    2323msgstr "この記事は"
    2424
    25 #: ../write-time.php:113 ../write-time.php:115
     25#: ../write-time.php:161 ../write-time.php:163 ../write-time.php:170
     26#: ../write-time.php:172 ../write-time.php:286 ../write-time.php:288
     27#: ../write-time.php:311 ../write-time.php:313
    2628msgid "minute"
    2729msgstr "分"
    2830
    29 #: ../write-time.php:113 ../write-time.php:115 ../write-time.php:117
     31#: ../write-time.php:161 ../write-time.php:163 ../write-time.php:165
     32#: ../write-time.php:170 ../write-time.php:172 ../write-time.php:174
     33#: ../write-time.php:286 ../write-time.php:288 ../write-time.php:290
     34#: ../write-time.php:311 ../write-time.php:313 ../write-time.php:315
    3035msgid "second"
    3136msgstr "秒"
    3237
    33 #: ../write-time.php:115
     38#: ../write-time.php:163 ../write-time.php:288 ../write-time.php:313
    3439msgid "hour"
    3540msgstr "時間"
    3641
    37 #: ../write-time.php:119 ../write-time.php:129
     42#: ../write-time.php:167
    3843msgid "I wrote in ."
    3944msgstr "で書きました。"
    4045
    41 #: ../write-time.php:123 ../write-time.php:125
    42 msgid "<span>minute</span>"
    43 msgstr "<span>分</span>"
    44 
    45 #: ../write-time.php:123 ../write-time.php:125 ../write-time.php:127
    46 msgid "<span>second</span>"
    47 msgstr "<span>秒</span>"
    48 
    49 #: ../write-time.php:125
     46#: ../write-time.php:172
    5047msgid "<span>hour</span>"
    5148msgstr "<span>時間</span>"
     49
     50#: ../write-time.php:267
     51msgid ""
     52"<table class=\"write_date\"><tbody class=\"scrollBody\"><tr><th>ID</"
     53"th><th>date</th><th>title</th><th>status</th><th>write time</th><th>edit</"
     54"th></tr>"
     55msgstr ""
     56"<table class=\"write_date\"><tbody class=\"scrollBody\"><tr><th>ID</th><th>日"
     57"付</th><th>記事タイトル</th><th>公開状態</th><th>執筆時間</th><th>編集リンク"
     58"</th></tr>"
     59
     60#: ../write-time.php:308
     61msgid "<p>ALL article"
     62msgstr "<p>全記事数"
     63
     64#: ../write-time.php:309
     65msgid "<p>ALL write time"
     66msgstr "<p>執筆時間合計"
     67
     68#~ msgid "<span>minute</span>"
     69#~ msgstr "<span>分</span>"
     70
     71#~ msgid "<span>second</span>"
     72#~ msgstr "<span>秒</span>"
    5273
    5374#~ msgctxt "text direction"
  • write-time/trunk/write-time.php

    r1029928 r1033049  
    44Plugin URI: http://11neko.com/
    55Description: To display the time it took to write the article .
    6 Version: 0.2.4
     6Version: 0.3
    77Author: shinji yonetsu
    88Author URI: http://11neko.com/
     
    3737    $last_edit_time = strtotime($last_edit_time);
    3838    $created_total_time = get_post_meta($created_edit_time_id, 'created_total_time', false);
    39 
    40 
    41 
    42     if( $post_time === $last_edit_time ){
     39    $post_status = get_post_status($created_edit_time_id);
     40
     41    if( $post_time === $last_edit_time or $post_status == "future"){
    4342        $start_edit_time_flg = get_post_meta($created_edit_time_id, 'start_edit_time', false);
    4443        if( empty($start_edit_time_flg) ){
     
    107106    $start_edit_time = get_post_meta($created_edit_time_id, 'start_edit_time', false);
    108107    $first_created_endtime = get_post_meta($created_edit_time_id, 'first_created_endtime', false);
     108
    109109    if( !empty($first_created_endtime)){
    110110        if( !empty($start_edit_time)){
     
    129129add_action('pre_post_update', 'get_article_last_edit_time');
    130130
     131
     132function future_post($post_id){
     133    if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
     134    return $post_id;
     135    global $post;
     136    if($post_id->post_status == 'future'){
     137        echo "true";
     138    } else{
     139        echo "false";
     140    }
     141}
     142
     143add_action( 'edit_post', 'my_function' );
     144
    131145// Program for beginners function
    132146// single or page
    133147function display_time($time_format){
     148    date_default_timezone_set( 'Asia/Tokyo' );
    134149    global $post;
    135150    $created_time = get_post_meta( $post->ID , 'created_total_time' , true );
    136     //$show_time = $created_time[0] + $edit_time[0];
    137151    $show_hor_time = floor($created_time / 3600);
    138152    $show_min_time = floor($created_time / 60);
    139153    $show_min_time = $show_min_time % 60;
    140154    $show_sec_time = $created_time % 60;
     155
    141156    // time_format_setting
    142157    if( !empty($created_time) or !empty($edit_time) ){
    143         if($time_format == 'default'){
     158        if($time_format == 'defalut'){
    144159            echo _e('This article' , 'write-time');
    145160            if( $created_time > 60 && $created_time < 3600){
     
    151166            }
    152167            echo _e('I wrote in .' , 'write-time');
    153         } elseif($time_format == 'only'){
    154             echo _e('This article' , 'write-time');
     168        } elseif($time_format == 'custom'){
    155169            if( $created_time > 60 && $created_time < 3600){
    156                 echo $show_min_time,_e('<span>minute</span>' , 'write-time'),$show_sec_time,_e('<span>second</span>' , 'write-time');
     170                echo $show_min_time,_e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
    157171            } elseif( $created_time > 3600 ){
    158                 echo $show_hor_time,_e('<span>hour</span>' , 'write-time'),$show_min_time,_e('<span>minute</span>' , 'write-time'),$show_sec_time,_e('<span>second</span>' , 'write-time');
     172                echo $show_hor_time,_e('<span>hour</span>' , 'write-time'),$show_min_time,_e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
    159173            } else{
    160                 echo $show_sec_time,_e('<span>second</span>' , 'write-time');
    161             }
    162             echo _e('I wrote in .' , 'write-time');
    163         }
    164     }
     174                echo $show_sec_time,_e('second' , 'write-time');
     175            }
     176           
     177        }
     178    }
     179}
     180
     181
     182// add menu style & script
     183add_action( 'admin_init', 'my_plugin_admin_init' );
     184
     185function my_plugin_admin_init() {
     186    wp_register_style( 'myPluginStylesheet', plugins_url('css/style.css', __FILE__) );
     187    wp_register_style( 'myPluginStylesheet2', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css' );
     188    wp_register_script( 'my-plugin-script', plugins_url( 'js/highstock.js', __FILE__ ) );
     189    wp_register_script( 'my-plugin-script2', plugins_url( 'js/exporting.js', __FILE__ ) );
     190    wp_register_script( 'my-plugin-script3', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js');
    165191}
    166192
    167193
    168194// add menu
    169 add_action('admin_menu' , 'add_write_time_menu');
    170 function add_write_time_menu(){
    171     add_menu_page('WriteTime', 'WriteTime', 'manage_options', 'write_time_page', 'write_time_display' , 'dashicons-clock');
    172 }
    173 
     195
     196function my_plugin_admin_styles() {
     197    wp_enqueue_style( 'myPluginStylesheet' );
     198    wp_enqueue_style( 'myPluginStylesheet2' );
     199}
     200
     201function my_plugin_admin_scripts() {
     202        wp_enqueue_script( 'my-plugin-script' );
     203        wp_enqueue_script( 'my-plugin-script2' );
     204        wp_enqueue_script( 'my-plugin-script3' );
     205    }
    174206// display page
    175 function write_time_display(){
     207/////////////////////////////////////////////////////////////////
     208
     209add_action('admin_menu' , 'add_hoge');
     210function add_hoge(){
     211    $page = add_menu_page('write time', 'write time', 'manage_options', 'myplugin_id', 'write_time_page','dashicons-clock');
     212    add_action( 'admin_print_styles-' . $page, 'my_plugin_admin_styles' );
     213    add_action('admin_print_scripts-' . $page, 'my_plugin_admin_scripts2');
     214}
     215function my_plugin_admin_scripts2() {
     216        wp_enqueue_script( 'my-plugin-script' );
     217        wp_enqueue_script( 'my-plugin-script2' );
     218        wp_enqueue_script( 'my-plugin-script3' );
     219    }
     220
     221add_action( 'wp_ajax_'.myplugin_get_action_name(), 'myplugin_response' );
     222add_action( 'wp_ajax_nopriv_'.myplugin_get_action_name(), 'myplugin_response' );
     223
     224function myplugin_get_action_name() {
     225    return 'myplugin_action';
     226}
     227
     228function myplugin_get_nonce_name() {
     229    return 'myplugin-nonce';
     230}
     231
     232function write_time_page() {
     233    echo '<h2>write time Page</h2>';
     234    echo '<div id="container"></div>';
     235    $nonce_name = myplugin_get_nonce_name();
     236    $nonce = wp_create_nonce( $nonce_name );
     237    $action_name = myplugin_get_action_name();
     238    $url = admin_url( 'admin-ajax.php' );
     239
     240    $json_options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
     241    $url = json_encode( $url,  $json_options );
     242
     243
     244    $json = json_encode(
     245    array(
     246      'action' => $action_name,
     247      'security' => $nonce,
     248      'foo' => 'bar'
     249    ), $json_options );
     250
    176251    $count;
    177252    $all_create_time;
     
    184259    $wp_query->query($args);
    185260
    186     // display
    187     echo '<table class="write_date"><tr><th>ID</th><th>date</th><th>title</th><th>status</th><th>write time</th></tr>';
     261
     262    // glaph
     263    echo '<div id="container"></div>';
     264   
     265    // display date
     266    echo '<div class="table_style">';
     267    echo _e('<table class="write_date"><tbody class="scrollBody"><tr><th>ID</th><th>date</th><th>title</th><th>status</th><th>write time</th><th>edit</th></tr>' , 'write-time');
    188268    $total_count = 0;
    189269    $count = 0;
    190270    while ($wp_query->have_posts()) : $wp_query->the_post();
    191     $post_id = get_the_ID();
    192     $total = get_post_meta($post_id , 'created_total_time' ,true);
    193     $total_count += $total;
    194 
    195     echo '<tr><td>' , get_the_id() , '</td>';
    196     echo '<td>' , the_time('Y-m-d') , '</td>';
    197     echo '<td>' , get_the_title() , '</td>';
    198     echo '<td>' , get_post_status() , '</td>';
    199     echo '<td>';
    200     $show_hor_time = floor($total / 3600);
    201     $show_min_time = floor($total / 60);
    202     $show_min_time = $total % 60;
    203     $show_sec_time = $total % 60;
    204 
    205     if( $total > 60 && $total < 3600){
    206                 echo $show_min_time, _e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
    207             } elseif( $total > 3600){
    208                 echo $show_hor_time,_e('hour' , 'write-time'),$show_min_time,_e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
    209             } else{
    210                 echo $show_sec_time,_e('second' , 'write-time');
    211             }
    212     echo '</td></tr>';
    213 
    214     $count++;
     271        $post_id = get_the_ID();
     272        $total = get_post_meta($post_id , 'created_total_time' ,true);
     273        if(!empty($total)){
     274            echo '<tr><td>' , get_the_id() , '</td>';
     275            echo '<td>' , the_time('Y-m-d') , '</td>';
     276            echo '<td>' , get_the_title() , '</td>';
     277            echo '<td>' , get_post_status() , '</td>';
     278            echo '<td>';
     279            $show_hor_time = floor($total / 3600);
     280            $show_min_time = floor($total / 60);
     281            $show_min_time = $show_min_time % 60;
     282            $show_sec_time = $total % 60;
     283       
     284
     285        if( $total > 60 && $total < 3600){
     286                    echo $show_min_time, _e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
     287                } elseif( $total > 3600){
     288                    echo $show_hor_time,_e('hour' , 'write-time'),$show_min_time,_e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
     289                } else{
     290                    echo $show_sec_time,_e('second' , 'write-time');
     291                }
     292        echo '</td>';
     293        echo '<td>' , edit_post_link('edit') , '</td>';
     294        echo '</tr>';
     295        }
     296        $total_count += $total;
     297        $count++;
    215298    endwhile;
     299    echo '</tbody>';
    216300    echo '</table>';
    217    
     301    echo '</div>';
     302
    218303    $show_hor_time = floor($total_count / 3600);
    219304    $show_min_time = floor($total_count / 60);
    220     $show_min_time = $total_count % 60;
     305    $show_min_time = $show_min_time % 60;
    221306    $show_sec_time = $total_count % 60;
    222 
    223     echo '<p>ALL article' , $count , '</p>';
    224     echo '<p>ALL write time';
     307    echo '<div class="article_date"';
     308    echo _e('<p>ALL article' , 'write-time') , $count , '</p>';
     309    echo _e('<p>ALL write time' , 'write-time') ;
    225310    if( $total_count > 60 && $total_count < 3600){
    226311                echo $show_min_time, _e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
     
    230315                echo $show_sec_time,_e('second' , 'write-time');
    231316            }
    232     echo '</p><br>';
     317    echo '</p>';
     318    echo '</div>';
    233319    wp_reset_query();
    234320
     321?>
     322
     323<div id="result"></div>
     324<script type="text/javascript">
     325function utc2dateString(utc_msec) {
     326  d=new Date();
     327  d.setTime(utc_msec);
     328  return d.getFullYear()+'/'+(d.getMonth()+1)+'/'+d.getDate();
     329}
     330
     331(function($) {
     332
     333  var url = <?php echo $url ?>;
     334  var data = <?php echo $json ?>;
     335
     336  $.post(url,data,function (ret) {
     337        console.log(ret);
     338        Highcharts.setOptions({
     339            global: {
     340            useUTC: true
     341        },
     342        lang: {
     343            rangeSelectorZoom: '表示範囲',
     344            resetZoom: '表示期間をリセット',
     345            resetZoomTitle: '表示期間をリセット',
     346            rangeSelectorFrom: '表示期間',
     347            rangeSelectorTo: '〜',
     348            printButtonTitle: 'チャートを印刷',
     349            exportButtonTitle: '画像としてダウンロード',
     350            downloadJPEG: 'JPEG画像でダウンロード',
     351            downloadPDF: 'PDF文書でダウンロード',
     352            downloadPNG: 'PNG画像でダウンロード',
     353            downloadSVG: 'SVG形式でダウンロード',
     354            months: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
     355            weekdays: ['日', '月', '火', '水', '木', '金', '土'],
     356            numericSymbols: null
     357          }
     358        });
     359
    235360   
    236 }
     361
     362        // Create the chart
     363        $('#container').highcharts('StockChart', {
     364            rangeSelector : {
     365                selected : 1
     366            },
     367
     368            title : {
     369                text : 'write time'
     370            },
     371
     372            series : [{
     373                name : 'write time',
     374                turboThreshold: 0,
     375                data : ret,
     376                tooltip: {
     377                    shared: true,
     378                    pointFormat: '{point.y} 分',
     379                    valueDecimals: 0
     380                }
     381            }],
     382
     383            xAxis: [{
     384                labels: {
     385                  formatter: function(){ return utc2dateString(this.value); }
     386                }
     387              }],
     388            navigator: {
     389                baseSeries: 0
     390            },
     391
     392            yAxis: [{
     393                title: {
     394                    text: '時間(分)'
     395                }
     396            }],
     397
     398            plotOptions: {
     399                series: {
     400                  dataGrouping: {
     401                    dateTimeLabelFormats: {
     402                       millisecond: ['%Y/%m/%d %H:%M:%S.%L', '%Y/%m/%d %H:%M:%S.%L', '-%H:%M:%S.%L'],
     403                       second: ['%Y/%m/%d %H:%M:%S', '%Y/%m/%d %H:%M:%S', '-%H:%M:%S'],
     404                       minute: ['%Y/%m/%d %H:%M', '%Y/%m/%d %H:%M', '-%H:%M'],
     405                       hour: ['%Y/%m/%d %H:%M', '%Y/%m/%d %H:%M', '-%H:%M'],
     406                       day: ['%Y/%m/%d', '%Y/%m/%d', '-%Y/%m/%d'],
     407                       week: ['%Y/%m/%d', '%Y/%m/%d', '-%Y/%m/%d'],
     408                       month: ['%B %Y', '%B', '-%B %Y'],
     409                       year: ['%Y', '%Y', '-%Y']
     410                    }
     411                  }
     412                },
     413            },
     414            rangeSelector: {
     415                selected : 1,
     416                inputDateFormat: '%Y/%m/%d',
     417                inputEditDateFormat: '%Y/%m/%d',
     418                buttons : [{
     419                    type : 'day',
     420                    count : 90,
     421                    text : '3ヶ月'
     422                }, {
     423                    type : 'day',
     424                    count : 180,
     425                    text : '6ヶ月'
     426                }, {
     427                    type : 'year',
     428                    count : 1,
     429                    text : '1年'
     430                    }, {
     431                    type : 'year',
     432                    count : 2,
     433                    text : '2年'
     434                }, {
     435                    type : 'year',
     436                    count : 3,
     437                    text : '3年'
     438                }, {
     439                    type : 'all',
     440                    count : 1,
     441                    text : 'All'
     442                }]
     443            }
     444        }, function (chart) {
     445        // apply the date pickers
     446        setTimeout(function () {
     447            $('input.highcharts-range-selector', $(chart.container).parent()).datepicker();}, 0);
     448            });
     449       
     450        // Set the datepicker's date format
     451        $.datepicker.setDefaults({
     452            dateFormat: 'yy-mm-dd',
     453            onSelect: function () {
     454                this.onchange();
     455                this.onblur();
     456            }
     457        });
     458
     459    });
     460})(jQuery);
     461</script>
     462
     463<?php
     464}
     465
     466function myplugin_response() {
     467    $nonce_name = myplugin_get_nonce_name();
     468    check_ajax_referer( $nonce_name, 'security' );
     469
     470    $ret = array();
     471    $args = array(
     472        'meta_key' => 'created_total_time',
     473        'order' => 'asc',
     474        'posts_per_page' => -1
     475        );
     476    $posts = get_posts( $args );
     477    foreach( $posts as $key => $post ) {
     478        $time_stomp = get_post_meta($post->ID , 'created_total_time' ,true);
     479        $time_stomp = intval($time_stomp);
     480        $show_hor_time = floor($time_stomp / 3600);
     481        $show_min_time = floor($time_stomp / 60);
     482
     483        $data_time = strtotime($post->post_date) * 1000;
     484
     485        $ret[$key] = array(
     486            $data_time,$show_min_time
     487            );
     488    }
     489    header( 'Content-Type: application/json' );
     490    wp_send_json( $ret );
     491}
     492
    237493
    238494?>
Note: See TracChangeset for help on using the changeset viewer.