Code

Project: jvfeatures

jvtypes.h      jvfeatures.h      chessSeg.cpp      jvtypes.cpp      jvtest.cpp      jvfeatures.cpp     

Project: Other

migrateMailbox.scpt.txt     

Project: Infinite HMM Tutorial

run.m      iHMM_tutorial.zip      HDP_HMM.m      README.txt      ConditionalProbabilityTable.m      HDP.m      HMMProblem.m      HMM.m     

Project: RRT

RRT.h      plot_output.py      RRT.tgz      rrt_test.cpp      RRT.cpp      BidirectionalRRT.cpp      AbstractRRT.cpp     

Project: Box2D_friction_mod

WheelConstraint.h      test_TopDownCar.py      b2FrictionJoint.h      python_friction_joint.patch      test_TopDownFrictionJoint.py      TestEntries.cpp      TopDownCar.h      b2FrictionJoint.cpp      box2d_friction_joint.patch     

Project: Dirichlet Process Mixture Tutorial

EM_GM.m      DP_Demo.m      DPMM.m      DP_Tutorial.zip      DirichletProcess.m      gaussian_EM.m     

Project: Arduino_Code

plot_ardunio_data.sh      Arduino_Code.zip      convert_range2D.py      arduino-serial.c      oscilloscope.sh      oscilloscope.pde      motordriver.pde      helicopter_controller.pde      accelerometer_test.pde      ranger_plane_sweep.pde      clodbuster_controller.pde      pwm_manual.pde      ranger_test.pde      servo_test.pde     

Project: ArduCom

arducom.py      setup.py     

Project: support

geshi.php      Protector.php     

Project: Cogent

CodePane.php      NotesPane.php      PicsPane.php      Cogent.php      PubsTable.php     
Click here to download "resources/site-code/Cogent/Cogent.php"

resources/site-code/Cogent/Cogent.php

<?php
/**
* Cogent - a content generation "agent"
* An abstract class for generating HTML content by scanning a directory
* containing sub-directories with presentable content.  The simple goal
* is to make it quick to throw together code that generates HTML by scanning
* the filesystem in cases where a bunch of content is organized over a flat
* directory structure with meaningful folder names.
*
* Cogent provides generic methods for listing directories under a root
* path, and files matching a filter.  The indended use for this class is
* for children to define a public method called "generate" which does the
* actual work of writing HTML based on what it found during the directory scan.
*
* Outline:
* Cogent("<directory name>", <array of filename suffixes>)
* Cogent->scan();               // scans all directories under <directory name> for content matching provided filters (conjunctive)
* Cogent->generate();   // generates HTML output for all images found, organized by album
*
*
* Author: Jonathan Scholz
* 2/3/2010
*/

abstract class Cogent
{
        /**
         * Property declarations:
         */

        protected $rootdir = "/~jscholz/cc.gatech~jscholz6/";
        protected $filters;
        protected $content_dirs;
        protected $recursive = false;
        protected $depth = 0;

        function __construct($rdir, $suffixes, $recursive) {
                $this->rootdir = $rdir;
                $this->filters = $suffixes;
                $this->recursive = $recursive;
        }

        /**
        * Utility function: a case-insensitive version of in_array
        */

        protected static function in_arrayi($needle, $haystack) {
                return in_array(strtolower($needle), array_map('strtolower', $haystack));
        }

/**
* Produces an array of all directories under the rootdir
*/

protected function scan(){

        $this->content_dirs = array();

        // Scan the root directory for all subdirs
        $roothndl = @opendir($this->rootdir); // @: suppress warning

        if ($roothndl == false) {
                print "<!-- Warning: could not find directory \"$this->rootdir\" -->";
                // return;
                throw new Exception("Could not find directory \"$this->rootdir\"");
        } else {
                // get each entry, filtered (case-insensitive)
                while (false !== ($dir_item = readdir($roothndl))) {
                       
                        if (is_dir($this->rootdir . "/" . $dir_item) &&
                                $dir_item != "." &&
                                $dir_item != ".." &&
                                $dir_item!=".svn") {
                                $this->content_dirs[] = $dir_item;
                        }
                }
                closedir($roothndl); // close directory
        }
}

/**
* Produces an array of all filenames matching the filter for each directory
*/

protected function list_content($directory) {
        $this->content_array = array();
        // open appropriate album
        $hndl = @opendir($directory);
        if ($hndl == false) {
                print "<!-- Warning: could not find directory \"$directory\" -->";
                exit;
        } else {
                // get each entry, filtered (case-insensitive)

                while (false !== ($dir_item = readdir($hndl))) {
                        // Get file extension
                        $ext = substr(strrchr($dir_item, '.'), 1);
                        if (Cogent::in_arrayi($ext, $this->filters)) {
                                $content_array[] = $dir_item;
                        }
                }
                closedir($hndl); // close directory
                if (isset($content_array)) {
                        return $content_array;
                }
                return;
                }
        }

/**
* Top-level executable method: scans from root directory and issues call to generate method
*/

public function run(){
        try {
                print "<!-- (Content generated by Cogent.php) -->\n";
                // Process subdirs
                $this->scan();
               
                for ($i=0; $i < count($this->content_dirs); $i++) {
                        $dir = $this->content_dirs[$i];
                        // scan topic directories for content (matching provided extensions):
                        $files = $this->list_content($this->rootdir."/".$dir);
                        // generate html for content
                        $this->generate($dir, $files);

                        if ($this->recursive) {
                                $cg = clone $this; // shallow copy to new object
                                $cg->rootdir = $this->rootdir.'/'.$dir; // update rootdir
                                $cg->depth++;
                                $cg->run();
                        }
                }
                print "<!-- (End Cogent.php content) -->\n";
        }
        catch (Exception $e) {
                echo 'Message: ' .$e->getMessage();
        }
}

/**
* Generates HTML for content found in specified directory
*/

abstract protected function generate($dirname, $files);

} // End: class Cogent

?>
 

About me

Pic of me