1<?php 2/** 3 * Autolink4 plugin for DokuWiki 4 * 5 * @license MIT 6 * @author Eli Fenton 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12/** 13 * 14 */ 15class admin_plugin_autolink4 extends DokuWiki_Admin_Plugin { 16 //public function getInfo() {return '';} 17 18 /** @type helper_plugin_autolink4 */ 19 protected $hlp; 20 21 public function __construct() { 22 /** @type helper_plugin_autolink4 $this ->hlp */ 23 $this->hlp = plugin_load('helper', 'autolink4'); 24 } 25 26 /** 27 * return sort order for position in admin menu 28 */ 29 public function getMenuSort() { 30 return 140; 31 } 32 33 /** 34 * handle user request 35 */ 36 public function handle() { 37 global $INPUT; 38 if ($INPUT->post->has('aldata')) { 39 if (!$this->hlp->saveConfigFile($INPUT->post->str('aldata'))) { 40 msg('Failed to save data', 1); 41 } 42 else { 43 // Break the cache, so that all pages are regenerated. 44 touch(DOKU_CONF."local.php"); 45 } 46 } 47 } 48 49 /** 50 * output appropriate html 51 */ 52 public function html() { 53 global $lang; 54 $config = $this->hlp->loadConfigFile(); 55 56 $lines = preg_split('/\r?\n/', $config); 57 $allTt = 'checked'; 58 $allOnce = 'checked'; 59 foreach ($lines as $line) { 60 if (!preg_match('/^\s*$/', $line)) { 61 if (!preg_match('/^.*,.*,.*,.*\btt\b.*/', $line)) { 62 $allTt = ''; 63 } 64 65 if (!preg_match('/^.*,.*,.*,.*\bonce\b.*/', $line)) { 66 $allOnce = ''; 67 } 68 } 69 } 70 71 echo $this->locale_xhtml('admin_help'); 72 73 if (!plugin_isdisabled('autotooltip') && plugin_load('helper', 'autotooltip')) { 74 echo '<p><label onclick="plugin_autolink4.toggleFlag(this.querySelector(\'input\').checked, \'tt\')">'; 75 echo '<input type="checkbox" name="tooltips" ' . $allTt . '/>'; 76 echo '<span> ' . $lang['enable_all_tooltips'] . '</span></label></p>'; 77 } 78 79 echo '<p><label onclick="plugin_autolink4.toggleFlag(this.querySelector(\'input\').checked, \'once\')">'; 80 echo '<input type="checkbox" name="linkonce" ' . $allOnce . '/>'; 81 echo '<span> ' . $lang['enable_all_once'] . '</span></label></p>'; 82 83 echo '<form action="" method="post" >'; 84 echo '<input type="hidden" name="do" value="admin" />'; 85 echo '<input type="hidden" name="page" value="autolink4" />'; 86 echo '<textarea class="edit plugin-autolink4__admintext" rows="15" cols="80" style="height: 500px; width: 100%" name="aldata">'; 87 echo formtext($config); 88 echo '</textarea><br/><br/>'; 89 echo '<input type="submit" value="' . $lang['btn_save'] . '" class="button" />'; 90 echo '</form>'; 91 } 92} 93