<?php 
/**
 * Theme Functions
 *
 * @package Outset
 * @since Outset 1.1
 */

// Loads the Options Panel found under the Appearance tab.
    define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/theme-options/' );
    require_once dirname( __FILE__ ) . '/theme-options/options-framework.php';
    require_once( get_template_directory() . '/theme-options/options-functions.php' );


// Registering scripts
  function outset_scripts() {
    wp_enqueue_script(
      'custom-script',
      get_stylesheet_directory_uri() . '/bootstrap/js/bootstrap.js',
      array( 'jquery' )
    );

    wp_enqueue_style(
      'outset-style',
      get_stylesheet_directory_uri() . '/style.css',
      array( 'outset-bootstrap', 'outset-bootstrap-theme' )
    );

    wp_enqueue_style( 
      'outset-bootstrap', 
      get_stylesheet_directory_uri() . '/css/bootstrap.css' 
    );
    
    wp_enqueue_style( 
      'outset-bootstrap-theme', 
      get_stylesheet_directory_uri() . '/css/bootstrap-responsive.css' 
    );

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




if ( ! function_exists( 'outset_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function outset_setup() {

  /*
   * Make theme available for translation.
   * Translations can be filed in the /languages/ directory.
   * If you're building a theme based on outset, use a find and replace
   * to change 'outset' to the name of your theme in all the template files
   */
  load_theme_textdomain( 'outset', get_template_directory() . '/languages' );

// Add Feed links
    add_theme_support( 'automatic-feed-links' );

// Add Featured image thumbnail beside post excerpts
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 180, 180, true );

// Register the Navigation Menu
register_nav_menus( array(
    'primary' => __( 'Primary Menu', 'outset' ),
  ) );
}
endif; // outset_setup
add_action( 'after_setup_theme', 'outset_setup' );




// Registers Sidebar
    if ( function_exists('register_sidebar') )
    	register_sidebar(array(
    		'before_widget' => '',
    		'after_widget' => '',
    		'before_title' => '<h3>',
    		'after_title' => '</h3>',
    	));



// Loads Navigation and Pagination
    require_once('pagination.php');
    require_once('wp_bootstrap_navwalker.php');



// Google Font Styles found in Options Panel > Typography
function ggl_load_styles() {
    if (!is_admin()) {
    wp_register_style('googleFont', '//fonts.googleapis.com/css?family=Open+Sans|Roboto|Oswald|Lato|PT+Sans|Source+Sans+Pro|Droid+Serif|Ubuntu|Lobster|Titillium+Web');
    wp_enqueue_style('ggl', get_stylesheet_uri(), array('googleFont') );
    }
    }
    add_action('wp_enqueue_scripts', 'ggl_load_styles');




// Changing excerpt [...] to Read more
   function new_excerpt_more($more) {
   global $post;
   return '&#8230; <a class="btn" href="'. get_permalink($post->ID) . '">' . 'Read More &raquo;' . '</a>';
   }
   add_filter('excerpt_more', 'new_excerpt_more');



// Content width
    if ( ! isset( $content_width ) ) $content_width = 1150;



// Commenting Function
    if ( ! function_exists( 'outset_comment' ) ) :
    /**
     * Template for comments and pingbacks. Taken from WordPress Twenty Ten 1.0
     */
    function outset_comment( $comment, $args, $depth ) {
      $GLOBALS['comment'] = $comment;
      switch ( $comment->comment_type ) :
        case '' :
      ?>
      <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
        <div id="comment-<?php comment_ID(); ?>">
          <div class="comment-author vcard">
            <?php echo get_avatar( $comment, 40 ); ?>
            <?php printf( __( '%s <span class="says">says:</span>', 'outset' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
          </div><!-- .comment-author .vcard -->
          <?php if ( $comment->comment_approved == '0' ) : ?>
            <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'outset' ); ?></em>
            <br />
          <?php endif; ?>

          <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
            <?php
              /* translators: 1: date, 2: time */
              printf( __( '%1$s at %2$s', 'outset' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'outset' ), ' ' );
            ?>
          </div><!-- .comment-meta .commentmetadata -->

          <div class="comment-body"><?php comment_text(); ?></div>

          <div class="reply">
            <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
          </div><!-- .reply -->
        </div><!-- #comment-##  -->

      <?php
          break;
        case 'pingback'  :
        case 'trackback' :
      ?>
      <li class="post pingback">
        <p><?php _e( 'Pingback:', 'outset' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'outset' ), ' ' ); ?></p>
      <?php
          break;
      endswitch;
    }
    endif;

    // Don't add the wp-includes/js/comment-reply.js?ver=20090102 script to single post pages unless threaded comments are enabled
    // adapted from http://bigredtin.com/behind-the-websites/including-wordpress-comment-reply-js/
    function theme_queue_js(){
      if (!is_admin()){
        if (is_singular() && (get_option('thread_comments') == 1) && comments_open() && have_comments())
          wp_enqueue_script('comment-reply');
      }
    }
    add_action('wp_print_scripts', 'theme_queue_js');

/**
 * Add breadcrumbs functionality to your WordPress theme
 */
function outset_breadcrumbs() {
  if(!is_home()) {
    echo '<nav class="breadcrumb">';
    if (is_category() || is_single()) {
      the_category(' <span class="divider"> &gt; </span> ');
      if (is_single()) {
        echo ' <span class="divider"> &gt; </span> ';
        the_title();
      }
    } elseif (is_page()) {
      echo the_title();
    }
    echo '</nav>';
  }
}


function outset_nav_menu_args( $args = '' )
{
    $args['container'] = false;
    return $args;
} // function
add_filter( 'wp_page_menu_args', 'outset_nav_menu_args' );




//Page and Post Title
add_filter( 'wp_title', 'filter_wp_title' );
/**
 * Filters the page title appropriately depending on the current page
 *
 * This function is attached to the 'wp_title' fiilter hook.
 *
 * @uses  get_bloginfo()
 * @uses  is_home()
 * @uses  is_front_page()
 */
function filter_wp_title( $title ) {
  global $page, $paged;

  if ( is_feed() )
    return $title;

  $site_description = get_bloginfo( 'description' );

  $filtered_title = $title . get_bloginfo( 'name' );
  $filtered_title .= ( ! empty( $site_description ) && ( is_home() || is_front_page() ) ) ? ' | ' . $site_description: '';
  $filtered_title .= ( 2 <= $paged || 2 <= $page ) ? ' | ' . sprintf( __( 'Page %s','outset' ), max( $paged, $page ) ) : '';

  return $filtered_title;
}
?>