<?php 
/*
Plugin Name: Cake Api Integration
Plugin URI: http://e-fusionsoft.com
Description: Plugin for displaying data from cake files
Author: Usha Kalura
Version: 1.0
Author URI: http://e-fusionsoft.com
*/

    #Admin function

	#Load plugin under wordpress plugin list
	function cake_admin() {
		include('cake_api_admin.php');
	}

	#Show menu & load respective page when user clicks in Cake Api menu
	function cake_admin_actions() {
	   add_options_page('Cake Api', 'Cake Api', 8, 'cakeapi', 'cake_admin');
	}
	
	#Add cake api menu link in admin panel
	add_action('admin_menu', 'cake_admin_actions');

	#Frontend function Starts
	function call_curl_func($url){
			// is cURL installed yet?
			if (!function_exists('curl_init')){
				die('Sorry cURL is not installed!');
			}
			$ch = curl_init($url);
            curl_setopt($ch, CURLOPT_REFERER, $url);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			//curl_setopt($ch,CURLOPT_USERPWD, 'tv2012ln:kasa879roCKS!');
            curl_setopt($ch, CURLOPT_TIMEOUT, 60);
            $output = curl_exec($ch);
            curl_close($ch);
			return $output;
	}
	#Get artist of week information
	function call_artist_of_week(){
			$url=get_option('cake_store_url')."artists/artistofweek";
			echo call_curl_func($url);
	}
	#Get success stories
	function call_success_stroies(){
			$url=get_option('cake_store_url')."artists/successstories";
			echo call_curl_func($url);
	}
	
	#Get login
	function call_artist_login(){
			$url=get_option('cake_store_url')."artist/users/login";
			echo call_curl_func($url);
	}
	#Get register
	function call_artist_register(){
			$url=get_option('cake_store_url')."artist/users/register";
			echo call_curl_func($url);
	}
	#check login
	function call_check_login(){
		   $url=get_option('cake_store_url')."users/check_login"; ?>
			<script>
			$.ajax({ url: '<?php echo $url;?>', success: function(data) {
			var a= $.trim(data);
				if(a!=0 && a!=""){
				//alert(a);
				$("li#fancylogin").html("<a href='logout/'>Logout</a>");
				$("li#fancyregister").html("<a href='/"+a+"'>View site</a>");
				}else{
				$("a#fancylogin").show();
				}
			} });
			</script>
			<?php
	}
	
	#Get artist gallery
	function call_artist_gallery(){
			$url=get_option('cake_store_url')."results/genrelist";
			echo call_curl_func($url);
	}
	
	#Get search result
	function call_search_result($str){
			$url=get_option('cake_store_url')."results/index/?".$str;
			echo call_curl_func($url);
	}
	
	function call_forgot_password(){
	   $url=get_option('cake_store_url')."artist/users/reset_request/";
	   echo call_curl_func($url);
	}
	
	function call_register_activate($link){
	   $url=get_option('cake_store_url')."artist/users/register_activate/".$link;
	   echo call_curl_func($url);
	}
	
	function call_reset_confirm($link){
	   $url=get_option('cake_store_url')."artist/users/reset_confirm/".$link;
	   echo call_curl_func($url);
	}
	
	function call_register_thanks(){
	   $url=get_option('cake_store_url')."artist/users/register_thanks/";
	   echo call_curl_func($url);
	}
	
	 #Fetech data from trakvan cake database
  
	/*
	function fetch_data_using_query(){
	$ctrakdb = new wpdb(get_option('cake_dbuser'),get_option('cake_dbpwd'), get_option('cake_dbname'), get_option('cake_dbhost'));
				$data = $ctrakdb->get_results("SELECT * FROM tbl_user_masters WHERE user_type_id='3' AND block='0' AND artistofweek='1'");
				echo "<pre>";
				print_r($data);
				$store_url = get_option('cake_store_url');
	}
	*/

    #Get organizer login
	function call_organizer_login(){
			//get site base url
			$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
			$siteUrl=$protocol.$_SERVER['HTTP_HOST'];
		
			$url= $siteUrl."/tvcontest/organizer/users/login";
			echo call_curl_func($url);
	}


?>