Merged branch 'no-javascript' with notes
authorDylan Lloyd <dylan@psu.edu>
Thu, 17 Feb 2011 04:38:42 +0000 (23:38 -0500)
committerDylan Lloyd <dylan@psu.edu>
Thu, 17 Feb 2011 04:38:42 +0000 (23:38 -0500)
Now gracefully falls back to friendly URL's when javascript is disabled. Links are adjusted to anchors with javascript on page load.

notes/ are paginated with index.php and rewritten to from /notes/page/# and notes are permalinked at /notes/note_title. index.php loads exhibits from MySQL to allow for this.

notes/ are published via publish.py, and exhibits are published via publish_projects.py. THESE SCRIPTS ARE NOT SAFE - they trust user input implicitly and are chmodded 700.

mysql> show tables;
+----------------------------+
| Tables_in_dylanstestserver |
+----------------------------+
| notes                      |
| projects                   |
+----------------------------+
2 rows in set (0.00 sec)

mysql> desc notes;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
| date_posted | date         | NO   |     | NULL    |                |
| title       | varchar(255) | NO   |     | NULL    |                |
| text        | longblob     | NO   |     | NULL    |                |
| url         | varchar(255) | NO   |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> desc projects;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| title | varchar(255) | NO   |     | NULL    |                |
| text  | longblob     | NO   |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

17 files changed:
.gitignore [deleted file]
.htaccess
includes/all.js
includes/style.css
includes/tabs.js
index.php
notes/index.php
notes/notes.php
projects/drawcss.html [new file with mode: 0644]
projects/i_like_pandora.html [new file with mode: 0644]
projects/peepshow.html [new file with mode: 0644]
projects/readoo.html [new file with mode: 0644]
projects/repthis.html [new file with mode: 0644]
projects/youtube_backup.html [new file with mode: 0644]
publish.py
publish_projects.py [new file with mode: 0755]
sample.ini [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
deleted file mode 100644 (file)
index 0c3fa09..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-notes/*
-!notes/index.php
-!notes/notes.php
index f58eeb4..b11bc6a 100644 (file)
--- a/.htaccess
+++ b/.htaccess
@@ -1,6 +1,6 @@
 ErrorDocument 404 /404.php
 RewriteEngine on
 RewriteRule ^notes/page/([1-9]+)/?$ notes/index.php?page=$1 [L]
-RewriteRule ^note/([^/\.]+)/?$ notes/index.php?note=$1 [L]
-php_flag display_errors on
-php_value error_reporting 7
+RewriteRule ^notes/([^/\.]+)/?$ notes/index.php?note=$1 [L]
+RewriteRule ^notes/?$ notes/ [L]
+RewriteRule ^([^/\.]+)/?$ index.php?project=$1 [L]
index a910e5c..f29299e 100644 (file)
@@ -248,11 +248,16 @@ b.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
 (function(c){c.effects.slide=function(d){return this.queue(function(){var a=c(this),h=["position","top","left"],f=c.effects.setMode(a,d.options.mode||"show"),b=d.options.direction||"left";c.effects.save(a,h);a.show();c.effects.createWrapper(a).css({overflow:"hidden"});var g=b=="up"||b=="down"?"top":"left";b=b=="up"||b=="left"?"pos":"neg";var e=d.options.distance||(g=="top"?a.outerHeight({margin:true}):a.outerWidth({margin:true}));if(f=="show")a.css(g,b=="pos"?isNaN(e)?"-"+e:-e:e);var i={};i[g]=(f==
 "show"?b=="pos"?"+=":"-=":b=="pos"?"-=":"+=")+e;a.animate(i,{queue:false,duration:d.duration,easing:d.options.easing,complete:function(){f=="hide"&&a.hide();c.effects.restore(a,h);c.effects.removeWrapper(a);d.callback&&d.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
 ;$(document).ready(function() {
-       $(".exhibit").hide();
-       var divs = document.getElementsByTagName('div');
        if(document.location.hash){
                $(document.location.hash + '_').show();
        }
+       $("ul#portfolio li a.tab").each(function(){
+               if (document.location.href.indexOf($(this).attr("href")) == 0) {
+                       $("#" + this.attr("href")).show("slide", 600);
+               }
+               $(this).attr("href", "#" + $(this).attr("href"));
+       });
+       var divs = document.getElementsByTagName('div');
        var i = 0;
        $("ul#portfolio li a.tab").click(function() {
                i++;
@@ -269,5 +274,4 @@ b.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
                        divs[i].className += (" shownDiv");
                }
        });
-
 });
index 265fcca..102c82c 100644 (file)
@@ -61,6 +61,7 @@ li {
        min-height:600px;
        border:1px solid black;
        padding:10px;
+       display:none;
 }
 
 .shownDiv {
@@ -69,7 +70,10 @@ li {
 
 #contact_me {
        margin-top:100px;
+<<<<<<< HEAD
        font-family:sans-serif;
+=======
+>>>>>>> no-javascript
 }
 
 /* reprap */
@@ -90,12 +94,21 @@ li {
 
 #peephow_title_2 {
        font-size:3em;
+<<<<<<< HEAD
 }
 
 #peepshow_entry {
        font:1.4em "lucida console";
 }
 
+=======
+}
+
+#peepshow_entry {
+       font:1.4em "lucida console";
+}
+
+>>>>>>> no-javascript
 /* readoo */
 #readoo_title {
        font:1.6em arial;
@@ -130,6 +143,7 @@ li {
 
 #i_like_pandora_entry {
        font:1.4em "lucida console";
+<<<<<<< HEAD
 }
 
 /* notes */
@@ -154,4 +168,6 @@ li {
 
 pre {
        margin-top:10px;
+=======
+>>>>>>> no-javascript
 }
index 79d76bb..346b76b 100644 (file)
@@ -1,9 +1,14 @@
 $(document).ready(function() {
-       $(".exhibit").hide();
-       var divs = document.getElementsByTagName('div');
        if(document.location.hash){
                $(document.location.hash + '_').show();
        }
+       $("ul#portfolio li a.tab").each(function(){
+               if (document.location.href.indexOf($(this).attr("href")) == 0) {
+                       $("#" + this.attr("href")).show("slide", 600);
+               }
+               $(this).attr("href", "#" + $(this).attr("href"));
+       });
+       var divs = document.getElementsByTagName('div');
        var i = 0;
        $("ul#portfolio li a.tab").click(function() {
                i++;
@@ -20,5 +25,4 @@ $(document).ready(function() {
                        divs[i].className += (" shownDiv");
                }
        });
-
 });
index c0971b1..dbff9a5 100644 (file)
--- a/index.php
+++ b/index.php
 
     <div id="content">
       <div id="exhibit">
-        <div class="exhibit" id="repthis_">
-          <span id="reprap_entry">3D printing is a form of additive
-          manufacturing technology where a three dimensional object
-          is created by successive layers of material. [1]:<a href=
-          "http://repthis.info/">http://en.wikipedia.org/wiki/3D_printing</a><br>
-
-          <br>
-          <a href="http://reprap.org">reprap</a> is a <a href=
-          "http://en.wikipedia.org/wiki/Free_software">free</a>
-          desktop 3D printer capable of printing plastic
-          objects.<br>
-          <br>
-          <a href="http://repthis.info">repthis.info</a> is the
-          account of a friend and I learning to build our own.<br>
-          <br></span>
-        </div>
-
-        <div class="exhibit" id="youtube_backup_">
-          <h1 id="youtube_backup_title"><a href=
-          "https://github.com/nospampleasemam/youtube_backup">youtube_backup</a></h1><span id="youtube_backup_entry">backs
-          up all the <a href="http://youtube.com">youtube</a>
-          videos in a users favorites list.<br>
-          <br>
-          this is my fork of the <a href=
-          "https://github.com/hagnas/youtube_backup">original
-          youtube_backup</a> which adds asynchronous alerts after
-          successful downloads.<br>
-          <br>
-          it's written in <a href=
-          "http://www.python.org/">python</a>.</span>
-        </div>
-
-        <div class="exhibit" id="i_like_pandora_">
-          <h1 id="i_like_pandora_title"><a href=
-          "https://github.com/nospampleasemam/i_like_pandora">i_like_pandora</a></h1><span id="i_like_pandora_entry">searches
-          <a href="http://youtube.com">youtube</a> for what you
-          like on <a href="http://pandora.com">pandora</a>.<br>
-          <br>
-          then it downloads the first video.<br>
-          <br>
-          it's working, but i'm still making it better.<br>
-          <br>
-          <br>
-          the code is free (as in freedom), <a href=
-          "http://github.com/nospampleasemam/i_like_pandora">here</a>.<br>
-          </span>
-        </div>
-
-        <div class="exhibit" id="peepshow_">
-          <h3 id="peepshow_title_1"><a href=
-          "foxy-addons/peepshow/peepshow.xpi">foxy-addons/</a></h3>
-
-          <h1 id="peepshow_title_2"><a href=
-          "foxy-addons/peepshow/peepshow.xpi">peepshow</a></h1><span id="peepshow_entry">a
-          <a href=
-          "http://www.mozilla.com/en-US/products/download.html">firefox</a>
-          addon, to load linked images inline (like on <a href=
-          "http://reddit.com/r/pics">reddit</a>).<br>
-          <br>
-          here's the <a href=
-          "http://github.com/nospampleasemam/peepshow/">repo</a>
-          for the source code.</span>
-        </div>
-
-        <div class="exhibit" id="drawcss_">
-          <h1 id="drawcss_title"><a href=
-          "drawcss">drawcss</a></h1><span id=
-          "drawcss_entry">writing markup for website wireframes
-          always seemed silly.<br>
-          <br>
-          this is a tool to draw them (it's not done).<br>
-          <br>
-          <a href="#show" id="showdivs" name="showdivs">check
-          out</a> the invisible divs this page is built on.<br>
-          <br>
-          then get <a href=
-          "http://github.com/nospampleasemam/drawcss">the
-          code</a>.</span>
-        </div>
-
-        <div class="exhibit" id="readoo_">
-          <h1 id="readoo_title"><a href=
-          "http://github.com/nospampleasemam/readoo">readoo</a></h1><span id="readoo_entry">helps
-          you find search keywords to target.<br>
-          <br>
-          it reads your IIS logs, and finds successful keywords
-          worth focusing on.<br>
-          <br>
-          it's not done yet! here's the <a href=
-          "http://github.com/nospampleasemam/readoo">source
-          code</a>.</span>
-        </div>
-      </div>
+           <?php
+                 $config = parse_ini_file('/etc/dylanstestserver.ini');
+          mysql_connect($config['domain'], $config['user'], $config['password']) or die(mysql_error());
+          mysql_select_db($config['database']) or die(mysql_error());
+                 if (isset($_GET['project'])) {
+                   $page_type = 'project';
+                       $project = mysql_real_escape_string($_GET['project']);
+                   $sql = "SELECT text FROM projects WHERE title='$project'";
+                 } else {
+                   $sql = "SELECT text FROM projects";
+                 }
+          $result = mysql_query($sql) or die (mysql_error());
+          while($project = mysql_fetch_array($result)) {
+                       $text = $project['text'];
+                       if (isset($page_type)) {
+                         $text = str_replace("<div class=\"exhibit\"", "<div class=\"exhibit\" style=\"display:block;\"", $text);
+                       }
+                       echo $text;
+          }
+           ?>
+         </div>
 
       <ul id="portfolio" style="text-align:right">
         <li>
           <h3>my projects:</h3>
         </li>
 
-        <li><a class="tab" href="#repthis">repthis.info</a></li>
+        <li><a class="tab" href="repthis">repthis.info</a></li>
 
         <li><a class="tab" href=
-        "#youtube_backup">youtube_backup</a></li>
+        "youtube_backup">youtube_backup</a></li>
 
         <li><a class="tab" href=
-        "#i_like_pandora">i_like_pandora</a></li>
+        "i_like_pandora">i_like_pandora</a></li>
 
         <li><a class="tab" href=
-        "#peepshow">foxy-addons/peepshow</a></li>
+        "peepshow">foxy-addons/peepshow</a></li>
 
-        <li><a class="tab" href="#drawcss">drawcss</a></li>
+        <li><a class="tab" href="drawcss">drawcss</a></li>
 
-        <li><a class="tab" href="#readoo">readoo</a></li>
+        <li><a class="tab" href="readoo">readoo</a></li>
 
         <li>
           <h3>things i've done for others:</h3>
         </li>
 
         <li><a href=
-        "notes">here</a></li>
+        "/dylanstestserver/notes">here</a></li>
 
         <li>
           <h1 id="contact_me"><a href=
index 6ad9ceb..31e3f1b 100644 (file)
@@ -8,8 +8,8 @@
   <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
 
   <title>dylanstestserver</title>
-  <link href="includes/style.css" rel="stylesheet" type="text/css">
-  <link rel="icon" href="favicon.ico" type="image/png">
+  <link href="/dylanstestserver/includes/style.css" rel="stylesheet" type="text/css">
+  <link rel="icon" href="/dylanstestserver/favicon.ico" type="image/png">
 </head>
 
 <body>
@@ -17,7 +17,7 @@
     <div id="banner">
       <a href=
       "http://dylanstestserver.com/">
-      <img src="images/dylanstestserver.png" alt="dylanstestserver"
+      <img src="/dylanstestserver/images/dylanstestserver.png" alt="dylanstestserver"
       border="0"></a>
     </div>
 
index 26148a4..e71ae69 100644 (file)
@@ -1,6 +1,7 @@
 <?php
-  mysql_connect('localhost', 'dylan', 'password') or die(mysql_error());
-  mysql_select_db('dylanstestserver') or die(mysql_error());
+  $config = parse_ini_file('/etc/dylanstestserver.ini');
+  mysql_connect($config['domain'], $config['user'], $config['password']) or die(mysql_error());
+  mysql_select_db($config['database']) or die(mysql_error());
   $sql = "SELECT COUNT(*) FROM notes";
   $result = mysql_query($sql);
   $result = mysql_fetch_row($result);
@@ -46,7 +47,7 @@
          $month_posted = $date_posted[1];
          $day_posted = $date_posted[2];
          $url = $note['url'];
-      echo "<h2><span style=\"color:grey;\">$year_posted/$month_posted/$day_posted/</span><a href=\"note/$url\">$title</a></h2>";
+      echo "<h2><span style=\"color:grey;\">$year_posted/$month_posted/$day_posted/</span><a href=\"/dylanstestserver/notes/$url\">$title</a></h2>";
          echo $note['text'];
          echo "</div>";
     }
          if(!$page == 2 && $total_number_of_pages == 2)
       echo "<a href=\"{$_SERVER['PHP_SELF']}/page/1\">first</a> / ";
       $previous_page = $page - 1;
-      echo "<a href=\"notes/page/$previous_page\">prev</a>";
+      echo "<a href=\"/dylanstestserver/notes/page/$previous_page\">prev</a>";
     }
     if($page < $total_number_of_pages) {
       $forward_page = $page + 1;
-      echo "<a href=\"notes/page/$forward_page\">next</a>";
+      echo "<a href=\"/dylanstestserver/notes/page/$forward_page\">next</a>";
     }
     if($page != $total_number_of_pages && (!$page == 1 && $total_number_of_pages == 2)){
-      echo " / <a href=\"notes/page/$total_number_of_pages\">last</a>";
+      echo " / <a href=\"/dylanstestserver/notes/page/$total_number_of_pages\">last</a>";
     }
     echo "</h2>";
   }
diff --git a/projects/drawcss.html b/projects/drawcss.html
new file mode 100644 (file)
index 0000000..e5f8bdd
--- /dev/null
@@ -0,0 +1,17 @@
+        <div class="exhibit" id="drawcss_">
+          <h1 id="drawcss_title"><a href=
+          "drawcss">drawcss</a></h1><span id=
+          "drawcss_entry">writing markup for website wireframes
+          always seemed silly.<br>
+
+          <br>
+          this is a tool to draw them (it's not done).<br>
+          <br>
+          <a href="#show" id="showdivs" name="showdivs">check
+          out</a> the invisible elements this page is built on.<br>
+          <br>
+          then get <a href=
+          "http://github.com/nospampleasemam/drawcss">the
+          code</a>.</span>
+
+        </div>
diff --git a/projects/i_like_pandora.html b/projects/i_like_pandora.html
new file mode 100644 (file)
index 0000000..0a615cc
--- /dev/null
@@ -0,0 +1,17 @@
+        <div class="exhibit" id="i_like_pandora_">
+          <h1 id="i_like_pandora_title"><a href=
+          "https://github.com/nospampleasemam/i_like_pandora">i_like_pandora</a></h1><span id="i_like_pandora_entry">searches
+          <a href="http://youtube.com">youtube</a> for what you
+          like on <a href="http://pandora.com">pandora</a>.<br>
+
+          <br>
+          then it downloads the first video.<br>
+          <br>
+          it's working, but i'm still making it better.<br>
+          <br>
+          <br>
+          the code is free (as in freedom), <a href=
+          "http://github.com/nospampleasemam/i_like_pandora">here</a>.<br>
+
+          </span>
+        </div>
diff --git a/projects/peepshow.html b/projects/peepshow.html
new file mode 100644 (file)
index 0000000..08156c5
--- /dev/null
@@ -0,0 +1,16 @@
+        <div class="exhibit" id="peepshow_">
+          <h3 id="peepshow_title_1"><a href=
+          "foxy-addons/peepshow/peepshow.xpi">foxy-addons/</a></h3>
+
+          <h1 id="peepshow_title_2"><a href=
+          "foxy-addons/peepshow/peepshow.xpi">peepshow</a></h1><span id="peepshow_entry">a
+          <a href=
+          "http://www.mozilla.com/en-US/products/download.html">firefox</a>
+          addon, to load linked images inline (like on <a href=
+          "http://reddit.com/r/pics">reddit</a>).<br>
+
+          <br>
+          here's the <a href=
+          "http://github.com/nospampleasemam/peepshow/">repo</a>
+          for the source code.</span>
+        </div>
diff --git a/projects/readoo.html b/projects/readoo.html
new file mode 100644 (file)
index 0000000..1c1919c
--- /dev/null
@@ -0,0 +1,13 @@
+        <div class="exhibit" id="readoo_">
+          <h1 id="readoo_title"><a href=
+          "http://github.com/nospampleasemam/readoo">readoo</a></h1><span id="readoo_entry">helps
+          you find search keywords to target.<br>
+          <br>
+          it reads your IIS logs, and finds successful keywords
+          worth focusing on.<br>
+          <br>
+          it's not done yet! here's the <a href=
+          "http://github.com/nospampleasemam/readoo">source
+          code</a>.</span>
+
+        </div>
diff --git a/projects/repthis.html b/projects/repthis.html
new file mode 100644 (file)
index 0000000..c395d49
--- /dev/null
@@ -0,0 +1,17 @@
+               <div class="exhibit" id="repthis_">
+          <span id="reprap_entry">3D printing is a form of additive
+          manufacturing technology where a three dimensional object
+          is created by successive layers of material. [1]:<a href=
+          "http://repthis.info/">http://en.wikipedia.org/wiki/3D_printing</a><br>
+
+          <br>
+          <a href="http://reprap.org">reprap</a> is a <a href=
+          "http://en.wikipedia.org/wiki/Free_software">free</a>
+
+          desktop 3D printer capable of printing plastic
+          objects.<br>
+          <br>
+          <a href="http://repthis.info">repthis.info</a> is the
+          account of a friend and I learning to build our own.<br>
+          <br></span>
+        </div>
diff --git a/projects/youtube_backup.html b/projects/youtube_backup.html
new file mode 100644 (file)
index 0000000..8f7767e
--- /dev/null
@@ -0,0 +1,16 @@
+        <div class="exhibit" id="youtube_backup_">
+
+          <h1 id="youtube_backup_title"><a href=
+          "https://github.com/nospampleasemam/youtube_backup">youtube_backup</a></h1><span id="youtube_backup_entry">backs
+          up all the <a href="http://youtube.com">youtube</a>
+          videos in a users favorites list.<br>
+          <br>
+          this is my fork of the <a href=
+          "https://github.com/hagnas/youtube_backup">original
+          youtube_backup</a> which adds asynchronous alerts after
+          successful downloads.<br>
+          <br>
+
+          it's written in <a href=
+          "http://www.python.org/">python</a>.</span>
+        </div>
index b0847ff..288a395 100755 (executable)
@@ -2,12 +2,18 @@
 
 import os
 import time
-import MySQLdb
+import MySQLdb as db
+import ConfigParser
 
-db = MySQLdb.connect('localhost','dylan','password', 'dylanstestserver')
-cursor = db.cursor()
+config = ConfigParser.RawConfigParser()
+config.read('/etc/dylanstestserver.ini')
+domain = config.get('database', 'domain')
+user = config.get('database', 'user')
+password = config.get('database', 'password')
+database = config.get('database', 'database')
+cursor = db.connect(domain, user, password, database).cursor()
 
-notes = os.listdir('notes')
+notes = os.listdir('/home/dylan/docs/notes')
 
 sql = "SELECT title FROM notes"
 cursor.execute(sql)
@@ -27,7 +33,7 @@ for note in notes:
     date_posted = "%s-%s-%s" % (str(mtime.tm_year)[2:], mtime.tm_mon, mtime.tm_mday)
     sql = "INSERT INTO notes (date_posted, url, title, text)\
              VALUES(\"%s\", \"%s\", \"%s\", \"%s\")"\
-             % (date_posted, url, title, MySQLdb.escape_string(text))
+             % (date_posted, url, title, db.escape_string(text))
 
     #print sql
     cursor.execute(sql)
diff --git a/publish_projects.py b/publish_projects.py
new file mode 100755 (executable)
index 0000000..7e5535c
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+
+import os
+import time
+import MySQLdb as db
+import ConfigParser
+
+config = ConfigParser.RawConfigParser()
+config.read('/etc/dylanstestserver.ini')
+domain = config.get('database', 'domain')
+user = config.get('database', 'user')
+password = config.get('database', 'password').replace('"', '')
+database = config.get('database', 'database')
+print domain, user, password, database
+cursor = db.connect(domain, user, password, database).cursor()
+
+notes = os.listdir('projects')
+
+sql = "SELECT title FROM projects"
+cursor.execute(sql)
+results = cursor.fetchall()
+existing_titles = []
+for row in results:
+    existing_titles.append(row[0])
+
+for note in notes:
+    title = note[:note.index('.')]
+    f = open(os.path.join('projects', note))
+    if title in existing_titles: continue
+    text = f.read()
+    cursor.execute("INSERT INTO projects (title, text)\
+                      VALUES (%s, %s)", (title, text))
diff --git a/sample.ini b/sample.ini
new file mode 100644 (file)
index 0000000..67e4350
--- /dev/null
@@ -0,0 +1,7 @@
+# this file will be looked for at /etc/dylanstestserver.ini
+
+[database]
+domain = localhost
+user = dylanstestuser
+password = "dylanstestpassword"
+database = dylanstestserver