use data links for git graph images
authorpk910 <philipp@zoelle1.de>
Sun, 10 Mar 2013 07:00:13 +0000 (08:00 +0100)
committerpk910 <philipp@zoelle1.de>
Sun, 10 Mar 2013 07:00:13 +0000 (08:00 +0100)
htdocs/config.example.php
htdocs/lib/PageClasses.shortlog.class.php
htdocs/lib/graph.class.php
htdocs/templates/default/shortlog.tpl

index 247833f1f8521340f276fe1757af1d5a597edf3e..0755ec8398473defba2ce04f2a1ad149b83c05d6 100644 (file)
@@ -53,6 +53,7 @@ class GitConfig {
        
        /* GIT Graphs */
        const GITGRAPH_ENABLE = true;
+       const GITGRAPH_DATA_URL = true;
        const GITGRAPH_MAX_BRANCHES = 20;
        const GITGRAPH_END_SIZE = 20;
        const GITGRAPH_TILE_SIZE = 20;
index 75573f28abde66f1b9d6cc20eb3e10ecb332f0b9..500167501471ad0053f35763cce2aa9fb6c2296a 100644 (file)
@@ -18,7 +18,7 @@
 
 class shortlog {
        private $project;
-       private $graph_data;
+       private $graph_data, $graph_gen;
        private $first_commit;
        private $have_more = false;
        
@@ -61,7 +61,16 @@ class shortlog {
                                }
                        }
                        $this->graph_data->parse($commits);
-                       $content->set('graph_data', $this->graph_data->get_header_graph());
+                       
+                       $graph = $this->graph_data->get_header_graph();
+                       if(GitConfig::GITGRAPH_DATA_URL) {
+                               $this->graph_gen = new graph_image_generator();
+                               $graph = $this->graph_gen->generate($graph, true);
+                               $graph = base64_encode($graph);
+                               $graph = "data:image/png;base64,".$graph;
+                       } else
+                               $graph = "?e=graph&gd=".$graph;
+                       $content->set('graph_data', $graph);
                }
                
                $commit_counter = 0;
@@ -108,8 +117,16 @@ class shortlog {
                        $entry->set('date', $date_str);
                        $entry->set('age', $age_str);
                }
-               if(GitConfig::GITGRAPH_ENABLE)
-                       $entry->set('graph_data', $this->graph_data->get_graph($commit['id']));
+               if(GitConfig::GITGRAPH_ENABLE) {
+                       $graph = $this->graph_data->get_graph($commit['id']);
+                       if(GitConfig::GITGRAPH_DATA_URL) {
+                               $graph = $this->graph_gen->generate($graph, true);
+                               $graph = base64_encode($graph);
+                               $graph = "data:image/png;base64,".$graph;
+                       } else
+                               $graph = "?e=graph&gd=".$graph;
+                       $entry->set('graph_data', $graph);
+               }
                
                $entry->set('refs', $this->shortlog_commit_refs($this->project, $commit['id']));
                
index 78deef381d341161ca9e988b45e654af1fcf8fb1..0906391d77cdcbb1e92bfc74a8c79b6e18426e07 100644 (file)
@@ -294,14 +294,19 @@ class graph_image_generator {
                );
        }
        
-       public function generate($data) {
+       public function generate($data, $return = false) {
                if(!GitConfig::GITGRAPH_ENABLE)
                        return;
                $data = $this->parse_data($data);
                if(!$data) {
+                       if($return)
+                               return null;
                        header('Content-Type: text/plain');
                        die(base64_decode("ICAgIC0tLS0tLS0tOi0tLS0tLS0tDQogICAgICAgICAgLC0iLC5fX19fX19fIC8NCiAgICAgICAgIC8gKSB8ICAgLC0tLS0nXA0KICAgICAgICAgXC9fX3wuLSINCiAgICAgICAgLl8vL19cXF8NCk5vdCB3aGF0IHlvdSBleHBlY3RlZCwgZWVlaD8="));
                }
+               if($data['header']) {
+                       return $this->display_header($data['data'], $return);
+               }
                
                $count = $data['count'];
                if($count > $this->max_branches)
@@ -314,12 +319,21 @@ class graph_image_generator {
                
                imagecolortransparent($this->image, $transparentIndex);
 
-               header('Content-Type: image/png');
-               imagepng($this->image);
+               if($return) {
+                       ob_start();
+                       imagepng($this->image);
+                       $ret = ob_get_contents();
+                       ob_end_clean();
+               } else {
+                       header('Content-Type: image/png');
+                       imagepng($this->image);
+                       $ret = null;
+               }
                imagedestroy($this->image);
+               return $ret;
        }
        
-       private function display_header($header) {
+       private function display_header($header, $return = false) {
                $header = explode("//",$header);
                $count = $header[0];
                $header = array_slice($header, 1);
@@ -347,12 +361,21 @@ class graph_image_generator {
                        $color = imagecolorallocatealpha($image, $color[0], $color[1], $color[2], 0);
                        imagettftext($image, 8, 28, ($head[0]-1) * $this->size + 10, $this->header_height-2, $color, realpath(dirname(__FILE__)."/../")."/res/arial.ttf", $name);
                }
-               if(!$branches) die();
+               if(!$branches) return null;
                imagecolortransparent($image, $transparentIndex);
-               header('Content-Type: image/png');
-               imagepng($image);
+               
+               if($return) {
+                       ob_start();
+                       imagepng($image);
+                       $ret = ob_get_contents();
+                       ob_end_clean();
+               } else {
+                       header('Content-Type: image/png');
+                       imagepng($image);
+                       $ret = null;
+               }
                imagedestroy($image);
-               die();
+               return $ret;
        }
        
        private function parse_data($data) {
@@ -360,12 +383,16 @@ class graph_image_generator {
                        $data = base64_decode($data);
                if(!preg_match("/^([0-9]+)([abc]{1})([0-9]+)\(([^\)]*)\)([a-z0-9,\|]*)(\(([^\)]*)\)|)/i", $data, $matches)) {
                        if(preg_match("/head:(.*)/i", $data, $matches)) {
-                               $this->display_header(substr($data, strlen("head:")));
+                               $cdata = array();
+                               $cdata['header'] = true;
+                               $cdata['data'] = substr($data, strlen("head:"));
+                               return $cdata;
                        }
                        return null;
                }
                
                $data = array();
+               $data['header'] = false;
                $data['dot'] = array();
                $data['dot']['pos'] = $matches[1];
                $data['dot']['type'] = $matches[2];
index 4ac1724bc1862aba0cb0f5d108cf60441d05594a..bb06636346f2e79187c62a23c880956077ca740d 100644 (file)
@@ -7,7 +7,7 @@
 # [shortlog]
 <table class="shortlog" cellspacing="0" cellpadding="0">
        <tr class="header">
-               <td colspan="2"><img class="graph" src="?e=graph&gd=%graph_data%" /></td>
+               <td colspan="2"><img class="graph" src="%graph_data%" /></td>
                <td valign="bottom"><b>Author</b></td>
                <td valign="bottom"><b>Commit</b></td>
                <td></td>
@@ -17,7 +17,7 @@
 
 # [shortlog_entry]
 <tr class="%class%">
-       <td><img class="graph" src="?e=graph&gd=%graph_data%" /></td>
+       <td><img class="graph" src="%graph_data%" /></td>
        <td title="%date%"><i>%age%</i></td>
        <td class="author"><a title="Search for commits authored by %author%" class="list" href="?p=%project%&a=search&h=%project_head%&s=%author%&st=author">%author%</a></td>
        <td><a class="list subject" href="?p=%project%&a=commit&h=%hash%">%message%</a> %refs%</td>