Changeset 1461999
- Timestamp:
- 07/28/2016 08:07:58 AM (10 years ago)
- Location:
- wp-allaround/trunk
- Files:
-
- 3 edited
-
README.txt (modified) (4 diffs)
-
wp-allaround-admin.php (modified) (3 diffs)
-
wp-allaround.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-allaround/trunk/README.txt
r1456305 r1461999 5 5 Requires at least: 4.0.0 6 6 Tested up to: 4.5.3 7 Stable tag: 0. 47 Stable tag: 0.5 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 14 14 15 15 WP-AllAround is the connector plugin for AllAroundSiena Telegram Bot service, that let you to spread via Telegram channels new posts of your blog. 16 To connect your blog to the Telegram Channel, you simply need an API key to get freely on http://www.allaroundsiena.com /.16 To connect your blog to the Telegram Channel, you simply need an API key to get freely on http://www.allaroundsiena.com 17 17 18 18 == Installation == … … 20 20 1. Upload the plugin files to the `/wp-content/plugins/` directory, or install the plugin through the WordPress plugins screen directly. 21 21 2. Activate the plugin through the 'Plugins' screen in WordPress 22 3. Use the Settings->AllAround Options screen to configure the plugins and add the AllAround API key (get for free on www.allaroundsiena.com /bot)22 3. Use the Settings->AllAround Options screen to configure the plugins and add the AllAround API key (get for free on www.allaroundsiena.com) 23 23 4. Click on "Connect this blog" button to validate the API key and connect your blog to the AllAroundSiena Telegram Bot service 24 5. You're done ! Now you need to create you Telegram Channel and configure it as explained on http://www.allaroundsiena.com /pages24 5. You're done ! Now you need to create you Telegram Channel and configure it as explained on http://www.allaroundsiena.com pages 25 25 26 26 == Frequently Asked Questions == … … 32 32 = How does it costs ? = 33 33 34 The "blog plan" it's f or free: 1 blog and 1 post every 12 hours free...for ever !34 The "blog plan" it's free, forever, and include 1 blog and 1 post every 12 hours. 35 35 36 36 == Changelog == 37 38 = 0.5 = 39 * Minor bug fixes 37 40 38 41 = 0.4 = -
wp-allaround/trunk/wp-allaround-admin.php
r1453957 r1461999 86 86 <label class="description" for="allaround_api_key"><?php _e('Type here your AllAround BOT Api Key', 'wp-allaround' ); ?></label> 87 87 </td> 88 </tr><tr><th scope="row"><?php _e('Default is to publish new articles', 'wp-allaround' ); ?></th> 89 <td> 90 <input type="checkbox" name="allaround_default_publish" id="allaround_default_publish" checked> 91 </td> 92 </tr> 88 93 </tr><tr> 89 94 <td> … … 96 101 </div> <!-- end post-body --> 97 102 </div> <!-- end poststuff --> 103 <?php 104 $option_api_key = get_option( 'allaround_api_key' ); 105 if(isset($option_api_key)) { 106 ?> 107 98 108 <div> 99 <p><?php echo _e('After setting BOT Api Key (get one for free at <a href=\'http://www.allaroundsiena.com\'>www.allaroundsiena.com</a>) click on the following button to start broadcasting:'); ?></p>109 <p><?php _e("Click on the following button to connect this blog and start broadcasting:"); ?></p> 100 110 <button class="btn btn-large" id="allaround_connect"><?php _e('Connect this blog', 'wp-allaround'); ?></button> 101 111 <span id="allaround_connect_result"> </span> … … 103 113 </div> 104 114 <?php 115 } 116 ?> 117 <p> 118 <?php _e("Before you start, please visit <a href='http://www.allaroundsiena.com'>allaroundsiena.com</a> to get an API key for your blog"); ?> 119 </p> 120 <?php 105 121 } 106 122 ?> -
wp-allaround/trunk/wp-allaround.php
r1456305 r1461999 4 4 Plugin URI: http://www.allaroundsiena.com/plugin 5 5 Description: This plugin let you to connect a Telegram Bot with your blog 6 Version: 0. 46 Version: 0.5 7 7 Author: Michele Pinassi 8 8 Author URI: http://www.zerozone.it … … 63 63 if($check_is_publish) { 64 64 $publish_date = get_post_meta($post->ID, 'allaround_post_publish_date', true); 65 echo _("Post published"); 65 66 $t_date = date_i18n( get_option( 'date_format' ),strtotime($publish_date)); 67 68 $string = sprintf( __('Post published on %s', 'wp-allaround'), $t_date); 69 70 echo $string; 66 71 } else { 67 echo _("This post was not published on AllAround"); 68 } 69 70 if(!isset($check_is_publish)) { 71 $check_is_publish = true; /* Default action is PUBLISH */ 72 } 72 echo __("This post was not published on AllAround",'wp-allaround'); 73 73 ?> 74 <p> 75 <input type="checkbox" name="allaround_post_publish" id="allaround_post_publish" <?php checked($check_is_publish); ?> /> 76 <label class="description" for="allaround_post_publish"><?php _e('Publish this post on AllAround', 'wp-allaround' ); ?></label> 77 </p> 78 <?php 74 <p> 75 <input type="checkbox" name="allaround_post_publish" id="allaround_post_publish" checked /> 76 <label class="description" for="allaround_post_publish"><?php _e('Publish this post on AllAround', 'wp-allaround' ); ?></label> 77 </p> 78 <?php 79 } 79 80 } 80 81 … … 101 102 } 102 103 104 function allaround_do_publish($post) { 105 $option_api_key = get_option( 'allaround_api_key' ); 106 107 // if(($option_api_key) && ('publish' === $new_status && 'publish' !== $old_status)) { 108 109 if($option_api_key) { 110 /* Get the post properties */ 111 112 $author = $post->post_author; 113 114 $post_title = $post->post_title; 115 $post_excerpt = allaround_excerpt($post->post_content); 116 $post_author = get_the_author_meta('display_name', $author); 117 $post_date = $post->post_date_gmt; 118 $post_url = get_permalink($post->ID); 119 /* Post have an image ? */ 120 if(has_post_thumbnail($post->ID)) { 121 $post_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium')[0]; 122 } else { 123 $post_image_url = ''; 124 } 125 126 /* Get post TAGS */ 127 $tags_array = array(); 128 $tags = wp_get_post_tags($post->ID); 129 130 foreach($tags as $tag) { 131 $tags_array[] = $tag->name; 132 } 133 134 $post_tags = implode(",",$tags_array); 135 136 /* Build REST query */ 137 138 $data = array('key' => $option_api_key, 139 'title' => $post_title, 140 'excerpt' => $post_excerpt, 141 'author' => $post_author, 142 'date' => $post_date, 143 'image_url' => $post_image_url, 144 'tags' => $post_tags, 145 'url' => $post_url, 146 ); 147 148 $headers = array('Accept' => 'application/json'); 149 150 $body = Unirest\Request\Body::multipart($data); 151 152 error_log(print_r($body, true)); 153 154 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/publish', $headers, $body); 155 error_log(print_r($result, true)); 156 157 return $result->code; 158 } 159 } 160 103 161 add_action('transition_post_status', 'allaround_post_publish', 10, 3); 104 162 … … 107 165 /* Check if this post was already published to avoid duplicates */ 108 166 $check_is_publish = get_post_meta($post->ID,'allaround_post_publish', true); 109 167 110 168 if($check_is_publish) { 111 $ is_publish = false;169 $do_publish = false; 112 170 } else { 113 $is_publish = $_POST['allaround_post_publish']; 171 $do_publish = false; 172 173 if(isset($_POST['allaround_post_publish'])) { 174 $do_publish = true; 175 } 114 176 } 115 177 116 if($is_publish) { 117 $option_api_key = get_option( 'allaround_api_key' ); 118 119 if(($option_api_key) && ('publish' === $new_status && 'publish' !== $old_status)) { 120 121 /* Get the post properties */ 122 123 $author = $post->post_author; 124 125 $post_title = $post->post_title; 126 $post_excerpt = allaround_excerpt($post->post_content); 127 $post_author = get_the_author_meta('display_name', $author); 128 $post_date = $post->post_date_gmt; 129 $post_url = get_permalink($post->ID); 130 131 /* Post have an image ? */ 132 if(has_post_thumbnail($post->ID)) { 133 $post_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium')[0]; 134 } else { 135 $post_image_url = ''; 136 } 137 138 /* Get post TAGS */ 139 $tags_array = array(); 140 $tags = wp_get_post_tags($post->ID); 141 142 foreach($tags as $tag) { 143 $tags_array[] = $tag->name; 144 } 145 146 $post_tags = implode(",",$tags_array); 147 148 /* Build REST query */ 149 150 $data = array('key' => $option_api_key, 151 'title' => $post_title, 152 'excerpt' => $post_excerpt, 153 'author' => $post_author, 154 'date' => $post_date, 155 'image_url' => $post_image_url, 156 'tags' => $post_tags, 157 'url' => $post_url, 158 ); 159 160 $headers = array('Accept' => 'application/json'); 161 162 $body = Unirest\Request\Body::multipart($data); 163 164 error_log(print_r($body, true)); 165 166 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/publish', $headers, $body); 167 168 error_log(print_r($result, true)); 169 170 /* Got the result */ 171 172 if($result->code == "200") { /* Success */ 173 174 $post_publish_date = current_time('mysql'); 175 176 update_post_meta($post->ID, "allaround_post_publish",true); 177 update_post_meta($post->ID, "allaround_post_publish_date","$post_publish_date"); 178 179 add_action( 'admin_notices', 'allaround_notice_publish_success' ); 180 } else { 181 update_post_meta($post->ID, "allaround_post_publish",false); 182 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 183 } 178 /* Need to publish ? */ 179 if($do_publish) { 180 /* Publish and get the result */ 181 $result = allaround_do_publish($post); 182 183 if($result == "200") { /* Success */ 184 $post_publish_date = current_time('mysql'); 185 186 update_post_meta($post->ID, "allaround_post_publish",true); 187 update_post_meta($post->ID, "allaround_post_publish_date","$post_publish_date"); 188 189 add_action( 'admin_notices', 'allaround_notice_publish_success' ); 190 } else { 191 update_post_meta($post->ID, "allaround_post_publish",false); 192 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 184 193 } 185 194 } else {
Note: See TracChangeset
for help on using the changeset viewer.