$db->unbuffered_query($query);
        } else {
            $url = "http://apcms.php-programs.de/download/plugins/" . $plugin_name . ".tar.gz";
            $return = apcms_GetHTML($url);
            $pplugin = preg_replace("`^.*\\s*\n\\s*\n\\s*`isU", "", $return['html']);
            $fp = fopen($apcms['path'] . "/plugins/" . $plugin_name . ".tar.gz", "w");
            fwrite($fp, $pplugin);
            fclose($fp);
            if (file_exists($apcms['path'] . "/plugins/" . $plugin_name . "/" . $plugin_name . "." . $SUFFIX)) {
                apcms_DeleteDirectory($apcms['path'] . "/plugins/" . $plugin_name);
            }
            require_once "Archive/Tar.php";
            $tar = new Archive_Tar($apcms['path'] . "/plugins/" . $plugin_name . ".tar.gz");
            $tar->extract($apcms['path'] . "/plugins/");
            @unlink($apcms['path'] . "/plugins/" . $plugin_name . ".tar.gz");
            apcms_ChmodDirectory($apcms['path'] . "/plugins/" . $plugin_name, 777);
            require_once $PATH . "/plugins/" . $plugin_name . "/" . $plugin_name . "." . $SUFFIX;
            $thisplugin = new $plugin_name(true);
            $thisplugin->install();
            $config_items = $thisplugin->config_items;
            $config = array();
            foreach ($config_items as $key => $val) {
                $config[$key] = $config_items[$key]['default'];
            }
            $query = "INSERT INTO `" . $apcms['table']['global']['plugins'] . "` \n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t`name`,\n\t\t\t\t\t\t\t\t\t\t`md5`,\n\t\t\t\t\t\t\t\t\t\t`config`, \n\t\t\t\t\t\t\t\t\t\t`version`\n\t\t\t\t\t\t) VALUES \t(\n\t\t\t\t\t\t\t\t\t\t'" . apcms_ESC($plugin_name) . "',\n\t\t\t\t\t\t\t\t\t\t'" . md5(apcms_ESC($plugin_name)) . "',\n\t\t\t\t\t\t\t\t\t\t'" . addslashes(serialize($config)) . "', \n\t\t\t\t\t\t\t\t\t\t'" . apcms_ESC($thisplugin->version) . "'\n\t\t\t\t\t\t\t\t\t)";
            $db->unbuffered_query($query);
        }
    }
}
$AOUT .= "<a href=\"" . $apcms['baseURL'] . "?c=admin&amp;act=installplugins\"><img src=\"" . $apcms['themesurl'] . "/images/download.png\" width=\"50\" height=\"50\" alt=\"" . $apcms['LANGUAGE']['ADMIN_PLUGINS_INSTALL_NEW_PLUGINS'] . "\" title=\"" . $apcms['LANGUAGE']['ADMIN_PLUGINS_INSTALL_NEW_PLUGINS'] . "\" /></a> &nbsp; &nbsp; <a href=\"" . $apcms['baseURL'] . "?c=admin&amp;act=installplugins\">" . $apcms['LANGUAGE']['ADMIN_PLUGINS_INSTALL_NEW_PLUGINS'] . "</a><br /><br />\n";
$AOUT .= "<form name=\"registerform\" action=\"" . $apcms['baseURL'] . "?c=admin&amp;act=plugins\" method=\"post\">\n";
/**
 * Chmodes a complete directory with its contents (recursive)
 *
 * @param          string $sourcedir
 * @access         private
 * @return         array
 * @author Alexander Mieland
 * @copyright 2000- by Alexander 'dma147' Mieland
 */
function apcms_ChmodDirectory($sourcedir, $mode = 777)
{
    $filemode = '0' . $mode;
    $filemode = octdec($filemode);
    if (!is_dir($sourcedir)) {
        return chmod($sourcedir, $filemode);
    }
    $filearray = array();
    $sourcedir .= "/";
    $handle = @opendir($sourcedir);
    while ($eintrag = @readdir($handle)) {
        $target = $sourcedir . $eintrag;
        if (is_dir($target) && $eintrag != "." && $eintrag != "..") {
            @chmod($target, $filemode);
            $slashpos = strrpos($target, "/");
            if ($slashpos) {
                $chmoddir = substr($target, 0, $slashpos);
                @chmod($chmoddir, $filemode);
            }
            $filearray[$target] = apcms_ChmodDirectory($target, $mode);
            @chmod($target, $filemode);
            $slashpos = strrpos($target, "/");
            if ($slashpos) {
                $chmoddir = substr($target, 0, $slashpos);
                @chmod($chmoddir, $filemode);
            }
        } elseif ($eintrag != "." && $eintrag != "..") {
            $filearray[] = $eintrag;
            @chmod($target, $filemode);
            $slashpos = strrpos($target, "/");
            if ($slashpos) {
                $chmoddir = substr($target, 0, $slashpos);
                @chmod($chmoddir, $filemode);
            }
        }
    }
    @closedir($handle);
    return $filearray;
}