| Server IP : 103.48.194.25 / Your IP : 216.73.217.33 Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 User : sieuthimay ( 1016) PHP Version : 8.2.20 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/sieuthimayasia.com/public_html/wp-content/themes/mtw-maycn/inc/ |
Upload File : |
<?php
/**
* Post format parser content.
*
* @package MTWTeam
*/
/**
* MTW_Post_Format class
*/
class MTW_Post_Format {
/**
* //
*
* @param string $content Content of the current post.
* @return array
*/
public static function parse_post_content( $content ) {
$post_format = get_post_format();
$callback = sprintf( 'parse_%s', $post_format );
$class = new static;
$results = array();
if ( method_exists( $class, $callback ) ) {
$results = call_user_func_array( array( $class, $callback ), array( $content ) );
if ( ! empty( $results['shortcode'] ) ) {
$content = str_replace( $results['shortcode'], '', $content );
}
}
/**
* Filter the post content.
*
* @param string $content Content of the current post.
*/
$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]>', $content );
/**
* //
*
* @var array
*/
$return = apply_filters( 'mtwfn_parse_post_content', array(
'data' => $results,
'content' => $content,
'post_format' => $post_format,
) );
return $return;
}
/**
* //
*
* <blockquote cite="Source">
* <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
* <cite>Source</cite>
* </blockquote>
*
* @param string $content Content of the current post to parser.
* @return array
*/
public function parse_quote( $content ) {
if ( ! preg_match( '/<blockquote.*?>((.|\n)*?)<\/blockquote>/', $content, $matches ) ) {
return;
}
$shortcode = $matches[0];
$cite = '';
if ( preg_match( '/cite=["|\'](.*)["|\']/', $shortcode, $cites ) ||
preg_match( '/<cite.*?>(.*)<\/cite>/', $shortcode, $cites ) ) {
$cite = strip_tags( $cites[1] );
}
$quote = strip_tags( $matches[1] );
$quote = str_replace( $cite, '', $quote );
$quote = trim( $quote );
return array(
'cite' => $cite,
'quote' => $quote,
'output' => $shortcode,
'shortcode' => $shortcode,
);
}
/**
* //
*
* @param string $content Content of the current post to parser.
* @return array
*/
public function parse_gallery( $content ) {
if ( ! preg_match( '/\[gallery.+?\]/', $content, $matches ) ) {
return;
}
$shortcode = $matches[0];
preg_match( '/ids=["|\'](.*)["|\']/', $shortcode, $ids );
if ( ! empty( $ids[1] ) ) {
$ids = explode( ',', $ids[1] );
$ids = array_filter( $ids, array( __CLASS__, 'is_valid_id' ) );
}
return array(
'ids' => $ids,
'output' => do_shortcode( $shortcode ),
'shortcode' => $shortcode,
);
}
/**
* //
*
* @param string $content Content of the current post to parser.
* @return array
*/
public function parse_audio( $content ) {
if ( preg_match( '/(\[audio.+?\])(\[\/audio\])?/', $content, $matches ) ) {
return array(
'output' => do_shortcode( $matches[0] ),
'shortcode' => $matches[0],
);
}
return static::parse_oembed( $content );
}
/**
* //
*
* @param string $content Content of the current post to parser.
* @return array
*/
public function parse_video( $content ) {
if ( preg_match( '/(\[video.+?\])(\[\/video\])?/', $content, $matches ) ) {
return array(
'output' => do_shortcode( $matches[0] ),
'shortcode' => $matches[0],
);
}
return static::parse_oembed( $content );
}
/**
* //
*
* @param string $content Content of the current post to parser.
* @return array
*/
public function parse_oembed( $content ) {
global $wp_embed;
if ( preg_match( '/\[embed.+?\]/', $content, $matches ) ) {
$shortcode = $matches[0];
if ( $embed = $wp_embed->run_shortcode( $shortcode ) ) {
return array(
'output' => do_shortcode( $embed ),
'shortcode' => $shortcode,
);
}
}
if ( ! preg_match( '/^\s*(https?:\/\/[^\s"]+)\s*$/im', $content, $matches ) ) {
return;
}
return array(
'link' => $matches[1],
'output' => wp_oembed_get( $matches[1] ),
'shortcode' => $matches[1],
);
}
/**
* //
*
* @param string $content Content of the current post to parser.
* @return array
*/
public function parse_link( $content ) {
if ( ! preg_match( '/^\s*(https?:\/\/[^\s"]+)\s*$/im', $content, $matches ) ) {
return;
}
return array(
'link' => $matches[1],
'output' => $matches[1],
'shortcode' => $matches[1],
);
}
/**
* //
*
* @param integet $id //.
* @return boolean
*/
public static function is_valid_id( $id ) {
return is_numeric( $id );
}
}