Integrating PHP apps [or ANYTHING] into your Jadu template
Submitted by jwheat on Tue, 07/29/2014 - 07:26
Eventually, you're going to have to integrate something into your site, whether that is an interactive form, a full on custom PHP application, some neat full page function that won't fit into a widget. I'm going to outline how I accomplished that ability here at Messiah College.
The recommended practice is to place any customizations into public_html/site/custom_scripts, however, that makes for a url that I don't like, so I've actually created a directory straight off root called 'a' - physically it sits here public_html/a
Working at a college, we have departments and as I build out integrated apps, I add a new directory for each department like this -
/a/academics
/a/admissions
/a/registration
So you'll notice that the registration directory above isn't a department, right? We have many, many workshops, conferences, and other forms that require registration and payment using CashNet, our eCommerce "solution" (I use that work loosely, not a fan of CashNet at all). I've grouped all of these into once location to keep them organized and able to share the CashNet libraries I've built easily. Yes, I know PHP can use a central include path, but I wanted everything grouped together, and didn't want to add another path to the PHP config.
Off of 'a' I also have
/a/lib
/a/cache
/a/javascript
/a/css
These are pretty much explanatory however, the big one here is the lib directory. Jadu CMS has many 'types' of pages it can render, but here we use Home pages, and Document pages. Each section of the site has a category based navigation, so for example if you were on the admissions page, just like you would expect, the left hand navigation lists admissions pages. Sometimes these pages are main homepages, and other times, they are multi-page document pages, but the important thing to think about here is what the navigation looks like.
If we create .php file - /a/academics/index.php - that will display exactly what is in that .php file, no pretty wraps, no template, no navigation, nothing that looks integrated. At this point the only thing that is integrated is is the url :) So how do we get the 'wrap' around our new .php page?
Enter my crazy-hair-brained integration code. Within the /a/lib directory I have 4 files that accomplish this -
/a/lib/jadu_homepage_header.php
/a/lib/jadu_homepage_footer.php
/a/lib/jadu_document_header.php
/a/lib/jadu_document_footer.php
I was able to copy code almost in whole from home_info.php, home_info.html.php, document_info.php and document_info.html.php. I used 99% of this code to create the header files, obviously cutting out the code that actually renders the homepage content, and document page content and page navigation. For the footer files, I just copied the last lines of the xxxx.html.php page, which for the homepage footer was simply a call to closing.php, the document footer has a closing DIV to wrap up the page before it ends.
Now all I have to do is add a require_once for the header and footer. Ahhh, not yet. If you do what I said above, you'll realize quickly that doesn't work. If there is not a pageID set, or documentID set, the code redirects you either to your main landing page or tries to load a document index. So we have to scam it into thinking we're rendering a specific page.
So here is where a little extra work comes in. You have to determine which Jadu page on the site you want to mimic. So for example since this is an Academics page, you probably want to mimic either the Academic's homepage, or possibly an internal document page. When I do these integrations here, I always ask the web department which page to mimic. Sometimes they even create a special placeholder page and then mark it hidden. They'll give me a page, and what you _need_ is the Jadu id number for that page. I'll log into Jadu and find either the homepage or document page and hover over the link to open it in the editor, and look at the url. It will look something like this
.../websections/homepages_designer.php?homepageID=1358
or
.../websections/websection_subsections_list.php?documentID=2246
In either case you want the number on the end. Lets pretend we're doing a homepage mimic, we'll use 1358.
In my /a/academics/index.php file I will paste in
# ###############################################
# To Mimic A Home Page set the Jadu Homepage ID
#
$homepage = 1358;
require_once CUSTOM_APP_ROOT . "/lib/jadu_homepage_header.php";
#
# ###############################################
Now there is more <i> Jadu</i> (aka Magic) happening in my header files.
In jadu_homepage_header.php we need to somehow setup that $homepage variable so all the out-of-the box Jadu libraries work. This code makes that happen -
# ############################################### # Home Page Integrations Settings # Params : set $homepage in code including this # $indexPage = false; $_SERVER['SCRIPT_NAME'] = '/site/scripts/home_info.php'; $_GET['homepageID'] = $homepage; # Common variables for both documents & homepages $categoryItemArray = array(); $dirTree = array(); $includeMaps = false;The above variables are all set to fake out the different libraries and Jadu code into thinking we're rendering a homepage with the id of 1450.
The same thing is done with document pages although it takes a bit more to fake these out-
If we were creating a document page, we woudl put the following in our index.php file -
# ############################################### # To Mimic A Document Page set the JAdu Document ID $documentID = 2246; require_once CUSTOM_APP_ROOT . "/lib/jadu_document_header.php"; # # ###############################################and you can see in the jadu_document_header.php code how that documentID is used to set all the proper variables to fake Jadu into thinking we're generating a document page for id 2246
# ############################################### # Document Page Integrations Settings # Params : set $document in code including this # $_SERVER['SCRIPT_NAME'] = '/site/scripts/documents_info.php'; $_GET['documentID'] = $documentID; $page->id = $documentID; $pageNumber = 1; $showDocument = true; $accessDenied = false; $page->id = $pageNumber; $previewAllowed = false; $categoryItemArray = array(); $dirTree = array(); $includeMaps = false; $pageNumber = 1; $showDocument = true; $accessDenied = false;Soif you've followed that, and save your index.php file you will now be able to go to
http://site.edu/a/academics - and have your personal PHP code wrapped in your site's graphical layout with the proper navigation for wherever it should be located in your site.
The last thing is to create a friendly URL for your page and you're all set.
There is too much Jadu proprietary code for me to post these files here, but if you would like them, email me - jwheat@messiah.edu and I'll send them over to you.
If you have any questions feel free to post them in the comments section below.
Happy Hacking.
-Jon
General Concept:
Jadu Product:
Jadu Version:
