/**
  * Initialize the public part of the plugin on every front-end page:
  * Determine how the popup is loaded.
  *
  * @since  4.6
  */
 public function init_public()
 {
     // Load plugin settings.
     $settings = IncPopupDatabase::get_settings();
     // Initialize javascript-data.
     $this->script_data['ajaxurl'] = '';
     $this->script_data['do'] = 'get_data';
     $this->script_data['ajax_data'] = array();
     // Find the current loading method.
     $cur_method = isset($settings['loadingmethod']) ? $settings['loadingmethod'] : 'ajax';
     if (empty($cur_method)) {
         $cur_method = 'ajax';
     }
     if (isset($_POST['_po_method_'])) {
         $cur_method = $_POST['_po_method_'];
     }
     /*
      * Apply the specific loading method to include the popup on the page.
      * Details to the loading methods are documented in the header comment
      * of the "load_method_xyz()" functions.
      */
     switch ($cur_method) {
         case 'ajax':
             // former 'external'
             $this->load_method_ajax();
             break;
         case 'front':
             // former 'frontloading'
             $this->load_method_front();
             if (isset($_GET['action']) && 'inc_popup' == $_GET['action']) {
                 $this->ajax_load_popup();
             }
             break;
         case 'footer':
             $this->load_method_footer();
             break;
         case 'raw':
             // Set via form field "_po_method_"
             $this->load_method_raw();
             break;
         default:
             /**
              * Custom loading handler can be processed by an add-on.
              */
             do_action('popup-init-loading-method', $cur_method, $this);
             break;
     }
 }
 /**
  * Parses the specified content and looks for shortcodes that are not
  * compatible with the current PopUp loading method.
  *
  * The function does not return a value, but if incompatible shortcodes are
  * detected a new Admin Notification will be generated which is displayed to
  * the user after the page has finished loading.
  *
  * @since  4.7.0
  * @param  string $content
  */
 public static function validate_shortcodes($content)
 {
     $settings = IncPopupDatabase::get_settings();
     $method = isset($settings['loadingmethod']) ? $settings['loadingmethod'] : 'ajax';
     // Check for specific/frequently used shortcodes.
     if ('footer' !== $method && preg_match('#\\[gravityforms?(\\s.*?\\]|\\])#', $content)) {
         lib2()->ui->admin_message(sprintf(__('You are using Gravity Forms inside this PopUp. It is best to switch to the <a href="%s">loading method</a> "Page Footer" to ensure the form works as expected.', PO_LANG), 'edit.php?post_type=' . IncPopupItem::POST_TYPE . '&page=settings'), 'err');
     }
     // General check for shortcode incompatibility
     switch ($method) {
         case 'ajax':
         case 'anonymous':
             // Check if the content contains any of the Front-Shortcodes:
             $check = IncPopupAddon_HeaderFooter::check();
             $content = do_shortcode($content);
             foreach ($check->shortcodes as $code) {
                 $match = array();
                 if (preg_match('#\\[' . $code . '(\\s.*?\\]|\\])#', $content, $match)) {
                     lib2()->ui->admin_message(sprintf(__('Shortcode <code>%s</code> requires a different <a href="%s">loading method</a> to work.<br />Try "Page Footer", though sometimes the method "Custom AJAX" also works (please test the result)', PO_LANG), $match[0], 'edit.php?post_type=' . IncPopupItem::POST_TYPE . '&page=settings'), 'err');
                 }
             }
             break;
         case 'footer':
         case 'front':
             // Nothing needs to be validated here...
             break;
         default:
             //lib2()->ui->admin_message( 'Shortcode-Check not defined for: ' . $method );
     }
 }
Example #3
0
<?php

global $shortcode_tags;
// Theme compatibility.
$theme_compat = IncPopupAddon_HeaderFooter::check();
$settings = IncPopupDatabase::get_settings();
$cur_method = $settings['loadingmethod'];
// Shortcodes with restrictions.
$limited = array('app_.*', '.*-form.*', '.*_form.*');
$shortcodes = array();
// Add Admin-Shortcodes to the list.
foreach ($shortcode_tags as $code => $handler) {
    if (!isset($shortcodes[$code])) {
        $shortcodes[$code] = '';
    }
    $shortcodes[$code] .= 'sc-admin ';
}
// Add Front-End Shortcodes to the list.
foreach ($theme_compat->shortcodes as $code) {
    if (!isset($shortcodes[$code])) {
        $shortcodes[$code] = '';
    }
    $shortcodes[$code] .= 'sc-front ';
}
foreach ($shortcodes as $code => $compat) {
    foreach ($limited as $pattern) {
        if (preg_match('/^' . $pattern . '$/i', $code)) {
            $shortcodes[$code] = $compat . 'sc-limited ';
        }
    }
}
 /**
  * Setup or migrate the database to current plugin version.
  *
  * This function uses error suppression on purpose.
  *
  * @since  4.6
  */
 public static function db_update()
 {
     // Required for dbDelta()
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     global $wpdb;
     $charset_collate = '';
     if (!empty($wpdb->charset)) {
         $charset_collate = ' DEFAULT CHARACTER SET ' . $wpdb->charset;
     }
     if (!empty($wpdb->collate)) {
         $charset_collate .= ' COLLATE ' . $wpdb->collate;
     }
     $tbl_popover = self::db_prefix('popover');
     $tbl_ip_cache = self::db_prefix('popover_ip_cache');
     $count = 0;
     if ($wpdb->get_var('SHOW TABLES LIKE "' . $tbl_popover . '" ') == $tbl_popover) {
         // Create a column in old table to monitor migration status.
         $sql = "CREATE TABLE {$tbl_popover} (\r\n\t\t\t\tid bigint(20) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t\tpopover_title varchar(250) DEFAULT NULL,\r\n\t\t\t\tpopover_content text,\r\n\t\t\t\tpopover_settings text,\r\n\t\t\t\tpopover_order bigint(20) DEFAULT '0',\r\n\t\t\t\tpopover_active int(11) DEFAULT '0',\r\n\t\t\t\tmigrated tinyint DEFAULT '0',\r\n\t\t\t\tPRIMARY KEY  (id)\r\n\t\t\t) {$charset_collate};";
         dbDelta($sql);
         // Migrate to custom post type.
         $sql = "\r\n\t\t\tSELECT\r\n\t\t\t\tid,\r\n\t\t\t\tpopover_title,\r\n\t\t\t\tpopover_content,\r\n\t\t\t\tpopover_settings,\r\n\t\t\t\tpopover_order,\r\n\t\t\t\tpopover_active\r\n\t\t\tFROM {$tbl_popover}\r\n\t\t\tWHERE migrated=0\r\n\t\t\t";
         $res = $wpdb->get_results($sql);
         // Name mapping of conditions/rules from build 5 -> 6.
         $mapping = array('isloggedin' => 'login', 'loggedin' => 'no_login', 'onurl' => 'url', 'notonurl' => 'no_url', 'incountry' => 'country', 'notincountry' => 'no_country', 'advanced_urls' => 'adv_url', 'not-advanced_urls' => 'no_adv_url', 'categories' => 'category', 'not-categories' => 'no_category', 'post_types' => 'posttype', 'not-post_types' => 'no_posttype', 'xprofile_value' => 'xprofile', 'not-xprofile_value' => 'no_xprofile', 'supporter' => 'no_prosite', 'searchengine' => 'searchengine', 'commented' => 'no_comment', 'internal' => 'no_internal', 'referrer' => 'referrer', 'count' => 'count', 'max_width' => 'width', 'wp_roles_rule' => 'role', 'membership_level' => 'membership');
         // Translate style to new keys
         $style_mapping = array('Default' => 'old-default', 'Default Fixed' => 'old-fixed', 'Dark Background Fixed' => 'old-fullbackground');
         // Migrate data from build 5 to build 6!
         foreach ($res as $item) {
             // Confirm the item was not migrated, just to be sure...
             // This is one-time code, we don't care for performance here.
             $sql = "\r\n\t\t\t\t\tSELECT 1 status\r\n\t\t\t\t\tFROM {$tbl_popover}\r\n\t\t\t\t\tWHERE id=%s AND migrated=0\r\n\t\t\t\t";
             $sql = $wpdb->prepare($sql, $item->id);
             $status = $wpdb->get_var($sql);
             if ('1' != $status) {
                 continue;
             }
             $raw = maybe_unserialize($item->popover_settings);
             $checks = explode(',', @$raw['popover_check']['order']);
             foreach ($checks as $ind => $key) {
                 if (isset($mapping[$key])) {
                     $checks[$ind] = $mapping[$key];
                 } else {
                     unset($checks[$ind]);
                 }
             }
             if (isset($style_mapping[@$raw['popover_style']])) {
                 $style = $style_mapping[@$raw['popover_style']];
             } else {
                 $style = @$raw['popover_style'];
             }
             $colors = array('col1' => @$raw['popover_colour']['back'], 'col2' => @$raw['popover_colour']['fore']);
             $display = 'delay';
             if (isset($raw['on_exit'])) {
                 $display = 'leave';
             }
             if (isset($raw['on_click'])) {
                 $display = 'click';
             }
             $custom_colors = false;
             if ('FFFFFF' != $colors['col1']) {
                 $custom_colors = true;
             }
             if ('000000' != $colors['col2']) {
                 $custom_colors = true;
             }
             $custom_size = true;
             if (!empty($raw['popover_size']['usejs'])) {
                 $custom_size = false;
             }
             if ('no' != @$raw['popover_usejs']) {
                 $custom_size = false;
             }
             $data = array('name' => $item->popover_title, 'content' => $item->popover_content, 'order' => $item->popover_order, 'active' => true == $item->popover_active, 'size' => @$raw['popover_size'], 'color' => $colors, 'custom_colors' => $custom_colors, 'custom_size' => $custom_size, 'style' => $style, 'can_hide' => 'no' == @$raw['popoverhideforeverlink'], 'close_hides' => 'no' != @$raw['popover_close_hideforever'], 'hide_expire' => absint(@$raw['popover_hideforever_expiry']), 'display' => $display, 'display_data' => array('delay' => absint(@$raw['popoverdelay']), 'delay_type' => 's', 'click' => @$raw['on_click']['selector'], 'click_multi' => !empty($raw['on_click']['selector'])), 'rule' => $checks, 'rule_data' => array('count' => @$raw['popover_count'], 'referrer' => @$raw['popover_ereg'], 'exit' => @$raw['on_exit'], 'url' => @$raw['onurl'], 'no_url' => @$raw['notonurl'], 'adv_url' => @$raw['advanced_urls']['urls'], 'no_adv_url' => @$raw['not-advanced_urls']['urls'], 'country' => @$raw['incountry'], 'no_country' => @$raw['notincountry'], 'category' => @$raw['categories'], 'no_category' => @$raw['not-categories'], 'posttype' => @$raw['post_types'], 'no_posttype' => @$raw['not-post_types'], 'xprofile' => @$raw['xprofile_value'], 'no_xprofile' => @$raw['not-xprofile_value'], 'width' => array('min' => @$raw['max_width']['width'])));
             // Save the popup as custom posttype.
             $popup = new IncPopupItem($data);
             $popup->save(false);
             // Mark Popup as migrated
             $sql = "\r\n\t\t\t\t\tUPDATE {$tbl_popover}\r\n\t\t\t\t\tSET migrated=1\r\n\t\t\t\t\tWHERE id=%s\r\n\t\t\t\t";
             $sql = $wpdb->prepare($sql, $item->id);
             $wpdb->query($sql);
             // Advance counter.
             $count += 1;
         }
     }
     self::refresh_order();
     // Create or update the IP cache table.
     $sql = "\r\n\t\tCREATE TABLE {$tbl_ip_cache} (\r\n\t\t\tIP varchar(12) NOT NULL DEFAULT '',\r\n\t\t\tcountry varchar(2) DEFAULT NULL,\r\n\t\t\tcached bigint(20) DEFAULT NULL,\r\n\t\t\tPRIMARY KEY  (IP),\r\n\t\t\tKEY cached (cached)\r\n\t\t) {$charset_collate};";
     dbDelta($sql);
     if ($count > 0) {
         lib2()->ui->admin_message(sprintf(__('<strong>PopUp Pro</strong><br />' . 'Your installation was successfully updated to use the ' . 'latest version of the plugin!<br />' . '<em>Note: Some PopUp options changed or were replaced. ' . 'You should have a look at your <a href="%s">PopUps</a> ' . 'to see if they still look as intended.</em>', PO_LANG), admin_url('edit.php?post_type=' . IncPopupItem::POST_TYPE)));
     }
     // Migrate the Plugin Settings.
     $old_settings = IncPopupDatabase::_get_option('popover-settings', array());
     $settings = array();
     $cur_method = @$old_settings['loadingmethod'];
     switch ($cur_method) {
         case '':
         case 'external':
             $cur_method = 'ajax';
             break;
         case 'frontloading':
             $cur_method = 'front';
             break;
     }
     $settings['loadingmethod'] = $cur_method;
     // Migrate Add-Ons to new settings.
     // Add-Ons were always saved in the local Options-table by old version.
     self::before_db();
     $addons = get_option('popover_activated_addons', array());
     self::after_db();
     $rules = array('class-popup-rule-browser.php', 'class-popup-rule-geo.php', 'class-popup-rule-popup.php', 'class-popup-rule-referrer.php', 'class-popup-rule-url.php', 'class-popup-rule-user.php', 'class-popup-rule-prosite.php');
     foreach ($addons as $addon) {
         switch ($addon) {
             case 'anonymous_loading.php':
             case 'testheadfooter.php':
                 /* Integrated; no option. */
                 break;
             case 'localgeodatabase.php':
                 $settings['geo_db'] = true;
                 break;
             case 'rules-advanced_url.php':
                 $rules[] = 'class-popup-rule-advurl.php';
                 break;
             case 'rules-categories.php':
                 $rules[] = 'class-popup-rule-category.php';
                 break;
             case 'rules-max_width.php':
                 $rules[] = 'class-popup-rule-width.php';
                 break;
             case 'rules-on_exit.php':
                 $rules[] = 'class-popup-rule-events.php';
                 break;
             case 'rules-onclick.php':
                 $rules[] = 'class-popup-rule-events.php';
                 break;
             case 'rules-post_types.php':
                 $rules[] = 'class-popup-rule-posttype.php';
                 break;
             case 'rules-xprofile_value.php':
                 $rules[] = 'class-popup-rule-xprofile.php';
                 break;
             case 'rules-membership.php':
                 $rules[] = 'class-popup-rule-membership.php';
                 break;
             case 'rules-wp_roles.php':
                 $rules[] = 'class-popup-rule-role.php';
                 break;
         }
     }
     $settings['rules'] = $rules;
     self::set_settings($settings);
     // Save the new DB version to options table.
     self::_set_option('popover_installed', PO_BUILD);
 }
 /**
  * Save the popup data to database
  *
  * @since  4.6.0
  * @param  int $post_id Post ID that was saved/created
  * @param  WP_Post $post Post object that was saved/created
  * @param  bool $update True means the post was updated (not created)
  */
 public static function form_save($post_id, $post, $update)
 {
     $popup = IncPopupDatabase::get($post_id);
     // Make sure the POST collection contains all required fields.
     if (0 !== lib2()->array->equip_post('popup-nonce', 'post_type', 'po-action')) {
         return;
     }
     // Autosave is not processed.
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // The nonce is invalid.
     if (!wp_verify_nonce($_POST['popup-nonce'], 'save-popup')) {
         return;
     }
     // This save event is for a different post type... ??
     if (IncPopupItem::POST_TYPE != $_POST['post_type']) {
         return;
     }
     // Global PopUp modified in a Network-Blog that is not the Main-Blog.
     if (!IncPopup::correct_level()) {
         return;
     }
     // User does not have permissions for this.
     if (!current_user_can(IncPopupPosttype::$perms)) {
         return;
     }
     $action = $_POST['po-action'];
     $status = false;
     switch ($action) {
         case 'save':
             // Don't force a status...
             break;
         case 'activate':
             $status = 'active';
             break;
         case 'deactivate':
             $status = 'inactive';
             break;
         default:
             // Unknown action.
             return;
     }
     // Populate the popup.
     $data = self::prepare_formdata($_POST);
     $data['id'] = $post_id;
     $data['order'] = $popup->order;
     if ($status) {
         $data['status'] = $status;
     }
     $popup->populate($data);
     // Prevent infinite loop when saving.
     remove_action('save_post_' . IncPopupItem::POST_TYPE, array('IncPopup', 'form_save'), 10);
     $popup->save();
     add_action('save_post_' . IncPopupItem::POST_TYPE, array('IncPopup', 'form_save'), 10, 3);
     // Removes the 'message' from the redirect URL.
     add_filter('redirect_post_location', array('IncPopup', 'form_redirect'), 10, 2);
     // Update the PopUp object in WP-Cache.
     IncPopupDatabase::get($post_id, true);
 }
Example #6
0
 /**
  * Returns an array of PopUp objects that should be displayed for the
  * current page/user. The PopUps are in the order in which they are defined
  * in the admin list.
  *
  * @since  4.6
  * @return array List of all popups that fit the current page.
  */
 protected function find_popups()
 {
     $popups = array();
     lib2()->array->equip_request('po_id', 'preview');
     /**
      * Allow other modules to provide a single popup ID to display.
      * The value 0 will use the default logic, which evaluates all active
      * Popups instead of displaying a single Popup.
      *
      * @since 4.8.0.0
      */
     $popup_id = apply_filters('popup-find-popup-single', absint($_REQUEST['po_id']));
     if ($popup_id) {
         // Check for forced popup.
         $popup_ids = array($popup_id);
     } else {
         $popup_ids = IncPopupDatabase::get_active_ids();
     }
     /**
      * Filter the list of Popup IDs that will be considered for display.
      * These Popups will be loaded and their rules evaluated in the next step.
      *
      * @since  4.8.0.0
      */
     $popup_ids = apply_filters('popup-active-popup-ids', $popup_ids, $popup_id, $this);
     foreach ($popup_ids as $id) {
         $popup = IncPopupDatabase::get($id);
         if ($popup_id) {
             // Forced popup ignores all conditions.
             $show = true;
         } else {
             // Apply the conditions to decide if the popup should be displayed.
             $show = apply_filters('popup-apply-rules', true, $popup);
         }
         // Stop here if the popup failed in some conditions.
         if (!$show) {
             continue;
         }
         // Stop here if the user did choose to hide the popup.
         if (!$_REQUEST['preview'] && $this->is_hidden($id)) {
             continue;
         }
         $popups[] = $popup;
     }
     return $popups;
 }
Example #7
0
<?php

/**
 * Metabox "submitdiv"
 *
 * Used in class-popup-admin.php
 * Available variables: $popup
 */
$delete_url = get_delete_post_link($post->ID);
$duplicate_url = esc_url_raw(add_query_arg('do', 'duplicate'));
$warn = 0 != IncPopupDatabase::count_active($post->ID);
?>
<div class="submitbox" id="submitpost">
	<?php 
/* Save/Deactivate/Preview */
?>
	<div id="minor-publishing">
		<?php 
// Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key
?>
		<div style="display:none;">
			<?php 
submit_button(__('Save', PO_LANG), 'button', 'save', false);
?>
		</div>

		<div id="minor-publishing-actions" class="non-sticky">
			<div class="status"
				<?php 
if ($warn) {
    ?>
 /**
  * Returns the lookup-service details
  *
  * @since  4.6.1.1
  * @return object Service object for geo lookup
  */
 protected static function get_service($type = null)
 {
     $service = false;
     if (null === $type) {
         // Default service.
         if (defined('PO_REMOTE_IP_URL') && strlen(PO_REMOTE_IP_URL) > 5) {
             $type = '';
         } else {
             $settings = IncPopupDatabase::get_settings();
             $type = @$settings['geo_lookup'];
         }
     }
     if ('' == $type) {
         $service = (object) array('url' => PO_REMOTE_IP_URL, 'label' => 'wp-config.php', 'type' => 'text');
     } else {
         if ('geo_db' === $type) {
             $service = (object) array('url' => 'db', 'label' => __('Local IP Lookup Table', PO_LANG), 'type' => 'text');
         } else {
             $geo_service = IncPopupDatabase::get_geo_services();
             $service = @$geo_service[$type];
         }
     }
     return $service;
 }
<?php

/**
 * Display the popup settings page.
 */
$loading_methods = IncPopupDatabase::get_loading_methods();
$settings = IncPopupDatabase::get_settings();
$cur_method = $settings['loadingmethod'];
$form_url = esc_url_raw(remove_query_arg(array('message', 'action', '_wpnonce')));
// Theme compatibility.
$theme_compat = IncPopupAddon_HeaderFooter::check();
$theme_class = $theme_compat->okay ? 'msg-ok' : 'msg-err';
// START: Geo Lookup
$geo_service = IncPopupDatabase::get_geo_services();
$no_ip_cache = false;
$custom_geo = false;
$geo_msg = '';
if (!IncPopupAddon_GeoDB::table_exists()) {
    $no_ip_cache = true;
    $settings['geo_db'] = false;
    $geo_msg .= '<p class="locked-msg">' . sprintf(__('<strong>Local IP Lookup Table</strong>: This is unavailable because ' . 'no geo-data table was found in your database. For details, ' . 'read the "Using a Local Geo-Database" in the ' . '<a href="%1$s" target="_blank">PopUp usage guide</a>.', PO_LANG), 'http://premium.wpmudev.org/project/the-pop-over-plugin/#usage') . '</p>';
}
if (defined('PO_REMOTE_IP_URL') && strlen(PO_REMOTE_IP_URL) > 5) {
    $custom_geo = true;
    $settings['geo_lookup'] = '';
    $geo_msg .= '<p class="locked-msg">' . __('<strong>Custom Webservice</strong>: You have configured a custom ' . 'lookup service in <tt>wp-config.php</tt> via the constant ' . '"<tt>PO_REMOTE_IP_URL</tt>". To use one of the default services ' . 'you have to remove that constant from wp-config.php.', PO_LANG) . '</p>';
}
// ----- END: Geo Lookup
$rules = IncPopup::get_rules();
$rule_headers = array('name' => 'Name', 'desc' => 'Description', 'rules' => 'Rules', 'limit' => 'Limit');
$ordered_rules = array();
 /**
  * Replaces selectors in the PopUp HTML/CSS code
  *
  * @since  1.0.0
  * @param  array $data Data collection that is printed to javascript.
  * @param  IncPopupItem $popup The original popup object.
  * @return array Modified data collection.
  */
 public static function filter_script_data($script_data, $popup)
 {
     $settings = IncPopupDatabase::get_settings();
     if (self::METHOD != $settings['loadingmethod']) {
         return $script_data;
     }
     if (!empty($script_data['html']) && !empty($script_data['styles'])) {
         $script_data['html'] = self::_filter($script_data['html'], true);
         $script_data['styles'] = self::_filter($script_data['styles']);
     }
     return $script_data;
 }
Example #11
0
 /**
  * Returns an array of PopUp objects that should be displayed for the
  * current page/user. The PopUps are in the order in which they are defined
  * in the admin list.
  *
  * @since  4.6
  * @return array List of all popups that fit the current page.
  */
 protected function find_popups()
 {
     $popups = array();
     WDev()->load_request_fields('po_id', 'preview');
     $popup_id = absint($_REQUEST['po_id']);
     if ($popup_id) {
         // Check for forced popup.
         $active_ids = array($popup_id);
     } else {
         $active_ids = IncPopupDatabase::get_active_ids();
     }
     foreach ($active_ids as $id) {
         $popup = IncPopupDatabase::get($id);
         if ($popup_id) {
             // Forced popup ignores all conditions.
             $show = true;
         } else {
             // Apply the conditions to decide if the popup should be displayed.
             $show = apply_filters('popup-apply-rules', true, $popup);
         }
         // Stop here if the popup failed in some conditions.
         if (!$show) {
             continue;
         }
         // Stop here if the user did choose to hide the popup.
         if (!$_REQUEST['preview'] && $this->is_hidden($id)) {
             continue;
         }
         $popups[] = $popup;
     }
     return $popups;
 }