';}
if ($rel == 'wooyoutube'){
$random_key = rand(0, 50);
$rel = 'wooyoutube_gallery_'.(int)$random_key;
}
wp_enqueue_script('modulobox'); wp_enqueue_style('modulobox');
if($exceptfirst){
array_shift($post_image_videos);
}
if($fullsize){
$size = 'width=800 height=520';
$nothumb = get_template_directory_uri() . '/images/default/noimage_800_520.png';
}else{
$size = 'width=450 height=350';
$nothumb = get_template_directory_uri() . '/images/default/noimage_450_350.png';
}
$i = 0;
foreach($post_image_videos as $key=>$video) {
$video = trim($video);
$img = parse_video_url(esc_url($video), "maxthumb");
$i ++;
$idclass = ($id) ? 'id='.$id.'-'.$i : '';
echo '
';
echo '';
if($onlyone) break;
}
if($wrapper == 1) {echo '
';}
}
}
}
/* */
function bd_cloaking_deal_url( $external_link, $post_id ){
if( is_string( $post_id ) ){
$dealstore = get_term_by('slug', $post_id, 'dealstore');
if( $dealstore ){
$external_link = get_term_meta( $dealstore->term_id, 'brand_url', true );
}
}
return $external_link;
}
add_filter( 'wpsmcal_filter_url', 'bd_cloaking_deal_url', 10, 2 );
/**
* Gets taxonomy term of th post
* @param $post as object or post ID as numeric
* @param $tag false by defult if it needs to get a tag taxonomy
*/
if(!function_exists('rh_get_taxonomy_of_post')){
function rh_get_taxonomy_of_post( $post = '', $tag = false ){
if( empty( $post ) )
global $post;
if( is_object( $post ) ){
$post_type = $post->post_type;
}elseif( is_numeric( $post ) ){
$post_type = get_post_type( $post );
}else{
$post_type = '';
}
if( empty( $post_type ) )
return false;
switch( $post_type ){
case 'blog':
$taxonomy = 'blog_category';
if( $tag )
$taxonomy = 'blog_tag';
break;
default:
$taxonomy = 'category';
if( $tag )
$taxonomy = 'post_tag';
}
return $taxonomy;
}
}
//////////////////////////////////////////////////////////////////
// Check plugin active
//////////////////////////////////////////////////////////////////
function rh_check_plugin_active( $plugin ) {
return in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) || rh_check_plugin_active_for_network( $plugin );
}
function rh_check_plugin_active_for_network( $plugin ) {
if ( !is_multisite() )
return false;
$plugins = get_site_option( 'active_sitewide_plugins');
if ( isset($plugins[$plugin]) )
return true;
return false;
}
function rh_filesystem( $method = 'get_content', $file_path='', $content = '' ){
if( empty( $file_path ) )
return;
global $wp_filesystem;
if( empty( $wp_filesystem ) ) {
require_once ( ABSPATH . '/wp-admin/includes/file.php' );
WP_Filesystem();
}
if( $method == 'get_content' ){
$result = $wp_filesystem->get_contents( $file_path );
if( $result && !is_wp_error( $result ) ){
return $result;
}else{
return;
}
}elseif( $method == 'put_content' ){
$result = $wp_filesystem->put_contents( $file_path, $content, FS_CHMOD_FILE );
if( !is_wp_error( $result ) ){
return true;
}else{
return;
}
}else{
return;
}
}
//////////////////////////////////////////////////////////////////
// Locate template with support RH grandchild
//////////////////////////////////////////////////////////////////
function rh_locate_template($template_names, $load = false, $require_once = true ) {
$located = '';
foreach ( (array) $template_names as $template_name ) {
if ( !$template_name )
continue;
if(defined( 'RH_GRANDCHILD_DIR' ) && file_exists(RH_GRANDCHILD_DIR . $template_name)){
$located = RH_GRANDCHILD_DIR . '/' . $template_name;
break;
}
if ( file_exists(get_stylesheet_directory() . '/' . $template_name)) {
$located = get_stylesheet_directory() . '/' . $template_name;
break;
} elseif ( file_exists(get_template_directory() . '/' . $template_name) ) {
$located = get_template_directory() . '/' . $template_name;
break;
}
}
if ( $load && '' != $located )
load_template( $located, $require_once );
return $located;
}
//////////////////////////////////////////////////////////////////
// Helper Functions
//////////////////////////////////////////////////////////////////
function rehub_kses($html)
{
$allow = array_merge(wp_kses_allowed_html( 'post' ), array(
'link' => array(
'href' => true,
'rel' => true,
'type' => true,
),
'script' => array(
'src' => true,
'charset' => true,
'type' => true,
),
'div' => array(
'data-href' => true,
'data-width' => true,
'data-numposts' => true,
'data-colorscheme' => true,
'class' => true,
'id' => true,
'style' => true,
'title' => true,
'role' => true,
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
)
));
return wp_kses($html, $allow);
}
function rh_import_tables_from_json( $db_table = '', $path_to_json_file = '' ) {
if( !empty( $db_table ) ){
global $wpdb;
$table_name = $wpdb->prefix . $db_table;
$table_name = esc_attr( $table_name );
$table_name = esc_sql( $table_name );
//$table_name = '%' . $table_name . '%';
if( $wpdb->get_var("SHOW TABLES LIKE '$table_name';") != $table_name )
return;
$responce = $wpdb->query( "TRUNCATE {$table_name};" );
if( $path_to_json_file ) {
$json_data = json_decode( rh_filesystem('get_content', $path_to_json_file), true );
if(empty($json_data)) return;
foreach( $json_data as $id => $row ){
$insert_pairs = array();
foreach( $row as $key => $val ) {
$insert_pairs[addslashes( $key )] = addslashes( $val );
}
$insert_keys = '`' . implode( '`,`', array_keys( $insert_pairs ) ) . '`';
$insert_vals = '"' . implode( '","', array_values( $insert_pairs ) ) . '"';
$wpdb->query( "INSERT INTO `{$table_name}` ({$insert_keys}) VALUES ({$insert_vals});" );
}
}
}
}
//////////////////////////////////////////////////////////////////
// EXCERPT
//////////////////////////////////////////////////////////////////
if( !function_exists('kama_excerpt') ) {
function kama_excerpt($args=''){
global $post;
parse_str($args, $i);
$maxchar = isset($i['maxchar']) ? (int)trim($i['maxchar']) : 350;
$sanitize_callback = isset($i['sanitize_callback']) ? trim($i['sanitize_callback']) : 'strip_tags';
$text = isset($i['text']) ? trim($i['text']) : '';
$save_format = isset($i['save_format']) ? trim($i['save_format']) : false;
$save_tags = isset($i['save_tags']) ? trim($i['save_tags']) : '';
$echo = isset($i['echo']) ? false : true;
$more = isset($i['more']) ? true : false;
$out ='';
if (!$text){
$out = $post->post_excerpt ? $post->post_excerpt : $post->post_content;
$out = preg_replace ("~\[/?.*?\]~", '', $out ); //delete shortcodes:[singlepic id=3]
// for
if($more && !$post->post_excerpt && strpos($post->post_content, '') ){
preg_match ('/(.*)/s', $out, $match);
$out = str_replace("\r", '', trim($match[1], "\n"));
$out = preg_replace( "!\n\n+!s", "". str_replace( "\n", "
", $out ) ."
";
if ($echo)
return print ''.$out;
return $out;
}
}
$out = $text.$out;
$out = 'strip_tags' === $sanitize_callback ? strip_tags( $out, $save_tags ) : call_user_func( $sanitize_callback, $out );
if ( mb_strlen( $out ) > $maxchar ){
$out = mb_substr( $out, 0, $maxchar );
$out = preg_replace('@(.*)\s[^\s]*$@s', '\\1 ...', $out );
}
if($save_format){
$out = str_replace( "\r", '', $out );
$out = preg_replace( "!\n\n+!", "". str_replace ( "\n", "
", trim($out) ) ."
";
}
if($echo) return print ''.$out;
return $out;
}
}
// Create the Custom Truncate
if( !function_exists('rehub_truncate') ) {
function rehub_truncate($args=''){
parse_str($args, $i);
$maxchar = isset($i['maxchar']) ? (int)trim($i['maxchar']) : 350;
$text = isset($i['text']) ? trim($i['text']) : '';
$save_format = isset($i['save_format']) ? trim($i['save_format']) : false;
$echo = isset($i['echo']) ? false : true;
$out ='';
$out = $text.$out;
$out = preg_replace ("~\[/?.*?\]~", '', $out );
$out = strip_tags(strip_shortcodes($out));
if ( mb_strlen( $out ) > $maxchar ){
$out = mb_substr( $out, 0, $maxchar );
$out = preg_replace('@(.*)\s[^\s]*$@s', '\\1 ...', $out );
}
if($save_format){
$out = str_replace( "\r", '', $out );
$out = preg_replace( "!\n\n+!", "". str_replace ( "\n", "
", trim($out) ) ."
";
}
if($echo) return print ''.$out;
return $out;
}
}
//////////////////////////////////////////////////////////////////
// Pagination
//////////////////////////////////////////////////////////////////
if( !function_exists('rehub_pagination') ) {
function rehub_pagination() {
if( is_singular() )
return;
global $paged;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '';
if ($show_home_link == 1) {
echo '
' . $text['home'] . '';
if ($frontpage_id == 0 || $parent_id != $frontpage_id) echo ''.$delimiter;
}
if ( is_category() ) {
$this_cat = get_category(get_query_var('cat'), false);
if ($this_cat->parent != 0) {
$cats = get_category_parents($this_cat->parent, TRUE, $delimiter);
if ($show_current == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);
$cats = str_replace('
', '' . $link_after, $cats);
if ($show_title == 0) $cats = preg_replace('/ title="(.*?)"/', '', $cats);
echo ''.$cats;
}
if ($show_current == 1) echo ''.$before . sprintf($text['category'], single_cat_title('', false)) . $after;
} elseif ( is_search() ) {
echo ''.$before . sprintf($text['search'], get_search_query()) . $after;
} elseif ( is_day() ) {
echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
echo sprintf($link, get_month_link(get_the_time('Y'),get_the_time('m')), get_the_time('F')) . $delimiter;
echo ''.$before . get_the_time('d') . $after;
} elseif ( is_month() ) {
echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
echo ''.$before . get_the_time('F') . $after;
} elseif ( is_year() ) {
echo ''.$before . get_the_time('Y') . $after;
} elseif ( is_single() && !is_attachment() ) {
if ( get_post_type() == 'blog' ) {
$bloglabel = (rehub_option('blog_posttype_label')) ? rehub_option('blog_posttype_label') : esc_html__('Blog', 'rehub-theme');
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
printf($link, $home_link . $slug['slug'] . '/', $bloglabel);
if ($show_current == 1) echo ''.$delimiter . $before . get_the_title() . $after;
}
else if ( get_post_type() != 'post' ) {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
printf($link, $home_link . $slug['slug'] . '/', $post_type->labels->singular_name);
if ($show_current == 1) echo ''.$delimiter . $before . get_the_title() . $after;
} else {
$cat = get_the_category();
if(!empty($cat)){
$cat = $cat[0];
$cats = get_category_parents($cat, TRUE, $delimiter);
if ($show_current == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);
$cats = str_replace('
', '' . $link_after, $cats);
if ($show_title == 0) $cats = preg_replace('/ title="(.*?)"/', '', $cats);
echo ''.$cats;
if ($show_current == 1) echo ''.$before . get_the_title() . $after;
}
}
} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
$post_type = get_post_type_object(get_post_type());
echo ''.$before . $post_type->labels->singular_name . $after;
} elseif ( is_attachment() ) {
$parent = get_post($parent_id);
$cat = get_the_category($parent->ID); $cat = (!empty($cat[0])) ? $cat[0] : '';
if ($cat) {
$cats = get_category_parents($cat, TRUE, $delimiter);
$cats = str_replace('
', '' . $link_after, $cats);
if ($show_title == 0) $cats = preg_replace('/ title="(.*?)"/', '', $cats);
echo ''.$cats;
}
printf($link, get_permalink($parent), $parent->post_title);
if ($show_current == 1) echo ''.$delimiter . $before . get_the_title() . $after;
} elseif ( is_page() && !$parent_id ) {
if ($show_current == 1) echo ''.$before . get_the_title() . $after;
} elseif ( is_page() && $parent_id ) {
if ($parent_id != $frontpage_id) {
$breadcrumbs = array();
while ($parent_id) {
$page = get_post($parent_id);
if ($parent_id != $frontpage_id) {
$breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID));
}
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
echo ''.$breadcrumbs[$i];
if ($i != count($breadcrumbs)-1) echo ''.$delimiter;
}
}
if ($show_current == 1) {
if ($show_home_link == 1 || ($parent_id_2 != 0 && $parent_id_2 != $frontpage_id)) echo ''.$delimiter;
echo ''.$before . get_the_title() . $after;
}
} elseif ( is_tag() ) {
echo ''.$before . sprintf($text['tag'], single_tag_title('', false)) . $after;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo ''.$before . sprintf($text['author'], $userdata->display_name) . $after;
} elseif ( is_404() ) {
echo ''.$before . $text['404'] . $after;
} elseif ( has_post_format() && !is_singular() ) {
echo get_post_format_string( get_post_format() );
}
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
echo 'Page ' . get_query_var('paged');
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
}
echo '
';
}
} // end dimox_breadcrumbs()
}
/** Autocontents class
* Taken from: wp-kama.ru/?p=1513
* V: 2.9.4
*/
class Kama_Contents{
// defaults options
public $opt = array(
'margin' => 40,
'selectors' => array('h2','h3','h4'),
'to_menu' => '↑',
'title' => '',
'css' => '',
'min_found' => 2,
'min_length' => 1500,
'page_url' => '',
'shortcode' => 'contents',
'spec' => '\'.+$*~=',
'wrap' => '',
'tag_inside' => '',
'anchor_type' => 'a', // or 'id'
'markup' => false,
);
public $contents; // collect html contents
private $temp;
static $inst;
function __construct( $args = array() ){
$this->set_opt( $args );
return $this;
}
static function init( $args = array() ){
is_null( self::$inst ) && self::$inst = new self( $args );
return self::$inst;
}
function set_opt( $args = array() ){
$this->opt = (object) array_merge( $this->opt, (array) $args );
}
function shortcode( $content, $contents_cb = '' ){
if( false === strpos( $content, '['. $this->opt->shortcode ) )
return $content;
// get contents data
if( ! preg_match('~^(.*)\['. $this->opt->shortcode .'([^\]]*)\](.*)$~s', $content, $m ) )
return $content;
$contents = $this->make_contents( $m[3], $m[2] );
if( $contents && $contents_cb && is_callable($contents_cb) )
$contents = $contents_cb( $contents );
return $m[1] . $contents . $m[3];
}
function make_contents( & $content, $tags = '' ){
$this->temp = $this->opt;
$this->temp->i = 0;
$this->contents = array();
if( is_string($tags) && $tags = trim($tags) )
$tags = array_map('trim', preg_split('~\s+~', $tags ) );
if( ! $tags )
$tags = $this->opt->selectors;
// check tags
foreach( $tags as $k => $tag ){
// remove special marker tags and set $args
if( in_array( $tag, array('embed','no_to_menu') ) ){
if( $tag == 'embed' ) $this->temp->embed = true;
if( $tag == 'no_to_menu' ) $this->opt->to_menu = false;
unset( $tags[ $k ] );
continue;
}
// remove tag if it's not exists in content
$patt = ( ($tag[0] == '.') ? 'class=[\'"][^\'"]*'. substr($tag, 1) : "<$tag" );
if( ! preg_match("/$patt/i", $content ) ){
unset( $tags[ $k ] );
continue;
}
}
if( ! $tags ) return;
// set patterns from given $tags
// separate classes & tags & set
$class_patt = $tag_patt = $level_tags = array();
foreach( $tags as $tag ){
// class
if( isset($tag[0]) && $tag[0] == '.' ){
$tag = substr( $tag, 1 );
$link = & $class_patt;
}
// html tag
else
$link = & $tag_patt;
$link[] = $tag;
$level_tags[] = $tag;
}
$this->temp->level_tags = array_flip( $level_tags );
$patt_in = array();
if( $tag_patt ) $patt_in[] = '(?:<('. implode('|', $tag_patt) .')([^>]*)>(.*?)<\/\1>)';
if( $class_patt ) $patt_in[] = '(?:<([^ >]+) ([^>]*class=["\'][^>]*('. implode('|', $class_patt) .')[^>]*["\'][^>]*)>(.*?)<\/'. ($patt_in?'\4':'\1') .'>)';
$patt_in = implode('|', $patt_in );
// collect and replace
$_content = preg_replace_callback("/$patt_in/is", array( &$this, 'kama_rh_contents_callback'), $content, -1, $count );
if( ! $count || $count < $this->opt->min_found )
return;
$content = $_content;
// html
static $css;
$embed = !! isset($this->temp->embed);
$ItemList = $this->opt->markup ? ' itemscope itemtype="https://schema.org/ItemList"' : '';
$this->contents =
( ( $this->opt->wrap ) ? '