Changeset 1517333
- Timestamp:
- 10/18/2016 01:08:18 PM (9 years ago)
- Location:
- wp-allaround
- Files:
-
- 8 added
- 6 deleted
- 3 edited
- 26 copied
-
tags/0.8.0 (copied) (copied from wp-allaround/trunk)
-
tags/0.8.0/LICENSE.txt (copied) (copied from wp-allaround/trunk/LICENSE.txt)
-
tags/0.8.0/README.txt (copied) (copied from wp-allaround/trunk/README.txt) (3 diffs)
-
tags/0.8.0/Unirest (copied) (copied from wp-allaround/trunk/Unirest)
-
tags/0.8.0/Unirest.php (copied) (copied from wp-allaround/trunk/Unirest.php)
-
tags/0.8.0/css (copied) (copied from wp-allaround/trunk/css)
-
tags/0.8.0/css/wp-allaround.css (copied) (copied from wp-allaround/trunk/css/wp-allaround.css)
-
tags/0.8.0/js (copied) (copied from wp-allaround/trunk/js)
-
tags/0.8.0/languages (copied) (copied from wp-allaround/trunk/languages)
-
tags/0.8.0/languages/default.mo (deleted)
-
tags/0.8.0/languages/default.po (deleted)
-
tags/0.8.0/languages/default.pot (deleted)
-
tags/0.8.0/languages/wp-allaround-it_IT.mo (copied) (copied from wp-allaround/trunk/languages/wp-allaround-it_IT.mo)
-
tags/0.8.0/languages/wp-allaround-it_IT.po (copied) (copied from wp-allaround/trunk/languages/wp-allaround-it_IT.po)
-
tags/0.8.0/trunk (copied) (copied from wp-allaround/trunk)
-
tags/0.8.0/trunk/LICENSE.txt (copied) (copied from wp-allaround/trunk/LICENSE.txt)
-
tags/0.8.0/trunk/README.txt (copied) (copied from wp-allaround/trunk/README.txt) (3 diffs)
-
tags/0.8.0/trunk/Unirest (copied) (copied from wp-allaround/trunk/Unirest)
-
tags/0.8.0/trunk/Unirest.php (copied) (copied from wp-allaround/trunk/Unirest.php)
-
tags/0.8.0/trunk/css (copied) (copied from wp-allaround/trunk/css)
-
tags/0.8.0/trunk/css/validationEngine.jquery.css (added)
-
tags/0.8.0/trunk/css/wp-allaround.css (copied) (copied from wp-allaround/trunk/css/wp-allaround.css)
-
tags/0.8.0/trunk/js (copied) (copied from wp-allaround/trunk/js)
-
tags/0.8.0/trunk/js/custom.js (added)
-
tags/0.8.0/trunk/js/jquery.validationEngine-it.js (added)
-
tags/0.8.0/trunk/js/jquery.validationEngine.js (added)
-
tags/0.8.0/trunk/languages (copied) (copied from wp-allaround/trunk/languages)
-
tags/0.8.0/trunk/languages/default.mo (deleted)
-
tags/0.8.0/trunk/languages/default.po (deleted)
-
tags/0.8.0/trunk/languages/default.pot (deleted)
-
tags/0.8.0/trunk/languages/wp-allaround-it_IT.mo (copied) (copied from wp-allaround/trunk/languages/wp-allaround-it_IT.mo)
-
tags/0.8.0/trunk/languages/wp-allaround-it_IT.po (copied) (copied from wp-allaround/trunk/languages/wp-allaround-it_IT.po)
-
tags/0.8.0/trunk/wp-allaround-admin.php (copied) (copied from wp-allaround/trunk/wp-allaround-admin.php) (5 diffs)
-
tags/0.8.0/trunk/wp-allaround.php (copied) (copied from wp-allaround/trunk/wp-allaround.php) (7 diffs)
-
tags/0.8.0/wp-allaround-admin.php (copied) (copied from wp-allaround/trunk/wp-allaround-admin.php) (5 diffs)
-
tags/0.8.0/wp-allaround.php (copied) (copied from wp-allaround/trunk/wp-allaround.php) (7 diffs)
-
trunk/README.txt (modified) (3 diffs)
-
trunk/css/validationEngine.jquery.css (added)
-
trunk/js/custom.js (added)
-
trunk/js/jquery.validationEngine-it.js (added)
-
trunk/js/jquery.validationEngine.js (added)
-
trunk/wp-allaround-admin.php (modified) (5 diffs)
-
trunk/wp-allaround.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-allaround/tags/0.8.0/README.txt
r1467486 r1517333 5 5 Requires at least: 4.0.0 6 6 Tested up to: 4.6.0 7 Stable tag: 0. 7.17 Stable tag: 0.8.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 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)23 4. Click on "Connect this blog" button to validate the API key and connect your blog to the AllAroundSiena Telegram Bot service22 3. Use the Settings->AllAround Options screen to configure the plugins and register your blog on AllAroundSiena.com 23 4. Wait for validation e-mail in your mailbox and follow the istructions 24 24 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 … … 35 35 36 36 == Changelog == 37 38 = 0.8.0 = 39 * Now you can register your blog directly from plugin, after installation 40 * Code cleanup and bugs fixed 37 41 38 42 = 0.7.1 = -
wp-allaround/tags/0.8.0/trunk/README.txt
r1467486 r1517333 5 5 Requires at least: 4.0.0 6 6 Tested up to: 4.6.0 7 Stable tag: 0. 7.17 Stable tag: 0.8.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 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)23 4. Click on "Connect this blog" button to validate the API key and connect your blog to the AllAroundSiena Telegram Bot service22 3. Use the Settings->AllAround Options screen to configure the plugins and register your blog on AllAroundSiena.com 23 4. Wait for validation e-mail in your mailbox and follow the istructions 24 24 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 … … 35 35 36 36 == Changelog == 37 38 = 0.8.0 = 39 * Now you can register your blog directly from plugin, after installation 40 * Code cleanup and bugs fixed 37 41 38 42 = 0.7.1 = -
wp-allaround/tags/0.8.0/trunk/wp-allaround-admin.php
r1466742 r1517333 1 1 <?php 2 2 /* Only if ADMIN */ 3 4 add_action( 'wp_ajax_connect', 'allaround_action_connect' ); 5 6 function allaround_action_connect() { 3 if(!is_admin()) { 4 wp_die(); 5 } 6 7 /* ============================================================ */ 8 /* */ 9 /* POST */ 10 /* */ 11 /* =============================================================*/ 12 13 add_action( 'admin_post_register', 'allaround_action_register' ); 14 15 function allaround_action_register() { 16 $headers = array('Accept' => 'application/json'); 17 18 // Verify if the nonce is valid 19 if ( !isset($_POST['_mynonce']) || !wp_verify_nonce($_POST['_mynonce'], 'register-user')) { 20 echo "NONCE VERIFICATION FAILED"; 21 } else { 22 $option_api_key = get_option( 'allaround_api_key' ); 23 24 if(!isset($option_api_key)) { 25 $option_api_key = ''; /* No API key */ 26 } 27 28 $blog_name = ($_POST["allaround_blog_name"] ? $_POST["allaround_blog_name"]:get_bloginfo('name')); 29 $blog_description = ($_POST["allaround_blog_description"] ? $_POST["allaround_blog_description"]:get_bloginfo('description')); 30 $blog_admin_email = ($_POST["allaround_admin_email"] ? $_POST["allaround_admin_email"]:get_bloginfo('admin_email')); 31 $blog_language = get_bloginfo('language'); 32 $blog_url = ($_POST["allaround_blog_url"] ? $_POST["allaround_blog_url"]:get_bloginfo('url')); 33 34 $data = array('key' => $option_api_key, 35 'blog_name' => $blog_name, 36 'blog_description' => $blog_description, 37 'blog_admin_email' => $blog_admin_email, 38 'blog_language' => $blog_language, 39 'blog_url' => $blog_url, 40 ); 41 42 $body = Unirest\Request\Body::multipart($data); 43 44 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/register', $headers, $body); 45 46 write_log($result); 47 48 if($result->code == '200') { 49 if(isset($result->body->apikey)) { 50 $api_key = $result->body->apikey; 51 52 update_option('allaround_api_key', $api_key); 53 54 $result = "success"; 55 } else { 56 $result = "fail"; 57 } 58 } else { 59 $result = "fail"; 60 } 61 62 wp_redirect(admin_url("admin.php?page=allaround_options&result=$result")); 63 exit; 64 } 65 wp_die(); 66 } 67 68 add_action( 'admin_post_update', 'allaround_action_update' ); 69 70 function allaround_action_update() { 71 if ( !isset($_POST['_mynonce']) || !wp_verify_nonce($_POST['_mynonce'], 'update')) { 72 echo "NONCE VERIFICATION FAILED"; 73 } else { 74 if(isset($_POST["allaround_default_publish"])) { 75 update_option( 'allaround_default_publish',true); 76 } else { 77 update_option( 'allaround_default_publish',false); 78 } 79 80 $result = 'updated'; 81 82 wp_redirect(admin_url("admin.php?page=allaround_options&result=$result")); 83 exit; 84 } 85 } 86 87 function allaround_enqueue() { 88 global $wp_styles; 89 90 wp_enqueue_script( 'ajax-script', 91 plugins_url( '/js/jquery.validationEngine-it.js', __FILE__ ), 92 array('jquery') 93 ); 94 95 wp_enqueue_script( 'ajax-script', 96 plugins_url( '/js/jquery.validationEngine.js', __FILE__ ), 97 array('jquery') 98 ); 99 100 wp_enqueue_script( 'ajax-script', 101 plugins_url( '/js/custom.js', __FILE__ ), 102 array('jquery') 103 ); 104 105 wp_localize_script( 'ajax-script', 'ajax_object', array( 106 'ajax_url' => admin_url( 'admin-ajax.php' ), 107 )); 108 109 // Load stylesheets 110 wp_enqueue_style( 'wp-allaround', plugins_url( '/css/validationEngine.jquery.css', __FILE__ )); 111 wp_enqueue_style( 'wp-allaround', plugins_url( '/css/wp-allaround.css', __FILE__ )); 112 } 113 114 add_action('admin_enqueue_scripts', 'allaround_enqueue'); 115 116 /* ============================================================ */ 117 /* */ 118 /* AJAX */ 119 /* */ 120 /* =============================================================*/ 121 122 add_action( 'wp_ajax_verify', 'allaround_action_verify' ); 123 124 function allaround_action_verify() { 7 125 global $wpdb; // this is how you get access to the database 8 126 … … 22 140 $body = Unirest\Request\Body::multipart($data); 23 141 24 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/ connect', $headers, $body);142 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/verify', $headers, $body); 25 143 26 144 if($result->code == '200') { … … 34 152 } 35 153 36 function allaround_enqueue() { 37 global $wp_styles; 38 39 wp_enqueue_script( 'ajax-script', 40 plugins_url( '/js/common.js', __FILE__ ), 41 array('jquery') 42 ); 43 44 wp_localize_script( 'ajax-script', 'ajax_object', array( 45 'ajax_url' => admin_url( 'admin-ajax.php' ), 46 )); 47 48 // Load the main stylesheet 49 wp_enqueue_style( 'wp-allaround', plugins_url( '/css/wp-allaround.css', __FILE__ )); 50 } 51 52 add_action('admin_enqueue_scripts', 'allaround_enqueue'); 154 /* ============================================================ */ 155 /* */ 156 /* ADMIN */ 157 /* */ 158 /* =============================================================*/ 53 159 54 160 function allaround_options_menu() { … … 69 175 'allaround_api_key' // setting name 70 176 ); 177 register_setting( 178 'allaround_options', // settings section 179 'allaround_default_ublish' // setting name 180 ); 181 71 182 } 72 183 add_action( 'admin_init', 'allaround_register_settings' ); … … 76 187 $_REQUEST['settings-updated'] = false; 77 188 } 78 ?> 79 <div class="wrap"> 189 settings_fields( 'allaround_options' ); 190 $option_api_key = get_option( 'allaround_api_key' ); 191 $option_default_publish = get_option( 'allaround_default_publish' ); 192 ?> 193 <div class="wrap"><!-- WRAP --> 80 194 <h2><?php echo esc_html( get_admin_page_title() ); ?></h2> 81 82 <div id="poststuff"> 83 <div id="post-body"> 84 <div id="post-body-content"> 85 <form method="post" action="options.php"> 86 <?php settings_fields( 'allaround_options' ); ?> 87 <?php $option_api_key = get_option( 'allaround_api_key' ); ?> 88 <table class="form-table"> 89 <tr valign="top"><th scope="row"><?php _e('Your AllAround BOT Api Key', 'wp-allaround' ); ?></th> 90 <td> 91 <input type="text" name="allaround_api_key" id="allaround_api_key" value="<?php echo $option_api_key; ?>"> 92 <br/> 93 <label class="description" for="allaround_api_key"><?php _e('Type here your AllAround BOT Api Key', 'wp-allaround' ); ?></label> 94 </td> 95 </tr><tr><th scope="row"><?php _e('Default is to publish new articles', 'wp-allaround' ); ?></th> 96 <td> 97 <input type="checkbox" name="allaround_default_publish" id="allaround_default_publish" checked> 98 </td> 99 </tr> 100 </tr><tr> 101 <td> 102 <input type="submit" value="<?php _e('Submit'); ?>"> 103 </td> 104 </tr> 105 </table> 106 </form> 195 <?php 196 if(empty($option_api_key)) { 197 198 if(isset($_REQUEST['result'])) { 199 if($_REQUEST['result'] == 'fail') { 200 ?> 201 <div class='notice notice-error'> 202 <p><?php _e('Ooops ! Something wrong while registering your blog: please try later.', 'wp-allaround' ); ?></p> 203 </div> 204 <?php 205 } else if($_REQUEST['result'] == 'success') { 206 ?> 207 <div class='notice notice-success'> 208 <p><?php _e('Great ! Your BLOG was registered successfully on AllAroundSiena.com: now check your mailbox...', 'wp-allaround' ); ?></p> 209 </div> 210 <?php 211 } 212 } 213 ?> 214 <div> 215 <script> 216 jQuery(document).ready(function($){ 217 jQuery(".validate").validationEngine('attach'); 218 }); 219 </script> 220 <form class="validate" action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post"> 221 <?php echo wp_nonce_field('register-user', '_mynonce'); ?> 222 <input type="hidden" name="action" value="register"> 223 <h3><?php _e('Register your blog on AllAroundSiena.com', 'wp-allaround' ); ?></h3> 224 <p><?php _e('Please check (and fix, if need) the following data, that will be sent to allaroundsiena.com server to register your blog. Check twice Admin e-mail field, because this mailbox will receive 225 credentials to access AllAroundSiena and manage your blog subscriptions'); ?></p> 226 <table class="form-table"> 227 <tr valign="top"> 228 <td> 229 <?php _e('Blog name','wp-allaround');?>: 230 </td><td> 231 <input type="text" name="allaround_blog_name" id="allaround_blog_name" class="validate[required]" value="<?php echo get_bloginfo('name'); ?>"> 232 </td> 233 </tr><tr> 234 <td> 235 <?php _e('Blog description','wp-allaround');?>: 236 </td><td> 237 <input type="text" name="allaround_blog_description" id="allaround_blog_description" class="validate[required]" value="<?php echo get_bloginfo('description'); ?>"> 238 </td> 239 </tr><tr> 240 <td> 241 <?php _e('Admin e-mail','wp-allaround');?>: 242 </td><td> 243 <input type="text" name="allaround_blog_admin" id="allaround_blog_admin" class="validate[required,custom[email]]" value="<?php echo get_bloginfo('admin_email'); ?>"> 244 </td> 245 </tr><tr> 246 <td> 247 <?php _e('Blog URL','wp-allaround');?>: 248 </td><td> 249 <input type="text" name="allaround_blog_url" id="allaround_blog_url" class="validate[required]" value="<?php echo get_bloginfo('url'); ?>"> 250 </td> 251 </tr> 252 </table> 253 <p> 254 <?php _e("By clicking Sign Up, you agree to our <a href='http://www.allaroundsiena.com/legal'>Terms</a>, including data use policy and cookie use"); ?> 255 </p> 256 <input type="submit" class="btn btn-large" id="allaround_register" value="<?php _e('Sign up', 'wp-allaround'); ?>"> 257 </form> 258 </div> 259 <?php 260 } else { 261 if(isset($_REQUEST['result'])) { 262 if($_REQUEST['result'] == 'updated') { 263 ?> 264 <div class='notice notice-success'> 265 <p><?php _e('Options updated !', 'wp-allaround' ); ?></p> 266 </div> 267 <?php 268 } 269 } 270 ?> 271 <div id="poststuff"> 272 <div id="post-body"> 273 <div id="post-body-content"> 274 <table class="form-table"> 275 <tr valign="top"> 276 <th scope="row"><?php _e('Your AllAround BOT Api Key', 'wp-allaround' ); ?></th> 277 <td> 278 <input type="text" name="allaround_api_key" id="allaround_api_key" value="<?php echo $option_api_key; ?>" readonly> 279 <br/> 280 <label class="description" for="allaround_api_key"><?php _e('This is the unique API key for your blog. Please, keep it safe.'); ?></label> 281 </td> 282 </tr><tr> 283 <td> 284 <button class="btn btn-large" id="allaround_verify"><?php _e('Verify connection', 'wp-allaround'); ?></button><span id="allaround_verify_result"> </span> 285 </td> 286 </tr> 287 </table> 288 <form action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post"> 289 <?php echo wp_nonce_field('update', '_mynonce'); ?> 290 <input type="hidden" name="action" value="update"> 291 <table class="form-table"> 292 <tr> 293 <th scope="row"><?php _e('Default is to publish new articles', 'wp-allaround' ); ?></th> 294 <td> 295 <input type="checkbox" name="allaround_default_publish" id="allaround_default_publish" <?php echo ($option_default_publish ? 'checked':''); ?> > 296 </td> 297 </tr><tr> 298 <td> 299 <input type="submit" value="<?php _e('Submit'); ?>"> 300 </td> 301 </tr> 302 </table> 303 </form> 107 304 </div> <!-- end post-body-content --> 108 305 </div> <!-- end post-body --> 109 306 </div> <!-- end poststuff --> 110 <?php 111 $option_api_key = get_option( 'allaround_api_key' ); 112 if(isset($option_api_key)) { 113 ?> 114 115 <div> 116 <p><?php _e("Click on the following button to connect this blog and start broadcasting:"); ?></p> 117 <button class="btn btn-large" id="allaround_connect"><?php _e('Connect this blog', 'wp-allaround'); ?></button> 118 <span id="allaround_connect_result"> </span> 119 </div> 120 </div> 121 <?php 122 } 123 ?> 124 <p> 125 <?php _e("Before you start, please visit <a href='http://www.allaroundsiena.com'>allaroundsiena.com</a> to get an API key for your blog"); ?> 126 </p> 127 <?php 128 } 129 ?> 130 307 <?php 308 } 309 ?> 310 </div><!-- /WRAP --> 311 <?php 312 } 313 ?> -
wp-allaround/tags/0.8.0/trunk/wp-allaround.php
r1467486 r1517333 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. 7.16 Version: 0.8.0 7 7 Author: Michele Pinassi 8 8 Author URI: http://www.zerozone.it … … 24 24 } 25 25 26 if (!function_exists('write_log')) { 27 function write_log ( $log ) { 28 if ( true === WP_DEBUG ) { 29 if ( is_array( $log ) || is_object( $log ) ) { 30 error_log( print_r( $log, true ) ); 31 } else { 32 error_log( $log ); 33 } 34 } 35 } 36 } 37 38 26 39 /* ============================================================ */ 27 40 /* */ … … 34 47 register_deactivation_hook(__FILE__, 'allaround_deactivate'); 35 48 49 add_action( 'activated_plugin', 'allaround_redirect' ); 50 51 function allaround_redirect($plugin) { 52 if($plugin == plugin_basename(__FILE__)) { 53 exit( wp_redirect( admin_url( 'admin.php?page=allaround_options' ) ) ); 54 } 55 } 56 36 57 function allaround_activate() { 37 58 add_option('allaround_api_key',false); 59 add_option('allaround_default_publish',true); 38 60 } 39 61 40 62 function allaround_deactivate() { 41 if(!defined('WP_UNINSTALL_PLUGIN')) { 42 exit(); 43 } 44 63 delete_option('allaround_api_key'); 64 delete_option('allaround_default_publish'); 45 65 } 46 66 … … 153 173 $option_api_key = get_option( 'allaround_api_key' ); 154 174 155 // if(($option_api_key) && ('publish' === $new_status && 'publish' !== $old_status)) {156 157 175 if($option_api_key) { 158 176 /* Get the post properties */ … … 198 216 $body = Unirest\Request\Body::multipart($data); 199 217 200 error_log(print_r($body, true));201 202 218 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/publish', $headers, $body); 203 219 error_log(print_r($result, true)); … … 213 229 return $result; 214 230 } 231 return false; 215 232 } 216 233 … … 245 262 $result = allaround_do_publish($post); 246 263 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 // ERROR ! 255 $post_result_code = $result->code; 256 $post_result_message = $post_result['error']['message']; 257 $post_is_published = false; 258 } else if(isset($post_result['success'])) { 259 // DONE ! 260 $post_result_code = $result->code; 261 $post_result_message = $post_result['success']; 262 $post_is_published = true; 264 if($result) { 265 $post_date = current_time('mysql'); 266 267 $post_result = json_decode($result->raw_body,true); 268 269 error_log(print_r($post_result, true)); 270 271 if(isset($post_result['error'])) { 272 // ERROR ! 273 $post_result_code = $result->code; 274 $post_result_message = $post_result['error']['message']; 275 $post_is_published = false; 276 } else if(isset($post_result['success'])) { 277 // DONE ! 278 $post_result_code = $result->code; 279 $post_result_message = $post_result['success']; 280 $post_is_published = true; 281 } else { 282 // Something wrong with network ? 283 $post_is_published = false; 284 } 285 286 update_post_meta($post->ID, "allaround_post_date","$post_date"); 287 update_post_meta($post->ID, "allaround_post_message", $post_result_message); 288 289 if($post_is_published) { /* Success */ 290 update_post_meta($post->ID, "allaround_post_status","published"); 291 add_action( 'admin_notices', 'allaround_notice_publish_success' ); 292 } else { 293 update_post_meta($post->ID, "allaround_post_status","error"); 294 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 295 } 263 296 } else { 264 // Something wrong with network ? 265 $post_is_published = false; 266 } 267 268 update_post_meta($post->ID, "allaround_post_date","$post_date"); 269 update_post_meta($post->ID, "allaround_post_message", $post_result_message); 270 271 if($post_is_published) { /* Success */ 272 update_post_meta($post->ID, "allaround_post_status","published"); 273 add_action( 'admin_notices', 'allaround_notice_publish_success' ); 274 } else { 275 update_post_meta($post->ID, "allaround_post_status","error"); 276 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 297 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 277 298 } 278 299 } -
wp-allaround/tags/0.8.0/wp-allaround-admin.php
r1466742 r1517333 1 1 <?php 2 2 /* Only if ADMIN */ 3 4 add_action( 'wp_ajax_connect', 'allaround_action_connect' ); 5 6 function allaround_action_connect() { 3 if(!is_admin()) { 4 wp_die(); 5 } 6 7 /* ============================================================ */ 8 /* */ 9 /* POST */ 10 /* */ 11 /* =============================================================*/ 12 13 add_action( 'admin_post_register', 'allaround_action_register' ); 14 15 function allaround_action_register() { 16 $headers = array('Accept' => 'application/json'); 17 18 // Verify if the nonce is valid 19 if ( !isset($_POST['_mynonce']) || !wp_verify_nonce($_POST['_mynonce'], 'register-user')) { 20 echo "NONCE VERIFICATION FAILED"; 21 } else { 22 $option_api_key = get_option( 'allaround_api_key' ); 23 24 if(!isset($option_api_key)) { 25 $option_api_key = ''; /* No API key */ 26 } 27 28 $blog_name = ($_POST["allaround_blog_name"] ? $_POST["allaround_blog_name"]:get_bloginfo('name')); 29 $blog_description = ($_POST["allaround_blog_description"] ? $_POST["allaround_blog_description"]:get_bloginfo('description')); 30 $blog_admin_email = ($_POST["allaround_admin_email"] ? $_POST["allaround_admin_email"]:get_bloginfo('admin_email')); 31 $blog_language = get_bloginfo('language'); 32 $blog_url = ($_POST["allaround_blog_url"] ? $_POST["allaround_blog_url"]:get_bloginfo('url')); 33 34 $data = array('key' => $option_api_key, 35 'blog_name' => $blog_name, 36 'blog_description' => $blog_description, 37 'blog_admin_email' => $blog_admin_email, 38 'blog_language' => $blog_language, 39 'blog_url' => $blog_url, 40 ); 41 42 $body = Unirest\Request\Body::multipart($data); 43 44 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/register', $headers, $body); 45 46 write_log($result); 47 48 if($result->code == '200') { 49 if(isset($result->body->apikey)) { 50 $api_key = $result->body->apikey; 51 52 update_option('allaround_api_key', $api_key); 53 54 $result = "success"; 55 } else { 56 $result = "fail"; 57 } 58 } else { 59 $result = "fail"; 60 } 61 62 wp_redirect(admin_url("admin.php?page=allaround_options&result=$result")); 63 exit; 64 } 65 wp_die(); 66 } 67 68 add_action( 'admin_post_update', 'allaround_action_update' ); 69 70 function allaround_action_update() { 71 if ( !isset($_POST['_mynonce']) || !wp_verify_nonce($_POST['_mynonce'], 'update')) { 72 echo "NONCE VERIFICATION FAILED"; 73 } else { 74 if(isset($_POST["allaround_default_publish"])) { 75 update_option( 'allaround_default_publish',true); 76 } else { 77 update_option( 'allaround_default_publish',false); 78 } 79 80 $result = 'updated'; 81 82 wp_redirect(admin_url("admin.php?page=allaround_options&result=$result")); 83 exit; 84 } 85 } 86 87 function allaround_enqueue() { 88 global $wp_styles; 89 90 wp_enqueue_script( 'ajax-script', 91 plugins_url( '/js/jquery.validationEngine-it.js', __FILE__ ), 92 array('jquery') 93 ); 94 95 wp_enqueue_script( 'ajax-script', 96 plugins_url( '/js/jquery.validationEngine.js', __FILE__ ), 97 array('jquery') 98 ); 99 100 wp_enqueue_script( 'ajax-script', 101 plugins_url( '/js/custom.js', __FILE__ ), 102 array('jquery') 103 ); 104 105 wp_localize_script( 'ajax-script', 'ajax_object', array( 106 'ajax_url' => admin_url( 'admin-ajax.php' ), 107 )); 108 109 // Load stylesheets 110 wp_enqueue_style( 'wp-allaround', plugins_url( '/css/validationEngine.jquery.css', __FILE__ )); 111 wp_enqueue_style( 'wp-allaround', plugins_url( '/css/wp-allaround.css', __FILE__ )); 112 } 113 114 add_action('admin_enqueue_scripts', 'allaround_enqueue'); 115 116 /* ============================================================ */ 117 /* */ 118 /* AJAX */ 119 /* */ 120 /* =============================================================*/ 121 122 add_action( 'wp_ajax_verify', 'allaround_action_verify' ); 123 124 function allaround_action_verify() { 7 125 global $wpdb; // this is how you get access to the database 8 126 … … 22 140 $body = Unirest\Request\Body::multipart($data); 23 141 24 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/ connect', $headers, $body);142 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/verify', $headers, $body); 25 143 26 144 if($result->code == '200') { … … 34 152 } 35 153 36 function allaround_enqueue() { 37 global $wp_styles; 38 39 wp_enqueue_script( 'ajax-script', 40 plugins_url( '/js/common.js', __FILE__ ), 41 array('jquery') 42 ); 43 44 wp_localize_script( 'ajax-script', 'ajax_object', array( 45 'ajax_url' => admin_url( 'admin-ajax.php' ), 46 )); 47 48 // Load the main stylesheet 49 wp_enqueue_style( 'wp-allaround', plugins_url( '/css/wp-allaround.css', __FILE__ )); 50 } 51 52 add_action('admin_enqueue_scripts', 'allaround_enqueue'); 154 /* ============================================================ */ 155 /* */ 156 /* ADMIN */ 157 /* */ 158 /* =============================================================*/ 53 159 54 160 function allaround_options_menu() { … … 69 175 'allaround_api_key' // setting name 70 176 ); 177 register_setting( 178 'allaround_options', // settings section 179 'allaround_default_ublish' // setting name 180 ); 181 71 182 } 72 183 add_action( 'admin_init', 'allaround_register_settings' ); … … 76 187 $_REQUEST['settings-updated'] = false; 77 188 } 78 ?> 79 <div class="wrap"> 189 settings_fields( 'allaround_options' ); 190 $option_api_key = get_option( 'allaround_api_key' ); 191 $option_default_publish = get_option( 'allaround_default_publish' ); 192 ?> 193 <div class="wrap"><!-- WRAP --> 80 194 <h2><?php echo esc_html( get_admin_page_title() ); ?></h2> 81 82 <div id="poststuff"> 83 <div id="post-body"> 84 <div id="post-body-content"> 85 <form method="post" action="options.php"> 86 <?php settings_fields( 'allaround_options' ); ?> 87 <?php $option_api_key = get_option( 'allaround_api_key' ); ?> 88 <table class="form-table"> 89 <tr valign="top"><th scope="row"><?php _e('Your AllAround BOT Api Key', 'wp-allaround' ); ?></th> 90 <td> 91 <input type="text" name="allaround_api_key" id="allaround_api_key" value="<?php echo $option_api_key; ?>"> 92 <br/> 93 <label class="description" for="allaround_api_key"><?php _e('Type here your AllAround BOT Api Key', 'wp-allaround' ); ?></label> 94 </td> 95 </tr><tr><th scope="row"><?php _e('Default is to publish new articles', 'wp-allaround' ); ?></th> 96 <td> 97 <input type="checkbox" name="allaround_default_publish" id="allaround_default_publish" checked> 98 </td> 99 </tr> 100 </tr><tr> 101 <td> 102 <input type="submit" value="<?php _e('Submit'); ?>"> 103 </td> 104 </tr> 105 </table> 106 </form> 195 <?php 196 if(empty($option_api_key)) { 197 198 if(isset($_REQUEST['result'])) { 199 if($_REQUEST['result'] == 'fail') { 200 ?> 201 <div class='notice notice-error'> 202 <p><?php _e('Ooops ! Something wrong while registering your blog: please try later.', 'wp-allaround' ); ?></p> 203 </div> 204 <?php 205 } else if($_REQUEST['result'] == 'success') { 206 ?> 207 <div class='notice notice-success'> 208 <p><?php _e('Great ! Your BLOG was registered successfully on AllAroundSiena.com: now check your mailbox...', 'wp-allaround' ); ?></p> 209 </div> 210 <?php 211 } 212 } 213 ?> 214 <div> 215 <script> 216 jQuery(document).ready(function($){ 217 jQuery(".validate").validationEngine('attach'); 218 }); 219 </script> 220 <form class="validate" action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post"> 221 <?php echo wp_nonce_field('register-user', '_mynonce'); ?> 222 <input type="hidden" name="action" value="register"> 223 <h3><?php _e('Register your blog on AllAroundSiena.com', 'wp-allaround' ); ?></h3> 224 <p><?php _e('Please check (and fix, if need) the following data, that will be sent to allaroundsiena.com server to register your blog. Check twice Admin e-mail field, because this mailbox will receive 225 credentials to access AllAroundSiena and manage your blog subscriptions'); ?></p> 226 <table class="form-table"> 227 <tr valign="top"> 228 <td> 229 <?php _e('Blog name','wp-allaround');?>: 230 </td><td> 231 <input type="text" name="allaround_blog_name" id="allaround_blog_name" class="validate[required]" value="<?php echo get_bloginfo('name'); ?>"> 232 </td> 233 </tr><tr> 234 <td> 235 <?php _e('Blog description','wp-allaround');?>: 236 </td><td> 237 <input type="text" name="allaround_blog_description" id="allaround_blog_description" class="validate[required]" value="<?php echo get_bloginfo('description'); ?>"> 238 </td> 239 </tr><tr> 240 <td> 241 <?php _e('Admin e-mail','wp-allaround');?>: 242 </td><td> 243 <input type="text" name="allaround_blog_admin" id="allaround_blog_admin" class="validate[required,custom[email]]" value="<?php echo get_bloginfo('admin_email'); ?>"> 244 </td> 245 </tr><tr> 246 <td> 247 <?php _e('Blog URL','wp-allaround');?>: 248 </td><td> 249 <input type="text" name="allaround_blog_url" id="allaround_blog_url" class="validate[required]" value="<?php echo get_bloginfo('url'); ?>"> 250 </td> 251 </tr> 252 </table> 253 <p> 254 <?php _e("By clicking Sign Up, you agree to our <a href='http://www.allaroundsiena.com/legal'>Terms</a>, including data use policy and cookie use"); ?> 255 </p> 256 <input type="submit" class="btn btn-large" id="allaround_register" value="<?php _e('Sign up', 'wp-allaround'); ?>"> 257 </form> 258 </div> 259 <?php 260 } else { 261 if(isset($_REQUEST['result'])) { 262 if($_REQUEST['result'] == 'updated') { 263 ?> 264 <div class='notice notice-success'> 265 <p><?php _e('Options updated !', 'wp-allaround' ); ?></p> 266 </div> 267 <?php 268 } 269 } 270 ?> 271 <div id="poststuff"> 272 <div id="post-body"> 273 <div id="post-body-content"> 274 <table class="form-table"> 275 <tr valign="top"> 276 <th scope="row"><?php _e('Your AllAround BOT Api Key', 'wp-allaround' ); ?></th> 277 <td> 278 <input type="text" name="allaround_api_key" id="allaround_api_key" value="<?php echo $option_api_key; ?>" readonly> 279 <br/> 280 <label class="description" for="allaround_api_key"><?php _e('This is the unique API key for your blog. Please, keep it safe.'); ?></label> 281 </td> 282 </tr><tr> 283 <td> 284 <button class="btn btn-large" id="allaround_verify"><?php _e('Verify connection', 'wp-allaround'); ?></button><span id="allaround_verify_result"> </span> 285 </td> 286 </tr> 287 </table> 288 <form action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post"> 289 <?php echo wp_nonce_field('update', '_mynonce'); ?> 290 <input type="hidden" name="action" value="update"> 291 <table class="form-table"> 292 <tr> 293 <th scope="row"><?php _e('Default is to publish new articles', 'wp-allaround' ); ?></th> 294 <td> 295 <input type="checkbox" name="allaround_default_publish" id="allaround_default_publish" <?php echo ($option_default_publish ? 'checked':''); ?> > 296 </td> 297 </tr><tr> 298 <td> 299 <input type="submit" value="<?php _e('Submit'); ?>"> 300 </td> 301 </tr> 302 </table> 303 </form> 107 304 </div> <!-- end post-body-content --> 108 305 </div> <!-- end post-body --> 109 306 </div> <!-- end poststuff --> 110 <?php 111 $option_api_key = get_option( 'allaround_api_key' ); 112 if(isset($option_api_key)) { 113 ?> 114 115 <div> 116 <p><?php _e("Click on the following button to connect this blog and start broadcasting:"); ?></p> 117 <button class="btn btn-large" id="allaround_connect"><?php _e('Connect this blog', 'wp-allaround'); ?></button> 118 <span id="allaround_connect_result"> </span> 119 </div> 120 </div> 121 <?php 122 } 123 ?> 124 <p> 125 <?php _e("Before you start, please visit <a href='http://www.allaroundsiena.com'>allaroundsiena.com</a> to get an API key for your blog"); ?> 126 </p> 127 <?php 128 } 129 ?> 130 307 <?php 308 } 309 ?> 310 </div><!-- /WRAP --> 311 <?php 312 } 313 ?> -
wp-allaround/tags/0.8.0/wp-allaround.php
r1467486 r1517333 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. 7.16 Version: 0.8.0 7 7 Author: Michele Pinassi 8 8 Author URI: http://www.zerozone.it … … 24 24 } 25 25 26 if (!function_exists('write_log')) { 27 function write_log ( $log ) { 28 if ( true === WP_DEBUG ) { 29 if ( is_array( $log ) || is_object( $log ) ) { 30 error_log( print_r( $log, true ) ); 31 } else { 32 error_log( $log ); 33 } 34 } 35 } 36 } 37 38 26 39 /* ============================================================ */ 27 40 /* */ … … 34 47 register_deactivation_hook(__FILE__, 'allaround_deactivate'); 35 48 49 add_action( 'activated_plugin', 'allaround_redirect' ); 50 51 function allaround_redirect($plugin) { 52 if($plugin == plugin_basename(__FILE__)) { 53 exit( wp_redirect( admin_url( 'admin.php?page=allaround_options' ) ) ); 54 } 55 } 56 36 57 function allaround_activate() { 37 58 add_option('allaround_api_key',false); 59 add_option('allaround_default_publish',true); 38 60 } 39 61 40 62 function allaround_deactivate() { 41 if(!defined('WP_UNINSTALL_PLUGIN')) { 42 exit(); 43 } 44 63 delete_option('allaround_api_key'); 64 delete_option('allaround_default_publish'); 45 65 } 46 66 … … 153 173 $option_api_key = get_option( 'allaround_api_key' ); 154 174 155 // if(($option_api_key) && ('publish' === $new_status && 'publish' !== $old_status)) {156 157 175 if($option_api_key) { 158 176 /* Get the post properties */ … … 198 216 $body = Unirest\Request\Body::multipart($data); 199 217 200 error_log(print_r($body, true));201 202 218 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/publish', $headers, $body); 203 219 error_log(print_r($result, true)); … … 213 229 return $result; 214 230 } 231 return false; 215 232 } 216 233 … … 245 262 $result = allaround_do_publish($post); 246 263 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 // ERROR ! 255 $post_result_code = $result->code; 256 $post_result_message = $post_result['error']['message']; 257 $post_is_published = false; 258 } else if(isset($post_result['success'])) { 259 // DONE ! 260 $post_result_code = $result->code; 261 $post_result_message = $post_result['success']; 262 $post_is_published = true; 264 if($result) { 265 $post_date = current_time('mysql'); 266 267 $post_result = json_decode($result->raw_body,true); 268 269 error_log(print_r($post_result, true)); 270 271 if(isset($post_result['error'])) { 272 // ERROR ! 273 $post_result_code = $result->code; 274 $post_result_message = $post_result['error']['message']; 275 $post_is_published = false; 276 } else if(isset($post_result['success'])) { 277 // DONE ! 278 $post_result_code = $result->code; 279 $post_result_message = $post_result['success']; 280 $post_is_published = true; 281 } else { 282 // Something wrong with network ? 283 $post_is_published = false; 284 } 285 286 update_post_meta($post->ID, "allaround_post_date","$post_date"); 287 update_post_meta($post->ID, "allaround_post_message", $post_result_message); 288 289 if($post_is_published) { /* Success */ 290 update_post_meta($post->ID, "allaround_post_status","published"); 291 add_action( 'admin_notices', 'allaround_notice_publish_success' ); 292 } else { 293 update_post_meta($post->ID, "allaround_post_status","error"); 294 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 295 } 263 296 } else { 264 // Something wrong with network ? 265 $post_is_published = false; 266 } 267 268 update_post_meta($post->ID, "allaround_post_date","$post_date"); 269 update_post_meta($post->ID, "allaround_post_message", $post_result_message); 270 271 if($post_is_published) { /* Success */ 272 update_post_meta($post->ID, "allaround_post_status","published"); 273 add_action( 'admin_notices', 'allaround_notice_publish_success' ); 274 } else { 275 update_post_meta($post->ID, "allaround_post_status","error"); 276 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 297 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 277 298 } 278 299 } -
wp-allaround/trunk/README.txt
r1467486 r1517333 5 5 Requires at least: 4.0.0 6 6 Tested up to: 4.6.0 7 Stable tag: 0. 7.17 Stable tag: 0.8.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 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)23 4. Click on "Connect this blog" button to validate the API key and connect your blog to the AllAroundSiena Telegram Bot service22 3. Use the Settings->AllAround Options screen to configure the plugins and register your blog on AllAroundSiena.com 23 4. Wait for validation e-mail in your mailbox and follow the istructions 24 24 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 … … 35 35 36 36 == Changelog == 37 38 = 0.8.0 = 39 * Now you can register your blog directly from plugin, after installation 40 * Code cleanup and bugs fixed 37 41 38 42 = 0.7.1 = -
wp-allaround/trunk/wp-allaround-admin.php
r1466742 r1517333 1 1 <?php 2 2 /* Only if ADMIN */ 3 4 add_action( 'wp_ajax_connect', 'allaround_action_connect' ); 5 6 function allaround_action_connect() { 3 if(!is_admin()) { 4 wp_die(); 5 } 6 7 /* ============================================================ */ 8 /* */ 9 /* POST */ 10 /* */ 11 /* =============================================================*/ 12 13 add_action( 'admin_post_register', 'allaround_action_register' ); 14 15 function allaround_action_register() { 16 $headers = array('Accept' => 'application/json'); 17 18 // Verify if the nonce is valid 19 if ( !isset($_POST['_mynonce']) || !wp_verify_nonce($_POST['_mynonce'], 'register-user')) { 20 echo "NONCE VERIFICATION FAILED"; 21 } else { 22 $option_api_key = get_option( 'allaround_api_key' ); 23 24 if(!isset($option_api_key)) { 25 $option_api_key = ''; /* No API key */ 26 } 27 28 $blog_name = ($_POST["allaround_blog_name"] ? $_POST["allaround_blog_name"]:get_bloginfo('name')); 29 $blog_description = ($_POST["allaround_blog_description"] ? $_POST["allaround_blog_description"]:get_bloginfo('description')); 30 $blog_admin_email = ($_POST["allaround_admin_email"] ? $_POST["allaround_admin_email"]:get_bloginfo('admin_email')); 31 $blog_language = get_bloginfo('language'); 32 $blog_url = ($_POST["allaround_blog_url"] ? $_POST["allaround_blog_url"]:get_bloginfo('url')); 33 34 $data = array('key' => $option_api_key, 35 'blog_name' => $blog_name, 36 'blog_description' => $blog_description, 37 'blog_admin_email' => $blog_admin_email, 38 'blog_language' => $blog_language, 39 'blog_url' => $blog_url, 40 ); 41 42 $body = Unirest\Request\Body::multipart($data); 43 44 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/register', $headers, $body); 45 46 write_log($result); 47 48 if($result->code == '200') { 49 if(isset($result->body->apikey)) { 50 $api_key = $result->body->apikey; 51 52 update_option('allaround_api_key', $api_key); 53 54 $result = "success"; 55 } else { 56 $result = "fail"; 57 } 58 } else { 59 $result = "fail"; 60 } 61 62 wp_redirect(admin_url("admin.php?page=allaround_options&result=$result")); 63 exit; 64 } 65 wp_die(); 66 } 67 68 add_action( 'admin_post_update', 'allaround_action_update' ); 69 70 function allaround_action_update() { 71 if ( !isset($_POST['_mynonce']) || !wp_verify_nonce($_POST['_mynonce'], 'update')) { 72 echo "NONCE VERIFICATION FAILED"; 73 } else { 74 if(isset($_POST["allaround_default_publish"])) { 75 update_option( 'allaround_default_publish',true); 76 } else { 77 update_option( 'allaround_default_publish',false); 78 } 79 80 $result = 'updated'; 81 82 wp_redirect(admin_url("admin.php?page=allaround_options&result=$result")); 83 exit; 84 } 85 } 86 87 function allaround_enqueue() { 88 global $wp_styles; 89 90 wp_enqueue_script( 'ajax-script', 91 plugins_url( '/js/jquery.validationEngine-it.js', __FILE__ ), 92 array('jquery') 93 ); 94 95 wp_enqueue_script( 'ajax-script', 96 plugins_url( '/js/jquery.validationEngine.js', __FILE__ ), 97 array('jquery') 98 ); 99 100 wp_enqueue_script( 'ajax-script', 101 plugins_url( '/js/custom.js', __FILE__ ), 102 array('jquery') 103 ); 104 105 wp_localize_script( 'ajax-script', 'ajax_object', array( 106 'ajax_url' => admin_url( 'admin-ajax.php' ), 107 )); 108 109 // Load stylesheets 110 wp_enqueue_style( 'wp-allaround', plugins_url( '/css/validationEngine.jquery.css', __FILE__ )); 111 wp_enqueue_style( 'wp-allaround', plugins_url( '/css/wp-allaround.css', __FILE__ )); 112 } 113 114 add_action('admin_enqueue_scripts', 'allaround_enqueue'); 115 116 /* ============================================================ */ 117 /* */ 118 /* AJAX */ 119 /* */ 120 /* =============================================================*/ 121 122 add_action( 'wp_ajax_verify', 'allaround_action_verify' ); 123 124 function allaround_action_verify() { 7 125 global $wpdb; // this is how you get access to the database 8 126 … … 22 140 $body = Unirest\Request\Body::multipart($data); 23 141 24 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/ connect', $headers, $body);142 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/verify', $headers, $body); 25 143 26 144 if($result->code == '200') { … … 34 152 } 35 153 36 function allaround_enqueue() { 37 global $wp_styles; 38 39 wp_enqueue_script( 'ajax-script', 40 plugins_url( '/js/common.js', __FILE__ ), 41 array('jquery') 42 ); 43 44 wp_localize_script( 'ajax-script', 'ajax_object', array( 45 'ajax_url' => admin_url( 'admin-ajax.php' ), 46 )); 47 48 // Load the main stylesheet 49 wp_enqueue_style( 'wp-allaround', plugins_url( '/css/wp-allaround.css', __FILE__ )); 50 } 51 52 add_action('admin_enqueue_scripts', 'allaround_enqueue'); 154 /* ============================================================ */ 155 /* */ 156 /* ADMIN */ 157 /* */ 158 /* =============================================================*/ 53 159 54 160 function allaround_options_menu() { … … 69 175 'allaround_api_key' // setting name 70 176 ); 177 register_setting( 178 'allaround_options', // settings section 179 'allaround_default_ublish' // setting name 180 ); 181 71 182 } 72 183 add_action( 'admin_init', 'allaround_register_settings' ); … … 76 187 $_REQUEST['settings-updated'] = false; 77 188 } 78 ?> 79 <div class="wrap"> 189 settings_fields( 'allaround_options' ); 190 $option_api_key = get_option( 'allaround_api_key' ); 191 $option_default_publish = get_option( 'allaround_default_publish' ); 192 ?> 193 <div class="wrap"><!-- WRAP --> 80 194 <h2><?php echo esc_html( get_admin_page_title() ); ?></h2> 81 82 <div id="poststuff"> 83 <div id="post-body"> 84 <div id="post-body-content"> 85 <form method="post" action="options.php"> 86 <?php settings_fields( 'allaround_options' ); ?> 87 <?php $option_api_key = get_option( 'allaround_api_key' ); ?> 88 <table class="form-table"> 89 <tr valign="top"><th scope="row"><?php _e('Your AllAround BOT Api Key', 'wp-allaround' ); ?></th> 90 <td> 91 <input type="text" name="allaround_api_key" id="allaround_api_key" value="<?php echo $option_api_key; ?>"> 92 <br/> 93 <label class="description" for="allaround_api_key"><?php _e('Type here your AllAround BOT Api Key', 'wp-allaround' ); ?></label> 94 </td> 95 </tr><tr><th scope="row"><?php _e('Default is to publish new articles', 'wp-allaround' ); ?></th> 96 <td> 97 <input type="checkbox" name="allaround_default_publish" id="allaround_default_publish" checked> 98 </td> 99 </tr> 100 </tr><tr> 101 <td> 102 <input type="submit" value="<?php _e('Submit'); ?>"> 103 </td> 104 </tr> 105 </table> 106 </form> 195 <?php 196 if(empty($option_api_key)) { 197 198 if(isset($_REQUEST['result'])) { 199 if($_REQUEST['result'] == 'fail') { 200 ?> 201 <div class='notice notice-error'> 202 <p><?php _e('Ooops ! Something wrong while registering your blog: please try later.', 'wp-allaround' ); ?></p> 203 </div> 204 <?php 205 } else if($_REQUEST['result'] == 'success') { 206 ?> 207 <div class='notice notice-success'> 208 <p><?php _e('Great ! Your BLOG was registered successfully on AllAroundSiena.com: now check your mailbox...', 'wp-allaround' ); ?></p> 209 </div> 210 <?php 211 } 212 } 213 ?> 214 <div> 215 <script> 216 jQuery(document).ready(function($){ 217 jQuery(".validate").validationEngine('attach'); 218 }); 219 </script> 220 <form class="validate" action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post"> 221 <?php echo wp_nonce_field('register-user', '_mynonce'); ?> 222 <input type="hidden" name="action" value="register"> 223 <h3><?php _e('Register your blog on AllAroundSiena.com', 'wp-allaround' ); ?></h3> 224 <p><?php _e('Please check (and fix, if need) the following data, that will be sent to allaroundsiena.com server to register your blog. Check twice Admin e-mail field, because this mailbox will receive 225 credentials to access AllAroundSiena and manage your blog subscriptions'); ?></p> 226 <table class="form-table"> 227 <tr valign="top"> 228 <td> 229 <?php _e('Blog name','wp-allaround');?>: 230 </td><td> 231 <input type="text" name="allaround_blog_name" id="allaround_blog_name" class="validate[required]" value="<?php echo get_bloginfo('name'); ?>"> 232 </td> 233 </tr><tr> 234 <td> 235 <?php _e('Blog description','wp-allaround');?>: 236 </td><td> 237 <input type="text" name="allaround_blog_description" id="allaround_blog_description" class="validate[required]" value="<?php echo get_bloginfo('description'); ?>"> 238 </td> 239 </tr><tr> 240 <td> 241 <?php _e('Admin e-mail','wp-allaround');?>: 242 </td><td> 243 <input type="text" name="allaround_blog_admin" id="allaround_blog_admin" class="validate[required,custom[email]]" value="<?php echo get_bloginfo('admin_email'); ?>"> 244 </td> 245 </tr><tr> 246 <td> 247 <?php _e('Blog URL','wp-allaround');?>: 248 </td><td> 249 <input type="text" name="allaround_blog_url" id="allaround_blog_url" class="validate[required]" value="<?php echo get_bloginfo('url'); ?>"> 250 </td> 251 </tr> 252 </table> 253 <p> 254 <?php _e("By clicking Sign Up, you agree to our <a href='http://www.allaroundsiena.com/legal'>Terms</a>, including data use policy and cookie use"); ?> 255 </p> 256 <input type="submit" class="btn btn-large" id="allaround_register" value="<?php _e('Sign up', 'wp-allaround'); ?>"> 257 </form> 258 </div> 259 <?php 260 } else { 261 if(isset($_REQUEST['result'])) { 262 if($_REQUEST['result'] == 'updated') { 263 ?> 264 <div class='notice notice-success'> 265 <p><?php _e('Options updated !', 'wp-allaround' ); ?></p> 266 </div> 267 <?php 268 } 269 } 270 ?> 271 <div id="poststuff"> 272 <div id="post-body"> 273 <div id="post-body-content"> 274 <table class="form-table"> 275 <tr valign="top"> 276 <th scope="row"><?php _e('Your AllAround BOT Api Key', 'wp-allaround' ); ?></th> 277 <td> 278 <input type="text" name="allaround_api_key" id="allaround_api_key" value="<?php echo $option_api_key; ?>" readonly> 279 <br/> 280 <label class="description" for="allaround_api_key"><?php _e('This is the unique API key for your blog. Please, keep it safe.'); ?></label> 281 </td> 282 </tr><tr> 283 <td> 284 <button class="btn btn-large" id="allaround_verify"><?php _e('Verify connection', 'wp-allaround'); ?></button><span id="allaround_verify_result"> </span> 285 </td> 286 </tr> 287 </table> 288 <form action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post"> 289 <?php echo wp_nonce_field('update', '_mynonce'); ?> 290 <input type="hidden" name="action" value="update"> 291 <table class="form-table"> 292 <tr> 293 <th scope="row"><?php _e('Default is to publish new articles', 'wp-allaround' ); ?></th> 294 <td> 295 <input type="checkbox" name="allaround_default_publish" id="allaround_default_publish" <?php echo ($option_default_publish ? 'checked':''); ?> > 296 </td> 297 </tr><tr> 298 <td> 299 <input type="submit" value="<?php _e('Submit'); ?>"> 300 </td> 301 </tr> 302 </table> 303 </form> 107 304 </div> <!-- end post-body-content --> 108 305 </div> <!-- end post-body --> 109 306 </div> <!-- end poststuff --> 110 <?php 111 $option_api_key = get_option( 'allaround_api_key' ); 112 if(isset($option_api_key)) { 113 ?> 114 115 <div> 116 <p><?php _e("Click on the following button to connect this blog and start broadcasting:"); ?></p> 117 <button class="btn btn-large" id="allaround_connect"><?php _e('Connect this blog', 'wp-allaround'); ?></button> 118 <span id="allaround_connect_result"> </span> 119 </div> 120 </div> 121 <?php 122 } 123 ?> 124 <p> 125 <?php _e("Before you start, please visit <a href='http://www.allaroundsiena.com'>allaroundsiena.com</a> to get an API key for your blog"); ?> 126 </p> 127 <?php 128 } 129 ?> 130 307 <?php 308 } 309 ?> 310 </div><!-- /WRAP --> 311 <?php 312 } 313 ?> -
wp-allaround/trunk/wp-allaround.php
r1467486 r1517333 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. 7.16 Version: 0.8.0 7 7 Author: Michele Pinassi 8 8 Author URI: http://www.zerozone.it … … 24 24 } 25 25 26 if (!function_exists('write_log')) { 27 function write_log ( $log ) { 28 if ( true === WP_DEBUG ) { 29 if ( is_array( $log ) || is_object( $log ) ) { 30 error_log( print_r( $log, true ) ); 31 } else { 32 error_log( $log ); 33 } 34 } 35 } 36 } 37 38 26 39 /* ============================================================ */ 27 40 /* */ … … 34 47 register_deactivation_hook(__FILE__, 'allaround_deactivate'); 35 48 49 add_action( 'activated_plugin', 'allaround_redirect' ); 50 51 function allaround_redirect($plugin) { 52 if($plugin == plugin_basename(__FILE__)) { 53 exit( wp_redirect( admin_url( 'admin.php?page=allaround_options' ) ) ); 54 } 55 } 56 36 57 function allaround_activate() { 37 58 add_option('allaround_api_key',false); 59 add_option('allaround_default_publish',true); 38 60 } 39 61 40 62 function allaround_deactivate() { 41 if(!defined('WP_UNINSTALL_PLUGIN')) { 42 exit(); 43 } 44 63 delete_option('allaround_api_key'); 64 delete_option('allaround_default_publish'); 45 65 } 46 66 … … 153 173 $option_api_key = get_option( 'allaround_api_key' ); 154 174 155 // if(($option_api_key) && ('publish' === $new_status && 'publish' !== $old_status)) {156 157 175 if($option_api_key) { 158 176 /* Get the post properties */ … … 198 216 $body = Unirest\Request\Body::multipart($data); 199 217 200 error_log(print_r($body, true));201 202 218 $result = Unirest\Request::post('https://www.allaroundsiena.com/rest/publish', $headers, $body); 203 219 error_log(print_r($result, true)); … … 213 229 return $result; 214 230 } 231 return false; 215 232 } 216 233 … … 245 262 $result = allaround_do_publish($post); 246 263 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 // ERROR ! 255 $post_result_code = $result->code; 256 $post_result_message = $post_result['error']['message']; 257 $post_is_published = false; 258 } else if(isset($post_result['success'])) { 259 // DONE ! 260 $post_result_code = $result->code; 261 $post_result_message = $post_result['success']; 262 $post_is_published = true; 264 if($result) { 265 $post_date = current_time('mysql'); 266 267 $post_result = json_decode($result->raw_body,true); 268 269 error_log(print_r($post_result, true)); 270 271 if(isset($post_result['error'])) { 272 // ERROR ! 273 $post_result_code = $result->code; 274 $post_result_message = $post_result['error']['message']; 275 $post_is_published = false; 276 } else if(isset($post_result['success'])) { 277 // DONE ! 278 $post_result_code = $result->code; 279 $post_result_message = $post_result['success']; 280 $post_is_published = true; 281 } else { 282 // Something wrong with network ? 283 $post_is_published = false; 284 } 285 286 update_post_meta($post->ID, "allaround_post_date","$post_date"); 287 update_post_meta($post->ID, "allaround_post_message", $post_result_message); 288 289 if($post_is_published) { /* Success */ 290 update_post_meta($post->ID, "allaround_post_status","published"); 291 add_action( 'admin_notices', 'allaround_notice_publish_success' ); 292 } else { 293 update_post_meta($post->ID, "allaround_post_status","error"); 294 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 295 } 263 296 } else { 264 // Something wrong with network ? 265 $post_is_published = false; 266 } 267 268 update_post_meta($post->ID, "allaround_post_date","$post_date"); 269 update_post_meta($post->ID, "allaround_post_message", $post_result_message); 270 271 if($post_is_published) { /* Success */ 272 update_post_meta($post->ID, "allaround_post_status","published"); 273 add_action( 'admin_notices', 'allaround_notice_publish_success' ); 274 } else { 275 update_post_meta($post->ID, "allaround_post_status","error"); 276 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 297 add_action( 'admin_notices', 'allaround_notice_publish_error' ); 277 298 } 278 299 }
Note: See TracChangeset
for help on using the changeset viewer.