first commit
This commit is contained in:
129
wp-content/plugins/brizy/editor/helper/dom-tag.php
Normal file
129
wp-content/plugins/brizy/editor/helper/dom-tag.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Editor_Helper_DomTag {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $html_tag;
|
||||
|
||||
/**
|
||||
* Brizy_DOM_Tag constructor.
|
||||
*
|
||||
* @param string $tag
|
||||
*/
|
||||
public function __construct( $tag ) {
|
||||
$this->html_tag = trim( $tag );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_tag() {
|
||||
return $this->html_tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function get_attr( $name ) {
|
||||
preg_match( "/$name\s*=\s*\"([^\"]*)\"/i", $this->get_tag(), $res );
|
||||
|
||||
if ( isset( $res[1] ) ) {
|
||||
return $res[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_attrs() {
|
||||
$res = array();
|
||||
preg_match_all( "/(\S+)=(?:\"(.[^\"]*)\")/", $this->get_tag(), $res );
|
||||
|
||||
$l = count( $res[0] );
|
||||
|
||||
$attrs = array();
|
||||
|
||||
for ( $i = 0; $i < $l; $i ++ ) {
|
||||
$attrs[ $res[1][ $i ] ] = $res[2][ $i ];
|
||||
}
|
||||
|
||||
return $attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_content() {
|
||||
|
||||
$res = preg_match( "/\/>$/i", $this->get_tag() );
|
||||
|
||||
if ( $res === 1 ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$html = $this->get_tag();
|
||||
$start = strpos( $html, ">" )+1;
|
||||
$end = strrpos( $html, "<" );
|
||||
|
||||
return substr($html,$start,$end-$start);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pattern
|
||||
*
|
||||
* @return Brizy_Editor_Helper_DomTag[]
|
||||
*/
|
||||
public function get_tags( $pattern ) {
|
||||
$tags = array();
|
||||
|
||||
preg_match_all( $pattern, $this->get_tag(), $matches );
|
||||
|
||||
foreach ( $matches[0] as $value ) {
|
||||
$tags[] = new Brizy_Editor_Helper_DomTag( $value );
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Brizy_Editor_Helper_DomTag[]
|
||||
*/
|
||||
public function get_links() {
|
||||
|
||||
return $this->get_tags( '/(<link[^>]+>)/is' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $rel_value
|
||||
*
|
||||
* @return Brizy_Editor_Helper_DomTag[]
|
||||
*/
|
||||
public function get_links_by_rel( $rel_value ) {
|
||||
|
||||
return $this->get_tags( "/(<link\s+(?=[^>]*rel=\"{$rel_value}\").[^>]*>)/is" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Brizy_Editor_Helper_DomTag[]
|
||||
*/
|
||||
public function get_scripts() {
|
||||
return $this->get_tags( '/(<script(.*?)<\/script>)/is' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Brizy_Editor_Helper_DomTag[]
|
||||
*/
|
||||
public function get_styles() {
|
||||
return $this->get_tags( '/(<style(.*?)<\/style>)/is' );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
62
wp-content/plugins/brizy/editor/helper/dom.php
Normal file
62
wp-content/plugins/brizy/editor/helper/dom.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Editor_Helper_Dom extends Brizy_Editor_Helper_DomTag {
|
||||
|
||||
|
||||
/**
|
||||
* @return Brizy_Editor_Helper_DomTag
|
||||
*/
|
||||
public function get_head() {
|
||||
$headPos = strpos( $this->get_html(), "<head" );
|
||||
$headEndPos = strpos( $this->get_html(), "</head>" );
|
||||
$headString = substr( $this->get_html(), $headPos, $headEndPos - $headPos + 7 );
|
||||
|
||||
return new Brizy_Editor_Helper_DomTag( $headString );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|Brizy_Editor_Helper_DomTag
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
$bodyPos = strpos( $this->get_html(), "<body" );
|
||||
$bodyEndPos = strpos( $this->get_html(), "</body>" );
|
||||
$bodyString = substr( $this->get_html(), $bodyPos, $bodyEndPos - $bodyPos + 7 );
|
||||
|
||||
return new Brizy_Editor_Helper_DomTag( $bodyString );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the tag html
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_html() {
|
||||
return $this->get_tag();
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo: Move this somewhere else..
|
||||
*
|
||||
* @param array $tags
|
||||
* @param $attr
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_attributes( $tags, $attr ) {
|
||||
$list = array();
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$link = trim( $tag->get_attr( $attr ) );
|
||||
|
||||
if ( empty( $link ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] = $link;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
30
wp-content/plugins/brizy/editor/helper/post-static.php
Normal file
30
wp-content/plugins/brizy/editor/helper/post-static.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
die( 'Direct access forbidden.' );
|
||||
}
|
||||
|
||||
class Brizy_Editor_Helper_PostStatic {
|
||||
|
||||
private $html;
|
||||
|
||||
public function __construct( $html ) {
|
||||
$this->html = $html;
|
||||
}
|
||||
|
||||
public function save_path() {
|
||||
static $path;
|
||||
|
||||
return $path ? $path : $path = $this->uploads_dir() . DIRECTORY_SEPARATOR . self::DIR;
|
||||
}
|
||||
|
||||
private function uploads_dir() {
|
||||
$upload_dir = Brizy_Admin_UploadDir::getUploadDir();
|
||||
|
||||
return $upload_dir['baseurl'];
|
||||
}
|
||||
|
||||
private function dom() {
|
||||
static $dom;
|
||||
|
||||
return $dom ? $dom : $dom = new Brizy_Editor_Helper_Dom( $this->html );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user