Beispiel #1
0
function main($args)
{
    $dryrun = in_array("-r", $args);
    $inline = in_array("-i", $args);
    $delete = in_array("-d", $args);
    $verbose = in_array("-v", $args);
    $args = array_values(array_filter($args, function ($arg) {
        return !startsWith($arg, "-");
    }));
    $src = $args[0];
    if (!file_exists($src)) {
        throw new Exception("can't find file/folder '{$src}'");
    }
    if ($dryrun) {
        if ($verbose) {
            print "DRYRUN MODE\n";
        }
        $changeFiles = [];
        foreach (getFileset($src) as $file) {
            if ($verbose) {
                print "CHECKING FILE '{$file}'\n";
            }
            $file = realpath($file);
            $lines = explode("\n", file_get_contents($file));
            if (willContentChange($lines)) {
                $changeFiles[] = $file;
            }
        }
        print "FILES THAT WILL CHANGE\n";
        print implode("\n - ", $changeFiles);
    } else {
        if ($delete) {
            if ($verbose) {
                print "LICENSE DELETE MODE\n";
            }
            foreach (getFileset($src) as $file) {
                if ($verbose) {
                    print "DELETING ANY LICENSE HEADERS FROM FILE '{$file}'\n";
                }
                $lines = explode("\n", file_get_contents(realpath($file)));
                $lines = cleanUpFileHeader(removeLicense($lines));
                file_put_contents($file, implode("\n", $lines));
            }
        } else {
            $fileContents = [];
            foreach (getFileset($src) as $file) {
                if ($verbose) {
                    print "UPDATING FILE '{$file}'\n";
                }
                $file = realpath($file);
                $contents = file_get_contents($file);
                $lines = explode("\n", $contents);
                $fileContents[$file] = implode("\n", updateLicense($lines));
            }
            if ($inline) {
                if ($verbose) {
                    print "INLINE MODE - WRITING FILES...\n";
                }
                foreach ($fileContents as $fileName => $contents) {
                    if ($verbose) {
                        print "WRITING FILE '{$fileName}'\n";
                    }
                    file_put_contents($fileName, $contents);
                }
                print "WROTE " . count($fileContents) . " FILES\n";
            } else {
                foreach ($fileContents as $fileName => $contents) {
                    print ">>>FILE {$fileName}\n{$contents}\n<<<FILE\n";
                }
            }
        }
    }
}
Beispiel #2
0
 * @category	DOCman
 * @package		DOCman15
 * @copyright	Copyright (C) 2003 - 2009 Johan Janssens and Mathias Verraes. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 * @link     	http://www.joomladocman.org
 */
defined('_JEXEC') or die('Restricted access');
include_once dirname(__FILE__) . '/licenses.html.php';
JArrayHelper::toInteger($cid);
switch ($task) {
    case "edit":
        $cid = isset($cid[0]) ? $cid[0] : 0;
        editLicense($option, $cid);
        break;
    case "remove":
        removeLicense($cid, $option);
        break;
    case "apply":
    case "save":
        saveLicense($option);
        break;
    case "cancel":
        cancelLicense($option);
        break;
    case "show":
    default:
        showLicenses($option);
}
function editLicense($option, $uid)
{
    $database = JFactory::getDBO();