Deprecated: Array and string offset access syntax with curly braces is deprecated in /var/www/html/ticnews.com.br/web/wp-includes/script-loader.php on line 757
Deprecated: Array and string offset access syntax with curly braces is deprecated in /var/www/html/ticnews.com.br/web/wp-includes/script-loader.php on line 757
Deprecated: Array and string offset access syntax with curly braces is deprecated in /var/www/html/ticnews.com.br/web/wp-includes/script-loader.php on line 758
Deprecated: Array and string offset access syntax with curly braces is deprecated in /var/www/html/ticnews.com.br/web/wp-includes/script-loader.php on line 758
as $name => $attributes ) {
// If the variable already exists, keep the old value.
if ( isset( $saved_variables[$name] ) ) {
$new_variables[$name]['value'] = $saved_variables[$name]['value'];
}
}
// Save the new variables to the DB.
$this->_registry->get( 'model.option' )->set(
self::DB_KEY_FOR_LESS_VARIABLES,
$new_variables
);
}
/**
* Get the theme variables from the theme user_variables.php file; also inject
* any other variables provided by extensions.
*
* @return array
*/
public function get_less_variable_data_from_config_file() {
// Load the file to parse using the theme loader to select the right file.
$loader = $this->_registry->get( 'theme.loader' );
$file = $loader->get_file( 'less/user_variables.php', array(), false );
// This variables are returned by evaluating the PHP file.
$variables = $file->get_content();
// Inject extension variables into this array.
return apply_filters( 'ai1ec_less_variables', $variables );
}
/**
* Returns compilation specific hashmap.
*
* @return array Hashmap.
*/
public function get_less_hashmap() {
foreach ( $this->variables as $key => $value ) {
if ( 'fontdir_' === substr( $key, 0, 8 ) ) {
unset( $this->variables[$key] );
}
}
$hashmap = $this->_registry->get(
'filesystem.misc'
)->build_current_theme_hashmap();
$variables = $this->variables;
ksort( $variables );
return array(
'variables' => $variables,
'files' => $hashmap,
);
}
/**
* Returns whether LESS compilation should be performed or not.
*
* @param array|null $variables LESS variables.
*
* @return bool Result.
*
* @throws Ai1ec_Bootstrap_Exception
*/
public function is_compilation_needed( $variables = array() ) {
if (
apply_filters( 'ai1ec_always_recompile_less', false ) ||
(
defined( 'AI1EC_DEBUG' ) &&
AI1EC_DEBUG
)
) {
return true;
}
if ( null === $variables ) {
$variables = array();
}
/* @var $misc Ai1ec_Filesystem_Misc */
$misc = $this->_registry->get( 'filesystem.misc' );
$cur_hashmap = $misc->get_current_theme_hashmap();
if ( empty( $variables ) ) {
$variables = $this->get_saved_variables( false );
}
$variables = $this->convert_less_variables_for_parsing( $variables );
$variables = apply_filters( 'ai1ec_less_constants', $variables );
$variables = $this->_compilation_check_clear_variables( $variables );
ksort( $variables );
if (
null === $cur_hashmap ||
$variables !== $cur_hashmap['variables']
) {
return true;
}
$file_hashmap = $misc->build_current_theme_hashmap();
return ! $misc->compare_hashmaps( $file_hashmap, $cur_hashmap['files'] );
}
/**
* Gets the saved variables from the database, and make sure all variables
* are set correctly as required by config file and any extensions. Also
* adds translations of variable descriptions as required at runtime.
*
* @param $with_description bool Whether to return variables with translated descriptions
* @return array
*/
public function get_saved_variables( $with_description = true ) {
// We don't store description in options table, so find it in current config
// file. Variables from extensions are already injected during this call.
$variables_from_config = $this->get_less_variable_data_from_config_file();
// Fetch current variable settings from options table.
$variables = $this->_registry->get( 'model.option' )->get(
self::DB_KEY_FOR_LESS_VARIABLES,
array()
);
// Generate default variable array from the config file, and union these
// with any saved variables to make sure all required variables are set.
$variables += $variables_from_config;
// Add the description at runtime so that it can be translated.
foreach ( $variables as $name => $attrs ) {
// Also filter out any legacy variables that are no longer found in
// current config file (exceptions thrown if this is not handled here).
if ( ! isset( $variables_from_config[$name] ) ) {
unset( $variables[$name] );
}
else {
// If description is requested and is available in config file, use it.
if (
$with_description &&
isset( $variables_from_config[$name]['description'] )
) {
$variables[$name]['description'] =
$variables_from_config[$name]['description'];
} else {
unset( $variables[$name]['description'] );
}
}
}
return $variables;
}
/**
* Tries to fix the double url as of AIOEC-882
*
* @param string $url
* @return string
*/
public function sanitize_default_theme_url( $url ) {
$pos_http = strrpos( $url, 'http://');
$pos_https = strrpos( $url, 'https://');
// if there are two http
if( 0 !== $pos_http ) {
// cut of the first one
$url = substr( $url, $pos_http );
} else if ( 0 !== $pos_https ) {
$url = substr( $url, $pos_https );
}
return $url;
}
/**
* Drop extraneous attributes from variable array and convertĀ to simple
* key-value pairs required by the LESS parser.
*
* @param array $variables
* @return array
*/
private function convert_less_variables_for_parsing( array $variables ) {
$converted_variables = array();
foreach ( $variables as $variable_name => $variable_params ) {
$converted_variables[$variable_name] = $variable_params['value'];
}
return $converted_variables;
}
/**
* Different themes need different variables.less files. This uses the theme
* loader (searches active theme first, then default) to load it unparsed.
*/
private function load_static_theme_variables() {
$loader = $this->_registry->get( 'theme.loader' );
$file = $loader->get_file( 'variables.less', array(), false );
$this->unparsed_variable_file = $file->get_content();
}
/**
* Load font as base 64 encoded
*
* @param array $matches
* @return string
*/
private function load_font_base64( $matches ) {
// Find out the active theme URL.
$option = $this->_registry->get( 'model.option' );
$theme = $option->get( 'ai1ec_current_theme' );
$dirs = apply_filters(
'ai1ec_font_dirs',
array(
'AI1EC' => array(
$theme['theme_dir'] . DIRECTORY_SEPARATOR . 'font',
AI1EC_DEFAULT_THEME_PATH . DIRECTORY_SEPARATOR . 'font',
)
)
);
$directories = $dirs[$matches[1]];
foreach ( $directories as $dir ) {
$font_file = $dir . DIRECTORY_SEPARATOR . $matches[2];
if ( file_exists( $font_file ) ) {
return base64_encode( file_get_contents( $font_file ) );
}
}
return '';
}
/**
* Removes fontdir variables added by add-ons.
*
* @param array $variables Input variables array.
*
* @return array Modified variables.
*/
protected function _compilation_check_clear_variables( array $variables ) {
foreach ( $variables as $key => $value ) {
if ( 'fontdir_' === substr( $key, 0, 8 ) ) {
unset( $variables[$key] );
}
}
return $variables;
}
}