<?php //ob_start();
$themename = "Adams";
define ('theme_name', $themename);
define ('theme_ver' , '1.2.0');

/**
 * Serpentsoft functions and definitions.
 *
 * Sets up the theme and provides some helper functions, which are used
 * in the theme as custom template tags. Others are attached to action and
 * filter hooks in WordPress to change core functionality.
 *
 * When using a child theme (see http://codex.wordpress.org/Theme_Development and
 * http://codex.wordpress.org/Child_Themes), you can override certain functions
 * (those wrapped in a function_exists() call) by defining them first in your child theme's
 * functions.php file. The child theme's functions.php file is included before the parent
 * theme's file, so the child theme functions would be used.
 *
 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
 * to a filter or action hook.
 *
 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
 *
 * @package Serpentsoft
 * @subpackage Adams_News 1.0
 * @since Adams News 1.0
 */

/**
 * Sets up the content width value based on the theme's design and stylesheet.
 */
if ( ! isset( $content_width ) ) {
    $content_width = 1240;
}

/**
* Options Framework
*/
require_once (TEMPLATEPATH . '/admin/index.php');

// Dynamic Sidebars
include (TEMPLATEPATH . '/inc/sidebars-dynamic.php');
include (TEMPLATEPATH . '/inc/sidebars-default.php');

// Custom-Header
/* include (TEMPLATEPATH . '/inc/custom-header.php'); */

// Widgets
include (TEMPLATEPATH . '/inc/widgets/gplus-box.php');
include (TEMPLATEPATH . '/inc/widgets/newsinpics-box.php');
include (TEMPLATEPATH . '/inc/widgets/tabs-box.php');
include (TEMPLATEPATH . '/inc/widgets/modern-posts-box.php');
include (TEMPLATEPATH . '/inc/widgets/login-box.php');
include (TEMPLATEPATH . '/inc/widgets/search-box.php');
include (TEMPLATEPATH . '/inc/widgets/video-box.php');
include (TEMPLATEPATH . '/inc/widgets/soundcloud-box.php');
include (TEMPLATEPATH . '/inc/widgets/googlemap-box.php');
include (TEMPLATEPATH . '/inc/widgets/social-counter.php');
include (TEMPLATEPATH . '/inc/widgets/social-icons-box.php');
include (TEMPLATEPATH . '/inc/widgets/adv-box.php');
include (TEMPLATEPATH . '/inc/widgets/tags-cats-box.php');
include (TEMPLATEPATH . '/inc/widgets/fb-box.php');
include (TEMPLATEPATH . '/inc/widgets/widget-functions.php');

//// Home Page Categories
include (TEMPLATEPATH . '/inc/header-func.php');
include (TEMPLATEPATH . '/inc/home-cats.php');
include (TEMPLATEPATH . '/inc/reviews.php');
//
// Backend File
include (TEMPLATEPATH . '/admin/backend/post-options.php');
include (TEMPLATEPATH . '/admin/backend/postoptions-fun.php');

// Post File
include (TEMPLATEPATH . '/inc/post-banner.php');
include (TEMPLATEPATH . '/inc/social-sharing.php');

// Post Views
include (TEMPLATEPATH . '/inc/post-views.php');

include (TEMPLATEPATH . '/inc/breadcrumb.php');
include (TEMPLATEPATH . '/inc/post-func.php');
include (TEMPLATEPATH . '/inc/wp_bootstrap_navwalker.php');

include (TEMPLATEPATH . '/inc/scripts.php');

// Google Fonts
include (get_template_directory() . '/inc/google-fonts.php');
include (get_template_directory() . '/inc/styling-theme.php');

/* Twitter API */
include (get_template_directory() . '/inc/twitter-ticker/twitteroauth.php');
include (get_template_directory() . '/inc/twitter-ticker/twitter-ticker.php');

/* Include the TGM_Plugin_Activation class. */
require_once get_template_directory() . '/inc/class-tgm-plugin-activation.php';
include (get_template_directory() . '/inc/class-tgm-plugin-including.php');

// Return Control Value from Option Panel
function serpentsoft_get_data( $id ){
    global $srpnt_data;
    if ( !empty($srpnt_data[$id]) ) { return $srpnt_data[$id]; }
    
    return false;
}

/* Check for New Theme Updates */
if( serpentsoft_get_data('serpentsoft_switch_updateTheme') ){
    
$serpentsoft_tf_username = serpentsoft_get_data('serpentsoft_tf_username');
$serpentsoft_tf_api_key = serpentsoft_get_data('serpentsoft_tf_api_key');

if ($serpentsoft_tf_username && $serpentsoft_tf_api_key) {

function add_update_menu() {
    add_theme_page(theme_name . ' Update', theme_name . ' Updates', 'manage_options', 'updating', 'theadminpage');
}
add_action('admin_menu', 'add_update_menu'); 

function theadminpage() {
    global $serpentsoft_tf_username, $serpentsoft_tf_api_key;

    include_once( get_template_directory() .'/framework/envato-wordpress-toolkit-library/class-envato-wordpress-theme-upgrader.php' );
    $upgrader = new Envato_WordPress_Theme_Upgrader( $serpentsoft_tf_username, $serpentsoft_tf_api_key );

    if (isset($_POST['upgradingthemever'])) {
        $upgrader->upgrade_theme();
    }
    $currver = $upgrader->check_for_theme_update(); ?>
    	
    <style>.updatenotice { margin-top: 20px;}</style>
    
    <?php if ($currver->updated_themes_count) { ?>
        <div class="updatenotice">New Update Available</div>
        <div>
        <form method="post">
            <input type="submit" name="upgradingthemever" value="Update Now" />
        </form>
        </div>
        <?php }else{ ?>
        <div class="updatenotice">Congratulations, you are up to date :)</div>

<?php } } } }

//Check Wordpress version >= 3.5
if ( ! function_exists( 'is_version' ) ) {
    function is_version( $version = '3.5' ) {
        global $wp_version;
        if ( version_compare( $wp_version, $version, '>=' ) ) { return false; }
        
        return true;
    }
}

// Add Color Picker Scripts
function serpentsoft_widgets_enqueue_color_picker(){
    // Color Picker Style
    if ( !wp_style_is( 'wp-color-picker', 'registered' ) ) { wp_register_style( 'wp-color-picker', get_template_directory_uri() . '/admin/assets/css/color-picker.min.css' ); }
    wp_enqueue_style( 'wp-color-picker' );
    
    // Color Picker
    // // Enqueue colorpicker scripts for versions below 3.5 for compatibility
    if ( !wp_script_is( 'wp-color-picker', 'registered' ) ) {
        wp_register_script( 'iris', get_template_directory_uri() . '/admin/assets/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), false, 1 );
        wp_register_script( 'wp-color-picker', get_template_directory_uri() . '/admin/assets/js/color-picker.min.js', array( 'jquery', 'iris' ) );
    }
    wp_enqueue_script( 'wp-color-picker' );
}
//add_action( 'admin_print_scripts-widgets.php', 'serpentsoft_widgets_enqueue_color_picker' );


/**
 * Sets up theme defaults and registers the various WordPress features that
 * Adams News supports.
 *
 * @uses load_theme_textdomain() For translation/localization support.
 * @uses add_editor_style() To add a Visual Editor styleshee.
 * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
 * 	custom background, and post formats.
 * @uses register_nav_menu() To add support for navigation menus.
 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
 *
 * @since Adams News 1.0
 */
function serpentsoft_setup() {
    
    if ( function_exists( 'add_image_size' ) ){
        add_image_size( 'serpentsoft_704', 704, 390, true );
        add_image_size( 'serpentsoft_343', 343, 220, true );
        
        add_image_size( 'serpentsoft_604', 604, 345, true );
        add_image_size( 'serpentsoft_310', 310, 200, true );
        add_image_size( 'serpentsoft_100', 100, 100, true );
    }
    
    /*
     * Makes Adams Magazine available for translation.
     *
     * Translations can be added to the /languages/ directory.
     * If you're building a theme based on Adams Magazine, use a find and replace
     * to change 'serpentsoft' to the name of your theme in all the template files.
     */
    load_theme_textdomain( 'serpentsoft', get_template_directory() . '/languages' );

    // This theme styles the visual editor with editor-style.css to match the theme style.
    add_editor_style();

    // Adds RSS feed links to <head> for posts and comments.
    add_theme_support( 'automatic-feed-links' );

    /*
     * This theme supports custom background color and image, and here
     * we also set up the default background color.
     */
    /* add_theme_support( 'custom-background', array( 'default-color' => 'e6e6e6', ) ); */

    //add_theme_support( 'custom-background', array( 'default-color' => 'ffffff' ) );

    // This theme uses a custom image size for featured images, displayed on "standard" posts.
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 604, 9999 ); // Unlimited height, soft crop

    register_nav_menus( array( 'topnav' => __( 'Top Navigation', 'serpentsoft' ), ) );
    register_nav_menus( array( 'mainnav' => __( 'Main Navigation', 'serpentsoft' ), ) );
    
    /* Support WooCommerce */
    /* add_theme_support( 'woocommerce' ); */
}
add_action( 'after_setup_theme', 'serpentsoft_setup' );

/**
* Enqueues scripts and styles for front-end.
*
* @since Adams News 1.0
*/
function serpentsoft_scripts_styles() {
    global $wp_styles;

    /*
     * Adds JavaScript to pages with the comment form to support
     * sites with threaded comments (when in use).
     */
    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
        wp_enqueue_script( 'comment-reply' );

    /*
     * Adds JavaScript for handling the navigation menu hide-and-show behavior.
     */
    wp_enqueue_script( 'serpentsoft-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true );

}
add_action( 'wp_enqueue_scripts', 'serpentsoft_scripts_styles' );

/**
* Creates a nicely formatted and more specific title element text
* for output in head of document, based on current view.
*
* @since Adams News 1.0
*
* @param string $title Default title text for current view.
* @param string $sep Optional separator.
* @return string Filtered title.
*/
function serpentsoft_wp_title( $title, $sep ) {
    global $paged, $page;

    if ( is_feed() ){
            return $title;
    }
    
    // Add the site name.
    $title .= get_bloginfo( 'name' );

    // Add the site description for the home/front page.
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) ){
            $title = "$title $sep $site_description";
    }
    
    // Add a page number if necessary.
    if ( $paged >= 2 || $page >= 2 ){
            $title = "$title $sep " . sprintf( __( 'Page %s', 'serpentsoft' ), max( $paged, $page ) );
    }
    
    return $title;
}
add_filter( 'wp_title', 'serpentsoft_wp_title', 10, 2 );

/**
* Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link.
*
* @since Adams News 1.0
*/
function serpentsoft_page_menu_args( $args ) {
    if ( ! isset( $args['show_home'] ) )
        $args['show_home'] = true;
    return $args;
}
add_filter( 'wp_page_menu_args', 'serpentsoft_page_menu_args' );


if ( ! function_exists( 'serpentsoft_content_nav' ) ) :
/**
* Displays navigation to next/previous pages when applicable.
*
* @since Adams News 1.0
*/
function serpentsoft_content_nav( $html_id ) {
    global $wp_query;

    $html_id = esc_attr( $html_id );

    if ( $wp_query->max_num_pages > 1 ) : ?>
        <nav id="<?php echo $html_id; ?>" class="navigation" role="navigation">
            <h3 class="assistive-text"><?php _e( 'Post navigation', 'serpentsoft' ); ?></h3>
            <div class="nav-previous alignleft"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'serpentsoft' ) ); ?></div>
            <div class="nav-next alignright"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'serpentsoft' ) ); ?></div>
        </nav><!-- #<?php echo $html_id; ?> .navigation -->
<?php endif;
}
endif;

// ==========================================================
// Excerpt Settings
// ==========================================================
function serpentsoft_the_excerpt_max_charlength($charlength) {
    $excerpt = get_the_excerpt();
    $charlength++;

    if ( mb_strlen( $excerpt ) > $charlength ) {
        $subex = mb_substr( $excerpt, 0, $charlength - 5 );
        $exwords = explode( ' ', $subex );
        $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
        if ( $excut < 0 ) {
            echo mb_substr( $subex, 0, $excut );
        } else {
            echo $subex;
        }
        echo '...';
    } else {
        echo $excerpt;
    }
}

function serpentsoft_slider_GetTheExcerpt(){
    // Read from options panel
    if( serpentsoft_get_data('serpentsoft_slider_exerpt') ) { $length = serpentsoft_get_data('serpentsoft_slider_exerpt'); }
    else { $length = 300; }
    
    serpentsoft_the_excerpt_max_charlength($length);
}

function serpentsoft_global_GetTheExcerpt(){
    // Read from options panel
    if(serpentsoft_get_data('serpentsoft_archive_blog_exerpt')) { $length = serpentsoft_get_data('serpentsoft_archive_blog_exerpt'); }
    else { $length = 300; }
    serpentsoft_the_excerpt_max_charlength($length);
}

/**
* Change the WordPress default excerpt length
*/
function serpentsoft_cats_GetTheExcerpt(){
    // Read from options panel
    if(serpentsoft_get_data('serpentsoft_homepage_cats_exerpt')) { $length = serpentsoft_get_data('serpentsoft_homepage_cats_exerpt'); }
    else { $length = 200; }
    serpentsoft_the_excerpt_max_charlength($length);
}

// ==========================================================
// Comments Template
// ==========================================================
if ( ! function_exists( 'serpentsoft_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own serpentsoft_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* @since Adams News 1.0
*/
function serpentsoft_comment( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
            case 'pingback' :
            case 'trackback' :
            // Display trackbacks differently than normal comments. ?>

	<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
            <p><?php _e( 'Pingback:', 'serpentsoft' ); ?>
                <?php comment_author_link(); ?>
                <?php edit_comment_link( __( '(Edit)', 'serpentsoft' ), '<span class="edit-link">', '</span>' ); ?>
            </p>
	<?php break;

        default :
        // Proceed with normal comments.
        global $post; ?>
            
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
            <article id="comment-<?php comment_ID(); ?>" class="comment">
                    <header class="comment-meta comment-author vcard">
                        <?php echo get_avatar( $comment, 50 );
                            printf( '<cite class="fn" itemprop="creator">%1$s %2$s</cite>',
                                get_comment_author_link(),
                                // If current post author is also comment author, make it known visually.
                                ( $comment->user_id === $post->post_author ) ? '<span> - ' . __( 'Post author', 'serpentsoft' ) . '</span>' : ''
                            );
                            printf( '<a href="%1$s"><i class="bo-icon-time"></i><time itemprop="commentTime" datetime="%2$s">%3$s</time></a>',
                                esc_url( get_comment_link( $comment->comment_ID ) ),
                                get_comment_time( 'c' ),
                                /* translators: 1: date, 2: time */
                                sprintf( __( '%1$s at %2$s', 'serpentsoft' ), get_comment_date(), get_comment_time() )
                            ); ?>
                    </header><!-- .comment-meta -->

                    <?php if ( '0' == $comment->comment_approved ) : ?>
                        <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'serpentsoft' ); ?></p>
                    <?php endif; ?>

                    <section class="comment-content comment">
                        <p itemprop="commentText"><?php echo get_comment_text(); ?></p>
                        <?php edit_comment_link( __( 'Edit', 'serpentsoft' ), '<p class="edit-link">', '</p>' ); ?>
                    </section><!-- .comment-content -->

                    <div class="reply btn-theme">
                        <?php comment_reply_link( array_merge( $args, array('before' => '<i class="bo-icon-comment bo-icon-white"></i>', 'reply_text' => __( 'Reply', 'serpentsoft' ), 'after' => '', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>

                        <meta itemprop="replyToUrl" content="<?php echo get_comment_reply_link(); ?>" />
                    </div><!-- .reply -->
            </article><!-- #comment-## -->
	
        <?php break;
	endswitch; // end comment_type check
}
endif;


// ===========================================
// Wordpress & Facebook Comments Box
// ===========================================
function serpentsoft_comments_box(){
    if( !is_single() ){
        if( is_page() ){
            if( serpentsoft_get_data('serpentsoft_switch_wp_comments_box') && serpentsoft_get_data('serpentsoft_switch_wp_comments_box_page') ){
                if (comments_open()): comments_template('', true); endif;
            }
        }
        else{
            if (comments_open()): comments_template('', true); endif;
        }
    }
    
    if( serpentsoft_get_data('serpentsoft_switch_fb_comments_box') ){
        if( is_page() && serpentsoft_get_data('serpentsoft_switch_fb_comments_box_page') ){ ?>

        <section class="comments-box w-comments" itemprop="comment" itemscope="" itemtype="http://schema.org/UserComments">
            <div class="cat-widget">
                <div class="cat-widget-title">
                    <h3>
                    <?php if( serpentsoft_get_data('serpentsoft_switch_fb_show_comments_number') ) { ?>
                        <fb:comments-count href="<?php the_permalink(); ?>"></fb:comments-count><?php echo ' ' . serpentsoft_get_data('serpentsoft_fb_comments_text'); ?>
                    <?php } else { echo serpentsoft_get_data('serpentsoft_fb_comments_text'); } ?>
                    </h3>
                </div>

                <div class="cat-widget-content"><div class="row-fluid comments"><?php serpentsoft_fb_comment_box( serpentsoft_get_data('serpentsoft_slider_fb_comments_number') ); ?></div></div>
            </div>
        </section>

    <?php } else{ ?>
        <section class="comments-box w-comments" itemprop="comment" itemscope="" itemtype="http://schema.org/UserComments">
            <div class="cat-widget">
                <div class="cat-widget-title">
                    <h3>
                    <?php if( serpentsoft_get_data('serpentsoft_switch_fb_show_comments_number') ) { ?>
                        <fb:comments-count href="<?php the_permalink(); ?>"></fb:comments-count><?php echo ' ' . serpentsoft_get_data('serpentsoft_fb_comments_text'); ?>
                    <?php } else { echo serpentsoft_get_data('serpentsoft_fb_comments_text'); } ?>
                    </h3>
                </div>

                <div class="cat-widget-content">
                    <div class="row-fluid comments"><?php serpentsoft_fb_comment_box( serpentsoft_get_data('serpentsoft_slider_fb_comments_number') ); ?></div>
                </div>
            </div>
        </section>
    <?php } } }


// ==========================================================
// Menu
// ==========================================================

// if doesn't exist
function serpentsoft_nav_default(){
    echo '<div class="menu-default">'.__( 'You can use WordPress menu builder ( Appearance > Menus ) to build this menu' , 'serpentsoft' ).'</div>';
}

// Mobile Menu
function serpentsoft_mobile_menu( $args = array() ) {			
    $output = '';

    @extract($args);						

    if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {	
        $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );						
        $menu_items = wp_get_nav_menu_items( $menu->term_id );				
        $output = "<select id='". $id. "' class='". $class. "'>";
        $output .= "<option value='' selected='selected'>" . __('Go to...', 'serpentsoft') . "</option>";
        foreach ( (array) $menu_items as $key => $menu_item ) {
            $title = $menu_item->title;
            $url = $menu_item->url;

            if($title === 'srp-icon') { $title = 'Icon Item'; }
            
            if ( $menu_item->menu_item_parent ) {
                $title = ' - ' . $title;
            }
            
            $output .= "<option value='" . $url . "'>" . $title . '</option>';
        }
        $output .= '</select>';
    }
    return $output;							
}

// ==========================================================
// Bootstrap Pagination
// ==========================================================
if( !function_exists('serpentsoft_bootstrap_pagination') ):

function serpentsoft_bootstrap_pagination($pages = '', $range = 2)
{
$showitems = ($range * 2) + 1;

global $paged;
    if(empty($paged)){ $paged = 1; }

    if($pages == ''){
        global $wp_query;
        $pages = $wp_query->max_num_pages;

        if(!$pages) { $pages = 1; }
    }

    if(1 != $pages){
        echo "<div class='pagination pagination-centered'><ul>";
        if($paged > 2 && $paged > $range + 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."'>&laquo;</a></li>";
        if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a></li>";

        for ($i=1; $i <= $pages; $i++)
        {
            if (1 != $pages &&( !($i >= $paged + $range + 1 || $i <= $paged - $range - 1) || $pages <= $showitems )) {
                echo ($paged == $i) ? "<li class='active'><span class='current'>".$i."</span></li>" : "<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>";
            }
        }

        if ($paged < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a></li>";
        if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."'>&raquo;</a></li>";
        echo "</ul></div>\n";
    }
	
}
endif;

// ==========================================================
// Get Date and Time Formats
// ==========================================================
if( !function_exists('serpentsoft_getDateTimeFormat') ):

function serpentsoft_getDateTimeFormat($var = 'dt'){
    $date_format = 'j F Y, g:i A';

    switch($var){
        // Date and Time
        case 'dt':{
            if( serpentsoft_get_data('serpentsoft_dateTime_format') ):
                $date_format = serpentsoft_get_data('serpentsoft_dateTime_format');
            else:
                $date_format = 'j F Y, g:i A';
            endif;
        }
        break;

        // Date Only
        case 'd':{
            if( serpentsoft_get_data('serpentsoft_date_format') ):
                $date_format = serpentsoft_get_data('serpentsoft_date_format');
            else:
                $date_format = 'j F Y';
            endif;
        }
        break;

        // Time Only
        case 't':{
            if( serpentsoft_get_data('serpentsoft_time_format') ):
                $date_format = serpentsoft_get_data('serpentsoft_time_format');
            else:
                $date_format = 'g:i A';
            endif;
        }
        break;
    }

    return $date_format;
}
endif;


/**
 * Extends the default WordPress body class to denote:
 * 1. Using a full-width layout, when no active widgets in the sidebar
 *    or full-width template.
 * 2. Front Page template: thumbnail in use and number of sidebars for
 *    widget areas.
 * 3. White or empty background color to change the layout and spacing.
 * 4. Custom fonts enabled.
 * 5. Single or multiple authors.
 *
 * @since Adams News 1.0
 *
 * @param array Existing class values.
 * @return array Filtered class values.
 */
function serpentsoft_body_class( $classes ) {
    $background_color = get_background_color();

    /*if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) )
        $classes[] = 'full-width';

    if ( is_page_template( 'page-templates/front-page.php' ) ) {
        $classes[] = 'template-front-page';
        if ( has_post_thumbnail() )
            $classes[] = 'has-post-thumbnail';
        if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) )
            $classes[] = 'two-sidebars';
    } */

    if ( empty( $background_color ) ){
        $classes[] = 'custom-background-empty';
    }
    elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ){
        $classes[] = 'custom-background-white';
    }
    
    // Enable custom font class only if the font CSS is queued to load.
    if ( wp_style_is( 'srpnt_opensans', 'queue' ) )
        $classes[] = 'custom-font-enabled';

    if ( ! is_multi_author() )
        $classes[] = 'single-author';

    return $classes;
}
add_filter( 'body_class', 'serpentsoft_body_class' );

/**
 * Adjusts content_width value for full-width and single image attachment
 * templates, and when there are no active widgets in the sidebar.
 *
 * @since Adams News 1.0
 */
/*function serpentsoft_content_width() {
    if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) {
        global $content_width;
        $content_width = 1240;
    }
}
add_action( 'template_redirect', 'serpentsoft_content_width' );*/

/**
* Add postMessage support for site title and description for the Theme Customizer.
*
* @since Adams News 1.0
*
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
* @return void
*/
function serpentsoft_customize_register( $wp_customize ) {
    $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
    $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
}

add_action( 'customize_register', 'serpentsoft_customize_register' );

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 *
 * @since Adams News 1.0
 */
add_action( 'customize_preview_init', 'serpentsoft_customize_preview_js' );
function serpentsoft_customize_preview_js() {
    wp_enqueue_script( 'serpentsoft-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20120827', true );
}

// ========= Methods =============
// Page Builder Output
function serpentsoft_build_homepage(){
    global $home_page_items_count;
    
    // Collect variables array from 'class.options_machine.php'/'optionsframework_builder_function'
    $arr_layout = serpentsoft_get_data('serpentsoft_builder');

    // Use variables
    if($arr_layout):

    foreach ($arr_layout as $option){
        $style = $option['catstyle'];
        $cat_id = $option['catid'];
        $cat_title = $option['title'];
        $cat_color = $option['color'];
        $cat_posts_num = $option['postsnum'];
        if( !is_numeric($cat_posts_num) || $cat_posts_num < 0 ) { $cat_posts_num = 6; }
        
        $cat_id_2 = $option['catid2'];
        $cat_title_2 = $option['title2'];
        $cat_color_2 = $option['color2'];
        $cat_posts_num_2 = $option['postsnum2'];
        if( !is_numeric($cat_posts_num_2) || $cat_posts_num_2 < 0 ) { $cat_posts_num_2 = 6; }
        
        //$adv_title = $option['advtitle'];
        $adv_code = $option['advcode'];
        
        $block_order = 'block-' . $option['order'];
        $block_order_ver1 = $block_order."_1";
        $block_order_ver2 = $block_order."_2";

        switch ($style){
            case 'horiz':{
                serpentsoft_horiz_cat($block_order, $cat_id, $cat_title, $cat_color, $cat_posts_num);
                $home_page_items_count++;
            }
            break;

            case 'vert':{
                serpentsoft_vertical_cat($block_order_ver1, $cat_id, $cat_title, $cat_color, $cat_posts_num, 
                    $block_order_ver2, $cat_id_2, $cat_title_2, $cat_color_2, $cat_posts_num_2);
                $home_page_items_count++;
            }
            break;

            case 'classic':{
                serpentsoft_horizDivided_cat($block_order, $cat_id, $cat_title, $cat_color, $cat_posts_num);
                $home_page_items_count++;
            }
            break;

            case 'rev':{
                serpentsoft_reviews_cat($block_order, $cat_id, $cat_title, $cat_color, $cat_posts_num);
                $home_page_items_count++;
            }
            break;
            
            case 'adv':{
                serpentsoft_advertisement_cat($block_order, $cat_title, $adv_code);
                $home_page_items_count++;
            }
            break;
        }
    }

    endif;
}

//Hex to RGB
function hex2rgb($hex, $alpha = '') {
    $hex = str_replace("#", "", $hex);

    if(strlen($hex) == 3) {
        $r = hexdec(substr($hex,0,1).substr($hex,0,1));
        $g = hexdec(substr($hex,1,1).substr($hex,1,1));
        $b = hexdec(substr($hex,2,1).substr($hex,2,1));
    } else {
        $r = hexdec(substr($hex,0,2));
        $g = hexdec(substr($hex,2,2));
        $b = hexdec(substr($hex,4,2));
    }

    if($alpha == '')
    {
        $rgb = array($r, $g, $b);
        return $rgb; // returns an array with the rgb values
    }
    else
    {
        $rgba = array($r, $g, $b, $alpha);
        return $rgba; // returns an array with the rgb values
    }	
    //return implode(",", $rgb); // returns the rgb values separated by commas
}


function serpentsoft_get_cat_title($id, $user_text = ''){
    if(!empty($user_text)){
        return $user_text;
    } else {
        return get_cat_name($id);
    }
}


// Add Social Networks to Author Options Panel
function serpentsoft_author_social_networks( $socialNetwork ) {
    $socialNetwork['facebook'] = __('Facebook', 'serpentsoft');
    $socialNetwork['twitter'] = __('Twitter', 'serpentsoft');
    $socialNetwork['gplus'] = __('Google Plus', 'serpentsoft');
    $socialNetwork['pinterest'] = __('Pinterest', 'serpentsoft');
    $socialNetwork['youtube'] = __('Youtube', 'serpentsoft');
    $socialNetwork['linkedin'] = __('Linkedin', 'serpentsoft');

    return $socialNetwork;
}
add_filter('user_contactmethods', 'serpentsoft_author_social_networks', 10, 1);


// ===========================================
// Set Default Avatar
// ===========================================
function serpentsoft_default_avatar($avatar_defaults) {
	$srpnt_avatar = serpentsoft_get_data('serpentsoft_upload_avatar');
	if($srpnt_avatar){
		$avatar_defaults[$srpnt_avatar] = "Default Avatar";
	}
	return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'serpentsoft_default_avatar' );

// ===========================================
// Get Image Thumb ( Return $img_url that represents an array of image properties (url ,width, height, is_original)  )
// ===========================================
function serpentsoft_get_thumb($img='', $width='', $height=''){
    global $post;

    if( isset($img) && !empty($img) ){
        return $img;
    }
    else{
        $image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array($width, $height) );
        return $image_url;
    }
}

// ========================================================
// Define og:image for Facebook and Google+ thumbs sharing
// ========================================================
function serpentsoft_og_image() {
    global $post;
    $img_thumb = '';
    
    if (function_exists("has_post_thumbnail") && has_post_thumbnail($post->ID)){
        $arr_img_thumb = serpentsoft_get_thumb('', 604, 345);
        $img_thumb = $arr_img_thumb[0];
    }
    else{
        $get_meta = get_post_custom($post->ID);
        
        if( !isset($get_meta['serpentsoft_post_format']) ) { return; }

        $postTypeControl = $get_meta['serpentsoft_post_format'][0];

        if($postTypeControl == 'video'):
            $videoProviderControl = $get_meta['serpentsoft_video_provider'][0];
            $videoCode = get_post_meta($post->ID, 'serpentsoft_video_url_code', true);

            switch ($videoProviderControl) {
                case 'youtube':
                case 'youtu':
                        $img_thumb = 'http://img.youtube.com/vi/' . $videoCode . '/0.jpg';
                    break;

                case 'vimeo':
                        /* $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/" . $videoCode . ".php"));
                        $img_thumb = $hash[0]['thumbnail_large']; */
                        $hash = wp_remote_get("http://vimeo.com/api/v2/video/" . $videoCode . ".php");
                        $thumb = unserialize($hash['body']);
                        $img_thumb = $thumb['0']['thumbnail_large'];
                    break;

                case 'dailymotion':
                        // Return (320 x 240) px
                        $img_thumb = 'http://www.dailymotion.com/thumbnail/video/' . $videoCode;
                    break;

                default:
                    break;
            }
        endif;
    }
    
    if( isset($img_thumb) && !empty($img_thumb) ){
        echo '<meta property="og:image" content="' . $img_thumb . '" />';
    }
}


// ========================================================
// Define fb:app_id , og:title , og:url , og:site_name , og:description
// ========================================================
function serpentsoft_facebook_opengraph_advanced() {
   $output = '';
    
    if( serpentsoft_get_data('serpentsoft_switch_social_facebook_sdk') ){
        $appID = serpentsoft_get_data('serpentsoft_switch_social_facebook_sdk_appid');
        if( !empty($appID) ){ $output .= '<meta property="fb:app_id" content="' . $appID . '" />'; }
    }
    
    $site_title = get_bloginfo('name');
    
    $current_post = get_post();
    
    $post_title = $current_post->post_title;
    $post_link = get_permalink();
    
    $description = wp_trim_words($current_post->post_content, 20);

    if( !empty($post_title) ){
        $output .= '<meta property="og:title" content="' . $post_title . '">';
        $output .= '<meta property="og:site_name" content="' . $site_title . '">';
        $output .= '<meta property="og:type" content="article">';
    }

    if( !empty($post_link) ){
        $output .= '<link rel="canonical" href="' . $post_link . '">';
        $output .= '<meta property="og:url" content="' . $post_link . '">';
    }

    if( !empty($description) ){
        $output .= '<meta name="description" content="' . $description . '">';
        $output .= '<meta property="og:description" content="' . $description . '">';
    }

    if( !empty($output) ) { echo $output; }
}
/* ob_clean(); ob_end_clean(); */ ?>