Permalink
Browse files

adding apps folder with all PHP files

  • Loading branch information...
1 parent 418fbf8 commit bcaa144ab5a5307d94c473742c68478e95380331 @theo-armour theo-armour committed Apr 16, 2012
@@ -0,0 +1,54 @@
+<?php
+global $basepath, $content;
+$basepath = "c:/2012-reference/patterns/original/";
+$content = "Towns<br>";
+
+function gen_content() {
+ global $content;
+ for($i = 1; $i < 254; $i++) {
+ $page = file_get_contents('c:/2012-reference/patterns/original/apl' . $i . '/apl' . $i . '.htm');
+ $pos1 = stripos($page, '<TITLE>');
+ $pos2 = stripos($page, '</TITLE>');
+ $title = substr($page, $pos1 + 7, $pos2 - $pos1 - 7);
+ $title = ucwords(strtolower($title));
+ $title = trim($title);
+ $patterns = array();
+ $patterns[0] = '/Of/';
+ $patterns[1] = '/To /';
+ $patterns[2] = '/And/';
+ $patterns[3] = '/In /';
+ $patterns[4] = '/As /';
+ $patterns[5] = '/A /';
+ $patterns[6] = '/The /';
+ $replacements = array();
+ $replacements[0] = 'of';
+ $replacements[1] = 'to ';
+ $replacements[2] = 'and';
+ $replacements[3] = 'in ';
+ $replacements[4] = 'as ';
+ $replacements[5] = 'a ';
+ $replacements[6] = 'the ';
+ $title = preg_replace($patterns, $replacements, $title);
+ $content = $content . '<a href="apl' . $i . '/apl' . $i . '.htm" target="pattern">' . $title . '</a><br>' . "\r\n";
+ if ($i === 94) {$content = $content . '<br>Buildings<br>';}
+ if ($i === 204) {$content = $content . '<br>Construction<br>';}
+ }
+}
+function new_file($s,$content) {
+ global $basepath;
+ if (!$handle = fopen($basepath.$s, 'w')) {
+ echo "Cannot open file ($s)";
+ exit;
+ }
+ if (fwrite($handle, $content) === FALSE) {
+ echo "Cannot write to file ($s)";
+ exit;
+ }
+ // echo "<br>Success, wrote ($content) to file: $s";
+ fclose($handle);
+}
+
+gen_content();
+echo $content;
+new_file('navigation.htm',$content);
+?>
@@ -0,0 +1,62 @@
+<?php
+// scrapes images off a web site
+global $basepath, $content;
+$basepath = "c:/2012-reference/patterns/original/";
+$content = "";
+
+function gen_content() {
+ global $content;
+ for($i = 244; $i < 254; $i++) {
+
+ $page = file_get_contents('c:/2012-reference/patterns/original/apl' . $i . '/apl' . $i . '.htm');
+ $finished = false;
+ while (!$finished) {
+ $pos1 = stripos($page, 'SRC=');
+ if ($pos1 < 5) {
+ $finished = true;
+ } else {
+ $tmp = substr($page, $pos1 + 5, 3);
+ // echo $tmp . '<br>';
+
+ if ($tmp <> '../') {
+ $pos2 = stripos($page, '.jpg');
+ if ($pos2 < $pos1 + 25) {
+ $image = substr($page, $pos1 + 5, $pos2 - $pos1 - 1);
+ echo $image . '<br>'; // . ' ' . $pos1 . '<br>-' . $pos2 . '<br>';
+ $content = $content . $image . '<br>';
+ } else {
+ $pos2 = stripos($page, '.gif');
+ if ($pos2 < $pos1 + 20) {
+ $image = substr($page, $pos1 + 5, $pos2 - $pos1 - 1);
+ //echo $image . '<br>'; // . ' ' . $pos1 . '<br>-' . $pos2 . '<br>';
+ $content = $content . $image . '<br>';
+ }
+ }
+ $source = file_get_contents('http://www.patternlanguage.com/apl/apl' . $i . '/' . $image);
+ $destination = 'c:/2012-reference/patterns/original/apl' . $i . '/' . $image;
+ file_put_contents($destination, $source);
+ }
+ $page = substr($page, $pos1 + 25);
+ }
+ }
+
+ }
+}
+function new_file($s,$content) {
+ global $basepath;
+ if (!$handle = fopen($basepath . $s, 'w')) {
+ echo "Cannot open file ($s)";
+ exit;
+ }
+ if (fwrite($handle, $content) === FALSE) {
+ echo "Cannot write to file ($s)";
+ exit;
+ }
+ // echo "<br>Success, wrote ($content) to file: $s";
+ fclose($handle);
+}
+
+gen_content();
+echo $content;
+// new_file('1try.htm',$content);
+?>
@@ -0,0 +1,42 @@
+<?php
+global $sourcesPath, $content;
+$sourcesPath = "c:/2012-reference/patterns/sources/";
+
+function doIt() {
+ global $sourcesPath;
+ $source = file($sourcesPath . 'aplbullets.htm');
+ $destination = $sourcesPath . 'cats.htm';
+ $cat = 'Regional policies';
+ $content = 'if ( $i < 2 ) { $subCat = "Regions instead of countries"; }' . "\n";
+ for($i = 0; $i < count($source); $i++) {
+ $line = $source[$i];
+ $pattern = "/span class=h3class/"; // new sub-cat
+ if ( preg_match($pattern, $line ) ) {
+ $previousCat = $cat;
+ $pattern = '/<span\b[^>]*>(.*?)<\/span>/smi';
+ $replacement = '\\1';
+ $cat = preg_replace($pattern, $replacement, $line);
+ $cat = substr($cat, 2, strlen($cat) - 3);
+ // echo $i . ' ' . ' ' . $line . '<br>';
+ }
+
+ $pattern = "/span class=h5class/";
+ if ( preg_match($pattern, $line ) ) {
+ $pattern = '/<p><a\b[^>]*>(.*?)<\/a>/smi';
+ $replacement = '\\1';
+ $line = preg_replace($pattern, $replacement, $source[$i + 1]);
+ $pos1 = strpos($line, ' ');
+ $number = substr($line, 0, $pos1);
+ if ($number > 2) {
+ $content .= 'elseif ( $i < ' . $number . ' ) { $subCat = "' . $previousCat . '"; }' . "\n";
+ }
+ }
+ }
+ $content .= 'else { $subCat = "Complete the Building"; }' . "\n";
+ file_put_contents($destination, $content);
+ echo $content;
+}
+
+doIt();
+
+?>
@@ -0,0 +1,19 @@
+<?php
+global $basepath, $content;
+$basepath = "c:/2012-reference/patterns/";
+
+function gen_content() {
+ global $basepath;
+ for($i = 1; $i < 254; $i++) {
+
+ $original = $basepath . 'clean2/apl' . $i . '/apl' . $i . '.htm';
+ $destination = $basepath . 'clean/apl' . $i . '/apl' . $i . '.htm';
+ echo $i . ' ' . $original . '<br>';
+
+ echo system('c:/2012-setup/htmltidy/tidy -output '. $destination . ' -w 0 --tidy-mark no --char-encoding utf8' . $original);
+
+ }
+}
+
+gen_content();
+?>
File renamed without changes.
@@ -0,0 +1,13 @@
+<?php
+function new_folder ($s) {
+ echo "Creating new folder...<br>";
+ global $basepath, $dir;
+ $d = $basepath.$dir.$s;
+ if (is_dir($d)) {echo "Folder already exists...<br>"; return;}
+ if (!mkdir($d, 0777)) {echo "Did not create folder...<br>";} else {echo "OK!<br>";}
+}
+
+for($i = 1; $i < 254; $i++){
+ new_folder("C:/2012-reference/patterns/newpat/newpat" . $i);
+}
+?>
File renamed without changes.
@@ -0,0 +1,163 @@
+<?php
+global $basepath, $content;
+$basepath = "c:/2012-reference/patterns/";
+
+function gen_content() {
+ global $basepath;
+ for($i = 1; $i < 254; $i++) {
+
+ $source = file_get_contents($basepath . 'tidy/apl' . $i . '/apl' . $i . '.htm');
+ $destination = $basepath . 'clean2/apl' . $i . '/apl' . $i . '.htm';
+ $cleaned = $source;
+
+ $pattern = '/<meta(.*?)>/si';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<style\b[^>]*>(.*?)<\/style>/siu';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<base target="_self">/';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<body(.*?)>/';
+ $replacement = '<body>';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<body>\r\n<p>(.*?)<\/p>/si';
+ $replacement = '<h1>\\1</h1>';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<span class=\"h2class\">(.*?)<\/span>/si';
+ $replacement = '\\1';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<span class=\"h3class\">(.*?)<\/span>/si';
+ $replacement = '\\1';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<span class=\"h5class\">(.*?)<\/span>/si';
+ $replacement = '\\1';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<span class=\"h6class\">(.*?)<\/span>/si';
+ $replacement = '\\1';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<div class=\"h4class\" align=\"center\">(.*?)<\/div>/si';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/ align=\"center\"/si';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/ width=(.*?)border=\"2\"/si';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/ width=\"120\"/si';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/\.\.\./';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<div>(.*?)<\/div>/si';
+ $replacement = "<p>\\1</p>";
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<p>&nbsp;<\/p>/si';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/&nbsp;/si';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<br>/si';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ // pattern 6 +
+
+ $pattern = '/<center>(.*?)<\/center>/si';
+ $replacement = '\\1';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<h4>(.*?)<\/h4>/si'; // copyright only?
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<font color=\"#FF0000\">/si';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<font color=\"#FFFF99\">/si';
+ $replacement = ' '; // <<<<
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ // $pattern = '/\.<\/font>/si';
+ // $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<\/font>/si';
+ $replacement = '';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<h3>(.*?)<\/h3>/si';
+ $replacement = '<p>\\1</p>';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<h5>(.*?)<\/h5>/si';
+ $replacement = '<p>\\1</p>';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<h6>(.*?)<\/h6>/si';
+ $replacement = '<p>\\1</p>';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/h2/si';
+ $replacement = 'h1';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/\r\n\r\n/si';
+ $replacement = "\r\n";
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/\r\n\r\n/si';
+ $replacement = "\r\n";
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/\s\s\./';
+ $replacement = ' ';
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/\r\n<img(.*?)>/si';
+ $replacement = "\r\n<p><img\\1></p>";
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<p>\r\n<\/p>/si';
+ $replacement = "";
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<p>\r\n<p>/si';
+ $replacement = "<p>";
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/<\/p>\r\n<\/p>/si';
+ $replacement = "</p>";
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ $pattern = '/\r\n\r\n/si';
+ $replacement = "\r\n";
+ $cleaned = preg_replace($pattern, $replacement, $cleaned);
+
+ file_put_contents($destination, $cleaned);
+ echo $i . ' ' . $cleaned . '<br>';
+ }
+}
+
+gen_content();
+?>
Oops, something went wrong.

0 comments on commit bcaa144

Please sign in to comment.