<?php


/* 
 * Loads the Options Panel
 *
 * If you're loading from a child theme use stylesheet_directory
 * instead of template_directory
 */
 
if ( !function_exists( 'optionsframework_init' ) ) {
	define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/inc/' );
	require_once dirname( __FILE__ ) . '/inc/options-framework.php';
}


if ( !function_exists( 'ol_init' ) ) {
	define( 'olp', get_template_directory_uri() . '/inc/widgets/hey-its-a-flickr-widget/' );
	require_once dirname( __FILE__ ) . '/inc/widgets/hey-its-a-flickr-widget/heyitsflickr.php';
}

if ( !function_exists( 'pchr_init' ) ) {
	define( 'reoc', get_template_directory_uri() . '/inc/widgets/flexible-posts-widget/' );
	require_once dirname( __FILE__ ) . '/inc/widgets/flexible-posts-widget/flexible-posts-widget.php';
}


define('MTMS_INCLUDE', get_template_directory() . '/inc'); 
define('MTMS_PLUGIN', get_template_directory() . '/inc/plugin'); 
define('MTMS_PLUGIN_URL', get_template_directory_uri() . '/inc/plugin'); 


require_once(MTMS_INCLUDE . '/sm-kodes.php');
require_once(MTMS_PLUGIN . '/shortcodes/shortcodes-ultimate.php');

require_once(MTMS_PLUGIN . '/per-page-sidebars.php');

/* 
 * Make theme available for translation
 * Translations can be filed in the /languages/ directory
 */
load_theme_textdomain( 'mi', get_template_directory() . '/languages' );


add_theme_support( 'automatic-feed-links' );

if ( ! isset( $content_width ) ) $content_width = 960;




if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Sidebar-Widgets',
'before_widget' => '<div class="side-cats2"><div class="sider-22">',
'after_widget' => '</div></div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));



	
	
	register_nav_menus( array(
        'primary' => __( 'Primary Navigation'),
                
    ) );
// remove menu container div
function my_wp_nav_menu_args( $args = '' )
{
    $args['container'] = false;
    return $args;
} // function
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );



/********************** Posts Thubmnail *******************************/

add_theme_support( 'post-thumbnails' ); 
add_image_size( 'category-thumb', 212, 9999 );
add_image_size( 'category-thumb-2', 293, 9999 );
add_image_size( 'category-thumb-3', 454, 9999 );
add_image_size( 'category-thumb-4', 148, 83, true );
add_image_size( 'category-thumb-s', 680, 398, true );
add_image_size( 'slide_post', 960, 351, true );
add_image_size( 'feature_posts', 240, 240, true );
add_image_size( 'thumb-blog', 640, 299, true );
add_image_size( 'related-thumb', 134, 100, true );
add_image_size( 'portoflio-thumb', 960, 487, true );
add_image_size( 'portoflio-related-thumb', 216, 140, true );

wp_link_pages( $args ); 
posts_nav_link();
the_tags();

add_action('init', 'project_custom_init');  
	
	/*-- Custom Post Init Begin --*/
	function project_custom_init()
	{
	  $labels = array(
		'name' => _x('Projects', 'post type general name'),
		'singular_name' => _x('Project', 'post type singular name'),
		'add_new' => _x('Add New', 'project'),
		'add_new_item' => __('Add New Project'),
		'edit_item' => __('Edit Project'),
		'new_item' => __('New Project'),
		'view_item' => __('View Project'),
		'search_items' => __('Search Projects'),
		'not_found' =>  __('No projects found'),
		'not_found_in_trash' => __('No projects found in Trash'),
		'parent_item_colon' => '',
		'menu_name' => 'Portfolio'

	  );
	  
	 $args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => true,
		'show_ui' => true,
		'show_in_menu' => true,
		'query_var' => true,
		'rewrite' => true,
		'capability_type' => 'post',
		'has_archive' => true,
		'hierarchical' => false,
		'menu_position' => null,
		'supports' => array('title','editor','author','thumbnail','excerpt','comments', 'post-formats')
	  );
	  // The following is the main step where we register the post.
	  register_post_type('project',$args);
	  
	  // Initialize New Taxonomy Labels
	  $labels = array(
		'name' => _x( 'Tags', 'taxonomy general name' ),
		'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
		'search_items' =>  __( 'Search Types' ),
		'all_items' => __( 'All Tags' ),
		'parent_item' => __( 'Parent Tag' ),
		'parent_item_colon' => __( 'Parent Tag:' ),
		'edit_item' => __( 'Edit Tags' ),
		'update_item' => __( 'Update Tag' ),
		'add_new_item' => __( 'Add New Tag' ),
		'new_item_name' => __( 'New Tag Name' ),
	  );
		// Custom taxonomy for Project Tags
		register_taxonomy('tagportifolio',array('project'), array(
		'hierarchical' => true,
		'labels' => $labels,
		'show_ui' => true,
		'query_var' => true,
		'rewrite' => array( 'slug' => 'tag-portifolio' ),
	  ));
	  
	}
	/*-- Custom Post Init Ends --*/
	
	/*--- Custom Messages - project_updated_messages ---*/
	add_filter('post_updated_messages', 'project_updated_messages');
	
	function project_updated_messages( $messages ) {
	  global $post, $post_ID;

	  $messages['project'] = array(
		0 => '', // Unused. Messages start at index 1.
		1 => sprintf( __('Project updated. <a href="%s">View project</a>'), esc_url( get_permalink($post_ID) ) ),
		2 => __('Custom field updated.'),
		3 => __('Custom field deleted.'),
		4 => __('Project updated.'),
		/* translators: %s: date and time of the revision */
		5 => isset($_GET['revision']) ? sprintf( __('Project restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
		6 => sprintf( __('Project published. <a href="%s">View project</a>'), esc_url( get_permalink($post_ID) ) ),
		7 => __('Project saved.'),
		8 => sprintf( __('Project submitted. <a target="_blank" href="%s">Preview project</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
		9 => sprintf( __('Project scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview project</a>'),
		  // translators: Publish box date format, see http://php.net/date
		  date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
		10 => sprintf( __('Project draft updated. <a target="_blank" href="%s">Preview project</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
	  );

	  return $messages;
	}
	
	/*--- #end SECTION - project_updated_messages ---*/
	
	
	
	function enqueue_filterable() 
	{
		wp_register_script( 'filterable', get_template_directory_uri() . '/js/filterable.js', array( 'jquery' ) );
		wp_enqueue_script( 'filterable' );
	}
	add_action('wp_enqueue_scripts', 'enqueue_filterable');
	
	
/********************** Tag Styles *******************************/

function tag_style($args = array ()) {

         $args['smallest'] = 11;
		 $args['largest'] = 11;
		 $args['unit'] = 'px';
		 $args['number'] = 25;
		 return $args;
		 }
add_filter ('widget_tag_cloud_args', 'tag_style', 90);	

/********************** Comments *******************************/

if ( ! function_exists( 'mt_comment' ) ) :
/**

 * @ Comments.php credit to Twenty Ten Wordpress theme - http://wordpress.org/extend/themes/twentyten
 * @ Modified by Moonthemes
 
 */
 
function mt_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, 36 ); ?>
				<?php printf( __( '%s <span class="says">(Author)</span>', 'mt' ), 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.', 'mt' ); ?></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', 'mt' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'mt' ), ' ' );
				?>
				&middot; <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
			
			</div><!-- .comment-meta .commentmetadata -->

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

			
		</div><!-- #comment-##  -->

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

// add filter to change the text of comment notes
add_filter ('comment_form_defaults','comment_reform');

function comment_reform($arg) {
    $arg['comment_notes_before'] = '<p class="comment-notes">' . __ ('Your email address and name are required fields marked') . '<span class="required2">' . __ ( ' * ' ) . '</span>' . '</p>';
	return $arg;
	}
	
/*
Plugin Name: Limit Posts
Plugin URI: http://labitacora.net/comunBlog/limit-post.phps
Description: Limits the displayed text length on the index page entries and generates a link to a page to read the full content if its bigger than the selected maximum length.
Usage: the_content_limit($max_charaters, $more_link)
Version: 1.1
Author: Alfonso Sánchez-Paus Díaz y Julián Simón de Castro
Author URI: http://labitacora.net/
License: GPL
Download URL: http://labitacora.net/comunBlog/limit-post.phps
Make:
    In file index.php
    replace the_content()
    with the_content_limit(1000, "more")
*/

function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = strip_tags($content);

   if (strlen($_GET['p']) > 0) {
      echo "<p>";
      echo $content;
      echo "</p>";
   }
   else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
        $content = substr($content, 0, $espacio);
        $content = $content;
        echo "<p>";
        echo $content;
        echo "</p>";
   }
   else {
      echo "<p>";
      echo $content;
      echo "</p>";
   }
}
	
?>