From d0b7317e10254490acbe748d1d8c1e04aaf8be6b Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Wed, 27 Jun 2012 21:09:07 +0200 Subject: Added new Tags to the standard library. * ste:in_array checks, if a value is in an array * ste:join joins an array with a glue string * ste:split splits a string with a delimiter to an array * ste:array_add adds an element to an array. --- docu/language_definition.html | 19 + docu/nd/files/stupid_template_engine-php.html | 12 +- example/templates/transc/articles.html.php | 172 +++++++++ example/templates/transc/custom_tags.tpl.php | 65 ++++ example/templates/transc/master.html.php | 503 ++++++++++++++++++++++++++ stupid_template_engine.php | 38 ++ 6 files changed, 803 insertions(+), 6 deletions(-) create mode 100644 example/templates/transc/articles.html.php create mode 100644 example/templates/transc/custom_tags.tpl.php create mode 100644 example/templates/transc/master.html.php diff --git a/docu/language_definition.html b/docu/language_definition.html index c4dd98b..4cf4aaf 100644 --- a/docu/language_definition.html +++ b/docu/language_definition.html @@ -77,6 +77,10 @@
  • ste:inc
  • ste:dec
  • ste:date
  • +
  • ste:in_array
  • +
  • ste:join
  • +
  • ste:split
  • +
  • ste:array_add
  • @@ -498,5 +502,20 @@ Result:
    18. Sep. 2011, 16:49:20

    + +

    ste:in_array

    +

    Check, if a value is in an array. The tag takes the variable name of the array by parameter array.The value to test with will be taken from the tags content.

    +

    Returns empty text, if the value is not in the array, otherwise a non-empty text.

    + +

    ste:join

    +

    Join parts of an array together. The array's variable name goes to the array parameter. The tag's content will be used as the glue, i.e. this will be between two elements.

    +

    Returns the joined array

    + +

    ste:split

    +

    Split a text and write the parts to an array. The array parameter takes the variable name of the resulting array, the delim parameter the text to split by. The tag's content will be the text to split.

    + +

    ste:array_add

    +

    Adding an element to an array. The array parameter takes the variable name of the array. The key parameter takes the array key to map the value to, if omitted, the value will be appended to the end of the array. The value is the tag's content.

    + diff --git a/docu/nd/files/stupid_template_engine-php.html b/docu/nd/files/stupid_template_engine-php.html index 2d68e6b..1567591 100644 --- a/docu/nd/files/stupid_template_engine-php.html +++ b/docu/nd/files/stupid_template_engine-php.html @@ -63,17 +63,17 @@ if (browserType) {document.write("
    ");if (browserV

    register_tag

    public function register_tag($name,
    $callback)

    Register a custom tag.

    Parameters

    $nameThe name of the tag.
    $callbackA callable function (This must tage three parameters: The STECore instance, an associative array of parameters, and a function representing the tags content(This expects the STECore instance as its only parameter and returns its text result, i.e to get the text, you neeed to call this function with the STECore instance as a parameter)).

    Throws

    An Exception if the tag could not be registered (if $callback is not callable or if $name is empty)

    -

    call_tag

    public function call_tag($name,
    $params,
    $sub)

    Calling a custom tag (builtin ones can not be called)

    Parameters

    $nameThe Tag’s name
    $paramsAssociative array of parameters
    $subA callable function (expecting an STECore instance as it’s parameter) that represents the tag’s content.

    Throws

    Might throw a FatalRuntimeError.

    Returns

    The output of the tag or, if a RuntimeError was thrown, the appropiate result (see <$mute_runtime_errors>).

    +

    call_tag

    public function call_tag($name,
    $params,
    $sub)

    Calling a custom tag (builtin ones can not be called)

    Parameters

    $nameThe Tag’s name
    $paramsAssociative array of parameters
    $subA callable function (expecting an STECore instance as it’s parameter) that represents the tag’s content.

    Throws

    Might throw a FatalRuntimeError (see $fatal_error_on_missing_tag.

    Returns

    The output of the tag or, if a RuntimeError was thrown, the appropiate result (see <$mute_runtime_errors>).

    -

    exectemplate

    public function exectemplate($tpl)

    Executes a template and returns the result.  The huge difference to load is that this function will also output all blocks.

    Parameters

    $tplThe name of the template to execute.

    Returns

    The output of the template.

    +

    exectemplate

    public function exectemplate($tpl)

    Executes a template and returns the result.  The huge difference to load is that this function will also output all blocks.

    Parameters

    $tplThe name of the template to execute.

    Throws

    Returns

    The output of the template.

    -

    get_var_reference

    public function &get_var_reference($name,
    $create_if_not_exist)

    Get a reference to a template variable using a variable name.  This can be used,if your custom tag takes a variable name as a parameter.

    Parameters

    $nameThe variables name.
    $create_if_not_existShould the variable be created, if it does not exist?  Otherwise NULL will be returned, if the variable does not exist.

    Throws

    RuntimeError if the variable name can not be parsed (e.g. unbalanced brackets).

    Returns

    A Reference to the variable.

    +

    get_var_reference

    public function &get_var_reference($name,
    $create_if_not_exist)

    Get a reference to a template variable using a variable name.  This can be used,if your custom tag takes a variable name as a parameter.

    Parameters

    $nameThe variables name.
    $create_if_not_existShould the variable be created, if it does not exist?  Otherwise NULL will be returned, if the variable does not exist.

    Throws

    RuntimeError if the variable name can not be parsed (e.g. unbalanced brackets).

    Returns

    A Reference to the variable.

    -

    set_var_by_name

    public function set_var_by_name($name,
    $val)

    Set a template variable by its name.  This can be used,if your custom tag takes a variable name as a parameter.

    Parameters

    $nameThe variables name.
    $valThe new value.

    Throws

    RuntimeError if the variable name can not be parsed (e.g. unbalanced brackets).

    +

    set_var_by_name

    public function set_var_by_name($name,
    $val)

    Set a template variable by its name.  This can be used,if your custom tag takes a variable name as a parameter.

    Parameters

    $nameThe variables name.
    $valThe new value.

    Throws

    RuntimeError if the variable name can not be parsed (e.g. unbalanced brackets).

    -

    get_var_by_name

    public function get_var_by_name($name)

    Get a template variable by its name.  This can be used,if your custom tag takes a variable name as a parameter.

    Parameters

    $nameThe variables name.

    Throws

    RuntimeError if the variable name can not be parsed (e.g. unbalanced brackets).

    Returns

    The variables value.

    +

    get_var_by_name

    public function get_var_by_name($name)

    Get a template variable by its name.  This can be used,if your custom tag takes a variable name as a parameter.

    Parameters

    $nameThe variables name.

    Throws

    RuntimeError if the variable name can not be parsed (e.g. unbalanced brackets).

    Returns

    The variables value.

    -

    load

    public function load($tpl,  
    $quiet = False)

    Load a template and return its result (blocks not included, use exectemplate for this).

    Parameters

    $tplThe name of the template to be loaded.
    $quietIf true, do not output anything and do notmodify the blocks.  This can be useful to load custom tags that are programmed in STE T/PL.  Default: false.

    Throws

    Returns

    The result of the template (if $quiet == false).

    +

    load

    public function load($tpl,  
    $quiet = False)

    Load a template and return its result (blocks not included, use exectemplate for this).

    Parameters

    $tplThe name of the template to be loaded.
    $quietIf true, do not output anything and do notmodify the blocks.  This can be useful to load custom tags that are programmed in STE T/PL.  Default: false.

    Throws

    Returns

    The result of the template (if $quiet == false).

    evalbool

    public function evalbool($txt)

    Test, if a text represents false (an empty / only whitespace text) or true (everything else).

    Parameters

    $txtThe text to test.

    Returns

    true/false.

    diff --git a/example/templates/transc/articles.html.php b/example/templates/transc/articles.html.php new file mode 100644 index 0000000..d52658c --- /dev/null +++ b/example/templates/transc/articles.html.php @@ -0,0 +1,172 @@ +load("custom_tags.tpl"); + $outputstack[$outputstack_i] .= $ste->load("master.html"); + $blockname_4feb57c8eb53c0_39108239 = "content"; + $ste->blocks['4feb57c8eb54f8.57715029'] = array_pop($outputstack); + $ste->blockorder[] = '4feb57c8eb54f8.57715029'; + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "

    Some Articles

    \n\t"; + $parameters_4feb57c8eb55d1_49937129 = array(); + $parameters_4feb57c8eb55d1_49937129['array'] = "articles"; + $parameters_4feb57c8eb55d1_49937129['value'] = "article"; + $parameters_4feb57c8eb55d1_49937129['max'] = "3"; + $parameters_4feb57c8eb55d1_49937129['counter'] = "i"; + $outputstack[$outputstack_i] .= $ste->call_tag('foreach_limit', $parameters_4feb57c8eb55d1_49937129, function($ste) + { + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "

    "; + $parameters_4feb57c8eb59c3_59434363 = array(); + $outputstack[$outputstack_i] .= $ste->call_tag('uppercase', $parameters_4feb57c8eb59c3_59434363, function($ste) + { + $outputstack = array(''); + $outputstack_i = 0; + $parameters_4feb57c8eb5a98_71645476 = array(); + $outputstack[$outputstack_i] .= $ste->call_tag('escape', $parameters_4feb57c8eb5a98_71645476, function($ste) + { + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= @$ste->vars["article"]["title"]; + return array_pop($outputstack); + }); + return array_pop($outputstack); + }); + $outputstack[$outputstack_i] .= "

    \n\t\t
    Author: "; + $parameters_4feb57c8eb5f92_71020272 = array(); + $outputstack[$outputstack_i] .= $ste->call_tag('escape', $parameters_4feb57c8eb5f92_71020272, function($ste) + { + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= @$ste->vars["article"]["author"]; + return array_pop($outputstack); + }); + $outputstack[$outputstack_i] .= "
    \n\t\t
    "; + $parameters_4feb57c8eb62b8_11002450 = array(); + $parameters_4feb57c8eb62b8_11002450['timestamp'] = @$ste->vars["article"]["timestamp"]; + $outputstack[$outputstack_i] .= $ste->call_tag('date', $parameters_4feb57c8eb62b8_11002450, function($ste) + { + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "%d. %h. %Y, %H:%M:%S"; + return array_pop($outputstack); + }); + $outputstack[$outputstack_i] .= "
    \n\t\t
    \n\t\t\t"; + $outputstack[] = ""; + $outputstack_i++; + $outputstack[$outputstack_i] .= (($ste->get_var_by_name("i")) == ("0")) ? 'yes' : ''; + $outputstack_i--; + if($ste->evalbool(array_pop($outputstack))) + { + $outputstack[$outputstack_i] .= "\n\t\t\t\t\t" . @$ste->vars["article"]["full"]; + + } + else + { + $outputstack[$outputstack_i] .= "\n\t\t\t\t\t" . @$ste->vars["article"]["excerpt"]; + + } + $outputstack[$outputstack_i] .= "
    \n\t\t
    \n\t"; + return array_pop($outputstack); + }); + $outputstack[] = ''; + $outputstack_i++; + $parameters_4feb57c8eb72f3_12728934 = array(); + $parameters_4feb57c8eb72f3_12728934['array'] = "articles"; + $outputstack[$outputstack_i] .= $ste->call_tag('arraylen', $parameters_4feb57c8eb72f3_12728934, function($ste) { return ''; }); + $outputstack_i--; + $ste->set_var_by_name("articles_n", array_pop($outputstack)); + $outputstack[] = ""; + $outputstack_i++; + $outputstack[$outputstack_i] .= ((@$ste->vars["articles_n"]) > ("3")) ? 'yes' : ''; + $outputstack_i--; + if($ste->evalbool(array_pop($outputstack))) + { + $outputstack[$outputstack_i] .= "

    There are more articles.

    \n\t\t"; + + } + $outputstack[$outputstack_i] .= "

    Some more useless demo stuff...

    \n\t\t

    Counting from 10 to 0...

    \n\t\t

    but take only the even ones and multiply by 5...

    \n\t\t"; + $forloop_4feb57c8eb7965_88913250_start = "10"; + $forloop_4feb57c8eb7965_88913250_stop = "0"; + $forloop_4feb57c8eb7965_88913250_countername = "i"; + for($forloop_4feb57c8eb7965_88913250_counter = $forloop_4feb57c8eb7965_88913250_start; $forloop_4feb57c8eb7965_88913250_counter >= $forloop_4feb57c8eb7965_88913250_stop; $forloop_4feb57c8eb7965_88913250_counter += -1) + { + try + { + $ste->set_var_by_name($forloop_4feb57c8eb7965_88913250_countername, $forloop_4feb57c8eb7965_88913250_counter); + $outputstack[] = ""; + $outputstack_i++; + $outputstack[] = ''; + $outputstack_i++; + $outputstack[$outputstack_i] .= @$ste->vars["i"]; + $outputstack_i--; + $tmp_even = array_pop($outputstack); + $outputstack[$outputstack_i] .= (is_numeric($tmp_even) and ($tmp_even % 2 == 0)) ? 'yes' : ''; + $outputstack_i--; + if($ste->evalbool(array_pop($outputstack))) + { + $outputstack[] = ''; + $outputstack_i++; + $outputstack[$outputstack_i] .= @$ste->vars["i"] . " * 5"; + $outputstack_i--; + $outputstack[$outputstack_i] .= $ste->calc(array_pop($outputstack)); + $outputstack[$outputstack_i] .= "
    \n\t\t\t\t"; + + } + + } + catch(\ste\BreakException $e) { break; } + catch(\ste\ContinueException $e) { continue; } + + } + + $outputstack[$outputstack_i] .= "

    Repeat some text...

    \n\t\t"; + $parameters_4feb57c8eb86f4_27000372 = array(); + $parameters_4feb57c8eb86f4_27000372['n'] = "10"; + $outputstack[$outputstack_i] .= $ste->call_tag('repeat', $parameters_4feb57c8eb86f4_27000372, function($ste) + { + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "

    Bla

    \n\t\t"; + return array_pop($outputstack); + }); + $outputstack[$outputstack_i] .= "

    Get a variable's content dynamically

    \n\t\t"; + $outputstack[$outputstack_i] .= $ste->get_var_by_name(@$ste->vars["foo"] . "[" . @$ste->vars["bar"] . "]");$outputstack[$outputstack_i] .= "

    We will call ste:repeat with a non-numerical value for n here to see the handling of a RuntimeError

    \n\t\t"; + $parameters_4feb57c8eb8be8_11772552 = array(); + $parameters_4feb57c8eb8be8_11772552['n'] = "lol"; + $outputstack[$outputstack_i] .= $ste->call_tag('repeat', $parameters_4feb57c8eb8be8_11772552, function($ste) + { + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "

    Bla

    \n\t\t"; + return array_pop($outputstack); + }); + $parameters_4feb57c8eb8e64_48510077 = array(); + $parameters_4feb57c8eb8e64_48510077['array'] = "hai"; + $parameters_4feb57c8eb8e64_48510077['delim'] = ","; + $outputstack[$outputstack_i] .= $ste->call_tag('split', $parameters_4feb57c8eb8e64_48510077, function($ste) + { + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "a,b,c,d,e"; + return array_pop($outputstack); + }); + $parameters_4feb57c8eb91f2_76021324 = array(); + $parameters_4feb57c8eb91f2_76021324['array'] = "hai"; + $outputstack[$outputstack_i] .= $ste->call_tag('join', $parameters_4feb57c8eb91f2_76021324, function($ste) + { + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "
    "; + return array_pop($outputstack); + }); + $ste->blocks[$blockname_4feb57c8eb53c0_39108239] = array_pop($outputstack); + if(array_search($blockname_4feb57c8eb53c0_39108239, $ste->blockorder) === FALSE) + $ste->blockorder[] = $blockname_4feb57c8eb53c0_39108239; + $outputstack = array(''); + $outputstack_i = 0; + return array_pop($outputstack); +}; ?> \ No newline at end of file diff --git a/example/templates/transc/custom_tags.tpl.php b/example/templates/transc/custom_tags.tpl.php new file mode 100644 index 0000000..b92f8a3 --- /dev/null +++ b/example/templates/transc/custom_tags.tpl.php @@ -0,0 +1,65 @@ +vars['_tag_parameters'] = $params; + foreach($mandatory_params as $mp) + { + if(!isset($params[$mp])) + throw new \ste\RuntimeError("$mp missing in ."); + }$foreachloop_4f4e9064144651_57761022_arrayvar = @$ste->vars["_tag_parameters"]["array"]; + $foreachloop_4f4e9064144651_57761022_valuevar = @$ste->vars["_tag_parameters"]["value"]; + $foreachloop_4f4e9064144651_57761022_countervar = "i"; + $foreachloop_4f4e9064144651_57761022_array = $ste->get_var_by_name($foreachloop_4f4e9064144651_57761022_arrayvar); + if(!is_array($foreachloop_4f4e9064144651_57761022_array)) + $foreachloop_4f4e9064144651_57761022_array = array(); + $foreachloop_4f4e9064144651_57761022_counter = -1; + foreach($foreachloop_4f4e9064144651_57761022_array as $foreachloop_4f4e9064144651_57761022_key => $foreachloop_4f4e9064144651_57761022_value) + { + try + { + $foreachloop_4f4e9064144651_57761022_counter++; + $ste->set_var_by_name($foreachloop_4f4e9064144651_57761022_countervar, $foreachloop_4f4e9064144651_57761022_counter); + $ste->set_var_by_name($foreachloop_4f4e9064144651_57761022_valuevar, $foreachloop_4f4e9064144651_57761022_value); + + $outputstack[] = ""; + $outputstack_i++; + $outputstack[$outputstack_i] .= (($ste->get_var_by_name("i")) >= ($ste->get_var_by_name("_tag_parameters[max]"))) ? 'yes' : ''; + $outputstack_i--; + if($ste->evalbool(array_pop($outputstack))) + { + throw new \ste\BreakException(); + + } + $outputstack[] = ""; + $outputstack_i++; + $outputstack[$outputstack_i] .= "\n\t\t\t" . @$ste->vars["_tag_parameters"]["counter"]; + $outputstack_i--; + if($ste->evalbool(array_pop($outputstack))) + { + $outputstack[] = ''; + $outputstack_i++; + $outputstack[$outputstack_i] .= @$ste->vars["i"]; + $outputstack_i--; + $ste->set_var_by_name(@$ste->vars["_tag_parameters"]["counter"], array_pop($outputstack)); + + } + $outputstack[$outputstack_i] .= $sub($ste); + } + catch(\ste\BreakException $e) { break; } + catch(\ste\ContinueException $e) { continue; } + + } + + return array_pop($outputstack); + }; + $ste->register_tag("foreach_limit", $tag_fx); + return array_pop($outputstack); +}; ?> \ No newline at end of file diff --git a/example/templates/transc/master.html.php b/example/templates/transc/master.html.php new file mode 100644 index 0000000..1bee843 --- /dev/null +++ b/example/templates/transc/master.html.php @@ -0,0 +1,503 @@ + ste\TextNode Object + ( + [text] => + + + + [tpl] => master.html + [offset] => 0 + ) + + [1] => ste\TagNode Object + ( + [name] => if + [params] => Array + ( + ) + + [sub] => Array + ( + [0] => ste\VariableNode Object + ( + [name] => title + [arrayfields] => Array + ( + ) + + [tpl] => master.html + [offset] => 206 + ) + + [1] => ste\TagNode Object + ( + [name] => then + [params] => Array + ( + ) + + [sub] => Array + ( + [0] => ste\VariableNode Object + ( + [name] => title + [arrayfields] => Array + ( + ) + + [tpl] => master.html + [offset] => 222 + ) + + [1] => ste\TextNode Object + ( + [text] => - example + [tpl] => master.html + [offset] => 227 + ) + + ) + + [tpl] => master.html + [offset] => 211 + ) + + [2] => ste\TagNode Object + ( + [name] => else + [params] => Array + ( + ) + + [sub] => Array + ( + [0] => ste\TextNode Object + ( + [text] => example + [tpl] => master.html + [offset] => 258 + ) + + ) + + [tpl] => master.html + [offset] => 248 + ) + + ) + + [tpl] => master.html + [offset] => 197 + ) + + [2] => ste\TextNode Object + ( + [text] => + [tpl] => master.html + [offset] => 285 + ) + + [3] => ste\TextNode Object + ( + [text] => + + + +

    example

    + +
    + + [tpl] => master.html + [offset] => 384 + ) + + [4] => ste\TagNode Object + ( + [name] => block + [params] => Array + ( + [name] => Array + ( + [0] => ste\TextNode Object + ( + [text] => content + [tpl] => master.html + [offset] => 626 + ) + + ) + + ) + + [sub] => Array + ( + [0] => ste\TextNode Object + ( + [text] => Default content. + + [tpl] => master.html + [offset] => 635 + ) + + ) + + [tpl] => master.html + [offset] => 609 + ) + + [5] => ste\TextNode Object + ( + [text] =>
    +
    + + [tpl] => master.html + [offset] => 670 + ) + + [6] => ste\TagNode Object + ( + [name] => block + [params] => Array + ( + [name] => Array + ( + [0] => ste\TextNode Object + ( + [text] => otherstuff + [tpl] => master.html + [offset] => 721 + ) + + ) + + ) + + [sub] => Array + ( + [0] => ste\TextNode Object + ( + [text] =>

    List of users

    + + [tpl] => master.html + [offset] => 733 + ) + + [1] => ste\TextNode Object + ( + [text] =>
      + + [tpl] => master.html + [offset] => 820 + ) + + [2] => ste\TagNode Object + ( + [name] => foreach + [params] => Array + ( + [array] => Array + ( + [0] => ste\TextNode Object + ( + [text] => users + [tpl] => master.html + [offset] => 853 + ) + + ) + + [value] => Array + ( + [0] => ste\TextNode Object + ( + [text] => user + [tpl] => master.html + [offset] => 867 + ) + + ) + + ) + + [sub] => Array + ( + [0] => ste\TextNode Object + ( + [text] =>
    • + [tpl] => master.html + [offset] => 975 + ) + + [3] => ste\VariableNode Object + ( + [name] => user + [arrayfields] => Array + ( + [0] => Array + ( + [0] => ste\TextNode Object + ( + [text] => name + [tpl] => master.html + [offset] => 983 + ) + + ) + + ) + + [tpl] => master.html + [offset] => 978 + ) + + [4] => ste\TextNode Object + ( + [text] => ( + [tpl] => master.html + [offset] => 988 + ) + + [5] => ste\VariableNode Object + ( + [name] => user + [arrayfields] => Array + ( + [0] => Array + ( + [0] => ste\TextNode Object + ( + [text] => username + [tpl] => master.html + [offset] => 996 + ) + + ) + + ) + + [tpl] => master.html + [offset] => 991 + ) + + [6] => ste\TextNode Object + ( + [text] => )
    • + + [tpl] => master.html + [offset] => 1005 + ) + + ) + + [tpl] => master.html + [offset] => 833 + ) + + [3] => ste\TextNode Object + ( + [text] =>
    + + [tpl] => master.html + [offset] => 1030 + ) + + ) + + [tpl] => master.html + [offset] => 704 + ) + + [7] => ste\TextNode Object + ( + [text] =>
    + + + + [tpl] => master.html + [offset] => 1054 + ) + +) +*/ + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "\n\n\n\t"; + $outputstack[] = ""; + $outputstack_i++; + $outputstack[$outputstack_i] .= @$ste->vars["title"]; + $outputstack_i--; + if($ste->evalbool(array_pop($outputstack))) + { + $outputstack[$outputstack_i] .= @$ste->vars["title"] . " - example"; + + } + else + { + $outputstack[$outputstack_i] .= "example"; + + } + $outputstack[$outputstack_i] .= "" . "\n\t\n\n\n\t

    example

    \n\t\n\t
    \n\t\t"; + $blockname_4f4e94ddd41342_39491438 = "content"; + $ste->blocks['4f4e94ddd41470.10353359'] = array_pop($outputstack); + $ste->blockorder[] = '4f4e94ddd41470.10353359'; + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "Default content.\n\t\t"; + $ste->blocks[$blockname_4f4e94ddd41342_39491438] = array_pop($outputstack); + if(array_search($blockname_4f4e94ddd41342_39491438, $ste->blockorder) === FALSE) + $ste->blockorder[] = $blockname_4f4e94ddd41342_39491438; + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "
    \n\t
    \n\t\t"; + $blockname_4f4e94ddd415e6_09352068 = "otherstuff"; + $ste->blocks['4f4e94ddd416b2.98760934'] = array_pop($outputstack); + $ste->blockorder[] = '4f4e94ddd416b2.98760934'; + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "

    List of users

    \n\t\t\t" . "
      \n\t\t\t\t"; + $foreachloop_4f4e94ddd417b7_50245786_arrayvar = "users"; + $foreachloop_4f4e94ddd417b7_50245786_valuevar = "user"; + $foreachloop_4f4e94ddd417b7_50245786_array = $ste->get_var_by_name($foreachloop_4f4e94ddd417b7_50245786_arrayvar); + if(!is_array($foreachloop_4f4e94ddd417b7_50245786_array)) + $foreachloop_4f4e94ddd417b7_50245786_array = array(); + foreach($foreachloop_4f4e94ddd417b7_50245786_array as $foreachloop_4f4e94ddd417b7_50245786_key => $foreachloop_4f4e94ddd417b7_50245786_value) + { + try + { + $ste->set_var_by_name($foreachloop_4f4e94ddd417b7_50245786_valuevar, $foreachloop_4f4e94ddd417b7_50245786_value); + + $outputstack[$outputstack_i] .= "
    • vars["user"]["online"]; + $outputstack_i--; + if($ste->evalbool(array_pop($outputstack))) + { + $outputstack[$outputstack_i] .= "online"; + + } + else + { + $outputstack[$outputstack_i] .= "offline"; + + } + $outputstack[$outputstack_i] .= "\">" . @$ste->vars["user"]["name"] . " (" . @$ste->vars["user"]["username"] . ")
    • \n\t\t\t\t"; + + } + catch(\ste\BreakException $e) { break; } + catch(\ste\ContinueException $e) { continue; } + + } + + $outputstack[$outputstack_i] .= "
    \n\t\t"; + $ste->blocks[$blockname_4f4e94ddd415e6_09352068] = array_pop($outputstack); + if(array_search($blockname_4f4e94ddd415e6_09352068, $ste->blockorder) === FALSE) + $ste->blockorder[] = $blockname_4f4e94ddd415e6_09352068; + $outputstack = array(''); + $outputstack_i = 0; + $outputstack[$outputstack_i] .= "
    \n\n\n"; + return array_pop($outputstack); +}; ?> \ No newline at end of file diff --git a/stupid_template_engine.php b/stupid_template_engine.php index 6acb6d7..e8e78ec 100644 --- a/stupid_template_engine.php +++ b/stupid_template_engine.php @@ -1396,6 +1396,44 @@ class STEStandardLibrary { return @strftime($sub($ste), empty($params["timestamp"]) ? @time() : (int) $params["timestamp"]); } + + static public function in_array($ste, $params, $sub) + { + if(empty($params["array"])) + throw new RuntimeError("Missing array parameter in ."); + $ar = &$ste->get_var_reference($params["array"], False); + if(!is_array($ar)) + return ""; + return in_array($sub($ste), $ar) ? "y" : ""; + } + + static public function join($ste, $params, $sub) + { + if(empty($params["array"])) + throw new RuntimeError("Missing array parameter in ."); + return implode($sub($ste), $ste->get_var_by_name($params["array"])); + } + + static public function split($ste, $params, $sub) + { + if(empty($params["array"])) + throw new RuntimeError("Missing array parameter in ."); + if(empty($params["delim"])) + throw new RuntimeError("Missing delim parameter in ."); + $ste->set_var_by_name($params["array"], explode($params["delim"], $sub($ste))); + } + + static public function array_add($ste, $params, $sub) + { + if(empty($params["array"])) + throw new RuntimeError("Missing array parameter in ."); + + $ar = &$ste->get_var_reference($params["array"], True); + if(empty($params["key"])) + $ar[] = $sub($ste); + else + $ar[$params["key"]] = $sub($ste); + } } ?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf