| Server IP : 47.82.179.145 / Your IP : 216.73.217.129 Web Server : nginx/1.26.3 System : Linux iZt4n9czhka2zvqfajdlr2Z 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64 User : www ( 1001) PHP Version : 8.3.30 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/scuipturepactory.com/wp-content/themes/colibri-wp/inc/src/ |
Upload File : |
<?php
namespace ColibriWP\Theme;
use ColibriWP\Theme\Core\Hooks;
use ColibriWP\Theme\Core\Utils;
class HeaderPresets {
private $headers_data = array();
public function __construct() {
$this->loadHeadersData();
Hooks::colibri_add_filter( 'customizer_js_data',
array( $this, 'addHeadersToJSData' ) );
}
public function loadHeadersData() {
if ( ! file_exists( get_template_directory() . "/inc/customizer-headers.php" ) ) {
return;
}
$assets_base_url = get_template_directory_uri() . "/resources/header-presets";
$headers = require_once get_template_directory() . "/inc/customizer-headers.php";
foreach ( $headers as $index => $header ) {
$image = Utils::pathGet( $header, 'image', '' );
$data = Utils::pathGet( $header, 'data', array() );
foreach ( $data as $data_index => $value ) {
$decoded_value = $this->maybeJSONDecode( $value );
if ( ( is_array( $value ) || $decoded_value !== $value ) && is_array( $decoded_value ) ) {
$decoded_value = $this->sprintfRecursive( $decoded_value, $assets_base_url );
$data[ $data_index ] = urlencode( json_encode( $decoded_value ) );
} else {
if ( is_string( $value ) ) {
$data[ $data_index ] = sprintf( $value, $assets_base_url );
}
}
}
$fallback_keys = array(
'header_front_page.icon_list.localProps.iconList',
'header_front_page.social_icons.localProps.icons'
);
foreach ( $fallback_keys as $fallback_key ) {
$data[ $fallback_key ] = Defaults::get( $fallback_key );
}
$headers[ $index ] = array(
'image' => sprintf( $image, "{$assets_base_url}/previews" ),
'data' => $data
);
$this->headers_data = $headers;
}
}
private function maybeJSONDecode( $value ) {
if ( is_string( $value ) && strlen( trim( $value ) ) ) {
// try to decode an url encoded value
$maybe_value = json_decode( urldecode( $value ), true );
if ( json_last_error() === JSON_ERROR_NONE ) {
return $maybe_value;
} else {
// try to decode the value directly
if ( is_string( $value ) ) {
$maybe_value = json_decode( $value, true );
if ( json_last_error() === JSON_ERROR_NONE ) {
return $maybe_value;
}
}
}
}
return $value;
}
public function sprintfRecursive( $array, $arg ) {
if ( ! is_array( $array ) ) {
if ( is_string( $array ) ) {
return sprintf( $array, $arg );
}
return $array;
}
foreach ( $array as $index => $value ) {
$array[ $index ] = $this->sprintfRecursive( $value, $arg );
}
return $array;
}
public function addHeadersToJSData( $data ) {
$data['headers'] = $this->headers_data;
return $data;
}
}