I ran it through a reformatter for you (See above). It only has a few dozen lines so figuring it out should not be that hard. For instance
if (file_exists($__oid.$__lp)) {
I'd be willing to bet that $__lp is a filename and $__oid is a pathname so doing a global replace with an editor would soon start to make the code readable and undertsandable.
Similarly, $__i seems to be a simple index, so and so forth.