<?php
/**
 * Filename: _widgets.php
 * Created by: BlogProfitNetwork.Com <marcus@blogprofitnetwork.com> (https://BlogProfitNetwork.Com)
 * Copyright:2018 All Rights Reserved - BlogProfitNetwork.Com <marcus@blogprofitnetwork.com> (https://BlogProfitNetwork.Com)
 *
 * Skype: blogprofitnetwork
 * Email: marcus@blogprofitnetwork.com
 * GTalk: marcus@blogprofitnetwork.com
 */
defined('_IN_MAIN_MODULE') or die ('ACCESS DENIED');

class funnelVoodooWidgets extends WP_Widget {
	var $db;

	function init() {
		register_widget('funnelVoodooWidgets');
	}

	function __construct() {
		global $funnelVoodooDatabase;

		$this->db = $funnelVoodooDatabase;

		$options = array(
			'classname'     => 'funnelVoodooWidgets',
			'description'   => FUNNELVOODOO_NAME .' is an awesome widget'
		);

		$controls = array(
			'width'     => 350,
			'height'    => 350,
			'id_base'   => FUNNELVOODOO_CODE .'-widgets'
		);

		parent::__construct(FUNNELVOODOO_CODE .'-widgets', FUNNELVOODOO_NAME, $options, $controls);
	}

	function update($new, $old) {
		$instance = array();
		return $instance;
	}

	function form($instance) {
		echo '<p>Please <a href="'. admin_url('admin.php?page='. FUNNELVOODOO_CODE) .'">click me</a> to go to the configuration area of this widget.</p>';
	}

	function widget($args, $instance) {
		$this->widgetForOptin($args);
		$this->widgetForAffiliate($args);
		$this->widgetForAdsense($args);
		$this->widgetForThankyou($args);
		$this->widgetForSales($args);
		$this->widgetForRecentComments($args);
		$this->widgetForRecentPost($args);
	}

	//* recent posts
	function widgetForRecentPost($args) {
		global $post;

		$postid = $post->ID;
		$count	= FUNNELVOODOO_DEFAULT_COUNT_RECENTPOSTS;

		for ($i = 1; $i <= $count; $i++) {
			$recentposts = get_option($this->db->tableRecentPosts .'_'. $i);
			if ($recentposts['enable'] == FUNNELVOODOO_ENABLED) {
				$sidebar 		= $recentposts['sidebar'];

//				$homepage       = $sidebar['homepage'];
//				$pages          = $sidebar['pages'];
////				$pagesid        = trim(str_replace(', ', ',', $sidebar['pagesid']));
////				$nopagesid      = trim(str_replace(', ', ',', $sidebar['nopagesid']));
//                $pagesid        = trim(str_replace(' ', '', $sidebar['pagesid']));
//                $nopagesid        = trim(str_replace(' ', '', $sidebar['nopagesid']));
//				$posts          = $sidebar['posts'];
////                $pagesid        = trim(str_replace(' ', '', $sidebar['pagesid']));
////                $nopagesid        = trim(str_replace(' ', '', $sidebar['nopagesid']));
//                $pagesid        = trim(str_replace(' ', '', $sidebar['pagesid']));
//                $nopagesid        = trim(str_replace(' ', '', $sidebar['nopagesid']));

                $homepage           = $sidebar['homepage'];
                $pages              = $sidebar['pages'];
                $pagesid            = trim(str_replace(' ', '', $sidebar['pagesid']));
                $nopagesid          = trim(str_replace(' ', '', $sidebar['nopagesid']));
                $posts              = $sidebar['posts'];
                $postsid            = trim(str_replace(' ', '', $sidebar['postsid']));
                $nopostsid          = trim(str_replace(' ', '', $sidebar['nopostsid']));


				//* homepage, sticky post, frontpage
				if (is_home() || is_sticky() || is_front_page()) {
					if ($homepage == FUNNELVOODOO_ENABLED) {
						$this->codeForRecentPosts($args, $recentposts);
					}
				}

				//* pages
				if (is_page()) {
					if ($pages == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopagesid)) {
							$explodedNoPagesId = explode(',', $nopagesid);
							if (!in_array($post->ID, $explodedNoPagesId)) {
								if (0 != strlen($pagesid)) {
									$explodePagesId = explode(',', $pagesid);
									if (in_array($post->ID, $explodePagesId)) {
										$this->codeForRecentPosts($args, $recentposts);
									}
								}
								else {
									$this->codeForRecentPosts($args, $recentposts);
								}
							}
						}
						else {
							if (0 != strlen($pagesid)) {
								$explodePagesId = explode(',', trim(str_replace(', ', ',', $pagesid)));
								if (in_array($post->ID, $explodePagesId)) {
									$this->codeForRecentPosts($args, $recentposts);
								}
							}
							else {
								$this->codeForRecentPosts($args, $recentposts);
							}
						}
					}
				}

				//* single
				if (is_single()) {
					echo 'recent posts';
					if ($posts == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopostsid)) {
							$explodedNoPostsId = explode(',', $nopostsid);
							if (in_array($post->ID, $explodedNoPostsId)) {
								if (0 != strlen($postsid)) {
									$explodePostsId = explode(',', $postsid);
									if (in_array($post->ID, $explodePostsId)) {
										$this->codeForRecentPosts($args, $recentposts);
									}
								}
								else {
									$this->codeForRecentPosts($args, $recentposts);
								}
							}
						}
						else {
							if (0 != strlen($postsid)) {
								$explodePostsId = explode(',', trim(str_replace(', ', ',', $postsid)));
								if (in_array($post->ID, $explodePostsId)) {
									$this->codeForRecentPosts($args, $recentposts);
								}
							}
							else {
								$this->codeForRecentPosts($args, $recentposts);
							}
						}
					}
				}
			}
		}
	}

		function codeForRecentPosts($args, $data) {
			extract ($args);

			echo $before_widget;
				echo $before_title;
					echo ($data['title_hide'] == FUNNELVOODOO_DISABLED) ? $data['title'] : '';
				echo $after_title;

				echo (0 != strlen($data['contents'])) ? str_replace('\\', '', $data['contents']) : '';

				if (0 != strlen($data['how_many'])) {
					query_posts('showposts='. $data['how_many']);
					if (have_posts()) {
						echo '<ul>';
							while (have_posts()) : the_post();
								?>

								<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

								<?php
							endwhile;
						echo '</ul>';
					}
				}

			echo $after_widget;
			wp_reset_query();
		}

	//* recent comments
	function widgetForRecentComments($args) {
		global $post;

		$postid = $post->ID;
		$count	= FUNNELVOODOO_DEFAULT_COUNT_RECENTCOMMENTS;

		for ($i = 1; $i <= $count; $i++) {
			$recentcomments = get_option($this->db->tableRecentComments .'_'. $i);
			if ($recentcomments['enable'] == FUNNELVOODOO_ENABLED) {
				$sidebar 		= $recentcomments['sidebar'];

				$homepage       = $sidebar['homepage'];
				$pages          = $sidebar['pages'];
				$pagesid        = trim(str_replace(', ', ',', $sidebar['pagesid']));
				$nopagesid      = trim(str_replace(', ', ',', $sidebar['nopagesid']));
				$posts          = $sidebar['posts'];
				$postsid        = trim(str_replace(', ', ',', $sidebar['postsid']));
				$nopostsid		= trim(str_replace(', ', ',', $sidebar['nopostsid']));

				//* homepage, sticky post, frontpage
				if (is_home() || is_sticky() || is_front_page()) {
					if ($homepage == FUNNELVOODOO_ENABLED) {
						$this->codeForRecentComments($args, $recentcomments);
					}
				}

				//* pages
				if (is_page()) {
					if ($pages == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopagesid)) {
							$explodedNoPagesId = explode(',', $nopagesid);
							if (!in_array($post->ID, $explodedNoPagesId)) {
								if (0 != strlen($pagesid)) {
									$explodePagesId = explode(',', $pagesid);
									if (in_array($post->ID, $explodePagesId)) {
										$this->codeForRecentComments($args, $recentcomments);
									}
								}
								else {
									$this->codeForRecentComments($args, $recentcomments);
								}
							}
						}
						else {
							if (0 != strlen($pagesid)) {
								$explodePagesId = explode(',', trim(str_replace(', ', ',', $pagesid)));
								if (in_array($post->ID, $explodePagesId)) {
									$this->codeForRecentComments($args, $recentcomments);
								}
							}
							else {
								$this->codeForRecentComments($args, $recentcomments);
							}
						}
					}
				}

				//* single
				if (is_single()) {
					if ($posts == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopostsid)) {
							$explodedNoPostsId = explode(',', $nopostsid);
							if (!in_array($post->ID, $explodedNoPostsId)) {
								if (0 != strlen($postsid)) {
									$explodePostsId = explode(',', $postsid);
									if (in_array($post->ID, $explodePostsId)) {
										$this->codeForRecentComments($args, $recentcomments);
									}
								}
								else {
									$this->codeForRecentComments($args, $recentcomments);
								}
							}
						}
						else {
							if (0 != strlen($postsid)) {
								$explodePostsId = explode(',', trim(str_replace(', ', ',', $postsid)));
								if (in_array($post->ID, $explodePostsId)) {
									$this->codeForRecentComments($args, $recentcomments);
								}
							}
							else {
								$this->codeForRecentComments($args, $recentcomments);
							}
						}
					}
				}
			}
		}
	}

		function codeForRecentComments($args, $data) {
			extract ($args);

			echo $before_widget;
				echo $before_title;
					echo ($data['title_hide'] == FUNNELVOODOO_DISABLED) ? $data['title'] : '';
				echo $after_title;

				echo (0 != strlen($data['contents'])) ? str_replace('\\', '', $data['contents']) : '';

				if (0 != strlen($data['how_many'])) {
					$q = array(
						'status'    => 'approve',
						'number'    => $data['how_many']
					);
					$comments = get_comments($q);

					echo '<ul>';
						foreach ($comments as $comment) {
							echo '<li>' . $comment->comment_author .' on <a href="'. get_comment_link($comment->comment_ID) .'" title="' . comment_excerpt() .'">' . get_the_title($comment->comment_post_ID) . '</a></li>';
						}
					echo '</ul>';
				}

			echo $after_widget;
			wp_reset_query();
		}

	//* sales
	function widgetForSales($args) {
		global $post;

		$postid = $post->ID;
		$count	= FUNNELVOODOO_DEFAULT_COUNT_SALES;

		for ($i = 1; $i <= $count; $i++) {
			$sales = get_option($this->db->tableSales .'_'. $i);
			if ($sales['enable'] == FUNNELVOODOO_ENABLED) {
				$sidebar 		= $sales['sidebar'];

				$homepage       = $sidebar['homepage'];
				$pages          = $sidebar['pages'];
				$pagesid        = trim(str_replace(', ', ',', $sidebar['pagesid']));
				$nopagesid      = trim(str_replace(', ', ',', $sidebar['nopagesid']));
				$posts          = $sidebar['posts'];
				$postsid        = trim(str_replace(', ', ',', $sidebar['postsid']));
				$nopostsid		= trim(str_replace(', ', ',', $sidebar['nopostsid']));

				//* homepage, sticky post, frontpage
				if (is_home() || is_sticky() || is_front_page()) {
					if ($homepage == FUNNELVOODOO_ENABLED) {
						$this->codeForAffiliateAdsenseThankyouSales($args, $sales);
					}
				}

				//* pages
				if (is_page()) {
					if ($pages == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopagesid)) {
							$explodedNoPagesId = explode(',', $nopagesid);
							if (!in_array($post->ID, $explodedNoPagesId)) {
								if (0 != strlen($pagesid)) {
									$explodePagesId = explode(',', $pagesid);
									if (in_array($post->ID, $explodePagesId)) {
										$this->codeForAffiliateAdsenseThankyouSales($args, $sales);
									}
								}
								else {
									$this->codeForAffiliateAdsenseThankyouSales($args, $sales);
								}
							}
						}
						else {
							if (0 != strlen($pagesid)) {
								$explodePagesId = explode(',', trim(str_replace(', ', ',', $pagesid)));
								if (in_array($post->ID, $explodePagesId)) {
									$this->codeForAffiliateAdsenseThankyouSales($args, $sales);
								}
							}
							else {
								$this->codeForAffiliateAdsenseThankyouSales($args, $sales);
							}
						}
					}
				}

				//* single
				if (is_single()) {
					if ($posts == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopostsid)) {
							$explodedNoPostsId = explode(',', $nopostsid);
							if (!in_array($post->ID, $explodedNoPostsId)) {
								if (0 != strlen($postsid)) {
									$explodePostsId = explode(',', $postsid);
									if (in_array($post->ID, $explodePostsId)) {
										$this->codeForAffiliateAdsenseThankyouSales($args, $sales);
									}
								}
								else {
									$this->codeForAffiliateAdsenseThankyouSales($args, $sales);
								}
							}
						}
						else {
							if (0 != strlen($postsid)) {
								$explodePostsId = explode(',', trim(str_replace(', ', ',', $postsid)));
								if (in_array($post->ID, $explodePostsId)) {
									$this->codeForAffiliateAdsenseThankyouSales($args, $sales);
								}
							}
							else {
								$this->codeForAffiliateAdsenseThankyouSales($args, $sales);
							}
						}
					}
				}
			}
		}
	}

	//* thankyous
	function widgetForThankyou($args) {
		global $post;

		$postid = $post->ID;
		$count	= FUNNELVOODOO_DEFAULT_COUNT_THANKYOUS;

		for ($i = 1; $i <= $count; $i++) {
			$thankyous = get_option($this->db->tableThankyous .'_'. $i);
			if ($thankyous['enable'] == FUNNELVOODOO_ENABLED) {
				$sidebar 		= $thankyous['sidebar'];

				$homepage       = $sidebar['homepage'];
				$pages          = $sidebar['pages'];
				$pagesid        = trim(str_replace(', ', ',', $sidebar['pagesid']));
				$nopagesid      = trim(str_replace(', ', ',', $sidebar['nopagesid']));
				$posts          = $sidebar['posts'];
				$postsid        = trim(str_replace(', ', ',', $sidebar['postsid']));
				$nopostsid		= trim(str_replace(', ', ',', $sidebar['nopostsid']));

				//* homepage, sticky post, frontpage
				if (is_home() || is_sticky() || is_front_page()) {
					if ($homepage == FUNNELVOODOO_ENABLED) {
						$this->codeForAffiliateAdsenseThankyouSales($args, $thankyous);
					}
				}

				//* pages
				if (is_page()) {
					if ($pages == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopagesid)) {
							$explodedNoPagesId = explode(',', $nopagesid);
							if (!in_array($post->ID, $explodedNoPagesId)) {
								if (0 != strlen($pagesid)) {
									$explodePagesId = explode(',', $pagesid);
									if (in_array($post->ID, $explodePagesId)) {
										$this->codeForAffiliateAdsenseThankyouSales($args, $thankyous);
									}
								}
								else {
									$this->codeForAffiliateAdsenseThankyouSales($args, $thankyous);
								}
							}
						}
						else {
							if (0 != strlen($pagesid)) {
								$explodePagesId = explode(',', trim(str_replace(', ', ',', $pagesid)));
								if (in_array($post->ID, $explodePagesId)) {
									$this->codeForAffiliateAdsenseThankyouSales($args, $thankyous);
								}
							}
							else {
								$this->codeForAffiliateAdsenseThankyouSales($args, $thankyous);
							}
						}
					}
				}

				//* single
				if (is_single()) {
					if ($posts == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopostsid)) {
							$explodedNoPostsId = explode(',', $nopostsid);
							if (!in_array($post->ID, $explodedNoPostsId)) {
								if (0 != strlen($postsid)) {
									$explodePostsId = explode(',', $postsid);
									if (in_array($post->ID, $explodePostsId)) {
										$this->codeForAffiliateAdsenseThankyouSales($args, $thankyous);
									}
								}
								else {
									$this->codeForAffiliateAdsenseThankyouSales($args, $thankyous);
								}
							}
						}
						else {
							if (0 != strlen($postsid)) {
								$explodePostsId = explode(',', trim(str_replace(', ', ',', $postsid)));
								if (in_array($post->ID, $explodePostsId)) {
									$this->codeForAffiliateAdsenseThankyouSales($args, $thankyous);
								}
							}
							else {
								$this->codeForAffiliateAdsenseThankyouSales($args, $thankyous);
							}
						}
					}
				}
			}
		}
	}

	//* adsense
	function widgetForAdsense($args) {
		global $post;

		$postid = $post->ID;
		$count	= FUNNELVOODOO_DEFAULT_COUNT_ADSENSE;

		for ($i = 1; $i <= $count; $i++) {
			$adsense = get_option($this->db->tableAdsense .'_'. $i);
			if ($adsense['enable'] == FUNNELVOODOO_ENABLED) {
				$sidebar 		= $adsense['sidebar'];

				$homepage       = $sidebar['homepage'];
				$pages          = $sidebar['pages'];
				$pagesid        = trim(str_replace(', ', ',', $sidebar['pagesid']));
				$nopagesid      = trim(str_replace(', ', ',', $sidebar['nopagesid']));
				$posts          = $sidebar['posts'];
				$postsid        = trim(str_replace(', ', ',', $sidebar['postsid']));
				$nopostsid		= trim(str_replace(', ', ',', $sidebar['nopostsid']));

				//* homepage, sticky post, frontpage
				if (is_home() || is_sticky() || is_front_page()) {
					if ($homepage == FUNNELVOODOO_ENABLED) {
						$this->codeForAffiliateAdsenseThankyouSales($args, $adsense);
					}
				}

				//* pages
				if (is_page()) {
					if ($pages == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopagesid)) {
							$explodedNoPagesId = explode(',', $nopagesid);
							if (!in_array($post->ID, $explodedNoPagesId)) {
								if (0 != strlen($pagesid)) {
									$explodePagesId = explode(',', $pagesid);
									if (in_array($post->ID, $explodePagesId)) {
										$this->codeForAffiliateAdsenseThankyouSales($args, $adsense);
									}
								}
								else {
									$this->codeForAffiliateAdsenseThankyouSales($args, $adsense);
								}
							}
						}
						else {
							if (0 != strlen($pagesid)) {
								$explodePagesId = explode(',', trim(str_replace(', ', ',', $pagesid)));
								if (in_array($post->ID, $explodePagesId)) {
									$this->codeForAffiliateAdsenseThankyouSales($args, $adsense);
								}
							}
							else {
								$this->codeForAffiliateAdsenseThankyouSales($args, $adsense);
							}
						}
					}
				}

				//* single
				if (is_single()) {
					if ($posts == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopostsid)) {
							$explodedNoPostsId = explode(',', $nopostsid);
							if (!in_array($post->ID, $explodedNoPostsId)) {
								if (0 != strlen($postsid)) {
									$explodePostsId = explode(',', $postsid);
									if (in_array($post->ID, $explodePostsId)) {
										$this->codeForAffiliateAdsenseThankyouSales($args, $adsense);
									}
								}
								else {
									$this->codeForAffiliateAdsenseThankyouSales($args, $adsense);
								}
							}
						}
						else {
							if (0 != strlen($postsid)) {
								$explodePostsId = explode(',', trim(str_replace(', ', ',', $postsid)));
								if (in_array($post->ID, $explodePostsId)) {
									$this->codeForAffiliateAdsenseThankyouSales($args, $adsense);
								}
							}
							else {
								$this->codeForAffiliateAdsenseThankyouSales($args, $adsense);
							}
						}
					}
				}
			}
		}
	}

	//* affiliates
	function widgetForAffiliate($args) {
		global $post;

		$postid = $post->ID;
		$count	= FUNNELVOODOO_DEFAULT_COUNT_AFFILIATES;

		for ($i = 1; $i <= $count; $i++) {
			$affiliate = get_option($this->db->tableAffiliates .'_'. $i);
			if ($affiliate['enable'] == FUNNELVOODOO_ENABLED) {
				$sidebar 		= $affiliate['sidebar'];

				$homepage       = $sidebar['homepage'];
				$pages          = $sidebar['pages'];
				$pagesid        = trim(str_replace(', ', ',', $sidebar['pagesid']));
				$nopagesid      = trim(str_replace(', ', ',', $sidebar['nopagesid']));
				$posts          = $sidebar['posts'];
				$postsid        = trim(str_replace(', ', ',', $sidebar['postsid']));
				$nopostsid		= trim(str_replace(', ', ',', $sidebar['nopostsid']));
				
				//* homepage, sticky post, frontpage
				if (is_home() || is_sticky() || is_front_page()) {
					if ($homepage == FUNNELVOODOO_ENABLED) {
						$this->codeForAffiliateAdsenseThankyouSales($args, $affiliate);
					}
				}

				//* pages
				if (is_page()) {
					if ($pages == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopagesid)) {
							$explodedNoPagesId = explode(',', $nopagesid);
							if (!in_array($post->ID, $explodedNoPagesId)) {
								if (0 != strlen($pagesid)) {
									$explodePagesId = explode(',', $pagesid);
									if (in_array($post->ID, $explodePagesId)) {
										$this->codeForAffiliateAdsenseThankyouSales($args, $affiliate);
									}
								}
								else {
									$this->codeForAffiliateAdsenseThankyouSales($args, $affiliate);
								}
							}
						}
						else {
							if (0 != strlen($pagesid)) {
								$explodePagesId = explode(',', trim(str_replace(', ', ',', $pagesid)));
								if (in_array($post->ID, $explodePagesId)) {
									$this->codeForAffiliateAdsenseThankyouSales($args, $affiliate);
								}
							}
							else {
								$this->codeForAffiliateAdsenseThankyouSales($args, $affiliate);
							}
						}
					}
				}

				//* single
				if (is_single()) {
					if ($posts == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopostsid)) {
							$explodedNoPostsId = explode(',', $nopostsid);
							if (!in_array($post->ID, $explodedNoPostsId)) {
								if (0 != strlen($postsid)) {
									$explodePostsId = explode(',', $postsid);
									if (in_array($post->ID, $explodePostsId)) {
										$this->codeForAffiliateAdsenseThankyouSales($args, $affiliate);
									}
								}
								else {
									$this->codeForAffiliateAdsenseThankyouSales($args, $affiliate);
								}
							}
						}
						else {
							if (0 != strlen($postsid)) {
								$explodePostsId = explode(',', trim(str_replace(', ', ',', $postsid)));
								if (in_array($post->ID, $explodePostsId)) {
									$this->codeForAffiliateAdsenseThankyouSales($args, $affiliate);
								}
							}
							else {
								$this->codeForAffiliateAdsenseThankyouSales($args, $affiliate);
							}
						}
					}
				}
			}
		}
	}

		function codeForAffiliateAdsenseThankyouSales($args, $data) {
			extract ($args);

			echo $before_widget;
				echo $before_title;
					echo ($data['title_hide'] == FUNNELVOODOO_DISABLED) ? $data['title'] : '';
				echo $after_title;

				echo (0 != strlen($data['contents'])) ? str_replace('\\', '', $data['contents']) : '';
			echo $after_widget;
		}
	//* end of affiliates

	//* optins
	function widgetForOptin($args) {
		global $funnelVoodooThemes,
		       $post;

		$postid = $post->ID;
		$count 	= FUNNELVOODOO_DEFAULT_COUNT_OPTINS;
		for ($i = 1; $i <= $count; $i++) {
			$optin = get_option($this->db->tableOptins .'_'. $i);
			if ($optin['enable'] == FUNNELVOODOO_ENABLED) {
				$aweber			= $optin['aweber'];
				$popup          = $optin['popup'];
				$theme          = $optin['theme'];
				$themeConfig    = $funnelVoodooThemes->themes[$theme['id']];
				$sidebar        = $optin['sidebar'];

				$homepage       = $sidebar['homepage'];
				$pages          = $sidebar['pages'];
				$pagesid        = trim(str_replace(', ', ',', $sidebar['pagesid']));
				$nopagesid      = trim(str_replace(', ', ',', $sidebar['nopagesid']));
				$posts          = $sidebar['posts'];
				$postsid        = trim(str_replace(', ', ',', $sidebar['postsid']));
				$nopostsid		= trim(str_replace(', ', ',', $sidebar['nopostsid']));
				?>

				<style type="text/css">
					.squeezepro-v3-optin-widget-<?php echo $i; ?> {
						margin: 0 !important;
						padding: 5px !important;
						background: <?php echo $theme['main_bg']; ?> !important;
						border: 3px solid <?php echo $theme['main_border_color']; ?> !important;
						border-radius: 5px !important;
							-moz-border-radius: 5px !important;
							-webkit-border-radius: 5px !important;

						/*width: 100% !important;*/
						width: 95% !important;
						overflow: hidden !important;
					}
					
					.squeezepro-v3-optin-widget-<?php echo $i; ?> .bullets ul {
						padding: 0 !important;
						margin: 0 !important;
						list-style-type: none !important;
					}

						.squeezepro-v3-optin-widget-<?php echo $i; ?> .bullets ul li::before {
							display: none !important;
						}

						.squeezepro-v3-optin-widget-<?php echo $i; ?> .bullets ul li {
							background: url(<?php echo FUNNELVOODOO_URL .'tmpl/images/check.png'; ?>) no-repeat !important;
							background-position: 0 0.2em !important;
							margin-left: 10px !important;
							padding-left: 20px !important;
							padding-bottom: 5px !important;

							color: #000 !important;
						}

					.squeezepro-v3-optin-widget-<?php echo $i; ?> a.popup {
						text-decoration: none !important;
						color: <?php echo $themeConfig['options']['popup_color']; ?> !important;
					}

						.squeezepro-v3-optin-widget-<?php echo $i; ?> a.popup > div {
							text-align:center !important;
							padding: 10px !important;
							background: <?php echo $themeConfig['options']['popup_bg']; ?> !important;
							border: 3px solid <?php echo $themeConfig['options']['popup_bg']; ?> !important;
							border-radius: 5px !important;
								-moz-border-radius: 5px !important;
								-webkit-border-radius: 5px !important;
							color: <?php echo $themeConfig['options']['popup_color']; ?> !important;
							font-weight: bold !important;
							font-size: 16px !important;
						}

					.squeezepro-v3-optin-widget-<?php echo $i; ?> .optin {
						text-align: center !important;
					}

						.squeezepro-v3-optin-widget-<?php echo $i; ?> .optin .headline {
							color: <?php echo $theme['headline_color']; ?> !important;
							font-weight: <?php echo $theme['headline_bold']; ?> !important;
							padding: 10px !important;

							font-family: Arial, Helvetica, Sans-serif !important;
							text-align: center !important;
						}

						.squeezepro-v3-optin-widget-<?php echo $i; ?> .optin input[type="text"] {
							width: <?php echo $theme['txtbox_width']; ?> !important;
							margin: 5px !important;
							padding: 10px !important;
							border: 2px solid <?php echo $theme['txtbox_border_color']; ?> !important;
							font-size: <?php echo $theme['txtbox_fontsize']; ?> !important;
						}

						.squeezepro-v3-optin-widget-<?php echo $i; ?> .optin input[type="submit"] {
							padding: 10px !important;
							margin: 0 auto !important;
							margin-top: 15px !important;
							background: <?php echo $theme['btn_bg']; ?> !important;
							border: 2px solid <?php echo $theme['btn_border_color']; ?> !important;
							border-radius: 5px !important;
								-moz-border-radius: 5px !important;
								-webkit-border-radius: 5px !important;
							font-weight: <?php echo $theme['btn_bold']; ?> !important;
							font-size: <?php echo $theme['btn_fontsize']; ?> !important;
							color: <?php echo $theme['btn_color']; ?> !important;
						}

					.squeezepro-v3-optin-widget-<?php echo $i; ?> .privacy p {
						text-align: center !important;
						padding-top: 10px !important;
						font-size: 12px !important;
						color: #8c8089 !important;
					}
				</style>


				<?php
				//* homepage, sticky post, frontpage
				if (is_home() || is_sticky() || is_front_page()) {
					if ($homepage == FUNNELVOODOO_ENABLED) {
						$this->codeForOptin($i, $args, $optin, $aweber, $popup, $theme);
					}
				}

				//* pages
				if (is_page()) {
					if ($pages == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopagesid)) {
							$explodedNoPagesId = explode(',', $nopagesid);
							if (!in_array($post->ID, $explodedNoPagesId)) {
								if (0 != strlen($pagesid)) {
									$explodePagesId = explode(',', $pagesid);
									if (in_array($post->ID, $explodePagesId)) {
										$this->codeForOptin($i, $args, $optin, $aweber, $popup, $theme);
									}
								}
								else {
									$this->codeForOptin($i, $args, $optin, $aweber, $popup, $theme);
								}
							}
						}
						else {
							if (0 != strlen($pagesid)) {
								$explodePagesId = explode(',', trim(str_replace(', ', ',', $pagesid)));
								if (in_array($post->ID, $explodePagesId)) {
									$this->codeForOptin($i, $args, $optin, $aweber, $popup, $theme);
								}
							}
							else {
								$this->codeForOptin($i, $args, $optin, $aweber, $popup, $theme);
							}
						}
					}
				}

				//* single
				if (is_single()) {
					if ($posts == FUNNELVOODOO_ENABLED) {
						if (0 != strlen($nopostsid)) {
							$explodedNoPostsId = explode(',', $nopostsid);
							if (!in_array($post->ID, $explodedNoPostsId)) {
								if (0 != strlen($postsid)) {
									$explodePostsId = explode(',', $pagesid);
									if (in_array($post->ID, $explodePostsId)) {
										$this->codeForOptin($i, $args, $optin, $aweber, $popup, $theme);
									}
								}
								else {
									$this->codeForOptin($i, $args, $optin, $aweber, $popup, $theme);
								}
							}
						}
						else {
							if (0 != strlen($postsid)) {
								$explodePostsId = explode(',', trim(str_replace(', ', ',', $postsid)));
								if (in_array($post->ID, $explodePostsId)) {
									$this->codeForOptin($i, $args, $optin, $aweber, $popup, $theme);
								}
							}
							else {
								$this->codeForOptin($i, $args, $optin, $aweber, $popup, $theme);
							}
						}
					}
				}

			}
		}
	}

		function codeForOptin($optinid, $args, $optin, $aweber, $popup, $theme) {
			extract ($args);

			echo $before_widget;
				echo $before_title;
					echo ($optin['title_hide'] == FUNNELVOODOO_DISABLED) ? $optin['title'] : '';
				echo $after_title;
				?>


				<div class="squeezepro-v3-optin-widget-<?php echo $optinid; ?>">
					<?php
					if (0 != strlen($optin['contents'])) {
						echo '<div class="content">';
							echo str_replace('\\', '', $optin['contents']);
						echo '</div>';
					}

					if ($aweber['enable'] == FUNNELVOODOO_ENABLED) {
						?>

						<div class="bullets">
							<?php
							if (0 != strlen($aweber['bullet_1']) || 0 != strlen($aweber['bullet_2']) || 0 != strlen($aweber['bullet_3'])) {
								echo '<ul>';
									echo (0 != strlen($aweber['bullet_1'])) ? '<li>'. $aweber['bullet_1'] .'</li>' : '';
									echo (0 != strlen($aweber['bullet_2'])) ? '<li>'. $aweber['bullet_2'] .'</li>' : '';
									echo (0 != strlen($aweber['bullet_3'])) ? '<li>'. $aweber['bullet_3'] .'</li>' : '';
								echo '</ul>';
							}
							?>
						</div> <br />


						<?php
						if ($popup['enable'] == FUNNELVOODOO_ENABLED) {
							$cssHeadline = 'color: '. $theme['headline_color'] .'!important;';
							$cssHeadline .= 'font-weight: '. $theme['headline_bold'] .'!important;';
							$cssHeadline .= 'padding:10px!important;';
							$cssHeadline .= 'font-family:Arial,Helvetica,Sans-serif!important;';
							$cssHeadline .= 'text-align:center!important;';

							$cssOptinFormInput = 'width: '. $theme['txtbox_width'] .'!important;';
							$cssOptinFormInput .= 'margin: 5px !important;';
							$cssOptinFormInput .= 'padding: 10px !important;';
							$cssOptinFormInput .= 'border: 2px solid '. $theme['txtbox_border_color'] .'!important;';
							$cssOptinFormInput .= 'font-size:'. $theme['txtbox_fontsize'] .'!important;';
							?>

							<a href="#dialog-optin-widget-popup-<?php echo $optinid; ?>" name="cmdOptinPopup" id="cmdOptinPopup" class="popup">
								<?php
								if ($popup['btn_type'] == 'button') {
									echo '<div>'. $popup['btn'] .'</div>';
								}
								else {
									echo str_replace('\\', '', $popup['btn_img']);
								}
								?>
							</a>
							<div id="dialog-optin-widget-popup-<?php echo $optinid; ?>" style="display:none;">
								<form method="POST" action="http://www.aweber.com/scripts/addlead.pl">
									<input type="hidden" name="meta_web_form_id" value="1256636276"/>
									<input type="hidden" name="meta_split_id" value=""/>
									<input type="hidden" name="listname" value="<?php echo $aweber['listname']; ?>"/>
									<input type="hidden" name="redirect" value="<?php echo $aweber['thankyou']; ?>" id="redirect_b221c6e90cbf15aa8cb43244834d4891"/>
									<input type="hidden" name="meta_redirect_onlist" value="<?php echo $aweber['thankyou']; ?>"/>
									<input type="hidden" name="meta_adtracking" value="My_Web_Form"/>
									<input type="hidden" name="meta_message" value="1"/>
									<input type="hidden" name="meta_required" value="name,email"/>
									<input type="hidden" name="meta_forward_vars" value=""/>
									<input type="hidden" name="meta_tooltip" value=""/>

									<div class="headline" style="<?php echo $cssHeadline; ?>">Fill in the form Below:</div>
									<div style="text-align:center!important;">
										<input type="text" name="name" id="name" placeholder="Enter name..." style="<?php echo $cssOptinFormInput; ?>" /> <br/>
										<input type="text" name="email" id="email" placeholder="Enter email address..." style="<?php echo $cssOptinFormInput; ?>" />

										<?php
										if ($popup['btn_type'] == 'image') {
											echo '<input type="image" id="submit_image_5f17aab77d6c" width="' . $theme['btn_img_size'] . '" src="' . $theme['btn_img_src'] . '" />';
										}
										else {
											echo '<input type="submit" id="submit_image_5f17aab77d6c" value="' . $theme['btn_value'] . '" style="padding:10px!important; margin-top:15px!important; background:'. $theme['btn_bg'] .'!important; border:2px solid '. $theme['btn_border_color'] .'!important; border-radius:5px!important; -moz-border-radius:5px!important; -webkit-border-radius:5px!important; font-weight:'. $theme['btn_bold'] .'!important; font-size:'. $theme['btn_fontsize'] .'!important; color:'. $theme['btn_color'] .'!important; font-family:Arial,Helvetica,Sans-Serif!important;" />';
										}
										?>
									</div>


									<?php
									if (0 != strlen($optin['privacy'])) {
										echo '<div class="privacy">';
										echo str_replace('\\', '', $optin['privacy']);
										echo '</div>';
									} else {
										echo '<div class="privacy" style="text-align:center; font-family:Arial,Helvetica,Sans-Serif!important; color:#8c8089!important; padding-top:10px!important; font-size:12px; text-align:center;"><a href="http://www.aweber.com/permission.html" target="_blank">Privacy</a></div>';
									}
									?>
								</form>
							</div>

							<?php
						}
						else {
							?>

							<form method="POST" action="http://www.aweber.com/scripts/addlead.pl">
								<input type="hidden" name="meta_web_form_id" value="1256636276"/>
								<input type="hidden" name="meta_split_id" value=""/>
								<input type="hidden" name="listname" value="<?php echo $aweber['listname']; ?>"/>
								<input type="hidden" name="redirect" value="<?php echo $aweber['thankyou']; ?>" id="redirect_b221c6e90cbf15aa8cb43244834d4891"/>
								<input type="hidden" name="meta_redirect_onlist" value="<?php echo $aweber['thankyou']; ?>"/>
								<input type="hidden" name="meta_adtracking" value="My_Web_Form"/>
								<input type="hidden" name="meta_message" value="1"/>
								<input type="hidden" name="meta_required" value="name,email"/>
								<input type="hidden" name="meta_forward_vars" value=""/>
								<input type="hidden" name="meta_tooltip" value=""/>

								<div class="optin">
									<div class="headline">Fill in the form Below:</div>
									<div style="text-align:center;">
										<input type="text" name="name" id="name" placeholder="Enter name..." /> <br/>
										<input type="text" name="email" id="email" placeholder="Enter email address..." />

										<?php
										if ($theme['btn_img'] == 'yes') {
											echo '<input type="image" id="submit_image_5f17aab77d6c" width="'. $theme['btn_img_size'] .'" src="'. $theme['btn_img_src'] .'" />';
										}
										else {
											echo '<input type="submit" id="submit_image_5f17aab77d6c" value="'. $theme['btn_value'] .'" />';
										}
										?>
									</div>
								</div>

								<?php
								if (0 != strlen($optin['privacy'])) {
									echo '<div class="privacy">';
										echo str_replace('\\', '', $optin['privacy']);
									echo '</div>';
								}
								else {
									echo '<div class="privacy" style="font-family:Arial,Helvetica,Sans-Serif!important; color:#8c8089!important; padding-top:10px!important; font-size:12px; text-align:center;"><a href="http://www.aweber.com/permission.html" target="_blank">Privacy</a></div>';
								}
								?>
							</form>

							<?php
						}
					}
					else {
						echo str_replace('\\', '', $aweber['contents']);
					}

					?>
				</div>
				<div style="clear:both!important;"></div>


				<?php
			echo $after_widget;
		}
	//* end for optins
}