<?php
/**
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Kai Dorschner <webmaster@krnl.de>
* @copyright Copyright 2009, Kai Dorschner
* @license http://www.gnu.org/licenses/lgpl.html LGPLv3
*/
/**
* Generates dynamic proxy.pac code for your browser.
*/
class proxylist {
protected $xmlpath;
protected $xslpath;
/**
* Defines how many proxy IPs should be displayed.
*/
protected static $maxProxies = 2;
/**
* Containing the XML-List as DomDocument.
*/
protected $xml;
/**
* Containing the XSL transformation definition.
*/
protected $xsl;
public function __construct($xmlpath = 'proxylist.xml', $xslpath = 'bestproxy.xsl') {
$this->xmlpath = $xmlpath;
$this->xslpath = $xslpath;
}
/**
* This function is requiered in the XSL-Parser to let him know how many proxies should be printed out.
*/
public static function maxProxies() {
return self::$maxProxies;
}
/**
* Creates the proxy.pac source code.
*
* Define a plain output in the HTTP-header and transform source XML file.
*/
public function create() {
$this->xml = new DomDocument();
$this->xml->load($this->xmlpath);
$this->xsl = new DOMDocument();
$this->xsl->load($this->xslpath);
if(!headers_sent())
header('Content-Type: text/plain', true);
$xsl = new XSLTProcessor();
$xsl->registerPHPFunctions(); // Allows the XSL to access custom PHP functions.
$xsl->importStyleSheet($this->xsl);
echo $xsl->transformToXML($this->xml);
}
}
|