Location: PHPKode > scripts > WereProxy > wereproxy/super/spr/Impfunctions.php
<?php
/*
	Copyright 2010 Iresha Gunathileke (hide@address.com)   
 	
 	Licensed under the Apache License, Version 2.0 (the "License");
 	
 	Changes to the original file include
 	1. Additional functions to read and supply proxies.
 	2. Implemtation of the enpty interfaces.
 	
 	http://code.google.com/p/were-proxy/
 */


/*
	Copyright 2010 Ping Shin Ching (hide@address.com)

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

		http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
	
	Project Mugatiya: mugatiya.wordpress.com
 */



/*
 * If true then bypass content filtering - faster response
 * Default add will be 'unclassified'
 */
define('STREAMLINE', true);


/*
 * Arrays and scalars to keep track of the subbed stuff
 */
$subbedurl=0;

$subtracker=array();
$subtrackerbbc=array();
$subtrackermini=array();

$sitecount=0;
$sitecountmini=0;
$sitecountbbc=0;

/*
 * Array of urls to replace other urls.
 */
$subinsites = array(
	"<a href='http://wereproxy.com'>Best free backlink builing proxy tool</a>"

);

$subinsitesbbc = array(
	"[url=http://wereproxy.com]Best free backlink builing proxy tool[/url]"

);

$subinsitesmini = array(
	"http://wereproxy.com/"
);

/*
 * Called to modify POST Values
 */
function imodpostvalues($url, $host, $post){
	//This function now does nothing;
}


/*
 * Check to see if we have made a change
 */
function changedpost(){
	global $subbedurl;
	return $subbedurl;
}


/*
 * Modify the response data and reverse the changes
 */
function imodresponse(&$output){
	global $subtracker, $subtrackerbbc,$subtrackermini, $subbedurl;

	/*
	error_log(print_r($subtracker,1));
	error_log(print_r($subtrackerbbc,1));
	error_log(print_r($subtrackermini,1));
	*/
	
	if($subbedurl){
		foreach($subtracker as $n => $v){
			$output=str_replace($v, $n, $output);	
		}
		foreach($subtrackerbbc as $n => $v){
			$output=str_replace($v, $n, $output);	
		}				
		foreach($subtrackermini as $n => $v){
			$output=str_replace($v, $n, $output);	
		}
	}
	return $output;
}

/*
 * Function to get a valid proxy from a list.
 */
function getaproxy($filename){
	global $subbedurl;
	if(!$subbedurl){
		return 0;	
	}
	$lines = array();
	if(($f = fopen($filename, 'r'))!==FALSE){
		while(!feof($f)){
			$s=fgets($f, 1024);
			if(preg_match("/\w+/ims", $s))
				array_push($lines, trim($s));
 		}
 		fclose($f);
 		if(count($lines)>0){
 			$lines = array_slice($lines, 0, 10);
 			return $lines[array_rand($lines)];
 		}
 		else
 			return 0; 	
	}
	else{
		return 0;	
	}	
}

/*
 * Modify the posted changes at the postrequest.php getencodedpost() function
 */
function postmodify($post){
	global $subtracker, $subtrackerbbc,$subtrackermini, 
	$subinsites, $subinsitesbbc, $subinsitesmini,
	$sitecount,	$sitecountmini,	$sitecountbbc,
	
	$subbedurl;
	
	if(preg_match_all("/<\s*a\s+href\s*=\s*\"?http:\/\/[\w\.\-\#\/=\&\?]+\"?>[^<>\"]+<\s*\/\s*a>/ims", $post, $matches)){
		$unique = array_merge(array(),array_unique($matches[0]));

		for( $i=0; $i < count($unique) ; $i++){
			$subbedurl=1;
			if(isset($subtracker[$unique[$i]])){
				$selectedsite=$subtracker[$unique[$i]];
			}
			else{
				if($sitecount<count($subinsites)){
					$subtracker[$unique[$i]]=$subinsites[$sitecount];	
					$sitecount++;
				}
				else{
				;
				}
			}
		}
		foreach($subtracker as $l => $nl){
			$post = str_replace($l, $nl, $post);
		}
		
	}
	else if(preg_match_all("/\[url=http:\/\/[\w\.\-\#\/=\&\?]+\"?\][^\[\]]+\[\/url\]/ims", $post, $matches)){

		$unique = array_merge(array(),array_unique($matches[0]));

		for( $i=0; $i < count($unique) ; $i++){
			$subbedurl=1;
			if(isset($subtrackerbbc[$unique[$i]])){
				$selectedsite=$subtrackerbbc[$unique[$i]];
			}
			else{
				if($sitecountbbc<count($subinsitesbbc)){
					$subtrackerbbc[$unique[$i]]=$subinsitesbbc[$sitecountbbc];	
					$sitecountbbc++;
				}
				else{
				;
				}
			}
		}
	
		foreach($subtrackerbbc as $l => $nl){
			$post = str_replace($l, $nl, $post);
		}
		
	}
	else if(preg_match_all("/http:\/\/[\w\.\-\#\/=\&\?]+/ims", $post, $matches)){

		$unique = array_merge(array(),array_unique($matches[0]));

		for( $i=0; $i < count($unique) ; $i++){
			$subbedurl=1;
			if(isset($subtrackermini[$unique[$i]])){
				$selectedsite=$subtrackermini[$unique[$i]];
			}
			else{
				if($sitecountmini<count($subinsitesmini)){
					$subtrackermini[$unique[$i]]=$subinsitesmini[$sitecountmini];	
					$sitecountmini++;
				}
				else{
				;
				}
			}
		}
		
		foreach($subtrackermini as $l => $nl){
			$post = str_replace($l, $nl, $post);
		}
	}
		
	
	else{
		;
	}

	return $post;
}
?>
Return current item: WereProxy