예제 #1
0
/**
 * Check if a popup is available for the current page.
 *
 * The function checks, in this order, if a popup is available for:
 * - The current post
 * - The current post type
 * - The whole site
 *
 * @since  1.0.0
 *
 * @param int $post_id Optional post ID to check for popup availability
 *
 * @return bool|int Popup ID if a popup is available, false otherwise
 */
function wpbo_page_has_popup($post_id = 0)
{
    /**
     * Checks in order:
     *
     * 1. Front-page
     * 2. Homepage
     * 3. Archives
     *  3.1 Search
     *  3.2 Post type
     * 4. 404
     * 5. Singular
     */
    $post_id = wpbo_get_post_id($post_id);
    /**
     * First of all let's check if the user is an admin
     * and if popups are hidden for admins.
     */
    if (is_user_logged_in() && current_user_can('administrator') && true === (bool) wpbo_get_option('hide_admins', false)) {
        return false;
    }
    // Try to get the popup from the cache
    $popup_id = wpbo_get_cached_popup($post_id);
    if (false === $popup_id) {
        $popup_id = wpbo_get_popup($post_id);
    }
    // Cache popup ID to avoid calculating again on page refresh */
    if (false !== $popup_id) {
        wpbo_cache_popup($popup_id, $post_id);
    }
    return $popup_id;
}
예제 #2
0
/**
 * Check if MailChimp settings are correct.
 *
 * @since  1.0.0
 * @return boolean True if MailPoet integration is ready to work
 */
function wpbo_is_mailpoet_ready()
{
    $list_id = wpbo_get_option('mp_list_id', '');
    if (empty($list_id)) {
        return false;
    }
    return true;
}
 /**
  * Subscribe the visitor to a list.
  *
  * @since  1.0.0
  *
  * @param array $data Form data
  *
  * @return array Result
  */
 protected function subscribe($data)
 {
     $email = sanitize_email($data['email']);
     $list_id = wpbo_get_option('mp_list_id', '');
     $popup_id = (int) $data['wpbo_id'];
     $custom_list = get_post_meta($popup_id, 'wpbo_mp_list', true);
     $list_id = '' != $custom_list ? $custom_list : $list_id;
     // Possibly get additional fields
     $first_name = isset($data['first_name']) ? sanitize_text_field($data['first_name']) : sanitize_key($data['name']);
     $last_name = isset($data['last_name']) ? sanitize_text_field($data['last_name']) : '';
     $user_data = array('email' => $email, 'firstname' => apply_filters('bomp_subscriber_first_name', $first_name), 'lastname' => apply_filters('bomp_subscriber_last_name', $last_name));
     $data_subscriber = array('user' => $user_data, 'user_list' => array('list_ids' => array($list_id)));
     $helper_user = WYSIJA::get('user', 'helper');
     $add = $helper_user->addSubscriber($data_subscriber);
     return $add;
 }
예제 #4
0
/**
 * Insert new subscriber.
 *
 * Add a new row of data in the failsafe table.
 *
 * @since  2.0
 *
 * @param  array   $data     Details of the subscriber
 * @param  boolean $wp_error Allow the function to return a WP_Error object
 *
 * @return mixed          Subscriber ID on success or WP_Error on failure
 */
function wpbo_failsafe_add_subscriber($data = array(), $wp_error = true)
{
    global $wpdb;
    $table_name = wpbo_failsafe_table;
    $defaults = array('ID' => false, 'conversion_id' => 0, 'time' => '', 'first_name' => '', 'last_name' => '', 'email' => '', 'provider' => '', 'status' => '');
    $data = array_merge($defaults, $data);
    if (empty($data['time']) || '0000-00-00 00:00:00' == $data['time']) {
        $data['time'] = current_time('mysql');
    }
    /**
     * Validate the date
     */
    $valid_date = wpbo_check_date($data['time']);
    if (!$valid_date) {
        if ($wp_error) {
            return new WP_Error('invalid_date', __('Whoops, the provided date is invalid.'));
        } else {
            return false;
        }
    }
    // Make sure we have a provider
    if (empty($data['provider'])) {
        $provider = str_replace(' ', '', ucwords(str_replace(array('-', '_'), ' ', sanitize_text_field(wpbo_get_option('mailing_provider', '')))));
        $data['provider'] = $provider;
    }
    // Set the status as failed by default
    if (empty($data['status'])) {
        $data['status'] = 'failed';
    }
    /* Sanitize all data values */
    $data = array_map('sanitize_text_field', $data);
    $insert = $wpdb->insert($table_name, $data, array('%s', '%d', '%d', '%s', '%s', '%s', '%s', '%s'));
    if (false === $insert) {
        if ($wp_error) {
            return new WP_Error('insert_failed', __('Whoops, we could not insert the data in the database.'));
        } else {
            return false;
        }
    } else {
        return $wpdb->insert_id;
    }
}
예제 #5
0
/**
 * Check if Aweber settings are correct.
 *
 * @since  1.0.0
 * @return boolean True if Aweber integration is ready to work
 */
function wpbo_is_aweber_ready()
{
    $tokens = maybe_unserialize(get_option('wpbo_aweber_tokens'));
    if (!is_array($tokens)) {
        return false;
    }
    $access_token = isset($tokens[0]) ? trim($tokens[0]) : '';
    $access_secret = isset($tokens[1]) ? trim($tokens[1]) : '';
    if (empty($access_token) || empty($access_secret)) {
        return false;
    }
    $auth_code = trim(wpbo_get_option('aw_auth_code', ''));
    if (empty($auth_code)) {
        return false;
    }
    $list_id = wpbo_get_option('aw_list_id', '');
    if (empty($list_id)) {
        return false;
    }
    return true;
}
예제 #6
0
 /**
  * Get a popup markup.
  *
  * Retrieve the markup for a specific popup. Check if the popup
  * was customized first, otherwise just load the default HTML file.
  *
  * @since  1.0.0
  * @param  integer $popup_id ID of the required popup
  * @return string            HTML markup of the popup to display
  */
 public static function get_popup_markup($popup_id)
 {
     /* Check if the template was customized */
     if ('' != ($customized = get_post_meta($popup_id, '_wpbo_template_display', true))) {
         if (is_admin()) {
             $output = html_entity_decode(get_post_meta($popup_id, '_wpbo_template_editor', true), ENT_COMPAT | ENT_HTML401, 'UTF-8');
         } else {
             $output = html_entity_decode($customized, ENT_COMPAT | ENT_HTML401, 'UTF-8');
         }
     } else {
         $template = get_post_meta($popup_id, 'wpbo_template', true);
         if ('' == $template) {
             return false;
         }
         $file = $template . '.php';
         $filepath = WPBO_PATH . 'admin/views/templates/' . $file;
         if (file_exists($filepath)) {
             /* Turn on buffering */
             ob_start();
             require $filepath;
             /* Get the buffered content into a var */
             $output = ob_get_contents();
             /* Clean buffer */
             ob_end_clean();
         }
     }
     if (!is_admin()) {
         global $post;
         /* Get return URL */
         if ('' != ($custom_url = wpbo_get_option('return_url', '', $popup_id))) {
             $return_url = $custom_url;
         } elseif ('' != ($default_url = wpbo_get_option('return_url', ''))) {
             $return_url = $default_url;
         } else {
             $return_url = false;
         }
         /**
          * wpbo_return_url hook
          *
          * @since  1.0.0
          */
         $return_url = apply_filters('wpbo_return_url', $return_url, $popup_id, $post->ID);
         /* Add the form */
         $output = sprintf('<form role="form" class="optform" id="%s" action="%s" method="post">', 'wpbo-popup-' . $popup_id, get_permalink($post->ID)) . $output;
         /* Add all hidden fields */
         $output .= wp_nonce_field('subscribe', 'wpbo_nonce', false, false);
         $output .= sprintf('<input type="hidden" name="wpbo_id" id="wpbo_id" value="%s">', self::get_popup_id());
         $output .= sprintf('<input type="hidden" name="post_id" id="post_id" value="%s">', $post->ID);
         if (false !== $return_url) {
             $output .= sprintf('<input type="hidden" name="return_url" id="return_url" value="%s">', $return_url);
         }
         /**
          * wpbo_popup_hidden_fields hook
          *
          * @since  1.0.0
          * @var    $popup_id ID of the popup to be triggered
          * @var    $post->ID ID of the post being veiwed
          */
         do_action('wpbo_popup_hidden_fields', $popup_id, $post->ID);
         /* Close the form */
         $output .= '</form>';
     }
     return $output;
 }
예제 #7
0
<?php

global $wpbo_submit;
$lists = wpbo_aw_get_lists();
$default = wpbo_get_option('aw_list_id');
$opts = array();
$value = isset($_GET['post']) ? get_post_meta((int) $_GET['post'], 'wpbo_aw_list', true) : '';
foreach ($lists as $key => $list) {
    $opts[$list['id']] = $list['name'];
}
$def_name = isset($opts[$default]) ? $opts[$default] : esc_html_x('None', 'No mailing list selected', 'betteroptin');
if ('' == $value) {
    ?>
	<p><?php 
    printf(esc_html__('If you don\'t select a list here, the default one will be used (currently %s).', 'betteroptin'), "<code>{$def_name}</code>");
    ?>
</p>
<?php 
}
?>

<select id="wpbo_aw_list" name="wpbo_aw_list" style="width:100%">
	<option value="" <?php 
if ('' == $value) {
    ?>
selected="selected"<?php 
}
?>
><?php 
esc_html_x('Default', 'Default mailing list', 'betteroptin');
?>
예제 #8
0
/**
 * Sanitize data row.
 *
 * @param  array $data     Array of data elements to sanitize
 * @param bool   $wp_error Whether or not to return a WP_Error object in case of problem
 *
 * @return array        A clean array of data elements
 */
function wpbo_db_sanitize_data($data = array(), $wp_error = true)
{
    $defaults = array('data_id' => false, 'time' => false, 'data_type' => false, 'popup_id' => false, 'user_agent' => false, 'referer' => false, 'ip_address' => false);
    $data = array_merge($defaults, $data);
    if (empty($data['time']) || '0000-00-00 00:00:00' == $data['time']) {
        $data['time'] = current_time('mysql');
    }
    /**
     * Validate the date
     */
    $valid_date = wpbo_check_date($data['time']);
    if (!$valid_date) {
        if ($wp_error) {
            return new WP_Error('invalid_date', __('Whoops, the provided date is invalid.'));
        } else {
            return false;
        }
    }
    /**
     * Possibly filter the IP address
     */
    if ('1' == wpbo_get_option('anonymize_ip', false) && false !== $data['ip_address'] && '0.0.0.0' !== $data['ip_address']) {
        $ip_breakdown = explode('.', $data['ip_address']);
        $ip_breakdown[3] = '*';
        $data['ip_address'] = implode('.', $ip_breakdown);
    }
    /**
     * Recreate the sanitized array of data elements
     */
    $clean = array('time' => $data['time'], 'data_type' => $data['data_type'], 'popup_id' => $data['popup_id'], 'user_agent' => $data['user_agent'], 'referer' => $data['referer'], 'ip_address' => $data['ip_address']);
    return $clean;
}
예제 #9
0
 /**
  * Setup MailChimp options
  *
  * @since 2.0
  * @return void
  */
 private function setup_options()
 {
     self::$api_key = wpbo_get_option('mc_api_key', '');
     self::$list_id = wpbo_get_option('mc_list_id', '');
     self::$double_optin = wpbo_get_option('mc_double_optin', true);
     self::$update = wpbo_get_option('mc_update_existing', true);
     self::$welcome = wpbo_get_option('mc_welcome', true);
     self::$fields = apply_filters('wpbo_mc_merge_vars', array('FNAME'));
 }
예제 #10
0
        /**
         * Display an admin notice if license key is missing
         *
         * @since 2.0
         * @return void
         */
        public function license_notification()
        {
            /**
             * We only want to display the notice to the site admin.
             */
            if (!current_user_can('administrator')) {
                return;
            }
            $license = wpbo_get_option('license_key', '');
            /**
             * Do not show the notice if the license key has already been entered.
             */
            if (!empty($license)) {
                return;
            }
            $license_page = wpbo_get_settings_page_link();
            ?>

			<div class="updated error">
				<p><?php 
            printf(__('You haven&#039;t entered your BetterOptin license key. This means that you will not get automatic updates and you will not get technical support. <a %s>Click here to enter your license key</a>.', 'betteroptin'), "href='{$license_page}'");
            ?>
</p>
			</div>

		<?php 
        }
예제 #11
0
 public function __construct()
 {
     if (!class_exists('AWeberAPI')) {
         require WPBO_PATH . 'vendor/aweber/aweber/aweber_api/aweber.php';
     }
     $this->auth_code = trim(wpbo_get_option('aw_auth_code', ''));
     $this->api_key = false !== $this->get_credentials() ? $this->get_credentials()['consumerKey'] : '';
     $this->api_secret = false !== $this->get_credentials() ? $this->get_credentials()['consumerSecret'] : '';
     $this->list_id = wpbo_get_option('aw_list_id', '');
     $this->get_tokens();
 }
예제 #12
0
" oninput="this.form.amount.value=this.value">
					<output name="amount" for="wpbo-overlay-opacity"><?php 
echo wpbo_get_option('overlay_opacity', '0.5', $post_id);
?>
</output>
				</td>
			</tr>
			<tr valign="top">
				<th scope="row">
					<label for="wpbo_return_url"><?php 
_e('Return URL', 'wpbo');
?>
</label>
				</th>
				<td>
					<input name="wpbo_settings[return_url]" type="url" class="regular-text" id="wpbo_return_url"value="<?php 
echo wpbo_get_option('return_url', '', $post_id);
?>
">
					<?php 
$returl = '' == ($url = wpbo_get_option('return_url')) ? 'none' : esc_url($url);
?>
					<p><?php 
printf(__('The return URL is optional. If not specified, the URL set in the general settings will be used (currently %s)', 'wpbo'), "<code>{$returl}</code>");
?>
</p>
				</td>
			</tr>
		</tbody>
	</table>
</fieldset>
예제 #13
0
 /**
  * Get the return URL.
  *
  * @todo   add support for failed submissions
  * @param  string $case The submission status
  * @return string       URL to redirect to
  */
 public function get_return_url($case = 'success')
 {
     $field = 'success' == $case ? 'return_url' : 'return_url';
     if (isset($_POST[$field]) && '' != $_POST[$field]) {
         $url = esc_url($_POST[$field]);
     } elseif ('' != ($custom_url = wpbo_get_option($field, '', $this->popup_id))) {
         $url = $custom_url;
     } elseif ('' != ($default_url = wpbo_get_option($field, ''))) {
         $url = $default_url;
     } else {
         $status = 'success' == $case ? 'done' : 'fail';
         $url = add_query_arg(array('wpbo_submit' => $status), esc_url(get_permalink($this->post_id)));
     }
     return $url;
 }
예제 #14
0
<?php

/**
 * BetterOptin Provider MailChimp
 *
 * @package   BetterOptin/Provider/MailChimp
 * @author    ThemeAvenue <*****@*****.**>
 * @license   GPL-2.0+
 * @link      http://themeavenue.net
 * @copyright 2015 ThemeAvenue
 */
// If this file is called directly, abort.
if (!defined('WPINC')) {
    die;
}
if ('mail-chimp' === wpbo_get_option('mailing_provider', '')) {
    require WPBO_PATH . 'includes/providers/mailchimp/functions-ajax.php';
    require WPBO_PATH . 'includes/providers/mailchimp/class-mailchimp.php';
    require WPBO_PATH . 'includes/providers/mailchimp/class-mailchimp-groups.php';
    if (!defined('DOING_AJAX') || !DOING_AJAX) {
        // Load provider files
        if (is_admin()) {
            require WPBO_PATH . 'includes/providers/mailchimp/settings.php';
            require WPBO_PATH . 'includes/providers/mailchimp/functions-metabox.php';
            require WPBO_PATH . 'includes/providers/mailchimp/functions-admin.php';
        }
        require WPBO_PATH . 'includes/providers/mailchimp/class-provider-mailchimp.php';
    }
    // Instantiate the MailChimp provider
    WPBO_MC();
}
예제 #15
0
 /**
  * Add link to leads.
  *
  * Add a direct link to the list of leads
  * collected by BetterOptin.
  *
  * @since    1.2.1
  */
 public function add_leads_menu()
 {
     $role = wpbo_get_option('wp_default_role');
     $page = add_query_arg(array('role' => $role), 'users.php');
     $this->leads = add_submenu_page('edit.php?post_type=wpbo-popup', __('Leads', 'wpbo'), __('Leads', 'wpbo'), 'administrator', $page);
 }
예제 #16
0
<?php

/**
 * BetterOptin Provider Aweber
 *
 * @package   BetterOptin/Provider/Aweber
 * @author    ThemeAvenue <*****@*****.**>
 * @license   GPL-2.0+
 * @link      http://themeavenue.net
 * @copyright 2015 ThemeAvenue
 */
// If this file is called directly, abort.
if (!defined('WPINC')) {
    die;
}
if ('aweber' === wpbo_get_option('mailing_provider', '')) {
    if (!defined('DOING_AJAX') || !DOING_AJAX) {
        // Load provider files
        if (is_admin()) {
            require WPBO_PATH . 'includes/providers/aweber/settings.php';
            require WPBO_PATH . 'includes/providers/aweber/functions-metabox.php';
            require WPBO_PATH . 'includes/providers/aweber/functions-admin.php';
        }
        require WPBO_PATH . 'includes/providers/aweber/functions-aweber.php';
        require WPBO_PATH . 'includes/providers/aweber/class-aweber.php';
        require WPBO_PATH . 'includes/providers/aweber/class-provider-aweber.php';
    }
}
add_filter('wpbo_mailing_providers', 'wpbo_provider_register_aweber');
/**
 * Register the WordPress provider
예제 #17
0
 /**
  * Get popup return URL
  *
  * @since 2.0
  * @return string
  */
 private function get_return_url()
 {
     $returl = $this->option('return_url', '');
     if (empty($returl)) {
         $returl = wpbo_get_option('return_url', home_url());
     }
     return esc_url($returl);
 }
예제 #18
0
/**
 * Get the standardized provider class name
 *
 * @since 2.0
 * @return string
 */
function wpbo_get_provider_class()
{
    $provider = wpbo_get_option('mailing_provider', '');
    if (empty($provider)) {
        return '';
    }
    $provider = str_replace(' ', '', ucwords(str_replace(array('-', '_'), ' ', sanitize_text_field($provider))));
    $class_name = 'WPBO_Provider_' . $provider;
    return $class_name;
}