Пример #1
0
		/**
		 * Parse personal details from content
		 * 
		 * @return array Profile details
		 * Example of output array
		 * <code>
		 * 	[Headline] => "feel easy to live"
		 *  [City]  => www.fakaofo.tk - Fakaofo
		 *  [State]  => State Info
		 *  [Country]  => Tokelau
		 *  [Last  Login] => 11/27/2006
		 *  [Age]  => 25
		 *  [Sex]  => Female
		 *  [Profile  Views] =>
		 *  [Online]  => 1
		 *  [Status]  => Single
		 *  [Here  for] => Networking, Dating, Friends
		 *  [Orientation]  => Not Sure
		 *  [Hometown]  => <a href="http://www.fakaofo.tk/">Fakaofo</a>
		 *  [Body  type] => 5' 2" / Athletic
		 *  [Ethnicity]  => Pacific Islander
		 *  [Religion]  => Other
		 *  [Zodiac  Sign] => <a href="http://collect.myspace.com/index.cfm?
		 * fuseaction=horoscope&sign=11&MyToken=5e6d132b-f9da-4df1-880d-
		 * 06d4a19d0fd2">Aquarius</a>
		 *  [Smoke  / Drink] => Yes / Yes
		 *  [Children]  => Love kids, but not for me
		 *  [Education]  => High school
		 *  [Occupation]  => Stranger
		 *  [General]  => 1. sex 2. drugs 3. rock & roll
		 *  [Music]  => rap, classic music
		 *  [Movies]  => matrix
		 *  [Television]  => mtv
		 *  [Books]  => udar russkix bogov
		 *  [Heroes]  => no heros
		 * </code>
		 * 
		 * @access public
		 */
		function GetPersonalDetails()
		{
			$details = array();
			
	
			$patterns = array(
				'/class\s*\=\s*(?:\'|\")nametext.*?\<table[^\>]+\>(.*?)\<\/table\>/msi'
			);
			
			//
			// Match personal info from top block
			//
			$this->PersonalInfoBlock = $this->GetMatches($patterns);
			
			if (preg_match('/\<td[^\>]+width\s*\=\s*\"193\"[^\>]*\>(.*?)\<\/td\>/msi', $this->PersonalInfoBlock, $matches))
			{
				$entries = preg_split('/\<br[^\>]*\>/ims', $matches[1]);
				
				//
				// parse entries
				//
				if ($entries)
				{
					$entries = array_map('trim', $entries);
					
					if (!in_array(trim($entries[2]), array('Male', 'Female')))
					{
						$this->Headline = $entries[1];
						$location = explode(",", $entries[3], 2);
						$this->City = trim($location[0]);
						$this->State = trim($location[1]);
						$this->Country = $entries[4];
						$this->ProfileViews = preg_replace('/[^0-9]+/msi', '', $entries[6]);
						$this->LastLogin = preg_replace('/[^0-9\/]+/msi', '', $entries[10]);
						if (stristr($entries[7], 'OnlineNow') || stristr($entries[8], 'OnlineNow'))
							$this->Online = true;
					}
					else
					{
						$this->Headline = $entries[0];
						$this->ProfileViews = preg_replace('/[^0-9]+/msi', '', $entries[1]);
						$this->Sex = $entries[2];
						$this->Age = preg_replace('/[^0-9]+/msi', '', $entries[3]);
						$location = explode(",", $entries[4], 2);
						$this->City = trim($location[0]);
						$this->State = trim($location[1]);
						$this->Country = $entries[5];
						$this->LastLogin = preg_replace('/[^0-9\/]+/msi', '', $entries[8]);
						if (stristr($entries[7], 'OnlineNow'))
							$this->Online = true;
					}
					
					$details = array(
						'Headline' 	=> $this->Headline,
						'City'		=> $this->City,
						'State' 	=> $this->State,
						'Country' 	=> $this->Country,
						'Last Login' => $this->LastLogin,
						'Age'		=> $this->Age,
						'Sex'		=> $this->Sex,
						'Profile Views'		=> $this->ProfileViews,
						'Online'	=> $this->Online
					);
				}
			}
			
			
			
			$patterns = array(
				'/\'s Details.*?\<table[^\>]+\>(.*?)\<\/table/msi'
			);
		
			//
			// Match personal info from middle block - Name's Details
			//
			$this->DetailsBlock = $this->GetMatches($patterns);
			
			if ($this->DetailsBlock)
			{
				$entries = preg_split('/\<\/tr[^\>]*\>/ims', $this->DetailsBlock);
				
				//
				// parse entries
				//
				if ($entries)
				{
					$entries = array_map('trim', $entries);
					
					foreach($entries as $entry)
					{
						if (!$entry) continue;
						if (preg_match('/\<span[^\>]+\>([^\<]+)\<\/span.*?\<td[^\>]+\>(.*?)\<\/td/msi', $entry, $match))
						{
							$key = str_replace(':', '', trim($match[1]));
							$details[$key] = HTMLParser::StripLinks(trim($match[2]));
						}
					}
					
				} // end if entries
			}
			


			$patterns = array(
				'/\'s Interests.*?\<([0-9]+)table[^\>]+\>(.*?)\<\\1\/table/msi'
			);
			
			
			//
			// Match Interests block information
			//
			$this->InterestsBlock = $this->GetMatches($patterns, true);
			
			if ($this->InterestsBlock)
			{
				$entries = preg_split('/<tr[\s\t]+id\=[\'\"a-z]+Row[^>]*>/ims', $this->InterestsBlock);
				
				//
				// parse entries
				//
				if ($entries)
				{
					$entries = array_map('trim', $entries);
					
					foreach($entries as &$entry)
					{
						if (!$entry) continue;
						
						if (preg_match('/<[0-9]+span[^>]+>([^<]+)<[0-9]+\/span.*?<([0-9]+)td[^>]+>(.*?)<\\2\/td/msi', HTMLParser::AddTagDepth($entry), $match))
						{
							$match[3] = HTMLParser::RemoveTagDepth(trim($match[3]));
							$key = HTMLParser::RemoveTagDepth(trim($match[1]));
							$key = str_replace(':', '', $key);
							
							// remove link to all groups
							if ($key == 'Groups')
								$match[3] = preg_replace('/\<br[^\>]*\>\<br[^\>]*\>.*$/msi', '', $match[3]);
							
							$details[$key] = HTMLParser::StripBlankLinks(trim($match[3]));
						}
					}
					
				} // end if entries
			}
			
			
			
			return $details;
		}
		/**
		 * Parse personal details from content
		 * 
		 * @return array profile details
		 * sample
		 *   [userpic]   => http://www.livejournal.com/userpic/38353247/8981002
		 *   [name]   => Natalie
		 *   [website]   => http://www.myspace.com/aggressiva
		 *   [city]   => La Verne
		 *   [state]   => California
		 *   [country]   => United States
		 *   [birthday] => 1971-12-15
		 *   [aboutme]	=> party ... I just believe in parties!
		 */
		function GetPersonalDetails()
		{
			$details = array();
						
			$pattern = '/><[0-9]*b>(user|name|website|location|birthdate|gizmo\/lj talk|bio|e\-mail)\:<[0-9]*\/b><[0-9]*\/td><([0-9]*)td[^>]*>(.*?)<\\2\/td>/msi';
			
			$this->Result = HTMLParser::AddTagDepth($this->Result);
			preg_match_all($pattern, $this->Result, $matches, PREG_SET_ORDER);
			$this->Result = HTMLParser::RemoveTagDepth($this->Result);
			
			foreach($matches as $match)
			{
				$match[2] = HTMLParser::RemoveTagDepth(trim($match[3]));
				
				switch ($match[1])
				{
					case 'Name':
						$details['name'] = $match[2];
						break;
					
					case 'Website':
						if (preg_match("/href=(\'|\")(.*?)\\1/", $match[2], $match2))
						{
							$details['website'] = $match2[2];
						}
						break;
					
					case 'Location':
						preg_match_all("/loc\_(ci|st|cn)\=[^>\&]+>(.*?)</msi", $match[2], $match2, PREG_SET_ORDER);
						
						foreach($match2 as $res)
						{
							if ($res[1] == 'ci')
								$details['city'] = $res[2];
							elseif ($res[1] == 'st')
								$details['state'] = $res[2];
							elseif ($res[1] == 'cn')
								$details['country'] = $res[2];
						}
						break;
					
					case 'Bio':
						$details['aboutme'] = $match[2];
						break;
					
					case 'Birthdate':
						$details['birthday'] = $match[2];
						break;
					
					case 'E-mail':
						$details['email'] = HTMLParser::StripTags($match[2]);
						
						break;
				}
			}
			
			
			if (preg_match("/http\:\/\/([a-z0-9\-]+\.)+[a-z0-9]{2,6}\/userpic\/[0-9]+\/[0-9]+/msi", $this->Result, $matches))
			{
				$details['userpic'] = $matches[0];
			}
			
			//echo '<xmp>'; print_r($details); echo '</xmp>'; exit;
			return $details;
		}
Пример #3
0
		/**
		 * Get first match from content and supplied patterns
		 * 
		 * @var array patterns
		 */
		function GetMatches($patterns, $add_tag_depth = false)
		{
			if (!$this->Result) return false;
			
			if ($add_tag_depth)
				$this->Result = HTMLParser::AddTagDepth($this->Result);
				
			foreach($patterns as $pattern)
			{
				if (preg_match($pattern, $this->Result, $matches))
					return ($add_tag_depth) ? HTMLParser::RemoveTagDepth(trim($matches[2])) : trim($matches[1]);
			}
			
			if ($add_tag_depth)
				$this->Result = HTMLParser::RemoveTagDepth($this->Result);
			
			return false;
		}