-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathExample.class.php
More file actions
221 lines (190 loc) · 7.24 KB
/
Copy pathExample.class.php
File metadata and controls
221 lines (190 loc) · 7.24 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
class Example
{
var $name;
var $cat;
var $file;
var $applet;
var $data_dir;
var $doc;
var $code;
var $fullcode;
var $sub;
var $width;
var $height;
function Example($name, $cat, $sub)
{
$this->name = $name;
$this->cat = $cat;
$this->sub = $sub;
$pde_dir = EXAMPLESOURCEDIR . $cat . '/' . $name . '/';
$this->data_dir = $pde_dir . 'data/';
$this->file = file_get_contents($pde_dir . $name .'.pde');
if ($handle = opendir($pde_dir)) {
while (false !== ($newfile = readdir($handle))) {
//if ($file != "." && $file != "..") {
if (preg_match("/pde/", $newfile)) {
//echo " $newfile\n";
if (strcmp($name.'.pde', $newfile) != 0) {
$this->file .= "\n\n\n";
#$this->file .= file_get_contents(CONTENTDIR.'examples/'.$cat.'/'.$name.'/'.$newfile);
$this->file .= file_get_contents($pde_dir . $newfile);
}
}
}
closedir($handle);
}
preg_match("/(^|\s|;)size\s*\(\s*(\d+)\s*,\s*(\d+),?\s*([^\)]*)\s*\)/", $this->file, $matches);
$this->width = $matches[2];
$this->height = $matches[3];
$this->split_file();
}
function split_file()
{
$lines = explode("\n", $this->file);
$doc_lines = array();
$code_lines = array();
$full_code_lines = array();
$doc = true;
foreach ($lines as $line) {
# Change for new comment style - cr
if (preg_match("/\*\//", $line) && $doc) {
$doc = false; # End the documentation
#echo "$line\n";
#break;
continue;
}
if ($doc) {
# Change for new comment style - cr
if (!preg_match("/\/\*\*/", $line)) {
$line = str_replace(" * ", "", $line);
$line = trim($line);
if($line == "") {
$line = "\n\n";
}
$doc_lines[] = $line;
}
} else {
$code_lines[] = htmlspecialchars($line);
$full_code_lines[] = $line;
}
}
$doc_lines[0] = "<strong>" . $doc_lines[0] . "</strong>";
$this->doc = implode(" ", $doc_lines);
$this->fullcode = implode("\n", $full_code_lines);
$this->code = implode("\n", $code_lines);
}
function display()
{
$html = "\n<div class=\"example\">"; // BEGIN example div
// This code is the from the Processing.js export from Processing 200
/**
<div>
<canvas id="Distance1D" data-processing-sources="Distance1D.pde" width="640" height="360">
<p>Your browser does not support the canvas tag.</p>
<!-- Note: you can put any alternative content here. -->
</canvas>
<noscript>
<p>JavaScript is required to view the contents of this page.</p>
</noscript>
</div>
*/
// This code is my attempt to generalize the code from Processing 200
/**
$html .= '<div>';
$html .= ' <canvas id="' . $this->name . '" data-processing-sources="' . $this->name . '.pde"';
$html .= 'width="640" height="360">';
$html .= ' <p>Your browser does not support the canvas tag.</p>';
$html .= ' </canvas>';
$html .= ' <noscript>';
$html .= ' <p>JavaScript is required to view the contents of this page.</p>';
$html .= ' </noscript>';
$html .= '</div>';
*/
// This code is based on the example style on ProcessingJS.org
$html .= '<script type="application/processing">';
$html .= $this->fullcode;
$html .= '</script><canvas width="640" height="360"></canvas>';
$html .= "\n<p class=\"doc\">";
$html .= nl2br($this->doc);
#$html .= $this->doc;
$html .= "</p>\n";
$html .= "\n<pre class=\"code\">\n";
$html .= $this->code;
$html .= "</pre>\n\n";
$html .= "\n</div>\n"; // END example div
return $html;
}
function output_file(&$menu_array, $rel_path = '/')
{
$page = new Page($this->name . ' \ Examples', $this->sub, "", "../");
$page->subtemplate('template.example.html');
$page->content($this->display());
$page->set('examples_nav', $this->back_to_list());
//writeFile("learning/".strtolower($this->sub)."/".strtolower($this->name).".html", $page->out());
// Move 2 May 2013
writeFile("examples/".strtolower($this->name).".html", $page->out());
$this->copy_media();
echo $this->name . '<br />';
#echo "learning/examples/".strtolower($this->sub)."/".strtolower($this->name).".html\n";
}
function back_to_list(){
$nav = "\n<div class=\"examples-nav\">";
$nav .= '<a href="/examples/"><img src="/img/back_off.gif" alt="Back to List" /> <span class="back-to">Back To List</span></a>';
$nav .= "\n</div>";
return $nav;
}
function make_nav(&$array, $rel_path = '/') {
$store = array();
$prev = array();
$next = array();
$get_next = false;
$html .= "\n<div class=\"examples-nav-div\">";
$html .= "\n<table width=\"480\" border=\"0\"><tr><td align=\"left\"><table>\n<tr>";
//$html = "\n<table id=\"examples-nav\" width=\"640\">\n<tr><td align=\"right\">";
$select = "\n<select name=\"nav\" size=\"1\" class=\"inputnav\" onChange=\"javascript:gogo(this)\">\n";
foreach ($array as $cat => $exs) {
$select .= "\t<optgroup label=\"$cat\">\n";
foreach ($exs as $file => $name) {
if ($get_next) {
$next = array($file, $name);
$get_next = false;
}
if ($file == $this->name.'.html') {
$sel = ' selected="selected"';
$prev = $store;
$get_next = true;
} else {
$sel = '';
}
$select .= "\t\t<option value=\"".strtolower($file)."\"$sel>$name</option>\n";
$store = array($file, $name);
}
$select .= "\t</optgroup>\n";
}
$select .= "</select>\n\n";
if (count($prev) > 0) {
$html .= '<td><a href="'.strtolower($prev[0]) .'">
<img src="'.$rel_path.'img/back_off.gif" alt="'.$prev[1].'" /></a></td>';
} else {
$html .= '<td width="48"> </td>';
}
$html .= '<td>'.$select.'</td>';
if (count($next) > 0) {
$html .= '<td><a class="next" href="'.strtolower($next[0]) .'">
<img src="'.$rel_path.'img/next_off.gif" alt="'.$next[1].'" /></a></td>';
}
return $html . '</tr></table></td><tr></table></div>';
}
function copy_media()
{
if (file_exists($this->data_dir)) {
if (!copydirr($this->data_dir, EXAMPLESDIR.'/')) {
echo "Could not copy" . EXAMPLESDIR.'/' . "<br />";
}
} else {
//echo "No data here: " . $this->data_dir . "<br />";
}
}
}
?>