name = $name; $this->cat = $cat; $this->sub = $sub; //Two directories; one for the p5 version, to be rendered on the page, //and one for the original PDE, whose text is displayed on the page. $p5_dir = EXAMPLESOURCEJSDIR . $cat . '/' . $name . '/'; $pde_dir = EXAMPLESOURCEDIR . $cat . '/' . $name . '/'; //p5 first $this->data_dir = $p5_dir . 'data/'; $this->p5_file = file_get_contents($p5_dir . $name .'.js'); if ($handle = opendir($p5_dir)) { while (false !== ($newfile = readdir($handle))) { if (preg_match("/js/", $newfile)) { if (strcmp($name.'.js', $newfile) != 0) { $this->p5_file .= "\n\n\n"; $this->p5_file .= file_get_contents($p5_dir . $newfile); } } } closedir($handle); } $this->p5_code = $this->p5_file; //$this->p5_code = implode("\n", $full_code_lines); //PDE second $this->pde_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->pde_file .= "\n\n\n"; #$this->file .= file_get_contents(CONTENTDIR.'examples/'.$cat.'/'.$name.'/'.$newfile); $this->pde_file .= file_get_contents($pde_dir . $newfile); } } } closedir($handle); } /* //OLD CODE -- BACKUP 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->pde_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] = "" . $doc_lines[0] . ""; $this->doc = implode(" ", $doc_lines); //$this->p5_code = implode("\n", $full_code_lines); $this->pde_code = implode("\n", $code_lines); } function display() { $html = "\n
"; $html .= nl2br($this->doc); #$html .= $this->doc; $html .= "
\n"; //Raw code from Processing (not p5) version $html .= "\n\n";
$html .= $this->pde_code;
$html .= "\n\n";
$html .= "\n
Back To List';
$nav .= "\n