Flourish Demo Site

Posted by Will Bond on 1/5/09 at 1:31 pm, 14 comments

About

Flourish is a PHP unframework, a general-purpose, object-oriented library focused on security, documentation, ease-of-use and portability.

If you've never worked with Flourish before, getting started building a site may seem a little daunting. Included below is the description and source code for a production site written with Flourish and SQLite.

The northshorewebgeeks.com site provides a simple list of upcoming and past meetups for the North Shore Web Geeks meetup. Rather than hand-editing the HTML and RSS feeds, Flourish was set up to provide a simple CMS to easily update the information.

Source Code

The source code for the demo can be found in the flourish-demo-site repository on Github. Github has a nice little code browser, so you can view the code without downloading or cloning.

Routing

The site is fairly simple, so I set up Apache with mod_rewrite to create some nice, clean URLs:

/                     # -> index.php  : Home/main page
/rss                  # -> index.php  : RSS feed
/manage               # -> manage.php : Lists all meetups
/manage/add           # -> manage.php : Allows adding a meetup
/manage/{date}/edit   # -> manage.php : Allows editing a meetup
/manage/{date}/delete # -> manage.php : Allows deleting a meetup
/log_in               # -> login.php  : Allows a user to log in
/log_out              # -> login.php  : Lets the user log out
/sup/*                # -> sup/*      : Static files including CSS and images

Anything other than those URLs will cause the page at views/404.php to be shown.

Directory Structure

The files on the filesystem are organized in the following structure:

/                     # The three php scripts that handle requests
/inc/                 # The bootstrap script init.php and config file
/inc/classes/         # The ORM classes
/inc/flourish/        # Flourish classes
/storage/db/          # The SQLite database the source .sql file
/storage/session/     # The PHP session files
/sup/css/             # The CSS files
/sup/img/             # The images
/views/               # The HTML templates for the site

Request Handling

As requests are received, they are routed the appropriate PHP page by mod_rewrite, however each of these pages first runs the bootstrapping code in inc/. Here is an example of the execution order:

config.php -> init.php -> manage.php

Live Instance

The site is currently running live on http://demo.flourishlib.com. You can log in with the following information:

  • Login: admin
  • Password: password

Right now the site will allow you to edit anything, however I may need to disabled saving changes if the site is spammed or inappropriate content is added.

Installation

If you wish to run the demo site on your own server, you’ll need to download the source from github and recursively chmod the storage directory to 777. This allows the web server to write to the SQLite database and session directory.

chmod -R 777 /path/to/flourish_demo_site/storage

All files included with the demo site, except for graphics and CSS files, are licensed under the MIT license. Graphics and CSS files are only provided for demo purposes. Please see the license.txt file for more details.


Comments

wbond at 12:56 pm on Jan 14, 2009

For those interested, Einars posted an example rewrite configuration in the forum if you want to use the demo site with lighttpd:

$HTTP["host"] == "flourish" {
    server.document-root = "/srv/www/flourish"
    url.rewrite-once += (
        "^/$"                    => "/index.php?type=html",
        "^/rss/?$"               => "/index.php?type=rss",
        "^/(log_in|log_out)$"    => "/login.php?action=$1",
        "^/manage/add$"          => "/manage.php?action=add",
        "^/manage/(\d{4}-\d{2}-\d{2})/(edit|delete)$"
                                 => "/manage.php?action=$2&date=$1",
        "^/manage/?(?:\?(.*))?$" => "/manage.php?$1",
    )
}

richard at 9:29 am on May 28, 2009

what does your mod rewrite look like?

wbond at 9:43 am on May 28, 2009

@richard

The mod_rewrite is as follows:

RewriteEngine   On

## the real rewrite rules
RewriteRule     ^favicon.ico                                    sup/img/favicon.ico             [L]

RewriteRule     ^$                                              index.php?type=html             [L]
RewriteRule     ^rss$                                           index.php?type=rss              [L]

RewriteRule     ^(log_in|log_out)$                              login.php?action=$1             [L]

RewriteRule     ^manage$                                        manage.php                      [L,QSA]
RewriteRule     ^manage/add$                                    manage.php?action=add           [L]
RewriteRule     ^manage/(\d{4}-\d{2}-\d{2})/(edit|delete)$      manage.php?action=$2&date=$1    [L]

# Prevent access to anything that didn't match so far and isn't in /sup/
RewriteCond     %{ENV:REDIRECT_STATUS}                          ^$ 
RewriteRule     ^(?!sup/|robots\.txt)                           views/404.php                   [L]

richard@guthnur.net at 10:03 am on May 28, 2009

@wbond Thanks. I'm a php developer with a company here in maine, I found your library and i have to say its really good, If you need good php developer let me know.

richard at 10:14 am on Jun 3, 2009

if i wanted to see a individual post how you handle that in the index.php

Mori at 11:01 am on Aug 8, 2009

Do you have a demo site that fully based on Flourish framework?

wbond at 8:44 pm on Aug 8, 2009

@Mori

This example site is fully based on Flourish, it uses only Flourish and built-in PHP functionality. Did you notice the ZIP download with all of the source files?

toln at 6:54 pm on Sep 25, 2009

RewriteCond     %{ENV:REDIRECT_STATUS}                          ^$ 
RewriteRule     ^(?!sup/|robots\.txt)                           views/404.php                   [L]

My set is a bit different I have

www.mysite.com

  • .htaccess
  • images
  • includes
    • flourish
    • init.php
    • config.php
  • index.php
  • templates
    • home.php
    • header.php
    • footer.php
    • 404.php

I am having a little issue with my 404 I figured i could change

RewriteRule     ^(?!sup/|robots\.txt)                           views/404.php                   [L]

to

RewriteRule     ^(?!templates/|robots\.txt)                           templates/404.php                   [L]

but no luck anyone? thanks

wbond at 1:45 pm on Oct 5, 2009

@toln

Since you renamed /views/ to /templates/ and /sup/ to /images/, the .htaccess should look like below. Notice how I changed sup/ to images/ and not templates/.

RewriteRule     ^(?!images/|robots\.txt)                           templates/404.php                   [L]

Yada at 6:18 am on Nov 28, 2010

This is a great demo. It took me a while to get it working. I was running WAMPSERVER and didn't have the Apache rewrite_module installed. Also my local environment wasn't was not running from port 80 so some of the stylesheets weren't linking properly. Please include the .htaccess file with the demo package and documentation that mod_rewrite is required to make the demo work properly. This will help beginners.

wbond at 3:18 pm on Dec 1, 2010

@Yada

I'm sorry that you had trouble getting this up and running. Perhaps I am misunderstanding what you are asking, but I do explicitly mention mod_rewrite in the first sentence of the third paragraph of this post. Also, the zip does seem to include the .htaccess file.

joho@boojam.se at 6:10 pm on Dec 6, 2010

Having a look at Flourish, and am liking what I'm seeing. One quick note though.. it'd be nice if all fCode? (that's short for "Flourish Code" ;)) stopped depending on $_SERVER DOCUMENT_ROOT? and instead required a $GLOBALS flourish_DocRoot? or some such instead (or a define called FLOURISH_DOC_ROOT.

Quite frequently, when I just sit and fiddle with various devStuff, I'll have one site (say mysite.com/playground) with many sub-directories, "emulating" the doc root. Querying $_SERVER DOCUMENT_ROOT? will yield "/var/www" (URL maps to mysite.com/playground), whereas this particular devStuff may be in /var/www/testingFlourish and mapping to mysite.com/playground/testingFlourish. This breaks every single examepl and "How To" I've seen. Setting $_SERVER DOCUMENT_ROOT? (yes, I know.. bad idea) early in config.php will sort of circumvent this.

Did that make any sense? :-)

wbond at 8:28 am on Dec 12, 2010

@joho

What sort of issues are you having with Flourish and $_SERVER['DOCUMENT_ROOT']? That value is only used in six of the classes, but is either not a requirement, or is used as a default value that can be overridden by a parameter or method call.

johnmahugu@gmail.com at 3:01 am on Mar 15, 2011

i am so lovingit.yaaaaaaaaay!

Add comment