<?php 

if (!class_exists('HtmlHelper')) {
	App::import('Helper', 'Html');
}



class LinkHelper extends AppHelper {

/**
 * Adds email links with subject (<a href="mailto:someone@somewhere.com?subject=What a Cool Subject) to a given text.
 *
 * @param string $text Text
 * @param string $subject Subject
 * @return string The text with links, seperated by spaces.
 * @access public
 */
	function autoLinkEmailsSubject($text, $subject) {
		
		$matches = array();
		$links = "";
		$number_of_matches = preg_match_all('#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#', $text, $matches, PREG_PATTERN_ORDER);
		if($number_of_matches > 0) {
			$Html = new HtmlHelper(); 
			$Html->tags = $Html->loadConfig(); 
			foreach($matches[0] as $match) {
			$links .= $Html->link($match, "mailto:" . $match . "?subject=" .$subject).' '; 
			}
			
			return $links;
			
		}
		
		else {
			return;
		}
		
	 }
		 

	
	

	
}
	
