PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/load-scripts.php

https://gitlab.com/Gashler/dp
PHP | 162 lines | 67 code | 35 blank | 60 comment | 19 complexity | 5d28692c60cdcce6c2492fd94fdcb1eb MD5 | raw file
  1. <?php
  2. /**
  3. * Disable error reporting
  4. *
  5. * Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) for debugging
  6. */
  7. error_reporting(0);
  8. /** Set ABSPATH for execution */
  9. define( 'ABSPATH', dirname(dirname(__FILE__)) . '/' );
  10. define( 'WPINC', 'wp-includes' );
  11. /**
  12. * @ignore
  13. */
  14. function __() {}
  15. /**
  16. * @ignore
  17. */
  18. function _x() {}
  19. /**
  20. * @ignore
  21. */
  22. function add_filter() {}
  23. /**
  24. * @ignore
  25. */
  26. function esc_attr() {}
  27. /**
  28. * @ignore
  29. */
  30. function apply_filters() {}
  31. /**
  32. * @ignore
  33. */
  34. function get_option() {}
  35. /**
  36. * @ignore
  37. */
  38. function is_lighttpd_before_150() {}
  39. /**
  40. * @ignore
  41. */
  42. function add_action() {}
  43. /**
  44. * @ignore
  45. */
  46. function did_action() {}
  47. /**
  48. * @ignore
  49. */
  50. function do_action_ref_array() {}
  51. /**
  52. * @ignore
  53. */
  54. function get_bloginfo() {}
  55. /**
  56. * @ignore
  57. */
  58. function is_admin() {return true;}
  59. /**
  60. * @ignore
  61. */
  62. function site_url() {}
  63. /**
  64. * @ignore
  65. */
  66. function admin_url() {}
  67. /**
  68. * @ignore
  69. */
  70. function home_url() {}
  71. /**
  72. * @ignore
  73. */
  74. function includes_url() {}
  75. /**
  76. * @ignore
  77. */
  78. function wp_guess_url() {}
  79. if ( ! function_exists( 'json_encode' ) ) :
  80. /**
  81. * @ignore
  82. */
  83. function json_encode() {}
  84. endif;
  85. function get_file($path) {
  86. if ( function_exists('realpath') )
  87. $path = realpath($path);
  88. if ( ! $path || ! @is_file($path) )
  89. return '';
  90. return @file_get_contents($path);
  91. }
  92. $load = $_GET['load'];
  93. if ( is_array( $load ) )
  94. $load = implode( '', $load );
  95. $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
  96. $load = array_unique( explode( ',', $load ) );
  97. if ( empty($load) )
  98. exit;
  99. require(ABSPATH . WPINC . '/script-loader.php');
  100. require(ABSPATH . WPINC . '/version.php');
  101. $compress = ( isset($_GET['c']) && $_GET['c'] );
  102. $force_gzip = ( $compress && 'gzip' == $_GET['c'] );
  103. $expires_offset = 31536000; // 1 year
  104. $out = '';
  105. $wp_scripts = new WP_Scripts();
  106. wp_default_scripts($wp_scripts);
  107. foreach( $load as $handle ) {
  108. if ( !array_key_exists($handle, $wp_scripts->registered) )
  109. continue;
  110. $path = ABSPATH . $wp_scripts->registered[$handle]->src;
  111. $out .= get_file($path) . "\n";
  112. }
  113. header('Content-Type: application/x-javascript; charset=UTF-8');
  114. header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
  115. header("Cache-Control: public, max-age=$expires_offset");
  116. if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) {
  117. header('Vary: Accept-Encoding'); // Handle proxies
  118. if ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
  119. header('Content-Encoding: deflate');
  120. $out = gzdeflate( $out, 3 );
  121. } elseif ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) {
  122. header('Content-Encoding: gzip');
  123. $out = gzencode( $out, 3 );
  124. }
  125. }
  126. echo $out;
  127. exit;