Anyone have experience programming a blog site?

Discussion in 'OT Technology' started by jinushaun, Aug 22, 2003.

  1. jinushaun

    jinushaun New Member

    Joined:
    Feb 6, 2002
    Messages:
    60,739
    Likes Received:
    0
    Location:
    Capitol Hill, Seattle, WA, USA
    I was wondering if anyone would like to share their experiences designing and programming a blog site. I'm mostly looking for design insights. I want to make my blog programme scalable.

    I'm looking to make a blog programme complete with user accounts, calendars, photo album, templates, planner, uploading, and importing and exporting capabilities. I want to make it completely dynamic (read: no hard code) and scalable. This is just for shits and giggles.
     
  2. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    yeah mines a blog site. (http://www.cyberbullets.net)

    i dont have a caldenar, templates, photo album or planner (dont want them as of yet)

    i wrote all of mine from scratch and is fairly easy. did in im php with mysql as my db.

    it was very easy... hardest part was that my server was running mysql 3.x so i changed my account to the test server for mysql 4.0x. i was trying to run UNIONs and couldnt figure out wtf was wrong until i realized it.

    but yeah, any questions or want some code ill help out.
     
  3. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Yep, I'd also use PHP/mySQL, I recently wrote a guestbook for my personal site and an inventory-type site for work, and they're both done that way (both somewhat similar to parts of a blog too).

    The templating part is fairly easy using include() and such things.
     
  4. jinushaun

    jinushaun New Member

    Joined:
    Feb 6, 2002
    Messages:
    60,739
    Likes Received:
    0
    Location:
    Capitol Hill, Seattle, WA, USA
    Well I'll be using PHP and MySQL cuz that's what my school's server provides.

    By template, I mean generic files containing pseudo tags whereby the user can arrange content however they want. My code will replace the pseudo tags by the content specified by those tags.

    So a single page may be a template, which may contain other templates. For instance, a page will contain a list of journal entries and each entry will have its own template. Not only can the user specify where the entry listing will look, but also how each entry will look.
     
  5. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    yeah i never did that. i never thought about letting others download my code.
     
  6. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Ah, yes, that's doable. I remember doing it in Perl long ago (nothing that fancy, but the same idea), so I'm sure it's much easier in PHP (most things are). I would use the file() function to get the content of the template file, then use preg_replace() (I think, could be ereg_replace(), I forget the difference) to replace the pseudo-tags with your content.

    Edit: Also, galleries are easy to do, look at the "Handling File Uploads" section on php.net for a start.
     
  7. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Woo-hoo! Templating! Lets see... I've built a basic template system in PHP. Then ported it to ASP so I could pick up the development pace at work. Then I ported the ASP code back to PHP since it was improved upon. Then it was ported over to Java.

    I'm not 100% sure I'm ready to post it. But its able to handle embedding templates within templates and my favorite web coding problem - the list (where there's a header, footer, and then an unknown number of rows). It handles form and URL data effortlessly as well as data from a query. It uses str_replace() to handle swapping data into the template and preg_replace() to handle voiding out any unfilled template variables (which is set as an option).

    As for the variable delimiters, I found

    Code:
    <!--$var_name$-->
    
    Works really well in PHP. If the variable isn't replaced, no problem. The
    Code:
    <!--  -->
    will comment the variable out in the HTML (although they will appear in text form fields, which is why I have an option to void these out).

    If you're going to do this in Java, then select something other then the $ (I ended up using % - which works, but sucked that I had to spend a few minutes updating all my templates).
     
  8. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    preg_replace() is one of the ones I used. Its uses Perl regular expression rules. I forgot what the difference is between preg_replace() and ereg_replace() other then I believe ereg_replace uses a slightly different replace rule set (I'm too lazy to look it up right now).

    You will want to use preg_replace() in moderation and use str_replace() whenever you can. All the preg_XXXX() functions take a performance hit, while str_replace() is very fast since it doesn't have to do the heavy regular expression processing.
     
  9. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    :cool: I don't think I found str_replace(). I'll keep it in mind for the future :wiggle:
     
  10. jinushaun

    jinushaun New Member

    Joined:
    Feb 6, 2002
    Messages:
    60,739
    Likes Received:
    0
    Location:
    Capitol Hill, Seattle, WA, USA
    I'm coding it this way in case it actually becomes marketable. Then I'll sell it and make millions! Muhahahaha! :x:

    Oh yeah, I know how templates work. I've done it before. However, I won't be using straight PHP variables because that's a security risk. I mean, what if the user enters server variables into their template?

    I was talking more along the lines of DB design and logical/schematic interpretations of a blog programme.

    For instance, I'd like to keep the hard code to a minimum, so I was wondering the best way to store and organise settings and registry-type data. Most likely, the user will be able to admin it from a web interface. For global variables and other stuff pertinent to the code, I normally have a global file called settings.inc.php or something which all files include.

    Also, I was wondering how most of you deal with functions. Let's say you wanted to post an entry, would you go about it this way:
    Code:
    /journal.php?action=post&data...
    
    or 
    
    /post.php?data=...
    I think the later would be more scalable and would result in many smaller files instead of one big file.

    Also, my friend suggested that I make a table for each user's journal data. I personally think this is a bit much, but would yield faster query times if each user had their own table.

    I've also have experience in programming file uploads.
     
  11. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    I would probably do it hte post.php method, although instead of using GET variables (?data=) I would use POST variables (just a personal preference maybe). I would go this route since I would want to have a posting page that is separate from my reading page, which is separate from my editing page, etc... Doing them each in a separate file keeps the pages separate and logically organized (for me at least).
     
  12. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    werd... i do that for my blog. its easier to organize it that way. i got a addentry (adds journal entry and comments) and modify (mod/delete comments journals). i try to keep my code theme related...
     
  13. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    GET vs POST and one way to look at it:

    Use POST if you want to hide the data you're sending back to the server. You're not worried about bookmarking.

    Use GET if you wish to make the variables available up on the URL (nothing new here). Use GET if you think it might be helpful if the URL could be bookmarked or shared. I find any time I have a search form, I use GET so the URL can be copied and shared in IM or email.
     
  14. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    This is only a serious problem if you're still on PHP3 OR you have REGISTER_GLOBALS turned ON. Otherwise, you have to pass variables around (which ends up being a good thing) and the worst case that I can think of is if someone creates a copy of your form but tweaks the data a little to try to mess you up (and here you can look at the referrer to make sure its coming from your site and no where else). Thats about it.

    No, don't just use PHP variables from within your templates. Thats not overly healthy. I'm not sure if you were thinking thats what I was doing. I take advantage of PHP's ability to handle an array as:

    PHP:
    $myArray['element1'] = 'data1';
    $myArray['element2'] = 'data2';
    And in my templates, I might have something like:

    Code:
    Data element 1 = <!--$element1$-->
    Data element 2 = <!--$element2$-->
    
    So the template variable matches up with an array. Really, it can be any array - even the GET, POST, SERVER, & record set arrays - but YOU control the array you pass in, not the user.

    For utility functions and classes, including the file is perfect. For server settings that only you should have accesss to, then an include file is fine. But if you even THINK the user should have access to some of these settings, then I'd suggest shoving them in the DB. Just keep in mind to design the DB so you can go back later and easily allow users to customize their settings. This is a rather general answer and may not fit you problem/solution...

    What do you plan to scale it to? Multiple servers? I'm a fan of shoving a lot of code that relates to a process in just one file. I personally find it easier to maintain, but if thats not your style, then thats cool too. PHP is handled as a script and I'm finding the performance doesn't drop when you're working with a 200k PHP file or a 2k PHP file. But in the end, go with whichever you find is the easiest, PHP can keep up with either way...


    Doh! Here's why:

    Let's take an example of you having 5 friends using your journal app.

    After several months of use, there's a fair amount of data. Each user has their own tables. You realize you want to add additional functionality to your app, but it requires modifing the existing tables (maybe you added a column, or changed a format, or even completely redesigned the table). Any changes you make, you have to replicate to the other 5 tables. No big deal? Well, what if you now have 20, 50, or 1000 users?

    One of the rules of database design is all like data should be grouped together (ideally in its simplest form). So it would make sense to group all your entry data into one table, all your user info into another table, etc. You'll need to toss in some INNER/OUTER JOINS as well as some indexes on the IDs (for performance). This may seem like more coding work, but it means your database is (or at least closer to being) clean which will mean it will be easier to maintain and upgrade down the road (which sounds like what you want and will need).

    That make sense?

    If you're worried about performance, MySQL doesn't have a lot of tricks that it can do, but I'm finding MySQL's HEAP table type ROCKS for super huge row counts (this only works for quering subsets of the data - it won't make a difference if you're quering on the entire data set). I've got a 2.8 million row database which is performing great.

    Database design is crucial. You will want to make third normalization your goal...
     
  15. jinushaun

    jinushaun New Member

    Joined:
    Feb 6, 2002
    Messages:
    60,739
    Likes Received:
    0
    Location:
    Capitol Hill, Seattle, WA, USA
    Astro, good stuff. :cool:
     

Share This Page