<?php

$pageUR1 = preg_replace("/\\/(.+)/", "", $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
$curdomain = str_replace("www.", "", $pageUR1);
if (strpos($_SERVER['HTTP_REFERER'], $curdomain)) {
    error_reporting(E_ALL ^ E_NOTICE);
    $post = !empty($_POST) ? true : false;
    if ($post) {
        if (!function_exists('add_action')) {
            require_once "../../../wp-config.php";
        }
        $news_user = get_option('newsletter_user');
        $news_pass = get_option('newsletter_pass');
        $apikey = get_option('newsletter_apikey');
        require_once "GAPI.class.php";
        $news_con = new GAPI($news_user, $news_pass);
        $news_fname = NULL;
        if ($_POST['id_first_name']) {
            $news_fname = stripslashes($_POST['id_first_name']);
        }
        $news_lname = NULL;
        if ($_POST['id_last_name']) {
            $news_lname = stripslashes($_POST['id_last_name']);
        }
        $news_confirm = False;
        if ($_POST['confirm'] == "on") {
            $news_confirm = True;
        }
        $response = array('status' => 'ok', 'message' => null);
        if ($news_con->subscription_add($_POST['id_email'], $_POST['newsletter'], utf8_encode($news_fname), utf8_encode($news_lname), $news_confirm, $apikey)) {
            if ($news_confirm == True && get_option('newsletter_msg_confirm')) {
    /** @see WP_Widget::form */
    function form($instance)
    {
        $news_pass = get_option('newsletter_pass');
        if ($news_pass) {
            $news_con = new GAPI('', $news_pass);
            if ($news_con->check_login()) {
                $title = esc_attr($instance['title']);
                $newskey = esc_attr($instance['newskey']);
                $fname = esc_attr($instance['fname']);
                $fnametxt = esc_attr($instance['fnametxt']);
                $lname = esc_attr($instance['lname']);
                $lnametxt = esc_attr($instance['lnametxt']);
                $submittext = esc_attr($instance['submittext']);
                ?>
				<p>
					<label for="<?php 
                echo $this->get_field_id('title');
                ?>
"><?php 
                _e('Title:');
                ?>
</label>
					<input class="widefat" id="<?php 
                echo $this->get_field_id('title');
                ?>
" name="<?php 
                echo $this->get_field_name('title');
                ?>
" type="text" value="<?php 
                echo $title;
                ?>
" />
				</p>
				<p>
					<label for="<?php 
                echo $this->get_field_id('newskey');
                ?>
"><?php 
                _e('Newsletter:');
                ?>
</label>
					<?php 
                if ($news_con->newsletters_show()) {
                    echo '<select class="widefat" id=' . $this->get_field_id("newskey") . ' name="' . $this->get_field_name("newskey") . '">';
                    foreach ($news_con->result as $newsitem) {
                        $selected_list = "";
                        if ($newskey == $newsitem["list_id"]) {
                            $selected_list = 'selected="selected"';
                        }
                        echo '<option ' . $selected_list . ' value="' . $newsitem["list_id"] . '">' . $newsitem["newsletter"] . '</option>';
                    }
                    echo '</select>';
                } else {
                    print $news_con->show_errors();
                }
                ?>
				</p>
				<p>
					<input class="checkbox" id="<?php 
                echo $this->get_field_id('fname');
                ?>
" name="<?php 
                echo $this->get_field_name('fname');
                ?>
" type="checkbox" <?php 
                if ($fname) {
                    echo 'checked="checked"';
                }
                ?>
 />
					<label for="<?php 
                echo $this->get_field_id('fname');
                ?>
"><?php 
                _e('Ask for First Name?<br>Label for First Name:');
                ?>
</label>
					<input size="15" id="<?php 
                echo $this->get_field_id('fnametxt');
                ?>
" name="<?php 
                echo $this->get_field_name('fnametxt');
                ?>
" type="text" value="<?php 
                echo $fnametxt;
                ?>
" />
				</p>
				<p>
					<input class="checkbox" id="<?php 
                echo $this->get_field_id('lname');
                ?>
" name="<?php 
                echo $this->get_field_name('lname');
                ?>
" type="checkbox" <?php 
                if ($lname) {
                    echo 'checked="checked"';
                }
                ?>
 />
					<label for="<?php 
                echo $this->get_field_id('lname');
                ?>
"><?php 
                _e('Ask for Last Name?<br>Label for Last Name:');
                ?>
</label>
					<input size="15" id="<?php 
                echo $this->get_field_id('lnametxt');
                ?>
" name="<?php 
                echo $this->get_field_name('lnametxt');
                ?>
" type="text" value="<?php 
                echo $lnametxt;
                ?>
" />
				</p>
				<p>
					<label for="<?php 
                echo $this->get_field_id('submittext');
                ?>
"><?php 
                _e('Submit button text:');
                ?>
</label>
					<input class="widefat" id="<?php 
                echo $this->get_field_id('submittext');
                ?>
" name="<?php 
                echo $this->get_field_name('submittext');
                ?>
" type="text" value="<?php 
                echo $submittext;
                ?>
" />
				</p>
				<?php 
            } else {
                echo '<p>Wrong Login details. Enter correct details in Get a Newsletter options page.</p>';
            }
        } else {
            echo '<p>Enter required details in Get a Newsletter options page.</p>';
        }
    }