myFilters is a mechanism you can use to write custom HTML filters for modifying websites and making them compatible with retro web browsers. You could also do it by editing proxy.php but using myFilters is much, much easier. 

Every custom filter is a .php file that you put in the myFilters directory in your retroTunnel installation(uploading a filter via retroTunnel's "My Filters" page is the best way to do this because it'll give the filter correct file permissions). A filter file needs to have the following basic structure:

<?php

//filterInfo;0;contains;example.com;end
function filter($url, $content){
	return $content;
}

?>

//filterInfo is crucial. It's how the HTTPS proxy can tell that a filter file is a filter file. //filterInfo must be separated by semi-colons, contain no spaces, and have four parameters in a specific order. The parameters are:

Filter level. A level 0 filter will be applied to a page after the HTTPS proxy has processed it. A level 1 filter will be applied to a page before the HTTPS proxy has processed it. And a level 2 filter will prevent the HTTPS proxy from processing a page at all, meaning you have to do all the processing yourself. For example, your level 2 filter will have to convert links from 

<a href="http://blahblah.website"> 

to 

<a href="./proxy.php?siteURL=http://blahblah.website">

And images from 

<img src="http://blahblah.website/example.jpg">

to 

<img src="./image.php?imageURL=http://blahblah.website/example.jpg">

Etc, etc, because the proxy won't do it for you. 

URL matching. "contains" means that your filter will operate on any URL that contains the URL keyword. "absolute" means that your filter will only operate on a URL that matches the URL keyword exactly. You'll probably want to use "contains" most of the time.

URL keyword. This is a portion of a URL like duckduckgo or a full URL like https://www.duckduckgo.com.

End. This simply marks the end of the //filterInfo statement.


There's an example filter in your retroTunnel installation called exampleFilter.php. If you want to activate it, then just put it in the myFilters directory. Here's what it looks like:

<?php

//filterInfo;0;contains;kontek.net;end
function filter($url, $content){

	if($url === "https://kontek.net" || $url === "https://kontek.net/"){
		$content = str_ireplace("Welcome!", "Bleh!", $content);
	}

	return $content;
}

?>

You probably don't even need me to explain this, but $url is the page URL and $content is the page itself. To filter a page you simply operate on $content and return it. If you want to cancel filtering the page for any reason, you return NULL. This is how a filter function works. And yes, every filter function needs to be named "filter". 

There's a special command of sorts you can use to prevent the proxy from processing part of an HTML tag. It's called rtDontProcess. 


<?php

//filterInfo;1;contains;kontek.net;end
function filter($url, $content){
	
	if($url === "https://kontek.net" || $url === "https://kontek.net/"){
		$content = str_ireplace("https://bonkzonk.com", "rtDontProcess:https://bonkzonk.com", $content);
	}
		
	return $content;
}
	
?>

This will stop the proxy from automatically converting "https://bonkzonk.com" into "proxy.php?siteURL=https://bonkzonk.com". rtDontProcess only works with level 1 filters. Why is this useful? Once you start writing your own filters the answer will reveal itself. Although if you want a hint, open up proxy.php and see how I use rtDontProcess. If you don't understand it, don't worry. It'll make sense when you need it to.


There's also a command you can use to automatically shrink images. 

<?php
//filterInfo;0;contains;kontek.net;end
	function filter($url, $content){
	
		if($url === "https://kontek.net" || $url === "https://kontek.net/"){
			$content = str_ireplace("image.php?imageURL", "image.php?imageMax=100&imageURL", $content);
		}
		
		return $content;
	}
	
?>

In this example, any image with a width over 100 pixels will be shrunk to 100 pixels wide. Scaling will be proportional. This doesn't work with Project Gutenberg images(these are already scaled down to reasonable sizes) or Wayback Machine mini-proxy images. Shrunken images will be either gifs or jpegs. I won't lie, I rushed this feature at the last minute while I was finishing up retroTunnel 1.3 so it's a little half-baked. But it works. 


If you want to know where to begin with page filtering, just go to a website that you'd like to filter and view its page source. Think about how you'd like to modify its HTML code. Then modify it in your filter script. That's all there is to it. Good luck writing your filter(s)!

Note: To make looking up filters more efficient, the HTTPS proxy maintains a sort of index of them. That's what the 0, 1, and 2 directories in rt/myFilters are. The HTTPS proxy tries to perform automatic housekeeping of the index but if it fails for some reason and your filter isn't working the way it should, then go to the index directories and manually delete any index file or files associated with your filter.

Also, you can only have one filter per URL keyword. So you can't have a dozen separate filters doing things to kontek.net. Although it's easy enough to change that limitation if you really want to.  