ad-ajax.php
11 years ago
ad-model.php
11 years ago
ad-select.php
11 years ago
ad.php
11 years ago
ad_ajax_callbacks.php
11 years ago
ad_group.php
11 years ago
ad_placements.php
11 years ago
ad_type_abstract.php
11 years ago
ad_type_content.php
11 years ago
ad_type_plain.php
11 years ago
plugin.php
11 years ago
widget.php
11 years ago
ad-ajax.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Provide public ajax interface. |
| 5 | * |
| 6 | * @since 1.5.0 |
| 7 | */ |
| 8 | class Advanced_Ads_Ajax { |
| 9 | |
| 10 | private function __construct() |
| 11 | { |
| 12 | add_action( 'wp_ajax_advads_ad_select', array( $this, 'advads_ajax_ad_select' ) ); |
| 13 | add_action( 'wp_ajax_nopriv_advads_ad_select', array( $this, 'advads_ajax_ad_select' ) ); |
| 14 | } |
| 15 | |
| 16 | private static $instance; |
| 17 | |
| 18 | public static function get_instance() |
| 19 | { |
| 20 | if ( ! isset(self::$instance) ) { |
| 21 | self::$instance = new self; |
| 22 | } |
| 23 | |
| 24 | return self::$instance; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Simple wp ajax interface for ad selection. |
| 29 | * |
| 30 | * Provides a single ad given ID and selection method. |
| 31 | */ |
| 32 | public function advads_ajax_ad_select() { |
| 33 | // set proper header |
| 34 | header( 'Content-Type: application/json; charset: utf-8' ); |
| 35 | |
| 36 | // init handlers |
| 37 | $selector = Advanced_Ads_Select::get_instance(); |
| 38 | $methods = $selector->get_methods(); |
| 39 | $method = isset( $_REQUEST['ad_method'] ) ? (string) $_REQUEST['ad_method'] : null; |
| 40 | $id = isset( $_REQUEST['ad_id'] ) ? (string) $_REQUEST['ad_id'] : null; |
| 41 | $arguments = isset( $_REQUEST['ad_args'] ) ? (array) $_REQUEST['ad_args'] : array(); |
| 42 | |
| 43 | $response = array(); |
| 44 | if ( isset( $methods[ $method ] ) && isset( $id ) ) { |
| 45 | $content = $selector->get_ad_by_method( $id, $method, $arguments ); |
| 46 | $response = array( 'status' => 'success', 'item' => $content, 'id' => $id, 'method' => $method ); |
| 47 | } else { |
| 48 | // report error |
| 49 | $response = array( 'status' => 'error', 'message' => 'No valid ID or METHOD found.' ); |
| 50 | } |
| 51 | |
| 52 | echo json_encode( $response ); |
| 53 | die(); |
| 54 | } |
| 55 | } |
| 56 |