Exemplo n.º 1
0
    public function savePackagesCategoryREST($category)
    {
        $cdir = $this->getCategoryDirectory();
        if (!is_dir($cdir)) {
            return;
        }
        // list packages in a category
        $dir = $cdir . urlencode($category) . DIRECTORY_SEPARATOR;
        if (!is_dir($dir)) {
            if (!mkdir($dir, 0777, true)) {
                return PEAR::raiseError('Creating directory ' . $dir . ' failed - Check the permissions');
            }
        }
        $pdir = $this->getPackageDirectory();
        $rdir = $this->getReleaseDirectory();
        include_once 'pear-database-category.php';
        $packages = category::listPackages($category);
        $fullpackageinfo = '<?xml version="1.0" encoding="UTF-8" ?>
<f xmlns="http://pear.php.net/dtd/rest.categorypackageinfo"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xsi:schemaLocation="http://pear.php.net/dtd/rest.categorypackageinfo
    http://pear.php.net/dtd/rest.categorypackageinfo.xsd">
';
        clearstatcache();
        foreach ($packages as $package) {
            $pmdir = $pdir . strtolower($package['name']) . DIRECTORY_SEPARATOR;
            if (!file_exists($pmdir . 'info.xml')) {
                continue;
            }
            $fullpackageinfo .= '<pi>
';
            $contents = file_get_contents($pmdir . 'info.xml');
            $fullpackageinfo .= '<p>' . substr($contents, strpos($contents, '<n>'));
            $rmdir = $rdir . strtolower($package['name']) . DIRECTORY_SEPARATOR;
            if (file_exists($rmdir . 'allreleases.xml')) {
                $fullpackageinfo .= str_replace($this->_getAllReleasesRESTProlog($package['name']), '
<a>
', file_get_contents($rmdir . 'allreleases.xml'));
                $files = scandir($rmdir);
                foreach ($files as $entry) {
                    if (strpos($entry, 'deps.') === 0) {
                        $version = str_replace(array('deps.', '.txt'), array('', ''), $entry);
                        $fullpackageinfo .= '
<deps>
 <v>' . $version . '</v>
 <d>' . htmlspecialchars(utf8_encode(file_get_contents($rmdir . $entry))) . '</d>
</deps>
';
                    }
                }
            }
            $fullpackageinfo .= '</pi>
';
        }
        $fullpackageinfo .= '</f>';
        $file = $dir . 'packagesinfo.xml';
        if (!file_put_contents($file, $fullpackageinfo)) {
            return PEAR::raiseError('Writing file ' . $file . ' failed - Check the permissions');
        }
        @chmod($file, 0666);
    }
Exemplo n.º 2
0
    function savePackagesCategoryREST($category)
    {
        $cdir = $this->_restdir . DIRECTORY_SEPARATOR . 'c';
        if (!is_dir($cdir)) {
            return;
        }
        $pdir = $this->_restdir . DIRECTORY_SEPARATOR . 'p';
        $rdir = $this->_restdir . DIRECTORY_SEPARATOR . 'r';
        $packages = category::listPackages($category);
        $fullpackageinfo = '<?xml version="1.0" encoding="UTF-8" ?>
<f xmlns="http://pear.php.net/dtd/rest.categorypackageinfo"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xsi:schemaLocation="http://pear.php.net/dtd/rest.categorypackageinfo
    http://pear.php.net/dtd/rest.categorypackageinfo.xsd">
';
        clearstatcache();
        foreach ($packages as $package) {
            if (!file_exists($pdir . DIRECTORY_SEPARATOR . strtolower($package['name']) . DIRECTORY_SEPARATOR . 'info.xml')) {
                continue;
            }
            $fullpackageinfo .= '<pi>
';
            $contents = file_get_contents($pdir . DIRECTORY_SEPARATOR . strtolower($package['name']) . DIRECTORY_SEPARATOR . 'info.xml');
            $fullpackageinfo .= '<p>' . substr($contents, strpos($contents, '<n>'));
            if (file_exists($rdir . DIRECTORY_SEPARATOR . strtolower($package['name']) . DIRECTORY_SEPARATOR . 'allreleases.xml')) {
                $fullpackageinfo .= str_replace($this->_getAllReleasesRESTProlog($package['name']), '
<a>
', file_get_contents($rdir . DIRECTORY_SEPARATOR . strtolower($package['name']) . DIRECTORY_SEPARATOR . 'allreleases.xml'));
                $dirhandle = opendir($rdir . DIRECTORY_SEPARATOR . strtolower($package['name']));
                while (false !== ($entry = readdir($dirhandle))) {
                    if (strpos($entry, 'deps.') === 0) {
                        $version = str_replace(array('deps.', '.txt'), array('', ''), $entry);
                        $fullpackageinfo .= '
<deps>
 <v>' . $version . '</v>
 <d>' . htmlspecialchars(utf8_encode(file_get_contents($rdir . DIRECTORY_SEPARATOR . strtolower($package['name']) . DIRECTORY_SEPARATOR . $entry))) . '</d>
</deps>
';
                    }
                }
            }
            $fullpackageinfo .= '</pi>
';
        }
        $fullpackageinfo .= '</f>';
        // list packages in a category
        if (!is_dir($cdir . DIRECTORY_SEPARATOR . urlencode($category))) {
            mkdir($cdir . DIRECTORY_SEPARATOR . urlencode($category));
        }
        file_put_contents($cdir . DIRECTORY_SEPARATOR . urlencode($category) . DIRECTORY_SEPARATOR . 'packagesinfo.xml', $fullpackageinfo);
        @chmod($cdir . DIRECTORY_SEPARATOR . urlencode($category) . DIRECTORY_SEPARATOR . 'packagesinfo.xml', 0666);
    }