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 3dcd57c commit 0f34b4b
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 70 deletions.
4 changes: 2 additions & 2 deletions library/api/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

}

Expand Down
81 changes: 46 additions & 35 deletions library/buffer/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -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..' );

Expand All @@ -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(){

Expand Down Expand Up @@ -82,34 +82,20 @@ 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;

}

// 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 );
Expand All @@ -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
*
Expand All @@ -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 );

Expand Down Expand Up @@ -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', [] );
Expand Down
71 changes: 60 additions & 11 deletions library/core/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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 );

}

Expand Down Expand Up @@ -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' )
Expand Down Expand Up @@ -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' );

}

Expand Down Expand Up @@ -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 ) ;

}

Expand Down Expand Up @@ -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 ##
Expand All @@ -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 );

}

Expand Down Expand Up @@ -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" :

Expand Down
17 changes: 17 additions & 0 deletions library/core/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}

}
17 changes: 0 additions & 17 deletions library/core/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion library/core/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'"' );

Expand Down
8 changes: 4 additions & 4 deletions willow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );

}
Expand Down

0 comments on commit 0f34b4b

Please sign in to comment.