Пример #1
0
 /**
  * Gateway function for Testing Comms
  *
  * @param array $args 
  * @return object cfd_message
  */
 public function ajax_test_comms($args)
 {
     $server = $args['cfd_settings']['remote_server'][0]['address'];
     $auth_key = $args['cfd_settings']['remote_server'][0]['key'];
     $method = 'ajax_test_' . $args['test_action'];
     if ($method == 'ajax_test_say_hello' && method_exists($this, $method)) {
         // simple "hello world" comms test
         $ret = $this->{$method}($server, $auth_key, $args);
         if (empty($ret) || !$ret instanceof cfd_message) {
             $ret = new cfd_message(array('success' => false, 'type' => 'unknown-return-value', 'message' => '<div class="error"><p>Unexpected return value from "' . esc_html($args['test_action']) . '"</p></div>'));
         } else {
             return $ret;
         }
     } elseif (method_exists($this, $method)) {
         // batch data testing
         $batch_data = $this->{$method}($args, array());
         if ($batch_data instanceof cfd_message) {
             return $batch_data;
         }
         $batch = new cfd_batch(array('ID' => 0, 'data' => $batch_data));
         $params = array('server' => $server, 'auth_key' => $auth_key, 'method' => 'import_batch', 'args' => array('batch' => $batch->get_deploy_data()));
         $ret = $this->send($params);
         if (is_array($ret->message)) {
             $post_type_messages = $ret->message;
             $ret->message = '';
             foreach ($post_type_messages as $post_type => $messages) {
                 $ret->message .= $this->parse_message_response($messages, $post_type);
             }
         }
         if ($ret->success) {
             $ret->message = '<div class="success message"><h3>Import Successful</h3></div>' . $ret->message;
         } else {
             $ret->message = '<div class="error message"><h3>Import Failed</h3></div>' . $ret->message;
         }
         if (empty($ret) || !$ret instanceof cfd_message) {
             $ret = new cfd_message(array('success' => false, 'type' => 'unknown-return-value', 'message' => '<div class="error message"><p>Unexpected return value from "' . esc_html($args['test_action']) . '"</p></div>'));
         }
     } else {
         $ret = new cfd_message(array('success' => false, 'type' => 'bad-method', 'message' => '<div class="error message"><p>Method "' . esc_html($args['test_action']) . '" does not exist</p></div>'));
     }
     return $ret;
 }