added small interface
[GITManagedWebpage.git] / GITManagedWebpage.class.php
index 0522cc8ea39ac14b08691be4753000d503ef912a..2a3076f73a5770607bfbd7ed04c70fc689990eb9 100644 (file)
@@ -164,6 +164,14 @@ class GITManagedWebpage {
             $this->error(self::ERROR_CRITICAL, "error cloning git repository.");
             return;
         }
+        
+        $fp = fopen($this->workdir.'.htaccess');
+        fwrite($fp, '
+Order deny,allow
+Deny from all
+');
+        fclose($fp);
+        
         $this->ready = true;
         
         $default_branch = str_replace(array("\r", "\n"), array("", ""), $this->gitcmd("rev-parse", "--abbrev-ref", "HEAD"));
@@ -243,9 +251,8 @@ class GITManagedWebpage {
         if(substr($path, -1) != '/')
             $path .= '/';
         $current_branch = str_replace(array("\r", "\n"), array("", ""), $this->gitcmd("rev-parse", "--abbrev-ref", "HEAD"));
-        if($current_branch != $branch)
-            $this->gitcmd("checkout", $branch);
-        $this->gitcmd("pull");
+        $this->gitcmd("fetch");
+        $this->gitcmd("reset", "--hard", "origin/".$branch);
         $gitret = $this->gitcmd("rev-list", "--max-count=1", $branch);
         preg_match("#([a-z0-9]{40})#", $gitret, $match);
         $newest_version = $match[1];
@@ -302,6 +309,7 @@ class GITManagedWebpage {
             return;
         
         if(!$this->branchExists($branch)) {
+            $this->gitcmd("fetch");
             if(!$this->branchExists('origin/'.$branch))
                 return false;
         }
@@ -326,7 +334,7 @@ class GITManagedWebpage {
         $default_branch = $this->getConfig("defaultbranch");
         $active_branch = $this->getActiveBranch();
         if($active_branch != $default_branch) {
-            if(!($dir = $this->localBranchPath($branch))) {
+            if(!($dir = $this->localBranchPath($active_branch))) {
                 $dir = $this->localBranchPath($active_branch, true);
                 $this->updateBranch($active_branch, $dir, true);
             }
@@ -337,6 +345,124 @@ class GITManagedWebpage {
         }
     }
     
+    public function showMngrWindow() {
+        $html = '<script type="text/javascript" src="http://lib.pk910.de/jquery.min.js"></script>';
+        $html .= '<script type="text/javascript" src="http://lib.pk910.de/jquery-ui/jquery-ui.min.js"></script>';
+        $html .= '<script type="text/javascript" src="http://lib.pk910.de/jquery-migrate.min.js"></script>';
+        $html .= '<script type="text/javascript" src="http://lib.pk910.de/jquery.window/jquery.window.js"></script>';
+        $html .= '<script type="text/javascript" src="http://lib.pk910.de/jquery.cookie/jquery.cookie.js"></script>';
+        $html .= '<link type="text/css" href="http://lib.pk910.de/jquery-ui/jquery-ui.min.css" rel="stylesheet" />';
+        $html .= '<link type="text/css" href="http://lib.pk910.de/jquery.window/css/jquery.window.css" rel="stylesheet" />';
+        
+        $current_branch = $this->getActiveBranch();
+        $current_version = substr($this->getConfig('version_'.$current_branch), 0, 7);
+        $html .= <<<HTML_END
+<div id="gitmanagedwindow" style="display:none;">
+    <table width="100%" class="gitmanaged">
+        <tr>
+            <td colspan="2" align="center">
+                <h2>GITManagedWebpage</h2>
+            </td>
+        </tr>
+        <tr>
+            <td width="150px">current branch:</td>
+            <td>{$current_branch}</td>
+        </tr>
+        <tr>
+            <td>current version:</td>
+            <td>{$current_version}</td>
+        </tr>
+        <tr>
+            <td colspan="2" align="center"><input type="button" value="update branch" class="update"></td>
+        </tr>
+    </table>
+</div>
+
+<script type="text/javascript">
+$.window.prepare({
+   dock: 'right',
+   animationSpeed: 200,
+   minWinLong: 65
+});
+
+var cookie_prefix = 'gitmanaged_';
+var win = $.window({
+    icon: 'http://lib.pk910.de/_ico/git.ico',
+    title: "GIT Managed Webpage",
+    content: $('#gitmanagedwindow').html(),
+    checkBoundary: true,
+    withinBrowserWindow: true,
+    
+    maximizable: false,
+    closable: false,
+    
+    width: 200,
+    height: 150,
+    
+    onMinimize: function(wnd) {
+        $.cookie(cookie_prefix+'minimized', '1');
+    },
+    onCascade: function(wnd) {
+        $.removeCookie(cookie_prefix+'minimized');
+    },
+    afterDrag: function(wnd) {
+        var pos = wnd.getContainer().position();
+        $.cookie(cookie_prefix+'pos', pos.left + ';' + pos.top)
+    },
+});
+
+function updateURLParameter(url, param, paramVal) {
+    var TheAnchor = null;
+    var newAdditionalURL = "";
+    var tempArray = url.split("?");
+    var baseURL = tempArray[0];
+    var additionalURL = tempArray[1];
+    var temp = "";
+    if (additionalURL) {
+        var tmpAnchor = additionalURL.split("#");
+        var TheParams = tmpAnchor[0];
+            TheAnchor = tmpAnchor[1];
+        if(TheAnchor)
+            additionalURL = TheParams;
+        tempArray = additionalURL.split("&");
+        for (i=0; i<tempArray.length; i++) {
+            if(tempArray[i].split('=')[0] != param) {
+                newAdditionalURL += temp + tempArray[i];
+                temp = "&";
+            }
+        }        
+    } else {
+        var tmpAnchor = baseURL.split("#");
+        var TheParams = tmpAnchor[0];
+            TheAnchor  = tmpAnchor[1];
+        if(TheParams)
+            baseURL = TheParams;
+    }
+    if(TheAnchor)
+        paramVal += "#" + TheAnchor;
+    var rows_txt = temp + "" + param + "=" + paramVal;
+    return baseURL + "?" + newAdditionalURL + rows_txt;
+}
+
+var container = win.getContainer();
+container.find('.update').on('click', function() {
+    var url = updateURLParameter(window.location.href, "update", "1");
+    window.location.href = url;
+});
+
+if($.cookie(cookie_prefix+'pos')) {
+    var pos = $.cookie(cookie_prefix+'pos').split(';');
+    container.css("left", pos[0]);
+    container.css("top", pos[1]);
+}
+if($.cookie(cookie_prefix+'minimized'))
+    win.minimize();
+
+</script>
+HTML_END;
+        return $html;
+    }
+    
 }
 
 ?>
\ No newline at end of file