PHP Classes

File: XsltPlugin.php

Recommend this page to a friend!
  Classes of Scott Christensen   Phramework   XsltPlugin.php   Download  
File: XsltPlugin.php
Role: Auxiliary script
Content type: text/plain
Description: Reusable view plugin class for XSLT in Phramework
Class: Phramework
MVC framework for building web applications
Author: By
Last change:
Date: 19 years ago
Size: 2,127 bytes
 

Contents

Class file image Download
<?php
/*
 * Phramework Copyright (C) 2005 GodsArmor.com
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option) any
 * later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, write to theFree Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/**
 * This class requires no parameters but does require that the data sent into
 * this class has the following key/value pairs
 * <ul>
 * <li>xml: (required) The XML data in string format.</li>
 * <li>params: (optional) An array of key/value pairs that coorespond to
 * parameters that should be passed into the XSL stylesheet.</li>
 * </ul>
 * This class also requires that CURL and an XSLT processor is compiled into PHP.
 */
class XsltPlugin extends ViewPlugin {
    function
XsltPlugin() {
       
// Nothing to set up here
   
}
   
    function
init($params) {
       
// No parameters required
   
}

    function
destroy() {
       
// Nothing to destroy
   
}

    function
processView($viewValue, $data) {
       
$xml = $data['xml'];
       
$params = null;
        if (isset(
$data['params'])) {
           
$params = $data['params'];
        }

       
$ch = curl_init();
       
curl_setopt($ch, CURLOPT_URL, $viewValue);
       
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       
$xsl = curl_exec($ch);
       
curl_close($ch);
       
       
$xslt=new Xslt();
       
$xslt->setXmlString($xml);
       
$xslt->setXslString($xsl);
       
        if (isset(
$params) && is_array($params)) {
           
$xslt->addParameters($params);
        }
       
        if(
$xslt->transform()) {
           
$ret=$xslt->getOutput();
            echo
$ret;
        } else {
            echo(
"Error:".$xslt->getError());
        }
    }
}
?>