PHP Classes
elePHPant
Icontem

File: proxylist.php5

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Kai Dorschner  >  PAC_proxylist  >  proxylist.php5  >  Download  
File: proxylist.php5
Role: Class source
Content type: text/plain
Description: Generates the PAC code
Class: PAC_proxylist
Generate proxy auto-configuration files from XML
Author: By
Last change: Converted global PHP Code to a class.
Date: 6 years ago
Size: 2,183 bytes
 

Contents

Class file image Download
<?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);
    }
}