*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); class admin_plugin_farmer_setup extends DokuWiki_Admin_Plugin { /** @var helper_plugin_farmer $helper */ private $helper; /** * @return bool admin only! */ public function forAdminOnly() { return true; } /** * Should carry out any processing required by the plugin. */ public function handle() { global $INPUT; global $ID; if(!$INPUT->bool('farmdir')) return; if(!checkSecurityToken()) return; $this->helper = plugin_load('helper', 'farmer'); $farmdir = trim($INPUT->str('farmdir', '')); if($farmdir[0] !== '/') $farmdir = DOKU_INC . $farmdir; $farmdir = fullpath($farmdir); $errors = array(); if($farmdir === '') { $errors[] = $this->getLang('farmdir_missing'); } elseif($this->helper->isInPath($farmdir, DOKU_INC) !== false) { $errors[] = $this->getLang('farmdir_in_dokuwiki'); } elseif(!io_mkdir_p($farmdir)) { $errors[] = $this->getLang('farmdir_uncreatable'); } elseif(!is_writeable($farmdir)) { $errors[] = $this->getLang('farmdir_unwritable'); } elseif(count(scandir($farmdir)) > 2) { $errors[] = $this->getLang('farmdir_notEmpty'); } if($errors) { foreach($errors as $error) { msg($error, -1); } return; } // create the files $ok = $this->createPreloadPHP(); if($ok && $INPUT->bool('htaccess')) $ok &= $this->createHtaccess(); $ok &= $this->createFarmIni($farmdir); if($ok) { msg($this->getLang('preload creation success'), 1); $link = wl($ID, array('do' => 'admin', 'page' => 'farmer', 'sub' => 'config'), true, '&'); send_redirect($link); } else { msg($this->getLang('preload creation error'), -1); } } /** * Render HTML output, e.g. helpful text and a form */ public function html() { // Is preload.php already enabled? if(file_exists(DOKU_INC . 'inc/preload.php')) { msg($this->getLang('overwrite_preload'), -1); } $form = new \dokuwiki\Form\Form(); $form->addClass('plugin_farmer'); $form->addFieldsetOpen($this->getLang('preloadPHPForm')); $form->addTextInput('farmdir', $this->getLang('farm dir')); $form->addCheckbox('htaccess', $this->getLang('htaccess setup'))->attr('checked', 'checked'); $form->addButton('farmer__submit', $this->getLang('submit'))->attr('type', 'submit'); $form->addFieldsetClose(); echo $form->toHTML(); echo sprintf($this->locale_xhtml('preload'), dirname(DOKU_REL) . '/farm/'); } /** * Creates the preload that loads our farm controller * @return bool true if saving was successful */ protected function createPreloadPHP() { $content = "