public static function import($params = array())
 {
     global $wp_filter;
     // Set error handler
     @set_error_handler('Ai1wm_Handler::error');
     // Set params
     if (empty($params)) {
         $params = ai1wm_urldecode($_REQUEST);
     }
     // Set priority
     $priority = 10;
     if (isset($params['priority'])) {
         $priority = (int) $params['priority'];
     }
     // Set secret key
     $secret_key = null;
     if (isset($params['secret_key'])) {
         $secret_key = $params['secret_key'];
     }
     // Verify secret key by using the value in the database, not in cache
     if ($secret_key !== get_option(AI1WM_SECRET_KEY)) {
         Ai1wm_Status::error(sprintf(__('Unable to authenticate your request with secret_key = "%s"', AI1WM_PLUGIN_NAME), $secret_key), __('Unable to import', AI1WM_PLUGIN_NAME));
         exit;
     }
     // Get hook
     if (isset($wp_filter['ai1wm_import']) && ($filters = $wp_filter['ai1wm_import']) && ksort($filters)) {
         while ($hooks = current($filters)) {
             if ($priority == key($filters)) {
                 foreach ($hooks as $hook) {
                     try {
                         $params = call_user_func_array($hook['function'], array($params));
                     } catch (Ai1wm_Import_Retry_Exception $exception) {
                         status_header($exception->getCode());
                         echo json_encode(array('message' => $exception->getMessage()));
                         exit;
                     } catch (Exception $e) {
                         Ai1wm_Status::error($e->getMessage(), __('Unable to import', AI1WM_PLUGIN_NAME));
                         exit;
                     }
                 }
                 // Set completed
                 $completed = true;
                 if (isset($params['completed'])) {
                     $completed = (bool) $params['completed'];
                 }
                 // Log request
                 if (empty($params['priority']) || is_file(ai1wm_import_path($params))) {
                     Ai1wm_Log::import($params);
                 }
                 // Do request
                 if ($completed === false || ($next = next($filters)) && ($params['priority'] = key($filters))) {
                     return Ai1wm_Http::get(admin_url('admin-ajax.php?action=ai1wm_import'), $params);
                 }
             }
             next($filters);
         }
     }
 }
	public static function execute( $params ) {

		// Set progress
		Ai1wm_Status::info( __( 'Resolving URL address...', AI1WM_PLUGIN_NAME ) );

		// HTTP resolve
		Ai1wm_Http::resolve( admin_url( 'admin-ajax.php?action=ai1wm_resolve' ) );

		// Set progress
		Ai1wm_Status::info( __( 'Done resolving URL address...', AI1WM_PLUGIN_NAME ) );

		return $params;
	}
Esempio n. 3
0
 public static function resolve($url)
 {
     // Reset IP address and transport layer
     delete_site_option(AI1WM_URL_IP);
     delete_site_option(AI1WM_URL_TRANSPORT);
     // Set secret
     $secret_key = get_site_option(AI1WM_SECRET_KEY, false, false);
     // Set scheme
     $scheme = parse_url($url, PHP_URL_SCHEME);
     // Set host name
     $host = parse_url($url, PHP_URL_HOST);
     // Set server IP address
     if (!empty($_SERVER['SERVER_ADDR'])) {
         $ip = $_SERVER['SERVER_ADDR'];
     } else {
         if (!empty($_SERVER['LOCAL_ADDR'])) {
             $ip = $_SERVER['LOCAL_ADDR'];
         } else {
             $ip = '127.0.0.1';
         }
     }
     // Set domain IP address
     $domain = gethostbyname($host);
     // HTTP resolve
     foreach (array('ai1wm', 'curl') as $transport) {
         foreach (array($ip, $domain, $host) as $ip) {
             // Set transport
             Ai1wm_Http::$transports = array($transport);
             // HTTP request
             Ai1wm_Http::request($url, $ip, array('secret_key' => $secret_key, 'url_ip' => $ip, 'url_transport' => $transport));
             // HTTP response
             for ($i = 0; $i < 5; $i++, sleep(1)) {
                 // Clear WP notoptions cache
                 wp_cache_delete('notoptions', 'options');
                 // Clear WP options cache
                 wp_cache_flush();
                 // Is valid transport layer?
                 if (get_site_option(AI1WM_URL_IP, false, false) && get_site_option(AI1WM_URL_TRANSPORT, false, false)) {
                     return;
                 }
             }
         }
     }
     // No connection
     throw new Ai1wm_Http_Exception(__('There was a problem while reaching your server.<br />' . 'Contact <a href="mailto:support@servmask.com">support@servmask.com</a> for assistance.', AI1WM_PLUGIN_NAME));
 }
 public static function resolve($url)
 {
     // Reset IP address and adapter
     delete_option(AI1WM_URL_IP);
     delete_option(AI1WM_URL_ADAPTER);
     // Set secret
     $secret_key = get_option(AI1WM_SECRET_KEY);
     // Set host
     $host = parse_url($url, PHP_URL_HOST);
     // Set server IP address
     if (!empty($_SERVER['SERVER_ADDR'])) {
         $server = $_SERVER['SERVER_ADDR'];
     } else {
         if (!empty($_SERVER['LOCAL_ADDR'])) {
             $server = $_SERVER['LOCAL_ADDR'];
         } else {
             $server = '127.0.0.1';
         }
     }
     // Set local IP address
     $local = gethostbyname($host);
     // HTTP resolve
     foreach (array('stream', 'curl') as $adapter) {
         foreach (array($server, $local, $host) as $ip) {
             // Add IPv6 support
             if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
                 $ip = "[{$ip}]";
             }
             // HTTP request
             Ai1wm_Http::request($url, $ip, $adapter, array('secret_key' => $secret_key, 'url_ip' => $ip, 'url_adapter' => $adapter));
             // HTTP response
             for ($i = 0; $i < 5; $i++, sleep(1)) {
                 // Flush WP cache
                 ai1wm_cache_flush();
                 // Is valid adapter?
                 if (get_option(AI1WM_URL_IP) && get_option(AI1WM_URL_ADAPTER)) {
                     return;
                 }
             }
         }
     }
     // No connection
     throw new Ai1wm_Http_Exception(__('There was a problem while reaching your server.<br />' . 'Contact <a href="mailto:support@servmask.com">support@servmask.com</a> for assistance.', AI1WM_PLUGIN_NAME));
 }
	public static function execute( $params ) {

		// Set progress
		Ai1wm_Status::info( __( 'Resolving URL address...', AI1WM_PLUGIN_NAME ) );

		// HTTP resolve
		Ai1wm_Http::resolve( admin_url( 'admin-ajax.php?action=ai1wm_resolve' ) );

		// Set archive
		if ( empty( $params['archive'] ) ) {
			$params['archive'] = ai1wm_archive_file();
		}

		// Set storage
		if ( empty( $params['storage'] ) ) {
			$params['storage'] = ai1wm_storage_folder();
		}

		// Set progress
		Ai1wm_Status::info( __( 'Done resolving URL address...', AI1WM_PLUGIN_NAME ) );

		return $params;
	}
 /**
  * Route to method
  *
  * @param  string $method Name of the method
  * @return void
  */
 protected function route_to($method)
 {
     // Redirect arguments
     $this->args['method'] = $method;
     $this->args['secret_key'] = get_site_option(AI1WM_SECRET_KEY, false, false);
     // Check the status of the export, maybe we need to stop it
     if (!is_file($this->storage()->archive())) {
         exit;
     }
     // HTTP request
     Ai1wm_Http::get(admin_url('admin-ajax.php?action=ai1wm_import'), $this->args);
 }