Example #1
0
<?php

require_once __DIR__ . "/../ErrorHandler.php";
require_once __DIR__ . "/../json.php";
require_once __DIR__ . "/../auth.php";
require_once __DIR__ . "/../fs/SFile.php";
$prj = $_GET["project"];
$fs = Auth::getFS();
$prjD = (new SFile($fs, Auth::homeDir()))->rel($prj);
$files = $prjD->listFiles();
$j = new Services_JSON();
$vecs = array();
foreach ($files as $file) {
    $vec = array();
    $c = $file->text();
    preg_replace_callback("/[a-zA-Z0-9]+/", function ($a) {
        global $vec;
        //print $a[0]."\n";
        if (!isset($vec[$a[0]])) {
            $vec[$a[0]] = 0;
        }
        $vec[$a[0]]++;
    }, $c);
    $vecs[$file->name()] = $vec;
}
print $j->encode($vecs);
Example #2
0
}
$json = new Services_JSON();
$lessonDir = "/home/lesson_samples/lesson_samples/";
if (!isset($_GET["src"]) || !isset($_GET["dst"])) {
    $res = array();
    foreach ($fs->ls($lessonDir) as $prj) {
        $prj = PathUtil::truncSep($prj);
        //echo "$lessonDir$prj/options.json";
        if ($fs->exists("{$lessonDir}{$prj}/options.json")) {
            array_push($res, $prj);
        }
    }
    print $json->encode($res);
    exit;
}
$dstdir = Auth::homeDir() . $_GET["dst"] . "/";
$srcdir = $lessonDir . $_GET["src"] . "/";
copyFiles($srcdir, $dstdir);
function copyFiles($sd, $dd)
{
    global $fs;
    foreach ($fs->ls($sd) as $fn) {
        $sfp = PathUtil::rel($sd, $fn);
        $dfp = PathUtil::rel($dd, $fn);
        //print "copy $sfp $dfp<BR>\n";
        if ($fs->isDir($sfp)) {
            copyFiles($sfp, $dfp);
        } else {
            $fs->setContent($dfp, $fs->getContent($sfp));
        }
    }