| Server IP : 185.11.201.71 / Your IP : 192.168.7.18 Web Server : Apache/2.4.29 (Ubuntu) System : Linux tech-virtual-machine 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 User : tech ( 1000) PHP Version : 7.4.28 Disable Function : 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_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/wordpress/wp-content/plugins/block-options/includes/ |
Upload File : |
<?php
/**
* Create shortcodes
*
* @package EditorsKit
* @author Jeffrey Carandang from EditorsKit
* @link https://editorskit.com
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* EditorsKit_Shortcodes Class
*
* @since 1.15
*/
class EditorsKit_Shortcodes {
/**
* Constructor
*/
public function __construct() {
add_shortcode( 'editorskit', array( $this, 'register_shortcode' ) );
}
/**
* Register EditorsKit shortcode.
*
* @param array $atts The shortcode attributes.
* @param mixed $content The shortcode content.
*
* @return mixed Returns shortcode display.
*/
public function register_shortcode( $atts, $content = '' ) {
if ( ! isset( $atts['display'] ) ) {
return $content;
}
$tag = 'div';
if ( isset( $atts['tag'] ) ) {
$tag = $atts['tag'];
}
$content = '<' . $tag . ' class="editorskit-shortcode">';
switch ( $atts['display'] ) {
case 'wordcount':
$wordcount = $this->wordcount( $atts, $content );
$content .= $wordcount;
if ( empty( $wordcount ) ) {
return false;
}
break;
default:
// code...
break;
}
$content .= '</' . $tag . '>';
return $content;
}
/**
* Calculate word count.
*
* @param array $atts The shortcode attributes.
* @param mixed $content The shortcode content.
*
* @return mixed Returns wordcount with content.
*/
public function wordcount( $atts, $content ) {
global $post;
if ( ! isset( $post->ID ) ) {
return false;
}
$returned_content = '';
$reading_time = get_post_meta( $post->ID, '_editorskit_reading_time', true );
if ( ! $reading_time && isset( $atts['fallback'] ) && 'true' === $atts['fallback'] ) {
$blocks = '';
if ( function_exists( 'has_blocks' ) && has_blocks( $post->post_content ) ) {
$blocks = parse_blocks( $post->post_content );
}
$text = trim( wp_strip_all_tags( $post->post_content ) );
$text = strip_shortcodes( $text );
$wordcount = str_word_count( $text );
$word_per_seconds = ( $wordcount / 275 ) * 60;
$media_blocks = array( 'core/image', 'core/gallery', 'core/cover' );
if ( ! empty( $blocks ) ) {
$i = 12;
foreach ( $blocks as $key => $block ) {
if ( in_array( $block['blockName'], $media_blocks ) ) { // phpcs:ignore
$word_per_seconds = $word_per_seconds + $i;
if ( $i > 3 ) {
$i--;
}
}
}
}
$word_per_minute = $word_per_seconds / 60;
if ( $word_per_minute < 1 ) {
$word_per_minute = 1;
}
$reading_time = round( $word_per_minute );
}
if ( ! $reading_time ) {
return false;
}
if ( isset( $atts['before'] ) ) {
$returned_content .= $atts['before'];
}
$returned_content .= $reading_time;
if ( isset( $atts['after'] ) ) {
$returned_content .= $atts['after'];
}
return $returned_content;
}
}
return new EditorsKit_Shortcodes();