Source

elbee-elgee / includes / functions / hooks.php

<?php
/**
 * Elbee Elgee Theme Hooks
 *
 * @package 		Elbee-Elgee
 * @copyright	Copyright (c) 2011, Doug Stewart
 * @license		http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, v2 (or newer)
 *
 * @since 		Elbee-Elgee 1.0
 */

/**
*  Action hooks
*/
function lblg_set_themename(){
	do_action( 'lblg_set_themename' );
}

function lblg_before_container(){
	do_action( 'lblg_before_container' );
}

function lblg_container_top(){
	do_action( 'lblg_container_top' );
}

function lblg_after_admin_header(){
	do_action( 'lblg_after_admin_header' );
}

function lblg_before_loop(){
	do_action( 'lblg_before_loop' );
}

function lblg_after_loop(){
	do_action( 'lblg_after_loop' );
}

function lblg_print_title(){
	do_action( 'lblg_print_title' );
}

function lblg_print_menu(){
	do_action( 'lblg_print_menu' );
}

function lblg_print_bp_menu(){
	do_action( 'lblg_print_bp_menu' );
}

function lblg_above_content_and_sidebars(){
	do_action( 'lblg_above_content_and_sidebars' );
}

function lblg_above_content(){
	do_action( 'lblg_above_content' );
}

function lblg_before_post_title(){
	do_action( 'lblg_before_post_title' );
}

function lblg_the_title(){
	do_action( 'lblg_the_title' );
}

function lblg_after_post_title(){
	do_action( 'lblg_after_post_title' );
}

function lblg_before_itemtext(){
	do_action( 'lblg_before_itemtext' );
}

function lblg_after_itemtext(){
	do_action( 'lblg_after_itemtext' );
}

function lblg_sidebar_header(){
	do_action( 'lblg_sidebar_header' );
}

function lblg_sidebar_footer(){
	do_action( 'lblg_sidebar_footer' );
}

function lblg_meta_info(){
	do_action( 'lblg_meta_info' );
}

function lblg_print_copyright(){
	do_action( 'lblg_print_copyright' );
}

function lblg_print_credits(){
	do_action( 'lblg_print_credits' );
}

function lblg_print_options(){
	do_action( 'lblg_print_options' );
}

function lblg_enqueue_styles(){
	do_action( 'lblg_enqueue_styles' );
}
add_action( 'wp_enqueue_scripts', 'lblg_enqueue_styles', 11 );

function lblg_nav_top() {
	do_action( 'lblg_nav_top' );
}

function lblg_nav_bottom() {
	do_action( 'lblg_nav_bottom' );
}
/**
* Output functions.
*
* These functions do useful things, like print the menu, the blog title, featured images, etc.
*
*/
// Output the blog title. Hook-able via lblg_print_title() action hook.
function lblg_title(){
	if(is_home()) { ?>
	<h1><span id="blogtitle"><a href="<?php echo home_url(); ?>"><?php echo get_bloginfo( 'name' ); ?></a></span></h1>
<?php
	} else { ?>
		<p class="blogtitle"><span id="blogtitle"><a href="<?php echo home_url(); ?>"><?php echo get_bloginfo( 'name' ); ?></a></span></p>
	<?php 
	}
}

// Output the primary menu. Hook-able via lblg_print_menu() action hook.
function lblg_menu(){
	if( function_exists( 'wp_nav_menu' ) ){
		wp_nav_menu( array( 'theme_location'	=> 'primary',  
							'container'			=> 'div',
							'container_id'		=> 'menu'
					) );
	} else {
	?>

	<?php
	}
}

// Output site breadcrumbs if Yoast's Breadcrumbs are available.
function lblg_breadcrumbs(){
	if ( function_exists('yoast_breadcrumb') && !is_home() ) {
		yoast_breadcrumb('<p id="breadcrumbs">','</p>');
	}
}
add_action( 'lblg_before_loop', 'lblg_breadcrumbs' );

// Output navigation info at the top of the Loop.
function lblg_topnav() {
	if ( is_attachment() ) { ?>

	<div class="navigation">
		<div class="left"><?php previous_image_link( 0 ) ?></div>
		<div class="right"><?php next_image_link( 0 ) ?></div>
		<div class="clear"></div>
	</div>		

	<?php 
	} elseif ( is_single() ) { ?>

	<div class="navigation">
		<div class="left"><?php previous_post_link() ?></div>
		<div class="right"><?php next_post_link() ?></div>
		<div class="clear"></div>
	</div>
	
	<?php 
	}
}
add_action( 'lblg_nav_top', 'lblg_topnav' );

function lblg_bottomnav() { ?>
	<div class="navigation">
			<?php if(function_exists('wp_pagenavi')) {
 					wp_pagenavi(); 
				} else { ?>
		<div class="left"><?php next_posts_link('<span>&laquo;</span> Older Entries') ?></div>
		<div class="right"><?php previous_posts_link('Newer Entries <span>&raquo;</span>') ?></div>
		<div class="clear"></div>
			<?php } ?>
	</div>
	<?php 
}
add_action( 'lblg_nav_bottom', 'lblg_bottomnav' );

function lblg_post_info(){
		?>
		<div class="postinfo">
			<span class="icon-calendar"></span><span class="postmeta">Posted by <?php the_author(); ?> on <a href="<?php the_permalink(); ?>"><?php the_time('F jS, Y'); ?></a> <?php if (!is_single() && !is_page() ){ ?>| <span class="commentlink"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span><span class="icon-comments"></span><?php } edit_post_link(' Edit this entry.', '', '<span class="icon-edit"></span>'); ?></span>
			<?php if( !is_page() ) { ?>
			<span class="icon-folder-close"></span><span class="postcats">Posted in <?php the_category(', '); ?></span>
			<?php } ?>
			<?php if( is_single() ){?>
			<span class="icon-tag"></span><span class="posttags"><?php the_tags('Tagged as: ',','); ?></span>
		<?php }?>
		</div>	
		<?php
}
add_action( 'lblg_after_itemtext', 'lblg_post_info' );

/**
 * Determine which stylesheets and layouts are to be applied and then add them to the
 * <head> via Core methods.
 */
function lblg_styles(){
	global $lblg_shortname, $lblg_options;
	$layout_handle = $lblg_shortname . '_layout_stylesheet';
	$alt_style_handle = $lblg_shortname . '_alt_stylesheet';
	$print_handle = $lblg_shortname . '_print_stylesheet';
	$normalize_handle = $lblg_shortname . '_normalize_stylesheet';
	
	$layout_style_option = $lblg_options['layout_stylesheet'];
	$alt_style_option = $lblg_options['alt_stylesheet'];
	
	switch($layout_style_option){
		case '':
		case 'Select a layout:':
			$layout = get_template_directory_uri() . '/layouts/css/2-columns-fixed-sb-right.css';
		break;
		case '*none*':
			unset($layout);
		break;
		default:
			$layout = get_template_directory_uri() . '/layouts/css/' . $layout_style_option;
		break;
	}
	
	switch($alt_style_option){
		case '':
		case 'Select a stylesheet:':
			$alt_style = get_template_directory_uri() .'/styles/ng.css';
		break;
		case '*none*':
			unset($alt_style);
		break;
		default:
			$alt_style = get_template_directory_uri() .'/styles/'. $alt_style_option;
		break;
	}
	
	if( isset($layout) ){ 
		//wp_enqueue_style( $layout_handle , $layout, '', '', 'screen' );
	}
	
	// if( isset($alt_style) ){
	// 		wp_enqueue_style( $alt_style_handle, $alt_style, '', '', 'screen' );
	// }
	
	wp_enqueue_style( 'lblg_normalize', get_template_directory_uri() . '/includes/css/normalize.css/normalize.css', '', '', 'screen' );
	wp_enqueue_style( $alt_style_handle, get_template_directory_uri() . '/styles/less/ng2.less', '', '', 'screen' );
	wp_enqueue_style( 'font_awesome', get_template_directory_uri() . '/includes/font-awesome/less/font-awesome.less', '', '', 'screen' );
	
	//wp_enqueue_style( $normalize_handle, get_template_directory_uri() . '/includes/css/normalize.css/normalize.css', '', '', 'screen' );
	wp_enqueue_style($print_handle,  get_template_directory_uri() . '/print.css', '', '', 'print' );
}
add_action( 'lblg_enqueue_styles', 'lblg_styles' );

/**
 * Spool up the LESS stylesheet handling.
 *
 * @param array $vars
 * @param string $handle
 * @return array 
 */
function lblg_less_vars( $vars, $handle ) {
	global $lblg_options;
	$vars['layout'] = $lblg_options['layout_stylesheet'];

	return apply_filters( 'lblg_less_vars', $vars );
}
add_filter( 'less_vars', 'lblg_less_vars', 10, 2 );

function lblg_credits(){
	global $lblg_shortname, $lblg_options;
	$tmp_credits = $lblg_options['footer_credit_text'];
	if($tmp_credits != ''){
		$credits_text = $tmp_credits;
	}else{
		$credits_text = 'Powered by <a href="http://wordpress.org\">WordPress</a> ' . get_bloginfo('version');
		$credits_text .= ' and <a href="http://literalbarrage.org/blog/code/elbee-elgee">Elbee Elgee</a>';
	}
	echo "<div id=\"credits-text\">$credits_text</div>";
}

/*
* Copyright code, courtesy of Chip Bennett
* http://wordpress.stackexchange.com/questions/14492/how-do-i-create-a-dynamically-updated-copyright-statement
*/
function lblg_copyright() {
    global $wpdb;
    $copyright_dates = $wpdb->get_results("
        SELECT
            YEAR(min(post_date_gmt)) AS firstdate,
            YEAR(max(post_date_gmt)) AS lastdate
        FROM
            $wpdb->posts
        WHERE
            post_status = 'publish'
    ");
    $output = '';
    if($copyright_dates) {
        $copyright = "&copy; " . $copyright_dates[0]->firstdate;
            if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
                $copyright .= '-' . $copyright_dates[0]->lastdate;
            }
        $output = $copyright;
    }
    return $output;
}

function lblg_echo_copyright() {
	global $lblg_shortname, $lblg_options;
	$tmp_copyright = $lblg_options['footer_copyright'];
	if( $tmp_copyright != '' ){
		$copyright_text = $tmp_copyright;
	} else {
		$copyright_text = "<a href=\"" . get_home_url() . "\">" . get_bloginfo('name') . "</a> " . lblg_copyright();
	}
	
	echo "<div id=\"copyright-text\">$copyright_text</div>";
}

// Output the Featured Image
function lblg_the_postimage() {
	if( has_post_thumbnail() ) {
		the_post_thumbnail( 'lb-content-header' );
	}
}
add_action( 'lblg_before_itemtext', 'lblg_the_postimage' );

/*
*  Utility hooks for use inside <head> and admin <head>,
*  via wp_head() and admin_head(). Just in case.
*/
function lblg_wp_head() { 
	global $lblg_themename, $lblg_shortname, $lblg_options;
}
add_action( 'wp_head', 'lblg_wp_head' );

function lblg_admin_head(){ 
	global $lblg_themename, $lblg_shortname, $lblg_options;
}
add_action( 'admin_head','lblg_admin_head' );

// Elbee Elgee action hooks
add_action( 'lblg_set_themename', 'lblg_themename' );
add_action( 'lblg_print_title', 'lblg_title' );
add_action( 'lblg_print_menu', 'lblg_menu' );
add_action( 'lblg_print_copyright', 'lblg_echo_copyright' );
add_action( 'lblg_print_credits', 'lblg_credits' );
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.