<?php
class links{
	function links(){}

	function get_all_links(&$message){
		preg_match_all("'<\s*a\s.*?href\s*=\s*([\"\'])?	(?(1) (.*?)\\1 | ([^\s\>]+))'isx",stripslashes($message),$links);
		$match = array();
		while(list($key,$val) = each($links[2])){
			if(!empty($val))
				$match[] = $val;
		}
		while(list($key,$val) = each($links[3])){
			if(!empty($val))
				$match[] = $val;
		}
		return $match;
	}

	/*
		$data = array(
			'target'=>'_blank'
		);
	*/
	function set_attribute($string, $data){
		$temp = $this->_parse_attribute($string);
		if(empty($temp) || empty($data)) return $string;
		foreach($data as $key=>$val){
			$flag = false;
			foreach($temp as &$v){
				if(strlen(trim($v[1])) == 0) continue;
				if(strtolower($key) != strtolower($v[0])) continue;
				$v[2] = "\"" . $val . "\"";
				$flag = true;
				break;
			}
			if($flag == false){
				array_push(
					$tmep, array($key, '=', "\"" . $val . "\"", '')	
				);
			}
		}
		$arr = '';
		foreach($temp as &$v){
			if(strlen(trim($v[1])) == 0){
				$arr[] = $v[0];
				continue;
			}
			$arr[] = $v[0] . $v[1] . $v[2];
		}
		return implode(" ", $arr);
	}

	function _parse_attribute($string){
		static $html = null;
		if($html == null){
			require_once(R_P . "/include/class.html_clear.php");
			$html = new html_clear();
		}
		return $html->get_attr_info($string);
	}

	function _clear_special_chars($string){
		$string = trim($string);
		$a = substr($string, 0, 1);
		if($a == '"' || $a == "'") $string = substr($string, 1);
		$a = substr($string, -1);
		if($string[0] == '"' || $string[0] == "'") $string = substr($string, 0, -1);
		return trim($string);
	}
}
?>