Plugin Directory

Changeset 1029921


Ignore:
Timestamp:
11/21/2014 06:40:47 AM (11 years ago)
Author:
jquerybloger
Message:

add menu and bugfix

Location:
write-time/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • write-time/trunk/readme.txt

    r1022453 r1029921  
    5555
    5656== Changelog ==
     57= 0.2.2 =
     58add menu. and bugfix.
    5759
    5860= 0.1 =
  • write-time/trunk/write-time.php

    r1022614 r1029921  
    44Plugin URI: http://11neko.com/
    55Description: To display the time it took to write the article .
    6 Version: 0.2.1
     6Version: 0.2.3
    77Author: shinji yonetsu
    88Author URI: http://11neko.com/
     
    3636    $post_time = strtotime($post_time);
    3737    $last_edit_time = strtotime($last_edit_time);
     38    $created_total_time = get_post_meta($created_edit_time_id, 'created_total_time', false);
     39
     40
    3841
    3942    if( $post_time === $last_edit_time ){
     
    6265        }
    6366    }
     67
     68    if( empty($created_total_time)){
     69        $total_edit_time = get_post_meta($created_edit_time_id, 'total_edit_time', false);
     70        $total_article_time = get_post_meta($created_edit_time_id, 'total_article_time', false);
     71        if(!isset($total_edit_time[0])){
     72            echo 'set_total';
     73            $total_edit_time[0] = 0;
     74        }
     75        if(!isset($total_article_time[0])){
     76            echo 'set_article';
     77            $total_article_time[0] = 0;
     78        }
     79        $created_total_time = $total_edit_time[0] + $total_article_time[0];
     80        add_post_meta($created_edit_time_id, 'created_total_time', $created_total_time);
     81    } else{
     82        $total_edit_time = get_post_meta($created_edit_time_id, 'total_edit_time', false);
     83        $total_article_time = get_post_meta($created_edit_time_id, 'total_article_time', false);
     84        if(!isset($total_edit_time[0])){
     85            echo 'set_total';
     86            $total_edit_time[0] = 0;
     87        }
     88        if(!isset($total_article_time[0])){
     89            echo 'set_article';
     90            $total_article_time[0] = 0;
     91        }
     92        $created_total_time = $total_edit_time[0] + $total_article_time[0];
     93        update_post_meta($created_edit_time_id, 'created_total_time', $created_total_time);
     94    }
     95
    6496}
    6597add_action( 'admin_head-post.php', 'get_article_edit_start_time' );
     
    99131function display_time($time_format){
    100132    global $post;
    101     $created_time = get_post_meta( $post->ID , 'total_article_time' , false );
    102     $edit_time = get_post_meta( $post->ID , 'total_edit_time' , false );
    103     $show_time = $created_time[0] + $edit_time[0];
    104     $show_hor_time = floor($show_time / 3600);
    105     $show_min_time = floor($show_time / 60);
     133    $created_time = get_post_meta( $post->ID , 'created_total_time' , true );
     134    //$show_time = $created_time[0] + $edit_time[0];
     135    $show_hor_time = floor($created_time / 3600);
     136    $show_min_time = floor($created_time / 60);
    106137    $show_min_time = $show_min_time % 60;
    107     $show_sec_time = $show_time % 60;
     138    $show_sec_time = $created_time % 60;
    108139    // time_format_setting
    109140    if( !empty($created_time) or !empty($edit_time) ){
    110141        if($time_format == 'default'){
    111142            echo _e('This article' , 'write-time');
    112             if( $show_time > 60 && $show_time < 3600){
     143            if( $created_time > 60 && $created_time < 3600){
    113144                echo $show_min_time, _e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
    114             } elseif( $show_time > 3600){
     145            } elseif( $created_time > 3600){
    115146                echo $show_hor_time,_e('hour' , 'write-time'),$show_min_time,_e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
    116147            } else{
     
    120151        } elseif($time_format == 'only'){
    121152            echo _e('This article' , 'write-time');
    122             if( $show_time > 60 && $show_time < 3600){
     153            if( $created_time > 60 && $created_time < 3600){
    123154                echo $show_min_time,_e('<span>minute</span>' , 'write-time'),$show_sec_time,_e('<span>second</span>' , 'write-time');
    124             } elseif( $show_time > 3600 ){
     155            } elseif( $created_time > 3600 ){
    125156                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');
    126157            } else{
     
    132163}
    133164
     165
     166// add menu
     167add_action('admin_menu' , 'add_write_time_menu');
     168function add_write_time_menu(){
     169    add_menu_page('WriteTime', 'WriteTime', 'manage_options', 'write_time_page', 'write_time_display' , 'dashicons-clock');
     170}
     171
     172// display page
     173function write_time_display(){
     174    $count; // 記事数
     175    $all_create_time; // 執筆時間
     176    // 最終計算値の値があるものだけ取得
     177
     178    //$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
     179    $wp_query = new WP_Query();
     180    $args = array(
     181            'meta_key' => 'created_total_time',
     182            'posts_per_page' => -1
     183        );
     184    //$wp_query = new WP_Query($args);
     185    $wp_query->query($args);
     186
     187    // display
     188    echo '<table class="write_date"><tr><th>ID</th><th>date</th><th>title</th><th>status</th><th>write time</th></tr>';
     189    //while ( $wp_query->have_posts() ) : $wp_query->the_post();
     190    $total_count = 0;
     191    $count = 0;
     192    while ($wp_query->have_posts()) : $wp_query->the_post();
     193    $post_id = get_the_ID();
     194    $total = get_post_meta($post_id , 'created_total_time' ,true);
     195    $total_count += $total;
     196
     197    echo '<tr><td>' , get_the_id() , '</td>';
     198    echo '<td>' , the_time('Y-m-d') , '</td>';
     199    echo '<td>' , get_the_title() , '</td>';
     200    echo '<td>' , get_post_status() , '</td>';
     201    echo '<td>';
     202    $show_hor_time = floor($total / 3600);
     203    $show_min_time = floor($total / 60);
     204    $show_min_time = $total % 60;
     205    $show_sec_time = $total % 60;
     206
     207    if( $total > 60 && $total < 3600){
     208                echo $show_min_time, _e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
     209            } elseif( $total > 3600){
     210                echo $show_hor_time,_e('hour' , 'write-time'),$show_min_time,_e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
     211            } else{
     212                echo $show_sec_time,_e('second' , 'write-time');
     213            }
     214    echo '</td></tr>';
     215
     216    $count++;
     217    endwhile;
     218    echo '</table>';
     219   
     220    $show_hor_time = floor($total_count / 3600);
     221    $show_min_time = floor($total_count / 60);
     222    $show_min_time = $total_count % 60;
     223    $show_sec_time = $total_count % 60;
     224
     225    // 総合情報
     226    echo '<p>ALL article' , $count , '</p>';
     227    echo '<p>ALL write time';
     228    if( $total_count > 60 && $total_count < 3600){
     229                echo $show_min_time, _e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
     230            } elseif( $total_count > 3600){
     231                echo $show_hor_time,_e('hour' , 'write-time'),$show_min_time,_e('minute' , 'write-time'),$show_sec_time,_e('second' , 'write-time');
     232            } else{
     233                echo $show_sec_time,_e('second' , 'write-time');
     234            }
     235    echo '</p><br>';
     236    wp_reset_query();
     237
     238   
     239}
     240
     241
     242
     243
     244
     245
     246
     247
     248
     249
     250
    134251?>
Note: See TracChangeset for help on using the changeset viewer.