Advertisement
Guest User

wp-quiz-pro.php

a guest
Jun 19th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 46.19 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: Testes Pop
  4.  * Plugin URI:  https://testespop.com.br
  5.  * Description: O TestesPop permite que você adicione facilmente testes para o facebook, ágeis e modernos ao seu site ou blog! Aumente o engajamento e os compartilhamentos enquanto fatura continuamente.
  6.  * Version:     1.1.1
  7.  * Author:      TestesPop
  8.  * Author URI:  http://testespop.com.br
  9.  *
  10.  * Text Domain: testes-pop
  11.  * Domain Path: /languages/
  12.  */
  13.  
  14. if ( ! defined( 'ABSPATH' ) ) {
  15.     exit; // disable direct access
  16. }
  17.  
  18. if ( ! class_exists( 'WP_Quiz_Pro_Plugin' ) ) :
  19.  
  20.     /**
  21.      * Register the plugin.
  22.      *
  23.      * Display the administration panel, insert JavaScript etc.
  24.      */
  25.     class WP_Quiz_Pro_Plugin {
  26.  
  27.         /**
  28.          * Hold plugin version
  29.          *
  30.          * @var string
  31.          */
  32.         public $version = '1.1.1';
  33.  
  34.         /**
  35.          * Hold an instance of WP_Quiz_Pro_Plugin class.
  36.          *
  37.          * @var WP_Quiz_Pro_Plugin
  38.          */
  39.         protected static $instance = null;
  40.  
  41.         /**
  42.          * Hold the current quiz instance
  43.          *
  44.          * @var WP_Quiz_Pro
  45.          */
  46.         public $quiz = null;
  47.  
  48.         /**
  49.          * Main WP_Quiz_Pro_Plugin instance.
  50.          * @return WP_Quiz_Pro_Plugin - Main instance.
  51.          */
  52.         public static function get_instance() {
  53.  
  54.             if ( is_null( self::$instance ) ) {
  55.                 self::$instance = new WP_Quiz_Pro_Plugin;
  56.             }
  57.  
  58.             return self::$instance;
  59.         }
  60.         /**
  61.          * You cannot clone this class.
  62.          */
  63.         public function __clone() {
  64.             _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'wp-quiz-pro' ), $this->version );
  65.         }
  66.  
  67.         /**
  68.          * You cannot unserialize instances of this class.
  69.          */
  70.         public function __wakeup() {
  71.             _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'wp-quiz-pro' ), $this->version );
  72.         }
  73.  
  74.         /**
  75.          * The Constructor
  76.          */
  77.         private function __construct() {
  78.  
  79.             $this->define_constants();
  80.             $this->includes();
  81.             $this->hooks();
  82.             $this->setup_shortcode();
  83.         }
  84.  
  85.         /**
  86.          * Define WP Quiz constants
  87.          */
  88.         private function define_constants() {
  89.  
  90.             define( 'WP_QUIZ_PRO_VERSION',    $this->version );
  91.             define( 'WP_QUIZ_PRO_BASE_URL',   trailingslashit( plugins_url( 'wp-quiz-pro' ) ) );
  92.             define( 'WP_QUIZ_PRO_ASSETS_URL', trailingslashit( WP_QUIZ_PRO_BASE_URL . 'assets' ) );
  93.             define( 'WP_QUIZ_PRO_PATH',       plugin_dir_path( __FILE__ ) );
  94.         }
  95.  
  96.         /**
  97.          * Load required classes
  98.          */
  99.         private function includes() {
  100.  
  101.             // Auto loader
  102.             spl_autoload_register( array( $this, 'autoloader' ) );
  103.  
  104.             new WP_Quiz_Pro_Admin;
  105.         }
  106.  
  107.         /**
  108.          * Autoload classes
  109.          */
  110.         public function autoloader( $class ) {
  111.  
  112.             $dir = WP_QUIZ_PRO_PATH . 'inc' . DIRECTORY_SEPARATOR;
  113.             $class_file_name = 'class-' . str_replace( array( 'wp_quiz_pro_', '_' ), array( '', '-' ), strtolower( $class ) ) . '.php';
  114.             if ( file_exists( $dir . $class_file_name ) ) {
  115.                 require $dir . $class_file_name;
  116.             }
  117.         }
  118.  
  119.         /**
  120.          * Register the [wp_quiz_pro] shortcode.
  121.          */
  122.         private function setup_shortcode() {
  123.  
  124.             add_shortcode( 'wp_quiz_pro', array( $this, 'register_shortcode' ) );
  125.         }
  126.  
  127.         /**
  128.          * Hook WP Quiz into WordPress
  129.          */
  130.         private function hooks() {
  131.  
  132.             // Common
  133.             add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
  134.             add_action( 'init', array( $this, 'register_post_type' ) );
  135.             add_action( 'init', array( $this, 'embeded_output' ) );
  136.  
  137.             // Frontend
  138.             add_action( 'wp_head', array( $this, 'inline_script' ), 1 );
  139.             add_filter( 'the_content', array( $this, 'create_quiz_page' ) );
  140.  
  141.             // Ajax
  142.             add_action( 'wp_ajax_wq_quizResults', array( $this, 'save_quiz_results' ) );
  143.             add_action( 'wp_ajax_nopriv_wq_quizResults', array( $this, 'save_quiz_results' ) );
  144.  
  145.             add_action( 'wp_ajax_wq_submitInfo', array( $this, 'save_quiz_user_info' ) );
  146.             add_action( 'wp_ajax_nopriv_wq_submitInfo', array( $this, 'save_quiz_user_info' ) );
  147.  
  148.             add_action( 'wp_ajax_wq_submitFbInfo', array( $this, 'save_quiz_fb_user_info' ) );
  149.             add_action( 'wp_ajax_nopriv_wq_submitFbInfo', array( $this, 'save_quiz_fb_user_info' ) );
  150.  
  151.             add_action( 'wp_ajax_check_image_file', array( $this, 'check_image_file' ) );
  152.             add_action( 'wp_ajax_check_video_file', array( $this, 'check_video_file' ) );
  153.             add_action( 'wp_ajax_dismiss_imagick_notice', array( $this, 'dismiss_imagick_notice' ) );
  154.             add_action( 'wp_ajax_dismiss_gdlibrary_notice', array( $this, 'dismiss_gdlibrary_notice' ) );
  155.             add_action( 'wp_ajax_wpquiz_get_debug_log', array( $this, 'wp_quiz_pro_get_debug_log' ) );
  156.  
  157.             add_action( 'wp_ajax_connect_aweber', array( $this, 'connect_aweber' ) );
  158.  
  159.             // FB SDK version 2.9 fix
  160.             if ( isset( $_GET['fbs'] ) && ! empty( $_GET['fbs'] ) ) {
  161.                 add_action( 'template_redirect', array( $this, 'fb_share_fix' ) );
  162.             }
  163.         }
  164.  
  165.         /**
  166.          * Initialise translations
  167.          */
  168.         public function load_plugin_textdomain() {
  169.  
  170.             load_plugin_textdomain( 'wp-quiz-pro', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  171.         }
  172.  
  173.         /**
  174.          * Register Quiz post type
  175.          */
  176.         public function register_post_type() {
  177.  
  178.             $labels = array(
  179.                 'name'               => __( 'Testes Pop', 'wp-quiz-pro' ),
  180.                 'menu_name'          => __( 'Testes Pop', 'wp-quiz-pro' ),
  181.                 'singular_name'      => __( 'TP WP', 'wp-quiz-pro' ),
  182.                 'name_admin_bar'     => _x( 'Testes Pop', 'name admin bar', 'wp-quiz-pro' ),
  183.                 'all_items'          => __( 'Todos os testes', 'wp-quiz-pro' ),
  184.                 'search_items'       => __( 'Procurar teste', 'wp-quiz-pro' ),
  185.                 'add_new'            => _x( 'Adicionar', 'quiz', 'wp-quiz-pro' ),
  186.                 'add_new_item'       => __( 'Adicionar novo teste', 'wp-quiz-pro' ),
  187.                 'new_item'           => __( 'Novo testes', 'wp-quiz-pro' ),
  188.                 'view_item'          => __( 'Ver teste', 'wp-quiz-pro' ),
  189.                 'edit_item'          => __( 'Editar teste', 'wp-quiz-pro' ),
  190.                 'not_found'          => __( 'Nenhum teste encontrado.', 'wp-quiz-pro' ),
  191.                 'not_found_in_trash' => __( 'Nenhum teste encontrado na lixeira.', 'wp-quiz-pro' ),
  192.                 'parent_item_colon'  => __( 'Teste pai', 'wp-quiz-pro' ),
  193.             );
  194.  
  195.             $args = array(
  196.                 'labels'             => $labels,
  197.                 'description'        => __( 'Mantém os testes e seus dados.', 'wp-quiz-pro' ),
  198.                 'menu_position'      => 5,
  199.                 'menu_icon'          => 'dashicons-editor-help',
  200.                 'public'             => true,
  201.                 'publicly_queryable' => true,
  202.                 'show_ui'            => true,
  203.                 'show_in_menu'       => true,
  204.                 'query_var'          => true,
  205.                 'capability_type'    => 'post',
  206.                 'has_archive'        => true,
  207.                 'hierarchical'       => false,
  208.                 'supports'           => array( 'title', 'author', 'thumbnail', 'excerpt' ),
  209.             );
  210.  
  211.             register_post_type( 'wp_quiz', $args );
  212.  
  213.             if ( false === get_option( 'wp_quiz_pro_version' ) ) {
  214.                 flush_rewrite_rules();
  215.                 update_option( 'wp_quiz_pro_version', WP_QUIZ_PRO_VERSION );
  216.             }
  217.         }
  218.  
  219.         /**
  220.          * Shortcode used to display quiz
  221.          *
  222.          * @return string HTML output of the shortcode
  223.          */
  224.         public function register_shortcode( $atts ) {
  225.  
  226.             if ( ! isset( $atts['id'] ) ) {
  227.                 return false;
  228.             }
  229.  
  230.             // we have an ID to work with
  231.             $quiz = get_post( $atts['id'] );
  232.  
  233.             // check if ID is correct
  234.             if ( ! $quiz || 'wp_quiz' !== $quiz->post_type ) {
  235.                 return "<!-- wp_quiz {$atts['id']} not found -->";
  236.             }
  237.  
  238.             // lets go
  239.             $this->set_quiz( $atts['id'] );
  240.             $this->quiz->enqueue_scripts();
  241.  
  242.             return $this->quiz->render_public_quiz();
  243.         }
  244.  
  245.         /**
  246.          * Set the current quiz
  247.          */
  248.         public function set_quiz( $id ) {
  249.             $quiz_type = get_post_meta( $id, 'quiz_type', true );
  250.             $quiz_type = str_replace( '_quiz', '', $quiz_type );
  251.             $quiz_type = 'WP_Quiz_Pro_' . ucwords( $quiz_type ) . '_Quiz';
  252.             $this->quiz = new $quiz_type( $id );
  253.         }
  254.  
  255.         /**
  256.          * [create_quiz_page description]
  257.          * @param  [type] $content [description]
  258.          * @return [type]          [description]
  259.          */
  260.         public function create_quiz_page( $content ) {
  261.  
  262.             global $post;
  263.  
  264.             if ( 'wp_quiz' !== $post->post_type ) {
  265.                 return $content;
  266.             }
  267.  
  268.             if ( ! is_single() ) {
  269.                 return $content;
  270.             }
  271.  
  272.             $quiz_html = $this->register_shortcode( array( 'id' => $post->ID ) );
  273.  
  274.             return $quiz_html . $content;
  275.         }
  276.  
  277.         /**
  278.          * [save_quiz_results description]
  279.          * @return [type] [description]
  280.          */
  281.         public function save_quiz_results() {
  282.  
  283.             if ( ! wp_verify_nonce( $_POST['_nonce'], 'ajax-quiz-content' ) ) {
  284.                 return;
  285.             }
  286.  
  287.             $correct   = isset( $_POST['correct'] ) ? absint( $_POST['correct'] ) : 0;
  288.             $rid       = isset( $_POST['rid'] ) ? $_POST['rid'] : '';
  289.             $pid       = absint( $_POST['pid'] );
  290.             $type      = sanitize_text_field( $_POST['type'] );
  291.             $user_ip   = $this->get_ip();
  292.             $user_id   = get_current_user_id();
  293.             $user_info = get_userdata( $user_id );
  294.             $username  = is_user_logged_in() ? $user_info->user_login : 'Guest';
  295.             $result    = '';
  296.  
  297.             $results = get_post_meta( $pid, 'results', true );
  298.  
  299.             if ( 'trivia' === $type ) {
  300.                 $rid = '';
  301.                 foreach ( $results as $result ) {
  302.                     if ( $result['min'] <= $correct && $result['max'] >= $correct ) {
  303.                         $result = $result['title'];
  304.                         break;
  305.                     }
  306.                 }
  307.             } else if ( 'personality' === $type ) {
  308.                 for ( $i = 0; $i < count( $results ); $i++ ) {
  309.                     if ( $i == $rid ) {
  310.                         $result = $results[ $i ]['title'];
  311.                         break;
  312.                     }
  313.                 }
  314.             } else if ( 'swiper' === $type ) {
  315.                 $results = $_POST['results'];
  316.                 $questions  = get_post_meta( $pid, 'questions', true );
  317.                 foreach ( $questions as $q_key => $question ) {
  318.                     foreach ( $results as $key => $result ) {
  319.                         if ( $question['uid'] == $key ) {
  320.                             if ( '0' == $result ) {
  321.                                 $questions[ $q_key ]['votesDown'] = $question['votesDown'] + 1;
  322.                             } else {
  323.                                 $questions[ $q_key ]['votesUp'] = $question['votesUp'] + 1;
  324.                             }
  325.                         }
  326.                     }
  327.                 }
  328.                 update_post_meta( $pid, 'questions', $questions );
  329.                 $result = '';
  330.             }
  331.  
  332.             // Save Result
  333.             $settings = get_option( 'wp_quiz_pro_default_settings' );
  334.             if ( isset( $settings['players_tracking'] ) && 1 === $settings['players_tracking'] ) {
  335.                 global $wpdb;
  336.                 $wpdb->insert(
  337.                     $wpdb->prefix . 'wp_quiz_players',
  338.                     array(
  339.                         'pid'               => $pid,
  340.                         'date'              => date( 'Y-m-d', time() ),
  341.                         'user_ip'           => $user_ip,
  342.                         'username'          => $username,
  343.                         'correct_answered'  => $correct,
  344.                         'result'            => $result,
  345.                         'quiz_type'         => $type,
  346.                     ),
  347.                     array( '%d', '%s', '%s', '%s', '%d', '%s', '%s' )
  348.                 );
  349.             }
  350.  
  351.             die( 'SUCCESS!' );
  352.         }
  353.  
  354.         /**
  355.          * [save_quiz_user_info description]
  356.          * @return [type] [description]
  357.          */
  358.         public function save_quiz_user_info() {
  359.  
  360.             if ( ! wp_verify_nonce( $_POST['_nonce'], 'ajax-quiz-content' ) ) {
  361.                 return;
  362.             }
  363.  
  364.             $output = array( 'status' => 1 );
  365.  
  366.             if ( is_email( $_POST['email'] ) ) {
  367.  
  368.                 global $wpdb;
  369.                 $username   = sanitize_text_field( $_POST['username'] );
  370.                 $email      = sanitize_email( $_POST['email'] );
  371.                 $pid        = absint( $_POST['pid'] );
  372.  
  373.                 $this->subscribe_user( $pid, $username, $email );
  374.                 $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wp_quiz_emails WHERE email = '" . $email . "'" );
  375.  
  376.                 if ( ! $result ) {
  377.                     //Save info
  378.                     $wpdb->insert(
  379.                         $wpdb->prefix . 'wp_quiz_emails',
  380.                         array(
  381.                             'pid'      => $pid,
  382.                             'username' => $username,
  383.                             'email'    => $email,
  384.                             'date'     => date( 'Y-m-d', time() ),
  385.                         ),
  386.                         array( '%d', '%s', '%s', '%s' )
  387.                     );
  388.                 }
  389.  
  390.                 $output['status'] = 2;
  391.             }
  392.  
  393.             wp_send_json( $output );
  394.         }
  395.  
  396.         /**
  397.          * [save_quiz_fb_user_info description]
  398.          * @return [type] [description]
  399.          */
  400.         public function save_quiz_fb_user_info() {
  401.  
  402.             if ( ! wp_verify_nonce( $_POST['_nonce'], 'ajax-quiz-content' ) ) {
  403.                 return;
  404.             }
  405.  
  406.             $output = array( 'status' => 1 );
  407.             if ( ! empty( $_POST['user'] ) ) {
  408.                 global $wpdb;
  409.  
  410.                 $user = $_POST['user'];
  411.                 $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}wp_quiz_fb_users WHERE uid = '" . $user['id'] . "'" );
  412.  
  413.                 if ( ! $result ) {
  414.                     $wpdb->insert(
  415.                         $wpdb->prefix . 'wp_quiz_fb_users',
  416.                         array(
  417.                             'uid'           => absint( $user['id'] ),
  418.                             'email'         => isset( $user['email'] ) ? $user['email'] : '',
  419.                             'first_name'    => $user['first_name'],
  420.                             'last_name'     => $user['last_name'],
  421.                             'gender'        => isset( $user['gender'] ) ? $user['gender'] : '',
  422.                             'picture'       => isset( $user['picture'] ) ? $user['picture'] : '',
  423.                             'friends'       => isset( $user['friends'] ) ? serialize( $user['friends'] ) : '',
  424.                             'created_at'    => date( 'Y-m-d', time() ),
  425.                             'updated_at'    => date( 'Y-m-d', time() ),
  426.                         ),
  427.                         array( '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )
  428.                     );
  429.  
  430.                     $user['insert_id'] = $wpdb->insert_id;
  431.                 } else {
  432.                     $user['insert_id'] = $result->id;
  433.                 }
  434.  
  435.                 if ( 'user' === $_POST['profile'] ) {
  436.                     $return = $this->generate_result_user_image( $_POST['pid'], $user );
  437.                 } else {
  438.                     $return = $this->generate_result_friend_image( $_POST['pid'], $user );
  439.                 }
  440.  
  441.                 if ( ! empty( $return['src'] ) ) {
  442.                     $output['src'] = $return['src'];
  443.                     $output['desc'] = $return['desc'];
  444.                     $output['key'] = $return['key'];
  445.                     $output['status'] = 2;
  446.                 } else {
  447.                     $output['error'] = $return['error'];
  448.                 }
  449.             }
  450.  
  451.             wp_send_json( $output );
  452.         }
  453.  
  454.         /**
  455.          * [generate_result_user_image description]
  456.          * @param  [type] $post_id [description]
  457.          * @param  [type] $user    [description]
  458.          * @return [type]          [description]
  459.          */
  460.         public function generate_result_user_image( $post_id, $user ) {
  461.             global $wpdb;
  462.  
  463.             $return     = array();
  464.             $results    = get_post_meta( $post_id, 'results', true );
  465.  
  466.             if ( extension_loaded( 'imagick' ) && ! empty( $results ) ) {
  467.  
  468.                 $index  = array_rand( $results );
  469.                 $result = $results[ $index ];
  470.                 $result['key'] = $index;
  471.  
  472.                 $play = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}wp_quiz_fb_plays WHERE user_id = '" . $user['insert_id'] . "' AND pid = '" . $post_id . "'" );
  473.  
  474.                 if ( ! $play ) {
  475.                     $wpdb->insert(
  476.                         $wpdb->prefix . 'wp_quiz_fb_plays',
  477.                         array(
  478.                             'user_id'   => absint( $user['insert_id'] ),
  479.                             'pid'       => absint( $post_id ),
  480.                         ),
  481.                         array( '%d', '%d' )
  482.                     );
  483.                 }
  484.  
  485.                 $names = array(
  486.                     'user_first_name'   => $user['first_name'],
  487.                     'user_last_name'    => $user['last_name'],
  488.                     'friend_first_name' => '',
  489.                     'friend_last_name'  => '',
  490.                 );
  491.  
  492.                 $profile = 'https://graph.facebook.com/' . $user['id'] . '/picture?width=320&height=320';
  493.                 $profile = $this->get_redirect_url( $profile );
  494.  
  495.                 $data   = $this->generate_fb_result( $post_id, $result, $profile, $names );
  496.                 $return = $data;
  497.             }
  498.  
  499.             return $return;
  500.         }
  501.  
  502.         public function generate_result_friend_image( $post_id, $user ) {
  503.             global $wpdb;
  504.  
  505.             $return     = array();
  506.             $results    = get_post_meta( $post_id, 'results', true );
  507.  
  508.             if ( extension_loaded( 'imagick' ) && ! empty( $results ) && ! empty( $user['friends'] ) ) {
  509.  
  510.                 $index  = array_rand( $results );
  511.                 $result = $results[ $index ];
  512.                 $result['key'] = $index;
  513.  
  514.                 $index_2    = array_rand( $user['friends'] );
  515.                 $friend     = $user['friends'][ $index_2 ];
  516.  
  517.                 $play = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}wp_quiz_fb_plays WHERE user_id = '" . $user['insert_id'] . "' AND pid = '" . $post_id . "'" );
  518.  
  519.                 if ( ! $play ) {
  520.                     $wpdb->insert(
  521.                         $wpdb->prefix . 'wp_quiz_fb_plays',
  522.                         array(
  523.                             'user_id'   => absint( $user['insert_id'] ),
  524.                             'pid'       => absint( $post_id ),
  525.                         ),
  526.                         array( '%d', '%d' )
  527.                     );
  528.                 }
  529.  
  530.                 $profile = 'https://graph.facebook.com/' . $friend['id'] . '/picture?width=320&height=320';
  531.                 $profile = $this->get_redirect_url( $profile );
  532.  
  533.                 $friend_name = explode( ' ', $friend['name'] );
  534.  
  535.                 $names = array(
  536.                     'user_first_name'   => $user['first_name'],
  537.                     'user_last_name'    => $user['last_name'],
  538.                     'friend_first_name' => $friend_name[0],
  539.                     'friend_last_name'  => $friend_name[1],
  540.                 );
  541.  
  542.                 $data   = $this->generate_fb_result( $post_id, $result, $profile, $names );
  543.                 $return = $data;
  544.             }
  545.  
  546.             return $return;
  547.         }
  548.  
  549.         public function generate_fb_result( $post_id, $result, $profile, $names ) {
  550.  
  551.             $return = array( 'src' => '', 'desc' => '', 'error' => '' );
  552.  
  553.             try {
  554.  
  555.                 $options    = get_option( 'wp_quiz_pro_default_settings' );
  556.                 $settings   = get_post_meta( $post_id, 'settings', true );
  557.                 $find       = array( '%%nomeusuario%%', '%%sobrenome%%', '%%nomeamigo%%', '%%sobrenomeamigo%%' );
  558.                 $replace    = array( $names['user_first_name'], $names['user_last_name'], $names['friend_first_name'], $names['friend_last_name'] );
  559.                 $title      = str_replace( $find, $replace, $result['title'] );
  560.                 $desc       = str_replace( $find, $replace, $result['desc'] );
  561.                 $upload_dir = wp_upload_dir();
  562.  
  563.                 // Load images
  564.                 $profile = new Imagick( $profile );
  565.                 $profile->resizeImage( $result['proImageWidth'], $result['proImageHeight'], imagick::FILTER_LANCZOS, 0.9 );
  566.                 $profile->roundCorners( $result['imageRadius'], $result['imageRadius'] );
  567.  
  568.                 // Create new image from result
  569.                 $output = new Imagick( str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $result['image'] ) );
  570.                 $output->compositeImage( $profile, Imagick::COMPOSITE_DEFAULT, $result['pos_x'], $result['pos_y'] );
  571.  
  572.                 // Annotate it
  573.                 if ( ! empty( $title ) ) {
  574.  
  575.                     $draw = new ImagickDraw();
  576.                     $draw->setFillColor( $settings['title_color'] );
  577.                     $draw->setGravity( 1 );
  578.                     $draw->setFontSize( $settings['title_size'] );
  579.  
  580.                     if ( isset( $options['defaults']['external_font'] ) && ! empty( $options['defaults']['external_font'] ) ) {
  581.                         $external_font = str_replace( home_url('/'), '', $options['defaults']['external_font'] );
  582.                         $draw->setFont( '../' . $external_font );
  583.                     } else {
  584.                         $draw->setFontFamily( $settings['title_font'] );
  585.                     }
  586.  
  587.                     list( $lines, $line_height ) = $this->word_wrap_annotation( $output, $draw, $title, $result['titleImageWidth'] );
  588.  
  589.                     for ( $i = 0; $i < count( $lines ); $i++ ) {
  590.                         $output->annotateImage( $draw, $result['pos_title_x'],  $result['pos_title_y'] + $i * $line_height, 0, $lines[ $i ] );
  591.                     }
  592.                 }
  593.  
  594.                 // Save to new image
  595.                 $upload_dir['basedir'] = $upload_dir['basedir'] . '/wp_quiz-result-images';
  596.                 $upload_dir['baseurl'] = $upload_dir['baseurl'] . '/wp_quiz-result-images';
  597.                 $output_name = 'image-' . rand( 0, 100000 ) . '.png';
  598.                 $output->writeImage(  $upload_dir['basedir'] . '/' . $output_name  );
  599.  
  600.                 // Clean up
  601.                 $profile->destroy();
  602.                 $output->destroy();
  603.  
  604.                 $return['src']  = $upload_dir['baseurl'] . '/' . $output_name;
  605.                 $return['desc'] = $desc;
  606.                 $return['key']  = $result['key'];
  607.  
  608.             } catch ( Exception $ex ) {
  609.                 $return['error'] = $ex->getMessage();
  610.             }
  611.  
  612.             return $return;
  613.         }
  614.  
  615.         public function get_redirect_url( $url ) {
  616.  
  617.             $response = wp_remote_head( $url );
  618.             $redirect_url = wp_remote_retrieve_header( $response, 'location' );
  619.  
  620.             return $redirect_url ? $redirect_url : $url;
  621.         }
  622.  
  623.         public function word_wrap_annotation( $image, $draw, $text, $max_width ) {
  624.  
  625.             $words = preg_split( '%\s%', $text, -1, PREG_SPLIT_NO_EMPTY );
  626.             $lines = array();
  627.             $i = 0;
  628.             $line_height = 0;
  629.  
  630.             while ( count( $words ) > 0 ) {
  631.                 $metrics = $image->queryFontMetrics( $draw, implode( ' ', array_slice( $words, 0, ++$i ) ) );
  632.                 $line_height = max( $metrics['textHeight'], $line_height );
  633.  
  634.                 if ( $metrics['textWidth'] > $max_width || count( $words ) < $i ) {
  635.                     if ( 1 === $i ) {
  636.                         $i++;
  637.                     }
  638.  
  639.                     $lines[] = implode( ' ', array_slice( $words, 0, --$i ) );
  640.                     $words = array_slice( $words, $i );
  641.                     $i = 0;
  642.                 }
  643.             }
  644.  
  645.             return array( $lines, $line_height );
  646.         }
  647.  
  648.         public function subscribe_user( $id, $name, $email ) {
  649.  
  650.             $settings   = get_post_meta( $id, 'settings', true );
  651.             $options    = get_option( 'wp_quiz_pro_default_settings' );
  652.             if ( '1' === $settings['force_action'] ) {
  653.                 if ( '1' === $options['mail_service'] ) {
  654.                     $this->subscribe_mailchimp( $options, $name, $email );
  655.                 } else if ( '2' === $options['mail_service'] ) {
  656.                     $this->subscribe_getresponse( $options, $name, $email );
  657.                 } else if ( '3' === $options['mail_service'] ) {
  658.                     $this->subscribe_aweber( $options, $name, $email );
  659.                 }
  660.             }
  661.         }
  662.  
  663.         private function subscribe_aweber( $options, $name, $email ) {
  664.  
  665.             // check for valid data
  666.             if ( empty( $email ) ) {
  667.                 wp_send_json( array(
  668.                     'success' => false,
  669.                     'error' => esc_html__( 'No email address found.', 'wp-quiz-pro' ),
  670.                 ) );
  671.             }
  672.  
  673.             if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
  674.                 wp_send_json( array(
  675.                     'success' => false,
  676.                     'error' => esc_html__( 'Not a valid email address.', 'wp-quiz-pro' ),
  677.                 ) );
  678.             }
  679.  
  680.             // Call service subscription method
  681.             try {
  682.                 $service = new WP_Quiz_Pro_Subscription_Aweber();
  683.                 $list_id        = $options['aweber']['listid'];
  684.                 $status = $service->subscribe( $name, $email, $list_id );
  685.  
  686.                 wp_send_json(array(
  687.                     'success' => true,
  688.                     'status' => $status['status'],
  689.                 ));
  690.             } catch ( Exception $e ) {
  691.                 wp_send_json(array(
  692.                     'success' => false,
  693.                     'error' => $e->getMessage(),
  694.                 ));
  695.             }
  696.         }
  697.  
  698.         private function subscribe_mailchimp( $options, $name, $email ) {
  699.  
  700.             $mc_api_key     = $options['mailchimp']['api_key'];
  701.             $mc_list_id     = $options['mailchimp']['list_id'];
  702.             $double_optin   = apply_filters( 'wp_quiz_mailchimp_double_notification', false );
  703.  
  704.             $vendor_path = $this->get_vendor_path();
  705.  
  706.             if ( $email && null !== $mc_api_key && null !== $mc_list_id ) {
  707.  
  708.                 try {
  709.                     if ( ! class_exists( 'Mailchimp' ) ) {
  710.                         require_once( $vendor_path . '/Mailchimp.php' );
  711.                     }
  712.  
  713.                     $list = new Mailchimp_Lists( new Mailchimp( $mc_api_key ) );
  714.                     $merge_vars = null;
  715.                     if ( $name ) {
  716.                         $fname = $name;
  717.                         $lname = '';
  718.                         if ( $space_pos = strpos( $name, ' ' ) ) {
  719.                             $fname = substr( $name, 0, $space_pos );
  720.                             $lname = substr( $name, $space_pos );
  721.                         }
  722.                         $merge_vars = array( 'FNAME' => $fname, 'LNAME' => $lname );
  723.                     }
  724.                     $list->subscribe( $mc_list_id, array( 'email' => $email ), $merge_vars, 'html', (bool) $double_optin, true );
  725.  
  726.                 } catch ( Exception $ex ) {}
  727.             }
  728.         }
  729.  
  730.         private function subscribe_getresponse( $options, $name, $email ) {
  731.  
  732.             $gr_api_key = $options['getresponse']['api_key'];
  733.             $gr_list_id = $options['getresponse']['campaign_name'];
  734.  
  735.             $vendor_path = $this->get_vendor_path();
  736.  
  737.             if ( $email && null !== $gr_api_key && null !== $gr_list_id ) {
  738.                 try {
  739.                     if ( ! class_exists( 'GetResponse' ) ) {
  740.                         require_once( $vendor_path . '/getresponse.php' );
  741.                     }
  742.  
  743.                     $api = new GetResponse( $gr_api_key );
  744.                     $campaign_ame       = $gr_list_id;
  745.                     $subscriber_name        = $name;
  746.                     $subscriber_email   = $email;
  747.  
  748.                     $result         = $api->getCampaigns( 'EQUALS', $campaign_ame );
  749.                     $campaigns      = array_keys( (array) $result );
  750.                     $campaign_id    = array_pop( $campaigns );
  751.  
  752.                     $api->addContact( $campaign_id, $subscriber_name, $subscriber_email );
  753.                 } catch ( Exception $ex ) {}
  754.             }
  755.         }
  756.  
  757.         public function get_vendor_path() {
  758.  
  759.             return plugin_dir_path( __FILE__ ) . 'vendor';
  760.         }
  761.  
  762.         public function check_image_file() {
  763.  
  764.             $output = array( 'status' => 1 );
  765.             $check = false;
  766.             if ( @getimagesize( $_POST['url'] ) ) {
  767.                 $check = true;
  768.             }
  769.  
  770.             $output['check'] = $check;
  771.             wp_send_json( $output );
  772.         }
  773.  
  774.         public function check_video_file() {
  775.  
  776.             $output = array( 'status' => 1 );
  777.             $check = false;
  778.             $id = $_POST['video_id'];
  779.             $url = "http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=$id&format=json";
  780.             $headers = get_headers( $url );
  781.             if ( '404' !== substr( $headers[0], 9, 3 ) ) {
  782.                 $check = true;
  783.             }
  784.  
  785.             $output['check'] = $check;
  786.             wp_send_json( $output );
  787.         }
  788.  
  789.         public static function activate_plugin() {
  790.  
  791.             // Don't activate on anything less than PHP 5.4.0 or WordPress 3.4
  792.             if ( version_compare( PHP_VERSION, '5.4.0', '<' ) || version_compare( get_bloginfo( 'version' ), '3.4', '<' ) || ! function_exists( 'spl_autoload_register' ) ) {
  793.                 require_once ABSPATH . 'wp-admin/includes/plugin.php';
  794.                 deactivate_plugins( basename( __FILE__ ) );
  795.                 wp_die( __( 'Testes Pop requires PHP version 5.4.0 with spl extension or greater and WordPress 3.4 or greater.', 'wp-quiz-pro' ) );
  796.             }
  797.  
  798.             //Dont't activate if wp quiz is active
  799.             if ( defined( 'WP_QUIZ_VERSION' ) ) {
  800.                 deactivate_plugins( basename( __FILE__ ) );
  801.                 wp_die( __( 'Please deactivate WP Quiz plugin first to use the Premium features!', 'wp-quiz-pro' ) );
  802.             }
  803.  
  804.             include( 'inc/activate-plugin.php' );
  805.  
  806.         }
  807.  
  808.         public function get_ip() {
  809.  
  810.             //Just get the headers if we can or else use the SERVER global
  811.             if ( function_exists( 'apache_request_headers' ) ) {
  812.                 $headers = apache_request_headers();
  813.             } else {
  814.                 $headers = $_SERVER;
  815.             }
  816.  
  817.             //Get the forwarded IP if it exists
  818.             if ( array_key_exists( 'X-Forwarded-For', $headers ) && filter_var( $headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) {
  819.                 $the_ip = $headers['X-Forwarded-For'];
  820.             } else if ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers ) && filter_var( $headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) {
  821.                 $the_ip = $headers['HTTP_X_FORWARDED_FOR'];
  822.             } else {
  823.                 $the_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 );
  824.             }
  825.             return $the_ip;
  826.  
  827.         }
  828.  
  829.         public function dismiss_imagick_notice() {
  830.             add_option( 'wp_dismiss_imagick_notice', 'true' );
  831.         }
  832.  
  833.         public function dismiss_gdlibrary_notice() {
  834.             add_option( 'wp_dismiss_gdlibrary_notice', 'true' );
  835.         }
  836.  
  837.         public function wp_quiz_pro_get_debug_log() {
  838.             $page = new WP_Quiz_Pro_Page_Support();
  839.             $page->get_debug_log();
  840.         }
  841.  
  842.         public function fb_share_fix() {
  843.  
  844.             $data = array_map( 'urldecode', $_GET );
  845.             $result = get_post_meta( $data['id'], 'results', true );
  846.             $result = isset( $result[ $data['rid'] ] ) ? $result[ $data['rid'] ] : array();
  847.  
  848.             // Picture
  849.             if ( 'r' === $data['pic'] ) {
  850.                 $data['source'] = $result['image'];
  851.             } elseif ( 'f' === $data['pic'] ) {
  852.                 $data['source'] = wp_get_attachment_url( get_post_thumbnail_id( $data['id'] ) );
  853.             } elseif ( ( substr( $data['pic'], 0, 6 ) === 'image-' ) ) {
  854.                 $upload_dir = wp_upload_dir();
  855.                 $upload_dir['baseurl'] = $upload_dir['baseurl'] . '/wp_quiz-result-images';
  856.                 $data['source'] = $upload_dir['baseurl'] . '/' . $data['pic'] . '.png';
  857.             } else {
  858.                 $data['source'] = false;
  859.             }
  860.  
  861.             // Description
  862.             if ( 'r' === $data['desc'] ) {
  863.                 $data['description'] = $result['desc'];
  864.             } elseif ( 'e' === $data['desc'] ) {
  865.                 $data['description'] = get_post_field( 'post_excerpt', $data['id'] );
  866.             } else {
  867.                 $data['description'] = false;
  868.             }
  869.  
  870.             if ( $data['description'] ) {
  871.  
  872.                 $first = array( '%%nomeusuario%%', '%%nomeamigo%%' );
  873.                 $last = array( '%%sobrenome%%', '%%sobrenomeamigo%%' );
  874.  
  875.                 $data['description'] = str_replace( $first, $data['nf'], $data['description'] );
  876.                 $data['description'] = str_replace( $last, $data['nl'], $data['description'] );
  877.             }
  878.  
  879.             $settings = get_option( 'wp_quiz_pro_default_settings' );
  880.             $url = ( is_ssl() ? 'https' : 'http' ) . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  881.  
  882.             global $post;
  883.             $pid  = $post ? $post->ID : $data['id'];
  884.             $original_url = get_permalink( $pid );
  885.             ?>
  886.             <html>
  887.                 <head>
  888.                     <title><?php wp_title( '' ) ?></title>
  889.                     <meta property="fb:app_id" content="<?php echo $settings['defaults']['fb_app_id'] ?>">
  890.                     <meta property="og:type" content="website">
  891.                     <meta name="twitter:card" content="summary_large_image">
  892.                     <meta property="og:url" content="<?php echo esc_url( $url ); ?>">
  893.                     <?php if ( ! empty( $data['text'] ) ) : ?>
  894.                     <meta property="og:title" content="<?php echo get_the_title( $pid ) ?> - <?php echo esc_attr( $data['text'] ); ?>">
  895.                     <meta property="twitter:title" content="<?php echo get_the_title( $pid ) ?> - <?php echo esc_attr( $data['text'] ); ?>">
  896.                     <?php endif; ?>
  897.                     <?php if ( ! empty( $data['source'] ) ) : ?>
  898.                     <meta property="og:image" content="<?php echo esc_url( $data['source'] ); ?>">
  899.                     <meta property="twitter:image" content="<?php echo esc_url( $data['source'] ); ?>">
  900.                         <?php list( $img_width, $img_height ) = getimagesize( $data['source'] ); ?>
  901.                         <?php if ( isset( $img_width ) && $img_width ) : ?>
  902.                         <meta property="og:image:width" content="<?php echo $img_width ?>">
  903.                         <?php endif; ?>
  904.                         <?php if ( isset( $img_height ) && $img_height ) : ?>
  905.                         <meta property="og:image:height" content="<?php echo $img_height ?>">
  906.                         <?php endif; ?>
  907.                     <?php endif; ?>
  908.                     <?php if ( ! empty( $data['description'] ) ) : ?>
  909.                     <meta property="og:description" content="<?php echo esc_attr( $data['description'] ); ?>">
  910.                     <meta property="twitter:description" content="<?php echo esc_attr( $data['description'] ); ?>">
  911.                     <?php endif; ?>
  912.                     <meta http-equiv="refresh" content="0;url=<?php echo esc_url( $original_url ); ?>">
  913.                 </head>
  914.             <body>
  915.                 Redirecting please wait....
  916.             </body>
  917.             </html>
  918.             <?php
  919.             exit;
  920.         }
  921. /*
  922. ////////////////////////////////////// ALTEREI AQUI ////////////////////////////////////
  923. */
  924.         protected static $url_facebook = null;
  925.         public static function get_url_facebook() {
  926.             return self::$url_facebook;
  927.         }
  928.         public function set_url_facebook($url) {
  929.             self::$url_facebook = $url;
  930.         }
  931. /*
  932. ////////////////////////////////////// ALTEREI AQUI ////////////////////////////////////
  933. */
  934.  
  935.         /**
  936.          * [inline_script description]
  937.          * @return [type] [description]
  938.          */
  939.         public function inline_script() {
  940.             $settings = get_option( 'wp_quiz_pro_default_settings' );
  941. /*
  942. ////////////////////////////////////// ALTEREI AQUI ////////////////////////////////////
  943. */
  944.             $this->set_url_facebook($settings['defaults']['fb_app_id2']);
  945. /*
  946. ////////////////////////////////////// ALTEREI AQUI ////////////////////////////////////
  947. */
  948.             ?>
  949.             <script>
  950.             var quizSiteUrl = '<?php echo home_url( '/' ) ?>';
  951.             <?php if ( ! empty( $settings['analytics']['tracking_id'] ) ) { ?>
  952.                 (function(i,s,o,g,r,a,m) {i['GoogleAnalyticsObject']=r;i[r]=i[r]||function() {
  953.                 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  954.                 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  955.                 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  956.  
  957.                 ga('create', '<?php echo $settings['analytics']['tracking_id'] ?>', 'auto');
  958.                 ga('send', 'pageview');
  959.             <?php } ?>
  960.             <?php if ( ! empty( $settings['defaults']['fb_app_id'] ) ) { ?>
  961.                 window.fbAsyncInit = function() {
  962.                     FB.init({
  963.                         appId    : '<?php echo $settings['defaults']['fb_app_id'] ?>',
  964.                         xfbml    : true,
  965.                         version  : 'v2.9'
  966.                     });
  967.  
  968.                     FB.getLoginStatus(function( response ) {
  969.                         getLogin( response );
  970.                     });
  971.                 };
  972.                
  973.                 (function(d, s, id) {
  974.                     var js, fjs = d.getElementsByTagName(s)[0];
  975.                     if (d.getElementById(id)) {return;}
  976.                     js = d.createElement(s); js.id = id;
  977.                     js.src = "//connect.facebook.net/pt_BR/sdk.js";
  978.                     fjs.parentNode.insertBefore(js, fjs);
  979.                 }(document, 'script', 'facebook-jssdk'));
  980.  
  981.             <?php } ?>
  982.             </script>
  983.  
  984.             <?php
  985.             if ( is_singular( array( 'wp_quiz' ) ) && isset( $settings['defaults']['share_meta'] ) && 1 === $settings['defaults']['share_meta'] ) {
  986.                 global $post, $wpseo_og;
  987.                 $twitter_desc = $og_desc = str_replace( array( "\r", "\n" ), '', strip_tags( $post->post_excerpt ) );
  988.                 if ( defined( 'WPSEO_VERSION' ) ) {
  989.                     remove_action( 'wpseo_head', array( $wpseo_og, 'opengraph' ), 30 );
  990.                     remove_action( 'wpseo_head', array( 'WPSEO_Twitter', 'get_instance' ), 40 );
  991.                     //use description from yoast
  992.                     $twitter_desc   = get_post_meta( $post->ID, '_yoast_wpseo_twitter-description', true );
  993.                     $og_desc        = get_post_meta( $post->ID, '_yoast_wpseo_opengraph-description', true );
  994.                 }
  995.                 ?>
  996.                 <meta name="twitter:title" content="<?php echo get_the_title(); ?>">
  997.                 <meta name="twitter:description" content="<?php echo $twitter_desc; ?>">
  998.                 <meta name="twitter:domain" content="<?php echo esc_url( site_url() ); ?>">
  999.                 <meta property="og:url" content="<?php the_permalink(); ?>" />
  1000.                 <meta property="og:title" content="<?php echo get_the_title(); ?>" />
  1001.                 <meta property="og:description" content="<?php echo $og_desc; ?>" />
  1002.                 <?php
  1003.                 if ( has_post_thumbnail() ) {
  1004.                     $thumb_id = get_post_thumbnail_id();
  1005.                     $thumb_url_array = wp_get_attachment_image_src( $thumb_id, 'full', true );
  1006.                     $thumb_url = $thumb_url_array[0];
  1007.                     ?>
  1008.                     <meta name="twitter:card" content="summary_large_image">
  1009.                     <meta name="twitter:image:src" content="<?php echo $thumb_url; ?>">
  1010.                     <meta property="og:image" content="<?php echo $thumb_url; ?>" />
  1011.                     <meta itemprop="image" content="<?php echo $thumb_url; ?>">
  1012.                 <?php
  1013.                 }
  1014.             }
  1015.         }
  1016.  
  1017.         public function embeded_output() {
  1018.  
  1019.             if ( ! isset( $_GET['wp_quiz_id'] ) ) {
  1020.                 return;
  1021.             }
  1022.  
  1023.             $qid        = absint( $_GET['wp_quiz_id'] );
  1024.             $quiz_html  = $this->register_shortcode( array( 'id' => $qid ) );
  1025.             $settings   = get_post_meta( $qid, 'settings', true );
  1026.             if ( empty( $quiz_html ) ) {
  1027.                 return;
  1028.             }
  1029.             ?>
  1030.                 <link rel='stylesheet' href='<?php echo WP_QUIZ_PRO_ASSETS_URL . 'css/main.css'; ?>' type='text/css' media='all' />
  1031.                 <link rel='stylesheet' href='<?php echo WP_QUIZ_PRO_ASSETS_URL . 'css/transition.min.css'; ?>' type='text/css' media='all' />
  1032.                 <link rel='stylesheet' href='<?php echo WP_QUIZ_PRO_ASSETS_URL . 'css/embed.min.css'; ?>' type='text/css' media='all' />
  1033.                 <style>
  1034.                     .wq_embedToggleQuizCtr{ display: none; }
  1035.                 </style>
  1036.             <?php
  1037.             if ( 'traditional' === $settings['skin'] ) {
  1038.                 ?>
  1039.                     <link rel='stylesheet' href='<?php echo WP_QUIZ_PRO_ASSETS_URL . 'css/traditional-skin.css'; ?>' type='text/css' media='all' />
  1040.                 <?php
  1041.             } else if ( 'flat' === $settings['skin'] ) {
  1042.                 ?>
  1043.                     <link rel='stylesheet' href='<?php echo WP_QUIZ_PRO_ASSETS_URL . 'css/flat-skin.css'; ?>' type='text/css' media='all' />
  1044.                 <?php
  1045.             }
  1046.             $this->inline_script();
  1047.             ?>
  1048.                 <script>
  1049.                     var wq_l10n = {"correct": "Correct !", "wrong": "Wrong !","captionTrivia":"You got %%score%% out of %%total%%","captionTriviaFB":"I got %%score%% out of %%total%%, and you?","youVoted":"You voted","nonce": "<?php echo wp_create_nonce( 'ajax-quiz-content' ) ?>"};
  1050.                 </script>
  1051.             <?php
  1052.  
  1053.             echo '<div class="wq_embed">' . $quiz_html . '</div>';
  1054.             ?>
  1055.                 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  1056.                 <script src="<?php echo WP_QUIZ_PRO_ASSETS_URL . 'js/embed.min.js'; ?>"></script>
  1057.                 <script src="<?php echo WP_QUIZ_PRO_ASSETS_URL . 'js/transition.min.js'; ?>"></script>
  1058.                 <script src="<?php echo WP_QUIZ_PRO_ASSETS_URL . 'js/jquery.flip.min.js'; ?>"></script>
  1059.                 <script src="<?php echo WP_QUIZ_PRO_ASSETS_URL . 'js/hammer.min.js'; ?>"></script>
  1060.                 <script src="<?php echo WP_QUIZ_PRO_ASSETS_URL . 'js/dynamics.min.js'; ?>"></script>
  1061.                 <script src="<?php echo WP_QUIZ_PRO_ASSETS_URL . 'js/jquery.jTinder.min.js'; ?>"></script>
  1062.                 <script src="<?php echo WP_QUIZ_PRO_ASSETS_URL . 'js/main.min.js'; ?>"></script>
  1063.             <?php
  1064.             die();
  1065.         }
  1066.  
  1067.         /**
  1068.          * [connect_aweber description]
  1069.          * @return [type] [description]
  1070.          */
  1071.         public function connect_aweber() {
  1072.  
  1073.             // check for data
  1074.             $aweber_code = isset( $_REQUEST['aweber_code'] ) ? $_REQUEST['aweber_code'] : array();
  1075.             if ( empty( $aweber_code ) ) {
  1076.                 wp_send_json( array(
  1077.                     'success' => false,
  1078.                     'error' => esc_html__( 'No aweber authorization code found.', 'wp-quiz-pro' ),
  1079.                 ) );
  1080.             }
  1081.  
  1082.             try {
  1083.                 $service = new WP_Quiz_Pro_Subscription_Aweber();
  1084.                 $data = $service->connect( $aweber_code );
  1085.  
  1086.                 wp_send_json(array(
  1087.                     'success' => true,
  1088.                     'data' => $data,
  1089.                 ));
  1090.             } catch ( Exception $e ) {
  1091.                 wp_send_json(array(
  1092.                     'success' => false,
  1093.                     'error' => $e->getMessage(),
  1094.                 ));
  1095.             }
  1096.         }
  1097.     }
  1098.  
  1099.     /**
  1100.      * Main instance of WP_Quiz_Pro_Plugin.
  1101.      *
  1102.      * Returns the main instance of WP_Quiz_Pro_Plugin to prevent the need to use globals.
  1103.      *
  1104.      * @return WP_Quiz_Pro_Plugin
  1105.      */
  1106.  
  1107.     function wp_quiz_pro() {
  1108.         return WP_Quiz_Pro_Plugin::get_instance();
  1109.     }
  1110. /*
  1111. ////////////////////////////////////// ALTEREI AQUI ////////////////////////////////////
  1112. */
  1113.     function prepare_url_facebook() {
  1114.         return WP_Quiz_Pro_Plugin::get_url_facebook();
  1115.     }
  1116. /*
  1117. ////////////////////////////////////// ALTEREI AQUI ////////////////////////////////////
  1118. */
  1119. endif;
  1120.  
  1121. add_action( 'plugins_loaded', 'wp_quiz_pro', 10 );
  1122. register_activation_hook( __FILE__, array( 'WP_Quiz_Pro_Plugin', 'activate_plugin' ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement