Plugin Directory

Changeset 1466742


Ignore:
Timestamp:
08/03/2016 09:28:13 AM (10 years ago)
Author:
O-Zone
Message:

version 0.7.0

Location:
wp-allaround
Files:
3 added
3 deleted
5 edited
12 copied

Legend:

Unmodified
Added
Removed
  • wp-allaround/tags/0.7.0/README.txt

    r1462090 r1466742  
    55Requires at least: 4.0.0
    66Tested up to: 4.6.0
    7 Stable tag: 0.6
     7Stable tag: 0.7.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3636== Changelog ==
    3737
     38= 0.7.0 =
     39* A lot of bug fixes: now plugin works as expected
     40* Added error messages display when post publish fail
     41* Minor code cleanups
     42
    3843= 0.6 =
    3944* Plugin internationalization now works
  • wp-allaround/tags/0.7.0/css/wp-allaround.css

    r1462090 r1466742  
     1
    12.allaround-score-icon.na {
    2     background-color: #888;
     3    background-color:#888888;
    34}
    45
    5 .allaround-score-icon.error {
    6     background-color: #dc3232;
     6.allaround-score-icon.iserror {
     7    background-color:#dc3232;
    78}
    89
    910.allaround-score-icon.published {
    10     background-color:#7ad03a
     11    background-color:#7ad03a;
    1112}
    1213
  • wp-allaround/tags/0.7.0/wp-allaround-admin.php

    r1462090 r1466742  
    100100                    </tr><tr>
    101101                    <td>
    102                         <input type="submit" value="<?php _e('Submit'); ?>>
     102                        <input type="submit" value="<?php _e('Submit'); ?>">
    103103                    </td>
    104104                    </tr>
  • wp-allaround/tags/0.7.0/wp-allaround.php

    r1464978 r1466742  
    44Plugin URI:     http://www.allaroundsiena.com/plugin
    55Description:    This plugin let you to connect a Telegram Bot with your blog
    6 Version:    0.6
     6Version:    0.7.0
    77Author:     Michele Pinassi
    88Author URI: http://www.zerozone.it
     
    6363function allaround_metabox_callback( $post, $metabox ) {
    6464
    65     $check_is_publish = get_post_meta($post->ID,'allaround_post_publish', true);
    66 
    67     if($check_is_publish) {
    68     $publish_date = get_post_meta($post->ID, 'allaround_post_publish_date', true);
    69 
    70     $t_date = date_i18n( get_option( 'date_format' ),strtotime($publish_date));
    71 
    72     $string = sprintf( __('Post published on %s', 'wp-allaround'), $t_date);
    73 
    74     echo $string;
     65    $post_status = get_post_meta($post->ID,'allaround_post_status', true);
     66    $post_date = get_post_meta($post->ID, 'allaround_post_date', true);
     67    $post_message = get_post_meta($post->ID,'allaround_post_message', true);
     68
     69    $t_date = date_i18n( get_option( 'date_format' ),strtotime($post_date));
     70
     71    if($post_status == 'published') {
     72    printf( __('Post published on %s', 'wp-allaround'), $t_date);
    7573    } else {
    76     echo __("This post was not published on AllAround",'wp-allaround');
    77 ?>
    78     <p>
    79         <input type="checkbox" name="allaround_post_do_publish" id="allaround_post_do_publish" value="1" checked/>
    80         <label class="description" for="allaround_post_do_publish"><?php _e('Publish this post on AllAround', 'wp-allaround' ); ?></label>
    81     </p>
    82 <?php
     74    if($post_status == 'error') { /* Error */
     75        printf( __('Error %s while publishing on %s', 'wp-allaround'), $post_message, $t_date);
     76?>
     77        <p>
     78        <input type="checkbox" name="allaround_post_do_publish" id="allaround_post_do_publish" value="1"/>
     79        <label class="description" for="allaround_post_do_publish"><?php _e('Try again', 'wp-allaround' ); ?></label>
     80        </p>
     81<?php
     82
     83    } else {
     84        echo __("This post was not published on AllAround",'wp-allaround');
     85?>
     86        <p>
     87        <input type="checkbox" name="allaround_post_do_publish" id="allaround_post_do_publish" value="1" checked/>
     88        <label class="description" for="allaround_post_do_publish"><?php _e('Publish this post on AllAround', 'wp-allaround' ); ?></label>
     89        </p>
     90<?php
     91    }
    8392    }
    8493}
     
    93102function allaround_display_column( $column, $post_id ) {
    94103    if ($column == 'allaround'){
    95     /* Check if this post was already published to avoid duplicates */
    96     $is_publish = get_post_meta($post_id,'allaround_post_publish', true);
    97 ?>
    98     <div aria-hidden="true" title="" class="allaround-score-icon <?php echo ($is_publish ? "published" : "na"); ?>"></div><span class="screen-reader-text"><?php echo ($is_publish ? __("Published") : __("Not published")); ?></span></td>
     104    $post_status = get_post_meta($post_id,'allaround_post_status', true);
     105
     106    switch($post_status) {
     107        case "error":
     108        $icon_status = "iserror";
     109        break;
     110        case "published":
     111        $icon_status = "published";
     112        break;
     113        default:
     114        $icon_status = "na";
     115        break;
     116    }   
     117?>
     118        <div aria-hidden="true" title="AllAround Post Status" class="allaround-score-icon <?php echo $icon_status; ?>"></div><span class="screen-reader-text"><?php echo $publish_status; ?></span></td>
    99119<?php
    100120    }
     
    183203    error_log(print_r($result, true));
    184204
    185     return $result->code;
    186     }
    187 }
    188 
    189 add_action('publish_post','allaround_action_publish',10,2);
    190 
    191 function allaround_action_publish($ID, $post) {
    192     /* Check if this post was already published to avoid duplicates */
    193     $check_is_publish = get_post_meta($post->ID,'allaround_post_publish', true);
    194 
    195     if($check_is_publish) {
    196     $do_publish = false;
    197     } else {
    198     $do_publish = false;
    199    
    200     if(isset($_POST['allaround_post_do_publish'])) {
    201             $do_publish = true;
    202     }
    203     }
    204    
     205    /*  [code] => 403
     206        [raw_body] => {
     207        "error": {
     208                "code": 403,
     209                "message": "Error: this POST seems to be a duplicate"
     210            }
     211    */
     212
     213    return $result;
     214    }
     215}
     216
     217/* ============================================================ */
     218/*                              */
     219/* PUBLISH HOOK                         */
     220/*                              */
     221/* =============================================================*/
     222
     223function allaround_action_publish($new_status, $old_status, $post) {
     224    $do_publish = false;
     225
     226    error_log("FIRED: allaround_action_publish($new_status,$old_status,$post->ID)");
     227
     228    if ($new_status == 'publish') {
     229
     230    /* Check if this post was already published to avoid duplicates */
     231    $post_status = get_post_meta($post->ID,'allaround_post_status', true);
     232
     233    if($post_status == 'published') {
     234        /* If already published, do nothing... */
     235    } else {
     236        if(isset($_POST['allaround_post_do_publish'])) {
     237            $do_publish = true;
     238        }
     239    }
     240    }
     241
    205242    /* Need to publish ? */
    206243    if($do_publish) {
     
    208245    $result = allaround_do_publish($post);
    209246
    210     if($result == "200") { /* Success */
    211         $post_publish_date = current_time('mysql');
    212 
    213         update_post_meta($post->ID, "allaround_post_publish",true);
    214         update_post_meta($post->ID, "allaround_post_publish_date","$post_publish_date");
    215 
     247    $post_date = current_time('mysql');
     248
     249    $post_result = json_decode($result->raw_body,true);
     250
     251    error_log(print_r($post_result, true));
     252
     253    if(isset($post_result['error'])) {
     254        $post_result_code = $result->code;
     255        $post_result_message = $post_result['error']['message'];
     256        $post_is_published = false;
     257    } else {
     258        $post_result_code = $result->code;
     259        $post_result_message = $post_result['success'];
     260        $post_is_published = true;
     261    }
     262
     263    update_post_meta($post->ID, "allaround_post_date","$post_date");
     264    update_post_meta($post->ID, "allaround_post_message", $post_result_message);
     265
     266    if($post_is_published) { /* Success */
     267        update_post_meta($post->ID, "allaround_post_status","published");
    216268        add_action( 'admin_notices', 'allaround_notice_publish_success' );
    217269    } else {
    218         update_post_meta($post->ID, "allaround_post_publish",false);
     270        update_post_meta($post->ID, "allaround_post_status","error");
    219271        add_action( 'admin_notices', 'allaround_notice_publish_error' );
    220272    }
    221     } else {
    222     update_post_meta($post->ID, "allaround_post_publish",false);
    223     }
    224 }
     273    }
     274}
     275
     276add_action('transition_post_status', 'allaround_action_publish', 10, 3);
     277
     278/* ============================================================ */
     279/*                              */
     280/* NOTICES                          */
     281/*                              */
     282/* =============================================================*/
     283
    225284
    226285function allaround_notice_publish_success() {
    227286?>
    228     <div class="updated notice">
    229     <p><?php _e('Post published successfully on your BOT !', 'wp-allaround' ); ?></p>
     287    <div class='notice notice-success'>
     288    <p><?php _e('Post published successfully on AllAround !', 'wp-allaround' ); ?></p>
    230289    </div>
    231290<?php
     
    234293function allaround_notice_publish_error() {
    235294?>
    236     <div class="error notice">
    237     <p><?php _e('Ooops ! Something wrong happens while publish your post on AllAround BOT: try again in few minutes', 'wp-allaround' ); ?></p>
     295    <div class='notice notice-error'>
     296    <p><?php _e('Ooops ! Something wrong happens while publish your post on AllAround: try again in few minutes', 'wp-allaround' ); ?></p>
    238297    </div>
    239298<?php
  • wp-allaround/trunk/README.txt

    r1462090 r1466742  
    55Requires at least: 4.0.0
    66Tested up to: 4.6.0
    7 Stable tag: 0.6
     7Stable tag: 0.7.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3636== Changelog ==
    3737
     38= 0.7.0 =
     39* A lot of bug fixes: now plugin works as expected
     40* Added error messages display when post publish fail
     41* Minor code cleanups
     42
    3843= 0.6 =
    3944* Plugin internationalization now works
  • wp-allaround/trunk/css/wp-allaround.css

    r1462090 r1466742  
     1
    12.allaround-score-icon.na {
    2     background-color: #888;
     3    background-color:#888888;
    34}
    45
    5 .allaround-score-icon.error {
    6     background-color: #dc3232;
     6.allaround-score-icon.iserror {
     7    background-color:#dc3232;
    78}
    89
    910.allaround-score-icon.published {
    10     background-color:#7ad03a
     11    background-color:#7ad03a;
    1112}
    1213
  • wp-allaround/trunk/wp-allaround-admin.php

    r1462090 r1466742  
    100100                    </tr><tr>
    101101                    <td>
    102                         <input type="submit" value="<?php _e('Submit'); ?>>
     102                        <input type="submit" value="<?php _e('Submit'); ?>">
    103103                    </td>
    104104                    </tr>
  • wp-allaround/trunk/wp-allaround.php

    r1464978 r1466742  
    44Plugin URI:     http://www.allaroundsiena.com/plugin
    55Description:    This plugin let you to connect a Telegram Bot with your blog
    6 Version:    0.6
     6Version:    0.7.0
    77Author:     Michele Pinassi
    88Author URI: http://www.zerozone.it
     
    6363function allaround_metabox_callback( $post, $metabox ) {
    6464
    65     $check_is_publish = get_post_meta($post->ID,'allaround_post_publish', true);
    66 
    67     if($check_is_publish) {
    68     $publish_date = get_post_meta($post->ID, 'allaround_post_publish_date', true);
    69 
    70     $t_date = date_i18n( get_option( 'date_format' ),strtotime($publish_date));
    71 
    72     $string = sprintf( __('Post published on %s', 'wp-allaround'), $t_date);
    73 
    74     echo $string;
     65    $post_status = get_post_meta($post->ID,'allaround_post_status', true);
     66    $post_date = get_post_meta($post->ID, 'allaround_post_date', true);
     67    $post_message = get_post_meta($post->ID,'allaround_post_message', true);
     68
     69    $t_date = date_i18n( get_option( 'date_format' ),strtotime($post_date));
     70
     71    if($post_status == 'published') {
     72    printf( __('Post published on %s', 'wp-allaround'), $t_date);
    7573    } else {
    76     echo __("This post was not published on AllAround",'wp-allaround');
    77 ?>
    78     <p>
    79         <input type="checkbox" name="allaround_post_do_publish" id="allaround_post_do_publish" value="1" checked/>
    80         <label class="description" for="allaround_post_do_publish"><?php _e('Publish this post on AllAround', 'wp-allaround' ); ?></label>
    81     </p>
    82 <?php
     74    if($post_status == 'error') { /* Error */
     75        printf( __('Error %s while publishing on %s', 'wp-allaround'), $post_message, $t_date);
     76?>
     77        <p>
     78        <input type="checkbox" name="allaround_post_do_publish" id="allaround_post_do_publish" value="1"/>
     79        <label class="description" for="allaround_post_do_publish"><?php _e('Try again', 'wp-allaround' ); ?></label>
     80        </p>
     81<?php
     82
     83    } else {
     84        echo __("This post was not published on AllAround",'wp-allaround');
     85?>
     86        <p>
     87        <input type="checkbox" name="allaround_post_do_publish" id="allaround_post_do_publish" value="1" checked/>
     88        <label class="description" for="allaround_post_do_publish"><?php _e('Publish this post on AllAround', 'wp-allaround' ); ?></label>
     89        </p>
     90<?php
     91    }
    8392    }
    8493}
     
    93102function allaround_display_column( $column, $post_id ) {
    94103    if ($column == 'allaround'){
    95     /* Check if this post was already published to avoid duplicates */
    96     $is_publish = get_post_meta($post_id,'allaround_post_publish', true);
    97 ?>
    98     <div aria-hidden="true" title="" class="allaround-score-icon <?php echo ($is_publish ? "published" : "na"); ?>"></div><span class="screen-reader-text"><?php echo ($is_publish ? __("Published") : __("Not published")); ?></span></td>
     104    $post_status = get_post_meta($post_id,'allaround_post_status', true);
     105
     106    switch($post_status) {
     107        case "error":
     108        $icon_status = "iserror";
     109        break;
     110        case "published":
     111        $icon_status = "published";
     112        break;
     113        default:
     114        $icon_status = "na";
     115        break;
     116    }   
     117?>
     118        <div aria-hidden="true" title="AllAround Post Status" class="allaround-score-icon <?php echo $icon_status; ?>"></div><span class="screen-reader-text"><?php echo $publish_status; ?></span></td>
    99119<?php
    100120    }
     
    183203    error_log(print_r($result, true));
    184204
    185     return $result->code;
    186     }
    187 }
    188 
    189 add_action('publish_post','allaround_action_publish',10,2);
    190 
    191 function allaround_action_publish($ID, $post) {
    192     /* Check if this post was already published to avoid duplicates */
    193     $check_is_publish = get_post_meta($post->ID,'allaround_post_publish', true);
    194 
    195     if($check_is_publish) {
    196     $do_publish = false;
    197     } else {
    198     $do_publish = false;
    199    
    200     if(isset($_POST['allaround_post_do_publish'])) {
    201             $do_publish = true;
    202     }
    203     }
    204    
     205    /*  [code] => 403
     206        [raw_body] => {
     207        "error": {
     208                "code": 403,
     209                "message": "Error: this POST seems to be a duplicate"
     210            }
     211    */
     212
     213    return $result;
     214    }
     215}
     216
     217/* ============================================================ */
     218/*                              */
     219/* PUBLISH HOOK                         */
     220/*                              */
     221/* =============================================================*/
     222
     223function allaround_action_publish($new_status, $old_status, $post) {
     224    $do_publish = false;
     225
     226    error_log("FIRED: allaround_action_publish($new_status,$old_status,$post->ID)");
     227
     228    if ($new_status == 'publish') {
     229
     230    /* Check if this post was already published to avoid duplicates */
     231    $post_status = get_post_meta($post->ID,'allaround_post_status', true);
     232
     233    if($post_status == 'published') {
     234        /* If already published, do nothing... */
     235    } else {
     236        if(isset($_POST['allaround_post_do_publish'])) {
     237            $do_publish = true;
     238        }
     239    }
     240    }
     241
    205242    /* Need to publish ? */
    206243    if($do_publish) {
     
    208245    $result = allaround_do_publish($post);
    209246
    210     if($result == "200") { /* Success */
    211         $post_publish_date = current_time('mysql');
    212 
    213         update_post_meta($post->ID, "allaround_post_publish",true);
    214         update_post_meta($post->ID, "allaround_post_publish_date","$post_publish_date");
    215 
     247    $post_date = current_time('mysql');
     248
     249    $post_result = json_decode($result->raw_body,true);
     250
     251    error_log(print_r($post_result, true));
     252
     253    if(isset($post_result['error'])) {
     254        $post_result_code = $result->code;
     255        $post_result_message = $post_result['error']['message'];
     256        $post_is_published = false;
     257    } else {
     258        $post_result_code = $result->code;
     259        $post_result_message = $post_result['success'];
     260        $post_is_published = true;
     261    }
     262
     263    update_post_meta($post->ID, "allaround_post_date","$post_date");
     264    update_post_meta($post->ID, "allaround_post_message", $post_result_message);
     265
     266    if($post_is_published) { /* Success */
     267        update_post_meta($post->ID, "allaround_post_status","published");
    216268        add_action( 'admin_notices', 'allaround_notice_publish_success' );
    217269    } else {
    218         update_post_meta($post->ID, "allaround_post_publish",false);
     270        update_post_meta($post->ID, "allaround_post_status","error");
    219271        add_action( 'admin_notices', 'allaround_notice_publish_error' );
    220272    }
    221     } else {
    222     update_post_meta($post->ID, "allaround_post_publish",false);
    223     }
    224 }
     273    }
     274}
     275
     276add_action('transition_post_status', 'allaround_action_publish', 10, 3);
     277
     278/* ============================================================ */
     279/*                              */
     280/* NOTICES                          */
     281/*                              */
     282/* =============================================================*/
     283
    225284
    226285function allaround_notice_publish_success() {
    227286?>
    228     <div class="updated notice">
    229     <p><?php _e('Post published successfully on your BOT !', 'wp-allaround' ); ?></p>
     287    <div class='notice notice-success'>
     288    <p><?php _e('Post published successfully on AllAround !', 'wp-allaround' ); ?></p>
    230289    </div>
    231290<?php
     
    234293function allaround_notice_publish_error() {
    235294?>
    236     <div class="error notice">
    237     <p><?php _e('Ooops ! Something wrong happens while publish your post on AllAround BOT: try again in few minutes', 'wp-allaround' ); ?></p>
     295    <div class='notice notice-error'>
     296    <p><?php _e('Ooops ! Something wrong happens while publish your post on AllAround: try again in few minutes', 'wp-allaround' ); ?></p>
    238297    </div>
    239298<?php
Note: See TracChangeset for help on using the changeset viewer.