*/ class Adfoxly { /** * The loader that's responsible for maintaining and registering all hooks that power * the plugin. * * @since 1.0.0 * @access protected * @var adfoxly_Loader $loader Maintains and registers all hooks for the plugin. */ protected $loader ; /** * The unique identifier of this plugin. * * @since 1.0.0 * @access protected * @var string $plugin_name The string used to uniquely identify this plugin. */ protected $plugin_name ; /** * The current version of the plugin. * * @since 1.0.0 * @access protected * @var string $version The current version of the plugin. */ protected $version ; protected $custom_url ; /** * Define the core functionality of the plugin. * * Set the plugin name and the plugin version that can be used throughout the plugin. * Load the dependencies, define the locale, and set the hooks for the admin area and * the public-facing side of the site. * * @since 1.0.0 */ public function __construct() { $this->version = ADFOXLY_VERSION; $this->plugin_name = 'adfoxly'; $this->custom_url = 'rdir-adfoxly'; $this->load_dependencies(); $this->set_locale(); $this->define_admin_hooks(); $this->define_public_hooks(); global $wp ; /** * redirecting init */ add_action( 'init', array( &$this, 'register_tags' ) ); add_action( 'wp_head', array( &$this, 'adfoxly_flush_rules' ) ); add_action( 'template_redirect', array( &$this, 'redirect' ) ); /** * shortcodes */ add_shortcode( 'adfoxly', array( &$this, 'adfoxly_shortcodes' ) ); add_filter( 'the_content', array( &$this, 'adfoxly_content' ) ); add_filter( 'admin_notices', array( &$this, 'adfoxly_admin_notice__success' ) ); add_action( 'wp_head', array( &$this, 'adfoxly_ajaxurl' ) ); $places = new PlacesController(); if ( !empty($places->getBannersByPlace( 1 )) ) { add_action( 'wp_footer', function () { $places = new PlacesController(); $popupPlace = $places->renderPlace( 1 ); ?> var adfoxlyAjax = {"ajax_url":"\\/wp-admin\\/admin-ajax.php"}; ' ; } static function adfoxly_admin_notice__success() { /** * todo: developer docs * notice debugger * * @param ?notice=show */ if ( isset( $_GET['notice'] ) && $_GET['notice'] === 'show' ) { ?>

loader = new adfoxly_Loader(); } /** * Define the locale for this plugin for internationalization. * * Uses the adfoxly_i18n class in order to set the domain and to register the hook * with WordPress. * * @since 1.0.0 * @access private */ private function set_locale() { $plugin_i18n = new adfoxly_i18n(); $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_adfoxly' ); } /** * Register all of the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { $plugin_admin = new adfoxly_Admin( $this->get_plugin_name(), $this->get_version() ); $server_request_uri = $_SERVER['REQUEST_URI']; if ( strpos( $server_request_uri, 'adfoxly' ) !== false && strpos( $server_request_uri, 'adfoxly-account' ) !== 25 ) { $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles', 0 ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts', 1 ); $this->loader->add_action( 'admin_body_class', $plugin_admin, 'add_admin_adfoxly_body_classes', 0 ); } $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'dashboard_enqueue_styles', 0 ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'adfoxly_analytics_inline_enqueue_script', 0 ); } /** * Register all of the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_public_hooks() { $plugin_public = new adfoxly_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); // add_filter( 'body_class', array( &$this, 'background_ads' ), 9999 ); } static function background_ads( $classes ) { /* * Background **/ $adzonesFromPlacesBackgroundArgs = array( 'meta_query' => array( array( 'key' => 'adfoxly-adzone-place', 'value' => sprintf( ':"%s";', 6 ), 'compare' => 'LIKE', ), array( 'relation' => 'OR', array( array( 'key' => 'adfoxly-ad-campaign-start', 'compare' => 'NOT EXISTS', ), array( 'key' => 'adfoxly-ad-campaign-end', 'compare' => 'NOT EXISTS', ) ), array( array( 'key' => 'adfoxly-ad-campaign-start', 'value' => date( "Y-m-d" ), 'compare' => '<=', 'type' => 'DATE', ), array( 'key' => 'adfoxly-ad-campaign-end', 'value' => date( "Y-m-d" ), 'compare' => '>=', 'type' => 'DATE', ) ), ) ), 'post_type' => 'adfoxly_banners', 'posts_per_page' => -1, ); $adzonesFromPlacesBackground = get_posts( $adzonesFromPlacesBackgroundArgs ); $bannerBackgroundArgs = array( 'meta_query' => array( array( 'key' => 'adfoxly-adzone', 'value' => $adzonesFromPlacesBackground[0]->ID, ) ), 'post_type' => 'adfoxly_banners', 'posts_per_page' => -1, ); $bannerBackground = get_posts( $bannerBackgroundArgs ); $img_url = get_post_meta( $bannerBackground[0]->ID, 'adfoxly-image', true ); if ( !empty($img_url) ) { $classes[] = '" style="background-repeat: repeat; background-size: inherit; background-image: url(' . $img_url . ')'; } return $classes; } /** * Run the loader to execute all of the hooks with WordPress. * * @since 1.0.0 */ public function run() { $this->loader->run(); } /** * The name of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. * * @since 1.0.0 * @return string The name of the plugin. */ public function get_plugin_name() { return $this->plugin_name; } /** * The reference to the class that orchestrates the hooks with the plugin. * * @since 1.0.0 * @return adfoxly_Loader Orchestrates the hooks of the plugin. */ public function get_loader() { return $this->loader; } /** * Retrieve the version number of the plugin. * * @since 1.0.0 * @return string The version number of the plugin. */ public function get_version() { return $this->version; } static function adfoxly_shortcodes( $attr = "" ) { if ( isset( $attr['group'] ) && !empty($attr['group']) ) { $groups = new GroupController(); return $groups->renderGroup( $attr['group'] ); } else { if ( isset( $attr['id'] ) && !empty($attr['id']) ) { $places = new PlacesController(); return $places->renderPlace( $attr['id'] ); } } } public function register_tags() { $settings = get_option( 'adfoxly_settings' ); if ( isset( $settings['redirect-slug'] ) && !empty($settings['redirect-slug']) ) { $this->custom_url = $settings['redirect-slug']; } $custom_url = $this->custom_url; add_rewrite_rule( $custom_url . '/([^/]*)', 'index.php?' . $custom_url . '=$matches[1]', 'top' ); add_rewrite_tag( '%' . $custom_url . '%', '([^&]+)' ); } public function adfoxly_flush_rules() { global $wp_rewrite ; if ( $wp_rewrite->rules && !array_key_exists( $this->custom_url . '/([^/]*)', $wp_rewrite->rules ) ) { $wp_rewrite->flush_rules(); } } public function redirect() { global $wp_query ; if ( isset( $wp_query->query_vars[$this->custom_url] ) ) { $id = $wp_query->query_vars[$this->custom_url]; $this->parse_redirect( $id ); } } public function parse_redirect( $id ) { $result = get_post_meta( $id, 'adfoxly-target-url', true ); if ( $result && is_numeric( $id ) ) { global $wpdb ; $dbStatisitcs = $wpdb->prefix . 'adfoxly_statistics' . '_clicks'; $wpdb->insert( $dbStatisitcs, array( 'id' => null, 'banner_id' => $id, 'date' => date( "Y-m-d H:i:s" ), 'fingerprint' => $this->getFingerPrint(), ) ); /* * add here google analytics condition * if ga than send to ga and use js redirect * if else try wp_redirect */ if ( 1 !== 1 ) { // js code here } else { wp_redirect( $result ); } } else { wp_redirect( get_home_url() ); } exit; } public function getFingerPrint() { $ip = Adfoxly::ip(); $browser = $_SERVER['HTTP_USER_AGENT']; $language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; $fingerprint = "{$ip} + {$browser} + {$language}"; return md5( $fingerprint ); } static function ip() { $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = $_SERVER['REMOTE_ADDR']; if ( filter_var( $client, FILTER_VALIDATE_IP ) ) { $ip = $client; } else { if ( filter_var( $forward, FILTER_VALIDATE_IP ) ) { $ip = $forward; } else { $ip = $remote; } } if ( 1 === 2 ) { return $ip; } $ipAnonymizer = new IpAnonymizer(); return $ipAnonymizer->anonymize( $ip ); } static function adfoxly_content( $content ) { $places = new PlacesController(); $textAdsList = array( 'meta_query' => array( array( 'key' => 'adfoxly_type_of_ad', 'value' => 'text', ) ), 'post_type' => 'adfoxly_banners', 'posts_per_page' => -1, ); if ( isset( $textAdsList ) && !empty($textAdsList) ) { $textAds = get_posts( $textAdsList ); } if ( is_single() ) { if ( !empty($places->getBannersByPlace( 4 )) || !empty($places->getBannersByPlace( 3 )) || !empty($places->getBannersByPlace( 5 )) ) { $custom_content = null; $new_content = null; if ( !empty($places->getBannersByPlace( 3 )) ) { $places = new PlacesController(); $new_content .= $places->renderPlace( 3 ); } if ( !empty($places->getBannersByPlace( 5 )) ) { $paragraphs = explode( '

', $content ); $paragraph_count = count( $paragraphs ); $paragraph_parts = ceil( ($paragraph_count - 1) / 2 ); foreach ( $paragraphs as $index => $paragraph ) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= '

'; } $custom_content .= $paragraphs[$index]; if ( $index + 1 == $paragraph_parts ) { $places = new PlacesController(); $custom_content .= $places->renderPlace( 5 ); } } $new_content .= $custom_content; } else { $new_content .= $content; } foreach ( $textAds as $ads ) { $metaTextAds = get_post_meta( $ads->ID ); if ( !empty($metaTextAds['adfoxly-text-to-link'][0]) ) { if ( !empty($metaTextAds['adfoxly-image']) ) { $new_content = str_replace( $metaTextAds['adfoxly-text-to-link'][0], "ID . "' target='_blank' class='tooltip-ad' style='border-bottom: 1px dotted black;'>" . $metaTextAds['adfoxly-text-to-link'][0] . "", $new_content ); } else { $new_content = str_replace( $metaTextAds['adfoxly-text-to-link'][0], "ID . "' target='_blank'>" . $metaTextAds['adfoxly-text-to-link'][0] . "", $new_content ); } } } if ( !empty($places->getBannersByPlace( 4 )) ) { $places = new PlacesController(); $new_content .= $places->renderPlace( 4 ); } return $new_content; } else { return $content; } } else { return $content; } } static function adfoxly_custom_url() { $custom_url = 'rdir-adfoxly'; $settings = get_option( 'adfoxly_settings' ); if ( isset( $settings['redirect-slug'] ) && !empty($settings['redirect-slug']) ) { $custom_url = $settings['redirect-slug']; } return $custom_url; } }