<?php /**
* Functions template used by LovelyAnimals.
*
* Authors: wpart
* Copyright: 2012
* {@link http://wpart.org/}
*
* Released under the terms of the GNU General Public License.
* You should have received a copy of the GNU General Public License,
* along with this software. In the main directory, see: /licensing/
* If not, see: {@link http://www.gnu.org/licenses/}.
*
* @package LovelyAnimals.
* @since 1.13
*/


function LovelyAnimals_register_sidebar() {    
	register_sidebar(array(
	    'id' => 'sidebar',
		'name' =>  'sidebar',
		'before_widget' => '<li id="%1$s" class="side widget %2$s">', 
		'after_widget' => '</li>',
		'before_title' => '<h3 class="title3">', 
		'after_title' => '</h3>' 
	));
 
}

add_action( 'widgets_init', 'LovelyAnimals_register_sidebar');

/*
 * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
*/
function LovelyAnimals_setup() {
		// Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.

	// This theme uses post thumbnails
	add_theme_support( 'post-thumbnails' ); 
	
	set_post_thumbnail_size( 116, 86, true );
	

	// Add default posts and comments RSS feed links to head
	add_theme_support( 'automatic-feed-links' );
	
	add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) );
	
		register_nav_menus( array(
		'primary' =>'Primary Menu',
	) );		
}
add_action( 'after_setup_theme', 'LovelyAnimals_setup' );

if ( ! isset( $content_width ) )
	$content_width = 665;


function LovelyAnimals_hotfriends(){
    global $wpdb;
    $counts = $wpdb->get_results("SELECT COUNT(comment_author) AS cnt, comment_author, comment_author_url, comment_author_email
    FROM {$wpdb->prefix}comments
    WHERE comment_date > date_sub( NOW(), INTERVAL 1 MONTH )
    AND comment_approved = '1'
    AND comment_author_email != 'example@example.com'
    AND comment_author_url != ''
    AND comment_type = ''
    AND user_id = '0'
    GROUP BY comment_author_email
    ORDER BY cnt DESC
    LIMIT 15");

    $mostactive = '';
    if ( $counts ) {
    foreach ($counts as $count) {
    $c_url = $count->comment_author_url;
    $mostactive .= '<li>'.'<a href="'.$count->comment_author_url.'">' . get_avatar($count->comment_author_email, 55, '', $count->comment_author . ' reply on ' . $count->cnt . '') . '</br>'.$count->comment_author.'</a></li>';
    }
    echo $mostactive;
    }
	
}
function LovelyAnimals_excerpt_more($more) {
       global $post;
	return '<br /><a class="more" href="'. get_permalink($post->ID) . '">Read the Rest...</a>';
}
add_filter('excerpt_more', 'LovelyAnimals_excerpt_more');

function LovelyAnimals_scripts(){
	if ( is_singular() && get_option( 'thread_comments' ) )
		wp_enqueue_script( 'comment-reply' );
  }
  add_action( 'wp_enqueue_scripts', 'LovelyAnimals_scripts' );
// filter function for wp_title
function LovelyAnimals_filter_wp_title( $old_title, $sep, $sep_location ){
 
// add padding to the sep
$ssep = ' ' . $sep . ' ';
 
// find the type of index page this is
if( is_category() ) $insert = $ssep . 'Category';
elseif( is_tag() ) $insert = $ssep . 'Tag';
elseif( is_author() ) $insert = $ssep . 'Author';
elseif( is_year() || is_month() || is_day() ) $insert = $ssep . 'Archives';
else $insert = NULL;
 
// get the page number we're on (index)
if( get_query_var( 'paged' ) )
$num = $ssep . 'page ' . get_query_var( 'paged' );
 
// get the page number we're on (multipage post)
elseif( get_query_var( 'page' ) )
$num = $ssep . 'page ' . get_query_var( 'page' );
 
// else
else $num = NULL;
 
// concoct and return new title
return  $insert . $old_title . $num  ;
}
add_filter( 'wp_title', 'LovelyAnimals_filter_wp_title', 10, 3 );
function LovelyAnimals_comment_reply_script() {
	if ( comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'comment_form_before', 'LovelyAnimals_comment_reply_script' );

?>
