File: README.html-utils

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (110 lines) | stat: -rw-r--r-- 3,438 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
Documentation of common HTML utility functions
──────────────────────────────────────────────

Please take note of the literature links at the bottom of this file.

Functions defined in src/common/include/utils.php → available: always.


• string util_html_encode(string $s)

	util_html_secure('a=1&b=2')
	⇒ 'a=1&b=2'        // HTML-encoded

	util_html_secure('a=1&b=2')
	⇒ 'a=1&b=2'    // changed!

  Encode a string for use in XHTML even if it is already encoded.

• string util_html_secure(string $s)

	util_html_secure('a=1&b=2')
	⇒ 'a=1&b=2'    // HTML-encoded

	util_html_secure('a=1&b=2')
	⇒ 'a=1&b=2'    // unchanged

  Encode a string for use in XHTML if it is not already encoded.
  (So, if you use this for output sanitising, other than a slight
  performance penalty no harm is done if the output was already
  sane.)

• string util_unconvert_htmlspecialchars(string $s)

	util_unconvert_htmlspecialchars('a=1&b=2')
	⇒ 'a=1&b=2'    // unchanged

	util_unconvert_htmlspecialchars('a=1&b=2')
	⇒ 'a=1&b=2'    // HTML-decoded

  Undo util_html_encode; be careful, this can decode partially.


• string util_gethref(optional(false) string $baseurl,
    optional(empty) array $args, optional(true) bool $ashtml,
    optional('&') string $sep)

	util_gethref("/x.php", array(
		'foo' => 'a+b&c',
		'bar' => 'd+b&e',
	    ));
	⇒ "/x.php?foo=a%2Bb%26c&bar=d%2Bb%26e"

	util_gethref("/x.php", array(
		'foo' => 'a+b&c',
		'bar' => 'd+b&e',
	    ), false);
	⇒ /x.php?foo=a%2Bb%26c&bar=d%2Bb%26e

	util_gethref("/x.php", array(
		'foo' => 'a+b&c',
		'bar' => 'd+b&e',
	    ), true, ';')
	⇒ "/x.php?foo=a%2Bb%26c;bar=d%2Bb%26e"

  Construct an URI for use with util_make_url, session_redirect,
  html_e('a', array('href' => …)), and similar. The first argument
  ($baseurl) is passed through as-is but, if falsy, defaults to
  getStringFromServer('PHP_SELF'); the arguments (both keys and
  values) are urlencoded (entries while values is false are not
  emitted at all) and appended, with a question mark in front and
  the $sep separator in between.

  If $ashtml is true (default), the result will then be run through
  util_html_encode; set this to false when using in html_e href as
  value (since html_e will html-encode itself).

• string util_make_url(string $path)

	util_make_url('/foo.php?a=1&b=2')
	⇒ 'https://forge.domain.com/fusionforge/foo.php?a=1&b=2'

  Return an absolute URI for the path in question, containing the
  system-defined protocol, hostname and (if defined) webroot prefix.

  Both html-encoded and not html-encoded return values of util_gethref
  are safe to pass as arguments, if their baseurl was only a path.

• integer|false util_nat0(ByRef string $s)

  If and only if $s is the normalised positive integer (ℕ₀)
  representation of a number, return that number; false otherwise.
  Limited by system constraints, i.e. usually [0;2³¹-1].


‣ common non-HTML utility functions


• mixed util_ifsetor(ByRef mixed $val, optional(false) mixed $default)

  If isset($val), return $val, otherwise (no warning) $default.

• string debug_string_backtrace(void)

  Return the current debugging backtrace as string.


Literature
──────────

• http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/