-
Notifications
You must be signed in to change notification settings - Fork 0
DOM Helpers
This class contains DOM-traversal helpers. This is largely focused around making certain \DOMDocument and \DOMXPath tasks easier, but some functionality is independent of those extensions.
Get an array of nodes containing one or more specified classes.
| Type | Description | Notes | Default |
|---|---|---|---|
| DOMDocument|DOMElement | Parent object. | ||
| array | Class(es). | ||
| bool | Match all. | If TRUE, only nodes with every passed class will be returned. Otherwise nodes matching any class will be returned. |
FALSE |
Returns an array containing the matching nodes, if any.
$foo = \blobfolio\common\dom::get_nodes_by_class($dom, 'apples');Generate a \DOMDocument object from a string containing SVG code. This performs some initial setup optimized for SVG content.
| Type | Description |
|---|---|
| string | SVG code. |
Returns a \DOMDocument object (empty on failure).
$svg = file_get_contents('foo.svg');
$dom = \blobfolio\common\dom::load_svg($svg);This is a handy little parser that will take CSS rules (e.g. from <style> tags or a .css file) and hand it back to you in an easily parsable array format.
| Type | Description |
|---|---|
| string | Style code. |
Returns an array containing the parsed styles.
//from a .css file
$css = @file_get_contents('css/styles.css');
//or something like...
$css = $dom->getElementsByTagName('style')->item(0)->nodeValue;
//then parse
$foo = \blobfolio\common\dom::parse_css($css);
/*
Array(
//example of a regular old rule
0 => Array(
[@] => FALSE
[nested] => FALSE
[selectors] => Array(
0 => .blobfolio-about-logo svg
)
[rules] => Array(
[transition] => color .3s ease;
[display] => block;
[width] => 100%;
[height] => auto;
)
[raw] => .blobfolio-about-logo svg{transition:color .3s ease;display:block;width:100%;height:auto;}
),
//example @ rule with regular definitions
1 => Array(
[@] => font-face
[nested] => FALSE
[selectors] => Array(
0 => @font-face
)
[rules] => Array(
[font-family] => "TotallyRealFont";
[src] => url ("../font/3197DB_0_0.woff2") format ("woff2"), url ("../font/3197DB_0_0.woff") format ("woff"), url ("../font/3197DB_0_0.ttf") format ("truetype");
[font-weight] => 700;
[font-style] => normal;
)
[raw] => @font-face{font-family:"TotallyRealFont";src:url ("../font/3197DB_0_0.woff2") format ("woff2"), url ("../font/3197DB_0_0.woff") format ("woff"), url ("../font/3197DB_0_0.ttf") format ("truetype");font-weight:700;font-style:normal;}
),
//example @ rule without any {...} block
2 => Array(
[@] => import
[nested] => FALSE
[selectors] => Array()
[rules] => Array(
0 => @import url (https://fonts.googleapis.com/css?family=Open+Sans);
)
[raw] => @import url (https://fonts.googleapis.com/css?family=Open+Sans);
),
//example nested @ rule
3 => Array(
[@] => media
[nested] => TRUE
[selector] => @media screen only and (min-width: 10em)
[nest] => Array (
0 => Array(
[@] => FALSE
[nested] => FALSE
[selectors] => Array(
0 => #debug-log
)
[rules] => Array(
[background] => red;
)
[raw] => #debug-log{background:red;}
)
)
[raw] => @media screen only and (min-width: 10em){#debug-log{background:red;}}
)
)
*/Remove a namespace and any corresponding tags from a \DOMDocument object.
| Type | Description |
|---|---|
| DOMDocument | DOM object. |
| string | Namespace. |
Returns TRUE or FALSE
\blobfolio\common\dom::remove_namespace($dom, 'foobar');Remove a \DOMElement or \DOMNode.
| Type | Description |
|---|---|
| DOMElement|DOMNode | Node object. |
Returns TRUE or FALSE
$styles = $dom->getElementsByTagName('style');
while($styles->length > 1){
\blobfolio\common\dom::remove_node($styles->item(0));
}Remove one or more nodes.
| Type | Description |
|---|---|
| DOMNodeList | Nodes object. |
Returns TRUE or FALSE
$styles = $dom->getElementsByTagName('style');
\blobfolio\common\dom::remove_nodes($styles);Extract the SVG code from a DOMDocument object (presumably one created with dom::load_svg()).
| Type | Description |
|---|---|
| DOMDocument | DOM object. |
Returns a string, either with the SVG code or empty on failure.
$svg = \blobfolio\common\dom::save_svg($dom);CLI
Constants
Dom Helpers
- ::get_nodes_by_class()
- ::innerhtml()
- ::load_svg()
- ::parse_css()
- ::remove_namespace()
- ::remove_node()
- ::remove_nodes()
- ::save_svg()
Files and Paths
- ::copy()
- ::csv_headers()
- ::data_uri()
- ::dirsize()
- ::empty_dir()
- ::hash_dir()
- ::leadingslash()
- ::line_count()
- ::mkdir()
- ::path()
- ::readfile_chunked()
- ::redirect()
- ::rmdir()
- ::scandir()
- ::trailingslash()
- ::unixslash()
- ::unleadingslash()
- ::unparse_url()
- ::untrailingslash()
Formatting
- ::array_flatten()
- ::array_to_indexed()
- ::ceil()
- ::cidr_to_range()
- ::decode_entities()
- ::decode_escape_entities()
- ::decode_js_entities()
- ::decode_unicode_entities()
- ::excerpt()
- ::floor()
- ::fraction()
- ::inflect()
- ::ip_to_number()
- ::ip_to_subnet()
- ::json()
- ::json_decode()
- ::json_encode()
- ::links()
- ::list_to_array()
- ::money()
- ::number_to_ip()
- ::phone()
- ::round()
- ::to_csv()
- ::to_timezone()
- ::to_xls()
General Data Helpers
- ::array_compare()
- ::array_idiff()
- ::array_iintersect()
- ::array_ikey_exists()
- ::array_isearch()
- ::array_map_recursive()
- ::array_otherize()
- ::array_pop()
- ::array_pop_rand()
- ::array_pop_top()
- ::cc_exp_months()
- ::cc_exp_years()
- ::datediff()
- ::iin_array()
- ::in_range()
- ::ip_in_range()
- ::is_json()
- ::is_utf8()
- ::json_decode_array()
- ::length_in_range()
- ::parse_args()
- ::random_int()
- ::random_string()
- ::switcheroo()
- ::unsetcookie()
Images
Multi-Byte Wrappers
- ::parse_str()
- ::parse_url()
- ::str_pad()
- ::str_split()
- ::strlen()
- ::strpos()
- ::strrev()
- ::strrpos()
- ::strtolower()
- ::strtoupper()
- ::substr()
- ::substr_count()
- ::trim()
- ::ucfirst()
- ::ucwords()
- ::wordwrap()
Sanitizing and Validation
- ::accents()
- ::attribute_value()
- ::au_state()
- ::ca_postal_code()
- ::cc()
- ::control_characters()
- ::country()
- ::csv()
- ::date()
- ::datetime()
- ::domain()
- ::ean()
- ::email()
- ::file_extension()
- ::html()
- ::hostname()
- ::ip()
- ::iri_value()
- ::isbn()
- ::js()
- ::mime()
- ::name()
- ::password()
- ::printable()
- ::province()
- ::quotes()
- ::state()
- ::svg()
- ::timezone()
- ::to_range()
- ::upc()
- ::url()
- ::utf8()
- ::whitespace()
- ::whitespace_multiline()
- ::zip5()
Typecasting