: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
return $hasInactiveExtensions;
public static function getSubscriptionColumnsById($id)
$popup = SGPopup::find($id);
if (empty($popup) || !is_object($popup)) {
$freeSavedOptions = $popup->getOptionValue('sgpb-subs-fields');
if (!empty($freeSavedOptions)) {
return array('firstName' => 'First name','lastName' => 'Last name', 'email' => 'Email', 'date' => 'Date');
$formFieldsJson = $popup->getOptionValue('sgpb-subscription-fields-json');
if (!empty($formFieldsJson)) {
$data = apply_filters('sgpbGetSubscriptionLabels', array(), $popup);
public static function getCustomFormFieldsByPopupId($popupId)
if (!class_exists('sgpbsubscriptionplus\SubscriptionPlusAdminHelper')) {
if (method_exists('sgpbsubscriptionplus\SubscriptionPlusAdminHelper', 'getCustomFormFieldsByPopupId')) {
return SubscriptionPlusAdminHelper::getCustomFormFieldsByPopupId($popupId);
public static function removeAllNonPrintableCharacters($title, $defaultValue)
$pattern = '/[\\\^£$%&*()}{@#~?><>,|=_+¬-]/u';
$title = preg_replace($pattern, '', $title);
$title = mb_ereg_replace($pattern, '', $title);
$title = htmlspecialchars($title, ENT_IGNORE, 'UTF-8');
$result = str_replace(' ', '', $title);
$titleRes = $defaultValue;
public static function renderCustomScripts($popupId)
$postMeta = get_post_meta($popupId, 'sg_popup_scripts', true);
$defaultData = \SGPBConfigDataHelper::defaultData();
if (!isset($postMeta['js'])) {
$postMeta['js'] = array();
$jsPostMeta = $postMeta['js'];
$jsDefaultData = $defaultData['customEditorContent']['js']['helperText'];
$suspiciousStrings = array('document.createElement', 'createElement', 'String.fromCharCode', 'fromCharCode', '<!--', '-->');
$suspiciousStringFound = false;
if (!empty($jsPostMeta)) {
$customScripts = '<script id="sgpb-custom-script-'.$popupId.'">';
foreach ($jsDefaultData as $key => $value) {
$eventName = 'sgpb'.$key;
if ((!isset($jsPostMeta['sgpb-'.$key]) || empty($jsPostMeta['sgpb-'.$key])) || $key == 'ShouldOpen' || $key == 'ShouldClose') {
$content = isset($jsPostMeta['sgpb-'.$key]) ? $jsPostMeta['sgpb-'.$key] : '';
$content = str_replace('popupId', $popupId, $content);
$content = str_replace("<", "<", $content);
$content = str_replace(">", ">", $content);
foreach ($suspiciousStrings as $string) {
if (strpos($content, $string)) {
$suspiciousStringFound = true;
if ($suspiciousStringFound) {
$content = html_entity_decode($content, ENT_QUOTES, 'UTF-8');
$finalContent .= 'jQuery(document).ready(function(){';
$finalContent .= 'sgAddEvent(window, "'.$eventName.'", function(e) {';
$finalContent .= 'if (e.detail.popupId == "'.$popupId.'") {';
$finalContent .= $content;
$customScripts .= $finalContent;
$customScripts .= '</script>';
if (empty($finalContent)) {
$finalResult .= $customScripts;
if (isset($postMeta['css'])) {
$cssPostMeta = $postMeta['css'];
if (!empty($cssPostMeta)) {
$customStyles = '<style id="sgpb-custom-style-'.$popupId.'">';
$finalContent = str_replace('popupId', $popupId, $cssPostMeta);
$finalContent = html_entity_decode($finalContent, ENT_QUOTES, 'UTF-8');
$customStyles .= $finalContent;
$customStyles .= '</style>';
$finalResult .= $customStyles;
public static function removeSelectedTypeOptions($type)
$crons = _get_cron_array();
foreach ($crons as $key => $value) {
foreach ($value as $key => $body) {
if (strstr($key, 'sgpb')) {
wp_clear_scheduled_hook($key);
public static function getSystemInfoText() {
$browser = self::getBrowser();
if (get_bloginfo('version') < '3.4') {
$themeData = wp_get_theme(get_stylesheet_directory().'/style.css');
$theme = $themeData['Name'].' '.$themeData['Version'];
$themeData = wp_get_theme();
$theme = $themeData->Name.' '.$themeData->Version;
// Try to identify the hosting provider
$systemInfoContent = '### Start System Info ###'."\n\n";
// Start with the basics...
$systemInfoContent .= '-- Site Info'."\n\n";
$systemInfoContent .= 'Site URL: '.site_url()."\n";
$systemInfoContent .= 'Home URL: '.home_url()."\n";
$systemInfoContent .= 'Multisite: '.(is_multisite() ? 'Yes' : 'No')."\n";
// Can we determine the site's host?
$systemInfoContent .= "\n".'-- Hosting Provider'."\n\n";
$systemInfoContent .= 'Host: '.$host."\n";
// The local users' browser information, handled by the Browser class
$systemInfoContent .= "\n".'-- User Browser'."\n\n";
$systemInfoContent .= $browser;
// WordPress configuration
$systemInfoContent .= "\n".'-- WordPress Configuration'."\n\n";
$systemInfoContent .= 'Version: '.get_bloginfo('version')."\n";
$systemInfoContent .= 'Language: '.(defined('WPLANG') && WPLANG ? WPLANG : 'en_US')."\n";
$systemInfoContent .= 'Permalink Structure: '.(get_option('permalink_structure') ? get_option('permalink_structure') : 'Default')."\n";
$systemInfoContent .= 'Active Theme: '.$theme."\n";
$systemInfoContent .= 'Show On Front: '.get_option('show_on_front')."\n";
// Only show page specs if frontpage is set to 'page'
if (get_option('show_on_front') == 'page') {
$frontPageId = get_option('page_on_front');
$blogPageId = get_option('page_for_posts');
$systemInfoContent .= 'Page On Front: '.($frontPageId != 0 ? get_the_title($frontPageId).' (#'.$frontPageId.')' : 'Unset')."\n";
$systemInfoContent .= 'Page For Posts: '.($blogPageId != 0 ? get_the_title($blogPageId).' (#'.$blogPageId.')' : 'Unset')."\n";
$systemInfoContent .= 'Table Prefix: '.'Prefix: '.$wpdb->prefix.' Length: '.strlen($wpdb->prefix ).' Status: '.( strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable')."\n";
$systemInfoContent .= 'WP_DEBUG: '.(defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set')."\n";
$systemInfoContent .= 'Memory Limit: '.WP_MEMORY_LIMIT."\n";
$systemInfoContent .= 'Registered Post Stati: '.implode(', ', get_post_stati())."\n";
$muplugins = get_mu_plugins();
if ($muplugins && count($muplugins)) {
$systemInfoContent .= "\n".'-- Must-Use Plugins'."\n\n";
foreach ($muplugins as $plugin => $plugin_data) {
$systemInfoContent .= $plugin_data['Name'].': '.$plugin_data['Version']."\n";
$registered = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
$registered = json_decode($registered, true);
if (empty($registered)) {
// remove free package data, we don't need it
array_shift($registered);
$systemInfoContent .= "\n".'-- Popup Builder License Data'."\n\n";
if (!empty($registered)) {
foreach ($registered as $singleExntensionData) {
if (empty($singleExntensionData['options'])) {
$key = $singleExntensionData['options']['licence']['key'];
$name = $singleExntensionData['options']['licence']['itemName'];
$licenseKey = __('No license');
$licenseKey = self::getOption('sgpb-license-key-'.$key);
$licenseStatus = 'Inactive';
if (self::getOption('sgpb-license-status-'.$key) == 'valid') {
$licenseStatus = 'Active';
$systemInfoContent .= 'Name: '.$name."\n";
$systemInfoContent .= 'License key: '.$licenseKey."\n";
$systemInfoContent .= 'License status: '.$licenseStatus."\n";
$systemInfoContent .= "\n";
$systemInfoContent .= "\n".'-- All created Popups'."\n\n";
$allPopups = self::getPopupsIdAndTitle();
$args['status'] = array('publish', 'draft', 'pending', 'private', 'trash');
foreach ($allPopups as $id => $popupTitleType) {
$popup = SGPopup::find($id, $args);
$popupStatus = ($popup->getOptionValue('sgpb-is-active')) ? 'Enabled' : 'Disabled';
$systemInfoContent .= 'Id: '.$id."\n";
$systemInfoContent .= 'Title: '.get_the_title($id)."\n";
$systemInfoContent .= 'Type: '.$popup->getOptionValue('sgpb-type')."\n";
$systemInfoContent .= 'Status: '.$popupStatus."\n";
$systemInfoContent .= "\n";
// WordPress active plugins
$systemInfoContent .= "\n".'-- WordPress Active Plugins'."\n\n";
$plugins = get_plugins();
$activePlugins = get_option('active_plugins', array());
foreach ($plugins as $pluginPath => $plugin) {
if (! in_array($pluginPath, $activePlugins)) {
$systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
// WordPress inactive plugins
$systemInfoContent .= "\n".'-- WordPress Inactive Plugins'."\n\n";
foreach ($plugins as $pluginPath => $plugin) {
if (in_array($pluginPath, $activePlugins)) {
$systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
// WordPress Multisite active plugins
$systemInfoContent .= "\n".'-- Network Active Plugins'."\n\n";
$plugins = wp_get_active_network_plugins();
$activePlugins = get_site_option('active_sitewide_plugins', array());
foreach ($plugins as $pluginPath) {
$plugin_base = plugin_basename($pluginPath);
if (! array_key_exists($plugin_base, $activePlugins)) {
$plugin = get_plugin_data($pluginPath);
$systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
// Server configuration (really just versioning)
$systemInfoContent .= "\n".'-- Webserver Configuration'."\n\n";
$systemInfoContent .= 'PHP Version: '.PHP_VERSION."\n";
$systemInfoContent .= 'MySQL Version: '.$wpdb->db_version()."\n";
$serverinfo = isset($_SERVER['SERVER_SOFTWARE']) ? sanitize_text_field($_SERVER['SERVER_SOFTWARE']) : '';
$systemInfoContent .= 'Webserver Info: '.$serverinfo."\n";
// PHP configs... now we're getting to the important stuff
$systemInfoContent .= "\n".'-- PHP Configuration'."\n\n";
$systemInfoContent .= 'Memory Limit: '.ini_get('memory_limit')."\n";
$systemInfoContent .= 'Upload Max Size: '.ini_get('upload_max_filesize')."\n";
$systemInfoContent .= 'Post Max Size: '.ini_get('post_max_size')."\n";
$systemInfoContent .= 'Upload Max Filesize: '.ini_get('upload_max_filesize')."\n";
$systemInfoContent .= 'Time Limit: '.ini_get('max_execution_time')."\n";
$systemInfoContent .= 'Max Input Vars: '.ini_get('max_input_vars')."\n";
$systemInfoContent .= 'Display Errors: '.(ini_get('display_errors') ? 'On ('.ini_get('display_errors').')' : 'N/A')."\n";
// PHP extensions and such
$systemInfoContent .= "\n".'-- PHP Extensions'."\n\n";
$systemInfoContent .= 'cURL: '.(function_exists('curl_init') ? 'Supported' : 'Not Supported')."\n";
$systemInfoContent .= 'fsockopen: '.(function_exists('fsockopen') ? 'Supported' : 'Not Supported')."\n";
$systemInfoContent .= 'SOAP Client: '.(class_exists('SoapClient') ? 'Installed' : 'Not Installed')."\n";
$systemInfoContent .= 'Suhosin: '.(extension_loaded('suhosin') ? 'Installed' : 'Not Installed')."\n";
$systemInfoContent .= "\n".'-- Session Configuration'."\n\n";
$systemInfoContent .= 'Session: '.(isset($_SESSION ) ? 'Enabled' : 'Disabled')."\n";
// The rest of this is only relevant is session is enabled
$systemInfoContent .= 'Session Name: '.esc_html( ini_get('session.name'))."\n";
$systemInfoContent .= 'Cookie Path: '.esc_html( ini_get('session.cookie_path'))."\n";
$systemInfoContent .= 'Save Path: '.esc_html( ini_get('session.save_path'))."\n";
$systemInfoContent .= 'Use Cookies: '.(ini_get('session.use_cookies') ? 'On' : 'Off')."\n";
$systemInfoContent .= 'Use Only Cookies: '.(ini_get('session.use_only_cookies') ? 'On' : 'Off')."\n";
$systemInfoContent = apply_filters('sgpbSystemInformation', $systemInfoContent);
$systemInfoContent .= "\n".'### End System Info ###';
return $systemInfoContent;
public static function getHost()
if (defined('WPE_APIKEY')) {
else if (defined('PAGELYBIN')) {
else if (DB_HOST == 'localhost:/tmp/mysql5.sock') {
else if (DB_HOST == 'mysqlv5') {
return 'NetworkSolutions';
else if (strpos(DB_HOST, 'ipagemysql.com') !== false) {
else if (strpos(DB_HOST, 'ipowermysql.com') !== false) {
else if (strpos(DB_HOST, '.gridserver.com') !== false) {
return 'MediaTemple Grid';
else if (strpos(DB_HOST, '.pair.com') !== false) {
else if (strpos(DB_HOST, '.stabletransit.com') !== false) {
return 'Rackspace Cloud';
else if (strpos(DB_HOST, '.sysfix.eu') !== false) {
return 'SysFix.eu Power Hosting';
else if (isset($_SERVER['SERVER_NAME']) && strpos($_SERVER['SERVER_NAME'], 'Flywheel') !== false) {
// Adding a general fallback for data gathering
$servername = isset($_SERVER['SERVER_NAME']) ? sanitize_text_field($_SERVER['SERVER_NAME']) : '';
return 'DBH: '.DB_HOST.', SRV: '.$servername;
public static function getBrowser()
$uAgent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : 'Unknown';
$bname = $platform = $ub = $version = 'Unknown';
$browserInfoContent = '';
//First get the platform?
if (preg_match('/linux/i', $uAgent)) {
else if (preg_match('/macintosh|mac os x/i', $uAgent)) {
else if (preg_match('/windows|win32/i', $uAgent)) {
if (preg_match('/MSIE/i',$uAgent) && !preg_match('/Opera/i',$uAgent)) {
$bname = 'Internet Explorer';
else if (preg_match('/Firefox/i',$uAgent)) {
$bname = 'Mozilla Firefox';
else if (preg_match('/OPR/i',$uAgent)) {
else if (preg_match('/Chrome/i',$uAgent) && !preg_match('/Edge/i',$uAgent)) {
$bname = 'Google Chrome';
else if (preg_match('/Safari/i',$uAgent) && !preg_match('/Edge/i',$uAgent)) {
else if (preg_match('/Netscape/i',$uAgent)) {
else if (preg_match('/Edge/i',$uAgent)) {
else if (preg_match('/Trident/i',$uAgent)) {
$bname = 'Internet Explorer';
// finally get the correct version number
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>'.implode('|', $known).')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
preg_match_all($pattern, $uAgent, $matches);
$i = count($matches['browser']);
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
if (strripos($uAgent,"Version") < strripos($uAgent,$ub)) {
$version= $matches['version'][0];
$version= $matches['version'][1];
$version= $matches['version'][0];
// check if we have a number
if ($version == null || $version == "") {$version = "?" ;}
$browserInfoContent .= 'Platform: '.$platform."\n";
$browserInfoContent .= 'Browser Name: '.$bname."\n";
$browserInfoContent .= 'Browser Version: '.$version."\n";
$browserInfoContent .= 'User Agent: '.$uAgent."\n";
return $browserInfoContent;
// checking user roles capability to do actions
public static function userCanAccessTo()
$savedUserRolesInPopup = self::getPopupPostAllowedUserRoles();
$currentUserRole = self::getCurrentUserRole();
// we need to check if there are any intersections between saved user roles and current user
$hasIntersection = array_intersect($currentUserRole, $savedUserRolesInPopup);
if (!empty($hasIntersection)) {
public static function filterUserCapabilitiesForTheUserRoles($hook = 'save')
$allAvailableWpRoles = $wp_roles->roles;
$savedUserRoles = get_option('sgpb-user-roles');
// we need to remove from all roles, either when deactivating the plugin and when there is no saved roles
if (empty($savedUserRoles) || $hook == 'deactivate') {
$savedUserRoles = array();