暂无描述

Ajax.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * AJAX Initialization & Helper Functions
  4. *
  5. * @since 1.4
  6. * @package PUM
  7. * @subpackage PUM/includes
  8. * @author Daniel Iser <danieliser@wizardinternetsolutions.com>
  9. * @copyright Copyright (c) 2019, Code Atlantic LLC
  10. * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
  11. */
  12. // Exit if accessed directly
  13. if ( ! defined( 'ABSPATH' ) ) {
  14. exit;
  15. }
  16. /**
  17. * Controls the basic analytics methods for Popup Maker
  18. *
  19. */
  20. class PUM_Ajax {
  21. /**
  22. * Creates and returns a 1x1 tracking gif to the browser.
  23. */
  24. public static function serve_pixel() {
  25. $gif = PUM_Ajax::get_file( POPMAKE_DIR . 'assets/images/beacon.gif' );
  26. header( 'Content-Type: image/gif' );
  27. header( 'Content-Length: ' . strlen( $gif ) );
  28. exit( $gif );
  29. }
  30. public static function get_file( $path ) {
  31. if ( function_exists( 'realpath' ) ) {
  32. $path = realpath( $path );
  33. }
  34. if ( ! $path || ! @is_file( $path ) ) {
  35. return '';
  36. }
  37. return @file_get_contents( $path );
  38. }
  39. /**
  40. * Returns a 204 no content header.
  41. */
  42. public static function serve_no_content() {
  43. header( "HTTP/1.0 204 No Content" );
  44. header( 'Content-Type: image/gif' );
  45. header( 'Content-Length: 0' );
  46. exit;
  47. }
  48. /**
  49. * Serves a proper json response.
  50. *
  51. * @param mixed $data
  52. */
  53. public static function serve_json( $data = 0 ) {
  54. header( 'Content-Type: application/json' );
  55. echo PUM_Utils_Array::safe_json_encode( $data );
  56. exit;
  57. }
  58. }