From 4cc7f3be63be6949f054559e077067b84aaf643c Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Fri, 9 Jul 2010 16:44:01 -0700 Subject: [PATCH] new directory recursion --- content/code/{ => bash}/date_for_filename | 0 content/code/{ => bash}/imageslice | 0 content/code/generic_entry | 11 ++ content/code/mel/mel_entry | 4 + content/code/{ => mel}/mel_notepad | 0 content/code/{ => mel}/mel_sphere_intersect | 0 content/code/mel_UV-luminosity/config | 3 - content/code/mel_UV-luminosity/content.html | 30 --- content/code/mel_sphere-intersect/config | 3 - .../code/mel_sphere-intersect/content.html | 65 ------- content/log/cat1/test_entry_in_cat_1 | 3 + content/log/cat2/test_entry_in_cat2 | 3 + content/log/cat2/test_entry_in_cat2_again | 3 + .../installation/installation_project | 4 + content/projects/project1 | 4 + content/projects/project2 | 4 + lib/data.php | 181 +++++++++--------- lib/init.php | 4 +- lib/output.php | 9 + pages/agg | 3 + public/index.php | 34 ++-- templates/default.html.tpl | 2 +- templates/entry.html.tpl | 5 +- templates/nav.html.tpl | 16 +- 24 files changed, 172 insertions(+), 219 deletions(-) rename content/code/{ => bash}/date_for_filename (100%) rename content/code/{ => bash}/imageslice (100%) create mode 100644 content/code/generic_entry create mode 100644 content/code/mel/mel_entry rename content/code/{ => mel}/mel_notepad (100%) rename content/code/{ => mel}/mel_sphere_intersect (100%) delete mode 100644 content/code/mel_UV-luminosity/config delete mode 100644 content/code/mel_UV-luminosity/content.html delete mode 100644 content/code/mel_sphere-intersect/config delete mode 100644 content/code/mel_sphere-intersect/content.html create mode 100644 content/log/cat1/test_entry_in_cat_1 create mode 100644 content/log/cat2/test_entry_in_cat2 create mode 100644 content/log/cat2/test_entry_in_cat2_again create mode 100644 content/projects/installation/installation_project create mode 100644 content/projects/project1 create mode 100644 content/projects/project2 create mode 100644 pages/agg diff --git a/content/code/date_for_filename b/content/code/bash/date_for_filename similarity index 100% rename from content/code/date_for_filename rename to content/code/bash/date_for_filename diff --git a/content/code/imageslice b/content/code/bash/imageslice similarity index 100% rename from content/code/imageslice rename to content/code/bash/imageslice diff --git a/content/code/generic_entry b/content/code/generic_entry new file mode 100644 index 0000000..28a536c --- /dev/null +++ b/content/code/generic_entry @@ -0,0 +1,11 @@ +title = a generic entry +date = 2009-06-05 +tags = generic entry +-- +the actual entry for this generic entry + +it's multi line + +`and it's got code!` + +wow. \ No newline at end of file diff --git a/content/code/mel/mel_entry b/content/code/mel/mel_entry new file mode 100644 index 0000000..1af2671 --- /dev/null +++ b/content/code/mel/mel_entry @@ -0,0 +1,4 @@ +title = a mel entry +tags = some tags for this mel entry +-- +the actual entry \ No newline at end of file diff --git a/content/code/mel_notepad b/content/code/mel/mel_notepad similarity index 100% rename from content/code/mel_notepad rename to content/code/mel/mel_notepad diff --git a/content/code/mel_sphere_intersect b/content/code/mel/mel_sphere_intersect similarity index 100% rename from content/code/mel_sphere_intersect rename to content/code/mel/mel_sphere_intersect diff --git a/content/code/mel_UV-luminosity/config b/content/code/mel_UV-luminosity/config deleted file mode 100644 index db3cd05..0000000 --- a/content/code/mel_UV-luminosity/config +++ /dev/null @@ -1,3 +0,0 @@ -title = Luminosity at UV coord -date = 2009/02/15 -medium = maya/mel diff --git a/content/code/mel_UV-luminosity/content.html b/content/code/mel_UV-luminosity/content.html deleted file mode 100644 index 74dc3cd..0000000 --- a/content/code/mel_UV-luminosity/content.html +++ /dev/null @@ -1,30 +0,0 @@ -

-Get luminosity of texture at UV coord in Maya with custom rgbToHsv node. -

- -
-global proc float getLuminosityAtUVCoord(string $texture, float $U, float $V)
-{
-	$id = "lum"; // unique identifier in case there are duplicate nodes
-	$rgbToHsv = "rgbToHsv_" + $id ; // create rgbToHSV node if necesarry
-	if(!`objExists $rgbToHsv`) {
-		createNode rgbToHsv -n $rgbToHsv;
-	}
-
-	vector $color = `colorAtPoint -o RGB -u $U -v $V  $texture`;
-
-	setAttr ($rgbToHsv+".ir") ($color.x);
-	setAttr ($rgbToHsv+".ig") ($color.y);
-	setAttr ($rgbToHsv+".ib") ($color.z);
-
-	return `getAttr ($rgbToHsv+".ov")`;
-}
-
- -

to use

-
-// returns luminosity value of 0.5 U 0.5 V on texture file_seq
-$value = getLuminosityAtUVCoord("file_seq", 0.5, 0.5);
-
- - \ No newline at end of file diff --git a/content/code/mel_sphere-intersect/config b/content/code/mel_sphere-intersect/config deleted file mode 100644 index b45fefc..0000000 --- a/content/code/mel_sphere-intersect/config +++ /dev/null @@ -1,3 +0,0 @@ -title = Sphere Intersect -date = 2009-06-12 -medium = maya/mel \ No newline at end of file diff --git a/content/code/mel_sphere-intersect/content.html b/content/code/mel_sphere-intersect/content.html deleted file mode 100644 index 8007317..0000000 --- a/content/code/mel_sphere-intersect/content.html +++ /dev/null @@ -1,65 +0,0 @@ -

-Function to return location of intersect with poly mesh and spherical object moving in the positive direction on the Y axis. -
-

- -

-mel source -

-
-
-global proc intersectSphereY()
-{
-    	print(". . . . . go go go\n");
-
-	int $iter = 50;
-	float $start[3] = {0, -0.5, 0};
-	float $limit[3] = {0, 5.0, 0};
-    	$mesh = "test_mesh";    
-	$tmpCN = "cpom";
-
-    
-	$obj = "rod1";
-    	float $radius = 0.5;
-    	float $curPos[3] = {0, 0, 0};
-
-	for ($i = 0; $i <= $iter; $i++)
-	{    
-       	$mesh = "test_mesh";
-		$shape = `listRelatives -shapes $mesh`;
-
-		createNode -n $tmpCN closestPointOnMesh;
-        	connectAttr -f ($shape[0] + ".outMesh") ($tmpCN + ".inMesh");
-        	setAttr ($tmpCN + ".inPosition") $curPos[0] $curPos[1] $curPos[2];
-        	
-		$cpom = `getAttr ($tmpCN + ".position")`;
-        	
-        	if ( pointDist($curPos, $cpom) <= $radius ) {
-			return ". . bonk\n";
-        	}
-
-        	$curPos[1] = ($limit.y) / $iter * $i;
-        	setAttr ($obj + ".translateY") $curPos[1];
-
-        	delete $tmpCN;
-    	}
-	return ". nope\n";
-}
-
-global proc float pointDist(float $p1[], float $p2[])
-{
-    return sqrt( 
-	(($p1[0] - $p2[0]) * ($p1[0] - $p2[0])) + 
-	(($p1[1] - $p2[1]) * ($p1[1] - $p2[1])) + 
-	(($p1[2] - $p2[2]) * ($p1[2] - $p2[2])));
-}
-
-intersectSphereY;
-
-
- - - - - - \ No newline at end of file diff --git a/content/log/cat1/test_entry_in_cat_1 b/content/log/cat1/test_entry_in_cat_1 new file mode 100644 index 0000000..5ffef5c --- /dev/null +++ b/content/log/cat1/test_entry_in_cat_1 @@ -0,0 +1,3 @@ +title = a test entry in category 1 +-- +the actual entry of this test entry \ No newline at end of file diff --git a/content/log/cat2/test_entry_in_cat2 b/content/log/cat2/test_entry_in_cat2 new file mode 100644 index 0000000..b94d469 --- /dev/null +++ b/content/log/cat2/test_entry_in_cat2 @@ -0,0 +1,3 @@ +title = wow another test +-- +woot woot! \ No newline at end of file diff --git a/content/log/cat2/test_entry_in_cat2_again b/content/log/cat2/test_entry_in_cat2_again new file mode 100644 index 0000000..3a31912 --- /dev/null +++ b/content/log/cat2/test_entry_in_cat2_again @@ -0,0 +1,3 @@ +title = again! +-- +yeah, again, that's right \ No newline at end of file diff --git a/content/projects/installation/installation_project b/content/projects/installation/installation_project new file mode 100644 index 0000000..e04b198 --- /dev/null +++ b/content/projects/installation/installation_project @@ -0,0 +1,4 @@ +title = Installation Project +tags = install project +-- +an installation project \ No newline at end of file diff --git a/content/projects/project1 b/content/projects/project1 new file mode 100644 index 0000000..a0f6046 --- /dev/null +++ b/content/projects/project1 @@ -0,0 +1,4 @@ +title = project 1 +tags = what what what +-- +some content \ No newline at end of file diff --git a/content/projects/project2 b/content/projects/project2 new file mode 100644 index 0000000..28ac44c --- /dev/null +++ b/content/projects/project2 @@ -0,0 +1,4 @@ +title = "project2" +tags = what the eff +-- +project 2 \ No newline at end of file diff --git a/lib/data.php b/lib/data.php index 6d04a9e..8c6a537 100644 --- a/lib/data.php +++ b/lib/data.php @@ -1,119 +1,124 @@ $info) { + if (!$info->isDir()) { + $entries[] = parse_entry($info); } } - - // order by date - foreach ($result as $key => $row) { - $time[$key] = $row['timestamp']; + + switch ($order_by) + { + default : + foreach ($entries as $key => $row) + $time[$key] = $row['timestamp']; + if ($time) + array_multisort($time, $order, $entries); } - if ($time) - array_multisort($time, SORT_DESC, $result); - - return array($result, $result_total); + + return array($entries, sizeof($entries)); } /** - * parse data file + * get pages */ -function parse_file($f) +function get_pages() { - $pathparts = explode("/", dirname($f)); - - $file_contents = explode("\n", file_get_contents($f, FILE_USE_INCLUDE_PATH)); - $cc = ""; - $content = ""; - $conf = true; - foreach ( $file_contents as $fc ) { - if ($fc == CONFIG_DELIMITER) { - $conf = false; - continue; - } - if ($conf) $cc .= $fc . "\n"; - else $content .= $fc . "\n"; + $path = LOCAL_ROOT . PAGE_DIR; + $dir_iterator = new DirectoryIterator($path); + $pages = array(); + foreach($dir_iterator as $page) { + if ($page->isDir()) continue; + $arr = parse_entry($page, 1); + $arr['is_page'] = 1; + $pages[] = $arr; } - - $config = parse_ini_string($cc); - - $res = $config; - - $res['url'] = $res['is_page'] == 1 ? get_base_dir() . '/' . basename($f) . '/' : get_base_dir() . '/' . $pathparts[sizeof($pathparts)-1] . '/' . basename($f); - $res['timestamp'] = date('U', strtotime( $config['date'] ? $config['date'] : filemtime($f))); - $res['cat'] = $pathparts[sizeof($pathparts)-1]; - $res['content'] = Markdown($content); - $res['tags'] = explode(' ', $config['tags']); - - return $res; + return $pages; } /** - * get content folders + * returns directories of a folder + * @param path the path to search. defaults to the CONTENT_DIR + * @param recursive default is true */ -function get_content_folders() +function get_dirs( $path = "", $args = array()) { - $folders = glob(LOCAL_ROOT . CONTENT_DIR . DIRECTORY_SEPARATOR . '/*', GLOB_ONLYDIR); - $content_folders = array(); - foreach($folders as $folder) - $content_folders[] = array( - 'basename' => basename($folder), - 'title' => basename($folder), - 'url' => get_base_dir() . '/' . basename($folder) . '/' - ); - return $content_folders; + $recursive = isset($args['recursive']) ? $args['recursive'] : 1; + $path = LOCAL_ROOT . CONTENT_DIR . $path; + + if ($recursive) { + $iterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_PATHNAME); + $dir_iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST); + } + else { + $dir_iterator = new DirectoryIterator($path); + } + $dirs = array(); + foreach ($dir_iterator as $dir => $info) { + if ($info->isDir() && $info->getFilename() != '.' && $info->getFilename() != '..') { + $dirs[] = str_replace($path, "", $info->getRealPath()); + } + } + return $dirs; } /** - * get pages + * @param splFileInfo SPLFileInfo Object + * @param include_drafts default is false */ -function get_pages() +function parse_entry($fileInfo, $page = 0) { - $page_files = glob(LOCAL_ROOT . PAGE_DIR . DIRECTORY_SEPARATOR . '/*'); - $pages = array(); - foreach($page_files as $page) { - $arr = parse_file($page); - $arr['is_page'] = 1; - $pages[] = $arr; + $config = ""; + $content = ""; + $passed_config = false; + $file_contents = file($fileInfo->getRealPath(), FILE_USE_INCLUDE_PATH); + foreach ( $file_contents as $line ) { + if (trim($line) == CONFIG_DELIMITER) { + $passed_config = true; + continue; + } + if (!$passed_config) { + $config .= $line; + continue; + } + $content .= $line; } - return $pages; + + $file = array(); + $file['config'] = parse_ini_string($config); + + $file['title'] = $file['config']['title']; + $file['timestamp'] = $file['config']['date'] ? date('U', strtotime( $file['config']['date'])) : $fileInfo->getCTime(); + $file['tags'] = $file['config']['tags'] ? explode(" ", $file['config']['tags']) : null; + $file['content'] = Markdown($content); + $file['cat'] = $page ? null : substr(clean_slashes(str_replace(LOCAL_ROOT . CONTENT_DIR, "", $fileInfo->getPath())),1); + $file['path'] = $fileInfo->getRealPath(); + $file['url'] = WEB_ROOT . $file['cat'] . $fileInfo->getFilename(); + + return $file; } + ?> diff --git a/lib/init.php b/lib/init.php index 7e2b8f5..a465d6c 100644 --- a/lib/init.php +++ b/lib/init.php @@ -6,11 +6,11 @@ define ('SITE_TITLE', 'quilime'); define ('LOCAL_ROOT', '/home/quilime/quilime-site/' ); - define ('WEB_ROOT', 'http://py.quilime.com/' ); + define ('WEB_ROOT', 'http://dev.quilime.com/' ); define ('CONTENT_DIR', 'content'); + define ('PAGE_DIR', 'pages'); define ('TEMPLATE_DIR', 'templates'); - define ('PAGE_DIR', 'pages'); define ('CONFIG_DELIMITER', '--'); require_once 'data.php'; diff --git a/lib/output.php b/lib/output.php index e70c913..c377dad 100644 --- a/lib/output.php +++ b/lib/output.php @@ -51,6 +51,15 @@ if( !function_exists('parse_ini_string') ) { } +/** + * removes double slashes + */ +function clean_slashes($path) +{ + return preg_replace('/\/+/', '/', $path); +} + + /** * @param int $seconds Number of seconds to convert into a human-readable timestamp * @return tring Human-readable approximate timestamp like "2 hours" diff --git a/pages/agg b/pages/agg new file mode 100644 index 0000000..8a2dcea --- /dev/null +++ b/pages/agg @@ -0,0 +1,3 @@ +title = agg +template = agg +-- diff --git a/public/index.php b/public/index.php index da0c655..d7221da 100644 --- a/public/index.php +++ b/public/index.php @@ -6,39 +6,35 @@ list($response_format, $response_mime_type) = parse_format($url_parts['extension'], 'html'); + # setup template $t = get_template_instance(); $t->response_format = $response_format; $t->assign('view', $_GET['v']); - # content folder - if (is_dir(LOCAL_ROOT . CONTENT_DIR . DIRECTORY_SEPARATOR . $url_parts['url']) && $url_parts['url'] != "/") { - list($data, $total) = get_data(array($url_parts['url'])); + # is folder + if (is_dir(LOCAL_ROOT . CONTENT_DIR . $url_parts['url']) && $url_parts['url'] != "/") { + list($data, $total) = get_entries($url_parts['url']); $t->assign('data', $data); } - # single file - else if (is_file( LOCAL_ROOT . CONTENT_DIR . $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename'])) { - $t->assign('single', true); - $t->assign('data', parse_file(LOCAL_ROOT . CONTENT_DIR . $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename'])); + # is file + else if (is_file( LOCAL_ROOT . CONTENT_DIR . $url_parts['url'])) { + $t->assign('single', true); + $t->assign('data', parse_entry(new SplFileInfo(LOCAL_ROOT . CONTENT_DIR . $url_parts['url']))); $template = 'single.'.$response_format.'.tpl'; } - # page - else if (is_file( LOCAL_ROOT . PAGE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename'] )) { - $page = parse_file(LOCAL_ROOT . PAGE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename']); + # is page + else if (is_file( LOCAL_ROOT . PAGE_DIR . $url_parts['url'])) { + $page = parse_entry(new SplFileInfo(LOCAL_ROOT . PAGE_DIR . $url_parts['url']), 1); $t->assign('data', $page); - $template = $page['template'] ? $page['template'] . '.' . $response_format . '.tpl' : 'page.' . $response_format . '.tpl'; + $template = $page['config']['template'] ? $page['config']['template'] . '.' . $response_format . '.tpl' : 'page.' . $response_format . '.tpl'; } - # direct template - else if (is_file( LOCAL_ROOT . TEMPLATE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename'] .'.'. $response_format . '.tpl')) { - $template = $url_parts['filename'] . '.' . $response_format . '.tpl'; - } - # default (index) + # default (all entries) else { - list($data, $total) = get_data(); + list($data, $total) = get_entries(); $t->assign('data', $data); } - - # render template + # render $t->assign('total', $total); header("Content-Type: {$response_mime_type}; charset=UTF-8"); $t->render($template); diff --git a/templates/default.html.tpl b/templates/default.html.tpl index f41a3de..678ebc3 100644 --- a/templates/default.html.tpl +++ b/templates/default.html.tpl @@ -12,7 +12,7 @@
- + 0) foreach($data as $entry): ?> include_template('entry.html.tpl', array('data' => $entry)); ?> diff --git a/templates/entry.html.tpl b/templates/entry.html.tpl index d0f1a4a..6994474 100644 --- a/templates/entry.html.tpl +++ b/templates/entry.html.tpl @@ -11,9 +11,9 @@ + diff --git a/templates/nav.html.tpl b/templates/nav.html.tpl index 2291480..0c33098 100644 --- a/templates/nav.html.tpl +++ b/templates/nav.html.tpl @@ -4,15 +4,19 @@
- - -
  • +

    content

    + 0)); ?> + +

  • -
  • aggregate
  • -
  • links
  • -
  • about
  • +

    pages

    + + + +
  • + -- 2.34.1