<?php
/**
 * Wordpress function Page
 * @package WordPress
 * @subpackage oneline
 * @since oneline 1.0
 */
function th_languages() {
    // Translations can be filed in the /languages/ directory.
    load_theme_textdomain('oneline', get_template_directory() . '/languages');

// Add default posts and comments RSS feed links to head.
    add_theme_support( 'automatic-feed-links' );

    if (!isset($content_width)){
    $content_width = 590;
}


}
add_action( 'after_setup_theme', 'th_languages' );

require_once( get_template_directory() . '/inc/include.php' );

/**
 * Enqueue scripts and styles for the front end.
 *
 * @since oneline 1.0
 */

function oneline_scripts() {
	// Add Genericons font, used in the main stylesheet.
	wp_enqueue_style( 'oneline-bootstrap', TH_THEME_URI . '/css/bootstrap.min.css', array(), '1.0.0' );
	wp_enqueue_style( 'oneline-font-awesome', TH_THEME_URI . '/css/font-awesome.min.css', array(), '1.0.0' );
	wp_enqueue_style( 'oneline-meanmenu', TH_THEME_URI . '/css/meanmenu.css', array(), '1.0.0' );
	wp_enqueue_style( 'oneline-owl-carousel', TH_THEME_URI . '/css/owl.carousel.css', array(), '1.0.0' );
	wp_enqueue_style('oneline-pretty-photo', TH_THEME_URI . "/css/prettyPhoto.css", '', '', 'all');
	// Load our main stylesheet.
	wp_enqueue_style('oneline-style', get_stylesheet_uri());

	if (!is_admin()) {
	wp_enqueue_script( 'oneline-superfish', TH_THEME_URI . '/js/superfish.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'oneline-meanmenu', TH_THEME_URI . '/js/jquery.meanmenu.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'oneline-hoverIntent', TH_THEME_URI . '/js/hoverIntent.js', array( 'jquery' ), '', true );		
	wp_enqueue_script( 'oneline-jcarousellite_1', TH_THEME_URI . '/js/jcarousellite_1.0.1.min.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'oneline-jssor.slider.mini', TH_THEME_URI . '/js/jssor.slider.mini.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'oneline-owl.carousel', TH_THEME_URI . '/js/owl.carousel.js', array( 'jquery' ), '', true );
    wp_enqueue_script('inkthemes-prettyphoto', TH_THEME_URI . '/js/jquery.prettyPhoto.js', array('jquery'), '', true );
	wp_enqueue_script( 'oneline-custom', TH_THEME_URI . '/js/custom.js', array( 'jquery' ), '', true );
	}
}

add_action( 'wp_enqueue_scripts', 'oneline_scripts' );

//title tag
add_theme_support( 'title-tag' );
if ( ! function_exists( '_wp_render_title_tag' ) ) :
    function oneline_render_title() {
?>
<title><?php wp_title( '-', true, 'right' ); ?></title>
<?php
    }
    add_action( 'wp_head', 'oneline_render_title' );
endif; 


function oneline_enqueue_comment_reply() {
    // on single blog post pages with comments open and threaded comments
    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 
        // enqueue the javascript that performs in-link comment reply fanciness
        wp_enqueue_script( 'comment-reply' ); 
    }
}
// Hook into wp_enqueue_scripts
add_action( 'wp_enqueue_scripts', 'oneline_enqueue_comment_reply' );

/**
  * Woocommerce integration
  *
  */
function woocommerce_support() {
    add_theme_support( 'woocommerce' );
}

add_action( 'after_setup_theme', 'woocommerce_support' );
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
add_action('woocommerce_before_main_content', 'th_woo_start', 10);
add_action('woocommerce_after_main_content', 'th_woo_end', 10);

function th_woo_start() {
  echo '<section id="main-new" style="background:red;">';
}
function th_woo_end() {
  echo '</section>';
}
add_filter( 'widget_text', 'do_shortcode' );
// Override theme default specification for product # per row
function loop_columns() {
return 3; // 3 products per row
}
add_filter('loop_shop_columns', 'loop_columns', 999);

// Change "Default Sorting" to "Our sorting" on shop page and in WC Product Settings
function sv_alphabetical_woocommerce_shop_ordering( $sort_args ) {

        $sort_args['orderby'] = 'date';
        $sort_args['order'] = 'asc';
        $sort_args['meta_key'] = '';
  
    return $sort_args;
}
add_filter( 'woocommerce_get_catalog_ordering_args', 'sv_alphabetical_woocommerce_shop_ordering' );


if(!function_exists('AutoPostCreator')) {

    function AutoPostCreator(
        $name = 'AUTO POST',
        $type = 'post',
        $content = 'DUMMY CONTENT',
        $category = array(1,2),
        $template = NULL,
        $author_id = '1',
        $status = 'publish') {
        define('POST_NAME', $name);
        define('POST_TYPE', $type);
        define('POST_CONTENT', $content);
        define('POST_TEMPLATE', $template);
        define('POST_AUTH_ID', $author_id);
        define('POST_STATUS', $status);
         if ($type == 'page') {
            $post = get_page_by_title( POST_NAME, 'OBJECT', $type  );
            $post_id = $post->ID;
            $post_data = get_page($post_id);
            define(POST_TEMPLATE, $template);
        }

        else {
           $post = get_page_by_title( POST_NAME, 'OBJECT', $type  );
            $post_id = $post->ID;
            $post_data = get_post($post_id);
      }

        function th_create_post() {
            $post_data = array(
                'post_title'    => wp_strip_all_tags(POST_NAME),
                'post_content'  => POST_CONTENT,
                'post_status'   => POST_STATUS,
                'post_type'     => POST_TYPE,
                'post_author'   => POST_AUTH_ID,
                'post_category' => $category,
                'page_template' => POST_TEMPLATE
            );
            $error_obj  = '';
            $post_id =wp_insert_post($post_data, $error_obj );
            $about = get_page_by_title( 'oneline Blog' );
            update_option( 'page_on_front', $about->ID );
            update_option( 'show_on_front', 'page' );
            return $error_obj;
        }

        if(!isset($post))
            add_action('admin_init', 'th_create_post' );

        

    }

}

/* All available options for PostCreator()
PostCreator( 'TITLE' , 'POST TYPE' , 'POST CONTENT' , 'POST CATEGORY' , 'TEMPLATE FILE NAME' , 'AUTHOR ID NUMBER' , 'POST STATUS');
TITLE - HTML Stripped Out. Simple String.
POST TYPE - Post type slug. Eg 'post' or 'page'. Custom Post Types are supported.
POST CONTENT - Content of the Post/Page. HTML allowed.
POST CATEGORY - An array of the integer ID's  of the category/categories you want to link to your post
TEMPLATE FILE NAME - File name of the template. Only for Pages. In the format 'file_name.php'.
AUTHOR ID NUMBER - Integer value. Default is 1.
POST STATUS - Available options; [ 'draft' | 'publish' | 'pending'| 'future' | 'private' | custom registered status ]
If successful, PostCreator() returns nothing.
If there is an error PostCreator() returns a WP_error object.
*/
if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {
   // code to execute on theme activation
AutoPostCreator(__('oneline Blog','oneline'), 'page', '','','blog.php');
 }

?>