/** * for backward compatability * @see inc/DokuWiki_Plugin#getInfo() */ function getInfo() { if (method_exists(parent, 'getInfo')) { $info = parent::getInfo(); } return is_array($info) ? $info : confToHash(dirname(__FILE__) . '/plugin.info.txt'); }
/** * Convenience method to access plugin language strings * * @param string $string * @return string */ public function getLang($string) { if (is_null($this->hlp)) { $this->hlp = plugin_load('helper', 'struct'); } return $this->hlp->getLang($string); }
/** * Returns the Admin Form to edit the schema * * This data is processed by the SchemaBuilder class * * @return string the HTML for the editor form * @see SchemaBuilder */ public function getEditor() { $form = new Form(array('method' => 'POST', 'id' => 'plugin__struct_editor')); $form->setHiddenField('do', 'admin'); $form->setHiddenField('page', 'struct_schemas'); $form->setHiddenField('table', $this->schema->getTable()); $form->setHiddenField('schema[id]', $this->schema->getId()); $form->setHiddenField('schema[islookup]', $this->schema->isLookup()); $form->addHTML('<table class="inline">'); $form->addHTML("<tr>\n <th>{$this->hlp->getLang('editor_sort')}</th>\n <th>{$this->hlp->getLang('editor_label')}</th>\n <th>{$this->hlp->getLang('editor_multi')}</th>\n <th>{$this->hlp->getLang('editor_conf')}</th>\n <th>{$this->hlp->getLang('editor_type')}</th>\n <th>{$this->hlp->getLang('editor_enabled')}</th>\n </tr>"); foreach ($this->schema->getColumns() as $key => $col) { $form->addHTML($this->adminColumn($col->getColref(), $col)); } // FIXME new one needs to be added dynamically, this is just for testing $form->addHTML($this->adminColumn('new1', new Column($this->schema->getMaxsort() + 10, new Text()), 'new')); $form->addHTML('</table>'); $form->addFieldsetOpen(); $form->addTextInput('schema[editors]', $this->hlp->getLang('editor_editors'))->val($this->schema->getEditors()); $form->addFieldsetClose(); $form->addButton('save', 'Save')->attr('type', 'submit'); return $form->toHTML() . $this->initJSONEditor(); }
/** * Build html for label and input of setting * * @param DokuWiki_Plugin $plugin object of config plugin * @param bool $echo true: show input value, when error occurred, otherwise the stored setting * @return string[] with content array(string $label_html, string $input_html) */ function html(&$plugin, $echo = false) { $disable = ''; if ($this->is_protected()) { $value = $this->_protected; $disable = 'disabled="disabled"'; } else { if ($echo && $this->_error) { $value = $this->_input; } else { $value = is_null($this->_local) ? $this->_default : $this->_local; } } $key = htmlspecialchars($this->_key); // convert from comma separated list into array + combine complimentary actions $value = $this->_str2array($value); $default = $this->_str2array($this->_default); $input = ''; foreach ($this->_choices as $choice) { $idx = array_search($choice, $value); $idx_default = array_search($choice, $default); $checked = $idx !== false ? 'checked="checked"' : ''; // ideally this would be handled using a second class of "default", however IE6 does not // correctly support CSS selectors referencing multiple class names on the same element // (e.g. .default.selection). $class = ($idx !== false) == (false !== $idx_default) ? " selectiondefault" : ""; $prompt = $plugin->getLang($this->_key . '_' . $choice) ? $plugin->getLang($this->_key . '_' . $choice) : htmlspecialchars($choice); $input .= '<div class="selection' . $class . '">' . "\n"; $input .= '<label for="config___' . $key . '_' . $choice . '">' . $prompt . "</label>\n"; $input .= '<input id="config___' . $key . '_' . $choice . '" name="config[' . $key . '][]" type="checkbox" class="checkbox" value="' . $choice . '" ' . $disable . ' ' . $checked . "/>\n"; $input .= "</div>\n"; // remove this action from the disabledactions array if ($idx !== false) { unset($value[$idx]); } if ($idx_default !== false) { unset($default[$idx_default]); } } // handle any remaining values $other = join(',', $value); $class = count($default) == count($value) && count($value) == count(array_intersect($value, $default)) ? " selectiondefault" : ""; $input .= '<div class="other' . $class . '">' . "\n"; $input .= '<label for="config___' . $key . '_other">' . $plugin->getLang($key . '_other') . "</label>\n"; $input .= '<input id="config___' . $key . '_other" name="config[' . $key . '][other]" type="text" class="edit" value="' . htmlspecialchars($other) . '" ' . $disable . " />\n"; $input .= "</div>\n"; $label = '<label>' . $this->prompt($plugin) . '</label>'; return array($label, $input); }
/** * Build html for label and input of setting * * @param DokuWiki_Plugin $plugin object of config plugin * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting * @return array with content array(string $label_html, string $input_html) */ function html(&$plugin, $echo = false) { // make some language adjustments (there must be a better way) // transfer some plugin names to the config plugin if (!$plugin->localised) { $plugin->setupLocale(); } foreach ($this->_choices as $choice) { if (!isset($plugin->lang[$this->_key . '_o_' . $choice])) { if (!isset($this->_prompts[$choice])) { $plugin->lang[$this->_key . '_o_' . $choice] = sprintf($plugin->lang['renderer__core'], $choice); } else { $plugin->lang[$this->_key . '_o_' . $choice] = sprintf($plugin->lang['renderer__plugin'], $this->_prompts[$choice]); } } } return parent::html($plugin, $echo); }
/** * Build html for label and input of setting * * @param DokuWiki_Plugin $plugin object of config plugin * @param bool $echo true: show input value, when error occurred, otherwise the stored setting * @return string[] with content array(string $label_html, string $input_html) */ function html(&$plugin, $echo = false) { $disable = ''; if ($this->is_protected()) { $value = $this->_protected; $disable = 'disabled="disabled"'; } else { if ($echo && $this->_error) { $value = $this->_input; } else { $value = is_null($this->_local) ? $this->_default : $this->_local; } } $key = htmlspecialchars($this->_key); // convert from comma separated list into array + combine complimentary actions $value = $this->_str2array($value); $default = $this->_str2array($this->_default); $input = ''; foreach ($this->_choices as $choice) { $idx = array_search($choice, $value); $idx_default = array_search($choice, $default); $checked = $idx !== false ? 'checked="checked"' : ''; // @todo ideally this would be handled using a second class of "default" $class = ($idx !== false) == (false !== $idx_default) ? " selectiondefault" : ""; $prompt = $plugin->getLang($this->_key . '_' . $choice) ? $plugin->getLang($this->_key . '_' . $choice) : htmlspecialchars($choice); $input .= '<div class="selection' . $class . '">' . "\n"; $input .= '<label for="config___' . $key . '_' . $choice . '">' . $prompt . "</label>\n"; $input .= '<input id="config___' . $key . '_' . $choice . '" name="config[' . $key . '][]" type="checkbox" class="checkbox" value="' . $choice . '" ' . $disable . ' ' . $checked . "/>\n"; $input .= "</div>\n"; // remove this action from the disabledactions array if ($idx !== false) { unset($value[$idx]); } if ($idx_default !== false) { unset($default[$idx_default]); } } // handle any remaining values if ($this->_other != 'never') { $other = join(',', $value); // test equivalent to ($this->_other == 'always' || ($other && $this->_other == 'exists') // use != 'exists' rather than == 'always' to ensure invalid values default to 'always' if ($this->_other != 'exists' || $other) { $class = count($default) == count($value) && count($value) == count(array_intersect($value, $default)) ? " selectiondefault" : ""; $input .= '<div class="other' . $class . '">' . "\n"; $input .= '<label for="config___' . $key . '_other">' . $plugin->getLang($key . '_other') . "</label>\n"; $input .= '<input id="config___' . $key . '_other" name="config[' . $key . '][other]" type="text" class="edit" value="' . htmlspecialchars($other) . '" ' . $disable . " />\n"; $input .= "</div>\n"; } } $label = '<label>' . $this->prompt($plugin) . '</label>'; return array($label, $input); }
/** * Returns the localized prompt * * @param DokuWiki_Plugin $plugin object of config plugin * @return string text */ public function prompt(&$plugin) { $prompt = $plugin->getLang($this->_key); if (!$prompt) { $prompt = htmlspecialchars(str_replace(array('____', '_'), ' ', $this->_key)); } return $prompt; }
/** * Renders internally formatted value for read-only output (e.g. on listing * table). * * @param integer $rowid ID of row containing given value * @param string $column name of column * @param mixed $in value returned from DB * @param string $type defined type of value * @param boolean $mayBeSkipped if true, the method should return null if * value is unset * @param boolean $inEditor if true, the value comes from an editor's * session (important for rendering attached * files/images) * @return string code describing value for read-only output */ protected function renderValue($rowid, $column, $value, $def, $mayBeSkipped = false, $inEditor = false, $rowACL = null) { if (!$this->isAuthorizedMulti($rowACL, $def['options'], 'mayview', null, true)) { return $mayBeSkipped ? null : '<em>' . $this->getLang('hidden') . '</em>'; } if (is_null($value) && $def['type'] != 'data') { return $mayBeSkipped ? null : ''; } switch ($def['format']) { case 'text': if (trim($value) === '' && $mayBeSkipped) { return null; } if ($this->options['wikimarkup'] || $def['options']['wikimarkup']) { // apply processing of contained wiki markup $value = p_render('xhtml', p_get_instructions($value), $info); if (preg_match('#^<p>((.|\\n)+)</p>$#i', trim($value), $matches)) { $value = $matches[1]; } } // strip some special tags from text (preventing some XSS attacks) $value = $this->stripTags($value); return trim($value); case 'image': case 'file': if ($value === true) { return '<span class="info">' . $this->getLang('fileexternalfound') . '</span>'; } else { if ($value === false) { return '<span class="info">' . $this->getLang('fileexternalnotfound') . '</span>'; } else { $temp = is_array($value) ? trim(implode('', $value)) : ''; if ($temp === '') { return $mayBeSkipped ? null : '<em>' . $this->getLang('none') . '</em>'; } if ($inEditor) { $url = $this->editorSessionMediaLink($column, $def['format'] != 'image'); } else { $url = $this->mediaLink($rowid, $column, $def['format'] != 'image'); } if (!$inEditor) { $url .= '&thumb=150'; } if ($def['format'] === 'image') { return "<img src=\"{$url}\" alt=\"" . sprintf($this->getLang('fileimagealt'), $column, $value['mime']) . "\" />"; } $mayDownload = $this->isAuthorizedMulti($rowACL, $this->options, 'maydownload'); if (!$mayDownload) { return '<em>' . $this->getLang('filedenied') . '</em>'; } return "<a href=\"{$url}\" title=\"" . $this->getLang('filedlhint') . '">' . $this->getLang('cmddl') . '</a>'; } } break; case 'email': if (trim($value) === '' && $mayBeSkipped) { return null; } return DokuWiki_Plugin::email($value, $email); case 'url': if (trim($value) === '' && $mayBeSkipped) { return null; } return DokuWiki_Plugin::external_link($value); case 'phone': case 'fax': if (trim($value) === '' && $mayBeSkipped) { return null; } return $value; case 'bool': if (!$value && $mayBeSkipped) { return null; } return $value ? '✗' : '–'; case 'date': if (!$value) { return $mayBeSkipped ? null : ''; } return strftime(strtok(trim($this->getConf('dformat')), ' '), $value); case 'datetime': if (!$value) { return $mayBeSkipped ? null : ''; } return strftime($this->getConf('dformat'), $value); case 'time': if ($value && substr($value, -3) == ':00' && strlen($value) > 5) { $value = substr($value, 0, -3); } return $value; case 'integer': case 'monetary': case 'real': if (!$value && $mayBeSkipped) { return null; } return $value; case 'enum': case 'related': if (is_integer($value)) { $value = $def['options']['selectables'][$value]; } return $value; case 'acl': if (!$this->isAuthorized($this->options['mayadmin'])) { // admins may see this value, only return null; } return $value; default: return $value; } }