Jump to content

Integrating Flourish With ProcessWire


netcarver
 Share

Recommended Posts

I've been asked how to integrate Will Bond's Flourish library with ProcessWire so I thought I'd post the code I use.

I downloaded the Flourish classes (not the whole flourish project) and put them into /site/.flourish. I then pasted the following into the top of my head.inc file.

function flourish_loader( $class_name )
{
// Customize this to your root Flourish directory
$flourish_root = wire('config')->paths->root . 'site/.flourish/';

$file = $flourish_root . $class_name . '.php';
if (file_exists($file)) {
	include $file;
}
}
spl_autoload_register( 'flourish_loader', true );

After that, you should be able to use flourish classes anywhere in your templates.

NB, if you do download the whole flourish project into .flourish, then read Alan's post on how to adapt the above to your layout.

Edited by netcarver
  • Like 5
Link to comment
Share on other sites

Excuse my question if it is a stupid one!

Why would you want to use Flourish with PW?

after a brief browse of flourish it seems that it covers a lot of the same

stuff that PW already has... isnt it?

Is it used as PEAR is used? for auxiliary classes?

Link to comment
Share on other sites

Thanks for sharing, Flourish looks useful and easy to use.

I read in a previous post that you used the Flourish library to collect emails from an IMAP account and display them in PW. I'd be interested to hear some more potential uses of this library when combined with PW.

Link to comment
Share on other sites

It's like PEAR in that it's a library of useful functions, but this one is all worked on by one guy (as far as I'm aware) so it's far more coherent than PEAR.

I'm using it for things like this: http://processwire.c...ndpost__p__2407 - it just allows previewing the last 10 emails of a given inbox - in this case it's a press email account so staff can read emails and write any news or other articles based on them. I toyed with the idea of being able to grab the email text and make a page automatically from it, but as anyone who's worked with emails knows you can end up with all sorts of formatting issues. Even if you remove all the formatting it does seem like overkill anyway.

I basically lost all my progress on that when my hard drive died last year, but it's actually not that hard to do things like that with Flourish and PW.

There is another topic on the forums where various newsletter systems were mentioned and that got me thinking (on a basic level) of something like PHPMailer too - before I remembered Flourish can cover that need - so there are things that PW can't do where it's useful to know about other well-coded classes and libraries to help out.

Oh, and before I forget - try this in your config instead of that $_SERVER['DOCUMENT_ROOT'] netcarver:

$flourish_root = wire('config')->paths->root . 'site/.flourish/'; 

Either will work of course, but I've had weird experiences with servers and paths in the past so I just felt a bit safer knowing I was definitely using the same paths throughout my code.

  • Like 1
Link to comment
Share on other sites

@Pete,

Good call, thanks for the update.

@Michael,

I use several classes regularly from Flourish and, as I just added a contact form to my first PW, I used the fValidation class for form validation & the fSMTP and fEmail classes to send things out via my SMTP server on successful form submission.

Link to comment
Share on other sites

  • 1 month later...

Doing a very lightweight events system so _thank you_ Steve + Pete for this perfect thread to help me get started.

I don't know if I am adding Flourish for a weak reason (I'm not strong at PHP date manipulation (or anything else PHP ;)) but even if I am, it will team me some stuff I am sure.

Link to comment
Share on other sites

Alan,

You got it! Yes, PW's default .htaccess file prevents web access to directories starting with a period.

Also, like Soma said above, all of the flourish classes need to be in that .flourish directory, not some sub-directory of it, if you want the class loader I posted to work out of the box.

Have fun!

  • Like 1
Link to comment
Share on other sites

Soma, Steve, thanks again you guys!

Because I use SourceTree.app to download from github things likes modules etc (and so keep them up to date and see when there are updates v.easily) I was keen to keep the installed Flourish 'standard' so rather than move the classes (I had missed that I was calling classes and they were represented by those files in that folder — DOH) I just edited the path in the loader to

$flourish_root = wire('config')->paths->root . 'site/.flourish/classes/';

and of course it all works! Thanks :)

Link to comment
Share on other sites

  • 8 months later...

Related (by who makes Flourish; Will Bond), I am in the process of being smitten by a new (to me) code editor, Sublime Text 2.

Although people's needs and tastes vary I thought I would note this down in case anyone else finds it handy (I should likely be posting this somewhere else, sorry).

In short: ST2 is so much more than I had at first thought and addresses the real pain when trying to get Coda 2, for example, to do a little more, like Zen Coding/Emmet—yes it can be coerced to do that but it feels bleeding edge, not normal. Expanding and customizing ST2 on the other hand feels natural. In danger of writing a whole video's worth of copy I'll stop and just note two links:

  1. I got intrigued about ST2 here
  2. the eloquent Jeffrey Way totally convinced me here (this is a free, full video course)

Mood: excited; PW, ST2 and just-subscribed tutsplus.com training.

PS: Had more info on SFTP from the clever Mr Bond but that'll have to wait for a blogpost. Better make one (in PW!) :)

Link to comment
Share on other sites

Related (by who makes Flourish; Will Bond), I am in the process of being smitten by a new (to me) code editor, Sublime Text 2.

Although people's needs and tastes vary I thought I would note this down in case anyone else finds it handy (I should likely be posting this somewhere else, sorry).

In short: ST2 is so much more than I had at first thought and addresses the real pain when trying to get Coda 2, for example, to do a little more, like Zen Coding/Emmet—yes it can be coerced to do that but it feels bleeding edge, not normal. Expanding and customizing ST2 on the other hand feels natural. In danger of writing a whole video's worth of copy I'll stop and just note two links:

  1. I got intrigued about ST2 here
  2. the eloquent Jeffrey Way totally convinced me here (this is a free, full video course)

Mood: excited; PW, ST2 and just-subscribed tutsplus.com training.

PS: Had more info on SFTP from the clever Mr Bond but that'll have to wait for a blogpost. Better make one (in PW!) :)

See also this thread: http://processwire.com/talk/topic/1888-sublime-text-2-course/

Link to comment
Share on other sites

Tks Soma. I am *sure* I tried ST2 a long time ago and simply didn't try to see how it worked (it didn't impress me with the prettiness of Coda). But this time I watched the video that's liked to and finally 'got it'. It's unbeatable and I've not even used it in a proper project yet.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...