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/NotesPane.php"

resources/site-code/Cogent/NotesPane.php

<?php
require("Cogent.php");
/**
* NotesPane
* A class for scanning for research notes exported by emacs into a
* target directory, and parsing out the desired content
*
* Outline:
* NotesPane("<directory name>")
* NotesPane->run();     // runs HTML output for all notes found
*
* Author: Jonathan Scholz
* 1/28/2012
*/

class NotesPane extends Cogent
{
        protected $password = null;
       
        public function run() {
                parent::run();
                $this->handle_anchor();
        }

        /*
         * Adds a content password
         */

        public function set_password($password) {
                $this->password = $password;
        }

        /*
         * Generates the HTML for provided files
         *
         * In this case involves scanning the requested directory
         * and installing _GET anchors for each one
         */

        public function generate($dir, $files){
                // write heading for this project
                if ($this->depth == 0) {
                        print '<h3 id="'.$dir.'">'.$dir."</h3>\n";
                }
               
                // count elements in array
                $numfiles = count($files);
               
                // loop over files to install url GET link
                for ($file=0; $file < $numfiles; $file++) {
                        print '<a href="'.
                                "notes.php?targ=$this->rootdir/$dir/$files[$file]".'">'.
                                "$files[$file]</a><br>\n";
                }
        }
       
        /* Installs the block for handling the _GET url argument, and
         * generates the appropriate html for that file.
         *
         */

        protected function handle_anchor() {
                if (isset($_GET['targ'])) {
                        // Check the url _GET that we NotesPane installed for us
                        $targ = $_GET['targ'];

                        // Extract content from target file
                        $content = "<hr>\n".
                                '<div class="notesbox">'.
                                '<h3 style="text-align: center">'.$targ.'</h3>'.
                                '<div class="scrollbox">'.
                                $this->parse_note($targ).
                                '</div>'.
                                '</div>';
                       
                        // Display content if password is provided
                        if ($this->password != null) {
                                require("resources/site-code/support/Protector.php");
                                $p = new Protector($this->password);
                                $p->protect($content);
                        } else {
                                print $content;
                        }
                }
        }

        /*
         * Helper function: Parses the specified file
         *
         * In this case involves parsing out the scripts and body
         * of each file, and re-serializing.
         */

        protected function parse_note($file_name) {
                // Loads string from research.html, but parses out the body only
                $DOM = new DOMDocument;
                $DOM->loadHTMLFile($file_name);

                // extract stuff we want
                $body = $DOM->getElementsByTagName("body");
                $scripts = $DOM->getElementsByTagName("script");

                // Re-serialize
                // Simple approach supported on PHP 5.3.6+
                // Print all javascripts (need the MathJax for latex)
                // for ($i = 0; $i < $scripts->length; $i++)
                //      print $DOM->saveHTML($scripts->item($i));
                // Print the HTML body
                // print $DOM->saveHTML($body->item(0));

                // Shitty approach pre PHP 5.3.6
                $doc = new DOMDocument('1.0');
                // Extract all javascripts (need the MathJax for latex)
                for ($i = 0; $i < $scripts->length; $i++)
                        $doc->appendChild($doc->importNode($scripts->item($i),true));
                // Grab the HTML body
                $doc->appendChild($doc->importNode($DOM->getElementsByTagName("body")->item(0),true));
               
                return $doc->saveHTML();
        }
} // End: class NotesPane

?>
 

About me

Pic of me