<?php

error_reporting(0);

/*

Plugin Name: Social Post Press

Plugin URI: http://socialpostpress.com/login

Description: Social Post Press is an easy-to-use plugin that lets you add email optin forms inside the Facebook Newsfeed.

Version: 2.4

Author: Joe Veloz	

Author URI: http://socialpostpress.com

*/

register_activation_hook(__FILE__, 'mq_create_db1');

register_activation_hook(__FILE__, 'mq_create_db2');

register_activation_hook(__FILE__, 'mq_create_db3');

register_activation_hook(__FILE__, 'mq_create_db4');

register_activation_hook(__FILE__, 'mq_create_db5');

register_activation_hook(__FILE__, 'mq_create_db6');



/* Create necessary table on plugin activation */

global $wpdb, $msg;

$table_name = $wpdb->prefix . "social_post_press";



function social_post_press_removeslashes($str){

	if(get_magic_quotes_gpc()){

		$str=stripslashes($str);

	}

	return $str;

}

function social_post_press_safeurl( $v )
    {
        $v = strtolower( $v );
        $v = preg_replace( "/[^a-z0-9]+/", "-", $v );
        $v = trim( $v, "-" );
        return $v;
    }

if(!empty($_POST) && $_POST['action'] == 'update'){

	global $wpdb, $msg;

	$table_name = $wpdb->prefix . "social_post_press";	

	if($_POST['sbmt']){

		$upload_dir = wp_upload_dir();

		$target = $upload_dir['basedir']."/"; 

		$url = $upload_dir['baseurl']."/";

		$allowedExts = array("jpg", "jpeg", "gif", "png");

		$extension = end(explode(".", $_FILES["social_post_press_upload_bg_img"]["name"]));

		$extension2 = end(explode(".", $_FILES["social_post_press_fb_icon"]["name"]));

		$extension2 = end(explode(".", $_FILES["social_post_press_fb_icon"]["name"]));

		$upload_bg_img='';

		if ((($_FILES["social_post_press_upload_bg_img"]["type"] == "image/gif") || ($_FILES["social_post_press_upload_bg_img"]["type"] == "image/jpeg") || ($_FILES["social_post_press_upload_bg_img"]["type"] == "image/png")	|| ($_FILES["social_post_press_upload_bg_img"]["type"] == "image/pjpeg")) && ((($_FILES["social_post_press_upload_bg_img"]["size"]/1024)/1024) < 1)	&& in_array($extension, $allowedExts)){

		  	if ($_FILES["social_post_press_upload_bg_img"]["error"] > 0){

		    	echo "Return Code: " . $_FILES["social_post_press_upload_bg_img"]["error"] . "<br>";

		    }else{
		    		$upload_bg_img=explode(".",$_FILES["social_post_press_upload_bg_img"]["name"]);
		    		$upload_bg_img[0]=social_post_press_safeurl($upload_bg_img[0]);
			    	move_uploaded_file($_FILES["social_post_press_upload_bg_img"]["tmp_name"],$target .$upload_bg_img[0].".".$upload_bg_img[1]);		  		
			    	$upload_bg_img=$url.$upload_bg_img[0].".".$upload_bg_img[1];
		    }	

		}

		$fb_icon='';

		if ((($_FILES["social_post_press_fb_icon"]["type"] == "image/gif") || ($_FILES["social_post_press_fb_icon"]["type"] == "image/jpeg") || ($_FILES["social_post_press_fb_icon"]["type"] == "image/png")	|| ($_FILES["social_post_press_fb_icon"]["type"] == "image/pjpeg")) && ((($_FILES["social_post_press_fb_icon"]["size"]/1024)/1024) < 1)	&& in_array($extension2, $allowedExts)){

		  	if ($_FILES["social_post_press_fb_icon"]["error"] > 0){

		    	echo "Return Code: " . $_FILES["social_post_press_fb_icon"]["error"] . "<br>";

		    }else{
		    		$fb_icon=explode(".",$_FILES["social_post_press_fb_icon"]["name"]);
		    		$fb_icon[0]=social_post_press_safeurl($fb_icon[0]);
			    	move_uploaded_file($_FILES["social_post_press_fb_icon"]["tmp_name"],$target .$fb_icon[0].".".$fb_icon[1]);		  		
			    	$fb_icon=$url.$fb_icon[0].".".$fb_icon[1];
		    }

		}



		$fb_image='';

		$mediatype=$_POST['social_post_press_mediatype'];



		if($_POST['social_post_press_mediatype']=="image"){

			if(strlen($_FILES["social_post_press_fb_image"]['name'])>0){

			 if((($_FILES["social_post_press_fb_image"]["type"] == "image/gif") || ($_FILES["social_post_press_fb_image"]["type"] == "image/jpeg") || ($_FILES["social_post_press_fb_image"]["type"] == "image/png")	|| ($_FILES["social_post_press_fb_image"]["type"] == "image/pjpeg"))){

			  	if ($_FILES["social_post_press_fb_image"]["error"] > 0){

			    	echo "Return Code: " . $_FILES["social_post_press_fb_image"]["error"] . "<br>";

			    }else{
			    		$fb_image=explode(".",$_FILES["social_post_press_fb_image"]["name"]);
		    			$fb_image[0]=social_post_press_safeurl($fb_image[0]);

				    	move_uploaded_file($_FILES["social_post_press_fb_image"]["tmp_name"],$target."fbimage".$fb_image[0].".".$fb_image[1]);	

				    		$fb_image=$url."fbimage".$fb_image[0].".".$fb_image[1];	  		

			    }

			}

		   }

		}



		if(strlen($fb_image)==0){

			$fb_image=$_POST['social_post_press_fb_image_temp'];

		}	



		$btn_img = spp_plugins_url()."images/buttons/";

		$bg_img = spp_plugins_url()."images/bg/";



		$social_post_press_optin_code = $_POST['social_post_press_optin_code'];

		$social_post_press_app_id = $_POST['social_post_press_app_id'];

		$social_post_press_fb_icon =$fb_icon;

		$social_post_press_upload_bg_img =$upload_bg_img;

		$social_post_press_background_img = $bg_img.$_POST['social_post_press_background_img'].".png";

		$social_post_press_headline = $_POST['social_post_press_headline'];

		$social_post_press_youtube_video_code = $_POST['social_post_press_youtube_video_code'];

		$social_post_press_choose_autoplay_option = $_POST['social_post_press_choose_autoplay_option'];

		$social_post_press_link_button = $_POST['social_post_press_link_button'];

		$social_post_press_font_type = $_POST['social_post_press_font_type'];

		$social_post_press_font_color = $_POST['social_post_press_font_color'];

		$social_post_press_sub_headline = $_POST['social_post_press_sub_headline'];

		$social_post_press_link_url = $_POST['social_post_press_link_url'];

		$buttontype = $btn_img.$_POST['buttontype'].".png";

		$social_post_press_navigationtype=$_POST['social_post_press_navigationtype'];

		$social_post_press_redirect_btn_title=$_POST['social_post_press_link_button'];

		//$social_post_press_redirect_btn_title=$_POST['social_post_press_redirect_btn_title'];

		$social_post_press_redirect_url=$_POST['social_post_press_redirect_url'];

		//$social_post_press_emailgate=$_POST['social_post_press_emailgate'];

		if(isset($_POST['social_post_press_emailgate'])){

			$social_post_press_emailgate='yes'; 

		}else{

			$social_post_press_emailgate='no';

		}

		$social_post_press_optin_form = extract_input_fields(social_post_press_removeslashes($_POST['social_post_press_optin_code']));

		$social_post_press_awberdelaydisplay=$_POST['social_post_press_awberdelaydisplay'];

		//print_r($_POST);die;

		if(isset($_POST['social_post_press_isheading'])){

			$social_post_press_enable_headsubhead='yes';

		}else{

			$social_post_press_enable_headsubhead='no';

		}



		if(isset($_POST['social_post_press_isbackground'])){

			$social_post_press_isbackground='yes';

		}else{

			$social_post_press_isbackground='no';

		}



		$social_post_press_posticonwidth=$_POST['social_post_press_posticonwidth'];

		$social_post_press_posticonheight=$_POST['social_post_press_posticonheight'];



		$social_post_press_videowidth=$_POST['social_post_press_videowidth'];

		$social_post_press_videoheight=$_POST['social_post_press_videoheight'];

		$social_post_press_postimagewidth=$_POST['social_post_press_postimagewidth'];

		$social_post_press_postimageheight=$_POST['social_post_press_postimageheight'];

		$social_post_press_placeholdertext=$_POST['social_post_press_placeholdertext'];

		$social_post_press_placeholdernametext=$_POST['social_post_press_placeholdernametext'];

		$social_post_press_redirectdelaydisplay=$_POST['social_post_press_redirectdelaydisplay'];

		$social_post_press_emailgateredirect=$_POST['social_post_press_emailgateredirect'];

		

		$social_post_press_optin_form = serialize($social_post_press_optin_form);

		

                $update_data4 = array('social_post_press_app_id'=>trim($social_post_press_app_id), 'social_post_press_fb_icon'=>$social_post_press_fb_icon, 'social_post_press_upload_bg_img'=>$social_post_press_upload_bg_img, 'social_post_press_background_img'=>NULL, 'social_post_press_headline'=>$social_post_press_headline, 'social_post_press_youtube_video_code'=>$social_post_press_youtube_video_code, 'social_post_press_choose_autoplay_option'=>$social_post_press_choose_autoplay_option, 'social_post_press_optin_form'=>$social_post_press_optin_form, 'social_post_press_optin_code' =>$social_post_press_optin_code, 'social_post_press_link_button'=>$social_post_press_link_button, 'social_post_press_font_type' => $social_post_press_font_type, 'social_post_press_font_color' => $social_post_press_font_color, 'social_post_press_sub_headline' => $social_post_press_sub_headline, 'social_post_press_link_url' => $social_post_press_link_url, 'buttontype' => $buttontype,'social_post_press_fb_image'=>$fb_image,'social_post_press_mediatype'=>$mediatype,'social_post_press_enable_headsubhead'=>$social_post_press_enable_headsubhead,'social_post_press_isbackground'=>$social_post_press_isbackground,'social_post_press_navigationtype'=>$social_post_press_navigationtype,'social_post_press_redirect_btn_title'=>$social_post_press_redirect_btn_title,'social_post_press_redirect_url'=>$social_post_press_redirect_url,'social_post_press_awberdelaydisplay'=>$social_post_press_awberdelaydisplay,'social_post_press_emailgate'=>$social_post_press_emailgate,'social_post_press_posticonwidth'=>$social_post_press_posticonwidth,'social_post_press_posticonheight'=>$social_post_press_posticonheight,'social_post_press_videowidth'=>$social_post_press_videowidth,'social_post_press_videoheight'=>$social_post_press_videoheight,'social_post_press_postimagewidth'=>$social_post_press_postimagewidth,'social_post_press_postimageheight'=>$social_post_press_postimageheight,'social_post_press_placeholdertext'=>$social_post_press_placeholdertext,'social_post_press_redirectdelaydisplay'=>$social_post_press_redirectdelaydisplay,'social_post_press_emailgateredirect'=>$social_post_press_emailgateredirect,'social_post_press_placeholdernametext'=>$social_post_press_placeholdernametext);



		$update_data = array('social_post_press_app_id'=>trim($social_post_press_app_id), 'social_post_press_headline'=>$social_post_press_headline, 'social_post_press_youtube_video_code'=>$social_post_press_youtube_video_code, 'social_post_press_choose_autoplay_option'=>$social_post_press_choose_autoplay_option, 'social_post_press_optin_form'=>$social_post_press_optin_form, 'social_post_press_optin_code' =>$social_post_press_optin_code, 'social_post_press_link_button'=>$social_post_press_link_button, 'social_post_press_font_type' => $social_post_press_font_type, 'social_post_press_font_color' => $social_post_press_font_color, 'social_post_press_sub_headline' => $social_post_press_sub_headline, 'social_post_press_link_url' => $social_post_press_link_url, 'buttontype' => $buttontype,'social_post_press_fb_image'=>$fb_image,'social_post_press_mediatype'=>$mediatype,'social_post_press_enable_headsubhead'=>$social_post_press_enable_headsubhead,'social_post_press_isbackground'=>$social_post_press_isbackground,'social_post_press_navigationtype'=>$social_post_press_navigationtype,'social_post_press_redirect_btn_title'=>$social_post_press_redirect_btn_title,'social_post_press_redirect_url'=>$social_post_press_redirect_url,'social_post_press_awberdelaydisplay'=>$social_post_press_awberdelaydisplay,'social_post_press_emailgate'=>$social_post_press_emailgate,'social_post_press_posticonwidth'=>$social_post_press_posticonwidth,'social_post_press_posticonheight'=>$social_post_press_posticonheight,'social_post_press_videowidth'=>$social_post_press_videowidth,'social_post_press_videoheight'=>$social_post_press_videoheight,'social_post_press_postimagewidth'=>$social_post_press_postimagewidth,'social_post_press_postimageheight'=>$social_post_press_postimageheight,'social_post_press_placeholdertext'=>$social_post_press_placeholdertext,'social_post_press_redirectdelaydisplay'=>$social_post_press_redirectdelaydisplay,'social_post_press_emailgateredirect'=>$social_post_press_emailgateredirect,'social_post_press_placeholdernametext'=>$social_post_press_placeholdernametext);



		$update_data5 = array('social_post_press_app_id'=>trim($social_post_press_app_id), 'social_post_press_fb_icon'=>$social_post_press_fb_icon, 'social_post_press_upload_bg_img'=>NULL, 'social_post_press_background_img'=>$social_post_press_background_img, 'social_post_press_headline'=>$social_post_press_headline, 'social_post_press_youtube_video_code'=>$social_post_press_youtube_video_code, 'social_post_press_choose_autoplay_option'=>$social_post_press_choose_autoplay_option, 'social_post_press_optin_form'=>$social_post_press_optin_form, 'social_post_press_optin_code' =>$social_post_press_optin_code, 'social_post_press_link_button'=>$social_post_press_link_button, 'social_post_press_font_type' => $social_post_press_font_type, 'social_post_press_font_color' => $social_post_press_font_color, 'social_post_press_sub_headline' => $social_post_press_sub_headline, 'social_post_press_link_url' => $social_post_press_link_url, 'buttontype' => $buttontype,'social_post_press_fb_image'=>$fb_image,'social_post_press_mediatype'=>$mediatype,'social_post_press_enable_headsubhead'=>$social_post_press_enable_headsubhead,'social_post_press_isbackground'=>$social_post_press_isbackground,'social_post_press_navigationtype'=>$social_post_press_navigationtype,'social_post_press_redirect_btn_title'=>$social_post_press_redirect_btn_title,'social_post_press_redirect_url'=>$social_post_press_redirect_url,'social_post_press_awberdelaydisplay'=>$social_post_press_awberdelaydisplay,'social_post_press_emailgate'=>$social_post_press_emailgate,'social_post_press_posticonwidth'=>$social_post_press_posticonwidth,'social_post_press_posticonheight'=>$social_post_press_posticonheight,'social_post_press_videowidth'=>$social_post_press_videowidth,'social_post_press_videoheight'=>$social_post_press_videoheight,'social_post_press_postimagewidth'=>$social_post_press_postimagewidth,'social_post_press_postimageheight'=>$social_post_press_postimageheight,'social_post_press_placeholdertext'=>$social_post_press_placeholdertext,'social_post_press_redirectdelaydisplay'=>$social_post_press_redirectdelaydisplay,'social_post_press_emailgateredirect'=>$social_post_press_emailgateredirect,'social_post_press_placeholdernametext'=>$social_post_press_placeholdernametext);



		$update_data1 = array('social_post_press_app_id'=>$social_post_press_app_id, 'social_post_press_upload_bg_img'=>$social_post_press_upload_bg_img, 'social_post_press_background_img'=>NULL, 'social_post_press_headline'=>$social_post_press_headline, 'social_post_press_youtube_video_code'=>$social_post_press_youtube_video_code, 'social_post_press_choose_autoplay_option'=>$social_post_press_choose_autoplay_option, 'social_post_press_optin_form'=>$social_post_press_optin_form, 'social_post_press_optin_code' =>$social_post_press_optin_code, 'social_post_press_link_button'=>$social_post_press_link_button, 'social_post_press_font_type' => $social_post_press_font_type, 'social_post_press_font_color' => $social_post_press_font_color, 'social_post_press_sub_headline' => $social_post_press_sub_headline, 'social_post_press_link_url'=>$social_post_press_link_url, 'buttontype' => $buttontype,'social_post_press_fb_image'=>$fb_image,'social_post_press_mediatype'=>$mediatype,'social_post_press_enable_headsubhead'=>$social_post_press_enable_headsubhead,'social_post_press_isbackground'=>$social_post_press_isbackground,'social_post_press_navigationtype'=>$social_post_press_navigationtype,'social_post_press_redirect_btn_title'=>$social_post_press_redirect_btn_title,'social_post_press_redirect_url'=>$social_post_press_redirect_url,'social_post_press_awberdelaydisplay'=>$social_post_press_awberdelaydisplay,'social_post_press_emailgate'=>$social_post_press_emailgate,'social_post_press_posticonwidth'=>$social_post_press_posticonwidth,'social_post_press_posticonheight'=>$social_post_press_posticonheight,'social_post_press_videowidth'=>$social_post_press_videowidth,'social_post_press_videoheight'=>$social_post_press_videoheight,'social_post_press_postimagewidth'=>$social_post_press_postimagewidth,'social_post_press_postimageheight'=>$social_post_press_postimageheight,'social_post_press_placeholdertext'=>$social_post_press_placeholdertext,'social_post_press_redirectdelaydisplay'=>$social_post_press_redirectdelaydisplay,'social_post_press_emailgateredirect'=>$social_post_press_emailgateredirect,'social_post_press_placeholdernametext'=>$social_post_press_placeholdernametext);	



		$update_data2 = array('social_post_press_app_id'=>$social_post_press_app_id, 'social_post_press_upload_bg_img'=>NULL, 'social_post_press_background_img'=>$social_post_press_background_img, 'social_post_press_headline'=>$social_post_press_headline, 'social_post_press_youtube_video_code'=>$social_post_press_youtube_video_code, 'social_post_press_choose_autoplay_option'=>$social_post_press_choose_autoplay_option, 'social_post_press_optin_form'=>$social_post_press_optin_form, 'social_post_press_optin_code' =>$social_post_press_optin_code, 'social_post_press_link_button'=>$social_post_press_link_button, 'social_post_press_font_type' => $social_post_press_font_type, 'social_post_press_font_color' => $social_post_press_font_color, 'social_post_press_sub_headline' => $social_post_press_sub_headline, 'social_post_press_link_url'=>$social_post_press_link_url, 'buttontype' => $buttontype,'social_post_press_fb_image'=>$fb_image,'social_post_press_mediatype'=>$mediatype,'social_post_press_enable_headsubhead'=>$social_post_press_enable_headsubhead,'social_post_press_isbackground'=>$social_post_press_isbackground,'social_post_press_navigationtype'=>$social_post_press_navigationtype,'social_post_press_redirect_btn_title'=>$social_post_press_redirect_btn_title,'social_post_press_redirect_url'=>$social_post_press_redirect_url,'social_post_press_awberdelaydisplay'=>$social_post_press_awberdelaydisplay,'social_post_press_emailgate'=>$social_post_press_emailgate,'social_post_press_posticonwidth'=>$social_post_press_posticonwidth,'social_post_press_posticonheight'=>$social_post_press_posticonheight,'social_post_press_videowidth'=>$social_post_press_videowidth,'social_post_press_videoheight'=>$social_post_press_videoheight,'social_post_press_postimagewidth'=>$social_post_press_postimagewidth,'social_post_press_postimageheight'=>$social_post_press_postimageheight,'social_post_press_placeholdertext'=>$social_post_press_placeholdertext,'social_post_press_redirectdelaydisplay'=>$social_post_press_redirectdelaydisplay,'social_post_press_emailgateredirect'=>$social_post_press_emailgateredirect,'social_post_press_placeholdernametext'=>$social_post_press_placeholdernametext);	





		$update_data3 = array('social_post_press_app_id'=>$social_post_press_app_id, 'social_post_press_fb_icon'=>$social_post_press_fb_icon, 'social_post_press_headline'=>$social_post_press_headline, 'social_post_press_youtube_video_code'=>$social_post_press_youtube_video_code, 'social_post_press_choose_autoplay_option'=>$social_post_press_choose_autoplay_option, 'social_post_press_optin_form'=>$social_post_press_optin_form, 'social_post_press_optin_code' =>$social_post_press_optin_code, 'social_post_press_link_button'=>$social_post_press_link_button, 'social_post_press_font_type' => $social_post_press_font_type, 'social_post_press_font_color' => $social_post_press_font_color, 'social_post_press_sub_headline' => $social_post_press_sub_headline, 'social_post_press_link_url'=>$social_post_press_link_url, 'buttontype' => $buttontype,'social_post_press_fb_image'=>$fb_image,'social_post_press_mediatype'=>$mediatype,'social_post_press_enable_headsubhead'=>$social_post_press_enable_headsubhead,'social_post_press_isbackground'=>$social_post_press_isbackground,'social_post_press_navigationtype'=>$social_post_press_navigationtype,'social_post_press_redirect_btn_title'=>$social_post_press_redirect_btn_title,'social_post_press_redirect_url'=>$social_post_press_redirect_url,'social_post_press_awberdelaydisplay'=>$social_post_press_awberdelaydisplay,'social_post_press_emailgate'=>$social_post_press_emailgate,'social_post_press_posticonwidth'=>$social_post_press_posticonwidth,'social_post_press_posticonheight'=>$social_post_press_posticonheight,'social_post_press_videowidth'=>$social_post_press_videowidth,'social_post_press_videoheight'=>$social_post_press_videoheight,'social_post_press_postimagewidth'=>$social_post_press_postimagewidth,'social_post_press_postimageheight'=>$social_post_press_postimageheight,'social_post_press_placeholdertext'=>$social_post_press_placeholdertext,'social_post_press_redirectdelaydisplay'=>$social_post_press_redirectdelaydisplay,'social_post_press_emailgateredirect'=>$social_post_press_emailgateredirect,'social_post_press_placeholdernametext'=>$social_post_press_placeholdernametext);



		if($_FILES["social_post_press_fb_icon"]["name"] != '' && $_FILES["social_post_press_upload_bg_img"]["name"] != ''){

		

			$wpdb->update( $table_name, $update_data4,array('id' => $_GET['pid'])); 

			$msg = "Record Inserted Successfully.";

		}elseif($_FILES["social_post_press_fb_icon"]["name"] != '' && $_POST['social_post_press_background_img'] != ''){

			$wpdb->update( $table_name, $update_data5,array('id' => $_GET['pid'])); 

			$msg = "Record Inserted Successfully.";

		}elseif($_FILES["social_post_press_fb_icon"]["name"] != ''){

			$wpdb->update( $table_name, $update_data3,array('id' => $_GET['pid'])); 

			$msg = "Record Inserted Successfully.";

		}elseif($_FILES["social_post_press_upload_bg_img"]["name"] != ''){

			$wpdb->update( $table_name, $update_data1,array('id' => $_GET['pid'])); 

			$msg = "Record Inserted Successfully.";

		}elseif($_POST['social_post_press_background_img'] != ''){

			$wpdb->update( $table_name, $update_data2,array('id' => $_GET['pid'])); 

			$msg = "Record Inserted Successfully.";

		}else{

			$wpdb->update( $table_name, $update_data,array('id' => $_GET['pid'])); 

			$msg = "Record Inserted Successfully.";                        

        }

        $redirectuel=get_admin_url()."admin.php?page=".$_GET['page']."&pid=".$_GET['pid'];
        ?>
        <script type="text/javascript">
        window.location='<?php echo $redirectuel; ?>';
        </script>
        <?php
        die;

	}

 

} //if post action

function mq_create_db1() {
	global $wpdb;

	$table_name=$wpdb->prefix."social_post_press_temp";

	$wpdb->query("drop table ".$table_name);

	$sql = "CREATE TABLE ".$table_name." as select * from ".$wpdb->prefix."social_post_press";

	$wpdb->query($sql);

	// $sql="insert into ".$table_name." select * from ".$wpdb->prefix."social_post_press";
	// $wpdb->query($sql);

	$table_name=$wpdb->prefix."social_post_press";

	$wpdb->query("drop table ".$table_name);
}


function mq_create_db2() {

    global $wpdb;

    $table_name = $wpdb->prefix . "social_post_press";

    $default_values = array('social_post_press_name' => 'Splash Post');

    $sql = "CREATE TABLE $table_name ( id bigint(9) NOT NULL AUTO_INCREMENT PRIMARY KEY, social_post_press_name VARCHAR(128), social_post_press_app_id VARCHAR(128), social_post_press_fb_icon VARCHAR(255), social_post_press_fb_image VARCHAR(255), social_post_press_upload_bg_img VARCHAR(255), social_post_press_background_img VARCHAR(255), social_post_press_mediatype enum('video','image'), social_post_press_font_type VARCHAR(32), social_post_press_font_color VARCHAR(32), social_post_press_headline VARCHAR(128), social_post_press_sub_headline VARCHAR(255), social_post_press_enable_headsubhead enum('yes','no'), social_post_press_isbackground enum('yes','no'), social_post_press_youtube_video_code VARCHAR(64), social_post_press_choose_autoplay_option VARCHAR(16), social_post_press_link_button VARCHAR(64), social_post_press_optin_form TEXT, social_post_press_optin_code TEXT, social_post_press_link_url VARCHAR(255), buttontype VARCHAR(255), cur_timestamp TIMESTAMP,social_post_press_navigationtype enum('optinform', 'simplebtn'),social_post_press_redirect_btn_title VARCHAR(255),social_post_press_redirect_url TEXT,social_post_press_awberdelaydisplay VARCHAR(4),social_post_press_emailgate enum('no','yes'),social_post_press_posticonwidth VARCHAR(255),social_post_press_posticonheight VARCHAR(255), 	social_post_press_postimagewidth VARCHAR(255),social_post_press_postimageheight VARCHAR(255),social_post_press_videowidth VARCHAR(255),social_post_press_videoheight VARCHAR(255),social_post_press_placeholdertext VARCHAR(255),social_post_press_redirectdelaydisplay VARCHAR(4),social_post_press_emailgateredirect TEXT,social_post_press_placeholdernametext VARCHAR(255));";



    $table_name = $wpdb->prefix . "social_post_press_options";

    $sql .= "CREATE TABLE $table_name ( id bigint(9) NOT NULL AUTO_INCREMENT PRIMARY KEY, type VARCHAR(255), value VARCHAR(255));";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

    dbDelta($sql);

   // $wpdb->insert($wpdb->prefix . "social_post_press", $default_values);

}



function mq_create_db4() {

    global $wpdb;

    $table_name = $wpdb->prefix . "social_post_press";

    $default_values = array('social_post_press_name' => 'Splash Post');



   $sql = "ALTER TABLE $table_name ADD (social_post_press_fb_image VARCHAR(255));";
    $wpdb->query($sql);

    $sql = "ALTER TABLE $table_name ADD (social_post_press_fb_image VARCHAR(255), social_post_press_mediatype enum('video','image'), social_post_press_enable_headsubhead enum('yes','no'), social_post_press_isbackground enum('yes','no'),social_post_press_navigationtype enum('optinform', 'simplebtn'),social_post_press_redirect_btn_title VARCHAR(255),social_post_press_redirect_url TEXT,social_post_press_awberdelaydisplay VARCHAR(4),social_post_press_emailgate enum('no','yes'),social_post_press_posticonwidth VARCHAR(255),social_post_press_posticonheight VARCHAR(255),social_post_press_postimagewidth VARCHAR(255),social_post_press_postimageheight VARCHAR(255),social_post_press_videowidth VARCHAR(255),social_post_press_videoheight VARCHAR(255),social_post_press_placeholdertext VARCHAR(255),social_post_press_redirectdelaydisplay VARCHAR(4),social_post_press_emailgateredirect TEXT,social_post_press_placeholdernametext VARCHAR(255));";
    $wpdb->query($sql);

   // require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

  //  dbDelta($sql);

   // $wpdb->insert($wpdb->prefix . "social_post_press", $default_values);

}

function mq_create_db5() {

    global $wpdb;

    $table_name2 = $wpdb->prefix . "social_post_press_emaildatabase";

    $sql = "CREATE TABLE $table_name2 ( id bigint(9) NOT NULL AUTO_INCREMENT PRIMARY KEY, email VARCHAR(320) UNIQUE KEY, ip VARCHAR(255), datetime TIMESTAMP);";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

    dbDelta($sql);

    //$default_values = array('id' => 'Splash Post');

    

}


function mq_create_db6(){
	global $wpdb;

	$result = $wpdb->get_results("SHOW COLUMNS FROM ".$wpdb->prefix."social_post_press_temp");

	$columns=array();

	if(count($result)>0){

		for($i=0;$i<count($result);$i++){
			$columns[]=$result[$i]->Field;
		}
		$columns=implode(',',$columns);

		$sql="insert into ".$wpdb->prefix."social_post_press(".$columns.") select * from ".$wpdb->prefix."social_post_press_temp";
		$wpdb->query($sql);
	}
}


function mq_create_db3() {

    global $wpdb;

    $table_name2 = $wpdb->prefix . "fb_visitor_track";

    $sql = "CREATE TABLE $table_name2 ( id bigint(9) NOT NULL AUTO_INCREMENT PRIMARY KEY, cid bigint(9), ip VARCHAR(255), datetime TIMESTAMP);";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

    dbDelta($sql);

    //$default_values = array('id' => 'Splash Post');

    

}



function mq_create_post_options(){



}



function spp_plugins_url() {



        //Try to use WP API if possible, introduced in WP 2.6

        if (function_exists('plugins_url')) return trailingslashit(plugins_url(basename(dirname(__FILE__))));



        //Try to find manually... can't work if wp-content was renamed or is redirected

        $path = dirname(__FILE__);

        $path = str_replace("\\","/",$path);

        $path = trailingslashit(get_bloginfo('wpurl')) . trailingslashit(substr($path,strpos($path,"wp-content/")));

        return $path;

}



//if user is admin

if ( is_admin() ){

	add_action('admin_menu', 'fb_admin_menu2');

	function fb_admin_menu2() {

		add_action( 'admin_footer'. $plugin_page, 'myplugin_admin_footer2' );

	}

}



//add js/css file

add_action('init','add_js_css_file2');  

function add_js_css_file2() {

    wp_enqueue_style('style-spp', plugins_url( '/css/style-spp.css', __FILE__ ));

    wp_enqueue_style('layout-css', plugins_url( '/css/layout.css', __FILE__ ));

    wp_enqueue_style('colorpicker-css', plugins_url( '/css/colorpicker.css', __FILE__ ));

	wp_enqueue_script('colorpicker-js', plugins_url( '/js/colorpicker.js', __FILE__ ));

    wp_enqueue_script('eye', plugins_url( '/js/eye.js', __FILE__ ));

    wp_enqueue_script('util', plugins_url( '/js/utils.js', __FILE__ ));

    wp_enqueue_script('layout-js', plugins_url( '/js/layout.js', __FILE__ ));

	wp_enqueue_script('blockui-js', plugins_url( '/js/blockui.js', __FILE__ ));

}



add_action('admin_menu','pro_admin_menu2');

function pro_admin_menu2() { 

	add_menu_page(

		"Social Post Press",

		"Social Post Press",

		8,

		'social-post-press',

		"pro_admin_menu_list2",

		spp_plugins_url()."images/plugin.png"

	); 

}



if(!class_exists('WP_List_Table')){

	require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );

}



class campaign_list_table extends WP_List_Table {

	function __construct() {

		 parent::__construct( array(

			'singular'=> 'wp_list_text_link', //Singular label

			'plural' => 'wp_list_test_links', //plural label, also this well be one of the table css class

			'ajax'	=> false //We won't support Ajax for this table

		) );

	}



	 /**

	 * Add extra markup in the toolbars before or after the list

	 * @param string $which, helps you decide if you add the markup after (bottom) or before (top) the list

	 */

	function extra_tablenav( $which ) {

		if ( $which == "top" ){

			

		}

		if ( $which == "bottom" ){

			

		}

	}



	/**

	 * Define the columns that are going to be used in the table

	 * @return array $columns, the array of columns to use with the table

	 */

	function get_columns() {

		return $columns= array(

			'cb'        => '<input type="checkbox" />',

			'col_app_name'=>__('App Name'),

			'col_hits_uniq'=>__('Hits'),

			'col_app_date'=>__('Created on'),

			'col_link_id'=>__('ID')

		);

	}



    function column_cb($item) {

	    return sprintf(

	    '<input type="checkbox" name="book[]" value="%s" />', $item['ID']

	    );

    }



	/**

	 * Decide which columns to activate the sorting functionality on

	 * @return array $sortable, the array of columns that can be sorted by the user

	 */

	public function get_sortable_columns() {

		return $sortable = array(

			'col_app_name'=>array('social_post_press_name'),

			'col_link_id'=> array('id'),

			'col_hits_uniq'=> array('ip'),

			'col_app_date' => array('cur_timestamp')

		);

	}

	

	/**

	 * Prepare the table with different parameters, pagination, columns and table elements

	 */

	function prepare_items() {

		global $wpdb, $_wp_column_headers;

		$screen = get_current_screen();

		

		/* -- Preparing your query -- */

	        $query = "SELECT * FROM ".$wpdb->prefix."social_post_press order by id DESC";



		/* -- Ordering parameters -- */

		    //Parameters that are going to be used to order the result

		    $orderby = !empty($_GET["orderby"]) ? mysql_real_escape_string($_GET["orderby"]) : 'ASC';

		    $order = !empty($_GET["order"]) ? mysql_real_escape_string($_GET["order"]) : '';

		    if(!empty($orderby) & !empty($order)){ $query.=' ORDER BY '.$orderby.' '.$order; }



		/* -- Pagination parameters -- */

	        //Number of elements in your table?

	        $totalitems = $wpdb->query($query); //return the total number of affected rows

	        //How many to display per page?

	        $perpage = 5;

	        //Which page is this?

	        $paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : '';

	        //Page Number

	        if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }

	        //How many pages do we have in total?

	        $totalpages = ceil($totalitems/$perpage);

	        //adjust the query to take pagination into account

		    if(!empty($paged) && !empty($perpage)){

			    $offset=($paged-1)*$perpage;

	    		$query.=' LIMIT '.(int)$offset.','.(int)$perpage;

		    }



		/* -- Register the pagination -- */

			$this->set_pagination_args( array(

				"total_items" => $totalitems,

				"total_pages" => $totalpages,

				"per_page" => $perpage,

			) );

			//The pagination links are automatically built according to those parameters



		/* -- Register the Columns -- */

			$columns = $this->get_columns();

			$hidden = array();

			$sortable = $this->get_sortable_columns();

			$this->_column_headers = array($columns, $hidden, $sortable);

			

		/* -- Fetch the items -- */

			$this->items = $wpdb->get_results($query);

	}



	/**

	 * Display the rows of records in the table

	 * @return string, echo the markup of the rows

	 */

	function display_rows() {

		global $wpdb;

		//Get the records registered in the prepare_items method

		$records = $this->items;



		$table_name2 = $wpdb->prefix . "fb_visitor_track";

		$rows = $wpdb->get_results( "SELECT * FROM $table_name2");

		foreach ( $rows as $row ) {

			$user_count = $wpdb->get_results( "SELECT * FROM $table_name2 WHERE cid = ".$row->cid." GROUP BY ip" ); 

		}



		//Get the columns registered in the get_columns and get_sortable_columns methods

		list( $columns, $hidden ) = $this->get_column_info();



		if(!empty($records)){ 

			$num = 0;

			foreach($records as $rec){

				$class = ($num % 2 == 0)?' class="alternate"':'';

				$num++;



			//Open the line

	        echo '<tr id="record_'.$rec->id.'"'.$class.'>';

	        // var_dump($columns);

			foreach ( $columns as $column_name => $column_display_name ) {

				

				//Style attributes for each col

				$class = "class='$column_name column-$column_name'";

				$style = "";

				if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"';

				$attributes = $class . $style;



				//edit link

				$editlink  = '/wp-admin/link.php?action=edit&id='.(int)$rec->id;

		

				//Display the cell

				switch ( $column_name ) {

					case "col_app_name": echo '<td '.$attributes.'>'.social_post_press_removeslashes($rec->social_post_press_name).'<br/><a href="?page=social-post-press&pid='.social_post_press_removeslashes($rec->id).'">Edit</a>&nbsp;<a class="delete" data-id="'.social_post_press_removeslashes($rec->id).'">Delete</a></td>'; break;

					case "col_link_id":	echo '<td '.$attributes.'>'.social_post_press_removeslashes($rec->id).'</td>';	break;

					case "col_hits_uniq": if($row->cid == $rec->id){ echo '<td '.$attributes.'>'.count($user_count).'</td>';  break;}else{echo '<td '.$attributes.'>0</td>'; break;}

					

					case "col_app_date": echo '<td '.$attributes.'>'.social_post_press_removeslashes($rec->cur_timestamp).'</td>'; break;

					case "cb": echo '<td '.$attributes.'><input type="checkbox" /></td>'; break;

					

				}

			}



			//Close the line

			echo'</tr>';

		}}

	}



}

function pro_admin_menu_list2(){ 

	global $wpdb, $msg, $table_name;

	$table_name = $wpdb->prefix . "social_post_press";

	if($_POST['submit_add']){

		$social_post_press_name = $_POST['social_post_press_name'];

		$social_post_press_id = $_POST['id'];

		$wpdb->query( $wpdb->prepare( 

			"

				INSERT INTO $table_name

				( social_post_press_name )

				VALUES ( %s )

			", 

		        array(

				$social_post_press_name

			) 

		) ); 

		$rec = $wpdb->get_row("select * from ".$table_name." where social_post_press_name = '".$social_post_press_name."'"); ?>

		<?php $page_url = site_url().'/wp-admin/admin.php?page=social-post-press&pid='.social_post_press_removeslashes($rec->id);  ?>

		<script type="text/javascript">

		<!--

		   window.location="<?php echo $page_url; ?>";

		//-->

		</script>

	<?php }



	$where='';



	if(isset($_GET['pid']) && $_GET['pid']>0 && is_numeric($_GET['pid'])){

		$where =' where id='.$_GET['pid'];

	}



	$content2 = $wpdb->get_results('select * from '.$table_name.$where); ?>



	<?php if(isset($msg) && $msg != ''){ ?>

		<div class="msg"><?php echo $msg; ?></div> 

	<?php } ?>

	<div class="clear">&nbsp;</div>

	<img src="<?php echo spp_plugins_url(); ?>images/logo-spp.png"/>

	<?php		

		if(!isset($_GET['pid'])):

			global $wpdb;

			//Prepare Table of elements

			$wp_list_table = new campaign_list_table();

			$wp_list_table->prepare_items();



			if(isset($_POST['save_license'])){

				if(validate_license_key($_POST['licensekey'])){

					$wpdb->query("delete from ".$wpdb->prefix."social_post_press_options where type='licensekey'");



					$wpdb->query( $wpdb->prepare( 

						"

							INSERT INTO ".$wpdb->prefix."social_post_press_options(type,value) VALUES (%s,%s)

						", 

					        array(

					        'licensekey',

							$_POST['licensekey']

						) 

					) );

				}else{

					$msg='Wrong License Key.';

				}

			}



			//check if license entered

			



			$row = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."social_post_press_options");

//print_r($row);

			if(count($row)>0 && isset($_POST['licensekey'])){

				$lsinfo=getlicenseInformation($_POST['licensekey']);

				?>

				<table cellpadding="0" cellspacing="0" width="100%">

					<tr>

						<td align="center">

							<div class="licensePDF" style="width:500px; padding:5px;background-color:#EAFEE8; text-align:center;">

								<p>

									<?php

									$licensename='';

									if(strtolower($lsinfo->name)=="basic"){

										$licensename='Single License';

									}elseif(strtolower($lsinfo->name)=="pro"){

										$licensename='Personal License';

									}else{

										$licensename='Agency License';

									}

									?>



									The <?php echo $licensename; ?> of Social Post Press plugin has been activated successfully.

								</p>

								<br /><br />

								<p>You are going to redirect on App Manager Page shortly.</p>

								<script type="text/javascript">

									setTimeout(function(){

										window.location.href='<?php echo site_url()."/wp-admin/admin.php?page=social-post-press";  ?>';

									},5000);

									

								</script>

							<!-- <h4>Your Activation Details:</h4>

							<h4>Download Social Post Press: <a href="#">Click to Download</a></h4>

							<h4>Your License Key: <?php echo $_POST['licensekey']; ?></h4>

							<h4>Activations Remaining: <?php echo $lsinfo->avail; ?></h4>

							<p>

								PLEASE NOTE: If you purchased the developers license and you exceed 10 activations, Please contact us to increase your activation limit.

							</p>

							<p>

							  <table cellpadding="5" cellspacing="5">

							  	<tr>

							  		<td align="left">

							  			<img width="100" src="<?php echo plugins_url() ?>/social-post-press/images/PDF.gif" />

							  		</td>

							  		<td align="left" width="50"></td>

							  		<td align="left">

							  			Social Post Press PDF Quickstart Installation Guide<br />

							  			<a href="#">(Click to download)</a>

							  		</td>

							  	</tr>

							  </table>

							</p> -->

						</div>

						</td>

					</tr>

				</table>

				

				<?php

			}else if(count($row)>0){

			//End

			

			?>

				<div class="clear">&nbsp;</div>



				<div><h2 style="float:left;width:140px; margin:4px 0;">Create App</h2><a class="button-primary" id="addnew" href="#">ADD NEW</a></div>

				<div class="hide addnew">

					<div class="clear">&nbsp;</div>

					<form id="addnew" name="addfrm" method="post" action="" enctype="multipart/form-data">

						<p>Enter Your App Name:&nbsp;<input type="text" name="social_post_press_name" value="" size="50"/>&nbsp;&nbsp;<input type="submit" name="submit_add" value="Publish" class="button-primary"/><p>

					</form>

				</div>

				<div class="clear">&nbsp;</div>

				<div class="clear">&nbsp;</div>

				<div class="icon30"></div><h2 style="margin:10px 0;">Manage Apps</h2>

				<?php

				//Table of elements

				$wp_list_table->display();

				?>



				<?php

			}else{

				?>

				<style type="text/css">

				fieldset {

				  padding: 1em;

				 }



				 fieldset { border:1px solid #000000; width: 90%; }



				legend {

				  padding: 0.2em 0.5em;

				  border:1px solid #000000;

				  color:#000000;

				  font-size:100%;

				  text-align:right;

				  }

				</style>

				<div class="clear">&nbsp;</div>

				

				<form action="" method="post">

				<div>

					<h4 style="color:red;"><?php echo @$msg; ?></h4>

					<fieldset>

						<legend>Enter you license key</legend>

						<input type="text" style="width:300px;" name="licensekey"> <input type="submit" name="save_license" value="Save"/>

					</fieldset>

				</div>

				</form>

				<?php

			}

		endif;

	

	 	if(isset($_GET['pid']) && $_GET['pid']>0 && is_numeric($_GET['pid'])){ ?>

			<script type="text/javascript">

			jQuery(document).ready(function(){

				jQuery(".setting-menu").addClass("hide");

				jQuery("#addnew").addClass("hide");				

				jQuery(".clr").addClass("hide");

			});

			</script>

			<div id='app_form'>

				<?php fb_html_page2(); ?>

			</div>

	<?php } ?>

<?php }









function fb_html_page2() {

	global $wpdb, $msg;

	$table_name = $wpdb->prefix . "social_post_press";	

	$row = $wpdb->get_row("SELECT * FROM $table_name WHERE id = ".$_GET['pid']);

	// var_dump($row);

	$row->social_post_press_optin_code;

	$upload_dir = wp_upload_dir();

	$target = $upload_dir['baseurl']."/";

?>

<div class="icon31"></div><h1>Add a New App</h1>

<a href="?page=social-post-press">Manage App</a>&nbsp;|&nbsp;<span class="bold">Add App</span>

<div class="clear">&nbsp;</div>

<div class="clear">&nbsp;</div>

<div class="upload-img">

	<?php if($row->social_post_press_fb_icon !=''){ ?>

		<p>Facebook Post Icon<br/><br/><img src="<?php echo $row->social_post_press_fb_icon; ?>" width="150"/></p>

	<?php } else{

		echo "No Image Found for facebook post icon.<br/><br/>"; 

	} ?>	

	<div class="clear">&nbsp;</div>

	<?php if($row->social_post_press_upload_bg_img !=NULL || $row->social_post_press_upload_bg_img !=''){ ?>

		<p>Background Image<br/><br/><img src="<?php echo $row->social_post_press_upload_bg_img; ?>" width="150"/><br/><!-- <a id="remove" href="#">Remove Image</a> --></p>

	<?php } elseif($row->social_post_press_background_img !='' || $row->social_post_press_background_img !=NULL){ ?>

		<p>Background Image<br/><br/><img src="<?php echo $row->social_post_press_background_img; ?>" width="150"/><br/><!-- <a id="remove" href="#">Remove Image</a> --></p>

	<?php }else{

		echo "<br/>"; 

	}?>

	<div class="clear">&nbsp;</div>

	<?php

	if($row->social_post_press_mediatype=="image"){

		?>

		<p>Facebook Post Image<br/><br/><img src="<?php echo $row->social_post_press_fb_image; ?>" width="150"/></p>

		<?php

	}

	?>

</div>

<?php 

$wurl=site_url();

      $wurl=trim($wurl,'/');

if($row->social_post_press_app_id != '' && isset($row->social_post_press_app_id)){ ?>

	<div id="fb-root"></div>

	<script>

		window.fbAsyncInit = function() {

		   FB.init({

		     appId      : '<?php echo $row->social_post_press_app_id; ?>', // App ID

		     status     : true, // check login status

		     cookie     : true, // enable cookies to allow the server to access the session

		     xfbml      : true,  // parse XFBML

		  	 oauth: true 

		   });

		   // Additional initialization code here

		};



		 // Load the SDK Asynchronously

		(function(d){

		    var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}

		    js = d.createElement('script'); js.id = id; js.async = true;

		    js.src = "//connect.facebook.net/en_US/all.js";

		    d.getElementsByTagName('head')[0].appendChild(js);

		}(document));

		function fb_login(){

		FB.login(function(response) {

			if (response.authResponse) {

				console.log('Welcome!  Fetching your information.... ');

				FB.api('/me', function(response) {

					FB.getLoginStatus(function(response) {

					  	if (response.status === 'connected') {

						    // the user is logged in and has authenticated your

						    // app, and response.authResponse supplies

						    // the user's ID, a valid access token, a signed

						    // request, and the time the access token 

						    // and signed request each expire

						    //alert(response.authResponse.accessToken);

						    var token=response.authResponse.accessToken;

							

							jQuery.blockUI({ css: { 

								border: 'none', 

								padding: '15px', 

								backgroundColor: '#000', 

								'-webkit-border-radius': '10px', 

								'-moz-border-radius': '10px', 

								opacity: .5, 

								color: '#fff' 

							} });



						    jQuery.ajax({

						   		type: 'POST',

						        url: ajaxurl,

						        data:{action:'my_fetch_pages', licensekey:jQuery("input[name=licensekey]").attr("value"), task:'getfblist'}, 

						        success: function(data){

						        	jQuery.unblockUI

									

						        	var div='<div class="popupdiv"><div>Select Page</div>';

					            	var obj = jQuery.parseJSON(data);

					            	if(obj.data.error==1){

					            		alert(obj.data.msg);					            		

					            	}else{

					            		for(var i=0;i<(obj.data.links).length;i++){

					            			div+='<span>'+obj.data.links[i].link+'</span>';

					            		}

					            	}

					            	div+='</div>';

					            	jQuery(".fbpages").css("display","");

									jQuery(".fbpages").html(div);

									jQuery.blockUI({ message: jQuery('.fbpages'),css:{width:'auto'} }); 

					            	

									jQuery(".fbpages span").unbind('click');

					            	jQuery(".fbpages span").click(function(){

					            		var pagename=jQuery(this).text();



					            		

										

										jQuery.blockUI({ css: { 

											border: 'none', 

											padding: '15px', 

											backgroundColor: '#000', 

											'-webkit-border-radius': '10px', 

											'-moz-border-radius': '10px', 

											opacity: .5, 

											color: '#fff' 

										} });



										jQuery('.fbpages').css('display','none');

										

					            		jQuery.ajax({

														   		type: 'POST',

														        url: ajaxurl,

														        data:{action:'my_fetch_pages_authenticate', licensekey:jQuery("input[name=licensekey]").attr("value"), task:'getfbauthenticate',page:pagename,link:'<?php echo $row->social_post_press_link_url; ?>'}, 

														        success: function(data){

																	jQuery.unblockUI();

																	

														        	var obj = jQuery.parseJSON(data);

														        	if(obj.data.error==1){

														        		alert(obj.data.msg);

														        	}else{

														        		var secureid=obj.data.id;

														        		//alert('<?php echo $row->social_post_press_link_url; ?>&secureid='+secureid);

																		//alert(pagename);



																		// FB.ui({

																		//     method: 'stream.share',

																		//     u: '<?php echo $row->social_post_press_link_url; ?>&secureid='+secureid

																		//   }, 

																		//   function(response) { alert(response); }

																		//  );



														        		  FB.ui(

																		  {

																		   method: 'feed',

																		   name: '<?php echo addslashes($row->social_post_press_headline); ?>',

																		   caption: '',

																		   description: (''),

																		   link: '<?php echo $row->social_post_press_link_url; ?>&secureid='+secureid,

																		   to: pagename,

																		   from:pagename

																		  },

																		  function(response) {

console.log(response);

																		    if (response && response.post_id) {

																			

																				jQuery.blockUI({ css: { 

																					border: 'none', 

																					padding: '15px', 

																					backgroundColor: '#000', 

																					'-webkit-border-radius': '10px', 

																					'-moz-border-radius': '10px', 

																					opacity: .5, 

																						color: '#fff' 

																				} });

																			

																		      jQuery.ajax({

																			   		type: 'POST',

																			        url: ajaxurl,

																			        data:{action:'my_fetch_pages_postdata', licensekey:jQuery("input[name=licensekey]").attr("value"), task:'getfbauthenticate',page:pagename,object_id:response.post_id,token:token,secureid:secureid,

																			    		pid:'<?php echo $_GET["pid"]; ?>'}, 

																			        success: function(data){

																						jQuery.unblockUI();



																						jQuery(".fbpages").css("display","none");

																					

																			        	var obj = jQuery.parseJSON(data);

																			        	if(obj.data.error==1){

																			        		alert(obj.data.msg);

																			        	}else{

																			        		jQuery(".fbpages").css('display','none');

																			        		alert('Published successfully!');

																			        	}

																			        }

																			   });

																		    } else {

																		    	jQuery(".fbpages").css('display','none');

																		      alert('Post was not published.');

																		    }

																		  }

																		);

														        	}

														        }

														   });

					        //     			   FB.ui(

													//   {

													//    method: 'feed',

													//    name: '<?php echo $row->social_post_press_headline; ?>',

													//    caption: '<?php echo $row->social_post_press_subheadline; ?>',

													//    description: (''),

													//    link: '<?php echo $row->social_post_press_link_url; ?>'

													//   },

													//   function(response) {



													//     if (response && response.post_id) {

													//       jQuery.ajax({

													// 	   		type: 'POST',

													// 	        url: ajaxurl,

													// 	        data:{action:'my_fetch_pages_authenticate', licensekey:'c3c2620cbc237eeb494e6afbc0601bad', task:'getfbauthenticate',page:pagename,object_id:response.post_id,token:token}, 

													// 	        success: function(data){

													// 	        	var obj = jQuery.parseJSON(data);

													// 	        	if(obj.data.error==1){

													// 	        		alert(obj.data.msg);

													// 	        	}

													// 	        }

													// 	   });

													//     } else {

													//       alert('Post was not published.');

													//     }

													//   }

													// );

					            			



					            	});

						        }

						   });



						 //    FB.ui(

							//   {

							//    method: 'feed',

							//    name: '<?php echo $row->social_post_press_headline; ?>',

							//    caption: '<?php echo $row->social_post_press_subheadline; ?>',

							//    description: (''),

							//    link: '<?php echo $row->social_post_press_link_url; ?>'

							//   },

							//   function(response) {



							//     if (response && response.post_id) {

							//       alert('Post was published.');

							//     } else {

							//       alert('Post was not published.');

							//     }

							//   }

							// );

					  	} else if (response.status === 'not_authorized') {

						    // the user is logged in to Facebook, 

						    // but has not authenticated your app

						    alert('Not authorized');

						} else {

						    // the user isn't logged in to Facebook.

						    alert('Connect to facebook first.');

					  	}

 					});

				//handle_fb_user(response);

				});

			/*

			FB.logout(function(response) {

			console.log('Logged out.');

			});*/

			// });

			} else {

				// console.log('User cancelled login or did not fully authorize.');

				alert('User cancelled login or did not fully authorize.');

			}

		}, {scope: 'email,publish_actions,manage_pages,publish_stream, offline_access,read_stream'});

	}

	</script>

	<style type="text/css">

		.fbpages{

			width: 300px;

			min-height: 80px;

			max-height: 200px;

			overflow: auto;

			border: 1px solid #000000;

		}



		.fbpages .popupdiv div{

			padding: 5px;

			text-align: center;

			color: #ffffff;

			background-color: green;

			border-bottom:1px solid #ffffff;

		}



		.fbpages .popupdiv span{

			padding: 5px;

			text-align: center;

			color: #000000;

			cursor: pointer;

			background-color: #E4E4E4;

			border-bottom:1px solid gray;

			display: block;

		}

	</style>

	<div class="fbpages" style="display:none;"></div>

	<a href="#" onClick="fb_login()" style="float:left;" class="fb-login-spp">Fb Login</a>

	<a style="display: block;float: left;margin-left: 15px;overflow: hidden;padding-top: 12px;" href="<?php echo get_admin_url(); ?>/admin.php?page=social-post-press&task=extractemails">Export Emails</a>


	<div class="clear">&nbsp;</div>

<?php } 

	global $wpdb;

	$row16 = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."social_post_press_options WHERE type='licensekey'");

?>

<form method="post" action="" enctype="multipart/form-data">



<input type="hidden" name="licensekey" value="<?php echo $row16->value; ?>" /> 

	<table class="social-post-press">	

		<p><span class="steps">Step 1:</span><em>Enter App ID</em></p>	

		<tr style="display:none;">

			<th class="first" valign="top">Facebook Share URL</th>

			<td><input type="text" value="<?php echo site_url(); ?>/?postaction=socialpostpress&cid=<?php echo $_GET['pid']; ?>" name="social_post_press_link_url"/><?php echo $row->social_post_press_link_url; ?></td>

		</tr>

		<tr>

			<th class="first f1" valign="top">App ID</th>

			<td class="f1"><input type="hidden" name="social_post_press_fb_image_temp" value="<?php echo $row->social_post_press_fb_image; ?>" size="100"/><input type="text" name="social_post_press_app_id" value="<?php echo $row->social_post_press_app_id; ?>" size="100"/><br/><em>Enter Your Facebook App ID Here</em></td> 

		</tr>

	</table>

	<p><span class="steps">Step 2:</span><em>Facebook Post Icon</em></p>

	<table class="social-post-press">

		<tr>

			<th class="first f1" valign="top">Facebook Post Icon</th>

			<td class="f1"><input type="file" name="social_post_press_fb_icon" size="73"/><br/><em>Upload Your Facebook Post Icon Here. Images Size 200px x 200px</em></td>

		</tr>



		<!-- <tr>

			<th class="first f1" valign="top">Facebook Post Icon Dimensions</th>

			<td class="f1"><input type="text" value="<?php echo (strlen($row->social_post_press_posticonwidth)>0?$row->social_post_press_posticonwidth:'400'); ?>" name="social_post_press_posticonwidth" size="73"/>&nbsp;Width&nbsp;<input type="text" value="<?php echo (strlen($row->social_post_press_posticonheight)>0?$row->social_post_press_posticonheight:'240'); ?>" name="social_post_press_posticonheight" size="73"/>&nbsp;Height</td>

		</tr> -->



		

	</table>

	<script type="text/javascript">

		jQuery(document).ready(function(){

			jQuery("input[name=social_post_press_isbackground]").change(function(){

				if(jQuery(this).attr("checked")){

					jQuery(".bgimagepanel").css('display','');

				}else{

					jQuery(".bgimagepanel").css('display','none');

				}

			});

		});

	</script>

	<input type="hidden" value="arial" name="social_post_press_font_type"/>
	<input type="hidden" value="000000" name="social_post_press_font_color"/>

	

	<p><span class="steps">Step 3:</span><em>Enter App Details</em></p>

	<table class="social-post-press">



		



		<tr class="headingpanel">

			<th class="first f1" valign="top">Headline</th>

			<td class="f1"><input type="text" name="social_post_press_headline" value="<?php echo social_post_press_removeslashes($row->social_post_press_headline); ?>" maxlength="35" size="100"/><br/><em>Enter Your Headline Text Here</em></td>

		</tr>

		<tr class="headingpanel">

			<th class="first" valign="top">Sub Headline</th>

			<td><input type="text" name="social_post_press_sub_headline" value="<?php echo social_post_press_removeslashes($row->social_post_press_sub_headline); ?>" maxlength="45" size="100"/><br/><em>Enter Your Sub Headline Text Here</em></td>

		</tr>

	</table>

	<script type="text/javascript">

		jQuery(document).ready(function(){

			//jQuery("input[name=social_post_press_isheading]").change(function(){

				//if(jQuery(this).attr("checked")){

					//jQuery(".headingpanel").css('display','');

				//}else{

					//jQuery(".headingpanel").css('display','none');

				//}

			//});

		});

	</script>

	<table>

		<tr>

			<td align="left" height="50">

				Media Type:&nbsp; <input <?php echo (isset($row->social_post_press_mediatype)?(($row->social_post_press_mediatype=="video")?"checked='checked'":''):'checked=""'); ?> type="radio" name="social_post_press_mediatype" value="video" checked="checked"/> Video &nbsp;&nbsp;&nbsp;<input name="social_post_press_mediatype" <?php echo ($row->social_post_press_mediatype=="image"?'checked="checked"':''); ?> type="radio" value="image" /> Image

			</td>

		</tr>

	</table>

	<table class="social-post-press videocontainer" <?php echo (isset($row->social_post_press_mediatype)?(($row->social_post_press_mediatype=="video")?"":'style="display:none;"'):''); ?>>

		<tr>

			<td colspan="2">

				<p style="margin-left:-10px;"><span class="steps">Step 4:</span><em>Enter Youtube Video Key(ID)</em></p>

			</td>

		</tr>

		<tr>

			<th class="first f1" valign="top">Youtube Video Code</th>

			<td class="f1"><input type="text" name="social_post_press_youtube_video_code" size="100" value="<?php echo $row->social_post_press_youtube_video_code; ?>"/><br/><em>Enter Your Youtube Video Code: (eg. y1lynv9RFLI)</em></td>

		</tr>

		

		<input type="hidden" name="social_post_press_choose_autoplay_option" value="yes" />







	</table>

	<table class="social-post-press imagecontainer" <?php echo (isset($row->social_post_press_mediatype)?(($row->social_post_press_mediatype=="image")?"":'style="display:none;"'):'style="display:none;"'); ?>>

		<tr>

			<td colspan="2" align="left" style="border:none;"><p style="margin-left:-10px;"><span class="steps">Step 4:</span><em>Upload Post Image.</em></p></td>

		</tr>

		<tr>

			<th class="first f1" valign="top">Facebook Post Image</th>

			<td class="f1"><input type="file" name="social_post_press_fb_image" size="73"/><br/><em>Upload Your Facebook Post Image.</em></td>

		</tr>



		<tr>

			<th class="first f1" valign="top">Facebook Post Image Dimensions</th>

			<td class="f1"><input type="text" value="<?php echo (strlen($row->social_post_press_postimagewidth)>0?$row->social_post_press_postimagewidth:'395'); ?>" name="social_post_press_postimagewidth" size="73"/>&nbsp;Width&nbsp;<input type="text" value="<?php echo (strlen($row->social_post_press_postimageheight)>0?$row->social_post_press_postimageheight:'195'); ?>" name="social_post_press_postimageheight" size="73"/>&nbsp;Height</td>

		</tr>

	</table>

	<table>

		<tr>

			<th class="first f1" width="86" align="left" valign="top" style="border:0px;">Email Gate:</th>

			<td align="left" valign="top">

				

				<input type="checkbox" name="social_post_press_emailgate" <?php echo (strlen($row->social_post_press_emailgate)>0)?($row->social_post_press_emailgate=="yes"?'checked="checked"':''):''; ?> value="yes"/> (Will work as a gate when enabled.)

			</td>

		</tr>

		<tr class="emailgateredirect" <?php echo (strlen($row->social_post_press_emailgate)>0?($row->social_post_press_emailgate=="yes"?'':'style="display:none;"'):'style="display:none;"'); ?>>

			<th class="first f1" valign="top" align="left" style="border:0px;">Redirect URL:</th>

			<td align="left" valign="top">

				<input type="text" name="social_post_press_emailgateredirect" size="50" placeholder="" value="<?php echo (strlen($row->social_post_press_emailgateredirect)>0)?$row->social_post_press_emailgateredirect:''; ?>" /> (Only works if email gate and optin form option selected.)  

			</td>

		</tr>

	</table>

	<table>

		<tr>

			<td align="left" height="50">

				Navigation Type:&nbsp; <input <?php echo (isset($row->social_post_press_navigationtype)?(($row->social_post_press_navigationtype=="optinform")?"checked='checked'":''):'checked=""'); ?> type="radio" name="social_post_press_navigationtype" value="optinform" checked="checked"/> Optin form &nbsp;&nbsp;&nbsp;<input name="social_post_press_navigationtype" <?php echo ($row->social_post_press_navigationtype=="simplebtn"?'checked="checked"':''); ?> type="radio" value="simplebtn" /> Redirect Button

			</td>

		</tr>

	</table>

	<table class="social-post-press optinformpanel" <?php echo (isset($row->social_post_press_navigationtype)?($row->social_post_press_navigationtype=="optinform"?'':'style="display:none;"'):''); ?>>

		<p class="optinformpanel" <?php echo (isset($row->social_post_press_navigationtype)?($row->social_post_press_navigationtype=="optinform"?'':'style="display:none;"'):''); ?>><span class="steps ">Step 5:</span><em>Enter/Paste Optin Form Code Here</em></p>







		<tr>

			<th class="first f1" valign="top">Optin Form Code</th>

			<td class="f1"><textarea name="social_post_press_optin_code" cols="97" rows="12"><?php echo social_post_press_removeslashes($row->social_post_press_optin_code); ?></textarea><br/><em>Enter Your Optin Form Code Here</em></td>

		</tr>



		<tr>

			<th class="first f1" valign="top">Placeholder Text:</th>

			<td align="left" height="50">



				<input type="text" name="social_post_press_placeholdertext" size="50" value="<?php echo (strlen($row->social_post_press_placeholdertext)>0)?$row->social_post_press_placeholdertext:'Enter Your Email Here'; ?>" /> (By default text for input box)  

			</td>

		</tr>

		<tr>

			<th class="first f1" valign="top">Placeholder Text:</th>

			<td align="left" height="50">



				<input type="text" name="social_post_press_placeholdernametext" size="50" value="<?php echo (strlen($row->social_post_press_placeholdernametext)>0)?$row->social_post_press_placeholdernametext:'Enter Your Name Here'; ?>" /> (By default text for input box)  

			</td>

		</tr>



		<tr>

			<th class="first f1" valign="top">Delay in Display(Seconds):</th>

			<td align="left" height="50">



				<input type="text" name="social_post_press_awberdelaydisplay" size="50" value="<?php echo (strlen($row->social_post_press_awberdelaydisplay)>0)?$row->social_post_press_awberdelaydisplay:'0'; ?>" maxlength="4"/> (Set value 0 to disable delay time)

			</td>

		</tr>

	</table>



	



	<table class="social-post-press redirectbtnpanel" <?php echo (isset($row->social_post_press_navigationtype)?($row->social_post_press_navigationtype=="simplebtn"?'':'style="display:none;"'):'style="display:none;"'); ?>>

		<p <?php echo (isset($row->social_post_press_navigationtype)?($row->social_post_press_navigationtype=="simplebtn"?'':'style="display:none;"'):'style="display:none;"'); ?> class="redirectbtnpanel"><span class="steps">Step 5:</span><em>Set Redirect Button</em></p>

		<!-- <tr>

			<th class="first f1" valign="top">Button Title</th>

			<td class="f1"><input type="text" placeholder="Button Title" name="social_post_press_redirect_btn_title" size="100" value="<?php echo $row->social_post_press_redirect_btn_title; ?>"/></td>

		</tr> -->



		<tr>

			<th class="first f1" valign="top">Redirect URL</th>

			<td class="f1"><input type="text" placeholder="Redirect URL" name="social_post_press_redirect_url" size="100" value="<?php echo $row->social_post_press_redirect_url; ?>"/></td>

		</tr>

		<tr>

			<th class="first f1" valign="top">Delay in Display(Seconds):</th>

			<td align="left" height="50">



				<input type="text" name="social_post_press_redirectdelaydisplay" size="50" value="<?php echo (strlen($row->social_post_press_redirectdelaydisplay)>0)?$row->social_post_press_redirectdelaydisplay:'0'; ?>" maxlength="4"/> (Set value 0 to disable delay time)

			</td>

		</tr>

	</table>



	<script type="text/javascript">

		jQuery(document).ready(function(){

			jQuery('input[name=social_post_press_navigationtype]').change(function(){

				if(jQuery(this).attr("value")=="optinform"){

					jQuery(".redirectbtnpanel").css('display','none');

					jQuery(".optinformpanel").css('display','');

				}else{

					jQuery(".redirectbtnpanel").css('display','');

					jQuery(".optinformpanel").css('display','none');

				}

			});

			jQuery('input[name=social_post_press_emailgate]').change(function(){

				if(jQuery(this).attr("checked")){
					jQuery(".emailgateredirect").css('display','');
				}else{
					jQuery(".emailgateredirect").css('display','none');
				}
			});

		});

	</script>



	<table class="social-post-press">

		<p><span class="steps">Step 6:</span><em>Enter Your Link Button Text & Set Link Button Image</em></p>

		<tr>

			<th class="first f1" valign="top">Link Button</th>

			<td class="f1"><input type="text" size="100" name="social_post_press_link_button" value="<?php echo $row->social_post_press_link_button; ?>"/><br/><em>Enter Your Link Button Text Here</em></td>

		</tr>

		<tr>

			<th class="first" valign="top">Link Button Image</th>

			<td><?php

					$buttons=array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22');

					for($i=0;$i<count($buttons);$i++){

				?>

					<?php 

						$img = spp_plugins_url().'images/buttons/'.$buttons[$i].'.png'; 

					?>

					<span><input <?php if ($row->buttontype == $img){ echo 'checked=checked'; } ?> style="margin-top:-6px;" type="radio" name="buttontype" value="<?php echo $buttons[$i]; ?>"> <img width="161" src="<?php echo spp_plugins_url(); ?>images/buttons/<?php echo $buttons[$i]; ?>.png" /></span>   

							

				<?php } ?><br/><em>Choose Your Link Button Image Here</em>

			</td>

		</tr>

	</table>

	<input type="hidden" name="action" value="update" />

	<input type="submit" name="sbmt" value="Submit" class="button-primary" /> &nbsp;&nbsp; <input type="reset" name="reset" value="Reset" class="button-primary" />

</form>

<?php }



function myplugin_admin_footer2(){ 

	global $wpdb; $table_name = $wpdb->prefix . "social_post_press";?>

	<script type="text/javascript">

		jQuery(document).ready(function(){

			jQuery('.delete').click(function(){ 

			  	var link=jQuery(this);

			   	jQuery.ajax({

			   		type: 'POST',

			        url: ajaxurl,

			        data:{action:'my_custom_action', task:'co', del:jQuery(this).attr("data-id")}, 

			        success: function(){

		            	link.parent().parent().fadeOut('slow', function() {

						    jQuery(this).remove();

						});

			        }

			   });

			});

			jQuery("#addnew").click(function(){

				jQuery("#addnew").parents().find(".addnew").removeClass("hide");

				jQuery("#addnew").parents().find(".addnew").addClass("show");

			});





			jQuery("input[name=social_post_press_mediatype]").change(function(){

				if(jQuery(this).val()=="image"){

					jQuery(".imagecontainer").css('display','');

					jQuery(".videocontainer").css('display','none');

				}else{

					jQuery(".imagecontainer").css('display','none');

					jQuery(".videocontainer").css('display','');

				}

			});

		});

	</script>

<?php }



//ajax

add_action('wp_ajax_my_custom_action', 'my_action_callback2');

add_action('wp_ajax_nopriv_my_custom_action', 'my_action_callback2');

add_action('wp_ajax_my_fetch_pages', 'my_fetch_pages');

add_action('wp_ajax_nopriv_my_fetch_pages', 'my_fetch_pages');

add_action('wp_ajax_my_fetch_pages_authenticate', 'my_fetch_pages_authenticate');

add_action('wp_ajax_nopriv_my_fetch_pages_authenticate', 'my_fetch_pages_authenticate');

add_action('wp_ajax_my_fetch_pages_postdata', 'my_fetch_pages_postdata');

add_action('wp_ajax_nopriv_my_fetch_pages_postdata', 'my_fetch_pages_postdata');









require_once('helper.php');







function my_action_callback2() {

	global $wpdb; // this is how you get access to the database 



	$table_name = $wpdb->prefix . "social_post_press";



	if($_POST['task'] == 'co'){	

		$wpdb->query(

			"DELETE FROM $table_name WHERE id = ".$_POST['del']

		);

	}

	die();

}







function handle_flash_player2(){

	if(isset($_GET['postaction']) && $_GET['postaction'] == 'servejson'){

		$cid = (int)$_GET['cid'];

		global $wpdb;

		$table_name = $wpdb->prefix . "social_post_press";	

		if($cid <= 0 ){

			echo json_encode(array('error' => 'No App found'));

		}else{

			$query = sprintf('select * from '.$table_name.' where id = %d',$cid);

			$result = $wpdb->get_results($query);

			$result[0]->social_post_press_optin_form = unserialize($result[0]->social_post_press_optin_form);

			if($result[0]->social_post_press_upload_bg_img != ''){ 

				$result[0]->social_post_press_background_img = $result[0]->social_post_press_upload_bg_img;

			}else{

				$result[0]->social_post_press_background_img = $result[0]->social_post_press_background_img;

			}

			echo json_encode(array('data'=>$result)); 

		}

		die;

	}



	if(isset($_GET['postaction']) && $_GET['postaction'] == 'loadcrossdomain'){

		header('Content-type: text/xml');

		echo '<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd"><cross-domain-policy><site-control permitted-cross-domain-policies="all"/><allow-access-from domain="*" to-ports="*" /><allow-http-request-headers-from domain="*" headers="*"/></cross-domain-policy>';

		die;

	}



	if(isset($_GET['postaction']) && $_GET['postaction'] == 'socialpostpress'){

		require_once('aweberdisplay.php'); 

		die;

	}



	if(isset($_GET['postaction']) && $_GET['postaction'] == 'socialpostpressformsubmit'){

		require_once('formsubmit.php'); 

		die;

	}



	if(isset($_GET['postaction']) && $_GET['postaction'] == 'socialpostpressformsubmit1'){

		require_once('formsubmit1.php'); 

		die;

	}



	if(isset($_GET['postaction']) && $_GET['postaction'] == 'socialpostpresstrackvisitor'){

		//print_r($_POST);

		global $wpdb;

		$table_name2 = $wpdb->prefix . "fb_visitor_track";

		//var_dump($table_name2);

		//$ip = getip();

    	$default_values = array('cid' => $_POST['cid'], 'ip' =>$_POST['ip']);



	    if(isset($_POST['cid'])){

	    	$wpdb->insert( $table_name2, $default_values);	

	    }

		die;

	}

}



function getip() {

$ip;

if (getenv("HTTP_CLIENT_IP"))

$ip = getenv("HTTP_CLIENT_IP");

else if(getenv("HTTP_X_FORWARDED_FOR"))

$ip = getenv("HTTP_X_FORWARDED_FOR");

else if(getenv("REMOTE_ADDR"))

$ip = getenv("REMOTE_ADDR");

else

$ip = "UNKNOWN";

return $ip;



} 



add_action('template_redirect','handle_flash_player2',1);



function extract_input_fields($embed_code){

	preg_match_all("#<input.*?.*?>#",$embed_code,$matches);

	$form = array();

	$count = 0;

	$trim_char_list = '\',",<,>';

	foreach($matches[0] as $inputs){

		$tmp = explode(" ",$inputs);

		foreach($tmp as $key=>$value){

			$pos = strpos($value,'name');

			if($pos === false)

			{

				$pos2 = strpos($value,'value');	

				if($pos2 !== false)

				{

					$val2 = explode("=",$value);

					$form[$count][$val2[0]] = trim(social_post_press_removeslashes($val2[1]),$trim_char_list);

				}



				$pos2 = strpos($value,'type');	

				if($pos2 !== false)

				{

					$val2 = explode("=",$value);

					$form[$count][$val2[0]] = trim($val2[1],$trim_char_list);

				}

			}

			else{



				$val = explode("=",$value);

				$form[$count][$val[0]] = trim($val[1],$trim_char_list);

			}

		}

		$count++;

	}



	if(strlen($embed_code)>0){

		$html=new DOMDocument();

		$html->loadHTML($embed_code);

		$els=$html->getelementsbytagname('form');

		$action='';

		foreach($els as $inp){

			$action=$inp->getAttribute('action');

		}

		$form[$count] = array('name'=>'formaction','type'=>'action','value'=>$action);

	}else{

		$form='';

	}

	return $form;

}

if((isset($_GET['page'])) && ($_GET['page']=="social-post-press") && ($_GET['task']=="extractemails")){
	global $wpdb;
	$query="select * from ".$wpdb->prefix."social_post_press_emaildatabase";
	$result=$wpdb->get_results($query);
	header("Content-type: application/csv");
	header("Content-Disposition: attachment; filename=file.csv");
	header("Pragma: no-cache");
	header("Expires: 0");

	ini_set('display_errors',1);
	$private=1;
	error_reporting(E_ALL ^ E_NOTICE);

	$output='';
		$output.="Email ID's,";
	echo    $output.="\n";

	for($i=0;$i<count($result);$i++){
		$output='';
		$output.="{$result[$i]->email},";
	    $output.="\n";
	    echo $output;
	}
	die;
}