Last active
February 6, 2021 05:18
-
-
Save alewolf/5eb4c222bf3a186b096483a0af2b7eb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Keywords: freemius, readme.txt, changelog, free version, pro version | |
* | |
* Description: This code takes a readme.txt of a WordPress plugin, that has been prepared for deployment | |
* over freemius, and generates a changelog text output with the changelog for the free and one for the pro version. | |
*/ | |
$source_file = '../src/readme.txt'; | |
$target_file_pro = 'tmp/changelog-pro.md'; | |
$target_file_free = 'tmp/changelog-free.md'; | |
$handle = fopen($source_file, 'r'); | |
$changelog_pro = []; | |
$changelog_free = []; | |
if ($handle) { | |
$write_mode = null; | |
while (($line = fgets($handle)) !== false) { | |
if (strpos($line, 'Changelog') == true) { | |
$write_mode = 'all'; | |
array_push($changelog_pro, $line); | |
array_push($changelog_free, $line); | |
continue; | |
} | |
// set up write mode | |
if (strpos($line, 'fs_premium_only_begin')) { | |
$write_mode = 'pro'; | |
continue; | |
} else if(strpos($line, 'fs_free_only_begin')) { | |
$write_mode = 'free'; | |
continue; | |
} | |
// never write if we're on an end directive | |
if (strpos($line, 'fs_premium_only_end') || strpos($line, 'fs_free_only_end')) { | |
$write_mode = 'all'; | |
continue; | |
} | |
if($write_mode === 'pro') { | |
array_push($changelog_pro, $line); | |
} else if($write_mode === 'free') { | |
array_push($changelog_free, $line); | |
} else if ($write_mode === 'all') { | |
array_push($changelog_pro, $line); | |
array_push($changelog_free, $line); | |
} | |
} | |
fclose($handle); | |
} else { | |
echo('error opening the file'); | |
} | |
file_put_contents($target_file_pro, $changelog_pro); | |
file_put_contents($target_file_free, $changelog_free); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment