| Server IP : 47.82.179.145 / Your IP : 216.73.217.129 Web Server : nginx/1.26.3 System : Linux iZt4n9czhka2zvqfajdlr2Z 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64 User : www ( 1001) PHP Version : 8.3.30 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/scuipturepactory.com/wp-content/themes/plover/core/src/Toolkits/Html/ |
Upload File : |
<?php
namespace Plover\Core\Toolkits\Html;
use DOMElement;
use Plover\Core\Toolkits\StyleEngine;
/**
* Wrapper for DOMElement
*
* @since 1.0.0
*/
class Element {
/**
* @var DOMElement
*/
protected $el;
/**
* @param DOMElement $el
*/
public function __construct( DOMElement $el ) {
$this->el = $el;
}
/**
* @return DOMElement
*/
public function get_dom_element() {
return $this->el;
}
/**
* @param Element $element
*
* @return void
*/
public function append_element( Element $element ) {
$this->el->appendChild( $element->get_dom_element() );
}
/**
* @param string $qualified_name
* @param string $value
*
* @return void
*/
public function set_attribute( string $qualified_name, string $value ) {
$this->el->setAttribute( $qualified_name, $value );
}
/**
* @param string $qualified_name
*
* @return void
*/
public function remove_attribute( string $qualified_name ) {
$this->el->removeAttribute( $qualified_name );
}
/**
* Change current element's tag name
*
* @param string $tag
*
* @return void|null
*/
public function transfer_to( string $tag ) {
if ( ! $this->el->ownerDocument ) {
return null;
}
$child_nodes = [];
foreach ( $this->el->childNodes as $child ) {
$child_nodes[] = $child;
}
$new_element = $this->el->ownerDocument->createElement( $tag );
foreach ( $child_nodes as $child ) {
$child2 = $this->el->ownerDocument->importNode( $child, true );
$new_element->appendChild( $child2 );
}
foreach ( $this->el->attributes as $attr_node ) {
$attr_name = $attr_node->nodeName;
$attr_value = $attr_node->nodeValue;
$new_element->setAttribute( $attr_name, $attr_value );
}
if ( $this->el->parentNode ) {
$this->el->parentNode->replaceChild( $new_element, $this->el );
}
$this->el = $new_element;
}
/**
* Add classnames to element.
*
* @param $classnames
*
* @return void
*/
public function add_classnames( $classnames ) {
$this->el->setAttribute( 'class',
implode( ' ',
array_unique(
array_merge(
$this->classnames_to_array( $this->get_attribute( 'class' ) ),
$this->classnames_to_array( $classnames )
)
) ) );
}
/**
* Convert classnames string to array
*
* @param $classnames
*
* @return array
*/
protected function classnames_to_array( $classnames ) {
if ( is_string( $classnames ) ) {
return array_map( 'trim', explode( ' ', $classnames ) );
}
return is_array( $classnames ) ? $classnames : [];
}
/**
* @param string $qualified_name
*
* @return string
*/
public function get_attribute( string $qualified_name ): string {
return $this->el->getAttribute( $qualified_name );
}
/**
* Remove classnames from element.
*
* @param $classnames
*
* @return void
*/
public function remove_classnames( $classnames ) {
$this->el->setAttribute( 'class',
implode( ' ',
array_diff(
$this->classnames_to_array( $this->get_attribute( 'class' ) ),
$this->classnames_to_array( $classnames )
) ) );
}
/**
* Append inline-styles.
*
* @param $css
*
* @return void
*/
public function add_styles( $css ) {
if ( ! is_array( $css ) ) {
$css = StyleEngine::css_to_declarations( $css );
}
$this->el->setAttribute( 'style',
StyleEngine::compile_css(
array_merge(
StyleEngine::css_to_declarations( $this->get_attribute( 'style' ) ),
$css
)
) );
}
/**
* Get some inline-styles properties.
*
* @param $properties
*
* @return array
*/
public function get_styles( $properties = array() ) {
$styles = StyleEngine::css_to_declarations( $this->get_attribute( 'style' ) );
if ( empty( $properties ) ) {
return $styles;
}
return array_intersect_key( $styles, array_flip( $properties ) );
}
/**
* Remove some inline-styles properties.
*
* @param $properties
*
* @return array
*/
public function remove_styles( $properties = array() ) {
$styles = StyleEngine::css_to_declarations( $this->get_attribute( 'style' ) );
if ( empty( $properties ) ) {
return $styles;
}
$this->set_styles( array_diff_key( $styles, array_flip( $properties ) ) );
return array_intersect_key( $styles, array_flip( $properties ) );
}
/**
* Replace inline-styles.
*
* @param $css
*
* @return void
*/
public function set_styles( $css ) {
if ( ! is_array( $css ) ) {
$css = StyleEngine::css_to_declarations( $css );
}
$this->el->setAttribute( 'style', StyleEngine::compile_css( $css ) );
}
}