*/ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'admin.php'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_dwcommits extends DokuWiki_Admin_Plugin { private $output = ''; private $submitted = false; private $helper; private $db; private $current_page; function __construct() { $this->helper =& plugin_load('helper', 'dwcommits'); $this->db = $this->helper->_getDB(); $this->helper->set_branches(); $this->helper->set_repros(); //ini_set('display_errors',1); //ini_set('error_reporting',E_ALL); } /** * return some info */ function getInfo(){ return array( 'author' => 'Myron Turner', 'email' => 'turnermm02@shaw.ca', 'date' => '2015-10-01', 'name' => 'admin plugin dwcommits', 'desc' => 'demonstration dwcommits', 'url' => 'http://www.dokuwiki.org/plugin:commits', ); } /** * return sort order for position in admin menu */ function getMenuSort() { return 999; } /** * return a menu prompt for the admin menu * NOT REQUIRED - its better to place $lang['menu'] string in localised string file * only use this function when you need to vary the string returned */ /** * handle user request */ function handle() { if (!isset($_REQUEST['cmd'])) return; // first time - nothing to do $this->output = 'invalid'; $nov_11 = mktime(0,0,0,11,11,2010); $dwc_Divs = array( 'init'=>"dcw_db_update",'update'=>"dcw_db_update", 'fetch'=>"dwc_git_advanced",'merge'=>"dwc_git_advanced",'commit'=>"dwc_git_advanced",'add'=>"dwc_git_advanced", 'status'=>"dcw_update_git", 'pull'=>"dcw_update_git",'remote_url'=>"dcw_update_git", 'branch'=>"dwc_repos_div",'repro'=>"dwc_repos_div", 'info'=>"dwc_info_div", 'query'=>"dwc_query_div", 'prune' =>"dwc_prune_div", 'restore'=>"dwc_prune_div",'prune_del'=>"dwc_prune_div" ); if (!is_array($_REQUEST['cmd'])) return; // verify valid values switch (key($_REQUEST['cmd'])) { case 'init' : $start_timestamp = $this->get_timestamp($_REQUEST['d']); if(!$start_timestamp) $start_timestamp = $nov_11; $rows_done = $this->helper->recreate_table($start_timestamp); $this->output = 'Initialized ' . $rows_done . ' rows'; break; case 'fetch' : case 'merge' : case 'commit' : case 'pull' : case 'branch': case 'remote_url': case 'add': $status = ""; $this->helper->update_commits(key($_REQUEST['cmd'])); $status = $this->helper->get_status_msg(); $this->output = $status; break; case 'update' : $start_timestamp = $this->get_timestamp($_REQUEST['dup']); if(!$start_timestamp){ $start_timestamp = $nov_11; $this->output = 'date set to default'; } $retv = $this->helper->populate($start_timestamp); if(is_array($retv)) { list($num,$recs) = $retv; $this->output = "Records written to database: $num. Records in database: $recs."; } break; case 'status' : $status = ""; if(!$this->helper->get_status()) { $status = $this->helper->get_status_msg(); } else $status = $this->helper->get_status_msg(); $this->output = $status; break; case 'repro': //path switched in helper constructor $this->output = $this->getLang('repro_switched') . ':' . $_REQUEST['dwc__repro']; break; case 'query': list($arr,$q) = $this->helper->select_all(); $this->output = "$q
"; if($arr) { if($_REQUEST['output_type'] == 'plain') { $this->output .= $this->helper->format_result_plain($arr); } else { $this->output .= $this->helper->format_result_table($arr); } } else $this->output .= "no result"; break; case 'set_remote_url': $this->output = $this->helper->set_githubURL($_REQUEST['remote_url_name']); break; case 'prune': $this->output = $this->helper->prune(false); break; case 'prune_del': $this->output = $this->helper->prune(true); break; case 'restore': $this->output = $this->helper->restore_backup(); break; } $this->current_page = $dwc_Divs[key($_REQUEST['cmd'])]; $this->submitted = ""; $this->submitted = $this->current_page . '
' . key($_REQUEST['cmd']) . '
' . print_r($_REQUEST,1) . '
'; } /** * output appropriate html */ function html() { global $ID; $date_str = $this->getConf('default_date'); if(isset($date_str)) { list($month,$day,$year) = explode('-',$date_str); } else { $month ='MM'; $day='DD'; $year='YYY'; } /* Navigation Bar */ ptln('
'); ptln(''); ptln('
' . $this->getLang('sql_opts') . ''); ptln('  ' . $this->getLang('git_opts') . ''); ptln('  ' . $this->getLang('git_advanced_opts') . ''); ptln('  ' . $this->getLang('git_repos') . ''); ptln('  ' . $this->getLang('git_query') . ''); ptln('  ' . $this->getLang('maintenance') . ''); ptln('  ' . $this->getLang('git_info') . ''); ptln('  ' . $this->getLang('btn_close_all') . ''); ptln('
'); ptln('
'); /* Form */ ptln('
'); // output hidden values to ensure dokuwiki will return back to this plugin ptln(' '); ptln(' '); ptln(' '); ptln(' '); /* Initialize Sqlite Database */ ptln('
'); ptln(''); ptln('' . $this->getLang('header_init') .'
'); ptln($this->getLang('explain_init') . '
'); ptln($this->getLang('input_year').'  (yyyy):   '); ptln($this->getLang('input_month').'  (mm):   '); ptln($this->getLang('input_day').'  (dd):   '); ptln('  '); /* Update Sqlite Database */ ptln('

' . $this->getLang('header_update') .'
'); ptln($this->getLang('explain_update') . '
'); ptln($this->getLang('input_year').'  (yyyy):   '); ptln($this->getLang('input_month').'  (mm):   '); ptln($this->getLang('input_day').'  (dd):   '); ptln('  '); ptln('
'); /* Update git */ ptln('
'); ptln(''); ptln(''. $this->getLang('header_git') . ''); ptln('
'); ptln(''); /* Check Git Status */ ptln(''); ptln(''); ptln(''); ptln(''); ptln(''); ptln('
' . $this->getLang('explain_git') . '
  ' . $this->getLang('header_git_status') . '   ' . $this->getLang('header_git_pull') . '
'); /* Get and Set Remote URL */ ptln('' . $this->getLang('header_remote_url') .'
'); ptln($this->getLang('explain_remote_url') . '
'); ptln('  '); ptln('  ' . $this->getLang('remote_url_text') . ' '); ptln('  '); ptln('
'); /* Advanced Git Options */ ptln('
'); ptln(''); ptln('
'); ptln($this->getLang('header_additional')); ptln('
'); ptln(''); /* Fetch */ ptln(''); ptln(''); /* Merge */ ptln(''); /* Add and Commit */ ptln(''); ptln('
'); ptln(' ' . $this->getLang('header_git_fetch') . '  '); ptln(' ' . $this->getLang('header_git_merge')); ptln('  '); ptln(' ' . $this->getLang('header_git_add')); ptln('    '); ptln(' ' . $this->getLang('header_git_commit')); ptln('  
'); ptln('
'); ptln('
'); ptln(''); /* Branches and Repos*/ ptln(''); ptln('' ); ptln('' ); ptln('
'); /* Current Sqlite DB Name */ ptln($this->getLang('current_db') . $this->helper->current_dbname()); ptln('
 '); //Row spacer /*Repos */ ptln('
' . $this->getLang('repo_names') . '   
'); ptln(' '); ptln('
 '); //Row spacer /*Branches */ ptln('
' . $this->getLang('branch_names') . '   
'); ptln(' '); ptln('
'); ptln('
'); /*Query */ ptln('
'); ptln(''); ptln('
'); ptln($this->getLang('header_git_query'). '
'); ptln('
'); ptln(''); ptln(''); ptln('  '); ptln(''); ptln(''); ptln(''); ptln(''); ptln(''); ptln(''); ptln('
' . $this->getLang('q_srch_term') . ' 1   ' . $this->getLang('q_srch_term') . ' 2   ' . $this->getLang('q_srch_type') . '  OR '); ptln('  AND
'. $this->getLang('q_author') .'  '); ptln('  ' . $this->getLang('q_srch_type') . '  OR '); ptln('  AND   '. $this->getLang('q_branch') . '  '); ptln('
' .$this->getLang('q_start_date') .'   ' . $this->getLang('q_end_date') .'   ' . $this->getLang('q_date_fmt') . '  MM-DD-YYYY
' .$this->getLang('q_output') . ':  ' . $this->getLang('q_table')); ptln('  ' . $this->getLang('q_plain')); ptln('        
'); ptln('
'); ptln('
'); ptln(''); ptln('' .$this->getLang('explain_maint') . '

'); echo $this->helper->db_data(); ptln('
'); ptln('   '); ptln('   '); ptln('
'); ptln('
'); /* Info Div */ ptln('
'); ptln('
'); ptln('Database Name: ' . $this->helper->current_dbname() . '
'); ptln('Current Repro: ' . $this->helper->selected_repro() . '
'); ptln('Branch: ' . $this->helper->selected_branch() . '
'); ptln('Remote Url: ' . $this->helper->get_remote_url() . '
'); ptln('
'); $help_file = $this->locale_xhtml('dwc_admin'); $help_file = preg_replace('/~~CLOSE~~/ms','
' . $this->getLang('div_close') .'
',$help_file); echo $help_file; ptln('
'); /* Message Area */ ptln('
'); ptln($this->getLang('header_git_MsgArea')); ptln('
'); ptln(''); ptln($this->getLang('btn_msg_big') .' '); ptln('   '); ptln($this->getLang('btn_msg_small') .' '); ptln('
'); ptln('
'); ptln('
'); ptln('

'.$this->output.'

'); ptln('
'); if($this->submitted) { // ptln($this->submitted); } ptln(''); } function get_timestamp($d) { $dstr = implode(' ',$d); if(preg_match('/[a-zA-Z]/',$dstr)){ msg('Date wasn\'t set:' . $dstr . ' Will be set to default', -1); return false; } if((strlen($d['month']) < 2) || (strlen($d['year']) < 4)||(strlen($d['day']) < 2) ) { msg('Incorrect date format: ' . $dstr .' Will be set to default', -1); } if((strlen($d['month']) + strlen($d['year']) + strlen($d['day']) > 8 ) ) { msg('Incorrect date format: ' . $dstr .' Will be set to default', -1); } return mktime (0,0,0, $d['month'], $d['day'], $d['year']); } }