PHP utility collection with hybrid and fluent APIs.

⌈⌋ ⎇ branch:  hybrid7 libraries


Check-in [39a0feb20f]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix template() description. State: incomplete. (Had a slightly more clever version lounging around somewhere..)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 39a0feb20ff8f214bcba58df1ee056dbdca0a4ea
User & Date: mario 2014-12-28 16:24:00
Context
2014-12-28
16:30
Array key traversion. (No idea why I kept this here, not related to the rest of h7.) check-in: ef20a08626 user: mario tags: trunk
16:24
Fix template() description. State: incomplete. (Had a slightly more clever version lounging around somewhere..) check-in: 39a0feb20f user: mario tags: trunk
2014-08-14
07:43
Relaxed _http() filter to allow leading numerics in host name, Added missing `p` tag in _strip_markup(). check-in: d467a4be29 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to template.php.

1
2
3
4
5
6
7
8
9

10

11
12


13
14
15
16



17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35

36

37


38
39
40
41
42
43
44
45
46
47
<?php
/**
 * api: php
 * title: PHP7 Templates
 * description: Output/Templating/Views utility code
 * version: 0.1
 * author: php7framwork team: Mario Salzer
 * type: output
 * category: library

 * 

 * 
 * Templating in P7F uses the simplest method that could possibly work:


 *
 *     include(template("index"));   // == template/default/index.en.htm
 *
 * Which gets executed in the current variable scope. It's recommended



 * to base templates upon PHPs short open tags:

 *
 *     <? include(template("defaults")); ?>
 *     <html><head>
 *       <title><?= $title ?></title>
 *     </head><body>
 *       <?= $body ?>
 * 
 * It's advisable to assemble templates with sub templates. The "defaults"
 * should be used in each, because it can instantiate default variables.
 * And it will also contain escaping code for any local output variables:
 *
 *     <? extract(html(get_defined_vars())); // filters local vars ?>
 *
 * Otherwise use above snippet in any template. It ensures that all output
 * is properly HTML-escaped to prevent XSS security exploits.
 *
 * Also:

 * - Utility functions can be defined within here, or in defaults.

 * - Sometimes you want a specific "functions" template also.

 * - template() looks for .php and .htm scripts, and localized variants


 * - $config["template"] usually redirects to "default" in ./template/
 * -
 * -
 *
 */



/**
 * HTML output escaping



|


|


>

>
|
<
>
>



|
>
>
>
|
>







|
|
|

|

|
|

|
>
|
>
|
>
|
>
>

<
<







1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50


51
52
53
54
55
56
57
<?php
/**
 * api: php
 * title: template lookup
 * description: Output/Templating/Views utility code
 * version: 0.1
 * author: mario
 * type: output
 * category: library
 * state: abandoned
 * 
 * Note that this was a pretty crude version, no longer updated.
 *

 * 
 * Implements a extremely trivial templating concept:
 *
 *     include(template("index"));   // == template/default/index.en.htm
 *
 * Which is supposed to inherit the current local variable scope.
 * Therefore only advised for terminating output logic; not between control
 * logic sections.
 *
 * Templates themselves, obviously, should use baseline PHP. Short tags
 * are advised (and just `phptags -l` for portability/transition).
 *
 *     <? include(template("defaults")); ?>
 *     <html><head>
 *       <title><?= $title ?></title>
 *     </head><body>
 *       <?= $body ?>
 * 
 * The "defaults" chaining here is supposed to instantiate predefined
 * variables, predeclare utility functions, and notably contains baseline
 * output filtering of local vars:
 *
 *     <? extract(html(get_defined_vars())); ?>
 *
 * (A more clever approach skipping `$raw_*` or `$html_*` prefixed vars
 * is often needed though.)
 *
 * Notes:
 *
 * - Utility functions can be defined within here, or in `defaults`.
 *
 * - It's sensible to craft more targetted "functions.xy" templates still.
 *
 * - template() looks for .php and .htm scripts, and may switch between
 *   localized variants
 *
 * - $config["template"] usually redirects to "default" in ./template/


 *
 */



/**
 * HTML output escaping