View source
<?php
define('NO_AUTOCOMPLETE_GREEN_OUTPUT', "\33[1;32;40m\33[1m[%s]\33[0m");
define('NO_AUTOCOMPLETE_RED_OUTPUT', "\33[31;40m\33[1m[%s]\33[0m");
function no_autocomplete_drush_command() {
$items['na-login'] = array(
'description' => dt('Configures the "autocomplete=off" option on the user login form.'),
'arguments' => array(
'status' => dt('The option status (on, off).'),
),
'aliases' => array(
'nal',
),
'examples' => array(
'na-login' => dt('Show the status for the use of the "autocomplete=off" option in the user login form.'),
'na-login on' => dt('The user login form will use the "autocomplete=off" option.'),
'na-login off' => dt('The user login form will don\'t use the "autocomplete=off" option.'),
),
);
return $items;
}
function no_autocomplete_drush_help($section) {
switch ($section) {
case 'meta:no_autocomplete:title':
return dt("No Autocomplete commands");
case 'meta:no_autocomplete:summary':
return dt("Interacts with the No Autocomplete module's functionalities.");
case 'drush:na-login':
return dt('Configures the "autocomplete=off" option on the user login form.');
}
}
function drush_no_autocomplete_na_login_validate() {
$args = func_get_args();
if (!_drush_no_autocomplete_validate_argument($args)) {
return;
}
}
function _drush_no_autocomplete_validate_argument(array $option) {
if (count($option) > 1) {
return drush_set_error('NO_AUTOCOMPLETE_INVALID_ARGUMENT', dt('This command use only one argument.'));
}
$available_options = array(
'on',
'off',
);
if (isset($option[0]) && !in_array($option[0], $available_options)) {
return drush_set_error('NO_AUTOCOMPLETE_INVALID_ARGUMENT', dt("You must specify as argument 'on' or 'off'"));
}
return TRUE;
}
function drush_no_autocomplete_na_login() {
$args = func_get_args();
_drush_no_autocomplete_set_options('no_autocomplete_login_form', $args);
}
function _drush_no_autocomplete_set_options($variable, $args) {
$config_status = variable_get($variable, FALSE);
$status = $config_status ? sprintf(NO_AUTOCOMPLETE_GREEN_OUTPUT, dt('Activated')) : sprintf(NO_AUTOCOMPLETE_RED_OUTPUT, dt('Disabled'));
switch ($variable) {
case 'no_autocomplete_login_form':
$option_text = dt('login form');
break;
}
if (isset($args[0])) {
list($value, $status) = $args[0] == 'on' ? array(
1,
dt('activated'),
) : array(
0,
dt('disabled'),
);
$already_configured = FALSE;
if ($config_status && $value) {
$already_configured = TRUE;
}
if (!$config_status && !$value) {
$already_configured = TRUE;
}
if ($already_configured) {
$message = dt('The "autocomplete=off" option on the user @option_text is already @status.', array(
'@status' => $status,
'@option_text' => $option_text,
));
drush_log($message, 'warning');
return;
}
variable_set($variable, $value);
$message = dt('You have @status the use of the "autocomplete=off" option on the user @option_text.', array(
'@status' => $status,
'@option_text' => $option_text,
));
drush_log($message, 'success');
}
else {
$message = dt('The "autocomplete=off" option on the user @option_text is: @status.', array(
'@status' => $status,
'@option_text' => $option_text,
));
drush_print($message);
}
}