: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use \SGPBConfigDataHelper;
if (class_exists("sgpb\SGPopup")) {
private $postData = array();
private $events = array();
private $savedPopup = false;
public function setId($id)
public function setCurrentPageIdForAjax($id)
$this->ajax_page_id = $id;
public function getCurrentPageIdForAjax()
return (int)$this->ajax_page_id;
public function setTitle($title)
public function getTitle()
public function setType($type)
public function getType()
public function setTarget($target)
public function getTarget()
public function setEvents($events)
public function getEvents()
public function setConditions($conditions)
$this->conditions = $conditions;
public function getConditions()
return $this->conditions;
public function setOptions($options)
$this->options = $options;
public function getOptions()
public function setLoadableModes($loadableModes)
$this->loadableModes = $loadableModes;
public function getLoadableModes()
return $this->loadableModes;
public function setSaveMode($saveMode)
$this->saveMode = $saveMode;
public function getSaveMode()
public function setSavedPopup($savedPopup)
$this->savedPopup = $savedPopup;
public function getSavedPopup()
return $this->savedPopup;
public function setContent($content)
$this->content = $content;
public function setSavedPopupById($popupId)
$popup = SGPopup::find($popupId);
$this->setSavedPopup($popup);
public function setReportData($popupId)
$events = $this->getEvents();
$options = $this->getOptions();
$targets = $this->getTarget();
$conditions = $this->getConditions();
do_action('sgpbDebugReportUpdate', 'options', $options, $popupId);
do_action('sgpbDebugReportUpdate', 'events', $events, $popupId);
do_action('sgpbDebugReportUpdate', 'targets', $targets, $popupId);
do_action('sgpbDebugReportUpdate', 'conditions', $conditions, $popupId);
public function getPopupAllEvents($postId, $popupId, $popupObj = false)
$loadableModes = $this->getLoadableModes();
if (isset($loadableModes['attr_event'])) {
$customEvents = SGPopup::getPostPopupCustomEvent($postId, $popupId);
$events = array_merge($events, $customEvents);
if (isset($loadableModes['option_event']) || is_null($loadableModes)) {
$optionEvents = $this->getEvents();
if (!is_array($optionEvents)) {
$events = array_merge($events, $optionEvents);
if (!empty($popupObj->getOptionValue('sgpb-enable-floating-button'))) {
$events[] = array('param' => 'setByCssClass', 'hiddenOption' => array());
return apply_filters('sgpbPopupEvents', $events, $popupObj);
public function getContent()
$postId = $this->getId();
if (!AdminHelper::hasBlocks($this->content)) {
$popupContent = wpautop($this->content);
$popupContent = $this->content;
$editorContent = AdminHelper::checkEditorByPopupId($postId);
if (!empty($editorContent)) {
if (class_exists('Vc_Manager')) {
$popupContent .= $editorContent;
$popupContent = $editorContent;
public function setPostData($postData)
$this->postData = apply_filters('sgpbSavedPostData', $postData);
public function getPostData()
public function getPopupTypeContent()
return $this->getContent();
public function insertIntoSanitizedData($sanitizedData)
if (!empty($sanitizedData)) {
$this->sanitizedData[$sanitizedData['name']] = $sanitizedData['value'];
abstract public function getExtraRenderOptions();
public function setSanitizedData($sanitizedData)
$this->sanitizedData = $sanitizedData;
public function getSanitizedData()
return $this->sanitizedData;
* Find popup and create this object
* @param object|int $popup
* @return object|false $obj
public static function find($popup, $args = array())
if (isset($_GET['sg_popup_preview_id'])) {
$args['is-preview'] = true;
// If the popup is object get data from object otherwise we find needed data from WordPress functions
if ($popup instanceof WP_Post) {
$status = $popup->post_status;
$title = $popup->post_title;
$popupContent = $popup->post_content;
$popupPost = get_post($popupId);
$title = get_the_title($popupId);
$status = get_post_status($popupId);
$popupContent = $popupPost->post_content;
$allowedStatus = array('publish', 'draft', 'private');
if (!empty($args['status'])) {
$allowedStatus = $args['status'];
if (!isset($args['checkActivePopupType']) && !in_array($status, $allowedStatus)) {
if ((@is_preview() && $post->ID == $popupId) || isset($args['preview'])) {
if (isset($args['is-preview'])) {
if (isset($args['insidePopup']) && $args['insidePopup'] == 'on') {
$currentPost = get_post($popupId);
$currentPostStatus = $currentPost->post_status;
if ($currentPostStatus == 'draft') {
if (file_exists(dirname(__FILE__).'/PopupData.php')) {
require_once(dirname(__FILE__).'/PopupData.php');
$savedData = PopupData::getPopupDataById($popupId, $saveMode);
$savedData = apply_filters('sgpbPopupSavedData', $savedData);
if (empty($savedData) && $currentPostStatus !== 'trash') {
if (isset($savedData['sgpb-type'])) {
$type = $savedData['sgpb-type'];
$popupClassName = self::getPopupClassNameFormType($type);
$typePath = self::getPopupTypeClassPath($type);
if (!file_exists($typePath.$popupClassName.'.php')) {
require_once($typePath.$popupClassName.'.php');
$popupClassName = __NAMESPACE__.'\\'.$popupClassName;
$obj = new $popupClassName();
$obj->setContent($popupContent);
if (!empty($savedData['sgpb-target'][0])) {
$obj->setTarget($savedData['sgpb-target'][0]);
unset($savedData['sgpb-target']);
if (!empty($savedData['sgpb-events'][0])) {
$events = self::shapeEventsToOneArray($savedData['sgpb-events'][0]);
$obj->setEvents($events);
unset($savedData['sgpb-events']);
if (!empty($savedData['sgpb-conditions'][0])) {
$obj->setConditions($savedData['sgpb-conditions'][0]);
unset($savedData['sgpb-conditions']);
$obj->setOptions($savedData);
private static function shapeEventsToOneArray($events)
foreach ($events as $event) {
if (empty($event['hiddenOption'])) {
$hiddenOptions = $event['hiddenOption'];
unset($event['hiddenOption']);
$eventsData[] = $event + $hiddenOptions;
return apply_filters('sgpbEventsToOneArray', $eventsData);
public static function getPopupClassNameFormType($type)
$popupName = ucfirst(strtolower($type));
$popupClassName = $popupName.'Popup';
return apply_filters('sgpbPopupClassNameFromType', $popupClassName);
public static function getPopupTypeClassPath($type)
global $SGPB_POPUP_TYPES;
$typePaths = $SGPB_POPUP_TYPES['typePath'];
if (empty($typePaths[$type])) {
return SG_POPUP_CLASSES_POPUPS_PATH;
return $typePaths[$type];
public function sanitizeValueByType($value, $type)
$sanitizedValue = $this->recursiveSanitizeTextField($value);
$sanitizedValue = htmlspecialchars($value);
$sanitizedValue = htmlspecialchars($value);
$sanitizedValue = $this->recursiveSanitizeTextField($value);
$sanitizedValue = sanitize_email($value);
$sanitizedValue = $this->recursiveHtmlSpecialchars($value);
$sanitizedValue = sanitize_text_field($value);
public static function sanitize_multidimensional_array($array) {
$sanitized_array = array();
foreach ($array as $key => $value) {
// If the value is an array, recursively sanitize it
$sanitized_array[$key] = SGPopup::sanitize_multidimensional_array($value);
// If the value is a string, sanitize it
$sanitized_array[$key] = is_string($value) ? sanitize_text_field($value) : $value;
public function recursiveSanitizeTextField($array)
foreach ($array as $key => &$value) {
$value = $this->recursiveSanitizeTextField($value);
/*get simple field type and do sanitization*/
$defaultData = $this->getDefaultDataByName($key);
if (empty($defaultData['type'])) {
$defaultData['type'] = 'string';
$value = $this->sanitizeValueByType($value, $defaultData['type']);
public function recursiveHtmlSpecialchars($array)
foreach ($array as $key => &$value) {
$value = $this->recursiveHtmlSpecialchars($value);
$value = htmlspecialchars($value);
public static function parsePopupDataFromData($data)
// Do not processing the whole input
$data = apply_filters('sgpbFilterOptionsBeforeSaving', $data);
foreach ($data as $key => $value) {
// Skip processing if the key is not essential
if ( !is_array( $value ) ) {
//Sanitize URL to avoid 404 error
if ( strpos( $key, '-url' ) === false )
$value = sanitize_text_field( $value );
$value = wp_sanitize_redirect( $value );
$value = SGPopup::sanitize_multidimensional_array( $value );
$popupData[$key] = $value;