Zionetrix::Git
Repositories
Help
Report an Issue
viewgit-showreadme-plugin
Code
Commits
Branches
Tags
Search
Tree:
0611e97
Branches
Tags
master
viewgit-showreadme-plugin
showreadme
main.php
Initial commit
Benjamin Renard
commited
0611e97
at 2013-08-21 17:20:57
main.php
Blame
History
Raw
<?php /** * Show readme plugin for ViewGit. * * This plugin display project README file content on summary page. * * @author Benjamin Renard <brenard@zionetrix.net> */ class ShowReadmePlugin extends VGPlugin { var $readme_filenames=array( 'README', 'INSTALL', 'README.txt', 'README.md', 'README.rst' ); function __construct() { global $conf; if (isset($conf['readme_filenames']) && is_array($conf['readme_filenames'])) { $this -> readme_filenames = $conf['readme_filenames']; } $this->register_hook('header'); $this->register_hook('summary'); } function hook($type) { if ($type == 'header') { echo "\t<link rel='stylesheet' href='plugins/showreadme/style.css' type='text/css' />\n"; } elseif ($type == 'summary') { global $page; $tree=git_ls_tree($page['project'],'HEAD'); $readme=array(); foreach($tree as $file) { if ($file['type']!="blob") continue; if (in_array($file['name'],$this -> readme_filenames)) { $readme[$file['name']]=fix_encoding(join("\n", run_git($page['project'], "cat-file blob ".$file['hash']))); } } if (!empty($readme)) { $page['readme']=$readme; $this->display_plugin_template('summary', FALSE); } } } }