code
stringlengths 17
247k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function getHTMLDefinition($raw = false, $optimized = false)
{
return $this->getDefinition('HTML', $raw, $optimized);
} | Retrieves object reference to the HTML definition.
@param bool $raw Return a copy that has not been setup yet. Must be
called before it's been setup, otherwise won't work.
@param bool $optimized If true, this method may return null, to
indicate that a cached version of the modified
definition object is available and no further edits
are necessary. Consider using
maybeGetRawHTMLDefinition, which is more explicitly
named, instead.
@return HTMLPurifier_HTMLDefinition | getHTMLDefinition | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getCSSDefinition($raw = false, $optimized = false)
{
return $this->getDefinition('CSS', $raw, $optimized);
} | Retrieves object reference to the CSS definition
@param bool $raw Return a copy that has not been setup yet. Must be
called before it's been setup, otherwise won't work.
@param bool $optimized If true, this method may return null, to
indicate that a cached version of the modified
definition object is available and no further edits
are necessary. Consider using
maybeGetRawCSSDefinition, which is more explicitly
named, instead.
@return HTMLPurifier_CSSDefinition | getCSSDefinition | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getURIDefinition($raw = false, $optimized = false)
{
return $this->getDefinition('URI', $raw, $optimized);
} | Retrieves object reference to the URI definition
@param bool $raw Return a copy that has not been setup yet. Must be
called before it's been setup, otherwise won't work.
@param bool $optimized If true, this method may return null, to
indicate that a cached version of the modified
definition object is available and no further edits
are necessary. Consider using
maybeGetRawURIDefinition, which is more explicitly
named, instead.
@return HTMLPurifier_URIDefinition | getURIDefinition | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getDefinition($type, $raw = false, $optimized = false)
{
if ($optimized && !$raw) {
throw new HTMLPurifier_Exception("Cannot set optimized = true when raw = false");
}
if (!$this->finalized) {
$this->autoFinalize();
}
// temporarily suspend locks, so we can handle recursive definition calls
$lock = $this->lock;
$this->lock = null;
$factory = HTMLPurifier_DefinitionCacheFactory::instance();
$cache = $factory->create($type, $this);
$this->lock = $lock;
if (!$raw) {
// full definition
// ---------------
// check if definition is in memory
if (!empty($this->definitions[$type])) {
$def = $this->definitions[$type];
// check if the definition is setup
if ($def->setup) {
return $def;
} else {
$def->setup($this);
if ($def->optimized) {
$cache->add($def, $this);
}
return $def;
}
}
// check if definition is in cache
$def = $cache->get($this);
if ($def) {
// definition in cache, save to memory and return it
$this->definitions[$type] = $def;
return $def;
}
// initialize it
$def = $this->initDefinition($type);
// set it up
$this->lock = $type;
$def->setup($this);
$this->lock = null;
// save in cache
$cache->add($def, $this);
// return it
return $def;
} else {
// raw definition
// --------------
// check preconditions
$def = null;
if ($optimized) {
if (is_null($this->get($type . '.DefinitionID'))) {
// fatally error out if definition ID not set
throw new HTMLPurifier_Exception(
"Cannot retrieve raw version without specifying %$type.DefinitionID"
);
}
}
if (!empty($this->definitions[$type])) {
$def = $this->definitions[$type];
if ($def->setup && !$optimized) {
$extra = $this->chatty ?
" (try moving this code block earlier in your initialization)" :
"";
throw new HTMLPurifier_Exception(
"Cannot retrieve raw definition after it has already been setup" .
$extra
);
}
if ($def->optimized === null) {
$extra = $this->chatty ? " (try flushing your cache)" : "";
throw new HTMLPurifier_Exception(
"Optimization status of definition is unknown" . $extra
);
}
if ($def->optimized !== $optimized) {
$msg = $optimized ? "optimized" : "unoptimized";
$extra = $this->chatty ?
" (this backtrace is for the first inconsistent call, which was for a $msg raw definition)"
: "";
throw new HTMLPurifier_Exception(
"Inconsistent use of optimized and unoptimized raw definition retrievals" . $extra
);
}
}
// check if definition was in memory
if ($def) {
if ($def->setup) {
// invariant: $optimized === true (checked above)
return null;
} else {
return $def;
}
}
// if optimized, check if definition was in cache
// (because we do the memory check first, this formulation
// is prone to cache slamming, but I think
// guaranteeing that either /all/ of the raw
// setup code or /none/ of it is run is more important.)
if ($optimized) {
// This code path only gets run once; once we put
// something in $definitions (which is guaranteed by the
// trailing code), we always short-circuit above.
$def = $cache->get($this);
if ($def) {
// save the full definition for later, but don't
// return it yet
$this->definitions[$type] = $def;
return null;
}
}
// check invariants for creation
if (!$optimized) {
if (!is_null($this->get($type . '.DefinitionID'))) {
if ($this->chatty) {
$this->triggerError(
'Due to a documentation error in previous version of HTML Purifier, your ' .
'definitions are not being cached. If this is OK, you can remove the ' .
'%$type.DefinitionRev and %$type.DefinitionID declaration. Otherwise, ' .
'modify your code to use maybeGetRawDefinition, and test if the returned ' .
'value is null before making any edits (if it is null, that means that a ' .
'cached version is available, and no raw operations are necessary). See ' .
'<a href="http://htmlpurifier.org/docs/enduser-customize.html#optimized">' .
'Customize</a> for more details',
E_USER_WARNING
);
} else {
$this->triggerError(
"Useless DefinitionID declaration",
E_USER_WARNING
);
}
}
}
// initialize it
$def = $this->initDefinition($type);
$def->optimized = $optimized;
return $def;
}
throw new HTMLPurifier_Exception("The impossible happened!");
} | Retrieves a definition
@param string $type Type of definition: HTML, CSS, etc
@param bool $raw Whether or not definition should be returned raw
@param bool $optimized Only has an effect when $raw is true. Whether
or not to return null if the result is already present in
the cache. This is off by default for backwards
compatibility reasons, but you need to do things this
way in order to ensure that caching is done properly.
Check out enduser-customize.html for more details.
We probably won't ever change this default, as much as the
maybe semantics is the "right thing to do."
@throws HTMLPurifier_Exception
@return HTMLPurifier_Definition | getDefinition | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public static function loadArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null)
{
$ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $schema);
$config = HTMLPurifier_Config::create($ret, $schema);
return $config;
} | Loads configuration values from $_GET/$_POST that were posted
via ConfigForm
@param array $array $_GET or $_POST array to import
@param string|bool $index Index/name that the config variables are in
@param array|bool $allowed List of allowed namespaces/directives
@param bool $mq_fix Boolean whether or not to enable magic quotes fix
@param HTMLPurifier_ConfigSchema $schema Schema to use, if not global copy
@return mixed | loadArrayFromForm | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function mergeArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true)
{
$ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $this->def);
$this->loadArray($ret);
} | Merges in configuration values from $_GET/$_POST to object. NOT STATIC.
@param array $array $_GET or $_POST array to import
@param string|bool $index Index/name that the config variables are in
@param array|bool $allowed List of allowed namespaces/directives
@param bool $mq_fix Boolean whether or not to enable magic quotes fix | mergeArrayFromForm | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function loadIni($filename)
{
if ($this->isFinalized('Cannot load directives after finalization')) {
return;
}
$array = parse_ini_file($filename, true);
$this->loadArray($array);
} | Loads configuration values from an ini file
@param string $filename Name of ini file | loadIni | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function isFinalized($error = false)
{
if ($this->finalized && $error) {
$this->triggerError($error, E_USER_ERROR);
}
return $this->finalized;
} | Checks whether or not the configuration object is finalized.
@param string|bool $error String error message, or false for no error
@return bool | isFinalized | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function autoFinalize()
{
if ($this->autoFinalize) {
$this->finalize();
} else {
$this->plist->squash(true);
}
} | Finalizes configuration only if auto finalize is on and not
already finalized | autoFinalize | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function finalize()
{
$this->finalized = true;
$this->parser = null;
} | Finalizes a configuration object, prohibiting further change | finalize | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
protected function triggerError($msg, $no)
{
// determine previous stack frame
$extra = '';
if ($this->chatty) {
$trace = debug_backtrace();
// zip(tail(trace), trace) -- but PHP is not Haskell har har
for ($i = 0, $c = count($trace); $i < $c - 1; $i++) {
// XXX this is not correct on some versions of HTML Purifier
if ($trace[$i + 1]['class'] === 'HTMLPurifier_Config') {
continue;
}
$frame = $trace[$i];
$extra = " invoked on line {$frame['line']} in file {$frame['file']}";
break;
}
}
trigger_error($msg . $extra, $no);
} | Produces a nicely formatted error message by supplying the
stack frame information OUTSIDE of HTMLPurifier_Config.
@param string $msg An error message
@param int $no An error number | triggerError | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function serialize()
{
$this->getDefinition('HTML');
$this->getDefinition('CSS');
$this->getDefinition('URI');
return serialize($this);
} | Returns a serialized form of the configuration object that can
be reconstituted.
@return string | serialize | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public static function makeFromSerial()
{
$contents = file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema.ser');
$r = unserialize($contents);
if (!$r) {
$hash = sha1($contents);
trigger_error("Unserialization of configuration schema failed, sha1 of file was $hash", E_USER_ERROR);
}
return $r;
} | Unserializes the default ConfigSchema.
@return HTMLPurifier_ConfigSchema | makeFromSerial | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function add($key, $default, $type, $allow_null)
{
$obj = new stdclass();
$obj->type = is_int($type) ? $type : HTMLPurifier_VarParser::$types[$type];
if ($allow_null) {
$obj->allow_null = true;
}
$this->info[$key] = $obj;
$this->defaults[$key] = $default;
$this->defaultPlist->set($key, $default);
} | Defines a directive for configuration
@warning Will fail of directive's namespace is defined.
@warning This method's signature is slightly different from the legacy
define() static method! Beware!
@param string $key Name of directive
@param mixed $default Default value of directive
@param string $type Allowed type of the directive. See
HTMLPurifier_DirectiveDef::$type for allowed values
@param bool $allow_null Whether or not to allow null values | add | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function addValueAliases($key, $aliases)
{
if (!isset($this->info[$key]->aliases)) {
$this->info[$key]->aliases = array();
}
foreach ($aliases as $alias => $real) {
$this->info[$key]->aliases[$alias] = $real;
}
} | Defines a directive value alias.
Directive value aliases are convenient for developers because it lets
them set a directive to several values and get the same result.
@param string $key Name of Directive
@param array $aliases Hash of aliased values to the real alias | addValueAliases | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function addAllowedValues($key, $allowed)
{
$this->info[$key]->allowed = $allowed;
} | Defines a set of allowed values for a directive.
@warning This is slightly different from the corresponding static
method definition.
@param string $key Name of directive
@param array $allowed Lookup array of allowed values | addAllowedValues | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function addAlias($key, $new_key)
{
$obj = new stdclass;
$obj->key = $new_key;
$obj->isAlias = true;
$this->info[$key] = $obj;
} | Defines a directive alias for backwards compatibility
@param string $key Directive that will be aliased
@param string $new_key Directive that the alias will be to | addAlias | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function generateChildDef(&$def, $module)
{
if (!empty($def->child)) { // already done!
return;
}
$content_model = $def->content_model;
if (is_string($content_model)) {
// Assume that $this->keys is alphanumeric
$def->content_model = preg_replace_callback(
'/\b(' . implode('|', $this->keys) . ')\b/',
array($this, 'generateChildDefCallback'),
$content_model
);
//$def->content_model = str_replace(
// $this->keys, $this->values, $content_model);
}
$def->child = $this->getChildDef($def, $module);
} | Accepts a definition; generates and assigns a ChildDef for it
@param HTMLPurifier_ElementDef $def HTMLPurifier_ElementDef reference
@param HTMLPurifier_HTMLModule $module Module that defined the ElementDef | generateChildDef | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getChildDef($def, $module)
{
$value = $def->content_model;
if (is_object($value)) {
trigger_error(
'Literal object child definitions should be stored in '.
'ElementDef->child not ElementDef->content_model',
E_USER_NOTICE
);
return $value;
}
switch ($def->content_model_type) {
case 'required':
return new HTMLPurifier_ChildDef_Required($value);
case 'optional':
return new HTMLPurifier_ChildDef_Optional($value);
case 'empty':
return new HTMLPurifier_ChildDef_Empty();
case 'custom':
return new HTMLPurifier_ChildDef_Custom($value);
}
// defer to its module
$return = false;
if ($module->defines_child_def) { // save a func call
$return = $module->getChildDef($def);
}
if ($return !== false) {
return $return;
}
// error-out
trigger_error(
'Could not determine which ChildDef class to instantiate',
E_USER_ERROR
);
return false;
} | Instantiates a ChildDef based on content_model and content_model_type
member variables in HTMLPurifier_ElementDef
@note This will also defer to modules for custom HTMLPurifier_ChildDef
subclasses that need content set expansion
@param HTMLPurifier_ElementDef $def HTMLPurifier_ElementDef to have ChildDef extracted
@param HTMLPurifier_HTMLModule $module Module that defined the ElementDef
@return HTMLPurifier_ChildDef corresponding to ElementDef | getChildDef | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
protected function convertToLookup($string)
{
$array = explode('|', str_replace(' ', '', $string));
$ret = array();
foreach ($array as $k) {
$ret[$k] = true;
}
return $ret;
} | Converts a string list of elements separated by pipes into
a lookup array.
@param string $string List of elements
@return array Lookup array of elements | convertToLookup | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function register($name, &$ref)
{
if (array_key_exists($name, $this->_storage)) {
trigger_error(
"Name $name produces collision, cannot re-register",
E_USER_ERROR
);
return;
}
$this->_storage[$name] =& $ref;
} | Registers a variable into the context.
@param string $name String name
@param mixed $ref Reference to variable to be registered | register | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function &get($name, $ignore_error = false)
{
if (!array_key_exists($name, $this->_storage)) {
if (!$ignore_error) {
trigger_error(
"Attempted to retrieve non-existent variable $name",
E_USER_ERROR
);
}
$var = null; // so we can return by reference
return $var;
}
return $this->_storage[$name];
} | Retrieves a variable reference from the context.
@param string $name String name
@param bool $ignore_error Boolean whether or not to ignore error
@return mixed | get | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function destroy($name)
{
if (!array_key_exists($name, $this->_storage)) {
trigger_error(
"Attempted to destroy non-existent variable $name",
E_USER_ERROR
);
return;
}
unset($this->_storage[$name]);
} | Destroys a variable in the context.
@param string $name String name | destroy | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function exists($name)
{
return array_key_exists($name, $this->_storage);
} | Checks whether or not the variable exists.
@param string $name String name
@return bool | exists | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function generateKey($config)
{
return $config->version . ',' . // possibly replace with function calls
$config->getBatchSerial($this->type) . ',' .
$config->get($this->type . '.DefinitionRev');
} | Generates a unique identifier for a particular configuration
@param HTMLPurifier_Config $config Instance of HTMLPurifier_Config
@return string | generateKey | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function isOld($key, $config)
{
if (substr_count($key, ',') < 2) {
return true;
}
list($version, $hash, $revision) = explode(',', $key, 3);
$compare = version_compare($version, $config->version);
// version mismatch, is always old
if ($compare != 0) {
return true;
}
// versions match, ids match, check revision number
if ($hash == $config->getBatchSerial($this->type) &&
$revision < $config->get($this->type . '.DefinitionRev')) {
return true;
}
return false;
} | Tests whether or not a key is old with respect to the configuration's
version and revision number.
@param string $key Key to test
@param HTMLPurifier_Config $config Instance of HTMLPurifier_Config to test against
@return bool | isOld | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function checkDefType($def)
{
if ($def->type !== $this->type) {
trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}");
return false;
}
return true;
} | Checks if a definition's type jives with the cache's type
@note Throws an error on failure
@param HTMLPurifier_Definition $def Definition object to check
@return bool true if good, false if not | checkDefType | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function register($short, $long)
{
$this->implementations[$short] = $long;
} | Registers a new definition cache object
@param string $short Short name of cache object, for reference
@param string $long Full class name of cache object, for construction | register | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function addDecorator($decorator)
{
if (is_string($decorator)) {
$class = "HTMLPurifier_DefinitionCache_Decorator_$decorator";
$decorator = new $class;
}
$this->decorators[$decorator->name] = $decorator;
} | Registers a decorator to add to all new cache objects
@param HTMLPurifier_DefinitionCache_Decorator|string $decorator An instance or the name of a decorator | addDecorator | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function get($doctype)
{
if (isset($this->aliases[$doctype])) {
$doctype = $this->aliases[$doctype];
}
if (!isset($this->doctypes[$doctype])) {
trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR);
$anon = new HTMLPurifier_Doctype($doctype);
return $anon;
}
return $this->doctypes[$doctype];
} | Retrieves reference to a doctype of a certain name
@note This function resolves aliases
@note When possible, use the more fully-featured make()
@param string $doctype Name of doctype
@return HTMLPurifier_Doctype Editable doctype object | get | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function make($config)
{
return clone $this->get($this->getDoctypeFromConfig($config));
} | Creates a doctype based on a configuration object,
will perform initialization on the doctype
@note Use this function to get a copy of doctype that config
can hold on to (this is necessary in order to tell
Generator whether or not the current document is XML
based or not).
@param HTMLPurifier_Config $config
@return HTMLPurifier_Doctype | make | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getDoctypeFromConfig($config)
{
// recommended test
$doctype = $config->get('HTML.Doctype');
if (!empty($doctype)) {
return $doctype;
}
$doctype = $config->get('HTML.CustomDoctype');
if (!empty($doctype)) {
return $doctype;
}
// backwards-compatibility
if ($config->get('HTML.XHTML')) {
$doctype = 'XHTML 1.0';
} else {
$doctype = 'HTML 4.01';
}
if ($config->get('HTML.Strict')) {
$doctype .= ' Strict';
} else {
$doctype .= ' Transitional';
}
return $doctype;
} | Retrieves the doctype from the configuration object
@param HTMLPurifier_Config $config
@return string | getDoctypeFromConfig | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public static function create($content_model, $content_model_type, $attr)
{
$def = new HTMLPurifier_ElementDef();
$def->content_model = $content_model;
$def->content_model_type = $content_model_type;
$def->attr = $attr;
return $def;
} | Low-level factory constructor for creating new standalone element defs | create | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function mergeIn($def)
{
// later keys takes precedence
foreach ($def->attr as $k => $v) {
if ($k === 0) {
// merge in the includes
// sorry, no way to override an include
foreach ($v as $v2) {
$this->attr[0][] = $v2;
}
continue;
}
if ($v === false) {
if (isset($this->attr[$k])) {
unset($this->attr[$k]);
}
continue;
}
$this->attr[$k] = $v;
}
$this->_mergeAssocArray($this->excludes, $def->excludes);
$this->attr_transform_pre = array_merge($this->attr_transform_pre, $def->attr_transform_pre);
$this->attr_transform_post = array_merge($this->attr_transform_post, $def->attr_transform_post);
if (!empty($def->content_model)) {
$this->content_model =
str_replace("#SUPER", $this->content_model, $def->content_model);
$this->child = false;
}
if (!empty($def->content_model_type)) {
$this->content_model_type = $def->content_model_type;
$this->child = false;
}
if (!is_null($def->child)) {
$this->child = $def->child;
}
if (!is_null($def->formatting)) {
$this->formatting = $def->formatting;
}
if ($def->descendants_are_inline) {
$this->descendants_are_inline = $def->descendants_are_inline;
}
} | Merges the values of another element definition into this one.
Values from the new element def take precedence if a value is
not mergeable.
@param HTMLPurifier_ElementDef $def | mergeIn | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
private function _mergeAssocArray(&$a1, $a2)
{
foreach ($a2 as $k => $v) {
if ($v === false) {
if (isset($a1[$k])) {
unset($a1[$k]);
}
continue;
}
$a1[$k] = $v;
}
} | Merges one array into another, removes values which equal false
@param $a1 Array by reference that is merged into
@param $a2 Array that merges into $a1 | _mergeAssocArray | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
private function __construct()
{
trigger_error('Cannot instantiate encoder, call methods statically', E_USER_ERROR);
} | Constructor throws fatal error if you attempt to instantiate class | __construct | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public static function muteErrorHandler()
{
} | Error-handler that mutes errors, alternative to shut-up operator. | muteErrorHandler | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public static function unsafeIconv($in, $out, $text)
{
set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
$r = iconv($in, $out, $text);
restore_error_handler();
return $r;
} | iconv wrapper which mutes errors, but doesn't work around bugs.
@param string $in Input encoding
@param string $out Output encoding
@param string $text The text to convert
@return string | unsafeIconv | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public static function iconv($in, $out, $text, $max_chunk_size = 8000)
{
$code = self::testIconvTruncateBug();
if ($code == self::ICONV_OK) {
return self::unsafeIconv($in, $out, $text);
} elseif ($code == self::ICONV_TRUNCATES) {
// we can only work around this if the input character set
// is utf-8
if ($in == 'utf-8') {
if ($max_chunk_size < 4) {
trigger_error('max_chunk_size is too small', E_USER_WARNING);
return false;
}
// split into 8000 byte chunks, but be careful to handle
// multibyte boundaries properly
if (($c = strlen($text)) <= $max_chunk_size) {
return self::unsafeIconv($in, $out, $text);
}
$r = '';
$i = 0;
while (true) {
if ($i + $max_chunk_size >= $c) {
$r .= self::unsafeIconv($in, $out, substr($text, $i));
break;
}
// wibble the boundary
if (0x80 != (0xC0 & ord($text[$i + $max_chunk_size]))) {
$chunk_size = $max_chunk_size;
} elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 1]))) {
$chunk_size = $max_chunk_size - 1;
} elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 2]))) {
$chunk_size = $max_chunk_size - 2;
} elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 3]))) {
$chunk_size = $max_chunk_size - 3;
} else {
return false; // rather confusing UTF-8...
}
$chunk = substr($text, $i, $chunk_size); // substr doesn't mind overlong lengths
$r .= self::unsafeIconv($in, $out, $chunk);
$i += $chunk_size;
}
return $r;
} else {
return false;
}
} else {
return false;
}
} | iconv wrapper which mutes errors and works around bugs.
@param string $in Input encoding
@param string $out Output encoding
@param string $text The text to convert
@param int $max_chunk_size
@return string | iconv | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public static function unichr($code)
{
if ($code > 1114111 or $code < 0 or
($code >= 55296 and $code <= 57343) ) {
// bits are set outside the "valid" range as defined
// by UNICODE 4.1.0
return '';
}
$x = $y = $z = $w = 0;
if ($code < 128) {
// regular ASCII character
$x = $code;
} else {
// set up bits for UTF-8
$x = ($code & 63) | 128;
if ($code < 2048) {
$y = (($code & 2047) >> 6) | 192;
} else {
$y = (($code & 4032) >> 6) | 128;
if ($code < 65536) {
$z = (($code >> 12) & 15) | 224;
} else {
$z = (($code >> 12) & 63) | 128;
$w = (($code >> 18) & 7) | 240;
}
}
}
// set up the actual character
$ret = '';
if ($w) {
$ret .= chr($w);
}
if ($z) {
$ret .= chr($z);
}
if ($y) {
$ret .= chr($y);
}
$ret .= chr($x);
return $ret;
} | Translates a Unicode codepoint into its corresponding UTF-8 character.
@note Based on Feyd's function at
<http://forums.devnetwork.net/viewtopic.php?p=191404#191404>,
which is in public domain.
@note While we're going to do code point parsing anyway, a good
optimization would be to refuse to translate code points that
are non-SGML characters. However, this could lead to duplication.
@note This is very similar to the unichr function in
maintenance/generate-entity-file.php (although this is superior,
due to its sanity checks). | unichr | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function setup($file = false)
{
if (!$file) {
$file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/EntityLookup/entities.ser';
}
$this->table = unserialize(file_get_contents($file));
} | Sets up the entity lookup table from the serialized file contents.
@param bool $file
@note The serialized contents are versioned, but were generated
using the maintenance script generate_entity_file.php
@warning This is not in constructor to help enforce the Singleton | setup | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function substituteNonSpecialEntities($string)
{
// it will try to detect missing semicolons, but don't rely on it
return preg_replace_callback(
$this->_substituteEntitiesRegex,
array($this, 'nonSpecialEntityCallback'),
$string
);
} | Substitutes non-special entities with their parsed equivalents. Since
running this whenever you have parsed character is t3h 5uck, we run
it before everything else.
@param string $string String to have non-special entities parsed.
@return string Parsed string. | substituteNonSpecialEntities | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
protected function nonSpecialEntityCallback($matches)
{
// replaces all but big five
$entity = $matches[0];
$is_num = (@$matches[0][1] === '#');
if ($is_num) {
$is_hex = (@$entity[2] === 'x');
$code = $is_hex ? hexdec($matches[1]) : (int) $matches[2];
// abort for special characters
if (isset($this->_special_dec2str[$code])) {
return $entity;
}
return HTMLPurifier_Encoder::unichr($code);
} else {
if (isset($this->_special_ent2dec[$matches[3]])) {
return $entity;
}
if (!$this->_entity_lookup) {
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
}
if (isset($this->_entity_lookup->table[$matches[3]])) {
return $this->_entity_lookup->table[$matches[3]];
} else {
return $entity;
}
}
} | Callback function for substituteNonSpecialEntities() that does the work.
@param array $matches PCRE matches array, with 0 the entire match, and
either index 1, 2 or 3 set with a hex value, dec value,
or string (respectively).
@return string Replacement string. | nonSpecialEntityCallback | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function substituteSpecialEntities($string)
{
return preg_replace_callback(
$this->_substituteEntitiesRegex,
array($this, 'specialEntityCallback'),
$string
);
} | Substitutes only special entities with their parsed equivalents.
@notice We try to avoid calling this function because otherwise, it
would have to be called a lot (for every parsed section).
@param string $string String to have non-special entities parsed.
@return string Parsed string. | substituteSpecialEntities | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function send($severity, $msg)
{
$args = array();
if (func_num_args() > 2) {
$args = func_get_args();
array_shift($args);
unset($args[0]);
}
$token = $this->context->get('CurrentToken', true);
$line = $token ? $token->line : $this->context->get('CurrentLine', true);
$col = $token ? $token->col : $this->context->get('CurrentCol', true);
$attr = $this->context->get('CurrentAttr', true);
// perform special substitutions, also add custom parameters
$subst = array();
if (!is_null($token)) {
$args['CurrentToken'] = $token;
}
if (!is_null($attr)) {
$subst['$CurrentAttr.Name'] = $attr;
if (isset($token->attr[$attr])) {
$subst['$CurrentAttr.Value'] = $token->attr[$attr];
}
}
if (empty($args)) {
$msg = $this->locale->getMessage($msg);
} else {
$msg = $this->locale->formatMessage($msg, $args);
}
if (!empty($subst)) {
$msg = strtr($msg, $subst);
}
// (numerically indexed)
$error = array(
self::LINENO => $line,
self::SEVERITY => $severity,
self::MESSAGE => $msg,
self::CHILDREN => array()
);
$this->_current[] = $error;
// NEW CODE BELOW ...
// Top-level errors are either:
// TOKEN type, if $value is set appropriately, or
// "syntax" type, if $value is null
$new_struct = new HTMLPurifier_ErrorStruct();
$new_struct->type = HTMLPurifier_ErrorStruct::TOKEN;
if ($token) {
$new_struct->value = clone $token;
}
if (is_int($line) && is_int($col)) {
if (isset($this->lines[$line][$col])) {
$struct = $this->lines[$line][$col];
} else {
$struct = $this->lines[$line][$col] = $new_struct;
}
// These ksorts may present a performance problem
ksort($this->lines[$line], SORT_NUMERIC);
} else {
if (isset($this->lines[-1])) {
$struct = $this->lines[-1];
} else {
$struct = $this->lines[-1] = $new_struct;
}
}
ksort($this->lines, SORT_NUMERIC);
// Now, check if we need to operate on a lower structure
if (!empty($attr)) {
$struct = $struct->getChild(HTMLPurifier_ErrorStruct::ATTR, $attr);
if (!$struct->value) {
$struct->value = array($attr, 'PUT VALUE HERE');
}
}
if (!empty($cssprop)) {
$struct = $struct->getChild(HTMLPurifier_ErrorStruct::CSSPROP, $cssprop);
if (!$struct->value) {
// if we tokenize CSS this might be a little more difficult to do
$struct->value = array($cssprop, 'PUT VALUE HERE');
}
}
// Ok, structs are all setup, now time to register the error
$struct->addError($severity, $msg);
} | Sends an error message to the collector for later use
@param int $severity Error severity, PHP error style (don't use E_USER_)
@param string $msg Error message text | send | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getRaw()
{
return $this->errors;
} | Retrieves raw error data for custom formatter to use | getRaw | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getHTMLFormatted($config, $errors = null)
{
$ret = array();
$this->generator = new HTMLPurifier_Generator($config, $this->context);
if ($errors === null) {
$errors = $this->errors;
}
// 'At line' message needs to be removed
// generation code for new structure goes here. It needs to be recursive.
foreach ($this->lines as $line => $col_array) {
if ($line == -1) {
continue;
}
foreach ($col_array as $col => $struct) {
$this->_renderStruct($ret, $struct, $line, $col);
}
}
if (isset($this->lines[-1])) {
$this->_renderStruct($ret, $this->lines[-1]);
}
if (empty($errors)) {
return '<p>' . $this->locale->getMessage('ErrorCollector: No errors') . '</p>';
} else {
return '<ul><li>' . implode('</li><li>', $ret) . '</li></ul>';
}
} | Default HTML formatting implementation for error messages
@param HTMLPurifier_Config $config Configuration, vital for HTML output nature
@param array $errors Errors array to display; used for recursion.
@return string | getHTMLFormatted | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function preFilter($html, $config, $context)
{
return $html;
} | Pre-processor function, handles HTML before HTML Purifier
@param string $html
@param HTMLPurifier_Config $config
@param HTMLPurifier_Context $context
@return string | preFilter | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function postFilter($html, $config, $context)
{
return $html;
} | Post-processor function, handles HTML after HTML Purifier
@param string $html
@param HTMLPurifier_Config $config
@param HTMLPurifier_Context $context
@return string | postFilter | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function generateFromTokens($tokens)
{
if (!$tokens) {
return '';
}
// Basic algorithm
$html = '';
for ($i = 0, $size = count($tokens); $i < $size; $i++) {
if ($this->_scriptFix && $tokens[$i]->name === 'script'
&& $i + 2 < $size && $tokens[$i+2] instanceof HTMLPurifier_Token_End) {
// script special case
// the contents of the script block must be ONE token
// for this to work.
$html .= $this->generateFromToken($tokens[$i++]);
$html .= $this->generateScriptFromToken($tokens[$i++]);
}
$html .= $this->generateFromToken($tokens[$i]);
}
// Tidy cleanup
if (extension_loaded('tidy') && $this->config->get('Output.TidyFormat')) {
$tidy = new Tidy;
$tidy->parseString(
$html,
array(
'indent'=> true,
'output-xhtml' => $this->_xhtml,
'show-body-only' => true,
'indent-spaces' => 2,
'wrap' => 68,
),
'utf8'
);
$tidy->cleanRepair();
$html = (string) $tidy; // explicit cast necessary
}
// Normalize newlines to system defined value
if ($this->config->get('Core.NormalizeNewlines')) {
$nl = $this->config->get('Output.Newline');
if ($nl === null) {
$nl = PHP_EOL;
}
if ($nl !== "\n") {
$html = str_replace("\n", $nl, $html);
}
}
return $html;
} | Generates HTML from an array of tokens.
@param HTMLPurifier_Token[] $tokens Array of HTMLPurifier_Token
@return string Generated HTML | generateFromTokens | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function generateScriptFromToken($token)
{
if (!$token instanceof HTMLPurifier_Token_Text) {
return $this->generateFromToken($token);
}
// Thanks <http://lachy.id.au/log/2005/05/script-comments>
$data = preg_replace('#//\s*$#', '', $token->data);
return '<!--//--><![CDATA[//><!--' . "\n" . trim($data) . "\n" . '//--><!]]>';
} | Special case processor for the contents of script tags
@param HTMLPurifier_Token $token HTMLPurifier_Token object.
@return string
@warning This runs into problems if there's already a literal
--> somewhere inside the script contents. | generateScriptFromToken | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function escape($string, $quote = null)
{
// Workaround for APC bug on Mac Leopard reported by sidepodcast
// http://htmlpurifier.org/phorum/read.php?3,4823,4846
if ($quote === null) {
$quote = ENT_COMPAT;
}
return htmlspecialchars($string, $quote, 'UTF-8');
} | Escapes raw text data.
@todo This really ought to be protected, but until we have a facility
for properly generating HTML here w/o using tokens, it stays
public.
@param string $string String data to escape for HTML.
@param int $quote Quoting style, like htmlspecialchars. ENT_NOQUOTES is
permissible for non-attribute output.
@return string escaped data. | escape | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function addAttribute($element_name, $attr_name, $def)
{
$module = $this->getAnonymousModule();
if (!isset($module->info[$element_name])) {
$element = $module->addBlankElement($element_name);
} else {
$element = $module->info[$element_name];
}
$element->attr[$attr_name] = $def;
} | Adds a custom attribute to a pre-existing element
@note This is strictly convenience, and does not have a corresponding
method in HTMLPurifier_HTMLModule
@param string $element_name Element name to add attribute to
@param string $attr_name Name of attribute
@param mixed $def Attribute definition, can be string or object, see
HTMLPurifier_AttrTypes for details | addAttribute | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function addBlankElement($element_name)
{
$module = $this->getAnonymousModule();
$element = $module->addBlankElement($element_name);
return $element;
} | Adds a blank element to your HTML definition, for overriding
existing behavior
@param string $element_name
@return HTMLPurifier_ElementDef
@see HTMLPurifier_HTMLModule::addBlankElement() for detailed
parameter and return value descriptions. | addBlankElement | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getAnonymousModule()
{
if (!$this->_anonModule) {
$this->_anonModule = new HTMLPurifier_HTMLModule();
$this->_anonModule->name = 'Anonymous';
}
return $this->_anonModule;
} | Retrieves a reference to the anonymous module, so you can
bust out advanced features without having to make your own
module.
@return HTMLPurifier_HTMLModule | getAnonymousModule | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function __construct()
{
$this->manager = new HTMLPurifier_HTMLModuleManager();
} | Performs low-cost, preliminary initialization. | __construct | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
protected function processModules($config)
{
if ($this->_anonModule) {
// for user specific changes
// this is late-loaded so we don't have to deal with PHP4
// reference wonky-ness
$this->manager->addModule($this->_anonModule);
unset($this->_anonModule);
}
$this->manager->setup($config);
$this->doctype = $this->manager->doctype;
foreach ($this->manager->modules as $module) {
foreach ($module->info_tag_transform as $k => $v) {
if ($v === false) {
unset($this->info_tag_transform[$k]);
} else {
$this->info_tag_transform[$k] = $v;
}
}
foreach ($module->info_attr_transform_pre as $k => $v) {
if ($v === false) {
unset($this->info_attr_transform_pre[$k]);
} else {
$this->info_attr_transform_pre[$k] = $v;
}
}
foreach ($module->info_attr_transform_post as $k => $v) {
if ($v === false) {
unset($this->info_attr_transform_post[$k]);
} else {
$this->info_attr_transform_post[$k] = $v;
}
}
foreach ($module->info_injector as $k => $v) {
if ($v === false) {
unset($this->info_injector[$k]);
} else {
$this->info_injector[$k] = $v;
}
}
}
$this->info = $this->manager->getElements();
$this->info_content_sets = $this->manager->contentSets->lookup;
} | Extract out the information from the manager
@param HTMLPurifier_Config $config | processModules | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getChildDef($def)
{
return false;
} | Retrieves a proper HTMLPurifier_ChildDef subclass based on
content_model and content_model_type member variables of
the HTMLPurifier_ElementDef class. There is a similar function
in HTMLPurifier_HTMLDefinition.
@param HTMLPurifier_ElementDef $def
@return HTMLPurifier_ChildDef subclass | getChildDef | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function addBlankElement($element)
{
if (!isset($this->info[$element])) {
$this->elements[] = $element;
$this->info[$element] = new HTMLPurifier_ElementDef();
$this->info[$element]->standalone = false;
} else {
trigger_error("Definition for $element already exists in module, cannot redefine");
}
return $this->info[$element];
} | Convenience function that creates a totally blank, non-standalone
element.
@param string $element Name of element to create
@return HTMLPurifier_ElementDef Created element | addBlankElement | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function addElementToContentSet($element, $type)
{
if (!isset($this->content_sets[$type])) {
$this->content_sets[$type] = '';
} else {
$this->content_sets[$type] .= ' | ';
}
$this->content_sets[$type] .= $element;
} | Convenience function that registers an element to a content set
@param string $element Element to register
@param string $type Name content set (warning: case sensitive, usually upper-case
first letter) | addElementToContentSet | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function parseContents($contents)
{
if (!is_string($contents)) {
return array(null, null);
} // defer
switch ($contents) {
// check for shorthand content model forms
case 'Empty':
return array('empty', '');
case 'Inline':
return array('optional', 'Inline | #PCDATA');
case 'Flow':
return array('optional', 'Flow | #PCDATA');
}
list($content_model_type, $content_model) = explode(':', $contents);
$content_model_type = strtolower(trim($content_model_type));
$content_model = trim($content_model);
return array($content_model_type, $content_model);
} | Convenience function that transforms single-string contents
into separate content model and content model type
@param string $contents Allowed children in form of:
"$content_model_type: $content_model"
@return array
@note If contents is an object, an array of two nulls will be
returned, and the callee needs to take the original $contents
and use it directly. | parseContents | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function mergeInAttrIncludes(&$attr, $attr_includes)
{
if (!is_array($attr_includes)) {
if (empty($attr_includes)) {
$attr_includes = array();
} else {
$attr_includes = array($attr_includes);
}
}
$attr[0] = $attr_includes;
} | Convenience function that merges a list of attribute includes into
an attribute array.
@param array $attr Reference to attr array to modify
@param array $attr_includes Array of includes / string include to merge in | mergeInAttrIncludes | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function makeLookup($list)
{
if (is_string($list)) {
$list = func_get_args();
}
$ret = array();
foreach ($list as $value) {
if (is_null($value)) {
continue;
}
$ret[$value] = true;
}
return $ret;
} | Convenience function that generates a lookup table with boolean
true as value.
@param string $list List of values to turn into a lookup
@note You can also pass an arbitrary number of arguments in
place of the regular argument
@return array array equivalent of list | makeLookup | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function setup($config)
{
} | Lazy load construction of the module after determining whether
or not it's needed, and also when a finalized configuration object
is available.
@param HTMLPurifier_Config $config | setup | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function registerModule($module, $overload = false)
{
if (is_string($module)) {
// attempt to load the module
$original_module = $module;
$ok = false;
foreach ($this->prefixes as $prefix) {
$module = $prefix . $original_module;
if (class_exists($module)) {
$ok = true;
break;
}
}
if (!$ok) {
$module = $original_module;
if (!class_exists($module)) {
trigger_error(
$original_module . ' module does not exist',
E_USER_ERROR
);
return;
}
}
$module = new $module();
}
if (empty($module->name)) {
trigger_error('Module instance of ' . get_class($module) . ' must have name');
return;
}
if (!$overload && isset($this->registeredModules[$module->name])) {
trigger_error('Overloading ' . $module->name . ' without explicit overload parameter', E_USER_WARNING);
}
$this->registeredModules[$module->name] = $module;
} | Registers a module to the recognized module list, useful for
overloading pre-existing modules.
@param $module Mixed: string module name, with or without
HTMLPurifier_HTMLModule prefix, or instance of
subclass of HTMLPurifier_HTMLModule.
@param $overload Boolean whether or not to overload previous modules.
If this is not set, and you do overload a module,
HTML Purifier will complain with a warning.
@note This function will not call autoload, you must instantiate
(and thus invoke) autoload outside the method.
@note If a string is passed as a module name, different variants
will be tested in this order:
- Check for HTMLPurifier_HTMLModule_$name
- Check all prefixes with $name in order they were added
- Check for literal object name
- Throw fatal error
If your object name collides with an internal class, specify
your module manually. All modules must have been included
externally: registerModule will not perform inclusions for you! | registerModule | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function addModule($module)
{
$this->registerModule($module);
if (is_object($module)) {
$module = $module->name;
}
$this->userModules[] = $module;
} | Adds a module to the current doctype by first registering it,
and then tacking it on to the active doctype | addModule | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function addPrefix($prefix)
{
$this->prefixes[] = $prefix;
} | Adds a class prefix that registerModule() will use to resolve a
string name to a concrete class | addPrefix | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function processModule($module)
{
if (!isset($this->registeredModules[$module]) || is_object($module)) {
$this->registerModule($module);
}
$this->modules[$module] = $this->registeredModules[$module];
} | Takes a module and adds it to the active module collection,
registering it if necessary. | processModule | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getElements()
{
$elements = array();
foreach ($this->modules as $module) {
if (!$this->trusted && !$module->safe) {
continue;
}
foreach ($module->info as $name => $v) {
if (isset($elements[$name])) {
continue;
}
$elements[$name] = $this->getElement($name);
}
}
// remove dud elements, this happens when an element that
// appeared to be safe actually wasn't
foreach ($elements as $n => $v) {
if ($v === false) {
unset($elements[$n]);
}
}
return $elements;
} | Retrieves merged element definitions.
@return Array of HTMLPurifier_ElementDef | getElements | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public static function build($config, $context)
{
$id_accumulator = new HTMLPurifier_IDAccumulator();
$id_accumulator->load($config->get('Attr.IDBlacklist'));
return $id_accumulator;
} | Builds an IDAccumulator, also initializing the default blacklist
@param HTMLPurifier_Config $config Instance of HTMLPurifier_Config
@param HTMLPurifier_Context $context Instance of HTMLPurifier_Context
@return HTMLPurifier_IDAccumulator Fully initialized HTMLPurifier_IDAccumulator | build | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function add($id)
{
if (isset($this->ids[$id])) {
return false;
}
return $this->ids[$id] = true;
} | Add an ID to the lookup table.
@param string $id ID to be added.
@return bool status, true if success, false if there's a dupe | add | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function load($array_of_ids)
{
foreach ($array_of_ids as $id) {
$this->ids[$id] = true;
}
} | Load a list of IDs into the lookup table
@param $array_of_ids Array of IDs to load
@note This function doesn't care about duplicates | load | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function rewindOffset($offset)
{
$this->rewindOffset = $offset;
} | Rewind to a spot to re-perform processing. This is useful if you
deleted a node, and now need to see if this change affected any
earlier nodes. Rewinding does not affect other injectors, and can
result in infinite loops if not used carefully.
@param bool|int $offset
@warning HTML Purifier will prevent you from fast-forwarding with this
function. | rewindOffset | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getRewindOffset()
{
$r = $this->rewindOffset;
$this->rewindOffset = false;
return $r;
} | Retrieves rewind offset, and then unsets it.
@return bool|int | getRewindOffset | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function prepare($config, $context)
{
$this->htmlDefinition = $config->getHTMLDefinition();
// Even though this might fail, some unit tests ignore this and
// still test checkNeeded, so be careful. Maybe get rid of that
// dependency.
$result = $this->checkNeeded($config);
if ($result !== false) {
return $result;
}
$this->currentNesting =& $context->get('CurrentNesting');
$this->currentToken =& $context->get('CurrentToken');
$this->inputZipper =& $context->get('InputZipper');
return false;
} | Prepares the injector by giving it the config and context objects:
this allows references to important variables to be made within
the injector. This function also checks if the HTML environment
will work with the Injector (see checkNeeded()).
@param HTMLPurifier_Config $config
@param HTMLPurifier_Context $context
@return bool|string Boolean false if success, string of missing needed element/attribute if failure | prepare | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function checkNeeded($config)
{
$def = $config->getHTMLDefinition();
foreach ($this->needed as $element => $attributes) {
if (is_int($element)) {
$element = $attributes;
}
if (!isset($def->info[$element])) {
return $element;
}
if (!is_array($attributes)) {
continue;
}
foreach ($attributes as $name) {
if (!isset($def->info[$element]->attr[$name])) {
return "$element.$name";
}
}
}
return false;
} | This function checks if the HTML environment
will work with the Injector: if p tags are not allowed, the
Auto-Paragraphing injector should not be enabled.
@param HTMLPurifier_Config $config
@return bool|string Boolean false if success, string of missing needed element/attribute if failure | checkNeeded | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function allowsElement($name)
{
if (!empty($this->currentNesting)) {
$parent_token = array_pop($this->currentNesting);
$this->currentNesting[] = $parent_token;
$parent = $this->htmlDefinition->info[$parent_token->name];
} else {
$parent = $this->htmlDefinition->info_parent_def;
}
if (!isset($parent->child->elements[$name]) || isset($parent->excludes[$name])) {
return false;
}
// check for exclusion
for ($i = count($this->currentNesting) - 2; $i >= 0; $i--) {
$node = $this->currentNesting[$i];
$def = $this->htmlDefinition->info[$node->name];
if (isset($def->excludes[$name])) {
return false;
}
}
return true;
} | Tests if the context node allows a certain element
@param string $name Name of element to test for
@return bool True if element is allowed, false if it is not | allowsElement | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
protected function forward(&$i, &$current)
{
if ($i === null) {
$i = count($this->inputZipper->back) - 1;
} else {
$i--;
}
if ($i < 0) {
return false;
}
$current = $this->inputZipper->back[$i];
return true;
} | Iterator function, which starts with the next token and continues until
you reach the end of the input tokens.
@warning Please prevent previous references from interfering with this
functions by setting $i = null beforehand!
@param int $i Current integer index variable for inputTokens
@param HTMLPurifier_Token $current Current token variable.
Do NOT use $token, as that variable is also a reference
@return bool | forward | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
protected function forwardUntilEndToken(&$i, &$current, &$nesting)
{
$result = $this->forward($i, $current);
if (!$result) {
return false;
}
if ($nesting === null) {
$nesting = 0;
}
if ($current instanceof HTMLPurifier_Token_Start) {
$nesting++;
} elseif ($current instanceof HTMLPurifier_Token_End) {
if ($nesting <= 0) {
return false;
}
$nesting--;
}
return true;
} | Similar to _forward, but accepts a third parameter $nesting (which
should be initialized at 0) and stops when we hit the end tag
for the node $this->inputIndex starts in.
@param int $i Current integer index variable for inputTokens
@param HTMLPurifier_Token $current Current token variable.
Do NOT use $token, as that variable is also a reference
@param int $nesting
@return bool | forwardUntilEndToken | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
protected function backward(&$i, &$current)
{
if ($i === null) {
$i = count($this->inputZipper->front) - 1;
} else {
$i--;
}
if ($i < 0) {
return false;
}
$current = $this->inputZipper->front[$i];
return true;
} | Iterator function, starts with the previous token and continues until
you reach the beginning of input tokens.
@warning Please prevent previous references from interfering with this
functions by setting $i = null beforehand!
@param int $i Current integer index variable for inputTokens
@param HTMLPurifier_Token $current Current token variable.
Do NOT use $token, as that variable is also a reference
@return bool | backward | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function handleText(&$token)
{
} | Handler that is called when a text token is processed | handleText | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function handleElement(&$token)
{
} | Handler that is called when a start or empty token is processed | handleElement | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function handleEnd(&$token)
{
$this->notifyEnd($token);
} | Handler that is called when an end token is processed | handleEnd | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function notifyEnd($token)
{
} | Notifier that is called when an end token is processed
@param HTMLPurifier_Token $token Current token variable.
@note This differs from handlers in that the token is read-only
@deprecated | notifyEnd | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function load()
{
if ($this->_loaded) {
return;
}
$factory = HTMLPurifier_LanguageFactory::instance();
$factory->loadLanguage($this->code);
foreach ($factory->keys as $key) {
$this->$key = $factory->cache[$this->code][$key];
}
$this->_loaded = true;
} | Loads language object with necessary info from factory cache
@note This is a lazy loader | load | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getMessage($key)
{
if (!$this->_loaded) {
$this->load();
}
if (!isset($this->messages[$key])) {
return "[$key]";
}
return $this->messages[$key];
} | Retrieves a localised message.
@param string $key string identifier of message
@return string localised message | getMessage | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getErrorName($int)
{
if (!$this->_loaded) {
$this->load();
}
if (!isset($this->errorNames[$int])) {
return "[Error: $int]";
}
return $this->errorNames[$int];
} | Retrieves a localised error name.
@param int $int error number, corresponding to PHP's error reporting
@return string localised message | getErrorName | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function listify($array)
{
$sep = $this->getMessage('Item separator');
$sep_last = $this->getMessage('Item separator last');
$ret = '';
for ($i = 0, $c = count($array); $i < $c; $i++) {
if ($i == 0) {
} elseif ($i + 1 < $c) {
$ret .= $sep;
} else {
$ret .= $sep_last;
}
$ret .= $array[$i];
}
return $ret;
} | Converts an array list into a string readable representation
@param array $array
@return string | listify | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function setup()
{
$this->validator = new HTMLPurifier_AttrDef_Lang();
$this->dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier';
} | Sets up the singleton, much like a constructor
@note Prevents people from getting this outside of the singleton | setup | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function create($config, $context, $code = false)
{
// validate language code
if ($code === false) {
$code = $this->validator->validate(
$config->get('Core.Language'),
$config,
$context
);
} else {
$code = $this->validator->validate($code, $config, $context);
}
if ($code === false) {
$code = 'en'; // malformed code becomes English
}
$pcode = str_replace('-', '_', $code); // make valid PHP classname
static $depth = 0; // recursion protection
if ($code == 'en') {
$lang = new HTMLPurifier_Language($config, $context);
} else {
$class = 'HTMLPurifier_Language_' . $pcode;
$file = $this->dir . '/Language/classes/' . $code . '.php';
if (file_exists($file) || class_exists($class, false)) {
$lang = new $class($config, $context);
} else {
// Go fallback
$raw_fallback = $this->getFallbackFor($code);
$fallback = $raw_fallback ? $raw_fallback : 'en';
$depth++;
$lang = $this->create($config, $context, $fallback);
if (!$raw_fallback) {
$lang->error = true;
}
$depth--;
}
}
$lang->code = $code;
return $lang;
} | Creates a language object, handles class fallbacks
@param HTMLPurifier_Config $config
@param HTMLPurifier_Context $context
@param bool|string $code Code to override configuration with. Private parameter.
@return HTMLPurifier_Language | create | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getFallbackFor($code)
{
$this->loadLanguage($code);
return $this->cache[$code]['fallback'];
} | Returns the fallback language for language
@note Loads the original language into cache
@param string $code language code
@return string|bool | getFallbackFor | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
protected function validate()
{
// Special case:
if ($this->n === '+0' || $this->n === '-0') {
$this->n = '0';
}
if ($this->n === '0' && $this->unit === false) {
return true;
}
if (!ctype_lower($this->unit)) {
$this->unit = strtolower($this->unit);
}
if (!isset(HTMLPurifier_Length::$allowedUnits[$this->unit])) {
return false;
}
// Hack:
$def = new HTMLPurifier_AttrDef_CSS_Number();
$result = $def->validate($this->n, false, false);
if ($result === false) {
return false;
}
$this->n = $result;
return true;
} | Validates the number and unit.
@return bool | validate | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function toString()
{
if (!$this->isValid()) {
return false;
}
return $this->n . $this->unit;
} | Returns string representation of number.
@return string | toString | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function getN()
{
return $this->n;
} | Retrieves string numeric magnitude.
@return string | getN | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function isValid()
{
if ($this->isValid === null) {
$this->isValid = $this->validate();
}
return $this->isValid;
} | Returns true if this length unit is valid.
@return bool | isValid | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function compareTo($l)
{
if ($l === false) {
return false;
}
if ($l->unit !== $this->unit) {
$converter = new HTMLPurifier_UnitConverter();
$l = $converter->convert($l, $this->unit);
if ($l === false) {
return false;
}
}
return $this->n - $l->n;
} | Compares two lengths, and returns 1 if greater, -1 if less and 0 if equal.
@param HTMLPurifier_Length $l
@return int
@warning If both values are too large or small, this calculation will
not work properly | compareTo | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public static function create($config)
{
if (!($config instanceof HTMLPurifier_Config)) {
$lexer = $config;
trigger_error(
"Passing a prototype to
HTMLPurifier_Lexer::create() is deprecated, please instead
use %Core.LexerImpl",
E_USER_WARNING
);
} else {
$lexer = $config->get('Core.LexerImpl');
}
$needs_tracking =
$config->get('Core.MaintainLineNumbers') ||
$config->get('Core.CollectErrors');
$inst = null;
if (is_object($lexer)) {
$inst = $lexer;
} else {
if (is_null($lexer)) {
do {
// auto-detection algorithm
if ($needs_tracking) {
$lexer = 'DirectLex';
break;
}
if (class_exists('DOMDocument') &&
method_exists('DOMDocument', 'loadHTML') &&
!extension_loaded('domxml')
) {
// check for DOM support, because while it's part of the
// core, it can be disabled compile time. Also, the PECL
// domxml extension overrides the default DOM, and is evil
// and nasty and we shan't bother to support it
$lexer = 'DOMLex';
} else {
$lexer = 'DirectLex';
}
} while (0);
} // do..while so we can break
// instantiate recognized string names
switch ($lexer) {
case 'DOMLex':
$inst = new HTMLPurifier_Lexer_DOMLex();
break;
case 'DirectLex':
$inst = new HTMLPurifier_Lexer_DirectLex();
break;
case 'PH5P':
$inst = new HTMLPurifier_Lexer_PH5P();
break;
default:
throw new HTMLPurifier_Exception(
"Cannot instantiate unrecognized Lexer type " .
htmlspecialchars($lexer)
);
}
}
if (!$inst) {
throw new HTMLPurifier_Exception('No lexer was instantiated');
}
// once PHP DOM implements native line numbers, or we
// hack out something using XSLT, remove this stipulation
if ($needs_tracking && !$inst->tracksLineNumbers) {
throw new HTMLPurifier_Exception(
'Cannot use lexer that does not support line numbers with ' .
'Core.MaintainLineNumbers or Core.CollectErrors (use DirectLex instead)'
);
}
return $inst;
} | Retrieves or sets the default Lexer as a Prototype Factory.
By default HTMLPurifier_Lexer_DOMLex will be returned. There are
a few exceptions involving special features that only DirectLex
implements.
@note The behavior of this class has changed, rather than accepting
a prototype object, it now accepts a configuration object.
To specify your own prototype, set %Core.LexerImpl to it.
This change in behavior de-singletonizes the lexer object.
@param HTMLPurifier_Config $config
@return HTMLPurifier_Lexer
@throws HTMLPurifier_Exception | create | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function parseData($string)
{
// following functions require at least one character
if ($string === '') {
return '';
}
// subtracts amps that cannot possibly be escaped
$num_amp = substr_count($string, '&') - substr_count($string, '& ') -
($string[strlen($string) - 1] === '&' ? 1 : 0);
if (!$num_amp) {
return $string;
} // abort if no entities
$num_esc_amp = substr_count($string, '&');
$string = strtr($string, $this->_special_entity2str);
// code duplication for sake of optimization, see above
$num_amp_2 = substr_count($string, '&') - substr_count($string, '& ') -
($string[strlen($string) - 1] === '&' ? 1 : 0);
if ($num_amp_2 <= $num_esc_amp) {
return $string;
}
// hmm... now we have some uncommon entities. Use the callback.
$string = $this->_entity_parser->substituteSpecialEntities($string);
return $string;
} | Parses special entities into the proper characters.
This string will translate escaped versions of the special characters
into the correct ones.
@warning
You should be able to treat the output of this function as
completely parsed, but that's only because all other entities should
have been handled previously in substituteNonSpecialEntities()
@param string $string String character data to be parsed.
@return string Parsed character data. | parseData | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
public function tokenizeHTML($string, $config, $context)
{
trigger_error('Call to abstract class', E_USER_ERROR);
} | Lexes an HTML string into tokens.
@param $string String HTML.
@param HTMLPurifier_Config $config
@param HTMLPurifier_Context $context
@return HTMLPurifier_Token[] array representation of HTML. | tokenizeHTML | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
protected static function escapeCDATA($string)
{
return preg_replace_callback(
'/<!\[CDATA\[(.+?)\]\]>/s',
array('HTMLPurifier_Lexer', 'CDATACallback'),
$string
);
} | Translates CDATA sections into regular sections (through escaping).
@param string $string HTML string to process.
@return string HTML with CDATA sections escaped. | escapeCDATA | php | boonex/dolphin.pro | plugins/htmlpurifier/HTMLPurifier.standalone.php | https://github.com/boonex/dolphin.pro/blob/master/plugins/htmlpurifier/HTMLPurifier.standalone.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.