$value;
if (count($userinfo_elements) === 2 && empty($result_value)) {
$result_value = trim($userinfo_elements[1]);
}
$str_input = str_replace('{'.$result_key.'}', urlencode($result_value), $str_input);
}
}
return $str_input;
}
static function replace_user_data($str_input) {
$current_user = wp_get_current_user();
$str_input = AdvancedIframeHelper::replace_key_with_default('userid', 'ID', $str_input,$current_user);
if (empty($current_user->ID)) {
$str_input = AdvancedIframeHelper::replace_key_with_default('username', '', $str_input,$current_user);
$str_input = AdvancedIframeHelper::replace_key_with_default('useremail', '', $str_input,$current_user);
} else {
$str_input = AdvancedIframeHelper::replace_key_with_default('username', 'user_login', $str_input,$current_user);
$str_input = AdvancedIframeHelper::replace_key_with_default('useremail', 'user_email', $str_input,$current_user);
// dynamic $propertyName = 'id'; print($phpObject->{$propertyName});
if (strpos($str_input,'{userinfo') !== false) {
$regex = '/{(userinfo.*?)}/';
$result = preg_match_all( $regex, $str_input, $match);
if ($result) {
foreach ($match[1] as $hits) {
$key = substr($hits, 9);
// we check if we have a default value
$userinfo_elements = explode(",", $key);
if (count($userinfo_elements) === 2) {
$value = $current_user->trim($userinfo_elements[0]);
if (empty($value)) {
$value = trim($userinfo_elements[1]);
}
} else {
$value = $current_user->trim($key);
}
$str_input = str_replace('{'.$hits.'}', urlencode($value), $str_input);
}
}
}
// postmeta! https://codex.wordpress.org/Custom_Fields
if (strpos($str_input,'{usermeta') !== false) {
$regex = '/{(usermeta.*?)}/';
$result = preg_match_all( $regex, $str_input, $match);
if ($result) {
foreach ($match[1] as $hits) {
$key = substr($hits, 9);
// we check if we have a default value
$usermeta_elements = explode(",", $key);
if (count($usermeta_elements) === 2) {
$value = get_user_meta( $current_user->ID, trim($usermeta_elements[0]), true );
if (empty($value)) {
$value = trim($usermeta_elements[1]);
}
} else {
$value = get_user_meta( $current_user->ID, trim($key), true );
}
$str_input = str_replace('{'.$hits.'}', urlencode($value), $str_input);
}
}
}
}
return $str_input;
}
static function replace_full_url_data($str_input) {
if (strpos($str_input,'{href}') !== false) {
$location = (@$_SERVER["HTTPS"] === "on") ? "https://" : "http://";
if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443" ) {
$location .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
$location .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
$str_input = str_replace('{href}', urlencode($location), $str_input);
}
return $str_input;
}
static function replace_query_data($str_input) {
if (strpos($str_input,'{query') !== false) {
$regex = '/{(query.*?)}/';
$result = preg_match_all( $regex, $str_input, $match);
if ($result) {
foreach ($match[1] as $hits) {
$key = substr($hits, 6);
$query_elements = explode(",", $key);
if (count($query_elements) === 2) {
$value = AdvancedIframeHelper::param(trim($query_elements[0]));
if (empty($value)) {
$value = trim($query_elements[1]);
}
} else {
$value = AdvancedIframeHelper::param(trim($key));
}
$str_input = str_replace('{'.$hits.'}', $value , $str_input);
}
}
}
return $str_input;
}
/**
* Handles {language:de,en,es}
*/
static function replace_locale_data($str_input) {
if (strpos($str_input,'{language') !== false) {
$regex = '/{(language.*?)}/';
$result = preg_match_all($regex, $str_input, $match);
if ($result) {
$language = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
foreach ($match[1] as $hits) {
$lang_elements_string = strtolower(substr($hits, 9));
$lang_elements = explode(",", $lang_elements_string);
if (in_array($language, $lang_elements)) {
$str_input = str_replace('{'.$hits.'}', $language , $str_input);
} else {
$str_input = str_replace('{'.$hits.'}', $lang_elements[0] , $str_input);
}
}
}
}
return $str_input;
}
static function removeEmptyParameters($str_input) {
$urlSplit = explode("?", $str_input);
if (!isset($urlSplit[1])) {
return $str_input;
}
$querySplit = explode("#", $urlSplit[1]);
$hash = isset($querySplit[1]) ? '#' . $querySplit[1] : '';
parse_str($querySplit[0], $queryArray);
$cleanedParams = array_filter($queryArray, function($var) {
return isset($var) && (is_array($var) || trim($var) !== '');
});
$count = count($cleanedParams);
$i = 0;
$newURL = $urlSplit[0] ;
foreach ($cleanedParams as $key => $cleanParam){
$newURL .= ($i === 0) ? '?' : '';
// No cleaning is done when arrays are in the params. This could change the logic on the remote side
// if this is removed and not an array anymore...
if (is_array($cleanParam)) {
return $str_input;
} else {
$newURL .= $key . "=" . urlencode($cleanParam) . (($i++ < $count - 1) ? '&' : '');
}
}
return $newURL . $hash;
}
static function replace_url_path_data($str_input) {
if (strpos($str_input,'{requesturi}') !== false) {
$str_input .= trim($_SERVER['REQUEST_URI']);
}
if (strpos($str_input,'{urlpath') !== false) {
// part of the url are extracted {urlpath1} = first path element
$path_elements = explode("/", trim($_SERVER['REQUEST_URI'], "/"));
$count = 1;
foreach($path_elements as $path_element){
$str_input = str_replace('{urlpath'.$count.'}', rawurlencode($path_element), $str_input);
$count++;
}
// part of the url counting from the end {urlpath-1} = last path element
reset($path_elements);
$rpath_elements = array_reverse($path_elements);
$count = 1;
foreach($rpath_elements as $path_element){
$str_input = str_replace('{urlpath-'.$count.'}', rawurlencode($path_element), $str_input);
$count++;
}
}
return $str_input;
}
static function check_shortcode_enabled($check_shortcode) {
return (isset($_GET['aiEnableCheckShortcode'])) ? 'true' : $check_shortcode;
}
static function check_debug_enabled($debug_js) {
return (isset($_COOKIE['aiEnableDebugConsole'])) ? 'bottom' : $debug_js;
}
static function check_debug_get_parameter() {
if (isset($_GET['aiEDC'])) {
$_GET['aiEnableDebugConsole'] = $_GET['aiEDC'];
}
if (isset($_GET['aiEnableDebugConsole'])) {
if ($_GET['aiEnableDebugConsole'] === 'true') {
setcookie('aiEnableDebugConsole', 'bottom', 0, '/');
$_COOKIE['aiEnableDebugConsole'] = 'bottom';
} else {
unset($_COOKIE['aiEnableDebugConsole']);
setcookie('aiEnableDebugConsole', 'bottom', 1, '/');
}
}
}
static function aiUpdateOption($name, $value, $time) {
$fileDir = dirname(__FILE__) . "/../../advanced-iframe-custom/";
$fileName = $fileDir . "iframe-data.csv";
$htaccessName = $fileDir . ".htaccess";
if(!file_exists($htaccessName)) {
file_put_contents($htaccessName, "ErrorDocument 403 /\n
' . $message . '
Please add an unique id to the iframe
"; } } return $content; } static function aiCreateDummyPage($id, $newContent) { $existingPage = AdvancedIframeHelper::aiGetPageByTitle('iframe-' . $id, 'ai_content_page'); // Check if the page already exists if(empty($existingPage)) { $page_id = wp_insert_post( array( 'comment_status' => 'close', 'ping_status' => 'close', 'post_author' => 1, 'post_title' => ucwords('iframe-' . $id), 'post_name' => sanitize_title('iframe-' . $id), 'post_status' => 'publish', 'post_content' => $newContent, 'post_type' => 'ai_content_page', ) ); } else if ($existingPage->post_content != $newContent || $existingPage->post_status != 'publish') { $my_post = array( 'ID' => $existingPage->ID, 'post_content' => $newContent, 'post_status' => 'publish', ); $result = wp_update_post( $my_post, true ); } // generate the url return site_url() . '/ai_content_page/iframe-' . $id . '?' . rand(1000, 9999) ; } static function aiGetPageByTitle( $title, $post_type) { $query = new WP_Query( array( 'post_type' => $post_type, 'title' => $title, 'post_status' => 'all', 'posts_per_page' => 1, 'no_found_rows' => true, 'ignore_sticky_posts' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'orderby' => 'post_date ID', 'order' => 'ASC', ) ); if (!empty( $query->post)) { $page_got_by_title = $query->post; } else { $page_got_by_title = null; } return $page_got_by_title; } static function aiDelecteAiContentPages() { $pages = get_pages( array( 'post_type' => 'ai_content_page', 'post_status' => get_post_stati())); if ($pages != false) { foreach( $pages as $page ) { wp_delete_post( $page->ID, true); } } } static $replaceArrayXSS = array('"',"'",' ', '(',')',';','=','}'); static function filterXSS($value) { return empty($value) ? '' : str_replace(static::$replaceArrayXSS, '', $value); } static function filterXSSTrueFalse($value) { return ($value === 'true' || $value === 'false') ? $value : 'false'; } static $replaceBasicXSS = array('"',"'",' ', '(',')',';','}'); static function filterBasicXSS($value) { return empty($value) ? '' : str_replace(static::$replaceBasicXSS, '', $value); } } ?>