views:

86

answers:

1

Hi all, I tried to ask this once, but I think that my former question was too unclear for you guys to answer, so I'll try again

I'm making a website using the Zend Framework, and am trying to include the premade messageboard Phorum. So far, I've made it work by not running it through my bootstrap using my .htaccess file. What I'd like to do i'd like to do is to be able to run it through my bootstrap so that I can use my previously created Layouts and Classes that I can only run through Zend.

For example, I have a premade sign in system that works through Zend_Auth. I have the person's data saved in Zend_Session. I load the user's profile through a controller. I have a service layer for the model that connects to my database on behalf of the user. There are several other dependencies that, as far as I can tell, I need the bootstrap for.

Phorum is basically just a large set of PHP scripts that are dependent on GET parameters. My original idea had been to use a controller to render the scripts. An example of what that URI would look like is this: My-Site.com/messageboard/list.php?1,3 with messageboard being the messageboardController. While this works for loading list, it can't capture the GET parameters, which Phorum is dependent on. Due to the complex nature of Phorum, it would be nearly impossible for me to be able to go in and make it something like My-Site.com/messageboard/list/1/3 or anything along those lines. The URI has to be the former, as it is built in to Phorum.

I have tried using frames. I got to keep my log in panel up top, and had the body of the page be a frame, but it was unbookmarkable, and the back button made everything outrageously difficult. I also couldn't get the frame to talk to the parent page in Zend well, so frames aren't an option.

Does anyone have a way that I can do this? What I need, in essence, is to take the script (ex. list.php?1,3) and place whatever it would render, after having used the 1,3 parameters, into a div in the "body" div of my layout. As far as I can tell, render doesn't seem to be able to capture the GET parameters. Does anyone know of a way I can do this.

Any ideas would be immeasurably appreciated. Thank you for your help!

+1  A: 

This isn't a trivial thing to process, however, it is possible to write a custom route, along with some controller magic to handle this sort of thing and include the proper php file:

First of all - Your route should probably be (in ZF1.9 application.ini conventions)

resources.router.routes.phorum.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.phorum.route = "messageboard(?:/(.*))?"
resources.router.routes.phorum.defaults.controller = "phorum"
resources.router.routes.phorum.defaults.action = "wrapper"
resources.router.routes.phorum.defaults.module = "default"
resources.router.routes.phorum.defaults.page = "index.php"
resources.router.routes.phorum.map.1 = "page"

Now all requests to messageboard/whatever.php should be routed to PhorumController::wrapperAction() and have 'whatever.php' in $this->getRequest()->getParam('page')

Then it should become a simple matter of redirecting your "wrapper" action to include the proper php file from phorum. I have added some code from a similar controller I have (although mine didn't include php files - it was meant solely for serving a directory of content)

public function wrapperAction() {
   $phorumPath = APPLICATION_PATH."../ext/phorum/";

   $file = realpath($phorumPath . $this->getRequest()->getParam('page');
   if (!$file || !is_file($file)) throw new Exception("File not found");

   // disable default viewRenderer - layout should still render at this point
   $this->_helper->viewRenderer->setNoRender(true);     

   // determine extension to determine mime-type
   preg_match("#\.([^.]+)$#", $filename, $matches);
   switch (strtolower($matches[1]))
   {
     case "php":

       // patch the request over to phorum
       include($file);
       return; // exit from the rest of the handler, which deals specifically
       // with other types of files

     case "js": 
       $this->getResponse()->setHeader('Content-Type', 'text/javascript'); 
       ini_set('html_errors', 0);
       break;
     case "css": 
       $this->getResponse()->setHeader('Content-Type', 'text/css'); 
       ini_set('html_errors', 0);
       break;
     case "html":
       $this->getResponse()->setHeader('Content-Type', 'text/html');
       break;
     // you get the idea... add any others like gif/etc that may be needed
     default:
       $this->getResponse()->setHeader('Content-Type', 'text/plain'); 
       ini_set('html_errors', 0);
       break;
   }

   // Disable Layout
   $this->_helper->layout->disableLayout();

   // Sending 304 cache headers if the file hasn't changed can be a bandwidth saver
   $mtime = filemtime($fn);  
   if ($modsince = $this->getRequest()->getServer('HTTP_IF_MODIFIED_SINCE'))
   {
     $modsince = new Zend_Date($modsince);
     $modsince = $modsince->getTimestamp();

     if ($mtime <= $modsince) {
       $this->getResponse()->setHttpResponseCode(304); 
       return;
     }
   }

   $this->getResponse()->setHeader('Last-Modified', gmdate("D, d M Y H:i:s",$mtime). " GMT");
   readfile($fn);
}

Please - Make sure to test this code for people trying to craft requests with .., etc in the page.

gnarf
Okay, I finally got it working. I did almost exactly what you said, gnarf. My biggest problem, and one that I found out halfway through, is that Phorum uses a javascript.php and a css.php, which, instead of reading javascript and css, generate it. What was happening was my layout was also getting printed around the javascript and css, which essentially put non javascript in a javascript file, making it unreadable. Your main idea was great though, thank you.
Ethan
@Ethan - You could easily add a `if ($this->getRequest()->getParam('page') == 'javascript.php') $this->_helper->layout->disableLayout();` or similar things for special cases
gnarf