Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php add_action( 'init', 'check_license' ); function check_license() { $current_do..
Decoded Output download
<?php
add_action( 'init', 'check_license' );
function check_license() {
$current_domain = $_SERVER['HTTP_HOST'];
$valid_domain = 'ngontinhplus.com';
if ( $current_domain !== $valid_domain ) {
wp_redirect( 'https://ngontinhplus.com' );
exit;
}
}
//-----include file--------//
include_once('metabox.php');
require get_template_directory() . '/options/options.php';
require get_template_directory() . '/options/theme-options.php';
require get_template_directory() . '/options/core.php';
require get_template_directory() . '/options/fixurl/fixurl.php';
foreach(glob(get_template_directory() . "/core/*.php") as $file){
require $file;
}
//--Khung son tho Clasic--//
add_filter('use_block_editor_for_post', '__return_false');
//-----theme custom-------//
add_theme_support('post-thumbnails', array('post', 'post_ngan'));
add_theme_support('post-thumbnails', array('post', 'chap'));
//T thm 2 c nh khi upload thumbnail trn ti khon BTV trnh KDN to thm nh khi leech trn ti khon Admin
if(get_current_user_id() == 2) {
add_image_size('image1', 33, 33, true);
add_image_size('image2', 100, 136, true);
add_image_size('image3', 200, 272, true);
}
//set_post_thumbnail_size( 215, 322, true );
add_theme_support( 'custom-logo' );
add_filter('excerpt_length', 'custom_excerpt_length', 999 );
add_filter('wp_trim_excerpt', 'tw_excerpt_more' );
add_filter('parse_query', 'tw_add_filter');
add_filter('pre_get_posts', 'tw_search_filter');
add_action('init', 'tw_radio_post_type', 0);
add_action('init', 'tw_chap_post_type', 0);
if(is_user_logged_in()) add_action('init', 'error_report_type', 0);
add_action('init', 'tw_add_nguon', 0);
add_action('init', 'tw_add_author', 0);
add_action('init', 'tw_add_prefix', 0);
add_action('wp_ajax_tw_ajax', 'tw_ajax');
add_action('wp_ajax_nopriv_tw_ajax', 'tw_ajax');
add_action('save_post', 'tw_save_post');
add_action('save_post', 'bt_save_post');
// xa b lc ca wordpress
remove_filter( 'the_title', 'wptexturize' );
//-------function------//
function tw_show_post_type($query){
if(!is_single() && !is_admin()){
$post_type = array('post', 'page','post_ngan');
$query->set('post_type', $post_type);
}
return $query;
}
function tw_search_filter( $query ) {
if ( $query->is_search && $query->is_main_query() )
$query->set('post_type', array('post', 'tac-gia','post_ngan'));
}
function tw_save_post($post_id){
$chapterID = isset($_POST['tw_parent']) ? $_POST['tw_parent'] : false;
if (!wp_is_post_revision($post_id) && $chapterID){
remove_action('save_post', 'tw_save_post');
$postdata = array(
'ID' => $post_id,
'post_parent' => $chapterID
);
wp_update_post( $postdata );
}
}
function tw_add_filter($query){
global $pagenow;
if (is_admin() && $pagenow == 'edit.php' && isset($_GET['parent_chap']) && $_GET['parent_chap'] != '') {
$query->query_vars['post_parent'] = $_GET['parent_chap'];
}
}
// TW_GET_CHAP_OPTION
function tw_get_chap_option($id, $chap){
$args = array(
'post_type' => 'chap',
'post_status' => 'publish',
'posts_per_page' => -1,
'post_parent' => $id,
'order' => 'ASC'
);
$wp_query = new wp_query($args);
echo '<select id="chapter_jump" class="btn btn-success form-control" onchange="window.location.href=this.value">';
while($wp_query->have_posts()){
$wp_query->the_post();
$subject = get_the_title();
$pattern = '/(.*)Chng\s*\d+((\s*-\s*\d+)|(\s*\(\s*\d+\s*\))|(\.\d+)*)/i';
preg_match($pattern, $subject, $matches);
if($matches) $title = mb_strimwidth(str_replace('Quyn ', 'Q.', $matches[0]), 0, 19, '..');
else $title = mb_strimwidth(str_replace('Quyn ', 'Q.', get_the_title()), 0, 19, '..');
echo '<option value="'.get_the_permalink().'"';
if($chap == get_the_ID()) echo 'selected';
echo '>'.$title.'</option>';
}
echo '</select>';
}
// TW_GET_NEXT_CHAP
function tw_get_next_chap($id){
global $wpdb;
$current_post_id = get_the_ID();
$query = $wpdb->get_results("select ID from ".$wpdb->posts." where ID > '$current_post_id' AND post_type = 'chap' and post_parent = '$id' and post_status = 'publish' ORDER BY ID ASC LIMIT 1");
if($query){
foreach($query as $chap) {
echo '<a class="btn btn-success" id="next_chap" href="'.get_the_permalink($chap->ID).'"><span class="hidden-xs">Chng tip</span> <span class="glyphicon glyphicon-chevron-right"></span></a>';
}
}
else
echo '<a class="btn btn-success disabled" href="javascript:void(0)" title="Khng hoc cha c chng tip theo" id="next_chap"><span class="hidden-xs">Chng tip</span> <span class="glyphicon glyphicon-chevron-right"></span></a>';
}
// TW_GET_NEXT_NGAN
function tw_get_next_ngan($id){
global $wpdb;
$current_post_id = get_the_ID();
$query = $wpdb->get_results("select ID from ".$wpdb->posts." where ID > '$current_post_id' AND post_type = 'post_ngan' and post_status = 'publish' ORDER BY ID ASC LIMIT 1");
if($query){
foreach($query as $ngan) {
echo '<a title="c tip truyn khc" class="btn btn-success" id="next_chap" href="'.get_the_permalink($ngan->ID).'"><span class="hidden-xs">Truyn sau</span> <span class="glyphicon glyphicon-chevron-right"></span></a>';
}
}
else
echo '<a class="btn btn-success disabled" href="javascript:void(0)" title="Khng c truyn tip theo" id="next_chap"><span class="hidden-xs">Truyn sau</span> <span class="glyphicon glyphicon-chevron-right"></span></a>';
}
// TW_GET_PREV_CHAP
function tw_get_prev_chap($id){
global $wpdb;
$current_post_id = get_the_ID();
$query = $wpdb->get_results("select ID from ".$wpdb->posts." where ID < '$current_post_id' AND post_type = 'chap' and post_parent = '$id' and post_status = 'publish' ORDER BY ID DESC LIMIT 1");
if($query){
foreach($query as $chap) {
echo '<a class="btn btn-success" id="prev_chap" href="'.get_the_permalink($chap->ID).'"><span class="glyphicon glyphicon-chevron-left"></span> <span class="hidden-xs">Chng trc</span></a>';
}
}
else
echo '<a class="btn btn-success disabled" href="javascript:void(0)" title="Khng c chng trc" id="prev_chap"><span class="glyphicon glyphicon-chevron-left"></span> <span class="hidden-xs">Chng trc</span></a>';
}
// TW_GET_PREV_NGAN
function tw_get_prev_ngan($id){
global $wpdb;
$current_post_id = get_the_ID();
$query = $wpdb->get_results("select ID from ".$wpdb->posts." where ID < '$current_post_id' AND post_type = 'post_ngan' and post_status = 'publish' ORDER BY ID DESC LIMIT 1");
if($query){
foreach($query as $ngan) {
echo '<a title="c tip truyn trc " class="btn btn-success" id="prev_chap" href="'.get_the_permalink($ngan->ID).'"><span class="glyphicon glyphicon-chevron-left"></span> <span class="hidden-xs">Truyn trc</span></a>';
}
}
else
echo '<a class="btn btn-success disabled" href="javascript:void(0)" title="Khng c truyn trc trc" id="prev_chap"><span class="glyphicon glyphicon-chevron-left"></span> <span class="hidden-xs">Truyn trc</span></a>';
}
function last_update($custom = false){
$options = get_option('my_option_name');
global $post;
$args = array(
'post_type' => 'chap',
'post_status' => 'publish',
'posts_per_page' => 1,
'post_parent' => $post->ID,
'order' => 'DESC',
'orderby' => 'ID'
);
$c_query = new wp_query($args);
/* if (get_post_meta($post->ID, 'tw_status', true) == 'Hon Thnh') {
echo 'Full';
}
else { */
if($c_query->have_posts()){
while($c_query->have_posts()){
$c_query->the_post();
/*
$timkytu = strpos(get_the_title(),':');
$timkytu3 = strpos(get_the_title(),'-');
$timkytu4 = strpos(get_the_title(),'Chng');
$demkytu = substr_count(get_the_title(),'-');
$timkytu2 = mb_strpos(get_the_title(),'Quyn');
$timkytu22 = mb_strpos(get_the_title(),'Q.');
if(($timkytu4 !== false && $timkytu3 !== false && $timkytu4 == 0 && (($timkytu !== false && $timkytu > $timkytu3) || $timkytu == false)) || (($timkytu2 !== false || $timkytu22 !== false) && ($timkytu2 == 0 || $timkytu22 == 0) && $timkytu3 !== false && (($timkytu !== false && $timkytu < $timkytu3) || ($demkytu >= 2 && $timkytu == false)))) $title2 = explode('-', get_the_title());
else $title2 = explode(':', get_the_title());
if(($timkytu2 !== false || $timkytu22 !== false) && ($timkytu2 == 0 || $timkytu22 == 0) && $timkytu3 !== false && $demkytu >= 2 && $timkytu == false) $title = mb_strimwidth(str_replace('Quyn ', 'Q.', $title2[0].' - '.$title2[1]), 0, 22, '..');
else $title = mb_strimwidth(str_replace('Quyn ', 'Q.', $title2[0]), 0, 19, '..');
*/
$subject = get_the_title();
$pattern = '/(.*)Chng\s*\d+((\s*-\s*\d+)|(\s*\(\s*\d+\s*\))|(\.\d+)*)/i';
preg_match($pattern, $subject, $matches);
if($matches) $title = mb_strimwidth(str_replace('Quyn ', 'Q.', $matches[0]), 0, 19, '..');
else $title = mb_strimwidth(str_replace('Quyn ', 'Q.', get_the_title()), 0, 19, '..');
if($custom){
echo '<span class="chapter-name" title="'.get_the_title().'">'.str_replace(array('Chng ','Chapter '), array('<span class="mini-chap"><span>Chng </span></span>','<span class="mini-chap"><span>Chapter </span></span>'),$title).'</span>';
}
else {
echo '<a class="text-primary" title="'.get_the_title().'" href="'.get_the_permalink().'"><span class="chapter-text"><span>'.str_replace(array('Chng ','Chapter '), array('<span class="mini-chap"><span>Chng </span></span>','<span class="mini-chap"><span>Chapter </span></span>'),$title).'</span></span></a>';
}
}
}
else {
if(get_post_meta($post->ID,'tw_multi_chap',true) == 1){
echo $options['chuaconoidung'] ? $options['chuaconoidung'] : 'Cha c ni dung';
} else {
echo $options['chuaconoidung2'] ? $options['chuaconoidung2'] : 'Cha c ni dung';
}
unset($c_query);
}
//}
}
// TIMEAGO
function timeago() {
global $post;
$date = get_post_time('G', false, $post);
if (empty($date)) {
return __('Pending Post');
}
$chunks = array(
array(60 * 60 * 24 * 365, __('nm'), __('nm')),
array(60 * 60 * 24 * 30, __('thng'), __('thng')),
array(60 * 60 * 24 * 7, __('tun'), __('tun')),
array(60 * 60 * 24, __('ngy'), __('ngy')),
array(60 * 60, __('gi'), __('gi')),
array(60, __('pht'), __('pht')),
array(1, __('giy'), __('giy'))
);
if (!is_numeric($date)) {
$time_chunks = explode(':', str_replace(' ', ':', $date));
$date_chunks = explode('-', str_replace(' ', '-', $date));
$date = gmmktime((int) $time_chunks[1], (int) $time_chunks[2], (int) $time_chunks[3], (int) $date_chunks[1], (int) $date_chunks[2], (int) $date_chunks[0]);
}
$current_time = current_time('mysql', $gmt = 0);
$newer_date = strtotime($current_time);
$since = $newer_date - $date;
if (0 > $since)
return __('sometime');
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
// Finding the biggest chunk (if the chunk fits, break)
if (( $count = floor($since / $seconds) ) != 0)
break;
}
// Set output var
$output = ( 1 == $count ) ? '1 ' . $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
if (!(int) trim($output)) {
$output = '0 ' . __('giy');
}
$output .= __(' trc');
return $output;
}
// TW_AJAX
function tw_ajax(){
switch($_POST['type']){
case 'pagination':
chap_pagination(intval($_POST['id']), intval($_POST['page']));
break;
case 'list_chap':
tw_get_chap_option($_POST['id'], $_POST['chap']);
break;
default:
case 'raty':
$id = $_POST['id'];
$rate = $_POST['score'];
echo tw_update_rate($id, $rate);
break;
}
die();
}
// TW_GET_RATE
function tw_get_rate($postID){
$count_key = 'tw_rate';
$count = get_post_meta($postID, $count_key, true);
if($count == ''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "10";
}
return $count;
}
// TW_GET_TOTAL_RATE
function tw_get_total_rate($postID){
$count_key = 'tw_total_rate';
$count = get_post_meta($postID, $count_key, true);
if($count == ''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0";
}
return $count;
}
// TW_UPDATE_RATE
function tw_update_rate($postID, $rate) {
//update rate
$tw_rate = get_post_meta($postID, 'tw_rate', true);
$tw_rate = $tw_rate + $rate;
update_post_meta($postID, 'tw_rate', $tw_rate);
//update total rate
$count = get_post_meta($postID, 'tw_total_rate', true);
$count++;
update_post_meta($postID, 'tw_total_rate', $count);
return json_encode(array('status' => 'success', 'rateCount' => $count, 'ratePoint' => ceil($tw_rate / $count)));
}
// TW_GET_VIEWS
function tw_get_views($postID){
$count_key = 'tw_views_post';
$count = get_post_meta($postID, $count_key, true);
if($count == ''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, rand(80, 99));
return "99";
}
return number_format($count,0,',','.');
}
// TW_VIEWS
function tw_views($postID) {
$count_key = 'tw_views_post';
$count = get_post_meta($postID, $count_key, true);
if($count == ''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, rand(80, 99));
}
else
{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
// TW_GET_THUMBNAIL
function tw_get_thumbnail($id){
global $post;
if($id){
$post = get_post($id);
}
$thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'image');
$parent_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(wp_get_post_parent_id($post->ID)), 'image');
if($thumbnail_src)
return $thumbnail_src[0];
elseif($parent_thumbnail_src)
return $parent_thumbnail_src[0];
// elseif(preg_match("/(http|https):\/\/[^\s]+(\.gif|\.jpg|\.jpeg|\.png)/is", $post->post_content, $thumb))
// return $thumb[0];
else {
$attachments = get_posts( array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post->ID
) );
if ( $attachments && has_post_thumbnail($id) ) {
foreach ( $attachments as $attachment ) {
$att_image = apply_filters( 'the_title', $attachment->guid );
}
$tim_webp = strpos($att_image, '.webp');
if($tim_webp) return $att_image.'" onerror="this.onerror=null; this.src=\'/wp-content/themes/boxtruyen/images/thumbnail-webp.png\'';
else return $att_image;
} else
return get_template_directory_uri() . '/images/poster.png';
}
}
// REGISTER POST TYPE: ERROR_REPORT
if(is_user_logged_in()) {
function error_report_type(){
$label = array(
'name' => 'Bo li',
'singular_name' => 'Bo li',
'add_new' => 'Thm bo li',
'add_new_item' => 'Thm bo li mi',
'edit_item' => 'Chnh sa bo li',
'new_item' => 'Bo li',
'view_item' => 'Xem bo li',
'search_items' => 'Tm bo li',
'not_found' => 'Khng c bo li no',
'not_found_in_trash' => 'Khng c bo li no trong thng rc',
'all_items' => 'Tt c bo li',
'menu_name' => 'Bo li',
'name_admin_bar' => 'Bo li',
);
$args = array(
'labels' => $label,
'description' => 'Tt c bo li',
'supports' => array( 'title', 'editor', 'parent', 'revisions', 'thumbnail',
),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 3,
'menu_icon' => 'dashicons-warning',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post'
);
register_post_type('error_report', $args);
}
}
// REGISTER POST TYPE: CHAP
function tw_chap_post_type(){
$label = array(
'name' => 'Chng',
'singular_name' => 'Chng',
'add_new' => 'Thm chng mi',
'add_new_item' => 'Thm chng mi',
'edit_item' => 'Chnh sa chng',
'new_item' => 'Chng',
'view_item' => 'Xem chng',
'search_items' => 'Tm chng',
'not_found' => 'Khng c chng no',
'not_found_in_trash' => 'Khng c chng no trong thng rc',
'all_items' => 'Tt c chng',
'menu_name' => 'Chng',
'name_admin_bar' => 'Chng',
);
$args = array(
'labels' => $label,
'description' => 'Tt c chng',
'supports' => array( 'title', 'editor', 'parent', 'revisions', 'thumbnail', 'comments'
),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => false,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => '',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post'
);
register_post_type('chap', $args);
flush_rewrite_rules();
}
// REGISTER TAXONOMY: TAC-GIA
function tw_add_author(){
$args = array(
'labels' => array(
'name' => 'Tc gi',
'singular' => 'Tc gi',
'menu-name' => 'Tc gi',
'all_items' => 'Tt c tc gi',
'edit_item' => 'Chnh sa tc gi',
'view_item' => 'Xem tc gi',
'add_new_item' => 'Thm tc gi',
'new_item_name' => 'Tn tc gi',
'parent_item' => 'Tc gi cha',
'search_items' => 'Tm tc gi',
'popular_items' => 'Tc gi ph bin',
'separate_items_with_commas' => 'Phn tch cc tc gi bng du phy.',
'add_or_remove_items' => 'Thm hoc xa tc gi',
'choose_from_most_used' => 'Chn tc gi dng nhiu nht'
),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_tagcloud' => true,
'show_in_nav_menus' => true
);
register_taxonomy('tac-gia',array('post','post_ngan'), $args);
}
// REGISTER TAXONOMY: NGUN
function tw_add_nguon(){
$args = array(
'labels' => array(
'name' => 'Ngun',
'singular' => 'Ngun',
'menu-name' => 'Ngun',
'all_items' => 'Tt c ngun',
'edit_item' => 'Chnh sa ngun',
'view_item' => 'Xem ngun',
'add_new_item' => 'Thm ngun',
'new_item_name' => 'Tn ngun',
'parent_item' => 'Ngun cha',
'search_items' => 'Tm ngun',
'popular_items' => 'Ngun ph bin',
'separate_items_with_commas' => 'Phn tch cc ngun bng du phy.',
'add_or_remove_items' => 'Thm hoc xa ngun',
'choose_from_most_used' => 'Chn ngun dng nhiu nht'
),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_tagcloud' => true,
'show_in_nav_menus' => true
);
register_taxonomy('nguon-truyen',array('post','post_ngan'), $args);
}
// REGISTER TAXONOMY: TIEN_TO
function tw_add_prefix(){
$args = array(
'labels' => array(
'name' => 'Sticker',
'singular' => 'Sticker',
'menu-name' => 'Sticker',
'all_items' => 'Tt c Sticker',
'edit_item' => 'Chnh sa Sticker',
'view_item' => 'Xem Sticker',
'add_new_item' => 'Thm Sticker',
'new_item_name' => 'Tn Sticker',
'parent_item' => 'Sticker cha',
'search_items' => 'Tm Sticker',
'popular_items' => 'Sticker ph bin',
'separate_items_with_commas' => 'Phn tch cc Sticker bng du phy.',
'add_or_remove_items' => 'Thm hoc xa Sticker',
'choose_from_most_used' => 'Chn Sticker dng nhiu nht'
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_tagcloud' => true,
'show_in_nav_menus' => true
);
register_taxonomy('sticker',array('post','post_ngan'), $args);
}
// GET TIEN_TO AND TRANGTHAI
function get_tien_to($id){
$tiento = get_the_terms($id,'sticker');
if(is_array($tiento)){
foreach ($tiento as $e_tiento){
$termid = $e_tiento->term_id;
$name = $e_tiento->name;
$slug = $e_tiento->slug;
echo '<span class="tien_to tien_to_'.$slug.'">'.$name.'</span> ';
}
}
}
function get_trangthai($id){
$trangthai = get_post_meta($id,'tw_status',true);
$options = get_option('my_option_name');
$hoanthanh = $options['trangthai_hoanthanh'] ? $options['trangthai_hoanthanh'] : 'Hon thnh';
if($trangthai == $hoanthanh){
echo '<span class="tien_to trang_thai_full">'; echo $options['trangthai_hoanthanh'] ? $options['trangthai_hoanthanh'] : 'Hon thnh'; echo '</span> ';
}
}
function get_tien_to_2($id){
$tiento = get_the_terms($id,'sticker');
if(is_array($tiento)){
foreach ($tiento as $e_tiento){
$termid = $e_tiento->term_id;
$name = $e_tiento->name;
$slug = $e_tiento->slug;
echo '<span class="sticker-'.$slug.'">'.$name.'</span>';
}
}
}
function get_tien_to_chu($id){
$tiento = get_the_terms($id,'sticker');
if(is_array($tiento)){
foreach ($tiento as $e_tiento){
$termid = $e_tiento->term_id;
$name = $e_tiento->name;
$slug = $e_tiento->slug;
echo '<span class="tien_to_'.$slug.'">'.$name.'</span> ';
}
}
}
function get_trangthai_chu($id){
$trangthai = get_post_meta($id,'tw_status',true);
$options = get_option('my_option_name');
$hoanthanh = $options['trangthai_hoanthanh'] ? $options['trangthai_hoanthanh'] : 'Hon thnh';
$huybo = $options['trangthai_huybo'] ? $options['trangthai_huybo'] : 'Hy b';
if($trangthai == $hoanthanh){
echo 'Full';
} elseif($trangthai == $huybo){
echo 'Drop';
}
}
function get_trangthai_2($id){
$trangthai = get_post_meta($id,'tw_status',true);
$options = get_option('my_option_name');
$hoanthanh = $options['trangthai_hoanthanh'] ? $options['trangthai_hoanthanh'] : 'Hon thnh';
if($trangthai == $hoanthanh){
echo '<img src="'; echo bloginfo('template_url'); echo '/images/full-label.png" class="full_label"/>';
}
}
//DOC TU DAU
function truyenhot_get_chap_old( $ID_parent ) {
$args = array(
'post_type' => 'chap',
'post_status' => 'publish',
'showposts' => 1,
'post_parent' => $ID_parent,
'order' => 'ASC',
'orderby' => 'ID'
);
$last_query = new wp_query($args);
while($last_query->have_posts()){
$last_query->the_post();
echo '<a href="'.get_the_permalink().'" title="'.get_the_title().'"><button type="button" class="btn button-border"><span class="glyphicon glyphicon-circle-arrow-right"></span> c t u</button></a>';
}
wp_reset_postdata();
}
// REGISTER POST TYPE: Blog_truyen
function tw_radio_post_type(){
$options = get_option('my_option_name');
$label = array(
'name' => $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Blog truyn',
'singular_name' => $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Blog truyn',
'add_new' => 'Thm '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn').' mi',
'add_new_item' => 'Thm '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn').' mi',
'edit_item' => 'Chnh sa '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn'),
'new_item' => $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Blog truyn',
'view_item' => 'Xem '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn'),
'search_items' => 'Tm '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn'),
'not_found' => 'Khng c '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn').' no',
'not_found_in_trash' => 'Khng c '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn').' no trong thng rc',
'all_items' => 'Tt c '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn'),
'menu_name' => $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Blog truyn',
'name_admin_bar' => $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Blog truyn',
);
$args = array(
'labels' => $label,
'description' => 'Tt c '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn'),
'supports' => array('title', 'editor', 'parent', 'thumbnail', 'author','revisions', 'comments'
),
'taxonomies' => array('post_tag', 'category','tac-gia'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-admin-post',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'post'
);
register_post_type('blog', $args);
flush_rewrite_rules();
}
// EXPCERPT
function custom_excerpt_length($length){
return 40;
}
function tw_excerpt_more( $excerpt ) {
return str_replace( '[...]', '...', $excerpt );
}
// CHAP PAGINATION
function chap_pagination($ID_parent, $page) {
$options = get_option('my_option_name');
$chapnum = $options['number'];
$args = array(
'post_type' => 'chap',
'post_status' => 'publish',
'posts_per_page' => $chapnum,
'paged' => $page,
'post_parent' => $ID_parent,
'order' => 'ASC',
'orderby' => 'ID'
);
$my_query = new wp_query($args);
$html = '<div class="col-xs-12 col-sm-6 col-md-6"><ul class="list-chapter">';
$i = 1;
while($my_query->have_posts()){
$my_query->the_post();
if($i == ($chapnum+1))
$html .= '</ul></div><div class="col-xs-12 col-sm-6 col-md-6"><ul class="list-chapter">';
$html .= (is_integer ($i / 2) ? '<li class="chap-left5'.(($i == $chapnum || $i + ($chapnum*$page) - $chapnum == $my_query->found_posts) ? ' last-list' : '').'">' : '<li class="chap-right5'.(($i == $chapnum || $i == $chapnum - 1 || $i + ($chapnum*$page) - $chapnum == $my_query->found_posts || $i + ($chapnum*$page) - $chapnum == $my_query->found_posts - 1) ? ' last-list' : '').'">').
'<span class="glyphicon glyphicon-book right-5"></span>
<a href="'.get_the_permalink().'" title="'.get_the_title().'">
<span class="chapter-text">'.get_the_title().'</span>
</a>
</li>';
++$i;
}
$html .= '</ul></div>';
$pagination = preg_replace("/href=\"(.+?)\"/is", 'href="#"', pagination(true, $my_query->max_num_pages, $page));
echo json_encode(array('list_chap' => $html, 'pagination' => $pagination));
}
// PAGINATION
function pagination($return = false, $max = false, $paged = false) {
global $wp_query;
if($wp_query->max_num_pages <= 1 && !$max)
return 'Trang khng tn ti<br/><br/>';
if(!$paged)
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = (!$max) ? intval($wp_query->max_num_pages) : $max;
$links[] = $paged;
for($i = $paged; $i < $paged + 5; $i++){
if($i <= $max && $i != $paged)
$links[] = $i;
}
for($i = $paged; $i >= ($paged - 5);$i--){
if($i >= 1 && $i != $paged)
$links[] = $i;
}
$html = '<ul class="pagination pagination-sm pagination-chap">' . "
";
// Previous button
if ($paged > 1) {
$prev_page = $paged - 1;
$html .= '<li><a href="'.esc_url( get_pagenum_link( $prev_page ) ).'" title="Prev">Prev</a></li>';
}
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
$html .= '<li '.$class.'><a data-page="1" href="'.esc_url( get_pagenum_link( 1 ) ).'" title="1">u</a></li>';
}
sort( $links );
foreach ( (array) $links as $link ) {
$class = $link == $paged ? ' class="active"' : '';
$html .= '<li '.$class.'><a data-page="'.$link.'" href="'.esc_url( get_pagenum_link( $link ) ).'">'.$link.'</a></li>';
}
// Next button
if ($paged < $max) {
$next_page = $paged + 1;
$html .= '<li><a href="'.esc_url( get_pagenum_link( $next_page ) ).'" title="Next">Next</a></li>';
}
if ( ! in_array( $max, $links ) ) {
$class = $paged == $max ? ' class="active"' : '';
$html .= '<li '.$class.'><a id = "last-catepage" data-page="'.$max.'" href="'.esc_url( get_pagenum_link( $max ) ).'" title="'.$max.'">Cui</a></li>';
}
if(!is_search() && !$_GET['loc']) {
$html .= '<li class="dropup page-nav"><span href="javascript:void(0)" data-toggle="dropdown" style="cursor:pointer">Chn trang <span class="caret"></span></span>
<div class="dropdown-menu dropdown-menu-right" role="menu">
<form action="." name="page_jump" id="page_jump" method="get">
<div class="input-group">';
if(is_category())
$html .= '<input name="page_url" type="hidden" value="'.get_pagenum_link().'">';
else
$html .= '<input name="total-page" type="hidden" value="'.$max.'"><input name="page_url" type="hidden" value="'.get_pagenum_link().'">';
$html .= '<input class="form-control" name="page" type="number" placeholder="S trang..." value="">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">i</button>
</span>
</div>
</form>
</div>
</li>';
}
$html .= '</ul>' . "
";
if($return)
return $html;
else
echo $html;
}
// BREADCRUMB
function the_breadcrumb() {
$options = get_option('my_option_name');
$breadcrumb = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$breadcrumb_ngan = $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Truyn ngn';
global $post;
if (!is_home()) {
echo '<ol class="breadcrumb" itemscope="" itemtype="https://schema.org/BreadcrumbList">';
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="'.get_option('home').'" accesskey="1"><span class="glyphicon glyphicon-home"></span></a><a href="'.get_option('home').'" title="Trang ch" itemprop="item"><span itemprop="name">Trang ch</span></a><meta itemprop="position" content="1"></li>';
if (is_single() && $post->post_type == 'blog') {
$categories = get_the_category();
$separator = ', ';
$output = '';
foreach( $categories as $category ) {
$output .= esc_html( $category->name ) . $separator;
}
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="'.str_replace('runninghorse-tt-display-', '', esc_url( get_category_link( $categories[0]->term_id ) )).'" title="'.trim( $output, $separator ).'" itemprop="item"><span itemprop="name">'.esc_html( $categories[0]->name ).'</span></a><meta itemprop="position" content="2"></li>';
echo '<li class="active" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_permalink().'" title="'.get_the_title().'" itemprop="item"><span itemprop="name">';
the_title();
echo '</span></a></h1><meta itemprop="position" content="3"></li>';
}
elseif (is_single() && $post->post_type != 'chap') {
$categories = get_the_category();
$separator = ', ';
$output = '';
foreach( $categories as $category ) {
$output .= esc_html( $category->name ) . $separator;
}
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="'.esc_url( get_category_link( $categories[0]->term_id ) ).'" title="'.trim( $output, $separator ).'" itemprop="item"><span itemprop="name">'.esc_html( $categories[0]->name ).'</span></a><meta itemprop="position" content="2"></li>';
echo '<li class="active" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_permalink().'" title="'.get_the_title().'" itemprop="item"><span itemprop="name">';
the_title();
echo '</span></a></h1><meta itemprop="position" content="3"></li>';
}
elseif (is_category()) {
$cat = get_category(get_query_var('cat'), false);
echo '<li'.(!get_query_var('paged') ? ' class="active"' : '').' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_category_link($cat->term_id).'" title="'.$cat->cat_name.'" itemprop="item"><span itemprop="name">'.$cat->name.'</span></a></h1><meta itemprop="position" content="2"></li>';
if(get_query_var('paged')){
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active"><a href="'.get_home_url().$_SERVER['REQUEST_URI'].'" title="Trang '.get_query_var('paged').'" itemprop="item"><span itemprop="name">Trang '.get_query_var('paged').'</span></a><meta itemprop="position" content="3"></li>';
}
}
elseif (is_tax()) {
$taxonomy = get_taxonomy(get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) )->taxonomy);
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="#nav" title="'.$taxonomy->label.'" itemprop="item"><span itemprop="name">'.$taxonomy->label.'</span></a><meta itemprop="position" content="2"></li>';
echo '<li'.(!get_query_var('paged') ? ' class="active"' : '').' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.$term->slug.'" title="'.$term->name.'" itemprop="item"><span itemprop="name">'.$term->name.'</span></a></h1><meta itemprop="position" content="3"></li>';
if(get_query_var('paged')){
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active"><a href="'.get_home_url().$_SERVER['REQUEST_URI'].'" title="Trang '.get_query_var('paged').'" itemprop="item"><span itemprop="name">Trang '.get_query_var('paged').'</span></a><meta itemprop="position" content="4"></li>';
}
}
elseif (is_tag()) {
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="#nav" title="Th" itemprop="item"><span itemprop="name">Th</span></a><meta itemprop="position" content="2"></li>';
echo '<li'.(!get_query_var('paged') ? ' class="active"' : '').' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_tag_link(get_queried_object()->term_id).'" title="'.get_queried_object()->name.'" itemprop="item"><span itemprop="name">'.get_queried_object()->name.'</span></a></h1><meta itemprop="position" content="3"></li>';
if(get_query_var('paged')){
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active"><a href="'.get_home_url().$_SERVER['REQUEST_URI'].'" title="Trang '.get_query_var('paged').'" itemprop="item"><span itemprop="name">Trang '.get_query_var('paged').'</span></a><meta itemprop="position" content="4"></li>';
}
}
elseif($post->post_type == 'chap' && !is_search()){
$id_parent = $post->post_parent;
$parent = get_post($id_parent);
$title = $parent->post_title;
$categories = get_the_category(get_post($id_parent));
$separator = ', ';
$output = '';
foreach( $categories as $category ) {
$output .= esc_html( $category->name ) . $separator;
}
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="'.get_permalink($parent).'" title="'.get_post($post->post_parent)->post_title.'" itemprop="item"><span itemprop="name"><h2>'.get_post($post->post_parent)->post_title.'</h2></span></a><meta itemprop="position" content="2"></li>';
echo '<li class="active" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_permalink($post).'" title="'.$post->post_title.'" itemprop="item"><span itemprop="name">'.$post->post_title.'</span></a></h1><meta itemprop="position" content="3"></li>';
}
elseif (is_page()) {
echo '<li'.(!get_query_var('paged') ? ' class="active"' : '').' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_permalink().'" title="'.get_the_title().'" itemprop="item"><span itemprop="name">'.get_the_title().'</span></a></h1><meta itemprop="position" content="2"></li>';
if(get_query_var('paged')){
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active"><a href="'.get_home_url().$_SERVER['REQUEST_URI'].'" title="Trang '.get_query_var('paged').'" itemprop="item"><span itemprop="name">Trang '.get_query_var('paged').'</span></a><meta itemprop="position" content="3"></li>';
}
}
elseif (is_search()) {
global $s;
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="#nav" title="Tm kim" itemprop="item"><span itemprop="name">Tm kim</span></a><meta itemprop="position" content="2"></li>';
echo '<li'.(!get_query_var('paged') ? ' class="active"' : '').' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a title="'.$s.'" href="/?s='.$s.'" itemprop="item"><span itemprop="name">'.$s.'</span></a></h1><meta itemprop="position" content="3"></li>';
if(get_query_var('paged')){
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active"><a href="'.get_home_url().$_SERVER['REQUEST_URI'].'" title="Trang '.get_query_var('paged').'" itemprop="item"><span itemprop="name">Trang '.get_query_var('paged').'</span></a><meta itemprop="position" content="4"></li>';
}
}
else echo '<li>404</li>';
echo '</ol>';
}
else {
$gioi_thieu = $options['gioi_thieu'];
echo '<span class="gioi_thieu glyphicon glyphicon-hand-right"></span><h1>'.$gioi_thieu.'</h1>';
if(current_user_can('administrator')) echo '<a href="'.home_url().'/testing" style="float:right;padding-right:15px;color:#666;text-decoration:underline">Testing</a><a href="'.home_url().'/database-optimize" style="float:right;padding-right:15px;color:#666;text-decoration:underline">DB OP</a>';
}
}
//REWRITE URL
add_filter('post_type_link', 'tw_rewrite_chapter_link', 10, 3);
add_action('init', 'tw_add_new_rules');
function tw_rewrite_chapter_link($link, $post){
$options = get_option('my_option_name'); $mo_rong = $options['mo_rong'];
if($post->post_type == 'chap') {
$parents = get_post_ancestors($post->ID);
$parent_id = ($parents) ? $parents[count($parents) - 1] : 0;
$parent = get_post($parent_id);
$chapname = preg_replace('/'.$parent->post_name.'-/','',$post->post_name,1);
$newlink = $parent->post_name . '/' . $chapname . $mo_rong;
return home_url($newlink);
}
elseif($post->post_type == 'post_ngan') {
$newlink = '/truyen-ngan/'.$post->post_name . $mo_rong;
return home_url($newlink);
}
else {
return $link;
}
}
function tw_add_new_rules() {
$options = get_option('my_option_name'); $mo_rong = $options['mo_rong'];
add_rewrite_rule('^truyen-ngan/([^/]+)'.$mo_rong.'$','index.php?post_type=post_ngan&name=$matches[1]', 'top');
add_rewrite_rule('^tac-gia/([^/]+)'.$mo_rong.'$','index.php?tac-gia=$matches[1]', 'top');
add_rewrite_rule('([^/]+)/([^/]+)'.$mo_rong.'$','index.php?post_type=chap&name=$matches[1]-$matches[2]', 'top');
}
// REGISTER MENU
function register_my_menu() {
register_nav_menu('header-menu',__( 'Header: Menu tri' ));
register_nav_menu('danh-sach',__( 'Header: Danh sch' ));
register_nav_menu('social-1',__( 'Header: Social 1' ));
register_nav_menu('social-2',__( 'Header: Social 2' ));
}
add_action( 'init', 'register_my_menu' );
add_filter('wp_nav_menu_args', 'prefix_nav_menu_args');
function prefix_nav_menu_args($args = ''){
$args['container'] = false;
return $args;
}
// CHANGE POST MENU LABEL
function revcon_change_post_label() {
$options = get_option('my_option_name');
global $menu;
global $submenu;
$menu[5][0] = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$submenu['edit.php'][5][0] = 'Tt c '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn');
$submenu['edit.php'][10][0] = 'Thm '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn').' mi';
}
function revcon_change_post_object() {
$options = get_option('my_option_name');
global $wp_post_types;
$labels = &$wp_post_types['post']->labels;
$labels->name = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$labels->singular_name = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$labels->add_new = 'Thm '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn').' mi';
$labels->add_new_item = 'Thm '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn').' mi';
$labels->edit_item = 'Chnh sa '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn');
$labels->new_item = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$labels->view_item = 'Xem '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn');
$labels->search_items = 'Tm '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn');
$labels->not_found = 'Khng c '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn').' no';
$labels->not_found_in_trash = 'Khng c '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn').' no trong thng rc';
$labels->all_items = 'Tt c '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn');
$labels->menu_name = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$labels->name_admin_bar = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
}
add_action( 'admin_menu', 'revcon_change_post_label' );
add_action( 'init', 'revcon_change_post_object' );
// ADD ALL CHAP MENU
add_action('admin_menu', 'add_custom_link_into_post_menu');
function add_custom_link_into_post_menu() {
global $submenu;
$permalink = get_site_url().'/wp-admin/edit.php?post_type=chap';
$submenu['edit.php'][] = array( 'Tt c chng', 'manage_options', $permalink);
}
// UPDATE NEW CHAP THEN SORT THE STORY FIRST
function bt_save_post($post_id){
if(get_post_type( $post_id ) == 'chap'){
if(wp_get_post_parent_id($post_id) > 0){
$my_post = array(
'ID' => wp_get_post_parent_id($post_id),
);
wp_update_post( $my_post );
//B THM THUMBNAIL CA TRUYN VO CHAP
/*if(!get_post_thumbnail_id($post_id)){
set_post_thumbnail($post_id,get_post_thumbnail_id(wp_get_post_parent_id($post_id)));
}*/
}
}
}
// Remove comment-js
function itsg_disable_comment_js(){
wp_deregister_script( 'comment-reply' );
}
add_action( 'init', 'itsg_disable_comment_js' );
//* Remove Emoji from WordPress
/*dng FVM nn ko cn on ny*/
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
//* Clean WordPress header
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action('wp_head', 'feed_links_extra', 3);
//Xa thi gian ng bi trong Yoast Seo
add_filter( 'wpseo_og_article_published_time', '__return_false' );
add_filter( 'wpseo_og_article_modified_time', '__return_false' );
add_filter( 'wpseo_og_og_updated_time', '__return_false' );
//Khc phc vic xung dng ko ng
remove_filter( 'the_content', 'wpautop' );
//br s chuyn thnh <p>
$br = false;
add_filter( 'the_content', function( $content ) use ( $br ) {
return wpautop( $content, $br );
}, 10 );
//Xa tn min truyenthoi.com trong ng dn nh chng truyn khi thay i tn min mi
function replace_ap($text){
if (is_single()) {
$replace = array(
'https://truyenthoi.com/wp-content' => '/wp-content'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
} else {
return $text;
}
}
add_filter('the_content', 'replace_ap');
//Xa nh 768 c sinh ra khi upload
function remove_default_image_sizes( $sizes ) {
unset( $sizes[ 'medium_large' ]); // Remove Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'remove_default_image_sizes' );
//Them tai khong dong bo js, muon them js thi them vao array
function async_js($tag){
$scripts_to_async = array('jquery-migrate.min.js');
foreach($scripts_to_async as $async_script){
if(true == strpos($tag, $async_script ) )
return str_replace( ' src', ' async="async" src', $tag );
}
return $tag;
}
add_filter( 'script_loader_tag', 'async_js', 10 );
//Ch search tiu truyn
function __search_by_title_only( $search, &$wp_query ) {
global $wpdb;
if ( empty( $search ) )
return $search; // skip processing - no search term in query
$q = $wp_query->query_vars;
$n = ! empty( $q['exact'] ) ? '' : '%';
$search =
$searchand = '';
foreach ( (array) $q['search_terms'] as $term ) {
$term = esc_sql( like_escape( $term ) );
$search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
$searchand = ' AND ';
}
if ( ! empty( $search ) ) {
$search = " AND ({$search}) ";
if ( ! is_user_logged_in() )
$search .= " AND ($wpdb->posts.post_password = '') ";
}
return $search;
}
add_filter( 'posts_search', '__search_by_title_only', 500, 2 );
//Xoa block-library/style.min.css (cua trinh soan thao moi, minh ko dung)
function wpassist_remove_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'wpassist_remove_block_library_css' );
//Tat hien thi schema Yoast Seo vi theme da co schema rieng
function bybe_remove_yoast_json($data){
$data = array();
return $data;
}
add_filter('wpseo_json_ld_output', 'bybe_remove_yoast_json', 10, 1);
//TRUYEN DA DOC
add_action( 'template_redirect', 'ft_posts_visited' );
function ft_posts_visited() {
if ( get_post_type() == 'chap' ) {
$ft_cookie_posts = isset( $_COOKIE['astx_recent_posts'] ) ? json_decode( $_COOKIE['astx_recent_posts'], true ) : null;
if ( isset( $ft_cookie_posts ) ) {
foreach ( $ft_cookie_posts as $postId ) {
$ft_post = get_post( absint( $postId ) ); // Get the post
$output .= get_post(get_the_ID())->post_parent.'-'.get_the_ID().', '.get_post($ft_post->ID)->post_parent.'-'.$ft_post->ID.', ';
}
}
$listcha = $output;
$socha = strlen(get_post(get_the_ID())->post_parent);
$mangdau1 = strstr($listcha, (string)get_post(get_the_ID())->post_parent);
$mangdau2 = str_replace(get_post(get_the_ID())->post_parent.'-'.get_the_ID().', ', '', $mangdau1);
$vitricha = strstr($mangdau2, (string)get_post(get_the_ID())->post_parent);
$phay = strpos($vitricha, ',');
$idcon = substr($vitricha, $socha + 1, $phay - ($socha + 1));
if(in_array( $listcha, array(get_post(get_the_ID())->post_parent) )) {
$cooki = 'astx_recent_posts';
$ft_posts = isset( $_COOKIE[ $cooki ] ) ? json_decode( $_COOKIE[ $cooki ], true ) : null;
if ( isset( $ft_posts ) ) {
// Remove current post in the cookie
$ft_posts = array_diff( $ft_posts, array( $idcon, get_the_ID() ) );
// update cookie with current post
array_unshift( $ft_posts, get_the_ID() );
} else {
echo'duoi';
$ft_posts = array( get_the_ID() );
}
setcookie( $cooki, json_encode( $ft_posts ), time() + ( DAY_IN_SECONDS * 31 ), COOKIEPATH, COOKIE_DOMAIN );
}
else {
$cooki = 'astx_recent_posts';
$ft_posts = isset( $_COOKIE[ $cooki ] ) ? json_decode( $_COOKIE[ $cooki ], true ) : null;
if ( isset( $ft_posts ) ) {
// Remove current post in the cookie
$ft_posts = array_diff( $ft_posts, array( get_the_ID() ) );
// update cookie with current post
array_unshift( $ft_posts, get_the_ID() );
} else {
$ft_posts = array( get_the_ID() );
}
setcookie( $cooki, json_encode( $ft_posts ), time() + ( DAY_IN_SECONDS * 31 ), COOKIEPATH, COOKIE_DOMAIN );
}
}
}
//BO LOC TRONG CATE
function custom_posts_loc( $query ) {
if ( isset($_GET['loc']) && $query->is_category() && $query->is_main_query() ) {
if($_GET['loc'] == 'doc-nhieu') {
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'meta_key', 'tw_views_post' );
}
if($_GET['loc'] == 'hoan-thanh') {
$options = get_option('my_option_name');
$hoanthanh = $options['trangthai_hoanthanh'] ? $options['trangthai_hoanthanh'] : 'Hon thnh';
$query->set( 'meta_query', array(array('key' => 'tw_status','value' => $hoanthanh),) );
}
}
elseif ($query->is_tag() && $query->is_main_query()) {
$query->set( 'post_type', array('post_ngan', 'post') );
}
elseif ($query->is_search() && $query->is_main_query()) {
$query->set( 'post_type', 'post' );
}
}
add_action( 'pre_get_posts', 'custom_posts_loc' );
/**
* Khng xa nh i din khi thu thp li bi vit.
* Thc hin 4 vic sau:
* - Khng xa nh i din.
* - Khng xa tp nh km l nh i din.
* - Khng chun b d liu nh i din.
* - Gi li nh km cho nh i din.
*/
// 1. Khng xa nh i din khi thu thp li.
add_filter('kdn/post/allow_delete_thumbnail', 'kdn_post_allow_delete_thumbnail', 10, 11);
function kdn_post_allow_delete_thumbnail($allowRun, $data, $postData, $postBot, $postSaver, $siteId, $postUrl, $urlTuple, $isRecrawl, $postId, $isFirstPage) {
// Nu ang thu thp li, khng xa nh i din.
if ($isRecrawl) return false;
}
// 2. Khng xa tp nh km l nh i din khi thu thp li.
add_filter('kdn/post/allow_delete_attached_media', 'kdn_post_allow_delete_attached_media', 10, 13);
function kdn_post_allow_delete_attached_media($allowDeleteAttachedMedia, $mediaPost, $alreadyAttachedMedia, $data, $postData, $postBot, $postSaver, $siteId, $postUrl, $urlTuple, $isRecrawl, $postId, $isFirstPage) {
// Ly ID ca tp nh km.
$attachedMediaId = $mediaPost->ID;
// Ly ID ca nh i din hin ti.
$postThumbnailId = get_post_thumbnail_id($postId);
// Nu ID ca tp nh km chnh l ID ca nh i din hin ti, khng xa tp nh km.
if ($attachedMediaId == $postThumbnailId) {
return false;
// Nu khng, tip tc xa tp nh km.
} else {
return true;
}
}
// 3. Khng chun b d liu nh i din cho bi vit khi thu thp li.
add_filter('kdn/post/allow_prepare_thumbnail', 'kdn_post_allow_prepare_thumbnail', 10, 5);
function kdn_post_allow_prepare_thumbnail($allowRun, $postData, $postBot, $proxyList, $postMediaPreparer) {
// Nu ang thu thp li, khng chun b d liu cho nh i din.
if ($postBot->isRecrawl()) {
return false;
// Nu khng, tip tc chun b d liu cho nh i din.
} else {
return true;
}
}
// 4. Gi li nh km cho nh i din ca bi vit khi thu thp li.
add_filter('kdn/post/thumbnail_data_before_set', 'kdn_post_thumbnail_data_before_set', 10, 11);
function kdn_post_thumbnail_data_before_set($mediaFile, $data, $postData, $postBot, $postSaver, $siteId, $postUrl, $urlTuple, $isRecrawl, $postId, $isFirstPage) {
// Nu ang thu thp li, gi li nh km cho nh i din.
if ($isRecrawl) {
return null;
// Nu khng, tip tc x l.
} else {
return $mediaFile;
}
}
// HIN TH QUNG CO PHN B U TRONG CHAP (Chung)
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
if(is_single() && !is_admin() && get_post_type() == 'chap') {
$options = get_option('my_option_name');
$ads_chuoiid = $options['id_loaitru'];
$fchuoiid = explode(',', str_replace(' ', '', $ads_chuoiid));
$fidtrang = get_the_ID();
if ( !in_array("".$fidtrang."", $fchuoiid) ) {
return prefix_insert_ads( $content );
}
}
return $content;
}
function prefix_insert_ads( $content ) {
$closing_p = '</p>';
$paragraphs = explode( $closing_p, $content );
$options = get_option('my_option_name');
$pnumber = substr_count($content, '<p>') + 1;
if($pnumber > 13 && $pnumber < 21) {
$pnumber1 = floor($pnumber / 2) - 1;
}
elseif($pnumber > 20 && $pnumber < 28) {
$pnumber1 = floor($pnumber / 3) - 1;
$pnumber2 = floor($pnumber / 3)*2 - 1;
}
elseif($pnumber > 27) {
$pnumber1 = floor($pnumber / 4) - 1;
$pnumber2 = floor($pnumber / 4)*2 - 1;
$pnumber3 = floor($pnumber / 4)*3 - 1;
}
foreach ($paragraphs as $index => $paragraph) {
$paragraphs[$index] .= $closing_p;
if($pnumber > 13 && $pnumber < 21) {
if ($index == $pnumber1) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c1'].'</div>';
}
}
elseif($pnumber > 20 && $pnumber < 28) {
if ($index == $pnumber1) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c1'].'</div>';
}
if ($index == $pnumber2) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c2'].'</div>';
}
}
elseif($pnumber > 27) {
if ($index == $pnumber1) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c1'].'</div>';
}
if ($index == $pnumber2) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c2'].'</div>';
}
if ($index == $pnumber3) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c3'].'</div>';
}
}
}
return implode( '', $paragraphs );
}
function remove_sticker_new($id){
$term_taxonomy_ids = wp_get_object_terms($id, 'sticker', array('term_taxonomy_id' => 407));
if (!empty($term_taxonomy_ids)) {
if(current_time('timestamp') - get_post_time() > 15552000) wp_remove_object_terms($id, 'new', 'sticker');
}
}
?>
Did this file decode correctly?
Original Code
<?php
add_action( 'init', 'check_license' );
function check_license() {
$current_domain = $_SERVER['HTTP_HOST'];
$valid_domain = 'ngontinhplus.com';
if ( $current_domain !== $valid_domain ) {
wp_redirect( 'https://ngontinhplus.com' );
exit;
}
}
//-----include file--------//
include_once('metabox.php');
require get_template_directory() . '/options/options.php';
require get_template_directory() . '/options/theme-options.php';
require get_template_directory() . '/options/core.php';
require get_template_directory() . '/options/fixurl/fixurl.php';
foreach(glob(get_template_directory() . "/core/*.php") as $file){
require $file;
}
//--Khung son tho Clasic--//
add_filter('use_block_editor_for_post', '__return_false');
//-----theme custom-------//
add_theme_support('post-thumbnails', array('post', 'post_ngan'));
add_theme_support('post-thumbnails', array('post', 'chap'));
//T thm 2 c nh khi upload thumbnail trn ti khon BTV trnh KDN to thm nh khi leech trn ti khon Admin
if(get_current_user_id() == 2) {
add_image_size('image1', 33, 33, true);
add_image_size('image2', 100, 136, true);
add_image_size('image3', 200, 272, true);
}
//set_post_thumbnail_size( 215, 322, true );
add_theme_support( 'custom-logo' );
add_filter('excerpt_length', 'custom_excerpt_length', 999 );
add_filter('wp_trim_excerpt', 'tw_excerpt_more' );
add_filter('parse_query', 'tw_add_filter');
add_filter('pre_get_posts', 'tw_search_filter');
add_action('init', 'tw_radio_post_type', 0);
add_action('init', 'tw_chap_post_type', 0);
if(is_user_logged_in()) add_action('init', 'error_report_type', 0);
add_action('init', 'tw_add_nguon', 0);
add_action('init', 'tw_add_author', 0);
add_action('init', 'tw_add_prefix', 0);
add_action('wp_ajax_tw_ajax', 'tw_ajax');
add_action('wp_ajax_nopriv_tw_ajax', 'tw_ajax');
add_action('save_post', 'tw_save_post');
add_action('save_post', 'bt_save_post');
// xa b lc ca wordpress
remove_filter( 'the_title', 'wptexturize' );
//-------function------//
function tw_show_post_type($query){
if(!is_single() && !is_admin()){
$post_type = array('post', 'page','post_ngan');
$query->set('post_type', $post_type);
}
return $query;
}
function tw_search_filter( $query ) {
if ( $query->is_search && $query->is_main_query() )
$query->set('post_type', array('post', 'tac-gia','post_ngan'));
}
function tw_save_post($post_id){
$chapterID = isset($_POST['tw_parent']) ? $_POST['tw_parent'] : false;
if (!wp_is_post_revision($post_id) && $chapterID){
remove_action('save_post', 'tw_save_post');
$postdata = array(
'ID' => $post_id,
'post_parent' => $chapterID
);
wp_update_post( $postdata );
}
}
function tw_add_filter($query){
global $pagenow;
if (is_admin() && $pagenow == 'edit.php' && isset($_GET['parent_chap']) && $_GET['parent_chap'] != '') {
$query->query_vars['post_parent'] = $_GET['parent_chap'];
}
}
// TW_GET_CHAP_OPTION
function tw_get_chap_option($id, $chap){
$args = array(
'post_type' => 'chap',
'post_status' => 'publish',
'posts_per_page' => -1,
'post_parent' => $id,
'order' => 'ASC'
);
$wp_query = new wp_query($args);
echo '<select id="chapter_jump" class="btn btn-success form-control" onchange="window.location.href=this.value">';
while($wp_query->have_posts()){
$wp_query->the_post();
$subject = get_the_title();
$pattern = '/(.*)Chng\s*\d+((\s*-\s*\d+)|(\s*\(\s*\d+\s*\))|(\.\d+)*)/i';
preg_match($pattern, $subject, $matches);
if($matches) $title = mb_strimwidth(str_replace('Quyn ', 'Q.', $matches[0]), 0, 19, '..');
else $title = mb_strimwidth(str_replace('Quyn ', 'Q.', get_the_title()), 0, 19, '..');
echo '<option value="'.get_the_permalink().'"';
if($chap == get_the_ID()) echo 'selected';
echo '>'.$title.'</option>';
}
echo '</select>';
}
// TW_GET_NEXT_CHAP
function tw_get_next_chap($id){
global $wpdb;
$current_post_id = get_the_ID();
$query = $wpdb->get_results("select ID from ".$wpdb->posts." where ID > '$current_post_id' AND post_type = 'chap' and post_parent = '$id' and post_status = 'publish' ORDER BY ID ASC LIMIT 1");
if($query){
foreach($query as $chap) {
echo '<a class="btn btn-success" id="next_chap" href="'.get_the_permalink($chap->ID).'"><span class="hidden-xs">Chng tip</span> <span class="glyphicon glyphicon-chevron-right"></span></a>';
}
}
else
echo '<a class="btn btn-success disabled" href="javascript:void(0)" title="Khng hoc cha c chng tip theo" id="next_chap"><span class="hidden-xs">Chng tip</span> <span class="glyphicon glyphicon-chevron-right"></span></a>';
}
// TW_GET_NEXT_NGAN
function tw_get_next_ngan($id){
global $wpdb;
$current_post_id = get_the_ID();
$query = $wpdb->get_results("select ID from ".$wpdb->posts." where ID > '$current_post_id' AND post_type = 'post_ngan' and post_status = 'publish' ORDER BY ID ASC LIMIT 1");
if($query){
foreach($query as $ngan) {
echo '<a title="c tip truyn khc" class="btn btn-success" id="next_chap" href="'.get_the_permalink($ngan->ID).'"><span class="hidden-xs">Truyn sau</span> <span class="glyphicon glyphicon-chevron-right"></span></a>';
}
}
else
echo '<a class="btn btn-success disabled" href="javascript:void(0)" title="Khng c truyn tip theo" id="next_chap"><span class="hidden-xs">Truyn sau</span> <span class="glyphicon glyphicon-chevron-right"></span></a>';
}
// TW_GET_PREV_CHAP
function tw_get_prev_chap($id){
global $wpdb;
$current_post_id = get_the_ID();
$query = $wpdb->get_results("select ID from ".$wpdb->posts." where ID < '$current_post_id' AND post_type = 'chap' and post_parent = '$id' and post_status = 'publish' ORDER BY ID DESC LIMIT 1");
if($query){
foreach($query as $chap) {
echo '<a class="btn btn-success" id="prev_chap" href="'.get_the_permalink($chap->ID).'"><span class="glyphicon glyphicon-chevron-left"></span> <span class="hidden-xs">Chng trc</span></a>';
}
}
else
echo '<a class="btn btn-success disabled" href="javascript:void(0)" title="Khng c chng trc" id="prev_chap"><span class="glyphicon glyphicon-chevron-left"></span> <span class="hidden-xs">Chng trc</span></a>';
}
// TW_GET_PREV_NGAN
function tw_get_prev_ngan($id){
global $wpdb;
$current_post_id = get_the_ID();
$query = $wpdb->get_results("select ID from ".$wpdb->posts." where ID < '$current_post_id' AND post_type = 'post_ngan' and post_status = 'publish' ORDER BY ID DESC LIMIT 1");
if($query){
foreach($query as $ngan) {
echo '<a title="c tip truyn trc " class="btn btn-success" id="prev_chap" href="'.get_the_permalink($ngan->ID).'"><span class="glyphicon glyphicon-chevron-left"></span> <span class="hidden-xs">Truyn trc</span></a>';
}
}
else
echo '<a class="btn btn-success disabled" href="javascript:void(0)" title="Khng c truyn trc trc" id="prev_chap"><span class="glyphicon glyphicon-chevron-left"></span> <span class="hidden-xs">Truyn trc</span></a>';
}
function last_update($custom = false){
$options = get_option('my_option_name');
global $post;
$args = array(
'post_type' => 'chap',
'post_status' => 'publish',
'posts_per_page' => 1,
'post_parent' => $post->ID,
'order' => 'DESC',
'orderby' => 'ID'
);
$c_query = new wp_query($args);
/* if (get_post_meta($post->ID, 'tw_status', true) == 'Hon Thnh') {
echo 'Full';
}
else { */
if($c_query->have_posts()){
while($c_query->have_posts()){
$c_query->the_post();
/*
$timkytu = strpos(get_the_title(),':');
$timkytu3 = strpos(get_the_title(),'-');
$timkytu4 = strpos(get_the_title(),'Chng');
$demkytu = substr_count(get_the_title(),'-');
$timkytu2 = mb_strpos(get_the_title(),'Quyn');
$timkytu22 = mb_strpos(get_the_title(),'Q.');
if(($timkytu4 !== false && $timkytu3 !== false && $timkytu4 == 0 && (($timkytu !== false && $timkytu > $timkytu3) || $timkytu == false)) || (($timkytu2 !== false || $timkytu22 !== false) && ($timkytu2 == 0 || $timkytu22 == 0) && $timkytu3 !== false && (($timkytu !== false && $timkytu < $timkytu3) || ($demkytu >= 2 && $timkytu == false)))) $title2 = explode('-', get_the_title());
else $title2 = explode(':', get_the_title());
if(($timkytu2 !== false || $timkytu22 !== false) && ($timkytu2 == 0 || $timkytu22 == 0) && $timkytu3 !== false && $demkytu >= 2 && $timkytu == false) $title = mb_strimwidth(str_replace('Quyn ', 'Q.', $title2[0].' - '.$title2[1]), 0, 22, '..');
else $title = mb_strimwidth(str_replace('Quyn ', 'Q.', $title2[0]), 0, 19, '..');
*/
$subject = get_the_title();
$pattern = '/(.*)Chng\s*\d+((\s*-\s*\d+)|(\s*\(\s*\d+\s*\))|(\.\d+)*)/i';
preg_match($pattern, $subject, $matches);
if($matches) $title = mb_strimwidth(str_replace('Quyn ', 'Q.', $matches[0]), 0, 19, '..');
else $title = mb_strimwidth(str_replace('Quyn ', 'Q.', get_the_title()), 0, 19, '..');
if($custom){
echo '<span class="chapter-name" title="'.get_the_title().'">'.str_replace(array('Chng ','Chapter '), array('<span class="mini-chap"><span>Chng </span></span>','<span class="mini-chap"><span>Chapter </span></span>'),$title).'</span>';
}
else {
echo '<a class="text-primary" title="'.get_the_title().'" href="'.get_the_permalink().'"><span class="chapter-text"><span>'.str_replace(array('Chng ','Chapter '), array('<span class="mini-chap"><span>Chng </span></span>','<span class="mini-chap"><span>Chapter </span></span>'),$title).'</span></span></a>';
}
}
}
else {
if(get_post_meta($post->ID,'tw_multi_chap',true) == 1){
echo $options['chuaconoidung'] ? $options['chuaconoidung'] : 'Cha c ni dung';
} else {
echo $options['chuaconoidung2'] ? $options['chuaconoidung2'] : 'Cha c ni dung';
}
unset($c_query);
}
//}
}
// TIMEAGO
function timeago() {
global $post;
$date = get_post_time('G', false, $post);
if (empty($date)) {
return __('Pending Post');
}
$chunks = array(
array(60 * 60 * 24 * 365, __('nm'), __('nm')),
array(60 * 60 * 24 * 30, __('thng'), __('thng')),
array(60 * 60 * 24 * 7, __('tun'), __('tun')),
array(60 * 60 * 24, __('ngy'), __('ngy')),
array(60 * 60, __('gi'), __('gi')),
array(60, __('pht'), __('pht')),
array(1, __('giy'), __('giy'))
);
if (!is_numeric($date)) {
$time_chunks = explode(':', str_replace(' ', ':', $date));
$date_chunks = explode('-', str_replace(' ', '-', $date));
$date = gmmktime((int) $time_chunks[1], (int) $time_chunks[2], (int) $time_chunks[3], (int) $date_chunks[1], (int) $date_chunks[2], (int) $date_chunks[0]);
}
$current_time = current_time('mysql', $gmt = 0);
$newer_date = strtotime($current_time);
$since = $newer_date - $date;
if (0 > $since)
return __('sometime');
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
// Finding the biggest chunk (if the chunk fits, break)
if (( $count = floor($since / $seconds) ) != 0)
break;
}
// Set output var
$output = ( 1 == $count ) ? '1 ' . $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
if (!(int) trim($output)) {
$output = '0 ' . __('giy');
}
$output .= __(' trc');
return $output;
}
// TW_AJAX
function tw_ajax(){
switch($_POST['type']){
case 'pagination':
chap_pagination(intval($_POST['id']), intval($_POST['page']));
break;
case 'list_chap':
tw_get_chap_option($_POST['id'], $_POST['chap']);
break;
default:
case 'raty':
$id = $_POST['id'];
$rate = $_POST['score'];
echo tw_update_rate($id, $rate);
break;
}
die();
}
// TW_GET_RATE
function tw_get_rate($postID){
$count_key = 'tw_rate';
$count = get_post_meta($postID, $count_key, true);
if($count == ''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "10";
}
return $count;
}
// TW_GET_TOTAL_RATE
function tw_get_total_rate($postID){
$count_key = 'tw_total_rate';
$count = get_post_meta($postID, $count_key, true);
if($count == ''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0";
}
return $count;
}
// TW_UPDATE_RATE
function tw_update_rate($postID, $rate) {
//update rate
$tw_rate = get_post_meta($postID, 'tw_rate', true);
$tw_rate = $tw_rate + $rate;
update_post_meta($postID, 'tw_rate', $tw_rate);
//update total rate
$count = get_post_meta($postID, 'tw_total_rate', true);
$count++;
update_post_meta($postID, 'tw_total_rate', $count);
return json_encode(array('status' => 'success', 'rateCount' => $count, 'ratePoint' => ceil($tw_rate / $count)));
}
// TW_GET_VIEWS
function tw_get_views($postID){
$count_key = 'tw_views_post';
$count = get_post_meta($postID, $count_key, true);
if($count == ''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, rand(80, 99));
return "99";
}
return number_format($count,0,',','.');
}
// TW_VIEWS
function tw_views($postID) {
$count_key = 'tw_views_post';
$count = get_post_meta($postID, $count_key, true);
if($count == ''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, rand(80, 99));
}
else
{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
// TW_GET_THUMBNAIL
function tw_get_thumbnail($id){
global $post;
if($id){
$post = get_post($id);
}
$thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'image');
$parent_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(wp_get_post_parent_id($post->ID)), 'image');
if($thumbnail_src)
return $thumbnail_src[0];
elseif($parent_thumbnail_src)
return $parent_thumbnail_src[0];
// elseif(preg_match("/(http|https):\/\/[^\s]+(\.gif|\.jpg|\.jpeg|\.png)/is", $post->post_content, $thumb))
// return $thumb[0];
else {
$attachments = get_posts( array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post->ID
) );
if ( $attachments && has_post_thumbnail($id) ) {
foreach ( $attachments as $attachment ) {
$att_image = apply_filters( 'the_title', $attachment->guid );
}
$tim_webp = strpos($att_image, '.webp');
if($tim_webp) return $att_image.'" onerror="this.onerror=null; this.src=\'/wp-content/themes/boxtruyen/images/thumbnail-webp.png\'';
else return $att_image;
} else
return get_template_directory_uri() . '/images/poster.png';
}
}
// REGISTER POST TYPE: ERROR_REPORT
if(is_user_logged_in()) {
function error_report_type(){
$label = array(
'name' => 'Bo li',
'singular_name' => 'Bo li',
'add_new' => 'Thm bo li',
'add_new_item' => 'Thm bo li mi',
'edit_item' => 'Chnh sa bo li',
'new_item' => 'Bo li',
'view_item' => 'Xem bo li',
'search_items' => 'Tm bo li',
'not_found' => 'Khng c bo li no',
'not_found_in_trash' => 'Khng c bo li no trong thng rc',
'all_items' => 'Tt c bo li',
'menu_name' => 'Bo li',
'name_admin_bar' => 'Bo li',
);
$args = array(
'labels' => $label,
'description' => 'Tt c bo li',
'supports' => array( 'title', 'editor', 'parent', 'revisions', 'thumbnail',
),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 3,
'menu_icon' => 'dashicons-warning',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post'
);
register_post_type('error_report', $args);
}
}
// REGISTER POST TYPE: CHAP
function tw_chap_post_type(){
$label = array(
'name' => 'Chng',
'singular_name' => 'Chng',
'add_new' => 'Thm chng mi',
'add_new_item' => 'Thm chng mi',
'edit_item' => 'Chnh sa chng',
'new_item' => 'Chng',
'view_item' => 'Xem chng',
'search_items' => 'Tm chng',
'not_found' => 'Khng c chng no',
'not_found_in_trash' => 'Khng c chng no trong thng rc',
'all_items' => 'Tt c chng',
'menu_name' => 'Chng',
'name_admin_bar' => 'Chng',
);
$args = array(
'labels' => $label,
'description' => 'Tt c chng',
'supports' => array( 'title', 'editor', 'parent', 'revisions', 'thumbnail', 'comments'
),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => false,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => '',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post'
);
register_post_type('chap', $args);
flush_rewrite_rules();
}
// REGISTER TAXONOMY: TAC-GIA
function tw_add_author(){
$args = array(
'labels' => array(
'name' => 'Tc gi',
'singular' => 'Tc gi',
'menu-name' => 'Tc gi',
'all_items' => 'Tt c tc gi',
'edit_item' => 'Chnh sa tc gi',
'view_item' => 'Xem tc gi',
'add_new_item' => 'Thm tc gi',
'new_item_name' => 'Tn tc gi',
'parent_item' => 'Tc gi cha',
'search_items' => 'Tm tc gi',
'popular_items' => 'Tc gi ph bin',
'separate_items_with_commas' => 'Phn tch cc tc gi bng du phy.',
'add_or_remove_items' => 'Thm hoc xa tc gi',
'choose_from_most_used' => 'Chn tc gi dng nhiu nht'
),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_tagcloud' => true,
'show_in_nav_menus' => true
);
register_taxonomy('tac-gia',array('post','post_ngan'), $args);
}
// REGISTER TAXONOMY: NGUN
function tw_add_nguon(){
$args = array(
'labels' => array(
'name' => 'Ngun',
'singular' => 'Ngun',
'menu-name' => 'Ngun',
'all_items' => 'Tt c ngun',
'edit_item' => 'Chnh sa ngun',
'view_item' => 'Xem ngun',
'add_new_item' => 'Thm ngun',
'new_item_name' => 'Tn ngun',
'parent_item' => 'Ngun cha',
'search_items' => 'Tm ngun',
'popular_items' => 'Ngun ph bin',
'separate_items_with_commas' => 'Phn tch cc ngun bng du phy.',
'add_or_remove_items' => 'Thm hoc xa ngun',
'choose_from_most_used' => 'Chn ngun dng nhiu nht'
),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_tagcloud' => true,
'show_in_nav_menus' => true
);
register_taxonomy('nguon-truyen',array('post','post_ngan'), $args);
}
// REGISTER TAXONOMY: TIEN_TO
function tw_add_prefix(){
$args = array(
'labels' => array(
'name' => 'Sticker',
'singular' => 'Sticker',
'menu-name' => 'Sticker',
'all_items' => 'Tt c Sticker',
'edit_item' => 'Chnh sa Sticker',
'view_item' => 'Xem Sticker',
'add_new_item' => 'Thm Sticker',
'new_item_name' => 'Tn Sticker',
'parent_item' => 'Sticker cha',
'search_items' => 'Tm Sticker',
'popular_items' => 'Sticker ph bin',
'separate_items_with_commas' => 'Phn tch cc Sticker bng du phy.',
'add_or_remove_items' => 'Thm hoc xa Sticker',
'choose_from_most_used' => 'Chn Sticker dng nhiu nht'
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_tagcloud' => true,
'show_in_nav_menus' => true
);
register_taxonomy('sticker',array('post','post_ngan'), $args);
}
// GET TIEN_TO AND TRANGTHAI
function get_tien_to($id){
$tiento = get_the_terms($id,'sticker');
if(is_array($tiento)){
foreach ($tiento as $e_tiento){
$termid = $e_tiento->term_id;
$name = $e_tiento->name;
$slug = $e_tiento->slug;
echo '<span class="tien_to tien_to_'.$slug.'">'.$name.'</span> ';
}
}
}
function get_trangthai($id){
$trangthai = get_post_meta($id,'tw_status',true);
$options = get_option('my_option_name');
$hoanthanh = $options['trangthai_hoanthanh'] ? $options['trangthai_hoanthanh'] : 'Hon thnh';
if($trangthai == $hoanthanh){
echo '<span class="tien_to trang_thai_full">'; echo $options['trangthai_hoanthanh'] ? $options['trangthai_hoanthanh'] : 'Hon thnh'; echo '</span> ';
}
}
function get_tien_to_2($id){
$tiento = get_the_terms($id,'sticker');
if(is_array($tiento)){
foreach ($tiento as $e_tiento){
$termid = $e_tiento->term_id;
$name = $e_tiento->name;
$slug = $e_tiento->slug;
echo '<span class="sticker-'.$slug.'">'.$name.'</span>';
}
}
}
function get_tien_to_chu($id){
$tiento = get_the_terms($id,'sticker');
if(is_array($tiento)){
foreach ($tiento as $e_tiento){
$termid = $e_tiento->term_id;
$name = $e_tiento->name;
$slug = $e_tiento->slug;
echo '<span class="tien_to_'.$slug.'">'.$name.'</span> ';
}
}
}
function get_trangthai_chu($id){
$trangthai = get_post_meta($id,'tw_status',true);
$options = get_option('my_option_name');
$hoanthanh = $options['trangthai_hoanthanh'] ? $options['trangthai_hoanthanh'] : 'Hon thnh';
$huybo = $options['trangthai_huybo'] ? $options['trangthai_huybo'] : 'Hy b';
if($trangthai == $hoanthanh){
echo 'Full';
} elseif($trangthai == $huybo){
echo 'Drop';
}
}
function get_trangthai_2($id){
$trangthai = get_post_meta($id,'tw_status',true);
$options = get_option('my_option_name');
$hoanthanh = $options['trangthai_hoanthanh'] ? $options['trangthai_hoanthanh'] : 'Hon thnh';
if($trangthai == $hoanthanh){
echo '<img src="'; echo bloginfo('template_url'); echo '/images/full-label.png" class="full_label"/>';
}
}
//DOC TU DAU
function truyenhot_get_chap_old( $ID_parent ) {
$args = array(
'post_type' => 'chap',
'post_status' => 'publish',
'showposts' => 1,
'post_parent' => $ID_parent,
'order' => 'ASC',
'orderby' => 'ID'
);
$last_query = new wp_query($args);
while($last_query->have_posts()){
$last_query->the_post();
echo '<a href="'.get_the_permalink().'" title="'.get_the_title().'"><button type="button" class="btn button-border"><span class="glyphicon glyphicon-circle-arrow-right"></span> c t u</button></a>';
}
wp_reset_postdata();
}
// REGISTER POST TYPE: Blog_truyen
function tw_radio_post_type(){
$options = get_option('my_option_name');
$label = array(
'name' => $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Blog truyn',
'singular_name' => $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Blog truyn',
'add_new' => 'Thm '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn').' mi',
'add_new_item' => 'Thm '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn').' mi',
'edit_item' => 'Chnh sa '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn'),
'new_item' => $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Blog truyn',
'view_item' => 'Xem '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn'),
'search_items' => 'Tm '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn'),
'not_found' => 'Khng c '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn').' no',
'not_found_in_trash' => 'Khng c '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn').' no trong thng rc',
'all_items' => 'Tt c '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn'),
'menu_name' => $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Blog truyn',
'name_admin_bar' => $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Blog truyn',
);
$args = array(
'labels' => $label,
'description' => 'Tt c '.strtolower($options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'blog truyn'),
'supports' => array('title', 'editor', 'parent', 'thumbnail', 'author','revisions', 'comments'
),
'taxonomies' => array('post_tag', 'category','tac-gia'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-admin-post',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'post'
);
register_post_type('blog', $args);
flush_rewrite_rules();
}
// EXPCERPT
function custom_excerpt_length($length){
return 40;
}
function tw_excerpt_more( $excerpt ) {
return str_replace( '[...]', '...', $excerpt );
}
// CHAP PAGINATION
function chap_pagination($ID_parent, $page) {
$options = get_option('my_option_name');
$chapnum = $options['number'];
$args = array(
'post_type' => 'chap',
'post_status' => 'publish',
'posts_per_page' => $chapnum,
'paged' => $page,
'post_parent' => $ID_parent,
'order' => 'ASC',
'orderby' => 'ID'
);
$my_query = new wp_query($args);
$html = '<div class="col-xs-12 col-sm-6 col-md-6"><ul class="list-chapter">';
$i = 1;
while($my_query->have_posts()){
$my_query->the_post();
if($i == ($chapnum+1))
$html .= '</ul></div><div class="col-xs-12 col-sm-6 col-md-6"><ul class="list-chapter">';
$html .= (is_integer ($i / 2) ? '<li class="chap-left5'.(($i == $chapnum || $i + ($chapnum*$page) - $chapnum == $my_query->found_posts) ? ' last-list' : '').'">' : '<li class="chap-right5'.(($i == $chapnum || $i == $chapnum - 1 || $i + ($chapnum*$page) - $chapnum == $my_query->found_posts || $i + ($chapnum*$page) - $chapnum == $my_query->found_posts - 1) ? ' last-list' : '').'">').
'<span class="glyphicon glyphicon-book right-5"></span>
<a href="'.get_the_permalink().'" title="'.get_the_title().'">
<span class="chapter-text">'.get_the_title().'</span>
</a>
</li>';
++$i;
}
$html .= '</ul></div>';
$pagination = preg_replace("/href=\"(.+?)\"/is", 'href="#"', pagination(true, $my_query->max_num_pages, $page));
echo json_encode(array('list_chap' => $html, 'pagination' => $pagination));
}
// PAGINATION
function pagination($return = false, $max = false, $paged = false) {
global $wp_query;
if($wp_query->max_num_pages <= 1 && !$max)
return 'Trang khng tn ti<br/><br/>';
if(!$paged)
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = (!$max) ? intval($wp_query->max_num_pages) : $max;
$links[] = $paged;
for($i = $paged; $i < $paged + 5; $i++){
if($i <= $max && $i != $paged)
$links[] = $i;
}
for($i = $paged; $i >= ($paged - 5);$i--){
if($i >= 1 && $i != $paged)
$links[] = $i;
}
$html = '<ul class="pagination pagination-sm pagination-chap">' . "\n";
// Previous button
if ($paged > 1) {
$prev_page = $paged - 1;
$html .= '<li><a href="'.esc_url( get_pagenum_link( $prev_page ) ).'" title="Prev">Prev</a></li>';
}
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
$html .= '<li '.$class.'><a data-page="1" href="'.esc_url( get_pagenum_link( 1 ) ).'" title="1">u</a></li>';
}
sort( $links );
foreach ( (array) $links as $link ) {
$class = $link == $paged ? ' class="active"' : '';
$html .= '<li '.$class.'><a data-page="'.$link.'" href="'.esc_url( get_pagenum_link( $link ) ).'">'.$link.'</a></li>';
}
// Next button
if ($paged < $max) {
$next_page = $paged + 1;
$html .= '<li><a href="'.esc_url( get_pagenum_link( $next_page ) ).'" title="Next">Next</a></li>';
}
if ( ! in_array( $max, $links ) ) {
$class = $paged == $max ? ' class="active"' : '';
$html .= '<li '.$class.'><a id = "last-catepage" data-page="'.$max.'" href="'.esc_url( get_pagenum_link( $max ) ).'" title="'.$max.'">Cui</a></li>';
}
if(!is_search() && !$_GET['loc']) {
$html .= '<li class="dropup page-nav"><span href="javascript:void(0)" data-toggle="dropdown" style="cursor:pointer">Chn trang <span class="caret"></span></span>
<div class="dropdown-menu dropdown-menu-right" role="menu">
<form action="." name="page_jump" id="page_jump" method="get">
<div class="input-group">';
if(is_category())
$html .= '<input name="page_url" type="hidden" value="'.get_pagenum_link().'">';
else
$html .= '<input name="total-page" type="hidden" value="'.$max.'"><input name="page_url" type="hidden" value="'.get_pagenum_link().'">';
$html .= '<input class="form-control" name="page" type="number" placeholder="S trang..." value="">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">i</button>
</span>
</div>
</form>
</div>
</li>';
}
$html .= '</ul>' . "\n";
if($return)
return $html;
else
echo $html;
}
// BREADCRUMB
function the_breadcrumb() {
$options = get_option('my_option_name');
$breadcrumb = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$breadcrumb_ngan = $options['breadcrumb_ngan'] ? $options['breadcrumb_ngan'] : 'Truyn ngn';
global $post;
if (!is_home()) {
echo '<ol class="breadcrumb" itemscope="" itemtype="https://schema.org/BreadcrumbList">';
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="'.get_option('home').'" accesskey="1"><span class="glyphicon glyphicon-home"></span></a><a href="'.get_option('home').'" title="Trang ch" itemprop="item"><span itemprop="name">Trang ch</span></a><meta itemprop="position" content="1"></li>';
if (is_single() && $post->post_type == 'blog') {
$categories = get_the_category();
$separator = ', ';
$output = '';
foreach( $categories as $category ) {
$output .= esc_html( $category->name ) . $separator;
}
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="'.str_replace('runninghorse-tt-display-', '', esc_url( get_category_link( $categories[0]->term_id ) )).'" title="'.trim( $output, $separator ).'" itemprop="item"><span itemprop="name">'.esc_html( $categories[0]->name ).'</span></a><meta itemprop="position" content="2"></li>';
echo '<li class="active" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_permalink().'" title="'.get_the_title().'" itemprop="item"><span itemprop="name">';
the_title();
echo '</span></a></h1><meta itemprop="position" content="3"></li>';
}
elseif (is_single() && $post->post_type != 'chap') {
$categories = get_the_category();
$separator = ', ';
$output = '';
foreach( $categories as $category ) {
$output .= esc_html( $category->name ) . $separator;
}
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="'.esc_url( get_category_link( $categories[0]->term_id ) ).'" title="'.trim( $output, $separator ).'" itemprop="item"><span itemprop="name">'.esc_html( $categories[0]->name ).'</span></a><meta itemprop="position" content="2"></li>';
echo '<li class="active" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_permalink().'" title="'.get_the_title().'" itemprop="item"><span itemprop="name">';
the_title();
echo '</span></a></h1><meta itemprop="position" content="3"></li>';
}
elseif (is_category()) {
$cat = get_category(get_query_var('cat'), false);
echo '<li'.(!get_query_var('paged') ? ' class="active"' : '').' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_category_link($cat->term_id).'" title="'.$cat->cat_name.'" itemprop="item"><span itemprop="name">'.$cat->name.'</span></a></h1><meta itemprop="position" content="2"></li>';
if(get_query_var('paged')){
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active"><a href="'.get_home_url().$_SERVER['REQUEST_URI'].'" title="Trang '.get_query_var('paged').'" itemprop="item"><span itemprop="name">Trang '.get_query_var('paged').'</span></a><meta itemprop="position" content="3"></li>';
}
}
elseif (is_tax()) {
$taxonomy = get_taxonomy(get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) )->taxonomy);
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="#nav" title="'.$taxonomy->label.'" itemprop="item"><span itemprop="name">'.$taxonomy->label.'</span></a><meta itemprop="position" content="2"></li>';
echo '<li'.(!get_query_var('paged') ? ' class="active"' : '').' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.$term->slug.'" title="'.$term->name.'" itemprop="item"><span itemprop="name">'.$term->name.'</span></a></h1><meta itemprop="position" content="3"></li>';
if(get_query_var('paged')){
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active"><a href="'.get_home_url().$_SERVER['REQUEST_URI'].'" title="Trang '.get_query_var('paged').'" itemprop="item"><span itemprop="name">Trang '.get_query_var('paged').'</span></a><meta itemprop="position" content="4"></li>';
}
}
elseif (is_tag()) {
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="#nav" title="Th" itemprop="item"><span itemprop="name">Th</span></a><meta itemprop="position" content="2"></li>';
echo '<li'.(!get_query_var('paged') ? ' class="active"' : '').' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_tag_link(get_queried_object()->term_id).'" title="'.get_queried_object()->name.'" itemprop="item"><span itemprop="name">'.get_queried_object()->name.'</span></a></h1><meta itemprop="position" content="3"></li>';
if(get_query_var('paged')){
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active"><a href="'.get_home_url().$_SERVER['REQUEST_URI'].'" title="Trang '.get_query_var('paged').'" itemprop="item"><span itemprop="name">Trang '.get_query_var('paged').'</span></a><meta itemprop="position" content="4"></li>';
}
}
elseif($post->post_type == 'chap' && !is_search()){
$id_parent = $post->post_parent;
$parent = get_post($id_parent);
$title = $parent->post_title;
$categories = get_the_category(get_post($id_parent));
$separator = ', ';
$output = '';
foreach( $categories as $category ) {
$output .= esc_html( $category->name ) . $separator;
}
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="'.get_permalink($parent).'" title="'.get_post($post->post_parent)->post_title.'" itemprop="item"><span itemprop="name"><h2>'.get_post($post->post_parent)->post_title.'</h2></span></a><meta itemprop="position" content="2"></li>';
echo '<li class="active" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_permalink($post).'" title="'.$post->post_title.'" itemprop="item"><span itemprop="name">'.$post->post_title.'</span></a></h1><meta itemprop="position" content="3"></li>';
}
elseif (is_page()) {
echo '<li'.(!get_query_var('paged') ? ' class="active"' : '').' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a href="'.get_permalink().'" title="'.get_the_title().'" itemprop="item"><span itemprop="name">'.get_the_title().'</span></a></h1><meta itemprop="position" content="2"></li>';
if(get_query_var('paged')){
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active"><a href="'.get_home_url().$_SERVER['REQUEST_URI'].'" title="Trang '.get_query_var('paged').'" itemprop="item"><span itemprop="name">Trang '.get_query_var('paged').'</span></a><meta itemprop="position" content="3"></li>';
}
}
elseif (is_search()) {
global $s;
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="#nav" title="Tm kim" itemprop="item"><span itemprop="name">Tm kim</span></a><meta itemprop="position" content="2"></li>';
echo '<li'.(!get_query_var('paged') ? ' class="active"' : '').' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><h1><a title="'.$s.'" href="/?s='.$s.'" itemprop="item"><span itemprop="name">'.$s.'</span></a></h1><meta itemprop="position" content="3"></li>';
if(get_query_var('paged')){
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active"><a href="'.get_home_url().$_SERVER['REQUEST_URI'].'" title="Trang '.get_query_var('paged').'" itemprop="item"><span itemprop="name">Trang '.get_query_var('paged').'</span></a><meta itemprop="position" content="4"></li>';
}
}
else echo '<li>404</li>';
echo '</ol>';
}
else {
$gioi_thieu = $options['gioi_thieu'];
echo '<span class="gioi_thieu glyphicon glyphicon-hand-right"></span><h1>'.$gioi_thieu.'</h1>';
if(current_user_can('administrator')) echo '<a href="'.home_url().'/testing" style="float:right;padding-right:15px;color:#666;text-decoration:underline">Testing</a><a href="'.home_url().'/database-optimize" style="float:right;padding-right:15px;color:#666;text-decoration:underline">DB OP</a>';
}
}
//REWRITE URL
add_filter('post_type_link', 'tw_rewrite_chapter_link', 10, 3);
add_action('init', 'tw_add_new_rules');
function tw_rewrite_chapter_link($link, $post){
$options = get_option('my_option_name'); $mo_rong = $options['mo_rong'];
if($post->post_type == 'chap') {
$parents = get_post_ancestors($post->ID);
$parent_id = ($parents) ? $parents[count($parents) - 1] : 0;
$parent = get_post($parent_id);
$chapname = preg_replace('/'.$parent->post_name.'-/','',$post->post_name,1);
$newlink = $parent->post_name . '/' . $chapname . $mo_rong;
return home_url($newlink);
}
elseif($post->post_type == 'post_ngan') {
$newlink = '/truyen-ngan/'.$post->post_name . $mo_rong;
return home_url($newlink);
}
else {
return $link;
}
}
function tw_add_new_rules() {
$options = get_option('my_option_name'); $mo_rong = $options['mo_rong'];
add_rewrite_rule('^truyen-ngan/([^/]+)'.$mo_rong.'$','index.php?post_type=post_ngan&name=$matches[1]', 'top');
add_rewrite_rule('^tac-gia/([^/]+)'.$mo_rong.'$','index.php?tac-gia=$matches[1]', 'top');
add_rewrite_rule('([^/]+)/([^/]+)'.$mo_rong.'$','index.php?post_type=chap&name=$matches[1]-$matches[2]', 'top');
}
// REGISTER MENU
function register_my_menu() {
register_nav_menu('header-menu',__( 'Header: Menu tri' ));
register_nav_menu('danh-sach',__( 'Header: Danh sch' ));
register_nav_menu('social-1',__( 'Header: Social 1' ));
register_nav_menu('social-2',__( 'Header: Social 2' ));
}
add_action( 'init', 'register_my_menu' );
add_filter('wp_nav_menu_args', 'prefix_nav_menu_args');
function prefix_nav_menu_args($args = ''){
$args['container'] = false;
return $args;
}
// CHANGE POST MENU LABEL
function revcon_change_post_label() {
$options = get_option('my_option_name');
global $menu;
global $submenu;
$menu[5][0] = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$submenu['edit.php'][5][0] = 'Tt c '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn');
$submenu['edit.php'][10][0] = 'Thm '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn').' mi';
}
function revcon_change_post_object() {
$options = get_option('my_option_name');
global $wp_post_types;
$labels = &$wp_post_types['post']->labels;
$labels->name = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$labels->singular_name = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$labels->add_new = 'Thm '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn').' mi';
$labels->add_new_item = 'Thm '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn').' mi';
$labels->edit_item = 'Chnh sa '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn');
$labels->new_item = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$labels->view_item = 'Xem '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn');
$labels->search_items = 'Tm '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn');
$labels->not_found = 'Khng c '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn').' no';
$labels->not_found_in_trash = 'Khng c '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn').' no trong thng rc';
$labels->all_items = 'Tt c '.strtolower($options['breadcrumb'] ? $options['breadcrumb'] : 'truyn');
$labels->menu_name = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
$labels->name_admin_bar = $options['breadcrumb'] ? $options['breadcrumb'] : 'Truyn';
}
add_action( 'admin_menu', 'revcon_change_post_label' );
add_action( 'init', 'revcon_change_post_object' );
// ADD ALL CHAP MENU
add_action('admin_menu', 'add_custom_link_into_post_menu');
function add_custom_link_into_post_menu() {
global $submenu;
$permalink = get_site_url().'/wp-admin/edit.php?post_type=chap';
$submenu['edit.php'][] = array( 'Tt c chng', 'manage_options', $permalink);
}
// UPDATE NEW CHAP THEN SORT THE STORY FIRST
function bt_save_post($post_id){
if(get_post_type( $post_id ) == 'chap'){
if(wp_get_post_parent_id($post_id) > 0){
$my_post = array(
'ID' => wp_get_post_parent_id($post_id),
);
wp_update_post( $my_post );
//B THM THUMBNAIL CA TRUYN VO CHAP
/*if(!get_post_thumbnail_id($post_id)){
set_post_thumbnail($post_id,get_post_thumbnail_id(wp_get_post_parent_id($post_id)));
}*/
}
}
}
// Remove comment-js
function itsg_disable_comment_js(){
wp_deregister_script( 'comment-reply' );
}
add_action( 'init', 'itsg_disable_comment_js' );
//* Remove Emoji from WordPress
/*dng FVM nn ko cn on ny*/
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
//* Clean WordPress header
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action('wp_head', 'feed_links_extra', 3);
//Xa thi gian ng bi trong Yoast Seo
add_filter( 'wpseo_og_article_published_time', '__return_false' );
add_filter( 'wpseo_og_article_modified_time', '__return_false' );
add_filter( 'wpseo_og_og_updated_time', '__return_false' );
//Khc phc vic xung dng ko ng
remove_filter( 'the_content', 'wpautop' );
//br s chuyn thnh <p>
$br = false;
add_filter( 'the_content', function( $content ) use ( $br ) {
return wpautop( $content, $br );
}, 10 );
//Xa tn min truyenthoi.com trong ng dn nh chng truyn khi thay i tn min mi
function replace_ap($text){
if (is_single()) {
$replace = array(
'https://truyenthoi.com/wp-content' => '/wp-content'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
} else {
return $text;
}
}
add_filter('the_content', 'replace_ap');
//Xa nh 768 c sinh ra khi upload
function remove_default_image_sizes( $sizes ) {
unset( $sizes[ 'medium_large' ]); // Remove Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'remove_default_image_sizes' );
//Them tai khong dong bo js, muon them js thi them vao array
function async_js($tag){
$scripts_to_async = array('jquery-migrate.min.js');
foreach($scripts_to_async as $async_script){
if(true == strpos($tag, $async_script ) )
return str_replace( ' src', ' async="async" src', $tag );
}
return $tag;
}
add_filter( 'script_loader_tag', 'async_js', 10 );
//Ch search tiu truyn
function __search_by_title_only( $search, &$wp_query ) {
global $wpdb;
if ( empty( $search ) )
return $search; // skip processing - no search term in query
$q = $wp_query->query_vars;
$n = ! empty( $q['exact'] ) ? '' : '%';
$search =
$searchand = '';
foreach ( (array) $q['search_terms'] as $term ) {
$term = esc_sql( like_escape( $term ) );
$search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
$searchand = ' AND ';
}
if ( ! empty( $search ) ) {
$search = " AND ({$search}) ";
if ( ! is_user_logged_in() )
$search .= " AND ($wpdb->posts.post_password = '') ";
}
return $search;
}
add_filter( 'posts_search', '__search_by_title_only', 500, 2 );
//Xoa block-library/style.min.css (cua trinh soan thao moi, minh ko dung)
function wpassist_remove_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'wpassist_remove_block_library_css' );
//Tat hien thi schema Yoast Seo vi theme da co schema rieng
function bybe_remove_yoast_json($data){
$data = array();
return $data;
}
add_filter('wpseo_json_ld_output', 'bybe_remove_yoast_json', 10, 1);
//TRUYEN DA DOC
add_action( 'template_redirect', 'ft_posts_visited' );
function ft_posts_visited() {
if ( get_post_type() == 'chap' ) {
$ft_cookie_posts = isset( $_COOKIE['astx_recent_posts'] ) ? json_decode( $_COOKIE['astx_recent_posts'], true ) : null;
if ( isset( $ft_cookie_posts ) ) {
foreach ( $ft_cookie_posts as $postId ) {
$ft_post = get_post( absint( $postId ) ); // Get the post
$output .= get_post(get_the_ID())->post_parent.'-'.get_the_ID().', '.get_post($ft_post->ID)->post_parent.'-'.$ft_post->ID.', ';
}
}
$listcha = $output;
$socha = strlen(get_post(get_the_ID())->post_parent);
$mangdau1 = strstr($listcha, (string)get_post(get_the_ID())->post_parent);
$mangdau2 = str_replace(get_post(get_the_ID())->post_parent.'-'.get_the_ID().', ', '', $mangdau1);
$vitricha = strstr($mangdau2, (string)get_post(get_the_ID())->post_parent);
$phay = strpos($vitricha, ',');
$idcon = substr($vitricha, $socha + 1, $phay - ($socha + 1));
if(in_array( $listcha, array(get_post(get_the_ID())->post_parent) )) {
$cooki = 'astx_recent_posts';
$ft_posts = isset( $_COOKIE[ $cooki ] ) ? json_decode( $_COOKIE[ $cooki ], true ) : null;
if ( isset( $ft_posts ) ) {
// Remove current post in the cookie
$ft_posts = array_diff( $ft_posts, array( $idcon, get_the_ID() ) );
// update cookie with current post
array_unshift( $ft_posts, get_the_ID() );
} else {
echo'duoi';
$ft_posts = array( get_the_ID() );
}
setcookie( $cooki, json_encode( $ft_posts ), time() + ( DAY_IN_SECONDS * 31 ), COOKIEPATH, COOKIE_DOMAIN );
}
else {
$cooki = 'astx_recent_posts';
$ft_posts = isset( $_COOKIE[ $cooki ] ) ? json_decode( $_COOKIE[ $cooki ], true ) : null;
if ( isset( $ft_posts ) ) {
// Remove current post in the cookie
$ft_posts = array_diff( $ft_posts, array( get_the_ID() ) );
// update cookie with current post
array_unshift( $ft_posts, get_the_ID() );
} else {
$ft_posts = array( get_the_ID() );
}
setcookie( $cooki, json_encode( $ft_posts ), time() + ( DAY_IN_SECONDS * 31 ), COOKIEPATH, COOKIE_DOMAIN );
}
}
}
//BO LOC TRONG CATE
function custom_posts_loc( $query ) {
if ( isset($_GET['loc']) && $query->is_category() && $query->is_main_query() ) {
if($_GET['loc'] == 'doc-nhieu') {
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'meta_key', 'tw_views_post' );
}
if($_GET['loc'] == 'hoan-thanh') {
$options = get_option('my_option_name');
$hoanthanh = $options['trangthai_hoanthanh'] ? $options['trangthai_hoanthanh'] : 'Hon thnh';
$query->set( 'meta_query', array(array('key' => 'tw_status','value' => $hoanthanh),) );
}
}
elseif ($query->is_tag() && $query->is_main_query()) {
$query->set( 'post_type', array('post_ngan', 'post') );
}
elseif ($query->is_search() && $query->is_main_query()) {
$query->set( 'post_type', 'post' );
}
}
add_action( 'pre_get_posts', 'custom_posts_loc' );
/**
* Khng xa nh i din khi thu thp li bi vit.
* Thc hin 4 vic sau:
* - Khng xa nh i din.
* - Khng xa tp nh km l nh i din.
* - Khng chun b d liu nh i din.
* - Gi li nh km cho nh i din.
*/
// 1. Khng xa nh i din khi thu thp li.
add_filter('kdn/post/allow_delete_thumbnail', 'kdn_post_allow_delete_thumbnail', 10, 11);
function kdn_post_allow_delete_thumbnail($allowRun, $data, $postData, $postBot, $postSaver, $siteId, $postUrl, $urlTuple, $isRecrawl, $postId, $isFirstPage) {
// Nu ang thu thp li, khng xa nh i din.
if ($isRecrawl) return false;
}
// 2. Khng xa tp nh km l nh i din khi thu thp li.
add_filter('kdn/post/allow_delete_attached_media', 'kdn_post_allow_delete_attached_media', 10, 13);
function kdn_post_allow_delete_attached_media($allowDeleteAttachedMedia, $mediaPost, $alreadyAttachedMedia, $data, $postData, $postBot, $postSaver, $siteId, $postUrl, $urlTuple, $isRecrawl, $postId, $isFirstPage) {
// Ly ID ca tp nh km.
$attachedMediaId = $mediaPost->ID;
// Ly ID ca nh i din hin ti.
$postThumbnailId = get_post_thumbnail_id($postId);
// Nu ID ca tp nh km chnh l ID ca nh i din hin ti, khng xa tp nh km.
if ($attachedMediaId == $postThumbnailId) {
return false;
// Nu khng, tip tc xa tp nh km.
} else {
return true;
}
}
// 3. Khng chun b d liu nh i din cho bi vit khi thu thp li.
add_filter('kdn/post/allow_prepare_thumbnail', 'kdn_post_allow_prepare_thumbnail', 10, 5);
function kdn_post_allow_prepare_thumbnail($allowRun, $postData, $postBot, $proxyList, $postMediaPreparer) {
// Nu ang thu thp li, khng chun b d liu cho nh i din.
if ($postBot->isRecrawl()) {
return false;
// Nu khng, tip tc chun b d liu cho nh i din.
} else {
return true;
}
}
// 4. Gi li nh km cho nh i din ca bi vit khi thu thp li.
add_filter('kdn/post/thumbnail_data_before_set', 'kdn_post_thumbnail_data_before_set', 10, 11);
function kdn_post_thumbnail_data_before_set($mediaFile, $data, $postData, $postBot, $postSaver, $siteId, $postUrl, $urlTuple, $isRecrawl, $postId, $isFirstPage) {
// Nu ang thu thp li, gi li nh km cho nh i din.
if ($isRecrawl) {
return null;
// Nu khng, tip tc x l.
} else {
return $mediaFile;
}
}
// HIN TH QUNG CO PHN B U TRONG CHAP (Chung)
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
if(is_single() && !is_admin() && get_post_type() == 'chap') {
$options = get_option('my_option_name');
$ads_chuoiid = $options['id_loaitru'];
$fchuoiid = explode(',', str_replace(' ', '', $ads_chuoiid));
$fidtrang = get_the_ID();
if ( !in_array("".$fidtrang."", $fchuoiid) ) {
return prefix_insert_ads( $content );
}
}
return $content;
}
function prefix_insert_ads( $content ) {
$closing_p = '</p>';
$paragraphs = explode( $closing_p, $content );
$options = get_option('my_option_name');
$pnumber = substr_count($content, '<p>') + 1;
if($pnumber > 13 && $pnumber < 21) {
$pnumber1 = floor($pnumber / 2) - 1;
}
elseif($pnumber > 20 && $pnumber < 28) {
$pnumber1 = floor($pnumber / 3) - 1;
$pnumber2 = floor($pnumber / 3)*2 - 1;
}
elseif($pnumber > 27) {
$pnumber1 = floor($pnumber / 4) - 1;
$pnumber2 = floor($pnumber / 4)*2 - 1;
$pnumber3 = floor($pnumber / 4)*3 - 1;
}
foreach ($paragraphs as $index => $paragraph) {
$paragraphs[$index] .= $closing_p;
if($pnumber > 13 && $pnumber < 21) {
if ($index == $pnumber1) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c1'].'</div>';
}
}
elseif($pnumber > 20 && $pnumber < 28) {
if ($index == $pnumber1) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c1'].'</div>';
}
if ($index == $pnumber2) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c2'].'</div>';
}
}
elseif($pnumber > 27) {
if ($index == $pnumber1) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c1'].'</div>';
}
if ($index == $pnumber2) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c2'].'</div>';
}
if ($index == $pnumber3) {
$paragraphs[$index] .= '<div style="margin-bottom:40px">'.$options['ads_c3'].'</div>';
}
}
}
return implode( '', $paragraphs );
}
function remove_sticker_new($id){
$term_taxonomy_ids = wp_get_object_terms($id, 'sticker', array('term_taxonomy_id' => 407));
if (!empty($term_taxonomy_ids)) {
if(current_time('timestamp') - get_post_time() > 15552000) wp_remove_object_terms($id, 'new', 'sticker');
}
}
?>
Function Calls
add_action | 1 |
Stats
MD5 | a7d4595b2632fea84b63908b565c5184 |
Eval Count | 0 |
Decode Time | 188 ms |