INDEX.HTML
\<\%
#WorldGeeks Home Page
require \'cgi\'
require \'worldgeeks/page\'
require \'worldgeeks/login\'
require \'worldgeeks/content_items\'

front = Front.new()
title = \"Worldgeeks\"

frontpage = Page.new(title, \"/worldgeeks/index\", front, \"\")
print frontpage.render
\%\>


CONTENT_ITEMS.RB

#Heather Van Aelst, hvanaels\@cs.oberlin.edu and John West, saalahuddeen\@hotmail.com
#April 2001

#ContentItem - an individual piece of content (story, feature)
#LinkItem - extends ContentItem to display links
#Front - makes the front page
#Cat - extends Front for Category pages


require \'cgi\'
require \'worldgeeks/db\'
require \'worldgeeks/foo\'
require \'worldgeeks/comments\'
require \'worldgeeks/tree\'

#ContentItem - an individual piece of content (story, feature)
class ContentItem
  
  def initialize(content_id, *body)
    \@content_id = content_id
    \@body = body             #optional - whether or not to show the body
    \@cgi = CGI.new(\'html4\')
    \@foo
  end

  attr_reader :content_id, :body, :cgi, :foo

  #As long as content exists, display it
  def render 
    if dbquery
      makeTable
    else 
      cgi.p { cgi.b { \"Sorry, no content found matching that request\" } }
    end #if
  end #render
  
  # query the db for info matching this objects content_id
  # returns true as long as content exists, sets foo
  def dbquery
    b = \"\"
    a = [\"content_type\", \"author\", \"title\", \"summary\", \"url\", \"date_submitted\", \"editor_comments\"]
    if body and body.length > 0
      b = \", body\"
      a << \"body\"
    end #if
    query = \"select content_type, author, title, summary, url, date_submitted, editor_comments\" +
            b + \" from content_items where content_id = \" + content_id

    db = DB.new
    res = db.query(query)
    db.disconnect

    # make instance vars out of results using foo
    if res.num_tuples > 0
      \@foo = Foo.new
      h = Hash.new
      i = 0
      a.each { |key| h[key] = res.getvalue(0, i); i += 1 }
      \@foo.bar(h)
      return true

    else
      return false
    end #if
  end #dbquery

  # the actual html for the content
  def makeTable

    #show body or \"read more\' link
    b = \"\"
    if body and body.length > 0
      b << CGI.unescape(foo.body) + Comment_Box.new(content_id).render + 
	Comments.new(content_id).render
    else
      b << cgi.a (\"/worldgeeks/article?content_id=\" + content_id) { \"read more...\" } << cgi.hr
    end #if

    #display url if exists
    u = \"\"
    if foo.url and foo.url.length > 0
      u = cgi.tr { cgi.td { \"

Link: \" + cgi.a (CGI.unescape(foo.url)) { CGI.unescape(foo.url) } } } end #if #display editor_comments if they exist ed = \"\" if foo.editor_comments and foo.editor_comments.length > 0 ed << cgi.tr { cgi.td { \"

ED: #{CGI.unescape(foo.editor_comments)}

\"} } end #if #main content display cgi.table (\"width\" => \"100%\") { cgi.tr { cgi.td { \"

\" + foo.content_type.capitalize + \": \" + CGI.unescape(foo.title) + \"

\" } } + cgi.tr { cgi.td { \"

Submitted by: \" + CGI.unescape(foo.author) + \" on \" + foo.date_submitted } } + u + cgi.tr { cgi.td { \"

\" + CGI.unescape(foo.summary) + \"

\" } } + ed + cgi.tr { cgi.td { b } } } end #makeTable end #ContentItem #LinkItem - extends ContentItem to display links class LinkItem < ContentItem #overwrites ContentItem\'s makeTable #displays the content slightly differently def makeTable b = \"\" if body and body.length > 0 b << foo.body #+ Comments.new(content_id) else b << cgi.a (\"/worldgeeks/article?content_id=\" + content_id) { \"Read More...\" } end #if u = \"\" if foo.url and foo.url.length > 0 u = cgi.tr { cgi.td { cgi.a (foo.url) { foo.url } } } end #if cgi.table { cgi.tr { cgi.td { cgi.h4 { cgi.a (foo.url) { foo.title } } } } + cgi.tr { cgi.td { cgi.p { foo.summary } } } } end #makeTable end #LinkItem #Front - makes the front page class Front def initialize() \@cgi = CGI.new(\'html4\') \@res end #initialize attr_reader :res, :cgi # for each piece of content returned, render it def render if dbquery summaries = \"\" 0.upto(res.num_tuples - 1) { |i| summaries << ContentItem.new(res.getvalue(i, 0)).render } return summaries else return \"No Stories or Features in this category.\" end #if end#render # get content_items (10 most recently submitted and approved) def dbquery query = \"select content_id from content_items c where current_status ~* \'approved\' and content_type !~* \'link\' and content_type !~* \'comment\' order by date_submitted desc limit 10\" db = DB.new \@res = db.query(query) if res.num_tuples > 0 return true else return false end #if end #dbquery end #Front #Cat - extends Front for Category pages class Cat < Front #classification_id corresoponds to the classification this page is for def initialize(classification_id) \@classification_id = classification_id.to_s super() end #initialize #grab relevant stories and features from db def dbquery query = \"select c.content_id from content_items c, content_classification_map m where c.current_status = \'approved\' and m.content_id = c.content_id and c.content_type <> \'link\' and m.classification_id = #{\@classification_id} order by date_submitted desc limit 10\" db = DB.new \@res = db.query(query) if res.num_tuples > 0 return true else return false end #if end #dbquery #display bboards, links, and stories and features def render bb + links + cgi.p { cgi.h2 {\"Stories and Features\"} } + super end #render #find bboard matching this categoy and display def bb query = \"select bboards.bboard_id, bboard from bboards, bboard_classification_map where bboards.bboard_id = bboard_classification_map.bboard_id and classification_id = #{\@classification_id}\" db = DB.new \@res = db.query(query) if res.num_tuples > 0 return cgi.p { cgi.h2 {\"BBoard\" } } + cgi.p { cgi.a (\"/worldgeeks/bboard?bboard_id=#{res.getvalue(0,0)}\") { \"#{res.getvalue(0,1)}\" } } else return \"\" end #if end #bb #find links matching this category and render def links l = \"\" query = \"select c.content_id from content_items c, content_classification_map m where c.current_status = \'approved\' and m.content_id = c.content_id and c.content_type <> \'link\' and m.classification_id = #{\@classification_id} order by date_submitted desc limit 10\" db = DB.new \@res = db.query(query) if res.num_tuples > 0 0.upto(res.num_tuples - 1) { |i| l << LinkItem.new(res.getvalue(i, 0)).render else l << \"No Links in this category.\" end #if return cgi.p { cgi.h2 {\"Links\" } } + l end #link end #Cat
"