From 0f34b4bc80cf5a351bf63714ce23f69c524d1753 Mon Sep 17 00:00:00 2001 From: RayQ Date: Tue, 28 Dec 2021 09:16:04 +0000 Subject: [PATCH] 2.1.0 --- library/api/function.php | 4 +- library/buffer/output.php | 81 ++++++++++++++++++++++----------------- library/core/config.php | 71 ++++++++++++++++++++++++++++------ library/core/file.php | 17 ++++++++ library/core/strings.php | 17 -------- library/core/template.php | 2 +- willow.php | 8 ++-- 7 files changed, 130 insertions(+), 70 deletions(-) diff --git a/library/api/function.php b/library/api/function.php index 0e70e4f..540d24b 100644 --- a/library/api/function.php +++ b/library/api/function.php @@ -162,9 +162,9 @@ function w__log_direct( $args = null ){ * @since 1.6.2 * @return Mixed */ -if( ! function_exists( 'w__id' ) ) { +if( ! function_exists( 'w__object' ) ) { - function w__id( $object ){ return $object; } + function w__object( $object ){ return $object; } } diff --git a/library/buffer/output.php b/library/buffer/output.php index 862b0d5..79ca46c 100644 --- a/library/buffer/output.php +++ b/library/buffer/output.php @@ -34,6 +34,15 @@ public function hooks() { return false; } + + // not on admin ## + if ( \is_admin() ) { + + // w__log( 'd:>Not running on admin' ); + + return false; + + } // w__log( 'd:>Buffer hooks run..' ); @@ -43,18 +52,9 @@ public function hooks() { while ( @ob_end_flush() ); } ); - // set _filter var to empty array ## + // set _filter prop to empty array ## \willow()->set( '_filter', [] ); - // not on admin ## - if ( \is_admin() ) { - - // w__log( 'd:>Not running on admin' ); - - return false; - - } - // \add_action( 'get_header', [ get_class(), 'ob_start' ], 0 ); // try -- template_redirect.. was init \add_action( 'wp', function(){ @@ -82,10 +82,8 @@ public function hooks() { // w__log( 'e:>No buffer.. so no go' ); - // ob_flush(); - if( ob_get_level() > 0 ) { - ob_flush(); - } + // flush OB ## + $this->ob_flush(); return false; @@ -93,23 +91,11 @@ public function hooks() { // w__log( 'e:>Doing shutdown buffer' ); - $string = ''; - - // We'll need to get the number of ob levels we're in, so that we can iterate over each, collecting - // that buffer's output into the final output. - $levels = ob_get_level(); - // w__log( $levels ); - - for ($i = 0; $i < $levels; $i++) { - $string .= ob_get_clean(); - } - - // w__log( 'e:>String: '.$string ); - - // ob_flush(); - if( ob_get_level() > 0 ) { - ob_flush(); - } + // get data from OB ## + $string = $this->ob_get(); + + // flush OB ## + $this->ob_flush(); // Output is directly echoed, once it has been parsed ## echo $this->prepare( $string ); @@ -121,6 +107,34 @@ public function hooks() { } + public function ob_get() + { + + $string = ''; + + // We'll need to get the number of ob levels we're in, so that we can iterate over each, collecting + // that buffer's output into the final output. + $levels = ob_get_level(); + // w__log( $levels ); + + for ($i = 0; $i < $levels; $i++) { + $string .= ob_get_clean(); + } + + return $string; + + } + + public function ob_flush() + { + + // ob_flush(); + if( ob_get_level() > 0 ) { + ob_flush(); + } + + } + /** * Prepare output for Buffer * @@ -141,9 +155,6 @@ public function prepare( String $string = null ) { } - // build factory objects ## - // \willow()->factory( $this->plugin ); - // we are passed an html string, captured from output buffering, which we need to parse for tags and process ## // w__log( $string ); @@ -175,7 +186,7 @@ public function prepare( String $string = null ) { // w__log( \willow()->get( '_buffer_markup' ) ); // clean up left over tags ## - \willow()->parse->cleanup->hooks( \willow()->get( '_buffer_args' ), 'primary' ); // @TODO - removed for testing ## + \willow()->parse->cleanup->hooks( \willow()->get( '_buffer_args' ), 'primary' ); // reset properties ## \willow()->set( '_buffer_map', [] ); diff --git a/library/core/config.php b/library/core/config.php index 783badd..e8b6b5d 100644 --- a/library/core/config.php +++ b/library/core/config.php @@ -149,8 +149,8 @@ public function set_cache(){ // if theme debugging, then load from single config files ## if ( \willow()->_debug ) { - // w__log('d:>Deubbing, so we do not need to resave __q.php.' ); - // w__log( 't:>How to dump file / cache and reload from config files, other than to delete __q.php??' ); + // 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??' ); return false; @@ -159,7 +159,7 @@ public function set_cache(){ if ( $this->has_config ){ w__log('d:>We do not need to resave the file, as it already exists' ); - // w__log( 't:>How to dump file / cache and reload from config files, other than to delete __q.php??' ); + // w__log( 't:>How to dump file / cache and reload from config files, other than to delete __willow.php??' ); return false; @@ -176,7 +176,7 @@ public function set_cache(){ // 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( '/__q.php' ), $this->config ); + willow\core\file::put_array( \q\theme\plugin::get_child_path( '/__willow.php' ), $this->config ); } @@ -207,7 +207,7 @@ public function get_cache(){ } - // w__log( 'd:>Child theme method found, so trying to load data from __q.php' ); + // w__log( 'd:>Child theme method found, so trying to load data from __willow.php' ); // w__log( \get_site_transient( 'willow_config' ) ); if ( $array = \get_site_transient( 'willow_config' ) @@ -263,13 +263,13 @@ public function delete_cache(){ if ( method_exists( 'q\theme\plugin', 'get_child_path' ) ){ - $file = \q\theme\plugin::get_child_path('/__q.php'); + $file = \q\theme\plugin::get_child_path('/__willow.php'); if ( $file && file_exists( $file ) ) { unlink( $file ); - // w__log( 'd:>...also deleting __q.php, so cache is clear' ); + // w__log( 'd:>...also deleting __willow.php, so cache is clear' ); } @@ -524,8 +524,8 @@ public function filter( $args = null, $source = null ) { $cache_key = ! is_null( $source ) ? - $k.'_'.$source.'_'.willow\core\strings::file_extension( $file ) : - $k.'_'.willow\core\strings::file_extension( $file ) ; + $k.'_'.$source.'_'.willow\core\file::extension( $file ) : + $k.'_'.willow\core\file::extension( $file ) ; } @@ -651,11 +651,60 @@ public function get( $args = null ) { // filter return with specific context/task/ ## $return = \apply_filters( 'willow/config/get/'.$this->config_args['context'].'/'.$this->config_args['task'], $return ); + // \w__log( $return ); + + // decode htmlentries ## + // $return = $this->html_entity_decode( $return ); + // $return = json_decode( $return ); + + \w__log( $return ); + // kick back ## return $return; } + 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 ## @@ -674,7 +723,7 @@ public function run_filter() { // w__log( $args ); - \apply_filters( 'willow/config/load', $this->config_args ); + $this->config_args = \apply_filters( 'willow/config/load', $this->config_args ); } @@ -729,7 +778,7 @@ public function load( $file = null, $handle = null ){ // w__log( 'dealing with file: '.$file. ' - ext: '.core\strings::file_extension( $file ) ); // get file extension ## - switch( willow\core\strings::file_extension( $file ) ){ + switch( willow\core\file::extension( $file ) ){ case "willow" : diff --git a/library/core/file.php b/library/core/file.php index 0695354..ff89881 100644 --- a/library/core/file.php +++ b/library/core/file.php @@ -33,4 +33,21 @@ public static function put_array( $path, $array ){ } + public static function extension( string $string = null ){ + + // sanity ## + if( is_null( $string ) ){ + + w__log( 'e:>No string passed to method' ); + + return false; + + } + + $n = strrpos( $string, "." ); + + return ( $n === false ) ? "" : substr( $string, $n+1 ); + + } + } diff --git a/library/core/strings.php b/library/core/strings.php index 6f63c5f..3dc3260 100644 --- a/library/core/strings.php +++ b/library/core/strings.php @@ -179,23 +179,6 @@ public static function chop( $content, $length = 0, $preprend = '...' ){ } - public static function file_extension( $string = null ){ - - // sanity ## - if( is_null( $string ) ){ - - w__log( 'e:>No string passed to method' ); - - return false; - - } - - $n = strrpos( $string, "." ); - - return ( $n === false ) ? "" : substr( $string, $n+1 ); - - } - /** * Strip unwated tags and shortcodes from the_content * diff --git a/library/core/template.php b/library/core/template.php index 310112a..8eedeec 100644 --- a/library/core/template.php +++ b/library/core/template.php @@ -56,7 +56,7 @@ public static function format(){ // h::log( 'e:>Template: "'.$template.'"' ); - $extension = \willow\core\strings::file_extension( $template ); + $extension = \willow\core\file::extension( $template ); // h::log( 'e:>Extension: "'.$extension.'"' ); diff --git a/willow.php b/willow.php index 4194b2d..8f9773c 100644 --- a/willow.php +++ b/willow.php @@ -66,7 +66,7 @@ \add_action( 'plugins_loaded', function() use( $plugin ){ // kick off config and store object ## - \w__id( $config = new willow\core\config )->hooks(); + \w__object( $config = new willow\core\config )->hooks(); $plugin->set( 'config', $config ); // extender ## @@ -83,10 +83,10 @@ // build views - required in admin and front-end ## // @todo -- add filter to make views optional ## - \w__id( new willow\core\view )->hooks(); + \w__object( new willow\core\view )->hooks(); // updates ## - \w__id( new willow\core\update )->hooks(); + \w__object( new willow\core\update )->hooks(); // set text domain on init hook ## \add_action( 'init', [ $plugin, 'load_plugin_textdomain' ], 1 ); @@ -158,7 +158,7 @@ // set buffer ## $buffer = new \stdClass(); $buffer->map = new willow\buffer\map(); - \w__id( $buffer->output = new willow\buffer\output )->hooks(); + \w__object( $buffer->output = new willow\buffer\output )->hooks(); $plugin->set( 'buffer', $buffer ); }