*/ if(!defined('DOKU_INC')) die(); define('REPLACE_DIR', DOKU_INC . 'data/meta/macros/'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_textinsert extends DokuWiki_Admin_Plugin { var $output = false; var $macros_file; var $macros_data; //used for html listings /** * handle user request */ function __construct() { if(!$this->getConf('farm')) { define('MACROS_FILE', REPLACE_DIR . 'macros.ser'); } else { define('MACROS_FILE', metaFN('macros','.ser')); } } function handle() { $this->macros_file=MACROS_FILE; if (!isset($_REQUEST['cmd'])) return; // first time - nothing to do $this->output = ''; if (!checkSecurityToken()) return; if (!is_array($_REQUEST['cmd'])) return; $action = ""; // verify valid values switch (key($_REQUEST['cmd'])) { case 'add' : $action = 'add'; $a = $this->add(); break; case 'delete' : $a = $this->del(); break; case 'edit': $a = $this->edit(); break; } // $this->output = print_r($a,true); // $this->output .= print_r($_REQUEST,true); } function add() { $a = $this->get_macros(); $macros = $_REQUEST['macro']; $words = $_REQUEST['word']; foreach ($macros AS $key=>$value) { if(isset($value) && trim($value)) { if(isset($words[$key]) && trim($words[$key])) { $value = utf8_deaccent($value); $a[$value] = htmlspecialchars (($words[$key]),ENT_NOQUOTES, 'UTF-8'); } } } io_saveFile(MACROS_FILE,serialize($a)); return $a; } function del() { $macros = $this->get_macros(); $deletions = $_REQUEST['delete']; $keys = array_keys($deletions); foreach ($keys AS $_key) { unset($macros[$_key]); } io_saveFile(MACROS_FILE,serialize($macros)); return $macros; } function edit() { $macros = $this->get_macros(); $encoded = $_REQUEST['encoded']; $encoded = array_map('urldecode',$encoded); foreach($encoded AS $k=>$val) { $macros[$k] = htmlspecialchars ($val,ENT_NOQUOTES, 'UTF-8', false); } io_saveFile(MACROS_FILE,serialize($macros)); return $macros; } function get_macros() { if(file_exists(MACROS_FILE)) { $a = unserialize(file_get_contents(MACROS_FILE)); if(!is_array($a)) return array(); ksort($a); return $a; } return array(); } function get_delete_list() { $macros = $this->macros_data; ptln(''); foreach($macros as $macro=>$subst) { ptln(""); } ptln('
"); ptln( "$macro$subst
'); } function get_edit_list() { $macros = $this->macros_data; ptln(''); foreach($macros as $macro=>$subst) { ptln(""); } else { ptln (""); } } ptln('
Macro' . $this->getLang('col_subst') .'
$macro "); $encoded = urlencode($subst); if($subst != $encoded) { ptln(""); } if(strlen($subst) > 80) { ptln ("
'); } function view_entries() { $macros = $this->macros_data; ptln(''); foreach($macros as $macro=>$subst) { ptln( ""); } ptln('
$macro$subst
'); } function js() { echo << ///g,">"); val = val.replace(/ JSFN; } /** * output appropriate html */ function html() { $this->macros_data = $this->get_macros(); $this->js(); if($this->output) { ptln('
' . $this->output . '
'); } ptln('
'); ptln('
'); ptln('    '); ptln('
'); ptln('

Info

'); ptln( $this->locale_xhtml('intro') . '
'); ptln('
'); ptln('  '); ptln('  '); ptln('  '); ptln('  '); ptln('  '); ptln(''); ptln('
'); ptln('
'); // output hidden values to ensure dokuwiki will return back to this plugin ptln(' '); ptln(' '); formSecurityToken(); ptln('
'); ptln(''); ptln(''); ptln('
'); ptln('
'); ptln('

' . $this->getLang('label_list') . '

'); $this->view_entries(); ptln('
'); } }