<?php
/*
Plugin Name:WappPress
Plugin URI: http://wapppress.com
Description: A WordPress mobile app plugin that makes it easy to build android apps for WordPress website
Version: 6.0.9
Author: WappPress Team
Author URI: http://wapppress.com
@2015. Unauthorized use and/or duplication of this plugin without express and written permission from this plugin's author and/or owner is strictly prohibited. A WappPress plugin can only be used for one WordPress website. If you want to  use it on second website, you have to purchase another license.
*/
 class wappPress {
	public static $dirPath;
	public static $dirUrl;
	public static $dirInc;
	public static $dirJs;
	public static $dirCss;
	public static $dirImg;
	function __construct() {
		
	  // Define plugin constants
		$dirPath  = trailingslashit( plugin_dir_path( __FILE__ ) );
		$dirUrl   = trailingslashit( plugins_url( dirname( plugin_basename( __FILE__ ) ) ) );
		$dirInc   = $dirPath  . 'includes/';
		$dirCss   = $dirUrl  . 'css/';
		$dirImg   = $dirUrl  . 'images/';
		$dirJs    = $dirUrl  . 'js/';
		
		
		// Setup our plugin loaded
		add_action( 'admin_enqueue_scripts', array( $this, 'admin_custom_scripts' ) );
		
		//Create comment table
		function create_plugin_database_table() {
			global $wpdb;
			$table_name = $wpdb->prefix . 'wappcomment';
			$sql = "CREATE TABLE $table_name (
					wapp_id mediumint(9) unsigned NOT NULL AUTO_INCREMENT,
					wapp_response varchar(100) NOT NULL,
					wapp_date varchar(50) NOT NULL,
					wapp_status  ENUM( '1', '0' ) NOT NULL,
					PRIMARY KEY  (wapp_id)
				);";
			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
			dbDelta( $sql );
		}
		register_activation_hook( __FILE__, 'create_plugin_database_table' );
		
		//Drop comment table
		function drop_plugin_database_table(){
			global $wpdb;	
			$table_name = $wpdb->prefix . 'wappcomment';
			$sql = "DROP TABLE ". $table_name;
			$wpdb->query($sql);
		}
		register_deactivation_hook(__FILE__, 'drop_plugin_database_table' );
		//Include file	
		require_once( $dirInc . 'wappPress_admin_setting.php' );
		require_once( $dirInc . 'wappPress_customize.php' );
		new wappPress_customize();
		$options = get_option('wapppress_settings');
		define('COMPILE_ID','http://wapppress.com');
		//Hide/Show App Name
		if(!empty($options['wapppress_name'])){	
			add_filter( 'bloginfo', 'wpse_alter_blog_name', 10, 2 );
			function wpse_alter_blog_name( $output, $show ) {
			$options = get_option('wapppress_settings');
			$title= $options['wapppress_name'];
			if ( $show != 'name' ) return $output;
				return $title;
			}
		}
		//Hide/Show Post Author Name
		if(isset($options['wapppress_theme_author']))
	  {
		if($options['wapppress_theme_author']!='on'){
			function wapppress_remove_post_auther() {
				add_filter('comment_author', '__return_false');
			}
		 add_action('loop_start', 'wapppress_remove_post_auther'); 
	  }	
	  }
	  //Hide/Show Post Date 
	  if(isset($options['wapppress_theme_date']))
	  {
		if($options['wapppress_theme_date']!='on'){
			function wappPress_remove_post_date() {
				add_filter('the_date', '__return_false');
				add_filter('the_time', '__return_false');
				add_filter('the_modified_date', '__return_false');
				add_filter('get_the_date', '__return_false');
				add_filter('get_the_time', '__return_false');
				add_filter('get_the_modified_date', '__return_false');
			} 
			add_action('loop_start', 'wappPress_remove_post_date');
		}	
	  }
	   if(isset($options['wapppress_theme_comment']))
	  {
		if($options['wapppress_theme_comment'] != 'on' ){
					//Hide Comment Count
					add_filter('get_comments_number','wapp_post_comment_count');
					function wapp_post_comment_count($post_id) {
						global $wpdb, $id;
						$post_id = (int) $post_id;
						if ( !$post_id )
						$post_id = (int) $id;
						$post = get_post($post_id);
						$post_owner = $post->post_author;
						$owner_email = get_the_author_meta('user_email', $post_owner);
						
						$request = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID != '$id' AND comment_approved >'1'  AND user_id != '$post_owner' AND comment_author_email != '$owner_email'";

						$newcount = $wpdb->get_var($request);
						return $newcount;
					}
					
				// Disable support for comments and trackbacks in post types
					function wapppress_disable_comments_post_types_support() {
						$post_types = get_post_types();
						foreach ($post_types as $post_type) {
							if(post_type_supports($post_type, 'comments')) {
								remove_post_type_support($post_type, 'comments');
								remove_post_type_support($post_type, 'trackbacks');
							}
						}
					}
					add_action('admin_init', 'wapppress_disable_comments_post_types_support');
					// Close comments on the front-end
					function wapppress_disable_comments_status() {
						return false;
					}
					add_filter('comments_open', 'wapppress_disable_comments_status', 20, 2);
					add_filter('pings_open', 'wapppress_disable_comments_status', 20, 2);

					// Hide existing comments
					function wapppress_disable_comments_hide_existing_comments($comments) {
						$comments = array();
						return $comments;
					}
					add_filter('comments_array', 'wapppress_disable_comments_hide_existing_comments', 10, 2);
				
	      } 
		  }
	}
	function admin_custom_scripts(){ 
		//Plugins css files
		wp_enqueue_style( 'bootstrap-css-4.5.2', plugins_url( 'css/bootstrap.min.css',  __FILE__ ) );
		wp_enqueue_style( 'styles-admin', plugins_url( 'css/styles-admin.css',  __FILE__ ) );
		wp_enqueue_style( 'jquery.loader.min', plugins_url( 'css/jquery.loader.min.css',  __FILE__ ) );
		wp_enqueue_style( 'wp-admin-wapp-style', plugins_url( 'css/wp-admin-wapp-style.css',  __FILE__ ) );
		wp_enqueue_style( 'wp-slider', plugins_url( 'css/wp-slider.css',  __FILE__ ) );
		wp_enqueue_style( 'media-queries', plugins_url( 'css/media-queries.css',  __FILE__ ) );
		wp_enqueue_style( 'jquery.Jcrop.min', plugins_url( 'css/jquery.Jcrop.min.css',  __FILE__ ) );
		wp_enqueue_style( 'croppie.min', plugins_url( 'css/croppie.min.css',  __FILE__ ) );
			
		
		//Plugins js files
		wp_enqueue_script( 'bootstrap-js-4.5.2', plugins_url( 'js/bootstrap.min.js',  __FILE__ ) );
		wp_enqueue_script( 'jquery.min"', plugins_url( 'js/jquery.min.js"',  __FILE__ ), array('jquery'));
		wp_enqueue_script( 'jquery.loader.min', plugins_url( 'js/jquery.loader.min.js',  __FILE__ ), array('jquery'));
		wp_enqueue_script( 'wp-slides.min.jquery', plugins_url( 'js/wp-slides.min.jquery.js',  __FILE__ ), array('jquery'));
		wp_enqueue_script( 'wp-selector', plugins_url( 'js/wp-selector.js',  __FILE__ ), array('jquery'));
		wp_enqueue_script( 'jquery.validate', plugins_url( 'js/jquery.validate.js',  __FILE__ ), array('jquery'));
		wp_enqueue_script( 'additional-methods.min', plugins_url( 'js/additional-methods.min.js',  __FILE__ ), array('jquery'));
		wp_enqueue_script( 'wapppress-admin-script.min', plugins_url( 'js/wapppress-admin-script.min.js?v='.rand(100,999),  __FILE__ ), array('jquery'));
		wp_enqueue_script( 'jquery.Jcrop.min', plugins_url( 'js/jquery.Jcrop.min.js',  __FILE__ ), array('jquery'));
		wp_enqueue_script( 'croppie', plugins_url( 'js/croppie.js',  __FILE__ ), array('jquery'));
		 // Pass data to JavaScript
		wp_localize_script('wapppress-admin-script.min', 'wapppressPluginData', array(
			'ajaxUrl' => admin_url('admin-ajax.php'),
			'nonce' => wp_create_nonce('wapppress_nonce'),
		));

	}
}
new wappPress();



		
		