Пример #1
0
 function processAction($action)
 {
     $this->debug("Action: {$action['action']} on {$action['path']}");
     switch ($action['action']) {
         case 'M':
             // modified
         // modified
         case 'A':
             // added.
             /* how to handle moves?? */
             // is it a file or directory?
             if ($this->isDir($action['path'])) {
                 if (!file_exists($this->target . $action['path'])) {
                     require_once 'System.php';
                     System::mkdir(array('-p', $this->target . $action['path']));
                 }
                 return;
             }
             $this->writeFile($this->target . $action['path'], svn_cat($this->repos . $action['path'], $this->rev));
             return;
         case 'D':
             // deleted.
             if (file_exists($this->target . $action['path'])) {
                 require_once 'System.php';
                 System::rm($this->target . $action['path']);
             }
             return;
         case 'R':
             // replaced????
             return;
     }
 }
Пример #2
0
 /**
  * Get content for version
  *
  * Get the contents of the current resource in the specified version.
  *
  * @param string $version 
  * @return string
  */
 public function getVersionedContent($version)
 {
     if (!in_array($version, $this->getVersions(), true)) {
         throw new vcsNoSuchVersionException($this->path, $version);
     }
     if (($content = vcsCache::get($this->path, $version, 'content')) === false) {
         // Execute command
         $content = svn_cat($this->root . $this->path, $version);
         vcsCache::cache($this->path, $version, 'content', $content);
     }
     return $content;
 }
Пример #3
0
		type_cat_free.checked=false;
		alert("fixed");
		n = categorie_fige.length;
		for (i=0; i<n; i++)
			{
				category_id.options.add(categorie_fige[i]);
			}//fin for
	}
}

function test(){	
	alert('mlkjlkjmkj');
}

function valider(){	
	<?php 
$contents = svn_cat($url . '/trunk/French/number_entries_and_references.csv', 0);
// echo $contents;
// alert("Langage selectionné : "+langage_search);
// alert("Version selectionné : "+version_search);
// alert("encoding selectionné : "+categorie_search);
?>
}
alert(lang_id.value);

</script>


	<!--******************************Fin JAVASCRIPT POUR LA RECHERCHE*********************************************!-->
</body>
</html>
Пример #4
0
 function getFile($path, $rev = null)
 {
     return svn_cat($this->mRepoPath . $path, $rev);
 }
Пример #5
0
function update_stats($username)
{
    global $username, $conf_svn_path, $stats, $prefix, $vrijeme_kreiranja, $svn_ignore, $vrijeme_limit, $skip_diff, $file_content_limit;
    //print "AŽURIRAMO...\n";
    // Uzimamo log sa SVNa
    $svn_path = "file://" . $conf_svn_path . "/" . $username . "/";
    $svn_log = svn_log($svn_path, SVN_REVISION_HEAD, $stats['last_update_rev']);
    if (!$svn_log || empty($svn_log)) {
        return;
    }
    foreach ($svn_log as &$entry) {
        $entry['unixtime'] = strtotime($entry['date']);
    }
    usort($svn_log, "svnsort");
    $last_time = $old_time = 0;
    $last_deletion = $last_addition = array("time" => 0);
    foreach ($svn_log as $entry) {
        $stats['last_update_rev'] = $entry['rev'];
        // Jedan entry može obuhvaćati više datoteka
        foreach ($entry['paths'] as $path) {
            //print "Path $path\n"
            // svn_diff funkcija ne radi :(
            /*list($diff, $errors) = svn_diff($svn_path, $rev, $svn_path, $old_rev);
            		if ($diff) {
            			$contents = '';
            			while (!feof($diff)) {
            				$contents .= fread($diff, 8192);
            			}
            			fclose($diff);
            			fclose($errors);
            			$log_zapisi[$old_rev]['diff'] = $contents;
            		}*/
            $filepath = $path['path'];
            if (substr($filepath, 0, strlen($prefix) + 1) !== "{$prefix}/") {
                //print "Greska: nije iz prefixa!\n";
                continue;
            }
            $filepath = substr($filepath, strlen($prefix) + 1);
            $svn_file_path = $svn_path . $filepath;
            // Specijalno procesiranje za login i logout
            if ($filepath == ".login") {
                $ftime = strtotime(svn_cat($svn_file_path, $entry['rev']));
                array_push($stats['global_events'], array("time" => $entry['unixtime'], "real_time" => $ftime, "text" => "login"));
                continue;
            }
            if ($filepath == ".logout") {
                $ftime = strtotime(svn_cat($svn_file_path, $entry['rev']));
                array_push($stats['global_events'], array("time" => $entry['unixtime'], "real_time" => $ftime, "text" => "logout"));
                continue;
            }
            // Ostali eventi
            // Praćenje vremena
            $old_time = $last_time;
            $last_time = $entry['unixtime'];
            // Sjeckamo put na dijelove
            $path_parts = explode("/", $filepath);
            $ignored = false;
            foreach ($path_parts as $part) {
                if (in_array($part, $svn_ignore)) {
                    $ignored = true;
                }
            }
            if ($ignored) {
                continue;
            }
            // Ignorisani putevi
            // Kompajliranje/pokretanje/autotest - event pridružujemo parent folderu
            $compiled = $runned = $tested = false;
            $filename = end($path_parts);
            if ($filename == ".gcc.out") {
                $compiled = true;
                if (count($path_parts) > 1) {
                    array_pop($path_parts);
                    $filepath = substr($filepath, 0, strlen($filepath) - strlen("/.gcc.out"));
                }
            } else {
                if ($filename == "runme" || $filename == ".runme") {
                    $runned = true;
                    if (count($path_parts) > 1) {
                        array_pop($path_parts);
                        $filepath = substr($filepath, 0, strlen($filepath) - strlen($filename) - 1);
                    }
                } else {
                    if ($filename == ".at_result") {
                        $tested = true;
                        if (count($path_parts) > 1) {
                            array_pop($path_parts);
                            $filepath = substr($filepath, 0, strlen($filepath) - strlen("/.at_result"));
                        }
                    } else {
                        if ($path['action'] == "M" || $path['action'] == "R") {
                            $diff = true;
                            foreach ($skip_diff as $cpattern) {
                                if (preg_match($cpattern, $filename)) {
                                    $diff = false;
                                }
                            }
                            if ($diff) {
                                $rev = $entry['rev'];
                                $old_rev = $stats[$filepath]['last_revision'];
                                $scpath = str_replace(" ", "\\ ", $svn_file_path);
                                $scpath = str_replace(")", "\\)", $svn_file_path);
                                $scpath = str_replace("(", "\\(", $svn_file_path);
                                $diff_contents = `svn diff {$scpath}@{$old_rev} {$scpath}@{$rev}`;
                                $diff_result = compressed_diff($diff_contents);
                            }
                        }
                    }
                }
            }
            // Praćenje ukupnog vremena rada
            if ($last_time - $old_time < $vrijeme_limit) {
                $vrijeme_zadatka = $last_time - $old_time;
            } else {
                $vrijeme_zadatka = $vrijeme_limit;
            }
            // ?? ispade da se više isplati raditi sporo?
            //print "$filepath last_time $last_time old_time $old_time vrijeme_zadatka $vrijeme_zadatka\n";
            // Rekurzivno ažuriramo sve nadfoldere
            $subpaths = array();
            foreach ($path_parts as $part) {
                if (!empty($subpaths)) {
                    $part = $subpaths[count($subpaths) - 1] . "/{$part}";
                }
                array_push($subpaths, $part);
            }
            // Kreiramo sve nadfoldere ako ne postoje
            $kreiran = false;
            foreach ($subpaths as $subpath) {
                // Ako nije ranije postojao put, kreiramo ga
                if (!array_key_exists($subpath, $stats)) {
                    $stats[$subpath] = array("total_time" => $vrijeme_kreiranja, "builds" => 0, "builds_succeeded" => 0, "testings" => 0, "last_test_results" => "", "events" => array(), "last_revision" => $entry['rev'], "entries" => array());
                    //print "Kreiram novi node $subpath vrijeme $vrijeme_kreiranja\n";
                    // Akcije vezane za kreiranje finalnog puta
                    if ($subpath == $filepath) {
                        // Da li je ovo rename?
                        $this_folder = substr($subpath, 0, strlen($subpath) - strlen($filename));
                        if ($entry['unixtime'] - $last_deletion['time'] < 3 && $this_folder == $last_deletion['folder'] && $filepath != $last_deletion['filepath']) {
                            // print "-- detektovan rename\n";
                            $delpath = $last_deletion['filepath'];
                            array_pop($stats[$delpath]['events']);
                            // Brišemo event brisanja
                            array_push($stats[$subpath]['events'], array("time" => $entry['unixtime'], "text" => "rename", "filename" => $filename, "old_filename" => $last_deletion['filename'], "old_filepath" => $last_deletion['filepath']));
                            $last_deletion = array("time" => 0);
                        } else {
                            if ($entry['unixtime'] - $last_deletion['time'] < 3 && $filename == $last_deletion['filename'] && $filepath != $last_deletion['filepath']) {
                                // print "-- detektovan move\n";
                                $delpath = $last_deletion['filepath'];
                                array_pop($stats[$delpath]['events']);
                                // Brišemo event brisanja
                                array_push($stats[$subpath]['events'], array("time" => $entry['unixtime'], "text" => "move", "filename" => $filename, "old_filename" => $last_deletion['filename'], "old_filepath" => $last_deletion['filepath']));
                                $last_deletion = array("time" => 0);
                            } else {
                                // Nije rename
                                $text = "created";
                                $scpath = str_replace(" ", "%20", $svn_file_path);
                                $content = @svn_cat($scpath, $entry['rev']);
                                $lastError = error_get_last();
                                if (strstr($lastError['message'], "refers to a directory")) {
                                    // print "Ovo je direktorij\n";
                                    $text = "created_folder";
                                } else {
                                    if (strstr($lastError['message'], "File not found") || strstr($lastError['message'], "Unable to find repository")) {
                                        // Funkcija svn_cat nekad radi nekad ne radi :( neobjašnjivo
                                        $scpath = str_replace(" ", "\\ ", $svn_file_path);
                                        $cmd = "svn cat {$scpath}@" . $entry['rev'] . " 2>&1";
                                        $content = `{$cmd}`;
                                        if (strstr($content, "refers to a directory")) {
                                            $text = "created_folder";
                                        }
                                    } else {
                                        if (!strstr($lastError['message'], "Undefined variable: undef_var")) {
                                            print "Neka nova greška: " . $lastError['message'] . "\n";
                                        }
                                    }
                                }
                                // Resetovanje PHP grešaka
                                set_error_handler('var_dump', 0);
                                @$undef_var;
                                restore_error_handler();
                                // Detekcija binarne datoteke preko magic-a
                                if (substr($content, 1, 3) == "ELF") {
                                    $content = "binary";
                                }
                                // Fajlovi čiji sadržaj ne uzimamo
                                $skip_content = false;
                                foreach ($skip_diff as $cpattern) {
                                    if (preg_match($cpattern, $filename)) {
                                        $skip_content = true;
                                    }
                                }
                                if ($skip_content) {
                                    $content = "binary";
                                }
                                // Skraćujemo datoteke >100k
                                if (strlen($content) > $file_content_limit) {
                                    $content = substr($content, 0, 100000) . "...";
                                }
                                // Dodajemo evenet
                                array_push($stats[$subpath]['events'], array("time" => $entry['unixtime'], "text" => $text, "filename" => $filename, "content" => $content));
                                $kreiran = true;
                                // Ako je u pitanju kreiranje finalnog puta, nećemo povećavati vrijeme svih nadfoldera
                                // Ovo se nažalost mora uraditi ovako jer su folderi složeni od viših ka nižim jer je to
                                // prirodan redoslijed kreiranja (ako nisu postojali ranije)
                                foreach ($subpaths as $subpath2) {
                                    if ($stats[$subpath2]['total_time'] > $vrijeme_kreiranja && $stats[$subpath2]['total_time'] > $vrijeme_zadatka) {
                                        $stats[$subpath2]['total_time'] -= $vrijeme_zadatka;
                                        //print "Smanjujem vrijeme za $subpath2 za $vrijeme_zadatka\n";
                                    }
                                }
                                // Praćenje move/rename akcija
                                $foulder = substr($filepath, 0, strlen($filepath) - strlen($filename));
                                $last_addition = array("time" => $entry['unixtime'], "filepath" => $filepath, "filename" => $filename, "folder" => $foulder);
                            }
                        }
                    } else {
                        // Nadfolder
                        array_push($stats[$subpath]['events'], array("time" => $entry['unixtime'], "text" => "created", "filename" => $filename));
                    }
                    $kreiran = true;
                } else {
                    $stats[$subpath]['total_time'] += $vrijeme_zadatka;
                    //print "Povećavam vrijeme za $subpath za $vrijeme_zadatka\n";
                }
            }
            // Ažuriramo entries
            $previous = "";
            foreach (array_reverse($subpaths) as $subpath) {
                if ($previous != "") {
                    if (!in_array($previous, $stats[$subpath]['entries'])) {
                        array_push($stats[$subpath]['entries'], $previous);
                    }
                }
                $previous = $subpath;
            }
            // Dodajemo event na stavku
            end($stats[$filepath]['events']);
            $lastk = key($stats[$filepath]['events']);
            $last_event =& $stats[$filepath]['events'][$lastk];
            $stats[$filepath]['last_revision'] = $entry['rev'];
            // Brisanje
            if ($path['action'] == "D") {
                if ($entry['unixtime'] - $last_addition['time'] < 3 && $this_folder == $last_addition['folder'] && $filepath != $last_addition['filepath']) {
                    // Rename
                    end($stats[$last_addition['filepath']]['events']);
                    $lastk = key($stats[$last_addition['filepath']]['events']);
                    $last_event =& $stats[$last_addition['filepath']]['events'][$lastk];
                    $addpath = $last_addition['filepath'];
                    $last_event['text'] = "rename";
                    $last_event['old_filename'] = $filename;
                    $last_event['old_filepath'] = $filepath;
                    $last_addition = array("time" => 0);
                } elseif ($entry['unixtime'] - $last_addition['time'] < 3 && $filename == $last_addition['filename'] && $filepath != $last_addition['filepath']) {
                    // Move
                    end($stats[$last_addition['filepath']]['events']);
                    $lastk = key($stats[$last_addition['filepath']]['events']);
                    $last_event =& $stats[$last_addition['filepath']]['events'][$lastk];
                    $addpath = $last_addition['filepath'];
                    $last_event['text'] = "move";
                    $last_event['old_path'] = $filepath;
                    $last_addition = array("time" => 0);
                } else {
                    // Fajl obrisan
                    array_push($stats[$filepath]['events'], array("time" => $entry['unixtime'], "text" => "deleted"));
                    $foulder = substr($filepath, 0, strlen($filepath) - strlen($filename));
                    $last_deletion = array("time" => $entry['unixtime'], "filepath" => $filepath, "filename" => $filename, "folder" => $foulder);
                }
                // Kompajliranje
            } else {
                if ($compiled) {
                    $stats[$filepath]['builds']++;
                    if ($last_event['text'] == "compiled successfully" && abs($last_event['time'] - $entry['unixtime']) < 3) {
                        // Samo ćemo dodati izlaz kompajlera na runme
                        $scpath = str_replace(" ", "%20", $svn_file_path);
                        $last_event['output'] = svn_cat($scpath, $entry['rev']);
                        // print "Rev: ".$entry['rev']." OUTPUT:\n".$last_event['output']."\n";
                    } else {
                        // Za sada ne znamo da li je uspješno pokrenut program
                        $scpath = str_replace(" ", "%20", $svn_file_path);
                        $output = svn_cat($scpath, $entry['rev']);
                        array_push($stats[$filepath]['events'], array("time" => $entry['unixtime'], "text" => "compiled", "output" => $output, "rev" => $entry['rev']));
                    }
                    // Uspješno kompajliranje
                } else {
                    if ($runned) {
                        $stats[$filepath]['builds_succeeded']++;
                        if ($last_event['text'] == "compiled" && abs($last_event['time'] - $entry['unixtime']) < 3) {
                            // Ako već postoji gcc output, samo ćemo označiti da je uspješno
                            $last_event['text'] = "compiled successfully";
                        } else {
                            array_push($stats[$filepath]['events'], array("time" => $entry['unixtime'], "text" => "compiled successfully", "rev" => $entry['rev']));
                        }
                        // Pokrenut buildservice za autotestove
                    } else {
                        if ($tested) {
                            $stats[$filepath]['testings']++;
                            // Rezultati testiranja
                            $scpath = str_replace(" ", "%20", $svn_file_path);
                            $rezultati_testova = json_decode(svn_cat($scpath, $entry['rev']), true);
                            $svn_test_path = $svn_path . $filepath . "/.autotest";
                            $scpath = str_replace(" ", "%20", $svn_test_path);
                            $testovi = json_decode(svn_cat($scpath, $entry['rev']), true);
                            $ukupno_testova = count($testovi['test_specifications']);
                            $uspjesnih_testova = 0;
                            foreach ($rezultati_testova['test_results'] as $test) {
                                if ($test['status'] == 1) {
                                    $uspjesnih_testova++;
                                }
                            }
                            $stats[$filepath]['last_test_results'] = "{$uspjesnih_testova}/{$ukupno_testova}";
                            array_push($stats[$filepath]['events'], array("time" => $entry['unixtime'], "text" => "ran tests", "test_results" => "{$uspjesnih_testova}/{$ukupno_testova}"));
                            // Izmjena fajla
                        } else {
                            if ($path['action'] != "A") {
                                array_push($stats[$filepath]['events'], array("time" => $entry['unixtime'], "text" => "modified", "diff" => $diff_result));
                                // SVN je registrovao kreiranje za put koji već imamo u statistici - dodajemo event "created"
                            } else {
                                if (!$kreiran) {
                                    array_push($stats[$filepath]['events'], array("time" => $entry['unixtime'], "text" => "created", "filename" => $filename));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Пример #6
0
function pwi_editor($username, $cur_path, $editable)
{
    global $conf_base_path;
    $svn_user_path = setup_paths($username)['svn'];
    $content = "";
    $ace_mode = "c_cpp";
    // fixme
    $isdir = `sudo {$conf_base_path}/bin/wsaccess {$username} isdir "{$cur_path}"`;
    if (isset($_REQUEST['svn_rev'])) {
        $rev = intval($_REQUEST['svn_rev']);
        $svn_file_path = "file://" . $svn_user_path . "/{$cur_path}";
        $content = htmlspecialchars(svn_cat($svn_file_path, $rev));
    } else {
        if (isset($_REQUEST['git_rev'])) {
            $rev = $_REQUEST['git_rev'];
            $content = htmlspecialchars(`sudo {$conf_base_path}/bin/wsaccess {$username} git-show "{$cur_path}" "{$rev}"`);
        } else {
            if ($isdir != 1) {
                $content = htmlspecialchars(`sudo {$conf_base_path}/bin/wsaccess {$username} read "{$cur_path}"`);
            }
        }
    }
    ?>
	<div id="editor"><?php 
    echo $content;
    ?>
</div>
	<div id="status"></div>

	<script src="https://zamger.etf.unsa.ba/js/ace/ace.js" type="text/javascript" charset="utf-8"></script>
	<script>
	    var editor = ace.edit("editor");
	    //editor.setTheme("ace/theme/monokai");
	    editor.getSession().setMode("ace/mode/<?php 
    echo $ace_mode;
    ?>
");

	    console.log(window.innerHeight);
	    console.log(document.getElementById('editor').style.top); // Zašto ne radi???
	    console.log(document.getElementById('phpwebide_tree').clientHeight);
	    var newbottom = window.innerHeight - 220 - document.getElementById('phpwebide_tree').clientHeight;
	    console.log(newbottom);
	    newbottom = "" + newbottom;
	    newbottom = newbottom + "px";
    	    document.getElementById('editor').style.bottom = newbottom;

	    
	    editor.focus();
	    

	<?php 
    if (!$editable) {
        ?>
		editor.setOptions({
			readOnly: true,
			highlightActiveLine: false,
			highlightGutterLine: false
		})
		editor.renderer.$cursorLayer.element.style.opacity=0
		editor.textInput.getElement().tabIndex=-1
		editor.commands.commmandKeyBinding={}
		<?php 
    } else {
        ?>

	    editor.getSession().on("change", scheduleSave);

	    var timeout, has_timeout=0;


	    function scheduleSave(e) {
	    	//alert("hello");
	    	if (has_timeout) clearTimeout(timeout);
	    	timeout = setTimeout('doSave()', 5000);
	    	has_timeout = 1;
	    }

	    function doSave() {
	    	has_timeout = 0;
			var mypostrequest=new ajaxRequest()
			mypostrequest.onreadystatechange=function() {
				if (mypostrequest.readyState==4){
					if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
						var xmldata=mypostrequest.responseText; //retrieve result as an text
						if (xmldata.indexOf("GRESKA") > -1)
							document.getElementById('status').innerHTML = xmldata; //"Greška pri snimanju A";
						else
							document.getElementById('status').innerHTML = "Program snimljen";
					}
					else {
						document.getElementById('status').innerHTML = "Greška pri snimanju B";
					}
				}
			}
			var editor = ace.edit("editor");
			var code = encodeURIComponent(editor.getSession().getValue())

			var sta = encodeURIComponent('<?php 
        echo $_REQUEST['sta'];
        ?>
');
			var akcija = encodeURIComponent("slanje");
			var student = encodeURIComponent(<?php 
        echo $student;
        ?>
);
			var zadaca = encodeURIComponent(<?php 
        echo $zadaca;
        ?>
);
			var zadatak = encodeURIComponent(<?php 
        echo $zadatak;
        ?>
);
			var projekat = encodeURIComponent(<?php 
        echo $projekat;
        ?>
);

			var parameters="sta="+sta+"&akcija="+akcija+"&student="+student+"&zadaca="+zadaca+"&zadatak="+zadatak+"&projekat="+projekat+"&code="+code;
			mypostrequest.open("POST", "index.php", true)
			mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
			mypostrequest.send(parameters)
	    }

	    function ajaxRequest() {
			var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
			if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
				for (var i=0; i<activexmodes.length; i++){
					try{
						return new ActiveXObject(activexmodes[i])
					}
					catch(e){
					//suppress error
					}
				}
			}
			else if (window.XMLHttpRequest) // if Mozilla, Safari etc
				return new XMLHttpRequest()
			else
				return false
		}
	<?php 
    }
    print "</script>\n";
}
Пример #7
0
 function checkSyntax()
 {
     $ret = '';
     $ar = $this->log;
     foreach ($ar[0]['paths'] as $action) {
         if (!in_array($action['action'], array('M', 'A'))) {
             continue;
         }
         if (!preg_match('#\\.php$#', $action['path'])) {
             continue;
         }
         $tmp = ini_get('session.save_path') . '/' . uniqid('tmp_php.') . '.php';
         $this->writeFile($tmp, svn_cat($this->repos . $action['path'], $this->rev));
         $data = $data = `/usr/bin/php -l {$tmp}`;
         unlink($tmp);
         if (preg_match('/^No syntax errors/', $data)) {
             continue;
         }
         $ret .= "Error in {$action['path']}\n" . $data;
     }
     return strlen($ret) ? $ret : false;
 }
Пример #8
0
 public function get_file($file)
 {
     return @svn_cat($file);
 }
Пример #9
0
 protected function svnCat($svnUri, $revision = SVN_REVISION_HEAD)
 {
     return svn_cat($svnUri, $revision);
 }