Jump to content
netcarver

Integrating Flourish With ProcessWire

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

Share this post


Link to post
Share on other sites

Thanks for that - it was infinitely simpler than what I'd managed to put together the last time - mich appreciated!

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Steve, is there a special reason for making the directory hidden?

DOH! Guessing this is 'cos it hides it from HTTP

  • Like 1

Share this post


Link to post
Share on other sites

Looks like the date class isn't loaded. Make sure you have all classes in /.flourish and not in a subfolder. So should be like /.flourish/fDate.php.

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

Thanks for posting that Alan, I've also updated the opening post to make it a little clearer too.

  • Like 1

Share this post


Link to post
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!) :)

Share this post


Link to post
Share on other sites

Thanks for the links Alan.

Just one correction. Sublime Text is not from Will Bond, he "only" made some packages for it. The developer of ST is a guy called Jon Skinner.

  • Like 1

Share this post


Link to post
Share on other sites

Yes diogo, thanks, I certainly implied that which I hadn't meant to, thanks for clarifying that :)

Share this post


Link to post
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/

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By fmgujju
      I would like to know how to integrate Flourish with PW. I have read Flourish module thread and related post as well but it doesn't tell anything more than as below:
      then in your code:
      // in templates
      $modules->get('LibFlourish');

      // in modules
      $this->modules->get('LibFlourish');

      // anywhere else
      wire('modules')->get('LibFlourish'); I am creating user registration and membership portal where I want to work with my own table structure which I created for membership project. I want to know how to use Flourish with PW to submit forms with Flourish validations. Do I have to create PW template first and then add into PW Template area using PW Admin panel and then create a page to use them? If so then how do the form submit (post action) work. I am confused. I follow same as I mentioned to create user registration page but none of the validation is working as expected. Also, I have to add post-action-template.php to PW in order to work but still not working.
      I am trying to build web application with Flourish with PW. I can do it without PW but then website style and look and feel, I need to maintain separately which I do not want it.
      If any one can give some example how can I do it that would be much appreciated.
×
×
  • Create New...