Completed
Push — master ( 67fff9...3dcfcd )
by David
08:00 queued 03:38
created
lib/Dwoo/Plugins/Functions/PluginEscape.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -32,56 +32,56 @@
 block discarded – undo
32 32
  */
33 33
 function PluginEscape(Core $dwoo, $value = '', $format = 'html', $charset = null)
34 34
 {
35
-    if ($charset === null) {
36
-        $charset = $dwoo->getCharset();
37
-    }
35
+	if ($charset === null) {
36
+		$charset = $dwoo->getCharset();
37
+	}
38 38
 
39
-    switch ($format) {
39
+	switch ($format) {
40 40
 
41
-        case 'html':
42
-            return htmlspecialchars((string)$value, ENT_QUOTES, $charset);
43
-        case 'htmlall':
44
-            return htmlentities((string)$value, ENT_QUOTES, $charset);
45
-        case 'url':
46
-            return rawurlencode((string)$value);
47
-        case 'urlpathinfo':
48
-            return str_replace('%2F', '/', rawurlencode((string)$value));
49
-        case 'quotes':
50
-            return preg_replace("#(?<!\\\\)'#", "\\'", (string)$value);
51
-        case 'hex':
52
-            $out = '';
53
-            $cnt = strlen((string)$value);
54
-            for ($i = 0; $i < $cnt; ++ $i) {
55
-                $out .= '%' . bin2hex((string)$value[$i]);
56
-            }
41
+		case 'html':
42
+			return htmlspecialchars((string)$value, ENT_QUOTES, $charset);
43
+		case 'htmlall':
44
+			return htmlentities((string)$value, ENT_QUOTES, $charset);
45
+		case 'url':
46
+			return rawurlencode((string)$value);
47
+		case 'urlpathinfo':
48
+			return str_replace('%2F', '/', rawurlencode((string)$value));
49
+		case 'quotes':
50
+			return preg_replace("#(?<!\\\\)'#", "\\'", (string)$value);
51
+		case 'hex':
52
+			$out = '';
53
+			$cnt = strlen((string)$value);
54
+			for ($i = 0; $i < $cnt; ++ $i) {
55
+				$out .= '%' . bin2hex((string)$value[$i]);
56
+			}
57 57
 
58
-            return $out;
59
-        case 'hexentity':
60
-            $out = '';
61
-            $cnt = strlen((string)$value);
62
-            for ($i = 0; $i < $cnt; ++ $i) {
63
-                $out .= '&#x' . bin2hex((string)$value[$i]) . ';';
64
-            }
58
+			return $out;
59
+		case 'hexentity':
60
+			$out = '';
61
+			$cnt = strlen((string)$value);
62
+			for ($i = 0; $i < $cnt; ++ $i) {
63
+				$out .= '&#x' . bin2hex((string)$value[$i]) . ';';
64
+			}
65 65
 
66
-            return $out;
67
-        case 'javascript':
68
-            return strtr((string)$value, array(
69
-                '\\' => '\\\\',
70
-                "'"  => "\\'",
71
-                '"'  => '\\"',
72
-                "\r" => '\\r',
73
-                "\n" => '\\n',
74
-                '</' => '<\/'
75
-            ));
76
-        case 'mail':
77
-            return str_replace(array(
78
-                '@',
79
-                '.'
80
-            ), array(
81
-                '&nbsp;(AT)&nbsp;',
82
-                '&nbsp;(DOT)&nbsp;'
83
-            ), (string)$value);
84
-        default:
85
-            $dwoo->triggerError('Escape\'s format argument must be one of : html, htmlall, url, urlpathinfo, hex, hexentity, javascript or mail, "' . $format . '" given.', E_USER_WARNING);
86
-    }
66
+			return $out;
67
+		case 'javascript':
68
+			return strtr((string)$value, array(
69
+				'\\' => '\\\\',
70
+				"'"  => "\\'",
71
+				'"'  => '\\"',
72
+				"\r" => '\\r',
73
+				"\n" => '\\n',
74
+				'</' => '<\/'
75
+			));
76
+		case 'mail':
77
+			return str_replace(array(
78
+				'@',
79
+				'.'
80
+			), array(
81
+				'&nbsp;(AT)&nbsp;',
82
+				'&nbsp;(DOT)&nbsp;'
83
+			), (string)$value);
84
+		default:
85
+			$dwoo->triggerError('Escape\'s format argument must be one of : html, htmlall, url, urlpathinfo, hex, hexentity, javascript or mail, "' . $format . '" given.', E_USER_WARNING);
86
+	}
87 87
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Functions/PluginMathCompile.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -39,143 +39,143 @@
 block discarded – undo
39 39
  */
40 40
 function PluginMathCompile(Compiler $compiler, $equation, $format = '', $assign = '', array $rest = array())
41 41
 {
42
-    /*
42
+	/*
43 43
      * Holds the allowed function, characters, operators and constants
44 44
      */
45
-    $allowed = array(
46
-        '0',
47
-        '1',
48
-        '2',
49
-        '3',
50
-        '4',
51
-        '5',
52
-        '6',
53
-        '7',
54
-        '8',
55
-        '9',
56
-        '+',
57
-        '-',
58
-        '/',
59
-        '*',
60
-        '.',
61
-        ' ',
62
-        '<<',
63
-        '>>',
64
-        '%',
65
-        '&',
66
-        '^',
67
-        '|',
68
-        '~',
69
-        'abs(',
70
-        'ceil(',
71
-        'floor(',
72
-        'exp(',
73
-        'log10(',
74
-        'cos(',
75
-        'sin(',
76
-        'sqrt(',
77
-        'tan(',
78
-        'M_PI',
79
-        'INF',
80
-        'M_E',
81
-    );
45
+	$allowed = array(
46
+		'0',
47
+		'1',
48
+		'2',
49
+		'3',
50
+		'4',
51
+		'5',
52
+		'6',
53
+		'7',
54
+		'8',
55
+		'9',
56
+		'+',
57
+		'-',
58
+		'/',
59
+		'*',
60
+		'.',
61
+		' ',
62
+		'<<',
63
+		'>>',
64
+		'%',
65
+		'&',
66
+		'^',
67
+		'|',
68
+		'~',
69
+		'abs(',
70
+		'ceil(',
71
+		'floor(',
72
+		'exp(',
73
+		'log10(',
74
+		'cos(',
75
+		'sin(',
76
+		'sqrt(',
77
+		'tan(',
78
+		'M_PI',
79
+		'INF',
80
+		'M_E',
81
+	);
82 82
 
83
-    /*
83
+	/*
84 84
      * Holds the functions that can accept multiple arguments
85 85
      */
86
-    $funcs = array(
87
-        'round(',
88
-        'log(',
89
-        'pow(',
90
-        'max(',
91
-        'min(',
92
-        'rand(',
93
-    );
86
+	$funcs = array(
87
+		'round(',
88
+		'log(',
89
+		'pow(',
90
+		'max(',
91
+		'min(',
92
+		'rand(',
93
+	);
94 94
 
95
-    $equation = $equationSrc = str_ireplace(array(
96
-        'pi',
97
-        'M_PI()',
98
-        'inf',
99
-        ' e '
100
-    ), array(
101
-        'M_PI',
102
-        'M_PI',
103
-        'INF',
104
-        ' M_E '
105
-    ), $equation);
95
+	$equation = $equationSrc = str_ireplace(array(
96
+		'pi',
97
+		'M_PI()',
98
+		'inf',
99
+		' e '
100
+	), array(
101
+		'M_PI',
102
+		'M_PI',
103
+		'INF',
104
+		' M_E '
105
+	), $equation);
106 106
 
107
-    $delim      = $equation[0];
108
-    $open       = $delim . '.';
109
-    $close      = '.' . $delim;
110
-    $equation   = substr($equation, 1, - 1);
111
-    $out        = '';
112
-    $ptr        = 1;
113
-    $allowcomma = 0;
114
-    while (strlen($equation) > 0) {
115
-        $substr = substr($equation, 0, $ptr);
116
-        if (array_search($substr, $allowed) !== false) {
117
-            // allowed string
118
-            $out .= $substr;
119
-            $equation = substr($equation, $ptr);
120
-            $ptr      = 0;
121
-        } elseif (array_search($substr, $funcs) !== false) {
122
-            // allowed func
123
-            $out .= $substr;
124
-            $equation = substr($equation, $ptr);
125
-            $ptr      = 0;
126
-            ++ $allowcomma;
127
-            if ($allowcomma === 1) {
128
-                $allowed[] = ',';
129
-            }
130
-        } elseif (isset($rest[$substr])) {
131
-            // variable
132
-            $out .= $rest[$substr];
133
-            $equation = substr($equation, $ptr);
134
-            $ptr      = 0;
135
-        } elseif ($substr === $open) {
136
-            // pre-replaced variable
137
-            preg_match('#.*\((?:[^()]*?|(?R))\)' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m);
138
-            if (empty($m)) {
139
-                preg_match('#.*?' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m);
140
-            }
141
-            $out .= substr($m[0], 0, - 2);
142
-            $equation = substr($equation, strlen($m[0]) + 2);
143
-            $ptr      = 0;
144
-        } elseif ($substr === '(') {
145
-            // opening parenthesis
146
-            if ($allowcomma > 0) {
147
-                ++ $allowcomma;
148
-            }
107
+	$delim      = $equation[0];
108
+	$open       = $delim . '.';
109
+	$close      = '.' . $delim;
110
+	$equation   = substr($equation, 1, - 1);
111
+	$out        = '';
112
+	$ptr        = 1;
113
+	$allowcomma = 0;
114
+	while (strlen($equation) > 0) {
115
+		$substr = substr($equation, 0, $ptr);
116
+		if (array_search($substr, $allowed) !== false) {
117
+			// allowed string
118
+			$out .= $substr;
119
+			$equation = substr($equation, $ptr);
120
+			$ptr      = 0;
121
+		} elseif (array_search($substr, $funcs) !== false) {
122
+			// allowed func
123
+			$out .= $substr;
124
+			$equation = substr($equation, $ptr);
125
+			$ptr      = 0;
126
+			++ $allowcomma;
127
+			if ($allowcomma === 1) {
128
+				$allowed[] = ',';
129
+			}
130
+		} elseif (isset($rest[$substr])) {
131
+			// variable
132
+			$out .= $rest[$substr];
133
+			$equation = substr($equation, $ptr);
134
+			$ptr      = 0;
135
+		} elseif ($substr === $open) {
136
+			// pre-replaced variable
137
+			preg_match('#.*\((?:[^()]*?|(?R))\)' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m);
138
+			if (empty($m)) {
139
+				preg_match('#.*?' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m);
140
+			}
141
+			$out .= substr($m[0], 0, - 2);
142
+			$equation = substr($equation, strlen($m[0]) + 2);
143
+			$ptr      = 0;
144
+		} elseif ($substr === '(') {
145
+			// opening parenthesis
146
+			if ($allowcomma > 0) {
147
+				++ $allowcomma;
148
+			}
149 149
 
150
-            $out .= $substr;
151
-            $equation = substr($equation, $ptr);
152
-            $ptr      = 0;
153
-        } elseif ($substr === ')') {
154
-            // closing parenthesis
155
-            if ($allowcomma > 0) {
156
-                -- $allowcomma;
157
-                if ($allowcomma === 0) {
158
-                    array_pop($allowed);
159
-                }
160
-            }
150
+			$out .= $substr;
151
+			$equation = substr($equation, $ptr);
152
+			$ptr      = 0;
153
+		} elseif ($substr === ')') {
154
+			// closing parenthesis
155
+			if ($allowcomma > 0) {
156
+				-- $allowcomma;
157
+				if ($allowcomma === 0) {
158
+					array_pop($allowed);
159
+				}
160
+			}
161 161
 
162
-            $out .= $substr;
163
-            $equation = substr($equation, $ptr);
164
-            $ptr      = 0;
165
-        } elseif ($ptr >= strlen($equation)) {
166
-            // parse error if we've consumed the entire equation without finding anything valid
167
-            throw new CompilationException($compiler, 'Math : Syntax error or variable undefined in equation ' . $equationSrc . ' at ' . $substr);
168
-        } else {
169
-            // nothing special, advance
170
-            ++ $ptr;
171
-        }
172
-    }
173
-    if ($format !== '\'\'') {
174
-        $out = 'sprintf(' . $format . ', ' . $out . ')';
175
-    }
176
-    if ($assign !== '\'\'') {
177
-        return '($this->assignInScope(' . $out . ', ' . $assign . '))';
178
-    }
162
+			$out .= $substr;
163
+			$equation = substr($equation, $ptr);
164
+			$ptr      = 0;
165
+		} elseif ($ptr >= strlen($equation)) {
166
+			// parse error if we've consumed the entire equation without finding anything valid
167
+			throw new CompilationException($compiler, 'Math : Syntax error or variable undefined in equation ' . $equationSrc . ' at ' . $substr);
168
+		} else {
169
+			// nothing special, advance
170
+			++ $ptr;
171
+		}
172
+	}
173
+	if ($format !== '\'\'') {
174
+		$out = 'sprintf(' . $format . ', ' . $out . ')';
175
+	}
176
+	if ($assign !== '\'\'') {
177
+		return '($this->assignInScope(' . $out . ', ' . $assign . '))';
178
+	}
179 179
 
180
-    return '(' . $out . ')';
180
+	return '(' . $out . ')';
181 181
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Functions/PluginIssetCompile.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,5 +28,5 @@
 block discarded – undo
28 28
  */
29 29
 function PluginIssetCompile(Compiler $compiler, $var)
30 30
 {
31
-    return '(' . $var . ' !== null)';
31
+	return '(' . $var . ' !== null)';
32 32
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Functions/PluginEval.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -36,17 +36,17 @@
 block discarded – undo
36 36
  */
37 37
 function PluginEval(Core $dwoo, $var, $assign = null)
38 38
 {
39
-    if ($var == '') {
40
-        return '';
41
-    }
39
+	if ($var == '') {
40
+		return '';
41
+	}
42 42
 
43
-    $tpl   = new TemplateString($var);
44
-    $clone = clone $dwoo;
45
-    $out   = $clone->get($tpl, $dwoo->readVar('_parent'));
43
+	$tpl   = new TemplateString($var);
44
+	$clone = clone $dwoo;
45
+	$out   = $clone->get($tpl, $dwoo->readVar('_parent'));
46 46
 
47
-    if ($assign !== null) {
48
-        $dwoo->assignInScope($out, $assign);
49
-    } else {
50
-        return $out;
51
-    }
47
+	if ($assign !== null) {
48
+		$dwoo->assignInScope($out, $assign);
49
+	} else {
50
+		return $out;
51
+	}
52 52
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Functions/PluginLoadTemplatesCompile.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -29,47 +29,47 @@  discard block
 block discarded – undo
29 29
  */
30 30
 function PluginLoadTemplatesCompile(Compiler $compiler, $file)
31 31
 {
32
-    $file = substr($file, 1, - 1);
32
+	$file = substr($file, 1, - 1);
33 33
 
34
-    if ($file === '') {
35
-        return '';
36
-    }
34
+	if ($file === '') {
35
+		return '';
36
+	}
37 37
 
38
-    if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
39
-        // resource:identifier given, extract them
40
-        $resource   = $m[1];
41
-        $identifier = $m[2];
42
-    } else {
43
-        // get the current template's resource
44
-        $resource   = $compiler->getDwoo()->getTemplate()->getResourceName();
45
-        $identifier = $file;
46
-    }
38
+	if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
39
+		// resource:identifier given, extract them
40
+		$resource   = $m[1];
41
+		$identifier = $m[2];
42
+	} else {
43
+		// get the current template's resource
44
+		$resource   = $compiler->getDwoo()->getTemplate()->getResourceName();
45
+		$identifier = $file;
46
+	}
47 47
 
48
-    $tpl = $compiler->getDwoo()->templateFactory($resource, $identifier);
48
+	$tpl = $compiler->getDwoo()->templateFactory($resource, $identifier);
49 49
 
50
-    if ($tpl === null) {
51
-        throw new CompilationException($compiler, 'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
52
-    } elseif ($tpl === false) {
53
-        throw new CompilationException($compiler, 'Load Templates : Resource "' . $resource . '" does not support includes.');
54
-    }
50
+	if ($tpl === null) {
51
+		throw new CompilationException($compiler, 'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
52
+	} elseif ($tpl === false) {
53
+		throw new CompilationException($compiler, 'Load Templates : Resource "' . $resource . '" does not support includes.');
54
+	}
55 55
 
56
-    $cmp = clone $compiler;
57
-    $cmp->compile($compiler->getDwoo(), $tpl);
58
-    foreach ($cmp->getTemplatePlugins() as $template => $args) {
59
-        $compiler->addTemplatePlugin($template, $args['params'], $args['uuid'], $args['body']);
60
-    }
61
-    foreach ($cmp->getUsedPlugins() as $plugin => $type) {
62
-        $compiler->addUsedPlugin($plugin, $type);
63
-    }
56
+	$cmp = clone $compiler;
57
+	$cmp->compile($compiler->getDwoo(), $tpl);
58
+	foreach ($cmp->getTemplatePlugins() as $template => $args) {
59
+		$compiler->addTemplatePlugin($template, $args['params'], $args['uuid'], $args['body']);
60
+	}
61
+	foreach ($cmp->getUsedPlugins() as $plugin => $type) {
62
+		$compiler->addUsedPlugin($plugin, $type);
63
+	}
64 64
 
65
-    $out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n";
65
+	$out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n";
66 66
 
67
-    $modCheck = $tpl->getIsModifiedCode();
67
+	$modCheck = $tpl->getIsModifiedCode();
68 68
 
69
-    if ($modCheck) {
70
-        $out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
71
-    } else {
72
-        $out .= 'try {
69
+	if ($modCheck) {
70
+		$out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
71
+	} else {
72
+		$out .= 'try {
73 73
 	$tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '");
74 74
 } catch (Dwoo\Exception $e) {
75 75
 	$this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING);
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 elseif ($tpl === false)
80 80
 	$this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING);
81 81
 if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }';
82
-    }
82
+	}
83 83
 
84
-    return $out;
84
+	return $out;
85 85
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Functions/PluginStringFormatCompile.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,5 +29,5 @@
 block discarded – undo
29 29
  */
30 30
 function PluginStringFormatCompile(Compiler $compiler, $value, $format)
31 31
 {
32
-    return 'sprintf(' . $format . ',' . $value . ')';
32
+	return 'sprintf(' . $format . ',' . $value . ')';
33 33
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Functions/PluginDefaultCompile.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,5 +29,5 @@
 block discarded – undo
29 29
  */
30 30
 function PluginDefaultCompile(Compiler $compiler, $value, $default = '')
31 31
 {
32
-    return '(($tmp = ' . $value . ')===null||$tmp===\'\' ? ' . $default . ' : $tmp)';
32
+	return '(($tmp = ' . $value . ')===null||$tmp===\'\' ? ' . $default . ' : $tmp)';
33 33
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Functions/PluginAssignCompile.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,5 +29,5 @@
 block discarded – undo
29 29
  */
30 30
 function PluginAssignCompile(Compiler $compiler, $value, $var)
31 31
 {
32
-    return '$this->assignInScope(' . $value . ', ' . $var . ')';
32
+	return '$this->assignInScope(' . $value . ', ' . $var . ')';
33 33
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Functions/PluginMailto.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -36,93 +36,93 @@
 block discarded – undo
36 36
  */
37 37
 function PluginMailto(Core $dwoo, $address, $text = null, $subject = null, $encode = null, $cc = null, $bcc = null, $newsgroups = null, $followupto = null, $extra = null)
38 38
 {
39
-    if (empty($address)) {
40
-        return '';
41
-    }
42
-    if (empty($text)) {
43
-        $text = $address;
44
-    }
45
-
46
-    // build address string
47
-    $address .= '?';
48
-
49
-    if (!empty($subject)) {
50
-        $address .= 'subject=' . rawurlencode($subject) . '&';
51
-    }
52
-    if (!empty($cc)) {
53
-        $address .= 'cc=' . rawurlencode($cc) . '&';
54
-    }
55
-    if (!empty($bcc)) {
56
-        $address .= 'bcc=' . rawurlencode($bcc) . '&';
57
-    }
58
-    if (!empty($newsgroups)) {
59
-        $address .= 'newsgroups=' . rawurlencode($newsgroups) . '&';
60
-    }
61
-    if (!empty($followupto)) {
62
-        $address .= 'followupto=' . rawurlencode($followupto) . '&';
63
-    }
64
-
65
-    $address = rtrim($address, '?&');
66
-
67
-    // output
68
-    switch ($encode) {
69
-
70
-        case 'none':
71
-        case null:
72
-            return '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
73
-
74
-        case 'js':
75
-        case 'javascript':
76
-            $str = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');';
77
-            $len = strlen($str);
78
-
79
-            $out = '';
80
-            for ($i = 0; $i < $len; ++ $i) {
81
-                $out .= '%' . bin2hex($str[$i]);
82
-            }
83
-
84
-            return '<script type="text/javascript">eval(unescape(\'' . $out . '\'));</script>';
85
-
86
-            break;
87
-        case 'javascript_charcode':
88
-        case 'js_charcode':
89
-        case 'jscharcode':
90
-        case 'jschar':
91
-            $str = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
92
-            $len = strlen($str);
93
-
94
-            $out = '<script type="text/javascript">' . "\n<!--\ndocument.write(String.fromCharCode(";
95
-            for ($i = 0; $i < $len; ++ $i) {
96
-                $out .= ord($str[$i]) . ',';
97
-            }
98
-
99
-            return rtrim($out, ',') . "));\n-->\n</script>\n";
100
-
101
-            break;
102
-
103
-        case 'hex':
104
-            if (strpos($address, '?') !== false) {
105
-                $dwoo->triggerError('Mailto: Hex encoding is not possible with extra attributes, use one of : <em>js, jscharcode or none</em>.', E_USER_WARNING);
106
-            }
107
-
108
-            $out = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;';
109
-            $len = strlen($address);
110
-            for ($i = 0; $i < $len; ++ $i) {
111
-                if (preg_match('#\w#', $address[$i])) {
112
-                    $out .= '%' . bin2hex($address[$i]);
113
-                } else {
114
-                    $out .= $address[$i];
115
-                }
116
-            }
117
-            $out .= '" ' . $extra . '>';
118
-            $len = strlen($text);
119
-            for ($i = 0; $i < $len; ++ $i) {
120
-                $out .= '&#x' . bin2hex($text[$i]);
121
-            }
122
-
123
-            return $out . '</a>';
124
-
125
-        default:
126
-            $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);
127
-    }
39
+	if (empty($address)) {
40
+		return '';
41
+	}
42
+	if (empty($text)) {
43
+		$text = $address;
44
+	}
45
+
46
+	// build address string
47
+	$address .= '?';
48
+
49
+	if (!empty($subject)) {
50
+		$address .= 'subject=' . rawurlencode($subject) . '&';
51
+	}
52
+	if (!empty($cc)) {
53
+		$address .= 'cc=' . rawurlencode($cc) . '&';
54
+	}
55
+	if (!empty($bcc)) {
56
+		$address .= 'bcc=' . rawurlencode($bcc) . '&';
57
+	}
58
+	if (!empty($newsgroups)) {
59
+		$address .= 'newsgroups=' . rawurlencode($newsgroups) . '&';
60
+	}
61
+	if (!empty($followupto)) {
62
+		$address .= 'followupto=' . rawurlencode($followupto) . '&';
63
+	}
64
+
65
+	$address = rtrim($address, '?&');
66
+
67
+	// output
68
+	switch ($encode) {
69
+
70
+		case 'none':
71
+		case null:
72
+			return '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
73
+
74
+		case 'js':
75
+		case 'javascript':
76
+			$str = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');';
77
+			$len = strlen($str);
78
+
79
+			$out = '';
80
+			for ($i = 0; $i < $len; ++ $i) {
81
+				$out .= '%' . bin2hex($str[$i]);
82
+			}
83
+
84
+			return '<script type="text/javascript">eval(unescape(\'' . $out . '\'));</script>';
85
+
86
+			break;
87
+		case 'javascript_charcode':
88
+		case 'js_charcode':
89
+		case 'jscharcode':
90
+		case 'jschar':
91
+			$str = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
92
+			$len = strlen($str);
93
+
94
+			$out = '<script type="text/javascript">' . "\n<!--\ndocument.write(String.fromCharCode(";
95
+			for ($i = 0; $i < $len; ++ $i) {
96
+				$out .= ord($str[$i]) . ',';
97
+			}
98
+
99
+			return rtrim($out, ',') . "));\n-->\n</script>\n";
100
+
101
+			break;
102
+
103
+		case 'hex':
104
+			if (strpos($address, '?') !== false) {
105
+				$dwoo->triggerError('Mailto: Hex encoding is not possible with extra attributes, use one of : <em>js, jscharcode or none</em>.', E_USER_WARNING);
106
+			}
107
+
108
+			$out = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;';
109
+			$len = strlen($address);
110
+			for ($i = 0; $i < $len; ++ $i) {
111
+				if (preg_match('#\w#', $address[$i])) {
112
+					$out .= '%' . bin2hex($address[$i]);
113
+				} else {
114
+					$out .= $address[$i];
115
+				}
116
+			}
117
+			$out .= '" ' . $extra . '>';
118
+			$len = strlen($text);
119
+			for ($i = 0; $i < $len; ++ $i) {
120
+				$out .= '&#x' . bin2hex($text[$i]);
121
+			}
122
+
123
+			return $out . '</a>';
124
+
125
+		default:
126
+			$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);
127
+	}
128 128
 }
Please login to merge, or discard this patch.