<?php
global $data;
/**************************************************************
*          All theme Paths 
***************************************************************/
//theme Directory and URI
define('Lioit_DIR', get_template_directory());
define('Lioit_URI', get_template_directory_uri());
//Lioitizat Lioit
define('Lioit_FW', Lioit_DIR . '/Lioit');

define('Lioit_TM', Lioit_FW . '/templates');
//post types
define('Lioit_TYPE', Lioit_FW . '/posttype');
define('Lioit_BTN', Lioit_FW . '/tinymce');

//assest
define('Lioit_JS', Lioit_URI . '/js');
define('Lioit_CSS', Lioit_URI . '/css');
define('Lioit_IMG', Lioit_URI . '/images');
define('Lioit_SCRIPTS', Lioit_FW. '/scripts');
define('Lioit_FUN', Lioit_FW . '/functions');
define('Lioit_ADMIN', Lioit_DIR . '/admin');
define('Lioit_META', Lioit_FW . '/metaboxes');
define('Lioit_SC', Lioit_FW . '/shortcodes');
define('Lioit_WIDGET', Lioit_FW . '/widgets');


require Lioit_META . '/meta-box.php';
require Lioit_META . '/theme_metaboxes.php';

require Lioit_FW . '/update-notice.php';
require Lioit_DIR . '/scripts/aq_resizer.php';

//Custom types
require Lioit_TYPE . '/video.php';
//Functions
require Lioit_FUN . '/functions.php';
require Lioit_FUN . '/pagination.php';
require Lioit_FUN . '/sidebar_generator.php';
require Lioit_FUN . '/news_tabs.php';
require Lioit_FUN . '/news_small_boxs.php';
require Lioit_FUN . '/news_big_boxs.php';
require Lioit_FUN . '/authors.php';
// Custom widgets
require Lioit_WIDGET . '/widget-tabbed.php';
require Lioit_WIDGET . '/widget-latest-posts.php';
require Lioit_WIDGET . '/widget-twitter.php';
require Lioit_WIDGET . '/widget-author.php';
require Lioit_WIDGET . '/widget-twitter-follow.php';
require Lioit_WIDGET . '/widget-facebook.php';
require Lioit_WIDGET . '/widget-gplus.php';
require Lioit_WIDGET . '/widget-subscribe.php';
require Lioit_WIDGET . '/social-counter.php';
require Lioit_WIDGET . '/video-widget.php';
require Lioit_WIDGET . '/widget-cat.php';
require Lioit_WIDGET . '/widget-catlist.php';
require Lioit_WIDGET . '/widget-flickr.php';
require Lioit_WIDGET . '/ads125.php';
require Lioit_WIDGET . '/ads300.php';
require Lioit_WIDGET . '/widget-login.php';
require Lioit_WIDGET . '/comments-widget.php';
require Lioit_WIDGET . '/postsImages-widget.php';
require Lioit_WIDGET . '/widget-authorinfo.php';
//ShortCodes
require Lioit_SC . '/shortcodes.php';
//Tinymce Buttons
require Lioit_FW . '/tinymce/twitterbt.php';
require Lioit_FW . '/tinymce/flickrbt.php';
require Lioit_FW . '/tinymce/highlight.php';
require Lioit_FW . '/tinymce/quote.php';
require Lioit_FW . '/tinymce/divide.php';
require Lioit_FW . '/tinymce/clear.php';
require Lioit_FW . '/tinymce/tooltip.php';
require Lioit_FW . '/tinymce/buttons.php';
require Lioit_FW . '/tinymce/lists.php';
require Lioit_FW . '/tinymce/tabs.php';
require Lioit_FW . '/tinymce/accordion.php';
require Lioit_FW . '/tinymce/columns.php';
require Lioit_FW . '/tinymce/gmap.php';
require Lioit_FW . '/tinymce/videosc.php';
require Lioit_FW . '/tinymce/box.php';
require Lioit_FW . '/tinymce/dropcap.php';
/*-----------------------------------------------------------------------------------*/
# Theme Support
/*-----------------------------------------------------------------------------------*/
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link', 'video', 'image', 'quote' ) );
add_theme_support('post-thumbnails');
add_theme_support( 'automatic-feed-links' );

add_editor_style('custom-editor-style.css');
if ( ! isset( $content_width ) ) 
    $content_width = 960;


/**************************************************************
 *          Menus
 ***************************************************************/
if ( function_exists( 'register_nav_menu' ) ) {
  register_nav_menus(
   array(
    'mainnav'   => __('Categories' , 'lioit'),
   )
  );
  register_nav_menus(
   array(
    'mainmenu'   => __('Main Menu' , 'lioit'),
   )
  );

}
 


/*-----------------------------------------------------------------------------------*/
/*	Output Custom CSS Into Header
/*-----------------------------------------------------------------------------------*/

function lioit_custom_css() {
	
		global $data;
		
		$custom_css ='';
		
		//CUSTOM FIELD CSS
		if(!empty($data['custom_css'])) {
			$custom_css .= $data['custom_css'];
		}


		
		//GENERAL BACKGROUND
		if(!empty($data['custom_bg'])) {
			$custom_css .= 'body{background-image: url('.$data['custom_bg'].');}';
		}
	
		
		//SECOND STATIC CIRCLE BACKGROUND COLOR
		if(!empty($data['bg_color'])) {
			$custom_css .= 'body { background: '.$data['bg_color'].' !important; }';
		}

		//SECOND STATIC CIRCLE BACKGROUND COLOR
		if(!empty($data['margin_logo'])) {
			$custom_css .= '#header #logo a img { margin-top: '.$data['margin_logo'].'px !important; }';
		}

		
		//ECHO CSS
		$css_output = "<!-- Custom CSS -->\n<style type=\"text/css\">\n" . $custom_css . "\n</style>";
		
		if(!empty($custom_css)) {
			echo $css_output;
		}
}

add_action('wp_head', 'lioit_custom_css');

/*-----------------------------------------------------------------------------------*/
/*	SIDEBARS
/*-----------------------------------------------------------------------------------*/
if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'name' => 'Main Sidebar',
		'id' => 'sidebar-one',
		'description' => 'Widgets in this area will be shown in Home',
		'before_widget' => '<div class="widget %2$s clearfix">',
		'after_widget' => '</div></div>',
		'before_title' => '<h2>',
		'after_title' => '</h2><div class="widgetContent">',
));
if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'name' => 'Single',
		'id' => 'single-side',
		'description' => 'Widgets in this area will be shown first section of single blog.',
		'before_widget' => '<div class="widget %2$s clearfix">',
		'after_widget' => '</div></div>',
		'before_title' => '<h2>',
		'after_title' => '</h2><div class="widgetContent">',
));
if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'name' => 'Archive',
		'id' => 'archive-side',
		'description' => 'Widgets in this area will be shown in Archive',
		'before_widget' => '<div class="widget %2$s clearfix">',
		'after_widget' => '</div></div>',
		'before_title' => '<h2>',
		'after_title' => '</h2><div class="widgetContent">',
));
if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'name' => 'Videos',
		'id' => 'videos-side',
		'description' => 'Widgets in this area will be shown in Archive',
		'before_widget' => '<div class="widget %2$s clearfix">',
		'after_widget' => '</div></div>',
		'before_title' => '<h2>',
		'after_title' => '</h2><div class="widgetContent">',
));
if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'name' => 'Footer',
		'id' => 'footer-widgets',
		'description' => 'Widgets in this area will be shown in Footer',
		'before_widget' => '<div class="footerWidgetsGrid">
                	<div class="widget %2$s">',
		'after_widget' => '</div><!--End Widegt-->
                </div><!--End FooterWidgetsGrid-->',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
));

/***************************************************************
@
@	Max Excerpt & Short Title Fanctions
@
/**************************************************************/
function the_excerpt_max_charlength($charlength) {
   $excerpt = get_the_excerpt();
   $charlength++;
   if(strlen($excerpt)>$charlength) {
       $subex = substr($excerpt,0,$charlength-5);
       $exwords = explode(" ",$subex);
       $excut = -(strlen($exwords[count($exwords)-1]));
       if($excut<0) {
            echo substr($subex,0,$excut);
       } else {
       	    echo $subex;
       }
   } else {
	   echo $excerpt;
   }
}

function short_title($after = '', $length) {
	$mytitle = explode(' ', get_the_title(), $length);
	if (count($mytitle)>=$length) {
		array_pop($mytitle);
		$mytitle = implode(" ",$mytitle). $after;
	} else {
		$mytitle = implode(" ",$mytitle);
	}
	return $mytitle;
}
function excerpt($limit) {
      $excerpt = explode(' ', get_the_excerpt(), $limit);
      if (count($excerpt)>=$limit) {
        array_pop($excerpt);
        $excerpt = implode(" ",$excerpt).'...';
      } else {
        $excerpt = implode(" ",$excerpt);
      } 
      $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
      return $excerpt;
    }
// Empty Pragraph Fix
  /*
    Plugin Name: Shortcode empty Paragraph fix
    Plugin URI: http://www.johannheyne.de/wordpress/shortcode-empty-paragraph-fix/
    Description: Fix issues when shortcodes are embedded in a block of content that is filtered by wpautop.
    Author URI: http://www.johannheyne.de
    Version: 0.1
    Put this in /wp-content/plugins/ of your Wordpress installation
    */


    add_filter('the_content', 'shortcode_empty_paragraph_fix');
    function shortcode_empty_paragraph_fix($content)
    {   
        $array = array (
            '<p>[' => '[', 
            ']</p>' => ']', 
            ']<br />' => ']'
        );

        $content = strtr($content, $array);

		return $content;
    }

//shortcodes in widgets
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode', 11);
/*-----------------------------------------------------------------------------------*/
/*	OTHER FUNCTIONS
/*-----------------------------------------------------------------------------------*/
// SHOW HOME LINK
function home_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );

function wpe_excerptlength_index($length) {
    return 15;
}
// LOCALIZATION SUPPORT
load_theme_textdomain( 'lioit', Lioit_DIR.'/lang' );
// FLUSH
if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {
	$wp_rewrite->flush_rules();
}
/*-----------------------------------------------------------------------------------*/
// OPTIONS Lioit
/*-----------------------------------------------------------------------------------*/
add_filter('comment_form_defaults', 'your_comment_form');
function your_comment_form($form_options)
{

    // Fields Array
    $fields = array(

        'author' =>
        '<p class="comment-form-author">' .
        ( $req ? '<span class="required">*</span>' : '' ) .
        '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' placeholder="' . __( 'Name','lioit' ) . '" />' .
        '</p>',

        'email' =>
        '<p class="comment-form-email">' .
        ( $req ? '<span class="required">*</span>' : '' ) .
        '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' placeholder="' . __( 'Email','lioit' ) . '" />' .
        '</p>',

        'url' =>
        '<p class="comment-form-url">'  .
        '<input name="url" size="30" id="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" type="text" placeholder="' . __( 'Website','lioit' ) . '" />' .
        '</p>',

    );

    // Form Options Array
    $form_options = array(
        // Include Fields Array
        'fields' => apply_filters( 'comment_form_default_fields', $fields ),

        // Template Options
        'comment_field' =>
        '<p class="comment-form-comment">' .
        '<textarea name="comment" id="comment" aria-required="true" rows="8" cols="45" placeholder="' . __( 'Comment', 'lioit' ) . '"></textarea>' .
        '</p>',

        'must_log_in' =>
        '<p class="must-log-in">' .
        sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.','lioit' ),
            wp_login_url( apply_filters( 'the_permalink', get_permalink($post_id) ) ) ) .
        '</p>',

        'logged_in_as' =>
        '<p class="logged-in-as">' .
        sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>','lioit' ),
            admin_url('profile.php'), $user_identity, wp_logout_url( apply_filters('the_permalink', get_permalink($post_id)) ) ) .
        '</p>',

        'comment_notes_before' =>
        '<p class="comment-notes">' .
        __( 'Your email address will not be published.','lioit' ) . ( $req ? $required_text : '' ) .
        '</p>',

        'comment_notes_after' => '',

        // Rest of Options
        'id_form' => 'form-comment',
        'id_submit' => 'submit',
        'title_reply' => __( 'Leave a Comment','lioit' ),
        'title_reply_to' => __( 'Leave a Reply to %s','lioit' ),
        'cancel_reply_link' => __( 'Cancel reply','lioit' ),
        'label_submit' => __( 'Post Comment','lioit' ),
    );

    return $form_options;
}
define('ADMIN_PATH', get_stylesheet_directory() . '/admin/');
define('ADMIN_DIR', get_stylesheet_directory_uri() . '/admin/');
$themedata = wp_get_theme('liomagazine');
define('THEMENAME', $themedata['Name']);
define('OPTIONS', 'of_options');
define('BACKUPS', 'of_options');
require_once (ADMIN_PATH . 'admin-interface.php');
require_once (ADMIN_PATH . 'theme-options.php');
require_once (ADMIN_PATH . 'admin-functions.php');
require_once (ADMIN_PATH . 'medialibrary-uploader.php');




