<?php
/* INCLUDE PHP FILES */
  require_once( trailingslashit( get_template_directory() ). 'includes/register_widgets.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/flash_game.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/widgets/widgets.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/metaboxes.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/extra-metaboxes.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/functions.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/custom_css.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/shortcodes.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/myarcadeplugin_api.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/plugins/tigu-login/tigu-login.php');
  require_once( trailingslashit( get_template_directory() ). 'tigu-options/options-init.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/plugins/whos-online/whos-online.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/plugins/wp-superlike/wp-superlike.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/plugins/dp-flickr-widget/dp-flickr-widget.php' );

  if(function_exists('bp_is_active') ):
  //
  else:
  require_once( trailingslashit( get_template_directory() ). 'includes/plugins/user-photo-master/user-photo.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/plugins/my-profile/my-profile.php' );
  require_once( trailingslashit( get_template_directory() ). 'includes/extra_contact_fields.php' );
  endif;

/* FIXING BLURRY IMAGE AVATAR */
  if(function_exists('bp_is_active') ):
	if ( !defined( 'BP_AVATAR_THUMB_WIDTH' ) )
		define( 'BP_AVATAR_THUMB_WIDTH', 100 );

	if ( !defined( 'BP_AVATAR_THUMB_HEIGHT' ) )
		define( 'BP_AVATAR_THUMB_HEIGHT', 100 );
  endif;

/* INCLUDE REVIEWS */
  $reviewbox = get_template_directory() . '/includes/plugins/reviews/reviews.php';
  include $reviewbox;

/* INCLUDE NEWS TICKER */
  $newstick = get_template_directory() . '/includes/plugins/jnewsticker/jnewsticker-for-wordpress.php';
  include $newstick;

/* INCLUDE NOTIFICATION BAR */
  if(get_option('tigu_notbar_enable', 'false') == 'true'):
  $notbar = get_template_directory() . '/includes/plugins/notification-bar/notificationbar.php';
  include $notbar;
  endif;

/* INCLUDE CUSTOM LOGIN PAGE */
  if(get_option('tigu_login_custom_wp') == 'true'):
  $customlooginpage = get_template_directory() . '/includes/plugins/custom-login/custom-login.php';
  include $customlooginpage;
  endif;

/* INCLUDE DASHBOARD SKIN */
  if(get_option('tigu_dashboard_skin') == 'true'):
  $dashboardskin = get_template_directory() . '/includes/plugins/dasboard-skin/ez-admin-skins.php';
  include $dashboardskin;
  endif;

/* INCLUDE  REVOLUTION SLIDER */
  $revslider = get_template_directory() . '/includes/sliders/revslider/revslider.php';
  include $revslider;

//Fixing empty sidebar widgets on dashboard at the first theme install
  if(get_option('tigu_revslider_active', '0') == '0') {
  if(!class_exists('RevSliderAdmin')) {
  $revslider_admin_hook = get_template_directory() . '/includes/sliders/revslider/revslider_admin.php';
  include $revslider_admin_hook;
  }
  $revslider_admin = new RevSliderAdmin($revslider);
  $revslider_admin->onActivate();
  update_option('tigu_revslider_active', '1');
  }

/* FRONTEND JAVASCRIPT */
add_action('wp_enqueue_scripts', 'tigu_frontend_scripts');
function tigu_frontend_scripts() {
    wp_register_script('easing', get_template_directory_uri().'/js/jquery.easing-1.3.min.js', 'jquery');
    wp_register_script('jCarouselLite', get_template_directory_uri().'/js/jcarousellite_1.0.1.pack.js', 'jquery');
    wp_register_script('tiptip', get_template_directory_uri().'/js/jquery.tipTip.minified.js', 'jquery');
    wp_register_script('scrollTop', get_template_directory_uri().'/js/scrolltopcontrol.js', 'jquery');
    wp_register_script('prettyPhoto', get_template_directory_uri().'/js/jquery.prettyPhoto.js', 'jquery');
    wp_register_script('superfish', get_template_directory_uri().'/js/superfish.js', 'jquery');
    wp_register_script('supersubs', get_template_directory_uri().'/js/supersubs.js', 'jquery');
    wp_register_script('GameleonTheme', get_template_directory_uri().'/js/scripts.js', 'jquery');
    wp_enqueue_script('jquery');
    wp_enqueue_script('easing');
    wp_enqueue_script('jCarouselLite');
    wp_enqueue_script('prettyPhoto');
    wp_enqueue_script('tiptip');
    wp_enqueue_script('scrollTop');
    wp_enqueue_script('superfish');
    wp_enqueue_script('supersubs');
    wp_enqueue_script("comment-reply");
    wp_enqueue_script('GameleonTheme');
    wp_localize_script('GameleonTheme', 'GameleonVars',
    array(
         'templateurl' => get_template_directory_uri(),
         'ajaxUrl' => admin_url('admin-ajax.php')
        )
    );
    
    // MyArcadePlugin Mochi Leaderboard
    if ( defined('MYARCADE_VERSION') && is_singular() ) {
      wp_enqueue_script('leaderboard', 'http://xs.mochiads.com/static/pub/swf/leaderboard.js', '', '', false);
    }
}

/* POST THUMBNAIL SETTINGS */
  if ( function_exists( 'add_theme_support' ) ) { 
  add_theme_support( 'post-thumbnails' );
  if ( function_exists( 'add_image_size' ) )
  add_image_size('post-image', 292, 242, true);        /*image size for SINGLE (featured image on description block - single.php) */
  add_image_size('hometabs-thumb', 137, 100, true);    /* image size for HOME TABS WIDGET (homepage) */
  add_image_size('slider-image', 633, 270, true);      /* image size for SLIDERS (homepage) */
  add_image_size('category-big', 280, 126, true);      /* image size for HOME CATEGORIES WIDGET - BIG IMAGE (homepage) */
  add_image_size('widget-image-thumb', 76, 60, true);  /* image size for HOME CATEGORIES WIDGET - SMALL IMAGE (homepage), CATEGORY, MOSTPLAYED, MOST POPULAR, AUTHOR, ARCHIVE PAGES */
  add_image_size('blog-style-image', 174, 100, true);  /* image size for BLOG STYLE(homepage and category), SEARCH, TAGS */
  add_image_size('sidebar-thumbs', 50, 50, true);      /* image size for SIDEBAR GLOBAL */
  add_image_size('miniscroller-thumb', 85, 60, true);  /* image size for MINISCROLLER WIDGET (homepage) */
  add_image_size('bigscroller-thumb', 183, 120, true); /* image size for BIGSCROLLER WIDGET (homepage) */
  add_image_size('related-thumb', 74, 60, true);       /* image size for RELATED GAMES (single.php) */
}
 
/* RSS FEED LINK SUPPORT */
	add_theme_support('automatic-feed-links');

/* THEME TRANSLATION */
  load_theme_textdomain('Gameleon', get_template_directory() . '/languages');
  $locale = get_locale();
  $locale_file = get_template_directory() . '/languages/' . $locale . '.php';
  if(is_readable($locale_file)) {
  require_once($locale_file);
}

/* COMMENTS FUNCTION */
  function gameleon_comment($comment, $args, $depth) {
  $GLOBALS['comment'] = $comment; ?>
    <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
    <div class="the-comment">
    <?php echo get_avatar($comment,$size='50'); ?>
    <div class="comment-arrow"></div>
    <div class="comment-box">
    <div class="comment-author">
    <strong><?php echo get_comment_author_link() ?></strong>
<small>
<?php printf(__('%1$s at %2$s', 'Gameleon'), get_comment_date(),  get_comment_time()) ?> <?php edit_comment_link(__('Edit', 'Gameleon'),'  ','') ?> -
<?php comment_reply_link(array_merge( $args, array(
'reply_text' => 'Reply',
'depth' => $depth,
'max_depth' => $args['max_depth']))) ?>
</small>
    </div>
    <div class="comment-text">
<?php if ($comment->comment_approved == '0') : ?>
    <em><?php _e('Your comment is awaiting moderation.', 'Gameleon') ?></em>
    <br />
<?php endif; ?>
<?php comment_text() ?>
    </div>
    </div>
    </div>

<?php }

/* ENABLE THREADED COMMENTS */
function enable_threaded_comments()
{
if (is_singular() AND comments_open()) {
wp_enqueue_script('comment-reply');
}
}
add_action('get_header', 'enable_threaded_comments');

if ( ! isset( $content_width ) ) $content_width = 800;
add_filter( 'the_category', 'add_nofollow_cat' );
function add_nofollow_cat( $text ) { $text = str_replace('rel="category tag"', "", $text); return $text; }

/* SWITCHING TEMPLATE FUNCTION */
add_filter( 'single_template', 'tigu_single_template' );

function tigu_single_template( $template ) {

$catarr = get_option('tigu_switching_template');
$catarr = explode(",", $catarr);
if (in_category($catarr))
$template = locate_template( array( 'single.php', 'single.php' ) );

elseif ( get_option('tigu_template_type', 'WordPres Default' ) == 'WordPres Default') {
$template = locate_template( array( 'single.php', 'single.php' ) );
}
else
$template = locate_template( array( 'single_games.php', 'single.php' ) );

return $template;
}

/* PRETTYPHOTO GALLERY */
add_filter( 'wp_get_attachment_link', 'tigu_prettyphoto_gallery');
 
function tigu_prettyphoto_gallery ($content) {
	$content = preg_replace("/<a/","<a rel=\"prettyPhoto[slides]\"",$content,1);
	return $content;
}

/* ADMIN MENU AND CONTACT FORM */
      $tigu = new TiguThemeIncludes('Gameleon');
      class TiguThemeIncludes {
      var $theme_name;
    public function __construct()
   {
      $theme_name = '';
      $this->theme_name = $theme_name;
      add_action('init', array($this, 'init'));
      add_action('admin_menu', array($this, 'admin_menu'));
      add_action('wp_ajax_tigu_contact_form', array($this, 'contact_form'));
      add_action('wp_ajax_nopriv_tigu_contact_form', array($this, 'contact_form'));

   }
      public function init()
   {
   register_nav_menu('topmenu', __('Top Menu', 'Gameleon'));
   register_nav_menu('mainmenu', __('Main Menu', 'Gameleon'));
}
   public function admin_menu()
   {
$object = '';
     add_action('admin_print_styles-'.$object, array($this, 'admin_scripts'));
   }

   public function contact_form()
   {
      $headers = 'From: ' . $_POST['tigu_name'] . ' <' . $_POST['tigu_email'] . '>' . "\r\n";
      wp_mail(get_option('admin_email'), 'Email From '. $_POST['tigu_name'], $_POST['tigu_message'], $headers);
   die();
   }
   }