Greymatter: Logware
home

Greymatter
Weblog/Journal Software . Version 1.6.1 . Software Developers Guide
Copyright (c) 2000-2006 The Greymatter Team . All Rights Reserved

Purpose

These are documents outside of the code to help create a 'big picture'. Note that code comments should superscede any documentation here. This document contains file layout to document what the files hold (information-wise). Api for the way to get this information should appear in the Perl Module. For example, look at the libs/Gm_Storage.pm file and you will see each public method with documentation on what arguments it takes, what it returns, how to use it, and what (if anything) it deprecates.

Developer rules/guildelines/style guide

Note that I don't really care about style and format of the code, rather, I care that there are comment, I care that the api is used and not worked around.

  • Strict. Always, always, always 'use Strict' in any new module. Perl strict will catch countless careless mistakes (we've all made them) and no brainers that its just harder to develop without it.
  • Warn. Use warns. Similar reasons as above, but it encourages better code writting in that it reminds you to dot your i's and cross your t's.
  • Constants. Try to use constants wherever you can, specifically, use values in Gm_Constants. Several defects have been tracked down due to mistypings of constant values/flags (for exapmple ' open' vs 'open' and 'templete' vs 'template').
  • Handlers. When appropriatte take a 'handler' as a subroutine argument. A handler is simply a reference to a subroutine. This handler can then be determined by the calling subroutine (for example, if a user page (such as comments.cgi) calls a function, any errors should show the User Template, not the Admin look and feel).
  • Newlines. Unless printing directly to the screen, avoid newlines. Subroutines that save data should handle newlines if necescary. For example, Gm_Store::addLogMessage adds a newline because its working on a flat file. But if it was stored a database, it wouldn't make sense to have the newline at the end of the control panel message. So when addLogMessage is called, it takes data that is 'peristant storage neutral'. Let the Storage subroutines worry about newlines and flatfile storge. When we switch to a database, then we won't have to hunt through the code getting rid of newline characters.
  • Printing. Return a string rather than printing, this is just more elegant. Leave prints to the calling subroutine if possible.
  • Encapsulation. Private subroutines should start with the '_' character. By private I mean it will never be called outside of this package.
  • Arguments. If you have more than 1 or 2 parameters, especially if they are not required, use named parameters such as in createRadioButton. By putting stuff in a hash we gain the flexibility to add more optional parameters without having to pass in '' placeholders or modify existing code.
  • Quotes. Use ' and " where appropriate. If you don't have any variables or newlines then use ', its quicker and cleaner.
  • Strings. Don't put all text on one huge long line. It messes with some programs that don't do line wraps well (some cvs, some text editors, etc.). Its also makes reading through the code difficult since people have to scroll down AND over.
  • Quotes. Use ' and " where appropriate. If you don't have any variables or newlines then use ', its quicker and cleaner.

Templates (gm-templates.cgi)

    The template file is now order independant, meaning that there is no special order to the templates stored within. This is because the format of the template is now:
    template_name=template_value
    One template per line, each line begining with the name of the template.
  • Naming. Template names should always end with the word 'template', as this will make it obvious that its a template and easy to pull out of a hash (form submission for example will contain templates and other values).
  • Todo: List template variables and what they are used for...

Configs (gm-configs.cgi)

    The config file is now order independant, meaning that there is no special order to the configuration variables stored within. This is because the format of the config is now:
    config_name=config_value
    One config per line, each line begining with the name of the config.
  • Naming. Config names should always start with the word 'gm', as this will make it obvious that its a GreyMatter config and easy to pull out of a hash (form submission for example will contain configs and other values).
  • Todo: List config variables and what they are used for...

Counter (gm-counter.cgi)

    The counter file is now order independant, meaning that there is no special order to the counter values stored within. This is because the format of the counter is now:
    counter_name=counter_value
    One counter per line, each line begining with the name of the counter variable.
  • Naming. Counter variables don't follow as precise a pattern as configs and templates. Rather the counter name attempts to be descriptive, while not providing redundant information.
  • The counter variables and their meaning:
    entrytotal = total number of entries posted
    archivetotal = total number of entries not on front page
    stayattopentry = entry# designated as "Stay At Top", marked 0 if there's no such thing
    karmapos = total positive karma votes
    karmaneg = total negative karma votes
    commenttotal = total comments posted
    opentotal = total number of open entries
    closedtotal = total number of closed entries

Entrylist (gm-entrylist.cgi)

    The entrylist file is now order independant, meaning that there is no special order to the entrylist lines within. The order of the items isn't needed for any of the current functionality provided by GreyMatter and here is an example of sorting by entry number:
    my $gmentrylist = Gm_Storage::getEntrylist( errHandler=>\&Gm_Web::displayAdminErrorExit );

    foreach my $entry ( sort { $gmentrylist->{$b}{'id'} <=> $gmentrylist->{$a}{'id'} } keys( %$gmentrylist ) ) {
    ...
  • One counter per line, each line containing the following values seperated by the '|' character:
    1. id = the numerical id of the entry (key of returned hash)(usually order in which entered, never 0)
    2. author = entry author's name (must be alphanumeric)
    3. subject = entry subject (must be alphanumeric)
    4. created = CREATE Date of entry in the format of mm/dd/yy (does include leading zeros)
    5. createt = CREATE Time of entry in the form of hh:mm [AM/PM] (does include leading zeros)
    6. status = entry status: open/closed, either O or C
    7. extended = is this an extended entry, either Y or N
    8. music = current music of entry (well author really)
    9. mood = current mood of entry (well author really)
    10. emoticons = are emoticons enabled, yes or no
  • Naming. Counter variables don't follow as precise a pattern as configs and templates. Rather the counter name attempts to be descriptive, while not providing redundant information.

Authors (gm-authors.cgi)

    The authors file is now order independant, meaning that there is no special order to the author information within. The order of the items isn't needed for any of the current functionality provided by GreyMatter and here is an example of sorting by author name alphabetically:
    my $gmauthors = Gm_Storage::getAuthors( errHandler=>\&Gm_Web::displayAdminErrorExit );

    foreach my $author ( sort { $gmauthors->{$a}{'author'} cmp $gmauthors->{$b}{'author'} } keys( %$gmauthors ) ) {
    ...
  • One author per line, each line containing the following values seperated by the '|' character:
    1. author = author's name (key of returned hash (case sensitive))
    2. password = author's password (crypted)
    3. email = author's email
    4. homepage = author's homepage
    5. created = CREATE Date of the author
    6. posttotal = total number of postings by this author
    7. postnew = can this author make new posts Y or N
    8. editentries = can this author edit entries Y or N
    9. editconfigs = can this author edit configs Y or N
    10. edittemplates = can this author edit templates Y or N
    11. editauthors = can this author edit other authors Y or N
    12. rebuild = can this author rebuild files Y or N
    13. viewcplog = can this author view the control panel Y or N
    14. bookmarklets = can this author use bookmarklets Y or N
    15. upload = can this author upload files Y or N
    16. viewadmin = can this author access the admin scene (gm.cgi) Y or N
  • Naming. Authors don't follow as precise a pattern as configs and templates. Rather the author variable name attempts to be descriptive, while not providing redundant information.

Entry (00000001.cgi and up)

    The entry file remains unchanged. Note that the entry information is contained withen the cgi file and it is generated to the html files (by default, the file type can be different than cgi). This information was culled from the old greymatterforums site, originally contributed by Flipped Cracker (Robert). The layout of the file is much more complex then the other files. The first 4 or 5 lines give the majority of the information about a particular entry with commments appearing after the 4th line:
    1. line, information about the post/entry
    2. line, Karma-related information. The IP addresses and the votes associated with those IP addresses are collated here.
    3. line, the "main text" of each entry.
    4. line, the "extended text" of each entry. If none, a blank line is left.
    5. line (and more if necessary), comments. One comment per line.
  • The entry information is stored in the first line, with the following information seperate by the '|' character:
    1. author = author's name (key of returned hash (case sensitive))
    2. id = numeric, never 0
    3. author = alphanumeric
    4. subject = title of post alphanumeric (we hope)
    5. weekday = numeric (0-6, 0=Sunday, 1=Monday, etc.)
    6. month = month of post numeric (1-12, no leading zeroes)
    7. day = day of post numeric (1-31, no leading zeroes)
    8. year = year of post numeric (format: yyyy)
    9. hour = hour of post numeric (1-12, no leading zeroes)
    10. minute = minute of post numeric (1-12, no leading zeroes)
    11. second = second of post numeric (1-12, no leading zeroes)
    12. ampm = either AM or PM
    13. karmapos = positive karma numeric
    14. karmaneg = negative karma numeric
    15. commenttotal = number of comments numeric; 0 if no comments
    16. karma = votes allowed yes/no
    17. comments = comments allowed yes/no
    18. status = entry open or closed open/closed
    19. music = current music of entry (well author really)
    20. mood = current mood of entry (well author really)
    21. emoticons = are emoticons enabled, yes or no
  • The karma votes is stored in the second line, with the following information seperate by the '|' character (note that each entry has the default line '0.0.0.0|I'):
    1. ip = the ip that cast the karma vote
    2. vote = the karma vote, either a P for positive or N for negative
  • The main text of the entry is stored in the third line, with single line breaks replaced with '|*|' and double line breaks with '|*||*|'. All the text is presented as one line.
  • The extended text of the entry is stored in the fourth line, following the same text conventions of line 3.
  • The comments are stored in the fifth line and beyond, with the following information seperate by the '|' character:
    1. name = commenter's name alphanumeric
    2. ip = in the form of xxx.xxx.xxx.xxx
    3. email = in the form of user@email.com. If not provided, left blank.
    4. homepage = commenter's webpage in the form of http://www.site.com. If not provided, left blank.
    5. weekday = of comment numeric (0-6, 0=Sunday, 1=Monday, etc.)
    6. month = of comment numeric (1-12, no leading zeroes)
    7. day = of comment numeric (1-31, no leading zeroes)
    8. year = of comment numeric (format: yyyy)
    9. hour = of comment numeric (1-12, no leading zeroes)
    10. minute = of comment numeric (1-12, no leading zeroes)
    11. second = of comment numeric (1-12, no leading zeroes)
    12. ampm = either AM or PM
    13. comment = text presented all on one line, with the same text replacement conventions as in the main entry text. (See Line 3.)

Banlist (gm-banlist.cgi)

    The banlist is simply a list of Internet Protocal addresses that are prevented from using the functionality of th egreymatter software, such as posting comments to accessing the admin page. The banlist file is now order independant, meaning that there is no special order to the banlist information within. The order of the items isn't needed for any of the current functionality provided by GreyMatter.
  • One banned ip per line, each line containing the following values seperated by the '|' character:
    1. ip = ip address of machine to ban (key of returned hash)
    2. host = the hostname of the banned ip (currently not used)
    3. label = an optional label to describe the banned ip
  • Naming. Authors don't follow as precise a pattern as configs and templates. Rather the author variable name attempts to be descriptive, while not providing redundant information.
  • Spam. We are at the mercy of the webserver to tell us the i.p. of the request (through the REMOTE_HOST environment variable. However, the webserver can be 'fooled' and given a bad i.p. (google: ip spoofing) also those users that use dialup or non-premium dsl/cable usually do not have a static i.p. (companies love to charge for this convienence). This means that banning by ip is usually ineffective to prevent spammers, but can usually be usefull against nuisance users (most work places will be using static i.p.s) and if you notice a patter you could ban a range of i.p.s.

Log (gm-cplist.cgi)

    The cplog file is a listing of log entries entered by GreyMatter to keep the user informed of certain events. This file is order dependant with the first line being the oldest and the last being the most recent. Note that Gm_Storage functions treat the cplog information as an array, mostly to preserve order (also, because there isn't really a logical key besides an arbitrary id number or the date+time the line was logged and this would be a pain to sort (probably).
  • One log 'entry' per line, with the date and time of the log entry usually added, but not always. Resetting the log is simply a matter of clearing out the file.
  • Naming. Authors don't follow as precise a pattern as configs and templates. Rather the author variable name attempts to be descriptive, while not providing redundant information.
  • Spam. We are at the mercy of the webserver to tell us the i.p. of the request (through the REMOTE_HOST environment variable. However, the webserver can be 'fooled' and given a bad i.p. (google: ip spoofing) also those users that use dialup or non-premium dsl/cable usually do not have a static i.p. (companies love to charge for this convienence). This means that banning by ip is usually ineffective to prevent spammers, but can usually be usefull against nuisance users (most work places will be using static i.p.s) and if you notice a patter you could ban a range of i.p.s.