function checkForArgument($inArgv, $inIndex) { if (!array_key_exists($inIndex, $inArgv)) { printHelp(); exit(0); } }
function setup($argc, $argv) { if ($argc == 1 || loadOptions($argv) === false) { printHelp(); } retrieveArgs($argv); loadConfigFiles(); setupAutoload(); }
function createAction($params) { if (count($params) < 2) { printHelp(); } else { list($actionType, $actionName) = explode(':', $params[0], 0); // expected to be "type:name", e.g. "f:save" if ($actionName == '') { printHelp(); } else { // second parameter is expected to be a module name $moduleName = $params[1]; if (count($params) == 2) { $g = new AppGenerator(__DIR__); } else { // third parameter (if given) is an app name $appName = $params[2]; $g = new AppGenerator(dirname(__DIR__) . '/' . $appName); } $g->createAction($moduleName, $actionName, array('type' => $actionType)); } } }
function getFacebookAuthorization($a = 1) { global $fbo, $key, $urlAccess, $urlAuth; if ($a == 1) { printHelp("You must give your athorization code.\nVisit http://www.facebook.com/code_gen.php?v=1.0&api_key={$key} to get one for php_batch_uploader.\n\n"); die; } try { $auth = $fbo->do_get_session($a); if (empty($auth)) { throw new Exception('Empty Code.'); } $fbReturn = $fbo->api_client->users_getInfo($fbo->api_client->users_getLoggedInUser(), array('name')); $name = $fbReturn[0]["name"]; } catch (Exception $e) { disp("Invalid auth code or could not authorize session.\nPlease check your auth code or generate a new one at: {$urlAuth}\n\nIf you removed php_batch_uploader from your privacy settings, you will need to reauthoize it at {$urlAccess}", 1); } disp("Executed facebook authorization.", 5); // Store authorization code in authentication array $auth['code'] = $a; // Save to users home directory file_put_contents(getenv('HOME') . "/.facebook_auth", serialize($auth)); disp("You are now authenticated {$name}! Re-run php_batch_uploader with a list of directories you would like uploaded to facebook.", 1); }
/* Map short options to long options. */ $shortOptMap = array('-h' => '--help', '-o' => '--out-dir', '-s' => '--stdout'); if (array_key_exists($a, $shortOptMap)) { $a = $shortOptMap[$a]; } switch ($a) { case '--validate-fingerprint': if ($v === NULL || strlen($v) === 0) { echo 'The --validate-fingerprint option requires an parameter.' . "\n"; echo 'Please run `' . $progName . ' --help` for usage information.' . "\n"; exit(1); } $validateFingerprint = $v; break; case '--help': printHelp(); exit(0); case '--out-dir': if ($v === NULL || strlen($v) === 0) { echo 'The --out-dir option requires an parameter.' . "\n"; echo 'Please run `' . $progName . ' --help` for usage information.' . "\n"; exit(1); } $outputDir = $baseDir . ($v[0] == '/' ? $v : '/' . $v); break; case '--stdout': $toStdOut = TRUE; break; default: echo 'Unknown option: ' . $a . "\n"; echo 'Please run `' . $progName . ' --help` for usage information.' . "\n";
/** * Parses (and checks some) command line arguments */ function parseArguments() { global $checkOptions, $cmdargs, $checksEnabled, $periods, $periodsEnabled, $argc, $argv; if ($argc == 1) { printUsage(true); exit(STATUS_UNKNOWN); } $i = 1; while ($i < $argc) { if ($argv[$i][0] != '-') { $i++; continue; } switch ($argv[$i][1]) { case 'V': printVersion(); exit(STATUS_OK); break; case 'v': $cmdargs['log_level'] = LOG__VERBOSE; $i++; break; case 'd': $cmdargs['log_level'] = LOG__DEBUG; $i++; break; case 'c': $cmdargs['community'] = $argv[$i + 1]; $i++; break; case 'h': $cmdargs['host'] = $argv[$i + 1]; $i++; break; case 'p': $cmdargs['port'] = $argv[$i + 1]; $i++; break; case '?': printHelp(); exit(STATUS_OK); break; default: if (!isset($argv[$i + 1]) || substr($argv[$i + 1], 0, 1) == '-') { $cmdargs[substr($argv[$i], 2)] = true; } else { $cmdargs[substr($argv[$i], 2)] = $argv[$i + 1]; } $i++; break; } } }
echo <<<EOF It looks like this is the first time you have run php_batch_uploader on this machine. If you have not already authorized php_batch_uploader access to your facebook account you must do that first at: {$urlAccess} You must then generate a one-time code at {$urlAuth} And run php_batch_uploader with the '-a' switch using the generated code. EOF; } else { // Display Help. printHelp("php_batch_uploader http://github.com/jedediahfrey/Facebook-PHP-Batch-Picture-Uploader\nCopyright: Copyright (C) 2011 Jedediah Frey <*****@*****.**>\n\n"); die; } } elseif (array_key_exists("m", $options) && $options['m'] == "h") { // If the user asks for mode help. printModeHelp(); die; } //// Set defaults // Set verbosity - Default 2. $verbosity = array_key_exists("v", $options) ? intval($options["v"]) : 2; // Set the upload mode - Default 1. $mode = array_key_exists("m", $options) ? $options["m"] : 1; $albumName = array_key_exists("n", $options) ? $options["n"] : NULL; $location = array_key_exists("l", $options) ? $options["l"] : NULL; $description = array_key_exists("d", $options) ? $options["d"] : NULL;
function translateCommandArgs($args) { $paths = $args[1]; foreach ($paths as $path) { if (!is_dir($path) && !is_file($path)) { die("Entered path is invalid: " . $path); } } foreach ($args[0] as $arg) { if (!isset($arg[0])) { continue; } switch ($arg[0]) { case '--noarchive': $GLOBALS['noarchive'] = true; break; case '--help': printHelp(); die; break; case '--maxdepth': $GLOBALS['maxdepth'] = intval($arg[1]); break; case '--nohidden': $GLOBALS['nohidden'] = true; break; case '--nosystem': $GLOBALS['nosystem'] = true; break; case '--nodotfiles': $GLOBALS['nodotfiles'] = true; break; case '--excluderegex': $GLOBALS['excluderegex'] = $arg[1]; break; case '--eofnewline': $GLOBALS['eofnewline'] = true; break; case '--eofstripwhite': $GLOBALS['eofstripwhite'] = true; break; case '--eolstripwhite': $GLOBALS['eolstripwhite'] = true; break; } } return $paths; }
#!/usr/bin/php <?php $bootstrapFile = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : null; if (!file_exists($bootstrapFile)) { printHelp('オートロード設定をするためのブートストラップファイルが見つかりません。'); } $dir = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : null; if (!is_dir($dir)) { printHelp('Validationクラスを配置したディレクトリが見つかりません。'); } // カラーが表示できない場合は、$GLOBALS['ricegrain-validator-colorize'] = false; を // ブートストラップファイルに記入して下さい。 $GLOBALS['ricegrain-validator-colorize'] = true; define('COLOR_BLACK', 30); define('COLOR_RED', 31); define('COLOR_GREEN', 32); define('COLOR_YELLOW', 33); define('COLOR_BLUE', 34); define('COLOR_PURPLE', 35); define('COLOR_LIGHT_BLUE', 36); define('COLOR_WHITE', 37); require $bootstrapFile; $fileList = findFile($dir); foreach ($fileList as $file) { $classString = file_get_contents($file); if (preg_match('!namespace\\s+([^;]+);!', $classString, $matches)) { $namespace = $matches[1]; if (preg_match('!class\\s+([a-zA-Z0-9]+)\\s+extends\\s+([^ ]*Validation)!', file_get_contents($file), $matches)) { $className = $namespace . '\\' . $matches[1]; if ($matches[2] != 'Validation' && $matches[2] != 'RiceGrain\\Validation\\Validation') { continue;
*/ echo "This will install the Aether PHP framework on this computer\n"; echo "Type install path or default [/home/aether] will be used:\n"; if (!empty($argv[1]) and $argv[1] != '--help' and $argv[1] != '-h') { $path = $argv[1]; } else { exit(printHelp()); } $arg = $argv[1]; // See if install or update is wanted if (preg_match('/(--prefix|-p)=\\/[a-z-_.\\/]+/i', $arg)) { install($arg); } elseif (preg_match('/--update|-u/', $arg)) { update(); } else { exit(printHelp()); } /** * Install Aether using path found in $arg * * @return void */ function install($arg) { if (preg_match('/^--prefix|-p=(\\/{1}[a-z-_.\\/]+[a-z-_.]+)$/i', $arg, $m)) { $path = $m[1]; echo "Trying to install to {$path}/aether\n"; // Path must exist(?) // Check permissions if (file_exists($path) and is_writable($path)) { $user = $_SERVER['USER'];
/** * Parses (and checks some) command line arguments */ function parseArguments() { global $checkOptions, $cmdargs, $checksEnabled, $periods, $periodsEnabled, $argc, $argv; if ($argc == 1) { printUsage(true); exit(STATUS_UNKNOWN); } $i = 1; while ($i < $argc) { if ($argv[$i][0] != '-') { $i++; continue; } //disabling or enabling checks if (substr($argv[$i], 2, 8) == 'disable-' || substr($argv[$i], 2, 7) == 'enable-') { $op = substr($argv[$i], 2, 7) == "disable" ? 0 : 1; $check = $op ? substr($argv[$i], 9) : substr($argv[$i], 10); if ($check == "all") { foreach ($checkOptions as $key => $check) { $checksEnabled[$key] = $op; } } else { if (in_array($check, $checkOptions)) { $checksEnabled[$checkOptions[$check]] = $op; } else { _log(sprintf("ERR: Unknown option %s. Use help for more details.", $argv[$i]), LOG__ERROR); exit(STATUS_UNKNOWN); } } $i++; continue; } if (substr($argv[$i], 2) == "help") { $argv[$i] = '-h'; } switch ($argv[$i][1]) { case 'V': printVersion(); exit(STATUS_OK); break; case 'v': $cmdargs['log_level'] = LOG__VERBOSE; $i++; break; case 'd': $cmdargs['log_level'] = LOG__DEBUG; $i++; break; case 'c': $cmdargs['configFile'] = $argv[$i + 1]; if (isset($argv[$i + 2])) { $periodsEnabled = array(); while (isset($argv[$i + 2])) { if (in_array($argv[$i + 2], $periods)) { $periodsEnabled[] = $argv[$i + 2]; $i++; } else { if ($argv[$i + 2][0] != "-") { _log("Bad period provided. Use help for more details.", LOG__ERROR); exit(STATUS_UNKNOWN); } else { break; } } } } $i++; break; case 'h': case '?': printHelp(); exit(STATUS_OK); break; default: $i++; } } //check the configuration file if (!file_exists($cmdargs['configFile']) || !is_readable($cmdargs['configFile'])) { _log(sprintf("Configuration file [%s] does not exist or cannot be read.", $cmdargs['configFile']), LOG__ERROR); exit(STATUS_UNKNOWN); } }
<?php define('TWITTERBOT', 1); require_once 'config.php'; require_once 'twitterbot.php'; require_once 'action.php'; require_once OAUTH . 'twitteroauth.php'; // which args are present? if (count($argv) > 2 || in_array('-h', $argv) || in_array('--help', $argv)) { die(printHelp()); } if (in_array('--stop', $argv)) { // stop has been set! try to kill it echo "\n" . '==SHUTTING DOWN TWITTERBOT==' . "\n"; halt(); exit; } if (in_array('--tests-only', $argv)) { test(); exit; } if (!in_array('--tests-skip', $argv)) { test(); } echo "\n" . '==POWERING UP TWITTERBOT==' . "\n"; // gain the lockfile $fp = @fopen(TWITTERBOT_LOCKFILE, "a"); if (!$fp || !flock($fp, LOCK_EX | LOCK_NB)) { die("Failed to acquire lock. Twitterbot may already be running.\n"); } // this bit guarantees that the process is 1) detached, and 2) independent
} // end func printSeperator if (!isset($argc) || !isset($argv)) { // redirect to the web gui // or maybe die("This is the command line interface, use php -f cli.php to run it! Open index.php for the web interface."); ? header('Location: GUI/index.php'); exit(0); } list($options, $error) = parseOptions($argc, $argv); if (!is_null($error) || empty($options) || isset($options['help'])) { // some sort of trouble or help output requested if (!is_null($error)) { printf("\n"); printf("Error: %s\n", $error); } printHelp($argv); } else { print "\n"; if (!empty($options['files'])) { foreach ($options['files'] as $k => $file) { convertFile($file, isset($options['verbose']), isset($options['quiet']), isset($options['update']), isset($options['backup']), isset($options['warnings'])); } } if (!empty($options['directories'])) { $conv = new MySQLConverterTool_Converter(); foreach ($options['directories'] as $k => $directory) { $files = $conv->getFilesOfDirectory($directory, isset($options['pattern']) ? $options['pattern'] : ''); if (empty($files)) { printSeperator(sprintf('No files found in "%s"', $directory), '*'); print "\n"; continue;