I’m not sure if possible, yet it sounds simple :_)
I made this plugin for Woocommerce and I’m going to offer it to users of a platform i manage. Yet, the market is competitive and I want to remove all comments in the zipped version of the plugin.


Use case is, we work on the source files, and when we are ready to publish it, it goes through a script that creates a copy of it in a seperate directory/folder, with php_strip_whitespace().
It won’t be obfuscated or anything, but at least it empties all our comments and reminders in the scripts.
Is this even do-able? I searched for a while but didn’t see any (paid) script for this anywhere.
Any suggestions and why this is or is not a good idea?

Thanks
KK
This is easy enough to create using the tokenizer or nikics PHP Parser
I think it’s pointless though, legal protections are the correct way to handle this.
Thanks. I just finished a script of my own which works great. Here it is:
(you’re right about legal protections but anybody can make small alterations and change it enough to make it slightly different. I’m just not interested in educating them with comments, quotes and helper codes in the code).
$src = "./x/";
$dst = "../y/";
function recurse_copy($src, $dst)
{
$dir = opendir($src);
!is_dir($dst) ? mkdir($dst) : "";
while (false !== ( $file = readdir($dir))) {
if (( $file != '.' ) && ( $file != '..' )) {
if (is_dir($src . '/' . $file)) {
recurse_copy($src . '/' . $file, $dst . '/' . $file);
} else {

$file_parts = pathinfo($src . '/' . $file);
$ext = $file_parts['extension'];
switch ($ext) {
case "php":
$code = php_strip_whitespace($src . '/' . $file);
$file = file_put_contents($dst . '/' . $file, $code);
break;
case in_array($ext, ["txt", "zip", "log", "psd"]):
break;
default:
copy($src . '/' . $file, $dst . '/' . $file);
break;
}
}
}
}
closedir($dir);
}
recurse_copy($src, $dst);
echo "<H3>Clean Copy Completed!</H3>";

EDIT: This code is partially from several StackEchange posts, I cannot find them anymore to give credit, but I made changes to make it fit my purpose. Anybody feel free to modify, copy, take, do whatever with it. It’s pretty handy.
Members
Online

source

Categories: CodingHostingPHPTech