From 574f4ed4076c84231ec75dc70a9120c553e37374 Mon Sep 17 00:00:00 2001 From: pk910 Date: Sun, 10 Mar 2013 08:00:13 +0100 Subject: [PATCH] use data links for git graph images --- htdocs/config.example.php | 1 + htdocs/lib/PageClasses.shortlog.class.php | 25 +++++++++++-- htdocs/lib/graph.class.php | 45 ++++++++++++++++++----- htdocs/templates/default/shortlog.tpl | 4 +- 4 files changed, 60 insertions(+), 15 deletions(-) diff --git a/htdocs/config.example.php b/htdocs/config.example.php index 247833f..0755ec8 100644 --- a/htdocs/config.example.php +++ b/htdocs/config.example.php @@ -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; diff --git a/htdocs/lib/PageClasses.shortlog.class.php b/htdocs/lib/PageClasses.shortlog.class.php index 75573f2..5001675 100644 --- a/htdocs/lib/PageClasses.shortlog.class.php +++ b/htdocs/lib/PageClasses.shortlog.class.php @@ -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'])); diff --git a/htdocs/lib/graph.class.php b/htdocs/lib/graph.class.php index 78deef3..0906391 100644 --- a/htdocs/lib/graph.class.php +++ b/htdocs/lib/graph.class.php @@ -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]; diff --git a/htdocs/templates/default/shortlog.tpl b/htdocs/templates/default/shortlog.tpl index 4ac1724..bb06636 100644 --- a/htdocs/templates/default/shortlog.tpl +++ b/htdocs/templates/default/shortlog.tpl @@ -7,7 +7,7 @@ # [shortlog] - + @@ -17,7 +17,7 @@ # [shortlog_entry] - + -- 2.20.1
Author Commit
%age% %author% %message% %refs%