summaryrefslogtreecommitdiff
blob: e61997084961e4b4e520825936736948069c193e (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php

include("code.php");

function test_lang($lang, $language = null, $line = null, $escaped = null)
{
  global $code;
  if (!isset($language)) $language = $lang;
  else $as = "as $language";

  if (isset($escaped)) $c = htmlspecialchars($code[$lang]);
  else { $c = $code[$lang]; $escaped = "false"; }

  $snippet = <<<EOF
<h2>$lang $as</h2>
<p>This *is* what some <code>$lang</code> code looks like (escaped:$escaped):</p>
<pre lang='$language' line="$line" escaped="$escaped"> \t \r
$c
</pre>
EOF;

  return $snippet;
}

function gather_content()
{
  $content = '';
  $content .= test_lang('php');
  $content .= test_lang('lisp', null, 1);
  $content .= test_lang('java', null, 1);
  $content .= test_lang('xml');
  $content .= test_lang('xml', null, null, "true");
  $content .= test_lang('html', 'html4strict');
  $content .= test_lang('html', 'xml', 18);
  $content .= test_lang('html', 'xml', 18, "true");
  $content .= test_lang('ocaml');
  $content .= test_lang('python');
  $content .= test_lang('ruby', null, 18);
  $content .= test_lang('ruby');
  $content .= test_lang('rails');
  $content .= test_lang('c');
  return $content;
}

function test_head()
{
  echo apply_filters("wp_head", "");
}

function test_all()
{
  echo apply_filters("the_content", gather_content());
}

function test_all_with_other_filters()
{
  add_filter('the_content', 'pre_killer');   // bad if run before GeSHi
  add_filter('the_content', 'amp_exposer');  // bad if run after GeSHi

  if (file_exists("filters/filters.php"))
  {
    include("filters/filters.php");
  }

  echo apply_filters("the_content", gather_content());
}

include("../wp-syntax.php");
?>

<html>
<head>
<title>WP-Syntax Test Page</title>
<link rel="stylesheet" href="../wp-syntax.css" type="text/css" media="screen" />
<?php
test_head();
define("TEMPLATEPATH", "../");
test_head();
?>
<style type="text/css" media="screen">
.wp_syntax td div, .wp_syntax div div {
  padding: 0;
}
</style>
</head>

<body>
<div style="width:50%;">
  <h1>Vanilla, without other filters</h1>
<?php
test_all();
?>

  <h1>Modified, with other filters</h1>
<?php
test_all_with_other_filters();
?>
</div>
</body>
</html>


<?php

function amp_exposer($content)
{
    return str_replace("&", "&amp;", $content);
}

function pre_killer($content)
{
    return preg_replace("/<(\/)?pre([^>]*)>/", "[$1pre$2]", $content);
}

/*
 * === WORDPRESS STUBS ===
 */
function get_bloginfo($arg) {
    return "http://yourblog.com/blog";
}

function get_option($arg) {
    return "http://yourblog.com/blog";
}

function remove_filter($tag, $function_to_remove, $priority = 10)
{
    return true;
}

function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1)
{
    global $test_filter;

    $test_filter[$tag][$priority][] = $function_to_add;
    $test_filter[$tag][$priority] = array_unique($test_filter[$tag][$priority]);

    return true;
}

function apply_filters($tag, $string)
{
    global $test_filter;

    if (!isset($test_filter[$tag])) return $string;

    uksort($test_filter[$tag], "strnatcasecmp");

    foreach ($test_filter[$tag] as $priority => $functions)
    {
        if (is_null($functions)) continue;

        foreach($functions as $function)
        {
            $string = call_user_func_array($function, array($string));
        }
    }
    return $string;
}

function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1)
{
    add_filter($tag, $function_to_add, $priority, $accepted_args);
}

function do_action($tag, $arg = '') {
    global $test_filter;

    if (!isset($test_filter[$tag])) return;

    uksort($test_filter[$tag], "strnatcasecmp");

    foreach ($test_filter[$tag] as $priority => $functions)
    {
        if (is_null($functions)) continue;

        foreach($functions as $function)
        {
            call_user_func_array($function, array($arg));
        }
    }
}

function do_action_ref_array($tag, $args) {
    global $test_filter;

    if (!isset($test_filter[$tag])) return;

    uksort($test_filter[$tag], "strnatcasecmp");

    foreach ($test_filter[$tag] as $priority => $functions)
    {
        if (is_null($functions)) continue;

        foreach($functions as $function)
        {
            call_user_func_array($function, $args);
        }
    }
}

?>