All-in-One WP Migration - Version 6.40

Version Description

  • Do not extract dropins files on import
  • Fix an issue with large files on import
  • Fix an issue with inactive plugins option in advanced settings on export
  • Do not exclude active plugins in package.json and multisite.json on export
  • Do not show "Resolving URL address..." on export/import
  • Add separate action hook in advanced settings called "ai1wm_export_advanced_settings" to allow custom checkbox options on export
Download this release

Release Info

Developer bangelov
Plugin Icon 128x128 All-in-One WP Migration
Version 6.40
Comparing to
See all releases

Code changes from version 6.39 to 6.40

Files changed (80) hide show
  1. all-in-one-wp-migration.php +2 -2
  2. constants.php +7 -2
  3. deprecated.php +1 -1
  4. exceptions.php +1 -1
  5. functions.php +104 -15
  6. lib/controller/class-ai1wm-backups-controller.php +1 -1
  7. lib/controller/class-ai1wm-export-controller.php +1 -1
  8. lib/controller/class-ai1wm-feedback-controller.php +9 -9
  9. lib/controller/class-ai1wm-import-controller.php +1 -1
  10. lib/controller/class-ai1wm-main-controller.php +57 -38
  11. lib/controller/class-ai1wm-report-controller.php +7 -7
  12. lib/controller/class-ai1wm-resolve-controller.php +1 -1
  13. lib/controller/class-ai1wm-status-controller.php +1 -1
  14. lib/controller/class-ai1wm-updater-controller.php +5 -5
  15. lib/model/class-ai1wm-backups.php +2 -2
  16. lib/model/class-ai1wm-compatibility.php +1 -1
  17. lib/model/class-ai1wm-deprecated.php +1 -1
  18. lib/model/class-ai1wm-extensions.php +1 -1
  19. lib/model/class-ai1wm-feedback.php +1 -1
  20. lib/model/class-ai1wm-handler.php +1 -1
  21. lib/model/class-ai1wm-http.php +1 -1
  22. lib/model/class-ai1wm-log.php +1 -1
  23. lib/model/class-ai1wm-report.php +1 -1
  24. lib/model/class-ai1wm-status.php +2 -2
  25. lib/model/class-ai1wm-template.php +1 -1
  26. lib/model/class-ai1wm-updater.php +1 -1
  27. lib/model/export/class-ai1wm-export-archive.php +1 -1
  28. lib/model/export/class-ai1wm-export-clean.php +1 -1
  29. lib/model/export/class-ai1wm-export-compatibility.php +7 -1
  30. lib/model/export/class-ai1wm-export-config.php +2 -6
  31. lib/model/export/class-ai1wm-export-content.php +1 -1
  32. lib/model/export/class-ai1wm-export-database.php +1 -1
  33. lib/model/export/class-ai1wm-export-download.php +1 -1
  34. lib/model/export/class-ai1wm-export-enumerate.php +2 -2
  35. lib/model/export/class-ai1wm-export-init.php +1 -7
  36. lib/model/export/class-ai1wm-export-resolve.php +2 -4
  37. lib/model/http/class-ai1wm-http-abstract.php +1 -1
  38. lib/model/http/class-ai1wm-http-curl.php +1 -1
  39. lib/model/http/class-ai1wm-http-factory.php +1 -1
  40. lib/model/http/class-ai1wm-http-stream.php +1 -1
  41. lib/model/import/class-ai1wm-import-blogs.php +1 -1
  42. lib/model/import/class-ai1wm-import-clean.php +1 -1
  43. lib/model/import/class-ai1wm-import-compatibility.php +6 -1
  44. lib/model/import/class-ai1wm-import-confirm.php +1 -1
  45. lib/model/import/class-ai1wm-import-content.php +1 -1
  46. lib/model/import/class-ai1wm-import-database.php +1 -1
  47. lib/model/import/class-ai1wm-import-done.php +1 -1
  48. lib/model/import/class-ai1wm-import-enumerate.php +1 -1
  49. lib/model/import/class-ai1wm-import-plugins.php +5 -11
  50. lib/model/import/class-ai1wm-import-resolve.php +2 -4
  51. lib/model/import/class-ai1wm-import-upload.php +1 -1
  52. lib/model/import/class-ai1wm-import-validate.php +1 -1
  53. lib/vendor/math/BigInteger.php +3811 -0
  54. lib/vendor/servmask/archiver/class-ai1wm-archiver.php +41 -10
  55. lib/vendor/servmask/archiver/class-ai1wm-compressor.php +1 -1
  56. lib/vendor/servmask/archiver/class-ai1wm-extractor.php +2 -12
  57. lib/vendor/servmask/cron/class-ai1wm-cron.php +1 -1
  58. lib/vendor/servmask/database/class-ai1wm-database-mysql.php +1 -1
  59. lib/vendor/servmask/database/class-ai1wm-database-mysqli.php +1 -1
  60. lib/vendor/servmask/database/class-ai1wm-database-utility.php +1 -1
  61. lib/vendor/servmask/database/class-ai1wm-database.php +1 -1
  62. lib/vendor/servmask/filesystem/class-ai1wm-file-htaccess.php +1 -1
  63. lib/vendor/servmask/filesystem/class-ai1wm-file-index.php +1 -1
  64. lib/vendor/servmask/filesystem/class-ai1wm-file-webconfig.php +1 -1
  65. lib/vendor/servmask/filesystem/class-ai1wm-file.php +1 -1
  66. lib/vendor/servmask/filter/class-ai1wm-extension-filter.php +1 -1
  67. lib/vendor/servmask/filter/class-ai1wm-recursive-exclude-filter.php +1 -1
  68. lib/vendor/servmask/iterator/class-ai1wm-recursive-directory-iterator.php +1 -1
  69. lib/view/assets/javascript/backups.min.js +8 -8
  70. lib/view/assets/javascript/export.min.js +12 -12
  71. lib/view/assets/javascript/import.min.js +1200 -915
  72. lib/view/assets/javascript/updater.min.js +2 -2
  73. lib/view/backups/index.php +2 -2
  74. lib/view/common/leave-feedback.php +3 -3
  75. lib/view/export/advanced-settings.php +2 -0
  76. lib/view/export/index.php +1 -1
  77. lib/view/import/index.php +1 -1
  78. loader.php +7 -1
  79. readme.txt +9 -1
  80. uninstall.php +1 -1
all-in-one-wp-migration.php CHANGED
@@ -5,12 +5,12 @@
5
  * Description: Migration tool for all your blog data. Import or Export your blog content with a single click.
6
  * Author: ServMask
7
  * Author URI: https://servmask.com/
8
- * Version: 6.39
9
  * Text Domain: all-in-one-wp-migration
10
  * Domain Path: /languages
11
  * Network: True
12
  *
13
- * Copyright (C) 2014-2016 ServMask Inc.
14
  *
15
  * This program is free software: you can redistribute it and/or modify
16
  * it under the terms of the GNU General Public License as published by
5
  * Description: Migration tool for all your blog data. Import or Export your blog content with a single click.
6
  * Author: ServMask
7
  * Author URI: https://servmask.com/
8
+ * Version: 6.40
9
  * Text Domain: all-in-one-wp-migration
10
  * Domain Path: /languages
11
  * Network: True
12
  *
13
+ * Copyright (C) 2014-2017 ServMask Inc.
14
  *
15
  * This program is free software: you can redistribute it and/or modify
16
  * it under the terms of the GNU General Public License as published by
constants.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@ define( 'AI1WM_DEBUG', false );
31
  // ==================
32
  // = Plugin Version =
33
  // ==================
34
- define( 'AI1WM_VERSION', '6.39' );
35
 
36
  // ===============
37
  // = Plugin Name =
@@ -123,6 +123,11 @@ define( 'AI1WM_ARCHIVE_TOOLS_URL', 'https://servmask.com/archive/tools' );
123
  // =========================
124
  define( 'AI1WM_TABLE_PREFIX', 'SERVMASK_PREFIX_' );
125
 
 
 
 
 
 
126
  // =========================
127
  // = Archive Database Name =
128
  // =========================
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
31
  // ==================
32
  // = Plugin Version =
33
  // ==================
34
+ define( 'AI1WM_VERSION', '6.40' );
35
 
36
  // ===============
37
  // = Plugin Name =
123
  // =========================
124
  define( 'AI1WM_TABLE_PREFIX', 'SERVMASK_PREFIX_' );
125
 
126
+ // ========================
127
+ // = Archive Backups Name =
128
+ // ========================
129
+ define( 'AI1WM_BACKUPS_NAME', 'ai1wm-backups' );
130
+
131
  // =========================
132
  // = Archive Database Name =
133
  // =========================
deprecated.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
exceptions.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
functions.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -469,17 +469,10 @@ function ai1wm_table_prefix( $blog_id = null ) {
469
  */
470
  function ai1wm_content_filters( $filters = array() ) {
471
  return array_merge( $filters, array(
472
- 'index.php',
473
- 'ai1wm-backups',
474
- 'object-cache.php',
475
- 'database.sql',
476
- 'package.json',
477
- 'multisite.json',
478
- 'blogs.json',
479
- 'filemap.list',
480
- 'themes' . DIRECTORY_SEPARATOR . 'index.php',
481
- 'plugins' . DIRECTORY_SEPARATOR . 'index.php',
482
- 'uploads' . DIRECTORY_SEPARATOR . 'index.php',
483
  ) );
484
  }
485
 
@@ -643,6 +636,7 @@ function ai1wm_active_plugins() {
643
  /**
644
  * Set active sitewide plugins (inspired by WordPress activate_plugins() function)
645
  *
 
646
  * @return boolean
647
  */
648
  function ai1wm_activate_sitewide_plugins( $plugins ) {
@@ -650,7 +644,7 @@ function ai1wm_activate_sitewide_plugins( $plugins ) {
650
 
651
  // Add plugins
652
  foreach ( $plugins as $plugin ) {
653
- if ( ! isset( $current[ $plugin ] ) ) {
654
  $current[ $plugin ] = time();
655
  }
656
  }
@@ -661,6 +655,7 @@ function ai1wm_activate_sitewide_plugins( $plugins ) {
661
  /**
662
  * Set active plugins (inspired by WordPress activate_plugins() function)
663
  *
 
664
  * @return boolean
665
  */
666
  function ai1wm_activate_plugins( $plugins ) {
@@ -668,7 +663,7 @@ function ai1wm_activate_plugins( $plugins ) {
668
 
669
  // Add plugins
670
  foreach ( $plugins as $plugin ) {
671
- if ( ! in_array( $plugin, $current ) ) {
672
  $current[] = $plugin;
673
  }
674
  }
@@ -751,7 +746,7 @@ function ai1wm_write( $handle, $content ) {
751
  if ( ( $meta = stream_get_meta_data( $handle ) ) ) {
752
  throw new Ai1wm_Not_Writable_Exception( sprintf( __( 'Unable to write to: %s', AI1WM_PLUGIN_NAME ), $meta['uri'] ) );
753
  }
754
- } elseif ( strlen( $content ) !== $write_result ) {
755
  throw new Ai1wm_Quota_Exceeded_Exception( __( 'Out of disk space.', AI1WM_PLUGIN_NAME ) );
756
  }
757
 
@@ -812,3 +807,97 @@ function ai1wm_copy( $source_file, $destination_file ) {
812
  ai1wm_close( $source_handle );
813
  ai1wm_close( $destination_handle );
814
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
469
  */
470
  function ai1wm_content_filters( $filters = array() ) {
471
  return array_merge( $filters, array(
472
+ AI1WM_BACKUPS_NAME,
473
+ AI1WM_PACKAGE_NAME,
474
+ AI1WM_MULTISITE_NAME,
475
+ AI1WM_DATABASE_NAME,
 
 
 
 
 
 
 
476
  ) );
477
  }
478
 
636
  /**
637
  * Set active sitewide plugins (inspired by WordPress activate_plugins() function)
638
  *
639
+ * @param array $plugins List of plugins
640
  * @return boolean
641
  */
642
  function ai1wm_activate_sitewide_plugins( $plugins ) {
644
 
645
  // Add plugins
646
  foreach ( $plugins as $plugin ) {
647
+ if ( ! isset( $current[ $plugin ] ) && ! is_wp_error( validate_plugin( $plugin ) ) ) {
648
  $current[ $plugin ] = time();
649
  }
650
  }
655
  /**
656
  * Set active plugins (inspired by WordPress activate_plugins() function)
657
  *
658
+ * @param array $plugins List of plugins
659
  * @return boolean
660
  */
661
  function ai1wm_activate_plugins( $plugins ) {
663
 
664
  // Add plugins
665
  foreach ( $plugins as $plugin ) {
666
+ if ( ! in_array( $plugin, $current ) && ! is_wp_error( validate_plugin( $plugin ) ) ) {
667
  $current[] = $plugin;
668
  }
669
  }
746
  if ( ( $meta = stream_get_meta_data( $handle ) ) ) {
747
  throw new Ai1wm_Not_Writable_Exception( sprintf( __( 'Unable to write to: %s', AI1WM_PLUGIN_NAME ), $meta['uri'] ) );
748
  }
749
+ } elseif ( strlen( $content ) !== $write_result ) {
750
  throw new Ai1wm_Quota_Exceeded_Exception( __( 'Out of disk space.', AI1WM_PLUGIN_NAME ) );
751
  }
752
 
807
  ai1wm_close( $source_handle );
808
  ai1wm_close( $destination_handle );
809
  }
810
+
811
+ /**
812
+ * Sanitize path
813
+ *
814
+ * @param string $path Path string
815
+ * @param boolean $leading_slash Add leading slash
816
+ * @param boolean $trailing_slash Add trailing slash
817
+ * @return string
818
+ */
819
+ function ai1wm_sanitize_path( $path, $leading_slash = false, $trailing_slash = false ) {
820
+ // Strip leadning and trailing whitespaces
821
+ $path = trim( $path );
822
+
823
+ // Strip leading backward and forward slashes
824
+ $path = ltrim( $path, '/\\' );
825
+
826
+ // Strip trailing backward and forward slashes
827
+ $path = rtrim( $path, '/\\' );
828
+
829
+ // Add forward leading slash
830
+ if ( $leading_slash ) {
831
+ $path = sprintf( '/%s', $path );
832
+ }
833
+
834
+ // Add forward trailing slash
835
+ if ( $trailing_slash ) {
836
+ $path = sprintf( '%s/', $path );
837
+ }
838
+
839
+ return preg_replace( '/[\\\\\/]+/', '/', $path );
840
+ }
841
+
842
+ /**
843
+ * Get the size of file in bytes
844
+ *
845
+ * This method supports files > 2GB on PHP x86
846
+ *
847
+ * @param string $file_path Path to the file
848
+ * @param bool $as_string Return the filesize as string instead of BigInteger
849
+ *
850
+ * @return mixed Math_BigInteger|string|null
851
+ */
852
+ function ai1wm_filesize( $file_path, $as_string = true ) {
853
+ $chunk_size = 2000000; // 2MB
854
+ $file_size = new Math_BigInteger( 0 );
855
+
856
+ try {
857
+ $file_handle = ai1wm_open( $file_path, 'rb' );
858
+
859
+ while ( ! feof( $file_handle ) ) {
860
+ $bytes = ai1wm_read( $file_handle, $chunk_size );
861
+ $file_size = $file_size->add( new Math_BigInteger( strlen( $bytes ) ) );
862
+ }
863
+
864
+ ai1wm_close( $file_handle );
865
+
866
+ return $as_string ? $file_size->toString() : $file_size;
867
+ } catch ( Exception $e ) {
868
+ return null;
869
+ }
870
+ }
871
+
872
+ /**
873
+ * Return the smaller of two numbers
874
+ *
875
+ * @param Math_BigInteger $a First number
876
+ * @param Math_BigInteger $b Second number
877
+ *
878
+ * @return Math_BigInteger
879
+ */
880
+ function ai1wm_find_smaller_number( Math_BigInteger $a, Math_BigInteger $b ) {
881
+ if ( $a->compare( $b ) === -1 ) {
882
+ return $a;
883
+ }
884
+
885
+ return $b;
886
+ }
887
+
888
+ /**
889
+ * Wrapper around fseek
890
+ *
891
+ * This function works with offsets that are > PHP_INT_MAX
892
+ *
893
+ * @param resource $file_handle Handle to the file
894
+ * @param Math_BigInteger $offset Offset of the file
895
+ */
896
+ function ai1wm_fseek( $file_handle, Math_BigInteger $offset ) {
897
+ $chunk_size = ai1wm_find_smaller_number( new Math_BigInteger( 2000000 ), $offset );
898
+ while ( ! feof( $file_handle ) && $offset->toString() != '0' ) {
899
+ $bytes = ai1wm_read( $file_handle, $chunk_size->toInteger() );
900
+ $offset = $offset->subtract( new Math_BigInteger( strlen( $bytes ) ) );
901
+ $chunk_size = ai1wm_find_smaller_number( $chunk_size, $offset );
902
+ }
903
+ }
lib/controller/class-ai1wm-backups-controller.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-export-controller.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-feedback-controller.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -29,26 +29,26 @@ class Ai1wm_Feedback_Controller {
29
 
30
  // Set Type
31
  $type = null;
32
- if ( isset( $_POST['ai1wm-type'] ) ) {
33
- $type = trim( $_POST['ai1wm-type'] );
34
  }
35
 
36
  // Set E-mail
37
  $email = null;
38
- if ( isset( $_POST['ai1wm-email'] ) ) {
39
- $email = trim( $_POST['ai1wm-email'] );
40
  }
41
 
42
  // Set Message
43
  $message = null;
44
- if ( isset( $_POST['ai1wm-message'] ) ) {
45
- $message = trim( $_POST['ai1wm-message'] );
46
  }
47
 
48
  // Set Terms
49
  $terms = false;
50
- if ( isset( $_POST['ai1wm-terms'] ) ) {
51
- $terms = (bool) $_POST['ai1wm-terms'];
52
  }
53
 
54
  $model = new Ai1wm_Feedback;
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
29
 
30
  // Set Type
31
  $type = null;
32
+ if ( isset( $_POST['ai1wm_type'] ) ) {
33
+ $type = trim( $_POST['ai1wm_type'] );
34
  }
35
 
36
  // Set E-mail
37
  $email = null;
38
+ if ( isset( $_POST['ai1wm_email'] ) ) {
39
+ $email = trim( $_POST['ai1wm_email'] );
40
  }
41
 
42
  // Set Message
43
  $message = null;
44
+ if ( isset( $_POST['ai1wm_message'] ) ) {
45
+ $message = trim( $_POST['ai1wm_message'] );
46
  }
47
 
48
  // Set Terms
49
  $terms = false;
50
+ if ( isset( $_POST['ai1wm_terms'] ) ) {
51
+ $terms = (bool) $_POST['ai1wm_terms'];
52
  }
53
 
54
  $model = new Ai1wm_Feedback;
lib/controller/class-ai1wm-import-controller.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-main-controller.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -86,8 +86,17 @@ class Ai1wm_Main_Controller {
86
  // Export and import buttons
87
  add_action( 'plugins_loaded', array( $this, 'ai1wm_buttons' ), 10 );
88
 
 
 
 
 
 
 
 
 
 
89
  // Add updater scripts and styles
90
- add_action( 'admin_enqueue_scripts', array( $this, 'register_updater_scripts_and_styles' ) );
91
 
92
  return $this;
93
  }
@@ -116,7 +125,12 @@ class Ai1wm_Main_Controller {
116
  // Add export commands
117
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Init::execute', 5 );
118
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Compatibility::execute', 5 );
119
- add_filter( 'ai1wm_export', 'Ai1wm_Export_Resolve::execute', 5 );
 
 
 
 
 
120
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Archive::execute', 10 );
121
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Config::execute', 50 );
122
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Enumerate::execute', 100 );
@@ -128,7 +142,12 @@ class Ai1wm_Main_Controller {
128
  // Add import commands
129
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Upload::execute', 5 );
130
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Compatibility::execute', 10 );
131
- add_filter( 'ai1wm_import', 'Ai1wm_Import_Resolve::execute', 10 );
 
 
 
 
 
132
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Validate::execute', 50 );
133
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Confirm::execute', 100 );
134
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Blogs::execute', 150 );
@@ -304,7 +323,7 @@ class Ai1wm_Main_Controller {
304
  );
305
 
306
  // sublevel Export menu
307
- $export_page_hook_suffix = add_submenu_page(
308
  'site-migration-export',
309
  __( 'Export', AI1WM_PLUGIN_NAME ),
310
  __( 'Export', AI1WM_PLUGIN_NAME ),
@@ -312,13 +331,9 @@ class Ai1wm_Main_Controller {
312
  'site-migration-export',
313
  'Ai1wm_Export_Controller::index'
314
  );
315
- add_action(
316
- 'admin_print_scripts-' . $export_page_hook_suffix,
317
- array( $this, 'register_export_scripts_and_styles' )
318
- );
319
 
320
  // sublevel Import menu
321
- $import_page_hook_suffix = add_submenu_page(
322
  'site-migration-export',
323
  __( 'Import', AI1WM_PLUGIN_NAME ),
324
  __( 'Import', AI1WM_PLUGIN_NAME ),
@@ -326,13 +341,9 @@ class Ai1wm_Main_Controller {
326
  'site-migration-import',
327
  'Ai1wm_Import_Controller::index'
328
  );
329
- add_action(
330
- 'admin_print_scripts-' . $import_page_hook_suffix,
331
- array( $this, 'register_import_scripts_and_styles' )
332
- );
333
 
334
  // sublevel Backups menu
335
- $backups_page_hook_suffix = add_submenu_page(
336
  'site-migration-export',
337
  __( 'Backups', AI1WM_PLUGIN_NAME ),
338
  __( 'Backups', AI1WM_PLUGIN_NAME ),
@@ -340,10 +351,6 @@ class Ai1wm_Main_Controller {
340
  'site-migration-backups',
341
  'Ai1wm_Backups_Controller::index'
342
  );
343
- add_action(
344
- 'admin_print_scripts-' . $backups_page_hook_suffix,
345
- array( $this, 'register_backups_scripts_and_styles' )
346
- );
347
  }
348
 
349
  /**
@@ -351,21 +358,25 @@ class Ai1wm_Main_Controller {
351
  *
352
  * @return void
353
  */
354
- public function register_export_scripts_and_styles() {
355
- do_action( 'ai1mw-register-export-scripts-and-styles' );
 
 
 
 
356
 
357
  // we don't want heartbeat to occur when exporting
358
  wp_deregister_script( 'heartbeat' );
359
 
 
 
 
 
360
  wp_enqueue_script(
361
  'ai1wm-js-export',
362
  Ai1wm_Template::asset_link( 'javascript/export.min.js' ),
363
  array( 'jquery' )
364
  );
365
- wp_enqueue_style(
366
- 'ai1wm-css-export',
367
- Ai1wm_Template::asset_link( 'css/export.min.css' )
368
- );
369
  wp_localize_script( 'ai1wm-js-export', 'ai1wm_feedback', array(
370
  'ajax' => array(
371
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_feedback' ) ),
@@ -392,21 +403,25 @@ class Ai1wm_Main_Controller {
392
  *
393
  * @return void
394
  */
395
- public function register_import_scripts_and_styles() {
396
- do_action( 'ai1mw-register-import-scripts-and-styles' );
 
 
 
 
397
 
398
  // we don't want heartbeat to occur when importing
399
  wp_deregister_script( 'heartbeat' );
400
 
 
 
 
 
401
  wp_enqueue_script(
402
  'ai1wm-js-import',
403
  Ai1wm_Template::asset_link( 'javascript/import.min.js' ),
404
  array( 'jquery' )
405
  );
406
- wp_enqueue_style(
407
- 'ai1wm-css-import',
408
- Ai1wm_Template::asset_link( 'css/import.min.css' )
409
- );
410
  wp_localize_script( 'ai1wm-js-import', 'ai1wm_uploader', array(
411
  'chunk_size' => apply_filters( 'ai1wm_max_chunk_size', AI1WM_MAX_CHUNK_SIZE ),
412
  'max_retries' => apply_filters( 'ai1wm_max_chunk_retries', AI1WM_MAX_CHUNK_RETRIES ),
@@ -468,18 +483,22 @@ class Ai1wm_Main_Controller {
468
  *
469
  * @return void
470
  */
471
- public function register_backups_scripts_and_styles() {
472
- do_action( 'ai1mw-register-backups-scripts-and-styles' );
 
 
 
 
473
 
 
 
 
 
474
  wp_enqueue_script(
475
  'ai1wm-js-backups',
476
  Ai1wm_Template::asset_link( 'javascript/backups.min.js' ),
477
  array( 'jquery' )
478
  );
479
- wp_enqueue_style(
480
- 'ai1wm-css-backups',
481
- Ai1wm_Template::asset_link( 'css/backups.min.css' )
482
- );
483
  wp_localize_script( 'ai1wm-js-backups', 'ai1wm_feedback', array(
484
  'ajax' => array(
485
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_feedback' ) ),
@@ -516,7 +535,7 @@ class Ai1wm_Main_Controller {
516
  return;
517
  }
518
 
519
- do_action( 'ai1mw-register-updater-scripts-and-styles' );
520
 
521
  wp_enqueue_style(
522
  'ai1wm-css-updater',
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
86
  // Export and import buttons
87
  add_action( 'plugins_loaded', array( $this, 'ai1wm_buttons' ), 10 );
88
 
89
+ // Add export scripts and styles
90
+ add_action( 'admin_enqueue_scripts', array( $this, 'register_export_scripts_and_styles' ), 10 );
91
+
92
+ // Add import scripts and styles
93
+ add_action( 'admin_enqueue_scripts', array( $this, 'register_import_scripts_and_styles' ), 10 );
94
+
95
+ // Add backups scripts and styles
96
+ add_action( 'admin_enqueue_scripts', array( $this, 'register_backups_scripts_and_styles' ), 10 );
97
+
98
  // Add updater scripts and styles
99
+ add_action( 'admin_enqueue_scripts', array( $this, 'register_updater_scripts_and_styles' ), 10 );
100
 
101
  return $this;
102
  }
125
  // Add export commands
126
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Init::execute', 5 );
127
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Compatibility::execute', 5 );
128
+
129
+ // Do not resolve URL address
130
+ if ( ! isset( $_REQUEST['ai1wm_manual_export'] ) ) {
131
+ add_filter( 'ai1wm_export', 'Ai1wm_Export_Resolve::execute', 5 );
132
+ }
133
+
134
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Archive::execute', 10 );
135
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Config::execute', 50 );
136
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Enumerate::execute', 100 );
142
  // Add import commands
143
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Upload::execute', 5 );
144
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Compatibility::execute', 10 );
145
+
146
+ // Do not resolve URL address
147
+ if ( ! isset( $_REQUEST['ai1wm_manual_import'] ) && ! isset( $_REQUEST['ai1wm_manual_backups'] ) ) {
148
+ add_filter( 'ai1wm_import', 'Ai1wm_Import_Resolve::execute', 10 );
149
+ }
150
+
151
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Validate::execute', 50 );
152
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Confirm::execute', 100 );
153
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Blogs::execute', 150 );
323
  );
324
 
325
  // sublevel Export menu
326
+ add_submenu_page(
327
  'site-migration-export',
328
  __( 'Export', AI1WM_PLUGIN_NAME ),
329
  __( 'Export', AI1WM_PLUGIN_NAME ),
331
  'site-migration-export',
332
  'Ai1wm_Export_Controller::index'
333
  );
 
 
 
 
334
 
335
  // sublevel Import menu
336
+ add_submenu_page(
337
  'site-migration-export',
338
  __( 'Import', AI1WM_PLUGIN_NAME ),
339
  __( 'Import', AI1WM_PLUGIN_NAME ),
341
  'site-migration-import',
342
  'Ai1wm_Import_Controller::index'
343
  );
 
 
 
 
344
 
345
  // sublevel Backups menu
346
+ add_submenu_page(
347
  'site-migration-export',
348
  __( 'Backups', AI1WM_PLUGIN_NAME ),
349
  __( 'Backups', AI1WM_PLUGIN_NAME ),
351
  'site-migration-backups',
352
  'Ai1wm_Backups_Controller::index'
353
  );
 
 
 
 
354
  }
355
 
356
  /**
358
  *
359
  * @return void
360
  */
361
+ public function register_export_scripts_and_styles( $hook ) {
362
+ if ( 'toplevel_page_site-migration-export' !== $hook ) {
363
+ return;
364
+ }
365
+
366
+ do_action( 'ai1mw_register_export_scripts_and_styles' );
367
 
368
  // we don't want heartbeat to occur when exporting
369
  wp_deregister_script( 'heartbeat' );
370
 
371
+ wp_enqueue_style(
372
+ 'ai1wm-css-export',
373
+ Ai1wm_Template::asset_link( 'css/export.min.css' )
374
+ );
375
  wp_enqueue_script(
376
  'ai1wm-js-export',
377
  Ai1wm_Template::asset_link( 'javascript/export.min.js' ),
378
  array( 'jquery' )
379
  );
 
 
 
 
380
  wp_localize_script( 'ai1wm-js-export', 'ai1wm_feedback', array(
381
  'ajax' => array(
382
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_feedback' ) ),
403
  *
404
  * @return void
405
  */
406
+ public function register_import_scripts_and_styles( $hook ) {
407
+ if ( 'all-in-one-wp-migration_page_site-migration-import' !== $hook ) {
408
+ return;
409
+ }
410
+
411
+ do_action( 'ai1mw_register_import_scripts_and_styles' );
412
 
413
  // we don't want heartbeat to occur when importing
414
  wp_deregister_script( 'heartbeat' );
415
 
416
+ wp_enqueue_style(
417
+ 'ai1wm-css-import',
418
+ Ai1wm_Template::asset_link( 'css/import.min.css' )
419
+ );
420
  wp_enqueue_script(
421
  'ai1wm-js-import',
422
  Ai1wm_Template::asset_link( 'javascript/import.min.js' ),
423
  array( 'jquery' )
424
  );
 
 
 
 
425
  wp_localize_script( 'ai1wm-js-import', 'ai1wm_uploader', array(
426
  'chunk_size' => apply_filters( 'ai1wm_max_chunk_size', AI1WM_MAX_CHUNK_SIZE ),
427
  'max_retries' => apply_filters( 'ai1wm_max_chunk_retries', AI1WM_MAX_CHUNK_RETRIES ),
483
  *
484
  * @return void
485
  */
486
+ public function register_backups_scripts_and_styles( $hook ) {
487
+ if ( 'all-in-one-wp-migration_page_site-migration-backups' !== $hook ) {
488
+ return;
489
+ }
490
+
491
+ do_action( 'ai1mw_register_backups_scripts_and_styles' );
492
 
493
+ wp_enqueue_style(
494
+ 'ai1wm-css-backups',
495
+ Ai1wm_Template::asset_link( 'css/backups.min.css' )
496
+ );
497
  wp_enqueue_script(
498
  'ai1wm-js-backups',
499
  Ai1wm_Template::asset_link( 'javascript/backups.min.js' ),
500
  array( 'jquery' )
501
  );
 
 
 
 
502
  wp_localize_script( 'ai1wm-js-backups', 'ai1wm_feedback', array(
503
  'ajax' => array(
504
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_feedback' ) ),
535
  return;
536
  }
537
 
538
+ do_action( 'ai1mw_register_updater_scripts_and_styles' );
539
 
540
  wp_enqueue_style(
541
  'ai1wm-css-updater',
lib/controller/class-ai1wm-report-controller.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -29,20 +29,20 @@ class Ai1wm_Report_Controller {
29
 
30
  // Set E-mail
31
  $email = null;
32
- if ( isset( $_POST['ai1wm-email'] ) ) {
33
- $email = trim( $_POST['ai1wm-email'] );
34
  }
35
 
36
  // Set Message
37
  $message = null;
38
- if ( isset( $_POST['ai1wm-message'] ) ) {
39
- $message = trim( $_POST['ai1wm-message'] );
40
  }
41
 
42
  // Set Terms
43
  $terms = false;
44
- if ( isset( $_POST['ai1wm-terms'] ) ) {
45
- $terms = (bool) $_POST['ai1wm-terms'];
46
  }
47
 
48
  $model = new Ai1wm_Report;
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
29
 
30
  // Set E-mail
31
  $email = null;
32
+ if ( isset( $_POST['ai1wm_email'] ) ) {
33
+ $email = trim( $_POST['ai1wm_email'] );
34
  }
35
 
36
  // Set Message
37
  $message = null;
38
+ if ( isset( $_POST['ai1wm_message'] ) ) {
39
+ $message = trim( $_POST['ai1wm_message'] );
40
  }
41
 
42
  // Set Terms
43
  $terms = false;
44
+ if ( isset( $_POST['ai1wm_terms'] ) ) {
45
+ $terms = (bool) $_POST['ai1wm_terms'];
46
  }
47
 
48
  $model = new Ai1wm_Report;
lib/controller/class-ai1wm-resolve-controller.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-status-controller.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-updater-controller.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -57,14 +57,14 @@ class Ai1wm_Updater_Controller {
57
 
58
  // Set uuid
59
  $uuid = null;
60
- if ( isset( $_POST['ai1wm-uuid'] ) ) {
61
- $uuid = trim( $_POST['ai1wm-uuid'] );
62
  }
63
 
64
  // Set extension
65
  $extension = null;
66
- if ( isset( $_POST['ai1wm-extension'] ) ) {
67
- $extension = trim( $_POST['ai1wm-extension'] );
68
  }
69
 
70
  // Verify whether extension exists
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
57
 
58
  // Set uuid
59
  $uuid = null;
60
+ if ( isset( $_POST['ai1wm_uuid'] ) ) {
61
+ $uuid = trim( $_POST['ai1wm_uuid'] );
62
  }
63
 
64
  // Set extension
65
  $extension = null;
66
+ if ( isset( $_POST['ai1wm_extension'] ) ) {
67
+ $extension = trim( $_POST['ai1wm_extension'] );
68
  }
69
 
70
  // Verify whether extension exists
lib/model/class-ai1wm-backups.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -50,7 +50,7 @@ class Ai1wm_Backups {
50
  $backups[] = array(
51
  'filename' => $item->getFilename(),
52
  'mtime' => null,
53
- 'size' => null,
54
  );
55
  }
56
  }
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
50
  $backups[] = array(
51
  'filename' => $item->getFilename(),
52
  'mtime' => null,
53
+ 'size' => ai1wm_filesize( $item->getPathname() ),
54
  );
55
  }
56
  }
lib/model/class-ai1wm-compatibility.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-deprecated.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-extensions.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-feedback.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-handler.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-http.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-log.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-report.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-status.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -54,7 +54,7 @@ class Ai1wm_Status {
54
  }
55
 
56
  public static function log( $data = array() ) {
57
- if ( ! defined( 'DOING_CRON' ) ) {
58
  update_option( AI1WM_STATUS, $data );
59
  }
60
  }
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
54
  }
55
 
56
  public static function log( $data = array() ) {
57
+ if ( isset( $_REQUEST['ai1wm_manual_export'] ) || isset( $_REQUEST['ai1wm_manual_import'] ) || isset( $_REQUEST['ai1wm_manual_backups'] ) ) {
58
  update_option( AI1WM_STATUS, $data );
59
  }
60
  }
lib/model/class-ai1wm-template.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-updater.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-archive.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-clean.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-compatibility.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,11 @@
26
  class Ai1wm_Export_Compatibility {
27
 
28
  public static function execute( $params ) {
 
 
 
 
 
29
  $messages = Ai1wm_Compatibility::get( $params );
30
 
31
  // Set messages
@@ -39,6 +44,7 @@ class Ai1wm_Export_Compatibility {
39
  // Manual export
40
  if ( empty( $params['ai1wm_manual_export'] ) ) {
41
  if ( function_exists( 'wp_mail' ) ) {
 
42
  // Set recipient
43
  $recipient = get_option( 'admin_email', '' );
44
 
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
26
  class Ai1wm_Export_Compatibility {
27
 
28
  public static function execute( $params ) {
29
+
30
+ // Set progress
31
+ Ai1wm_Status::info( __( 'Checking extensions compatibility...', AI1WM_PLUGIN_NAME ) );
32
+
33
+ // Get messages
34
  $messages = Ai1wm_Compatibility::get( $params );
35
 
36
  // Set messages
44
  // Manual export
45
  if ( empty( $params['ai1wm_manual_export'] ) ) {
46
  if ( function_exists( 'wp_mail' ) ) {
47
+
48
  // Set recipient
49
  $recipient = get_option( 'admin_email', '' );
50
 
lib/model/export/class-ai1wm-export-config.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -58,11 +58,7 @@ class Ai1wm_Export_Config {
58
  $config['Plugin'] = array( 'Version' => AI1WM_VERSION );
59
 
60
  // Set active plugins
61
- if ( isset( $params['options']['no_plugins'] ) ) {
62
- $config['Plugins'] = array();
63
- } else {
64
- $config['Plugins'] = array_values( array_diff( ai1wm_active_plugins(), ai1wm_active_servmask_plugins() ) );
65
- }
66
 
67
  // Set WordPress version and content
68
  $config['WordPress'] = array( 'Version' => $wp_version, 'Content' => WP_CONTENT_DIR );
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
58
  $config['Plugin'] = array( 'Version' => AI1WM_VERSION );
59
 
60
  // Set active plugins
61
+ $config['Plugins'] = array_values( array_diff( ai1wm_active_plugins(), ai1wm_active_servmask_plugins() ) );
 
 
 
 
62
 
63
  // Set WordPress version and content
64
  $config['WordPress'] = array( 'Version' => $wp_version, 'Content' => WP_CONTENT_DIR );
lib/model/export/class-ai1wm-export-content.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-database.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-download.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-enumerate.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -72,7 +72,7 @@ class Ai1wm_Export_Enumerate {
72
  // Exclude inactive plugins
73
  if ( isset( $params['options']['no_inactive_plugins'] ) ) {
74
  foreach ( get_plugins() as $plugin => $info ) {
75
- if ( is_plugin_inactive( $basename ) ) {
76
  $inactive_plugins[] = 'plugins' . DIRECTORY_SEPARATOR .
77
  ( ( dirname( $plugin ) === '.' ) ? basename( $plugin ) : dirname( $plugin ) );
78
  }
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
72
  // Exclude inactive plugins
73
  if ( isset( $params['options']['no_inactive_plugins'] ) ) {
74
  foreach ( get_plugins() as $plugin => $info ) {
75
+ if ( is_plugin_inactive( $plugin ) ) {
76
  $inactive_plugins[] = 'plugins' . DIRECTORY_SEPARATOR .
77
  ( ( dirname( $plugin ) === '.' ) ? basename( $plugin ) : dirname( $plugin ) );
78
  }
lib/model/export/class-ai1wm-export-init.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -27,9 +27,6 @@ class Ai1wm_Export_Init {
27
 
28
  public static function execute( $params ) {
29
 
30
- // Set progress
31
- Ai1wm_Status::info( __( 'Preparing to export...', AI1WM_PLUGIN_NAME ) );
32
-
33
  // Set archive
34
  if ( empty( $params['archive'] ) ) {
35
  $params['archive'] = ai1wm_archive_file();
@@ -40,9 +37,6 @@ class Ai1wm_Export_Init {
40
  $params['storage'] = ai1wm_storage_folder();
41
  }
42
 
43
- // Set progress
44
- Ai1wm_Status::info( __( 'Done preparing to export.', AI1WM_PLUGIN_NAME ) );
45
-
46
  return $params;
47
  }
48
  }
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
27
 
28
  public static function execute( $params ) {
29
 
 
 
 
30
  // Set archive
31
  if ( empty( $params['archive'] ) ) {
32
  $params['archive'] = ai1wm_archive_file();
37
  $params['storage'] = ai1wm_storage_folder();
38
  }
39
 
 
 
 
40
  return $params;
41
  }
42
  }
lib/model/export/class-ai1wm-export-resolve.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -31,9 +31,7 @@ class Ai1wm_Export_Resolve {
31
  Ai1wm_Status::info( __( 'Resolving URL address...', AI1WM_PLUGIN_NAME ) );
32
 
33
  // HTTP resolve
34
- if ( empty( $params['ai1wm_manual_export'] ) ) {
35
- Ai1wm_Http::resolve( admin_url( 'admin-ajax.php?action=ai1wm_resolve' ) );
36
- }
37
 
38
  // Set progress
39
  Ai1wm_Status::info( __( 'Done resolving URL address...', AI1WM_PLUGIN_NAME ) );
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
31
  Ai1wm_Status::info( __( 'Resolving URL address...', AI1WM_PLUGIN_NAME ) );
32
 
33
  // HTTP resolve
34
+ Ai1wm_Http::resolve( admin_url( 'admin-ajax.php?action=ai1wm_resolve' ) );
 
 
35
 
36
  // Set progress
37
  Ai1wm_Status::info( __( 'Done resolving URL address...', AI1WM_PLUGIN_NAME ) );
lib/model/http/class-ai1wm-http-abstract.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/http/class-ai1wm-http-curl.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/http/class-ai1wm-http-factory.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/http/class-ai1wm-http-stream.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-blogs.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-clean.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-compatibility.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,11 @@
26
  class Ai1wm_Import_Compatibility {
27
 
28
  public static function execute( $params ) {
 
 
 
 
 
29
  $messages = Ai1wm_Compatibility::get( $params );
30
 
31
  // Set messages
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
26
  class Ai1wm_Import_Compatibility {
27
 
28
  public static function execute( $params ) {
29
+
30
+ // Set progress
31
+ Ai1wm_Status::info( __( 'Checking extensions compatibility...', AI1WM_PLUGIN_NAME ) );
32
+
33
+ // Get messages
34
  $messages = Ai1wm_Compatibility::get( $params );
35
 
36
  // Set messages
lib/model/import/class-ai1wm-import-confirm.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-content.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-database.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-done.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-enumerate.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-plugins.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -28,25 +28,19 @@ class Ai1wm_Import_Plugins {
28
  public static function execute( $params ) {
29
 
30
  // Set progress
31
- Ai1wm_Status::info( __( 'Activating plugins...', AI1WM_PLUGIN_NAME ) );
32
 
33
  // Open the archive file for reading
34
  $archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );
35
 
36
- // Include WordPress files
37
- $include_files = array_keys( _get_dropins() );
38
-
39
- // Include mu-plugins files
40
- $include_files = array_merge( $include_files, array( AI1WM_MUPLUGINS_NAME ) );
41
-
42
- // Unpack WordPress files and mu-plugins files
43
- $archive->extract_by_files_array( WP_CONTENT_DIR, $include_files );
44
 
45
  // Close the archive file
46
  $archive->close();
47
 
48
  // Set progress
49
- Ai1wm_Status::info( __( 'Done activating plugins...', AI1WM_PLUGIN_NAME ) );
50
 
51
  return $params;
52
  }
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
28
  public static function execute( $params ) {
29
 
30
  // Set progress
31
+ Ai1wm_Status::info( __( 'Activating mu-plugins...', AI1WM_PLUGIN_NAME ) );
32
 
33
  // Open the archive file for reading
34
  $archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );
35
 
36
+ // Unpack mu-plugins files
37
+ $archive->extract_by_files_array( WP_CONTENT_DIR, array( AI1WM_MUPLUGINS_NAME ) );
 
 
 
 
 
 
38
 
39
  // Close the archive file
40
  $archive->close();
41
 
42
  // Set progress
43
+ Ai1wm_Status::info( __( 'Done activating mu-plugins...', AI1WM_PLUGIN_NAME ) );
44
 
45
  return $params;
46
  }
lib/model/import/class-ai1wm-import-resolve.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -31,9 +31,7 @@ class Ai1wm_Import_Resolve {
31
  Ai1wm_Status::info( __( 'Resolving URL address...', AI1WM_PLUGIN_NAME ) );
32
 
33
  // HTTP resolve
34
- if ( empty( $params['ai1wm_manual_import'] ) && empty( $params['ai1wm_manual_backups'] ) ) {
35
- Ai1wm_Http::resolve( admin_url( 'admin-ajax.php?action=ai1wm_resolve' ) );
36
- }
37
 
38
  // Set progress
39
  Ai1wm_Status::info( __( 'Done resolving URL address...', AI1WM_PLUGIN_NAME ) );
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
31
  Ai1wm_Status::info( __( 'Resolving URL address...', AI1WM_PLUGIN_NAME ) );
32
 
33
  // HTTP resolve
34
+ Ai1wm_Http::resolve( admin_url( 'admin-ajax.php?action=ai1wm_resolve' ) );
 
 
35
 
36
  // Set progress
37
  Ai1wm_Status::info( __( 'Done resolving URL address...', AI1WM_PLUGIN_NAME ) );
lib/model/import/class-ai1wm-import-upload.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-validate.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/math/BigInteger.php ADDED
@@ -0,0 +1,3811 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! class_exists( 'Math_BigInteger' ) ) {
4
+ /**
5
+ * Pure-PHP arbitrary precision integer arithmetic library.
6
+ *
7
+ * Supports base-2, base-10, base-16, and base-256 numbers. Uses the GMP or BCMath extensions, if available,
8
+ * and an internal implementation, otherwise.
9
+ *
10
+ * PHP versions 4 and 5
11
+ *
12
+ * {@internal (all DocBlock comments regarding implementation - such as the one that follows - refer to the
13
+ * {@link MATH_BIGINTEGER_MODE_INTERNAL MATH_BIGINTEGER_MODE_INTERNAL} mode)
14
+ *
15
+ * Math_BigInteger uses base-2**26 to perform operations such as multiplication and division and
16
+ * base-2**52 (ie. two base 2**26 digits) to perform addition and subtraction. Because the largest possible
17
+ * value when multiplying two base-2**26 numbers together is a base-2**52 number, double precision floating
18
+ * point numbers - numbers that should be supported on most hardware and whose significand is 53 bits - are
19
+ * used. As a consequence, bitwise operators such as >> and << cannot be used, nor can the modulo operator %,
20
+ * which only supports integers. Although this fact will slow this library down, the fact that such a high
21
+ * base is being used should more than compensate.
22
+ *
23
+ * Numbers are stored in {@link http://en.wikipedia.org/wiki/Endianness little endian} format. ie.
24
+ * (new Math_BigInteger(pow(2, 26)))->value = array(0, 1)
25
+ *
26
+ * Useful resources are as follows:
27
+ *
28
+ * - {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf Handbook of Applied Cryptography (HAC)}
29
+ * - {@link http://math.libtomcrypt.com/files/tommath.pdf Multi-Precision Math (MPM)}
30
+ * - Java's BigInteger classes. See /j2se/src/share/classes/java/math in jdk-1_5_0-src-jrl.zip
31
+ *
32
+ * Here's an example of how to use this library:
33
+ * <code>
34
+ * <?php
35
+ * include 'Math/BigInteger.php';
36
+ *
37
+ * $a = new Math_BigInteger(2);
38
+ * $b = new Math_BigInteger(3);
39
+ *
40
+ * $c = $a->add($b);
41
+ *
42
+ * echo $c->toString(); // outputs 5
43
+ * ?>
44
+ * </code>
45
+ *
46
+ * LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
47
+ * of this software and associated documentation files (the "Software"), to deal
48
+ * in the Software without restriction, including without limitation the rights
49
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
50
+ * copies of the Software, and to permit persons to whom the Software is
51
+ * furnished to do so, subject to the following conditions:
52
+ *
53
+ * The above copyright notice and this permission notice shall be included in
54
+ * all copies or substantial portions of the Software.
55
+ *
56
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
59
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
60
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
61
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
62
+ * THE SOFTWARE.
63
+ *
64
+ * @category Math
65
+ * @package Math_BigInteger
66
+ * @author Jim Wigginton <terrafrost@php.net>
67
+ * @copyright 2006 Jim Wigginton
68
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
69
+ * @link http://pear.php.net/package/Math_BigInteger
70
+ */
71
+
72
+ /**#@+
73
+ * Reduction constants
74
+ *
75
+ * @access private
76
+ * @see self::_reduce()
77
+ */
78
+ /**
79
+ * @see self::_montgomery()
80
+ * @see self::_prepMontgomery()
81
+ */
82
+ define('MATH_BIGINTEGER_MONTGOMERY', 0);
83
+ /**
84
+ * @see self::_barrett()
85
+ */
86
+ define('MATH_BIGINTEGER_BARRETT', 1);
87
+ /**
88
+ * @see self::_mod2()
89
+ */
90
+ define('MATH_BIGINTEGER_POWEROF2', 2);
91
+ /**
92
+ * @see self::_remainder()
93
+ */
94
+ define('MATH_BIGINTEGER_CLASSIC', 3);
95
+ /**
96
+ * @see self::__clone()
97
+ */
98
+ define('MATH_BIGINTEGER_NONE', 4);
99
+ /**#@-*/
100
+
101
+ /**#@+
102
+ * Array constants
103
+ *
104
+ * Rather than create a thousands and thousands of new Math_BigInteger objects in repeated function calls to add() and
105
+ * multiply() or whatever, we'll just work directly on arrays, taking them in as parameters and returning them.
106
+ *
107
+ * @access private
108
+ */
109
+ /**
110
+ * $result[MATH_BIGINTEGER_VALUE] contains the value.
111
+ */
112
+ define('MATH_BIGINTEGER_VALUE', 0);
113
+ /**
114
+ * $result[MATH_BIGINTEGER_SIGN] contains the sign.
115
+ */
116
+ define('MATH_BIGINTEGER_SIGN', 1);
117
+ /**#@-*/
118
+
119
+ /**#@+
120
+ * @access private
121
+ * @see self::_montgomery()
122
+ * @see self::_barrett()
123
+ */
124
+ /**
125
+ * Cache constants
126
+ *
127
+ * $cache[MATH_BIGINTEGER_VARIABLE] tells us whether or not the cached data is still valid.
128
+ */
129
+ define('MATH_BIGINTEGER_VARIABLE', 0);
130
+ /**
131
+ * $cache[MATH_BIGINTEGER_DATA] contains the cached data.
132
+ */
133
+ define('MATH_BIGINTEGER_DATA', 1);
134
+ /**#@-*/
135
+
136
+ /**#@+
137
+ * Mode constants.
138
+ *
139
+ * @access private
140
+ * @see self::Math_BigInteger()
141
+ */
142
+ /**
143
+ * To use the pure-PHP implementation
144
+ */
145
+ define('MATH_BIGINTEGER_MODE_INTERNAL', 1);
146
+ /**
147
+ * To use the BCMath library
148
+ *
149
+ * (if enabled; otherwise, the internal implementation will be used)
150
+ */
151
+ define('MATH_BIGINTEGER_MODE_BCMATH', 2);
152
+ /**
153
+ * To use the GMP library
154
+ *
155
+ * (if present; otherwise, either the BCMath or the internal implementation will be used)
156
+ */
157
+ define('MATH_BIGINTEGER_MODE_GMP', 3);
158
+ /**#@-*/
159
+
160
+ /**
161
+ * Karatsuba Cutoff
162
+ *
163
+ * At what point do we switch between Karatsuba multiplication and schoolbook long multiplication?
164
+ *
165
+ * @access private
166
+ */
167
+ define('MATH_BIGINTEGER_KARATSUBA_CUTOFF', 25);
168
+
169
+ /**
170
+ * Pure-PHP arbitrary precision integer arithmetic library. Supports base-2, base-10, base-16, and base-256
171
+ * numbers.
172
+ *
173
+ * @package Math_BigInteger
174
+ * @author Jim Wigginton <terrafrost@php.net>
175
+ * @access public
176
+ */
177
+ class Math_BigInteger
178
+ {
179
+ /**
180
+ * Holds the BigInteger's value.
181
+ *
182
+ * @var array
183
+ * @access private
184
+ */
185
+ var $value;
186
+
187
+ /**
188
+ * Holds the BigInteger's magnitude.
189
+ *
190
+ * @var bool
191
+ * @access private
192
+ */
193
+ var $is_negative = false;
194
+
195
+ /**
196
+ * Precision
197
+ *
198
+ * @see self::setPrecision()
199
+ * @access private
200
+ */
201
+ var $precision = -1;
202
+
203
+ /**
204
+ * Precision Bitmask
205
+ *
206
+ * @see self::setPrecision()
207
+ * @access private
208
+ */
209
+ var $bitmask = false;
210
+
211
+ /**
212
+ * Mode independent value used for serialization.
213
+ *
214
+ * If the bcmath or gmp extensions are installed $this->value will be a non-serializable resource, hence the need for
215
+ * a variable that'll be serializable regardless of whether or not extensions are being used. Unlike $this->value,
216
+ * however, $this->hex is only calculated when $this->__sleep() is called.
217
+ *
218
+ * @see self::__sleep()
219
+ * @see self::__wakeup()
220
+ * @var string
221
+ * @access private
222
+ */
223
+ var $hex;
224
+
225
+ /**
226
+ * Converts base-2, base-10, base-16, and binary strings (base-256) to BigIntegers.
227
+ *
228
+ * If the second parameter - $base - is negative, then it will be assumed that the number's are encoded using
229
+ * two's compliment. The sole exception to this is -10, which is treated the same as 10 is.
230
+ *
231
+ * Here's an example:
232
+ * <code>
233
+ * <?php
234
+ * include 'Math/BigInteger.php';
235
+ *
236
+ * $a = new Math_BigInteger('0x32', 16); // 50 in base-16
237
+ *
238
+ * echo $a->toString(); // outputs 50
239
+ * ?>
240
+ * </code>
241
+ *
242
+ * @param $x base-10 number or base-$base number if $base set.
243
+ * @param int $base
244
+ * @return Math_BigInteger
245
+ * @access public
246
+ */
247
+ function __construct($x = 0, $base = 10)
248
+ {
249
+ if (!defined('MATH_BIGINTEGER_MODE')) {
250
+ switch (true) {
251
+ case extension_loaded('gmp'):
252
+ define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP);
253
+ break;
254
+ case extension_loaded('bcmath'):
255
+ define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_BCMATH);
256
+ break;
257
+ default:
258
+ define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_INTERNAL);
259
+ }
260
+ }
261
+
262
+ if (extension_loaded('openssl') && !defined('MATH_BIGINTEGER_OPENSSL_DISABLE') && !defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) {
263
+ // some versions of XAMPP have mismatched versions of OpenSSL which causes it not to work
264
+ ob_start();
265
+ @phpinfo();
266
+ $content = ob_get_contents();
267
+ ob_end_clean();
268
+
269
+ preg_match_all('#OpenSSL (Header|Library) Version(.*)#im', $content, $matches);
270
+
271
+ $versions = array();
272
+ if (!empty($matches[1])) {
273
+ for ($i = 0; $i < count($matches[1]); $i++) {
274
+ $fullVersion = trim(str_replace('=>', '', strip_tags($matches[2][$i])));
275
+
276
+ // Remove letter part in OpenSSL version
277
+ if (!preg_match('/(\d+\.\d+\.\d+)/i', $fullVersion, $m)) {
278
+ $versions[$matches[1][$i]] = $fullVersion;
279
+ } else {
280
+ $versions[$matches[1][$i]] = $m[0];
281
+ }
282
+ }
283
+ }
284
+
285
+ // it doesn't appear that OpenSSL versions were reported upon until PHP 5.3+
286
+ switch (true) {
287
+ case !isset($versions['Header']):
288
+ case !isset($versions['Library']):
289
+ case $versions['Header'] == $versions['Library']:
290
+ case version_compare($versions['Header'], '1.0.0') >= 0 && version_compare($versions['Library'], '1.0.0') >= 0:
291
+ define('MATH_BIGINTEGER_OPENSSL_ENABLED', true);
292
+ break;
293
+ default:
294
+ define('MATH_BIGINTEGER_OPENSSL_DISABLE', true);
295
+ }
296
+ }
297
+
298
+ if (!defined('PHP_INT_SIZE')) {
299
+ define('PHP_INT_SIZE', 4);
300
+ }
301
+
302
+ if (!defined('MATH_BIGINTEGER_BASE') && MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_INTERNAL) {
303
+ switch (PHP_INT_SIZE) {
304
+ case 8: // use 64-bit integers if int size is 8 bytes
305
+ define('MATH_BIGINTEGER_BASE', 31);
306
+ define('MATH_BIGINTEGER_BASE_FULL', 0x80000000);
307
+ define('MATH_BIGINTEGER_MAX_DIGIT', 0x7FFFFFFF);
308
+ define('MATH_BIGINTEGER_MSB', 0x40000000);
309
+ // 10**9 is the closest we can get to 2**31 without passing it
310
+ define('MATH_BIGINTEGER_MAX10', 1000000000);
311
+ define('MATH_BIGINTEGER_MAX10_LEN', 9);
312
+ // the largest digit that may be used in addition / subtraction
313
+ define('MATH_BIGINTEGER_MAX_DIGIT2', pow(2, 62));
314
+ break;
315
+ //case 4: // use 64-bit floats if int size is 4 bytes
316
+ default:
317
+ define('MATH_BIGINTEGER_BASE', 26);
318
+ define('MATH_BIGINTEGER_BASE_FULL', 0x4000000);
319
+ define('MATH_BIGINTEGER_MAX_DIGIT', 0x3FFFFFF);
320
+ define('MATH_BIGINTEGER_MSB', 0x2000000);
321
+ // 10**7 is the closest to 2**26 without passing it
322
+ define('MATH_BIGINTEGER_MAX10', 10000000);
323
+ define('MATH_BIGINTEGER_MAX10_LEN', 7);
324
+ // the largest digit that may be used in addition / subtraction
325
+ // we do pow(2, 52) instead of using 4503599627370496 directly because some
326
+ // PHP installations will truncate 4503599627370496.
327
+ define('MATH_BIGINTEGER_MAX_DIGIT2', pow(2, 52));
328
+ }
329
+ }
330
+
331
+ switch (MATH_BIGINTEGER_MODE) {
332
+ case MATH_BIGINTEGER_MODE_GMP:
333
+ switch (true) {
334
+ case is_resource($x) && get_resource_type($x) == 'GMP integer':
335
+ // PHP 5.6 switched GMP from using resources to objects
336
+ case is_object($x) && get_class($x) == 'GMP':
337
+ $this->value = $x;
338
+ return;
339
+ }
340
+ $this->value = gmp_init(0);
341
+ break;
342
+ case MATH_BIGINTEGER_MODE_BCMATH:
343
+ $this->value = '0';
344
+ break;
345
+ default:
346
+ $this->value = array();
347
+ }
348
+
349
+ // '0' counts as empty() but when the base is 256 '0' is equal to ord('0') or 48
350
+ // '0' is the only value like this per http://php.net/empty
351
+ if (empty($x) && (abs($base) != 256 || $x !== '0')) {
352
+ return;
353
+ }
354
+
355
+ switch ($base) {
356
+ case -256:
357
+ if (ord($x[0]) & 0x80) {
358
+ $x = ~$x;
359
+ $this->is_negative = true;
360
+ }
361
+ case 256:
362
+ switch (MATH_BIGINTEGER_MODE) {
363
+ case MATH_BIGINTEGER_MODE_GMP:
364
+ $sign = $this->is_negative ? '-' : '';
365
+ $this->value = gmp_init($sign . '0x' . bin2hex($x));
366
+ break;
367
+ case MATH_BIGINTEGER_MODE_BCMATH:
368
+ // round $len to the nearest 4 (thanks, DavidMJ!)
369
+ $len = (strlen($x) + 3) & 0xFFFFFFFC;
370
+
371
+ $x = str_pad($x, $len, chr(0), STR_PAD_LEFT);
372
+
373
+ for ($i = 0; $i < $len; $i+= 4) {
374
+ $this->value = bcmul($this->value, '4294967296', 0); // 4294967296 == 2**32
375
+ $this->value = bcadd($this->value, 0x1000000 * ord($x[$i]) + ((ord($x[$i + 1]) << 16) | (ord($x[$i + 2]) << 8) | ord($x[$i + 3])), 0);
376
+ }
377
+
378
+ if ($this->is_negative) {
379
+ $this->value = '-' . $this->value;
380
+ }
381
+
382
+ break;
383
+ // converts a base-2**8 (big endian / msb) number to base-2**26 (little endian / lsb)
384
+ default:
385
+ while (strlen($x)) {
386
+ $this->value[] = $this->_bytes2int($this->_base256_rshift($x, MATH_BIGINTEGER_BASE));
387
+ }
388
+ }
389
+
390
+ if ($this->is_negative) {
391
+ if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) {
392
+ $this->is_negative = false;
393
+ }
394
+ $temp = $this->add(new Math_BigInteger('-1'));
395
+ $this->value = $temp->value;
396
+ }
397
+ break;
398
+ case 16:
399
+ case -16:
400
+ if ($base > 0 && $x[0] == '-') {
401
+ $this->is_negative = true;
402
+ $x = substr($x, 1);
403
+ }
404
+
405
+ $x = preg_replace('#^(?:0x)?([A-Fa-f0-9]*).*#', '$1', $x);
406
+
407
+ $is_negative = false;
408
+ if ($base < 0 && hexdec($x[0]) >= 8) {
409
+ $this->is_negative = $is_negative = true;
410
+ $x = bin2hex(~pack('H*', $x));
411
+ }
412
+
413
+ switch (MATH_BIGINTEGER_MODE) {
414
+ case MATH_BIGINTEGER_MODE_GMP:
415
+ $temp = $this->is_negative ? '-0x' . $x : '0x' . $x;
416
+ $this->value = gmp_init($temp);
417
+ $this->is_negative = false;
418
+ break;
419
+ case MATH_BIGINTEGER_MODE_BCMATH:
420
+ $x = (strlen($x) & 1) ? '0' . $x : $x;
421
+ $temp = new Math_BigInteger(pack('H*', $x), 256);
422
+ $this->value = $this->is_negative ? '-' . $temp->value : $temp->value;
423
+ $this->is_negative = false;
424
+ break;
425
+ default:
426
+ $x = (strlen($x) & 1) ? '0' . $x : $x;
427
+ $temp = new Math_BigInteger(pack('H*', $x), 256);
428
+ $this->value = $temp->value;
429
+ }
430
+
431
+ if ($is_negative) {
432
+ $temp = $this->add(new Math_BigInteger('-1'));
433
+ $this->value = $temp->value;
434
+ }
435
+ break;
436
+ case 10:
437
+ case -10:
438
+ // (?<!^)(?:-).*: find any -'s that aren't at the beginning and then any characters that follow that
439
+ // (?<=^|-)0*: find any 0's that are preceded by the start of the string or by a - (ie. octals)
440
+ // [^-0-9].*: find any non-numeric characters and then any characters that follow that
441
+ $x = preg_replace('#(?<!^)(?:-).*|(?<=^|-)0*|[^-0-9].*#', '', $x);
442
+
443
+ switch (MATH_BIGINTEGER_MODE) {
444
+ case MATH_BIGINTEGER_MODE_GMP:
445
+ $this->value = gmp_init($x);
446
+ break;
447
+ case MATH_BIGINTEGER_MODE_BCMATH:
448
+ // explicitly casting $x to a string is necessary, here, since doing $x[0] on -1 yields different
449
+ // results then doing it on '-1' does (modInverse does $x[0])
450
+ $this->value = $x === '-' ? '0' : (string) $x;
451
+ break;
452
+ default:
453
+ $temp = new Math_BigInteger();
454
+
455
+ $multiplier = new Math_BigInteger();
456
+ $multiplier->value = array(MATH_BIGINTEGER_MAX10);
457
+
458
+ if ($x[0] == '-') {
459
+ $this->is_negative = true;
460
+ $x = substr($x, 1);
461
+ }
462
+
463
+ $x = str_pad($x, strlen($x) + ((MATH_BIGINTEGER_MAX10_LEN - 1) * strlen($x)) % MATH_BIGINTEGER_MAX10_LEN, 0, STR_PAD_LEFT);
464
+ while (strlen($x)) {
465
+ $temp = $temp->multiply($multiplier);
466
+ $temp = $temp->add(new Math_BigInteger($this->_int2bytes(substr($x, 0, MATH_BIGINTEGER_MAX10_LEN)), 256));
467
+ $x = substr($x, MATH_BIGINTEGER_MAX10_LEN);
468
+ }
469
+
470
+ $this->value = $temp->value;
471
+ }
472
+ break;
473
+ case 2: // base-2 support originally implemented by Lluis Pamies - thanks!
474
+ case -2:
475
+ if ($base > 0 && $x[0] == '-') {
476
+ $this->is_negative = true;
477
+ $x = substr($x, 1);
478
+ }
479
+
480
+ $x = preg_replace('#^([01]*).*#', '$1', $x);
481
+ $x = str_pad($x, strlen($x) + (3 * strlen($x)) % 4, 0, STR_PAD_LEFT);
482
+
483
+ $str = '0x';
484
+ while (strlen($x)) {
485
+ $part = substr($x, 0, 4);
486
+ $str.= dechex(bindec($part));
487
+ $x = substr($x, 4);
488
+ }
489
+
490
+ if ($this->is_negative) {
491
+ $str = '-' . $str;
492
+ }
493
+
494
+ $temp = new Math_BigInteger($str, 8 * $base); // ie. either -16 or +16
495
+ $this->value = $temp->value;
496
+ $this->is_negative = $temp->is_negative;
497
+
498
+ break;
499
+ default:
500
+ // base not supported, so we'll let $this == 0
501
+ }
502
+ }
503
+
504
+ /**
505
+ * PHP4 compatible Default Constructor.
506
+ *
507
+ * @see self::__construct()
508
+ * @param $x base-10 number or base-$base number if $base set.
509
+ * @param int $base
510
+ * @access public
511
+ */
512
+ function Math_BigInteger($x = 0, $base = 10)
513
+ {
514
+ $this->__construct($x, $base);
515
+ }
516
+
517
+ /**
518
+ * Converts a BigInteger to a byte string (eg. base-256).
519
+ *
520
+ * Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're
521
+ * saved as two's compliment.
522
+ *
523
+ * Here's an example:
524
+ * <code>
525
+ * <?php
526
+ * include 'Math/BigInteger.php';
527
+ *
528
+ * $a = new Math_BigInteger('65');
529
+ *
530
+ * echo $a->toBytes(); // outputs chr(65)
531
+ * ?>
532
+ * </code>
533
+ *
534
+ * @param bool $twos_compliment
535
+ * @return string
536
+ * @access public
537
+ * @internal Converts a base-2**26 number to base-2**8
538
+ */
539
+ function toBytes($twos_compliment = false)
540
+ {
541
+ if ($twos_compliment) {
542
+ $comparison = $this->compare(new Math_BigInteger());
543
+ if ($comparison == 0) {
544
+ return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
545
+ }
546
+
547
+ $temp = $comparison < 0 ? $this->add(new Math_BigInteger(1)) : $this->copy();
548
+ $bytes = $temp->toBytes();
549
+
550
+ if (empty($bytes)) { // eg. if the number we're trying to convert is -1
551
+ $bytes = chr(0);
552
+ }
553
+
554
+ if (ord($bytes[0]) & 0x80) {
555
+ $bytes = chr(0) . $bytes;
556
+ }
557
+
558
+ return $comparison < 0 ? ~$bytes : $bytes;
559
+ }
560
+
561
+ switch (MATH_BIGINTEGER_MODE) {
562
+ case MATH_BIGINTEGER_MODE_GMP:
563
+ if (gmp_cmp($this->value, gmp_init(0)) == 0) {
564
+ return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
565
+ }
566
+
567
+ $temp = gmp_strval(gmp_abs($this->value), 16);
568
+ $temp = (strlen($temp) & 1) ? '0' . $temp : $temp;
569
+ $temp = pack('H*', $temp);
570
+
571
+ return $this->precision > 0 ?
572
+ substr(str_pad($temp, $this->precision >> 3, chr(0), STR_PAD_LEFT), -($this->precision >> 3)) :
573
+ ltrim($temp, chr(0));
574
+ case MATH_BIGINTEGER_MODE_BCMATH:
575
+ if ($this->value === '0') {
576
+ return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
577
+ }
578
+
579
+ $value = '';
580
+ $current = $this->value;
581
+
582
+ if ($current[0] == '-') {
583
+ $current = substr($current, 1);
584
+ }
585
+
586
+ while (bccomp($current, '0', 0) > 0) {
587
+ $temp = bcmod($current, '16777216');
588
+ $value = chr($temp >> 16) . chr($temp >> 8) . chr($temp) . $value;
589
+ $current = bcdiv($current, '16777216', 0);
590
+ }
591
+
592
+ return $this->precision > 0 ?
593
+ substr(str_pad($value, $this->precision >> 3, chr(0), STR_PAD_LEFT), -($this->precision >> 3)) :
594
+ ltrim($value, chr(0));
595
+ }
596
+
597
+ if (!count($this->value)) {
598
+ return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
599
+ }
600
+ $result = $this->_int2bytes($this->value[count($this->value) - 1]);
601
+
602
+ $temp = $this->copy();
603
+
604
+ for ($i = count($temp->value) - 2; $i >= 0; --$i) {
605
+ $temp->_base256_lshift($result, MATH_BIGINTEGER_BASE);
606
+ $result = $result | str_pad($temp->_int2bytes($temp->value[$i]), strlen($result), chr(0), STR_PAD_LEFT);
607
+ }
608
+
609
+ return $this->precision > 0 ?
610
+ str_pad(substr($result, -(($this->precision + 7) >> 3)), ($this->precision + 7) >> 3, chr(0), STR_PAD_LEFT) :
611
+ $result;
612
+ }
613
+
614
+ /**
615
+ * Converts a BigInteger to a hex string (eg. base-16)).
616
+ *
617
+ * Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're
618
+ * saved as two's compliment.
619
+ *
620
+ * Here's an example:
621
+ * <code>
622
+ * <?php
623
+ * include 'Math/BigInteger.php';
624
+ *
625
+ * $a = new Math_BigInteger('65');
626
+ *
627
+ * echo $a->toHex(); // outputs '41'
628
+ * ?>
629
+ * </code>
630
+ *
631
+ * @param bool $twos_compliment
632
+ * @return string
633
+ * @access public
634
+ * @internal Converts a base-2**26 number to base-2**8
635
+ */
636
+ function toHex($twos_compliment = false)
637
+ {
638
+ return bin2hex($this->toBytes($twos_compliment));
639
+ }
640
+
641
+ /**
642
+ * Converts a BigInteger to a bit string (eg. base-2).
643
+ *
644
+ * Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're
645
+ * saved as two's compliment.
646
+ *
647
+ * Here's an example:
648
+ * <code>
649
+ * <?php
650
+ * include 'Math/BigInteger.php';
651
+ *
652
+ * $a = new Math_BigInteger('65');
653
+ *
654
+ * echo $a->toBits(); // outputs '1000001'
655
+ * ?>
656
+ * </code>
657
+ *
658
+ * @param bool $twos_compliment
659
+ * @return string
660
+ * @access public
661
+ * @internal Converts a base-2**26 number to base-2**2
662
+ */
663
+ function toBits($twos_compliment = false)
664
+ {
665
+ $hex = $this->toHex($twos_compliment);
666
+ $bits = '';
667
+ for ($i = strlen($hex) - 8, $start = strlen($hex) & 7; $i >= $start; $i-=8) {
668
+ $bits = str_pad(decbin(hexdec(substr($hex, $i, 8))), 32, '0', STR_PAD_LEFT) . $bits;
669
+ }
670
+ if ($start) { // hexdec('') == 0
671
+ $bits = str_pad(decbin(hexdec(substr($hex, 0, $start))), 8, '0', STR_PAD_LEFT) . $bits;
672
+ }
673
+ $result = $this->precision > 0 ? substr($bits, -$this->precision) : ltrim($bits, '0');
674
+
675
+ if ($twos_compliment && $this->compare(new Math_BigInteger()) > 0 && $this->precision <= 0) {
676
+ return '0' . $result;
677
+ }
678
+
679
+ return $result;
680
+ }
681
+
682
+ /**
683
+ * Converts a BigInteger to a base-10 number.
684
+ *
685
+ * Here's an example:
686
+ * <code>
687
+ * <?php
688
+ * include 'Math/BigInteger.php';
689
+ *
690
+ * $a = new Math_BigInteger('50');
691
+ *
692
+ * echo $a->toString(); // outputs 50
693
+ * ?>
694
+ * </code>
695
+ *
696
+ * @return string
697
+ * @access public
698
+ * @internal Converts a base-2**26 number to base-10**7 (which is pretty much base-10)
699
+ */
700
+ function toString()
701
+ {
702
+ switch (MATH_BIGINTEGER_MODE) {
703
+ case MATH_BIGINTEGER_MODE_GMP:
704
+ return gmp_strval($this->value);
705
+ case MATH_BIGINTEGER_MODE_BCMATH:
706
+ if ($this->value === '0') {
707
+ return '0';
708
+ }
709
+
710
+ return ltrim($this->value, '0');
711
+ }
712
+
713
+ if (!count($this->value)) {
714
+ return '0';
715
+ }
716
+
717
+ $temp = $this->copy();
718
+ $temp->is_negative = false;
719
+
720
+ $divisor = new Math_BigInteger();
721
+ $divisor->value = array(MATH_BIGINTEGER_MAX10);
722
+ $result = '';
723
+ while (count($temp->value)) {
724
+ list($temp, $mod) = $temp->divide($divisor);
725
+ $result = str_pad(isset($mod->value[0]) ? $mod->value[0] : '', MATH_BIGINTEGER_MAX10_LEN, '0', STR_PAD_LEFT) . $result;
726
+ }
727
+ $result = ltrim($result, '0');
728
+ if (empty($result)) {
729
+ $result = '0';
730
+ }
731
+
732
+ if ($this->is_negative) {
733
+ $result = '-' . $result;
734
+ }
735
+
736
+ return $result;
737
+ }
738
+
739
+ function toInteger()
740
+ {
741
+ return (int) $this->toString();
742
+ }
743
+
744
+ /**
745
+ * Copy an object
746
+ *
747
+ * PHP5 passes objects by reference while PHP4 passes by value. As such, we need a function to guarantee
748
+ * that all objects are passed by value, when appropriate. More information can be found here:
749
+ *
750
+ * {@link http://php.net/language.oop5.basic#51624}
751
+ *
752
+ * @access public
753
+ * @see self::__clone()
754
+ * @return Math_BigInteger
755
+ */
756
+ function copy()
757
+ {
758
+ $temp = new Math_BigInteger();
759
+ $temp->value = $this->value;
760
+ $temp->is_negative = $this->is_negative;
761
+ $temp->precision = $this->precision;
762
+ $temp->bitmask = $this->bitmask;
763
+ return $temp;
764
+ }
765
+
766
+ /**
767
+ * __toString() magic method
768
+ *
769
+ * Will be called, automatically, if you're supporting just PHP5. If you're supporting PHP4, you'll need to call
770
+ * toString().
771
+ *
772
+ * @access public
773
+ * @internal Implemented per a suggestion by Techie-Michael - thanks!
774
+ */
775
+ function __toString()
776
+ {
777
+ return $this->toString();
778
+ }
779
+
780
+ /**
781
+ * __clone() magic method
782
+ *
783
+ * Although you can call Math_BigInteger::__toString() directly in PHP5, you cannot call Math_BigInteger::__clone()
784
+ * directly in PHP5. You can in PHP4 since it's not a magic method, but in PHP5, you have to call it by using the PHP5
785
+ * only syntax of $y = clone $x. As such, if you're trying to write an application that works on both PHP4 and PHP5,
786
+ * call Math_BigInteger::copy(), instead.
787
+ *
788
+ * @access public
789
+ * @see self::copy()
790
+ * @return Math_BigInteger
791
+ */
792
+ function __clone()
793
+ {
794
+ return $this->copy();
795
+ }
796
+
797
+ /**
798
+ * __sleep() magic method
799
+ *
800
+ * Will be called, automatically, when serialize() is called on a Math_BigInteger object.
801
+ *
802
+ * @see self::__wakeup()
803
+ * @access public
804
+ */
805
+ function __sleep()
806
+ {
807
+ $this->hex = $this->toHex(true);
808
+ $vars = array('hex');
809
+ if ($this->precision > 0) {
810
+ $vars[] = 'precision';
811
+ }
812
+ return $vars;
813
+ }
814
+
815
+ /**
816
+ * __wakeup() magic method
817
+ *
818
+ * Will be called, automatically, when unserialize() is called on a Math_BigInteger object.
819
+ *
820
+ * @see self::__sleep()
821
+ * @access public
822
+ */
823
+ function __wakeup()
824
+ {
825
+ $temp = new Math_BigInteger($this->hex, -16);
826
+ $this->value = $temp->value;
827
+ $this->is_negative = $temp->is_negative;
828
+ if ($this->precision > 0) {
829
+ // recalculate $this->bitmask
830
+ $this->setPrecision($this->precision);
831
+ }
832
+ }
833
+
834
+ /**
835
+ * __debugInfo() magic method
836
+ *
837
+ * Will be called, automatically, when print_r() or var_dump() are called
838
+ *
839
+ * @access public
840
+ */
841
+ function __debugInfo()
842
+ {
843
+ $opts = array();
844
+ switch (MATH_BIGINTEGER_MODE) {
845
+ case MATH_BIGINTEGER_MODE_GMP:
846
+ $engine = 'gmp';
847
+ break;
848
+ case MATH_BIGINTEGER_MODE_BCMATH:
849
+ $engine = 'bcmath';
850
+ break;
851
+ case MATH_BIGINTEGER_MODE_INTERNAL:
852
+ $engine = 'internal';
853
+ $opts[] = PHP_INT_SIZE == 8 ? '64-bit' : '32-bit';
854
+ }
855
+ if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_GMP && defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) {
856
+ $opts[] = 'OpenSSL';
857
+ }
858
+ if (!empty($opts)) {
859
+ $engine.= ' (' . implode($opts, ', ') . ')';
860
+ }
861
+ return array(
862
+ 'value' => '0x' . $this->toHex(true),
863
+ 'engine' => $engine
864
+ );
865
+ }
866
+
867
+ /**
868
+ * Adds two BigIntegers.
869
+ *
870
+ * Here's an example:
871
+ * <code>
872
+ * <?php
873
+ * include 'Math/BigInteger.php';
874
+ *
875
+ * $a = new Math_BigInteger('10');
876
+ * $b = new Math_BigInteger('20');
877
+ *
878
+ * $c = $a->add($b);
879
+ *
880
+ * echo $c->toString(); // outputs 30
881
+ * ?>
882
+ * </code>
883
+ *
884
+ * @param Math_BigInteger $y
885
+ * @return Math_BigInteger
886
+ * @access public
887
+ * @internal Performs base-2**52 addition
888
+ */
889
+ function add($y)
890
+ {
891
+ switch (MATH_BIGINTEGER_MODE) {
892
+ case MATH_BIGINTEGER_MODE_GMP:
893
+ $temp = new Math_BigInteger();
894
+ $temp->value = gmp_add($this->value, $y->value);
895
+
896
+ return $this->_normalize($temp);
897
+ case MATH_BIGINTEGER_MODE_BCMATH:
898
+ $temp = new Math_BigInteger();
899
+ $temp->value = bcadd($this->value, $y->value, 0);
900
+
901
+ return $this->_normalize($temp);
902
+ }
903
+
904
+ $temp = $this->_add($this->value, $this->is_negative, $y->value, $y->is_negative);
905
+
906
+ $result = new Math_BigInteger();
907
+ $result->value = $temp[MATH_BIGINTEGER_VALUE];
908
+ $result->is_negative = $temp[MATH_BIGINTEGER_SIGN];
909
+
910
+ return $this->_normalize($result);
911
+ }
912
+
913
+ /**
914
+ * Performs addition.
915
+ *
916
+ * @param array $x_value
917
+ * @param bool $x_negative
918
+ * @param array $y_value
919
+ * @param bool $y_negative
920
+ * @return array
921
+ * @access private
922
+ */
923
+ function _add($x_value, $x_negative, $y_value, $y_negative)
924
+ {
925
+ $x_size = count($x_value);
926
+ $y_size = count($y_value);
927
+
928
+ if ($x_size == 0) {
929
+ return array(
930
+ MATH_BIGINTEGER_VALUE => $y_value,
931
+ MATH_BIGINTEGER_SIGN => $y_negative
932
+ );
933
+ } elseif ($y_size == 0) {
934
+ return array(
935
+ MATH_BIGINTEGER_VALUE => $x_value,
936
+ MATH_BIGINTEGER_SIGN => $x_negative
937
+ );
938
+ }
939
+
940
+ // subtract, if appropriate
941
+ if ($x_negative != $y_negative) {
942
+ if ($x_value == $y_value) {
943
+ return array(
944
+ MATH_BIGINTEGER_VALUE => array(),
945
+ MATH_BIGINTEGER_SIGN => false
946
+ );
947
+ }
948
+
949
+ $temp = $this->_subtract($x_value, false, $y_value, false);
950
+ $temp[MATH_BIGINTEGER_SIGN] = $this->_compare($x_value, false, $y_value, false) > 0 ?
951
+ $x_negative : $y_negative;
952
+
953
+ return $temp;
954
+ }
955
+
956
+ if ($x_size < $y_size) {
957
+ $size = $x_size;
958
+ $value = $y_value;
959
+ } else {
960
+ $size = $y_size;
961
+ $value = $x_value;
962
+ }
963
+
964
+ $value[count($value)] = 0; // just in case the carry adds an extra digit
965
+
966
+ $carry = 0;
967
+ for ($i = 0, $j = 1; $j < $size; $i+=2, $j+=2) {
968
+ $sum = $x_value[$j] * MATH_BIGINTEGER_BASE_FULL + $x_value[$i] + $y_value[$j] * MATH_BIGINTEGER_BASE_FULL + $y_value[$i] + $carry;
969
+ $carry = $sum >= MATH_BIGINTEGER_MAX_DIGIT2; // eg. floor($sum / 2**52); only possible values (in any base) are 0 and 1
970
+ $sum = $carry ? $sum - MATH_BIGINTEGER_MAX_DIGIT2 : $sum;
971
+
972
+ $temp = MATH_BIGINTEGER_BASE === 26 ? intval($sum / 0x4000000) : ($sum >> 31);
973
+
974
+ $value[$i] = (int) ($sum - MATH_BIGINTEGER_BASE_FULL * $temp); // eg. a faster alternative to fmod($sum, 0x4000000)
975
+ $value[$j] = $temp;
976
+ }
977
+
978
+ if ($j == $size) { // ie. if $y_size is odd
979
+ $sum = $x_value[$i] + $y_value[$i] + $carry;
980
+ $carry = $sum >= MATH_BIGINTEGER_BASE_FULL;
981
+ $value[$i] = $carry ? $sum - MATH_BIGINTEGER_BASE_FULL : $sum;
982
+ ++$i; // ie. let $i = $j since we've just done $value[$i]
983
+ }
984
+
985
+ if ($carry) {
986
+ for (; $value[$i] == MATH_BIGINTEGER_MAX_DIGIT; ++$i) {
987
+ $value[$i] = 0;
988
+ }
989
+ ++$value[$i];
990
+ }
991
+
992
+ return array(
993
+ MATH_BIGINTEGER_VALUE => $this->_trim($value),
994
+ MATH_BIGINTEGER_SIGN => $x_negative
995
+ );
996
+ }
997
+
998
+ /**
999
+ * Subtracts two BigIntegers.
1000
+ *
1001
+ * Here's an example:
1002
+ * <code>
1003
+ * <?php
1004
+ * include 'Math/BigInteger.php';
1005
+ *
1006
+ * $a = new Math_BigInteger('10');
1007
+ * $b = new Math_BigInteger('20');
1008
+ *
1009
+ * $c = $a->subtract($b);
1010
+ *
1011
+ * echo $c->toString(); // outputs -10
1012
+ * ?>
1013
+ * </code>
1014
+ *
1015
+ * @param Math_BigInteger $y
1016
+ * @return Math_BigInteger
1017
+ * @access public
1018
+ * @internal Performs base-2**52 subtraction
1019
+ */
1020
+ function subtract($y)
1021
+ {
1022
+ switch (MATH_BIGINTEGER_MODE) {
1023
+ case MATH_BIGINTEGER_MODE_GMP:
1024
+ $temp = new Math_BigInteger();
1025
+ $temp->value = gmp_sub($this->value, $y->value);
1026
+
1027
+ return $this->_normalize($temp);
1028
+ case MATH_BIGINTEGER_MODE_BCMATH:
1029
+ $temp = new Math_BigInteger();
1030
+ $temp->value = bcsub($this->value, $y->value, 0);
1031
+
1032
+ return $this->_normalize($temp);
1033
+ }
1034
+
1035
+ $temp = $this->_subtract($this->value, $this->is_negative, $y->value, $y->is_negative);
1036
+
1037
+ $result = new Math_BigInteger();
1038
+ $result->value = $temp[MATH_BIGINTEGER_VALUE];
1039
+ $result->is_negative = $temp[MATH_BIGINTEGER_SIGN];
1040
+
1041
+ return $this->_normalize($result);
1042
+ }
1043
+
1044
+ /**
1045
+ * Performs subtraction.
1046
+ *
1047
+ * @param array $x_value
1048
+ * @param bool $x_negative
1049
+ * @param array $y_value
1050
+ * @param bool $y_negative
1051
+ * @return array
1052
+ * @access private
1053
+ */
1054
+ function _subtract($x_value, $x_negative, $y_value, $y_negative)
1055
+ {
1056
+ $x_size = count($x_value);
1057
+ $y_size = count($y_value);
1058
+
1059
+ if ($x_size == 0) {
1060
+ return array(
1061
+ MATH_BIGINTEGER_VALUE => $y_value,
1062
+ MATH_BIGINTEGER_SIGN => !$y_negative
1063
+ );
1064
+ } elseif ($y_size == 0) {
1065
+ return array(
1066
+ MATH_BIGINTEGER_VALUE => $x_value,
1067
+ MATH_BIGINTEGER_SIGN => $x_negative
1068
+ );
1069
+ }
1070
+
1071
+ // add, if appropriate (ie. -$x - +$y or +$x - -$y)
1072
+ if ($x_negative != $y_negative) {
1073
+ $temp = $this->_add($x_value, false, $y_value, false);
1074
+ $temp[MATH_BIGINTEGER_SIGN] = $x_negative;
1075
+
1076
+ return $temp;
1077
+ }
1078
+
1079
+ $diff = $this->_compare($x_value, $x_negative, $y_value, $y_negative);
1080
+
1081
+ if (!$diff) {
1082
+ return array(
1083
+ MATH_BIGINTEGER_VALUE => array(),
1084
+ MATH_BIGINTEGER_SIGN => false
1085
+ );
1086
+ }
1087
+
1088
+ // switch $x and $y around, if appropriate.
1089
+ if ((!$x_negative && $diff < 0) || ($x_negative && $diff > 0)) {
1090
+ $temp = $x_value;
1091
+ $x_value = $y_value;
1092
+ $y_value = $temp;
1093
+
1094
+ $x_negative = !$x_negative;
1095
+
1096
+ $x_size = count($x_value);
1097
+ $y_size = count($y_value);
1098
+ }
1099
+
1100
+ // at this point, $x_value should be at least as big as - if not bigger than - $y_value
1101
+
1102
+ $carry = 0;
1103
+ for ($i = 0, $j = 1; $j < $y_size; $i+=2, $j+=2) {
1104
+ $sum = $x_value[$j] * MATH_BIGINTEGER_BASE_FULL + $x_value[$i] - $y_value[$j] * MATH_BIGINTEGER_BASE_FULL - $y_value[$i] - $carry;
1105
+ $carry = $sum < 0; // eg. floor($sum / 2**52); only possible values (in any base) are 0 and 1
1106
+ $sum = $carry ? $sum + MATH_BIGINTEGER_MAX_DIGIT2 : $sum;
1107
+
1108
+ $temp = MATH_BIGINTEGER_BASE === 26 ? intval($sum / 0x4000000) : ($sum >> 31);
1109
+
1110
+ $x_value[$i] = (int) ($sum - MATH_BIGINTEGER_BASE_FULL * $temp);
1111
+ $x_value[$j] = $temp;
1112
+ }
1113
+
1114
+ if ($j == $y_size) { // ie. if $y_size is odd
1115
+ $sum = $x_value[$i] - $y_value[$i] - $carry;
1116
+ $carry = $sum < 0;
1117
+ $x_value[$i] = $carry ? $sum + MATH_BIGINTEGER_BASE_FULL : $sum;
1118
+ ++$i;
1119
+ }
1120
+
1121
+ if ($carry) {
1122
+ for (; !$x_value[$i]; ++$i) {
1123
+ $x_value[$i] = MATH_BIGINTEGER_MAX_DIGIT;
1124
+ }
1125
+ --$x_value[$i];
1126
+ }
1127
+
1128
+ return array(
1129
+ MATH_BIGINTEGER_VALUE => $this->_trim($x_value),
1130
+ MATH_BIGINTEGER_SIGN => $x_negative
1131
+ );
1132
+ }
1133
+
1134
+ /**
1135
+ * Multiplies two BigIntegers
1136
+ *
1137
+ * Here's an example:
1138
+ * <code>
1139
+ * <?php
1140
+ * include 'Math/BigInteger.php';
1141
+ *
1142
+ * $a = new Math_BigInteger('10');
1143
+ * $b = new Math_BigInteger('20');
1144
+ *
1145
+ * $c = $a->multiply($b);
1146
+ *
1147
+ * echo $c->toString(); // outputs 200
1148
+ * ?>
1149
+ * </code>
1150
+ *
1151
+ * @param Math_BigInteger $x
1152
+ * @return Math_BigInteger
1153
+ * @access public
1154
+ */
1155
+ function multiply($x)
1156
+ {
1157
+ switch (MATH_BIGINTEGER_MODE) {
1158
+ case MATH_BIGINTEGER_MODE_GMP:
1159
+ $temp = new Math_BigInteger();
1160
+ $temp->value = gmp_mul($this->value, $x->value);
1161
+
1162
+ return $this->_normalize($temp);
1163
+ case MATH_BIGINTEGER_MODE_BCMATH:
1164
+ $temp = new Math_BigInteger();
1165
+ $temp->value = bcmul($this->value, $x->value, 0);
1166
+
1167
+ return $this->_normalize($temp);
1168
+ }
1169
+
1170
+ $temp = $this->_multiply($this->value, $this->is_negative, $x->value, $x->is_negative);
1171
+
1172
+ $product = new Math_BigInteger();
1173
+ $product->value = $temp[MATH_BIGINTEGER_VALUE];
1174
+ $product->is_negative = $temp[MATH_BIGINTEGER_SIGN];
1175
+
1176
+ return $this->_normalize($product);
1177
+ }
1178
+
1179
+ /**
1180
+ * Performs multiplication.
1181
+ *
1182
+ * @param array $x_value
1183
+ * @param bool $x_negative
1184
+ * @param array $y_value
1185
+ * @param bool $y_negative
1186
+ * @return array
1187
+ * @access private
1188
+ */
1189
+ function _multiply($x_value, $x_negative, $y_value, $y_negative)
1190
+ {
1191
+ //if ( $x_value == $y_value ) {
1192
+ // return array(
1193
+ // MATH_BIGINTEGER_VALUE => $this->_square($x_value),
1194
+ // MATH_BIGINTEGER_SIGN => $x_sign != $y_value
1195
+ // );
1196
+ //}
1197
+
1198
+ $x_length = count($x_value);
1199
+ $y_length = count($y_value);
1200
+
1201
+ if (!$x_length || !$y_length) { // a 0 is being multiplied
1202
+ return array(
1203
+ MATH_BIGINTEGER_VALUE => array(),
1204
+ MATH_BIGINTEGER_SIGN => false
1205
+ );
1206
+ }
1207
+
1208
+ return array(
1209
+ MATH_BIGINTEGER_VALUE => min($x_length, $y_length) < 2 * MATH_BIGINTEGER_KARATSUBA_CUTOFF ?
1210
+ $this->_trim($this->_regularMultiply($x_value, $y_value)) :
1211
+ $this->_trim($this->_karatsuba($x_value, $y_value)),
1212
+ MATH_BIGINTEGER_SIGN => $x_negative != $y_negative
1213
+ );
1214
+ }
1215
+
1216
+ /**
1217
+ * Performs long multiplication on two BigIntegers
1218
+ *
1219
+ * Modeled after 'multiply' in MutableBigInteger.java.
1220
+ *
1221
+ * @param array $x_value
1222
+ * @param array $y_value
1223
+ * @return array
1224
+ * @access private
1225
+ */
1226
+ function _regularMultiply($x_value, $y_value)
1227
+ {
1228
+ $x_length = count($x_value);
1229
+ $y_length = count($y_value);
1230
+
1231
+ if (!$x_length || !$y_length) { // a 0 is being multiplied
1232
+ return array();
1233
+ }
1234
+
1235
+ if ($x_length < $y_length) {
1236
+ $temp = $x_value;
1237
+ $x_value = $y_value;
1238
+ $y_value = $temp;
1239
+
1240
+ $x_length = count($x_value);
1241
+ $y_length = count($y_value);
1242
+ }
1243
+
1244
+ $product_value = $this->_array_repeat(0, $x_length + $y_length);
1245
+
1246
+ // the following for loop could be removed if the for loop following it
1247
+ // (the one with nested for loops) initially set $i to 0, but
1248
+ // doing so would also make the result in one set of unnecessary adds,
1249
+ // since on the outermost loops first pass, $product->value[$k] is going
1250
+ // to always be 0
1251
+
1252
+ $carry = 0;
1253
+
1254
+ for ($j = 0; $j < $x_length; ++$j) { // ie. $i = 0
1255
+ $temp = $x_value[$j] * $y_value[0] + $carry; // $product_value[$k] == 0
1256
+ $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
1257
+ $product_value[$j] = (int) ($temp - MATH_BIGINTEGER_BASE_FULL * $carry);
1258
+ }
1259
+
1260
+ $product_value[$j] = $carry;
1261
+
1262
+ // the above for loop is what the previous comment was talking about. the
1263
+ // following for loop is the "one with nested for loops"
1264
+ for ($i = 1; $i < $y_length; ++$i) {
1265
+ $carry = 0;
1266
+
1267
+ for ($j = 0, $k = $i; $j < $x_length; ++$j, ++$k) {
1268
+ $temp = $product_value[$k] + $x_value[$j] * $y_value[$i] + $carry;
1269
+ $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
1270
+ $product_value[$k] = (int) ($temp - MATH_BIGINTEGER_BASE_FULL * $carry);
1271
+ }
1272
+
1273
+ $product_value[$k] = $carry;
1274
+ }
1275
+
1276
+ return $product_value;
1277
+ }
1278
+
1279
+ /**
1280
+ * Performs Karatsuba multiplication on two BigIntegers
1281
+ *
1282
+ * See {@link http://en.wikipedia.org/wiki/Karatsuba_algorithm Karatsuba algorithm} and
1283
+ * {@link http://math.libtomcrypt.com/files/tommath.pdf#page=120 MPM 5.2.3}.
1284
+ *
1285
+ * @param array $x_value
1286
+ * @param array $y_value
1287
+ * @return array
1288
+ * @access private
1289
+ */
1290
+ function _karatsuba($x_value, $y_value)
1291
+ {
1292
+ $m = min(count($x_value) >> 1, count($y_value) >> 1);
1293
+
1294
+ if ($m < MATH_BIGINTEGER_KARATSUBA_CUTOFF) {
1295
+ return $this->_regularMultiply($x_value, $y_value);
1296
+ }
1297
+
1298
+ $x1 = array_slice($x_value, $m);
1299
+ $x0 = array_slice($x_value, 0, $m);
1300
+ $y1 = array_slice($y_value, $m);
1301
+ $y0 = array_slice($y_value, 0, $m);
1302
+
1303
+ $z2 = $this->_karatsuba($x1, $y1);
1304
+ $z0 = $this->_karatsuba($x0, $y0);
1305
+
1306
+ $z1 = $this->_add($x1, false, $x0, false);
1307
+ $temp = $this->_add($y1, false, $y0, false);
1308
+ $z1 = $this->_karatsuba($z1[MATH_BIGINTEGER_VALUE], $temp[MATH_BIGINTEGER_VALUE]);
1309
+ $temp = $this->_add($z2, false, $z0, false);
1310
+ $z1 = $this->_subtract($z1, false, $temp[MATH_BIGINTEGER_VALUE], false);
1311
+
1312
+ $z2 = array_merge(array_fill(0, 2 * $m, 0), $z2);
1313
+ $z1[MATH_BIGINTEGER_VALUE] = array_merge(array_fill(0, $m, 0), $z1[MATH_BIGINTEGER_VALUE]);
1314
+
1315
+ $xy = $this->_add($z2, false, $z1[MATH_BIGINTEGER_VALUE], $z1[MATH_BIGINTEGER_SIGN]);
1316
+ $xy = $this->_add($xy[MATH_BIGINTEGER_VALUE], $xy[MATH_BIGINTEGER_SIGN], $z0, false);
1317
+
1318
+ return $xy[MATH_BIGINTEGER_VALUE];
1319
+ }
1320
+
1321
+ /**
1322
+ * Performs squaring
1323
+ *
1324
+ * @param array $x
1325
+ * @return array
1326
+ * @access private
1327
+ */
1328
+ function _square($x = false)
1329
+ {
1330
+ return count($x) < 2 * MATH_BIGINTEGER_KARATSUBA_CUTOFF ?
1331
+ $this->_trim($this->_baseSquare($x)) :
1332
+ $this->_trim($this->_karatsubaSquare($x));
1333
+ }
1334
+
1335
+ /**
1336
+ * Performs traditional squaring on two BigIntegers
1337
+ *
1338
+ * Squaring can be done faster than multiplying a number by itself can be. See
1339
+ * {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=7 HAC 14.2.4} /
1340
+ * {@link http://math.libtomcrypt.com/files/tommath.pdf#page=141 MPM 5.3} for more information.
1341
+ *
1342
+ * @param array $value
1343
+ * @return array
1344
+ * @access private
1345
+ */
1346
+ function _baseSquare($value)
1347
+ {
1348
+ if (empty($value)) {
1349
+ return array();
1350
+ }
1351
+ $square_value = $this->_array_repeat(0, 2 * count($value));
1352
+
1353
+ for ($i = 0, $max_index = count($value) - 1; $i <= $max_index; ++$i) {
1354
+ $i2 = $i << 1;
1355
+
1356
+ $temp = $square_value[$i2] + $value[$i] * $value[$i];
1357
+ $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
1358
+ $square_value[$i2] = (int) ($temp - MATH_BIGINTEGER_BASE_FULL * $carry);
1359
+
1360
+ // note how we start from $i+1 instead of 0 as we do in multiplication.
1361
+ for ($j = $i + 1, $k = $i2 + 1; $j <= $max_index; ++$j, ++$k) {
1362
+ $temp = $square_value[$k] + 2 * $value[$j] * $value[$i] + $carry;
1363
+ $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
1364
+ $square_value[$k] = (int) ($temp - MATH_BIGINTEGER_BASE_FULL * $carry);
1365
+ }
1366
+
1367
+ // the following line can yield values larger 2**15. at this point, PHP should switch
1368
+ // over to floats.
1369
+ $square_value[$i + $max_index + 1] = $carry;
1370
+ }
1371
+
1372
+ return $square_value;
1373
+ }
1374
+
1375
+ /**
1376
+ * Performs Karatsuba "squaring" on two BigIntegers
1377
+ *
1378
+ * See {@link http://en.wikipedia.org/wiki/Karatsuba_algorithm Karatsuba algorithm} and
1379
+ * {@link http://math.libtomcrypt.com/files/tommath.pdf#page=151 MPM 5.3.4}.
1380
+ *
1381
+ * @param array $value
1382
+ * @return array
1383
+ * @access private
1384
+ */
1385
+ function _karatsubaSquare($value)
1386
+ {
1387
+ $m = count($value) >> 1;
1388
+
1389
+ if ($m < MATH_BIGINTEGER_KARATSUBA_CUTOFF) {
1390
+ return $this->_baseSquare($value);
1391
+ }
1392
+
1393
+ $x1 = array_slice($value, $m);
1394
+ $x0 = array_slice($value, 0, $m);
1395
+
1396
+ $z2 = $this->_karatsubaSquare($x1);
1397
+ $z0 = $this->_karatsubaSquare($x0);
1398
+
1399
+ $z1 = $this->_add($x1, false, $x0, false);
1400
+ $z1 = $this->_karatsubaSquare($z1[MATH_BIGINTEGER_VALUE]);
1401
+ $temp = $this->_add($z2, false, $z0, false);
1402
+ $z1 = $this->_subtract($z1, false, $temp[MATH_BIGINTEGER_VALUE], false);
1403
+
1404
+ $z2 = array_merge(array_fill(0, 2 * $m, 0), $z2);
1405
+ $z1[MATH_BIGINTEGER_VALUE] = array_merge(array_fill(0, $m, 0), $z1[MATH_BIGINTEGER_VALUE]);
1406
+
1407
+ $xx = $this->_add($z2, false, $z1[MATH_BIGINTEGER_VALUE], $z1[MATH_BIGINTEGER_SIGN]);
1408
+ $xx = $this->_add($xx[MATH_BIGINTEGER_VALUE], $xx[MATH_BIGINTEGER_SIGN], $z0, false);
1409
+
1410
+ return $xx[MATH_BIGINTEGER_VALUE];
1411
+ }
1412
+
1413
+ /**
1414
+ * Divides two BigIntegers.
1415
+ *
1416
+ * Returns an array whose first element contains the quotient and whose second element contains the
1417
+ * "common residue". If the remainder would be positive, the "common residue" and the remainder are the
1418
+ * same. If the remainder would be negative, the "common residue" is equal to the sum of the remainder
1419
+ * and the divisor (basically, the "common residue" is the first positive modulo).
1420
+ *
1421
+ * Here's an example:
1422
+ * <code>
1423
+ * <?php
1424
+ * include 'Math/BigInteger.php';
1425
+ *
1426
+ * $a = new Math_BigInteger('10');
1427
+ * $b = new Math_BigInteger('20');
1428
+ *
1429
+ * list($quotient, $remainder) = $a->divide($b);
1430
+ *
1431
+ * echo $quotient->toString(); // outputs 0
1432
+ * echo "\r\n";
1433
+ * echo $remainder->toString(); // outputs 10
1434
+ * ?>
1435
+ * </code>
1436
+ *
1437
+ * @param Math_BigInteger $y
1438
+ * @return array
1439
+ * @access public
1440
+ * @internal This function is based off of {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=9 HAC 14.20}.
1441
+ */
1442
+ function divide($y)
1443
+ {
1444
+ switch (MATH_BIGINTEGER_MODE) {
1445
+ case MATH_BIGINTEGER_MODE_GMP:
1446
+ $quotient = new Math_BigInteger();
1447
+ $remainder = new Math_BigInteger();
1448
+
1449
+ list($quotient->value, $remainder->value) = gmp_div_qr($this->value, $y->value);
1450
+
1451
+ if (gmp_sign($remainder->value) < 0) {
1452
+ $remainder->value = gmp_add($remainder->value, gmp_abs($y->value));
1453
+ }
1454
+
1455
+ return array($this->_normalize($quotient), $this->_normalize($remainder));
1456
+ case MATH_BIGINTEGER_MODE_BCMATH:
1457
+ $quotient = new Math_BigInteger();
1458
+ $remainder = new Math_BigInteger();
1459
+
1460
+ $quotient->value = bcdiv($this->value, $y->value, 0);
1461
+ $remainder->value = bcmod($this->value, $y->value);
1462
+
1463
+ if ($remainder->value[0] == '-') {
1464
+ $remainder->value = bcadd($remainder->value, $y->value[0] == '-' ? substr($y->value, 1) : $y->value, 0);
1465
+ }
1466
+
1467
+ return array($this->_normalize($quotient), $this->_normalize($remainder));
1468
+ }
1469
+
1470
+ if (count($y->value) == 1) {
1471
+ list($q, $r) = $this->_divide_digit($this->value, $y->value[0]);
1472
+ $quotient = new Math_BigInteger();
1473
+ $remainder = new Math_BigInteger();
1474
+ $quotient->value = $q;
1475
+ $remainder->value = array($r);
1476
+ $quotient->is_negative = $this->is_negative != $y->is_negative;
1477
+ return array($this->_normalize($quotient), $this->_normalize($remainder));
1478
+ }
1479
+
1480
+ static $zero;
1481
+ if (!isset($zero)) {
1482
+ $zero = new Math_BigInteger();
1483
+ }
1484
+
1485
+ $x = $this->copy();
1486
+ $y = $y->copy();
1487
+
1488
+ $x_sign = $x->is_negative;
1489
+ $y_sign = $y->is_negative;
1490
+
1491
+ $x->is_negative = $y->is_negative = false;
1492
+
1493
+ $diff = $x->compare($y);
1494
+
1495
+ if (!$diff) {
1496
+ $temp = new Math_BigInteger();
1497
+ $temp->value = array(1);
1498
+ $temp->is_negative = $x_sign != $y_sign;
1499
+ return array($this->_normalize($temp), $this->_normalize(new Math_BigInteger()));
1500
+ }
1501
+
1502
+ if ($diff < 0) {
1503
+ // if $x is negative, "add" $y.
1504
+ if ($x_sign) {
1505
+ $x = $y->subtract($x);
1506
+ }
1507
+ return array($this->_normalize(new Math_BigInteger()), $this->_normalize($x));
1508
+ }
1509
+
1510
+ // normalize $x and $y as described in HAC 14.23 / 14.24
1511
+ $msb = $y->value[count($y->value) - 1];
1512
+ for ($shift = 0; !($msb & MATH_BIGINTEGER_MSB); ++$shift) {
1513
+ $msb <<= 1;
1514
+ }
1515
+ $x->_lshift($shift);
1516
+ $y->_lshift($shift);
1517
+ $y_value = &$y->value;
1518
+
1519
+ $x_max = count($x->value) - 1;
1520
+ $y_max = count($y->value) - 1;
1521
+
1522
+ $quotient = new Math_BigInteger();
1523
+ $quotient_value = &$quotient->value;
1524
+ $quotient_value = $this->_array_repeat(0, $x_max - $y_max + 1);
1525
+
1526
+ static $temp, $lhs, $rhs;
1527
+ if (!isset($temp)) {
1528
+ $temp = new Math_BigInteger();
1529
+ $lhs = new Math_BigInteger();
1530
+ $rhs = new Math_BigInteger();
1531
+ }
1532
+ $temp_value = &$temp->value;
1533
+ $rhs_value = &$rhs->value;
1534
+
1535
+ // $temp = $y << ($x_max - $y_max-1) in base 2**26
1536
+ $temp_value = array_merge($this->_array_repeat(0, $x_max - $y_max), $y_value);
1537
+
1538
+ while ($x->compare($temp) >= 0) {
1539
+ // calculate the "common residue"
1540
+ ++$quotient_value[$x_max - $y_max];
1541
+ $x = $x->subtract($temp);
1542
+ $x_max = count($x->value) - 1;
1543
+ }
1544
+
1545
+ for ($i = $x_max; $i >= $y_max + 1; --$i) {
1546
+ $x_value = &$x->value;
1547
+ $x_window = array(
1548
+ isset($x_value[$i]) ? $x_value[$i] : 0,
1549
+ isset($x_value[$i - 1]) ? $x_value[$i - 1] : 0,
1550
+ isset($x_value[$i - 2]) ? $x_value[$i - 2] : 0
1551
+ );
1552
+ $y_window = array(
1553
+ $y_value[$y_max],
1554
+ ($y_max > 0) ? $y_value[$y_max - 1] : 0
1555
+ );
1556
+
1557
+ $q_index = $i - $y_max - 1;
1558
+ if ($x_window[0] == $y_window[0]) {
1559
+ $quotient_value[$q_index] = MATH_BIGINTEGER_MAX_DIGIT;
1560
+ } else {
1561
+ $quotient_value[$q_index] = $this->_safe_divide(
1562
+ $x_window[0] * MATH_BIGINTEGER_BASE_FULL + $x_window[1],
1563
+ $y_window[0]
1564
+ );
1565
+ }
1566
+
1567
+ $temp_value = array($y_window[1], $y_window[0]);
1568
+
1569
+ $lhs->value = array($quotient_value[$q_index]);
1570
+ $lhs = $lhs->multiply($temp);
1571
+
1572
+ $rhs_value = array($x_window[2], $x_window[1], $x_window[0]);
1573
+
1574
+ while ($lhs->compare($rhs) > 0) {
1575
+ --$quotient_value[$q_index];
1576
+
1577
+ $lhs->value = array($quotient_value[$q_index]);
1578
+ $lhs = $lhs->multiply($temp);
1579
+ }
1580
+
1581
+ $adjust = $this->_array_repeat(0, $q_index);
1582
+ $temp_value = array($quotient_value[$q_index]);
1583
+ $temp = $temp->multiply($y);
1584
+ $temp_value = &$temp->value;
1585
+ $temp_value = array_merge($adjust, $temp_value);
1586
+
1587
+ $x = $x->subtract($temp);
1588
+
1589
+ if ($x->compare($zero) < 0) {
1590
+ $temp_value = array_merge($adjust, $y_value);
1591
+ $x = $x->add($temp);
1592
+
1593
+ --$quotient_value[$q_index];
1594
+ }
1595
+
1596
+ $x_max = count($x_value) - 1;
1597
+ }
1598
+
1599
+ // unnormalize the remainder
1600
+ $x->_rshift($shift);
1601
+
1602
+ $quotient->is_negative = $x_sign != $y_sign;
1603
+
1604
+ // calculate the "common residue", if appropriate
1605
+ if ($x_sign) {
1606
+ $y->_rshift($shift);
1607
+ $x = $y->subtract($x);
1608
+ }
1609
+
1610
+ return array($this->_normalize($quotient), $this->_normalize($x));
1611
+ }
1612
+
1613
+ /**
1614
+ * Divides a BigInteger by a regular integer
1615
+ *
1616
+ * abc / x = a00 / x + b0 / x + c / x
1617
+ *
1618
+ * @param array $dividend
1619
+ * @param array $divisor
1620
+ * @return array
1621
+ * @access private
1622
+ */
1623
+ function _divide_digit($dividend, $divisor)
1624
+ {
1625
+ $carry = 0;
1626
+ $result = array();
1627
+
1628
+ for ($i = count($dividend) - 1; $i >= 0; --$i) {
1629
+ $temp = MATH_BIGINTEGER_BASE_FULL * $carry + $dividend[$i];
1630
+ $result[$i] = $this->_safe_divide($temp, $divisor);
1631
+ $carry = (int) ($temp - $divisor * $result[$i]);
1632
+ }
1633
+
1634
+ return array($result, $carry);
1635
+ }
1636
+
1637
+ /**
1638
+ * Performs modular exponentiation.
1639
+ *
1640
+ * Here's an example:
1641
+ * <code>
1642
+ * <?php
1643
+ * include 'Math/BigInteger.php';
1644
+ *
1645
+ * $a = new Math_BigInteger('10');
1646
+ * $b = new Math_BigInteger('20');
1647
+ * $c = new Math_BigInteger('30');
1648
+ *
1649
+ * $c = $a->modPow($b, $c);
1650
+ *
1651
+ * echo $c->toString(); // outputs 10
1652
+ * ?>
1653
+ * </code>
1654
+ *
1655
+ * @param Math_BigInteger $e
1656
+ * @param Math_BigInteger $n
1657
+ * @return Math_BigInteger
1658
+ * @access public
1659
+ * @internal The most naive approach to modular exponentiation has very unreasonable requirements, and
1660
+ * and although the approach involving repeated squaring does vastly better, it, too, is impractical
1661
+ * for our purposes. The reason being that division - by far the most complicated and time-consuming
1662
+ * of the basic operations (eg. +,-,*,/) - occurs multiple times within it.
1663
+ *
1664
+ * Modular reductions resolve this issue. Although an individual modular reduction takes more time
1665
+ * then an individual division, when performed in succession (with the same modulo), they're a lot faster.
1666
+ *
1667
+ * The two most commonly used modular reductions are Barrett and Montgomery reduction. Montgomery reduction,
1668
+ * although faster, only works when the gcd of the modulo and of the base being used is 1. In RSA, when the
1669
+ * base is a power of two, the modulo - a product of two primes - is always going to have a gcd of 1 (because
1670
+ * the product of two odd numbers is odd), but what about when RSA isn't used?
1671
+ *
1672
+ * In contrast, Barrett reduction has no such constraint. As such, some bigint implementations perform a
1673
+ * Barrett reduction after every operation in the modpow function. Others perform Barrett reductions when the
1674
+ * modulo is even and Montgomery reductions when the modulo is odd. BigInteger.java's modPow method, however,
1675
+ * uses a trick involving the Chinese Remainder Theorem to factor the even modulo into two numbers - one odd and
1676
+ * the other, a power of two - and recombine them, later. This is the method that this modPow function uses.
1677
+ * {@link http://islab.oregonstate.edu/papers/j34monex.pdf Montgomery Reduction with Even Modulus} elaborates.
1678
+ */
1679
+ function modPow($e, $n)
1680
+ {
1681
+ $n = $this->bitmask !== false && $this->bitmask->compare($n) < 0 ? $this->bitmask : $n->abs();
1682
+
1683
+ if ($e->compare(new Math_BigInteger()) < 0) {
1684
+ $e = $e->abs();
1685
+
1686
+ $temp = $this->modInverse($n);
1687
+ if ($temp === false) {
1688
+ return false;
1689
+ }
1690
+
1691
+ return $this->_normalize($temp->modPow($e, $n));
1692
+ }
1693
+
1694
+ if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP) {
1695
+ $temp = new Math_BigInteger();
1696
+ $temp->value = gmp_powm($this->value, $e->value, $n->value);
1697
+
1698
+ return $this->_normalize($temp);
1699
+ }
1700
+
1701
+ if ($this->compare(new Math_BigInteger()) < 0 || $this->compare($n) > 0) {
1702
+ list(, $temp) = $this->divide($n);
1703
+ return $temp->modPow($e, $n);
1704
+ }
1705
+
1706
+ if (defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) {
1707
+ $components = array(
1708
+ 'modulus' => $n->toBytes(true),
1709
+ 'publicExponent' => $e->toBytes(true)
1710
+ );
1711
+
1712
+ $components = array(
1713
+ 'modulus' => pack('Ca*a*', 2, $this->_encodeASN1Length(strlen($components['modulus'])), $components['modulus']),
1714
+ 'publicExponent' => pack('Ca*a*', 2, $this->_encodeASN1Length(strlen($components['publicExponent'])), $components['publicExponent'])
1715
+ );
1716
+
1717
+ $RSAPublicKey = pack(
1718
+ 'Ca*a*a*',
1719
+ 48,
1720
+ $this->_encodeASN1Length(strlen($components['modulus']) + strlen($components['publicExponent'])),
1721
+ $components['modulus'],
1722
+ $components['publicExponent']
1723
+ );
1724
+
1725
+ $rsaOID = pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
1726
+ $RSAPublicKey = chr(0) . $RSAPublicKey;
1727
+ $RSAPublicKey = chr(3) . $this->_encodeASN1Length(strlen($RSAPublicKey)) . $RSAPublicKey;
1728
+
1729
+ $encapsulated = pack(
1730
+ 'Ca*a*',
1731
+ 48,
1732
+ $this->_encodeASN1Length(strlen($rsaOID . $RSAPublicKey)),
1733
+ $rsaOID . $RSAPublicKey
1734
+ );
1735
+
1736
+ $RSAPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" .
1737
+ chunk_split(base64_encode($encapsulated)) .
1738
+ '-----END PUBLIC KEY-----';
1739
+
1740
+ $plaintext = str_pad($this->toBytes(), strlen($n->toBytes(true)) - 1, "\0", STR_PAD_LEFT);
1741
+
1742
+ if (openssl_public_encrypt($plaintext, $result, $RSAPublicKey, OPENSSL_NO_PADDING)) {
1743
+ return new Math_BigInteger($result, 256);
1744
+ }
1745
+ }
1746
+
1747
+ if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH) {
1748
+ $temp = new Math_BigInteger();
1749
+ $temp->value = bcpowmod($this->value, $e->value, $n->value, 0);
1750
+
1751
+ return $this->_normalize($temp);
1752
+ }
1753
+
1754
+ if (empty($e->value)) {
1755
+ $temp = new Math_BigInteger();
1756
+ $temp->value = array(1);
1757
+ return $this->_normalize($temp);
1758
+ }
1759
+
1760
+ if ($e->value == array(1)) {
1761
+ list(, $temp) = $this->divide($n);
1762
+ return $this->_normalize($temp);
1763
+ }
1764
+
1765
+ if ($e->value == array(2)) {
1766
+ $temp = new Math_BigInteger();
1767
+ $temp->value = $this->_square($this->value);
1768
+ list(, $temp) = $temp->divide($n);
1769
+ return $this->_normalize($temp);
1770
+ }
1771
+
1772
+ return $this->_normalize($this->_slidingWindow($e, $n, MATH_BIGINTEGER_BARRETT));
1773
+
1774
+ // the following code, although not callable, can be run independently of the above code
1775
+ // although the above code performed better in my benchmarks the following could might
1776
+ // perform better under different circumstances. in lieu of deleting it it's just been
1777
+ // made uncallable
1778
+
1779
+ // is the modulo odd?
1780
+ if ($n->value[0] & 1) {
1781
+ return $this->_normalize($this->_slidingWindow($e, $n, MATH_BIGINTEGER_MONTGOMERY));
1782
+ }
1783
+ // if it's not, it's even
1784
+
1785
+ // find the lowest set bit (eg. the max pow of 2 that divides $n)
1786
+ for ($i = 0; $i < count($n->value); ++$i) {
1787
+ if ($n->value[$i]) {
1788
+ $temp = decbin($n->value[$i]);
1789
+ $j = strlen($temp) - strrpos($temp, '1') - 1;
1790
+ $j+= 26 * $i;
1791
+ break;
1792
+ }
1793
+ }
1794
+ // at this point, 2^$j * $n/(2^$j) == $n
1795
+
1796
+ $mod1 = $n->copy();
1797
+ $mod1->_rshift($j);
1798
+ $mod2 = new Math_BigInteger();
1799
+ $mod2->value = array(1);
1800
+ $mod2->_lshift($j);
1801
+
1802
+ $part1 = ($mod1->value != array(1)) ? $this->_slidingWindow($e, $mod1, MATH_BIGINTEGER_MONTGOMERY) : new Math_BigInteger();
1803
+ $part2 = $this->_slidingWindow($e, $mod2, MATH_BIGINTEGER_POWEROF2);
1804
+
1805
+ $y1 = $mod2->modInverse($mod1);
1806
+ $y2 = $mod1->modInverse($mod2);
1807
+
1808
+ $result = $part1->multiply($mod2);
1809
+ $result = $result->multiply($y1);
1810
+
1811
+ $temp = $part2->multiply($mod1);
1812
+ $temp = $temp->multiply($y2);
1813
+
1814
+ $result = $result->add($temp);
1815
+ list(, $result) = $result->divide($n);
1816
+
1817
+ return $this->_normalize($result);
1818
+ }
1819
+
1820
+ /**
1821
+ * Performs modular exponentiation.
1822
+ *
1823
+ * Alias for Math_BigInteger::modPow()
1824
+ *
1825
+ * @param Math_BigInteger $e
1826
+ * @param Math_BigInteger $n
1827
+ * @return Math_BigInteger
1828
+ * @access public
1829
+ */
1830
+ function powMod($e, $n)
1831
+ {
1832
+ return $this->modPow($e, $n);
1833
+ }
1834
+
1835
+ /**
1836
+ * Sliding Window k-ary Modular Exponentiation
1837
+ *
1838
+ * Based on {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=27 HAC 14.85} /
1839
+ * {@link http://math.libtomcrypt.com/files/tommath.pdf#page=210 MPM 7.7}. In a departure from those algorithims,
1840
+ * however, this function performs a modular reduction after every multiplication and squaring operation.
1841
+ * As such, this function has the same preconditions that the reductions being used do.
1842
+ *
1843
+ * @param Math_BigInteger $e
1844
+ * @param Math_BigInteger $n
1845
+ * @param int $mode
1846
+ * @return Math_BigInteger
1847
+ * @access private
1848
+ */
1849
+ function _slidingWindow($e, $n, $mode)
1850
+ {
1851
+ static $window_ranges = array(7, 25, 81, 241, 673, 1793); // from BigInteger.java's oddModPow function
1852
+ //static $window_ranges = array(0, 7, 36, 140, 450, 1303, 3529); // from MPM 7.3.1
1853
+
1854
+ $e_value = $e->value;
1855
+ $e_length = count($e_value) - 1;
1856
+ $e_bits = decbin($e_value[$e_length]);
1857
+ for ($i = $e_length - 1; $i >= 0; --$i) {
1858
+ $e_bits.= str_pad(decbin($e_value[$i]), MATH_BIGINTEGER_BASE, '0', STR_PAD_LEFT);
1859
+ }
1860
+
1861
+ $e_length = strlen($e_bits);
1862
+
1863
+ // calculate the appropriate window size.
1864
+ // $window_size == 3 if $window_ranges is between 25 and 81, for example.
1865
+ for ($i = 0, $window_size = 1; $i < count($window_ranges) && $e_length > $window_ranges[$i]; ++$window_size, ++$i) {
1866
+ }
1867
+
1868
+ $n_value = $n->value;
1869
+
1870
+ // precompute $this^0 through $this^$window_size
1871
+ $powers = array();
1872
+ $powers[1] = $this->_prepareReduce($this->value, $n_value, $mode);
1873
+ $powers[2] = $this->_squareReduce($powers[1], $n_value, $mode);
1874
+
1875
+ // we do every other number since substr($e_bits, $i, $j+1) (see below) is supposed to end
1876
+ // in a 1. ie. it's supposed to be odd.
1877
+ $temp = 1 << ($window_size - 1);
1878
+ for ($i = 1; $i < $temp; ++$i) {
1879
+ $i2 = $i << 1;
1880
+ $powers[$i2 + 1] = $this->_multiplyReduce($powers[$i2 - 1], $powers[2], $n_value, $mode);
1881
+ }
1882
+
1883
+ $result = array(1);
1884
+ $result = $this->_prepareReduce($result, $n_value, $mode);
1885
+
1886
+ for ($i = 0; $i < $e_length;) {
1887
+ if (!$e_bits[$i]) {
1888
+ $result = $this->_squareReduce($result, $n_value, $mode);
1889
+ ++$i;
1890
+ } else {
1891
+ for ($j = $window_size - 1; $j > 0; --$j) {
1892
+ if (!empty($e_bits[$i + $j])) {
1893
+ break;
1894
+ }
1895
+ }
1896
+
1897
+ // eg. the length of substr($e_bits, $i, $j + 1)
1898
+ for ($k = 0; $k <= $j; ++$k) {
1899
+ $result = $this->_squareReduce($result, $n_value, $mode);
1900
+ }
1901
+
1902
+ $result = $this->_multiplyReduce($result, $powers[bindec(substr($e_bits, $i, $j + 1))], $n_value, $mode);
1903
+
1904
+ $i += $j + 1;
1905
+ }
1906
+ }
1907
+
1908
+ $temp = new Math_BigInteger();
1909
+ $temp->value = $this->_reduce($result, $n_value, $mode);
1910
+
1911
+ return $temp;
1912
+ }
1913
+
1914
+ /**
1915
+ * Modular reduction
1916
+ *
1917
+ * For most $modes this will return the remainder.
1918
+ *
1919
+ * @see self::_slidingWindow()
1920
+ * @access private
1921
+ * @param array $x
1922
+ * @param array $n
1923
+ * @param int $mode
1924
+ * @return array
1925
+ */
1926
+ function _reduce($x, $n, $mode)
1927
+ {
1928
+ switch ($mode) {
1929
+ case MATH_BIGINTEGER_MONTGOMERY:
1930
+ return $this->_montgomery($x, $n);
1931
+ case MATH_BIGINTEGER_BARRETT:
1932
+ return $this->_barrett($x, $n);
1933
+ case MATH_BIGINTEGER_POWEROF2:
1934
+ $lhs = new Math_BigInteger();
1935
+ $lhs->value = $x;
1936
+ $rhs = new Math_BigInteger();
1937
+ $rhs->value = $n;
1938
+ return $x->_mod2($n);
1939
+ case MATH_BIGINTEGER_CLASSIC:
1940
+ $lhs = new Math_BigInteger();
1941
+ $lhs->value = $x;
1942
+ $rhs = new Math_BigInteger();
1943
+ $rhs->value = $n;
1944
+ list(, $temp) = $lhs->divide($rhs);
1945
+ return $temp->value;
1946
+ case MATH_BIGINTEGER_NONE:
1947
+ return $x;
1948
+ default:
1949
+ // an invalid $mode was provided
1950
+ }
1951
+ }
1952
+
1953
+ /**
1954
+ * Modular reduction preperation
1955
+ *
1956
+ * @see self::_slidingWindow()
1957
+ * @access private
1958
+ * @param array $x
1959
+ * @param array $n
1960
+ * @param int $mode
1961
+ * @return array
1962
+ */
1963
+ function _prepareReduce($x, $n, $mode)
1964
+ {
1965
+ if ($mode == MATH_BIGINTEGER_MONTGOMERY) {
1966
+ return $this->_prepMontgomery($x, $n);
1967
+ }
1968
+ return $this->_reduce($x, $n, $mode);
1969
+ }
1970
+
1971
+ /**
1972
+ * Modular multiply
1973
+ *
1974
+ * @see self::_slidingWindow()
1975
+ * @access private
1976
+ * @param array $x
1977
+ * @param array $y
1978
+ * @param array $n
1979
+ * @param int $mode
1980
+ * @return array
1981
+ */
1982
+ function _multiplyReduce($x, $y, $n, $mode)
1983
+ {
1984
+ if ($mode == MATH_BIGINTEGER_MONTGOMERY) {
1985
+ return $this->_montgomeryMultiply($x, $y, $n);
1986
+ }
1987
+ $temp = $this->_multiply($x, false, $y, false);
1988
+ return $this->_reduce($temp[MATH_BIGINTEGER_VALUE], $n, $mode);
1989
+ }
1990
+
1991
+ /**
1992
+ * Modular square
1993
+ *
1994
+ * @see self::_slidingWindow()
1995
+ * @access private
1996
+ * @param array $x
1997
+ * @param array $n
1998
+ * @param int $mode
1999
+ * @return array
2000
+ */
2001
+ function _squareReduce($x, $n, $mode)
2002
+ {
2003
+ if ($mode == MATH_BIGINTEGER_MONTGOMERY) {
2004
+ return $this->_montgomeryMultiply($x, $x, $n);
2005
+ }
2006
+ return $this->_reduce($this->_square($x), $n, $mode);
2007
+ }
2008
+
2009
+ /**
2010
+ * Modulos for Powers of Two
2011
+ *
2012
+ * Calculates $x%$n, where $n = 2**$e, for some $e. Since this is basically the same as doing $x & ($n-1),
2013
+ * we'll just use this function as a wrapper for doing that.
2014
+ *
2015
+ * @see self::_slidingWindow()
2016
+ * @access private
2017
+ * @param Math_BigInteger
2018
+ * @return Math_BigInteger
2019
+ */
2020
+ function _mod2($n)
2021
+ {
2022
+ $temp = new Math_BigInteger();
2023
+ $temp->value = array(1);
2024
+ return $this->bitwise_and($n->subtract($temp));
2025
+ }
2026
+
2027
+ /**
2028
+ * Barrett Modular Reduction
2029
+ *
2030
+ * See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=14 HAC 14.3.3} /
2031
+ * {@link http://math.libtomcrypt.com/files/tommath.pdf#page=165 MPM 6.2.5} for more information. Modified slightly,
2032
+ * so as not to require negative numbers (initially, this script didn't support negative numbers).
2033
+ *
2034
+ * Employs "folding", as described at
2035
+ * {@link http://www.cosic.esat.kuleuven.be/publications/thesis-149.pdf#page=66 thesis-149.pdf#page=66}. To quote from
2036
+ * it, "the idea [behind folding] is to find a value x' such that x (mod m) = x' (mod m), with x' being smaller than x."
2037
+ *
2038
+ * Unfortunately, the "Barrett Reduction with Folding" algorithm described in thesis-149.pdf is not, as written, all that
2039
+ * usable on account of (1) its not using reasonable radix points as discussed in
2040
+ * {@link http://math.libtomcrypt.com/files/tommath.pdf#page=162 MPM 6.2.2} and (2) the fact that, even with reasonable
2041
+ * radix points, it only works when there are an even number of digits in the denominator. The reason for (2) is that
2042
+ * (x >> 1) + (x >> 1) != x / 2 + x / 2. If x is even, they're the same, but if x is odd, they're not. See the in-line
2043
+ * comments for details.
2044
+ *
2045
+ * @see self::_slidingWindow()
2046
+ * @access private
2047
+ * @param array $n
2048
+ * @param array $m
2049
+ * @return array
2050
+ */
2051
+ function _barrett($n, $m)
2052
+ {
2053
+ static $cache = array(
2054
+ MATH_BIGINTEGER_VARIABLE => array(),
2055
+ MATH_BIGINTEGER_DATA => array()
2056
+ );
2057
+
2058
+ $m_length = count($m);
2059
+
2060
+ // if ($this->_compare($n, $this->_square($m)) >= 0) {
2061
+ if (count($n) > 2 * $m_length) {
2062
+ $lhs = new Math_BigInteger();
2063
+ $rhs = new Math_BigInteger();
2064
+ $lhs->value = $n;
2065
+ $rhs->value = $m;
2066
+ list(, $temp) = $lhs->divide($rhs);
2067
+ return $temp->value;
2068
+ }
2069
+
2070
+ // if (m.length >> 1) + 2 <= m.length then m is too small and n can't be reduced
2071
+ if ($m_length < 5) {
2072
+ return $this->_regularBarrett($n, $m);
2073
+ }
2074
+
2075
+ // n = 2 * m.length
2076
+
2077
+ if (($key = array_search($m, $cache[MATH_BIGINTEGER_VARIABLE])) === false) {
2078
+ $key = count($cache[MATH_BIGINTEGER_VARIABLE]);
2079
+ $cache[MATH_BIGINTEGER_VARIABLE][] = $m;
2080
+
2081
+ $lhs = new Math_BigInteger();
2082
+ $lhs_value = &$lhs->value;
2083
+ $lhs_value = $this->_array_repeat(0, $m_length + ($m_length >> 1));
2084
+ $lhs_value[] = 1;
2085
+ $rhs = new Math_BigInteger();
2086
+ $rhs->value = $m;
2087
+
2088
+ list($u, $m1) = $lhs->divide($rhs);
2089
+ $u = $u->value;
2090
+ $m1 = $m1->value;
2091
+
2092
+ $cache[MATH_BIGINTEGER_DATA][] = array(
2093
+ 'u' => $u, // m.length >> 1 (technically (m.length >> 1) + 1)
2094
+ 'm1'=> $m1 // m.length
2095
+ );
2096
+ } else {
2097
+ extract($cache[MATH_BIGINTEGER_DATA][$key]);
2098
+ }
2099
+
2100
+ $cutoff = $m_length + ($m_length >> 1);
2101
+ $lsd = array_slice($n, 0, $cutoff); // m.length + (m.length >> 1)
2102
+ $msd = array_slice($n, $cutoff); // m.length >> 1
2103
+ $lsd = $this->_trim($lsd);
2104
+ $temp = $this->_multiply($msd, false, $m1, false);
2105
+ $n = $this->_add($lsd, false, $temp[MATH_BIGINTEGER_VALUE], false); // m.length + (m.length >> 1) + 1
2106
+
2107
+ if ($m_length & 1) {
2108
+ return $this->_regularBarrett($n[MATH_BIGINTEGER_VALUE], $m);
2109
+ }
2110
+
2111
+ // (m.length + (m.length >> 1) + 1) - (m.length - 1) == (m.length >> 1) + 2
2112
+ $temp = array_slice($n[MATH_BIGINTEGER_VALUE], $m_length - 1);
2113
+ // if even: ((m.length >> 1) + 2) + (m.length >> 1) == m.length + 2
2114
+ // if odd: ((m.length >> 1) + 2) + (m.length >> 1) == (m.length - 1) + 2 == m.length + 1
2115
+ $temp = $this->_multiply($temp, false, $u, false);
2116
+ // if even: (m.length + 2) - ((m.length >> 1) + 1) = m.length - (m.length >> 1) + 1
2117
+ // if odd: (m.length + 1) - ((m.length >> 1) + 1) = m.length - (m.length >> 1)
2118
+ $temp = array_slice($temp[MATH_BIGINTEGER_VALUE], ($m_length >> 1) + 1);
2119
+ // if even: (m.length - (m.length >> 1) + 1) + m.length = 2 * m.length - (m.length >> 1) + 1
2120
+ // if odd: (m.length - (m.length >> 1)) + m.length = 2 * m.length - (m.length >> 1)
2121
+ $temp = $this->_multiply($temp, false, $m, false);
2122
+
2123
+ // at this point, if m had an odd number of digits, we'd be subtracting a 2 * m.length - (m.length >> 1) digit
2124
+ // number from a m.length + (m.length >> 1) + 1 digit number. ie. there'd be an extra digit and the while loop
2125
+ // following this comment would loop a lot (hence our calling _regularBarrett() in that situation).
2126
+
2127
+ $result = $this->_subtract($n[MATH_BIGINTEGER_VALUE], false, $temp[MATH_BIGINTEGER_VALUE], false);
2128
+
2129
+ while ($this->_compare($result[MATH_BIGINTEGER_VALUE], $result[MATH_BIGINTEGER_SIGN], $m, false) >= 0) {
2130
+ $result = $this->_subtract($result[MATH_BIGINTEGER_VALUE], $result[MATH_BIGINTEGER_SIGN], $m, false);
2131
+ }
2132
+
2133
+ return $result[MATH_BIGINTEGER_VALUE];
2134
+ }
2135
+
2136
+ /**
2137
+ * (Regular) Barrett Modular Reduction
2138
+ *
2139
+ * For numbers with more than four digits Math_BigInteger::_barrett() is faster. The difference between that and this
2140
+ * is that this function does not fold the denominator into a smaller form.
2141
+ *
2142
+ * @see self::_slidingWindow()
2143
+ * @access private
2144
+ * @param array $x
2145
+ * @param array $n
2146
+ * @return array
2147
+ */
2148
+ function _regularBarrett($x, $n)
2149
+ {
2150
+ static $cache = array(
2151
+ MATH_BIGINTEGER_VARIABLE => array(),
2152
+ MATH_BIGINTEGER_DATA => array()
2153
+ );
2154
+
2155
+ $n_length = count($n);
2156
+
2157
+ if (count($x) > 2 * $n_length) {
2158
+ $lhs = new Math_BigInteger();
2159
+ $rhs = new Math_BigInteger();
2160
+ $lhs->value = $x;
2161
+ $rhs->value = $n;
2162
+ list(, $temp) = $lhs->divide($rhs);
2163
+ return $temp->value;
2164
+ }
2165
+
2166
+ if (($key = array_search($n, $cache[MATH_BIGINTEGER_VARIABLE])) === false) {
2167
+ $key = count($cache[MATH_BIGINTEGER_VARIABLE]);
2168
+ $cache[MATH_BIGINTEGER_VARIABLE][] = $n;
2169
+ $lhs = new Math_BigInteger();
2170
+ $lhs_value = &$lhs->value;
2171
+ $lhs_value = $this->_array_repeat(0, 2 * $n_length);
2172
+ $lhs_value[] = 1;
2173
+ $rhs = new Math_BigInteger();
2174
+ $rhs->value = $n;
2175
+ list($temp, ) = $lhs->divide($rhs); // m.length
2176
+ $cache[MATH_BIGINTEGER_DATA][] = $temp->value;
2177
+ }
2178
+
2179
+ // 2 * m.length - (m.length - 1) = m.length + 1
2180
+ $temp = array_slice($x, $n_length - 1);
2181
+ // (m.length + 1) + m.length = 2 * m.length + 1
2182
+ $temp = $this->_multiply($temp, false, $cache[MATH_BIGINTEGER_DATA][$key], false);
2183
+ // (2 * m.length + 1) - (m.length - 1) = m.length + 2
2184
+ $temp = array_slice($temp[MATH_BIGINTEGER_VALUE], $n_length + 1);
2185
+
2186
+ // m.length + 1
2187
+ $result = array_slice($x, 0, $n_length + 1);
2188
+ // m.length + 1
2189
+ $temp = $this->_multiplyLower($temp, false, $n, false, $n_length + 1);
2190
+ // $temp == array_slice($temp->_multiply($temp, false, $n, false)->value, 0, $n_length + 1)
2191
+
2192
+ if ($this->_compare($result, false, $temp[MATH_BIGINTEGER_VALUE], $temp[MATH_BIGINTEGER_SIGN]) < 0) {
2193
+ $corrector_value = $this->_array_repeat(0, $n_length + 1);
2194
+ $corrector_value[count($corrector_value)] = 1;
2195
+ $result = $this->_add($result, false, $corrector_value, false);
2196
+ $result = $result[MATH_BIGINTEGER_VALUE];
2197
+ }
2198
+
2199
+ // at this point, we're subtracting a number with m.length + 1 digits from another number with m.length + 1 digits
2200
+ $result = $this->_subtract($result, false, $temp[MATH_BIGINTEGER_VALUE], $temp[MATH_BIGINTEGER_SIGN]);
2201
+ while ($this->_compare($result[MATH_BIGINTEGER_VALUE], $result[MATH_BIGINTEGER_SIGN], $n, false) > 0) {
2202
+ $result = $this->_subtract($result[MATH_BIGINTEGER_VALUE], $result[MATH_BIGINTEGER_SIGN], $n, false);
2203
+ }
2204
+
2205
+ return $result[MATH_BIGINTEGER_VALUE];
2206
+ }
2207
+
2208
+ /**
2209
+ * Performs long multiplication up to $stop digits
2210
+ *
2211
+ * If you're going to be doing array_slice($product->value, 0, $stop), some cycles can be saved.
2212
+ *
2213
+ * @see self::_regularBarrett()
2214
+ * @param array $x_value
2215
+ * @param bool $x_negative
2216
+ * @param array $y_value
2217
+ * @param bool $y_negative
2218
+ * @param int $stop
2219
+ * @return array
2220
+ * @access private
2221
+ */
2222
+ function _multiplyLower($x_value, $x_negative, $y_value, $y_negative, $stop)
2223
+ {
2224
+ $x_length = count($x_value);
2225
+ $y_length = count($y_value);
2226
+
2227
+ if (!$x_length || !$y_length) { // a 0 is being multiplied
2228
+ return array(
2229
+ MATH_BIGINTEGER_VALUE => array(),
2230
+ MATH_BIGINTEGER_SIGN => false
2231
+ );
2232
+ }
2233
+
2234
+ if ($x_length < $y_length) {
2235
+ $temp = $x_value;
2236
+ $x_value = $y_value;
2237
+ $y_value = $temp;
2238
+
2239
+ $x_length = count($x_value);
2240
+ $y_length = count($y_value);
2241
+ }
2242
+
2243
+ $product_value = $this->_array_repeat(0, $x_length + $y_length);
2244
+
2245
+ // the following for loop could be removed if the for loop following it
2246
+ // (the one with nested for loops) initially set $i to 0, but
2247
+ // doing so would also make the result in one set of unnecessary adds,
2248
+ // since on the outermost loops first pass, $product->value[$k] is going
2249
+ // to always be 0
2250
+
2251
+ $carry = 0;
2252
+
2253
+ for ($j = 0; $j < $x_length; ++$j) { // ie. $i = 0, $k = $i
2254
+ $temp = $x_value[$j] * $y_value[0] + $carry; // $product_value[$k] == 0
2255
+ $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
2256
+ $product_value[$j] = (int) ($temp - MATH_BIGINTEGER_BASE_FULL * $carry);
2257
+ }
2258
+
2259
+ if ($j < $stop) {
2260
+ $product_value[$j] = $carry;
2261
+ }
2262
+
2263
+ // the above for loop is what the previous comment was talking about. the
2264
+ // following for loop is the "one with nested for loops"
2265
+
2266
+ for ($i = 1; $i < $y_length; ++$i) {
2267
+ $carry = 0;
2268
+
2269
+ for ($j = 0, $k = $i; $j < $x_length && $k < $stop; ++$j, ++$k) {
2270
+ $temp = $product_value[$k] + $x_value[$j] * $y_value[$i] + $carry;
2271
+ $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
2272
+ $product_value[$k] = (int) ($temp - MATH_BIGINTEGER_BASE_FULL * $carry);
2273
+ }
2274
+
2275
+ if ($k < $stop) {
2276
+ $product_value[$k] = $carry;
2277
+ }
2278
+ }
2279
+
2280
+ return array(
2281
+ MATH_BIGINTEGER_VALUE => $this->_trim($product_value),
2282
+ MATH_BIGINTEGER_SIGN => $x_negative != $y_negative
2283
+ );
2284
+ }
2285
+
2286
+ /**
2287
+ * Montgomery Modular Reduction
2288
+ *
2289
+ * ($x->_prepMontgomery($n))->_montgomery($n) yields $x % $n.
2290
+ * {@link http://math.libtomcrypt.com/files/tommath.pdf#page=170 MPM 6.3} provides insights on how this can be
2291
+ * improved upon (basically, by using the comba method). gcd($n, 2) must be equal to one for this function
2292
+ * to work correctly.
2293
+ *
2294
+ * @see self::_prepMontgomery()
2295
+ * @see self::_slidingWindow()
2296
+ * @access private
2297
+ * @param array $x
2298
+ * @param array $n
2299
+ * @return array
2300
+ */
2301
+ function _montgomery($x, $n)
2302
+ {
2303
+ static $cache = array(
2304
+ MATH_BIGINTEGER_VARIABLE => array(),
2305
+ MATH_BIGINTEGER_DATA => array()
2306
+ );
2307
+
2308
+ if (($key = array_search($n, $cache[MATH_BIGINTEGER_VARIABLE])) === false) {
2309
+ $key = count($cache[MATH_BIGINTEGER_VARIABLE]);
2310
+ $cache[MATH_BIGINTEGER_VARIABLE][] = $x;
2311
+ $cache[MATH_BIGINTEGER_DATA][] = $this->_modInverse67108864($n);
2312
+ }
2313
+
2314
+ $k = count($n);
2315
+
2316
+ $result = array(MATH_BIGINTEGER_VALUE => $x);
2317
+
2318
+ for ($i = 0; $i < $k; ++$i) {
2319
+ $temp = $result[MATH_BIGINTEGER_VALUE][$i] * $cache[MATH_BIGINTEGER_DATA][$key];
2320
+ $temp = $temp - MATH_BIGINTEGER_BASE_FULL * (MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31));
2321
+ $temp = $this->_regularMultiply(array($temp), $n);
2322
+ $temp = array_merge($this->_array_repeat(0, $i), $temp);
2323
+ $result = $this->_add($result[MATH_BIGINTEGER_VALUE], false, $temp, false);
2324
+ }
2325
+
2326
+ $result[MATH_BIGINTEGER_VALUE] = array_slice($result[MATH_BIGINTEGER_VALUE], $k);
2327
+
2328
+ if ($this->_compare($result, false, $n, false) >= 0) {
2329
+ $result = $this->_subtract($result[MATH_BIGINTEGER_VALUE], false, $n, false);
2330
+ }
2331
+
2332
+ return $result[MATH_BIGINTEGER_VALUE];
2333
+ }
2334
+
2335
+ /**
2336
+ * Montgomery Multiply
2337
+ *
2338
+ * Interleaves the montgomery reduction and long multiplication algorithms together as described in
2339
+ * {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=13 HAC 14.36}
2340
+ *
2341
+ * @see self::_prepMontgomery()
2342
+ * @see self::_montgomery()
2343
+ * @access private
2344
+ * @param array $x
2345
+ * @param array $y
2346
+ * @param array $m
2347
+ * @return array
2348
+ */
2349
+ function _montgomeryMultiply($x, $y, $m)
2350
+ {
2351
+ $temp = $this->_multiply($x, false, $y, false);
2352
+ return $this->_montgomery($temp[MATH_BIGINTEGER_VALUE], $m);
2353
+
2354
+ // the following code, although not callable, can be run independently of the above code
2355
+ // although the above code performed better in my benchmarks the following could might
2356
+ // perform better under different circumstances. in lieu of deleting it it's just been
2357
+ // made uncallable
2358
+
2359
+ static $cache = array(
2360
+ MATH_BIGINTEGER_VARIABLE => array(),
2361
+ MATH_BIGINTEGER_DATA => array()
2362
+ );
2363
+
2364
+ if (($key = array_search($m, $cache[MATH_BIGINTEGER_VARIABLE])) === false) {
2365
+ $key = count($cache[MATH_BIGINTEGER_VARIABLE]);
2366
+ $cache[MATH_BIGINTEGER_VARIABLE][] = $m;
2367
+ $cache[MATH_BIGINTEGER_DATA][] = $this->_modInverse67108864($m);
2368
+ }
2369
+
2370
+ $n = max(count($x), count($y), count($m));
2371
+ $x = array_pad($x, $n, 0);
2372
+ $y = array_pad($y, $n, 0);
2373
+ $m = array_pad($m, $n, 0);
2374
+ $a = array(MATH_BIGINTEGER_VALUE => $this->_array_repeat(0, $n + 1));
2375
+ for ($i = 0; $i < $n; ++$i) {
2376
+ $temp = $a[MATH_BIGINTEGER_VALUE][0] + $x[$i] * $y[0];
2377
+ $temp = $temp - MATH_BIGINTEGER_BASE_FULL * (MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31));
2378
+ $temp = $temp * $cache[MATH_BIGINTEGER_DATA][$key];
2379
+ $temp = $temp - MATH_BIGINTEGER_BASE_FULL * (MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31));
2380
+ $temp = $this->_add($this->_regularMultiply(array($x[$i]), $y), false, $this->_regularMultiply(array($temp), $m), false);
2381
+ $a = $this->_add($a[MATH_BIGINTEGER_VALUE], false, $temp[MATH_BIGINTEGER_VALUE], false);
2382
+ $a[MATH_BIGINTEGER_VALUE] = array_slice($a[MATH_BIGINTEGER_VALUE], 1);
2383
+ }
2384
+ if ($this->_compare($a[MATH_BIGINTEGER_VALUE], false, $m, false) >= 0) {
2385
+ $a = $this->_subtract($a[MATH_BIGINTEGER_VALUE], false, $m, false);
2386
+ }
2387
+ return $a[MATH_BIGINTEGER_VALUE];
2388
+ }
2389
+
2390
+ /**
2391
+ * Prepare a number for use in Montgomery Modular Reductions
2392
+ *
2393
+ * @see self::_montgomery()
2394
+ * @see self::_slidingWindow()
2395
+ * @access private
2396
+ * @param array $x
2397
+ * @param array $n
2398
+ * @return array
2399
+ */
2400
+ function _prepMontgomery($x, $n)
2401
+ {
2402
+ $lhs = new Math_BigInteger();
2403
+ $lhs->value = array_merge($this->_array_repeat(0, count($n)), $x);
2404
+ $rhs = new Math_BigInteger();
2405
+ $rhs->value = $n;
2406
+
2407
+ list(, $temp) = $lhs->divide($rhs);
2408
+ return $temp->value;
2409
+ }
2410
+
2411
+ /**
2412
+ * Modular Inverse of a number mod 2**26 (eg. 67108864)
2413
+ *
2414
+ * Based off of the bnpInvDigit function implemented and justified in the following URL:
2415
+ *
2416
+ * {@link http://www-cs-students.stanford.edu/~tjw/jsbn/jsbn.js}
2417
+ *
2418
+ * The following URL provides more info:
2419
+ *
2420
+ * {@link http://groups.google.com/group/sci.crypt/msg/7a137205c1be7d85}
2421
+ *
2422
+ * As for why we do all the bitmasking... strange things can happen when converting from floats to ints. For
2423
+ * instance, on some computers, var_dump((int) -4294967297) yields int(-1) and on others, it yields
2424
+ * int(-2147483648). To avoid problems stemming from this, we use bitmasks to guarantee that ints aren't
2425
+ * auto-converted to floats. The outermost bitmask is present because without it, there's no guarantee that
2426
+ * the "residue" returned would be the so-called "common residue". We use fmod, in the last step, because the
2427
+ * maximum possible $x is 26 bits and the maximum $result is 16 bits. Thus, we have to be able to handle up to
2428
+ * 40 bits, which only 64-bit floating points will support.
2429
+ *
2430
+ * Thanks to Pedro Gimeno Fortea for input!
2431
+ *
2432
+ * @see self::_montgomery()
2433
+ * @access private
2434
+ * @param array $x
2435
+ * @return int
2436
+ */
2437
+ function _modInverse67108864($x) // 2**26 == 67,108,864
2438
+ {
2439
+ $x = -$x[0];
2440
+ $result = $x & 0x3; // x**-1 mod 2**2
2441
+ $result = ($result * (2 - $x * $result)) & 0xF; // x**-1 mod 2**4
2442
+ $result = ($result * (2 - ($x & 0xFF) * $result)) & 0xFF; // x**-1 mod 2**8
2443
+ $result = ($result * ((2 - ($x & 0xFFFF) * $result) & 0xFFFF)) & 0xFFFF; // x**-1 mod 2**16
2444
+ $result = fmod($result * (2 - fmod($x * $result, MATH_BIGINTEGER_BASE_FULL)), MATH_BIGINTEGER_BASE_FULL); // x**-1 mod 2**26
2445
+ return $result & MATH_BIGINTEGER_MAX_DIGIT;
2446
+ }
2447
+
2448
+ /**
2449
+ * Calculates modular inverses.
2450
+ *
2451
+ * Say you have (30 mod 17 * x mod 17) mod 17 == 1. x can be found using modular inverses.
2452
+ *
2453
+ * Here's an example:
2454
+ * <code>
2455
+ * <?php
2456
+ * include 'Math/BigInteger.php';
2457
+ *
2458
+ * $a = new Math_BigInteger(30);
2459
+ * $b = new Math_BigInteger(17);
2460
+ *
2461
+ * $c = $a->modInverse($b);
2462
+ * echo $c->toString(); // outputs 4
2463
+ *
2464
+ * echo "\r\n";
2465
+ *
2466
+ * $d = $a->multiply($c);
2467
+ * list(, $d) = $d->divide($b);
2468
+ * echo $d; // outputs 1 (as per the definition of modular inverse)
2469
+ * ?>
2470
+ * </code>
2471
+ *
2472
+ * @param Math_BigInteger $n
2473
+ * @return Math_BigInteger|false
2474
+ * @access public
2475
+ * @internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=21 HAC 14.64} for more information.
2476
+ */
2477
+ function modInverse($n)
2478
+ {
2479
+ switch (MATH_BIGINTEGER_MODE) {
2480
+ case MATH_BIGINTEGER_MODE_GMP:
2481
+ $temp = new Math_BigInteger();
2482
+ $temp->value = gmp_invert($this->value, $n->value);
2483
+
2484
+ return ($temp->value === false) ? false : $this->_normalize($temp);
2485
+ }
2486
+
2487
+ static $zero, $one;
2488
+ if (!isset($zero)) {
2489
+ $zero = new Math_BigInteger();
2490
+ $one = new Math_BigInteger(1);
2491
+ }
2492
+
2493
+ // $x mod -$n == $x mod $n.
2494
+ $n = $n->abs();
2495
+
2496
+ if ($this->compare($zero) < 0) {
2497
+ $temp = $this->abs();
2498
+ $temp = $temp->modInverse($n);
2499
+ return $this->_normalize($n->subtract($temp));
2500
+ }
2501
+
2502
+ extract($this->extendedGCD($n));
2503
+
2504
+ if (!$gcd->equals($one)) {
2505
+ return false;
2506
+ }
2507
+
2508
+ $x = $x->compare($zero) < 0 ? $x->add($n) : $x;
2509
+
2510
+ return $this->compare($zero) < 0 ? $this->_normalize($n->subtract($x)) : $this->_normalize($x);
2511
+ }
2512
+
2513
+ /**
2514
+ * Calculates the greatest common divisor and Bezout's identity.
2515
+ *
2516
+ * Say you have 693 and 609. The GCD is 21. Bezout's identity states that there exist integers x and y such that
2517
+ * 693*x + 609*y == 21. In point of fact, there are actually an infinite number of x and y combinations and which
2518
+ * combination is returned is dependent upon which mode is in use. See
2519
+ * {@link http://en.wikipedia.org/wiki/B%C3%A9zout%27s_identity Bezout's identity - Wikipedia} for more information.
2520
+ *
2521
+ * Here's an example:
2522
+ * <code>
2523
+ * <?php
2524
+ * include 'Math/BigInteger.php';
2525
+ *
2526
+ * $a = new Math_BigInteger(693);
2527
+ * $b = new Math_BigInteger(609);
2528
+ *
2529
+ * extract($a->extendedGCD($b));
2530
+ *
2531
+ * echo $gcd->toString() . "\r\n"; // outputs 21
2532
+ * echo $a->toString() * $x->toString() + $b->toString() * $y->toString(); // outputs 21
2533
+ * ?>
2534
+ * </code>
2535
+ *
2536
+ * @param Math_BigInteger $n
2537
+ * @return Math_BigInteger
2538
+ * @access public
2539
+ * @internal Calculates the GCD using the binary xGCD algorithim described in
2540
+ * {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=19 HAC 14.61}. As the text above 14.61 notes,
2541
+ * the more traditional algorithim requires "relatively costly multiple-precision divisions".
2542
+ */
2543
+ function extendedGCD($n)
2544
+ {
2545
+ switch (MATH_BIGINTEGER_MODE) {
2546
+ case MATH_BIGINTEGER_MODE_GMP:
2547
+ extract(gmp_gcdext($this->value, $n->value));
2548
+
2549
+ return array(
2550
+ 'gcd' => $this->_normalize(new Math_BigInteger($g)),
2551
+ 'x' => $this->_normalize(new Math_BigInteger($s)),
2552
+ 'y' => $this->_normalize(new Math_BigInteger($t))
2553
+ );
2554
+ case MATH_BIGINTEGER_MODE_BCMATH:
2555
+ // it might be faster to use the binary xGCD algorithim here, as well, but (1) that algorithim works
2556
+ // best when the base is a power of 2 and (2) i don't think it'd make much difference, anyway. as is,
2557
+ // the basic extended euclidean algorithim is what we're using.
2558
+
2559
+ $u = $this->value;
2560
+ $v = $n->value;
2561
+
2562
+ $a = '1';
2563
+ $b = '0';
2564
+ $c = '0';
2565
+ $d = '1';
2566
+
2567
+ while (bccomp($v, '0', 0) != 0) {
2568
+ $q = bcdiv($u, $v, 0);
2569
+
2570
+ $temp = $u;
2571
+ $u = $v;
2572
+ $v = bcsub($temp, bcmul($v, $q, 0), 0);
2573
+
2574
+ $temp = $a;
2575
+ $a = $c;
2576
+ $c = bcsub($temp, bcmul($a, $q, 0), 0);
2577
+
2578
+ $temp = $b;
2579
+ $b = $d;
2580
+ $d = bcsub($temp, bcmul($b, $q, 0), 0);
2581
+ }
2582
+
2583
+ return array(
2584
+ 'gcd' => $this->_normalize(new Math_BigInteger($u)),
2585
+ 'x' => $this->_normalize(new Math_BigInteger($a)),
2586
+ 'y' => $this->_normalize(new Math_BigInteger($b))
2587
+ );
2588
+ }
2589
+
2590
+ $y = $n->copy();
2591
+ $x = $this->copy();
2592
+ $g = new Math_BigInteger();
2593
+ $g->value = array(1);
2594
+
2595
+ while (!(($x->value[0] & 1)|| ($y->value[0] & 1))) {
2596
+ $x->_rshift(1);
2597
+ $y->_rshift(1);
2598
+ $g->_lshift(1);
2599
+ }
2600
+
2601
+ $u = $x->copy();
2602
+ $v = $y->copy();
2603
+
2604
+ $a = new Math_BigInteger();
2605
+ $b = new Math_BigInteger();
2606
+ $c = new Math_BigInteger();
2607
+ $d = new Math_BigInteger();
2608
+
2609
+ $a->value = $d->value = $g->value = array(1);
2610
+ $b->value = $c->value = array();
2611
+
2612
+ while (!empty($u->value)) {
2613
+ while (!($u->value[0] & 1)) {
2614
+ $u->_rshift(1);
2615
+ if ((!empty($a->value) && ($a->value[0] & 1)) || (!empty($b->value) && ($b->value[0] & 1))) {
2616
+ $a = $a->add($y);
2617
+ $b = $b->subtract($x);
2618
+ }
2619
+ $a->_rshift(1);
2620
+ $b->_rshift(1);
2621
+ }
2622
+
2623
+ while (!($v->value[0] & 1)) {
2624
+ $v->_rshift(1);
2625
+ if ((!empty($d->value) && ($d->value[0] & 1)) || (!empty($c->value) && ($c->value[0] & 1))) {
2626
+ $c = $c->add($y);
2627
+ $d = $d->subtract($x);
2628
+ }
2629
+ $c->_rshift(1);
2630
+ $d->_rshift(1);
2631
+ }
2632
+
2633
+ if ($u->compare($v) >= 0) {
2634
+ $u = $u->subtract($v);
2635
+ $a = $a->subtract($c);
2636
+ $b = $b->subtract($d);
2637
+ } else {
2638
+ $v = $v->subtract($u);
2639
+ $c = $c->subtract($a);
2640
+ $d = $d->subtract($b);
2641
+ }
2642
+ }
2643
+
2644
+ return array(
2645
+ 'gcd' => $this->_normalize($g->multiply($v)),
2646
+ 'x' => $this->_normalize($c),
2647
+ 'y' => $this->_normalize($d)
2648
+ );
2649
+ }
2650
+
2651
+ /**
2652
+ * Calculates the greatest common divisor
2653
+ *
2654
+ * Say you have 693 and 609. The GCD is 21.
2655
+ *
2656
+ * Here's an example:
2657
+ * <code>
2658
+ * <?php
2659
+ * include 'Math/BigInteger.php';
2660
+ *
2661
+ * $a = new Math_BigInteger(693);
2662
+ * $b = new Math_BigInteger(609);
2663
+ *
2664
+ * $gcd = a->extendedGCD($b);
2665
+ *
2666
+ * echo $gcd->toString() . "\r\n"; // outputs 21
2667
+ * ?>
2668
+ * </code>
2669
+ *
2670
+ * @param Math_BigInteger $n
2671
+ * @return Math_BigInteger
2672
+ * @access public
2673
+ */
2674
+ function gcd($n)
2675
+ {
2676
+ extract($this->extendedGCD($n));
2677
+ return $gcd;
2678
+ }
2679
+
2680
+ /**
2681
+ * Absolute value.
2682
+ *
2683
+ * @return Math_BigInteger
2684
+ * @access public
2685
+ */
2686
+ function abs()
2687
+ {
2688
+ $temp = new Math_BigInteger();
2689
+
2690
+ switch (MATH_BIGINTEGER_MODE) {
2691
+ case MATH_BIGINTEGER_MODE_GMP:
2692
+ $temp->value = gmp_abs($this->value);
2693
+ break;
2694
+ case MATH_BIGINTEGER_MODE_BCMATH:
2695
+ $temp->value = (bccomp($this->value, '0', 0) < 0) ? substr($this->value, 1) : $this->value;
2696
+ break;
2697
+ default:
2698
+ $temp->value = $this->value;
2699
+ }
2700
+
2701
+ return $temp;
2702
+ }
2703
+
2704
+ /**
2705
+ * Compares two numbers.
2706
+ *
2707
+ * Although one might think !$x->compare($y) means $x != $y, it, in fact, means the opposite. The reason for this is
2708
+ * demonstrated thusly:
2709
+ *
2710
+ * $x > $y: $x->compare($y) > 0
2711
+ * $x < $y: $x->compare($y) < 0
2712
+ * $x == $y: $x->compare($y) == 0
2713
+ *
2714
+ * Note how the same comparison operator is used. If you want to test for equality, use $x->equals($y).
2715
+ *
2716
+ * @param Math_BigInteger $y
2717
+ * @return int < 0 if $this is less than $y; > 0 if $this is greater than $y, and 0 if they are equal.
2718
+ * @access public
2719
+ * @see self::equals()
2720
+ * @internal Could return $this->subtract($x), but that's not as fast as what we do do.
2721
+ */
2722
+ function compare($y)
2723
+ {
2724
+ switch (MATH_BIGINTEGER_MODE) {
2725
+ case MATH_BIGINTEGER_MODE_GMP:
2726
+ return gmp_cmp($this->value, $y->value);
2727
+ case MATH_BIGINTEGER_MODE_BCMATH:
2728
+ return bccomp($this->value, $y->value, 0);
2729
+ }
2730
+
2731
+ return $this->_compare($this->value, $this->is_negative, $y->value, $y->is_negative);
2732
+ }
2733
+
2734
+ /**
2735
+ * Compares two numbers.
2736
+ *
2737
+ * @param array $x_value
2738
+ * @param bool $x_negative
2739
+ * @param array $y_value
2740
+ * @param bool $y_negative
2741
+ * @return int
2742
+ * @see self::compare()
2743
+ * @access private
2744
+ */
2745
+ function _compare($x_value, $x_negative, $y_value, $y_negative)
2746
+ {
2747
+ if ($x_negative != $y_negative) {
2748
+ return (!$x_negative && $y_negative) ? 1 : -1;
2749
+ }
2750
+
2751
+ $result = $x_negative ? -1 : 1;
2752
+
2753
+ if (count($x_value) != count($y_value)) {
2754
+ return (count($x_value) > count($y_value)) ? $result : -$result;
2755
+ }
2756
+ $size = max(count($x_value), count($y_value));
2757
+
2758
+ $x_value = array_pad($x_value, $size, 0);
2759
+ $y_value = array_pad($y_value, $size, 0);
2760
+
2761
+ for ($i = count($x_value) - 1; $i >= 0; --$i) {
2762
+ if ($x_value[$i] != $y_value[$i]) {
2763
+ return ($x_value[$i] > $y_value[$i]) ? $result : -$result;
2764
+ }
2765
+ }
2766
+
2767
+ return 0;
2768
+ }
2769
+
2770
+ /**
2771
+ * Tests the equality of two numbers.
2772
+ *
2773
+ * If you need to see if one number is greater than or less than another number, use Math_BigInteger::compare()
2774
+ *
2775
+ * @param Math_BigInteger $x
2776
+ * @return bool
2777
+ * @access public
2778
+ * @see self::compare()
2779
+ */
2780
+ function equals($x)
2781
+ {
2782
+ switch (MATH_BIGINTEGER_MODE) {
2783
+ case MATH_BIGINTEGER_MODE_GMP:
2784
+ return gmp_cmp($this->value, $x->value) == 0;
2785
+ default:
2786
+ return $this->value === $x->value && $this->is_negative == $x->is_negative;
2787
+ }
2788
+ }
2789
+
2790
+ /**
2791
+ * Set Precision
2792
+ *
2793
+ * Some bitwise operations give different results depending on the precision being used. Examples include left
2794
+ * shift, not, and rotates.
2795
+ *
2796
+ * @param int $bits
2797
+ * @access public
2798
+ */
2799
+ function setPrecision($bits)
2800
+ {
2801
+ $this->precision = $bits;
2802
+ if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_BCMATH) {
2803
+ $this->bitmask = new Math_BigInteger(chr((1 << ($bits & 0x7)) - 1) . str_repeat(chr(0xFF), $bits >> 3), 256);
2804
+ } else {
2805
+ $this->bitmask = new Math_BigInteger(bcpow('2', $bits, 0));
2806
+ }
2807
+
2808
+ $temp = $this->_normalize($this);
2809
+ $this->value = $temp->value;
2810
+ }
2811
+
2812
+ /**
2813
+ * Logical And
2814
+ *
2815
+ * @param Math_BigInteger $x
2816
+ * @access public
2817
+ * @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
2818
+ * @return Math_BigInteger
2819
+ */
2820
+ function bitwise_and($x)
2821
+ {
2822
+ switch (MATH_BIGINTEGER_MODE) {
2823
+ case MATH_BIGINTEGER_MODE_GMP:
2824
+ $temp = new Math_BigInteger();
2825
+ $temp->value = gmp_and($this->value, $x->value);
2826
+
2827
+ return $this->_normalize($temp);
2828
+ case MATH_BIGINTEGER_MODE_BCMATH:
2829
+ $left = $this->toBytes();
2830
+ $right = $x->toBytes();
2831
+
2832
+ $length = max(strlen($left), strlen($right));
2833
+
2834
+ $left = str_pad($left, $length, chr(0), STR_PAD_LEFT);
2835
+ $right = str_pad($right, $length, chr(0), STR_PAD_LEFT);
2836
+
2837
+ return $this->_normalize(new Math_BigInteger($left & $right, 256));
2838
+ }
2839
+
2840
+ $result = $this->copy();
2841
+
2842
+ $length = min(count($x->value), count($this->value));
2843
+
2844
+ $result->value = array_slice($result->value, 0, $length);
2845
+
2846
+ for ($i = 0; $i < $length; ++$i) {
2847
+ $result->value[$i]&= $x->value[$i];
2848
+ }
2849
+
2850
+ return $this->_normalize($result);
2851
+ }
2852
+
2853
+ /**
2854
+ * Logical Or
2855
+ *
2856
+ * @param Math_BigInteger $x
2857
+ * @access public
2858
+ * @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
2859
+ * @return Math_BigInteger
2860
+ */
2861
+ function bitwise_or($x)
2862
+ {
2863
+ switch (MATH_BIGINTEGER_MODE) {
2864
+ case MATH_BIGINTEGER_MODE_GMP:
2865
+ $temp = new Math_BigInteger();
2866
+ $temp->value = gmp_or($this->value, $x->value);
2867
+
2868
+ return $this->_normalize($temp);
2869
+ case MATH_BIGINTEGER_MODE_BCMATH:
2870
+ $left = $this->toBytes();
2871
+ $right = $x->toBytes();
2872
+
2873
+ $length = max(strlen($left), strlen($right));
2874
+
2875
+ $left = str_pad($left, $length, chr(0), STR_PAD_LEFT);
2876
+ $right = str_pad($right, $length, chr(0), STR_PAD_LEFT);
2877
+
2878
+ return $this->_normalize(new Math_BigInteger($left | $right, 256));
2879
+ }
2880
+
2881
+ $length = max(count($this->value), count($x->value));
2882
+ $result = $this->copy();
2883
+ $result->value = array_pad($result->value, $length, 0);
2884
+ $x->value = array_pad($x->value, $length, 0);
2885
+
2886
+ for ($i = 0; $i < $length; ++$i) {
2887
+ $result->value[$i]|= $x->value[$i];
2888
+ }
2889
+
2890
+ return $this->_normalize($result);
2891
+ }
2892
+
2893
+ /**
2894
+ * Logical Exclusive-Or
2895
+ *
2896
+ * @param Math_BigInteger $x
2897
+ * @access public
2898
+ * @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
2899
+ * @return Math_BigInteger
2900
+ */
2901
+ function bitwise_xor($x)
2902
+ {
2903
+ switch (MATH_BIGINTEGER_MODE) {
2904
+ case MATH_BIGINTEGER_MODE_GMP:
2905
+ $temp = new Math_BigInteger();
2906
+ $temp->value = gmp_xor($this->value, $x->value);
2907
+
2908
+ return $this->_normalize($temp);
2909
+ case MATH_BIGINTEGER_MODE_BCMATH:
2910
+ $left = $this->toBytes();
2911
+ $right = $x->toBytes();
2912
+
2913
+ $length = max(strlen($left), strlen($right));
2914
+
2915
+ $left = str_pad($left, $length, chr(0), STR_PAD_LEFT);
2916
+ $right = str_pad($right, $length, chr(0), STR_PAD_LEFT);
2917
+
2918
+ return $this->_normalize(new Math_BigInteger($left ^ $right, 256));
2919
+ }
2920
+
2921
+ $length = max(count($this->value), count($x->value));
2922
+ $result = $this->copy();
2923
+ $result->value = array_pad($result->value, $length, 0);
2924
+ $x->value = array_pad($x->value, $length, 0);
2925
+
2926
+ for ($i = 0; $i < $length; ++$i) {
2927
+ $result->value[$i]^= $x->value[$i];
2928
+ }
2929
+
2930
+ return $this->_normalize($result);
2931
+ }
2932
+
2933
+ /**
2934
+ * Logical Not
2935
+ *
2936
+ * @access public
2937
+ * @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
2938
+ * @return Math_BigInteger
2939
+ */
2940
+ function bitwise_not()
2941
+ {
2942
+ // calculuate "not" without regard to $this->precision
2943
+ // (will always result in a smaller number. ie. ~1 isn't 1111 1110 - it's 0)
2944
+ $temp = $this->toBytes();
2945
+ if ($temp == '') {
2946
+ return '';
2947
+ }
2948
+ $pre_msb = decbin(ord($temp[0]));
2949
+ $temp = ~$temp;
2950
+ $msb = decbin(ord($temp[0]));
2951
+ if (strlen($msb) == 8) {
2952
+ $msb = substr($msb, strpos($msb, '0'));
2953
+ }
2954
+ $temp[0] = chr(bindec($msb));
2955
+
2956
+ // see if we need to add extra leading 1's
2957
+ $current_bits = strlen($pre_msb) + 8 * strlen($temp) - 8;
2958
+ $new_bits = $this->precision - $current_bits;
2959
+ if ($new_bits <= 0) {
2960
+ return $this->_normalize(new Math_BigInteger($temp, 256));
2961
+ }
2962
+
2963
+ // generate as many leading 1's as we need to.
2964
+ $leading_ones = chr((1 << ($new_bits & 0x7)) - 1) . str_repeat(chr(0xFF), $new_bits >> 3);
2965
+ $this->_base256_lshift($leading_ones, $current_bits);
2966
+
2967
+ $temp = str_pad($temp, strlen($leading_ones), chr(0), STR_PAD_LEFT);
2968
+
2969
+ return $this->_normalize(new Math_BigInteger($leading_ones | $temp, 256));
2970
+ }
2971
+
2972
+ /**
2973
+ * Logical Right Shift
2974
+ *
2975
+ * Shifts BigInteger's by $shift bits, effectively dividing by 2**$shift.
2976
+ *
2977
+ * @param int $shift
2978
+ * @return Math_BigInteger
2979
+ * @access public
2980
+ * @internal The only version that yields any speed increases is the internal version.
2981
+ */
2982
+ function bitwise_rightShift($shift)
2983
+ {
2984
+ $temp = new Math_BigInteger();
2985
+
2986
+ switch (MATH_BIGINTEGER_MODE) {
2987
+ case MATH_BIGINTEGER_MODE_GMP:
2988
+ static $two;
2989
+
2990
+ if (!isset($two)) {
2991
+ $two = gmp_init('2');
2992
+ }
2993
+
2994
+ $temp->value = gmp_div_q($this->value, gmp_pow($two, $shift));
2995
+
2996
+ break;
2997
+ case MATH_BIGINTEGER_MODE_BCMATH:
2998
+ $temp->value = bcdiv($this->value, bcpow('2', $shift, 0), 0);
2999
+
3000
+ break;
3001
+ default: // could just replace _lshift with this, but then all _lshift() calls would need to be rewritten
3002
+ // and I don't want to do that...
3003
+ $temp->value = $this->value;
3004
+ $temp->_rshift($shift);
3005
+ }
3006
+
3007
+ return $this->_normalize($temp);
3008
+ }
3009
+
3010
+ /**
3011
+ * Logical Left Shift
3012
+ *
3013
+ * Shifts BigInteger's by $shift bits, effectively multiplying by 2**$shift.
3014
+ *
3015
+ * @param int $shift
3016
+ * @return Math_BigInteger
3017
+ * @access public
3018
+ * @internal The only version that yields any speed increases is the internal version.
3019
+ */
3020
+ function bitwise_leftShift($shift)
3021
+ {
3022
+ $temp = new Math_BigInteger();
3023
+
3024
+ switch (MATH_BIGINTEGER_MODE) {
3025
+ case MATH_BIGINTEGER_MODE_GMP:
3026
+ static $two;
3027
+
3028
+ if (!isset($two)) {
3029
+ $two = gmp_init('2');
3030
+ }
3031
+
3032
+ $temp->value = gmp_mul($this->value, gmp_pow($two, $shift));
3033
+
3034
+ break;
3035
+ case MATH_BIGINTEGER_MODE_BCMATH:
3036
+ $temp->value = bcmul($this->value, bcpow('2', $shift, 0), 0);
3037
+
3038
+ break;
3039
+ default: // could just replace _rshift with this, but then all _lshift() calls would need to be rewritten
3040
+ // and I don't want to do that...
3041
+ $temp->value = $this->value;
3042
+ $temp->_lshift($shift);
3043
+ }
3044
+
3045
+ return $this->_normalize($temp);
3046
+ }
3047
+
3048
+ /**
3049
+ * Logical Left Rotate
3050
+ *
3051
+ * Instead of the top x bits being dropped they're appended to the shifted bit string.
3052
+ *
3053
+ * @param int $shift
3054
+ * @return Math_BigInteger
3055
+ * @access public
3056
+ */
3057
+ function bitwise_leftRotate($shift)
3058
+ {
3059
+ $bits = $this->toBytes();
3060
+
3061
+ if ($this->precision > 0) {
3062
+ $precision = $this->precision;
3063
+ if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH) {
3064
+ $mask = $this->bitmask->subtract(new Math_BigInteger(1));
3065
+ $mask = $mask->toBytes();
3066
+ } else {
3067
+ $mask = $this->bitmask->toBytes();
3068
+ }
3069
+ } else {
3070
+ $temp = ord($bits[0]);
3071
+ for ($i = 0; $temp >> $i; ++$i) {
3072
+ }
3073
+ $precision = 8 * strlen($bits) - 8 + $i;
3074
+ $mask = chr((1 << ($precision & 0x7)) - 1) . str_repeat(chr(0xFF), $precision >> 3);
3075
+ }
3076
+
3077
+ if ($shift < 0) {
3078
+ $shift+= $precision;
3079
+ }
3080
+ $shift%= $precision;
3081
+
3082
+ if (!$shift) {
3083
+ return $this->copy();
3084
+ }
3085
+
3086
+ $left = $this->bitwise_leftShift($shift);
3087
+ $left = $left->bitwise_and(new Math_BigInteger($mask, 256));
3088
+ $right = $this->bitwise_rightShift($precision - $shift);
3089
+ $result = MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_BCMATH ? $left->bitwise_or($right) : $left->add($right);
3090
+ return $this->_normalize($result);
3091
+ }
3092
+
3093
+ /**
3094
+ * Logical Right Rotate
3095
+ *
3096
+ * Instead of the bottom x bits being dropped they're prepended to the shifted bit string.
3097
+ *
3098
+ * @param int $shift
3099
+ * @return Math_BigInteger
3100
+ * @access public
3101
+ */
3102
+ function bitwise_rightRotate($shift)
3103
+ {
3104
+ return $this->bitwise_leftRotate(-$shift);
3105
+ }
3106
+
3107
+ /**
3108
+ * Set random number generator function
3109
+ *
3110
+ * This function is deprecated.
3111
+ *
3112
+ * @param string $generator
3113
+ * @access public
3114
+ */
3115
+ function setRandomGenerator($generator)
3116
+ {
3117
+ }
3118
+
3119
+ /**
3120
+ * Generates a random BigInteger
3121
+ *
3122
+ * Byte length is equal to $length. Uses crypt_random if it's loaded and mt_rand if it's not.
3123
+ *
3124
+ * @param int $length
3125
+ * @return Math_BigInteger
3126
+ * @access private
3127
+ */
3128
+ function _random_number_helper($size)
3129
+ {
3130
+ if (function_exists('crypt_random_string')) {
3131
+ $random = crypt_random_string($size);
3132
+ } else {
3133
+ $random = '';
3134
+
3135
+ if ($size & 1) {
3136
+ $random.= chr(mt_rand(0, 255));
3137
+ }
3138
+
3139
+ $blocks = $size >> 1;
3140
+ for ($i = 0; $i < $blocks; ++$i) {
3141
+ // mt_rand(-2147483648, 0x7FFFFFFF) always produces -2147483648 on some systems
3142
+ $random.= pack('n', mt_rand(0, 0xFFFF));
3143
+ }
3144
+ }
3145
+
3146
+ return new Math_BigInteger($random, 256);
3147
+ }
3148
+
3149
+ /**
3150
+ * Generate a random number
3151
+ *
3152
+ * Returns a random number between $min and $max where $min and $max
3153
+ * can be defined using one of the two methods:
3154
+ *
3155
+ * $min->random($max)
3156
+ * $max->random($min)
3157
+ *
3158
+ * @param Math_BigInteger $arg1
3159
+ * @param Math_BigInteger $arg2
3160
+ * @return Math_BigInteger
3161
+ * @access public
3162
+ * @internal The API for creating random numbers used to be $a->random($min, $max), where $a was a Math_BigInteger object.
3163
+ * That method is still supported for BC purposes.
3164
+ */
3165
+ function random($arg1, $arg2 = false)
3166
+ {
3167
+ if ($arg1 === false) {
3168
+ return false;
3169
+ }
3170
+
3171
+ if ($arg2 === false) {
3172
+ $max = $arg1;
3173
+ $min = $this;
3174
+ } else {
3175
+ $min = $arg1;
3176
+ $max = $arg2;
3177
+ }
3178
+
3179
+ $compare = $max->compare($min);
3180
+
3181
+ if (!$compare) {
3182
+ return $this->_normalize($min);
3183
+ } elseif ($compare < 0) {
3184
+ // if $min is bigger then $max, swap $min and $max
3185
+ $temp = $max;
3186
+ $max = $min;
3187
+ $min = $temp;
3188
+ }
3189
+
3190
+ static $one;
3191
+ if (!isset($one)) {
3192
+ $one = new Math_BigInteger(1);
3193
+ }
3194
+
3195
+ $max = $max->subtract($min->subtract($one));
3196
+ $size = strlen(ltrim($max->toBytes(), chr(0)));
3197
+
3198
+ /*
3199
+ doing $random % $max doesn't work because some numbers will be more likely to occur than others.
3200
+ eg. if $max is 140 and $random's max is 255 then that'd mean both $random = 5 and $random = 145
3201
+ would produce 5 whereas the only value of random that could produce 139 would be 139. ie.
3202
+ not all numbers would be equally likely. some would be more likely than others.
3203
+
3204
+ creating a whole new random number until you find one that is within the range doesn't work
3205
+ because, for sufficiently small ranges, the likelihood that you'd get a number within that range
3206
+ would be pretty small. eg. with $random's max being 255 and if your $max being 1 the probability
3207
+ would be pretty high that $random would be greater than $max.
3208
+
3209
+ phpseclib works around this using the technique described here:
3210
+
3211
+ http://crypto.stackexchange.com/questions/5708/creating-a-small-number-from-a-cryptographically-secure-random-string
3212
+ */
3213
+ $random_max = new Math_BigInteger(chr(1) . str_repeat("\0", $size), 256);
3214
+ $random = $this->_random_number_helper($size);
3215
+
3216
+ list($max_multiple) = $random_max->divide($max);
3217
+ $max_multiple = $max_multiple->multiply($max);
3218
+
3219
+ while ($random->compare($max_multiple) >= 0) {
3220
+ $random = $random->subtract($max_multiple);
3221
+ $random_max = $random_max->subtract($max_multiple);
3222
+ $random = $random->bitwise_leftShift(8);
3223
+ $random = $random->add($this->_random_number_helper(1));
3224
+ $random_max = $random_max->bitwise_leftShift(8);
3225
+ list($max_multiple) = $random_max->divide($max);
3226
+ $max_multiple = $max_multiple->multiply($max);
3227
+ }
3228
+ list(, $random) = $random->divide($max);
3229
+
3230
+ return $this->_normalize($random->add($min));
3231
+ }
3232
+
3233
+ /**
3234
+ * Generate a random prime number.
3235
+ *
3236
+ * If there's not a prime within the given range, false will be returned.
3237
+ * If more than $timeout seconds have elapsed, give up and return false.
3238
+ *
3239
+ * @param Math_BigInteger $arg1
3240
+ * @param Math_BigInteger $arg2
3241
+ * @param int $timeout
3242
+ * @return Math_BigInteger|false
3243
+ * @access public
3244
+ * @internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=15 HAC 4.44}.
3245
+ */
3246
+ function randomPrime($arg1, $arg2 = false, $timeout = false)
3247
+ {
3248
+ if ($arg1 === false) {
3249
+ return false;
3250
+ }
3251
+
3252
+ if ($arg2 === false) {
3253
+ $max = $arg1;
3254
+ $min = $this;
3255
+ } else {
3256
+ $min = $arg1;
3257
+ $max = $arg2;
3258
+ }
3259
+
3260
+ $compare = $max->compare($min);
3261
+
3262
+ if (!$compare) {
3263
+ return $min->isPrime() ? $min : false;
3264
+ } elseif ($compare < 0) {
3265
+ // if $min is bigger then $max, swap $min and $max
3266
+ $temp = $max;
3267
+ $max = $min;
3268
+ $min = $temp;
3269
+ }
3270
+
3271
+ static $one, $two;
3272
+ if (!isset($one)) {
3273
+ $one = new Math_BigInteger(1);
3274
+ $two = new Math_BigInteger(2);
3275
+ }
3276
+
3277
+ $start = time();
3278
+
3279
+ $x = $this->random($min, $max);
3280
+
3281
+ // gmp_nextprime() requires PHP 5 >= 5.2.0 per <http://php.net/gmp-nextprime>.
3282
+ if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP && extension_loaded('gmp') && version_compare(PHP_VERSION, '5.2.0', '>=')) {
3283
+ $p = new Math_BigInteger();
3284
+ $p->value = gmp_nextprime($x->value);
3285
+
3286
+ if ($p->compare($max) <= 0) {
3287
+ return $p;
3288
+ }
3289
+
3290
+ if (!$min->equals($x)) {
3291
+ $x = $x->subtract($one);
3292
+ }
3293
+
3294
+ return $x->randomPrime($min, $x);
3295
+ }
3296
+
3297
+ if ($x->equals($two)) {
3298
+ return $x;
3299
+ }
3300
+
3301
+ $x->_make_odd();
3302
+ if ($x->compare($max) > 0) {
3303
+ // if $x > $max then $max is even and if $min == $max then no prime number exists between the specified range
3304
+ if ($min->equals($max)) {
3305
+ return false;
3306
+ }
3307
+ $x = $min->copy();
3308
+ $x->_make_odd();
3309
+ }
3310
+
3311
+ $initial_x = $x->copy();
3312
+
3313
+ while (true) {
3314
+ if ($timeout !== false && time() - $start > $timeout) {
3315
+ return false;
3316
+ }
3317
+
3318
+ if ($x->isPrime()) {
3319
+ return $x;
3320
+ }
3321
+
3322
+ $x = $x->add($two);
3323
+
3324
+ if ($x->compare($max) > 0) {
3325
+ $x = $min->copy();
3326
+ if ($x->equals($two)) {
3327
+ return $x;
3328
+ }
3329
+ $x->_make_odd();
3330
+ }
3331
+
3332
+ if ($x->equals($initial_x)) {
3333
+ return false;
3334
+ }
3335
+ }
3336
+ }
3337
+
3338
+ /**
3339
+ * Make the current number odd
3340
+ *
3341
+ * If the current number is odd it'll be unchanged. If it's even, one will be added to it.
3342
+ *
3343
+ * @see self::randomPrime()
3344
+ * @access private
3345
+ */
3346
+ function _make_odd()
3347
+ {
3348
+ switch (MATH_BIGINTEGER_MODE) {
3349
+ case MATH_BIGINTEGER_MODE_GMP:
3350
+ gmp_setbit($this->value, 0);
3351
+ break;
3352
+ case MATH_BIGINTEGER_MODE_BCMATH:
3353
+ if ($this->value[strlen($this->value) - 1] % 2 == 0) {
3354
+ $this->value = bcadd($this->value, '1');
3355
+ }
3356
+ break;
3357
+ default:
3358
+ $this->value[0] |= 1;
3359
+ }
3360
+ }
3361
+
3362
+ /**
3363
+ * Checks a numer to see if it's prime
3364
+ *
3365
+ * Assuming the $t parameter is not set, this function has an error rate of 2**-80. The main motivation for the
3366
+ * $t parameter is distributability. Math_BigInteger::randomPrime() can be distributed across multiple pageloads
3367
+ * on a website instead of just one.
3368
+ *
3369
+ * @param Math_BigInteger $t
3370
+ * @return bool
3371
+ * @access public
3372
+ * @internal Uses the
3373
+ * {@link http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test Miller-Rabin primality test}. See
3374
+ * {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=8 HAC 4.24}.
3375
+ */
3376
+ function isPrime($t = false)
3377
+ {
3378
+ $length = strlen($this->toBytes());
3379
+
3380
+ if (!$t) {
3381
+ // see HAC 4.49 "Note (controlling the error probability)"
3382
+ // @codingStandardsIgnoreStart
3383
+ if ($length >= 163) { $t = 2; } // floor(1300 / 8)
3384
+ else if ($length >= 106) { $t = 3; } // floor( 850 / 8)
3385
+ else if ($length >= 81 ) { $t = 4; } // floor( 650 / 8)
3386
+ else if ($length >= 68 ) { $t = 5; } // floor( 550 / 8)
3387
+ else if ($length >= 56 ) { $t = 6; } // floor( 450 / 8)
3388
+ else if ($length >= 50 ) { $t = 7; } // floor( 400 / 8)
3389
+ else if ($length >= 43 ) { $t = 8; } // floor( 350 / 8)
3390
+ else if ($length >= 37 ) { $t = 9; } // floor( 300 / 8)
3391
+ else if ($length >= 31 ) { $t = 12; } // floor( 250 / 8)
3392
+ else if ($length >= 25 ) { $t = 15; } // floor( 200 / 8)
3393
+ else if ($length >= 18 ) { $t = 18; } // floor( 150 / 8)
3394
+ else { $t = 27; }
3395
+ // @codingStandardsIgnoreEnd
3396
+ }
3397
+
3398
+ // ie. gmp_testbit($this, 0)
3399
+ // ie. isEven() or !isOdd()
3400
+ switch (MATH_BIGINTEGER_MODE) {
3401
+ case MATH_BIGINTEGER_MODE_GMP:
3402
+ return gmp_prob_prime($this->value, $t) != 0;
3403
+ case MATH_BIGINTEGER_MODE_BCMATH:
3404
+ if ($this->value === '2') {
3405
+ return true;
3406
+ }
3407
+ if ($this->value[strlen($this->value) - 1] % 2 == 0) {
3408
+ return false;
3409
+ }
3410
+ break;
3411
+ default:
3412
+ if ($this->value == array(2)) {
3413
+ return true;
3414
+ }
3415
+ if (~$this->value[0] & 1) {
3416
+ return false;
3417
+ }
3418
+ }
3419
+
3420
+ static $primes, $zero, $one, $two;
3421
+
3422
+ if (!isset($primes)) {
3423
+ $primes = array(
3424
+ 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
3425
+ 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
3426
+ 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227,
3427
+ 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
3428
+ 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
3429
+ 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
3430
+ 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617,
3431
+ 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,
3432
+ 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829,
3433
+ 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947,
3434
+ 953, 967, 971, 977, 983, 991, 997
3435
+ );
3436
+
3437
+ if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) {
3438
+ for ($i = 0; $i < count($primes); ++$i) {
3439
+ $primes[$i] = new Math_BigInteger($primes[$i]);
3440
+ }
3441
+ }
3442
+
3443
+ $zero = new Math_BigInteger();
3444
+ $one = new Math_BigInteger(1);
3445
+ $two = new Math_BigInteger(2);
3446
+ }
3447
+
3448
+ if ($this->equals($one)) {
3449
+ return false;
3450
+ }
3451
+
3452
+ // see HAC 4.4.1 "Random search for probable primes"
3453
+ if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) {
3454
+ foreach ($primes as $prime) {
3455
+ list(, $r) = $this->divide($prime);
3456
+ if ($r->equals($zero)) {
3457
+ return $this->equals($prime);
3458
+ }
3459
+ }
3460
+ } else {
3461
+ $value = $this->value;
3462
+ foreach ($primes as $prime) {
3463
+ list(, $r) = $this->_divide_digit($value, $prime);
3464
+ if (!$r) {
3465
+ return count($value) == 1 && $value[0] == $prime;
3466
+ }
3467
+ }
3468
+ }
3469
+
3470
+ $n = $this->copy();
3471
+ $n_1 = $n->subtract($one);
3472
+ $n_2 = $n->subtract($two);
3473
+
3474
+ $r = $n_1->copy();
3475
+ $r_value = $r->value;
3476
+ // ie. $s = gmp_scan1($n, 0) and $r = gmp_div_q($n, gmp_pow(gmp_init('2'), $s));
3477
+ if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH) {
3478
+ $s = 0;
3479
+ // if $n was 1, $r would be 0 and this would be an infinite loop, hence our $this->equals($one) check earlier
3480
+ while ($r->value[strlen($r->value) - 1] % 2 == 0) {
3481
+ $r->value = bcdiv($r->value, '2', 0);
3482
+ ++$s;
3483
+ }
3484
+ } else {
3485
+ for ($i = 0, $r_length = count($r_value); $i < $r_length; ++$i) {
3486
+ $temp = ~$r_value[$i] & 0xFFFFFF;
3487
+ for ($j = 1; ($temp >> $j) & 1; ++$j) {
3488
+ }
3489
+ if ($j != 25) {
3490
+ break;
3491
+ }
3492
+ }
3493
+ $s = 26 * $i + $j - 1;
3494
+ $r->_rshift($s);
3495
+ }
3496
+
3497
+ for ($i = 0; $i < $t; ++$i) {
3498
+ $a = $this->random($two, $n_2);
3499
+ $y = $a->modPow($r, $n);
3500
+
3501
+ if (!$y->equals($one) && !$y->equals($n_1)) {
3502
+ for ($j = 1; $j < $s && !$y->equals($n_1); ++$j) {
3503
+ $y = $y->modPow($two, $n);
3504
+ if ($y->equals($one)) {
3505
+ return false;
3506
+ }
3507
+ }
3508
+
3509
+ if (!$y->equals($n_1)) {
3510
+ return false;
3511
+ }
3512
+ }
3513
+ }
3514
+ return true;
3515
+ }
3516
+
3517
+ /**
3518
+ * Logical Left Shift
3519
+ *
3520
+ * Shifts BigInteger's by $shift bits.
3521
+ *
3522
+ * @param int $shift
3523
+ * @access private
3524
+ */
3525
+ function _lshift($shift)
3526
+ {
3527
+ if ($shift == 0) {
3528
+ return;
3529
+ }
3530
+
3531
+ $num_digits = (int) ($shift / MATH_BIGINTEGER_BASE);
3532
+ $shift %= MATH_BIGINTEGER_BASE;
3533
+ $shift = 1 << $shift;
3534
+
3535
+ $carry = 0;
3536
+
3537
+ for ($i = 0; $i < count($this->value); ++$i) {
3538
+ $temp = $this->value[$i] * $shift + $carry;
3539
+ $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
3540
+ $this->value[$i] = (int) ($temp - $carry * MATH_BIGINTEGER_BASE_FULL);
3541
+ }
3542
+
3543
+ if ($carry) {
3544
+ $this->value[count($this->value)] = $carry;
3545
+ }
3546
+
3547
+ while ($num_digits--) {
3548
+ array_unshift($this->value, 0);
3549
+ }
3550
+ }
3551
+
3552
+ /**
3553
+ * Logical Right Shift
3554
+ *
3555
+ * Shifts BigInteger's by $shift bits.
3556
+ *
3557
+ * @param int $shift
3558
+ * @access private
3559
+ */
3560
+ function _rshift($shift)
3561
+ {
3562
+ if ($shift == 0) {
3563
+ return;
3564
+ }
3565
+
3566
+ $num_digits = (int) ($shift / MATH_BIGINTEGER_BASE);
3567
+ $shift %= MATH_BIGINTEGER_BASE;
3568
+ $carry_shift = MATH_BIGINTEGER_BASE - $shift;
3569
+ $carry_mask = (1 << $shift) - 1;
3570
+
3571
+ if ($num_digits) {
3572
+ $this->value = array_slice($this->value, $num_digits);
3573
+ }
3574
+
3575
+ $carry = 0;
3576
+
3577
+ for ($i = count($this->value) - 1; $i >= 0; --$i) {
3578
+ $temp = $this->value[$i] >> $shift | $carry;
3579
+ $carry = ($this->value[$i] & $carry_mask) << $carry_shift;
3580
+ $this->value[$i] = $temp;
3581
+ }
3582
+
3583
+ $this->value = $this->_trim($this->value);
3584
+ }
3585
+
3586
+ /**
3587
+ * Normalize
3588
+ *
3589
+ * Removes leading zeros and truncates (if necessary) to maintain the appropriate precision
3590
+ *
3591
+ * @param Math_BigInteger
3592
+ * @return Math_BigInteger
3593
+ * @see self::_trim()
3594
+ * @access private
3595
+ */
3596
+ function _normalize($result)
3597
+ {
3598
+ $result->precision = $this->precision;
3599
+ $result->bitmask = $this->bitmask;
3600
+
3601
+ switch (MATH_BIGINTEGER_MODE) {
3602
+ case MATH_BIGINTEGER_MODE_GMP:
3603
+ if ($this->bitmask !== false) {
3604
+ $result->value = gmp_and($result->value, $result->bitmask->value);
3605
+ }
3606
+
3607
+ return $result;
3608
+ case MATH_BIGINTEGER_MODE_BCMATH:
3609
+ if (!empty($result->bitmask->value)) {
3610
+ $result->value = bcmod($result->value, $result->bitmask->value);
3611
+ }
3612
+
3613
+ return $result;
3614
+ }
3615
+
3616
+ $value = &$result->value;
3617
+
3618
+ if (!count($value)) {
3619
+ return $result;
3620
+ }
3621
+
3622
+ $value = $this->_trim($value);
3623
+
3624
+ if (!empty($result->bitmask->value)) {
3625
+ $length = min(count($value), count($this->bitmask->value));
3626
+ $value = array_slice($value, 0, $length);
3627
+
3628
+ for ($i = 0; $i < $length; ++$i) {
3629
+ $value[$i] = $value[$i] & $this->bitmask->value[$i];
3630
+ }
3631
+ }
3632
+
3633
+ return $result;
3634
+ }
3635
+
3636
+ /**
3637
+ * Trim
3638
+ *
3639
+ * Removes leading zeros
3640
+ *
3641
+ * @param array $value
3642
+ * @return Math_BigInteger
3643
+ * @access private
3644
+ */
3645
+ function _trim($value)
3646
+ {
3647
+ for ($i = count($value) - 1; $i >= 0; --$i) {
3648
+ if ($value[$i]) {
3649
+ break;
3650
+ }
3651
+ unset($value[$i]);
3652
+ }
3653
+
3654
+ return $value;
3655
+ }
3656
+
3657
+ /**
3658
+ * Array Repeat
3659
+ *
3660
+ * @param $input Array
3661
+ * @param $multiplier mixed
3662
+ * @return array
3663
+ * @access private
3664
+ */
3665
+ function _array_repeat($input, $multiplier)
3666
+ {
3667
+ return ($multiplier) ? array_fill(0, $multiplier, $input) : array();
3668
+ }
3669
+
3670
+ /**
3671
+ * Logical Left Shift
3672
+ *
3673
+ * Shifts binary strings $shift bits, essentially multiplying by 2**$shift.
3674
+ *
3675
+ * @param $x String
3676
+ * @param $shift Integer
3677
+ * @return string
3678
+ * @access private
3679
+ */
3680
+ function _base256_lshift(&$x, $shift)
3681
+ {
3682
+ if ($shift == 0) {
3683
+ return;
3684
+ }
3685
+
3686
+ $num_bytes = $shift >> 3; // eg. floor($shift/8)
3687
+ $shift &= 7; // eg. $shift % 8
3688
+
3689
+ $carry = 0;
3690
+ for ($i = strlen($x) - 1; $i >= 0; --$i) {
3691
+ $temp = ord($x[$i]) << $shift | $carry;
3692
+ $x[$i] = chr($temp);
3693
+ $carry = $temp >> 8;
3694
+ }
3695
+ $carry = ($carry != 0) ? chr($carry) : '';
3696
+ $x = $carry . $x . str_repeat(chr(0), $num_bytes);
3697
+ }
3698
+
3699
+ /**
3700
+ * Logical Right Shift
3701
+ *
3702
+ * Shifts binary strings $shift bits, essentially dividing by 2**$shift and returning the remainder.
3703
+ *
3704
+ * @param $x String
3705
+ * @param $shift Integer
3706
+ * @return string
3707
+ * @access private
3708
+ */
3709
+ function _base256_rshift(&$x, $shift)
3710
+ {
3711
+ if ($shift == 0) {
3712
+ $x = ltrim($x, chr(0));
3713
+ return '';
3714
+ }
3715
+
3716
+ $num_bytes = $shift >> 3; // eg. floor($shift/8)
3717
+ $shift &= 7; // eg. $shift % 8
3718
+
3719
+ $remainder = '';
3720
+ if ($num_bytes) {
3721
+ $start = $num_bytes > strlen($x) ? -strlen($x) : -$num_bytes;
3722
+ $remainder = substr($x, $start);
3723
+ $x = substr($x, 0, -$num_bytes);
3724
+ }
3725
+
3726
+ $carry = 0;
3727
+ $carry_shift = 8 - $shift;
3728
+ for ($i = 0; $i < strlen($x); ++$i) {
3729
+ $temp = (ord($x[$i]) >> $shift) | $carry;
3730
+ $carry = (ord($x[$i]) << $carry_shift) & 0xFF;
3731
+ $x[$i] = chr($temp);
3732
+ }
3733
+ $x = ltrim($x, chr(0));
3734
+
3735
+ $remainder = chr($carry >> $carry_shift) . $remainder;
3736
+
3737
+ return ltrim($remainder, chr(0));
3738
+ }
3739
+
3740
+ // one quirk about how the following functions are implemented is that PHP defines N to be an unsigned long
3741
+ // at 32-bits, while java's longs are 64-bits.
3742
+
3743
+ /**
3744
+ * Converts 32-bit integers to bytes.
3745
+ *
3746
+ * @param int $x
3747
+ * @return string
3748
+ * @access private
3749
+ */
3750
+ function _int2bytes($x)
3751
+ {
3752
+ return ltrim(pack('N', $x), chr(0));
3753
+ }
3754
+
3755
+ /**
3756
+ * Converts bytes to 32-bit integers
3757
+ *
3758
+ * @param string $x
3759
+ * @return int
3760
+ * @access private
3761
+ */
3762
+ function _bytes2int($x)
3763
+ {
3764
+ $temp = unpack('Nint', str_pad($x, 4, chr(0), STR_PAD_LEFT));
3765
+ return $temp['int'];
3766
+ }
3767
+
3768
+ /**
3769
+ * DER-encode an integer
3770
+ *
3771
+ * The ability to DER-encode integers is needed to create RSA public keys for use with OpenSSL
3772
+ *
3773
+ * @see self::modPow()
3774
+ * @access private
3775
+ * @param int $length
3776
+ * @return string
3777
+ */
3778
+ function _encodeASN1Length($length)
3779
+ {
3780
+ if ($length <= 0x7F) {
3781
+ return chr($length);
3782
+ }
3783
+
3784
+ $temp = ltrim(pack('N', $length), chr(0));
3785
+ return pack('Ca*', 0x80 | strlen($temp), $temp);
3786
+ }
3787
+
3788
+ /**
3789
+ * Single digit division
3790
+ *
3791
+ * Even if int64 is being used the division operator will return a float64 value
3792
+ * if the dividend is not evenly divisible by the divisor. Since a float64 doesn't
3793
+ * have the precision of int64 this is a problem so, when int64 is being used,
3794
+ * we'll guarantee that the dividend is divisible by first subtracting the remainder.
3795
+ *
3796
+ * @access private
3797
+ * @param int $x
3798
+ * @param int $y
3799
+ * @return int
3800
+ */
3801
+ function _safe_divide($x, $y)
3802
+ {
3803
+ if (MATH_BIGINTEGER_BASE === 26) {
3804
+ return (int) ($x / $y);
3805
+ }
3806
+
3807
+ // MATH_BIGINTEGER_BASE === 31
3808
+ return ($x - ($x % $y)) / $y;
3809
+ }
3810
+ }
3811
+ }
lib/vendor/servmask/archiver/class-ai1wm-archiver.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -43,6 +43,14 @@ abstract class Ai1wm_Archiver {
43
  'a4096' // path
44
  );
45
 
 
 
 
 
 
 
 
 
46
  /**
47
  * Filename including path to the file
48
  *
@@ -50,6 +58,14 @@ abstract class Ai1wm_Archiver {
50
  */
51
  protected $filename = null;
52
 
 
 
 
 
 
 
 
 
53
  /**
54
  * Handle to the file
55
  *
@@ -57,6 +73,14 @@ abstract class Ai1wm_Archiver {
57
  */
58
  protected $file_handle = null;
59
 
 
 
 
 
 
 
 
 
60
  /**
61
  * Current file size
62
  *
@@ -64,6 +88,14 @@ abstract class Ai1wm_Archiver {
64
  */
65
  protected $current_filesize = null;
66
 
 
 
 
 
 
 
 
 
67
  /**
68
  * End Of File block string
69
  *
@@ -71,6 +103,14 @@ abstract class Ai1wm_Archiver {
71
  */
72
  protected $eof = null;
73
 
 
 
 
 
 
 
 
 
74
  /**
75
  * Default constructor
76
  *
@@ -196,15 +236,6 @@ abstract class Ai1wm_Archiver {
196
  return false;
197
  }
198
 
199
- /**
200
- * Get current file size
201
- *
202
- * return int
203
- */
204
- public function get_current_filesize() {
205
- return $this->current_filesize;
206
- }
207
-
208
  /**
209
  * Closes the archive file
210
  *
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
43
  'a4096' // path
44
  );
45
 
46
+ public function get_block_format() {
47
+ return $this->block_format;
48
+ }
49
+
50
+ public function set_block_format( $block_format ) {
51
+ $this->block_format = $block_format;
52
+ }
53
+
54
  /**
55
  * Filename including path to the file
56
  *
58
  */
59
  protected $filename = null;
60
 
61
+ public function get_filename() {
62
+ return $this->filename;
63
+ }
64
+
65
+ public function set_filename( $filename ) {
66
+ $this->filename = $filename;
67
+ }
68
+
69
  /**
70
  * Handle to the file
71
  *
73
  */
74
  protected $file_handle = null;
75
 
76
+ public function get_file_handle() {
77
+ return $this->file_handle;
78
+ }
79
+
80
+ public function set_file_handle( $file_handle ) {
81
+ $this->file_handle = $file_handle;
82
+ }
83
+
84
  /**
85
  * Current file size
86
  *
88
  */
89
  protected $current_filesize = null;
90
 
91
+ public function get_current_filesize() {
92
+ return $this->current_filesize;
93
+ }
94
+
95
+ public function set_current_filesize( $current_filesize ) {
96
+ $this->current_filesize = $current_filesize;
97
+ }
98
+
99
  /**
100
  * End Of File block string
101
  *
103
  */
104
  protected $eof = null;
105
 
106
+ public function get_eof() {
107
+ return $this->eof;
108
+ }
109
+
110
+ public function set_eof( $eof ) {
111
+ $this->eof = $eof;
112
+ }
113
+
114
  /**
115
  * Default constructor
116
  *
236
  return false;
237
  }
238
 
 
 
 
 
 
 
 
 
 
239
  /**
240
  * Closes the archive file
241
  *
lib/vendor/servmask/archiver/class-ai1wm-compressor.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/archiver/class-ai1wm-extractor.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -35,16 +35,6 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
35
  parent::__construct( $file );
36
  }
37
 
38
- /**
39
- * Extract files from archive to specified location
40
- *
41
- * @param string $location Location where the files should be extracted
42
- * @param int $seek Location in the file to start exporting data from
43
- */
44
- public function extract_files( $location, $seek = 0 ) {
45
-
46
- }
47
-
48
  /**
49
  * Get the total files in an archive
50
  *
@@ -337,7 +327,7 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
337
  // all files should chmoded to 644
338
  $this->set_file_mode( $file, $this->get_permissions_for_file() );
339
 
340
- return $offset;
341
  }
342
 
343
  private function set_mtime_of_file( $file, $mtime ) {
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
35
  parent::__construct( $file );
36
  }
37
 
 
 
 
 
 
 
 
 
 
 
38
  /**
39
  * Get the total files in an archive
40
  *
327
  // all files should chmoded to 644
328
  $this->set_file_mode( $file, $this->get_permissions_for_file() );
329
 
330
+ return 0;
331
  }
332
 
333
  private function set_mtime_of_file( $file, $mtime ) {
lib/vendor/servmask/cron/class-ai1wm-cron.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/database/class-ai1wm-database-mysql.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/database/class-ai1wm-database-mysqli.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/database/class-ai1wm-database-utility.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/database/class-ai1wm-database.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/filesystem/class-ai1wm-file-htaccess.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/filesystem/class-ai1wm-file-index.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/filesystem/class-ai1wm-file-webconfig.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/filesystem/class-ai1wm-file.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/filter/class-ai1wm-extension-filter.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/filter/class-ai1wm-recursive-exclude-filter.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/vendor/servmask/iterator/class-ai1wm-recursive-directory-iterator.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/view/assets/javascript/backups.min.js CHANGED
@@ -47,7 +47,7 @@
47
  'use strict';
48
 
49
  /**
50
- * Copyright (C) 2014-2016 ServMask Inc.
51
  *
52
  * This program is free software: you can redistribute it and/or modify
53
  * it under the terms of the GNU General Public License as published by
@@ -135,7 +135,7 @@
135
  'use strict';
136
 
137
  /**
138
- * Copyright (C) 2014-2016 ServMask Inc.
139
  *
140
  * This program is free software: you can redistribute it and/or modify
141
  * it under the terms of the GNU General Public License as published by
@@ -181,7 +181,7 @@
181
  $.ajax({
182
  type: 'POST',
183
  url: ai1wm_report.ajax.url,
184
- data: { 'ai1wm-email': email, 'ai1wm-message': message, 'ai1wm-terms': +terms },
185
  success: function success(data) {
186
  var errors = data.errors;
187
  if (errors.length > 0) {
@@ -217,7 +217,7 @@
217
  'use strict';
218
 
219
  /**
220
- * Copyright (C) 2014-2016 ServMask Inc.
221
  *
222
  * This program is free software: you can redistribute it and/or modify
223
  * it under the terms of the GNU General Public License as published by
@@ -300,7 +300,7 @@
300
  $.ajax({
301
  type: 'POST',
302
  url: ai1wm_feedback.ajax.url,
303
- data: { 'ai1wm-type': type, 'ai1wm-email': email, 'ai1wm-message': message, 'ai1wm-terms': +terms },
304
  success: function success(data) {
305
  var errors = data.errors;
306
  if (errors.length > 0) {
@@ -331,7 +331,7 @@
331
  'use strict';
332
 
333
  /**
334
- * Copyright (C) 2014-2016 ServMask Inc.
335
  *
336
  * This program is free software: you can redistribute it and/or modify
337
  * it under the terms of the GNU General Public License as published by
@@ -401,7 +401,7 @@
401
  'use strict';
402
 
403
  /**
404
- * Copyright (C) 2014-2016 ServMask Inc.
405
  *
406
  * This program is free software: you can redistribute it and/or modify
407
  * it under the terms of the GNU General Public License as published by
@@ -716,7 +716,7 @@
716
  'use strict';
717
 
718
  /**
719
- * Copyright (C) 2014-2016 ServMask Inc.
720
  *
721
  * This program is free software: you can redistribute it and/or modify
722
  * it under the terms of the GNU General Public License as published by
47
  'use strict';
48
 
49
  /**
50
+ * Copyright (C) 2014-2017 ServMask Inc.
51
  *
52
  * This program is free software: you can redistribute it and/or modify
53
  * it under the terms of the GNU General Public License as published by
135
  'use strict';
136
 
137
  /**
138
+ * Copyright (C) 2014-2017 ServMask Inc.
139
  *
140
  * This program is free software: you can redistribute it and/or modify
141
  * it under the terms of the GNU General Public License as published by
181
  $.ajax({
182
  type: 'POST',
183
  url: ai1wm_report.ajax.url,
184
+ data: { 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
185
  success: function success(data) {
186
  var errors = data.errors;
187
  if (errors.length > 0) {
217
  'use strict';
218
 
219
  /**
220
+ * Copyright (C) 2014-2017 ServMask Inc.
221
  *
222
  * This program is free software: you can redistribute it and/or modify
223
  * it under the terms of the GNU General Public License as published by
300
  $.ajax({
301
  type: 'POST',
302
  url: ai1wm_feedback.ajax.url,
303
+ data: { 'ai1wm_type': type, 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
304
  success: function success(data) {
305
  var errors = data.errors;
306
  if (errors.length > 0) {
331
  'use strict';
332
 
333
  /**
334
+ * Copyright (C) 2014-2017 ServMask Inc.
335
  *
336
  * This program is free software: you can redistribute it and/or modify
337
  * it under the terms of the GNU General Public License as published by
401
  'use strict';
402
 
403
  /**
404
+ * Copyright (C) 2014-2017 ServMask Inc.
405
  *
406
  * This program is free software: you can redistribute it and/or modify
407
  * it under the terms of the GNU General Public License as published by
716
  'use strict';
717
 
718
  /**
719
+ * Copyright (C) 2014-2017 ServMask Inc.
720
  *
721
  * This program is free software: you can redistribute it and/or modify
722
  * it under the terms of the GNU General Public License as published by
lib/view/assets/javascript/export.min.js CHANGED
@@ -47,7 +47,7 @@
47
  /* WEBPACK VAR INJECTION */(function(global) {'use strict';
48
 
49
  /**
50
- * Copyright (C) 2014-2016 ServMask Inc.
51
  *
52
  * This program is free software: you can redistribute it and/or modify
53
  * it under the terms of the GNU General Public License as published by
@@ -120,7 +120,7 @@
120
  'use strict';
121
 
122
  /**
123
- * Copyright (C) 2014-2016 ServMask Inc.
124
  *
125
  * This program is free software: you can redistribute it and/or modify
126
  * it under the terms of the GNU General Public License as published by
@@ -166,7 +166,7 @@
166
  $.ajax({
167
  type: 'POST',
168
  url: ai1wm_report.ajax.url,
169
- data: { 'ai1wm-email': email, 'ai1wm-message': message, 'ai1wm-terms': +terms },
170
  success: function success(data) {
171
  var errors = data.errors;
172
  if (errors.length > 0) {
@@ -202,7 +202,7 @@
202
  'use strict';
203
 
204
  /**
205
- * Copyright (C) 2014-2016 ServMask Inc.
206
  *
207
  * This program is free software: you can redistribute it and/or modify
208
  * it under the terms of the GNU General Public License as published by
@@ -285,7 +285,7 @@
285
  $.ajax({
286
  type: 'POST',
287
  url: ai1wm_feedback.ajax.url,
288
- data: { 'ai1wm-type': type, 'ai1wm-email': email, 'ai1wm-message': message, 'ai1wm-terms': +terms },
289
  success: function success(data) {
290
  var errors = data.errors;
291
  if (errors.length > 0) {
@@ -316,7 +316,7 @@
316
  'use strict';
317
 
318
  /**
319
- * Copyright (C) 2014-2016 ServMask Inc.
320
  *
321
  * This program is free software: you can redistribute it and/or modify
322
  * it under the terms of the GNU General Public License as published by
@@ -388,7 +388,7 @@
388
  'use strict';
389
 
390
  /**
391
- * Copyright (C) 2014-2016 ServMask Inc.
392
  *
393
  * This program is free software: you can redistribute it and/or modify
394
  * it under the terms of the GNU General Public License as published by
@@ -439,7 +439,7 @@
439
  'use strict';
440
 
441
  /**
442
- * Copyright (C) 2014-2016 ServMask Inc.
443
  *
444
  * This program is free software: you can redistribute it and/or modify
445
  * it under the terms of the GNU General Public License as published by
@@ -502,7 +502,7 @@
502
  'use strict';
503
 
504
  /**
505
- * Copyright (C) 2014-2016 ServMask Inc.
506
  *
507
  * This program is free software: you can redistribute it and/or modify
508
  * it under the terms of the GNU General Public License as published by
@@ -596,7 +596,7 @@
596
  'use strict';
597
 
598
  /**
599
- * Copyright (C) 2014-2016 ServMask Inc.
600
  *
601
  * This program is free software: you can redistribute it and/or modify
602
  * it under the terms of the GNU General Public License as published by
@@ -673,7 +673,7 @@
673
  'use strict';
674
 
675
  /**
676
- * Copyright (C) 2014-2016 ServMask Inc.
677
  *
678
  * This program is free software: you can redistribute it and/or modify
679
  * it under the terms of the GNU General Public License as published by
@@ -895,7 +895,7 @@
895
  'use strict';
896
 
897
  /**
898
- * Copyright (C) 2014-2016 ServMask Inc.
899
  *
900
  * This program is free software: you can redistribute it and/or modify
901
  * it under the terms of the GNU General Public License as published by
47
  /* WEBPACK VAR INJECTION */(function(global) {'use strict';
48
 
49
  /**
50
+ * Copyright (C) 2014-2017 ServMask Inc.
51
  *
52
  * This program is free software: you can redistribute it and/or modify
53
  * it under the terms of the GNU General Public License as published by
120
  'use strict';
121
 
122
  /**
123
+ * Copyright (C) 2014-2017 ServMask Inc.
124
  *
125
  * This program is free software: you can redistribute it and/or modify
126
  * it under the terms of the GNU General Public License as published by
166
  $.ajax({
167
  type: 'POST',
168
  url: ai1wm_report.ajax.url,
169
+ data: { 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
170
  success: function success(data) {
171
  var errors = data.errors;
172
  if (errors.length > 0) {
202
  'use strict';
203
 
204
  /**
205
+ * Copyright (C) 2014-2017 ServMask Inc.
206
  *
207
  * This program is free software: you can redistribute it and/or modify
208
  * it under the terms of the GNU General Public License as published by
285
  $.ajax({
286
  type: 'POST',
287
  url: ai1wm_feedback.ajax.url,
288
+ data: { 'ai1wm_type': type, 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
289
  success: function success(data) {
290
  var errors = data.errors;
291
  if (errors.length > 0) {
316
  'use strict';
317
 
318
  /**
319
+ * Copyright (C) 2014-2017 ServMask Inc.
320
  *
321
  * This program is free software: you can redistribute it and/or modify
322
  * it under the terms of the GNU General Public License as published by
388
  'use strict';
389
 
390
  /**
391
+ * Copyright (C) 2014-2017 ServMask Inc.
392
  *
393
  * This program is free software: you can redistribute it and/or modify
394
  * it under the terms of the GNU General Public License as published by
439
  'use strict';
440
 
441
  /**
442
+ * Copyright (C) 2014-2017 ServMask Inc.
443
  *
444
  * This program is free software: you can redistribute it and/or modify
445
  * it under the terms of the GNU General Public License as published by
502
  'use strict';
503
 
504
  /**
505
+ * Copyright (C) 2014-2017 ServMask Inc.
506
  *
507
  * This program is free software: you can redistribute it and/or modify
508
  * it under the terms of the GNU General Public License as published by
596
  'use strict';
597
 
598
  /**
599
+ * Copyright (C) 2014-2017 ServMask Inc.
600
  *
601
  * This program is free software: you can redistribute it and/or modify
602
  * it under the terms of the GNU General Public License as published by
673
  'use strict';
674
 
675
  /**
676
+ * Copyright (C) 2014-2017 ServMask Inc.
677
  *
678
  * This program is free software: you can redistribute it and/or modify
679
  * it under the terms of the GNU General Public License as published by
895
  'use strict';
896
 
897
  /**
898
+ * Copyright (C) 2014-2017 ServMask Inc.
899
  *
900
  * This program is free software: you can redistribute it and/or modify
901
  * it under the terms of the GNU General Public License as published by
lib/view/assets/javascript/import.min.js CHANGED
@@ -47,7 +47,7 @@
47
  'use strict';
48
 
49
  /**
50
- * Copyright (C) 2014-2016 ServMask Inc.
51
  *
52
  * This program is free software: you can redistribute it and/or modify
53
  * it under the terms of the GNU General Public License as published by
@@ -94,7 +94,7 @@
94
  'use strict';
95
 
96
  /**
97
- * Copyright (C) 2014-2016 ServMask Inc.
98
  *
99
  * This program is free software: you can redistribute it and/or modify
100
  * it under the terms of the GNU General Public License as published by
@@ -140,7 +140,7 @@
140
  $.ajax({
141
  type: 'POST',
142
  url: ai1wm_report.ajax.url,
143
- data: { 'ai1wm-email': email, 'ai1wm-message': message, 'ai1wm-terms': +terms },
144
  success: function success(data) {
145
  var errors = data.errors;
146
  if (errors.length > 0) {
@@ -176,7 +176,7 @@
176
  'use strict';
177
 
178
  /**
179
- * Copyright (C) 2014-2016 ServMask Inc.
180
  *
181
  * This program is free software: you can redistribute it and/or modify
182
  * it under the terms of the GNU General Public License as published by
@@ -259,7 +259,7 @@
259
  $.ajax({
260
  type: 'POST',
261
  url: ai1wm_feedback.ajax.url,
262
- data: { 'ai1wm-type': type, 'ai1wm-email': email, 'ai1wm-message': message, 'ai1wm-terms': +terms },
263
  success: function success(data) {
264
  var errors = data.errors;
265
  if (errors.length > 0) {
@@ -290,7 +290,7 @@
290
  'use strict';
291
 
292
  /**
293
- * Copyright (C) 2014-2016 ServMask Inc.
294
  *
295
  * This program is free software: you can redistribute it and/or modify
296
  * it under the terms of the GNU General Public License as published by
@@ -360,7 +360,7 @@
360
  'use strict';
361
 
362
  /**
363
- * Copyright (C) 2014-2016 ServMask Inc.
364
  *
365
  * This program is free software: you can redistribute it and/or modify
366
  * it under the terms of the GNU General Public License as published by
@@ -675,7 +675,7 @@
675
  'use strict';
676
 
677
  /**
678
- * Copyright (C) 2014-2016 ServMask Inc.
679
  *
680
  * This program is free software: you can redistribute it and/or modify
681
  * it under the terms of the GNU General Public License as published by
@@ -1039,7 +1039,7 @@
1039
  'use strict';
1040
 
1041
  /**
1042
- * Copyright (C) 2014-2016 ServMask Inc.
1043
  *
1044
  * This program is free software: you can redistribute it and/or modify
1045
  * it under the terms of the GNU General Public License as published by
@@ -1133,7 +1133,7 @@
1133
  'use strict';
1134
 
1135
  /**
1136
- * Copyright (C) 2014-2016 ServMask Inc.
1137
  *
1138
  * This program is free software: you can redistribute it and/or modify
1139
  * it under the terms of the GNU General Public License as published by
@@ -1212,7 +1212,7 @@
1212
  /* WEBPACK VAR INJECTION */(function(fetch, global) {'use strict';
1213
 
1214
  /**
1215
- * Copyright (C) 2014-2016 ServMask Inc.
1216
  *
1217
  * This program is free software: you can redistribute it and/or modify
1218
  * it under the terms of the GNU General Public License as published by
@@ -1452,6 +1452,28 @@
1452
  arrayBuffer: 'ArrayBuffer' in self
1453
  }
1454
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1455
  function normalizeName(name) {
1456
  if (typeof name !== 'string') {
1457
  name = String(name)
@@ -1584,14 +1606,36 @@
1584
 
1585
  function readBlobAsArrayBuffer(blob) {
1586
  var reader = new FileReader()
 
1587
  reader.readAsArrayBuffer(blob)
1588
- return fileReaderReady(reader)
1589
  }
1590
 
1591
  function readBlobAsText(blob) {
1592
  var reader = new FileReader()
 
1593
  reader.readAsText(blob)
1594
- return fileReaderReady(reader)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1595
  }
1596
 
1597
  function Body() {
@@ -1599,7 +1643,9 @@
1599
 
1600
  this._initBody = function(body) {
1601
  this._bodyInit = body
1602
- if (typeof body === 'string') {
 
 
1603
  this._bodyText = body
1604
  } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
1605
  this._bodyBlob = body
@@ -1607,11 +1653,12 @@
1607
  this._bodyFormData = body
1608
  } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
1609
  this._bodyText = body.toString()
1610
- } else if (!body) {
1611
- this._bodyText = ''
1612
- } else if (support.arrayBuffer && ArrayBuffer.prototype.isPrototypeOf(body)) {
1613
- // Only support ArrayBuffers for POST method.
1614
- // Receiving ArrayBuffers happens via Blobs, instead.
 
1615
  } else {
1616
  throw new Error('unsupported BodyInit type')
1617
  }
@@ -1636,6 +1683,8 @@
1636
 
1637
  if (this._bodyBlob) {
1638
  return Promise.resolve(this._bodyBlob)
 
 
1639
  } else if (this._bodyFormData) {
1640
  throw new Error('could not read FormData body as blob')
1641
  } else {
@@ -1644,27 +1693,28 @@
1644
  }
1645
 
1646
  this.arrayBuffer = function() {
1647
- return this.blob().then(readBlobAsArrayBuffer)
1648
- }
1649
-
1650
- this.text = function() {
1651
- var rejected = consumed(this)
1652
- if (rejected) {
1653
- return rejected
1654
- }
1655
-
1656
- if (this._bodyBlob) {
1657
- return readBlobAsText(this._bodyBlob)
1658
- } else if (this._bodyFormData) {
1659
- throw new Error('could not read FormData body as text')
1660
  } else {
1661
- return Promise.resolve(this._bodyText)
1662
  }
1663
  }
1664
- } else {
1665
- this.text = function() {
1666
- var rejected = consumed(this)
1667
- return rejected ? rejected : Promise.resolve(this._bodyText)
 
 
 
 
 
 
 
 
 
 
 
 
1668
  }
1669
  }
1670
 
@@ -1692,7 +1742,10 @@
1692
  function Request(input, options) {
1693
  options = options || {}
1694
  var body = options.body
1695
- if (Request.prototype.isPrototypeOf(input)) {
 
 
 
1696
  if (input.bodyUsed) {
1697
  throw new TypeError('Already read')
1698
  }
@@ -1703,12 +1756,10 @@
1703
  }
1704
  this.method = input.method
1705
  this.mode = input.mode
1706
- if (!body) {
1707
  body = input._bodyInit
1708
  input.bodyUsed = true
1709
  }
1710
- } else {
1711
- this.url = input
1712
  }
1713
 
1714
  this.credentials = options.credentials || this.credentials || 'omit'
@@ -1726,7 +1777,7 @@
1726
  }
1727
 
1728
  Request.prototype.clone = function() {
1729
- return new Request(this)
1730
  }
1731
 
1732
  function decode(body) {
@@ -1742,16 +1793,17 @@
1742
  return form
1743
  }
1744
 
1745
- function headers(xhr) {
1746
- var head = new Headers()
1747
- var pairs = (xhr.getAllResponseHeaders() || '').trim().split('\n')
1748
- pairs.forEach(function(header) {
1749
- var split = header.trim().split(':')
1750
- var key = split.shift().trim()
1751
- var value = split.join(':').trim()
1752
- head.append(key, value)
 
1753
  })
1754
- return head
1755
  }
1756
 
1757
  Body.call(Request.prototype)
@@ -1762,10 +1814,10 @@
1762
  }
1763
 
1764
  this.type = 'default'
1765
- this.status = options.status
1766
  this.ok = this.status >= 200 && this.status < 300
1767
- this.statusText = options.statusText
1768
- this.headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers)
1769
  this.url = options.url || ''
1770
  this._initBody(bodyInit)
1771
  }
@@ -1803,35 +1855,16 @@
1803
 
1804
  self.fetch = function(input, init) {
1805
  return new Promise(function(resolve, reject) {
1806
- var request
1807
- if (Request.prototype.isPrototypeOf(input) && !init) {
1808
- request = input
1809
- } else {
1810
- request = new Request(input, init)
1811
- }
1812
-
1813
  var xhr = new XMLHttpRequest()
1814
 
1815
- function responseURL() {
1816
- if ('responseURL' in xhr) {
1817
- return xhr.responseURL
1818
- }
1819
-
1820
- // Avoid security warnings on getResponseHeader when not allowed by CORS
1821
- if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
1822
- return xhr.getResponseHeader('X-Request-URL')
1823
- }
1824
-
1825
- return
1826
- }
1827
-
1828
  xhr.onload = function() {
1829
  var options = {
1830
  status: xhr.status,
1831
  statusText: xhr.statusText,
1832
- headers: headers(xhr),
1833
- url: responseURL()
1834
  }
 
1835
  var body = 'response' in xhr ? xhr.response : xhr.responseText
1836
  resolve(new Response(body, options))
1837
  }
@@ -1874,987 +1907,1262 @@
1874
  /* 14 */
1875
  /***/ function(module, exports, __webpack_require__) {
1876
 
1877
- var require;var __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(process, global, module) {/*** IMPORTS FROM imports-loader ***/
1878
  (function() {
1879
 
1880
  /*!
1881
  * @overview es6-promise - a tiny implementation of Promises/A+.
1882
  * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
1883
  * @license Licensed under MIT license
1884
- * See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE
1885
- * @version 3.2.1
1886
  */
1887
 
1888
- (function() {
1889
- "use strict";
1890
- function lib$es6$promise$utils$$objectOrFunction(x) {
1891
- return typeof x === 'function' || (typeof x === 'object' && x !== null);
1892
- }
1893
 
1894
- function lib$es6$promise$utils$$isFunction(x) {
1895
- return typeof x === 'function';
1896
- }
1897
 
1898
- function lib$es6$promise$utils$$isMaybeThenable(x) {
1899
- return typeof x === 'object' && x !== null;
1900
- }
1901
 
1902
- var lib$es6$promise$utils$$_isArray;
1903
- if (!Array.isArray) {
1904
- lib$es6$promise$utils$$_isArray = function (x) {
1905
- return Object.prototype.toString.call(x) === '[object Array]';
1906
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1907
  } else {
1908
- lib$es6$promise$utils$$_isArray = Array.isArray;
1909
  }
 
 
1910
 
1911
- var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray;
1912
- var lib$es6$promise$asap$$len = 0;
1913
- var lib$es6$promise$asap$$vertxNext;
1914
- var lib$es6$promise$asap$$customSchedulerFn;
1915
-
1916
- var lib$es6$promise$asap$$asap = function asap(callback, arg) {
1917
- lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback;
1918
- lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg;
1919
- lib$es6$promise$asap$$len += 2;
1920
- if (lib$es6$promise$asap$$len === 2) {
1921
- // If len is 2, that means that we need to schedule an async flush.
1922
- // If additional callbacks are queued before the queue is flushed, they
1923
- // will be processed by this flush that we are scheduling.
1924
- if (lib$es6$promise$asap$$customSchedulerFn) {
1925
- lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush);
1926
- } else {
1927
- lib$es6$promise$asap$$scheduleFlush();
1928
- }
1929
- }
1930
- }
1931
 
1932
- function lib$es6$promise$asap$$setScheduler(scheduleFn) {
1933
- lib$es6$promise$asap$$customSchedulerFn = scheduleFn;
1934
- }
1935
 
1936
- function lib$es6$promise$asap$$setAsap(asapFn) {
1937
- lib$es6$promise$asap$$asap = asapFn;
1938
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
1939
 
1940
- var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined;
1941
- var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {};
1942
- var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver;
1943
- var lib$es6$promise$asap$$isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
1944
-
1945
- // test for web worker but not in IE10
1946
- var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
1947
- typeof importScripts !== 'undefined' &&
1948
- typeof MessageChannel !== 'undefined';
1949
-
1950
- // node
1951
- function lib$es6$promise$asap$$useNextTick() {
1952
- // node version 0.10.x displays a deprecation warning when nextTick is used recursively
1953
- // see https://github.com/cujojs/when/issues/410 for details
1954
- return function() {
1955
- process.nextTick(lib$es6$promise$asap$$flush);
1956
- };
1957
- }
1958
 
1959
- // vertx
1960
- function lib$es6$promise$asap$$useVertxTimer() {
1961
- return function() {
1962
- lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush);
1963
- };
1964
- }
1965
 
1966
- function lib$es6$promise$asap$$useMutationObserver() {
1967
- var iterations = 0;
1968
- var observer = new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush);
1969
- var node = document.createTextNode('');
1970
- observer.observe(node, { characterData: true });
1971
 
1972
- return function() {
1973
- node.data = (iterations = ++iterations % 2);
1974
- };
1975
- }
 
 
 
 
1976
 
1977
- // web worker
1978
- function lib$es6$promise$asap$$useMessageChannel() {
1979
- var channel = new MessageChannel();
1980
- channel.port1.onmessage = lib$es6$promise$asap$$flush;
1981
- return function () {
1982
- channel.port2.postMessage(0);
1983
- };
1984
- }
1985
 
1986
- function lib$es6$promise$asap$$useSetTimeout() {
1987
- return function() {
1988
- setTimeout(lib$es6$promise$asap$$flush, 1);
1989
- };
1990
- }
1991
 
1992
- var lib$es6$promise$asap$$queue = new Array(1000);
1993
- function lib$es6$promise$asap$$flush() {
1994
- for (var i = 0; i < lib$es6$promise$asap$$len; i+=2) {
1995
- var callback = lib$es6$promise$asap$$queue[i];
1996
- var arg = lib$es6$promise$asap$$queue[i+1];
1997
 
1998
- callback(arg);
 
 
1999
 
2000
- lib$es6$promise$asap$$queue[i] = undefined;
2001
- lib$es6$promise$asap$$queue[i+1] = undefined;
2002
- }
2003
 
2004
- lib$es6$promise$asap$$len = 0;
2005
- }
 
 
 
 
 
 
 
 
2006
 
2007
- function lib$es6$promise$asap$$attemptVertx() {
2008
- try {
2009
- var r = require;
2010
- var vertx = __webpack_require__(17);
2011
- lib$es6$promise$asap$$vertxNext = vertx.runOnLoop || vertx.runOnContext;
2012
- return lib$es6$promise$asap$$useVertxTimer();
2013
- } catch(e) {
2014
- return lib$es6$promise$asap$$useSetTimeout();
2015
- }
2016
- }
 
 
 
2017
 
2018
- var lib$es6$promise$asap$$scheduleFlush;
2019
- // Decide what async method to use to triggering processing of queued callbacks:
2020
- if (lib$es6$promise$asap$$isNode) {
2021
- lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick();
2022
- } else if (lib$es6$promise$asap$$BrowserMutationObserver) {
2023
- lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMutationObserver();
2024
- } else if (lib$es6$promise$asap$$isWorker) {
2025
- lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel();
2026
- } else if (lib$es6$promise$asap$$browserWindow === undefined && "function" === 'function') {
2027
- lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertx();
2028
- } else {
2029
- lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout();
2030
- }
2031
- function lib$es6$promise$then$$then(onFulfillment, onRejection) {
2032
- var parent = this;
2033
 
2034
- var child = new this.constructor(lib$es6$promise$$internal$$noop);
2035
 
2036
- if (child[lib$es6$promise$$internal$$PROMISE_ID] === undefined) {
2037
- lib$es6$promise$$internal$$makePromise(child);
2038
- }
2039
 
2040
- var state = parent._state;
 
 
2041
 
2042
- if (state) {
2043
- var callback = arguments[state - 1];
2044
- lib$es6$promise$asap$$asap(function(){
2045
- lib$es6$promise$$internal$$invokeCallback(state, child, callback, parent._result);
2046
- });
2047
- } else {
2048
- lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection);
2049
- }
2050
 
2051
- return child;
2052
- }
2053
- var lib$es6$promise$then$$default = lib$es6$promise$then$$then;
2054
- function lib$es6$promise$promise$resolve$$resolve(object) {
2055
- /*jshint validthis:true */
2056
- var Constructor = this;
 
 
 
 
2057
 
2058
- if (object && typeof object === 'object' && object.constructor === Constructor) {
2059
- return object;
2060
- }
2061
 
2062
- var promise = new Constructor(lib$es6$promise$$internal$$noop);
2063
- lib$es6$promise$$internal$$resolve(promise, object);
2064
- return promise;
2065
- }
2066
- var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve;
2067
- var lib$es6$promise$$internal$$PROMISE_ID = Math.random().toString(36).substring(16);
2068
 
2069
- function lib$es6$promise$$internal$$noop() {}
 
 
 
2070
 
2071
- var lib$es6$promise$$internal$$PENDING = void 0;
2072
- var lib$es6$promise$$internal$$FULFILLED = 1;
2073
- var lib$es6$promise$$internal$$REJECTED = 2;
 
2074
 
2075
- var lib$es6$promise$$internal$$GET_THEN_ERROR = new lib$es6$promise$$internal$$ErrorObject();
2076
 
2077
- function lib$es6$promise$$internal$$selfFulfillment() {
2078
- return new TypeError("You cannot resolve a promise with itself");
2079
- }
2080
 
2081
- function lib$es6$promise$$internal$$cannotReturnOwn() {
2082
- return new TypeError('A promises callback cannot return that same promise.');
2083
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2084
 
2085
- function lib$es6$promise$$internal$$getThen(promise) {
2086
- try {
2087
- return promise.then;
2088
- } catch(error) {
2089
- lib$es6$promise$$internal$$GET_THEN_ERROR.error = error;
2090
- return lib$es6$promise$$internal$$GET_THEN_ERROR;
2091
- }
2092
- }
2093
 
2094
- function lib$es6$promise$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) {
2095
- try {
2096
- then.call(value, fulfillmentHandler, rejectionHandler);
2097
- } catch(e) {
2098
- return e;
2099
- }
2100
- }
2101
 
2102
- function lib$es6$promise$$internal$$handleForeignThenable(promise, thenable, then) {
2103
- lib$es6$promise$asap$$asap(function(promise) {
2104
- var sealed = false;
2105
- var error = lib$es6$promise$$internal$$tryThen(then, thenable, function(value) {
2106
- if (sealed) { return; }
2107
- sealed = true;
2108
- if (thenable !== value) {
2109
- lib$es6$promise$$internal$$resolve(promise, value);
2110
- } else {
2111
- lib$es6$promise$$internal$$fulfill(promise, value);
2112
- }
2113
- }, function(reason) {
2114
- if (sealed) { return; }
2115
- sealed = true;
2116
 
2117
- lib$es6$promise$$internal$$reject(promise, reason);
2118
- }, 'Settle: ' + (promise._label || ' unknown promise'));
 
2119
 
2120
- if (!sealed && error) {
2121
- sealed = true;
2122
- lib$es6$promise$$internal$$reject(promise, error);
2123
- }
2124
- }, promise);
2125
- }
2126
 
2127
- function lib$es6$promise$$internal$$handleOwnThenable(promise, thenable) {
2128
- if (thenable._state === lib$es6$promise$$internal$$FULFILLED) {
2129
- lib$es6$promise$$internal$$fulfill(promise, thenable._result);
2130
- } else if (thenable._state === lib$es6$promise$$internal$$REJECTED) {
2131
- lib$es6$promise$$internal$$reject(promise, thenable._result);
2132
- } else {
2133
- lib$es6$promise$$internal$$subscribe(thenable, undefined, function(value) {
2134
- lib$es6$promise$$internal$$resolve(promise, value);
2135
- }, function(reason) {
2136
- lib$es6$promise$$internal$$reject(promise, reason);
2137
- });
2138
- }
2139
- }
2140
 
2141
- function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable, then) {
2142
- if (maybeThenable.constructor === promise.constructor &&
2143
- then === lib$es6$promise$then$$default &&
2144
- constructor.resolve === lib$es6$promise$promise$resolve$$default) {
2145
- lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable);
2146
- } else {
2147
- if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) {
2148
- lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error);
2149
- } else if (then === undefined) {
2150
- lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
2151
- } else if (lib$es6$promise$utils$$isFunction(then)) {
2152
- lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then);
2153
- } else {
2154
- lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
2155
- }
2156
- }
2157
- }
 
 
 
2158
 
2159
- function lib$es6$promise$$internal$$resolve(promise, value) {
2160
- if (promise === value) {
2161
- lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFulfillment());
2162
- } else if (lib$es6$promise$utils$$objectOrFunction(value)) {
2163
- lib$es6$promise$$internal$$handleMaybeThenable(promise, value, lib$es6$promise$$internal$$getThen(value));
 
 
 
 
 
2164
  } else {
2165
- lib$es6$promise$$internal$$fulfill(promise, value);
2166
  }
2167
- }
2168
-
2169
- function lib$es6$promise$$internal$$publishRejection(promise) {
2170
- if (promise._onerror) {
2171
- promise._onerror(promise._result);
2172
  }
 
2173
 
2174
- lib$es6$promise$$internal$$publish(promise);
2175
- }
2176
 
2177
- function lib$es6$promise$$internal$$fulfill(promise, value) {
2178
- if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
 
 
 
 
2179
 
2180
- promise._result = value;
2181
- promise._state = lib$es6$promise$$internal$$FULFILLED;
 
 
 
 
 
 
 
 
 
 
 
2182
 
2183
- if (promise._subscribers.length !== 0) {
2184
- lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, promise);
2185
- }
 
 
 
 
 
 
 
 
 
2186
  }
 
 
2187
 
2188
- function lib$es6$promise$$internal$$reject(promise, reason) {
2189
- if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
2190
- promise._state = lib$es6$promise$$internal$$REJECTED;
2191
- promise._result = reason;
 
 
 
 
 
2192
 
2193
- lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publishRejection, promise);
2194
- }
 
 
2195
 
2196
- function lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection) {
2197
- var subscribers = parent._subscribers;
2198
- var length = subscribers.length;
2199
 
2200
- parent._onerror = null;
 
 
 
2201
 
2202
- subscribers[length] = child;
2203
- subscribers[length + lib$es6$promise$$internal$$FULFILLED] = onFulfillment;
2204
- subscribers[length + lib$es6$promise$$internal$$REJECTED] = onRejection;
2205
 
2206
- if (length === 0 && parent._state) {
2207
- lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, parent);
2208
- }
2209
- }
2210
 
2211
- function lib$es6$promise$$internal$$publish(promise) {
2212
- var subscribers = promise._subscribers;
2213
- var settled = promise._state;
 
 
 
2214
 
2215
- if (subscribers.length === 0) { return; }
 
2216
 
2217
- var child, callback, detail = promise._result;
 
 
2218
 
2219
- for (var i = 0; i < subscribers.length; i += 3) {
2220
- child = subscribers[i];
2221
- callback = subscribers[i + settled];
2222
 
2223
- if (child) {
2224
- lib$es6$promise$$internal$$invokeCallback(settled, child, callback, detail);
2225
- } else {
2226
- callback(detail);
2227
- }
2228
- }
2229
 
2230
- promise._subscribers.length = 0;
2231
- }
 
 
2232
 
2233
- function lib$es6$promise$$internal$$ErrorObject() {
2234
- this.error = null;
2235
- }
2236
 
2237
- var lib$es6$promise$$internal$$TRY_CATCH_ERROR = new lib$es6$promise$$internal$$ErrorObject();
 
 
2238
 
2239
- function lib$es6$promise$$internal$$tryCatch(callback, detail) {
2240
- try {
2241
- return callback(detail);
2242
- } catch(e) {
2243
- lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e;
2244
- return lib$es6$promise$$internal$$TRY_CATCH_ERROR;
2245
- }
 
 
 
 
 
2246
  }
 
2247
 
2248
- function lib$es6$promise$$internal$$invokeCallback(settled, promise, callback, detail) {
2249
- var hasCallback = lib$es6$promise$utils$$isFunction(callback),
2250
- value, error, succeeded, failed;
2251
 
2252
- if (hasCallback) {
2253
- value = lib$es6$promise$$internal$$tryCatch(callback, detail);
 
2254
 
2255
- if (value === lib$es6$promise$$internal$$TRY_CATCH_ERROR) {
2256
- failed = true;
2257
- error = value.error;
2258
- value = null;
2259
- } else {
2260
- succeeded = true;
2261
- }
2262
 
2263
- if (promise === value) {
2264
- lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$cannotReturnOwn());
2265
- return;
2266
- }
 
 
 
 
2267
 
2268
- } else {
2269
- value = detail;
2270
- succeeded = true;
2271
- }
 
 
2272
 
2273
- if (promise._state !== lib$es6$promise$$internal$$PENDING) {
2274
- // noop
2275
- } else if (hasCallback && succeeded) {
2276
- lib$es6$promise$$internal$$resolve(promise, value);
2277
- } else if (failed) {
2278
- lib$es6$promise$$internal$$reject(promise, error);
2279
- } else if (settled === lib$es6$promise$$internal$$FULFILLED) {
2280
- lib$es6$promise$$internal$$fulfill(promise, value);
2281
- } else if (settled === lib$es6$promise$$internal$$REJECTED) {
2282
- lib$es6$promise$$internal$$reject(promise, value);
2283
- }
2284
- }
2285
 
2286
- function lib$es6$promise$$internal$$initializePromise(promise, resolver) {
2287
- try {
2288
- resolver(function resolvePromise(value){
2289
- lib$es6$promise$$internal$$resolve(promise, value);
2290
- }, function rejectPromise(reason) {
2291
- lib$es6$promise$$internal$$reject(promise, reason);
2292
- });
2293
- } catch(e) {
2294
- lib$es6$promise$$internal$$reject(promise, e);
2295
- }
2296
  }
2297
 
2298
- var lib$es6$promise$$internal$$id = 0;
2299
- function lib$es6$promise$$internal$$nextId() {
2300
- return lib$es6$promise$$internal$$id++;
2301
  }
 
 
 
 
2302
 
2303
- function lib$es6$promise$$internal$$makePromise(promise) {
2304
- promise[lib$es6$promise$$internal$$PROMISE_ID] = lib$es6$promise$$internal$$id++;
2305
- promise._state = undefined;
2306
- promise._result = undefined;
2307
- promise._subscribers = [];
 
 
 
 
 
2308
  }
 
2309
 
2310
- function lib$es6$promise$promise$all$$all(entries) {
2311
- return new lib$es6$promise$enumerator$$default(this, entries).promise;
2312
- }
2313
- var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all;
2314
- function lib$es6$promise$promise$race$$race(entries) {
2315
- /*jshint validthis:true */
2316
- var Constructor = this;
2317
-
2318
- if (!lib$es6$promise$utils$$isArray(entries)) {
2319
- return new Constructor(function(resolve, reject) {
2320
- reject(new TypeError('You must pass an array to race.'));
2321
- });
2322
- } else {
2323
- return new Constructor(function(resolve, reject) {
2324
- var length = entries.length;
2325
- for (var i = 0; i < length; i++) {
2326
- Constructor.resolve(entries[i]).then(resolve, reject);
2327
- }
2328
- });
2329
- }
2330
- }
2331
- var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race;
2332
- function lib$es6$promise$promise$reject$$reject(reason) {
2333
- /*jshint validthis:true */
2334
- var Constructor = this;
2335
- var promise = new Constructor(lib$es6$promise$$internal$$noop);
2336
- lib$es6$promise$$internal$$reject(promise, reason);
2337
- return promise;
2338
- }
2339
- var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject;
2340
 
 
 
 
 
 
 
2341
 
2342
- function lib$es6$promise$promise$$needsResolver() {
2343
- throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
2344
- }
2345
 
2346
- function lib$es6$promise$promise$$needsNew() {
2347
- throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
2348
- }
 
 
 
 
 
2349
 
2350
- var lib$es6$promise$promise$$default = lib$es6$promise$promise$$Promise;
2351
- /**
2352
- Promise objects represent the eventual result of an asynchronous operation. The
2353
- primary way of interacting with a promise is through its `then` method, which
2354
- registers callbacks to receive either a promise's eventual value or the reason
2355
- why the promise cannot be fulfilled.
2356
 
2357
- Terminology
2358
- -----------
 
 
 
 
 
 
 
 
 
 
 
2359
 
2360
- - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
2361
- - `thenable` is an object or function that defines a `then` method.
2362
- - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
2363
- - `exception` is a value that is thrown using the throw statement.
2364
- - `reason` is a value that indicates why a promise was rejected.
2365
- - `settled` the final resting state of a promise, fulfilled or rejected.
2366
 
2367
- A promise can be in one of three states: pending, fulfilled, or rejected.
 
 
2368
 
2369
- Promises that are fulfilled have a fulfillment value and are in the fulfilled
2370
- state. Promises that are rejected have a rejection reason and are in the
2371
- rejected state. A fulfillment value is never a thenable.
 
2372
 
2373
- Promises can also be said to *resolve* a value. If this value is also a
2374
- promise, then the original promise's settled state will match the value's
2375
- settled state. So a promise that *resolves* a promise that rejects will
2376
- itself reject, and a promise that *resolves* a promise that fulfills will
2377
- itself fulfill.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2378
 
 
 
2379
 
2380
- Basic Usage:
2381
- ------------
2382
 
2383
- ```js
2384
- var promise = new Promise(function(resolve, reject) {
2385
- // on success
2386
- resolve(value);
 
 
2387
 
2388
- // on failure
2389
- reject(reason);
2390
- });
 
2391
 
2392
- promise.then(function(value) {
2393
- // on fulfillment
2394
- }, function(reason) {
2395
- // on rejection
2396
- });
2397
- ```
2398
-
2399
- Advanced Usage:
2400
- ---------------
2401
-
2402
- Promises shine when abstracting away asynchronous interactions such as
2403
- `XMLHttpRequest`s.
2404
-
2405
- ```js
2406
- function getJSON(url) {
2407
- return new Promise(function(resolve, reject){
2408
- var xhr = new XMLHttpRequest();
2409
-
2410
- xhr.open('GET', url);
2411
- xhr.onreadystatechange = handler;
2412
- xhr.responseType = 'json';
2413
- xhr.setRequestHeader('Accept', 'application/json');
2414
- xhr.send();
2415
-
2416
- function handler() {
2417
- if (this.readyState === this.DONE) {
2418
- if (this.status === 200) {
2419
- resolve(this.response);
2420
- } else {
2421
- reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
2422
- }
2423
- }
2424
- };
2425
- });
2426
- }
2427
 
2428
- getJSON('/posts.json').then(function(json) {
2429
- // on fulfillment
2430
- }, function(reason) {
2431
- // on rejection
2432
- });
2433
- ```
2434
 
2435
- Unlike callbacks, promises are great composable primitives.
 
 
 
 
2436
 
2437
- ```js
2438
- Promise.all([
2439
- getJSON('/posts'),
2440
- getJSON('/comments')
2441
- ]).then(function(values){
2442
- values[0] // => postsJSON
2443
- values[1] // => commentsJSON
2444
 
2445
- return values;
2446
- });
2447
- ```
2448
-
2449
- @class Promise
2450
- @param {function} resolver
2451
- Useful for tooling.
2452
- @constructor
2453
- */
2454
- function lib$es6$promise$promise$$Promise(resolver) {
2455
- this[lib$es6$promise$$internal$$PROMISE_ID] = lib$es6$promise$$internal$$nextId();
2456
- this._result = this._state = undefined;
2457
- this._subscribers = [];
2458
-
2459
- if (lib$es6$promise$$internal$$noop !== resolver) {
2460
- typeof resolver !== 'function' && lib$es6$promise$promise$$needsResolver();
2461
- this instanceof lib$es6$promise$promise$$Promise ? lib$es6$promise$$internal$$initializePromise(this, resolver) : lib$es6$promise$promise$$needsNew();
2462
- }
2463
- }
2464
 
2465
- lib$es6$promise$promise$$Promise.all = lib$es6$promise$promise$all$$default;
2466
- lib$es6$promise$promise$$Promise.race = lib$es6$promise$promise$race$$default;
2467
- lib$es6$promise$promise$$Promise.resolve = lib$es6$promise$promise$resolve$$default;
2468
- lib$es6$promise$promise$$Promise.reject = lib$es6$promise$promise$reject$$default;
2469
- lib$es6$promise$promise$$Promise._setScheduler = lib$es6$promise$asap$$setScheduler;
2470
- lib$es6$promise$promise$$Promise._setAsap = lib$es6$promise$asap$$setAsap;
2471
- lib$es6$promise$promise$$Promise._asap = lib$es6$promise$asap$$asap;
2472
-
2473
- lib$es6$promise$promise$$Promise.prototype = {
2474
- constructor: lib$es6$promise$promise$$Promise,
2475
-
2476
- /**
2477
- The primary way of interacting with a promise is through its `then` method,
2478
- which registers callbacks to receive either a promise's eventual value or the
2479
- reason why the promise cannot be fulfilled.
2480
-
2481
- ```js
2482
- findUser().then(function(user){
2483
- // user is available
2484
- }, function(reason){
2485
- // user is unavailable, and you are given the reason why
2486
- });
2487
- ```
2488
-
2489
- Chaining
2490
- --------
2491
-
2492
- The return value of `then` is itself a promise. This second, 'downstream'
2493
- promise is resolved with the return value of the first promise's fulfillment
2494
- or rejection handler, or rejected if the handler throws an exception.
2495
-
2496
- ```js
2497
- findUser().then(function (user) {
2498
- return user.name;
2499
- }, function (reason) {
2500
- return 'default name';
2501
- }).then(function (userName) {
2502
- // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
2503
- // will be `'default name'`
2504
- });
2505
 
2506
- findUser().then(function (user) {
2507
- throw new Error('Found user, but still unhappy');
2508
- }, function (reason) {
2509
- throw new Error('`findUser` rejected and we're unhappy');
2510
- }).then(function (value) {
2511
- // never reached
2512
- }, function (reason) {
2513
- // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
2514
- // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
2515
- });
2516
- ```
2517
- If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
2518
-
2519
- ```js
2520
- findUser().then(function (user) {
2521
- throw new PedagogicalException('Upstream error');
2522
- }).then(function (value) {
2523
- // never reached
2524
- }).then(function (value) {
2525
- // never reached
2526
- }, function (reason) {
2527
- // The `PedgagocialException` is propagated all the way down to here
2528
- });
2529
- ```
2530
 
2531
- Assimilation
2532
- ------------
2533
 
2534
- Sometimes the value you want to propagate to a downstream promise can only be
2535
- retrieved asynchronously. This can be achieved by returning a promise in the
2536
- fulfillment or rejection handler. The downstream promise will then be pending
2537
- until the returned promise is settled. This is called *assimilation*.
 
2538
 
2539
- ```js
2540
- findUser().then(function (user) {
2541
- return findCommentsByAuthor(user);
2542
- }).then(function (comments) {
2543
- // The user's comments are now available
2544
- });
2545
- ```
 
 
 
 
 
 
 
 
 
 
 
 
2546
 
2547
- If the assimliated promise rejects, then the downstream promise will also reject.
 
 
2548
 
2549
- ```js
2550
- findUser().then(function (user) {
2551
- return findCommentsByAuthor(user);
2552
- }).then(function (comments) {
2553
- // If `findCommentsByAuthor` fulfills, we'll have the value here
2554
- }, function (reason) {
2555
- // If `findCommentsByAuthor` rejects, we'll have the reason here
2556
- });
2557
- ```
2558
 
2559
- Simple Example
2560
- --------------
 
 
 
 
2561
 
2562
- Synchronous Example
 
 
 
 
2563
 
2564
- ```javascript
2565
- var result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2566
 
2567
- try {
2568
- result = findResult();
2569
- // success
2570
- } catch(reason) {
2571
- // failure
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2572
  }
2573
- ```
 
 
2574
 
2575
- Errback Example
 
 
2576
 
2577
- ```js
2578
- findResult(function(result, err){
2579
- if (err) {
2580
- // failure
2581
- } else {
2582
- // success
2583
- }
2584
- });
2585
- ```
2586
 
2587
- Promise Example;
 
 
 
 
 
2588
 
2589
- ```javascript
2590
- findResult().then(function(result){
2591
- // success
2592
- }, function(reason){
2593
- // failure
2594
- });
2595
- ```
2596
 
2597
- Advanced Example
2598
- --------------
2599
 
2600
- Synchronous Example
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2601
 
2602
- ```javascript
2603
- var author, books;
 
2604
 
2605
- try {
2606
- author = findAuthor();
2607
- books = findBooksByAuthor(author);
2608
- // success
2609
- } catch(reason) {
2610
- // failure
2611
- }
2612
- ```
2613
 
2614
- Errback Example
 
 
 
 
2615
 
2616
- ```js
 
2617
 
2618
- function foundBooks(books) {
 
 
 
 
 
2619
 
2620
- }
2621
 
2622
- function failure(reason) {
 
 
2623
 
2624
- }
 
 
 
 
2625
 
2626
- findAuthor(function(author, err){
2627
- if (err) {
2628
- failure(err);
2629
- // failure
2630
- } else {
2631
- try {
2632
- findBoooksByAuthor(author, function(books, err) {
2633
- if (err) {
2634
- failure(err);
2635
- } else {
2636
- try {
2637
- foundBooks(books);
2638
- } catch(reason) {
2639
- failure(reason);
2640
- }
2641
- }
2642
- });
2643
- } catch(error) {
2644
- failure(err);
2645
- }
2646
- // success
2647
- }
2648
- });
2649
- ```
2650
 
2651
- Promise Example;
 
2652
 
2653
- ```javascript
2654
- findAuthor().
2655
- then(findBooksByAuthor).
2656
- then(function(books){
2657
- // found books
2658
- }).catch(function(reason){
2659
- // something went wrong
2660
- });
2661
- ```
2662
-
2663
- @method then
2664
- @param {Function} onFulfilled
2665
- @param {Function} onRejected
2666
- Useful for tooling.
2667
- @return {Promise}
2668
- */
2669
- then: lib$es6$promise$then$$default,
2670
-
2671
- /**
2672
- `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
2673
- as the catch block of a try/catch statement.
2674
-
2675
- ```js
2676
- function findAuthor(){
2677
- throw new Error('couldn't find that author');
2678
- }
2679
 
2680
- // synchronous
2681
- try {
2682
- findAuthor();
2683
- } catch(reason) {
2684
- // something went wrong
2685
- }
2686
 
2687
- // async with promises
2688
- findAuthor().catch(function(reason){
2689
- // something went wrong
2690
- });
2691
- ```
2692
-
2693
- @method catch
2694
- @param {Function} onRejection
2695
- Useful for tooling.
2696
- @return {Promise}
2697
- */
2698
- 'catch': function(onRejection) {
2699
- return this.then(null, onRejection);
2700
- }
2701
- };
2702
- var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator;
2703
- function lib$es6$promise$enumerator$$Enumerator(Constructor, input) {
2704
- this._instanceConstructor = Constructor;
2705
- this.promise = new Constructor(lib$es6$promise$$internal$$noop);
2706
-
2707
- if (!this.promise[lib$es6$promise$$internal$$PROMISE_ID]) {
2708
- lib$es6$promise$$internal$$makePromise(this.promise);
2709
- }
2710
 
2711
- if (lib$es6$promise$utils$$isArray(input)) {
2712
- this._input = input;
2713
- this.length = input.length;
2714
- this._remaining = input.length;
2715
 
2716
- this._result = new Array(this.length);
 
2717
 
2718
- if (this.length === 0) {
2719
- lib$es6$promise$$internal$$fulfill(this.promise, this._result);
2720
- } else {
2721
- this.length = this.length || 0;
2722
- this._enumerate();
2723
- if (this._remaining === 0) {
2724
- lib$es6$promise$$internal$$fulfill(this.promise, this._result);
 
 
 
 
 
 
 
 
 
 
2725
  }
2726
  }
2727
- } else {
2728
- lib$es6$promise$$internal$$reject(this.promise, lib$es6$promise$enumerator$$validationError());
2729
- }
2730
- }
2731
-
2732
- function lib$es6$promise$enumerator$$validationError() {
2733
- return new Error('Array Methods must be provided an Array');
2734
- }
2735
 
2736
- lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() {
2737
- var length = this.length;
2738
- var input = this._input;
 
 
 
2739
 
2740
- for (var i = 0; this._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
2741
- this._eachEntry(input[i], i);
2742
- }
2743
- };
2744
-
2745
- lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
2746
- var c = this._instanceConstructor;
2747
- var resolve = c.resolve;
2748
-
2749
- if (resolve === lib$es6$promise$promise$resolve$$default) {
2750
- var then = lib$es6$promise$$internal$$getThen(entry);
2751
-
2752
- if (then === lib$es6$promise$then$$default &&
2753
- entry._state !== lib$es6$promise$$internal$$PENDING) {
2754
- this._settledAt(entry._state, i, entry._result);
2755
- } else if (typeof then !== 'function') {
2756
- this._remaining--;
2757
- this._result[i] = entry;
2758
- } else if (c === lib$es6$promise$promise$$default) {
2759
- var promise = new c(lib$es6$promise$$internal$$noop);
2760
- lib$es6$promise$$internal$$handleMaybeThenable(promise, entry, then);
2761
- this._willSettleAt(promise, i);
2762
- } else {
2763
- this._willSettleAt(new c(function(resolve) { resolve(entry); }), i);
2764
- }
2765
- } else {
2766
- this._willSettleAt(resolve(entry), i);
2767
- }
2768
- };
2769
 
2770
- lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
2771
- var promise = this.promise;
 
 
 
 
 
2772
 
2773
- if (promise._state === lib$es6$promise$$internal$$PENDING) {
2774
- this._remaining--;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2775
 
2776
- if (state === lib$es6$promise$$internal$$REJECTED) {
2777
- lib$es6$promise$$internal$$reject(promise, value);
2778
- } else {
2779
- this._result[i] = value;
2780
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2781
  }
2782
-
2783
- if (this._remaining === 0) {
2784
- lib$es6$promise$$internal$$fulfill(promise, this._result);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2785
  }
2786
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2787
 
2788
- lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
2789
- var enumerator = this;
2790
 
2791
- lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) {
2792
- enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value);
2793
- }, function(reason) {
2794
- enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason);
2795
- });
2796
- };
2797
- function lib$es6$promise$polyfill$$polyfill() {
2798
- var local;
2799
-
2800
- if (typeof global !== 'undefined') {
2801
- local = global;
2802
- } else if (typeof self !== 'undefined') {
2803
- local = self;
2804
- } else {
2805
- try {
2806
- local = Function('return this')();
2807
- } catch (e) {
2808
- throw new Error('polyfill failed because global object is unavailable in this environment');
2809
- }
2810
- }
2811
 
2812
- var P = local.Promise;
2813
 
2814
- if (P && Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast) {
2815
- return;
2816
- }
 
 
 
 
2817
 
2818
- local.Promise = lib$es6$promise$promise$$default;
2819
- }
2820
- var lib$es6$promise$polyfill$$default = lib$es6$promise$polyfill$$polyfill;
2821
-
2822
- var lib$es6$promise$umd$$ES6Promise = {
2823
- 'Promise': lib$es6$promise$promise$$default,
2824
- 'polyfill': lib$es6$promise$polyfill$$default
2825
- };
2826
-
2827
- /* global define:true module:true window: true */
2828
- if ("function" === 'function' && __webpack_require__(18)['amd']) {
2829
- !(__WEBPACK_AMD_DEFINE_RESULT__ = function() { return lib$es6$promise$umd$$ES6Promise; }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
2830
- } else if (typeof module !== 'undefined' && module['exports']) {
2831
- module['exports'] = lib$es6$promise$umd$$ES6Promise;
2832
- } else if (typeof this !== 'undefined') {
2833
- this['ES6Promise'] = lib$es6$promise$umd$$ES6Promise;
2834
  }
2835
 
2836
- lib$es6$promise$polyfill$$default();
2837
- }).call(this);
 
 
 
 
 
2838
 
 
2839
 
 
 
2840
 
2841
  /*** EXPORTS FROM exports-loader ***/
2842
  module.exports = global.Promise;
2843
  }.call(global));
2844
- /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(15), (function() { return this; }()), __webpack_require__(16)(module)))
2845
 
2846
  /***/ },
2847
  /* 15 */
2848
  /***/ function(module, exports) {
2849
 
2850
  // shim for using process in browser
2851
-
2852
  var process = module.exports = {};
2853
 
2854
- // cached from whatever global is present so that test runners that stub it don't break things.
2855
- var cachedSetTimeout = setTimeout;
2856
- var cachedClearTimeout = clearTimeout;
 
2857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2858
  var queue = [];
2859
  var draining = false;
2860
  var currentQueue;
@@ -2879,7 +3187,7 @@
2879
  if (draining) {
2880
  return;
2881
  }
2882
- var timeout = cachedSetTimeout(cleanUpNextTick);
2883
  draining = true;
2884
 
2885
  var len = queue.length;
@@ -2896,7 +3204,7 @@
2896
  }
2897
  currentQueue = null;
2898
  draining = false;
2899
- cachedClearTimeout(timeout);
2900
  }
2901
 
2902
  process.nextTick = function (fun) {
@@ -2908,7 +3216,7 @@
2908
  }
2909
  queue.push(new Item(fun, args));
2910
  if (queue.length === 1 && !draining) {
2911
- cachedSetTimeout(drainQueue, 0);
2912
  }
2913
  };
2914
 
@@ -2950,32 +3258,9 @@
2950
 
2951
  /***/ },
2952
  /* 16 */
2953
- /***/ function(module, exports) {
2954
-
2955
- module.exports = function(module) {
2956
- if(!module.webpackPolyfill) {
2957
- module.deprecate = function() {};
2958
- module.paths = [];
2959
- // module.parent = undefined by default
2960
- module.children = [];
2961
- module.webpackPolyfill = 1;
2962
- }
2963
- return module;
2964
- }
2965
-
2966
-
2967
- /***/ },
2968
- /* 17 */
2969
  /***/ function(module, exports) {
2970
 
2971
  /* (ignored) */
2972
 
2973
- /***/ },
2974
- /* 18 */
2975
- /***/ function(module, exports) {
2976
-
2977
- module.exports = function() { throw new Error("define cannot be used indirect"); };
2978
-
2979
-
2980
  /***/ }
2981
  /******/ ]);
47
  'use strict';
48
 
49
  /**
50
+ * Copyright (C) 2014-2017 ServMask Inc.
51
  *
52
  * This program is free software: you can redistribute it and/or modify
53
  * it under the terms of the GNU General Public License as published by
94
  'use strict';
95
 
96
  /**
97
+ * Copyright (C) 2014-2017 ServMask Inc.
98
  *
99
  * This program is free software: you can redistribute it and/or modify
100
  * it under the terms of the GNU General Public License as published by
140
  $.ajax({
141
  type: 'POST',
142
  url: ai1wm_report.ajax.url,
143
+ data: { 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
144
  success: function success(data) {
145
  var errors = data.errors;
146
  if (errors.length > 0) {
176
  'use strict';
177
 
178
  /**
179
+ * Copyright (C) 2014-2017 ServMask Inc.
180
  *
181
  * This program is free software: you can redistribute it and/or modify
182
  * it under the terms of the GNU General Public License as published by
259
  $.ajax({
260
  type: 'POST',
261
  url: ai1wm_feedback.ajax.url,
262
+ data: { 'ai1wm_type': type, 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
263
  success: function success(data) {
264
  var errors = data.errors;
265
  if (errors.length > 0) {
290
  'use strict';
291
 
292
  /**
293
+ * Copyright (C) 2014-2017 ServMask Inc.
294
  *
295
  * This program is free software: you can redistribute it and/or modify
296
  * it under the terms of the GNU General Public License as published by
360
  'use strict';
361
 
362
  /**
363
+ * Copyright (C) 2014-2017 ServMask Inc.
364
  *
365
  * This program is free software: you can redistribute it and/or modify
366
  * it under the terms of the GNU General Public License as published by
675
  'use strict';
676
 
677
  /**
678
+ * Copyright (C) 2014-2017 ServMask Inc.
679
  *
680
  * This program is free software: you can redistribute it and/or modify
681
  * it under the terms of the GNU General Public License as published by
1039
  'use strict';
1040
 
1041
  /**
1042
+ * Copyright (C) 2014-2017 ServMask Inc.
1043
  *
1044
  * This program is free software: you can redistribute it and/or modify
1045
  * it under the terms of the GNU General Public License as published by
1133
  'use strict';
1134
 
1135
  /**
1136
+ * Copyright (C) 2014-2017 ServMask Inc.
1137
  *
1138
  * This program is free software: you can redistribute it and/or modify
1139
  * it under the terms of the GNU General Public License as published by
1212
  /* WEBPACK VAR INJECTION */(function(fetch, global) {'use strict';
1213
 
1214
  /**
1215
+ * Copyright (C) 2014-2017 ServMask Inc.
1216
  *
1217
  * This program is free software: you can redistribute it and/or modify
1218
  * it under the terms of the GNU General Public License as published by
1452
  arrayBuffer: 'ArrayBuffer' in self
1453
  }
1454
 
1455
+ if (support.arrayBuffer) {
1456
+ var viewClasses = [
1457
+ '[object Int8Array]',
1458
+ '[object Uint8Array]',
1459
+ '[object Uint8ClampedArray]',
1460
+ '[object Int16Array]',
1461
+ '[object Uint16Array]',
1462
+ '[object Int32Array]',
1463
+ '[object Uint32Array]',
1464
+ '[object Float32Array]',
1465
+ '[object Float64Array]'
1466
+ ]
1467
+
1468
+ var isDataView = function(obj) {
1469
+ return obj && DataView.prototype.isPrototypeOf(obj)
1470
+ }
1471
+
1472
+ var isArrayBufferView = ArrayBuffer.isView || function(obj) {
1473
+ return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
1474
+ }
1475
+ }
1476
+
1477
  function normalizeName(name) {
1478
  if (typeof name !== 'string') {
1479
  name = String(name)
1606
 
1607
  function readBlobAsArrayBuffer(blob) {
1608
  var reader = new FileReader()
1609
+ var promise = fileReaderReady(reader)
1610
  reader.readAsArrayBuffer(blob)
1611
+ return promise
1612
  }
1613
 
1614
  function readBlobAsText(blob) {
1615
  var reader = new FileReader()
1616
+ var promise = fileReaderReady(reader)
1617
  reader.readAsText(blob)
1618
+ return promise
1619
+ }
1620
+
1621
+ function readArrayBufferAsText(buf) {
1622
+ var view = new Uint8Array(buf)
1623
+ var chars = new Array(view.length)
1624
+
1625
+ for (var i = 0; i < view.length; i++) {
1626
+ chars[i] = String.fromCharCode(view[i])
1627
+ }
1628
+ return chars.join('')
1629
+ }
1630
+
1631
+ function bufferClone(buf) {
1632
+ if (buf.slice) {
1633
+ return buf.slice(0)
1634
+ } else {
1635
+ var view = new Uint8Array(buf.byteLength)
1636
+ view.set(new Uint8Array(buf))
1637
+ return view.buffer
1638
+ }
1639
  }
1640
 
1641
  function Body() {
1643
 
1644
  this._initBody = function(body) {
1645
  this._bodyInit = body
1646
+ if (!body) {
1647
+ this._bodyText = ''
1648
+ } else if (typeof body === 'string') {
1649
  this._bodyText = body
1650
  } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
1651
  this._bodyBlob = body
1653
  this._bodyFormData = body
1654
  } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
1655
  this._bodyText = body.toString()
1656
+ } else if (support.arrayBuffer && support.blob && isDataView(body)) {
1657
+ this._bodyArrayBuffer = bufferClone(body.buffer)
1658
+ // IE 10-11 can't handle a DataView body.
1659
+ this._bodyInit = new Blob([this._bodyArrayBuffer])
1660
+ } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
1661
+ this._bodyArrayBuffer = bufferClone(body)
1662
  } else {
1663
  throw new Error('unsupported BodyInit type')
1664
  }
1683
 
1684
  if (this._bodyBlob) {
1685
  return Promise.resolve(this._bodyBlob)
1686
+ } else if (this._bodyArrayBuffer) {
1687
+ return Promise.resolve(new Blob([this._bodyArrayBuffer]))
1688
  } else if (this._bodyFormData) {
1689
  throw new Error('could not read FormData body as blob')
1690
  } else {
1693
  }
1694
 
1695
  this.arrayBuffer = function() {
1696
+ if (this._bodyArrayBuffer) {
1697
+ return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
 
 
 
 
 
 
 
 
 
 
 
1698
  } else {
1699
+ return this.blob().then(readBlobAsArrayBuffer)
1700
  }
1701
  }
1702
+ }
1703
+
1704
+ this.text = function() {
1705
+ var rejected = consumed(this)
1706
+ if (rejected) {
1707
+ return rejected
1708
+ }
1709
+
1710
+ if (this._bodyBlob) {
1711
+ return readBlobAsText(this._bodyBlob)
1712
+ } else if (this._bodyArrayBuffer) {
1713
+ return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
1714
+ } else if (this._bodyFormData) {
1715
+ throw new Error('could not read FormData body as text')
1716
+ } else {
1717
+ return Promise.resolve(this._bodyText)
1718
  }
1719
  }
1720
 
1742
  function Request(input, options) {
1743
  options = options || {}
1744
  var body = options.body
1745
+
1746
+ if (typeof input === 'string') {
1747
+ this.url = input
1748
+ } else {
1749
  if (input.bodyUsed) {
1750
  throw new TypeError('Already read')
1751
  }
1756
  }
1757
  this.method = input.method
1758
  this.mode = input.mode
1759
+ if (!body && input._bodyInit != null) {
1760
  body = input._bodyInit
1761
  input.bodyUsed = true
1762
  }
 
 
1763
  }
1764
 
1765
  this.credentials = options.credentials || this.credentials || 'omit'
1777
  }
1778
 
1779
  Request.prototype.clone = function() {
1780
+ return new Request(this, { body: this._bodyInit })
1781
  }
1782
 
1783
  function decode(body) {
1793
  return form
1794
  }
1795
 
1796
+ function parseHeaders(rawHeaders) {
1797
+ var headers = new Headers()
1798
+ rawHeaders.split('\r\n').forEach(function(line) {
1799
+ var parts = line.split(':')
1800
+ var key = parts.shift().trim()
1801
+ if (key) {
1802
+ var value = parts.join(':').trim()
1803
+ headers.append(key, value)
1804
+ }
1805
  })
1806
+ return headers
1807
  }
1808
 
1809
  Body.call(Request.prototype)
1814
  }
1815
 
1816
  this.type = 'default'
1817
+ this.status = 'status' in options ? options.status : 200
1818
  this.ok = this.status >= 200 && this.status < 300
1819
+ this.statusText = 'statusText' in options ? options.statusText : 'OK'
1820
+ this.headers = new Headers(options.headers)
1821
  this.url = options.url || ''
1822
  this._initBody(bodyInit)
1823
  }
1855
 
1856
  self.fetch = function(input, init) {
1857
  return new Promise(function(resolve, reject) {
1858
+ var request = new Request(input, init)
 
 
 
 
 
 
1859
  var xhr = new XMLHttpRequest()
1860
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1861
  xhr.onload = function() {
1862
  var options = {
1863
  status: xhr.status,
1864
  statusText: xhr.statusText,
1865
+ headers: parseHeaders(xhr.getAllResponseHeaders() || '')
 
1866
  }
1867
+ options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL')
1868
  var body = 'response' in xhr ? xhr.response : xhr.responseText
1869
  resolve(new Response(body, options))
1870
  }
1907
  /* 14 */
1908
  /***/ function(module, exports, __webpack_require__) {
1909
 
1910
+ var require;/* WEBPACK VAR INJECTION */(function(process, Promise, global) {/*** IMPORTS FROM imports-loader ***/
1911
  (function() {
1912
 
1913
  /*!
1914
  * @overview es6-promise - a tiny implementation of Promises/A+.
1915
  * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
1916
  * @license Licensed under MIT license
1917
+ * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
1918
+ * @version 3.3.1
1919
  */
1920
 
1921
+ (function (global, factory) {
1922
+ true ? module.exports = factory() :
1923
+ typeof define === 'function' && define.amd ? define(factory) :
1924
+ (global.ES6Promise = factory());
1925
+ }(this, (function () { 'use strict';
1926
 
1927
+ function objectOrFunction(x) {
1928
+ return typeof x === 'function' || typeof x === 'object' && x !== null;
1929
+ }
1930
 
1931
+ function isFunction(x) {
1932
+ return typeof x === 'function';
1933
+ }
1934
 
1935
+ var _isArray = undefined;
1936
+ if (!Array.isArray) {
1937
+ _isArray = function (x) {
1938
+ return Object.prototype.toString.call(x) === '[object Array]';
1939
+ };
1940
+ } else {
1941
+ _isArray = Array.isArray;
1942
+ }
1943
+
1944
+ var isArray = _isArray;
1945
+
1946
+ var len = 0;
1947
+ var vertxNext = undefined;
1948
+ var customSchedulerFn = undefined;
1949
+
1950
+ var asap = function asap(callback, arg) {
1951
+ queue[len] = callback;
1952
+ queue[len + 1] = arg;
1953
+ len += 2;
1954
+ if (len === 2) {
1955
+ // If len is 2, that means that we need to schedule an async flush.
1956
+ // If additional callbacks are queued before the queue is flushed, they
1957
+ // will be processed by this flush that we are scheduling.
1958
+ if (customSchedulerFn) {
1959
+ customSchedulerFn(flush);
1960
  } else {
1961
+ scheduleFlush();
1962
  }
1963
+ }
1964
+ };
1965
 
1966
+ function setScheduler(scheduleFn) {
1967
+ customSchedulerFn = scheduleFn;
1968
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1969
 
1970
+ function setAsap(asapFn) {
1971
+ asap = asapFn;
1972
+ }
1973
 
1974
+ var browserWindow = typeof window !== 'undefined' ? window : undefined;
1975
+ var browserGlobal = browserWindow || {};
1976
+ var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
1977
+ var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]';
1978
+
1979
+ // test for web worker but not in IE10
1980
+ var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
1981
+
1982
+ // node
1983
+ function useNextTick() {
1984
+ // node version 0.10.x displays a deprecation warning when nextTick is used recursively
1985
+ // see https://github.com/cujojs/when/issues/410 for details
1986
+ return function () {
1987
+ return process.nextTick(flush);
1988
+ };
1989
+ }
1990
 
1991
+ // vertx
1992
+ function useVertxTimer() {
1993
+ return function () {
1994
+ vertxNext(flush);
1995
+ };
1996
+ }
 
 
 
 
 
 
 
 
 
 
 
 
1997
 
1998
+ function useMutationObserver() {
1999
+ var iterations = 0;
2000
+ var observer = new BrowserMutationObserver(flush);
2001
+ var node = document.createTextNode('');
2002
+ observer.observe(node, { characterData: true });
 
2003
 
2004
+ return function () {
2005
+ node.data = iterations = ++iterations % 2;
2006
+ };
2007
+ }
 
2008
 
2009
+ // web worker
2010
+ function useMessageChannel() {
2011
+ var channel = new MessageChannel();
2012
+ channel.port1.onmessage = flush;
2013
+ return function () {
2014
+ return channel.port2.postMessage(0);
2015
+ };
2016
+ }
2017
 
2018
+ function useSetTimeout() {
2019
+ // Store setTimeout reference so es6-promise will be unaffected by
2020
+ // other code modifying setTimeout (like sinon.useFakeTimers())
2021
+ var globalSetTimeout = setTimeout;
2022
+ return function () {
2023
+ return globalSetTimeout(flush, 1);
2024
+ };
2025
+ }
2026
 
2027
+ var queue = new Array(1000);
2028
+ function flush() {
2029
+ for (var i = 0; i < len; i += 2) {
2030
+ var callback = queue[i];
2031
+ var arg = queue[i + 1];
2032
 
2033
+ callback(arg);
 
 
 
 
2034
 
2035
+ queue[i] = undefined;
2036
+ queue[i + 1] = undefined;
2037
+ }
2038
 
2039
+ len = 0;
2040
+ }
 
2041
 
2042
+ function attemptVertx() {
2043
+ try {
2044
+ var r = require;
2045
+ var vertx = __webpack_require__(16);
2046
+ vertxNext = vertx.runOnLoop || vertx.runOnContext;
2047
+ return useVertxTimer();
2048
+ } catch (e) {
2049
+ return useSetTimeout();
2050
+ }
2051
+ }
2052
 
2053
+ var scheduleFlush = undefined;
2054
+ // Decide what async method to use to triggering processing of queued callbacks:
2055
+ if (isNode) {
2056
+ scheduleFlush = useNextTick();
2057
+ } else if (BrowserMutationObserver) {
2058
+ scheduleFlush = useMutationObserver();
2059
+ } else if (isWorker) {
2060
+ scheduleFlush = useMessageChannel();
2061
+ } else if (browserWindow === undefined && "function" === 'function') {
2062
+ scheduleFlush = attemptVertx();
2063
+ } else {
2064
+ scheduleFlush = useSetTimeout();
2065
+ }
2066
 
2067
+ function then(onFulfillment, onRejection) {
2068
+ var _arguments = arguments;
 
 
 
 
 
 
 
 
 
 
 
 
 
2069
 
2070
+ var parent = this;
2071
 
2072
+ var child = new this.constructor(noop);
 
 
2073
 
2074
+ if (child[PROMISE_ID] === undefined) {
2075
+ makePromise(child);
2076
+ }
2077
 
2078
+ var _state = parent._state;
 
 
 
 
 
 
 
2079
 
2080
+ if (_state) {
2081
+ (function () {
2082
+ var callback = _arguments[_state - 1];
2083
+ asap(function () {
2084
+ return invokeCallback(_state, child, callback, parent._result);
2085
+ });
2086
+ })();
2087
+ } else {
2088
+ subscribe(parent, child, onFulfillment, onRejection);
2089
+ }
2090
 
2091
+ return child;
2092
+ }
 
2093
 
2094
+ /**
2095
+ `Promise.resolve` returns a promise that will become resolved with the
2096
+ passed `value`. It is shorthand for the following:
 
 
 
2097
 
2098
+ ```javascript
2099
+ let promise = new Promise(function(resolve, reject){
2100
+ resolve(1);
2101
+ });
2102
 
2103
+ promise.then(function(value){
2104
+ // value === 1
2105
+ });
2106
+ ```
2107
 
2108
+ Instead of writing the above, your code now simply becomes the following:
2109
 
2110
+ ```javascript
2111
+ let promise = Promise.resolve(1);
 
2112
 
2113
+ promise.then(function(value){
2114
+ // value === 1
2115
+ });
2116
+ ```
2117
+
2118
+ @method resolve
2119
+ @static
2120
+ @param {Any} value value that the returned promise will be resolved with
2121
+ Useful for tooling.
2122
+ @return {Promise} a promise that will become fulfilled with the given
2123
+ `value`
2124
+ */
2125
+ function resolve(object) {
2126
+ /*jshint validthis:true */
2127
+ var Constructor = this;
2128
+
2129
+ if (object && typeof object === 'object' && object.constructor === Constructor) {
2130
+ return object;
2131
+ }
2132
 
2133
+ var promise = new Constructor(noop);
2134
+ _resolve(promise, object);
2135
+ return promise;
2136
+ }
 
 
 
 
2137
 
2138
+ var PROMISE_ID = Math.random().toString(36).substring(16);
 
 
 
 
 
 
2139
 
2140
+ function noop() {}
 
 
 
 
 
 
 
 
 
 
 
 
 
2141
 
2142
+ var PENDING = void 0;
2143
+ var FULFILLED = 1;
2144
+ var REJECTED = 2;
2145
 
2146
+ var GET_THEN_ERROR = new ErrorObject();
 
 
 
 
 
2147
 
2148
+ function selfFulfillment() {
2149
+ return new TypeError("You cannot resolve a promise with itself");
2150
+ }
 
 
 
 
 
 
 
 
 
 
2151
 
2152
+ function cannotReturnOwn() {
2153
+ return new TypeError('A promises callback cannot return that same promise.');
2154
+ }
2155
+
2156
+ function getThen(promise) {
2157
+ try {
2158
+ return promise.then;
2159
+ } catch (error) {
2160
+ GET_THEN_ERROR.error = error;
2161
+ return GET_THEN_ERROR;
2162
+ }
2163
+ }
2164
+
2165
+ function tryThen(then, value, fulfillmentHandler, rejectionHandler) {
2166
+ try {
2167
+ then.call(value, fulfillmentHandler, rejectionHandler);
2168
+ } catch (e) {
2169
+ return e;
2170
+ }
2171
+ }
2172
 
2173
+ function handleForeignThenable(promise, thenable, then) {
2174
+ asap(function (promise) {
2175
+ var sealed = false;
2176
+ var error = tryThen(then, thenable, function (value) {
2177
+ if (sealed) {
2178
+ return;
2179
+ }
2180
+ sealed = true;
2181
+ if (thenable !== value) {
2182
+ _resolve(promise, value);
2183
  } else {
2184
+ fulfill(promise, value);
2185
  }
2186
+ }, function (reason) {
2187
+ if (sealed) {
2188
+ return;
 
 
2189
  }
2190
+ sealed = true;
2191
 
2192
+ _reject(promise, reason);
2193
+ }, 'Settle: ' + (promise._label || ' unknown promise'));
2194
 
2195
+ if (!sealed && error) {
2196
+ sealed = true;
2197
+ _reject(promise, error);
2198
+ }
2199
+ }, promise);
2200
+ }
2201
 
2202
+ function handleOwnThenable(promise, thenable) {
2203
+ if (thenable._state === FULFILLED) {
2204
+ fulfill(promise, thenable._result);
2205
+ } else if (thenable._state === REJECTED) {
2206
+ _reject(promise, thenable._result);
2207
+ } else {
2208
+ subscribe(thenable, undefined, function (value) {
2209
+ return _resolve(promise, value);
2210
+ }, function (reason) {
2211
+ return _reject(promise, reason);
2212
+ });
2213
+ }
2214
+ }
2215
 
2216
+ function handleMaybeThenable(promise, maybeThenable, then$$) {
2217
+ if (maybeThenable.constructor === promise.constructor && then$$ === then && maybeThenable.constructor.resolve === resolve) {
2218
+ handleOwnThenable(promise, maybeThenable);
2219
+ } else {
2220
+ if (then$$ === GET_THEN_ERROR) {
2221
+ _reject(promise, GET_THEN_ERROR.error);
2222
+ } else if (then$$ === undefined) {
2223
+ fulfill(promise, maybeThenable);
2224
+ } else if (isFunction(then$$)) {
2225
+ handleForeignThenable(promise, maybeThenable, then$$);
2226
+ } else {
2227
+ fulfill(promise, maybeThenable);
2228
  }
2229
+ }
2230
+ }
2231
 
2232
+ function _resolve(promise, value) {
2233
+ if (promise === value) {
2234
+ _reject(promise, selfFulfillment());
2235
+ } else if (objectOrFunction(value)) {
2236
+ handleMaybeThenable(promise, value, getThen(value));
2237
+ } else {
2238
+ fulfill(promise, value);
2239
+ }
2240
+ }
2241
 
2242
+ function publishRejection(promise) {
2243
+ if (promise._onerror) {
2244
+ promise._onerror(promise._result);
2245
+ }
2246
 
2247
+ publish(promise);
2248
+ }
 
2249
 
2250
+ function fulfill(promise, value) {
2251
+ if (promise._state !== PENDING) {
2252
+ return;
2253
+ }
2254
 
2255
+ promise._result = value;
2256
+ promise._state = FULFILLED;
 
2257
 
2258
+ if (promise._subscribers.length !== 0) {
2259
+ asap(publish, promise);
2260
+ }
2261
+ }
2262
 
2263
+ function _reject(promise, reason) {
2264
+ if (promise._state !== PENDING) {
2265
+ return;
2266
+ }
2267
+ promise._state = REJECTED;
2268
+ promise._result = reason;
2269
 
2270
+ asap(publishRejection, promise);
2271
+ }
2272
 
2273
+ function subscribe(parent, child, onFulfillment, onRejection) {
2274
+ var _subscribers = parent._subscribers;
2275
+ var length = _subscribers.length;
2276
 
2277
+ parent._onerror = null;
 
 
2278
 
2279
+ _subscribers[length] = child;
2280
+ _subscribers[length + FULFILLED] = onFulfillment;
2281
+ _subscribers[length + REJECTED] = onRejection;
 
 
 
2282
 
2283
+ if (length === 0 && parent._state) {
2284
+ asap(publish, parent);
2285
+ }
2286
+ }
2287
 
2288
+ function publish(promise) {
2289
+ var subscribers = promise._subscribers;
2290
+ var settled = promise._state;
2291
 
2292
+ if (subscribers.length === 0) {
2293
+ return;
2294
+ }
2295
 
2296
+ var child = undefined,
2297
+ callback = undefined,
2298
+ detail = promise._result;
2299
+
2300
+ for (var i = 0; i < subscribers.length; i += 3) {
2301
+ child = subscribers[i];
2302
+ callback = subscribers[i + settled];
2303
+
2304
+ if (child) {
2305
+ invokeCallback(settled, child, callback, detail);
2306
+ } else {
2307
+ callback(detail);
2308
  }
2309
+ }
2310
 
2311
+ promise._subscribers.length = 0;
2312
+ }
 
2313
 
2314
+ function ErrorObject() {
2315
+ this.error = null;
2316
+ }
2317
 
2318
+ var TRY_CATCH_ERROR = new ErrorObject();
 
 
 
 
 
 
2319
 
2320
+ function tryCatch(callback, detail) {
2321
+ try {
2322
+ return callback(detail);
2323
+ } catch (e) {
2324
+ TRY_CATCH_ERROR.error = e;
2325
+ return TRY_CATCH_ERROR;
2326
+ }
2327
+ }
2328
 
2329
+ function invokeCallback(settled, promise, callback, detail) {
2330
+ var hasCallback = isFunction(callback),
2331
+ value = undefined,
2332
+ error = undefined,
2333
+ succeeded = undefined,
2334
+ failed = undefined;
2335
 
2336
+ if (hasCallback) {
2337
+ value = tryCatch(callback, detail);
 
 
 
 
 
 
 
 
 
 
2338
 
2339
+ if (value === TRY_CATCH_ERROR) {
2340
+ failed = true;
2341
+ error = value.error;
2342
+ value = null;
2343
+ } else {
2344
+ succeeded = true;
 
 
 
 
2345
  }
2346
 
2347
+ if (promise === value) {
2348
+ _reject(promise, cannotReturnOwn());
2349
+ return;
2350
  }
2351
+ } else {
2352
+ value = detail;
2353
+ succeeded = true;
2354
+ }
2355
 
2356
+ if (promise._state !== PENDING) {
2357
+ // noop
2358
+ } else if (hasCallback && succeeded) {
2359
+ _resolve(promise, value);
2360
+ } else if (failed) {
2361
+ _reject(promise, error);
2362
+ } else if (settled === FULFILLED) {
2363
+ fulfill(promise, value);
2364
+ } else if (settled === REJECTED) {
2365
+ _reject(promise, value);
2366
  }
2367
+ }
2368
 
2369
+ function initializePromise(promise, resolver) {
2370
+ try {
2371
+ resolver(function resolvePromise(value) {
2372
+ _resolve(promise, value);
2373
+ }, function rejectPromise(reason) {
2374
+ _reject(promise, reason);
2375
+ });
2376
+ } catch (e) {
2377
+ _reject(promise, e);
2378
+ }
2379
+ }
2380
+
2381
+ var id = 0;
2382
+ function nextId() {
2383
+ return id++;
2384
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2385
 
2386
+ function makePromise(promise) {
2387
+ promise[PROMISE_ID] = id++;
2388
+ promise._state = undefined;
2389
+ promise._result = undefined;
2390
+ promise._subscribers = [];
2391
+ }
2392
 
2393
+ function Enumerator(Constructor, input) {
2394
+ this._instanceConstructor = Constructor;
2395
+ this.promise = new Constructor(noop);
2396
 
2397
+ if (!this.promise[PROMISE_ID]) {
2398
+ makePromise(this.promise);
2399
+ }
2400
+
2401
+ if (isArray(input)) {
2402
+ this._input = input;
2403
+ this.length = input.length;
2404
+ this._remaining = input.length;
2405
 
2406
+ this._result = new Array(this.length);
 
 
 
 
 
2407
 
2408
+ if (this.length === 0) {
2409
+ fulfill(this.promise, this._result);
2410
+ } else {
2411
+ this.length = this.length || 0;
2412
+ this._enumerate();
2413
+ if (this._remaining === 0) {
2414
+ fulfill(this.promise, this._result);
2415
+ }
2416
+ }
2417
+ } else {
2418
+ _reject(this.promise, validationError());
2419
+ }
2420
+ }
2421
 
2422
+ function validationError() {
2423
+ return new Error('Array Methods must be provided an Array');
2424
+ };
 
 
 
2425
 
2426
+ Enumerator.prototype._enumerate = function () {
2427
+ var length = this.length;
2428
+ var _input = this._input;
2429
 
2430
+ for (var i = 0; this._state === PENDING && i < length; i++) {
2431
+ this._eachEntry(_input[i], i);
2432
+ }
2433
+ };
2434
 
2435
+ Enumerator.prototype._eachEntry = function (entry, i) {
2436
+ var c = this._instanceConstructor;
2437
+ var resolve$$ = c.resolve;
2438
+
2439
+ if (resolve$$ === resolve) {
2440
+ var _then = getThen(entry);
2441
+
2442
+ if (_then === then && entry._state !== PENDING) {
2443
+ this._settledAt(entry._state, i, entry._result);
2444
+ } else if (typeof _then !== 'function') {
2445
+ this._remaining--;
2446
+ this._result[i] = entry;
2447
+ } else if (c === Promise) {
2448
+ var promise = new c(noop);
2449
+ handleMaybeThenable(promise, entry, _then);
2450
+ this._willSettleAt(promise, i);
2451
+ } else {
2452
+ this._willSettleAt(new c(function (resolve$$) {
2453
+ return resolve$$(entry);
2454
+ }), i);
2455
+ }
2456
+ } else {
2457
+ this._willSettleAt(resolve$$(entry), i);
2458
+ }
2459
+ };
2460
 
2461
+ Enumerator.prototype._settledAt = function (state, i, value) {
2462
+ var promise = this.promise;
2463
 
2464
+ if (promise._state === PENDING) {
2465
+ this._remaining--;
2466
 
2467
+ if (state === REJECTED) {
2468
+ _reject(promise, value);
2469
+ } else {
2470
+ this._result[i] = value;
2471
+ }
2472
+ }
2473
 
2474
+ if (this._remaining === 0) {
2475
+ fulfill(promise, this._result);
2476
+ }
2477
+ };
2478
 
2479
+ Enumerator.prototype._willSettleAt = function (promise, i) {
2480
+ var enumerator = this;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2481
 
2482
+ subscribe(promise, undefined, function (value) {
2483
+ return enumerator._settledAt(FULFILLED, i, value);
2484
+ }, function (reason) {
2485
+ return enumerator._settledAt(REJECTED, i, reason);
2486
+ });
2487
+ };
2488
 
2489
+ /**
2490
+ `Promise.all` accepts an array of promises, and returns a new promise which
2491
+ is fulfilled with an array of fulfillment values for the passed promises, or
2492
+ rejected with the reason of the first passed promise to be rejected. It casts all
2493
+ elements of the passed iterable to promises as it runs this algorithm.
2494
 
2495
+ Example:
 
 
 
 
 
 
2496
 
2497
+ ```javascript
2498
+ let promise1 = resolve(1);
2499
+ let promise2 = resolve(2);
2500
+ let promise3 = resolve(3);
2501
+ let promises = [ promise1, promise2, promise3 ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2502
 
2503
+ Promise.all(promises).then(function(array){
2504
+ // The array here would be [ 1, 2, 3 ];
2505
+ });
2506
+ ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2507
 
2508
+ If any of the `promises` given to `all` are rejected, the first promise
2509
+ that is rejected will be given as an argument to the returned promises's
2510
+ rejection handler. For example:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2511
 
2512
+ Example:
 
2513
 
2514
+ ```javascript
2515
+ let promise1 = resolve(1);
2516
+ let promise2 = reject(new Error("2"));
2517
+ let promise3 = reject(new Error("3"));
2518
+ let promises = [ promise1, promise2, promise3 ];
2519
 
2520
+ Promise.all(promises).then(function(array){
2521
+ // Code here never runs because there are rejected promises!
2522
+ }, function(error) {
2523
+ // error.message === "2"
2524
+ });
2525
+ ```
2526
+
2527
+ @method all
2528
+ @static
2529
+ @param {Array} entries array of promises
2530
+ @param {String} label optional string for labeling the promise.
2531
+ Useful for tooling.
2532
+ @return {Promise} promise that is fulfilled when all `promises` have been
2533
+ fulfilled, or rejected if any of them become rejected.
2534
+ @static
2535
+ */
2536
+ function all(entries) {
2537
+ return new Enumerator(this, entries).promise;
2538
+ }
2539
 
2540
+ /**
2541
+ `Promise.race` returns a new promise which is settled in the same way as the
2542
+ first passed promise to settle.
2543
 
2544
+ Example:
 
 
 
 
 
 
 
 
2545
 
2546
+ ```javascript
2547
+ let promise1 = new Promise(function(resolve, reject){
2548
+ setTimeout(function(){
2549
+ resolve('promise 1');
2550
+ }, 200);
2551
+ });
2552
 
2553
+ let promise2 = new Promise(function(resolve, reject){
2554
+ setTimeout(function(){
2555
+ resolve('promise 2');
2556
+ }, 100);
2557
+ });
2558
 
2559
+ Promise.race([promise1, promise2]).then(function(result){
2560
+ // result === 'promise 2' because it was resolved before promise1
2561
+ // was resolved.
2562
+ });
2563
+ ```
2564
+
2565
+ `Promise.race` is deterministic in that only the state of the first
2566
+ settled promise matters. For example, even if other promises given to the
2567
+ `promises` array argument are resolved, but the first settled promise has
2568
+ become rejected before the other promises became fulfilled, the returned
2569
+ promise will become rejected:
2570
+
2571
+ ```javascript
2572
+ let promise1 = new Promise(function(resolve, reject){
2573
+ setTimeout(function(){
2574
+ resolve('promise 1');
2575
+ }, 200);
2576
+ });
2577
 
2578
+ let promise2 = new Promise(function(resolve, reject){
2579
+ setTimeout(function(){
2580
+ reject(new Error('promise 2'));
2581
+ }, 100);
2582
+ });
2583
+
2584
+ Promise.race([promise1, promise2]).then(function(result){
2585
+ // Code here never runs
2586
+ }, function(reason){
2587
+ // reason.message === 'promise 2' because promise 2 became rejected before
2588
+ // promise 1 became fulfilled
2589
+ });
2590
+ ```
2591
+
2592
+ An example real-world use case is implementing timeouts:
2593
+
2594
+ ```javascript
2595
+ Promise.race([ajax('foo.json'), timeout(5000)])
2596
+ ```
2597
+
2598
+ @method race
2599
+ @static
2600
+ @param {Array} promises array of promises to observe
2601
+ Useful for tooling.
2602
+ @return {Promise} a promise which settles in the same way as the first passed
2603
+ promise to settle.
2604
+ */
2605
+ function race(entries) {
2606
+ /*jshint validthis:true */
2607
+ var Constructor = this;
2608
+
2609
+ if (!isArray(entries)) {
2610
+ return new Constructor(function (_, reject) {
2611
+ return reject(new TypeError('You must pass an array to race.'));
2612
+ });
2613
+ } else {
2614
+ return new Constructor(function (resolve, reject) {
2615
+ var length = entries.length;
2616
+ for (var i = 0; i < length; i++) {
2617
+ Constructor.resolve(entries[i]).then(resolve, reject);
2618
  }
2619
+ });
2620
+ }
2621
+ }
2622
 
2623
+ /**
2624
+ `Promise.reject` returns a promise rejected with the passed `reason`.
2625
+ It is shorthand for the following:
2626
 
2627
+ ```javascript
2628
+ let promise = new Promise(function(resolve, reject){
2629
+ reject(new Error('WHOOPS'));
2630
+ });
 
 
 
 
 
2631
 
2632
+ promise.then(function(value){
2633
+ // Code here doesn't run because the promise is rejected!
2634
+ }, function(reason){
2635
+ // reason.message === 'WHOOPS'
2636
+ });
2637
+ ```
2638
 
2639
+ Instead of writing the above, your code now simply becomes the following:
 
 
 
 
 
 
2640
 
2641
+ ```javascript
2642
+ let promise = Promise.reject(new Error('WHOOPS'));
2643
 
2644
+ promise.then(function(value){
2645
+ // Code here doesn't run because the promise is rejected!
2646
+ }, function(reason){
2647
+ // reason.message === 'WHOOPS'
2648
+ });
2649
+ ```
2650
+
2651
+ @method reject
2652
+ @static
2653
+ @param {Any} reason value that the returned promise will be rejected with.
2654
+ Useful for tooling.
2655
+ @return {Promise} a promise rejected with the given `reason`.
2656
+ */
2657
+ function reject(reason) {
2658
+ /*jshint validthis:true */
2659
+ var Constructor = this;
2660
+ var promise = new Constructor(noop);
2661
+ _reject(promise, reason);
2662
+ return promise;
2663
+ }
2664
 
2665
+ function needsResolver() {
2666
+ throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
2667
+ }
2668
 
2669
+ function needsNew() {
2670
+ throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
2671
+ }
 
 
 
 
 
2672
 
2673
+ /**
2674
+ Promise objects represent the eventual result of an asynchronous operation. The
2675
+ primary way of interacting with a promise is through its `then` method, which
2676
+ registers callbacks to receive either a promise's eventual value or the reason
2677
+ why the promise cannot be fulfilled.
2678
 
2679
+ Terminology
2680
+ -----------
2681
 
2682
+ - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
2683
+ - `thenable` is an object or function that defines a `then` method.
2684
+ - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
2685
+ - `exception` is a value that is thrown using the throw statement.
2686
+ - `reason` is a value that indicates why a promise was rejected.
2687
+ - `settled` the final resting state of a promise, fulfilled or rejected.
2688
 
2689
+ A promise can be in one of three states: pending, fulfilled, or rejected.
2690
 
2691
+ Promises that are fulfilled have a fulfillment value and are in the fulfilled
2692
+ state. Promises that are rejected have a rejection reason and are in the
2693
+ rejected state. A fulfillment value is never a thenable.
2694
 
2695
+ Promises can also be said to *resolve* a value. If this value is also a
2696
+ promise, then the original promise's settled state will match the value's
2697
+ settled state. So a promise that *resolves* a promise that rejects will
2698
+ itself reject, and a promise that *resolves* a promise that fulfills will
2699
+ itself fulfill.
2700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2701
 
2702
+ Basic Usage:
2703
+ ------------
2704
 
2705
+ ```js
2706
+ let promise = new Promise(function(resolve, reject) {
2707
+ // on success
2708
+ resolve(value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2709
 
2710
+ // on failure
2711
+ reject(reason);
2712
+ });
 
 
 
2713
 
2714
+ promise.then(function(value) {
2715
+ // on fulfillment
2716
+ }, function(reason) {
2717
+ // on rejection
2718
+ });
2719
+ ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2720
 
2721
+ Advanced Usage:
2722
+ ---------------
 
 
2723
 
2724
+ Promises shine when abstracting away asynchronous interactions such as
2725
+ `XMLHttpRequest`s.
2726
 
2727
+ ```js
2728
+ function getJSON(url) {
2729
+ return new Promise(function(resolve, reject){
2730
+ let xhr = new XMLHttpRequest();
2731
+
2732
+ xhr.open('GET', url);
2733
+ xhr.onreadystatechange = handler;
2734
+ xhr.responseType = 'json';
2735
+ xhr.setRequestHeader('Accept', 'application/json');
2736
+ xhr.send();
2737
+
2738
+ function handler() {
2739
+ if (this.readyState === this.DONE) {
2740
+ if (this.status === 200) {
2741
+ resolve(this.response);
2742
+ } else {
2743
+ reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
2744
  }
2745
  }
2746
+ };
2747
+ });
2748
+ }
 
 
 
 
 
2749
 
2750
+ getJSON('/posts.json').then(function(json) {
2751
+ // on fulfillment
2752
+ }, function(reason) {
2753
+ // on rejection
2754
+ });
2755
+ ```
2756
 
2757
+ Unlike callbacks, promises are great composable primitives.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2758
 
2759
+ ```js
2760
+ Promise.all([
2761
+ getJSON('/posts'),
2762
+ getJSON('/comments')
2763
+ ]).then(function(values){
2764
+ values[0] // => postsJSON
2765
+ values[1] // => commentsJSON
2766
 
2767
+ return values;
2768
+ });
2769
+ ```
2770
+
2771
+ @class Promise
2772
+ @param {function} resolver
2773
+ Useful for tooling.
2774
+ @constructor
2775
+ */
2776
+ function Promise(resolver) {
2777
+ this[PROMISE_ID] = nextId();
2778
+ this._result = this._state = undefined;
2779
+ this._subscribers = [];
2780
+
2781
+ if (noop !== resolver) {
2782
+ typeof resolver !== 'function' && needsResolver();
2783
+ this instanceof Promise ? initializePromise(this, resolver) : needsNew();
2784
+ }
2785
+ }
2786
 
2787
+ Promise.all = all;
2788
+ Promise.race = race;
2789
+ Promise.resolve = resolve;
2790
+ Promise.reject = reject;
2791
+ Promise._setScheduler = setScheduler;
2792
+ Promise._setAsap = setAsap;
2793
+ Promise._asap = asap;
2794
+
2795
+ Promise.prototype = {
2796
+ constructor: Promise,
2797
+
2798
+ /**
2799
+ The primary way of interacting with a promise is through its `then` method,
2800
+ which registers callbacks to receive either a promise's eventual value or the
2801
+ reason why the promise cannot be fulfilled.
2802
+
2803
+ ```js
2804
+ findUser().then(function(user){
2805
+ // user is available
2806
+ }, function(reason){
2807
+ // user is unavailable, and you are given the reason why
2808
+ });
2809
+ ```
2810
+
2811
+ Chaining
2812
+ --------
2813
+
2814
+ The return value of `then` is itself a promise. This second, 'downstream'
2815
+ promise is resolved with the return value of the first promise's fulfillment
2816
+ or rejection handler, or rejected if the handler throws an exception.
2817
+
2818
+ ```js
2819
+ findUser().then(function (user) {
2820
+ return user.name;
2821
+ }, function (reason) {
2822
+ return 'default name';
2823
+ }).then(function (userName) {
2824
+ // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
2825
+ // will be `'default name'`
2826
+ });
2827
+
2828
+ findUser().then(function (user) {
2829
+ throw new Error('Found user, but still unhappy');
2830
+ }, function (reason) {
2831
+ throw new Error('`findUser` rejected and we're unhappy');
2832
+ }).then(function (value) {
2833
+ // never reached
2834
+ }, function (reason) {
2835
+ // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
2836
+ // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
2837
+ });
2838
+ ```
2839
+ If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
2840
+
2841
+ ```js
2842
+ findUser().then(function (user) {
2843
+ throw new PedagogicalException('Upstream error');
2844
+ }).then(function (value) {
2845
+ // never reached
2846
+ }).then(function (value) {
2847
+ // never reached
2848
+ }, function (reason) {
2849
+ // The `PedgagocialException` is propagated all the way down to here
2850
+ });
2851
+ ```
2852
+
2853
+ Assimilation
2854
+ ------------
2855
+
2856
+ Sometimes the value you want to propagate to a downstream promise can only be
2857
+ retrieved asynchronously. This can be achieved by returning a promise in the
2858
+ fulfillment or rejection handler. The downstream promise will then be pending
2859
+ until the returned promise is settled. This is called *assimilation*.
2860
+
2861
+ ```js
2862
+ findUser().then(function (user) {
2863
+ return findCommentsByAuthor(user);
2864
+ }).then(function (comments) {
2865
+ // The user's comments are now available
2866
+ });
2867
+ ```
2868
+
2869
+ If the assimliated promise rejects, then the downstream promise will also reject.
2870
+
2871
+ ```js
2872
+ findUser().then(function (user) {
2873
+ return findCommentsByAuthor(user);
2874
+ }).then(function (comments) {
2875
+ // If `findCommentsByAuthor` fulfills, we'll have the value here
2876
+ }, function (reason) {
2877
+ // If `findCommentsByAuthor` rejects, we'll have the reason here
2878
+ });
2879
+ ```
2880
+
2881
+ Simple Example
2882
+ --------------
2883
+
2884
+ Synchronous Example
2885
+
2886
+ ```javascript
2887
+ let result;
2888
+
2889
+ try {
2890
+ result = findResult();
2891
+ // success
2892
+ } catch(reason) {
2893
+ // failure
2894
+ }
2895
+ ```
2896
+
2897
+ Errback Example
2898
+
2899
+ ```js
2900
+ findResult(function(result, err){
2901
+ if (err) {
2902
+ // failure
2903
+ } else {
2904
+ // success
2905
  }
2906
+ });
2907
+ ```
2908
+
2909
+ Promise Example;
2910
+
2911
+ ```javascript
2912
+ findResult().then(function(result){
2913
+ // success
2914
+ }, function(reason){
2915
+ // failure
2916
+ });
2917
+ ```
2918
+
2919
+ Advanced Example
2920
+ --------------
2921
+
2922
+ Synchronous Example
2923
+
2924
+ ```javascript
2925
+ let author, books;
2926
+
2927
+ try {
2928
+ author = findAuthor();
2929
+ books = findBooksByAuthor(author);
2930
+ // success
2931
+ } catch(reason) {
2932
+ // failure
2933
+ }
2934
+ ```
2935
+
2936
+ Errback Example
2937
+
2938
+ ```js
2939
+
2940
+ function foundBooks(books) {
2941
+
2942
+ }
2943
+
2944
+ function failure(reason) {
2945
+
2946
+ }
2947
+
2948
+ findAuthor(function(author, err){
2949
+ if (err) {
2950
+ failure(err);
2951
+ // failure
2952
+ } else {
2953
+ try {
2954
+ findBoooksByAuthor(author, function(books, err) {
2955
+ if (err) {
2956
+ failure(err);
2957
+ } else {
2958
+ try {
2959
+ foundBooks(books);
2960
+ } catch(reason) {
2961
+ failure(reason);
2962
+ }
2963
+ }
2964
+ });
2965
+ } catch(error) {
2966
+ failure(err);
2967
+ }
2968
+ // success
2969
  }
2970
+ });
2971
+ ```
2972
+
2973
+ Promise Example;
2974
+
2975
+ ```javascript
2976
+ findAuthor().
2977
+ then(findBooksByAuthor).
2978
+ then(function(books){
2979
+ // found books
2980
+ }).catch(function(reason){
2981
+ // something went wrong
2982
+ });
2983
+ ```
2984
+
2985
+ @method then
2986
+ @param {Function} onFulfilled
2987
+ @param {Function} onRejected
2988
+ Useful for tooling.
2989
+ @return {Promise}
2990
+ */
2991
+ then: then,
2992
+
2993
+ /**
2994
+ `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
2995
+ as the catch block of a try/catch statement.
2996
+
2997
+ ```js
2998
+ function findAuthor(){
2999
+ throw new Error('couldn't find that author');
3000
+ }
3001
+
3002
+ // synchronous
3003
+ try {
3004
+ findAuthor();
3005
+ } catch(reason) {
3006
+ // something went wrong
3007
+ }
3008
+
3009
+ // async with promises
3010
+ findAuthor().catch(function(reason){
3011
+ // something went wrong
3012
+ });
3013
+ ```
3014
+
3015
+ @method catch
3016
+ @param {Function} onRejection
3017
+ Useful for tooling.
3018
+ @return {Promise}
3019
+ */
3020
+ 'catch': function _catch(onRejection) {
3021
+ return this.then(null, onRejection);
3022
+ }
3023
+ };
3024
 
3025
+ function polyfill() {
3026
+ var local = undefined;
3027
 
3028
+ if (typeof global !== 'undefined') {
3029
+ local = global;
3030
+ } else if (typeof self !== 'undefined') {
3031
+ local = self;
3032
+ } else {
3033
+ try {
3034
+ local = Function('return this')();
3035
+ } catch (e) {
3036
+ throw new Error('polyfill failed because global object is unavailable in this environment');
3037
+ }
3038
+ }
 
 
 
 
 
 
 
 
 
3039
 
3040
+ var P = local.Promise;
3041
 
3042
+ if (P) {
3043
+ var promiseToString = null;
3044
+ try {
3045
+ promiseToString = Object.prototype.toString.call(P.resolve());
3046
+ } catch (e) {
3047
+ // silently ignored
3048
+ }
3049
 
3050
+ if (promiseToString === '[object Promise]' && !P.cast) {
3051
+ return;
3052
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
3053
  }
3054
 
3055
+ local.Promise = Promise;
3056
+ }
3057
+
3058
+ polyfill();
3059
+ // Strange compat..
3060
+ Promise.polyfill = polyfill;
3061
+ Promise.Promise = Promise;
3062
 
3063
+ return Promise;
3064
 
3065
+ })));
3066
+ //# sourceMappingURL=es6-promise.map
3067
 
3068
  /*** EXPORTS FROM exports-loader ***/
3069
  module.exports = global.Promise;
3070
  }.call(global));
3071
+ /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(15), __webpack_require__(14), (function() { return this; }())))
3072
 
3073
  /***/ },
3074
  /* 15 */
3075
  /***/ function(module, exports) {
3076
 
3077
  // shim for using process in browser
 
3078
  var process = module.exports = {};
3079
 
3080
+ // cached from whatever global is present so that test runners that stub it
3081
+ // don't break things. But we need to wrap it in a try catch in case it is
3082
+ // wrapped in strict mode code which doesn't define any globals. It's inside a
3083
+ // function because try/catches deoptimize in certain engines.
3084
 
3085
+ var cachedSetTimeout;
3086
+ var cachedClearTimeout;
3087
+
3088
+ function defaultSetTimout() {
3089
+ throw new Error('setTimeout has not been defined');
3090
+ }
3091
+ function defaultClearTimeout () {
3092
+ throw new Error('clearTimeout has not been defined');
3093
+ }
3094
+ (function () {
3095
+ try {
3096
+ if (typeof setTimeout === 'function') {
3097
+ cachedSetTimeout = setTimeout;
3098
+ } else {
3099
+ cachedSetTimeout = defaultSetTimout;
3100
+ }
3101
+ } catch (e) {
3102
+ cachedSetTimeout = defaultSetTimout;
3103
+ }
3104
+ try {
3105
+ if (typeof clearTimeout === 'function') {
3106
+ cachedClearTimeout = clearTimeout;
3107
+ } else {
3108
+ cachedClearTimeout = defaultClearTimeout;
3109
+ }
3110
+ } catch (e) {
3111
+ cachedClearTimeout = defaultClearTimeout;
3112
+ }
3113
+ } ())
3114
+ function runTimeout(fun) {
3115
+ if (cachedSetTimeout === setTimeout) {
3116
+ //normal enviroments in sane situations
3117
+ return setTimeout(fun, 0);
3118
+ }
3119
+ // if setTimeout wasn't available but was latter defined
3120
+ if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
3121
+ cachedSetTimeout = setTimeout;
3122
+ return setTimeout(fun, 0);
3123
+ }
3124
+ try {
3125
+ // when when somebody has screwed with setTimeout but no I.E. maddness
3126
+ return cachedSetTimeout(fun, 0);
3127
+ } catch(e){
3128
+ try {
3129
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
3130
+ return cachedSetTimeout.call(null, fun, 0);
3131
+ } catch(e){
3132
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
3133
+ return cachedSetTimeout.call(this, fun, 0);
3134
+ }
3135
+ }
3136
+
3137
+
3138
+ }
3139
+ function runClearTimeout(marker) {
3140
+ if (cachedClearTimeout === clearTimeout) {
3141
+ //normal enviroments in sane situations
3142
+ return clearTimeout(marker);
3143
+ }
3144
+ // if clearTimeout wasn't available but was latter defined
3145
+ if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
3146
+ cachedClearTimeout = clearTimeout;
3147
+ return clearTimeout(marker);
3148
+ }
3149
+ try {
3150
+ // when when somebody has screwed with setTimeout but no I.E. maddness
3151
+ return cachedClearTimeout(marker);
3152
+ } catch (e){
3153
+ try {
3154
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
3155
+ return cachedClearTimeout.call(null, marker);
3156
+ } catch (e){
3157
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
3158
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
3159
+ return cachedClearTimeout.call(this, marker);
3160
+ }
3161
+ }
3162
+
3163
+
3164
+
3165
+ }
3166
  var queue = [];
3167
  var draining = false;
3168
  var currentQueue;
3187
  if (draining) {
3188
  return;
3189
  }
3190
+ var timeout = runTimeout(cleanUpNextTick);
3191
  draining = true;
3192
 
3193
  var len = queue.length;
3204
  }
3205
  currentQueue = null;
3206
  draining = false;
3207
+ runClearTimeout(timeout);
3208
  }
3209
 
3210
  process.nextTick = function (fun) {
3216
  }
3217
  queue.push(new Item(fun, args));
3218
  if (queue.length === 1 && !draining) {
3219
+ runTimeout(drainQueue);
3220
  }
3221
  };
3222
 
3258
 
3259
  /***/ },
3260
  /* 16 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3261
  /***/ function(module, exports) {
3262
 
3263
  /* (ignored) */
3264
 
 
 
 
 
 
 
 
3265
  /***/ }
3266
  /******/ ]);
lib/view/assets/javascript/updater.min.js CHANGED
@@ -47,7 +47,7 @@
47
  'use strict';
48
 
49
  /**
50
- * Copyright (C) 2014-2016 ServMask Inc.
51
  *
52
  * This program is free software: you can redistribute it and/or modify
53
  * it under the terms of the GNU General Public License as published by
@@ -85,7 +85,7 @@
85
 
86
  // Check Purchase ID
87
  $.getJSON('https://servmask.com/purchase/' + purchaseId + '/check', function (product) {
88
- $.post(ai1wm_updater.ajax.url, { 'ai1wm-uuid': product.uuid, 'ai1wm-extension': product.extension }, function () {
89
  window.location.hash = '';
90
 
91
  // Update plugin row
47
  'use strict';
48
 
49
  /**
50
+ * Copyright (C) 2014-2017 ServMask Inc.
51
  *
52
  * This program is free software: you can redistribute it and/or modify
53
  * it under the terms of the GNU General Public License as published by
85
 
86
  // Check Purchase ID
87
  $.getJSON('https://servmask.com/purchase/' + purchaseId + '/check', function (product) {
88
+ $.post(ai1wm_updater.ajax.url, { 'ai1wm_uuid': product.uuid, 'ai1wm_extension': product.extension }, function () {
89
  window.location.hash = '';
90
 
91
  // Update plugin row
lib/view/backups/index.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -52,7 +52,7 @@
52
  <i class="ai1wm-icon-file-zip"></i>
53
  <?php echo esc_html( $backup['filename'] ); ?>
54
  </td>
55
- <?php if ( is_null( $backup['mtime'] ) || is_null( $backup['size'] ) ) : ?>
56
  <td class="ai1wm-column-info" colspan="3">
57
  <?php _e( 'The file is too large for your hosting plan.', AI1WM_PLUGIN_NAME ); ?>
58
  </td>
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
52
  <i class="ai1wm-icon-file-zip"></i>
53
  <?php echo esc_html( $backup['filename'] ); ?>
54
  </td>
55
+ <?php if ( is_null( $backup['size'] ) ) : ?>
56
  <td class="ai1wm-column-info" colspan="3">
57
  <?php _e( 'The file is too large for your hosting plan.', AI1WM_PLUGIN_NAME ); ?>
58
  </td>
lib/view/common/leave-feedback.php CHANGED
@@ -1,21 +1,21 @@
1
  <div class="ai1wm-feedback">
2
  <ul class="ai1wm-feedback-types">
3
  <li>
4
- <input type="radio" class="ai1wm-flat-radio-button ai1wm-feedback-type" id="ai1wm-feedback-type-1" name="ai1wm-feedback-type" value="review" />
5
  <a id="ai1wm-feedback-type-link-1" href="https://wordpress.org/support/view/plugin-reviews/all-in-one-wp-migration?rate=5#postform" target="_blank">
6
  <i></i>
7
  <span><?php _e( 'I would like to review this plugin', AI1WM_PLUGIN_NAME ); ?></span>
8
  </a>
9
  </li>
10
  <li>
11
- <input type="radio" class="ai1wm-flat-radio-button ai1wm-feedback-type" id="ai1wm-feedback-type-2" name="ai1wm-feedback-type" value="suggestions" />
12
  <label for="ai1wm-feedback-type-2">
13
  <i></i>
14
  <span><?php _e( 'I have ideas to improve this plugin', AI1WM_PLUGIN_NAME ); ?></span>
15
  </label>
16
  </li>
17
  <li>
18
- <input type="radio" class="ai1wm-flat-radio-button ai1wm-feedback-type" id="ai1wm-feedback-type-3" name="ai1wm-feedback-type" value="help-needed" />
19
  <label for="ai1wm-feedback-type-3">
20
  <i></i>
21
  <span><?php _e( 'I need help with this plugin', AI1WM_PLUGIN_NAME ); ?></span>
1
  <div class="ai1wm-feedback">
2
  <ul class="ai1wm-feedback-types">
3
  <li>
4
+ <input type="radio" class="ai1wm-flat-radio-button ai1wm-feedback-type" id="ai1wm-feedback-type-1" name="ai1wm_feedback_type" value="review" />
5
  <a id="ai1wm-feedback-type-link-1" href="https://wordpress.org/support/view/plugin-reviews/all-in-one-wp-migration?rate=5#postform" target="_blank">
6
  <i></i>
7
  <span><?php _e( 'I would like to review this plugin', AI1WM_PLUGIN_NAME ); ?></span>
8
  </a>
9
  </li>
10
  <li>
11
+ <input type="radio" class="ai1wm-flat-radio-button ai1wm-feedback-type" id="ai1wm-feedback-type-2" name="ai1wm_feedback_type" value="suggestions" />
12
  <label for="ai1wm-feedback-type-2">
13
  <i></i>
14
  <span><?php _e( 'I have ideas to improve this plugin', AI1WM_PLUGIN_NAME ); ?></span>
15
  </label>
16
  </li>
17
  <li>
18
+ <input type="radio" class="ai1wm-flat-radio-button ai1wm-feedback-type" id="ai1wm-feedback-type-3" name="ai1wm_feedback_type" value="help-needed" />
19
  <label for="ai1wm-feedback-type-3">
20
  <i></i>
21
  <span><?php _e( 'I need help with this plugin', AI1WM_PLUGIN_NAME ); ?></span>
lib/view/export/advanced-settings.php CHANGED
@@ -64,6 +64,8 @@
64
  <label for="ai1wm-no-email-replace"><?php _e( 'Do <strong>not</strong> replace email domain (sql)', AI1WM_PLUGIN_NAME ); ?></label>
65
  <small style="color:red"><?php _e( 'new', AI1WM_PLUGIN_NAME ); ?></small>
66
  </li>
 
 
67
  </ul>
68
  </div>
69
  </div>
64
  <label for="ai1wm-no-email-replace"><?php _e( 'Do <strong>not</strong> replace email domain (sql)', AI1WM_PLUGIN_NAME ); ?></label>
65
  <small style="color:red"><?php _e( 'new', AI1WM_PLUGIN_NAME ); ?></small>
66
  </li>
67
+
68
+ <?php do_action( 'ai1wm_export_advanced_settings' ); ?>
69
  </ul>
70
  </div>
71
  </div>
lib/view/export/index.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
lib/view/import/index.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
loader.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
@@ -154,6 +154,12 @@ require_once AI1WM_VENDOR_PATH .
154
  DIRECTORY_SEPARATOR .
155
  'class-ai1wm-database-utility.php';
156
 
 
 
 
 
 
 
157
  require_once AI1WM_CONTROLLER_PATH .
158
  DIRECTORY_SEPARATOR .
159
  'class-ai1wm-main-controller.php';
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
154
  DIRECTORY_SEPARATOR .
155
  'class-ai1wm-database-utility.php';
156
 
157
+ require_once AI1WM_VENDOR_PATH .
158
+ DIRECTORY_SEPARATOR .
159
+ 'math' .
160
+ DIRECTORY_SEPARATOR .
161
+ 'BigInteger.php';
162
+
163
  require_once AI1WM_CONTROLLER_PATH .
164
  DIRECTORY_SEPARATOR .
165
  'class-ai1wm-main-controller.php';
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: yani.iliev, bangelov, pimjitsawang
3
  Tags: db migration, migration, wordpress migration, db backup, db restore, website backup, website restore, website migration, website deploy, wordpress deploy, db backup, database export, database serialization, database find replace
4
  Requires at least: 3.3
5
  Tested up to: 4.7
6
- Stable tag: 6.39
7
  License: GPLv2 or later
8
 
9
  All-in-One WP Migration is the only tool that you will ever need to migrate a WordPress site.
@@ -78,6 +78,14 @@ All in One WP Plugin is the first plugin to offer true mobile experience on Word
78
  3. Plugin Menu
79
 
80
  == Changelog ==
 
 
 
 
 
 
 
 
81
  = 6.39 =
82
  * Add support for MariaDB
83
  * Do not include package.json, multisite.json, blogs.json, database.sql and filemap.list files on export
3
  Tags: db migration, migration, wordpress migration, db backup, db restore, website backup, website restore, website migration, website deploy, wordpress deploy, db backup, database export, database serialization, database find replace
4
  Requires at least: 3.3
5
  Tested up to: 4.7
6
+ Stable tag: 6.40
7
  License: GPLv2 or later
8
 
9
  All-in-One WP Migration is the only tool that you will ever need to migrate a WordPress site.
78
  3. Plugin Menu
79
 
80
  == Changelog ==
81
+ = 6.40 =
82
+ * Do not extract dropins files on import
83
+ * Fix an issue with large files on import
84
+ * Fix an issue with inactive plugins option in advanced settings on export
85
+ * Do not exclude active plugins in package.json and multisite.json on export
86
+ * Do not show "Resolving URL address..." on export/import
87
+ * Add separate action hook in advanced settings called "ai1wm_export_advanced_settings" to allow custom checkbox options on export
88
+
89
  = 6.39 =
90
  * Add support for MariaDB
91
  * Do not include package.json, multisite.json, blogs.json, database.sql and filemap.list files on export
uninstall.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Copyright (C) 2014-2016 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by
1
  <?php
2
  /**
3
+ * Copyright (C) 2014-2017 ServMask Inc.
4
  *
5
  * This program is free software: you can redistribute it and/or modify
6
  * it under the terms of the GNU General Public License as published by