Пример #1
0
 /**
  * run the status check on call
  */
 public function status_yourls()
 {
     // only run on admin
     if (!is_admin()) {
         die;
     }
     // start our return
     $ret = array();
     // verify our nonce
     $check = check_ajax_referer('yourls_status_nonce', 'nonce', false);
     // check to see if our nonce failed
     if (!$check) {
         $ret['success'] = false;
         $ret['errcode'] = 'NONCE_FAILED';
         $ret['message'] = __('The nonce did not validate.', 'wpyourls');
         echo json_encode($ret);
         die;
     }
     // bail if the API key or URL have not been entered
     if (false === ($api = YOURLSCreator_Helper::get_yourls_api_data())) {
         $ret['success'] = false;
         $ret['errcode'] = 'NO_API_DATA';
         $ret['message'] = __('No API data has been entered.', 'wpyourls');
         echo json_encode($ret);
         die;
     }
     // make the API call
     $build = YOURLSCreator_Helper::run_yourls_api_call('db-stats');
     // handle the check and set it
     $check = !empty($build) && false !== $build['success'] ? 'connect' : 'noconnect';
     // set the option return
     if (false !== get_option('yourls_api_test')) {
         update_option('yourls_api_test', $check);
     } else {
         add_option('yourls_api_test', $check, null, 'no');
     }
     // now get the API data
     $data = YOURLSCreator_Helper::get_api_status_data();
     // check to see if no data happened
     if (empty($data)) {
         $ret['success'] = false;
         $ret['errcode'] = 'NO_STATUS_DATA';
         $ret['message'] = __('The status of the YOURLS API could not be determined.', 'wpyourls');
         echo json_encode($ret);
         die;
     }
     // if we have data, send back things
     if (!empty($data)) {
         $ret['success'] = true;
         $ret['errcode'] = null;
         $ret['baricon'] = $data['icon'];
         $ret['message'] = $data['text'];
         $ret['stcheck'] = '<span class="dashicons dashicons-yes api-status-checkmark"></span>';
         echo json_encode($ret);
         die;
     }
     // we've reached the end, and nothing worked....
     $ret['success'] = false;
     $ret['errcode'] = 'UNKNOWN';
     $ret['message'] = __('There was an unknown error.', 'wpyourls');
     echo json_encode($ret);
     die;
 }
Пример #2
0
        /**
         * the status sidebox
         */
        public static function sidebox_status()
        {
            // get my API status data
            if (false === ($data = YOURLSCreator_Helper::get_api_status_data())) {
                return;
            }
            ?>

		<div id="yourls-admin-status" class="postbox yourls-sidebox">
			<h3 class="hndle" id="status-sidebar"><?php 
            echo $data['icon'];
            _e('API Status Check', 'wpyourls');
            ?>
</h3>
			<div class="inside">
				<form>

				<p class="api-status-text"><?php 
            echo esc_attr($data['text']);
            ?>
</p>

				<p class="api-status-actions">
					<input type="button" class="yourls-click-status button-primary" value="<?php 
            _e('Check Status', 'wpyourls');
            ?>
" >
					<span class="spinner yourls-spinner yourls-status-spinner"></span>
					<?php 
            wp_nonce_field('yourls_status_nonce', 'yourls_status', false, true);
            ?>

				</p>

				</form>
			</div>
		</div>

	<?php 
        }