Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qstudio committed Dec 28, 2021
1 parent 0f34b4b commit bcc0fdc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 50 deletions.
74 changes: 24 additions & 50 deletions library/core/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public function hooks() {

}

// error_log( 'Helper hooks run..' );

\add_filter( 'willow/config/load',
function( $args ){
$source = 'parent'; // context source ##
Expand Down Expand Up @@ -99,7 +97,7 @@ function( $args ){
public function properties(){

// cache ##
if ( $this->properties_loaded ) return false;
if ( $this->properties_loaded ) return;

// check for child theme path method ##
$this->get_child_path = method_exists( 'q\theme\plugin', 'get_child_path' );
Expand All @@ -108,15 +106,15 @@ public function properties(){
$this->get_parent_path = method_exists( 'q\theme\plugin', 'get_parent_path' );

// config file extension ##
$this->file_extensions = \apply_filters( 'willow/config/load/ext', [
$this->file_extensions = \apply_filters( 'willow/config/load/extensions', [
'.willow',
'.php',
] );

// config file path ( h::get will do fallback checks form child theme, parent theme, plugin + Q.. )
$this->willow_path = \apply_filters( 'willow/config/load/path', 'willow/' );

// template ##
// get current template ##
$this->template = willow\core\template::get() ? willow\core\template::get() : '404';

// update tracker ##
Expand Down Expand Up @@ -147,7 +145,7 @@ public function set_cache(){
}

// if theme debugging, then load from single config files ##
if ( \willow()->_debug ) {
if ( true === \willow()->get( '_debug') ) {

// w__log('d:>Deubbing, so we do not need to resave __willow.php.' );
// w__log( 't:>How to dump file / cache and reload from config files, other than to delete __willow.php??' );
Expand All @@ -165,20 +163,29 @@ public function set_cache(){

}

// check if array is still in JSON format -- if so decode ##
if( ! willow\core\is::json( $this->config ) ){

$this->config = json_encode( $this->config );

}

// cache in DB ##
\set_site_transient( 'willow_config', $this->config, 24 * HOUR_IN_SECONDS );

// w__log('d:>saved config to DB...' );

// return true;

/*
if ( method_exists( 'q\theme\plugin', 'get_child_path' ) ){
// w__log( 'e:>Q Theme class not available, perhaps this function was hooked too early?' );
willow\core\file::put_array( \q\theme\plugin::get_child_path( '/__willow.php' ), $this->config );
}
*/

return true;

Expand All @@ -192,7 +199,7 @@ public function set_cache(){
public function get_cache(){

// if theme debugging, then load from indiviual config files ##
if ( \willow()->get('_debug') ) {
if ( true === \willow()->get('_debug') ) {

// w__log( 'd:>Theme is debugging, so load from individual context files...' );

Expand All @@ -213,6 +220,13 @@ public function get_cache(){
$array = \get_site_transient( 'willow_config' )
) {

// check if array is still in JSON format -- if so decode ##
if( willow\core\is::json( $array ) ){

$array = json_decode( $array );

}

// log ##
// w__log( 'd:>DB Transient Found...' );

Expand Down Expand Up @@ -261,6 +275,7 @@ public function delete_cache(){

// w__log( 'e:>Deleted config cache from DB...' );

/*
if ( method_exists( 'q\theme\plugin', 'get_child_path' ) ){
$file = \q\theme\plugin::get_child_path('/__willow.php');
Expand All @@ -274,6 +289,7 @@ public function delete_cache(){
}
}
*/

// update tracker ##
$this->delete_config = false;
Expand Down Expand Up @@ -591,7 +607,7 @@ public function get( $args = null ) {
$backtrace = willow\core\backtrace::get([ 'level' => 2, 'return' => 'class_function' ]);

// config is loaded by context or process, so we need one of those to continue ##
w__log( 'e:>Q -> '.$backtrace.': config is loaded by context and process, so we need both of those to continue' );
w__log( 'e:>Willow -> '.$backtrace.': config is loaded by context and process, so we need both of those to continue' );

return false;

Expand Down Expand Up @@ -664,47 +680,6 @@ public function get( $args = null ) {

}

public function html_entity_decode( $value ){

// if is a string ##
if( is_string( $value ) ){

$value = html_entity_decode( $value, ENT_NOQUOTES, 'UTF-8');

} else if( is_array( $value ) ){

if ( count($value) == count($value, COUNT_RECURSIVE)) {

\w__log( 'array is not multidimensional' );

$value = array_map(fn($e) => html_entity_decode( $e, ENT_QUOTES, 'UTF-8' ), $value);

} else {

// \w__log( 'array is multidimensional' );
\w__log( $value );
// array_walk_recursive( $value, function ($e) {
// $e = html_entity_decode($e, ENT_QUOTES, 'UTF-8');
// });

}

// $value = html_entity_decode( $value, ENT_NOQUOTES, 'UTF-8');

}

// $return = array_walk_recursive( $return, function ( $value ) {
// $value = html_entity_decode( $value );
// });

// $return = array_walk_recursive(function ($e) {
// return html_entity_decode($e, ENT_NOQUOTES, 'UTF-8');
// }, $return);

return $value;

}

public function run_filter() {

// sanity ##
Expand Down Expand Up @@ -741,7 +716,6 @@ public function load( $file = null, $handle = null ){
if (
is_null( $file )
|| is_null( $handle )
// || is_null( $args )
){

w__log( 'Error in passed params' );
Expand Down
36 changes: 36 additions & 0 deletions library/core/is.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace willow\core;

use willow\core;

class is {

/**
* Check if a string is JSON
*
* @since 2.0.2
*/
public static function json( $string )
{

// if it's not a string, false ##
if( ! is_string( $string ) ) {

return false;

}

json_decode( $string );

if ( json_last_error() === JSON_ERROR_NONE ){

return true;

}

return false;

}

}

0 comments on commit bcc0fdc

Please sign in to comment.