@@ -21,5 +21,5 @@ |
||
21 | 21 | */ |
22 | 22 | function Dwoo_Plugin_lower_compile(Dwoo_Compiler $compiler, $value) |
23 | 23 | { |
24 | - return 'mb_strtolower((string) '.$value.', $this->charset)'; |
|
24 | + return 'mb_strtolower((string) '.$value.', $this->charset)'; |
|
25 | 25 | } |
@@ -29,94 +29,94 @@ |
||
29 | 29 | */ |
30 | 30 | function Dwoo_Plugin_mailto(Dwoo_Core $dwoo, $address, $text = null, $subject = null, $encode = null, $cc = null, $bcc = null, $newsgroups = null, $followupto = null, $extra = null) |
31 | 31 | { |
32 | - if (empty($address)) { |
|
33 | - return ''; |
|
34 | - } |
|
35 | - if (empty($text)) { |
|
36 | - $text = $address; |
|
37 | - } |
|
38 | - |
|
39 | - // build address string |
|
40 | - $address .= '?'; |
|
41 | - |
|
42 | - if (!empty($subject)) { |
|
43 | - $address .= 'subject='.rawurlencode($subject).'&'; |
|
44 | - } |
|
45 | - if (!empty($cc)) { |
|
46 | - $address .= 'cc='.rawurlencode($cc).'&'; |
|
47 | - } |
|
48 | - if (!empty($bcc)) { |
|
49 | - $address .= 'bcc='.rawurlencode($bcc).'&'; |
|
50 | - } |
|
51 | - if (!empty($newsgroups)) { |
|
52 | - $address .= 'newsgroups='.rawurlencode($newsgroups).'&'; |
|
53 | - } |
|
54 | - if (!empty($followupto)) { |
|
55 | - $address .= 'followupto='.rawurlencode($followupto).'&'; |
|
56 | - } |
|
57 | - |
|
58 | - $address = rtrim($address, '?&'); |
|
59 | - |
|
60 | - // output |
|
61 | - switch ($encode) { |
|
62 | - |
|
63 | - case 'none': |
|
64 | - case null: |
|
65 | - return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>'; |
|
66 | - |
|
67 | - case 'js': |
|
68 | - case 'javascript': |
|
69 | - $str = 'document.write(\'<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>\');'; |
|
70 | - $len = strlen($str); |
|
71 | - |
|
72 | - $out = ''; |
|
73 | - for ($i = 0; $i < $len; ++$i) { |
|
74 | - $out .= '%'.bin2hex($str[$i]); |
|
75 | - } |
|
76 | - |
|
77 | - return '<script type="text/javascript">eval(unescape(\''.$out.'\'));</script>'; |
|
78 | - |
|
79 | - break; |
|
80 | - case 'javascript_charcode': |
|
81 | - case 'js_charcode': |
|
82 | - case 'jscharcode': |
|
83 | - case 'jschar': |
|
84 | - $str = '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>'; |
|
85 | - $len = strlen($str); |
|
86 | - |
|
87 | - $out = '<script type="text/javascript">'."\n<!--\ndocument.write(String.fromCharCode("; |
|
88 | - for ($i = 0; $i < $len; ++$i) { |
|
89 | - $out .= ord($str[$i]).','; |
|
90 | - } |
|
91 | - |
|
92 | - return rtrim($out, ',')."));\n-->\n</script>\n"; |
|
93 | - |
|
94 | - break; |
|
95 | - |
|
96 | - case 'hex': |
|
97 | - if (strpos($address, '?') !== false) { |
|
98 | - $dwoo->triggerError('Mailto: Hex encoding is not possible with extra attributes, use one of : <em>js, jscharcode or none</em>.', E_USER_WARNING); |
|
99 | - } |
|
100 | - |
|
101 | - $out = '<a href="mailto:'; |
|
102 | - $len = strlen($address); |
|
103 | - for ($i = 0; $i < $len; ++$i) { |
|
104 | - if (preg_match('#\w#', $address[$i])) { |
|
105 | - $out .= '%'.bin2hex($address[$i]); |
|
106 | - } else { |
|
107 | - $out .= $address[$i]; |
|
108 | - } |
|
109 | - } |
|
110 | - $out .= '" '.$extra.'>'; |
|
111 | - $len = strlen($text); |
|
112 | - for ($i = 0; $i < $len; ++$i) { |
|
113 | - $out .= '&#x'.bin2hex($text[$i]); |
|
114 | - } |
|
115 | - |
|
116 | - return $out.'</a>'; |
|
117 | - |
|
118 | - default: |
|
119 | - $dwoo->triggerError('Mailto: <em>encode</em> argument is invalid, it must be one of : <em>none (= no value), js, js_charcode or hex</em>', E_USER_WARNING); |
|
120 | - |
|
121 | - } |
|
32 | + if (empty($address)) { |
|
33 | + return ''; |
|
34 | + } |
|
35 | + if (empty($text)) { |
|
36 | + $text = $address; |
|
37 | + } |
|
38 | + |
|
39 | + // build address string |
|
40 | + $address .= '?'; |
|
41 | + |
|
42 | + if (!empty($subject)) { |
|
43 | + $address .= 'subject='.rawurlencode($subject).'&'; |
|
44 | + } |
|
45 | + if (!empty($cc)) { |
|
46 | + $address .= 'cc='.rawurlencode($cc).'&'; |
|
47 | + } |
|
48 | + if (!empty($bcc)) { |
|
49 | + $address .= 'bcc='.rawurlencode($bcc).'&'; |
|
50 | + } |
|
51 | + if (!empty($newsgroups)) { |
|
52 | + $address .= 'newsgroups='.rawurlencode($newsgroups).'&'; |
|
53 | + } |
|
54 | + if (!empty($followupto)) { |
|
55 | + $address .= 'followupto='.rawurlencode($followupto).'&'; |
|
56 | + } |
|
57 | + |
|
58 | + $address = rtrim($address, '?&'); |
|
59 | + |
|
60 | + // output |
|
61 | + switch ($encode) { |
|
62 | + |
|
63 | + case 'none': |
|
64 | + case null: |
|
65 | + return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>'; |
|
66 | + |
|
67 | + case 'js': |
|
68 | + case 'javascript': |
|
69 | + $str = 'document.write(\'<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>\');'; |
|
70 | + $len = strlen($str); |
|
71 | + |
|
72 | + $out = ''; |
|
73 | + for ($i = 0; $i < $len; ++$i) { |
|
74 | + $out .= '%'.bin2hex($str[$i]); |
|
75 | + } |
|
76 | + |
|
77 | + return '<script type="text/javascript">eval(unescape(\''.$out.'\'));</script>'; |
|
78 | + |
|
79 | + break; |
|
80 | + case 'javascript_charcode': |
|
81 | + case 'js_charcode': |
|
82 | + case 'jscharcode': |
|
83 | + case 'jschar': |
|
84 | + $str = '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>'; |
|
85 | + $len = strlen($str); |
|
86 | + |
|
87 | + $out = '<script type="text/javascript">'."\n<!--\ndocument.write(String.fromCharCode("; |
|
88 | + for ($i = 0; $i < $len; ++$i) { |
|
89 | + $out .= ord($str[$i]).','; |
|
90 | + } |
|
91 | + |
|
92 | + return rtrim($out, ',')."));\n-->\n</script>\n"; |
|
93 | + |
|
94 | + break; |
|
95 | + |
|
96 | + case 'hex': |
|
97 | + if (strpos($address, '?') !== false) { |
|
98 | + $dwoo->triggerError('Mailto: Hex encoding is not possible with extra attributes, use one of : <em>js, jscharcode or none</em>.', E_USER_WARNING); |
|
99 | + } |
|
100 | + |
|
101 | + $out = '<a href="mailto:'; |
|
102 | + $len = strlen($address); |
|
103 | + for ($i = 0; $i < $len; ++$i) { |
|
104 | + if (preg_match('#\w#', $address[$i])) { |
|
105 | + $out .= '%'.bin2hex($address[$i]); |
|
106 | + } else { |
|
107 | + $out .= $address[$i]; |
|
108 | + } |
|
109 | + } |
|
110 | + $out .= '" '.$extra.'>'; |
|
111 | + $len = strlen($text); |
|
112 | + for ($i = 0; $i < $len; ++$i) { |
|
113 | + $out .= '&#x'.bin2hex($text[$i]); |
|
114 | + } |
|
115 | + |
|
116 | + return $out.'</a>'; |
|
117 | + |
|
118 | + default: |
|
119 | + $dwoo->triggerError('Mailto: <em>encode</em> argument is invalid, it must be one of : <em>none (= no value), js, js_charcode or hex</em>', E_USER_WARNING); |
|
120 | + |
|
121 | + } |
|
122 | 122 | } |
@@ -25,25 +25,25 @@ |
||
25 | 25 | */ |
26 | 26 | function Dwoo_Plugin_truncate(Dwoo_Core $dwoo, $value, $length = 80, $etc = '...', $break = false, $middle = false) |
27 | 27 | { |
28 | - if ($length == 0) { |
|
29 | - return ''; |
|
30 | - } |
|
28 | + if ($length == 0) { |
|
29 | + return ''; |
|
30 | + } |
|
31 | 31 | |
32 | - $value = (string) $value; |
|
33 | - $etc = (string) $etc; |
|
34 | - $length = (int) $length; |
|
32 | + $value = (string) $value; |
|
33 | + $etc = (string) $etc; |
|
34 | + $length = (int) $length; |
|
35 | 35 | |
36 | - if (strlen($value) < $length) { |
|
37 | - return $value; |
|
38 | - } |
|
36 | + if (strlen($value) < $length) { |
|
37 | + return $value; |
|
38 | + } |
|
39 | 39 | |
40 | - $length = max($length - strlen($etc), 0); |
|
41 | - if ($break === false && $middle === false) { |
|
42 | - $value = preg_replace('#\s+(\S*)?$#', '', substr($value, 0, $length + 1)); |
|
43 | - } |
|
44 | - if ($middle === false) { |
|
45 | - return substr($value, 0, $length).$etc; |
|
46 | - } |
|
40 | + $length = max($length - strlen($etc), 0); |
|
41 | + if ($break === false && $middle === false) { |
|
42 | + $value = preg_replace('#\s+(\S*)?$#', '', substr($value, 0, $length + 1)); |
|
43 | + } |
|
44 | + if ($middle === false) { |
|
45 | + return substr($value, 0, $length).$etc; |
|
46 | + } |
|
47 | 47 | |
48 | - return substr($value, 0, ceil($length / 2)).$etc.substr($value, -floor($length / 2)); |
|
48 | + return substr($value, 0, ceil($length / 2)).$etc.substr($value, -floor($length / 2)); |
|
49 | 49 | } |
@@ -22,5 +22,5 @@ |
||
22 | 22 | */ |
23 | 23 | function Dwoo_Plugin_spacify_compile(Dwoo_Compiler $compiler, $value, $space_char = ' ') |
24 | 24 | { |
25 | - return 'implode('.$space_char.', str_split('.$value.', 1))'; |
|
25 | + return 'implode('.$space_char.', str_split('.$value.', 1))'; |
|
26 | 26 | } |
@@ -22,5 +22,5 @@ |
||
22 | 22 | */ |
23 | 23 | function Dwoo_Plugin_optional_compile(Dwoo_Compiler $compiler, $value) |
24 | 24 | { |
25 | - return $value; |
|
25 | + return $value; |
|
26 | 26 | } |
@@ -23,9 +23,9 @@ |
||
23 | 23 | */ |
24 | 24 | function Dwoo_Plugin_replace_compile(Dwoo_Compiler $compiler, $value, $search, $replace, $case_sensitive = true) |
25 | 25 | { |
26 | - if ($case_sensitive == 'false' || (bool) $case_sensitive === false) { |
|
27 | - return 'str_ireplace('.$search.', '.$replace.', '.$value.')'; |
|
28 | - } else { |
|
29 | - return 'str_replace('.$search.', '.$replace.', '.$value.')'; |
|
30 | - } |
|
26 | + if ($case_sensitive == 'false' || (bool) $case_sensitive === false) { |
|
27 | + return 'str_ireplace('.$search.', '.$replace.', '.$value.')'; |
|
28 | + } else { |
|
29 | + return 'str_replace('.$search.', '.$replace.', '.$value.')'; |
|
30 | + } |
|
31 | 31 | } |
@@ -27,56 +27,56 @@ |
||
27 | 27 | */ |
28 | 28 | function Dwoo_Plugin_include(Dwoo_Core $dwoo, $file, $cache_time = null, $cache_id = null, $compile_id = null, $data = '_root', $assign = null, array $rest = array()) |
29 | 29 | { |
30 | - if ($file === '') { |
|
31 | - return ''; |
|
32 | - } |
|
30 | + if ($file === '') { |
|
31 | + return ''; |
|
32 | + } |
|
33 | 33 | |
34 | - if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) { |
|
35 | - // resource:identifier given, extract them |
|
36 | - $resource = $m[1]; |
|
37 | - $identifier = $m[2]; |
|
38 | - } else { |
|
39 | - // get the current template's resource |
|
40 | - $resource = $dwoo->getTemplate()->getResourceName(); |
|
41 | - $identifier = $file; |
|
42 | - } |
|
34 | + if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) { |
|
35 | + // resource:identifier given, extract them |
|
36 | + $resource = $m[1]; |
|
37 | + $identifier = $m[2]; |
|
38 | + } else { |
|
39 | + // get the current template's resource |
|
40 | + $resource = $dwoo->getTemplate()->getResourceName(); |
|
41 | + $identifier = $file; |
|
42 | + } |
|
43 | 43 | |
44 | - try { |
|
45 | - $include = $dwoo->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id); |
|
46 | - } catch (Dwoo_Security_Exception $e) { |
|
47 | - $dwoo->triggerError('Include : Security restriction : '.$e->getMessage(), E_USER_WARNING); |
|
48 | - } catch (Dwoo_Exception $e) { |
|
49 | - $dwoo->triggerError('Include : '.$e->getMessage(), E_USER_WARNING); |
|
50 | - } |
|
44 | + try { |
|
45 | + $include = $dwoo->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id); |
|
46 | + } catch (Dwoo_Security_Exception $e) { |
|
47 | + $dwoo->triggerError('Include : Security restriction : '.$e->getMessage(), E_USER_WARNING); |
|
48 | + } catch (Dwoo_Exception $e) { |
|
49 | + $dwoo->triggerError('Include : '.$e->getMessage(), E_USER_WARNING); |
|
50 | + } |
|
51 | 51 | |
52 | - if ($include === null) { |
|
53 | - $dwoo->triggerError('Include : Resource "'.$resource.':'.$identifier.'" not found.', E_USER_WARNING); |
|
54 | - } elseif ($include === false) { |
|
55 | - $dwoo->triggerError('Include : Resource "'.$resource.'" does not support includes.', E_USER_WARNING); |
|
56 | - } |
|
52 | + if ($include === null) { |
|
53 | + $dwoo->triggerError('Include : Resource "'.$resource.':'.$identifier.'" not found.', E_USER_WARNING); |
|
54 | + } elseif ($include === false) { |
|
55 | + $dwoo->triggerError('Include : Resource "'.$resource.'" does not support includes.', E_USER_WARNING); |
|
56 | + } |
|
57 | 57 | |
58 | - if (is_string($data)) { |
|
59 | - $vars = $dwoo->readVar($data); |
|
60 | - } else { |
|
61 | - $vars = $data; |
|
62 | - } |
|
58 | + if (is_string($data)) { |
|
59 | + $vars = $dwoo->readVar($data); |
|
60 | + } else { |
|
61 | + $vars = $data; |
|
62 | + } |
|
63 | 63 | |
64 | - if (count($rest)) { |
|
65 | - $vars = $rest + $vars; |
|
66 | - } |
|
64 | + if (count($rest)) { |
|
65 | + $vars = $rest + $vars; |
|
66 | + } |
|
67 | 67 | |
68 | - $clone = clone $dwoo; |
|
69 | - $out = $clone->get($include, $vars); |
|
68 | + $clone = clone $dwoo; |
|
69 | + $out = $clone->get($include, $vars); |
|
70 | 70 | |
71 | - if ($assign !== null) { |
|
72 | - $dwoo->assignInScope($out, $assign); |
|
73 | - } |
|
71 | + if ($assign !== null) { |
|
72 | + $dwoo->assignInScope($out, $assign); |
|
73 | + } |
|
74 | 74 | |
75 | - foreach ($clone->getReturnValues() as $name => $value) { |
|
76 | - $dwoo->assignInScope($value, $name); |
|
77 | - } |
|
75 | + foreach ($clone->getReturnValues() as $name => $value) { |
|
76 | + $dwoo->assignInScope($value, $name); |
|
77 | + } |
|
78 | 78 | |
79 | - if ($assign === null) { |
|
80 | - return $out; |
|
81 | - } |
|
79 | + if ($assign === null) { |
|
80 | + return $out; |
|
81 | + } |
|
82 | 82 | } |
@@ -22,5 +22,5 @@ |
||
22 | 22 | */ |
23 | 23 | function Dwoo_Plugin_default_compile(Dwoo_Compiler $compiler, $value, $default = '') |
24 | 24 | { |
25 | - return '(($tmp = '.$value.')===null||$tmp===\'\' ? '.$default.' : $tmp)'; |
|
25 | + return '(($tmp = '.$value.')===null||$tmp===\'\' ? '.$default.' : $tmp)'; |
|
26 | 26 | } |
@@ -22,19 +22,19 @@ |
||
22 | 22 | */ |
23 | 23 | function Dwoo_Plugin_capitalize(Dwoo_Core $dwoo, $value, $numwords = false) |
24 | 24 | { |
25 | - if ($numwords || preg_match('#^[^0-9]+$#', $value)) { |
|
26 | - return mb_convert_case((string) $value, MB_CASE_TITLE, $dwoo->getCharset()); |
|
27 | - } else { |
|
28 | - $bits = explode(' ', (string) $value); |
|
29 | - $out = ''; |
|
30 | - while (list(, $v) = each($bits)) { |
|
31 | - if (preg_match('#^[^0-9]+$#', $v)) { |
|
32 | - $out .= ' '.mb_convert_case($v, MB_CASE_TITLE, $dwoo->getCharset()); |
|
33 | - } else { |
|
34 | - $out .= ' '.$v; |
|
35 | - } |
|
36 | - } |
|
25 | + if ($numwords || preg_match('#^[^0-9]+$#', $value)) { |
|
26 | + return mb_convert_case((string) $value, MB_CASE_TITLE, $dwoo->getCharset()); |
|
27 | + } else { |
|
28 | + $bits = explode(' ', (string) $value); |
|
29 | + $out = ''; |
|
30 | + while (list(, $v) = each($bits)) { |
|
31 | + if (preg_match('#^[^0-9]+$#', $v)) { |
|
32 | + $out .= ' '.mb_convert_case($v, MB_CASE_TITLE, $dwoo->getCharset()); |
|
33 | + } else { |
|
34 | + $out .= ' '.$v; |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - return substr($out, 1); |
|
39 | - } |
|
38 | + return substr($out, 1); |
|
39 | + } |
|
40 | 40 | } |