2 global $HOME_PAGE_PROVIDERS;
\r
5 $CALL_ME_FUNCTIONS["repoadmin"] = "gwvpmini_RepoCallMe";
6 $HOME_PAGE_PROVIDERS["gitlog"] = "gwvpmini_GitLogProvider";
\r
9 // the home_page_provders bit is an array
\r
11 $MENU_ITEMS["10repos"]["text"] = "Repos";
\r
12 $MENU_ITEMS["10repos"]["link"] = "$BASE_URL/repos";
15 function gwvpmini_RepoCallMe()
\r
18 error_log("in repoadmin callme - err?");
19 error_log(print_r($_REQUEST, true));
\r
20 if(isset($_REQUEST["q"])) {
21 error_log("in repoadmin callme, for Q");
\r
22 $query = $_REQUEST["q"];
\r
23 $qspl = explode("/", $query);
\r
24 if(isset($qspl[0])) {
\r
25 if($qspl[0] == "repos") {
26 error_log("in repos call");
28 if($qspl[1] == "create") {
29 return "gwvpmini_RepoCreate";
31 return "gwvpmini_RepoMainPage";
34 error_log("i got here, where next?");
\r
35 return "gwvpmini_RepoMainPage";
37 } else return false;
\r
46 function gwvpmini_RepoMainPage()
\r
48 gwvpmini_goMainPage("gwvpmini_RepoMainPageBody");
\r
52 function gwvpmini_RepoMainPageBody()
56 if(gwvpmini_isLoggedIn()) {
57 gwvpmini_GitCreateRepoForm();
58 $repos = gwvpmini_GetOwnedRepos($_SESSION["username"]);
60 echo "You currently own no repos<br>";
62 echo "<h2>Your Repos</h2>";
63 echo "<table border=\"1\"><tr><th>Repo Name</th><th>Repo Description</th><th>Last Log</th></tr>";
64 foreach($repos as $repo) {
65 $name = $repo["name"];
66 $desc = $repo["desc"];
67 echo "<tr><td><a href=\"$BASE_URL/view/$name\">$name</a></td><td>$desc</td>";
69 $repo_base = gwvpmini_getConfigVal("repodir");
\r
70 $cmd = "git --git-dir=\"$repo_base/$name.git\" log -1 2>&1";
\r
71 error_log("CMD: $cmd");
\r
83 function gwvpmini_GitLogProvider()
\r
86 * The home page provider will:
\r
87 * 1) show the last 10 commits for every repository - though, excluding private repos
\r
88 * 2) if loged in, show the last commit on any repo's the user owns
\r
90 * So i need a table thats going to list "writes" by user - as in POST writes but only
\r
91 * put that info into the stats (doesnt exist) db if the repo is publically readable
\r
93 * Or... should we instead just list every repo?
\r
98 echo "<h2>Repo Activity</h2>";
99 if(gwvpmini_isLoggedIn()) {
\r
100 $repos = gwvpmini_GetOwnedRepos($_SESSION["username"]);
102 echo "You currently own no repos<br>";
104 echo "<h2>Your Repos</h2>";
105 echo "<table border=\"1\"><tr><th>Repo Name</th><th>Repo Description</th><th>Repo Log</th></tr>";
106 foreach($repos as $repo) {
107 $name = $repo["name"];
108 $desc = $repo["desc"];
109 echo "<tr><td><a href=\"$BASE_URL/view/$name\">$name</a></td><td>$desc</td>";
111 $repo_base = gwvpmini_getConfigVal("repodir");
112 $cmd = "git --git-dir=\"$repo_base/$name.git\" log -1 2>&1";
113 error_log("CMD: $cmd");
123 function gwvpmini_GitCreateRepoForm()
127 echo "<form method=\"post\" action=\"$BASE_URL/repos/create\">";
128 echo "<table border=\"1\">";
129 echo "<tr><th colspan=\"2\">Create Repo</th></tr>";
130 echo "<tr><th>Repo Name</th><td><input type=\"text\" name=\"reponame\"></td></tr>";
131 echo "<tr><th>Repo Description</th><td><input type=\"text\" name=\"repodesc\"></td></tr>";
132 echo "<tr><th>Read Permissions</th><td>";
133 echo "<select name=\"perms\">";
134 echo "<option value=\"perms-public\">Anyone Can Read</option>";
135 echo "<option value=\"perms-registered\">Must be Registered To Read</option>";
136 echo "<option value=\"perms-onlywrite\">Only Writers can Read</option>";
139 echo "<tr><td colspan=\"2\"><input type=\"submit\" name=\"Create\" value=\"Create\"></td></tr>";
144 function gwvpmini_RepoCreate()
149 // TODO: check the stuff out
153 // remove a .git at the end if it was input
154 $_REQUEST["reponame"] = preg_replace("/\.git$/", "", $_REQUEST["reponame"]);
156 // check for valid chars
157 $replcheck = preg_replace("/[a-zA-Z0-9_\-\.]/", "", $_REQUEST["reponame"]);
158 if(strlen($replcheck)>0) {
160 $inputcheckerror = "Repo name contains invalid characters, repos can only contain a-z, A-Z, 0-9, _, - and .";
164 gwvpmini_SendMessage("error", "$inputcheckerror");
\r
165 header("Location: $BASE_URL/repos");
166 } else if(gwvpmini_isLoggedIn()) {
167 //gwvpmini_createGitRepo($name, $ownerid, $desc, $bundle=null, $defaultperms=0)
168 if(gwvpmini_HaveRepo($_REQUEST["reponame"])) {
169 gwvpmini_SendMessage("error", "Repo ".$_REQUEST["reponame"]." already exists");
\r
170 header("Location: $BASE_URL/repos");
172 gwvpmini_createGitRepo($_REQUEST["reponame"], $_SESSION["id"], $_REQUEST["repodesc"], $_REQUEST["perms"]);
173 gwvpmini_SendMessage("info", "Repo ".$_REQUEST["reponame"]." has been created");
174 header("Location: $BASE_URL/repos");
177 gwvpmini_SendMessage("info", "Must be logged in to create repo");
178 header("Location: $BASE_URL/repos");
182 function gwvpmini_HaveRepo($reponame)
184 $repo_base = gwvpmini_getConfigVal("repodir");
186 if(file_exists("$repo_base/$reponame.git")) return true;
190 function gwvpmini_RemoveRepo($rid)
192 $repo_base = gwvpmini_getConfigVal("repodir");
194 $repdet = gwvpmini_getRepo(null, null, $rid);
196 $rname = $repdet["name"];
198 error_log("FROM PANTS:".print_r($repdet,true)." ----------- ".print_r($rname, true));
200 if($repdet != false && $rname != "") {
201 if(file_exists("$repo_base/$rname.git")) {
202 // recursive remove - frightening
203 if(gwvpmini_RecursiveDelete("$repo_base/$rname.git")) {
204 gwvpmini_RemoveRepoDB($rid);
210 function gwvpmini_RecursiveDelete($fpath)
212 error_log("RECURSEDETELE: ".$fpath);
213 if(is_file($fpath)){
\r
214 return @unlink($fpath);
\r
216 elseif(is_dir($fpath)){
\r
217 $scan = glob(rtrim($fpath,'/').'/*');
\r
218 foreach($scan as $index=>$path){
\r
219 gwvpmini_RecursiveDelete($path);
\r
221 return @rmdir($fpath);
\r