示例#1
0
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-7-11
 * Time: 上午10:40
 */
function copyDir($dirSrc, $dirTo)
{
    if (is_file($dirTo)) {
        //如果目标不是一个目录则退出
        echo "目标不是目录不能创建!!";
        return;
    }
    if (!file_exists($dirTo)) {
        //如果目标不存在,则创建目录
        mkdir($dirTo);
    }
    if ($dir_handle = @opendir($dirSrc)) {
        //打开目录并判断是否成功
        while ($filename = readdir($dir_handle)) {
            //循环遍历目录
            if ($filename != "." && $filename != "..") {
                //排除两个特殊目录
                $subSrcFile = $dirSrc . "/" . $filename;
                $subToFile = $dirTo . "/" . $filename;
                if (is_dir($subSrcFile)) {
                    //如果是子目录,则递归
                    copyDir($subSrcFile, $subToFile);
                }
                if (is_file($subSrcFile)) {
                    //如果是文件,则使用copy直接拷贝
                    copy($subSrcFile, $subToFile);
                }
            }
        }
        closedir($dir_handle);
        //最后记得一定要关闭目录句柄
    }
}
示例#2
0
function copyDir($source, $target, $exclude = array())
{
    if (is_dir($source)) {
        @mkdir($target, 0777, true);
        $dirRef = dir($source);
        while (FALSE !== ($entry = $dirRef->read())) {
            // Read through exclude list. If the current directory is on it, skip it
            $skip = false;
            foreach ($exclude as $exclFile) {
                if ($entry == $exclFile) {
                    $skip = true;
                    continue;
                }
            }
            if ($entry == '.' || $entry == '..' || $skip) {
                continue;
            }
            $entryFullPath = $source . '/' . $entry;
            if (is_dir($entryFullPath)) {
                copyDir($entryFullPath, $target . '/' . $entry, $exclude);
                continue;
            }
            copy($entryFullPath, $target . '/' . $entry);
            echo "Copying " . $entry . " to " . $target . "/\n";
        }
        $dirRef->close();
    } else {
        copy($source, $target);
    }
}
function exportBuildFiles($configArray)
{
    global $modx;
    $dirPermission = $modx->getOption('dirPermission', $configArray, 0777);
    $packageNameLower = $modx->getOption('packageNameLower', $configArray, '');
    $targetRoot = $modx->getOption('targetRoot', $configArray, '');
    $workingDir = $modx->getOption('core_path') . 'components/migxelementsmanager/_buildsources/';
    if (!empty($packageNameLower) && !empty($workingDir) && !empty($targetRoot)) {
        $targetDir = $targetRoot . '_build/';
        copyDir($workingDir, $targetDir, $dirPermission);
        //overwrite from package
        $workingDir = $modx->getOption('core_path') . 'components/' . $packageNameLower . '/_buildsources/';
        copyDir($workingDir, $targetDir, $dirPermission);
    }
}
示例#4
0
function copyDir($src, $dst)
{
    // 原目录,复制到的目录
    $dir = opendir($src);
    @mkdir($dst);
    while (false !== ($file = readdir($dir))) {
        if ($file != '.' && $file != '..') {
            if (is_dir($src . '/' . $file)) {
                copyDir($src . '/' . $file, $dst . '/' . $file);
            } else {
                copy($src . '/' . $file, $dst . '/' . $file);
            }
        }
    }
    closedir($dir);
}
示例#5
0
function copyDir($path, $newPath)
{
    $items = listDirectory($path);
    if (!is_dir($newPath)) {
        mkdir($newPath, octdec(DIRPERMISSIONS));
    }
    foreach ($items as $item) {
        if ($item == '.' || $item == '..') {
            continue;
        }
        $oldPath = RoxyFile::FixPath($path . '/' . $item);
        $tmpNewPath = RoxyFile::FixPath($newPath . '/' . $item);
        if (is_file($oldPath)) {
            copy($oldPath, $tmpNewPath);
        } elseif (is_dir($oldPath)) {
            copyDir($oldPath, $tmpNewPath);
        }
    }
}
示例#6
0
文件: ModAdd.php 项目: simpart/trut
 public function exec()
 {
     try {
         /* check specified directory */
         chkRequireConts($this->getPrm());
         $desc = yaml_parse_file($this->getPrm() . 'conf/desc.yml');
         if (false === $desc) {
             throw new \err\ComErr('could not read module description file', 'please check ' . $tgt . 'conf/desc.yml');
         }
         /* check installed module */
         if (true === isInstalled($desc['name'])) {
             /* target module is already installed */
             throw new \err\ComErr('specified module is already installed', 'please check \'spac mod list\'');
         }
         /* copy module contents */
         copyDir($this->getPrm(), __DIR__ . '/../../mod/' . $desc['name']);
         /* add module name to module config file */
         $modcnf = yaml_parse_file(__DIR__ . '/../../../../conf/module.yml');
         $first = false;
         if (null === $modcnf) {
             $first = true;
             $modcnf = array();
         }
         $add = array('name' => $desc['name'], 'select' => false);
         if (true === $first) {
             $add['select'] = true;
         }
         $modcnf[] = $add;
         if (false === copy(__DIR__ . '/../../../../conf/module.yml', __DIR__ . '/../../../../conf/module.yml_')) {
             throw new \err\ComErr('could not create backup of module config', 'please check ' . __DIR__ . '/../../../../conf');
         }
         if (false === file_put_contents(__DIR__ . '/../../../../conf/module.yml', yaml_emit($modcnf))) {
             throw new \err\ComErr('could not edit module config file', 'please check ' . __DIR__ . '/../../../../conf/module.yml');
         }
         unlink(__DIR__ . '/../../../../conf/module.yml_');
         echo 'Successful install ' . $desc['name'] . ' module' . PHP_EOL;
         echo 'You can check installed module \'spac mod list\',' . PHP_EOL;
     } catch (\Exception $e) {
         throw $e;
     }
 }
示例#7
0
function copyDir($source, $destination)
{
    if (is_dir($source)) {
        @mkdir($destination, 0755);
        $directory = dir($source);
        while (FALSE !== ($readdirectory = $directory->read())) {
            if ($readdirectory == '.' || $readdirectory == '..') {
                continue;
            }
            $PathDir = $source . '/' . $readdirectory;
            if (is_dir($PathDir)) {
                copyDir($PathDir, $destination . '/' . $readdirectory);
                continue;
            }
            copy($PathDir, $destination . '/' . $readdirectory);
        }
        $directory->close();
    } else {
        copy($source, $destination);
    }
}
示例#8
0
文件: helpers.php 项目: exakat/exakat
function copyDir($src, $dst)
{
    if (!file_exists($src)) {
        throw new \Exakat\Exceptions\NoSuchDir('Can\'t find dir : "' . $src . '"');
    }
    $dir = opendir($src);
    if (!$dir) {
        throw new \Exakat\Exceptions\NoSuchDir('Can\'t open dir : "' . $src . '"');
    }
    $total = 0;
    mkdir($dst, 0755);
    while (false !== ($file = readdir($dir))) {
        if ($file != '.' && $file != '..') {
            if (is_dir($src . '/' . $file)) {
                $total += copyDir($src . '/' . $file, $dst . '/' . $file);
            } else {
                copy($src . '/' . $file, $dst . '/' . $file);
                ++$total;
            }
        }
    }
    closedir($dir);
    return $total;
}
function copyDir($subject, $to)
{
    if (file_exists($to) || !mkdir($to)) {
        return refresh('Destination exists or creation of destination failed.');
    }
    $handle = opendir($subject);
    while (($dirItem = readdir($handle)) !== false) {
        if ($dirItem == '.' || $dirItem == '..') {
            continue;
        }
        $path = $subject . '/' . $dirItem;
        if (is_dir($path)) {
            copyDir($path, $to . '/' . $dirItem);
        } else {
            copy($path, $to . '/' . $dirItem);
        }
    }
    closedir($handle);
}
示例#10
0
文件: index.php 项目: 41835478/GMU
function copyDir($src, $desc)
{
    if (is_file($src)) {
        return copy($src, $desc);
    } else {
        if (is_dir($src)) {
            is_dir($desc) || mkdir($desc);
            $files = scandir($src);
            foreach ($files as $file) {
                if ($file == '.' || $file == '..') {
                    continue;
                }
                if (!copyDir($src . '/' . $file, $desc . "/" . $file)) {
                    return false;
                }
            }
            return true;
        }
    }
}
示例#11
0
function copyDir($src, $dst)
{
    if (is_dir($src) === true) {
        $handle = opendir($src);
        while ($entry = readdir($handle)) {
            if ($entry === '.' || $entry === '..') {
                continue;
            }
            if (is_dir("{$src}/{$entry}")) {
                mkdir("{$dst}/{$entry}");
            }
            copyDir("{$src}/{$entry}", "{$dst}/{$entry}");
        }
        closedir($handle);
    } else {
        copy($src, $dst);
    }
}
示例#12
0
 /**
  * Clear and init folder
  *
  * @return string
  */
 private function initFolder()
 {
     if ($this->finalName === null) {
         return "Can't produce Devoops format to stdout";
     }
     // Clean temporary destination
     if (file_exists($this->tmpName)) {
         rmdirRecursive($this->tmpName);
     }
     // Copy template
     copyDir($this->config->dir_root . '/media/devfaceted', $this->tmpName);
 }
示例#13
0
文件: Update.php 项目: exakat/exakat
 public function run()
 {
     if ($this->config->project === 'default') {
         throw new ProjectNeeded();
     }
     $path = $this->config->projects_root . '/projects/' . $this->config->project;
     if (!file_exists($path)) {
         throw new NoSuchProject($this->config->project);
     }
     if (!file_exists($path . '/code')) {
         throw new NoCodeInProject($this->config->project);
     }
     switch (true) {
         // symlink case
         case $this->config->project_vcs === 'symlink':
             // Nothing to do, the symlink is here for that
             break;
             // copy case
         // copy case
         case $this->config->project_vcs === 'copy':
             // Remove and copy again
             $total = rmdirRecursive($this->config->projects_root . '/projects/' . $this->config->project . '/code/');
             display("{$total} files were removed");
             $total = copyDir(realpath($this->config->project_url), $this->config->projects_root . '/projects/' . $this->config->project . '/code');
             display("{$total} files were copied");
             break;
             // Git case
         // Git case
         case file_exists($path . '/code/.git'):
             display('Git pull for ' . $this->config->project);
             $res = shell_exec('cd ' . $path . '/code/; git branch | grep \\*');
             $branch = substr(trim($res), 2);
             $resInitial = shell_exec('cd ' . $path . '/code/; git show-ref --heads ' . $branch);
             $date = trim(shell_exec('cd ' . $path . '/code/; git pull --quiet; git log -1 --format=%cd '));
             $resFinal = shell_exec('cd ' . $path . '/code/; git show-ref --heads ' . $branch);
             if ($resFinal != $resInitial) {
                 display("Git updated to commit {$res} (Last commit : {$date})");
             } else {
                 display("No update available (Last commit : {$date})");
             }
             break;
             // svn case
         // svn case
         case file_exists($path . '/code/.svn'):
             display('SVN update ' . $this->config->project);
             $res = shell_exec('cd ' . $path . '/code/; svn update');
             preg_match('/At revision (\\d+)/', $res, $r);
             display("SVN updated to revision {$r['1']}");
             break;
             // bazaar case
         // bazaar case
         case file_exists($path . '/code/.bzr'):
             display('Bazaar update ' . $this->config->project);
             $res = shell_exec('cd ' . $path . '/code/; bzr update 2>&1');
             preg_match('/revision (\\d+)/', $res, $r);
             display("Bazaar updated to revision {$r['1']}");
             break;
             // composer case
         // composer case
         case $this->config->project_vcs === 'composer':
             display('Composer update ' . $this->config->project);
             $res = shell_exec('cd ' . $path . '/code/; composer install ');
             $json = file_get_contents($path . '/code/composer.lock');
             $json = json_decode($json);
             foreach ($json->packages as $package) {
                 if ($package->name == $this->config->project_url) {
                     display("Composer updated to revision " . $package->source->reference . ' ( version : ' . $package->version . ' )');
                 }
             }
             break;
         default:
             display('No VCS found to update (Only git, svn and bazaar are supported. Ask exakat to add more.');
     }
 }
示例#14
0
文件: file.php 项目: simpart/trut
function copyDir($src, $dst)
{
    try {
        /* check source directory */
        if (false === isDirExists($src)) {
            throw new \Exception('could not find source directory');
        }
        /* check destination directory */
        if (false === isDirExists($dst)) {
            if (false === mkdir($dst)) {
                throw new \Exception('could not create destination directory');
            }
        }
        $scan = scandir($src);
        foreach ($scan as $elm) {
            if (0 === strcmp($elm, '.') || 0 === strcmp($elm, '..')) {
                continue;
            }
            $ftype = filetype($src . '/' . $elm);
            if (0 === strcmp($ftype, 'dir')) {
                copyDir($src . '/' . $elm, $dst . '/' . $elm);
            } else {
                if (false === copy($src . '/' . $elm, $dst . '/' . $elm)) {
                    throw new \Exception('could not copy \'' . $src . '/' . $elm . '\'' . ' to \'' . $dst . '\'');
                }
            }
        }
    } catch (\Exception $e) {
        throw $e;
    }
}
 function copy($source, $destination)
 {
     append_to_log("Source: {$source}   Destination: {$destination}");
     ob_start();
     var_dump($_SERVER);
     $m = ob_get_contents();
     ob_end_clean();
     append_to_log($m);
     // Make real path to source and destination.
     $realSource = $_SERVER["DOCUMENT_ROOT"] . $source;
     $realDestination = $_SERVER["DOCUMENT_ROOT"] . $destination;
     append_to_log("RealSource: {$realSource}   RealDestination: {$realDestination}");
     $status = copyDir($realSource, $realDestination);
     if ($status) {
         append_to_log("copy was OK");
         return eZWebDAVServer::OK_CREATED;
     } else {
         append_to_log("copy FAILED");
         return eZWebDAVServer::FAILED_CONFLICT;
     }
 }
示例#16
0
     if (is_file($dir . $module . '/sql.php')) {
         $sqlfiles[] = $dir . $module . '/sql.php';
     }
 }
 if ($import == 1) {
     if (is_file(ROOT_PATH . 'admin/install/' . $_SESSION['typ'] . '/datas.php')) {
         $sqlfiles[] = ROOT_PATH . 'admin/install/' . $_SESSION['typ'] . '/datas.php';
     } elseif (is_file(ROOT_PATH . 'admin/install/' . $_SESSION['typ'] . '/datas.sql')) {
         $sqlfiles[] = ROOT_PATH . 'admin/install/' . $_SESSION['typ'] . '/datas.sql';
     }
     $datas_dir = ROOT_PATH . 'admin/install/' . $_SESSION['typ'] . '/datas';
     if (is_dir($datas_dir)) {
         // connect ftp
         $ftp = new ftp($_SESSION['ftp_host'], $_SESSION['ftp_username'], $_SESSION['ftp_password'], $_SESSION['ftp_root'], $_SESSION['ftp_port']);
         // สำเนาข้อมูลตัวอย่าง
         copyDir("{$datas_dir}/", DATA_PATH);
     }
 }
 $dir = ROOT_PATH . "widgets/";
 $f = opendir($dir);
 while (false !== ($text = readdir($f))) {
     if ($text != '.' && $text != '..') {
         if (is_file($dir . $text . '/sql.php')) {
             $sqlfiles[] = $dir . $text . '/sql.php';
         }
         if ($import == 1 && is_file($dir . $text . '/datas.php')) {
             $sqlfiles[] = $dir . $text . '/datas.php';
         }
     }
 }
 closedir($f);
示例#17
0
    private function init_project($project, $repositoryURL)
    {
        if (!file_exists($this->config->projects_root . '/projects/' . $project)) {
            mkdir($this->config->projects_root . '/projects/' . $project, 0755);
        } else {
            display($this->config->projects_root . '/projects/' . $project . ' already exists. Reusing' . "\n");
        }
        if (!file_exists($this->config->projects_root . '/projects/' . $project . '/log/')) {
            mkdir($this->config->projects_root . '/projects/' . $project . '/log/', 0755);
        } else {
            display($this->config->projects_root . '/projects/' . $project . '/log/ already exists. Ignoring' . "\n");
            return null;
        }
        $this->datastore = new Datastore(Config::factory(), Datastore::CREATE);
        if (!file_exists($this->config->projects_root . '/projects/' . $project . '/config.ini')) {
            if ($this->config->symlink === true) {
                $vcs = 'symlink';
            } elseif ($this->config->svn === true) {
                $vcs = 'svn';
            } elseif ($this->config->git === true) {
                $vcs = 'git';
            } elseif ($this->config->copy === true) {
                $vcs = 'copy';
            } elseif ($this->config->bzr === true) {
                $vcs = 'bzr';
            } elseif ($this->config->hg === true) {
                $vcs = 'hg';
            } elseif ($this->config->composer === true) {
                $vcs = 'composer';
            } else {
                $vcs = 'git';
            }
            // default initial config. Found in test project.
            $configIni = <<<INI
phpversion = 7.1

ignore_dirs[] = /test
ignore_dirs[] = /tests
ignore_dirs[] = /Tests
ignore_dirs[] = /Test
ignore_dirs[] = /example
ignore_dirs[] = /examples
ignore_dirs[] = /docs
ignore_dirs[] = /doc
ignore_dirs[] = /tmp
ignore_dirs[] = /version
ignore_dirs[] = /vendor
ignore_dirs[] = /js
ignore_dirs[] = /lang
ignore_dirs[] = /data
ignore_dirs[] = /css
ignore_dirs[] = /cache
ignore_dirs[] = /vendor
ignore_dirs[] = /assets
ignore_dirs[] = /spec
ignore_dirs[] = /sql

file_extensions =

project_name        = "{$project}";
project_url         = "{$repositoryURL}";
project_vcs         = "{$vcs}";
project_description = "";
project_packagist   = "";

INI;
            file_put_contents($this->config->projects_root . '/projects/' . $project . '/config.ini', $configIni);
        } else {
            display($this->config->projects_root . '/projects/' . $project . '/config.ini already exists. Ignoring' . "\n");
        }
        shell_exec('chmod -R g+w ' . $this->config->projects_root . '/projects/' . $project);
        $repositoryDetails = parse_url($repositoryURL);
        $skipFiles = false;
        if (!file_exists($this->config->projects_root . '/projects/' . $project . '/code/')) {
            switch (true) {
                // Symlink
                case $this->config->symlink === true:
                    display('Symlink initialization : ' . realpath($repositoryURL));
                    symlink(realpath($repositoryURL), $this->config->projects_root . '/projects/' . $project . '/code');
                    break 1;
                    // Empty initialization
                // Empty initialization
                case $this->config->copy === true:
                    display('Copy initialization');
                    $total = copyDir(realpath($repositoryURL), $this->config->projects_root . '/projects/' . $project . '/code');
                    display($total . ' files were copied');
                    break 1;
                    // Empty initialization
                // Empty initialization
                case $repositoryURL === '' || $repositoryURL === false:
                    display('Empty initialization');
                    break 1;
                    // composer archive (early in the list, as this won't have 'scheme'
                // composer archive (early in the list, as this won't have 'scheme'
                case $this->config->composer === true:
                    display('Initialization with composer');
                    $res = shell_exec('composer --version');
                    if (strpos($res, 'Composer') === false) {
                        throw new HelperException('Composer');
                    }
                    // composer install
                    $composer = new \stdClass();
                    $composer->require = new \stdClass();
                    $composer->require->{$repositoryURL} = 'dev-master';
                    $json = json_encode($composer);
                    mkdir($this->config->projects_root . '/projects/' . $project . '/code', 0755);
                    file_put_contents($this->config->projects_root . '/projects/' . $project . '/code/composer.json', $json);
                    shell_exec('cd ' . $this->config->projects_root . '/projects/' . $project . '/code; composer -q install');
                    break 1;
                    // SVN
                // SVN
                case isset($repositoryDetails['scheme']) && $repositoryDetails['scheme'] == 'svn' || $this->config->svn === true:
                    $res = shell_exec('svn --version');
                    if (strpos($res, 'svn') === false) {
                        throw new HelperException('SVN');
                    }
                    display('SVN initialization');
                    shell_exec('cd ' . $this->config->projects_root . '/projects/' . $project . '; svn checkout ' . escapeshellarg($repositoryURL) . ' code');
                    break 1;
                    // Bazaar
                // Bazaar
                case $this->config->bzr === true:
                    $res = shell_exec('bzr --version');
                    if (strpos($res, 'Bazaar') === false) {
                        throw new HelperException('Bazar');
                    }
                    display('Bazaar initialization');
                    shell_exec('cd ' . $this->config->projects_root . '/projects/' . $project . '; bzr branch ' . escapeshellarg($repositoryURL) . ' code');
                    break 1;
                    // HG
                // HG
                case $this->config->hg === true:
                    $res = shell_exec('hg --version');
                    if (strpos($res, 'Mercurial') === false) {
                        throw new HelperException('Mercurial');
                    }
                    display('Mercurial initialization');
                    shell_exec('cd ' . $this->config->projects_root . '/projects/' . $project . '; hg clone ' . escapeshellarg($repositoryURL) . ' code');
                    break 1;
                    // Tbz archive
                // Tbz archive
                case $this->config->tbz === true:
                    display('Download the tar.bz2');
                    $binary = file_get_contents($repositoryURL);
                    display('Saving');
                    $archiveFile = tempnam(sys_get_temp_dir(), 'archiveTgz') . '.tgz';
                    file_put_contents($archiveFile, $binary);
                    display('Unarchive');
                    shell_exec('tar -jxf ' . $archiveFile . ' --directory ' . $this->config->projects_root . '/projects/' . $project . '/code/');
                    display('Cleanup');
                    unlink($archiveFile);
                    break 1;
                    // tgz archive
                // tgz archive
                case $this->config->tgz === true:
                    display('Download the tar.gz');
                    $binary = file_get_contents($repositoryURL);
                    display('Saving');
                    $archiveFile = tempnam(sys_get_temp_dir(), 'archiveTgz') . '.tgz';
                    file_put_contents($archiveFile, $binary);
                    display('Unarchive');
                    mkdir($this->config->projects_root . '/projects/' . $project . '/code/');
                    shell_exec('tar -zxf ' . $archiveFile . ' -C ' . $this->config->projects_root . '/projects/' . $project . '/code/');
                    display('Cleanup');
                    unlink($archiveFile);
                    break 1;
                    // zip archive
                // zip archive
                case $this->config->zip === true:
                    $res = shell_exec('zip --version');
                    if (strpos($res, 'Zip') === false) {
                        throw new HelperException('zip');
                    }
                    display('Download the zip');
                    $binary = file_get_contents($repositoryURL);
                    display('Saving');
                    $archiveFile = tempnam(sys_get_temp_dir(), 'archiveZip') . '.zip';
                    file_put_contents($archiveFile, $binary);
                    display('Unzip');
                    shell_exec('unzip ' . $archiveFile . ' -d ' . $this->config->projects_root . '/projects/' . $project . '/code/');
                    display('Cleanup');
                    unlink($archiveFile);
                    break 1;
                    // Git
                    // Git is last, as it will act as a default
                // Git
                // Git is last, as it will act as a default
                case isset($repositoryDetails['scheme']) && $repositoryDetails['scheme'] == 'git' || $this->config->git === true:
                    $res = shell_exec('git --version');
                    if (strpos($res, 'git') === false) {
                        throw new HelperException('git');
                    }
                    display('Git initialization');
                    $res = shell_exec('cd ' . $this->config->projects_root . '/projects/' . $project . '; git clone -q ' . $repositoryURL . ' code 2>&1 ');
                    if (($offset = strpos($res, 'fatal: ')) !== false) {
                        $this->datastore->addRow('hash', array('init error' => trim(substr($res, $offset + 7))));
                        display("An error prevented code initialization : " . trim(substr($res, $offset + 7)) . "\nNo code was loaded.\n");
                        $skipFiles = true;
                    }
                    break 1;
                default:
                    display('No Initialization');
            }
        } elseif (file_exists($this->config->projects_root . '/projects/' . $project . '/code/')) {
            display("Code folder is already there. Leaving it intact.\n");
        }
        display("Counting files\n");
        $this->datastore->addRow('hash', array('status' => 'Initproject'));
        if (!$skipFiles) {
            display("Running files\n");
            $analyze = new Files($this->gremlin, $this->config);
            $analyze->run();
            unset($analyze);
        }
    }
示例#18
0
 public function generate($dirName, $fileName = null)
 {
     if ($fileName === null) {
         return "Can't produce report to stdout\nAborting\n";
     }
     // Clean temporary destination
     if (file_exists($dirName . '/' . $fileName)) {
         rmdirRecursive($dirName . '/' . $fileName);
     }
     $finalName = $fileName;
     $tmpFileName = '.' . $fileName;
     mkdir($dirName . '/' . $tmpFileName, self::FOLDER_PRIVILEGES);
     // Building index.html
     $html = file_get_contents($this->config->dir_root . '/media/faceted2/index.html');
     $html = str_replace('PROJECT_NAME', $this->config->project_name, $html);
     file_put_contents($dirName . '/' . $tmpFileName . '/index.html', $html);
     // Building app.js
     $js = file_get_contents($this->config->dir_root . '/media/faceted2/app.js');
     $json = parent::generate($dirName);
     $js = str_replace('DUMP_JSON', $json, $js);
     $docs = array();
     $analyzes = json_decode($json);
     foreach ($analyzes as $analyze) {
         $ini = parse_ini_file($this->config->dir_root . '/human/en/' . $analyze->analyzer . '.ini');
         $docs[$ini['name']] = $ini['description'];
     }
     $docs = json_encode($docs);
     $js = str_replace('__DOCS__', $docs, $js);
     $json = parent::generate($dirName);
     $js = str_replace('DUMP_JSON', $json, $js);
     print file_put_contents($dirName . '/' . $tmpFileName . '/app.js', $js) . ' octets écrits';
     copyDir($this->config->dir_root . '/media/faceted2/bower_components', $dirName . '/' . $tmpFileName . '/bower_components');
     copyDir($this->config->dir_root . '/media/faceted2/node_modules', $dirName . '/' . $tmpFileName . '/node_modules');
     copy($this->config->dir_root . '/media/faceted2/exakat.css', $dirName . '/' . $tmpFileName . '/exakat.css');
     $css = file_get_contents($this->config->dir_root . '/media/faceted/faceted.css');
     file_put_contents($dirName . '/' . $tmpFileName . '/faceted.css', $css);
     $errors = json_decode($json);
     $docsList = array();
     $filesList = array();
     foreach ($errors as $error) {
         $docsList[$error->analyzer] = $error->error;
         $filesList[$error->file] = $error->line;
     }
     asort($docsList);
     $docsHtml = '<dl>';
     foreach ($docsList as $id => $dl) {
         $ini = parse_ini_file($this->config->dir_root . '/human/en/' . $id . '.ini');
         $description = htmlentities($ini['description'], ENT_COMPAT | ENT_HTML401, 'UTF-8');
         $description = preg_replace_callback('/\\s*(&lt;\\?php.*?\\?&gt;)\\s*/si', function ($r) {
             return '<br />' . highlight_string(html_entity_decode($r[1]), true);
         }, $description);
         $description = nl2br($description);
         $docsHtml .= "<dt id=\"{$id}\">{$dl}</dt>\n        <dd>{$description}</dd>\n";
     }
     $docsHtml .= '</dl>';
     $docs = file_get_contents($this->config->dir_root . '/media/faceted/docs.html');
     $docs = str_replace('DOCS_LIST', $docsHtml, $docs);
     $docs = str_replace('PROJECT_NAME', $this->config->project_name, $docs);
     file_put_contents($dirName . '/' . $tmpFileName . '/docs.html', $docs);
     foreach ($filesList as $path => $line) {
         $dirs = explode('/', $path);
         array_pop($dirs);
         // remove file name
         array_shift($dirs);
         // remove root /
         $d = '';
         foreach ($dirs as $dir) {
             $d .= '/' . $dir;
             if (!file_exists($dirName . '/' . $tmpFileName . $d)) {
                 mkdir($dirName . '/' . $tmpFileName . $d, 0755);
             }
         }
         $php = file_get_contents($dirName . '/code' . $path);
         $html = highlight_string($php, true);
         $html = preg_replace_callback('$<br />$s', function ($r) {
             static $line;
             if (!isset($line)) {
                 $line = 2;
             } else {
                 ++$line;
             }
             return "<br id=\"{$line}\" />{$line}) ";
         }, $html);
         $html = '<code><a id="1" />1) ' . substr($html, 6);
         file_put_contents($dirName . '/' . $tmpFileName . $path . '.html', $html);
     }
     if (file_exists($dirName . '/' . $finalName)) {
         rename($dirName . '/' . $finalName, $dirName . '/.' . $tmpFileName);
         rename($dirName . '/' . $tmpFileName, $dirName . '/' . $finalName);
         // Clean previous folder
         if ($dirName . '/.' . $tmpFileName !== '/') {
             rmdirRecursive($dirName . '/.' . $fileName);
         }
     } else {
         // No previous art, so just move
         rename($dirName . '/' . $tmpFileName, $dirName . '/' . $finalName);
     }
 }
示例#19
0
文件: function.php 项目: sembrono/1
function copyDir($path, $dest)
{
    if (is_dir($path)) {
        @mkdir($dest);
        $objects = scandir($path);
        if (sizeof($objects) > 0) {
            foreach ($objects as $file) {
                if ($file == "." || $file == "..") {
                    continue;
                }
                if (is_dir($path . DIRECTORY_SEPARATOR . $file)) {
                    copyDir($path . DIRECTORY_SEPARATOR . $file, $dest . DIRECTORY_SEPARATOR . $file);
                } else {
                    copy($path . DIRECTORY_SEPARATOR . $file, $dest . DIRECTORY_SEPARATOR . $file);
                }
            }
        }
        return true;
    } elseif (is_file($path)) {
        return copy($path, $dest);
    } else {
        return false;
    }
}
示例#20
0
        move_uploaded_file($_FILES['iconImageFile']['tmp_name'][$i], $dest);
        $size = getimagesize($dest);
        $ret[$i] = array();
        $ret[$i]['options'] = array();
        $ret[$i]['options']['iconUrl'] = $dest;
        $ret[$i]['options']['size'] = array();
        $ret[$i]['options']['size']['x'] = $size[0];
        $ret[$i]['options']['size']['y'] = $size[1];
    }
    echo json_encode($ret, JSON_NUMERIC_CHECK);
}
if ($_POST['req'] == 'setNewProject') {
    if (!file_exists("project/{$_POST['data']['projectId']}")) {
        mkdir("project/{$_POST['data']['projectId']}", "0777", true);
    }
    copyDir("template", "project/{$_POST['data']['projectId']}");
}
if ($_POST['req'] == 'uploadInformImage') {
    $data = $_POST['data'];
    switch ($_FILES['informImgFile']['type']) {
        case 'image/jpeg':
            $ext = 'jpg';
            break;
        case 'image/png':
            $ext = 'png';
            break;
        case 'image/gif':
            $ext = 'gif';
            break;
    }
    $dest = "project/{$data['projectId']}/inform_img/{$data['id']}.{$ext}";
示例#21
0
    public function generate($folder, $name = 'report')
    {
        $finalName = $name;
        $name = '.' . $name;
        if ($name === null) {
            return "Can't produce Devoops format to stdout";
        }
        // Clean final destination
        if ($folder . '/' . $finalName !== '/') {
            rmdirRecursive($folder . '/' . $finalName);
        }
        if (file_exists($folder . '/' . $finalName)) {
            display($folder . '/' . $finalName . " folder was not cleaned. Please, remove it before producing the report. Aborting report\n");
            return;
        }
        // Clean temporary destination
        if (file_exists($folder . '/' . $name)) {
            rmdirRecursive($folder . '/' . $name);
        }
        mkdir($folder . '/' . $name, Devoops::FOLDER_PRIVILEGES);
        mkdir($folder . '/' . $name . '/ajax', Devoops::FOLDER_PRIVILEGES);
        copyDir($this->config->dir_root . '/media/devoops/css', $folder . '/' . $name . '/css');
        copyDir($this->config->dir_root . '/media/devoops/img', $folder . '/' . $name . '/img');
        copyDir($this->config->dir_root . '/media/devoops/js', $folder . '/' . $name . '/js');
        copyDir($this->config->dir_root . '/media/devoops/plugins', $folder . '/' . $name . '/plugins');
        display("Copied media files");
        $this->dump = new \Sqlite3($folder . '/dump.sqlite', SQLITE3_OPEN_READONLY);
        $this->datastore = new \sqlite3($folder . '/datastore.sqlite', \SQLITE3_OPEN_READONLY);
        // Compatibility
        $compatibility = array('Compilation' => 'Compilation');
        foreach ($this->config->other_php_versions as $code) {
            if ($code == 52) {
                continue;
            }
            $version = $code[0] . '.' . substr($code, 1);
            $compatibility['Compatibility ' . $version] = 'Compatibility';
        }
        // Analyze
        $analyze = array();
        //count > 0 AND
        print 'SELECT * FROM resultsCounts WHERE analyzer in ' . $this->themesList . ' ORDER BY id';
        $res = $this->sqlite->query('SELECT * FROM resultsCounts WHERE analyzer in ' . $this->themesList);
        while ($row = $res->fetchArray()) {
            $analyzer = Analyzer::getInstance($row['analyzer']);
            $this->analyzers[$analyzer->getDescription()->getName()] = $analyzer;
            $analyze[$analyzer->getDescription()->getName()] = 'OneAnalyzer';
        }
        uksort($analyze, function ($a, $b) {
            return -strnatcmp($a, $b);
        });
        $analyze = array_merge(array('Results Counts' => 'AnalyzersResultsCounts'), $analyze);
        // Files
        $files = array();
        $res = $this->sqlite->query('SELECT DISTINCT file FROM results ORDER BY file');
        while ($row = $res->fetchArray()) {
            $files[$row['file']] = 'OneFile';
        }
        $files = array_merge(array('Files Counts' => 'FilesResultsCounts'), $files);
        $summary = array('Report presentation' => array('Audit configuration' => 'AuditConfiguration', 'Processed Files' => 'ProcessedFiles', 'Non-processed Files' => 'NonProcessedFiles'), 'Zend Framework' => $analyze);
        $summaryHtml = $this->makeSummary($summary);
        $faviconHtml = '';
        if (file_exists($this->config->dir_root . '/projects/' . $this->config->project . '/code/favicon.ico')) {
            // Should be checked and reported
            copy($this->config->dir_root . '/projects/' . $this->config->project . '/code/favicon.ico', $folder . '/' . $name . '/img/' . $this->config->project . '.ico');
            $faviconHtml = <<<HTML
<img src="img/{$this->config->project}.ico" class="img-circle" alt="{$this->config->project} logo" />
HTML;
            if (!empty($this->config->project_url)) {
                $faviconHtml = "<a href=\"{$this->config->project_url}\" class=\"avatar\">{$faviconHtml}</a>";
            }
            $faviconHtml = <<<HTML
\t\t\t\t<div class="avatar">
\t\t\t\t\t{$faviconHtml}
\t\t\t\t</div>
HTML;
        }
        $html = file_get_contents($this->config->dir_root . '/media/devoops/index.exakat.html');
        $html = str_replace('<menu>', $summaryHtml, $html);
        $html = str_replace('EXAKAT_VERSION', Exakat::VERSION, $html);
        $html = str_replace('EXAKAT_BUILD', Exakat::BUILD, $html);
        $html = str_replace('PROJECT_NAME', $this->config->project_name, $html);
        $html = str_replace('PROJECT_FAVICON', $faviconHtml, $html);
        file_put_contents($folder . '/' . $name . '/index.html', $html);
        foreach ($summary as $titleUp => $section) {
            foreach ($section as $title => $method) {
                if (method_exists($this, $method)) {
                    $html = $this->{$method}($title);
                } else {
                    $html = 'Using default for ' . $title . "\n";
                    display($html);
                }
                $filename = $this->makeFileName($title);
                $html = <<<HTML
<script language="javascript">
if (!document.getElementById("main")) {
    window.location.href = "../index.html#ajax/{$filename}";
}
</script >
<div class="row">
\t<div id="breadcrumb" class="col-xs-12">
\t\t<a href="#" class="show-sidebar">
\t\t\t<i class="fa fa-bars"></i>
\t\t</a>
\t\t<ol class="breadcrumb pull-left">
\t\t\t<li><a href="index.html">Dashboard</a></li>
\t\t\t<li><a href="#ajax/About-This-Report.html">About This Report</a></li>
\t\t</ol>
\t</div>
</div>

<h4 class="page-header">{$title}</h4>
<div class="row">
\t<div class="col-xs-12">
{$html}
    </div>
</div>
HTML;
                file_put_contents($folder . '/' . $name . '/ajax/' . $filename, $html);
            }
        }
        rename($folder . '/' . $name, $folder . '/' . $finalName);
        return '';
    }
示例#22
0
         if ($ftp->is_dir($_SESSION['ftp_root'])) {
             echo '<li class=correct><strong>FTP</strong> <i>เชื่อมต่อสำเร็จ</i></li>';
         } else {
             echo '<li class=incorrect><strong>FTP Root</strong> <em>ไม่ถูกต้อง</em> กรุณาตรวจสอบจากโฮสต์ของคุณ</li>';
         }
     } else {
         echo '<li class=incorrect><strong>FTP</strong> <em>ไม่สามารถใช้งานได้</em></li>';
     }
 }
 if (is_dir(DATA_PATH)) {
     echo '<li>ตรวจสอบโฟลเดอร์ <strong>' . DATA_FOLDER . '</strong></li>';
     ob_flush();
     flush();
     $datas_dir = ROOT_PATH . "{$mmktime}/";
     if (@rename(DATA_PATH, $datas_dir)) {
         copyDir($datas_dir, DATA_PATH);
     }
     gcms::rm_dir($datas_dir);
     echo '<li class=correct>ตรวจสอบโฟลเดอร์ <strong>' . DATA_FOLDER . '</strong> <i>เรียบร้อย</i></li>';
     ob_flush();
     flush();
 }
 $files = array();
 $files[] = ROOT_PATH . 'bin/config.php';
 $files[] = ROOT_PATH . 'bin/vars.php';
 foreach ($files as $file) {
     if (!is_writeable($file)) {
         $ftp->chmod($file, 0646);
     }
     if (is_writeable($file)) {
         echo '<li class=correct>ไฟล์ <strong>' . str_replace(ROOT_PATH, '', $file) . '</strong> <i>สามารถเขียนได้</i></li>';
示例#23
0
        } else {
            $phinxCommand = PHP_BINARY . ' ' . ROOT_PATH . 'Package/robmorgan/phinx/bin/phinx';
        }
        exec($phinxCommand . ' migrate', $return_arr, $return_arr2);
        print_arr($return_arr);
        if (stripos($return_arr[count($return_arr) - 1], 'All Done.') === false) {
            echo colorize(PHP_EOL . PHP_EOL . 'Failed to migrate database, you can try it manually: ', 'WARNING') . colorize('./Package/bin/phinx migrate', 'WARNING') . PHP_EOL;
            // rollback
            exec($phinxCommand . ' rollback', $return_arr, $return_arr2);
            break;
        }
        echo 'Now installing resources...' . PHP_EOL;
        echo 'Deleting old resources...  ' . PHP_EOL;
        echo delDir(ROOT_PATH . 'Public/Resource') ? 'Done.' . PHP_EOL : 'old resources not exist.' . PHP_EOL;
        echo 'Copying resources...' . PHP_EOL;
        copyDir(ROOT_PATH . 'Resource', ROOT_PATH . 'Public/Resource');
        echo colorize('All done~ Cheers! open site: ' . BASE_URL . 'yourdomain.com/', 'NOTE') . PHP_EOL;
        break;
    case 'import-sspanel':
        // TODO: 从 ss-panel 导入用户数据
        break;
    case 'test':
        echo colorize('FAILED!' . PHP_EOL, 'SUCCESS');
        echo colorize('FAILED!' . PHP_EOL, 'FAILURE');
        echo colorize('FAILED!' . PHP_EOL, 'WARNING');
        echo colorize('FAILED!' . PHP_EOL, 'NOTE');
        break;
    default:
        echo 'Unknown command';
}
echo PHP_EOL;
示例#24
0
文件: copy.php 项目: sembrono/1
<div class="big_board"><div class="board_title">批量复制-复制结果</div></div>
<span class="true">■</span>已经复制 <span class="false">■</span>复制异常
HTML;
        $i = 0;
        while ($i < count($_SESSION['path'])) {
            if (preg_match('/[\\/]$/', $_REQUEST['dir']) == false) {
                $todir = $_REQUEST['dir'] . '/' . path2name(_decode($_SESSION['path'][$i]));
            } else {
                $todir = $_REQUEST['dir'] . path2name(_decode($_SESSION['path'][$i]));
            }
            echo <<<HTML
<div class="big_board"><div class="board_title"></div></div>
HTML;
            if (is_dir(_decode($_SESSION['path'][$i])) == true) {
                echo '[dir]';
                if (copyDir(_decode($_SESSION['path'][$i]), $todir)) {
                    echo '<span class="true">' . _decode($_SESSION['path'][$i]) . '</span>';
                } else {
                    echo '<span class="false">' . _decode($_SESSION['path'][$i]) . '</span>';
                }
            }
            if (is_file(_decode($_SESSION['path'][$i])) == true) {
                echo '[file]';
                if (copy(_decode($_SESSION['path'][$i]), $todir)) {
                    echo '<span class="true">' . _decode($_SESSION['path'][$i]) . '</span>';
                } else {
                    echo '<span class="false">' . _decode($_SESSION['path'][$i]) . '</span>';
                }
            }
            $i++;
        }
示例#25
0
function copyDir($src, $dest)
{
    mkdir($dest);
    foreach (scandir($src) as $file) {
        $df = $dest . '/' . $file;
        $sf = $src . '/' . $file;
        if (!is_readable($sf)) {
            continue;
        }
        if (is_dir($sf) && $file != '.' && $file != '..') {
            copyDir($sf, $df);
        } else {
            @copy($sf, $df);
        }
    }
}
示例#26
0
文件: index.php 项目: phannack/GCMS
function copyDir($dir, $todir)
{
    global $ftp;
    $f = opendir($dir);
    $ftp->mkdir($todir, 0755);
    while (false !== ($text = readdir($f))) {
        if (!in_array($text, array('.', '..'))) {
            if (is_dir($dir . $text)) {
                if (!in_array($text, array('cache', 'counter', 'language', '_thumbs'))) {
                    copyDir($dir . $text . '/', $todir . $text . '/');
                }
            } else {
                copy($dir . $text, $todir . $text);
            }
        }
    }
    closedir($f);
}
function processUpdate($url)
{
    // Archive path
    $name = md5($url) . '.zip';
    $update_dir = $dir_base . 'store/updates/';
    $path = JAPPIX_BASE . '/store/updates/' . $name;
    $extract_to = $update_dir . 'jappix/';
    $store_tree = JAPPIX_BASE . '/php/store-tree.php';
    // We must get the archive from the server
    if (!file_exists($path)) {
        echo '<p>» ' . T_("Downloading package...") . '</p>';
        // Open the packages
        $local = fopen($path, 'w');
        $remote = fopen($url, 'r');
        // Could not open a socket?!
        if (!$remote) {
            echo '<p>» ' . T_("Aborted: socket error!") . '</p>';
            // Remove the broken local archive
            unlink($path);
            return false;
        }
        // Read the file
        while (!feof($remote)) {
            // Get the buffer
            $buffer = fread($remote, 1024);
            // Any error?
            if ($buffer == 'Error.') {
                echo '<p>» ' . T_("Aborted: buffer error!") . '</p>';
                // Remove the broken local archive
                unlink($path);
                return false;
            }
            // Write the buffer to the file
            fwrite($local, $buffer);
            // Flush the current buffer
            ob_flush();
            flush();
        }
        // Close the files
        fclose($local);
        fclose($remote);
    }
    // Then, we extract the archive
    echo '<p>» ' . T_("Extracting package...") . '</p>';
    try {
        $zip = new ZipArchive();
        $zip_open = $zip->open($path);
        if ($zip_open === TRUE) {
            $zip->extractTo($update_dir);
            $zip->close();
        } else {
            echo '<p>» ' . T_("Aborted: could not extract the package!") . '</p>';
            // Remove the broken source folder
            removeDir($to_remove);
            return false;
        }
    } catch (Exception $e) {
        echo '<p>» ' . T_("Aborted: could not extract the package!") . '</p>';
        // Remove the broken source folder
        removeDir($to_remove);
        return false;
    }
    // Remove the ./store dir from the source directory
    removeDir($extract_to . 'store/');
    // Then, we remove the Jappix system files
    echo '<p>» ' . T_("Removing current Jappix system files...") . '</p>';
    // Open the general directory
    $dir_base = JAPPIX_BASE . '/';
    $scan = scandir($dir_base);
    // Filter the scan array
    $scan = array_diff($scan, array('.', '..', '.svn', 'store'));
    // Check all the files are writable
    foreach ($scan as $scanned) {
        // Element path
        $scanned_current = $dir_base . $scanned;
        // Element not writable
        if (!is_writable($scanned_current)) {
            // Try to change the element rights
            chmod($scanned_current, 0777);
            // Check it again!
            if (!is_writable($scanned_current)) {
                echo '<p>» ' . T_("Aborted: everything is not writable!") . '</p>';
                return false;
            }
        }
    }
    // Process the files deletion
    foreach ($scan as $current) {
        $to_remove = $dir_base . $current;
        // Remove folders
        if (is_dir($to_remove)) {
            removeDir($to_remove);
        } else {
            unlink($to_remove);
        }
    }
    // Move the extracted files to the base
    copyDir($extract_to, $dir_base);
    // Remove the source directory
    removeDir($extract_to);
    // Regenerates the store tree
    if (file_exists($store_tree)) {
        echo '<p>» ' . T_("Regenerating storage folder tree...") . '</p>';
        // Call the special regeneration script
        include $store_tree;
    }
    // Remove the version package
    unlink($path);
    // The new version is now installed!
    echo '<p>» ' . T_("Jappix is now up to date!") . '</p>';
    return true;
}
示例#28
0
/**
 * Copy all files in directory.
 *
 * @param string $src
 * @param string $des
 * @return int
 */
function copyDir($src, $des)
{
    if (!file_exists($src)) {
        echo "Directory {$src} does not exists!\n";
        return 1;
    }
    $d = basename($src);
    if (!file_exists($des . DIRECTORY_SEPARATOR . $d)) {
        mkdir($des . DIRECTORY_SEPARATOR . $d);
    }
    foreach (new DirectoryIterator($src) as $f) {
        if ($f->isDot()) {
            continue;
        } elseif ($f->isFile()) {
            $sf = $f->getRealPath();
            $b = copy($sf, $des . DIRECTORY_SEPARATOR . $d . DIRECTORY_SEPARATOR . $f->getFilename());
            if (!$b) {
                echo "Copy file {$sf} failed\n";
                return 1;
            }
        } elseif ($f->isDir()) {
            $b = copyDir($f->getRealPath(), $des . DIRECTORY_SEPARATOR . $d);
            if ($b !== 0) {
                return $b;
            }
        }
    }
    return 0;
}