ICErepo v0.8

This commit is contained in:
Matt Pass
2013-06-21 20:17:18 +01:00
parent 5f29c44a9e
commit 761a9f4505
14 changed files with 1215 additions and 199 deletions

1
plugins/ice-repo/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
error-log.txt

View File

@@ -1,4 +1,4 @@
Copyright (C) 2012 Matt Pass
Copyright (C) 2013 Matt Pass
Website: mattpass.com
Email: matt@mattpass.com
Twitter: @mattpass

View File

@@ -15,7 +15,7 @@ Cool huh?
**Current screnshot:**
<img src="http://www.icecoder.net/github/screenshot.jpg" alt="ICErepo screenshot">
<img src="http://www.icecoder.net/images/icerepo.png" alt="ICErepo screenshot">
This lib uses customised & minified versions of these brilliant and time tested repos:
@@ -33,29 +33,15 @@ $ git clone git@github:mattpass/ICErepo
####Step 2: Enter your auth settings
```
Open index.php and enter either your Github oauth token or username & password
Open settings.php and enter either your Github oauth token or username & password
oauth is recommended here, view http://developer.github.com/v3/oauth/ for info
(If using oauth ensure you have repo scope & your app is granted the URL you'll run under)
```
####Step 3: Enter your repo & server dir settings
```
Also in index.php, enter the repo & corresponding server paths
Also in settings.php, enter the repo & corresponding server paths
Enter 'selected' as a 3rd param next to your default repo/server option to autoload that
Finally, set $_SESSION['userLevel'] to be > 0 with your own login system, or simply uncomment line 3
Finally, set $_SESSION['userLevel'] to be > 0 with your own login system
Upload ICErepo, visit in a web browser & enjoy
```
**Dev schedule:**
**v0.8**
Bug testing, refactoring & optimisation
**v0.9**
Alpha testing
**v0.95**
Beta testing
**v1.0**
Version 1 released
```

View File

@@ -1,23 +1,8 @@
<?php
session_start();
if (!$_SESSION['loggedIn']) {
die("Sorry, you need to be logged in to use ICErepo");
}
function strClean($var) {
// returns converted entities where there are HTML entity equivalents
return htmlentities($var, ENT_QUOTES, "UTF-8");
}
function numClean($var) {
// returns a number, whole or decimal or null
return is_numeric($var) ? floatval($var) : false;
}
?>
<?php include("settings.php"); ?>
<!DOCTYPE html>
<html>
<head>
<title>ICErepo v<?php echo $version;?></title>
<title>ICErepo v <?php echo $version;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="lib/base64.js"></script>
<script src="lib/github.js"></script>
@@ -29,24 +14,6 @@ function numClean($var) {
<body>
<?php
// Function to sort given values alphabetically
function alphasort($a, $b) {
return strcmp($a->getPathname(), $b->getPathname());
}
// Class to put forward the values for sorting
class SortingIterator implements IteratorAggregate {
private $iterator = null;
public function __construct(Traversable $iterator, $callback) {
$array = iterator_to_array($iterator);
usort($array, $callback);
$this->iterator = new ArrayIterator($array);
}
public function getIterator() {
return $this->iterator;
}
}
// Get a full list of dirs & files and begin sorting using above class & function
$repoPath = explode("@",strClean($_POST['repo']));
$repo = $repoPath[0];
@@ -55,15 +22,24 @@ $objectList = new SortingIterator(new RecursiveIteratorIterator(new RecursiveDir
// Finally, we have our ordered list, so display
$i=0;
$dirListArray = array();
$dirSHAArray = array();
$dirTypeArray = array();
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$dirListArray = $dirSHAArray = $dirTypeArray = array();
foreach ($objectList as $objectRef) {
$fileFolderName = rtrim(substr($objectRef->getPathname(), strlen($path)),"..");
if ($objectRef->getFilename()!="." && $fileFolderName[strlen($fileFolderName)-1]!="/") {
$fileFolderName = @rtrim(substr(str_replace("\\","/",$objectRef->getPathname()), strlen($path)),"..");
if (!is_dir($path.$fileFolderName)) {
$contents = file_get_contents($path.$fileFolderName);
if (strpos(finfo_file($finfo, $path.$fileFolderName),"text")===0) {
$finfo = "";
// Determine what to do based on mime type
if (function_exists('finfo_open')) {
$finfoMIME = finfo_open(FILEINFO_MIME_TYPE);
$finfo = finfo_file($finfoMIME, $path.$fileFolderName);
finfo_close($finfoMIME);
} else {
$fileExt = explode(" ",pathinfo($path.$fileFolderName, PATHINFO_EXTENSION));
$fileExt = $fileExt[0];
if (array_search($fileExt,array("coffee","css","htm","html","js","less","md","php","py","rb","ruby","txt","xml"))!==false) {$finfo = "text";};
if (array_search($fileExt,array("gif","jpg","jpeg","png"))!==false) {$finfo = "image";};
}
if (strpos($finfo,"text")===0 || strpos($finfo,"empty")!==false) {
$contents = str_replace("\r","",$contents);
};
$store = "blob ".strlen($contents)."\000".$contents;
@@ -74,7 +50,6 @@ foreach ($objectList as $objectRef) {
array_push($dirTypeArray,$type);
}
}
finfo_close($finfo);
?>
<script>
@@ -88,21 +63,18 @@ dirTypeArray = [<?php echo "'".implode("','", $dirTypeArray)."'";?>];
<div id="compareList" class="mainContainer"></div>
<div id="commitPane" class="commitPane">
<b style='font-size: 18px'>COMMIT CHANGES:</b><br><br>
<form name="fcForm" action="file-control.php" target="fileControl" method="POST">
<input type="text" name="title" value="Title..." style="width: 260px; border: 0; background: #f8f8f8; margin-bottom: 10px" onFocus="titleDefault='Title...'; if(this.value==titleDefault) {this.value=''}" onBlur="if(this.value=='') {this.value=titleDefault}"><br>
<textarea name="message" style="width: 260px; height: 180px; border: 0; background: #f8f8f8; margin-bottom: 5px" onFocus="messageDefault='Message...'; if(this.value==messageDefault) {this.value=''}" onBlur="if(this.value=='') {this.value=messageDefault}">Message...</textarea>
<input type="hidden" name="token" value="<?php echo strClean($_POST['token']);?>">
<input type="hidden" name="username" value="<?php echo strClean($_POST['username']);?>">
<input type="hidden" name="password" value="<?php echo strClean($_POST['password']);?>">
<input type="hidden" name="path" value="<?php echo $path; ?>">
<input type="hidden" name="rowID" value="">
<input type="hidden" name="gitRepo" value="<?php echo $repo; ?>">
<input type="hidden" name="repo" value="">
<input type="hidden" name="dir" value="">
<input type="hidden" name="action" value="">
<input type="submit" name="commit" value="Commit changes" onClick="return commitChanges()" style="border: 0; background: #555; color: #fff; cursor: pointer">
</form>
<b style='font-size: 18px'>COMMIT CHANGES:</b><br><br>
<form name="fcForm" action="file-control.php?username=<?php echo $username;?>&password=<?php echo $password;?>" target="fileControl" method="POST">
<input type="text" name="title" value="Title..." style="width: 260px; border: 0; background: #f8f8f8; margin-bottom: 10px" onFocus="titleDefault='Title...'; if(this.value==titleDefault) {this.value=''}" onBlur="if(this.value=='') {this.value=titleDefault}"><br>
<textarea name="message" style="width: 260px; height: 180px; border: 0; background: #f8f8f8; margin-bottom: 5px" onFocus="messageDefault='Message...'; if(this.value==messageDefault) {this.value=''}" onBlur="if(this.value=='') {this.value=messageDefault}">Message...</textarea>
<input type="hidden" name="path" value="<?php echo $path; ?>">
<input type="hidden" name="rowID" value="">
<input type="hidden" name="gitRepo" value="<?php echo $repo; ?>">
<input type="hidden" name="repo" value="">
<input type="hidden" name="dir" value="">
<input type="hidden" name="action" value="">
<input type="submit" name="commit" value="Commit changes" onClick="return commitChanges()" style="border: 0; background: #555; color: #fff; cursor: pointer">
</form>
</div>
<div id="infoPane" class="infoPane"></div>
@@ -110,10 +82,10 @@ dirTypeArray = [<?php echo "'".implode("','", $dirTypeArray)."'";?>];
<script>
top.fcFormAlias = document.fcForm;
var github = new Github(<?php
if ($_POST['token']!="") {
echo '{token: "'.strClean($_POST['token']).'", auth: "oauth"}';
if ($token!="") {
echo '{token: "'.$token.'", auth: "oauth"}';
} else{
echo '{username: "'.strClean($_POST['username']).'", password: "'.strClean($_POST['password']).'", auth: "basic"}';
echo '{username: "'.$username.'", password: "'.$password.'", auth: "basic"}';
}?>);
repoListArray = [];
repoSHAArray = [];

View File

@@ -1,19 +1,6 @@
<?php include("settings.php"); ?>
<?php
session_start();
if (!$_SESSION['loggedIn']) {
die("Sorry, you need to be logged in to use ICErepo");
}
// returns converted entities where there are HTML entity equivalents
function strClean($var) {
return htmlentities($var, ENT_QUOTES, "UTF-8");
}
// returns a number, whole or decimal or null
function numClean($var) {
return is_numeric($var) ? floatval($var) : false;
}
$repoPath = strClean($_POST['repoPath']);
//$repoPath = strClean($_POST['repoPath']);
$gitRepo = strClean($_POST['gitRepo']);
$path = strClean($_POST['path']);
$rowID = strClean($_POST['rowID']);
@@ -44,10 +31,10 @@ $actionArray = explode(",",$action);
fullRepoPath='<?php echo $repo;?>';
gitRepo='<?php echo $gitRepo;?>';
var github = new Github(<?php
if ($_POST['token']!="") {
echo '{token: "'.strClean($_POST['token']).'", auth: "oauth"}';
if ($token!="") {
echo '{token: "'.$token.'", auth: "oauth"}';
} else{
echo '{username: "'.strClean($_POST['username']).'", password: "'.strClean($_POST['password']).'", auth: "basic"}';
echo '{username: "'.$username.'", password: "'.$password.'", auth: "basic"}';
}?>);
repoUser = gitRepo.split('/')[0];
repoName = gitRepo.split('/')[1];
@@ -57,7 +44,7 @@ $actionArray = explode(",",$action);
<?php if ($_POST['action']=="view") {?>
<form name="fcForm">
<textarea name="fileContents"><?php echo htmlentities(file_get_contents($dir)); ?></textarea>
<textarea name="fileContents"><?php echo file_exists($dir) ? htmlentities(file_get_contents($dir)) : ''; ?></textarea>
</form>
<script>
rowID = <?php echo $rowID; ?>;
@@ -67,19 +54,19 @@ $actionArray = explode(",",$action);
window.onLoad = sendData(baseTextName,newTextName);
</script>
<?php } else if (substr($_POST['action'],0,5)=="PULL:") { ?>
<form name="fcForm" action="file-control.php" method="POST">
<?php
echo '<input type="hidden" name="rowID" value="'.$rowID.'">';
echo '<input type="hidden" name="repo" value="'.$repo.'">';
echo '<input type="hidden" name="dir" value="'.$dir.'">';
echo '<input type="hidden" name="action" value="SAVEPULLS:'.$action.'">';
echo '<input type="hidden" name="path" value="'.$path.'">';
for ($i=0;$i<count($rowIDArray);$i++) {
if ($repoArray[$i]!="") {
echo '<textarea name="repoContents'.$rowIDArray[$i].'"></textarea>';
<form name="fcForm" action="file-control.php?username=<?php echo $username;?>&password=<?php echo $password;?>" method="POST">
<?php
echo '<input type="hidden" name="rowID" value="'.$rowID.'">';
echo '<input type="hidden" name="repo" value="'.$repo.'">';
echo '<input type="hidden" name="dir" value="'.$dir.'">';
echo '<input type="hidden" name="action" value="SAVEPULLS:'.$action.'">';
echo '<input type="hidden" name="path" value="'.$path.'">';
for ($i=0;$i<count($rowIDArray);$i++) {
if ($repoArray[$i]!="") {
echo '<textarea name="repoContents'.$rowIDArray[$i].'"></textarea>';
}
}
}
?>
?>
</form>
<script>
rowIDArray = [<?php echo implode(",", $rowIDArray);?>];
@@ -101,7 +88,7 @@ $actionArray = explode(",",$action);
mkdir($path.$relDir, 0755);
}
}
$fh = fopen($path."/".$repoArray[$i], 'w') or die("alert('Sorry, there was a problem pulling ".$repoArray[$i].". Either the file is unavailable on Github or server permissions aren\'t allowing it to be created/updated.');get('blackMask','top').style.display='none';");
$fh = fopen($path."/".$repoArray[$i], 'w') or die("alert('Sorry, there was a problem pulling ".$repoArray[$i].". Either the file is unavailable on Github or server permissions aren\'t allowing it to be created/updated.');get('loadingMask','top').style.display='none';");
fwrite($fh, $_POST['repoContents'.$rowIDArray[$i]]);
fclose($fh);
echo "hideRow(".$rowIDArray[$i].");top.newCount--;";
@@ -115,19 +102,19 @@ $actionArray = explode(",",$action);
}
}
}
echo "get('blackMask','top').style.display = 'none';";
echo "get('loadingMask','top').style.display = 'none';";
?>
</script>
<?php } else { ?>
<form name="fcForm">
<?php
for ($i=0;$i<count($rowIDArray);$i++) {
if ($dirArray[$i]!="") {
echo '<textarea name="fileContents'.$rowIDArray[$i].'">';
echo htmlentities(file_get_contents($dirArray[$i]));
echo '</textarea>';
for ($i=0;$i<count($rowIDArray);$i++) {
if ($dirArray[$i]!="") {
echo '<textarea name="fileContents'.$rowIDArray[$i].'">';
echo htmlentities(file_get_contents($dirArray[$i]));
echo '</textarea>';
}
}
}
?>
</form>
<script>

View File

@@ -9,10 +9,10 @@ dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
font-family: arial, verdana, helvetica, sans-serif;
border: 0px;
margin: 0px;
padding: 0px;
outline: 0px;
border: 0;
margin: 0;
padding: 0;
outline: 0;
font-size: 12px;
vertical-align: top;
}
@@ -25,18 +25,39 @@ textarea, input {font-family: arial, verdana, helvetica, sans-serif; padding: 4p
.mainContainer {position: relative; display: block; width: 900px; padding: 20px}
.blackMask {position: absolute; width: 100%; height: 100%; background: rgba(0,0,0,0.9); z-index: 200}
.loadingMsgCenter {position: absolute; display: inline-block; left: 50%; top: 50%; width: 1px; height: 1px}
.loadingMsgContainer {position: absolute; display: inline-block; left: -30px; top: -7px; width: 60px; height: 14px; background-color: #bbb; color: #222; font-weight: bold; text-align: center; padding: 15px; z-index: 201;
-webkit-box-shadow: 8px 8px 8px 8px rgba(0,0,0,0.4);
-moz-box-shadow: 8px 8px 8px 8px rgba(0,0,0,0.4);
box-shadow: 4px 4px 8px 4px rgba(0,0,0,0.4)}
.blackMask {position: fixed; display: table; width: 100%; height: 100%; top: 0; left: 0; visibility: hidden; background-color: rgba(0,0,0,0.8); text-align: center; z-index: 100}
.blackMask .popupVCenter {#position: absolute; display: table-cell; #top: 50%; vertical-align: middle; text-align: center}
.popupVCenter .popup {#position: relative; #top: -50%; text-align: center; color: #fff; font-size: 10px}
.whiteGlow {box-shadow: 0 0 8px 2px rgba(255,255,255,0.6)}
.circleOutside {background-color: rgba(0,0,0,0); border:5px solid rgba(0,183,229,0.9); opacity:.9; border-top:5px solid rgba(0,0,0,0); border-left:5px solid rgba(0,0,0,0); border-radius:50px; box-shadow: 0 0 35px #2187e7;
width:50px; height:50px; margin:0 auto; -moz-animation:spin .5s infinite linear; -webkit-animation:spin .5s infinite linear;
}
.circleInside {background-color: rgba(0,0,0,0); border:5px solid rgba(0,183,229,0.9); opacity:.9; border-top:5px solid rgba(0,0,0,0); border-left:5px solid rgba(0,0,0,0); border-radius:50px; box-shadow: 0 0 15px #2187e7;
width:30px; height:30px; margin:0 auto; position:relative; top:-50px; -moz-animation:spinoff .5s infinite linear; -webkit-animation:spinoff .5s infinite linear;
}
@-moz-keyframes spin {
0% {-moz-transform:rotate(0deg)}
100% {-moz-transform:rotate(360deg)}
}
@-moz-keyframes spinoff {
0% {-moz-transform:rotate(0deg)}
100% {-moz-transform:rotate(-360deg)}
}
@-webkit-keyframes spin {
0% {-webkit-transform:rotate(0deg)}
100% {-webkit-transform:rotate(360deg)}
}
@-webkit-keyframes spinoff {
0% {-webkit-transform:rotate(0deg)}
100% {-webkit-transform:rotate(-360deg)}
}
.repoFrame {position: absolute; width: 100%; height: 90%; left: 0px; margin-top: 60px}
.row {position: relative; display: inline-block; background: #ccc; color: #000; width: 880px; padding: 10px 7px; margin-bottom: 2px; cursor: pointer; padding-left: 35px}
.row:hover {background: #888; color: #fff}
.row .icon {display: inline-block; width: 16px; height: 16px; margin-right: 7px; background-image:url('../../images/file-folder-icons.png'); background-repeat: no-repeat}
.row .icon {display: inline-block; width: 16px; height: 16px; margin-right: 7px; background-image:url('images/file-folder-icons.png'); background-repeat: no-repeat}
.row .checkbox {position: absolute; display: inline-block; height: 38px; width: 30px; top: -4px; left: 0px}
.rowContent {position: relative; display: none; background: #eee; width: 100%; height: 300px; padding: 7px; margin-bottom: 10px; overflow: auto}
.pullGithub {position: absolute; display: inline-block; top: 7px; left: 822px; padding: 5px; background: #bbb; color: #444; font-size: 10px; cursor: pointer}

View File

@@ -46,7 +46,7 @@ getContent = function(thisRow,path) {
commitChanges = function() {
if(top.selRowArray.length>0) {
if (document.fcForm.title.value!="Title..." && document.fcForm.message.value!="Message...") {
get('blackMask','top').style.display = "block";
get('loadingMask','top').style.display = "table";
top.selRowValue = "";
top.selDirValue = "";
top.selRepoValue = "";
@@ -88,7 +88,7 @@ commitChanges = function() {
}
pullContent = function(thisRow,thisPath,thisRepo,thisAction) {
get('blackMask','top').style.display = "block";
get('loadingMask','top').style.display = "table";
if (thisRow=="selected") {
top.selRowValue = "";
top.selDirValue = "";
@@ -175,8 +175,8 @@ hideRow = function(row) {
}
function diffUsingJS (dirContent,repoContent,baseTextName,newTextName) {
var base = difflib.stringAsLines(dirContent);
var newtxt = difflib.stringAsLines(repoContent);
var base = difflib.stringAsLines(dirContent ? dirContent : '');
var newtxt = difflib.stringAsLines(repoContent ? repoContent : '');
var sm = new difflib.SequenceMatcher(base, newtxt);
var opcodes = sm.get_opcodes();
var diffoutputdiv = get("row"+rowID+"Content","parent");
@@ -201,11 +201,12 @@ function diffUsingJS (dirContent,repoContent,baseTextName,newTextName) {
// Add or Update files...
ffAddOrUpdate = function(row,gitRepo,action) {
repo.write('master', gitRepo, document.fcForm['fileContents'+row].value,parent.document.fcForm.title.value+ '\n\n'+parent.document.fcForm.message.value, function(err) {
if(!err) {
removeFirstArrayItems();
hideRow(row);
top.newCount--;
rowIDArray.length>0 ? startProcess() : get('blackMask','top').style.display = "none";
rowIDArray.length>0 ? startProcess() : get('loadingMask','top').style.display = "none";
} else {
alert('Sorry, there was an error adding '+gitRepo);
}
@@ -218,7 +219,7 @@ ffDelete = function(row,gitRepo,action) {
removeFirstArrayItems();
hideRow(row);
top.deletedCount--;
rowIDArray.length>0 ? startProcess() : get('blackMask','top').style.display = "none";
rowIDArray.length>0 ? startProcess() : get('loadingMask','top').style.display = "none";
} else {
alert('Sorry, there was an error deleting '+gitRepo);
}
@@ -228,7 +229,7 @@ ffDelete = function(row,gitRepo,action) {
startProcess = function() {
if(actionArray[0]=="changed"||actionArray[0]=="new") {
if(actionArray[0]=="changed") {repoLoc = repoArray[0].replace(repoUser+"/"+repoName+"/","")}
if(actionArray[0]=="new") {repoLoc = dirArray[0].replace(top.path,'')}
if(actionArray[0]=="new") {repoLoc = dirArray[0].replace(top.path+"/",'')}
ffAddOrUpdate(rowIDArray[0],repoLoc,actionArray[0]);
}
if(actionArray[0]=="deleted") {
@@ -329,7 +330,7 @@ gitCommand = function(comm,value) {
get('compareList').innerHTML = c+"<br><br>"+n+"<br><br>"+d;
updateInfo();
get('blackMask','top').style.display='none';
get('loadingMask','top').style.display='none';
}
)
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@@ -1,33 +1,8 @@
<?php
session_start();
// $_SESSION['loggedIn'] = true;
if (!$_SESSION['loggedIn']) {
die("Sorry, you need to be logged in to use ICErepo");
}
$docRoot = $_SERVER['DOCUMENT_ROOT'];
$version = "0.7.2";
// AUTHENTICATION
// Can either be done by oauth, or username & password.
// oauth
$token = "";
// Basic
$username = "username";
$password = "password";
// REPOS & SERVER DIRS
// Here you identify the repo location and related path on your server
// (the last param is to identify which dropdown option to select by default).
$repos = array(
"mattpass/dirTree",$docRoot."/dirTree","",
"mattpass/CodeMirror2",$docRoot."/CodeMirror2","selected"
);
?>
<?php include("settings.php"); ?>
<!DOCTYPE html>
<html>
<head>
<title>ICErepo v<?php echo $version;?></title>
<title>ICErepo v <?php echo $version;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="lib/base64.js"></script>
<script src="lib/github.js"></script>
@@ -35,40 +10,61 @@ $repos = array(
<link rel="stylesheet" type="text/css" href="ice-repo.css">
</head>
<body style="margin: 0; overflow: hidden" onLoad="doRepo(get('repos').value)">
<div class="blackMask" id="blackMask" style="display: block">
<div id="loadingMsgCenter" class="loadingMsgCenter">
<div id="loadingMsgContainer" class="loadingMsgContainer">
WORKING...
</div>
</div>
</div>
<?php
if (isset($_GET['sessionLogin'])) {
?>
<div class="header">
<select name="repos" id="repos" onChange="doRepo(this.value)" style="margin: 20px 0 0 20px">
<?php
for ($i=0;$i<count($repos);$i+=3) {
echo '<option id="repo'.($i/3).'" value="'.$repos[$i].'@'.$repos[$i+1].'"';
echo $repos[$i+2]=="selected" ? ' selected' : '';
echo '>'.$repos[$i]."</option>\n";
}
?>
</select>
<div class="pullGithubSel" onClick="pullContent('selected')">Pull selected from Github</div>
<div class="version"><?php echo $version;?></div>
<img src="images/ice-repo.gif" alt="ICErepo" class="logo">
</div>
<form name="showRepo" action="contents.php" target="repo" method="POST">
<input type="hidden" name="token" value="<?php echo $token;?>">
<input type="hidden" name="username" value="<?php echo $username;?>">
<input type="hidden" name="password" value="<?php echo $password;?>">
<input type="hidden" name="repo" value="">
<form name="sessionLogin" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="POST">
<b>Token:</b><br>
<input type="text" name="token">
<br><br>
or:<br><br>
<b>Username:</b><br>
<input type="text" name="username"><br>
<b>Password:</b><br>
<input type="password" name="password"><br>
<input type="submit">
</form>
<iframe id="repo" class="repoFrame" frameborder="0"></iframe>
<?php
} else {
?>
<body style="margin: 0; overflow: hidden" onLoad="doRepo(get('repos').value)">
<div id="loadingMask" class="blackMask" style="visibility: visible" onContextMenu="return false">
<div class="popupVCenter">
<div class="popup">
<div class="circleOutside"></div>
<div class="circleInside"></div>
&nbsp;&nbsp;&nbsp;working...
</div>
</div>
</div>
<div class="header">
<select name="repos" id="repos" onChange="doRepo(this.value)" style="margin: 20px 0 0 20px">
<?php
for ($i=0;$i<count($repos);$i+=3) {
echo '<option id="repo'.($i/3).'" value="'.$repos[$i].'@'.$repos[$i+1].'"';
echo $repos[$i+2]=="selected" ? ' selected' : '';
echo '>'.$repos[$i]."</option>\n";
}
?>
</select>
<div class="pullGithubSel" onClick="pullContent('selected')">Pull selected from Github</div>
<div class="version"><?php echo $version;?></div>
<img src="images/ice-repo.gif" alt="ICErepo" class="logo">
</div>
<form name="showRepo" action="contents.php?username=<?php echo $username;?>&password=<?php echo $password;?>" target="repo" method="POST">
<input type="hidden" name="repo" value="">
</form>
<iframe id="repo" class="repoFrame" frameborder="0"></iframe>
<?php
;};
?>
</body>

File diff suppressed because one or more lines are too long

View File

@@ -8,4 +8,389 @@
// For all details and documentation:
// http://substance.io/michael/github
(function(){var e,t="https://api.github.com";e=window.Github=function(n){function r(e,r,i,s,o){function u(){var e=t+r;return e+(/\?/.test(e)?"&":"?")+(new Date).getTime()}var a=new XMLHttpRequest;o||(a.dataType="json"),a.open(e,u()),a.onreadystatechange=function(){this.readyState==4&&(this.status>=200&&this.status<300||this.status===304?s(null,o?this.responseText:this.responseText?JSON.parse(this.responseText):!0):s({request:this,error:this.status}))},a.setRequestHeader("Accept","application/vnd.github.raw"),a.setRequestHeader("Content-Type","application/json;charset=UTF-8"),(n.auth=="oauth"&&n.token||n.auth=="basic"&&n.username&&n.password)&&a.setRequestHeader("Authorization",n.auth=="oauth"?"token "+n.token:"Basic "+Base64.encode(n.username+":"+n.password)),i?a.send(JSON.stringify(i)):a.send()}e.Repository=function(e){function u(e,t){if(e===o.branch&&o.sha)return t(null,o.sha);i.getRef("heads/"+e,function(n,r){o.branch=e,o.sha=r,t(n,r)})}var t=e.name,n=e.user,i=this,s="/repos/"+n+"/"+t,o={branch:null,sha:null};this.getRef=function(e,t){r("GET",s+"/git/refs/"+e,null,function(e,n){if(e)return t(e);t(null,n.object.sha)})},this.createRef=function(e,t){r("POST",s+"/git/refs",e,t)},this.deleteRef=function(t,n){r("DELETE",s+"/git/refs/"+t,e,n)},this.listBranches=function(e){r("GET",s+"/git/refs/heads",null,function(t,n){if(t)return e(t);e(null,_.map(n,function(e){return _.last(e.ref.split("/"))}))})},this.getBlob=function(e,t){r("GET",s+"/git/blobs/"+e,null,t,"raw")},this.getSha=function(e,t,n){if(t==="")return i.getRef("heads/"+e,n);i.getTree(e+"?recursive=true",function(e,r){var i=_.select(r,function(e){return e.path===t})[0];n(null,i?i.sha:null)})},this.getTree=function(e,t){r("GET",s+"/git/trees/"+e,null,function(e,n){if(e)return t(e);t(null,n.tree)})},this.postBlob=function(e,t){typeof e=="string"&&(e={content:e,encoding:"utf-8"}),r("POST",s+"/git/blobs",e,function(e,n){if(e)return t(e);t(null,n.sha)})},this.updateTree=function(e,t,n,i){var o={base_tree:e,tree:[{path:t,mode:"100644",type:"blob",sha:n}]};r("POST",s+"/git/trees",o,function(e,t){if(e)return i(e);i(null,t.sha)})},this.postTree=function(e,t){r("POST",s+"/git/trees",{tree:e},function(e,n){if(e)return t(e);t(null,n.sha)})},this.commit=function(t,n,i,u){var a={message:i,author:{name:e.username},parents:[t],tree:n};r("POST",s+"/git/commits",a,function(e,t){o.sha=t.sha;if(e)return u(e);u(null,t.sha)})},this.updateHead=function(e,t,n){r("PATCH",s+"/git/refs/heads/"+e,{sha:t},function(e,t){n(e)})},this.show=function(e){r("GET",s,null,e)},this.contents=function(e,t){r("GET",s+"/contents",{path:e},t)},this.fork=function(e){r("POST",s+"/forks",null,e)},this.createPullRequest=function(e,t){r("POST",s+"/pulls",e,t)},this.read=function(e,t,n){i.getSha(e,t,function(e,t){if(!t)return n("not found",null);i.getBlob(t,function(e,r){n(e,r,t)})})},this.remove=function(e,t,n){u(e,function(r,s){i.getTree(s+"?recursive=true",function(r,o){var u=_.reject(o,function(e){return e.path===t});_.each(u,function(e){e.type==="tree"&&delete e.sha}),i.postTree(u,function(r,o){i.commit(s,o,"Deleted "+t,function(t,r){i.updateHead(e,r,function(e){n(e)})})})})})},this.move=function(e,t,n,r){u(e,function(s,o){i.getTree(o+"?recursive=true",function(s,u){_.each(u,function(e){e.path===t&&(e.path=n),e.type==="tree"&&delete e.sha}),i.postTree(u,function(n,s){i.commit(o,s,"Deleted "+t,function(t,n){i.updateHead(e,n,function(e){r(e)})})})})})},this.write=function(e,t,n,r,s){u(e,function(o,u){if(o)return s(o);i.postBlob(n,function(n,o){if(n)return s(n);i.updateTree(u,t,o,function(t,n){if(t)return s(t);i.commit(u,n,r,function(t,n){if(t)return s(t);i.updateHead(e,n,s)})})})})}},e.Gist=function(e){var t=e.id,n=this,i="/gists/"+t;this.read=function(e){r("GET",i,null,function(t,n){e(t,n)})},this.delete=function(e){r("DELETE",i,null,function(t,n){e(t,n)})},this.fork=function(e){r("POST",i+"/fork",null,function(t,n){e(t,n)})},this.update=function(e,t){r("PATCH",i,e,function(e,n){t(e,n)})}},this.getRepo=function(t,n){return new e.Repository({user:t,name:n})}}}).call(this)
(function() {
var Github;
var API_URL = 'https://api.github.com';
Github = window.Github = function(options) {
// HTTP Request Abstraction
// =======
//
// I'm not proud of this and neither should you be if you were responsible for the XMLHttpRequest spec.
function _request(method, path, data, cb, raw) {
function getURL() {
var url = API_URL + path;
return url + ((/\?/).test(url) ? "&" : "?") + (new Date()).getTime();
}
var xhr = new XMLHttpRequest();
if (!raw) {xhr.dataType = "json"}
xhr.open(method, getURL());
xhr.onreadystatechange = function () {
if (this.readyState == 4) {
if (this.status >= 200 && this.status < 300 || this.status === 304) {
cb(null, raw ? this.responseText : this.responseText ? JSON.parse(this.responseText) : true);
} else {
cb({request: this, error: this.status});
}
}
}
xhr.setRequestHeader('Accept','application/vnd.github.raw');
xhr.setRequestHeader('Content-Type','application/json;charset=UTF-8');
if (
(options.auth == 'oauth' && options.token) ||
(options.auth == 'basic' && options.username && options.password)
) {
xhr.setRequestHeader('Authorization',options.auth == 'oauth'
? 'token '+ options.token
: 'Basic ' + Base64.encode(options.username + ':' + options.password)
);
}
data ? xhr.send(JSON.stringify(data)) : xhr.send();
}
// Repository API
// =======
Github.Repository = function(options) {
var repo = options.name;
var user = options.user;
var that = this;
var repoPath = "/repos/" + user + "/" + repo;
var currentTree = {
"branch": null,
"sha": null
};
// Uses the cache if branch has not been changed
// -------
function updateTree(branch, cb) {
if (branch === currentTree.branch && currentTree.sha) return cb(null, currentTree.sha);
that.getRef("heads/"+branch, function(err, sha) {
currentTree.branch = branch;
currentTree.sha = sha;
cb(err, sha);
});
}
// Get a particular reference
// -------
this.getRef = function(ref, cb) {
_request("GET", repoPath + "/git/refs/" + ref, null, function(err, res) {
if (err) return cb(err);
cb(null, res.object.sha);
});
};
// Create a new reference
// --------
//
// {
// "ref": "refs/heads/my-new-branch-name",
// "sha": "827efc6d56897b048c772eb4087f854f46256132"
// }
this.createRef = function(options, cb) {
_request("POST", repoPath + "/git/refs", options, cb);
};
// Delete a reference
// --------
//
// repo.deleteRef('heads/gh-pages')
// repo.deleteRef('tags/v1.0')
this.deleteRef = function(ref, cb) {
_request("DELETE", repoPath + "/git/refs/"+ref, options, cb);
};
// List all branches of a repository
// -------
this.listBranches = function(cb) {
_request("GET", repoPath + "/git/refs/heads", null, function(err, heads) {
if (err) return cb(err);
cb(null, _.map(heads, function(head) { return _.last(head.ref.split('/')); }));
});
};
// Retrieve the contents of a blob
// -------
this.getBlob = function(sha, cb) {
_request("GET", repoPath + "/git/blobs/" + sha, null, cb, 'raw');
};
// For a given file path, get the corresponding sha (blob for files, tree for dirs)
// -------
this.getSha = function(branch, path, cb) {
// Just use head if path is empty
if (path === "") return that.getRef("heads/"+branch, cb);
that.getTree(branch+"?recursive=true", function(err, tree) {
var file = _.select(tree, function(file) {
return file.path === path;
})[0];
cb(null, file ? file.sha : null);
});
};
// Retrieve the tree a commit points to
// -------
this.getTree = function(tree, cb) {
_request("GET", repoPath + "/git/trees/"+tree, null, function(err, res) {
if (err) return cb(err);
cb(null, res.tree);
});
};
// Post a new blob object, getting a blob SHA back
// -------
this.postBlob = function(content, cb) {
if (typeof(content) === "string") {
content = {
"content": content,
"encoding": "utf-8"
};
}
_request("POST", repoPath + "/git/blobs", content, function(err, res) {
if (err) return cb(err);
cb(null, res.sha);
});
};
// Update an existing tree adding a new blob object getting a tree SHA back
// -------
this.updateTree = function(baseTree, path, blob, cb) {
var data = {
"base_tree": baseTree,
"tree": [
{
"path": path,
"mode": "100644",
"type": "blob",
"sha": blob
}
]
};
_request("POST", repoPath + "/git/trees", data, function(err, res) {
if (err) return cb(err);
cb(null, res.sha);
});
};
// Post a new tree object having a file path pointer replaced
// with a new blob SHA getting a tree SHA back
// -------
this.postTree = function(tree, cb) {
_request("POST", repoPath + "/git/trees", { "tree": tree }, function(err, res) {
if (err) return cb(err);
cb(null, res.sha);
});
};
// Create a new commit object with the current commit SHA as the parent
// and the new tree SHA, getting a commit SHA back
// -------
this.commit = function(parent, tree, message, cb) {
var data = {
"message": message,
"author": {
"name": options.username
},
"parents": [
parent
],
"tree": tree
};
_request("POST", repoPath + "/git/commits", data, function(err, res) {
currentTree.sha = res.sha; // update latest commit
if (err) return cb(err);
cb(null, res.sha);
});
};
// Update the reference of your head to point to the new commit SHA
// -------
this.updateHead = function(head, commit, cb) {
_request("PATCH", repoPath + "/git/refs/heads/" + head, { "sha": commit }, function(err, res) {
cb(err);
});
};
// Show repository information
// -------
this.show = function(cb) {
_request("GET", repoPath, null, cb);
};
// Get contents
// --------
this.contents = function(path, cb) {
_request("GET", repoPath + "/contents", { path: path }, cb);
};
// Fork repository
// -------
this.fork = function(cb) {
_request("POST", repoPath + "/forks", null, cb);
};
// Create pull request
// --------
this.createPullRequest = function(options, cb) {
_request("POST", repoPath + "/pulls", options, cb);
};
// Read file at given path
// -------
this.read = function(branch, path, cb) {
that.getSha(branch, path, function(err, sha) {
if (!sha) return cb("not found", null);
that.getBlob(sha, function(err, content) {
cb(err, content, sha);
});
});
};
// Remove a file from the tree
// -------
this.remove = function(branch, path, cb) {
updateTree(branch, function(err, latestCommit) {
that.getTree(latestCommit+"?recursive=true", function(err, tree) {
// Update Tree
var newTree = _.reject(tree, function(ref) { return ref.path === path });
_.each(newTree, function(ref) {
if (ref.type === "tree") delete ref.sha;
});
that.postTree(newTree, function(err, rootTree) {
that.commit(latestCommit, rootTree, 'Deleted '+path , function(err, commit) {
that.updateHead(branch, commit, function(err) {
cb(err);
});
});
});
});
});
};
// Move a file to a new location
// -------
this.move = function(branch, path, newPath, cb) {
updateTree(branch, function(err, latestCommit) {
that.getTree(latestCommit+"?recursive=true", function(err, tree) {
// Update Tree
_.each(tree, function(ref) {
if (ref.path === path) ref.path = newPath;
if (ref.type === "tree") delete ref.sha;
});
that.postTree(tree, function(err, rootTree) {
that.commit(latestCommit, rootTree, 'Deleted '+path , function(err, commit) {
that.updateHead(branch, commit, function(err) {
cb(err);
});
});
});
});
});
};
// Write file contents to a given branch and path
// -------
this.write = function(branch, path, content, message, cb) {
updateTree(branch, function(err, latestCommit) {
if (err) return cb(err);
that.postBlob(content, function(err, blob) {
if (err) return cb(err);
that.updateTree(latestCommit, path, blob, function(err, tree) {
if (err) return cb(err);
that.commit(latestCommit, tree, message, function(err, commit) {
if (err) return cb(err);
that.updateHead(branch, commit, cb);
});
});
});
});
};
};
// Gists API
// =======
Github.Gist = function(options) {
var id = options.id;
var that = this;
var gistPath = "/gists/"+id;
// Read the gist
// --------
this.read = function(cb) {
_request("GET", gistPath, null, function(err, gist) {
cb(err, gist);
});
};
// Delete the gist
// --------
this.delete = function(cb) {
_request("DELETE", gistPath, null, function(err,res) {
cb(err,res);
});
};
// Fork a gist
// --------
this.fork = function(cb) {
_request("POST", gistPath+"/fork", null, function(err,res) {
cb(err,res);
});
};
// Update a gist with the new stuff
// --------
this.update = function(options, cb) {
_request("PATCH", gistPath, options, function(err,res) {
cb(err,res);
});
};
};
// Top Level API
// -------
this.getRepo = function(user, repo) {
return new Github.Repository({user: user, name: repo});
};
};
}).call(this);

1
plugins/ice-repo/php.ini Normal file
View File

@@ -0,0 +1 @@
magic_quotes_gpc = Off

View File

@@ -0,0 +1,121 @@
<?php
// -----------------
// START USER CONFIG
// -----------------
// SYSTEM SETTINGS
// Document root and ICErepo version no:
$docRoot = $_SERVER['DOCUMENT_ROOT'];
$version = "0.8.0";
// AUTHENTICATION
// Can either be done by oauth (recommended), or username & password (less secure)
// oauth
$token = "";
// Basic
$username = "";
$password = "";
// REPOS & SERVER DIRS
// Here you identify the repo location and related path on your server
// (the last param is to identify which dropdown option to select by default).
$repos = array(
"mattpass/dirTree",$docRoot."/TEST2","",
"mattpass/TEST",$docRoot."/TEST","selected"
);
// User level setting. Set at 1 or above to use
$_SESSION['userLevel'] = 10;
// ---------------
// END USER CONFIG
// ---------------
// Don't display, but log all errors
ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__).'/error-log.txt');
error_reporting(-1);
// Set our default timezone and supress warning with @
@date_default_timezone_set(date_default_timezone_get());
// Set a stream context timeout for file reading
$context = stream_context_create(array('http'=>
array(
'timeout' => 60 // secs
)
));
// Start a session if we haven't already
if(!isset($_SESSION)) {@session_start();}
if (!isset($_SESSION['userLevel']) || $_SESSION['userLevel'] < 1) {
die("Sorry, you need to be logged in to use ICErepo");
}
// Set session vars if we're logging in via a session
if (isset($_REQUEST['token']) && $_REQUEST['token']!="") {
$_SESSION['token'] = $_REQUEST['token'];
}
if (isset($_REQUEST['username']) && $_REQUEST['username']!="") {
$_SESSION['username'] = $_REQUEST['username'];
$_SESSION['password'] = $_REQUEST['password'];
}
// Reestablish those session vars in an ongoing way
if (isset($_SESSION['token'])) {
$_SESSION['token'] = $_SESSION['token'];
}
if (isset($_SESSION['username'])) {
$username = $_SESSION['username'] = $_SESSION['username'];
$password = $_SESSION['password'] = $_SESSION['password'];
}
if ($token=="" && $username=="" && !isset($_GET['sessionLogin'])) {
header("Location: ?sessionLogin=true");
}
// returns converted entities where there are HTML entity equivalents
function strClean($var) {
return htmlentities($var, ENT_QUOTES, "UTF-8");
}
// returns a number, whole or decimal or null
function numClean($var) {
return is_numeric($var) ? floatval($var) : false;
}
// Function to sort given values alphabetically
function alphasort($a, $b) {
return strcmp($a->getPathname(), $b->getPathname());
}
// Class to put forward the values for sorting
class SortingIterator implements IteratorAggregate {
private $iterator = null;
public function __construct(Traversable $iterator, $callback) {
$array = iterator_to_array($iterator);
usort($array, $callback);
$this->iterator = new ArrayIterator($array);
}
public function getIterator() {
return $this->iterator;
}
}
// If magic quotes are still on (attempted to switch off in php.ini)
if (get_magic_quotes_gpc ()) {
function stripslashes_deep($value) {
$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
return $value;
}
$_POST = (isset($_POST) && !empty($_POST)) ? array_map('stripslashes_deep', $_POST) : array();
$_GET = (isset($_GET) && !empty($_GET)) ? array_map('stripslashes_deep', $_GET) : array();
$_COOKIE = (isset($_COOKIE) && !empty($_COOKIE)) ? array_map('stripslashes_deep', $_COOKIE) : array();
$_REQUEST = (isset($_REQUEST) && !empty($_REQUEST)) ? array_map('stripslashes_deep', $_REQUEST) : array();
}
?>