/** * Include Framework and Plugins */ require_once(TEMPLATEPATH . '/tesla_framework/tesla.php'); require_once(TEMPLATEPATH . '/theme_config/theme_shortcodes.php'); (!class_exists('GenerateCustomMeta')) ? require_once(TEMPLATEPATH . '/theme_config/helper/custom_meta_box.php') : ''; require_once(TEMPLATEPATH . '/theme_config/helper/widget-recent-posts.php'); require_once(TEMPLATEPATH . '/plugins/tgm-plugin-activation/register-plugins.php'); Class Megalith { public function __construct() { TT_ENQUEUE::$enabled = FALSE; // Actions add_action( 'after_setup_theme', array($this, 'theme_setup') ); add_action( 'wp_head', array($this, 'theme_favicon')); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_goods' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'request_js' ), 99); add_action( 'wp_enqueue_scripts', array($this, 'theme_custom_css'), 99); add_action( 'tt_theme_header', array( $this, 'header_view' ) ); add_action( 'tt_footer', array( $this, 'footer_content' ) ); //add_action( 'tt_page_meta', array( $this, 'page_meta_view' ) ); add_action( 'tt_content', array($this, 'create_pages_contents')); add_action( 'tt_before_pages', array($this, 'before_pages')); add_action( 'tt_after_pages', array($this, 'after_pages')); add_action( 'wp', array($this, 'detect_shortcode') ); add_action( 'widgets_init', array($this, 'sidebar_init') ); add_action('wp_ajax_tt_contact_form', array($this, 'tt_contact_form')); add_action('wp_ajax_nopriv_tt_contact_form', array($this, 'tt_contact_form')); add_action( 'wp_footer', array($this, 'theme_custom_js'), 100); if ( is_admin() ) { add_action( 'admin_enqueue_scripts', array( $this,'admin_enqueue_goods' ), 10, 1); add_action( 'load-post.php', array( $this, 'generate_custom_meta')); add_action( 'load-post-new.php', array( $this, 'generate_custom_meta')); } // Filters add_filter( 'get_search_form', array($this, 'filter_search_form') ); add_filter( 'excerpt_more', array($this, 'read_more_link') ); add_filter( 'get_the_excerpt', array($this, 'read_more_link_excerpt') ); add_filter( 'script_loader_tag',array( $this, 'add_id_to_script'),10,2); // Widgets register_widget('Recent_posts'); // Activate Visual Composer $this->start_visual_composer(); } /** * Add theme support and register theme support */ public function theme_setup() { add_theme_support( 'automatic-feed-links' ); add_theme_support( 'title-tag' ); add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 825, 510, true ); add_image_size('blog-thumb', 850, 350, true); add_image_size('testimonials-thumb', 120, 120, true); register_nav_menus( array( 'main_menu' => __( 'Primary Menu', 'megalith' ), ) ); register_nav_menus( array( 'footer_menu' => __( 'Footer Menu', 'megalith' ), ) ); add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' ) ); add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'audio' ) ); } /** * Favicon Picker */ public function theme_favicon() { $favicon_pat = ''; $favicon = _go('favicon_link') ? _go('favicon_link') : TT_THEME_URI . '/images/favicon.ico'; echo "\r\n" . sprintf($favicon_pat, $favicon) . "\r\n"; } /** * Enqueue Fonts, Styles and JS (front-end) */ public function enqueue_goods() { $protocol = is_ssl() ? 'https' : 'http'; $gfont_changer = array( _go('global_typo_font'), _go('links_settings_font'), _go('logo_text_font'), _go('headings_settings_font') ); $default_css = array( 'base-font' => "$protocol://fonts.googleapis.com/css?family=Lato:300,400,700|Merriweather:400,700,300", 'main-style' => TT_THEME_URI . "/css/screen.css", 'heme-style' => get_stylesheet_uri() ); // Google font picker foreach($gfont_changer as $font){ $font = str_replace(' ', '+', $font); if($font !== '') { wp_enqueue_style( 'tt-custom-font-' . $font, "$protocol://fonts.googleapis.com/css?family=$font"); } } // Main CSS and Fonts foreach ($default_css as $k => $css) { wp_enqueue_style( 'tt-' . $k, $css); } if ( is_singular() ) { wp_enqueue_script( "comment-reply" ); } } public function request_js() { wp_enqueue_script('require.js', TT_THEME_URI . '/js/components/require.js', array('jquery'), false, true); $custom_js = _go('custom_js'); // Transfer data to js $send_js = array( 'dirUri' => get_template_directory_uri() ); wp_localize_script('require.js', 'themeOptions', $send_js); } public function add_id_to_script($tag, $handle){ if( strpos($tag, '/js/components/require') ) { return ''; } else { return $tag; } } public function last_script() { global $wp_scripts; if(!empty($wp_scripts->registered['require.js']->src)) { printf("", $wp_scripts->registered['require.js']->src, TT_THEME_URI . '/js/options' ); } } /** * Enqueue Fonts, Styles and JS (admin) */ public function admin_enqueue_goods($hook) { if ( $hook == 'post-new.php' || $hook == 'post.php' ) { wp_enqueue_style( 'wp-color-picker' ); } wp_enqueue_style('tt-admin', TT_THEME_URI . '/css/admin/admin.css'); wp_enqueue_script('admin.js', TT_THEME_URI . '/js/admin/admin.js', array('jquery'), false, true); } /** * Theme custom CSS */ public function theme_custom_css() { // Main styles switches $custom_css = (_go('layout_style') == 'Boxed') ? '.main-container {max-width: 1300px; margin: 0 auto; overflow: hidden} ' : ''; $custom_css .= (_go('body_background') && (_go('body_color') || _go('body_background_repeat') || _go('body_background_position'))) ? 'body {' : ''; $custom_css .= (_go('body_background')) ? 'background-image: url('._go('body_background').'); ' : ''; $custom_css .= (_go('body_color')) ? 'background-color: '._go('body_color').'; ' : ''; $custom_css .= (_go('body_background') && _go('body_background_repeat')) ? 'background-repeat: '.strtolower(_go('body_background_repeat')).'; ' : ''; $custom_css .= ( _go('body_background') && _go('body_background_position')) ? 'background-attachment: '.strtolower(_go('body_background_position')).'; ' : ''; $custom_css .= (_go('body_background') && (_go('body_color') || _go('body_background_repeat') || _go('body_background_position'))) ? '}' : ''; // Main styles switches $custom_css .= (_go('header_color')) ? '.header-navbar {background-color: '._go('header_color').' !important;}' : ''; // Logo text $custom_css .= (_go('logo_text') && (_go('logo_text_color') || _go('logo_text_font') || _go('logo_text_size'))) ? '.logo-text{' : ''; $custom_css .= (_go('logo_text') && _go('logo_text_color')) ? 'color: '._go('logo_text_color').';' : ''; $custom_css .= (_go('logo_text') && _go('logo_text_font')) ? 'font-family: '._go('logo_text_font').';' : ''; $custom_css .= (_go('logo_text') && _go('logo_text_size')) ? 'font-size: '._go('logo_text_size').'px;' : ''; $custom_css .= (_go('logo_text') && (_go('logo_text_color') || _go('logo_text_font') || _go('logo_text_size'))) ? '}' : ''; // Page meta $page_meta = $this->get_custom_meta('page_meta'); $custom_css .= !empty($page_meta->bg_color)? '.box-breadcrumbs {background-color: '.$page_meta->bg_color.';}' : ''; $custom_css .= !empty($page_meta->icon_color)? '.breadcrumbs-title, .breadcrumbs-links * {color: '.$page_meta->icon_color.';}' : ''; $custom_css .= (_go('canvas_color')) ? sprintf('.main-container { background: %s;}', _go('canvas_color')) : ''; $custom_css .= (_go('primary_color')) ? sprintf('.bg-alpha, .vc_btn-alpha, .bg-alpha-hover:hover, .timeline-item > h6:before, .air-nav .current, .tabs-nav a:after, .featured-icon figure > a:hover, .big-tabs:before, .toggle-item input[type="radio"]:checked + h6, .sort-by > ul input[type=radio] + span:before, .page-numbers.current, .pagination-links > li:hover, .main-nav > ul > .current_page_item > a, .current_page_parent > a, .portfolio-filters > ul > li label input:checked + span:hover, button.button-outline:hover, .portfolio-filters > ul > li label input:checked + span {background: %s !important;}', _go('primary_color')) : ''; $custom_css .= (_go('primary_color')) ? sprintf('body .text-alpha, .loop-facts .featured-icon:hover + *, .portfolio-filters > ul > li label input:checked + span:after, input[type=text]:focus + span, input[type=email]:focus + span, html li:not(.current_page_item) a:not(.vc_btn):hover, input[type=search]:focus + span, textarea:focus + span, .big-tabs-content:after, .social-networks > li a:hover i, .social-networks > li a:focus i, .active-big-tab > .tab-item > div {color: %s !important;}', _go('primary_color')) : ''; $custom_css .= (_go('primary_color')) ? sprintf('a:hover {color: %s}', _go('primary_color')) : ''; $custom_css .= (_go('primary_color')) ? sprintf('.post:not(.format-standard) .post-thumb {border-color: %s}', _go('primary_color')) : ''; $custom_css .= (_go('primary_color')) ? sprintf('.big-tabs, .portfolio-filters, input[type=text]:focus, input[type=email]:focus, input[type=search]:focus, textarea:focus {border-bottom-color: %s !important;}', _go('primary_color')) : ''; $custom_css .= (_go('secondary_color')) ? sprintf('.bg-beta {background: %s !important;}', _go('secondary_color')) : ''; $custom_css .= (_go('secondary_color')) ? sprintf('.text-beta {color: %s !important;}', _go('secondary_color')) : ''; $custom_css .= (_go('global_typo_color')) ? sprintf('body {color: %s;}', _go('global_typo_color')) : ''; $custom_css .= (_go('global_typo_size')) ? sprintf('body {font-size: %spx;}', _go('global_typo_size')) : ''; $custom_css .= (_go('global_typo_font')) ? sprintf('body {font-family: %s;}', _go('global_typo_font')) : ''; $custom_css .= (_go('links_settings_color')) ? sprintf('a {color: %s;}', _go('links_settings_color')) : ''; $custom_css .= (_go('links_settings_size')) ? sprintf('a {font-size: %spx;}', _go('links_settings_size')) : ''; $custom_css .= (_go('links_settings_font')) ? sprintf('a {font-family: %s;}', _go('links_settings_font')) : ''; $custom_css .= (_go('headings_settings_color')) ? sprintf('h1, h2, h3, h4, h5, h6 {color: %s;}', _go('headings_settings_color')) : ''; $custom_css .= (_go('headings_settings_font')) ? sprintf('h1, h2, h3, h4, h5, h6 {font-family: %s;}', _go('headings_settings_font')) : ''; $custom_css .= (_go('headings_one_settings_size')) ? sprintf('h1 {font-size: %spx;}', _go('headings_one_settings_size')) : ''; $custom_css .= (_go('headings_two_settings_size')) ? sprintf('h2 {font-size: %spx;}', _go('headings_two_settings_size')) : ''; $custom_css .= (_go('headings_three_settings_size')) ? sprintf('h3 {font-size: %spx;}', _go('headings_three_settings_size')) : ''; $custom_css .= (_go('headings_four_settings_size')) ? sprintf('h4 {font-size: %spx;}', _go('headings_four_settings_size')) : ''; $custom_css .= (_go('headings_five_settings_size')) ? sprintf('h5 {font-size: %spx;}', _go('headings_five_settings_size')) : ''; $custom_css .= (_go('headings_six_settings_size')) ? sprintf('h6 {font-size: %spx;}', _go('headings_six_settings_size')) : ''; $custom_css .= (_go('custom_css')) ? _go('custom_css') : ''; wp_add_inline_style('tt-main-style', $custom_css); } /** * Generate navigation */ public function theme_navigation($menu_name, $css_class=null, $menu=null) { $defaults = array( 'theme_location' => strtolower(str_replace(" ", "_", $menu_name)), 'menu' => $menu, 'container' => false, 'container_class' => '', 'container_id' => '', 'menu_class' => $css_class, 'menu_id' => '', 'echo' => false, 'fallback_cb' => array($this, 'menu_callback'), 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '', 'depth' => 0, 'walker' => '' ); $menu_items = wp_nav_menu( $defaults ); if(is_singular('portfolio')) { $menu_items = str_replace('current_page_parent', '', $menu_items); $menu_items = str_replace('current_menu_parent', '', $menu_items); $menu_items = str_replace('page-item-'.get_option('page_for_portfolio'), 'page-item-'.get_option('page_for_portfolio').' current_page_parent', $menu_items); } return $menu_items; } /** * Menu callback (default input) */ public function menu_callback($class = '') { $defaults = array( 'authors' => '', 'child_of' => 0, 'date_format' => get_option('date_format'), 'depth' => 0, 'echo' => 0, 'exclude' => '', 'include' => '', 'link_after' => '', 'link_before' => '', 'post_type' => 'page', 'post_status' => 'publish', 'show_date' => '', 'sort_column' => 'menu_order, post_title', 'title_li' => '', 'walker' => '' ); return sprintf('', $class['menu_class'], wp_list_pages($defaults)); } /** * Lazy images */ public function lazy_img($img, $alt=null, $width=null, $height=null) { if(is_array($img)) { $img = $img[0]; $width = $img[1]; $height = $img[2]; } $width = !empty($width) ? sprintf('width="%s"', $width) : ''; $height = !empty($height) ? sprintf('height="%s"', $height) : ''; $holder = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQIW2NkAAIAAAoAAggA9GkAAAAASUVORK5CYII='; return sprintf('%s', $holder, $img, $alt, $width, $height); } /** * Main Logo */ public function theme_logo($logo_id = false, $class='') { $logo_url = _go('logo_image'); $logo_text = _go('logo_text'); $pattern = '
%s
'; if(!empty($logo_id)) { $logo_url = wp_get_attachment_url( $logo_id); } if(!empty($logo_text)) { return sprintf($pattern, $class, esc_url( home_url( '/' ) ), '' . $logo_text . ''); } else { if(!empty($logo_url)) { $logo_image = sprintf('%s', get_bloginfo('name'), $logo_url); } else { $logo_image = sprintf('%s', get_bloginfo('name'), TT_THEME_URI . '/images/logo.png'); } return sprintf($pattern, $class, esc_url( home_url( '/' ) ), $logo_image); } } /** * Helper to invoke template views */ public function tt_view($name = null, array $params = array(), $folder=false) { global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; do_action("get_template_part_tt", 'tt', $name); $templates = array(); if (isset($name)) { $template_container = isset($folder) ? 'templates/'.$folder : 'templates'; $templates[] = $template_container."/tt-{$name}.php"; } $_template_file = locate_template($templates, false, false); if (is_array($wp_query->query_vars)) { extract($wp_query->query_vars, EXTR_SKIP); } extract($params, EXTR_SKIP); require($_template_file); } /** * Build class attribute */ private function class_attr($class = null) { $pattern = 'class="%s"'; if(isset($class)) { return sprintf($pattern, $class); } } /** * Build breadcrumbs */ private function breadcrumbs() { global $post; $links = array(); $meta = $this->get_custom_meta('page_meta'); if(!empty($meta->hide_breadcrumbs) || is_404()) { return; } if(is_home()) { $page_id = get_option( 'page_for_posts' ); $links[] = get_the_title($page_id); } else if(is_singular('post')) { $page_id = get_option( 'page_for_posts' ); ( !empty( $page_id ) ) ? $links[get_permalink($page_id)] = get_the_title($page_id) : ''; $links[] = get_the_title(); } else if(is_singular('portfolio')) { $page_id = get_option( 'page_for_portfolio' ); ( !empty( $page_id ) ) ? $links[get_permalink($page_id)] = get_the_title($page_id) : ''; $links[] = get_the_title(); } else if(is_tag()) { $page_id = get_option( 'page_for_posts' ); ( !empty( $page_id ) ) ? $links[get_permalink($page_id)] = get_the_title($page_id) : ''; $links[] = single_tag_title('', false); } else if(is_category()) { $page_id = get_option( 'page_for_posts' ); ( !empty( $page_id ) ) ? $links[get_permalink($page_id)] = get_the_title($page_id) : ''; $links[] = single_cat_title("", false); } else if(is_archive()) { $page_id = get_option( 'page_for_posts' ); ( !empty( $page_id ) ) ? $links[get_permalink($page_id)] = get_the_title($page_id) : ''; $links[] = get_the_archive_title(); } else if(is_search()) { $page_id = get_option( 'page_for_posts' ); $links[] = __('Search', 'megalith'); } else if(is_page()) { if($post->post_parent > 0) { $page_id = $post->post_parent; if($page_id !== (int) get_option('page_on_front')) { $links[get_permalink($page_id)] = get_the_title($page_id); } } $links[] = get_the_title(); } if(is_home() || is_singular('post') || is_tag() || is_archive() || is_search()) { $id = get_option( 'page_for_posts' ); } else if(isset($post->ID)) { $id = $post->ID; } else { return; } $page_meta = $this->get_custom_meta('page_meta'); $blog_meta = $this->get_custom_meta('blog_meta'); $page_icon = !empty($page_meta->icon) ? sprintf(' ', $page_meta->icon) : ''; if(!empty($blog_meta->post_image)) { $thumb_id = $blog_meta->post_image; $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full', true); $thumb_url = (!empty($thumb_url_array[0])) ? 'data-box-img="'.$thumb_url_array[0].'"' : ''; } else { $thumb_id = get_post_thumbnail_id($id); $thumb_url_array = (is_singular('portfolio')) ? get_option( 'page_for_portfolio' ) : wp_get_attachment_image_src($thumb_id, 'full', true); $thumb_url = (!empty($thumb_url_array[0]) && has_post_thumbnail($id)) ? 'data-box-img="'.$thumb_url_array[0].'"' : ''; } if(is_archive()) { $alt_title = !empty($page_meta->description) ? sprintf('', $page_icon.$page_meta->description) : sprintf('', $page_icon.get_the_archive_title()); } else if(is_search()) { $alt_title = !empty($page_meta->description) ? sprintf('', $page_icon.$page_meta->description) : sprintf( __( '', 'megalith' ), $page_icon.get_search_query() ); } else { $alt_title = !empty($page_meta->description) ? sprintf('', $page_icon.$page_meta->description) : sprintf('', $page_icon.get_the_title($id)); } $defaults = array( 'links' => $links, 'thumbnail_url' => $thumb_url, 'alt_title' => $alt_title, ); ob_start(); $this->tt_view('breadcrumbs', $defaults); return ob_get_clean(); } /** * Build header */ public function header_view() { $logo_size = _go('header_size_logo'); $nav_size = _go('header_size_nav'); $logo_position = _go('logo_position') ? 'align-'._go('logo_position') : ''; $nav_position = _go('nav_position') ? 'align-'._go('nav_position') : 'align-right'; $defaults = array( 'logo_class' => !empty($logo_size) ? $this->class_attr('col-xs-8 col-sm-'.$logo_size) : $this->class_attr('col-sm-2 col-xs-8'), 'navigation_class' => !empty($nav_size) ? $this->class_attr('col-xs-4 col-sm-'.$nav_size) : $this->class_attr('col-sm-10 col-xs-4'), 'logo' => $this->theme_logo(false, $logo_position), 'navigation' => $this->theme_navigation('main_menu', 'inline-list uppercase '.$nav_position), 'breadcrumbs' => $this->breadcrumbs() ); // Hide main header $page_content = get_queried_object(); $page_content = !empty($page_content->post_content) ? $page_content->post_content : ''; if(!empty($page_content) && has_shortcode($page_content, 'tt_header')) { return; } $nav_option = strtolower(_go('navigation')); switch ($nav_option) { case 'regular': $nav_settings = ''; break; case 'sticky': $nav_settings = 'data-sticky="true" data-nav-scroll="true"'; break; case 'sticky hide on scroll': $nav_settings = 'data-sticky="true"'; break; default: $nav_settings = 'data-sticky="true"'; break; } $defaults['nav_settings'] = $nav_settings; $this->tt_view('header', $defaults); } /** * Build footer menu section */ public function footer_content() { $page_meta = $this->get_custom_meta('page_meta'); if(is_active_sidebar('sidebar-3')) { echo ''; } } /** * Global social networks */ public function global_socials() { $networks = array( '182' => 'facebook', '510' => 'twitter', '298' => 'linkedin', '397' => 'rss', '158' => 'dribbble', '244' => 'google' ); $social_buttons = ''; foreach ($networks as $icon => $item) { $network = _go('social_platforms_'.$item); if(!empty($network)) { $social_buttons .= sprintf('
  • ', $item, _go('social_platforms_'.$item), $icon); } } if(!empty($social_buttons)) { return sprintf('', $social_buttons); } } /** * Build content for different page instance */ public function create_pages_contents() { global $post; if(is_home() || is_singular('post') || is_tag() || is_category() || is_archive() || is_search()) { $thumb_id = get_post_thumbnail_id($post->ID); $thumb_size = is_singular('post') ? 'full' : 'blog-thumb'; $thumb_array = wp_get_attachment_image_src($thumb_id, $thumb_size, true); $alt_meta = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); $post_format = get_post_format(); $format_pat = '
    '; switch ($post_format) { case 'aside': $post_format_icon = sprintf($format_pat, '347'); break; case 'image': $post_format_icon = sprintf($format_pat, '265'); break; case 'video': $post_format_icon = sprintf($format_pat, '208'); break; case 'quote': $post_format_icon = sprintf($format_pat, '375'); break; case 'link': $post_format_icon = sprintf($format_pat, '296'); break; case 'gallery': $post_format_icon = sprintf($format_pat, '222'); break; case 'audio': $post_format_icon = sprintf($format_pat, '332'); break; default: $post_format_icon = ''; break; } if(is_singular('post')) { $post_format_icon = ''; } ob_start(); the_content($post->ID); $output = ob_get_clean(); $embeds = get_media_embedded_in_content( $output ); $defaults = array( 'post_thumbnail' => $this->lazy_img($thumb_array[0], $alt_meta, $thumb_array[1], $thumb_array[2]), 'post_share' => '', 'post_format' => $post_format, 'post_format_icon' => $post_format_icon, 'video_embed' => !empty($embeds[0]) ? $embeds[0] : '', 'content' => $output ); $format = get_post_format(); $posts_format = !empty($format) ? '-'.$format : ''; $this->tt_view('blog-loop', $defaults); } else { echo '
    '; the_content(); echo '
    '; } } /** * Get all kind of posts */ public function tt_get_post($post_type = 'post', $config = false) { $args = array( 'posts_per_page' => -1, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => $post_type, 'post_mime_type' => '', 'post_parent' => '', 'post_status' => 'publish', 'suppress_filters' => true ); if(!empty($config)) { $args = wp_parse_args( $config, $args ); } return get_posts($args); } /** * Before page hook */ public function before_pages() { if(is_home() || is_singular('post') || is_tag() || is_category() || is_archive() || is_search()) { echo '
    '; if(is_active_sidebar('sidebar-1') && is_active_sidebar('sidebar-2')) { echo '
    '; echo '
    '; } else if(is_active_sidebar('sidebar-2')) { echo '
    '; echo '
    '; } else if(is_active_sidebar('sidebar-1')) { echo '
    '; } else { echo '
    '; } echo '
      '; } } /** * After page hook */ public function after_pages() { if(is_home() || is_singular('post') || is_tag() || is_category() || is_archive() || is_search()) { echo sprintf('
    %s', $this->pagination_links()); if(is_singular('post')) { the_tags( '
    • '.__('Tags:', 'megalith').'
    • ', '
    • ', '
    ' ); comments_template(); } echo '
    '; if(is_active_sidebar('sidebar-1')) { echo '
    '; } echo '
    '; } } /** * Build read more link */ function read_more_link() { return ''; } function read_more_link_excerpt($content) { return $content . '

    '.__('Read more', 'megalith').''; } /** * Build pagination links */ public function pagination_links() { $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; $pagenum_link = html_entity_decode( get_pagenum_link() ); $query_args = array(); $url_parts = explode( '?', $pagenum_link ); if ( isset( $url_parts[1] ) ) { wp_parse_str( $url_parts[1], $query_args ); } $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link ); $pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%'; // Set up paginated links. $links = paginate_links( array( 'base' => $pagenum_link, 'format' => $format, 'total' => $GLOBALS['wp_query']->max_num_pages, 'current' => $paged, 'mid_size' => 1, 'add_args' => array_map( 'urlencode', $query_args ), 'prev_text' => '', 'next_text' => '', 'type' => 'array', ) ); $pagination_pat = '
    '; return !empty($links) ? sprintf($pagination_pat, join("\n\t
  • ", $links)) : ''; } /** * Comments pagination */ public function comments_pagination() { $default = array( 'echo' => false, 'prev_text' => '', 'next_text' => '' ); $pag_links = trim(preg_replace('/\s+/', ' ', paginate_comments_links($default))); if($pag_links) { $pag_links = str_replace('', '
  • ', $pag_links); $pag_links = str_replace('> ", "current bg-alpha'>", $pag_links); $pag_links = str_replace('', '
  • ', $pag_links); $pag_links = sprintf('
  • %s
  • ', $pag_links); $pag_links = str_replace('
  • ', '', $pag_links); echo sprintf('
    ', $pag_links); } } /** * Generate sidebars */ public function sidebar_init() { register_sidebar( array( 'name' => __( 'Main left sidebar', 'megalith' ), 'id' => 'sidebar-1', 'description' => __( 'Use this sidebar for left side widgets', 'megalith' ), 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '
    ', 'after_title' => '
    ', )); register_sidebar( array( 'name' => __( 'Main right sidebar', 'megalith' ), 'id' => 'sidebar-2', 'description' => __( 'Use this sidebar for left side widgets', 'megalith' ), 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '
    ', 'after_title' => '
    ', )); register_sidebar( array( 'name' => __( 'Footer widget area', 'megalith' ), 'id' => 'sidebar-3', 'description' => __( 'Use this sidebar to show widgets in the footer', 'megalith' ), 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '', )); register_sidebar( array( 'name' => __( 'Page optional sidebar', 'megalith' ), 'id' => 'sidebar-4', 'description' => __( 'Use this sidebar only with Visual Composer', 'megalith' ), 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '
    ', 'after_title' => '
    ', )); } /** * Separate title and widget content */ /*public function filter_widget_title($title, $instance, $id) { $class = ($id !== 'search') ? 'widget-content style-alpha' : ''; if(!empty($title)) { return sprintf('
    %s
    ', $title, $class); } else { return sprintf('
    ', $class); } }*/ /** * Make better default widgets */ public function better_sidebr($sidebar_name) { add_filter( 'widget_title', array($this, 'filter_widget_title'), 10, 3 ); ob_start(); dynamic_sidebar($sidebar_name); $sidebar_content = ob_get_clean(); $sidebar_content = str_replace('