Skip to content

Commit

Permalink
1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qstudio committed Sep 3, 2020
1 parent 440bb94 commit c9724b2
Show file tree
Hide file tree
Showing 29 changed files with 1,205 additions and 279 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.3.0 ###

* Formatting flags replaced with extensible filters - https://github.com/qstudio/q-willow/wiki/Tags-Flag

### 1.2.4 ###

* New: {{ [u] Uppercase }} and {{ [l] Lowercase }} filters for variables and strings
Expand Down
25 changes: 6 additions & 19 deletions library/buffer/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function prepare() {

// h::log( 'Row: '.$value['hash'].' is a child to: '.self::$buffer_map[ $row ]['hash'] );

// so, we want to str_replace the value of "tag" in this key, in the "output" of the found key with "output" from this key ##
// so, we need to str_replace the value of "tag" in this key, in the "output" of the found key with "output" from this key... ##
self::$buffer_map[ $row ]['output'] = str_replace( $value['tag'], $value['output'], self::$buffer_map[ $row ]['output'] );

}
Expand All @@ -82,7 +82,7 @@ public static function prepare() {
if(
'0' == $key
|| $value['parent'] // skip rows with a parent value ##
|| ! isset( $value['hash'] ) // ?? added, but not tested much yet ###
|| ! isset( $value['hash'] ) // skip rows without a hash ###
){

continue;
Expand All @@ -107,22 +107,6 @@ public static function prepare() {

// h::log( $string );

// $string = str_replace( ' ', ' ', $string );
// $string = nl2br( htmlentities( $string, ENT_QUOTES, 'UTF-8' ) );
/*
$return = '';
$lines = explode( "\n", $string );
// h::log( $lines );
foreach ($lines as $line) {
$return .= core\method::tab2space($line);
}
// $return = nl2br( htmlentities( $return, ENT_QUOTES, 'UTF-8' ) );
$return = nl2br( $return );
// h::log( $return );
*/

// kick back ##
return $string;

Expand Down Expand Up @@ -157,13 +141,15 @@ public static function get_key_from_value( $key = null, $value = null ){

}

// negative, if not found by now ##
return false;

/*
$result = array_search( $value, array_column( self::$buffer_map, $key ) );
$keys = array_keys(array_column( self::$buffer_map, $key ), $value );
h::log( $keys );
*/
/*
if(
! isset( self::$buffer_map[$result] )
){
Expand All @@ -174,9 +160,10 @@ public static function get_key_from_value( $key = null, $value = null ){
}
h::log( 'key found in row: '.$result );
// h::log( 'key found in row: '.$result );
return $result;
*/

}

Expand Down
1 change: 1 addition & 0 deletions library/buffer/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public static function prepare( String $string = null ) {
// h::log( self::$buffer_markup );

// clean up left over tags ##
// @todo - seems this cleans up willow tags rendered from db calls - need a fix, perhaps ignore inside <code>xx</code> ??
willow\parse::cleanup( self::$buffer_args, 'buffer' );

// clear buffer objects ##
Expand Down
10 changes: 7 additions & 3 deletions library/context/_load.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ class_exists( $namespace ) // && exists ##
// set task tracker -- i.e "title" ##
$args['task'] = $method;

// h::log( self::$args );
// h::log( $args );

// create hash ##
$hash = false;
$hash = $args['context'].'__'.$args['task'].'.'.rand();
$hash = $args['config']['hash'] ?: $args['context'].'__'.$args['task'].'.'.rand(); // HASH now passed from calling Willow ##

// h::log( 'e:>Context Loaded: '.$hash );

Expand Down Expand Up @@ -272,7 +272,7 @@ class_exists( $namespace ) // && exists ##
isset( $args['config']['buffer'] )
){

/// HMMM, but effective ##
// get buffer data ##
$return_array = [ $args['task'] => ob_get_clean() ];

// ob_flush();
Expand Down Expand Up @@ -315,11 +315,15 @@ class_exists( $namespace ) // && exists ##
// assign fields ##
render\fields::define( $return_array );

// h::log( self::$markup['template'] );

// h::log( $return_array );

// prepare field data ##
render\fields::prepare();

// h::log( self::$markup['template'] );

// check if feature is enabled ##
if ( ! render\args::is_enabled() ) {

Expand Down
81 changes: 81 additions & 0 deletions library/core/method.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,4 +911,85 @@ public static function get_acronym( $string = null, $length = 10 ) {
}


/**
* Make a nice hash ( of it.. )
*
* @since 1.2.0
* @return String
*/
public static function hash( $length = 10 ){

$token = "";
$codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$codeAlphabet.= "abcdefghijklmnopqrstuvwxyz";
$codeAlphabet.= "0123456789";
$max = strlen($codeAlphabet); // edited

for ($i=0; $i < $length; $i++) {
$token .= $codeAlphabet[ self::hash_helper( 0, $max-1 ) ];
}

return $token;

}


/**
* Hash Helper
*
* @since 1.2.0
* @return String
*/
public static function hash_helper( $min, $max ){

$range = $max - $min;
if ($range < 1) return $min; // not so random...
$log = ceil(log($range, 2));
$bytes = (int) ($log / 8) + 1; // length in bytes
$bits = (int) $log + 1; // length in bits
$filter = (int) (1 << $bits) - 1; // set all lower bits to 1
do {
$rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));
$rnd = $rnd & $filter; // discard irrelevant bits
} while ($rnd > $range);

return $min + $rnd;

}




/**
* Check is key_exists in MD array
*
* @since 1.2.0
* @return Boolean
*/
public static function array_key_exists( array $array, $key ){

// is in base array?
if ( array_key_exists( $key, $array ) ) {
return true;
}

// check arrays contained in this array
foreach ( $array as $element ) {

if ( is_array( $element ) ) {

if ( self::array_key_exists( $element, $key ) ) {

return true;

}

}

}

return false;
}


}
92 changes: 92 additions & 0 deletions library/filter/.__escape.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace q\willow\filter;

use q\willow\core;
use q\willow\core\helper as h;
use q\willow;
use q\willow\filter;

// load it up ##
\q\willow\filter\escape::__run();

class escape extends willow\filter {

public static function __run(){

// filter variable ##
\add_filter( 'q/willow/render/markup/variable', [ get_class(), 'variable' ], 10, 2 );

// filter tag ##
\add_filter( 'q/willow/render/markup/tag', [ get_class(), 'tag' ], 10, 2 );

}


// @todo - escape entire tag
public static function tag( $value, $key ) {

// h::log( self::$filter );
// h::log( self::$args );

/*
filters stored by context->task with ->global filters and ->variable filters, stored under original [f] flag reference
*/

// h::log( 'e:>Global string escaping on: '.self::$args['context'].'->'.self::$args['task'].'->'.$key );

// global first ##
if(
isset( self::$filter[self::$args['context']][self::$args['task']]['global']['e'] )
|| isset( self::$filter[self::$args['context']][self::$args['task']]['global']['esc'] )
|| isset( self::$filter[self::$args['context']][self::$args['task']]['global']['escape'] )
){

// h::log( 'e:>Global string escaping on: '.self::$args['context'].'->'.self::$args['task'].'->'.$key );

$value = mb_convert_encoding( $value, 'UTF-8', 'UTF-8' );
$value = htmlentities( $value, ENT_QUOTES, 'UTF-8' );

}

return $value;

}



// @todo - escape single variable
public static function variable( $value, $key ) {

// h::log( self::$filter );
// h::log( self::$args );
// h::log( 'Key: '.$key );

/*
filters stored by context->task with ->global filters and ->variable filters, stored under original [f] flag reference
*/

// global first ##
if(
isset( self::$filter[self::$args['context']][self::$args['task']]['variables'][$key]['e'] )
|| isset( self::$filter[self::$args['context']][self::$args['task']]['variables'][$key]['esc'] )
|| isset( self::$filter[self::$args['context']][self::$args['task']]['variables'][$key]['escape'] )
){

// h::log( 'd:>Variable escaping on: '.self::$args['context'].'->'.self::$args['task'].'->'.$key );

// look for {{ variable }}
// h::log( '$value: '.$value );

$value = mb_convert_encoding( $value, 'UTF-8', 'UTF-8' );
$value = htmlentities( $value, ENT_QUOTES, 'UTF-8' );

// h::log( '$value: '.$value );

}

return $value;

}

}
12 changes: 6 additions & 6 deletions library/filter/escape.php → library/filter/.__format.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use q\willow\filter;

// load it up ##
\q\willow\filter\escape::run();
\q\willow\filter\format::__run();

class escape extends willow\filter {
class format extends willow\filter {

public static function run(){
public static function __run(){

// filter variable ##
\add_filter( 'q/willow/render/markup/variable', [ get_class(), 'variable' ], 10, 2 );
Expand All @@ -36,7 +36,9 @@ public static function tag( $value, $key ) {
// h::log( 'e:>Global string escaping on: '.self::$args['context'].'->'.self::$args['task'].'->'.$key );

// global first ##
if( isset( self::$filter[self::$args['context']][self::$args['task']]['global']['e'] ) ){
if(
isset( self::$filter[self::$args['context']][self::$args['task']]['global']['format'] )
){

// h::log( 'e:>Global string escaping on: '.self::$args['context'].'->'.self::$args['task'].'->'.$key );

Expand All @@ -54,8 +56,6 @@ public static function tag( $value, $key ) {
// @todo - escape single variable
public static function variable( $value, $key ) {

// h::log( 't:>ALL values should be escaped - this can be avoided with [u] tag -- plus, we need to remove flags again for search/replace to work...??' );

// h::log( self::$filter );
// h::log( self::$args );
// h::log( 'Key: '.$key );
Expand Down
12 changes: 10 additions & 2 deletions library/filter/lowercase.php → library/filter/.__lowercase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public static function run(){
public static function variable( $value, $key ) {

// global first ##
if( isset( self::$filter[self::$args['context']][self::$args['task']]['variables'][$key]['l'] ) ){
if(
isset( self::$filter[self::$args['context']][self::$args['task']]['variables'][$key]['l'] )
|| isset( self::$filter[self::$args['context']][self::$args['task']]['variables'][$key]['lowercase'] )
|| isset( self::$filter[self::$args['context']][self::$args['task']]['variables'][$key]['strtolower'] )
){

// h::log( 'e:>Variable tag lowercaseping on: '.self::$args['context'].'->'.self::$args['task'].'->'.$key );

Expand All @@ -52,7 +56,11 @@ public static function tag( $value, $key ) {
// h::log( self::$args );

// global first ##
if( isset( self::$filter[self::$args['context']][self::$args['task']]['global']['l'] ) ){
if(
isset( self::$filter[self::$args['context']][self::$args['task']]['global']['l'] )
|| isset( self::$filter[self::$args['context']][self::$args['task']]['global']['lowercase'] )
|| isset( self::$filter[self::$args['context']][self::$args['task']]['global']['strtolower'] )
){

// h::log( 'e:>Global tag lowercaseping on: '.self::$args['context'].'->'.self::$args['task'].'->'.$key );

Expand Down
10 changes: 8 additions & 2 deletions library/filter/nl2br.php → library/filter/.__nl2br.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public static function tag( $value, $key ) {
// h::log( 'e:>Global string escaping on: '.self::$args['context'].'->'.self::$args['task'].'->'.$key );

// global first ##
if( isset( self::$filter[self::$args['context']][self::$args['task']]['global']['n'] ) ){
if(
isset( self::$filter[self::$args['context']][self::$args['task']]['global']['n'] )
|| isset( self::$filter[self::$args['context']][self::$args['task']]['global']['nl2br'] )
){

// h::log( 'e:>Global string escaping on: '.self::$args['context'].'->'.self::$args['task'].'->'.$key );

Expand All @@ -57,7 +60,10 @@ public static function variable( $value, $key ) {
// h::log( 'Key: '.$key );

// global first ##
if( isset( self::$filter[self::$args['context']][self::$args['task']]['variables'][$key]['n'] ) ){
if(
isset( self::$filter[self::$args['context']][self::$args['task']]['variables'][$key]['n'] )
|| isset( self::$filter[self::$args['context']][self::$args['task']]['variables'][$key]['nl2br'] )
){

// h::log( 'd:>Variable escaping on: '.self::$args['context'].'->'.self::$args['task'].'->'.$key );

Expand Down
Loading

0 comments on commit c9724b2

Please sign in to comment.