HTMLPurifier_Config::getAllowedDirectivesForForm PHP Method

getAllowedDirectivesForForm() public static method

Returns a list of array(namespace, directive) for all directives that are allowed in a web-form context as per an allowed namespaces/directives list.
public static getAllowedDirectivesForForm ( array $allowed, HTMLPurifier_ConfigSchema $schema = null ) : array
$allowed array List of allowed namespaces/directives
$schema HTMLPurifier_ConfigSchema Schema to use, if not global copy
return array
    public static function getAllowedDirectivesForForm($allowed, $schema = null)
    {
        if (!$schema) {
            $schema = HTMLPurifier_ConfigSchema::instance();
        }
        if ($allowed !== true) {
            if (is_string($allowed)) {
                $allowed = array($allowed);
            }
            $allowed_ns = array();
            $allowed_directives = array();
            $blacklisted_directives = array();
            foreach ($allowed as $ns_or_directive) {
                if (strpos($ns_or_directive, '.') !== false) {
                    // directive
                    if ($ns_or_directive[0] == '-') {
                        $blacklisted_directives[substr($ns_or_directive, 1)] = true;
                    } else {
                        $allowed_directives[$ns_or_directive] = true;
                    }
                } else {
                    // namespace
                    $allowed_ns[$ns_or_directive] = true;
                }
            }
        }
        $ret = array();
        foreach ($schema->info as $key => $def) {
            list($ns, $directive) = explode('.', $key, 2);
            if ($allowed !== true) {
                if (isset($blacklisted_directives["{$ns}.{$directive}"])) {
                    continue;
                }
                if (!isset($allowed_directives["{$ns}.{$directive}"]) && !isset($allowed_ns[$ns])) {
                    continue;
                }
            }
            if (isset($def->isAlias)) {
                continue;
            }
            if ($directive == 'DefinitionID' || $directive == 'DefinitionRev') {
                continue;
            }
            $ret[] = array($ns, $directive);
        }
        return $ret;
    }

Usage Example

コード例 #1
0
 /**
  * Returns HTML output for a configuration form
  * @param $config Configuration object of current form state
  * @param $allowed Optional namespace(s) and directives to restrict form to.
  */
 function render($config, $allowed = true, $render_controls = true)
 {
     $this->config = $config;
     $this->prepareGenerator($config);
     $allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed);
     $all = array();
     foreach ($allowed as $key) {
         list($ns, $directive) = $key;
         $all[$ns][$directive] = $config->get($ns, $directive);
     }
     $ret = '';
     $ret .= $this->start('table', array('class' => 'hp-config'));
     $ret .= $this->start('thead');
     $ret .= $this->start('tr');
     $ret .= $this->element('th', 'Directive');
     $ret .= $this->element('th', 'Value');
     $ret .= $this->end('tr');
     $ret .= $this->end('thead');
     foreach ($all as $ns => $directives) {
         $ret .= $this->renderNamespace($ns, $directives);
     }
     if ($render_controls) {
         $ret .= $this->start('tbody');
         $ret .= $this->start('tr');
         $ret .= $this->start('td', array('colspan' => 2, 'class' => 'controls'));
         $ret .= $this->elementEmpty('input', array('type' => 'submit', 'value' => 'Submit'));
         $ret .= '[<a href="?">Reset</a>]';
         $ret .= $this->end('td');
         $ret .= $this->end('tr');
         $ret .= $this->end('tbody');
     }
     $ret .= $this->end('table');
     return $ret;
 }
All Usage Examples Of HTMLPurifier_Config::getAllowedDirectivesForForm