All pastes #127262 Raw Edit

Mine

public php v1 · immutable
·published 2006-08-12 02:59 UTC
rendered paste body
<?php/* snip */    /**     * Install gallery     */    function Install($config)    {        $site = &Site::Get();        if ( $_REQUEST["setup"] == "manual" || $config["installation_path"] != "modules/gallery/gallery2" )        {            eval("?>".$site->GetInterfaceTemplate("gallery", "setup-manual")."<?");            return;        }                if ( !isset($_REQUEST["command"]) )        {            InitialiseScriptaculous();            eval("?>".$site->GetInterfaceTemplate("gallery", "setup")."<?");            return;        }                header("Content-Type: application/xml");        header("Cache-Control: no-cache");        $site->DisableHeaders();                switch ( $_REQUEST["command"] )        {            case "download":                $url = ( isset($_REQUEST["url"]) ? $_REQUEST["url"] : GALLERY_DEFAULT_URL );                                $fd = @fopen($url, "r");                if ( !$fd )                {                    $url = GALLERY_DEFAULT_URL;                    $fd = @fopen($url, "r");                }                                if ( !$fd )                {                    echo "<?xml version=\"1.0\" ?><result><resultcode>1</resultcode><resultstring>".                        htmlspecialchars("The download process failed.  Please <a href=\"?setup=manual\">install manually</a>.").                        "</resultstring></result>";                    return;                }                                $ofd = @fopen("/tmp/gallery.tar.gz", "w");                if ( !$ofd )                {                    echo "<?xml version=\"1.0\" ?><result><resultcode>2</resultcode><resultstring>".                        htmlspecialchars("Could not write to /tmp/gallery.tar.gz. Please check permissions, or <a href=\"?setup=manual\">install manually</a>.").                        "</resultstring></result>";                    return;                }                                try                {                    while ( !@feof($fd) )                    {                        if ( @file_exists("/tmp/gallery-cancel-download") )                        {                            $cancelled = true;                            @unlink("/tmp/gallery-cancel-download");                            break;                        }                        @fwrite($ofd, @fgets($fd));                    }                                        @fclose($fd);                    @fclose($ofd);                }                catch ( Exception $e )                {                    echo "<?xml version=\"1.0\" ?><result><resultcode>3</resultcode><resultstring>".                    htmlspecialchars("The download process failed.  Please <a href=\"?setup=manual\">install manually</a>.").                        "</resultstring></result>";                    @unlink("/tmp/gallery.tar.gz");                    return;                }                                if ( $cancelled )                {                    echo "<?xml version=\"1.0\" ?><result><resultcode>4</resultcode><resultstring>".                        htmlspecialchars("The download was cancelled.  Please <a href=\"?setup=manual\">install manually</a>.").                    @unlink("/tmp/gallery.tar.gz");                    return;                }                                echo "<?xml version=\"1.0\" ?><result><resultcode>0</resultcode><resultstring>".                    "Succeeded.</resultstring></result>";                break;                        case "get_download_status":                if ( file_exists("/tmp/gallery.tar.gz") )                {                    echo "<?xml version=\"1.0\" ?><result><resultcode>0</resultcode><resultstring>".                        filesize("/tmp/gallery.tar.gz").                        "</resultstring></result>";                }                else                {                    echo "<?xml version=\"1.0\" ?><result><resultcode>1</resultcode><resultstring>".                        "Not downloaded.</resultstring></result>";                }                                break;                            case "cancel-download":                if ( @touch("/tmp/gallery-cancel-download") )                {                    echo "<?xml version=\"1.0\" ?><result><resultcode>0</resultcode><resultstring>".                        "Cancelling...</resultstring></result>";                }                else                {                    echo "<?xml version=\"1.0\" ?><result><resultcode>1</resultcode><resultstring>".                        "Couldn't cancel.</resultstring></result>";                }                break;                        case "extract":                            @chdir($_SERVER["DOCUMENT_ROOT"]."/modules/gallery");                                $err = trim(@shell_exec("tar zxf /tmp/gallery.tar.gz 2>&1"));                                if ( file_exists("gallery2/index.php") )                {                    echo "<?xml version=\"1.0\" ?><result><resultcode>0</resultcode><resultstring>".                        "Succeeded.</resultstring></result>";                }                else                {                    echo "<?xml version=\"1.0\" ?><result><resultcode>1</resultcode><resultstring>".                        "Could not extract Gallery package.".                        ($err?"  Extraction process said: ".htmlspecialchars($err):"").                        htmlspecialchars("<br />Please <a href=\"?setup=manual\">install manually</a>.").                        "</resultstring></result>";                }                                @unlink("/tmp/gallery.tar.gz");            break;        }    }?>