]> git.quilime.com - plog.git/commitdiff
new directory recursion
authorGabriel Dunne <gdunne@quilime.com>
Fri, 9 Jul 2010 23:44:01 +0000 (16:44 -0700)
committerGabriel Dunne <gdunne@quilime.com>
Fri, 9 Jul 2010 23:44:01 +0000 (16:44 -0700)
24 files changed:
content/code/bash/date_for_filename [moved from content/code/date_for_filename with 100% similarity]
content/code/bash/imageslice [moved from content/code/imageslice with 100% similarity]
content/code/generic_entry [new file with mode: 0644]
content/code/mel/mel_entry [new file with mode: 0644]
content/code/mel/mel_notepad [moved from content/code/mel_notepad with 100% similarity]
content/code/mel/mel_sphere_intersect [moved from content/code/mel_sphere_intersect with 100% similarity]
content/code/mel_UV-luminosity/config [deleted file]
content/code/mel_UV-luminosity/content.html [deleted file]
content/code/mel_sphere-intersect/config [deleted file]
content/code/mel_sphere-intersect/content.html [deleted file]
content/log/cat1/test_entry_in_cat_1 [new file with mode: 0644]
content/log/cat2/test_entry_in_cat2 [new file with mode: 0644]
content/log/cat2/test_entry_in_cat2_again [new file with mode: 0644]
content/projects/installation/installation_project [new file with mode: 0644]
content/projects/project1 [new file with mode: 0644]
content/projects/project2 [new file with mode: 0644]
lib/data.php
lib/init.php
lib/output.php
pages/agg [new file with mode: 0644]
public/index.php
templates/default.html.tpl
templates/entry.html.tpl
templates/nav.html.tpl

diff --git a/content/code/generic_entry b/content/code/generic_entry
new file mode 100644 (file)
index 0000000..28a536c
--- /dev/null
@@ -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 (file)
index 0000000..1af2671
--- /dev/null
@@ -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_UV-luminosity/config b/content/code/mel_UV-luminosity/config
deleted file mode 100644 (file)
index db3cd05..0000000
+++ /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 (file)
index 74dc3cd..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<p>
-Get luminosity of texture at UV coord in Maya with custom rgbToHsv node.
-</p>
-
-<pre class="prettyprint lang-mel">
-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")`;
-}
-</pre>
-
-<h3>to use</h3>
-<pre class="prettyprint lang-mel">
-// returns luminosity value of 0.5 U 0.5 V on texture file_seq
-$value = getLuminosityAtUVCoord("file_seq", 0.5, 0.5);
-</pre>
-
-</pre>
\ 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 (file)
index b45fefc..0000000
+++ /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 (file)
index 8007317..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-<p>
-Function to return location of intersect with poly mesh and spherical object moving in the positive direction on the Y axis.
-<br/>
-</p>
-
-<h2>
-mel source
-</h2>
-<pre class="prettyprint lang-mel">
-
-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;
-
-</pre>
-
-
-
-
-
-<img src="http://media.quilime.com/files/img/sphere_intersect.png">
\ 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 (file)
index 0000000..5ffef5c
--- /dev/null
@@ -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 (file)
index 0000000..b94d469
--- /dev/null
@@ -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 (file)
index 0000000..3a31912
--- /dev/null
@@ -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 (file)
index 0000000..e04b198
--- /dev/null
@@ -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 (file)
index 0000000..a0f6046
--- /dev/null
@@ -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 (file)
index 0000000..28ac44c
--- /dev/null
@@ -0,0 +1,4 @@
+title = "project2"
+tags = what the eff
+--
+project 2
\ No newline at end of file
index 6d04a9e2c87ec5c3c1e990e255009edc125cf3b0..8c6a537ff8412cd1b31c9ebf33cc8284631548fb 100644 (file)
 <?php
 
 /**
- * get data
+ *     return entries of a folder
+ *     @param path: the path to search. defaults to the CONTENT_DIR
+ *     @param args array
  */
-function get_data( $sources = array(),  $params  = array())
+function get_entries( $path = "", $args = array())
 {
-       // if no set sources, grab everything in the content folder
-       if (sizeof($sources) == 0)
-               $sources = get_content_folders();
-
-       $result = array();
-       $result_total = 0;
-       foreach ($sources as $dir) {
-
-               if (is_array($dir) && isset($dir['basename']))
-                       $dir = $dir['basename'];
-
-               $contents = glob(LOCAL_ROOT . CONTENT_DIR . DIRECTORY_SEPARATOR . $dir . '/*');
-
-               if (sizeof($contents) <= 0) continue;
-
-               foreach ($contents as $f) {
-                       if (is_file($f)) {
-
-                               if ($params['name']) {
-                                       if (basename($f) != $params['name'])
-                                               continue;
-                               }
-
-                               $parsed = parse_file($f);
-
-                               if ($parsed['draft'])
-                                       continue;
-
-                               $result[] = $parsed;
-                               $result_total++;
-                       }
+       $recursive = isset($args['recursive']) ? $args['recursive'] : 1;
+       $order_by = empty($args['order_by']) ? null : $args['order_by'];
+       $order = empty($args['order']) ? SORT_DESC : $args['order'];
+       
+       $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);
+       }
+       $entries = array();
+       foreach ($dir_iterator as $file => $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;
 }
 
+
 ?>
index 7e2b8f59b235b6e9dd1b4c19d19866756ec3066c..a465d6c591eb697fc9facb0d2a51a33ca5db207d 100644 (file)
@@ -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';
index e70c913c30bf15fc7691de86c6ba7fdc28c77f32..c377dad7edc4c8d9fd79de078a1a78033620591b 100644 (file)
@@ -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 (file)
index 0000000..8a2dcea
--- /dev/null
+++ b/pages/agg
@@ -0,0 +1,3 @@
+title = agg
+template = agg
+--
index da0c655a0e16966eb8e4644a2791db8f19715091..d7221da6cd3ead4debbb8cd3b5d8c1fed0dfb6fb 100644 (file)
@@ -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);
index f41a3dea72f12097f8604523fa444d68cb4318b4..678ebc3cc17c7b7886837d3948a478821d26ab82 100644 (file)
@@ -12,7 +12,7 @@
     
 <div id="content">
 
-       <? foreach($data as $entry): ?>
+       <? if (sizeof($data) > 0) foreach($data as $entry): ?>
        <? $this->include_template('entry.html.tpl', array('data' => $entry)); ?>
        <? endforeach; ?>       
        
index d0f1a4a11753ad1410f6dbc49b49ddd0e1283617..699447468fe284cd702ce1b837c3d9c6ae2548d0 100644 (file)
@@ -11,9 +11,9 @@
 
        <? if ($single) :?>
        <div class="metadata">
-               posted <?=date("F d, Y", $data['timestamp'])?> in <a href="/<?=$data['cat'];?>/"><?=$data['cat'];?></a><br/>
+               posted <?=date("F d, Y", $data['timestamp'])?> in <a href="<?=get_base_dir();?>/<?=$data['cat'];?>"><?=$data['cat'];?></a><br/>
                <ul class="tags">
-               <? foreach($data['tags'] as $tag) : ?>
+               <? if (sizeof($data['tags']) > 0) foreach($data['tags'] as $tag) : ?>
                <li>#<?=$tag?></li>
                <? endforeach; ?>
                </ul>
@@ -21,3 +21,4 @@
        <? endif; ?>
 
 </div>
+
index 2291480ccb5a49aea2cab004d0cc21dcf8033989..0c33098f7e365c51fd3968d632da912aa5fa1a9a 100644 (file)
@@ -4,15 +4,19 @@
        
        <br />
        
-       <? $categories = get_content_folders(); ?>
-       <? foreach($categories as $cat) : ?>
-       <li><a href="<?=$cat['url']?>"><?=$cat['title']?></a></li>
+       <h2>content</h2>
+       <? $dirs = get_dirs("/", array('recursive' => 0)); ?>
+       <? foreach($dirs as $d) : ?>
+       <li><a href="<?=get_base_dir();?>/<?=$d?>"><?=$d?></a></li>
        <? endforeach; ?>
        
        <br />
        
-       <li><a href="/agg/">aggregate</a></li>
-       <li><a href="/links/">links</a></li>    
-       <li><a href="/about/">about</a></li>
+       <h2>pages</h2>  
+       
+       <? $pages = get_pages(); ?>
+       <? foreach($pages as $p) : ?>
+       <li><a href="<?=$p['url']?>"><?=$p['title']?></a></li>
+       <? endforeach; ?>
 
 </ul>