Table of Contents

Postnuke 0.8x / AMFPHP 1.9 beta

This version of Postnuke has a strong separation of GUI and API, utilizing the SMARTY Templating system. Providing a secure environment, easily developable, and written in PHP gives Postnuke an edge missing from alot of other CMS‘s out there. But being easily adjustable like it is makes for a system that you can make your own, as this conversion process is attempting to do.

Conversion

Converting AmfPHP to AmfPN should not be that difficult of a process. The most important things to think about here are the facts that:

  1. Postnuke handles ALL database calls. So technically, we just need amfphp to handle the amf-conversions for us. Most of our calls are going to be converted to simple module function calls which will return simple strings and numbers.
  2. Postnuke has an onboard class management system introduced in 0.8x that SHOULD allow us to just make a class call to AmfPHP and since we are placing the class in teh correct folder, Postnuke will take care of the includes/requires as needed.
  3. Postnuke handles the security for us MOSTLY, we do need to have a closer look at the security that AMFPHP uses and see what we should keep ( AMF-side security ) versus what we can ignore ( Server side security such as MySql injection protection ).

Step 1: Install

The first thing I have done is install Postnuke 0.8x.

My thoughts are that I need to get AMFPHP working from within a running install of PN, and I am going to do ANY and ALL File Conversions from within that environment. This way I can babystep my adjustments. Change this... test. Change that... test. And when I hit a problem, I just have to step back a step and re-do.

My first BIG goal is to get the Hello World program to return SOMETHING from the Postnuke Environment. I don’t really care what. I think that getting the PN Environment to interact with this program is just going to be too cool!

Thats all for now... forgive the blog’ishness of these Wiki entries. I will clean it all up once I get this thing done!

Step 2: Root Files

Alright. We have gone somewhere! I am a LITTLE elated.

Ok. I moved the amfphp directory INTO Postnuke. I decided the best place to do this was under:

root: includes/classes/amfphp

My next step was to create the generic HelloWorld.php file. I went to Sephiroths website and grabbed the HelloWorld.php code. And here it is:

<?php
 
include_once AMFPHP_BASE . "shared/util/MethodTable.php";
 
/**
 * First tutorial class
 */
class HelloWorld {
 
    /**
     * first simple method
     * @returns a string saying 'Hello World!'
     */
    function sayHello()
    {
		return "Hello World!";
    }
 
}
 
?>

Ok. So far so good.

We have a single method, sayHello. It returns a string. That’s all I need for now.

Next, I got to thinking. We want to give Postnuke the reigns of the security, to handle all database calls... etc. So what is the best way of doing this? A new root file! That’s right. For the AJAX functionality of Postnuke they created Ajax.php in the root, so I took the liberty of creating an amfph.php file... here are the contents of that file...

<?php
/**
 * PostNuke Application Framework
 *
 * @copyright (c) 2001, PostNuke Development Team
 * @link http://www.postnuke.com
 * @version $Id: amfpn.php 04JAN07:1449 randomblink $
 * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
 */
 
// include base api
include 'includes/pnAPI.php';
include 'includes/classes/amfphp/core/amf/app/Gateway.php';
 
// start PN
pnInit(PN_CORE_ALL & ~PN_CORE_TOOLS & ~PN_CORE_DECODEURLS);
 
// Check for site closed
if (pnConfigGetVar('siteoff') && !SecurityUtil::checkPermission('Settings::', 'SiteOff::', ACCESS_ADMIN) && !($module == 'Users' && $func == 'siteofflogin')) 
{
    if(SecurityUtil::checkPermission('Users::', '::', ACCESS_OVERVIEW) && pnUserLoggedIn())
	{
        pnUserLogOut();
    }
    
	echo ("Site is currently disabled");
}
	define("PRODUCTION_SERVER", false);
 
	$amfpn = new Gateway();
	$amfpn->setBaseClassPath('includes/classes/amfphp/services/');
	$amfpn->setLooseMode(true);
	$amfpn->setErrorHandling(E_ALL ^ E_NOTICE);
	$amfpn->setWebServiceHandler('php5');
	$amfpn->setAmf3RecordSetFormat("ArrayCollection");
	
	if(PRODUCTION_SERVER)
	{
		$amfpn->disableTrace();
		$amfpn->disableDebug();
		$amfpn->disableServiceDescription();
	}
	
	include_once('includes/classes/amfphp/advancedsettings.php');
	include_once('includes/classes/amfphp/adaptersettings.php');
 
	$amfpn->service();
 
?>

Basically? I took the Ajax.php file from the root... renamed it. Then I dumped the Ajax utilities and such, keeping the basic necessities.

For those of you familiar with amfphp, you will notice, I removed the $gateway and replaced it with $amfpn. I then had to make adjustments to advancedsettings and adaptersettings, altho I am FAIRLY certain I will be removing those two files completely. Since I believe I can start storing settings and such in some kind of Postnuke variable.

Step 3: Service Browser

We have our system setup just right now. Everything should TECHNICALLY be working. Let’s make sure.

Now since I dumped the entire amfphp directory I included the service browser. For those of you following along? Postnuke has a debug option. You can turn on debug and you get a popup window full of variables for testing and building purposes. I am envisioning a conversion of the service browser to an admin function. With full on Smarty templating and everything. This way module developers can test their Flash/Flex creations during testing with a live system.

BUT for now... let’s just make sure everything is working alright.

I pointed my browser to www.MySiteName.com/includes/classes/amfphp/browser and VOILA! It worked like a charm! I tested out my HelloWorld class, everything was just fine.

THEN I went into my HelloWorld.php file and I made a couple minor adjustments. These adjustments are the cause for my excitement right now.

on line 16 you will see:

return “Hello World!”;

I replaced this with the following line.

return pnGetBaseURL();

Guess what sayHello returned? That’s right! You got it! I got my websites root URL!

SO, my next step will be to build a Custom HelloWorld swf that points to amfpn.php and instantiates an $amfpn and go from there.

Thats all for today!