1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Stephan Dekker <Stephan@SparklingSoftware.com.au> 5 */ 6 7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 8require_once DOKU_PLUGIN.'action.php'; 9require_once(DOKU_PLUGIN.'git/lib/Git.php'); 10 11 12class action_plugin_git_push extends DokuWiki_Action_Plugin { 13 14 var $helper = null; 15 16 function action_plugin_git_push(){ 17 $this->helper =& plugin_load('helper', 'git'); 18 if (is_null($this->helper)) { 19 msg('The GIT plugin could not load its helper class', -1); 20 return false; 21 } 22 } 23 24 function register(&$controller) { 25 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_handle'); 26 } 27 28 function _handle(&$event, $param) { 29 30 if ($_REQUEST['cmd'] === null) return; 31 32 // verify valid values 33 switch (key($_REQUEST['cmd'])) { 34 case 'push' : 35 $this->push(); 36 $this->helper->changeReadOnly(false); 37 $this->redirect(); 38 break; 39 } 40 } 41 42 function redirect() 43 { 44 global $conf; 45 $this->getConf(''); 46 $local_status_page = $conf['plugin']['git']['local_status_page']; 47 48 header( 'Location:doku.php?id='.$local_status_page ); 49 } 50 51 function push() 52 { 53 try { 54 global $conf; 55 $this->getConf(''); 56 57 $git_exe_path = $conf['plugin']['git']['git_exe_path']; 58 $datapath = $conf['savedir']; 59 60 $repo = new GitRepo($datapath); 61 $repo->git_path = $git_exe_path; 62 $result = $repo->push(); 63 } 64 catch(Exception $e) 65 { 66 msg($e->getMessage()); 67 return false; 68 } 69 } 70 71 72 73}