public function ingestInput($vars, $skipValidate = false) { parent::ingestInput($vars, $skipValidate); //Prep file upload data if (isset($this->api_vars["file"])) { $this->method = "uploadFile"; $this->endpoint = $this->job; if (!isset($this->api_vars["brand_name"])) { $this->api_vars["brand_name"] = $this->account->getName(); if ($this->api_vars["brand_name"] == null) { CliScriptAbstract::confirm("You need to provide a brand if you are not using a preconfigured account.\nContinue anyway?", "Add the '-h' option for more details on valid inputs."); $this->api_vars["brand_name"] = "unknown"; } } if (CliScriptAbstract::$flags["isValidateFile"]) { $this->api_vars["is_skip_check"] = true; } } //Correctly manage updates. if (isset($this->api_vars["vars"])) { if (!isset($this->api_vars["update"])) { $this->api_vars["update"] = array(); } $this->api_vars["update"]["vars"] = $this->api_vars["vars"]; unset($this->api_vars["vars"]); } if (isset($this->api_vars["lists"])) { if (!isset($this->api_vars["update"])) { $this->api_vars["update"] = array(); } $this->api_vars["update"]["lists"] = $this->api_vars["lists"]; unset($this->api_vars["lists"]); } if (isset($this->api_vars["optout"])) { if (!isset($this->api_vars["update"])) { $this->api_vars["update"] = array(); } $this->api_vars["update"]["optout"] = $this->api_vars["optout"]; unset($this->api_vars["optout"]); } if (isset($this->api_vars["delete_vars"])) { if (!isset($this->api_vars["update"])) { $this->api_vars["update"] = array(); } $tmp = explode(",", $this->api_vars["delete_vars"]); foreach ($tmp as $i => $c) { $tmp[$i] = trim($c); } $this->api_vars["update"]["delete_vars"] = $tmp; unset($this->api_vars["delete_vars"]); } if (isset($this->api_vars["signup_date"])) { if (!isset($this->api_vars["update"])) { $this->api_vars["update"] = array(); } $this->api_vars["update"]["signup_date"] = $this->api_vars["signup_date"]; unset($this->api_vars["signup_date"]); } }
public function ingestInput($vars, $skipValidate = false) { parent::ingestInput($vars, $skipValidate); if (isset($this->api_vars["file"])) { $this->method = "uploadFile"; $this->endpoint = $this->job; $this->api_vars["file_type"] = "json"; if (!isset($this->api_vars["brand_name"])) { $this->api_vars["brand_name"] = $this->account->getName(); if ($this->api_vars["brand_name"] == null) { CliScriptAbstract::confirm("You need to provide a brand if you are not using a preconfigured account.\nContinue anyway?", "Add the '-h' option for more details on valid inputs."); $this->api_vars["brand_name"] = "unknown"; } } } }
public function ingestInput($vars, $skipValidate = false) { parent::ingestInput($vars, $skipValidate); //Prep file upload data if (isset($this->api_vars["file"])) { $this->method = "uploadFile"; $this->endpoint = $this->job; if (!isset($this->api_vars["brand_name"])) { $this->api_vars["brand_name"] = $this->account->getName(); if ($this->api_vars["brand_name"] == null) { CliScriptAbstract::confirm("You need to provide a brand if you are not using a preconfigured account.\nContinue anyway?", "Add the '-h' option for more details on valid inputs."); $this->api_vars["brand_name"] = "unknown"; } } if (CliScriptAbstract::$flags["isValidateFile"]) { $this->api_vars["is_skip_check"] = true; } if (!isset($this->api_vars["file_type"])) { $this->api_vars["file_type"] = "json"; } } else { echo "This isn't supported. How did you get here?\n\nSERIOUSLY!!!???\n\n"; } }
// Base Script to be copied then modified. // COPY THEN MODIFY require_once dirname(__DIR__) . "/Classes/Api/Account_Credentials/KeysAndSecrets.php"; $account_credentials = new KeysAndSecrets(); $account_credentials->setAccount(); //START CALL SPECIFIC require_once dirname(__DIR__) . "/Classes/Api/List/ListGet.php"; //Call Specifc//Incomplete// $api_object = new ListGet(); //Call Specifc//Incomplete// $api_object->setAccount($account_credentials); include_once dirname(__DIR__) . "/Use_Case_Vars/ListGetVars.php"; //Call Specifc//Incomplete// //END CALL SPECIFIC require_once dirname(__DIR__) . "/Classes/CliScriptAbstract.php"; $script = new CliScriptAbstract(); require_once dirname(__DIR__) . "/Classes/Client_Library/Sailthru_Implementation_Client.php"; include_once dirname(__DIR__) . "/Setup_Files/ScriptSettings.php"; new ScriptSettings(); //////////////////// VARS /* There are three ways to input vars for a script: 1) Thorugh the Command Line Interface, CLI, when you run the script. 2) The vars array in this file. 3) An include file specific to this script. The Use_Vase_Vars include above. While they are essentially equivalent, The Use Case include is the prefered method. The other two are provided to give ease of use in a given situation. They can also be used in conjunction -with each overridden by the next in the order given above. That means if you add two vars, a & b, to the use case vars file but provide b again in the CLI, 'a' will be the value from the use case file, but 'b' will be the command line value. This allows for a lot of flexibility but can create confusing results if you
function inspectTemplateForZephyr($response, $bad_includes, $horizon_includes, $bad_zephyr_functions) { $html_hit = inspectForZephyr($response["content_html"], $bad_zephyr_functions); $setup_hit = inspectForZephyr($response["setup"], $bad_zephyr_functions); if ($setup_hit || $html_hit) { if (is_array($setup_hit)) { if (is_array($html_hit)) { $hits_array = array_merge($html_hit, $setup_hit); } else { $hits_array = $setup_hit; } } else { $hits_array = $html_hit; } $preg_hits_array = []; foreach ($hits_array as $tmp) { array_push($preg_hits_array, preg_quote($tmp)); } $bad_functions = array_intersect($bad_zephyr_functions, $preg_hits_array); if ($bad_functions) { if (count($bad_functions) == 1 && in_array("filter\\(", $bad_functions)) { CliScriptAbstract::printColor($response["name"] . " >> Reason: Bad Function: " . implode($bad_functions, ", ") . "\n", "cyan"); return; } CliScriptAbstract::printColor($response["name"] . " >> Reason: Bad Function: " . implode($bad_functions, ", ") . "\n", "red"); return; } if (in_array("include \"", $hits_array) && count($bad_includes) > 0) { $test = "/(\\b" . implode("\\b)|(\\b", $bad_includes) . "\\b)/"; if (preg_match_all($test, $response["content_html"], $hits)) { CliScriptAbstract::printColor($response["name"] . " >> Reason: Bad Include: " . implode($hits[0], ", ") . "\n", "red"); return; } else { if (preg_match_all($test, $response["setup"], $hits)) { CliScriptAbstract::printColor($response["name"] . " >> Reason: Bad Include: " . implode($hits[0], ", ") . "\n", "red"); return; } } $test = "/(\\b" . implode("\\b)|(\\b", $horizon_includes) . "\\b)/"; if (preg_match_all($test, $response["content_html"], $hits)) { CliScriptAbstract::printColor($response["name"] . "\n", "green"); return; } else { if (preg_match_all($test, $response["setup"], $hits)) { CliScriptAbstract::printColor($response["name"] . "\n", "green"); return; } } } if (in_array("horizon_select(", $hits_array)) { CliScriptAbstract::printColor($response["name"] . "\n", "green"); return; } CliScriptAbstract::printColor($response["name"] . "\n", "yellow"); return; } else { CliScriptAbstract::printColor($response["name"] . " -- \n", "yellow"); } }
public static function readCliArguments(array $argv, CliScriptInterface $cli_interface) { ////Read in flags first. //Get flag options (I'm being annoying here so the flags from this file over ride any others but still display last.) $cli_options = CliScriptAbstract::$script_cli_options + array_reverse($cli_interface->getCliOptions()); $cli_options = array_reverse($cli_options); //read in, save, then remove flags from argv. $argv = CliScriptAbstract::processFlags($argv, $cli_options, CliScriptAbstract::getFlagModifications($cli_interface)); //make the flags easier to access here by giving them local scope. extract(CliScriptAbstract::$flags); //Read in all other vars. $cli_description = $cli_interface->getCliDescription(); $cli_params = $cli_interface->getCliParameters(); $cli_extras = $cli_interface->getOtherInputsDescription(); //I want the full help menu to have precedence over the brief window. if (!$isRun && (count($argv) == 1 || $isHelp)) { CliScriptAbstract::print_help($cli_description, $cli_params, $cli_options, $cli_extras); die("\n"); } else { if (!$isRun && ($isBriefHelp || $isBashHelp)) { $brief = $isBriefHelp ? "brief" : "bash"; CliScriptAbstract::print_help($cli_description, $cli_params, $cli_options, $cli_extras, $brief); die("\n"); } } //Past the help Menu, lets read in some vars $vars = array(); //Named Vars sent through in the config as expected $flags = array(); //Flags sent through in the config as expected $wildcards = array(); //Named vars that were not expected $other_inputs = array(); //Catch all for other input. $exploded_args = array(); foreach ($argv as $arg) { if (strpos($arg, "=") !== FALSE) { $e = explode("=", $arg); $param_key = $e[0]; if ($e[1][0] == "{") { $e[1] = CliScriptAbstract::convertSmartQuotes($e[1]); $exploded_args[$param_key] = json_decode($e[1], true); if (json_last_error() !== JSON_ERROR_NONE) { CliScriptAbstract::$last_error = $e[0]; CliScriptAbstract::confirm("JSON Object, " . $e[0] . ", was not successfully decoded: " . json_last_error_msg() . "\nContinue anyway?", "Try 'http://www.jsoneditoronline.org/' if you don't know what is wrong."); unset($exploded_args[$param_key]); } } else { if (strpos($e[1], "(string)") !== false) { $exploded_args[$param_key] = substr($e[1], 0, -8); } else { if (is_numeric($e[1])) { $exploded_args[$param_key] = $e[1] + 0; } else { $exploded_args[$param_key] = $e[1]; } } } } else { array_push($other_inputs, $arg); } } foreach ($cli_params as $param_var => $rest) { if (isset($exploded_args[$rest[0]])) { $vars[$param_var] = $exploded_args[$rest[0]]; unset($exploded_args[$rest[0]]); } } CliScriptAbstract::processVars($exploded_args, $cli_params); return array("config_vars" => $vars, "wildcard_vars" => $exploded_args, "other_inputs" => $other_inputs); }
private function confirm($question, $failText) { CliScriptAbstract::confirm($question, $failText); }
protected function validateVars() { $criteria = $this->api_params_validation; $display = $this->cli_params; foreach ($criteria as $key => $value) { if (isset($this->api_vars[$key]) || $key == "always_required") { //Proceed to validate if the key is set, or the key is the required parameters key. Unlike below, the "always_required" naming is important. foreach ($value as $negation => $dependencies) { if (!isset($this->api_vars[$negation]) && $negation != "require_one" && $negation != "value_specifics") { //As "always_required" (or any other arbitrary name) won't be set, any dependencies of a nonsense name will always run. Unless some asshole submits always_required as a param.. Edit: If passed as a 0, now works as a feature. foreach ($dependencies as $dependency) { if (!isset($this->api_vars[$dependency])) { if ($key == "always_required") { CliScriptAbstract::confirm("You are missing a required parameter: " . $display[$dependency][0] . ".\nContinue anyway?", "Add the '-h' option for more details on valid inputs."); } else { CliScriptAbstract::confirm("To use " . $display[$key][0] . " you should also provide " . $display[$dependency][0] . ".\nContinue anyway?", "Add the '-h' option for more details on valid inputs."); } } } } else { if ($negation == "require_one") { $mix = array_intersect($dependencies, array_keys($this->api_vars)); if (count($mix) > 1 || count($mix) == 0) { CliScriptAbstract::confirm("One, and only one, of the following must be submitted: " . implode(", ", $dependencies) . ".\nContinue anyway?", "Add the '-h' option for more details on valid inputs."); } } else { if ($negation == "value_specifics") { foreach ($dependencies as $value => $value_dependencies) { if ($this->api_vars[$key] == $value) { foreach ($value_dependencies as $dependency) { if (!isset($this->api_vars[$dependency])) { CliScriptAbstract::confirm("To use " . $display[$key][0] . " as " . $value . " you should also provide " . $display[$dependency][0] . ".\nContinue anyway?", "Add the '-h' option for more details on valid inputs."); } } } } } } } } } } }